blob: e0960b3ff29068b9a434e6527c3c71e71fb7ad91 [file] [log] [blame]
Mark Brownb83a3132011-05-11 19:59:58 +02001#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
Mark Brownb83a3132011-05-11 19:59:58 +020016#include <linux/list.h>
Krystian Garbaciak6863ca62012-06-15 11:23:56 +010017#include <linux/rbtree.h>
Mateusz Krawczuk49ccc142013-08-06 18:34:40 +020018#include <linux/err.h>
Kevin Hilman3f0fa9a2013-08-14 16:05:02 -070019#include <linux/bug.h>
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +080020#include <linux/lockdep.h>
Mark Brownb83a3132011-05-11 19:59:58 +020021
Paul Gortmakerde477252011-05-26 13:46:22 -040022struct module;
Paul Gortmaker313162d2012-01-30 11:46:54 -050023struct device;
Mark Brown9943fa32011-06-20 19:02:29 +010024struct i2c_client;
Mark Brown90f790d2012-08-20 21:45:05 +010025struct irq_domain;
Mark Browna676f082011-05-12 11:42:10 +020026struct spi_device;
Josh Cartwrighta01779f2013-10-28 13:12:35 -050027struct spmi_device;
Mark Brownb83d2ff2012-03-11 11:49:17 +000028struct regmap;
Krystian Garbaciak6863ca62012-06-15 11:23:56 +010029struct regmap_range_cfg;
Srinivas Kandagatla67252282013-06-11 13:18:15 +010030struct regmap_field;
Mark Brown22853222014-11-18 19:45:51 +010031struct snd_ac97;
Mark Brown9943fa32011-06-20 19:02:29 +010032
Dimitris Papastamos9fabe242011-09-19 14:34:00 +010033/* An enum of all the supported cache types */
34enum regcache_type {
35 REGCACHE_NONE,
Dimitris Papastamos28644c802011-09-19 14:34:02 +010036 REGCACHE_RBTREE,
Mark Brown2ac902c2012-12-19 14:51:55 +000037 REGCACHE_COMPRESSED,
38 REGCACHE_FLAT,
Dimitris Papastamos9fabe242011-09-19 14:34:00 +010039};
40
Mark Browndd898b22011-07-20 22:28:58 +010041/**
Mark Brownbd20eb52011-08-19 18:09:38 +090042 * Default value for a register. We use an array of structs rather
43 * than a simple array as many modern devices have very sparse
44 * register maps.
45 *
46 * @reg: Register address.
47 * @def: Register default value.
48 */
49struct reg_default {
50 unsigned int reg;
51 unsigned int def;
52};
53
Nariman Poushin8019ff62015-07-16 16:36:21 +010054/**
Nariman Poushin2de9d602015-07-16 16:36:22 +010055 * Register/value pairs for sequences of writes with an optional delay in
56 * microseconds to be applied after each write.
Nariman Poushin8019ff62015-07-16 16:36:21 +010057 *
58 * @reg: Register address.
59 * @def: Register value.
Nariman Poushin2de9d602015-07-16 16:36:22 +010060 * @delay_us: Delay to be applied after the register write in microseconds
Nariman Poushin8019ff62015-07-16 16:36:21 +010061 */
62struct reg_sequence {
63 unsigned int reg;
64 unsigned int def;
Nariman Poushin2de9d602015-07-16 16:36:22 +010065 unsigned int delay_us;
Nariman Poushin8019ff62015-07-16 16:36:21 +010066};
67
Kuninori Morimotoca7a9442016-02-15 05:22:42 +000068#define regmap_update_bits(map, reg, mask, val) \
69 regmap_update_bits_base(map, reg, mask, val, NULL, false, false)
Kuninori Morimoto30ed9cb2016-02-15 05:23:01 +000070#define regmap_update_bits_async(map, reg, mask, val)\
71 regmap_update_bits_base(map, reg, mask, val, NULL, true, false)
Kuninori Morimoto98c2dc42016-02-15 05:23:17 +000072#define regmap_update_bits_check(map, reg, mask, val, change)\
73 regmap_update_bits_base(map, reg, mask, val, change, false, false)
Kuninori Morimoto89d8d4b2016-02-15 05:23:37 +000074#define regmap_update_bits_check_async(map, reg, mask, val, change)\
75 regmap_update_bits_base(map, reg, mask, val, change, true, false)
Kuninori Morimotoca7a9442016-02-15 05:22:42 +000076
Kuninori Morimoto36741242016-02-15 05:24:15 +000077#define regmap_field_write(field, val) \
78 regmap_field_update_bits_base(field, ~0, val, NULL, false, false)
Kuninori Morimoto489061b2016-02-15 05:25:54 +000079#define regmap_field_force_write(field, val) \
80 regmap_field_update_bits_base(field, ~0, val, NULL, false, true)
Kuninori Morimoto721ed642016-02-15 05:24:33 +000081#define regmap_field_update_bits(field, mask, val)\
82 regmap_field_update_bits_base(field, mask, val, NULL, false, false)
Kuninori Morimoto489061b2016-02-15 05:25:54 +000083#define regmap_field_force_update_bits(field, mask, val) \
84 regmap_field_update_bits_base(field, mask, val, NULL, false, true)
Kuninori Morimoto36741242016-02-15 05:24:15 +000085
Kuninori Morimotobbf2c462016-02-15 05:25:15 +000086#define regmap_fields_write(field, id, val) \
87 regmap_fields_update_bits_base(field, id, ~0, val, NULL, false, false)
Kuninori Morimotoe6ef2432016-02-15 05:26:14 +000088#define regmap_fields_force_write(field, id, val) \
89 regmap_fields_update_bits_base(field, id, ~0, val, NULL, false, true)
Kuninori Morimoto48138602016-02-15 05:25:32 +000090#define regmap_fields_update_bits(field, id, mask, val)\
91 regmap_fields_update_bits_base(field, id, mask, val, NULL, false, false)
Kuninori Morimotoe6ef2432016-02-15 05:26:14 +000092#define regmap_fields_force_update_bits(field, id, mask, val) \
93 regmap_fields_update_bits_base(field, id, mask, val, NULL, false, true)
Kuninori Morimotobbf2c462016-02-15 05:25:15 +000094
Mark Brownb83d2ff2012-03-11 11:49:17 +000095#ifdef CONFIG_REGMAP
96
Stephen Warren141eba22012-05-24 10:47:26 -060097enum regmap_endian {
98 /* Unspecified -> 0 -> Backwards compatible default */
99 REGMAP_ENDIAN_DEFAULT = 0,
100 REGMAP_ENDIAN_BIG,
101 REGMAP_ENDIAN_LITTLE,
102 REGMAP_ENDIAN_NATIVE,
103};
104
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100105/**
106 * A register range, used for access related checks
107 * (readable/writeable/volatile/precious checks)
108 *
109 * @range_min: address of first register
110 * @range_max: address of last register
111 */
112struct regmap_range {
113 unsigned int range_min;
114 unsigned int range_max;
115};
116
Laxman Dewangan6112fe62013-09-20 18:00:10 +0530117#define regmap_reg_range(low, high) { .range_min = low, .range_max = high, }
118
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100119/*
120 * A table of ranges including some yes ranges and some no ranges.
121 * If a register belongs to a no_range, the corresponding check function
122 * will return false. If a register belongs to a yes range, the corresponding
123 * check function will return true. "no_ranges" are searched first.
124 *
125 * @yes_ranges : pointer to an array of regmap ranges used as "yes ranges"
126 * @n_yes_ranges: size of the above array
127 * @no_ranges: pointer to an array of regmap ranges used as "no ranges"
128 * @n_no_ranges: size of the above array
129 */
130struct regmap_access_table {
131 const struct regmap_range *yes_ranges;
132 unsigned int n_yes_ranges;
133 const struct regmap_range *no_ranges;
134 unsigned int n_no_ranges;
135};
136
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200137typedef void (*regmap_lock)(void *);
138typedef void (*regmap_unlock)(void *);
139
Mark Brownbd20eb52011-08-19 18:09:38 +0900140/**
Mark Browndd898b22011-07-20 22:28:58 +0100141 * Configuration for the register map of a device.
142 *
Stephen Warrend3c242e2012-04-04 15:48:29 -0600143 * @name: Optional name of the regmap. Useful when a device has multiple
144 * register regions.
145 *
Mark Browndd898b22011-07-20 22:28:58 +0100146 * @reg_bits: Number of bits in a register address, mandatory.
Stephen Warrenf01ee602012-04-09 13:40:24 -0600147 * @reg_stride: The register address stride. Valid register addresses are a
148 * multiple of this value. If set to 0, a value of 1 will be
149 * used.
Mark Brown82159ba2012-01-18 10:52:25 +0000150 * @pad_bits: Number of bits of padding between register and value.
Mark Browndd898b22011-07-20 22:28:58 +0100151 * @val_bits: Number of bits in a register value, mandatory.
Mark Brown2e2ae662011-07-20 22:33:39 +0100152 *
Mark Brown3566cc92011-08-09 10:23:22 +0900153 * @writeable_reg: Optional callback returning true if the register
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100154 * can be written to. If this field is NULL but wr_table
155 * (see below) is not, the check is performed on such table
156 * (a register is writeable if it belongs to one of the ranges
157 * specified by wr_table).
Mark Brown3566cc92011-08-09 10:23:22 +0900158 * @readable_reg: Optional callback returning true if the register
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100159 * can be read from. If this field is NULL but rd_table
160 * (see below) is not, the check is performed on such table
161 * (a register is readable if it belongs to one of the ranges
162 * specified by rd_table).
Mark Brown3566cc92011-08-09 10:23:22 +0900163 * @volatile_reg: Optional callback returning true if the register
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100164 * value can't be cached. If this field is NULL but
165 * volatile_table (see below) is not, the check is performed on
166 * such table (a register is volatile if it belongs to one of
167 * the ranges specified by volatile_table).
Laszlo Pappbdc39642014-01-09 14:13:41 +0000168 * @precious_reg: Optional callback returning true if the register
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100169 * should not be read outside of a call from the driver
Laszlo Pappbdc39642014-01-09 14:13:41 +0000170 * (e.g., a clear on read interrupt status register). If this
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100171 * field is NULL but precious_table (see below) is not, the
172 * check is performed on such table (a register is precious if
173 * it belongs to one of the ranges specified by precious_table).
174 * @lock: Optional lock callback (overrides regmap's default lock
175 * function, based on spinlock or mutex).
176 * @unlock: As above for unlocking.
177 * @lock_arg: this field is passed as the only argument of lock/unlock
178 * functions (ignored in case regular lock/unlock functions
179 * are not overridden).
Andrey Smirnovd2a58842013-01-27 10:49:05 -0800180 * @reg_read: Optional callback that if filled will be used to perform
181 * all the reads from the registers. Should only be provided for
Laszlo Pappbdc39642014-01-09 14:13:41 +0000182 * devices whose read operation cannot be represented as a simple
183 * read operation on a bus such as SPI, I2C, etc. Most of the
184 * devices do not need this.
Andrey Smirnovd2a58842013-01-27 10:49:05 -0800185 * @reg_write: Same as above for writing.
186 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
187 * to perform locking. This field is ignored if custom lock/unlock
188 * functions are used (see fields lock/unlock of struct regmap_config).
189 * This field is a duplicate of a similar file in
190 * 'struct regmap_bus' and serves exact same purpose.
191 * Use it only for "no-bus" cases.
Mark Brownbd20eb52011-08-19 18:09:38 +0900192 * @max_register: Optional, specifies the maximum valid register index.
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100193 * @wr_table: Optional, points to a struct regmap_access_table specifying
194 * valid ranges for write access.
195 * @rd_table: As above, for read access.
196 * @volatile_table: As above, for volatile registers.
197 * @precious_table: As above, for precious registers.
Mark Brownbd20eb52011-08-19 18:09:38 +0900198 * @reg_defaults: Power on reset values for registers (for use with
199 * register cache support).
200 * @num_reg_defaults: Number of elements in reg_defaults.
Lars-Peter Clausen6f306442011-09-05 20:46:32 +0200201 *
202 * @read_flag_mask: Mask to be set in the top byte of the register when doing
203 * a read.
204 * @write_flag_mask: Mask to be set in the top byte of the register when doing
205 * a write. If both read_flag_mask and write_flag_mask are
206 * empty the regmap_bus default masks are used.
Ashish Jangam2e33caf2012-04-30 23:23:40 +0100207 * @use_single_rw: If set, converts the bulk read and write operations into
208 * a series of single read and write operations. This is useful
209 * for device that does not support bulk read and write.
Opensource [Anthony Olech]e894c3f2014-03-04 13:54:02 +0000210 * @can_multi_write: If set, the device supports the multi write mode of bulk
211 * write operations, if clear multi write requests will be
212 * split into individual write operations
Dimitris Papastamos9fabe242011-09-19 14:34:00 +0100213 *
214 * @cache_type: The actual cache type.
215 * @reg_defaults_raw: Power on reset values for registers (for use with
216 * register cache support).
217 * @num_reg_defaults_raw: Number of elements in reg_defaults_raw.
Stephen Warren141eba22012-05-24 10:47:26 -0600218 * @reg_format_endian: Endianness for formatted register addresses. If this is
219 * DEFAULT, the @reg_format_endian_default value from the
220 * regmap bus is used.
221 * @val_format_endian: Endianness for formatted register values. If this is
222 * DEFAULT, the @reg_format_endian_default value from the
223 * regmap bus is used.
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100224 *
225 * @ranges: Array of configuration entries for virtual address ranges.
226 * @num_ranges: Number of range configuration entries.
Mark Browndd898b22011-07-20 22:28:58 +0100227 */
Mark Brownb83a3132011-05-11 19:59:58 +0200228struct regmap_config {
Stephen Warrend3c242e2012-04-04 15:48:29 -0600229 const char *name;
230
Mark Brownb83a3132011-05-11 19:59:58 +0200231 int reg_bits;
Stephen Warrenf01ee602012-04-09 13:40:24 -0600232 int reg_stride;
Mark Brown82159ba2012-01-18 10:52:25 +0000233 int pad_bits;
Mark Brownb83a3132011-05-11 19:59:58 +0200234 int val_bits;
Mark Brown2e2ae662011-07-20 22:33:39 +0100235
Mark Brown2e2ae662011-07-20 22:33:39 +0100236 bool (*writeable_reg)(struct device *dev, unsigned int reg);
237 bool (*readable_reg)(struct device *dev, unsigned int reg);
238 bool (*volatile_reg)(struct device *dev, unsigned int reg);
Mark Brown18694882011-08-08 15:40:22 +0900239 bool (*precious_reg)(struct device *dev, unsigned int reg);
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200240 regmap_lock lock;
241 regmap_unlock unlock;
242 void *lock_arg;
Mark Brownbd20eb52011-08-19 18:09:38 +0900243
Andrey Smirnovd2a58842013-01-27 10:49:05 -0800244 int (*reg_read)(void *context, unsigned int reg, unsigned int *val);
245 int (*reg_write)(void *context, unsigned int reg, unsigned int val);
246
247 bool fast_io;
248
Mark Brownbd20eb52011-08-19 18:09:38 +0900249 unsigned int max_register;
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100250 const struct regmap_access_table *wr_table;
251 const struct regmap_access_table *rd_table;
252 const struct regmap_access_table *volatile_table;
253 const struct regmap_access_table *precious_table;
Lars-Peter Clausen720e4612011-11-16 16:28:17 +0100254 const struct reg_default *reg_defaults;
Dimitris Papastamos9fabe242011-09-19 14:34:00 +0100255 unsigned int num_reg_defaults;
256 enum regcache_type cache_type;
257 const void *reg_defaults_raw;
258 unsigned int num_reg_defaults_raw;
Lars-Peter Clausen6f306442011-09-05 20:46:32 +0200259
260 u8 read_flag_mask;
261 u8 write_flag_mask;
Ashish Jangam2e33caf2012-04-30 23:23:40 +0100262
263 bool use_single_rw;
Opensource [Anthony Olech]e894c3f2014-03-04 13:54:02 +0000264 bool can_multi_write;
Stephen Warren141eba22012-05-24 10:47:26 -0600265
266 enum regmap_endian reg_format_endian;
267 enum regmap_endian val_format_endian;
Mark Brown38e23192012-07-22 19:26:07 +0100268
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100269 const struct regmap_range_cfg *ranges;
Mark Browne3549cd2012-10-02 20:17:15 +0100270 unsigned int num_ranges;
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100271};
272
273/**
274 * Configuration for indirectly accessed or paged registers.
275 * Registers, mapped to this virtual range, are accessed in two steps:
276 * 1. page selector register update;
277 * 2. access through data window registers.
278 *
Mark Brownd058bb42012-10-03 12:40:47 +0100279 * @name: Descriptive name for diagnostics
280 *
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100281 * @range_min: Address of the lowest register address in virtual range.
282 * @range_max: Address of the highest register in virtual range.
283 *
284 * @page_sel_reg: Register with selector field.
285 * @page_sel_mask: Bit shift for selector value.
286 * @page_sel_shift: Bit mask for selector value.
287 *
288 * @window_start: Address of first (lowest) register in data window.
289 * @window_len: Number of registers in data window.
290 */
291struct regmap_range_cfg {
Mark Brownd058bb42012-10-03 12:40:47 +0100292 const char *name;
293
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100294 /* Registers of virtual address range */
295 unsigned int range_min;
296 unsigned int range_max;
297
298 /* Page selector for indirect addressing */
299 unsigned int selector_reg;
300 unsigned int selector_mask;
301 int selector_shift;
302
303 /* Data window (per each page) */
304 unsigned int window_start;
305 unsigned int window_len;
Mark Brownb83a3132011-05-11 19:59:58 +0200306};
307
Mark Brown0d509f22013-01-27 22:07:38 +0800308struct regmap_async;
309
Stephen Warren0135bbc2012-04-04 15:48:30 -0600310typedef int (*regmap_hw_write)(void *context, const void *data,
Mark Brownb83a3132011-05-11 19:59:58 +0200311 size_t count);
Stephen Warren0135bbc2012-04-04 15:48:30 -0600312typedef int (*regmap_hw_gather_write)(void *context,
Mark Brownb83a3132011-05-11 19:59:58 +0200313 const void *reg, size_t reg_len,
314 const void *val, size_t val_len);
Mark Brown0d509f22013-01-27 22:07:38 +0800315typedef int (*regmap_hw_async_write)(void *context,
316 const void *reg, size_t reg_len,
317 const void *val, size_t val_len,
318 struct regmap_async *async);
Stephen Warren0135bbc2012-04-04 15:48:30 -0600319typedef int (*regmap_hw_read)(void *context,
Mark Brownb83a3132011-05-11 19:59:58 +0200320 const void *reg_buf, size_t reg_size,
321 void *val_buf, size_t val_size);
Boris BREZILLON3ac17032014-04-17 11:40:11 +0200322typedef int (*regmap_hw_reg_read)(void *context, unsigned int reg,
323 unsigned int *val);
324typedef int (*regmap_hw_reg_write)(void *context, unsigned int reg,
325 unsigned int val);
Jon Ringle77792b12015-10-01 12:38:07 -0400326typedef int (*regmap_hw_reg_update_bits)(void *context, unsigned int reg,
327 unsigned int mask, unsigned int val);
Mark Brown0d509f22013-01-27 22:07:38 +0800328typedef struct regmap_async *(*regmap_hw_async_alloc)(void);
Stephen Warren0135bbc2012-04-04 15:48:30 -0600329typedef void (*regmap_hw_free_context)(void *context);
Mark Brownb83a3132011-05-11 19:59:58 +0200330
331/**
332 * Description of a hardware bus for the register map infrastructure.
333 *
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600334 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200335 * to perform locking. This field is ignored if custom lock/unlock
336 * functions are used (see fields lock/unlock of
337 * struct regmap_config).
Mark Brownb83a3132011-05-11 19:59:58 +0200338 * @write: Write operation.
339 * @gather_write: Write operation with split register/value, return -ENOTSUPP
340 * if not implemented on a given device.
Mark Brown0d509f22013-01-27 22:07:38 +0800341 * @async_write: Write operation which completes asynchronously, optional and
342 * must serialise with respect to non-async I/O.
Markus Pargmannc5f58f22015-08-21 10:26:40 +0200343 * @reg_write: Write a single register value to the given register address. This
344 * write operation has to complete when returning from the function.
Mark Brownb83a3132011-05-11 19:59:58 +0200345 * @read: Read operation. Data is returned in the buffer used to transmit
346 * data.
Markus Pargmannc5f58f22015-08-21 10:26:40 +0200347 * @reg_read: Read a single register value from a given register address.
348 * @free_context: Free context.
Mark Brown0d509f22013-01-27 22:07:38 +0800349 * @async_alloc: Allocate a regmap_async() structure.
Mark Brownb83a3132011-05-11 19:59:58 +0200350 * @read_flag_mask: Mask to be set in the top byte of the register when doing
351 * a read.
Stephen Warren141eba22012-05-24 10:47:26 -0600352 * @reg_format_endian_default: Default endianness for formatted register
353 * addresses. Used when the regmap_config specifies DEFAULT. If this is
354 * DEFAULT, BIG is assumed.
355 * @val_format_endian_default: Default endianness for formatted register
356 * values. Used when the regmap_config specifies DEFAULT. If this is
357 * DEFAULT, BIG is assumed.
Markus Pargmannadaac452015-08-30 09:33:53 +0200358 * @max_raw_read: Max raw read size that can be used on the bus.
359 * @max_raw_write: Max raw write size that can be used on the bus.
Mark Brownb83a3132011-05-11 19:59:58 +0200360 */
361struct regmap_bus {
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600362 bool fast_io;
Mark Brownb83a3132011-05-11 19:59:58 +0200363 regmap_hw_write write;
364 regmap_hw_gather_write gather_write;
Mark Brown0d509f22013-01-27 22:07:38 +0800365 regmap_hw_async_write async_write;
Boris BREZILLON3ac17032014-04-17 11:40:11 +0200366 regmap_hw_reg_write reg_write;
Jon Ringle77792b12015-10-01 12:38:07 -0400367 regmap_hw_reg_update_bits reg_update_bits;
Mark Brownb83a3132011-05-11 19:59:58 +0200368 regmap_hw_read read;
Boris BREZILLON3ac17032014-04-17 11:40:11 +0200369 regmap_hw_reg_read reg_read;
Stephen Warren0135bbc2012-04-04 15:48:30 -0600370 regmap_hw_free_context free_context;
Mark Brown0d509f22013-01-27 22:07:38 +0800371 regmap_hw_async_alloc async_alloc;
Mark Brownb83a3132011-05-11 19:59:58 +0200372 u8 read_flag_mask;
Stephen Warren141eba22012-05-24 10:47:26 -0600373 enum regmap_endian reg_format_endian_default;
374 enum regmap_endian val_format_endian_default;
Markus Pargmannadaac452015-08-30 09:33:53 +0200375 size_t max_raw_read;
376 size_t max_raw_write;
Mark Brownb83a3132011-05-11 19:59:58 +0200377};
378
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800379/*
380 * __regmap_init functions.
381 *
382 * These functions take a lock key and name parameter, and should not be called
383 * directly. Instead, use the regmap_init macros that generate a key and name
384 * for each call.
385 */
386struct regmap *__regmap_init(struct device *dev,
387 const struct regmap_bus *bus,
388 void *bus_context,
389 const struct regmap_config *config,
390 struct lock_class_key *lock_key,
391 const char *lock_name);
392struct regmap *__regmap_init_i2c(struct i2c_client *i2c,
393 const struct regmap_config *config,
394 struct lock_class_key *lock_key,
395 const char *lock_name);
396struct regmap *__regmap_init_spi(struct spi_device *dev,
397 const struct regmap_config *config,
398 struct lock_class_key *lock_key,
399 const char *lock_name);
400struct regmap *__regmap_init_spmi_base(struct spmi_device *dev,
401 const struct regmap_config *config,
402 struct lock_class_key *lock_key,
403 const char *lock_name);
404struct regmap *__regmap_init_spmi_ext(struct spmi_device *dev,
405 const struct regmap_config *config,
406 struct lock_class_key *lock_key,
407 const char *lock_name);
408struct regmap *__regmap_init_mmio_clk(struct device *dev, const char *clk_id,
409 void __iomem *regs,
410 const struct regmap_config *config,
411 struct lock_class_key *lock_key,
412 const char *lock_name);
413struct regmap *__regmap_init_ac97(struct snd_ac97 *ac97,
414 const struct regmap_config *config,
415 struct lock_class_key *lock_key,
416 const char *lock_name);
417
418struct regmap *__devm_regmap_init(struct device *dev,
419 const struct regmap_bus *bus,
420 void *bus_context,
421 const struct regmap_config *config,
422 struct lock_class_key *lock_key,
423 const char *lock_name);
424struct regmap *__devm_regmap_init_i2c(struct i2c_client *i2c,
425 const struct regmap_config *config,
426 struct lock_class_key *lock_key,
427 const char *lock_name);
428struct regmap *__devm_regmap_init_spi(struct spi_device *dev,
429 const struct regmap_config *config,
430 struct lock_class_key *lock_key,
431 const char *lock_name);
432struct regmap *__devm_regmap_init_spmi_base(struct spmi_device *dev,
433 const struct regmap_config *config,
434 struct lock_class_key *lock_key,
435 const char *lock_name);
436struct regmap *__devm_regmap_init_spmi_ext(struct spmi_device *dev,
437 const struct regmap_config *config,
438 struct lock_class_key *lock_key,
439 const char *lock_name);
440struct regmap *__devm_regmap_init_mmio_clk(struct device *dev,
441 const char *clk_id,
442 void __iomem *regs,
443 const struct regmap_config *config,
444 struct lock_class_key *lock_key,
445 const char *lock_name);
446struct regmap *__devm_regmap_init_ac97(struct snd_ac97 *ac97,
447 const struct regmap_config *config,
448 struct lock_class_key *lock_key,
449 const char *lock_name);
450
451/*
452 * Wrapper for regmap_init macros to include a unique lockdep key and name
453 * for each call. No-op if CONFIG_LOCKDEP is not set.
454 *
455 * @fn: Real function to call (in the form __[*_]regmap_init[_*])
456 * @name: Config variable name (#config in the calling macro)
457 **/
458#ifdef CONFIG_LOCKDEP
459#define __regmap_lockdep_wrapper(fn, name, ...) \
460( \
461 ({ \
462 static struct lock_class_key _key; \
463 fn(__VA_ARGS__, &_key, \
464 KBUILD_BASENAME ":" \
465 __stringify(__LINE__) ":" \
466 "(" name ")->lock"); \
467 }) \
468)
469#else
470#define __regmap_lockdep_wrapper(fn, name, ...) fn(__VA_ARGS__, NULL, NULL)
471#endif
472
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800473/**
474 * regmap_init(): Initialise register map
475 *
476 * @dev: Device that will be interacted with
477 * @bus: Bus-specific callbacks to use with device
478 * @bus_context: Data passed to bus-specific callbacks
479 * @config: Configuration for register map
480 *
481 * The return value will be an ERR_PTR() on error or a valid pointer to
482 * a struct regmap. This function should generally not be called
483 * directly, it should be called by bus-specific init functions.
484 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800485#define regmap_init(dev, bus, bus_context, config) \
486 __regmap_lockdep_wrapper(__regmap_init, #config, \
487 dev, bus, bus_context, config)
Michal Simek6cfec042014-02-10 16:22:33 +0100488int regmap_attach_dev(struct device *dev, struct regmap *map,
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800489 const struct regmap_config *config);
Mark Browna676f082011-05-12 11:42:10 +0200490
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800491/**
492 * regmap_init_i2c(): Initialise register map
493 *
494 * @i2c: Device that will be interacted with
495 * @config: Configuration for register map
496 *
497 * The return value will be an ERR_PTR() on error or a valid pointer to
498 * a struct regmap.
499 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800500#define regmap_init_i2c(i2c, config) \
501 __regmap_lockdep_wrapper(__regmap_init_i2c, #config, \
502 i2c, config)
Mark Brown22853222014-11-18 19:45:51 +0100503
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800504/**
505 * regmap_init_spi(): Initialise register map
506 *
507 * @spi: Device that will be interacted with
508 * @config: Configuration for register map
509 *
510 * The return value will be an ERR_PTR() on error or a valid pointer to
511 * a struct regmap.
512 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800513#define regmap_init_spi(dev, config) \
514 __regmap_lockdep_wrapper(__regmap_init_spi, #config, \
515 dev, config)
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800516
517/**
518 * regmap_init_spmi_base(): Create regmap for the Base register space
519 * @sdev: SPMI device that will be interacted with
520 * @config: Configuration for register map
521 *
522 * The return value will be an ERR_PTR() on error or a valid pointer to
523 * a struct regmap.
524 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800525#define regmap_init_spmi_base(dev, config) \
526 __regmap_lockdep_wrapper(__regmap_init_spmi_base, #config, \
527 dev, config)
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800528
529/**
530 * regmap_init_spmi_ext(): Create regmap for Ext register space
531 * @sdev: Device that will be interacted with
532 * @config: Configuration for register map
533 *
534 * The return value will be an ERR_PTR() on error or a valid pointer to
535 * a struct regmap.
536 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800537#define regmap_init_spmi_ext(dev, config) \
538 __regmap_lockdep_wrapper(__regmap_init_spmi_ext, #config, \
539 dev, config)
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800540
541/**
542 * regmap_init_mmio_clk(): Initialise register map with register clock
543 *
544 * @dev: Device that will be interacted with
545 * @clk_id: register clock consumer ID
546 * @regs: Pointer to memory-mapped IO region
547 * @config: Configuration for register map
548 *
549 * The return value will be an ERR_PTR() on error or a valid pointer to
550 * a struct regmap.
551 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800552#define regmap_init_mmio_clk(dev, clk_id, regs, config) \
553 __regmap_lockdep_wrapper(__regmap_init_mmio_clk, #config, \
554 dev, clk_id, regs, config)
Philipp Zabel878ec672013-02-14 17:39:08 +0100555
556/**
557 * regmap_init_mmio(): Initialise register map
558 *
559 * @dev: Device that will be interacted with
560 * @regs: Pointer to memory-mapped IO region
561 * @config: Configuration for register map
562 *
563 * The return value will be an ERR_PTR() on error or a valid pointer to
564 * a struct regmap.
565 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800566#define regmap_init_mmio(dev, regs, config) \
567 regmap_init_mmio_clk(dev, NULL, regs, config)
Philipp Zabel878ec672013-02-14 17:39:08 +0100568
569/**
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800570 * regmap_init_ac97(): Initialise AC'97 register map
571 *
572 * @ac97: Device that will be interacted with
573 * @config: Configuration for register map
574 *
575 * The return value will be an ERR_PTR() on error or a valid pointer to
576 * a struct regmap.
577 */
578#define regmap_init_ac97(ac97, config) \
579 __regmap_lockdep_wrapper(__regmap_init_ac97, #config, \
580 ac97, config)
581bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg);
582
583/**
584 * devm_regmap_init(): Initialise managed register map
585 *
586 * @dev: Device that will be interacted with
587 * @bus: Bus-specific callbacks to use with device
588 * @bus_context: Data passed to bus-specific callbacks
589 * @config: Configuration for register map
590 *
591 * The return value will be an ERR_PTR() on error or a valid pointer
592 * to a struct regmap. This function should generally not be called
593 * directly, it should be called by bus-specific init functions. The
594 * map will be automatically freed by the device management code.
595 */
596#define devm_regmap_init(dev, bus, bus_context, config) \
597 __regmap_lockdep_wrapper(__devm_regmap_init, #config, \
598 dev, bus, bus_context, config)
599
600/**
601 * devm_regmap_init_i2c(): Initialise managed register map
602 *
603 * @i2c: Device that will be interacted with
604 * @config: Configuration for register map
605 *
606 * The return value will be an ERR_PTR() on error or a valid pointer
607 * to a struct regmap. The regmap will be automatically freed by the
608 * device management code.
609 */
610#define devm_regmap_init_i2c(i2c, config) \
611 __regmap_lockdep_wrapper(__devm_regmap_init_i2c, #config, \
612 i2c, config)
613
614/**
615 * devm_regmap_init_spi(): Initialise register map
616 *
617 * @spi: Device that will be interacted with
618 * @config: Configuration for register map
619 *
620 * The return value will be an ERR_PTR() on error or a valid pointer
621 * to a struct regmap. The map will be automatically freed by the
622 * device management code.
623 */
624#define devm_regmap_init_spi(dev, config) \
625 __regmap_lockdep_wrapper(__devm_regmap_init_spi, #config, \
626 dev, config)
627
628/**
629 * devm_regmap_init_spmi_base(): Create managed regmap for Base register space
630 * @sdev: SPMI device that will be interacted with
631 * @config: Configuration for register map
632 *
633 * The return value will be an ERR_PTR() on error or a valid pointer
634 * to a struct regmap. The regmap will be automatically freed by the
635 * device management code.
636 */
637#define devm_regmap_init_spmi_base(dev, config) \
638 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_base, #config, \
639 dev, config)
640
641/**
642 * devm_regmap_init_spmi_ext(): Create managed regmap for Ext register space
643 * @sdev: SPMI device that will be interacted with
644 * @config: Configuration for register map
645 *
646 * The return value will be an ERR_PTR() on error or a valid pointer
647 * to a struct regmap. The regmap will be automatically freed by the
648 * device management code.
649 */
650#define devm_regmap_init_spmi_ext(dev, config) \
651 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_ext, #config, \
652 dev, config)
653
654/**
655 * devm_regmap_init_mmio_clk(): Initialise managed register map with clock
656 *
657 * @dev: Device that will be interacted with
658 * @clk_id: register clock consumer ID
659 * @regs: Pointer to memory-mapped IO region
660 * @config: Configuration for register map
661 *
662 * The return value will be an ERR_PTR() on error or a valid pointer
663 * to a struct regmap. The regmap will be automatically freed by the
664 * device management code.
665 */
666#define devm_regmap_init_mmio_clk(dev, clk_id, regs, config) \
667 __regmap_lockdep_wrapper(__devm_regmap_init_mmio_clk, #config, \
668 dev, clk_id, regs, config)
Philipp Zabel878ec672013-02-14 17:39:08 +0100669
670/**
671 * devm_regmap_init_mmio(): Initialise managed register map
672 *
673 * @dev: Device that will be interacted with
674 * @regs: Pointer to memory-mapped IO region
675 * @config: Configuration for register map
676 *
677 * The return value will be an ERR_PTR() on error or a valid pointer
678 * to a struct regmap. The regmap will be automatically freed by the
679 * device management code.
680 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800681#define devm_regmap_init_mmio(dev, regs, config) \
682 devm_regmap_init_mmio_clk(dev, NULL, regs, config)
Mark Brownc0eb4672012-01-30 19:56:52 +0000683
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800684/**
685 * devm_regmap_init_ac97(): Initialise AC'97 register map
686 *
687 * @ac97: Device that will be interacted with
688 * @config: Configuration for register map
689 *
690 * The return value will be an ERR_PTR() on error or a valid pointer
691 * to a struct regmap. The regmap will be automatically freed by the
692 * device management code.
693 */
694#define devm_regmap_init_ac97(ac97, config) \
695 __regmap_lockdep_wrapper(__devm_regmap_init_ac97, #config, \
696 ac97, config)
Mark Brownb83a3132011-05-11 19:59:58 +0200697
698void regmap_exit(struct regmap *map);
699int regmap_reinit_cache(struct regmap *map,
700 const struct regmap_config *config);
Mark Brown72b39f62012-05-08 17:44:40 +0100701struct regmap *dev_get_regmap(struct device *dev, const char *name);
Tuomas Tynkkynen8d7d3972014-07-21 18:38:47 +0300702struct device *regmap_get_device(struct regmap *map);
Mark Brownb83a3132011-05-11 19:59:58 +0200703int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
Mark Brown915f4412013-10-09 13:30:10 +0100704int regmap_write_async(struct regmap *map, unsigned int reg, unsigned int val);
Mark Brownb83a3132011-05-11 19:59:58 +0200705int regmap_raw_write(struct regmap *map, unsigned int reg,
706 const void *val, size_t val_len);
Laxman Dewangan8eaeb212012-02-12 19:49:43 +0530707int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
708 size_t val_count);
Nariman Poushin8019ff62015-07-16 16:36:21 +0100709int regmap_multi_reg_write(struct regmap *map, const struct reg_sequence *regs,
Anthony Oleche33fabd2013-10-11 15:31:11 +0100710 int num_regs);
Charles Keepax1d5b40b2014-02-25 13:45:50 +0000711int regmap_multi_reg_write_bypassed(struct regmap *map,
Nariman Poushin8019ff62015-07-16 16:36:21 +0100712 const struct reg_sequence *regs,
Charles Keepax1d5b40b2014-02-25 13:45:50 +0000713 int num_regs);
Mark Brown0d509f22013-01-27 22:07:38 +0800714int regmap_raw_write_async(struct regmap *map, unsigned int reg,
715 const void *val, size_t val_len);
Mark Brownb83a3132011-05-11 19:59:58 +0200716int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
717int regmap_raw_read(struct regmap *map, unsigned int reg,
718 void *val, size_t val_len);
719int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
720 size_t val_count);
Kuninori Morimoto91d31b92016-02-15 05:22:18 +0000721int regmap_update_bits_base(struct regmap *map, unsigned int reg,
722 unsigned int mask, unsigned int val,
723 bool *change, bool async, bool force);
Kuninori Morimotofd4b7286c2015-06-16 08:52:39 +0000724int regmap_write_bits(struct regmap *map, unsigned int reg,
725 unsigned int mask, unsigned int val);
Mark Browna6539c32012-02-17 14:20:14 -0800726int regmap_get_val_bytes(struct regmap *map);
Srinivas Kandagatla668abc72015-05-21 17:42:43 +0100727int regmap_get_max_register(struct regmap *map);
Srinivas Kandagatlaa2f776c2015-05-21 17:42:54 +0100728int regmap_get_reg_stride(struct regmap *map);
Mark Brown0d509f22013-01-27 22:07:38 +0800729int regmap_async_complete(struct regmap *map);
Mark Brown221ad7f2013-03-26 21:24:20 +0000730bool regmap_can_raw_write(struct regmap *map);
Markus Pargmannf50c9eb2015-08-30 09:33:54 +0200731size_t regmap_get_raw_read_max(struct regmap *map);
732size_t regmap_get_raw_write_max(struct regmap *map);
Mark Brownb83a3132011-05-11 19:59:58 +0200733
Mark Brown39a58432011-09-19 18:21:49 +0100734int regcache_sync(struct regmap *map);
Mark Brown4d4cfd12012-02-23 20:53:37 +0000735int regcache_sync_region(struct regmap *map, unsigned int min,
736 unsigned int max);
Mark Brown697e85b2013-05-08 13:55:22 +0100737int regcache_drop_region(struct regmap *map, unsigned int min,
738 unsigned int max);
Mark Brown92afb282011-09-19 18:22:14 +0100739void regcache_cache_only(struct regmap *map, bool enable);
Dimitris Papastamos6eb0f5e2011-09-29 14:36:27 +0100740void regcache_cache_bypass(struct regmap *map, bool enable);
Mark Brown8ae0d7e2011-10-26 10:34:22 +0200741void regcache_mark_dirty(struct regmap *map);
Mark Brown92afb282011-09-19 18:22:14 +0100742
Mark Brown154881e2013-05-08 13:55:23 +0100743bool regmap_check_range_table(struct regmap *map, unsigned int reg,
744 const struct regmap_access_table *table);
745
Nariman Poushin8019ff62015-07-16 16:36:21 +0100746int regmap_register_patch(struct regmap *map, const struct reg_sequence *regs,
Mark Brown22f0d902012-01-21 12:01:14 +0000747 int num_regs);
Nenghua Cao13ff50c2014-02-19 18:44:13 +0800748int regmap_parse_val(struct regmap *map, const void *buf,
749 unsigned int *val);
Mark Brown22f0d902012-01-21 12:01:14 +0000750
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100751static inline bool regmap_reg_in_range(unsigned int reg,
752 const struct regmap_range *range)
753{
754 return reg >= range->range_min && reg <= range->range_max;
755}
756
757bool regmap_reg_in_ranges(unsigned int reg,
758 const struct regmap_range *ranges,
759 unsigned int nranges);
760
Mark Brownf8beab22011-10-28 23:50:49 +0200761/**
Srinivas Kandagatla67252282013-06-11 13:18:15 +0100762 * Description of an register field
763 *
764 * @reg: Offset of the register within the regmap bank
765 * @lsb: lsb of the register field.
Bintian Wangf27b37f2015-01-27 20:50:29 +0800766 * @msb: msb of the register field.
Kuninori Morimotoa0102372013-09-01 20:30:50 -0700767 * @id_size: port size if it has some ports
768 * @id_offset: address offset for each ports
Srinivas Kandagatla67252282013-06-11 13:18:15 +0100769 */
770struct reg_field {
771 unsigned int reg;
772 unsigned int lsb;
773 unsigned int msb;
Kuninori Morimotoa0102372013-09-01 20:30:50 -0700774 unsigned int id_size;
775 unsigned int id_offset;
Srinivas Kandagatla67252282013-06-11 13:18:15 +0100776};
777
778#define REG_FIELD(_reg, _lsb, _msb) { \
779 .reg = _reg, \
780 .lsb = _lsb, \
781 .msb = _msb, \
782 }
783
784struct regmap_field *regmap_field_alloc(struct regmap *regmap,
785 struct reg_field reg_field);
786void regmap_field_free(struct regmap_field *field);
787
788struct regmap_field *devm_regmap_field_alloc(struct device *dev,
789 struct regmap *regmap, struct reg_field reg_field);
790void devm_regmap_field_free(struct device *dev, struct regmap_field *field);
791
792int regmap_field_read(struct regmap_field *field, unsigned int *val);
Kuninori Morimoto28972ea2016-02-15 05:23:55 +0000793int regmap_field_update_bits_base(struct regmap_field *field,
794 unsigned int mask, unsigned int val,
795 bool *change, bool async, bool force);
Kuninori Morimotoa0102372013-09-01 20:30:50 -0700796int regmap_fields_read(struct regmap_field *field, unsigned int id,
797 unsigned int *val);
Kuninori Morimotoe126ede2016-02-15 05:24:51 +0000798int regmap_fields_update_bits_base(struct regmap_field *field, unsigned int id,
799 unsigned int mask, unsigned int val,
800 bool *change, bool async, bool force);
Srinivas Kandagatla67252282013-06-11 13:18:15 +0100801
802/**
Mark Brownf8beab22011-10-28 23:50:49 +0200803 * Description of an IRQ for the generic regmap irq_chip.
804 *
805 * @reg_offset: Offset of the status/mask register within the bank
806 * @mask: Mask used to flag/control the register.
Laxman Dewangan7a78479f2015-12-22 18:25:26 +0530807 * @type_reg_offset: Offset register for the irq type setting.
808 * @type_rising_mask: Mask bit to configure RISING type irq.
809 * @type_falling_mask: Mask bit to configure FALLING type irq.
Mark Brownf8beab22011-10-28 23:50:49 +0200810 */
811struct regmap_irq {
812 unsigned int reg_offset;
813 unsigned int mask;
Laxman Dewangan7a78479f2015-12-22 18:25:26 +0530814 unsigned int type_reg_offset;
815 unsigned int type_rising_mask;
816 unsigned int type_falling_mask;
Mark Brownf8beab22011-10-28 23:50:49 +0200817};
818
Qipeng Zhab4fe8ba2015-09-15 00:39:17 +0800819#define REGMAP_IRQ_REG(_irq, _off, _mask) \
820 [_irq] = { .reg_offset = (_off), .mask = (_mask) }
821
Mark Brownf8beab22011-10-28 23:50:49 +0200822/**
823 * Description of a generic regmap irq_chip. This is not intended to
824 * handle every possible interrupt controller, but it should handle a
825 * substantial proportion of those that are found in the wild.
826 *
827 * @name: Descriptive name for IRQ controller.
828 *
829 * @status_base: Base status register address.
830 * @mask_base: Base mask register address.
Guo Zeng7b7d1962015-09-17 05:23:20 +0000831 * @unmask_base: Base unmask register address. for chips who have
832 * separate mask and unmask registers
Alexander Shiyand3233432013-12-15 13:36:51 +0400833 * @ack_base: Base ack address. If zero then the chip is clear on read.
834 * Using zero value is possible with @use_ack bit.
Mark Browna43fd502012-06-05 14:34:03 +0100835 * @wake_base: Base address for wake enables. If zero unsupported.
Laxman Dewangan7a78479f2015-12-22 18:25:26 +0530836 * @type_base: Base address for irq type. If zero unsupported.
Graeme Gregory022f926a2012-05-14 22:40:43 +0900837 * @irq_reg_stride: Stride to use for chips where registers are not contiguous.
Philipp Zabel2753e6f2013-07-22 17:15:52 +0200838 * @init_ack_masked: Ack all masked interrupts once during initalization.
Philipp Zabel68622bd2013-07-24 10:26:48 +0200839 * @mask_invert: Inverted mask register: cleared bits are masked out.
Alexander Shiyand3233432013-12-15 13:36:51 +0400840 * @use_ack: Use @ack register even if it is zero.
Guo Zenga650fdd2015-09-17 05:23:21 +0000841 * @ack_invert: Inverted ack register: cleared bits for ack.
Philipp Zabel68622bd2013-07-24 10:26:48 +0200842 * @wake_invert: Inverted wake register: cleared bits are wake enabled.
Laxman Dewangan7a78479f2015-12-22 18:25:26 +0530843 * @type_invert: Invert the type flags.
Mark Brown0c00c502012-07-24 15:41:19 +0100844 * @runtime_pm: Hold a runtime PM lock on the device when accessing it.
Mark Brownf8beab22011-10-28 23:50:49 +0200845 *
846 * @num_regs: Number of registers in each control bank.
847 * @irqs: Descriptors for individual IRQs. Interrupt numbers are
848 * assigned based on the index in the array of the interrupt.
849 * @num_irqs: Number of descriptors.
Laxman Dewangan7a78479f2015-12-22 18:25:26 +0530850 * @num_type_reg: Number of type registers.
851 * @type_reg_stride: Stride to use for chips where type registers are not
852 * contiguous.
Mark Brownf8beab22011-10-28 23:50:49 +0200853 */
854struct regmap_irq_chip {
855 const char *name;
856
857 unsigned int status_base;
858 unsigned int mask_base;
Guo Zeng7b7d1962015-09-17 05:23:20 +0000859 unsigned int unmask_base;
Mark Brownf8beab22011-10-28 23:50:49 +0200860 unsigned int ack_base;
Mark Browna43fd502012-06-05 14:34:03 +0100861 unsigned int wake_base;
Laxman Dewangan7a78479f2015-12-22 18:25:26 +0530862 unsigned int type_base;
Graeme Gregory022f926a2012-05-14 22:40:43 +0900863 unsigned int irq_reg_stride;
Philipp Zabelf484f7a2013-07-24 10:26:42 +0200864 bool init_ack_masked:1;
865 bool mask_invert:1;
Alexander Shiyand3233432013-12-15 13:36:51 +0400866 bool use_ack:1;
Guo Zenga650fdd2015-09-17 05:23:21 +0000867 bool ack_invert:1;
Philipp Zabelf484f7a2013-07-24 10:26:42 +0200868 bool wake_invert:1;
869 bool runtime_pm:1;
Laxman Dewangan7a78479f2015-12-22 18:25:26 +0530870 bool type_invert:1;
Mark Brownf8beab22011-10-28 23:50:49 +0200871
872 int num_regs;
873
874 const struct regmap_irq *irqs;
875 int num_irqs;
Laxman Dewangan7a78479f2015-12-22 18:25:26 +0530876
877 int num_type_reg;
878 unsigned int type_reg_stride;
Mark Brownf8beab22011-10-28 23:50:49 +0200879};
880
881struct regmap_irq_chip_data;
882
883int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
Mark Brownb026ddb2012-05-31 21:01:46 +0100884 int irq_base, const struct regmap_irq_chip *chip,
Mark Brownf8beab22011-10-28 23:50:49 +0200885 struct regmap_irq_chip_data **data);
886void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data);
Mark Brown209a6002011-12-05 16:10:15 +0000887int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data);
Mark Brown4af8be62012-05-13 10:59:56 +0100888int regmap_irq_get_virq(struct regmap_irq_chip_data *data, int irq);
Mark Brown90f790d2012-08-20 21:45:05 +0100889struct irq_domain *regmap_irq_get_domain(struct regmap_irq_chip_data *data);
Mark Brownb83a3132011-05-11 19:59:58 +0200890
Mark Brown9cde5fc2012-02-17 14:49:51 -0800891#else
892
893/*
894 * These stubs should only ever be called by generic code which has
895 * regmap based facilities, if they ever get called at runtime
896 * something is going wrong and something probably needs to select
897 * REGMAP.
898 */
899
900static inline int regmap_write(struct regmap *map, unsigned int reg,
901 unsigned int val)
902{
903 WARN_ONCE(1, "regmap API is disabled");
904 return -EINVAL;
905}
906
Mark Brown915f4412013-10-09 13:30:10 +0100907static inline int regmap_write_async(struct regmap *map, unsigned int reg,
908 unsigned int val)
909{
910 WARN_ONCE(1, "regmap API is disabled");
911 return -EINVAL;
912}
913
Mark Brown9cde5fc2012-02-17 14:49:51 -0800914static inline int regmap_raw_write(struct regmap *map, unsigned int reg,
915 const void *val, size_t val_len)
916{
917 WARN_ONCE(1, "regmap API is disabled");
918 return -EINVAL;
919}
920
Mark Brown0d509f22013-01-27 22:07:38 +0800921static inline int regmap_raw_write_async(struct regmap *map, unsigned int reg,
922 const void *val, size_t val_len)
923{
924 WARN_ONCE(1, "regmap API is disabled");
925 return -EINVAL;
926}
927
Mark Brown9cde5fc2012-02-17 14:49:51 -0800928static inline int regmap_bulk_write(struct regmap *map, unsigned int reg,
929 const void *val, size_t val_count)
930{
931 WARN_ONCE(1, "regmap API is disabled");
932 return -EINVAL;
933}
934
935static inline int regmap_read(struct regmap *map, unsigned int reg,
936 unsigned int *val)
937{
938 WARN_ONCE(1, "regmap API is disabled");
939 return -EINVAL;
940}
941
942static inline int regmap_raw_read(struct regmap *map, unsigned int reg,
943 void *val, size_t val_len)
944{
945 WARN_ONCE(1, "regmap API is disabled");
946 return -EINVAL;
947}
948
949static inline int regmap_bulk_read(struct regmap *map, unsigned int reg,
950 void *val, size_t val_count)
951{
952 WARN_ONCE(1, "regmap API is disabled");
953 return -EINVAL;
954}
955
Kuninori Morimoto91d31b92016-02-15 05:22:18 +0000956static inline int regmap_update_bits_base(struct regmap *map, unsigned int reg,
957 unsigned int mask, unsigned int val,
958 bool *change, bool async, bool force)
959{
960 WARN_ONCE(1, "regmap API is disabled");
961 return -EINVAL;
962}
963
Kuninori Morimotofd4b7286c2015-06-16 08:52:39 +0000964static inline int regmap_write_bits(struct regmap *map, unsigned int reg,
965 unsigned int mask, unsigned int val)
966{
967 WARN_ONCE(1, "regmap API is disabled");
968 return -EINVAL;
969}
970
Kuninori Morimoto28972ea2016-02-15 05:23:55 +0000971static inline int regmap_field_update_bits_base(struct regmap_field *field,
972 unsigned int mask, unsigned int val,
973 bool *change, bool async, bool force)
974{
975 WARN_ONCE(1, "regmap API is disabled");
976 return -EINVAL;
977}
978
Kuninori Morimotoe126ede2016-02-15 05:24:51 +0000979static inline int regmap_fields_update_bits_base(struct regmap_field *field,
980 unsigned int id,
981 unsigned int mask, unsigned int val,
982 bool *change, bool async, bool force)
983{
984 WARN_ONCE(1, "regmap API is disabled");
985 return -EINVAL;
986}
987
Mark Brown9cde5fc2012-02-17 14:49:51 -0800988static inline int regmap_get_val_bytes(struct regmap *map)
989{
990 WARN_ONCE(1, "regmap API is disabled");
991 return -EINVAL;
992}
993
Srinivas Kandagatla668abc72015-05-21 17:42:43 +0100994static inline int regmap_get_max_register(struct regmap *map)
995{
996 WARN_ONCE(1, "regmap API is disabled");
997 return -EINVAL;
998}
999
Srinivas Kandagatlaa2f776c2015-05-21 17:42:54 +01001000static inline int regmap_get_reg_stride(struct regmap *map)
1001{
1002 WARN_ONCE(1, "regmap API is disabled");
1003 return -EINVAL;
1004}
1005
Mark Brown9cde5fc2012-02-17 14:49:51 -08001006static inline int regcache_sync(struct regmap *map)
1007{
1008 WARN_ONCE(1, "regmap API is disabled");
1009 return -EINVAL;
1010}
1011
Mark Browna313f9f2012-02-23 19:49:43 +00001012static inline int regcache_sync_region(struct regmap *map, unsigned int min,
1013 unsigned int max)
1014{
1015 WARN_ONCE(1, "regmap API is disabled");
1016 return -EINVAL;
1017}
1018
Mark Brown697e85b2013-05-08 13:55:22 +01001019static inline int regcache_drop_region(struct regmap *map, unsigned int min,
1020 unsigned int max)
1021{
1022 WARN_ONCE(1, "regmap API is disabled");
1023 return -EINVAL;
1024}
1025
Mark Brown9cde5fc2012-02-17 14:49:51 -08001026static inline void regcache_cache_only(struct regmap *map, bool enable)
1027{
1028 WARN_ONCE(1, "regmap API is disabled");
1029}
1030
1031static inline void regcache_cache_bypass(struct regmap *map, bool enable)
1032{
1033 WARN_ONCE(1, "regmap API is disabled");
1034}
1035
1036static inline void regcache_mark_dirty(struct regmap *map)
1037{
1038 WARN_ONCE(1, "regmap API is disabled");
1039}
1040
Mark Brown0d509f22013-01-27 22:07:38 +08001041static inline void regmap_async_complete(struct regmap *map)
1042{
1043 WARN_ONCE(1, "regmap API is disabled");
1044}
1045
Mark Brown9cde5fc2012-02-17 14:49:51 -08001046static inline int regmap_register_patch(struct regmap *map,
Daniel Wagnera6baa3d2015-11-30 16:20:15 +01001047 const struct reg_sequence *regs,
Mark Brown9cde5fc2012-02-17 14:49:51 -08001048 int num_regs)
1049{
1050 WARN_ONCE(1, "regmap API is disabled");
1051 return -EINVAL;
1052}
1053
Nenghua Cao13ff50c2014-02-19 18:44:13 +08001054static inline int regmap_parse_val(struct regmap *map, const void *buf,
1055 unsigned int *val)
1056{
1057 WARN_ONCE(1, "regmap API is disabled");
1058 return -EINVAL;
1059}
1060
Mark Brown72b39f62012-05-08 17:44:40 +01001061static inline struct regmap *dev_get_regmap(struct device *dev,
1062 const char *name)
1063{
Mark Brown72b39f62012-05-08 17:44:40 +01001064 return NULL;
1065}
1066
Tuomas Tynkkynen8d7d3972014-07-21 18:38:47 +03001067static inline struct device *regmap_get_device(struct regmap *map)
1068{
1069 WARN_ONCE(1, "regmap API is disabled");
Mark Brown1d33dc62014-07-25 19:01:53 +01001070 return NULL;
Tuomas Tynkkynen8d7d3972014-07-21 18:38:47 +03001071}
1072
Mark Brown9cde5fc2012-02-17 14:49:51 -08001073#endif
1074
Mark Brownb83a3132011-05-11 19:59:58 +02001075#endif