Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0-only */
2#ifndef __LINUX_REGMAP_H
3#define __LINUX_REGMAP_H
4
5/*
6 * Register map access API
7 *
8 * Copyright 2011 Wolfson Microelectronics plc
9 *
10 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
11 */
12
13#include <linux/list.h>
14#include <linux/rbtree.h>
15#include <linux/ktime.h>
16#include <linux/delay.h>
17#include <linux/err.h>
18#include <linux/bug.h>
19#include <linux/lockdep.h>
20#include <linux/iopoll.h>
21#include <linux/fwnode.h>
22
23struct module;
24struct clk;
25struct device;
26struct device_node;
27struct i2c_client;
28struct i3c_device;
29struct irq_domain;
30struct mdio_device;
31struct slim_device;
32struct spi_device;
33struct spmi_device;
34struct regmap;
35struct regmap_range_cfg;
36struct regmap_field;
37struct snd_ac97;
38struct sdw_slave;
39
40/* An enum of all the supported cache types */
41enum regcache_type {
42 REGCACHE_NONE,
43 REGCACHE_RBTREE,
44 REGCACHE_COMPRESSED,
45 REGCACHE_FLAT,
46};
47
48/**
49 * struct reg_default - Default value for a register.
50 *
51 * @reg: Register address.
52 * @def: Register default value.
53 *
54 * We use an array of structs rather than a simple array as many modern devices
55 * have very sparse register maps.
56 */
57struct reg_default {
58 unsigned int reg;
59 unsigned int def;
60};
61
62/**
63 * struct reg_sequence - An individual write from a sequence of writes.
64 *
65 * @reg: Register address.
66 * @def: Register value.
67 * @delay_us: Delay to be applied after the register write in microseconds
68 *
69 * Register/value pairs for sequences of writes with an optional delay in
70 * microseconds to be applied after each write.
71 */
72struct reg_sequence {
73 unsigned int reg;
74 unsigned int def;
75 unsigned int delay_us;
76};
77
78#define REG_SEQ(_reg, _def, _delay_us) { \
79 .reg = _reg, \
80 .def = _def, \
81 .delay_us = _delay_us, \
82 }
83#define REG_SEQ0(_reg, _def) REG_SEQ(_reg, _def, 0)
84
85/**
86 * regmap_read_poll_timeout - Poll until a condition is met or a timeout occurs
87 *
88 * @map: Regmap to read from
89 * @addr: Address to poll
90 * @val: Unsigned integer variable to read the value into
91 * @cond: Break condition (usually involving @val)
92 * @sleep_us: Maximum time to sleep between reads in us (0
93 * tight-loops). Should be less than ~20ms since usleep_range
94 * is used (see Documentation/timers/timers-howto.rst).
95 * @timeout_us: Timeout in us, 0 means never timeout
96 *
97 * Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_read
98 * error return value in case of a error read. In the two former cases,
99 * the last read value at @addr is stored in @val. Must not be called
100 * from atomic context if sleep_us or timeout_us are used.
101 *
102 * This is modelled after the readx_poll_timeout macros in linux/iopoll.h.
103 */
104#define regmap_read_poll_timeout(map, addr, val, cond, sleep_us, timeout_us) \
105({ \
106 int __ret, __tmp; \
107 __tmp = read_poll_timeout(regmap_read, __ret, __ret || (cond), \
108 sleep_us, timeout_us, false, (map), (addr), &(val)); \
109 __ret ?: __tmp; \
110})
111
112/**
113 * regmap_read_poll_timeout_atomic - Poll until a condition is met or a timeout occurs
114 *
115 * @map: Regmap to read from
116 * @addr: Address to poll
117 * @val: Unsigned integer variable to read the value into
118 * @cond: Break condition (usually involving @val)
119 * @delay_us: Time to udelay between reads in us (0 tight-loops).
120 * Should be less than ~10us since udelay is used
121 * (see Documentation/timers/timers-howto.rst).
122 * @timeout_us: Timeout in us, 0 means never timeout
123 *
124 * Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_read
125 * error return value in case of a error read. In the two former cases,
126 * the last read value at @addr is stored in @val.
127 *
128 * This is modelled after the readx_poll_timeout_atomic macros in linux/iopoll.h.
129 *
130 * Note: In general regmap cannot be used in atomic context. If you want to use
131 * this macro then first setup your regmap for atomic use (flat or no cache
132 * and MMIO regmap).
133 */
134#define regmap_read_poll_timeout_atomic(map, addr, val, cond, delay_us, timeout_us) \
135({ \
136 u64 __timeout_us = (timeout_us); \
137 unsigned long __delay_us = (delay_us); \
138 ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \
139 int __ret; \
140 for (;;) { \
141 __ret = regmap_read((map), (addr), &(val)); \
142 if (__ret) \
143 break; \
144 if (cond) \
145 break; \
146 if ((__timeout_us) && \
147 ktime_compare(ktime_get(), __timeout) > 0) { \
148 __ret = regmap_read((map), (addr), &(val)); \
149 break; \
150 } \
151 if (__delay_us) \
152 udelay(__delay_us); \
153 } \
154 __ret ?: ((cond) ? 0 : -ETIMEDOUT); \
155})
156
157/**
158 * regmap_field_read_poll_timeout - Poll until a condition is met or timeout
159 *
160 * @field: Regmap field to read from
161 * @val: Unsigned integer variable to read the value into
162 * @cond: Break condition (usually involving @val)
163 * @sleep_us: Maximum time to sleep between reads in us (0
164 * tight-loops). Should be less than ~20ms since usleep_range
165 * is used (see Documentation/timers/timers-howto.rst).
166 * @timeout_us: Timeout in us, 0 means never timeout
167 *
168 * Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_field_read
169 * error return value in case of a error read. In the two former cases,
170 * the last read value at @addr is stored in @val. Must not be called
171 * from atomic context if sleep_us or timeout_us are used.
172 *
173 * This is modelled after the readx_poll_timeout macros in linux/iopoll.h.
174 */
175#define regmap_field_read_poll_timeout(field, val, cond, sleep_us, timeout_us) \
176({ \
177 int __ret, __tmp; \
178 __tmp = read_poll_timeout(regmap_field_read, __ret, __ret || (cond), \
179 sleep_us, timeout_us, false, (field), &(val)); \
180 __ret ?: __tmp; \
181})
182
183#ifdef CONFIG_REGMAP
184
185enum regmap_endian {
186 /* Unspecified -> 0 -> Backwards compatible default */
187 REGMAP_ENDIAN_DEFAULT = 0,
188 REGMAP_ENDIAN_BIG,
189 REGMAP_ENDIAN_LITTLE,
190 REGMAP_ENDIAN_NATIVE,
191};
192
193/**
194 * struct regmap_range - A register range, used for access related checks
195 * (readable/writeable/volatile/precious checks)
196 *
197 * @range_min: address of first register
198 * @range_max: address of last register
199 */
200struct regmap_range {
201 unsigned int range_min;
202 unsigned int range_max;
203};
204
205#define regmap_reg_range(low, high) { .range_min = low, .range_max = high, }
206
207/**
208 * struct regmap_access_table - A table of register ranges for access checks
209 *
210 * @yes_ranges : pointer to an array of regmap ranges used as "yes ranges"
211 * @n_yes_ranges: size of the above array
212 * @no_ranges: pointer to an array of regmap ranges used as "no ranges"
213 * @n_no_ranges: size of the above array
214 *
215 * A table of ranges including some yes ranges and some no ranges.
216 * If a register belongs to a no_range, the corresponding check function
217 * will return false. If a register belongs to a yes range, the corresponding
218 * check function will return true. "no_ranges" are searched first.
219 */
220struct regmap_access_table {
221 const struct regmap_range *yes_ranges;
222 unsigned int n_yes_ranges;
223 const struct regmap_range *no_ranges;
224 unsigned int n_no_ranges;
225};
226
227typedef void (*regmap_lock)(void *);
228typedef void (*regmap_unlock)(void *);
229
230/**
231 * struct regmap_config - Configuration for the register map of a device.
232 *
233 * @name: Optional name of the regmap. Useful when a device has multiple
234 * register regions.
235 *
236 * @reg_bits: Number of bits in a register address, mandatory.
237 * @reg_stride: The register address stride. Valid register addresses are a
238 * multiple of this value. If set to 0, a value of 1 will be
239 * used.
240 * @pad_bits: Number of bits of padding between register and value.
241 * @val_bits: Number of bits in a register value, mandatory.
242 *
243 * @writeable_reg: Optional callback returning true if the register
244 * can be written to. If this field is NULL but wr_table
245 * (see below) is not, the check is performed on such table
246 * (a register is writeable if it belongs to one of the ranges
247 * specified by wr_table).
248 * @readable_reg: Optional callback returning true if the register
249 * can be read from. If this field is NULL but rd_table
250 * (see below) is not, the check is performed on such table
251 * (a register is readable if it belongs to one of the ranges
252 * specified by rd_table).
253 * @volatile_reg: Optional callback returning true if the register
254 * value can't be cached. If this field is NULL but
255 * volatile_table (see below) is not, the check is performed on
256 * such table (a register is volatile if it belongs to one of
257 * the ranges specified by volatile_table).
258 * @precious_reg: Optional callback returning true if the register
259 * should not be read outside of a call from the driver
260 * (e.g., a clear on read interrupt status register). If this
261 * field is NULL but precious_table (see below) is not, the
262 * check is performed on such table (a register is precious if
263 * it belongs to one of the ranges specified by precious_table).
264 * @writeable_noinc_reg: Optional callback returning true if the register
265 * supports multiple write operations without incrementing
266 * the register number. If this field is NULL but
267 * wr_noinc_table (see below) is not, the check is
268 * performed on such table (a register is no increment
269 * writeable if it belongs to one of the ranges specified
270 * by wr_noinc_table).
271 * @readable_noinc_reg: Optional callback returning true if the register
272 * supports multiple read operations without incrementing
273 * the register number. If this field is NULL but
274 * rd_noinc_table (see below) is not, the check is
275 * performed on such table (a register is no increment
276 * readable if it belongs to one of the ranges specified
277 * by rd_noinc_table).
278 * @disable_locking: This regmap is either protected by external means or
279 * is guaranteed not to be accessed from multiple threads.
280 * Don't use any locking mechanisms.
281 * @lock: Optional lock callback (overrides regmap's default lock
282 * function, based on spinlock or mutex).
283 * @unlock: As above for unlocking.
284 * @lock_arg: this field is passed as the only argument of lock/unlock
285 * functions (ignored in case regular lock/unlock functions
286 * are not overridden).
287 * @reg_read: Optional callback that if filled will be used to perform
288 * all the reads from the registers. Should only be provided for
289 * devices whose read operation cannot be represented as a simple
290 * read operation on a bus such as SPI, I2C, etc. Most of the
291 * devices do not need this.
292 * @reg_write: Same as above for writing.
293 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
294 * to perform locking. This field is ignored if custom lock/unlock
295 * functions are used (see fields lock/unlock of struct regmap_config).
296 * This field is a duplicate of a similar file in
297 * 'struct regmap_bus' and serves exact same purpose.
298 * Use it only for "no-bus" cases.
299 * @max_register: Optional, specifies the maximum valid register address.
300 * @wr_table: Optional, points to a struct regmap_access_table specifying
301 * valid ranges for write access.
302 * @rd_table: As above, for read access.
303 * @volatile_table: As above, for volatile registers.
304 * @precious_table: As above, for precious registers.
305 * @wr_noinc_table: As above, for no increment writeable registers.
306 * @rd_noinc_table: As above, for no increment readable registers.
307 * @reg_defaults: Power on reset values for registers (for use with
308 * register cache support).
309 * @num_reg_defaults: Number of elements in reg_defaults.
310 *
311 * @read_flag_mask: Mask to be set in the top bytes of the register when doing
312 * a read.
313 * @write_flag_mask: Mask to be set in the top bytes of the register when doing
314 * a write. If both read_flag_mask and write_flag_mask are
315 * empty and zero_flag_mask is not set the regmap_bus default
316 * masks are used.
317 * @zero_flag_mask: If set, read_flag_mask and write_flag_mask are used even
318 * if they are both empty.
319 * @use_relaxed_mmio: If set, MMIO R/W operations will not use memory barriers.
320 * This can avoid load on devices which don't require strict
321 * orderings, but drivers should carefully add any explicit
322 * memory barriers when they may require them.
323 * @use_single_read: If set, converts the bulk read operation into a series of
324 * single read operations. This is useful for a device that
325 * does not support bulk read.
326 * @use_single_write: If set, converts the bulk write operation into a series of
327 * single write operations. This is useful for a device that
328 * does not support bulk write.
329 * @can_multi_write: If set, the device supports the multi write mode of bulk
330 * write operations, if clear multi write requests will be
331 * split into individual write operations
332 *
333 * @cache_type: The actual cache type.
334 * @reg_defaults_raw: Power on reset values for registers (for use with
335 * register cache support).
336 * @num_reg_defaults_raw: Number of elements in reg_defaults_raw.
337 * @reg_format_endian: Endianness for formatted register addresses. If this is
338 * DEFAULT, the @reg_format_endian_default value from the
339 * regmap bus is used.
340 * @val_format_endian: Endianness for formatted register values. If this is
341 * DEFAULT, the @reg_format_endian_default value from the
342 * regmap bus is used.
343 *
344 * @ranges: Array of configuration entries for virtual address ranges.
345 * @num_ranges: Number of range configuration entries.
346 * @use_hwlock: Indicate if a hardware spinlock should be used.
347 * @hwlock_id: Specify the hardware spinlock id.
348 * @hwlock_mode: The hardware spinlock mode, should be HWLOCK_IRQSTATE,
349 * HWLOCK_IRQ or 0.
350 * @can_sleep: Optional, specifies whether regmap operations can sleep.
351 */
352struct regmap_config {
353 const char *name;
354
355 int reg_bits;
356 int reg_stride;
357 int pad_bits;
358 int val_bits;
359
360 bool (*writeable_reg)(struct device *dev, unsigned int reg);
361 bool (*readable_reg)(struct device *dev, unsigned int reg);
362 bool (*volatile_reg)(struct device *dev, unsigned int reg);
363 bool (*precious_reg)(struct device *dev, unsigned int reg);
364 bool (*writeable_noinc_reg)(struct device *dev, unsigned int reg);
365 bool (*readable_noinc_reg)(struct device *dev, unsigned int reg);
366
367 bool disable_locking;
368 regmap_lock lock;
369 regmap_unlock unlock;
370 void *lock_arg;
371
372 int (*reg_read)(void *context, unsigned int reg, unsigned int *val);
373 int (*reg_write)(void *context, unsigned int reg, unsigned int val);
374
375 bool fast_io;
376
377 unsigned int max_register;
378 const struct regmap_access_table *wr_table;
379 const struct regmap_access_table *rd_table;
380 const struct regmap_access_table *volatile_table;
381 const struct regmap_access_table *precious_table;
382 const struct regmap_access_table *wr_noinc_table;
383 const struct regmap_access_table *rd_noinc_table;
384 const struct reg_default *reg_defaults;
385 unsigned int num_reg_defaults;
386 enum regcache_type cache_type;
387 const void *reg_defaults_raw;
388 unsigned int num_reg_defaults_raw;
389
390 unsigned long read_flag_mask;
391 unsigned long write_flag_mask;
392 bool zero_flag_mask;
393
394 bool use_single_read;
395 bool use_single_write;
396 bool use_relaxed_mmio;
397 bool can_multi_write;
398
399 enum regmap_endian reg_format_endian;
400 enum regmap_endian val_format_endian;
401
402 const struct regmap_range_cfg *ranges;
403 unsigned int num_ranges;
404
405 bool use_hwlock;
406 unsigned int hwlock_id;
407 unsigned int hwlock_mode;
408
409 bool can_sleep;
410};
411
412/**
413 * struct regmap_range_cfg - Configuration for indirectly accessed or paged
414 * registers.
415 *
416 * @name: Descriptive name for diagnostics
417 *
418 * @range_min: Address of the lowest register address in virtual range.
419 * @range_max: Address of the highest register in virtual range.
420 *
421 * @selector_reg: Register with selector field.
422 * @selector_mask: Bit mask for selector value.
423 * @selector_shift: Bit shift for selector value.
424 *
425 * @window_start: Address of first (lowest) register in data window.
426 * @window_len: Number of registers in data window.
427 *
428 * Registers, mapped to this virtual range, are accessed in two steps:
429 * 1. page selector register update;
430 * 2. access through data window registers.
431 */
432struct regmap_range_cfg {
433 const char *name;
434
435 /* Registers of virtual address range */
436 unsigned int range_min;
437 unsigned int range_max;
438
439 /* Page selector for indirect addressing */
440 unsigned int selector_reg;
441 unsigned int selector_mask;
442 int selector_shift;
443
444 /* Data window (per each page) */
445 unsigned int window_start;
446 unsigned int window_len;
447};
448
449struct regmap_async;
450
451typedef int (*regmap_hw_write)(void *context, const void *data,
452 size_t count);
453typedef int (*regmap_hw_gather_write)(void *context,
454 const void *reg, size_t reg_len,
455 const void *val, size_t val_len);
456typedef int (*regmap_hw_async_write)(void *context,
457 const void *reg, size_t reg_len,
458 const void *val, size_t val_len,
459 struct regmap_async *async);
460typedef int (*regmap_hw_read)(void *context,
461 const void *reg_buf, size_t reg_size,
462 void *val_buf, size_t val_size);
463typedef int (*regmap_hw_reg_read)(void *context, unsigned int reg,
464 unsigned int *val);
465typedef int (*regmap_hw_reg_write)(void *context, unsigned int reg,
466 unsigned int val);
467typedef int (*regmap_hw_reg_update_bits)(void *context, unsigned int reg,
468 unsigned int mask, unsigned int val);
469typedef struct regmap_async *(*regmap_hw_async_alloc)(void);
470typedef void (*regmap_hw_free_context)(void *context);
471
472/**
473 * struct regmap_bus - Description of a hardware bus for the register map
474 * infrastructure.
475 *
476 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
477 * to perform locking. This field is ignored if custom lock/unlock
478 * functions are used (see fields lock/unlock of
479 * struct regmap_config).
480 * @write: Write operation.
481 * @gather_write: Write operation with split register/value, return -ENOTSUPP
482 * if not implemented on a given device.
483 * @async_write: Write operation which completes asynchronously, optional and
484 * must serialise with respect to non-async I/O.
485 * @reg_write: Write a single register value to the given register address. This
486 * write operation has to complete when returning from the function.
487 * @reg_update_bits: Update bits operation to be used against volatile
488 * registers, intended for devices supporting some mechanism
489 * for setting clearing bits without having to
490 * read/modify/write.
491 * @read: Read operation. Data is returned in the buffer used to transmit
492 * data.
493 * @reg_read: Read a single register value from a given register address.
494 * @free_context: Free context.
495 * @async_alloc: Allocate a regmap_async() structure.
496 * @read_flag_mask: Mask to be set in the top byte of the register when doing
497 * a read.
498 * @reg_format_endian_default: Default endianness for formatted register
499 * addresses. Used when the regmap_config specifies DEFAULT. If this is
500 * DEFAULT, BIG is assumed.
501 * @val_format_endian_default: Default endianness for formatted register
502 * values. Used when the regmap_config specifies DEFAULT. If this is
503 * DEFAULT, BIG is assumed.
504 * @max_raw_read: Max raw read size that can be used on the bus.
505 * @max_raw_write: Max raw write size that can be used on the bus.
506 * @free_on_exit: kfree this on exit of regmap
507 */
508struct regmap_bus {
509 bool fast_io;
510 regmap_hw_write write;
511 regmap_hw_gather_write gather_write;
512 regmap_hw_async_write async_write;
513 regmap_hw_reg_write reg_write;
514 regmap_hw_reg_update_bits reg_update_bits;
515 regmap_hw_read read;
516 regmap_hw_reg_read reg_read;
517 regmap_hw_free_context free_context;
518 regmap_hw_async_alloc async_alloc;
519 u8 read_flag_mask;
520 enum regmap_endian reg_format_endian_default;
521 enum regmap_endian val_format_endian_default;
522 size_t max_raw_read;
523 size_t max_raw_write;
524 bool free_on_exit;
525};
526
527/*
528 * __regmap_init functions.
529 *
530 * These functions take a lock key and name parameter, and should not be called
531 * directly. Instead, use the regmap_init macros that generate a key and name
532 * for each call.
533 */
534struct regmap *__regmap_init(struct device *dev,
535 const struct regmap_bus *bus,
536 void *bus_context,
537 const struct regmap_config *config,
538 struct lock_class_key *lock_key,
539 const char *lock_name);
540struct regmap *__regmap_init_i2c(struct i2c_client *i2c,
541 const struct regmap_config *config,
542 struct lock_class_key *lock_key,
543 const char *lock_name);
544struct regmap *__regmap_init_mdio(struct mdio_device *mdio_dev,
545 const struct regmap_config *config,
546 struct lock_class_key *lock_key,
547 const char *lock_name);
548struct regmap *__regmap_init_sccb(struct i2c_client *i2c,
549 const struct regmap_config *config,
550 struct lock_class_key *lock_key,
551 const char *lock_name);
552struct regmap *__regmap_init_slimbus(struct slim_device *slimbus,
553 const struct regmap_config *config,
554 struct lock_class_key *lock_key,
555 const char *lock_name);
556struct regmap *__regmap_init_spi(struct spi_device *dev,
557 const struct regmap_config *config,
558 struct lock_class_key *lock_key,
559 const char *lock_name);
560struct regmap *__regmap_init_spmi_base(struct spmi_device *dev,
561 const struct regmap_config *config,
562 struct lock_class_key *lock_key,
563 const char *lock_name);
564struct regmap *__regmap_init_spmi_ext(struct spmi_device *dev,
565 const struct regmap_config *config,
566 struct lock_class_key *lock_key,
567 const char *lock_name);
568struct regmap *__regmap_init_w1(struct device *w1_dev,
569 const struct regmap_config *config,
570 struct lock_class_key *lock_key,
571 const char *lock_name);
572struct regmap *__regmap_init_mmio_clk(struct device *dev, const char *clk_id,
573 void __iomem *regs,
574 const struct regmap_config *config,
575 struct lock_class_key *lock_key,
576 const char *lock_name);
577struct regmap *__regmap_init_ac97(struct snd_ac97 *ac97,
578 const struct regmap_config *config,
579 struct lock_class_key *lock_key,
580 const char *lock_name);
581struct regmap *__regmap_init_sdw(struct sdw_slave *sdw,
582 const struct regmap_config *config,
583 struct lock_class_key *lock_key,
584 const char *lock_name);
585struct regmap *__regmap_init_sdw_mbq(struct sdw_slave *sdw,
586 const struct regmap_config *config,
587 struct lock_class_key *lock_key,
588 const char *lock_name);
589struct regmap *__regmap_init_spi_avmm(struct spi_device *spi,
590 const struct regmap_config *config,
591 struct lock_class_key *lock_key,
592 const char *lock_name);
593
594struct regmap *__devm_regmap_init(struct device *dev,
595 const struct regmap_bus *bus,
596 void *bus_context,
597 const struct regmap_config *config,
598 struct lock_class_key *lock_key,
599 const char *lock_name);
600struct regmap *__devm_regmap_init_i2c(struct i2c_client *i2c,
601 const struct regmap_config *config,
602 struct lock_class_key *lock_key,
603 const char *lock_name);
604struct regmap *__devm_regmap_init_mdio(struct mdio_device *mdio_dev,
605 const struct regmap_config *config,
606 struct lock_class_key *lock_key,
607 const char *lock_name);
608struct regmap *__devm_regmap_init_sccb(struct i2c_client *i2c,
609 const struct regmap_config *config,
610 struct lock_class_key *lock_key,
611 const char *lock_name);
612struct regmap *__devm_regmap_init_spi(struct spi_device *dev,
613 const struct regmap_config *config,
614 struct lock_class_key *lock_key,
615 const char *lock_name);
616struct regmap *__devm_regmap_init_spmi_base(struct spmi_device *dev,
617 const struct regmap_config *config,
618 struct lock_class_key *lock_key,
619 const char *lock_name);
620struct regmap *__devm_regmap_init_spmi_ext(struct spmi_device *dev,
621 const struct regmap_config *config,
622 struct lock_class_key *lock_key,
623 const char *lock_name);
624struct regmap *__devm_regmap_init_w1(struct device *w1_dev,
625 const struct regmap_config *config,
626 struct lock_class_key *lock_key,
627 const char *lock_name);
628struct regmap *__devm_regmap_init_mmio_clk(struct device *dev,
629 const char *clk_id,
630 void __iomem *regs,
631 const struct regmap_config *config,
632 struct lock_class_key *lock_key,
633 const char *lock_name);
634struct regmap *__devm_regmap_init_ac97(struct snd_ac97 *ac97,
635 const struct regmap_config *config,
636 struct lock_class_key *lock_key,
637 const char *lock_name);
638struct regmap *__devm_regmap_init_sdw(struct sdw_slave *sdw,
639 const struct regmap_config *config,
640 struct lock_class_key *lock_key,
641 const char *lock_name);
642struct regmap *__devm_regmap_init_sdw_mbq(struct sdw_slave *sdw,
643 const struct regmap_config *config,
644 struct lock_class_key *lock_key,
645 const char *lock_name);
646struct regmap *__devm_regmap_init_slimbus(struct slim_device *slimbus,
647 const struct regmap_config *config,
648 struct lock_class_key *lock_key,
649 const char *lock_name);
650struct regmap *__devm_regmap_init_i3c(struct i3c_device *i3c,
651 const struct regmap_config *config,
652 struct lock_class_key *lock_key,
653 const char *lock_name);
654struct regmap *__devm_regmap_init_spi_avmm(struct spi_device *spi,
655 const struct regmap_config *config,
656 struct lock_class_key *lock_key,
657 const char *lock_name);
658/*
659 * Wrapper for regmap_init macros to include a unique lockdep key and name
660 * for each call. No-op if CONFIG_LOCKDEP is not set.
661 *
662 * @fn: Real function to call (in the form __[*_]regmap_init[_*])
663 * @name: Config variable name (#config in the calling macro)
664 **/
665#ifdef CONFIG_LOCKDEP
666#define __regmap_lockdep_wrapper(fn, name, ...) \
667( \
668 ({ \
669 static struct lock_class_key _key; \
670 fn(__VA_ARGS__, &_key, \
671 KBUILD_BASENAME ":" \
672 __stringify(__LINE__) ":" \
673 "(" name ")->lock"); \
674 }) \
675)
676#else
677#define __regmap_lockdep_wrapper(fn, name, ...) fn(__VA_ARGS__, NULL, NULL)
678#endif
679
680/**
681 * regmap_init() - Initialise register map
682 *
683 * @dev: Device that will be interacted with
684 * @bus: Bus-specific callbacks to use with device
685 * @bus_context: Data passed to bus-specific callbacks
686 * @config: Configuration for register map
687 *
688 * The return value will be an ERR_PTR() on error or a valid pointer to
689 * a struct regmap. This function should generally not be called
690 * directly, it should be called by bus-specific init functions.
691 */
692#define regmap_init(dev, bus, bus_context, config) \
693 __regmap_lockdep_wrapper(__regmap_init, #config, \
694 dev, bus, bus_context, config)
695int regmap_attach_dev(struct device *dev, struct regmap *map,
696 const struct regmap_config *config);
697
698/**
699 * regmap_init_i2c() - Initialise register map
700 *
701 * @i2c: Device that will be interacted with
702 * @config: Configuration for register map
703 *
704 * The return value will be an ERR_PTR() on error or a valid pointer to
705 * a struct regmap.
706 */
707#define regmap_init_i2c(i2c, config) \
708 __regmap_lockdep_wrapper(__regmap_init_i2c, #config, \
709 i2c, config)
710
711/**
712 * regmap_init_mdio() - Initialise register map
713 *
714 * @mdio_dev: Device that will be interacted with
715 * @config: Configuration for register map
716 *
717 * The return value will be an ERR_PTR() on error or a valid pointer to
718 * a struct regmap.
719 */
720#define regmap_init_mdio(mdio_dev, config) \
721 __regmap_lockdep_wrapper(__regmap_init_mdio, #config, \
722 mdio_dev, config)
723
724/**
725 * regmap_init_sccb() - Initialise register map
726 *
727 * @i2c: Device that will be interacted with
728 * @config: Configuration for register map
729 *
730 * The return value will be an ERR_PTR() on error or a valid pointer to
731 * a struct regmap.
732 */
733#define regmap_init_sccb(i2c, config) \
734 __regmap_lockdep_wrapper(__regmap_init_sccb, #config, \
735 i2c, config)
736
737/**
738 * regmap_init_slimbus() - Initialise register map
739 *
740 * @slimbus: Device that will be interacted with
741 * @config: Configuration for register map
742 *
743 * The return value will be an ERR_PTR() on error or a valid pointer to
744 * a struct regmap.
745 */
746#define regmap_init_slimbus(slimbus, config) \
747 __regmap_lockdep_wrapper(__regmap_init_slimbus, #config, \
748 slimbus, config)
749
750/**
751 * regmap_init_spi() - Initialise register map
752 *
753 * @dev: Device that will be interacted with
754 * @config: Configuration for register map
755 *
756 * The return value will be an ERR_PTR() on error or a valid pointer to
757 * a struct regmap.
758 */
759#define regmap_init_spi(dev, config) \
760 __regmap_lockdep_wrapper(__regmap_init_spi, #config, \
761 dev, config)
762
763/**
764 * regmap_init_spmi_base() - Create regmap for the Base register space
765 *
766 * @dev: SPMI device that will be interacted with
767 * @config: Configuration for register map
768 *
769 * The return value will be an ERR_PTR() on error or a valid pointer to
770 * a struct regmap.
771 */
772#define regmap_init_spmi_base(dev, config) \
773 __regmap_lockdep_wrapper(__regmap_init_spmi_base, #config, \
774 dev, config)
775
776/**
777 * regmap_init_spmi_ext() - Create regmap for Ext register space
778 *
779 * @dev: Device that will be interacted with
780 * @config: Configuration for register map
781 *
782 * The return value will be an ERR_PTR() on error or a valid pointer to
783 * a struct regmap.
784 */
785#define regmap_init_spmi_ext(dev, config) \
786 __regmap_lockdep_wrapper(__regmap_init_spmi_ext, #config, \
787 dev, config)
788
789/**
790 * regmap_init_w1() - Initialise register map
791 *
792 * @w1_dev: Device that will be interacted with
793 * @config: Configuration for register map
794 *
795 * The return value will be an ERR_PTR() on error or a valid pointer to
796 * a struct regmap.
797 */
798#define regmap_init_w1(w1_dev, config) \
799 __regmap_lockdep_wrapper(__regmap_init_w1, #config, \
800 w1_dev, config)
801
802/**
803 * regmap_init_mmio_clk() - Initialise register map with register clock
804 *
805 * @dev: Device that will be interacted with
806 * @clk_id: register clock consumer ID
807 * @regs: Pointer to memory-mapped IO region
808 * @config: Configuration for register map
809 *
810 * The return value will be an ERR_PTR() on error or a valid pointer to
811 * a struct regmap.
812 */
813#define regmap_init_mmio_clk(dev, clk_id, regs, config) \
814 __regmap_lockdep_wrapper(__regmap_init_mmio_clk, #config, \
815 dev, clk_id, regs, config)
816
817/**
818 * regmap_init_mmio() - Initialise register map
819 *
820 * @dev: Device that will be interacted with
821 * @regs: Pointer to memory-mapped IO region
822 * @config: Configuration for register map
823 *
824 * The return value will be an ERR_PTR() on error or a valid pointer to
825 * a struct regmap.
826 */
827#define regmap_init_mmio(dev, regs, config) \
828 regmap_init_mmio_clk(dev, NULL, regs, config)
829
830/**
831 * regmap_init_ac97() - Initialise AC'97 register map
832 *
833 * @ac97: Device that will be interacted with
834 * @config: Configuration for register map
835 *
836 * The return value will be an ERR_PTR() on error or a valid pointer to
837 * a struct regmap.
838 */
839#define regmap_init_ac97(ac97, config) \
840 __regmap_lockdep_wrapper(__regmap_init_ac97, #config, \
841 ac97, config)
842bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg);
843
844/**
845 * regmap_init_sdw() - Initialise register map
846 *
847 * @sdw: Device that will be interacted with
848 * @config: Configuration for register map
849 *
850 * The return value will be an ERR_PTR() on error or a valid pointer to
851 * a struct regmap.
852 */
853#define regmap_init_sdw(sdw, config) \
854 __regmap_lockdep_wrapper(__regmap_init_sdw, #config, \
855 sdw, config)
856
857/**
858 * regmap_init_sdw_mbq() - Initialise register map
859 *
860 * @sdw: Device that will be interacted with
861 * @config: Configuration for register map
862 *
863 * The return value will be an ERR_PTR() on error or a valid pointer to
864 * a struct regmap.
865 */
866#define regmap_init_sdw_mbq(sdw, config) \
867 __regmap_lockdep_wrapper(__regmap_init_sdw_mbq, #config, \
868 sdw, config)
869
870/**
871 * regmap_init_spi_avmm() - Initialize register map for Intel SPI Slave
872 * to AVMM Bus Bridge
873 *
874 * @spi: Device that will be interacted with
875 * @config: Configuration for register map
876 *
877 * The return value will be an ERR_PTR() on error or a valid pointer
878 * to a struct regmap.
879 */
880#define regmap_init_spi_avmm(spi, config) \
881 __regmap_lockdep_wrapper(__regmap_init_spi_avmm, #config, \
882 spi, config)
883
884/**
885 * devm_regmap_init() - Initialise managed register map
886 *
887 * @dev: Device that will be interacted with
888 * @bus: Bus-specific callbacks to use with device
889 * @bus_context: Data passed to bus-specific callbacks
890 * @config: Configuration for register map
891 *
892 * The return value will be an ERR_PTR() on error or a valid pointer
893 * to a struct regmap. This function should generally not be called
894 * directly, it should be called by bus-specific init functions. The
895 * map will be automatically freed by the device management code.
896 */
897#define devm_regmap_init(dev, bus, bus_context, config) \
898 __regmap_lockdep_wrapper(__devm_regmap_init, #config, \
899 dev, bus, bus_context, config)
900
901/**
902 * devm_regmap_init_i2c() - Initialise managed register map
903 *
904 * @i2c: Device that will be interacted with
905 * @config: Configuration for register map
906 *
907 * The return value will be an ERR_PTR() on error or a valid pointer
908 * to a struct regmap. The regmap will be automatically freed by the
909 * device management code.
910 */
911#define devm_regmap_init_i2c(i2c, config) \
912 __regmap_lockdep_wrapper(__devm_regmap_init_i2c, #config, \
913 i2c, config)
914
915/**
916 * devm_regmap_init_mdio() - Initialise managed register map
917 *
918 * @mdio_dev: Device that will be interacted with
919 * @config: Configuration for register map
920 *
921 * The return value will be an ERR_PTR() on error or a valid pointer
922 * to a struct regmap. The regmap will be automatically freed by the
923 * device management code.
924 */
925#define devm_regmap_init_mdio(mdio_dev, config) \
926 __regmap_lockdep_wrapper(__devm_regmap_init_mdio, #config, \
927 mdio_dev, config)
928
929/**
930 * devm_regmap_init_sccb() - Initialise managed register map
931 *
932 * @i2c: Device that will be interacted with
933 * @config: Configuration for register map
934 *
935 * The return value will be an ERR_PTR() on error or a valid pointer
936 * to a struct regmap. The regmap will be automatically freed by the
937 * device management code.
938 */
939#define devm_regmap_init_sccb(i2c, config) \
940 __regmap_lockdep_wrapper(__devm_regmap_init_sccb, #config, \
941 i2c, config)
942
943/**
944 * devm_regmap_init_spi() - Initialise register map
945 *
946 * @dev: Device that will be interacted with
947 * @config: Configuration for register map
948 *
949 * The return value will be an ERR_PTR() on error or a valid pointer
950 * to a struct regmap. The map will be automatically freed by the
951 * device management code.
952 */
953#define devm_regmap_init_spi(dev, config) \
954 __regmap_lockdep_wrapper(__devm_regmap_init_spi, #config, \
955 dev, config)
956
957/**
958 * devm_regmap_init_spmi_base() - Create managed regmap for Base register space
959 *
960 * @dev: SPMI device that will be interacted with
961 * @config: Configuration for register map
962 *
963 * The return value will be an ERR_PTR() on error or a valid pointer
964 * to a struct regmap. The regmap will be automatically freed by the
965 * device management code.
966 */
967#define devm_regmap_init_spmi_base(dev, config) \
968 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_base, #config, \
969 dev, config)
970
971/**
972 * devm_regmap_init_spmi_ext() - Create managed regmap for Ext register space
973 *
974 * @dev: SPMI device that will be interacted with
975 * @config: Configuration for register map
976 *
977 * The return value will be an ERR_PTR() on error or a valid pointer
978 * to a struct regmap. The regmap will be automatically freed by the
979 * device management code.
980 */
981#define devm_regmap_init_spmi_ext(dev, config) \
982 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_ext, #config, \
983 dev, config)
984
985/**
986 * devm_regmap_init_w1() - Initialise managed register map
987 *
988 * @w1_dev: Device that will be interacted with
989 * @config: Configuration for register map
990 *
991 * The return value will be an ERR_PTR() on error or a valid pointer
992 * to a struct regmap. The regmap will be automatically freed by the
993 * device management code.
994 */
995#define devm_regmap_init_w1(w1_dev, config) \
996 __regmap_lockdep_wrapper(__devm_regmap_init_w1, #config, \
997 w1_dev, config)
998/**
999 * devm_regmap_init_mmio_clk() - Initialise managed register map with clock
1000 *
1001 * @dev: Device that will be interacted with
1002 * @clk_id: register clock consumer ID
1003 * @regs: Pointer to memory-mapped IO region
1004 * @config: Configuration for register map
1005 *
1006 * The return value will be an ERR_PTR() on error or a valid pointer
1007 * to a struct regmap. The regmap will be automatically freed by the
1008 * device management code.
1009 */
1010#define devm_regmap_init_mmio_clk(dev, clk_id, regs, config) \
1011 __regmap_lockdep_wrapper(__devm_regmap_init_mmio_clk, #config, \
1012 dev, clk_id, regs, config)
1013
1014/**
1015 * devm_regmap_init_mmio() - Initialise managed register map
1016 *
1017 * @dev: Device that will be interacted with
1018 * @regs: Pointer to memory-mapped IO region
1019 * @config: Configuration for register map
1020 *
1021 * The return value will be an ERR_PTR() on error or a valid pointer
1022 * to a struct regmap. The regmap will be automatically freed by the
1023 * device management code.
1024 */
1025#define devm_regmap_init_mmio(dev, regs, config) \
1026 devm_regmap_init_mmio_clk(dev, NULL, regs, config)
1027
1028/**
1029 * devm_regmap_init_ac97() - Initialise AC'97 register map
1030 *
1031 * @ac97: Device that will be interacted with
1032 * @config: Configuration for register map
1033 *
1034 * The return value will be an ERR_PTR() on error or a valid pointer
1035 * to a struct regmap. The regmap will be automatically freed by the
1036 * device management code.
1037 */
1038#define devm_regmap_init_ac97(ac97, config) \
1039 __regmap_lockdep_wrapper(__devm_regmap_init_ac97, #config, \
1040 ac97, config)
1041
1042/**
1043 * devm_regmap_init_sdw() - Initialise managed register map
1044 *
1045 * @sdw: Device that will be interacted with
1046 * @config: Configuration for register map
1047 *
1048 * The return value will be an ERR_PTR() on error or a valid pointer
1049 * to a struct regmap. The regmap will be automatically freed by the
1050 * device management code.
1051 */
1052#define devm_regmap_init_sdw(sdw, config) \
1053 __regmap_lockdep_wrapper(__devm_regmap_init_sdw, #config, \
1054 sdw, config)
1055
1056/**
1057 * devm_regmap_init_sdw_mbq() - Initialise managed register map
1058 *
1059 * @sdw: Device that will be interacted with
1060 * @config: Configuration for register map
1061 *
1062 * The return value will be an ERR_PTR() on error or a valid pointer
1063 * to a struct regmap. The regmap will be automatically freed by the
1064 * device management code.
1065 */
1066#define devm_regmap_init_sdw_mbq(sdw, config) \
1067 __regmap_lockdep_wrapper(__devm_regmap_init_sdw_mbq, #config, \
1068 sdw, config)
1069
1070/**
1071 * devm_regmap_init_slimbus() - Initialise managed register map
1072 *
1073 * @slimbus: Device that will be interacted with
1074 * @config: Configuration for register map
1075 *
1076 * The return value will be an ERR_PTR() on error or a valid pointer
1077 * to a struct regmap. The regmap will be automatically freed by the
1078 * device management code.
1079 */
1080#define devm_regmap_init_slimbus(slimbus, config) \
1081 __regmap_lockdep_wrapper(__devm_regmap_init_slimbus, #config, \
1082 slimbus, config)
1083
1084/**
1085 * devm_regmap_init_i3c() - Initialise managed register map
1086 *
1087 * @i3c: Device that will be interacted with
1088 * @config: Configuration for register map
1089 *
1090 * The return value will be an ERR_PTR() on error or a valid pointer
1091 * to a struct regmap. The regmap will be automatically freed by the
1092 * device management code.
1093 */
1094#define devm_regmap_init_i3c(i3c, config) \
1095 __regmap_lockdep_wrapper(__devm_regmap_init_i3c, #config, \
1096 i3c, config)
1097
1098/**
1099 * devm_regmap_init_spi_avmm() - Initialize register map for Intel SPI Slave
1100 * to AVMM Bus Bridge
1101 *
1102 * @spi: Device that will be interacted with
1103 * @config: Configuration for register map
1104 *
1105 * The return value will be an ERR_PTR() on error or a valid pointer
1106 * to a struct regmap. The map will be automatically freed by the
1107 * device management code.
1108 */
1109#define devm_regmap_init_spi_avmm(spi, config) \
1110 __regmap_lockdep_wrapper(__devm_regmap_init_spi_avmm, #config, \
1111 spi, config)
1112
1113int regmap_mmio_attach_clk(struct regmap *map, struct clk *clk);
1114void regmap_mmio_detach_clk(struct regmap *map);
1115void regmap_exit(struct regmap *map);
1116int regmap_reinit_cache(struct regmap *map,
1117 const struct regmap_config *config);
1118struct regmap *dev_get_regmap(struct device *dev, const char *name);
1119struct device *regmap_get_device(struct regmap *map);
1120int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
1121int regmap_write_async(struct regmap *map, unsigned int reg, unsigned int val);
1122int regmap_raw_write(struct regmap *map, unsigned int reg,
1123 const void *val, size_t val_len);
1124int regmap_noinc_write(struct regmap *map, unsigned int reg,
1125 const void *val, size_t val_len);
1126int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
1127 size_t val_count);
1128int regmap_multi_reg_write(struct regmap *map, const struct reg_sequence *regs,
1129 int num_regs);
1130int regmap_multi_reg_write_bypassed(struct regmap *map,
1131 const struct reg_sequence *regs,
1132 int num_regs);
1133int regmap_raw_write_async(struct regmap *map, unsigned int reg,
1134 const void *val, size_t val_len);
1135int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
1136int regmap_raw_read(struct regmap *map, unsigned int reg,
1137 void *val, size_t val_len);
1138int regmap_noinc_read(struct regmap *map, unsigned int reg,
1139 void *val, size_t val_len);
1140int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
1141 size_t val_count);
1142int regmap_update_bits_base(struct regmap *map, unsigned int reg,
1143 unsigned int mask, unsigned int val,
1144 bool *change, bool async, bool force);
1145
1146static inline int regmap_update_bits(struct regmap *map, unsigned int reg,
1147 unsigned int mask, unsigned int val)
1148{
1149 return regmap_update_bits_base(map, reg, mask, val, NULL, false, false);
1150}
1151
1152static inline int regmap_update_bits_async(struct regmap *map, unsigned int reg,
1153 unsigned int mask, unsigned int val)
1154{
1155 return regmap_update_bits_base(map, reg, mask, val, NULL, true, false);
1156}
1157
1158static inline int regmap_update_bits_check(struct regmap *map, unsigned int reg,
1159 unsigned int mask, unsigned int val,
1160 bool *change)
1161{
1162 return regmap_update_bits_base(map, reg, mask, val,
1163 change, false, false);
1164}
1165
1166static inline int
1167regmap_update_bits_check_async(struct regmap *map, unsigned int reg,
1168 unsigned int mask, unsigned int val,
1169 bool *change)
1170{
1171 return regmap_update_bits_base(map, reg, mask, val,
1172 change, true, false);
1173}
1174
1175static inline int regmap_write_bits(struct regmap *map, unsigned int reg,
1176 unsigned int mask, unsigned int val)
1177{
1178 return regmap_update_bits_base(map, reg, mask, val, NULL, false, true);
1179}
1180
1181int regmap_get_val_bytes(struct regmap *map);
1182int regmap_get_max_register(struct regmap *map);
1183int regmap_get_reg_stride(struct regmap *map);
1184int regmap_async_complete(struct regmap *map);
1185bool regmap_can_raw_write(struct regmap *map);
1186size_t regmap_get_raw_read_max(struct regmap *map);
1187size_t regmap_get_raw_write_max(struct regmap *map);
1188
1189int regcache_sync(struct regmap *map);
1190int regcache_sync_region(struct regmap *map, unsigned int min,
1191 unsigned int max);
1192int regcache_drop_region(struct regmap *map, unsigned int min,
1193 unsigned int max);
1194void regcache_cache_only(struct regmap *map, bool enable);
1195void regcache_cache_bypass(struct regmap *map, bool enable);
1196void regcache_mark_dirty(struct regmap *map);
1197
1198bool regmap_check_range_table(struct regmap *map, unsigned int reg,
1199 const struct regmap_access_table *table);
1200
1201int regmap_register_patch(struct regmap *map, const struct reg_sequence *regs,
1202 int num_regs);
1203int regmap_parse_val(struct regmap *map, const void *buf,
1204 unsigned int *val);
1205
1206static inline bool regmap_reg_in_range(unsigned int reg,
1207 const struct regmap_range *range)
1208{
1209 return reg >= range->range_min && reg <= range->range_max;
1210}
1211
1212bool regmap_reg_in_ranges(unsigned int reg,
1213 const struct regmap_range *ranges,
1214 unsigned int nranges);
1215
1216static inline int regmap_set_bits(struct regmap *map,
1217 unsigned int reg, unsigned int bits)
1218{
1219 return regmap_update_bits_base(map, reg, bits, bits,
1220 NULL, false, false);
1221}
1222
1223static inline int regmap_clear_bits(struct regmap *map,
1224 unsigned int reg, unsigned int bits)
1225{
1226 return regmap_update_bits_base(map, reg, bits, 0, NULL, false, false);
1227}
1228
1229int regmap_test_bits(struct regmap *map, unsigned int reg, unsigned int bits);
1230
1231/**
1232 * struct reg_field - Description of an register field
1233 *
1234 * @reg: Offset of the register within the regmap bank
1235 * @lsb: lsb of the register field.
1236 * @msb: msb of the register field.
1237 * @id_size: port size if it has some ports
1238 * @id_offset: address offset for each ports
1239 */
1240struct reg_field {
1241 unsigned int reg;
1242 unsigned int lsb;
1243 unsigned int msb;
1244 unsigned int id_size;
1245 unsigned int id_offset;
1246};
1247
1248#define REG_FIELD(_reg, _lsb, _msb) { \
1249 .reg = _reg, \
1250 .lsb = _lsb, \
1251 .msb = _msb, \
1252 }
1253
1254#define REG_FIELD_ID(_reg, _lsb, _msb, _size, _offset) { \
1255 .reg = _reg, \
1256 .lsb = _lsb, \
1257 .msb = _msb, \
1258 .id_size = _size, \
1259 .id_offset = _offset, \
1260 }
1261
1262struct regmap_field *regmap_field_alloc(struct regmap *regmap,
1263 struct reg_field reg_field);
1264void regmap_field_free(struct regmap_field *field);
1265
1266struct regmap_field *devm_regmap_field_alloc(struct device *dev,
1267 struct regmap *regmap, struct reg_field reg_field);
1268void devm_regmap_field_free(struct device *dev, struct regmap_field *field);
1269
1270int regmap_field_bulk_alloc(struct regmap *regmap,
1271 struct regmap_field **rm_field,
1272 struct reg_field *reg_field,
1273 int num_fields);
1274void regmap_field_bulk_free(struct regmap_field *field);
1275int devm_regmap_field_bulk_alloc(struct device *dev, struct regmap *regmap,
1276 struct regmap_field **field,
1277 struct reg_field *reg_field, int num_fields);
1278void devm_regmap_field_bulk_free(struct device *dev,
1279 struct regmap_field *field);
1280
1281int regmap_field_read(struct regmap_field *field, unsigned int *val);
1282int regmap_field_update_bits_base(struct regmap_field *field,
1283 unsigned int mask, unsigned int val,
1284 bool *change, bool async, bool force);
1285int regmap_fields_read(struct regmap_field *field, unsigned int id,
1286 unsigned int *val);
1287int regmap_fields_update_bits_base(struct regmap_field *field, unsigned int id,
1288 unsigned int mask, unsigned int val,
1289 bool *change, bool async, bool force);
1290
1291static inline int regmap_field_write(struct regmap_field *field,
1292 unsigned int val)
1293{
1294 return regmap_field_update_bits_base(field, ~0, val,
1295 NULL, false, false);
1296}
1297
1298static inline int regmap_field_force_write(struct regmap_field *field,
1299 unsigned int val)
1300{
1301 return regmap_field_update_bits_base(field, ~0, val, NULL, false, true);
1302}
1303
1304static inline int regmap_field_update_bits(struct regmap_field *field,
1305 unsigned int mask, unsigned int val)
1306{
1307 return regmap_field_update_bits_base(field, mask, val,
1308 NULL, false, false);
1309}
1310
1311static inline int
1312regmap_field_force_update_bits(struct regmap_field *field,
1313 unsigned int mask, unsigned int val)
1314{
1315 return regmap_field_update_bits_base(field, mask, val,
1316 NULL, false, true);
1317}
1318
1319static inline int regmap_fields_write(struct regmap_field *field,
1320 unsigned int id, unsigned int val)
1321{
1322 return regmap_fields_update_bits_base(field, id, ~0, val,
1323 NULL, false, false);
1324}
1325
1326static inline int regmap_fields_force_write(struct regmap_field *field,
1327 unsigned int id, unsigned int val)
1328{
1329 return regmap_fields_update_bits_base(field, id, ~0, val,
1330 NULL, false, true);
1331}
1332
1333static inline int
1334regmap_fields_update_bits(struct regmap_field *field, unsigned int id,
1335 unsigned int mask, unsigned int val)
1336{
1337 return regmap_fields_update_bits_base(field, id, mask, val,
1338 NULL, false, false);
1339}
1340
1341static inline int
1342regmap_fields_force_update_bits(struct regmap_field *field, unsigned int id,
1343 unsigned int mask, unsigned int val)
1344{
1345 return regmap_fields_update_bits_base(field, id, mask, val,
1346 NULL, false, true);
1347}
1348
1349/**
1350 * struct regmap_irq_type - IRQ type definitions.
1351 *
1352 * @type_reg_offset: Offset register for the irq type setting.
1353 * @type_rising_val: Register value to configure RISING type irq.
1354 * @type_falling_val: Register value to configure FALLING type irq.
1355 * @type_level_low_val: Register value to configure LEVEL_LOW type irq.
1356 * @type_level_high_val: Register value to configure LEVEL_HIGH type irq.
1357 * @types_supported: logical OR of IRQ_TYPE_* flags indicating supported types.
1358 */
1359struct regmap_irq_type {
1360 unsigned int type_reg_offset;
1361 unsigned int type_reg_mask;
1362 unsigned int type_rising_val;
1363 unsigned int type_falling_val;
1364 unsigned int type_level_low_val;
1365 unsigned int type_level_high_val;
1366 unsigned int types_supported;
1367};
1368
1369/**
1370 * struct regmap_irq - Description of an IRQ for the generic regmap irq_chip.
1371 *
1372 * @reg_offset: Offset of the status/mask register within the bank
1373 * @mask: Mask used to flag/control the register.
1374 * @type: IRQ trigger type setting details if supported.
1375 */
1376struct regmap_irq {
1377 unsigned int reg_offset;
1378 unsigned int mask;
1379 struct regmap_irq_type type;
1380};
1381
1382#define REGMAP_IRQ_REG(_irq, _off, _mask) \
1383 [_irq] = { .reg_offset = (_off), .mask = (_mask) }
1384
1385#define REGMAP_IRQ_REG_LINE(_id, _reg_bits) \
1386 [_id] = { \
1387 .mask = BIT((_id) % (_reg_bits)), \
1388 .reg_offset = (_id) / (_reg_bits), \
1389 }
1390
1391#define REGMAP_IRQ_MAIN_REG_OFFSET(arr) \
1392 { .num_regs = ARRAY_SIZE((arr)), .offset = &(arr)[0] }
1393
1394struct regmap_irq_sub_irq_map {
1395 unsigned int num_regs;
1396 unsigned int *offset;
1397};
1398
1399/**
1400 * struct regmap_irq_chip - Description of a generic regmap irq_chip.
1401 *
1402 * @name: Descriptive name for IRQ controller.
1403 *
1404 * @main_status: Base main status register address. For chips which have
1405 * interrupts arranged in separate sub-irq blocks with own IRQ
1406 * registers and which have a main IRQ registers indicating
1407 * sub-irq blocks with unhandled interrupts. For such chips fill
1408 * sub-irq register information in status_base, mask_base and
1409 * ack_base.
1410 * @num_main_status_bits: Should be given to chips where number of meaningfull
1411 * main status bits differs from num_regs.
1412 * @sub_reg_offsets: arrays of mappings from main register bits to sub irq
1413 * registers. First item in array describes the registers
1414 * for first main status bit. Second array for second bit etc.
1415 * Offset is given as sub register status offset to
1416 * status_base. Should contain num_regs arrays.
1417 * Can be provided for chips with more complex mapping than
1418 * 1.st bit to 1.st sub-reg, 2.nd bit to 2.nd sub-reg, ...
1419 * When used with not_fixed_stride, each one-element array
1420 * member contains offset calculated as address from each
1421 * peripheral to first peripheral.
1422 * @num_main_regs: Number of 'main status' irq registers for chips which have
1423 * main_status set.
1424 *
1425 * @status_base: Base status register address.
1426 * @mask_base: Base mask register address.
1427 * @mask_writeonly: Base mask register is write only.
1428 * @unmask_base: Base unmask register address. for chips who have
1429 * separate mask and unmask registers
1430 * @ack_base: Base ack address. If zero then the chip is clear on read.
1431 * Using zero value is possible with @use_ack bit.
1432 * @wake_base: Base address for wake enables. If zero unsupported.
1433 * @type_base: Base address for irq type. If zero unsupported.
1434 * @virt_reg_base: Base addresses for extra config regs.
1435 * @irq_reg_stride: Stride to use for chips where registers are not contiguous.
1436 * @init_ack_masked: Ack all masked interrupts once during initalization.
1437 * @mask_invert: Inverted mask register: cleared bits are masked out.
1438 * @use_ack: Use @ack register even if it is zero.
1439 * @ack_invert: Inverted ack register: cleared bits for ack.
1440 * @clear_ack: Use this to set 1 and 0 or vice-versa to clear interrupts.
1441 * @wake_invert: Inverted wake register: cleared bits are wake enabled.
1442 * @type_invert: Invert the type flags.
1443 * @type_in_mask: Use the mask registers for controlling irq type. For
1444 * interrupts defining type_rising/falling_mask use mask_base
1445 * for edge configuration and never update bits in type_base.
1446 * @clear_on_unmask: For chips with interrupts cleared on read: read the status
1447 * registers before unmasking interrupts to clear any bits
1448 * set when they were masked.
1449 * @not_fixed_stride: Used when chip peripherals are not laid out with fixed
1450 * stride. Must be used with sub_reg_offsets containing the
1451 * offsets to each peripheral.
1452 * @status_invert: Inverted status register: cleared bits are active interrupts.
1453 * @runtime_pm: Hold a runtime PM lock on the device when accessing it.
1454 *
1455 * @num_regs: Number of registers in each control bank.
1456 * @irqs: Descriptors for individual IRQs. Interrupt numbers are
1457 * assigned based on the index in the array of the interrupt.
1458 * @num_irqs: Number of descriptors.
1459 * @num_type_reg: Number of type registers.
1460 * @num_virt_regs: Number of non-standard irq configuration registers.
1461 * If zero unsupported.
1462 * @type_reg_stride: Stride to use for chips where type registers are not
1463 * contiguous.
1464 * @handle_pre_irq: Driver specific callback to handle interrupt from device
1465 * before regmap_irq_handler process the interrupts.
1466 * @handle_post_irq: Driver specific callback to handle interrupt from device
1467 * after handling the interrupts in regmap_irq_handler().
1468 * @set_type_virt: Driver specific callback to extend regmap_irq_set_type()
1469 * and configure virt regs.
1470 * @irq_drv_data: Driver specific IRQ data which is passed as parameter when
1471 * driver specific pre/post interrupt handler is called.
1472 *
1473 * This is not intended to handle every possible interrupt controller, but
1474 * it should handle a substantial proportion of those that are found in the
1475 * wild.
1476 */
1477struct regmap_irq_chip {
1478 const char *name;
1479
1480 unsigned int main_status;
1481 unsigned int num_main_status_bits;
1482 struct regmap_irq_sub_irq_map *sub_reg_offsets;
1483 int num_main_regs;
1484
1485 unsigned int status_base;
1486 unsigned int mask_base;
1487 unsigned int unmask_base;
1488 unsigned int ack_base;
1489 unsigned int wake_base;
1490 unsigned int type_base;
1491 unsigned int *virt_reg_base;
1492 unsigned int irq_reg_stride;
1493 bool mask_writeonly:1;
1494 bool init_ack_masked:1;
1495 bool mask_invert:1;
1496 bool use_ack:1;
1497 bool ack_invert:1;
1498 bool clear_ack:1;
1499 bool wake_invert:1;
1500 bool runtime_pm:1;
1501 bool type_invert:1;
1502 bool type_in_mask:1;
1503 bool clear_on_unmask:1;
1504 bool not_fixed_stride:1;
1505 bool status_invert:1;
1506
1507 int num_regs;
1508
1509 const struct regmap_irq *irqs;
1510 int num_irqs;
1511
1512 int num_type_reg;
1513 int num_virt_regs;
1514 unsigned int type_reg_stride;
1515
1516 int (*handle_pre_irq)(void *irq_drv_data);
1517 int (*handle_post_irq)(void *irq_drv_data);
1518 int (*set_type_virt)(unsigned int **buf, unsigned int type,
1519 unsigned long hwirq, int reg);
1520 void *irq_drv_data;
1521};
1522
1523struct regmap_irq_chip_data;
1524
1525int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
1526 int irq_base, const struct regmap_irq_chip *chip,
1527 struct regmap_irq_chip_data **data);
1528int regmap_add_irq_chip_fwnode(struct fwnode_handle *fwnode,
1529 struct regmap *map, int irq,
1530 int irq_flags, int irq_base,
1531 const struct regmap_irq_chip *chip,
1532 struct regmap_irq_chip_data **data);
1533void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data);
1534
1535int devm_regmap_add_irq_chip(struct device *dev, struct regmap *map, int irq,
1536 int irq_flags, int irq_base,
1537 const struct regmap_irq_chip *chip,
1538 struct regmap_irq_chip_data **data);
1539int devm_regmap_add_irq_chip_fwnode(struct device *dev,
1540 struct fwnode_handle *fwnode,
1541 struct regmap *map, int irq,
1542 int irq_flags, int irq_base,
1543 const struct regmap_irq_chip *chip,
1544 struct regmap_irq_chip_data **data);
1545void devm_regmap_del_irq_chip(struct device *dev, int irq,
1546 struct regmap_irq_chip_data *data);
1547
1548int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data);
1549int regmap_irq_get_virq(struct regmap_irq_chip_data *data, int irq);
1550struct irq_domain *regmap_irq_get_domain(struct regmap_irq_chip_data *data);
1551
1552#else
1553
1554/*
1555 * These stubs should only ever be called by generic code which has
1556 * regmap based facilities, if they ever get called at runtime
1557 * something is going wrong and something probably needs to select
1558 * REGMAP.
1559 */
1560
1561static inline int regmap_write(struct regmap *map, unsigned int reg,
1562 unsigned int val)
1563{
1564 WARN_ONCE(1, "regmap API is disabled");
1565 return -EINVAL;
1566}
1567
1568static inline int regmap_write_async(struct regmap *map, unsigned int reg,
1569 unsigned int val)
1570{
1571 WARN_ONCE(1, "regmap API is disabled");
1572 return -EINVAL;
1573}
1574
1575static inline int regmap_raw_write(struct regmap *map, unsigned int reg,
1576 const void *val, size_t val_len)
1577{
1578 WARN_ONCE(1, "regmap API is disabled");
1579 return -EINVAL;
1580}
1581
1582static inline int regmap_raw_write_async(struct regmap *map, unsigned int reg,
1583 const void *val, size_t val_len)
1584{
1585 WARN_ONCE(1, "regmap API is disabled");
1586 return -EINVAL;
1587}
1588
1589static inline int regmap_noinc_write(struct regmap *map, unsigned int reg,
1590 const void *val, size_t val_len)
1591{
1592 WARN_ONCE(1, "regmap API is disabled");
1593 return -EINVAL;
1594}
1595
1596static inline int regmap_bulk_write(struct regmap *map, unsigned int reg,
1597 const void *val, size_t val_count)
1598{
1599 WARN_ONCE(1, "regmap API is disabled");
1600 return -EINVAL;
1601}
1602
1603static inline int regmap_read(struct regmap *map, unsigned int reg,
1604 unsigned int *val)
1605{
1606 WARN_ONCE(1, "regmap API is disabled");
1607 return -EINVAL;
1608}
1609
1610static inline int regmap_raw_read(struct regmap *map, unsigned int reg,
1611 void *val, size_t val_len)
1612{
1613 WARN_ONCE(1, "regmap API is disabled");
1614 return -EINVAL;
1615}
1616
1617static inline int regmap_noinc_read(struct regmap *map, unsigned int reg,
1618 void *val, size_t val_len)
1619{
1620 WARN_ONCE(1, "regmap API is disabled");
1621 return -EINVAL;
1622}
1623
1624static inline int regmap_bulk_read(struct regmap *map, unsigned int reg,
1625 void *val, size_t val_count)
1626{
1627 WARN_ONCE(1, "regmap API is disabled");
1628 return -EINVAL;
1629}
1630
1631static inline int regmap_update_bits_base(struct regmap *map, unsigned int reg,
1632 unsigned int mask, unsigned int val,
1633 bool *change, bool async, bool force)
1634{
1635 WARN_ONCE(1, "regmap API is disabled");
1636 return -EINVAL;
1637}
1638
1639static inline int regmap_set_bits(struct regmap *map,
1640 unsigned int reg, unsigned int bits)
1641{
1642 WARN_ONCE(1, "regmap API is disabled");
1643 return -EINVAL;
1644}
1645
1646static inline int regmap_clear_bits(struct regmap *map,
1647 unsigned int reg, unsigned int bits)
1648{
1649 WARN_ONCE(1, "regmap API is disabled");
1650 return -EINVAL;
1651}
1652
1653static inline int regmap_test_bits(struct regmap *map,
1654 unsigned int reg, unsigned int bits)
1655{
1656 WARN_ONCE(1, "regmap API is disabled");
1657 return -EINVAL;
1658}
1659
1660static inline int regmap_field_update_bits_base(struct regmap_field *field,
1661 unsigned int mask, unsigned int val,
1662 bool *change, bool async, bool force)
1663{
1664 WARN_ONCE(1, "regmap API is disabled");
1665 return -EINVAL;
1666}
1667
1668static inline int regmap_fields_update_bits_base(struct regmap_field *field,
1669 unsigned int id,
1670 unsigned int mask, unsigned int val,
1671 bool *change, bool async, bool force)
1672{
1673 WARN_ONCE(1, "regmap API is disabled");
1674 return -EINVAL;
1675}
1676
1677static inline int regmap_update_bits(struct regmap *map, unsigned int reg,
1678 unsigned int mask, unsigned int val)
1679{
1680 WARN_ONCE(1, "regmap API is disabled");
1681 return -EINVAL;
1682}
1683
1684static inline int regmap_update_bits_async(struct regmap *map, unsigned int reg,
1685 unsigned int mask, unsigned int val)
1686{
1687 WARN_ONCE(1, "regmap API is disabled");
1688 return -EINVAL;
1689}
1690
1691static inline int regmap_update_bits_check(struct regmap *map, unsigned int reg,
1692 unsigned int mask, unsigned int val,
1693 bool *change)
1694{
1695 WARN_ONCE(1, "regmap API is disabled");
1696 return -EINVAL;
1697}
1698
1699static inline int
1700regmap_update_bits_check_async(struct regmap *map, unsigned int reg,
1701 unsigned int mask, unsigned int val,
1702 bool *change)
1703{
1704 WARN_ONCE(1, "regmap API is disabled");
1705 return -EINVAL;
1706}
1707
1708static inline int regmap_write_bits(struct regmap *map, unsigned int reg,
1709 unsigned int mask, unsigned int val)
1710{
1711 WARN_ONCE(1, "regmap API is disabled");
1712 return -EINVAL;
1713}
1714
1715static inline int regmap_field_write(struct regmap_field *field,
1716 unsigned int val)
1717{
1718 WARN_ONCE(1, "regmap API is disabled");
1719 return -EINVAL;
1720}
1721
1722static inline int regmap_field_force_write(struct regmap_field *field,
1723 unsigned int val)
1724{
1725 WARN_ONCE(1, "regmap API is disabled");
1726 return -EINVAL;
1727}
1728
1729static inline int regmap_field_update_bits(struct regmap_field *field,
1730 unsigned int mask, unsigned int val)
1731{
1732 WARN_ONCE(1, "regmap API is disabled");
1733 return -EINVAL;
1734}
1735
1736static inline int
1737regmap_field_force_update_bits(struct regmap_field *field,
1738 unsigned int mask, unsigned int val)
1739{
1740 WARN_ONCE(1, "regmap API is disabled");
1741 return -EINVAL;
1742}
1743
1744static inline int regmap_fields_write(struct regmap_field *field,
1745 unsigned int id, unsigned int val)
1746{
1747 WARN_ONCE(1, "regmap API is disabled");
1748 return -EINVAL;
1749}
1750
1751static inline int regmap_fields_force_write(struct regmap_field *field,
1752 unsigned int id, unsigned int val)
1753{
1754 WARN_ONCE(1, "regmap API is disabled");
1755 return -EINVAL;
1756}
1757
1758static inline int
1759regmap_fields_update_bits(struct regmap_field *field, unsigned int id,
1760 unsigned int mask, unsigned int val)
1761{
1762 WARN_ONCE(1, "regmap API is disabled");
1763 return -EINVAL;
1764}
1765
1766static inline int
1767regmap_fields_force_update_bits(struct regmap_field *field, unsigned int id,
1768 unsigned int mask, unsigned int val)
1769{
1770 WARN_ONCE(1, "regmap API is disabled");
1771 return -EINVAL;
1772}
1773
1774static inline int regmap_get_val_bytes(struct regmap *map)
1775{
1776 WARN_ONCE(1, "regmap API is disabled");
1777 return -EINVAL;
1778}
1779
1780static inline int regmap_get_max_register(struct regmap *map)
1781{
1782 WARN_ONCE(1, "regmap API is disabled");
1783 return -EINVAL;
1784}
1785
1786static inline int regmap_get_reg_stride(struct regmap *map)
1787{
1788 WARN_ONCE(1, "regmap API is disabled");
1789 return -EINVAL;
1790}
1791
1792static inline int regcache_sync(struct regmap *map)
1793{
1794 WARN_ONCE(1, "regmap API is disabled");
1795 return -EINVAL;
1796}
1797
1798static inline int regcache_sync_region(struct regmap *map, unsigned int min,
1799 unsigned int max)
1800{
1801 WARN_ONCE(1, "regmap API is disabled");
1802 return -EINVAL;
1803}
1804
1805static inline int regcache_drop_region(struct regmap *map, unsigned int min,
1806 unsigned int max)
1807{
1808 WARN_ONCE(1, "regmap API is disabled");
1809 return -EINVAL;
1810}
1811
1812static inline void regcache_cache_only(struct regmap *map, bool enable)
1813{
1814 WARN_ONCE(1, "regmap API is disabled");
1815}
1816
1817static inline void regcache_cache_bypass(struct regmap *map, bool enable)
1818{
1819 WARN_ONCE(1, "regmap API is disabled");
1820}
1821
1822static inline void regcache_mark_dirty(struct regmap *map)
1823{
1824 WARN_ONCE(1, "regmap API is disabled");
1825}
1826
1827static inline void regmap_async_complete(struct regmap *map)
1828{
1829 WARN_ONCE(1, "regmap API is disabled");
1830}
1831
1832static inline int regmap_register_patch(struct regmap *map,
1833 const struct reg_sequence *regs,
1834 int num_regs)
1835{
1836 WARN_ONCE(1, "regmap API is disabled");
1837 return -EINVAL;
1838}
1839
1840static inline int regmap_parse_val(struct regmap *map, const void *buf,
1841 unsigned int *val)
1842{
1843 WARN_ONCE(1, "regmap API is disabled");
1844 return -EINVAL;
1845}
1846
1847static inline struct regmap *dev_get_regmap(struct device *dev,
1848 const char *name)
1849{
1850 return NULL;
1851}
1852
1853static inline struct device *regmap_get_device(struct regmap *map)
1854{
1855 WARN_ONCE(1, "regmap API is disabled");
1856 return NULL;
1857}
1858
1859#endif
1860
1861#endif