Skip to content

Commit

Permalink
watchdog: of_xilinx_wdt: Initialize watchdog via data structure
Browse files Browse the repository at this point in the history
This patch is preparation for adding new watchdog based on this driver.
of_id->data is storing link xwdt_devtype_data which stores watchdog
info and ops pointers to structures.

Signed-off-by: Srinivas Goud <srinivas.goud@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Radhey Shyam Pandey <radhey.shyam.pandey@xilinx.com>
Signed-off-by: Srinivas Neeli <srinivas.neeli@xilinx.com>
State: pending
  • Loading branch information
Srinivas Neeli authored and Michal Simek committed Apr 16, 2020
1 parent 8e12063 commit 5511e5b
Showing 1 changed file with 36 additions and 14 deletions.
50 changes: 36 additions & 14 deletions drivers/watchdog/of_xilinx_wdt.c
Expand Up @@ -37,6 +37,11 @@

#define WATCHDOG_NAME "Xilinx Watchdog"

struct xwdt_devtype_data {
const struct watchdog_ops *xwdt_ops;
const struct watchdog_info *xwdt_info;
};

struct xwdt_device {
void __iomem *base;
u32 wdt_interval;
Expand Down Expand Up @@ -160,21 +165,44 @@ static void xwdt_clk_disable_unprepare(void *data)
clk_disable_unprepare(data);
}

static const struct xwdt_devtype_data xwdt_wdt_data = {
.xwdt_info = &xilinx_wdt_ident,
.xwdt_ops = &xilinx_wdt_ops,
};

static const struct of_device_id xwdt_of_match[] = {
{ .compatible = "xlnx,xps-timebase-wdt-1.00.a",
.data = &xwdt_wdt_data },
{ .compatible = "xlnx,xps-timebase-wdt-1.01.a",
.data = &xwdt_wdt_data },
{},
};
MODULE_DEVICE_TABLE(of, xwdt_of_match);

static int xwdt_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
int rc;
u32 pfreq = 0, enable_once = 0;
struct xwdt_device *xdev;
struct watchdog_device *xilinx_wdt_wdd;
const struct of_device_id *of_id;
const struct xwdt_devtype_data *devtype;

xdev = devm_kzalloc(dev, sizeof(*xdev), GFP_KERNEL);
if (!xdev)
return -ENOMEM;

xilinx_wdt_wdd = &xdev->xilinx_wdt_wdd;
xilinx_wdt_wdd->info = &xilinx_wdt_ident;
xilinx_wdt_wdd->ops = &xilinx_wdt_ops;

of_id = of_match_device(xwdt_of_match, &pdev->dev);
if (!of_id)
return -EINVAL;

devtype = of_id->data;

xilinx_wdt_wdd->info = devtype->xwdt_info;
xilinx_wdt_wdd->ops = devtype->xwdt_ops;
xilinx_wdt_wdd->parent = dev;

xdev->base = devm_platform_ioremap_resource(pdev, 0);
Expand Down Expand Up @@ -264,9 +292,10 @@ static int xwdt_probe(struct platform_device *pdev)
static int __maybe_unused xwdt_suspend(struct device *dev)
{
struct xwdt_device *xdev = dev_get_drvdata(dev);
struct watchdog_device *xilinx_wdt_wdd = &xdev->xilinx_wdt_wdd;

if (watchdog_active(&xdev->xilinx_wdt_wdd))
xilinx_wdt_stop(&xdev->xilinx_wdt_wdd);
if (watchdog_active(xilinx_wdt_wdd))
xilinx_wdt_wdd->ops->stop(xilinx_wdt_wdd);

return 0;
}
Expand All @@ -280,24 +309,17 @@ static int __maybe_unused xwdt_suspend(struct device *dev)
static int __maybe_unused xwdt_resume(struct device *dev)
{
struct xwdt_device *xdev = dev_get_drvdata(dev);
struct watchdog_device *xilinx_wdt_wdd = &xdev->xilinx_wdt_wdd;
int ret = 0;

if (watchdog_active(&xdev->xilinx_wdt_wdd))
ret = xilinx_wdt_start(&xdev->xilinx_wdt_wdd);
if (watchdog_active(xilinx_wdt_wdd))
ret = xilinx_wdt_wdd->ops->start(xilinx_wdt_wdd);

return ret;
}

static SIMPLE_DEV_PM_OPS(xwdt_pm_ops, xwdt_suspend, xwdt_resume);

/* Match table for of_platform binding */
static const struct of_device_id xwdt_of_match[] = {
{ .compatible = "xlnx,xps-timebase-wdt-1.00.a", },
{ .compatible = "xlnx,xps-timebase-wdt-1.01.a", },
{},
};
MODULE_DEVICE_TABLE(of, xwdt_of_match);

static struct platform_driver xwdt_driver = {
.probe = xwdt_probe,
.driver = {
Expand Down

0 comments on commit 5511e5b

Please sign in to comment.