]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/regmap.h
regmap: Add tracepoints for cache only and cache bypass
[mirror_ubuntu-bionic-kernel.git] / include / linux / regmap.h
CommitLineData
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
16#include <linux/device.h>
17#include <linux/list.h>
b83a313b 18
9cde5fcd
MB
19#ifdef CONFIG_REGMAP
20
de477254 21struct module;
9943fa30 22struct i2c_client;
a676f083 23struct spi_device;
9943fa30 24
9fabe24e
DP
25/* An enum of all the supported cache types */
26enum regcache_type {
27 REGCACHE_NONE,
28644c80 28 REGCACHE_RBTREE,
50b776fc 29 REGCACHE_COMPRESSED
9fabe24e
DP
30};
31
bd20eb54
MB
32/**
33 * Default value for a register. We use an array of structs rather
34 * than a simple array as many modern devices have very sparse
35 * register maps.
36 *
37 * @reg: Register address.
38 * @def: Register default value.
39 */
40struct reg_default {
41 unsigned int reg;
42 unsigned int def;
43};
44
dd898b20
MB
45/**
46 * Configuration for the register map of a device.
47 *
48 * @reg_bits: Number of bits in a register address, mandatory.
82159ba8 49 * @pad_bits: Number of bits of padding between register and value.
dd898b20 50 * @val_bits: Number of bits in a register value, mandatory.
2e2ae66d 51 *
3566cc9d
MB
52 * @writeable_reg: Optional callback returning true if the register
53 * can be written to.
54 * @readable_reg: Optional callback returning true if the register
55 * can be read from.
56 * @volatile_reg: Optional callback returning true if the register
57 * value can't be cached.
58 * @precious_reg: Optional callback returning true if the rgister
59 * should not be read outside of a call from the driver
60 * (eg, a clear on read interrupt status register).
bd20eb54
MB
61 *
62 * @max_register: Optional, specifies the maximum valid register index.
63 * @reg_defaults: Power on reset values for registers (for use with
64 * register cache support).
65 * @num_reg_defaults: Number of elements in reg_defaults.
6f306441
LPC
66 *
67 * @read_flag_mask: Mask to be set in the top byte of the register when doing
68 * a read.
69 * @write_flag_mask: Mask to be set in the top byte of the register when doing
70 * a write. If both read_flag_mask and write_flag_mask are
71 * empty the regmap_bus default masks are used.
9fabe24e
DP
72 *
73 * @cache_type: The actual cache type.
74 * @reg_defaults_raw: Power on reset values for registers (for use with
75 * register cache support).
76 * @num_reg_defaults_raw: Number of elements in reg_defaults_raw.
dd898b20 77 */
b83a313b
MB
78struct regmap_config {
79 int reg_bits;
82159ba8 80 int pad_bits;
b83a313b 81 int val_bits;
2e2ae66d 82
2e2ae66d
MB
83 bool (*writeable_reg)(struct device *dev, unsigned int reg);
84 bool (*readable_reg)(struct device *dev, unsigned int reg);
85 bool (*volatile_reg)(struct device *dev, unsigned int reg);
18694886 86 bool (*precious_reg)(struct device *dev, unsigned int reg);
bd20eb54
MB
87
88 unsigned int max_register;
720e4616 89 const struct reg_default *reg_defaults;
9fabe24e
DP
90 unsigned int num_reg_defaults;
91 enum regcache_type cache_type;
92 const void *reg_defaults_raw;
93 unsigned int num_reg_defaults_raw;
6f306441
LPC
94
95 u8 read_flag_mask;
96 u8 write_flag_mask;
b83a313b
MB
97};
98
99typedef int (*regmap_hw_write)(struct device *dev, const void *data,
100 size_t count);
101typedef int (*regmap_hw_gather_write)(struct device *dev,
102 const void *reg, size_t reg_len,
103 const void *val, size_t val_len);
104typedef int (*regmap_hw_read)(struct device *dev,
105 const void *reg_buf, size_t reg_size,
106 void *val_buf, size_t val_size);
107
108/**
109 * Description of a hardware bus for the register map infrastructure.
110 *
b83a313b
MB
111 * @write: Write operation.
112 * @gather_write: Write operation with split register/value, return -ENOTSUPP
113 * if not implemented on a given device.
114 * @read: Read operation. Data is returned in the buffer used to transmit
115 * data.
b83a313b
MB
116 * @read_flag_mask: Mask to be set in the top byte of the register when doing
117 * a read.
118 */
119struct regmap_bus {
b83a313b
MB
120 regmap_hw_write write;
121 regmap_hw_gather_write gather_write;
122 regmap_hw_read read;
b83a313b
MB
123 u8 read_flag_mask;
124};
125
126struct regmap *regmap_init(struct device *dev,
127 const struct regmap_bus *bus,
128 const struct regmap_config *config);
9943fa30
MB
129struct regmap *regmap_init_i2c(struct i2c_client *i2c,
130 const struct regmap_config *config);
a676f083
MB
131struct regmap *regmap_init_spi(struct spi_device *dev,
132 const struct regmap_config *config);
133
b83a313b 134void regmap_exit(struct regmap *map);
bf315173
MB
135int regmap_reinit_cache(struct regmap *map,
136 const struct regmap_config *config);
b83a313b
MB
137int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
138int regmap_raw_write(struct regmap *map, unsigned int reg,
139 const void *val, size_t val_len);
140int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
141int regmap_raw_read(struct regmap *map, unsigned int reg,
142 void *val, size_t val_len);
143int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
144 size_t val_count);
145int regmap_update_bits(struct regmap *map, unsigned int reg,
146 unsigned int mask, unsigned int val);
018690d3
MB
147int regmap_update_bits_check(struct regmap *map, unsigned int reg,
148 unsigned int mask, unsigned int val,
149 bool *change);
b83a313b 150
39a58439 151int regcache_sync(struct regmap *map);
92afb286 152void regcache_cache_only(struct regmap *map, bool enable);
6eb0f5e0 153void regcache_cache_bypass(struct regmap *map, bool enable);
8ae0d7e8 154void regcache_mark_dirty(struct regmap *map);
92afb286 155
f8beab2b
MB
156/**
157 * Description of an IRQ for the generic regmap irq_chip.
158 *
159 * @reg_offset: Offset of the status/mask register within the bank
160 * @mask: Mask used to flag/control the register.
161 */
162struct regmap_irq {
163 unsigned int reg_offset;
164 unsigned int mask;
165};
166
167/**
168 * Description of a generic regmap irq_chip. This is not intended to
169 * handle every possible interrupt controller, but it should handle a
170 * substantial proportion of those that are found in the wild.
171 *
172 * @name: Descriptive name for IRQ controller.
173 *
174 * @status_base: Base status register address.
175 * @mask_base: Base mask register address.
176 * @ack_base: Base ack address. If zero then the chip is clear on read.
177 *
178 * @num_regs: Number of registers in each control bank.
179 * @irqs: Descriptors for individual IRQs. Interrupt numbers are
180 * assigned based on the index in the array of the interrupt.
181 * @num_irqs: Number of descriptors.
182 */
183struct regmap_irq_chip {
184 const char *name;
185
186 unsigned int status_base;
187 unsigned int mask_base;
188 unsigned int ack_base;
189
190 int num_regs;
191
192 const struct regmap_irq *irqs;
193 int num_irqs;
194};
195
196struct regmap_irq_chip_data;
197
198int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
199 int irq_base, struct regmap_irq_chip *chip,
200 struct regmap_irq_chip_data **data);
201void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data);
209a6006 202int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data);
92afb286 203
9cde5fcd
MB
204#else
205
206/*
207 * These stubs should only ever be called by generic code which has
208 * regmap based facilities, if they ever get called at runtime
209 * something is going wrong and something probably needs to select
210 * REGMAP.
211 */
212
213static inline int regmap_write(struct regmap *map, unsigned int reg,
214 unsigned int val)
215{
216 WARN_ONCE(1, "regmap API is disabled");
217 return -EINVAL;
218}
219
220static inline int regmap_raw_write(struct regmap *map, unsigned int reg,
221 const void *val, size_t val_len)
222{
223 WARN_ONCE(1, "regmap API is disabled");
224 return -EINVAL;
225}
226
227static inline int regmap_bulk_write(struct regmap *map, unsigned int reg,
228 const void *val, size_t val_count)
229{
230 WARN_ONCE(1, "regmap API is disabled");
231 return -EINVAL;
232}
233
234static inline int regmap_read(struct regmap *map, unsigned int reg,
235 unsigned int *val)
236{
237 WARN_ONCE(1, "regmap API is disabled");
238 return -EINVAL;
239}
240
241static inline int regmap_raw_read(struct regmap *map, unsigned int reg,
242 void *val, size_t val_len)
243{
244 WARN_ONCE(1, "regmap API is disabled");
245 return -EINVAL;
246}
247
248static inline int regmap_bulk_read(struct regmap *map, unsigned int reg,
249 void *val, size_t val_count)
250{
251 WARN_ONCE(1, "regmap API is disabled");
252 return -EINVAL;
253}
254
255static inline int regmap_update_bits(struct regmap *map, unsigned int reg,
256 unsigned int mask, unsigned int val)
257{
258 WARN_ONCE(1, "regmap API is disabled");
259 return -EINVAL;
260}
261
262static inline int regmap_update_bits_check(struct regmap *map,
263 unsigned int reg,
264 unsigned int mask, unsigned int val,
265 bool *change)
266{
267 WARN_ONCE(1, "regmap API is disabled");
268 return -EINVAL;
269}
270
271static inline int regmap_get_val_bytes(struct regmap *map)
272{
273 WARN_ONCE(1, "regmap API is disabled");
274 return -EINVAL;
275}
276
277static inline int regcache_sync(struct regmap *map)
278{
279 WARN_ONCE(1, "regmap API is disabled");
280 return -EINVAL;
281}
282
283static inline void regcache_cache_only(struct regmap *map, bool enable)
284{
285 WARN_ONCE(1, "regmap API is disabled");
286}
287
288static inline void regcache_cache_bypass(struct regmap *map, bool enable)
289{
290 WARN_ONCE(1, "regmap API is disabled");
291}
292
293static inline void regcache_mark_dirty(struct regmap *map)
294{
295 WARN_ONCE(1, "regmap API is disabled");
296}
297
298static inline int regmap_register_patch(struct regmap *map,
299 const struct reg_default *regs,
300 int num_regs)
301{
302 WARN_ONCE(1, "regmap API is disabled");
303 return -EINVAL;
304}
305
306#endif
307
b83a313b 308#endif