diff options
Diffstat (limited to 'arch/powerpc/platforms/celleb/beat.c')
-rw-r--r-- | arch/powerpc/platforms/celleb/beat.c | 163 |
1 files changed, 163 insertions, 0 deletions
diff --git a/arch/powerpc/platforms/celleb/beat.c b/arch/powerpc/platforms/celleb/beat.c new file mode 100644 index 000000000000..99341ce8a697 --- /dev/null +++ b/arch/powerpc/platforms/celleb/beat.c | |||
@@ -0,0 +1,163 @@ | |||
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 | |||
21 | #include <linux/module.h> | ||
22 | #include <linux/init.h> | ||
23 | #include <linux/err.h> | ||
24 | #include <linux/rtc.h> | ||
25 | |||
26 | #include <asm/hvconsole.h> | ||
27 | #include <asm/time.h> | ||
28 | |||
29 | #include "beat_wrapper.h" | ||
30 | #include "beat.h" | ||
31 | |||
32 | void beat_restart(char *cmd) | ||
33 | { | ||
34 | beat_shutdown_logical_partition(1); | ||
35 | } | ||
36 | |||
37 | void beat_power_off(void) | ||
38 | { | ||
39 | beat_shutdown_logical_partition(0); | ||
40 | } | ||
41 | |||
42 | u64 beat_halt_code = 0x1000000000000000UL; | ||
43 | |||
44 | void beat_halt(void) | ||
45 | { | ||
46 | beat_shutdown_logical_partition(beat_halt_code); | ||
47 | } | ||
48 | |||
49 | int beat_set_rtc_time(struct rtc_time *rtc_time) | ||
50 | { | ||
51 | u64 tim; | ||
52 | tim = mktime(rtc_time->tm_year+1900, | ||
53 | rtc_time->tm_mon+1, rtc_time->tm_mday, | ||
54 | rtc_time->tm_hour, rtc_time->tm_min, rtc_time->tm_sec); | ||
55 | if (beat_rtc_write(tim)) | ||
56 | return -1; | ||
57 | return 0; | ||
58 | } | ||
59 | |||
60 | void beat_get_rtc_time(struct rtc_time *rtc_time) | ||
61 | { | ||
62 | u64 tim; | ||
63 | |||
64 | if (beat_rtc_read(&tim)) | ||
65 | tim = 0; | ||
66 | to_tm(tim, rtc_time); | ||
67 | rtc_time->tm_year -= 1900; | ||
68 | rtc_time->tm_mon -= 1; | ||
69 | } | ||
70 | |||
71 | #define BEAT_NVRAM_SIZE 4096 | ||
72 | |||
73 | ssize_t beat_nvram_read(char *buf, size_t count, loff_t *index) | ||
74 | { | ||
75 | unsigned int i; | ||
76 | unsigned long len; | ||
77 | char *p = buf; | ||
78 | |||
79 | if (*index >= BEAT_NVRAM_SIZE) | ||
80 | return -ENODEV; | ||
81 | i = *index; | ||
82 | if (i + count > BEAT_NVRAM_SIZE) | ||
83 | count = BEAT_NVRAM_SIZE - i; | ||
84 | |||
85 | for (; count != 0; count -= len) { | ||
86 | len = count; | ||
87 | if (len > BEAT_NVRW_CNT) | ||
88 | len = BEAT_NVRW_CNT; | ||
89 | if (beat_eeprom_read(i, len, p)) { | ||
90 | return -EIO; | ||
91 | } | ||
92 | |||
93 | p += len; | ||
94 | i += len; | ||
95 | } | ||
96 | *index = i; | ||
97 | return p - buf; | ||
98 | } | ||
99 | |||
100 | ssize_t beat_nvram_write(char *buf, size_t count, loff_t *index) | ||
101 | { | ||
102 | unsigned int i; | ||
103 | unsigned long len; | ||
104 | char *p = buf; | ||
105 | |||
106 | if (*index >= BEAT_NVRAM_SIZE) | ||
107 | return -ENODEV; | ||
108 | i = *index; | ||
109 | if (i + count > BEAT_NVRAM_SIZE) | ||
110 | count = BEAT_NVRAM_SIZE - i; | ||
111 | |||
112 | for (; count != 0; count -= len) { | ||
113 | len = count; | ||
114 | if (len > BEAT_NVRW_CNT) | ||
115 | len = BEAT_NVRW_CNT; | ||
116 | if (beat_eeprom_write(i, len, p)) { | ||
117 | return -EIO; | ||
118 | } | ||
119 | |||
120 | p += len; | ||
121 | i += len; | ||
122 | } | ||
123 | *index = i; | ||
124 | return p - buf; | ||
125 | } | ||
126 | |||
127 | ssize_t beat_nvram_get_size(void) | ||
128 | { | ||
129 | return BEAT_NVRAM_SIZE; | ||
130 | } | ||
131 | |||
132 | int beat_set_xdabr(unsigned long dabr) | ||
133 | { | ||
134 | if (beat_set_dabr(dabr, DABRX_KERNEL | DABRX_USER)) | ||
135 | return -1; | ||
136 | return 0; | ||
137 | } | ||
138 | |||
139 | int64_t beat_get_term_char(u64 vterm, u64 *len, u64 *t1, u64 *t2) | ||
140 | { | ||
141 | u64 db[2]; | ||
142 | s64 ret; | ||
143 | |||
144 | ret = beat_get_characters_from_console(vterm, len, (u8*)db); | ||
145 | if (ret == 0) { | ||
146 | *t1 = db[0]; | ||
147 | *t2 = db[1]; | ||
148 | } | ||
149 | return ret; | ||
150 | } | ||
151 | |||
152 | int64_t beat_put_term_char(u64 vterm, u64 len, u64 t1, u64 t2) | ||
153 | { | ||
154 | u64 db[2]; | ||
155 | |||
156 | db[0] = t1; | ||
157 | db[1] = t2; | ||
158 | return beat_put_characters_to_console(vterm, len, (u8*)db); | ||
159 | } | ||
160 | |||
161 | EXPORT_SYMBOL(beat_get_term_char); | ||
162 | EXPORT_SYMBOL(beat_put_term_char); | ||
163 | EXPORT_SYMBOL(beat_halt_code); | ||