OSDN Git Service

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