beat.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * Simple routines for Celleb/Beat
  3. *
  4. * (C) Copyright 2006-2007 TOSHIBA CORPORATION
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  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 along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. */
  20. #include <linux/module.h>
  21. #include <linux/init.h>
  22. #include <linux/err.h>
  23. #include <linux/rtc.h>
  24. #include <asm/hvconsole.h>
  25. #include <asm/time.h>
  26. #include "beat_wrapper.h"
  27. #include "beat.h"
  28. void beat_restart(char *cmd)
  29. {
  30. beat_shutdown_logical_partition(1);
  31. }
  32. void beat_power_off(void)
  33. {
  34. beat_shutdown_logical_partition(0);
  35. }
  36. u64 beat_halt_code = 0x1000000000000000UL;
  37. void beat_halt(void)
  38. {
  39. beat_shutdown_logical_partition(beat_halt_code);
  40. }
  41. int beat_set_rtc_time(struct rtc_time *rtc_time)
  42. {
  43. u64 tim;
  44. tim = mktime(rtc_time->tm_year+1900,
  45. rtc_time->tm_mon+1, rtc_time->tm_mday,
  46. rtc_time->tm_hour, rtc_time->tm_min, rtc_time->tm_sec);
  47. if (beat_rtc_write(tim))
  48. return -1;
  49. return 0;
  50. }
  51. void beat_get_rtc_time(struct rtc_time *rtc_time)
  52. {
  53. u64 tim;
  54. if (beat_rtc_read(&tim))
  55. tim = 0;
  56. to_tm(tim, rtc_time);
  57. rtc_time->tm_year -= 1900;
  58. rtc_time->tm_mon -= 1;
  59. }
  60. #define BEAT_NVRAM_SIZE 4096
  61. ssize_t beat_nvram_read(char *buf, size_t count, loff_t *index)
  62. {
  63. unsigned int i;
  64. unsigned long len;
  65. char *p = buf;
  66. if (*index >= BEAT_NVRAM_SIZE)
  67. return -ENODEV;
  68. i = *index;
  69. if (i + count > BEAT_NVRAM_SIZE)
  70. count = BEAT_NVRAM_SIZE - i;
  71. for (; count != 0; count -= len) {
  72. len = count;
  73. if (len > BEAT_NVRW_CNT)
  74. len = BEAT_NVRW_CNT;
  75. if (beat_eeprom_read(i, len, p)) {
  76. return -EIO;
  77. }
  78. p += len;
  79. i += len;
  80. }
  81. *index = i;
  82. return p - buf;
  83. }
  84. ssize_t beat_nvram_write(char *buf, size_t count, loff_t *index)
  85. {
  86. unsigned int i;
  87. unsigned long len;
  88. char *p = buf;
  89. if (*index >= BEAT_NVRAM_SIZE)
  90. return -ENODEV;
  91. i = *index;
  92. if (i + count > BEAT_NVRAM_SIZE)
  93. count = BEAT_NVRAM_SIZE - i;
  94. for (; count != 0; count -= len) {
  95. len = count;
  96. if (len > BEAT_NVRW_CNT)
  97. len = BEAT_NVRW_CNT;
  98. if (beat_eeprom_write(i, len, p)) {
  99. return -EIO;
  100. }
  101. p += len;
  102. i += len;
  103. }
  104. *index = i;
  105. return p - buf;
  106. }
  107. ssize_t beat_nvram_get_size(void)
  108. {
  109. return BEAT_NVRAM_SIZE;
  110. }
  111. int beat_set_xdabr(unsigned long dabr)
  112. {
  113. if (beat_set_dabr(dabr, DABRX_KERNEL | DABRX_USER))
  114. return -1;
  115. return 0;
  116. }
  117. int64_t beat_get_term_char(u64 vterm, u64 *len, u64 *t1, u64 *t2)
  118. {
  119. u64 db[2];
  120. s64 ret;
  121. ret = beat_get_characters_from_console(vterm, len, (u8*)db);
  122. if (ret == 0) {
  123. *t1 = db[0];
  124. *t2 = db[1];
  125. }
  126. return ret;
  127. }
  128. int64_t beat_put_term_char(u64 vterm, u64 len, u64 t1, u64 t2)
  129. {
  130. u64 db[2];
  131. db[0] = t1;
  132. db[1] = t2;
  133. return beat_put_characters_to_console(vterm, len, (u8*)db);
  134. }
  135. EXPORT_SYMBOL(beat_get_term_char);
  136. EXPORT_SYMBOL(beat_put_term_char);
  137. EXPORT_SYMBOL(beat_halt_code);