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