1 /* SPDX-License-Identifier: GPL-2.0-only */
2 #ifndef __LINUX_REGMAP_H
3 #define __LINUX_REGMAP_H
6 * Register map access API
8 * Copyright 2011 Wolfson Microelectronics plc
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 #include <linux/iopoll.h>
21 #include <linux/fwnode.h>
35 struct regmap_range_cfg;
40 /* An enum of all the supported cache types */
49 * struct reg_default - Default value for a register.
51 * @reg: Register address.
52 * @def: Register default value.
54 * We use an array of structs rather than a simple array as many modern devices
55 * have very sparse register maps.
63 * struct reg_sequence - An individual write from a sequence of writes.
65 * @reg: Register address.
66 * @def: Register value.
67 * @delay_us: Delay to be applied after the register write in microseconds
69 * Register/value pairs for sequences of writes with an optional delay in
70 * microseconds to be applied after each write.
75 unsigned int delay_us;
78 #define REG_SEQ(_reg, _def, _delay_us) { \
81 .delay_us = _delay_us, \
83 #define REG_SEQ0(_reg, _def) REG_SEQ(_reg, _def, 0)
86 * regmap_read_poll_timeout - Poll until a condition is met or a timeout occurs
88 * @map: Regmap to read from
89 * @addr: Address to poll
90 * @val: Unsigned integer variable to read the value into
91 * @cond: Break condition (usually involving @val)
92 * @sleep_us: Maximum time to sleep between reads in us (0
93 * tight-loops). Should be less than ~20ms since usleep_range
94 * is used (see Documentation/timers/timers-howto.rst).
95 * @timeout_us: Timeout in us, 0 means never timeout
97 * Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_read
98 * error return value in case of a error read. In the two former cases,
99 * the last read value at @addr is stored in @val. Must not be called
100 * from atomic context if sleep_us or timeout_us are used.
102 * This is modelled after the readx_poll_timeout macros in linux/iopoll.h.
104 #define regmap_read_poll_timeout(map, addr, val, cond, sleep_us, timeout_us) \
107 __tmp = read_poll_timeout(regmap_read, __ret, __ret || (cond), \
108 sleep_us, timeout_us, false, (map), (addr), &(val)); \
113 * regmap_read_poll_timeout_atomic - Poll until a condition is met or a timeout occurs
115 * @map: Regmap to read from
116 * @addr: Address to poll
117 * @val: Unsigned integer variable to read the value into
118 * @cond: Break condition (usually involving @val)
119 * @delay_us: Time to udelay between reads in us (0 tight-loops).
120 * Should be less than ~10us since udelay is used
121 * (see Documentation/timers/timers-howto.rst).
122 * @timeout_us: Timeout in us, 0 means never timeout
124 * Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_read
125 * error return value in case of a error read. In the two former cases,
126 * the last read value at @addr is stored in @val.
128 * This is modelled after the readx_poll_timeout_atomic macros in linux/iopoll.h.
130 * Note: In general regmap cannot be used in atomic context. If you want to use
131 * this macro then first setup your regmap for atomic use (flat or no cache
134 #define regmap_read_poll_timeout_atomic(map, addr, val, cond, delay_us, timeout_us) \
136 u64 __timeout_us = (timeout_us); \
137 unsigned long __delay_us = (delay_us); \
138 ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \
141 __ret = regmap_read((map), (addr), &(val)); \
146 if ((__timeout_us) && \
147 ktime_compare(ktime_get(), __timeout) > 0) { \
148 __ret = regmap_read((map), (addr), &(val)); \
152 udelay(__delay_us); \
154 __ret ?: ((cond) ? 0 : -ETIMEDOUT); \
158 * regmap_field_read_poll_timeout - Poll until a condition is met or timeout
160 * @field: Regmap field to read from
161 * @val: Unsigned integer variable to read the value into
162 * @cond: Break condition (usually involving @val)
163 * @sleep_us: Maximum time to sleep between reads in us (0
164 * tight-loops). Should be less than ~20ms since usleep_range
165 * is used (see Documentation/timers/timers-howto.rst).
166 * @timeout_us: Timeout in us, 0 means never timeout
168 * Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_field_read
169 * error return value in case of a error read. In the two former cases,
170 * the last read value at @addr is stored in @val. Must not be called
171 * from atomic context if sleep_us or timeout_us are used.
173 * This is modelled after the readx_poll_timeout macros in linux/iopoll.h.
175 #define regmap_field_read_poll_timeout(field, val, cond, sleep_us, timeout_us) \
178 __tmp = read_poll_timeout(regmap_field_read, __ret, __ret || (cond), \
179 sleep_us, timeout_us, false, (field), &(val)); \
186 /* Unspecified -> 0 -> Backwards compatible default */
187 REGMAP_ENDIAN_DEFAULT = 0,
189 REGMAP_ENDIAN_LITTLE,
190 REGMAP_ENDIAN_NATIVE,
194 * struct regmap_range - A register range, used for access related checks
195 * (readable/writeable/volatile/precious checks)
197 * @range_min: address of first register
198 * @range_max: address of last register
200 struct regmap_range {
201 unsigned int range_min;
202 unsigned int range_max;
205 #define regmap_reg_range(low, high) { .range_min = low, .range_max = high, }
208 * struct regmap_access_table - A table of register ranges for access checks
210 * @yes_ranges : pointer to an array of regmap ranges used as "yes ranges"
211 * @n_yes_ranges: size of the above array
212 * @no_ranges: pointer to an array of regmap ranges used as "no ranges"
213 * @n_no_ranges: size of the above array
215 * A table of ranges including some yes ranges and some no ranges.
216 * If a register belongs to a no_range, the corresponding check function
217 * will return false. If a register belongs to a yes range, the corresponding
218 * check function will return true. "no_ranges" are searched first.
220 struct regmap_access_table {
221 const struct regmap_range *yes_ranges;
222 unsigned int n_yes_ranges;
223 const struct regmap_range *no_ranges;
224 unsigned int n_no_ranges;
227 typedef void (*regmap_lock)(void *);
228 typedef void (*regmap_unlock)(void *);
231 * struct regmap_config - Configuration for the register map of a device.
233 * @name: Optional name of the regmap. Useful when a device has multiple
236 * @reg_bits: Number of bits in a register address, mandatory.
237 * @reg_stride: The register address stride. Valid register addresses are a
238 * multiple of this value. If set to 0, a value of 1 will be
240 * @reg_downshift: The number of bits to downshift the register before
241 * performing any operations.
242 * @reg_base: Value to be added to every register address before performing any
244 * @pad_bits: Number of bits of padding between register and value.
245 * @val_bits: Number of bits in a register value, mandatory.
247 * @writeable_reg: Optional callback returning true if the register
248 * can be written to. If this field is NULL but wr_table
249 * (see below) is not, the check is performed on such table
250 * (a register is writeable if it belongs to one of the ranges
251 * specified by wr_table).
252 * @readable_reg: Optional callback returning true if the register
253 * can be read from. If this field is NULL but rd_table
254 * (see below) is not, the check is performed on such table
255 * (a register is readable if it belongs to one of the ranges
256 * specified by rd_table).
257 * @volatile_reg: Optional callback returning true if the register
258 * value can't be cached. If this field is NULL but
259 * volatile_table (see below) is not, the check is performed on
260 * such table (a register is volatile if it belongs to one of
261 * the ranges specified by volatile_table).
262 * @precious_reg: Optional callback returning true if the register
263 * should not be read outside of a call from the driver
264 * (e.g., a clear on read interrupt status register). If this
265 * field is NULL but precious_table (see below) is not, the
266 * check is performed on such table (a register is precious if
267 * it belongs to one of the ranges specified by precious_table).
268 * @writeable_noinc_reg: Optional callback returning true if the register
269 * supports multiple write operations without incrementing
270 * the register number. If this field is NULL but
271 * wr_noinc_table (see below) is not, the check is
272 * performed on such table (a register is no increment
273 * writeable if it belongs to one of the ranges specified
274 * by wr_noinc_table).
275 * @readable_noinc_reg: Optional callback returning true if the register
276 * supports multiple read operations without incrementing
277 * the register number. If this field is NULL but
278 * rd_noinc_table (see below) is not, the check is
279 * performed on such table (a register is no increment
280 * readable if it belongs to one of the ranges specified
281 * by rd_noinc_table).
282 * @disable_locking: This regmap is either protected by external means or
283 * is guaranteed not to be accessed from multiple threads.
284 * Don't use any locking mechanisms.
285 * @lock: Optional lock callback (overrides regmap's default lock
286 * function, based on spinlock or mutex).
287 * @unlock: As above for unlocking.
288 * @lock_arg: this field is passed as the only argument of lock/unlock
289 * functions (ignored in case regular lock/unlock functions
290 * are not overridden).
291 * @reg_read: Optional callback that if filled will be used to perform
292 * all the reads from the registers. Should only be provided for
293 * devices whose read operation cannot be represented as a simple
294 * read operation on a bus such as SPI, I2C, etc. Most of the
295 * devices do not need this.
296 * @reg_write: Same as above for writing.
297 * @reg_update_bits: Optional callback that if filled will be used to perform
298 * all the update_bits(rmw) operation. Should only be provided
299 * if the function require special handling with lock and reg
300 * handling and the operation cannot be represented as a simple
301 * update_bits operation on a bus such as SPI, I2C, etc.
302 * @read: Optional callback that if filled will be used to perform all the
303 * bulk reads from the registers. Data is returned in the buffer used
305 * @write: Same as above for writing.
306 * @max_raw_read: Max raw read size that can be used on the device.
307 * @max_raw_write: Max raw write size that can be used on the device.
308 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
309 * to perform locking. This field is ignored if custom lock/unlock
310 * functions are used (see fields lock/unlock of struct regmap_config).
311 * This field is a duplicate of a similar file in
312 * 'struct regmap_bus' and serves exact same purpose.
313 * Use it only for "no-bus" cases.
314 * @io_port: Support IO port accessors. Makes sense only when MMIO vs. IO port
315 * access can be distinguished.
316 * @max_register: Optional, specifies the maximum valid register address.
317 * @wr_table: Optional, points to a struct regmap_access_table specifying
318 * valid ranges for write access.
319 * @rd_table: As above, for read access.
320 * @volatile_table: As above, for volatile registers.
321 * @precious_table: As above, for precious registers.
322 * @wr_noinc_table: As above, for no increment writeable registers.
323 * @rd_noinc_table: As above, for no increment readable registers.
324 * @reg_defaults: Power on reset values for registers (for use with
325 * register cache support).
326 * @num_reg_defaults: Number of elements in reg_defaults.
328 * @read_flag_mask: Mask to be set in the top bytes of the register when doing
330 * @write_flag_mask: Mask to be set in the top bytes of the register when doing
331 * a write. If both read_flag_mask and write_flag_mask are
332 * empty and zero_flag_mask is not set the regmap_bus default
334 * @zero_flag_mask: If set, read_flag_mask and write_flag_mask are used even
335 * if they are both empty.
336 * @use_relaxed_mmio: If set, MMIO R/W operations will not use memory barriers.
337 * This can avoid load on devices which don't require strict
338 * orderings, but drivers should carefully add any explicit
339 * memory barriers when they may require them.
340 * @use_single_read: If set, converts the bulk read operation into a series of
341 * single read operations. This is useful for a device that
342 * does not support bulk read.
343 * @use_single_write: If set, converts the bulk write operation into a series of
344 * single write operations. This is useful for a device that
345 * does not support bulk write.
346 * @can_multi_write: If set, the device supports the multi write mode of bulk
347 * write operations, if clear multi write requests will be
348 * split into individual write operations
350 * @cache_type: The actual cache type.
351 * @reg_defaults_raw: Power on reset values for registers (for use with
352 * register cache support).
353 * @num_reg_defaults_raw: Number of elements in reg_defaults_raw.
354 * @reg_format_endian: Endianness for formatted register addresses. If this is
355 * DEFAULT, the @reg_format_endian_default value from the
356 * regmap bus is used.
357 * @val_format_endian: Endianness for formatted register values. If this is
358 * DEFAULT, the @reg_format_endian_default value from the
359 * regmap bus is used.
361 * @ranges: Array of configuration entries for virtual address ranges.
362 * @num_ranges: Number of range configuration entries.
363 * @use_hwlock: Indicate if a hardware spinlock should be used.
364 * @use_raw_spinlock: Indicate if a raw spinlock should be used.
365 * @hwlock_id: Specify the hardware spinlock id.
366 * @hwlock_mode: The hardware spinlock mode, should be HWLOCK_IRQSTATE,
368 * @can_sleep: Optional, specifies whether regmap operations can sleep.
370 struct regmap_config {
376 unsigned int reg_base;
380 bool (*writeable_reg)(struct device *dev, unsigned int reg);
381 bool (*readable_reg)(struct device *dev, unsigned int reg);
382 bool (*volatile_reg)(struct device *dev, unsigned int reg);
383 bool (*precious_reg)(struct device *dev, unsigned int reg);
384 bool (*writeable_noinc_reg)(struct device *dev, unsigned int reg);
385 bool (*readable_noinc_reg)(struct device *dev, unsigned int reg);
387 bool disable_locking;
389 regmap_unlock unlock;
392 int (*reg_read)(void *context, unsigned int reg, unsigned int *val);
393 int (*reg_write)(void *context, unsigned int reg, unsigned int val);
394 int (*reg_update_bits)(void *context, unsigned int reg,
395 unsigned int mask, unsigned int val);
396 /* Bulk read/write */
397 int (*read)(void *context, const void *reg_buf, size_t reg_size,
398 void *val_buf, size_t val_size);
399 int (*write)(void *context, const void *data, size_t count);
401 size_t max_raw_write;
406 unsigned int max_register;
407 const struct regmap_access_table *wr_table;
408 const struct regmap_access_table *rd_table;
409 const struct regmap_access_table *volatile_table;
410 const struct regmap_access_table *precious_table;
411 const struct regmap_access_table *wr_noinc_table;
412 const struct regmap_access_table *rd_noinc_table;
413 const struct reg_default *reg_defaults;
414 unsigned int num_reg_defaults;
415 enum regcache_type cache_type;
416 const void *reg_defaults_raw;
417 unsigned int num_reg_defaults_raw;
419 unsigned long read_flag_mask;
420 unsigned long write_flag_mask;
423 bool use_single_read;
424 bool use_single_write;
425 bool use_relaxed_mmio;
426 bool can_multi_write;
428 enum regmap_endian reg_format_endian;
429 enum regmap_endian val_format_endian;
431 const struct regmap_range_cfg *ranges;
432 unsigned int num_ranges;
435 bool use_raw_spinlock;
436 unsigned int hwlock_id;
437 unsigned int hwlock_mode;
443 * struct regmap_range_cfg - Configuration for indirectly accessed or paged
446 * @name: Descriptive name for diagnostics
448 * @range_min: Address of the lowest register address in virtual range.
449 * @range_max: Address of the highest register in virtual range.
451 * @selector_reg: Register with selector field.
452 * @selector_mask: Bit mask for selector value.
453 * @selector_shift: Bit shift for selector value.
455 * @window_start: Address of first (lowest) register in data window.
456 * @window_len: Number of registers in data window.
458 * Registers, mapped to this virtual range, are accessed in two steps:
459 * 1. page selector register update;
460 * 2. access through data window registers.
462 struct regmap_range_cfg {
465 /* Registers of virtual address range */
466 unsigned int range_min;
467 unsigned int range_max;
469 /* Page selector for indirect addressing */
470 unsigned int selector_reg;
471 unsigned int selector_mask;
474 /* Data window (per each page) */
475 unsigned int window_start;
476 unsigned int window_len;
481 typedef int (*regmap_hw_write)(void *context, const void *data,
483 typedef int (*regmap_hw_gather_write)(void *context,
484 const void *reg, size_t reg_len,
485 const void *val, size_t val_len);
486 typedef int (*regmap_hw_async_write)(void *context,
487 const void *reg, size_t reg_len,
488 const void *val, size_t val_len,
489 struct regmap_async *async);
490 typedef int (*regmap_hw_read)(void *context,
491 const void *reg_buf, size_t reg_size,
492 void *val_buf, size_t val_size);
493 typedef int (*regmap_hw_reg_read)(void *context, unsigned int reg,
495 typedef int (*regmap_hw_reg_noinc_read)(void *context, unsigned int reg,
496 void *val, size_t val_count);
497 typedef int (*regmap_hw_reg_write)(void *context, unsigned int reg,
499 typedef int (*regmap_hw_reg_noinc_write)(void *context, unsigned int reg,
500 const void *val, size_t val_count);
501 typedef int (*regmap_hw_reg_update_bits)(void *context, unsigned int reg,
502 unsigned int mask, unsigned int val);
503 typedef struct regmap_async *(*regmap_hw_async_alloc)(void);
504 typedef void (*regmap_hw_free_context)(void *context);
507 * struct regmap_bus - Description of a hardware bus for the register map
510 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
511 * to perform locking. This field is ignored if custom lock/unlock
512 * functions are used (see fields lock/unlock of
513 * struct regmap_config).
514 * @write: Write operation.
515 * @gather_write: Write operation with split register/value, return -ENOTSUPP
516 * if not implemented on a given device.
517 * @async_write: Write operation which completes asynchronously, optional and
518 * must serialise with respect to non-async I/O.
519 * @reg_write: Write a single register value to the given register address. This
520 * write operation has to complete when returning from the function.
521 * @reg_write_noinc: Write multiple register value to the same register. This
522 * write operation has to complete when returning from the function.
523 * @reg_update_bits: Update bits operation to be used against volatile
524 * registers, intended for devices supporting some mechanism
525 * for setting clearing bits without having to
527 * @read: Read operation. Data is returned in the buffer used to transmit
529 * @reg_read: Read a single register value from a given register address.
530 * @free_context: Free context.
531 * @async_alloc: Allocate a regmap_async() structure.
532 * @read_flag_mask: Mask to be set in the top byte of the register when doing
534 * @reg_format_endian_default: Default endianness for formatted register
535 * addresses. Used when the regmap_config specifies DEFAULT. If this is
536 * DEFAULT, BIG is assumed.
537 * @val_format_endian_default: Default endianness for formatted register
538 * values. Used when the regmap_config specifies DEFAULT. If this is
539 * DEFAULT, BIG is assumed.
540 * @max_raw_read: Max raw read size that can be used on the bus.
541 * @max_raw_write: Max raw write size that can be used on the bus.
542 * @free_on_exit: kfree this on exit of regmap
546 regmap_hw_write write;
547 regmap_hw_gather_write gather_write;
548 regmap_hw_async_write async_write;
549 regmap_hw_reg_write reg_write;
550 regmap_hw_reg_noinc_write reg_noinc_write;
551 regmap_hw_reg_update_bits reg_update_bits;
553 regmap_hw_reg_read reg_read;
554 regmap_hw_reg_noinc_read reg_noinc_read;
555 regmap_hw_free_context free_context;
556 regmap_hw_async_alloc async_alloc;
558 enum regmap_endian reg_format_endian_default;
559 enum regmap_endian val_format_endian_default;
561 size_t max_raw_write;
566 * __regmap_init functions.
568 * These functions take a lock key and name parameter, and should not be called
569 * directly. Instead, use the regmap_init macros that generate a key and name
572 struct regmap *__regmap_init(struct device *dev,
573 const struct regmap_bus *bus,
575 const struct regmap_config *config,
576 struct lock_class_key *lock_key,
577 const char *lock_name);
578 struct regmap *__regmap_init_i2c(struct i2c_client *i2c,
579 const struct regmap_config *config,
580 struct lock_class_key *lock_key,
581 const char *lock_name);
582 struct regmap *__regmap_init_mdio(struct mdio_device *mdio_dev,
583 const struct regmap_config *config,
584 struct lock_class_key *lock_key,
585 const char *lock_name);
586 struct regmap *__regmap_init_sccb(struct i2c_client *i2c,
587 const struct regmap_config *config,
588 struct lock_class_key *lock_key,
589 const char *lock_name);
590 struct regmap *__regmap_init_slimbus(struct slim_device *slimbus,
591 const struct regmap_config *config,
592 struct lock_class_key *lock_key,
593 const char *lock_name);
594 struct regmap *__regmap_init_spi(struct spi_device *dev,
595 const struct regmap_config *config,
596 struct lock_class_key *lock_key,
597 const char *lock_name);
598 struct regmap *__regmap_init_spmi_base(struct spmi_device *dev,
599 const struct regmap_config *config,
600 struct lock_class_key *lock_key,
601 const char *lock_name);
602 struct regmap *__regmap_init_spmi_ext(struct spmi_device *dev,
603 const struct regmap_config *config,
604 struct lock_class_key *lock_key,
605 const char *lock_name);
606 struct regmap *__regmap_init_w1(struct device *w1_dev,
607 const struct regmap_config *config,
608 struct lock_class_key *lock_key,
609 const char *lock_name);
610 struct regmap *__regmap_init_mmio_clk(struct device *dev, const char *clk_id,
612 const struct regmap_config *config,
613 struct lock_class_key *lock_key,
614 const char *lock_name);
615 struct regmap *__regmap_init_ac97(struct snd_ac97 *ac97,
616 const struct regmap_config *config,
617 struct lock_class_key *lock_key,
618 const char *lock_name);
619 struct regmap *__regmap_init_sdw(struct sdw_slave *sdw,
620 const struct regmap_config *config,
621 struct lock_class_key *lock_key,
622 const char *lock_name);
623 struct regmap *__regmap_init_sdw_mbq(struct sdw_slave *sdw,
624 const struct regmap_config *config,
625 struct lock_class_key *lock_key,
626 const char *lock_name);
627 struct regmap *__regmap_init_spi_avmm(struct spi_device *spi,
628 const struct regmap_config *config,
629 struct lock_class_key *lock_key,
630 const char *lock_name);
632 struct regmap *__devm_regmap_init(struct device *dev,
633 const struct regmap_bus *bus,
635 const struct regmap_config *config,
636 struct lock_class_key *lock_key,
637 const char *lock_name);
638 struct regmap *__devm_regmap_init_i2c(struct i2c_client *i2c,
639 const struct regmap_config *config,
640 struct lock_class_key *lock_key,
641 const char *lock_name);
642 struct regmap *__devm_regmap_init_mdio(struct mdio_device *mdio_dev,
643 const struct regmap_config *config,
644 struct lock_class_key *lock_key,
645 const char *lock_name);
646 struct regmap *__devm_regmap_init_sccb(struct i2c_client *i2c,
647 const struct regmap_config *config,
648 struct lock_class_key *lock_key,
649 const char *lock_name);
650 struct regmap *__devm_regmap_init_spi(struct spi_device *dev,
651 const struct regmap_config *config,
652 struct lock_class_key *lock_key,
653 const char *lock_name);
654 struct regmap *__devm_regmap_init_spmi_base(struct spmi_device *dev,
655 const struct regmap_config *config,
656 struct lock_class_key *lock_key,
657 const char *lock_name);
658 struct regmap *__devm_regmap_init_spmi_ext(struct spmi_device *dev,
659 const struct regmap_config *config,
660 struct lock_class_key *lock_key,
661 const char *lock_name);
662 struct regmap *__devm_regmap_init_w1(struct device *w1_dev,
663 const struct regmap_config *config,
664 struct lock_class_key *lock_key,
665 const char *lock_name);
666 struct regmap *__devm_regmap_init_mmio_clk(struct device *dev,
669 const struct regmap_config *config,
670 struct lock_class_key *lock_key,
671 const char *lock_name);
672 struct regmap *__devm_regmap_init_ac97(struct snd_ac97 *ac97,
673 const struct regmap_config *config,
674 struct lock_class_key *lock_key,
675 const char *lock_name);
676 struct regmap *__devm_regmap_init_sdw(struct sdw_slave *sdw,
677 const struct regmap_config *config,
678 struct lock_class_key *lock_key,
679 const char *lock_name);
680 struct regmap *__devm_regmap_init_sdw_mbq(struct sdw_slave *sdw,
681 const struct regmap_config *config,
682 struct lock_class_key *lock_key,
683 const char *lock_name);
684 struct regmap *__devm_regmap_init_slimbus(struct slim_device *slimbus,
685 const struct regmap_config *config,
686 struct lock_class_key *lock_key,
687 const char *lock_name);
688 struct regmap *__devm_regmap_init_i3c(struct i3c_device *i3c,
689 const struct regmap_config *config,
690 struct lock_class_key *lock_key,
691 const char *lock_name);
692 struct regmap *__devm_regmap_init_spi_avmm(struct spi_device *spi,
693 const struct regmap_config *config,
694 struct lock_class_key *lock_key,
695 const char *lock_name);
697 * Wrapper for regmap_init macros to include a unique lockdep key and name
698 * for each call. No-op if CONFIG_LOCKDEP is not set.
700 * @fn: Real function to call (in the form __[*_]regmap_init[_*])
701 * @name: Config variable name (#config in the calling macro)
703 #ifdef CONFIG_LOCKDEP
704 #define __regmap_lockdep_wrapper(fn, name, ...) \
707 static struct lock_class_key _key; \
708 fn(__VA_ARGS__, &_key, \
709 KBUILD_BASENAME ":" \
710 __stringify(__LINE__) ":" \
711 "(" name ")->lock"); \
715 #define __regmap_lockdep_wrapper(fn, name, ...) fn(__VA_ARGS__, NULL, NULL)
719 * regmap_init() - Initialise register map
721 * @dev: Device that will be interacted with
722 * @bus: Bus-specific callbacks to use with device
723 * @bus_context: Data passed to bus-specific callbacks
724 * @config: Configuration for register map
726 * The return value will be an ERR_PTR() on error or a valid pointer to
727 * a struct regmap. This function should generally not be called
728 * directly, it should be called by bus-specific init functions.
730 #define regmap_init(dev, bus, bus_context, config) \
731 __regmap_lockdep_wrapper(__regmap_init, #config, \
732 dev, bus, bus_context, config)
733 int regmap_attach_dev(struct device *dev, struct regmap *map,
734 const struct regmap_config *config);
737 * regmap_init_i2c() - Initialise register map
739 * @i2c: Device that will be interacted with
740 * @config: Configuration for register map
742 * The return value will be an ERR_PTR() on error or a valid pointer to
745 #define regmap_init_i2c(i2c, config) \
746 __regmap_lockdep_wrapper(__regmap_init_i2c, #config, \
750 * regmap_init_mdio() - Initialise register map
752 * @mdio_dev: Device that will be interacted with
753 * @config: Configuration for register map
755 * The return value will be an ERR_PTR() on error or a valid pointer to
758 #define regmap_init_mdio(mdio_dev, config) \
759 __regmap_lockdep_wrapper(__regmap_init_mdio, #config, \
763 * regmap_init_sccb() - Initialise register map
765 * @i2c: Device that will be interacted with
766 * @config: Configuration for register map
768 * The return value will be an ERR_PTR() on error or a valid pointer to
771 #define regmap_init_sccb(i2c, config) \
772 __regmap_lockdep_wrapper(__regmap_init_sccb, #config, \
776 * regmap_init_slimbus() - Initialise register map
778 * @slimbus: Device that will be interacted with
779 * @config: Configuration for register map
781 * The return value will be an ERR_PTR() on error or a valid pointer to
784 #define regmap_init_slimbus(slimbus, config) \
785 __regmap_lockdep_wrapper(__regmap_init_slimbus, #config, \
789 * regmap_init_spi() - Initialise register map
791 * @dev: Device that will be interacted with
792 * @config: Configuration for register map
794 * The return value will be an ERR_PTR() on error or a valid pointer to
797 #define regmap_init_spi(dev, config) \
798 __regmap_lockdep_wrapper(__regmap_init_spi, #config, \
802 * regmap_init_spmi_base() - Create regmap for the Base register space
804 * @dev: SPMI device that will be interacted with
805 * @config: Configuration for register map
807 * The return value will be an ERR_PTR() on error or a valid pointer to
810 #define regmap_init_spmi_base(dev, config) \
811 __regmap_lockdep_wrapper(__regmap_init_spmi_base, #config, \
815 * regmap_init_spmi_ext() - Create regmap for Ext register space
817 * @dev: Device that will be interacted with
818 * @config: Configuration for register map
820 * The return value will be an ERR_PTR() on error or a valid pointer to
823 #define regmap_init_spmi_ext(dev, config) \
824 __regmap_lockdep_wrapper(__regmap_init_spmi_ext, #config, \
828 * regmap_init_w1() - Initialise register map
830 * @w1_dev: Device that will be interacted with
831 * @config: Configuration for register map
833 * The return value will be an ERR_PTR() on error or a valid pointer to
836 #define regmap_init_w1(w1_dev, config) \
837 __regmap_lockdep_wrapper(__regmap_init_w1, #config, \
841 * regmap_init_mmio_clk() - Initialise register map with register clock
843 * @dev: Device that will be interacted with
844 * @clk_id: register clock consumer ID
845 * @regs: Pointer to memory-mapped IO region
846 * @config: Configuration for register map
848 * The return value will be an ERR_PTR() on error or a valid pointer to
851 #define regmap_init_mmio_clk(dev, clk_id, regs, config) \
852 __regmap_lockdep_wrapper(__regmap_init_mmio_clk, #config, \
853 dev, clk_id, regs, config)
856 * regmap_init_mmio() - Initialise register map
858 * @dev: Device that will be interacted with
859 * @regs: Pointer to memory-mapped IO region
860 * @config: Configuration for register map
862 * The return value will be an ERR_PTR() on error or a valid pointer to
865 #define regmap_init_mmio(dev, regs, config) \
866 regmap_init_mmio_clk(dev, NULL, regs, config)
869 * regmap_init_ac97() - Initialise AC'97 register map
871 * @ac97: Device that will be interacted with
872 * @config: Configuration for register map
874 * The return value will be an ERR_PTR() on error or a valid pointer to
877 #define regmap_init_ac97(ac97, config) \
878 __regmap_lockdep_wrapper(__regmap_init_ac97, #config, \
880 bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg);
883 * regmap_init_sdw() - Initialise register map
885 * @sdw: Device that will be interacted with
886 * @config: Configuration for register map
888 * The return value will be an ERR_PTR() on error or a valid pointer to
891 #define regmap_init_sdw(sdw, config) \
892 __regmap_lockdep_wrapper(__regmap_init_sdw, #config, \
896 * regmap_init_sdw_mbq() - Initialise register map
898 * @sdw: Device that will be interacted with
899 * @config: Configuration for register map
901 * The return value will be an ERR_PTR() on error or a valid pointer to
904 #define regmap_init_sdw_mbq(sdw, config) \
905 __regmap_lockdep_wrapper(__regmap_init_sdw_mbq, #config, \
909 * regmap_init_spi_avmm() - Initialize register map for Intel SPI Slave
912 * @spi: Device that will be interacted with
913 * @config: Configuration for register map
915 * The return value will be an ERR_PTR() on error or a valid pointer
916 * to a struct regmap.
918 #define regmap_init_spi_avmm(spi, config) \
919 __regmap_lockdep_wrapper(__regmap_init_spi_avmm, #config, \
923 * devm_regmap_init() - Initialise managed register map
925 * @dev: Device that will be interacted with
926 * @bus: Bus-specific callbacks to use with device
927 * @bus_context: Data passed to bus-specific callbacks
928 * @config: Configuration for register map
930 * The return value will be an ERR_PTR() on error or a valid pointer
931 * to a struct regmap. This function should generally not be called
932 * directly, it should be called by bus-specific init functions. The
933 * map will be automatically freed by the device management code.
935 #define devm_regmap_init(dev, bus, bus_context, config) \
936 __regmap_lockdep_wrapper(__devm_regmap_init, #config, \
937 dev, bus, bus_context, config)
940 * devm_regmap_init_i2c() - Initialise managed register map
942 * @i2c: Device that will be interacted with
943 * @config: Configuration for register map
945 * The return value will be an ERR_PTR() on error or a valid pointer
946 * to a struct regmap. The regmap will be automatically freed by the
947 * device management code.
949 #define devm_regmap_init_i2c(i2c, config) \
950 __regmap_lockdep_wrapper(__devm_regmap_init_i2c, #config, \
954 * devm_regmap_init_mdio() - Initialise managed register map
956 * @mdio_dev: Device that will be interacted with
957 * @config: Configuration for register map
959 * The return value will be an ERR_PTR() on error or a valid pointer
960 * to a struct regmap. The regmap will be automatically freed by the
961 * device management code.
963 #define devm_regmap_init_mdio(mdio_dev, config) \
964 __regmap_lockdep_wrapper(__devm_regmap_init_mdio, #config, \
968 * devm_regmap_init_sccb() - Initialise managed register map
970 * @i2c: Device that will be interacted with
971 * @config: Configuration for register map
973 * The return value will be an ERR_PTR() on error or a valid pointer
974 * to a struct regmap. The regmap will be automatically freed by the
975 * device management code.
977 #define devm_regmap_init_sccb(i2c, config) \
978 __regmap_lockdep_wrapper(__devm_regmap_init_sccb, #config, \
982 * devm_regmap_init_spi() - Initialise register map
984 * @dev: Device that will be interacted with
985 * @config: Configuration for register map
987 * The return value will be an ERR_PTR() on error or a valid pointer
988 * to a struct regmap. The map will be automatically freed by the
989 * device management code.
991 #define devm_regmap_init_spi(dev, config) \
992 __regmap_lockdep_wrapper(__devm_regmap_init_spi, #config, \
996 * devm_regmap_init_spmi_base() - Create managed regmap for Base register space
998 * @dev: SPMI device that will be interacted with
999 * @config: Configuration for register map
1001 * The return value will be an ERR_PTR() on error or a valid pointer
1002 * to a struct regmap. The regmap will be automatically freed by the
1003 * device management code.
1005 #define devm_regmap_init_spmi_base(dev, config) \
1006 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_base, #config, \
1010 * devm_regmap_init_spmi_ext() - Create managed regmap for Ext register space
1012 * @dev: SPMI device that will be interacted with
1013 * @config: Configuration for register map
1015 * The return value will be an ERR_PTR() on error or a valid pointer
1016 * to a struct regmap. The regmap will be automatically freed by the
1017 * device management code.
1019 #define devm_regmap_init_spmi_ext(dev, config) \
1020 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_ext, #config, \
1024 * devm_regmap_init_w1() - Initialise managed register map
1026 * @w1_dev: Device that will be interacted with
1027 * @config: Configuration for register map
1029 * The return value will be an ERR_PTR() on error or a valid pointer
1030 * to a struct regmap. The regmap will be automatically freed by the
1031 * device management code.
1033 #define devm_regmap_init_w1(w1_dev, config) \
1034 __regmap_lockdep_wrapper(__devm_regmap_init_w1, #config, \
1037 * devm_regmap_init_mmio_clk() - Initialise managed register map with clock
1039 * @dev: Device that will be interacted with
1040 * @clk_id: register clock consumer ID
1041 * @regs: Pointer to memory-mapped IO region
1042 * @config: Configuration for register map
1044 * The return value will be an ERR_PTR() on error or a valid pointer
1045 * to a struct regmap. The regmap will be automatically freed by the
1046 * device management code.
1048 #define devm_regmap_init_mmio_clk(dev, clk_id, regs, config) \
1049 __regmap_lockdep_wrapper(__devm_regmap_init_mmio_clk, #config, \
1050 dev, clk_id, regs, config)
1053 * devm_regmap_init_mmio() - Initialise managed register map
1055 * @dev: Device that will be interacted with
1056 * @regs: Pointer to memory-mapped IO region
1057 * @config: Configuration for register map
1059 * The return value will be an ERR_PTR() on error or a valid pointer
1060 * to a struct regmap. The regmap will be automatically freed by the
1061 * device management code.
1063 #define devm_regmap_init_mmio(dev, regs, config) \
1064 devm_regmap_init_mmio_clk(dev, NULL, regs, config)
1067 * devm_regmap_init_ac97() - Initialise AC'97 register map
1069 * @ac97: Device that will be interacted with
1070 * @config: Configuration for register map
1072 * The return value will be an ERR_PTR() on error or a valid pointer
1073 * to a struct regmap. The regmap will be automatically freed by the
1074 * device management code.
1076 #define devm_regmap_init_ac97(ac97, config) \
1077 __regmap_lockdep_wrapper(__devm_regmap_init_ac97, #config, \
1081 * devm_regmap_init_sdw() - Initialise managed register map
1083 * @sdw: Device that will be interacted with
1084 * @config: Configuration for register map
1086 * The return value will be an ERR_PTR() on error or a valid pointer
1087 * to a struct regmap. The regmap will be automatically freed by the
1088 * device management code.
1090 #define devm_regmap_init_sdw(sdw, config) \
1091 __regmap_lockdep_wrapper(__devm_regmap_init_sdw, #config, \
1095 * devm_regmap_init_sdw_mbq() - Initialise managed register map
1097 * @sdw: Device that will be interacted with
1098 * @config: Configuration for register map
1100 * The return value will be an ERR_PTR() on error or a valid pointer
1101 * to a struct regmap. The regmap will be automatically freed by the
1102 * device management code.
1104 #define devm_regmap_init_sdw_mbq(sdw, config) \
1105 __regmap_lockdep_wrapper(__devm_regmap_init_sdw_mbq, #config, \
1109 * devm_regmap_init_slimbus() - Initialise managed register map
1111 * @slimbus: Device that will be interacted with
1112 * @config: Configuration for register map
1114 * The return value will be an ERR_PTR() on error or a valid pointer
1115 * to a struct regmap. The regmap will be automatically freed by the
1116 * device management code.
1118 #define devm_regmap_init_slimbus(slimbus, config) \
1119 __regmap_lockdep_wrapper(__devm_regmap_init_slimbus, #config, \
1123 * devm_regmap_init_i3c() - Initialise managed register map
1125 * @i3c: Device that will be interacted with
1126 * @config: Configuration for register map
1128 * The return value will be an ERR_PTR() on error or a valid pointer
1129 * to a struct regmap. The regmap will be automatically freed by the
1130 * device management code.
1132 #define devm_regmap_init_i3c(i3c, config) \
1133 __regmap_lockdep_wrapper(__devm_regmap_init_i3c, #config, \
1137 * devm_regmap_init_spi_avmm() - Initialize register map for Intel SPI Slave
1138 * to AVMM Bus Bridge
1140 * @spi: Device that will be interacted with
1141 * @config: Configuration for register map
1143 * The return value will be an ERR_PTR() on error or a valid pointer
1144 * to a struct regmap. The map will be automatically freed by the
1145 * device management code.
1147 #define devm_regmap_init_spi_avmm(spi, config) \
1148 __regmap_lockdep_wrapper(__devm_regmap_init_spi_avmm, #config, \
1151 int regmap_mmio_attach_clk(struct regmap *map, struct clk *clk);
1152 void regmap_mmio_detach_clk(struct regmap *map);
1153 void regmap_exit(struct regmap *map);
1154 int regmap_reinit_cache(struct regmap *map,
1155 const struct regmap_config *config);
1156 struct regmap *dev_get_regmap(struct device *dev, const char *name);
1157 struct device *regmap_get_device(struct regmap *map);
1158 int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
1159 int regmap_write_async(struct regmap *map, unsigned int reg, unsigned int val);
1160 int regmap_raw_write(struct regmap *map, unsigned int reg,
1161 const void *val, size_t val_len);
1162 int regmap_noinc_write(struct regmap *map, unsigned int reg,
1163 const void *val, size_t val_len);
1164 int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
1166 int regmap_multi_reg_write(struct regmap *map, const struct reg_sequence *regs,
1168 int regmap_multi_reg_write_bypassed(struct regmap *map,
1169 const struct reg_sequence *regs,
1171 int regmap_raw_write_async(struct regmap *map, unsigned int reg,
1172 const void *val, size_t val_len);
1173 int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
1174 int regmap_raw_read(struct regmap *map, unsigned int reg,
1175 void *val, size_t val_len);
1176 int regmap_noinc_read(struct regmap *map, unsigned int reg,
1177 void *val, size_t val_len);
1178 int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
1180 int regmap_update_bits_base(struct regmap *map, unsigned int reg,
1181 unsigned int mask, unsigned int val,
1182 bool *change, bool async, bool force);
1184 static inline int regmap_update_bits(struct regmap *map, unsigned int reg,
1185 unsigned int mask, unsigned int val)
1187 return regmap_update_bits_base(map, reg, mask, val, NULL, false, false);
1190 static inline int regmap_update_bits_async(struct regmap *map, unsigned int reg,
1191 unsigned int mask, unsigned int val)
1193 return regmap_update_bits_base(map, reg, mask, val, NULL, true, false);
1196 static inline int regmap_update_bits_check(struct regmap *map, unsigned int reg,
1197 unsigned int mask, unsigned int val,
1200 return regmap_update_bits_base(map, reg, mask, val,
1201 change, false, false);
1205 regmap_update_bits_check_async(struct regmap *map, unsigned int reg,
1206 unsigned int mask, unsigned int val,
1209 return regmap_update_bits_base(map, reg, mask, val,
1210 change, true, false);
1213 static inline int regmap_write_bits(struct regmap *map, unsigned int reg,
1214 unsigned int mask, unsigned int val)
1216 return regmap_update_bits_base(map, reg, mask, val, NULL, false, true);
1219 int regmap_get_val_bytes(struct regmap *map);
1220 int regmap_get_max_register(struct regmap *map);
1221 int regmap_get_reg_stride(struct regmap *map);
1222 int regmap_async_complete(struct regmap *map);
1223 bool regmap_can_raw_write(struct regmap *map);
1224 size_t regmap_get_raw_read_max(struct regmap *map);
1225 size_t regmap_get_raw_write_max(struct regmap *map);
1227 int regcache_sync(struct regmap *map);
1228 int regcache_sync_region(struct regmap *map, unsigned int min,
1230 int regcache_drop_region(struct regmap *map, unsigned int min,
1232 void regcache_cache_only(struct regmap *map, bool enable);
1233 void regcache_cache_bypass(struct regmap *map, bool enable);
1234 void regcache_mark_dirty(struct regmap *map);
1236 bool regmap_check_range_table(struct regmap *map, unsigned int reg,
1237 const struct regmap_access_table *table);
1239 int regmap_register_patch(struct regmap *map, const struct reg_sequence *regs,
1241 int regmap_parse_val(struct regmap *map, const void *buf,
1244 static inline bool regmap_reg_in_range(unsigned int reg,
1245 const struct regmap_range *range)
1247 return reg >= range->range_min && reg <= range->range_max;
1250 bool regmap_reg_in_ranges(unsigned int reg,
1251 const struct regmap_range *ranges,
1252 unsigned int nranges);
1254 static inline int regmap_set_bits(struct regmap *map,
1255 unsigned int reg, unsigned int bits)
1257 return regmap_update_bits_base(map, reg, bits, bits,
1258 NULL, false, false);
1261 static inline int regmap_clear_bits(struct regmap *map,
1262 unsigned int reg, unsigned int bits)
1264 return regmap_update_bits_base(map, reg, bits, 0, NULL, false, false);
1267 int regmap_test_bits(struct regmap *map, unsigned int reg, unsigned int bits);
1270 * struct reg_field - Description of an register field
1272 * @reg: Offset of the register within the regmap bank
1273 * @lsb: lsb of the register field.
1274 * @msb: msb of the register field.
1275 * @id_size: port size if it has some ports
1276 * @id_offset: address offset for each ports
1282 unsigned int id_size;
1283 unsigned int id_offset;
1286 #define REG_FIELD(_reg, _lsb, _msb) { \
1292 #define REG_FIELD_ID(_reg, _lsb, _msb, _size, _offset) { \
1297 .id_offset = _offset, \
1300 struct regmap_field *regmap_field_alloc(struct regmap *regmap,
1301 struct reg_field reg_field);
1302 void regmap_field_free(struct regmap_field *field);
1304 struct regmap_field *devm_regmap_field_alloc(struct device *dev,
1305 struct regmap *regmap, struct reg_field reg_field);
1306 void devm_regmap_field_free(struct device *dev, struct regmap_field *field);
1308 int regmap_field_bulk_alloc(struct regmap *regmap,
1309 struct regmap_field **rm_field,
1310 const struct reg_field *reg_field,
1312 void regmap_field_bulk_free(struct regmap_field *field);
1313 int devm_regmap_field_bulk_alloc(struct device *dev, struct regmap *regmap,
1314 struct regmap_field **field,
1315 const struct reg_field *reg_field,
1317 void devm_regmap_field_bulk_free(struct device *dev,
1318 struct regmap_field *field);
1320 int regmap_field_read(struct regmap_field *field, unsigned int *val);
1321 int regmap_field_update_bits_base(struct regmap_field *field,
1322 unsigned int mask, unsigned int val,
1323 bool *change, bool async, bool force);
1324 int regmap_fields_read(struct regmap_field *field, unsigned int id,
1326 int regmap_fields_update_bits_base(struct regmap_field *field, unsigned int id,
1327 unsigned int mask, unsigned int val,
1328 bool *change, bool async, bool force);
1330 static inline int regmap_field_write(struct regmap_field *field,
1333 return regmap_field_update_bits_base(field, ~0, val,
1334 NULL, false, false);
1337 static inline int regmap_field_force_write(struct regmap_field *field,
1340 return regmap_field_update_bits_base(field, ~0, val, NULL, false, true);
1343 static inline int regmap_field_update_bits(struct regmap_field *field,
1344 unsigned int mask, unsigned int val)
1346 return regmap_field_update_bits_base(field, mask, val,
1347 NULL, false, false);
1350 static inline int regmap_field_set_bits(struct regmap_field *field,
1353 return regmap_field_update_bits_base(field, bits, bits, NULL, false,
1357 static inline int regmap_field_clear_bits(struct regmap_field *field,
1360 return regmap_field_update_bits_base(field, bits, 0, NULL, false,
1364 int regmap_field_test_bits(struct regmap_field *field, unsigned int bits);
1367 regmap_field_force_update_bits(struct regmap_field *field,
1368 unsigned int mask, unsigned int val)
1370 return regmap_field_update_bits_base(field, mask, val,
1374 static inline int regmap_fields_write(struct regmap_field *field,
1375 unsigned int id, unsigned int val)
1377 return regmap_fields_update_bits_base(field, id, ~0, val,
1378 NULL, false, false);
1381 static inline int regmap_fields_force_write(struct regmap_field *field,
1382 unsigned int id, unsigned int val)
1384 return regmap_fields_update_bits_base(field, id, ~0, val,
1389 regmap_fields_update_bits(struct regmap_field *field, unsigned int id,
1390 unsigned int mask, unsigned int val)
1392 return regmap_fields_update_bits_base(field, id, mask, val,
1393 NULL, false, false);
1397 regmap_fields_force_update_bits(struct regmap_field *field, unsigned int id,
1398 unsigned int mask, unsigned int val)
1400 return regmap_fields_update_bits_base(field, id, mask, val,
1405 * struct regmap_irq_type - IRQ type definitions.
1407 * @type_reg_offset: Offset register for the irq type setting.
1408 * @type_rising_val: Register value to configure RISING type irq.
1409 * @type_falling_val: Register value to configure FALLING type irq.
1410 * @type_level_low_val: Register value to configure LEVEL_LOW type irq.
1411 * @type_level_high_val: Register value to configure LEVEL_HIGH type irq.
1412 * @types_supported: logical OR of IRQ_TYPE_* flags indicating supported types.
1414 struct regmap_irq_type {
1415 unsigned int type_reg_offset;
1416 unsigned int type_reg_mask;
1417 unsigned int type_rising_val;
1418 unsigned int type_falling_val;
1419 unsigned int type_level_low_val;
1420 unsigned int type_level_high_val;
1421 unsigned int types_supported;
1425 * struct regmap_irq - Description of an IRQ for the generic regmap irq_chip.
1427 * @reg_offset: Offset of the status/mask register within the bank
1428 * @mask: Mask used to flag/control the register.
1429 * @type: IRQ trigger type setting details if supported.
1432 unsigned int reg_offset;
1434 struct regmap_irq_type type;
1437 #define REGMAP_IRQ_REG(_irq, _off, _mask) \
1438 [_irq] = { .reg_offset = (_off), .mask = (_mask) }
1440 #define REGMAP_IRQ_REG_LINE(_id, _reg_bits) \
1442 .mask = BIT((_id) % (_reg_bits)), \
1443 .reg_offset = (_id) / (_reg_bits), \
1446 #define REGMAP_IRQ_MAIN_REG_OFFSET(arr) \
1447 { .num_regs = ARRAY_SIZE((arr)), .offset = &(arr)[0] }
1449 struct regmap_irq_sub_irq_map {
1450 unsigned int num_regs;
1451 unsigned int *offset;
1454 struct regmap_irq_chip_data;
1457 * struct regmap_irq_chip - Description of a generic regmap irq_chip.
1459 * @name: Descriptive name for IRQ controller.
1461 * @main_status: Base main status register address. For chips which have
1462 * interrupts arranged in separate sub-irq blocks with own IRQ
1463 * registers and which have a main IRQ registers indicating
1464 * sub-irq blocks with unhandled interrupts. For such chips fill
1465 * sub-irq register information in status_base, mask_base and
1467 * @num_main_status_bits: Should be given to chips where number of meaningfull
1468 * main status bits differs from num_regs.
1469 * @sub_reg_offsets: arrays of mappings from main register bits to sub irq
1470 * registers. First item in array describes the registers
1471 * for first main status bit. Second array for second bit etc.
1472 * Offset is given as sub register status offset to
1473 * status_base. Should contain num_regs arrays.
1474 * Can be provided for chips with more complex mapping than
1475 * 1.st bit to 1.st sub-reg, 2.nd bit to 2.nd sub-reg, ...
1476 * When used with not_fixed_stride, each one-element array
1477 * member contains offset calculated as address from each
1478 * peripheral to first peripheral.
1479 * @num_main_regs: Number of 'main status' irq registers for chips which have
1482 * @status_base: Base status register address.
1483 * @mask_base: Base mask register address. Mask bits are set to 1 when an
1484 * interrupt is masked, 0 when unmasked.
1485 * @unmask_base: Base unmask register address. Unmask bits are set to 1 when
1486 * an interrupt is unmasked and 0 when masked.
1487 * @ack_base: Base ack address. If zero then the chip is clear on read.
1488 * Using zero value is possible with @use_ack bit.
1489 * @wake_base: Base address for wake enables. If zero unsupported.
1490 * @type_base: Base address for irq type. If zero unsupported. Deprecated,
1491 * use @config_base instead.
1492 * @virt_reg_base: Base addresses for extra config regs. Deprecated, use
1493 * @config_base instead.
1494 * @config_base: Base address for IRQ type config regs. If null unsupported.
1495 * @irq_reg_stride: Stride to use for chips where registers are not contiguous.
1496 * @init_ack_masked: Ack all masked interrupts once during initalization.
1497 * @mask_invert: Inverted mask register: cleared bits are masked out.
1498 * Deprecated; prefer describing an inverted mask register as
1499 * an unmask register.
1500 * @mask_unmask_non_inverted: Controls mask bit inversion for chips that set
1501 * both @mask_base and @unmask_base. If false, mask and unmask bits are
1502 * inverted (which is deprecated behavior); if true, bits will not be
1503 * inverted and the registers keep their normal behavior. Note that if
1504 * you use only one of @mask_base or @unmask_base, this flag has no
1505 * effect and is unnecessary. Any new drivers that set both @mask_base
1506 * and @unmask_base should set this to true to avoid relying on the
1507 * deprecated behavior.
1508 * @use_ack: Use @ack register even if it is zero.
1509 * @ack_invert: Inverted ack register: cleared bits for ack.
1510 * @clear_ack: Use this to set 1 and 0 or vice-versa to clear interrupts.
1511 * @wake_invert: Inverted wake register: cleared bits are wake enabled.
1512 * @type_invert: Invert the type flags. Deprecated, use config registers
1514 * @type_in_mask: Use the mask registers for controlling irq type. Use this if
1515 * the hardware provides separate bits for rising/falling edge
1516 * or low/high level interrupts and they should be combined into
1517 * a single logical interrupt. Use &struct regmap_irq_type data
1518 * to define the mask bit for each irq type.
1519 * @clear_on_unmask: For chips with interrupts cleared on read: read the status
1520 * registers before unmasking interrupts to clear any bits
1521 * set when they were masked.
1522 * @not_fixed_stride: Used when chip peripherals are not laid out with fixed
1523 * stride. Must be used with sub_reg_offsets containing the
1524 * offsets to each peripheral. Deprecated; the same thing
1525 * can be accomplished with a @get_irq_reg callback, without
1526 * the need for a @sub_reg_offsets table.
1527 * @status_invert: Inverted status register: cleared bits are active interrupts.
1528 * @runtime_pm: Hold a runtime PM lock on the device when accessing it.
1530 * @num_regs: Number of registers in each control bank.
1531 * @irqs: Descriptors for individual IRQs. Interrupt numbers are
1532 * assigned based on the index in the array of the interrupt.
1533 * @num_irqs: Number of descriptors.
1534 * @num_type_reg: Number of type registers. Deprecated, use config registers
1536 * @num_virt_regs: Number of non-standard irq configuration registers.
1537 * If zero unsupported. Deprecated, use config registers
1539 * @num_config_bases: Number of config base registers.
1540 * @num_config_regs: Number of config registers for each config base register.
1541 * @handle_pre_irq: Driver specific callback to handle interrupt from device
1542 * before regmap_irq_handler process the interrupts.
1543 * @handle_post_irq: Driver specific callback to handle interrupt from device
1544 * after handling the interrupts in regmap_irq_handler().
1545 * @set_type_virt: Driver specific callback to extend regmap_irq_set_type()
1546 * and configure virt regs. Deprecated, use @set_type_config
1547 * callback and config registers instead.
1548 * @set_type_config: Callback used for configuring irq types.
1549 * @get_irq_reg: Callback for mapping (base register, index) pairs to register
1550 * addresses. The base register will be one of @status_base,
1551 * @mask_base, etc., @main_status, or any of @config_base.
1552 * The index will be in the range [0, num_main_regs[ for the
1553 * main status base, [0, num_type_settings[ for any config
1554 * register base, and [0, num_regs[ for any other base.
1555 * If unspecified then regmap_irq_get_irq_reg_linear() is used.
1556 * @irq_drv_data: Driver specific IRQ data which is passed as parameter when
1557 * driver specific pre/post interrupt handler is called.
1559 * This is not intended to handle every possible interrupt controller, but
1560 * it should handle a substantial proportion of those that are found in the
1563 struct regmap_irq_chip {
1566 unsigned int main_status;
1567 unsigned int num_main_status_bits;
1568 struct regmap_irq_sub_irq_map *sub_reg_offsets;
1571 unsigned int status_base;
1572 unsigned int mask_base;
1573 unsigned int unmask_base;
1574 unsigned int ack_base;
1575 unsigned int wake_base;
1576 unsigned int type_base;
1577 unsigned int *virt_reg_base;
1578 const unsigned int *config_base;
1579 unsigned int irq_reg_stride;
1580 unsigned int init_ack_masked:1;
1581 unsigned int mask_invert:1;
1582 unsigned int mask_unmask_non_inverted:1;
1583 unsigned int use_ack:1;
1584 unsigned int ack_invert:1;
1585 unsigned int clear_ack:1;
1586 unsigned int wake_invert:1;
1587 unsigned int runtime_pm:1;
1588 unsigned int type_invert:1;
1589 unsigned int type_in_mask:1;
1590 unsigned int clear_on_unmask:1;
1591 unsigned int not_fixed_stride:1;
1592 unsigned int status_invert:1;
1596 const struct regmap_irq *irqs;
1601 int num_config_bases;
1602 int num_config_regs;
1604 int (*handle_pre_irq)(void *irq_drv_data);
1605 int (*handle_post_irq)(void *irq_drv_data);
1606 int (*set_type_virt)(unsigned int **buf, unsigned int type,
1607 unsigned long hwirq, int reg);
1608 int (*set_type_config)(unsigned int **buf, unsigned int type,
1609 const struct regmap_irq *irq_data, int idx);
1610 unsigned int (*get_irq_reg)(struct regmap_irq_chip_data *data,
1611 unsigned int base, int index);
1615 unsigned int regmap_irq_get_irq_reg_linear(struct regmap_irq_chip_data *data,
1616 unsigned int base, int index);
1617 int regmap_irq_set_type_config_simple(unsigned int **buf, unsigned int type,
1618 const struct regmap_irq *irq_data, int idx);
1620 int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
1621 int irq_base, const struct regmap_irq_chip *chip,
1622 struct regmap_irq_chip_data **data);
1623 int regmap_add_irq_chip_fwnode(struct fwnode_handle *fwnode,
1624 struct regmap *map, int irq,
1625 int irq_flags, int irq_base,
1626 const struct regmap_irq_chip *chip,
1627 struct regmap_irq_chip_data **data);
1628 void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data);
1630 int devm_regmap_add_irq_chip(struct device *dev, struct regmap *map, int irq,
1631 int irq_flags, int irq_base,
1632 const struct regmap_irq_chip *chip,
1633 struct regmap_irq_chip_data **data);
1634 int devm_regmap_add_irq_chip_fwnode(struct device *dev,
1635 struct fwnode_handle *fwnode,
1636 struct regmap *map, int irq,
1637 int irq_flags, int irq_base,
1638 const struct regmap_irq_chip *chip,
1639 struct regmap_irq_chip_data **data);
1640 void devm_regmap_del_irq_chip(struct device *dev, int irq,
1641 struct regmap_irq_chip_data *data);
1643 int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data);
1644 int regmap_irq_get_virq(struct regmap_irq_chip_data *data, int irq);
1645 struct irq_domain *regmap_irq_get_domain(struct regmap_irq_chip_data *data);
1650 * These stubs should only ever be called by generic code which has
1651 * regmap based facilities, if they ever get called at runtime
1652 * something is going wrong and something probably needs to select
1656 static inline int regmap_write(struct regmap *map, unsigned int reg,
1659 WARN_ONCE(1, "regmap API is disabled");
1663 static inline int regmap_write_async(struct regmap *map, unsigned int reg,
1666 WARN_ONCE(1, "regmap API is disabled");
1670 static inline int regmap_raw_write(struct regmap *map, unsigned int reg,
1671 const void *val, size_t val_len)
1673 WARN_ONCE(1, "regmap API is disabled");
1677 static inline int regmap_raw_write_async(struct regmap *map, unsigned int reg,
1678 const void *val, size_t val_len)
1680 WARN_ONCE(1, "regmap API is disabled");
1684 static inline int regmap_noinc_write(struct regmap *map, unsigned int reg,
1685 const void *val, size_t val_len)
1687 WARN_ONCE(1, "regmap API is disabled");
1691 static inline int regmap_bulk_write(struct regmap *map, unsigned int reg,
1692 const void *val, size_t val_count)
1694 WARN_ONCE(1, "regmap API is disabled");
1698 static inline int regmap_read(struct regmap *map, unsigned int reg,
1701 WARN_ONCE(1, "regmap API is disabled");
1705 static inline int regmap_raw_read(struct regmap *map, unsigned int reg,
1706 void *val, size_t val_len)
1708 WARN_ONCE(1, "regmap API is disabled");
1712 static inline int regmap_noinc_read(struct regmap *map, unsigned int reg,
1713 void *val, size_t val_len)
1715 WARN_ONCE(1, "regmap API is disabled");
1719 static inline int regmap_bulk_read(struct regmap *map, unsigned int reg,
1720 void *val, size_t val_count)
1722 WARN_ONCE(1, "regmap API is disabled");
1726 static inline int regmap_update_bits_base(struct regmap *map, unsigned int reg,
1727 unsigned int mask, unsigned int val,
1728 bool *change, bool async, bool force)
1730 WARN_ONCE(1, "regmap API is disabled");
1734 static inline int regmap_set_bits(struct regmap *map,
1735 unsigned int reg, unsigned int bits)
1737 WARN_ONCE(1, "regmap API is disabled");
1741 static inline int regmap_clear_bits(struct regmap *map,
1742 unsigned int reg, unsigned int bits)
1744 WARN_ONCE(1, "regmap API is disabled");
1748 static inline int regmap_test_bits(struct regmap *map,
1749 unsigned int reg, unsigned int bits)
1751 WARN_ONCE(1, "regmap API is disabled");
1755 static inline int regmap_field_update_bits_base(struct regmap_field *field,
1756 unsigned int mask, unsigned int val,
1757 bool *change, bool async, bool force)
1759 WARN_ONCE(1, "regmap API is disabled");
1763 static inline int regmap_fields_update_bits_base(struct regmap_field *field,
1765 unsigned int mask, unsigned int val,
1766 bool *change, bool async, bool force)
1768 WARN_ONCE(1, "regmap API is disabled");
1772 static inline int regmap_update_bits(struct regmap *map, unsigned int reg,
1773 unsigned int mask, unsigned int val)
1775 WARN_ONCE(1, "regmap API is disabled");
1779 static inline int regmap_update_bits_async(struct regmap *map, unsigned int reg,
1780 unsigned int mask, unsigned int val)
1782 WARN_ONCE(1, "regmap API is disabled");
1786 static inline int regmap_update_bits_check(struct regmap *map, unsigned int reg,
1787 unsigned int mask, unsigned int val,
1790 WARN_ONCE(1, "regmap API is disabled");
1795 regmap_update_bits_check_async(struct regmap *map, unsigned int reg,
1796 unsigned int mask, unsigned int val,
1799 WARN_ONCE(1, "regmap API is disabled");
1803 static inline int regmap_write_bits(struct regmap *map, unsigned int reg,
1804 unsigned int mask, unsigned int val)
1806 WARN_ONCE(1, "regmap API is disabled");
1810 static inline int regmap_field_write(struct regmap_field *field,
1813 WARN_ONCE(1, "regmap API is disabled");
1817 static inline int regmap_field_force_write(struct regmap_field *field,
1820 WARN_ONCE(1, "regmap API is disabled");
1824 static inline int regmap_field_update_bits(struct regmap_field *field,
1825 unsigned int mask, unsigned int val)
1827 WARN_ONCE(1, "regmap API is disabled");
1832 regmap_field_force_update_bits(struct regmap_field *field,
1833 unsigned int mask, unsigned int val)
1835 WARN_ONCE(1, "regmap API is disabled");
1839 static inline int regmap_field_set_bits(struct regmap_field *field,
1842 WARN_ONCE(1, "regmap API is disabled");
1846 static inline int regmap_field_clear_bits(struct regmap_field *field,
1849 WARN_ONCE(1, "regmap API is disabled");
1853 static inline int regmap_field_test_bits(struct regmap_field *field,
1856 WARN_ONCE(1, "regmap API is disabled");
1860 static inline int regmap_fields_write(struct regmap_field *field,
1861 unsigned int id, unsigned int val)
1863 WARN_ONCE(1, "regmap API is disabled");
1867 static inline int regmap_fields_force_write(struct regmap_field *field,
1868 unsigned int id, unsigned int val)
1870 WARN_ONCE(1, "regmap API is disabled");
1875 regmap_fields_update_bits(struct regmap_field *field, unsigned int id,
1876 unsigned int mask, unsigned int val)
1878 WARN_ONCE(1, "regmap API is disabled");
1883 regmap_fields_force_update_bits(struct regmap_field *field, unsigned int id,
1884 unsigned int mask, unsigned int val)
1886 WARN_ONCE(1, "regmap API is disabled");
1890 static inline int regmap_get_val_bytes(struct regmap *map)
1892 WARN_ONCE(1, "regmap API is disabled");
1896 static inline int regmap_get_max_register(struct regmap *map)
1898 WARN_ONCE(1, "regmap API is disabled");
1902 static inline int regmap_get_reg_stride(struct regmap *map)
1904 WARN_ONCE(1, "regmap API is disabled");
1908 static inline int regcache_sync(struct regmap *map)
1910 WARN_ONCE(1, "regmap API is disabled");
1914 static inline int regcache_sync_region(struct regmap *map, unsigned int min,
1917 WARN_ONCE(1, "regmap API is disabled");
1921 static inline int regcache_drop_region(struct regmap *map, unsigned int min,
1924 WARN_ONCE(1, "regmap API is disabled");
1928 static inline void regcache_cache_only(struct regmap *map, bool enable)
1930 WARN_ONCE(1, "regmap API is disabled");
1933 static inline void regcache_cache_bypass(struct regmap *map, bool enable)
1935 WARN_ONCE(1, "regmap API is disabled");
1938 static inline void regcache_mark_dirty(struct regmap *map)
1940 WARN_ONCE(1, "regmap API is disabled");
1943 static inline void regmap_async_complete(struct regmap *map)
1945 WARN_ONCE(1, "regmap API is disabled");
1948 static inline int regmap_register_patch(struct regmap *map,
1949 const struct reg_sequence *regs,
1952 WARN_ONCE(1, "regmap API is disabled");
1956 static inline int regmap_parse_val(struct regmap *map, const void *buf,
1959 WARN_ONCE(1, "regmap API is disabled");
1963 static inline struct regmap *dev_get_regmap(struct device *dev,
1969 static inline struct device *regmap_get_device(struct regmap *map)
1971 WARN_ONCE(1, "regmap API is disabled");