Skip to content

Commit 6d53214

Browse files
pcercueiWim Van Sebroeck
authored andcommitted
watchdog: jz4740: Use regmap provided by TCU driver
Since we broke the ABI by changing the clock, the driver was also updated to use the regmap provided by the TCU driver. Signed-off-by: Paul Cercueil <[email protected]> Tested-by: Mathieu Malaterre <[email protected]> Tested-by: Artur Rojek <[email protected]> Acked-by: Guenter Roeck <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Guenter Roeck <[email protected]> Signed-off-by: Wim Van Sebroeck <[email protected]>
1 parent 1d9c307 commit 6d53214

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

drivers/watchdog/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,6 +1645,7 @@ config JZ4740_WDT
16451645
depends on MACH_JZ4740 || MACH_JZ4780
16461646
depends on COMMON_CLK
16471647
select WATCHDOG_CORE
1648+
select MFD_SYSCON
16481649
help
16491650
Hardware driver for the built-in watchdog timer on Ingenic jz4740 SoCs.
16501651

drivers/watchdog/jz4740_wdt.c

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
#include <linux/mfd/ingenic-tcu.h>
8+
#include <linux/mfd/syscon.h>
89
#include <linux/module.h>
910
#include <linux/moduleparam.h>
1011
#include <linux/types.h>
@@ -17,6 +18,7 @@
1718
#include <linux/slab.h>
1819
#include <linux/err.h>
1920
#include <linux/of.h>
21+
#include <linux/regmap.h>
2022

2123
#define DEFAULT_HEARTBEAT 5
2224
#define MAX_HEARTBEAT 2048
@@ -36,7 +38,7 @@ MODULE_PARM_DESC(heartbeat,
3638

3739
struct jz4740_wdt_drvdata {
3840
struct watchdog_device wdt;
39-
void __iomem *base;
41+
struct regmap *map;
4042
struct clk *clk;
4143
unsigned long clk_rate;
4244
};
@@ -45,7 +47,8 @@ static int jz4740_wdt_ping(struct watchdog_device *wdt_dev)
4547
{
4648
struct jz4740_wdt_drvdata *drvdata = watchdog_get_drvdata(wdt_dev);
4749

48-
writew(0x0, drvdata->base + TCU_REG_WDT_TCNT);
50+
regmap_write(drvdata->map, TCU_REG_WDT_TCNT, 0);
51+
4952
return 0;
5053
}
5154

@@ -54,16 +57,16 @@ static int jz4740_wdt_set_timeout(struct watchdog_device *wdt_dev,
5457
{
5558
struct jz4740_wdt_drvdata *drvdata = watchdog_get_drvdata(wdt_dev);
5659
u16 timeout_value = (u16)(drvdata->clk_rate * new_timeout);
57-
u8 tcer;
60+
unsigned int tcer;
5861

59-
tcer = readb(drvdata->base + TCU_REG_WDT_TCER);
60-
writeb(0x0, drvdata->base + TCU_REG_WDT_TCER);
62+
regmap_read(drvdata->map, TCU_REG_WDT_TCER, &tcer);
63+
regmap_write(drvdata->map, TCU_REG_WDT_TCER, 0);
6164

62-
writew((u16)timeout_value, drvdata->base + TCU_REG_WDT_TDR);
63-
writew(0x0, drvdata->base + TCU_REG_WDT_TCNT);
65+
regmap_write(drvdata->map, TCU_REG_WDT_TDR, timeout_value);
66+
regmap_write(drvdata->map, TCU_REG_WDT_TCNT, 0);
6467

6568
if (tcer & TCU_WDT_TCER_TCEN)
66-
writeb(TCU_WDT_TCER_TCEN, drvdata->base + TCU_REG_WDT_TCER);
69+
regmap_write(drvdata->map, TCU_REG_WDT_TCER, TCU_WDT_TCER_TCEN);
6770

6871
wdt_dev->timeout = new_timeout;
6972
return 0;
@@ -72,20 +75,20 @@ static int jz4740_wdt_set_timeout(struct watchdog_device *wdt_dev,
7275
static int jz4740_wdt_start(struct watchdog_device *wdt_dev)
7376
{
7477
struct jz4740_wdt_drvdata *drvdata = watchdog_get_drvdata(wdt_dev);
78+
unsigned int tcer;
7579
int ret;
76-
u8 tcer;
7780

7881
ret = clk_prepare_enable(drvdata->clk);
7982
if (ret)
8083
return ret;
8184

82-
tcer = readb(drvdata->base + TCU_REG_WDT_TCER);
85+
regmap_read(drvdata->map, TCU_REG_WDT_TCER, &tcer);
8386

8487
jz4740_wdt_set_timeout(wdt_dev, wdt_dev->timeout);
8588

8689
/* Start watchdog if it wasn't started already */
8790
if (!(tcer & TCU_WDT_TCER_TCEN))
88-
writeb(TCU_WDT_TCER_TCEN, drvdata->base + TCU_REG_WDT_TCER);
91+
regmap_write(drvdata->map, TCU_REG_WDT_TCER, TCU_WDT_TCER_TCEN);
8992

9093
return 0;
9194
}
@@ -94,7 +97,7 @@ static int jz4740_wdt_stop(struct watchdog_device *wdt_dev)
9497
{
9598
struct jz4740_wdt_drvdata *drvdata = watchdog_get_drvdata(wdt_dev);
9699

97-
writeb(0x0, drvdata->base + TCU_REG_WDT_TCER);
100+
regmap_write(drvdata->map, TCU_REG_WDT_TCER, 0);
98101
clk_disable_unprepare(drvdata->clk);
99102

100103
return 0;
@@ -172,9 +175,11 @@ static int jz4740_wdt_probe(struct platform_device *pdev)
172175
watchdog_set_nowayout(jz4740_wdt, nowayout);
173176
watchdog_set_drvdata(jz4740_wdt, drvdata);
174177

175-
drvdata->base = devm_platform_ioremap_resource(pdev, 0);
176-
if (IS_ERR(drvdata->base))
177-
return PTR_ERR(drvdata->base);
178+
drvdata->map = device_node_to_regmap(dev->parent->of_node);
179+
if (!drvdata->map) {
180+
dev_err(dev, "regmap not found\n");
181+
return -EINVAL;
182+
}
178183

179184
return devm_watchdog_register_device(dev, &drvdata->wdt);
180185
}

0 commit comments

Comments
 (0)