regmap: merge regmap_fields_update_bits() into macro
[deliverable/linux.git] / include / linux / regmap.h
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/err.h>
19 #include <linux/bug.h>
20 #include <linux/lockdep.h>
21
22 struct module;
23 struct device;
24 struct i2c_client;
25 struct irq_domain;
26 struct spi_device;
27 struct spmi_device;
28 struct regmap;
29 struct regmap_range_cfg;
30 struct regmap_field;
31 struct snd_ac97;
32
33 /* An enum of all the supported cache types */
34 enum regcache_type {
35 REGCACHE_NONE,
36 REGCACHE_RBTREE,
37 REGCACHE_COMPRESSED,
38 REGCACHE_FLAT,
39 };
40
41 /**
42 * Default value for a register. We use an array of structs rather
43 * than a simple array as many modern devices have very sparse
44 * register maps.
45 *
46 * @reg: Register address.
47 * @def: Register default value.
48 */
49 struct reg_default {
50 unsigned int reg;
51 unsigned int def;
52 };
53
54 /**
55 * Register/value pairs for sequences of writes with an optional delay in
56 * microseconds to be applied after each write.
57 *
58 * @reg: Register address.
59 * @def: Register value.
60 * @delay_us: Delay to be applied after the register write in microseconds
61 */
62 struct reg_sequence {
63 unsigned int reg;
64 unsigned int def;
65 unsigned int delay_us;
66 };
67
68 #define regmap_update_bits(map, reg, mask, val) \
69 regmap_update_bits_base(map, reg, mask, val, NULL, false, false)
70 #define regmap_update_bits_async(map, reg, mask, val)\
71 regmap_update_bits_base(map, reg, mask, val, NULL, true, false)
72 #define regmap_update_bits_check(map, reg, mask, val, change)\
73 regmap_update_bits_base(map, reg, mask, val, change, false, false)
74 #define regmap_update_bits_check_async(map, reg, mask, val, change)\
75 regmap_update_bits_base(map, reg, mask, val, change, true, false)
76
77 #define regmap_field_write(field, val) \
78 regmap_field_update_bits_base(field, ~0, val, NULL, false, false)
79 #define regmap_field_update_bits(field, mask, val)\
80 regmap_field_update_bits_base(field, mask, val, NULL, false, false)
81
82 #define regmap_fields_write(field, id, val) \
83 regmap_fields_update_bits_base(field, id, ~0, val, NULL, false, false)
84 #define regmap_fields_update_bits(field, id, mask, val)\
85 regmap_fields_update_bits_base(field, id, mask, val, NULL, false, false)
86
87 #ifdef CONFIG_REGMAP
88
89 enum regmap_endian {
90 /* Unspecified -> 0 -> Backwards compatible default */
91 REGMAP_ENDIAN_DEFAULT = 0,
92 REGMAP_ENDIAN_BIG,
93 REGMAP_ENDIAN_LITTLE,
94 REGMAP_ENDIAN_NATIVE,
95 };
96
97 /**
98 * A register range, used for access related checks
99 * (readable/writeable/volatile/precious checks)
100 *
101 * @range_min: address of first register
102 * @range_max: address of last register
103 */
104 struct regmap_range {
105 unsigned int range_min;
106 unsigned int range_max;
107 };
108
109 #define regmap_reg_range(low, high) { .range_min = low, .range_max = high, }
110
111 /*
112 * A table of ranges including some yes ranges and some no ranges.
113 * If a register belongs to a no_range, the corresponding check function
114 * will return false. If a register belongs to a yes range, the corresponding
115 * check function will return true. "no_ranges" are searched first.
116 *
117 * @yes_ranges : pointer to an array of regmap ranges used as "yes ranges"
118 * @n_yes_ranges: size of the above array
119 * @no_ranges: pointer to an array of regmap ranges used as "no ranges"
120 * @n_no_ranges: size of the above array
121 */
122 struct regmap_access_table {
123 const struct regmap_range *yes_ranges;
124 unsigned int n_yes_ranges;
125 const struct regmap_range *no_ranges;
126 unsigned int n_no_ranges;
127 };
128
129 typedef void (*regmap_lock)(void *);
130 typedef void (*regmap_unlock)(void *);
131
132 /**
133 * Configuration for the register map of a device.
134 *
135 * @name: Optional name of the regmap. Useful when a device has multiple
136 * register regions.
137 *
138 * @reg_bits: Number of bits in a register address, mandatory.
139 * @reg_stride: The register address stride. Valid register addresses are a
140 * multiple of this value. If set to 0, a value of 1 will be
141 * used.
142 * @pad_bits: Number of bits of padding between register and value.
143 * @val_bits: Number of bits in a register value, mandatory.
144 *
145 * @writeable_reg: Optional callback returning true if the register
146 * can be written to. If this field is NULL but wr_table
147 * (see below) is not, the check is performed on such table
148 * (a register is writeable if it belongs to one of the ranges
149 * specified by wr_table).
150 * @readable_reg: Optional callback returning true if the register
151 * can be read from. If this field is NULL but rd_table
152 * (see below) is not, the check is performed on such table
153 * (a register is readable if it belongs to one of the ranges
154 * specified by rd_table).
155 * @volatile_reg: Optional callback returning true if the register
156 * value can't be cached. If this field is NULL but
157 * volatile_table (see below) is not, the check is performed on
158 * such table (a register is volatile if it belongs to one of
159 * the ranges specified by volatile_table).
160 * @precious_reg: Optional callback returning true if the register
161 * should not be read outside of a call from the driver
162 * (e.g., a clear on read interrupt status register). If this
163 * field is NULL but precious_table (see below) is not, the
164 * check is performed on such table (a register is precious if
165 * it belongs to one of the ranges specified by precious_table).
166 * @lock: Optional lock callback (overrides regmap's default lock
167 * function, based on spinlock or mutex).
168 * @unlock: As above for unlocking.
169 * @lock_arg: this field is passed as the only argument of lock/unlock
170 * functions (ignored in case regular lock/unlock functions
171 * are not overridden).
172 * @reg_read: Optional callback that if filled will be used to perform
173 * all the reads from the registers. Should only be provided for
174 * devices whose read operation cannot be represented as a simple
175 * read operation on a bus such as SPI, I2C, etc. Most of the
176 * devices do not need this.
177 * @reg_write: Same as above for writing.
178 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
179 * to perform locking. This field is ignored if custom lock/unlock
180 * functions are used (see fields lock/unlock of struct regmap_config).
181 * This field is a duplicate of a similar file in
182 * 'struct regmap_bus' and serves exact same purpose.
183 * Use it only for "no-bus" cases.
184 * @max_register: Optional, specifies the maximum valid register index.
185 * @wr_table: Optional, points to a struct regmap_access_table specifying
186 * valid ranges for write access.
187 * @rd_table: As above, for read access.
188 * @volatile_table: As above, for volatile registers.
189 * @precious_table: As above, for precious registers.
190 * @reg_defaults: Power on reset values for registers (for use with
191 * register cache support).
192 * @num_reg_defaults: Number of elements in reg_defaults.
193 *
194 * @read_flag_mask: Mask to be set in the top byte of the register when doing
195 * a read.
196 * @write_flag_mask: Mask to be set in the top byte of the register when doing
197 * a write. If both read_flag_mask and write_flag_mask are
198 * empty the regmap_bus default masks are used.
199 * @use_single_rw: If set, converts the bulk read and write operations into
200 * a series of single read and write operations. This is useful
201 * for device that does not support bulk read and write.
202 * @can_multi_write: If set, the device supports the multi write mode of bulk
203 * write operations, if clear multi write requests will be
204 * split into individual write operations
205 *
206 * @cache_type: The actual cache type.
207 * @reg_defaults_raw: Power on reset values for registers (for use with
208 * register cache support).
209 * @num_reg_defaults_raw: Number of elements in reg_defaults_raw.
210 * @reg_format_endian: Endianness for formatted register addresses. If this is
211 * DEFAULT, the @reg_format_endian_default value from the
212 * regmap bus is used.
213 * @val_format_endian: Endianness for formatted register values. If this is
214 * DEFAULT, the @reg_format_endian_default value from the
215 * regmap bus is used.
216 *
217 * @ranges: Array of configuration entries for virtual address ranges.
218 * @num_ranges: Number of range configuration entries.
219 */
220 struct regmap_config {
221 const char *name;
222
223 int reg_bits;
224 int reg_stride;
225 int pad_bits;
226 int val_bits;
227
228 bool (*writeable_reg)(struct device *dev, unsigned int reg);
229 bool (*readable_reg)(struct device *dev, unsigned int reg);
230 bool (*volatile_reg)(struct device *dev, unsigned int reg);
231 bool (*precious_reg)(struct device *dev, unsigned int reg);
232 regmap_lock lock;
233 regmap_unlock unlock;
234 void *lock_arg;
235
236 int (*reg_read)(void *context, unsigned int reg, unsigned int *val);
237 int (*reg_write)(void *context, unsigned int reg, unsigned int val);
238
239 bool fast_io;
240
241 unsigned int max_register;
242 const struct regmap_access_table *wr_table;
243 const struct regmap_access_table *rd_table;
244 const struct regmap_access_table *volatile_table;
245 const struct regmap_access_table *precious_table;
246 const struct reg_default *reg_defaults;
247 unsigned int num_reg_defaults;
248 enum regcache_type cache_type;
249 const void *reg_defaults_raw;
250 unsigned int num_reg_defaults_raw;
251
252 u8 read_flag_mask;
253 u8 write_flag_mask;
254
255 bool use_single_rw;
256 bool can_multi_write;
257
258 enum regmap_endian reg_format_endian;
259 enum regmap_endian val_format_endian;
260
261 const struct regmap_range_cfg *ranges;
262 unsigned int num_ranges;
263 };
264
265 /**
266 * Configuration for indirectly accessed or paged registers.
267 * Registers, mapped to this virtual range, are accessed in two steps:
268 * 1. page selector register update;
269 * 2. access through data window registers.
270 *
271 * @name: Descriptive name for diagnostics
272 *
273 * @range_min: Address of the lowest register address in virtual range.
274 * @range_max: Address of the highest register in virtual range.
275 *
276 * @page_sel_reg: Register with selector field.
277 * @page_sel_mask: Bit shift for selector value.
278 * @page_sel_shift: Bit mask for selector value.
279 *
280 * @window_start: Address of first (lowest) register in data window.
281 * @window_len: Number of registers in data window.
282 */
283 struct regmap_range_cfg {
284 const char *name;
285
286 /* Registers of virtual address range */
287 unsigned int range_min;
288 unsigned int range_max;
289
290 /* Page selector for indirect addressing */
291 unsigned int selector_reg;
292 unsigned int selector_mask;
293 int selector_shift;
294
295 /* Data window (per each page) */
296 unsigned int window_start;
297 unsigned int window_len;
298 };
299
300 struct regmap_async;
301
302 typedef int (*regmap_hw_write)(void *context, const void *data,
303 size_t count);
304 typedef int (*regmap_hw_gather_write)(void *context,
305 const void *reg, size_t reg_len,
306 const void *val, size_t val_len);
307 typedef int (*regmap_hw_async_write)(void *context,
308 const void *reg, size_t reg_len,
309 const void *val, size_t val_len,
310 struct regmap_async *async);
311 typedef int (*regmap_hw_read)(void *context,
312 const void *reg_buf, size_t reg_size,
313 void *val_buf, size_t val_size);
314 typedef int (*regmap_hw_reg_read)(void *context, unsigned int reg,
315 unsigned int *val);
316 typedef int (*regmap_hw_reg_write)(void *context, unsigned int reg,
317 unsigned int val);
318 typedef int (*regmap_hw_reg_update_bits)(void *context, unsigned int reg,
319 unsigned int mask, unsigned int val);
320 typedef struct regmap_async *(*regmap_hw_async_alloc)(void);
321 typedef void (*regmap_hw_free_context)(void *context);
322
323 /**
324 * Description of a hardware bus for the register map infrastructure.
325 *
326 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
327 * to perform locking. This field is ignored if custom lock/unlock
328 * functions are used (see fields lock/unlock of
329 * struct regmap_config).
330 * @write: Write operation.
331 * @gather_write: Write operation with split register/value, return -ENOTSUPP
332 * if not implemented on a given device.
333 * @async_write: Write operation which completes asynchronously, optional and
334 * must serialise with respect to non-async I/O.
335 * @reg_write: Write a single register value to the given register address. This
336 * write operation has to complete when returning from the function.
337 * @read: Read operation. Data is returned in the buffer used to transmit
338 * data.
339 * @reg_read: Read a single register value from a given register address.
340 * @free_context: Free context.
341 * @async_alloc: Allocate a regmap_async() structure.
342 * @read_flag_mask: Mask to be set in the top byte of the register when doing
343 * a read.
344 * @reg_format_endian_default: Default endianness for formatted register
345 * addresses. Used when the regmap_config specifies DEFAULT. If this is
346 * DEFAULT, BIG is assumed.
347 * @val_format_endian_default: Default endianness for formatted register
348 * values. Used when the regmap_config specifies DEFAULT. If this is
349 * DEFAULT, BIG is assumed.
350 * @max_raw_read: Max raw read size that can be used on the bus.
351 * @max_raw_write: Max raw write size that can be used on the bus.
352 */
353 struct regmap_bus {
354 bool fast_io;
355 regmap_hw_write write;
356 regmap_hw_gather_write gather_write;
357 regmap_hw_async_write async_write;
358 regmap_hw_reg_write reg_write;
359 regmap_hw_reg_update_bits reg_update_bits;
360 regmap_hw_read read;
361 regmap_hw_reg_read reg_read;
362 regmap_hw_free_context free_context;
363 regmap_hw_async_alloc async_alloc;
364 u8 read_flag_mask;
365 enum regmap_endian reg_format_endian_default;
366 enum regmap_endian val_format_endian_default;
367 size_t max_raw_read;
368 size_t max_raw_write;
369 };
370
371 /*
372 * __regmap_init functions.
373 *
374 * These functions take a lock key and name parameter, and should not be called
375 * directly. Instead, use the regmap_init macros that generate a key and name
376 * for each call.
377 */
378 struct regmap *__regmap_init(struct device *dev,
379 const struct regmap_bus *bus,
380 void *bus_context,
381 const struct regmap_config *config,
382 struct lock_class_key *lock_key,
383 const char *lock_name);
384 struct regmap *__regmap_init_i2c(struct i2c_client *i2c,
385 const struct regmap_config *config,
386 struct lock_class_key *lock_key,
387 const char *lock_name);
388 struct regmap *__regmap_init_spi(struct spi_device *dev,
389 const struct regmap_config *config,
390 struct lock_class_key *lock_key,
391 const char *lock_name);
392 struct regmap *__regmap_init_spmi_base(struct spmi_device *dev,
393 const struct regmap_config *config,
394 struct lock_class_key *lock_key,
395 const char *lock_name);
396 struct regmap *__regmap_init_spmi_ext(struct spmi_device *dev,
397 const struct regmap_config *config,
398 struct lock_class_key *lock_key,
399 const char *lock_name);
400 struct regmap *__regmap_init_mmio_clk(struct device *dev, const char *clk_id,
401 void __iomem *regs,
402 const struct regmap_config *config,
403 struct lock_class_key *lock_key,
404 const char *lock_name);
405 struct regmap *__regmap_init_ac97(struct snd_ac97 *ac97,
406 const struct regmap_config *config,
407 struct lock_class_key *lock_key,
408 const char *lock_name);
409
410 struct regmap *__devm_regmap_init(struct device *dev,
411 const struct regmap_bus *bus,
412 void *bus_context,
413 const struct regmap_config *config,
414 struct lock_class_key *lock_key,
415 const char *lock_name);
416 struct regmap *__devm_regmap_init_i2c(struct i2c_client *i2c,
417 const struct regmap_config *config,
418 struct lock_class_key *lock_key,
419 const char *lock_name);
420 struct regmap *__devm_regmap_init_spi(struct spi_device *dev,
421 const struct regmap_config *config,
422 struct lock_class_key *lock_key,
423 const char *lock_name);
424 struct regmap *__devm_regmap_init_spmi_base(struct spmi_device *dev,
425 const struct regmap_config *config,
426 struct lock_class_key *lock_key,
427 const char *lock_name);
428 struct regmap *__devm_regmap_init_spmi_ext(struct spmi_device *dev,
429 const struct regmap_config *config,
430 struct lock_class_key *lock_key,
431 const char *lock_name);
432 struct regmap *__devm_regmap_init_mmio_clk(struct device *dev,
433 const char *clk_id,
434 void __iomem *regs,
435 const struct regmap_config *config,
436 struct lock_class_key *lock_key,
437 const char *lock_name);
438 struct regmap *__devm_regmap_init_ac97(struct snd_ac97 *ac97,
439 const struct regmap_config *config,
440 struct lock_class_key *lock_key,
441 const char *lock_name);
442
443 /*
444 * Wrapper for regmap_init macros to include a unique lockdep key and name
445 * for each call. No-op if CONFIG_LOCKDEP is not set.
446 *
447 * @fn: Real function to call (in the form __[*_]regmap_init[_*])
448 * @name: Config variable name (#config in the calling macro)
449 **/
450 #ifdef CONFIG_LOCKDEP
451 #define __regmap_lockdep_wrapper(fn, name, ...) \
452 ( \
453 ({ \
454 static struct lock_class_key _key; \
455 fn(__VA_ARGS__, &_key, \
456 KBUILD_BASENAME ":" \
457 __stringify(__LINE__) ":" \
458 "(" name ")->lock"); \
459 }) \
460 )
461 #else
462 #define __regmap_lockdep_wrapper(fn, name, ...) fn(__VA_ARGS__, NULL, NULL)
463 #endif
464
465 /**
466 * regmap_init(): Initialise register map
467 *
468 * @dev: Device that will be interacted with
469 * @bus: Bus-specific callbacks to use with device
470 * @bus_context: Data passed to bus-specific callbacks
471 * @config: Configuration for register map
472 *
473 * The return value will be an ERR_PTR() on error or a valid pointer to
474 * a struct regmap. This function should generally not be called
475 * directly, it should be called by bus-specific init functions.
476 */
477 #define regmap_init(dev, bus, bus_context, config) \
478 __regmap_lockdep_wrapper(__regmap_init, #config, \
479 dev, bus, bus_context, config)
480 int regmap_attach_dev(struct device *dev, struct regmap *map,
481 const struct regmap_config *config);
482
483 /**
484 * regmap_init_i2c(): Initialise register map
485 *
486 * @i2c: Device that will be interacted with
487 * @config: Configuration for register map
488 *
489 * The return value will be an ERR_PTR() on error or a valid pointer to
490 * a struct regmap.
491 */
492 #define regmap_init_i2c(i2c, config) \
493 __regmap_lockdep_wrapper(__regmap_init_i2c, #config, \
494 i2c, config)
495
496 /**
497 * regmap_init_spi(): Initialise register map
498 *
499 * @spi: Device that will be interacted with
500 * @config: Configuration for register map
501 *
502 * The return value will be an ERR_PTR() on error or a valid pointer to
503 * a struct regmap.
504 */
505 #define regmap_init_spi(dev, config) \
506 __regmap_lockdep_wrapper(__regmap_init_spi, #config, \
507 dev, config)
508
509 /**
510 * regmap_init_spmi_base(): Create regmap for the Base register space
511 * @sdev: SPMI device that will be interacted with
512 * @config: Configuration for register map
513 *
514 * The return value will be an ERR_PTR() on error or a valid pointer to
515 * a struct regmap.
516 */
517 #define regmap_init_spmi_base(dev, config) \
518 __regmap_lockdep_wrapper(__regmap_init_spmi_base, #config, \
519 dev, config)
520
521 /**
522 * regmap_init_spmi_ext(): Create regmap for Ext register space
523 * @sdev: Device that will be interacted with
524 * @config: Configuration for register map
525 *
526 * The return value will be an ERR_PTR() on error or a valid pointer to
527 * a struct regmap.
528 */
529 #define regmap_init_spmi_ext(dev, config) \
530 __regmap_lockdep_wrapper(__regmap_init_spmi_ext, #config, \
531 dev, config)
532
533 /**
534 * regmap_init_mmio_clk(): Initialise register map with register clock
535 *
536 * @dev: Device that will be interacted with
537 * @clk_id: register clock consumer ID
538 * @regs: Pointer to memory-mapped IO region
539 * @config: Configuration for register map
540 *
541 * The return value will be an ERR_PTR() on error or a valid pointer to
542 * a struct regmap.
543 */
544 #define regmap_init_mmio_clk(dev, clk_id, regs, config) \
545 __regmap_lockdep_wrapper(__regmap_init_mmio_clk, #config, \
546 dev, clk_id, regs, config)
547
548 /**
549 * regmap_init_mmio(): Initialise register map
550 *
551 * @dev: Device that will be interacted with
552 * @regs: Pointer to memory-mapped IO region
553 * @config: Configuration for register map
554 *
555 * The return value will be an ERR_PTR() on error or a valid pointer to
556 * a struct regmap.
557 */
558 #define regmap_init_mmio(dev, regs, config) \
559 regmap_init_mmio_clk(dev, NULL, regs, config)
560
561 /**
562 * regmap_init_ac97(): Initialise AC'97 register map
563 *
564 * @ac97: Device that will be interacted with
565 * @config: Configuration for register map
566 *
567 * The return value will be an ERR_PTR() on error or a valid pointer to
568 * a struct regmap.
569 */
570 #define regmap_init_ac97(ac97, config) \
571 __regmap_lockdep_wrapper(__regmap_init_ac97, #config, \
572 ac97, config)
573 bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg);
574
575 /**
576 * devm_regmap_init(): Initialise managed register map
577 *
578 * @dev: Device that will be interacted with
579 * @bus: Bus-specific callbacks to use with device
580 * @bus_context: Data passed to bus-specific callbacks
581 * @config: Configuration for register map
582 *
583 * The return value will be an ERR_PTR() on error or a valid pointer
584 * to a struct regmap. This function should generally not be called
585 * directly, it should be called by bus-specific init functions. The
586 * map will be automatically freed by the device management code.
587 */
588 #define devm_regmap_init(dev, bus, bus_context, config) \
589 __regmap_lockdep_wrapper(__devm_regmap_init, #config, \
590 dev, bus, bus_context, config)
591
592 /**
593 * devm_regmap_init_i2c(): Initialise managed register map
594 *
595 * @i2c: Device that will be interacted with
596 * @config: Configuration for register map
597 *
598 * The return value will be an ERR_PTR() on error or a valid pointer
599 * to a struct regmap. The regmap will be automatically freed by the
600 * device management code.
601 */
602 #define devm_regmap_init_i2c(i2c, config) \
603 __regmap_lockdep_wrapper(__devm_regmap_init_i2c, #config, \
604 i2c, config)
605
606 /**
607 * devm_regmap_init_spi(): Initialise register map
608 *
609 * @spi: Device that will be interacted with
610 * @config: Configuration for register map
611 *
612 * The return value will be an ERR_PTR() on error or a valid pointer
613 * to a struct regmap. The map will be automatically freed by the
614 * device management code.
615 */
616 #define devm_regmap_init_spi(dev, config) \
617 __regmap_lockdep_wrapper(__devm_regmap_init_spi, #config, \
618 dev, config)
619
620 /**
621 * devm_regmap_init_spmi_base(): Create managed regmap for Base register space
622 * @sdev: SPMI device that will be interacted with
623 * @config: Configuration for register map
624 *
625 * The return value will be an ERR_PTR() on error or a valid pointer
626 * to a struct regmap. The regmap will be automatically freed by the
627 * device management code.
628 */
629 #define devm_regmap_init_spmi_base(dev, config) \
630 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_base, #config, \
631 dev, config)
632
633 /**
634 * devm_regmap_init_spmi_ext(): Create managed regmap for Ext register space
635 * @sdev: SPMI device that will be interacted with
636 * @config: Configuration for register map
637 *
638 * The return value will be an ERR_PTR() on error or a valid pointer
639 * to a struct regmap. The regmap will be automatically freed by the
640 * device management code.
641 */
642 #define devm_regmap_init_spmi_ext(dev, config) \
643 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_ext, #config, \
644 dev, config)
645
646 /**
647 * devm_regmap_init_mmio_clk(): Initialise managed register map with clock
648 *
649 * @dev: Device that will be interacted with
650 * @clk_id: register clock consumer ID
651 * @regs: Pointer to memory-mapped IO region
652 * @config: Configuration for register map
653 *
654 * The return value will be an ERR_PTR() on error or a valid pointer
655 * to a struct regmap. The regmap will be automatically freed by the
656 * device management code.
657 */
658 #define devm_regmap_init_mmio_clk(dev, clk_id, regs, config) \
659 __regmap_lockdep_wrapper(__devm_regmap_init_mmio_clk, #config, \
660 dev, clk_id, regs, config)
661
662 /**
663 * devm_regmap_init_mmio(): Initialise managed register map
664 *
665 * @dev: Device that will be interacted with
666 * @regs: Pointer to memory-mapped IO region
667 * @config: Configuration for register map
668 *
669 * The return value will be an ERR_PTR() on error or a valid pointer
670 * to a struct regmap. The regmap will be automatically freed by the
671 * device management code.
672 */
673 #define devm_regmap_init_mmio(dev, regs, config) \
674 devm_regmap_init_mmio_clk(dev, NULL, regs, config)
675
676 /**
677 * devm_regmap_init_ac97(): Initialise AC'97 register map
678 *
679 * @ac97: Device that will be interacted with
680 * @config: Configuration for register map
681 *
682 * The return value will be an ERR_PTR() on error or a valid pointer
683 * to a struct regmap. The regmap will be automatically freed by the
684 * device management code.
685 */
686 #define devm_regmap_init_ac97(ac97, config) \
687 __regmap_lockdep_wrapper(__devm_regmap_init_ac97, #config, \
688 ac97, config)
689
690 void regmap_exit(struct regmap *map);
691 int regmap_reinit_cache(struct regmap *map,
692 const struct regmap_config *config);
693 struct regmap *dev_get_regmap(struct device *dev, const char *name);
694 struct device *regmap_get_device(struct regmap *map);
695 int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
696 int regmap_write_async(struct regmap *map, unsigned int reg, unsigned int val);
697 int regmap_raw_write(struct regmap *map, unsigned int reg,
698 const void *val, size_t val_len);
699 int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
700 size_t val_count);
701 int regmap_multi_reg_write(struct regmap *map, const struct reg_sequence *regs,
702 int num_regs);
703 int regmap_multi_reg_write_bypassed(struct regmap *map,
704 const struct reg_sequence *regs,
705 int num_regs);
706 int regmap_raw_write_async(struct regmap *map, unsigned int reg,
707 const void *val, size_t val_len);
708 int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
709 int regmap_raw_read(struct regmap *map, unsigned int reg,
710 void *val, size_t val_len);
711 int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
712 size_t val_count);
713 int regmap_update_bits_base(struct regmap *map, unsigned int reg,
714 unsigned int mask, unsigned int val,
715 bool *change, bool async, bool force);
716 int regmap_write_bits(struct regmap *map, unsigned int reg,
717 unsigned int mask, unsigned int val);
718 int regmap_get_val_bytes(struct regmap *map);
719 int regmap_get_max_register(struct regmap *map);
720 int regmap_get_reg_stride(struct regmap *map);
721 int regmap_async_complete(struct regmap *map);
722 bool regmap_can_raw_write(struct regmap *map);
723 size_t regmap_get_raw_read_max(struct regmap *map);
724 size_t regmap_get_raw_write_max(struct regmap *map);
725
726 int regcache_sync(struct regmap *map);
727 int regcache_sync_region(struct regmap *map, unsigned int min,
728 unsigned int max);
729 int regcache_drop_region(struct regmap *map, unsigned int min,
730 unsigned int max);
731 void regcache_cache_only(struct regmap *map, bool enable);
732 void regcache_cache_bypass(struct regmap *map, bool enable);
733 void regcache_mark_dirty(struct regmap *map);
734
735 bool regmap_check_range_table(struct regmap *map, unsigned int reg,
736 const struct regmap_access_table *table);
737
738 int regmap_register_patch(struct regmap *map, const struct reg_sequence *regs,
739 int num_regs);
740 int regmap_parse_val(struct regmap *map, const void *buf,
741 unsigned int *val);
742
743 static inline bool regmap_reg_in_range(unsigned int reg,
744 const struct regmap_range *range)
745 {
746 return reg >= range->range_min && reg <= range->range_max;
747 }
748
749 bool regmap_reg_in_ranges(unsigned int reg,
750 const struct regmap_range *ranges,
751 unsigned int nranges);
752
753 /**
754 * Description of an register field
755 *
756 * @reg: Offset of the register within the regmap bank
757 * @lsb: lsb of the register field.
758 * @msb: msb of the register field.
759 * @id_size: port size if it has some ports
760 * @id_offset: address offset for each ports
761 */
762 struct reg_field {
763 unsigned int reg;
764 unsigned int lsb;
765 unsigned int msb;
766 unsigned int id_size;
767 unsigned int id_offset;
768 };
769
770 #define REG_FIELD(_reg, _lsb, _msb) { \
771 .reg = _reg, \
772 .lsb = _lsb, \
773 .msb = _msb, \
774 }
775
776 struct regmap_field *regmap_field_alloc(struct regmap *regmap,
777 struct reg_field reg_field);
778 void regmap_field_free(struct regmap_field *field);
779
780 struct regmap_field *devm_regmap_field_alloc(struct device *dev,
781 struct regmap *regmap, struct reg_field reg_field);
782 void devm_regmap_field_free(struct device *dev, struct regmap_field *field);
783
784 int regmap_field_read(struct regmap_field *field, unsigned int *val);
785 int regmap_field_update_bits_base(struct regmap_field *field,
786 unsigned int mask, unsigned int val,
787 bool *change, bool async, bool force);
788 int regmap_fields_force_write(struct regmap_field *field, unsigned int id,
789 unsigned int val);
790 int regmap_fields_read(struct regmap_field *field, unsigned int id,
791 unsigned int *val);
792 int regmap_fields_update_bits_base(struct regmap_field *field, unsigned int id,
793 unsigned int mask, unsigned int val,
794 bool *change, bool async, bool force);
795
796 /**
797 * Description of an IRQ for the generic regmap irq_chip.
798 *
799 * @reg_offset: Offset of the status/mask register within the bank
800 * @mask: Mask used to flag/control the register.
801 * @type_reg_offset: Offset register for the irq type setting.
802 * @type_rising_mask: Mask bit to configure RISING type irq.
803 * @type_falling_mask: Mask bit to configure FALLING type irq.
804 */
805 struct regmap_irq {
806 unsigned int reg_offset;
807 unsigned int mask;
808 unsigned int type_reg_offset;
809 unsigned int type_rising_mask;
810 unsigned int type_falling_mask;
811 };
812
813 #define REGMAP_IRQ_REG(_irq, _off, _mask) \
814 [_irq] = { .reg_offset = (_off), .mask = (_mask) }
815
816 /**
817 * Description of a generic regmap irq_chip. This is not intended to
818 * handle every possible interrupt controller, but it should handle a
819 * substantial proportion of those that are found in the wild.
820 *
821 * @name: Descriptive name for IRQ controller.
822 *
823 * @status_base: Base status register address.
824 * @mask_base: Base mask register address.
825 * @unmask_base: Base unmask register address. for chips who have
826 * separate mask and unmask registers
827 * @ack_base: Base ack address. If zero then the chip is clear on read.
828 * Using zero value is possible with @use_ack bit.
829 * @wake_base: Base address for wake enables. If zero unsupported.
830 * @type_base: Base address for irq type. If zero unsupported.
831 * @irq_reg_stride: Stride to use for chips where registers are not contiguous.
832 * @init_ack_masked: Ack all masked interrupts once during initalization.
833 * @mask_invert: Inverted mask register: cleared bits are masked out.
834 * @use_ack: Use @ack register even if it is zero.
835 * @ack_invert: Inverted ack register: cleared bits for ack.
836 * @wake_invert: Inverted wake register: cleared bits are wake enabled.
837 * @type_invert: Invert the type flags.
838 * @runtime_pm: Hold a runtime PM lock on the device when accessing it.
839 *
840 * @num_regs: Number of registers in each control bank.
841 * @irqs: Descriptors for individual IRQs. Interrupt numbers are
842 * assigned based on the index in the array of the interrupt.
843 * @num_irqs: Number of descriptors.
844 * @num_type_reg: Number of type registers.
845 * @type_reg_stride: Stride to use for chips where type registers are not
846 * contiguous.
847 */
848 struct regmap_irq_chip {
849 const char *name;
850
851 unsigned int status_base;
852 unsigned int mask_base;
853 unsigned int unmask_base;
854 unsigned int ack_base;
855 unsigned int wake_base;
856 unsigned int type_base;
857 unsigned int irq_reg_stride;
858 bool init_ack_masked:1;
859 bool mask_invert:1;
860 bool use_ack:1;
861 bool ack_invert:1;
862 bool wake_invert:1;
863 bool runtime_pm:1;
864 bool type_invert:1;
865
866 int num_regs;
867
868 const struct regmap_irq *irqs;
869 int num_irqs;
870
871 int num_type_reg;
872 unsigned int type_reg_stride;
873 };
874
875 struct regmap_irq_chip_data;
876
877 int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
878 int irq_base, const struct regmap_irq_chip *chip,
879 struct regmap_irq_chip_data **data);
880 void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data);
881 int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data);
882 int regmap_irq_get_virq(struct regmap_irq_chip_data *data, int irq);
883 struct irq_domain *regmap_irq_get_domain(struct regmap_irq_chip_data *data);
884
885 #else
886
887 /*
888 * These stubs should only ever be called by generic code which has
889 * regmap based facilities, if they ever get called at runtime
890 * something is going wrong and something probably needs to select
891 * REGMAP.
892 */
893
894 static inline int regmap_write(struct regmap *map, unsigned int reg,
895 unsigned int val)
896 {
897 WARN_ONCE(1, "regmap API is disabled");
898 return -EINVAL;
899 }
900
901 static inline int regmap_write_async(struct regmap *map, unsigned int reg,
902 unsigned int val)
903 {
904 WARN_ONCE(1, "regmap API is disabled");
905 return -EINVAL;
906 }
907
908 static inline int regmap_raw_write(struct regmap *map, unsigned int reg,
909 const void *val, size_t val_len)
910 {
911 WARN_ONCE(1, "regmap API is disabled");
912 return -EINVAL;
913 }
914
915 static inline int regmap_raw_write_async(struct regmap *map, unsigned int reg,
916 const void *val, size_t val_len)
917 {
918 WARN_ONCE(1, "regmap API is disabled");
919 return -EINVAL;
920 }
921
922 static inline int regmap_bulk_write(struct regmap *map, unsigned int reg,
923 const void *val, size_t val_count)
924 {
925 WARN_ONCE(1, "regmap API is disabled");
926 return -EINVAL;
927 }
928
929 static inline int regmap_read(struct regmap *map, unsigned int reg,
930 unsigned int *val)
931 {
932 WARN_ONCE(1, "regmap API is disabled");
933 return -EINVAL;
934 }
935
936 static inline int regmap_raw_read(struct regmap *map, unsigned int reg,
937 void *val, size_t val_len)
938 {
939 WARN_ONCE(1, "regmap API is disabled");
940 return -EINVAL;
941 }
942
943 static inline int regmap_bulk_read(struct regmap *map, unsigned int reg,
944 void *val, size_t val_count)
945 {
946 WARN_ONCE(1, "regmap API is disabled");
947 return -EINVAL;
948 }
949
950 static inline int regmap_update_bits_base(struct regmap *map, unsigned int reg,
951 unsigned int mask, unsigned int val,
952 bool *change, bool async, bool force)
953 {
954 WARN_ONCE(1, "regmap API is disabled");
955 return -EINVAL;
956 }
957
958 static inline int regmap_write_bits(struct regmap *map, unsigned int reg,
959 unsigned int mask, unsigned int val)
960 {
961 WARN_ONCE(1, "regmap API is disabled");
962 return -EINVAL;
963 }
964
965 static inline int regmap_field_update_bits_base(struct regmap_field *field,
966 unsigned int mask, unsigned int val,
967 bool *change, bool async, bool force)
968 {
969 WARN_ONCE(1, "regmap API is disabled");
970 return -EINVAL;
971 }
972
973 static inline int regmap_fields_update_bits_base(struct regmap_field *field,
974 unsigned int id,
975 unsigned int mask, unsigned int val,
976 bool *change, bool async, bool force)
977 {
978 WARN_ONCE(1, "regmap API is disabled");
979 return -EINVAL;
980 }
981
982 static inline int regmap_get_val_bytes(struct regmap *map)
983 {
984 WARN_ONCE(1, "regmap API is disabled");
985 return -EINVAL;
986 }
987
988 static inline int regmap_get_max_register(struct regmap *map)
989 {
990 WARN_ONCE(1, "regmap API is disabled");
991 return -EINVAL;
992 }
993
994 static inline int regmap_get_reg_stride(struct regmap *map)
995 {
996 WARN_ONCE(1, "regmap API is disabled");
997 return -EINVAL;
998 }
999
1000 static inline int regcache_sync(struct regmap *map)
1001 {
1002 WARN_ONCE(1, "regmap API is disabled");
1003 return -EINVAL;
1004 }
1005
1006 static inline int regcache_sync_region(struct regmap *map, unsigned int min,
1007 unsigned int max)
1008 {
1009 WARN_ONCE(1, "regmap API is disabled");
1010 return -EINVAL;
1011 }
1012
1013 static inline int regcache_drop_region(struct regmap *map, unsigned int min,
1014 unsigned int max)
1015 {
1016 WARN_ONCE(1, "regmap API is disabled");
1017 return -EINVAL;
1018 }
1019
1020 static inline void regcache_cache_only(struct regmap *map, bool enable)
1021 {
1022 WARN_ONCE(1, "regmap API is disabled");
1023 }
1024
1025 static inline void regcache_cache_bypass(struct regmap *map, bool enable)
1026 {
1027 WARN_ONCE(1, "regmap API is disabled");
1028 }
1029
1030 static inline void regcache_mark_dirty(struct regmap *map)
1031 {
1032 WARN_ONCE(1, "regmap API is disabled");
1033 }
1034
1035 static inline void regmap_async_complete(struct regmap *map)
1036 {
1037 WARN_ONCE(1, "regmap API is disabled");
1038 }
1039
1040 static inline int regmap_register_patch(struct regmap *map,
1041 const struct reg_sequence *regs,
1042 int num_regs)
1043 {
1044 WARN_ONCE(1, "regmap API is disabled");
1045 return -EINVAL;
1046 }
1047
1048 static inline int regmap_parse_val(struct regmap *map, const void *buf,
1049 unsigned int *val)
1050 {
1051 WARN_ONCE(1, "regmap API is disabled");
1052 return -EINVAL;
1053 }
1054
1055 static inline struct regmap *dev_get_regmap(struct device *dev,
1056 const char *name)
1057 {
1058 return NULL;
1059 }
1060
1061 static inline struct device *regmap_get_device(struct regmap *map)
1062 {
1063 WARN_ONCE(1, "regmap API is disabled");
1064 return NULL;
1065 }
1066
1067 #endif
1068
1069 #endif
This page took 0.051863 seconds and 6 git commands to generate.