aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorSrinivas Kandagatla <srinivas.kandagatla@st.com>2013-06-11 08:18:15 -0400
committerMark Brown <broonie@linaro.org>2013-06-12 11:27:44 -0400
commit67252287871113deba96adf7e4df1752f3f08688 (patch)
tree8fd124b776d577d4d8dd0fa48b6c1a2df3be7ca3 /include
parent317ddd256b9c24b0d78fa8018f80f1e495481a10 (diff)
regmap: Add regmap_field APIs
It is common to access regmap registers at bit level, using regmap_update_bits or regmap_read functions, however the end user has to take care of a mask or shifting. This becomes overhead when such use cases are high. Having a common function to do this is much convenient and less error prone. The idea of regmap_field is simple, regmap_field gives a logical structure to bits of the regmap register, and the driver can use this logical entity without the knowledge of the bit positions and masks all over the code. This way code looks much neat and it need not handle the masks, shifts every time it access the those entities. With this new regmap_field_read/write apis the end user can setup a regmap field using regmap_field_init and use the return regmap_field to read write the register field without worrying about the masks or shifts. Also this apis will be useful for drivers which are based on regmaps, like some clocks or pinctrls which can work on the regmap_fields directly without having to worry about bit positions. Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@st.com> Signed-off-by: Mark Brown <broonie@linaro.org>
Diffstat (limited to 'include')
-rw-r--r--include/linux/regmap.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index 02d84e24b7c2..eebea9b5f43e 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -23,6 +23,7 @@ struct irq_domain;
23struct spi_device; 23struct spi_device;
24struct regmap; 24struct regmap;
25struct regmap_range_cfg; 25struct regmap_range_cfg;
26struct regmap_field;
26 27
27/* An enum of all the supported cache types */ 28/* An enum of all the supported cache types */
28enum regcache_type { 29enum regcache_type {
@@ -412,6 +413,36 @@ bool regmap_reg_in_ranges(unsigned int reg,
412 unsigned int nranges); 413 unsigned int nranges);
413 414
414/** 415/**
416 * Description of an register field
417 *
418 * @reg: Offset of the register within the regmap bank
419 * @lsb: lsb of the register field.
420 * @reg: msb of the register field.
421 */
422struct reg_field {
423 unsigned int reg;
424 unsigned int lsb;
425 unsigned int msb;
426};
427
428#define REG_FIELD(_reg, _lsb, _msb) { \
429 .reg = _reg, \
430 .lsb = _lsb, \
431 .msb = _msb, \
432 }
433
434struct regmap_field *regmap_field_alloc(struct regmap *regmap,
435 struct reg_field reg_field);
436void regmap_field_free(struct regmap_field *field);
437
438struct regmap_field *devm_regmap_field_alloc(struct device *dev,
439 struct regmap *regmap, struct reg_field reg_field);
440void devm_regmap_field_free(struct device *dev, struct regmap_field *field);
441
442int regmap_field_read(struct regmap_field *field, unsigned int *val);
443int regmap_field_write(struct regmap_field *field, unsigned int val);
444
445/**
415 * Description of an IRQ for the generic regmap irq_chip. 446 * Description of an IRQ for the generic regmap irq_chip.
416 * 447 *
417 * @reg_offset: Offset of the status/mask register within the bank 448 * @reg_offset: Offset of the status/mask register within the bank