blob: 28e50a3d2872f2472b9e12fdae67dd65fc132ebe [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
Mark Brownb83d2ff2012-03-11 11:49:17 +000068#ifdef CONFIG_REGMAP
69
Stephen Warren141eba22012-05-24 10:47:26 -060070enum regmap_endian {
71 /* Unspecified -> 0 -> Backwards compatible default */
72 REGMAP_ENDIAN_DEFAULT = 0,
73 REGMAP_ENDIAN_BIG,
74 REGMAP_ENDIAN_LITTLE,
75 REGMAP_ENDIAN_NATIVE,
76};
77
Davide Ciminaghi76aad392012-11-20 15:20:30 +010078/**
79 * A register range, used for access related checks
80 * (readable/writeable/volatile/precious checks)
81 *
82 * @range_min: address of first register
83 * @range_max: address of last register
84 */
85struct regmap_range {
86 unsigned int range_min;
87 unsigned int range_max;
88};
89
Laxman Dewangan6112fe62013-09-20 18:00:10 +053090#define regmap_reg_range(low, high) { .range_min = low, .range_max = high, }
91
Davide Ciminaghi76aad392012-11-20 15:20:30 +010092/*
93 * A table of ranges including some yes ranges and some no ranges.
94 * If a register belongs to a no_range, the corresponding check function
95 * will return false. If a register belongs to a yes range, the corresponding
96 * check function will return true. "no_ranges" are searched first.
97 *
98 * @yes_ranges : pointer to an array of regmap ranges used as "yes ranges"
99 * @n_yes_ranges: size of the above array
100 * @no_ranges: pointer to an array of regmap ranges used as "no ranges"
101 * @n_no_ranges: size of the above array
102 */
103struct regmap_access_table {
104 const struct regmap_range *yes_ranges;
105 unsigned int n_yes_ranges;
106 const struct regmap_range *no_ranges;
107 unsigned int n_no_ranges;
108};
109
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200110typedef void (*regmap_lock)(void *);
111typedef void (*regmap_unlock)(void *);
112
Mark Brownbd20eb52011-08-19 18:09:38 +0900113/**
Mark Browndd898b22011-07-20 22:28:58 +0100114 * Configuration for the register map of a device.
115 *
Stephen Warrend3c242e2012-04-04 15:48:29 -0600116 * @name: Optional name of the regmap. Useful when a device has multiple
117 * register regions.
118 *
Mark Browndd898b22011-07-20 22:28:58 +0100119 * @reg_bits: Number of bits in a register address, mandatory.
Stephen Warrenf01ee602012-04-09 13:40:24 -0600120 * @reg_stride: The register address stride. Valid register addresses are a
121 * multiple of this value. If set to 0, a value of 1 will be
122 * used.
Mark Brown82159ba2012-01-18 10:52:25 +0000123 * @pad_bits: Number of bits of padding between register and value.
Mark Browndd898b22011-07-20 22:28:58 +0100124 * @val_bits: Number of bits in a register value, mandatory.
Mark Brown2e2ae662011-07-20 22:33:39 +0100125 *
Mark Brown3566cc92011-08-09 10:23:22 +0900126 * @writeable_reg: Optional callback returning true if the register
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100127 * can be written to. If this field is NULL but wr_table
128 * (see below) is not, the check is performed on such table
129 * (a register is writeable if it belongs to one of the ranges
130 * specified by wr_table).
Mark Brown3566cc92011-08-09 10:23:22 +0900131 * @readable_reg: Optional callback returning true if the register
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100132 * can be read from. If this field is NULL but rd_table
133 * (see below) is not, the check is performed on such table
134 * (a register is readable if it belongs to one of the ranges
135 * specified by rd_table).
Mark Brown3566cc92011-08-09 10:23:22 +0900136 * @volatile_reg: Optional callback returning true if the register
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100137 * value can't be cached. If this field is NULL but
138 * volatile_table (see below) is not, the check is performed on
139 * such table (a register is volatile if it belongs to one of
140 * the ranges specified by volatile_table).
Laszlo Pappbdc39642014-01-09 14:13:41 +0000141 * @precious_reg: Optional callback returning true if the register
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100142 * should not be read outside of a call from the driver
Laszlo Pappbdc39642014-01-09 14:13:41 +0000143 * (e.g., a clear on read interrupt status register). If this
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100144 * field is NULL but precious_table (see below) is not, the
145 * check is performed on such table (a register is precious if
146 * it belongs to one of the ranges specified by precious_table).
147 * @lock: Optional lock callback (overrides regmap's default lock
148 * function, based on spinlock or mutex).
149 * @unlock: As above for unlocking.
150 * @lock_arg: this field is passed as the only argument of lock/unlock
151 * functions (ignored in case regular lock/unlock functions
152 * are not overridden).
Andrey Smirnovd2a58842013-01-27 10:49:05 -0800153 * @reg_read: Optional callback that if filled will be used to perform
154 * all the reads from the registers. Should only be provided for
Laszlo Pappbdc39642014-01-09 14:13:41 +0000155 * devices whose read operation cannot be represented as a simple
156 * read operation on a bus such as SPI, I2C, etc. Most of the
157 * devices do not need this.
Andrey Smirnovd2a58842013-01-27 10:49:05 -0800158 * @reg_write: Same as above for writing.
159 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
160 * to perform locking. This field is ignored if custom lock/unlock
161 * functions are used (see fields lock/unlock of struct regmap_config).
162 * This field is a duplicate of a similar file in
163 * 'struct regmap_bus' and serves exact same purpose.
164 * Use it only for "no-bus" cases.
Mark Brownbd20eb52011-08-19 18:09:38 +0900165 * @max_register: Optional, specifies the maximum valid register index.
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100166 * @wr_table: Optional, points to a struct regmap_access_table specifying
167 * valid ranges for write access.
168 * @rd_table: As above, for read access.
169 * @volatile_table: As above, for volatile registers.
170 * @precious_table: As above, for precious registers.
Mark Brownbd20eb52011-08-19 18:09:38 +0900171 * @reg_defaults: Power on reset values for registers (for use with
172 * register cache support).
173 * @num_reg_defaults: Number of elements in reg_defaults.
Lars-Peter Clausen6f306442011-09-05 20:46:32 +0200174 *
175 * @read_flag_mask: Mask to be set in the top byte of the register when doing
176 * a read.
177 * @write_flag_mask: Mask to be set in the top byte of the register when doing
178 * a write. If both read_flag_mask and write_flag_mask are
179 * empty the regmap_bus default masks are used.
Ashish Jangam2e33caf2012-04-30 23:23:40 +0100180 * @use_single_rw: If set, converts the bulk read and write operations into
181 * a series of single read and write operations. This is useful
182 * for device that does not support bulk read and write.
Opensource [Anthony Olech]e894c3f2014-03-04 13:54:02 +0000183 * @can_multi_write: If set, the device supports the multi write mode of bulk
184 * write operations, if clear multi write requests will be
185 * split into individual write operations
Dimitris Papastamos9fabe242011-09-19 14:34:00 +0100186 *
187 * @cache_type: The actual cache type.
188 * @reg_defaults_raw: Power on reset values for registers (for use with
189 * register cache support).
190 * @num_reg_defaults_raw: Number of elements in reg_defaults_raw.
Stephen Warren141eba22012-05-24 10:47:26 -0600191 * @reg_format_endian: Endianness for formatted register addresses. If this is
192 * DEFAULT, the @reg_format_endian_default value from the
193 * regmap bus is used.
194 * @val_format_endian: Endianness for formatted register values. If this is
195 * DEFAULT, the @reg_format_endian_default value from the
196 * regmap bus is used.
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100197 *
198 * @ranges: Array of configuration entries for virtual address ranges.
199 * @num_ranges: Number of range configuration entries.
Mark Browndd898b22011-07-20 22:28:58 +0100200 */
Mark Brownb83a3132011-05-11 19:59:58 +0200201struct regmap_config {
Stephen Warrend3c242e2012-04-04 15:48:29 -0600202 const char *name;
203
Mark Brownb83a3132011-05-11 19:59:58 +0200204 int reg_bits;
Stephen Warrenf01ee602012-04-09 13:40:24 -0600205 int reg_stride;
Mark Brown82159ba2012-01-18 10:52:25 +0000206 int pad_bits;
Mark Brownb83a3132011-05-11 19:59:58 +0200207 int val_bits;
Mark Brown2e2ae662011-07-20 22:33:39 +0100208
Mark Brown2e2ae662011-07-20 22:33:39 +0100209 bool (*writeable_reg)(struct device *dev, unsigned int reg);
210 bool (*readable_reg)(struct device *dev, unsigned int reg);
211 bool (*volatile_reg)(struct device *dev, unsigned int reg);
Mark Brown18694882011-08-08 15:40:22 +0900212 bool (*precious_reg)(struct device *dev, unsigned int reg);
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200213 regmap_lock lock;
214 regmap_unlock unlock;
215 void *lock_arg;
Mark Brownbd20eb52011-08-19 18:09:38 +0900216
Andrey Smirnovd2a58842013-01-27 10:49:05 -0800217 int (*reg_read)(void *context, unsigned int reg, unsigned int *val);
218 int (*reg_write)(void *context, unsigned int reg, unsigned int val);
219
220 bool fast_io;
221
Mark Brownbd20eb52011-08-19 18:09:38 +0900222 unsigned int max_register;
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100223 const struct regmap_access_table *wr_table;
224 const struct regmap_access_table *rd_table;
225 const struct regmap_access_table *volatile_table;
226 const struct regmap_access_table *precious_table;
Lars-Peter Clausen720e4612011-11-16 16:28:17 +0100227 const struct reg_default *reg_defaults;
Dimitris Papastamos9fabe242011-09-19 14:34:00 +0100228 unsigned int num_reg_defaults;
229 enum regcache_type cache_type;
230 const void *reg_defaults_raw;
231 unsigned int num_reg_defaults_raw;
Lars-Peter Clausen6f306442011-09-05 20:46:32 +0200232
233 u8 read_flag_mask;
234 u8 write_flag_mask;
Ashish Jangam2e33caf2012-04-30 23:23:40 +0100235
236 bool use_single_rw;
Opensource [Anthony Olech]e894c3f2014-03-04 13:54:02 +0000237 bool can_multi_write;
Stephen Warren141eba22012-05-24 10:47:26 -0600238
239 enum regmap_endian reg_format_endian;
240 enum regmap_endian val_format_endian;
Mark Brown38e23192012-07-22 19:26:07 +0100241
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100242 const struct regmap_range_cfg *ranges;
Mark Browne3549cd2012-10-02 20:17:15 +0100243 unsigned int num_ranges;
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100244};
245
246/**
247 * Configuration for indirectly accessed or paged registers.
248 * Registers, mapped to this virtual range, are accessed in two steps:
249 * 1. page selector register update;
250 * 2. access through data window registers.
251 *
Mark Brownd058bb42012-10-03 12:40:47 +0100252 * @name: Descriptive name for diagnostics
253 *
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100254 * @range_min: Address of the lowest register address in virtual range.
255 * @range_max: Address of the highest register in virtual range.
256 *
257 * @page_sel_reg: Register with selector field.
258 * @page_sel_mask: Bit shift for selector value.
259 * @page_sel_shift: Bit mask for selector value.
260 *
261 * @window_start: Address of first (lowest) register in data window.
262 * @window_len: Number of registers in data window.
263 */
264struct regmap_range_cfg {
Mark Brownd058bb42012-10-03 12:40:47 +0100265 const char *name;
266
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100267 /* Registers of virtual address range */
268 unsigned int range_min;
269 unsigned int range_max;
270
271 /* Page selector for indirect addressing */
272 unsigned int selector_reg;
273 unsigned int selector_mask;
274 int selector_shift;
275
276 /* Data window (per each page) */
277 unsigned int window_start;
278 unsigned int window_len;
Mark Brownb83a3132011-05-11 19:59:58 +0200279};
280
Mark Brown0d509f22013-01-27 22:07:38 +0800281struct regmap_async;
282
Stephen Warren0135bbc2012-04-04 15:48:30 -0600283typedef int (*regmap_hw_write)(void *context, const void *data,
Mark Brownb83a3132011-05-11 19:59:58 +0200284 size_t count);
Stephen Warren0135bbc2012-04-04 15:48:30 -0600285typedef int (*regmap_hw_gather_write)(void *context,
Mark Brownb83a3132011-05-11 19:59:58 +0200286 const void *reg, size_t reg_len,
287 const void *val, size_t val_len);
Mark Brown0d509f22013-01-27 22:07:38 +0800288typedef int (*regmap_hw_async_write)(void *context,
289 const void *reg, size_t reg_len,
290 const void *val, size_t val_len,
291 struct regmap_async *async);
Stephen Warren0135bbc2012-04-04 15:48:30 -0600292typedef int (*regmap_hw_read)(void *context,
Mark Brownb83a3132011-05-11 19:59:58 +0200293 const void *reg_buf, size_t reg_size,
294 void *val_buf, size_t val_size);
Boris BREZILLON3ac17032014-04-17 11:40:11 +0200295typedef int (*regmap_hw_reg_read)(void *context, unsigned int reg,
296 unsigned int *val);
297typedef int (*regmap_hw_reg_write)(void *context, unsigned int reg,
298 unsigned int val);
Jon Ringle77792b12015-10-01 12:38:07 -0400299typedef int (*regmap_hw_reg_update_bits)(void *context, unsigned int reg,
300 unsigned int mask, unsigned int val);
Mark Brown0d509f22013-01-27 22:07:38 +0800301typedef struct regmap_async *(*regmap_hw_async_alloc)(void);
Stephen Warren0135bbc2012-04-04 15:48:30 -0600302typedef void (*regmap_hw_free_context)(void *context);
Mark Brownb83a3132011-05-11 19:59:58 +0200303
304/**
305 * Description of a hardware bus for the register map infrastructure.
306 *
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600307 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200308 * to perform locking. This field is ignored if custom lock/unlock
309 * functions are used (see fields lock/unlock of
310 * struct regmap_config).
Mark Brownb83a3132011-05-11 19:59:58 +0200311 * @write: Write operation.
312 * @gather_write: Write operation with split register/value, return -ENOTSUPP
313 * if not implemented on a given device.
Mark Brown0d509f22013-01-27 22:07:38 +0800314 * @async_write: Write operation which completes asynchronously, optional and
315 * must serialise with respect to non-async I/O.
Markus Pargmannc5f58f22015-08-21 10:26:40 +0200316 * @reg_write: Write a single register value to the given register address. This
317 * write operation has to complete when returning from the function.
Mark Brownb83a3132011-05-11 19:59:58 +0200318 * @read: Read operation. Data is returned in the buffer used to transmit
319 * data.
Markus Pargmannc5f58f22015-08-21 10:26:40 +0200320 * @reg_read: Read a single register value from a given register address.
321 * @free_context: Free context.
Mark Brown0d509f22013-01-27 22:07:38 +0800322 * @async_alloc: Allocate a regmap_async() structure.
Mark Brownb83a3132011-05-11 19:59:58 +0200323 * @read_flag_mask: Mask to be set in the top byte of the register when doing
324 * a read.
Stephen Warren141eba22012-05-24 10:47:26 -0600325 * @reg_format_endian_default: Default endianness for formatted register
326 * addresses. Used when the regmap_config specifies DEFAULT. If this is
327 * DEFAULT, BIG is assumed.
328 * @val_format_endian_default: Default endianness for formatted register
329 * values. Used when the regmap_config specifies DEFAULT. If this is
330 * DEFAULT, BIG is assumed.
Markus Pargmannadaac452015-08-30 09:33:53 +0200331 * @max_raw_read: Max raw read size that can be used on the bus.
332 * @max_raw_write: Max raw write size that can be used on the bus.
Mark Brownb83a3132011-05-11 19:59:58 +0200333 */
334struct regmap_bus {
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600335 bool fast_io;
Mark Brownb83a3132011-05-11 19:59:58 +0200336 regmap_hw_write write;
337 regmap_hw_gather_write gather_write;
Mark Brown0d509f22013-01-27 22:07:38 +0800338 regmap_hw_async_write async_write;
Boris BREZILLON3ac17032014-04-17 11:40:11 +0200339 regmap_hw_reg_write reg_write;
Jon Ringle77792b12015-10-01 12:38:07 -0400340 regmap_hw_reg_update_bits reg_update_bits;
Mark Brownb83a3132011-05-11 19:59:58 +0200341 regmap_hw_read read;
Boris BREZILLON3ac17032014-04-17 11:40:11 +0200342 regmap_hw_reg_read reg_read;
Stephen Warren0135bbc2012-04-04 15:48:30 -0600343 regmap_hw_free_context free_context;
Mark Brown0d509f22013-01-27 22:07:38 +0800344 regmap_hw_async_alloc async_alloc;
Mark Brownb83a3132011-05-11 19:59:58 +0200345 u8 read_flag_mask;
Stephen Warren141eba22012-05-24 10:47:26 -0600346 enum regmap_endian reg_format_endian_default;
347 enum regmap_endian val_format_endian_default;
Markus Pargmannadaac452015-08-30 09:33:53 +0200348 size_t max_raw_read;
349 size_t max_raw_write;
Mark Brownb83a3132011-05-11 19:59:58 +0200350};
351
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800352/*
353 * __regmap_init functions.
354 *
355 * These functions take a lock key and name parameter, and should not be called
356 * directly. Instead, use the regmap_init macros that generate a key and name
357 * for each call.
358 */
359struct regmap *__regmap_init(struct device *dev,
360 const struct regmap_bus *bus,
361 void *bus_context,
362 const struct regmap_config *config,
363 struct lock_class_key *lock_key,
364 const char *lock_name);
365struct regmap *__regmap_init_i2c(struct i2c_client *i2c,
366 const struct regmap_config *config,
367 struct lock_class_key *lock_key,
368 const char *lock_name);
369struct regmap *__regmap_init_spi(struct spi_device *dev,
370 const struct regmap_config *config,
371 struct lock_class_key *lock_key,
372 const char *lock_name);
373struct regmap *__regmap_init_spmi_base(struct spmi_device *dev,
374 const struct regmap_config *config,
375 struct lock_class_key *lock_key,
376 const char *lock_name);
377struct regmap *__regmap_init_spmi_ext(struct spmi_device *dev,
378 const struct regmap_config *config,
379 struct lock_class_key *lock_key,
380 const char *lock_name);
381struct regmap *__regmap_init_mmio_clk(struct device *dev, const char *clk_id,
382 void __iomem *regs,
383 const struct regmap_config *config,
384 struct lock_class_key *lock_key,
385 const char *lock_name);
386struct regmap *__regmap_init_ac97(struct snd_ac97 *ac97,
387 const struct regmap_config *config,
388 struct lock_class_key *lock_key,
389 const char *lock_name);
390
391struct regmap *__devm_regmap_init(struct device *dev,
392 const struct regmap_bus *bus,
393 void *bus_context,
394 const struct regmap_config *config,
395 struct lock_class_key *lock_key,
396 const char *lock_name);
397struct regmap *__devm_regmap_init_i2c(struct i2c_client *i2c,
398 const struct regmap_config *config,
399 struct lock_class_key *lock_key,
400 const char *lock_name);
401struct regmap *__devm_regmap_init_spi(struct spi_device *dev,
402 const struct regmap_config *config,
403 struct lock_class_key *lock_key,
404 const char *lock_name);
405struct regmap *__devm_regmap_init_spmi_base(struct spmi_device *dev,
406 const struct regmap_config *config,
407 struct lock_class_key *lock_key,
408 const char *lock_name);
409struct regmap *__devm_regmap_init_spmi_ext(struct spmi_device *dev,
410 const struct regmap_config *config,
411 struct lock_class_key *lock_key,
412 const char *lock_name);
413struct regmap *__devm_regmap_init_mmio_clk(struct device *dev,
414 const char *clk_id,
415 void __iomem *regs,
416 const struct regmap_config *config,
417 struct lock_class_key *lock_key,
418 const char *lock_name);
419struct regmap *__devm_regmap_init_ac97(struct snd_ac97 *ac97,
420 const struct regmap_config *config,
421 struct lock_class_key *lock_key,
422 const char *lock_name);
423
424/*
425 * Wrapper for regmap_init macros to include a unique lockdep key and name
426 * for each call. No-op if CONFIG_LOCKDEP is not set.
427 *
428 * @fn: Real function to call (in the form __[*_]regmap_init[_*])
429 * @name: Config variable name (#config in the calling macro)
430 **/
431#ifdef CONFIG_LOCKDEP
432#define __regmap_lockdep_wrapper(fn, name, ...) \
433( \
434 ({ \
435 static struct lock_class_key _key; \
436 fn(__VA_ARGS__, &_key, \
437 KBUILD_BASENAME ":" \
438 __stringify(__LINE__) ":" \
439 "(" name ")->lock"); \
440 }) \
441)
442#else
443#define __regmap_lockdep_wrapper(fn, name, ...) fn(__VA_ARGS__, NULL, NULL)
444#endif
445
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800446/**
447 * regmap_init(): Initialise register map
448 *
449 * @dev: Device that will be interacted with
450 * @bus: Bus-specific callbacks to use with device
451 * @bus_context: Data passed to bus-specific callbacks
452 * @config: Configuration for register map
453 *
454 * The return value will be an ERR_PTR() on error or a valid pointer to
455 * a struct regmap. This function should generally not be called
456 * directly, it should be called by bus-specific init functions.
457 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800458#define regmap_init(dev, bus, bus_context, config) \
459 __regmap_lockdep_wrapper(__regmap_init, #config, \
460 dev, bus, bus_context, config)
Michal Simek6cfec042014-02-10 16:22:33 +0100461int regmap_attach_dev(struct device *dev, struct regmap *map,
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800462 const struct regmap_config *config);
Mark Browna676f082011-05-12 11:42:10 +0200463
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800464/**
465 * regmap_init_i2c(): Initialise register map
466 *
467 * @i2c: Device that will be interacted with
468 * @config: Configuration for register map
469 *
470 * The return value will be an ERR_PTR() on error or a valid pointer to
471 * a struct regmap.
472 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800473#define regmap_init_i2c(i2c, config) \
474 __regmap_lockdep_wrapper(__regmap_init_i2c, #config, \
475 i2c, config)
Mark Brown22853222014-11-18 19:45:51 +0100476
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800477/**
478 * regmap_init_spi(): Initialise register map
479 *
480 * @spi: Device that will be interacted with
481 * @config: Configuration for register map
482 *
483 * The return value will be an ERR_PTR() on error or a valid pointer to
484 * a struct regmap.
485 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800486#define regmap_init_spi(dev, config) \
487 __regmap_lockdep_wrapper(__regmap_init_spi, #config, \
488 dev, config)
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800489
490/**
491 * regmap_init_spmi_base(): Create regmap for the Base register space
492 * @sdev: SPMI 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_spmi_base(dev, config) \
499 __regmap_lockdep_wrapper(__regmap_init_spmi_base, #config, \
500 dev, config)
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800501
502/**
503 * regmap_init_spmi_ext(): Create regmap for Ext register space
504 * @sdev: 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_ext(dev, config) \
511 __regmap_lockdep_wrapper(__regmap_init_spmi_ext, #config, \
512 dev, config)
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800513
514/**
515 * regmap_init_mmio_clk(): Initialise register map with register clock
516 *
517 * @dev: Device that will be interacted with
518 * @clk_id: register clock consumer ID
519 * @regs: Pointer to memory-mapped IO region
520 * @config: Configuration for register map
521 *
522 * The return value will be an ERR_PTR() on error or a valid pointer to
523 * a struct regmap.
524 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800525#define regmap_init_mmio_clk(dev, clk_id, regs, config) \
526 __regmap_lockdep_wrapper(__regmap_init_mmio_clk, #config, \
527 dev, clk_id, regs, config)
Philipp Zabel878ec672013-02-14 17:39:08 +0100528
529/**
530 * regmap_init_mmio(): Initialise register map
531 *
532 * @dev: Device that will be interacted with
533 * @regs: Pointer to memory-mapped IO region
534 * @config: Configuration for register map
535 *
536 * The return value will be an ERR_PTR() on error or a valid pointer to
537 * a struct regmap.
538 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800539#define regmap_init_mmio(dev, regs, config) \
540 regmap_init_mmio_clk(dev, NULL, regs, config)
Philipp Zabel878ec672013-02-14 17:39:08 +0100541
542/**
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800543 * regmap_init_ac97(): Initialise AC'97 register map
544 *
545 * @ac97: Device that will be interacted with
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 */
551#define regmap_init_ac97(ac97, config) \
552 __regmap_lockdep_wrapper(__regmap_init_ac97, #config, \
553 ac97, config)
554bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg);
555
556/**
557 * devm_regmap_init(): Initialise managed register map
558 *
559 * @dev: Device that will be interacted with
560 * @bus: Bus-specific callbacks to use with device
561 * @bus_context: Data passed to bus-specific callbacks
562 * @config: Configuration for register map
563 *
564 * The return value will be an ERR_PTR() on error or a valid pointer
565 * to a struct regmap. This function should generally not be called
566 * directly, it should be called by bus-specific init functions. The
567 * map will be automatically freed by the device management code.
568 */
569#define devm_regmap_init(dev, bus, bus_context, config) \
570 __regmap_lockdep_wrapper(__devm_regmap_init, #config, \
571 dev, bus, bus_context, config)
572
573/**
574 * devm_regmap_init_i2c(): Initialise managed register map
575 *
576 * @i2c: Device that will be interacted with
577 * @config: Configuration for register map
578 *
579 * The return value will be an ERR_PTR() on error or a valid pointer
580 * to a struct regmap. The regmap will be automatically freed by the
581 * device management code.
582 */
583#define devm_regmap_init_i2c(i2c, config) \
584 __regmap_lockdep_wrapper(__devm_regmap_init_i2c, #config, \
585 i2c, config)
586
587/**
588 * devm_regmap_init_spi(): Initialise register map
589 *
590 * @spi: Device that will be interacted with
591 * @config: Configuration for register map
592 *
593 * The return value will be an ERR_PTR() on error or a valid pointer
594 * to a struct regmap. The map will be automatically freed by the
595 * device management code.
596 */
597#define devm_regmap_init_spi(dev, config) \
598 __regmap_lockdep_wrapper(__devm_regmap_init_spi, #config, \
599 dev, config)
600
601/**
602 * devm_regmap_init_spmi_base(): Create managed regmap for Base register space
603 * @sdev: SPMI device that will be interacted with
604 * @config: Configuration for register map
605 *
606 * The return value will be an ERR_PTR() on error or a valid pointer
607 * to a struct regmap. The regmap will be automatically freed by the
608 * device management code.
609 */
610#define devm_regmap_init_spmi_base(dev, config) \
611 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_base, #config, \
612 dev, config)
613
614/**
615 * devm_regmap_init_spmi_ext(): Create managed regmap for Ext register space
616 * @sdev: SPMI device that will be interacted with
617 * @config: Configuration for register map
618 *
619 * The return value will be an ERR_PTR() on error or a valid pointer
620 * to a struct regmap. The regmap will be automatically freed by the
621 * device management code.
622 */
623#define devm_regmap_init_spmi_ext(dev, config) \
624 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_ext, #config, \
625 dev, config)
626
627/**
628 * devm_regmap_init_mmio_clk(): Initialise managed register map with clock
629 *
630 * @dev: Device that will be interacted with
631 * @clk_id: register clock consumer ID
632 * @regs: Pointer to memory-mapped IO region
633 * @config: Configuration for register map
634 *
635 * The return value will be an ERR_PTR() on error or a valid pointer
636 * to a struct regmap. The regmap will be automatically freed by the
637 * device management code.
638 */
639#define devm_regmap_init_mmio_clk(dev, clk_id, regs, config) \
640 __regmap_lockdep_wrapper(__devm_regmap_init_mmio_clk, #config, \
641 dev, clk_id, regs, config)
Philipp Zabel878ec672013-02-14 17:39:08 +0100642
643/**
644 * devm_regmap_init_mmio(): Initialise managed register map
645 *
646 * @dev: Device that will be interacted with
647 * @regs: Pointer to memory-mapped IO region
648 * @config: Configuration for register map
649 *
650 * The return value will be an ERR_PTR() on error or a valid pointer
651 * to a struct regmap. The regmap will be automatically freed by the
652 * device management code.
653 */
Nicolas Boichat3cfe7a72015-07-08 14:30:18 +0800654#define devm_regmap_init_mmio(dev, regs, config) \
655 devm_regmap_init_mmio_clk(dev, NULL, regs, config)
Mark Brownc0eb4672012-01-30 19:56:52 +0000656
Nicolas Boichat1ed81112015-08-11 18:04:21 +0800657/**
658 * devm_regmap_init_ac97(): Initialise AC'97 register map
659 *
660 * @ac97: Device that will be interacted with
661 * @config: Configuration for register map
662 *
663 * The return value will be an ERR_PTR() on error or a valid pointer
664 * to a struct regmap. The regmap will be automatically freed by the
665 * device management code.
666 */
667#define devm_regmap_init_ac97(ac97, config) \
668 __regmap_lockdep_wrapper(__devm_regmap_init_ac97, #config, \
669 ac97, config)
Mark Brownb83a3132011-05-11 19:59:58 +0200670
671void regmap_exit(struct regmap *map);
672int regmap_reinit_cache(struct regmap *map,
673 const struct regmap_config *config);
Mark Brown72b39f62012-05-08 17:44:40 +0100674struct regmap *dev_get_regmap(struct device *dev, const char *name);
Tuomas Tynkkynen8d7d3972014-07-21 18:38:47 +0300675struct device *regmap_get_device(struct regmap *map);
Mark Brownb83a3132011-05-11 19:59:58 +0200676int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
Mark Brown915f4412013-10-09 13:30:10 +0100677int regmap_write_async(struct regmap *map, unsigned int reg, unsigned int val);
Mark Brownb83a3132011-05-11 19:59:58 +0200678int regmap_raw_write(struct regmap *map, unsigned int reg,
679 const void *val, size_t val_len);
Laxman Dewangan8eaeb212012-02-12 19:49:43 +0530680int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
681 size_t val_count);
Nariman Poushin8019ff62015-07-16 16:36:21 +0100682int regmap_multi_reg_write(struct regmap *map, const struct reg_sequence *regs,
Anthony Oleche33fabd2013-10-11 15:31:11 +0100683 int num_regs);
Charles Keepax1d5b40b2014-02-25 13:45:50 +0000684int regmap_multi_reg_write_bypassed(struct regmap *map,
Nariman Poushin8019ff62015-07-16 16:36:21 +0100685 const struct reg_sequence *regs,
Charles Keepax1d5b40b2014-02-25 13:45:50 +0000686 int num_regs);
Mark Brown0d509f22013-01-27 22:07:38 +0800687int regmap_raw_write_async(struct regmap *map, unsigned int reg,
688 const void *val, size_t val_len);
Mark Brownb83a3132011-05-11 19:59:58 +0200689int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
690int regmap_raw_read(struct regmap *map, unsigned int reg,
691 void *val, size_t val_len);
692int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
693 size_t val_count);
Kuninori Morimoto91d31b92016-02-15 05:22:18 +0000694int regmap_update_bits_base(struct regmap *map, unsigned int reg,
695 unsigned int mask, unsigned int val,
696 bool *change, bool async, bool force);
Mark Brownb83a3132011-05-11 19:59:58 +0200697int regmap_update_bits(struct regmap *map, unsigned int reg,
698 unsigned int mask, unsigned int val);
Kuninori Morimotofd4b7286c2015-06-16 08:52:39 +0000699int regmap_write_bits(struct regmap *map, unsigned int reg,
700 unsigned int mask, unsigned int val);
Mark Brown915f4412013-10-09 13:30:10 +0100701int regmap_update_bits_async(struct regmap *map, unsigned int reg,
702 unsigned int mask, unsigned int val);
Mark Brown018690d2011-11-29 20:10:36 +0000703int regmap_update_bits_check(struct regmap *map, unsigned int reg,
704 unsigned int mask, unsigned int val,
705 bool *change);
Mark Brown915f4412013-10-09 13:30:10 +0100706int regmap_update_bits_check_async(struct regmap *map, unsigned int reg,
707 unsigned int mask, unsigned int val,
708 bool *change);
Mark Browna6539c32012-02-17 14:20:14 -0800709int regmap_get_val_bytes(struct regmap *map);
Srinivas Kandagatla668abc72015-05-21 17:42:43 +0100710int regmap_get_max_register(struct regmap *map);
Srinivas Kandagatlaa2f776c2015-05-21 17:42:54 +0100711int regmap_get_reg_stride(struct regmap *map);
Mark Brown0d509f22013-01-27 22:07:38 +0800712int regmap_async_complete(struct regmap *map);
Mark Brown221ad7f2013-03-26 21:24:20 +0000713bool regmap_can_raw_write(struct regmap *map);
Markus Pargmannf50c9eb2015-08-30 09:33:54 +0200714size_t regmap_get_raw_read_max(struct regmap *map);
715size_t regmap_get_raw_write_max(struct regmap *map);
Mark Brownb83a3132011-05-11 19:59:58 +0200716
Mark Brown39a58432011-09-19 18:21:49 +0100717int regcache_sync(struct regmap *map);
Mark Brown4d4cfd12012-02-23 20:53:37 +0000718int regcache_sync_region(struct regmap *map, unsigned int min,
719 unsigned int max);
Mark Brown697e85b2013-05-08 13:55:22 +0100720int regcache_drop_region(struct regmap *map, unsigned int min,
721 unsigned int max);
Mark Brown92afb282011-09-19 18:22:14 +0100722void regcache_cache_only(struct regmap *map, bool enable);
Dimitris Papastamos6eb0f5e2011-09-29 14:36:27 +0100723void regcache_cache_bypass(struct regmap *map, bool enable);
Mark Brown8ae0d7e2011-10-26 10:34:22 +0200724void regcache_mark_dirty(struct regmap *map);
Mark Brown92afb282011-09-19 18:22:14 +0100725
Mark Brown154881e2013-05-08 13:55:23 +0100726bool regmap_check_range_table(struct regmap *map, unsigned int reg,
727 const struct regmap_access_table *table);
728
Nariman Poushin8019ff62015-07-16 16:36:21 +0100729int regmap_register_patch(struct regmap *map, const struct reg_sequence *regs,
Mark Brown22f0d902012-01-21 12:01:14 +0000730 int num_regs);
Nenghua Cao13ff50c2014-02-19 18:44:13 +0800731int regmap_parse_val(struct regmap *map, const void *buf,
732 unsigned int *val);
Mark Brown22f0d902012-01-21 12:01:14 +0000733
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100734static inline bool regmap_reg_in_range(unsigned int reg,
735 const struct regmap_range *range)
736{
737 return reg >= range->range_min && reg <= range->range_max;
738}
739
740bool regmap_reg_in_ranges(unsigned int reg,
741 const struct regmap_range *ranges,
742 unsigned int nranges);
743
Mark Brownf8beab22011-10-28 23:50:49 +0200744/**
Srinivas Kandagatla67252282013-06-11 13:18:15 +0100745 * Description of an register field
746 *
747 * @reg: Offset of the register within the regmap bank
748 * @lsb: lsb of the register field.
Bintian Wangf27b37f2015-01-27 20:50:29 +0800749 * @msb: msb of the register field.
Kuninori Morimotoa0102372013-09-01 20:30:50 -0700750 * @id_size: port size if it has some ports
751 * @id_offset: address offset for each ports
Srinivas Kandagatla67252282013-06-11 13:18:15 +0100752 */
753struct reg_field {
754 unsigned int reg;
755 unsigned int lsb;
756 unsigned int msb;
Kuninori Morimotoa0102372013-09-01 20:30:50 -0700757 unsigned int id_size;
758 unsigned int id_offset;
Srinivas Kandagatla67252282013-06-11 13:18:15 +0100759};
760
761#define REG_FIELD(_reg, _lsb, _msb) { \
762 .reg = _reg, \
763 .lsb = _lsb, \
764 .msb = _msb, \
765 }
766
767struct regmap_field *regmap_field_alloc(struct regmap *regmap,
768 struct reg_field reg_field);
769void regmap_field_free(struct regmap_field *field);
770
771struct regmap_field *devm_regmap_field_alloc(struct device *dev,
772 struct regmap *regmap, struct reg_field reg_field);
773void devm_regmap_field_free(struct device *dev, struct regmap_field *field);
774
775int regmap_field_read(struct regmap_field *field, unsigned int *val);
776int regmap_field_write(struct regmap_field *field, unsigned int val);
Kuninori Morimotofdf20022013-09-01 20:24:50 -0700777int regmap_field_update_bits(struct regmap_field *field,
778 unsigned int mask, unsigned int val);
Srinivas Kandagatla67252282013-06-11 13:18:15 +0100779
Kuninori Morimotoa0102372013-09-01 20:30:50 -0700780int regmap_fields_write(struct regmap_field *field, unsigned int id,
781 unsigned int val);
Kuninori Morimotoe874e6c2015-06-16 08:52:55 +0000782int regmap_fields_force_write(struct regmap_field *field, unsigned int id,
783 unsigned int val);
Kuninori Morimotoa0102372013-09-01 20:30:50 -0700784int regmap_fields_read(struct regmap_field *field, unsigned int id,
785 unsigned int *val);
786int regmap_fields_update_bits(struct regmap_field *field, unsigned int id,
787 unsigned int mask, unsigned int val);
Srinivas Kandagatla67252282013-06-11 13:18:15 +0100788
789/**
Mark Brownf8beab22011-10-28 23:50:49 +0200790 * Description of an IRQ for the generic regmap irq_chip.
791 *
792 * @reg_offset: Offset of the status/mask register within the bank
793 * @mask: Mask used to flag/control the register.
Laxman Dewangan7a78479f2015-12-22 18:25:26 +0530794 * @type_reg_offset: Offset register for the irq type setting.
795 * @type_rising_mask: Mask bit to configure RISING type irq.
796 * @type_falling_mask: Mask bit to configure FALLING type irq.
Mark Brownf8beab22011-10-28 23:50:49 +0200797 */
798struct regmap_irq {
799 unsigned int reg_offset;
800 unsigned int mask;
Laxman Dewangan7a78479f2015-12-22 18:25:26 +0530801 unsigned int type_reg_offset;
802 unsigned int type_rising_mask;
803 unsigned int type_falling_mask;
Mark Brownf8beab22011-10-28 23:50:49 +0200804};
805
Qipeng Zhab4fe8ba2015-09-15 00:39:17 +0800806#define REGMAP_IRQ_REG(_irq, _off, _mask) \
807 [_irq] = { .reg_offset = (_off), .mask = (_mask) }
808
Mark Brownf8beab22011-10-28 23:50:49 +0200809/**
810 * Description of a generic regmap irq_chip. This is not intended to
811 * handle every possible interrupt controller, but it should handle a
812 * substantial proportion of those that are found in the wild.
813 *
814 * @name: Descriptive name for IRQ controller.
815 *
816 * @status_base: Base status register address.
817 * @mask_base: Base mask register address.
Guo Zeng7b7d1962015-09-17 05:23:20 +0000818 * @unmask_base: Base unmask register address. for chips who have
819 * separate mask and unmask registers
Alexander Shiyand3233432013-12-15 13:36:51 +0400820 * @ack_base: Base ack address. If zero then the chip is clear on read.
821 * Using zero value is possible with @use_ack bit.
Mark Browna43fd502012-06-05 14:34:03 +0100822 * @wake_base: Base address for wake enables. If zero unsupported.
Laxman Dewangan7a78479f2015-12-22 18:25:26 +0530823 * @type_base: Base address for irq type. If zero unsupported.
Graeme Gregory022f926a2012-05-14 22:40:43 +0900824 * @irq_reg_stride: Stride to use for chips where registers are not contiguous.
Philipp Zabel2753e6f2013-07-22 17:15:52 +0200825 * @init_ack_masked: Ack all masked interrupts once during initalization.
Philipp Zabel68622bd2013-07-24 10:26:48 +0200826 * @mask_invert: Inverted mask register: cleared bits are masked out.
Alexander Shiyand3233432013-12-15 13:36:51 +0400827 * @use_ack: Use @ack register even if it is zero.
Guo Zenga650fdd2015-09-17 05:23:21 +0000828 * @ack_invert: Inverted ack register: cleared bits for ack.
Philipp Zabel68622bd2013-07-24 10:26:48 +0200829 * @wake_invert: Inverted wake register: cleared bits are wake enabled.
Laxman Dewangan7a78479f2015-12-22 18:25:26 +0530830 * @type_invert: Invert the type flags.
Mark Brown0c00c502012-07-24 15:41:19 +0100831 * @runtime_pm: Hold a runtime PM lock on the device when accessing it.
Mark Brownf8beab22011-10-28 23:50:49 +0200832 *
833 * @num_regs: Number of registers in each control bank.
834 * @irqs: Descriptors for individual IRQs. Interrupt numbers are
835 * assigned based on the index in the array of the interrupt.
836 * @num_irqs: Number of descriptors.
Laxman Dewangan7a78479f2015-12-22 18:25:26 +0530837 * @num_type_reg: Number of type registers.
838 * @type_reg_stride: Stride to use for chips where type registers are not
839 * contiguous.
Mark Brownf8beab22011-10-28 23:50:49 +0200840 */
841struct regmap_irq_chip {
842 const char *name;
843
844 unsigned int status_base;
845 unsigned int mask_base;
Guo Zeng7b7d1962015-09-17 05:23:20 +0000846 unsigned int unmask_base;
Mark Brownf8beab22011-10-28 23:50:49 +0200847 unsigned int ack_base;
Mark Browna43fd502012-06-05 14:34:03 +0100848 unsigned int wake_base;
Laxman Dewangan7a78479f2015-12-22 18:25:26 +0530849 unsigned int type_base;
Graeme Gregory022f926a2012-05-14 22:40:43 +0900850 unsigned int irq_reg_stride;
Philipp Zabelf484f7a2013-07-24 10:26:42 +0200851 bool init_ack_masked:1;
852 bool mask_invert:1;
Alexander Shiyand3233432013-12-15 13:36:51 +0400853 bool use_ack:1;
Guo Zenga650fdd2015-09-17 05:23:21 +0000854 bool ack_invert:1;
Philipp Zabelf484f7a2013-07-24 10:26:42 +0200855 bool wake_invert:1;
856 bool runtime_pm:1;
Laxman Dewangan7a78479f2015-12-22 18:25:26 +0530857 bool type_invert:1;
Mark Brownf8beab22011-10-28 23:50:49 +0200858
859 int num_regs;
860
861 const struct regmap_irq *irqs;
862 int num_irqs;
Laxman Dewangan7a78479f2015-12-22 18:25:26 +0530863
864 int num_type_reg;
865 unsigned int type_reg_stride;
Mark Brownf8beab22011-10-28 23:50:49 +0200866};
867
868struct regmap_irq_chip_data;
869
870int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
Mark Brownb026ddb2012-05-31 21:01:46 +0100871 int irq_base, const struct regmap_irq_chip *chip,
Mark Brownf8beab22011-10-28 23:50:49 +0200872 struct regmap_irq_chip_data **data);
873void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data);
Mark Brown209a6002011-12-05 16:10:15 +0000874int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data);
Mark Brown4af8be62012-05-13 10:59:56 +0100875int regmap_irq_get_virq(struct regmap_irq_chip_data *data, int irq);
Mark Brown90f790d2012-08-20 21:45:05 +0100876struct irq_domain *regmap_irq_get_domain(struct regmap_irq_chip_data *data);
Mark Brownb83a3132011-05-11 19:59:58 +0200877
Mark Brown9cde5fc2012-02-17 14:49:51 -0800878#else
879
880/*
881 * These stubs should only ever be called by generic code which has
882 * regmap based facilities, if they ever get called at runtime
883 * something is going wrong and something probably needs to select
884 * REGMAP.
885 */
886
887static inline int regmap_write(struct regmap *map, unsigned int reg,
888 unsigned int val)
889{
890 WARN_ONCE(1, "regmap API is disabled");
891 return -EINVAL;
892}
893
Mark Brown915f4412013-10-09 13:30:10 +0100894static inline int regmap_write_async(struct regmap *map, unsigned int reg,
895 unsigned int val)
896{
897 WARN_ONCE(1, "regmap API is disabled");
898 return -EINVAL;
899}
900
Mark Brown9cde5fc2012-02-17 14:49:51 -0800901static inline int regmap_raw_write(struct regmap *map, unsigned int reg,
902 const void *val, size_t val_len)
903{
904 WARN_ONCE(1, "regmap API is disabled");
905 return -EINVAL;
906}
907
Mark Brown0d509f22013-01-27 22:07:38 +0800908static inline int regmap_raw_write_async(struct regmap *map, unsigned int reg,
909 const void *val, size_t val_len)
910{
911 WARN_ONCE(1, "regmap API is disabled");
912 return -EINVAL;
913}
914
Mark Brown9cde5fc2012-02-17 14:49:51 -0800915static inline int regmap_bulk_write(struct regmap *map, unsigned int reg,
916 const void *val, size_t val_count)
917{
918 WARN_ONCE(1, "regmap API is disabled");
919 return -EINVAL;
920}
921
922static inline int regmap_read(struct regmap *map, unsigned int reg,
923 unsigned int *val)
924{
925 WARN_ONCE(1, "regmap API is disabled");
926 return -EINVAL;
927}
928
929static inline int regmap_raw_read(struct regmap *map, unsigned int reg,
930 void *val, size_t val_len)
931{
932 WARN_ONCE(1, "regmap API is disabled");
933 return -EINVAL;
934}
935
936static inline int regmap_bulk_read(struct regmap *map, unsigned int reg,
937 void *val, size_t val_count)
938{
939 WARN_ONCE(1, "regmap API is disabled");
940 return -EINVAL;
941}
942
Kuninori Morimoto91d31b92016-02-15 05:22:18 +0000943static inline int regmap_update_bits_base(struct regmap *map, unsigned int reg,
944 unsigned int mask, unsigned int val,
945 bool *change, bool async, bool force)
946{
947 WARN_ONCE(1, "regmap API is disabled");
948 return -EINVAL;
949}
950
Mark Brown9cde5fc2012-02-17 14:49:51 -0800951static inline int regmap_update_bits(struct regmap *map, unsigned int reg,
952 unsigned int mask, unsigned int val)
953{
954 WARN_ONCE(1, "regmap API is disabled");
955 return -EINVAL;
956}
957
Kuninori Morimotofd4b7286c2015-06-16 08:52:39 +0000958static inline int regmap_write_bits(struct regmap *map, unsigned int reg,
959 unsigned int mask, unsigned int val)
960{
961 WARN_ONCE(1, "regmap API is disabled");
962 return -EINVAL;
963}
964
Mark Brown915f4412013-10-09 13:30:10 +0100965static inline int regmap_update_bits_async(struct regmap *map,
966 unsigned int reg,
967 unsigned int mask, unsigned int val)
968{
969 WARN_ONCE(1, "regmap API is disabled");
970 return -EINVAL;
971}
972
Mark Brown9cde5fc2012-02-17 14:49:51 -0800973static inline int regmap_update_bits_check(struct regmap *map,
974 unsigned int reg,
975 unsigned int mask, unsigned int val,
976 bool *change)
977{
978 WARN_ONCE(1, "regmap API is disabled");
979 return -EINVAL;
980}
981
Mark Brown915f4412013-10-09 13:30:10 +0100982static inline int regmap_update_bits_check_async(struct regmap *map,
983 unsigned int reg,
984 unsigned int mask,
985 unsigned int val,
986 bool *change)
987{
988 WARN_ONCE(1, "regmap API is disabled");
989 return -EINVAL;
990}
991
Mark Brown9cde5fc2012-02-17 14:49:51 -0800992static inline int regmap_get_val_bytes(struct regmap *map)
993{
994 WARN_ONCE(1, "regmap API is disabled");
995 return -EINVAL;
996}
997
Srinivas Kandagatla668abc72015-05-21 17:42:43 +0100998static inline int regmap_get_max_register(struct regmap *map)
999{
1000 WARN_ONCE(1, "regmap API is disabled");
1001 return -EINVAL;
1002}
1003
Srinivas Kandagatlaa2f776c2015-05-21 17:42:54 +01001004static inline int regmap_get_reg_stride(struct regmap *map)
1005{
1006 WARN_ONCE(1, "regmap API is disabled");
1007 return -EINVAL;
1008}
1009
Mark Brown9cde5fc2012-02-17 14:49:51 -08001010static inline int regcache_sync(struct regmap *map)
1011{
1012 WARN_ONCE(1, "regmap API is disabled");
1013 return -EINVAL;
1014}
1015
Mark Browna313f9f2012-02-23 19:49:43 +00001016static inline int regcache_sync_region(struct regmap *map, unsigned int min,
1017 unsigned int max)
1018{
1019 WARN_ONCE(1, "regmap API is disabled");
1020 return -EINVAL;
1021}
1022
Mark Brown697e85b2013-05-08 13:55:22 +01001023static inline int regcache_drop_region(struct regmap *map, unsigned int min,
1024 unsigned int max)
1025{
1026 WARN_ONCE(1, "regmap API is disabled");
1027 return -EINVAL;
1028}
1029
Mark Brown9cde5fc2012-02-17 14:49:51 -08001030static inline void regcache_cache_only(struct regmap *map, bool enable)
1031{
1032 WARN_ONCE(1, "regmap API is disabled");
1033}
1034
1035static inline void regcache_cache_bypass(struct regmap *map, bool enable)
1036{
1037 WARN_ONCE(1, "regmap API is disabled");
1038}
1039
1040static inline void regcache_mark_dirty(struct regmap *map)
1041{
1042 WARN_ONCE(1, "regmap API is disabled");
1043}
1044
Mark Brown0d509f22013-01-27 22:07:38 +08001045static inline void regmap_async_complete(struct regmap *map)
1046{
1047 WARN_ONCE(1, "regmap API is disabled");
1048}
1049
Mark Brown9cde5fc2012-02-17 14:49:51 -08001050static inline int regmap_register_patch(struct regmap *map,
Daniel Wagnera6baa3d2015-11-30 16:20:15 +01001051 const struct reg_sequence *regs,
Mark Brown9cde5fc2012-02-17 14:49:51 -08001052 int num_regs)
1053{
1054 WARN_ONCE(1, "regmap API is disabled");
1055 return -EINVAL;
1056}
1057
Nenghua Cao13ff50c2014-02-19 18:44:13 +08001058static inline int regmap_parse_val(struct regmap *map, const void *buf,
1059 unsigned int *val)
1060{
1061 WARN_ONCE(1, "regmap API is disabled");
1062 return -EINVAL;
1063}
1064
Mark Brown72b39f62012-05-08 17:44:40 +01001065static inline struct regmap *dev_get_regmap(struct device *dev,
1066 const char *name)
1067{
Mark Brown72b39f62012-05-08 17:44:40 +01001068 return NULL;
1069}
1070
Tuomas Tynkkynen8d7d3972014-07-21 18:38:47 +03001071static inline struct device *regmap_get_device(struct regmap *map)
1072{
1073 WARN_ONCE(1, "regmap API is disabled");
Mark Brown1d33dc62014-07-25 19:01:53 +01001074 return NULL;
Tuomas Tynkkynen8d7d3972014-07-21 18:38:47 +03001075}
1076
Mark Brown9cde5fc2012-02-17 14:49:51 -08001077#endif
1078
Mark Brownb83a3132011-05-11 19:59:58 +02001079#endif