mc13783-rtc.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (C) 2008, Guennadi Liakhovetski <lg@denx.de>
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include <common.h>
  23. #include <rtc.h>
  24. #include <spi.h>
  25. #include <fsl_pmic.h>
  26. int rtc_get(struct rtc_time *rtc)
  27. {
  28. u32 day1, day2, time;
  29. int tim, i = 0;
  30. do {
  31. day1 = pmic_reg_read(REG_RTC_DAY);
  32. if (day1 < 0)
  33. return -1;
  34. time = pmic_reg_read(REG_RTC_TIME);
  35. if (time < 0)
  36. return -1;
  37. day2 = pmic_reg_read(REG_RTC_DAY);
  38. if (day2 < 0)
  39. return -1;
  40. } while (day1 != day2 && i++ < 3);
  41. tim = day1 * 86400 + time;
  42. to_tm(tim, rtc);
  43. rtc->tm_yday = 0;
  44. rtc->tm_isdst = 0;
  45. return 0;
  46. }
  47. int rtc_set(struct rtc_time *rtc)
  48. {
  49. u32 time, day;
  50. time = mktime(rtc->tm_year, rtc->tm_mon, rtc->tm_mday,
  51. rtc->tm_hour, rtc->tm_min, rtc->tm_sec);
  52. day = time / 86400;
  53. time %= 86400;
  54. pmic_reg_write(REG_RTC_DAY, day);
  55. pmic_reg_write(REG_RTC_TIME, time);
  56. return 0;
  57. }
  58. void rtc_reset(void)
  59. {
  60. }