Ignore:
Timestamp:
Jan 3, 2021, 7:20:20 AM (5 years ago)
Author:
Paul Smedley
Message:

Code cleanups to simplify future maintenance, update regmap/regcache/rbtree to linux 4.19.163 level

File:
1 edited

Legend:

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

    r621 r625  
    1010 * published by the Free Software Foundation.
    1111 */
    12 /* from 4.14.202 */
     12/* from 4.19.163 */
    1313
    1414#include <linux/device.h>
     
    2222#include <linux/delay.h>
    2323#include <linux/log2.h>
     24//#include <linux/hwspinlock.h>
     25#include <asm/unaligned.h>
    2426#include <linux/module.h>
    2527#include <linux/workqueue.h>
    2628#include <linux/byteorder/little_endian.h>
    2729#include <linux/printk.h>
     30
     31/* hwspinlock mode argument */
     32#define HWLOCK_IRQSTATE 0x01    /* Disable interrupts, save state */
     33#define HWLOCK_IRQ      0x02    /* Disable interrupts, don't save state */
     34#define HWLOCK_RAW      0x03
    2835
    2936#define CREATE_TRACE_POINTS
     
    4047#undef LOG_DEVICE
    4148
    42 static int _regmap_update_bits(struct regmap *map, unsigned int reg,
     49/*static inline*/ int _regmap_update_bits(struct regmap *map, unsigned int reg,
    4350                               unsigned int mask, unsigned int val,
    4451                               bool *change, bool force_write);
    4552
    46 static int _regmap_bus_reg_read(void *context, unsigned int reg,
     53/*static inline*/ int _regmap_bus_reg_read(void *context, unsigned int reg,
    4754                                unsigned int *val);
    48 static int _regmap_bus_read(void *context, unsigned int reg,
     55/*static inline*/ int _regmap_bus_read(void *context, unsigned int reg,
    4956                            unsigned int *val);
    50 static int _regmap_bus_formatted_write(void *context, unsigned int reg,
     57/*static inline*/ int _regmap_bus_formatted_write(void *context, unsigned int reg,
    5158                                       unsigned int val);
    52 static int _regmap_bus_reg_write(void *context, unsigned int reg,
     59/*static inline*/ int _regmap_bus_reg_write(void *context, unsigned int reg,
    5360                                 unsigned int val);
    54 static int _regmap_bus_raw_write(void *context, unsigned int reg,
     61/*static inline*/ int _regmap_bus_raw_write(void *context, unsigned int reg,
    5562                                 unsigned int val);
    5663
     
    173180}
    174181
    175 static bool regmap_volatile_range(struct regmap *map, unsigned int reg,
     182bool regmap_readable_noinc(struct regmap *map, unsigned int reg)
     183{
     184        if (map->readable_noinc_reg)
     185                return map->readable_noinc_reg(map->dev, reg);
     186
     187        if (map->rd_noinc_table)
     188                return regmap_check_range_table(map, reg, map->rd_noinc_table);
     189
     190        return true;
     191}
     192
     193/*static inline*/ bool regmap_volatile_range(struct regmap *map, unsigned int reg,
    176194        size_t num)
    177195{
     
    179197
    180198        for (i = 0; i < num; i++)
    181                 if (!regmap_volatile(map, reg + i))
     199                if (!regmap_volatile(map, reg + regmap_get_offset(map, i)))
    182200                        return false;
    183201
     
    185203}
    186204
    187 static void regmap_format_2_6_write(struct regmap *map,
     205/*static inline*/ void regmap_format_2_6_write(struct regmap *map,
    188206                                     unsigned int reg, unsigned int val)
    189207{
     
    193211}
    194212
    195 static void regmap_format_4_12_write(struct regmap *map,
     213/*static inline*/ void regmap_format_4_12_write(struct regmap *map,
    196214                                     unsigned int reg, unsigned int val)
    197215{
     
    200218}
    201219
    202 static void regmap_format_7_9_write(struct regmap *map,
     220/*static inline*/ void regmap_format_7_9_write(struct regmap *map,
    203221                                    unsigned int reg, unsigned int val)
    204222{
     
    207225}
    208226
    209 static void regmap_format_10_14_write(struct regmap *map,
     227/*static inline*/ void regmap_format_10_14_write(struct regmap *map,
    210228                                    unsigned int reg, unsigned int val)
    211229{
     
    217235}
    218236
    219 static void regmap_format_8(void *buf, unsigned int val, unsigned int shift)
     237/*static inline*/ void regmap_format_8(void *buf, unsigned int val, unsigned int shift)
    220238{
    221239        u8 *b = buf;
     
    224242}
    225243
    226 static void regmap_format_16_be(void *buf, unsigned int val, unsigned int shift)
    227 {
    228         __be16 *b = buf;
    229 
    230         b[0] = cpu_to_be16(val << shift);
    231 }
    232 
    233 static void regmap_format_16_le(void *buf, unsigned int val, unsigned int shift)
    234 {
    235         __le16 *b = buf;
    236 
    237         b[0] = cpu_to_le16(val << shift);
    238 }
    239 
    240 static void regmap_format_16_native(void *buf, unsigned int val,
     244/*static inline*/ void regmap_format_16_be(void *buf, unsigned int val, unsigned int shift)
     245{
     246        put_unaligned_be16(val << shift, buf);
     247}
     248
     249/*static inline*/ void regmap_format_16_le(void *buf, unsigned int val, unsigned int shift)
     250{
     251        put_unaligned_le16(val << shift, buf);
     252}
     253
     254/*static inline*/ void regmap_format_16_native(void *buf, unsigned int val,
    241255                                    unsigned int shift)
    242256{
    243         *(u16 *)buf = val << shift;
    244 }
    245 
    246 static void regmap_format_24(void *buf, unsigned int val, unsigned int shift)
     257        u16 v = val << shift;
     258
     259        memcpy(buf, &v, sizeof(v));
     260}
     261
     262/*static inline*/ void regmap_format_24(void *buf, unsigned int val, unsigned int shift)
    247263{
    248264        u8 *b = buf;
     
    255271}
    256272
    257 static void regmap_format_32_be(void *buf, unsigned int val, unsigned int shift)
    258 {
    259         __be32 *b = buf;
    260 
    261         b[0] = cpu_to_be32(val << shift);
    262 }
    263 
    264 static void regmap_format_32_le(void *buf, unsigned int val, unsigned int shift)
    265 {
    266         __le32 *b = buf;
    267 
    268         b[0] = cpu_to_le32(val << shift);
    269 }
    270 
    271 static void regmap_format_32_native(void *buf, unsigned int val,
     273/*static inline*/ void regmap_format_32_be(void *buf, unsigned int val, unsigned int shift)
     274{
     275        put_unaligned_be32(val << shift, buf);
     276}
     277
     278/*static inline*/ void regmap_format_32_le(void *buf, unsigned int val, unsigned int shift)
     279{
     280        put_unaligned_le32(val << shift, buf);
     281}
     282
     283/*static inline*/ void regmap_format_32_native(void *buf, unsigned int val,
    272284                                    unsigned int shift)
    273285{
    274         *(u32 *)buf = val << shift;
     286        u32 v = val << shift;
     287
     288        memcpy(buf, &v, sizeof(v));
    275289}
    276290
    277291#ifdef CONFIG_64BIT
    278 static void regmap_format_64_be(void *buf, unsigned int val, unsigned int shift)
    279 {
    280         __be64 *b = buf;
    281 
    282         b[0] = cpu_to_be64((u64)val << shift);
    283 }
    284 
    285 static void regmap_format_64_le(void *buf, unsigned int val, unsigned int shift)
    286 {
    287         __le64 *b = buf;
    288 
    289         b[0] = cpu_to_le64((u64)val << shift);
    290 }
    291 
    292 static void regmap_format_64_native(void *buf, unsigned int val,
     292/*static inline*/ void regmap_format_64_be(void *buf, unsigned int val, unsigned int shift)
     293{
     294        put_unaligned_be64((u64) val << shift, buf);
     295}
     296
     297/*static inline*/ void regmap_format_64_le(void *buf, unsigned int val, unsigned int shift)
     298{
     299        put_unaligned_le64((u64) val << shift, buf);
     300}
     301
     302/*static inline*/ void regmap_format_64_native(void *buf, unsigned int val,
    293303                                    unsigned int shift)
    294304{
    295         *(u64 *)buf = (u64)val << shift;
     305        u64 v = (u64) val << shift;
     306
     307        memcpy(buf, &v, sizeof(v));
    296308}
    297309#endif
    298310
    299 static void regmap_parse_inplace_noop(void *buf)
    300 {
    301 }
    302 
    303 static unsigned int regmap_parse_8(const void *buf)
     311/*static inline*/ void regmap_parse_inplace_noop(void *buf)
     312{
     313}
     314
     315/*static inline*/ unsigned int regmap_parse_8(const void *buf)
    304316{
    305317        const u8 *b = buf;
     
    308320}
    309321
    310 static unsigned int regmap_parse_16_be(const void *buf)
    311 {
    312         const __be16 *b = buf;
    313 
    314         return be16_to_cpu(b[0]);
    315 }
    316 
    317 static unsigned int regmap_parse_16_le(const void *buf)
    318 {
    319         const __le16 *b = buf;
    320 
    321         return le16_to_cpu(b[0]);
    322 }
    323 
    324 static void regmap_parse_16_be_inplace(void *buf)
    325 {
    326         __be16 *b = buf;
    327 
    328         b[0] = be16_to_cpu(b[0]);
    329 }
    330 
    331 static void regmap_parse_16_le_inplace(void *buf)
    332 {
    333         __le16 *b = buf;
    334 
    335         b[0] = le16_to_cpu(b[0]);
    336 }
    337 
    338 static unsigned int regmap_parse_16_native(const void *buf)
    339 {
    340         return *(u16 *)buf;
    341 }
    342 
    343 static unsigned int regmap_parse_24(const void *buf)
     322/*static inline*/ unsigned int regmap_parse_16_be(const void *buf)
     323{
     324        return get_unaligned_be16(buf);
     325}
     326
     327/*static inline*/ unsigned int regmap_parse_16_le(const void *buf)
     328{
     329        return get_unaligned_le16(buf);
     330}
     331
     332/*static inline*/ void regmap_parse_16_be_inplace(void *buf)
     333{
     334        u16 v = get_unaligned_be16(buf);
     335
     336        memcpy(buf, &v, sizeof(v));
     337}
     338
     339/*static inline*/ void regmap_parse_16_le_inplace(void *buf)
     340{
     341        u16 v = get_unaligned_le16(buf);
     342
     343        memcpy(buf, &v, sizeof(v));
     344}
     345
     346/*static inline*/ unsigned int regmap_parse_16_native(const void *buf)
     347{
     348        u16 v;
     349
     350        memcpy(&v, buf, sizeof(v));
     351        return v;
     352}
     353
     354/*static inline*/ unsigned int regmap_parse_24(const void *buf)
    344355{
    345356        const u8 *b = buf;
     
    351362}
    352363
    353 static unsigned int regmap_parse_32_be(const void *buf)
    354 {
    355         const __be32 *b = buf;
    356 
    357         return be32_to_cpu(b[0]);
    358 }
    359 
    360 static unsigned int regmap_parse_32_le(const void *buf)
    361 {
    362         const __le32 *b = buf;
    363 
    364         return le32_to_cpu(b[0]);
    365 }
    366 
    367 static void regmap_parse_32_be_inplace(void *buf)
    368 {
    369         __be32 *b = buf;
    370 
    371         b[0] = be32_to_cpu(b[0]);
    372 }
    373 
    374 static void regmap_parse_32_le_inplace(void *buf)
    375 {
    376         __le32 *b = buf;
    377 
    378         b[0] = le32_to_cpu(b[0]);
    379 }
    380 
    381 static unsigned int regmap_parse_32_native(const void *buf)
    382 {
    383         return *(u32 *)buf;
     364/*static inline*/ unsigned int regmap_parse_32_be(const void *buf)
     365{
     366        return get_unaligned_be32(buf);
     367}
     368
     369/*static inline*/ unsigned int regmap_parse_32_le(const void *buf)
     370{
     371        return get_unaligned_le32(buf);
     372}
     373
     374/*static inline*/ void regmap_parse_32_be_inplace(void *buf)
     375{
     376        u32 v = get_unaligned_be32(buf);
     377
     378        memcpy(buf, &v, sizeof(v));
     379}
     380
     381/*static inline*/ void regmap_parse_32_le_inplace(void *buf)
     382{
     383        u32 v = get_unaligned_le32(buf);
     384
     385        memcpy(buf, &v, sizeof(v));
     386}
     387
     388/*static inline*/ unsigned int regmap_parse_32_native(const void *buf)
     389{
     390        u32 v;
     391
     392        memcpy(&v, buf, sizeof(v));
     393        return v;
    384394}
    385395
    386396#ifdef CONFIG_64BIT
    387 static unsigned int regmap_parse_64_be(const void *buf)
    388 {
    389         const __be64 *b = buf;
    390 
    391         return be64_to_cpu(b[0]);
    392 }
    393 
    394 static unsigned int regmap_parse_64_le(const void *buf)
    395 {
    396         const __le64 *b = buf;
    397 
    398         return le64_to_cpu(b[0]);
    399 }
    400 
    401 static void regmap_parse_64_be_inplace(void *buf)
    402 {
    403         __be64 *b = buf;
    404 
    405         b[0] = be64_to_cpu(b[0]);
    406 }
    407 
    408 static void regmap_parse_64_le_inplace(void *buf)
    409 {
    410         __le64 *b = buf;
    411 
    412         b[0] = le64_to_cpu(b[0]);
    413 }
    414 
    415 static unsigned int regmap_parse_64_native(const void *buf)
    416 {
    417         return *(u64 *)buf;
     397/*static inline*/ unsigned int regmap_parse_64_be(const void *buf)
     398{
     399        return get_unaligned_be64(buf);
     400}
     401
     402/*static inline*/ unsigned int regmap_parse_64_le(const void *buf)
     403{
     404        return get_unaligned_le64(buf);
     405}
     406
     407/*static inline*/ void regmap_parse_64_be_inplace(void *buf)
     408{
     409        u64 v =  get_unaligned_be64(buf);
     410
     411        memcpy(buf, &v, sizeof(v));
     412}
     413
     414/*static inline*/ void regmap_parse_64_le_inplace(void *buf)
     415{
     416        u64 v = get_unaligned_le64(buf);
     417
     418        memcpy(buf, &v, sizeof(v));
     419}
     420
     421/*static inline*/ unsigned int regmap_parse_64_native(const void *buf)
     422{
     423        u64 v;
     424
     425        memcpy(&v, buf, sizeof(v));
     426        return v;
    418427}
    419428#endif
    420429
    421 static void regmap_lock_mutex(void *__map)
     430/*static inline*/ void regmap_lock_hwlock(void *__map)
     431{
     432        struct regmap *map = __map;
     433
     434//      hwspin_lock_timeout(map->hwlock, UINT_MAX);
     435}
     436
     437/*static inline*/ void regmap_lock_hwlock_irq(void *__map)
     438{
     439        struct regmap *map = __map;
     440
     441//      hwspin_lock_timeout_irq(map->hwlock, UINT_MAX);
     442}
     443
     444/*static inline*/ void regmap_lock_hwlock_irqsave(void *__map)
     445{
     446        struct regmap *map = __map;
     447
     448//      hwspin_lock_timeout_irqsave(map->hwlock, UINT_MAX,
     449//                                  &map->spinlock_flags);
     450}
     451
     452/*static inline*/ void regmap_unlock_hwlock(void *__map)
     453{
     454        struct regmap *map = __map;
     455
     456//      hwspin_unlock(map->hwlock);
     457}
     458
     459/*static inline*/ void regmap_unlock_hwlock_irq(void *__map)
     460{
     461        struct regmap *map = __map;
     462
     463//      hwspin_unlock_irq(map->hwlock);
     464}
     465
     466/*static inline*/ void regmap_unlock_hwlock_irqrestore(void *__map)
     467{
     468        struct regmap *map = __map;
     469
     470//      hwspin_unlock_irqrestore(map->hwlock, &map->spinlock_flags);
     471}
     472
     473/*static inline*/ void regmap_lock_unlock_none(void *__map)
     474{
     475
     476}
     477
     478/*static inline*/ void regmap_lock_mutex(void *__map)
    422479{
    423480        struct regmap *map = __map;
     
    425482}
    426483
    427 static void regmap_unlock_mutex(void *__map)
     484/*static inline*/ void regmap_unlock_mutex(void *__map)
    428485{
    429486        struct regmap *map = __map;
     
    431488}
    432489
    433 static void regmap_lock_spinlock(void *__map)
     490/*static inline*/ void regmap_lock_spinlock(void *__map)
    434491__acquires(&map->spinlock)
    435492{
     
    441498}
    442499
    443 static void regmap_unlock_spinlock(void *__map)
     500/*static inline*/ void regmap_unlock_spinlock(void *__map)
    444501__releases(&map->spinlock)
    445502{
     
    448505}
    449506
    450 static void dev_get_regmap_release(struct device *dev, void *res)
     507/*static inline*/ void dev_get_regmap_release(struct device *dev, void *res)
    451508{
    452509        /*
     
    457514}
    458515
    459 static bool _regmap_range_add(struct regmap *map,
     516/*static inline*/ bool _regmap_range_add(struct regmap *map,
    460517                              struct regmap_range_node *data)
    461518{
     
    482539}
    483540
    484 static struct regmap_range_node *_regmap_range_lookup(struct regmap *map,
     541/*static inline*/ struct regmap_range_node *_regmap_range_lookup(struct regmap *map,
    485542                                                      unsigned int reg)
    486543{
     
    502559}
    503560
    504 static void regmap_range_exit(struct regmap *map)
     561/*static inline*/ void regmap_range_exit(struct regmap *map)
    505562{
    506563        struct rb_node *next;
     
    540597EXPORT_SYMBOL_GPL(regmap_attach_dev);
    541598
    542 static enum regmap_endian regmap_get_reg_endian(const struct regmap_bus *bus,
     599/*static inline*/ enum regmap_endian regmap_get_reg_endian(const struct regmap_bus *bus,
    543600                                        const struct regmap_config *config)
    544601{
     
    633690        }
    634691
    635         if (config->lock && config->unlock) {
     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        }
     703
     704        if (config->disable_locking) {
     705                map->lock = map->unlock = regmap_lock_unlock_none;
     706                regmap_debugfs_disable(map);
     707        } else if (config->lock && config->unlock) {
    636708                map->lock = config->lock;
    637709                map->unlock = config->unlock;
    638710                map->lock_arg = config->lock_arg;
     711        } 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
     718                switch (config->hwlock_mode) {
     719                case HWLOCK_IRQSTATE:
     720                        map->lock = regmap_lock_hwlock_irqsave;
     721                        map->unlock = regmap_unlock_hwlock_irqrestore;
     722                        break;
     723                case HWLOCK_IRQ:
     724                        map->lock = regmap_lock_hwlock_irq;
     725                        map->unlock = regmap_unlock_hwlock_irq;
     726                        break;
     727                default:
     728                        map->lock = regmap_lock_hwlock;
     729                        map->unlock = regmap_unlock_hwlock;
     730                        break;
     731                }
     732
     733                map->lock_arg = map;
    639734        } else {
    640735                if ((bus && bus->fast_io) ||
     
    693788        map->volatile_table = config->volatile_table;
    694789        map->precious_table = config->precious_table;
     790        map->rd_noinc_table = config->rd_noinc_table;
    695791        map->writeable_reg = config->writeable_reg;
    696792        map->readable_reg = config->readable_reg;
    697793        map->volatile_reg = config->volatile_reg;
    698794        map->precious_reg = config->precious_reg;
     795        map->readable_noinc_reg = config->readable_noinc_reg;
    699796        map->cache_type = config->cache_type;
    700         map->name = config->name;
    701797
    702798        spin_lock_init(&map->async_lock);
     
    705801        init_waitqueue_head(&map->async_waitq);
    706802
    707         if (config->read_flag_mask || config->write_flag_mask) {
     803        if (config->read_flag_mask ||
     804            config->write_flag_mask ||
     805            config->zero_flag_mask) {
    708806                map->read_flag_mask = config->read_flag_mask;
    709807                map->write_flag_mask = config->write_flag_mask;
     
    739837                        break;
    740838                default:
    741                         goto err_map;
     839                        goto err_hwlock;
    742840                }
    743841                break;
     
    749847                        break;
    750848                default:
    751                         goto err_map;
     849                        goto err_hwlock;
    752850                }
    753851                break;
     
    759857                        break;
    760858                default:
    761                         goto err_map;
     859                        goto err_hwlock;
    762860                }
    763861                break;
     
    769867                        break;
    770868                default:
    771                         goto err_map;
     869                        goto err_hwlock;
    772870                }
    773871                break;
     
    789887                        break;
    790888                default:
    791                         goto err_map;
     889                        goto err_hwlock;
    792890                }
    793891                break;
     
    795893        case 24:
    796894                if (reg_endian != REGMAP_ENDIAN_BIG)
    797                         goto err_map;
     895                        goto err_hwlock;
    798896                map->format.format_reg = regmap_format_24;
    799897                break;
     
    811909                        break;
    812910                default:
    813                         goto err_map;
     911                        goto err_hwlock;
    814912                }
    815913                break;
     
    828926                        break;
    829927                default:
    830                         goto err_map;
     928                        goto err_hwlock;
    831929                }
    832930                break;
     
    834932
    835933        default:
    836                 goto err_map;
     934                goto err_hwlock;
    837935        }
    838936
     
    863961                        break;
    864962                default:
    865                         goto err_map;
     963                        goto err_hwlock;
    866964                }
    867965                break;
    868966        case 24:
    869967                if (val_endian != REGMAP_ENDIAN_BIG)
    870                         goto err_map;
     968                        goto err_hwlock;
    871969                map->format.format_val = regmap_format_24;
    872970                map->format.parse_val = regmap_parse_24;
     
    889987                        break;
    890988                default:
    891                         goto err_map;
     989                        goto err_hwlock;
    892990                }
    893991                break;
     
    9101008                        break;
    9111009                default:
    912                         goto err_map;
     1010                        goto err_hwlock;
    9131011                }
    9141012                break;
     
    9191017                if ((reg_endian != REGMAP_ENDIAN_BIG) ||
    9201018                    (val_endian != REGMAP_ENDIAN_BIG))
    921                         goto err_map;
     1019                        goto err_hwlock;
    9221020                map->use_single_write = true;
    9231021        }
     
    9251023        if (!map->format.format_write &&
    9261024            !(map->format.format_reg && map->format.format_val))
    927                 goto err_map;
     1025                goto err_hwlock;
    9281026
    9291027        map->work_buf = kzalloc(map->format.buf_size, GFP_KERNEL);
    9301028        if (map->work_buf == NULL) {
    9311029                ret = -ENOMEM;
    932                 goto err_map;
     1030                goto err_hwlock;
    9331031        }
    9341032
     
    10471145        if (dev) {
    10481146                ret = regmap_attach_dev(dev, map, config);
    1049 
    10501147                if (ret != 0)
    10511148                        goto err_regcache;
     1149        } else {
     1150                regmap_debugfs_init(map, config->name);
    10521151        }
    10531152
     
    10591158        regmap_range_exit(map);
    10601159        kfree(map->work_buf);
     1160err_hwlock:
     1161//      if (map->hwlock)
     1162//              hwspin_lock_free(map->hwlock);
     1163err_name:
     1164//      kfree_const(map->name);
    10611165err_map:
    10621166        kfree(map);
     
    10671171
    10681172#ifndef TARGET_OS2
    1069 static void devm_regmap_release(struct device *dev, void *res)
     1173/*static inline*/ void devm_regmap_release(struct device *dev, void *res)
    10701174{
    10711175        regmap_exit(*(struct regmap **)res);
     
    10991203#endif
    11001204
    1101 static void regmap_field_init(struct regmap_field *rm_field,
     1205/*static inline*/ void regmap_field_init(struct regmap_field *rm_field,
    11021206        struct regmap *regmap, struct reg_field reg_field)
    11031207{
     
    12161320        map->volatile_reg = config->volatile_reg;
    12171321        map->precious_reg = config->precious_reg;
     1322        map->readable_noinc_reg = config->readable_noinc_reg;
    12181323        map->cache_type = config->cache_type;
    12191324
     
    12501355                kfree(async);
    12511356        }
     1357//      if (map->hwlock)
     1358//              hwspin_lock_free(map->hwlock);
     1359//      kfree_const(map->name);
     1360        kfree(map->patch);
    12521361        kfree(map);
    12531362}
    12541363EXPORT_SYMBOL_GPL(regmap_exit);
    12551364
    1256 static int dev_get_regmap_match(struct device *dev, void *res, void *data)
     1365/*static inline*/ int dev_get_regmap_match(struct device *dev, void *res, void *data)
    12571366{
    12581367        struct regmap **r = res;
     
    13051414EXPORT_SYMBOL_GPL(regmap_get_device);
    13061415
    1307 static int _regmap_select_page(struct regmap *map, unsigned int *reg,
     1416/*static inline*/ int _regmap_select_page(struct regmap *map, unsigned int *reg,
    13081417                               struct regmap_range_node *range,
    13091418                               unsigned int val_num)
     
    13531462}
    13541463
    1355 static void regmap_set_work_buf_flag_mask(struct regmap *map, int max_bytes,
     1464/*static inline*/ void regmap_set_work_buf_flag_mask(struct regmap *map, int max_bytes,
    13561465                                          unsigned long mask)
    13571466{
     
    13681477}
    13691478
    1370 int _regmap_raw_write(struct regmap *map, unsigned int reg,
    1371                       const void *val, size_t val_len)
     1479/*static inline*/ int _regmap_raw_write_impl(struct regmap *map, unsigned int reg,
     1480                                  const void *val, size_t val_len)
    13721481{
    13731482        struct regmap_range_node *range;
     
    14201529                        dev_dbg(map->dev, "Writing window %d/%zu\n",
    14211530                                win_residue, val_len / map->format.val_bytes);
    1422                         ret = _regmap_raw_write(map, reg, val, win_residue *
    1423                                                 map->format.val_bytes);
     1531                        ret = _regmap_raw_write_impl(map, reg, val,
     1532                                                     win_residue *
     1533                                                     map->format.val_bytes);
    14241534                        if (ret != 0)
    14251535                                return ret;
     
    15881698EXPORT_SYMBOL_GPL(regmap_get_raw_write_max);
    15891699
    1590 static int _regmap_bus_formatted_write(void *context, unsigned int reg,
     1700/*static inline*/ int _regmap_bus_formatted_write(void *context, unsigned int reg,
    15911701                                       unsigned int val)
    15921702{
     
    16121722}
    16131723
    1614 static int _regmap_bus_reg_write(void *context, unsigned int reg,
     1724/*static inline*/ int _regmap_bus_reg_write(void *context, unsigned int reg,
    16151725                                 unsigned int val)
    16161726{
     
    16201730}
    16211731
    1622 static int _regmap_bus_raw_write(void *context, unsigned int reg,
     1732/*static inline*/ int _regmap_bus_raw_write(void *context, unsigned int reg,
    16231733                                 unsigned int val)
    16241734{
     
    16291739        map->format.format_val(map->work_buf + map->format.reg_bytes
    16301740                               + map->format.pad_bytes, val, 0);
    1631         return _regmap_raw_write(map, reg,
    1632                                  map->work_buf +
    1633                                  map->format.reg_bytes +
    1634                                  map->format.pad_bytes,
    1635                                  map->format.val_bytes);
    1636 }
    1637 
    1638 static inline void *_regmap_map_get_context(struct regmap *map)
     1741        return _regmap_raw_write_impl(map, reg,
     1742                                      map->work_buf +
     1743                                      map->format.reg_bytes +
     1744                                      map->format.pad_bytes,
     1745                                      map->format.val_bytes);
     1746}
     1747
     1748/*static inline*/ inline void *_regmap_map_get_context(struct regmap *map)
    16391749{
    16401750        return (map->bus) ? map : map->bus_context;
     
    17281838EXPORT_SYMBOL_GPL(regmap_write_async);
    17291839
     1840int _regmap_raw_write(struct regmap *map, unsigned int reg,
     1841                      const void *val, size_t val_len)
     1842{
     1843        size_t val_bytes = map->format.val_bytes;
     1844        size_t val_count = val_len / val_bytes;
     1845        size_t chunk_count, chunk_bytes;
     1846        size_t chunk_regs = val_count;
     1847        int ret, i;
     1848
     1849        if (!val_count)
     1850                return -EINVAL;
     1851
     1852        if (map->use_single_write)
     1853                chunk_regs = 1;
     1854        else if (map->max_raw_write && val_len > map->max_raw_write)
     1855                chunk_regs = map->max_raw_write / val_bytes;
     1856
     1857        chunk_count = val_count / chunk_regs;
     1858        chunk_bytes = chunk_regs * val_bytes;
     1859
     1860        /* Write as many bytes as possible with chunk_size */
     1861        for (i = 0; i < chunk_count; i++) {
     1862                ret = _regmap_raw_write_impl(map, reg, val, chunk_bytes);
     1863                if (ret)
     1864                        return ret;
     1865
     1866                reg += regmap_get_offset(map, chunk_regs);
     1867                val += chunk_bytes;
     1868                val_len -= chunk_bytes;
     1869        }
     1870
     1871        /* Write remaining bytes */
     1872        if (val_len)
     1873                ret = _regmap_raw_write_impl(map, reg, val, val_len);
     1874
     1875        return ret;
     1876}
     1877
    17301878/**
    17311879 * regmap_raw_write() - Write raw values to one or more registers
     
    17531901        if (val_len % map->format.val_bytes)
    17541902                return -EINVAL;
    1755         if (map->max_raw_write && map->max_raw_write < val_len)
    1756                 return -E2BIG;
    17571903
    17581904        map->lock(map->lock_arg);
     
    18451991        int ret = 0, i;
    18461992        size_t val_bytes = map->format.val_bytes;
    1847         size_t total_size = val_bytes * val_count;
    18481993
    18491994        if (!IS_ALIGNED(reg, map->reg_stride))
     
    18511996
    18521997        /*
    1853          * Some devices don't support bulk write, for
    1854          * them we have a series of single write operations in the first two if
    1855          * blocks.
    1856          *
    1857          * The first if block is used for memory mapped io. It does not allow
    1858          * val_bytes of 3 for example.
    1859          * The second one is for busses that do not provide raw I/O.
    1860          * The third one is used for busses which do not have these limitations
    1861          * and can write arbitrary value lengths.
     1998         * Some devices don't support bulk write, for them we have a series of
     1999         * single write operations.
    18622000         */
    1863         if (!map->bus) {
     2001        if (!map->bus || !map->format.parse_inplace) {
    18642002                map->lock(map->lock_arg);
    18652003                for (i = 0; i < val_count; i++) {
     
    18942032out:
    18952033                map->unlock(map->lock_arg);
    1896         } else if (map->bus && !map->format.parse_inplace) {
    1897                 const u8 *u8 = val;
    1898                 const u16 *u16 = val;
    1899                 const u32 *u32 = val;
    1900                 unsigned int ival;
    1901 
    1902                 for (i = 0; i < val_count; i++) {
    1903                         switch (map->format.val_bytes) {
    1904                         case 4:
    1905                                 ival = u32[i];
    1906                                 break;
    1907                         case 2:
    1908                                 ival = u16[i];
    1909                                 break;
    1910                         case 1:
    1911                                 ival = u8[i];
    1912                                 break;
    1913                         default:
    1914                                 return -EINVAL;
    1915                         }
    1916 
    1917                         ret = regmap_write(map, reg + (i * map->reg_stride),
    1918                                            ival);
    1919                         if (ret)
    1920                                 return ret;
    1921                 }
    1922         } else if (map->use_single_write ||
    1923                    (map->max_raw_write && map->max_raw_write < total_size)) {
    1924                 int chunk_stride = map->reg_stride;
    1925                 size_t chunk_size = val_bytes;
    1926                 size_t chunk_count = val_count;
    1927 
    1928                 if (!map->use_single_write) {
    1929                         chunk_size = map->max_raw_write;
    1930                         if (chunk_size % val_bytes)
    1931                                 chunk_size -= chunk_size % val_bytes;
    1932                         chunk_count = total_size / chunk_size;
    1933                         chunk_stride *= chunk_size / val_bytes;
    1934                 }
    1935 
    1936                 map->lock(map->lock_arg);
    1937                 /* Write as many bytes as possible with chunk_size */
    1938                 for (i = 0; i < chunk_count; i++) {
    1939                         ret = _regmap_raw_write(map,
    1940                                                 reg + (i * chunk_stride),
    1941                                                 val + (i * chunk_size),
    1942                                                 chunk_size);
    1943                         if (ret)
    1944                                 break;
    1945                 }
    1946 
    1947                 /* Write remaining bytes */
    1948                 if (!ret && chunk_size * i < total_size) {
    1949                         ret = _regmap_raw_write(map, reg + (i * chunk_stride),
    1950                                                 val + (i * chunk_size),
    1951                                                 total_size - i * chunk_size);
    1952                 }
    1953                 map->unlock(map->lock_arg);
    19542034        } else {
    19552035                void *wval;
    19562036
    1957                 if (!val_count)
    1958                         return -EINVAL;
    1959 
    19602037                wval = kmemdup(val, val_count * val_bytes, map->alloc_flags);
    1961                 if (!wval) {
    1962                         dev_err(map->dev, "Error in memory allocation\n");
     2038                if (!wval)
    19632039                        return -ENOMEM;
    1964                 }
     2040
    19652041                for (i = 0; i < val_count * val_bytes; i += val_bytes)
    19662042                        map->format.parse_inplace(wval + i);
    19672043
    1968                 map->lock(map->lock_arg);
    1969                 ret = _regmap_raw_write(map, reg, wval, val_bytes * val_count);
    1970                 map->unlock(map->lock_arg);
     2044                ret = regmap_raw_write(map, reg, wval, val_bytes * val_count);
    19712045
    19722046                kfree(wval);
     
    19832057 * relative. The page register has been written if that was necessary.
    19842058 */
    1985 static int _regmap_raw_multi_reg_write(struct regmap *map,
     2059/*static inline*/ int _regmap_raw_multi_reg_write(struct regmap *map,
    19862060                                       const struct reg_sequence *regs,
    19872061                                       size_t num_regs)
     
    20292103}
    20302104
    2031 static unsigned int _regmap_register_page(struct regmap *map,
     2105/*static inline*/ unsigned int _regmap_register_page(struct regmap *map,
    20322106                                          unsigned int reg,
    20332107                                          struct regmap_range_node *range)
     
    20382112}
    20392113
    2040 static int _regmap_range_multi_paged_reg_write(struct regmap *map,
     2114/*static inline*/ int _regmap_range_multi_paged_reg_write(struct regmap *map,
    20412115                                               struct reg_sequence *regs,
    20422116                                               size_t num_regs)
     
    21152189}
    21162190
    2117 static int _regmap_multi_reg_write(struct regmap *map,
     2191/*static inline*/ int _regmap_multi_reg_write(struct regmap *map,
    21182192                                   const struct reg_sequence *regs,
    21192193                                   size_t num_regs)
     
    23102384EXPORT_SYMBOL_GPL(regmap_raw_write_async);
    23112385
    2312 static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
    2313                             unsigned int val_len)
     2386/*static inline*/ int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
     2387                            unsigned int val_len, bool noinc)
    23142388{
    23152389        struct regmap_range_node *range;
     
    23242398        if (range) {
    23252399                ret = _regmap_select_page(map, &reg, range,
    2326                                           val_len / map->format.val_bytes);
     2400                                          noinc ? 1 : val_len / map->format.val_bytes);
    23272401                if (ret != 0)
    23282402                        return ret;
     
    23402414}
    23412415
    2342 static int _regmap_bus_reg_read(void *context, unsigned int reg,
     2416/*static inline*/ int _regmap_bus_reg_read(void *context, unsigned int reg,
    23432417                                unsigned int *val)
    23442418{
     
    23482422}
    23492423
    2350 static int _regmap_bus_read(void *context, unsigned int reg,
     2424/*static inline*/ int _regmap_bus_read(void *context, unsigned int reg,
    23512425                            unsigned int *val)
    23522426{
    23532427        int ret;
    23542428        struct regmap *map = context;
     2429        void *work_val = map->work_buf + map->format.reg_bytes +
     2430                map->format.pad_bytes;
    23552431
    23562432        if (!map->format.parse_val)
    23572433                return -EINVAL;
    23582434
    2359         ret = _regmap_raw_read(map, reg, map->work_buf, map->format.val_bytes);
     2435        ret = _regmap_raw_read(map, reg, work_val, map->format.val_bytes, false);
    23602436        if (ret == 0)
    2361                 *val = map->format.parse_val(map->work_buf);
     2437                *val = map->format.parse_val(work_val);
    23622438
    23632439        return ret;
    23642440}
    23652441
    2366 static int _regmap_read(struct regmap *map, unsigned int reg,
     2442/*static inline*/ int _regmap_read(struct regmap *map, unsigned int reg,
    23672443                        unsigned int *val)
    23682444{
     
    24552531        if (regmap_volatile_range(map, reg, val_count) || map->cache_bypass ||
    24562532            map->cache_type == REGCACHE_NONE) {
     2533                size_t chunk_count, chunk_bytes;
     2534                size_t chunk_regs = val_count;
     2535
    24572536                if (!map->bus->read) {
    24582537                        ret = -ENOTSUPP;
    24592538                        goto out;
    24602539                }
    2461                 if (map->max_raw_read && map->max_raw_read < val_len) {
    2462                         ret = -E2BIG;
    2463                         goto out;
    2464                 }
    2465 
    2466                 /* Physical block read if there's no cache involved */
    2467                 ret = _regmap_raw_read(map, reg, val, val_len);
    2468 
     2540
     2541                if (map->use_single_read)
     2542                        chunk_regs = 1;
     2543                else if (map->max_raw_read && val_len > map->max_raw_read)
     2544                        chunk_regs = map->max_raw_read / val_bytes;
     2545
     2546                chunk_count = val_count / chunk_regs;
     2547                chunk_bytes = chunk_regs * val_bytes;
     2548
     2549                /* Read bytes that fit into whole chunks */
     2550                for (i = 0; i < chunk_count; i++) {
     2551                        ret = _regmap_raw_read(map, reg, val, chunk_bytes, false);
     2552                        if (ret != 0)
     2553                                goto out;
     2554
     2555                        reg += regmap_get_offset(map, chunk_regs);
     2556                        val += chunk_bytes;
     2557                        val_len -= chunk_bytes;
     2558                }
     2559
     2560                /* Read remaining bytes */
     2561                if (val_len) {
     2562                        ret = _regmap_raw_read(map, reg, val, val_len, false);
     2563                        if (ret != 0)
     2564                                goto out;
     2565                }
    24692566        } else {
    24702567                /* Otherwise go word by word for the cache; should be low
     
    24892586
    24902587/**
    2491  * regmap_field_read() - Read a value to a single register field
     2588 * regmap_noinc_read(): Read data from a register without incrementing the
     2589 *                      register number
     2590 *
     2591 * @map: Register map to read from
     2592 * @reg: Register to read from
     2593 * @val: Pointer to data buffer
     2594 * @val_len: Length of output buffer in bytes.
     2595 *
     2596 * The regmap API usually assumes that bulk bus read operations will read a
     2597 * range of registers. Some devices have certain registers for which a read
     2598 * operation read will read from an internal FIFO.
     2599 *
     2600 * The target register must be volatile but registers after it can be
     2601 * completely unrelated cacheable registers.
     2602 *
     2603 * This will attempt multiple reads as required to read val_len bytes.
     2604 *
     2605 * A value of zero will be returned on success, a negative errno will be
     2606 * returned in error cases.
     2607 */
     2608int regmap_noinc_read(struct regmap *map, unsigned int reg,
     2609                      void *val, size_t val_len)
     2610{
     2611        size_t read_len;
     2612        int ret;
     2613
     2614        if (!map->bus)
     2615                return -EINVAL;
     2616        if (!map->bus->read)
     2617                return -ENOTSUPP;
     2618        if (val_len % map->format.val_bytes)
     2619                return -EINVAL;
     2620        if (!IS_ALIGNED(reg, map->reg_stride))
     2621                return -EINVAL;
     2622        if (val_len == 0)
     2623                return -EINVAL;
     2624
     2625        map->lock(map->lock_arg);
     2626
     2627        if (!regmap_volatile(map, reg) || !regmap_readable_noinc(map, reg)) {
     2628                ret = -EINVAL;
     2629                goto out_unlock;
     2630        }
     2631
     2632        while (val_len) {
     2633                if (map->max_raw_read && map->max_raw_read < val_len)
     2634                        read_len = map->max_raw_read;
     2635                else
     2636                        read_len = val_len;
     2637                ret = _regmap_raw_read(map, reg, val, read_len, true);
     2638                if (ret)
     2639                        goto out_unlock;
     2640                val = ((u8 *)val) + read_len;
     2641                val_len -= read_len;
     2642        }
     2643
     2644out_unlock:
     2645        map->unlock(map->lock_arg);
     2646        return ret;
     2647}
     2648EXPORT_SYMBOL_GPL(regmap_noinc_read);
     2649
     2650/**
     2651 * regmap_field_read(): Read a value to a single register field
    24922652 *
    24932653 * @field: Register field to read from
     
    25662726        if (!IS_ALIGNED(reg, map->reg_stride))
    25672727                return -EINVAL;
     2728        if (val_count == 0)
     2729                return -EINVAL;
    25682730
    25692731        if (map->bus && map->format.parse_inplace && (vol || map->cache_type == REGCACHE_NONE)) {
    2570                 /*
    2571                  * Some devices does not support bulk read, for
    2572                  * them we have a series of single read operations.
    2573                  */
    2574                 size_t total_size = val_bytes * val_count;
    2575 
    2576                 if (!map->use_single_read &&
    2577                     (!map->max_raw_read || map->max_raw_read > total_size)) {
    2578                         ret = regmap_raw_read(map, reg, val,
    2579                                               val_bytes * val_count);
    2580                         if (ret != 0)
    2581                                 return ret;
    2582                 } else {
    2583                         /*
    2584                          * Some devices do not support bulk read or do not
    2585                          * support large bulk reads, for them we have a series
    2586                          * of read operations.
    2587                          */
    2588                         int chunk_stride = map->reg_stride;
    2589                         size_t chunk_size = val_bytes;
    2590                         size_t chunk_count = val_count;
    2591 
    2592                         if (!map->use_single_read) {
    2593                                 chunk_size = map->max_raw_read;
    2594                                 if (chunk_size % val_bytes)
    2595                                         chunk_size -= chunk_size % val_bytes;
    2596                                 chunk_count = total_size / chunk_size;
    2597                                 chunk_stride *= chunk_size / val_bytes;
    2598                         }
    2599 
    2600                         /* Read bytes that fit into a multiple of chunk_size */
    2601                         for (i = 0; i < chunk_count; i++) {
    2602                                 ret = regmap_raw_read(map,
    2603                                                       reg + (i * chunk_stride),
    2604                                                       val + (i * chunk_size),
    2605                                                       chunk_size);
    2606                                 if (ret != 0)
    2607                                         return ret;
    2608                         }
    2609 
    2610                         /* Read remaining bytes */
    2611                         if (chunk_size * i < total_size) {
    2612                                 ret = regmap_raw_read(map,
    2613                                                       reg + (i * chunk_stride),
    2614                                                       val + (i * chunk_size),
    2615                                                       total_size - i * chunk_size);
    2616                                 if (ret != 0)
    2617                                         return ret;
    2618                         }
    2619                 }
     2732                ret = regmap_raw_read(map, reg, val, val_bytes * val_count);
     2733                if (ret != 0)
     2734                        return ret;
    26202735
    26212736                for (i = 0; i < val_count * val_bytes; i += val_bytes)
    26222737                        map->format.parse_inplace(val + i);
    26232738        } else {
     2739#ifdef CONFIG_64BIT
     2740                u64 *u64 = val;
     2741#endif
     2742                u32 *u32 = val;
     2743                u16 *u16 = val;
     2744                u8 *u8 = val;
     2745
     2746                map->lock(map->lock_arg);
     2747
    26242748                for (i = 0; i < val_count; i++) {
    26252749                        unsigned int ival;
    2626                         ret = regmap_read(map, reg + regmap_get_offset(map, i),
    2627                                           &ival);
     2750
     2751                        ret = _regmap_read(map, reg + regmap_get_offset(map, i),
     2752                                           &ival);
    26282753                        if (ret != 0)
    2629                                 return ret;
    2630 
    2631                         if (map->format.format_val) {
    2632                                 map->format.format_val(val + (i * val_bytes), ival, 0);
    2633                         } else {
    2634                                 /* Devices providing read and write
    2635                                  * operations can use the bulk I/O
    2636                                  * functions if they define a val_bytes,
    2637                                  * we assume that the values are native
    2638                                  * endian.
    2639                                  */
     2754                                goto out;
     2755
     2756                        switch (map->format.val_bytes) {
    26402757#ifdef CONFIG_64BIT
    2641                                 u64 *u64 = val;
     2758                        case 8:
     2759                                u64[i] = ival;
     2760                                break;
    26422761#endif
    2643                                 u32 *u32 = val;
    2644                                 u16 *u16 = val;
    2645                                 u8 *u8 = val;
    2646 
    2647                                 switch (map->format.val_bytes) {
    2648 #ifdef CONFIG_64BIT
    2649                                 case 8:
    2650                                         u64[i] = ival;
    2651                                         break;
    2652 #endif
    2653                                 case 4:
    2654                                         u32[i] = ival;
    2655                                         break;
    2656                                 case 2:
    2657                                         u16[i] = ival;
    2658                                         break;
    2659                                 case 1:
    2660                                         u8[i] = ival;
    2661                                         break;
    2662                                 default:
    2663                                         return -EINVAL;
    2664                                 }
     2762                        case 4:
     2763                                u32[i] = ival;
     2764                                break;
     2765                        case 2:
     2766                                u16[i] = ival;
     2767                                break;
     2768                        case 1:
     2769                                u8[i] = ival;
     2770                                break;
     2771                        default:
     2772                                ret = -EINVAL;
     2773                                goto out;
    26652774                        }
    26662775                }
    2667         }
    2668 
    2669         return 0;
     2776
     2777out:
     2778                map->unlock(map->lock_arg);
     2779        }
     2780
     2781        return ret;
    26702782}
    26712783EXPORT_SYMBOL_GPL(regmap_bulk_read);
    26722784
    2673 static int _regmap_update_bits(struct regmap *map, unsigned int reg,
     2785/*static inline*/ int _regmap_update_bits(struct regmap *map, unsigned int reg,
    26742786                               unsigned int mask, unsigned int val,
    26752787                               bool *change, bool force_write)
     
    27642876EXPORT_SYMBOL_GPL(regmap_async_complete_cb);
    27652877
    2766 #ifndef TARGET_OS2
    2767 static int regmap_async_is_done(struct regmap *map)
     2878/*static inline*/ int regmap_async_is_done(struct regmap *map)
    27682879{
    27692880        unsigned long flags;
     
    27762887        return ret;
    27772888}
    2778 #endif
    27792889
    27802890/**
     
    27952905                return 0;
    27962906
    2797 //FIXME wait_event(map->async_waitq, regmap_async_is_done(map));
     2907//      wait_event(map->async_waitq, regmap_async_is_done(map));
    27982908
    27992909        spin_lock_irqsave(&map->async_lock, flags);
     
    28352945                return 0;
    28362946#endif
    2837 
    28382947        p = krealloc(map->patch,
    28392948                     sizeof(struct reg_sequence) * (map->patch_regs + num_regs),
     
    29243033EXPORT_SYMBOL_GPL(regmap_parse_val);
    29253034
    2926 static int __init regmap_initcall(void)
     3035/*static inline*/ int __init regmap_initcall(void)
    29273036{
    29283037        regmap_debugfs_initcall();
Note: See TracChangeset for help on using the changeset viewer.