]>
Commit | Line | Data |
---|---|---|
1 | #ifndef __LINUX_REGMAP_H | |
2 | #define __LINUX_REGMAP_H | |
3 | ||
4 | /* | |
5 | * Register map access API | |
6 | * | |
7 | * Copyright 2011 Wolfson Microelectronics plc | |
8 | * | |
9 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> | |
10 | * | |
11 | * This program is free software; you can redistribute it and/or modify | |
12 | * it under the terms of the GNU General Public License version 2 as | |
13 | * published by the Free Software Foundation. | |
14 | */ | |
15 | ||
16 | #include <linux/list.h> | |
17 | #include <linux/rbtree.h> | |
18 | #include <linux/ktime.h> | |
19 | #include <linux/delay.h> | |
20 | #include <linux/err.h> | |
21 | #include <linux/bug.h> | |
22 | #include <linux/lockdep.h> | |
23 | ||
24 | struct module; | |
25 | struct clk; | |
26 | struct device; | |
27 | struct i2c_client; | |
28 | struct irq_domain; | |
29 | struct slim_device; | |
30 | struct spi_device; | |
31 | struct spmi_device; | |
32 | struct regmap; | |
33 | struct regmap_range_cfg; | |
34 | struct regmap_field; | |
35 | struct snd_ac97; | |
36 | struct sdw_slave; | |
37 | ||
38 | /* An enum of all the supported cache types */ | |
39 | enum regcache_type { | |
40 | REGCACHE_NONE, | |
41 | REGCACHE_RBTREE, | |
42 | REGCACHE_COMPRESSED, | |
43 | REGCACHE_FLAT, | |
44 | }; | |
45 | ||
46 | /** | |
47 | * struct reg_default - Default value for a register. | |
48 | * | |
49 | * @reg: Register address. | |
50 | * @def: Register default value. | |
51 | * | |
52 | * We use an array of structs rather than a simple array as many modern devices | |
53 | * have very sparse register maps. | |
54 | */ | |
55 | struct reg_default { | |
56 | unsigned int reg; | |
57 | unsigned int def; | |
58 | }; | |
59 | ||
60 | /** | |
61 | * struct reg_sequence - An individual write from a sequence of writes. | |
62 | * | |
63 | * @reg: Register address. | |
64 | * @def: Register value. | |
65 | * @delay_us: Delay to be applied after the register write in microseconds | |
66 | * | |
67 | * Register/value pairs for sequences of writes with an optional delay in | |
68 | * microseconds to be applied after each write. | |
69 | */ | |
70 | struct reg_sequence { | |
71 | unsigned int reg; | |
72 | unsigned int def; | |
73 | unsigned int delay_us; | |
74 | }; | |
75 | ||
76 | #define regmap_update_bits(map, reg, mask, val) \ | |
77 | regmap_update_bits_base(map, reg, mask, val, NULL, false, false) | |
78 | #define regmap_update_bits_async(map, reg, mask, val)\ | |
79 | regmap_update_bits_base(map, reg, mask, val, NULL, true, false) | |
80 | #define regmap_update_bits_check(map, reg, mask, val, change)\ | |
81 | regmap_update_bits_base(map, reg, mask, val, change, false, false) | |
82 | #define regmap_update_bits_check_async(map, reg, mask, val, change)\ | |
83 | regmap_update_bits_base(map, reg, mask, val, change, true, false) | |
84 | ||
85 | #define regmap_write_bits(map, reg, mask, val) \ | |
86 | regmap_update_bits_base(map, reg, mask, val, NULL, false, true) | |
87 | ||
88 | #define regmap_field_write(field, val) \ | |
89 | regmap_field_update_bits_base(field, ~0, val, NULL, false, false) | |
90 | #define regmap_field_force_write(field, val) \ | |
91 | regmap_field_update_bits_base(field, ~0, val, NULL, false, true) | |
92 | #define regmap_field_update_bits(field, mask, val)\ | |
93 | regmap_field_update_bits_base(field, mask, val, NULL, false, false) | |
94 | #define regmap_field_force_update_bits(field, mask, val) \ | |
95 | regmap_field_update_bits_base(field, mask, val, NULL, false, true) | |
96 | ||
97 | #define regmap_fields_write(field, id, val) \ | |
98 | regmap_fields_update_bits_base(field, id, ~0, val, NULL, false, false) | |
99 | #define regmap_fields_force_write(field, id, val) \ | |
100 | regmap_fields_update_bits_base(field, id, ~0, val, NULL, false, true) | |
101 | #define regmap_fields_update_bits(field, id, mask, val)\ | |
102 | regmap_fields_update_bits_base(field, id, mask, val, NULL, false, false) | |
103 | #define regmap_fields_force_update_bits(field, id, mask, val) \ | |
104 | regmap_fields_update_bits_base(field, id, mask, val, NULL, false, true) | |
105 | ||
106 | /** | |
107 | * regmap_read_poll_timeout - Poll until a condition is met or a timeout occurs | |
108 | * | |
109 | * @map: Regmap to read from | |
110 | * @addr: Address to poll | |
111 | * @val: Unsigned integer variable to read the value into | |
112 | * @cond: Break condition (usually involving @val) | |
113 | * @sleep_us: Maximum time to sleep between reads in us (0 | |
114 | * tight-loops). Should be less than ~20ms since usleep_range | |
115 | * is used (see Documentation/timers/timers-howto.txt). | |
116 | * @timeout_us: Timeout in us, 0 means never timeout | |
117 | * | |
118 | * Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_read | |
119 | * error return value in case of a error read. In the two former cases, | |
120 | * the last read value at @addr is stored in @val. Must not be called | |
121 | * from atomic context if sleep_us or timeout_us are used. | |
122 | * | |
123 | * This is modelled after the readx_poll_timeout macros in linux/iopoll.h. | |
124 | */ | |
125 | #define regmap_read_poll_timeout(map, addr, val, cond, sleep_us, timeout_us) \ | |
126 | ({ \ | |
127 | u64 __timeout_us = (timeout_us); \ | |
128 | unsigned long __sleep_us = (sleep_us); \ | |
129 | ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \ | |
130 | int __ret; \ | |
131 | might_sleep_if(__sleep_us); \ | |
132 | for (;;) { \ | |
133 | __ret = regmap_read((map), (addr), &(val)); \ | |
134 | if (__ret) \ | |
135 | break; \ | |
136 | if (cond) \ | |
137 | break; \ | |
138 | if ((__timeout_us) && \ | |
139 | ktime_compare(ktime_get(), __timeout) > 0) { \ | |
140 | __ret = regmap_read((map), (addr), &(val)); \ | |
141 | break; \ | |
142 | } \ | |
143 | if (__sleep_us) \ | |
144 | usleep_range((__sleep_us >> 2) + 1, __sleep_us); \ | |
145 | } \ | |
146 | __ret ?: ((cond) ? 0 : -ETIMEDOUT); \ | |
147 | }) | |
148 | ||
149 | /** | |
150 | * regmap_field_read_poll_timeout - Poll until a condition is met or timeout | |
151 | * | |
152 | * @field: Regmap field to read from | |
153 | * @val: Unsigned integer variable to read the value into | |
154 | * @cond: Break condition (usually involving @val) | |
155 | * @sleep_us: Maximum time to sleep between reads in us (0 | |
156 | * tight-loops). Should be less than ~20ms since usleep_range | |
157 | * is used (see Documentation/timers/timers-howto.txt). | |
158 | * @timeout_us: Timeout in us, 0 means never timeout | |
159 | * | |
160 | * Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_field_read | |
161 | * error return value in case of a error read. In the two former cases, | |
162 | * the last read value at @addr is stored in @val. Must not be called | |
163 | * from atomic context if sleep_us or timeout_us are used. | |
164 | * | |
165 | * This is modelled after the readx_poll_timeout macros in linux/iopoll.h. | |
166 | */ | |
167 | #define regmap_field_read_poll_timeout(field, val, cond, sleep_us, timeout_us) \ | |
168 | ({ \ | |
169 | u64 __timeout_us = (timeout_us); \ | |
170 | unsigned long __sleep_us = (sleep_us); \ | |
171 | ktime_t timeout = ktime_add_us(ktime_get(), __timeout_us); \ | |
172 | int pollret; \ | |
173 | might_sleep_if(__sleep_us); \ | |
174 | for (;;) { \ | |
175 | pollret = regmap_field_read((field), &(val)); \ | |
176 | if (pollret) \ | |
177 | break; \ | |
178 | if (cond) \ | |
179 | break; \ | |
180 | if (__timeout_us && ktime_compare(ktime_get(), timeout) > 0) { \ | |
181 | pollret = regmap_field_read((field), &(val)); \ | |
182 | break; \ | |
183 | } \ | |
184 | if (__sleep_us) \ | |
185 | usleep_range((__sleep_us >> 2) + 1, __sleep_us); \ | |
186 | } \ | |
187 | pollret ?: ((cond) ? 0 : -ETIMEDOUT); \ | |
188 | }) | |
189 | ||
190 | #ifdef CONFIG_REGMAP | |
191 | ||
192 | enum regmap_endian { | |
193 | /* Unspecified -> 0 -> Backwards compatible default */ | |
194 | REGMAP_ENDIAN_DEFAULT = 0, | |
195 | REGMAP_ENDIAN_BIG, | |
196 | REGMAP_ENDIAN_LITTLE, | |
197 | REGMAP_ENDIAN_NATIVE, | |
198 | }; | |
199 | ||
200 | /** | |
201 | * struct regmap_range - A register range, used for access related checks | |
202 | * (readable/writeable/volatile/precious checks) | |
203 | * | |
204 | * @range_min: address of first register | |
205 | * @range_max: address of last register | |
206 | */ | |
207 | struct regmap_range { | |
208 | unsigned int range_min; | |
209 | unsigned int range_max; | |
210 | }; | |
211 | ||
212 | #define regmap_reg_range(low, high) { .range_min = low, .range_max = high, } | |
213 | ||
214 | /** | |
215 | * struct regmap_access_table - A table of register ranges for access checks | |
216 | * | |
217 | * @yes_ranges : pointer to an array of regmap ranges used as "yes ranges" | |
218 | * @n_yes_ranges: size of the above array | |
219 | * @no_ranges: pointer to an array of regmap ranges used as "no ranges" | |
220 | * @n_no_ranges: size of the above array | |
221 | * | |
222 | * A table of ranges including some yes ranges and some no ranges. | |
223 | * If a register belongs to a no_range, the corresponding check function | |
224 | * will return false. If a register belongs to a yes range, the corresponding | |
225 | * check function will return true. "no_ranges" are searched first. | |
226 | */ | |
227 | struct regmap_access_table { | |
228 | const struct regmap_range *yes_ranges; | |
229 | unsigned int n_yes_ranges; | |
230 | const struct regmap_range *no_ranges; | |
231 | unsigned int n_no_ranges; | |
232 | }; | |
233 | ||
234 | typedef void (*regmap_lock)(void *); | |
235 | typedef void (*regmap_unlock)(void *); | |
236 | ||
237 | /** | |
238 | * struct regmap_config - Configuration for the register map of a device. | |
239 | * | |
240 | * @name: Optional name of the regmap. Useful when a device has multiple | |
241 | * register regions. | |
242 | * | |
243 | * @reg_bits: Number of bits in a register address, mandatory. | |
244 | * @reg_stride: The register address stride. Valid register addresses are a | |
245 | * multiple of this value. If set to 0, a value of 1 will be | |
246 | * used. | |
247 | * @pad_bits: Number of bits of padding between register and value. | |
248 | * @val_bits: Number of bits in a register value, mandatory. | |
249 | * | |
250 | * @writeable_reg: Optional callback returning true if the register | |
251 | * can be written to. If this field is NULL but wr_table | |
252 | * (see below) is not, the check is performed on such table | |
253 | * (a register is writeable if it belongs to one of the ranges | |
254 | * specified by wr_table). | |
255 | * @readable_reg: Optional callback returning true if the register | |
256 | * can be read from. If this field is NULL but rd_table | |
257 | * (see below) is not, the check is performed on such table | |
258 | * (a register is readable if it belongs to one of the ranges | |
259 | * specified by rd_table). | |
260 | * @volatile_reg: Optional callback returning true if the register | |
261 | * value can't be cached. If this field is NULL but | |
262 | * volatile_table (see below) is not, the check is performed on | |
263 | * such table (a register is volatile if it belongs to one of | |
264 | * the ranges specified by volatile_table). | |
265 | * @precious_reg: Optional callback returning true if the register | |
266 | * should not be read outside of a call from the driver | |
267 | * (e.g., a clear on read interrupt status register). If this | |
268 | * field is NULL but precious_table (see below) is not, the | |
269 | * check is performed on such table (a register is precious if | |
270 | * it belongs to one of the ranges specified by precious_table). | |
271 | * @writeable_noinc_reg: Optional callback returning true if the register | |
272 | * supports multiple write operations without incrementing | |
273 | * the register number. If this field is NULL but | |
274 | * wr_noinc_table (see below) is not, the check is | |
275 | * performed on such table (a register is no increment | |
276 | * writeable if it belongs to one of the ranges specified | |
277 | * by wr_noinc_table). | |
278 | * @readable_noinc_reg: Optional callback returning true if the register | |
279 | * supports multiple read operations without incrementing | |
280 | * the register number. If this field is NULL but | |
281 | * rd_noinc_table (see below) is not, the check is | |
282 | * performed on such table (a register is no increment | |
283 | * readable if it belongs to one of the ranges specified | |
284 | * by rd_noinc_table). | |
285 | * @disable_locking: This regmap is either protected by external means or | |
286 | * is guaranteed not be be accessed from multiple threads. | |
287 | * Don't use any locking mechanisms. | |
288 | * @lock: Optional lock callback (overrides regmap's default lock | |
289 | * function, based on spinlock or mutex). | |
290 | * @unlock: As above for unlocking. | |
291 | * @lock_arg: this field is passed as the only argument of lock/unlock | |
292 | * functions (ignored in case regular lock/unlock functions | |
293 | * are not overridden). | |
294 | * @reg_read: Optional callback that if filled will be used to perform | |
295 | * all the reads from the registers. Should only be provided for | |
296 | * devices whose read operation cannot be represented as a simple | |
297 | * read operation on a bus such as SPI, I2C, etc. Most of the | |
298 | * devices do not need this. | |
299 | * @reg_write: Same as above for writing. | |
300 | * @fast_io: Register IO is fast. Use a spinlock instead of a mutex | |
301 | * to perform locking. This field is ignored if custom lock/unlock | |
302 | * functions are used (see fields lock/unlock of struct regmap_config). | |
303 | * This field is a duplicate of a similar file in | |
304 | * 'struct regmap_bus' and serves exact same purpose. | |
305 | * Use it only for "no-bus" cases. | |
306 | * @max_register: Optional, specifies the maximum valid register address. | |
307 | * @wr_table: Optional, points to a struct regmap_access_table specifying | |
308 | * valid ranges for write access. | |
309 | * @rd_table: As above, for read access. | |
310 | * @volatile_table: As above, for volatile registers. | |
311 | * @precious_table: As above, for precious registers. | |
312 | * @wr_noinc_table: As above, for no increment writeable registers. | |
313 | * @rd_noinc_table: As above, for no increment readable registers. | |
314 | * @reg_defaults: Power on reset values for registers (for use with | |
315 | * register cache support). | |
316 | * @num_reg_defaults: Number of elements in reg_defaults. | |
317 | * | |
318 | * @read_flag_mask: Mask to be set in the top bytes of the register when doing | |
319 | * a read. | |
320 | * @write_flag_mask: Mask to be set in the top bytes of the register when doing | |
321 | * a write. If both read_flag_mask and write_flag_mask are | |
322 | * empty and zero_flag_mask is not set the regmap_bus default | |
323 | * masks are used. | |
324 | * @zero_flag_mask: If set, read_flag_mask and write_flag_mask are used even | |
325 | * if they are both empty. | |
326 | * @use_single_read: If set, converts the bulk read operation into a series of | |
327 | * single read operations. This is useful for a device that | |
328 | * does not support bulk read. | |
329 | * @use_single_write: If set, converts the bulk write operation into a series of | |
330 | * single write operations. This is useful for a device that | |
331 | * does not support bulk write. | |
332 | * @can_multi_write: If set, the device supports the multi write mode of bulk | |
333 | * write operations, if clear multi write requests will be | |
334 | * split into individual write operations | |
335 | * | |
336 | * @cache_type: The actual cache type. | |
337 | * @reg_defaults_raw: Power on reset values for registers (for use with | |
338 | * register cache support). | |
339 | * @num_reg_defaults_raw: Number of elements in reg_defaults_raw. | |
340 | * @reg_format_endian: Endianness for formatted register addresses. If this is | |
341 | * DEFAULT, the @reg_format_endian_default value from the | |
342 | * regmap bus is used. | |
343 | * @val_format_endian: Endianness for formatted register values. If this is | |
344 | * DEFAULT, the @reg_format_endian_default value from the | |
345 | * regmap bus is used. | |
346 | * | |
347 | * @ranges: Array of configuration entries for virtual address ranges. | |
348 | * @num_ranges: Number of range configuration entries. | |
349 | * @use_hwlock: Indicate if a hardware spinlock should be used. | |
350 | * @hwlock_id: Specify the hardware spinlock id. | |
351 | * @hwlock_mode: The hardware spinlock mode, should be HWLOCK_IRQSTATE, | |
352 | * HWLOCK_IRQ or 0. | |
353 | */ | |
354 | struct regmap_config { | |
355 | const char *name; | |
356 | ||
357 | int reg_bits; | |
358 | int reg_stride; | |
359 | int pad_bits; | |
360 | int val_bits; | |
361 | ||
362 | bool (*writeable_reg)(struct device *dev, unsigned int reg); | |
363 | bool (*readable_reg)(struct device *dev, unsigned int reg); | |
364 | bool (*volatile_reg)(struct device *dev, unsigned int reg); | |
365 | bool (*precious_reg)(struct device *dev, unsigned int reg); | |
366 | bool (*writeable_noinc_reg)(struct device *dev, unsigned int reg); | |
367 | bool (*readable_noinc_reg)(struct device *dev, unsigned int reg); | |
368 | ||
369 | bool disable_locking; | |
370 | regmap_lock lock; | |
371 | regmap_unlock unlock; | |
372 | void *lock_arg; | |
373 | ||
374 | int (*reg_read)(void *context, unsigned int reg, unsigned int *val); | |
375 | int (*reg_write)(void *context, unsigned int reg, unsigned int val); | |
376 | ||
377 | bool fast_io; | |
378 | ||
379 | unsigned int max_register; | |
380 | const struct regmap_access_table *wr_table; | |
381 | const struct regmap_access_table *rd_table; | |
382 | const struct regmap_access_table *volatile_table; | |
383 | const struct regmap_access_table *precious_table; | |
384 | const struct regmap_access_table *wr_noinc_table; | |
385 | const struct regmap_access_table *rd_noinc_table; | |
386 | const struct reg_default *reg_defaults; | |
387 | unsigned int num_reg_defaults; | |
388 | enum regcache_type cache_type; | |
389 | const void *reg_defaults_raw; | |
390 | unsigned int num_reg_defaults_raw; | |
391 | ||
392 | unsigned long read_flag_mask; | |
393 | unsigned long write_flag_mask; | |
394 | bool zero_flag_mask; | |
395 | ||
396 | bool use_single_read; | |
397 | bool use_single_write; | |
398 | bool can_multi_write; | |
399 | ||
400 | enum regmap_endian reg_format_endian; | |
401 | enum regmap_endian val_format_endian; | |
402 | ||
403 | const struct regmap_range_cfg *ranges; | |
404 | unsigned int num_ranges; | |
405 | ||
406 | bool use_hwlock; | |
407 | unsigned int hwlock_id; | |
408 | unsigned int hwlock_mode; | |
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 shift for selector value. | |
422 | * @selector_shift: Bit mask 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 | ||
579 | struct regmap *__devm_regmap_init(struct device *dev, | |
580 | const struct regmap_bus *bus, | |
581 | void *bus_context, | |
582 | const struct regmap_config *config, | |
583 | struct lock_class_key *lock_key, | |
584 | const char *lock_name); | |
585 | struct regmap *__devm_regmap_init_i2c(struct i2c_client *i2c, | |
586 | const struct regmap_config *config, | |
587 | struct lock_class_key *lock_key, | |
588 | const char *lock_name); | |
589 | struct regmap *__devm_regmap_init_sccb(struct i2c_client *i2c, | |
590 | const struct regmap_config *config, | |
591 | struct lock_class_key *lock_key, | |
592 | const char *lock_name); | |
593 | struct regmap *__devm_regmap_init_spi(struct spi_device *dev, | |
594 | const struct regmap_config *config, | |
595 | struct lock_class_key *lock_key, | |
596 | const char *lock_name); | |
597 | struct regmap *__devm_regmap_init_spmi_base(struct spmi_device *dev, | |
598 | const struct regmap_config *config, | |
599 | struct lock_class_key *lock_key, | |
600 | const char *lock_name); | |
601 | struct regmap *__devm_regmap_init_spmi_ext(struct spmi_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_w1(struct device *w1_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_mmio_clk(struct device *dev, | |
610 | const char *clk_id, | |
611 | void __iomem *regs, | |
612 | const struct regmap_config *config, | |
613 | struct lock_class_key *lock_key, | |
614 | const char *lock_name); | |
615 | struct regmap *__devm_regmap_init_ac97(struct snd_ac97 *ac97, | |
616 | const struct regmap_config *config, | |
617 | struct lock_class_key *lock_key, | |
618 | const char *lock_name); | |
619 | struct regmap *__devm_regmap_init_sdw(struct sdw_slave *sdw, | |
620 | const struct regmap_config *config, | |
621 | struct lock_class_key *lock_key, | |
622 | const char *lock_name); | |
623 | struct regmap *__devm_regmap_init_slimbus(struct slim_device *slimbus, | |
624 | const struct regmap_config *config, | |
625 | struct lock_class_key *lock_key, | |
626 | const char *lock_name); | |
627 | /* | |
628 | * Wrapper for regmap_init macros to include a unique lockdep key and name | |
629 | * for each call. No-op if CONFIG_LOCKDEP is not set. | |
630 | * | |
631 | * @fn: Real function to call (in the form __[*_]regmap_init[_*]) | |
632 | * @name: Config variable name (#config in the calling macro) | |
633 | **/ | |
634 | #ifdef CONFIG_LOCKDEP | |
635 | #define __regmap_lockdep_wrapper(fn, name, ...) \ | |
636 | ( \ | |
637 | ({ \ | |
638 | static struct lock_class_key _key; \ | |
639 | fn(__VA_ARGS__, &_key, \ | |
640 | KBUILD_BASENAME ":" \ | |
641 | __stringify(__LINE__) ":" \ | |
642 | "(" name ")->lock"); \ | |
643 | }) \ | |
644 | ) | |
645 | #else | |
646 | #define __regmap_lockdep_wrapper(fn, name, ...) fn(__VA_ARGS__, NULL, NULL) | |
647 | #endif | |
648 | ||
649 | /** | |
650 | * regmap_init() - Initialise register map | |
651 | * | |
652 | * @dev: Device that will be interacted with | |
653 | * @bus: Bus-specific callbacks to use with device | |
654 | * @bus_context: Data passed to bus-specific callbacks | |
655 | * @config: Configuration for register map | |
656 | * | |
657 | * The return value will be an ERR_PTR() on error or a valid pointer to | |
658 | * a struct regmap. This function should generally not be called | |
659 | * directly, it should be called by bus-specific init functions. | |
660 | */ | |
661 | #define regmap_init(dev, bus, bus_context, config) \ | |
662 | __regmap_lockdep_wrapper(__regmap_init, #config, \ | |
663 | dev, bus, bus_context, config) | |
664 | int regmap_attach_dev(struct device *dev, struct regmap *map, | |
665 | const struct regmap_config *config); | |
666 | ||
667 | /** | |
668 | * regmap_init_i2c() - Initialise register map | |
669 | * | |
670 | * @i2c: Device that will be interacted with | |
671 | * @config: Configuration for register map | |
672 | * | |
673 | * The return value will be an ERR_PTR() on error or a valid pointer to | |
674 | * a struct regmap. | |
675 | */ | |
676 | #define regmap_init_i2c(i2c, config) \ | |
677 | __regmap_lockdep_wrapper(__regmap_init_i2c, #config, \ | |
678 | i2c, config) | |
679 | ||
680 | /** | |
681 | * regmap_init_sccb() - Initialise register map | |
682 | * | |
683 | * @i2c: Device that will be interacted with | |
684 | * @config: Configuration for register map | |
685 | * | |
686 | * The return value will be an ERR_PTR() on error or a valid pointer to | |
687 | * a struct regmap. | |
688 | */ | |
689 | #define regmap_init_sccb(i2c, config) \ | |
690 | __regmap_lockdep_wrapper(__regmap_init_sccb, #config, \ | |
691 | i2c, config) | |
692 | ||
693 | /** | |
694 | * regmap_init_slimbus() - Initialise register map | |
695 | * | |
696 | * @slimbus: Device that will be interacted with | |
697 | * @config: Configuration for register map | |
698 | * | |
699 | * The return value will be an ERR_PTR() on error or a valid pointer to | |
700 | * a struct regmap. | |
701 | */ | |
702 | #define regmap_init_slimbus(slimbus, config) \ | |
703 | __regmap_lockdep_wrapper(__regmap_init_slimbus, #config, \ | |
704 | slimbus, config) | |
705 | ||
706 | /** | |
707 | * regmap_init_spi() - Initialise register map | |
708 | * | |
709 | * @dev: Device that will be interacted with | |
710 | * @config: Configuration for register map | |
711 | * | |
712 | * The return value will be an ERR_PTR() on error or a valid pointer to | |
713 | * a struct regmap. | |
714 | */ | |
715 | #define regmap_init_spi(dev, config) \ | |
716 | __regmap_lockdep_wrapper(__regmap_init_spi, #config, \ | |
717 | dev, config) | |
718 | ||
719 | /** | |
720 | * regmap_init_spmi_base() - Create regmap for the Base register space | |
721 | * | |
722 | * @dev: SPMI device that will be interacted with | |
723 | * @config: Configuration for register map | |
724 | * | |
725 | * The return value will be an ERR_PTR() on error or a valid pointer to | |
726 | * a struct regmap. | |
727 | */ | |
728 | #define regmap_init_spmi_base(dev, config) \ | |
729 | __regmap_lockdep_wrapper(__regmap_init_spmi_base, #config, \ | |
730 | dev, config) | |
731 | ||
732 | /** | |
733 | * regmap_init_spmi_ext() - Create regmap for Ext register space | |
734 | * | |
735 | * @dev: Device that will be interacted with | |
736 | * @config: Configuration for register map | |
737 | * | |
738 | * The return value will be an ERR_PTR() on error or a valid pointer to | |
739 | * a struct regmap. | |
740 | */ | |
741 | #define regmap_init_spmi_ext(dev, config) \ | |
742 | __regmap_lockdep_wrapper(__regmap_init_spmi_ext, #config, \ | |
743 | dev, config) | |
744 | ||
745 | /** | |
746 | * regmap_init_w1() - Initialise register map | |
747 | * | |
748 | * @w1_dev: Device that will be interacted with | |
749 | * @config: Configuration for register map | |
750 | * | |
751 | * The return value will be an ERR_PTR() on error or a valid pointer to | |
752 | * a struct regmap. | |
753 | */ | |
754 | #define regmap_init_w1(w1_dev, config) \ | |
755 | __regmap_lockdep_wrapper(__regmap_init_w1, #config, \ | |
756 | w1_dev, config) | |
757 | ||
758 | /** | |
759 | * regmap_init_mmio_clk() - Initialise register map with register clock | |
760 | * | |
761 | * @dev: Device that will be interacted with | |
762 | * @clk_id: register clock consumer ID | |
763 | * @regs: Pointer to memory-mapped IO region | |
764 | * @config: Configuration for register map | |
765 | * | |
766 | * The return value will be an ERR_PTR() on error or a valid pointer to | |
767 | * a struct regmap. | |
768 | */ | |
769 | #define regmap_init_mmio_clk(dev, clk_id, regs, config) \ | |
770 | __regmap_lockdep_wrapper(__regmap_init_mmio_clk, #config, \ | |
771 | dev, clk_id, regs, config) | |
772 | ||
773 | /** | |
774 | * regmap_init_mmio() - Initialise register map | |
775 | * | |
776 | * @dev: Device that will be interacted with | |
777 | * @regs: Pointer to memory-mapped IO region | |
778 | * @config: Configuration for register map | |
779 | * | |
780 | * The return value will be an ERR_PTR() on error or a valid pointer to | |
781 | * a struct regmap. | |
782 | */ | |
783 | #define regmap_init_mmio(dev, regs, config) \ | |
784 | regmap_init_mmio_clk(dev, NULL, regs, config) | |
785 | ||
786 | /** | |
787 | * regmap_init_ac97() - Initialise AC'97 register map | |
788 | * | |
789 | * @ac97: Device that will be interacted with | |
790 | * @config: Configuration for register map | |
791 | * | |
792 | * The return value will be an ERR_PTR() on error or a valid pointer to | |
793 | * a struct regmap. | |
794 | */ | |
795 | #define regmap_init_ac97(ac97, config) \ | |
796 | __regmap_lockdep_wrapper(__regmap_init_ac97, #config, \ | |
797 | ac97, config) | |
798 | bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg); | |
799 | ||
800 | /** | |
801 | * regmap_init_sdw() - Initialise register map | |
802 | * | |
803 | * @sdw: Device that will be interacted with | |
804 | * @config: Configuration for register map | |
805 | * | |
806 | * The return value will be an ERR_PTR() on error or a valid pointer to | |
807 | * a struct regmap. | |
808 | */ | |
809 | #define regmap_init_sdw(sdw, config) \ | |
810 | __regmap_lockdep_wrapper(__regmap_init_sdw, #config, \ | |
811 | sdw, config) | |
812 | ||
813 | ||
814 | /** | |
815 | * devm_regmap_init() - Initialise managed register map | |
816 | * | |
817 | * @dev: Device that will be interacted with | |
818 | * @bus: Bus-specific callbacks to use with device | |
819 | * @bus_context: Data passed to bus-specific callbacks | |
820 | * @config: Configuration for register map | |
821 | * | |
822 | * The return value will be an ERR_PTR() on error or a valid pointer | |
823 | * to a struct regmap. This function should generally not be called | |
824 | * directly, it should be called by bus-specific init functions. The | |
825 | * map will be automatically freed by the device management code. | |
826 | */ | |
827 | #define devm_regmap_init(dev, bus, bus_context, config) \ | |
828 | __regmap_lockdep_wrapper(__devm_regmap_init, #config, \ | |
829 | dev, bus, bus_context, config) | |
830 | ||
831 | /** | |
832 | * devm_regmap_init_i2c() - Initialise managed register map | |
833 | * | |
834 | * @i2c: Device that will be interacted with | |
835 | * @config: Configuration for register map | |
836 | * | |
837 | * The return value will be an ERR_PTR() on error or a valid pointer | |
838 | * to a struct regmap. The regmap will be automatically freed by the | |
839 | * device management code. | |
840 | */ | |
841 | #define devm_regmap_init_i2c(i2c, config) \ | |
842 | __regmap_lockdep_wrapper(__devm_regmap_init_i2c, #config, \ | |
843 | i2c, config) | |
844 | ||
845 | /** | |
846 | * devm_regmap_init_sccb() - Initialise managed register map | |
847 | * | |
848 | * @i2c: Device that will be interacted with | |
849 | * @config: Configuration for register map | |
850 | * | |
851 | * The return value will be an ERR_PTR() on error or a valid pointer | |
852 | * to a struct regmap. The regmap will be automatically freed by the | |
853 | * device management code. | |
854 | */ | |
855 | #define devm_regmap_init_sccb(i2c, config) \ | |
856 | __regmap_lockdep_wrapper(__devm_regmap_init_sccb, #config, \ | |
857 | i2c, config) | |
858 | ||
859 | /** | |
860 | * devm_regmap_init_spi() - Initialise register map | |
861 | * | |
862 | * @dev: Device that will be interacted with | |
863 | * @config: Configuration for register map | |
864 | * | |
865 | * The return value will be an ERR_PTR() on error or a valid pointer | |
866 | * to a struct regmap. The map will be automatically freed by the | |
867 | * device management code. | |
868 | */ | |
869 | #define devm_regmap_init_spi(dev, config) \ | |
870 | __regmap_lockdep_wrapper(__devm_regmap_init_spi, #config, \ | |
871 | dev, config) | |
872 | ||
873 | /** | |
874 | * devm_regmap_init_spmi_base() - Create managed regmap for Base register space | |
875 | * | |
876 | * @dev: SPMI device that will be interacted with | |
877 | * @config: Configuration for register map | |
878 | * | |
879 | * The return value will be an ERR_PTR() on error or a valid pointer | |
880 | * to a struct regmap. The regmap will be automatically freed by the | |
881 | * device management code. | |
882 | */ | |
883 | #define devm_regmap_init_spmi_base(dev, config) \ | |
884 | __regmap_lockdep_wrapper(__devm_regmap_init_spmi_base, #config, \ | |
885 | dev, config) | |
886 | ||
887 | /** | |
888 | * devm_regmap_init_spmi_ext() - Create managed regmap for Ext register space | |
889 | * | |
890 | * @dev: SPMI device that will be interacted with | |
891 | * @config: Configuration for register map | |
892 | * | |
893 | * The return value will be an ERR_PTR() on error or a valid pointer | |
894 | * to a struct regmap. The regmap will be automatically freed by the | |
895 | * device management code. | |
896 | */ | |
897 | #define devm_regmap_init_spmi_ext(dev, config) \ | |
898 | __regmap_lockdep_wrapper(__devm_regmap_init_spmi_ext, #config, \ | |
899 | dev, config) | |
900 | ||
901 | /** | |
902 | * devm_regmap_init_w1() - Initialise managed register map | |
903 | * | |
904 | * @w1_dev: Device that will be interacted with | |
905 | * @config: Configuration for register map | |
906 | * | |
907 | * The return value will be an ERR_PTR() on error or a valid pointer | |
908 | * to a struct regmap. The regmap will be automatically freed by the | |
909 | * device management code. | |
910 | */ | |
911 | #define devm_regmap_init_w1(w1_dev, config) \ | |
912 | __regmap_lockdep_wrapper(__devm_regmap_init_w1, #config, \ | |
913 | w1_dev, config) | |
914 | /** | |
915 | * devm_regmap_init_mmio_clk() - Initialise managed register map with clock | |
916 | * | |
917 | * @dev: Device that will be interacted with | |
918 | * @clk_id: register clock consumer ID | |
919 | * @regs: Pointer to memory-mapped IO region | |
920 | * @config: Configuration for register map | |
921 | * | |
922 | * The return value will be an ERR_PTR() on error or a valid pointer | |
923 | * to a struct regmap. The regmap will be automatically freed by the | |
924 | * device management code. | |
925 | */ | |
926 | #define devm_regmap_init_mmio_clk(dev, clk_id, regs, config) \ | |
927 | __regmap_lockdep_wrapper(__devm_regmap_init_mmio_clk, #config, \ | |
928 | dev, clk_id, regs, config) | |
929 | ||
930 | /** | |
931 | * devm_regmap_init_mmio() - Initialise managed register map | |
932 | * | |
933 | * @dev: Device that will be interacted with | |
934 | * @regs: Pointer to memory-mapped IO region | |
935 | * @config: Configuration for register map | |
936 | * | |
937 | * The return value will be an ERR_PTR() on error or a valid pointer | |
938 | * to a struct regmap. The regmap will be automatically freed by the | |
939 | * device management code. | |
940 | */ | |
941 | #define devm_regmap_init_mmio(dev, regs, config) \ | |
942 | devm_regmap_init_mmio_clk(dev, NULL, regs, config) | |
943 | ||
944 | /** | |
945 | * devm_regmap_init_ac97() - Initialise AC'97 register map | |
946 | * | |
947 | * @ac97: Device that will be interacted with | |
948 | * @config: Configuration for register map | |
949 | * | |
950 | * The return value will be an ERR_PTR() on error or a valid pointer | |
951 | * to a struct regmap. The regmap will be automatically freed by the | |
952 | * device management code. | |
953 | */ | |
954 | #define devm_regmap_init_ac97(ac97, config) \ | |
955 | __regmap_lockdep_wrapper(__devm_regmap_init_ac97, #config, \ | |
956 | ac97, config) | |
957 | ||
958 | /** | |
959 | * devm_regmap_init_sdw() - Initialise managed register map | |
960 | * | |
961 | * @sdw: Device that will be interacted with | |
962 | * @config: Configuration for register map | |
963 | * | |
964 | * The return value will be an ERR_PTR() on error or a valid pointer | |
965 | * to a struct regmap. The regmap will be automatically freed by the | |
966 | * device management code. | |
967 | */ | |
968 | #define devm_regmap_init_sdw(sdw, config) \ | |
969 | __regmap_lockdep_wrapper(__devm_regmap_init_sdw, #config, \ | |
970 | sdw, config) | |
971 | ||
972 | /** | |
973 | * devm_regmap_init_slimbus() - Initialise managed register map | |
974 | * | |
975 | * @slimbus: Device that will be interacted with | |
976 | * @config: Configuration for register map | |
977 | * | |
978 | * The return value will be an ERR_PTR() on error or a valid pointer | |
979 | * to a struct regmap. The regmap will be automatically freed by the | |
980 | * device management code. | |
981 | */ | |
982 | #define devm_regmap_init_slimbus(slimbus, config) \ | |
983 | __regmap_lockdep_wrapper(__devm_regmap_init_slimbus, #config, \ | |
984 | slimbus, config) | |
985 | int regmap_mmio_attach_clk(struct regmap *map, struct clk *clk); | |
986 | void regmap_mmio_detach_clk(struct regmap *map); | |
987 | void regmap_exit(struct regmap *map); | |
988 | int regmap_reinit_cache(struct regmap *map, | |
989 | const struct regmap_config *config); | |
990 | struct regmap *dev_get_regmap(struct device *dev, const char *name); | |
991 | struct device *regmap_get_device(struct regmap *map); | |
992 | int regmap_write(struct regmap *map, unsigned int reg, unsigned int val); | |
993 | int regmap_write_async(struct regmap *map, unsigned int reg, unsigned int val); | |
994 | int regmap_raw_write(struct regmap *map, unsigned int reg, | |
995 | const void *val, size_t val_len); | |
996 | int regmap_noinc_write(struct regmap *map, unsigned int reg, | |
997 | const void *val, size_t val_len); | |
998 | int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val, | |
999 | size_t val_count); | |
1000 | int regmap_multi_reg_write(struct regmap *map, const struct reg_sequence *regs, | |
1001 | int num_regs); | |
1002 | int regmap_multi_reg_write_bypassed(struct regmap *map, | |
1003 | const struct reg_sequence *regs, | |
1004 | int num_regs); | |
1005 | int regmap_raw_write_async(struct regmap *map, unsigned int reg, | |
1006 | const void *val, size_t val_len); | |
1007 | int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val); | |
1008 | int regmap_raw_read(struct regmap *map, unsigned int reg, | |
1009 | void *val, size_t val_len); | |
1010 | int regmap_noinc_read(struct regmap *map, unsigned int reg, | |
1011 | void *val, size_t val_len); | |
1012 | int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val, | |
1013 | size_t val_count); | |
1014 | int regmap_update_bits_base(struct regmap *map, unsigned int reg, | |
1015 | unsigned int mask, unsigned int val, | |
1016 | bool *change, bool async, bool force); | |
1017 | int regmap_get_val_bytes(struct regmap *map); | |
1018 | int regmap_get_max_register(struct regmap *map); | |
1019 | int regmap_get_reg_stride(struct regmap *map); | |
1020 | int regmap_async_complete(struct regmap *map); | |
1021 | bool regmap_can_raw_write(struct regmap *map); | |
1022 | size_t regmap_get_raw_read_max(struct regmap *map); | |
1023 | size_t regmap_get_raw_write_max(struct regmap *map); | |
1024 | ||
1025 | int regcache_sync(struct regmap *map); | |
1026 | int regcache_sync_region(struct regmap *map, unsigned int min, | |
1027 | unsigned int max); | |
1028 | int regcache_drop_region(struct regmap *map, unsigned int min, | |
1029 | unsigned int max); | |
1030 | void regcache_cache_only(struct regmap *map, bool enable); | |
1031 | void regcache_cache_bypass(struct regmap *map, bool enable); | |
1032 | void regcache_mark_dirty(struct regmap *map); | |
1033 | ||
1034 | bool regmap_check_range_table(struct regmap *map, unsigned int reg, | |
1035 | const struct regmap_access_table *table); | |
1036 | ||
1037 | int regmap_register_patch(struct regmap *map, const struct reg_sequence *regs, | |
1038 | int num_regs); | |
1039 | int regmap_parse_val(struct regmap *map, const void *buf, | |
1040 | unsigned int *val); | |
1041 | ||
1042 | static inline bool regmap_reg_in_range(unsigned int reg, | |
1043 | const struct regmap_range *range) | |
1044 | { | |
1045 | return reg >= range->range_min && reg <= range->range_max; | |
1046 | } | |
1047 | ||
1048 | bool regmap_reg_in_ranges(unsigned int reg, | |
1049 | const struct regmap_range *ranges, | |
1050 | unsigned int nranges); | |
1051 | ||
1052 | /** | |
1053 | * struct reg_field - Description of an register field | |
1054 | * | |
1055 | * @reg: Offset of the register within the regmap bank | |
1056 | * @lsb: lsb of the register field. | |
1057 | * @msb: msb of the register field. | |
1058 | * @id_size: port size if it has some ports | |
1059 | * @id_offset: address offset for each ports | |
1060 | */ | |
1061 | struct reg_field { | |
1062 | unsigned int reg; | |
1063 | unsigned int lsb; | |
1064 | unsigned int msb; | |
1065 | unsigned int id_size; | |
1066 | unsigned int id_offset; | |
1067 | }; | |
1068 | ||
1069 | #define REG_FIELD(_reg, _lsb, _msb) { \ | |
1070 | .reg = _reg, \ | |
1071 | .lsb = _lsb, \ | |
1072 | .msb = _msb, \ | |
1073 | } | |
1074 | ||
1075 | struct regmap_field *regmap_field_alloc(struct regmap *regmap, | |
1076 | struct reg_field reg_field); | |
1077 | void regmap_field_free(struct regmap_field *field); | |
1078 | ||
1079 | struct regmap_field *devm_regmap_field_alloc(struct device *dev, | |
1080 | struct regmap *regmap, struct reg_field reg_field); | |
1081 | void devm_regmap_field_free(struct device *dev, struct regmap_field *field); | |
1082 | ||
1083 | int regmap_field_read(struct regmap_field *field, unsigned int *val); | |
1084 | int regmap_field_update_bits_base(struct regmap_field *field, | |
1085 | unsigned int mask, unsigned int val, | |
1086 | bool *change, bool async, bool force); | |
1087 | int regmap_fields_read(struct regmap_field *field, unsigned int id, | |
1088 | unsigned int *val); | |
1089 | int regmap_fields_update_bits_base(struct regmap_field *field, unsigned int id, | |
1090 | unsigned int mask, unsigned int val, | |
1091 | bool *change, bool async, bool force); | |
1092 | /** | |
1093 | * struct regmap_irq_type - IRQ type definitions. | |
1094 | * | |
1095 | * @type_reg_offset: Offset register for the irq type setting. | |
1096 | * @type_rising_val: Register value to configure RISING type irq. | |
1097 | * @type_falling_val: Register value to configure FALLING type irq. | |
1098 | * @type_level_low_val: Register value to configure LEVEL_LOW type irq. | |
1099 | * @type_level_high_val: Register value to configure LEVEL_HIGH type irq. | |
1100 | * @types_supported: logical OR of IRQ_TYPE_* flags indicating supported types. | |
1101 | */ | |
1102 | struct regmap_irq_type { | |
1103 | unsigned int type_reg_offset; | |
1104 | unsigned int type_reg_mask; | |
1105 | unsigned int type_rising_val; | |
1106 | unsigned int type_falling_val; | |
1107 | unsigned int type_level_low_val; | |
1108 | unsigned int type_level_high_val; | |
1109 | unsigned int types_supported; | |
1110 | }; | |
1111 | ||
1112 | /** | |
1113 | * struct regmap_irq - Description of an IRQ for the generic regmap irq_chip. | |
1114 | * | |
1115 | * @reg_offset: Offset of the status/mask register within the bank | |
1116 | * @mask: Mask used to flag/control the register. | |
1117 | * @type: IRQ trigger type setting details if supported. | |
1118 | */ | |
1119 | struct regmap_irq { | |
1120 | unsigned int reg_offset; | |
1121 | unsigned int mask; | |
1122 | struct regmap_irq_type type; | |
1123 | }; | |
1124 | ||
1125 | #define REGMAP_IRQ_REG(_irq, _off, _mask) \ | |
1126 | [_irq] = { .reg_offset = (_off), .mask = (_mask) } | |
1127 | ||
1128 | #define REGMAP_IRQ_REG_LINE(_id, _reg_bits) \ | |
1129 | [_id] = { \ | |
1130 | .mask = BIT((_id) % (_reg_bits)), \ | |
1131 | .reg_offset = (_id) / (_reg_bits), \ | |
1132 | } | |
1133 | ||
1134 | #define REGMAP_IRQ_MAIN_REG_OFFSET(arr) \ | |
1135 | { .num_regs = ARRAY_SIZE((arr)), .offset = &(arr)[0] } | |
1136 | ||
1137 | struct regmap_irq_sub_irq_map { | |
1138 | unsigned int num_regs; | |
1139 | unsigned int *offset; | |
1140 | }; | |
1141 | ||
1142 | /** | |
1143 | * struct regmap_irq_chip - Description of a generic regmap irq_chip. | |
1144 | * | |
1145 | * @name: Descriptive name for IRQ controller. | |
1146 | * | |
1147 | * @main_status: Base main status register address. For chips which have | |
1148 | * interrupts arranged in separate sub-irq blocks with own IRQ | |
1149 | * registers and which have a main IRQ registers indicating | |
1150 | * sub-irq blocks with unhandled interrupts. For such chips fill | |
1151 | * sub-irq register information in status_base, mask_base and | |
1152 | * ack_base. | |
1153 | * @num_main_status_bits: Should be given to chips where number of meaningfull | |
1154 | * main status bits differs from num_regs. | |
1155 | * @sub_reg_offsets: arrays of mappings from main register bits to sub irq | |
1156 | * registers. First item in array describes the registers | |
1157 | * for first main status bit. Second array for second bit etc. | |
1158 | * Offset is given as sub register status offset to | |
1159 | * status_base. Should contain num_regs arrays. | |
1160 | * Can be provided for chips with more complex mapping than | |
1161 | * 1.st bit to 1.st sub-reg, 2.nd bit to 2.nd sub-reg, ... | |
1162 | * @num_main_regs: Number of 'main status' irq registers for chips which have | |
1163 | * main_status set. | |
1164 | * | |
1165 | * @status_base: Base status register address. | |
1166 | * @mask_base: Base mask register address. | |
1167 | * @mask_writeonly: Base mask register is write only. | |
1168 | * @unmask_base: Base unmask register address. for chips who have | |
1169 | * separate mask and unmask registers | |
1170 | * @ack_base: Base ack address. If zero then the chip is clear on read. | |
1171 | * Using zero value is possible with @use_ack bit. | |
1172 | * @wake_base: Base address for wake enables. If zero unsupported. | |
1173 | * @type_base: Base address for irq type. If zero unsupported. | |
1174 | * @irq_reg_stride: Stride to use for chips where registers are not contiguous. | |
1175 | * @init_ack_masked: Ack all masked interrupts once during initalization. | |
1176 | * @mask_invert: Inverted mask register: cleared bits are masked out. | |
1177 | * @use_ack: Use @ack register even if it is zero. | |
1178 | * @ack_invert: Inverted ack register: cleared bits for ack. | |
1179 | * @wake_invert: Inverted wake register: cleared bits are wake enabled. | |
1180 | * @type_invert: Invert the type flags. | |
1181 | * @type_in_mask: Use the mask registers for controlling irq type. For | |
1182 | * interrupts defining type_rising/falling_mask use mask_base | |
1183 | * for edge configuration and never update bits in type_base. | |
1184 | * @clear_on_unmask: For chips with interrupts cleared on read: read the status | |
1185 | * registers before unmasking interrupts to clear any bits | |
1186 | * set when they were masked. | |
1187 | * @runtime_pm: Hold a runtime PM lock on the device when accessing it. | |
1188 | * | |
1189 | * @num_regs: Number of registers in each control bank. | |
1190 | * @irqs: Descriptors for individual IRQs. Interrupt numbers are | |
1191 | * assigned based on the index in the array of the interrupt. | |
1192 | * @num_irqs: Number of descriptors. | |
1193 | * @num_type_reg: Number of type registers. | |
1194 | * @type_reg_stride: Stride to use for chips where type registers are not | |
1195 | * contiguous. | |
1196 | * @handle_pre_irq: Driver specific callback to handle interrupt from device | |
1197 | * before regmap_irq_handler process the interrupts. | |
1198 | * @handle_post_irq: Driver specific callback to handle interrupt from device | |
1199 | * after handling the interrupts in regmap_irq_handler(). | |
1200 | * @irq_drv_data: Driver specific IRQ data which is passed as parameter when | |
1201 | * driver specific pre/post interrupt handler is called. | |
1202 | * | |
1203 | * This is not intended to handle every possible interrupt controller, but | |
1204 | * it should handle a substantial proportion of those that are found in the | |
1205 | * wild. | |
1206 | */ | |
1207 | struct regmap_irq_chip { | |
1208 | const char *name; | |
1209 | ||
1210 | unsigned int main_status; | |
1211 | unsigned int num_main_status_bits; | |
1212 | struct regmap_irq_sub_irq_map *sub_reg_offsets; | |
1213 | int num_main_regs; | |
1214 | ||
1215 | unsigned int status_base; | |
1216 | unsigned int mask_base; | |
1217 | unsigned int unmask_base; | |
1218 | unsigned int ack_base; | |
1219 | unsigned int wake_base; | |
1220 | unsigned int type_base; | |
1221 | unsigned int irq_reg_stride; | |
1222 | bool mask_writeonly:1; | |
1223 | bool init_ack_masked:1; | |
1224 | bool mask_invert:1; | |
1225 | bool use_ack:1; | |
1226 | bool ack_invert:1; | |
1227 | bool wake_invert:1; | |
1228 | bool runtime_pm:1; | |
1229 | bool type_invert:1; | |
1230 | bool type_in_mask:1; | |
1231 | bool clear_on_unmask:1; | |
1232 | ||
1233 | int num_regs; | |
1234 | ||
1235 | const struct regmap_irq *irqs; | |
1236 | int num_irqs; | |
1237 | ||
1238 | int num_type_reg; | |
1239 | unsigned int type_reg_stride; | |
1240 | ||
1241 | int (*handle_pre_irq)(void *irq_drv_data); | |
1242 | int (*handle_post_irq)(void *irq_drv_data); | |
1243 | void *irq_drv_data; | |
1244 | }; | |
1245 | ||
1246 | struct regmap_irq_chip_data; | |
1247 | ||
1248 | int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags, | |
1249 | int irq_base, const struct regmap_irq_chip *chip, | |
1250 | struct regmap_irq_chip_data **data); | |
1251 | void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data); | |
1252 | ||
1253 | int devm_regmap_add_irq_chip(struct device *dev, struct regmap *map, int irq, | |
1254 | int irq_flags, int irq_base, | |
1255 | const struct regmap_irq_chip *chip, | |
1256 | struct regmap_irq_chip_data **data); | |
1257 | void devm_regmap_del_irq_chip(struct device *dev, int irq, | |
1258 | struct regmap_irq_chip_data *data); | |
1259 | ||
1260 | int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data); | |
1261 | int regmap_irq_get_virq(struct regmap_irq_chip_data *data, int irq); | |
1262 | struct irq_domain *regmap_irq_get_domain(struct regmap_irq_chip_data *data); | |
1263 | ||
1264 | #else | |
1265 | ||
1266 | /* | |
1267 | * These stubs should only ever be called by generic code which has | |
1268 | * regmap based facilities, if they ever get called at runtime | |
1269 | * something is going wrong and something probably needs to select | |
1270 | * REGMAP. | |
1271 | */ | |
1272 | ||
1273 | static inline int regmap_write(struct regmap *map, unsigned int reg, | |
1274 | unsigned int val) | |
1275 | { | |
1276 | WARN_ONCE(1, "regmap API is disabled"); | |
1277 | return -EINVAL; | |
1278 | } | |
1279 | ||
1280 | static inline int regmap_write_async(struct regmap *map, unsigned int reg, | |
1281 | unsigned int val) | |
1282 | { | |
1283 | WARN_ONCE(1, "regmap API is disabled"); | |
1284 | return -EINVAL; | |
1285 | } | |
1286 | ||
1287 | static inline int regmap_raw_write(struct regmap *map, unsigned int reg, | |
1288 | const void *val, size_t val_len) | |
1289 | { | |
1290 | WARN_ONCE(1, "regmap API is disabled"); | |
1291 | return -EINVAL; | |
1292 | } | |
1293 | ||
1294 | static inline int regmap_raw_write_async(struct regmap *map, unsigned int reg, | |
1295 | const void *val, size_t val_len) | |
1296 | { | |
1297 | WARN_ONCE(1, "regmap API is disabled"); | |
1298 | return -EINVAL; | |
1299 | } | |
1300 | ||
1301 | static inline int regmap_noinc_write(struct regmap *map, unsigned int reg, | |
1302 | const void *val, size_t val_len) | |
1303 | { | |
1304 | WARN_ONCE(1, "regmap API is disabled"); | |
1305 | return -EINVAL; | |
1306 | } | |
1307 | ||
1308 | static inline int regmap_bulk_write(struct regmap *map, unsigned int reg, | |
1309 | const void *val, size_t val_count) | |
1310 | { | |
1311 | WARN_ONCE(1, "regmap API is disabled"); | |
1312 | return -EINVAL; | |
1313 | } | |
1314 | ||
1315 | static inline int regmap_read(struct regmap *map, unsigned int reg, | |
1316 | unsigned int *val) | |
1317 | { | |
1318 | WARN_ONCE(1, "regmap API is disabled"); | |
1319 | return -EINVAL; | |
1320 | } | |
1321 | ||
1322 | static inline int regmap_raw_read(struct regmap *map, unsigned int reg, | |
1323 | void *val, size_t val_len) | |
1324 | { | |
1325 | WARN_ONCE(1, "regmap API is disabled"); | |
1326 | return -EINVAL; | |
1327 | } | |
1328 | ||
1329 | static inline int regmap_noinc_read(struct regmap *map, unsigned int reg, | |
1330 | void *val, size_t val_len) | |
1331 | { | |
1332 | WARN_ONCE(1, "regmap API is disabled"); | |
1333 | return -EINVAL; | |
1334 | } | |
1335 | ||
1336 | static inline int regmap_bulk_read(struct regmap *map, unsigned int reg, | |
1337 | void *val, size_t val_count) | |
1338 | { | |
1339 | WARN_ONCE(1, "regmap API is disabled"); | |
1340 | return -EINVAL; | |
1341 | } | |
1342 | ||
1343 | static inline int regmap_update_bits_base(struct regmap *map, unsigned int reg, | |
1344 | unsigned int mask, unsigned int val, | |
1345 | bool *change, bool async, bool force) | |
1346 | { | |
1347 | WARN_ONCE(1, "regmap API is disabled"); | |
1348 | return -EINVAL; | |
1349 | } | |
1350 | ||
1351 | static inline int regmap_field_update_bits_base(struct regmap_field *field, | |
1352 | unsigned int mask, unsigned int val, | |
1353 | bool *change, bool async, bool force) | |
1354 | { | |
1355 | WARN_ONCE(1, "regmap API is disabled"); | |
1356 | return -EINVAL; | |
1357 | } | |
1358 | ||
1359 | static inline int regmap_fields_update_bits_base(struct regmap_field *field, | |
1360 | unsigned int id, | |
1361 | unsigned int mask, unsigned int val, | |
1362 | bool *change, bool async, bool force) | |
1363 | { | |
1364 | WARN_ONCE(1, "regmap API is disabled"); | |
1365 | return -EINVAL; | |
1366 | } | |
1367 | ||
1368 | static inline int regmap_get_val_bytes(struct regmap *map) | |
1369 | { | |
1370 | WARN_ONCE(1, "regmap API is disabled"); | |
1371 | return -EINVAL; | |
1372 | } | |
1373 | ||
1374 | static inline int regmap_get_max_register(struct regmap *map) | |
1375 | { | |
1376 | WARN_ONCE(1, "regmap API is disabled"); | |
1377 | return -EINVAL; | |
1378 | } | |
1379 | ||
1380 | static inline int regmap_get_reg_stride(struct regmap *map) | |
1381 | { | |
1382 | WARN_ONCE(1, "regmap API is disabled"); | |
1383 | return -EINVAL; | |
1384 | } | |
1385 | ||
1386 | static inline int regcache_sync(struct regmap *map) | |
1387 | { | |
1388 | WARN_ONCE(1, "regmap API is disabled"); | |
1389 | return -EINVAL; | |
1390 | } | |
1391 | ||
1392 | static inline int regcache_sync_region(struct regmap *map, unsigned int min, | |
1393 | unsigned int max) | |
1394 | { | |
1395 | WARN_ONCE(1, "regmap API is disabled"); | |
1396 | return -EINVAL; | |
1397 | } | |
1398 | ||
1399 | static inline int regcache_drop_region(struct regmap *map, unsigned int min, | |
1400 | unsigned int max) | |
1401 | { | |
1402 | WARN_ONCE(1, "regmap API is disabled"); | |
1403 | return -EINVAL; | |
1404 | } | |
1405 | ||
1406 | static inline void regcache_cache_only(struct regmap *map, bool enable) | |
1407 | { | |
1408 | WARN_ONCE(1, "regmap API is disabled"); | |
1409 | } | |
1410 | ||
1411 | static inline void regcache_cache_bypass(struct regmap *map, bool enable) | |
1412 | { | |
1413 | WARN_ONCE(1, "regmap API is disabled"); | |
1414 | } | |
1415 | ||
1416 | static inline void regcache_mark_dirty(struct regmap *map) | |
1417 | { | |
1418 | WARN_ONCE(1, "regmap API is disabled"); | |
1419 | } | |
1420 | ||
1421 | static inline void regmap_async_complete(struct regmap *map) | |
1422 | { | |
1423 | WARN_ONCE(1, "regmap API is disabled"); | |
1424 | } | |
1425 | ||
1426 | static inline int regmap_register_patch(struct regmap *map, | |
1427 | const struct reg_sequence *regs, | |
1428 | int num_regs) | |
1429 | { | |
1430 | WARN_ONCE(1, "regmap API is disabled"); | |
1431 | return -EINVAL; | |
1432 | } | |
1433 | ||
1434 | static inline int regmap_parse_val(struct regmap *map, const void *buf, | |
1435 | unsigned int *val) | |
1436 | { | |
1437 | WARN_ONCE(1, "regmap API is disabled"); | |
1438 | return -EINVAL; | |
1439 | } | |
1440 | ||
1441 | static inline struct regmap *dev_get_regmap(struct device *dev, | |
1442 | const char *name) | |
1443 | { | |
1444 | return NULL; | |
1445 | } | |
1446 | ||
1447 | static inline struct device *regmap_get_device(struct regmap *map) | |
1448 | { | |
1449 | WARN_ONCE(1, "regmap API is disabled"); | |
1450 | return NULL; | |
1451 | } | |
1452 | ||
1453 | #endif | |
1454 | ||
1455 | #endif |