* [PATCH 1/2] watchdog: of_xilinx_wdt: Add support for reading freq via CCF
@ 2017-08-07 11:24 Michal Simek
2017-08-07 11:24 ` [PATCH 2/2] watchdog: of_xilinx_wdt: Add suspend/resume support Michal Simek
2017-08-15 1:49 ` [1/2] watchdog: of_xilinx_wdt: Add support for reading freq via CCF Guenter Roeck
0 siblings, 2 replies; 4+ messages in thread
From: Michal Simek @ 2017-08-07 11:24 UTC (permalink / raw)
To: linux-kernel, monstr
Cc: Maulik Jodhani, Sören Brinkmann, Guenter Roeck,
linux-watchdog, Wim Van Sebroeck, linux-arm-kernel
From: Maulik Jodhani <maulik.jodhani@xilinx.com>
Improve CLK handling in the code to read freq via CCF.
Also disable CLK asap and add clk handling code to start and stop.
Signed-off-by: Maulik Jodhani <maulik.jodhani@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
---
drivers/watchdog/of_xilinx_wdt.c | 45 ++++++++++++++++++++++++++++------------
1 file changed, 32 insertions(+), 13 deletions(-)
diff --git a/drivers/watchdog/of_xilinx_wdt.c b/drivers/watchdog/of_xilinx_wdt.c
index fae7fe929ea3..41edeb93a327 100644
--- a/drivers/watchdog/of_xilinx_wdt.c
+++ b/drivers/watchdog/of_xilinx_wdt.c
@@ -51,9 +51,16 @@ struct xwdt_device {
static int xilinx_wdt_start(struct watchdog_device *wdd)
{
+ int ret;
u32 control_status_reg;
struct xwdt_device *xdev = watchdog_get_drvdata(wdd);
+ ret = clk_enable(xdev->clk);
+ if (ret) {
+ dev_err(wdd->parent, "Failed to enable clock\n");
+ return ret;
+ }
+
spin_lock(&xdev->spinlock);
/* Clean previous status and enable the watchdog timer */
@@ -85,6 +92,9 @@ static int xilinx_wdt_stop(struct watchdog_device *wdd)
iowrite32(0, xdev->base + XWT_TWCSR1_OFFSET);
spin_unlock(&xdev->spinlock);
+
+ clk_disable(xdev->clk);
+
pr_info("Stopped!\n");
return 0;
@@ -167,11 +177,6 @@ static int xwdt_probe(struct platform_device *pdev)
if (IS_ERR(xdev->base))
return PTR_ERR(xdev->base);
- rc = of_property_read_u32(pdev->dev.of_node, "clock-frequency", &pfreq);
- if (rc)
- dev_warn(&pdev->dev,
- "The watchdog clock frequency cannot be obtained\n");
-
rc = of_property_read_u32(pdev->dev.of_node, "xlnx,wdt-interval",
&xdev->wdt_interval);
if (rc)
@@ -186,6 +191,26 @@ static int xwdt_probe(struct platform_device *pdev)
watchdog_set_nowayout(xilinx_wdt_wdd, enable_once);
+ xdev->clk = devm_clk_get(&pdev->dev, NULL);
+ if (IS_ERR(xdev->clk)) {
+ if (PTR_ERR(xdev->clk) != -ENOENT)
+ return PTR_ERR(xdev->clk);
+
+ /*
+ * Clock framework support is optional, continue on
+ * anyways if we don't find a matching clock.
+ */
+ xdev->clk = NULL;
+
+ rc = of_property_read_u32(pdev->dev.of_node, "clock-frequency",
+ &pfreq);
+ if (rc)
+ dev_warn(&pdev->dev,
+ "The watchdog clock freq cannot be obtained\n");
+ } else {
+ pfreq = clk_get_rate(xdev->clk);
+ }
+
/*
* Twice of the 2^wdt_interval / freq because the first wdt overflow is
* ignored (interrupt), reset is only generated at second wdt overflow
@@ -197,14 +222,6 @@ static int xwdt_probe(struct platform_device *pdev)
spin_lock_init(&xdev->spinlock);
watchdog_set_drvdata(xilinx_wdt_wdd, xdev);
- xdev->clk = devm_clk_get(&pdev->dev, NULL);
- if (IS_ERR(xdev->clk)) {
- if (PTR_ERR(xdev->clk) == -ENOENT)
- xdev->clk = NULL;
- else
- return PTR_ERR(xdev->clk);
- }
-
rc = clk_prepare_enable(xdev->clk);
if (rc) {
dev_err(&pdev->dev, "unable to enable clock\n");
@@ -223,6 +240,8 @@ static int xwdt_probe(struct platform_device *pdev)
goto err_clk_disable;
}
+ clk_disable(xdev->clk);
+
dev_info(&pdev->dev, "Xilinx Watchdog Timer at %p with timeout %ds\n",
xdev->base, xilinx_wdt_wdd->timeout);
--
1.9.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] watchdog: of_xilinx_wdt: Add suspend/resume support
2017-08-07 11:24 [PATCH 1/2] watchdog: of_xilinx_wdt: Add support for reading freq via CCF Michal Simek
@ 2017-08-07 11:24 ` Michal Simek
2017-08-15 1:51 ` [2/2] " Guenter Roeck
2017-08-15 1:49 ` [1/2] watchdog: of_xilinx_wdt: Add support for reading freq via CCF Guenter Roeck
1 sibling, 1 reply; 4+ messages in thread
From: Michal Simek @ 2017-08-07 11:24 UTC (permalink / raw)
To: linux-kernel, monstr
Cc: Sören Brinkmann, Guenter Roeck, linux-watchdog,
Wim Van Sebroeck, linux-arm-kernel
Add suspend/resume support to driver.
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
---
drivers/watchdog/of_xilinx_wdt.c | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/drivers/watchdog/of_xilinx_wdt.c b/drivers/watchdog/of_xilinx_wdt.c
index 41edeb93a327..1cf286945b7a 100644
--- a/drivers/watchdog/of_xilinx_wdt.c
+++ b/drivers/watchdog/of_xilinx_wdt.c
@@ -264,6 +264,43 @@ static int xwdt_remove(struct platform_device *pdev)
return 0;
}
+/**
+ * xwdt_suspend - Suspend the device.
+ *
+ * @dev: handle to the device structure.
+ * Return: 0 always.
+ */
+static int __maybe_unused xwdt_suspend(struct device *dev)
+{
+ struct platform_device *pdev = to_platform_device(dev);
+ struct xwdt_device *xdev = platform_get_drvdata(pdev);
+
+ if (watchdog_active(&xdev->xilinx_wdt_wdd))
+ xilinx_wdt_stop(&xdev->xilinx_wdt_wdd);
+
+ return 0;
+}
+
+/**
+ * xwdt_resume - Resume the device.
+ *
+ * @dev: handle to the device structure.
+ * Return: 0 on success, errno otherwise.
+ */
+static int __maybe_unused xwdt_resume(struct device *dev)
+{
+ struct platform_device *pdev = to_platform_device(dev);
+ struct xwdt_device *xdev = platform_get_drvdata(pdev);
+ int ret = 0;
+
+ if (watchdog_active(&xdev->xilinx_wdt_wdd))
+ ret = xilinx_wdt_start(&xdev->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", },
@@ -278,6 +315,7 @@ static int xwdt_remove(struct platform_device *pdev)
.driver = {
.name = WATCHDOG_NAME,
.of_match_table = xwdt_of_match,
+ .pm = &xwdt_pm_ops,
},
};
--
1.9.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [1/2] watchdog: of_xilinx_wdt: Add support for reading freq via CCF
2017-08-07 11:24 [PATCH 1/2] watchdog: of_xilinx_wdt: Add support for reading freq via CCF Michal Simek
2017-08-07 11:24 ` [PATCH 2/2] watchdog: of_xilinx_wdt: Add suspend/resume support Michal Simek
@ 2017-08-15 1:49 ` Guenter Roeck
1 sibling, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2017-08-15 1:49 UTC (permalink / raw)
To: Michal Simek
Cc: linux-kernel, monstr, Maulik Jodhani, Sören Brinkmann,
linux-watchdog, Wim Van Sebroeck, linux-arm-kernel
On Mon, Aug 07, 2017 at 01:24:22PM +0200, Michal Simek wrote:
> From: Maulik Jodhani <maulik.jodhani@xilinx.com>
>
> Improve CLK handling in the code to read freq via CCF.
> Also disable CLK asap and add clk handling code to start and stop.
>
> Signed-off-by: Maulik Jodhani <maulik.jodhani@xilinx.com>
> Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
> ---
>
> drivers/watchdog/of_xilinx_wdt.c | 45 ++++++++++++++++++++++++++++------------
> 1 file changed, 32 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/watchdog/of_xilinx_wdt.c b/drivers/watchdog/of_xilinx_wdt.c
> index fae7fe929ea3..41edeb93a327 100644
> --- a/drivers/watchdog/of_xilinx_wdt.c
> +++ b/drivers/watchdog/of_xilinx_wdt.c
> @@ -51,9 +51,16 @@ struct xwdt_device {
>
> static int xilinx_wdt_start(struct watchdog_device *wdd)
> {
> + int ret;
> u32 control_status_reg;
> struct xwdt_device *xdev = watchdog_get_drvdata(wdd);
>
> + ret = clk_enable(xdev->clk);
> + if (ret) {
> + dev_err(wdd->parent, "Failed to enable clock\n");
> + return ret;
> + }
> +
> spin_lock(&xdev->spinlock);
>
> /* Clean previous status and enable the watchdog timer */
> @@ -85,6 +92,9 @@ static int xilinx_wdt_stop(struct watchdog_device *wdd)
> iowrite32(0, xdev->base + XWT_TWCSR1_OFFSET);
>
> spin_unlock(&xdev->spinlock);
> +
> + clk_disable(xdev->clk);
> +
> pr_info("Stopped!\n");
>
> return 0;
> @@ -167,11 +177,6 @@ static int xwdt_probe(struct platform_device *pdev)
> if (IS_ERR(xdev->base))
> return PTR_ERR(xdev->base);
>
> - rc = of_property_read_u32(pdev->dev.of_node, "clock-frequency", &pfreq);
> - if (rc)
> - dev_warn(&pdev->dev,
> - "The watchdog clock frequency cannot be obtained\n");
> -
> rc = of_property_read_u32(pdev->dev.of_node, "xlnx,wdt-interval",
> &xdev->wdt_interval);
> if (rc)
> @@ -186,6 +191,26 @@ static int xwdt_probe(struct platform_device *pdev)
>
> watchdog_set_nowayout(xilinx_wdt_wdd, enable_once);
>
> + xdev->clk = devm_clk_get(&pdev->dev, NULL);
> + if (IS_ERR(xdev->clk)) {
> + if (PTR_ERR(xdev->clk) != -ENOENT)
> + return PTR_ERR(xdev->clk);
> +
> + /*
> + * Clock framework support is optional, continue on
> + * anyways if we don't find a matching clock.
> + */
> + xdev->clk = NULL;
> +
> + rc = of_property_read_u32(pdev->dev.of_node, "clock-frequency",
> + &pfreq);
> + if (rc)
> + dev_warn(&pdev->dev,
> + "The watchdog clock freq cannot be obtained\n");
> + } else {
> + pfreq = clk_get_rate(xdev->clk);
> + }
> +
> /*
> * Twice of the 2^wdt_interval / freq because the first wdt overflow is
> * ignored (interrupt), reset is only generated at second wdt overflow
> @@ -197,14 +222,6 @@ static int xwdt_probe(struct platform_device *pdev)
> spin_lock_init(&xdev->spinlock);
> watchdog_set_drvdata(xilinx_wdt_wdd, xdev);
>
> - xdev->clk = devm_clk_get(&pdev->dev, NULL);
> - if (IS_ERR(xdev->clk)) {
> - if (PTR_ERR(xdev->clk) == -ENOENT)
> - xdev->clk = NULL;
> - else
> - return PTR_ERR(xdev->clk);
> - }
> -
> rc = clk_prepare_enable(xdev->clk);
> if (rc) {
> dev_err(&pdev->dev, "unable to enable clock\n");
> @@ -223,6 +240,8 @@ static int xwdt_probe(struct platform_device *pdev)
> goto err_clk_disable;
> }
>
> + clk_disable(xdev->clk);
> +
> dev_info(&pdev->dev, "Xilinx Watchdog Timer at %p with timeout %ds\n",
> xdev->base, xilinx_wdt_wdd->timeout);
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [2/2] watchdog: of_xilinx_wdt: Add suspend/resume support
2017-08-07 11:24 ` [PATCH 2/2] watchdog: of_xilinx_wdt: Add suspend/resume support Michal Simek
@ 2017-08-15 1:51 ` Guenter Roeck
0 siblings, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2017-08-15 1:51 UTC (permalink / raw)
To: Michal Simek
Cc: linux-kernel, monstr, Sören Brinkmann, linux-watchdog,
Wim Van Sebroeck, linux-arm-kernel
On Mon, Aug 07, 2017 at 01:24:23PM +0200, Michal Simek wrote:
> Add suspend/resume support to driver.
>
> Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
> ---
>
> drivers/watchdog/of_xilinx_wdt.c | 38 ++++++++++++++++++++++++++++++++++++++
> 1 file changed, 38 insertions(+)
>
> diff --git a/drivers/watchdog/of_xilinx_wdt.c b/drivers/watchdog/of_xilinx_wdt.c
> index 41edeb93a327..1cf286945b7a 100644
> --- a/drivers/watchdog/of_xilinx_wdt.c
> +++ b/drivers/watchdog/of_xilinx_wdt.c
> @@ -264,6 +264,43 @@ static int xwdt_remove(struct platform_device *pdev)
> return 0;
> }
>
> +/**
> + * xwdt_suspend - Suspend the device.
> + *
> + * @dev: handle to the device structure.
> + * Return: 0 always.
> + */
> +static int __maybe_unused xwdt_suspend(struct device *dev)
> +{
> + struct platform_device *pdev = to_platform_device(dev);
> + struct xwdt_device *xdev = platform_get_drvdata(pdev);
> +
> + if (watchdog_active(&xdev->xilinx_wdt_wdd))
> + xilinx_wdt_stop(&xdev->xilinx_wdt_wdd);
> +
> + return 0;
> +}
> +
> +/**
> + * xwdt_resume - Resume the device.
> + *
> + * @dev: handle to the device structure.
> + * Return: 0 on success, errno otherwise.
> + */
> +static int __maybe_unused xwdt_resume(struct device *dev)
> +{
> + struct platform_device *pdev = to_platform_device(dev);
> + struct xwdt_device *xdev = platform_get_drvdata(pdev);
> + int ret = 0;
> +
> + if (watchdog_active(&xdev->xilinx_wdt_wdd))
> + ret = xilinx_wdt_start(&xdev->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", },
> @@ -278,6 +315,7 @@ static int xwdt_remove(struct platform_device *pdev)
> .driver = {
> .name = WATCHDOG_NAME,
> .of_match_table = xwdt_of_match,
> + .pm = &xwdt_pm_ops,
> },
> };
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-08-15 1:52 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-07 11:24 [PATCH 1/2] watchdog: of_xilinx_wdt: Add support for reading freq via CCF Michal Simek
2017-08-07 11:24 ` [PATCH 2/2] watchdog: of_xilinx_wdt: Add suspend/resume support Michal Simek
2017-08-15 1:51 ` [2/2] " Guenter Roeck
2017-08-15 1:49 ` [1/2] watchdog: of_xilinx_wdt: Add support for reading freq via CCF Guenter Roeck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).