blob: f6673132431d09c3caa0c1394286fb310c93f9c1 [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>
Masahiro Yamadaadf08d42016-10-13 19:07:54 +090018#include <linux/delay.h>
Mateusz Krawczuk49ccc142013-08-06 18:34:40 +020019#include <linux/err.h>
Kevin Hilman3f0fa9a2013-08-14 16:05:02 -070020#include <linux/bug.h>
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +080021#include <linux/lockdep.h>
Mark Brownb83a3132011-05-11 19:59:58 +020022
Paul Gortmakerde477252011-05-26 13:46:22 -040023struct module;
Paul Gortmaker313162d2012-01-30 11:46:54 -050024struct device;
Mark Brown9943fa32011-06-20 19:02:29 +010025struct i2c_client;
Mark Brown90f790d2012-08-20 21:45:05 +010026struct irq_domain;
Mark Browna676f082011-05-12 11:42:10 +020027struct spi_device;
Josh Cartwrighta01779f2013-10-28 13:12:35 -050028struct spmi_device;
Mark Brownb83d2ff2012-03-11 11:49:17 +000029struct regmap;
Krystian Garbaciak6863ca62012-06-15 11:23:56 +010030struct regmap_range_cfg;
Srinivas Kandagatla67252282013-06-11 13:18:15 +010031struct regmap_field;
Mark Brown22853222014-11-18 19:45:51 +010032struct snd_ac97;
Mark Brown9943fa32011-06-20 19:02:29 +010033
Dimitris Papastamos9fabe242011-09-19 14:34:00 +010034/* An enum of all the supported cache types */
35enum regcache_type {
36 REGCACHE_NONE,
Dimitris Papastamos28644c802011-09-19 14:34:02 +010037 REGCACHE_RBTREE,
Mark Brown2ac902c2012-12-19 14:51:55 +000038 REGCACHE_COMPRESSED,
39 REGCACHE_FLAT,
Dimitris Papastamos9fabe242011-09-19 14:34:00 +010040};
41
Mark Browndd898b22011-07-20 22:28:58 +010042/**
Mark Brownbd20eb52011-08-19 18:09:38 +090043 * 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 */
50struct reg_default {
51 unsigned int reg;
52 unsigned int def;
53};
54
Nariman Poushin8019ff62015-07-16 16:36:21 +010055/**
Nariman Poushin2de9d602015-07-16 16:36:22 +010056 * Register/value pairs for sequences of writes with an optional delay in
57 * microseconds to be applied after each write.
Nariman Poushin8019ff62015-07-16 16:36:21 +010058 *
59 * @reg: Register address.
60 * @def: Register value.
Nariman Poushin2de9d602015-07-16 16:36:22 +010061 * @delay_us: Delay to be applied after the register write in microseconds
Nariman Poushin8019ff62015-07-16 16:36:21 +010062 */
63struct reg_sequence {
64 unsigned int reg;
65 unsigned int def;
Nariman Poushin2de9d602015-07-16 16:36:22 +010066 unsigned int delay_us;
Nariman Poushin8019ff62015-07-16 16:36:21 +010067};
68
Kuninori Morimotoca7a9442016-02-15 05:22:42 +000069#define regmap_update_bits(map, reg, mask, val) \
70 regmap_update_bits_base(map, reg, mask, val, NULL, false, false)
Kuninori Morimoto30ed9cb2016-02-15 05:23:01 +000071#define regmap_update_bits_async(map, reg, mask, val)\
72 regmap_update_bits_base(map, reg, mask, val, NULL, true, false)
Kuninori Morimoto98c2dc42016-02-15 05:23:17 +000073#define regmap_update_bits_check(map, reg, mask, val, change)\
74 regmap_update_bits_base(map, reg, mask, val, change, false, false)
Kuninori Morimoto89d8d4b2016-02-15 05:23:37 +000075#define regmap_update_bits_check_async(map, reg, mask, val, change)\
76 regmap_update_bits_base(map, reg, mask, val, change, true, false)
Kuninori Morimotoca7a9442016-02-15 05:22:42 +000077
Kuninori Morimotob8219572016-03-03 00:48:30 +000078#define regmap_write_bits(map, reg, mask, val) \
79 regmap_update_bits_base(map, reg, mask, val, NULL, false, true)
80
Kuninori Morimoto36741242016-02-15 05:24:15 +000081#define regmap_field_write(field, val) \
82 regmap_field_update_bits_base(field, ~0, val, NULL, false, false)
Kuninori Morimoto489061b2016-02-15 05:25:54 +000083#define regmap_field_force_write(field, val) \
84 regmap_field_update_bits_base(field, ~0, val, NULL, false, true)
Kuninori Morimoto721ed642016-02-15 05:24:33 +000085#define regmap_field_update_bits(field, mask, val)\
86 regmap_field_update_bits_base(field, mask, val, NULL, false, false)
Kuninori Morimoto489061b2016-02-15 05:25:54 +000087#define regmap_field_force_update_bits(field, mask, val) \
88 regmap_field_update_bits_base(field, mask, val, NULL, false, true)
Kuninori Morimoto36741242016-02-15 05:24:15 +000089
Kuninori Morimotobbf2c462016-02-15 05:25:15 +000090#define regmap_fields_write(field, id, val) \
91 regmap_fields_update_bits_base(field, id, ~0, val, NULL, false, false)
Kuninori Morimotoe6ef2432016-02-15 05:26:14 +000092#define regmap_fields_force_write(field, id, val) \
93 regmap_fields_update_bits_base(field, id, ~0, val, NULL, false, true)
Kuninori Morimoto48138602016-02-15 05:25:32 +000094#define regmap_fields_update_bits(field, id, mask, val)\
95 regmap_fields_update_bits_base(field, id, mask, val, NULL, false, false)
Kuninori Morimotoe6ef2432016-02-15 05:26:14 +000096#define regmap_fields_force_update_bits(field, id, mask, val) \
97 regmap_fields_update_bits_base(field, id, mask, val, NULL, false, true)
Kuninori Morimotobbf2c462016-02-15 05:25:15 +000098
Philipp Zabel08188ba2016-07-06 16:19:41 +020099/**
100 * regmap_read_poll_timeout - Poll until a condition is met or a timeout occurs
101 * @map: Regmap to read from
102 * @addr: Address to poll
103 * @val: Unsigned integer variable to read the value into
104 * @cond: Break condition (usually involving @val)
105 * @sleep_us: Maximum time to sleep between reads in us (0
106 * tight-loops). Should be less than ~20ms since usleep_range
107 * is used (see Documentation/timers/timers-howto.txt).
108 * @timeout_us: Timeout in us, 0 means never timeout
109 *
110 * Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_read
111 * error return value in case of a error read. In the two former cases,
112 * the last read value at @addr is stored in @val. Must not be called
113 * from atomic context if sleep_us or timeout_us are used.
114 *
115 * This is modelled after the readx_poll_timeout macros in linux/iopoll.h.
116 */
117#define regmap_read_poll_timeout(map, addr, val, cond, sleep_us, timeout_us) \
118({ \
119 ktime_t timeout = ktime_add_us(ktime_get(), timeout_us); \
Charles Keepax72193a92016-10-28 11:38:53 +0100120 int pollret; \
Philipp Zabel08188ba2016-07-06 16:19:41 +0200121 might_sleep_if(sleep_us); \
122 for (;;) { \
Charles Keepax72193a92016-10-28 11:38:53 +0100123 pollret = regmap_read((map), (addr), &(val)); \
124 if (pollret) \
Philipp Zabel08188ba2016-07-06 16:19:41 +0200125 break; \
126 if (cond) \
127 break; \
128 if (timeout_us && ktime_compare(ktime_get(), timeout) > 0) { \
Charles Keepax72193a92016-10-28 11:38:53 +0100129 pollret = regmap_read((map), (addr), &(val)); \
Philipp Zabel08188ba2016-07-06 16:19:41 +0200130 break; \
131 } \
132 if (sleep_us) \
133 usleep_range((sleep_us >> 2) + 1, sleep_us); \
134 } \
Charles Keepax72193a92016-10-28 11:38:53 +0100135 pollret ?: ((cond) ? 0 : -ETIMEDOUT); \
Philipp Zabel08188ba2016-07-06 16:19:41 +0200136})
137
Mark Brownb83d2ff2012-03-11 11:49:17 +0000138#ifdef CONFIG_REGMAP
139
Stephen Warren141eba22012-05-24 10:47:26 -0600140enum regmap_endian {
141 /* Unspecified -> 0 -> Backwards compatible default */
142 REGMAP_ENDIAN_DEFAULT = 0,
143 REGMAP_ENDIAN_BIG,
144 REGMAP_ENDIAN_LITTLE,
145 REGMAP_ENDIAN_NATIVE,
146};
147
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100148/**
149 * A register range, used for access related checks
150 * (readable/writeable/volatile/precious checks)
151 *
152 * @range_min: address of first register
153 * @range_max: address of last register
154 */
155struct regmap_range {
156 unsigned int range_min;
157 unsigned int range_max;
158};
159
Laxman Dewangan6112fe62013-09-20 18:00:10 +0530160#define regmap_reg_range(low, high) { .range_min = low, .range_max = high, }
161
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100162/*
163 * A table of ranges including some yes ranges and some no ranges.
164 * If a register belongs to a no_range, the corresponding check function
165 * will return false. If a register belongs to a yes range, the corresponding
166 * check function will return true. "no_ranges" are searched first.
167 *
168 * @yes_ranges : pointer to an array of regmap ranges used as "yes ranges"
169 * @n_yes_ranges: size of the above array
170 * @no_ranges: pointer to an array of regmap ranges used as "no ranges"
171 * @n_no_ranges: size of the above array
172 */
173struct regmap_access_table {
174 const struct regmap_range *yes_ranges;
175 unsigned int n_yes_ranges;
176 const struct regmap_range *no_ranges;
177 unsigned int n_no_ranges;
178};
179
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200180typedef void (*regmap_lock)(void *);
181typedef void (*regmap_unlock)(void *);
182
Mark Brownbd20eb52011-08-19 18:09:38 +0900183/**
Mark Browndd898b22011-07-20 22:28:58 +0100184 * Configuration for the register map of a device.
185 *
Stephen Warrend3c242e2012-04-04 15:48:29 -0600186 * @name: Optional name of the regmap. Useful when a device has multiple
187 * register regions.
188 *
Mark Browndd898b22011-07-20 22:28:58 +0100189 * @reg_bits: Number of bits in a register address, mandatory.
Stephen Warrenf01ee602012-04-09 13:40:24 -0600190 * @reg_stride: The register address stride. Valid register addresses are a
191 * multiple of this value. If set to 0, a value of 1 will be
192 * used.
Mark Brown82159ba2012-01-18 10:52:25 +0000193 * @pad_bits: Number of bits of padding between register and value.
Mark Browndd898b22011-07-20 22:28:58 +0100194 * @val_bits: Number of bits in a register value, mandatory.
Mark Brown2e2ae662011-07-20 22:33:39 +0100195 *
Mark Brown3566cc92011-08-09 10:23:22 +0900196 * @writeable_reg: Optional callback returning true if the register
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100197 * can be written to. If this field is NULL but wr_table
198 * (see below) is not, the check is performed on such table
199 * (a register is writeable if it belongs to one of the ranges
200 * specified by wr_table).
Mark Brown3566cc92011-08-09 10:23:22 +0900201 * @readable_reg: Optional callback returning true if the register
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100202 * can be read from. If this field is NULL but rd_table
203 * (see below) is not, the check is performed on such table
204 * (a register is readable if it belongs to one of the ranges
205 * specified by rd_table).
Mark Brown3566cc92011-08-09 10:23:22 +0900206 * @volatile_reg: Optional callback returning true if the register
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100207 * value can't be cached. If this field is NULL but
208 * volatile_table (see below) is not, the check is performed on
209 * such table (a register is volatile if it belongs to one of
210 * the ranges specified by volatile_table).
Laszlo Pappbdc39642014-01-09 14:13:41 +0000211 * @precious_reg: Optional callback returning true if the register
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100212 * should not be read outside of a call from the driver
Laszlo Pappbdc39642014-01-09 14:13:41 +0000213 * (e.g., a clear on read interrupt status register). If this
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100214 * field is NULL but precious_table (see below) is not, the
215 * check is performed on such table (a register is precious if
216 * it belongs to one of the ranges specified by precious_table).
217 * @lock: Optional lock callback (overrides regmap's default lock
218 * function, based on spinlock or mutex).
219 * @unlock: As above for unlocking.
220 * @lock_arg: this field is passed as the only argument of lock/unlock
221 * functions (ignored in case regular lock/unlock functions
222 * are not overridden).
Andrey Smirnovd2a58842013-01-27 10:49:05 -0800223 * @reg_read: Optional callback that if filled will be used to perform
224 * all the reads from the registers. Should only be provided for
Laszlo Pappbdc39642014-01-09 14:13:41 +0000225 * devices whose read operation cannot be represented as a simple
226 * read operation on a bus such as SPI, I2C, etc. Most of the
227 * devices do not need this.
Andrey Smirnovd2a58842013-01-27 10:49:05 -0800228 * @reg_write: Same as above for writing.
229 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
230 * to perform locking. This field is ignored if custom lock/unlock
231 * functions are used (see fields lock/unlock of struct regmap_config).
232 * This field is a duplicate of a similar file in
233 * 'struct regmap_bus' and serves exact same purpose.
234 * Use it only for "no-bus" cases.
Stefan Agnerb429fab2016-01-19 17:14:39 -0800235 * @max_register: Optional, specifies the maximum valid register address.
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100236 * @wr_table: Optional, points to a struct regmap_access_table specifying
237 * valid ranges for write access.
238 * @rd_table: As above, for read access.
239 * @volatile_table: As above, for volatile registers.
240 * @precious_table: As above, for precious registers.
Mark Brownbd20eb52011-08-19 18:09:38 +0900241 * @reg_defaults: Power on reset values for registers (for use with
242 * register cache support).
243 * @num_reg_defaults: Number of elements in reg_defaults.
Lars-Peter Clausen6f306442011-09-05 20:46:32 +0200244 *
Tony Lindgrenf50e38c2016-09-15 13:56:10 -0700245 * @read_flag_mask: Mask to be set in the top bytes of the register when doing
Lars-Peter Clausen6f306442011-09-05 20:46:32 +0200246 * a read.
Tony Lindgrenf50e38c2016-09-15 13:56:10 -0700247 * @write_flag_mask: Mask to be set in the top bytes of the register when doing
Lars-Peter Clausen6f306442011-09-05 20:46:32 +0200248 * a write. If both read_flag_mask and write_flag_mask are
249 * empty the regmap_bus default masks are used.
Ashish Jangam2e33caf2012-04-30 23:23:40 +0100250 * @use_single_rw: If set, converts the bulk read and write operations into
251 * a series of single read and write operations. This is useful
252 * for device that does not support bulk read and write.
Opensource [Anthony Olech]e894c3f2014-03-04 13:54:02 +0000253 * @can_multi_write: If set, the device supports the multi write mode of bulk
254 * write operations, if clear multi write requests will be
255 * split into individual write operations
Dimitris Papastamos9fabe242011-09-19 14:34:00 +0100256 *
257 * @cache_type: The actual cache type.
258 * @reg_defaults_raw: Power on reset values for registers (for use with
259 * register cache support).
260 * @num_reg_defaults_raw: Number of elements in reg_defaults_raw.
Stephen Warren141eba22012-05-24 10:47:26 -0600261 * @reg_format_endian: Endianness for formatted register addresses. If this is
262 * DEFAULT, the @reg_format_endian_default value from the
263 * regmap bus is used.
264 * @val_format_endian: Endianness for formatted register values. If this is
265 * DEFAULT, the @reg_format_endian_default value from the
266 * regmap bus is used.
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100267 *
268 * @ranges: Array of configuration entries for virtual address ranges.
269 * @num_ranges: Number of range configuration entries.
Mark Browndd898b22011-07-20 22:28:58 +0100270 */
Mark Brownb83a3132011-05-11 19:59:58 +0200271struct regmap_config {
Stephen Warrend3c242e2012-04-04 15:48:29 -0600272 const char *name;
273
Mark Brownb83a3132011-05-11 19:59:58 +0200274 int reg_bits;
Stephen Warrenf01ee602012-04-09 13:40:24 -0600275 int reg_stride;
Mark Brown82159ba2012-01-18 10:52:25 +0000276 int pad_bits;
Mark Brownb83a3132011-05-11 19:59:58 +0200277 int val_bits;
Mark Brown2e2ae662011-07-20 22:33:39 +0100278
Mark Brown2e2ae662011-07-20 22:33:39 +0100279 bool (*writeable_reg)(struct device *dev, unsigned int reg);
280 bool (*readable_reg)(struct device *dev, unsigned int reg);
281 bool (*volatile_reg)(struct device *dev, unsigned int reg);
Mark Brown18694882011-08-08 15:40:22 +0900282 bool (*precious_reg)(struct device *dev, unsigned int reg);
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200283 regmap_lock lock;
284 regmap_unlock unlock;
285 void *lock_arg;
Mark Brownbd20eb52011-08-19 18:09:38 +0900286
Andrey Smirnovd2a58842013-01-27 10:49:05 -0800287 int (*reg_read)(void *context, unsigned int reg, unsigned int *val);
288 int (*reg_write)(void *context, unsigned int reg, unsigned int val);
289
290 bool fast_io;
291
Mark Brownbd20eb52011-08-19 18:09:38 +0900292 unsigned int max_register;
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100293 const struct regmap_access_table *wr_table;
294 const struct regmap_access_table *rd_table;
295 const struct regmap_access_table *volatile_table;
296 const struct regmap_access_table *precious_table;
Lars-Peter Clausen720e4612011-11-16 16:28:17 +0100297 const struct reg_default *reg_defaults;
Dimitris Papastamos9fabe242011-09-19 14:34:00 +0100298 unsigned int num_reg_defaults;
299 enum regcache_type cache_type;
300 const void *reg_defaults_raw;
301 unsigned int num_reg_defaults_raw;
Lars-Peter Clausen6f306442011-09-05 20:46:32 +0200302
Tony Lindgrenf50e38c2016-09-15 13:56:10 -0700303 unsigned long read_flag_mask;
304 unsigned long write_flag_mask;
Ashish Jangam2e33caf2012-04-30 23:23:40 +0100305
306 bool use_single_rw;
Opensource [Anthony Olech]e894c3f2014-03-04 13:54:02 +0000307 bool can_multi_write;
Stephen Warren141eba22012-05-24 10:47:26 -0600308
309 enum regmap_endian reg_format_endian;
310 enum regmap_endian val_format_endian;
Mark Brown38e23192012-07-22 19:26:07 +0100311
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100312 const struct regmap_range_cfg *ranges;
Mark Browne3549cd2012-10-02 20:17:15 +0100313 unsigned int num_ranges;
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100314};
315
316/**
317 * Configuration for indirectly accessed or paged registers.
318 * Registers, mapped to this virtual range, are accessed in two steps:
319 * 1. page selector register update;
320 * 2. access through data window registers.
321 *
Mark Brownd058bb42012-10-03 12:40:47 +0100322 * @name: Descriptive name for diagnostics
323 *
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100324 * @range_min: Address of the lowest register address in virtual range.
325 * @range_max: Address of the highest register in virtual range.
326 *
327 * @page_sel_reg: Register with selector field.
328 * @page_sel_mask: Bit shift for selector value.
329 * @page_sel_shift: Bit mask for selector value.
330 *
331 * @window_start: Address of first (lowest) register in data window.
332 * @window_len: Number of registers in data window.
333 */
334struct regmap_range_cfg {
Mark Brownd058bb42012-10-03 12:40:47 +0100335 const char *name;
336
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100337 /* Registers of virtual address range */
338 unsigned int range_min;
339 unsigned int range_max;
340
341 /* Page selector for indirect addressing */
342 unsigned int selector_reg;
343 unsigned int selector_mask;
344 int selector_shift;
345
346 /* Data window (per each page) */
347 unsigned int window_start;
348 unsigned int window_len;
Mark Brownb83a3132011-05-11 19:59:58 +0200349};
350
Mark Brown0d509f22013-01-27 22:07:38 +0800351struct regmap_async;
352
Stephen Warren0135bbc2012-04-04 15:48:30 -0600353typedef int (*regmap_hw_write)(void *context, const void *data,
Mark Brownb83a3132011-05-11 19:59:58 +0200354 size_t count);
Stephen Warren0135bbc2012-04-04 15:48:30 -0600355typedef int (*regmap_hw_gather_write)(void *context,
Mark Brownb83a3132011-05-11 19:59:58 +0200356 const void *reg, size_t reg_len,
357 const void *val, size_t val_len);
Mark Brown0d509f22013-01-27 22:07:38 +0800358typedef int (*regmap_hw_async_write)(void *context,
359 const void *reg, size_t reg_len,
360 const void *val, size_t val_len,
361 struct regmap_async *async);
Stephen Warren0135bbc2012-04-04 15:48:30 -0600362typedef int (*regmap_hw_read)(void *context,
Mark Brownb83a3132011-05-11 19:59:58 +0200363 const void *reg_buf, size_t reg_size,
364 void *val_buf, size_t val_size);
Boris BREZILLON3ac17032014-04-17 11:40:11 +0200365typedef int (*regmap_hw_reg_read)(void *context, unsigned int reg,
366 unsigned int *val);
367typedef int (*regmap_hw_reg_write)(void *context, unsigned int reg,
368 unsigned int val);
Jon Ringle77792b12015-10-01 12:38:07 -0400369typedef int (*regmap_hw_reg_update_bits)(void *context, unsigned int reg,
370 unsigned int mask, unsigned int val);
Mark Brown0d509f22013-01-27 22:07:38 +0800371typedef struct regmap_async *(*regmap_hw_async_alloc)(void);
Stephen Warren0135bbc2012-04-04 15:48:30 -0600372typedef void (*regmap_hw_free_context)(void *context);
Mark Brownb83a3132011-05-11 19:59:58 +0200373
374/**
375 * Description of a hardware bus for the register map infrastructure.
376 *
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600377 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200378 * to perform locking. This field is ignored if custom lock/unlock
379 * functions are used (see fields lock/unlock of
380 * struct regmap_config).
Mark Brownb83a3132011-05-11 19:59:58 +0200381 * @write: Write operation.
382 * @gather_write: Write operation with split register/value, return -ENOTSUPP
383 * if not implemented on a given device.
Mark Brown0d509f22013-01-27 22:07:38 +0800384 * @async_write: Write operation which completes asynchronously, optional and
385 * must serialise with respect to non-async I/O.
Markus Pargmannc5f58f22015-08-21 10:26:40 +0200386 * @reg_write: Write a single register value to the given register address. This
387 * write operation has to complete when returning from the function.
Mark Brownb83a3132011-05-11 19:59:58 +0200388 * @read: Read operation. Data is returned in the buffer used to transmit
389 * data.
Markus Pargmannc5f58f22015-08-21 10:26:40 +0200390 * @reg_read: Read a single register value from a given register address.
391 * @free_context: Free context.
Mark Brown0d509f22013-01-27 22:07:38 +0800392 * @async_alloc: Allocate a regmap_async() structure.
Mark Brownb83a3132011-05-11 19:59:58 +0200393 * @read_flag_mask: Mask to be set in the top byte of the register when doing
394 * a read.
Stephen Warren141eba22012-05-24 10:47:26 -0600395 * @reg_format_endian_default: Default endianness for formatted register
396 * addresses. Used when the regmap_config specifies DEFAULT. If this is
397 * DEFAULT, BIG is assumed.
398 * @val_format_endian_default: Default endianness for formatted register
399 * values. Used when the regmap_config specifies DEFAULT. If this is
400 * DEFAULT, BIG is assumed.
Markus Pargmannadaac452015-08-30 09:33:53 +0200401 * @max_raw_read: Max raw read size that can be used on the bus.
402 * @max_raw_write: Max raw write size that can be used on the bus.
Mark Brownb83a3132011-05-11 19:59:58 +0200403 */
404struct regmap_bus {
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600405 bool fast_io;
Mark Brownb83a3132011-05-11 19:59:58 +0200406 regmap_hw_write write;
407 regmap_hw_gather_write gather_write;
Mark Brown0d509f22013-01-27 22:07:38 +0800408 regmap_hw_async_write async_write;
Boris BREZILLON3ac17032014-04-17 11:40:11 +0200409 regmap_hw_reg_write reg_write;
Jon Ringle77792b12015-10-01 12:38:07 -0400410 regmap_hw_reg_update_bits reg_update_bits;
Mark Brownb83a3132011-05-11 19:59:58 +0200411 regmap_hw_read read;
Boris BREZILLON3ac17032014-04-17 11:40:11 +0200412 regmap_hw_reg_read reg_read;
Stephen Warren0135bbc2012-04-04 15:48:30 -0600413 regmap_hw_free_context free_context;
Mark Brown0d509f22013-01-27 22:07:38 +0800414 regmap_hw_async_alloc async_alloc;
Mark Brownb83a3132011-05-11 19:59:58 +0200415 u8 read_flag_mask;
Stephen Warren141eba22012-05-24 10:47:26 -0600416 enum regmap_endian reg_format_endian_default;
417 enum regmap_endian val_format_endian_default;
Markus Pargmannadaac452015-08-30 09:33:53 +0200418 size_t max_raw_read;
419 size_t max_raw_write;
Mark Brownb83a3132011-05-11 19:59:58 +0200420};
421
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800422/*
423 * __regmap_init functions.
424 *
425 * These functions take a lock key and name parameter, and should not be called
426 * directly. Instead, use the regmap_init macros that generate a key and name
427 * for each call.
428 */
429struct regmap *__regmap_init(struct device *dev,
430 const struct regmap_bus *bus,
431 void *bus_context,
432 const struct regmap_config *config,
433 struct lock_class_key *lock_key,
434 const char *lock_name);
435struct regmap *__regmap_init_i2c(struct i2c_client *i2c,
436 const struct regmap_config *config,
437 struct lock_class_key *lock_key,
438 const char *lock_name);
439struct regmap *__regmap_init_spi(struct spi_device *dev,
440 const struct regmap_config *config,
441 struct lock_class_key *lock_key,
442 const char *lock_name);
443struct regmap *__regmap_init_spmi_base(struct spmi_device *dev,
444 const struct regmap_config *config,
445 struct lock_class_key *lock_key,
446 const char *lock_name);
447struct regmap *__regmap_init_spmi_ext(struct spmi_device *dev,
448 const struct regmap_config *config,
449 struct lock_class_key *lock_key,
450 const char *lock_name);
451struct regmap *__regmap_init_mmio_clk(struct device *dev, const char *clk_id,
452 void __iomem *regs,
453 const struct regmap_config *config,
454 struct lock_class_key *lock_key,
455 const char *lock_name);
456struct regmap *__regmap_init_ac97(struct snd_ac97 *ac97,
457 const struct regmap_config *config,
458 struct lock_class_key *lock_key,
459 const char *lock_name);
460
461struct regmap *__devm_regmap_init(struct device *dev,
462 const struct regmap_bus *bus,
463 void *bus_context,
464 const struct regmap_config *config,
465 struct lock_class_key *lock_key,
466 const char *lock_name);
467struct regmap *__devm_regmap_init_i2c(struct i2c_client *i2c,
468 const struct regmap_config *config,
469 struct lock_class_key *lock_key,
470 const char *lock_name);
471struct regmap *__devm_regmap_init_spi(struct spi_device *dev,
472 const struct regmap_config *config,
473 struct lock_class_key *lock_key,
474 const char *lock_name);
475struct regmap *__devm_regmap_init_spmi_base(struct spmi_device *dev,
476 const struct regmap_config *config,
477 struct lock_class_key *lock_key,
478 const char *lock_name);
479struct regmap *__devm_regmap_init_spmi_ext(struct spmi_device *dev,
480 const struct regmap_config *config,
481 struct lock_class_key *lock_key,
482 const char *lock_name);
483struct regmap *__devm_regmap_init_mmio_clk(struct device *dev,
484 const char *clk_id,
485 void __iomem *regs,
486 const struct regmap_config *config,
487 struct lock_class_key *lock_key,
488 const char *lock_name);
489struct regmap *__devm_regmap_init_ac97(struct snd_ac97 *ac97,
490 const struct regmap_config *config,
491 struct lock_class_key *lock_key,
492 const char *lock_name);
493
494/*
495 * Wrapper for regmap_init macros to include a unique lockdep key and name
496 * for each call. No-op if CONFIG_LOCKDEP is not set.
497 *
498 * @fn: Real function to call (in the form __[*_]regmap_init[_*])
499 * @name: Config variable name (#config in the calling macro)
500 **/
501#ifdef CONFIG_LOCKDEP
502#define __regmap_lockdep_wrapper(fn, name, ...) \
503( \
504 ({ \
505 static struct lock_class_key _key; \
506 fn(__VA_ARGS__, &_key, \
507 KBUILD_BASENAME ":" \
508 __stringify(__LINE__) ":" \
509 "(" name ")->lock"); \
510 }) \
511)
512#else
513#define __regmap_lockdep_wrapper(fn, name, ...) fn(__VA_ARGS__, NULL, NULL)
514#endif
515
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800516/**
517 * regmap_init(): Initialise register map
518 *
519 * @dev: Device that will be interacted with
520 * @bus: Bus-specific callbacks to use with device
521 * @bus_context: Data passed to bus-specific callbacks
522 * @config: Configuration for register map
523 *
524 * The return value will be an ERR_PTR() on error or a valid pointer to
525 * a struct regmap. This function should generally not be called
526 * directly, it should be called by bus-specific init functions.
527 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800528#define regmap_init(dev, bus, bus_context, config) \
529 __regmap_lockdep_wrapper(__regmap_init, #config, \
530 dev, bus, bus_context, config)
Michal Simek6cfec042014-02-10 16:22:33 +0100531int regmap_attach_dev(struct device *dev, struct regmap *map,
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800532 const struct regmap_config *config);
Mark Browna676f082011-05-12 11:42:10 +0200533
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800534/**
535 * regmap_init_i2c(): Initialise register map
536 *
537 * @i2c: Device that will be interacted with
538 * @config: Configuration for register map
539 *
540 * The return value will be an ERR_PTR() on error or a valid pointer to
541 * a struct regmap.
542 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800543#define regmap_init_i2c(i2c, config) \
544 __regmap_lockdep_wrapper(__regmap_init_i2c, #config, \
545 i2c, config)
Mark Brown22853222014-11-18 19:45:51 +0100546
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800547/**
548 * regmap_init_spi(): Initialise register map
549 *
550 * @spi: Device that will be interacted with
551 * @config: Configuration for register map
552 *
553 * The return value will be an ERR_PTR() on error or a valid pointer to
554 * a struct regmap.
555 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800556#define regmap_init_spi(dev, config) \
557 __regmap_lockdep_wrapper(__regmap_init_spi, #config, \
558 dev, config)
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800559
560/**
561 * regmap_init_spmi_base(): Create regmap for the Base register space
562 * @sdev: SPMI device that will be interacted with
563 * @config: Configuration for register map
564 *
565 * The return value will be an ERR_PTR() on error or a valid pointer to
566 * a struct regmap.
567 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800568#define regmap_init_spmi_base(dev, config) \
569 __regmap_lockdep_wrapper(__regmap_init_spmi_base, #config, \
570 dev, config)
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800571
572/**
573 * regmap_init_spmi_ext(): Create regmap for Ext register space
574 * @sdev: Device that will be interacted with
575 * @config: Configuration for register map
576 *
577 * The return value will be an ERR_PTR() on error or a valid pointer to
578 * a struct regmap.
579 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800580#define regmap_init_spmi_ext(dev, config) \
581 __regmap_lockdep_wrapper(__regmap_init_spmi_ext, #config, \
582 dev, config)
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800583
584/**
585 * regmap_init_mmio_clk(): Initialise register map with register clock
586 *
587 * @dev: Device that will be interacted with
588 * @clk_id: register clock consumer ID
589 * @regs: Pointer to memory-mapped IO region
590 * @config: Configuration for register map
591 *
592 * The return value will be an ERR_PTR() on error or a valid pointer to
593 * a struct regmap.
594 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800595#define regmap_init_mmio_clk(dev, clk_id, regs, config) \
596 __regmap_lockdep_wrapper(__regmap_init_mmio_clk, #config, \
597 dev, clk_id, regs, config)
Philipp Zabel878ec672013-02-14 17:39:08 +0100598
599/**
600 * regmap_init_mmio(): Initialise register map
601 *
602 * @dev: Device that will be interacted with
603 * @regs: Pointer to memory-mapped IO region
604 * @config: Configuration for register map
605 *
606 * The return value will be an ERR_PTR() on error or a valid pointer to
607 * a struct regmap.
608 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800609#define regmap_init_mmio(dev, regs, config) \
610 regmap_init_mmio_clk(dev, NULL, regs, config)
Philipp Zabel878ec672013-02-14 17:39:08 +0100611
612/**
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800613 * regmap_init_ac97(): Initialise AC'97 register map
614 *
615 * @ac97: Device that will be interacted with
616 * @config: Configuration for register map
617 *
618 * The return value will be an ERR_PTR() on error or a valid pointer to
619 * a struct regmap.
620 */
621#define regmap_init_ac97(ac97, config) \
622 __regmap_lockdep_wrapper(__regmap_init_ac97, #config, \
623 ac97, config)
624bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg);
625
626/**
627 * devm_regmap_init(): Initialise managed register map
628 *
629 * @dev: Device that will be interacted with
630 * @bus: Bus-specific callbacks to use with device
631 * @bus_context: Data passed to bus-specific callbacks
632 * @config: Configuration for register map
633 *
634 * The return value will be an ERR_PTR() on error or a valid pointer
635 * to a struct regmap. This function should generally not be called
636 * directly, it should be called by bus-specific init functions. The
637 * map will be automatically freed by the device management code.
638 */
639#define devm_regmap_init(dev, bus, bus_context, config) \
640 __regmap_lockdep_wrapper(__devm_regmap_init, #config, \
641 dev, bus, bus_context, config)
642
643/**
644 * devm_regmap_init_i2c(): Initialise managed register map
645 *
646 * @i2c: Device that will be interacted with
647 * @config: Configuration for register map
648 *
649 * The return value will be an ERR_PTR() on error or a valid pointer
650 * to a struct regmap. The regmap will be automatically freed by the
651 * device management code.
652 */
653#define devm_regmap_init_i2c(i2c, config) \
654 __regmap_lockdep_wrapper(__devm_regmap_init_i2c, #config, \
655 i2c, config)
656
657/**
658 * devm_regmap_init_spi(): Initialise register map
659 *
660 * @spi: Device that will be interacted with
661 * @config: Configuration for register map
662 *
663 * The return value will be an ERR_PTR() on error or a valid pointer
664 * to a struct regmap. The map will be automatically freed by the
665 * device management code.
666 */
667#define devm_regmap_init_spi(dev, config) \
668 __regmap_lockdep_wrapper(__devm_regmap_init_spi, #config, \
669 dev, config)
670
671/**
672 * devm_regmap_init_spmi_base(): Create managed regmap for Base register space
673 * @sdev: SPMI device that will be interacted with
674 * @config: Configuration for register map
675 *
676 * The return value will be an ERR_PTR() on error or a valid pointer
677 * to a struct regmap. The regmap will be automatically freed by the
678 * device management code.
679 */
680#define devm_regmap_init_spmi_base(dev, config) \
681 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_base, #config, \
682 dev, config)
683
684/**
685 * devm_regmap_init_spmi_ext(): Create managed regmap for Ext register space
686 * @sdev: SPMI device that will be interacted with
687 * @config: Configuration for register map
688 *
689 * The return value will be an ERR_PTR() on error or a valid pointer
690 * to a struct regmap. The regmap will be automatically freed by the
691 * device management code.
692 */
693#define devm_regmap_init_spmi_ext(dev, config) \
694 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_ext, #config, \
695 dev, config)
696
697/**
698 * devm_regmap_init_mmio_clk(): Initialise managed register map with clock
699 *
700 * @dev: Device that will be interacted with
701 * @clk_id: register clock consumer ID
702 * @regs: Pointer to memory-mapped IO region
703 * @config: Configuration for register map
704 *
705 * The return value will be an ERR_PTR() on error or a valid pointer
706 * to a struct regmap. The regmap will be automatically freed by the
707 * device management code.
708 */
709#define devm_regmap_init_mmio_clk(dev, clk_id, regs, config) \
710 __regmap_lockdep_wrapper(__devm_regmap_init_mmio_clk, #config, \
711 dev, clk_id, regs, config)
Philipp Zabel878ec672013-02-14 17:39:08 +0100712
713/**
714 * devm_regmap_init_mmio(): Initialise managed register map
715 *
716 * @dev: Device that will be interacted with
717 * @regs: Pointer to memory-mapped IO region
718 * @config: Configuration for register map
719 *
720 * The return value will be an ERR_PTR() on error or a valid pointer
721 * to a struct regmap. The regmap will be automatically freed by the
722 * device management code.
723 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800724#define devm_regmap_init_mmio(dev, regs, config) \
725 devm_regmap_init_mmio_clk(dev, NULL, regs, config)
Mark Brownc0eb4672012-01-30 19:56:52 +0000726
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800727/**
728 * devm_regmap_init_ac97(): Initialise AC'97 register map
729 *
730 * @ac97: Device that will be interacted with
731 * @config: Configuration for register map
732 *
733 * The return value will be an ERR_PTR() on error or a valid pointer
734 * to a struct regmap. The regmap will be automatically freed by the
735 * device management code.
736 */
737#define devm_regmap_init_ac97(ac97, config) \
738 __regmap_lockdep_wrapper(__devm_regmap_init_ac97, #config, \
739 ac97, config)
Mark Brownb83a3132011-05-11 19:59:58 +0200740
741void regmap_exit(struct regmap *map);
742int regmap_reinit_cache(struct regmap *map,
743 const struct regmap_config *config);
Mark Brown72b39f62012-05-08 17:44:40 +0100744struct regmap *dev_get_regmap(struct device *dev, const char *name);
Tuomas Tynkkynen8d7d3972014-07-21 18:38:47 +0300745struct device *regmap_get_device(struct regmap *map);
Mark Brownb83a3132011-05-11 19:59:58 +0200746int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
Mark Brown915f4412013-10-09 13:30:10 +0100747int regmap_write_async(struct regmap *map, unsigned int reg, unsigned int val);
Mark Brownb83a3132011-05-11 19:59:58 +0200748int regmap_raw_write(struct regmap *map, unsigned int reg,
749 const void *val, size_t val_len);
Laxman Dewangan8eaeb212012-02-12 19:49:43 +0530750int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
751 size_t val_count);
Nariman Poushin8019ff62015-07-16 16:36:21 +0100752int regmap_multi_reg_write(struct regmap *map, const struct reg_sequence *regs,
Anthony Oleche33fabd2013-10-11 15:31:11 +0100753 int num_regs);
Charles Keepax1d5b40b2014-02-25 13:45:50 +0000754int regmap_multi_reg_write_bypassed(struct regmap *map,
Nariman Poushin8019ff62015-07-16 16:36:21 +0100755 const struct reg_sequence *regs,
Charles Keepax1d5b40b2014-02-25 13:45:50 +0000756 int num_regs);
Mark Brown0d509f22013-01-27 22:07:38 +0800757int regmap_raw_write_async(struct regmap *map, unsigned int reg,
758 const void *val, size_t val_len);
Mark Brownb83a3132011-05-11 19:59:58 +0200759int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
760int regmap_raw_read(struct regmap *map, unsigned int reg,
761 void *val, size_t val_len);
762int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
763 size_t val_count);
Kuninori Morimoto91d31b92016-02-15 05:22:18 +0000764int regmap_update_bits_base(struct regmap *map, unsigned int reg,
765 unsigned int mask, unsigned int val,
766 bool *change, bool async, bool force);
Mark Browna6539c32012-02-17 14:20:14 -0800767int regmap_get_val_bytes(struct regmap *map);
Srinivas Kandagatla668abc72015-05-21 17:42:43 +0100768int regmap_get_max_register(struct regmap *map);
Srinivas Kandagatlaa2f776c2015-05-21 17:42:54 +0100769int regmap_get_reg_stride(struct regmap *map);
Mark Brown0d509f22013-01-27 22:07:38 +0800770int regmap_async_complete(struct regmap *map);
Mark Brown221ad7f2013-03-26 21:24:20 +0000771bool regmap_can_raw_write(struct regmap *map);
Markus Pargmannf50c9eb2015-08-30 09:33:54 +0200772size_t regmap_get_raw_read_max(struct regmap *map);
773size_t regmap_get_raw_write_max(struct regmap *map);
Mark Brownb83a3132011-05-11 19:59:58 +0200774
Mark Brown39a58432011-09-19 18:21:49 +0100775int regcache_sync(struct regmap *map);
Mark Brown4d4cfd12012-02-23 20:53:37 +0000776int regcache_sync_region(struct regmap *map, unsigned int min,
777 unsigned int max);
Mark Brown697e85b2013-05-08 13:55:22 +0100778int regcache_drop_region(struct regmap *map, unsigned int min,
779 unsigned int max);
Mark Brown92afb282011-09-19 18:22:14 +0100780void regcache_cache_only(struct regmap *map, bool enable);
Dimitris Papastamos6eb0f5e2011-09-29 14:36:27 +0100781void regcache_cache_bypass(struct regmap *map, bool enable);
Mark Brown8ae0d7e2011-10-26 10:34:22 +0200782void regcache_mark_dirty(struct regmap *map);
Mark Brown92afb282011-09-19 18:22:14 +0100783
Mark Brown154881e2013-05-08 13:55:23 +0100784bool regmap_check_range_table(struct regmap *map, unsigned int reg,
785 const struct regmap_access_table *table);
786
Nariman Poushin8019ff62015-07-16 16:36:21 +0100787int regmap_register_patch(struct regmap *map, const struct reg_sequence *regs,
Mark Brown22f0d902012-01-21 12:01:14 +0000788 int num_regs);
Nenghua Cao13ff50c2014-02-19 18:44:13 +0800789int regmap_parse_val(struct regmap *map, const void *buf,
790 unsigned int *val);
Mark Brown22f0d902012-01-21 12:01:14 +0000791
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100792static inline bool regmap_reg_in_range(unsigned int reg,
793 const struct regmap_range *range)
794{
795 return reg >= range->range_min && reg <= range->range_max;
796}
797
798bool regmap_reg_in_ranges(unsigned int reg,
799 const struct regmap_range *ranges,
800 unsigned int nranges);
801
Mark Brownf8beab22011-10-28 23:50:49 +0200802/**
Srinivas Kandagatla67252282013-06-11 13:18:15 +0100803 * Description of an register field
804 *
805 * @reg: Offset of the register within the regmap bank
806 * @lsb: lsb of the register field.
Bintian Wangf27b37f2015-01-27 20:50:29 +0800807 * @msb: msb of the register field.
Kuninori Morimotoa0102372013-09-01 20:30:50 -0700808 * @id_size: port size if it has some ports
809 * @id_offset: address offset for each ports
Srinivas Kandagatla67252282013-06-11 13:18:15 +0100810 */
811struct reg_field {
812 unsigned int reg;
813 unsigned int lsb;
814 unsigned int msb;
Kuninori Morimotoa0102372013-09-01 20:30:50 -0700815 unsigned int id_size;
816 unsigned int id_offset;
Srinivas Kandagatla67252282013-06-11 13:18:15 +0100817};
818
819#define REG_FIELD(_reg, _lsb, _msb) { \
820 .reg = _reg, \
821 .lsb = _lsb, \
822 .msb = _msb, \
823 }
824
825struct regmap_field *regmap_field_alloc(struct regmap *regmap,
826 struct reg_field reg_field);
827void regmap_field_free(struct regmap_field *field);
828
829struct regmap_field *devm_regmap_field_alloc(struct device *dev,
830 struct regmap *regmap, struct reg_field reg_field);
831void devm_regmap_field_free(struct device *dev, struct regmap_field *field);
832
833int regmap_field_read(struct regmap_field *field, unsigned int *val);
Kuninori Morimoto28972ea2016-02-15 05:23:55 +0000834int regmap_field_update_bits_base(struct regmap_field *field,
835 unsigned int mask, unsigned int val,
836 bool *change, bool async, bool force);
Kuninori Morimotoa0102372013-09-01 20:30:50 -0700837int regmap_fields_read(struct regmap_field *field, unsigned int id,
838 unsigned int *val);
Kuninori Morimotoe126ede2016-02-15 05:24:51 +0000839int regmap_fields_update_bits_base(struct regmap_field *field, unsigned int id,
840 unsigned int mask, unsigned int val,
841 bool *change, bool async, bool force);
Srinivas Kandagatla67252282013-06-11 13:18:15 +0100842
843/**
Mark Brownf8beab22011-10-28 23:50:49 +0200844 * Description of an IRQ for the generic regmap irq_chip.
845 *
846 * @reg_offset: Offset of the status/mask register within the bank
847 * @mask: Mask used to flag/control the register.
Laxman Dewangan7a78479f2015-12-22 18:25:26 +0530848 * @type_reg_offset: Offset register for the irq type setting.
849 * @type_rising_mask: Mask bit to configure RISING type irq.
850 * @type_falling_mask: Mask bit to configure FALLING type irq.
Mark Brownf8beab22011-10-28 23:50:49 +0200851 */
852struct regmap_irq {
853 unsigned int reg_offset;
854 unsigned int mask;
Laxman Dewangan7a78479f2015-12-22 18:25:26 +0530855 unsigned int type_reg_offset;
856 unsigned int type_rising_mask;
857 unsigned int type_falling_mask;
Mark Brownf8beab22011-10-28 23:50:49 +0200858};
859
Qipeng Zhab4fe8ba2015-09-15 00:39:17 +0800860#define REGMAP_IRQ_REG(_irq, _off, _mask) \
861 [_irq] = { .reg_offset = (_off), .mask = (_mask) }
862
Mark Brownf8beab22011-10-28 23:50:49 +0200863/**
864 * Description of a generic regmap irq_chip. This is not intended to
865 * handle every possible interrupt controller, but it should handle a
866 * substantial proportion of those that are found in the wild.
867 *
868 * @name: Descriptive name for IRQ controller.
869 *
870 * @status_base: Base status register address.
871 * @mask_base: Base mask register address.
Guo Zeng7b7d1962015-09-17 05:23:20 +0000872 * @unmask_base: Base unmask register address. for chips who have
873 * separate mask and unmask registers
Alexander Shiyand3233432013-12-15 13:36:51 +0400874 * @ack_base: Base ack address. If zero then the chip is clear on read.
875 * Using zero value is possible with @use_ack bit.
Mark Browna43fd502012-06-05 14:34:03 +0100876 * @wake_base: Base address for wake enables. If zero unsupported.
Laxman Dewangan7a78479f2015-12-22 18:25:26 +0530877 * @type_base: Base address for irq type. If zero unsupported.
Graeme Gregory022f926a2012-05-14 22:40:43 +0900878 * @irq_reg_stride: Stride to use for chips where registers are not contiguous.
Philipp Zabel2753e6f2013-07-22 17:15:52 +0200879 * @init_ack_masked: Ack all masked interrupts once during initalization.
Philipp Zabel68622bd2013-07-24 10:26:48 +0200880 * @mask_invert: Inverted mask register: cleared bits are masked out.
Alexander Shiyand3233432013-12-15 13:36:51 +0400881 * @use_ack: Use @ack register even if it is zero.
Guo Zenga650fdd2015-09-17 05:23:21 +0000882 * @ack_invert: Inverted ack register: cleared bits for ack.
Philipp Zabel68622bd2013-07-24 10:26:48 +0200883 * @wake_invert: Inverted wake register: cleared bits are wake enabled.
Laxman Dewangan7a78479f2015-12-22 18:25:26 +0530884 * @type_invert: Invert the type flags.
Mark Brown0c00c502012-07-24 15:41:19 +0100885 * @runtime_pm: Hold a runtime PM lock on the device when accessing it.
Mark Brownf8beab22011-10-28 23:50:49 +0200886 *
887 * @num_regs: Number of registers in each control bank.
888 * @irqs: Descriptors for individual IRQs. Interrupt numbers are
889 * assigned based on the index in the array of the interrupt.
890 * @num_irqs: Number of descriptors.
Laxman Dewangan7a78479f2015-12-22 18:25:26 +0530891 * @num_type_reg: Number of type registers.
892 * @type_reg_stride: Stride to use for chips where type registers are not
893 * contiguous.
Laxman Dewanganccc12562016-05-20 20:40:26 +0530894 * @handle_pre_irq: Driver specific callback to handle interrupt from device
895 * before regmap_irq_handler process the interrupts.
896 * @handle_post_irq: Driver specific callback to handle interrupt from device
897 * after handling the interrupts in regmap_irq_handler().
898 * @irq_drv_data: Driver specific IRQ data which is passed as parameter when
899 * driver specific pre/post interrupt handler is called.
Mark Brownf8beab22011-10-28 23:50:49 +0200900 */
901struct regmap_irq_chip {
902 const char *name;
903
904 unsigned int status_base;
905 unsigned int mask_base;
Guo Zeng7b7d1962015-09-17 05:23:20 +0000906 unsigned int unmask_base;
Mark Brownf8beab22011-10-28 23:50:49 +0200907 unsigned int ack_base;
Mark Browna43fd502012-06-05 14:34:03 +0100908 unsigned int wake_base;
Laxman Dewangan7a78479f2015-12-22 18:25:26 +0530909 unsigned int type_base;
Graeme Gregory022f926a2012-05-14 22:40:43 +0900910 unsigned int irq_reg_stride;
Philipp Zabelf484f7a2013-07-24 10:26:42 +0200911 bool init_ack_masked:1;
912 bool mask_invert:1;
Alexander Shiyand3233432013-12-15 13:36:51 +0400913 bool use_ack:1;
Guo Zenga650fdd2015-09-17 05:23:21 +0000914 bool ack_invert:1;
Philipp Zabelf484f7a2013-07-24 10:26:42 +0200915 bool wake_invert:1;
916 bool runtime_pm:1;
Laxman Dewangan7a78479f2015-12-22 18:25:26 +0530917 bool type_invert:1;
Mark Brownf8beab22011-10-28 23:50:49 +0200918
919 int num_regs;
920
921 const struct regmap_irq *irqs;
922 int num_irqs;
Laxman Dewangan7a78479f2015-12-22 18:25:26 +0530923
924 int num_type_reg;
925 unsigned int type_reg_stride;
Laxman Dewanganccc12562016-05-20 20:40:26 +0530926
927 int (*handle_pre_irq)(void *irq_drv_data);
928 int (*handle_post_irq)(void *irq_drv_data);
929 void *irq_drv_data;
Mark Brownf8beab22011-10-28 23:50:49 +0200930};
931
932struct regmap_irq_chip_data;
933
934int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
Mark Brownb026ddb2012-05-31 21:01:46 +0100935 int irq_base, const struct regmap_irq_chip *chip,
Mark Brownf8beab22011-10-28 23:50:49 +0200936 struct regmap_irq_chip_data **data);
937void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data);
Laxman Dewangan045b9842016-02-10 14:29:50 +0530938
939int devm_regmap_add_irq_chip(struct device *dev, struct regmap *map, int irq,
940 int irq_flags, int irq_base,
941 const struct regmap_irq_chip *chip,
942 struct regmap_irq_chip_data **data);
943void devm_regmap_del_irq_chip(struct device *dev, int irq,
944 struct regmap_irq_chip_data *data);
945
Mark Brown209a6002011-12-05 16:10:15 +0000946int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data);
Mark Brown4af8be62012-05-13 10:59:56 +0100947int regmap_irq_get_virq(struct regmap_irq_chip_data *data, int irq);
Mark Brown90f790d2012-08-20 21:45:05 +0100948struct irq_domain *regmap_irq_get_domain(struct regmap_irq_chip_data *data);
Mark Brownb83a3132011-05-11 19:59:58 +0200949
Mark Brown9cde5fc2012-02-17 14:49:51 -0800950#else
951
952/*
953 * These stubs should only ever be called by generic code which has
954 * regmap based facilities, if they ever get called at runtime
955 * something is going wrong and something probably needs to select
956 * REGMAP.
957 */
958
959static inline int regmap_write(struct regmap *map, unsigned int reg,
960 unsigned int val)
961{
962 WARN_ONCE(1, "regmap API is disabled");
963 return -EINVAL;
964}
965
Mark Brown915f4412013-10-09 13:30:10 +0100966static inline int regmap_write_async(struct regmap *map, unsigned int reg,
967 unsigned int val)
968{
969 WARN_ONCE(1, "regmap API is disabled");
970 return -EINVAL;
971}
972
Mark Brown9cde5fc2012-02-17 14:49:51 -0800973static inline int regmap_raw_write(struct regmap *map, unsigned int reg,
974 const void *val, size_t val_len)
975{
976 WARN_ONCE(1, "regmap API is disabled");
977 return -EINVAL;
978}
979
Mark Brown0d509f22013-01-27 22:07:38 +0800980static inline int regmap_raw_write_async(struct regmap *map, unsigned int reg,
981 const void *val, size_t val_len)
982{
983 WARN_ONCE(1, "regmap API is disabled");
984 return -EINVAL;
985}
986
Mark Brown9cde5fc2012-02-17 14:49:51 -0800987static inline int regmap_bulk_write(struct regmap *map, unsigned int reg,
988 const void *val, size_t val_count)
989{
990 WARN_ONCE(1, "regmap API is disabled");
991 return -EINVAL;
992}
993
994static inline int regmap_read(struct regmap *map, unsigned int reg,
995 unsigned int *val)
996{
997 WARN_ONCE(1, "regmap API is disabled");
998 return -EINVAL;
999}
1000
1001static inline int regmap_raw_read(struct regmap *map, unsigned int reg,
1002 void *val, size_t val_len)
1003{
1004 WARN_ONCE(1, "regmap API is disabled");
1005 return -EINVAL;
1006}
1007
1008static inline int regmap_bulk_read(struct regmap *map, unsigned int reg,
1009 void *val, size_t val_count)
1010{
1011 WARN_ONCE(1, "regmap API is disabled");
1012 return -EINVAL;
1013}
1014
Kuninori Morimoto91d31b92016-02-15 05:22:18 +00001015static inline int regmap_update_bits_base(struct regmap *map, unsigned int reg,
1016 unsigned int mask, unsigned int val,
1017 bool *change, bool async, bool force)
Mark Brown9cde5fc2012-02-17 14:49:51 -08001018{
1019 WARN_ONCE(1, "regmap API is disabled");
1020 return -EINVAL;
1021}
1022
Kuninori Morimoto28972ea2016-02-15 05:23:55 +00001023static inline int regmap_field_update_bits_base(struct regmap_field *field,
1024 unsigned int mask, unsigned int val,
1025 bool *change, bool async, bool force)
Kuninori Morimotofd4b7286c2015-06-16 08:52:39 +00001026{
1027 WARN_ONCE(1, "regmap API is disabled");
1028 return -EINVAL;
1029}
1030
Kuninori Morimotoe126ede2016-02-15 05:24:51 +00001031static inline int regmap_fields_update_bits_base(struct regmap_field *field,
1032 unsigned int id,
1033 unsigned int mask, unsigned int val,
1034 bool *change, bool async, bool force)
Mark Brown915f4412013-10-09 13:30:10 +01001035{
1036 WARN_ONCE(1, "regmap API is disabled");
1037 return -EINVAL;
1038}
1039
Mark Brown9cde5fc2012-02-17 14:49:51 -08001040static inline int regmap_get_val_bytes(struct regmap *map)
1041{
1042 WARN_ONCE(1, "regmap API is disabled");
1043 return -EINVAL;
1044}
1045
Srinivas Kandagatla668abc72015-05-21 17:42:43 +01001046static inline int regmap_get_max_register(struct regmap *map)
1047{
1048 WARN_ONCE(1, "regmap API is disabled");
1049 return -EINVAL;
1050}
1051
Srinivas Kandagatlaa2f776c2015-05-21 17:42:54 +01001052static inline int regmap_get_reg_stride(struct regmap *map)
1053{
1054 WARN_ONCE(1, "regmap API is disabled");
1055 return -EINVAL;
1056}
1057
Mark Brown9cde5fc2012-02-17 14:49:51 -08001058static inline int regcache_sync(struct regmap *map)
1059{
1060 WARN_ONCE(1, "regmap API is disabled");
1061 return -EINVAL;
1062}
1063
Mark Browna313f9f2012-02-23 19:49:43 +00001064static inline int regcache_sync_region(struct regmap *map, unsigned int min,
1065 unsigned int max)
1066{
1067 WARN_ONCE(1, "regmap API is disabled");
1068 return -EINVAL;
1069}
1070
Mark Brown697e85b2013-05-08 13:55:22 +01001071static inline int regcache_drop_region(struct regmap *map, unsigned int min,
1072 unsigned int max)
1073{
1074 WARN_ONCE(1, "regmap API is disabled");
1075 return -EINVAL;
1076}
1077
Mark Brown9cde5fc2012-02-17 14:49:51 -08001078static inline void regcache_cache_only(struct regmap *map, bool enable)
1079{
1080 WARN_ONCE(1, "regmap API is disabled");
1081}
1082
1083static inline void regcache_cache_bypass(struct regmap *map, bool enable)
1084{
1085 WARN_ONCE(1, "regmap API is disabled");
1086}
1087
1088static inline void regcache_mark_dirty(struct regmap *map)
1089{
1090 WARN_ONCE(1, "regmap API is disabled");
1091}
1092
Mark Brown0d509f22013-01-27 22:07:38 +08001093static inline void regmap_async_complete(struct regmap *map)
1094{
1095 WARN_ONCE(1, "regmap API is disabled");
1096}
1097
Mark Brown9cde5fc2012-02-17 14:49:51 -08001098static inline int regmap_register_patch(struct regmap *map,
Daniel Wagnera6baa3d2015-11-30 16:20:15 +01001099 const struct reg_sequence *regs,
Mark Brown9cde5fc2012-02-17 14:49:51 -08001100 int num_regs)
1101{
1102 WARN_ONCE(1, "regmap API is disabled");
1103 return -EINVAL;
1104}
1105
Nenghua Cao13ff50c2014-02-19 18:44:13 +08001106static inline int regmap_parse_val(struct regmap *map, const void *buf,
1107 unsigned int *val)
1108{
1109 WARN_ONCE(1, "regmap API is disabled");
1110 return -EINVAL;
1111}
1112
Mark Brown72b39f62012-05-08 17:44:40 +01001113static inline struct regmap *dev_get_regmap(struct device *dev,
1114 const char *name)
1115{
Mark Brown72b39f62012-05-08 17:44:40 +01001116 return NULL;
1117}
1118
Tuomas Tynkkynen8d7d3972014-07-21 18:38:47 +03001119static inline struct device *regmap_get_device(struct regmap *map)
1120{
1121 WARN_ONCE(1, "regmap API is disabled");
Mark Brown1d33dc62014-07-25 19:01:53 +01001122 return NULL;
Tuomas Tynkkynen8d7d3972014-07-21 18:38:47 +03001123}
1124
Mark Brown9cde5fc2012-02-17 14:49:51 -08001125#endif
1126
Mark Brownb83a3132011-05-11 19:59:58 +02001127#endif