rtc: ds1307: add support for MCP7941x RTCs
PATCH 1/1 rtc: ds1307: add support for MCP7941x RTCs
MCP7941x RTCs are very similar to ds1307. So add support in the ds1307 driver, as it is done in the linux kernel
Signed-off-by Soeren Moch <[email protected]>
---
Cc: Tom Rini <[email protected]>
--- drivers/rtc/ds1307.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-)
drivers/rtc/ds1307.c +24 -6
@@ -10,6 +10,10 @@/* * Date & Time support (no alarms) for Dallas Semiconductor (now Maxim) * DS1307 and DS1338/9 Real Time Clock (RTC). +* i2c address 0x68 +* +* Date & Time support (no alarms) for MCP7941x Real Time Clock (RTC). +* i2c address 0x6f * * based on ds1337.c */
@@ -52,12 +56,24 @@#define RTC_CTL_REG_ADDR 0x07#define RTC_SEC_BIT_CH 0x80/* Clock Halt (in Register 0) */ +#define RTC_SEC_CH 0x80/* Clock Halt (in Register 0) */ + +#define RTC_DAY_VBATEN 0x00/* Battery EN (in Register 3) */ #define RTC_CTL_BIT_RS0 0x01/* Rate select 0 */ #define RTC_CTL_BIT_RS1 0x02/* Rate select 1 */ #define RTC_CTL_BIT_SQWE 0x10/* Square Wave Enable */ #define RTC_CTL_BIT_OUT 0x80/* Output Control */ +#if CONFIG_SYS_I2C_RTC_ADDR ==0x6f +#undef RTC_SEC_CH +#undef RTC_DAY_VBATEN +#undef RTC_CTL_BIT_SQWE +#define RTC_SEC_CH 0x00/* Clock Halt (in Register 0) */ +#define RTC_DAY_VBATEN 0x08/* Battery EN (in Register 3) */ +#define RTC_CTL_BIT_SQWE 0x40/* Square Wave Enable */ +#endif +static uchar rtc_read (uchar reg);static void rtc_write (uchar reg,uchar val);
@@ -81,11 +97,11 @@ int rtc_get (struct rtc_time *tmp)"hr: %02x min: %02x sec: %02x\n" , year, mon, mday, wday, hour, min, sec); -if (sec &RTC_SEC_BIT_CH ) { +if ((sec &RTC_SEC_BIT_CH ) ==RTC_SEC_CH ) {printf ("### Warning: RTC oscillator has stopped\n" ); -/* clear the CH flag */ +/* start clock */ rtc_write (RTC_SEC_REG_ADDR , -rtc_read (RTC_SEC_REG_ADDR ) & ~RTC_SEC_BIT_CH ); +rtc_read (RTC_SEC_REG_ADDR ) ^RTC_SEC_BIT_CH ); rel =-1 ; }
@@ -112,6 +128,9 @@ int rtc_get (struct rtc_time *tmp)*/ int rtc_set (struct rtc_time *tmp) { +uchar clk_en =RTC_SEC_BIT_CH & ~RTC_SEC_CH ; +uchar bat_en =RTC_DAY_VBATEN ; +DEBUGR ("Set DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n" , tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
@@ -121,11 +140,11 @@ int rtc_set (struct rtc_time *tmp)rtc_write (RTC_YR_REG_ADDR ,bin2bcd (tmp->tm_year %100 ));rtc_write (RTC_MON_REG_ADDR ,bin2bcd (tmp->tm_mon)); -rtc_write (RTC_DAY_REG_ADDR ,bin2bcd (tmp->tm_wday +1 )); +rtc_write (RTC_DAY_REG_ADDR ,bin2bcd (tmp->tm_wday +1 ) | bat_en);rtc_write (RTC_DATE_REG_ADDR ,bin2bcd (tmp->tm_mday));rtc_write (RTC_HR_REG_ADDR ,bin2bcd (tmp->tm_hour));rtc_write (RTC_MIN_REG_ADDR ,bin2bcd (tmp->tm_min)); -rtc_write (RTC_SEC_REG_ADDR ,bin2bcd (tmp->tm_sec)); +rtc_write (RTC_SEC_REG_ADDR ,bin2bcd (tmp->tm_sec) | clk_en);return 0 ; }
@@ -142,7 +161,6 @@ void rtc_reset (void) {struct rtc_time tmp; -rtc_write (RTC_SEC_REG_ADDR ,0x00 );/* clearing Clock Halt */ rtc_write (RTC_CTL_REG_ADDR ,RTC_CTL_BIT_SQWE |RTC_CTL_BIT_RS1 |RTC_CTL_BIT_RS0 ); tmp.tm_year =1970 ;
Signature · 1 line
1.9.1
PATCH 1/1 rtc: ds1307: add support for MCP7941x RTCs
Quoted 6 lines
MCP7941x RTCs are very similar to ds1307. So add support in the ds1307 driver, as it is done in the linux kernel
Signed-off-by Soeren Moch <[email protected]>---
Cc: Tom Rini <[email protected]>
Tom,
since the merge window is open now, can you pick up this patch? Or do you think this should go through some other tree?
Thanks,
Soeren
Quoted 91 lines
--- drivers/rtc/ds1307.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-)drivers/rtc/ds1307.c +24
-6@@ -10,6 +10,10 @@/* * Date & Time support (no alarms) for Dallas Semiconductor (now Maxim) * DS1307 and DS1338/9 Real Time Clock (RTC). +* i2c address 0x68 +* +* Date & Time support (no alarms) for MCP7941x Real Time Clock (RTC). +* i2c address 0x6f * * based on ds1337.c */ @@ -52,12 +56,24 @@#define RTC_CTL_REG_ADDR 0x07#define RTC_SEC_BIT_CH 0x80/* Clock Halt (in Register 0) */ +#define RTC_SEC_CH 0x80/* Clock Halt (in Register 0) */ + +#define RTC_DAY_VBATEN 0x00/* Battery EN (in Register 3) */ #define RTC_CTL_BIT_RS0 0x01/* Rate select 0 */ #define RTC_CTL_BIT_RS1 0x02/* Rate select 1 */ #define RTC_CTL_BIT_SQWE 0x10/* Square Wave Enable */ #define RTC_CTL_BIT_OUT 0x80/* Output Control */ +#if CONFIG_SYS_I2C_RTC_ADDR ==0x6f +#undef RTC_SEC_CH +#undef RTC_DAY_VBATEN +#undef RTC_CTL_BIT_SQWE +#define RTC_SEC_CH 0x00/* Clock Halt (in Register 0) */ +#define RTC_DAY_VBATEN 0x08/* Battery EN (in Register 3) */ +#define RTC_CTL_BIT_SQWE 0x40/* Square Wave Enable */ +#endif +static uchar rtc_read (uchar reg);static void rtc_write (uchar reg,uchar val);@@ -81,11 +97,11 @@ int rtc_get (struct rtc_time *tmp)"hr: %02x min: %02x sec: %02x\n" , year, mon, mday, wday, hour, min, sec); -if (sec &RTC_SEC_BIT_CH ) { +if ((sec &RTC_SEC_BIT_CH ) ==RTC_SEC_CH ) {printf ("### Warning: RTC oscillator has stopped\n" ); -/* clear the CH flag */ +/* start clock */ rtc_write (RTC_SEC_REG_ADDR , -rtc_read (RTC_SEC_REG_ADDR ) & ~RTC_SEC_BIT_CH ); +rtc_read (RTC_SEC_REG_ADDR ) ^RTC_SEC_BIT_CH ); rel =-1 ; }@@ -112,6 +128,9 @@ int rtc_get (struct rtc_time *tmp)*/ int rtc_set (struct rtc_time *tmp) { +uchar clk_en =RTC_SEC_BIT_CH & ~RTC_SEC_CH ; +uchar bat_en =RTC_DAY_VBATEN ; +DEBUGR ("Set DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n" , tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec);@@ -121,11 +140,11 @@ int rtc_set (struct rtc_time *tmp)rtc_write (RTC_YR_REG_ADDR ,bin2bcd (tmp->tm_year %100 ));rtc_write (RTC_MON_REG_ADDR ,bin2bcd (tmp->tm_mon)); -rtc_write (RTC_DAY_REG_ADDR ,bin2bcd (tmp->tm_wday +1 )); +rtc_write (RTC_DAY_REG_ADDR ,bin2bcd (tmp->tm_wday +1 ) | bat_en);rtc_write (RTC_DATE_REG_ADDR ,bin2bcd (tmp->tm_mday));rtc_write (RTC_HR_REG_ADDR ,bin2bcd (tmp->tm_hour));rtc_write (RTC_MIN_REG_ADDR ,bin2bcd (tmp->tm_min)); -rtc_write (RTC_SEC_REG_ADDR ,bin2bcd (tmp->tm_sec)); +rtc_write (RTC_SEC_REG_ADDR ,bin2bcd (tmp->tm_sec) | clk_en);return 0 ; }@@ -142,7 +161,6 @@ void rtc_reset (void) {struct rtc_time tmp; -rtc_write (RTC_SEC_REG_ADDR ,0x00 );/* clearing Clock Halt */ rtc_write (RTC_CTL_REG_ADDR ,RTC_CTL_BIT_SQWE |RTC_CTL_BIT_RS1 |RTC_CTL_BIT_RS0 ); tmp.tm_year =1970 ;