aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/regmap.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/regmap.h')
-rw-r--r--include/linux/regmap.h192
1 files changed, 177 insertions, 15 deletions
diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index e3bcc3f4dcb8..bf77dfdabef9 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -19,6 +19,7 @@
19struct module; 19struct module;
20struct device; 20struct device;
21struct i2c_client; 21struct i2c_client;
22struct irq_domain;
22struct spi_device; 23struct spi_device;
23struct regmap; 24struct regmap;
24struct regmap_range_cfg; 25struct regmap_range_cfg;
@@ -27,7 +28,8 @@ struct regmap_range_cfg;
27enum regcache_type { 28enum regcache_type {
28 REGCACHE_NONE, 29 REGCACHE_NONE,
29 REGCACHE_RBTREE, 30 REGCACHE_RBTREE,
30 REGCACHE_COMPRESSED 31 REGCACHE_COMPRESSED,
32 REGCACHE_FLAT,
31}; 33};
32 34
33/** 35/**
@@ -54,6 +56,39 @@ enum regmap_endian {
54}; 56};
55 57
56/** 58/**
59 * A register range, used for access related checks
60 * (readable/writeable/volatile/precious checks)
61 *
62 * @range_min: address of first register
63 * @range_max: address of last register
64 */
65struct regmap_range {
66 unsigned int range_min;
67 unsigned int range_max;
68};
69
70/*
71 * A table of ranges including some yes ranges and some no ranges.
72 * If a register belongs to a no_range, the corresponding check function
73 * will return false. If a register belongs to a yes range, the corresponding
74 * check function will return true. "no_ranges" are searched first.
75 *
76 * @yes_ranges : pointer to an array of regmap ranges used as "yes ranges"
77 * @n_yes_ranges: size of the above array
78 * @no_ranges: pointer to an array of regmap ranges used as "no ranges"
79 * @n_no_ranges: size of the above array
80 */
81struct regmap_access_table {
82 const struct regmap_range *yes_ranges;
83 unsigned int n_yes_ranges;
84 const struct regmap_range *no_ranges;
85 unsigned int n_no_ranges;
86};
87
88typedef void (*regmap_lock)(void *);
89typedef void (*regmap_unlock)(void *);
90
91/**
57 * Configuration for the register map of a device. 92 * Configuration for the register map of a device.
58 * 93 *
59 * @name: Optional name of the regmap. Useful when a device has multiple 94 * @name: Optional name of the regmap. Useful when a device has multiple
@@ -67,16 +102,50 @@ enum regmap_endian {
67 * @val_bits: Number of bits in a register value, mandatory. 102 * @val_bits: Number of bits in a register value, mandatory.
68 * 103 *
69 * @writeable_reg: Optional callback returning true if the register 104 * @writeable_reg: Optional callback returning true if the register
70 * can be written to. 105 * can be written to. If this field is NULL but wr_table
106 * (see below) is not, the check is performed on such table
107 * (a register is writeable if it belongs to one of the ranges
108 * specified by wr_table).
71 * @readable_reg: Optional callback returning true if the register 109 * @readable_reg: Optional callback returning true if the register
72 * can be read from. 110 * can be read from. If this field is NULL but rd_table
111 * (see below) is not, the check is performed on such table
112 * (a register is readable if it belongs to one of the ranges
113 * specified by rd_table).
73 * @volatile_reg: Optional callback returning true if the register 114 * @volatile_reg: Optional callback returning true if the register
74 * value can't be cached. 115 * value can't be cached. If this field is NULL but
116 * volatile_table (see below) is not, the check is performed on
117 * such table (a register is volatile if it belongs to one of
118 * the ranges specified by volatile_table).
75 * @precious_reg: Optional callback returning true if the rgister 119 * @precious_reg: Optional callback returning true if the rgister
76 * should not be read outside of a call from the driver 120 * should not be read outside of a call from the driver
77 * (eg, a clear on read interrupt status register). 121 * (eg, a clear on read interrupt status register). If this
78 * 122 * field is NULL but precious_table (see below) is not, the
123 * check is performed on such table (a register is precious if
124 * it belongs to one of the ranges specified by precious_table).
125 * @lock: Optional lock callback (overrides regmap's default lock
126 * function, based on spinlock or mutex).
127 * @unlock: As above for unlocking.
128 * @lock_arg: this field is passed as the only argument of lock/unlock
129 * functions (ignored in case regular lock/unlock functions
130 * are not overridden).
131 * @reg_read: Optional callback that if filled will be used to perform
132 * all the reads from the registers. Should only be provided for
133 * devices whos read operation cannot be represented as a simple read
134 * operation on a bus such as SPI, I2C, etc. Most of the devices do
135 * not need this.
136 * @reg_write: Same as above for writing.
137 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
138 * to perform locking. This field is ignored if custom lock/unlock
139 * functions are used (see fields lock/unlock of struct regmap_config).
140 * This field is a duplicate of a similar file in
141 * 'struct regmap_bus' and serves exact same purpose.
142 * Use it only for "no-bus" cases.
79 * @max_register: Optional, specifies the maximum valid register index. 143 * @max_register: Optional, specifies the maximum valid register index.
144 * @wr_table: Optional, points to a struct regmap_access_table specifying
145 * valid ranges for write access.
146 * @rd_table: As above, for read access.
147 * @volatile_table: As above, for volatile registers.
148 * @precious_table: As above, for precious registers.
80 * @reg_defaults: Power on reset values for registers (for use with 149 * @reg_defaults: Power on reset values for registers (for use with
81 * register cache support). 150 * register cache support).
82 * @num_reg_defaults: Number of elements in reg_defaults. 151 * @num_reg_defaults: Number of elements in reg_defaults.
@@ -116,8 +185,20 @@ struct regmap_config {
116 bool (*readable_reg)(struct device *dev, unsigned int reg); 185 bool (*readable_reg)(struct device *dev, unsigned int reg);
117 bool (*volatile_reg)(struct device *dev, unsigned int reg); 186 bool (*volatile_reg)(struct device *dev, unsigned int reg);
118 bool (*precious_reg)(struct device *dev, unsigned int reg); 187 bool (*precious_reg)(struct device *dev, unsigned int reg);
188 regmap_lock lock;
189 regmap_unlock unlock;
190 void *lock_arg;
191
192 int (*reg_read)(void *context, unsigned int reg, unsigned int *val);
193 int (*reg_write)(void *context, unsigned int reg, unsigned int val);
194
195 bool fast_io;
119 196
120 unsigned int max_register; 197 unsigned int max_register;
198 const struct regmap_access_table *wr_table;
199 const struct regmap_access_table *rd_table;
200 const struct regmap_access_table *volatile_table;
201 const struct regmap_access_table *precious_table;
121 const struct reg_default *reg_defaults; 202 const struct reg_default *reg_defaults;
122 unsigned int num_reg_defaults; 203 unsigned int num_reg_defaults;
123 enum regcache_type cache_type; 204 enum regcache_type cache_type;
@@ -133,7 +214,7 @@ struct regmap_config {
133 enum regmap_endian val_format_endian; 214 enum regmap_endian val_format_endian;
134 215
135 const struct regmap_range_cfg *ranges; 216 const struct regmap_range_cfg *ranges;
136 unsigned int n_ranges; 217 unsigned int num_ranges;
137}; 218};
138 219
139/** 220/**
@@ -142,6 +223,8 @@ struct regmap_config {
142 * 1. page selector register update; 223 * 1. page selector register update;
143 * 2. access through data window registers. 224 * 2. access through data window registers.
144 * 225 *
226 * @name: Descriptive name for diagnostics
227 *
145 * @range_min: Address of the lowest register address in virtual range. 228 * @range_min: Address of the lowest register address in virtual range.
146 * @range_max: Address of the highest register in virtual range. 229 * @range_max: Address of the highest register in virtual range.
147 * 230 *
@@ -153,6 +236,8 @@ struct regmap_config {
153 * @window_len: Number of registers in data window. 236 * @window_len: Number of registers in data window.
154 */ 237 */
155struct regmap_range_cfg { 238struct regmap_range_cfg {
239 const char *name;
240
156 /* Registers of virtual address range */ 241 /* Registers of virtual address range */
157 unsigned int range_min; 242 unsigned int range_min;
158 unsigned int range_max; 243 unsigned int range_max;
@@ -167,26 +252,38 @@ struct regmap_range_cfg {
167 unsigned int window_len; 252 unsigned int window_len;
168}; 253};
169 254
255struct regmap_async;
256
170typedef int (*regmap_hw_write)(void *context, const void *data, 257typedef int (*regmap_hw_write)(void *context, const void *data,
171 size_t count); 258 size_t count);
172typedef int (*regmap_hw_gather_write)(void *context, 259typedef int (*regmap_hw_gather_write)(void *context,
173 const void *reg, size_t reg_len, 260 const void *reg, size_t reg_len,
174 const void *val, size_t val_len); 261 const void *val, size_t val_len);
262typedef int (*regmap_hw_async_write)(void *context,
263 const void *reg, size_t reg_len,
264 const void *val, size_t val_len,
265 struct regmap_async *async);
175typedef int (*regmap_hw_read)(void *context, 266typedef int (*regmap_hw_read)(void *context,
176 const void *reg_buf, size_t reg_size, 267 const void *reg_buf, size_t reg_size,
177 void *val_buf, size_t val_size); 268 void *val_buf, size_t val_size);
269typedef struct regmap_async *(*regmap_hw_async_alloc)(void);
178typedef void (*regmap_hw_free_context)(void *context); 270typedef void (*regmap_hw_free_context)(void *context);
179 271
180/** 272/**
181 * Description of a hardware bus for the register map infrastructure. 273 * Description of a hardware bus for the register map infrastructure.
182 * 274 *
183 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex 275 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
184 * to perform locking. 276 * to perform locking. This field is ignored if custom lock/unlock
277 * functions are used (see fields lock/unlock of
278 * struct regmap_config).
185 * @write: Write operation. 279 * @write: Write operation.
186 * @gather_write: Write operation with split register/value, return -ENOTSUPP 280 * @gather_write: Write operation with split register/value, return -ENOTSUPP
187 * if not implemented on a given device. 281 * if not implemented on a given device.
282 * @async_write: Write operation which completes asynchronously, optional and
283 * must serialise with respect to non-async I/O.
188 * @read: Read operation. Data is returned in the buffer used to transmit 284 * @read: Read operation. Data is returned in the buffer used to transmit
189 * data. 285 * data.
286 * @async_alloc: Allocate a regmap_async() structure.
190 * @read_flag_mask: Mask to be set in the top byte of the register when doing 287 * @read_flag_mask: Mask to be set in the top byte of the register when doing
191 * a read. 288 * a read.
192 * @reg_format_endian_default: Default endianness for formatted register 289 * @reg_format_endian_default: Default endianness for formatted register
@@ -195,13 +292,16 @@ typedef void (*regmap_hw_free_context)(void *context);
195 * @val_format_endian_default: Default endianness for formatted register 292 * @val_format_endian_default: Default endianness for formatted register
196 * values. Used when the regmap_config specifies DEFAULT. If this is 293 * values. Used when the regmap_config specifies DEFAULT. If this is
197 * DEFAULT, BIG is assumed. 294 * DEFAULT, BIG is assumed.
295 * @async_size: Size of struct used for async work.
198 */ 296 */
199struct regmap_bus { 297struct regmap_bus {
200 bool fast_io; 298 bool fast_io;
201 regmap_hw_write write; 299 regmap_hw_write write;
202 regmap_hw_gather_write gather_write; 300 regmap_hw_gather_write gather_write;
301 regmap_hw_async_write async_write;
203 regmap_hw_read read; 302 regmap_hw_read read;
204 regmap_hw_free_context free_context; 303 regmap_hw_free_context free_context;
304 regmap_hw_async_alloc async_alloc;
205 u8 read_flag_mask; 305 u8 read_flag_mask;
206 enum regmap_endian reg_format_endian_default; 306 enum regmap_endian reg_format_endian_default;
207 enum regmap_endian val_format_endian_default; 307 enum regmap_endian val_format_endian_default;
@@ -215,9 +315,9 @@ struct regmap *regmap_init_i2c(struct i2c_client *i2c,
215 const struct regmap_config *config); 315 const struct regmap_config *config);
216struct regmap *regmap_init_spi(struct spi_device *dev, 316struct regmap *regmap_init_spi(struct spi_device *dev,
217 const struct regmap_config *config); 317 const struct regmap_config *config);
218struct regmap *regmap_init_mmio(struct device *dev, 318struct regmap *regmap_init_mmio_clk(struct device *dev, const char *clk_id,
219 void __iomem *regs, 319 void __iomem *regs,
220 const struct regmap_config *config); 320 const struct regmap_config *config);
221 321
222struct regmap *devm_regmap_init(struct device *dev, 322struct regmap *devm_regmap_init(struct device *dev,
223 const struct regmap_bus *bus, 323 const struct regmap_bus *bus,
@@ -227,9 +327,44 @@ struct regmap *devm_regmap_init_i2c(struct i2c_client *i2c,
227 const struct regmap_config *config); 327 const struct regmap_config *config);
228struct regmap *devm_regmap_init_spi(struct spi_device *dev, 328struct regmap *devm_regmap_init_spi(struct spi_device *dev,
229 const struct regmap_config *config); 329 const struct regmap_config *config);
230struct regmap *devm_regmap_init_mmio(struct device *dev, 330struct regmap *devm_regmap_init_mmio_clk(struct device *dev, const char *clk_id,
231 void __iomem *regs, 331 void __iomem *regs,
232 const struct regmap_config *config); 332 const struct regmap_config *config);
333
334/**
335 * regmap_init_mmio(): Initialise register map
336 *
337 * @dev: Device that will be interacted with
338 * @regs: Pointer to memory-mapped IO region
339 * @config: Configuration for register map
340 *
341 * The return value will be an ERR_PTR() on error or a valid pointer to
342 * a struct regmap.
343 */
344static inline struct regmap *regmap_init_mmio(struct device *dev,
345 void __iomem *regs,
346 const struct regmap_config *config)
347{
348 return regmap_init_mmio_clk(dev, NULL, regs, config);
349}
350
351/**
352 * devm_regmap_init_mmio(): Initialise managed register map
353 *
354 * @dev: Device that will be interacted with
355 * @regs: Pointer to memory-mapped IO region
356 * @config: Configuration for register map
357 *
358 * The return value will be an ERR_PTR() on error or a valid pointer
359 * to a struct regmap. The regmap will be automatically freed by the
360 * device management code.
361 */
362static inline struct regmap *devm_regmap_init_mmio(struct device *dev,
363 void __iomem *regs,
364 const struct regmap_config *config)
365{
366 return devm_regmap_init_mmio_clk(dev, NULL, regs, config);
367}
233 368
234void regmap_exit(struct regmap *map); 369void regmap_exit(struct regmap *map);
235int regmap_reinit_cache(struct regmap *map, 370int regmap_reinit_cache(struct regmap *map,
@@ -240,6 +375,8 @@ int regmap_raw_write(struct regmap *map, unsigned int reg,
240 const void *val, size_t val_len); 375 const void *val, size_t val_len);
241int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val, 376int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
242 size_t val_count); 377 size_t val_count);
378int regmap_raw_write_async(struct regmap *map, unsigned int reg,
379 const void *val, size_t val_len);
243int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val); 380int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
244int regmap_raw_read(struct regmap *map, unsigned int reg, 381int regmap_raw_read(struct regmap *map, unsigned int reg,
245 void *val, size_t val_len); 382 void *val, size_t val_len);
@@ -251,6 +388,7 @@ int regmap_update_bits_check(struct regmap *map, unsigned int reg,
251 unsigned int mask, unsigned int val, 388 unsigned int mask, unsigned int val,
252 bool *change); 389 bool *change);
253int regmap_get_val_bytes(struct regmap *map); 390int regmap_get_val_bytes(struct regmap *map);
391int regmap_async_complete(struct regmap *map);
254 392
255int regcache_sync(struct regmap *map); 393int regcache_sync(struct regmap *map);
256int regcache_sync_region(struct regmap *map, unsigned int min, 394int regcache_sync_region(struct regmap *map, unsigned int min,
@@ -262,6 +400,16 @@ void regcache_mark_dirty(struct regmap *map);
262int regmap_register_patch(struct regmap *map, const struct reg_default *regs, 400int regmap_register_patch(struct regmap *map, const struct reg_default *regs,
263 int num_regs); 401 int num_regs);
264 402
403static inline bool regmap_reg_in_range(unsigned int reg,
404 const struct regmap_range *range)
405{
406 return reg >= range->range_min && reg <= range->range_max;
407}
408
409bool regmap_reg_in_ranges(unsigned int reg,
410 const struct regmap_range *ranges,
411 unsigned int nranges);
412
265/** 413/**
266 * Description of an IRQ for the generic regmap irq_chip. 414 * Description of an IRQ for the generic regmap irq_chip.
267 * 415 *
@@ -301,6 +449,7 @@ struct regmap_irq_chip {
301 unsigned int wake_base; 449 unsigned int wake_base;
302 unsigned int irq_reg_stride; 450 unsigned int irq_reg_stride;
303 unsigned int mask_invert; 451 unsigned int mask_invert;
452 unsigned int wake_invert;
304 bool runtime_pm; 453 bool runtime_pm;
305 454
306 int num_regs; 455 int num_regs;
@@ -317,6 +466,7 @@ int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
317void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data); 466void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data);
318int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data); 467int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data);
319int regmap_irq_get_virq(struct regmap_irq_chip_data *data, int irq); 468int regmap_irq_get_virq(struct regmap_irq_chip_data *data, int irq);
469struct irq_domain *regmap_irq_get_domain(struct regmap_irq_chip_data *data);
320 470
321#else 471#else
322 472
@@ -341,6 +491,13 @@ static inline int regmap_raw_write(struct regmap *map, unsigned int reg,
341 return -EINVAL; 491 return -EINVAL;
342} 492}
343 493
494static inline int regmap_raw_write_async(struct regmap *map, unsigned int reg,
495 const void *val, size_t val_len)
496{
497 WARN_ONCE(1, "regmap API is disabled");
498 return -EINVAL;
499}
500
344static inline int regmap_bulk_write(struct regmap *map, unsigned int reg, 501static inline int regmap_bulk_write(struct regmap *map, unsigned int reg,
345 const void *val, size_t val_count) 502 const void *val, size_t val_count)
346{ 503{
@@ -419,6 +576,11 @@ static inline void regcache_mark_dirty(struct regmap *map)
419 WARN_ONCE(1, "regmap API is disabled"); 576 WARN_ONCE(1, "regmap API is disabled");
420} 577}
421 578
579static inline void regmap_async_complete(struct regmap *map)
580{
581 WARN_ONCE(1, "regmap API is disabled");
582}
583
422static inline int regmap_register_patch(struct regmap *map, 584static inline int regmap_register_patch(struct regmap *map,
423 const struct reg_default *regs, 585 const struct reg_default *regs,
424 int num_regs) 586 int num_regs)