13 #include <linux/kernel.h>
15 #include <linux/module.h>
18 #include <linux/string.h>
26 #include <asm/setup.h>
34 static u16 ec_wakeup_mask;
37 #define EC_BASE_TIMEOUT 20
42 static int __init olpc_ec_timeout_set(
char *
str)
47 "'olpc_ec_timeout=', ignoring!\n");
53 __setup(
"olpc_ec_timeout=", olpc_ec_timeout_set);
59 static inline unsigned int ibf_status(
unsigned int port)
61 return !!(
inb(port) & 0x02);
64 static inline unsigned int obf_status(
unsigned int port)
66 return inb(port) & 0x01;
69 #define wait_on_ibf(p, d) __wait_on_ibf(__LINE__, (p), (d))
70 static int __wait_on_ibf(
unsigned int line,
unsigned int port,
int desired)
73 int state = ibf_status(port);
75 for (timeo = ec_timeout; state != desired && timeo; timeo--) {
77 state = ibf_status(port);
83 line, ec_timeout - timeo);
86 return !(state == desired);
89 #define wait_on_obf(p, d) __wait_on_obf(__LINE__, (p), (d))
90 static int __wait_on_obf(
unsigned int line,
unsigned int port,
int desired)
93 int state = obf_status(port);
95 for (timeo = ec_timeout; state != desired && timeo; timeo--) {
97 state = obf_status(port);
103 line, ec_timeout - timeo);
106 return !(state == desired);
124 for (i = 0; i < 10 && (obf_status(0x6c) == 1); i++)
128 "clear OBF flag!\n");
148 pr_devel(
"olpc-ec: running cmd 0x%x\n", cmd);
157 if (inbuf && inlen) {
159 for (i = 0; i <
inlen; i++) {
160 pr_devel(
"olpc-ec: sending cmd arg 0x%x\n", inbuf[i]);
161 outb(inbuf[i], 0x68);
164 " EC accept data!\n");
169 if (outbuf && outlen) {
171 for (i = 0; i <
outlen; i++) {
174 " EC to provide data!\n");
179 outbuf[
i] =
inb(0x68);
180 pr_devel(
"olpc-ec: received 0x%x\n", outbuf[i]);
191 ec_wakeup_mask |=
value;
197 ec_wakeup_mask &= ~value;
207 if (!machine_is_olpc())
214 #ifdef CONFIG_OLPC_XO1_SCI
223 #ifdef CONFIG_OLPC_XO15_SCI
239 unsigned char ec_byte = bits & 0xff;
252 NULL, 0, (
void *) &ec_word, 2);
256 unsigned char ec_byte;
259 *sci_value = ec_byte;
268 const char *olpc_arch;
272 return propsize == 5 &&
strncmp(
"OLPC", olpc_arch, 5) == 0;
287 static bool __init platform_detect(
void)
295 success = check_ofw_architecture(root);
305 static int __init add_xo1_platform_devices(
void)
309 pdev = platform_device_register_simple(
"xo1-rfkill", -1,
NULL, 0);
311 return PTR_ERR(pdev);
313 pdev = platform_device_register_simple(
"olpc-xo1", -1,
NULL, 0);
315 return PTR_ERR(pdev);
330 pr_info(
"OLPC board revision %s%X (EC=%x)\n",
364 .probe = olpc_xo1_ec_probe,
365 .suspend = olpc_xo1_ec_suspend,
366 .resume = olpc_xo1_ec_resume,
367 .ec_cmd = olpc_xo1_ec_cmd,
371 .probe = olpc_xo1_ec_probe,
372 .ec_cmd = olpc_xo1_ec_cmd,
375 static int __init olpc_init(
void)
387 platform_device_register_simple(
"olpc-ec", -1,
NULL, 0);
390 if (olpc_board_at_least(olpc_board(0xb1)))
393 #ifdef CONFIG_PCI_OLPC
402 r = add_xo1_platform_devices();