time.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * PS3 time and rtc routines.
  3. *
  4. * Copyright (C) 2006 Sony Computer Entertainment Inc.
  5. * Copyright 2006 Sony Corp.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; version 2 of the License.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <linux/kernel.h>
  21. #include <asm/rtc.h>
  22. #include <asm/lv1call.h>
  23. #include <asm/ps3.h>
  24. #include "platform.h"
  25. #define dump_tm(_a) _dump_tm(_a, __func__, __LINE__)
  26. static void _dump_tm(const struct rtc_time *tm, const char* func, int line)
  27. {
  28. pr_debug("%s:%d tm_sec %d\n", func, line, tm->tm_sec);
  29. pr_debug("%s:%d tm_min %d\n", func, line, tm->tm_min);
  30. pr_debug("%s:%d tm_hour %d\n", func, line, tm->tm_hour);
  31. pr_debug("%s:%d tm_mday %d\n", func, line, tm->tm_mday);
  32. pr_debug("%s:%d tm_mon %d\n", func, line, tm->tm_mon);
  33. pr_debug("%s:%d tm_year %d\n", func, line, tm->tm_year);
  34. pr_debug("%s:%d tm_wday %d\n", func, line, tm->tm_wday);
  35. }
  36. #define dump_time(_a) _dump_time(_a, __func__, __LINE__)
  37. static void __maybe_unused _dump_time(int time, const char *func,
  38. int line)
  39. {
  40. struct rtc_time tm;
  41. to_tm(time, &tm);
  42. pr_debug("%s:%d time %d\n", func, line, time);
  43. _dump_tm(&tm, func, line);
  44. }
  45. void __init ps3_calibrate_decr(void)
  46. {
  47. int result;
  48. u64 tmp;
  49. result = ps3_repository_read_be_tb_freq(0, &tmp);
  50. BUG_ON(result);
  51. ppc_tb_freq = tmp;
  52. ppc_proc_freq = ppc_tb_freq * 40;
  53. }
  54. static u64 read_rtc(void)
  55. {
  56. int result;
  57. u64 rtc_val;
  58. u64 tb_val;
  59. result = lv1_get_rtc(&rtc_val, &tb_val);
  60. BUG_ON(result);
  61. return rtc_val;
  62. }
  63. int ps3_set_rtc_time(struct rtc_time *tm)
  64. {
  65. u64 now = mktime(tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
  66. tm->tm_hour, tm->tm_min, tm->tm_sec);
  67. ps3_os_area_set_rtc_diff(now - read_rtc());
  68. return 0;
  69. }
  70. void ps3_get_rtc_time(struct rtc_time *tm)
  71. {
  72. to_tm(read_rtc() + ps3_os_area_get_rtc_diff(), tm);
  73. tm->tm_year -= 1900;
  74. tm->tm_mon -= 1;
  75. }
  76. unsigned long __init ps3_get_boot_time(void)
  77. {
  78. return read_rtc() + ps3_os_area_get_rtc_diff();
  79. }