1 #ifndef __LINUX_REGMAP_H
2 #define __LINUX_REGMAP_H
5 * Register map access API
7 * Copyright 2011 Wolfson Microelectronics plc
9 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
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.
16 #include <linux/list.h>
24 /* An enum of all the supported cache types */
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
36 * @reg: Register address.
37 * @def: Register default value.
47 * Configuration for the register map of a device.
49 * @name: Optional name of the regmap. Useful when a device has multiple
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
56 * @pad_bits: Number of bits of padding between register and value.
57 * @val_bits: Number of bits in a register value, mandatory.
59 * @writeable_reg: Optional callback returning true if the register
61 * @readable_reg: Optional callback returning true if the register
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).
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.
74 * @read_flag_mask: Mask to be set in the top byte of the register when doing
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.
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.
85 struct regmap_config
{
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
);
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
;
109 typedef int (*regmap_hw_write
)(void *context
, const void *data
,
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
);
120 * Description of a hardware bus for the register map infrastructure.
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
129 * @read_flag_mask: Mask to be set in the top byte of the register when doing
134 regmap_hw_write write
;
135 regmap_hw_gather_write gather_write
;
137 regmap_hw_free_context free_context
;
141 struct regmap
*regmap_init(struct device
*dev
,
142 const struct regmap_bus
*bus
,
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
,
151 const struct regmap_config
*config
);
153 struct regmap
*devm_regmap_init(struct device
*dev
,
154 const struct regmap_bus
*bus
,
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
,
163 const struct regmap_config
*config
);
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
,
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
,
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
,
183 int regmap_get_val_bytes(struct regmap
*map
);
185 int regcache_sync(struct regmap
*map
);
186 int regcache_sync_region(struct regmap
*map
, unsigned int min
,
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
);
192 int regmap_register_patch(struct regmap
*map
, const struct reg_default
*regs
,
196 * Description of an IRQ for the generic regmap irq_chip.
198 * @reg_offset: Offset of the status/mask register within the bank
199 * @mask: Mask used to flag/control the register.
202 unsigned int reg_offset
;
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.
211 * @name: Descriptive name for IRQ controller.
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.
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.
222 struct regmap_irq_chip
{
225 unsigned int status_base
;
226 unsigned int mask_base
;
227 unsigned int ack_base
;
231 const struct regmap_irq
*irqs
;
235 struct regmap_irq_chip_data
;
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
);
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
252 static inline int regmap_write(struct regmap
*map
, unsigned int reg
,
255 WARN_ONCE(1, "regmap API is disabled");
259 static inline int regmap_raw_write(struct regmap
*map
, unsigned int reg
,
260 const void *val
, size_t val_len
)
262 WARN_ONCE(1, "regmap API is disabled");
266 static inline int regmap_bulk_write(struct regmap
*map
, unsigned int reg
,
267 const void *val
, size_t val_count
)
269 WARN_ONCE(1, "regmap API is disabled");
273 static inline int regmap_read(struct regmap
*map
, unsigned int reg
,
276 WARN_ONCE(1, "regmap API is disabled");
280 static inline int regmap_raw_read(struct regmap
*map
, unsigned int reg
,
281 void *val
, size_t val_len
)
283 WARN_ONCE(1, "regmap API is disabled");
287 static inline int regmap_bulk_read(struct regmap
*map
, unsigned int reg
,
288 void *val
, size_t val_count
)
290 WARN_ONCE(1, "regmap API is disabled");
294 static inline int regmap_update_bits(struct regmap
*map
, unsigned int reg
,
295 unsigned int mask
, unsigned int val
)
297 WARN_ONCE(1, "regmap API is disabled");
301 static inline int regmap_update_bits_check(struct regmap
*map
,
303 unsigned int mask
, unsigned int val
,
306 WARN_ONCE(1, "regmap API is disabled");
310 static inline int regmap_get_val_bytes(struct regmap
*map
)
312 WARN_ONCE(1, "regmap API is disabled");
316 static inline int regcache_sync(struct regmap
*map
)
318 WARN_ONCE(1, "regmap API is disabled");
322 static inline int regcache_sync_region(struct regmap
*map
, unsigned int min
,
325 WARN_ONCE(1, "regmap API is disabled");
329 static inline void regcache_cache_only(struct regmap
*map
, bool enable
)
331 WARN_ONCE(1, "regmap API is disabled");
334 static inline void regcache_cache_bypass(struct regmap
*map
, bool enable
)
336 WARN_ONCE(1, "regmap API is disabled");
339 static inline void regcache_mark_dirty(struct regmap
*map
)
341 WARN_ONCE(1, "regmap API is disabled");
344 static inline int regmap_register_patch(struct regmap
*map
,
345 const struct reg_default
*regs
,
348 WARN_ONCE(1, "regmap API is disabled");