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>
31 struct regmap_range_cfg
;
36 /* An enum of all the supported cache types */
45 * struct reg_default - Default value for a register.
47 * @reg: Register address.
48 * @def: Register default value.
50 * We use an array of structs rather than a simple array as many modern devices
51 * have very sparse register maps.
59 * struct reg_sequence - An individual write from a sequence of writes.
61 * @reg: Register address.
62 * @def: Register value.
63 * @delay_us: Delay to be applied after the register write in microseconds
65 * Register/value pairs for sequences of writes with an optional delay in
66 * microseconds to be applied after each write.
71 unsigned int delay_us
;
74 #define regmap_update_bits(map, reg, mask, val) \
75 regmap_update_bits_base(map, reg, mask, val, NULL, false, false)
76 #define regmap_update_bits_async(map, reg, mask, val)\
77 regmap_update_bits_base(map, reg, mask, val, NULL, true, false)
78 #define regmap_update_bits_check(map, reg, mask, val, change)\
79 regmap_update_bits_base(map, reg, mask, val, change, false, false)
80 #define regmap_update_bits_check_async(map, reg, mask, val, change)\
81 regmap_update_bits_base(map, reg, mask, val, change, true, false)
83 #define regmap_write_bits(map, reg, mask, val) \
84 regmap_update_bits_base(map, reg, mask, val, NULL, false, true)
86 #define regmap_field_write(field, val) \
87 regmap_field_update_bits_base(field, ~0, val, NULL, false, false)
88 #define regmap_field_force_write(field, val) \
89 regmap_field_update_bits_base(field, ~0, val, NULL, false, true)
90 #define regmap_field_update_bits(field, mask, val)\
91 regmap_field_update_bits_base(field, mask, val, NULL, false, false)
92 #define regmap_field_force_update_bits(field, mask, val) \
93 regmap_field_update_bits_base(field, mask, val, NULL, false, true)
95 #define regmap_fields_write(field, id, val) \
96 regmap_fields_update_bits_base(field, id, ~0, val, NULL, false, false)
97 #define regmap_fields_force_write(field, id, val) \
98 regmap_fields_update_bits_base(field, id, ~0, val, NULL, false, true)
99 #define regmap_fields_update_bits(field, id, mask, val)\
100 regmap_fields_update_bits_base(field, id, mask, val, NULL, false, false)
101 #define regmap_fields_force_update_bits(field, id, mask, val) \
102 regmap_fields_update_bits_base(field, id, mask, val, NULL, false, true)
105 * regmap_read_poll_timeout - Poll until a condition is met or a timeout occurs
107 * @map: Regmap to read from
108 * @addr: Address to poll
109 * @val: Unsigned integer variable to read the value into
110 * @cond: Break condition (usually involving @val)
111 * @sleep_us: Maximum time to sleep between reads in us (0
112 * tight-loops). Should be less than ~20ms since usleep_range
113 * is used (see Documentation/timers/timers-howto.txt).
114 * @timeout_us: Timeout in us, 0 means never timeout
116 * Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_read
117 * error return value in case of a error read. In the two former cases,
118 * the last read value at @addr is stored in @val. Must not be called
119 * from atomic context if sleep_us or timeout_us are used.
121 * This is modelled after the readx_poll_timeout macros in linux/iopoll.h.
123 #define regmap_read_poll_timeout(map, addr, val, cond, sleep_us, timeout_us) \
125 u64 __timeout_us = (timeout_us); \
126 unsigned long __sleep_us = (sleep_us); \
127 ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \
129 might_sleep_if(__sleep_us); \
131 __ret = regmap_read((map), (addr), &(val)); \
136 if ((__timeout_us) && \
137 ktime_compare(ktime_get(), __timeout) > 0) { \
138 __ret = regmap_read((map), (addr), &(val)); \
142 usleep_range((__sleep_us >> 2) + 1, __sleep_us); \
144 __ret ?: ((cond) ? 0 : -ETIMEDOUT); \
148 * regmap_field_read_poll_timeout - Poll until a condition is met or timeout
150 * @field: Regmap field to read from
151 * @val: Unsigned integer variable to read the value into
152 * @cond: Break condition (usually involving @val)
153 * @sleep_us: Maximum time to sleep between reads in us (0
154 * tight-loops). Should be less than ~20ms since usleep_range
155 * is used (see Documentation/timers/timers-howto.txt).
156 * @timeout_us: Timeout in us, 0 means never timeout
158 * Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_field_read
159 * error return value in case of a error read. In the two former cases,
160 * the last read value at @addr is stored in @val. Must not be called
161 * from atomic context if sleep_us or timeout_us are used.
163 * This is modelled after the readx_poll_timeout macros in linux/iopoll.h.
165 #define regmap_field_read_poll_timeout(field, val, cond, sleep_us, timeout_us) \
167 u64 __timeout_us = (timeout_us); \
168 unsigned long __sleep_us = (sleep_us); \
169 ktime_t timeout = ktime_add_us(ktime_get(), __timeout_us); \
171 might_sleep_if(__sleep_us); \
173 pollret = regmap_field_read((field), &(val)); \
178 if (__timeout_us && ktime_compare(ktime_get(), timeout) > 0) { \
179 pollret = regmap_field_read((field), &(val)); \
183 usleep_range((__sleep_us >> 2) + 1, __sleep_us); \
185 pollret ?: ((cond) ? 0 : -ETIMEDOUT); \
191 /* Unspecified -> 0 -> Backwards compatible default */
192 REGMAP_ENDIAN_DEFAULT
= 0,
194 REGMAP_ENDIAN_LITTLE
,
195 REGMAP_ENDIAN_NATIVE
,
199 * struct regmap_range - A register range, used for access related checks
200 * (readable/writeable/volatile/precious checks)
202 * @range_min: address of first register
203 * @range_max: address of last register
205 struct regmap_range
{
206 unsigned int range_min
;
207 unsigned int range_max
;
210 #define regmap_reg_range(low, high) { .range_min = low, .range_max = high, }
213 * struct regmap_access_table - A table of register ranges for access checks
215 * @yes_ranges : pointer to an array of regmap ranges used as "yes ranges"
216 * @n_yes_ranges: size of the above array
217 * @no_ranges: pointer to an array of regmap ranges used as "no ranges"
218 * @n_no_ranges: size of the above array
220 * A table of ranges including some yes ranges and some no ranges.
221 * If a register belongs to a no_range, the corresponding check function
222 * will return false. If a register belongs to a yes range, the corresponding
223 * check function will return true. "no_ranges" are searched first.
225 struct regmap_access_table
{
226 const struct regmap_range
*yes_ranges
;
227 unsigned int n_yes_ranges
;
228 const struct regmap_range
*no_ranges
;
229 unsigned int n_no_ranges
;
232 typedef void (*regmap_lock
)(void *);
233 typedef void (*regmap_unlock
)(void *);
236 * struct regmap_config - Configuration for the register map of a device.
238 * @name: Optional name of the regmap. Useful when a device has multiple
241 * @reg_bits: Number of bits in a register address, mandatory.
242 * @reg_stride: The register address stride. Valid register addresses are a
243 * multiple of this value. If set to 0, a value of 1 will be
245 * @pad_bits: Number of bits of padding between register and value.
246 * @val_bits: Number of bits in a register value, mandatory.
248 * @writeable_reg: Optional callback returning true if the register
249 * can be written to. If this field is NULL but wr_table
250 * (see below) is not, the check is performed on such table
251 * (a register is writeable if it belongs to one of the ranges
252 * specified by wr_table).
253 * @readable_reg: Optional callback returning true if the register
254 * can be read from. If this field is NULL but rd_table
255 * (see below) is not, the check is performed on such table
256 * (a register is readable if it belongs to one of the ranges
257 * specified by rd_table).
258 * @volatile_reg: Optional callback returning true if the register
259 * value can't be cached. If this field is NULL but
260 * volatile_table (see below) is not, the check is performed on
261 * such table (a register is volatile if it belongs to one of
262 * the ranges specified by volatile_table).
263 * @precious_reg: Optional callback returning true if the register
264 * should not be read outside of a call from the driver
265 * (e.g., a clear on read interrupt status register). If this
266 * field is NULL but precious_table (see below) is not, the
267 * check is performed on such table (a register is precious if
268 * it belongs to one of the ranges specified by precious_table).
269 * @disable_locking: This regmap is either protected by external means or
270 * is guaranteed not be be accessed from multiple threads.
271 * Don't use any locking mechanisms.
272 * @lock: Optional lock callback (overrides regmap's default lock
273 * function, based on spinlock or mutex).
274 * @unlock: As above for unlocking.
275 * @lock_arg: this field is passed as the only argument of lock/unlock
276 * functions (ignored in case regular lock/unlock functions
277 * are not overridden).
278 * @reg_read: Optional callback that if filled will be used to perform
279 * all the reads from the registers. Should only be provided for
280 * devices whose read operation cannot be represented as a simple
281 * read operation on a bus such as SPI, I2C, etc. Most of the
282 * devices do not need this.
283 * @reg_write: Same as above for writing.
284 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
285 * to perform locking. This field is ignored if custom lock/unlock
286 * functions are used (see fields lock/unlock of struct regmap_config).
287 * This field is a duplicate of a similar file in
288 * 'struct regmap_bus' and serves exact same purpose.
289 * Use it only for "no-bus" cases.
290 * @max_register: Optional, specifies the maximum valid register address.
291 * @wr_table: Optional, points to a struct regmap_access_table specifying
292 * valid ranges for write access.
293 * @rd_table: As above, for read access.
294 * @volatile_table: As above, for volatile registers.
295 * @precious_table: As above, for precious registers.
296 * @reg_defaults: Power on reset values for registers (for use with
297 * register cache support).
298 * @num_reg_defaults: Number of elements in reg_defaults.
300 * @read_flag_mask: Mask to be set in the top bytes of the register when doing
302 * @write_flag_mask: Mask to be set in the top bytes of the register when doing
303 * a write. If both read_flag_mask and write_flag_mask are
304 * empty and zero_flag_mask is not set the regmap_bus default
306 * @zero_flag_mask: If set, read_flag_mask and write_flag_mask are used even
307 * if they are both empty.
308 * @use_single_rw: If set, converts the bulk read and write operations into
309 * a series of single read and write operations. This is useful
310 * for device that does not support bulk read and write.
311 * @can_multi_write: If set, the device supports the multi write mode of bulk
312 * write operations, if clear multi write requests will be
313 * split into individual write operations
315 * @cache_type: The actual cache type.
316 * @reg_defaults_raw: Power on reset values for registers (for use with
317 * register cache support).
318 * @num_reg_defaults_raw: Number of elements in reg_defaults_raw.
319 * @reg_format_endian: Endianness for formatted register addresses. If this is
320 * DEFAULT, the @reg_format_endian_default value from the
321 * regmap bus is used.
322 * @val_format_endian: Endianness for formatted register values. If this is
323 * DEFAULT, the @reg_format_endian_default value from the
324 * regmap bus is used.
326 * @ranges: Array of configuration entries for virtual address ranges.
327 * @num_ranges: Number of range configuration entries.
328 * @use_hwlock: Indicate if a hardware spinlock should be used.
329 * @hwlock_id: Specify the hardware spinlock id.
330 * @hwlock_mode: The hardware spinlock mode, should be HWLOCK_IRQSTATE,
333 struct regmap_config
{
341 bool (*writeable_reg
)(struct device
*dev
, unsigned int reg
);
342 bool (*readable_reg
)(struct device
*dev
, unsigned int reg
);
343 bool (*volatile_reg
)(struct device
*dev
, unsigned int reg
);
344 bool (*precious_reg
)(struct device
*dev
, unsigned int reg
);
346 bool disable_locking
;
348 regmap_unlock unlock
;
351 int (*reg_read
)(void *context
, unsigned int reg
, unsigned int *val
);
352 int (*reg_write
)(void *context
, unsigned int reg
, unsigned int val
);
356 unsigned int max_register
;
357 const struct regmap_access_table
*wr_table
;
358 const struct regmap_access_table
*rd_table
;
359 const struct regmap_access_table
*volatile_table
;
360 const struct regmap_access_table
*precious_table
;
361 const struct reg_default
*reg_defaults
;
362 unsigned int num_reg_defaults
;
363 enum regcache_type cache_type
;
364 const void *reg_defaults_raw
;
365 unsigned int num_reg_defaults_raw
;
367 unsigned long read_flag_mask
;
368 unsigned long write_flag_mask
;
372 bool can_multi_write
;
374 enum regmap_endian reg_format_endian
;
375 enum regmap_endian val_format_endian
;
377 const struct regmap_range_cfg
*ranges
;
378 unsigned int num_ranges
;
381 unsigned int hwlock_id
;
382 unsigned int hwlock_mode
;
386 * struct regmap_range_cfg - Configuration for indirectly accessed or paged
389 * @name: Descriptive name for diagnostics
391 * @range_min: Address of the lowest register address in virtual range.
392 * @range_max: Address of the highest register in virtual range.
394 * @selector_reg: Register with selector field.
395 * @selector_mask: Bit shift for selector value.
396 * @selector_shift: Bit mask for selector value.
398 * @window_start: Address of first (lowest) register in data window.
399 * @window_len: Number of registers in data window.
401 * Registers, mapped to this virtual range, are accessed in two steps:
402 * 1. page selector register update;
403 * 2. access through data window registers.
405 struct regmap_range_cfg
{
408 /* Registers of virtual address range */
409 unsigned int range_min
;
410 unsigned int range_max
;
412 /* Page selector for indirect addressing */
413 unsigned int selector_reg
;
414 unsigned int selector_mask
;
417 /* Data window (per each page) */
418 unsigned int window_start
;
419 unsigned int window_len
;
424 typedef int (*regmap_hw_write
)(void *context
, const void *data
,
426 typedef int (*regmap_hw_gather_write
)(void *context
,
427 const void *reg
, size_t reg_len
,
428 const void *val
, size_t val_len
);
429 typedef int (*regmap_hw_async_write
)(void *context
,
430 const void *reg
, size_t reg_len
,
431 const void *val
, size_t val_len
,
432 struct regmap_async
*async
);
433 typedef int (*regmap_hw_read
)(void *context
,
434 const void *reg_buf
, size_t reg_size
,
435 void *val_buf
, size_t val_size
);
436 typedef int (*regmap_hw_reg_read
)(void *context
, unsigned int reg
,
438 typedef int (*regmap_hw_reg_write
)(void *context
, unsigned int reg
,
440 typedef int (*regmap_hw_reg_update_bits
)(void *context
, unsigned int reg
,
441 unsigned int mask
, unsigned int val
);
442 typedef struct regmap_async
*(*regmap_hw_async_alloc
)(void);
443 typedef void (*regmap_hw_free_context
)(void *context
);
446 * struct regmap_bus - Description of a hardware bus for the register map
449 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
450 * to perform locking. This field is ignored if custom lock/unlock
451 * functions are used (see fields lock/unlock of
452 * struct regmap_config).
453 * @write: Write operation.
454 * @gather_write: Write operation with split register/value, return -ENOTSUPP
455 * if not implemented on a given device.
456 * @async_write: Write operation which completes asynchronously, optional and
457 * must serialise with respect to non-async I/O.
458 * @reg_write: Write a single register value to the given register address. This
459 * write operation has to complete when returning from the function.
460 * @reg_update_bits: Update bits operation to be used against volatile
461 * registers, intended for devices supporting some mechanism
462 * for setting clearing bits without having to
464 * @read: Read operation. Data is returned in the buffer used to transmit
466 * @reg_read: Read a single register value from a given register address.
467 * @free_context: Free context.
468 * @async_alloc: Allocate a regmap_async() structure.
469 * @read_flag_mask: Mask to be set in the top byte of the register when doing
471 * @reg_format_endian_default: Default endianness for formatted register
472 * addresses. Used when the regmap_config specifies DEFAULT. If this is
473 * DEFAULT, BIG is assumed.
474 * @val_format_endian_default: Default endianness for formatted register
475 * values. Used when the regmap_config specifies DEFAULT. If this is
476 * DEFAULT, BIG is assumed.
477 * @max_raw_read: Max raw read size that can be used on the bus.
478 * @max_raw_write: Max raw write size that can be used on the bus.
482 regmap_hw_write write
;
483 regmap_hw_gather_write gather_write
;
484 regmap_hw_async_write async_write
;
485 regmap_hw_reg_write reg_write
;
486 regmap_hw_reg_update_bits reg_update_bits
;
488 regmap_hw_reg_read reg_read
;
489 regmap_hw_free_context free_context
;
490 regmap_hw_async_alloc async_alloc
;
492 enum regmap_endian reg_format_endian_default
;
493 enum regmap_endian val_format_endian_default
;
495 size_t max_raw_write
;
499 * __regmap_init functions.
501 * These functions take a lock key and name parameter, and should not be called
502 * directly. Instead, use the regmap_init macros that generate a key and name
505 struct regmap
*__regmap_init(struct device
*dev
,
506 const struct regmap_bus
*bus
,
508 const struct regmap_config
*config
,
509 struct lock_class_key
*lock_key
,
510 const char *lock_name
);
511 struct regmap
*__regmap_init_i2c(struct i2c_client
*i2c
,
512 const struct regmap_config
*config
,
513 struct lock_class_key
*lock_key
,
514 const char *lock_name
);
515 struct regmap
*__regmap_init_slimbus(struct slim_device
*slimbus
,
516 const struct regmap_config
*config
,
517 struct lock_class_key
*lock_key
,
518 const char *lock_name
);
519 struct regmap
*__regmap_init_spi(struct spi_device
*dev
,
520 const struct regmap_config
*config
,
521 struct lock_class_key
*lock_key
,
522 const char *lock_name
);
523 struct regmap
*__regmap_init_spmi_base(struct spmi_device
*dev
,
524 const struct regmap_config
*config
,
525 struct lock_class_key
*lock_key
,
526 const char *lock_name
);
527 struct regmap
*__regmap_init_spmi_ext(struct spmi_device
*dev
,
528 const struct regmap_config
*config
,
529 struct lock_class_key
*lock_key
,
530 const char *lock_name
);
531 struct regmap
*__regmap_init_w1(struct device
*w1_dev
,
532 const struct regmap_config
*config
,
533 struct lock_class_key
*lock_key
,
534 const char *lock_name
);
535 struct regmap
*__regmap_init_mmio_clk(struct device
*dev
, const char *clk_id
,
537 const struct regmap_config
*config
,
538 struct lock_class_key
*lock_key
,
539 const char *lock_name
);
540 struct regmap
*__regmap_init_ac97(struct snd_ac97
*ac97
,
541 const struct regmap_config
*config
,
542 struct lock_class_key
*lock_key
,
543 const char *lock_name
);
544 struct regmap
*__regmap_init_sdw(struct sdw_slave
*sdw
,
545 const struct regmap_config
*config
,
546 struct lock_class_key
*lock_key
,
547 const char *lock_name
);
549 struct regmap
*__devm_regmap_init(struct device
*dev
,
550 const struct regmap_bus
*bus
,
552 const struct regmap_config
*config
,
553 struct lock_class_key
*lock_key
,
554 const char *lock_name
);
555 struct regmap
*__devm_regmap_init_i2c(struct i2c_client
*i2c
,
556 const struct regmap_config
*config
,
557 struct lock_class_key
*lock_key
,
558 const char *lock_name
);
559 struct regmap
*__devm_regmap_init_spi(struct spi_device
*dev
,
560 const struct regmap_config
*config
,
561 struct lock_class_key
*lock_key
,
562 const char *lock_name
);
563 struct regmap
*__devm_regmap_init_spmi_base(struct spmi_device
*dev
,
564 const struct regmap_config
*config
,
565 struct lock_class_key
*lock_key
,
566 const char *lock_name
);
567 struct regmap
*__devm_regmap_init_spmi_ext(struct spmi_device
*dev
,
568 const struct regmap_config
*config
,
569 struct lock_class_key
*lock_key
,
570 const char *lock_name
);
571 struct regmap
*__devm_regmap_init_w1(struct device
*w1_dev
,
572 const struct regmap_config
*config
,
573 struct lock_class_key
*lock_key
,
574 const char *lock_name
);
575 struct regmap
*__devm_regmap_init_mmio_clk(struct device
*dev
,
578 const struct regmap_config
*config
,
579 struct lock_class_key
*lock_key
,
580 const char *lock_name
);
581 struct regmap
*__devm_regmap_init_ac97(struct snd_ac97
*ac97
,
582 const struct regmap_config
*config
,
583 struct lock_class_key
*lock_key
,
584 const char *lock_name
);
585 struct regmap
*__devm_regmap_init_sdw(struct sdw_slave
*sdw
,
586 const struct regmap_config
*config
,
587 struct lock_class_key
*lock_key
,
588 const char *lock_name
);
591 * Wrapper for regmap_init macros to include a unique lockdep key and name
592 * for each call. No-op if CONFIG_LOCKDEP is not set.
594 * @fn: Real function to call (in the form __[*_]regmap_init[_*])
595 * @name: Config variable name (#config in the calling macro)
597 #ifdef CONFIG_LOCKDEP
598 #define __regmap_lockdep_wrapper(fn, name, ...) \
601 static struct lock_class_key _key; \
602 fn(__VA_ARGS__, &_key, \
603 KBUILD_BASENAME ":" \
604 __stringify(__LINE__) ":" \
605 "(" name ")->lock"); \
609 #define __regmap_lockdep_wrapper(fn, name, ...) fn(__VA_ARGS__, NULL, NULL)
613 * regmap_init() - Initialise register map
615 * @dev: Device that will be interacted with
616 * @bus: Bus-specific callbacks to use with device
617 * @bus_context: Data passed to bus-specific callbacks
618 * @config: Configuration for register map
620 * The return value will be an ERR_PTR() on error or a valid pointer to
621 * a struct regmap. This function should generally not be called
622 * directly, it should be called by bus-specific init functions.
624 #define regmap_init(dev, bus, bus_context, config) \
625 __regmap_lockdep_wrapper(__regmap_init, #config, \
626 dev, bus, bus_context, config)
627 int regmap_attach_dev(struct device
*dev
, struct regmap
*map
,
628 const struct regmap_config
*config
);
631 * regmap_init_i2c() - Initialise register map
633 * @i2c: Device that will be interacted with
634 * @config: Configuration for register map
636 * The return value will be an ERR_PTR() on error or a valid pointer to
639 #define regmap_init_i2c(i2c, config) \
640 __regmap_lockdep_wrapper(__regmap_init_i2c, #config, \
644 * regmap_init_slimbus() - Initialise register map
646 * @slimbus: Device that will be interacted with
647 * @config: Configuration for register map
649 * The return value will be an ERR_PTR() on error or a valid pointer to
652 #define regmap_init_slimbus(slimbus, config) \
653 __regmap_lockdep_wrapper(__regmap_init_slimbus, #config, \
657 * regmap_init_spi() - Initialise register map
659 * @dev: Device that will be interacted with
660 * @config: Configuration for register map
662 * The return value will be an ERR_PTR() on error or a valid pointer to
665 #define regmap_init_spi(dev, config) \
666 __regmap_lockdep_wrapper(__regmap_init_spi, #config, \
670 * regmap_init_spmi_base() - Create regmap for the Base register space
672 * @dev: SPMI device that will be interacted with
673 * @config: Configuration for register map
675 * The return value will be an ERR_PTR() on error or a valid pointer to
678 #define regmap_init_spmi_base(dev, config) \
679 __regmap_lockdep_wrapper(__regmap_init_spmi_base, #config, \
683 * regmap_init_spmi_ext() - Create regmap for Ext register space
685 * @dev: Device that will be interacted with
686 * @config: Configuration for register map
688 * The return value will be an ERR_PTR() on error or a valid pointer to
691 #define regmap_init_spmi_ext(dev, config) \
692 __regmap_lockdep_wrapper(__regmap_init_spmi_ext, #config, \
696 * regmap_init_w1() - Initialise register map
698 * @w1_dev: Device that will be interacted with
699 * @config: Configuration for register map
701 * The return value will be an ERR_PTR() on error or a valid pointer to
704 #define regmap_init_w1(w1_dev, config) \
705 __regmap_lockdep_wrapper(__regmap_init_w1, #config, \
709 * regmap_init_mmio_clk() - Initialise register map with register clock
711 * @dev: Device that will be interacted with
712 * @clk_id: register clock consumer ID
713 * @regs: Pointer to memory-mapped IO region
714 * @config: Configuration for register map
716 * The return value will be an ERR_PTR() on error or a valid pointer to
719 #define regmap_init_mmio_clk(dev, clk_id, regs, config) \
720 __regmap_lockdep_wrapper(__regmap_init_mmio_clk, #config, \
721 dev, clk_id, regs, config)
724 * regmap_init_mmio() - Initialise register map
726 * @dev: Device that will be interacted with
727 * @regs: Pointer to memory-mapped IO region
728 * @config: Configuration for register map
730 * The return value will be an ERR_PTR() on error or a valid pointer to
733 #define regmap_init_mmio(dev, regs, config) \
734 regmap_init_mmio_clk(dev, NULL, regs, config)
737 * regmap_init_ac97() - Initialise AC'97 register map
739 * @ac97: Device that will be interacted with
740 * @config: Configuration for register map
742 * The return value will be an ERR_PTR() on error or a valid pointer to
745 #define regmap_init_ac97(ac97, config) \
746 __regmap_lockdep_wrapper(__regmap_init_ac97, #config, \
748 bool regmap_ac97_default_volatile(struct device
*dev
, unsigned int reg
);
751 * regmap_init_sdw() - Initialise register map
753 * @sdw: Device that will be interacted with
754 * @config: Configuration for register map
756 * The return value will be an ERR_PTR() on error or a valid pointer to
759 #define regmap_init_sdw(sdw, config) \
760 __regmap_lockdep_wrapper(__regmap_init_sdw, #config, \
765 * devm_regmap_init() - Initialise managed register map
767 * @dev: Device that will be interacted with
768 * @bus: Bus-specific callbacks to use with device
769 * @bus_context: Data passed to bus-specific callbacks
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. This function should generally not be called
774 * directly, it should be called by bus-specific init functions. The
775 * map will be automatically freed by the device management code.
777 #define devm_regmap_init(dev, bus, bus_context, config) \
778 __regmap_lockdep_wrapper(__devm_regmap_init, #config, \
779 dev, bus, bus_context, config)
782 * devm_regmap_init_i2c() - Initialise managed register map
784 * @i2c: Device that will be interacted with
785 * @config: Configuration for register map
787 * The return value will be an ERR_PTR() on error or a valid pointer
788 * to a struct regmap. The regmap will be automatically freed by the
789 * device management code.
791 #define devm_regmap_init_i2c(i2c, config) \
792 __regmap_lockdep_wrapper(__devm_regmap_init_i2c, #config, \
796 * devm_regmap_init_spi() - Initialise register map
798 * @dev: Device that will be interacted with
799 * @config: Configuration for register map
801 * The return value will be an ERR_PTR() on error or a valid pointer
802 * to a struct regmap. The map will be automatically freed by the
803 * device management code.
805 #define devm_regmap_init_spi(dev, config) \
806 __regmap_lockdep_wrapper(__devm_regmap_init_spi, #config, \
810 * devm_regmap_init_spmi_base() - Create managed regmap for Base register space
812 * @dev: SPMI device that will be interacted with
813 * @config: Configuration for register map
815 * The return value will be an ERR_PTR() on error or a valid pointer
816 * to a struct regmap. The regmap will be automatically freed by the
817 * device management code.
819 #define devm_regmap_init_spmi_base(dev, config) \
820 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_base, #config, \
824 * devm_regmap_init_spmi_ext() - Create managed regmap for Ext register space
826 * @dev: SPMI device that will be interacted with
827 * @config: Configuration for register map
829 * The return value will be an ERR_PTR() on error or a valid pointer
830 * to a struct regmap. The regmap will be automatically freed by the
831 * device management code.
833 #define devm_regmap_init_spmi_ext(dev, config) \
834 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_ext, #config, \
838 * devm_regmap_init_w1() - Initialise managed register map
840 * @w1_dev: Device that will be interacted with
841 * @config: Configuration for register map
843 * The return value will be an ERR_PTR() on error or a valid pointer
844 * to a struct regmap. The regmap will be automatically freed by the
845 * device management code.
847 #define devm_regmap_init_w1(w1_dev, config) \
848 __regmap_lockdep_wrapper(__devm_regmap_init_w1, #config, \
851 * devm_regmap_init_mmio_clk() - Initialise managed register map with clock
853 * @dev: Device that will be interacted with
854 * @clk_id: register clock consumer ID
855 * @regs: Pointer to memory-mapped IO region
856 * @config: Configuration for register map
858 * The return value will be an ERR_PTR() on error or a valid pointer
859 * to a struct regmap. The regmap will be automatically freed by the
860 * device management code.
862 #define devm_regmap_init_mmio_clk(dev, clk_id, regs, config) \
863 __regmap_lockdep_wrapper(__devm_regmap_init_mmio_clk, #config, \
864 dev, clk_id, regs, config)
867 * devm_regmap_init_mmio() - Initialise managed register map
869 * @dev: Device that will be interacted with
870 * @regs: Pointer to memory-mapped IO region
871 * @config: Configuration for register map
873 * The return value will be an ERR_PTR() on error or a valid pointer
874 * to a struct regmap. The regmap will be automatically freed by the
875 * device management code.
877 #define devm_regmap_init_mmio(dev, regs, config) \
878 devm_regmap_init_mmio_clk(dev, NULL, regs, config)
881 * devm_regmap_init_ac97() - Initialise AC'97 register map
883 * @ac97: Device that will be interacted with
884 * @config: Configuration for register map
886 * The return value will be an ERR_PTR() on error or a valid pointer
887 * to a struct regmap. The regmap will be automatically freed by the
888 * device management code.
890 #define devm_regmap_init_ac97(ac97, config) \
891 __regmap_lockdep_wrapper(__devm_regmap_init_ac97, #config, \
895 * devm_regmap_init_sdw() - Initialise managed register map
897 * @sdw: Device that will be interacted with
898 * @config: Configuration for register map
900 * The return value will be an ERR_PTR() on error or a valid pointer
901 * to a struct regmap. The regmap will be automatically freed by the
902 * device management code.
904 #define devm_regmap_init_sdw(sdw, config) \
905 __regmap_lockdep_wrapper(__devm_regmap_init_sdw, #config, \
908 void regmap_exit(struct regmap
*map
);
909 int regmap_reinit_cache(struct regmap
*map
,
910 const struct regmap_config
*config
);
911 struct regmap
*dev_get_regmap(struct device
*dev
, const char *name
);
912 struct device
*regmap_get_device(struct regmap
*map
);
913 int regmap_write(struct regmap
*map
, unsigned int reg
, unsigned int val
);
914 int regmap_write_async(struct regmap
*map
, unsigned int reg
, unsigned int val
);
915 int regmap_raw_write(struct regmap
*map
, unsigned int reg
,
916 const void *val
, size_t val_len
);
917 int regmap_bulk_write(struct regmap
*map
, unsigned int reg
, const void *val
,
919 int regmap_multi_reg_write(struct regmap
*map
, const struct reg_sequence
*regs
,
921 int regmap_multi_reg_write_bypassed(struct regmap
*map
,
922 const struct reg_sequence
*regs
,
924 int regmap_raw_write_async(struct regmap
*map
, unsigned int reg
,
925 const void *val
, size_t val_len
);
926 int regmap_read(struct regmap
*map
, unsigned int reg
, unsigned int *val
);
927 int regmap_raw_read(struct regmap
*map
, unsigned int reg
,
928 void *val
, size_t val_len
);
929 int regmap_bulk_read(struct regmap
*map
, unsigned int reg
, void *val
,
931 int regmap_update_bits_base(struct regmap
*map
, unsigned int reg
,
932 unsigned int mask
, unsigned int val
,
933 bool *change
, bool async
, bool force
);
934 int regmap_get_val_bytes(struct regmap
*map
);
935 int regmap_get_max_register(struct regmap
*map
);
936 int regmap_get_reg_stride(struct regmap
*map
);
937 int regmap_async_complete(struct regmap
*map
);
938 bool regmap_can_raw_write(struct regmap
*map
);
939 size_t regmap_get_raw_read_max(struct regmap
*map
);
940 size_t regmap_get_raw_write_max(struct regmap
*map
);
942 int regcache_sync(struct regmap
*map
);
943 int regcache_sync_region(struct regmap
*map
, unsigned int min
,
945 int regcache_drop_region(struct regmap
*map
, unsigned int min
,
947 void regcache_cache_only(struct regmap
*map
, bool enable
);
948 void regcache_cache_bypass(struct regmap
*map
, bool enable
);
949 void regcache_mark_dirty(struct regmap
*map
);
951 bool regmap_check_range_table(struct regmap
*map
, unsigned int reg
,
952 const struct regmap_access_table
*table
);
954 int regmap_register_patch(struct regmap
*map
, const struct reg_sequence
*regs
,
956 int regmap_parse_val(struct regmap
*map
, const void *buf
,
959 static inline bool regmap_reg_in_range(unsigned int reg
,
960 const struct regmap_range
*range
)
962 return reg
>= range
->range_min
&& reg
<= range
->range_max
;
965 bool regmap_reg_in_ranges(unsigned int reg
,
966 const struct regmap_range
*ranges
,
967 unsigned int nranges
);
970 * struct reg_field - Description of an register field
972 * @reg: Offset of the register within the regmap bank
973 * @lsb: lsb of the register field.
974 * @msb: msb of the register field.
975 * @id_size: port size if it has some ports
976 * @id_offset: address offset for each ports
982 unsigned int id_size
;
983 unsigned int id_offset
;
986 #define REG_FIELD(_reg, _lsb, _msb) { \
992 struct regmap_field
*regmap_field_alloc(struct regmap
*regmap
,
993 struct reg_field reg_field
);
994 void regmap_field_free(struct regmap_field
*field
);
996 struct regmap_field
*devm_regmap_field_alloc(struct device
*dev
,
997 struct regmap
*regmap
, struct reg_field reg_field
);
998 void devm_regmap_field_free(struct device
*dev
, struct regmap_field
*field
);
1000 int regmap_field_read(struct regmap_field
*field
, unsigned int *val
);
1001 int regmap_field_update_bits_base(struct regmap_field
*field
,
1002 unsigned int mask
, unsigned int val
,
1003 bool *change
, bool async
, bool force
);
1004 int regmap_fields_read(struct regmap_field
*field
, unsigned int id
,
1006 int regmap_fields_update_bits_base(struct regmap_field
*field
, unsigned int id
,
1007 unsigned int mask
, unsigned int val
,
1008 bool *change
, bool async
, bool force
);
1011 * struct regmap_irq - Description of an IRQ for the generic regmap irq_chip.
1013 * @reg_offset: Offset of the status/mask register within the bank
1014 * @mask: Mask used to flag/control the register.
1015 * @type_reg_offset: Offset register for the irq type setting.
1016 * @type_rising_mask: Mask bit to configure RISING type irq.
1017 * @type_falling_mask: Mask bit to configure FALLING type irq.
1020 unsigned int reg_offset
;
1022 unsigned int type_reg_offset
;
1023 unsigned int type_rising_mask
;
1024 unsigned int type_falling_mask
;
1027 #define REGMAP_IRQ_REG(_irq, _off, _mask) \
1028 [_irq] = { .reg_offset = (_off), .mask = (_mask) }
1031 * struct regmap_irq_chip - Description of a generic regmap irq_chip.
1033 * @name: Descriptive name for IRQ controller.
1035 * @status_base: Base status register address.
1036 * @mask_base: Base mask register address.
1037 * @mask_writeonly: Base mask register is write only.
1038 * @unmask_base: Base unmask register address. for chips who have
1039 * separate mask and unmask registers
1040 * @ack_base: Base ack address. If zero then the chip is clear on read.
1041 * Using zero value is possible with @use_ack bit.
1042 * @wake_base: Base address for wake enables. If zero unsupported.
1043 * @type_base: Base address for irq type. If zero unsupported.
1044 * @irq_reg_stride: Stride to use for chips where registers are not contiguous.
1045 * @init_ack_masked: Ack all masked interrupts once during initalization.
1046 * @mask_invert: Inverted mask register: cleared bits are masked out.
1047 * @use_ack: Use @ack register even if it is zero.
1048 * @ack_invert: Inverted ack register: cleared bits for ack.
1049 * @wake_invert: Inverted wake register: cleared bits are wake enabled.
1050 * @type_invert: Invert the type flags.
1051 * @runtime_pm: Hold a runtime PM lock on the device when accessing it.
1053 * @num_regs: Number of registers in each control bank.
1054 * @irqs: Descriptors for individual IRQs. Interrupt numbers are
1055 * assigned based on the index in the array of the interrupt.
1056 * @num_irqs: Number of descriptors.
1057 * @num_type_reg: Number of type registers.
1058 * @type_reg_stride: Stride to use for chips where type registers are not
1060 * @handle_pre_irq: Driver specific callback to handle interrupt from device
1061 * before regmap_irq_handler process the interrupts.
1062 * @handle_post_irq: Driver specific callback to handle interrupt from device
1063 * after handling the interrupts in regmap_irq_handler().
1064 * @irq_drv_data: Driver specific IRQ data which is passed as parameter when
1065 * driver specific pre/post interrupt handler is called.
1067 * This is not intended to handle every possible interrupt controller, but
1068 * it should handle a substantial proportion of those that are found in the
1071 struct regmap_irq_chip
{
1074 unsigned int status_base
;
1075 unsigned int mask_base
;
1076 unsigned int unmask_base
;
1077 unsigned int ack_base
;
1078 unsigned int wake_base
;
1079 unsigned int type_base
;
1080 unsigned int irq_reg_stride
;
1081 bool mask_writeonly
:1;
1082 bool init_ack_masked
:1;
1092 const struct regmap_irq
*irqs
;
1096 unsigned int type_reg_stride
;
1098 int (*handle_pre_irq
)(void *irq_drv_data
);
1099 int (*handle_post_irq
)(void *irq_drv_data
);
1103 struct regmap_irq_chip_data
;
1105 int regmap_add_irq_chip(struct regmap
*map
, int irq
, int irq_flags
,
1106 int irq_base
, const struct regmap_irq_chip
*chip
,
1107 struct regmap_irq_chip_data
**data
);
1108 void regmap_del_irq_chip(int irq
, struct regmap_irq_chip_data
*data
);
1110 int devm_regmap_add_irq_chip(struct device
*dev
, struct regmap
*map
, int irq
,
1111 int irq_flags
, int irq_base
,
1112 const struct regmap_irq_chip
*chip
,
1113 struct regmap_irq_chip_data
**data
);
1114 void devm_regmap_del_irq_chip(struct device
*dev
, int irq
,
1115 struct regmap_irq_chip_data
*data
);
1117 int regmap_irq_chip_get_base(struct regmap_irq_chip_data
*data
);
1118 int regmap_irq_get_virq(struct regmap_irq_chip_data
*data
, int irq
);
1119 struct irq_domain
*regmap_irq_get_domain(struct regmap_irq_chip_data
*data
);
1124 * These stubs should only ever be called by generic code which has
1125 * regmap based facilities, if they ever get called at runtime
1126 * something is going wrong and something probably needs to select
1130 static inline int regmap_write(struct regmap
*map
, unsigned int reg
,
1133 WARN_ONCE(1, "regmap API is disabled");
1137 static inline int regmap_write_async(struct regmap
*map
, unsigned int reg
,
1140 WARN_ONCE(1, "regmap API is disabled");
1144 static inline int regmap_raw_write(struct regmap
*map
, unsigned int reg
,
1145 const void *val
, size_t val_len
)
1147 WARN_ONCE(1, "regmap API is disabled");
1151 static inline int regmap_raw_write_async(struct regmap
*map
, unsigned int reg
,
1152 const void *val
, size_t val_len
)
1154 WARN_ONCE(1, "regmap API is disabled");
1158 static inline int regmap_bulk_write(struct regmap
*map
, unsigned int reg
,
1159 const void *val
, size_t val_count
)
1161 WARN_ONCE(1, "regmap API is disabled");
1165 static inline int regmap_read(struct regmap
*map
, unsigned int reg
,
1168 WARN_ONCE(1, "regmap API is disabled");
1172 static inline int regmap_raw_read(struct regmap
*map
, unsigned int reg
,
1173 void *val
, size_t val_len
)
1175 WARN_ONCE(1, "regmap API is disabled");
1179 static inline int regmap_bulk_read(struct regmap
*map
, unsigned int reg
,
1180 void *val
, size_t val_count
)
1182 WARN_ONCE(1, "regmap API is disabled");
1186 static inline int regmap_update_bits_base(struct regmap
*map
, unsigned int reg
,
1187 unsigned int mask
, unsigned int val
,
1188 bool *change
, bool async
, bool force
)
1190 WARN_ONCE(1, "regmap API is disabled");
1194 static inline int regmap_field_update_bits_base(struct regmap_field
*field
,
1195 unsigned int mask
, unsigned int val
,
1196 bool *change
, bool async
, bool force
)
1198 WARN_ONCE(1, "regmap API is disabled");
1202 static inline int regmap_fields_update_bits_base(struct regmap_field
*field
,
1204 unsigned int mask
, unsigned int val
,
1205 bool *change
, bool async
, bool force
)
1207 WARN_ONCE(1, "regmap API is disabled");
1211 static inline int regmap_get_val_bytes(struct regmap
*map
)
1213 WARN_ONCE(1, "regmap API is disabled");
1217 static inline int regmap_get_max_register(struct regmap
*map
)
1219 WARN_ONCE(1, "regmap API is disabled");
1223 static inline int regmap_get_reg_stride(struct regmap
*map
)
1225 WARN_ONCE(1, "regmap API is disabled");
1229 static inline int regcache_sync(struct regmap
*map
)
1231 WARN_ONCE(1, "regmap API is disabled");
1235 static inline int regcache_sync_region(struct regmap
*map
, unsigned int min
,
1238 WARN_ONCE(1, "regmap API is disabled");
1242 static inline int regcache_drop_region(struct regmap
*map
, unsigned int min
,
1245 WARN_ONCE(1, "regmap API is disabled");
1249 static inline void regcache_cache_only(struct regmap
*map
, bool enable
)
1251 WARN_ONCE(1, "regmap API is disabled");
1254 static inline void regcache_cache_bypass(struct regmap
*map
, bool enable
)
1256 WARN_ONCE(1, "regmap API is disabled");
1259 static inline void regcache_mark_dirty(struct regmap
*map
)
1261 WARN_ONCE(1, "regmap API is disabled");
1264 static inline void regmap_async_complete(struct regmap
*map
)
1266 WARN_ONCE(1, "regmap API is disabled");
1269 static inline int regmap_register_patch(struct regmap
*map
,
1270 const struct reg_sequence
*regs
,
1273 WARN_ONCE(1, "regmap API is disabled");
1277 static inline int regmap_parse_val(struct regmap
*map
, const void *buf
,
1280 WARN_ONCE(1, "regmap API is disabled");
1284 static inline struct regmap
*dev_get_regmap(struct device
*dev
,
1290 static inline struct device
*regmap_get_device(struct regmap
*map
)
1292 WARN_ONCE(1, "regmap API is disabled");