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/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_mmio_clk(struct device *dev, const char *clk_id,
467 const struct regmap_config *config,
468 struct lock_class_key *lock_key,
469 const char *lock_name);
470 struct regmap *__regmap_init_ac97(struct snd_ac97 *ac97,
471 const struct regmap_config *config,
472 struct lock_class_key *lock_key,
473 const char *lock_name);
475 struct regmap *__devm_regmap_init(struct device *dev,
476 const struct regmap_bus *bus,
478 const struct regmap_config *config,
479 struct lock_class_key *lock_key,
480 const char *lock_name);
481 struct regmap *__devm_regmap_init_i2c(struct i2c_client *i2c,
482 const struct regmap_config *config,
483 struct lock_class_key *lock_key,
484 const char *lock_name);
485 struct regmap *__devm_regmap_init_spi(struct spi_device *dev,
486 const struct regmap_config *config,
487 struct lock_class_key *lock_key,
488 const char *lock_name);
489 struct regmap *__devm_regmap_init_spmi_base(struct spmi_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_ext(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_mmio_clk(struct device *dev,
500 const struct regmap_config *config,
501 struct lock_class_key *lock_key,
502 const char *lock_name);
503 struct regmap *__devm_regmap_init_ac97(struct snd_ac97 *ac97,
504 const struct regmap_config *config,
505 struct lock_class_key *lock_key,
506 const char *lock_name);
509 * Wrapper for regmap_init macros to include a unique lockdep key and name
510 * for each call. No-op if CONFIG_LOCKDEP is not set.
512 * @fn: Real function to call (in the form __[*_]regmap_init[_*])
513 * @name: Config variable name (#config in the calling macro)
515 #ifdef CONFIG_LOCKDEP
516 #define __regmap_lockdep_wrapper(fn, name, ...) \
519 static struct lock_class_key _key; \
520 fn(__VA_ARGS__, &_key, \
521 KBUILD_BASENAME ":" \
522 __stringify(__LINE__) ":" \
523 "(" name ")->lock"); \
527 #define __regmap_lockdep_wrapper(fn, name, ...) fn(__VA_ARGS__, NULL, NULL)
531 * regmap_init() - Initialise register map
533 * @dev: Device that will be interacted with
534 * @bus: Bus-specific callbacks to use with device
535 * @bus_context: Data passed to bus-specific callbacks
536 * @config: Configuration for register map
538 * The return value will be an ERR_PTR() on error or a valid pointer to
539 * a struct regmap. This function should generally not be called
540 * directly, it should be called by bus-specific init functions.
542 #define regmap_init(dev, bus, bus_context, config) \
543 __regmap_lockdep_wrapper(__regmap_init, #config, \
544 dev, bus, bus_context, config)
545 int regmap_attach_dev(struct device *dev, struct regmap *map,
546 const struct regmap_config *config);
549 * regmap_init_i2c() - Initialise register map
551 * @i2c: Device that will be interacted with
552 * @config: Configuration for register map
554 * The return value will be an ERR_PTR() on error or a valid pointer to
557 #define regmap_init_i2c(i2c, config) \
558 __regmap_lockdep_wrapper(__regmap_init_i2c, #config, \
562 * regmap_init_spi() - Initialise register map
564 * @dev: Device that will be interacted with
565 * @config: Configuration for register map
567 * The return value will be an ERR_PTR() on error or a valid pointer to
570 #define regmap_init_spi(dev, config) \
571 __regmap_lockdep_wrapper(__regmap_init_spi, #config, \
575 * regmap_init_spmi_base() - Create regmap for the Base register space
577 * @dev: SPMI device that will be interacted with
578 * @config: Configuration for register map
580 * The return value will be an ERR_PTR() on error or a valid pointer to
583 #define regmap_init_spmi_base(dev, config) \
584 __regmap_lockdep_wrapper(__regmap_init_spmi_base, #config, \
588 * regmap_init_spmi_ext() - Create regmap for Ext register space
590 * @dev: Device that will be interacted with
591 * @config: Configuration for register map
593 * The return value will be an ERR_PTR() on error or a valid pointer to
596 #define regmap_init_spmi_ext(dev, config) \
597 __regmap_lockdep_wrapper(__regmap_init_spmi_ext, #config, \
601 * regmap_init_mmio_clk() - Initialise register map with register clock
603 * @dev: Device that will be interacted with
604 * @clk_id: register clock consumer ID
605 * @regs: Pointer to memory-mapped IO region
606 * @config: Configuration for register map
608 * The return value will be an ERR_PTR() on error or a valid pointer to
611 #define regmap_init_mmio_clk(dev, clk_id, regs, config) \
612 __regmap_lockdep_wrapper(__regmap_init_mmio_clk, #config, \
613 dev, clk_id, regs, config)
616 * regmap_init_mmio() - Initialise register map
618 * @dev: Device that will be interacted with
619 * @regs: Pointer to memory-mapped IO region
620 * @config: Configuration for register map
622 * The return value will be an ERR_PTR() on error or a valid pointer to
625 #define regmap_init_mmio(dev, regs, config) \
626 regmap_init_mmio_clk(dev, NULL, regs, config)
629 * regmap_init_ac97() - Initialise AC'97 register map
631 * @ac97: Device that will be interacted with
632 * @config: Configuration for register map
634 * The return value will be an ERR_PTR() on error or a valid pointer to
637 #define regmap_init_ac97(ac97, config) \
638 __regmap_lockdep_wrapper(__regmap_init_ac97, #config, \
640 bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg);
643 * devm_regmap_init() - Initialise managed register map
645 * @dev: Device that will be interacted with
646 * @bus: Bus-specific callbacks to use with device
647 * @bus_context: Data passed to bus-specific callbacks
648 * @config: Configuration for register map
650 * The return value will be an ERR_PTR() on error or a valid pointer
651 * to a struct regmap. This function should generally not be called
652 * directly, it should be called by bus-specific init functions. The
653 * map will be automatically freed by the device management code.
655 #define devm_regmap_init(dev, bus, bus_context, config) \
656 __regmap_lockdep_wrapper(__devm_regmap_init, #config, \
657 dev, bus, bus_context, config)
660 * devm_regmap_init_i2c() - Initialise managed register map
662 * @i2c: Device that will be interacted with
663 * @config: Configuration for register map
665 * The return value will be an ERR_PTR() on error or a valid pointer
666 * to a struct regmap. The regmap will be automatically freed by the
667 * device management code.
669 #define devm_regmap_init_i2c(i2c, config) \
670 __regmap_lockdep_wrapper(__devm_regmap_init_i2c, #config, \
674 * devm_regmap_init_spi() - Initialise register map
676 * @dev: Device that will be interacted with
677 * @config: Configuration for register map
679 * The return value will be an ERR_PTR() on error or a valid pointer
680 * to a struct regmap. The map will be automatically freed by the
681 * device management code.
683 #define devm_regmap_init_spi(dev, config) \
684 __regmap_lockdep_wrapper(__devm_regmap_init_spi, #config, \
688 * devm_regmap_init_spmi_base() - Create managed regmap for Base register space
690 * @dev: SPMI 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
694 * to a struct regmap. The regmap will be automatically freed by the
695 * device management code.
697 #define devm_regmap_init_spmi_base(dev, config) \
698 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_base, #config, \
702 * devm_regmap_init_spmi_ext() - Create managed regmap for Ext register space
704 * @dev: SPMI device that will be interacted with
705 * @config: Configuration for register map
707 * The return value will be an ERR_PTR() on error or a valid pointer
708 * to a struct regmap. The regmap will be automatically freed by the
709 * device management code.
711 #define devm_regmap_init_spmi_ext(dev, config) \
712 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_ext, #config, \
716 * devm_regmap_init_mmio_clk() - Initialise managed register map with clock
718 * @dev: Device that will be interacted with
719 * @clk_id: register clock consumer ID
720 * @regs: Pointer to memory-mapped IO region
721 * @config: Configuration for register map
723 * The return value will be an ERR_PTR() on error or a valid pointer
724 * to a struct regmap. The regmap will be automatically freed by the
725 * device management code.
727 #define devm_regmap_init_mmio_clk(dev, clk_id, regs, config) \
728 __regmap_lockdep_wrapper(__devm_regmap_init_mmio_clk, #config, \
729 dev, clk_id, regs, config)
732 * devm_regmap_init_mmio() - Initialise managed register map
734 * @dev: Device that will be interacted with
735 * @regs: Pointer to memory-mapped IO region
736 * @config: Configuration for register map
738 * The return value will be an ERR_PTR() on error or a valid pointer
739 * to a struct regmap. The regmap will be automatically freed by the
740 * device management code.
742 #define devm_regmap_init_mmio(dev, regs, config) \
743 devm_regmap_init_mmio_clk(dev, NULL, regs, config)
746 * devm_regmap_init_ac97() - Initialise AC'97 register map
748 * @ac97: Device that will be interacted with
749 * @config: Configuration for register map
751 * The return value will be an ERR_PTR() on error or a valid pointer
752 * to a struct regmap. The regmap will be automatically freed by the
753 * device management code.
755 #define devm_regmap_init_ac97(ac97, config) \
756 __regmap_lockdep_wrapper(__devm_regmap_init_ac97, #config, \
759 void regmap_exit(struct regmap *map);
760 int regmap_reinit_cache(struct regmap *map,
761 const struct regmap_config *config);
762 struct regmap *dev_get_regmap(struct device *dev, const char *name);
763 struct device *regmap_get_device(struct regmap *map);
764 int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
765 int regmap_write_async(struct regmap *map, unsigned int reg, unsigned int val);
766 int regmap_raw_write(struct regmap *map, unsigned int reg,
767 const void *val, size_t val_len);
768 int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
770 int regmap_multi_reg_write(struct regmap *map, const struct reg_sequence *regs,
772 int regmap_multi_reg_write_bypassed(struct regmap *map,
773 const struct reg_sequence *regs,
775 int regmap_raw_write_async(struct regmap *map, unsigned int reg,
776 const void *val, size_t val_len);
777 int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
778 int regmap_raw_read(struct regmap *map, unsigned int reg,
779 void *val, size_t val_len);
780 int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
782 int regmap_update_bits_base(struct regmap *map, unsigned int reg,
783 unsigned int mask, unsigned int val,
784 bool *change, bool async, bool force);
785 int regmap_get_val_bytes(struct regmap *map);
786 int regmap_get_max_register(struct regmap *map);
787 int regmap_get_reg_stride(struct regmap *map);
788 int regmap_async_complete(struct regmap *map);
789 bool regmap_can_raw_write(struct regmap *map);
790 size_t regmap_get_raw_read_max(struct regmap *map);
791 size_t regmap_get_raw_write_max(struct regmap *map);
793 int regcache_sync(struct regmap *map);
794 int regcache_sync_region(struct regmap *map, unsigned int min,
796 int regcache_drop_region(struct regmap *map, unsigned int min,
798 void regcache_cache_only(struct regmap *map, bool enable);
799 void regcache_cache_bypass(struct regmap *map, bool enable);
800 void regcache_mark_dirty(struct regmap *map);
802 bool regmap_check_range_table(struct regmap *map, unsigned int reg,
803 const struct regmap_access_table *table);
805 int regmap_register_patch(struct regmap *map, const struct reg_sequence *regs,
807 int regmap_parse_val(struct regmap *map, const void *buf,
810 static inline bool regmap_reg_in_range(unsigned int reg,
811 const struct regmap_range *range)
813 return reg >= range->range_min && reg <= range->range_max;
816 bool regmap_reg_in_ranges(unsigned int reg,
817 const struct regmap_range *ranges,
818 unsigned int nranges);
821 * struct reg_field - Description of an register field
823 * @reg: Offset of the register within the regmap bank
824 * @lsb: lsb of the register field.
825 * @msb: msb of the register field.
826 * @id_size: port size if it has some ports
827 * @id_offset: address offset for each ports
833 unsigned int id_size;
834 unsigned int id_offset;
837 #define REG_FIELD(_reg, _lsb, _msb) { \
843 struct regmap_field *regmap_field_alloc(struct regmap *regmap,
844 struct reg_field reg_field);
845 void regmap_field_free(struct regmap_field *field);
847 struct regmap_field *devm_regmap_field_alloc(struct device *dev,
848 struct regmap *regmap, struct reg_field reg_field);
849 void devm_regmap_field_free(struct device *dev, struct regmap_field *field);
851 int regmap_field_read(struct regmap_field *field, unsigned int *val);
852 int regmap_field_update_bits_base(struct regmap_field *field,
853 unsigned int mask, unsigned int val,
854 bool *change, bool async, bool force);
855 int regmap_fields_read(struct regmap_field *field, unsigned int id,
857 int regmap_fields_update_bits_base(struct regmap_field *field, unsigned int id,
858 unsigned int mask, unsigned int val,
859 bool *change, bool async, bool force);
862 * struct regmap_irq - Description of an IRQ for the generic regmap irq_chip.
864 * @reg_offset: Offset of the status/mask register within the bank
865 * @mask: Mask used to flag/control the register.
866 * @type_reg_offset: Offset register for the irq type setting.
867 * @type_rising_mask: Mask bit to configure RISING type irq.
868 * @type_falling_mask: Mask bit to configure FALLING type irq.
871 unsigned int reg_offset;
873 unsigned int type_reg_offset;
874 unsigned int type_rising_mask;
875 unsigned int type_falling_mask;
878 #define REGMAP_IRQ_REG(_irq, _off, _mask) \
879 [_irq] = { .reg_offset = (_off), .mask = (_mask) }
882 * struct regmap_irq_chip - Description of a generic regmap irq_chip.
884 * @name: Descriptive name for IRQ controller.
886 * @status_base: Base status register address.
887 * @mask_base: Base mask register address.
888 * @unmask_base: Base unmask register address. for chips who have
889 * separate mask and unmask registers
890 * @ack_base: Base ack address. If zero then the chip is clear on read.
891 * Using zero value is possible with @use_ack bit.
892 * @wake_base: Base address for wake enables. If zero unsupported.
893 * @type_base: Base address for irq type. If zero unsupported.
894 * @irq_reg_stride: Stride to use for chips where registers are not contiguous.
895 * @init_ack_masked: Ack all masked interrupts once during initalization.
896 * @mask_invert: Inverted mask register: cleared bits are masked out.
897 * @use_ack: Use @ack register even if it is zero.
898 * @ack_invert: Inverted ack register: cleared bits for ack.
899 * @wake_invert: Inverted wake register: cleared bits are wake enabled.
900 * @type_invert: Invert the type flags.
901 * @runtime_pm: Hold a runtime PM lock on the device when accessing it.
903 * @num_regs: Number of registers in each control bank.
904 * @irqs: Descriptors for individual IRQs. Interrupt numbers are
905 * assigned based on the index in the array of the interrupt.
906 * @num_irqs: Number of descriptors.
907 * @num_type_reg: Number of type registers.
908 * @type_reg_stride: Stride to use for chips where type registers are not
910 * @handle_pre_irq: Driver specific callback to handle interrupt from device
911 * before regmap_irq_handler process the interrupts.
912 * @handle_post_irq: Driver specific callback to handle interrupt from device
913 * after handling the interrupts in regmap_irq_handler().
914 * @irq_drv_data: Driver specific IRQ data which is passed as parameter when
915 * driver specific pre/post interrupt handler is called.
917 * This is not intended to handle every possible interrupt controller, but
918 * it should handle a substantial proportion of those that are found in the
921 struct regmap_irq_chip {
924 unsigned int status_base;
925 unsigned int mask_base;
926 unsigned int unmask_base;
927 unsigned int ack_base;
928 unsigned int wake_base;
929 unsigned int type_base;
930 unsigned int irq_reg_stride;
931 bool init_ack_masked:1;
941 const struct regmap_irq *irqs;
945 unsigned int type_reg_stride;
947 int (*handle_pre_irq)(void *irq_drv_data);
948 int (*handle_post_irq)(void *irq_drv_data);
952 struct regmap_irq_chip_data;
954 int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
955 int irq_base, const struct regmap_irq_chip *chip,
956 struct regmap_irq_chip_data **data);
957 void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data);
959 int devm_regmap_add_irq_chip(struct device *dev, struct regmap *map, int irq,
960 int irq_flags, int irq_base,
961 const struct regmap_irq_chip *chip,
962 struct regmap_irq_chip_data **data);
963 void devm_regmap_del_irq_chip(struct device *dev, int irq,
964 struct regmap_irq_chip_data *data);
966 int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data);
967 int regmap_irq_get_virq(struct regmap_irq_chip_data *data, int irq);
968 struct irq_domain *regmap_irq_get_domain(struct regmap_irq_chip_data *data);
973 * These stubs should only ever be called by generic code which has
974 * regmap based facilities, if they ever get called at runtime
975 * something is going wrong and something probably needs to select
979 static inline int regmap_write(struct regmap *map, unsigned int reg,
982 WARN_ONCE(1, "regmap API is disabled");
986 static inline int regmap_write_async(struct regmap *map, unsigned int reg,
989 WARN_ONCE(1, "regmap API is disabled");
993 static inline int regmap_raw_write(struct regmap *map, unsigned int reg,
994 const void *val, size_t val_len)
996 WARN_ONCE(1, "regmap API is disabled");
1000 static inline int regmap_raw_write_async(struct regmap *map, unsigned int reg,
1001 const void *val, size_t val_len)
1003 WARN_ONCE(1, "regmap API is disabled");
1007 static inline int regmap_bulk_write(struct regmap *map, unsigned int reg,
1008 const void *val, size_t val_count)
1010 WARN_ONCE(1, "regmap API is disabled");
1014 static inline int regmap_read(struct regmap *map, unsigned int reg,
1017 WARN_ONCE(1, "regmap API is disabled");
1021 static inline int regmap_raw_read(struct regmap *map, unsigned int reg,
1022 void *val, size_t val_len)
1024 WARN_ONCE(1, "regmap API is disabled");
1028 static inline int regmap_bulk_read(struct regmap *map, unsigned int reg,
1029 void *val, size_t val_count)
1031 WARN_ONCE(1, "regmap API is disabled");
1035 static inline int regmap_update_bits_base(struct regmap *map, unsigned int reg,
1036 unsigned int mask, unsigned int val,
1037 bool *change, bool async, bool force)
1039 WARN_ONCE(1, "regmap API is disabled");
1043 static inline int regmap_field_update_bits_base(struct regmap_field *field,
1044 unsigned int mask, unsigned int val,
1045 bool *change, bool async, bool force)
1047 WARN_ONCE(1, "regmap API is disabled");
1051 static inline int regmap_fields_update_bits_base(struct regmap_field *field,
1053 unsigned int mask, unsigned int val,
1054 bool *change, bool async, bool force)
1056 WARN_ONCE(1, "regmap API is disabled");
1060 static inline int regmap_get_val_bytes(struct regmap *map)
1062 WARN_ONCE(1, "regmap API is disabled");
1066 static inline int regmap_get_max_register(struct regmap *map)
1068 WARN_ONCE(1, "regmap API is disabled");
1072 static inline int regmap_get_reg_stride(struct regmap *map)
1074 WARN_ONCE(1, "regmap API is disabled");
1078 static inline int regcache_sync(struct regmap *map)
1080 WARN_ONCE(1, "regmap API is disabled");
1084 static inline int regcache_sync_region(struct regmap *map, unsigned int min,
1087 WARN_ONCE(1, "regmap API is disabled");
1091 static inline int regcache_drop_region(struct regmap *map, unsigned int min,
1094 WARN_ONCE(1, "regmap API is disabled");
1098 static inline void regcache_cache_only(struct regmap *map, bool enable)
1100 WARN_ONCE(1, "regmap API is disabled");
1103 static inline void regcache_cache_bypass(struct regmap *map, bool enable)
1105 WARN_ONCE(1, "regmap API is disabled");
1108 static inline void regcache_mark_dirty(struct regmap *map)
1110 WARN_ONCE(1, "regmap API is disabled");
1113 static inline void regmap_async_complete(struct regmap *map)
1115 WARN_ONCE(1, "regmap API is disabled");
1118 static inline int regmap_register_patch(struct regmap *map,
1119 const struct reg_sequence *regs,
1122 WARN_ONCE(1, "regmap API is disabled");
1126 static inline int regmap_parse_val(struct regmap *map, const void *buf,
1129 WARN_ONCE(1, "regmap API is disabled");
1133 static inline struct regmap *dev_get_regmap(struct device *dev,
1139 static inline struct device *regmap_get_device(struct regmap *map)
1141 WARN_ONCE(1, "regmap API is disabled");