1 #ifndef __LINUX_REGMAP_H
2 #define __LINUX_REGMAP_H
5 * Register map access API
7 * Copyright 2011 Wolfson Microelectronics plc
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
16 #include <linux/list.h>
17 #include <linux/rbtree.h>
18 #include <linux/ktime.h>
19 #include <linux/delay.h>
20 #include <linux/err.h>
21 #include <linux/bug.h>
22 #include <linux/lockdep.h>
33 struct regmap_range_cfg;
38 /* An enum of all the supported cache types */
47 * struct reg_default - Default value for a register.
49 * @reg: Register address.
50 * @def: Register default value.
52 * We use an array of structs rather than a simple array as many modern devices
53 * have very sparse register maps.
61 * struct reg_sequence - An individual write from a sequence of writes.
63 * @reg: Register address.
64 * @def: Register value.
65 * @delay_us: Delay to be applied after the register write in microseconds
67 * Register/value pairs for sequences of writes with an optional delay in
68 * microseconds to be applied after each write.
73 unsigned int delay_us;
76 #define regmap_update_bits(map, reg, mask, val) \
77 regmap_update_bits_base(map, reg, mask, val, NULL, false, false)
78 #define regmap_update_bits_async(map, reg, mask, val)\
79 regmap_update_bits_base(map, reg, mask, val, NULL, true, false)
80 #define regmap_update_bits_check(map, reg, mask, val, change)\
81 regmap_update_bits_base(map, reg, mask, val, change, false, false)
82 #define regmap_update_bits_check_async(map, reg, mask, val, change)\
83 regmap_update_bits_base(map, reg, mask, val, change, true, false)
85 #define regmap_write_bits(map, reg, mask, val) \
86 regmap_update_bits_base(map, reg, mask, val, NULL, false, true)
88 #define regmap_field_write(field, val) \
89 regmap_field_update_bits_base(field, ~0, val, NULL, false, false)
90 #define regmap_field_force_write(field, val) \
91 regmap_field_update_bits_base(field, ~0, val, NULL, false, true)
92 #define regmap_field_update_bits(field, mask, val)\
93 regmap_field_update_bits_base(field, mask, val, NULL, false, false)
94 #define regmap_field_force_update_bits(field, mask, val) \
95 regmap_field_update_bits_base(field, mask, val, NULL, false, true)
97 #define regmap_fields_write(field, id, val) \
98 regmap_fields_update_bits_base(field, id, ~0, val, NULL, false, false)
99 #define regmap_fields_force_write(field, id, val) \
100 regmap_fields_update_bits_base(field, id, ~0, val, NULL, false, true)
101 #define regmap_fields_update_bits(field, id, mask, val)\
102 regmap_fields_update_bits_base(field, id, mask, val, NULL, false, false)
103 #define regmap_fields_force_update_bits(field, id, mask, val) \
104 regmap_fields_update_bits_base(field, id, mask, val, NULL, false, true)
107 * regmap_read_poll_timeout - Poll until a condition is met or a timeout occurs
109 * @map: Regmap to read from
110 * @addr: Address to poll
111 * @val: Unsigned integer variable to read the value into
112 * @cond: Break condition (usually involving @val)
113 * @sleep_us: Maximum time to sleep between reads in us (0
114 * tight-loops). Should be less than ~20ms since usleep_range
115 * is used (see Documentation/timers/timers-howto.txt).
116 * @timeout_us: Timeout in us, 0 means never timeout
118 * Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_read
119 * error return value in case of a error read. In the two former cases,
120 * the last read value at @addr is stored in @val. Must not be called
121 * from atomic context if sleep_us or timeout_us are used.
123 * This is modelled after the readx_poll_timeout macros in linux/iopoll.h.
125 #define regmap_read_poll_timeout(map, addr, val, cond, sleep_us, timeout_us) \
127 u64 __timeout_us = (timeout_us); \
128 unsigned long __sleep_us = (sleep_us); \
129 ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \
131 might_sleep_if(__sleep_us); \
133 __ret = regmap_read((map), (addr), &(val)); \
138 if ((__timeout_us) && \
139 ktime_compare(ktime_get(), __timeout) > 0) { \
140 __ret = regmap_read((map), (addr), &(val)); \
144 usleep_range((__sleep_us >> 2) + 1, __sleep_us); \
146 __ret ?: ((cond) ? 0 : -ETIMEDOUT); \
150 * regmap_field_read_poll_timeout - Poll until a condition is met or timeout
152 * @field: Regmap field to read from
153 * @val: Unsigned integer variable to read the value into
154 * @cond: Break condition (usually involving @val)
155 * @sleep_us: Maximum time to sleep between reads in us (0
156 * tight-loops). Should be less than ~20ms since usleep_range
157 * is used (see Documentation/timers/timers-howto.txt).
158 * @timeout_us: Timeout in us, 0 means never timeout
160 * Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_field_read
161 * error return value in case of a error read. In the two former cases,
162 * the last read value at @addr is stored in @val. Must not be called
163 * from atomic context if sleep_us or timeout_us are used.
165 * This is modelled after the readx_poll_timeout macros in linux/iopoll.h.
167 #define regmap_field_read_poll_timeout(field, val, cond, sleep_us, timeout_us) \
169 u64 __timeout_us = (timeout_us); \
170 unsigned long __sleep_us = (sleep_us); \
171 ktime_t timeout = ktime_add_us(ktime_get(), __timeout_us); \
173 might_sleep_if(__sleep_us); \
175 pollret = regmap_field_read((field), &(val)); \
180 if (__timeout_us && ktime_compare(ktime_get(), timeout) > 0) { \
181 pollret = regmap_field_read((field), &(val)); \
185 usleep_range((__sleep_us >> 2) + 1, __sleep_us); \
187 pollret ?: ((cond) ? 0 : -ETIMEDOUT); \
193 /* Unspecified -> 0 -> Backwards compatible default */
194 REGMAP_ENDIAN_DEFAULT = 0,
196 REGMAP_ENDIAN_LITTLE,
197 REGMAP_ENDIAN_NATIVE,
201 * struct regmap_range - A register range, used for access related checks
202 * (readable/writeable/volatile/precious checks)
204 * @range_min: address of first register
205 * @range_max: address of last register
207 struct regmap_range {
208 unsigned int range_min;
209 unsigned int range_max;
212 #define regmap_reg_range(low, high) { .range_min = low, .range_max = high, }
215 * struct regmap_access_table - A table of register ranges for access checks
217 * @yes_ranges : pointer to an array of regmap ranges used as "yes ranges"
218 * @n_yes_ranges: size of the above array
219 * @no_ranges: pointer to an array of regmap ranges used as "no ranges"
220 * @n_no_ranges: size of the above array
222 * A table of ranges including some yes ranges and some no ranges.
223 * If a register belongs to a no_range, the corresponding check function
224 * will return false. If a register belongs to a yes range, the corresponding
225 * check function will return true. "no_ranges" are searched first.
227 struct regmap_access_table {
228 const struct regmap_range *yes_ranges;
229 unsigned int n_yes_ranges;
230 const struct regmap_range *no_ranges;
231 unsigned int n_no_ranges;
234 typedef void (*regmap_lock)(void *);
235 typedef void (*regmap_unlock)(void *);
238 * struct regmap_config - Configuration for the register map of a device.
240 * @name: Optional name of the regmap. Useful when a device has multiple
243 * @reg_bits: Number of bits in a register address, mandatory.
244 * @reg_stride: The register address stride. Valid register addresses are a
245 * multiple of this value. If set to 0, a value of 1 will be
247 * @pad_bits: Number of bits of padding between register and value.
248 * @val_bits: Number of bits in a register value, mandatory.
250 * @writeable_reg: Optional callback returning true if the register
251 * can be written to. If this field is NULL but wr_table
252 * (see below) is not, the check is performed on such table
253 * (a register is writeable if it belongs to one of the ranges
254 * specified by wr_table).
255 * @readable_reg: Optional callback returning true if the register
256 * can be read from. If this field is NULL but rd_table
257 * (see below) is not, the check is performed on such table
258 * (a register is readable if it belongs to one of the ranges
259 * specified by rd_table).
260 * @volatile_reg: Optional callback returning true if the register
261 * value can't be cached. If this field is NULL but
262 * volatile_table (see below) is not, the check is performed on
263 * such table (a register is volatile if it belongs to one of
264 * the ranges specified by volatile_table).
265 * @precious_reg: Optional callback returning true if the register
266 * should not be read outside of a call from the driver
267 * (e.g., a clear on read interrupt status register). If this
268 * field is NULL but precious_table (see below) is not, the
269 * check is performed on such table (a register is precious if
270 * it belongs to one of the ranges specified by precious_table).
271 * @disable_locking: This regmap is either protected by external means or
272 * is guaranteed not be be accessed from multiple threads.
273 * Don't use any locking mechanisms.
274 * @lock: Optional lock callback (overrides regmap's default lock
275 * function, based on spinlock or mutex).
276 * @unlock: As above for unlocking.
277 * @lock_arg: this field is passed as the only argument of lock/unlock
278 * functions (ignored in case regular lock/unlock functions
279 * are not overridden).
280 * @reg_read: Optional callback that if filled will be used to perform
281 * all the reads from the registers. Should only be provided for
282 * devices whose read operation cannot be represented as a simple
283 * read operation on a bus such as SPI, I2C, etc. Most of the
284 * devices do not need this.
285 * @reg_write: Same as above for writing.
286 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
287 * to perform locking. This field is ignored if custom lock/unlock
288 * functions are used (see fields lock/unlock of struct regmap_config).
289 * This field is a duplicate of a similar file in
290 * 'struct regmap_bus' and serves exact same purpose.
291 * Use it only for "no-bus" cases.
292 * @max_register: Optional, specifies the maximum valid register address.
293 * @wr_table: Optional, points to a struct regmap_access_table specifying
294 * valid ranges for write access.
295 * @rd_table: As above, for read access.
296 * @volatile_table: As above, for volatile registers.
297 * @precious_table: As above, for precious registers.
298 * @reg_defaults: Power on reset values for registers (for use with
299 * register cache support).
300 * @num_reg_defaults: Number of elements in reg_defaults.
302 * @read_flag_mask: Mask to be set in the top bytes of the register when doing
304 * @write_flag_mask: Mask to be set in the top bytes of the register when doing
305 * a write. If both read_flag_mask and write_flag_mask are
306 * empty and zero_flag_mask is not set the regmap_bus default
308 * @zero_flag_mask: If set, read_flag_mask and write_flag_mask are used even
309 * if they are both empty.
310 * @use_single_rw: If set, converts the bulk read and write operations into
311 * a series of single read and write operations. This is useful
312 * for device that does not support bulk read and write.
313 * @can_multi_write: If set, the device supports the multi write mode of bulk
314 * write operations, if clear multi write requests will be
315 * split into individual write operations
317 * @cache_type: The actual cache type.
318 * @reg_defaults_raw: Power on reset values for registers (for use with
319 * register cache support).
320 * @num_reg_defaults_raw: Number of elements in reg_defaults_raw.
321 * @reg_format_endian: Endianness for formatted register addresses. If this is
322 * DEFAULT, the @reg_format_endian_default value from the
323 * regmap bus is used.
324 * @val_format_endian: Endianness for formatted register values. If this is
325 * DEFAULT, the @reg_format_endian_default value from the
326 * regmap bus is used.
328 * @ranges: Array of configuration entries for virtual address ranges.
329 * @num_ranges: Number of range configuration entries.
330 * @use_hwlock: Indicate if a hardware spinlock should be used.
331 * @hwlock_id: Specify the hardware spinlock id.
332 * @hwlock_mode: The hardware spinlock mode, should be HWLOCK_IRQSTATE,
335 struct regmap_config {
343 bool (*writeable_reg)(struct device *dev, unsigned int reg);
344 bool (*readable_reg)(struct device *dev, unsigned int reg);
345 bool (*volatile_reg)(struct device *dev, unsigned int reg);
346 bool (*precious_reg)(struct device *dev, unsigned int reg);
348 bool disable_locking;
350 regmap_unlock unlock;
353 int (*reg_read)(void *context, unsigned int reg, unsigned int *val);
354 int (*reg_write)(void *context, unsigned int reg, unsigned int val);
358 unsigned int max_register;
359 const struct regmap_access_table *wr_table;
360 const struct regmap_access_table *rd_table;
361 const struct regmap_access_table *volatile_table;
362 const struct regmap_access_table *precious_table;
363 const struct reg_default *reg_defaults;
364 unsigned int num_reg_defaults;
365 enum regcache_type cache_type;
366 const void *reg_defaults_raw;
367 unsigned int num_reg_defaults_raw;
369 unsigned long read_flag_mask;
370 unsigned long write_flag_mask;
374 bool can_multi_write;
376 enum regmap_endian reg_format_endian;
377 enum regmap_endian val_format_endian;
379 const struct regmap_range_cfg *ranges;
380 unsigned int num_ranges;
383 unsigned int hwlock_id;
384 unsigned int hwlock_mode;
388 * struct regmap_range_cfg - Configuration for indirectly accessed or paged
391 * @name: Descriptive name for diagnostics
393 * @range_min: Address of the lowest register address in virtual range.
394 * @range_max: Address of the highest register in virtual range.
396 * @selector_reg: Register with selector field.
397 * @selector_mask: Bit shift for selector value.
398 * @selector_shift: Bit mask for selector value.
400 * @window_start: Address of first (lowest) register in data window.
401 * @window_len: Number of registers in data window.
403 * Registers, mapped to this virtual range, are accessed in two steps:
404 * 1. page selector register update;
405 * 2. access through data window registers.
407 struct regmap_range_cfg {
410 /* Registers of virtual address range */
411 unsigned int range_min;
412 unsigned int range_max;
414 /* Page selector for indirect addressing */
415 unsigned int selector_reg;
416 unsigned int selector_mask;
419 /* Data window (per each page) */
420 unsigned int window_start;
421 unsigned int window_len;
426 typedef int (*regmap_hw_write)(void *context, const void *data,
428 typedef int (*regmap_hw_gather_write)(void *context,
429 const void *reg, size_t reg_len,
430 const void *val, size_t val_len);
431 typedef int (*regmap_hw_async_write)(void *context,
432 const void *reg, size_t reg_len,
433 const void *val, size_t val_len,
434 struct regmap_async *async);
435 typedef int (*regmap_hw_read)(void *context,
436 const void *reg_buf, size_t reg_size,
437 void *val_buf, size_t val_size);
438 typedef int (*regmap_hw_reg_read)(void *context, unsigned int reg,
440 typedef int (*regmap_hw_reg_write)(void *context, unsigned int reg,
442 typedef int (*regmap_hw_reg_update_bits)(void *context, unsigned int reg,
443 unsigned int mask, unsigned int val);
444 typedef struct regmap_async *(*regmap_hw_async_alloc)(void);
445 typedef void (*regmap_hw_free_context)(void *context);
448 * struct regmap_bus - Description of a hardware bus for the register map
451 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
452 * to perform locking. This field is ignored if custom lock/unlock
453 * functions are used (see fields lock/unlock of
454 * struct regmap_config).
455 * @write: Write operation.
456 * @gather_write: Write operation with split register/value, return -ENOTSUPP
457 * if not implemented on a given device.
458 * @async_write: Write operation which completes asynchronously, optional and
459 * must serialise with respect to non-async I/O.
460 * @reg_write: Write a single register value to the given register address. This
461 * write operation has to complete when returning from the function.
462 * @reg_update_bits: Update bits operation to be used against volatile
463 * registers, intended for devices supporting some mechanism
464 * for setting clearing bits without having to
466 * @read: Read operation. Data is returned in the buffer used to transmit
468 * @reg_read: Read a single register value from a given register address.
469 * @free_context: Free context.
470 * @async_alloc: Allocate a regmap_async() structure.
471 * @read_flag_mask: Mask to be set in the top byte of the register when doing
473 * @reg_format_endian_default: Default endianness for formatted register
474 * addresses. Used when the regmap_config specifies DEFAULT. If this is
475 * DEFAULT, BIG is assumed.
476 * @val_format_endian_default: Default endianness for formatted register
477 * values. Used when the regmap_config specifies DEFAULT. If this is
478 * DEFAULT, BIG is assumed.
479 * @max_raw_read: Max raw read size that can be used on the bus.
480 * @max_raw_write: Max raw write size that can be used on the bus.
484 regmap_hw_write write;
485 regmap_hw_gather_write gather_write;
486 regmap_hw_async_write async_write;
487 regmap_hw_reg_write reg_write;
488 regmap_hw_reg_update_bits reg_update_bits;
490 regmap_hw_reg_read reg_read;
491 regmap_hw_free_context free_context;
492 regmap_hw_async_alloc async_alloc;
494 enum regmap_endian reg_format_endian_default;
495 enum regmap_endian val_format_endian_default;
497 size_t max_raw_write;
501 * __regmap_init functions.
503 * These functions take a lock key and name parameter, and should not be called
504 * directly. Instead, use the regmap_init macros that generate a key and name
507 struct regmap *__regmap_init(struct device *dev,
508 const struct regmap_bus *bus,
510 const struct regmap_config *config,
511 struct lock_class_key *lock_key,
512 const char *lock_name);
513 struct regmap *__regmap_init_i2c(struct i2c_client *i2c,
514 const struct regmap_config *config,
515 struct lock_class_key *lock_key,
516 const char *lock_name);
517 struct regmap *__regmap_init_slimbus(struct slim_device *slimbus,
518 const struct regmap_config *config,
519 struct lock_class_key *lock_key,
520 const char *lock_name);
521 struct regmap *__regmap_init_spi(struct spi_device *dev,
522 const struct regmap_config *config,
523 struct lock_class_key *lock_key,
524 const char *lock_name);
525 struct regmap *__regmap_init_spmi_base(struct spmi_device *dev,
526 const struct regmap_config *config,
527 struct lock_class_key *lock_key,
528 const char *lock_name);
529 struct regmap *__regmap_init_spmi_ext(struct spmi_device *dev,
530 const struct regmap_config *config,
531 struct lock_class_key *lock_key,
532 const char *lock_name);
533 struct regmap *__regmap_init_w1(struct device *w1_dev,
534 const struct regmap_config *config,
535 struct lock_class_key *lock_key,
536 const char *lock_name);
537 struct regmap *__regmap_init_mmio_clk(struct device *dev, const char *clk_id,
539 const struct regmap_config *config,
540 struct lock_class_key *lock_key,
541 const char *lock_name);
542 struct regmap *__regmap_init_ac97(struct snd_ac97 *ac97,
543 const struct regmap_config *config,
544 struct lock_class_key *lock_key,
545 const char *lock_name);
546 struct regmap *__regmap_init_sdw(struct sdw_slave *sdw,
547 const struct regmap_config *config,
548 struct lock_class_key *lock_key,
549 const char *lock_name);
551 struct regmap *__devm_regmap_init(struct device *dev,
552 const struct regmap_bus *bus,
554 const struct regmap_config *config,
555 struct lock_class_key *lock_key,
556 const char *lock_name);
557 struct regmap *__devm_regmap_init_i2c(struct i2c_client *i2c,
558 const struct regmap_config *config,
559 struct lock_class_key *lock_key,
560 const char *lock_name);
561 struct regmap *__devm_regmap_init_spi(struct spi_device *dev,
562 const struct regmap_config *config,
563 struct lock_class_key *lock_key,
564 const char *lock_name);
565 struct regmap *__devm_regmap_init_spmi_base(struct spmi_device *dev,
566 const struct regmap_config *config,
567 struct lock_class_key *lock_key,
568 const char *lock_name);
569 struct regmap *__devm_regmap_init_spmi_ext(struct spmi_device *dev,
570 const struct regmap_config *config,
571 struct lock_class_key *lock_key,
572 const char *lock_name);
573 struct regmap *__devm_regmap_init_w1(struct device *w1_dev,
574 const struct regmap_config *config,
575 struct lock_class_key *lock_key,
576 const char *lock_name);
577 struct regmap *__devm_regmap_init_mmio_clk(struct device *dev,
580 const struct regmap_config *config,
581 struct lock_class_key *lock_key,
582 const char *lock_name);
583 struct regmap *__devm_regmap_init_ac97(struct snd_ac97 *ac97,
584 const struct regmap_config *config,
585 struct lock_class_key *lock_key,
586 const char *lock_name);
587 struct regmap *__devm_regmap_init_sdw(struct sdw_slave *sdw,
588 const struct regmap_config *config,
589 struct lock_class_key *lock_key,
590 const char *lock_name);
591 struct regmap *__devm_regmap_init_slimbus(struct slim_device *slimbus,
592 const struct regmap_config *config,
593 struct lock_class_key *lock_key,
594 const char *lock_name);
596 * Wrapper for regmap_init macros to include a unique lockdep key and name
597 * for each call. No-op if CONFIG_LOCKDEP is not set.
599 * @fn: Real function to call (in the form __[*_]regmap_init[_*])
600 * @name: Config variable name (#config in the calling macro)
602 #ifdef CONFIG_LOCKDEP
603 #define __regmap_lockdep_wrapper(fn, name, ...) \
606 static struct lock_class_key _key; \
607 fn(__VA_ARGS__, &_key, \
608 KBUILD_BASENAME ":" \
609 __stringify(__LINE__) ":" \
610 "(" name ")->lock"); \
614 #define __regmap_lockdep_wrapper(fn, name, ...) fn(__VA_ARGS__, NULL, NULL)
618 * regmap_init() - Initialise register map
620 * @dev: Device that will be interacted with
621 * @bus: Bus-specific callbacks to use with device
622 * @bus_context: Data passed to bus-specific callbacks
623 * @config: Configuration for register map
625 * The return value will be an ERR_PTR() on error or a valid pointer to
626 * a struct regmap. This function should generally not be called
627 * directly, it should be called by bus-specific init functions.
629 #define regmap_init(dev, bus, bus_context, config) \
630 __regmap_lockdep_wrapper(__regmap_init, #config, \
631 dev, bus, bus_context, config)
632 int regmap_attach_dev(struct device *dev, struct regmap *map,
633 const struct regmap_config *config);
636 * regmap_init_i2c() - Initialise register map
638 * @i2c: Device that will be interacted with
639 * @config: Configuration for register map
641 * The return value will be an ERR_PTR() on error or a valid pointer to
644 #define regmap_init_i2c(i2c, config) \
645 __regmap_lockdep_wrapper(__regmap_init_i2c, #config, \
649 * regmap_init_slimbus() - Initialise register map
651 * @slimbus: Device that will be interacted with
652 * @config: Configuration for register map
654 * The return value will be an ERR_PTR() on error or a valid pointer to
657 #define regmap_init_slimbus(slimbus, config) \
658 __regmap_lockdep_wrapper(__regmap_init_slimbus, #config, \
662 * regmap_init_spi() - Initialise register map
664 * @dev: Device that will be interacted with
665 * @config: Configuration for register map
667 * The return value will be an ERR_PTR() on error or a valid pointer to
670 #define regmap_init_spi(dev, config) \
671 __regmap_lockdep_wrapper(__regmap_init_spi, #config, \
675 * regmap_init_spmi_base() - Create regmap for the Base register space
677 * @dev: SPMI device that will be interacted with
678 * @config: Configuration for register map
680 * The return value will be an ERR_PTR() on error or a valid pointer to
683 #define regmap_init_spmi_base(dev, config) \
684 __regmap_lockdep_wrapper(__regmap_init_spmi_base, #config, \
688 * regmap_init_spmi_ext() - Create regmap for Ext register space
690 * @dev: Device that will be interacted with
691 * @config: Configuration for register map
693 * The return value will be an ERR_PTR() on error or a valid pointer to
696 #define regmap_init_spmi_ext(dev, config) \
697 __regmap_lockdep_wrapper(__regmap_init_spmi_ext, #config, \
701 * regmap_init_w1() - Initialise register map
703 * @w1_dev: Device that will be interacted with
704 * @config: Configuration for register map
706 * The return value will be an ERR_PTR() on error or a valid pointer to
709 #define regmap_init_w1(w1_dev, config) \
710 __regmap_lockdep_wrapper(__regmap_init_w1, #config, \
714 * regmap_init_mmio_clk() - Initialise register map with register clock
716 * @dev: Device that will be interacted with
717 * @clk_id: register clock consumer ID
718 * @regs: Pointer to memory-mapped IO region
719 * @config: Configuration for register map
721 * The return value will be an ERR_PTR() on error or a valid pointer to
724 #define regmap_init_mmio_clk(dev, clk_id, regs, config) \
725 __regmap_lockdep_wrapper(__regmap_init_mmio_clk, #config, \
726 dev, clk_id, regs, config)
729 * regmap_init_mmio() - Initialise register map
731 * @dev: Device that will be interacted with
732 * @regs: Pointer to memory-mapped IO region
733 * @config: Configuration for register map
735 * The return value will be an ERR_PTR() on error or a valid pointer to
738 #define regmap_init_mmio(dev, regs, config) \
739 regmap_init_mmio_clk(dev, NULL, regs, config)
742 * regmap_init_ac97() - Initialise AC'97 register map
744 * @ac97: Device that will be interacted with
745 * @config: Configuration for register map
747 * The return value will be an ERR_PTR() on error or a valid pointer to
750 #define regmap_init_ac97(ac97, config) \
751 __regmap_lockdep_wrapper(__regmap_init_ac97, #config, \
753 bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg);
756 * regmap_init_sdw() - Initialise register map
758 * @sdw: Device that will be interacted with
759 * @config: Configuration for register map
761 * The return value will be an ERR_PTR() on error or a valid pointer to
764 #define regmap_init_sdw(sdw, config) \
765 __regmap_lockdep_wrapper(__regmap_init_sdw, #config, \
770 * devm_regmap_init() - Initialise managed register map
772 * @dev: Device that will be interacted with
773 * @bus: Bus-specific callbacks to use with device
774 * @bus_context: Data passed to bus-specific callbacks
775 * @config: Configuration for register map
777 * The return value will be an ERR_PTR() on error or a valid pointer
778 * to a struct regmap. This function should generally not be called
779 * directly, it should be called by bus-specific init functions. The
780 * map will be automatically freed by the device management code.
782 #define devm_regmap_init(dev, bus, bus_context, config) \
783 __regmap_lockdep_wrapper(__devm_regmap_init, #config, \
784 dev, bus, bus_context, config)
787 * devm_regmap_init_i2c() - Initialise managed register map
789 * @i2c: Device that will be interacted with
790 * @config: Configuration for register map
792 * The return value will be an ERR_PTR() on error or a valid pointer
793 * to a struct regmap. The regmap will be automatically freed by the
794 * device management code.
796 #define devm_regmap_init_i2c(i2c, config) \
797 __regmap_lockdep_wrapper(__devm_regmap_init_i2c, #config, \
801 * devm_regmap_init_spi() - Initialise register map
803 * @dev: Device that will be interacted with
804 * @config: Configuration for register map
806 * The return value will be an ERR_PTR() on error or a valid pointer
807 * to a struct regmap. The map will be automatically freed by the
808 * device management code.
810 #define devm_regmap_init_spi(dev, config) \
811 __regmap_lockdep_wrapper(__devm_regmap_init_spi, #config, \
815 * devm_regmap_init_spmi_base() - Create managed regmap for Base register space
817 * @dev: SPMI 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
821 * to a struct regmap. The regmap will be automatically freed by the
822 * device management code.
824 #define devm_regmap_init_spmi_base(dev, config) \
825 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_base, #config, \
829 * devm_regmap_init_spmi_ext() - Create managed regmap for Ext register space
831 * @dev: SPMI device that will be interacted with
832 * @config: Configuration for register map
834 * The return value will be an ERR_PTR() on error or a valid pointer
835 * to a struct regmap. The regmap will be automatically freed by the
836 * device management code.
838 #define devm_regmap_init_spmi_ext(dev, config) \
839 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_ext, #config, \
843 * devm_regmap_init_w1() - Initialise managed register map
845 * @w1_dev: Device that will be interacted with
846 * @config: Configuration for register map
848 * The return value will be an ERR_PTR() on error or a valid pointer
849 * to a struct regmap. The regmap will be automatically freed by the
850 * device management code.
852 #define devm_regmap_init_w1(w1_dev, config) \
853 __regmap_lockdep_wrapper(__devm_regmap_init_w1, #config, \
856 * devm_regmap_init_mmio_clk() - Initialise managed register map with clock
858 * @dev: Device that will be interacted with
859 * @clk_id: register clock consumer ID
860 * @regs: Pointer to memory-mapped IO region
861 * @config: Configuration for register map
863 * The return value will be an ERR_PTR() on error or a valid pointer
864 * to a struct regmap. The regmap will be automatically freed by the
865 * device management code.
867 #define devm_regmap_init_mmio_clk(dev, clk_id, regs, config) \
868 __regmap_lockdep_wrapper(__devm_regmap_init_mmio_clk, #config, \
869 dev, clk_id, regs, config)
872 * devm_regmap_init_mmio() - Initialise managed register map
874 * @dev: Device that will be interacted with
875 * @regs: Pointer to memory-mapped IO region
876 * @config: Configuration for register map
878 * The return value will be an ERR_PTR() on error or a valid pointer
879 * to a struct regmap. The regmap will be automatically freed by the
880 * device management code.
882 #define devm_regmap_init_mmio(dev, regs, config) \
883 devm_regmap_init_mmio_clk(dev, NULL, regs, config)
886 * devm_regmap_init_ac97() - Initialise AC'97 register map
888 * @ac97: Device that will be interacted with
889 * @config: Configuration for register map
891 * The return value will be an ERR_PTR() on error or a valid pointer
892 * to a struct regmap. The regmap will be automatically freed by the
893 * device management code.
895 #define devm_regmap_init_ac97(ac97, config) \
896 __regmap_lockdep_wrapper(__devm_regmap_init_ac97, #config, \
900 * devm_regmap_init_sdw() - Initialise managed register map
902 * @sdw: Device that will be interacted with
903 * @config: Configuration for register map
905 * The return value will be an ERR_PTR() on error or a valid pointer
906 * to a struct regmap. The regmap will be automatically freed by the
907 * device management code.
909 #define devm_regmap_init_sdw(sdw, config) \
910 __regmap_lockdep_wrapper(__devm_regmap_init_sdw, #config, \
914 * devm_regmap_init_slimbus() - Initialise managed register map
916 * @slimbus: 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
920 * to a struct regmap. The regmap will be automatically freed by the
921 * device management code.
923 #define devm_regmap_init_slimbus(slimbus, config) \
924 __regmap_lockdep_wrapper(__devm_regmap_init_slimbus, #config, \
926 int regmap_mmio_attach_clk(struct regmap *map, struct clk *clk);
927 void regmap_mmio_detach_clk(struct regmap *map);
928 void regmap_exit(struct regmap *map);
929 int regmap_reinit_cache(struct regmap *map,
930 const struct regmap_config *config);
931 struct regmap *dev_get_regmap(struct device *dev, const char *name);
932 struct device *regmap_get_device(struct regmap *map);
933 int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
934 int regmap_write_async(struct regmap *map, unsigned int reg, unsigned int val);
935 int regmap_raw_write(struct regmap *map, unsigned int reg,
936 const void *val, size_t val_len);
937 int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
939 int regmap_multi_reg_write(struct regmap *map, const struct reg_sequence *regs,
941 int regmap_multi_reg_write_bypassed(struct regmap *map,
942 const struct reg_sequence *regs,
944 int regmap_raw_write_async(struct regmap *map, unsigned int reg,
945 const void *val, size_t val_len);
946 int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
947 int regmap_raw_read(struct regmap *map, unsigned int reg,
948 void *val, size_t val_len);
949 int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
951 int regmap_update_bits_base(struct regmap *map, unsigned int reg,
952 unsigned int mask, unsigned int val,
953 bool *change, bool async, bool force);
954 int regmap_get_val_bytes(struct regmap *map);
955 int regmap_get_max_register(struct regmap *map);
956 int regmap_get_reg_stride(struct regmap *map);
957 int regmap_async_complete(struct regmap *map);
958 bool regmap_can_raw_write(struct regmap *map);
959 size_t regmap_get_raw_read_max(struct regmap *map);
960 size_t regmap_get_raw_write_max(struct regmap *map);
962 int regcache_sync(struct regmap *map);
963 int regcache_sync_region(struct regmap *map, unsigned int min,
965 int regcache_drop_region(struct regmap *map, unsigned int min,
967 void regcache_cache_only(struct regmap *map, bool enable);
968 void regcache_cache_bypass(struct regmap *map, bool enable);
969 void regcache_mark_dirty(struct regmap *map);
971 bool regmap_check_range_table(struct regmap *map, unsigned int reg,
972 const struct regmap_access_table *table);
974 int regmap_register_patch(struct regmap *map, const struct reg_sequence *regs,
976 int regmap_parse_val(struct regmap *map, const void *buf,
979 static inline bool regmap_reg_in_range(unsigned int reg,
980 const struct regmap_range *range)
982 return reg >= range->range_min && reg <= range->range_max;
985 bool regmap_reg_in_ranges(unsigned int reg,
986 const struct regmap_range *ranges,
987 unsigned int nranges);
990 * struct reg_field - Description of an register field
992 * @reg: Offset of the register within the regmap bank
993 * @lsb: lsb of the register field.
994 * @msb: msb of the register field.
995 * @id_size: port size if it has some ports
996 * @id_offset: address offset for each ports
1002 unsigned int id_size;
1003 unsigned int id_offset;
1006 #define REG_FIELD(_reg, _lsb, _msb) { \
1012 struct regmap_field *regmap_field_alloc(struct regmap *regmap,
1013 struct reg_field reg_field);
1014 void regmap_field_free(struct regmap_field *field);
1016 struct regmap_field *devm_regmap_field_alloc(struct device *dev,
1017 struct regmap *regmap, struct reg_field reg_field);
1018 void devm_regmap_field_free(struct device *dev, struct regmap_field *field);
1020 int regmap_field_read(struct regmap_field *field, unsigned int *val);
1021 int regmap_field_update_bits_base(struct regmap_field *field,
1022 unsigned int mask, unsigned int val,
1023 bool *change, bool async, bool force);
1024 int regmap_fields_read(struct regmap_field *field, unsigned int id,
1026 int regmap_fields_update_bits_base(struct regmap_field *field, unsigned int id,
1027 unsigned int mask, unsigned int val,
1028 bool *change, bool async, bool force);
1031 * struct regmap_irq - Description of an IRQ for the generic regmap irq_chip.
1033 * @reg_offset: Offset of the status/mask register within the bank
1034 * @mask: Mask used to flag/control the register.
1035 * @type_reg_offset: Offset register for the irq type setting.
1036 * @type_rising_mask: Mask bit to configure RISING type irq.
1037 * @type_falling_mask: Mask bit to configure FALLING type irq.
1040 unsigned int reg_offset;
1042 unsigned int type_reg_offset;
1043 unsigned int type_rising_mask;
1044 unsigned int type_falling_mask;
1047 #define REGMAP_IRQ_REG(_irq, _off, _mask) \
1048 [_irq] = { .reg_offset = (_off), .mask = (_mask) }
1051 * struct regmap_irq_chip - Description of a generic regmap irq_chip.
1053 * @name: Descriptive name for IRQ controller.
1055 * @status_base: Base status register address.
1056 * @mask_base: Base mask register address.
1057 * @mask_writeonly: Base mask register is write only.
1058 * @unmask_base: Base unmask register address. for chips who have
1059 * separate mask and unmask registers
1060 * @ack_base: Base ack address. If zero then the chip is clear on read.
1061 * Using zero value is possible with @use_ack bit.
1062 * @wake_base: Base address for wake enables. If zero unsupported.
1063 * @type_base: Base address for irq type. If zero unsupported.
1064 * @irq_reg_stride: Stride to use for chips where registers are not contiguous.
1065 * @init_ack_masked: Ack all masked interrupts once during initalization.
1066 * @mask_invert: Inverted mask register: cleared bits are masked out.
1067 * @use_ack: Use @ack register even if it is zero.
1068 * @ack_invert: Inverted ack register: cleared bits for ack.
1069 * @wake_invert: Inverted wake register: cleared bits are wake enabled.
1070 * @type_invert: Invert the type flags.
1071 * @runtime_pm: Hold a runtime PM lock on the device when accessing it.
1073 * @num_regs: Number of registers in each control bank.
1074 * @irqs: Descriptors for individual IRQs. Interrupt numbers are
1075 * assigned based on the index in the array of the interrupt.
1076 * @num_irqs: Number of descriptors.
1077 * @num_type_reg: Number of type registers.
1078 * @type_reg_stride: Stride to use for chips where type registers are not
1080 * @handle_pre_irq: Driver specific callback to handle interrupt from device
1081 * before regmap_irq_handler process the interrupts.
1082 * @handle_post_irq: Driver specific callback to handle interrupt from device
1083 * after handling the interrupts in regmap_irq_handler().
1084 * @irq_drv_data: Driver specific IRQ data which is passed as parameter when
1085 * driver specific pre/post interrupt handler is called.
1087 * This is not intended to handle every possible interrupt controller, but
1088 * it should handle a substantial proportion of those that are found in the
1091 struct regmap_irq_chip {
1094 unsigned int status_base;
1095 unsigned int mask_base;
1096 unsigned int unmask_base;
1097 unsigned int ack_base;
1098 unsigned int wake_base;
1099 unsigned int type_base;
1100 unsigned int irq_reg_stride;
1101 bool mask_writeonly:1;
1102 bool init_ack_masked:1;
1112 const struct regmap_irq *irqs;
1116 unsigned int type_reg_stride;
1118 int (*handle_pre_irq)(void *irq_drv_data);
1119 int (*handle_post_irq)(void *irq_drv_data);
1123 struct regmap_irq_chip_data;
1125 int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
1126 int irq_base, const struct regmap_irq_chip *chip,
1127 struct regmap_irq_chip_data **data);
1128 void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data);
1130 int devm_regmap_add_irq_chip(struct device *dev, struct regmap *map, int irq,
1131 int irq_flags, int irq_base,
1132 const struct regmap_irq_chip *chip,
1133 struct regmap_irq_chip_data **data);
1134 void devm_regmap_del_irq_chip(struct device *dev, int irq,
1135 struct regmap_irq_chip_data *data);
1137 int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data);
1138 int regmap_irq_get_virq(struct regmap_irq_chip_data *data, int irq);
1139 struct irq_domain *regmap_irq_get_domain(struct regmap_irq_chip_data *data);
1144 * These stubs should only ever be called by generic code which has
1145 * regmap based facilities, if they ever get called at runtime
1146 * something is going wrong and something probably needs to select
1150 static inline int regmap_write(struct regmap *map, unsigned int reg,
1153 WARN_ONCE(1, "regmap API is disabled");
1157 static inline int regmap_write_async(struct regmap *map, unsigned int reg,
1160 WARN_ONCE(1, "regmap API is disabled");
1164 static inline int regmap_raw_write(struct regmap *map, unsigned int reg,
1165 const void *val, size_t val_len)
1167 WARN_ONCE(1, "regmap API is disabled");
1171 static inline int regmap_raw_write_async(struct regmap *map, unsigned int reg,
1172 const void *val, size_t val_len)
1174 WARN_ONCE(1, "regmap API is disabled");
1178 static inline int regmap_bulk_write(struct regmap *map, unsigned int reg,
1179 const void *val, size_t val_count)
1181 WARN_ONCE(1, "regmap API is disabled");
1185 static inline int regmap_read(struct regmap *map, unsigned int reg,
1188 WARN_ONCE(1, "regmap API is disabled");
1192 static inline int regmap_raw_read(struct regmap *map, unsigned int reg,
1193 void *val, size_t val_len)
1195 WARN_ONCE(1, "regmap API is disabled");
1199 static inline int regmap_bulk_read(struct regmap *map, unsigned int reg,
1200 void *val, size_t val_count)
1202 WARN_ONCE(1, "regmap API is disabled");
1206 static inline int regmap_update_bits_base(struct regmap *map, unsigned int reg,
1207 unsigned int mask, unsigned int val,
1208 bool *change, bool async, bool force)
1210 WARN_ONCE(1, "regmap API is disabled");
1214 static inline int regmap_field_update_bits_base(struct regmap_field *field,
1215 unsigned int mask, unsigned int val,
1216 bool *change, bool async, bool force)
1218 WARN_ONCE(1, "regmap API is disabled");
1222 static inline int regmap_fields_update_bits_base(struct regmap_field *field,
1224 unsigned int mask, unsigned int val,
1225 bool *change, bool async, bool force)
1227 WARN_ONCE(1, "regmap API is disabled");
1231 static inline int regmap_get_val_bytes(struct regmap *map)
1233 WARN_ONCE(1, "regmap API is disabled");
1237 static inline int regmap_get_max_register(struct regmap *map)
1239 WARN_ONCE(1, "regmap API is disabled");
1243 static inline int regmap_get_reg_stride(struct regmap *map)
1245 WARN_ONCE(1, "regmap API is disabled");
1249 static inline int regcache_sync(struct regmap *map)
1251 WARN_ONCE(1, "regmap API is disabled");
1255 static inline int regcache_sync_region(struct regmap *map, unsigned int min,
1258 WARN_ONCE(1, "regmap API is disabled");
1262 static inline int regcache_drop_region(struct regmap *map, unsigned int min,
1265 WARN_ONCE(1, "regmap API is disabled");
1269 static inline void regcache_cache_only(struct regmap *map, bool enable)
1271 WARN_ONCE(1, "regmap API is disabled");
1274 static inline void regcache_cache_bypass(struct regmap *map, bool enable)
1276 WARN_ONCE(1, "regmap API is disabled");
1279 static inline void regcache_mark_dirty(struct regmap *map)
1281 WARN_ONCE(1, "regmap API is disabled");
1284 static inline void regmap_async_complete(struct regmap *map)
1286 WARN_ONCE(1, "regmap API is disabled");
1289 static inline int regmap_register_patch(struct regmap *map,
1290 const struct reg_sequence *regs,
1293 WARN_ONCE(1, "regmap API is disabled");
1297 static inline int regmap_parse_val(struct regmap *map, const void *buf,
1300 WARN_ONCE(1, "regmap API is disabled");
1304 static inline struct regmap *dev_get_regmap(struct device *dev,
1310 static inline struct device *regmap_get_device(struct regmap *map)
1312 WARN_ONCE(1, "regmap API is disabled");