Skip to content
Snippets Groups Projects
Commit b093db33 authored by Gianfranco Mariotti's avatar Gianfranco Mariotti
Browse files

[ALL][i.MX6QDL][A62] Add GPIO watchdog driver

This patch adds a driver for gpio-based WDTs that use two gpios: enable and trigger.
This driver is based on the linux GPIO-controlled Watchdog driver.
It was necessary for enabling the watchdog on A62, since on reboot it was noticed
its absence prevented the correct reinitialization of lvds.
There exists another driver that could be used for similar hardware, called with
the compatible name "seco,apx-wdog".
That one initializes the watchdog early in the boot process, and is used for more
complex cases.
parent 55276fc3
No related branches found
No related tags found
No related merge requests found
...@@ -224,7 +224,25 @@ ...@@ -224,7 +224,25 @@
}; };
}; };
/* __________________________________________________________________________
* | |
* | WATCHDOG |
* |__________________________________________________________________________|
*/
&wdog1 {
status = "disabled";
};
/ {
watchdog: watchdog {
compatible = "seco,wdt-gpio";
enable-gpios = <&gpio4 11 GPIO_ACTIVE_HIGH>;
trigger-gpios = <&gpio3 25 GPIO_ACTIVE_LOW>;
hw_margin_ms = <500>;
timeout_s = <30>;
enable_high;
};
};
/* __________________________________________________________________________ /* __________________________________________________________________________
* | | * | |
......
...@@ -274,6 +274,7 @@ CONFIG_DA9062_WATCHDOG=y ...@@ -274,6 +274,7 @@ CONFIG_DA9062_WATCHDOG=y
CONFIG_RN5T618_WATCHDOG=y CONFIG_RN5T618_WATCHDOG=y
CONFIG_IMX2_WDT=y CONFIG_IMX2_WDT=y
CONFIG_IMX7ULP_WDT=y CONFIG_IMX7ULP_WDT=y
CONFIG_SECO_GPIO_WATCHDOG=y
CONFIG_MFD_DA9052_I2C=y CONFIG_MFD_DA9052_I2C=y
CONFIG_MFD_DA9062=y CONFIG_MFD_DA9062=y
CONFIG_MFD_DA9063=y CONFIG_MFD_DA9063=y
......
...@@ -214,6 +214,14 @@ config DA9062_WATCHDOG ...@@ -214,6 +214,14 @@ config DA9062_WATCHDOG
This driver can be built as a module. The module name is da9062_wdt. This driver can be built as a module. The module name is da9062_wdt.
config SECO_GPIO_WATCHDOG
tristate "SECO Watchdog device controlled through GPIO-line"
depends on OF_GPIO
select WATCHDOG_CORE
help
If you say yes here you get support for SECO watchdog device
controlled through GPIO-line.
config GPIO_WATCHDOG config GPIO_WATCHDOG
tristate "Watchdog device controlled through GPIO-line" tristate "Watchdog device controlled through GPIO-line"
depends on OF_GPIO depends on OF_GPIO
......
...@@ -227,3 +227,6 @@ obj-$(CONFIG_MENZ069_WATCHDOG) += menz69_wdt.o ...@@ -227,3 +227,6 @@ obj-$(CONFIG_MENZ069_WATCHDOG) += menz69_wdt.o
obj-$(CONFIG_RAVE_SP_WATCHDOG) += rave-sp-wdt.o obj-$(CONFIG_RAVE_SP_WATCHDOG) += rave-sp-wdt.o
obj-$(CONFIG_STPMIC1_WATCHDOG) += stpmic1_wdt.o obj-$(CONFIG_STPMIC1_WATCHDOG) += stpmic1_wdt.o
obj-$(CONFIG_SL28CPLD_WATCHDOG) += sl28cpld_wdt.o obj-$(CONFIG_SL28CPLD_WATCHDOG) += sl28cpld_wdt.o
# SECO
obj-$(CONFIG_SECO_GPIO_WATCHDOG) += seco_gpio_wdt.o
/*
* Driver for SECO watchdog device controlled through GPIO-line
*
* Author: 2023, Gianfranco Mariotti <gianfranco.mariotti@seco.com>
*
* 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.
*/
#include <linux/err.h>
#include <linux/delay.h>
#include <linux/module.h>
#include <linux/gpio/consumer.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/watchdog.h>
struct gpio_wdt_priv {
struct gpio_desc *gpio_en;
struct gpio_desc *gpio_trg;
struct watchdog_device wdd;
bool state;
bool enable_high;
bool trigger_high;
};
static int gpio_wdt_ping(struct watchdog_device *wdd)
{
struct gpio_wdt_priv *priv = watchdog_get_drvdata(wdd);
/* Toggle trigger pin */
priv->state = !priv->state;
gpiod_set_value_cansleep(priv->gpio_trg, priv->state);
return 0;
}
static int gpio_wdt_start(struct watchdog_device *wdd)
{
struct gpio_wdt_priv *priv = watchdog_get_drvdata(wdd);
gpiod_direction_output(priv->gpio_en, priv->enable_high);
priv->state = priv->trigger_high;
gpiod_direction_output(priv->gpio_trg, priv->state);
set_bit(WDOG_HW_RUNNING, &wdd->status);
return gpio_wdt_ping(wdd);
}
static int gpio_wdt_stop(struct watchdog_device *wdd)
{
struct gpio_wdt_priv *priv = watchdog_get_drvdata(wdd);
set_bit(WDOG_HW_RUNNING, &wdd->status);
return 0;
}
static const struct watchdog_info gpio_wdt_ident = {
.options = WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT,
.identity = "SECO GPIO Watchdog",
};
static const struct watchdog_ops gpio_wdt_ops = {
.owner = THIS_MODULE,
.start = gpio_wdt_start,
.stop = gpio_wdt_stop,
.ping = gpio_wdt_ping,
};
static int gpio_wdt_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct device_node *np = dev->of_node;
struct gpio_wdt_priv *priv;
enum gpiod_flags gflags;
unsigned int hw_margin;
unsigned int timeout;
int ret;
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
return -ENOMEM;
platform_set_drvdata(pdev, priv);
priv->gpio_en = devm_gpiod_get(dev, "enable", GPIOD_ASIS);
if (IS_ERR(priv->gpio_en))
return PTR_ERR(priv->gpio_en);
priv->gpio_trg = devm_gpiod_get(dev, "trigger", GPIOD_ASIS);
if (IS_ERR(priv->gpio_trg))
return PTR_ERR(priv->gpio_trg);
ret = of_property_read_u32(np, "hw_margin_ms", &hw_margin);
if (ret)
return ret;
if (hw_margin < 2 || hw_margin > 65535)
return -EINVAL;
priv->enable_high = of_property_read_bool(np, "enable_high");
priv->trigger_high = of_property_read_bool(np, "trigger_high");
watchdog_set_drvdata(&priv->wdd, priv);
priv->wdd.info = &gpio_wdt_ident;
priv->wdd.ops = &gpio_wdt_ops;
priv->wdd.min_timeout = 1;
priv->wdd.max_hw_heartbeat_ms = hw_margin;
priv->wdd.parent = dev;
ret = of_property_read_u32(np, "timeout_s", &timeout);
if (ret)
priv->wdd.timeout = 60;
else {
if (timeout < 5 || timeout > 120)
priv->wdd.timeout = 60;
else
priv->wdd.timeout = timeout;
}
watchdog_init_timeout(&priv->wdd, 0, &pdev->dev);
watchdog_stop_on_reboot(&priv->wdd);
gpio_wdt_start(&priv->wdd);
ret = watchdog_register_device(&priv->wdd);
return ret;
}
static int gpio_wdt_remove(struct platform_device *pdev)
{
struct gpio_wdt_priv *priv = platform_get_drvdata(pdev);
watchdog_unregister_device(&priv->wdd);
return 0;
}
static const struct of_device_id gpio_wdt_dt_ids[] = {
{ .compatible = "seco,wdt-gpio", },
{ }
};
MODULE_DEVICE_TABLE(of, gpio_wdt_dt_ids);
static struct platform_driver gpio_wdt_driver = {
.driver = {
.name = "seco-gpio-wdt",
.of_match_table = gpio_wdt_dt_ids,
},
.probe = gpio_wdt_probe,
.remove = gpio_wdt_remove,
};
#ifdef CONFIG_GPIO_WATCHDOG_ARCH_INITCALL
static int __init gpio_wdt_init(void)
{
return platform_driver_register(&gpio_wdt_driver);
}
arch_initcall(gpio_wdt_init);
#else
module_platform_driver(gpio_wdt_driver);
#endif
MODULE_AUTHOR("Gianfranco Mariotti <gianfranco.mariotti@seco.com>");
MODULE_DESCRIPTION("SECO GPIO Watchdog");
MODULE_LICENSE("GPL");
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment