Skip to content

Conversation

@Farsin-Nasar-Microchip
Copy link
Contributor

@Farsin-Nasar-Microchip Farsin-Nasar-Microchip commented Nov 10, 2025

Add rtc driver for Microchip RTC G1.
Add the device tree node and the binding file for microchip RTC G1.
Add RTC node in sam_e54_xpro.dts
Update sam_e54_xpro.yaml to reflect RTC G1 support on the board.
Added sam_e54_xpro.conf file for test

Copy link
Contributor

@bjarki-andreasen bjarki-andreasen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add this board to the rtc test suite and run it.

Comment on lines +4 to +5
title: Microchip G1 RTC driver

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Belongs in the previous commit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Comment on lines 26 to 28
#define RTC_DATA_LOCK_INIT(p_lock) k_mutex_init(p_lock)
#define RTC_DATA_LOCK(p_lock) k_mutex_lock(p_lock, K_FOREVER)
#define RTC_DATA_UNLOCK(p_lock) k_mutex_unlock(p_lock)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should not be defines, its just as short and clearer to just write the actual line

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, use semaphores for locking, mutexes are only needed if tracking thread ownership is needed, like for condvar

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

#endif /* CONFIG_RTC_ALARM */

/* Clock configuration structure for RTC. */
struct mchp_rtc_clock {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rtc_mchp or?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @bjarki-andreasen for your review. Do you mean the structure name should be changed to rtc_mchp_clock or something similar?

(dataClockCalendar & RTC_MODE2_CLOCK_DAY_Msk) >> RTC_MODE2_CLOCK_DAY_Pos;
}

static bool rtc_validate_rtc_clock_time(const struct rtc_time *rtc_clock_time)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use rtc_utils_validate_rtc_time()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

}

/* Lock interrupts to ensure setting of callback */
unsigned int key = irq_lock();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The zephyr way of doing a critical section is with a spinlock, though since this lock looks like it is only preventing concurrent access from threads, use a mutex/sem for locking?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the code to use a semaphore

Comment on lines 870 to 871
/* Perform a software reset on the RTC peripheral */
rtc_swrst(cfg->regs);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this action reset the time of the rtc? RTCs are supposed to survive a reboot, and any other event which does not physically take away power if possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the information. I have updated the code and removed the rtc_swrst

Comment on lines 887 to 889
if (ret == -EALREADY) {
ret = 0;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be moved up to right after ret is set, makes it easier to see why ret == -EALREADY is ok

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@albertofloyd albertofloyd removed their request for review November 10, 2025 18:33
@nandojve nandojve added this to the v4.4.0 milestone Nov 10, 2025
Comment on lines 928 to 955
#ifdef CONFIG_RTC_ALARM
#define RTC_MCHP_IRQ_HANDLER(n) \
static void rtc_mchp_irq_config_##n(const struct device *dev) \
{ \
RTC_MCHP_IRQ_CONNECT(n, 0); \
}
#endif /* CONFIG_RTC_ALARM */

/* RTC driver configuration structure for instance n */
/* clang-format off */
#define RTC_MCHP_CONFIG_DEFN(n) \
static const struct rtc_mchp_dev_config rtc_mchp_dev_config_##n = { \
.regs = (rtc_registers_t *)DT_INST_REG_ADDR(n), \
.prescaler = DT_INST_ENUM_IDX(n, prescaler), \
IF_ENABLED(CONFIG_RTC_ALARM, ( \
.alarms_count = DT_INST_PROP(n, alarms_count), \
.irq_config_func = &rtc_mchp_irq_config_##n,)) \
IF_ENABLED(CONFIG_RTC_CALIBRATION, ( \
.cal_constant = DT_INST_PROP(n, cal_constant),)) \
RTC_MCHP_CLOCK_DEFN(n) \
}
/* clang-format on */
/* Define and initialize the RTC device. */
#define RTC_MCHP_DEVICE_INIT(n) \
IF_ENABLED(CONFIG_RTC_ALARM, ( \
static void rtc_mchp_irq_config_##n(const struct device *dev); \
)) \
RTC_MCHP_CONFIG_DEFN(n); \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

backslash are not align in the right in some places.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@Farsin-Nasar-Microchip
Copy link
Contributor Author

Farsin-Nasar-Microchip commented Nov 13, 2025

Please add this board to the rtc test suite and run it.
Hi @bjarki-andreasen, Should I create a separate PR to add this board to the RTC test suite?, I have already run it locally.

@bjarki-andreasen
Copy link
Contributor

Please add this board to the rtc test suite and run it.

Hi @bjarki-andreasen, Should I create a separate PR to add this board to the RTC test suite?, I have already run it locally.

Please add it in this PR

@zephyrbot zephyrbot added the area: Tests Issues related to a particular existing or missing test label Nov 17, 2025
@zephyrbot zephyrbot requested a review from nashif November 17, 2025 06:18
NhMchp
NhMchp previously approved these changes Nov 17, 2025
ArunMCHP
ArunMCHP previously approved these changes Nov 20, 2025
NhMchp
NhMchp previously approved these changes Nov 20, 2025
};

&rtc {
compatible = "microchip,rtc-g1";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you defining again the compatible inside the board ?
Usually in the board, the user should define the values that are necessary. The compatible should be in the dts/arm/microchip/sam/sam_d5x_e5x/common/samd5xe5x.dtsi.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed the redundant compatible string from the board DTS.

compatible = "microchip,rtc-g1";
prescaler = <1024>;
alarms-count = <2>;
cal-constant = <1048576>; /* (8192 * 128 = 1048576) */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with this constant. User should not know about this if it never changes. This means that is should be defined at dts/arm/microchip/sam/sam_d5x_e5x/common/samd5xe5x.dtsi.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated accordingly

Add the device tree node and the binding file for
microchip RTC G1 IP.

Signed-off-by: farsin NASAR V A <[email protected]>
Add rtc driver for Microchip RTC G1.

Signed-off-by: Farsin Nasar V A <[email protected]>
Add RTC node in sam_e54_xpro.dts
Update sam_e54_xpro.yaml to reflect RTC G1 support on the board.

Signed-off-by: farsin NASAR V A <[email protected]>
Added sam_e54_xpro.conf file

Signed-off-by: farsin NASAR V A <[email protected]>
@sonarqubecloud
Copy link

@Farsin-Nasar-Microchip
Copy link
Contributor Author

The error comes from the CI script. Other recent PRs also show the same issue. eg : #99799

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Boards/SoCs area: Devicetree Bindings area: RTC Real Time Clock area: Tests Issues related to a particular existing or missing test platform: Microchip MEC Microchip MEC Platform platform: Microchip SAM Microchip SAM Platform (formerly Atmel SAM)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants