Skip to contentSkip to conversation

rtc: Add fallbacks for dm functions

PATCH In review Sean Anderson 2 participants 5 messages Nov 22, 2022 – Dec 9, 2022 x86

lore
Share & tools
lore
#0 lore raw

v4 cover rtc: Add fallbacks for dm functions

This adds some fallbacks for DM RTC consumers, so they don't have to ifdef out their RTC code.

Changes in v4:
- Don't compile fsp_save_s3_stack in SPL (or TPL/VPL).

Changes in v3:
- Select SPL_DM_RTC for HAVE_FSP. Before this series, even if just DM_RTC was selected, the DM RTC functions would be forward-declared. This probably would result in funky things at runtime.

Changes in v2:
- Include linux/errno.h for ENOSYS. This is needed for some mips boards when CONFIG_BLK is enabled for whatever reason.

Sean Anderson (2):
x86: fsp: Only compile fsp_save_s3_stack if (SPL_)DM_RTC is enabled
rtc: Add fallbacks for dm functions

 arch/x86/lib/fsp/fsp_common.c |  2 ++
 include/rtc.h                 | 32 +++++++++++++++++++++++++++++---
 2 files changed, 31 insertions(+), 3 deletions(-)
Signature · 1 line
2.35.1.1320.gc452695387.dirty
#1 lore raw

PATCH v4 1/2 x86: fsp: Only compile fsp_save_s3_stack if (SPL_)DM_RTC is enabled

This function calls rtc_write32, which has a different signature depending on if (SPL_)DM_RTC is enabled or not. This could result in a mismatch in SPL if DM_RTC was enabled but SPL_DM_RTC, as the non-DM declaration would still be used in SPL even though the implementation would be for non-DM_RTC. We are switching to the correct definitions in the next commit, so this will become a compilation error. Since fsp_save_s3_stack is not called from SPL, avoid compiling it if (SPL_)DM_RTC is disabled.

---

Changes in v4:
- Don't compile fsp_save_s3_stack in SPL (or TPL/VPL).

Changes in v3:
- New

 arch/x86/lib/fsp/fsp_common.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/lib/fsp/fsp_common.c +2 -0
index 82f7d3ab5f..8f2977a807 100644
@@ -61,6 +61,7 @@ void board_final_init(void)
 		debug("OK\n");
 }
 
+#if CONFIG_IS_ENABLED(DM_RTC)
 int fsp_save_s3_stack(void)
 {
 	struct udevice *dev;
@@ -84,3 +85,4 @@ int fsp_save_s3_stack(void)
 
 	return 0;
 }
+#endif
Signature · 1 line
2.35.1.1320.gc452695387.dirty
#2 lore raw

Re: [PATCH v4 1/2] x86: fsp: Only compile fsp_save_s3_stack if (SPL_)DM_RTC is enabled

Quoted 10 lines · Sean Anderson

This function calls rtc_write32, which has a different signature depending on if (SPL_)DM_RTC is enabled or not. This could result in a mismatch in SPL if DM_RTC was enabled but SPL_DM_RTC, as the non-DM declaration would still be used in SPL even though the implementation would be for non-DM_RTC. We are switching to the correct definitions in the next commit, so this will become a compilation error. Since fsp_save_s3_stack is not called from SPL, avoid compiling it if (SPL_)DM_RTC is disabled.

Applied to u-boot/next, thanks!

Signature · 1 line
Tom
#3 lore raw

PATCH v4 2/2 rtc: Add fallbacks for dm functions

In reply to Sean Anderson

This adds fallbacks for the various dm_rtc_* functions. This allows common code to use these functions without ifdefs.

Fixes c8ce7ba87d1 ("misc: Add support for nvmem cells")

---

(no changes since v2)

Changes in v2:
- Include linux/errno.h for ENOSYS. This is needed for some mips boards when CONFIG_BLK is enabled for whatever reason.

 include/rtc.h | 32 +++++++++++++++++++++++++++++---
 1 file changed, 29 insertions(+), 3 deletions(-)
include/rtc.h +29 -3
index 10104e3bf5..b6fdbb60dc 100644
@@ -15,13 +15,12 @@
 
 #include <bcd.h>
 #include <rtc_def.h>
+#include <linux/errno.h>
 
 typedef int64_t time64_t;
-
-#ifdef CONFIG_DM_RTC
-
 struct udevice;
 
+#if CONFIG_IS_ENABLED(DM_RTC)
 struct rtc_ops {
 	/**
 	 * get() - get the current time
@@ -222,6 +221,33 @@ int rtc_enable_32khz_output(int busnum, int chip_addr);
 #endif
 
 #else
+static inline int dm_rtc_get(struct udevice *dev, struct rtc_time *time)
+{
+	return -ENOSYS;
+}
+
+static inline int dm_rtc_set(struct udevice *dev, struct rtc_time *time)
+{
+	return -ENOSYS;
+}
+
+static inline int dm_rtc_reset(struct udevice *dev)
+{
+	return -ENOSYS;
+}
+
+static inline int dm_rtc_read(struct udevice *dev, unsigned int reg, u8 *buf,
+			      unsigned int len)
+{
+	return -ENOSYS;
+}
+
+static inline int dm_rtc_write(struct udevice *dev, unsigned int reg,
+			       const u8 *buf, unsigned int len)
+{
+	return -ENOSYS;
+}
+
 int rtc_get (struct rtc_time *);
 int rtc_set (struct rtc_time *);
 void rtc_reset (void);
Signature · 1 line
2.35.1.1320.gc452695387.dirty