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_write_bits(map, reg, mask, val) \
78 regmap_update_bits_base(map, reg, mask, val, NULL, false, true)
80 #define regmap_field_write(field, val) \
81 regmap_field_update_bits_base(field, ~0, val, NULL, false, false)
82 #define regmap_field_force_write(field, val) \
83 regmap_field_update_bits_base(field, ~0, val, NULL, false, true)
84 #define regmap_field_update_bits(field, mask, val)\
85 regmap_field_update_bits_base(field, mask, val, NULL, false, false)
86 #define regmap_field_force_update_bits(field, mask, val) \
87 regmap_field_update_bits_base(field, mask, val, NULL, false, true)
89 #define regmap_fields_write(field, id, val) \
90 regmap_fields_update_bits_base(field, id, ~0, val, NULL, false, false)
91 #define regmap_fields_force_write(field, id, val) \
92 regmap_fields_update_bits_base(field, id, ~0, val, NULL, false, true)
93 #define regmap_fields_update_bits(field, id, mask, val)\
94 regmap_fields_update_bits_base(field, id, mask, val, NULL, false, false)
95 #define regmap_fields_force_update_bits(field, id, mask, val) \
96 regmap_fields_update_bits_base(field, id, mask, val, NULL, false, true)
101 /* Unspecified -> 0 -> Backwards compatible default */
102 REGMAP_ENDIAN_DEFAULT
= 0,
104 REGMAP_ENDIAN_LITTLE
,
105 REGMAP_ENDIAN_NATIVE
,
109 * A register range, used for access related checks
110 * (readable/writeable/volatile/precious checks)
112 * @range_min: address of first register
113 * @range_max: address of last register
115 struct regmap_range
{
116 unsigned int range_min
;
117 unsigned int range_max
;
120 #define regmap_reg_range(low, high) { .range_min = low, .range_max = high, }
123 * A table of ranges including some yes ranges and some no ranges.
124 * If a register belongs to a no_range, the corresponding check function
125 * will return false. If a register belongs to a yes range, the corresponding
126 * check function will return true. "no_ranges" are searched first.
128 * @yes_ranges : pointer to an array of regmap ranges used as "yes ranges"
129 * @n_yes_ranges: size of the above array
130 * @no_ranges: pointer to an array of regmap ranges used as "no ranges"
131 * @n_no_ranges: size of the above array
133 struct regmap_access_table
{
134 const struct regmap_range
*yes_ranges
;
135 unsigned int n_yes_ranges
;
136 const struct regmap_range
*no_ranges
;
137 unsigned int n_no_ranges
;
140 typedef void (*regmap_lock
)(void *);
141 typedef void (*regmap_unlock
)(void *);
144 * Configuration for the register map of a device.
146 * @name: Optional name of the regmap. Useful when a device has multiple
149 * @reg_bits: Number of bits in a register address, mandatory.
150 * @reg_stride: The register address stride. Valid register addresses are a
151 * multiple of this value. If set to 0, a value of 1 will be
153 * @pad_bits: Number of bits of padding between register and value.
154 * @val_bits: Number of bits in a register value, mandatory.
156 * @writeable_reg: Optional callback returning true if the register
157 * can be written to. If this field is NULL but wr_table
158 * (see below) is not, the check is performed on such table
159 * (a register is writeable if it belongs to one of the ranges
160 * specified by wr_table).
161 * @readable_reg: Optional callback returning true if the register
162 * can be read from. If this field is NULL but rd_table
163 * (see below) is not, the check is performed on such table
164 * (a register is readable if it belongs to one of the ranges
165 * specified by rd_table).
166 * @volatile_reg: Optional callback returning true if the register
167 * value can't be cached. If this field is NULL but
168 * volatile_table (see below) is not, the check is performed on
169 * such table (a register is volatile if it belongs to one of
170 * the ranges specified by volatile_table).
171 * @precious_reg: Optional callback returning true if the register
172 * should not be read outside of a call from the driver
173 * (e.g., a clear on read interrupt status register). If this
174 * field is NULL but precious_table (see below) is not, the
175 * check is performed on such table (a register is precious if
176 * it belongs to one of the ranges specified by precious_table).
177 * @lock: Optional lock callback (overrides regmap's default lock
178 * function, based on spinlock or mutex).
179 * @unlock: As above for unlocking.
180 * @lock_arg: this field is passed as the only argument of lock/unlock
181 * functions (ignored in case regular lock/unlock functions
182 * are not overridden).
183 * @reg_read: Optional callback that if filled will be used to perform
184 * all the reads from the registers. Should only be provided for
185 * devices whose read operation cannot be represented as a simple
186 * read operation on a bus such as SPI, I2C, etc. Most of the
187 * devices do not need this.
188 * @reg_write: Same as above for writing.
189 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
190 * to perform locking. This field is ignored if custom lock/unlock
191 * functions are used (see fields lock/unlock of struct regmap_config).
192 * This field is a duplicate of a similar file in
193 * 'struct regmap_bus' and serves exact same purpose.
194 * Use it only for "no-bus" cases.
195 * @max_register: Optional, specifies the maximum valid register address.
196 * @wr_table: Optional, points to a struct regmap_access_table specifying
197 * valid ranges for write access.
198 * @rd_table: As above, for read access.
199 * @volatile_table: As above, for volatile registers.
200 * @precious_table: As above, for precious registers.
201 * @reg_defaults: Power on reset values for registers (for use with
202 * register cache support).
203 * @num_reg_defaults: Number of elements in reg_defaults.
205 * @read_flag_mask: Mask to be set in the top byte of the register when doing
207 * @write_flag_mask: Mask to be set in the top byte of the register when doing
208 * a write. If both read_flag_mask and write_flag_mask are
209 * empty the regmap_bus default masks are used.
210 * @use_single_rw: If set, converts the bulk read and write operations into
211 * a series of single read and write operations. This is useful
212 * for device that does not support bulk read and write.
213 * @can_multi_write: If set, the device supports the multi write mode of bulk
214 * write operations, if clear multi write requests will be
215 * split into individual write operations
217 * @cache_type: The actual cache type.
218 * @reg_defaults_raw: Power on reset values for registers (for use with
219 * register cache support).
220 * @num_reg_defaults_raw: Number of elements in reg_defaults_raw.
221 * @reg_format_endian: Endianness for formatted register addresses. If this is
222 * DEFAULT, the @reg_format_endian_default value from the
223 * regmap bus is used.
224 * @val_format_endian: Endianness for formatted register values. If this is
225 * DEFAULT, the @reg_format_endian_default value from the
226 * regmap bus is used.
228 * @ranges: Array of configuration entries for virtual address ranges.
229 * @num_ranges: Number of range configuration entries.
231 struct regmap_config
{
239 bool (*writeable_reg
)(struct device
*dev
, unsigned int reg
);
240 bool (*readable_reg
)(struct device
*dev
, unsigned int reg
);
241 bool (*volatile_reg
)(struct device
*dev
, unsigned int reg
);
242 bool (*precious_reg
)(struct device
*dev
, unsigned int reg
);
244 regmap_unlock unlock
;
247 int (*reg_read
)(void *context
, unsigned int reg
, unsigned int *val
);
248 int (*reg_write
)(void *context
, unsigned int reg
, unsigned int val
);
252 unsigned int max_register
;
253 const struct regmap_access_table
*wr_table
;
254 const struct regmap_access_table
*rd_table
;
255 const struct regmap_access_table
*volatile_table
;
256 const struct regmap_access_table
*precious_table
;
257 const struct reg_default
*reg_defaults
;
258 unsigned int num_reg_defaults
;
259 enum regcache_type cache_type
;
260 const void *reg_defaults_raw
;
261 unsigned int num_reg_defaults_raw
;
267 bool can_multi_write
;
269 enum regmap_endian reg_format_endian
;
270 enum regmap_endian val_format_endian
;
272 const struct regmap_range_cfg
*ranges
;
273 unsigned int num_ranges
;
277 * Configuration for indirectly accessed or paged registers.
278 * Registers, mapped to this virtual range, are accessed in two steps:
279 * 1. page selector register update;
280 * 2. access through data window registers.
282 * @name: Descriptive name for diagnostics
284 * @range_min: Address of the lowest register address in virtual range.
285 * @range_max: Address of the highest register in virtual range.
287 * @page_sel_reg: Register with selector field.
288 * @page_sel_mask: Bit shift for selector value.
289 * @page_sel_shift: Bit mask for selector value.
291 * @window_start: Address of first (lowest) register in data window.
292 * @window_len: Number of registers in data window.
294 struct regmap_range_cfg
{
297 /* Registers of virtual address range */
298 unsigned int range_min
;
299 unsigned int range_max
;
301 /* Page selector for indirect addressing */
302 unsigned int selector_reg
;
303 unsigned int selector_mask
;
306 /* Data window (per each page) */
307 unsigned int window_start
;
308 unsigned int window_len
;
313 typedef int (*regmap_hw_write
)(void *context
, const void *data
,
315 typedef int (*regmap_hw_gather_write
)(void *context
,
316 const void *reg
, size_t reg_len
,
317 const void *val
, size_t val_len
);
318 typedef int (*regmap_hw_async_write
)(void *context
,
319 const void *reg
, size_t reg_len
,
320 const void *val
, size_t val_len
,
321 struct regmap_async
*async
);
322 typedef int (*regmap_hw_read
)(void *context
,
323 const void *reg_buf
, size_t reg_size
,
324 void *val_buf
, size_t val_size
);
325 typedef int (*regmap_hw_reg_read
)(void *context
, unsigned int reg
,
327 typedef int (*regmap_hw_reg_write
)(void *context
, unsigned int reg
,
329 typedef int (*regmap_hw_reg_update_bits
)(void *context
, unsigned int reg
,
330 unsigned int mask
, unsigned int val
);
331 typedef struct regmap_async
*(*regmap_hw_async_alloc
)(void);
332 typedef void (*regmap_hw_free_context
)(void *context
);
335 * Description of a hardware bus for the register map infrastructure.
337 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
338 * to perform locking. This field is ignored if custom lock/unlock
339 * functions are used (see fields lock/unlock of
340 * struct regmap_config).
341 * @write: Write operation.
342 * @gather_write: Write operation with split register/value, return -ENOTSUPP
343 * if not implemented on a given device.
344 * @async_write: Write operation which completes asynchronously, optional and
345 * must serialise with respect to non-async I/O.
346 * @reg_write: Write a single register value to the given register address. This
347 * write operation has to complete when returning from the function.
348 * @read: Read operation. Data is returned in the buffer used to transmit
350 * @reg_read: Read a single register value from a given register address.
351 * @free_context: Free context.
352 * @async_alloc: Allocate a regmap_async() structure.
353 * @read_flag_mask: Mask to be set in the top byte of the register when doing
355 * @reg_format_endian_default: Default endianness for formatted register
356 * addresses. Used when the regmap_config specifies DEFAULT. If this is
357 * DEFAULT, BIG is assumed.
358 * @val_format_endian_default: Default endianness for formatted register
359 * values. Used when the regmap_config specifies DEFAULT. If this is
360 * DEFAULT, BIG is assumed.
361 * @max_raw_read: Max raw read size that can be used on the bus.
362 * @max_raw_write: Max raw write size that can be used on the bus.
366 regmap_hw_write write
;
367 regmap_hw_gather_write gather_write
;
368 regmap_hw_async_write async_write
;
369 regmap_hw_reg_write reg_write
;
370 regmap_hw_reg_update_bits reg_update_bits
;
372 regmap_hw_reg_read reg_read
;
373 regmap_hw_free_context free_context
;
374 regmap_hw_async_alloc async_alloc
;
376 enum regmap_endian reg_format_endian_default
;
377 enum regmap_endian val_format_endian_default
;
379 size_t max_raw_write
;
383 * __regmap_init functions.
385 * These functions take a lock key and name parameter, and should not be called
386 * directly. Instead, use the regmap_init macros that generate a key and name
389 struct regmap
*__regmap_init(struct device
*dev
,
390 const struct regmap_bus
*bus
,
392 const struct regmap_config
*config
,
393 struct lock_class_key
*lock_key
,
394 const char *lock_name
);
395 struct regmap
*__regmap_init_i2c(struct i2c_client
*i2c
,
396 const struct regmap_config
*config
,
397 struct lock_class_key
*lock_key
,
398 const char *lock_name
);
399 struct regmap
*__regmap_init_spi(struct spi_device
*dev
,
400 const struct regmap_config
*config
,
401 struct lock_class_key
*lock_key
,
402 const char *lock_name
);
403 struct regmap
*__regmap_init_spmi_base(struct spmi_device
*dev
,
404 const struct regmap_config
*config
,
405 struct lock_class_key
*lock_key
,
406 const char *lock_name
);
407 struct regmap
*__regmap_init_spmi_ext(struct spmi_device
*dev
,
408 const struct regmap_config
*config
,
409 struct lock_class_key
*lock_key
,
410 const char *lock_name
);
411 struct regmap
*__regmap_init_mmio_clk(struct device
*dev
, const char *clk_id
,
413 const struct regmap_config
*config
,
414 struct lock_class_key
*lock_key
,
415 const char *lock_name
);
416 struct regmap
*__regmap_init_ac97(struct snd_ac97
*ac97
,
417 const struct regmap_config
*config
,
418 struct lock_class_key
*lock_key
,
419 const char *lock_name
);
421 struct regmap
*__devm_regmap_init(struct device
*dev
,
422 const struct regmap_bus
*bus
,
424 const struct regmap_config
*config
,
425 struct lock_class_key
*lock_key
,
426 const char *lock_name
);
427 struct regmap
*__devm_regmap_init_i2c(struct i2c_client
*i2c
,
428 const struct regmap_config
*config
,
429 struct lock_class_key
*lock_key
,
430 const char *lock_name
);
431 struct regmap
*__devm_regmap_init_spi(struct spi_device
*dev
,
432 const struct regmap_config
*config
,
433 struct lock_class_key
*lock_key
,
434 const char *lock_name
);
435 struct regmap
*__devm_regmap_init_spmi_base(struct spmi_device
*dev
,
436 const struct regmap_config
*config
,
437 struct lock_class_key
*lock_key
,
438 const char *lock_name
);
439 struct regmap
*__devm_regmap_init_spmi_ext(struct spmi_device
*dev
,
440 const struct regmap_config
*config
,
441 struct lock_class_key
*lock_key
,
442 const char *lock_name
);
443 struct regmap
*__devm_regmap_init_mmio_clk(struct device
*dev
,
446 const struct regmap_config
*config
,
447 struct lock_class_key
*lock_key
,
448 const char *lock_name
);
449 struct regmap
*__devm_regmap_init_ac97(struct snd_ac97
*ac97
,
450 const struct regmap_config
*config
,
451 struct lock_class_key
*lock_key
,
452 const char *lock_name
);
455 * Wrapper for regmap_init macros to include a unique lockdep key and name
456 * for each call. No-op if CONFIG_LOCKDEP is not set.
458 * @fn: Real function to call (in the form __[*_]regmap_init[_*])
459 * @name: Config variable name (#config in the calling macro)
461 #ifdef CONFIG_LOCKDEP
462 #define __regmap_lockdep_wrapper(fn, name, ...) \
465 static struct lock_class_key _key; \
466 fn(__VA_ARGS__, &_key, \
467 KBUILD_BASENAME ":" \
468 __stringify(__LINE__) ":" \
469 "(" name ")->lock"); \
473 #define __regmap_lockdep_wrapper(fn, name, ...) fn(__VA_ARGS__, NULL, NULL)
477 * regmap_init(): Initialise register map
479 * @dev: Device that will be interacted with
480 * @bus: Bus-specific callbacks to use with device
481 * @bus_context: Data passed to bus-specific callbacks
482 * @config: Configuration for register map
484 * The return value will be an ERR_PTR() on error or a valid pointer to
485 * a struct regmap. This function should generally not be called
486 * directly, it should be called by bus-specific init functions.
488 #define regmap_init(dev, bus, bus_context, config) \
489 __regmap_lockdep_wrapper(__regmap_init, #config, \
490 dev, bus, bus_context, config)
491 int regmap_attach_dev(struct device
*dev
, struct regmap
*map
,
492 const struct regmap_config
*config
);
495 * regmap_init_i2c(): Initialise register map
497 * @i2c: 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_i2c(i2c, config) \
504 __regmap_lockdep_wrapper(__regmap_init_i2c, #config, \
508 * regmap_init_spi(): Initialise register map
510 * @spi: Device that will be interacted with
511 * @config: Configuration for register map
513 * The return value will be an ERR_PTR() on error or a valid pointer to
516 #define regmap_init_spi(dev, config) \
517 __regmap_lockdep_wrapper(__regmap_init_spi, #config, \
521 * regmap_init_spmi_base(): Create regmap for the Base register space
522 * @sdev: SPMI device that will be interacted with
523 * @config: Configuration for register map
525 * The return value will be an ERR_PTR() on error or a valid pointer to
528 #define regmap_init_spmi_base(dev, config) \
529 __regmap_lockdep_wrapper(__regmap_init_spmi_base, #config, \
533 * regmap_init_spmi_ext(): Create regmap for Ext register space
534 * @sdev: Device that will be interacted with
535 * @config: Configuration for register map
537 * The return value will be an ERR_PTR() on error or a valid pointer to
540 #define regmap_init_spmi_ext(dev, config) \
541 __regmap_lockdep_wrapper(__regmap_init_spmi_ext, #config, \
545 * regmap_init_mmio_clk(): Initialise register map with register clock
547 * @dev: Device that will be interacted with
548 * @clk_id: register clock consumer ID
549 * @regs: Pointer to memory-mapped IO region
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_mmio_clk(dev, clk_id, regs, config) \
556 __regmap_lockdep_wrapper(__regmap_init_mmio_clk, #config, \
557 dev, clk_id, regs, config)
560 * regmap_init_mmio(): Initialise register map
562 * @dev: Device that will be interacted with
563 * @regs: Pointer to memory-mapped IO region
564 * @config: Configuration for register map
566 * The return value will be an ERR_PTR() on error or a valid pointer to
569 #define regmap_init_mmio(dev, regs, config) \
570 regmap_init_mmio_clk(dev, NULL, regs, config)
573 * regmap_init_ac97(): Initialise AC'97 register map
575 * @ac97: 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_ac97(ac97, config) \
582 __regmap_lockdep_wrapper(__regmap_init_ac97, #config, \
584 bool regmap_ac97_default_volatile(struct device
*dev
, unsigned int reg
);
587 * devm_regmap_init(): Initialise managed register map
589 * @dev: Device that will be interacted with
590 * @bus: Bus-specific callbacks to use with device
591 * @bus_context: Data passed to bus-specific callbacks
592 * @config: Configuration for register map
594 * The return value will be an ERR_PTR() on error or a valid pointer
595 * to a struct regmap. This function should generally not be called
596 * directly, it should be called by bus-specific init functions. The
597 * map will be automatically freed by the device management code.
599 #define devm_regmap_init(dev, bus, bus_context, config) \
600 __regmap_lockdep_wrapper(__devm_regmap_init, #config, \
601 dev, bus, bus_context, config)
604 * devm_regmap_init_i2c(): Initialise managed register map
606 * @i2c: Device that will be interacted with
607 * @config: Configuration for register map
609 * The return value will be an ERR_PTR() on error or a valid pointer
610 * to a struct regmap. The regmap will be automatically freed by the
611 * device management code.
613 #define devm_regmap_init_i2c(i2c, config) \
614 __regmap_lockdep_wrapper(__devm_regmap_init_i2c, #config, \
618 * devm_regmap_init_spi(): Initialise register map
620 * @spi: 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 map will be automatically freed by the
625 * device management code.
627 #define devm_regmap_init_spi(dev, config) \
628 __regmap_lockdep_wrapper(__devm_regmap_init_spi, #config, \
632 * devm_regmap_init_spmi_base(): Create managed regmap for Base 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_base(dev, config) \
641 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_base, #config, \
645 * devm_regmap_init_spmi_ext(): Create managed regmap for Ext register space
646 * @sdev: SPMI device that will be interacted with
647 * @config: Configuration for register map
649 * The return value will be an ERR_PTR() on error or a valid pointer
650 * to a struct regmap. The regmap will be automatically freed by the
651 * device management code.
653 #define devm_regmap_init_spmi_ext(dev, config) \
654 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_ext, #config, \
658 * devm_regmap_init_mmio_clk(): Initialise managed register map with clock
660 * @dev: Device that will be interacted with
661 * @clk_id: register clock consumer ID
662 * @regs: Pointer to memory-mapped IO region
663 * @config: Configuration for register map
665 * The return value will be an ERR_PTR() on error or a valid pointer
666 * to a struct regmap. The regmap will be automatically freed by the
667 * device management code.
669 #define devm_regmap_init_mmio_clk(dev, clk_id, regs, config) \
670 __regmap_lockdep_wrapper(__devm_regmap_init_mmio_clk, #config, \
671 dev, clk_id, regs, config)
674 * devm_regmap_init_mmio(): Initialise managed register map
676 * @dev: Device that will be interacted with
677 * @regs: Pointer to memory-mapped IO region
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_mmio(dev, regs, config) \
685 devm_regmap_init_mmio_clk(dev, NULL, regs, config)
688 * devm_regmap_init_ac97(): Initialise AC'97 register map
690 * @ac97: Device that will be interacted with
691 * @config: Configuration for register map
693 * The return value will be an ERR_PTR() on error or a valid pointer
694 * to a struct regmap. The regmap will be automatically freed by the
695 * device management code.
697 #define devm_regmap_init_ac97(ac97, config) \
698 __regmap_lockdep_wrapper(__devm_regmap_init_ac97, #config, \
701 void regmap_exit(struct regmap
*map
);
702 int regmap_reinit_cache(struct regmap
*map
,
703 const struct regmap_config
*config
);
704 struct regmap
*dev_get_regmap(struct device
*dev
, const char *name
);
705 struct device
*regmap_get_device(struct regmap
*map
);
706 int regmap_write(struct regmap
*map
, unsigned int reg
, unsigned int val
);
707 int regmap_write_async(struct regmap
*map
, unsigned int reg
, unsigned int val
);
708 int regmap_raw_write(struct regmap
*map
, unsigned int reg
,
709 const void *val
, size_t val_len
);
710 int regmap_bulk_write(struct regmap
*map
, unsigned int reg
, const void *val
,
712 int regmap_multi_reg_write(struct regmap
*map
, const struct reg_sequence
*regs
,
714 int regmap_multi_reg_write_bypassed(struct regmap
*map
,
715 const struct reg_sequence
*regs
,
717 int regmap_raw_write_async(struct regmap
*map
, unsigned int reg
,
718 const void *val
, size_t val_len
);
719 int regmap_read(struct regmap
*map
, unsigned int reg
, unsigned int *val
);
720 int regmap_raw_read(struct regmap
*map
, unsigned int reg
,
721 void *val
, size_t val_len
);
722 int regmap_bulk_read(struct regmap
*map
, unsigned int reg
, void *val
,
724 int regmap_update_bits_base(struct regmap
*map
, unsigned int reg
,
725 unsigned int mask
, unsigned int val
,
726 bool *change
, bool async
, bool force
);
727 int regmap_get_val_bytes(struct regmap
*map
);
728 int regmap_get_max_register(struct regmap
*map
);
729 int regmap_get_reg_stride(struct regmap
*map
);
730 int regmap_async_complete(struct regmap
*map
);
731 bool regmap_can_raw_write(struct regmap
*map
);
732 size_t regmap_get_raw_read_max(struct regmap
*map
);
733 size_t regmap_get_raw_write_max(struct regmap
*map
);
735 int regcache_sync(struct regmap
*map
);
736 int regcache_sync_region(struct regmap
*map
, unsigned int min
,
738 int regcache_drop_region(struct regmap
*map
, unsigned int min
,
740 void regcache_cache_only(struct regmap
*map
, bool enable
);
741 void regcache_cache_bypass(struct regmap
*map
, bool enable
);
742 void regcache_mark_dirty(struct regmap
*map
);
744 bool regmap_check_range_table(struct regmap
*map
, unsigned int reg
,
745 const struct regmap_access_table
*table
);
747 int regmap_register_patch(struct regmap
*map
, const struct reg_sequence
*regs
,
749 int regmap_parse_val(struct regmap
*map
, const void *buf
,
752 static inline bool regmap_reg_in_range(unsigned int reg
,
753 const struct regmap_range
*range
)
755 return reg
>= range
->range_min
&& reg
<= range
->range_max
;
758 bool regmap_reg_in_ranges(unsigned int reg
,
759 const struct regmap_range
*ranges
,
760 unsigned int nranges
);
763 * Description of an register field
765 * @reg: Offset of the register within the regmap bank
766 * @lsb: lsb of the register field.
767 * @msb: msb of the register field.
768 * @id_size: port size if it has some ports
769 * @id_offset: address offset for each ports
775 unsigned int id_size
;
776 unsigned int id_offset
;
779 #define REG_FIELD(_reg, _lsb, _msb) { \
785 struct regmap_field
*regmap_field_alloc(struct regmap
*regmap
,
786 struct reg_field reg_field
);
787 void regmap_field_free(struct regmap_field
*field
);
789 struct regmap_field
*devm_regmap_field_alloc(struct device
*dev
,
790 struct regmap
*regmap
, struct reg_field reg_field
);
791 void devm_regmap_field_free(struct device
*dev
, struct regmap_field
*field
);
793 int regmap_field_read(struct regmap_field
*field
, unsigned int *val
);
794 int regmap_field_update_bits_base(struct regmap_field
*field
,
795 unsigned int mask
, unsigned int val
,
796 bool *change
, bool async
, bool force
);
797 int regmap_fields_read(struct regmap_field
*field
, unsigned int id
,
799 int regmap_fields_update_bits_base(struct regmap_field
*field
, unsigned int id
,
800 unsigned int mask
, unsigned int val
,
801 bool *change
, bool async
, bool force
);
804 * Description of an IRQ for the generic regmap irq_chip.
806 * @reg_offset: Offset of the status/mask register within the bank
807 * @mask: Mask used to flag/control the register.
808 * @type_reg_offset: Offset register for the irq type setting.
809 * @type_rising_mask: Mask bit to configure RISING type irq.
810 * @type_falling_mask: Mask bit to configure FALLING type irq.
813 unsigned int reg_offset
;
815 unsigned int type_reg_offset
;
816 unsigned int type_rising_mask
;
817 unsigned int type_falling_mask
;
820 #define REGMAP_IRQ_REG(_irq, _off, _mask) \
821 [_irq] = { .reg_offset = (_off), .mask = (_mask) }
824 * Description of a generic regmap irq_chip. This is not intended to
825 * handle every possible interrupt controller, but it should handle a
826 * substantial proportion of those that are found in the wild.
828 * @name: Descriptive name for IRQ controller.
830 * @status_base: Base status register address.
831 * @mask_base: Base mask register address.
832 * @unmask_base: Base unmask register address. for chips who have
833 * separate mask and unmask registers
834 * @ack_base: Base ack address. If zero then the chip is clear on read.
835 * Using zero value is possible with @use_ack bit.
836 * @wake_base: Base address for wake enables. If zero unsupported.
837 * @type_base: Base address for irq type. If zero unsupported.
838 * @irq_reg_stride: Stride to use for chips where registers are not contiguous.
839 * @init_ack_masked: Ack all masked interrupts once during initalization.
840 * @mask_invert: Inverted mask register: cleared bits are masked out.
841 * @use_ack: Use @ack register even if it is zero.
842 * @ack_invert: Inverted ack register: cleared bits for ack.
843 * @wake_invert: Inverted wake register: cleared bits are wake enabled.
844 * @type_invert: Invert the type flags.
845 * @runtime_pm: Hold a runtime PM lock on the device when accessing it.
847 * @num_regs: Number of registers in each control bank.
848 * @irqs: Descriptors for individual IRQs. Interrupt numbers are
849 * assigned based on the index in the array of the interrupt.
850 * @num_irqs: Number of descriptors.
851 * @num_type_reg: Number of type registers.
852 * @type_reg_stride: Stride to use for chips where type registers are not
855 struct regmap_irq_chip
{
858 unsigned int status_base
;
859 unsigned int mask_base
;
860 unsigned int unmask_base
;
861 unsigned int ack_base
;
862 unsigned int wake_base
;
863 unsigned int type_base
;
864 unsigned int irq_reg_stride
;
865 bool init_ack_masked
:1;
875 const struct regmap_irq
*irqs
;
879 unsigned int type_reg_stride
;
882 struct regmap_irq_chip_data
;
884 int regmap_add_irq_chip(struct regmap
*map
, int irq
, int irq_flags
,
885 int irq_base
, const struct regmap_irq_chip
*chip
,
886 struct regmap_irq_chip_data
**data
);
887 void regmap_del_irq_chip(int irq
, struct regmap_irq_chip_data
*data
);
889 int devm_regmap_add_irq_chip(struct device
*dev
, struct regmap
*map
, int irq
,
890 int irq_flags
, int irq_base
,
891 const struct regmap_irq_chip
*chip
,
892 struct regmap_irq_chip_data
**data
);
893 void devm_regmap_del_irq_chip(struct device
*dev
, int irq
,
894 struct regmap_irq_chip_data
*data
);
896 int regmap_irq_chip_get_base(struct regmap_irq_chip_data
*data
);
897 int regmap_irq_get_virq(struct regmap_irq_chip_data
*data
, int irq
);
898 struct irq_domain
*regmap_irq_get_domain(struct regmap_irq_chip_data
*data
);
903 * These stubs should only ever be called by generic code which has
904 * regmap based facilities, if they ever get called at runtime
905 * something is going wrong and something probably needs to select
909 static inline int regmap_write(struct regmap
*map
, unsigned int reg
,
912 WARN_ONCE(1, "regmap API is disabled");
916 static inline int regmap_write_async(struct regmap
*map
, unsigned int reg
,
919 WARN_ONCE(1, "regmap API is disabled");
923 static inline int regmap_raw_write(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_raw_write_async(struct regmap
*map
, unsigned int reg
,
931 const void *val
, size_t val_len
)
933 WARN_ONCE(1, "regmap API is disabled");
937 static inline int regmap_bulk_write(struct regmap
*map
, unsigned int reg
,
938 const void *val
, size_t val_count
)
940 WARN_ONCE(1, "regmap API is disabled");
944 static inline int regmap_read(struct regmap
*map
, unsigned int reg
,
947 WARN_ONCE(1, "regmap API is disabled");
951 static inline int regmap_raw_read(struct regmap
*map
, unsigned int reg
,
952 void *val
, size_t val_len
)
954 WARN_ONCE(1, "regmap API is disabled");
958 static inline int regmap_bulk_read(struct regmap
*map
, unsigned int reg
,
959 void *val
, size_t val_count
)
961 WARN_ONCE(1, "regmap API is disabled");
965 static inline int regmap_update_bits_base(struct regmap
*map
, unsigned int reg
,
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_field_update_bits_base(struct regmap_field
*field
,
974 unsigned int mask
, unsigned int val
,
975 bool *change
, bool async
, bool force
)
977 WARN_ONCE(1, "regmap API is disabled");
981 static inline int regmap_fields_update_bits_base(struct regmap_field
*field
,
983 unsigned int mask
, unsigned int val
,
984 bool *change
, bool async
, bool force
)
986 WARN_ONCE(1, "regmap API is disabled");
990 static inline int regmap_get_val_bytes(struct regmap
*map
)
992 WARN_ONCE(1, "regmap API is disabled");
996 static inline int regmap_get_max_register(struct regmap
*map
)
998 WARN_ONCE(1, "regmap API is disabled");
1002 static inline int regmap_get_reg_stride(struct regmap
*map
)
1004 WARN_ONCE(1, "regmap API is disabled");
1008 static inline int regcache_sync(struct regmap
*map
)
1010 WARN_ONCE(1, "regmap API is disabled");
1014 static inline int regcache_sync_region(struct regmap
*map
, unsigned int min
,
1017 WARN_ONCE(1, "regmap API is disabled");
1021 static inline int regcache_drop_region(struct regmap
*map
, unsigned int min
,
1024 WARN_ONCE(1, "regmap API is disabled");
1028 static inline void regcache_cache_only(struct regmap
*map
, bool enable
)
1030 WARN_ONCE(1, "regmap API is disabled");
1033 static inline void regcache_cache_bypass(struct regmap
*map
, bool enable
)
1035 WARN_ONCE(1, "regmap API is disabled");
1038 static inline void regcache_mark_dirty(struct regmap
*map
)
1040 WARN_ONCE(1, "regmap API is disabled");
1043 static inline void regmap_async_complete(struct regmap
*map
)
1045 WARN_ONCE(1, "regmap API is disabled");
1048 static inline int regmap_register_patch(struct regmap
*map
,
1049 const struct reg_sequence
*regs
,
1052 WARN_ONCE(1, "regmap API is disabled");
1056 static inline int regmap_parse_val(struct regmap
*map
, const void *buf
,
1059 WARN_ONCE(1, "regmap API is disabled");
1063 static inline struct regmap
*dev_get_regmap(struct device
*dev
,
1069 static inline struct device
*regmap_get_device(struct regmap
*map
)
1071 WARN_ONCE(1, "regmap API is disabled");