diff options
-rw-r--r-- | arch/x86/include/asm/olpc.h | 19 | ||||
-rw-r--r-- | arch/x86/platform/olpc/olpc-xo1-pm.c | 16 | ||||
-rw-r--r-- | arch/x86/platform/olpc/olpc-xo1-sci.c | 1 | ||||
-rw-r--r-- | arch/x86/platform/olpc/olpc-xo15-sci.c | 1 | ||||
-rw-r--r-- | arch/x86/platform/olpc/olpc.c | 190 | ||||
-rw-r--r-- | drivers/net/wireless/libertas/if_usb.c | 1 | ||||
-rw-r--r-- | drivers/platform/Makefile | 1 | ||||
-rw-r--r-- | drivers/platform/olpc/Makefile | 4 | ||||
-rw-r--r-- | drivers/platform/olpc/olpc-ec.c | 336 | ||||
-rw-r--r-- | drivers/platform/x86/xo1-rfkill.c | 3 | ||||
-rw-r--r-- | drivers/power/olpc_battery.c | 1 | ||||
-rw-r--r-- | drivers/staging/olpc_dcon/olpc_dcon.c | 1 | ||||
-rw-r--r-- | include/linux/olpc-ec.h | 41 |
13 files changed, 451 insertions, 164 deletions
diff --git a/arch/x86/include/asm/olpc.h b/arch/x86/include/asm/olpc.h index 87bdbca72f94..72f9adf6eca4 100644 --- a/arch/x86/include/asm/olpc.h +++ b/arch/x86/include/asm/olpc.h | |||
@@ -100,25 +100,6 @@ extern void olpc_xo1_pm_wakeup_clear(u16 value); | |||
100 | 100 | ||
101 | extern int pci_olpc_init(void); | 101 | extern int pci_olpc_init(void); |
102 | 102 | ||
103 | /* EC related functions */ | ||
104 | |||
105 | extern int olpc_ec_cmd(unsigned char cmd, unsigned char *inbuf, size_t inlen, | ||
106 | unsigned char *outbuf, size_t outlen); | ||
107 | |||
108 | /* EC commands */ | ||
109 | |||
110 | #define EC_FIRMWARE_REV 0x08 | ||
111 | #define EC_WRITE_SCI_MASK 0x1b | ||
112 | #define EC_WAKE_UP_WLAN 0x24 | ||
113 | #define EC_WLAN_LEAVE_RESET 0x25 | ||
114 | #define EC_READ_EB_MODE 0x2a | ||
115 | #define EC_SET_SCI_INHIBIT 0x32 | ||
116 | #define EC_SET_SCI_INHIBIT_RELEASE 0x34 | ||
117 | #define EC_WLAN_ENTER_RESET 0x35 | ||
118 | #define EC_WRITE_EXT_SCI_MASK 0x38 | ||
119 | #define EC_SCI_QUERY 0x84 | ||
120 | #define EC_EXT_SCI_QUERY 0x85 | ||
121 | |||
122 | /* SCI source values */ | 103 | /* SCI source values */ |
123 | 104 | ||
124 | #define EC_SCI_SRC_EMPTY 0x00 | 105 | #define EC_SCI_SRC_EMPTY 0x00 |
diff --git a/arch/x86/platform/olpc/olpc-xo1-pm.c b/arch/x86/platform/olpc/olpc-xo1-pm.c index 0ce8616c88ae..d75582d1aa55 100644 --- a/arch/x86/platform/olpc/olpc-xo1-pm.c +++ b/arch/x86/platform/olpc/olpc-xo1-pm.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <linux/pm.h> | 18 | #include <linux/pm.h> |
19 | #include <linux/mfd/core.h> | 19 | #include <linux/mfd/core.h> |
20 | #include <linux/suspend.h> | 20 | #include <linux/suspend.h> |
21 | #include <linux/olpc-ec.h> | ||
21 | 22 | ||
22 | #include <asm/io.h> | 23 | #include <asm/io.h> |
23 | #include <asm/olpc.h> | 24 | #include <asm/olpc.h> |
@@ -51,16 +52,11 @@ EXPORT_SYMBOL_GPL(olpc_xo1_pm_wakeup_clear); | |||
51 | static int xo1_power_state_enter(suspend_state_t pm_state) | 52 | static int xo1_power_state_enter(suspend_state_t pm_state) |
52 | { | 53 | { |
53 | unsigned long saved_sci_mask; | 54 | unsigned long saved_sci_mask; |
54 | int r; | ||
55 | 55 | ||
56 | /* Only STR is supported */ | 56 | /* Only STR is supported */ |
57 | if (pm_state != PM_SUSPEND_MEM) | 57 | if (pm_state != PM_SUSPEND_MEM) |
58 | return -EINVAL; | 58 | return -EINVAL; |
59 | 59 | ||
60 | r = olpc_ec_cmd(EC_SET_SCI_INHIBIT, NULL, 0, NULL, 0); | ||
61 | if (r) | ||
62 | return r; | ||
63 | |||
64 | /* | 60 | /* |
65 | * Save SCI mask (this gets lost since PM1_EN is used as a mask for | 61 | * Save SCI mask (this gets lost since PM1_EN is used as a mask for |
66 | * wakeup events, which is not necessarily the same event set) | 62 | * wakeup events, which is not necessarily the same event set) |
@@ -76,16 +72,6 @@ static int xo1_power_state_enter(suspend_state_t pm_state) | |||
76 | /* Restore SCI mask (using dword access to CS5536_PM1_EN) */ | 72 | /* Restore SCI mask (using dword access to CS5536_PM1_EN) */ |
77 | outl(saved_sci_mask, acpi_base + CS5536_PM1_STS); | 73 | outl(saved_sci_mask, acpi_base + CS5536_PM1_STS); |
78 | 74 | ||
79 | /* Tell the EC to stop inhibiting SCIs */ | ||
80 | olpc_ec_cmd(EC_SET_SCI_INHIBIT_RELEASE, NULL, 0, NULL, 0); | ||
81 | |||
82 | /* | ||
83 | * Tell the wireless module to restart USB communication. | ||
84 | * Must be done twice. | ||
85 | */ | ||
86 | olpc_ec_cmd(EC_WAKE_UP_WLAN, NULL, 0, NULL, 0); | ||
87 | olpc_ec_cmd(EC_WAKE_UP_WLAN, NULL, 0, NULL, 0); | ||
88 | |||
89 | return 0; | 75 | return 0; |
90 | } | 76 | } |
91 | 77 | ||
diff --git a/arch/x86/platform/olpc/olpc-xo1-sci.c b/arch/x86/platform/olpc/olpc-xo1-sci.c index 04b8c73659c5..63d4aa40956e 100644 --- a/arch/x86/platform/olpc/olpc-xo1-sci.c +++ b/arch/x86/platform/olpc/olpc-xo1-sci.c | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <linux/power_supply.h> | 23 | #include <linux/power_supply.h> |
24 | #include <linux/suspend.h> | 24 | #include <linux/suspend.h> |
25 | #include <linux/workqueue.h> | 25 | #include <linux/workqueue.h> |
26 | #include <linux/olpc-ec.h> | ||
26 | 27 | ||
27 | #include <asm/io.h> | 28 | #include <asm/io.h> |
28 | #include <asm/msr.h> | 29 | #include <asm/msr.h> |
diff --git a/arch/x86/platform/olpc/olpc-xo15-sci.c b/arch/x86/platform/olpc/olpc-xo15-sci.c index 599be499fdf7..2fdca25905ae 100644 --- a/arch/x86/platform/olpc/olpc-xo15-sci.c +++ b/arch/x86/platform/olpc/olpc-xo15-sci.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include <linux/slab.h> | 13 | #include <linux/slab.h> |
14 | #include <linux/workqueue.h> | 14 | #include <linux/workqueue.h> |
15 | #include <linux/power_supply.h> | 15 | #include <linux/power_supply.h> |
16 | #include <linux/olpc-ec.h> | ||
16 | 17 | ||
17 | #include <acpi/acpi_bus.h> | 18 | #include <acpi/acpi_bus.h> |
18 | #include <acpi/acpi_drivers.h> | 19 | #include <acpi/acpi_drivers.h> |
diff --git a/arch/x86/platform/olpc/olpc.c b/arch/x86/platform/olpc/olpc.c index a4bee53c2e54..27376081ddec 100644 --- a/arch/x86/platform/olpc/olpc.c +++ b/arch/x86/platform/olpc/olpc.c | |||
@@ -14,14 +14,13 @@ | |||
14 | #include <linux/init.h> | 14 | #include <linux/init.h> |
15 | #include <linux/module.h> | 15 | #include <linux/module.h> |
16 | #include <linux/delay.h> | 16 | #include <linux/delay.h> |
17 | #include <linux/spinlock.h> | ||
18 | #include <linux/io.h> | 17 | #include <linux/io.h> |
19 | #include <linux/string.h> | 18 | #include <linux/string.h> |
20 | #include <linux/platform_device.h> | 19 | #include <linux/platform_device.h> |
21 | #include <linux/of.h> | 20 | #include <linux/of.h> |
22 | #include <linux/syscore_ops.h> | 21 | #include <linux/syscore_ops.h> |
23 | #include <linux/debugfs.h> | ||
24 | #include <linux/mutex.h> | 22 | #include <linux/mutex.h> |
23 | #include <linux/olpc-ec.h> | ||
25 | 24 | ||
26 | #include <asm/geode.h> | 25 | #include <asm/geode.h> |
27 | #include <asm/setup.h> | 26 | #include <asm/setup.h> |
@@ -31,17 +30,6 @@ | |||
31 | struct olpc_platform_t olpc_platform_info; | 30 | struct olpc_platform_t olpc_platform_info; |
32 | EXPORT_SYMBOL_GPL(olpc_platform_info); | 31 | EXPORT_SYMBOL_GPL(olpc_platform_info); |
33 | 32 | ||
34 | static DEFINE_SPINLOCK(ec_lock); | ||
35 | |||
36 | /* debugfs interface to EC commands */ | ||
37 | #define EC_MAX_CMD_ARGS (5 + 1) /* cmd byte + 5 args */ | ||
38 | #define EC_MAX_CMD_REPLY (8) | ||
39 | |||
40 | static struct dentry *ec_debugfs_dir; | ||
41 | static DEFINE_MUTEX(ec_debugfs_cmd_lock); | ||
42 | static unsigned char ec_debugfs_resp[EC_MAX_CMD_REPLY]; | ||
43 | static unsigned int ec_debugfs_resp_bytes; | ||
44 | |||
45 | /* EC event mask to be applied during suspend (defining wakeup sources). */ | 33 | /* EC event mask to be applied during suspend (defining wakeup sources). */ |
46 | static u16 ec_wakeup_mask; | 34 | static u16 ec_wakeup_mask; |
47 | 35 | ||
@@ -125,16 +113,13 @@ static int __wait_on_obf(unsigned int line, unsigned int port, int desired) | |||
125 | * <http://wiki.laptop.org/go/Ec_specification>. Unfortunately, while | 113 | * <http://wiki.laptop.org/go/Ec_specification>. Unfortunately, while |
126 | * OpenFirmware's source is available, the EC's is not. | 114 | * OpenFirmware's source is available, the EC's is not. |
127 | */ | 115 | */ |
128 | int olpc_ec_cmd(unsigned char cmd, unsigned char *inbuf, size_t inlen, | 116 | static int olpc_xo1_ec_cmd(u8 cmd, u8 *inbuf, size_t inlen, u8 *outbuf, |
129 | unsigned char *outbuf, size_t outlen) | 117 | size_t outlen, void *arg) |
130 | { | 118 | { |
131 | unsigned long flags; | ||
132 | int ret = -EIO; | 119 | int ret = -EIO; |
133 | int i; | 120 | int i; |
134 | int restarts = 0; | 121 | int restarts = 0; |
135 | 122 | ||
136 | spin_lock_irqsave(&ec_lock, flags); | ||
137 | |||
138 | /* Clear OBF */ | 123 | /* Clear OBF */ |
139 | for (i = 0; i < 10 && (obf_status(0x6c) == 1); i++) | 124 | for (i = 0; i < 10 && (obf_status(0x6c) == 1); i++) |
140 | inb(0x68); | 125 | inb(0x68); |
@@ -198,10 +183,8 @@ restart: | |||
198 | 183 | ||
199 | ret = 0; | 184 | ret = 0; |
200 | err: | 185 | err: |
201 | spin_unlock_irqrestore(&ec_lock, flags); | ||
202 | return ret; | 186 | return ret; |
203 | } | 187 | } |
204 | EXPORT_SYMBOL_GPL(olpc_ec_cmd); | ||
205 | 188 | ||
206 | void olpc_ec_wakeup_set(u16 value) | 189 | void olpc_ec_wakeup_set(u16 value) |
207 | { | 190 | { |
@@ -280,96 +263,6 @@ int olpc_ec_sci_query(u16 *sci_value) | |||
280 | } | 263 | } |
281 | EXPORT_SYMBOL_GPL(olpc_ec_sci_query); | 264 | EXPORT_SYMBOL_GPL(olpc_ec_sci_query); |
282 | 265 | ||
283 | static ssize_t ec_debugfs_cmd_write(struct file *file, const char __user *buf, | ||
284 | size_t size, loff_t *ppos) | ||
285 | { | ||
286 | int i, m; | ||
287 | unsigned char ec_cmd[EC_MAX_CMD_ARGS]; | ||
288 | unsigned int ec_cmd_int[EC_MAX_CMD_ARGS]; | ||
289 | char cmdbuf[64]; | ||
290 | int ec_cmd_bytes; | ||
291 | |||
292 | mutex_lock(&ec_debugfs_cmd_lock); | ||
293 | |||
294 | size = simple_write_to_buffer(cmdbuf, sizeof(cmdbuf), ppos, buf, size); | ||
295 | |||
296 | m = sscanf(cmdbuf, "%x:%u %x %x %x %x %x", &ec_cmd_int[0], | ||
297 | &ec_debugfs_resp_bytes, | ||
298 | &ec_cmd_int[1], &ec_cmd_int[2], &ec_cmd_int[3], | ||
299 | &ec_cmd_int[4], &ec_cmd_int[5]); | ||
300 | if (m < 2 || ec_debugfs_resp_bytes > EC_MAX_CMD_REPLY) { | ||
301 | /* reset to prevent overflow on read */ | ||
302 | ec_debugfs_resp_bytes = 0; | ||
303 | |||
304 | printk(KERN_DEBUG "olpc-ec: bad ec cmd: " | ||
305 | "cmd:response-count [arg1 [arg2 ...]]\n"); | ||
306 | size = -EINVAL; | ||
307 | goto out; | ||
308 | } | ||
309 | |||
310 | /* convert scanf'd ints to char */ | ||
311 | ec_cmd_bytes = m - 2; | ||
312 | for (i = 0; i <= ec_cmd_bytes; i++) | ||
313 | ec_cmd[i] = ec_cmd_int[i]; | ||
314 | |||
315 | printk(KERN_DEBUG "olpc-ec: debugfs cmd 0x%02x with %d args " | ||
316 | "%02x %02x %02x %02x %02x, want %d returns\n", | ||
317 | ec_cmd[0], ec_cmd_bytes, ec_cmd[1], ec_cmd[2], ec_cmd[3], | ||
318 | ec_cmd[4], ec_cmd[5], ec_debugfs_resp_bytes); | ||
319 | |||
320 | olpc_ec_cmd(ec_cmd[0], (ec_cmd_bytes == 0) ? NULL : &ec_cmd[1], | ||
321 | ec_cmd_bytes, ec_debugfs_resp, ec_debugfs_resp_bytes); | ||
322 | |||
323 | printk(KERN_DEBUG "olpc-ec: response " | ||
324 | "%02x %02x %02x %02x %02x %02x %02x %02x (%d bytes expected)\n", | ||
325 | ec_debugfs_resp[0], ec_debugfs_resp[1], ec_debugfs_resp[2], | ||
326 | ec_debugfs_resp[3], ec_debugfs_resp[4], ec_debugfs_resp[5], | ||
327 | ec_debugfs_resp[6], ec_debugfs_resp[7], ec_debugfs_resp_bytes); | ||
328 | |||
329 | out: | ||
330 | mutex_unlock(&ec_debugfs_cmd_lock); | ||
331 | return size; | ||
332 | } | ||
333 | |||
334 | static ssize_t ec_debugfs_cmd_read(struct file *file, char __user *buf, | ||
335 | size_t size, loff_t *ppos) | ||
336 | { | ||
337 | unsigned int i, r; | ||
338 | char *rp; | ||
339 | char respbuf[64]; | ||
340 | |||
341 | mutex_lock(&ec_debugfs_cmd_lock); | ||
342 | rp = respbuf; | ||
343 | rp += sprintf(rp, "%02x", ec_debugfs_resp[0]); | ||
344 | for (i = 1; i < ec_debugfs_resp_bytes; i++) | ||
345 | rp += sprintf(rp, ", %02x", ec_debugfs_resp[i]); | ||
346 | mutex_unlock(&ec_debugfs_cmd_lock); | ||
347 | rp += sprintf(rp, "\n"); | ||
348 | |||
349 | r = rp - respbuf; | ||
350 | return simple_read_from_buffer(buf, size, ppos, respbuf, r); | ||
351 | } | ||
352 | |||
353 | static const struct file_operations ec_debugfs_genops = { | ||
354 | .write = ec_debugfs_cmd_write, | ||
355 | .read = ec_debugfs_cmd_read, | ||
356 | }; | ||
357 | |||
358 | static void setup_debugfs(void) | ||
359 | { | ||
360 | ec_debugfs_dir = debugfs_create_dir("olpc-ec", 0); | ||
361 | if (ec_debugfs_dir == ERR_PTR(-ENODEV)) | ||
362 | return; | ||
363 | |||
364 | debugfs_create_file("cmd", 0600, ec_debugfs_dir, NULL, | ||
365 | &ec_debugfs_genops); | ||
366 | } | ||
367 | |||
368 | static int olpc_ec_suspend(void) | ||
369 | { | ||
370 | return olpc_ec_mask_write(ec_wakeup_mask); | ||
371 | } | ||
372 | |||
373 | static bool __init check_ofw_architecture(struct device_node *root) | 266 | static bool __init check_ofw_architecture(struct device_node *root) |
374 | { | 267 | { |
375 | const char *olpc_arch; | 268 | const char *olpc_arch; |
@@ -424,8 +317,59 @@ static int __init add_xo1_platform_devices(void) | |||
424 | return 0; | 317 | return 0; |
425 | } | 318 | } |
426 | 319 | ||
427 | static struct syscore_ops olpc_syscore_ops = { | 320 | static int olpc_xo1_ec_probe(struct platform_device *pdev) |
428 | .suspend = olpc_ec_suspend, | 321 | { |
322 | /* get the EC revision */ | ||
323 | olpc_ec_cmd(EC_FIRMWARE_REV, NULL, 0, | ||
324 | (unsigned char *) &olpc_platform_info.ecver, 1); | ||
325 | |||
326 | /* EC version 0x5f adds support for wide SCI mask */ | ||
327 | if (olpc_platform_info.ecver >= 0x5f) | ||
328 | olpc_platform_info.flags |= OLPC_F_EC_WIDE_SCI; | ||
329 | |||
330 | pr_info("OLPC board revision %s%X (EC=%x)\n", | ||
331 | ((olpc_platform_info.boardrev & 0xf) < 8) ? "pre" : "", | ||
332 | olpc_platform_info.boardrev >> 4, | ||
333 | olpc_platform_info.ecver); | ||
334 | |||
335 | return 0; | ||
336 | } | ||
337 | static int olpc_xo1_ec_suspend(struct platform_device *pdev) | ||
338 | { | ||
339 | olpc_ec_mask_write(ec_wakeup_mask); | ||
340 | |||
341 | /* | ||
342 | * Squelch SCIs while suspended. This is a fix for | ||
343 | * <http://dev.laptop.org/ticket/1835>. | ||
344 | */ | ||
345 | return olpc_ec_cmd(EC_SET_SCI_INHIBIT, NULL, 0, NULL, 0); | ||
346 | } | ||
347 | |||
348 | static int olpc_xo1_ec_resume(struct platform_device *pdev) | ||
349 | { | ||
350 | /* Tell the EC to stop inhibiting SCIs */ | ||
351 | olpc_ec_cmd(EC_SET_SCI_INHIBIT_RELEASE, NULL, 0, NULL, 0); | ||
352 | |||
353 | /* | ||
354 | * Tell the wireless module to restart USB communication. | ||
355 | * Must be done twice. | ||
356 | */ | ||
357 | olpc_ec_cmd(EC_WAKE_UP_WLAN, NULL, 0, NULL, 0); | ||
358 | olpc_ec_cmd(EC_WAKE_UP_WLAN, NULL, 0, NULL, 0); | ||
359 | |||
360 | return 0; | ||
361 | } | ||
362 | |||
363 | static struct olpc_ec_driver ec_xo1_driver = { | ||
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, | ||
368 | }; | ||
369 | |||
370 | static struct olpc_ec_driver ec_xo1_5_driver = { | ||
371 | .probe = olpc_xo1_ec_probe, | ||
372 | .ec_cmd = olpc_xo1_ec_cmd, | ||
429 | }; | 373 | }; |
430 | 374 | ||
431 | static int __init olpc_init(void) | 375 | static int __init olpc_init(void) |
@@ -435,16 +379,17 @@ static int __init olpc_init(void) | |||
435 | if (!olpc_ofw_present() || !platform_detect()) | 379 | if (!olpc_ofw_present() || !platform_detect()) |
436 | return 0; | 380 | return 0; |
437 | 381 | ||
438 | spin_lock_init(&ec_lock); | 382 | /* register the XO-1 and 1.5-specific EC handler */ |
383 | if (olpc_platform_info.boardrev < olpc_board_pre(0xd0)) /* XO-1 */ | ||
384 | olpc_ec_driver_register(&ec_xo1_driver, NULL); | ||
385 | else | ||
386 | olpc_ec_driver_register(&ec_xo1_5_driver, NULL); | ||
387 | platform_device_register_simple("olpc-ec", -1, NULL, 0); | ||
439 | 388 | ||
440 | /* assume B1 and above models always have a DCON */ | 389 | /* assume B1 and above models always have a DCON */ |
441 | if (olpc_board_at_least(olpc_board(0xb1))) | 390 | if (olpc_board_at_least(olpc_board(0xb1))) |
442 | olpc_platform_info.flags |= OLPC_F_DCON; | 391 | olpc_platform_info.flags |= OLPC_F_DCON; |
443 | 392 | ||
444 | /* get the EC revision */ | ||
445 | olpc_ec_cmd(EC_FIRMWARE_REV, NULL, 0, | ||
446 | (unsigned char *) &olpc_platform_info.ecver, 1); | ||
447 | |||
448 | #ifdef CONFIG_PCI_OLPC | 393 | #ifdef CONFIG_PCI_OLPC |
449 | /* If the VSA exists let it emulate PCI, if not emulate in kernel. | 394 | /* If the VSA exists let it emulate PCI, if not emulate in kernel. |
450 | * XO-1 only. */ | 395 | * XO-1 only. */ |
@@ -452,14 +397,6 @@ static int __init olpc_init(void) | |||
452 | !cs5535_has_vsa2()) | 397 | !cs5535_has_vsa2()) |
453 | x86_init.pci.arch_init = pci_olpc_init; | 398 | x86_init.pci.arch_init = pci_olpc_init; |
454 | #endif | 399 | #endif |
455 | /* EC version 0x5f adds support for wide SCI mask */ | ||
456 | if (olpc_platform_info.ecver >= 0x5f) | ||
457 | olpc_platform_info.flags |= OLPC_F_EC_WIDE_SCI; | ||
458 | |||
459 | printk(KERN_INFO "OLPC board revision %s%X (EC=%x)\n", | ||
460 | ((olpc_platform_info.boardrev & 0xf) < 8) ? "pre" : "", | ||
461 | olpc_platform_info.boardrev >> 4, | ||
462 | olpc_platform_info.ecver); | ||
463 | 400 | ||
464 | if (olpc_platform_info.boardrev < olpc_board_pre(0xd0)) { /* XO-1 */ | 401 | if (olpc_platform_info.boardrev < olpc_board_pre(0xd0)) { /* XO-1 */ |
465 | r = add_xo1_platform_devices(); | 402 | r = add_xo1_platform_devices(); |
@@ -467,9 +404,6 @@ static int __init olpc_init(void) | |||
467 | return r; | 404 | return r; |
468 | } | 405 | } |
469 | 406 | ||
470 | register_syscore_ops(&olpc_syscore_ops); | ||
471 | setup_debugfs(); | ||
472 | |||
473 | return 0; | 407 | return 0; |
474 | } | 408 | } |
475 | 409 | ||
diff --git a/drivers/net/wireless/libertas/if_usb.c b/drivers/net/wireless/libertas/if_usb.c index 55a77e41170a..27980778d992 100644 --- a/drivers/net/wireless/libertas/if_usb.c +++ b/drivers/net/wireless/libertas/if_usb.c | |||
@@ -10,6 +10,7 @@ | |||
10 | #include <linux/netdevice.h> | 10 | #include <linux/netdevice.h> |
11 | #include <linux/slab.h> | 11 | #include <linux/slab.h> |
12 | #include <linux/usb.h> | 12 | #include <linux/usb.h> |
13 | #include <linux/olpc-ec.h> | ||
13 | 14 | ||
14 | #ifdef CONFIG_OLPC | 15 | #ifdef CONFIG_OLPC |
15 | #include <asm/olpc.h> | 16 | #include <asm/olpc.h> |
diff --git a/drivers/platform/Makefile b/drivers/platform/Makefile index 782953ae4c03..b17c16ce54ad 100644 --- a/drivers/platform/Makefile +++ b/drivers/platform/Makefile | |||
@@ -3,3 +3,4 @@ | |||
3 | # | 3 | # |
4 | 4 | ||
5 | obj-$(CONFIG_X86) += x86/ | 5 | obj-$(CONFIG_X86) += x86/ |
6 | obj-$(CONFIG_OLPC) += olpc/ | ||
diff --git a/drivers/platform/olpc/Makefile b/drivers/platform/olpc/Makefile new file mode 100644 index 000000000000..dc8b26bc7209 --- /dev/null +++ b/drivers/platform/olpc/Makefile | |||
@@ -0,0 +1,4 @@ | |||
1 | # | ||
2 | # OLPC XO platform-specific drivers | ||
3 | # | ||
4 | obj-$(CONFIG_OLPC) += olpc-ec.o | ||
diff --git a/drivers/platform/olpc/olpc-ec.c b/drivers/platform/olpc/olpc-ec.c new file mode 100644 index 000000000000..0f9f8596b300 --- /dev/null +++ b/drivers/platform/olpc/olpc-ec.c | |||
@@ -0,0 +1,336 @@ | |||
1 | /* | ||
2 | * Generic driver for the OLPC Embedded Controller. | ||
3 | * | ||
4 | * Copyright (C) 2011-2012 One Laptop per Child Foundation. | ||
5 | * | ||
6 | * Licensed under the GPL v2 or later. | ||
7 | */ | ||
8 | #include <linux/completion.h> | ||
9 | #include <linux/debugfs.h> | ||
10 | #include <linux/spinlock.h> | ||
11 | #include <linux/mutex.h> | ||
12 | #include <linux/platform_device.h> | ||
13 | #include <linux/slab.h> | ||
14 | #include <linux/workqueue.h> | ||
15 | #include <linux/module.h> | ||
16 | #include <linux/list.h> | ||
17 | #include <linux/olpc-ec.h> | ||
18 | #include <asm/olpc.h> | ||
19 | |||
20 | struct ec_cmd_desc { | ||
21 | u8 cmd; | ||
22 | u8 *inbuf, *outbuf; | ||
23 | size_t inlen, outlen; | ||
24 | |||
25 | int err; | ||
26 | struct completion finished; | ||
27 | struct list_head node; | ||
28 | |||
29 | void *priv; | ||
30 | }; | ||
31 | |||
32 | struct olpc_ec_priv { | ||
33 | struct olpc_ec_driver *drv; | ||
34 | struct work_struct worker; | ||
35 | struct mutex cmd_lock; | ||
36 | |||
37 | /* Pending EC commands */ | ||
38 | struct list_head cmd_q; | ||
39 | spinlock_t cmd_q_lock; | ||
40 | |||
41 | struct dentry *dbgfs_dir; | ||
42 | |||
43 | /* | ||
44 | * Running an EC command while suspending means we don't always finish | ||
45 | * the command before the machine suspends. This means that the EC | ||
46 | * is expecting the command protocol to finish, but we after a period | ||
47 | * of time (while the OS is asleep) the EC times out and restarts its | ||
48 | * idle loop. Meanwhile, the OS wakes up, thinks it's still in the | ||
49 | * middle of the command protocol, starts throwing random things at | ||
50 | * the EC... and everyone's uphappy. | ||
51 | */ | ||
52 | bool suspended; | ||
53 | }; | ||
54 | |||
55 | static struct olpc_ec_driver *ec_driver; | ||
56 | static struct olpc_ec_priv *ec_priv; | ||
57 | static void *ec_cb_arg; | ||
58 | |||
59 | void olpc_ec_driver_register(struct olpc_ec_driver *drv, void *arg) | ||
60 | { | ||
61 | ec_driver = drv; | ||
62 | ec_cb_arg = arg; | ||
63 | } | ||
64 | EXPORT_SYMBOL_GPL(olpc_ec_driver_register); | ||
65 | |||
66 | static void olpc_ec_worker(struct work_struct *w) | ||
67 | { | ||
68 | struct olpc_ec_priv *ec = container_of(w, struct olpc_ec_priv, worker); | ||
69 | struct ec_cmd_desc *desc = NULL; | ||
70 | unsigned long flags; | ||
71 | |||
72 | /* Grab the first pending command from the queue */ | ||
73 | spin_lock_irqsave(&ec->cmd_q_lock, flags); | ||
74 | if (!list_empty(&ec->cmd_q)) { | ||
75 | desc = list_first_entry(&ec->cmd_q, struct ec_cmd_desc, node); | ||
76 | list_del(&desc->node); | ||
77 | } | ||
78 | spin_unlock_irqrestore(&ec->cmd_q_lock, flags); | ||
79 | |||
80 | /* Do we actually have anything to do? */ | ||
81 | if (!desc) | ||
82 | return; | ||
83 | |||
84 | /* Protect the EC hw with a mutex; only run one cmd at a time */ | ||
85 | mutex_lock(&ec->cmd_lock); | ||
86 | desc->err = ec_driver->ec_cmd(desc->cmd, desc->inbuf, desc->inlen, | ||
87 | desc->outbuf, desc->outlen, ec_cb_arg); | ||
88 | mutex_unlock(&ec->cmd_lock); | ||
89 | |||
90 | /* Finished, wake up olpc_ec_cmd() */ | ||
91 | complete(&desc->finished); | ||
92 | |||
93 | /* Run the worker thread again in case there are more cmds pending */ | ||
94 | schedule_work(&ec->worker); | ||
95 | } | ||
96 | |||
97 | /* | ||
98 | * Throw a cmd descripter onto the list. We now have SMP OLPC machines, so | ||
99 | * locking is pretty critical. | ||
100 | */ | ||
101 | static void queue_ec_descriptor(struct ec_cmd_desc *desc, | ||
102 | struct olpc_ec_priv *ec) | ||
103 | { | ||
104 | unsigned long flags; | ||
105 | |||
106 | INIT_LIST_HEAD(&desc->node); | ||
107 | |||
108 | spin_lock_irqsave(&ec->cmd_q_lock, flags); | ||
109 | list_add_tail(&desc->node, &ec->cmd_q); | ||
110 | spin_unlock_irqrestore(&ec->cmd_q_lock, flags); | ||
111 | |||
112 | schedule_work(&ec->worker); | ||
113 | } | ||
114 | |||
115 | int olpc_ec_cmd(u8 cmd, u8 *inbuf, size_t inlen, u8 *outbuf, size_t outlen) | ||
116 | { | ||
117 | struct olpc_ec_priv *ec = ec_priv; | ||
118 | struct ec_cmd_desc desc; | ||
119 | |||
120 | /* Ensure a driver and ec hook have been registered */ | ||
121 | if (WARN_ON(!ec_driver || !ec_driver->ec_cmd)) | ||
122 | return -ENODEV; | ||
123 | |||
124 | if (!ec) | ||
125 | return -ENOMEM; | ||
126 | |||
127 | /* Suspending in the middle of a command hoses things really badly */ | ||
128 | if (WARN_ON(ec->suspended)) | ||
129 | return -EBUSY; | ||
130 | |||
131 | might_sleep(); | ||
132 | |||
133 | desc.cmd = cmd; | ||
134 | desc.inbuf = inbuf; | ||
135 | desc.outbuf = outbuf; | ||
136 | desc.inlen = inlen; | ||
137 | desc.outlen = outlen; | ||
138 | desc.err = 0; | ||
139 | init_completion(&desc.finished); | ||
140 | |||
141 | queue_ec_descriptor(&desc, ec); | ||
142 | |||
143 | /* Timeouts must be handled in the platform-specific EC hook */ | ||
144 | wait_for_completion(&desc.finished); | ||
145 | |||
146 | /* The worker thread dequeues the cmd; no need to do anything here */ | ||
147 | return desc.err; | ||
148 | } | ||
149 | EXPORT_SYMBOL_GPL(olpc_ec_cmd); | ||
150 | |||
151 | #ifdef CONFIG_DEBUG_FS | ||
152 | |||
153 | /* | ||
154 | * debugfs support for "generic commands", to allow sending | ||
155 | * arbitrary EC commands from userspace. | ||
156 | */ | ||
157 | |||
158 | #define EC_MAX_CMD_ARGS (5 + 1) /* cmd byte + 5 args */ | ||
159 | #define EC_MAX_CMD_REPLY (8) | ||
160 | |||
161 | static DEFINE_MUTEX(ec_dbgfs_lock); | ||
162 | static unsigned char ec_dbgfs_resp[EC_MAX_CMD_REPLY]; | ||
163 | static unsigned int ec_dbgfs_resp_bytes; | ||
164 | |||
165 | static ssize_t ec_dbgfs_cmd_write(struct file *file, const char __user *buf, | ||
166 | size_t size, loff_t *ppos) | ||
167 | { | ||
168 | int i, m; | ||
169 | unsigned char ec_cmd[EC_MAX_CMD_ARGS]; | ||
170 | unsigned int ec_cmd_int[EC_MAX_CMD_ARGS]; | ||
171 | char cmdbuf[64]; | ||
172 | int ec_cmd_bytes; | ||
173 | |||
174 | mutex_lock(&ec_dbgfs_lock); | ||
175 | |||
176 | size = simple_write_to_buffer(cmdbuf, sizeof(cmdbuf), ppos, buf, size); | ||
177 | |||
178 | m = sscanf(cmdbuf, "%x:%u %x %x %x %x %x", &ec_cmd_int[0], | ||
179 | &ec_dbgfs_resp_bytes, &ec_cmd_int[1], &ec_cmd_int[2], | ||
180 | &ec_cmd_int[3], &ec_cmd_int[4], &ec_cmd_int[5]); | ||
181 | if (m < 2 || ec_dbgfs_resp_bytes > EC_MAX_CMD_REPLY) { | ||
182 | /* reset to prevent overflow on read */ | ||
183 | ec_dbgfs_resp_bytes = 0; | ||
184 | |||
185 | pr_debug("olpc-ec: bad ec cmd: cmd:response-count [arg1 [arg2 ...]]\n"); | ||
186 | size = -EINVAL; | ||
187 | goto out; | ||
188 | } | ||
189 | |||
190 | /* convert scanf'd ints to char */ | ||
191 | ec_cmd_bytes = m - 2; | ||
192 | for (i = 0; i <= ec_cmd_bytes; i++) | ||
193 | ec_cmd[i] = ec_cmd_int[i]; | ||
194 | |||
195 | pr_debug("olpc-ec: debugfs cmd 0x%02x with %d args %02x %02x %02x %02x %02x, want %d returns\n", | ||
196 | ec_cmd[0], ec_cmd_bytes, ec_cmd[1], ec_cmd[2], | ||
197 | ec_cmd[3], ec_cmd[4], ec_cmd[5], ec_dbgfs_resp_bytes); | ||
198 | |||
199 | olpc_ec_cmd(ec_cmd[0], (ec_cmd_bytes == 0) ? NULL : &ec_cmd[1], | ||
200 | ec_cmd_bytes, ec_dbgfs_resp, ec_dbgfs_resp_bytes); | ||
201 | |||
202 | pr_debug("olpc-ec: response %02x %02x %02x %02x %02x %02x %02x %02x (%d bytes expected)\n", | ||
203 | ec_dbgfs_resp[0], ec_dbgfs_resp[1], ec_dbgfs_resp[2], | ||
204 | ec_dbgfs_resp[3], ec_dbgfs_resp[4], ec_dbgfs_resp[5], | ||
205 | ec_dbgfs_resp[6], ec_dbgfs_resp[7], | ||
206 | ec_dbgfs_resp_bytes); | ||
207 | |||
208 | out: | ||
209 | mutex_unlock(&ec_dbgfs_lock); | ||
210 | return size; | ||
211 | } | ||
212 | |||
213 | static ssize_t ec_dbgfs_cmd_read(struct file *file, char __user *buf, | ||
214 | size_t size, loff_t *ppos) | ||
215 | { | ||
216 | unsigned int i, r; | ||
217 | char *rp; | ||
218 | char respbuf[64]; | ||
219 | |||
220 | mutex_lock(&ec_dbgfs_lock); | ||
221 | rp = respbuf; | ||
222 | rp += sprintf(rp, "%02x", ec_dbgfs_resp[0]); | ||
223 | for (i = 1; i < ec_dbgfs_resp_bytes; i++) | ||
224 | rp += sprintf(rp, ", %02x", ec_dbgfs_resp[i]); | ||
225 | mutex_unlock(&ec_dbgfs_lock); | ||
226 | rp += sprintf(rp, "\n"); | ||
227 | |||
228 | r = rp - respbuf; | ||
229 | return simple_read_from_buffer(buf, size, ppos, respbuf, r); | ||
230 | } | ||
231 | |||
232 | static const struct file_operations ec_dbgfs_ops = { | ||
233 | .write = ec_dbgfs_cmd_write, | ||
234 | .read = ec_dbgfs_cmd_read, | ||
235 | }; | ||
236 | |||
237 | static struct dentry *olpc_ec_setup_debugfs(void) | ||
238 | { | ||
239 | struct dentry *dbgfs_dir; | ||
240 | |||
241 | dbgfs_dir = debugfs_create_dir("olpc-ec", NULL); | ||
242 | if (IS_ERR_OR_NULL(dbgfs_dir)) | ||
243 | return NULL; | ||
244 | |||
245 | debugfs_create_file("cmd", 0600, dbgfs_dir, NULL, &ec_dbgfs_ops); | ||
246 | |||
247 | return dbgfs_dir; | ||
248 | } | ||
249 | |||
250 | #else | ||
251 | |||
252 | static struct dentry *olpc_ec_setup_debugfs(void) | ||
253 | { | ||
254 | return NULL; | ||
255 | } | ||
256 | |||
257 | #endif /* CONFIG_DEBUG_FS */ | ||
258 | |||
259 | static int olpc_ec_probe(struct platform_device *pdev) | ||
260 | { | ||
261 | struct olpc_ec_priv *ec; | ||
262 | int err; | ||
263 | |||
264 | if (!ec_driver) | ||
265 | return -ENODEV; | ||
266 | |||
267 | ec = kzalloc(sizeof(*ec), GFP_KERNEL); | ||
268 | if (!ec) | ||
269 | return -ENOMEM; | ||
270 | |||
271 | ec->drv = ec_driver; | ||
272 | INIT_WORK(&ec->worker, olpc_ec_worker); | ||
273 | mutex_init(&ec->cmd_lock); | ||
274 | |||
275 | INIT_LIST_HEAD(&ec->cmd_q); | ||
276 | spin_lock_init(&ec->cmd_q_lock); | ||
277 | |||
278 | ec_priv = ec; | ||
279 | platform_set_drvdata(pdev, ec); | ||
280 | |||
281 | err = ec_driver->probe ? ec_driver->probe(pdev) : 0; | ||
282 | if (err) { | ||
283 | ec_priv = NULL; | ||
284 | kfree(ec); | ||
285 | } else { | ||
286 | ec->dbgfs_dir = olpc_ec_setup_debugfs(); | ||
287 | } | ||
288 | |||
289 | return err; | ||
290 | } | ||
291 | |||
292 | static int olpc_ec_suspend(struct device *dev) | ||
293 | { | ||
294 | struct platform_device *pdev = to_platform_device(dev); | ||
295 | struct olpc_ec_priv *ec = platform_get_drvdata(pdev); | ||
296 | int err = 0; | ||
297 | |||
298 | if (ec_driver->suspend) | ||
299 | err = ec_driver->suspend(pdev); | ||
300 | if (!err) | ||
301 | ec->suspended = true; | ||
302 | |||
303 | return err; | ||
304 | } | ||
305 | |||
306 | static int olpc_ec_resume(struct device *dev) | ||
307 | { | ||
308 | struct platform_device *pdev = to_platform_device(dev); | ||
309 | struct olpc_ec_priv *ec = platform_get_drvdata(pdev); | ||
310 | |||
311 | ec->suspended = false; | ||
312 | return ec_driver->resume ? ec_driver->resume(pdev) : 0; | ||
313 | } | ||
314 | |||
315 | static const struct dev_pm_ops olpc_ec_pm_ops = { | ||
316 | .suspend_late = olpc_ec_suspend, | ||
317 | .resume_early = olpc_ec_resume, | ||
318 | }; | ||
319 | |||
320 | static struct platform_driver olpc_ec_plat_driver = { | ||
321 | .probe = olpc_ec_probe, | ||
322 | .driver = { | ||
323 | .name = "olpc-ec", | ||
324 | .pm = &olpc_ec_pm_ops, | ||
325 | }, | ||
326 | }; | ||
327 | |||
328 | static int __init olpc_ec_init_module(void) | ||
329 | { | ||
330 | return platform_driver_register(&olpc_ec_plat_driver); | ||
331 | } | ||
332 | |||
333 | module_init(olpc_ec_init_module); | ||
334 | |||
335 | MODULE_AUTHOR("Andres Salomon <dilinger@queued.net>"); | ||
336 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/platform/x86/xo1-rfkill.c b/drivers/platform/x86/xo1-rfkill.c index b57ad8641480..1da13ed34b04 100644 --- a/drivers/platform/x86/xo1-rfkill.c +++ b/drivers/platform/x86/xo1-rfkill.c | |||
@@ -12,8 +12,7 @@ | |||
12 | #include <linux/module.h> | 12 | #include <linux/module.h> |
13 | #include <linux/platform_device.h> | 13 | #include <linux/platform_device.h> |
14 | #include <linux/rfkill.h> | 14 | #include <linux/rfkill.h> |
15 | 15 | #include <linux/olpc-ec.h> | |
16 | #include <asm/olpc.h> | ||
17 | 16 | ||
18 | static bool card_blocked; | 17 | static bool card_blocked; |
19 | 18 | ||
diff --git a/drivers/power/olpc_battery.c b/drivers/power/olpc_battery.c index 55b10b813353..a89a41acf9c5 100644 --- a/drivers/power/olpc_battery.c +++ b/drivers/power/olpc_battery.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/power_supply.h> | 17 | #include <linux/power_supply.h> |
18 | #include <linux/jiffies.h> | 18 | #include <linux/jiffies.h> |
19 | #include <linux/sched.h> | 19 | #include <linux/sched.h> |
20 | #include <linux/olpc-ec.h> | ||
20 | #include <asm/olpc.h> | 21 | #include <asm/olpc.h> |
21 | 22 | ||
22 | 23 | ||
diff --git a/drivers/staging/olpc_dcon/olpc_dcon.c b/drivers/staging/olpc_dcon/olpc_dcon.c index 992275c0d87c..2c4bd746715a 100644 --- a/drivers/staging/olpc_dcon/olpc_dcon.c +++ b/drivers/staging/olpc_dcon/olpc_dcon.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include <linux/uaccess.h> | 27 | #include <linux/uaccess.h> |
28 | #include <linux/ctype.h> | 28 | #include <linux/ctype.h> |
29 | #include <linux/reboot.h> | 29 | #include <linux/reboot.h> |
30 | #include <linux/olpc-ec.h> | ||
30 | #include <asm/tsc.h> | 31 | #include <asm/tsc.h> |
31 | #include <asm/olpc.h> | 32 | #include <asm/olpc.h> |
32 | 33 | ||
diff --git a/include/linux/olpc-ec.h b/include/linux/olpc-ec.h new file mode 100644 index 000000000000..5bb6e760aa61 --- /dev/null +++ b/include/linux/olpc-ec.h | |||
@@ -0,0 +1,41 @@ | |||
1 | #ifndef _LINUX_OLPC_EC_H | ||
2 | #define _LINUX_OLPC_EC_H | ||
3 | |||
4 | /* XO-1 EC commands */ | ||
5 | #define EC_FIRMWARE_REV 0x08 | ||
6 | #define EC_WRITE_SCI_MASK 0x1b | ||
7 | #define EC_WAKE_UP_WLAN 0x24 | ||
8 | #define EC_WLAN_LEAVE_RESET 0x25 | ||
9 | #define EC_READ_EB_MODE 0x2a | ||
10 | #define EC_SET_SCI_INHIBIT 0x32 | ||
11 | #define EC_SET_SCI_INHIBIT_RELEASE 0x34 | ||
12 | #define EC_WLAN_ENTER_RESET 0x35 | ||
13 | #define EC_WRITE_EXT_SCI_MASK 0x38 | ||
14 | #define EC_SCI_QUERY 0x84 | ||
15 | #define EC_EXT_SCI_QUERY 0x85 | ||
16 | |||
17 | struct platform_device; | ||
18 | |||
19 | struct olpc_ec_driver { | ||
20 | int (*probe)(struct platform_device *); | ||
21 | int (*suspend)(struct platform_device *); | ||
22 | int (*resume)(struct platform_device *); | ||
23 | |||
24 | int (*ec_cmd)(u8, u8 *, size_t, u8 *, size_t, void *); | ||
25 | }; | ||
26 | |||
27 | #ifdef CONFIG_OLPC | ||
28 | |||
29 | extern void olpc_ec_driver_register(struct olpc_ec_driver *drv, void *arg); | ||
30 | |||
31 | extern int olpc_ec_cmd(u8 cmd, u8 *inbuf, size_t inlen, u8 *outbuf, | ||
32 | size_t outlen); | ||
33 | |||
34 | #else | ||
35 | |||
36 | static inline int olpc_ec_cmd(u8 cmd, u8 *inbuf, size_t inlen, u8 *outbuf, | ||
37 | size_t outlen) { return -ENODEV; } | ||
38 | |||
39 | #endif /* CONFIG_OLPC */ | ||
40 | |||
41 | #endif /* _LINUX_OLPC_EC_H */ | ||