diff --git a/drivers/rtc/rtc_mc146818.c b/drivers/rtc/rtc_mc146818.c index 9f603304aec..6ecdfafa634 100644 --- a/drivers/rtc/rtc_mc146818.c +++ b/drivers/rtc/rtc_mc146818.c @@ -113,6 +113,11 @@ #define MIN_YEAR_DIFF 0 /* YEAR - 1900 */ #define MAX_YEAR_DIFF 99 /* YEAR - 1999 */ +/* Input clock frequency mapped to divider bits */ +#define RTC_IN_CLK_DIV_BITS_4194304 (0) +#define RTC_IN_CLK_DIV_BITS_1048576 (1 << 4) +#define RTC_IN_CLK_DIV_BITS_32768 (2 << 4) + struct rtc_mc146818_data { struct k_spinlock lock; bool alarm_pending; @@ -509,7 +514,10 @@ struct rtc_driver_api rtc_mc146818_driver_api = { #define RTC_MC146818_INIT_FN_DEFINE(n) \ static int rtc_mc146818_init##n(const struct device *dev) \ { \ - rtc_write(RTC_REG_A, 0); \ + rtc_write(RTC_REG_A, \ + _CONCAT(RTC_IN_CLK_DIV_BITS_, \ + DT_INST_PROP(n, clock_frequency))); \ + \ rtc_write(RTC_REG_B, RTC_DMODE_BIT | RTC_HFORMAT_BIT); \ \ IRQ_CONNECT(DT_INST_IRQN(0), \ diff --git a/dts/bindings/rtc/motorola,mc146818.yaml b/dts/bindings/rtc/motorola,mc146818.yaml index 11fd987ab58..7974c1d68c3 100644 --- a/dts/bindings/rtc/motorola,mc146818.yaml +++ b/dts/bindings/rtc/motorola,mc146818.yaml @@ -7,3 +7,13 @@ description: Motorola MC146818 compatible Real Timer Clock compatible: "motorola,mc146818" include: rtc-device.yaml + +properties: + clock-frequency: + type: int + default: 32768 + enum: + - 4194304 + - 1048576 + - 32768 + description: Frequency of the input-clock in Hertz (Hz)