From dc6fa20b6f75caf1a1eb1c55d185154444798bdf Mon Sep 17 00:00:00 2001 From: Mert Vatansever Date: Mon, 23 Dec 2024 20:25:28 +0300 Subject: [PATCH 1/5] dts: bindings: rtc: Add clock source to rtc for MAX32xxx This commit adds clock source to rtc properties for MAX32xxx. Signed-off-by: Mert Vatansever --- dts/bindings/counter/adi,max32-rtc-counter.yaml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/dts/bindings/counter/adi,max32-rtc-counter.yaml b/dts/bindings/counter/adi,max32-rtc-counter.yaml index 9b1058545fb93..9bb7dcc34ee5b 100644 --- a/dts/bindings/counter/adi,max32-rtc-counter.yaml +++ b/dts/bindings/counter/adi,max32-rtc-counter.yaml @@ -7,3 +7,18 @@ description: ADI MAX32 compatible Counter RTC compatible: "adi,max32-rtc-counter" include: [base.yaml] + +properties: + reg: + required: true + + clock-source: + type: int + enum: [4, 5] + description: | + Clock source to be used by the RTC peripheral. The following options + are available: + - 4: "ADI_MAX32_PRPH_CLK_SRC_ERTCO" External Real-Time Clock Oscillator + - 5: "ADI_MAX32_PRPH_CLK_SRC_INRO" Internal Ring Oscillator + The target device might not support all option please take a look on + target device user guide From e904ba5251615da312dc95946ae08ae5820ac845 Mon Sep 17 00:00:00 2001 From: Tahsin Mutlugun Date: Thu, 2 Jan 2025 18:59:03 +0300 Subject: [PATCH 2/5] drivers: counter: max32_rtc: Add clock source selection support Add clock source selection support by applying changes introduced in 41a0ba7. Signed-off-by: Tahsin Mutlugun --- drivers/counter/counter_max32_rtc.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/counter/counter_max32_rtc.c b/drivers/counter/counter_max32_rtc.c index 832a1394508cf..d0e8af2ca7f7c 100644 --- a/drivers/counter/counter_max32_rtc.c +++ b/drivers/counter/counter_max32_rtc.c @@ -10,9 +10,13 @@ #include #include #include +#include #include #include +#include + +LOG_MODULE_REGISTER(max32_counter_rtc, CONFIG_COUNTER_LOG_LEVEL); /* Resoultion is 1sec for time of day alarm*/ #define MAX32_RTC_COUNTER_FREQ 1 @@ -34,6 +38,7 @@ struct max32_rtc_config { struct counter_config_info info; mxc_rtc_regs_t *regs; void (*irq_func)(void); + struct max32_perclk perclk; }; static int api_start(const struct device *dev) @@ -207,10 +212,14 @@ static void rtc_max32_isr(const struct device *dev) static int rtc_max32_init(const struct device *dev) { + int ret; const struct max32_rtc_config *cfg = dev->config; - while (MXC_RTC_Init(0, 0) == E_BUSY) { - ; + while ((ret = Wrap_MXC_RTC_Init(0, 0, cfg->perclk.clk_src)) != E_SUCCESS) { + if (ret < 0) { + LOG_ERR("RTC does not support this clock source."); + return -ENOTSUP; + } } api_stop(dev); @@ -252,6 +261,8 @@ static DEVICE_API(counter, counter_rtc_max32_driver_api) = { }, \ .regs = (mxc_rtc_regs_t *)DT_INST_REG_ADDR(_num), \ .irq_func = max32_rtc_irq_init_##_num, \ + .perclk.clk_src = \ + DT_INST_PROP_OR(_num, clock_source, ADI_MAX32_PRPH_CLK_SRC_ERTCO), \ }; \ \ DEVICE_DT_INST_DEFINE(_num, &rtc_max32_init, NULL, &rtc_max32_data_##_num, \ From 66755ecfb1742766107e8ee23c66b51e3b0cd76a Mon Sep 17 00:00:00 2001 From: Sadik Ozer Date: Thu, 8 Aug 2024 13:41:01 +0300 Subject: [PATCH 3/5] dts: arm: adi: Add RTC device node Add MAX32657 RTC device node Signed-off-by: Sadik Ozer --- dts/arm/adi/max32/max32657_common.dtsi | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/dts/arm/adi/max32/max32657_common.dtsi b/dts/arm/adi/max32/max32657_common.dtsi index bc5b70b651c80..fbd223a410952 100644 --- a/dts/arm/adi/max32/max32657_common.dtsi +++ b/dts/arm/adi/max32/max32657_common.dtsi @@ -269,6 +269,13 @@ }; }; + rtc_counter: rtc_counter@6000 { + compatible = "adi,max32-rtc-counter"; + reg = <0x6000 0x400>; + interrupts = <2 0>; + status = "disabled"; + }; + spi0: spi@46000 { compatible = "adi,max32-spi"; reg = <0x46000 0x1000>; From 346abe8ef840de648503ab6e2e7c0d6f6021a41b Mon Sep 17 00:00:00 2001 From: Mert Vatansever Date: Mon, 23 Dec 2024 20:29:16 +0300 Subject: [PATCH 4/5] boards: adi: Enable RTC for MAX32657EVKit This commit enables RTC for MAX32657EVKit. Signed-off-by: Mert Vatansever --- boards/adi/max32657evkit/max32657evkit_max32657.dts | 5 +++++ boards/adi/max32657evkit/max32657evkit_max32657.yaml | 1 + 2 files changed, 6 insertions(+) diff --git a/boards/adi/max32657evkit/max32657evkit_max32657.dts b/boards/adi/max32657evkit/max32657evkit_max32657.dts index 7cee4e1127711..f0fd23fcb1ad6 100644 --- a/boards/adi/max32657evkit/max32657evkit_max32657.dts +++ b/boards/adi/max32657evkit/max32657evkit_max32657.dts @@ -50,3 +50,8 @@ &trng { status = "okay"; }; + +&rtc_counter { + status = "okay"; + clock-source = ; +}; diff --git a/boards/adi/max32657evkit/max32657evkit_max32657.yaml b/boards/adi/max32657evkit/max32657evkit_max32657.yaml index 4d351c9c0555a..ffb7e9e4ffb58 100644 --- a/boards/adi/max32657evkit/max32657evkit_max32657.yaml +++ b/boards/adi/max32657evkit/max32657evkit_max32657.yaml @@ -14,6 +14,7 @@ supported: - dma - counter - pwm + - rtc_counter - spi ram: 256 flash: 960 From 4a1a2474e255c8b9e284c1e8f74757ed290e4b3c Mon Sep 17 00:00:00 2001 From: Tahsin Mutlugun Date: Thu, 2 Jan 2025 18:54:19 +0300 Subject: [PATCH 5/5] boards: adi: Enable RTC for MAX32657EVKIT nonsecure board Add RTC to MAX32657EVKIT nonsecure configuration. Signed-off-by: Tahsin Mutlugun --- boards/adi/max32657evkit/max32657evkit_max32657.dts | 5 ----- boards/adi/max32657evkit/max32657evkit_max32657_common.dtsi | 5 +++++ boards/adi/max32657evkit/max32657evkit_max32657_ns.yaml | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/boards/adi/max32657evkit/max32657evkit_max32657.dts b/boards/adi/max32657evkit/max32657evkit_max32657.dts index f0fd23fcb1ad6..7cee4e1127711 100644 --- a/boards/adi/max32657evkit/max32657evkit_max32657.dts +++ b/boards/adi/max32657evkit/max32657evkit_max32657.dts @@ -50,8 +50,3 @@ &trng { status = "okay"; }; - -&rtc_counter { - status = "okay"; - clock-source = ; -}; diff --git a/boards/adi/max32657evkit/max32657evkit_max32657_common.dtsi b/boards/adi/max32657evkit/max32657evkit_max32657_common.dtsi index 17f5bf9125475..306f3d973e555 100644 --- a/boards/adi/max32657evkit/max32657evkit_max32657_common.dtsi +++ b/boards/adi/max32657evkit/max32657evkit_max32657_common.dtsi @@ -71,3 +71,8 @@ pinctrl-0 = <&spi0_mosi_p0_2 &spi0_miso_p0_4 &spi0_sck_p0_6 &spi0_ss0_p0_3>; pinctrl-names = "default"; }; + +&rtc_counter { + status = "okay"; + clock-source = ; +}; diff --git a/boards/adi/max32657evkit/max32657evkit_max32657_ns.yaml b/boards/adi/max32657evkit/max32657evkit_max32657_ns.yaml index b8323e5aca877..fc80cba6625d7 100644 --- a/boards/adi/max32657evkit/max32657evkit_max32657_ns.yaml +++ b/boards/adi/max32657evkit/max32657evkit_max32657_ns.yaml @@ -13,6 +13,7 @@ supported: - dma - counter - pwm + - rtc_counter - spi ram: 192 flash: 576