s3c44b0_rtc.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. /*
  27. * S3C44B0 CPU specific code
  28. */
  29. #include <common.h>
  30. #include <command.h>
  31. #include <asm/hardware.h>
  32. #include <rtc.h>
  33. #include <bcd.h>
  34. int rtc_get (struct rtc_time* tm)
  35. {
  36. RTCCON |= 1;
  37. tm->tm_year = BCD2BIN(BCDYEAR);
  38. tm->tm_mon = BCD2BIN(BCDMON);
  39. tm->tm_wday = BCD2BIN(BCDDATE);
  40. tm->tm_mday = BCD2BIN(BCDDAY);
  41. tm->tm_hour = BCD2BIN(BCDHOUR);
  42. tm->tm_min = BCD2BIN(BCDMIN);
  43. tm->tm_sec = BCD2BIN(BCDSEC);
  44. if (tm->tm_sec==0) {
  45. /* we have to re-read the rtc data because of the "one second deviation" problem */
  46. /* see RTC datasheet for more info about it */
  47. tm->tm_year = BCD2BIN(BCDYEAR);
  48. tm->tm_mon = BCD2BIN(BCDMON);
  49. tm->tm_mday = BCD2BIN(BCDDAY);
  50. tm->tm_wday = BCD2BIN(BCDDATE);
  51. tm->tm_hour = BCD2BIN(BCDHOUR);
  52. tm->tm_min = BCD2BIN(BCDMIN);
  53. tm->tm_sec = BCD2BIN(BCDSEC);
  54. }
  55. RTCCON &= ~1;
  56. if(tm->tm_year >= 70)
  57. tm->tm_year += 1900;
  58. else
  59. tm->tm_year += 2000;
  60. return 0;
  61. }
  62. int rtc_set (struct rtc_time* tm)
  63. {
  64. if(tm->tm_year < 2000)
  65. tm->tm_year -= 1900;
  66. else
  67. tm->tm_year -= 2000;
  68. RTCCON |= 1;
  69. BCDYEAR = BIN2BCD(tm->tm_year);
  70. BCDMON = BIN2BCD(tm->tm_mon);
  71. BCDDAY = BIN2BCD(tm->tm_mday);
  72. BCDDATE = BIN2BCD(tm->tm_wday);
  73. BCDHOUR = BIN2BCD(tm->tm_hour);
  74. BCDMIN = BIN2BCD(tm->tm_min);
  75. BCDSEC = BIN2BCD(tm->tm_sec);
  76. RTCCON &= 1;
  77. return 0;
  78. }
  79. void rtc_reset (void)
  80. {
  81. RTCCON |= 1;
  82. BCDYEAR = 0;
  83. BCDMON = 0;
  84. BCDDAY = 0;
  85. BCDDATE = 0;
  86. BCDHOUR = 0;
  87. BCDMIN = 0;
  88. BCDSEC = 0;
  89. RTCCON &= 1;
  90. }