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 * @pad_bits: Number of bits of padding between register and value.
54 * @val_bits: Number of bits in a register value, mandatory.
56 * @writeable_reg: Optional callback returning true if the register
58 * @readable_reg: Optional callback returning true if the register
60 * @volatile_reg: Optional callback returning true if the register
61 * value can't be cached.
62 * @precious_reg: Optional callback returning true if the rgister
63 * should not be read outside of a call from the driver
64 * (eg, a clear on read interrupt status register).
66 * @max_register: Optional, specifies the maximum valid register index.
67 * @reg_defaults: Power on reset values for registers (for use with
68 * register cache support).
69 * @num_reg_defaults: Number of elements in reg_defaults.
71 * @read_flag_mask: Mask to be set in the top byte of the register when doing
73 * @write_flag_mask: Mask to be set in the top byte of the register when doing
74 * a write. If both read_flag_mask and write_flag_mask are
75 * empty the regmap_bus default masks are used.
77 * @cache_type: The actual cache type.
78 * @reg_defaults_raw: Power on reset values for registers (for use with
79 * register cache support).
80 * @num_reg_defaults_raw: Number of elements in reg_defaults_raw.
82 struct regmap_config
{
89 bool (*writeable_reg
)(struct device
*dev
, unsigned int reg
);
90 bool (*readable_reg
)(struct device
*dev
, unsigned int reg
);
91 bool (*volatile_reg
)(struct device
*dev
, unsigned int reg
);
92 bool (*precious_reg
)(struct device
*dev
, unsigned int reg
);
94 unsigned int max_register
;
95 const struct reg_default
*reg_defaults
;
96 unsigned int num_reg_defaults
;
97 enum regcache_type cache_type
;
98 const void *reg_defaults_raw
;
99 unsigned int num_reg_defaults_raw
;
105 typedef int (*regmap_hw_write
)(void *context
, const void *data
,
107 typedef int (*regmap_hw_gather_write
)(void *context
,
108 const void *reg
, size_t reg_len
,
109 const void *val
, size_t val_len
);
110 typedef int (*regmap_hw_read
)(void *context
,
111 const void *reg_buf
, size_t reg_size
,
112 void *val_buf
, size_t val_size
);
113 typedef void (*regmap_hw_free_context
)(void *context
);
116 * Description of a hardware bus for the register map infrastructure.
118 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
119 * to perform locking.
120 * @write: Write operation.
121 * @gather_write: Write operation with split register/value, return -ENOTSUPP
122 * if not implemented on a given device.
123 * @read: Read operation. Data is returned in the buffer used to transmit
125 * @read_flag_mask: Mask to be set in the top byte of the register when doing
130 regmap_hw_write write
;
131 regmap_hw_gather_write gather_write
;
133 regmap_hw_free_context free_context
;
137 struct regmap
*regmap_init(struct device
*dev
,
138 const struct regmap_bus
*bus
,
140 const struct regmap_config
*config
);
141 struct regmap
*regmap_init_i2c(struct i2c_client
*i2c
,
142 const struct regmap_config
*config
);
143 struct regmap
*regmap_init_spi(struct spi_device
*dev
,
144 const struct regmap_config
*config
);
145 struct regmap
*regmap_init_mmio(struct device
*dev
,
147 const struct regmap_config
*config
);
149 struct regmap
*devm_regmap_init(struct device
*dev
,
150 const struct regmap_bus
*bus
,
152 const struct regmap_config
*config
);
153 struct regmap
*devm_regmap_init_i2c(struct i2c_client
*i2c
,
154 const struct regmap_config
*config
);
155 struct regmap
*devm_regmap_init_spi(struct spi_device
*dev
,
156 const struct regmap_config
*config
);
157 struct regmap
*devm_regmap_init_mmio(struct device
*dev
,
159 const struct regmap_config
*config
);
161 void regmap_exit(struct regmap
*map
);
162 int regmap_reinit_cache(struct regmap
*map
,
163 const struct regmap_config
*config
);
164 int regmap_write(struct regmap
*map
, unsigned int reg
, unsigned int val
);
165 int regmap_raw_write(struct regmap
*map
, unsigned int reg
,
166 const void *val
, size_t val_len
);
167 int regmap_bulk_write(struct regmap
*map
, unsigned int reg
, const void *val
,
169 int regmap_read(struct regmap
*map
, unsigned int reg
, unsigned int *val
);
170 int regmap_raw_read(struct regmap
*map
, unsigned int reg
,
171 void *val
, size_t val_len
);
172 int regmap_bulk_read(struct regmap
*map
, unsigned int reg
, void *val
,
174 int regmap_update_bits(struct regmap
*map
, unsigned int reg
,
175 unsigned int mask
, unsigned int val
);
176 int regmap_update_bits_check(struct regmap
*map
, unsigned int reg
,
177 unsigned int mask
, unsigned int val
,
179 int regmap_get_val_bytes(struct regmap
*map
);
181 int regcache_sync(struct regmap
*map
);
182 int regcache_sync_region(struct regmap
*map
, unsigned int min
,
184 void regcache_cache_only(struct regmap
*map
, bool enable
);
185 void regcache_cache_bypass(struct regmap
*map
, bool enable
);
186 void regcache_mark_dirty(struct regmap
*map
);
188 int regmap_register_patch(struct regmap
*map
, const struct reg_default
*regs
,
192 * Description of an IRQ for the generic regmap irq_chip.
194 * @reg_offset: Offset of the status/mask register within the bank
195 * @mask: Mask used to flag/control the register.
198 unsigned int reg_offset
;
203 * Description of a generic regmap irq_chip. This is not intended to
204 * handle every possible interrupt controller, but it should handle a
205 * substantial proportion of those that are found in the wild.
207 * @name: Descriptive name for IRQ controller.
209 * @status_base: Base status register address.
210 * @mask_base: Base mask register address.
211 * @ack_base: Base ack address. If zero then the chip is clear on read.
213 * @num_regs: Number of registers in each control bank.
214 * @irqs: Descriptors for individual IRQs. Interrupt numbers are
215 * assigned based on the index in the array of the interrupt.
216 * @num_irqs: Number of descriptors.
218 struct regmap_irq_chip
{
221 unsigned int status_base
;
222 unsigned int mask_base
;
223 unsigned int ack_base
;
227 const struct regmap_irq
*irqs
;
231 struct regmap_irq_chip_data
;
233 int regmap_add_irq_chip(struct regmap
*map
, int irq
, int irq_flags
,
234 int irq_base
, struct regmap_irq_chip
*chip
,
235 struct regmap_irq_chip_data
**data
);
236 void regmap_del_irq_chip(int irq
, struct regmap_irq_chip_data
*data
);
237 int regmap_irq_chip_get_base(struct regmap_irq_chip_data
*data
);
242 * These stubs should only ever be called by generic code which has
243 * regmap based facilities, if they ever get called at runtime
244 * something is going wrong and something probably needs to select
248 static inline int regmap_write(struct regmap
*map
, unsigned int reg
,
251 WARN_ONCE(1, "regmap API is disabled");
255 static inline int regmap_raw_write(struct regmap
*map
, unsigned int reg
,
256 const void *val
, size_t val_len
)
258 WARN_ONCE(1, "regmap API is disabled");
262 static inline int regmap_bulk_write(struct regmap
*map
, unsigned int reg
,
263 const void *val
, size_t val_count
)
265 WARN_ONCE(1, "regmap API is disabled");
269 static inline int regmap_read(struct regmap
*map
, unsigned int reg
,
272 WARN_ONCE(1, "regmap API is disabled");
276 static inline int regmap_raw_read(struct regmap
*map
, unsigned int reg
,
277 void *val
, size_t val_len
)
279 WARN_ONCE(1, "regmap API is disabled");
283 static inline int regmap_bulk_read(struct regmap
*map
, unsigned int reg
,
284 void *val
, size_t val_count
)
286 WARN_ONCE(1, "regmap API is disabled");
290 static inline int regmap_update_bits(struct regmap
*map
, unsigned int reg
,
291 unsigned int mask
, unsigned int val
)
293 WARN_ONCE(1, "regmap API is disabled");
297 static inline int regmap_update_bits_check(struct regmap
*map
,
299 unsigned int mask
, unsigned int val
,
302 WARN_ONCE(1, "regmap API is disabled");
306 static inline int regmap_get_val_bytes(struct regmap
*map
)
308 WARN_ONCE(1, "regmap API is disabled");
312 static inline int regcache_sync(struct regmap
*map
)
314 WARN_ONCE(1, "regmap API is disabled");
318 static inline int regcache_sync_region(struct regmap
*map
, unsigned int min
,
321 WARN_ONCE(1, "regmap API is disabled");
325 static inline void regcache_cache_only(struct regmap
*map
, bool enable
)
327 WARN_ONCE(1, "regmap API is disabled");
330 static inline void regcache_cache_bypass(struct regmap
*map
, bool enable
)
332 WARN_ONCE(1, "regmap API is disabled");
335 static inline void regcache_mark_dirty(struct regmap
*map
)
337 WARN_ONCE(1, "regmap API is disabled");
340 static inline int regmap_register_patch(struct regmap
*map
,
341 const struct reg_default
*regs
,
344 WARN_ONCE(1, "regmap API is disabled");