-
Notifications
You must be signed in to change notification settings - Fork 8.3k
drivers: rtc: microchip: Add rtc driver #99144
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
base: main
Are you sure you want to change the base?
drivers: rtc: microchip: Add rtc driver #99144
Conversation
ed10fea to
5ebd07e
Compare
5ebd07e to
5ec84ac
Compare
bjarki-andreasen
left a comment
There was a problem hiding this 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.
| title: Microchip G1 RTC driver | ||
|
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
drivers/rtc/rtc_mchp_g1.c
Outdated
| #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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
drivers/rtc/rtc_mchp_g1.c
Outdated
| #endif /* CONFIG_RTC_ALARM */ | ||
|
|
||
| /* Clock configuration structure for RTC. */ | ||
| struct mchp_rtc_clock { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rtc_mchp or?
There was a problem hiding this comment.
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?
drivers/rtc/rtc_mchp_g1.c
Outdated
| (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) |
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
drivers/rtc/rtc_mchp_g1.c
Outdated
| } | ||
|
|
||
| /* Lock interrupts to ensure setting of callback */ | ||
| unsigned int key = irq_lock(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
drivers/rtc/rtc_mchp_g1.c
Outdated
| /* Perform a software reset on the RTC peripheral */ | ||
| rtc_swrst(cfg->regs); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
drivers/rtc/rtc_mchp_g1.c
Outdated
| if (ret == -EALREADY) { | ||
| ret = 0; | ||
| } |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
drivers/rtc/rtc_mchp_g1.c
Outdated
| #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); \ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
|
Please add it in this PR |
5ec84ac to
c5a914e
Compare
c5a914e to
6c90730
Compare
6c90730 to
3bf448c
Compare
| }; | ||
|
|
||
| &rtc { | ||
| compatible = "microchip,rtc-g1"; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) */ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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]>
5bbb6c8
3bf448c to
5bbb6c8
Compare
Added sam_e54_xpro.conf file Signed-off-by: farsin NASAR V A <[email protected]>
5bbb6c8 to
9f35618
Compare
|
|
The error comes from the CI script. Other recent PRs also show the same issue. eg : #99799 |



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