regmap: fix compile errors in regmap-irq.c due to stride changes
[deliverable/linux.git] / include / linux / regmap.h
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
16 #include <linux/list.h>
17
18 struct module;
19 struct device;
20 struct i2c_client;
21 struct spi_device;
22 struct regmap;
23
24 /* An enum of all the supported cache types */
25 enum regcache_type {
26 REGCACHE_NONE,
27 REGCACHE_RBTREE,
28 REGCACHE_COMPRESSED
29 };
30
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
44 #ifdef CONFIG_REGMAP
45
46 /**
47 * Configuration for the register map of a device.
48 *
49 * @name: Optional name of the regmap. Useful when a device has multiple
50 * register regions.
51 *
52 * @reg_bits: Number of bits in a register address, mandatory.
53 * @reg_stride: The register address stride. Valid register addresses are a
54 * multiple of this value. If set to 0, a value of 1 will be
55 * used.
56 * @pad_bits: Number of bits of padding between register and value.
57 * @val_bits: Number of bits in a register value, mandatory.
58 *
59 * @writeable_reg: Optional callback returning true if the register
60 * can be written to.
61 * @readable_reg: Optional callback returning true if the register
62 * can be read from.
63 * @volatile_reg: Optional callback returning true if the register
64 * value can't be cached.
65 * @precious_reg: Optional callback returning true if the rgister
66 * should not be read outside of a call from the driver
67 * (eg, a clear on read interrupt status register).
68 *
69 * @max_register: Optional, specifies the maximum valid register index.
70 * @reg_defaults: Power on reset values for registers (for use with
71 * register cache support).
72 * @num_reg_defaults: Number of elements in reg_defaults.
73 *
74 * @read_flag_mask: Mask to be set in the top byte of the register when doing
75 * a read.
76 * @write_flag_mask: Mask to be set in the top byte of the register when doing
77 * a write. If both read_flag_mask and write_flag_mask are
78 * empty the regmap_bus default masks are used.
79 *
80 * @cache_type: The actual cache type.
81 * @reg_defaults_raw: Power on reset values for registers (for use with
82 * register cache support).
83 * @num_reg_defaults_raw: Number of elements in reg_defaults_raw.
84 */
85 struct regmap_config {
86 const char *name;
87
88 int reg_bits;
89 int reg_stride;
90 int pad_bits;
91 int val_bits;
92
93 bool (*writeable_reg)(struct device *dev, unsigned int reg);
94 bool (*readable_reg)(struct device *dev, unsigned int reg);
95 bool (*volatile_reg)(struct device *dev, unsigned int reg);
96 bool (*precious_reg)(struct device *dev, unsigned int reg);
97
98 unsigned int max_register;
99 const struct reg_default *reg_defaults;
100 unsigned int num_reg_defaults;
101 enum regcache_type cache_type;
102 const void *reg_defaults_raw;
103 unsigned int num_reg_defaults_raw;
104
105 u8 read_flag_mask;
106 u8 write_flag_mask;
107 };
108
109 typedef int (*regmap_hw_write)(void *context, const void *data,
110 size_t count);
111 typedef int (*regmap_hw_gather_write)(void *context,
112 const void *reg, size_t reg_len,
113 const void *val, size_t val_len);
114 typedef int (*regmap_hw_read)(void *context,
115 const void *reg_buf, size_t reg_size,
116 void *val_buf, size_t val_size);
117 typedef void (*regmap_hw_free_context)(void *context);
118
119 /**
120 * Description of a hardware bus for the register map infrastructure.
121 *
122 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
123 * to perform locking.
124 * @write: Write operation.
125 * @gather_write: Write operation with split register/value, return -ENOTSUPP
126 * if not implemented on a given device.
127 * @read: Read operation. Data is returned in the buffer used to transmit
128 * data.
129 * @read_flag_mask: Mask to be set in the top byte of the register when doing
130 * a read.
131 */
132 struct regmap_bus {
133 bool fast_io;
134 regmap_hw_write write;
135 regmap_hw_gather_write gather_write;
136 regmap_hw_read read;
137 regmap_hw_free_context free_context;
138 u8 read_flag_mask;
139 };
140
141 struct regmap *regmap_init(struct device *dev,
142 const struct regmap_bus *bus,
143 void *bus_context,
144 const struct regmap_config *config);
145 struct regmap *regmap_init_i2c(struct i2c_client *i2c,
146 const struct regmap_config *config);
147 struct regmap *regmap_init_spi(struct spi_device *dev,
148 const struct regmap_config *config);
149 struct regmap *regmap_init_mmio(struct device *dev,
150 void __iomem *regs,
151 const struct regmap_config *config);
152
153 struct regmap *devm_regmap_init(struct device *dev,
154 const struct regmap_bus *bus,
155 void *bus_context,
156 const struct regmap_config *config);
157 struct regmap *devm_regmap_init_i2c(struct i2c_client *i2c,
158 const struct regmap_config *config);
159 struct regmap *devm_regmap_init_spi(struct spi_device *dev,
160 const struct regmap_config *config);
161 struct regmap *devm_regmap_init_mmio(struct device *dev,
162 void __iomem *regs,
163 const struct regmap_config *config);
164
165 void regmap_exit(struct regmap *map);
166 int regmap_reinit_cache(struct regmap *map,
167 const struct regmap_config *config);
168 int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
169 int regmap_raw_write(struct regmap *map, unsigned int reg,
170 const void *val, size_t val_len);
171 int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
172 size_t val_count);
173 int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
174 int regmap_raw_read(struct regmap *map, unsigned int reg,
175 void *val, size_t val_len);
176 int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
177 size_t val_count);
178 int regmap_update_bits(struct regmap *map, unsigned int reg,
179 unsigned int mask, unsigned int val);
180 int regmap_update_bits_check(struct regmap *map, unsigned int reg,
181 unsigned int mask, unsigned int val,
182 bool *change);
183 int regmap_get_val_bytes(struct regmap *map);
184
185 int regcache_sync(struct regmap *map);
186 int regcache_sync_region(struct regmap *map, unsigned int min,
187 unsigned int max);
188 void regcache_cache_only(struct regmap *map, bool enable);
189 void regcache_cache_bypass(struct regmap *map, bool enable);
190 void regcache_mark_dirty(struct regmap *map);
191
192 int regmap_register_patch(struct regmap *map, const struct reg_default *regs,
193 int num_regs);
194
195 /**
196 * Description of an IRQ for the generic regmap irq_chip.
197 *
198 * @reg_offset: Offset of the status/mask register within the bank
199 * @mask: Mask used to flag/control the register.
200 */
201 struct regmap_irq {
202 unsigned int reg_offset;
203 unsigned int mask;
204 };
205
206 /**
207 * Description of a generic regmap irq_chip. This is not intended to
208 * handle every possible interrupt controller, but it should handle a
209 * substantial proportion of those that are found in the wild.
210 *
211 * @name: Descriptive name for IRQ controller.
212 *
213 * @status_base: Base status register address.
214 * @mask_base: Base mask register address.
215 * @ack_base: Base ack address. If zero then the chip is clear on read.
216 *
217 * @num_regs: Number of registers in each control bank.
218 * @irqs: Descriptors for individual IRQs. Interrupt numbers are
219 * assigned based on the index in the array of the interrupt.
220 * @num_irqs: Number of descriptors.
221 */
222 struct regmap_irq_chip {
223 const char *name;
224
225 unsigned int status_base;
226 unsigned int mask_base;
227 unsigned int ack_base;
228
229 int num_regs;
230
231 const struct regmap_irq *irqs;
232 int num_irqs;
233 };
234
235 struct regmap_irq_chip_data;
236
237 int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
238 int irq_base, struct regmap_irq_chip *chip,
239 struct regmap_irq_chip_data **data);
240 void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data);
241 int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data);
242
243 #else
244
245 /*
246 * These stubs should only ever be called by generic code which has
247 * regmap based facilities, if they ever get called at runtime
248 * something is going wrong and something probably needs to select
249 * REGMAP.
250 */
251
252 static inline int regmap_write(struct regmap *map, unsigned int reg,
253 unsigned int val)
254 {
255 WARN_ONCE(1, "regmap API is disabled");
256 return -EINVAL;
257 }
258
259 static inline int regmap_raw_write(struct regmap *map, unsigned int reg,
260 const void *val, size_t val_len)
261 {
262 WARN_ONCE(1, "regmap API is disabled");
263 return -EINVAL;
264 }
265
266 static inline int regmap_bulk_write(struct regmap *map, unsigned int reg,
267 const void *val, size_t val_count)
268 {
269 WARN_ONCE(1, "regmap API is disabled");
270 return -EINVAL;
271 }
272
273 static inline int regmap_read(struct regmap *map, unsigned int reg,
274 unsigned int *val)
275 {
276 WARN_ONCE(1, "regmap API is disabled");
277 return -EINVAL;
278 }
279
280 static inline int regmap_raw_read(struct regmap *map, unsigned int reg,
281 void *val, size_t val_len)
282 {
283 WARN_ONCE(1, "regmap API is disabled");
284 return -EINVAL;
285 }
286
287 static inline int regmap_bulk_read(struct regmap *map, unsigned int reg,
288 void *val, size_t val_count)
289 {
290 WARN_ONCE(1, "regmap API is disabled");
291 return -EINVAL;
292 }
293
294 static inline int regmap_update_bits(struct regmap *map, unsigned int reg,
295 unsigned int mask, unsigned int val)
296 {
297 WARN_ONCE(1, "regmap API is disabled");
298 return -EINVAL;
299 }
300
301 static inline int regmap_update_bits_check(struct regmap *map,
302 unsigned int reg,
303 unsigned int mask, unsigned int val,
304 bool *change)
305 {
306 WARN_ONCE(1, "regmap API is disabled");
307 return -EINVAL;
308 }
309
310 static inline int regmap_get_val_bytes(struct regmap *map)
311 {
312 WARN_ONCE(1, "regmap API is disabled");
313 return -EINVAL;
314 }
315
316 static inline int regcache_sync(struct regmap *map)
317 {
318 WARN_ONCE(1, "regmap API is disabled");
319 return -EINVAL;
320 }
321
322 static inline int regcache_sync_region(struct regmap *map, unsigned int min,
323 unsigned int max)
324 {
325 WARN_ONCE(1, "regmap API is disabled");
326 return -EINVAL;
327 }
328
329 static inline void regcache_cache_only(struct regmap *map, bool enable)
330 {
331 WARN_ONCE(1, "regmap API is disabled");
332 }
333
334 static inline void regcache_cache_bypass(struct regmap *map, bool enable)
335 {
336 WARN_ONCE(1, "regmap API is disabled");
337 }
338
339 static inline void regcache_mark_dirty(struct regmap *map)
340 {
341 WARN_ONCE(1, "regmap API is disabled");
342 }
343
344 static inline int regmap_register_patch(struct regmap *map,
345 const struct reg_default *regs,
346 int num_regs)
347 {
348 WARN_ONCE(1, "regmap API is disabled");
349 return -EINVAL;
350 }
351
352 #endif
353
354 #endif
This page took 0.043246 seconds and 5 git commands to generate.