allow coexistance of N build and AC build.
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / arch / powerpc / platforms / celleb / beat.c
blob99341ce8a6978cdcad8dd309fd277e677cd29732
1 /*
2 * Simple routines for Celleb/Beat
4 * (C) Copyright 2006-2007 TOSHIBA CORPORATION
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.
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.
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.
21 #include <linux/module.h>
22 #include <linux/init.h>
23 #include <linux/err.h>
24 #include <linux/rtc.h>
26 #include <asm/hvconsole.h>
27 #include <asm/time.h>
29 #include "beat_wrapper.h"
30 #include "beat.h"
32 void beat_restart(char *cmd)
34 beat_shutdown_logical_partition(1);
37 void beat_power_off(void)
39 beat_shutdown_logical_partition(0);
42 u64 beat_halt_code = 0x1000000000000000UL;
44 void beat_halt(void)
46 beat_shutdown_logical_partition(beat_halt_code);
49 int beat_set_rtc_time(struct rtc_time *rtc_time)
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;
60 void beat_get_rtc_time(struct rtc_time *rtc_time)
62 u64 tim;
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;
71 #define BEAT_NVRAM_SIZE 4096
73 ssize_t beat_nvram_read(char *buf, size_t count, loff_t *index)
75 unsigned int i;
76 unsigned long len;
77 char *p = buf;
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;
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;
93 p += len;
94 i += len;
96 *index = i;
97 return p - buf;
100 ssize_t beat_nvram_write(char *buf, size_t count, loff_t *index)
102 unsigned int i;
103 unsigned long len;
104 char *p = buf;
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;
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;
120 p += len;
121 i += len;
123 *index = i;
124 return p - buf;
127 ssize_t beat_nvram_get_size(void)
129 return BEAT_NVRAM_SIZE;
132 int beat_set_xdabr(unsigned long dabr)
134 if (beat_set_dabr(dabr, DABRX_KERNEL | DABRX_USER))
135 return -1;
136 return 0;
139 int64_t beat_get_term_char(u64 vterm, u64 *len, u64 *t1, u64 *t2)
141 u64 db[2];
142 s64 ret;
144 ret = beat_get_characters_from_console(vterm, len, (u8*)db);
145 if (ret == 0) {
146 *t1 = db[0];
147 *t2 = db[1];
149 return ret;
152 int64_t beat_put_term_char(u64 vterm, u64 len, u64 t1, u64 t2)
154 u64 db[2];
156 db[0] = t1;
157 db[1] = t2;
158 return beat_put_characters_to_console(vterm, len, (u8*)db);
161 EXPORT_SYMBOL(beat_get_term_char);
162 EXPORT_SYMBOL(beat_put_term_char);
163 EXPORT_SYMBOL(beat_halt_code);