Skip to content

Commit 3f58f6d

Browse files
minimaxwellbroonie
authored andcommitted
regmap: add a helper to translate the register address
Register addresses passed to regmap operations can be offset with regmap.reg_base and downshifted with regmap.reg_downshift. Add a helper to apply both these operations and return the translated address, that we can then use to perform the actual register operation ont the underlying bus. Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com> Link: https://lore.kernel.org/r/20230324093644.464704-2-maxime.chevallier@bootlin.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent e8d018d commit 3f58f6d

1 file changed

Lines changed: 13 additions & 14 deletions

File tree

drivers/base/regmap/regmap.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,6 +1676,12 @@ static void regmap_set_work_buf_flag_mask(struct regmap *map, int max_bytes,
16761676
buf[i] |= (mask >> (8 * i)) & 0xff;
16771677
}
16781678

1679+
static unsigned int regmap_reg_addr(struct regmap *map, unsigned int reg)
1680+
{
1681+
reg += map->reg_base;
1682+
return reg >> map->format.reg_downshift;
1683+
}
1684+
16791685
static int _regmap_raw_write_impl(struct regmap *map, unsigned int reg,
16801686
const void *val, size_t val_len, bool noinc)
16811687
{
@@ -1753,8 +1759,7 @@ static int _regmap_raw_write_impl(struct regmap *map, unsigned int reg,
17531759
return ret;
17541760
}
17551761

1756-
reg += map->reg_base;
1757-
reg >>= map->format.reg_downshift;
1762+
reg = regmap_reg_addr(map, reg);
17581763
map->format.format_reg(map->work_buf, reg, map->reg_shift);
17591764
regmap_set_work_buf_flag_mask(map, map->format.reg_bytes,
17601765
map->write_flag_mask);
@@ -1924,8 +1929,7 @@ static int _regmap_bus_formatted_write(void *context, unsigned int reg,
19241929
return ret;
19251930
}
19261931

1927-
reg += map->reg_base;
1928-
reg >>= map->format.reg_downshift;
1932+
reg = regmap_reg_addr(map, reg);
19291933
map->format.format_write(map, reg, val);
19301934

19311935
trace_regmap_hw_write_start(map, reg, 1);
@@ -1942,8 +1946,7 @@ static int _regmap_bus_reg_write(void *context, unsigned int reg,
19421946
{
19431947
struct regmap *map = context;
19441948

1945-
reg += map->reg_base;
1946-
reg >>= map->format.reg_downshift;
1949+
reg = regmap_reg_addr(map, reg);
19471950
return map->bus->reg_write(map->bus_context, reg, val);
19481951
}
19491952

@@ -2494,8 +2497,7 @@ static int _regmap_raw_multi_reg_write(struct regmap *map,
24942497
unsigned int reg = regs[i].reg;
24952498
unsigned int val = regs[i].def;
24962499
trace_regmap_hw_write_start(map, reg, 1);
2497-
reg += map->reg_base;
2498-
reg >>= map->format.reg_downshift;
2500+
reg = regmap_reg_addr(map, reg);
24992501
map->format.format_reg(u8, reg, map->reg_shift);
25002502
u8 += reg_bytes + pad_bytes;
25012503
map->format.format_val(u8, val, 0);
@@ -2821,8 +2823,7 @@ static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
28212823
return ret;
28222824
}
28232825

2824-
reg += map->reg_base;
2825-
reg >>= map->format.reg_downshift;
2826+
reg = regmap_reg_addr(map, reg);
28262827
map->format.format_reg(map->work_buf, reg, map->reg_shift);
28272828
regmap_set_work_buf_flag_mask(map, map->format.reg_bytes,
28282829
map->read_flag_mask);
@@ -2842,8 +2843,7 @@ static int _regmap_bus_reg_read(void *context, unsigned int reg,
28422843
{
28432844
struct regmap *map = context;
28442845

2845-
reg += map->reg_base;
2846-
reg >>= map->format.reg_downshift;
2846+
reg = regmap_reg_addr(map, reg);
28472847
return map->bus->reg_read(map->bus_context, reg, val);
28482848
}
28492849

@@ -3235,8 +3235,7 @@ static int _regmap_update_bits(struct regmap *map, unsigned int reg,
32353235
*change = false;
32363236

32373237
if (regmap_volatile(map, reg) && map->reg_update_bits) {
3238-
reg += map->reg_base;
3239-
reg >>= map->format.reg_downshift;
3238+
reg = regmap_reg_addr(map, reg);
32403239
ret = map->reg_update_bits(map->bus_context, reg, mask, val);
32413240
if (ret == 0 && change)
32423241
*change = true;

0 commit comments

Comments
 (0)