Re: [PATCH v3] da9063: Add watchdog support
Hi Stefan, On 04/10/2024 09:43, Stefan Roese wrote: Sure, please pull it in if this makes sense for you. Applied to u-boot-imx/next, thanks.
Re: [PATCH v3] da9063: Add watchdog support
Hi Fabio, On 10/4/24 14:32, Fabio Estevam wrote: Hi Stefan, On 20/09/2024 07:00, Stefan Roese wrote: Changes since v2: - Use u8 instead of char. (Stefan) - Keep the Copyright header from Linux. (Stfan) Reviewed-by: Stefan Roese Would it be OK if I take this patch via the u-boot-imx tree? I have a patch that adds the DA9063 watchdog support to the imx6q-lxr2 board. Sure, please pull it in if this makes sense for you. Thanks, Stefan
Re: [PATCH v3] da9063: Add watchdog support
Hi Stefan, On 20/09/2024 07:00, Stefan Roese wrote: Changes since v2: - Use u8 instead of char. (Stefan) - Keep the Copyright header from Linux. (Stfan) Reviewed-by: Stefan Roese Would it be OK if I take this patch via the u-boot-imx tree? I have a patch that adds the DA9063 watchdog support to the imx6q-lxr2 board. Thanks, Fabio Estevam
Re: [PATCH v3] da9063: Add watchdog support
Hi Fabio, On 9/17/24 15:55, Fabio Estevam wrote: From: Fabio Estevam The DA9063 PMIC is a multi-function device that provides regulator, watchdog, RTC, and ON key functionalities. Add support for the DA9063 PMIC watchdog functionality. Based on the 6.11 kernel drivers/watchdog/da9063_wdt.c driver. Signed-off-by: Fabio Estevam --- Changes since v2: - Use u8 instead of char. (Stefan) - Keep the Copyright header from Linux. (Stfan) Reviewed-by: Stefan Roese Thanks, Stefan drivers/power/pmic/da9063.c | 12 ++- drivers/watchdog/Kconfig | 6 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/da9063-wdt.c | 149 ++ 4 files changed, 166 insertions(+), 2 deletions(-) create mode 100644 drivers/watchdog/da9063-wdt.c diff --git a/drivers/power/pmic/da9063.c b/drivers/power/pmic/da9063.c index 7bd3df391421..59c65702863c 100644 --- a/drivers/power/pmic/da9063.c +++ b/drivers/power/pmic/da9063.c @@ -7,6 +7,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -86,6 +89,7 @@ static int da9063_read(struct udevice *dev, uint reg, uint8_t *buff, int len) static int da9063_bind(struct udevice *dev) { ofnode regulators_node; + struct driver *drv; int children; regulators_node = dev_read_subnode(dev, "regulators"); @@ -101,8 +105,12 @@ static int da9063_bind(struct udevice *dev) if (!children) debug("%s: %s - no child found\n", __func__, dev->name); - /* Always return success for this device */ - return 0; + drv = lists_driver_lookup_name("da9063-wdt"); + if (!drv) + return 0; + + return device_bind_with_driver_data(dev, drv, "da9063-wdt", dev->driver_data, + dev_ofnode(dev), &dev); } static int da9063_probe(struct udevice *dev) diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index 0c3e99133186..90bc5653ee33 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -169,6 +169,12 @@ config WDT_CORTINA This driver support all CPU ISAs supported by Cortina Access CA SoCs. +config WDT_DA9063 + bool "DA9063 watchdog timer support" + depends on WDT && DM_PMIC_DA9063 + help + Enable support for the watchdog timer in Dialog DA9063. + config WDT_GPIO bool "External gpio watchdog support" depends on WDT diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile index 7b39adcf0ff4..6b564b7f96d2 100644 --- a/drivers/watchdog/Makefile +++ b/drivers/watchdog/Makefile @@ -29,6 +29,7 @@ obj-$(CONFIG_WDT_BOOKE) += booke_wdt.o obj-$(CONFIG_WDT_CORTINA) += cortina_wdt.o obj-$(CONFIG_WDT_ORION) += orion_wdt.o obj-$(CONFIG_WDT_CDNS) += cdns_wdt.o +obj-$(CONFIG_WDT_DA9063) += da9063-wdt.o obj-$(CONFIG_WDT_FTWDT010) += ftwdt010_wdt.o obj-$(CONFIG_WDT_GPIO) += gpio_wdt.o obj-$(CONFIG_WDT_MAX6370) += max6370_wdt.o diff --git a/drivers/watchdog/da9063-wdt.c b/drivers/watchdog/da9063-wdt.c new file mode 100644 index ..b7216b578630 --- /dev/null +++ b/drivers/watchdog/da9063-wdt.c @@ -0,0 +1,149 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Based on the Linux drivers/watchdog/da9063_wdt.c file. + * + * Watchdog driver for DA9063 PMICs. + * + * Copyright(c) 2012 Dialog Semiconductor Ltd. + * + * Author: Mariusz Wojtasik + * + * Ported to U-Boot by Fabio Estevam + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#defineDA9063_REG_CONTROL_D0x11 +/* DA9063_REG_CONTROL_D (addr=0x11) */ +#defineDA9063_TWDSCALE_MASK0x0 +#define DA9063_TWDSCALE_DISABLE0 +#defineDA9063_REG_CONTROL_F0x13 +/* DA9063_REG_CONTROL_F (addr=0x13) */ +#defineDA9063_WATCHDOG 0x01 +#defineDA9063_SHUTDOWN 0x02 + +/* + * Watchdog selector to timeout in seconds. + * 0: WDT disabled; + * others: timeout = 2048 ms * 2^(TWDSCALE-1). + */ +static const unsigned int wdt_timeout[] = { 0, 2, 4, 8, 16, 32, 65, 131 }; + +#define DA9063_TWDSCALE_DISABLE0 +#define DA9063_TWDSCALE_MIN1 +#define DA9063_TWDSCALE_MAX(ARRAY_SIZE(wdt_timeout) - 1) + +static unsigned int da9063_wdt_timeout_to_sel(unsigned int secs) +{ + unsigned int i; + + for (i = DA9063_TWDSCALE_MIN; i <= DA9063_TWDSCALE_MAX; i++) { + if (wdt_timeout[i] >= secs) + return i; + } + + return DA9063_TWDSCALE_MAX; +} + +static int da9063_read(struct udevice *dev, uint reg, uint8_t *buff, int len) +{ + return dm_i2c_read(dev->parent, reg, buff, len); +} + +static int da9063_write(struct udevice *dev, uint reg, const u8 *buff, int len) +{ + return dm_i2c_write(dev->parent, reg, buff, len); +} + +static int da9063_wdt_disable_timer(struct udevice *dev) +{ +
[PATCH v3] da9063: Add watchdog support
From: Fabio Estevam The DA9063 PMIC is a multi-function device that provides regulator, watchdog, RTC, and ON key functionalities. Add support for the DA9063 PMIC watchdog functionality. Based on the 6.11 kernel drivers/watchdog/da9063_wdt.c driver. Signed-off-by: Fabio Estevam --- Changes since v2: - Use u8 instead of char. (Stefan) - Keep the Copyright header from Linux. (Stfan) drivers/power/pmic/da9063.c | 12 ++- drivers/watchdog/Kconfig | 6 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/da9063-wdt.c | 149 ++ 4 files changed, 166 insertions(+), 2 deletions(-) create mode 100644 drivers/watchdog/da9063-wdt.c diff --git a/drivers/power/pmic/da9063.c b/drivers/power/pmic/da9063.c index 7bd3df391421..59c65702863c 100644 --- a/drivers/power/pmic/da9063.c +++ b/drivers/power/pmic/da9063.c @@ -7,6 +7,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -86,6 +89,7 @@ static int da9063_read(struct udevice *dev, uint reg, uint8_t *buff, int len) static int da9063_bind(struct udevice *dev) { ofnode regulators_node; + struct driver *drv; int children; regulators_node = dev_read_subnode(dev, "regulators"); @@ -101,8 +105,12 @@ static int da9063_bind(struct udevice *dev) if (!children) debug("%s: %s - no child found\n", __func__, dev->name); - /* Always return success for this device */ - return 0; + drv = lists_driver_lookup_name("da9063-wdt"); + if (!drv) + return 0; + + return device_bind_with_driver_data(dev, drv, "da9063-wdt", dev->driver_data, + dev_ofnode(dev), &dev); } static int da9063_probe(struct udevice *dev) diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index 0c3e99133186..90bc5653ee33 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -169,6 +169,12 @@ config WDT_CORTINA This driver support all CPU ISAs supported by Cortina Access CA SoCs. +config WDT_DA9063 + bool "DA9063 watchdog timer support" + depends on WDT && DM_PMIC_DA9063 + help + Enable support for the watchdog timer in Dialog DA9063. + config WDT_GPIO bool "External gpio watchdog support" depends on WDT diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile index 7b39adcf0ff4..6b564b7f96d2 100644 --- a/drivers/watchdog/Makefile +++ b/drivers/watchdog/Makefile @@ -29,6 +29,7 @@ obj-$(CONFIG_WDT_BOOKE) += booke_wdt.o obj-$(CONFIG_WDT_CORTINA) += cortina_wdt.o obj-$(CONFIG_WDT_ORION) += orion_wdt.o obj-$(CONFIG_WDT_CDNS) += cdns_wdt.o +obj-$(CONFIG_WDT_DA9063) += da9063-wdt.o obj-$(CONFIG_WDT_FTWDT010) += ftwdt010_wdt.o obj-$(CONFIG_WDT_GPIO) += gpio_wdt.o obj-$(CONFIG_WDT_MAX6370) += max6370_wdt.o diff --git a/drivers/watchdog/da9063-wdt.c b/drivers/watchdog/da9063-wdt.c new file mode 100644 index ..b7216b578630 --- /dev/null +++ b/drivers/watchdog/da9063-wdt.c @@ -0,0 +1,149 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Based on the Linux drivers/watchdog/da9063_wdt.c file. + * + * Watchdog driver for DA9063 PMICs. + * + * Copyright(c) 2012 Dialog Semiconductor Ltd. + * + * Author: Mariusz Wojtasik + * + * Ported to U-Boot by Fabio Estevam + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#defineDA9063_REG_CONTROL_D0x11 +/* DA9063_REG_CONTROL_D (addr=0x11) */ +#defineDA9063_TWDSCALE_MASK0x0 +#define DA9063_TWDSCALE_DISABLE0 +#defineDA9063_REG_CONTROL_F0x13 +/* DA9063_REG_CONTROL_F (addr=0x13) */ +#defineDA9063_WATCHDOG 0x01 +#defineDA9063_SHUTDOWN 0x02 + +/* + * Watchdog selector to timeout in seconds. + * 0: WDT disabled; + * others: timeout = 2048 ms * 2^(TWDSCALE-1). + */ +static const unsigned int wdt_timeout[] = { 0, 2, 4, 8, 16, 32, 65, 131 }; + +#define DA9063_TWDSCALE_DISABLE0 +#define DA9063_TWDSCALE_MIN1 +#define DA9063_TWDSCALE_MAX(ARRAY_SIZE(wdt_timeout) - 1) + +static unsigned int da9063_wdt_timeout_to_sel(unsigned int secs) +{ + unsigned int i; + + for (i = DA9063_TWDSCALE_MIN; i <= DA9063_TWDSCALE_MAX; i++) { + if (wdt_timeout[i] >= secs) + return i; + } + + return DA9063_TWDSCALE_MAX; +} + +static int da9063_read(struct udevice *dev, uint reg, uint8_t *buff, int len) +{ + return dm_i2c_read(dev->parent, reg, buff, len); +} + +static int da9063_write(struct udevice *dev, uint reg, const u8 *buff, int len) +{ + return dm_i2c_write(dev->parent, reg, buff, len); +} + +static int da9063_wdt_disable_timer(struct udevice *dev) +{ + u8 val; + + da9063_read(dev, DA9063_REG_CONTROL_D, &val, 1); + val &= ~DA9063_TWDSCALE_MASK; +