[U-Boot] [PATCH v3 0/4] Xilinx Axi Watchdog driver conversion to driver model

Hi,
this is moving MB watchdog to DM. I have taken v2 from Shreenidhi and did some changes to speedup upstreaming because I need this for my gpio work. Removing watchdog in the first patch is not big deal because this is generic platform and adresses are fake.
Thanks, Michal
Changes in v3: - Fix commit message - Fix commit message and subject - Add support for seq aliases - Fix commit message - s/Axi/AXI - Use platdata instead of private data. - Remove \n from wdt reset to catch logs - Add debug to wdt_start - New patch
Changes in v2: - Added appropriate commit message. - Moving wdt.h out of ifdef clause - Using CONFIG_WDT & CONFIG_WATCHDOG based on review comments - Rectified print message - Removed stop instruction from probe
Changes in v1: - Removed reduntant macros. - Watchdog reset support, inorder to get WATCHDOG_RESET macro working - Xilinx Axi wdt driver conversion to DM initial version
Michal Simek (1): microblaze: Enable watchdog via defconfig
Shreenidhi Shedi (3): microblaze: Delete Xilinx watchdog related macros microblaze: Support for watchdog_reset in init watchdog: Convert Xilinx Axi watchdog driver to driver model
.../xilinx/microblaze-generic/microblaze-generic.c | 47 ++++++++- board/xilinx/microblaze-generic/xparameters.h | 4 - configs/microblaze-generic_defconfig | 2 + drivers/watchdog/Kconfig | 8 ++ drivers/watchdog/xilinx_tb_wdt.c | 109 ++++++++++++++++----- include/configs/microblaze-generic.h | 10 -- 6 files changed, 137 insertions(+), 43 deletions(-)

From: Shreenidhi Shedi yesshedi@gmail.com
These macros are not required anymore. These will be taken from configuration file.
Signed-off-by: Shreenidhi Shedi yesshedi@gmail.com Signed-off-by: Michal Simek michal.simek@xilinx.com ---
Changes in v3: - Fix commit message
Changes in v2: - Added appropriate commit message.
Changes in v1: - Removed reduntant macros.
board/xilinx/microblaze-generic/xparameters.h | 4 ---- include/configs/microblaze-generic.h | 10 ---------- 2 files changed, 14 deletions(-)
diff --git a/board/xilinx/microblaze-generic/xparameters.h b/board/xilinx/microblaze-generic/xparameters.h index 57998edba472..01116d827c63 100644 --- a/board/xilinx/microblaze-generic/xparameters.h +++ b/board/xilinx/microblaze-generic/xparameters.h @@ -19,7 +19,3 @@ /* Flash Memory is FLASH_2Mx32 */ #define XILINX_FLASH_START 0x2c000000 #define XILINX_FLASH_SIZE 0x00800000 - -/* Watchdog IP is wxi_timebase_wdt_0 */ -#define XILINX_WATCHDOG_BASEADDR 0x50000000 -#define XILINX_WATCHDOG_IRQ 1 diff --git a/include/configs/microblaze-generic.h b/include/configs/microblaze-generic.h index 7f16700d4f13..6a049cf2af6b 100644 --- a/include/configs/microblaze-generic.h +++ b/include/configs/microblaze-generic.h @@ -43,16 +43,6 @@ # define CONFIG_SYS_GPIO_0_ADDR XILINX_GPIO_BASEADDR #endif
-/* watchdog */ -#if defined(XILINX_WATCHDOG_BASEADDR) && defined(XILINX_WATCHDOG_IRQ) -# define CONFIG_WATCHDOG_BASEADDR XILINX_WATCHDOG_BASEADDR -# define CONFIG_WATCHDOG_IRQ XILINX_WATCHDOG_IRQ -# ifndef CONFIG_SPL_BUILD -# define CONFIG_HW_WATCHDOG -# define CONFIG_XILINX_TB_WATCHDOG -# endif -#endif - #define CONFIG_SYS_MALLOC_LEN 0xC0000
/* Stack location before relocation */

From: Shreenidhi Shedi yesshedi@gmail.com
We should support watchdog reset so that WATCHDOG_RESET will function properly.
Signed-off-by: Shreenidhi Shedi yesshedi@gmail.com Signed-off-by: Michal Simek michal.simek@xilinx.com ---
Changes in v3: - Fix commit message and subject - Add support for seq aliases
Changes in v2: - Moving wdt.h out of ifdef clause - Using CONFIG_WDT & CONFIG_WATCHDOG based on review comments
Changes in v1: - Watchdog reset support, inorder to get WATCHDOG_RESET macro working
.../xilinx/microblaze-generic/microblaze-generic.c | 47 ++++++++++++++++++++-- 1 file changed, 43 insertions(+), 4 deletions(-)
diff --git a/board/xilinx/microblaze-generic/microblaze-generic.c b/board/xilinx/microblaze-generic/microblaze-generic.c index 9be2cceca705..556d0de7f143 100644 --- a/board/xilinx/microblaze-generic/microblaze-generic.c +++ b/board/xilinx/microblaze-generic/microblaze-generic.c @@ -17,6 +17,8 @@ #include <asm/microblaze_intc.h> #include <asm/asm.h> #include <asm/gpio.h> +#include <dm/uclass.h> +#include <wdt.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -24,6 +26,10 @@ DECLARE_GLOBAL_DATA_PTR; static int reset_pin = -1; #endif
+#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_WDT) +static struct udevice *watchdog_dev; +#endif /* !CONFIG_SPL_BUILD && CONFIG_WDT */ + ulong ram_base;
int dram_init_banksize(void) @@ -68,10 +74,6 @@ int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if (reset_pin != -1) gpio_direction_output(reset_pin, 1); #endif - -#ifdef CONFIG_XILINX_TB_WATCHDOG - hw_watchdog_disable(); -#endif #endif puts("Resetting board\n"); __asm__ __volatile__ (" mts rmsr, r0;" \ @@ -91,9 +93,46 @@ static int gpio_init(void) return 0; }
+#ifdef CONFIG_WDT +/* Called by macro WATCHDOG_RESET */ +void watchdog_reset(void) +{ +#if !defined(CONFIG_SPL_BUILD) + ulong now; + static ulong next_reset; + + if (!watchdog_dev) + return; + + now = timer_get_us(); + + /* Do not reset the watchdog too often */ + if (now > next_reset) { + wdt_reset(watchdog_dev); + next_reset = now + 1000; + } +#endif /* !CONFIG_SPL_BUILD */ +} +#endif /* CONFIG_WDT */ + int board_late_init(void) { gpio_init();
+#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_WDT) + watchdog_dev = NULL; + + if (uclass_get_device_by_seq(UCLASS_WDT, 0, &watchdog_dev)) { + debug("Watchdog: Not found by seq!\n"); + if (uclass_get_device(UCLASS_WDT, 0, &watchdog_dev)) { + puts("Watchdog: Not found!\n"); + return 0; + } + } + + wdt_start(watchdog_dev, 0, 0); + puts("Watchdog: Started\n"); +#endif /* !CONFIG_SPL_BUILD && CONFIG_WDT */ + return 0; }

From: Shreenidhi Shedi yesshedi@gmail.com
Xilinx Axi wdt driver conversion to driver model & Kconfig update for the same.
Signed-off-by: Shreenidhi Shedi yesshedi@gmail.com Signed-off-by: Michal Simek michal.simek@xilinx.com ---
Changes in v3: - Fix commit message - s/Axi/AXI - Use platdata instead of private data. - Remove \n from wdt reset to catch logs - Add debug to wdt_start
Changes in v2: - Rectified print message - Removed stop instruction from probe
Changes in v1: - Xilinx Axi wdt driver conversion to DM initial version
drivers/watchdog/Kconfig | 8 +++ drivers/watchdog/xilinx_tb_wdt.c | 109 ++++++++++++++++++++++++++++++--------- 2 files changed, 92 insertions(+), 25 deletions(-)
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index 148c6a0d687c..351d2af8d98b 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -103,4 +103,12 @@ config WDT_CDNS Select this to enable Cadence watchdog timer, which can be found on some Xilinx Microzed Platform.
+config XILINX_TB_WATCHDOG + bool "Xilinx Axi watchdog timer support" + depends on WDT + imply WATCHDOG + help + Select this to enable Xilinx Axi watchdog timer, which can be found on some + Xilinx Microblaze Platform. + endmenu diff --git a/drivers/watchdog/xilinx_tb_wdt.c b/drivers/watchdog/xilinx_tb_wdt.c index 2274123e4919..6cb03e9892d1 100644 --- a/drivers/watchdog/xilinx_tb_wdt.c +++ b/drivers/watchdog/xilinx_tb_wdt.c @@ -1,13 +1,17 @@ // SPDX-License-Identifier: GPL-2.0+ /* - * Copyright (c) 2011-2013 Xilinx Inc. + * Xilinx AXI platforms watchdog timer driver. + * + * Author(s): Michal Simek michal.simek@xilinx.com + * Shreenidhi Shedi yesshedi@gmail.com + * + * Copyright (c) 2011-2018 Xilinx Inc. */
#include <common.h> -#include <asm/io.h> -#include <asm/microblaze_intc.h> -#include <asm/processor.h> -#include <watchdog.h> +#include <dm.h> +#include <wdt.h> +#include <linux/io.h>
#define XWT_CSR0_WRS_MASK 0x00000008 /* Reset status Mask */ #define XWT_CSR0_WDS_MASK 0x00000004 /* Timer state Mask */ @@ -20,49 +24,104 @@ struct watchdog_regs { u32 tbr; /* 0x8 */ };
-static struct watchdog_regs *watchdog_base = - (struct watchdog_regs *)CONFIG_WATCHDOG_BASEADDR; +struct xlnx_wdt_platdata { + bool enable_once; + struct watchdog_regs *regs; +};
-void hw_watchdog_reset(void) +static int xlnx_wdt_reset(struct udevice *dev) { u32 reg; + struct xlnx_wdt_platdata *platdata = dev_get_platdata(dev); + + debug("%s ", __func__);
/* Read the current contents of TCSR0 */ - reg = readl(&watchdog_base->twcsr0); + reg = readl(&platdata->regs->twcsr0);
/* Clear the watchdog WDS bit */ if (reg & (XWT_CSR0_EWDT1_MASK | XWT_CSRX_EWDT2_MASK)) - writel(reg | XWT_CSR0_WDS_MASK, &watchdog_base->twcsr0); + writel(reg | XWT_CSR0_WDS_MASK, &platdata->regs->twcsr0); + + return 0; }
-void hw_watchdog_disable(void) +static int xlnx_wdt_stop(struct udevice *dev) { u32 reg; + struct xlnx_wdt_platdata *platdata = dev_get_platdata(dev); + + if (platdata->enable_once) { + puts("Can't stop Xilinx watchdog.\n"); + return -1; + }
/* Read the current contents of TCSR0 */ - reg = readl(&watchdog_base->twcsr0); + reg = readl(&platdata->regs->twcsr0);
- writel(reg & ~XWT_CSR0_EWDT1_MASK, &watchdog_base->twcsr0); - writel(~XWT_CSRX_EWDT2_MASK, &watchdog_base->twcsr1); + writel(reg & ~XWT_CSR0_EWDT1_MASK, &platdata->regs->twcsr0); + writel(~XWT_CSRX_EWDT2_MASK, &platdata->regs->twcsr1);
puts("Watchdog disabled!\n"); + + return 0; }
-static void hw_watchdog_isr(void *arg) +static int xlnx_wdt_start(struct udevice *dev, u64 timeout, ulong flags) { - hw_watchdog_reset(); + struct xlnx_wdt_platdata *platdata = dev_get_platdata(dev); + + debug("%s:\n", __func__); + + writel((XWT_CSR0_WRS_MASK | XWT_CSR0_WDS_MASK | XWT_CSR0_EWDT1_MASK), + &platdata->regs->twcsr0); + + writel(XWT_CSRX_EWDT2_MASK, &platdata->regs->twcsr1); + + return 0; }
-void hw_watchdog_init(void) +static int xlnx_wdt_probe(struct udevice *dev) { - int ret; + debug("%s: Probing wdt%u\n", __func__, dev->seq);
- writel((XWT_CSR0_WRS_MASK | XWT_CSR0_WDS_MASK | XWT_CSR0_EWDT1_MASK), - &watchdog_base->twcsr0); - writel(XWT_CSRX_EWDT2_MASK, &watchdog_base->twcsr1); + return 0; +}
- ret = install_interrupt_handler(CONFIG_WATCHDOG_IRQ, - hw_watchdog_isr, NULL); - if (ret) - puts("Watchdog IRQ registration failed."); +static int xlnx_wdt_ofdata_to_platdata(struct udevice *dev) +{ + struct xlnx_wdt_platdata *platdata = dev_get_platdata(dev); + + platdata->regs = (struct watchdog_regs *)dev_read_addr(dev); + if (IS_ERR(platdata->regs)) + return PTR_ERR(platdata->regs); + + platdata->enable_once = dev_read_u32_default(dev, + "xlnx,wdt-enable-once", 0); + + debug("%s: wdt-enable-once %d\n", __func__, platdata->enable_once); + + return 0; } + +static const struct wdt_ops xlnx_wdt_ops = { + .start = xlnx_wdt_start, + .reset = xlnx_wdt_reset, + .stop = xlnx_wdt_stop, +}; + +static const struct udevice_id xlnx_wdt_ids[] = { + { .compatible = "xlnx,xps-timebase-wdt-1.00.a", }, + { .compatible = "xlnx,xps-timebase-wdt-1.01.a", }, + {}, +}; + +U_BOOT_DRIVER(xlnx_wdt) = { + .name = "xlnx_wdt", + .id = UCLASS_WDT, + .of_match = xlnx_wdt_ids, + .probe = xlnx_wdt_probe, + .platdata_auto_alloc_size = sizeof(struct xlnx_wdt_platdata), + .ofdata_to_platdata = xlnx_wdt_ofdata_to_platdata, + .ops = &xlnx_wdt_ops, +};

DM watchdog should be enabled by default.
Signed-off-by: Michal Simek michal.simek@xilinx.com ---
Changes in v3: - New patch
Changes in v2: None Changes in v1: None
configs/microblaze-generic_defconfig | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/configs/microblaze-generic_defconfig b/configs/microblaze-generic_defconfig index 6ba70223e292..c366a80ed628 100644 --- a/configs/microblaze-generic_defconfig +++ b/configs/microblaze-generic_defconfig @@ -56,3 +56,5 @@ CONFIG_XILINX_AXIEMAC=y CONFIG_XILINX_EMACLITE=y CONFIG_SYS_NS16550=y CONFIG_XILINX_UARTLITE=y +CONFIG_WDT=y +CONFIG_XILINX_TB_WATCHDOG=y
participants (1)
-
Michal Simek