aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/regmap/regmap.c
diff options
context:
space:
mode:
authorMarc Reilly <marc@cpdesign.com.au>2012-03-15 21:11:43 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-04-01 06:55:20 -0400
commitd939fb9a78b4743bc4bc3cc415894ed42050c5cc (patch)
tree74980bd7c634676da11abb41f87447b50d3a4163 /drivers/base/regmap/regmap.c
parentea279fc5619e2541a0c28196b0fa06447d9ad026 (diff)
regmap: Use pad_bits and reg_bits when determining register format.
This change combines any padding bits into the register address bits when determining register format handlers to use the next byte-divisible register size. A reg_shift member is introduced to the regmap struct to enable fixup of the reg format. Format handlers now take an extra parameter specifying the number of bits to shift the value by. Signed-off-by: Marc Reilly <marc@cpdesign.com.au> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/base/regmap/regmap.c')
-rw-r--r--drivers/base/regmap/regmap.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 8ffce9bdb481..178989a8949e 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -112,34 +112,36 @@ static void regmap_format_10_14_write(struct regmap *map,
112 out[0] = reg >> 2; 112 out[0] = reg >> 2;
113} 113}
114 114
115static void regmap_format_8(void *buf, unsigned int val) 115static void regmap_format_8(void *buf, unsigned int val, unsigned int shift)
116{ 116{
117 u8 *b = buf; 117 u8 *b = buf;
118 118
119 b[0] = val; 119 b[0] = val << shift;
120} 120}
121 121
122static void regmap_format_16(void *buf, unsigned int val) 122static void regmap_format_16(void *buf, unsigned int val, unsigned int shift)
123{ 123{
124 __be16 *b = buf; 124 __be16 *b = buf;
125 125
126 b[0] = cpu_to_be16(val); 126 b[0] = cpu_to_be16(val << shift);
127} 127}
128 128
129static void regmap_format_24(void *buf, unsigned int val) 129static void regmap_format_24(void *buf, unsigned int val, unsigned int shift)
130{ 130{
131 u8 *b = buf; 131 u8 *b = buf;
132 132
133 val <<= shift;
134
133 b[0] = val >> 16; 135 b[0] = val >> 16;
134 b[1] = val >> 8; 136 b[1] = val >> 8;
135 b[2] = val; 137 b[2] = val;
136} 138}
137 139
138static void regmap_format_32(void *buf, unsigned int val) 140static void regmap_format_32(void *buf, unsigned int val, unsigned int shift)
139{ 141{
140 __be32 *b = buf; 142 __be32 *b = buf;
141 143
142 b[0] = cpu_to_be32(val); 144 b[0] = cpu_to_be32(val << shift);
143} 145}
144 146
145static unsigned int regmap_parse_8(void *buf) 147static unsigned int regmap_parse_8(void *buf)
@@ -210,6 +212,7 @@ struct regmap *regmap_init(struct device *dev,
210 map->format.pad_bytes = config->pad_bits / 8; 212 map->format.pad_bytes = config->pad_bits / 8;
211 map->format.val_bytes = DIV_ROUND_UP(config->val_bits, 8); 213 map->format.val_bytes = DIV_ROUND_UP(config->val_bits, 8);
212 map->format.buf_size += map->format.pad_bytes; 214 map->format.buf_size += map->format.pad_bytes;
215 map->reg_shift = config->pad_bits % 8;
213 map->dev = dev; 216 map->dev = dev;
214 map->bus = bus; 217 map->bus = bus;
215 map->max_register = config->max_register; 218 map->max_register = config->max_register;
@@ -226,7 +229,7 @@ struct regmap *regmap_init(struct device *dev,
226 map->read_flag_mask = bus->read_flag_mask; 229 map->read_flag_mask = bus->read_flag_mask;
227 } 230 }
228 231
229 switch (config->reg_bits) { 232 switch (config->reg_bits + map->reg_shift) {
230 case 2: 233 case 2:
231 switch (config->val_bits) { 234 switch (config->val_bits) {
232 case 6: 235 case 6:
@@ -454,7 +457,7 @@ static int _regmap_raw_write(struct regmap *map, unsigned int reg,
454 } 457 }
455 } 458 }
456 459
457 map->format.format_reg(map->work_buf, reg); 460 map->format.format_reg(map->work_buf, reg, map->reg_shift);
458 461
459 u8[0] |= map->write_flag_mask; 462 u8[0] |= map->write_flag_mask;
460 463
@@ -529,7 +532,7 @@ int _regmap_write(struct regmap *map, unsigned int reg,
529 return ret; 532 return ret;
530 } else { 533 } else {
531 map->format.format_val(map->work_buf + map->format.reg_bytes 534 map->format.format_val(map->work_buf + map->format.reg_bytes
532 + map->format.pad_bytes, val); 535 + map->format.pad_bytes, val, 0);
533 return _regmap_raw_write(map, reg, 536 return _regmap_raw_write(map, reg,
534 map->work_buf + 537 map->work_buf +
535 map->format.reg_bytes + 538 map->format.reg_bytes +
@@ -649,7 +652,7 @@ static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
649 u8 *u8 = map->work_buf; 652 u8 *u8 = map->work_buf;
650 int ret; 653 int ret;
651 654
652 map->format.format_reg(map->work_buf, reg); 655 map->format.format_reg(map->work_buf, reg, map->reg_shift);
653 656
654 /* 657 /*
655 * Some buses or devices flag reads by setting the high bits in the 658 * Some buses or devices flag reads by setting the high bits in the
@@ -757,7 +760,7 @@ int regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
757 if (ret != 0) 760 if (ret != 0)
758 goto out; 761 goto out;
759 762
760 map->format.format_val(val + (i * val_bytes), v); 763 map->format.format_val(val + (i * val_bytes), v, 0);
761 } 764 }
762 } 765 }
763 766