Skip to content
Snippets Groups Projects
Commit c79e1c1c authored by Andy Fleming's avatar Andy Fleming Committed by York Sun
Browse files

rtc: Add MCP79411 support to DS1307 rtc driver


The code is from Adrian Cox, and is patterned after similar
support in Linux (drivers/rtc/rtc-ds1307.c:1121-1135). This
chip is used on the Cyrus board from Varisys.

Signed-off-by: default avatarAndy Fleming <afleming@gmail.com>
Reviewed-by: default avatarYork Sun <yorksun@freescale.com>
parent 83bf0057
No related branches found
No related tags found
No related merge requests found
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
# #
# SPDX-License-Identifier: GPL-2.0+ # SPDX-License-Identifier: GPL-2.0+
# #
#ccflags-y += -DDEBUG #ccflags-y += -DDEBUG
obj-$(CONFIG_DM_RTC) += rtc-uclass.o obj-$(CONFIG_DM_RTC) += rtc-uclass.o
...@@ -37,6 +36,7 @@ obj-$(CONFIG_RTC_M48T35A) += m48t35ax.o ...@@ -37,6 +36,7 @@ obj-$(CONFIG_RTC_M48T35A) += m48t35ax.o
obj-$(CONFIG_RTC_MAX6900) += max6900.o obj-$(CONFIG_RTC_MAX6900) += max6900.o
obj-$(CONFIG_RTC_MC13XXX) += mc13xxx-rtc.o obj-$(CONFIG_RTC_MC13XXX) += mc13xxx-rtc.o
obj-$(CONFIG_RTC_MC146818) += mc146818.o obj-$(CONFIG_RTC_MC146818) += mc146818.o
obj-$(CONFIG_RTC_MCP79411) += ds1307.o
obj-$(CONFIG_MCFRTC) += mcfrtc.o obj-$(CONFIG_MCFRTC) += mcfrtc.o
obj-$(CONFIG_RTC_MK48T59) += mk48t59.o obj-$(CONFIG_RTC_MK48T59) += mk48t59.o
obj-$(CONFIG_RTC_MPC5200) += mpc5xxx.o obj-$(CONFIG_RTC_MPC5200) += mpc5xxx.o
......
...@@ -58,6 +58,10 @@ ...@@ -58,6 +58,10 @@
#define RTC_CTL_BIT_SQWE 0x10 /* Square Wave Enable */ #define RTC_CTL_BIT_SQWE 0x10 /* Square Wave Enable */
#define RTC_CTL_BIT_OUT 0x80 /* Output Control */ #define RTC_CTL_BIT_OUT 0x80 /* Output Control */
/* MCP7941X-specific bits */
#define MCP7941X_BIT_ST 0x80
#define MCP7941X_BIT_VBATEN 0x08
static uchar rtc_read (uchar reg); static uchar rtc_read (uchar reg);
static void rtc_write (uchar reg, uchar val); static void rtc_write (uchar reg, uchar val);
...@@ -69,6 +73,9 @@ int rtc_get (struct rtc_time *tmp) ...@@ -69,6 +73,9 @@ int rtc_get (struct rtc_time *tmp)
int rel = 0; int rel = 0;
uchar sec, min, hour, mday, wday, mon, year; uchar sec, min, hour, mday, wday, mon, year;
#ifdef CONFIG_RTC_MCP79411
read_rtc:
#endif
sec = rtc_read (RTC_SEC_REG_ADDR); sec = rtc_read (RTC_SEC_REG_ADDR);
min = rtc_read (RTC_MIN_REG_ADDR); min = rtc_read (RTC_MIN_REG_ADDR);
hour = rtc_read (RTC_HR_REG_ADDR); hour = rtc_read (RTC_HR_REG_ADDR);
...@@ -81,6 +88,7 @@ int rtc_get (struct rtc_time *tmp) ...@@ -81,6 +88,7 @@ int rtc_get (struct rtc_time *tmp)
"hr: %02x min: %02x sec: %02x\n", "hr: %02x min: %02x sec: %02x\n",
year, mon, mday, wday, hour, min, sec); year, mon, mday, wday, hour, min, sec);
#ifdef CONFIG_RTC_DS1307
if (sec & RTC_SEC_BIT_CH) { if (sec & RTC_SEC_BIT_CH) {
printf ("### Warning: RTC oscillator has stopped\n"); printf ("### Warning: RTC oscillator has stopped\n");
/* clear the CH flag */ /* clear the CH flag */
...@@ -88,6 +96,23 @@ int rtc_get (struct rtc_time *tmp) ...@@ -88,6 +96,23 @@ int rtc_get (struct rtc_time *tmp)
rtc_read (RTC_SEC_REG_ADDR) & ~RTC_SEC_BIT_CH); rtc_read (RTC_SEC_REG_ADDR) & ~RTC_SEC_BIT_CH);
rel = -1; rel = -1;
} }
#endif
#ifdef CONFIG_RTC_MCP79411
/* make sure that the backup battery is enabled */
if (!(wday & MCP7941X_BIT_VBATEN)) {
rtc_write(RTC_DAY_REG_ADDR,
wday | MCP7941X_BIT_VBATEN);
}
/* clock halted? turn it on, so clock can tick. */
if (!(sec & MCP7941X_BIT_ST)) {
rtc_write(RTC_SEC_REG_ADDR, MCP7941X_BIT_ST);
printf("Started RTC\n");
goto read_rtc;
}
#endif
tmp->tm_sec = bcd2bin (sec & 0x7F); tmp->tm_sec = bcd2bin (sec & 0x7F);
tmp->tm_min = bcd2bin (min & 0x7F); tmp->tm_min = bcd2bin (min & 0x7F);
...@@ -121,11 +146,20 @@ int rtc_set (struct rtc_time *tmp) ...@@ -121,11 +146,20 @@ int rtc_set (struct rtc_time *tmp)
rtc_write (RTC_YR_REG_ADDR, bin2bcd (tmp->tm_year % 100)); rtc_write (RTC_YR_REG_ADDR, bin2bcd (tmp->tm_year % 100));
rtc_write (RTC_MON_REG_ADDR, bin2bcd (tmp->tm_mon)); rtc_write (RTC_MON_REG_ADDR, bin2bcd (tmp->tm_mon));
#ifdef CONFIG_RTC_MCP79411
rtc_write (RTC_DAY_REG_ADDR,
bin2bcd (tmp->tm_wday + 1) | MCP7941X_BIT_VBATEN);
#else
rtc_write (RTC_DAY_REG_ADDR, bin2bcd (tmp->tm_wday + 1)); rtc_write (RTC_DAY_REG_ADDR, bin2bcd (tmp->tm_wday + 1));
#endif
rtc_write (RTC_DATE_REG_ADDR, bin2bcd (tmp->tm_mday)); rtc_write (RTC_DATE_REG_ADDR, bin2bcd (tmp->tm_mday));
rtc_write (RTC_HR_REG_ADDR, bin2bcd (tmp->tm_hour)); rtc_write (RTC_HR_REG_ADDR, bin2bcd (tmp->tm_hour));
rtc_write (RTC_MIN_REG_ADDR, bin2bcd (tmp->tm_min)); rtc_write (RTC_MIN_REG_ADDR, bin2bcd (tmp->tm_min));
#ifdef CONFIG_RTC_MCP79411
rtc_write (RTC_SEC_REG_ADDR, bin2bcd (tmp->tm_sec) | MCP7941X_BIT_ST);
#else
rtc_write (RTC_SEC_REG_ADDR, bin2bcd (tmp->tm_sec)); rtc_write (RTC_SEC_REG_ADDR, bin2bcd (tmp->tm_sec));
#endif
return 0; return 0;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment