]>
Commit | Line | Data |
---|---|---|
b83a313b MB |
1 | #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 | ||
b83a313b | 16 | #include <linux/list.h> |
b83a313b | 17 | |
de477254 | 18 | struct module; |
313162d0 | 19 | struct device; |
9943fa30 | 20 | struct i2c_client; |
a676f083 | 21 | struct spi_device; |
b83d2ff0 | 22 | struct regmap; |
9943fa30 | 23 | |
9fabe24e DP |
24 | /* An enum of all the supported cache types */ |
25 | enum regcache_type { | |
26 | REGCACHE_NONE, | |
28644c80 | 27 | REGCACHE_RBTREE, |
50b776fc | 28 | REGCACHE_COMPRESSED |
9fabe24e DP |
29 | }; |
30 | ||
bd20eb54 MB |
31 | /** |
32 | * Default value for a register. We use an array of structs rather | |
33 | * than a simple array as many modern devices have very sparse | |
34 | * register maps. | |
35 | * | |
36 | * @reg: Register address. | |
37 | * @def: Register default value. | |
38 | */ | |
39 | struct reg_default { | |
40 | unsigned int reg; | |
41 | unsigned int def; | |
42 | }; | |
43 | ||
b83d2ff0 MB |
44 | #ifdef CONFIG_REGMAP |
45 | ||
141eba2e SW |
46 | enum regmap_endian { |
47 | /* Unspecified -> 0 -> Backwards compatible default */ | |
48 | REGMAP_ENDIAN_DEFAULT = 0, | |
49 | REGMAP_ENDIAN_BIG, | |
50 | REGMAP_ENDIAN_LITTLE, | |
51 | REGMAP_ENDIAN_NATIVE, | |
52 | }; | |
53 | ||
dd898b20 MB |
54 | /** |
55 | * Configuration for the register map of a device. | |
56 | * | |
d3c242e1 SW |
57 | * @name: Optional name of the regmap. Useful when a device has multiple |
58 | * register regions. | |
59 | * | |
dd898b20 | 60 | * @reg_bits: Number of bits in a register address, mandatory. |
f01ee60f SW |
61 | * @reg_stride: The register address stride. Valid register addresses are a |
62 | * multiple of this value. If set to 0, a value of 1 will be | |
63 | * used. | |
82159ba8 | 64 | * @pad_bits: Number of bits of padding between register and value. |
dd898b20 | 65 | * @val_bits: Number of bits in a register value, mandatory. |
2e2ae66d | 66 | * |
3566cc9d MB |
67 | * @writeable_reg: Optional callback returning true if the register |
68 | * can be written to. | |
69 | * @readable_reg: Optional callback returning true if the register | |
70 | * can be read from. | |
71 | * @volatile_reg: Optional callback returning true if the register | |
72 | * value can't be cached. | |
73 | * @precious_reg: Optional callback returning true if the rgister | |
74 | * should not be read outside of a call from the driver | |
75 | * (eg, a clear on read interrupt status register). | |
bd20eb54 MB |
76 | * |
77 | * @max_register: Optional, specifies the maximum valid register index. | |
78 | * @reg_defaults: Power on reset values for registers (for use with | |
79 | * register cache support). | |
80 | * @num_reg_defaults: Number of elements in reg_defaults. | |
6f306441 LPC |
81 | * |
82 | * @read_flag_mask: Mask to be set in the top byte of the register when doing | |
83 | * a read. | |
84 | * @write_flag_mask: Mask to be set in the top byte of the register when doing | |
85 | * a write. If both read_flag_mask and write_flag_mask are | |
86 | * empty the regmap_bus default masks are used. | |
2e33caf1 AJ |
87 | * @use_single_rw: If set, converts the bulk read and write operations into |
88 | * a series of single read and write operations. This is useful | |
89 | * for device that does not support bulk read and write. | |
9fabe24e DP |
90 | * |
91 | * @cache_type: The actual cache type. | |
92 | * @reg_defaults_raw: Power on reset values for registers (for use with | |
93 | * register cache support). | |
94 | * @num_reg_defaults_raw: Number of elements in reg_defaults_raw. | |
141eba2e SW |
95 | * @reg_format_endian: Endianness for formatted register addresses. If this is |
96 | * DEFAULT, the @reg_format_endian_default value from the | |
97 | * regmap bus is used. | |
98 | * @val_format_endian: Endianness for formatted register values. If this is | |
99 | * DEFAULT, the @reg_format_endian_default value from the | |
100 | * regmap bus is used. | |
dd898b20 | 101 | */ |
b83a313b | 102 | struct regmap_config { |
d3c242e1 SW |
103 | const char *name; |
104 | ||
b83a313b | 105 | int reg_bits; |
f01ee60f | 106 | int reg_stride; |
82159ba8 | 107 | int pad_bits; |
b83a313b | 108 | int val_bits; |
2e2ae66d | 109 | |
2e2ae66d MB |
110 | bool (*writeable_reg)(struct device *dev, unsigned int reg); |
111 | bool (*readable_reg)(struct device *dev, unsigned int reg); | |
112 | bool (*volatile_reg)(struct device *dev, unsigned int reg); | |
18694886 | 113 | bool (*precious_reg)(struct device *dev, unsigned int reg); |
bd20eb54 MB |
114 | |
115 | unsigned int max_register; | |
720e4616 | 116 | const struct reg_default *reg_defaults; |
9fabe24e DP |
117 | unsigned int num_reg_defaults; |
118 | enum regcache_type cache_type; | |
119 | const void *reg_defaults_raw; | |
120 | unsigned int num_reg_defaults_raw; | |
6f306441 LPC |
121 | |
122 | u8 read_flag_mask; | |
123 | u8 write_flag_mask; | |
2e33caf1 AJ |
124 | |
125 | bool use_single_rw; | |
141eba2e SW |
126 | |
127 | enum regmap_endian reg_format_endian; | |
128 | enum regmap_endian val_format_endian; | |
b83a313b MB |
129 | }; |
130 | ||
0135bbcc | 131 | typedef int (*regmap_hw_write)(void *context, const void *data, |
b83a313b | 132 | size_t count); |
0135bbcc | 133 | typedef int (*regmap_hw_gather_write)(void *context, |
b83a313b MB |
134 | const void *reg, size_t reg_len, |
135 | const void *val, size_t val_len); | |
0135bbcc | 136 | typedef int (*regmap_hw_read)(void *context, |
b83a313b MB |
137 | const void *reg_buf, size_t reg_size, |
138 | void *val_buf, size_t val_size); | |
0135bbcc | 139 | typedef void (*regmap_hw_free_context)(void *context); |
b83a313b MB |
140 | |
141 | /** | |
142 | * Description of a hardware bus for the register map infrastructure. | |
143 | * | |
bacdbe07 SW |
144 | * @fast_io: Register IO is fast. Use a spinlock instead of a mutex |
145 | * to perform locking. | |
b83a313b MB |
146 | * @write: Write operation. |
147 | * @gather_write: Write operation with split register/value, return -ENOTSUPP | |
148 | * if not implemented on a given device. | |
149 | * @read: Read operation. Data is returned in the buffer used to transmit | |
150 | * data. | |
b83a313b MB |
151 | * @read_flag_mask: Mask to be set in the top byte of the register when doing |
152 | * a read. | |
141eba2e SW |
153 | * @reg_format_endian_default: Default endianness for formatted register |
154 | * addresses. Used when the regmap_config specifies DEFAULT. If this is | |
155 | * DEFAULT, BIG is assumed. | |
156 | * @val_format_endian_default: Default endianness for formatted register | |
157 | * values. Used when the regmap_config specifies DEFAULT. If this is | |
158 | * DEFAULT, BIG is assumed. | |
b83a313b MB |
159 | */ |
160 | struct regmap_bus { | |
bacdbe07 | 161 | bool fast_io; |
b83a313b MB |
162 | regmap_hw_write write; |
163 | regmap_hw_gather_write gather_write; | |
164 | regmap_hw_read read; | |
0135bbcc | 165 | regmap_hw_free_context free_context; |
b83a313b | 166 | u8 read_flag_mask; |
141eba2e SW |
167 | enum regmap_endian reg_format_endian_default; |
168 | enum regmap_endian val_format_endian_default; | |
b83a313b MB |
169 | }; |
170 | ||
171 | struct regmap *regmap_init(struct device *dev, | |
172 | const struct regmap_bus *bus, | |
0135bbcc | 173 | void *bus_context, |
b83a313b | 174 | const struct regmap_config *config); |
9943fa30 MB |
175 | struct regmap *regmap_init_i2c(struct i2c_client *i2c, |
176 | const struct regmap_config *config); | |
a676f083 MB |
177 | struct regmap *regmap_init_spi(struct spi_device *dev, |
178 | const struct regmap_config *config); | |
45f5ff81 SW |
179 | struct regmap *regmap_init_mmio(struct device *dev, |
180 | void __iomem *regs, | |
181 | const struct regmap_config *config); | |
a676f083 | 182 | |
c0eb4676 MB |
183 | struct regmap *devm_regmap_init(struct device *dev, |
184 | const struct regmap_bus *bus, | |
0135bbcc | 185 | void *bus_context, |
c0eb4676 MB |
186 | const struct regmap_config *config); |
187 | struct regmap *devm_regmap_init_i2c(struct i2c_client *i2c, | |
188 | const struct regmap_config *config); | |
189 | struct regmap *devm_regmap_init_spi(struct spi_device *dev, | |
190 | const struct regmap_config *config); | |
45f5ff81 SW |
191 | struct regmap *devm_regmap_init_mmio(struct device *dev, |
192 | void __iomem *regs, | |
193 | const struct regmap_config *config); | |
c0eb4676 | 194 | |
b83a313b | 195 | void regmap_exit(struct regmap *map); |
bf315173 MB |
196 | int regmap_reinit_cache(struct regmap *map, |
197 | const struct regmap_config *config); | |
72b39f6f | 198 | struct regmap *dev_get_regmap(struct device *dev, const char *name); |
b83a313b MB |
199 | int regmap_write(struct regmap *map, unsigned int reg, unsigned int val); |
200 | int regmap_raw_write(struct regmap *map, unsigned int reg, | |
201 | const void *val, size_t val_len); | |
8eaeb219 LD |
202 | int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val, |
203 | size_t val_count); | |
b83a313b MB |
204 | int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val); |
205 | int regmap_raw_read(struct regmap *map, unsigned int reg, | |
206 | void *val, size_t val_len); | |
207 | int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val, | |
208 | size_t val_count); | |
209 | int regmap_update_bits(struct regmap *map, unsigned int reg, | |
210 | unsigned int mask, unsigned int val); | |
018690d3 MB |
211 | int regmap_update_bits_check(struct regmap *map, unsigned int reg, |
212 | unsigned int mask, unsigned int val, | |
213 | bool *change); | |
a6539c32 | 214 | int regmap_get_val_bytes(struct regmap *map); |
b83a313b | 215 | |
39a58439 | 216 | int regcache_sync(struct regmap *map); |
4d4cfd16 MB |
217 | int regcache_sync_region(struct regmap *map, unsigned int min, |
218 | unsigned int max); | |
92afb286 | 219 | void regcache_cache_only(struct regmap *map, bool enable); |
6eb0f5e0 | 220 | void regcache_cache_bypass(struct regmap *map, bool enable); |
8ae0d7e8 | 221 | void regcache_mark_dirty(struct regmap *map); |
92afb286 | 222 | |
22f0d90a MB |
223 | int regmap_register_patch(struct regmap *map, const struct reg_default *regs, |
224 | int num_regs); | |
225 | ||
f8beab2b MB |
226 | /** |
227 | * Description of an IRQ for the generic regmap irq_chip. | |
228 | * | |
229 | * @reg_offset: Offset of the status/mask register within the bank | |
230 | * @mask: Mask used to flag/control the register. | |
231 | */ | |
232 | struct regmap_irq { | |
233 | unsigned int reg_offset; | |
234 | unsigned int mask; | |
235 | }; | |
236 | ||
237 | /** | |
238 | * Description of a generic regmap irq_chip. This is not intended to | |
239 | * handle every possible interrupt controller, but it should handle a | |
240 | * substantial proportion of those that are found in the wild. | |
241 | * | |
242 | * @name: Descriptive name for IRQ controller. | |
243 | * | |
244 | * @status_base: Base status register address. | |
245 | * @mask_base: Base mask register address. | |
246 | * @ack_base: Base ack address. If zero then the chip is clear on read. | |
022f926a | 247 | * @irq_reg_stride: Stride to use for chips where registers are not contiguous. |
f8beab2b MB |
248 | * |
249 | * @num_regs: Number of registers in each control bank. | |
250 | * @irqs: Descriptors for individual IRQs. Interrupt numbers are | |
251 | * assigned based on the index in the array of the interrupt. | |
252 | * @num_irqs: Number of descriptors. | |
253 | */ | |
254 | struct regmap_irq_chip { | |
255 | const char *name; | |
256 | ||
257 | unsigned int status_base; | |
258 | unsigned int mask_base; | |
259 | unsigned int ack_base; | |
022f926a | 260 | unsigned int irq_reg_stride; |
f8beab2b MB |
261 | |
262 | int num_regs; | |
263 | ||
264 | const struct regmap_irq *irqs; | |
265 | int num_irqs; | |
266 | }; | |
267 | ||
268 | struct regmap_irq_chip_data; | |
269 | ||
270 | int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags, | |
b026ddbb | 271 | int irq_base, const struct regmap_irq_chip *chip, |
f8beab2b MB |
272 | struct regmap_irq_chip_data **data); |
273 | void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data); | |
209a6006 | 274 | int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data); |
4af8be67 | 275 | int regmap_irq_get_virq(struct regmap_irq_chip_data *data, int irq); |
92afb286 | 276 | |
9cde5fcd MB |
277 | #else |
278 | ||
279 | /* | |
280 | * These stubs should only ever be called by generic code which has | |
281 | * regmap based facilities, if they ever get called at runtime | |
282 | * something is going wrong and something probably needs to select | |
283 | * REGMAP. | |
284 | */ | |
285 | ||
286 | static inline int regmap_write(struct regmap *map, unsigned int reg, | |
287 | unsigned int val) | |
288 | { | |
289 | WARN_ONCE(1, "regmap API is disabled"); | |
290 | return -EINVAL; | |
291 | } | |
292 | ||
293 | static inline int regmap_raw_write(struct regmap *map, unsigned int reg, | |
294 | const void *val, size_t val_len) | |
295 | { | |
296 | WARN_ONCE(1, "regmap API is disabled"); | |
297 | return -EINVAL; | |
298 | } | |
299 | ||
300 | static inline int regmap_bulk_write(struct regmap *map, unsigned int reg, | |
301 | const void *val, size_t val_count) | |
302 | { | |
303 | WARN_ONCE(1, "regmap API is disabled"); | |
304 | return -EINVAL; | |
305 | } | |
306 | ||
307 | static inline int regmap_read(struct regmap *map, unsigned int reg, | |
308 | unsigned int *val) | |
309 | { | |
310 | WARN_ONCE(1, "regmap API is disabled"); | |
311 | return -EINVAL; | |
312 | } | |
313 | ||
314 | static inline int regmap_raw_read(struct regmap *map, unsigned int reg, | |
315 | void *val, size_t val_len) | |
316 | { | |
317 | WARN_ONCE(1, "regmap API is disabled"); | |
318 | return -EINVAL; | |
319 | } | |
320 | ||
321 | static inline int regmap_bulk_read(struct regmap *map, unsigned int reg, | |
322 | void *val, size_t val_count) | |
323 | { | |
324 | WARN_ONCE(1, "regmap API is disabled"); | |
325 | return -EINVAL; | |
326 | } | |
327 | ||
328 | static inline int regmap_update_bits(struct regmap *map, unsigned int reg, | |
329 | unsigned int mask, unsigned int val) | |
330 | { | |
331 | WARN_ONCE(1, "regmap API is disabled"); | |
332 | return -EINVAL; | |
333 | } | |
334 | ||
335 | static inline int regmap_update_bits_check(struct regmap *map, | |
336 | unsigned int reg, | |
337 | unsigned int mask, unsigned int val, | |
338 | bool *change) | |
339 | { | |
340 | WARN_ONCE(1, "regmap API is disabled"); | |
341 | return -EINVAL; | |
342 | } | |
343 | ||
344 | static inline int regmap_get_val_bytes(struct regmap *map) | |
345 | { | |
346 | WARN_ONCE(1, "regmap API is disabled"); | |
347 | return -EINVAL; | |
348 | } | |
349 | ||
350 | static inline int regcache_sync(struct regmap *map) | |
351 | { | |
352 | WARN_ONCE(1, "regmap API is disabled"); | |
353 | return -EINVAL; | |
354 | } | |
355 | ||
a313f9f5 MB |
356 | static inline int regcache_sync_region(struct regmap *map, unsigned int min, |
357 | unsigned int max) | |
358 | { | |
359 | WARN_ONCE(1, "regmap API is disabled"); | |
360 | return -EINVAL; | |
361 | } | |
362 | ||
9cde5fcd MB |
363 | static inline void regcache_cache_only(struct regmap *map, bool enable) |
364 | { | |
365 | WARN_ONCE(1, "regmap API is disabled"); | |
366 | } | |
367 | ||
368 | static inline void regcache_cache_bypass(struct regmap *map, bool enable) | |
369 | { | |
370 | WARN_ONCE(1, "regmap API is disabled"); | |
371 | } | |
372 | ||
373 | static inline void regcache_mark_dirty(struct regmap *map) | |
374 | { | |
375 | WARN_ONCE(1, "regmap API is disabled"); | |
376 | } | |
377 | ||
378 | static inline int regmap_register_patch(struct regmap *map, | |
379 | const struct reg_default *regs, | |
380 | int num_regs) | |
381 | { | |
382 | WARN_ONCE(1, "regmap API is disabled"); | |
383 | return -EINVAL; | |
384 | } | |
385 | ||
72b39f6f MB |
386 | static inline struct regmap *dev_get_regmap(struct device *dev, |
387 | const char *name) | |
388 | { | |
72b39f6f MB |
389 | return NULL; |
390 | } | |
391 | ||
9cde5fcd MB |
392 | #endif |
393 | ||
b83a313b | 394 | #endif |