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;
34 /* An enum of all the supported cache types */
43 * Default value for a register. We use an array of structs rather
44 * than a simple array as many modern devices have very sparse
47 * @reg: Register address.
48 * @def: Register default value.
56 * Register/value pairs for sequences of writes with an optional delay in
57 * microseconds to be applied after each write.
59 * @reg: Register address.
60 * @def: Register value.
61 * @delay_us: Delay to be applied after the register write in microseconds
66 unsigned int delay_us;
72 /* Unspecified -> 0 -> Backwards compatible default */
73 REGMAP_ENDIAN_DEFAULT = 0,
80 * A register range, used for access related checks
81 * (readable/writeable/volatile/precious checks)
83 * @range_min: address of first register
84 * @range_max: address of last register
87 unsigned int range_min;
88 unsigned int range_max;
91 #define regmap_reg_range(low, high) { .range_min = low, .range_max = high, }
94 * A table of ranges including some yes ranges and some no ranges.
95 * If a register belongs to a no_range, the corresponding check function
96 * will return false. If a register belongs to a yes range, the corresponding
97 * check function will return true. "no_ranges" are searched first.
99 * @yes_ranges : pointer to an array of regmap ranges used as "yes ranges"
100 * @n_yes_ranges: size of the above array
101 * @no_ranges: pointer to an array of regmap ranges used as "no ranges"
102 * @n_no_ranges: size of the above array
104 struct regmap_access_table {
105 const struct regmap_range *yes_ranges;
106 unsigned int n_yes_ranges;
107 const struct regmap_range *no_ranges;
108 unsigned int n_no_ranges;
111 typedef void (*regmap_lock)(void *);
112 typedef void (*regmap_unlock)(void *);
115 * Configuration for the register map of a device.
117 * @name: Optional name of the regmap. Useful when a device has multiple
120 * @reg_bits: Number of bits in a register address, mandatory.
121 * @reg_stride: The register address stride. Valid register addresses are a
122 * multiple of this value. If set to 0, a value of 1 will be
124 * @pad_bits: Number of bits of padding between register and value.
125 * @val_bits: Number of bits in a register value, mandatory.
127 * @writeable_reg: Optional callback returning true if the register
128 * can be written to. If this field is NULL but wr_table
129 * (see below) is not, the check is performed on such table
130 * (a register is writeable if it belongs to one of the ranges
131 * specified by wr_table).
132 * @readable_reg: Optional callback returning true if the register
133 * can be read from. If this field is NULL but rd_table
134 * (see below) is not, the check is performed on such table
135 * (a register is readable if it belongs to one of the ranges
136 * specified by rd_table).
137 * @volatile_reg: Optional callback returning true if the register
138 * value can't be cached. If this field is NULL but
139 * volatile_table (see below) is not, the check is performed on
140 * such table (a register is volatile if it belongs to one of
141 * the ranges specified by volatile_table).
142 * @precious_reg: Optional callback returning true if the register
143 * should not be read outside of a call from the driver
144 * (e.g., a clear on read interrupt status register). If this
145 * field is NULL but precious_table (see below) is not, the
146 * check is performed on such table (a register is precious if
147 * it belongs to one of the ranges specified by precious_table).
148 * @lock: Optional lock callback (overrides regmap's default lock
149 * function, based on spinlock or mutex).
150 * @unlock: As above for unlocking.
151 * @lock_arg: this field is passed as the only argument of lock/unlock
152 * functions (ignored in case regular lock/unlock functions
153 * are not overridden).
154 * @reg_read: Optional callback that if filled will be used to perform
155 * all the reads from the registers. Should only be provided for
156 * devices whose read operation cannot be represented as a simple
157 * read operation on a bus such as SPI, I2C, etc. Most of the
158 * devices do not need this.
159 * @reg_write: Same as above for writing.
160 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
161 * to perform locking. This field is ignored if custom lock/unlock
162 * functions are used (see fields lock/unlock of struct regmap_config).
163 * This field is a duplicate of a similar file in
164 * 'struct regmap_bus' and serves exact same purpose.
165 * Use it only for "no-bus" cases.
166 * @max_register: Optional, specifies the maximum valid register index.
167 * @wr_table: Optional, points to a struct regmap_access_table specifying
168 * valid ranges for write access.
169 * @rd_table: As above, for read access.
170 * @volatile_table: As above, for volatile registers.
171 * @precious_table: As above, for precious registers.
172 * @reg_defaults: Power on reset values for registers (for use with
173 * register cache support).
174 * @num_reg_defaults: Number of elements in reg_defaults.
176 * @read_flag_mask: Mask to be set in the top byte of the register when doing
178 * @write_flag_mask: Mask to be set in the top byte of the register when doing
179 * a write. If both read_flag_mask and write_flag_mask are
180 * empty the regmap_bus default masks are used.
181 * @use_single_rw: If set, converts the bulk read and write operations into
182 * a series of single read and write operations. This is useful
183 * for device that does not support bulk read and write.
184 * @can_multi_write: If set, the device supports the multi write mode of bulk
185 * write operations, if clear multi write requests will be
186 * split into individual write operations
188 * @cache_type: The actual cache type.
189 * @reg_defaults_raw: Power on reset values for registers (for use with
190 * register cache support).
191 * @num_reg_defaults_raw: Number of elements in reg_defaults_raw.
192 * @reg_format_endian: Endianness for formatted register addresses. If this is
193 * DEFAULT, the @reg_format_endian_default value from the
194 * regmap bus is used.
195 * @val_format_endian: Endianness for formatted register values. If this is
196 * DEFAULT, the @reg_format_endian_default value from the
197 * regmap bus is used.
199 * @ranges: Array of configuration entries for virtual address ranges.
200 * @num_ranges: Number of range configuration entries.
202 struct regmap_config {
210 bool (*writeable_reg)(struct device *dev, unsigned int reg);
211 bool (*readable_reg)(struct device *dev, unsigned int reg);
212 bool (*volatile_reg)(struct device *dev, unsigned int reg);
213 bool (*precious_reg)(struct device *dev, unsigned int reg);
215 regmap_unlock unlock;
218 int (*reg_read)(void *context, unsigned int reg, unsigned int *val);
219 int (*reg_write)(void *context, unsigned int reg, unsigned int val);
223 unsigned int max_register;
224 const struct regmap_access_table *wr_table;
225 const struct regmap_access_table *rd_table;
226 const struct regmap_access_table *volatile_table;
227 const struct regmap_access_table *precious_table;
228 const struct reg_default *reg_defaults;
229 unsigned int num_reg_defaults;
230 enum regcache_type cache_type;
231 const void *reg_defaults_raw;
232 unsigned int num_reg_defaults_raw;
238 bool can_multi_write;
240 enum regmap_endian reg_format_endian;
241 enum regmap_endian val_format_endian;
243 const struct regmap_range_cfg *ranges;
244 unsigned int num_ranges;
248 * Configuration for indirectly accessed or paged registers.
249 * Registers, mapped to this virtual range, are accessed in two steps:
250 * 1. page selector register update;
251 * 2. access through data window registers.
253 * @name: Descriptive name for diagnostics
255 * @range_min: Address of the lowest register address in virtual range.
256 * @range_max: Address of the highest register in virtual range.
258 * @page_sel_reg: Register with selector field.
259 * @page_sel_mask: Bit shift for selector value.
260 * @page_sel_shift: Bit mask for selector value.
262 * @window_start: Address of first (lowest) register in data window.
263 * @window_len: Number of registers in data window.
265 struct regmap_range_cfg {
268 /* Registers of virtual address range */
269 unsigned int range_min;
270 unsigned int range_max;
272 /* Page selector for indirect addressing */
273 unsigned int selector_reg;
274 unsigned int selector_mask;
277 /* Data window (per each page) */
278 unsigned int window_start;
279 unsigned int window_len;
284 typedef int (*regmap_hw_write)(void *context, const void *data,
286 typedef int (*regmap_hw_gather_write)(void *context,
287 const void *reg, size_t reg_len,
288 const void *val, size_t val_len);
289 typedef int (*regmap_hw_async_write)(void *context,
290 const void *reg, size_t reg_len,
291 const void *val, size_t val_len,
292 struct regmap_async *async);
293 typedef int (*regmap_hw_read)(void *context,
294 const void *reg_buf, size_t reg_size,
295 void *val_buf, size_t val_size);
296 typedef int (*regmap_hw_reg_read)(void *context, unsigned int reg,
298 typedef int (*regmap_hw_reg_write)(void *context, unsigned int reg,
300 typedef int (*regmap_hw_reg_update_bits)(void *context, unsigned int reg,
301 unsigned int mask, unsigned int val);
302 typedef struct regmap_async *(*regmap_hw_async_alloc)(void);
303 typedef void (*regmap_hw_free_context)(void *context);
306 * Description of a hardware bus for the register map infrastructure.
308 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
309 * to perform locking. This field is ignored if custom lock/unlock
310 * functions are used (see fields lock/unlock of
311 * struct regmap_config).
312 * @write: Write operation.
313 * @gather_write: Write operation with split register/value, return -ENOTSUPP
314 * if not implemented on a given device.
315 * @async_write: Write operation which completes asynchronously, optional and
316 * must serialise with respect to non-async I/O.
317 * @reg_write: Write a single register value to the given register address. This
318 * write operation has to complete when returning from the function.
319 * @read: Read operation. Data is returned in the buffer used to transmit
321 * @reg_read: Read a single register value from a given register address.
322 * @free_context: Free context.
323 * @async_alloc: Allocate a regmap_async() structure.
324 * @read_flag_mask: Mask to be set in the top byte of the register when doing
326 * @reg_format_endian_default: Default endianness for formatted register
327 * addresses. Used when the regmap_config specifies DEFAULT. If this is
328 * DEFAULT, BIG is assumed.
329 * @val_format_endian_default: Default endianness for formatted register
330 * values. Used when the regmap_config specifies DEFAULT. If this is
331 * DEFAULT, BIG is assumed.
332 * @max_raw_read: Max raw read size that can be used on the bus.
333 * @max_raw_write: Max raw write size that can be used on the bus.
337 regmap_hw_write write;
338 regmap_hw_gather_write gather_write;
339 regmap_hw_async_write async_write;
340 regmap_hw_reg_write reg_write;
341 regmap_hw_reg_update_bits reg_update_bits;
343 regmap_hw_reg_read reg_read;
344 regmap_hw_free_context free_context;
345 regmap_hw_async_alloc async_alloc;
347 enum regmap_endian reg_format_endian_default;
348 enum regmap_endian val_format_endian_default;
350 size_t max_raw_write;
354 * __regmap_init functions.
356 * These functions take a lock key and name parameter, and should not be called
357 * directly. Instead, use the regmap_init macros that generate a key and name
360 struct regmap *__regmap_init(struct device *dev,
361 const struct regmap_bus *bus,
363 const struct regmap_config *config,
364 struct lock_class_key *lock_key,
365 const char *lock_name);
366 struct regmap *__regmap_init_i2c(struct i2c_client *i2c,
367 const struct regmap_config *config,
368 struct lock_class_key *lock_key,
369 const char *lock_name);
370 struct regmap *__regmap_init_spi(struct spi_device *dev,
371 const struct regmap_config *config,
372 struct lock_class_key *lock_key,
373 const char *lock_name);
374 struct regmap *__regmap_init_spmi_base(struct spmi_device *dev,
375 const struct regmap_config *config,
376 struct lock_class_key *lock_key,
377 const char *lock_name);
378 struct regmap *__regmap_init_spmi_ext(struct spmi_device *dev,
379 const struct regmap_config *config,
380 struct lock_class_key *lock_key,
381 const char *lock_name);
382 struct regmap *__regmap_init_mmio_clk(struct device *dev, const char *clk_id,
384 const struct regmap_config *config,
385 struct lock_class_key *lock_key,
386 const char *lock_name);
387 struct regmap *__regmap_init_ac97(struct snd_ac97 *ac97,
388 const struct regmap_config *config,
389 struct lock_class_key *lock_key,
390 const char *lock_name);
391 struct regmap *__regmap_init_swr(struct swr_device *dev,
392 const struct regmap_config *config,
393 struct lock_class_key *lock_key,
394 const char *lock_name);
395 struct regmap *__devm_regmap_init(struct device *dev,
396 const struct regmap_bus *bus,
398 const struct regmap_config *config,
399 struct lock_class_key *lock_key,
400 const char *lock_name);
401 struct regmap *__devm_regmap_init_i2c(struct i2c_client *i2c,
402 const struct regmap_config *config,
403 struct lock_class_key *lock_key,
404 const char *lock_name);
405 struct regmap *__devm_regmap_init_spi(struct spi_device *dev,
406 const struct regmap_config *config,
407 struct lock_class_key *lock_key,
408 const char *lock_name);
409 struct regmap *__devm_regmap_init_spmi_base(struct spmi_device *dev,
410 const struct regmap_config *config,
411 struct lock_class_key *lock_key,
412 const char *lock_name);
413 struct regmap *__devm_regmap_init_spmi_ext(struct spmi_device *dev,
414 const struct regmap_config *config,
415 struct lock_class_key *lock_key,
416 const char *lock_name);
417 struct regmap *__devm_regmap_init_mmio_clk(struct device *dev,
420 const struct regmap_config *config,
421 struct lock_class_key *lock_key,
422 const char *lock_name);
423 struct regmap *__devm_regmap_init_ac97(struct snd_ac97 *ac97,
424 const struct regmap_config *config,
425 struct lock_class_key *lock_key,
426 const char *lock_name);
427 struct regmap *__devm_regmap_init_swr(struct swr_device *dev,
428 const struct regmap_config *config,
429 struct lock_class_key *lock_key,
430 const char *lock_name);
433 * Wrapper for regmap_init macros to include a unique lockdep key and name
434 * for each call. No-op if CONFIG_LOCKDEP is not set.
436 * @fn: Real function to call (in the form __[*_]regmap_init[_*])
437 * @name: Config variable name (#config in the calling macro)
439 #ifdef CONFIG_LOCKDEP
440 #define __regmap_lockdep_wrapper(fn, name, ...) \
443 static struct lock_class_key _key; \
444 fn(__VA_ARGS__, &_key, \
445 KBUILD_BASENAME ":" \
446 __stringify(__LINE__) ":" \
447 "(" name ")->lock"); \
451 #define __regmap_lockdep_wrapper(fn, name, ...) fn(__VA_ARGS__, NULL, NULL)
455 * regmap_init(): Initialise register map
457 * @dev: Device that will be interacted with
458 * @bus: Bus-specific callbacks to use with device
459 * @bus_context: Data passed to bus-specific callbacks
460 * @config: Configuration for register map
462 * The return value will be an ERR_PTR() on error or a valid pointer to
463 * a struct regmap. This function should generally not be called
464 * directly, it should be called by bus-specific init functions.
466 #define regmap_init(dev, bus, bus_context, config) \
467 __regmap_lockdep_wrapper(__regmap_init, #config, \
468 dev, bus, bus_context, config)
469 int regmap_attach_dev(struct device *dev, struct regmap *map,
470 const struct regmap_config *config);
473 * regmap_init_i2c(): Initialise register map
475 * @i2c: Device that will be interacted with
476 * @config: Configuration for register map
478 * The return value will be an ERR_PTR() on error or a valid pointer to
481 #define regmap_init_i2c(i2c, config) \
482 __regmap_lockdep_wrapper(__regmap_init_i2c, #config, \
486 * regmap_init_spi(): Initialise register map
488 * @spi: Device that will be interacted with
489 * @config: Configuration for register map
491 * The return value will be an ERR_PTR() on error or a valid pointer to
494 #define regmap_init_spi(dev, config) \
495 __regmap_lockdep_wrapper(__regmap_init_spi, #config, \
499 * regmap_init_spmi_base(): Create regmap for the Base register space
500 * @sdev: SPMI device that will be interacted with
501 * @config: Configuration for register map
503 * The return value will be an ERR_PTR() on error or a valid pointer to
506 #define regmap_init_spmi_base(dev, config) \
507 __regmap_lockdep_wrapper(__regmap_init_spmi_base, #config, \
511 * regmap_init_spmi_ext(): Create regmap for Ext register space
512 * @sdev: Device that will be interacted with
513 * @config: Configuration for register map
515 * The return value will be an ERR_PTR() on error or a valid pointer to
518 #define regmap_init_spmi_ext(dev, config) \
519 __regmap_lockdep_wrapper(__regmap_init_spmi_ext, #config, \
523 * regmap_init_mmio_clk(): Initialise register map with register clock
525 * @dev: Device that will be interacted with
526 * @clk_id: register clock consumer ID
527 * @regs: Pointer to memory-mapped IO region
528 * @config: Configuration for register map
530 * The return value will be an ERR_PTR() on error or a valid pointer to
533 #define regmap_init_mmio_clk(dev, clk_id, regs, config) \
534 __regmap_lockdep_wrapper(__regmap_init_mmio_clk, #config, \
535 dev, clk_id, regs, config)
538 * regmap_init_mmio(): Initialise register map
540 * @dev: Device that will be interacted with
541 * @regs: Pointer to memory-mapped IO region
542 * @config: Configuration for register map
544 * The return value will be an ERR_PTR() on error or a valid pointer to
547 #define regmap_init_mmio(dev, regs, config) \
548 regmap_init_mmio_clk(dev, NULL, regs, config)
551 * regmap_init_ac97(): Initialise AC'97 register map
553 * @ac97: Device that will be interacted with
554 * @config: Configuration for register map
556 * The return value will be an ERR_PTR() on error or a valid pointer to
559 #define regmap_init_ac97(ac97, config) \
560 __regmap_lockdep_wrapper(__regmap_init_ac97, #config, \
562 bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg);
565 * regmap_init_swr(): Initialise register map
567 * @swr: Device that will be interacted with
568 * @config: Configuration for register map
570 * The return value will be an ERR_PTR() on error or a valid pointer to
573 #define regmap_init_swr(swr, config) \
574 __regmap_lockdep_wrapper(__regmap_init_swr, #config, \
577 * devm_regmap_init(): Initialise managed register map
579 * @dev: Device that will be interacted with
580 * @bus: Bus-specific callbacks to use with device
581 * @bus_context: Data passed to bus-specific callbacks
582 * @config: Configuration for register map
584 * The return value will be an ERR_PTR() on error or a valid pointer
585 * to a struct regmap. This function should generally not be called
586 * directly, it should be called by bus-specific init functions. The
587 * map will be automatically freed by the device management code.
589 #define devm_regmap_init(dev, bus, bus_context, config) \
590 __regmap_lockdep_wrapper(__devm_regmap_init, #config, \
591 dev, bus, bus_context, config)
594 * devm_regmap_init_i2c(): Initialise managed register map
596 * @i2c: Device that will be interacted with
597 * @config: Configuration for register map
599 * The return value will be an ERR_PTR() on error or a valid pointer
600 * to a struct regmap. The regmap will be automatically freed by the
601 * device management code.
603 #define devm_regmap_init_i2c(i2c, config) \
604 __regmap_lockdep_wrapper(__devm_regmap_init_i2c, #config, \
608 * devm_regmap_init_spi(): Initialise register map
610 * @spi: Device that will be interacted with
611 * @config: Configuration for register map
613 * The return value will be an ERR_PTR() on error or a valid pointer
614 * to a struct regmap. The map will be automatically freed by the
615 * device management code.
617 #define devm_regmap_init_spi(dev, config) \
618 __regmap_lockdep_wrapper(__devm_regmap_init_spi, #config, \
622 * devm_regmap_init_spmi_base(): Create managed regmap for Base register space
623 * @sdev: SPMI device that will be interacted with
624 * @config: Configuration for register map
626 * The return value will be an ERR_PTR() on error or a valid pointer
627 * to a struct regmap. The regmap will be automatically freed by the
628 * device management code.
630 #define devm_regmap_init_spmi_base(dev, config) \
631 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_base, #config, \
635 * devm_regmap_init_spmi_ext(): Create managed regmap for Ext register space
636 * @sdev: SPMI device that will be interacted with
637 * @config: Configuration for register map
639 * The return value will be an ERR_PTR() on error or a valid pointer
640 * to a struct regmap. The regmap will be automatically freed by the
641 * device management code.
643 #define devm_regmap_init_spmi_ext(dev, config) \
644 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_ext, #config, \
648 * devm_regmap_init_mmio_clk(): Initialise managed register map with clock
650 * @dev: Device that will be interacted with
651 * @clk_id: register clock consumer ID
652 * @regs: Pointer to memory-mapped IO region
653 * @config: Configuration for register map
655 * The return value will be an ERR_PTR() on error or a valid pointer
656 * to a struct regmap. The regmap will be automatically freed by the
657 * device management code.
659 #define devm_regmap_init_mmio_clk(dev, clk_id, regs, config) \
660 __regmap_lockdep_wrapper(__devm_regmap_init_mmio_clk, #config, \
661 dev, clk_id, regs, config)
664 * devm_regmap_init_mmio(): Initialise managed register map
666 * @dev: Device that will be interacted with
667 * @regs: Pointer to memory-mapped IO region
668 * @config: Configuration for register map
670 * The return value will be an ERR_PTR() on error or a valid pointer
671 * to a struct regmap. The regmap will be automatically freed by the
672 * device management code.
674 #define devm_regmap_init_mmio(dev, regs, config) \
675 devm_regmap_init_mmio_clk(dev, NULL, regs, config)
678 * devm_regmap_init_ac97(): Initialise AC'97 register map
680 * @ac97: Device that will be interacted with
681 * @config: Configuration for register map
683 * The return value will be an ERR_PTR() on error or a valid pointer
684 * to a struct regmap. The regmap will be automatically freed by the
685 * device management code.
687 #define devm_regmap_init_ac97(ac97, config) \
688 __regmap_lockdep_wrapper(__devm_regmap_init_ac97, #config, \
692 * devm_regmap_init_swr(): Initialise managed register map
694 * @swr: Device that will be interacted with
695 * @config: Configuration for register map
697 * The return value will be an ERR_PTR() on error or a valid pointer
698 * to a struct regmap. The regmap will be automatically freed by the
699 * device management code.
701 #define devm_regmap_init_swr(swr, config) \
702 __regmap_lockdep_wrapper(__devm_regmap_init_swr, #config, \
705 void regmap_exit(struct regmap *map);
706 int regmap_reinit_cache(struct regmap *map,
707 const struct regmap_config *config);
708 struct regmap *dev_get_regmap(struct device *dev, const char *name);
709 struct device *regmap_get_device(struct regmap *map);
710 int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
711 int regmap_write_async(struct regmap *map, unsigned int reg, unsigned int val);
712 int regmap_raw_write(struct regmap *map, unsigned int reg,
713 const void *val, size_t val_len);
714 int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
716 int regmap_multi_reg_write(struct regmap *map, const struct reg_sequence *regs,
718 int regmap_multi_reg_write_bypassed(struct regmap *map,
719 const struct reg_sequence *regs,
721 int regmap_raw_write_async(struct regmap *map, unsigned int reg,
722 const void *val, size_t val_len);
723 int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
724 int regmap_raw_read(struct regmap *map, unsigned int reg,
725 void *val, size_t val_len);
726 int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
728 int regmap_update_bits(struct regmap *map, unsigned int reg,
729 unsigned int mask, unsigned int val);
730 int regmap_write_bits(struct regmap *map, unsigned int reg,
731 unsigned int mask, unsigned int val);
732 int regmap_update_bits_async(struct regmap *map, unsigned int reg,
733 unsigned int mask, unsigned int val);
734 int regmap_update_bits_check(struct regmap *map, unsigned int reg,
735 unsigned int mask, unsigned int val,
737 int regmap_update_bits_check_async(struct regmap *map, unsigned int reg,
738 unsigned int mask, unsigned int val,
740 int regmap_get_val_bytes(struct regmap *map);
741 int regmap_get_max_register(struct regmap *map);
742 int regmap_get_reg_stride(struct regmap *map);
743 int regmap_async_complete(struct regmap *map);
744 bool regmap_can_raw_write(struct regmap *map);
745 size_t regmap_get_raw_read_max(struct regmap *map);
746 size_t regmap_get_raw_write_max(struct regmap *map);
748 int regcache_sync(struct regmap *map);
749 int regcache_sync_region(struct regmap *map, unsigned int min,
751 int regcache_drop_region(struct regmap *map, unsigned int min,
753 void regcache_cache_only(struct regmap *map, bool enable);
754 void regcache_cache_bypass(struct regmap *map, bool enable);
755 void regcache_mark_dirty(struct regmap *map);
757 bool regmap_check_range_table(struct regmap *map, unsigned int reg,
758 const struct regmap_access_table *table);
760 int regmap_register_patch(struct regmap *map, const struct reg_sequence *regs,
762 int regmap_parse_val(struct regmap *map, const void *buf,
765 static inline bool regmap_reg_in_range(unsigned int reg,
766 const struct regmap_range *range)
768 return reg >= range->range_min && reg <= range->range_max;
771 bool regmap_reg_in_ranges(unsigned int reg,
772 const struct regmap_range *ranges,
773 unsigned int nranges);
776 * Description of an register field
778 * @reg: Offset of the register within the regmap bank
779 * @lsb: lsb of the register field.
780 * @msb: msb of the register field.
781 * @id_size: port size if it has some ports
782 * @id_offset: address offset for each ports
788 unsigned int id_size;
789 unsigned int id_offset;
792 #define REG_FIELD(_reg, _lsb, _msb) { \
798 struct regmap_field *regmap_field_alloc(struct regmap *regmap,
799 struct reg_field reg_field);
800 void regmap_field_free(struct regmap_field *field);
802 struct regmap_field *devm_regmap_field_alloc(struct device *dev,
803 struct regmap *regmap, struct reg_field reg_field);
804 void devm_regmap_field_free(struct device *dev, struct regmap_field *field);
806 int regmap_field_read(struct regmap_field *field, unsigned int *val);
807 int regmap_field_write(struct regmap_field *field, unsigned int val);
808 int regmap_field_update_bits(struct regmap_field *field,
809 unsigned int mask, unsigned int val);
811 int regmap_fields_write(struct regmap_field *field, unsigned int id,
813 int regmap_fields_force_write(struct regmap_field *field, unsigned int id,
815 int regmap_fields_read(struct regmap_field *field, unsigned int id,
817 int regmap_fields_update_bits(struct regmap_field *field, unsigned int id,
818 unsigned int mask, unsigned int val);
821 * Description of an IRQ for the generic regmap irq_chip.
823 * @reg_offset: Offset of the status/mask register within the bank
824 * @mask: Mask used to flag/control the register.
827 unsigned int reg_offset;
831 #define REGMAP_IRQ_REG(_irq, _off, _mask) \
832 [_irq] = { .reg_offset = (_off), .mask = (_mask) }
835 * Description of a generic regmap irq_chip. This is not intended to
836 * handle every possible interrupt controller, but it should handle a
837 * substantial proportion of those that are found in the wild.
839 * @name: Descriptive name for IRQ controller.
841 * @status_base: Base status register address.
842 * @mask_base: Base mask register address.
843 * @unmask_base: Base unmask register address. for chips who have
844 * separate mask and unmask registers
845 * @ack_base: Base ack address. If zero then the chip is clear on read.
846 * Using zero value is possible with @use_ack bit.
847 * @wake_base: Base address for wake enables. If zero unsupported.
848 * @irq_reg_stride: Stride to use for chips where registers are not contiguous.
849 * @init_ack_masked: Ack all masked interrupts once during initalization.
850 * @mask_invert: Inverted mask register: cleared bits are masked out.
851 * @use_ack: Use @ack register even if it is zero.
852 * @ack_invert: Inverted ack register: cleared bits for ack.
853 * @wake_invert: Inverted wake register: cleared bits are wake enabled.
854 * @runtime_pm: Hold a runtime PM lock on the device when accessing it.
856 * @num_regs: Number of registers in each control bank.
857 * @irqs: Descriptors for individual IRQs. Interrupt numbers are
858 * assigned based on the index in the array of the interrupt.
859 * @num_irqs: Number of descriptors.
861 struct regmap_irq_chip {
864 unsigned int status_base;
865 unsigned int mask_base;
866 unsigned int unmask_base;
867 unsigned int ack_base;
868 unsigned int wake_base;
869 unsigned int irq_reg_stride;
870 bool init_ack_masked:1;
879 const struct regmap_irq *irqs;
883 struct regmap_irq_chip_data;
885 int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
886 int irq_base, const struct regmap_irq_chip *chip,
887 struct regmap_irq_chip_data **data);
888 void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data);
889 int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data);
890 int regmap_irq_get_virq(struct regmap_irq_chip_data *data, int irq);
891 struct irq_domain *regmap_irq_get_domain(struct regmap_irq_chip_data *data);
896 * These stubs should only ever be called by generic code which has
897 * regmap based facilities, if they ever get called at runtime
898 * something is going wrong and something probably needs to select
902 static inline int regmap_write(struct regmap *map, unsigned int reg,
905 WARN_ONCE(1, "regmap API is disabled");
909 static inline int regmap_write_async(struct regmap *map, unsigned int reg,
912 WARN_ONCE(1, "regmap API is disabled");
916 static inline int regmap_raw_write(struct regmap *map, unsigned int reg,
917 const void *val, size_t val_len)
919 WARN_ONCE(1, "regmap API is disabled");
923 static inline int regmap_raw_write_async(struct regmap *map, unsigned int reg,
924 const void *val, size_t val_len)
926 WARN_ONCE(1, "regmap API is disabled");
930 static inline int regmap_bulk_write(struct regmap *map, unsigned int reg,
931 const void *val, size_t val_count)
933 WARN_ONCE(1, "regmap API is disabled");
937 static inline int regmap_read(struct regmap *map, unsigned int reg,
940 WARN_ONCE(1, "regmap API is disabled");
944 static inline int regmap_raw_read(struct regmap *map, unsigned int reg,
945 void *val, size_t val_len)
947 WARN_ONCE(1, "regmap API is disabled");
951 static inline int regmap_bulk_read(struct regmap *map, unsigned int reg,
952 void *val, size_t val_count)
954 WARN_ONCE(1, "regmap API is disabled");
958 static inline int regmap_update_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_write_bits(struct regmap *map, unsigned int reg,
966 unsigned int mask, unsigned int val)
968 WARN_ONCE(1, "regmap API is disabled");
972 static inline int regmap_update_bits_async(struct regmap *map,
974 unsigned int mask, unsigned int val)
976 WARN_ONCE(1, "regmap API is disabled");
980 static inline int regmap_update_bits_check(struct regmap *map,
982 unsigned int mask, unsigned int val,
985 WARN_ONCE(1, "regmap API is disabled");
989 static inline int regmap_update_bits_check_async(struct regmap *map,
995 WARN_ONCE(1, "regmap API is disabled");
999 static inline int regmap_get_val_bytes(struct regmap *map)
1001 WARN_ONCE(1, "regmap API is disabled");
1005 static inline int regmap_get_max_register(struct regmap *map)
1007 WARN_ONCE(1, "regmap API is disabled");
1011 static inline int regmap_get_reg_stride(struct regmap *map)
1013 WARN_ONCE(1, "regmap API is disabled");
1017 static inline int regcache_sync(struct regmap *map)
1019 WARN_ONCE(1, "regmap API is disabled");
1023 static inline int regcache_sync_region(struct regmap *map, unsigned int min,
1026 WARN_ONCE(1, "regmap API is disabled");
1030 static inline int regcache_drop_region(struct regmap *map, unsigned int min,
1033 WARN_ONCE(1, "regmap API is disabled");
1037 static inline void regcache_cache_only(struct regmap *map, bool enable)
1039 WARN_ONCE(1, "regmap API is disabled");
1042 static inline void regcache_cache_bypass(struct regmap *map, bool enable)
1044 WARN_ONCE(1, "regmap API is disabled");
1047 static inline void regcache_mark_dirty(struct regmap *map)
1049 WARN_ONCE(1, "regmap API is disabled");
1052 static inline void regmap_async_complete(struct regmap *map)
1054 WARN_ONCE(1, "regmap API is disabled");
1057 static inline int regmap_register_patch(struct regmap *map,
1058 const struct reg_default *regs,
1061 WARN_ONCE(1, "regmap API is disabled");
1065 static inline int regmap_parse_val(struct regmap *map, const void *buf,
1068 WARN_ONCE(1, "regmap API is disabled");
1072 static inline struct regmap *dev_get_regmap(struct device *dev,
1078 static inline struct device *regmap_get_device(struct regmap *map)
1080 WARN_ONCE(1, "regmap API is disabled");