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