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 * Default value for a register. We use an array of structs rather
43 * than a simple array as many modern devices have very sparse
46 * @reg: Register address.
47 * @def: Register default value.
55 * Register/value pairs for sequences of writes with an optional delay in
56 * microseconds to be applied after each write.
58 * @reg: Register address.
59 * @def: Register value.
60 * @delay_us: Delay to be applied after the register write in microseconds
65 unsigned int delay_us;
68 #define regmap_update_bits(map, reg, mask, val) \
69 regmap_update_bits_base(map, reg, mask, val, NULL, false, false)
70 #define regmap_update_bits_async(map, reg, mask, val)\
71 regmap_update_bits_base(map, reg, mask, val, NULL, true, false)
72 #define regmap_update_bits_check(map, reg, mask, val, change)\
73 regmap_update_bits_base(map, reg, mask, val, change, false, false)
74 #define regmap_update_bits_check_async(map, reg, mask, val, change)\
75 regmap_update_bits_base(map, reg, mask, val, change, true, false)
77 #define regmap_field_write(field, val) \
78 regmap_field_update_bits_base(field, ~0, val, NULL, false, false)
79 #define regmap_field_update_bits(field, mask, val)\
80 regmap_field_update_bits_base(field, mask, val, NULL, false, false)
82 #define regmap_fields_write(field, id, val) \
83 regmap_fields_update_bits_base(field, id, ~0, val, NULL, false, false)
88 /* Unspecified -> 0 -> Backwards compatible default */
89 REGMAP_ENDIAN_DEFAULT = 0,
96 * A register range, used for access related checks
97 * (readable/writeable/volatile/precious checks)
99 * @range_min: address of first register
100 * @range_max: address of last register
102 struct regmap_range {
103 unsigned int range_min;
104 unsigned int range_max;
107 #define regmap_reg_range(low, high) { .range_min = low, .range_max = high, }
110 * A table of ranges including some yes ranges and some no ranges.
111 * If a register belongs to a no_range, the corresponding check function
112 * will return false. If a register belongs to a yes range, the corresponding
113 * check function will return true. "no_ranges" are searched first.
115 * @yes_ranges : pointer to an array of regmap ranges used as "yes ranges"
116 * @n_yes_ranges: size of the above array
117 * @no_ranges: pointer to an array of regmap ranges used as "no ranges"
118 * @n_no_ranges: size of the above array
120 struct regmap_access_table {
121 const struct regmap_range *yes_ranges;
122 unsigned int n_yes_ranges;
123 const struct regmap_range *no_ranges;
124 unsigned int n_no_ranges;
127 typedef void (*regmap_lock)(void *);
128 typedef void (*regmap_unlock)(void *);
131 * Configuration for the register map of a device.
133 * @name: Optional name of the regmap. Useful when a device has multiple
136 * @reg_bits: Number of bits in a register address, mandatory.
137 * @reg_stride: The register address stride. Valid register addresses are a
138 * multiple of this value. If set to 0, a value of 1 will be
140 * @pad_bits: Number of bits of padding between register and value.
141 * @val_bits: Number of bits in a register value, mandatory.
143 * @writeable_reg: Optional callback returning true if the register
144 * can be written to. If this field is NULL but wr_table
145 * (see below) is not, the check is performed on such table
146 * (a register is writeable if it belongs to one of the ranges
147 * specified by wr_table).
148 * @readable_reg: Optional callback returning true if the register
149 * can be read from. If this field is NULL but rd_table
150 * (see below) is not, the check is performed on such table
151 * (a register is readable if it belongs to one of the ranges
152 * specified by rd_table).
153 * @volatile_reg: Optional callback returning true if the register
154 * value can't be cached. If this field is NULL but
155 * volatile_table (see below) is not, the check is performed on
156 * such table (a register is volatile if it belongs to one of
157 * the ranges specified by volatile_table).
158 * @precious_reg: Optional callback returning true if the register
159 * should not be read outside of a call from the driver
160 * (e.g., a clear on read interrupt status register). If this
161 * field is NULL but precious_table (see below) is not, the
162 * check is performed on such table (a register is precious if
163 * it belongs to one of the ranges specified by precious_table).
164 * @lock: Optional lock callback (overrides regmap's default lock
165 * function, based on spinlock or mutex).
166 * @unlock: As above for unlocking.
167 * @lock_arg: this field is passed as the only argument of lock/unlock
168 * functions (ignored in case regular lock/unlock functions
169 * are not overridden).
170 * @reg_read: Optional callback that if filled will be used to perform
171 * all the reads from the registers. Should only be provided for
172 * devices whose read operation cannot be represented as a simple
173 * read operation on a bus such as SPI, I2C, etc. Most of the
174 * devices do not need this.
175 * @reg_write: Same as above for writing.
176 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
177 * to perform locking. This field is ignored if custom lock/unlock
178 * functions are used (see fields lock/unlock of struct regmap_config).
179 * This field is a duplicate of a similar file in
180 * 'struct regmap_bus' and serves exact same purpose.
181 * Use it only for "no-bus" cases.
182 * @max_register: Optional, specifies the maximum valid register index.
183 * @wr_table: Optional, points to a struct regmap_access_table specifying
184 * valid ranges for write access.
185 * @rd_table: As above, for read access.
186 * @volatile_table: As above, for volatile registers.
187 * @precious_table: As above, for precious registers.
188 * @reg_defaults: Power on reset values for registers (for use with
189 * register cache support).
190 * @num_reg_defaults: Number of elements in reg_defaults.
192 * @read_flag_mask: Mask to be set in the top byte of the register when doing
194 * @write_flag_mask: Mask to be set in the top byte of the register when doing
195 * a write. If both read_flag_mask and write_flag_mask are
196 * empty the regmap_bus default masks are used.
197 * @use_single_rw: If set, converts the bulk read and write operations into
198 * a series of single read and write operations. This is useful
199 * for device that does not support bulk read and write.
200 * @can_multi_write: If set, the device supports the multi write mode of bulk
201 * write operations, if clear multi write requests will be
202 * split into individual write operations
204 * @cache_type: The actual cache type.
205 * @reg_defaults_raw: Power on reset values for registers (for use with
206 * register cache support).
207 * @num_reg_defaults_raw: Number of elements in reg_defaults_raw.
208 * @reg_format_endian: Endianness for formatted register addresses. If this is
209 * DEFAULT, the @reg_format_endian_default value from the
210 * regmap bus is used.
211 * @val_format_endian: Endianness for formatted register values. If this is
212 * DEFAULT, the @reg_format_endian_default value from the
213 * regmap bus is used.
215 * @ranges: Array of configuration entries for virtual address ranges.
216 * @num_ranges: Number of range configuration entries.
218 struct regmap_config {
226 bool (*writeable_reg)(struct device *dev, unsigned int reg);
227 bool (*readable_reg)(struct device *dev, unsigned int reg);
228 bool (*volatile_reg)(struct device *dev, unsigned int reg);
229 bool (*precious_reg)(struct device *dev, unsigned int reg);
231 regmap_unlock unlock;
234 int (*reg_read)(void *context, unsigned int reg, unsigned int *val);
235 int (*reg_write)(void *context, unsigned int reg, unsigned int val);
239 unsigned int max_register;
240 const struct regmap_access_table *wr_table;
241 const struct regmap_access_table *rd_table;
242 const struct regmap_access_table *volatile_table;
243 const struct regmap_access_table *precious_table;
244 const struct reg_default *reg_defaults;
245 unsigned int num_reg_defaults;
246 enum regcache_type cache_type;
247 const void *reg_defaults_raw;
248 unsigned int num_reg_defaults_raw;
254 bool can_multi_write;
256 enum regmap_endian reg_format_endian;
257 enum regmap_endian val_format_endian;
259 const struct regmap_range_cfg *ranges;
260 unsigned int num_ranges;
264 * Configuration for indirectly accessed or paged registers.
265 * Registers, mapped to this virtual range, are accessed in two steps:
266 * 1. page selector register update;
267 * 2. access through data window registers.
269 * @name: Descriptive name for diagnostics
271 * @range_min: Address of the lowest register address in virtual range.
272 * @range_max: Address of the highest register in virtual range.
274 * @page_sel_reg: Register with selector field.
275 * @page_sel_mask: Bit shift for selector value.
276 * @page_sel_shift: Bit mask for selector value.
278 * @window_start: Address of first (lowest) register in data window.
279 * @window_len: Number of registers in data window.
281 struct regmap_range_cfg {
284 /* Registers of virtual address range */
285 unsigned int range_min;
286 unsigned int range_max;
288 /* Page selector for indirect addressing */
289 unsigned int selector_reg;
290 unsigned int selector_mask;
293 /* Data window (per each page) */
294 unsigned int window_start;
295 unsigned int window_len;
300 typedef int (*regmap_hw_write)(void *context, const void *data,
302 typedef int (*regmap_hw_gather_write)(void *context,
303 const void *reg, size_t reg_len,
304 const void *val, size_t val_len);
305 typedef int (*regmap_hw_async_write)(void *context,
306 const void *reg, size_t reg_len,
307 const void *val, size_t val_len,
308 struct regmap_async *async);
309 typedef int (*regmap_hw_read)(void *context,
310 const void *reg_buf, size_t reg_size,
311 void *val_buf, size_t val_size);
312 typedef int (*regmap_hw_reg_read)(void *context, unsigned int reg,
314 typedef int (*regmap_hw_reg_write)(void *context, unsigned int reg,
316 typedef int (*regmap_hw_reg_update_bits)(void *context, unsigned int reg,
317 unsigned int mask, unsigned int val);
318 typedef struct regmap_async *(*regmap_hw_async_alloc)(void);
319 typedef void (*regmap_hw_free_context)(void *context);
322 * Description of a hardware bus for the register map infrastructure.
324 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
325 * to perform locking. This field is ignored if custom lock/unlock
326 * functions are used (see fields lock/unlock of
327 * struct regmap_config).
328 * @write: Write operation.
329 * @gather_write: Write operation with split register/value, return -ENOTSUPP
330 * if not implemented on a given device.
331 * @async_write: Write operation which completes asynchronously, optional and
332 * must serialise with respect to non-async I/O.
333 * @reg_write: Write a single register value to the given register address. This
334 * write operation has to complete when returning from the function.
335 * @read: Read operation. Data is returned in the buffer used to transmit
337 * @reg_read: Read a single register value from a given register address.
338 * @free_context: Free context.
339 * @async_alloc: Allocate a regmap_async() structure.
340 * @read_flag_mask: Mask to be set in the top byte of the register when doing
342 * @reg_format_endian_default: Default endianness for formatted register
343 * addresses. Used when the regmap_config specifies DEFAULT. If this is
344 * DEFAULT, BIG is assumed.
345 * @val_format_endian_default: Default endianness for formatted register
346 * values. Used when the regmap_config specifies DEFAULT. If this is
347 * DEFAULT, BIG is assumed.
348 * @max_raw_read: Max raw read size that can be used on the bus.
349 * @max_raw_write: Max raw write size that can be used on the bus.
353 regmap_hw_write write;
354 regmap_hw_gather_write gather_write;
355 regmap_hw_async_write async_write;
356 regmap_hw_reg_write reg_write;
357 regmap_hw_reg_update_bits reg_update_bits;
359 regmap_hw_reg_read reg_read;
360 regmap_hw_free_context free_context;
361 regmap_hw_async_alloc async_alloc;
363 enum regmap_endian reg_format_endian_default;
364 enum regmap_endian val_format_endian_default;
366 size_t max_raw_write;
370 * __regmap_init functions.
372 * These functions take a lock key and name parameter, and should not be called
373 * directly. Instead, use the regmap_init macros that generate a key and name
376 struct regmap *__regmap_init(struct device *dev,
377 const struct regmap_bus *bus,
379 const struct regmap_config *config,
380 struct lock_class_key *lock_key,
381 const char *lock_name);
382 struct regmap *__regmap_init_i2c(struct i2c_client *i2c,
383 const struct regmap_config *config,
384 struct lock_class_key *lock_key,
385 const char *lock_name);
386 struct regmap *__regmap_init_spi(struct spi_device *dev,
387 const struct regmap_config *config,
388 struct lock_class_key *lock_key,
389 const char *lock_name);
390 struct regmap *__regmap_init_spmi_base(struct spmi_device *dev,
391 const struct regmap_config *config,
392 struct lock_class_key *lock_key,
393 const char *lock_name);
394 struct regmap *__regmap_init_spmi_ext(struct spmi_device *dev,
395 const struct regmap_config *config,
396 struct lock_class_key *lock_key,
397 const char *lock_name);
398 struct regmap *__regmap_init_mmio_clk(struct device *dev, const char *clk_id,
400 const struct regmap_config *config,
401 struct lock_class_key *lock_key,
402 const char *lock_name);
403 struct regmap *__regmap_init_ac97(struct snd_ac97 *ac97,
404 const struct regmap_config *config,
405 struct lock_class_key *lock_key,
406 const char *lock_name);
408 struct regmap *__devm_regmap_init(struct device *dev,
409 const struct regmap_bus *bus,
411 const struct regmap_config *config,
412 struct lock_class_key *lock_key,
413 const char *lock_name);
414 struct regmap *__devm_regmap_init_i2c(struct i2c_client *i2c,
415 const struct regmap_config *config,
416 struct lock_class_key *lock_key,
417 const char *lock_name);
418 struct regmap *__devm_regmap_init_spi(struct spi_device *dev,
419 const struct regmap_config *config,
420 struct lock_class_key *lock_key,
421 const char *lock_name);
422 struct regmap *__devm_regmap_init_spmi_base(struct spmi_device *dev,
423 const struct regmap_config *config,
424 struct lock_class_key *lock_key,
425 const char *lock_name);
426 struct regmap *__devm_regmap_init_spmi_ext(struct spmi_device *dev,
427 const struct regmap_config *config,
428 struct lock_class_key *lock_key,
429 const char *lock_name);
430 struct regmap *__devm_regmap_init_mmio_clk(struct device *dev,
433 const struct regmap_config *config,
434 struct lock_class_key *lock_key,
435 const char *lock_name);
436 struct regmap *__devm_regmap_init_ac97(struct snd_ac97 *ac97,
437 const struct regmap_config *config,
438 struct lock_class_key *lock_key,
439 const char *lock_name);
442 * Wrapper for regmap_init macros to include a unique lockdep key and name
443 * for each call. No-op if CONFIG_LOCKDEP is not set.
445 * @fn: Real function to call (in the form __[*_]regmap_init[_*])
446 * @name: Config variable name (#config in the calling macro)
448 #ifdef CONFIG_LOCKDEP
449 #define __regmap_lockdep_wrapper(fn, name, ...) \
452 static struct lock_class_key _key; \
453 fn(__VA_ARGS__, &_key, \
454 KBUILD_BASENAME ":" \
455 __stringify(__LINE__) ":" \
456 "(" name ")->lock"); \
460 #define __regmap_lockdep_wrapper(fn, name, ...) fn(__VA_ARGS__, NULL, NULL)
464 * regmap_init(): Initialise register map
466 * @dev: Device that will be interacted with
467 * @bus: Bus-specific callbacks to use with device
468 * @bus_context: Data passed to bus-specific callbacks
469 * @config: Configuration for register map
471 * The return value will be an ERR_PTR() on error or a valid pointer to
472 * a struct regmap. This function should generally not be called
473 * directly, it should be called by bus-specific init functions.
475 #define regmap_init(dev, bus, bus_context, config) \
476 __regmap_lockdep_wrapper(__regmap_init, #config, \
477 dev, bus, bus_context, config)
478 int regmap_attach_dev(struct device *dev, struct regmap *map,
479 const struct regmap_config *config);
482 * regmap_init_i2c(): Initialise register map
484 * @i2c: Device that will be interacted with
485 * @config: Configuration for register map
487 * The return value will be an ERR_PTR() on error or a valid pointer to
490 #define regmap_init_i2c(i2c, config) \
491 __regmap_lockdep_wrapper(__regmap_init_i2c, #config, \
495 * regmap_init_spi(): Initialise register map
497 * @spi: Device that will be interacted with
498 * @config: Configuration for register map
500 * The return value will be an ERR_PTR() on error or a valid pointer to
503 #define regmap_init_spi(dev, config) \
504 __regmap_lockdep_wrapper(__regmap_init_spi, #config, \
508 * regmap_init_spmi_base(): Create regmap for the Base register space
509 * @sdev: SPMI device that will be interacted with
510 * @config: Configuration for register map
512 * The return value will be an ERR_PTR() on error or a valid pointer to
515 #define regmap_init_spmi_base(dev, config) \
516 __regmap_lockdep_wrapper(__regmap_init_spmi_base, #config, \
520 * regmap_init_spmi_ext(): Create regmap for Ext register space
521 * @sdev: Device that will be interacted with
522 * @config: Configuration for register map
524 * The return value will be an ERR_PTR() on error or a valid pointer to
527 #define regmap_init_spmi_ext(dev, config) \
528 __regmap_lockdep_wrapper(__regmap_init_spmi_ext, #config, \
532 * regmap_init_mmio_clk(): Initialise register map with register clock
534 * @dev: Device that will be interacted with
535 * @clk_id: register clock consumer ID
536 * @regs: Pointer to memory-mapped IO region
537 * @config: Configuration for register map
539 * The return value will be an ERR_PTR() on error or a valid pointer to
542 #define regmap_init_mmio_clk(dev, clk_id, regs, config) \
543 __regmap_lockdep_wrapper(__regmap_init_mmio_clk, #config, \
544 dev, clk_id, regs, config)
547 * regmap_init_mmio(): Initialise register map
549 * @dev: Device that will be interacted with
550 * @regs: Pointer to memory-mapped IO region
551 * @config: Configuration for register map
553 * The return value will be an ERR_PTR() on error or a valid pointer to
556 #define regmap_init_mmio(dev, regs, config) \
557 regmap_init_mmio_clk(dev, NULL, regs, config)
560 * regmap_init_ac97(): Initialise AC'97 register map
562 * @ac97: 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_ac97(ac97, config) \
569 __regmap_lockdep_wrapper(__regmap_init_ac97, #config, \
571 bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg);
574 * devm_regmap_init(): Initialise managed register map
576 * @dev: Device that will be interacted with
577 * @bus: Bus-specific callbacks to use with device
578 * @bus_context: Data passed to bus-specific callbacks
579 * @config: Configuration for register map
581 * The return value will be an ERR_PTR() on error or a valid pointer
582 * to a struct regmap. This function should generally not be called
583 * directly, it should be called by bus-specific init functions. The
584 * map will be automatically freed by the device management code.
586 #define devm_regmap_init(dev, bus, bus_context, config) \
587 __regmap_lockdep_wrapper(__devm_regmap_init, #config, \
588 dev, bus, bus_context, config)
591 * devm_regmap_init_i2c(): Initialise managed register map
593 * @i2c: Device that will be interacted with
594 * @config: Configuration for register map
596 * The return value will be an ERR_PTR() on error or a valid pointer
597 * to a struct regmap. The regmap will be automatically freed by the
598 * device management code.
600 #define devm_regmap_init_i2c(i2c, config) \
601 __regmap_lockdep_wrapper(__devm_regmap_init_i2c, #config, \
605 * devm_regmap_init_spi(): Initialise register map
607 * @spi: Device that will be interacted with
608 * @config: Configuration for register map
610 * The return value will be an ERR_PTR() on error or a valid pointer
611 * to a struct regmap. The map will be automatically freed by the
612 * device management code.
614 #define devm_regmap_init_spi(dev, config) \
615 __regmap_lockdep_wrapper(__devm_regmap_init_spi, #config, \
619 * devm_regmap_init_spmi_base(): Create managed regmap for Base register space
620 * @sdev: SPMI device that will be interacted with
621 * @config: Configuration for register map
623 * The return value will be an ERR_PTR() on error or a valid pointer
624 * to a struct regmap. The regmap will be automatically freed by the
625 * device management code.
627 #define devm_regmap_init_spmi_base(dev, config) \
628 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_base, #config, \
632 * devm_regmap_init_spmi_ext(): Create managed regmap for Ext register space
633 * @sdev: SPMI 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
637 * to a struct regmap. The regmap will be automatically freed by the
638 * device management code.
640 #define devm_regmap_init_spmi_ext(dev, config) \
641 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_ext, #config, \
645 * devm_regmap_init_mmio_clk(): Initialise managed register map with clock
647 * @dev: Device that will be interacted with
648 * @clk_id: register clock consumer ID
649 * @regs: Pointer to memory-mapped IO region
650 * @config: Configuration for register map
652 * The return value will be an ERR_PTR() on error or a valid pointer
653 * to a struct regmap. The regmap will be automatically freed by the
654 * device management code.
656 #define devm_regmap_init_mmio_clk(dev, clk_id, regs, config) \
657 __regmap_lockdep_wrapper(__devm_regmap_init_mmio_clk, #config, \
658 dev, clk_id, regs, config)
661 * devm_regmap_init_mmio(): Initialise managed register map
663 * @dev: Device that will be interacted with
664 * @regs: Pointer to memory-mapped IO region
665 * @config: Configuration for register map
667 * The return value will be an ERR_PTR() on error or a valid pointer
668 * to a struct regmap. The regmap will be automatically freed by the
669 * device management code.
671 #define devm_regmap_init_mmio(dev, regs, config) \
672 devm_regmap_init_mmio_clk(dev, NULL, regs, config)
675 * devm_regmap_init_ac97(): Initialise AC'97 register map
677 * @ac97: Device that will be interacted with
678 * @config: Configuration for register map
680 * The return value will be an ERR_PTR() on error or a valid pointer
681 * to a struct regmap. The regmap will be automatically freed by the
682 * device management code.
684 #define devm_regmap_init_ac97(ac97, config) \
685 __regmap_lockdep_wrapper(__devm_regmap_init_ac97, #config, \
688 void regmap_exit(struct regmap *map);
689 int regmap_reinit_cache(struct regmap *map,
690 const struct regmap_config *config);
691 struct regmap *dev_get_regmap(struct device *dev, const char *name);
692 struct device *regmap_get_device(struct regmap *map);
693 int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
694 int regmap_write_async(struct regmap *map, unsigned int reg, unsigned int val);
695 int regmap_raw_write(struct regmap *map, unsigned int reg,
696 const void *val, size_t val_len);
697 int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
699 int regmap_multi_reg_write(struct regmap *map, const struct reg_sequence *regs,
701 int regmap_multi_reg_write_bypassed(struct regmap *map,
702 const struct reg_sequence *regs,
704 int regmap_raw_write_async(struct regmap *map, unsigned int reg,
705 const void *val, size_t val_len);
706 int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
707 int regmap_raw_read(struct regmap *map, unsigned int reg,
708 void *val, size_t val_len);
709 int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
711 int regmap_update_bits_base(struct regmap *map, unsigned int reg,
712 unsigned int mask, unsigned int val,
713 bool *change, bool async, bool force);
714 int regmap_write_bits(struct regmap *map, unsigned int reg,
715 unsigned int mask, unsigned int val);
716 int regmap_get_val_bytes(struct regmap *map);
717 int regmap_get_max_register(struct regmap *map);
718 int regmap_get_reg_stride(struct regmap *map);
719 int regmap_async_complete(struct regmap *map);
720 bool regmap_can_raw_write(struct regmap *map);
721 size_t regmap_get_raw_read_max(struct regmap *map);
722 size_t regmap_get_raw_write_max(struct regmap *map);
724 int regcache_sync(struct regmap *map);
725 int regcache_sync_region(struct regmap *map, unsigned int min,
727 int regcache_drop_region(struct regmap *map, unsigned int min,
729 void regcache_cache_only(struct regmap *map, bool enable);
730 void regcache_cache_bypass(struct regmap *map, bool enable);
731 void regcache_mark_dirty(struct regmap *map);
733 bool regmap_check_range_table(struct regmap *map, unsigned int reg,
734 const struct regmap_access_table *table);
736 int regmap_register_patch(struct regmap *map, const struct reg_sequence *regs,
738 int regmap_parse_val(struct regmap *map, const void *buf,
741 static inline bool regmap_reg_in_range(unsigned int reg,
742 const struct regmap_range *range)
744 return reg >= range->range_min && reg <= range->range_max;
747 bool regmap_reg_in_ranges(unsigned int reg,
748 const struct regmap_range *ranges,
749 unsigned int nranges);
752 * Description of an register field
754 * @reg: Offset of the register within the regmap bank
755 * @lsb: lsb of the register field.
756 * @msb: msb of the register field.
757 * @id_size: port size if it has some ports
758 * @id_offset: address offset for each ports
764 unsigned int id_size;
765 unsigned int id_offset;
768 #define REG_FIELD(_reg, _lsb, _msb) { \
774 struct regmap_field *regmap_field_alloc(struct regmap *regmap,
775 struct reg_field reg_field);
776 void regmap_field_free(struct regmap_field *field);
778 struct regmap_field *devm_regmap_field_alloc(struct device *dev,
779 struct regmap *regmap, struct reg_field reg_field);
780 void devm_regmap_field_free(struct device *dev, struct regmap_field *field);
782 int regmap_field_read(struct regmap_field *field, unsigned int *val);
783 int regmap_field_update_bits_base(struct regmap_field *field,
784 unsigned int mask, unsigned int val,
785 bool *change, bool async, bool force);
786 int regmap_fields_force_write(struct regmap_field *field, unsigned int id,
788 int regmap_fields_read(struct regmap_field *field, unsigned int id,
790 int regmap_fields_update_bits(struct regmap_field *field, unsigned int id,
791 unsigned int mask, unsigned int val);
792 int regmap_fields_update_bits_base(struct regmap_field *field, unsigned int id,
793 unsigned int mask, unsigned int val,
794 bool *change, bool async, bool force);
797 * Description of an IRQ for the generic regmap irq_chip.
799 * @reg_offset: Offset of the status/mask register within the bank
800 * @mask: Mask used to flag/control the register.
801 * @type_reg_offset: Offset register for the irq type setting.
802 * @type_rising_mask: Mask bit to configure RISING type irq.
803 * @type_falling_mask: Mask bit to configure FALLING type irq.
806 unsigned int reg_offset;
808 unsigned int type_reg_offset;
809 unsigned int type_rising_mask;
810 unsigned int type_falling_mask;
813 #define REGMAP_IRQ_REG(_irq, _off, _mask) \
814 [_irq] = { .reg_offset = (_off), .mask = (_mask) }
817 * Description of a generic regmap irq_chip. This is not intended to
818 * handle every possible interrupt controller, but it should handle a
819 * substantial proportion of those that are found in the wild.
821 * @name: Descriptive name for IRQ controller.
823 * @status_base: Base status register address.
824 * @mask_base: Base mask register address.
825 * @unmask_base: Base unmask register address. for chips who have
826 * separate mask and unmask registers
827 * @ack_base: Base ack address. If zero then the chip is clear on read.
828 * Using zero value is possible with @use_ack bit.
829 * @wake_base: Base address for wake enables. If zero unsupported.
830 * @type_base: Base address for irq type. If zero unsupported.
831 * @irq_reg_stride: Stride to use for chips where registers are not contiguous.
832 * @init_ack_masked: Ack all masked interrupts once during initalization.
833 * @mask_invert: Inverted mask register: cleared bits are masked out.
834 * @use_ack: Use @ack register even if it is zero.
835 * @ack_invert: Inverted ack register: cleared bits for ack.
836 * @wake_invert: Inverted wake register: cleared bits are wake enabled.
837 * @type_invert: Invert the type flags.
838 * @runtime_pm: Hold a runtime PM lock on the device when accessing it.
840 * @num_regs: Number of registers in each control bank.
841 * @irqs: Descriptors for individual IRQs. Interrupt numbers are
842 * assigned based on the index in the array of the interrupt.
843 * @num_irqs: Number of descriptors.
844 * @num_type_reg: Number of type registers.
845 * @type_reg_stride: Stride to use for chips where type registers are not
848 struct regmap_irq_chip {
851 unsigned int status_base;
852 unsigned int mask_base;
853 unsigned int unmask_base;
854 unsigned int ack_base;
855 unsigned int wake_base;
856 unsigned int type_base;
857 unsigned int irq_reg_stride;
858 bool init_ack_masked:1;
868 const struct regmap_irq *irqs;
872 unsigned int type_reg_stride;
875 struct regmap_irq_chip_data;
877 int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
878 int irq_base, const struct regmap_irq_chip *chip,
879 struct regmap_irq_chip_data **data);
880 void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data);
881 int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data);
882 int regmap_irq_get_virq(struct regmap_irq_chip_data *data, int irq);
883 struct irq_domain *regmap_irq_get_domain(struct regmap_irq_chip_data *data);
888 * These stubs should only ever be called by generic code which has
889 * regmap based facilities, if they ever get called at runtime
890 * something is going wrong and something probably needs to select
894 static inline int regmap_write(struct regmap *map, unsigned int reg,
897 WARN_ONCE(1, "regmap API is disabled");
901 static inline int regmap_write_async(struct regmap *map, unsigned int reg,
904 WARN_ONCE(1, "regmap API is disabled");
908 static inline int regmap_raw_write(struct regmap *map, unsigned int reg,
909 const void *val, size_t val_len)
911 WARN_ONCE(1, "regmap API is disabled");
915 static inline int regmap_raw_write_async(struct regmap *map, unsigned int reg,
916 const void *val, size_t val_len)
918 WARN_ONCE(1, "regmap API is disabled");
922 static inline int regmap_bulk_write(struct regmap *map, unsigned int reg,
923 const void *val, size_t val_count)
925 WARN_ONCE(1, "regmap API is disabled");
929 static inline int regmap_read(struct regmap *map, unsigned int reg,
932 WARN_ONCE(1, "regmap API is disabled");
936 static inline int regmap_raw_read(struct regmap *map, unsigned int reg,
937 void *val, size_t val_len)
939 WARN_ONCE(1, "regmap API is disabled");
943 static inline int regmap_bulk_read(struct regmap *map, unsigned int reg,
944 void *val, size_t val_count)
946 WARN_ONCE(1, "regmap API is disabled");
950 static inline int regmap_update_bits_base(struct regmap *map, unsigned int reg,
951 unsigned int mask, unsigned int val,
952 bool *change, bool async, bool force)
954 WARN_ONCE(1, "regmap API is disabled");
958 static inline int regmap_write_bits(struct regmap *map, unsigned int reg,
959 unsigned int mask, unsigned int val)
961 WARN_ONCE(1, "regmap API is disabled");
965 static inline int regmap_field_update_bits_base(struct regmap_field *field,
966 unsigned int mask, unsigned int val,
967 bool *change, bool async, bool force)
969 WARN_ONCE(1, "regmap API is disabled");
973 static inline int regmap_fields_update_bits_base(struct regmap_field *field,
975 unsigned int mask, unsigned int val,
976 bool *change, bool async, bool force)
978 WARN_ONCE(1, "regmap API is disabled");
982 static inline int regmap_get_val_bytes(struct regmap *map)
984 WARN_ONCE(1, "regmap API is disabled");
988 static inline int regmap_get_max_register(struct regmap *map)
990 WARN_ONCE(1, "regmap API is disabled");
994 static inline int regmap_get_reg_stride(struct regmap *map)
996 WARN_ONCE(1, "regmap API is disabled");
1000 static inline int regcache_sync(struct regmap *map)
1002 WARN_ONCE(1, "regmap API is disabled");
1006 static inline int regcache_sync_region(struct regmap *map, unsigned int min,
1009 WARN_ONCE(1, "regmap API is disabled");
1013 static inline int regcache_drop_region(struct regmap *map, unsigned int min,
1016 WARN_ONCE(1, "regmap API is disabled");
1020 static inline void regcache_cache_only(struct regmap *map, bool enable)
1022 WARN_ONCE(1, "regmap API is disabled");
1025 static inline void regcache_cache_bypass(struct regmap *map, bool enable)
1027 WARN_ONCE(1, "regmap API is disabled");
1030 static inline void regcache_mark_dirty(struct regmap *map)
1032 WARN_ONCE(1, "regmap API is disabled");
1035 static inline void regmap_async_complete(struct regmap *map)
1037 WARN_ONCE(1, "regmap API is disabled");
1040 static inline int regmap_register_patch(struct regmap *map,
1041 const struct reg_sequence *regs,
1044 WARN_ONCE(1, "regmap API is disabled");
1048 static inline int regmap_parse_val(struct regmap *map, const void *buf,
1051 WARN_ONCE(1, "regmap API is disabled");
1055 static inline struct regmap *dev_get_regmap(struct device *dev,
1061 static inline struct device *regmap_get_device(struct regmap *map)
1063 WARN_ONCE(1, "regmap API is disabled");