Ignore:
Timestamp:
Jan 24, 2021, 8:40:08 AM (5 years ago)
Author:
Paul Smedley
Message:

Update regmap & regcache to 5.10.10 kernel code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GPL/branches/uniaud32-next/lib32/regmap.c

    r638 r652  
    1 /*
    2  * Register map access API
    3  *
    4  * Copyright 2011 Wolfson Microelectronics plc
    5  *
    6  * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
    7  *
    8  * This program is free software; you can redistribute it and/or modify
    9  * it under the terms of the GNU General Public License version 2 as
    10  * published by the Free Software Foundation.
    11  */
    12 /* from 4.19.163 */
     1// SPDX-License-Identifier: GPL-2.0
     2//
     3// Register map access API
     4//
     5// Copyright 2011 Wolfson Microelectronics plc
     6//
     7// Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
     8
     9/* from 5.10.10 */
    1310
    1411#include <linux/device.h>
     
    1714#include <linux/mutex.h>
    1815#include <linux/err.h>
    19 #include <linux/of.h>
     16//#include <linux/property.h>
    2017#include <linux/rbtree.h>
    2118#include <linux/sched.h>
     
    4744#undef LOG_DEVICE
    4845
    49 /*static inline*/ int _regmap_update_bits(struct regmap *map, unsigned int reg,
     46#ifdef LOG_DEVICE
     47static inline bool regmap_should_log(struct regmap *map)
     48{
     49        return (map->dev && strcmp(dev_name(map->dev), LOG_DEVICE) == 0);
     50}
     51#else
     52static inline bool regmap_should_log(struct regmap *map) { return false; }
     53#endif
     54
     55
     56static int _regmap_update_bits(struct regmap *map, unsigned int reg,
    5057                               unsigned int mask, unsigned int val,
    5158                               bool *change, bool force_write);
    5259
    53 /*static inline*/ int _regmap_bus_reg_read(void *context, unsigned int reg,
     60static int _regmap_bus_reg_read(void *context, unsigned int reg,
    5461                                unsigned int *val);
    55 /*static inline*/ int _regmap_bus_read(void *context, unsigned int reg,
     62static int _regmap_bus_read(void *context, unsigned int reg,
    5663                            unsigned int *val);
    57 /*static inline*/ int _regmap_bus_formatted_write(void *context, unsigned int reg,
     64static int _regmap_bus_formatted_write(void *context, unsigned int reg,
    5865                                       unsigned int val);
    59 /*static inline*/ int _regmap_bus_reg_write(void *context, unsigned int reg,
     66static int _regmap_bus_reg_write(void *context, unsigned int reg,
    6067                                 unsigned int val);
    61 /*static inline*/ int _regmap_bus_raw_write(void *context, unsigned int reg,
     68static int _regmap_bus_raw_write(void *context, unsigned int reg,
    6269                                 unsigned int val);
    6370
     
    180187}
    181188
     189bool regmap_writeable_noinc(struct regmap *map, unsigned int reg)
     190{
     191        if (map->writeable_noinc_reg)
     192                return map->writeable_noinc_reg(map->dev, reg);
     193
     194        if (map->wr_noinc_table)
     195                return regmap_check_range_table(map, reg, map->wr_noinc_table);
     196
     197        return true;
     198}
     199
    182200bool regmap_readable_noinc(struct regmap *map, unsigned int reg)
    183201{
     
    191209}
    192210
    193 /*static inline*/ bool regmap_volatile_range(struct regmap *map, unsigned int reg,
     211static bool regmap_volatile_range(struct regmap *map, unsigned int reg,
    194212        size_t num)
    195213{
     
    203221}
    204222
    205 /*static inline*/ void regmap_format_2_6_write(struct regmap *map,
     223static void regmap_format_12_20_write(struct regmap *map,
    206224                                     unsigned int reg, unsigned int val)
    207225{
    208226        u8 *out = map->work_buf;
    209227
     228        out[0] = reg >> 4;
     229        out[1] = (reg << 4) | (val >> 16);
     230        out[2] = val >> 8;
     231        out[3] = val;
     232}
     233
     234
     235static void regmap_format_2_6_write(struct regmap *map,
     236                                     unsigned int reg, unsigned int val)
     237{
     238        u8 *out = map->work_buf;
     239
    210240        *out = (reg << 6) | val;
    211241}
    212242
    213 /*static inline*/ void regmap_format_4_12_write(struct regmap *map,
     243static void regmap_format_4_12_write(struct regmap *map,
    214244                                     unsigned int reg, unsigned int val)
    215245{
     
    218248}
    219249
    220 /*static inline*/ void regmap_format_7_9_write(struct regmap *map,
     250static void regmap_format_7_9_write(struct regmap *map,
    221251                                    unsigned int reg, unsigned int val)
    222252{
     
    225255}
    226256
    227 /*static inline*/ void regmap_format_10_14_write(struct regmap *map,
     257static void regmap_format_10_14_write(struct regmap *map,
    228258                                    unsigned int reg, unsigned int val)
    229259{
     
    235265}
    236266
    237 /*static inline*/ void regmap_format_8(void *buf, unsigned int val, unsigned int shift)
     267static void regmap_format_8(void *buf, unsigned int val, unsigned int shift)
    238268{
    239269        u8 *b = buf;
     
    242272}
    243273
    244 /*static inline*/ void regmap_format_16_be(void *buf, unsigned int val, unsigned int shift)
     274static void regmap_format_16_be(void *buf, unsigned int val, unsigned int shift)
    245275{
    246276        put_unaligned_be16(val << shift, buf);
    247277}
    248278
    249 /*static inline*/ void regmap_format_16_le(void *buf, unsigned int val, unsigned int shift)
     279static void regmap_format_16_le(void *buf, unsigned int val, unsigned int shift)
    250280{
    251281        put_unaligned_le16(val << shift, buf);
    252282}
    253283
    254 /*static inline*/ void regmap_format_16_native(void *buf, unsigned int val,
     284static void regmap_format_16_native(void *buf, unsigned int val,
    255285                                    unsigned int shift)
    256286{
     
    260290}
    261291
    262 /*static inline*/ void regmap_format_24(void *buf, unsigned int val, unsigned int shift)
     292static void regmap_format_24(void *buf, unsigned int val, unsigned int shift)
    263293{
    264294        u8 *b = buf;
     
    271301}
    272302
    273 /*static inline*/ void regmap_format_32_be(void *buf, unsigned int val, unsigned int shift)
     303static void regmap_format_32_be(void *buf, unsigned int val, unsigned int shift)
    274304{
    275305        put_unaligned_be32(val << shift, buf);
    276306}
    277307
    278 /*static inline*/ void regmap_format_32_le(void *buf, unsigned int val, unsigned int shift)
     308static void regmap_format_32_le(void *buf, unsigned int val, unsigned int shift)
    279309{
    280310        put_unaligned_le32(val << shift, buf);
    281311}
    282312
    283 /*static inline*/ void regmap_format_32_native(void *buf, unsigned int val,
     313static void regmap_format_32_native(void *buf, unsigned int val,
    284314                                    unsigned int shift)
    285315{
     
    290320
    291321#ifdef CONFIG_64BIT
    292 /*static inline*/ void regmap_format_64_be(void *buf, unsigned int val, unsigned int shift)
     322static void regmap_format_64_be(void *buf, unsigned int val, unsigned int shift)
    293323{
    294324        put_unaligned_be64((u64) val << shift, buf);
    295325}
    296326
    297 /*static inline*/ void regmap_format_64_le(void *buf, unsigned int val, unsigned int shift)
     327static void regmap_format_64_le(void *buf, unsigned int val, unsigned int shift)
    298328{
    299329        put_unaligned_le64((u64) val << shift, buf);
    300330}
    301331
    302 /*static inline*/ void regmap_format_64_native(void *buf, unsigned int val,
     332static void regmap_format_64_native(void *buf, unsigned int val,
    303333                                    unsigned int shift)
    304334{
     
    309339#endif
    310340
    311 /*static inline*/ void regmap_parse_inplace_noop(void *buf)
    312 {
    313 }
    314 
    315 /*static inline*/ unsigned int regmap_parse_8(const void *buf)
     341static void regmap_parse_inplace_noop(void *buf)
     342{
     343}
     344
     345static unsigned int regmap_parse_8(const void *buf)
    316346{
    317347        const u8 *b = buf;
     
    320350}
    321351
    322 /*static inline*/ unsigned int regmap_parse_16_be(const void *buf)
     352static unsigned int regmap_parse_16_be(const void *buf)
    323353{
    324354        return get_unaligned_be16(buf);
    325355}
    326356
    327 /*static inline*/ unsigned int regmap_parse_16_le(const void *buf)
     357static unsigned int regmap_parse_16_le(const void *buf)
    328358{
    329359        return get_unaligned_le16(buf);
    330360}
    331361
    332 /*static inline*/ void regmap_parse_16_be_inplace(void *buf)
     362static void regmap_parse_16_be_inplace(void *buf)
    333363{
    334364        u16 v = get_unaligned_be16(buf);
     
    337367}
    338368
    339 /*static inline*/ void regmap_parse_16_le_inplace(void *buf)
     369static void regmap_parse_16_le_inplace(void *buf)
    340370{
    341371        u16 v = get_unaligned_le16(buf);
     
    344374}
    345375
    346 /*static inline*/ unsigned int regmap_parse_16_native(const void *buf)
     376static unsigned int regmap_parse_16_native(const void *buf)
    347377{
    348378        u16 v;
     
    352382}
    353383
    354 /*static inline*/ unsigned int regmap_parse_24(const void *buf)
     384static unsigned int regmap_parse_24(const void *buf)
    355385{
    356386        const u8 *b = buf;
     
    362392}
    363393
    364 /*static inline*/ unsigned int regmap_parse_32_be(const void *buf)
     394static unsigned int regmap_parse_32_be(const void *buf)
    365395{
    366396        return get_unaligned_be32(buf);
    367397}
    368398
    369 /*static inline*/ unsigned int regmap_parse_32_le(const void *buf)
     399static unsigned int regmap_parse_32_le(const void *buf)
    370400{
    371401        return get_unaligned_le32(buf);
    372402}
    373403
    374 /*static inline*/ void regmap_parse_32_be_inplace(void *buf)
     404static void regmap_parse_32_be_inplace(void *buf)
    375405{
    376406        u32 v = get_unaligned_be32(buf);
     
    379409}
    380410
    381 /*static inline*/ void regmap_parse_32_le_inplace(void *buf)
     411static void regmap_parse_32_le_inplace(void *buf)
    382412{
    383413        u32 v = get_unaligned_le32(buf);
     
    386416}
    387417
    388 /*static inline*/ unsigned int regmap_parse_32_native(const void *buf)
     418static unsigned int regmap_parse_32_native(const void *buf)
    389419{
    390420        u32 v;
     
    395425
    396426#ifdef CONFIG_64BIT
    397 /*static inline*/ unsigned int regmap_parse_64_be(const void *buf)
     427static unsigned int regmap_parse_64_be(const void *buf)
    398428{
    399429        return get_unaligned_be64(buf);
    400430}
    401431
    402 /*static inline*/ unsigned int regmap_parse_64_le(const void *buf)
     432static unsigned int regmap_parse_64_le(const void *buf)
    403433{
    404434        return get_unaligned_le64(buf);
    405435}
    406436
    407 /*static inline*/ void regmap_parse_64_be_inplace(void *buf)
     437static void regmap_parse_64_be_inplace(void *buf)
    408438{
    409439        u64 v =  get_unaligned_be64(buf);
     
    412442}
    413443
    414 /*static inline*/ void regmap_parse_64_le_inplace(void *buf)
     444static void regmap_parse_64_le_inplace(void *buf)
    415445{
    416446        u64 v = get_unaligned_le64(buf);
     
    419449}
    420450
    421 /*static inline*/ unsigned int regmap_parse_64_native(const void *buf)
     451static unsigned int regmap_parse_64_native(const void *buf)
    422452{
    423453        u64 v;
     
    428458#endif
    429459
    430 /*static inline*/ void regmap_lock_hwlock(void *__map)
    431 {
    432         //NOT_USED struct regmap *map = __map;
     460static void regmap_lock_hwlock(void *__map)
     461{
     462        struct regmap *map = __map;
    433463
    434464//      hwspin_lock_timeout(map->hwlock, UINT_MAX);
    435465}
    436466
    437 /*static inline*/ void regmap_lock_hwlock_irq(void *__map)
    438 {
    439         //NOT_USED struct regmap *map = __map;
     467static void regmap_lock_hwlock_irq(void *__map)
     468{
     469        struct regmap *map = __map;
    440470
    441471//      hwspin_lock_timeout_irq(map->hwlock, UINT_MAX);
    442472}
    443473
    444 /*static inline*/ void regmap_lock_hwlock_irqsave(void *__map)
    445 {
    446         //NOT_USED struct regmap *map = __map;
     474static void regmap_lock_hwlock_irqsave(void *__map)
     475{
     476        struct regmap *map = __map;
    447477
    448478//      hwspin_lock_timeout_irqsave(map->hwlock, UINT_MAX,
     
    450480}
    451481
    452 /*static inline*/ void regmap_unlock_hwlock(void *__map)
    453 {
    454         //NOT_USED struct regmap *map = __map;
     482static void regmap_unlock_hwlock(void *__map)
     483{
     484        struct regmap *map = __map;
    455485
    456486//      hwspin_unlock(map->hwlock);
    457487}
    458488
    459 /*static inline*/ void regmap_unlock_hwlock_irq(void *__map)
    460 {
    461         //NOT_USED struct regmap *map = __map;
     489static void regmap_unlock_hwlock_irq(void *__map)
     490{
     491        struct regmap *map = __map;
    462492
    463493//      hwspin_unlock_irq(map->hwlock);
    464494}
    465495
    466 /*static inline*/ void regmap_unlock_hwlock_irqrestore(void *__map)
    467 {
    468         //NOT_USED struct regmap *map = __map;
     496static void regmap_unlock_hwlock_irqrestore(void *__map)
     497{
     498        struct regmap *map = __map;
    469499
    470500//      hwspin_unlock_irqrestore(map->hwlock, &map->spinlock_flags);
    471501}
    472502
    473 /*static inline*/ void regmap_lock_unlock_none(void *__map)
    474 {
    475 
    476 }
    477 
    478 /*static inline*/ void regmap_lock_mutex(void *__map)
     503static void regmap_lock_unlock_none(void *__map)
     504{
     505
     506}
     507
     508static void regmap_lock_mutex(void *__map)
    479509{
    480510        struct regmap *map = __map;
     
    482512}
    483513
    484 /*static inline*/ void regmap_unlock_mutex(void *__map)
     514static void regmap_unlock_mutex(void *__map)
    485515{
    486516        struct regmap *map = __map;
     
    488518}
    489519
    490 /*static inline*/ void regmap_lock_spinlock(void *__map)
     520static void regmap_lock_spinlock(void *__map)
    491521__acquires(&map->spinlock)
    492522{
     
    498528}
    499529
    500 /*static inline*/ void regmap_unlock_spinlock(void *__map)
     530static void regmap_unlock_spinlock(void *__map)
    501531__releases(&map->spinlock)
    502532{
     
    505535}
    506536
    507 /*static inline*/ void dev_get_regmap_release(struct device *dev, void *res)
     537static void dev_get_regmap_release(struct device *dev, void *res)
    508538{
    509539        /*
     
    514544}
    515545
    516 /*static inline*/ bool _regmap_range_add(struct regmap *map,
     546static bool _regmap_range_add(struct regmap *map,
    517547                              struct regmap_range_node *data)
    518548{
     
    539569}
    540570
    541 /*static inline*/ struct regmap_range_node *_regmap_range_lookup(struct regmap *map,
     571static struct regmap_range_node *_regmap_range_lookup(struct regmap *map,
    542572                                                      unsigned int reg)
    543573{
     
    559589}
    560590
    561 /*static inline*/ void regmap_range_exit(struct regmap *map)
     591static void regmap_range_exit(struct regmap *map)
    562592{
    563593        struct rb_node *next;
     
    575605}
    576606
     607static int regmap_set_name(struct regmap *map, const struct regmap_config *config)
     608{
     609        if (config->name) {
     610#ifndef TARGET_OS2
     611                const char *name = kstrdup_const(config->name, GFP_KERNEL);
     612#else
     613                const char *name = config->name;
     614#endif
     615
     616                if (!name)
     617                        return -ENOMEM;
     618
     619#ifndef TARGET_OS2
     620                kfree_const(map->name);
     621#else
     622                kfree(map->name);
     623#endif
     624                map->name = name;
     625        }
     626
     627        return 0;
     628}
     629
    577630int regmap_attach_dev(struct device *dev, struct regmap *map,
    578631                      const struct regmap_config *config)
    579632{
    580633        struct regmap **m;
     634        int ret;
    581635
    582636        map->dev = dev;
    583637
    584         regmap_debugfs_init(map, config->name);
     638        ret = regmap_set_name(map, config);
     639        if (ret)
     640                return ret;
     641
     642        regmap_debugfs_init(map);
    585643
    586644        /* Add a devres resource for dev_get_regmap() */
     
    597655EXPORT_SYMBOL_GPL(regmap_attach_dev);
    598656
    599 /*static inline*/ enum regmap_endian regmap_get_reg_endian(const struct regmap_bus *bus,
     657static enum regmap_endian regmap_get_reg_endian(const struct regmap_bus *bus,
    600658                                        const struct regmap_config *config)
    601659{
     
    625683                                         const struct regmap_config *config)
    626684{
    627         struct device_node *np;
     685#ifndef TARGET_OS2
     686        struct fwnode_handle *fwnode = dev ? dev_fwnode(dev) : NULL;
     687#else
     688        struct fwnode_handle *fwnode = NULL;
     689#endif
    628690        enum regmap_endian endian;
    629691
     
    635697                return endian;
    636698
    637         /* If the dev and dev->of_node exist try to get endianness from DT */
    638         if (dev && dev->of_node) {
    639                 np = dev->of_node;
    640 
    641                 /* Parse the device's DT node for an endianness specification */
    642                 if (of_property_read_bool(np, "big-endian"))
    643                         endian = REGMAP_ENDIAN_BIG;
    644                 else if (of_property_read_bool(np, "little-endian"))
    645                         endian = REGMAP_ENDIAN_LITTLE;
    646                 else if (of_property_read_bool(np, "native-endian"))
    647                         endian = REGMAP_ENDIAN_NATIVE;
    648 
    649                 /* If the endianness was specified in DT, use that */
    650                 if (endian != REGMAP_ENDIAN_DEFAULT)
    651                         return endian;
    652         }
     699#ifndef TARGET_OS2
     700        /* If the firmware node exist try to get endianness from it */
     701        if (fwnode_property_read_bool(fwnode, "big-endian"))
     702                endian = REGMAP_ENDIAN_BIG;
     703        else if (fwnode_property_read_bool(fwnode, "little-endian"))
     704                endian = REGMAP_ENDIAN_LITTLE;
     705        else if (fwnode_property_read_bool(fwnode, "native-endian"))
     706                endian = REGMAP_ENDIAN_NATIVE;
     707#endif
     708        /* If the endianness was specified in fwnode, use that */
     709        if (endian != REGMAP_ENDIAN_DEFAULT)
     710                return endian;
    653711
    654712        /* Retrieve the endianness specification from the bus config */
     
    690748        }
    691749
    692         if (config->name) {
    693 #ifndef TARGET_OS2
    694                 map->name = kstrdup_const(config->name, GFP_KERNEL);
    695 #else
    696                 map->name = config->name;
    697 #endif
    698                 if (!map->name) {
    699                         ret = -ENOMEM;
    700                         goto err_map;
    701                 }
    702         }
     750        ret = regmap_set_name(map, config);
     751        if (ret)
     752                goto err_map;
     753
     754        ret = -EINVAL; /* Later error paths rely on this */
    703755
    704756        if (config->disable_locking) {
    705757                map->lock = map->unlock = regmap_lock_unlock_none;
     758                map->can_sleep = config->can_sleep;
    706759                regmap_debugfs_disable(map);
    707760        } else if (config->lock && config->unlock) {
     
    709762                map->unlock = config->unlock;
    710763                map->lock_arg = config->lock_arg;
     764                map->can_sleep = config->can_sleep;
    711765        } else if (config->use_hwlock) {
    712 //              map->hwlock = hwspin_lock_request_specific(config->hwlock_id);
    713 //              if (!map->hwlock) {
    714 //                      ret = -ENXIO;
    715 //                      goto err_name;
    716 //              }
    717 
     766#ifndef TARGET_OS2
     767                map->hwlock = hwspin_lock_request_specific(config->hwlock_id);
     768                if (!map->hwlock) {
     769                        ret = -ENXIO;
     770                        goto err_name;
     771                }
     772#endif
    718773                switch (config->hwlock_mode) {
    719774                case HWLOCK_IRQSTATE:
     
    744799                        map->lock = regmap_lock_mutex;
    745800                        map->unlock = regmap_unlock_mutex;
     801                        map->can_sleep = true;
    746802                        lockdep_set_class_and_name(&map->mutex,
    747803                                                   lock_key, lock_name);
     
    774830                map->reg_stride_order = -1;
    775831        map->use_single_read = config->use_single_read || !bus || !bus->read;
    776         map->use_single_write = config->use_single_read || !bus || !bus->write;
     832        map->use_single_write = config->use_single_write || !bus || !bus->write;
    777833        map->can_multi_write = config->can_multi_write && bus && bus->write;
    778834        if (bus) {
     
    788844        map->volatile_table = config->volatile_table;
    789845        map->precious_table = config->precious_table;
     846        map->wr_noinc_table = config->wr_noinc_table;
    790847        map->rd_noinc_table = config->rd_noinc_table;
    791848        map->writeable_reg = config->writeable_reg;
     
    793850        map->volatile_reg = config->volatile_reg;
    794851        map->precious_reg = config->precious_reg;
     852        map->writeable_noinc_reg = config->writeable_noinc_reg;
    795853        map->readable_noinc_reg = config->readable_noinc_reg;
    796854        map->cache_type = config->cache_type;
     
    819877                map->reg_read = _regmap_bus_reg_read;
    820878                map->reg_write = _regmap_bus_reg_write;
     879                map->reg_update_bits = bus->reg_update_bits;
    821880
    822881                map->defer_caching = false;
     
    865924                case 14:
    866925                        map->format.format_write = regmap_format_10_14_write;
     926                        break;
     927                default:
     928                        goto err_hwlock;
     929                }
     930                break;
     931
     932        case 12:
     933                switch (config->val_bits) {
     934                case 20:
     935                        map->format.format_write = regmap_format_12_20_write;
    867936                        break;
    868937                default:
     
    10481117        memset(&map->range_tree, 0, sizeof(struct rb_root));
    10491118#endif
    1050 
    10511119        for (i = 0; i < config->num_ranges; i++) {
    10521120                const struct regmap_range_cfg *range_cfg = &config->ranges[i];
     
    11481216                        goto err_regcache;
    11491217        } else {
    1150                 regmap_debugfs_init(map, config->name);
     1218                regmap_debugfs_init(map);
    11511219        }
    11521220
     
    11591227        kfree(map->work_buf);
    11601228err_hwlock:
    1161 //      if (map->hwlock)
    1162 //              hwspin_lock_free(map->hwlock);
    1163 //err_name:
    1164 //      kfree_const(map->name);
     1229#ifndef TARGET_OS2
     1230        if (map->hwlock)
     1231                hwspin_lock_free(map->hwlock);
     1232#endif
     1233err_name:
     1234#ifndef TARGET_OS2
     1235        kfree_const(map->name);
     1236#else
     1237        kfree(map->name);
     1238#endif
    11651239err_map:
    11661240        kfree(map);
     
    11711245
    11721246#ifndef TARGET_OS2
    1173 /*static inline*/ void devm_regmap_release(struct device *dev, void *res)
     1247static void devm_regmap_release(struct device *dev, void *res)
    11741248{
    11751249        regmap_exit(*(struct regmap **)res);
     
    12031277#endif
    12041278
    1205 /*static inline*/ void regmap_field_init(struct regmap_field *rm_field,
     1279static void regmap_field_init(struct regmap_field *rm_field,
    12061280        struct regmap *regmap, struct reg_field reg_field)
    12071281{
     
    12401314}
    12411315EXPORT_SYMBOL_GPL(devm_regmap_field_alloc);
     1316#endif
     1317
     1318/**
     1319 * regmap_field_bulk_alloc() - Allocate and initialise a bulk register field.
     1320 *
     1321 * @regmap: regmap bank in which this register field is located.
     1322 * @rm_field: regmap register fields within the bank.
     1323 * @reg_field: Register fields within the bank.
     1324 * @num_fields: Number of register fields.
     1325 *
     1326 * The return value will be an -ENOMEM on error or zero for success.
     1327 * Newly allocated regmap_fields should be freed by calling
     1328 * regmap_field_bulk_free()
     1329 */
     1330int regmap_field_bulk_alloc(struct regmap *regmap,
     1331                            struct regmap_field **rm_field,
     1332                            struct reg_field *reg_field,
     1333                            int num_fields)
     1334{
     1335        struct regmap_field *rf;
     1336        int i;
     1337
     1338        rf = kcalloc(num_fields, sizeof(*rf), GFP_KERNEL);
     1339        if (!rf)
     1340                return -ENOMEM;
     1341
     1342        for (i = 0; i < num_fields; i++) {
     1343                regmap_field_init(&rf[i], regmap, reg_field[i]);
     1344                rm_field[i] = &rf[i];
     1345        }
     1346
     1347        return 0;
     1348}
     1349EXPORT_SYMBOL_GPL(regmap_field_bulk_alloc);
     1350
     1351#ifndef TARGET_OS2
     1352/**
     1353 * devm_regmap_field_bulk_alloc() - Allocate and initialise a bulk register
     1354 * fields.
     1355 *
     1356 * @dev: Device that will be interacted with
     1357 * @regmap: regmap bank in which this register field is located.
     1358 * @rm_field: regmap register fields within the bank.
     1359 * @reg_field: Register fields within the bank.
     1360 * @num_fields: Number of register fields.
     1361 *
     1362 * The return value will be an -ENOMEM on error or zero for success.
     1363 * Newly allocated regmap_fields will be automatically freed by the
     1364 * device management code.
     1365 */
     1366int devm_regmap_field_bulk_alloc(struct device *dev,
     1367                                 struct regmap *regmap,
     1368                                 struct regmap_field **rm_field,
     1369                                 struct reg_field *reg_field,
     1370                                 int num_fields)
     1371{
     1372        struct regmap_field *rf;
     1373        int i;
     1374
     1375        rf = devm_kcalloc(dev, num_fields, sizeof(*rf), GFP_KERNEL);
     1376        if (!rf)
     1377                return -ENOMEM;
     1378
     1379        for (i = 0; i < num_fields; i++) {
     1380                regmap_field_init(&rf[i], regmap, reg_field[i]);
     1381                rm_field[i] = &rf[i];
     1382        }
     1383
     1384        return 0;
     1385}
     1386EXPORT_SYMBOL_GPL(devm_regmap_field_bulk_alloc);
     1387#endif
     1388
     1389/**
     1390 * regmap_field_bulk_free() - Free register field allocated using
     1391 *                       regmap_field_bulk_alloc.
     1392 *
     1393 * @field: regmap fields which should be freed.
     1394 */
     1395void regmap_field_bulk_free(struct regmap_field *field)
     1396{
     1397        kfree(field);
     1398}
     1399EXPORT_SYMBOL_GPL(regmap_field_bulk_free);
     1400
     1401#ifndef TARGET_OS2
     1402/**
     1403 * devm_regmap_field_bulk_free() - Free a bulk register field allocated using
     1404 *                            devm_regmap_field_bulk_alloc.
     1405 *
     1406 * @dev: Device that will be interacted with
     1407 * @field: regmap field which should be freed.
     1408 *
     1409 * Free register field allocated using devm_regmap_field_bulk_alloc(). Usually
     1410 * drivers need not call this function, as the memory allocated via devm
     1411 * will be freed as per device-driver life-cycle.
     1412 */
     1413void devm_regmap_field_bulk_free(struct device *dev,
     1414                                 struct regmap_field *field)
     1415{
     1416        devm_kfree(dev, field);
     1417}
     1418EXPORT_SYMBOL_GPL(devm_regmap_field_bulk_free);
    12421419
    12431420/**
     
    13121489int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config)
    13131490{
     1491        int ret;
     1492
    13141493        regcache_exit(map);
    13151494        regmap_debugfs_exit(map);
     
    13201499        map->volatile_reg = config->volatile_reg;
    13211500        map->precious_reg = config->precious_reg;
     1501        map->writeable_noinc_reg = config->writeable_noinc_reg;
    13221502        map->readable_noinc_reg = config->readable_noinc_reg;
    13231503        map->cache_type = config->cache_type;
    13241504
    1325         regmap_debugfs_init(map, config->name);
     1505        ret = regmap_set_name(map, config);
     1506        if (ret)
     1507                return ret;
     1508
     1509        regmap_debugfs_init(map);
    13261510
    13271511        map->cache_bypass = false;
     
    13551539                kfree(async);
    13561540        }
    1357 //      if (map->hwlock)
    1358 //              hwspin_lock_free(map->hwlock);
    1359 //      kfree_const(map->name);
     1541#ifndef TARGET_OS2
     1542        if (map->hwlock)
     1543                hwspin_lock_free(map->hwlock);
     1544#endif
     1545        if (map->lock == regmap_lock_mutex)
     1546                mutex_destroy(&map->mutex);
     1547#ifndef TARGET_OS2
     1548        kfree_const(map->name);
     1549#else
     1550        kfree(map->name);
     1551#endif
    13601552        kfree(map->patch);
    13611553        kfree(map);
     
    13631555EXPORT_SYMBOL_GPL(regmap_exit);
    13641556
    1365 /*static inline*/ int dev_get_regmap_match(struct device *dev, void *res, void *data)
     1557static int dev_get_regmap_match(struct device *dev, void *res, void *data)
    13661558{
    13671559        struct regmap **r = res;
     
    14141606EXPORT_SYMBOL_GPL(regmap_get_device);
    14151607
    1416 /*static inline*/ int _regmap_select_page(struct regmap *map, unsigned int *reg,
     1608static int _regmap_select_page(struct regmap *map, unsigned int *reg,
    14171609                               struct regmap_range_node *range,
    14181610                               unsigned int val_num)
     
    14621654}
    14631655
    1464 /*static inline*/ void regmap_set_work_buf_flag_mask(struct regmap *map, int max_bytes,
     1656static void regmap_set_work_buf_flag_mask(struct regmap *map, int max_bytes,
    14651657                                          unsigned long mask)
    14661658{
     
    14771669}
    14781670
    1479 /*static inline*/ int _regmap_raw_write_impl(struct regmap *map, unsigned int reg,
    1480                                   const void *val, size_t val_len)
     1671static int _regmap_raw_write_impl(struct regmap *map, unsigned int reg,
     1672                                  const void *val, size_t val_len, bool noinc)
    14811673{
    14821674        struct regmap_range_node *range;
     
    14911683        WARN_ON(!map->bus);
    14921684
    1493         /* Check for unwritable registers before we start */
    1494         if (map->writeable_reg)
    1495                 for (i = 0; i < val_len / map->format.val_bytes; i++)
    1496                         if (!map->writeable_reg(map->dev,
    1497                                                reg + regmap_get_offset(map, i)))
     1685        /* Check for unwritable or noinc registers in range
     1686         * before we start
     1687         */
     1688        if (!regmap_writeable_noinc(map, reg)) {
     1689                for (i = 0; i < val_len / map->format.val_bytes; i++) {
     1690                        unsigned int element =
     1691                                reg + regmap_get_offset(map, i);
     1692                        if (!regmap_writeable(map, element) ||
     1693                                regmap_writeable_noinc(map, element))
    14981694                                return -EINVAL;
     1695                }
     1696        }
    14991697
    15001698        if (!map->cache_bypass && map->format.parse_val) {
     
    15311729                        ret = _regmap_raw_write_impl(map, reg, val,
    15321730                                                     win_residue *
    1533                                                      map->format.val_bytes);
     1731                                                     map->format.val_bytes, noinc);
    15341732                        if (ret != 0)
    15351733                                return ret;
     
    15451743                }
    15461744
    1547                 ret = _regmap_select_page(map, &reg, range, val_num);
     1745                ret = _regmap_select_page(map, &reg, range, noinc ? 1 : val_num);
    15481746                if (ret != 0)
    15491747                        return ret;
     
    16981896EXPORT_SYMBOL_GPL(regmap_get_raw_write_max);
    16991897
    1700 /*static inline*/ int _regmap_bus_formatted_write(void *context, unsigned int reg,
     1898static int _regmap_bus_formatted_write(void *context, unsigned int reg,
    17011899                                       unsigned int val)
    17021900{
     
    17221920}
    17231921
    1724 /*static inline*/ int _regmap_bus_reg_write(void *context, unsigned int reg,
     1922static int _regmap_bus_reg_write(void *context, unsigned int reg,
    17251923                                 unsigned int val)
    17261924{
     
    17301928}
    17311929
    1732 /*static inline*/ int _regmap_bus_raw_write(void *context, unsigned int reg,
     1930static int _regmap_bus_raw_write(void *context, unsigned int reg,
    17331931                                 unsigned int val)
    17341932{
     
    17431941                                      map->format.reg_bytes +
    17441942                                      map->format.pad_bytes,
    1745                                       map->format.val_bytes);
    1746 }
    1747 
    1748 /*static inline*/ inline void *_regmap_map_get_context(struct regmap *map)
     1943                                      map->format.val_bytes,
     1944                                      false);
     1945}
     1946
     1947static inline void *_regmap_map_get_context(struct regmap *map)
    17491948{
    17501949        return (map->bus) ? map : map->bus_context;
     
    17701969        }
    17711970
    1772 #ifdef LOG_DEVICE
    1773         if (map->dev && strcmp(dev_name(map->dev), LOG_DEVICE) == 0)
     1971        if (regmap_should_log(map))
    17741972                dev_info(map->dev, "%x <= %x\n", reg, val);
     1973
     1974        return map->reg_write(context, reg, val);
     1975}
     1976
     1977#ifdef TARGET_OS2
     1978#define IS_ALIGNED(x, a)                (((x) & ((unsigned int)(a) - 1)) == 0)
    17751979#endif
    1776 
    1777         return map->reg_write(context, reg, val);
    1778 }
    1779 
    1780 #define IS_ALIGNED(x, a)                (((x) & ((unsigned int)(a) - 1)) == 0)
    17811980
    17821981/**
     
    18392038
    18402039int _regmap_raw_write(struct regmap *map, unsigned int reg,
    1841                       const void *val, size_t val_len)
     2040                      const void *val, size_t val_len, bool noinc)
    18422041{
    18432042        size_t val_bytes = map->format.val_bytes;
     
    18602059        /* Write as many bytes as possible with chunk_size */
    18612060        for (i = 0; i < chunk_count; i++) {
    1862                 ret = _regmap_raw_write_impl(map, reg, val, chunk_bytes);
     2061                ret = _regmap_raw_write_impl(map, reg, val, chunk_bytes, noinc);
    18632062                if (ret)
    18642063                        return ret;
     
    18712070        /* Write remaining bytes */
    18722071        if (val_len)
    1873                 ret = _regmap_raw_write_impl(map, reg, val, val_len);
     2072                ret = _regmap_raw_write_impl(map, reg, val, val_len, noinc);
    18742073
    18752074        return ret;
     
    19042103        map->lock(map->lock_arg);
    19052104
    1906         ret = _regmap_raw_write(map, reg, val, val_len);
     2105        ret = _regmap_raw_write(map, reg, val, val_len, false);
    19072106
    19082107        map->unlock(map->lock_arg);
     
    19112110}
    19122111EXPORT_SYMBOL_GPL(regmap_raw_write);
     2112
     2113/**
     2114 * regmap_noinc_write(): Write data from a register without incrementing the
     2115 *                      register number
     2116 *
     2117 * @map: Register map to write to
     2118 * @reg: Register to write to
     2119 * @val: Pointer to data buffer
     2120 * @val_len: Length of output buffer in bytes.
     2121 *
     2122 * The regmap API usually assumes that bulk bus write operations will write a
     2123 * range of registers. Some devices have certain registers for which a write
     2124 * operation can write to an internal FIFO.
     2125 *
     2126 * The target register must be volatile but registers after it can be
     2127 * completely unrelated cacheable registers.
     2128 *
     2129 * This will attempt multiple writes as required to write val_len bytes.
     2130 *
     2131 * A value of zero will be returned on success, a negative errno will be
     2132 * returned in error cases.
     2133 */
     2134int regmap_noinc_write(struct regmap *map, unsigned int reg,
     2135                      const void *val, size_t val_len)
     2136{
     2137        size_t write_len;
     2138        int ret;
     2139
     2140        if (!map->bus)
     2141                return -EINVAL;
     2142        if (!map->bus->write)
     2143                return -ENOTSUPP;
     2144        if (val_len % map->format.val_bytes)
     2145                return -EINVAL;
     2146        if (!IS_ALIGNED(reg, map->reg_stride))
     2147                return -EINVAL;
     2148        if (val_len == 0)
     2149                return -EINVAL;
     2150
     2151        map->lock(map->lock_arg);
     2152
     2153        if (!regmap_volatile(map, reg) || !regmap_writeable_noinc(map, reg)) {
     2154                ret = -EINVAL;
     2155                goto out_unlock;
     2156        }
     2157
     2158        while (val_len) {
     2159                if (map->max_raw_write && map->max_raw_write < val_len)
     2160                        write_len = map->max_raw_write;
     2161                else
     2162                        write_len = val_len;
     2163                ret = _regmap_raw_write(map, reg, val, write_len, true);
     2164                if (ret)
     2165                        goto out_unlock;
     2166                val = ((u8 *)val) + write_len;
     2167                val_len -= write_len;
     2168        }
     2169
     2170out_unlock:
     2171        map->unlock(map->lock_arg);
     2172        return ret;
     2173}
     2174EXPORT_SYMBOL_GPL(regmap_noinc_write);
    19132175
    19142176/**
     
    19562218 * be returned in error cases.
    19572219 */
    1958 int regmap_fields_update_bits_base(struct regmap_field *field,  unsigned int id,
     2220int regmap_fields_update_bits_base(struct regmap_field *field, unsigned int id,
    19592221                                   unsigned int mask, unsigned int val,
    19602222                                   bool *change, bool async, bool force)
     
    20572319 * relative. The page register has been written if that was necessary.
    20582320 */
    2059 /*static inline*/ int _regmap_raw_multi_reg_write(struct regmap *map,
     2321static int _regmap_raw_multi_reg_write(struct regmap *map,
    20602322                                       const struct reg_sequence *regs,
    20612323                                       size_t num_regs)
     
    20982360
    20992361        for (i = 0; i < num_regs; i++) {
    2100                 int reg;
    2101                 reg = regs[i].reg;
     2362                int reg = regs[i].reg;
    21022363        }
    21032364        return ret;
    21042365}
    21052366
    2106 /*static inline*/ unsigned int _regmap_register_page(struct regmap *map,
     2367static unsigned int _regmap_register_page(struct regmap *map,
    21072368                                          unsigned int reg,
    21082369                                          struct regmap_range_node *range)
     
    21132374}
    21142375
    2115 /*static inline*/ int _regmap_range_multi_paged_reg_write(struct regmap *map,
     2376static int _regmap_range_multi_paged_reg_write(struct regmap *map,
    21162377                                               struct reg_sequence *regs,
    21172378                                               size_t num_regs)
     
    21662427                                        return ret;
    21672428
    2168                                 if (regs[i].delay_us)
    2169                                         udelay(regs[i].delay_us);
     2429                                if (regs[i].delay_us) {
     2430#ifndef TARGET_OS2
     2431                                        if (map->can_sleep)
     2432                                                fsleep(regs[i].delay_us);
     2433                                        else
     2434#endif
     2435                                                udelay(regs[i].delay_us);
     2436                                }
    21702437
    21712438                                base += n;
     
    21902457}
    21912458
    2192 /*static inline*/ int _regmap_multi_reg_write(struct regmap *map,
     2459static int _regmap_multi_reg_write(struct regmap *map,
    21932460                                   const struct reg_sequence *regs,
    21942461                                   size_t num_regs)
     
    22032470                                return ret;
    22042471
    2205                         if (regs[i].delay_us)
    2206                                 udelay(regs[i].delay_us);
     2472                        if (regs[i].delay_us) {
     2473#ifndef TARGET_OS2
     2474                                if (map->can_sleep)
     2475                                        fsleep(regs[i].delay_us);
     2476                                else
     2477#endif
     2478                                        udelay(regs[i].delay_us);
     2479                        }
    22072480                }
    22082481                return 0;
     
    23752648        map->async = true;
    23762649
    2377         ret = _regmap_raw_write(map, reg, val, val_len);
     2650        ret = _regmap_raw_write(map, reg, val, val_len, false);
    23782651
    23792652        map->async = false;
     
    23852658EXPORT_SYMBOL_GPL(regmap_raw_write_async);
    23862659
    2387 /*static inline*/ int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
     2660static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
    23882661                            unsigned int val_len, bool noinc)
    23892662{
     
    24152688}
    24162689
    2417 /*static inline*/ int _regmap_bus_reg_read(void *context, unsigned int reg,
     2690static int _regmap_bus_reg_read(void *context, unsigned int reg,
    24182691                                unsigned int *val)
    24192692{
     
    24232696}
    24242697
    2425 /*static inline*/ int _regmap_bus_read(void *context, unsigned int reg,
     2698static int _regmap_bus_read(void *context, unsigned int reg,
    24262699                            unsigned int *val)
    24272700{
     
    24412714}
    24422715
    2443 /*static inline*/ int _regmap_read(struct regmap *map, unsigned int reg,
     2716static int _regmap_read(struct regmap *map, unsigned int reg,
    24442717                        unsigned int *val)
    24452718{
     
    24612734        ret = map->reg_read(context, reg, val);
    24622735        if (ret == 0) {
    2463 #ifdef LOG_DEVICE
    2464                 if (map->dev && strcmp(dev_name(map->dev), LOG_DEVICE) == 0)
     2736                if (regmap_should_log(map))
    24652737                        dev_info(map->dev, "%x => %x\n", reg, *val);
    2466 #endif
    24672738
    24682739                if (!map->cache_bypass)
     
    27843055EXPORT_SYMBOL_GPL(regmap_bulk_read);
    27853056
    2786 /*static inline*/ int _regmap_update_bits(struct regmap *map, unsigned int reg,
     3057static int _regmap_update_bits(struct regmap *map, unsigned int reg,
    27873058                               unsigned int mask, unsigned int val,
    27883059                               bool *change, bool force_write)
     
    28583129EXPORT_SYMBOL_GPL(regmap_update_bits_base);
    28593130
     3131/**
     3132 * regmap_test_bits() - Check if all specified bits are set in a register.
     3133 *
     3134 * @map: Register map to operate on
     3135 * @reg: Register to read from
     3136 * @bits: Bits to test
     3137 *
     3138 * Returns 0 if at least one of the tested bits is not set, 1 if all tested
     3139 * bits are set and a negative error number if the underlying regmap_read()
     3140 * fails.
     3141 */
     3142int regmap_test_bits(struct regmap *map, unsigned int reg, unsigned int bits)
     3143{
     3144        unsigned int val, ret;
     3145
     3146        ret = regmap_read(map, reg, &val);
     3147        if (ret)
     3148                return ret;
     3149
     3150        return (val & bits) == bits;
     3151}
     3152EXPORT_SYMBOL_GPL(regmap_test_bits);
     3153
    28603154void regmap_async_complete_cb(struct regmap_async *async, int ret)
    28613155{
     
    28773171EXPORT_SYMBOL_GPL(regmap_async_complete_cb);
    28783172
    2879 /*static inline*/ int regmap_async_is_done(struct regmap *map)
     3173static int regmap_async_is_done(struct regmap *map)
    28803174{
    28813175        unsigned long flags;
     
    29063200                return 0;
    29073201
    2908 //      wait_event(map->async_waitq, regmap_async_is_done(map));
    2909 
     3202#ifndef TARGET_OS2
     3203        wait_event(map->async_waitq, regmap_async_is_done(map));
     3204#endif
    29103205        spin_lock_irqsave(&map->async_lock, flags);
    29113206        ret = map->async_ret;
     
    29413236        bool bypass;
    29423237
    2943 #if 0
     3238#ifndef TARGET_OS2
    29443239        if (WARN_ONCE(num_regs <= 0, "invalid registers number (%d)\n",
    29453240            num_regs))
    29463241                return 0;
     3242#else
     3243        if (num_regs <= 0) {
     3244                pr_warn("invalid registers number (%d)", num_regs);
     3245                return 0;
     3246        }
    29473247#endif
    29483248        p = krealloc(map->patch,
     
    30343334EXPORT_SYMBOL_GPL(regmap_parse_val);
    30353335
    3036 /*static inline*/ int __init regmap_initcall(void)
     3336static int __init regmap_initcall(void)
    30373337{
    30383338        regmap_debugfs_initcall();
Note: See TracChangeset for help on using the changeset viewer.