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>
36 struct regmap_range_cfg;
42 * regmap_mdio address encoding. IEEE 802.3ae clause 45 addresses consist of a
43 * device address and a register address.
45 #define REGMAP_MDIO_C45_DEVAD_SHIFT 16
46 #define REGMAP_MDIO_C45_DEVAD_MASK GENMASK(20, 16)
47 #define REGMAP_MDIO_C45_REGNUM_MASK GENMASK(15, 0)
49 /* An enum of all the supported cache types */
58 * struct reg_default - Default value for a register.
60 * @reg: Register address.
61 * @def: Register default value.
63 * We use an array of structs rather than a simple array as many modern devices
64 * have very sparse register maps.
72 * struct reg_sequence - An individual write from a sequence of writes.
74 * @reg: Register address.
75 * @def: Register value.
76 * @delay_us: Delay to be applied after the register write in microseconds
78 * Register/value pairs for sequences of writes with an optional delay in
79 * microseconds to be applied after each write.
84 unsigned int delay_us;
87 #define REG_SEQ(_reg, _def, _delay_us) { \
90 .delay_us = _delay_us, \
92 #define REG_SEQ0(_reg, _def) REG_SEQ(_reg, _def, 0)
95 * regmap_read_poll_timeout - Poll until a condition is met or a timeout occurs
97 * @map: Regmap to read from
98 * @addr: Address to poll
99 * @val: Unsigned integer variable to read the value into
100 * @cond: Break condition (usually involving @val)
101 * @sleep_us: Maximum time to sleep between reads in us (0
102 * tight-loops). Should be less than ~20ms since usleep_range
103 * is used (see Documentation/timers/timers-howto.rst).
104 * @timeout_us: Timeout in us, 0 means never timeout
106 * Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_read
107 * error return value in case of a error read. In the two former cases,
108 * the last read value at @addr is stored in @val. Must not be called
109 * from atomic context if sleep_us or timeout_us are used.
111 * This is modelled after the readx_poll_timeout macros in linux/iopoll.h.
113 #define regmap_read_poll_timeout(map, addr, val, cond, sleep_us, timeout_us) \
116 __tmp = read_poll_timeout(regmap_read, __ret, __ret || (cond), \
117 sleep_us, timeout_us, false, (map), (addr), &(val)); \
122 * regmap_read_poll_timeout_atomic - Poll until a condition is met or a timeout occurs
124 * @map: Regmap to read from
125 * @addr: Address to poll
126 * @val: Unsigned integer variable to read the value into
127 * @cond: Break condition (usually involving @val)
128 * @delay_us: Time to udelay between reads in us (0 tight-loops).
129 * Should be less than ~10us since udelay is used
130 * (see Documentation/timers/timers-howto.rst).
131 * @timeout_us: Timeout in us, 0 means never timeout
133 * Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_read
134 * error return value in case of a error read. In the two former cases,
135 * the last read value at @addr is stored in @val.
137 * This is modelled after the readx_poll_timeout_atomic macros in linux/iopoll.h.
139 * Note: In general regmap cannot be used in atomic context. If you want to use
140 * this macro then first setup your regmap for atomic use (flat or no cache
143 #define regmap_read_poll_timeout_atomic(map, addr, val, cond, delay_us, timeout_us) \
145 u64 __timeout_us = (timeout_us); \
146 unsigned long __delay_us = (delay_us); \
147 ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \
150 __ret = regmap_read((map), (addr), &(val)); \
155 if ((__timeout_us) && \
156 ktime_compare(ktime_get(), __timeout) > 0) { \
157 __ret = regmap_read((map), (addr), &(val)); \
161 udelay(__delay_us); \
163 __ret ?: ((cond) ? 0 : -ETIMEDOUT); \
167 * regmap_field_read_poll_timeout - Poll until a condition is met or timeout
169 * @field: Regmap field to read from
170 * @val: Unsigned integer variable to read the value into
171 * @cond: Break condition (usually involving @val)
172 * @sleep_us: Maximum time to sleep between reads in us (0
173 * tight-loops). Should be less than ~20ms since usleep_range
174 * is used (see Documentation/timers/timers-howto.rst).
175 * @timeout_us: Timeout in us, 0 means never timeout
177 * Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_field_read
178 * error return value in case of a error read. In the two former cases,
179 * the last read value at @addr is stored in @val. Must not be called
180 * from atomic context if sleep_us or timeout_us are used.
182 * This is modelled after the readx_poll_timeout macros in linux/iopoll.h.
184 #define regmap_field_read_poll_timeout(field, val, cond, sleep_us, timeout_us) \
187 __tmp = read_poll_timeout(regmap_field_read, __ret, __ret || (cond), \
188 sleep_us, timeout_us, false, (field), &(val)); \
195 /* Unspecified -> 0 -> Backwards compatible default */
196 REGMAP_ENDIAN_DEFAULT = 0,
198 REGMAP_ENDIAN_LITTLE,
199 REGMAP_ENDIAN_NATIVE,
203 * struct regmap_range - A register range, used for access related checks
204 * (readable/writeable/volatile/precious checks)
206 * @range_min: address of first register
207 * @range_max: address of last register
209 struct regmap_range {
210 unsigned int range_min;
211 unsigned int range_max;
214 #define regmap_reg_range(low, high) { .range_min = low, .range_max = high, }
217 * struct regmap_access_table - A table of register ranges for access checks
219 * @yes_ranges : pointer to an array of regmap ranges used as "yes ranges"
220 * @n_yes_ranges: size of the above array
221 * @no_ranges: pointer to an array of regmap ranges used as "no ranges"
222 * @n_no_ranges: size of the above array
224 * A table of ranges including some yes ranges and some no ranges.
225 * If a register belongs to a no_range, the corresponding check function
226 * will return false. If a register belongs to a yes range, the corresponding
227 * check function will return true. "no_ranges" are searched first.
229 struct regmap_access_table {
230 const struct regmap_range *yes_ranges;
231 unsigned int n_yes_ranges;
232 const struct regmap_range *no_ranges;
233 unsigned int n_no_ranges;
236 typedef void (*regmap_lock)(void *);
237 typedef void (*regmap_unlock)(void *);
240 * struct regmap_config - Configuration for the register map of a device.
242 * @name: Optional name of the regmap. Useful when a device has multiple
245 * @reg_bits: Number of bits in a register address, mandatory.
246 * @reg_stride: The register address stride. Valid register addresses are a
247 * multiple of this value. If set to 0, a value of 1 will be
249 * @reg_downshift: The number of bits to downshift the register before
250 * performing any operations.
251 * @reg_base: Value to be added to every register address before performing any
253 * @pad_bits: Number of bits of padding between register and value.
254 * @val_bits: Number of bits in a register value, mandatory.
256 * @writeable_reg: Optional callback returning true if the register
257 * can be written to. If this field is NULL but wr_table
258 * (see below) is not, the check is performed on such table
259 * (a register is writeable if it belongs to one of the ranges
260 * specified by wr_table).
261 * @readable_reg: Optional callback returning true if the register
262 * can be read from. If this field is NULL but rd_table
263 * (see below) is not, the check is performed on such table
264 * (a register is readable if it belongs to one of the ranges
265 * specified by rd_table).
266 * @volatile_reg: Optional callback returning true if the register
267 * value can't be cached. If this field is NULL but
268 * volatile_table (see below) is not, the check is performed on
269 * such table (a register is volatile if it belongs to one of
270 * the ranges specified by volatile_table).
271 * @precious_reg: Optional callback returning true if the register
272 * should not be read outside of a call from the driver
273 * (e.g., a clear on read interrupt status register). If this
274 * field is NULL but precious_table (see below) is not, the
275 * check is performed on such table (a register is precious if
276 * it belongs to one of the ranges specified by precious_table).
277 * @writeable_noinc_reg: Optional callback returning true if the register
278 * supports multiple write operations without incrementing
279 * the register number. If this field is NULL but
280 * wr_noinc_table (see below) is not, the check is
281 * performed on such table (a register is no increment
282 * writeable if it belongs to one of the ranges specified
283 * by wr_noinc_table).
284 * @readable_noinc_reg: Optional callback returning true if the register
285 * supports multiple read operations without incrementing
286 * the register number. If this field is NULL but
287 * rd_noinc_table (see below) is not, the check is
288 * performed on such table (a register is no increment
289 * readable if it belongs to one of the ranges specified
290 * by rd_noinc_table).
291 * @disable_locking: This regmap is either protected by external means or
292 * is guaranteed not to be accessed from multiple threads.
293 * Don't use any locking mechanisms.
294 * @lock: Optional lock callback (overrides regmap's default lock
295 * function, based on spinlock or mutex).
296 * @unlock: As above for unlocking.
297 * @lock_arg: this field is passed as the only argument of lock/unlock
298 * functions (ignored in case regular lock/unlock functions
299 * are not overridden).
300 * @reg_read: Optional callback that if filled will be used to perform
301 * all the reads from the registers. Should only be provided for
302 * devices whose read operation cannot be represented as a simple
303 * read operation on a bus such as SPI, I2C, etc. Most of the
304 * devices do not need this.
305 * @reg_write: Same as above for writing.
306 * @reg_update_bits: Optional callback that if filled will be used to perform
307 * all the update_bits(rmw) operation. Should only be provided
308 * if the function require special handling with lock and reg
309 * handling and the operation cannot be represented as a simple
310 * update_bits operation on a bus such as SPI, I2C, etc.
311 * @read: Optional callback that if filled will be used to perform all the
312 * bulk reads from the registers. Data is returned in the buffer used
314 * @write: Same as above for writing.
315 * @max_raw_read: Max raw read size that can be used on the device.
316 * @max_raw_write: Max raw write size that can be used on the device.
317 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
318 * to perform locking. This field is ignored if custom lock/unlock
319 * functions are used (see fields lock/unlock of struct regmap_config).
320 * This field is a duplicate of a similar file in
321 * 'struct regmap_bus' and serves exact same purpose.
322 * Use it only for "no-bus" cases.
323 * @io_port: Support IO port accessors. Makes sense only when MMIO vs. IO port
324 * access can be distinguished.
325 * @max_register: Optional, specifies the maximum valid register address.
326 * @wr_table: Optional, points to a struct regmap_access_table specifying
327 * valid ranges for write access.
328 * @rd_table: As above, for read access.
329 * @volatile_table: As above, for volatile registers.
330 * @precious_table: As above, for precious registers.
331 * @wr_noinc_table: As above, for no increment writeable registers.
332 * @rd_noinc_table: As above, for no increment readable registers.
333 * @reg_defaults: Power on reset values for registers (for use with
334 * register cache support).
335 * @num_reg_defaults: Number of elements in reg_defaults.
337 * @read_flag_mask: Mask to be set in the top bytes of the register when doing
339 * @write_flag_mask: Mask to be set in the top bytes of the register when doing
340 * a write. If both read_flag_mask and write_flag_mask are
341 * empty and zero_flag_mask is not set the regmap_bus default
343 * @zero_flag_mask: If set, read_flag_mask and write_flag_mask are used even
344 * if they are both empty.
345 * @use_relaxed_mmio: If set, MMIO R/W operations will not use memory barriers.
346 * This can avoid load on devices which don't require strict
347 * orderings, but drivers should carefully add any explicit
348 * memory barriers when they may require them.
349 * @use_single_read: If set, converts the bulk read operation into a series of
350 * single read operations. This is useful for a device that
351 * does not support bulk read.
352 * @use_single_write: If set, converts the bulk write operation into a series of
353 * single write operations. This is useful for a device that
354 * does not support bulk write.
355 * @can_multi_write: If set, the device supports the multi write mode of bulk
356 * write operations, if clear multi write requests will be
357 * split into individual write operations
359 * @cache_type: The actual cache type.
360 * @reg_defaults_raw: Power on reset values for registers (for use with
361 * register cache support).
362 * @num_reg_defaults_raw: Number of elements in reg_defaults_raw.
363 * @reg_format_endian: Endianness for formatted register addresses. If this is
364 * DEFAULT, the @reg_format_endian_default value from the
365 * regmap bus is used.
366 * @val_format_endian: Endianness for formatted register values. If this is
367 * DEFAULT, the @reg_format_endian_default value from the
368 * regmap bus is used.
370 * @ranges: Array of configuration entries for virtual address ranges.
371 * @num_ranges: Number of range configuration entries.
372 * @use_hwlock: Indicate if a hardware spinlock should be used.
373 * @use_raw_spinlock: Indicate if a raw spinlock should be used.
374 * @hwlock_id: Specify the hardware spinlock id.
375 * @hwlock_mode: The hardware spinlock mode, should be HWLOCK_IRQSTATE,
377 * @can_sleep: Optional, specifies whether regmap operations can sleep.
379 struct regmap_config {
385 unsigned int reg_base;
389 bool (*writeable_reg)(struct device *dev, unsigned int reg);
390 bool (*readable_reg)(struct device *dev, unsigned int reg);
391 bool (*volatile_reg)(struct device *dev, unsigned int reg);
392 bool (*precious_reg)(struct device *dev, unsigned int reg);
393 bool (*writeable_noinc_reg)(struct device *dev, unsigned int reg);
394 bool (*readable_noinc_reg)(struct device *dev, unsigned int reg);
396 bool disable_locking;
398 regmap_unlock unlock;
401 int (*reg_read)(void *context, unsigned int reg, unsigned int *val);
402 int (*reg_write)(void *context, unsigned int reg, unsigned int val);
403 int (*reg_update_bits)(void *context, unsigned int reg,
404 unsigned int mask, unsigned int val);
405 /* Bulk read/write */
406 int (*read)(void *context, const void *reg_buf, size_t reg_size,
407 void *val_buf, size_t val_size);
408 int (*write)(void *context, const void *data, size_t count);
410 size_t max_raw_write;
415 unsigned int max_register;
416 const struct regmap_access_table *wr_table;
417 const struct regmap_access_table *rd_table;
418 const struct regmap_access_table *volatile_table;
419 const struct regmap_access_table *precious_table;
420 const struct regmap_access_table *wr_noinc_table;
421 const struct regmap_access_table *rd_noinc_table;
422 const struct reg_default *reg_defaults;
423 unsigned int num_reg_defaults;
424 enum regcache_type cache_type;
425 const void *reg_defaults_raw;
426 unsigned int num_reg_defaults_raw;
428 unsigned long read_flag_mask;
429 unsigned long write_flag_mask;
432 bool use_single_read;
433 bool use_single_write;
434 bool use_relaxed_mmio;
435 bool can_multi_write;
437 enum regmap_endian reg_format_endian;
438 enum regmap_endian val_format_endian;
440 const struct regmap_range_cfg *ranges;
441 unsigned int num_ranges;
444 bool use_raw_spinlock;
445 unsigned int hwlock_id;
446 unsigned int hwlock_mode;
452 * struct regmap_range_cfg - Configuration for indirectly accessed or paged
455 * @name: Descriptive name for diagnostics
457 * @range_min: Address of the lowest register address in virtual range.
458 * @range_max: Address of the highest register in virtual range.
460 * @selector_reg: Register with selector field.
461 * @selector_mask: Bit mask for selector value.
462 * @selector_shift: Bit shift for selector value.
464 * @window_start: Address of first (lowest) register in data window.
465 * @window_len: Number of registers in data window.
467 * Registers, mapped to this virtual range, are accessed in two steps:
468 * 1. page selector register update;
469 * 2. access through data window registers.
471 struct regmap_range_cfg {
474 /* Registers of virtual address range */
475 unsigned int range_min;
476 unsigned int range_max;
478 /* Page selector for indirect addressing */
479 unsigned int selector_reg;
480 unsigned int selector_mask;
483 /* Data window (per each page) */
484 unsigned int window_start;
485 unsigned int window_len;
490 typedef int (*regmap_hw_write)(void *context, const void *data,
492 typedef int (*regmap_hw_gather_write)(void *context,
493 const void *reg, size_t reg_len,
494 const void *val, size_t val_len);
495 typedef int (*regmap_hw_async_write)(void *context,
496 const void *reg, size_t reg_len,
497 const void *val, size_t val_len,
498 struct regmap_async *async);
499 typedef int (*regmap_hw_read)(void *context,
500 const void *reg_buf, size_t reg_size,
501 void *val_buf, size_t val_size);
502 typedef int (*regmap_hw_reg_read)(void *context, unsigned int reg,
504 typedef int (*regmap_hw_reg_noinc_read)(void *context, unsigned int reg,
505 void *val, size_t val_count);
506 typedef int (*regmap_hw_reg_write)(void *context, unsigned int reg,
508 typedef int (*regmap_hw_reg_noinc_write)(void *context, unsigned int reg,
509 const void *val, size_t val_count);
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);
516 * struct regmap_bus - Description of a hardware bus for the register map
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 * @free_on_exit: kfree this on exit of regmap
524 * @write: Write operation.
525 * @gather_write: Write operation with split register/value, return -ENOTSUPP
526 * if not implemented on a given device.
527 * @async_write: Write operation which completes asynchronously, optional and
528 * must serialise with respect to non-async I/O.
529 * @reg_write: Write a single register value to the given register address. This
530 * write operation has to complete when returning from the function.
531 * @reg_write_noinc: Write multiple register value to the same register. This
532 * write operation has to complete when returning from the function.
533 * @reg_update_bits: Update bits operation to be used against volatile
534 * registers, intended for devices supporting some mechanism
535 * for setting clearing bits without having to
537 * @read: Read operation. Data is returned in the buffer used to transmit
539 * @reg_read: Read a single register value from a given register address.
540 * @free_context: Free context.
541 * @async_alloc: Allocate a regmap_async() structure.
542 * @read_flag_mask: Mask to be set in the top byte of the register when doing
544 * @reg_format_endian_default: Default endianness for formatted register
545 * addresses. Used when the regmap_config specifies DEFAULT. If this is
546 * DEFAULT, BIG is assumed.
547 * @val_format_endian_default: Default endianness for formatted register
548 * values. Used when the regmap_config specifies DEFAULT. If this is
549 * DEFAULT, BIG is assumed.
550 * @max_raw_read: Max raw read size that can be used on the bus.
551 * @max_raw_write: Max raw write size that can be used on the bus.
556 regmap_hw_write write;
557 regmap_hw_gather_write gather_write;
558 regmap_hw_async_write async_write;
559 regmap_hw_reg_write reg_write;
560 regmap_hw_reg_noinc_write reg_noinc_write;
561 regmap_hw_reg_update_bits reg_update_bits;
563 regmap_hw_reg_read reg_read;
564 regmap_hw_reg_noinc_read reg_noinc_read;
565 regmap_hw_free_context free_context;
566 regmap_hw_async_alloc async_alloc;
568 enum regmap_endian reg_format_endian_default;
569 enum regmap_endian val_format_endian_default;
571 size_t max_raw_write;
575 * __regmap_init functions.
577 * These functions take a lock key and name parameter, and should not be called
578 * directly. Instead, use the regmap_init macros that generate a key and name
581 struct regmap *__regmap_init(struct device *dev,
582 const struct regmap_bus *bus,
584 const struct regmap_config *config,
585 struct lock_class_key *lock_key,
586 const char *lock_name);
587 struct regmap *__regmap_init_i2c(struct i2c_client *i2c,
588 const struct regmap_config *config,
589 struct lock_class_key *lock_key,
590 const char *lock_name);
591 struct regmap *__regmap_init_mdio(struct mdio_device *mdio_dev,
592 const struct regmap_config *config,
593 struct lock_class_key *lock_key,
594 const char *lock_name);
595 struct regmap *__regmap_init_sccb(struct i2c_client *i2c,
596 const struct regmap_config *config,
597 struct lock_class_key *lock_key,
598 const char *lock_name);
599 struct regmap *__regmap_init_slimbus(struct slim_device *slimbus,
600 const struct regmap_config *config,
601 struct lock_class_key *lock_key,
602 const char *lock_name);
603 struct regmap *__regmap_init_spi(struct spi_device *dev,
604 const struct regmap_config *config,
605 struct lock_class_key *lock_key,
606 const char *lock_name);
607 struct regmap *__regmap_init_spmi_base(struct spmi_device *dev,
608 const struct regmap_config *config,
609 struct lock_class_key *lock_key,
610 const char *lock_name);
611 struct regmap *__regmap_init_spmi_ext(struct spmi_device *dev,
612 const struct regmap_config *config,
613 struct lock_class_key *lock_key,
614 const char *lock_name);
615 struct regmap *__regmap_init_w1(struct device *w1_dev,
616 const struct regmap_config *config,
617 struct lock_class_key *lock_key,
618 const char *lock_name);
619 struct regmap *__regmap_init_mmio_clk(struct device *dev, const char *clk_id,
621 const struct regmap_config *config,
622 struct lock_class_key *lock_key,
623 const char *lock_name);
624 struct regmap *__regmap_init_ac97(struct snd_ac97 *ac97,
625 const struct regmap_config *config,
626 struct lock_class_key *lock_key,
627 const char *lock_name);
628 struct regmap *__regmap_init_sdw(struct sdw_slave *sdw,
629 const struct regmap_config *config,
630 struct lock_class_key *lock_key,
631 const char *lock_name);
632 struct regmap *__regmap_init_sdw_mbq(struct sdw_slave *sdw,
633 const struct regmap_config *config,
634 struct lock_class_key *lock_key,
635 const char *lock_name);
636 struct regmap *__regmap_init_spi_avmm(struct spi_device *spi,
637 const struct regmap_config *config,
638 struct lock_class_key *lock_key,
639 const char *lock_name);
640 struct regmap *__regmap_init_fsi(struct fsi_device *fsi_dev,
641 const struct regmap_config *config,
642 struct lock_class_key *lock_key,
643 const char *lock_name);
645 struct regmap *__devm_regmap_init(struct device *dev,
646 const struct regmap_bus *bus,
648 const struct regmap_config *config,
649 struct lock_class_key *lock_key,
650 const char *lock_name);
651 struct regmap *__devm_regmap_init_i2c(struct i2c_client *i2c,
652 const struct regmap_config *config,
653 struct lock_class_key *lock_key,
654 const char *lock_name);
655 struct regmap *__devm_regmap_init_mdio(struct mdio_device *mdio_dev,
656 const struct regmap_config *config,
657 struct lock_class_key *lock_key,
658 const char *lock_name);
659 struct regmap *__devm_regmap_init_sccb(struct i2c_client *i2c,
660 const struct regmap_config *config,
661 struct lock_class_key *lock_key,
662 const char *lock_name);
663 struct regmap *__devm_regmap_init_spi(struct spi_device *dev,
664 const struct regmap_config *config,
665 struct lock_class_key *lock_key,
666 const char *lock_name);
667 struct regmap *__devm_regmap_init_spmi_base(struct spmi_device *dev,
668 const struct regmap_config *config,
669 struct lock_class_key *lock_key,
670 const char *lock_name);
671 struct regmap *__devm_regmap_init_spmi_ext(struct spmi_device *dev,
672 const struct regmap_config *config,
673 struct lock_class_key *lock_key,
674 const char *lock_name);
675 struct regmap *__devm_regmap_init_w1(struct device *w1_dev,
676 const struct regmap_config *config,
677 struct lock_class_key *lock_key,
678 const char *lock_name);
679 struct regmap *__devm_regmap_init_mmio_clk(struct device *dev,
682 const struct regmap_config *config,
683 struct lock_class_key *lock_key,
684 const char *lock_name);
685 struct regmap *__devm_regmap_init_ac97(struct snd_ac97 *ac97,
686 const struct regmap_config *config,
687 struct lock_class_key *lock_key,
688 const char *lock_name);
689 struct regmap *__devm_regmap_init_sdw(struct sdw_slave *sdw,
690 const struct regmap_config *config,
691 struct lock_class_key *lock_key,
692 const char *lock_name);
693 struct regmap *__devm_regmap_init_sdw_mbq(struct sdw_slave *sdw,
694 const struct regmap_config *config,
695 struct lock_class_key *lock_key,
696 const char *lock_name);
697 struct regmap *__devm_regmap_init_slimbus(struct slim_device *slimbus,
698 const struct regmap_config *config,
699 struct lock_class_key *lock_key,
700 const char *lock_name);
701 struct regmap *__devm_regmap_init_i3c(struct i3c_device *i3c,
702 const struct regmap_config *config,
703 struct lock_class_key *lock_key,
704 const char *lock_name);
705 struct regmap *__devm_regmap_init_spi_avmm(struct spi_device *spi,
706 const struct regmap_config *config,
707 struct lock_class_key *lock_key,
708 const char *lock_name);
709 struct regmap *__devm_regmap_init_fsi(struct fsi_device *fsi_dev,
710 const struct regmap_config *config,
711 struct lock_class_key *lock_key,
712 const char *lock_name);
715 * Wrapper for regmap_init macros to include a unique lockdep key and name
716 * for each call. No-op if CONFIG_LOCKDEP is not set.
718 * @fn: Real function to call (in the form __[*_]regmap_init[_*])
719 * @name: Config variable name (#config in the calling macro)
721 #ifdef CONFIG_LOCKDEP
722 #define __regmap_lockdep_wrapper(fn, name, ...) \
725 static struct lock_class_key _key; \
726 fn(__VA_ARGS__, &_key, \
727 KBUILD_BASENAME ":" \
728 __stringify(__LINE__) ":" \
729 "(" name ")->lock"); \
733 #define __regmap_lockdep_wrapper(fn, name, ...) fn(__VA_ARGS__, NULL, NULL)
737 * regmap_init() - Initialise register map
739 * @dev: Device that will be interacted with
740 * @bus: Bus-specific callbacks to use with device
741 * @bus_context: Data passed to bus-specific callbacks
742 * @config: Configuration for register map
744 * The return value will be an ERR_PTR() on error or a valid pointer to
745 * a struct regmap. This function should generally not be called
746 * directly, it should be called by bus-specific init functions.
748 #define regmap_init(dev, bus, bus_context, config) \
749 __regmap_lockdep_wrapper(__regmap_init, #config, \
750 dev, bus, bus_context, config)
751 int regmap_attach_dev(struct device *dev, struct regmap *map,
752 const struct regmap_config *config);
755 * regmap_init_i2c() - Initialise register map
757 * @i2c: Device that will be interacted with
758 * @config: Configuration for register map
760 * The return value will be an ERR_PTR() on error or a valid pointer to
763 #define regmap_init_i2c(i2c, config) \
764 __regmap_lockdep_wrapper(__regmap_init_i2c, #config, \
768 * regmap_init_mdio() - Initialise register map
770 * @mdio_dev: Device that will be interacted with
771 * @config: Configuration for register map
773 * The return value will be an ERR_PTR() on error or a valid pointer to
776 #define regmap_init_mdio(mdio_dev, config) \
777 __regmap_lockdep_wrapper(__regmap_init_mdio, #config, \
781 * regmap_init_sccb() - Initialise register map
783 * @i2c: Device that will be interacted with
784 * @config: Configuration for register map
786 * The return value will be an ERR_PTR() on error or a valid pointer to
789 #define regmap_init_sccb(i2c, config) \
790 __regmap_lockdep_wrapper(__regmap_init_sccb, #config, \
794 * regmap_init_slimbus() - Initialise register map
796 * @slimbus: Device that will be interacted with
797 * @config: Configuration for register map
799 * The return value will be an ERR_PTR() on error or a valid pointer to
802 #define regmap_init_slimbus(slimbus, config) \
803 __regmap_lockdep_wrapper(__regmap_init_slimbus, #config, \
807 * regmap_init_spi() - Initialise register map
809 * @dev: Device that will be interacted with
810 * @config: Configuration for register map
812 * The return value will be an ERR_PTR() on error or a valid pointer to
815 #define regmap_init_spi(dev, config) \
816 __regmap_lockdep_wrapper(__regmap_init_spi, #config, \
820 * regmap_init_spmi_base() - Create regmap for the Base register space
822 * @dev: SPMI device that will be interacted with
823 * @config: Configuration for register map
825 * The return value will be an ERR_PTR() on error or a valid pointer to
828 #define regmap_init_spmi_base(dev, config) \
829 __regmap_lockdep_wrapper(__regmap_init_spmi_base, #config, \
833 * regmap_init_spmi_ext() - Create regmap for Ext register space
835 * @dev: Device that will be interacted with
836 * @config: Configuration for register map
838 * The return value will be an ERR_PTR() on error or a valid pointer to
841 #define regmap_init_spmi_ext(dev, config) \
842 __regmap_lockdep_wrapper(__regmap_init_spmi_ext, #config, \
846 * regmap_init_w1() - Initialise register map
848 * @w1_dev: Device that will be interacted with
849 * @config: Configuration for register map
851 * The return value will be an ERR_PTR() on error or a valid pointer to
854 #define regmap_init_w1(w1_dev, config) \
855 __regmap_lockdep_wrapper(__regmap_init_w1, #config, \
859 * regmap_init_mmio_clk() - Initialise register map with register clock
861 * @dev: Device that will be interacted with
862 * @clk_id: register clock consumer ID
863 * @regs: Pointer to memory-mapped IO region
864 * @config: Configuration for register map
866 * The return value will be an ERR_PTR() on error or a valid pointer to
869 #define regmap_init_mmio_clk(dev, clk_id, regs, config) \
870 __regmap_lockdep_wrapper(__regmap_init_mmio_clk, #config, \
871 dev, clk_id, regs, config)
874 * regmap_init_mmio() - Initialise register map
876 * @dev: Device that will be interacted with
877 * @regs: Pointer to memory-mapped IO region
878 * @config: Configuration for register map
880 * The return value will be an ERR_PTR() on error or a valid pointer to
883 #define regmap_init_mmio(dev, regs, config) \
884 regmap_init_mmio_clk(dev, NULL, regs, config)
887 * regmap_init_ac97() - Initialise AC'97 register map
889 * @ac97: Device that will be interacted with
890 * @config: Configuration for register map
892 * The return value will be an ERR_PTR() on error or a valid pointer to
895 #define regmap_init_ac97(ac97, config) \
896 __regmap_lockdep_wrapper(__regmap_init_ac97, #config, \
898 bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg);
901 * regmap_init_sdw() - Initialise register map
903 * @sdw: Device that will be interacted with
904 * @config: Configuration for register map
906 * The return value will be an ERR_PTR() on error or a valid pointer to
909 #define regmap_init_sdw(sdw, config) \
910 __regmap_lockdep_wrapper(__regmap_init_sdw, #config, \
914 * regmap_init_sdw_mbq() - Initialise register map
916 * @sdw: Device that will be interacted with
917 * @config: Configuration for register map
919 * The return value will be an ERR_PTR() on error or a valid pointer to
922 #define regmap_init_sdw_mbq(sdw, config) \
923 __regmap_lockdep_wrapper(__regmap_init_sdw_mbq, #config, \
927 * regmap_init_spi_avmm() - Initialize register map for Intel SPI Slave
930 * @spi: Device that will be interacted with
931 * @config: Configuration for register map
933 * The return value will be an ERR_PTR() on error or a valid pointer
934 * to a struct regmap.
936 #define regmap_init_spi_avmm(spi, config) \
937 __regmap_lockdep_wrapper(__regmap_init_spi_avmm, #config, \
941 * regmap_init_fsi() - Initialise register map
943 * @fsi_dev: Device that will be interacted with
944 * @config: Configuration for register map
946 * The return value will be an ERR_PTR() on error or a valid pointer to
949 #define regmap_init_fsi(fsi_dev, config) \
950 __regmap_lockdep_wrapper(__regmap_init_fsi, #config, fsi_dev, \
954 * devm_regmap_init() - Initialise managed register map
956 * @dev: Device that will be interacted with
957 * @bus: Bus-specific callbacks to use with device
958 * @bus_context: Data passed to bus-specific callbacks
959 * @config: Configuration for register map
961 * The return value will be an ERR_PTR() on error or a valid pointer
962 * to a struct regmap. This function should generally not be called
963 * directly, it should be called by bus-specific init functions. The
964 * map will be automatically freed by the device management code.
966 #define devm_regmap_init(dev, bus, bus_context, config) \
967 __regmap_lockdep_wrapper(__devm_regmap_init, #config, \
968 dev, bus, bus_context, config)
971 * devm_regmap_init_i2c() - Initialise managed register map
973 * @i2c: Device that will be interacted with
974 * @config: Configuration for register map
976 * The return value will be an ERR_PTR() on error or a valid pointer
977 * to a struct regmap. The regmap will be automatically freed by the
978 * device management code.
980 #define devm_regmap_init_i2c(i2c, config) \
981 __regmap_lockdep_wrapper(__devm_regmap_init_i2c, #config, \
985 * devm_regmap_init_mdio() - Initialise managed register map
987 * @mdio_dev: Device that will be interacted with
988 * @config: Configuration for register map
990 * The return value will be an ERR_PTR() on error or a valid pointer
991 * to a struct regmap. The regmap will be automatically freed by the
992 * device management code.
994 #define devm_regmap_init_mdio(mdio_dev, config) \
995 __regmap_lockdep_wrapper(__devm_regmap_init_mdio, #config, \
999 * devm_regmap_init_sccb() - Initialise managed register map
1001 * @i2c: Device that will be interacted with
1002 * @config: Configuration for register map
1004 * The return value will be an ERR_PTR() on error or a valid pointer
1005 * to a struct regmap. The regmap will be automatically freed by the
1006 * device management code.
1008 #define devm_regmap_init_sccb(i2c, config) \
1009 __regmap_lockdep_wrapper(__devm_regmap_init_sccb, #config, \
1013 * devm_regmap_init_spi() - Initialise register map
1015 * @dev: Device that will be interacted with
1016 * @config: Configuration for register map
1018 * The return value will be an ERR_PTR() on error or a valid pointer
1019 * to a struct regmap. The map will be automatically freed by the
1020 * device management code.
1022 #define devm_regmap_init_spi(dev, config) \
1023 __regmap_lockdep_wrapper(__devm_regmap_init_spi, #config, \
1027 * devm_regmap_init_spmi_base() - Create managed regmap for Base register space
1029 * @dev: SPMI device that will be interacted with
1030 * @config: Configuration for register map
1032 * The return value will be an ERR_PTR() on error or a valid pointer
1033 * to a struct regmap. The regmap will be automatically freed by the
1034 * device management code.
1036 #define devm_regmap_init_spmi_base(dev, config) \
1037 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_base, #config, \
1041 * devm_regmap_init_spmi_ext() - Create managed regmap for Ext register space
1043 * @dev: SPMI device that will be interacted with
1044 * @config: Configuration for register map
1046 * The return value will be an ERR_PTR() on error or a valid pointer
1047 * to a struct regmap. The regmap will be automatically freed by the
1048 * device management code.
1050 #define devm_regmap_init_spmi_ext(dev, config) \
1051 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_ext, #config, \
1055 * devm_regmap_init_w1() - Initialise managed register map
1057 * @w1_dev: Device that will be interacted with
1058 * @config: Configuration for register map
1060 * The return value will be an ERR_PTR() on error or a valid pointer
1061 * to a struct regmap. The regmap will be automatically freed by the
1062 * device management code.
1064 #define devm_regmap_init_w1(w1_dev, config) \
1065 __regmap_lockdep_wrapper(__devm_regmap_init_w1, #config, \
1068 * devm_regmap_init_mmio_clk() - Initialise managed register map with clock
1070 * @dev: Device that will be interacted with
1071 * @clk_id: register clock consumer ID
1072 * @regs: Pointer to memory-mapped IO region
1073 * @config: Configuration for register map
1075 * The return value will be an ERR_PTR() on error or a valid pointer
1076 * to a struct regmap. The regmap will be automatically freed by the
1077 * device management code.
1079 #define devm_regmap_init_mmio_clk(dev, clk_id, regs, config) \
1080 __regmap_lockdep_wrapper(__devm_regmap_init_mmio_clk, #config, \
1081 dev, clk_id, regs, config)
1084 * devm_regmap_init_mmio() - Initialise managed register map
1086 * @dev: Device that will be interacted with
1087 * @regs: Pointer to memory-mapped IO region
1088 * @config: Configuration for register map
1090 * The return value will be an ERR_PTR() on error or a valid pointer
1091 * to a struct regmap. The regmap will be automatically freed by the
1092 * device management code.
1094 #define devm_regmap_init_mmio(dev, regs, config) \
1095 devm_regmap_init_mmio_clk(dev, NULL, regs, config)
1098 * devm_regmap_init_ac97() - Initialise AC'97 register map
1100 * @ac97: Device that will be interacted with
1101 * @config: Configuration for register map
1103 * The return value will be an ERR_PTR() on error or a valid pointer
1104 * to a struct regmap. The regmap will be automatically freed by the
1105 * device management code.
1107 #define devm_regmap_init_ac97(ac97, config) \
1108 __regmap_lockdep_wrapper(__devm_regmap_init_ac97, #config, \
1112 * devm_regmap_init_sdw() - Initialise managed register map
1114 * @sdw: Device that will be interacted with
1115 * @config: Configuration for register map
1117 * The return value will be an ERR_PTR() on error or a valid pointer
1118 * to a struct regmap. The regmap will be automatically freed by the
1119 * device management code.
1121 #define devm_regmap_init_sdw(sdw, config) \
1122 __regmap_lockdep_wrapper(__devm_regmap_init_sdw, #config, \
1126 * devm_regmap_init_sdw_mbq() - Initialise managed register map
1128 * @sdw: Device that will be interacted with
1129 * @config: Configuration for register map
1131 * The return value will be an ERR_PTR() on error or a valid pointer
1132 * to a struct regmap. The regmap will be automatically freed by the
1133 * device management code.
1135 #define devm_regmap_init_sdw_mbq(sdw, config) \
1136 __regmap_lockdep_wrapper(__devm_regmap_init_sdw_mbq, #config, \
1140 * devm_regmap_init_slimbus() - Initialise managed register map
1142 * @slimbus: Device that will be interacted with
1143 * @config: Configuration for register map
1145 * The return value will be an ERR_PTR() on error or a valid pointer
1146 * to a struct regmap. The regmap will be automatically freed by the
1147 * device management code.
1149 #define devm_regmap_init_slimbus(slimbus, config) \
1150 __regmap_lockdep_wrapper(__devm_regmap_init_slimbus, #config, \
1154 * devm_regmap_init_i3c() - Initialise managed register map
1156 * @i3c: Device that will be interacted with
1157 * @config: Configuration for register map
1159 * The return value will be an ERR_PTR() on error or a valid pointer
1160 * to a struct regmap. The regmap will be automatically freed by the
1161 * device management code.
1163 #define devm_regmap_init_i3c(i3c, config) \
1164 __regmap_lockdep_wrapper(__devm_regmap_init_i3c, #config, \
1168 * devm_regmap_init_spi_avmm() - Initialize register map for Intel SPI Slave
1169 * to AVMM Bus Bridge
1171 * @spi: Device that will be interacted with
1172 * @config: Configuration for register map
1174 * The return value will be an ERR_PTR() on error or a valid pointer
1175 * to a struct regmap. The map will be automatically freed by the
1176 * device management code.
1178 #define devm_regmap_init_spi_avmm(spi, config) \
1179 __regmap_lockdep_wrapper(__devm_regmap_init_spi_avmm, #config, \
1183 * devm_regmap_init_fsi() - Initialise managed register map
1185 * @fsi_dev: Device that will be interacted with
1186 * @config: Configuration for register map
1188 * The return value will be an ERR_PTR() on error or a valid pointer
1189 * to a struct regmap. The regmap will be automatically freed by the
1190 * device management code.
1192 #define devm_regmap_init_fsi(fsi_dev, config) \
1193 __regmap_lockdep_wrapper(__devm_regmap_init_fsi, #config, \
1196 int regmap_mmio_attach_clk(struct regmap *map, struct clk *clk);
1197 void regmap_mmio_detach_clk(struct regmap *map);
1198 void regmap_exit(struct regmap *map);
1199 int regmap_reinit_cache(struct regmap *map,
1200 const struct regmap_config *config);
1201 struct regmap *dev_get_regmap(struct device *dev, const char *name);
1202 struct device *regmap_get_device(struct regmap *map);
1203 int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
1204 int regmap_write_async(struct regmap *map, unsigned int reg, unsigned int val);
1205 int regmap_raw_write(struct regmap *map, unsigned int reg,
1206 const void *val, size_t val_len);
1207 int regmap_noinc_write(struct regmap *map, unsigned int reg,
1208 const void *val, size_t val_len);
1209 int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
1211 int regmap_multi_reg_write(struct regmap *map, const struct reg_sequence *regs,
1213 int regmap_multi_reg_write_bypassed(struct regmap *map,
1214 const struct reg_sequence *regs,
1216 int regmap_raw_write_async(struct regmap *map, unsigned int reg,
1217 const void *val, size_t val_len);
1218 int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
1219 int regmap_raw_read(struct regmap *map, unsigned int reg,
1220 void *val, size_t val_len);
1221 int regmap_noinc_read(struct regmap *map, unsigned int reg,
1222 void *val, size_t val_len);
1223 int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
1225 int regmap_update_bits_base(struct regmap *map, unsigned int reg,
1226 unsigned int mask, unsigned int val,
1227 bool *change, bool async, bool force);
1229 static inline int regmap_update_bits(struct regmap *map, unsigned int reg,
1230 unsigned int mask, unsigned int val)
1232 return regmap_update_bits_base(map, reg, mask, val, NULL, false, false);
1235 static inline int regmap_update_bits_async(struct regmap *map, unsigned int reg,
1236 unsigned int mask, unsigned int val)
1238 return regmap_update_bits_base(map, reg, mask, val, NULL, true, false);
1241 static inline int regmap_update_bits_check(struct regmap *map, unsigned int reg,
1242 unsigned int mask, unsigned int val,
1245 return regmap_update_bits_base(map, reg, mask, val,
1246 change, false, false);
1250 regmap_update_bits_check_async(struct regmap *map, unsigned int reg,
1251 unsigned int mask, unsigned int val,
1254 return regmap_update_bits_base(map, reg, mask, val,
1255 change, true, false);
1258 static inline int regmap_write_bits(struct regmap *map, unsigned int reg,
1259 unsigned int mask, unsigned int val)
1261 return regmap_update_bits_base(map, reg, mask, val, NULL, false, true);
1264 int regmap_get_val_bytes(struct regmap *map);
1265 int regmap_get_max_register(struct regmap *map);
1266 int regmap_get_reg_stride(struct regmap *map);
1267 bool regmap_might_sleep(struct regmap *map);
1268 int regmap_async_complete(struct regmap *map);
1269 bool regmap_can_raw_write(struct regmap *map);
1270 size_t regmap_get_raw_read_max(struct regmap *map);
1271 size_t regmap_get_raw_write_max(struct regmap *map);
1273 int regcache_sync(struct regmap *map);
1274 int regcache_sync_region(struct regmap *map, unsigned int min,
1276 int regcache_drop_region(struct regmap *map, unsigned int min,
1278 void regcache_cache_only(struct regmap *map, bool enable);
1279 void regcache_cache_bypass(struct regmap *map, bool enable);
1280 void regcache_mark_dirty(struct regmap *map);
1282 bool regmap_check_range_table(struct regmap *map, unsigned int reg,
1283 const struct regmap_access_table *table);
1285 int regmap_register_patch(struct regmap *map, const struct reg_sequence *regs,
1287 int regmap_parse_val(struct regmap *map, const void *buf,
1290 static inline bool regmap_reg_in_range(unsigned int reg,
1291 const struct regmap_range *range)
1293 return reg >= range->range_min && reg <= range->range_max;
1296 bool regmap_reg_in_ranges(unsigned int reg,
1297 const struct regmap_range *ranges,
1298 unsigned int nranges);
1300 static inline int regmap_set_bits(struct regmap *map,
1301 unsigned int reg, unsigned int bits)
1303 return regmap_update_bits_base(map, reg, bits, bits,
1304 NULL, false, false);
1307 static inline int regmap_clear_bits(struct regmap *map,
1308 unsigned int reg, unsigned int bits)
1310 return regmap_update_bits_base(map, reg, bits, 0, NULL, false, false);
1313 int regmap_test_bits(struct regmap *map, unsigned int reg, unsigned int bits);
1316 * struct reg_field - Description of an register field
1318 * @reg: Offset of the register within the regmap bank
1319 * @lsb: lsb of the register field.
1320 * @msb: msb of the register field.
1321 * @id_size: port size if it has some ports
1322 * @id_offset: address offset for each ports
1328 unsigned int id_size;
1329 unsigned int id_offset;
1332 #define REG_FIELD(_reg, _lsb, _msb) { \
1338 #define REG_FIELD_ID(_reg, _lsb, _msb, _size, _offset) { \
1343 .id_offset = _offset, \
1346 struct regmap_field *regmap_field_alloc(struct regmap *regmap,
1347 struct reg_field reg_field);
1348 void regmap_field_free(struct regmap_field *field);
1350 struct regmap_field *devm_regmap_field_alloc(struct device *dev,
1351 struct regmap *regmap, struct reg_field reg_field);
1352 void devm_regmap_field_free(struct device *dev, struct regmap_field *field);
1354 int regmap_field_bulk_alloc(struct regmap *regmap,
1355 struct regmap_field **rm_field,
1356 const struct reg_field *reg_field,
1358 void regmap_field_bulk_free(struct regmap_field *field);
1359 int devm_regmap_field_bulk_alloc(struct device *dev, struct regmap *regmap,
1360 struct regmap_field **field,
1361 const struct reg_field *reg_field,
1363 void devm_regmap_field_bulk_free(struct device *dev,
1364 struct regmap_field *field);
1366 int regmap_field_read(struct regmap_field *field, unsigned int *val);
1367 int regmap_field_update_bits_base(struct regmap_field *field,
1368 unsigned int mask, unsigned int val,
1369 bool *change, bool async, bool force);
1370 int regmap_fields_read(struct regmap_field *field, unsigned int id,
1372 int regmap_fields_update_bits_base(struct regmap_field *field, unsigned int id,
1373 unsigned int mask, unsigned int val,
1374 bool *change, bool async, bool force);
1376 static inline int regmap_field_write(struct regmap_field *field,
1379 return regmap_field_update_bits_base(field, ~0, val,
1380 NULL, false, false);
1383 static inline int regmap_field_force_write(struct regmap_field *field,
1386 return regmap_field_update_bits_base(field, ~0, val, NULL, false, true);
1389 static inline int regmap_field_update_bits(struct regmap_field *field,
1390 unsigned int mask, unsigned int val)
1392 return regmap_field_update_bits_base(field, mask, val,
1393 NULL, false, false);
1396 static inline int regmap_field_set_bits(struct regmap_field *field,
1399 return regmap_field_update_bits_base(field, bits, bits, NULL, false,
1403 static inline int regmap_field_clear_bits(struct regmap_field *field,
1406 return regmap_field_update_bits_base(field, bits, 0, NULL, false,
1410 int regmap_field_test_bits(struct regmap_field *field, unsigned int bits);
1413 regmap_field_force_update_bits(struct regmap_field *field,
1414 unsigned int mask, unsigned int val)
1416 return regmap_field_update_bits_base(field, mask, val,
1420 static inline int regmap_fields_write(struct regmap_field *field,
1421 unsigned int id, unsigned int val)
1423 return regmap_fields_update_bits_base(field, id, ~0, val,
1424 NULL, false, false);
1427 static inline int regmap_fields_force_write(struct regmap_field *field,
1428 unsigned int id, unsigned int val)
1430 return regmap_fields_update_bits_base(field, id, ~0, val,
1435 regmap_fields_update_bits(struct regmap_field *field, unsigned int id,
1436 unsigned int mask, unsigned int val)
1438 return regmap_fields_update_bits_base(field, id, mask, val,
1439 NULL, false, false);
1443 regmap_fields_force_update_bits(struct regmap_field *field, unsigned int id,
1444 unsigned int mask, unsigned int val)
1446 return regmap_fields_update_bits_base(field, id, mask, val,
1451 * struct regmap_irq_type - IRQ type definitions.
1453 * @type_reg_offset: Offset register for the irq type setting.
1454 * @type_rising_val: Register value to configure RISING type irq.
1455 * @type_falling_val: Register value to configure FALLING type irq.
1456 * @type_level_low_val: Register value to configure LEVEL_LOW type irq.
1457 * @type_level_high_val: Register value to configure LEVEL_HIGH type irq.
1458 * @types_supported: logical OR of IRQ_TYPE_* flags indicating supported types.
1460 struct regmap_irq_type {
1461 unsigned int type_reg_offset;
1462 unsigned int type_reg_mask;
1463 unsigned int type_rising_val;
1464 unsigned int type_falling_val;
1465 unsigned int type_level_low_val;
1466 unsigned int type_level_high_val;
1467 unsigned int types_supported;
1471 * struct regmap_irq - Description of an IRQ for the generic regmap irq_chip.
1473 * @reg_offset: Offset of the status/mask register within the bank
1474 * @mask: Mask used to flag/control the register.
1475 * @type: IRQ trigger type setting details if supported.
1478 unsigned int reg_offset;
1480 struct regmap_irq_type type;
1483 #define REGMAP_IRQ_REG(_irq, _off, _mask) \
1484 [_irq] = { .reg_offset = (_off), .mask = (_mask) }
1486 #define REGMAP_IRQ_REG_LINE(_id, _reg_bits) \
1488 .mask = BIT((_id) % (_reg_bits)), \
1489 .reg_offset = (_id) / (_reg_bits), \
1492 #define REGMAP_IRQ_MAIN_REG_OFFSET(arr) \
1493 { .num_regs = ARRAY_SIZE((arr)), .offset = &(arr)[0] }
1495 struct regmap_irq_sub_irq_map {
1496 unsigned int num_regs;
1497 unsigned int *offset;
1500 struct regmap_irq_chip_data;
1503 * struct regmap_irq_chip - Description of a generic regmap irq_chip.
1505 * @name: Descriptive name for IRQ controller.
1507 * @main_status: Base main status register address. For chips which have
1508 * interrupts arranged in separate sub-irq blocks with own IRQ
1509 * registers and which have a main IRQ registers indicating
1510 * sub-irq blocks with unhandled interrupts. For such chips fill
1511 * sub-irq register information in status_base, mask_base and
1513 * @num_main_status_bits: Should be given to chips where number of meaningfull
1514 * main status bits differs from num_regs.
1515 * @sub_reg_offsets: arrays of mappings from main register bits to sub irq
1516 * registers. First item in array describes the registers
1517 * for first main status bit. Second array for second bit etc.
1518 * Offset is given as sub register status offset to
1519 * status_base. Should contain num_regs arrays.
1520 * Can be provided for chips with more complex mapping than
1521 * 1.st bit to 1.st sub-reg, 2.nd bit to 2.nd sub-reg, ...
1522 * When used with not_fixed_stride, each one-element array
1523 * member contains offset calculated as address from each
1524 * peripheral to first peripheral.
1525 * @num_main_regs: Number of 'main status' irq registers for chips which have
1528 * @status_base: Base status register address.
1529 * @mask_base: Base mask register address. Mask bits are set to 1 when an
1530 * interrupt is masked, 0 when unmasked.
1531 * @unmask_base: Base unmask register address. Unmask bits are set to 1 when
1532 * an interrupt is unmasked and 0 when masked.
1533 * @ack_base: Base ack address. If zero then the chip is clear on read.
1534 * Using zero value is possible with @use_ack bit.
1535 * @wake_base: Base address for wake enables. If zero unsupported.
1536 * @type_base: Base address for irq type. If zero unsupported. Deprecated,
1537 * use @config_base instead.
1538 * @virt_reg_base: Base addresses for extra config regs. Deprecated, use
1539 * @config_base instead.
1540 * @config_base: Base address for IRQ type config regs. If null unsupported.
1541 * @irq_reg_stride: Stride to use for chips where registers are not contiguous.
1542 * @init_ack_masked: Ack all masked interrupts once during initalization.
1543 * @mask_unmask_non_inverted: Controls mask bit inversion for chips that set
1544 * both @mask_base and @unmask_base. If false, mask and unmask bits are
1545 * inverted (which is deprecated behavior); if true, bits will not be
1546 * inverted and the registers keep their normal behavior. Note that if
1547 * you use only one of @mask_base or @unmask_base, this flag has no
1548 * effect and is unnecessary. Any new drivers that set both @mask_base
1549 * and @unmask_base should set this to true to avoid relying on the
1550 * deprecated behavior.
1551 * @use_ack: Use @ack register even if it is zero.
1552 * @ack_invert: Inverted ack register: cleared bits for ack.
1553 * @clear_ack: Use this to set 1 and 0 or vice-versa to clear interrupts.
1554 * @wake_invert: Inverted wake register: cleared bits are wake enabled.
1555 * @type_in_mask: Use the mask registers for controlling irq type. Use this if
1556 * the hardware provides separate bits for rising/falling edge
1557 * or low/high level interrupts and they should be combined into
1558 * a single logical interrupt. Use &struct regmap_irq_type data
1559 * to define the mask bit for each irq type.
1560 * @clear_on_unmask: For chips with interrupts cleared on read: read the status
1561 * registers before unmasking interrupts to clear any bits
1562 * set when they were masked.
1563 * @not_fixed_stride: Used when chip peripherals are not laid out with fixed
1564 * stride. Must be used with sub_reg_offsets containing the
1565 * offsets to each peripheral. Deprecated; the same thing
1566 * can be accomplished with a @get_irq_reg callback, without
1567 * the need for a @sub_reg_offsets table.
1568 * @status_invert: Inverted status register: cleared bits are active interrupts.
1569 * @runtime_pm: Hold a runtime PM lock on the device when accessing it.
1571 * @num_regs: Number of registers in each control bank.
1572 * @irqs: Descriptors for individual IRQs. Interrupt numbers are
1573 * assigned based on the index in the array of the interrupt.
1574 * @num_irqs: Number of descriptors.
1575 * @num_type_reg: Number of type registers. Deprecated, use config registers
1577 * @num_virt_regs: Number of non-standard irq configuration registers.
1578 * If zero unsupported. Deprecated, use config registers
1580 * @num_config_bases: Number of config base registers.
1581 * @num_config_regs: Number of config registers for each config base register.
1582 * @handle_pre_irq: Driver specific callback to handle interrupt from device
1583 * before regmap_irq_handler process the interrupts.
1584 * @handle_post_irq: Driver specific callback to handle interrupt from device
1585 * after handling the interrupts in regmap_irq_handler().
1586 * @handle_mask_sync: Callback used to handle IRQ mask syncs. The index will be
1587 * in the range [0, num_regs)
1588 * @set_type_virt: Driver specific callback to extend regmap_irq_set_type()
1589 * and configure virt regs. Deprecated, use @set_type_config
1590 * callback and config registers instead.
1591 * @set_type_config: Callback used for configuring irq types.
1592 * @get_irq_reg: Callback for mapping (base register, index) pairs to register
1593 * addresses. The base register will be one of @status_base,
1594 * @mask_base, etc., @main_status, or any of @config_base.
1595 * The index will be in the range [0, num_main_regs[ for the
1596 * main status base, [0, num_type_settings[ for any config
1597 * register base, and [0, num_regs[ for any other base.
1598 * If unspecified then regmap_irq_get_irq_reg_linear() is used.
1599 * @irq_drv_data: Driver specific IRQ data which is passed as parameter when
1600 * driver specific pre/post interrupt handler is called.
1602 * This is not intended to handle every possible interrupt controller, but
1603 * it should handle a substantial proportion of those that are found in the
1606 struct regmap_irq_chip {
1609 unsigned int main_status;
1610 unsigned int num_main_status_bits;
1611 struct regmap_irq_sub_irq_map *sub_reg_offsets;
1614 unsigned int status_base;
1615 unsigned int mask_base;
1616 unsigned int unmask_base;
1617 unsigned int ack_base;
1618 unsigned int wake_base;
1619 unsigned int type_base;
1620 unsigned int *virt_reg_base;
1621 const unsigned int *config_base;
1622 unsigned int irq_reg_stride;
1623 unsigned int init_ack_masked:1;
1624 unsigned int mask_unmask_non_inverted:1;
1625 unsigned int use_ack:1;
1626 unsigned int ack_invert:1;
1627 unsigned int clear_ack:1;
1628 unsigned int wake_invert:1;
1629 unsigned int runtime_pm:1;
1630 unsigned int type_in_mask:1;
1631 unsigned int clear_on_unmask:1;
1632 unsigned int not_fixed_stride:1;
1633 unsigned int status_invert:1;
1637 const struct regmap_irq *irqs;
1642 int num_config_bases;
1643 int num_config_regs;
1645 int (*handle_pre_irq)(void *irq_drv_data);
1646 int (*handle_post_irq)(void *irq_drv_data);
1647 int (*handle_mask_sync)(struct regmap *map, int index,
1648 unsigned int mask_buf_def,
1649 unsigned int mask_buf, void *irq_drv_data);
1650 int (*set_type_virt)(unsigned int **buf, unsigned int type,
1651 unsigned long hwirq, int reg);
1652 int (*set_type_config)(unsigned int **buf, unsigned int type,
1653 const struct regmap_irq *irq_data, int idx);
1654 unsigned int (*get_irq_reg)(struct regmap_irq_chip_data *data,
1655 unsigned int base, int index);
1659 unsigned int regmap_irq_get_irq_reg_linear(struct regmap_irq_chip_data *data,
1660 unsigned int base, int index);
1661 int regmap_irq_set_type_config_simple(unsigned int **buf, unsigned int type,
1662 const struct regmap_irq *irq_data, int idx);
1664 int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
1665 int irq_base, const struct regmap_irq_chip *chip,
1666 struct regmap_irq_chip_data **data);
1667 int regmap_add_irq_chip_fwnode(struct fwnode_handle *fwnode,
1668 struct regmap *map, int irq,
1669 int irq_flags, int irq_base,
1670 const struct regmap_irq_chip *chip,
1671 struct regmap_irq_chip_data **data);
1672 void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data);
1674 int devm_regmap_add_irq_chip(struct device *dev, struct regmap *map, int irq,
1675 int irq_flags, int irq_base,
1676 const struct regmap_irq_chip *chip,
1677 struct regmap_irq_chip_data **data);
1678 int devm_regmap_add_irq_chip_fwnode(struct device *dev,
1679 struct fwnode_handle *fwnode,
1680 struct regmap *map, int irq,
1681 int irq_flags, int irq_base,
1682 const struct regmap_irq_chip *chip,
1683 struct regmap_irq_chip_data **data);
1684 void devm_regmap_del_irq_chip(struct device *dev, int irq,
1685 struct regmap_irq_chip_data *data);
1687 int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data);
1688 int regmap_irq_get_virq(struct regmap_irq_chip_data *data, int irq);
1689 struct irq_domain *regmap_irq_get_domain(struct regmap_irq_chip_data *data);
1694 * These stubs should only ever be called by generic code which has
1695 * regmap based facilities, if they ever get called at runtime
1696 * something is going wrong and something probably needs to select
1700 static inline int regmap_write(struct regmap *map, unsigned int reg,
1703 WARN_ONCE(1, "regmap API is disabled");
1707 static inline int regmap_write_async(struct regmap *map, unsigned int reg,
1710 WARN_ONCE(1, "regmap API is disabled");
1714 static inline int regmap_raw_write(struct regmap *map, unsigned int reg,
1715 const void *val, size_t val_len)
1717 WARN_ONCE(1, "regmap API is disabled");
1721 static inline int regmap_raw_write_async(struct regmap *map, unsigned int reg,
1722 const void *val, size_t val_len)
1724 WARN_ONCE(1, "regmap API is disabled");
1728 static inline int regmap_noinc_write(struct regmap *map, unsigned int reg,
1729 const void *val, size_t val_len)
1731 WARN_ONCE(1, "regmap API is disabled");
1735 static inline int regmap_bulk_write(struct regmap *map, unsigned int reg,
1736 const void *val, size_t val_count)
1738 WARN_ONCE(1, "regmap API is disabled");
1742 static inline int regmap_read(struct regmap *map, unsigned int reg,
1745 WARN_ONCE(1, "regmap API is disabled");
1749 static inline int regmap_raw_read(struct regmap *map, unsigned int reg,
1750 void *val, size_t val_len)
1752 WARN_ONCE(1, "regmap API is disabled");
1756 static inline int regmap_noinc_read(struct regmap *map, unsigned int reg,
1757 void *val, size_t val_len)
1759 WARN_ONCE(1, "regmap API is disabled");
1763 static inline int regmap_bulk_read(struct regmap *map, unsigned int reg,
1764 void *val, size_t val_count)
1766 WARN_ONCE(1, "regmap API is disabled");
1770 static inline int regmap_update_bits_base(struct regmap *map, unsigned int reg,
1771 unsigned int mask, unsigned int val,
1772 bool *change, bool async, bool force)
1774 WARN_ONCE(1, "regmap API is disabled");
1778 static inline int regmap_set_bits(struct regmap *map,
1779 unsigned int reg, unsigned int bits)
1781 WARN_ONCE(1, "regmap API is disabled");
1785 static inline int regmap_clear_bits(struct regmap *map,
1786 unsigned int reg, unsigned int bits)
1788 WARN_ONCE(1, "regmap API is disabled");
1792 static inline int regmap_test_bits(struct regmap *map,
1793 unsigned int reg, unsigned int bits)
1795 WARN_ONCE(1, "regmap API is disabled");
1799 static inline int regmap_field_update_bits_base(struct regmap_field *field,
1800 unsigned int mask, unsigned int val,
1801 bool *change, bool async, bool force)
1803 WARN_ONCE(1, "regmap API is disabled");
1807 static inline int regmap_fields_update_bits_base(struct regmap_field *field,
1809 unsigned int mask, unsigned int val,
1810 bool *change, bool async, bool force)
1812 WARN_ONCE(1, "regmap API is disabled");
1816 static inline int regmap_update_bits(struct regmap *map, unsigned int reg,
1817 unsigned int mask, unsigned int val)
1819 WARN_ONCE(1, "regmap API is disabled");
1823 static inline int regmap_update_bits_async(struct regmap *map, unsigned int reg,
1824 unsigned int mask, unsigned int val)
1826 WARN_ONCE(1, "regmap API is disabled");
1830 static inline int regmap_update_bits_check(struct regmap *map, unsigned int reg,
1831 unsigned int mask, unsigned int val,
1834 WARN_ONCE(1, "regmap API is disabled");
1839 regmap_update_bits_check_async(struct regmap *map, unsigned int reg,
1840 unsigned int mask, unsigned int val,
1843 WARN_ONCE(1, "regmap API is disabled");
1847 static inline int regmap_write_bits(struct regmap *map, unsigned int reg,
1848 unsigned int mask, unsigned int val)
1850 WARN_ONCE(1, "regmap API is disabled");
1854 static inline int regmap_field_write(struct regmap_field *field,
1857 WARN_ONCE(1, "regmap API is disabled");
1861 static inline int regmap_field_force_write(struct regmap_field *field,
1864 WARN_ONCE(1, "regmap API is disabled");
1868 static inline int regmap_field_update_bits(struct regmap_field *field,
1869 unsigned int mask, unsigned int val)
1871 WARN_ONCE(1, "regmap API is disabled");
1876 regmap_field_force_update_bits(struct regmap_field *field,
1877 unsigned int mask, unsigned int val)
1879 WARN_ONCE(1, "regmap API is disabled");
1883 static inline int regmap_field_set_bits(struct regmap_field *field,
1886 WARN_ONCE(1, "regmap API is disabled");
1890 static inline int regmap_field_clear_bits(struct regmap_field *field,
1893 WARN_ONCE(1, "regmap API is disabled");
1897 static inline int regmap_field_test_bits(struct regmap_field *field,
1900 WARN_ONCE(1, "regmap API is disabled");
1904 static inline int regmap_fields_write(struct regmap_field *field,
1905 unsigned int id, unsigned int val)
1907 WARN_ONCE(1, "regmap API is disabled");
1911 static inline int regmap_fields_force_write(struct regmap_field *field,
1912 unsigned int id, unsigned int val)
1914 WARN_ONCE(1, "regmap API is disabled");
1919 regmap_fields_update_bits(struct regmap_field *field, unsigned int id,
1920 unsigned int mask, unsigned int val)
1922 WARN_ONCE(1, "regmap API is disabled");
1927 regmap_fields_force_update_bits(struct regmap_field *field, unsigned int id,
1928 unsigned int mask, unsigned int val)
1930 WARN_ONCE(1, "regmap API is disabled");
1934 static inline int regmap_get_val_bytes(struct regmap *map)
1936 WARN_ONCE(1, "regmap API is disabled");
1940 static inline int regmap_get_max_register(struct regmap *map)
1942 WARN_ONCE(1, "regmap API is disabled");
1946 static inline int regmap_get_reg_stride(struct regmap *map)
1948 WARN_ONCE(1, "regmap API is disabled");
1952 static inline bool regmap_might_sleep(struct regmap *map)
1954 WARN_ONCE(1, "regmap API is disabled");
1958 static inline int regcache_sync(struct regmap *map)
1960 WARN_ONCE(1, "regmap API is disabled");
1964 static inline int regcache_sync_region(struct regmap *map, unsigned int min,
1967 WARN_ONCE(1, "regmap API is disabled");
1971 static inline int regcache_drop_region(struct regmap *map, unsigned int min,
1974 WARN_ONCE(1, "regmap API is disabled");
1978 static inline void regcache_cache_only(struct regmap *map, bool enable)
1980 WARN_ONCE(1, "regmap API is disabled");
1983 static inline void regcache_cache_bypass(struct regmap *map, bool enable)
1985 WARN_ONCE(1, "regmap API is disabled");
1988 static inline void regcache_mark_dirty(struct regmap *map)
1990 WARN_ONCE(1, "regmap API is disabled");
1993 static inline void regmap_async_complete(struct regmap *map)
1995 WARN_ONCE(1, "regmap API is disabled");
1998 static inline int regmap_register_patch(struct regmap *map,
1999 const struct reg_sequence *regs,
2002 WARN_ONCE(1, "regmap API is disabled");
2006 static inline int regmap_parse_val(struct regmap *map, const void *buf,
2009 WARN_ONCE(1, "regmap API is disabled");
2013 static inline struct regmap *dev_get_regmap(struct device *dev,
2019 static inline struct device *regmap_get_device(struct regmap *map)
2021 WARN_ONCE(1, "regmap API is disabled");