generic: 6.1: move stmmac backport fix patches to generic
[openwrt/openwrt.git] / target / linux / generic / backport-6.1 / 831-v6.7-rtc-rtc7301-Support-byte-addressed-IO.patch
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
5
6 The old RTC7301 driver in OpenWrt used byte access, but the
7 current mainline Linux driver uses 32bit word access.
8
9 Make this configurable using device properties using the
10 standard property "reg-io-width" in e.g. device tree.
11
12 This is needed for the USRobotics USR8200 which has the
13 chip connected using byte accesses.
14
15 Debugging and testing by Howard Harte.
16
17 Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
18 ---
19 drivers/rtc/rtc-r7301.c | 35 +++++++++++++++++++++++++++++++++--
20 1 file changed, 33 insertions(+), 2 deletions(-)
21
22 --- a/drivers/rtc/rtc-r7301.c
23 +++ b/drivers/rtc/rtc-r7301.c
24 @@ -14,6 +14,7 @@
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 {
33 u8 bank;
34 };
35
36 -static const struct regmap_config rtc7301_regmap_config = {
37 +/*
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.
41 + */
42 +static const struct regmap_config rtc7301_regmap_32_config = {
43 .reg_bits = 32,
44 .val_bits = 8,
45 .reg_stride = 4,
46 };
47
48 +static const struct regmap_config rtc7301_regmap_8_config = {
49 + .reg_bits = 8,
50 + .val_bits = 8,
51 + .reg_stride = 1,
52 +};
53 +
54 static u8 rtc7301_read(struct rtc7301_priv *priv, unsigned int reg)
55 {
56 int reg_stride = regmap_get_reg_stride(priv->regmap);
57 @@ -356,7 +368,9 @@ static int __init rtc7301_rtc_probe(stru
58 void __iomem *regs;
59 struct rtc7301_priv *priv;
60 struct rtc_device *rtc;
61 + static const struct regmap_config *mapconf;
62 int ret;
63 + u32 val;
64
65 priv = devm_kzalloc(&dev->dev, sizeof(*priv), GFP_KERNEL);
66 if (!priv)
67 @@ -366,8 +380,25 @@ static int __init rtc7301_rtc_probe(stru
68 if (IS_ERR(regs))
69 return PTR_ERR(regs);
70
71 + ret = device_property_read_u32(&dev->dev, "reg-io-width", &val);
72 + if (ret)
73 + /* Default to 32bit accesses */
74 + val = 4;
75 +
76 + switch (val) {
77 + case 1:
78 + mapconf = &rtc7301_regmap_8_config;
79 + break;
80 + case 4:
81 + mapconf = &rtc7301_regmap_32_config;
82 + break;
83 + default:
84 + dev_err(&dev->dev, "invalid reg-io-width %d\n", val);
85 + return -EINVAL;
86 + }
87 +
88 priv->regmap = devm_regmap_init_mmio(&dev->dev, regs,
89 - &rtc7301_regmap_config);
90 + mapconf);
91 if (IS_ERR(priv->regmap))
92 return PTR_ERR(priv->regmap);
93