From d9e4f8fa1dde7623c0072da11396e37228debd02 Mon Sep 17 00:00:00 2001 From: Sreeram Tatapudi Date: Fri, 5 May 2023 16:57:21 -0700 Subject: [PATCH] drivers: watchdog: Driver for Infineon watchdog Initial version of the driver for Infineon CAT1 devices Signed-off-by: Sreeram Tatapudi --- CODEOWNERS | 1 + .../cy8cproto_062_4343w.dts | 5 + .../cy8cproto_063_ble/cy8cproto_063_ble.dts | 5 + .../cy8cproto_063_ble/cy8cproto_063_ble.yaml | 1 + drivers/watchdog/CMakeLists.txt | 1 + drivers/watchdog/Kconfig | 2 + drivers/watchdog/Kconfig.ifx_cat1 | 14 ++ drivers/watchdog/wdt_ifx_cat1.c | 142 ++++++++++++++++++ dts/arm/infineon/psoc6/psoc6_01/psoc6_01.dtsi | 2 +- dts/arm/infineon/psoc6/psoc6_02/psoc6_02.dtsi | 7 + .../watchdog/infineon,cat1-watchdog.yaml | 14 ++ modules/hal_infineon/Kconfig | 6 + .../hal_infineon/mtb-hal-cat1/CMakeLists.txt | 1 + .../hal_infineon/mtb-pdl-cat1/CMakeLists.txt | 1 + 14 files changed, 201 insertions(+), 1 deletion(-) create mode 100644 drivers/watchdog/Kconfig.ifx_cat1 create mode 100644 drivers/watchdog/wdt_ifx_cat1.c create mode 100644 dts/bindings/watchdog/infineon,cat1-watchdog.yaml diff --git a/CODEOWNERS b/CODEOWNERS index f719cbb6d3..f78b2762f3 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -474,6 +474,7 @@ /drivers/watchdog/wdt_counter.c @nordic-krch /drivers/watchdog/*rpi_pico* @thedjnK /drivers/watchdog/*dw* @softwarecki +/drivers/watchdog/*ifx* @sreeramIfx /drivers/wifi/ @rlubos @tbursztyka /drivers/wifi/esp_at/ @mniestroj /drivers/wifi/eswifi/ @loicpoulain @nandojve diff --git a/boards/arm/cy8cproto_062_4343w/cy8cproto_062_4343w.dts b/boards/arm/cy8cproto_062_4343w/cy8cproto_062_4343w.dts index f4a7aad4ba..9c2ba3b345 100644 --- a/boards/arm/cy8cproto_062_4343w/cy8cproto_062_4343w.dts +++ b/boards/arm/cy8cproto_062_4343w/cy8cproto_062_4343w.dts @@ -16,6 +16,7 @@ aliases { uart-5 = &uart5; i2c-0 = &i2c3; + watchdog0 = &watchdog0; }; chosen { @@ -102,3 +103,7 @@ i2c3: &scb3 { pinctrl-0 = <&p6_0_scb3_i2c_scl &p6_1_scb3_i2c_sda>; pinctrl-names = "default"; }; + +&watchdog0 { + status = "okay"; +}; diff --git a/boards/arm/cy8cproto_063_ble/cy8cproto_063_ble.dts b/boards/arm/cy8cproto_063_ble/cy8cproto_063_ble.dts index 331af88942..449ed03abf 100644 --- a/boards/arm/cy8cproto_063_ble/cy8cproto_063_ble.dts +++ b/boards/arm/cy8cproto_063_ble/cy8cproto_063_ble.dts @@ -18,6 +18,7 @@ uart-5 = &uart5; led0 = &user_led; sw0 = &user_bt; + watchdog0 = &watchdog0; }; chosen { @@ -120,3 +121,7 @@ uart5: &scb5 { &bluetooth { status = "okay"; }; + +&watchdog0 { + status = "okay"; +}; diff --git a/boards/arm/cy8cproto_063_ble/cy8cproto_063_ble.yaml b/boards/arm/cy8cproto_063_ble/cy8cproto_063_ble.yaml index d0e42303aa..ba6ceaa0f0 100644 --- a/boards/arm/cy8cproto_063_ble/cy8cproto_063_ble.yaml +++ b/boards/arm/cy8cproto_063_ble/cy8cproto_063_ble.yaml @@ -17,3 +17,4 @@ supported: - gpio - uart - i2c + - watchdog diff --git a/drivers/watchdog/CMakeLists.txt b/drivers/watchdog/CMakeLists.txt index b96db0278c..f7a00aae20 100644 --- a/drivers/watchdog/CMakeLists.txt +++ b/drivers/watchdog/CMakeLists.txt @@ -33,6 +33,7 @@ zephyr_library_sources_ifdef(CONFIG_WDT_NXP_S32 wdt_nxp_s32.c) zephyr_library_sources_ifdef(CONFIG_WDT_SMARTBOND wdt_smartbond.c) zephyr_library_sources_ifdef(CONFIG_WDT_TI_TPS382X wdt_ti_tps382x.c) zephyr_library_sources_ifdef(CONFIG_WDT_XILINX_AXI wdt_xilinx_axi.c) +zephyr_library_sources_ifdef(CONFIG_WDT_INFINEON_CAT1 wdt_ifx_cat1.c) zephyr_library_sources_ifdef(CONFIG_WDT_DW wdt_dw.c wdt_dw_common.c) zephyr_library_sources_ifdef(CONFIG_WDT_INTEL_ADSP wdt_intel_adsp.c wdt_dw_common.c) diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index 8bec6eed73..96f3248cd5 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -106,4 +106,6 @@ source "drivers/watchdog/Kconfig.tco" source "drivers/watchdog/Kconfig.xlnx" +source "drivers/watchdog/Kconfig.ifx_cat1" + endif # WATCHDOG diff --git a/drivers/watchdog/Kconfig.ifx_cat1 b/drivers/watchdog/Kconfig.ifx_cat1 new file mode 100644 index 0000000000..94150064f8 --- /dev/null +++ b/drivers/watchdog/Kconfig.ifx_cat1 @@ -0,0 +1,14 @@ +# Infineon CAT1 Watchdog configuration options + +# Copyright (c) 2023 Cypress Semiconductor Corporation (an Infineon company) or +# an affiliate of Cypress Semiconductor Corporation +# +# SPDX-License-Identifier: Apache-2.0 + +config WDT_INFINEON_CAT1 + bool "Infineon CAT1 Watchdog Driver" + default y + depends on DT_HAS_INFINEON_CAT1_WATCHDOG_ENABLED + select USE_INFINEON_WDT + help + Enable Watchdog driver for Infineon CAT1 devices. diff --git a/drivers/watchdog/wdt_ifx_cat1.c b/drivers/watchdog/wdt_ifx_cat1.c new file mode 100644 index 0000000000..3cfe41d4a3 --- /dev/null +++ b/drivers/watchdog/wdt_ifx_cat1.c @@ -0,0 +1,142 @@ +/* + * Copyright 2023 Cypress Semiconductor Corporation (an Infineon company) or + * an affiliate of Cypress Semiconductor Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#define DT_DRV_COMPAT infineon_cat1_watchdog + +#include "cyhal_wdt.h" + +#include +#include +#include +#include +LOG_MODULE_REGISTER(wdt_infineon_cat1, CONFIG_WDT_LOG_LEVEL); + +#define IFX_CAT1_WDT_IS_IRQ_EN DT_NODE_HAS_PROP(DT_DRV_INST(0), interrupts) + +struct ifx_cat1_wdt_data { + cyhal_wdt_t obj; +#ifdef IFX_CAT1_WDT_IS_IRQ_EN + wdt_callback_t callback; +#endif /* IFX_CAT1_WDT_IS_IRQ_EN */ + uint32_t timeout; + bool timeout_installed; +}; + +struct ifx_cat1_wdt_data wdt_data; + +#ifdef IFX_CAT1_WDT_IS_IRQ_EN +static void ifx_cat1_wdt_isr_handler(const struct device *dev) +{ + struct ifx_cat1_wdt_data *dev_data = dev->data; + + if (dev_data->callback) { + dev_data->callback(dev, 0); + } +} +#endif /* IFX_CAT1_WDT_IS_IRQ_EN */ + +static int ifx_cat1_wdt_setup(const struct device *dev, uint8_t options) +{ + cy_rslt_t result; + struct ifx_cat1_wdt_data *dev_data = dev->data; + + /* Initialize the WDT */ + result = cyhal_wdt_init(&dev_data->obj, dev_data->timeout); + if (result != CY_RSLT_SUCCESS) { + LOG_ERR("Initialization failure : 0x%x", result); + return -ENOMSG; + } + +#ifdef IFX_CAT1_WDT_IS_IRQ_EN + if (dev_data->callback) { + Cy_WDT_UnmaskInterrupt(); + irq_enable(DT_INST_IRQN(0)); + } +#endif /* IFX_CAT1_WDT_IS_IRQ_EN */ + + return 0; +} + +static int ifx_cat1_wdt_disable(const struct device *dev) +{ + struct ifx_cat1_wdt_data *dev_data = dev->data; + +#ifdef IFX_CAT1_WDT_IS_IRQ_EN + Cy_WDT_MaskInterrupt(); + irq_disable(DT_INST_IRQN(0)); +#endif /* IFX_CAT1_WDT_IS_IRQ_EN */ + + cyhal_wdt_free(&dev_data->obj); + + return 0; +} + +static int ifx_cat1_wdt_install_timeout(const struct device *dev, const struct wdt_timeout_cfg *cfg) +{ + struct ifx_cat1_wdt_data *dev_data = dev->data; + + if (dev_data->timeout_installed) { + LOG_ERR("No more timeouts can be installed"); + return -ENOMEM; + } + + if (cfg->flags) { + LOG_WRN("Watchdog behavior is not configurable."); + } + + if (cfg->callback) { +#ifndef IFX_CAT1_WDT_IS_IRQ_EN + LOG_WRN("Interrupt is not configured, can't set a callback."); +#else + dev_data->callback = cfg->callback; +#endif /* IFX_CAT1_WDT_IS_IRQ_EN */ + } + + /* window watchdog not supported */ + if (cfg->window.min != 0U || cfg->window.max == 0U) { + return -EINVAL; + } + + dev_data->timeout = cfg->window.max; + + return 0; +} + +static int ifx_cat1_wdt_feed(const struct device *dev, int channel_id) +{ + struct ifx_cat1_wdt_data *data = dev->data; + + /* Only channel 0 is supported */ + if (channel_id) { + return -EINVAL; + } + + cyhal_wdt_kick(&data->obj); + + return 0; +} + +static int ifx_cat1_wdt_init(const struct device *dev) +{ +#ifdef IFX_CAT1_WDT_IS_IRQ_EN + /* Connect WDT interrupt to ISR */ + IRQ_CONNECT(DT_INST_IRQN(0), DT_INST_IRQ(0, priority), ifx_cat1_wdt_isr_handler, + DEVICE_DT_INST_GET(0), 0); +#endif /* IFX_CAT1_WDT_IS_IRQ_EN */ + + return 0; +} + +static const struct wdt_driver_api ifx_cat1_wdt_api = { + .setup = ifx_cat1_wdt_setup, + .disable = ifx_cat1_wdt_disable, + .install_timeout = ifx_cat1_wdt_install_timeout, + .feed = ifx_cat1_wdt_feed, +}; + +DEVICE_DT_INST_DEFINE(0, ifx_cat1_wdt_init, NULL, &wdt_data, NULL, POST_KERNEL, + CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &ifx_cat1_wdt_api); diff --git a/dts/arm/infineon/psoc6/psoc6_01/psoc6_01.dtsi b/dts/arm/infineon/psoc6/psoc6_01/psoc6_01.dtsi index 933937e18e..975cc988f0 100644 --- a/dts/arm/infineon/psoc6/psoc6_01/psoc6_01.dtsi +++ b/dts/arm/infineon/psoc6/psoc6_01/psoc6_01.dtsi @@ -299,7 +299,7 @@ status = "disabled"; }; - watchdog@40260180 { + watchdog0: watchdog@40260180 { compatible = "infineon,cat1-watchdog"; reg = <0x40260180 0xc>; interrupts = <22 6>; diff --git a/dts/arm/infineon/psoc6/psoc6_02/psoc6_02.dtsi b/dts/arm/infineon/psoc6/psoc6_02/psoc6_02.dtsi index 17d60806a5..3437420b10 100644 --- a/dts/arm/infineon/psoc6/psoc6_02/psoc6_02.dtsi +++ b/dts/arm/infineon/psoc6/psoc6_02/psoc6_02.dtsi @@ -310,5 +310,12 @@ status = "disabled"; #io-channel-cells = <1>; }; + + watchdog0: watchdog@40260180 { + compatible = "infineon,cat1-watchdog"; + reg = <0x40260180 0xc>; + interrupts = <22 6>; + status = "disabled"; + }; }; }; diff --git a/dts/bindings/watchdog/infineon,cat1-watchdog.yaml b/dts/bindings/watchdog/infineon,cat1-watchdog.yaml new file mode 100644 index 0000000000..029bea50ee --- /dev/null +++ b/dts/bindings/watchdog/infineon,cat1-watchdog.yaml @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Cypress Semiconductor Corporation (an Infineon company) or +# an affiliate of Cypress Semiconductor Corporation +# +# SPDX-License-Identifier: Apache-2.0 + +description: Infineon CAT1 Watchdog + +compatible: "infineon,cat1-watchdog" + +include: base.yaml + +properties: + reg: + required: true diff --git a/modules/hal_infineon/Kconfig b/modules/hal_infineon/Kconfig index 84ba8efe2f..0522c96769 100644 --- a/modules/hal_infineon/Kconfig +++ b/modules/hal_infineon/Kconfig @@ -60,6 +60,12 @@ config USE_INFINEON_PWM Enable Pulse Width Modulator (PWM) HAL module driver for Infineon devices +config USE_INFINEON_WDT + bool + help + Enable WATCHDOG TIMER (WDT) HAL module + driver for Infineon devices + config ABSTRACTION_RTOS_COMPONENT_ZEPHYR bool "Abstraction RTOS component (Zephyr support)" default n diff --git a/modules/hal_infineon/mtb-hal-cat1/CMakeLists.txt b/modules/hal_infineon/mtb-hal-cat1/CMakeLists.txt index 800fb35e28..dcd78ee84f 100644 --- a/modules/hal_infineon/mtb-hal-cat1/CMakeLists.txt +++ b/modules/hal_infineon/mtb-hal-cat1/CMakeLists.txt @@ -78,6 +78,7 @@ zephyr_library_sources_ifdef(CONFIG_USE_INFINEON_SPI ${hal_psoc6_dir}/source zephyr_library_sources_ifdef(CONFIG_USE_INFINEON_TIMER ${hal_psoc6_dir}/source/cyhal_timer.c) zephyr_library_sources_ifdef(CONFIG_USE_INFINEON_TRNG ${hal_psoc6_dir}/source/cyhal_trng.c) zephyr_library_sources_ifdef(CONFIG_USE_INFINEON_UART ${hal_psoc6_dir}/source/cyhal_uart.c) +zephyr_library_sources_ifdef(CONFIG_USE_INFINEON_WDT ${hal_psoc6_dir}/source/cyhal_wdt.c) if(CONFIG_USE_INFINEON_ADC) diff --git a/modules/hal_infineon/mtb-pdl-cat1/CMakeLists.txt b/modules/hal_infineon/mtb-pdl-cat1/CMakeLists.txt index 7b30d8bd01..4ab1c2bb3d 100644 --- a/modules/hal_infineon/mtb-pdl-cat1/CMakeLists.txt +++ b/modules/hal_infineon/mtb-pdl-cat1/CMakeLists.txt @@ -36,6 +36,7 @@ zephyr_library_sources_ifdef(CONFIG_USE_INFINEON_SPI ${pdl_drv_dir}/source/ zephyr_library_sources_ifdef(CONFIG_USE_INFINEON_TIMER ${pdl_drv_dir}/source/cy_tcpwm_counter.c) zephyr_library_sources_ifdef(CONFIG_USE_INFINEON_UART ${pdl_drv_dir}/source/cy_scb_uart.c) zephyr_library_sources_ifdef(CONFIG_USE_INFINEON_FLASH ${pdl_drv_dir}/source/cy_flash.c) +zephyr_library_sources_ifdef(CONFIG_USE_INFINEON_WDT ${pdl_drv_dir}/source/cy_wdt.c) if(CONFIG_USE_INFINEON_TRNG) zephyr_library_sources(${pdl_drv_dir}/source/cy_crypto.c)