Skip to content

Commit 86fc59e

Browse files
colin-foster-in-advantagebroonie
authored andcommitted
regmap: add configurable downshift for addresses
Add an additional reg_downshift to be applied to register addresses before any register accesses. An example of a device that uses this is a VSC7514 chip, which require each register address to be downshifted by two if the access is performed over a SPI bus. Signed-off-by: Colin Foster <colin.foster@in-advantage.com> Link: https://lore.kernel.org/r/20220313224524.399947-2-colin.foster@in-advantage.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 2d23297 commit 86fc59e

3 files changed

Lines changed: 9 additions & 0 deletions

File tree

drivers/base/regmap/internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct regmap_format {
3131
size_t buf_size;
3232
size_t reg_bytes;
3333
size_t pad_bytes;
34+
size_t reg_downshift;
3435
size_t val_bytes;
3536
void (*format_write)(struct regmap *map,
3637
unsigned int reg, unsigned int val);

drivers/base/regmap/regmap.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,7 @@ struct regmap *__regmap_init(struct device *dev,
823823

824824
map->format.reg_bytes = DIV_ROUND_UP(config->reg_bits, 8);
825825
map->format.pad_bytes = config->pad_bits / 8;
826+
map->format.reg_downshift = config->reg_downshift;
826827
map->format.val_bytes = DIV_ROUND_UP(config->val_bits, 8);
827828
map->format.buf_size = DIV_ROUND_UP(config->reg_bits +
828829
config->val_bits + config->pad_bits, 8);
@@ -1735,6 +1736,7 @@ static int _regmap_raw_write_impl(struct regmap *map, unsigned int reg,
17351736
return ret;
17361737
}
17371738

1739+
reg >>= map->format.reg_downshift;
17381740
map->format.format_reg(map->work_buf, reg, map->reg_shift);
17391741
regmap_set_work_buf_flag_mask(map, map->format.reg_bytes,
17401742
map->write_flag_mask);
@@ -1905,6 +1907,7 @@ static int _regmap_bus_formatted_write(void *context, unsigned int reg,
19051907
return ret;
19061908
}
19071909

1910+
reg >>= map->format.reg_downshift;
19081911
map->format.format_write(map, reg, val);
19091912

19101913
trace_regmap_hw_write_start(map, reg, 1);
@@ -2346,6 +2349,7 @@ static int _regmap_raw_multi_reg_write(struct regmap *map,
23462349
unsigned int reg = regs[i].reg;
23472350
unsigned int val = regs[i].def;
23482351
trace_regmap_hw_write_start(map, reg, 1);
2352+
reg >>= map->format.reg_downshift;
23492353
map->format.format_reg(u8, reg, map->reg_shift);
23502354
u8 += reg_bytes + pad_bytes;
23512355
map->format.format_val(u8, val, 0);
@@ -2673,6 +2677,7 @@ static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
26732677
return ret;
26742678
}
26752679

2680+
reg >>= map->format.reg_downshift;
26762681
map->format.format_reg(map->work_buf, reg, map->reg_shift);
26772682
regmap_set_work_buf_flag_mask(map, map->format.reg_bytes,
26782683
map->read_flag_mask);

include/linux/regmap.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ typedef void (*regmap_unlock)(void *);
237237
* @reg_stride: The register address stride. Valid register addresses are a
238238
* multiple of this value. If set to 0, a value of 1 will be
239239
* used.
240+
* @reg_downshift: The number of bits to downshift the register before
241+
* performing any operations.
240242
* @pad_bits: Number of bits of padding between register and value.
241243
* @val_bits: Number of bits in a register value, mandatory.
242244
*
@@ -360,6 +362,7 @@ struct regmap_config {
360362

361363
int reg_bits;
362364
int reg_stride;
365+
int reg_downshift;
363366
int pad_bits;
364367
int val_bits;
365368

0 commit comments

Comments
 (0)