bc3865c75b92afff02d9c299f46b371eb9f2ef4a
[openwrt/staging/ldir.git] /
1 From 697c3892d825fb78f42ec8e53bed065dd728db3e Mon Sep 17 00:00:00 2001
2 From: Daniel Golle <daniel@makrotopia.org>
3 Date: Mon, 30 Jan 2023 02:04:57 +0000
4 Subject: [PATCH] regmap: apply reg_base and reg_downshift for single register
5 ops
6
7 reg_base and reg_downshift currently don't have any effect if used with
8 a regmap_bus or regmap_config which only offers single register
9 operations (ie. reg_read, reg_write and optionally reg_update_bits).
10
11 Fix that and take them into account also for regmap_bus with only
12 reg_read and read_write operations by applying reg_base and
13 reg_downshift in _regmap_bus_reg_write, _regmap_bus_reg_read.
14
15 Also apply reg_base and reg_downshift in _regmap_update_bits, but only
16 in case the operation is carried out with a reg_update_bits call
17 defined in either regmap_bus or regmap_config.
18
19 Fixes: 0074f3f2b1e43d ("regmap: allow a defined reg_base to be added to every address")
20 Fixes: 86fc59ef818beb ("regmap: add configurable downshift for addresses")
21 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
22 Tested-by: Colin Foster <colin.foster@in-advantage.com>
23 Link: https://lore.kernel.org/r/Y9clyVS3tQEHlUhA@makrotopia.org
24 Signed-off-by: Mark Brown <broonie@kernel.org>
25 ---
26 drivers/base/regmap/regmap.c | 6 ++++++
27 1 file changed, 6 insertions(+)
28
29 --- a/drivers/base/regmap/regmap.c
30 +++ b/drivers/base/regmap/regmap.c
31 @@ -1931,6 +1931,8 @@ static int _regmap_bus_reg_write(void *c
32 {
33 struct regmap *map = context;
34
35 + reg += map->reg_base;
36 + reg >>= map->format.reg_downshift;
37 return map->bus->reg_write(map->bus_context, reg, val);
38 }
39
40 @@ -2705,6 +2707,8 @@ static int _regmap_bus_reg_read(void *co
41 {
42 struct regmap *map = context;
43
44 + reg += map->reg_base;
45 + reg >>= map->format.reg_downshift;
46 return map->bus->reg_read(map->bus_context, reg, val);
47 }
48
49 @@ -3080,6 +3084,8 @@ static int _regmap_update_bits(struct re
50 *change = false;
51
52 if (regmap_volatile(map, reg) && map->reg_update_bits) {
53 + reg += map->reg_base;
54 + reg >>= map->format.reg_downshift;
55 ret = map->reg_update_bits(map->bus_context, reg, mask, val);
56 if (ret == 0 && change)
57 *change = true;