blob: 13e9ebdea1c7d23e4d71c73c51a7362411944c27 [file] [log] [blame]
Mark Brownb83a3132011-05-11 19:59:58 +02001#ifndef __LINUX_REGMAP_H
2#define __LINUX_REGMAP_H
3
4/*
5 * Register map access API
6 *
7 * Copyright 2011 Wolfson Microelectronics plc
8 *
9 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 */
15
Mark Brownb83a3132011-05-11 19:59:58 +020016#include <linux/list.h>
Krystian Garbaciak6863ca62012-06-15 11:23:56 +010017#include <linux/rbtree.h>
Mateusz Krawczuk49ccc142013-08-06 18:34:40 +020018#include <linux/err.h>
Kevin Hilman3f0fa9a2013-08-14 16:05:02 -070019#include <linux/bug.h>
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +080020#include <linux/lockdep.h>
Mark Brownb83a3132011-05-11 19:59:58 +020021
Paul Gortmakerde477252011-05-26 13:46:22 -040022struct module;
Paul Gortmaker313162d2012-01-30 11:46:54 -050023struct device;
Mark Brown9943fa32011-06-20 19:02:29 +010024struct i2c_client;
Mark Brown90f790d2012-08-20 21:45:05 +010025struct irq_domain;
Mark Browna676f082011-05-12 11:42:10 +020026struct spi_device;
Josh Cartwrighta01779f2013-10-28 13:12:35 -050027struct spmi_device;
Mark Brownb83d2ff2012-03-11 11:49:17 +000028struct regmap;
Krystian Garbaciak6863ca62012-06-15 11:23:56 +010029struct regmap_range_cfg;
Srinivas Kandagatla67252282013-06-11 13:18:15 +010030struct regmap_field;
Mark Brown22853222014-11-18 19:45:51 +010031struct snd_ac97;
Mark Brown9943fa32011-06-20 19:02:29 +010032
Dimitris Papastamos9fabe242011-09-19 14:34:00 +010033/* An enum of all the supported cache types */
34enum regcache_type {
35 REGCACHE_NONE,
Dimitris Papastamos28644c802011-09-19 14:34:02 +010036 REGCACHE_RBTREE,
Mark Brown2ac902c2012-12-19 14:51:55 +000037 REGCACHE_COMPRESSED,
38 REGCACHE_FLAT,
Dimitris Papastamos9fabe242011-09-19 14:34:00 +010039};
40
Mark Browndd898b22011-07-20 22:28:58 +010041/**
Mark Brownbd20eb52011-08-19 18:09:38 +090042 * Default value for a register. We use an array of structs rather
43 * than a simple array as many modern devices have very sparse
44 * register maps.
45 *
46 * @reg: Register address.
47 * @def: Register default value.
48 */
49struct reg_default {
50 unsigned int reg;
51 unsigned int def;
52};
53
Nariman Poushin8019ff62015-07-16 16:36:21 +010054/**
Nariman Poushin2de9d602015-07-16 16:36:22 +010055 * Register/value pairs for sequences of writes with an optional delay in
56 * microseconds to be applied after each write.
Nariman Poushin8019ff62015-07-16 16:36:21 +010057 *
58 * @reg: Register address.
59 * @def: Register value.
Nariman Poushin2de9d602015-07-16 16:36:22 +010060 * @delay_us: Delay to be applied after the register write in microseconds
Nariman Poushin8019ff62015-07-16 16:36:21 +010061 */
62struct reg_sequence {
63 unsigned int reg;
64 unsigned int def;
Nariman Poushin2de9d602015-07-16 16:36:22 +010065 unsigned int delay_us;
Nariman Poushin8019ff62015-07-16 16:36:21 +010066};
67
Kuninori Morimotoca7a9442016-02-15 05:22:42 +000068#define regmap_update_bits(map, reg, mask, val) \
69 regmap_update_bits_base(map, reg, mask, val, NULL, false, false)
Kuninori Morimoto30ed9cb2016-02-15 05:23:01 +000070#define regmap_update_bits_async(map, reg, mask, val)\
71 regmap_update_bits_base(map, reg, mask, val, NULL, true, false)
Kuninori Morimoto98c2dc42016-02-15 05:23:17 +000072#define regmap_update_bits_check(map, reg, mask, val, change)\
73 regmap_update_bits_base(map, reg, mask, val, change, false, false)
Kuninori Morimoto89d8d4b2016-02-15 05:23:37 +000074#define regmap_update_bits_check_async(map, reg, mask, val, change)\
75 regmap_update_bits_base(map, reg, mask, val, change, true, false)
Kuninori Morimotoca7a9442016-02-15 05:22:42 +000076
Kuninori Morimoto36741242016-02-15 05:24:15 +000077#define regmap_field_write(field, val) \
78 regmap_field_update_bits_base(field, ~0, val, NULL, false, false)
79
Mark Brownb83d2ff2012-03-11 11:49:17 +000080#ifdef CONFIG_REGMAP
81
Stephen Warren141eba22012-05-24 10:47:26 -060082enum regmap_endian {
83 /* Unspecified -> 0 -> Backwards compatible default */
84 REGMAP_ENDIAN_DEFAULT = 0,
85 REGMAP_ENDIAN_BIG,
86 REGMAP_ENDIAN_LITTLE,
87 REGMAP_ENDIAN_NATIVE,
88};
89
Davide Ciminaghi76aad392012-11-20 15:20:30 +010090/**
91 * A register range, used for access related checks
92 * (readable/writeable/volatile/precious checks)
93 *
94 * @range_min: address of first register
95 * @range_max: address of last register
96 */
97struct regmap_range {
98 unsigned int range_min;
99 unsigned int range_max;
100};
101
Laxman Dewangan6112fe62013-09-20 18:00:10 +0530102#define regmap_reg_range(low, high) { .range_min = low, .range_max = high, }
103
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100104/*
105 * A table of ranges including some yes ranges and some no ranges.
106 * If a register belongs to a no_range, the corresponding check function
107 * will return false. If a register belongs to a yes range, the corresponding
108 * check function will return true. "no_ranges" are searched first.
109 *
110 * @yes_ranges : pointer to an array of regmap ranges used as "yes ranges"
111 * @n_yes_ranges: size of the above array
112 * @no_ranges: pointer to an array of regmap ranges used as "no ranges"
113 * @n_no_ranges: size of the above array
114 */
115struct regmap_access_table {
116 const struct regmap_range *yes_ranges;
117 unsigned int n_yes_ranges;
118 const struct regmap_range *no_ranges;
119 unsigned int n_no_ranges;
120};
121
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200122typedef void (*regmap_lock)(void *);
123typedef void (*regmap_unlock)(void *);
124
Mark Brownbd20eb52011-08-19 18:09:38 +0900125/**
Mark Browndd898b22011-07-20 22:28:58 +0100126 * Configuration for the register map of a device.
127 *
Stephen Warrend3c242e2012-04-04 15:48:29 -0600128 * @name: Optional name of the regmap. Useful when a device has multiple
129 * register regions.
130 *
Mark Browndd898b22011-07-20 22:28:58 +0100131 * @reg_bits: Number of bits in a register address, mandatory.
Stephen Warrenf01ee602012-04-09 13:40:24 -0600132 * @reg_stride: The register address stride. Valid register addresses are a
133 * multiple of this value. If set to 0, a value of 1 will be
134 * used.
Mark Brown82159ba2012-01-18 10:52:25 +0000135 * @pad_bits: Number of bits of padding between register and value.
Mark Browndd898b22011-07-20 22:28:58 +0100136 * @val_bits: Number of bits in a register value, mandatory.
Mark Brown2e2ae662011-07-20 22:33:39 +0100137 *
Mark Brown3566cc92011-08-09 10:23:22 +0900138 * @writeable_reg: Optional callback returning true if the register
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100139 * can be written to. If this field is NULL but wr_table
140 * (see below) is not, the check is performed on such table
141 * (a register is writeable if it belongs to one of the ranges
142 * specified by wr_table).
Mark Brown3566cc92011-08-09 10:23:22 +0900143 * @readable_reg: Optional callback returning true if the register
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100144 * can be read from. If this field is NULL but rd_table
145 * (see below) is not, the check is performed on such table
146 * (a register is readable if it belongs to one of the ranges
147 * specified by rd_table).
Mark Brown3566cc92011-08-09 10:23:22 +0900148 * @volatile_reg: Optional callback returning true if the register
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100149 * value can't be cached. If this field is NULL but
150 * volatile_table (see below) is not, the check is performed on
151 * such table (a register is volatile if it belongs to one of
152 * the ranges specified by volatile_table).
Laszlo Pappbdc39642014-01-09 14:13:41 +0000153 * @precious_reg: Optional callback returning true if the register
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100154 * should not be read outside of a call from the driver
Laszlo Pappbdc39642014-01-09 14:13:41 +0000155 * (e.g., a clear on read interrupt status register). If this
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100156 * field is NULL but precious_table (see below) is not, the
157 * check is performed on such table (a register is precious if
158 * it belongs to one of the ranges specified by precious_table).
159 * @lock: Optional lock callback (overrides regmap's default lock
160 * function, based on spinlock or mutex).
161 * @unlock: As above for unlocking.
162 * @lock_arg: this field is passed as the only argument of lock/unlock
163 * functions (ignored in case regular lock/unlock functions
164 * are not overridden).
Andrey Smirnovd2a58842013-01-27 10:49:05 -0800165 * @reg_read: Optional callback that if filled will be used to perform
166 * all the reads from the registers. Should only be provided for
Laszlo Pappbdc39642014-01-09 14:13:41 +0000167 * devices whose read operation cannot be represented as a simple
168 * read operation on a bus such as SPI, I2C, etc. Most of the
169 * devices do not need this.
Andrey Smirnovd2a58842013-01-27 10:49:05 -0800170 * @reg_write: Same as above for writing.
171 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
172 * to perform locking. This field is ignored if custom lock/unlock
173 * functions are used (see fields lock/unlock of struct regmap_config).
174 * This field is a duplicate of a similar file in
175 * 'struct regmap_bus' and serves exact same purpose.
176 * Use it only for "no-bus" cases.
Mark Brownbd20eb52011-08-19 18:09:38 +0900177 * @max_register: Optional, specifies the maximum valid register index.
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100178 * @wr_table: Optional, points to a struct regmap_access_table specifying
179 * valid ranges for write access.
180 * @rd_table: As above, for read access.
181 * @volatile_table: As above, for volatile registers.
182 * @precious_table: As above, for precious registers.
Mark Brownbd20eb52011-08-19 18:09:38 +0900183 * @reg_defaults: Power on reset values for registers (for use with
184 * register cache support).
185 * @num_reg_defaults: Number of elements in reg_defaults.
Lars-Peter Clausen6f306442011-09-05 20:46:32 +0200186 *
187 * @read_flag_mask: Mask to be set in the top byte of the register when doing
188 * a read.
189 * @write_flag_mask: Mask to be set in the top byte of the register when doing
190 * a write. If both read_flag_mask and write_flag_mask are
191 * empty the regmap_bus default masks are used.
Ashish Jangam2e33caf2012-04-30 23:23:40 +0100192 * @use_single_rw: If set, converts the bulk read and write operations into
193 * a series of single read and write operations. This is useful
194 * for device that does not support bulk read and write.
Opensource [Anthony Olech]e894c3f2014-03-04 13:54:02 +0000195 * @can_multi_write: If set, the device supports the multi write mode of bulk
196 * write operations, if clear multi write requests will be
197 * split into individual write operations
Dimitris Papastamos9fabe242011-09-19 14:34:00 +0100198 *
199 * @cache_type: The actual cache type.
200 * @reg_defaults_raw: Power on reset values for registers (for use with
201 * register cache support).
202 * @num_reg_defaults_raw: Number of elements in reg_defaults_raw.
Stephen Warren141eba22012-05-24 10:47:26 -0600203 * @reg_format_endian: Endianness for formatted register addresses. If this is
204 * DEFAULT, the @reg_format_endian_default value from the
205 * regmap bus is used.
206 * @val_format_endian: Endianness for formatted register values. If this is
207 * DEFAULT, the @reg_format_endian_default value from the
208 * regmap bus is used.
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100209 *
210 * @ranges: Array of configuration entries for virtual address ranges.
211 * @num_ranges: Number of range configuration entries.
Mark Browndd898b22011-07-20 22:28:58 +0100212 */
Mark Brownb83a3132011-05-11 19:59:58 +0200213struct regmap_config {
Stephen Warrend3c242e2012-04-04 15:48:29 -0600214 const char *name;
215
Mark Brownb83a3132011-05-11 19:59:58 +0200216 int reg_bits;
Stephen Warrenf01ee602012-04-09 13:40:24 -0600217 int reg_stride;
Mark Brown82159ba2012-01-18 10:52:25 +0000218 int pad_bits;
Mark Brownb83a3132011-05-11 19:59:58 +0200219 int val_bits;
Mark Brown2e2ae662011-07-20 22:33:39 +0100220
Mark Brown2e2ae662011-07-20 22:33:39 +0100221 bool (*writeable_reg)(struct device *dev, unsigned int reg);
222 bool (*readable_reg)(struct device *dev, unsigned int reg);
223 bool (*volatile_reg)(struct device *dev, unsigned int reg);
Mark Brown18694882011-08-08 15:40:22 +0900224 bool (*precious_reg)(struct device *dev, unsigned int reg);
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200225 regmap_lock lock;
226 regmap_unlock unlock;
227 void *lock_arg;
Mark Brownbd20eb52011-08-19 18:09:38 +0900228
Andrey Smirnovd2a58842013-01-27 10:49:05 -0800229 int (*reg_read)(void *context, unsigned int reg, unsigned int *val);
230 int (*reg_write)(void *context, unsigned int reg, unsigned int val);
231
232 bool fast_io;
233
Mark Brownbd20eb52011-08-19 18:09:38 +0900234 unsigned int max_register;
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100235 const struct regmap_access_table *wr_table;
236 const struct regmap_access_table *rd_table;
237 const struct regmap_access_table *volatile_table;
238 const struct regmap_access_table *precious_table;
Lars-Peter Clausen720e4612011-11-16 16:28:17 +0100239 const struct reg_default *reg_defaults;
Dimitris Papastamos9fabe242011-09-19 14:34:00 +0100240 unsigned int num_reg_defaults;
241 enum regcache_type cache_type;
242 const void *reg_defaults_raw;
243 unsigned int num_reg_defaults_raw;
Lars-Peter Clausen6f306442011-09-05 20:46:32 +0200244
245 u8 read_flag_mask;
246 u8 write_flag_mask;
Ashish Jangam2e33caf2012-04-30 23:23:40 +0100247
248 bool use_single_rw;
Opensource [Anthony Olech]e894c3f2014-03-04 13:54:02 +0000249 bool can_multi_write;
Stephen Warren141eba22012-05-24 10:47:26 -0600250
251 enum regmap_endian reg_format_endian;
252 enum regmap_endian val_format_endian;
Mark Brown38e23192012-07-22 19:26:07 +0100253
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100254 const struct regmap_range_cfg *ranges;
Mark Browne3549cd2012-10-02 20:17:15 +0100255 unsigned int num_ranges;
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100256};
257
258/**
259 * Configuration for indirectly accessed or paged registers.
260 * Registers, mapped to this virtual range, are accessed in two steps:
261 * 1. page selector register update;
262 * 2. access through data window registers.
263 *
Mark Brownd058bb42012-10-03 12:40:47 +0100264 * @name: Descriptive name for diagnostics
265 *
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100266 * @range_min: Address of the lowest register address in virtual range.
267 * @range_max: Address of the highest register in virtual range.
268 *
269 * @page_sel_reg: Register with selector field.
270 * @page_sel_mask: Bit shift for selector value.
271 * @page_sel_shift: Bit mask for selector value.
272 *
273 * @window_start: Address of first (lowest) register in data window.
274 * @window_len: Number of registers in data window.
275 */
276struct regmap_range_cfg {
Mark Brownd058bb42012-10-03 12:40:47 +0100277 const char *name;
278
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100279 /* Registers of virtual address range */
280 unsigned int range_min;
281 unsigned int range_max;
282
283 /* Page selector for indirect addressing */
284 unsigned int selector_reg;
285 unsigned int selector_mask;
286 int selector_shift;
287
288 /* Data window (per each page) */
289 unsigned int window_start;
290 unsigned int window_len;
Mark Brownb83a3132011-05-11 19:59:58 +0200291};
292
Mark Brown0d509f22013-01-27 22:07:38 +0800293struct regmap_async;
294
Stephen Warren0135bbc2012-04-04 15:48:30 -0600295typedef int (*regmap_hw_write)(void *context, const void *data,
Mark Brownb83a3132011-05-11 19:59:58 +0200296 size_t count);
Stephen Warren0135bbc2012-04-04 15:48:30 -0600297typedef int (*regmap_hw_gather_write)(void *context,
Mark Brownb83a3132011-05-11 19:59:58 +0200298 const void *reg, size_t reg_len,
299 const void *val, size_t val_len);
Mark Brown0d509f22013-01-27 22:07:38 +0800300typedef int (*regmap_hw_async_write)(void *context,
301 const void *reg, size_t reg_len,
302 const void *val, size_t val_len,
303 struct regmap_async *async);
Stephen Warren0135bbc2012-04-04 15:48:30 -0600304typedef int (*regmap_hw_read)(void *context,
Mark Brownb83a3132011-05-11 19:59:58 +0200305 const void *reg_buf, size_t reg_size,
306 void *val_buf, size_t val_size);
Boris BREZILLON3ac17032014-04-17 11:40:11 +0200307typedef int (*regmap_hw_reg_read)(void *context, unsigned int reg,
308 unsigned int *val);
309typedef int (*regmap_hw_reg_write)(void *context, unsigned int reg,
310 unsigned int val);
Jon Ringle77792b12015-10-01 12:38:07 -0400311typedef int (*regmap_hw_reg_update_bits)(void *context, unsigned int reg,
312 unsigned int mask, unsigned int val);
Mark Brown0d509f22013-01-27 22:07:38 +0800313typedef struct regmap_async *(*regmap_hw_async_alloc)(void);
Stephen Warren0135bbc2012-04-04 15:48:30 -0600314typedef void (*regmap_hw_free_context)(void *context);
Mark Brownb83a3132011-05-11 19:59:58 +0200315
316/**
317 * Description of a hardware bus for the register map infrastructure.
318 *
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600319 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200320 * to perform locking. This field is ignored if custom lock/unlock
321 * functions are used (see fields lock/unlock of
322 * struct regmap_config).
Mark Brownb83a3132011-05-11 19:59:58 +0200323 * @write: Write operation.
324 * @gather_write: Write operation with split register/value, return -ENOTSUPP
325 * if not implemented on a given device.
Mark Brown0d509f22013-01-27 22:07:38 +0800326 * @async_write: Write operation which completes asynchronously, optional and
327 * must serialise with respect to non-async I/O.
Markus Pargmannc5f58f22015-08-21 10:26:40 +0200328 * @reg_write: Write a single register value to the given register address. This
329 * write operation has to complete when returning from the function.
Mark Brownb83a3132011-05-11 19:59:58 +0200330 * @read: Read operation. Data is returned in the buffer used to transmit
331 * data.
Markus Pargmannc5f58f22015-08-21 10:26:40 +0200332 * @reg_read: Read a single register value from a given register address.
333 * @free_context: Free context.
Mark Brown0d509f22013-01-27 22:07:38 +0800334 * @async_alloc: Allocate a regmap_async() structure.
Mark Brownb83a3132011-05-11 19:59:58 +0200335 * @read_flag_mask: Mask to be set in the top byte of the register when doing
336 * a read.
Stephen Warren141eba22012-05-24 10:47:26 -0600337 * @reg_format_endian_default: Default endianness for formatted register
338 * addresses. Used when the regmap_config specifies DEFAULT. If this is
339 * DEFAULT, BIG is assumed.
340 * @val_format_endian_default: Default endianness for formatted register
341 * values. Used when the regmap_config specifies DEFAULT. If this is
342 * DEFAULT, BIG is assumed.
Markus Pargmannadaac452015-08-30 09:33:53 +0200343 * @max_raw_read: Max raw read size that can be used on the bus.
344 * @max_raw_write: Max raw write size that can be used on the bus.
Mark Brownb83a3132011-05-11 19:59:58 +0200345 */
346struct regmap_bus {
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600347 bool fast_io;
Mark Brownb83a3132011-05-11 19:59:58 +0200348 regmap_hw_write write;
349 regmap_hw_gather_write gather_write;
Mark Brown0d509f22013-01-27 22:07:38 +0800350 regmap_hw_async_write async_write;
Boris BREZILLON3ac17032014-04-17 11:40:11 +0200351 regmap_hw_reg_write reg_write;
Jon Ringle77792b12015-10-01 12:38:07 -0400352 regmap_hw_reg_update_bits reg_update_bits;
Mark Brownb83a3132011-05-11 19:59:58 +0200353 regmap_hw_read read;
Boris BREZILLON3ac17032014-04-17 11:40:11 +0200354 regmap_hw_reg_read reg_read;
Stephen Warren0135bbc2012-04-04 15:48:30 -0600355 regmap_hw_free_context free_context;
Mark Brown0d509f22013-01-27 22:07:38 +0800356 regmap_hw_async_alloc async_alloc;
Mark Brownb83a3132011-05-11 19:59:58 +0200357 u8 read_flag_mask;
Stephen Warren141eba22012-05-24 10:47:26 -0600358 enum regmap_endian reg_format_endian_default;
359 enum regmap_endian val_format_endian_default;
Markus Pargmannadaac452015-08-30 09:33:53 +0200360 size_t max_raw_read;
361 size_t max_raw_write;
Mark Brownb83a3132011-05-11 19:59:58 +0200362};
363
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800364/*
365 * __regmap_init functions.
366 *
367 * These functions take a lock key and name parameter, and should not be called
368 * directly. Instead, use the regmap_init macros that generate a key and name
369 * for each call.
370 */
371struct regmap *__regmap_init(struct device *dev,
372 const struct regmap_bus *bus,
373 void *bus_context,
374 const struct regmap_config *config,
375 struct lock_class_key *lock_key,
376 const char *lock_name);
377struct regmap *__regmap_init_i2c(struct i2c_client *i2c,
378 const struct regmap_config *config,
379 struct lock_class_key *lock_key,
380 const char *lock_name);
381struct regmap *__regmap_init_spi(struct spi_device *dev,
382 const struct regmap_config *config,
383 struct lock_class_key *lock_key,
384 const char *lock_name);
385struct regmap *__regmap_init_spmi_base(struct spmi_device *dev,
386 const struct regmap_config *config,
387 struct lock_class_key *lock_key,
388 const char *lock_name);
389struct regmap *__regmap_init_spmi_ext(struct spmi_device *dev,
390 const struct regmap_config *config,
391 struct lock_class_key *lock_key,
392 const char *lock_name);
393struct regmap *__regmap_init_mmio_clk(struct device *dev, const char *clk_id,
394 void __iomem *regs,
395 const struct regmap_config *config,
396 struct lock_class_key *lock_key,
397 const char *lock_name);
398struct regmap *__regmap_init_ac97(struct snd_ac97 *ac97,
399 const struct regmap_config *config,
400 struct lock_class_key *lock_key,
401 const char *lock_name);
402
403struct regmap *__devm_regmap_init(struct device *dev,
404 const struct regmap_bus *bus,
405 void *bus_context,
406 const struct regmap_config *config,
407 struct lock_class_key *lock_key,
408 const char *lock_name);
409struct regmap *__devm_regmap_init_i2c(struct i2c_client *i2c,
410 const struct regmap_config *config,
411 struct lock_class_key *lock_key,
412 const char *lock_name);
413struct regmap *__devm_regmap_init_spi(struct spi_device *dev,
414 const struct regmap_config *config,
415 struct lock_class_key *lock_key,
416 const char *lock_name);
417struct regmap *__devm_regmap_init_spmi_base(struct spmi_device *dev,
418 const struct regmap_config *config,
419 struct lock_class_key *lock_key,
420 const char *lock_name);
421struct regmap *__devm_regmap_init_spmi_ext(struct spmi_device *dev,
422 const struct regmap_config *config,
423 struct lock_class_key *lock_key,
424 const char *lock_name);
425struct regmap *__devm_regmap_init_mmio_clk(struct device *dev,
426 const char *clk_id,
427 void __iomem *regs,
428 const struct regmap_config *config,
429 struct lock_class_key *lock_key,
430 const char *lock_name);
431struct regmap *__devm_regmap_init_ac97(struct snd_ac97 *ac97,
432 const struct regmap_config *config,
433 struct lock_class_key *lock_key,
434 const char *lock_name);
435
436/*
437 * Wrapper for regmap_init macros to include a unique lockdep key and name
438 * for each call. No-op if CONFIG_LOCKDEP is not set.
439 *
440 * @fn: Real function to call (in the form __[*_]regmap_init[_*])
441 * @name: Config variable name (#config in the calling macro)
442 **/
443#ifdef CONFIG_LOCKDEP
444#define __regmap_lockdep_wrapper(fn, name, ...) \
445( \
446 ({ \
447 static struct lock_class_key _key; \
448 fn(__VA_ARGS__, &_key, \
449 KBUILD_BASENAME ":" \
450 __stringify(__LINE__) ":" \
451 "(" name ")->lock"); \
452 }) \
453)
454#else
455#define __regmap_lockdep_wrapper(fn, name, ...) fn(__VA_ARGS__, NULL, NULL)
456#endif
457
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800458/**
459 * regmap_init(): Initialise register map
460 *
461 * @dev: Device that will be interacted with
462 * @bus: Bus-specific callbacks to use with device
463 * @bus_context: Data passed to bus-specific callbacks
464 * @config: Configuration for register map
465 *
466 * The return value will be an ERR_PTR() on error or a valid pointer to
467 * a struct regmap. This function should generally not be called
468 * directly, it should be called by bus-specific init functions.
469 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800470#define regmap_init(dev, bus, bus_context, config) \
471 __regmap_lockdep_wrapper(__regmap_init, #config, \
472 dev, bus, bus_context, config)
Michal Simek6cfec042014-02-10 16:22:33 +0100473int regmap_attach_dev(struct device *dev, struct regmap *map,
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800474 const struct regmap_config *config);
Mark Browna676f082011-05-12 11:42:10 +0200475
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800476/**
477 * regmap_init_i2c(): Initialise register map
478 *
479 * @i2c: Device that will be interacted with
480 * @config: Configuration for register map
481 *
482 * The return value will be an ERR_PTR() on error or a valid pointer to
483 * a struct regmap.
484 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800485#define regmap_init_i2c(i2c, config) \
486 __regmap_lockdep_wrapper(__regmap_init_i2c, #config, \
487 i2c, config)
Mark Brown22853222014-11-18 19:45:51 +0100488
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800489/**
490 * regmap_init_spi(): Initialise register map
491 *
492 * @spi: Device that will be interacted with
493 * @config: Configuration for register map
494 *
495 * The return value will be an ERR_PTR() on error or a valid pointer to
496 * a struct regmap.
497 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800498#define regmap_init_spi(dev, config) \
499 __regmap_lockdep_wrapper(__regmap_init_spi, #config, \
500 dev, config)
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800501
502/**
503 * regmap_init_spmi_base(): Create regmap for the Base register space
504 * @sdev: SPMI device that will be interacted with
505 * @config: Configuration for register map
506 *
507 * The return value will be an ERR_PTR() on error or a valid pointer to
508 * a struct regmap.
509 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800510#define regmap_init_spmi_base(dev, config) \
511 __regmap_lockdep_wrapper(__regmap_init_spmi_base, #config, \
512 dev, config)
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800513
514/**
515 * regmap_init_spmi_ext(): Create regmap for Ext register space
516 * @sdev: Device that will be interacted with
517 * @config: Configuration for register map
518 *
519 * The return value will be an ERR_PTR() on error or a valid pointer to
520 * a struct regmap.
521 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800522#define regmap_init_spmi_ext(dev, config) \
523 __regmap_lockdep_wrapper(__regmap_init_spmi_ext, #config, \
524 dev, config)
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800525
526/**
527 * regmap_init_mmio_clk(): Initialise register map with register clock
528 *
529 * @dev: Device that will be interacted with
530 * @clk_id: register clock consumer ID
531 * @regs: Pointer to memory-mapped IO region
532 * @config: Configuration for register map
533 *
534 * The return value will be an ERR_PTR() on error or a valid pointer to
535 * a struct regmap.
536 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800537#define regmap_init_mmio_clk(dev, clk_id, regs, config) \
538 __regmap_lockdep_wrapper(__regmap_init_mmio_clk, #config, \
539 dev, clk_id, regs, config)
Philipp Zabel878ec672013-02-14 17:39:08 +0100540
541/**
542 * regmap_init_mmio(): Initialise register map
543 *
544 * @dev: Device that will be interacted with
545 * @regs: Pointer to memory-mapped IO region
546 * @config: Configuration for register map
547 *
548 * The return value will be an ERR_PTR() on error or a valid pointer to
549 * a struct regmap.
550 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800551#define regmap_init_mmio(dev, regs, config) \
552 regmap_init_mmio_clk(dev, NULL, regs, config)
Philipp Zabel878ec672013-02-14 17:39:08 +0100553
554/**
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800555 * regmap_init_ac97(): Initialise AC'97 register map
556 *
557 * @ac97: Device that will be interacted with
558 * @config: Configuration for register map
559 *
560 * The return value will be an ERR_PTR() on error or a valid pointer to
561 * a struct regmap.
562 */
563#define regmap_init_ac97(ac97, config) \
564 __regmap_lockdep_wrapper(__regmap_init_ac97, #config, \
565 ac97, config)
566bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg);
567
568/**
569 * devm_regmap_init(): Initialise managed register map
570 *
571 * @dev: Device that will be interacted with
572 * @bus: Bus-specific callbacks to use with device
573 * @bus_context: Data passed to bus-specific callbacks
574 * @config: Configuration for register map
575 *
576 * The return value will be an ERR_PTR() on error or a valid pointer
577 * to a struct regmap. This function should generally not be called
578 * directly, it should be called by bus-specific init functions. The
579 * map will be automatically freed by the device management code.
580 */
581#define devm_regmap_init(dev, bus, bus_context, config) \
582 __regmap_lockdep_wrapper(__devm_regmap_init, #config, \
583 dev, bus, bus_context, config)
584
585/**
586 * devm_regmap_init_i2c(): Initialise managed register map
587 *
588 * @i2c: Device that will be interacted with
589 * @config: Configuration for register map
590 *
591 * The return value will be an ERR_PTR() on error or a valid pointer
592 * to a struct regmap. The regmap will be automatically freed by the
593 * device management code.
594 */
595#define devm_regmap_init_i2c(i2c, config) \
596 __regmap_lockdep_wrapper(__devm_regmap_init_i2c, #config, \
597 i2c, config)
598
599/**
600 * devm_regmap_init_spi(): Initialise register map
601 *
602 * @spi: Device that will be interacted with
603 * @config: Configuration for register map
604 *
605 * The return value will be an ERR_PTR() on error or a valid pointer
606 * to a struct regmap. The map will be automatically freed by the
607 * device management code.
608 */
609#define devm_regmap_init_spi(dev, config) \
610 __regmap_lockdep_wrapper(__devm_regmap_init_spi, #config, \
611 dev, config)
612
613/**
614 * devm_regmap_init_spmi_base(): Create managed regmap for Base register space
615 * @sdev: SPMI 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
619 * to a struct regmap. The regmap will be automatically freed by the
620 * device management code.
621 */
622#define devm_regmap_init_spmi_base(dev, config) \
623 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_base, #config, \
624 dev, config)
625
626/**
627 * devm_regmap_init_spmi_ext(): Create managed regmap for Ext register space
628 * @sdev: SPMI device that will be interacted with
629 * @config: Configuration for register map
630 *
631 * The return value will be an ERR_PTR() on error or a valid pointer
632 * to a struct regmap. The regmap will be automatically freed by the
633 * device management code.
634 */
635#define devm_regmap_init_spmi_ext(dev, config) \
636 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_ext, #config, \
637 dev, config)
638
639/**
640 * devm_regmap_init_mmio_clk(): Initialise managed register map with clock
641 *
642 * @dev: Device that will be interacted with
643 * @clk_id: register clock consumer ID
644 * @regs: Pointer to memory-mapped IO region
645 * @config: Configuration for register map
646 *
647 * The return value will be an ERR_PTR() on error or a valid pointer
648 * to a struct regmap. The regmap will be automatically freed by the
649 * device management code.
650 */
651#define devm_regmap_init_mmio_clk(dev, clk_id, regs, config) \
652 __regmap_lockdep_wrapper(__devm_regmap_init_mmio_clk, #config, \
653 dev, clk_id, regs, config)
Philipp Zabel878ec672013-02-14 17:39:08 +0100654
655/**
656 * devm_regmap_init_mmio(): Initialise managed register map
657 *
658 * @dev: Device that will be interacted with
659 * @regs: Pointer to memory-mapped IO region
660 * @config: Configuration for register map
661 *
662 * The return value will be an ERR_PTR() on error or a valid pointer
663 * to a struct regmap. The regmap will be automatically freed by the
664 * device management code.
665 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800666#define devm_regmap_init_mmio(dev, regs, config) \
667 devm_regmap_init_mmio_clk(dev, NULL, regs, config)
Mark Brownc0eb4672012-01-30 19:56:52 +0000668
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800669/**
670 * devm_regmap_init_ac97(): Initialise AC'97 register map
671 *
672 * @ac97: Device that will be interacted with
673 * @config: Configuration for register map
674 *
675 * The return value will be an ERR_PTR() on error or a valid pointer
676 * to a struct regmap. The regmap will be automatically freed by the
677 * device management code.
678 */
679#define devm_regmap_init_ac97(ac97, config) \
680 __regmap_lockdep_wrapper(__devm_regmap_init_ac97, #config, \
681 ac97, config)
Mark Brownb83a3132011-05-11 19:59:58 +0200682
683void regmap_exit(struct regmap *map);
684int regmap_reinit_cache(struct regmap *map,
685 const struct regmap_config *config);
Mark Brown72b39f62012-05-08 17:44:40 +0100686struct regmap *dev_get_regmap(struct device *dev, const char *name);
Tuomas Tynkkynen8d7d3972014-07-21 18:38:47 +0300687struct device *regmap_get_device(struct regmap *map);
Mark Brownb83a3132011-05-11 19:59:58 +0200688int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
Mark Brown915f4412013-10-09 13:30:10 +0100689int regmap_write_async(struct regmap *map, unsigned int reg, unsigned int val);
Mark Brownb83a3132011-05-11 19:59:58 +0200690int regmap_raw_write(struct regmap *map, unsigned int reg,
691 const void *val, size_t val_len);
Laxman Dewangan8eaeb212012-02-12 19:49:43 +0530692int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
693 size_t val_count);
Nariman Poushin8019ff62015-07-16 16:36:21 +0100694int regmap_multi_reg_write(struct regmap *map, const struct reg_sequence *regs,
Anthony Oleche33fabd2013-10-11 15:31:11 +0100695 int num_regs);
Charles Keepax1d5b40b2014-02-25 13:45:50 +0000696int regmap_multi_reg_write_bypassed(struct regmap *map,
Nariman Poushin8019ff62015-07-16 16:36:21 +0100697 const struct reg_sequence *regs,
Charles Keepax1d5b40b2014-02-25 13:45:50 +0000698 int num_regs);
Mark Brown0d509f22013-01-27 22:07:38 +0800699int regmap_raw_write_async(struct regmap *map, unsigned int reg,
700 const void *val, size_t val_len);
Mark Brownb83a3132011-05-11 19:59:58 +0200701int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
702int regmap_raw_read(struct regmap *map, unsigned int reg,
703 void *val, size_t val_len);
704int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
705 size_t val_count);
Kuninori Morimoto91d31b92016-02-15 05:22:18 +0000706int regmap_update_bits_base(struct regmap *map, unsigned int reg,
707 unsigned int mask, unsigned int val,
708 bool *change, bool async, bool force);
Kuninori Morimotofd4b7286c2015-06-16 08:52:39 +0000709int regmap_write_bits(struct regmap *map, unsigned int reg,
710 unsigned int mask, unsigned int val);
Mark Browna6539c32012-02-17 14:20:14 -0800711int regmap_get_val_bytes(struct regmap *map);
Srinivas Kandagatla668abc72015-05-21 17:42:43 +0100712int regmap_get_max_register(struct regmap *map);
Srinivas Kandagatlaa2f776c2015-05-21 17:42:54 +0100713int regmap_get_reg_stride(struct regmap *map);
Mark Brown0d509f22013-01-27 22:07:38 +0800714int regmap_async_complete(struct regmap *map);
Mark Brown221ad7f2013-03-26 21:24:20 +0000715bool regmap_can_raw_write(struct regmap *map);
Markus Pargmannf50c9eb2015-08-30 09:33:54 +0200716size_t regmap_get_raw_read_max(struct regmap *map);
717size_t regmap_get_raw_write_max(struct regmap *map);
Mark Brownb83a3132011-05-11 19:59:58 +0200718
Mark Brown39a58432011-09-19 18:21:49 +0100719int regcache_sync(struct regmap *map);
Mark Brown4d4cfd12012-02-23 20:53:37 +0000720int regcache_sync_region(struct regmap *map, unsigned int min,
721 unsigned int max);
Mark Brown697e85b2013-05-08 13:55:22 +0100722int regcache_drop_region(struct regmap *map, unsigned int min,
723 unsigned int max);
Mark Brown92afb282011-09-19 18:22:14 +0100724void regcache_cache_only(struct regmap *map, bool enable);
Dimitris Papastamos6eb0f5e2011-09-29 14:36:27 +0100725void regcache_cache_bypass(struct regmap *map, bool enable);
Mark Brown8ae0d7e2011-10-26 10:34:22 +0200726void regcache_mark_dirty(struct regmap *map);
Mark Brown92afb282011-09-19 18:22:14 +0100727
Mark Brown154881e2013-05-08 13:55:23 +0100728bool regmap_check_range_table(struct regmap *map, unsigned int reg,
729 const struct regmap_access_table *table);
730
Nariman Poushin8019ff62015-07-16 16:36:21 +0100731int regmap_register_patch(struct regmap *map, const struct reg_sequence *regs,
Mark Brown22f0d902012-01-21 12:01:14 +0000732 int num_regs);
Nenghua Cao13ff50c2014-02-19 18:44:13 +0800733int regmap_parse_val(struct regmap *map, const void *buf,
734 unsigned int *val);
Mark Brown22f0d902012-01-21 12:01:14 +0000735
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100736static inline bool regmap_reg_in_range(unsigned int reg,
737 const struct regmap_range *range)
738{
739 return reg >= range->range_min && reg <= range->range_max;
740}
741
742bool regmap_reg_in_ranges(unsigned int reg,
743 const struct regmap_range *ranges,
744 unsigned int nranges);
745
Mark Brownf8beab22011-10-28 23:50:49 +0200746/**
Srinivas Kandagatla67252282013-06-11 13:18:15 +0100747 * Description of an register field
748 *
749 * @reg: Offset of the register within the regmap bank
750 * @lsb: lsb of the register field.
Bintian Wangf27b37f2015-01-27 20:50:29 +0800751 * @msb: msb of the register field.
Kuninori Morimotoa0102372013-09-01 20:30:50 -0700752 * @id_size: port size if it has some ports
753 * @id_offset: address offset for each ports
Srinivas Kandagatla67252282013-06-11 13:18:15 +0100754 */
755struct reg_field {
756 unsigned int reg;
757 unsigned int lsb;
758 unsigned int msb;
Kuninori Morimotoa0102372013-09-01 20:30:50 -0700759 unsigned int id_size;
760 unsigned int id_offset;
Srinivas Kandagatla67252282013-06-11 13:18:15 +0100761};
762
763#define REG_FIELD(_reg, _lsb, _msb) { \
764 .reg = _reg, \
765 .lsb = _lsb, \
766 .msb = _msb, \
767 }
768
769struct regmap_field *regmap_field_alloc(struct regmap *regmap,
770 struct reg_field reg_field);
771void regmap_field_free(struct regmap_field *field);
772
773struct regmap_field *devm_regmap_field_alloc(struct device *dev,
774 struct regmap *regmap, struct reg_field reg_field);
775void devm_regmap_field_free(struct device *dev, struct regmap_field *field);
776
777int regmap_field_read(struct regmap_field *field, unsigned int *val);
Kuninori Morimoto28972ea2016-02-15 05:23:55 +0000778int regmap_field_update_bits_base(struct regmap_field *field,
779 unsigned int mask, unsigned int val,
780 bool *change, bool async, bool force);
Kuninori Morimotofdf20022013-09-01 20:24:50 -0700781int regmap_field_update_bits(struct regmap_field *field,
782 unsigned int mask, unsigned int val);
Kuninori Morimotoa0102372013-09-01 20:30:50 -0700783int regmap_fields_write(struct regmap_field *field, unsigned int id,
784 unsigned int val);
Kuninori Morimotoe874e6c2015-06-16 08:52:55 +0000785int regmap_fields_force_write(struct regmap_field *field, unsigned int id,
786 unsigned int val);
Kuninori Morimotoa0102372013-09-01 20:30:50 -0700787int regmap_fields_read(struct regmap_field *field, unsigned int id,
788 unsigned int *val);
789int regmap_fields_update_bits(struct regmap_field *field, unsigned int id,
790 unsigned int mask, unsigned int val);
Srinivas Kandagatla67252282013-06-11 13:18:15 +0100791
792/**
Mark Brownf8beab22011-10-28 23:50:49 +0200793 * Description of an IRQ for the generic regmap irq_chip.
794 *
795 * @reg_offset: Offset of the status/mask register within the bank
796 * @mask: Mask used to flag/control the register.
Laxman Dewangan7a78479f2015-12-22 18:25:26 +0530797 * @type_reg_offset: Offset register for the irq type setting.
798 * @type_rising_mask: Mask bit to configure RISING type irq.
799 * @type_falling_mask: Mask bit to configure FALLING type irq.
Mark Brownf8beab22011-10-28 23:50:49 +0200800 */
801struct regmap_irq {
802 unsigned int reg_offset;
803 unsigned int mask;
Laxman Dewangan7a78479f2015-12-22 18:25:26 +0530804 unsigned int type_reg_offset;
805 unsigned int type_rising_mask;
806 unsigned int type_falling_mask;
Mark Brownf8beab22011-10-28 23:50:49 +0200807};
808
Qipeng Zhab4fe8ba2015-09-15 00:39:17 +0800809#define REGMAP_IRQ_REG(_irq, _off, _mask) \
810 [_irq] = { .reg_offset = (_off), .mask = (_mask) }
811
Mark Brownf8beab22011-10-28 23:50:49 +0200812/**
813 * Description of a generic regmap irq_chip. This is not intended to
814 * handle every possible interrupt controller, but it should handle a
815 * substantial proportion of those that are found in the wild.
816 *
817 * @name: Descriptive name for IRQ controller.
818 *
819 * @status_base: Base status register address.
820 * @mask_base: Base mask register address.
Guo Zeng7b7d1962015-09-17 05:23:20 +0000821 * @unmask_base: Base unmask register address. for chips who have
822 * separate mask and unmask registers
Alexander Shiyand3233432013-12-15 13:36:51 +0400823 * @ack_base: Base ack address. If zero then the chip is clear on read.
824 * Using zero value is possible with @use_ack bit.
Mark Browna43fd502012-06-05 14:34:03 +0100825 * @wake_base: Base address for wake enables. If zero unsupported.
Laxman Dewangan7a78479f2015-12-22 18:25:26 +0530826 * @type_base: Base address for irq type. If zero unsupported.
Graeme Gregory022f926a2012-05-14 22:40:43 +0900827 * @irq_reg_stride: Stride to use for chips where registers are not contiguous.
Philipp Zabel2753e6f2013-07-22 17:15:52 +0200828 * @init_ack_masked: Ack all masked interrupts once during initalization.
Philipp Zabel68622bd2013-07-24 10:26:48 +0200829 * @mask_invert: Inverted mask register: cleared bits are masked out.
Alexander Shiyand3233432013-12-15 13:36:51 +0400830 * @use_ack: Use @ack register even if it is zero.
Guo Zenga650fdd2015-09-17 05:23:21 +0000831 * @ack_invert: Inverted ack register: cleared bits for ack.
Philipp Zabel68622bd2013-07-24 10:26:48 +0200832 * @wake_invert: Inverted wake register: cleared bits are wake enabled.
Laxman Dewangan7a78479f2015-12-22 18:25:26 +0530833 * @type_invert: Invert the type flags.
Mark Brown0c00c502012-07-24 15:41:19 +0100834 * @runtime_pm: Hold a runtime PM lock on the device when accessing it.
Mark Brownf8beab22011-10-28 23:50:49 +0200835 *
836 * @num_regs: Number of registers in each control bank.
837 * @irqs: Descriptors for individual IRQs. Interrupt numbers are
838 * assigned based on the index in the array of the interrupt.
839 * @num_irqs: Number of descriptors.
Laxman Dewangan7a78479f2015-12-22 18:25:26 +0530840 * @num_type_reg: Number of type registers.
841 * @type_reg_stride: Stride to use for chips where type registers are not
842 * contiguous.
Mark Brownf8beab22011-10-28 23:50:49 +0200843 */
844struct regmap_irq_chip {
845 const char *name;
846
847 unsigned int status_base;
848 unsigned int mask_base;
Guo Zeng7b7d1962015-09-17 05:23:20 +0000849 unsigned int unmask_base;
Mark Brownf8beab22011-10-28 23:50:49 +0200850 unsigned int ack_base;
Mark Browna43fd502012-06-05 14:34:03 +0100851 unsigned int wake_base;
Laxman Dewangan7a78479f2015-12-22 18:25:26 +0530852 unsigned int type_base;
Graeme Gregory022f926a2012-05-14 22:40:43 +0900853 unsigned int irq_reg_stride;
Philipp Zabelf484f7a2013-07-24 10:26:42 +0200854 bool init_ack_masked:1;
855 bool mask_invert:1;
Alexander Shiyand3233432013-12-15 13:36:51 +0400856 bool use_ack:1;
Guo Zenga650fdd2015-09-17 05:23:21 +0000857 bool ack_invert:1;
Philipp Zabelf484f7a2013-07-24 10:26:42 +0200858 bool wake_invert:1;
859 bool runtime_pm:1;
Laxman Dewangan7a78479f2015-12-22 18:25:26 +0530860 bool type_invert:1;
Mark Brownf8beab22011-10-28 23:50:49 +0200861
862 int num_regs;
863
864 const struct regmap_irq *irqs;
865 int num_irqs;
Laxman Dewangan7a78479f2015-12-22 18:25:26 +0530866
867 int num_type_reg;
868 unsigned int type_reg_stride;
Mark Brownf8beab22011-10-28 23:50:49 +0200869};
870
871struct regmap_irq_chip_data;
872
873int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
Mark Brownb026ddb2012-05-31 21:01:46 +0100874 int irq_base, const struct regmap_irq_chip *chip,
Mark Brownf8beab22011-10-28 23:50:49 +0200875 struct regmap_irq_chip_data **data);
876void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data);
Mark Brown209a6002011-12-05 16:10:15 +0000877int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data);
Mark Brown4af8be62012-05-13 10:59:56 +0100878int regmap_irq_get_virq(struct regmap_irq_chip_data *data, int irq);
Mark Brown90f790d2012-08-20 21:45:05 +0100879struct irq_domain *regmap_irq_get_domain(struct regmap_irq_chip_data *data);
Mark Brownb83a3132011-05-11 19:59:58 +0200880
Mark Brown9cde5fc2012-02-17 14:49:51 -0800881#else
882
883/*
884 * These stubs should only ever be called by generic code which has
885 * regmap based facilities, if they ever get called at runtime
886 * something is going wrong and something probably needs to select
887 * REGMAP.
888 */
889
890static inline int regmap_write(struct regmap *map, unsigned int reg,
891 unsigned int val)
892{
893 WARN_ONCE(1, "regmap API is disabled");
894 return -EINVAL;
895}
896
Mark Brown915f4412013-10-09 13:30:10 +0100897static inline int regmap_write_async(struct regmap *map, unsigned int reg,
898 unsigned int val)
899{
900 WARN_ONCE(1, "regmap API is disabled");
901 return -EINVAL;
902}
903
Mark Brown9cde5fc2012-02-17 14:49:51 -0800904static inline int regmap_raw_write(struct regmap *map, unsigned int reg,
905 const void *val, size_t val_len)
906{
907 WARN_ONCE(1, "regmap API is disabled");
908 return -EINVAL;
909}
910
Mark Brown0d509f22013-01-27 22:07:38 +0800911static inline int regmap_raw_write_async(struct regmap *map, unsigned int reg,
912 const void *val, size_t val_len)
913{
914 WARN_ONCE(1, "regmap API is disabled");
915 return -EINVAL;
916}
917
Mark Brown9cde5fc2012-02-17 14:49:51 -0800918static inline int regmap_bulk_write(struct regmap *map, unsigned int reg,
919 const void *val, size_t val_count)
920{
921 WARN_ONCE(1, "regmap API is disabled");
922 return -EINVAL;
923}
924
925static inline int regmap_read(struct regmap *map, unsigned int reg,
926 unsigned int *val)
927{
928 WARN_ONCE(1, "regmap API is disabled");
929 return -EINVAL;
930}
931
932static inline int regmap_raw_read(struct regmap *map, unsigned int reg,
933 void *val, size_t val_len)
934{
935 WARN_ONCE(1, "regmap API is disabled");
936 return -EINVAL;
937}
938
939static inline int regmap_bulk_read(struct regmap *map, unsigned int reg,
940 void *val, size_t val_count)
941{
942 WARN_ONCE(1, "regmap API is disabled");
943 return -EINVAL;
944}
945
Kuninori Morimoto91d31b92016-02-15 05:22:18 +0000946static inline int regmap_update_bits_base(struct regmap *map, unsigned int reg,
947 unsigned int mask, unsigned int val,
948 bool *change, bool async, bool force)
949{
950 WARN_ONCE(1, "regmap API is disabled");
951 return -EINVAL;
952}
953
Kuninori Morimotofd4b7286c2015-06-16 08:52:39 +0000954static inline int regmap_write_bits(struct regmap *map, unsigned int reg,
955 unsigned int mask, unsigned int val)
956{
957 WARN_ONCE(1, "regmap API is disabled");
958 return -EINVAL;
959}
960
Kuninori Morimoto28972ea2016-02-15 05:23:55 +0000961static inline int regmap_field_update_bits_base(struct regmap_field *field,
962 unsigned int mask, unsigned int val,
963 bool *change, bool async, bool force)
964{
965 WARN_ONCE(1, "regmap API is disabled");
966 return -EINVAL;
967}
968
Mark Brown9cde5fc2012-02-17 14:49:51 -0800969static inline int regmap_get_val_bytes(struct regmap *map)
970{
971 WARN_ONCE(1, "regmap API is disabled");
972 return -EINVAL;
973}
974
Srinivas Kandagatla668abc72015-05-21 17:42:43 +0100975static inline int regmap_get_max_register(struct regmap *map)
976{
977 WARN_ONCE(1, "regmap API is disabled");
978 return -EINVAL;
979}
980
Srinivas Kandagatlaa2f776c2015-05-21 17:42:54 +0100981static inline int regmap_get_reg_stride(struct regmap *map)
982{
983 WARN_ONCE(1, "regmap API is disabled");
984 return -EINVAL;
985}
986
Mark Brown9cde5fc2012-02-17 14:49:51 -0800987static inline int regcache_sync(struct regmap *map)
988{
989 WARN_ONCE(1, "regmap API is disabled");
990 return -EINVAL;
991}
992
Mark Browna313f9f2012-02-23 19:49:43 +0000993static inline int regcache_sync_region(struct regmap *map, unsigned int min,
994 unsigned int max)
995{
996 WARN_ONCE(1, "regmap API is disabled");
997 return -EINVAL;
998}
999
Mark Brown697e85b2013-05-08 13:55:22 +01001000static inline int regcache_drop_region(struct regmap *map, unsigned int min,
1001 unsigned int max)
1002{
1003 WARN_ONCE(1, "regmap API is disabled");
1004 return -EINVAL;
1005}
1006
Mark Brown9cde5fc2012-02-17 14:49:51 -08001007static inline void regcache_cache_only(struct regmap *map, bool enable)
1008{
1009 WARN_ONCE(1, "regmap API is disabled");
1010}
1011
1012static inline void regcache_cache_bypass(struct regmap *map, bool enable)
1013{
1014 WARN_ONCE(1, "regmap API is disabled");
1015}
1016
1017static inline void regcache_mark_dirty(struct regmap *map)
1018{
1019 WARN_ONCE(1, "regmap API is disabled");
1020}
1021
Mark Brown0d509f22013-01-27 22:07:38 +08001022static inline void regmap_async_complete(struct regmap *map)
1023{
1024 WARN_ONCE(1, "regmap API is disabled");
1025}
1026
Mark Brown9cde5fc2012-02-17 14:49:51 -08001027static inline int regmap_register_patch(struct regmap *map,
Daniel Wagnera6baa3d2015-11-30 16:20:15 +01001028 const struct reg_sequence *regs,
Mark Brown9cde5fc2012-02-17 14:49:51 -08001029 int num_regs)
1030{
1031 WARN_ONCE(1, "regmap API is disabled");
1032 return -EINVAL;
1033}
1034
Nenghua Cao13ff50c2014-02-19 18:44:13 +08001035static inline int regmap_parse_val(struct regmap *map, const void *buf,
1036 unsigned int *val)
1037{
1038 WARN_ONCE(1, "regmap API is disabled");
1039 return -EINVAL;
1040}
1041
Mark Brown72b39f62012-05-08 17:44:40 +01001042static inline struct regmap *dev_get_regmap(struct device *dev,
1043 const char *name)
1044{
Mark Brown72b39f62012-05-08 17:44:40 +01001045 return NULL;
1046}
1047
Tuomas Tynkkynen8d7d3972014-07-21 18:38:47 +03001048static inline struct device *regmap_get_device(struct regmap *map)
1049{
1050 WARN_ONCE(1, "regmap API is disabled");
Mark Brown1d33dc62014-07-25 19:01:53 +01001051 return NULL;
Tuomas Tynkkynen8d7d3972014-07-21 18:38:47 +03001052}
1053
Mark Brown9cde5fc2012-02-17 14:49:51 -08001054#endif
1055
Mark Brownb83a3132011-05-11 19:59:58 +02001056#endif