[U-Boot] [PATCH v4 1/4] rtc: ds3232/ds3231: Add support to generate 32KHz output for driver module
Chuanhua Han
chuanhua.han at nxp.com
Fri Jul 26 11:24:00 UTC 2019
This patch add an implementation of the rtc_enable_32khz_output() that
uses the driver model i2c APIs.
Signed-off-by: Chuanhua Han <chuanhua.han at nxp.com>
---
depends on:
- http://patchwork.ozlabs.org/project/uboot/list/?series=118772
- http://patchwork.ozlabs.org/project/uboot/list/?series=117226
Changes in v4:
- No change.
Changes in v3:
- Delete something about DS3231_BUS_NUM
- Modify the interface and definition of rtc_enable_32khz_output function
Changes in v2:
- No change.
drivers/rtc/Kconfig | 6 ++++++
drivers/rtc/ds3231.c | 17 +++++++++++++++++
include/rtc.h | 6 ++++++
3 files changed, 29 insertions(+)
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index fd0009b..cf15914 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -31,6 +31,12 @@ config TPL_DM_RTC
drivers to perform the actual functions. See rtc.h for a
description of the API.
+config RTC_ENABLE_32KHZ_OUTPUT
+ bool "Enable RTC 32Khz output"
+ help
+ Some real-time clocks support the output of 32kHz square waves (such as ds3231),
+ the config symbol choose Real Time Clock device 32Khz output feature.
+
config RTC_PCF2127
bool "Enable PCF2127 driver"
depends on DM_RTC
diff --git a/drivers/rtc/ds3231.c b/drivers/rtc/ds3231.c
index 79b026a..fde4d86 100644
--- a/drivers/rtc/ds3231.c
+++ b/drivers/rtc/ds3231.c
@@ -148,11 +148,13 @@ void rtc_reset (void)
/*
* Enable 32KHz output
*/
+#ifdef CONFIG_RTC_ENABLE_32KHZ_OUTPUT
void rtc_enable_32khz_output(void)
{
rtc_write(RTC_STAT_REG_ADDR,
RTC_STAT_BIT_BB32KHZ | RTC_STAT_BIT_EN32KHZ);
}
+#endif
/*
* Helper functions
@@ -251,6 +253,21 @@ static int ds3231_probe(struct udevice *dev)
return 0;
}
+#ifdef CONFIG_RTC_ENABLE_32KHZ_OUTPUT
+int rtc_enable_32khz_output(int busnum, int chip_addr)
+{
+ int ret;
+ struct udevice *dev;
+
+ ret = i2c_get_chip_for_busnum(busnum, chip_addr, 1, &dev);
+ if (!ret)
+ ret = dm_i2c_reg_write(dev, RTC_STAT_REG_ADDR,
+ RTC_STAT_BIT_BB32KHZ |
+ RTC_STAT_BIT_EN32KHZ);
+ return ret;
+}
+#endif
+
static const struct rtc_ops ds3231_rtc_ops = {
.get = ds3231_rtc_get,
.set = ds3231_rtc_set,
diff --git a/include/rtc.h b/include/rtc.h
index b255bdc..7386d52 100644
--- a/include/rtc.h
+++ b/include/rtc.h
@@ -166,11 +166,17 @@ int rtc_read32(struct udevice *dev, unsigned int reg, u32 *valuep);
*/
int rtc_write32(struct udevice *dev, unsigned int reg, u32 value);
+#ifdef CONFIG_RTC_ENABLE_32KHZ_OUTPUT
+int rtc_enable_32khz_output(int busnum, int chip_addr);
+#endif
+
#else
int rtc_get (struct rtc_time *);
int rtc_set (struct rtc_time *);
void rtc_reset (void);
+#ifdef CONFIG_RTC_ENABLE_32KHZ_OUTPUT
void rtc_enable_32khz_output(void);
+#endif
/**
* rtc_read8() - Read an 8-bit register
--
2.9.5
More information about the U-Boot
mailing list