df716c4b651c263d2c87c9140523ec4ad6a4a907
[openwrt/staging/xback.git] /
1 From 0074f3f2b1e43d3cedd97e47fb6980db6d2ba79e Mon Sep 17 00:00:00 2001
2 From: Colin Foster <colin.foster@in-advantage.com>
3 Date: Sun, 13 Mar 2022 15:45:24 -0700
4 Subject: [PATCH 2/2] regmap: allow a defined reg_base to be added to every
5 address
6
7 There's an inconsistency that arises when a register set can be accessed
8 internally via MMIO, or externally via SPI. The VSC7514 chip allows both
9 modes of operation. When internally accessed, the system utilizes __iomem,
10 devm_ioremap_resource, and devm_regmap_init_mmio.
11
12 For SPI it isn't possible to utilize memory-mapped IO. To properly operate,
13 the resource base must be added to the register before every operation.
14
15 Signed-off-by: Colin Foster <colin.foster@in-advantage.com>
16 Link: https://lore.kernel.org/r/20220313224524.399947-3-colin.foster@in-advantage.com
17 Signed-off-by: Mark Brown <broonie@kernel.org>
18 ---
19 drivers/base/regmap/internal.h | 1 +
20 drivers/base/regmap/regmap.c | 6 ++++++
21 include/linux/regmap.h | 3 +++
22 3 files changed, 10 insertions(+)
23
24 --- a/drivers/base/regmap/internal.h
25 +++ b/drivers/base/regmap/internal.h
26 @@ -63,6 +63,7 @@ struct regmap {
27 regmap_unlock unlock;
28 void *lock_arg; /* This is passed to lock/unlock functions */
29 gfp_t alloc_flags;
30 + unsigned int reg_base;
31
32 struct device *dev; /* Device we do I/O on */
33 void *work_buf; /* Scratch buffer used to format I/O */
34 --- a/drivers/base/regmap/regmap.c
35 +++ b/drivers/base/regmap/regmap.c
36 @@ -821,6 +821,8 @@ struct regmap *__regmap_init(struct devi
37 else
38 map->alloc_flags = GFP_KERNEL;
39
40 + map->reg_base = config->reg_base;
41 +
42 map->format.reg_bytes = DIV_ROUND_UP(config->reg_bits, 8);
43 map->format.pad_bytes = config->pad_bits / 8;
44 map->format.reg_downshift = config->reg_downshift;
45 @@ -1751,6 +1753,7 @@ static int _regmap_raw_write_impl(struct
46 return ret;
47 }
48
49 + reg += map->reg_base;
50 reg >>= map->format.reg_downshift;
51 map->format.format_reg(map->work_buf, reg, map->reg_shift);
52 regmap_set_work_buf_flag_mask(map, map->format.reg_bytes,
53 @@ -1922,6 +1925,7 @@ static int _regmap_bus_formatted_write(v
54 return ret;
55 }
56
57 + reg += map->reg_base;
58 reg >>= map->format.reg_downshift;
59 map->format.format_write(map, reg, val);
60
61 @@ -2363,6 +2367,7 @@ static int _regmap_raw_multi_reg_write(s
62 unsigned int reg = regs[i].reg;
63 unsigned int val = regs[i].def;
64 trace_regmap_hw_write_start(map, reg, 1);
65 + reg += map->reg_base;
66 reg >>= map->format.reg_downshift;
67 map->format.format_reg(u8, reg, map->reg_shift);
68 u8 += reg_bytes + pad_bytes;
69 @@ -2689,6 +2694,7 @@ static int _regmap_raw_read(struct regma
70 return ret;
71 }
72
73 + reg += map->reg_base;
74 reg >>= map->format.reg_downshift;
75 map->format.format_reg(map->work_buf, reg, map->reg_shift);
76 regmap_set_work_buf_flag_mask(map, map->format.reg_bytes,
77 --- a/include/linux/regmap.h
78 +++ b/include/linux/regmap.h
79 @@ -239,6 +239,8 @@ typedef void (*regmap_unlock)(void *);
80 * used.
81 * @reg_downshift: The number of bits to downshift the register before
82 * performing any operations.
83 + * @reg_base: Value to be added to every register address before performing any
84 + * operation.
85 * @pad_bits: Number of bits of padding between register and value.
86 * @val_bits: Number of bits in a register value, mandatory.
87 *
88 @@ -369,6 +371,7 @@ struct regmap_config {
89 int reg_bits;
90 int reg_stride;
91 int reg_downshift;
92 + unsigned int reg_base;
93 int pad_bits;
94 int val_bits;
95