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