1 From edd25a77e69b7c546c28077e5dffe72c54c0afe8 Mon Sep 17 00:00:00 2001
2 From: Linus Walleij <linus.walleij@linaro.org>
3 Date: Thu, 21 Sep 2023 22:18:12 +0200
4 Subject: [PATCH 2/4] rtc: rtc7301: Support byte-addressed IO
6 The old RTC7301 driver in OpenWrt used byte access, but the
7 current mainline Linux driver uses 32bit word access.
9 Make this configurable using device properties using the
10 standard property "reg-io-width" in e.g. device tree.
12 This is needed for the USRobotics USR8200 which has the
13 chip connected using byte accesses.
15 Debugging and testing by Howard Harte.
17 Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
19 drivers/rtc/rtc-r7301.c | 35 +++++++++++++++++++++++++++++++++--
20 1 file changed, 33 insertions(+), 2 deletions(-)
22 --- a/drivers/rtc/rtc-r7301.c
23 +++ b/drivers/rtc/rtc-r7301.c
25 #include <linux/module.h>
26 #include <linux/mod_devicetable.h>
27 #include <linux/delay.h>
28 +#include <linux/property.h>
29 #include <linux/regmap.h>
30 #include <linux/platform_device.h>
31 #include <linux/rtc.h>
32 @@ -55,12 +56,23 @@ struct rtc7301_priv {
36 -static const struct regmap_config rtc7301_regmap_config = {
38 + * When the device is memory-mapped, some platforms pack the registers into
39 + * 32-bit access using the lower 8 bits at each 4-byte stride, while others
40 + * expose them as simply consecutive bytes.
42 +static const struct regmap_config rtc7301_regmap_32_config = {
48 +static const struct regmap_config rtc7301_regmap_8_config = {
54 static u8 rtc7301_read(struct rtc7301_priv *priv, unsigned int reg)
56 int reg_stride = regmap_get_reg_stride(priv->regmap);
57 @@ -356,7 +368,9 @@ static int __init rtc7301_rtc_probe(stru
59 struct rtc7301_priv *priv;
60 struct rtc_device *rtc;
61 + static const struct regmap_config *mapconf;
65 priv = devm_kzalloc(&dev->dev, sizeof(*priv), GFP_KERNEL);
67 @@ -366,8 +380,25 @@ static int __init rtc7301_rtc_probe(stru
71 + ret = device_property_read_u32(&dev->dev, "reg-io-width", &val);
73 + /* Default to 32bit accesses */
78 + mapconf = &rtc7301_regmap_8_config;
81 + mapconf = &rtc7301_regmap_32_config;
84 + dev_err(&dev->dev, "invalid reg-io-width %d\n", val);
88 priv->regmap = devm_regmap_init_mmio(&dev->dev, regs,
89 - &rtc7301_regmap_config);
91 if (IS_ERR(priv->regmap))
92 return PTR_ERR(priv->regmap);