Changeset 652


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

Location:
GPL/branches/uniaud32-next
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • GPL/branches/uniaud32-next/include/linux/regmap.h

    r625 r652  
     1/* SPDX-License-Identifier: GPL-2.0-only */
    12#ifndef __LINUX_REGMAP_H
    23#define __LINUX_REGMAP_H
     
    89 *
    910 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
    10  *
    11  * This program is free software; you can redistribute it and/or modify
    12  * it under the terms of the GNU General Public License version 2 as
    13  * published by the Free Software Foundation.
    14  */
    15 /* from 4.19.163 */
     11 */
     12
     13/* from 5.10.10 */
    1614
    1715#include <linux/list.h>
     
    2220//#include <linux/bug.h>
    2321#include <linux/lockdep.h>
     22//#include <linux/iopoll.h>
     23#include <linux/fwnode.h>
    2424
    2525struct module;
    2626struct clk;
    2727struct device;
     28struct device_node;
    2829struct i2c_client;
     30struct i3c_device;
    2931struct irq_domain;
    3032struct slim_device;
     
    7577};
    7678
    77 #define regmap_update_bits(map, reg, mask, val) \
    78         regmap_update_bits_base(map, reg, mask, val, NULL, false, false)
    79 #define regmap_update_bits_async(map, reg, mask, val)\
    80         regmap_update_bits_base(map, reg, mask, val, NULL, true, false)
    81 #define regmap_update_bits_check(map, reg, mask, val, change)\
    82         regmap_update_bits_base(map, reg, mask, val, change, false, false)
    83 #define regmap_update_bits_check_async(map, reg, mask, val, change)\
    84         regmap_update_bits_base(map, reg, mask, val, change, true, false)
    85 
    86 #define regmap_write_bits(map, reg, mask, val) \
    87         regmap_update_bits_base(map, reg, mask, val, NULL, false, true)
    88 
    89 #define regmap_field_write(field, val) \
    90         regmap_field_update_bits_base(field, ~0, val, NULL, false, false)
    91 #define regmap_field_force_write(field, val) \
    92         regmap_field_update_bits_base(field, ~0, val, NULL, false, true)
    93 #define regmap_field_update_bits(field, mask, val)\
    94         regmap_field_update_bits_base(field, mask, val, NULL, false, false)
    95 #define regmap_field_force_update_bits(field, mask, val) \
    96         regmap_field_update_bits_base(field, mask, val, NULL, false, true)
    97 
    98 #define regmap_fields_write(field, id, val) \
    99         regmap_fields_update_bits_base(field, id, ~0, val, NULL, false, false)
    100 #define regmap_fields_force_write(field, id, val) \
    101         regmap_fields_update_bits_base(field, id, ~0, val, NULL, false, true)
    102 #define regmap_fields_update_bits(field, id, mask, val)\
    103         regmap_fields_update_bits_base(field, id, mask, val, NULL, false, false)
    104 #define regmap_fields_force_update_bits(field, id, mask, val) \
    105         regmap_fields_update_bits_base(field, id, mask, val, NULL, false, true)
     79#define REG_SEQ(_reg, _def, _delay_us) {                \
     80                                .reg = _reg,            \
     81                                .def = _def,            \
     82                                .delay_us = _delay_us,  \
     83                                }
     84#define REG_SEQ0(_reg, _def)    REG_SEQ(_reg, _def, 0)
    10685
    10786/**
     
    11493 * @sleep_us: Maximum time to sleep between reads in us (0
    11594 *            tight-loops).  Should be less than ~20ms since usleep_range
    116  *            is used (see Documentation/timers/timers-howto.txt).
     95 *            is used (see Documentation/timers/timers-howto.rst).
    11796 * @timeout_us: Timeout in us, 0 means never timeout
    11897 *
     
    126105#define regmap_read_poll_timeout(map, addr, val, cond, sleep_us, timeout_us) \
    127106({ \
     107        int __ret, __tmp; \
     108        __tmp = read_poll_timeout(regmap_read, __ret, __ret || (cond), \
     109                        sleep_us, timeout_us, false, (map), (addr), &(val)); \
     110        __ret ?: __tmp; \
     111})
     112
     113/**
     114 * regmap_read_poll_timeout_atomic - Poll until a condition is met or a timeout occurs
     115 *
     116 * @map: Regmap to read from
     117 * @addr: Address to poll
     118 * @val: Unsigned integer variable to read the value into
     119 * @cond: Break condition (usually involving @val)
     120 * @delay_us: Time to udelay between reads in us (0 tight-loops).
     121 *            Should be less than ~10us since udelay is used
     122 *            (see Documentation/timers/timers-howto.rst).
     123 * @timeout_us: Timeout in us, 0 means never timeout
     124 *
     125 * Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_read
     126 * error return value in case of a error read. In the two former cases,
     127 * the last read value at @addr is stored in @val.
     128 *
     129 * This is modelled after the readx_poll_timeout_atomic macros in linux/iopoll.h.
     130 *
     131 * Note: In general regmap cannot be used in atomic context. If you want to use
     132 * this macro then first setup your regmap for atomic use (flat or no cache
     133 * and MMIO regmap).
     134 */
     135#define regmap_read_poll_timeout_atomic(map, addr, val, cond, delay_us, timeout_us) \
     136({ \
    128137        u64 __timeout_us = (timeout_us); \
    129         unsigned long __sleep_us = (sleep_us); \
     138        unsigned long __delay_us = (delay_us); \
    130139        ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \
    131140        int __ret; \
    132         might_sleep_if(__sleep_us); \
    133141        for (;;) { \
    134142                __ret = regmap_read((map), (addr), &(val)); \
     
    142150                        break; \
    143151                } \
    144                 if (__sleep_us) \
    145                         usleep_range((__sleep_us >> 2) + 1, __sleep_us); \
     152                if (__delay_us) \
     153                        udelay(__delay_us); \
    146154        } \
    147155        __ret ?: ((cond) ? 0 : -ETIMEDOUT); \
     
    156164 * @sleep_us: Maximum time to sleep between reads in us (0
    157165 *            tight-loops).  Should be less than ~20ms since usleep_range
    158  *            is used (see Documentation/timers/timers-howto.txt).
     166 *            is used (see Documentation/timers/timers-howto.rst).
    159167 * @timeout_us: Timeout in us, 0 means never timeout
    160168 *
     
    168176#define regmap_field_read_poll_timeout(field, val, cond, sleep_us, timeout_us) \
    169177({ \
    170         u64 __timeout_us = (timeout_us); \
    171         unsigned long __sleep_us = (sleep_us); \
    172         ktime_t timeout = ktime_add_us(ktime_get(), __timeout_us); \
    173         int pollret; \
    174         might_sleep_if(__sleep_us); \
    175         for (;;) { \
    176                 pollret = regmap_field_read((field), &(val)); \
    177                 if (pollret) \
    178                         break; \
    179                 if (cond) \
    180                         break; \
    181                 if (__timeout_us && ktime_compare(ktime_get(), timeout) > 0) { \
    182                         pollret = regmap_field_read((field), &(val)); \
    183                         break; \
    184                 } \
    185                 if (__sleep_us) \
    186                         usleep_range((__sleep_us >> 2) + 1, __sleep_us); \
    187         } \
    188         pollret ?: ((cond) ? 0 : -ETIMEDOUT); \
     178        int __ret, __tmp; \
     179        __tmp = read_poll_timeout(regmap_field_read, __ret, __ret || (cond), \
     180                        sleep_us, timeout_us, false, (field), &(val)); \
     181        __ret ?: __tmp; \
    189182})
    190183
     
    271264 *                check is performed on such table (a register is precious if
    272265 *                it belongs to one of the ranges specified by precious_table).
     266 * @writeable_noinc_reg: Optional callback returning true if the register
     267 *                      supports multiple write operations without incrementing
     268 *                      the register number. If this field is NULL but
     269 *                      wr_noinc_table (see below) is not, the check is
     270 *                      performed on such table (a register is no increment
     271 *                      writeable if it belongs to one of the ranges specified
     272 *                      by wr_noinc_table).
    273273 * @readable_noinc_reg: Optional callback returning true if the register
    274274 *                      supports multiple read operations without incrementing
     
    279279 *                      by rd_noinc_table).
    280280 * @disable_locking: This regmap is either protected by external means or
    281  *                   is guaranteed not be be accessed from multiple threads.
     281 *                   is guaranteed not to be accessed from multiple threads.
    282282 *                   Don't use any locking mechanisms.
    283283 * @lock:         Optional lock callback (overrides regmap's default lock
     
    305305 * @volatile_table: As above, for volatile registers.
    306306 * @precious_table: As above, for precious registers.
     307 * @wr_noinc_table: As above, for no increment writeable registers.
    307308 * @rd_noinc_table: As above, for no increment readable registers.
    308309 * @reg_defaults: Power on reset values for registers (for use with
     
    318319 * @zero_flag_mask: If set, read_flag_mask and write_flag_mask are used even
    319320 *                   if they are both empty.
    320  * @use_single_rw: If set, converts the bulk read and write operations into
    321  *                  a series of single read and write operations. This is useful
    322  *                  for device that does not support bulk read and write.
     321 * @use_single_read: If set, converts the bulk read operation into a series of
     322 *                   single read operations. This is useful for a device that
     323 *                   does not support  bulk read.
     324 * @use_single_write: If set, converts the bulk write operation into a series of
     325 *                    single write operations. This is useful for a device that
     326 *                    does not support bulk write.
    323327 * @can_multi_write: If set, the device supports the multi write mode of bulk
    324328 *                   write operations, if clear multi write requests will be
     
    342346 * @hwlock_mode: The hardware spinlock mode, should be HWLOCK_IRQSTATE,
    343347 *               HWLOCK_IRQ or 0.
     348 * @can_sleep: Optional, specifies whether regmap operations can sleep.
    344349 */
    345350struct regmap_config {
     
    355360        bool (*volatile_reg)(struct device *dev, unsigned int reg);
    356361        bool (*precious_reg)(struct device *dev, unsigned int reg);
     362        bool (*writeable_noinc_reg)(struct device *dev, unsigned int reg);
    357363        bool (*readable_noinc_reg)(struct device *dev, unsigned int reg);
    358364
     
    372378        const struct regmap_access_table *volatile_table;
    373379        const struct regmap_access_table *precious_table;
     380        const struct regmap_access_table *wr_noinc_table;
    374381        const struct regmap_access_table *rd_noinc_table;
    375382        const struct reg_default *reg_defaults;
     
    396403        unsigned int hwlock_id;
    397404        unsigned int hwlock_mode;
     405
     406        bool can_sleep;
    398407};
    399408
     
    408417 *
    409418 * @selector_reg: Register with selector field.
    410  * @selector_mask: Bit shift for selector value.
    411  * @selector_shift: Bit mask for selector value.
     419 * @selector_mask: Bit mask for selector value.
     420 * @selector_shift: Bit shift for selector value.
    412421 *
    413422 * @window_start: Address of first (lowest) register in data window.
     
    565574                                 struct lock_class_key *lock_key,
    566575                                 const char *lock_name);
     576struct regmap *__regmap_init_spi_avmm(struct spi_device *spi,
     577                                      const struct regmap_config *config,
     578                                      struct lock_class_key *lock_key,
     579                                      const char *lock_name);
    567580
    568581struct regmap *__devm_regmap_init(struct device *dev,
     
    614627                                 struct lock_class_key *lock_key,
    615628                                 const char *lock_name);
     629struct regmap *__devm_regmap_init_i3c(struct i3c_device *i3c,
     630                                 const struct regmap_config *config,
     631                                 struct lock_class_key *lock_key,
     632                                 const char *lock_name);
     633struct regmap *__devm_regmap_init_spi_avmm(struct spi_device *spi,
     634                                           const struct regmap_config *config,
     635                                           struct lock_class_key *lock_key,
     636                                           const char *lock_name);
    616637/*
    617638 * Wrapper for regmap_init macros to include a unique lockdep key and name
     
    800821                                sdw, config)
    801822
     823/**
     824 * regmap_init_spi_avmm() - Initialize register map for Intel SPI Slave
     825 * to AVMM Bus Bridge
     826 *
     827 * @spi: Device that will be interacted with
     828 * @config: Configuration for register map
     829 *
     830 * The return value will be an ERR_PTR() on error or a valid pointer
     831 * to a struct regmap.
     832 */
     833#define regmap_init_spi_avmm(spi, config)                                       \
     834        __regmap_lockdep_wrapper(__regmap_init_spi_avmm, #config,               \
     835                                 spi, config)
    802836
    803837/**
     
    9721006        __regmap_lockdep_wrapper(__devm_regmap_init_slimbus, #config,   \
    9731007                                slimbus, config)
     1008
     1009/**
     1010 * devm_regmap_init_i3c() - Initialise managed register map
     1011 *
     1012 * @i3c: Device that will be interacted with
     1013 * @config: Configuration for register map
     1014 *
     1015 * The return value will be an ERR_PTR() on error or a valid pointer
     1016 * to a struct regmap.  The regmap will be automatically freed by the
     1017 * device management code.
     1018 */
     1019#define devm_regmap_init_i3c(i3c, config)                               \
     1020        __regmap_lockdep_wrapper(__devm_regmap_init_i3c, #config,       \
     1021                                i3c, config)
     1022
     1023/**
     1024 * devm_regmap_init_spi_avmm() - Initialize register map for Intel SPI Slave
     1025 * to AVMM Bus Bridge
     1026 *
     1027 * @spi: Device that will be interacted with
     1028 * @config: Configuration for register map
     1029 *
     1030 * The return value will be an ERR_PTR() on error or a valid pointer
     1031 * to a struct regmap.  The map will be automatically freed by the
     1032 * device management code.
     1033 */
     1034#define devm_regmap_init_spi_avmm(spi, config)                          \
     1035        __regmap_lockdep_wrapper(__devm_regmap_init_spi_avmm, #config,  \
     1036                                 spi, config)
     1037
    9741038int regmap_mmio_attach_clk(struct regmap *map, struct clk *clk);
    9751039void regmap_mmio_detach_clk(struct regmap *map);
     
    9821046int regmap_write_async(struct regmap *map, unsigned int reg, unsigned int val);
    9831047int regmap_raw_write(struct regmap *map, unsigned int reg,
     1048                     const void *val, size_t val_len);
     1049int regmap_noinc_write(struct regmap *map, unsigned int reg,
    9841050                     const void *val, size_t val_len);
    9851051int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
     
    10021068                            unsigned int mask, unsigned int val,
    10031069                            bool *change, bool async, bool force);
     1070
     1071static inline int regmap_update_bits(struct regmap *map, unsigned int reg,
     1072                                     unsigned int mask, unsigned int val)
     1073{
     1074        return regmap_update_bits_base(map, reg, mask, val, NULL, false, false);
     1075}
     1076
     1077static inline int regmap_update_bits_async(struct regmap *map, unsigned int reg,
     1078                                           unsigned int mask, unsigned int val)
     1079{
     1080        return regmap_update_bits_base(map, reg, mask, val, NULL, true, false);
     1081}
     1082
     1083static inline int regmap_update_bits_check(struct regmap *map, unsigned int reg,
     1084                                           unsigned int mask, unsigned int val,
     1085                                           bool *change)
     1086{
     1087        return regmap_update_bits_base(map, reg, mask, val,
     1088                                       change, false, false);
     1089}
     1090
     1091static inline int
     1092regmap_update_bits_check_async(struct regmap *map, unsigned int reg,
     1093                               unsigned int mask, unsigned int val,
     1094                               bool *change)
     1095{
     1096        return regmap_update_bits_base(map, reg, mask, val,
     1097                                       change, true, false);
     1098}
     1099
     1100static inline int regmap_write_bits(struct regmap *map, unsigned int reg,
     1101                                    unsigned int mask, unsigned int val)
     1102{
     1103        return regmap_update_bits_base(map, reg, mask, val, NULL, false, true);
     1104}
     1105
    10041106int regmap_get_val_bytes(struct regmap *map);
    10051107int regmap_get_max_register(struct regmap *map);
     
    10371139                          unsigned int nranges);
    10381140
     1141static inline int regmap_set_bits(struct regmap *map,
     1142                                  unsigned int reg, unsigned int bits)
     1143{
     1144        return regmap_update_bits_base(map, reg, bits, bits,
     1145                                       NULL, false, false);
     1146}
     1147
     1148static inline int regmap_clear_bits(struct regmap *map,
     1149                                    unsigned int reg, unsigned int bits)
     1150{
     1151        return regmap_update_bits_base(map, reg, bits, 0, NULL, false, false);
     1152}
     1153
     1154int regmap_test_bits(struct regmap *map, unsigned int reg, unsigned int bits);
     1155
    10391156/**
    10401157 * struct reg_field - Description of an register field
     
    10601177                                }
    10611178
     1179#define REG_FIELD_ID(_reg, _lsb, _msb, _size, _offset) {        \
     1180                                .reg = _reg,                    \
     1181                                .lsb = _lsb,                    \
     1182                                .msb = _msb,                    \
     1183                                .id_size = _size,               \
     1184                                .id_offset = _offset,           \
     1185                                }
     1186
    10621187struct regmap_field *regmap_field_alloc(struct regmap *regmap,
    10631188                struct reg_field reg_field);
     
    10671192                struct regmap *regmap, struct reg_field reg_field);
    10681193void devm_regmap_field_free(struct device *dev, struct regmap_field *field);
     1194
     1195int regmap_field_bulk_alloc(struct regmap *regmap,
     1196                             struct regmap_field **rm_field,
     1197                             struct reg_field *reg_field,
     1198                             int num_fields);
     1199void regmap_field_bulk_free(struct regmap_field *field);
     1200int devm_regmap_field_bulk_alloc(struct device *dev, struct regmap *regmap,
     1201                                 struct regmap_field **field,
     1202                                 struct reg_field *reg_field, int num_fields);
     1203void devm_regmap_field_bulk_free(struct device *dev,
     1204                                 struct regmap_field *field);
    10691205
    10701206int regmap_field_read(struct regmap_field *field, unsigned int *val);
     
    10781214                                   bool *change, bool async, bool force);
    10791215
     1216static inline int regmap_field_write(struct regmap_field *field,
     1217                                     unsigned int val)
     1218{
     1219        return regmap_field_update_bits_base(field, ~0, val,
     1220                                             NULL, false, false);
     1221}
     1222
     1223static inline int regmap_field_force_write(struct regmap_field *field,
     1224                                           unsigned int val)
     1225{
     1226        return regmap_field_update_bits_base(field, ~0, val, NULL, false, true);
     1227}
     1228
     1229static inline int regmap_field_update_bits(struct regmap_field *field,
     1230                                           unsigned int mask, unsigned int val)
     1231{
     1232        return regmap_field_update_bits_base(field, mask, val,
     1233                                             NULL, false, false);
     1234}
     1235
     1236static inline int
     1237regmap_field_force_update_bits(struct regmap_field *field,
     1238                               unsigned int mask, unsigned int val)
     1239{
     1240        return regmap_field_update_bits_base(field, mask, val,
     1241                                             NULL, false, true);
     1242}
     1243
     1244static inline int regmap_fields_write(struct regmap_field *field,
     1245                                      unsigned int id, unsigned int val)
     1246{
     1247        return regmap_fields_update_bits_base(field, id, ~0, val,
     1248                                              NULL, false, false);
     1249}
     1250
     1251static inline int regmap_fields_force_write(struct regmap_field *field,
     1252                                            unsigned int id, unsigned int val)
     1253{
     1254        return regmap_fields_update_bits_base(field, id, ~0, val,
     1255                                              NULL, false, true);
     1256}
     1257
     1258static inline int
     1259regmap_fields_update_bits(struct regmap_field *field, unsigned int id,
     1260                          unsigned int mask, unsigned int val)
     1261{
     1262        return regmap_fields_update_bits_base(field, id, mask, val,
     1263                                              NULL, false, false);
     1264}
     1265
     1266static inline int
     1267regmap_fields_force_update_bits(struct regmap_field *field, unsigned int id,
     1268                                unsigned int mask, unsigned int val)
     1269{
     1270        return regmap_fields_update_bits_base(field, id, mask, val,
     1271                                              NULL, false, true);
     1272}
     1273
     1274/**
     1275 * struct regmap_irq_type - IRQ type definitions.
     1276 *
     1277 * @type_reg_offset: Offset register for the irq type setting.
     1278 * @type_rising_val: Register value to configure RISING type irq.
     1279 * @type_falling_val: Register value to configure FALLING type irq.
     1280 * @type_level_low_val: Register value to configure LEVEL_LOW type irq.
     1281 * @type_level_high_val: Register value to configure LEVEL_HIGH type irq.
     1282 * @types_supported: logical OR of IRQ_TYPE_* flags indicating supported types.
     1283 */
     1284struct regmap_irq_type {
     1285        unsigned int type_reg_offset;
     1286        unsigned int type_reg_mask;
     1287        unsigned int type_rising_val;
     1288        unsigned int type_falling_val;
     1289        unsigned int type_level_low_val;
     1290        unsigned int type_level_high_val;
     1291        unsigned int types_supported;
     1292};
     1293
    10801294/**
    10811295 * struct regmap_irq - Description of an IRQ for the generic regmap irq_chip.
     
    10831297 * @reg_offset: Offset of the status/mask register within the bank
    10841298 * @mask:       Mask used to flag/control the register.
    1085  * @type_reg_offset: Offset register for the irq type setting.
    1086  * @type_rising_mask: Mask bit to configure RISING type irq.
    1087  * @type_falling_mask: Mask bit to configure FALLING type irq.
     1299 * @type:       IRQ trigger type setting details if supported.
    10881300 */
    10891301struct regmap_irq {
    10901302        unsigned int reg_offset;
    10911303        unsigned int mask;
    1092         unsigned int type_reg_offset;
    1093         unsigned int type_rising_mask;
    1094         unsigned int type_falling_mask;
     1304        struct regmap_irq_type type;
    10951305};
    10961306
     
    10981308        [_irq] = { .reg_offset = (_off), .mask = (_mask) }
    10991309
     1310#define REGMAP_IRQ_REG_LINE(_id, _reg_bits) \
     1311        [_id] = {                               \
     1312                .mask = BIT((_id) % (_reg_bits)),       \
     1313                .reg_offset = (_id) / (_reg_bits),      \
     1314        }
     1315
     1316#define REGMAP_IRQ_MAIN_REG_OFFSET(arr)                         \
     1317        { .num_regs = ARRAY_SIZE((arr)), .offset = &(arr)[0] }
     1318
     1319struct regmap_irq_sub_irq_map {
     1320        unsigned int num_regs;
     1321        unsigned int *offset;
     1322};
     1323
    11001324/**
    11011325 * struct regmap_irq_chip - Description of a generic regmap irq_chip.
    11021326 *
    11031327 * @name:        Descriptive name for IRQ controller.
     1328 *
     1329 * @main_status: Base main status register address. For chips which have
     1330 *               interrupts arranged in separate sub-irq blocks with own IRQ
     1331 *               registers and which have a main IRQ registers indicating
     1332 *               sub-irq blocks with unhandled interrupts. For such chips fill
     1333 *               sub-irq register information in status_base, mask_base and
     1334 *               ack_base.
     1335 * @num_main_status_bits: Should be given to chips where number of meaningfull
     1336 *                        main status bits differs from num_regs.
     1337 * @sub_reg_offsets: arrays of mappings from main register bits to sub irq
     1338 *                   registers. First item in array describes the registers
     1339 *                   for first main status bit. Second array for second bit etc.
     1340 *                   Offset is given as sub register status offset to
     1341 *                   status_base. Should contain num_regs arrays.
     1342 *                   Can be provided for chips with more complex mapping than
     1343 *                   1.st bit to 1.st sub-reg, 2.nd bit to 2.nd sub-reg, ...
     1344 * @num_main_regs: Number of 'main status' irq registers for chips which have
     1345 *                 main_status set.
    11041346 *
    11051347 * @status_base: Base status register address.
     
    11171359 * @use_ack:     Use @ack register even if it is zero.
    11181360 * @ack_invert:  Inverted ack register: cleared bits for ack.
     1361 * @clear_ack:  Use this to set 1 and 0 or vice-versa to clear interrupts.
    11191362 * @wake_invert: Inverted wake register: cleared bits are wake enabled.
    11201363 * @type_invert: Invert the type flags.
     1364 * @type_in_mask: Use the mask registers for controlling irq type. For
     1365 *                interrupts defining type_rising/falling_mask use mask_base
     1366 *                for edge configuration and never update bits in type_base.
     1367 * @clear_on_unmask: For chips with interrupts cleared on read: read the status
     1368 *                   registers before unmasking interrupts to clear any bits
     1369 *                   set when they were masked.
    11211370 * @runtime_pm:  Hold a runtime PM lock on the device when accessing it.
    11221371 *
     
    11421391        const char *name;
    11431392
     1393        unsigned int main_status;
     1394        unsigned int num_main_status_bits;
     1395        struct regmap_irq_sub_irq_map *sub_reg_offsets;
     1396        int num_main_regs;
     1397
    11441398        unsigned int status_base;
    11451399        unsigned int mask_base;
     
    11541408        bool use_ack:1;
    11551409        bool ack_invert:1;
     1410        bool clear_ack:1;
    11561411        bool wake_invert:1;
    11571412        bool runtime_pm:1;
    11581413        bool type_invert:1;
     1414        bool type_in_mask:1;
     1415        bool clear_on_unmask:1;
    11591416
    11601417        int num_regs;
     
    11761433                        int irq_base, const struct regmap_irq_chip *chip,
    11771434                        struct regmap_irq_chip_data **data);
     1435int regmap_add_irq_chip_fwnode(struct fwnode_handle *fwnode,
     1436                               struct regmap *map, int irq,
     1437                               int irq_flags, int irq_base,
     1438                               const struct regmap_irq_chip *chip,
     1439                               struct regmap_irq_chip_data **data);
    11781440void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data);
    11791441
     
    11821444                             const struct regmap_irq_chip *chip,
    11831445                             struct regmap_irq_chip_data **data);
     1446int devm_regmap_add_irq_chip_fwnode(struct device *dev,
     1447                                    struct fwnode_handle *fwnode,
     1448                                    struct regmap *map, int irq,
     1449                                    int irq_flags, int irq_base,
     1450                                    const struct regmap_irq_chip *chip,
     1451                                    struct regmap_irq_chip_data **data);
    11841452void devm_regmap_del_irq_chip(struct device *dev, int irq,
    11851453                              struct regmap_irq_chip_data *data);
     
    12261494}
    12271495
     1496static inline int regmap_noinc_write(struct regmap *map, unsigned int reg,
     1497                                    const void *val, size_t val_len)
     1498{
     1499        WARN_ONCE(1, "regmap API is disabled");
     1500        return -EINVAL;
     1501}
     1502
    12281503static inline int regmap_bulk_write(struct regmap *map, unsigned int reg,
    12291504                                    const void *val, size_t val_count)
     
    12641539                                          unsigned int mask, unsigned int val,
    12651540                                          bool *change, bool async, bool force)
     1541{
     1542        WARN_ONCE(1, "regmap API is disabled");
     1543        return -EINVAL;
     1544}
     1545
     1546static inline int regmap_set_bits(struct regmap *map,
     1547                                  unsigned int reg, unsigned int bits)
     1548{
     1549        WARN_ONCE(1, "regmap API is disabled");
     1550        return -EINVAL;
     1551}
     1552
     1553static inline int regmap_clear_bits(struct regmap *map,
     1554                                    unsigned int reg, unsigned int bits)
     1555{
     1556        WARN_ONCE(1, "regmap API is disabled");
     1557        return -EINVAL;
     1558}
     1559
     1560static inline int regmap_test_bits(struct regmap *map,
     1561                                   unsigned int reg, unsigned int bits)
    12661562{
    12671563        WARN_ONCE(1, "regmap API is disabled");
     
    12861582}
    12871583
     1584static inline int regmap_update_bits(struct regmap *map, unsigned int reg,
     1585                                     unsigned int mask, unsigned int val)
     1586{
     1587        WARN_ONCE(1, "regmap API is disabled");
     1588        return -EINVAL;
     1589}
     1590
     1591static inline int regmap_update_bits_async(struct regmap *map, unsigned int reg,
     1592                                           unsigned int mask, unsigned int val)
     1593{
     1594        WARN_ONCE(1, "regmap API is disabled");
     1595        return -EINVAL;
     1596}
     1597
     1598static inline int regmap_update_bits_check(struct regmap *map, unsigned int reg,
     1599                                           unsigned int mask, unsigned int val,
     1600                                           bool *change)
     1601{
     1602        WARN_ONCE(1, "regmap API is disabled");
     1603        return -EINVAL;
     1604}
     1605
     1606static inline int
     1607regmap_update_bits_check_async(struct regmap *map, unsigned int reg,
     1608                               unsigned int mask, unsigned int val,
     1609                               bool *change)
     1610{
     1611        WARN_ONCE(1, "regmap API is disabled");
     1612        return -EINVAL;
     1613}
     1614
     1615static inline int regmap_write_bits(struct regmap *map, unsigned int reg,
     1616                                    unsigned int mask, unsigned int val)
     1617{
     1618        WARN_ONCE(1, "regmap API is disabled");
     1619        return -EINVAL;
     1620}
     1621
     1622static inline int regmap_field_write(struct regmap_field *field,
     1623                                     unsigned int val)
     1624{
     1625        WARN_ONCE(1, "regmap API is disabled");
     1626        return -EINVAL;
     1627}
     1628
     1629static inline int regmap_field_force_write(struct regmap_field *field,
     1630                                           unsigned int val)
     1631{
     1632        WARN_ONCE(1, "regmap API is disabled");
     1633        return -EINVAL;
     1634}
     1635
     1636static inline int regmap_field_update_bits(struct regmap_field *field,
     1637                                           unsigned int mask, unsigned int val)
     1638{
     1639        WARN_ONCE(1, "regmap API is disabled");
     1640        return -EINVAL;
     1641}
     1642
     1643static inline int
     1644regmap_field_force_update_bits(struct regmap_field *field,
     1645                               unsigned int mask, unsigned int val)
     1646{
     1647        WARN_ONCE(1, "regmap API is disabled");
     1648        return -EINVAL;
     1649}
     1650
     1651static inline int regmap_fields_write(struct regmap_field *field,
     1652                                      unsigned int id, unsigned int val)
     1653{
     1654        WARN_ONCE(1, "regmap API is disabled");
     1655        return -EINVAL;
     1656}
     1657
     1658static inline int regmap_fields_force_write(struct regmap_field *field,
     1659                                            unsigned int id, unsigned int val)
     1660{
     1661        WARN_ONCE(1, "regmap API is disabled");
     1662        return -EINVAL;
     1663}
     1664
     1665static inline int
     1666regmap_fields_update_bits(struct regmap_field *field, unsigned int id,
     1667                          unsigned int mask, unsigned int val)
     1668{
     1669        WARN_ONCE(1, "regmap API is disabled");
     1670        return -EINVAL;
     1671}
     1672
     1673static inline int
     1674regmap_fields_force_update_bits(struct regmap_field *field, unsigned int id,
     1675                                unsigned int mask, unsigned int val)
     1676{
     1677        WARN_ONCE(1, "regmap API is disabled");
     1678        return -EINVAL;
     1679}
     1680
    12881681static inline int regmap_get_val_bytes(struct regmap *map)
    12891682{
  • GPL/branches/uniaud32-next/lib32/internal.h

    r625 r652  
     1/* SPDX-License-Identifier: GPL-2.0 */
    12/*
    23 * Register map access API internal header
     
    56 *
    67 * 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.
    118 */
    12 /* from 4.19.163 */
     9
     10/* from 5.10.10 */
    1311
    1412#ifndef _REGMAP_INTERNAL_H
     
    2018#include <linux/list.h>
    2119#include <linux/wait.h>
    22 #include <linux/timer.h>
    23 #include <linux/bitops.h>
    24 #include <linux/bitmap.h>
    2520
    2621struct regmap;
     
    9994        bool (*volatile_reg)(struct device *dev, unsigned int reg);
    10095        bool (*precious_reg)(struct device *dev, unsigned int reg);
     96        bool (*writeable_noinc_reg)(struct device *dev, unsigned int reg);
    10197        bool (*readable_noinc_reg)(struct device *dev, unsigned int reg);
    10298        const struct regmap_access_table *wr_table;
     
    104100        const struct regmap_access_table *volatile_table;
    105101        const struct regmap_access_table *precious_table;
     102        const struct regmap_access_table *wr_noinc_table;
    106103        const struct regmap_access_table *rd_noinc_table;
    107104
     
    154151        /* if set, converts bulk read to single read */
    155152        bool use_single_read;
    156         /* if set, converts bulk read to single read */
     153        /* if set, converts bulk write to single write */
    157154        bool use_single_write;
    158155        /* if set, the device supports multi write mode */
     
    167164
    168165        struct hwspinlock *hwlock;
     166
     167        /* if set, the regmap core can sleep */
     168        bool can_sleep;
    169169};
    170170
     
    188188bool regmap_volatile(struct regmap *map, unsigned int reg);
    189189bool regmap_precious(struct regmap *map, unsigned int reg);
     190bool regmap_writeable_noinc(struct regmap *map, unsigned int reg);
    190191bool regmap_readable_noinc(struct regmap *map, unsigned int reg);
    191192
     
    222223#ifdef CONFIG_DEBUG_FS
    223224extern void regmap_debugfs_initcall(void);
    224 extern void regmap_debugfs_init(struct regmap *map, const char *name);
     225extern void regmap_debugfs_init(struct regmap *map);
    225226extern void regmap_debugfs_exit(struct regmap *map);
    226227
     
    232233#else
    233234static inline void regmap_debugfs_initcall(void) { }
    234 static inline void regmap_debugfs_init(struct regmap *map, const char *name) { }
     235static inline void regmap_debugfs_init(struct regmap *map) { }
    235236static inline void regmap_debugfs_exit(struct regmap *map) { }
    236237static inline void regmap_debugfs_disable(struct regmap *map) { }
     
    264265
    265266int _regmap_raw_write(struct regmap *map, unsigned int reg,
    266                       const void *val, size_t val_len);
     267                      const void *val, size_t val_len, bool noinc);
    267268
    268269void regmap_async_complete_cb(struct regmap_async *async, int ret);
  • GPL/branches/uniaud32-next/lib32/regcache-flat.c

    r625 r652  
    1 /*
    2  * Register cache access API - flat caching support
    3  *
    4  * Copyright 2012 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 cache access API - flat caching support
     4//
     5// Copyright 2012 Wolfson Microelectronics plc
     6//
     7// Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
     8
     9/* from 5.10.10 */
    1310
    1411#include <linux/device.h>
  • GPL/branches/uniaud32-next/lib32/regcache-lzo.c

    r615 r652  
    1 /*
    2  * Register cache access API - LZO caching support
    3  *
    4  * Copyright 2011 Wolfson Microelectronics plc
    5  *
    6  * Author: Dimitris Papastamos <dp@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.14.202 */
     1// SPDX-License-Identifier: GPL-2.0
     2//
     3// Register cache access API - LZO caching support
     4//
     5// Copyright 2011 Wolfson Microelectronics plc
     6//
     7// Author: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
     8
     9/* from 5.10.10 */
    1310
    1411#include <linux/device.h>
    1512#include <linux/lzo.h>
    1613#include <linux/slab.h>
    17 #include <linux/module.h>
    18 #include <linux/workqueue.h>
    19 #include <linux/byteorder/little_endian.h>
    20 #include <linux/printk.h>
    2114
    2215#include "internal.h"
     
    158151         */
    159152        bmp_size = map->num_reg_defaults_raw;
    160         sync_bmp = kmalloc_array(BITS_TO_LONGS(bmp_size), sizeof(long),
    161                                  GFP_KERNEL);
     153        sync_bmp = bitmap_zalloc(bmp_size, GFP_KERNEL);
    162154        if (!sync_bmp) {
    163155                ret = -ENOMEM;
    164156                goto err;
    165157        }
    166         bitmap_zero(sync_bmp, bmp_size);
    167158
    168159        /* allocate the lzo blocks and initialize them */
     
    171162                                        GFP_KERNEL);
    172163                if (!lzo_blocks[i]) {
    173                         kfree(sync_bmp);
     164                        bitmap_free(sync_bmp);
    174165                        ret = -ENOMEM;
    175166                        goto err;
     
    223214         */
    224215        if (lzo_blocks[0])
    225                 kfree(lzo_blocks[0]->sync_bmp);
     216                bitmap_free(lzo_blocks[0]->sync_bmp);
    226217        for (i = 0; i < blkcount; i++) {
    227218                if (lzo_blocks[i]) {
  • GPL/branches/uniaud32-next/lib32/regcache-rbtree.c

    r647 r652  
    1 /*
    2  * Register cache access API - rbtree caching support
    3  *
    4  * Copyright 2011 Wolfson Microelectronics plc
    5  *
    6  * Author: Dimitris Papastamos <dp@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 cache access API - rbtree caching support
     4//
     5// Copyright 2011 Wolfson Microelectronics plc
     6//
     7// Author: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
     8
     9/* from 5.10.10 */
    1310
    1411//#include <linux/debugfs.h>
     
    1714#include <linux/seq_file.h>
    1815#include <linux/slab.h>
    19 #include <linux/module.h>
    20 #include <linux/workqueue.h>
    21 #include <linux/byteorder/little_endian.h>
    22 #include <linux/printk.h>
    23 
     16#ifdef TARGET_OS2
     17#include <linux/bitmap.h>
     18#endif
    2419#include "internal.h"
    2520
    26 /*static inline*/ int regcache_rbtree_write(struct regmap *map, unsigned int reg,
     21static int regcache_rbtree_write(struct regmap *map, unsigned int reg,
    2722                                 unsigned int value);
    28 /*static inline*/ int regcache_rbtree_exit(struct regmap *map);
     23static int regcache_rbtree_exit(struct regmap *map);
    2924
    3025struct regcache_rbtree_node {
     
    3934        /* the actual rbtree node holding this block */
    4035        struct rb_node node;
    41 } /*__attribute__ ((packed))*/;
     36};
    4237
    4338struct regcache_rbtree_ctx {
     
    4641};
    4742
    48 /*static inline*/ inline void regcache_rbtree_get_base_top_reg(
     43static inline void regcache_rbtree_get_base_top_reg(
    4944        struct regmap *map,
    5045        struct regcache_rbtree_node *rbnode,
     
    5550}
    5651
    57 /*static inline*/ unsigned int regcache_rbtree_get_register(struct regmap *map,
     52static unsigned int regcache_rbtree_get_register(struct regmap *map,
    5853        struct regcache_rbtree_node *rbnode, unsigned int idx)
    5954{
     
    6156}
    6257
    63 /*static inline*/ void regcache_rbtree_set_register(struct regmap *map,
     58static void regcache_rbtree_set_register(struct regmap *map,
    6459                                         struct regcache_rbtree_node *rbnode,
    6560                                         unsigned int idx, unsigned int val)
     
    6964}
    7065
    71 /*static inline*/ struct regcache_rbtree_node *regcache_rbtree_lookup(struct regmap *map,
     66static struct regcache_rbtree_node *regcache_rbtree_lookup(struct regmap *map,
    7267                                                           unsigned int reg)
    7368{
     
    10398}
    10499
    105 /*static inline*/ int regcache_rbtree_insert(struct regmap *map, struct rb_root *root,
     100static int regcache_rbtree_insert(struct regmap *map, struct rb_root *root,
    106101                                  struct regcache_rbtree_node *rbnode)
    107102{
     
    139134
    140135#ifdef CONFIG_DEBUG_FS
    141 /*static inline*/ int rbtree_show(struct seq_file *s, void *ignored)
     136static int rbtree_show(struct seq_file *s, void *ignored)
    142137{
    143138        struct regmap *map = s->private;
     
    183178}
    184179
    185 /*static inline*/ int rbtree_open(struct inode *inode, struct file *file)
    186 {
    187         return single_open(file, rbtree_show, inode->i_private);
    188 }
    189 
    190 /*static inline*/ const struct file_operations rbtree_fops = {
    191         .open           = rbtree_open,
    192         .read           = seq_read,
    193         .llseek         = seq_lseek,
    194         .release        = single_release,
    195 };
    196 
    197 /*static inline*/ void rbtree_debugfs_init(struct regmap *map)
     180DEFINE_SHOW_ATTRIBUTE(rbtree);
     181
     182static void rbtree_debugfs_init(struct regmap *map)
    198183{
    199184        debugfs_create_file("rbtree", 0400, map->debugfs, map, &rbtree_fops);
     
    201186#endif
    202187
    203 /*static inline*/ int regcache_rbtree_init(struct regmap *map)
     188static int regcache_rbtree_init(struct regmap *map)
    204189{
    205190        struct regcache_rbtree_ctx *rbtree_ctx;
    206191        int i;
    207192        int ret;
     193
    208194#ifdef TARGET_OS2
    209195        // 2020-11-17 SHL FIXME patched struct rb_root
     
    240226}
    241227
    242 /*static inline*/ int regcache_rbtree_exit(struct regmap *map)
     228static int regcache_rbtree_exit(struct regmap *map)
    243229{
    244230        struct rb_node *next;
     
    269255}
    270256
    271 /*static inline*/ int regcache_rbtree_read(struct regmap *map,
     257static int regcache_rbtree_read(struct regmap *map,
    272258                                unsigned int reg, unsigned int *value)
    273259{
     
    289275
    290276
    291 /*static inline*/ int regcache_rbtree_insert_to_block(struct regmap *map,
     277static int regcache_rbtree_insert_to_block(struct regmap *map,
    292278                                           struct regcache_rbtree_node *rbnode,
    293279                                           unsigned int base_reg,
     
    324310                       * sizeof(*present));
    325311        } else {
    326                 present = (unsigned long *)rbnode->cache_present;
     312                present = rbnode->cache_present;
    327313        }
    328314
     
    338324        rbnode->blklen = blklen;
    339325        rbnode->base_reg = base_reg;
    340         rbnode->cache_present = (long*)present;
     326        rbnode->cache_present = present;
    341327
    342328        regcache_rbtree_set_register(map, rbnode, pos, value);
     
    344330}
    345331
    346 /*static inline*/ struct regcache_rbtree_node *
     332static struct regcache_rbtree_node *
    347333regcache_rbtree_node_alloc(struct regmap *map, unsigned int reg)
    348334{
     
    396382}
    397383
    398 /*static inline*/ int regcache_rbtree_write(struct regmap *map, unsigned int reg,
     384static int regcache_rbtree_write(struct regmap *map, unsigned int reg,
    399385                                 unsigned int value)
    400386{
     
    492478}
    493479
    494 /*static inline*/ int regcache_rbtree_sync(struct regmap *map, unsigned int min,
     480static int regcache_rbtree_sync(struct regmap *map, unsigned int min,
    495481                                unsigned int max)
    496482{
     
    524510
    525511                ret = regcache_sync_block(map, rbnode->block,
    526                                           (unsigned long *)rbnode->cache_present,
     512                                          rbnode->cache_present,
    527513                                          rbnode->base_reg, start, end);
    528514                if (ret != 0)
     
    533519}
    534520
    535 /*static inline*/ int regcache_rbtree_drop(struct regmap *map, unsigned int min,
     521static int regcache_rbtree_drop(struct regmap *map, unsigned int min,
    536522                                unsigned int max)
    537523{
     
    563549                        end = rbnode->blklen;
    564550
    565                 bitmap_clear((unsigned long *)rbnode->cache_present, start, end - start);
     551                bitmap_clear(rbnode->cache_present, start, end - start);
    566552        }
    567553
  • GPL/branches/uniaud32-next/lib32/regcache.c

    r625 r652  
    1 /*
    2  * Register cache access API
    3  *
    4  * Copyright 2011 Wolfson Microelectronics plc
    5  *
    6  * Author: Dimitris Papastamos <dp@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 cache access API
     4//
     5// Copyright 2011 Wolfson Microelectronics plc
     6//
     7// Author: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
     8
     9/* from 5.10.10 */
    1310
    1411//#include <linux/bsearch.h>
     
    253250                ret = map->cache_ops->read(map, reg, value);
    254251
     252#ifndef TARGET_OS2
     253                if (ret == 0)
     254                        trace_regmap_reg_read_cache(map, reg, *value);
     255#endif
    255256                return ret;
    256257        }
     
    358359                map->cache_ops->name);
    359360        name = map->cache_ops->name;
    360 
     361#ifndef TARGET_OS2
     362        trace_regcache_sync(map, name, "start");
     363#endif
    361364        if (!map->cache_dirty)
    362365                goto out;
     
    393396        regmap_async_complete(map);
    394397
     398#ifndef TARGET_OS2
     399        trace_regcache_sync(map, name, "stop");
     400#endif
    395401        return ret;
    396402}
     
    426432        dev_dbg(map->dev, "Syncing %s cache from %d-%d\n", name, min, max);
    427433
     434#ifndef TARGET_OS2
     435        trace_regcache_sync(map, name, "start region");
     436#endif
    428437        if (!map->cache_dirty)
    429438                goto out;
     
    445454        regmap_async_complete(map);
    446455
     456#ifndef TARGET_OS2
     457        trace_regcache_sync(map, name, "stop region");
     458#endif
    447459        return ret;
    448460}
     
    470482        map->lock(map->lock_arg);
    471483
     484#ifndef TARGET_OS2
     485        trace_regcache_drop_region(map, min, max);
     486#endif
    472487        ret = map->cache_ops->drop(map, min, max);
    473488
     
    495510        WARN_ON(map->cache_bypass && enable);
    496511        map->cache_only = enable;
     512#ifndef TARGET_OS2
     513        trace_regmap_cache_only(map, enable);
     514#endif
    497515        map->unlock(map->lock_arg);
    498516}
     
    537555        WARN_ON(map->cache_only && enable);
    538556        map->cache_bypass = enable;
     557#ifndef TARGET_OS2
     558        trace_regmap_cache_bypass(map, enable);
     559#endif
    539560        map->unlock(map->lock_arg);
    540561}
     
    713734        map->cache_bypass = true;
    714735
    715         ret = _regmap_raw_write(map, base, *data, count * val_bytes);
     736        ret = _regmap_raw_write(map, base, *data, count * val_bytes, false);
    716737        if (ret)
    717738                dev_err(map->dev, "Unable to sync registers %#x-%#x. %d\n",
  • 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.