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