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/err.h>
19 #include <linux/bug.h>
20 #include <linux/lockdep.h>
29 struct regmap_range_cfg;
33 /* An enum of all the supported cache types */
42 * struct reg_default - Default value for a register.
44 * @reg: Register address.
45 * @def: Register default value.
47 * We use an array of structs rather than a simple array as many modern devices
48 * have very sparse register maps.
56 * struct reg_sequence - An individual write from a sequence of writes.
58 * @reg: Register address.
59 * @def: Register value.
60 * @delay_us: Delay to be applied after the register write in microseconds
62 * Register/value pairs for sequences of writes with an optional delay in
63 * microseconds to be applied after each write.
68 unsigned int delay_us;
71 #define regmap_update_bits(map, reg, mask, val) \
72 regmap_update_bits_base(map, reg, mask, val, NULL, false, false)
73 #define regmap_update_bits_async(map, reg, mask, val)\
74 regmap_update_bits_base(map, reg, mask, val, NULL, true, false)
75 #define regmap_update_bits_check(map, reg, mask, val, change)\
76 regmap_update_bits_base(map, reg, mask, val, change, false, false)
77 #define regmap_update_bits_check_async(map, reg, mask, val, change)\
78 regmap_update_bits_base(map, reg, mask, val, change, true, false)
80 #define regmap_write_bits(map, reg, mask, val) \
81 regmap_update_bits_base(map, reg, mask, val, NULL, false, true)
83 #define regmap_field_write(field, val) \
84 regmap_field_update_bits_base(field, ~0, val, NULL, false, false)
85 #define regmap_field_force_write(field, val) \
86 regmap_field_update_bits_base(field, ~0, val, NULL, false, true)
87 #define regmap_field_update_bits(field, mask, val)\
88 regmap_field_update_bits_base(field, mask, val, NULL, false, false)
89 #define regmap_field_force_update_bits(field, mask, val) \
90 regmap_field_update_bits_base(field, mask, val, NULL, false, true)
92 #define regmap_fields_write(field, id, val) \
93 regmap_fields_update_bits_base(field, id, ~0, val, NULL, false, false)
94 #define regmap_fields_force_write(field, id, val) \
95 regmap_fields_update_bits_base(field, id, ~0, val, NULL, false, true)
96 #define regmap_fields_update_bits(field, id, mask, val)\
97 regmap_fields_update_bits_base(field, id, mask, val, NULL, false, false)
98 #define regmap_fields_force_update_bits(field, id, mask, val) \
99 regmap_fields_update_bits_base(field, id, mask, val, NULL, false, true)
102 * regmap_read_poll_timeout - Poll until a condition is met or a timeout occurs
104 * @map: Regmap to read from
105 * @addr: Address to poll
106 * @val: Unsigned integer variable to read the value into
107 * @cond: Break condition (usually involving @val)
108 * @sleep_us: Maximum time to sleep between reads in us (0
109 * tight-loops). Should be less than ~20ms since usleep_range
110 * is used (see Documentation/timers/timers-howto.txt).
111 * @timeout_us: Timeout in us, 0 means never timeout
113 * Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_read
114 * error return value in case of a error read. In the two former cases,
115 * the last read value at @addr is stored in @val. Must not be called
116 * from atomic context if sleep_us or timeout_us are used.
118 * This is modelled after the readx_poll_timeout macros in linux/iopoll.h.
120 #define regmap_read_poll_timeout(map, addr, val, cond, sleep_us, timeout_us) \
122 ktime_t timeout = ktime_add_us(ktime_get(), timeout_us); \
124 might_sleep_if(sleep_us); \
126 ret = regmap_read((map), (addr), &(val)); \
131 if (timeout_us && ktime_compare(ktime_get(), timeout) > 0) { \
132 ret = regmap_read((map), (addr), &(val)); \
136 usleep_range((sleep_us >> 2) + 1, sleep_us); \
138 ret ?: ((cond) ? 0 : -ETIMEDOUT); \
144 /* Unspecified -> 0 -> Backwards compatible default */
145 REGMAP_ENDIAN_DEFAULT = 0,
147 REGMAP_ENDIAN_LITTLE,
148 REGMAP_ENDIAN_NATIVE,
152 * struct regmap_range - A register range, used for access related checks
153 * (readable/writeable/volatile/precious checks)
155 * @range_min: address of first register
156 * @range_max: address of last register
158 struct regmap_range {
159 unsigned int range_min;
160 unsigned int range_max;
163 #define regmap_reg_range(low, high) { .range_min = low, .range_max = high, }
166 * struct regmap_access_table - A table of register ranges for access checks
168 * @yes_ranges : pointer to an array of regmap ranges used as "yes ranges"
169 * @n_yes_ranges: size of the above array
170 * @no_ranges: pointer to an array of regmap ranges used as "no ranges"
171 * @n_no_ranges: size of the above array
173 * A table of ranges including some yes ranges and some no ranges.
174 * If a register belongs to a no_range, the corresponding check function
175 * will return false. If a register belongs to a yes range, the corresponding
176 * check function will return true. "no_ranges" are searched first.
178 struct regmap_access_table {
179 const struct regmap_range *yes_ranges;
180 unsigned int n_yes_ranges;
181 const struct regmap_range *no_ranges;
182 unsigned int n_no_ranges;
185 typedef void (*regmap_lock)(void *);
186 typedef void (*regmap_unlock)(void *);
189 * struct regmap_config - Configuration for the register map of a device.
191 * @name: Optional name of the regmap. Useful when a device has multiple
194 * @reg_bits: Number of bits in a register address, mandatory.
195 * @reg_stride: The register address stride. Valid register addresses are a
196 * multiple of this value. If set to 0, a value of 1 will be
198 * @pad_bits: Number of bits of padding between register and value.
199 * @val_bits: Number of bits in a register value, mandatory.
201 * @writeable_reg: Optional callback returning true if the register
202 * can be written to. If this field is NULL but wr_table
203 * (see below) is not, the check is performed on such table
204 * (a register is writeable if it belongs to one of the ranges
205 * specified by wr_table).
206 * @readable_reg: Optional callback returning true if the register
207 * can be read from. If this field is NULL but rd_table
208 * (see below) is not, the check is performed on such table
209 * (a register is readable if it belongs to one of the ranges
210 * specified by rd_table).
211 * @volatile_reg: Optional callback returning true if the register
212 * value can't be cached. If this field is NULL but
213 * volatile_table (see below) is not, the check is performed on
214 * such table (a register is volatile if it belongs to one of
215 * the ranges specified by volatile_table).
216 * @precious_reg: Optional callback returning true if the register
217 * should not be read outside of a call from the driver
218 * (e.g., a clear on read interrupt status register). If this
219 * field is NULL but precious_table (see below) is not, the
220 * check is performed on such table (a register is precious if
221 * it belongs to one of the ranges specified by precious_table).
222 * @lock: Optional lock callback (overrides regmap's default lock
223 * function, based on spinlock or mutex).
224 * @unlock: As above for unlocking.
225 * @lock_arg: this field is passed as the only argument of lock/unlock
226 * functions (ignored in case regular lock/unlock functions
227 * are not overridden).
228 * @reg_read: Optional callback that if filled will be used to perform
229 * all the reads from the registers. Should only be provided for
230 * devices whose read operation cannot be represented as a simple
231 * read operation on a bus such as SPI, I2C, etc. Most of the
232 * devices do not need this.
233 * @reg_write: Same as above for writing.
234 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
235 * to perform locking. This field is ignored if custom lock/unlock
236 * functions are used (see fields lock/unlock of struct regmap_config).
237 * This field is a duplicate of a similar file in
238 * 'struct regmap_bus' and serves exact same purpose.
239 * Use it only for "no-bus" cases.
240 * @max_register: Optional, specifies the maximum valid register address.
241 * @wr_table: Optional, points to a struct regmap_access_table specifying
242 * valid ranges for write access.
243 * @rd_table: As above, for read access.
244 * @volatile_table: As above, for volatile registers.
245 * @precious_table: As above, for precious registers.
246 * @reg_defaults: Power on reset values for registers (for use with
247 * register cache support).
248 * @num_reg_defaults: Number of elements in reg_defaults.
250 * @read_flag_mask: Mask to be set in the top bytes of the register when doing
252 * @write_flag_mask: Mask to be set in the top bytes of the register when doing
253 * a write. If both read_flag_mask and write_flag_mask are
254 * empty the regmap_bus default masks are used.
255 * @use_single_rw: If set, converts the bulk read and write operations into
256 * a series of single read and write operations. This is useful
257 * for device that does not support bulk read and write.
258 * @can_multi_write: If set, the device supports the multi write mode of bulk
259 * write operations, if clear multi write requests will be
260 * split into individual write operations
262 * @cache_type: The actual cache type.
263 * @reg_defaults_raw: Power on reset values for registers (for use with
264 * register cache support).
265 * @num_reg_defaults_raw: Number of elements in reg_defaults_raw.
266 * @reg_format_endian: Endianness for formatted register addresses. If this is
267 * DEFAULT, the @reg_format_endian_default value from the
268 * regmap bus is used.
269 * @val_format_endian: Endianness for formatted register values. If this is
270 * DEFAULT, the @reg_format_endian_default value from the
271 * regmap bus is used.
273 * @ranges: Array of configuration entries for virtual address ranges.
274 * @num_ranges: Number of range configuration entries.
276 struct regmap_config {
284 bool (*writeable_reg)(struct device *dev, unsigned int reg);
285 bool (*readable_reg)(struct device *dev, unsigned int reg);
286 bool (*volatile_reg)(struct device *dev, unsigned int reg);
287 bool (*precious_reg)(struct device *dev, unsigned int reg);
289 regmap_unlock unlock;
292 int (*reg_read)(void *context, unsigned int reg, unsigned int *val);
293 int (*reg_write)(void *context, unsigned int reg, unsigned int val);
297 unsigned int max_register;
298 const struct regmap_access_table *wr_table;
299 const struct regmap_access_table *rd_table;
300 const struct regmap_access_table *volatile_table;
301 const struct regmap_access_table *precious_table;
302 const struct reg_default *reg_defaults;
303 unsigned int num_reg_defaults;
304 enum regcache_type cache_type;
305 const void *reg_defaults_raw;
306 unsigned int num_reg_defaults_raw;
308 unsigned long read_flag_mask;
309 unsigned long write_flag_mask;
312 bool can_multi_write;
314 enum regmap_endian reg_format_endian;
315 enum regmap_endian val_format_endian;
317 const struct regmap_range_cfg *ranges;
318 unsigned int num_ranges;
322 * struct regmap_range_cfg - Configuration for indirectly accessed or paged
325 * @name: Descriptive name for diagnostics
327 * @range_min: Address of the lowest register address in virtual range.
328 * @range_max: Address of the highest register in virtual range.
330 * @selector_reg: Register with selector field.
331 * @selector_mask: Bit shift for selector value.
332 * @selector_shift: Bit mask for selector value.
334 * @window_start: Address of first (lowest) register in data window.
335 * @window_len: Number of registers in data window.
337 * Registers, mapped to this virtual range, are accessed in two steps:
338 * 1. page selector register update;
339 * 2. access through data window registers.
341 struct regmap_range_cfg {
344 /* Registers of virtual address range */
345 unsigned int range_min;
346 unsigned int range_max;
348 /* Page selector for indirect addressing */
349 unsigned int selector_reg;
350 unsigned int selector_mask;
353 /* Data window (per each page) */
354 unsigned int window_start;
355 unsigned int window_len;
360 typedef int (*regmap_hw_write)(void *context, const void *data,
362 typedef int (*regmap_hw_gather_write)(void *context,
363 const void *reg, size_t reg_len,
364 const void *val, size_t val_len);
365 typedef int (*regmap_hw_async_write)(void *context,
366 const void *reg, size_t reg_len,
367 const void *val, size_t val_len,
368 struct regmap_async *async);
369 typedef int (*regmap_hw_read)(void *context,
370 const void *reg_buf, size_t reg_size,
371 void *val_buf, size_t val_size);
372 typedef int (*regmap_hw_reg_read)(void *context, unsigned int reg,
374 typedef int (*regmap_hw_reg_write)(void *context, unsigned int reg,
376 typedef int (*regmap_hw_reg_update_bits)(void *context, unsigned int reg,
377 unsigned int mask, unsigned int val);
378 typedef struct regmap_async *(*regmap_hw_async_alloc)(void);
379 typedef void (*regmap_hw_free_context)(void *context);
382 * struct regmap_bus - Description of a hardware bus for the register map
385 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
386 * to perform locking. This field is ignored if custom lock/unlock
387 * functions are used (see fields lock/unlock of
388 * struct regmap_config).
389 * @write: Write operation.
390 * @gather_write: Write operation with split register/value, return -ENOTSUPP
391 * if not implemented on a given device.
392 * @async_write: Write operation which completes asynchronously, optional and
393 * must serialise with respect to non-async I/O.
394 * @reg_write: Write a single register value to the given register address. This
395 * write operation has to complete when returning from the function.
396 * @reg_update_bits: Update bits operation to be used against volatile
397 * registers, intended for devices supporting some mechanism
398 * for setting clearing bits without having to
400 * @read: Read operation. Data is returned in the buffer used to transmit
402 * @reg_read: Read a single register value from a given register address.
403 * @free_context: Free context.
404 * @async_alloc: Allocate a regmap_async() structure.
405 * @read_flag_mask: Mask to be set in the top byte of the register when doing
407 * @reg_format_endian_default: Default endianness for formatted register
408 * addresses. Used when the regmap_config specifies DEFAULT. If this is
409 * DEFAULT, BIG is assumed.
410 * @val_format_endian_default: Default endianness for formatted register
411 * values. Used when the regmap_config specifies DEFAULT. If this is
412 * DEFAULT, BIG is assumed.
413 * @max_raw_read: Max raw read size that can be used on the bus.
414 * @max_raw_write: Max raw write size that can be used on the bus.
418 regmap_hw_write write;
419 regmap_hw_gather_write gather_write;
420 regmap_hw_async_write async_write;
421 regmap_hw_reg_write reg_write;
422 regmap_hw_reg_update_bits reg_update_bits;
424 regmap_hw_reg_read reg_read;
425 regmap_hw_free_context free_context;
426 regmap_hw_async_alloc async_alloc;
428 enum regmap_endian reg_format_endian_default;
429 enum regmap_endian val_format_endian_default;
431 size_t max_raw_write;
435 * __regmap_init functions.
437 * These functions take a lock key and name parameter, and should not be called
438 * directly. Instead, use the regmap_init macros that generate a key and name
441 struct regmap *__regmap_init(struct device *dev,
442 const struct regmap_bus *bus,
444 const struct regmap_config *config,
445 struct lock_class_key *lock_key,
446 const char *lock_name);
447 struct regmap *__regmap_init_i2c(struct i2c_client *i2c,
448 const struct regmap_config *config,
449 struct lock_class_key *lock_key,
450 const char *lock_name);
451 struct regmap *__regmap_init_spi(struct spi_device *dev,
452 const struct regmap_config *config,
453 struct lock_class_key *lock_key,
454 const char *lock_name);
455 struct regmap *__regmap_init_spmi_base(struct spmi_device *dev,
456 const struct regmap_config *config,
457 struct lock_class_key *lock_key,
458 const char *lock_name);
459 struct regmap *__regmap_init_spmi_ext(struct spmi_device *dev,
460 const struct regmap_config *config,
461 struct lock_class_key *lock_key,
462 const char *lock_name);
463 struct regmap *__regmap_init_mmio_clk(struct device *dev, const char *clk_id,
465 const struct regmap_config *config,
466 struct lock_class_key *lock_key,
467 const char *lock_name);
468 struct regmap *__regmap_init_ac97(struct snd_ac97 *ac97,
469 const struct regmap_config *config,
470 struct lock_class_key *lock_key,
471 const char *lock_name);
473 struct regmap *__devm_regmap_init(struct device *dev,
474 const struct regmap_bus *bus,
476 const struct regmap_config *config,
477 struct lock_class_key *lock_key,
478 const char *lock_name);
479 struct regmap *__devm_regmap_init_i2c(struct i2c_client *i2c,
480 const struct regmap_config *config,
481 struct lock_class_key *lock_key,
482 const char *lock_name);
483 struct regmap *__devm_regmap_init_spi(struct spi_device *dev,
484 const struct regmap_config *config,
485 struct lock_class_key *lock_key,
486 const char *lock_name);
487 struct regmap *__devm_regmap_init_spmi_base(struct spmi_device *dev,
488 const struct regmap_config *config,
489 struct lock_class_key *lock_key,
490 const char *lock_name);
491 struct regmap *__devm_regmap_init_spmi_ext(struct spmi_device *dev,
492 const struct regmap_config *config,
493 struct lock_class_key *lock_key,
494 const char *lock_name);
495 struct regmap *__devm_regmap_init_mmio_clk(struct 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_ac97(struct snd_ac97 *ac97,
502 const struct regmap_config *config,
503 struct lock_class_key *lock_key,
504 const char *lock_name);
507 * Wrapper for regmap_init macros to include a unique lockdep key and name
508 * for each call. No-op if CONFIG_LOCKDEP is not set.
510 * @fn: Real function to call (in the form __[*_]regmap_init[_*])
511 * @name: Config variable name (#config in the calling macro)
513 #ifdef CONFIG_LOCKDEP
514 #define __regmap_lockdep_wrapper(fn, name, ...) \
517 static struct lock_class_key _key; \
518 fn(__VA_ARGS__, &_key, \
519 KBUILD_BASENAME ":" \
520 __stringify(__LINE__) ":" \
521 "(" name ")->lock"); \
525 #define __regmap_lockdep_wrapper(fn, name, ...) fn(__VA_ARGS__, NULL, NULL)
529 * regmap_init() - Initialise register map
531 * @dev: Device that will be interacted with
532 * @bus: Bus-specific callbacks to use with device
533 * @bus_context: Data passed to bus-specific callbacks
534 * @config: Configuration for register map
536 * The return value will be an ERR_PTR() on error or a valid pointer to
537 * a struct regmap. This function should generally not be called
538 * directly, it should be called by bus-specific init functions.
540 #define regmap_init(dev, bus, bus_context, config) \
541 __regmap_lockdep_wrapper(__regmap_init, #config, \
542 dev, bus, bus_context, config)
543 int regmap_attach_dev(struct device *dev, struct regmap *map,
544 const struct regmap_config *config);
547 * regmap_init_i2c() - Initialise register map
549 * @i2c: Device that will be interacted with
550 * @config: Configuration for register map
552 * The return value will be an ERR_PTR() on error or a valid pointer to
555 #define regmap_init_i2c(i2c, config) \
556 __regmap_lockdep_wrapper(__regmap_init_i2c, #config, \
560 * regmap_init_spi() - Initialise register map
562 * @dev: Device that will be interacted with
563 * @config: Configuration for register map
565 * The return value will be an ERR_PTR() on error or a valid pointer to
568 #define regmap_init_spi(dev, config) \
569 __regmap_lockdep_wrapper(__regmap_init_spi, #config, \
573 * regmap_init_spmi_base() - Create regmap for the Base register space
575 * @dev: SPMI device that will be interacted with
576 * @config: Configuration for register map
578 * The return value will be an ERR_PTR() on error or a valid pointer to
581 #define regmap_init_spmi_base(dev, config) \
582 __regmap_lockdep_wrapper(__regmap_init_spmi_base, #config, \
586 * regmap_init_spmi_ext() - Create regmap for Ext register space
588 * @dev: Device that will be interacted with
589 * @config: Configuration for register map
591 * The return value will be an ERR_PTR() on error or a valid pointer to
594 #define regmap_init_spmi_ext(dev, config) \
595 __regmap_lockdep_wrapper(__regmap_init_spmi_ext, #config, \
599 * regmap_init_mmio_clk() - Initialise register map with register clock
601 * @dev: Device that will be interacted with
602 * @clk_id: register clock consumer ID
603 * @regs: Pointer to memory-mapped IO region
604 * @config: Configuration for register map
606 * The return value will be an ERR_PTR() on error or a valid pointer to
609 #define regmap_init_mmio_clk(dev, clk_id, regs, config) \
610 __regmap_lockdep_wrapper(__regmap_init_mmio_clk, #config, \
611 dev, clk_id, regs, config)
614 * regmap_init_mmio() - Initialise register map
616 * @dev: Device that will be interacted with
617 * @regs: Pointer to memory-mapped IO region
618 * @config: Configuration for register map
620 * The return value will be an ERR_PTR() on error or a valid pointer to
623 #define regmap_init_mmio(dev, regs, config) \
624 regmap_init_mmio_clk(dev, NULL, regs, config)
627 * regmap_init_ac97() - Initialise AC'97 register map
629 * @ac97: Device that will be interacted with
630 * @config: Configuration for register map
632 * The return value will be an ERR_PTR() on error or a valid pointer to
635 #define regmap_init_ac97(ac97, config) \
636 __regmap_lockdep_wrapper(__regmap_init_ac97, #config, \
638 bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg);
641 * devm_regmap_init() - Initialise managed register map
643 * @dev: Device that will be interacted with
644 * @bus: Bus-specific callbacks to use with device
645 * @bus_context: Data passed to bus-specific callbacks
646 * @config: Configuration for register map
648 * The return value will be an ERR_PTR() on error or a valid pointer
649 * to a struct regmap. This function should generally not be called
650 * directly, it should be called by bus-specific init functions. The
651 * map will be automatically freed by the device management code.
653 #define devm_regmap_init(dev, bus, bus_context, config) \
654 __regmap_lockdep_wrapper(__devm_regmap_init, #config, \
655 dev, bus, bus_context, config)
658 * devm_regmap_init_i2c() - Initialise managed register map
660 * @i2c: Device that will be interacted with
661 * @config: Configuration for register map
663 * The return value will be an ERR_PTR() on error or a valid pointer
664 * to a struct regmap. The regmap will be automatically freed by the
665 * device management code.
667 #define devm_regmap_init_i2c(i2c, config) \
668 __regmap_lockdep_wrapper(__devm_regmap_init_i2c, #config, \
672 * devm_regmap_init_spi() - Initialise register map
674 * @dev: Device that will be interacted with
675 * @config: Configuration for register map
677 * The return value will be an ERR_PTR() on error or a valid pointer
678 * to a struct regmap. The map will be automatically freed by the
679 * device management code.
681 #define devm_regmap_init_spi(dev, config) \
682 __regmap_lockdep_wrapper(__devm_regmap_init_spi, #config, \
686 * devm_regmap_init_spmi_base() - Create managed regmap for Base register space
688 * @dev: SPMI device that will be interacted with
689 * @config: Configuration for register map
691 * The return value will be an ERR_PTR() on error or a valid pointer
692 * to a struct regmap. The regmap will be automatically freed by the
693 * device management code.
695 #define devm_regmap_init_spmi_base(dev, config) \
696 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_base, #config, \
700 * devm_regmap_init_spmi_ext() - Create managed regmap for Ext register space
702 * @dev: SPMI device that will be interacted with
703 * @config: Configuration for register map
705 * The return value will be an ERR_PTR() on error or a valid pointer
706 * to a struct regmap. The regmap will be automatically freed by the
707 * device management code.
709 #define devm_regmap_init_spmi_ext(dev, config) \
710 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_ext, #config, \
714 * devm_regmap_init_mmio_clk() - Initialise managed register map with clock
716 * @dev: Device that will be interacted with
717 * @clk_id: register clock consumer ID
718 * @regs: Pointer to memory-mapped IO region
719 * @config: Configuration for register map
721 * The return value will be an ERR_PTR() on error or a valid pointer
722 * to a struct regmap. The regmap will be automatically freed by the
723 * device management code.
725 #define devm_regmap_init_mmio_clk(dev, clk_id, regs, config) \
726 __regmap_lockdep_wrapper(__devm_regmap_init_mmio_clk, #config, \
727 dev, clk_id, regs, config)
730 * devm_regmap_init_mmio() - Initialise managed register map
732 * @dev: Device that will be interacted with
733 * @regs: Pointer to memory-mapped IO region
734 * @config: Configuration for register map
736 * The return value will be an ERR_PTR() on error or a valid pointer
737 * to a struct regmap. The regmap will be automatically freed by the
738 * device management code.
740 #define devm_regmap_init_mmio(dev, regs, config) \
741 devm_regmap_init_mmio_clk(dev, NULL, regs, config)
744 * devm_regmap_init_ac97() - Initialise AC'97 register map
746 * @ac97: Device that will be interacted with
747 * @config: Configuration for register map
749 * The return value will be an ERR_PTR() on error or a valid pointer
750 * to a struct regmap. The regmap will be automatically freed by the
751 * device management code.
753 #define devm_regmap_init_ac97(ac97, config) \
754 __regmap_lockdep_wrapper(__devm_regmap_init_ac97, #config, \
757 void regmap_exit(struct regmap *map);
758 int regmap_reinit_cache(struct regmap *map,
759 const struct regmap_config *config);
760 struct regmap *dev_get_regmap(struct device *dev, const char *name);
761 struct device *regmap_get_device(struct regmap *map);
762 int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
763 int regmap_write_async(struct regmap *map, unsigned int reg, unsigned int val);
764 int regmap_raw_write(struct regmap *map, unsigned int reg,
765 const void *val, size_t val_len);
766 int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
768 int regmap_multi_reg_write(struct regmap *map, const struct reg_sequence *regs,
770 int regmap_multi_reg_write_bypassed(struct regmap *map,
771 const struct reg_sequence *regs,
773 int regmap_raw_write_async(struct regmap *map, unsigned int reg,
774 const void *val, size_t val_len);
775 int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
776 int regmap_raw_read(struct regmap *map, unsigned int reg,
777 void *val, size_t val_len);
778 int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
780 int regmap_update_bits_base(struct regmap *map, unsigned int reg,
781 unsigned int mask, unsigned int val,
782 bool *change, bool async, bool force);
783 int regmap_get_val_bytes(struct regmap *map);
784 int regmap_get_max_register(struct regmap *map);
785 int regmap_get_reg_stride(struct regmap *map);
786 int regmap_async_complete(struct regmap *map);
787 bool regmap_can_raw_write(struct regmap *map);
788 size_t regmap_get_raw_read_max(struct regmap *map);
789 size_t regmap_get_raw_write_max(struct regmap *map);
791 int regcache_sync(struct regmap *map);
792 int regcache_sync_region(struct regmap *map, unsigned int min,
794 int regcache_drop_region(struct regmap *map, unsigned int min,
796 void regcache_cache_only(struct regmap *map, bool enable);
797 void regcache_cache_bypass(struct regmap *map, bool enable);
798 void regcache_mark_dirty(struct regmap *map);
800 bool regmap_check_range_table(struct regmap *map, unsigned int reg,
801 const struct regmap_access_table *table);
803 int regmap_register_patch(struct regmap *map, const struct reg_sequence *regs,
805 int regmap_parse_val(struct regmap *map, const void *buf,
808 static inline bool regmap_reg_in_range(unsigned int reg,
809 const struct regmap_range *range)
811 return reg >= range->range_min && reg <= range->range_max;
814 bool regmap_reg_in_ranges(unsigned int reg,
815 const struct regmap_range *ranges,
816 unsigned int nranges);
819 * struct reg_field - Description of an register field
821 * @reg: Offset of the register within the regmap bank
822 * @lsb: lsb of the register field.
823 * @msb: msb of the register field.
824 * @id_size: port size if it has some ports
825 * @id_offset: address offset for each ports
831 unsigned int id_size;
832 unsigned int id_offset;
835 #define REG_FIELD(_reg, _lsb, _msb) { \
841 struct regmap_field *regmap_field_alloc(struct regmap *regmap,
842 struct reg_field reg_field);
843 void regmap_field_free(struct regmap_field *field);
845 struct regmap_field *devm_regmap_field_alloc(struct device *dev,
846 struct regmap *regmap, struct reg_field reg_field);
847 void devm_regmap_field_free(struct device *dev, struct regmap_field *field);
849 int regmap_field_read(struct regmap_field *field, unsigned int *val);
850 int regmap_field_update_bits_base(struct regmap_field *field,
851 unsigned int mask, unsigned int val,
852 bool *change, bool async, bool force);
853 int regmap_fields_read(struct regmap_field *field, unsigned int id,
855 int regmap_fields_update_bits_base(struct regmap_field *field, unsigned int id,
856 unsigned int mask, unsigned int val,
857 bool *change, bool async, bool force);
860 * struct regmap_irq - Description of an IRQ for the generic regmap irq_chip.
862 * @reg_offset: Offset of the status/mask register within the bank
863 * @mask: Mask used to flag/control the register.
864 * @type_reg_offset: Offset register for the irq type setting.
865 * @type_rising_mask: Mask bit to configure RISING type irq.
866 * @type_falling_mask: Mask bit to configure FALLING type irq.
869 unsigned int reg_offset;
871 unsigned int type_reg_offset;
872 unsigned int type_rising_mask;
873 unsigned int type_falling_mask;
876 #define REGMAP_IRQ_REG(_irq, _off, _mask) \
877 [_irq] = { .reg_offset = (_off), .mask = (_mask) }
880 * struct regmap_irq_chip - Description of a generic regmap irq_chip.
882 * @name: Descriptive name for IRQ controller.
884 * @status_base: Base status register address.
885 * @mask_base: Base mask register address.
886 * @unmask_base: Base unmask register address. for chips who have
887 * separate mask and unmask registers
888 * @ack_base: Base ack address. If zero then the chip is clear on read.
889 * Using zero value is possible with @use_ack bit.
890 * @wake_base: Base address for wake enables. If zero unsupported.
891 * @type_base: Base address for irq type. If zero unsupported.
892 * @irq_reg_stride: Stride to use for chips where registers are not contiguous.
893 * @init_ack_masked: Ack all masked interrupts once during initalization.
894 * @mask_invert: Inverted mask register: cleared bits are masked out.
895 * @use_ack: Use @ack register even if it is zero.
896 * @ack_invert: Inverted ack register: cleared bits for ack.
897 * @wake_invert: Inverted wake register: cleared bits are wake enabled.
898 * @type_invert: Invert the type flags.
899 * @runtime_pm: Hold a runtime PM lock on the device when accessing it.
901 * @num_regs: Number of registers in each control bank.
902 * @irqs: Descriptors for individual IRQs. Interrupt numbers are
903 * assigned based on the index in the array of the interrupt.
904 * @num_irqs: Number of descriptors.
905 * @num_type_reg: Number of type registers.
906 * @type_reg_stride: Stride to use for chips where type registers are not
908 * @handle_pre_irq: Driver specific callback to handle interrupt from device
909 * before regmap_irq_handler process the interrupts.
910 * @handle_post_irq: Driver specific callback to handle interrupt from device
911 * after handling the interrupts in regmap_irq_handler().
912 * @irq_drv_data: Driver specific IRQ data which is passed as parameter when
913 * driver specific pre/post interrupt handler is called.
915 * This is not intended to handle every possible interrupt controller, but
916 * it should handle a substantial proportion of those that are found in the
919 struct regmap_irq_chip {
922 unsigned int status_base;
923 unsigned int mask_base;
924 unsigned int unmask_base;
925 unsigned int ack_base;
926 unsigned int wake_base;
927 unsigned int type_base;
928 unsigned int irq_reg_stride;
929 bool init_ack_masked:1;
939 const struct regmap_irq *irqs;
943 unsigned int type_reg_stride;
945 int (*handle_pre_irq)(void *irq_drv_data);
946 int (*handle_post_irq)(void *irq_drv_data);
950 struct regmap_irq_chip_data;
952 int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
953 int irq_base, const struct regmap_irq_chip *chip,
954 struct regmap_irq_chip_data **data);
955 void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data);
957 int devm_regmap_add_irq_chip(struct device *dev, struct regmap *map, int irq,
958 int irq_flags, int irq_base,
959 const struct regmap_irq_chip *chip,
960 struct regmap_irq_chip_data **data);
961 void devm_regmap_del_irq_chip(struct device *dev, int irq,
962 struct regmap_irq_chip_data *data);
964 int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data);
965 int regmap_irq_get_virq(struct regmap_irq_chip_data *data, int irq);
966 struct irq_domain *regmap_irq_get_domain(struct regmap_irq_chip_data *data);
971 * These stubs should only ever be called by generic code which has
972 * regmap based facilities, if they ever get called at runtime
973 * something is going wrong and something probably needs to select
977 static inline int regmap_write(struct regmap *map, unsigned int reg,
980 WARN_ONCE(1, "regmap API is disabled");
984 static inline int regmap_write_async(struct regmap *map, unsigned int reg,
987 WARN_ONCE(1, "regmap API is disabled");
991 static inline int regmap_raw_write(struct regmap *map, unsigned int reg,
992 const void *val, size_t val_len)
994 WARN_ONCE(1, "regmap API is disabled");
998 static inline int regmap_raw_write_async(struct regmap *map, unsigned int reg,
999 const void *val, size_t val_len)
1001 WARN_ONCE(1, "regmap API is disabled");
1005 static inline int regmap_bulk_write(struct regmap *map, unsigned int reg,
1006 const void *val, size_t val_count)
1008 WARN_ONCE(1, "regmap API is disabled");
1012 static inline int regmap_read(struct regmap *map, unsigned int reg,
1015 WARN_ONCE(1, "regmap API is disabled");
1019 static inline int regmap_raw_read(struct regmap *map, unsigned int reg,
1020 void *val, size_t val_len)
1022 WARN_ONCE(1, "regmap API is disabled");
1026 static inline int regmap_bulk_read(struct regmap *map, unsigned int reg,
1027 void *val, size_t val_count)
1029 WARN_ONCE(1, "regmap API is disabled");
1033 static inline int regmap_update_bits_base(struct regmap *map, unsigned int reg,
1034 unsigned int mask, unsigned int val,
1035 bool *change, bool async, bool force)
1037 WARN_ONCE(1, "regmap API is disabled");
1041 static inline int regmap_field_update_bits_base(struct regmap_field *field,
1042 unsigned int mask, unsigned int val,
1043 bool *change, bool async, bool force)
1045 WARN_ONCE(1, "regmap API is disabled");
1049 static inline int regmap_fields_update_bits_base(struct regmap_field *field,
1051 unsigned int mask, unsigned int val,
1052 bool *change, bool async, bool force)
1054 WARN_ONCE(1, "regmap API is disabled");
1058 static inline int regmap_get_val_bytes(struct regmap *map)
1060 WARN_ONCE(1, "regmap API is disabled");
1064 static inline int regmap_get_max_register(struct regmap *map)
1066 WARN_ONCE(1, "regmap API is disabled");
1070 static inline int regmap_get_reg_stride(struct regmap *map)
1072 WARN_ONCE(1, "regmap API is disabled");
1076 static inline int regcache_sync(struct regmap *map)
1078 WARN_ONCE(1, "regmap API is disabled");
1082 static inline int regcache_sync_region(struct regmap *map, unsigned int min,
1085 WARN_ONCE(1, "regmap API is disabled");
1089 static inline int regcache_drop_region(struct regmap *map, unsigned int min,
1092 WARN_ONCE(1, "regmap API is disabled");
1096 static inline void regcache_cache_only(struct regmap *map, bool enable)
1098 WARN_ONCE(1, "regmap API is disabled");
1101 static inline void regcache_cache_bypass(struct regmap *map, bool enable)
1103 WARN_ONCE(1, "regmap API is disabled");
1106 static inline void regcache_mark_dirty(struct regmap *map)
1108 WARN_ONCE(1, "regmap API is disabled");
1111 static inline void regmap_async_complete(struct regmap *map)
1113 WARN_ONCE(1, "regmap API is disabled");
1116 static inline int regmap_register_patch(struct regmap *map,
1117 const struct reg_sequence *regs,
1120 WARN_ONCE(1, "regmap API is disabled");
1124 static inline int regmap_parse_val(struct regmap *map, const void *buf,
1127 WARN_ONCE(1, "regmap API is disabled");
1131 static inline struct regmap *dev_get_regmap(struct device *dev,
1137 static inline struct device *regmap_get_device(struct regmap *map)
1139 WARN_ONCE(1, "regmap API is disabled");