regmap-irq: make it possible to add irq_chip do a specific device node
[linux-2.6-microblaze.git] / include / linux / regmap.h
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 #ifndef __LINUX_REGMAP_H
3 #define __LINUX_REGMAP_H
4
5 /*
6  * Register map access API
7  *
8  * Copyright 2011 Wolfson Microelectronics plc
9  *
10  * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
11  */
12
13 #include <linux/list.h>
14 #include <linux/rbtree.h>
15 #include <linux/ktime.h>
16 #include <linux/delay.h>
17 #include <linux/err.h>
18 #include <linux/bug.h>
19 #include <linux/lockdep.h>
20
21 struct module;
22 struct clk;
23 struct device;
24 struct device_node;
25 struct i2c_client;
26 struct i3c_device;
27 struct irq_domain;
28 struct slim_device;
29 struct spi_device;
30 struct spmi_device;
31 struct regmap;
32 struct regmap_range_cfg;
33 struct regmap_field;
34 struct snd_ac97;
35 struct sdw_slave;
36
37 /* An enum of all the supported cache types */
38 enum regcache_type {
39         REGCACHE_NONE,
40         REGCACHE_RBTREE,
41         REGCACHE_COMPRESSED,
42         REGCACHE_FLAT,
43 };
44
45 /**
46  * struct reg_default - Default value for a register.
47  *
48  * @reg: Register address.
49  * @def: Register default value.
50  *
51  * We use an array of structs rather than a simple array as many modern devices
52  * have very sparse register maps.
53  */
54 struct reg_default {
55         unsigned int reg;
56         unsigned int def;
57 };
58
59 /**
60  * struct reg_sequence - An individual write from a sequence of writes.
61  *
62  * @reg: Register address.
63  * @def: Register value.
64  * @delay_us: Delay to be applied after the register write in microseconds
65  *
66  * Register/value pairs for sequences of writes with an optional delay in
67  * microseconds to be applied after each write.
68  */
69 struct reg_sequence {
70         unsigned int reg;
71         unsigned int def;
72         unsigned int delay_us;
73 };
74
75 #define regmap_update_bits(map, reg, mask, val) \
76         regmap_update_bits_base(map, reg, mask, val, NULL, false, false)
77 #define regmap_update_bits_async(map, reg, mask, val)\
78         regmap_update_bits_base(map, reg, mask, val, NULL, true, false)
79 #define regmap_update_bits_check(map, reg, mask, val, change)\
80         regmap_update_bits_base(map, reg, mask, val, change, false, false)
81 #define regmap_update_bits_check_async(map, reg, mask, val, change)\
82         regmap_update_bits_base(map, reg, mask, val, change, true, false)
83
84 #define regmap_write_bits(map, reg, mask, val) \
85         regmap_update_bits_base(map, reg, mask, val, NULL, false, true)
86
87 #define regmap_field_write(field, val) \
88         regmap_field_update_bits_base(field, ~0, val, NULL, false, false)
89 #define regmap_field_force_write(field, val) \
90         regmap_field_update_bits_base(field, ~0, val, NULL, false, true)
91 #define regmap_field_update_bits(field, mask, val)\
92         regmap_field_update_bits_base(field, mask, val, NULL, false, false)
93 #define regmap_field_force_update_bits(field, mask, val) \
94         regmap_field_update_bits_base(field, mask, val, NULL, false, true)
95
96 #define regmap_fields_write(field, id, val) \
97         regmap_fields_update_bits_base(field, id, ~0, val, NULL, false, false)
98 #define regmap_fields_force_write(field, id, val) \
99         regmap_fields_update_bits_base(field, id, ~0, val, NULL, false, true)
100 #define regmap_fields_update_bits(field, id, mask, val)\
101         regmap_fields_update_bits_base(field, id, mask, val, NULL, false, false)
102 #define regmap_fields_force_update_bits(field, id, mask, val) \
103         regmap_fields_update_bits_base(field, id, mask, val, NULL, false, true)
104
105 /**
106  * regmap_read_poll_timeout - Poll until a condition is met or a timeout occurs
107  *
108  * @map: Regmap to read from
109  * @addr: Address to poll
110  * @val: Unsigned integer variable to read the value into
111  * @cond: Break condition (usually involving @val)
112  * @sleep_us: Maximum time to sleep between reads in us (0
113  *            tight-loops).  Should be less than ~20ms since usleep_range
114  *            is used (see Documentation/timers/timers-howto.rst).
115  * @timeout_us: Timeout in us, 0 means never timeout
116  *
117  * Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_read
118  * error return value in case of a error read. In the two former cases,
119  * the last read value at @addr is stored in @val. Must not be called
120  * from atomic context if sleep_us or timeout_us are used.
121  *
122  * This is modelled after the readx_poll_timeout macros in linux/iopoll.h.
123  */
124 #define regmap_read_poll_timeout(map, addr, val, cond, sleep_us, timeout_us) \
125 ({ \
126         u64 __timeout_us = (timeout_us); \
127         unsigned long __sleep_us = (sleep_us); \
128         ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \
129         int __ret; \
130         might_sleep_if(__sleep_us); \
131         for (;;) { \
132                 __ret = regmap_read((map), (addr), &(val)); \
133                 if (__ret) \
134                         break; \
135                 if (cond) \
136                         break; \
137                 if ((__timeout_us) && \
138                     ktime_compare(ktime_get(), __timeout) > 0) { \
139                         __ret = regmap_read((map), (addr), &(val)); \
140                         break; \
141                 } \
142                 if (__sleep_us) \
143                         usleep_range((__sleep_us >> 2) + 1, __sleep_us); \
144         } \
145         __ret ?: ((cond) ? 0 : -ETIMEDOUT); \
146 })
147
148 /**
149  * regmap_read_poll_timeout_atomic - Poll until a condition is met or a timeout occurs
150  *
151  * @map: Regmap to read from
152  * @addr: Address to poll
153  * @val: Unsigned integer variable to read the value into
154  * @cond: Break condition (usually involving @val)
155  * @delay_us: Time to udelay between reads in us (0 tight-loops).
156  *            Should be less than ~10us since udelay is used
157  *            (see Documentation/timers/timers-howto.rst).
158  * @timeout_us: Timeout in us, 0 means never timeout
159  *
160  * Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_read
161  * error return value in case of a error read. In the two former cases,
162  * the last read value at @addr is stored in @val.
163  *
164  * This is modelled after the readx_poll_timeout_atomic macros in linux/iopoll.h.
165  *
166  * Note: In general regmap cannot be used in atomic context. If you want to use
167  * this macro then first setup your regmap for atomic use (flat or no cache
168  * and MMIO regmap).
169  */
170 #define regmap_read_poll_timeout_atomic(map, addr, val, cond, delay_us, timeout_us) \
171 ({ \
172         u64 __timeout_us = (timeout_us); \
173         unsigned long __delay_us = (delay_us); \
174         ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \
175         int __ret; \
176         for (;;) { \
177                 __ret = regmap_read((map), (addr), &(val)); \
178                 if (__ret) \
179                         break; \
180                 if (cond) \
181                         break; \
182                 if ((__timeout_us) && \
183                     ktime_compare(ktime_get(), __timeout) > 0) { \
184                         __ret = regmap_read((map), (addr), &(val)); \
185                         break; \
186                 } \
187                 if (__delay_us) \
188                         udelay(__delay_us); \
189         } \
190         __ret ?: ((cond) ? 0 : -ETIMEDOUT); \
191 })
192
193 /**
194  * regmap_field_read_poll_timeout - Poll until a condition is met or timeout
195  *
196  * @field: Regmap field to read from
197  * @val: Unsigned integer variable to read the value into
198  * @cond: Break condition (usually involving @val)
199  * @sleep_us: Maximum time to sleep between reads in us (0
200  *            tight-loops).  Should be less than ~20ms since usleep_range
201  *            is used (see Documentation/timers/timers-howto.rst).
202  * @timeout_us: Timeout in us, 0 means never timeout
203  *
204  * Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_field_read
205  * error return value in case of a error read. In the two former cases,
206  * the last read value at @addr is stored in @val. Must not be called
207  * from atomic context if sleep_us or timeout_us are used.
208  *
209  * This is modelled after the readx_poll_timeout macros in linux/iopoll.h.
210  */
211 #define regmap_field_read_poll_timeout(field, val, cond, sleep_us, timeout_us) \
212 ({ \
213         u64 __timeout_us = (timeout_us); \
214         unsigned long __sleep_us = (sleep_us); \
215         ktime_t timeout = ktime_add_us(ktime_get(), __timeout_us); \
216         int pollret; \
217         might_sleep_if(__sleep_us); \
218         for (;;) { \
219                 pollret = regmap_field_read((field), &(val)); \
220                 if (pollret) \
221                         break; \
222                 if (cond) \
223                         break; \
224                 if (__timeout_us && ktime_compare(ktime_get(), timeout) > 0) { \
225                         pollret = regmap_field_read((field), &(val)); \
226                         break; \
227                 } \
228                 if (__sleep_us) \
229                         usleep_range((__sleep_us >> 2) + 1, __sleep_us); \
230         } \
231         pollret ?: ((cond) ? 0 : -ETIMEDOUT); \
232 })
233
234 #ifdef CONFIG_REGMAP
235
236 enum regmap_endian {
237         /* Unspecified -> 0 -> Backwards compatible default */
238         REGMAP_ENDIAN_DEFAULT = 0,
239         REGMAP_ENDIAN_BIG,
240         REGMAP_ENDIAN_LITTLE,
241         REGMAP_ENDIAN_NATIVE,
242 };
243
244 /**
245  * struct regmap_range - A register range, used for access related checks
246  *                       (readable/writeable/volatile/precious checks)
247  *
248  * @range_min: address of first register
249  * @range_max: address of last register
250  */
251 struct regmap_range {
252         unsigned int range_min;
253         unsigned int range_max;
254 };
255
256 #define regmap_reg_range(low, high) { .range_min = low, .range_max = high, }
257
258 /**
259  * struct regmap_access_table - A table of register ranges for access checks
260  *
261  * @yes_ranges : pointer to an array of regmap ranges used as "yes ranges"
262  * @n_yes_ranges: size of the above array
263  * @no_ranges: pointer to an array of regmap ranges used as "no ranges"
264  * @n_no_ranges: size of the above array
265  *
266  * A table of ranges including some yes ranges and some no ranges.
267  * If a register belongs to a no_range, the corresponding check function
268  * will return false. If a register belongs to a yes range, the corresponding
269  * check function will return true. "no_ranges" are searched first.
270  */
271 struct regmap_access_table {
272         const struct regmap_range *yes_ranges;
273         unsigned int n_yes_ranges;
274         const struct regmap_range *no_ranges;
275         unsigned int n_no_ranges;
276 };
277
278 typedef void (*regmap_lock)(void *);
279 typedef void (*regmap_unlock)(void *);
280
281 /**
282  * struct regmap_config - Configuration for the register map of a device.
283  *
284  * @name: Optional name of the regmap. Useful when a device has multiple
285  *        register regions.
286  *
287  * @reg_bits: Number of bits in a register address, mandatory.
288  * @reg_stride: The register address stride. Valid register addresses are a
289  *              multiple of this value. If set to 0, a value of 1 will be
290  *              used.
291  * @pad_bits: Number of bits of padding between register and value.
292  * @val_bits: Number of bits in a register value, mandatory.
293  *
294  * @writeable_reg: Optional callback returning true if the register
295  *                 can be written to. If this field is NULL but wr_table
296  *                 (see below) is not, the check is performed on such table
297  *                 (a register is writeable if it belongs to one of the ranges
298  *                  specified by wr_table).
299  * @readable_reg: Optional callback returning true if the register
300  *                can be read from. If this field is NULL but rd_table
301  *                 (see below) is not, the check is performed on such table
302  *                 (a register is readable if it belongs to one of the ranges
303  *                  specified by rd_table).
304  * @volatile_reg: Optional callback returning true if the register
305  *                value can't be cached. If this field is NULL but
306  *                volatile_table (see below) is not, the check is performed on
307  *                such table (a register is volatile if it belongs to one of
308  *                the ranges specified by volatile_table).
309  * @precious_reg: Optional callback returning true if the register
310  *                should not be read outside of a call from the driver
311  *                (e.g., a clear on read interrupt status register). If this
312  *                field is NULL but precious_table (see below) is not, the
313  *                check is performed on such table (a register is precious if
314  *                it belongs to one of the ranges specified by precious_table).
315  * @writeable_noinc_reg: Optional callback returning true if the register
316  *                      supports multiple write operations without incrementing
317  *                      the register number. If this field is NULL but
318  *                      wr_noinc_table (see below) is not, the check is
319  *                      performed on such table (a register is no increment
320  *                      writeable if it belongs to one of the ranges specified
321  *                      by wr_noinc_table).
322  * @readable_noinc_reg: Optional callback returning true if the register
323  *                      supports multiple read operations without incrementing
324  *                      the register number. If this field is NULL but
325  *                      rd_noinc_table (see below) is not, the check is
326  *                      performed on such table (a register is no increment
327  *                      readable if it belongs to one of the ranges specified
328  *                      by rd_noinc_table).
329  * @disable_locking: This regmap is either protected by external means or
330  *                   is guaranteed not be be accessed from multiple threads.
331  *                   Don't use any locking mechanisms.
332  * @lock:         Optional lock callback (overrides regmap's default lock
333  *                function, based on spinlock or mutex).
334  * @unlock:       As above for unlocking.
335  * @lock_arg:     this field is passed as the only argument of lock/unlock
336  *                functions (ignored in case regular lock/unlock functions
337  *                are not overridden).
338  * @reg_read:     Optional callback that if filled will be used to perform
339  *                all the reads from the registers. Should only be provided for
340  *                devices whose read operation cannot be represented as a simple
341  *                read operation on a bus such as SPI, I2C, etc. Most of the
342  *                devices do not need this.
343  * @reg_write:    Same as above for writing.
344  * @fast_io:      Register IO is fast. Use a spinlock instead of a mutex
345  *                to perform locking. This field is ignored if custom lock/unlock
346  *                functions are used (see fields lock/unlock of struct regmap_config).
347  *                This field is a duplicate of a similar file in
348  *                'struct regmap_bus' and serves exact same purpose.
349  *                 Use it only for "no-bus" cases.
350  * @max_register: Optional, specifies the maximum valid register address.
351  * @wr_table:     Optional, points to a struct regmap_access_table specifying
352  *                valid ranges for write access.
353  * @rd_table:     As above, for read access.
354  * @volatile_table: As above, for volatile registers.
355  * @precious_table: As above, for precious registers.
356  * @wr_noinc_table: As above, for no increment writeable registers.
357  * @rd_noinc_table: As above, for no increment readable registers.
358  * @reg_defaults: Power on reset values for registers (for use with
359  *                register cache support).
360  * @num_reg_defaults: Number of elements in reg_defaults.
361  *
362  * @read_flag_mask: Mask to be set in the top bytes of the register when doing
363  *                  a read.
364  * @write_flag_mask: Mask to be set in the top bytes of the register when doing
365  *                   a write. If both read_flag_mask and write_flag_mask are
366  *                   empty and zero_flag_mask is not set the regmap_bus default
367  *                   masks are used.
368  * @zero_flag_mask: If set, read_flag_mask and write_flag_mask are used even
369  *                   if they are both empty.
370  * @use_single_read: If set, converts the bulk read operation into a series of
371  *                   single read operations. This is useful for a device that
372  *                   does not support  bulk read.
373  * @use_single_write: If set, converts the bulk write operation into a series of
374  *                    single write operations. This is useful for a device that
375  *                    does not support bulk write.
376  * @can_multi_write: If set, the device supports the multi write mode of bulk
377  *                   write operations, if clear multi write requests will be
378  *                   split into individual write operations
379  *
380  * @cache_type: The actual cache type.
381  * @reg_defaults_raw: Power on reset values for registers (for use with
382  *                    register cache support).
383  * @num_reg_defaults_raw: Number of elements in reg_defaults_raw.
384  * @reg_format_endian: Endianness for formatted register addresses. If this is
385  *                     DEFAULT, the @reg_format_endian_default value from the
386  *                     regmap bus is used.
387  * @val_format_endian: Endianness for formatted register values. If this is
388  *                     DEFAULT, the @reg_format_endian_default value from the
389  *                     regmap bus is used.
390  *
391  * @ranges: Array of configuration entries for virtual address ranges.
392  * @num_ranges: Number of range configuration entries.
393  * @use_hwlock: Indicate if a hardware spinlock should be used.
394  * @hwlock_id: Specify the hardware spinlock id.
395  * @hwlock_mode: The hardware spinlock mode, should be HWLOCK_IRQSTATE,
396  *               HWLOCK_IRQ or 0.
397  */
398 struct regmap_config {
399         const char *name;
400
401         int reg_bits;
402         int reg_stride;
403         int pad_bits;
404         int val_bits;
405
406         bool (*writeable_reg)(struct device *dev, unsigned int reg);
407         bool (*readable_reg)(struct device *dev, unsigned int reg);
408         bool (*volatile_reg)(struct device *dev, unsigned int reg);
409         bool (*precious_reg)(struct device *dev, unsigned int reg);
410         bool (*writeable_noinc_reg)(struct device *dev, unsigned int reg);
411         bool (*readable_noinc_reg)(struct device *dev, unsigned int reg);
412
413         bool disable_locking;
414         regmap_lock lock;
415         regmap_unlock unlock;
416         void *lock_arg;
417
418         int (*reg_read)(void *context, unsigned int reg, unsigned int *val);
419         int (*reg_write)(void *context, unsigned int reg, unsigned int val);
420
421         bool fast_io;
422
423         unsigned int max_register;
424         const struct regmap_access_table *wr_table;
425         const struct regmap_access_table *rd_table;
426         const struct regmap_access_table *volatile_table;
427         const struct regmap_access_table *precious_table;
428         const struct regmap_access_table *wr_noinc_table;
429         const struct regmap_access_table *rd_noinc_table;
430         const struct reg_default *reg_defaults;
431         unsigned int num_reg_defaults;
432         enum regcache_type cache_type;
433         const void *reg_defaults_raw;
434         unsigned int num_reg_defaults_raw;
435
436         unsigned long read_flag_mask;
437         unsigned long write_flag_mask;
438         bool zero_flag_mask;
439
440         bool use_single_read;
441         bool use_single_write;
442         bool can_multi_write;
443
444         enum regmap_endian reg_format_endian;
445         enum regmap_endian val_format_endian;
446
447         const struct regmap_range_cfg *ranges;
448         unsigned int num_ranges;
449
450         bool use_hwlock;
451         unsigned int hwlock_id;
452         unsigned int hwlock_mode;
453 };
454
455 /**
456  * struct regmap_range_cfg - Configuration for indirectly accessed or paged
457  *                           registers.
458  *
459  * @name: Descriptive name for diagnostics
460  *
461  * @range_min: Address of the lowest register address in virtual range.
462  * @range_max: Address of the highest register in virtual range.
463  *
464  * @selector_reg: Register with selector field.
465  * @selector_mask: Bit mask for selector value.
466  * @selector_shift: Bit shift for selector value.
467  *
468  * @window_start: Address of first (lowest) register in data window.
469  * @window_len: Number of registers in data window.
470  *
471  * Registers, mapped to this virtual range, are accessed in two steps:
472  *     1. page selector register update;
473  *     2. access through data window registers.
474  */
475 struct regmap_range_cfg {
476         const char *name;
477
478         /* Registers of virtual address range */
479         unsigned int range_min;
480         unsigned int range_max;
481
482         /* Page selector for indirect addressing */
483         unsigned int selector_reg;
484         unsigned int selector_mask;
485         int selector_shift;
486
487         /* Data window (per each page) */
488         unsigned int window_start;
489         unsigned int window_len;
490 };
491
492 struct regmap_async;
493
494 typedef int (*regmap_hw_write)(void *context, const void *data,
495                                size_t count);
496 typedef int (*regmap_hw_gather_write)(void *context,
497                                       const void *reg, size_t reg_len,
498                                       const void *val, size_t val_len);
499 typedef int (*regmap_hw_async_write)(void *context,
500                                      const void *reg, size_t reg_len,
501                                      const void *val, size_t val_len,
502                                      struct regmap_async *async);
503 typedef int (*regmap_hw_read)(void *context,
504                               const void *reg_buf, size_t reg_size,
505                               void *val_buf, size_t val_size);
506 typedef int (*regmap_hw_reg_read)(void *context, unsigned int reg,
507                                   unsigned int *val);
508 typedef int (*regmap_hw_reg_write)(void *context, unsigned int reg,
509                                    unsigned int val);
510 typedef int (*regmap_hw_reg_update_bits)(void *context, unsigned int reg,
511                                          unsigned int mask, unsigned int val);
512 typedef struct regmap_async *(*regmap_hw_async_alloc)(void);
513 typedef void (*regmap_hw_free_context)(void *context);
514
515 /**
516  * struct regmap_bus - Description of a hardware bus for the register map
517  *                     infrastructure.
518  *
519  * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
520  *           to perform locking. This field is ignored if custom lock/unlock
521  *           functions are used (see fields lock/unlock of
522  *           struct regmap_config).
523  * @write: Write operation.
524  * @gather_write: Write operation with split register/value, return -ENOTSUPP
525  *                if not implemented  on a given device.
526  * @async_write: Write operation which completes asynchronously, optional and
527  *               must serialise with respect to non-async I/O.
528  * @reg_write: Write a single register value to the given register address. This
529  *             write operation has to complete when returning from the function.
530  * @reg_update_bits: Update bits operation to be used against volatile
531  *                   registers, intended for devices supporting some mechanism
532  *                   for setting clearing bits without having to
533  *                   read/modify/write.
534  * @read: Read operation.  Data is returned in the buffer used to transmit
535  *         data.
536  * @reg_read: Read a single register value from a given register address.
537  * @free_context: Free context.
538  * @async_alloc: Allocate a regmap_async() structure.
539  * @read_flag_mask: Mask to be set in the top byte of the register when doing
540  *                  a read.
541  * @reg_format_endian_default: Default endianness for formatted register
542  *     addresses. Used when the regmap_config specifies DEFAULT. If this is
543  *     DEFAULT, BIG is assumed.
544  * @val_format_endian_default: Default endianness for formatted register
545  *     values. Used when the regmap_config specifies DEFAULT. If this is
546  *     DEFAULT, BIG is assumed.
547  * @max_raw_read: Max raw read size that can be used on the bus.
548  * @max_raw_write: Max raw write size that can be used on the bus.
549  */
550 struct regmap_bus {
551         bool fast_io;
552         regmap_hw_write write;
553         regmap_hw_gather_write gather_write;
554         regmap_hw_async_write async_write;
555         regmap_hw_reg_write reg_write;
556         regmap_hw_reg_update_bits reg_update_bits;
557         regmap_hw_read read;
558         regmap_hw_reg_read reg_read;
559         regmap_hw_free_context free_context;
560         regmap_hw_async_alloc async_alloc;
561         u8 read_flag_mask;
562         enum regmap_endian reg_format_endian_default;
563         enum regmap_endian val_format_endian_default;
564         size_t max_raw_read;
565         size_t max_raw_write;
566 };
567
568 /*
569  * __regmap_init functions.
570  *
571  * These functions take a lock key and name parameter, and should not be called
572  * directly. Instead, use the regmap_init macros that generate a key and name
573  * for each call.
574  */
575 struct regmap *__regmap_init(struct device *dev,
576                              const struct regmap_bus *bus,
577                              void *bus_context,
578                              const struct regmap_config *config,
579                              struct lock_class_key *lock_key,
580                              const char *lock_name);
581 struct regmap *__regmap_init_i2c(struct i2c_client *i2c,
582                                  const struct regmap_config *config,
583                                  struct lock_class_key *lock_key,
584                                  const char *lock_name);
585 struct regmap *__regmap_init_sccb(struct i2c_client *i2c,
586                                   const struct regmap_config *config,
587                                   struct lock_class_key *lock_key,
588                                   const char *lock_name);
589 struct regmap *__regmap_init_slimbus(struct slim_device *slimbus,
590                                  const struct regmap_config *config,
591                                  struct lock_class_key *lock_key,
592                                  const char *lock_name);
593 struct regmap *__regmap_init_spi(struct spi_device *dev,
594                                  const struct regmap_config *config,
595                                  struct lock_class_key *lock_key,
596                                  const char *lock_name);
597 struct regmap *__regmap_init_spmi_base(struct spmi_device *dev,
598                                        const struct regmap_config *config,
599                                        struct lock_class_key *lock_key,
600                                        const char *lock_name);
601 struct regmap *__regmap_init_spmi_ext(struct spmi_device *dev,
602                                       const struct regmap_config *config,
603                                       struct lock_class_key *lock_key,
604                                       const char *lock_name);
605 struct regmap *__regmap_init_w1(struct device *w1_dev,
606                                  const struct regmap_config *config,
607                                  struct lock_class_key *lock_key,
608                                  const char *lock_name);
609 struct regmap *__regmap_init_mmio_clk(struct device *dev, const char *clk_id,
610                                       void __iomem *regs,
611                                       const struct regmap_config *config,
612                                       struct lock_class_key *lock_key,
613                                       const char *lock_name);
614 struct regmap *__regmap_init_ac97(struct snd_ac97 *ac97,
615                                   const struct regmap_config *config,
616                                   struct lock_class_key *lock_key,
617                                   const char *lock_name);
618 struct regmap *__regmap_init_sdw(struct sdw_slave *sdw,
619                                  const struct regmap_config *config,
620                                  struct lock_class_key *lock_key,
621                                  const char *lock_name);
622
623 struct regmap *__devm_regmap_init(struct device *dev,
624                                   const struct regmap_bus *bus,
625                                   void *bus_context,
626                                   const struct regmap_config *config,
627                                   struct lock_class_key *lock_key,
628                                   const char *lock_name);
629 struct regmap *__devm_regmap_init_i2c(struct i2c_client *i2c,
630                                       const struct regmap_config *config,
631                                       struct lock_class_key *lock_key,
632                                       const char *lock_name);
633 struct regmap *__devm_regmap_init_sccb(struct i2c_client *i2c,
634                                        const struct regmap_config *config,
635                                        struct lock_class_key *lock_key,
636                                        const char *lock_name);
637 struct regmap *__devm_regmap_init_spi(struct spi_device *dev,
638                                       const struct regmap_config *config,
639                                       struct lock_class_key *lock_key,
640                                       const char *lock_name);
641 struct regmap *__devm_regmap_init_spmi_base(struct spmi_device *dev,
642                                             const struct regmap_config *config,
643                                             struct lock_class_key *lock_key,
644                                             const char *lock_name);
645 struct regmap *__devm_regmap_init_spmi_ext(struct spmi_device *dev,
646                                            const struct regmap_config *config,
647                                            struct lock_class_key *lock_key,
648                                            const char *lock_name);
649 struct regmap *__devm_regmap_init_w1(struct device *w1_dev,
650                                       const struct regmap_config *config,
651                                       struct lock_class_key *lock_key,
652                                       const char *lock_name);
653 struct regmap *__devm_regmap_init_mmio_clk(struct device *dev,
654                                            const char *clk_id,
655                                            void __iomem *regs,
656                                            const struct regmap_config *config,
657                                            struct lock_class_key *lock_key,
658                                            const char *lock_name);
659 struct regmap *__devm_regmap_init_ac97(struct snd_ac97 *ac97,
660                                        const struct regmap_config *config,
661                                        struct lock_class_key *lock_key,
662                                        const char *lock_name);
663 struct regmap *__devm_regmap_init_sdw(struct sdw_slave *sdw,
664                                  const struct regmap_config *config,
665                                  struct lock_class_key *lock_key,
666                                  const char *lock_name);
667 struct regmap *__devm_regmap_init_slimbus(struct slim_device *slimbus,
668                                  const struct regmap_config *config,
669                                  struct lock_class_key *lock_key,
670                                  const char *lock_name);
671 struct regmap *__devm_regmap_init_i3c(struct i3c_device *i3c,
672                                  const struct regmap_config *config,
673                                  struct lock_class_key *lock_key,
674                                  const char *lock_name);
675 /*
676  * Wrapper for regmap_init macros to include a unique lockdep key and name
677  * for each call. No-op if CONFIG_LOCKDEP is not set.
678  *
679  * @fn: Real function to call (in the form __[*_]regmap_init[_*])
680  * @name: Config variable name (#config in the calling macro)
681  **/
682 #ifdef CONFIG_LOCKDEP
683 #define __regmap_lockdep_wrapper(fn, name, ...)                         \
684 (                                                                       \
685         ({                                                              \
686                 static struct lock_class_key _key;                      \
687                 fn(__VA_ARGS__, &_key,                                  \
688                         KBUILD_BASENAME ":"                             \
689                         __stringify(__LINE__) ":"                       \
690                         "(" name ")->lock");                            \
691         })                                                              \
692 )
693 #else
694 #define __regmap_lockdep_wrapper(fn, name, ...) fn(__VA_ARGS__, NULL, NULL)
695 #endif
696
697 /**
698  * regmap_init() - Initialise register map
699  *
700  * @dev: Device that will be interacted with
701  * @bus: Bus-specific callbacks to use with device
702  * @bus_context: Data passed to bus-specific callbacks
703  * @config: Configuration for register map
704  *
705  * The return value will be an ERR_PTR() on error or a valid pointer to
706  * a struct regmap.  This function should generally not be called
707  * directly, it should be called by bus-specific init functions.
708  */
709 #define regmap_init(dev, bus, bus_context, config)                      \
710         __regmap_lockdep_wrapper(__regmap_init, #config,                \
711                                 dev, bus, bus_context, config)
712 int regmap_attach_dev(struct device *dev, struct regmap *map,
713                       const struct regmap_config *config);
714
715 /**
716  * regmap_init_i2c() - Initialise register map
717  *
718  * @i2c: Device that will be interacted with
719  * @config: Configuration for register map
720  *
721  * The return value will be an ERR_PTR() on error or a valid pointer to
722  * a struct regmap.
723  */
724 #define regmap_init_i2c(i2c, config)                                    \
725         __regmap_lockdep_wrapper(__regmap_init_i2c, #config,            \
726                                 i2c, config)
727
728 /**
729  * regmap_init_sccb() - Initialise register map
730  *
731  * @i2c: Device that will be interacted with
732  * @config: Configuration for register map
733  *
734  * The return value will be an ERR_PTR() on error or a valid pointer to
735  * a struct regmap.
736  */
737 #define regmap_init_sccb(i2c, config)                                   \
738         __regmap_lockdep_wrapper(__regmap_init_sccb, #config,           \
739                                 i2c, config)
740
741 /**
742  * regmap_init_slimbus() - Initialise register map
743  *
744  * @slimbus: Device that will be interacted with
745  * @config: Configuration for register map
746  *
747  * The return value will be an ERR_PTR() on error or a valid pointer to
748  * a struct regmap.
749  */
750 #define regmap_init_slimbus(slimbus, config)                            \
751         __regmap_lockdep_wrapper(__regmap_init_slimbus, #config,        \
752                                 slimbus, config)
753
754 /**
755  * regmap_init_spi() - Initialise register map
756  *
757  * @dev: Device that will be interacted with
758  * @config: Configuration for register map
759  *
760  * The return value will be an ERR_PTR() on error or a valid pointer to
761  * a struct regmap.
762  */
763 #define regmap_init_spi(dev, config)                                    \
764         __regmap_lockdep_wrapper(__regmap_init_spi, #config,            \
765                                 dev, config)
766
767 /**
768  * regmap_init_spmi_base() - Create regmap for the Base register space
769  *
770  * @dev:        SPMI device that will be interacted with
771  * @config:     Configuration for register map
772  *
773  * The return value will be an ERR_PTR() on error or a valid pointer to
774  * a struct regmap.
775  */
776 #define regmap_init_spmi_base(dev, config)                              \
777         __regmap_lockdep_wrapper(__regmap_init_spmi_base, #config,      \
778                                 dev, config)
779
780 /**
781  * regmap_init_spmi_ext() - Create regmap for Ext register space
782  *
783  * @dev:        Device that will be interacted with
784  * @config:     Configuration for register map
785  *
786  * The return value will be an ERR_PTR() on error or a valid pointer to
787  * a struct regmap.
788  */
789 #define regmap_init_spmi_ext(dev, config)                               \
790         __regmap_lockdep_wrapper(__regmap_init_spmi_ext, #config,       \
791                                 dev, config)
792
793 /**
794  * regmap_init_w1() - Initialise register map
795  *
796  * @w1_dev: Device that will be interacted with
797  * @config: Configuration for register map
798  *
799  * The return value will be an ERR_PTR() on error or a valid pointer to
800  * a struct regmap.
801  */
802 #define regmap_init_w1(w1_dev, config)                                  \
803         __regmap_lockdep_wrapper(__regmap_init_w1, #config,             \
804                                 w1_dev, config)
805
806 /**
807  * regmap_init_mmio_clk() - Initialise register map with register clock
808  *
809  * @dev: Device that will be interacted with
810  * @clk_id: register clock consumer ID
811  * @regs: Pointer to memory-mapped IO region
812  * @config: Configuration for register map
813  *
814  * The return value will be an ERR_PTR() on error or a valid pointer to
815  * a struct regmap.
816  */
817 #define regmap_init_mmio_clk(dev, clk_id, regs, config)                 \
818         __regmap_lockdep_wrapper(__regmap_init_mmio_clk, #config,       \
819                                 dev, clk_id, regs, config)
820
821 /**
822  * regmap_init_mmio() - Initialise register map
823  *
824  * @dev: Device that will be interacted with
825  * @regs: Pointer to memory-mapped IO region
826  * @config: Configuration for register map
827  *
828  * The return value will be an ERR_PTR() on error or a valid pointer to
829  * a struct regmap.
830  */
831 #define regmap_init_mmio(dev, regs, config)             \
832         regmap_init_mmio_clk(dev, NULL, regs, config)
833
834 /**
835  * regmap_init_ac97() - Initialise AC'97 register map
836  *
837  * @ac97: 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 to
841  * a struct regmap.
842  */
843 #define regmap_init_ac97(ac97, config)                                  \
844         __regmap_lockdep_wrapper(__regmap_init_ac97, #config,           \
845                                 ac97, config)
846 bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg);
847
848 /**
849  * regmap_init_sdw() - Initialise register map
850  *
851  * @sdw: Device that will be interacted with
852  * @config: Configuration for register map
853  *
854  * The return value will be an ERR_PTR() on error or a valid pointer to
855  * a struct regmap.
856  */
857 #define regmap_init_sdw(sdw, config)                                    \
858         __regmap_lockdep_wrapper(__regmap_init_sdw, #config,            \
859                                 sdw, config)
860
861
862 /**
863  * devm_regmap_init() - Initialise managed register map
864  *
865  * @dev: Device that will be interacted with
866  * @bus: Bus-specific callbacks to use with device
867  * @bus_context: Data passed to bus-specific callbacks
868  * @config: Configuration for register map
869  *
870  * The return value will be an ERR_PTR() on error or a valid pointer
871  * to a struct regmap.  This function should generally not be called
872  * directly, it should be called by bus-specific init functions.  The
873  * map will be automatically freed by the device management code.
874  */
875 #define devm_regmap_init(dev, bus, bus_context, config)                 \
876         __regmap_lockdep_wrapper(__devm_regmap_init, #config,           \
877                                 dev, bus, bus_context, config)
878
879 /**
880  * devm_regmap_init_i2c() - Initialise managed register map
881  *
882  * @i2c: Device that will be interacted with
883  * @config: Configuration for register map
884  *
885  * The return value will be an ERR_PTR() on error or a valid pointer
886  * to a struct regmap.  The regmap will be automatically freed by the
887  * device management code.
888  */
889 #define devm_regmap_init_i2c(i2c, config)                               \
890         __regmap_lockdep_wrapper(__devm_regmap_init_i2c, #config,       \
891                                 i2c, config)
892
893 /**
894  * devm_regmap_init_sccb() - Initialise managed register map
895  *
896  * @i2c: Device that will be interacted with
897  * @config: Configuration for register map
898  *
899  * The return value will be an ERR_PTR() on error or a valid pointer
900  * to a struct regmap.  The regmap will be automatically freed by the
901  * device management code.
902  */
903 #define devm_regmap_init_sccb(i2c, config)                              \
904         __regmap_lockdep_wrapper(__devm_regmap_init_sccb, #config,      \
905                                 i2c, config)
906
907 /**
908  * devm_regmap_init_spi() - Initialise register map
909  *
910  * @dev: Device that will be interacted with
911  * @config: Configuration for register map
912  *
913  * The return value will be an ERR_PTR() on error or a valid pointer
914  * to a struct regmap.  The map will be automatically freed by the
915  * device management code.
916  */
917 #define devm_regmap_init_spi(dev, config)                               \
918         __regmap_lockdep_wrapper(__devm_regmap_init_spi, #config,       \
919                                 dev, config)
920
921 /**
922  * devm_regmap_init_spmi_base() - Create managed regmap for Base register space
923  *
924  * @dev:        SPMI device that will be interacted with
925  * @config:     Configuration for register map
926  *
927  * The return value will be an ERR_PTR() on error or a valid pointer
928  * to a struct regmap.  The regmap will be automatically freed by the
929  * device management code.
930  */
931 #define devm_regmap_init_spmi_base(dev, config)                         \
932         __regmap_lockdep_wrapper(__devm_regmap_init_spmi_base, #config, \
933                                 dev, config)
934
935 /**
936  * devm_regmap_init_spmi_ext() - Create managed regmap for Ext register space
937  *
938  * @dev:        SPMI device that will be interacted with
939  * @config:     Configuration for register map
940  *
941  * The return value will be an ERR_PTR() on error or a valid pointer
942  * to a struct regmap.  The regmap will be automatically freed by the
943  * device management code.
944  */
945 #define devm_regmap_init_spmi_ext(dev, config)                          \
946         __regmap_lockdep_wrapper(__devm_regmap_init_spmi_ext, #config,  \
947                                 dev, config)
948
949 /**
950  * devm_regmap_init_w1() - Initialise managed register map
951  *
952  * @w1_dev: Device that will be interacted with
953  * @config: Configuration for register map
954  *
955  * The return value will be an ERR_PTR() on error or a valid pointer
956  * to a struct regmap.  The regmap will be automatically freed by the
957  * device management code.
958  */
959 #define devm_regmap_init_w1(w1_dev, config)                             \
960         __regmap_lockdep_wrapper(__devm_regmap_init_w1, #config,        \
961                                 w1_dev, config)
962 /**
963  * devm_regmap_init_mmio_clk() - Initialise managed register map with clock
964  *
965  * @dev: Device that will be interacted with
966  * @clk_id: register clock consumer ID
967  * @regs: Pointer to memory-mapped IO region
968  * @config: Configuration for register map
969  *
970  * The return value will be an ERR_PTR() on error or a valid pointer
971  * to a struct regmap.  The regmap will be automatically freed by the
972  * device management code.
973  */
974 #define devm_regmap_init_mmio_clk(dev, clk_id, regs, config)            \
975         __regmap_lockdep_wrapper(__devm_regmap_init_mmio_clk, #config,  \
976                                 dev, clk_id, regs, config)
977
978 /**
979  * devm_regmap_init_mmio() - Initialise managed register map
980  *
981  * @dev: Device that will be interacted with
982  * @regs: Pointer to memory-mapped IO region
983  * @config: Configuration for register map
984  *
985  * The return value will be an ERR_PTR() on error or a valid pointer
986  * to a struct regmap.  The regmap will be automatically freed by the
987  * device management code.
988  */
989 #define devm_regmap_init_mmio(dev, regs, config)                \
990         devm_regmap_init_mmio_clk(dev, NULL, regs, config)
991
992 /**
993  * devm_regmap_init_ac97() - Initialise AC'97 register map
994  *
995  * @ac97: Device that will be interacted with
996  * @config: Configuration for register map
997  *
998  * The return value will be an ERR_PTR() on error or a valid pointer
999  * to a struct regmap.  The regmap will be automatically freed by the
1000  * device management code.
1001  */
1002 #define devm_regmap_init_ac97(ac97, config)                             \
1003         __regmap_lockdep_wrapper(__devm_regmap_init_ac97, #config,      \
1004                                 ac97, config)
1005
1006 /**
1007  * devm_regmap_init_sdw() - Initialise managed register map
1008  *
1009  * @sdw: Device that will be interacted with
1010  * @config: Configuration for register map
1011  *
1012  * The return value will be an ERR_PTR() on error or a valid pointer
1013  * to a struct regmap. The regmap will be automatically freed by the
1014  * device management code.
1015  */
1016 #define devm_regmap_init_sdw(sdw, config)                               \
1017         __regmap_lockdep_wrapper(__devm_regmap_init_sdw, #config,       \
1018                                 sdw, config)
1019
1020 /**
1021  * devm_regmap_init_slimbus() - Initialise managed register map
1022  *
1023  * @slimbus: Device that will be interacted with
1024  * @config: Configuration for register map
1025  *
1026  * The return value will be an ERR_PTR() on error or a valid pointer
1027  * to a struct regmap. The regmap will be automatically freed by the
1028  * device management code.
1029  */
1030 #define devm_regmap_init_slimbus(slimbus, config)                       \
1031         __regmap_lockdep_wrapper(__devm_regmap_init_slimbus, #config,   \
1032                                 slimbus, config)
1033
1034 /**
1035  * devm_regmap_init_i3c() - Initialise managed register map
1036  *
1037  * @i3c: Device that will be interacted with
1038  * @config: Configuration for register map
1039  *
1040  * The return value will be an ERR_PTR() on error or a valid pointer
1041  * to a struct regmap.  The regmap will be automatically freed by the
1042  * device management code.
1043  */
1044 #define devm_regmap_init_i3c(i3c, config)                               \
1045         __regmap_lockdep_wrapper(__devm_regmap_init_i3c, #config,       \
1046                                 i3c, config)
1047
1048 int regmap_mmio_attach_clk(struct regmap *map, struct clk *clk);
1049 void regmap_mmio_detach_clk(struct regmap *map);
1050 void regmap_exit(struct regmap *map);
1051 int regmap_reinit_cache(struct regmap *map,
1052                         const struct regmap_config *config);
1053 struct regmap *dev_get_regmap(struct device *dev, const char *name);
1054 struct device *regmap_get_device(struct regmap *map);
1055 int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
1056 int regmap_write_async(struct regmap *map, unsigned int reg, unsigned int val);
1057 int regmap_raw_write(struct regmap *map, unsigned int reg,
1058                      const void *val, size_t val_len);
1059 int regmap_noinc_write(struct regmap *map, unsigned int reg,
1060                      const void *val, size_t val_len);
1061 int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
1062                         size_t val_count);
1063 int regmap_multi_reg_write(struct regmap *map, const struct reg_sequence *regs,
1064                         int num_regs);
1065 int regmap_multi_reg_write_bypassed(struct regmap *map,
1066                                     const struct reg_sequence *regs,
1067                                     int num_regs);
1068 int regmap_raw_write_async(struct regmap *map, unsigned int reg,
1069                            const void *val, size_t val_len);
1070 int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
1071 int regmap_raw_read(struct regmap *map, unsigned int reg,
1072                     void *val, size_t val_len);
1073 int regmap_noinc_read(struct regmap *map, unsigned int reg,
1074                       void *val, size_t val_len);
1075 int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
1076                      size_t val_count);
1077 int regmap_update_bits_base(struct regmap *map, unsigned int reg,
1078                             unsigned int mask, unsigned int val,
1079                             bool *change, bool async, bool force);
1080 int regmap_get_val_bytes(struct regmap *map);
1081 int regmap_get_max_register(struct regmap *map);
1082 int regmap_get_reg_stride(struct regmap *map);
1083 int regmap_async_complete(struct regmap *map);
1084 bool regmap_can_raw_write(struct regmap *map);
1085 size_t regmap_get_raw_read_max(struct regmap *map);
1086 size_t regmap_get_raw_write_max(struct regmap *map);
1087
1088 int regcache_sync(struct regmap *map);
1089 int regcache_sync_region(struct regmap *map, unsigned int min,
1090                          unsigned int max);
1091 int regcache_drop_region(struct regmap *map, unsigned int min,
1092                          unsigned int max);
1093 void regcache_cache_only(struct regmap *map, bool enable);
1094 void regcache_cache_bypass(struct regmap *map, bool enable);
1095 void regcache_mark_dirty(struct regmap *map);
1096
1097 bool regmap_check_range_table(struct regmap *map, unsigned int reg,
1098                               const struct regmap_access_table *table);
1099
1100 int regmap_register_patch(struct regmap *map, const struct reg_sequence *regs,
1101                           int num_regs);
1102 int regmap_parse_val(struct regmap *map, const void *buf,
1103                                 unsigned int *val);
1104
1105 static inline bool regmap_reg_in_range(unsigned int reg,
1106                                        const struct regmap_range *range)
1107 {
1108         return reg >= range->range_min && reg <= range->range_max;
1109 }
1110
1111 bool regmap_reg_in_ranges(unsigned int reg,
1112                           const struct regmap_range *ranges,
1113                           unsigned int nranges);
1114
1115 /**
1116  * struct reg_field - Description of an register field
1117  *
1118  * @reg: Offset of the register within the regmap bank
1119  * @lsb: lsb of the register field.
1120  * @msb: msb of the register field.
1121  * @id_size: port size if it has some ports
1122  * @id_offset: address offset for each ports
1123  */
1124 struct reg_field {
1125         unsigned int reg;
1126         unsigned int lsb;
1127         unsigned int msb;
1128         unsigned int id_size;
1129         unsigned int id_offset;
1130 };
1131
1132 #define REG_FIELD(_reg, _lsb, _msb) {           \
1133                                 .reg = _reg,    \
1134                                 .lsb = _lsb,    \
1135                                 .msb = _msb,    \
1136                                 }
1137
1138 struct regmap_field *regmap_field_alloc(struct regmap *regmap,
1139                 struct reg_field reg_field);
1140 void regmap_field_free(struct regmap_field *field);
1141
1142 struct regmap_field *devm_regmap_field_alloc(struct device *dev,
1143                 struct regmap *regmap, struct reg_field reg_field);
1144 void devm_regmap_field_free(struct device *dev, struct regmap_field *field);
1145
1146 int regmap_field_read(struct regmap_field *field, unsigned int *val);
1147 int regmap_field_update_bits_base(struct regmap_field *field,
1148                                   unsigned int mask, unsigned int val,
1149                                   bool *change, bool async, bool force);
1150 int regmap_fields_read(struct regmap_field *field, unsigned int id,
1151                        unsigned int *val);
1152 int regmap_fields_update_bits_base(struct regmap_field *field,  unsigned int id,
1153                                    unsigned int mask, unsigned int val,
1154                                    bool *change, bool async, bool force);
1155 /**
1156  * struct regmap_irq_type - IRQ type definitions.
1157  *
1158  * @type_reg_offset: Offset register for the irq type setting.
1159  * @type_rising_val: Register value to configure RISING type irq.
1160  * @type_falling_val: Register value to configure FALLING type irq.
1161  * @type_level_low_val: Register value to configure LEVEL_LOW type irq.
1162  * @type_level_high_val: Register value to configure LEVEL_HIGH type irq.
1163  * @types_supported: logical OR of IRQ_TYPE_* flags indicating supported types.
1164  */
1165 struct regmap_irq_type {
1166         unsigned int type_reg_offset;
1167         unsigned int type_reg_mask;
1168         unsigned int type_rising_val;
1169         unsigned int type_falling_val;
1170         unsigned int type_level_low_val;
1171         unsigned int type_level_high_val;
1172         unsigned int types_supported;
1173 };
1174
1175 /**
1176  * struct regmap_irq - Description of an IRQ for the generic regmap irq_chip.
1177  *
1178  * @reg_offset: Offset of the status/mask register within the bank
1179  * @mask:       Mask used to flag/control the register.
1180  * @type:       IRQ trigger type setting details if supported.
1181  */
1182 struct regmap_irq {
1183         unsigned int reg_offset;
1184         unsigned int mask;
1185         struct regmap_irq_type type;
1186 };
1187
1188 #define REGMAP_IRQ_REG(_irq, _off, _mask)               \
1189         [_irq] = { .reg_offset = (_off), .mask = (_mask) }
1190
1191 #define REGMAP_IRQ_REG_LINE(_id, _reg_bits) \
1192         [_id] = {                               \
1193                 .mask = BIT((_id) % (_reg_bits)),       \
1194                 .reg_offset = (_id) / (_reg_bits),      \
1195         }
1196
1197 #define REGMAP_IRQ_MAIN_REG_OFFSET(arr)                         \
1198         { .num_regs = ARRAY_SIZE((arr)), .offset = &(arr)[0] }
1199
1200 struct regmap_irq_sub_irq_map {
1201         unsigned int num_regs;
1202         unsigned int *offset;
1203 };
1204
1205 /**
1206  * struct regmap_irq_chip - Description of a generic regmap irq_chip.
1207  *
1208  * @name:        Descriptive name for IRQ controller.
1209  *
1210  * @main_status: Base main status register address. For chips which have
1211  *               interrupts arranged in separate sub-irq blocks with own IRQ
1212  *               registers and which have a main IRQ registers indicating
1213  *               sub-irq blocks with unhandled interrupts. For such chips fill
1214  *               sub-irq register information in status_base, mask_base and
1215  *               ack_base.
1216  * @num_main_status_bits: Should be given to chips where number of meaningfull
1217  *                        main status bits differs from num_regs.
1218  * @sub_reg_offsets: arrays of mappings from main register bits to sub irq
1219  *                   registers. First item in array describes the registers
1220  *                   for first main status bit. Second array for second bit etc.
1221  *                   Offset is given as sub register status offset to
1222  *                   status_base. Should contain num_regs arrays.
1223  *                   Can be provided for chips with more complex mapping than
1224  *                   1.st bit to 1.st sub-reg, 2.nd bit to 2.nd sub-reg, ...
1225  * @num_main_regs: Number of 'main status' irq registers for chips which have
1226  *                 main_status set.
1227  *
1228  * @status_base: Base status register address.
1229  * @mask_base:   Base mask register address.
1230  * @mask_writeonly: Base mask register is write only.
1231  * @unmask_base:  Base unmask register address. for chips who have
1232  *                separate mask and unmask registers
1233  * @ack_base:    Base ack address. If zero then the chip is clear on read.
1234  *               Using zero value is possible with @use_ack bit.
1235  * @wake_base:   Base address for wake enables.  If zero unsupported.
1236  * @type_base:   Base address for irq type.  If zero unsupported.
1237  * @irq_reg_stride:  Stride to use for chips where registers are not contiguous.
1238  * @init_ack_masked: Ack all masked interrupts once during initalization.
1239  * @mask_invert: Inverted mask register: cleared bits are masked out.
1240  * @use_ack:     Use @ack register even if it is zero.
1241  * @ack_invert:  Inverted ack register: cleared bits for ack.
1242  * @wake_invert: Inverted wake register: cleared bits are wake enabled.
1243  * @type_invert: Invert the type flags.
1244  * @type_in_mask: Use the mask registers for controlling irq type. For
1245  *                interrupts defining type_rising/falling_mask use mask_base
1246  *                for edge configuration and never update bits in type_base.
1247  * @clear_on_unmask: For chips with interrupts cleared on read: read the status
1248  *                   registers before unmasking interrupts to clear any bits
1249  *                   set when they were masked.
1250  * @runtime_pm:  Hold a runtime PM lock on the device when accessing it.
1251  *
1252  * @num_regs:    Number of registers in each control bank.
1253  * @irqs:        Descriptors for individual IRQs.  Interrupt numbers are
1254  *               assigned based on the index in the array of the interrupt.
1255  * @num_irqs:    Number of descriptors.
1256  * @num_type_reg:    Number of type registers.
1257  * @type_reg_stride: Stride to use for chips where type registers are not
1258  *                      contiguous.
1259  * @handle_pre_irq:  Driver specific callback to handle interrupt from device
1260  *                   before regmap_irq_handler process the interrupts.
1261  * @handle_post_irq: Driver specific callback to handle interrupt from device
1262  *                   after handling the interrupts in regmap_irq_handler().
1263  * @irq_drv_data:    Driver specific IRQ data which is passed as parameter when
1264  *                   driver specific pre/post interrupt handler is called.
1265  *
1266  * This is not intended to handle every possible interrupt controller, but
1267  * it should handle a substantial proportion of those that are found in the
1268  * wild.
1269  */
1270 struct regmap_irq_chip {
1271         const char *name;
1272
1273         unsigned int main_status;
1274         unsigned int num_main_status_bits;
1275         struct regmap_irq_sub_irq_map *sub_reg_offsets;
1276         int num_main_regs;
1277
1278         unsigned int status_base;
1279         unsigned int mask_base;
1280         unsigned int unmask_base;
1281         unsigned int ack_base;
1282         unsigned int wake_base;
1283         unsigned int type_base;
1284         unsigned int irq_reg_stride;
1285         bool mask_writeonly:1;
1286         bool init_ack_masked:1;
1287         bool mask_invert:1;
1288         bool use_ack:1;
1289         bool ack_invert:1;
1290         bool wake_invert:1;
1291         bool runtime_pm:1;
1292         bool type_invert:1;
1293         bool type_in_mask:1;
1294         bool clear_on_unmask:1;
1295
1296         int num_regs;
1297
1298         const struct regmap_irq *irqs;
1299         int num_irqs;
1300
1301         int num_type_reg;
1302         unsigned int type_reg_stride;
1303
1304         int (*handle_pre_irq)(void *irq_drv_data);
1305         int (*handle_post_irq)(void *irq_drv_data);
1306         void *irq_drv_data;
1307 };
1308
1309 struct regmap_irq_chip_data;
1310
1311 int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
1312                         int irq_base, const struct regmap_irq_chip *chip,
1313                         struct regmap_irq_chip_data **data);
1314 int regmap_add_irq_chip_np(struct device_node *np, struct regmap *map, int irq,
1315                            int irq_flags, int irq_base,
1316                            const struct regmap_irq_chip *chip,
1317                            struct regmap_irq_chip_data **data);
1318 void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data);
1319
1320 int devm_regmap_add_irq_chip(struct device *dev, struct regmap *map, int irq,
1321                              int irq_flags, int irq_base,
1322                              const struct regmap_irq_chip *chip,
1323                              struct regmap_irq_chip_data **data);
1324 int devm_regmap_add_irq_chip_np(struct device *dev, struct device_node *np,
1325                                 struct regmap *map, int irq, int irq_flags,
1326                                 int irq_base,
1327                                 const struct regmap_irq_chip *chip,
1328                                 struct regmap_irq_chip_data **data);
1329 void devm_regmap_del_irq_chip(struct device *dev, int irq,
1330                               struct regmap_irq_chip_data *data);
1331
1332 int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data);
1333 int regmap_irq_get_virq(struct regmap_irq_chip_data *data, int irq);
1334 struct irq_domain *regmap_irq_get_domain(struct regmap_irq_chip_data *data);
1335
1336 #else
1337
1338 /*
1339  * These stubs should only ever be called by generic code which has
1340  * regmap based facilities, if they ever get called at runtime
1341  * something is going wrong and something probably needs to select
1342  * REGMAP.
1343  */
1344
1345 static inline int regmap_write(struct regmap *map, unsigned int reg,
1346                                unsigned int val)
1347 {
1348         WARN_ONCE(1, "regmap API is disabled");
1349         return -EINVAL;
1350 }
1351
1352 static inline int regmap_write_async(struct regmap *map, unsigned int reg,
1353                                      unsigned int val)
1354 {
1355         WARN_ONCE(1, "regmap API is disabled");
1356         return -EINVAL;
1357 }
1358
1359 static inline int regmap_raw_write(struct regmap *map, unsigned int reg,
1360                                    const void *val, size_t val_len)
1361 {
1362         WARN_ONCE(1, "regmap API is disabled");
1363         return -EINVAL;
1364 }
1365
1366 static inline int regmap_raw_write_async(struct regmap *map, unsigned int reg,
1367                                          const void *val, size_t val_len)
1368 {
1369         WARN_ONCE(1, "regmap API is disabled");
1370         return -EINVAL;
1371 }
1372
1373 static inline int regmap_noinc_write(struct regmap *map, unsigned int reg,
1374                                     const void *val, size_t val_len)
1375 {
1376         WARN_ONCE(1, "regmap API is disabled");
1377         return -EINVAL;
1378 }
1379
1380 static inline int regmap_bulk_write(struct regmap *map, unsigned int reg,
1381                                     const void *val, size_t val_count)
1382 {
1383         WARN_ONCE(1, "regmap API is disabled");
1384         return -EINVAL;
1385 }
1386
1387 static inline int regmap_read(struct regmap *map, unsigned int reg,
1388                               unsigned int *val)
1389 {
1390         WARN_ONCE(1, "regmap API is disabled");
1391         return -EINVAL;
1392 }
1393
1394 static inline int regmap_raw_read(struct regmap *map, unsigned int reg,
1395                                   void *val, size_t val_len)
1396 {
1397         WARN_ONCE(1, "regmap API is disabled");
1398         return -EINVAL;
1399 }
1400
1401 static inline int regmap_noinc_read(struct regmap *map, unsigned int reg,
1402                                     void *val, size_t val_len)
1403 {
1404         WARN_ONCE(1, "regmap API is disabled");
1405         return -EINVAL;
1406 }
1407
1408 static inline int regmap_bulk_read(struct regmap *map, unsigned int reg,
1409                                    void *val, size_t val_count)
1410 {
1411         WARN_ONCE(1, "regmap API is disabled");
1412         return -EINVAL;
1413 }
1414
1415 static inline int regmap_update_bits_base(struct regmap *map, unsigned int reg,
1416                                           unsigned int mask, unsigned int val,
1417                                           bool *change, bool async, bool force)
1418 {
1419         WARN_ONCE(1, "regmap API is disabled");
1420         return -EINVAL;
1421 }
1422
1423 static inline int regmap_field_update_bits_base(struct regmap_field *field,
1424                                         unsigned int mask, unsigned int val,
1425                                         bool *change, bool async, bool force)
1426 {
1427         WARN_ONCE(1, "regmap API is disabled");
1428         return -EINVAL;
1429 }
1430
1431 static inline int regmap_fields_update_bits_base(struct regmap_field *field,
1432                                    unsigned int id,
1433                                    unsigned int mask, unsigned int val,
1434                                    bool *change, bool async, bool force)
1435 {
1436         WARN_ONCE(1, "regmap API is disabled");
1437         return -EINVAL;
1438 }
1439
1440 static inline int regmap_get_val_bytes(struct regmap *map)
1441 {
1442         WARN_ONCE(1, "regmap API is disabled");
1443         return -EINVAL;
1444 }
1445
1446 static inline int regmap_get_max_register(struct regmap *map)
1447 {
1448         WARN_ONCE(1, "regmap API is disabled");
1449         return -EINVAL;
1450 }
1451
1452 static inline int regmap_get_reg_stride(struct regmap *map)
1453 {
1454         WARN_ONCE(1, "regmap API is disabled");
1455         return -EINVAL;
1456 }
1457
1458 static inline int regcache_sync(struct regmap *map)
1459 {
1460         WARN_ONCE(1, "regmap API is disabled");
1461         return -EINVAL;
1462 }
1463
1464 static inline int regcache_sync_region(struct regmap *map, unsigned int min,
1465                                        unsigned int max)
1466 {
1467         WARN_ONCE(1, "regmap API is disabled");
1468         return -EINVAL;
1469 }
1470
1471 static inline int regcache_drop_region(struct regmap *map, unsigned int min,
1472                                        unsigned int max)
1473 {
1474         WARN_ONCE(1, "regmap API is disabled");
1475         return -EINVAL;
1476 }
1477
1478 static inline void regcache_cache_only(struct regmap *map, bool enable)
1479 {
1480         WARN_ONCE(1, "regmap API is disabled");
1481 }
1482
1483 static inline void regcache_cache_bypass(struct regmap *map, bool enable)
1484 {
1485         WARN_ONCE(1, "regmap API is disabled");
1486 }
1487
1488 static inline void regcache_mark_dirty(struct regmap *map)
1489 {
1490         WARN_ONCE(1, "regmap API is disabled");
1491 }
1492
1493 static inline void regmap_async_complete(struct regmap *map)
1494 {
1495         WARN_ONCE(1, "regmap API is disabled");
1496 }
1497
1498 static inline int regmap_register_patch(struct regmap *map,
1499                                         const struct reg_sequence *regs,
1500                                         int num_regs)
1501 {
1502         WARN_ONCE(1, "regmap API is disabled");
1503         return -EINVAL;
1504 }
1505
1506 static inline int regmap_parse_val(struct regmap *map, const void *buf,
1507                                 unsigned int *val)
1508 {
1509         WARN_ONCE(1, "regmap API is disabled");
1510         return -EINVAL;
1511 }
1512
1513 static inline struct regmap *dev_get_regmap(struct device *dev,
1514                                             const char *name)
1515 {
1516         return NULL;
1517 }
1518
1519 static inline struct device *regmap_get_device(struct regmap *map)
1520 {
1521         WARN_ONCE(1, "regmap API is disabled");
1522         return NULL;
1523 }
1524
1525 #endif
1526
1527 #endif