~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/regmap.h

Version: ~ [ linux-5.16-rc3 ] ~ [ linux-5.15.5 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.82 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.162 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.218 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.256 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.291 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.293 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #ifndef __LINUX_REGMAP_H
  2 #define __LINUX_REGMAP_H
  3 
  4 /*
  5  * Register map access API
  6  *
  7  * Copyright 2011 Wolfson Microelectronics plc
  8  *
  9  * 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 
 16 #include <linux/list.h>
 17 #include <linux/rbtree.h>
 18 #include <linux/delay.h>
 19 #include <linux/err.h>
 20 #include <linux/bug.h>
 21 #include <linux/lockdep.h>
 22 
 23 struct module;
 24 struct device;
 25 struct i2c_client;
 26 struct irq_domain;
 27 struct spi_device;
 28 struct spmi_device;
 29 struct regmap;
 30 struct regmap_range_cfg;
 31 struct regmap_field;
 32 struct snd_ac97;
 33 
 34 /* An enum of all the supported cache types */
 35 enum regcache_type {
 36         REGCACHE_NONE,
 37         REGCACHE_RBTREE,
 38         REGCACHE_COMPRESSED,
 39         REGCACHE_FLAT,
 40 };
 41 
 42 /**
 43  * struct reg_default - Default value for a register.
 44  *
 45  * @reg: Register address.
 46  * @def: Register default value.
 47  *
 48  * We use an array of structs rather than a simple array as many modern devices
 49  * have very sparse register maps.
 50  */
 51 struct reg_default {
 52         unsigned int reg;
 53         unsigned int def;
 54 };
 55 
 56 /**
 57  * struct reg_sequence - An individual write from a sequence of writes.
 58  *
 59  * @reg: Register address.
 60  * @def: Register value.
 61  * @delay_us: Delay to be applied after the register write in microseconds
 62  *
 63  * Register/value pairs for sequences of writes with an optional delay in
 64  * microseconds to be applied after each write.
 65  */
 66 struct reg_sequence {
 67         unsigned int reg;
 68         unsigned int def;
 69         unsigned int delay_us;
 70 };
 71 
 72 #define regmap_update_bits(map, reg, mask, val) \
 73         regmap_update_bits_base(map, reg, mask, val, NULL, false, false)
 74 #define regmap_update_bits_async(map, reg, mask, val)\
 75         regmap_update_bits_base(map, reg, mask, val, NULL, true, false)
 76 #define regmap_update_bits_check(map, reg, mask, val, change)\
 77         regmap_update_bits_base(map, reg, mask, val, change, false, false)
 78 #define regmap_update_bits_check_async(map, reg, mask, val, change)\
 79         regmap_update_bits_base(map, reg, mask, val, change, true, false)
 80 
 81 #define regmap_write_bits(map, reg, mask, val) \
 82         regmap_update_bits_base(map, reg, mask, val, NULL, false, true)
 83 
 84 #define regmap_field_write(field, val) \
 85         regmap_field_update_bits_base(field, ~0, val, NULL, false, false)
 86 #define regmap_field_force_write(field, val) \
 87         regmap_field_update_bits_base(field, ~0, val, NULL, false, true)
 88 #define regmap_field_update_bits(field, mask, val)\
 89         regmap_field_update_bits_base(field, mask, val, NULL, false, false)
 90 #define regmap_field_force_update_bits(field, mask, val) \
 91         regmap_field_update_bits_base(field, mask, val, NULL, false, true)
 92 
 93 #define regmap_fields_write(field, id, val) \
 94         regmap_fields_update_bits_base(field, id, ~0, val, NULL, false, false)
 95 #define regmap_fields_force_write(field, id, val) \
 96         regmap_fields_update_bits_base(field, id, ~0, val, NULL, false, true)
 97 #define regmap_fields_update_bits(field, id, mask, val)\
 98         regmap_fields_update_bits_base(field, id, mask, val, NULL, false, false)
 99 #define regmap_fields_force_update_bits(field, id, mask, val) \
100         regmap_fields_update_bits_base(field, id, mask, val, NULL, false, true)
101 
102 /**
103  * regmap_read_poll_timeout - Poll until a condition is met or a timeout occurs
104  *
105  * @map: Regmap to read from
106  * @addr: Address to poll
107  * @val: Unsigned integer variable to read the value into
108  * @cond: Break condition (usually involving @val)
109  * @sleep_us: Maximum time to sleep between reads in us (0
110  *            tight-loops).  Should be less than ~20ms since usleep_range
111  *            is used (see Documentation/timers/timers-howto.txt).
112  * @timeout_us: Timeout in us, 0 means never timeout
113  *
114  * Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_read
115  * error return value in case of a error read. In the two former cases,
116  * the last read value at @addr is stored in @val. Must not be called
117  * from atomic context if sleep_us or timeout_us are used.
118  *
119  * This is modelled after the readx_poll_timeout macros in linux/iopoll.h.
120  */
121 #define regmap_read_poll_timeout(map, addr, val, cond, sleep_us, timeout_us) \
122 ({ \
123         ktime_t timeout = ktime_add_us(ktime_get(), timeout_us); \
124         int pollret; \
125         might_sleep_if(sleep_us); \
126         for (;;) { \
127                 pollret = regmap_read((map), (addr), &(val)); \
128                 if (pollret) \
129                         break; \
130                 if (cond) \
131                         break; \
132                 if (timeout_us && ktime_compare(ktime_get(), timeout) > 0) { \
133                         pollret = regmap_read((map), (addr), &(val)); \
134                         break; \
135                 } \
136                 if (sleep_us) \
137                         usleep_range((sleep_us >> 2) + 1, sleep_us); \
138         } \
139         pollret ?: ((cond) ? 0 : -ETIMEDOUT); \
140 })
141 
142 #ifdef CONFIG_REGMAP
143 
144 enum regmap_endian {
145         /* Unspecified -> 0 -> Backwards compatible default */
146         REGMAP_ENDIAN_DEFAULT = 0,
147         REGMAP_ENDIAN_BIG,
148         REGMAP_ENDIAN_LITTLE,
149         REGMAP_ENDIAN_NATIVE,
150 };
151 
152 /**
153  * struct regmap_range - A register range, used for access related checks
154  *                       (readable/writeable/volatile/precious checks)
155  *
156  * @range_min: address of first register
157  * @range_max: address of last register
158  */
159 struct regmap_range {
160         unsigned int range_min;
161         unsigned int range_max;
162 };
163 
164 #define regmap_reg_range(low, high) { .range_min = low, .range_max = high, }
165 
166 /**
167  * struct regmap_access_table - A table of register ranges for access checks
168  *
169  * @yes_ranges : pointer to an array of regmap ranges used as "yes ranges"
170  * @n_yes_ranges: size of the above array
171  * @no_ranges: pointer to an array of regmap ranges used as "no ranges"
172  * @n_no_ranges: size of the above array
173  *
174  * A table of ranges including some yes ranges and some no ranges.
175  * If a register belongs to a no_range, the corresponding check function
176  * will return false. If a register belongs to a yes range, the corresponding
177  * check function will return true. "no_ranges" are searched first.
178  */
179 struct regmap_access_table {
180         const struct regmap_range *yes_ranges;
181         unsigned int n_yes_ranges;
182         const struct regmap_range *no_ranges;
183         unsigned int n_no_ranges;
184 };
185 
186 typedef void (*regmap_lock)(void *);
187 typedef void (*regmap_unlock)(void *);
188 
189 /**
190  * struct regmap_config - Configuration for the register map of a device.
191  *
192  * @name: Optional name of the regmap. Useful when a device has multiple
193  *        register regions.
194  *
195  * @reg_bits: Number of bits in a register address, mandatory.
196  * @reg_stride: The register address stride. Valid register addresses are a
197  *              multiple of this value. If set to 0, a value of 1 will be
198  *              used.
199  * @pad_bits: Number of bits of padding between register and value.
200  * @val_bits: Number of bits in a register value, mandatory.
201  *
202  * @writeable_reg: Optional callback returning true if the register
203  *                 can be written to. If this field is NULL but wr_table
204  *                 (see below) is not, the check is performed on such table
205  *                 (a register is writeable if it belongs to one of the ranges
206  *                  specified by wr_table).
207  * @readable_reg: Optional callback returning true if the register
208  *                can be read from. If this field is NULL but rd_table
209  *                 (see below) is not, the check is performed on such table
210  *                 (a register is readable if it belongs to one of the ranges
211  *                  specified by rd_table).
212  * @volatile_reg: Optional callback returning true if the register
213  *                value can't be cached. If this field is NULL but
214  *                volatile_table (see below) is not, the check is performed on
215  *                such table (a register is volatile if it belongs to one of
216  *                the ranges specified by volatile_table).
217  * @precious_reg: Optional callback returning true if the register
218  *                should not be read outside of a call from the driver
219  *                (e.g., a clear on read interrupt status register). If this
220  *                field is NULL but precious_table (see below) is not, the
221  *                check is performed on such table (a register is precious if
222  *                it belongs to one of the ranges specified by precious_table).
223  * @lock:         Optional lock callback (overrides regmap's default lock
224  *                function, based on spinlock or mutex).
225  * @unlock:       As above for unlocking.
226  * @lock_arg:     this field is passed as the only argument of lock/unlock
227  *                functions (ignored in case regular lock/unlock functions
228  *                are not overridden).
229  * @reg_read:     Optional callback that if filled will be used to perform
230  *                all the reads from the registers. Should only be provided for
231  *                devices whose read operation cannot be represented as a simple
232  *                read operation on a bus such as SPI, I2C, etc. Most of the
233  *                devices do not need this.
234  * @reg_write:    Same as above for writing.
235  * @fast_io:      Register IO is fast. Use a spinlock instead of a mutex
236  *                to perform locking. This field is ignored if custom lock/unlock
237  *                functions are used (see fields lock/unlock of struct regmap_config).
238  *                This field is a duplicate of a similar file in
239  *                'struct regmap_bus' and serves exact same purpose.
240  *                 Use it only for "no-bus" cases.
241  * @max_register: Optional, specifies the maximum valid register address.
242  * @wr_table:     Optional, points to a struct regmap_access_table specifying
243  *                valid ranges for write access.
244  * @rd_table:     As above, for read access.
245  * @volatile_table: As above, for volatile registers.
246  * @precious_table: As above, for precious registers.
247  * @reg_defaults: Power on reset values for registers (for use with
248  *                register cache support).
249  * @num_reg_defaults: Number of elements in reg_defaults.
250  *
251  * @read_flag_mask: Mask to be set in the top bytes of the register when doing
252  *                  a read.
253  * @write_flag_mask: Mask to be set in the top bytes of the register when doing
254  *                   a write. If both read_flag_mask and write_flag_mask are
255  *                   empty the regmap_bus default masks are used.
256  * @use_single_rw: If set, converts the bulk read and write operations into
257  *                  a series of single read and write operations. This is useful
258  *                  for device that does not support bulk read and write.
259  * @can_multi_write: If set, the device supports the multi write mode of bulk
260  *                   write operations, if clear multi write requests will be
261  *                   split into individual write operations
262  *
263  * @cache_type: The actual cache type.
264  * @reg_defaults_raw: Power on reset values for registers (for use with
265  *                    register cache support).
266  * @num_reg_defaults_raw: Number of elements in reg_defaults_raw.
267  * @reg_format_endian: Endianness for formatted register addresses. If this is
268  *                     DEFAULT, the @reg_format_endian_default value from the
269  *                     regmap bus is used.
270  * @val_format_endian: Endianness for formatted register values. If this is
271  *                     DEFAULT, the @reg_format_endian_default value from the
272  *                     regmap bus is used.
273  *
274  * @ranges: Array of configuration entries for virtual address ranges.
275  * @num_ranges: Number of range configuration entries.
276  */
277 struct regmap_config {
278         const char *name;
279 
280         int reg_bits;
281         int reg_stride;
282         int pad_bits;
283         int val_bits;
284 
285         bool (*writeable_reg)(struct device *dev, unsigned int reg);
286         bool (*readable_reg)(struct device *dev, unsigned int reg);
287         bool (*volatile_reg)(struct device *dev, unsigned int reg);
288         bool (*precious_reg)(struct device *dev, unsigned int reg);
289         regmap_lock lock;
290         regmap_unlock unlock;
291         void *lock_arg;
292 
293         int (*reg_read)(void *context, unsigned int reg, unsigned int *val);
294         int (*reg_write)(void *context, unsigned int reg, unsigned int val);
295 
296         bool fast_io;
297 
298         unsigned int max_register;
299         const struct regmap_access_table *wr_table;
300         const struct regmap_access_table *rd_table;
301         const struct regmap_access_table *volatile_table;
302         const struct regmap_access_table *precious_table;
303         const struct reg_default *reg_defaults;
304         unsigned int num_reg_defaults;
305         enum regcache_type cache_type;
306         const void *reg_defaults_raw;
307         unsigned int num_reg_defaults_raw;
308 
309         unsigned long read_flag_mask;
310         unsigned long write_flag_mask;
311 
312         bool use_single_rw;
313         bool can_multi_write;
314 
315         enum regmap_endian reg_format_endian;
316         enum regmap_endian val_format_endian;
317 
318         const struct regmap_range_cfg *ranges;
319         unsigned int num_ranges;
320 };
321 
322 /**
323  * struct regmap_range_cfg - Configuration for indirectly accessed or paged
324  *                           registers.
325  *
326  * @name: Descriptive name for diagnostics
327  *
328  * @range_min: Address of the lowest register address in virtual range.
329  * @range_max: Address of the highest register in virtual range.
330  *
331  * @selector_reg: Register with selector field.
332  * @selector_mask: Bit shift for selector value.
333  * @selector_shift: Bit mask for selector value.
334  *
335  * @window_start: Address of first (lowest) register in data window.
336  * @window_len: Number of registers in data window.
337  *
338  * Registers, mapped to this virtual range, are accessed in two steps:
339  *     1. page selector register update;
340  *     2. access through data window registers.
341  */
342 struct regmap_range_cfg {
343         const char *name;
344 
345         /* Registers of virtual address range */
346         unsigned int range_min;
347         unsigned int range_max;
348 
349         /* Page selector for indirect addressing */
350         unsigned int selector_reg;
351         unsigned int selector_mask;
352         int selector_shift;
353 
354         /* Data window (per each page) */
355         unsigned int window_start;
356         unsigned int window_len;
357 };
358 
359 struct regmap_async;
360 
361 typedef int (*regmap_hw_write)(void *context, const void *data,
362                                size_t count);
363 typedef int (*regmap_hw_gather_write)(void *context,
364                                       const void *reg, size_t reg_len,
365                                       const void *val, size_t val_len);
366 typedef int (*regmap_hw_async_write)(void *context,
367                                      const void *reg, size_t reg_len,
368                                      const void *val, size_t val_len,
369                                      struct regmap_async *async);
370 typedef int (*regmap_hw_read)(void *context,
371                               const void *reg_buf, size_t reg_size,
372                               void *val_buf, size_t val_size);
373 typedef int (*regmap_hw_reg_read)(void *context, unsigned int reg,
374                                   unsigned int *val);
375 typedef int (*regmap_hw_reg_write)(void *context, unsigned int reg,
376                                    unsigned int val);
377 typedef int (*regmap_hw_reg_update_bits)(void *context, unsigned int reg,
378                                          unsigned int mask, unsigned int val);
379 typedef struct regmap_async *(*regmap_hw_async_alloc)(void);
380 typedef void (*regmap_hw_free_context)(void *context);
381 
382 /**
383  * struct regmap_bus - Description of a hardware bus for the register map
384  *                     infrastructure.
385  *
386  * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
387  *           to perform locking. This field is ignored if custom lock/unlock
388  *           functions are used (see fields lock/unlock of
389  *           struct regmap_config).
390  * @write: Write operation.
391  * @gather_write: Write operation with split register/value, return -ENOTSUPP
392  *                if not implemented  on a given device.
393  * @async_write: Write operation which completes asynchronously, optional and
394  *               must serialise with respect to non-async I/O.
395  * @reg_write: Write a single register value to the given register address. This
396  *             write operation has to complete when returning from the function.
397  * @reg_update_bits: Update bits operation to be used against volatile
398  *                   registers, intended for devices supporting some mechanism
399  *                   for setting clearing bits without having to
400  *                   read/modify/write.
401  * @read: Read operation.  Data is returned in the buffer used to transmit
402  *         data.
403  * @reg_read: Read a single register value from a given register address.
404  * @free_context: Free context.
405  * @async_alloc: Allocate a regmap_async() structure.
406  * @read_flag_mask: Mask to be set in the top byte of the register when doing
407  *                  a read.
408  * @reg_format_endian_default: Default endianness for formatted register
409  *     addresses. Used when the regmap_config specifies DEFAULT. If this is
410  *     DEFAULT, BIG is assumed.
411  * @val_format_endian_default: Default endianness for formatted register
412  *     values. Used when the regmap_config specifies DEFAULT. If this is
413  *     DEFAULT, BIG is assumed.
414  * @max_raw_read: Max raw read size that can be used on the bus.
415  * @max_raw_write: Max raw write size that can be used on the bus.
416  */
417 struct regmap_bus {
418         bool fast_io;
419         regmap_hw_write write;
420         regmap_hw_gather_write gather_write;
421         regmap_hw_async_write async_write;
422         regmap_hw_reg_write reg_write;
423         regmap_hw_reg_update_bits reg_update_bits;
424         regmap_hw_read read;
425         regmap_hw_reg_read reg_read;
426         regmap_hw_free_context free_context;
427         regmap_hw_async_alloc async_alloc;
428         u8 read_flag_mask;
429         enum regmap_endian reg_format_endian_default;
430         enum regmap_endian val_format_endian_default;
431         size_t max_raw_read;
432         size_t max_raw_write;
433 };
434 
435 /*
436  * __regmap_init functions.
437  *
438  * These functions take a lock key and name parameter, and should not be called
439  * directly. Instead, use the regmap_init macros that generate a key and name
440  * for each call.
441  */
442 struct regmap *__regmap_init(struct device *dev,
443                              const struct regmap_bus *bus,
444                              void *bus_context,
445                              const struct regmap_config *config,
446                              struct lock_class_key *lock_key,
447                              const char *lock_name);
448 struct regmap *__regmap_init_i2c(struct i2c_client *i2c,
449                                  const struct regmap_config *config,
450                                  struct lock_class_key *lock_key,
451                                  const char *lock_name);
452 struct regmap *__regmap_init_spi(struct spi_device *dev,
453                                  const struct regmap_config *config,
454                                  struct lock_class_key *lock_key,
455                                  const char *lock_name);
456 struct regmap *__regmap_init_spmi_base(struct spmi_device *dev,
457                                        const struct regmap_config *config,
458                                        struct lock_class_key *lock_key,
459                                        const char *lock_name);
460 struct regmap *__regmap_init_spmi_ext(struct spmi_device *dev,
461                                       const struct regmap_config *config,
462                                       struct lock_class_key *lock_key,
463                                       const char *lock_name);
464 struct regmap *__regmap_init_mmio_clk(struct device *dev, const char *clk_id,
465                                       void __iomem *regs,
466                                       const struct regmap_config *config,
467                                       struct lock_class_key *lock_key,
468                                       const char *lock_name);
469 struct regmap *__regmap_init_ac97(struct snd_ac97 *ac97,
470                                   const struct regmap_config *config,
471                                   struct lock_class_key *lock_key,
472                                   const char *lock_name);
473 
474 struct regmap *__devm_regmap_init(struct device *dev,
475                                   const struct regmap_bus *bus,
476                                   void *bus_context,
477                                   const struct regmap_config *config,
478                                   struct lock_class_key *lock_key,
479                                   const char *lock_name);
480 struct regmap *__devm_regmap_init_i2c(struct i2c_client *i2c,
481                                       const struct regmap_config *config,
482                                       struct lock_class_key *lock_key,
483                                       const char *lock_name);
484 struct regmap *__devm_regmap_init_spi(struct spi_device *dev,
485                                       const struct regmap_config *config,
486                                       struct lock_class_key *lock_key,
487                                       const char *lock_name);
488 struct regmap *__devm_regmap_init_spmi_base(struct spmi_device *dev,
489                                             const struct regmap_config *config,
490                                             struct lock_class_key *lock_key,
491                                             const char *lock_name);
492 struct regmap *__devm_regmap_init_spmi_ext(struct spmi_device *dev,
493                                            const struct regmap_config *config,
494                                            struct lock_class_key *lock_key,
495                                            const char *lock_name);
496 struct regmap *__devm_regmap_init_mmio_clk(struct device *dev,
497                                            const char *clk_id,
498                                            void __iomem *regs,
499                                            const struct regmap_config *config,
500                                            struct lock_class_key *lock_key,
501                                            const char *lock_name);
502 struct regmap *__devm_regmap_init_ac97(struct snd_ac97 *ac97,
503                                        const struct regmap_config *config,
504                                        struct lock_class_key *lock_key,
505                                        const char *lock_name);
506 
507 /*
508  * Wrapper for regmap_init macros to include a unique lockdep key and name
509  * for each call. No-op if CONFIG_LOCKDEP is not set.
510  *
511  * @fn: Real function to call (in the form __[*_]regmap_init[_*])
512  * @name: Config variable name (#config in the calling macro)
513  **/
514 #ifdef CONFIG_LOCKDEP
515 #define __regmap_lockdep_wrapper(fn, name, ...)                         \
516 (                                                                       \
517         ({                                                              \
518                 static struct lock_class_key _key;                      \
519                 fn(__VA_ARGS__, &_key,                                  \
520                         KBUILD_BASENAME ":"                             \
521                         __stringify(__LINE__) ":"                       \
522                         "(" name ")->lock");                            \
523         })                                                              \
524 )
525 #else
526 #define __regmap_lockdep_wrapper(fn, name, ...) fn(__VA_ARGS__, NULL, NULL)
527 #endif
528 
529 /**
530  * regmap_init() - Initialise register map
531  *
532  * @dev: Device that will be interacted with
533  * @bus: Bus-specific callbacks to use with device
534  * @bus_context: Data passed to bus-specific callbacks
535  * @config: Configuration for register map
536  *
537  * The return value will be an ERR_PTR() on error or a valid pointer to
538  * a struct regmap.  This function should generally not be called
539  * directly, it should be called by bus-specific init functions.
540  */
541 #define regmap_init(dev, bus, bus_context, config)                      \
542         __regmap_lockdep_wrapper(__regmap_init, #config,                \
543                                 dev, bus, bus_context, config)
544 int regmap_attach_dev(struct device *dev, struct regmap *map,
545                       const struct regmap_config *config);
546 
547 /**
548  * regmap_init_i2c() - Initialise register map
549  *
550  * @i2c: Device that will be interacted with
551  * @config: Configuration for register map
552  *
553  * The return value will be an ERR_PTR() on error or a valid pointer to
554  * a struct regmap.
555  */
556 #define regmap_init_i2c(i2c, config)                                    \
557         __regmap_lockdep_wrapper(__regmap_init_i2c, #config,            \
558                                 i2c, config)
559 
560 /**
561  * regmap_init_spi() - Initialise register map
562  *
563  * @dev: Device that will be interacted with
564  * @config: Configuration for register map
565  *
566  * The return value will be an ERR_PTR() on error or a valid pointer to
567  * a struct regmap.
568  */
569 #define regmap_init_spi(dev, config)                                    \
570         __regmap_lockdep_wrapper(__regmap_init_spi, #config,            \
571                                 dev, config)
572 
573 /**
574  * regmap_init_spmi_base() - Create regmap for the Base register space
575  *
576  * @dev:        SPMI device that will be interacted with
577  * @config:     Configuration for register map
578  *
579  * The return value will be an ERR_PTR() on error or a valid pointer to
580  * a struct regmap.
581  */
582 #define regmap_init_spmi_base(dev, config)                              \
583         __regmap_lockdep_wrapper(__regmap_init_spmi_base, #config,      \
584                                 dev, config)
585 
586 /**
587  * regmap_init_spmi_ext() - Create regmap for Ext register space
588  *
589  * @dev:        Device that will be interacted with
590  * @config:     Configuration for register map
591  *
592  * The return value will be an ERR_PTR() on error or a valid pointer to
593  * a struct regmap.
594  */
595 #define regmap_init_spmi_ext(dev, config)                               \
596         __regmap_lockdep_wrapper(__regmap_init_spmi_ext, #config,       \
597                                 dev, config)
598 
599 /**
600  * regmap_init_mmio_clk() - Initialise register map with register clock
601  *
602  * @dev: Device that will be interacted with
603  * @clk_id: register clock consumer ID
604  * @regs: Pointer to memory-mapped IO region
605  * @config: Configuration for register map
606  *
607  * The return value will be an ERR_PTR() on error or a valid pointer to
608  * a struct regmap.
609  */
610 #define regmap_init_mmio_clk(dev, clk_id, regs, config)                 \
611         __regmap_lockdep_wrapper(__regmap_init_mmio_clk, #config,       \
612                                 dev, clk_id, regs, config)
613 
614 /**
615  * regmap_init_mmio() - Initialise register map
616  *
617  * @dev: Device that will be interacted with
618  * @regs: Pointer to memory-mapped IO region
619  * @config: Configuration for register map
620  *
621  * The return value will be an ERR_PTR() on error or a valid pointer to
622  * a struct regmap.
623  */
624 #define regmap_init_mmio(dev, regs, config)             \
625         regmap_init_mmio_clk(dev, NULL, regs, config)
626 
627 /**
628  * regmap_init_ac97() - Initialise AC'97 register map
629  *
630  * @ac97: Device that will be interacted with
631  * @config: Configuration for register map
632  *
633  * The return value will be an ERR_PTR() on error or a valid pointer to
634  * a struct regmap.
635  */
636 #define regmap_init_ac97(ac97, config)                                  \
637         __regmap_lockdep_wrapper(__regmap_init_ac97, #config,           \
638                                 ac97, config)
639 bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg);
640 
641 /**
642  * devm_regmap_init() - Initialise managed register map
643  *
644  * @dev: Device that will be interacted with
645  * @bus: Bus-specific callbacks to use with device
646  * @bus_context: Data passed to bus-specific callbacks
647  * @config: Configuration for register map
648  *
649  * The return value will be an ERR_PTR() on error or a valid pointer
650  * to a struct regmap.  This function should generally not be called
651  * directly, it should be called by bus-specific init functions.  The
652  * map will be automatically freed by the device management code.
653  */
654 #define devm_regmap_init(dev, bus, bus_context, config)                 \
655         __regmap_lockdep_wrapper(__devm_regmap_init, #config,           \
656                                 dev, bus, bus_context, config)
657 
658 /**
659  * devm_regmap_init_i2c() - Initialise managed register map
660  *
661  * @i2c: Device that will be interacted with
662  * @config: Configuration for register map
663  *
664  * The return value will be an ERR_PTR() on error or a valid pointer
665  * to a struct regmap.  The regmap will be automatically freed by the
666  * device management code.
667  */
668 #define devm_regmap_init_i2c(i2c, config)                               \
669         __regmap_lockdep_wrapper(__devm_regmap_init_i2c, #config,       \
670                                 i2c, config)
671 
672 /**
673  * devm_regmap_init_spi() - Initialise register map
674  *
675  * @dev: Device that will be interacted with
676  * @config: Configuration for register map
677  *
678  * The return value will be an ERR_PTR() on error or a valid pointer
679  * to a struct regmap.  The map will be automatically freed by the
680  * device management code.
681  */
682 #define devm_regmap_init_spi(dev, config)                               \
683         __regmap_lockdep_wrapper(__devm_regmap_init_spi, #config,       \
684                                 dev, config)
685 
686 /**
687  * devm_regmap_init_spmi_base() - Create managed regmap for Base register space
688  *
689  * @dev:        SPMI device that will be interacted with
690  * @config:     Configuration for register map
691  *
692  * The return value will be an ERR_PTR() on error or a valid pointer
693  * to a struct regmap.  The regmap will be automatically freed by the
694  * device management code.
695  */
696 #define devm_regmap_init_spmi_base(dev, config)                         \
697         __regmap_lockdep_wrapper(__devm_regmap_init_spmi_base, #config, \
698                                 dev, config)
699 
700 /**
701  * devm_regmap_init_spmi_ext() - Create managed regmap for Ext register space
702  *
703  * @dev:        SPMI device that will be interacted with
704  * @config:     Configuration for register map
705  *
706  * The return value will be an ERR_PTR() on error or a valid pointer
707  * to a struct regmap.  The regmap will be automatically freed by the
708  * device management code.
709  */
710 #define devm_regmap_init_spmi_ext(dev, config)                          \
711         __regmap_lockdep_wrapper(__devm_regmap_init_spmi_ext, #config,  \
712                                 dev, config)
713 
714 /**
715  * devm_regmap_init_mmio_clk() - Initialise managed register map with clock
716  *
717  * @dev: Device that will be interacted with
718  * @clk_id: register clock consumer ID
719  * @regs: Pointer to memory-mapped IO region
720  * @config: Configuration for register map
721  *
722  * The return value will be an ERR_PTR() on error or a valid pointer
723  * to a struct regmap.  The regmap will be automatically freed by the
724  * device management code.
725  */
726 #define devm_regmap_init_mmio_clk(dev, clk_id, regs, config)            \
727         __regmap_lockdep_wrapper(__devm_regmap_init_mmio_clk, #config,  \
728                                 dev, clk_id, regs, config)
729 
730 /**
731  * devm_regmap_init_mmio() - Initialise managed register map
732  *
733  * @dev: Device that will be interacted with
734  * @regs: Pointer to memory-mapped IO region
735  * @config: Configuration for register map
736  *
737  * The return value will be an ERR_PTR() on error or a valid pointer
738  * to a struct regmap.  The regmap will be automatically freed by the
739  * device management code.
740  */
741 #define devm_regmap_init_mmio(dev, regs, config)                \
742         devm_regmap_init_mmio_clk(dev, NULL, regs, config)
743 
744 /**
745  * devm_regmap_init_ac97() - Initialise AC'97 register map
746  *
747  * @ac97: Device that will be interacted with
748  * @config: Configuration for register map
749  *
750  * The return value will be an ERR_PTR() on error or a valid pointer
751  * to a struct regmap.  The regmap will be automatically freed by the
752  * device management code.
753  */
754 #define devm_regmap_init_ac97(ac97, config)                             \
755         __regmap_lockdep_wrapper(__devm_regmap_init_ac97, #config,      \
756                                 ac97, config)
757 
758 void regmap_exit(struct regmap *map);
759 int regmap_reinit_cache(struct regmap *map,
760                         const struct regmap_config *config);
761 struct regmap *dev_get_regmap(struct device *dev, const char *name);
762 struct device *regmap_get_device(struct regmap *map);
763 int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
764 int regmap_write_async(struct regmap *map, unsigned int reg, unsigned int val);
765 int regmap_raw_write(struct regmap *map, unsigned int reg,
766                      const void *val, size_t val_len);
767 int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
768                         size_t val_count);
769 int regmap_multi_reg_write(struct regmap *map, const struct reg_sequence *regs,
770                         int num_regs);
771 int regmap_multi_reg_write_bypassed(struct regmap *map,
772                                     const struct reg_sequence *regs,
773                                     int num_regs);
774 int regmap_raw_write_async(struct regmap *map, unsigned int reg,
775                            const void *val, size_t val_len);
776 int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
777 int regmap_raw_read(struct regmap *map, unsigned int reg,
778                     void *val, size_t val_len);
779 int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
780                      size_t val_count);
781 int regmap_update_bits_base(struct regmap *map, unsigned int reg,
782                             unsigned int mask, unsigned int val,
783                             bool *change, bool async, bool force);
784 int regmap_get_val_bytes(struct regmap *map);
785 int regmap_get_max_register(struct regmap *map);
786 int regmap_get_reg_stride(struct regmap *map);
787 int regmap_async_complete(struct regmap *map);
788 bool regmap_can_raw_write(struct regmap *map);
789 size_t regmap_get_raw_read_max(struct regmap *map);
790 size_t regmap_get_raw_write_max(struct regmap *map);
791 
792 int regcache_sync(struct regmap *map);
793 int regcache_sync_region(struct regmap *map, unsigned int min,
794                          unsigned int max);
795 int regcache_drop_region(struct regmap *map, unsigned int min,
796                          unsigned int max);
797 void regcache_cache_only(struct regmap *map, bool enable);
798 void regcache_cache_bypass(struct regmap *map, bool enable);
799 void regcache_mark_dirty(struct regmap *map);
800 
801 bool regmap_check_range_table(struct regmap *map, unsigned int reg,
802                               const struct regmap_access_table *table);
803 
804 int regmap_register_patch(struct regmap *map, const struct reg_sequence *regs,
805                           int num_regs);
806 int regmap_parse_val(struct regmap *map, const void *buf,
807                                 unsigned int *val);
808 
809 static inline bool regmap_reg_in_range(unsigned int reg,
810                                        const struct regmap_range *range)
811 {
812         return reg >= range->range_min && reg <= range->range_max;
813 }
814 
815 bool regmap_reg_in_ranges(unsigned int reg,
816                           const struct regmap_range *ranges,
817                           unsigned int nranges);
818 
819 /**
820  * struct reg_field - Description of an register field
821  *
822  * @reg: Offset of the register within the regmap bank
823  * @lsb: lsb of the register field.
824  * @msb: msb of the register field.
825  * @id_size: port size if it has some ports
826  * @id_offset: address offset for each ports
827  */
828 struct reg_field {
829         unsigned int reg;
830         unsigned int lsb;
831         unsigned int msb;
832         unsigned int id_size;
833         unsigned int id_offset;
834 };
835 
836 #define REG_FIELD(_reg, _lsb, _msb) {           \
837                                 .reg = _reg,    \
838                                 .lsb = _lsb,    \
839                                 .msb = _msb,    \
840                                 }
841 
842 struct regmap_field *regmap_field_alloc(struct regmap *regmap,
843                 struct reg_field reg_field);
844 void regmap_field_free(struct regmap_field *field);
845 
846 struct regmap_field *devm_regmap_field_alloc(struct device *dev,
847                 struct regmap *regmap, struct reg_field reg_field);
848 void devm_regmap_field_free(struct device *dev, struct regmap_field *field);
849 
850 int regmap_field_read(struct regmap_field *field, unsigned int *val);
851 int regmap_field_update_bits_base(struct regmap_field *field,
852                                   unsigned int mask, unsigned int val,
853                                   bool *change, bool async, bool force);
854 int regmap_fields_read(struct regmap_field *field, unsigned int id,
855                        unsigned int *val);
856 int regmap_fields_update_bits_base(struct regmap_field *field,  unsigned int id,
857                                    unsigned int mask, unsigned int val,
858                                    bool *change, bool async, bool force);
859 
860 /**
861  * struct regmap_irq - Description of an IRQ for the generic regmap irq_chip.
862  *
863  * @reg_offset: Offset of the status/mask register within the bank
864  * @mask:       Mask used to flag/control the register.
865  * @type_reg_offset: Offset register for the irq type setting.
866  * @type_rising_mask: Mask bit to configure RISING type irq.
867  * @type_falling_mask: Mask bit to configure FALLING type irq.
868  */
869 struct regmap_irq {
870         unsigned int reg_offset;
871         unsigned int mask;
872         unsigned int type_reg_offset;
873         unsigned int type_rising_mask;
874         unsigned int type_falling_mask;
875 };
876 
877 #define REGMAP_IRQ_REG(_irq, _off, _mask)               \
878         [_irq] = { .reg_offset = (_off), .mask = (_mask) }
879 
880 /**
881  * struct regmap_irq_chip - Description of a generic regmap irq_chip.
882  *
883  * @name:        Descriptive name for IRQ controller.
884  *
885  * @status_base: Base status register address.
886  * @mask_base:   Base mask register address.
887  * @unmask_base:  Base unmask register address. for chips who have
888  *                separate mask and unmask registers
889  * @ack_base:    Base ack address. If zero then the chip is clear on read.
890  *               Using zero value is possible with @use_ack bit.
891  * @wake_base:   Base address for wake enables.  If zero unsupported.
892  * @type_base:   Base address for irq type.  If zero unsupported.
893  * @irq_reg_stride:  Stride to use for chips where registers are not contiguous.
894  * @init_ack_masked: Ack all masked interrupts once during initalization.
895  * @mask_invert: Inverted mask register: cleared bits are masked out.
896  * @use_ack:     Use @ack register even if it is zero.
897  * @ack_invert:  Inverted ack register: cleared bits for ack.
898  * @wake_invert: Inverted wake register: cleared bits are wake enabled.
899  * @type_invert: Invert the type flags.
900  * @runtime_pm:  Hold a runtime PM lock on the device when accessing it.
901  *
902  * @num_regs:    Number of registers in each control bank.
903  * @irqs:        Descriptors for individual IRQs.  Interrupt numbers are
904  *               assigned based on the index in the array of the interrupt.
905  * @num_irqs:    Number of descriptors.
906  * @num_type_reg:    Number of type registers.
907  * @type_reg_stride: Stride to use for chips where type registers are not
908  *                      contiguous.
909  * @handle_pre_irq:  Driver specific callback to handle interrupt from device
910  *                   before regmap_irq_handler process the interrupts.
911  * @handle_post_irq: Driver specific callback to handle interrupt from device
912  *                   after handling the interrupts in regmap_irq_handler().
913  * @irq_drv_data:    Driver specific IRQ data which is passed as parameter when
914  *                   driver specific pre/post interrupt handler is called.
915  *
916  * This is not intended to handle every possible interrupt controller, but
917  * it should handle a substantial proportion of those that are found in the
918  * wild.
919  */
920 struct regmap_irq_chip {
921         const char *name;
922 
923         unsigned int status_base;
924         unsigned int mask_base;
925         unsigned int unmask_base;
926         unsigned int ack_base;
927         unsigned int wake_base;
928         unsigned int type_base;
929         unsigned int irq_reg_stride;
930         bool init_ack_masked:1;
931         bool mask_invert:1;
932         bool use_ack:1;
933         bool ack_invert:1;
934         bool wake_invert:1;
935         bool runtime_pm:1;
936         bool type_invert:1;
937 
938         int num_regs;
939 
940         const struct regmap_irq *irqs;
941         int num_irqs;
942 
943         int num_type_reg;
944         unsigned int type_reg_stride;
945 
946         int (*handle_pre_irq)(void *irq_drv_data);
947         int (*handle_post_irq)(void *irq_drv_data);
948         void *irq_drv_data;
949 };
950 
951 struct regmap_irq_chip_data;
952 
953 int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
954                         int irq_base, const struct regmap_irq_chip *chip,
955                         struct regmap_irq_chip_data **data);
956 void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data);
957 
958 int devm_regmap_add_irq_chip(struct device *dev, struct regmap *map, int irq,
959                              int irq_flags, int irq_base,
960                              const struct regmap_irq_chip *chip,
961                              struct regmap_irq_chip_data **data);
962 void devm_regmap_del_irq_chip(struct device *dev, int irq,
963                               struct regmap_irq_chip_data *data);
964 
965 int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data);
966 int regmap_irq_get_virq(struct regmap_irq_chip_data *data, int irq);
967 struct irq_domain *regmap_irq_get_domain(struct regmap_irq_chip_data *data);
968 
969 #else
970 
971 /*
972  * These stubs should only ever be called by generic code which has
973  * regmap based facilities, if they ever get called at runtime
974  * something is going wrong and something probably needs to select
975  * REGMAP.
976  */
977 
978 static inline int regmap_write(struct regmap *map, unsigned int reg,
979                                unsigned int val)
980 {
981         WARN_ONCE(1, "regmap API is disabled");
982         return -EINVAL;
983 }
984 
985 static inline int regmap_write_async(struct regmap *map, unsigned int reg,
986                                      unsigned int val)
987 {
988         WARN_ONCE(1, "regmap API is disabled");
989         return -EINVAL;
990 }
991 
992 static inline int regmap_raw_write(struct regmap *map, unsigned int reg,
993                                    const void *val, size_t val_len)
994 {
995         WARN_ONCE(1, "regmap API is disabled");
996         return -EINVAL;
997 }
998 
999 static inline int regmap_raw_write_async(struct regmap *map, unsigned int reg,
1000                                          const void *val, size_t val_len)
1001 {
1002         WARN_ONCE(1, "regmap API is disabled");
1003         return -EINVAL;
1004 }
1005 
1006 static inline int regmap_bulk_write(struct regmap *map, unsigned int reg,
1007                                     const void *val, size_t val_count)
1008 {
1009         WARN_ONCE(1, "regmap API is disabled");
1010         return -EINVAL;
1011 }
1012 
1013 static inline int regmap_read(struct regmap *map, unsigned int reg,
1014                               unsigned int *val)
1015 {
1016         WARN_ONCE(1, "regmap API is disabled");
1017         return -EINVAL;
1018 }
1019 
1020 static inline int regmap_raw_read(struct regmap *map, unsigned int reg,
1021                                   void *val, size_t val_len)
1022 {
1023         WARN_ONCE(1, "regmap API is disabled");
1024         return -EINVAL;
1025 }
1026 
1027 static inline int regmap_bulk_read(struct regmap *map, unsigned int reg,
1028                                    void *val, size_t val_count)
1029 {
1030         WARN_ONCE(1, "regmap API is disabled");
1031         return -EINVAL;
1032 }
1033 
1034 static inline int regmap_update_bits_base(struct regmap *map, unsigned int reg,
1035                                           unsigned int mask, unsigned int val,
1036                                           bool *change, bool async, bool force)
1037 {
1038         WARN_ONCE(1, "regmap API is disabled");
1039         return -EINVAL;
1040 }
1041 
1042 static inline int regmap_field_update_bits_base(struct regmap_field *field,
1043                                         unsigned int mask, unsigned int val,
1044                                         bool *change, bool async, bool force)
1045 {
1046         WARN_ONCE(1, "regmap API is disabled");
1047         return -EINVAL;
1048 }
1049 
1050 static inline int regmap_fields_update_bits_base(struct regmap_field *field,
1051                                    unsigned int id,
1052                                    unsigned int mask, unsigned int val,
1053                                    bool *change, bool async, bool force)
1054 {
1055         WARN_ONCE(1, "regmap API is disabled");
1056         return -EINVAL;
1057 }
1058 
1059 static inline int regmap_get_val_bytes(struct regmap *map)
1060 {
1061         WARN_ONCE(1, "regmap API is disabled");
1062         return -EINVAL;
1063 }
1064 
1065 static inline int regmap_get_max_register(struct regmap *map)
1066 {
1067         WARN_ONCE(1, "regmap API is disabled");
1068         return -EINVAL;
1069 }
1070 
1071 static inline int regmap_get_reg_stride(struct regmap *map)
1072 {
1073         WARN_ONCE(1, "regmap API is disabled");
1074         return -EINVAL;
1075 }
1076 
1077 static inline int regcache_sync(struct regmap *map)
1078 {
1079         WARN_ONCE(1, "regmap API is disabled");
1080         return -EINVAL;
1081 }
1082 
1083 static inline int regcache_sync_region(struct regmap *map, unsigned int min,
1084                                        unsigned int max)
1085 {
1086         WARN_ONCE(1, "regmap API is disabled");
1087         return -EINVAL;
1088 }
1089 
1090 static inline int regcache_drop_region(struct regmap *map, unsigned int min,
1091                                        unsigned int max)
1092 {
1093         WARN_ONCE(1, "regmap API is disabled");
1094         return -EINVAL;
1095 }
1096 
1097 static inline void regcache_cache_only(struct regmap *map, bool enable)
1098 {
1099         WARN_ONCE(1, "regmap API is disabled");
1100 }
1101 
1102 static inline void regcache_cache_bypass(struct regmap *map, bool enable)
1103 {
1104         WARN_ONCE(1, "regmap API is disabled");
1105 }
1106 
1107 static inline void regcache_mark_dirty(struct regmap *map)
1108 {
1109         WARN_ONCE(1, "regmap API is disabled");
1110 }
1111 
1112 static inline void regmap_async_complete(struct regmap *map)
1113 {
1114         WARN_ONCE(1, "regmap API is disabled");
1115 }
1116 
1117 static inline int regmap_register_patch(struct regmap *map,
1118                                         const struct reg_sequence *regs,
1119                                         int num_regs)
1120 {
1121         WARN_ONCE(1, "regmap API is disabled");
1122         return -EINVAL;
1123 }
1124 
1125 static inline int regmap_parse_val(struct regmap *map, const void *buf,
1126                                 unsigned int *val)
1127 {
1128         WARN_ONCE(1, "regmap API is disabled");
1129         return -EINVAL;
1130 }
1131 
1132 static inline struct regmap *dev_get_regmap(struct device *dev,
1133                                             const char *name)
1134 {
1135         return NULL;
1136 }
1137 
1138 static inline struct device *regmap_get_device(struct regmap *map)
1139 {
1140         WARN_ONCE(1, "regmap API is disabled");
1141         return NULL;
1142 }
1143 
1144 #endif
1145 
1146 #endif
1147 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp