watchdog: tangier: Convert to use WDT class
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Fri, 21 Jun 2019 10:28:08 +0000 (13:28 +0300)
committerBin Meng <bmeng.cn@gmail.com>
Sat, 22 Jun 2019 14:27:13 +0000 (22:27 +0800)
Convert legacy driver to use watchdog class.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Stefan Roese <sr@denx.de>
arch/x86/cpu/tangier/Kconfig
arch/x86/dts/edison.dts
configs/edison_defconfig
drivers/watchdog/Kconfig
drivers/watchdog/Makefile
drivers/watchdog/tangier_wdt.c

index a3bd16799dfd13cdf3b5c924ee97e94fcd969a0e..d2b7edecd6041eee4e60c7cf9de1ee06f5b24245 100644 (file)
@@ -10,7 +10,6 @@ config INTEL_TANGIER
        imply MMC_SDHCI
        imply MMC_SDHCI_SDMA
        imply MMC_SDHCI_TANGIER
        imply MMC_SDHCI
        imply MMC_SDHCI_SDMA
        imply MMC_SDHCI_TANGIER
-       imply TANGIER_WATCHDOG
        imply USB
        imply USB_DWC3
 
        imply USB
        imply USB_DWC3
 
index e8564bbb8a92efca5679d48bbb2261886b1274c5..c0487656d3f03a161109bc19aadef2199cbce510 100644 (file)
                reg = <0xff009000 0x1000>;
        };
 
                reg = <0xff009000 0x1000>;
        };
 
+       watchdog: wdt@0 {
+               compatible = "intel,tangier-wdt";
+       };
+
        reset {
                compatible = "intel,reset-tangier";
                u-boot,dm-pre-reloc;
        reset {
                compatible = "intel,reset-tangier";
                u-boot,dm-pre-reloc;
index 840c87ac5aeb9f983dcd4db34ed077d5753a01d4..468754493eb108bb81eb2c04945345f01bddb43d 100644 (file)
@@ -39,5 +39,7 @@ CONFIG_USB_GADGET_VENDOR_NUM=0x8087
 CONFIG_USB_GADGET_PRODUCT_NUM=0x0a99
 CONFIG_USB_GADGET_DOWNLOAD=y
 # CONFIG_USB_HOST_ETHER is not set
 CONFIG_USB_GADGET_PRODUCT_NUM=0x0a99
 CONFIG_USB_GADGET_DOWNLOAD=y
 # CONFIG_USB_HOST_ETHER is not set
+CONFIG_WDT=y
+CONFIG_WDT_TANGIER=y
 CONFIG_FAT_WRITE=y
 CONFIG_SHA1=y
 CONFIG_FAT_WRITE=y
 CONFIG_SHA1=y
index dbafb74a34d2a941b147b465aebe00a4de2fbc55..ee0ddffe7355e8193070c951d5a8bedb54059d3c 100644 (file)
@@ -41,15 +41,6 @@ config OMAP_WATCHDOG
        help
          Say Y here to enable the OMAP3+ watchdog driver.
 
        help
          Say Y here to enable the OMAP3+ watchdog driver.
 
-config TANGIER_WATCHDOG
-       bool "Intel Tangier watchdog"
-       depends on INTEL_MID
-       select HW_WATCHDOG
-       help
-         This enables support for watchdog controller available on
-         Intel Tangier SoC. If you're using a board with Intel Tangier
-         SoC, say Y here.
-
 config ULP_WATCHDOG
        bool "i.MX7ULP watchdog"
        help
 config ULP_WATCHDOG
        bool "i.MX7ULP watchdog"
        help
@@ -170,4 +161,12 @@ config XILINX_TB_WATCHDOG
           Select this to enable Xilinx Axi watchdog timer, which can be found on some
           Xilinx Microblaze Platforms.
 
           Select this to enable Xilinx Axi watchdog timer, which can be found on some
           Xilinx Microblaze Platforms.
 
+config WDT_TANGIER
+       bool "Intel Tangier watchdog timer support"
+       depends on WDT && INTEL_MID
+       help
+         This enables support for watchdog controller available on
+         Intel Tangier SoC. If you're using a board with Intel Tangier
+         SoC, say Y here.
+
 endmenu
 endmenu
index e3f4fdb406f4619fc1316edbdbb17b3e4031b99b..68c989aa0b905fe09d66805953d914d810ccacc3 100644 (file)
@@ -14,7 +14,6 @@ obj-$(CONFIG_S5P)               += s5p_wdt.o
 obj-$(CONFIG_XILINX_TB_WATCHDOG) += xilinx_tb_wdt.o
 obj-$(CONFIG_OMAP_WATCHDOG) += omap_wdt.o
 obj-$(CONFIG_DESIGNWARE_WATCHDOG) += designware_wdt.o
 obj-$(CONFIG_XILINX_TB_WATCHDOG) += xilinx_tb_wdt.o
 obj-$(CONFIG_OMAP_WATCHDOG) += omap_wdt.o
 obj-$(CONFIG_DESIGNWARE_WATCHDOG) += designware_wdt.o
-obj-$(CONFIG_TANGIER_WATCHDOG) += tangier_wdt.o
 obj-$(CONFIG_ULP_WATCHDOG) += ulp_wdog.o
 obj-$(CONFIG_WDT) += wdt-uclass.o
 obj-$(CONFIG_WDT_SANDBOX) += sandbox_wdt.o
 obj-$(CONFIG_ULP_WATCHDOG) += ulp_wdog.o
 obj-$(CONFIG_WDT) += wdt-uclass.o
 obj-$(CONFIG_WDT_SANDBOX) += sandbox_wdt.o
@@ -29,3 +28,4 @@ obj-$(CONFIG_WDT_MT7621) += mt7621_wdt.o
 obj-$(CONFIG_WDT_MTK) += mtk_wdt.o
 obj-$(CONFIG_WDT_SP805) += sp805_wdt.o
 obj-$(CONFIG_WDT_STM32MP) += stm32mp_wdt.o
 obj-$(CONFIG_WDT_MTK) += mtk_wdt.o
 obj-$(CONFIG_WDT_SP805) += sp805_wdt.o
 obj-$(CONFIG_WDT_STM32MP) += stm32mp_wdt.o
+obj-$(CONFIG_WDT_TANGIER) += tangier_wdt.o
index b2f40ef0574453b51733ba7db5e5fd3c79e5adb0..ba265cf223d8c5b07bd792437a64e8314a5da006 100644 (file)
@@ -3,7 +3,9 @@
  * Copyright (c) 2017 Intel Corporation
  */
 #include <common.h>
  * Copyright (c) 2017 Intel Corporation
  */
 #include <common.h>
-#include <watchdog.h>
+#include <dm.h>
+#include <wdt.h>
+#include <div64.h>
 #include <asm/scu.h>
 
 /* Hardware timeout in seconds */
 #include <asm/scu.h>
 
 /* Hardware timeout in seconds */
  * the reboot will happen.
  */
 
  * the reboot will happen.
  */
 
-#ifndef CONFIG_WATCHDOG_TIMEOUT_MSECS
-#define WATCHDOG_HEARTBEAT 60000
-#else
-#define WATCHDOG_HEARTBEAT CONFIG_WATCHDOG_TIMEOUT_MSECS
-#endif
-
 enum {
        SCU_WATCHDOG_START                      = 0,
        SCU_WATCHDOG_STOP                       = 1,
 enum {
        SCU_WATCHDOG_START                      = 0,
        SCU_WATCHDOG_STOP                       = 1,
@@ -30,39 +26,33 @@ enum {
        SCU_WATCHDOG_SET_ACTION_ON_TIMEOUT      = 3,
 };
 
        SCU_WATCHDOG_SET_ACTION_ON_TIMEOUT      = 3,
 };
 
-void hw_watchdog_reset(void)
+static int tangier_wdt_reset(struct udevice *dev)
 {
 {
-       static unsigned long last;
-       unsigned long now;
-
-       if (gd->timer)
-               now = timer_get_us();
-       else
-               now = rdtsc() / 1000;
-
-       /* Do not flood SCU */
-       if (last > now)
-               last = 0;
-
-       if (unlikely((now - last) > (WDT_PRETIMEOUT / 2) * 1000000)) {
-               last = now;
-               scu_ipc_simple_command(IPCMSG_WATCHDOG_TIMER, SCU_WATCHDOG_KEEPALIVE);
-       }
+       scu_ipc_simple_command(IPCMSG_WATCHDOG_TIMER, SCU_WATCHDOG_KEEPALIVE);
+       return 0;
 }
 
 }
 
-int hw_watchdog_disable(void)
+static int tangier_wdt_stop(struct udevice *dev)
 {
        return scu_ipc_simple_command(IPCMSG_WATCHDOG_TIMER, SCU_WATCHDOG_STOP);
 }
 
 {
        return scu_ipc_simple_command(IPCMSG_WATCHDOG_TIMER, SCU_WATCHDOG_STOP);
 }
 
-void hw_watchdog_init(void)
+static int tangier_wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags)
 {
 {
-       u32 timeout = WATCHDOG_HEARTBEAT / 1000;
+       u32 timeout_sec;
        int in_size;
        struct ipc_wd_start {
                u32 pretimeout;
                u32 timeout;
        int in_size;
        struct ipc_wd_start {
                u32 pretimeout;
                u32 timeout;
-       } ipc_wd_start = { timeout - WDT_PRETIMEOUT, timeout };
+       } ipc_wd_start;
+
+       /* Calculate timeout in seconds and restrict to min and max value */
+       do_div(timeout_ms, 1000);
+       timeout_sec = clamp_t(u32, timeout_ms, WDT_TIMEOUT_MIN, WDT_TIMEOUT_MAX);
+
+       /* Update values in the IPC request */
+       ipc_wd_start.pretimeout = timeout_sec - WDT_PRETIMEOUT;
+       ipc_wd_start.timeout = timeout_sec;
 
        /*
         * SCU expects the input size for watchdog IPC
 
        /*
         * SCU expects the input size for watchdog IPC
@@ -72,4 +62,31 @@ void hw_watchdog_init(void)
 
        scu_ipc_command(IPCMSG_WATCHDOG_TIMER, SCU_WATCHDOG_START,
                        (u32 *)&ipc_wd_start, in_size, NULL, 0);
 
        scu_ipc_command(IPCMSG_WATCHDOG_TIMER, SCU_WATCHDOG_START,
                        (u32 *)&ipc_wd_start, in_size, NULL, 0);
+
+       return 0;
+}
+
+static const struct wdt_ops tangier_wdt_ops = {
+       .reset = tangier_wdt_reset,
+       .start = tangier_wdt_start,
+       .stop = tangier_wdt_stop,
+};
+
+static const struct udevice_id tangier_wdt_ids[] = {
+       { .compatible = "intel,tangier-wdt" },
+       { /* sentinel */ }
+};
+
+static int tangier_wdt_probe(struct udevice *dev)
+{
+       debug("%s: Probing wdt%u\n", __func__, dev->seq);
+       return 0;
 }
 }
+
+U_BOOT_DRIVER(wdt_tangier) = {
+       .name = "wdt_tangier",
+       .id = UCLASS_WDT,
+       .of_match = tangier_wdt_ids,
+       .ops = &tangier_wdt_ops,
+       .probe = tangier_wdt_probe,
+};