提交 1924227b 编写于 作者: E Ezequiel Garcia 提交者: Jason Cooper

watchdog: orion: Add per-compatible clock initialization

Following the introduction of the compatible-data field,
it's now possible to further abstract the clock initialization.
This will allow to support SoC with a different clock setup.
Reviewed-by: NGuenter Roeck <linux@roeck-us.net>
Tested-by: NSebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
Tested-by: NWilly Tarreau <w@1wt.eu>
Signed-off-by: NEzequiel Garcia <ezequiel.garcia@free-electrons.com>
Acked-by: NWim Van Sebroeck <wim@iguana.be>
Tested-By: NJason Gunthorpe <jgunthorpe@obsidianresearch.com>
Signed-off-by: NJason Cooper <jason@lakedaemon.net>
上级 fc723856
...@@ -42,10 +42,14 @@ ...@@ -42,10 +42,14 @@
static bool nowayout = WATCHDOG_NOWAYOUT; static bool nowayout = WATCHDOG_NOWAYOUT;
static int heartbeat = -1; /* module parameter (seconds) */ static int heartbeat = -1; /* module parameter (seconds) */
struct orion_watchdog;
struct orion_watchdog_data { struct orion_watchdog_data {
int wdt_counter_offset; int wdt_counter_offset;
int wdt_enable_bit; int wdt_enable_bit;
int rstout_enable_bit; int rstout_enable_bit;
int (*clock_init)(struct platform_device *,
struct orion_watchdog *);
}; };
struct orion_watchdog { struct orion_watchdog {
...@@ -57,6 +61,22 @@ struct orion_watchdog { ...@@ -57,6 +61,22 @@ struct orion_watchdog {
const struct orion_watchdog_data *data; const struct orion_watchdog_data *data;
}; };
static int orion_wdt_clock_init(struct platform_device *pdev,
struct orion_watchdog *dev)
{
int ret;
dev->clk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(dev->clk))
return PTR_ERR(dev->clk);
ret = clk_prepare_enable(dev->clk);
if (ret)
return ret;
dev->clk_rate = clk_get_rate(dev->clk);
return 0;
}
static int orion_wdt_ping(struct watchdog_device *wdt_dev) static int orion_wdt_ping(struct watchdog_device *wdt_dev)
{ {
struct orion_watchdog *dev = watchdog_get_drvdata(wdt_dev); struct orion_watchdog *dev = watchdog_get_drvdata(wdt_dev);
...@@ -172,6 +192,7 @@ static const struct orion_watchdog_data orion_data = { ...@@ -172,6 +192,7 @@ static const struct orion_watchdog_data orion_data = {
.rstout_enable_bit = BIT(1), .rstout_enable_bit = BIT(1),
.wdt_enable_bit = BIT(4), .wdt_enable_bit = BIT(4),
.wdt_counter_offset = 0x24, .wdt_counter_offset = 0x24,
.clock_init = orion_wdt_clock_init,
}; };
static const struct of_device_id orion_wdt_of_match_table[] = { static const struct of_device_id orion_wdt_of_match_table[] = {
...@@ -206,34 +227,24 @@ static int orion_wdt_probe(struct platform_device *pdev) ...@@ -206,34 +227,24 @@ static int orion_wdt_probe(struct platform_device *pdev)
dev->wdt.min_timeout = 1; dev->wdt.min_timeout = 1;
dev->data = match->data; dev->data = match->data;
dev->clk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(dev->clk)) {
dev_err(&pdev->dev, "Orion Watchdog missing clock\n");
return PTR_ERR(dev->clk);
}
ret = clk_prepare_enable(dev->clk);
if (ret)
return ret;
dev->clk_rate = clk_get_rate(dev->clk);
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) { if (!res)
ret = -ENODEV; return -ENODEV;
goto disable_clk;
}
dev->reg = devm_ioremap(&pdev->dev, res->start, dev->reg = devm_ioremap(&pdev->dev, res->start,
resource_size(res)); resource_size(res));
if (!dev->reg) { if (!dev->reg)
ret = -ENOMEM; return -ENOMEM;
goto disable_clk;
}
dev->rstout = orion_wdt_ioremap_rstout(pdev, res->start & dev->rstout = orion_wdt_ioremap_rstout(pdev, res->start &
INTERNAL_REGS_MASK); INTERNAL_REGS_MASK);
if (!dev->rstout) { if (!dev->rstout)
ret = -ENODEV; return -ENODEV;
goto disable_clk;
ret = dev->data->clock_init(pdev, dev);
if (ret) {
dev_err(&pdev->dev, "cannot initialize clock\n");
return ret;
} }
wdt_max_duration = WDT_MAX_CYCLE_COUNT / dev->clk_rate; wdt_max_duration = WDT_MAX_CYCLE_COUNT / dev->clk_rate;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册