blob: 5a7cf2136c81fd9ec5a97f5c819b705febf96fbf [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>
Mark Brownb83a3132011-05-11 19:59:58 +020020
Paul Gortmakerde477252011-05-26 13:46:22 -040021struct module;
Paul Gortmaker313162d2012-01-30 11:46:54 -050022struct device;
Mark Brown9943fa32011-06-20 19:02:29 +010023struct i2c_client;
Mark Brown90f790d2012-08-20 21:45:05 +010024struct irq_domain;
Mark Browna676f082011-05-12 11:42:10 +020025struct spi_device;
Josh Cartwrighta01779f2013-10-28 13:12:35 -050026struct spmi_device;
Mark Brownb83d2ff2012-03-11 11:49:17 +000027struct regmap;
Krystian Garbaciak6863ca62012-06-15 11:23:56 +010028struct regmap_range_cfg;
Srinivas Kandagatla67252282013-06-11 13:18:15 +010029struct regmap_field;
Mark Brown22853222014-11-18 19:45:51 +010030struct snd_ac97;
Mark Brown9943fa32011-06-20 19:02:29 +010031
Dimitris Papastamos9fabe242011-09-19 14:34:00 +010032/* An enum of all the supported cache types */
33enum regcache_type {
34 REGCACHE_NONE,
Dimitris Papastamos28644c802011-09-19 14:34:02 +010035 REGCACHE_RBTREE,
Mark Brown2ac902c2012-12-19 14:51:55 +000036 REGCACHE_COMPRESSED,
37 REGCACHE_FLAT,
Dimitris Papastamos9fabe242011-09-19 14:34:00 +010038};
39
Mark Browndd898b22011-07-20 22:28:58 +010040/**
Mark Brownbd20eb52011-08-19 18:09:38 +090041 * Default value for a register. We use an array of structs rather
42 * than a simple array as many modern devices have very sparse
43 * register maps.
44 *
45 * @reg: Register address.
46 * @def: Register default value.
47 */
48struct reg_default {
49 unsigned int reg;
50 unsigned int def;
51};
52
Nariman Poushin8019ff62015-07-16 16:36:21 +010053/**
Nariman Poushin2de9d602015-07-16 16:36:22 +010054 * Register/value pairs for sequences of writes with an optional delay in
55 * microseconds to be applied after each write.
Nariman Poushin8019ff62015-07-16 16:36:21 +010056 *
57 * @reg: Register address.
58 * @def: Register value.
Nariman Poushin2de9d602015-07-16 16:36:22 +010059 * @delay_us: Delay to be applied after the register write in microseconds
Nariman Poushin8019ff62015-07-16 16:36:21 +010060 */
61struct reg_sequence {
62 unsigned int reg;
63 unsigned int def;
Nariman Poushin2de9d602015-07-16 16:36:22 +010064 unsigned int delay_us;
Nariman Poushin8019ff62015-07-16 16:36:21 +010065};
66
Mark Brownb83d2ff2012-03-11 11:49:17 +000067#ifdef CONFIG_REGMAP
68
Stephen Warren141eba22012-05-24 10:47:26 -060069enum regmap_endian {
70 /* Unspecified -> 0 -> Backwards compatible default */
71 REGMAP_ENDIAN_DEFAULT = 0,
72 REGMAP_ENDIAN_BIG,
73 REGMAP_ENDIAN_LITTLE,
74 REGMAP_ENDIAN_NATIVE,
75};
76
Davide Ciminaghi76aad392012-11-20 15:20:30 +010077/**
78 * A register range, used for access related checks
79 * (readable/writeable/volatile/precious checks)
80 *
81 * @range_min: address of first register
82 * @range_max: address of last register
83 */
84struct regmap_range {
85 unsigned int range_min;
86 unsigned int range_max;
87};
88
Laxman Dewangan6112fe62013-09-20 18:00:10 +053089#define regmap_reg_range(low, high) { .range_min = low, .range_max = high, }
90
Davide Ciminaghi76aad392012-11-20 15:20:30 +010091/*
92 * A table of ranges including some yes ranges and some no ranges.
93 * If a register belongs to a no_range, the corresponding check function
94 * will return false. If a register belongs to a yes range, the corresponding
95 * check function will return true. "no_ranges" are searched first.
96 *
97 * @yes_ranges : pointer to an array of regmap ranges used as "yes ranges"
98 * @n_yes_ranges: size of the above array
99 * @no_ranges: pointer to an array of regmap ranges used as "no ranges"
100 * @n_no_ranges: size of the above array
101 */
102struct regmap_access_table {
103 const struct regmap_range *yes_ranges;
104 unsigned int n_yes_ranges;
105 const struct regmap_range *no_ranges;
106 unsigned int n_no_ranges;
107};
108
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200109typedef void (*regmap_lock)(void *);
110typedef void (*regmap_unlock)(void *);
111
Mark Brownbd20eb52011-08-19 18:09:38 +0900112/**
Mark Browndd898b22011-07-20 22:28:58 +0100113 * Configuration for the register map of a device.
114 *
Stephen Warrend3c242e2012-04-04 15:48:29 -0600115 * @name: Optional name of the regmap. Useful when a device has multiple
116 * register regions.
117 *
Mark Browndd898b22011-07-20 22:28:58 +0100118 * @reg_bits: Number of bits in a register address, mandatory.
Stephen Warrenf01ee602012-04-09 13:40:24 -0600119 * @reg_stride: The register address stride. Valid register addresses are a
120 * multiple of this value. If set to 0, a value of 1 will be
121 * used.
Mark Brown82159ba2012-01-18 10:52:25 +0000122 * @pad_bits: Number of bits of padding between register and value.
Mark Browndd898b22011-07-20 22:28:58 +0100123 * @val_bits: Number of bits in a register value, mandatory.
Mark Brown2e2ae662011-07-20 22:33:39 +0100124 *
Mark Brown3566cc92011-08-09 10:23:22 +0900125 * @writeable_reg: Optional callback returning true if the register
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100126 * can be written to. If this field is NULL but wr_table
127 * (see below) is not, the check is performed on such table
128 * (a register is writeable if it belongs to one of the ranges
129 * specified by wr_table).
Mark Brown3566cc92011-08-09 10:23:22 +0900130 * @readable_reg: Optional callback returning true if the register
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100131 * can be read from. If this field is NULL but rd_table
132 * (see below) is not, the check is performed on such table
133 * (a register is readable if it belongs to one of the ranges
134 * specified by rd_table).
Mark Brown3566cc92011-08-09 10:23:22 +0900135 * @volatile_reg: Optional callback returning true if the register
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100136 * value can't be cached. If this field is NULL but
137 * volatile_table (see below) is not, the check is performed on
138 * such table (a register is volatile if it belongs to one of
139 * the ranges specified by volatile_table).
Laszlo Pappbdc39642014-01-09 14:13:41 +0000140 * @precious_reg: Optional callback returning true if the register
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100141 * should not be read outside of a call from the driver
Laszlo Pappbdc39642014-01-09 14:13:41 +0000142 * (e.g., a clear on read interrupt status register). If this
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100143 * field is NULL but precious_table (see below) is not, the
144 * check is performed on such table (a register is precious if
145 * it belongs to one of the ranges specified by precious_table).
146 * @lock: Optional lock callback (overrides regmap's default lock
147 * function, based on spinlock or mutex).
148 * @unlock: As above for unlocking.
149 * @lock_arg: this field is passed as the only argument of lock/unlock
150 * functions (ignored in case regular lock/unlock functions
151 * are not overridden).
Andrey Smirnovd2a58842013-01-27 10:49:05 -0800152 * @reg_read: Optional callback that if filled will be used to perform
153 * all the reads from the registers. Should only be provided for
Laszlo Pappbdc39642014-01-09 14:13:41 +0000154 * devices whose read operation cannot be represented as a simple
155 * read operation on a bus such as SPI, I2C, etc. Most of the
156 * devices do not need this.
Andrey Smirnovd2a58842013-01-27 10:49:05 -0800157 * @reg_write: Same as above for writing.
158 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
159 * to perform locking. This field is ignored if custom lock/unlock
160 * functions are used (see fields lock/unlock of struct regmap_config).
161 * This field is a duplicate of a similar file in
162 * 'struct regmap_bus' and serves exact same purpose.
163 * Use it only for "no-bus" cases.
Mark Brownbd20eb52011-08-19 18:09:38 +0900164 * @max_register: Optional, specifies the maximum valid register index.
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100165 * @wr_table: Optional, points to a struct regmap_access_table specifying
166 * valid ranges for write access.
167 * @rd_table: As above, for read access.
168 * @volatile_table: As above, for volatile registers.
169 * @precious_table: As above, for precious registers.
Mark Brownbd20eb52011-08-19 18:09:38 +0900170 * @reg_defaults: Power on reset values for registers (for use with
171 * register cache support).
172 * @num_reg_defaults: Number of elements in reg_defaults.
Lars-Peter Clausen6f306442011-09-05 20:46:32 +0200173 *
174 * @read_flag_mask: Mask to be set in the top byte of the register when doing
175 * a read.
176 * @write_flag_mask: Mask to be set in the top byte of the register when doing
177 * a write. If both read_flag_mask and write_flag_mask are
178 * empty the regmap_bus default masks are used.
Ashish Jangam2e33caf2012-04-30 23:23:40 +0100179 * @use_single_rw: If set, converts the bulk read and write operations into
180 * a series of single read and write operations. This is useful
181 * for device that does not support bulk read and write.
Opensource [Anthony Olech]e894c3f2014-03-04 13:54:02 +0000182 * @can_multi_write: If set, the device supports the multi write mode of bulk
183 * write operations, if clear multi write requests will be
184 * split into individual write operations
Dimitris Papastamos9fabe242011-09-19 14:34:00 +0100185 *
186 * @cache_type: The actual cache type.
187 * @reg_defaults_raw: Power on reset values for registers (for use with
188 * register cache support).
189 * @num_reg_defaults_raw: Number of elements in reg_defaults_raw.
Stephen Warren141eba22012-05-24 10:47:26 -0600190 * @reg_format_endian: Endianness for formatted register addresses. If this is
191 * DEFAULT, the @reg_format_endian_default value from the
192 * regmap bus is used.
193 * @val_format_endian: Endianness for formatted register values. If this is
194 * DEFAULT, the @reg_format_endian_default value from the
195 * regmap bus is used.
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100196 *
197 * @ranges: Array of configuration entries for virtual address ranges.
198 * @num_ranges: Number of range configuration entries.
Mark Browndd898b22011-07-20 22:28:58 +0100199 */
Mark Brownb83a3132011-05-11 19:59:58 +0200200struct regmap_config {
Stephen Warrend3c242e2012-04-04 15:48:29 -0600201 const char *name;
202
Mark Brownb83a3132011-05-11 19:59:58 +0200203 int reg_bits;
Stephen Warrenf01ee602012-04-09 13:40:24 -0600204 int reg_stride;
Mark Brown82159ba2012-01-18 10:52:25 +0000205 int pad_bits;
Mark Brownb83a3132011-05-11 19:59:58 +0200206 int val_bits;
Mark Brown2e2ae662011-07-20 22:33:39 +0100207
Mark Brown2e2ae662011-07-20 22:33:39 +0100208 bool (*writeable_reg)(struct device *dev, unsigned int reg);
209 bool (*readable_reg)(struct device *dev, unsigned int reg);
210 bool (*volatile_reg)(struct device *dev, unsigned int reg);
Mark Brown18694882011-08-08 15:40:22 +0900211 bool (*precious_reg)(struct device *dev, unsigned int reg);
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200212 regmap_lock lock;
213 regmap_unlock unlock;
214 void *lock_arg;
Mark Brownbd20eb52011-08-19 18:09:38 +0900215
Andrey Smirnovd2a58842013-01-27 10:49:05 -0800216 int (*reg_read)(void *context, unsigned int reg, unsigned int *val);
217 int (*reg_write)(void *context, unsigned int reg, unsigned int val);
218
219 bool fast_io;
220
Mark Brownbd20eb52011-08-19 18:09:38 +0900221 unsigned int max_register;
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100222 const struct regmap_access_table *wr_table;
223 const struct regmap_access_table *rd_table;
224 const struct regmap_access_table *volatile_table;
225 const struct regmap_access_table *precious_table;
Lars-Peter Clausen720e4612011-11-16 16:28:17 +0100226 const struct reg_default *reg_defaults;
Dimitris Papastamos9fabe242011-09-19 14:34:00 +0100227 unsigned int num_reg_defaults;
228 enum regcache_type cache_type;
229 const void *reg_defaults_raw;
230 unsigned int num_reg_defaults_raw;
Lars-Peter Clausen6f306442011-09-05 20:46:32 +0200231
232 u8 read_flag_mask;
233 u8 write_flag_mask;
Ashish Jangam2e33caf2012-04-30 23:23:40 +0100234
235 bool use_single_rw;
Opensource [Anthony Olech]e894c3f2014-03-04 13:54:02 +0000236 bool can_multi_write;
Stephen Warren141eba22012-05-24 10:47:26 -0600237
238 enum regmap_endian reg_format_endian;
239 enum regmap_endian val_format_endian;
Mark Brown38e23192012-07-22 19:26:07 +0100240
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100241 const struct regmap_range_cfg *ranges;
Mark Browne3549cd2012-10-02 20:17:15 +0100242 unsigned int num_ranges;
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100243};
244
245/**
246 * Configuration for indirectly accessed or paged registers.
247 * Registers, mapped to this virtual range, are accessed in two steps:
248 * 1. page selector register update;
249 * 2. access through data window registers.
250 *
Mark Brownd058bb42012-10-03 12:40:47 +0100251 * @name: Descriptive name for diagnostics
252 *
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100253 * @range_min: Address of the lowest register address in virtual range.
254 * @range_max: Address of the highest register in virtual range.
255 *
256 * @page_sel_reg: Register with selector field.
257 * @page_sel_mask: Bit shift for selector value.
258 * @page_sel_shift: Bit mask for selector value.
259 *
260 * @window_start: Address of first (lowest) register in data window.
261 * @window_len: Number of registers in data window.
262 */
263struct regmap_range_cfg {
Mark Brownd058bb42012-10-03 12:40:47 +0100264 const char *name;
265
Krystian Garbaciak6863ca62012-06-15 11:23:56 +0100266 /* Registers of virtual address range */
267 unsigned int range_min;
268 unsigned int range_max;
269
270 /* Page selector for indirect addressing */
271 unsigned int selector_reg;
272 unsigned int selector_mask;
273 int selector_shift;
274
275 /* Data window (per each page) */
276 unsigned int window_start;
277 unsigned int window_len;
Mark Brownb83a3132011-05-11 19:59:58 +0200278};
279
Mark Brown0d509f22013-01-27 22:07:38 +0800280struct regmap_async;
281
Stephen Warren0135bbc2012-04-04 15:48:30 -0600282typedef int (*regmap_hw_write)(void *context, const void *data,
Mark Brownb83a3132011-05-11 19:59:58 +0200283 size_t count);
Stephen Warren0135bbc2012-04-04 15:48:30 -0600284typedef int (*regmap_hw_gather_write)(void *context,
Mark Brownb83a3132011-05-11 19:59:58 +0200285 const void *reg, size_t reg_len,
286 const void *val, size_t val_len);
Mark Brown0d509f22013-01-27 22:07:38 +0800287typedef int (*regmap_hw_async_write)(void *context,
288 const void *reg, size_t reg_len,
289 const void *val, size_t val_len,
290 struct regmap_async *async);
Stephen Warren0135bbc2012-04-04 15:48:30 -0600291typedef int (*regmap_hw_read)(void *context,
Mark Brownb83a3132011-05-11 19:59:58 +0200292 const void *reg_buf, size_t reg_size,
293 void *val_buf, size_t val_size);
Boris BREZILLON3ac17032014-04-17 11:40:11 +0200294typedef int (*regmap_hw_reg_read)(void *context, unsigned int reg,
295 unsigned int *val);
296typedef int (*regmap_hw_reg_write)(void *context, unsigned int reg,
297 unsigned int val);
Mark Brown0d509f22013-01-27 22:07:38 +0800298typedef struct regmap_async *(*regmap_hw_async_alloc)(void);
Stephen Warren0135bbc2012-04-04 15:48:30 -0600299typedef void (*regmap_hw_free_context)(void *context);
Mark Brownb83a3132011-05-11 19:59:58 +0200300
301/**
302 * Description of a hardware bus for the register map infrastructure.
303 *
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600304 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
Davide Ciminaghi0d4529c2012-10-16 15:56:59 +0200305 * to perform locking. This field is ignored if custom lock/unlock
306 * functions are used (see fields lock/unlock of
307 * struct regmap_config).
Mark Brownb83a3132011-05-11 19:59:58 +0200308 * @write: Write operation.
309 * @gather_write: Write operation with split register/value, return -ENOTSUPP
310 * if not implemented on a given device.
Mark Brown0d509f22013-01-27 22:07:38 +0800311 * @async_write: Write operation which completes asynchronously, optional and
312 * must serialise with respect to non-async I/O.
Mark Brownb83a3132011-05-11 19:59:58 +0200313 * @read: Read operation. Data is returned in the buffer used to transmit
314 * data.
Mark Brown0d509f22013-01-27 22:07:38 +0800315 * @async_alloc: Allocate a regmap_async() structure.
Mark Brownb83a3132011-05-11 19:59:58 +0200316 * @read_flag_mask: Mask to be set in the top byte of the register when doing
317 * a read.
Stephen Warren141eba22012-05-24 10:47:26 -0600318 * @reg_format_endian_default: Default endianness for formatted register
319 * addresses. Used when the regmap_config specifies DEFAULT. If this is
320 * DEFAULT, BIG is assumed.
321 * @val_format_endian_default: Default endianness for formatted register
322 * values. Used when the regmap_config specifies DEFAULT. If this is
323 * DEFAULT, BIG is assumed.
Mark Brown0d509f22013-01-27 22:07:38 +0800324 * @async_size: Size of struct used for async work.
Mark Brownb83a3132011-05-11 19:59:58 +0200325 */
326struct regmap_bus {
Stephen Warrenbacdbe02012-04-04 15:48:28 -0600327 bool fast_io;
Mark Brownb83a3132011-05-11 19:59:58 +0200328 regmap_hw_write write;
329 regmap_hw_gather_write gather_write;
Mark Brown0d509f22013-01-27 22:07:38 +0800330 regmap_hw_async_write async_write;
Boris BREZILLON3ac17032014-04-17 11:40:11 +0200331 regmap_hw_reg_write reg_write;
Mark Brownb83a3132011-05-11 19:59:58 +0200332 regmap_hw_read read;
Boris BREZILLON3ac17032014-04-17 11:40:11 +0200333 regmap_hw_reg_read reg_read;
Stephen Warren0135bbc2012-04-04 15:48:30 -0600334 regmap_hw_free_context free_context;
Mark Brown0d509f22013-01-27 22:07:38 +0800335 regmap_hw_async_alloc async_alloc;
Mark Brownb83a3132011-05-11 19:59:58 +0200336 u8 read_flag_mask;
Stephen Warren141eba22012-05-24 10:47:26 -0600337 enum regmap_endian reg_format_endian_default;
338 enum regmap_endian val_format_endian_default;
Mark Brownb83a3132011-05-11 19:59:58 +0200339};
340
341struct regmap *regmap_init(struct device *dev,
342 const struct regmap_bus *bus,
Stephen Warren0135bbc2012-04-04 15:48:30 -0600343 void *bus_context,
Mark Brownb83a3132011-05-11 19:59:58 +0200344 const struct regmap_config *config);
Michal Simek6cfec042014-02-10 16:22:33 +0100345int regmap_attach_dev(struct device *dev, struct regmap *map,
346 const struct regmap_config *config);
Mark Brown9943fa32011-06-20 19:02:29 +0100347struct regmap *regmap_init_i2c(struct i2c_client *i2c,
348 const struct regmap_config *config);
Mark Browna676f082011-05-12 11:42:10 +0200349struct regmap *regmap_init_spi(struct spi_device *dev,
350 const struct regmap_config *config);
Josh Cartwrightc9afbb02014-02-12 13:44:27 -0600351struct regmap *regmap_init_spmi_base(struct spmi_device *dev,
352 const struct regmap_config *config);
353struct regmap *regmap_init_spmi_ext(struct spmi_device *dev,
354 const struct regmap_config *config);
Philipp Zabel878ec672013-02-14 17:39:08 +0100355struct regmap *regmap_init_mmio_clk(struct device *dev, const char *clk_id,
356 void __iomem *regs,
357 const struct regmap_config *config);
Mark Brown22853222014-11-18 19:45:51 +0100358struct regmap *regmap_init_ac97(struct snd_ac97 *ac97,
359 const struct regmap_config *config);
Mark Browna676f082011-05-12 11:42:10 +0200360
Mark Brownc0eb4672012-01-30 19:56:52 +0000361struct regmap *devm_regmap_init(struct device *dev,
362 const struct regmap_bus *bus,
Stephen Warren0135bbc2012-04-04 15:48:30 -0600363 void *bus_context,
Mark Brownc0eb4672012-01-30 19:56:52 +0000364 const struct regmap_config *config);
365struct regmap *devm_regmap_init_i2c(struct i2c_client *i2c,
366 const struct regmap_config *config);
367struct regmap *devm_regmap_init_spi(struct spi_device *dev,
368 const struct regmap_config *config);
Josh Cartwrightc9afbb02014-02-12 13:44:27 -0600369struct regmap *devm_regmap_init_spmi_base(struct spmi_device *dev,
370 const struct regmap_config *config);
371struct regmap *devm_regmap_init_spmi_ext(struct spmi_device *dev,
372 const struct regmap_config *config);
Philipp Zabel878ec672013-02-14 17:39:08 +0100373struct regmap *devm_regmap_init_mmio_clk(struct device *dev, const char *clk_id,
374 void __iomem *regs,
375 const struct regmap_config *config);
Mark Brown22853222014-11-18 19:45:51 +0100376struct regmap *devm_regmap_init_ac97(struct snd_ac97 *ac97,
377 const struct regmap_config *config);
378
379bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg);
Philipp Zabel878ec672013-02-14 17:39:08 +0100380
381/**
382 * regmap_init_mmio(): Initialise register map
383 *
384 * @dev: Device that will be interacted with
385 * @regs: Pointer to memory-mapped IO region
386 * @config: Configuration for register map
387 *
388 * The return value will be an ERR_PTR() on error or a valid pointer to
389 * a struct regmap.
390 */
391static inline struct regmap *regmap_init_mmio(struct device *dev,
392 void __iomem *regs,
393 const struct regmap_config *config)
394{
395 return regmap_init_mmio_clk(dev, NULL, regs, config);
396}
397
398/**
399 * devm_regmap_init_mmio(): Initialise managed register map
400 *
401 * @dev: Device that will be interacted with
402 * @regs: Pointer to memory-mapped IO region
403 * @config: Configuration for register map
404 *
405 * The return value will be an ERR_PTR() on error or a valid pointer
406 * to a struct regmap. The regmap will be automatically freed by the
407 * device management code.
408 */
409static inline struct regmap *devm_regmap_init_mmio(struct device *dev,
410 void __iomem *regs,
411 const struct regmap_config *config)
412{
413 return devm_regmap_init_mmio_clk(dev, NULL, regs, config);
414}
Mark Brownc0eb4672012-01-30 19:56:52 +0000415
Mark Brownb83a3132011-05-11 19:59:58 +0200416void regmap_exit(struct regmap *map);
Mark Brownbf315172011-12-03 17:06:20 +0000417int regmap_reinit_cache(struct regmap *map,
418 const struct regmap_config *config);
Mark Brown72b39f62012-05-08 17:44:40 +0100419struct regmap *dev_get_regmap(struct device *dev, const char *name);
Tuomas Tynkkynen8d7d3972014-07-21 18:38:47 +0300420struct device *regmap_get_device(struct regmap *map);
Mark Brownb83a3132011-05-11 19:59:58 +0200421int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
Mark Brown915f4412013-10-09 13:30:10 +0100422int regmap_write_async(struct regmap *map, unsigned int reg, unsigned int val);
Mark Brownb83a3132011-05-11 19:59:58 +0200423int regmap_raw_write(struct regmap *map, unsigned int reg,
424 const void *val, size_t val_len);
Laxman Dewangan8eaeb212012-02-12 19:49:43 +0530425int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
426 size_t val_count);
Nariman Poushin8019ff62015-07-16 16:36:21 +0100427int regmap_multi_reg_write(struct regmap *map, const struct reg_sequence *regs,
Anthony Oleche33fabd2013-10-11 15:31:11 +0100428 int num_regs);
Charles Keepax1d5b40b2014-02-25 13:45:50 +0000429int regmap_multi_reg_write_bypassed(struct regmap *map,
Nariman Poushin8019ff62015-07-16 16:36:21 +0100430 const struct reg_sequence *regs,
Charles Keepax1d5b40b2014-02-25 13:45:50 +0000431 int num_regs);
Mark Brown0d509f22013-01-27 22:07:38 +0800432int regmap_raw_write_async(struct regmap *map, unsigned int reg,
433 const void *val, size_t val_len);
Mark Brownb83a3132011-05-11 19:59:58 +0200434int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
435int regmap_raw_read(struct regmap *map, unsigned int reg,
436 void *val, size_t val_len);
437int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
438 size_t val_count);
439int regmap_update_bits(struct regmap *map, unsigned int reg,
440 unsigned int mask, unsigned int val);
Mark Brown915f4412013-10-09 13:30:10 +0100441int regmap_update_bits_async(struct regmap *map, unsigned int reg,
442 unsigned int mask, unsigned int val);
Mark Brown018690d2011-11-29 20:10:36 +0000443int regmap_update_bits_check(struct regmap *map, unsigned int reg,
444 unsigned int mask, unsigned int val,
445 bool *change);
Mark Brown915f4412013-10-09 13:30:10 +0100446int regmap_update_bits_check_async(struct regmap *map, unsigned int reg,
447 unsigned int mask, unsigned int val,
448 bool *change);
Mark Browna6539c32012-02-17 14:20:14 -0800449int regmap_get_val_bytes(struct regmap *map);
Srinivas Kandagatla668abc72015-05-21 17:42:43 +0100450int regmap_get_max_register(struct regmap *map);
Srinivas Kandagatlaa2f776c2015-05-21 17:42:54 +0100451int regmap_get_reg_stride(struct regmap *map);
Mark Brown0d509f22013-01-27 22:07:38 +0800452int regmap_async_complete(struct regmap *map);
Mark Brown221ad7f2013-03-26 21:24:20 +0000453bool regmap_can_raw_write(struct regmap *map);
Mark Brownb83a3132011-05-11 19:59:58 +0200454
Mark Brown39a58432011-09-19 18:21:49 +0100455int regcache_sync(struct regmap *map);
Mark Brown4d4cfd12012-02-23 20:53:37 +0000456int regcache_sync_region(struct regmap *map, unsigned int min,
457 unsigned int max);
Mark Brown697e85b2013-05-08 13:55:22 +0100458int regcache_drop_region(struct regmap *map, unsigned int min,
459 unsigned int max);
Mark Brown92afb282011-09-19 18:22:14 +0100460void regcache_cache_only(struct regmap *map, bool enable);
Dimitris Papastamos6eb0f5e2011-09-29 14:36:27 +0100461void regcache_cache_bypass(struct regmap *map, bool enable);
Mark Brown8ae0d7e2011-10-26 10:34:22 +0200462void regcache_mark_dirty(struct regmap *map);
Mark Brown92afb282011-09-19 18:22:14 +0100463
Mark Brown154881e2013-05-08 13:55:23 +0100464bool regmap_check_range_table(struct regmap *map, unsigned int reg,
465 const struct regmap_access_table *table);
466
Nariman Poushin8019ff62015-07-16 16:36:21 +0100467int regmap_register_patch(struct regmap *map, const struct reg_sequence *regs,
Mark Brown22f0d902012-01-21 12:01:14 +0000468 int num_regs);
Nenghua Cao13ff50c2014-02-19 18:44:13 +0800469int regmap_parse_val(struct regmap *map, const void *buf,
470 unsigned int *val);
Mark Brown22f0d902012-01-21 12:01:14 +0000471
Davide Ciminaghi76aad392012-11-20 15:20:30 +0100472static inline bool regmap_reg_in_range(unsigned int reg,
473 const struct regmap_range *range)
474{
475 return reg >= range->range_min && reg <= range->range_max;
476}
477
478bool regmap_reg_in_ranges(unsigned int reg,
479 const struct regmap_range *ranges,
480 unsigned int nranges);
481
Mark Brownf8beab22011-10-28 23:50:49 +0200482/**
Srinivas Kandagatla67252282013-06-11 13:18:15 +0100483 * Description of an register field
484 *
485 * @reg: Offset of the register within the regmap bank
486 * @lsb: lsb of the register field.
Bintian Wangf27b37f2015-01-27 20:50:29 +0800487 * @msb: msb of the register field.
Kuninori Morimotoa0102372013-09-01 20:30:50 -0700488 * @id_size: port size if it has some ports
489 * @id_offset: address offset for each ports
Srinivas Kandagatla67252282013-06-11 13:18:15 +0100490 */
491struct reg_field {
492 unsigned int reg;
493 unsigned int lsb;
494 unsigned int msb;
Kuninori Morimotoa0102372013-09-01 20:30:50 -0700495 unsigned int id_size;
496 unsigned int id_offset;
Srinivas Kandagatla67252282013-06-11 13:18:15 +0100497};
498
499#define REG_FIELD(_reg, _lsb, _msb) { \
500 .reg = _reg, \
501 .lsb = _lsb, \
502 .msb = _msb, \
503 }
504
505struct regmap_field *regmap_field_alloc(struct regmap *regmap,
506 struct reg_field reg_field);
507void regmap_field_free(struct regmap_field *field);
508
509struct regmap_field *devm_regmap_field_alloc(struct device *dev,
510 struct regmap *regmap, struct reg_field reg_field);
511void devm_regmap_field_free(struct device *dev, struct regmap_field *field);
512
513int regmap_field_read(struct regmap_field *field, unsigned int *val);
514int regmap_field_write(struct regmap_field *field, unsigned int val);
Kuninori Morimotofdf20022013-09-01 20:24:50 -0700515int regmap_field_update_bits(struct regmap_field *field,
516 unsigned int mask, unsigned int val);
Srinivas Kandagatla67252282013-06-11 13:18:15 +0100517
Kuninori Morimotoa0102372013-09-01 20:30:50 -0700518int regmap_fields_write(struct regmap_field *field, unsigned int id,
519 unsigned int val);
520int regmap_fields_read(struct regmap_field *field, unsigned int id,
521 unsigned int *val);
522int regmap_fields_update_bits(struct regmap_field *field, unsigned int id,
523 unsigned int mask, unsigned int val);
Srinivas Kandagatla67252282013-06-11 13:18:15 +0100524
525/**
Mark Brownf8beab22011-10-28 23:50:49 +0200526 * Description of an IRQ for the generic regmap irq_chip.
527 *
528 * @reg_offset: Offset of the status/mask register within the bank
529 * @mask: Mask used to flag/control the register.
530 */
531struct regmap_irq {
532 unsigned int reg_offset;
533 unsigned int mask;
534};
535
536/**
537 * Description of a generic regmap irq_chip. This is not intended to
538 * handle every possible interrupt controller, but it should handle a
539 * substantial proportion of those that are found in the wild.
540 *
541 * @name: Descriptive name for IRQ controller.
542 *
543 * @status_base: Base status register address.
544 * @mask_base: Base mask register address.
Alexander Shiyand3233432013-12-15 13:36:51 +0400545 * @ack_base: Base ack address. If zero then the chip is clear on read.
546 * Using zero value is possible with @use_ack bit.
Mark Browna43fd502012-06-05 14:34:03 +0100547 * @wake_base: Base address for wake enables. If zero unsupported.
Graeme Gregory022f926a2012-05-14 22:40:43 +0900548 * @irq_reg_stride: Stride to use for chips where registers are not contiguous.
Philipp Zabel2753e6f2013-07-22 17:15:52 +0200549 * @init_ack_masked: Ack all masked interrupts once during initalization.
Philipp Zabel68622bd2013-07-24 10:26:48 +0200550 * @mask_invert: Inverted mask register: cleared bits are masked out.
Alexander Shiyand3233432013-12-15 13:36:51 +0400551 * @use_ack: Use @ack register even if it is zero.
Philipp Zabel68622bd2013-07-24 10:26:48 +0200552 * @wake_invert: Inverted wake register: cleared bits are wake enabled.
Mark Brown0c00c502012-07-24 15:41:19 +0100553 * @runtime_pm: Hold a runtime PM lock on the device when accessing it.
Mark Brownf8beab22011-10-28 23:50:49 +0200554 *
555 * @num_regs: Number of registers in each control bank.
556 * @irqs: Descriptors for individual IRQs. Interrupt numbers are
557 * assigned based on the index in the array of the interrupt.
558 * @num_irqs: Number of descriptors.
559 */
560struct regmap_irq_chip {
561 const char *name;
562
563 unsigned int status_base;
564 unsigned int mask_base;
565 unsigned int ack_base;
Mark Browna43fd502012-06-05 14:34:03 +0100566 unsigned int wake_base;
Graeme Gregory022f926a2012-05-14 22:40:43 +0900567 unsigned int irq_reg_stride;
Philipp Zabelf484f7a2013-07-24 10:26:42 +0200568 bool init_ack_masked:1;
569 bool mask_invert:1;
Alexander Shiyand3233432013-12-15 13:36:51 +0400570 bool use_ack:1;
Philipp Zabelf484f7a2013-07-24 10:26:42 +0200571 bool wake_invert:1;
572 bool runtime_pm:1;
Mark Brownf8beab22011-10-28 23:50:49 +0200573
574 int num_regs;
575
576 const struct regmap_irq *irqs;
577 int num_irqs;
578};
579
580struct regmap_irq_chip_data;
581
582int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
Mark Brownb026ddb2012-05-31 21:01:46 +0100583 int irq_base, const struct regmap_irq_chip *chip,
Mark Brownf8beab22011-10-28 23:50:49 +0200584 struct regmap_irq_chip_data **data);
585void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data);
Mark Brown209a6002011-12-05 16:10:15 +0000586int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data);
Mark Brown4af8be62012-05-13 10:59:56 +0100587int regmap_irq_get_virq(struct regmap_irq_chip_data *data, int irq);
Mark Brown90f790d2012-08-20 21:45:05 +0100588struct irq_domain *regmap_irq_get_domain(struct regmap_irq_chip_data *data);
Mark Brownb83a3132011-05-11 19:59:58 +0200589
Mark Brown9cde5fc2012-02-17 14:49:51 -0800590#else
591
592/*
593 * These stubs should only ever be called by generic code which has
594 * regmap based facilities, if they ever get called at runtime
595 * something is going wrong and something probably needs to select
596 * REGMAP.
597 */
598
599static inline int regmap_write(struct regmap *map, unsigned int reg,
600 unsigned int val)
601{
602 WARN_ONCE(1, "regmap API is disabled");
603 return -EINVAL;
604}
605
Mark Brown915f4412013-10-09 13:30:10 +0100606static inline int regmap_write_async(struct regmap *map, unsigned int reg,
607 unsigned int val)
608{
609 WARN_ONCE(1, "regmap API is disabled");
610 return -EINVAL;
611}
612
Mark Brown9cde5fc2012-02-17 14:49:51 -0800613static inline int regmap_raw_write(struct regmap *map, unsigned int reg,
614 const void *val, size_t val_len)
615{
616 WARN_ONCE(1, "regmap API is disabled");
617 return -EINVAL;
618}
619
Mark Brown0d509f22013-01-27 22:07:38 +0800620static inline int regmap_raw_write_async(struct regmap *map, unsigned int reg,
621 const void *val, size_t val_len)
622{
623 WARN_ONCE(1, "regmap API is disabled");
624 return -EINVAL;
625}
626
Mark Brown9cde5fc2012-02-17 14:49:51 -0800627static inline int regmap_bulk_write(struct regmap *map, unsigned int reg,
628 const void *val, size_t val_count)
629{
630 WARN_ONCE(1, "regmap API is disabled");
631 return -EINVAL;
632}
633
634static inline int regmap_read(struct regmap *map, unsigned int reg,
635 unsigned int *val)
636{
637 WARN_ONCE(1, "regmap API is disabled");
638 return -EINVAL;
639}
640
641static inline int regmap_raw_read(struct regmap *map, unsigned int reg,
642 void *val, size_t val_len)
643{
644 WARN_ONCE(1, "regmap API is disabled");
645 return -EINVAL;
646}
647
648static inline int regmap_bulk_read(struct regmap *map, unsigned int reg,
649 void *val, size_t val_count)
650{
651 WARN_ONCE(1, "regmap API is disabled");
652 return -EINVAL;
653}
654
655static inline int regmap_update_bits(struct regmap *map, unsigned int reg,
656 unsigned int mask, unsigned int val)
657{
658 WARN_ONCE(1, "regmap API is disabled");
659 return -EINVAL;
660}
661
Mark Brown915f4412013-10-09 13:30:10 +0100662static inline int regmap_update_bits_async(struct regmap *map,
663 unsigned int reg,
664 unsigned int mask, unsigned int val)
665{
666 WARN_ONCE(1, "regmap API is disabled");
667 return -EINVAL;
668}
669
Mark Brown9cde5fc2012-02-17 14:49:51 -0800670static inline int regmap_update_bits_check(struct regmap *map,
671 unsigned int reg,
672 unsigned int mask, unsigned int val,
673 bool *change)
674{
675 WARN_ONCE(1, "regmap API is disabled");
676 return -EINVAL;
677}
678
Mark Brown915f4412013-10-09 13:30:10 +0100679static inline int regmap_update_bits_check_async(struct regmap *map,
680 unsigned int reg,
681 unsigned int mask,
682 unsigned int val,
683 bool *change)
684{
685 WARN_ONCE(1, "regmap API is disabled");
686 return -EINVAL;
687}
688
Mark Brown9cde5fc2012-02-17 14:49:51 -0800689static inline int regmap_get_val_bytes(struct regmap *map)
690{
691 WARN_ONCE(1, "regmap API is disabled");
692 return -EINVAL;
693}
694
Srinivas Kandagatla668abc72015-05-21 17:42:43 +0100695static inline int regmap_get_max_register(struct regmap *map)
696{
697 WARN_ONCE(1, "regmap API is disabled");
698 return -EINVAL;
699}
700
Srinivas Kandagatlaa2f776c2015-05-21 17:42:54 +0100701static inline int regmap_get_reg_stride(struct regmap *map)
702{
703 WARN_ONCE(1, "regmap API is disabled");
704 return -EINVAL;
705}
706
Mark Brown9cde5fc2012-02-17 14:49:51 -0800707static inline int regcache_sync(struct regmap *map)
708{
709 WARN_ONCE(1, "regmap API is disabled");
710 return -EINVAL;
711}
712
Mark Browna313f9f2012-02-23 19:49:43 +0000713static inline int regcache_sync_region(struct regmap *map, unsigned int min,
714 unsigned int max)
715{
716 WARN_ONCE(1, "regmap API is disabled");
717 return -EINVAL;
718}
719
Mark Brown697e85b2013-05-08 13:55:22 +0100720static inline int regcache_drop_region(struct regmap *map, unsigned int min,
721 unsigned int max)
722{
723 WARN_ONCE(1, "regmap API is disabled");
724 return -EINVAL;
725}
726
Mark Brown9cde5fc2012-02-17 14:49:51 -0800727static inline void regcache_cache_only(struct regmap *map, bool enable)
728{
729 WARN_ONCE(1, "regmap API is disabled");
730}
731
732static inline void regcache_cache_bypass(struct regmap *map, bool enable)
733{
734 WARN_ONCE(1, "regmap API is disabled");
735}
736
737static inline void regcache_mark_dirty(struct regmap *map)
738{
739 WARN_ONCE(1, "regmap API is disabled");
740}
741
Mark Brown0d509f22013-01-27 22:07:38 +0800742static inline void regmap_async_complete(struct regmap *map)
743{
744 WARN_ONCE(1, "regmap API is disabled");
745}
746
Mark Brown9cde5fc2012-02-17 14:49:51 -0800747static inline int regmap_register_patch(struct regmap *map,
748 const struct reg_default *regs,
749 int num_regs)
750{
751 WARN_ONCE(1, "regmap API is disabled");
752 return -EINVAL;
753}
754
Nenghua Cao13ff50c2014-02-19 18:44:13 +0800755static inline int regmap_parse_val(struct regmap *map, const void *buf,
756 unsigned int *val)
757{
758 WARN_ONCE(1, "regmap API is disabled");
759 return -EINVAL;
760}
761
Mark Brown72b39f62012-05-08 17:44:40 +0100762static inline struct regmap *dev_get_regmap(struct device *dev,
763 const char *name)
764{
Mark Brown72b39f62012-05-08 17:44:40 +0100765 return NULL;
766}
767
Tuomas Tynkkynen8d7d3972014-07-21 18:38:47 +0300768static inline struct device *regmap_get_device(struct regmap *map)
769{
770 WARN_ONCE(1, "regmap API is disabled");
Mark Brown1d33dc62014-07-25 19:01:53 +0100771 return NULL;
Tuomas Tynkkynen8d7d3972014-07-21 18:38:47 +0300772}
773
Mark Brown9cde5fc2012-02-17 14:49:51 -0800774#endif
775
Mark Brownb83a3132011-05-11 19:59:58 +0200776#endif