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