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
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.
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.
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>
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(+)
24 --- a/drivers/base/regmap/internal.h
25 +++ b/drivers/base/regmap/internal.h
26 @@ -63,6 +63,7 @@ struct regmap {
28 void *lock_arg; /* This is passed to lock/unlock functions */
30 + unsigned int reg_base;
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
38 map->alloc_flags = GFP_KERNEL;
40 + map->reg_base = config->reg_base;
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 @@ -1738,6 +1740,7 @@ static int _regmap_raw_write_impl(struct
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 @@ -1909,6 +1912,7 @@ static int _regmap_bus_formatted_write(v
57 + reg += map->reg_base;
58 reg >>= map->format.reg_downshift;
59 map->format.format_write(map, reg, val);
61 @@ -2351,6 +2355,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 @@ -2679,6 +2684,7 @@ static int _regmap_raw_read(struct regma
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 *);
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
85 * @pad_bits: Number of bits of padding between register and value.
86 * @val_bits: Number of bits in a register value, mandatory.
88 @@ -363,6 +365,7 @@ struct regmap_config {
92 + unsigned int reg_base;