ds1307.c (7bee1c91a94db19bd26f92cc67be35d3592c6429) | ds1307.c (c79e1c1ce9e5c1ddf6fac631e4741999f8a0cc58) |
---|---|
1/* 2 * (C) Copyright 2001, 2002, 2003 3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. 4 * Keith Outwater, keith_outwater@mvis.com` 5 * Steven Scholz, steven.scholz@imc-berlin.de 6 * 7 * SPDX-License-Identifier: GPL-2.0+ 8 */ --- 44 unchanged lines hidden (view full) --- 53 54#define RTC_SEC_BIT_CH 0x80 /* Clock Halt (in Register 0) */ 55 56#define RTC_CTL_BIT_RS0 0x01 /* Rate select 0 */ 57#define RTC_CTL_BIT_RS1 0x02 /* Rate select 1 */ 58#define RTC_CTL_BIT_SQWE 0x10 /* Square Wave Enable */ 59#define RTC_CTL_BIT_OUT 0x80 /* Output Control */ 60 | 1/* 2 * (C) Copyright 2001, 2002, 2003 3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. 4 * Keith Outwater, keith_outwater@mvis.com` 5 * Steven Scholz, steven.scholz@imc-berlin.de 6 * 7 * SPDX-License-Identifier: GPL-2.0+ 8 */ --- 44 unchanged lines hidden (view full) --- 53 54#define RTC_SEC_BIT_CH 0x80 /* Clock Halt (in Register 0) */ 55 56#define RTC_CTL_BIT_RS0 0x01 /* Rate select 0 */ 57#define RTC_CTL_BIT_RS1 0x02 /* Rate select 1 */ 58#define RTC_CTL_BIT_SQWE 0x10 /* Square Wave Enable */ 59#define RTC_CTL_BIT_OUT 0x80 /* Output Control */ 60 |
61/* MCP7941X-specific bits */ 62#define MCP7941X_BIT_ST 0x80 63#define MCP7941X_BIT_VBATEN 0x08 64 |
|
61static uchar rtc_read (uchar reg); 62static void rtc_write (uchar reg, uchar val); 63 64/* 65 * Get the current time from the RTC 66 */ 67int rtc_get (struct rtc_time *tmp) 68{ 69 int rel = 0; 70 uchar sec, min, hour, mday, wday, mon, year; 71 | 65static uchar rtc_read (uchar reg); 66static void rtc_write (uchar reg, uchar val); 67 68/* 69 * Get the current time from the RTC 70 */ 71int rtc_get (struct rtc_time *tmp) 72{ 73 int rel = 0; 74 uchar sec, min, hour, mday, wday, mon, year; 75 |
76#ifdef CONFIG_RTC_MCP79411 77read_rtc: 78#endif |
|
72 sec = rtc_read (RTC_SEC_REG_ADDR); 73 min = rtc_read (RTC_MIN_REG_ADDR); 74 hour = rtc_read (RTC_HR_REG_ADDR); 75 wday = rtc_read (RTC_DAY_REG_ADDR); 76 mday = rtc_read (RTC_DATE_REG_ADDR); 77 mon = rtc_read (RTC_MON_REG_ADDR); 78 year = rtc_read (RTC_YR_REG_ADDR); 79 80 DEBUGR ("Get RTC year: %02x mon: %02x mday: %02x wday: %02x " 81 "hr: %02x min: %02x sec: %02x\n", 82 year, mon, mday, wday, hour, min, sec); 83 | 79 sec = rtc_read (RTC_SEC_REG_ADDR); 80 min = rtc_read (RTC_MIN_REG_ADDR); 81 hour = rtc_read (RTC_HR_REG_ADDR); 82 wday = rtc_read (RTC_DAY_REG_ADDR); 83 mday = rtc_read (RTC_DATE_REG_ADDR); 84 mon = rtc_read (RTC_MON_REG_ADDR); 85 year = rtc_read (RTC_YR_REG_ADDR); 86 87 DEBUGR ("Get RTC year: %02x mon: %02x mday: %02x wday: %02x " 88 "hr: %02x min: %02x sec: %02x\n", 89 year, mon, mday, wday, hour, min, sec); 90 |
91#ifdef CONFIG_RTC_DS1307 |
|
84 if (sec & RTC_SEC_BIT_CH) { 85 printf ("### Warning: RTC oscillator has stopped\n"); 86 /* clear the CH flag */ 87 rtc_write (RTC_SEC_REG_ADDR, 88 rtc_read (RTC_SEC_REG_ADDR) & ~RTC_SEC_BIT_CH); 89 rel = -1; 90 } | 92 if (sec & RTC_SEC_BIT_CH) { 93 printf ("### Warning: RTC oscillator has stopped\n"); 94 /* clear the CH flag */ 95 rtc_write (RTC_SEC_REG_ADDR, 96 rtc_read (RTC_SEC_REG_ADDR) & ~RTC_SEC_BIT_CH); 97 rel = -1; 98 } |
99#endif |
|
91 | 100 |
101#ifdef CONFIG_RTC_MCP79411 102 /* make sure that the backup battery is enabled */ 103 if (!(wday & MCP7941X_BIT_VBATEN)) { 104 rtc_write(RTC_DAY_REG_ADDR, 105 wday | MCP7941X_BIT_VBATEN); 106 } 107 108 /* clock halted? turn it on, so clock can tick. */ 109 if (!(sec & MCP7941X_BIT_ST)) { 110 rtc_write(RTC_SEC_REG_ADDR, MCP7941X_BIT_ST); 111 printf("Started RTC\n"); 112 goto read_rtc; 113 } 114#endif 115 116 |
|
92 tmp->tm_sec = bcd2bin (sec & 0x7F); 93 tmp->tm_min = bcd2bin (min & 0x7F); 94 tmp->tm_hour = bcd2bin (hour & 0x3F); 95 tmp->tm_mday = bcd2bin (mday & 0x3F); 96 tmp->tm_mon = bcd2bin (mon & 0x1F); 97 tmp->tm_year = bcd2bin (year) + ( bcd2bin (year) >= 70 ? 1900 : 2000); 98 tmp->tm_wday = bcd2bin ((wday - 1) & 0x07); 99 tmp->tm_yday = 0; --- 16 unchanged lines hidden (view full) --- 116 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday, 117 tmp->tm_hour, tmp->tm_min, tmp->tm_sec); 118 119 if (tmp->tm_year < 1970 || tmp->tm_year > 2069) 120 printf("WARNING: year should be between 1970 and 2069!\n"); 121 122 rtc_write (RTC_YR_REG_ADDR, bin2bcd (tmp->tm_year % 100)); 123 rtc_write (RTC_MON_REG_ADDR, bin2bcd (tmp->tm_mon)); | 117 tmp->tm_sec = bcd2bin (sec & 0x7F); 118 tmp->tm_min = bcd2bin (min & 0x7F); 119 tmp->tm_hour = bcd2bin (hour & 0x3F); 120 tmp->tm_mday = bcd2bin (mday & 0x3F); 121 tmp->tm_mon = bcd2bin (mon & 0x1F); 122 tmp->tm_year = bcd2bin (year) + ( bcd2bin (year) >= 70 ? 1900 : 2000); 123 tmp->tm_wday = bcd2bin ((wday - 1) & 0x07); 124 tmp->tm_yday = 0; --- 16 unchanged lines hidden (view full) --- 141 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday, 142 tmp->tm_hour, tmp->tm_min, tmp->tm_sec); 143 144 if (tmp->tm_year < 1970 || tmp->tm_year > 2069) 145 printf("WARNING: year should be between 1970 and 2069!\n"); 146 147 rtc_write (RTC_YR_REG_ADDR, bin2bcd (tmp->tm_year % 100)); 148 rtc_write (RTC_MON_REG_ADDR, bin2bcd (tmp->tm_mon)); |
149#ifdef CONFIG_RTC_MCP79411 150 rtc_write (RTC_DAY_REG_ADDR, 151 bin2bcd (tmp->tm_wday + 1) | MCP7941X_BIT_VBATEN); 152#else |
|
124 rtc_write (RTC_DAY_REG_ADDR, bin2bcd (tmp->tm_wday + 1)); | 153 rtc_write (RTC_DAY_REG_ADDR, bin2bcd (tmp->tm_wday + 1)); |
154#endif |
|
125 rtc_write (RTC_DATE_REG_ADDR, bin2bcd (tmp->tm_mday)); 126 rtc_write (RTC_HR_REG_ADDR, bin2bcd (tmp->tm_hour)); 127 rtc_write (RTC_MIN_REG_ADDR, bin2bcd (tmp->tm_min)); | 155 rtc_write (RTC_DATE_REG_ADDR, bin2bcd (tmp->tm_mday)); 156 rtc_write (RTC_HR_REG_ADDR, bin2bcd (tmp->tm_hour)); 157 rtc_write (RTC_MIN_REG_ADDR, bin2bcd (tmp->tm_min)); |
158#ifdef CONFIG_RTC_MCP79411 159 rtc_write (RTC_SEC_REG_ADDR, bin2bcd (tmp->tm_sec) | MCP7941X_BIT_ST); 160#else |
|
128 rtc_write (RTC_SEC_REG_ADDR, bin2bcd (tmp->tm_sec)); | 161 rtc_write (RTC_SEC_REG_ADDR, bin2bcd (tmp->tm_sec)); |
162#endif |
|
129 130 return 0; 131} 132 133 134/* 135 * Reset the RTC. We setting the date back to 1970-01-01. 136 * We also enable the oscillator output on the SQW/OUT pin and program --- 44 unchanged lines hidden --- | 163 164 return 0; 165} 166 167 168/* 169 * Reset the RTC. We setting the date back to 1970-01-01. 170 * We also enable the oscillator output on the SQW/OUT pin and program --- 44 unchanged lines hidden --- |