Commit 42d4ebb4 authored by Linus Torvalds's avatar Linus Torvalds

Merge git://www.linux-watchdog.org/linux-watchdog

Pull watchdog update from Wim Van Sebroeck:

 - New driver for Broadcom 7038 Set-Top Box
 - imx2_wdt: Use register definition in regmap_write()
 - intel-mid: add Magic Closure flag
 - watchdog framework improvements:
      - Use device tree alias for naming watchdogs
      - propagate ping error code to the user space
      - Always evaluate new timeout against min_timeout
      - Use single variable name for struct watchdog_device
 - include clean-ups

* git://www.linux-watchdog.org/linux-watchdog:
  watchdog: include: add units for timeout values in kerneldoc
  watchdog: include: fix some typos
  watchdog: core: propagate ping error code to the user space
  watchdog: watchdog_dev: Use single variable name for struct watchdog_device
  watchdog: Always evaluate new timeout against min_timeout
  watchdog: intel-mid: add Magic Closure flag
  watchdog: imx2_wdt: Use register definition in regmap_write()
  watchdog: watchdog_dev: Use device tree alias for naming watchdogs
  watchdog: Watchdog driver for Broadcom Set-Top Box
  watchdog: bcm7038: add device tree binding documentation
parents 6aabef68 760d2800
BCM7038 Watchdog timer
Required properties:
- compatible : should be "brcm,bcm7038-wdt"
- reg : Specifies base physical address and size of the registers.
Optional properties:
- clocks: The clock running the watchdog. If no clock is found the
driver will default to 27000000 Hz.
Example:
watchdog@f040a7e8 {
compatible = "brcm,bcm7038-wdt";
clocks = <&upg_fixed>;
reg = <0xf040a7e8 0x16>;
};
......@@ -1313,6 +1313,14 @@ config BCM_KONA_WDT_DEBUG
If in doubt, say 'N'.
config BCM7038_WDT
tristate "BCM7038 Watchdog"
select WATCHDOG_CORE
help
Watchdog driver for the built-in hardware in Broadcom 7038 SoCs.
Say 'Y or 'M' here to enable the driver.
config IMGPDC_WDT
tristate "Imagination Technologies PDC Watchdog Timer"
depends on HAS_IOMEM
......
......@@ -68,6 +68,7 @@ obj-$(CONFIG_MESON_WATCHDOG) += meson_wdt.o
obj-$(CONFIG_MEDIATEK_WATCHDOG) += mtk_wdt.o
obj-$(CONFIG_DIGICOLOR_WATCHDOG) += digicolor_wdt.o
obj-$(CONFIG_LPC18XX_WATCHDOG) += lpc18xx_wdt.o
obj-$(CONFIG_BCM7038_WDT) += bcm7038_wdt.o
# AVR32 Architecture
obj-$(CONFIG_AT32AP700X_WDT) += at32ap700x_wdt.o
......
/*
* Copyright (C) 2015 Broadcom Corporation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <linux/clk.h>
#include <linux/init.h>
#include <linux/io.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/pm.h>
#include <linux/watchdog.h>
#define WDT_START_1 0xff00
#define WDT_START_2 0x00ff
#define WDT_STOP_1 0xee00
#define WDT_STOP_2 0x00ee
#define WDT_TIMEOUT_REG 0x0
#define WDT_CMD_REG 0x4
#define WDT_MIN_TIMEOUT 1 /* seconds */
#define WDT_DEFAULT_TIMEOUT 30 /* seconds */
#define WDT_DEFAULT_RATE 27000000
struct bcm7038_watchdog {
void __iomem *base;
struct watchdog_device wdd;
u32 rate;
struct clk *clk;
};
static bool nowayout = WATCHDOG_NOWAYOUT;
static void bcm7038_wdt_set_timeout_reg(struct watchdog_device *wdog)
{
struct bcm7038_watchdog *wdt = watchdog_get_drvdata(wdog);
u32 timeout;
timeout = wdt->rate * wdog->timeout;
writel(timeout, wdt->base + WDT_TIMEOUT_REG);
}
static int bcm7038_wdt_ping(struct watchdog_device *wdog)
{
struct bcm7038_watchdog *wdt = watchdog_get_drvdata(wdog);
writel(WDT_START_1, wdt->base + WDT_CMD_REG);
writel(WDT_START_2, wdt->base + WDT_CMD_REG);
return 0;
}
static int bcm7038_wdt_start(struct watchdog_device *wdog)
{
bcm7038_wdt_set_timeout_reg(wdog);
bcm7038_wdt_ping(wdog);
return 0;
}
static int bcm7038_wdt_stop(struct watchdog_device *wdog)
{
struct bcm7038_watchdog *wdt = watchdog_get_drvdata(wdog);
writel(WDT_STOP_1, wdt->base + WDT_CMD_REG);
writel(WDT_STOP_2, wdt->base + WDT_CMD_REG);
return 0;
}
static int bcm7038_wdt_set_timeout(struct watchdog_device *wdog,
unsigned int t)
{
/* Can't modify timeout value if watchdog timer is running */
bcm7038_wdt_stop(wdog);
wdog->timeout = t;
bcm7038_wdt_start(wdog);
return 0;
}
static unsigned int bcm7038_wdt_get_timeleft(struct watchdog_device *wdog)
{
struct bcm7038_watchdog *wdt = watchdog_get_drvdata(wdog);
u32 time_left;
time_left = readl(wdt->base + WDT_CMD_REG);
return time_left / wdt->rate;
}
static struct watchdog_info bcm7038_wdt_info = {
.identity = "Broadcom BCM7038 Watchdog Timer",
.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING |
WDIOF_MAGICCLOSE
};
static struct watchdog_ops bcm7038_wdt_ops = {
.owner = THIS_MODULE,
.start = bcm7038_wdt_start,
.stop = bcm7038_wdt_stop,
.set_timeout = bcm7038_wdt_set_timeout,
.get_timeleft = bcm7038_wdt_get_timeleft,
};
static int bcm7038_wdt_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct bcm7038_watchdog *wdt;
struct resource *res;
int err;
wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL);
if (!wdt)
return -ENOMEM;
platform_set_drvdata(pdev, wdt);
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
wdt->base = devm_ioremap_resource(dev, res);
if (IS_ERR(wdt->base))
return PTR_ERR(wdt->base);
wdt->clk = devm_clk_get(dev, NULL);
/* If unable to get clock, use default frequency */
if (!IS_ERR(wdt->clk)) {
clk_prepare_enable(wdt->clk);
wdt->rate = clk_get_rate(wdt->clk);
/* Prevent divide-by-zero exception */
if (!wdt->rate)
wdt->rate = WDT_DEFAULT_RATE;
} else {
wdt->rate = WDT_DEFAULT_RATE;
wdt->clk = NULL;
}
wdt->wdd.info = &bcm7038_wdt_info;
wdt->wdd.ops = &bcm7038_wdt_ops;
wdt->wdd.min_timeout = WDT_MIN_TIMEOUT;
wdt->wdd.timeout = WDT_DEFAULT_TIMEOUT;
wdt->wdd.max_timeout = 0xffffffff / wdt->rate;
wdt->wdd.parent = dev;
watchdog_set_drvdata(&wdt->wdd, wdt);
err = watchdog_register_device(&wdt->wdd);
if (err) {
dev_err(dev, "Failed to register watchdog device\n");
clk_disable_unprepare(wdt->clk);
return err;
}
dev_info(dev, "Registered BCM7038 Watchdog\n");
return 0;
}
static int bcm7038_wdt_remove(struct platform_device *pdev)
{
struct bcm7038_watchdog *wdt = platform_get_drvdata(pdev);
if (!nowayout)
bcm7038_wdt_stop(&wdt->wdd);
watchdog_unregister_device(&wdt->wdd);
clk_disable_unprepare(wdt->clk);
return 0;
}
#ifdef CONFIG_PM_SLEEP
static int bcm7038_wdt_suspend(struct device *dev)
{
struct bcm7038_watchdog *wdt = dev_get_drvdata(dev);
if (watchdog_active(&wdt->wdd))
return bcm7038_wdt_stop(&wdt->wdd);
return 0;
}
static int bcm7038_wdt_resume(struct device *dev)
{
struct bcm7038_watchdog *wdt = dev_get_drvdata(dev);
if (watchdog_active(&wdt->wdd))
return bcm7038_wdt_start(&wdt->wdd);
return 0;
}
#endif
static SIMPLE_DEV_PM_OPS(bcm7038_wdt_pm_ops, bcm7038_wdt_suspend,
bcm7038_wdt_resume);
static void bcm7038_wdt_shutdown(struct platform_device *pdev)
{
struct bcm7038_watchdog *wdt = platform_get_drvdata(pdev);
if (watchdog_active(&wdt->wdd))
bcm7038_wdt_stop(&wdt->wdd);
}
static const struct of_device_id bcm7038_wdt_match[] = {
{ .compatible = "brcm,bcm7038-wdt" },
{},
};
static struct platform_driver bcm7038_wdt_driver = {
.probe = bcm7038_wdt_probe,
.remove = bcm7038_wdt_remove,
.shutdown = bcm7038_wdt_shutdown,
.driver = {
.name = "bcm7038-wdt",
.of_match_table = bcm7038_wdt_match,
.pm = &bcm7038_wdt_pm_ops,
}
};
module_platform_driver(bcm7038_wdt_driver);
module_param(nowayout, bool, 0);
MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
MODULE_LICENSE("GPL v2");
MODULE_DESCRIPTION("Driver for Broadcom 7038 SoCs Watchdog");
MODULE_AUTHOR("Justin Chen");
......@@ -91,7 +91,7 @@ static int imx2_restart_handler(struct notifier_block *this, unsigned long mode,
struct imx2_wdt_device,
restart_handler);
/* Assert SRS signal */
regmap_write(wdev->regmap, 0, wcr_enable);
regmap_write(wdev->regmap, IMX2_WDT_WCR, wcr_enable);
/*
* Due to imx6q errata ERR004346 (WDOG: WDOG SRS bit requires to be
* written twice), we add another two writes to ensure there must be at
......@@ -99,8 +99,8 @@ static int imx2_restart_handler(struct notifier_block *this, unsigned long mode,
* the target check here, since the writes shouldn't be a huge burden
* for other platforms.
*/
regmap_write(wdev->regmap, 0, wcr_enable);
regmap_write(wdev->regmap, 0, wcr_enable);
regmap_write(wdev->regmap, IMX2_WDT_WCR, wcr_enable);
regmap_write(wdev->regmap, IMX2_WDT_WCR, wcr_enable);
/* wait for reset to assert... */
mdelay(500);
......
......@@ -101,7 +101,7 @@ static irqreturn_t mid_wdt_irq(int irq, void *dev_id)
static const struct watchdog_info mid_wdt_info = {
.identity = "Intel MID SCU watchdog",
.options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT,
.options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE,
};
static const struct watchdog_ops mid_wdt_ops = {
......
......@@ -139,7 +139,7 @@ EXPORT_SYMBOL_GPL(watchdog_init_timeout);
static int __watchdog_register_device(struct watchdog_device *wdd)
{
int ret, id, devno;
int ret, id = -1, devno;
if (wdd == NULL || wdd->info == NULL || wdd->ops == NULL)
return -EINVAL;
......@@ -157,7 +157,18 @@ static int __watchdog_register_device(struct watchdog_device *wdd)
*/
mutex_init(&wdd->lock);
/* Use alias for watchdog id if possible */
if (wdd->parent) {
ret = of_alias_get_id(wdd->parent->of_node, "watchdog");
if (ret >= 0)
id = ida_simple_get(&watchdog_ida, ret,
ret + 1, GFP_KERNEL);
}
if (id < 0)
id = ida_simple_get(&watchdog_ida, 0, MAX_DOGS, GFP_KERNEL);
if (id < 0)
return id;
wdd->id = id;
......
This diff is collapsed.
......@@ -24,8 +24,8 @@ struct watchdog_device;
* @stop: The routine for stopping the watchdog device.
* @ping: The routine that sends a keepalive ping to the watchdog device.
* @status: The routine that shows the status of the watchdog device.
* @set_timeout:The routine for setting the watchdog devices timeout value.
* @get_timeleft:The routine that get's the time that's left before a reset.
* @set_timeout:The routine for setting the watchdog devices timeout value (in seconds).
* @get_timeleft:The routine that gets the time left before a reset (in seconds).
* @ref: The ref operation for dyn. allocated watchdog_device structs
* @unref: The unref operation for dyn. allocated watchdog_device structs
* @ioctl: The routines that handles extra ioctl calls.
......@@ -33,7 +33,7 @@ struct watchdog_device;
* The watchdog_ops structure contains a list of low-level operations
* that control a watchdog device. It also contains the module that owns
* these operations. The start and stop function are mandatory, all other
* functions are optonal.
* functions are optional.
*/
struct watchdog_ops {
struct module *owner;
......@@ -59,9 +59,9 @@ struct watchdog_ops {
* @info: Pointer to a watchdog_info structure.
* @ops: Pointer to the list of watchdog operations.
* @bootstatus: Status of the watchdog device at boot.
* @timeout: The watchdog devices timeout value.
* @min_timeout:The watchdog devices minimum timeout value.
* @max_timeout:The watchdog devices maximum timeout value.
* @timeout: The watchdog devices timeout value (in seconds).
* @min_timeout:The watchdog devices minimum timeout value (in seconds).
* @max_timeout:The watchdog devices maximum timeout value (in seconds).
* @driver-data:Pointer to the drivers private data.
* @lock: Lock for watchdog core internal use only.
* @status: Field that contains the devices internal status bits.
......@@ -119,8 +119,15 @@ static inline void watchdog_set_nowayout(struct watchdog_device *wdd, bool noway
/* Use the following function to check if a timeout value is invalid */
static inline bool watchdog_timeout_invalid(struct watchdog_device *wdd, unsigned int t)
{
return ((wdd->max_timeout != 0) &&
(t < wdd->min_timeout || t > wdd->max_timeout));
/*
* The timeout is invalid if
* - the requested value is smaller than the configured minimum timeout,
* or
* - a maximum timeout is configured, and the requested value is larger
* than the maximum timeout.
*/
return t < wdd->min_timeout ||
(wdd->max_timeout && t > wdd->max_timeout);
}
/* Use the following functions to manipulate watchdog driver specific data */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment