Skip to content

Commit 19f7eae

Browse files
prabhakarladWim Van Sebroeck
authored andcommitted
watchdog: rzv2h: Obtain clock-divider and timeout values from OF match data
Update the rzv2h_wdt driver to fetch clock configuration and timeout parameters from device tree match data rather than relying on hardcoded constants. Introduce a new structure rzv2h_of_data that encapsulates minimum and maximum clock select values (cks_min and cks_max), clock divider (cks_div), timeout cycle count (timeout_cycles), and the timeout period select bits (tops). These values are provided through the OF match table and retrieved via of_device_get_match_data() during probe. This change allows dynamic configuration of the watchdog timer for different SoCs, such as the RZ/T2H, which require different settings. Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> Reviewed-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>
1 parent 5cacd26 commit 19f7eae

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

drivers/watchdog/rzv2h_wdt.c

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,28 @@
3535

3636
#define WDTRCR_RSTIRQS BIT(7)
3737

38-
#define MAX_TIMEOUT_CYCLES 16384
39-
#define CLOCK_DIV_BY_256 256
40-
4138
#define WDT_DEFAULT_TIMEOUT 60U
4239

4340
static bool nowayout = WATCHDOG_NOWAYOUT;
4441
module_param(nowayout, bool, 0);
4542
MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
4643
__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
4744

45+
struct rzv2h_of_data {
46+
u8 cks_min;
47+
u8 cks_max;
48+
u16 cks_div;
49+
u8 tops;
50+
u16 timeout_cycles;
51+
};
52+
4853
struct rzv2h_wdt_priv {
4954
void __iomem *base;
5055
struct clk *pclk;
5156
struct clk *oscclk;
5257
struct reset_control *rstc;
5358
struct watchdog_device wdev;
59+
const struct rzv2h_of_data *of_data;
5460
};
5561

5662
static int rzv2h_wdt_ping(struct watchdog_device *wdev)
@@ -84,6 +90,7 @@ static void rzv2h_wdt_setup(struct watchdog_device *wdev, u16 wdtcr)
8490
static int rzv2h_wdt_start(struct watchdog_device *wdev)
8591
{
8692
struct rzv2h_wdt_priv *priv = watchdog_get_drvdata(wdev);
93+
const struct rzv2h_of_data *of_data = priv->of_data;
8794
int ret;
8895

8996
ret = pm_runtime_resume_and_get(wdev->parent);
@@ -106,8 +113,8 @@ static int rzv2h_wdt_start(struct watchdog_device *wdev)
106113
* - RPES[9:8] - Window End Position Select - 11b: 0%
107114
* - TOPS[1:0] - Timeout Period Select - 11b: 16384 cycles (3FFFh)
108115
*/
109-
rzv2h_wdt_setup(wdev, WDTCR_CKS_CLK_256 | WDTCR_RPSS_100 |
110-
WDTCR_RPES_0 | WDTCR_TOPS_16384);
116+
rzv2h_wdt_setup(wdev, of_data->cks_max | WDTCR_RPSS_100 |
117+
WDTCR_RPES_0 | of_data->tops);
111118

112119
/*
113120
* Down counting starts after writing the sequence 00h -> FFh to the
@@ -184,7 +191,7 @@ static int rzv2h_wdt_restart(struct watchdog_device *wdev,
184191
* - RPES[9:8] - Window End Position Select - 00b: 75%
185192
* - TOPS[1:0] - Timeout Period Select - 00b: 1024 cycles (03FFh)
186193
*/
187-
rzv2h_wdt_setup(wdev, WDTCR_CKS_CLK_1 | WDTCR_RPSS_25 |
194+
rzv2h_wdt_setup(wdev, priv->of_data->cks_min | WDTCR_RPSS_25 |
188195
WDTCR_RPES_75 | WDTCR_TOPS_1024);
189196

190197
rzv2h_wdt_ping(wdev);
@@ -213,6 +220,8 @@ static int rzv2h_wdt_probe(struct platform_device *pdev)
213220
if (!priv)
214221
return -ENOMEM;
215222

223+
priv->of_data = of_device_get_match_data(dev);
224+
216225
priv->base = devm_platform_ioremap_resource(pdev, 0);
217226
if (IS_ERR(priv->base))
218227
return PTR_ERR(priv->base);
@@ -230,8 +239,8 @@ static int rzv2h_wdt_probe(struct platform_device *pdev)
230239
return dev_err_probe(dev, PTR_ERR(priv->rstc),
231240
"failed to get cpg reset");
232241

233-
priv->wdev.max_hw_heartbeat_ms = (MILLI * MAX_TIMEOUT_CYCLES * CLOCK_DIV_BY_256) /
234-
clk_get_rate(priv->oscclk);
242+
priv->wdev.max_hw_heartbeat_ms = (MILLI * priv->of_data->timeout_cycles *
243+
priv->of_data->cks_div) / clk_get_rate(priv->oscclk);
235244
dev_dbg(dev, "max hw timeout of %dms\n", priv->wdev.max_hw_heartbeat_ms);
236245

237246
ret = devm_pm_runtime_enable(dev);
@@ -254,8 +263,16 @@ static int rzv2h_wdt_probe(struct platform_device *pdev)
254263
return devm_watchdog_register_device(dev, &priv->wdev);
255264
}
256265

266+
static const struct rzv2h_of_data rzv2h_wdt_of_data = {
267+
.cks_min = WDTCR_CKS_CLK_1,
268+
.cks_max = WDTCR_CKS_CLK_256,
269+
.cks_div = 256,
270+
.tops = WDTCR_TOPS_16384,
271+
.timeout_cycles = 16384,
272+
};
273+
257274
static const struct of_device_id rzv2h_wdt_ids[] = {
258-
{ .compatible = "renesas,r9a09g057-wdt", },
275+
{ .compatible = "renesas,r9a09g057-wdt", .data = &rzv2h_wdt_of_data },
259276
{ /* sentinel */ }
260277
};
261278
MODULE_DEVICE_TABLE(of, rzv2h_wdt_ids);

0 commit comments

Comments
 (0)