Skip to content

dts: arm: adi: Enable RTC counter for MAX32657 #93429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions boards/adi/max32657evkit/max32657evkit_max32657.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ supported:
- dma
- counter
- pwm
- rtc_counter
- spi
ram: 256
flash: 960
5 changes: 5 additions & 0 deletions boards/adi/max32657evkit/max32657evkit_max32657_common.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <ADI_MAX32_PRPH_CLK_SRC_INRO>;
};
1 change: 1 addition & 0 deletions boards/adi/max32657evkit/max32657evkit_max32657_ns.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ supported:
- dma
- counter
- pwm
- rtc_counter
- spi
ram: 192
flash: 576
15 changes: 13 additions & 2 deletions drivers/counter/counter_max32_rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@
#include <zephyr/drivers/clock_control/adi_max32_clock_control.h>
#include <zephyr/drivers/pinctrl.h>
#include <zephyr/irq.h>
#include <zephyr/logging/log.h>

#include <rtc.h>
#include <wrap_max32_lp.h>
#include <wrap_max32_rtc.h>

LOG_MODULE_REGISTER(max32_counter_rtc, CONFIG_COUNTER_LOG_LEVEL);

/* Resoultion is 1sec for time of day alarm*/
#define MAX32_RTC_COUNTER_FREQ 1
Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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, \
Expand Down
7 changes: 7 additions & 0 deletions dts/arm/adi/max32/max32657_common.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down
15 changes: 15 additions & 0 deletions dts/bindings/counter/adi,max32-rtc-counter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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