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

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

File:
1 edited

Legend:

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

    r615 r625  
    1313 * published by the Free Software Foundation.
    1414 */
    15 /* from 4.14.202 */
     15/* from 4.19.163 */
    1616
    1717#include <linux/list.h>
    1818#include <linux/rbtree.h>
     19#include <linux/ktime.h>
    1920#include <linux/delay.h>
    2021#include <linux/err.h>
     
    2223#include <linux/lockdep.h>
    2324
    24 #define CONFIG_REGMAP
    25 
    2625struct module;
     26struct clk;
    2727struct device;
    2828struct i2c_client;
    2929struct irq_domain;
     30struct slim_device;
    3031struct spi_device;
    3132struct spmi_device;
     
    3435struct regmap_field;
    3536struct snd_ac97;
     37struct sdw_slave;
    3638
    3739/* An enum of all the supported cache types */
     
    124126#define regmap_read_poll_timeout(map, addr, val, cond, sleep_us, timeout_us) \
    125127({ \
    126         ktime_t timeout = ktime_add_us(ktime_get(), timeout_us); \
     128        u64 __timeout_us = (timeout_us); \
     129        unsigned long __sleep_us = (sleep_us); \
     130        ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \
     131        int __ret; \
     132        might_sleep_if(__sleep_us); \
     133        for (;;) { \
     134                __ret = regmap_read((map), (addr), &(val)); \
     135                if (__ret) \
     136                        break; \
     137                if (cond) \
     138                        break; \
     139                if ((__timeout_us) && \
     140                    ktime_compare(ktime_get(), __timeout) > 0) { \
     141                        __ret = regmap_read((map), (addr), &(val)); \
     142                        break; \
     143                } \
     144                if (__sleep_us) \
     145                        usleep_range((__sleep_us >> 2) + 1, __sleep_us); \
     146        } \
     147        __ret ?: ((cond) ? 0 : -ETIMEDOUT); \
     148})
     149
     150/**
     151 * regmap_field_read_poll_timeout - Poll until a condition is met or timeout
     152 *
     153 * @field: Regmap field to read from
     154 * @val: Unsigned integer variable to read the value into
     155 * @cond: Break condition (usually involving @val)
     156 * @sleep_us: Maximum time to sleep between reads in us (0
     157 *            tight-loops).  Should be less than ~20ms since usleep_range
     158 *            is used (see Documentation/timers/timers-howto.txt).
     159 * @timeout_us: Timeout in us, 0 means never timeout
     160 *
     161 * Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_field_read
     162 * error return value in case of a error read. In the two former cases,
     163 * the last read value at @addr is stored in @val. Must not be called
     164 * from atomic context if sleep_us or timeout_us are used.
     165 *
     166 * This is modelled after the readx_poll_timeout macros in linux/iopoll.h.
     167 */
     168#define regmap_field_read_poll_timeout(field, val, cond, sleep_us, timeout_us) \
     169({ \
     170        u64 __timeout_us = (timeout_us); \
     171        unsigned long __sleep_us = (sleep_us); \
     172        ktime_t timeout = ktime_add_us(ktime_get(), __timeout_us); \
    127173        int pollret; \
    128         might_sleep_if(sleep_us); \
     174        might_sleep_if(__sleep_us); \
    129175        for (;;) { \
    130                 pollret = regmap_read((map), (addr), &(val)); \
     176                pollret = regmap_field_read((field), &(val)); \
    131177                if (pollret) \
    132178                        break; \
    133179                if (cond) \
    134180                        break; \
    135                 if (timeout_us && ktime_compare(ktime_get(), timeout) > 0) { \
    136                         pollret = regmap_read((map), (addr), &(val)); \
     181                if (__timeout_us && ktime_compare(ktime_get(), timeout) > 0) { \
     182                        pollret = regmap_field_read((field), &(val)); \
    137183                        break; \
    138184                } \
    139                 if (sleep_us) \
    140                         usleep_range((sleep_us >> 2) + 1, sleep_us); \
     185                if (__sleep_us) \
     186                        usleep_range((__sleep_us >> 2) + 1, __sleep_us); \
    141187        } \
    142188        pollret ?: ((cond) ? 0 : -ETIMEDOUT); \
    143189})
    144190
     191#define CONFIG_REGMAP
    145192#ifdef CONFIG_REGMAP
    146193
     
    224271 *                check is performed on such table (a register is precious if
    225272 *                it belongs to one of the ranges specified by precious_table).
     273 * @readable_noinc_reg: Optional callback returning true if the register
     274 *                      supports multiple read operations without incrementing
     275 *                      the register number. If this field is NULL but
     276 *                      rd_noinc_table (see below) is not, the check is
     277 *                      performed on such table (a register is no increment
     278 *                      readable if it belongs to one of the ranges specified
     279 *                      by rd_noinc_table).
     280 * @disable_locking: This regmap is either protected by external means or
     281 *                   is guaranteed not be be accessed from multiple threads.
     282 *                   Don't use any locking mechanisms.
    226283 * @lock:         Optional lock callback (overrides regmap's default lock
    227284 *                function, based on spinlock or mutex).
     
    248305 * @volatile_table: As above, for volatile registers.
    249306 * @precious_table: As above, for precious registers.
     307 * @rd_noinc_table: As above, for no increment readable registers.
    250308 * @reg_defaults: Power on reset values for registers (for use with
    251309 *                register cache support).
     
    256314 * @write_flag_mask: Mask to be set in the top bytes of the register when doing
    257315 *                   a write. If both read_flag_mask and write_flag_mask are
    258  *                   empty the regmap_bus default masks are used.
     316 *                   empty and zero_flag_mask is not set the regmap_bus default
     317 *                   masks are used.
     318 * @zero_flag_mask: If set, read_flag_mask and write_flag_mask are used even
     319 *                   if they are both empty.
    259320 * @use_single_rw: If set, converts the bulk read and write operations into
    260321 *                  a series of single read and write operations. This is useful
     
    277338 * @ranges: Array of configuration entries for virtual address ranges.
    278339 * @num_ranges: Number of range configuration entries.
     340 * @use_hwlock: Indicate if a hardware spinlock should be used.
     341 * @hwlock_id: Specify the hardware spinlock id.
     342 * @hwlock_mode: The hardware spinlock mode, should be HWLOCK_IRQSTATE,
     343 *               HWLOCK_IRQ or 0.
    279344 */
    280345struct regmap_config {
     
    290355        bool (*volatile_reg)(struct device *dev, unsigned int reg);
    291356        bool (*precious_reg)(struct device *dev, unsigned int reg);
     357        bool (*readable_noinc_reg)(struct device *dev, unsigned int reg);
     358
     359        bool disable_locking;
    292360        regmap_lock lock;
    293361        regmap_unlock unlock;
     
    304372        const struct regmap_access_table *volatile_table;
    305373        const struct regmap_access_table *precious_table;
     374        const struct regmap_access_table *rd_noinc_table;
    306375        const struct reg_default *reg_defaults;
    307376        unsigned int num_reg_defaults;
     
    312381        unsigned long read_flag_mask;
    313382        unsigned long write_flag_mask;
     383        bool zero_flag_mask;
    314384
    315385        bool use_single_read;
     
    322392        const struct regmap_range_cfg *ranges;
    323393        unsigned int num_ranges;
     394
     395        bool use_hwlock;
     396        unsigned int hwlock_id;
     397        unsigned int hwlock_mode;
    324398};
    325399
     
    454528                                 struct lock_class_key *lock_key,
    455529                                 const char *lock_name);
     530struct regmap *__regmap_init_sccb(struct i2c_client *i2c,
     531                                  const struct regmap_config *config,
     532                                  struct lock_class_key *lock_key,
     533                                  const char *lock_name);
     534struct regmap *__regmap_init_slimbus(struct slim_device *slimbus,
     535                                 const struct regmap_config *config,
     536                                 struct lock_class_key *lock_key,
     537                                 const char *lock_name);
    456538struct regmap *__regmap_init_spi(struct spi_device *dev,
    457539                                 const struct regmap_config *config,
     
    479561                                  struct lock_class_key *lock_key,
    480562                                  const char *lock_name);
     563struct regmap *__regmap_init_sdw(struct sdw_slave *sdw,
     564                                 const struct regmap_config *config,
     565                                 struct lock_class_key *lock_key,
     566                                 const char *lock_name);
    481567
    482568struct regmap *__devm_regmap_init(struct device *dev,
     
    490576                                      struct lock_class_key *lock_key,
    491577                                      const char *lock_name);
     578struct regmap *__devm_regmap_init_sccb(struct i2c_client *i2c,
     579                                       const struct regmap_config *config,
     580                                       struct lock_class_key *lock_key,
     581                                       const char *lock_name);
    492582struct regmap *__devm_regmap_init_spi(struct spi_device *dev,
    493583                                      const struct regmap_config *config,
     
    516606                                       struct lock_class_key *lock_key,
    517607                                       const char *lock_name);
    518 
     608struct regmap *__devm_regmap_init_sdw(struct sdw_slave *sdw,
     609                                 const struct regmap_config *config,
     610                                 struct lock_class_key *lock_key,
     611                                 const char *lock_name);
     612struct regmap *__devm_regmap_init_slimbus(struct slim_device *slimbus,
     613                                 const struct regmap_config *config,
     614                                 struct lock_class_key *lock_key,
     615                                 const char *lock_name);
    519616/*
    520617 * Wrapper for regmap_init macros to include a unique lockdep key and name
     
    571668
    572669/**
     670 * regmap_init_sccb() - Initialise register map
     671 *
     672 * @i2c: Device that will be interacted with
     673 * @config: Configuration for register map
     674 *
     675 * The return value will be an ERR_PTR() on error or a valid pointer to
     676 * a struct regmap.
     677 */
     678#define regmap_init_sccb(i2c, config)                                   \
     679        __regmap_lockdep_wrapper(__regmap_init_sccb, #config,           \
     680                                i2c, config)
     681
     682/**
     683 * regmap_init_slimbus() - Initialise register map
     684 *
     685 * @slimbus: Device that will be interacted with
     686 * @config: Configuration for register map
     687 *
     688 * The return value will be an ERR_PTR() on error or a valid pointer to
     689 * a struct regmap.
     690 */
     691#define regmap_init_slimbus(slimbus, config)                            \
     692        __regmap_lockdep_wrapper(__regmap_init_slimbus, #config,        \
     693                                slimbus, config)
     694
     695/**
    573696 * regmap_init_spi() - Initialise register map
    574697 *
     
    665788
    666789/**
     790 * regmap_init_sdw() - Initialise register map
     791 *
     792 * @sdw: Device that will be interacted with
     793 * @config: Configuration for register map
     794 *
     795 * The return value will be an ERR_PTR() on error or a valid pointer to
     796 * a struct regmap.
     797 */
     798#define regmap_init_sdw(sdw, config)                                    \
     799        __regmap_lockdep_wrapper(__regmap_init_sdw, #config,            \
     800                                sdw, config)
     801
     802
     803/**
    667804 * devm_regmap_init() - Initialise managed register map
    668805 *
     
    696833
    697834/**
     835 * devm_regmap_init_sccb() - Initialise managed register map
     836 *
     837 * @i2c: Device that will be interacted with
     838 * @config: Configuration for register map
     839 *
     840 * The return value will be an ERR_PTR() on error or a valid pointer
     841 * to a struct regmap.  The regmap will be automatically freed by the
     842 * device management code.
     843 */
     844#define devm_regmap_init_sccb(i2c, config)                              \
     845        __regmap_lockdep_wrapper(__devm_regmap_init_sccb, #config,      \
     846                                i2c, config)
     847
     848/**
    698849 * devm_regmap_init_spi() - Initialise register map
    699850 *
     
    794945                                ac97, config)
    795946
     947/**
     948 * devm_regmap_init_sdw() - Initialise managed register map
     949 *
     950 * @sdw: Device that will be interacted with
     951 * @config: Configuration for register map
     952 *
     953 * The return value will be an ERR_PTR() on error or a valid pointer
     954 * to a struct regmap. The regmap will be automatically freed by the
     955 * device management code.
     956 */
     957#define devm_regmap_init_sdw(sdw, config)                               \
     958        __regmap_lockdep_wrapper(__devm_regmap_init_sdw, #config,       \
     959                                sdw, config)
     960
     961/**
     962 * devm_regmap_init_slimbus() - Initialise managed register map
     963 *
     964 * @slimbus: Device that will be interacted with
     965 * @config: Configuration for register map
     966 *
     967 * The return value will be an ERR_PTR() on error or a valid pointer
     968 * to a struct regmap. The regmap will be automatically freed by the
     969 * device management code.
     970 */
     971#define devm_regmap_init_slimbus(slimbus, config)                       \
     972        __regmap_lockdep_wrapper(__devm_regmap_init_slimbus, #config,   \
     973                                slimbus, config)
     974int regmap_mmio_attach_clk(struct regmap *map, struct clk *clk);
     975void regmap_mmio_detach_clk(struct regmap *map);
    796976void regmap_exit(struct regmap *map);
    797977int regmap_reinit_cache(struct regmap *map,
     
    815995int regmap_raw_read(struct regmap *map, unsigned int reg,
    816996                    void *val, size_t val_len);
     997int regmap_noinc_read(struct regmap *map, unsigned int reg,
     998                      void *val, size_t val_len);
    817999int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
    8181000                     size_t val_count);
     
    10191201                               unsigned int val)
    10201202{
    1021         WARN_ONCE(1, "regmap API is disabled");
     1203//      WARN_ONCE(1, "regmap API is disabled");
    10221204        return -EINVAL;
    10231205}
     
    10601242static inline int regmap_raw_read(struct regmap *map, unsigned int reg,
    10611243                                  void *val, size_t val_len)
     1244{
     1245        WARN_ONCE(1, "regmap API is disabled");
     1246        return -EINVAL;
     1247}
     1248
     1249static inline int regmap_noinc_read(struct regmap *map, unsigned int reg,
     1250                                    void *val, size_t val_len)
    10621251{
    10631252        WARN_ONCE(1, "regmap API is disabled");
Note: See TracChangeset for help on using the changeset viewer.