1 #ifndef __LINUX_REGMAP_H
2 #define __LINUX_REGMAP_H
5 * Register map access API
7 * Copyright 2011 Wolfson Microelectronics plc
9 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
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/delay.h>
19 #include <linux/err.h>
20 #include <linux/bug.h>
21 #include <linux/lockdep.h>
30 struct regmap_range_cfg;
34 /* An enum of all the supported cache types */
43 * struct reg_default - Default value for a register.
45 * @reg: Register address.
46 * @def: Register default value.
48 * We use an array of structs rather than a simple array as many modern devices
49 * have very sparse register maps.
57 * struct reg_sequence - An individual write from a sequence of writes.
59 * @reg: Register address.
60 * @def: Register value.
61 * @delay_us: Delay to be applied after the register write in microseconds
63 * Register/value pairs for sequences of writes with an optional delay in
64 * microseconds to be applied after each write.
69 unsigned int delay_us;
72 #define regmap_update_bits(map, reg, mask, val) \
73 regmap_update_bits_base(map, reg, mask, val, NULL, false, false)
74 #define regmap_update_bits_async(map, reg, mask, val)\
75 regmap_update_bits_base(map, reg, mask, val, NULL, true, false)
76 #define regmap_update_bits_check(map, reg, mask, val, change)\
77 regmap_update_bits_base(map, reg, mask, val, change, false, false)
78 #define regmap_update_bits_check_async(map, reg, mask, val, change)\
79 regmap_update_bits_base(map, reg, mask, val, change, true, false)
81 #define regmap_write_bits(map, reg, mask, val) \
82 regmap_update_bits_base(map, reg, mask, val, NULL, false, true)
84 #define regmap_field_write(field, val) \
85 regmap_field_update_bits_base(field, ~0, val, NULL, false, false)
86 #define regmap_field_force_write(field, val) \
87 regmap_field_update_bits_base(field, ~0, val, NULL, false, true)
88 #define regmap_field_update_bits(field, mask, val)\
89 regmap_field_update_bits_base(field, mask, val, NULL, false, false)
90 #define regmap_field_force_update_bits(field, mask, val) \
91 regmap_field_update_bits_base(field, mask, val, NULL, false, true)
93 #define regmap_fields_write(field, id, val) \
94 regmap_fields_update_bits_base(field, id, ~0, val, NULL, false, false)
95 #define regmap_fields_force_write(field, id, val) \
96 regmap_fields_update_bits_base(field, id, ~0, val, NULL, false, true)
97 #define regmap_fields_update_bits(field, id, mask, val)\
98 regmap_fields_update_bits_base(field, id, mask, val, NULL, false, false)
99 #define regmap_fields_force_update_bits(field, id, mask, val) \
100 regmap_fields_update_bits_base(field, id, mask, val, NULL, false, true)
103 * regmap_read_poll_timeout - Poll until a condition is met or a timeout occurs
105 * @map: Regmap to read from
106 * @addr: Address to poll
107 * @val: Unsigned integer variable to read the value into
108 * @cond: Break condition (usually involving @val)
109 * @sleep_us: Maximum time to sleep between reads in us (0
110 * tight-loops). Should be less than ~20ms since usleep_range
111 * is used (see Documentation/timers/timers-howto.txt).
112 * @timeout_us: Timeout in us, 0 means never timeout
114 * Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_read
115 * error return value in case of a error read. In the two former cases,
116 * the last read value at @addr is stored in @val. Must not be called
117 * from atomic context if sleep_us or timeout_us are used.
119 * This is modelled after the readx_poll_timeout macros in linux/iopoll.h.
121 #define regmap_read_poll_timeout(map, addr, val, cond, sleep_us, timeout_us) \
123 ktime_t __timeout = ktime_add_us(ktime_get(), timeout_us); \
125 might_sleep_if(sleep_us); \
127 __ret = regmap_read((map), (addr), &(val)); \
132 if ((timeout_us) && \
133 ktime_compare(ktime_get(), __timeout) > 0) { \
134 __ret = regmap_read((map), (addr), &(val)); \
138 usleep_range(((sleep_us) >> 2) + 1, sleep_us); \
140 __ret ?: ((cond) ? 0 : -ETIMEDOUT); \
146 /* Unspecified -> 0 -> Backwards compatible default */
147 REGMAP_ENDIAN_DEFAULT = 0,
149 REGMAP_ENDIAN_LITTLE,
150 REGMAP_ENDIAN_NATIVE,
154 * struct regmap_range - A register range, used for access related checks
155 * (readable/writeable/volatile/precious checks)
157 * @range_min: address of first register
158 * @range_max: address of last register
160 struct regmap_range {
161 unsigned int range_min;
162 unsigned int range_max;
165 #define regmap_reg_range(low, high) { .range_min = low, .range_max = high, }
168 * struct regmap_access_table - A table of register ranges for access checks
170 * @yes_ranges : pointer to an array of regmap ranges used as "yes ranges"
171 * @n_yes_ranges: size of the above array
172 * @no_ranges: pointer to an array of regmap ranges used as "no ranges"
173 * @n_no_ranges: size of the above array
175 * A table of ranges including some yes ranges and some no ranges.
176 * If a register belongs to a no_range, the corresponding check function
177 * will return false. If a register belongs to a yes range, the corresponding
178 * check function will return true. "no_ranges" are searched first.
180 struct regmap_access_table {
181 const struct regmap_range *yes_ranges;
182 unsigned int n_yes_ranges;
183 const struct regmap_range *no_ranges;
184 unsigned int n_no_ranges;
187 typedef void (*regmap_lock)(void *);
188 typedef void (*regmap_unlock)(void *);
191 * struct regmap_config - Configuration for the register map of a device.
193 * @name: Optional name of the regmap. Useful when a device has multiple
196 * @reg_bits: Number of bits in a register address, mandatory.
197 * @reg_stride: The register address stride. Valid register addresses are a
198 * multiple of this value. If set to 0, a value of 1 will be
200 * @pad_bits: Number of bits of padding between register and value.
201 * @val_bits: Number of bits in a register value, mandatory.
203 * @writeable_reg: Optional callback returning true if the register
204 * can be written to. If this field is NULL but wr_table
205 * (see below) is not, the check is performed on such table
206 * (a register is writeable if it belongs to one of the ranges
207 * specified by wr_table).
208 * @readable_reg: Optional callback returning true if the register
209 * can be read from. If this field is NULL but rd_table
210 * (see below) is not, the check is performed on such table
211 * (a register is readable if it belongs to one of the ranges
212 * specified by rd_table).
213 * @volatile_reg: Optional callback returning true if the register
214 * value can't be cached. If this field is NULL but
215 * volatile_table (see below) is not, the check is performed on
216 * such table (a register is volatile if it belongs to one of
217 * the ranges specified by volatile_table).
218 * @precious_reg: Optional callback returning true if the register
219 * should not be read outside of a call from the driver
220 * (e.g., a clear on read interrupt status register). If this
221 * field is NULL but precious_table (see below) is not, the
222 * check is performed on such table (a register is precious if
223 * it belongs to one of the ranges specified by precious_table).
224 * @lock: Optional lock callback (overrides regmap's default lock
225 * function, based on spinlock or mutex).
226 * @unlock: As above for unlocking.
227 * @lock_arg: this field is passed as the only argument of lock/unlock
228 * functions (ignored in case regular lock/unlock functions
229 * are not overridden).
230 * @reg_read: Optional callback that if filled will be used to perform
231 * all the reads from the registers. Should only be provided for
232 * devices whose read operation cannot be represented as a simple
233 * read operation on a bus such as SPI, I2C, etc. Most of the
234 * devices do not need this.
235 * @reg_write: Same as above for writing.
236 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
237 * to perform locking. This field is ignored if custom lock/unlock
238 * functions are used (see fields lock/unlock of struct regmap_config).
239 * This field is a duplicate of a similar file in
240 * 'struct regmap_bus' and serves exact same purpose.
241 * Use it only for "no-bus" cases.
242 * @max_register: Optional, specifies the maximum valid register address.
243 * @wr_table: Optional, points to a struct regmap_access_table specifying
244 * valid ranges for write access.
245 * @rd_table: As above, for read access.
246 * @volatile_table: As above, for volatile registers.
247 * @precious_table: As above, for precious registers.
248 * @reg_defaults: Power on reset values for registers (for use with
249 * register cache support).
250 * @num_reg_defaults: Number of elements in reg_defaults.
252 * @read_flag_mask: Mask to be set in the top bytes of the register when doing
254 * @write_flag_mask: Mask to be set in the top bytes of the register when doing
255 * a write. If both read_flag_mask and write_flag_mask are
256 * empty the regmap_bus default masks are used.
257 * @use_single_rw: If set, converts the bulk read and write operations into
258 * a series of single read and write operations. This is useful
259 * for device that does not support bulk read and write.
260 * @can_multi_write: If set, the device supports the multi write mode of bulk
261 * write operations, if clear multi write requests will be
262 * split into individual write operations
264 * @cache_type: The actual cache type.
265 * @reg_defaults_raw: Power on reset values for registers (for use with
266 * register cache support).
267 * @num_reg_defaults_raw: Number of elements in reg_defaults_raw.
268 * @reg_format_endian: Endianness for formatted register addresses. If this is
269 * DEFAULT, the @reg_format_endian_default value from the
270 * regmap bus is used.
271 * @val_format_endian: Endianness for formatted register values. If this is
272 * DEFAULT, the @reg_format_endian_default value from the
273 * regmap bus is used.
275 * @ranges: Array of configuration entries for virtual address ranges.
276 * @num_ranges: Number of range configuration entries.
278 struct regmap_config {
286 bool (*writeable_reg)(struct device *dev, unsigned int reg);
287 bool (*readable_reg)(struct device *dev, unsigned int reg);
288 bool (*volatile_reg)(struct device *dev, unsigned int reg);
289 bool (*precious_reg)(struct device *dev, unsigned int reg);
291 regmap_unlock unlock;
294 int (*reg_read)(void *context, unsigned int reg, unsigned int *val);
295 int (*reg_write)(void *context, unsigned int reg, unsigned int val);
299 unsigned int max_register;
300 const struct regmap_access_table *wr_table;
301 const struct regmap_access_table *rd_table;
302 const struct regmap_access_table *volatile_table;
303 const struct regmap_access_table *precious_table;
304 const struct reg_default *reg_defaults;
305 unsigned int num_reg_defaults;
306 enum regcache_type cache_type;
307 const void *reg_defaults_raw;
308 unsigned int num_reg_defaults_raw;
310 unsigned long read_flag_mask;
311 unsigned long write_flag_mask;
314 bool can_multi_write;
316 enum regmap_endian reg_format_endian;
317 enum regmap_endian val_format_endian;
319 const struct regmap_range_cfg *ranges;
320 unsigned int num_ranges;
324 * struct regmap_range_cfg - Configuration for indirectly accessed or paged
327 * @name: Descriptive name for diagnostics
329 * @range_min: Address of the lowest register address in virtual range.
330 * @range_max: Address of the highest register in virtual range.
332 * @selector_reg: Register with selector field.
333 * @selector_mask: Bit shift for selector value.
334 * @selector_shift: Bit mask for selector value.
336 * @window_start: Address of first (lowest) register in data window.
337 * @window_len: Number of registers in data window.
339 * Registers, mapped to this virtual range, are accessed in two steps:
340 * 1. page selector register update;
341 * 2. access through data window registers.
343 struct regmap_range_cfg {
346 /* Registers of virtual address range */
347 unsigned int range_min;
348 unsigned int range_max;
350 /* Page selector for indirect addressing */
351 unsigned int selector_reg;
352 unsigned int selector_mask;
355 /* Data window (per each page) */
356 unsigned int window_start;
357 unsigned int window_len;
362 typedef int (*regmap_hw_write)(void *context, const void *data,
364 typedef int (*regmap_hw_gather_write)(void *context,
365 const void *reg, size_t reg_len,
366 const void *val, size_t val_len);
367 typedef int (*regmap_hw_async_write)(void *context,
368 const void *reg, size_t reg_len,
369 const void *val, size_t val_len,
370 struct regmap_async *async);
371 typedef int (*regmap_hw_read)(void *context,
372 const void *reg_buf, size_t reg_size,
373 void *val_buf, size_t val_size);
374 typedef int (*regmap_hw_reg_read)(void *context, unsigned int reg,
376 typedef int (*regmap_hw_reg_write)(void *context, unsigned int reg,
378 typedef int (*regmap_hw_reg_update_bits)(void *context, unsigned int reg,
379 unsigned int mask, unsigned int val);
380 typedef struct regmap_async *(*regmap_hw_async_alloc)(void);
381 typedef void (*regmap_hw_free_context)(void *context);
384 * struct regmap_bus - Description of a hardware bus for the register map
387 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
388 * to perform locking. This field is ignored if custom lock/unlock
389 * functions are used (see fields lock/unlock of
390 * struct regmap_config).
391 * @write: Write operation.
392 * @gather_write: Write operation with split register/value, return -ENOTSUPP
393 * if not implemented on a given device.
394 * @async_write: Write operation which completes asynchronously, optional and
395 * must serialise with respect to non-async I/O.
396 * @reg_write: Write a single register value to the given register address. This
397 * write operation has to complete when returning from the function.
398 * @reg_update_bits: Update bits operation to be used against volatile
399 * registers, intended for devices supporting some mechanism
400 * for setting clearing bits without having to
402 * @read: Read operation. Data is returned in the buffer used to transmit
404 * @reg_read: Read a single register value from a given register address.
405 * @free_context: Free context.
406 * @async_alloc: Allocate a regmap_async() structure.
407 * @read_flag_mask: Mask to be set in the top byte of the register when doing
409 * @reg_format_endian_default: Default endianness for formatted register
410 * addresses. Used when the regmap_config specifies DEFAULT. If this is
411 * DEFAULT, BIG is assumed.
412 * @val_format_endian_default: Default endianness for formatted register
413 * values. Used when the regmap_config specifies DEFAULT. If this is
414 * DEFAULT, BIG is assumed.
415 * @max_raw_read: Max raw read size that can be used on the bus.
416 * @max_raw_write: Max raw write size that can be used on the bus.
420 regmap_hw_write write;
421 regmap_hw_gather_write gather_write;
422 regmap_hw_async_write async_write;
423 regmap_hw_reg_write reg_write;
424 regmap_hw_reg_update_bits reg_update_bits;
426 regmap_hw_reg_read reg_read;
427 regmap_hw_free_context free_context;
428 regmap_hw_async_alloc async_alloc;
430 enum regmap_endian reg_format_endian_default;
431 enum regmap_endian val_format_endian_default;
433 size_t max_raw_write;
437 * __regmap_init functions.
439 * These functions take a lock key and name parameter, and should not be called
440 * directly. Instead, use the regmap_init macros that generate a key and name
443 struct regmap *__regmap_init(struct device *dev,
444 const struct regmap_bus *bus,
446 const struct regmap_config *config,
447 struct lock_class_key *lock_key,
448 const char *lock_name);
449 struct regmap *__regmap_init_i2c(struct i2c_client *i2c,
450 const struct regmap_config *config,
451 struct lock_class_key *lock_key,
452 const char *lock_name);
453 struct regmap *__regmap_init_spi(struct spi_device *dev,
454 const struct regmap_config *config,
455 struct lock_class_key *lock_key,
456 const char *lock_name);
457 struct regmap *__regmap_init_spmi_base(struct spmi_device *dev,
458 const struct regmap_config *config,
459 struct lock_class_key *lock_key,
460 const char *lock_name);
461 struct regmap *__regmap_init_spmi_ext(struct spmi_device *dev,
462 const struct regmap_config *config,
463 struct lock_class_key *lock_key,
464 const char *lock_name);
465 struct regmap *__regmap_init_w1(struct device *w1_dev,
466 const struct regmap_config *config,
467 struct lock_class_key *lock_key,
468 const char *lock_name);
469 struct regmap *__regmap_init_mmio_clk(struct device *dev, const char *clk_id,
471 const struct regmap_config *config,
472 struct lock_class_key *lock_key,
473 const char *lock_name);
474 struct regmap *__regmap_init_ac97(struct snd_ac97 *ac97,
475 const struct regmap_config *config,
476 struct lock_class_key *lock_key,
477 const char *lock_name);
479 struct regmap *__devm_regmap_init(struct device *dev,
480 const struct regmap_bus *bus,
482 const struct regmap_config *config,
483 struct lock_class_key *lock_key,
484 const char *lock_name);
485 struct regmap *__devm_regmap_init_i2c(struct i2c_client *i2c,
486 const struct regmap_config *config,
487 struct lock_class_key *lock_key,
488 const char *lock_name);
489 struct regmap *__devm_regmap_init_spi(struct spi_device *dev,
490 const struct regmap_config *config,
491 struct lock_class_key *lock_key,
492 const char *lock_name);
493 struct regmap *__devm_regmap_init_spmi_base(struct spmi_device *dev,
494 const struct regmap_config *config,
495 struct lock_class_key *lock_key,
496 const char *lock_name);
497 struct regmap *__devm_regmap_init_spmi_ext(struct spmi_device *dev,
498 const struct regmap_config *config,
499 struct lock_class_key *lock_key,
500 const char *lock_name);
501 struct regmap *__devm_regmap_init_w1(struct device *w1_dev,
502 const struct regmap_config *config,
503 struct lock_class_key *lock_key,
504 const char *lock_name);
505 struct regmap *__devm_regmap_init_mmio_clk(struct device *dev,
508 const struct regmap_config *config,
509 struct lock_class_key *lock_key,
510 const char *lock_name);
511 struct regmap *__devm_regmap_init_ac97(struct snd_ac97 *ac97,
512 const struct regmap_config *config,
513 struct lock_class_key *lock_key,
514 const char *lock_name);
517 * Wrapper for regmap_init macros to include a unique lockdep key and name
518 * for each call. No-op if CONFIG_LOCKDEP is not set.
520 * @fn: Real function to call (in the form __[*_]regmap_init[_*])
521 * @name: Config variable name (#config in the calling macro)
523 #ifdef CONFIG_LOCKDEP
524 #define __regmap_lockdep_wrapper(fn, name, ...) \
527 static struct lock_class_key _key; \
528 fn(__VA_ARGS__, &_key, \
529 KBUILD_BASENAME ":" \
530 __stringify(__LINE__) ":" \
531 "(" name ")->lock"); \
535 #define __regmap_lockdep_wrapper(fn, name, ...) fn(__VA_ARGS__, NULL, NULL)
539 * regmap_init() - Initialise register map
541 * @dev: Device that will be interacted with
542 * @bus: Bus-specific callbacks to use with device
543 * @bus_context: Data passed to bus-specific callbacks
544 * @config: Configuration for register map
546 * The return value will be an ERR_PTR() on error or a valid pointer to
547 * a struct regmap. This function should generally not be called
548 * directly, it should be called by bus-specific init functions.
550 #define regmap_init(dev, bus, bus_context, config) \
551 __regmap_lockdep_wrapper(__regmap_init, #config, \
552 dev, bus, bus_context, config)
553 int regmap_attach_dev(struct device *dev, struct regmap *map,
554 const struct regmap_config *config);
557 * regmap_init_i2c() - Initialise register map
559 * @i2c: Device that will be interacted with
560 * @config: Configuration for register map
562 * The return value will be an ERR_PTR() on error or a valid pointer to
565 #define regmap_init_i2c(i2c, config) \
566 __regmap_lockdep_wrapper(__regmap_init_i2c, #config, \
570 * regmap_init_spi() - Initialise register map
572 * @dev: Device that will be interacted with
573 * @config: Configuration for register map
575 * The return value will be an ERR_PTR() on error or a valid pointer to
578 #define regmap_init_spi(dev, config) \
579 __regmap_lockdep_wrapper(__regmap_init_spi, #config, \
583 * regmap_init_spmi_base() - Create regmap for the Base register space
585 * @dev: SPMI device that will be interacted with
586 * @config: Configuration for register map
588 * The return value will be an ERR_PTR() on error or a valid pointer to
591 #define regmap_init_spmi_base(dev, config) \
592 __regmap_lockdep_wrapper(__regmap_init_spmi_base, #config, \
596 * regmap_init_spmi_ext() - Create regmap for Ext register space
598 * @dev: Device that will be interacted with
599 * @config: Configuration for register map
601 * The return value will be an ERR_PTR() on error or a valid pointer to
604 #define regmap_init_spmi_ext(dev, config) \
605 __regmap_lockdep_wrapper(__regmap_init_spmi_ext, #config, \
609 * regmap_init_w1() - Initialise register map
611 * @w1_dev: Device that will be interacted with
612 * @config: Configuration for register map
614 * The return value will be an ERR_PTR() on error or a valid pointer to
617 #define regmap_init_w1(w1_dev, config) \
618 __regmap_lockdep_wrapper(__regmap_init_w1, #config, \
622 * regmap_init_mmio_clk() - Initialise register map with register clock
624 * @dev: Device that will be interacted with
625 * @clk_id: register clock consumer ID
626 * @regs: Pointer to memory-mapped IO region
627 * @config: Configuration for register map
629 * The return value will be an ERR_PTR() on error or a valid pointer to
632 #define regmap_init_mmio_clk(dev, clk_id, regs, config) \
633 __regmap_lockdep_wrapper(__regmap_init_mmio_clk, #config, \
634 dev, clk_id, regs, config)
637 * regmap_init_mmio() - Initialise register map
639 * @dev: Device that will be interacted with
640 * @regs: Pointer to memory-mapped IO region
641 * @config: Configuration for register map
643 * The return value will be an ERR_PTR() on error or a valid pointer to
646 #define regmap_init_mmio(dev, regs, config) \
647 regmap_init_mmio_clk(dev, NULL, regs, config)
650 * regmap_init_ac97() - Initialise AC'97 register map
652 * @ac97: Device that will be interacted with
653 * @config: Configuration for register map
655 * The return value will be an ERR_PTR() on error or a valid pointer to
658 #define regmap_init_ac97(ac97, config) \
659 __regmap_lockdep_wrapper(__regmap_init_ac97, #config, \
661 bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg);
664 * devm_regmap_init() - Initialise managed register map
666 * @dev: Device that will be interacted with
667 * @bus: Bus-specific callbacks to use with device
668 * @bus_context: Data passed to bus-specific callbacks
669 * @config: Configuration for register map
671 * The return value will be an ERR_PTR() on error or a valid pointer
672 * to a struct regmap. This function should generally not be called
673 * directly, it should be called by bus-specific init functions. The
674 * map will be automatically freed by the device management code.
676 #define devm_regmap_init(dev, bus, bus_context, config) \
677 __regmap_lockdep_wrapper(__devm_regmap_init, #config, \
678 dev, bus, bus_context, config)
681 * devm_regmap_init_i2c() - Initialise managed register map
683 * @i2c: Device that will be interacted with
684 * @config: Configuration for register map
686 * The return value will be an ERR_PTR() on error or a valid pointer
687 * to a struct regmap. The regmap will be automatically freed by the
688 * device management code.
690 #define devm_regmap_init_i2c(i2c, config) \
691 __regmap_lockdep_wrapper(__devm_regmap_init_i2c, #config, \
695 * devm_regmap_init_spi() - Initialise register map
697 * @dev: Device that will be interacted with
698 * @config: Configuration for register map
700 * The return value will be an ERR_PTR() on error or a valid pointer
701 * to a struct regmap. The map will be automatically freed by the
702 * device management code.
704 #define devm_regmap_init_spi(dev, config) \
705 __regmap_lockdep_wrapper(__devm_regmap_init_spi, #config, \
709 * devm_regmap_init_spmi_base() - Create managed regmap for Base register space
711 * @dev: SPMI device that will be interacted with
712 * @config: Configuration for register map
714 * The return value will be an ERR_PTR() on error or a valid pointer
715 * to a struct regmap. The regmap will be automatically freed by the
716 * device management code.
718 #define devm_regmap_init_spmi_base(dev, config) \
719 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_base, #config, \
723 * devm_regmap_init_spmi_ext() - Create managed regmap for Ext register space
725 * @dev: SPMI device that will be interacted with
726 * @config: Configuration for register map
728 * The return value will be an ERR_PTR() on error or a valid pointer
729 * to a struct regmap. The regmap will be automatically freed by the
730 * device management code.
732 #define devm_regmap_init_spmi_ext(dev, config) \
733 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_ext, #config, \
737 * devm_regmap_init_w1() - Initialise managed register map
739 * @w1_dev: Device that will be interacted with
740 * @config: Configuration for register map
742 * The return value will be an ERR_PTR() on error or a valid pointer
743 * to a struct regmap. The regmap will be automatically freed by the
744 * device management code.
746 #define devm_regmap_init_w1(w1_dev, config) \
747 __regmap_lockdep_wrapper(__devm_regmap_init_w1, #config, \
750 * devm_regmap_init_mmio_clk() - Initialise managed register map with clock
752 * @dev: Device that will be interacted with
753 * @clk_id: register clock consumer ID
754 * @regs: Pointer to memory-mapped IO region
755 * @config: Configuration for register map
757 * The return value will be an ERR_PTR() on error or a valid pointer
758 * to a struct regmap. The regmap will be automatically freed by the
759 * device management code.
761 #define devm_regmap_init_mmio_clk(dev, clk_id, regs, config) \
762 __regmap_lockdep_wrapper(__devm_regmap_init_mmio_clk, #config, \
763 dev, clk_id, regs, config)
766 * devm_regmap_init_mmio() - Initialise managed register map
768 * @dev: Device that will be interacted with
769 * @regs: Pointer to memory-mapped IO region
770 * @config: Configuration for register map
772 * The return value will be an ERR_PTR() on error or a valid pointer
773 * to a struct regmap. The regmap will be automatically freed by the
774 * device management code.
776 #define devm_regmap_init_mmio(dev, regs, config) \
777 devm_regmap_init_mmio_clk(dev, NULL, regs, config)
780 * devm_regmap_init_ac97() - Initialise AC'97 register map
782 * @ac97: Device that will be interacted with
783 * @config: Configuration for register map
785 * The return value will be an ERR_PTR() on error or a valid pointer
786 * to a struct regmap. The regmap will be automatically freed by the
787 * device management code.
789 #define devm_regmap_init_ac97(ac97, config) \
790 __regmap_lockdep_wrapper(__devm_regmap_init_ac97, #config, \
793 void regmap_exit(struct regmap *map);
794 int regmap_reinit_cache(struct regmap *map,
795 const struct regmap_config *config);
796 struct regmap *dev_get_regmap(struct device *dev, const char *name);
797 struct device *regmap_get_device(struct regmap *map);
798 int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
799 int regmap_write_async(struct regmap *map, unsigned int reg, unsigned int val);
800 int regmap_raw_write(struct regmap *map, unsigned int reg,
801 const void *val, size_t val_len);
802 int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
804 int regmap_multi_reg_write(struct regmap *map, const struct reg_sequence *regs,
806 int regmap_multi_reg_write_bypassed(struct regmap *map,
807 const struct reg_sequence *regs,
809 int regmap_raw_write_async(struct regmap *map, unsigned int reg,
810 const void *val, size_t val_len);
811 int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
812 int regmap_raw_read(struct regmap *map, unsigned int reg,
813 void *val, size_t val_len);
814 int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
816 int regmap_update_bits_base(struct regmap *map, unsigned int reg,
817 unsigned int mask, unsigned int val,
818 bool *change, bool async, bool force);
819 int regmap_get_val_bytes(struct regmap *map);
820 int regmap_get_max_register(struct regmap *map);
821 int regmap_get_reg_stride(struct regmap *map);
822 int regmap_async_complete(struct regmap *map);
823 bool regmap_can_raw_write(struct regmap *map);
824 size_t regmap_get_raw_read_max(struct regmap *map);
825 size_t regmap_get_raw_write_max(struct regmap *map);
827 int regcache_sync(struct regmap *map);
828 int regcache_sync_region(struct regmap *map, unsigned int min,
830 int regcache_drop_region(struct regmap *map, unsigned int min,
832 void regcache_cache_only(struct regmap *map, bool enable);
833 void regcache_cache_bypass(struct regmap *map, bool enable);
834 void regcache_mark_dirty(struct regmap *map);
836 bool regmap_check_range_table(struct regmap *map, unsigned int reg,
837 const struct regmap_access_table *table);
839 int regmap_register_patch(struct regmap *map, const struct reg_sequence *regs,
841 int regmap_parse_val(struct regmap *map, const void *buf,
844 static inline bool regmap_reg_in_range(unsigned int reg,
845 const struct regmap_range *range)
847 return reg >= range->range_min && reg <= range->range_max;
850 bool regmap_reg_in_ranges(unsigned int reg,
851 const struct regmap_range *ranges,
852 unsigned int nranges);
855 * struct reg_field - Description of an register field
857 * @reg: Offset of the register within the regmap bank
858 * @lsb: lsb of the register field.
859 * @msb: msb of the register field.
860 * @id_size: port size if it has some ports
861 * @id_offset: address offset for each ports
867 unsigned int id_size;
868 unsigned int id_offset;
871 #define REG_FIELD(_reg, _lsb, _msb) { \
877 struct regmap_field *regmap_field_alloc(struct regmap *regmap,
878 struct reg_field reg_field);
879 void regmap_field_free(struct regmap_field *field);
881 struct regmap_field *devm_regmap_field_alloc(struct device *dev,
882 struct regmap *regmap, struct reg_field reg_field);
883 void devm_regmap_field_free(struct device *dev, struct regmap_field *field);
885 int regmap_field_read(struct regmap_field *field, unsigned int *val);
886 int regmap_field_update_bits_base(struct regmap_field *field,
887 unsigned int mask, unsigned int val,
888 bool *change, bool async, bool force);
889 int regmap_fields_read(struct regmap_field *field, unsigned int id,
891 int regmap_fields_update_bits_base(struct regmap_field *field, unsigned int id,
892 unsigned int mask, unsigned int val,
893 bool *change, bool async, bool force);
896 * struct regmap_irq - Description of an IRQ for the generic regmap irq_chip.
898 * @reg_offset: Offset of the status/mask register within the bank
899 * @mask: Mask used to flag/control the register.
900 * @type_reg_offset: Offset register for the irq type setting.
901 * @type_rising_mask: Mask bit to configure RISING type irq.
902 * @type_falling_mask: Mask bit to configure FALLING type irq.
905 unsigned int reg_offset;
907 unsigned int type_reg_offset;
908 unsigned int type_rising_mask;
909 unsigned int type_falling_mask;
912 #define REGMAP_IRQ_REG(_irq, _off, _mask) \
913 [_irq] = { .reg_offset = (_off), .mask = (_mask) }
916 * struct regmap_irq_chip - Description of a generic regmap irq_chip.
918 * @name: Descriptive name for IRQ controller.
920 * @status_base: Base status register address.
921 * @mask_base: Base mask register address.
922 * @mask_writeonly: Base mask register is write only.
923 * @unmask_base: Base unmask register address. for chips who have
924 * separate mask and unmask registers
925 * @ack_base: Base ack address. If zero then the chip is clear on read.
926 * Using zero value is possible with @use_ack bit.
927 * @wake_base: Base address for wake enables. If zero unsupported.
928 * @type_base: Base address for irq type. If zero unsupported.
929 * @irq_reg_stride: Stride to use for chips where registers are not contiguous.
930 * @init_ack_masked: Ack all masked interrupts once during initalization.
931 * @mask_invert: Inverted mask register: cleared bits are masked out.
932 * @use_ack: Use @ack register even if it is zero.
933 * @ack_invert: Inverted ack register: cleared bits for ack.
934 * @wake_invert: Inverted wake register: cleared bits are wake enabled.
935 * @type_invert: Invert the type flags.
936 * @runtime_pm: Hold a runtime PM lock on the device when accessing it.
938 * @num_regs: Number of registers in each control bank.
939 * @irqs: Descriptors for individual IRQs. Interrupt numbers are
940 * assigned based on the index in the array of the interrupt.
941 * @num_irqs: Number of descriptors.
942 * @num_type_reg: Number of type registers.
943 * @type_reg_stride: Stride to use for chips where type registers are not
945 * @handle_pre_irq: Driver specific callback to handle interrupt from device
946 * before regmap_irq_handler process the interrupts.
947 * @handle_post_irq: Driver specific callback to handle interrupt from device
948 * after handling the interrupts in regmap_irq_handler().
949 * @irq_drv_data: Driver specific IRQ data which is passed as parameter when
950 * driver specific pre/post interrupt handler is called.
952 * This is not intended to handle every possible interrupt controller, but
953 * it should handle a substantial proportion of those that are found in the
956 struct regmap_irq_chip {
959 unsigned int status_base;
960 unsigned int mask_base;
961 unsigned int unmask_base;
962 unsigned int ack_base;
963 unsigned int wake_base;
964 unsigned int type_base;
965 unsigned int irq_reg_stride;
966 bool mask_writeonly:1;
967 bool init_ack_masked:1;
977 const struct regmap_irq *irqs;
981 unsigned int type_reg_stride;
983 int (*handle_pre_irq)(void *irq_drv_data);
984 int (*handle_post_irq)(void *irq_drv_data);
988 struct regmap_irq_chip_data;
990 int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
991 int irq_base, const struct regmap_irq_chip *chip,
992 struct regmap_irq_chip_data **data);
993 void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data);
995 int devm_regmap_add_irq_chip(struct device *dev, struct regmap *map, int irq,
996 int irq_flags, int irq_base,
997 const struct regmap_irq_chip *chip,
998 struct regmap_irq_chip_data **data);
999 void devm_regmap_del_irq_chip(struct device *dev, int irq,
1000 struct regmap_irq_chip_data *data);
1002 int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data);
1003 int regmap_irq_get_virq(struct regmap_irq_chip_data *data, int irq);
1004 struct irq_domain *regmap_irq_get_domain(struct regmap_irq_chip_data *data);
1009 * These stubs should only ever be called by generic code which has
1010 * regmap based facilities, if they ever get called at runtime
1011 * something is going wrong and something probably needs to select
1015 static inline int regmap_write(struct regmap *map, unsigned int reg,
1018 WARN_ONCE(1, "regmap API is disabled");
1022 static inline int regmap_write_async(struct regmap *map, unsigned int reg,
1025 WARN_ONCE(1, "regmap API is disabled");
1029 static inline int regmap_raw_write(struct regmap *map, unsigned int reg,
1030 const void *val, size_t val_len)
1032 WARN_ONCE(1, "regmap API is disabled");
1036 static inline int regmap_raw_write_async(struct regmap *map, unsigned int reg,
1037 const void *val, size_t val_len)
1039 WARN_ONCE(1, "regmap API is disabled");
1043 static inline int regmap_bulk_write(struct regmap *map, unsigned int reg,
1044 const void *val, size_t val_count)
1046 WARN_ONCE(1, "regmap API is disabled");
1050 static inline int regmap_read(struct regmap *map, unsigned int reg,
1053 WARN_ONCE(1, "regmap API is disabled");
1057 static inline int regmap_raw_read(struct regmap *map, unsigned int reg,
1058 void *val, size_t val_len)
1060 WARN_ONCE(1, "regmap API is disabled");
1064 static inline int regmap_bulk_read(struct regmap *map, unsigned int reg,
1065 void *val, size_t val_count)
1067 WARN_ONCE(1, "regmap API is disabled");
1071 static inline int regmap_update_bits_base(struct regmap *map, unsigned int reg,
1072 unsigned int mask, unsigned int val,
1073 bool *change, bool async, bool force)
1075 WARN_ONCE(1, "regmap API is disabled");
1079 static inline int regmap_field_update_bits_base(struct regmap_field *field,
1080 unsigned int mask, unsigned int val,
1081 bool *change, bool async, bool force)
1083 WARN_ONCE(1, "regmap API is disabled");
1087 static inline int regmap_fields_update_bits_base(struct regmap_field *field,
1089 unsigned int mask, unsigned int val,
1090 bool *change, bool async, bool force)
1092 WARN_ONCE(1, "regmap API is disabled");
1096 static inline int regmap_get_val_bytes(struct regmap *map)
1098 WARN_ONCE(1, "regmap API is disabled");
1102 static inline int regmap_get_max_register(struct regmap *map)
1104 WARN_ONCE(1, "regmap API is disabled");
1108 static inline int regmap_get_reg_stride(struct regmap *map)
1110 WARN_ONCE(1, "regmap API is disabled");
1114 static inline int regcache_sync(struct regmap *map)
1116 WARN_ONCE(1, "regmap API is disabled");
1120 static inline int regcache_sync_region(struct regmap *map, unsigned int min,
1123 WARN_ONCE(1, "regmap API is disabled");
1127 static inline int regcache_drop_region(struct regmap *map, unsigned int min,
1130 WARN_ONCE(1, "regmap API is disabled");
1134 static inline void regcache_cache_only(struct regmap *map, bool enable)
1136 WARN_ONCE(1, "regmap API is disabled");
1139 static inline void regcache_cache_bypass(struct regmap *map, bool enable)
1141 WARN_ONCE(1, "regmap API is disabled");
1144 static inline void regcache_mark_dirty(struct regmap *map)
1146 WARN_ONCE(1, "regmap API is disabled");
1149 static inline void regmap_async_complete(struct regmap *map)
1151 WARN_ONCE(1, "regmap API is disabled");
1154 static inline int regmap_register_patch(struct regmap *map,
1155 const struct reg_sequence *regs,
1158 WARN_ONCE(1, "regmap API is disabled");
1162 static inline int regmap_parse_val(struct regmap *map, const void *buf,
1165 WARN_ONCE(1, "regmap API is disabled");
1169 static inline struct regmap *dev_get_regmap(struct device *dev,
1175 static inline struct device *regmap_get_device(struct regmap *map)
1177 WARN_ONCE(1, "regmap API is disabled");