blob: 3dc08ce15426e67eff3cd1c785544c6877603e97 [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 Morimotob8219572016-03-03 00:48:30 +000077#define regmap_write_bits(map, reg, mask, val) \
78 regmap_update_bits_base(map, reg, mask, val, NULL, false, true)
79
Kuninori Morimoto36741242016-02-15 05:24:15 +000080#define regmap_field_write(field, val) \
81 regmap_field_update_bits_base(field, ~0, val, NULL, false, false)
Kuninori Morimoto489061b2016-02-15 05:25:54 +000082#define regmap_field_force_write(field, val) \
83 regmap_field_update_bits_base(field, ~0, val, NULL, false, true)
Kuninori Morimoto721ed642016-02-15 05:24:33 +000084#define regmap_field_update_bits(field, mask, val)\
85 regmap_field_update_bits_base(field, mask, val, NULL, false, false)
Kuninori Morimoto489061b2016-02-15 05:25:54 +000086#define regmap_field_force_update_bits(field, mask, val) \
87 regmap_field_update_bits_base(field, mask, val, NULL, false, true)
Kuninori Morimoto36741242016-02-15 05:24:15 +000088
Kuninori Morimotobbf2c462016-02-15 05:25:15 +000089#define regmap_fields_write(field, id, val) \
90 regmap_fields_update_bits_base(field, id, ~0, val, NULL, false, false)
Kuninori Morimotoe6ef2432016-02-15 05:26:14 +000091#define regmap_fields_force_write(field, id, val) \
92 regmap_fields_update_bits_base(field, id, ~0, val, NULL, false, true)
Kuninori Morimoto48138602016-02-15 05:25:32 +000093#define regmap_fields_update_bits(field, id, mask, val)\
94 regmap_fields_update_bits_base(field, id, mask, val, NULL, false, false)
Kuninori Morimotoe6ef2432016-02-15 05:26:14 +000095#define regmap_fields_force_update_bits(field, id, mask, val) \
96 regmap_fields_update_bits_base(field, id, mask, val, NULL, false, true)
Kuninori Morimotobbf2c462016-02-15 05:25:15 +000097
Mark Brownb83d2ff2012-03-11 11:49:17 +000098#ifdef CONFIG_REGMAP
99
Stephen Warren141eba22012-05-24 10:47:26 -0600100enum regmap_endian {
101 /* Unspecified -> 0 -> Backwards compatible default */
102 REGMAP_ENDIAN_DEFAULT = 0,
103 REGMAP_ENDIAN_BIG,
104 REGMAP_ENDIAN_LITTLE,
105 REGMAP_ENDIAN_NATIVE,
106};
107
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100108/**
109 * A register range, used for access related checks
110 * (readable/writeable/volatile/precious checks)
111 *
112 * @range_min: address of first register
113 * @range_max: address of last register
114 */
115struct regmap_range {
116 unsigned int range_min;
117 unsigned int range_max;
118};
119
Laxman Dewangan6112fe62013-09-20 18:00:10 +0530120#define regmap_reg_range(low, high) { .range_min = low, .range_max = high, }
121
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100122/*
123 * A table of ranges including some yes ranges and some no ranges.
124 * If a register belongs to a no_range, the corresponding check function
125 * will return false. If a register belongs to a yes range, the corresponding
126 * check function will return true. "no_ranges" are searched first.
127 *
128 * @yes_ranges : pointer to an array of regmap ranges used as "yes ranges"
129 * @n_yes_ranges: size of the above array
130 * @no_ranges: pointer to an array of regmap ranges used as "no ranges"
131 * @n_no_ranges: size of the above array
132 */
133struct regmap_access_table {
134 const struct regmap_range *yes_ranges;
135 unsigned int n_yes_ranges;
136 const struct regmap_range *no_ranges;
137 unsigned int n_no_ranges;
138};
139
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200140typedef void (*regmap_lock)(void *);
141typedef void (*regmap_unlock)(void *);
142
Mark Brownbd20eb52011-08-19 18:09:38 +0900143/**
Mark Browndd898b22011-07-20 22:28:58 +0100144 * Configuration for the register map of a device.
145 *
Stephen Warrend3c242e2012-04-04 15:48:29 -0600146 * @name: Optional name of the regmap. Useful when a device has multiple
147 * register regions.
148 *
Mark Browndd898b22011-07-20 22:28:58 +0100149 * @reg_bits: Number of bits in a register address, mandatory.
Stephen Warrenf01ee602012-04-09 13:40:24 -0600150 * @reg_stride: The register address stride. Valid register addresses are a
151 * multiple of this value. If set to 0, a value of 1 will be
152 * used.
Mark Brown82159ba2012-01-18 10:52:25 +0000153 * @pad_bits: Number of bits of padding between register and value.
Mark Browndd898b22011-07-20 22:28:58 +0100154 * @val_bits: Number of bits in a register value, mandatory.
Mark Brown2e2ae662011-07-20 22:33:39 +0100155 *
Mark Brown3566cc92011-08-09 10:23:22 +0900156 * @writeable_reg: Optional callback returning true if the register
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100157 * can be written to. If this field is NULL but wr_table
158 * (see below) is not, the check is performed on such table
159 * (a register is writeable if it belongs to one of the ranges
160 * specified by wr_table).
Mark Brown3566cc92011-08-09 10:23:22 +0900161 * @readable_reg: Optional callback returning true if the register
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100162 * can be read from. If this field is NULL but rd_table
163 * (see below) is not, the check is performed on such table
164 * (a register is readable if it belongs to one of the ranges
165 * specified by rd_table).
Mark Brown3566cc92011-08-09 10:23:22 +0900166 * @volatile_reg: Optional callback returning true if the register
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100167 * value can't be cached. If this field is NULL but
168 * volatile_table (see below) is not, the check is performed on
169 * such table (a register is volatile if it belongs to one of
170 * the ranges specified by volatile_table).
Laszlo Pappbdc39642014-01-09 14:13:41 +0000171 * @precious_reg: Optional callback returning true if the register
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100172 * should not be read outside of a call from the driver
Laszlo Pappbdc39642014-01-09 14:13:41 +0000173 * (e.g., a clear on read interrupt status register). If this
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100174 * field is NULL but precious_table (see below) is not, the
175 * check is performed on such table (a register is precious if
176 * it belongs to one of the ranges specified by precious_table).
177 * @lock: Optional lock callback (overrides regmap's default lock
178 * function, based on spinlock or mutex).
179 * @unlock: As above for unlocking.
180 * @lock_arg: this field is passed as the only argument of lock/unlock
181 * functions (ignored in case regular lock/unlock functions
182 * are not overridden).
Andrey Smirnovd2a58842013-01-27 10:49:05 -0800183 * @reg_read: Optional callback that if filled will be used to perform
184 * all the reads from the registers. Should only be provided for
Laszlo Pappbdc39642014-01-09 14:13:41 +0000185 * devices whose read operation cannot be represented as a simple
186 * read operation on a bus such as SPI, I2C, etc. Most of the
187 * devices do not need this.
Andrey Smirnovd2a58842013-01-27 10:49:05 -0800188 * @reg_write: Same as above for writing.
189 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
190 * to perform locking. This field is ignored if custom lock/unlock
191 * functions are used (see fields lock/unlock of struct regmap_config).
192 * This field is a duplicate of a similar file in
193 * 'struct regmap_bus' and serves exact same purpose.
194 * Use it only for "no-bus" cases.
Stefan Agnerb429fab2016-01-19 17:14:39 -0800195 * @max_register: Optional, specifies the maximum valid register address.
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100196 * @wr_table: Optional, points to a struct regmap_access_table specifying
197 * valid ranges for write access.
198 * @rd_table: As above, for read access.
199 * @volatile_table: As above, for volatile registers.
200 * @precious_table: As above, for precious registers.
Mark Brownbd20eb52011-08-19 18:09:38 +0900201 * @reg_defaults: Power on reset values for registers (for use with
202 * register cache support).
203 * @num_reg_defaults: Number of elements in reg_defaults.
Lars-Peter Clausen6f306442011-09-05 20:46:32 +0200204 *
205 * @read_flag_mask: Mask to be set in the top byte of the register when doing
206 * a read.
207 * @write_flag_mask: Mask to be set in the top byte of the register when doing
208 * a write. If both read_flag_mask and write_flag_mask are
209 * empty the regmap_bus default masks are used.
Ashish Jangam2e33caf2012-04-30 23:23:40 +0100210 * @use_single_rw: If set, converts the bulk read and write operations into
211 * a series of single read and write operations. This is useful
212 * for device that does not support bulk read and write.
Opensource [Anthony Olech]e894c3f2014-03-04 13:54:02 +0000213 * @can_multi_write: If set, the device supports the multi write mode of bulk
214 * write operations, if clear multi write requests will be
215 * split into individual write operations
Dimitris Papastamos9fabe242011-09-19 14:34:00 +0100216 *
217 * @cache_type: The actual cache type.
218 * @reg_defaults_raw: Power on reset values for registers (for use with
219 * register cache support).
220 * @num_reg_defaults_raw: Number of elements in reg_defaults_raw.
Stephen Warren141eba22012-05-24 10:47:26 -0600221 * @reg_format_endian: Endianness for formatted register addresses. If this is
222 * DEFAULT, the @reg_format_endian_default value from the
223 * regmap bus is used.
224 * @val_format_endian: Endianness for formatted register values. If this is
225 * DEFAULT, the @reg_format_endian_default value from the
226 * regmap bus is used.
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100227 *
228 * @ranges: Array of configuration entries for virtual address ranges.
229 * @num_ranges: Number of range configuration entries.
Mark Browndd898b22011-07-20 22:28:58 +0100230 */
Mark Brownb83a3132011-05-11 19:59:58 +0200231struct regmap_config {
Stephen Warrend3c242e2012-04-04 15:48:29 -0600232 const char *name;
233
Mark Brownb83a3132011-05-11 19:59:58 +0200234 int reg_bits;
Stephen Warrenf01ee602012-04-09 13:40:24 -0600235 int reg_stride;
Mark Brown82159ba2012-01-18 10:52:25 +0000236 int pad_bits;
Mark Brownb83a3132011-05-11 19:59:58 +0200237 int val_bits;
Mark Brown2e2ae662011-07-20 22:33:39 +0100238
Mark Brown2e2ae662011-07-20 22:33:39 +0100239 bool (*writeable_reg)(struct device *dev, unsigned int reg);
240 bool (*readable_reg)(struct device *dev, unsigned int reg);
241 bool (*volatile_reg)(struct device *dev, unsigned int reg);
Mark Brown18694882011-08-08 15:40:22 +0900242 bool (*precious_reg)(struct device *dev, unsigned int reg);
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200243 regmap_lock lock;
244 regmap_unlock unlock;
245 void *lock_arg;
Mark Brownbd20eb52011-08-19 18:09:38 +0900246
Andrey Smirnovd2a58842013-01-27 10:49:05 -0800247 int (*reg_read)(void *context, unsigned int reg, unsigned int *val);
248 int (*reg_write)(void *context, unsigned int reg, unsigned int val);
249
250 bool fast_io;
251
Mark Brownbd20eb52011-08-19 18:09:38 +0900252 unsigned int max_register;
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100253 const struct regmap_access_table *wr_table;
254 const struct regmap_access_table *rd_table;
255 const struct regmap_access_table *volatile_table;
256 const struct regmap_access_table *precious_table;
Lars-Peter Clausen720e4612011-11-16 16:28:17 +0100257 const struct reg_default *reg_defaults;
Dimitris Papastamos9fabe242011-09-19 14:34:00 +0100258 unsigned int num_reg_defaults;
259 enum regcache_type cache_type;
260 const void *reg_defaults_raw;
261 unsigned int num_reg_defaults_raw;
Lars-Peter Clausen6f306442011-09-05 20:46:32 +0200262
263 u8 read_flag_mask;
264 u8 write_flag_mask;
Ashish Jangam2e33caf2012-04-30 23:23:40 +0100265
266 bool use_single_rw;
Opensource [Anthony Olech]e894c3f2014-03-04 13:54:02 +0000267 bool can_multi_write;
Stephen Warren141eba22012-05-24 10:47:26 -0600268
269 enum regmap_endian reg_format_endian;
270 enum regmap_endian val_format_endian;
Mark Brown38e23192012-07-22 19:26:07 +0100271
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100272 const struct regmap_range_cfg *ranges;
Mark Browne3549cd2012-10-02 20:17:15 +0100273 unsigned int num_ranges;
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100274};
275
276/**
277 * Configuration for indirectly accessed or paged registers.
278 * Registers, mapped to this virtual range, are accessed in two steps:
279 * 1. page selector register update;
280 * 2. access through data window registers.
281 *
Mark Brownd058bb42012-10-03 12:40:47 +0100282 * @name: Descriptive name for diagnostics
283 *
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100284 * @range_min: Address of the lowest register address in virtual range.
285 * @range_max: Address of the highest register in virtual range.
286 *
287 * @page_sel_reg: Register with selector field.
288 * @page_sel_mask: Bit shift for selector value.
289 * @page_sel_shift: Bit mask for selector value.
290 *
291 * @window_start: Address of first (lowest) register in data window.
292 * @window_len: Number of registers in data window.
293 */
294struct regmap_range_cfg {
Mark Brownd058bb42012-10-03 12:40:47 +0100295 const char *name;
296
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100297 /* Registers of virtual address range */
298 unsigned int range_min;
299 unsigned int range_max;
300
301 /* Page selector for indirect addressing */
302 unsigned int selector_reg;
303 unsigned int selector_mask;
304 int selector_shift;
305
306 /* Data window (per each page) */
307 unsigned int window_start;
308 unsigned int window_len;
Mark Brownb83a3132011-05-11 19:59:58 +0200309};
310
Mark Brown0d509f22013-01-27 22:07:38 +0800311struct regmap_async;
312
Stephen Warren0135bbc2012-04-04 15:48:30 -0600313typedef int (*regmap_hw_write)(void *context, const void *data,
Mark Brownb83a3132011-05-11 19:59:58 +0200314 size_t count);
Stephen Warren0135bbc2012-04-04 15:48:30 -0600315typedef int (*regmap_hw_gather_write)(void *context,
Mark Brownb83a3132011-05-11 19:59:58 +0200316 const void *reg, size_t reg_len,
317 const void *val, size_t val_len);
Mark Brown0d509f22013-01-27 22:07:38 +0800318typedef int (*regmap_hw_async_write)(void *context,
319 const void *reg, size_t reg_len,
320 const void *val, size_t val_len,
321 struct regmap_async *async);
Stephen Warren0135bbc2012-04-04 15:48:30 -0600322typedef int (*regmap_hw_read)(void *context,
Mark Brownb83a3132011-05-11 19:59:58 +0200323 const void *reg_buf, size_t reg_size,
324 void *val_buf, size_t val_size);
Boris BREZILLON3ac17032014-04-17 11:40:11 +0200325typedef int (*regmap_hw_reg_read)(void *context, unsigned int reg,
326 unsigned int *val);
327typedef int (*regmap_hw_reg_write)(void *context, unsigned int reg,
328 unsigned int val);
Jon Ringle77792b12015-10-01 12:38:07 -0400329typedef int (*regmap_hw_reg_update_bits)(void *context, unsigned int reg,
330 unsigned int mask, unsigned int val);
Mark Brown0d509f22013-01-27 22:07:38 +0800331typedef struct regmap_async *(*regmap_hw_async_alloc)(void);
Stephen Warren0135bbc2012-04-04 15:48:30 -0600332typedef void (*regmap_hw_free_context)(void *context);
Mark Brownb83a3132011-05-11 19:59:58 +0200333
334/**
335 * Description of a hardware bus for the register map infrastructure.
336 *
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600337 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200338 * to perform locking. This field is ignored if custom lock/unlock
339 * functions are used (see fields lock/unlock of
340 * struct regmap_config).
Mark Brownb83a3132011-05-11 19:59:58 +0200341 * @write: Write operation.
342 * @gather_write: Write operation with split register/value, return -ENOTSUPP
343 * if not implemented on a given device.
Mark Brown0d509f22013-01-27 22:07:38 +0800344 * @async_write: Write operation which completes asynchronously, optional and
345 * must serialise with respect to non-async I/O.
Markus Pargmannc5f58f22015-08-21 10:26:40 +0200346 * @reg_write: Write a single register value to the given register address. This
347 * write operation has to complete when returning from the function.
Mark Brownb83a3132011-05-11 19:59:58 +0200348 * @read: Read operation. Data is returned in the buffer used to transmit
349 * data.
Markus Pargmannc5f58f22015-08-21 10:26:40 +0200350 * @reg_read: Read a single register value from a given register address.
351 * @free_context: Free context.
Mark Brown0d509f22013-01-27 22:07:38 +0800352 * @async_alloc: Allocate a regmap_async() structure.
Mark Brownb83a3132011-05-11 19:59:58 +0200353 * @read_flag_mask: Mask to be set in the top byte of the register when doing
354 * a read.
Stephen Warren141eba22012-05-24 10:47:26 -0600355 * @reg_format_endian_default: Default endianness for formatted register
356 * addresses. Used when the regmap_config specifies DEFAULT. If this is
357 * DEFAULT, BIG is assumed.
358 * @val_format_endian_default: Default endianness for formatted register
359 * values. Used when the regmap_config specifies DEFAULT. If this is
360 * DEFAULT, BIG is assumed.
Markus Pargmannadaac452015-08-30 09:33:53 +0200361 * @max_raw_read: Max raw read size that can be used on the bus.
362 * @max_raw_write: Max raw write size that can be used on the bus.
Mark Brownb83a3132011-05-11 19:59:58 +0200363 */
364struct regmap_bus {
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600365 bool fast_io;
Mark Brownb83a3132011-05-11 19:59:58 +0200366 regmap_hw_write write;
367 regmap_hw_gather_write gather_write;
Mark Brown0d509f22013-01-27 22:07:38 +0800368 regmap_hw_async_write async_write;
Boris BREZILLON3ac17032014-04-17 11:40:11 +0200369 regmap_hw_reg_write reg_write;
Jon Ringle77792b12015-10-01 12:38:07 -0400370 regmap_hw_reg_update_bits reg_update_bits;
Mark Brownb83a3132011-05-11 19:59:58 +0200371 regmap_hw_read read;
Boris BREZILLON3ac17032014-04-17 11:40:11 +0200372 regmap_hw_reg_read reg_read;
Stephen Warren0135bbc2012-04-04 15:48:30 -0600373 regmap_hw_free_context free_context;
Mark Brown0d509f22013-01-27 22:07:38 +0800374 regmap_hw_async_alloc async_alloc;
Mark Brownb83a3132011-05-11 19:59:58 +0200375 u8 read_flag_mask;
Stephen Warren141eba22012-05-24 10:47:26 -0600376 enum regmap_endian reg_format_endian_default;
377 enum regmap_endian val_format_endian_default;
Markus Pargmannadaac452015-08-30 09:33:53 +0200378 size_t max_raw_read;
379 size_t max_raw_write;
Mark Brownb83a3132011-05-11 19:59:58 +0200380};
381
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800382/*
383 * __regmap_init functions.
384 *
385 * These functions take a lock key and name parameter, and should not be called
386 * directly. Instead, use the regmap_init macros that generate a key and name
387 * for each call.
388 */
389struct regmap *__regmap_init(struct device *dev,
390 const struct regmap_bus *bus,
391 void *bus_context,
392 const struct regmap_config *config,
393 struct lock_class_key *lock_key,
394 const char *lock_name);
395struct regmap *__regmap_init_i2c(struct i2c_client *i2c,
396 const struct regmap_config *config,
397 struct lock_class_key *lock_key,
398 const char *lock_name);
399struct regmap *__regmap_init_spi(struct spi_device *dev,
400 const struct regmap_config *config,
401 struct lock_class_key *lock_key,
402 const char *lock_name);
403struct regmap *__regmap_init_spmi_base(struct spmi_device *dev,
404 const struct regmap_config *config,
405 struct lock_class_key *lock_key,
406 const char *lock_name);
407struct regmap *__regmap_init_spmi_ext(struct spmi_device *dev,
408 const struct regmap_config *config,
409 struct lock_class_key *lock_key,
410 const char *lock_name);
411struct regmap *__regmap_init_mmio_clk(struct device *dev, const char *clk_id,
412 void __iomem *regs,
413 const struct regmap_config *config,
414 struct lock_class_key *lock_key,
415 const char *lock_name);
416struct regmap *__regmap_init_ac97(struct snd_ac97 *ac97,
417 const struct regmap_config *config,
418 struct lock_class_key *lock_key,
419 const char *lock_name);
420
421struct regmap *__devm_regmap_init(struct device *dev,
422 const struct regmap_bus *bus,
423 void *bus_context,
424 const struct regmap_config *config,
425 struct lock_class_key *lock_key,
426 const char *lock_name);
427struct regmap *__devm_regmap_init_i2c(struct i2c_client *i2c,
428 const struct regmap_config *config,
429 struct lock_class_key *lock_key,
430 const char *lock_name);
431struct regmap *__devm_regmap_init_spi(struct spi_device *dev,
432 const struct regmap_config *config,
433 struct lock_class_key *lock_key,
434 const char *lock_name);
435struct regmap *__devm_regmap_init_spmi_base(struct spmi_device *dev,
436 const struct regmap_config *config,
437 struct lock_class_key *lock_key,
438 const char *lock_name);
439struct regmap *__devm_regmap_init_spmi_ext(struct spmi_device *dev,
440 const struct regmap_config *config,
441 struct lock_class_key *lock_key,
442 const char *lock_name);
443struct regmap *__devm_regmap_init_mmio_clk(struct device *dev,
444 const char *clk_id,
445 void __iomem *regs,
446 const struct regmap_config *config,
447 struct lock_class_key *lock_key,
448 const char *lock_name);
449struct regmap *__devm_regmap_init_ac97(struct snd_ac97 *ac97,
450 const struct regmap_config *config,
451 struct lock_class_key *lock_key,
452 const char *lock_name);
453
454/*
455 * Wrapper for regmap_init macros to include a unique lockdep key and name
456 * for each call. No-op if CONFIG_LOCKDEP is not set.
457 *
458 * @fn: Real function to call (in the form __[*_]regmap_init[_*])
459 * @name: Config variable name (#config in the calling macro)
460 **/
461#ifdef CONFIG_LOCKDEP
462#define __regmap_lockdep_wrapper(fn, name, ...) \
463( \
464 ({ \
465 static struct lock_class_key _key; \
466 fn(__VA_ARGS__, &_key, \
467 KBUILD_BASENAME ":" \
468 __stringify(__LINE__) ":" \
469 "(" name ")->lock"); \
470 }) \
471)
472#else
473#define __regmap_lockdep_wrapper(fn, name, ...) fn(__VA_ARGS__, NULL, NULL)
474#endif
475
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800476/**
477 * regmap_init(): Initialise register map
478 *
479 * @dev: Device that will be interacted with
480 * @bus: Bus-specific callbacks to use with device
481 * @bus_context: Data passed to bus-specific callbacks
482 * @config: Configuration for register map
483 *
484 * The return value will be an ERR_PTR() on error or a valid pointer to
485 * a struct regmap. This function should generally not be called
486 * directly, it should be called by bus-specific init functions.
487 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800488#define regmap_init(dev, bus, bus_context, config) \
489 __regmap_lockdep_wrapper(__regmap_init, #config, \
490 dev, bus, bus_context, config)
Michal Simek6cfec042014-02-10 16:22:33 +0100491int regmap_attach_dev(struct device *dev, struct regmap *map,
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800492 const struct regmap_config *config);
Mark Browna676f082011-05-12 11:42:10 +0200493
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800494/**
495 * regmap_init_i2c(): Initialise register map
496 *
497 * @i2c: Device that will be interacted with
498 * @config: Configuration for register map
499 *
500 * The return value will be an ERR_PTR() on error or a valid pointer to
501 * a struct regmap.
502 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800503#define regmap_init_i2c(i2c, config) \
504 __regmap_lockdep_wrapper(__regmap_init_i2c, #config, \
505 i2c, config)
Mark Brown22853222014-11-18 19:45:51 +0100506
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800507/**
508 * regmap_init_spi(): Initialise register map
509 *
510 * @spi: Device that will be interacted with
511 * @config: Configuration for register map
512 *
513 * The return value will be an ERR_PTR() on error or a valid pointer to
514 * a struct regmap.
515 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800516#define regmap_init_spi(dev, config) \
517 __regmap_lockdep_wrapper(__regmap_init_spi, #config, \
518 dev, config)
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800519
520/**
521 * regmap_init_spmi_base(): Create regmap for the Base register space
522 * @sdev: SPMI device that will be interacted with
523 * @config: Configuration for register map
524 *
525 * The return value will be an ERR_PTR() on error or a valid pointer to
526 * a struct regmap.
527 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800528#define regmap_init_spmi_base(dev, config) \
529 __regmap_lockdep_wrapper(__regmap_init_spmi_base, #config, \
530 dev, config)
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800531
532/**
533 * regmap_init_spmi_ext(): Create regmap for Ext register space
534 * @sdev: Device that will be interacted with
535 * @config: Configuration for register map
536 *
537 * The return value will be an ERR_PTR() on error or a valid pointer to
538 * a struct regmap.
539 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800540#define regmap_init_spmi_ext(dev, config) \
541 __regmap_lockdep_wrapper(__regmap_init_spmi_ext, #config, \
542 dev, config)
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800543
544/**
545 * regmap_init_mmio_clk(): Initialise register map with register clock
546 *
547 * @dev: Device that will be interacted with
548 * @clk_id: register clock consumer ID
549 * @regs: Pointer to memory-mapped IO region
550 * @config: Configuration for register map
551 *
552 * The return value will be an ERR_PTR() on error or a valid pointer to
553 * a struct regmap.
554 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800555#define regmap_init_mmio_clk(dev, clk_id, regs, config) \
556 __regmap_lockdep_wrapper(__regmap_init_mmio_clk, #config, \
557 dev, clk_id, regs, config)
Philipp Zabel878ec672013-02-14 17:39:08 +0100558
559/**
560 * regmap_init_mmio(): Initialise register map
561 *
562 * @dev: Device that will be interacted with
563 * @regs: Pointer to memory-mapped IO region
564 * @config: Configuration for register map
565 *
566 * The return value will be an ERR_PTR() on error or a valid pointer to
567 * a struct regmap.
568 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800569#define regmap_init_mmio(dev, regs, config) \
570 regmap_init_mmio_clk(dev, NULL, regs, config)
Philipp Zabel878ec672013-02-14 17:39:08 +0100571
572/**
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800573 * regmap_init_ac97(): Initialise AC'97 register map
574 *
575 * @ac97: Device that will be interacted with
576 * @config: Configuration for register map
577 *
578 * The return value will be an ERR_PTR() on error or a valid pointer to
579 * a struct regmap.
580 */
581#define regmap_init_ac97(ac97, config) \
582 __regmap_lockdep_wrapper(__regmap_init_ac97, #config, \
583 ac97, config)
584bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg);
585
586/**
587 * devm_regmap_init(): Initialise managed register map
588 *
589 * @dev: Device that will be interacted with
590 * @bus: Bus-specific callbacks to use with device
591 * @bus_context: Data passed to bus-specific callbacks
592 * @config: Configuration for register map
593 *
594 * The return value will be an ERR_PTR() on error or a valid pointer
595 * to a struct regmap. This function should generally not be called
596 * directly, it should be called by bus-specific init functions. The
597 * map will be automatically freed by the device management code.
598 */
599#define devm_regmap_init(dev, bus, bus_context, config) \
600 __regmap_lockdep_wrapper(__devm_regmap_init, #config, \
601 dev, bus, bus_context, config)
602
603/**
604 * devm_regmap_init_i2c(): Initialise managed register map
605 *
606 * @i2c: Device that will be interacted with
607 * @config: Configuration for register map
608 *
609 * The return value will be an ERR_PTR() on error or a valid pointer
610 * to a struct regmap. The regmap will be automatically freed by the
611 * device management code.
612 */
613#define devm_regmap_init_i2c(i2c, config) \
614 __regmap_lockdep_wrapper(__devm_regmap_init_i2c, #config, \
615 i2c, config)
616
617/**
618 * devm_regmap_init_spi(): Initialise register map
619 *
620 * @spi: Device that will be interacted with
621 * @config: Configuration for register map
622 *
623 * The return value will be an ERR_PTR() on error or a valid pointer
624 * to a struct regmap. The map will be automatically freed by the
625 * device management code.
626 */
627#define devm_regmap_init_spi(dev, config) \
628 __regmap_lockdep_wrapper(__devm_regmap_init_spi, #config, \
629 dev, config)
630
631/**
632 * devm_regmap_init_spmi_base(): Create managed regmap for Base register space
633 * @sdev: SPMI device that will be interacted with
634 * @config: Configuration for register map
635 *
636 * The return value will be an ERR_PTR() on error or a valid pointer
637 * to a struct regmap. The regmap will be automatically freed by the
638 * device management code.
639 */
640#define devm_regmap_init_spmi_base(dev, config) \
641 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_base, #config, \
642 dev, config)
643
644/**
645 * devm_regmap_init_spmi_ext(): Create managed regmap for Ext register space
646 * @sdev: SPMI 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_spmi_ext(dev, config) \
654 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_ext, #config, \
655 dev, config)
656
657/**
658 * devm_regmap_init_mmio_clk(): Initialise managed register map with clock
659 *
660 * @dev: Device that will be interacted with
661 * @clk_id: register clock consumer ID
662 * @regs: Pointer to memory-mapped IO region
663 * @config: Configuration for register map
664 *
665 * The return value will be an ERR_PTR() on error or a valid pointer
666 * to a struct regmap. The regmap will be automatically freed by the
667 * device management code.
668 */
669#define devm_regmap_init_mmio_clk(dev, clk_id, regs, config) \
670 __regmap_lockdep_wrapper(__devm_regmap_init_mmio_clk, #config, \
671 dev, clk_id, regs, config)
Philipp Zabel878ec672013-02-14 17:39:08 +0100672
673/**
674 * devm_regmap_init_mmio(): Initialise managed register map
675 *
676 * @dev: Device that will be interacted with
677 * @regs: Pointer to memory-mapped IO region
678 * @config: Configuration for register map
679 *
680 * The return value will be an ERR_PTR() on error or a valid pointer
681 * to a struct regmap. The regmap will be automatically freed by the
682 * device management code.
683 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800684#define devm_regmap_init_mmio(dev, regs, config) \
685 devm_regmap_init_mmio_clk(dev, NULL, regs, config)
Mark Brownc0eb4672012-01-30 19:56:52 +0000686
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800687/**
688 * devm_regmap_init_ac97(): Initialise AC'97 register map
689 *
690 * @ac97: Device that will be interacted with
691 * @config: Configuration for register map
692 *
693 * The return value will be an ERR_PTR() on error or a valid pointer
694 * to a struct regmap. The regmap will be automatically freed by the
695 * device management code.
696 */
697#define devm_regmap_init_ac97(ac97, config) \
698 __regmap_lockdep_wrapper(__devm_regmap_init_ac97, #config, \
699 ac97, config)
Mark Brownb83a3132011-05-11 19:59:58 +0200700
701void regmap_exit(struct regmap *map);
702int regmap_reinit_cache(struct regmap *map,
703 const struct regmap_config *config);
Mark Brown72b39f62012-05-08 17:44:40 +0100704struct regmap *dev_get_regmap(struct device *dev, const char *name);
Tuomas Tynkkynen8d7d3972014-07-21 18:38:47 +0300705struct device *regmap_get_device(struct regmap *map);
Mark Brownb83a3132011-05-11 19:59:58 +0200706int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
Mark Brown915f4412013-10-09 13:30:10 +0100707int regmap_write_async(struct regmap *map, unsigned int reg, unsigned int val);
Mark Brownb83a3132011-05-11 19:59:58 +0200708int regmap_raw_write(struct regmap *map, unsigned int reg,
709 const void *val, size_t val_len);
Laxman Dewangan8eaeb212012-02-12 19:49:43 +0530710int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
711 size_t val_count);
Nariman Poushin8019ff62015-07-16 16:36:21 +0100712int regmap_multi_reg_write(struct regmap *map, const struct reg_sequence *regs,
Anthony Oleche33fabd2013-10-11 15:31:11 +0100713 int num_regs);
Charles Keepax1d5b40b2014-02-25 13:45:50 +0000714int regmap_multi_reg_write_bypassed(struct regmap *map,
Nariman Poushin8019ff62015-07-16 16:36:21 +0100715 const struct reg_sequence *regs,
Charles Keepax1d5b40b2014-02-25 13:45:50 +0000716 int num_regs);
Mark Brown0d509f22013-01-27 22:07:38 +0800717int regmap_raw_write_async(struct regmap *map, unsigned int reg,
718 const void *val, size_t val_len);
Mark Brownb83a3132011-05-11 19:59:58 +0200719int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
720int regmap_raw_read(struct regmap *map, unsigned int reg,
721 void *val, size_t val_len);
722int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
723 size_t val_count);
Kuninori Morimoto91d31b92016-02-15 05:22:18 +0000724int regmap_update_bits_base(struct regmap *map, unsigned int reg,
725 unsigned int mask, unsigned int val,
726 bool *change, bool async, bool force);
Mark Browna6539c32012-02-17 14:20:14 -0800727int regmap_get_val_bytes(struct regmap *map);
Srinivas Kandagatla668abc72015-05-21 17:42:43 +0100728int regmap_get_max_register(struct regmap *map);
Srinivas Kandagatlaa2f776c2015-05-21 17:42:54 +0100729int regmap_get_reg_stride(struct regmap *map);
Mark Brown0d509f22013-01-27 22:07:38 +0800730int regmap_async_complete(struct regmap *map);
Mark Brown221ad7f2013-03-26 21:24:20 +0000731bool regmap_can_raw_write(struct regmap *map);
Markus Pargmannf50c9eb2015-08-30 09:33:54 +0200732size_t regmap_get_raw_read_max(struct regmap *map);
733size_t regmap_get_raw_write_max(struct regmap *map);
Mark Brownb83a3132011-05-11 19:59:58 +0200734
Mark Brown39a58432011-09-19 18:21:49 +0100735int regcache_sync(struct regmap *map);
Mark Brown4d4cfd12012-02-23 20:53:37 +0000736int regcache_sync_region(struct regmap *map, unsigned int min,
737 unsigned int max);
Mark Brown697e85b2013-05-08 13:55:22 +0100738int regcache_drop_region(struct regmap *map, unsigned int min,
739 unsigned int max);
Mark Brown92afb282011-09-19 18:22:14 +0100740void regcache_cache_only(struct regmap *map, bool enable);
Dimitris Papastamos6eb0f5e2011-09-29 14:36:27 +0100741void regcache_cache_bypass(struct regmap *map, bool enable);
Mark Brown8ae0d7e2011-10-26 10:34:22 +0200742void regcache_mark_dirty(struct regmap *map);
Mark Brown92afb282011-09-19 18:22:14 +0100743
Mark Brown154881e2013-05-08 13:55:23 +0100744bool regmap_check_range_table(struct regmap *map, unsigned int reg,
745 const struct regmap_access_table *table);
746
Nariman Poushin8019ff62015-07-16 16:36:21 +0100747int regmap_register_patch(struct regmap *map, const struct reg_sequence *regs,
Mark Brown22f0d902012-01-21 12:01:14 +0000748 int num_regs);
Nenghua Cao13ff50c2014-02-19 18:44:13 +0800749int regmap_parse_val(struct regmap *map, const void *buf,
750 unsigned int *val);
Mark Brown22f0d902012-01-21 12:01:14 +0000751
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100752static inline bool regmap_reg_in_range(unsigned int reg,
753 const struct regmap_range *range)
754{
755 return reg >= range->range_min && reg <= range->range_max;
756}
757
758bool regmap_reg_in_ranges(unsigned int reg,
759 const struct regmap_range *ranges,
760 unsigned int nranges);
761
Mark Brownf8beab22011-10-28 23:50:49 +0200762/**
Srinivas Kandagatla67252282013-06-11 13:18:15 +0100763 * Description of an register field
764 *
765 * @reg: Offset of the register within the regmap bank
766 * @lsb: lsb of the register field.
Bintian Wangf27b37f2015-01-27 20:50:29 +0800767 * @msb: msb of the register field.
Kuninori Morimotoa0102372013-09-01 20:30:50 -0700768 * @id_size: port size if it has some ports
769 * @id_offset: address offset for each ports
Srinivas Kandagatla67252282013-06-11 13:18:15 +0100770 */
771struct reg_field {
772 unsigned int reg;
773 unsigned int lsb;
774 unsigned int msb;
Kuninori Morimotoa0102372013-09-01 20:30:50 -0700775 unsigned int id_size;
776 unsigned int id_offset;
Srinivas Kandagatla67252282013-06-11 13:18:15 +0100777};
778
779#define REG_FIELD(_reg, _lsb, _msb) { \
780 .reg = _reg, \
781 .lsb = _lsb, \
782 .msb = _msb, \
783 }
784
785struct regmap_field *regmap_field_alloc(struct regmap *regmap,
786 struct reg_field reg_field);
787void regmap_field_free(struct regmap_field *field);
788
789struct regmap_field *devm_regmap_field_alloc(struct device *dev,
790 struct regmap *regmap, struct reg_field reg_field);
791void devm_regmap_field_free(struct device *dev, struct regmap_field *field);
792
793int regmap_field_read(struct regmap_field *field, unsigned int *val);
Kuninori Morimoto28972eaa2016-02-15 05:23:55 +0000794int regmap_field_update_bits_base(struct regmap_field *field,
795 unsigned int mask, unsigned int val,
796 bool *change, bool async, bool force);
Kuninori Morimotoa0102372013-09-01 20:30:50 -0700797int regmap_fields_read(struct regmap_field *field, unsigned int id,
798 unsigned int *val);
Kuninori Morimotoe126ede2016-02-15 05:24:51 +0000799int regmap_fields_update_bits_base(struct regmap_field *field, unsigned int id,
800 unsigned int mask, unsigned int val,
801 bool *change, bool async, bool force);
Srinivas Kandagatla67252282013-06-11 13:18:15 +0100802
803/**
Mark Brownf8beab22011-10-28 23:50:49 +0200804 * Description of an IRQ for the generic regmap irq_chip.
805 *
806 * @reg_offset: Offset of the status/mask register within the bank
807 * @mask: Mask used to flag/control the register.
Laxman Dewangan7a784792015-12-22 18:25:26 +0530808 * @type_reg_offset: Offset register for the irq type setting.
809 * @type_rising_mask: Mask bit to configure RISING type irq.
810 * @type_falling_mask: Mask bit to configure FALLING type irq.
Mark Brownf8beab22011-10-28 23:50:49 +0200811 */
812struct regmap_irq {
813 unsigned int reg_offset;
814 unsigned int mask;
Laxman Dewangan7a784792015-12-22 18:25:26 +0530815 unsigned int type_reg_offset;
816 unsigned int type_rising_mask;
817 unsigned int type_falling_mask;
Mark Brownf8beab22011-10-28 23:50:49 +0200818};
819
Qipeng Zhab4fe8ba2015-09-15 00:39:17 +0800820#define REGMAP_IRQ_REG(_irq, _off, _mask) \
821 [_irq] = { .reg_offset = (_off), .mask = (_mask) }
822
Mark Brownf8beab22011-10-28 23:50:49 +0200823/**
824 * Description of a generic regmap irq_chip. This is not intended to
825 * handle every possible interrupt controller, but it should handle a
826 * substantial proportion of those that are found in the wild.
827 *
828 * @name: Descriptive name for IRQ controller.
829 *
830 * @status_base: Base status register address.
831 * @mask_base: Base mask register address.
Guo Zeng7b7d1962015-09-17 05:23:20 +0000832 * @unmask_base: Base unmask register address. for chips who have
833 * separate mask and unmask registers
Alexander Shiyand3233432013-12-15 13:36:51 +0400834 * @ack_base: Base ack address. If zero then the chip is clear on read.
835 * Using zero value is possible with @use_ack bit.
Mark Browna43fd502012-06-05 14:34:03 +0100836 * @wake_base: Base address for wake enables. If zero unsupported.
Laxman Dewangan7a784792015-12-22 18:25:26 +0530837 * @type_base: Base address for irq type. If zero unsupported.
Graeme Gregory022f926a2012-05-14 22:40:43 +0900838 * @irq_reg_stride: Stride to use for chips where registers are not contiguous.
Philipp Zabel2753e6f2013-07-22 17:15:52 +0200839 * @init_ack_masked: Ack all masked interrupts once during initalization.
Philipp Zabel68622bd2013-07-24 10:26:48 +0200840 * @mask_invert: Inverted mask register: cleared bits are masked out.
Alexander Shiyand3233432013-12-15 13:36:51 +0400841 * @use_ack: Use @ack register even if it is zero.
Guo Zenga650fdd2015-09-17 05:23:21 +0000842 * @ack_invert: Inverted ack register: cleared bits for ack.
Philipp Zabel68622bd2013-07-24 10:26:48 +0200843 * @wake_invert: Inverted wake register: cleared bits are wake enabled.
Laxman Dewangan7a784792015-12-22 18:25:26 +0530844 * @type_invert: Invert the type flags.
Mark Brown0c00c502012-07-24 15:41:19 +0100845 * @runtime_pm: Hold a runtime PM lock on the device when accessing it.
Mark Brownf8beab22011-10-28 23:50:49 +0200846 *
847 * @num_regs: Number of registers in each control bank.
848 * @irqs: Descriptors for individual IRQs. Interrupt numbers are
849 * assigned based on the index in the array of the interrupt.
850 * @num_irqs: Number of descriptors.
Laxman Dewangan7a784792015-12-22 18:25:26 +0530851 * @num_type_reg: Number of type registers.
852 * @type_reg_stride: Stride to use for chips where type registers are not
853 * contiguous.
Mark Brownf8beab22011-10-28 23:50:49 +0200854 */
855struct regmap_irq_chip {
856 const char *name;
857
858 unsigned int status_base;
859 unsigned int mask_base;
Guo Zeng7b7d1962015-09-17 05:23:20 +0000860 unsigned int unmask_base;
Mark Brownf8beab22011-10-28 23:50:49 +0200861 unsigned int ack_base;
Mark Browna43fd502012-06-05 14:34:03 +0100862 unsigned int wake_base;
Laxman Dewangan7a784792015-12-22 18:25:26 +0530863 unsigned int type_base;
Graeme Gregory022f926a2012-05-14 22:40:43 +0900864 unsigned int irq_reg_stride;
Philipp Zabelf484f7a2013-07-24 10:26:42 +0200865 bool init_ack_masked:1;
866 bool mask_invert:1;
Alexander Shiyand3233432013-12-15 13:36:51 +0400867 bool use_ack:1;
Guo Zenga650fdd2015-09-17 05:23:21 +0000868 bool ack_invert:1;
Philipp Zabelf484f7a2013-07-24 10:26:42 +0200869 bool wake_invert:1;
870 bool runtime_pm:1;
Laxman Dewangan7a784792015-12-22 18:25:26 +0530871 bool type_invert:1;
Mark Brownf8beab22011-10-28 23:50:49 +0200872
873 int num_regs;
874
875 const struct regmap_irq *irqs;
876 int num_irqs;
Laxman Dewangan7a784792015-12-22 18:25:26 +0530877
878 int num_type_reg;
879 unsigned int type_reg_stride;
Mark Brownf8beab22011-10-28 23:50:49 +0200880};
881
882struct regmap_irq_chip_data;
883
884int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
Mark Brownb026ddb2012-05-31 21:01:46 +0100885 int irq_base, const struct regmap_irq_chip *chip,
Mark Brownf8beab22011-10-28 23:50:49 +0200886 struct regmap_irq_chip_data **data);
887void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data);
Laxman Dewangan045b9842016-02-10 14:29:50 +0530888
889int devm_regmap_add_irq_chip(struct device *dev, struct regmap *map, int irq,
890 int irq_flags, int irq_base,
891 const struct regmap_irq_chip *chip,
892 struct regmap_irq_chip_data **data);
893void devm_regmap_del_irq_chip(struct device *dev, int irq,
894 struct regmap_irq_chip_data *data);
895
Mark Brown209a6002011-12-05 16:10:15 +0000896int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data);
Mark Brown4af8be62012-05-13 10:59:56 +0100897int regmap_irq_get_virq(struct regmap_irq_chip_data *data, int irq);
Mark Brown90f790d2012-08-20 21:45:05 +0100898struct irq_domain *regmap_irq_get_domain(struct regmap_irq_chip_data *data);
Mark Brownb83a3132011-05-11 19:59:58 +0200899
Mark Brown9cde5fc2012-02-17 14:49:51 -0800900#else
901
902/*
903 * These stubs should only ever be called by generic code which has
904 * regmap based facilities, if they ever get called at runtime
905 * something is going wrong and something probably needs to select
906 * REGMAP.
907 */
908
909static inline int regmap_write(struct regmap *map, unsigned int reg,
910 unsigned int val)
911{
912 WARN_ONCE(1, "regmap API is disabled");
913 return -EINVAL;
914}
915
Mark Brown915f4412013-10-09 13:30:10 +0100916static inline int regmap_write_async(struct regmap *map, unsigned int reg,
917 unsigned int val)
918{
919 WARN_ONCE(1, "regmap API is disabled");
920 return -EINVAL;
921}
922
Mark Brown9cde5fc2012-02-17 14:49:51 -0800923static inline int regmap_raw_write(struct regmap *map, unsigned int reg,
924 const void *val, size_t val_len)
925{
926 WARN_ONCE(1, "regmap API is disabled");
927 return -EINVAL;
928}
929
Mark Brown0d509f22013-01-27 22:07:38 +0800930static inline int regmap_raw_write_async(struct regmap *map, unsigned int reg,
931 const void *val, size_t val_len)
932{
933 WARN_ONCE(1, "regmap API is disabled");
934 return -EINVAL;
935}
936
Mark Brown9cde5fc2012-02-17 14:49:51 -0800937static inline int regmap_bulk_write(struct regmap *map, unsigned int reg,
938 const void *val, size_t val_count)
939{
940 WARN_ONCE(1, "regmap API is disabled");
941 return -EINVAL;
942}
943
944static inline int regmap_read(struct regmap *map, unsigned int reg,
945 unsigned int *val)
946{
947 WARN_ONCE(1, "regmap API is disabled");
948 return -EINVAL;
949}
950
951static inline int regmap_raw_read(struct regmap *map, unsigned int reg,
952 void *val, size_t val_len)
953{
954 WARN_ONCE(1, "regmap API is disabled");
955 return -EINVAL;
956}
957
958static inline int regmap_bulk_read(struct regmap *map, unsigned int reg,
959 void *val, size_t val_count)
960{
961 WARN_ONCE(1, "regmap API is disabled");
962 return -EINVAL;
963}
964
Kuninori Morimoto91d31b92016-02-15 05:22:18 +0000965static inline int regmap_update_bits_base(struct regmap *map, unsigned int reg,
966 unsigned int mask, unsigned int val,
967 bool *change, bool async, bool force)
Mark Brown9cde5fc2012-02-17 14:49:51 -0800968{
969 WARN_ONCE(1, "regmap API is disabled");
970 return -EINVAL;
971}
972
Kuninori Morimoto28972eaa2016-02-15 05:23:55 +0000973static inline int regmap_field_update_bits_base(struct regmap_field *field,
974 unsigned int mask, unsigned int val,
975 bool *change, bool async, bool force)
Kuninori Morimotofd4b7286c2015-06-16 08:52:39 +0000976{
977 WARN_ONCE(1, "regmap API is disabled");
978 return -EINVAL;
979}
980
Kuninori Morimotoe126ede2016-02-15 05:24:51 +0000981static inline int regmap_fields_update_bits_base(struct regmap_field *field,
982 unsigned int id,
983 unsigned int mask, unsigned int val,
984 bool *change, bool async, bool force)
Mark Brown915f4412013-10-09 13:30:10 +0100985{
986 WARN_ONCE(1, "regmap API is disabled");
987 return -EINVAL;
988}
989
Mark Brown9cde5fc2012-02-17 14:49:51 -0800990static inline int regmap_get_val_bytes(struct regmap *map)
991{
992 WARN_ONCE(1, "regmap API is disabled");
993 return -EINVAL;
994}
995
Srinivas Kandagatla668abc72015-05-21 17:42:43 +0100996static inline int regmap_get_max_register(struct regmap *map)
997{
998 WARN_ONCE(1, "regmap API is disabled");
999 return -EINVAL;
1000}
1001
Srinivas Kandagatlaa2f776c2015-05-21 17:42:54 +01001002static inline int regmap_get_reg_stride(struct regmap *map)
1003{
1004 WARN_ONCE(1, "regmap API is disabled");
1005 return -EINVAL;
1006}
1007
Mark Brown9cde5fc2012-02-17 14:49:51 -08001008static inline int regcache_sync(struct regmap *map)
1009{
1010 WARN_ONCE(1, "regmap API is disabled");
1011 return -EINVAL;
1012}
1013
Mark Browna313f9f2012-02-23 19:49:43 +00001014static inline int regcache_sync_region(struct regmap *map, unsigned int min,
1015 unsigned int max)
1016{
1017 WARN_ONCE(1, "regmap API is disabled");
1018 return -EINVAL;
1019}
1020
Mark Brown697e85b2013-05-08 13:55:22 +01001021static inline int regcache_drop_region(struct regmap *map, unsigned int min,
1022 unsigned int max)
1023{
1024 WARN_ONCE(1, "regmap API is disabled");
1025 return -EINVAL;
1026}
1027
Mark Brown9cde5fc2012-02-17 14:49:51 -08001028static inline void regcache_cache_only(struct regmap *map, bool enable)
1029{
1030 WARN_ONCE(1, "regmap API is disabled");
1031}
1032
1033static inline void regcache_cache_bypass(struct regmap *map, bool enable)
1034{
1035 WARN_ONCE(1, "regmap API is disabled");
1036}
1037
1038static inline void regcache_mark_dirty(struct regmap *map)
1039{
1040 WARN_ONCE(1, "regmap API is disabled");
1041}
1042
Mark Brown0d509f22013-01-27 22:07:38 +08001043static inline void regmap_async_complete(struct regmap *map)
1044{
1045 WARN_ONCE(1, "regmap API is disabled");
1046}
1047
Mark Brown9cde5fc2012-02-17 14:49:51 -08001048static inline int regmap_register_patch(struct regmap *map,
Daniel Wagnera6baa3d2015-11-30 16:20:15 +01001049 const struct reg_sequence *regs,
Mark Brown9cde5fc2012-02-17 14:49:51 -08001050 int num_regs)
1051{
1052 WARN_ONCE(1, "regmap API is disabled");
1053 return -EINVAL;
1054}
1055
Nenghua Cao13ff50c2014-02-19 18:44:13 +08001056static inline int regmap_parse_val(struct regmap *map, const void *buf,
1057 unsigned int *val)
1058{
1059 WARN_ONCE(1, "regmap API is disabled");
1060 return -EINVAL;
1061}
1062
Mark Brown72b39f62012-05-08 17:44:40 +01001063static inline struct regmap *dev_get_regmap(struct device *dev,
1064 const char *name)
1065{
Mark Brown72b39f62012-05-08 17:44:40 +01001066 return NULL;
1067}
1068
Tuomas Tynkkynen8d7d3972014-07-21 18:38:47 +03001069static inline struct device *regmap_get_device(struct regmap *map)
1070{
1071 WARN_ONCE(1, "regmap API is disabled");
Mark Brown1d33dc62014-07-25 19:01:53 +01001072 return NULL;
Tuomas Tynkkynen8d7d3972014-07-21 18:38:47 +03001073}
1074
Mark Brown9cde5fc2012-02-17 14:49:51 -08001075#endif
1076
Mark Brownb83a3132011-05-11 19:59:58 +02001077#endif