Jean-Christophe PLAGNIOL-VILLARD | 20b5080 | 2009-03-29 23:01:40 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2004 |
| 3 | * DAVE Srl |
| 4 | * http://www.dave-tech.it |
| 5 | * http://www.wawnet.biz |
| 6 | * mailto:info@wawnet.biz |
| 7 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
Jean-Christophe PLAGNIOL-VILLARD | 20b5080 | 2009-03-29 23:01:40 +0200 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | /* |
| 12 | * S3C44B0 CPU specific code |
| 13 | */ |
| 14 | |
| 15 | #include <common.h> |
| 16 | #include <command.h> |
| 17 | #include <asm/hardware.h> |
| 18 | #include <rtc.h> |
Jean-Christophe PLAGNIOL-VILLARD | 20b5080 | 2009-03-29 23:01:40 +0200 | [diff] [blame] | 19 | |
| 20 | int rtc_get (struct rtc_time* tm) |
| 21 | { |
| 22 | RTCCON |= 1; |
Albin Tonnerre | 8aca720 | 2009-08-13 15:31:11 +0200 | [diff] [blame] | 23 | tm->tm_year = bcd2bin(BCDYEAR); |
| 24 | tm->tm_mon = bcd2bin(BCDMON); |
| 25 | tm->tm_wday = bcd2bin(BCDDATE); |
| 26 | tm->tm_mday = bcd2bin(BCDDAY); |
| 27 | tm->tm_hour = bcd2bin(BCDHOUR); |
| 28 | tm->tm_min = bcd2bin(BCDMIN); |
| 29 | tm->tm_sec = bcd2bin(BCDSEC); |
Jean-Christophe PLAGNIOL-VILLARD | 20b5080 | 2009-03-29 23:01:40 +0200 | [diff] [blame] | 30 | |
| 31 | if (tm->tm_sec==0) { |
| 32 | /* we have to re-read the rtc data because of the "one second deviation" problem */ |
| 33 | /* see RTC datasheet for more info about it */ |
Albin Tonnerre | 8aca720 | 2009-08-13 15:31:11 +0200 | [diff] [blame] | 34 | tm->tm_year = bcd2bin(BCDYEAR); |
| 35 | tm->tm_mon = bcd2bin(BCDMON); |
| 36 | tm->tm_mday = bcd2bin(BCDDAY); |
| 37 | tm->tm_wday = bcd2bin(BCDDATE); |
| 38 | tm->tm_hour = bcd2bin(BCDHOUR); |
| 39 | tm->tm_min = bcd2bin(BCDMIN); |
| 40 | tm->tm_sec = bcd2bin(BCDSEC); |
Jean-Christophe PLAGNIOL-VILLARD | 20b5080 | 2009-03-29 23:01:40 +0200 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | RTCCON &= ~1; |
| 44 | |
| 45 | if(tm->tm_year >= 70) |
| 46 | tm->tm_year += 1900; |
| 47 | else |
| 48 | tm->tm_year += 2000; |
| 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | int rtc_set (struct rtc_time* tm) |
| 54 | { |
| 55 | if(tm->tm_year < 2000) |
| 56 | tm->tm_year -= 1900; |
| 57 | else |
| 58 | tm->tm_year -= 2000; |
| 59 | |
| 60 | RTCCON |= 1; |
Albin Tonnerre | 8aca720 | 2009-08-13 15:31:11 +0200 | [diff] [blame] | 61 | BCDYEAR = bin2bcd(tm->tm_year); |
| 62 | BCDMON = bin2bcd(tm->tm_mon); |
| 63 | BCDDAY = bin2bcd(tm->tm_mday); |
| 64 | BCDDATE = bin2bcd(tm->tm_wday); |
| 65 | BCDHOUR = bin2bcd(tm->tm_hour); |
| 66 | BCDMIN = bin2bcd(tm->tm_min); |
| 67 | BCDSEC = bin2bcd(tm->tm_sec); |
Jean-Christophe PLAGNIOL-VILLARD | 20b5080 | 2009-03-29 23:01:40 +0200 | [diff] [blame] | 68 | RTCCON &= 1; |
| 69 | |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | void rtc_reset (void) |
| 74 | { |
| 75 | RTCCON |= 1; |
| 76 | BCDYEAR = 0; |
| 77 | BCDMON = 0; |
| 78 | BCDDAY = 0; |
| 79 | BCDDATE = 0; |
| 80 | BCDHOUR = 0; |
| 81 | BCDMIN = 0; |
| 82 | BCDSEC = 0; |
| 83 | RTCCON &= 1; |
| 84 | } |