Merge branch 'for-linus-3.6' of git://dev.laptop.org/users/dilinger/linux-olpc

Pull OLPC platform updates from Andres Salomon:
"These move the OLPC Embedded Controller driver out of
arch/x86/platform and into drivers/platform/olpc.

OLPC machines are now ARM-based (which means lots of x86 and ARM
changes), but are typically pretty self-contained.. so it makes more
sense to go through a separate OLPC tree after getting the appropriate
review/ACKs."

* 'for-linus-3.6' of git://dev.laptop.org/users/dilinger/linux-olpc:
x86: OLPC: move s/r-related EC cmds to EC driver
Platform: OLPC: move global variables into priv struct
Platform: OLPC: move debugfs support from x86 EC driver
x86: OLPC: switch over to using new EC driver on x86
Platform: OLPC: add a suspended flag to the EC driver
Platform: OLPC: turn EC driver into a platform_driver
Platform: OLPC: allow EC cmd to be overridden, and create a workqueue to call it
drivers: OLPC: update various drivers to include olpc-ec.h
Platform: OLPC: add a stub to drivers/platform/ for the OLPC EC driver

Changed files
+451 -164
arch
x86
drivers
net
wireless
libertas
platform
power
staging
olpc_dcon
include
linux
-19
arch/x86/include/asm/olpc.h
··· 100 100 101 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 103 /* SCI source values */ 123 104 124 105 #define EC_SCI_SRC_EMPTY 0x00
+1 -15
arch/x86/platform/olpc/olpc-xo1-pm.c
··· 18 18 #include <linux/pm.h> 19 19 #include <linux/mfd/core.h> 20 20 #include <linux/suspend.h> 21 + #include <linux/olpc-ec.h> 21 22 22 23 #include <asm/io.h> 23 24 #include <asm/olpc.h> ··· 52 51 static int xo1_power_state_enter(suspend_state_t pm_state) 53 52 { 54 53 unsigned long saved_sci_mask; 55 - int r; 56 54 57 55 /* Only STR is supported */ 58 56 if (pm_state != PM_SUSPEND_MEM) 59 57 return -EINVAL; 60 - 61 - r = olpc_ec_cmd(EC_SET_SCI_INHIBIT, NULL, 0, NULL, 0); 62 - if (r) 63 - return r; 64 58 65 59 /* 66 60 * Save SCI mask (this gets lost since PM1_EN is used as a mask for ··· 71 75 72 76 /* Restore SCI mask (using dword access to CS5536_PM1_EN) */ 73 77 outl(saved_sci_mask, acpi_base + CS5536_PM1_STS); 74 - 75 - /* Tell the EC to stop inhibiting SCIs */ 76 - olpc_ec_cmd(EC_SET_SCI_INHIBIT_RELEASE, NULL, 0, NULL, 0); 77 - 78 - /* 79 - * Tell the wireless module to restart USB communication. 80 - * Must be done twice. 81 - */ 82 - olpc_ec_cmd(EC_WAKE_UP_WLAN, NULL, 0, NULL, 0); 83 - olpc_ec_cmd(EC_WAKE_UP_WLAN, NULL, 0, NULL, 0); 84 78 85 79 return 0; 86 80 }
+1
arch/x86/platform/olpc/olpc-xo1-sci.c
··· 23 23 #include <linux/power_supply.h> 24 24 #include <linux/suspend.h> 25 25 #include <linux/workqueue.h> 26 + #include <linux/olpc-ec.h> 26 27 27 28 #include <asm/io.h> 28 29 #include <asm/msr.h>
+1
arch/x86/platform/olpc/olpc-xo15-sci.c
··· 13 13 #include <linux/slab.h> 14 14 #include <linux/workqueue.h> 15 15 #include <linux/power_supply.h> 16 + #include <linux/olpc-ec.h> 16 17 17 18 #include <acpi/acpi_bus.h> 18 19 #include <acpi/acpi_drivers.h>
+62 -128
arch/x86/platform/olpc/olpc.c
··· 14 14 #include <linux/init.h> 15 15 #include <linux/module.h> 16 16 #include <linux/delay.h> 17 - #include <linux/spinlock.h> 18 17 #include <linux/io.h> 19 18 #include <linux/string.h> 20 19 #include <linux/platform_device.h> 21 20 #include <linux/of.h> 22 21 #include <linux/syscore_ops.h> 23 - #include <linux/debugfs.h> 24 22 #include <linux/mutex.h> 23 + #include <linux/olpc-ec.h> 25 24 26 25 #include <asm/geode.h> 27 26 #include <asm/setup.h> ··· 29 30 30 31 struct olpc_platform_t olpc_platform_info; 31 32 EXPORT_SYMBOL_GPL(olpc_platform_info); 32 - 33 - static DEFINE_SPINLOCK(ec_lock); 34 - 35 - /* debugfs interface to EC commands */ 36 - #define EC_MAX_CMD_ARGS (5 + 1) /* cmd byte + 5 args */ 37 - #define EC_MAX_CMD_REPLY (8) 38 - 39 - static struct dentry *ec_debugfs_dir; 40 - static DEFINE_MUTEX(ec_debugfs_cmd_lock); 41 - static unsigned char ec_debugfs_resp[EC_MAX_CMD_REPLY]; 42 - static unsigned int ec_debugfs_resp_bytes; 43 33 44 34 /* EC event mask to be applied during suspend (defining wakeup sources). */ 45 35 static u16 ec_wakeup_mask; ··· 113 125 * <http://wiki.laptop.org/go/Ec_specification>. Unfortunately, while 114 126 * OpenFirmware's source is available, the EC's is not. 115 127 */ 116 - int olpc_ec_cmd(unsigned char cmd, unsigned char *inbuf, size_t inlen, 117 - unsigned char *outbuf, size_t outlen) 128 + static int olpc_xo1_ec_cmd(u8 cmd, u8 *inbuf, size_t inlen, u8 *outbuf, 129 + size_t outlen, void *arg) 118 130 { 119 - unsigned long flags; 120 131 int ret = -EIO; 121 132 int i; 122 133 int restarts = 0; 123 - 124 - spin_lock_irqsave(&ec_lock, flags); 125 134 126 135 /* Clear OBF */ 127 136 for (i = 0; i < 10 && (obf_status(0x6c) == 1); i++) ··· 183 198 184 199 ret = 0; 185 200 err: 186 - spin_unlock_irqrestore(&ec_lock, flags); 187 201 return ret; 188 202 } 189 - EXPORT_SYMBOL_GPL(olpc_ec_cmd); 190 203 191 204 void olpc_ec_wakeup_set(u16 value) 192 205 { ··· 263 280 } 264 281 EXPORT_SYMBOL_GPL(olpc_ec_sci_query); 265 282 266 - static ssize_t ec_debugfs_cmd_write(struct file *file, const char __user *buf, 267 - size_t size, loff_t *ppos) 268 - { 269 - int i, m; 270 - unsigned char ec_cmd[EC_MAX_CMD_ARGS]; 271 - unsigned int ec_cmd_int[EC_MAX_CMD_ARGS]; 272 - char cmdbuf[64]; 273 - int ec_cmd_bytes; 274 - 275 - mutex_lock(&ec_debugfs_cmd_lock); 276 - 277 - size = simple_write_to_buffer(cmdbuf, sizeof(cmdbuf), ppos, buf, size); 278 - 279 - m = sscanf(cmdbuf, "%x:%u %x %x %x %x %x", &ec_cmd_int[0], 280 - &ec_debugfs_resp_bytes, 281 - &ec_cmd_int[1], &ec_cmd_int[2], &ec_cmd_int[3], 282 - &ec_cmd_int[4], &ec_cmd_int[5]); 283 - if (m < 2 || ec_debugfs_resp_bytes > EC_MAX_CMD_REPLY) { 284 - /* reset to prevent overflow on read */ 285 - ec_debugfs_resp_bytes = 0; 286 - 287 - printk(KERN_DEBUG "olpc-ec: bad ec cmd: " 288 - "cmd:response-count [arg1 [arg2 ...]]\n"); 289 - size = -EINVAL; 290 - goto out; 291 - } 292 - 293 - /* convert scanf'd ints to char */ 294 - ec_cmd_bytes = m - 2; 295 - for (i = 0; i <= ec_cmd_bytes; i++) 296 - ec_cmd[i] = ec_cmd_int[i]; 297 - 298 - printk(KERN_DEBUG "olpc-ec: debugfs cmd 0x%02x with %d args " 299 - "%02x %02x %02x %02x %02x, want %d returns\n", 300 - ec_cmd[0], ec_cmd_bytes, ec_cmd[1], ec_cmd[2], ec_cmd[3], 301 - ec_cmd[4], ec_cmd[5], ec_debugfs_resp_bytes); 302 - 303 - olpc_ec_cmd(ec_cmd[0], (ec_cmd_bytes == 0) ? NULL : &ec_cmd[1], 304 - ec_cmd_bytes, ec_debugfs_resp, ec_debugfs_resp_bytes); 305 - 306 - printk(KERN_DEBUG "olpc-ec: response " 307 - "%02x %02x %02x %02x %02x %02x %02x %02x (%d bytes expected)\n", 308 - ec_debugfs_resp[0], ec_debugfs_resp[1], ec_debugfs_resp[2], 309 - ec_debugfs_resp[3], ec_debugfs_resp[4], ec_debugfs_resp[5], 310 - ec_debugfs_resp[6], ec_debugfs_resp[7], ec_debugfs_resp_bytes); 311 - 312 - out: 313 - mutex_unlock(&ec_debugfs_cmd_lock); 314 - return size; 315 - } 316 - 317 - static ssize_t ec_debugfs_cmd_read(struct file *file, char __user *buf, 318 - size_t size, loff_t *ppos) 319 - { 320 - unsigned int i, r; 321 - char *rp; 322 - char respbuf[64]; 323 - 324 - mutex_lock(&ec_debugfs_cmd_lock); 325 - rp = respbuf; 326 - rp += sprintf(rp, "%02x", ec_debugfs_resp[0]); 327 - for (i = 1; i < ec_debugfs_resp_bytes; i++) 328 - rp += sprintf(rp, ", %02x", ec_debugfs_resp[i]); 329 - mutex_unlock(&ec_debugfs_cmd_lock); 330 - rp += sprintf(rp, "\n"); 331 - 332 - r = rp - respbuf; 333 - return simple_read_from_buffer(buf, size, ppos, respbuf, r); 334 - } 335 - 336 - static const struct file_operations ec_debugfs_genops = { 337 - .write = ec_debugfs_cmd_write, 338 - .read = ec_debugfs_cmd_read, 339 - }; 340 - 341 - static void setup_debugfs(void) 342 - { 343 - ec_debugfs_dir = debugfs_create_dir("olpc-ec", 0); 344 - if (ec_debugfs_dir == ERR_PTR(-ENODEV)) 345 - return; 346 - 347 - debugfs_create_file("cmd", 0600, ec_debugfs_dir, NULL, 348 - &ec_debugfs_genops); 349 - } 350 - 351 - static int olpc_ec_suspend(void) 352 - { 353 - return olpc_ec_mask_write(ec_wakeup_mask); 354 - } 355 - 356 283 static bool __init check_ofw_architecture(struct device_node *root) 357 284 { 358 285 const char *olpc_arch; ··· 317 424 return 0; 318 425 } 319 426 320 - static struct syscore_ops olpc_syscore_ops = { 321 - .suspend = olpc_ec_suspend, 427 + static int olpc_xo1_ec_probe(struct platform_device *pdev) 428 + { 429 + /* get the EC revision */ 430 + olpc_ec_cmd(EC_FIRMWARE_REV, NULL, 0, 431 + (unsigned char *) &olpc_platform_info.ecver, 1); 432 + 433 + /* EC version 0x5f adds support for wide SCI mask */ 434 + if (olpc_platform_info.ecver >= 0x5f) 435 + olpc_platform_info.flags |= OLPC_F_EC_WIDE_SCI; 436 + 437 + pr_info("OLPC board revision %s%X (EC=%x)\n", 438 + ((olpc_platform_info.boardrev & 0xf) < 8) ? "pre" : "", 439 + olpc_platform_info.boardrev >> 4, 440 + olpc_platform_info.ecver); 441 + 442 + return 0; 443 + } 444 + static int olpc_xo1_ec_suspend(struct platform_device *pdev) 445 + { 446 + olpc_ec_mask_write(ec_wakeup_mask); 447 + 448 + /* 449 + * Squelch SCIs while suspended. This is a fix for 450 + * <http://dev.laptop.org/ticket/1835>. 451 + */ 452 + return olpc_ec_cmd(EC_SET_SCI_INHIBIT, NULL, 0, NULL, 0); 453 + } 454 + 455 + static int olpc_xo1_ec_resume(struct platform_device *pdev) 456 + { 457 + /* Tell the EC to stop inhibiting SCIs */ 458 + olpc_ec_cmd(EC_SET_SCI_INHIBIT_RELEASE, NULL, 0, NULL, 0); 459 + 460 + /* 461 + * Tell the wireless module to restart USB communication. 462 + * Must be done twice. 463 + */ 464 + olpc_ec_cmd(EC_WAKE_UP_WLAN, NULL, 0, NULL, 0); 465 + olpc_ec_cmd(EC_WAKE_UP_WLAN, NULL, 0, NULL, 0); 466 + 467 + return 0; 468 + } 469 + 470 + static struct olpc_ec_driver ec_xo1_driver = { 471 + .probe = olpc_xo1_ec_probe, 472 + .suspend = olpc_xo1_ec_suspend, 473 + .resume = olpc_xo1_ec_resume, 474 + .ec_cmd = olpc_xo1_ec_cmd, 475 + }; 476 + 477 + static struct olpc_ec_driver ec_xo1_5_driver = { 478 + .probe = olpc_xo1_ec_probe, 479 + .ec_cmd = olpc_xo1_ec_cmd, 322 480 }; 323 481 324 482 static int __init olpc_init(void) ··· 379 435 if (!olpc_ofw_present() || !platform_detect()) 380 436 return 0; 381 437 382 - spin_lock_init(&ec_lock); 438 + /* register the XO-1 and 1.5-specific EC handler */ 439 + if (olpc_platform_info.boardrev < olpc_board_pre(0xd0)) /* XO-1 */ 440 + olpc_ec_driver_register(&ec_xo1_driver, NULL); 441 + else 442 + olpc_ec_driver_register(&ec_xo1_5_driver, NULL); 443 + platform_device_register_simple("olpc-ec", -1, NULL, 0); 383 444 384 445 /* assume B1 and above models always have a DCON */ 385 446 if (olpc_board_at_least(olpc_board(0xb1))) 386 447 olpc_platform_info.flags |= OLPC_F_DCON; 387 - 388 - /* get the EC revision */ 389 - olpc_ec_cmd(EC_FIRMWARE_REV, NULL, 0, 390 - (unsigned char *) &olpc_platform_info.ecver, 1); 391 448 392 449 #ifdef CONFIG_PCI_OLPC 393 450 /* If the VSA exists let it emulate PCI, if not emulate in kernel. ··· 397 452 !cs5535_has_vsa2()) 398 453 x86_init.pci.arch_init = pci_olpc_init; 399 454 #endif 400 - /* EC version 0x5f adds support for wide SCI mask */ 401 - if (olpc_platform_info.ecver >= 0x5f) 402 - olpc_platform_info.flags |= OLPC_F_EC_WIDE_SCI; 403 - 404 - printk(KERN_INFO "OLPC board revision %s%X (EC=%x)\n", 405 - ((olpc_platform_info.boardrev & 0xf) < 8) ? "pre" : "", 406 - olpc_platform_info.boardrev >> 4, 407 - olpc_platform_info.ecver); 408 455 409 456 if (olpc_platform_info.boardrev < olpc_board_pre(0xd0)) { /* XO-1 */ 410 457 r = add_xo1_platform_devices(); 411 458 if (r) 412 459 return r; 413 460 } 414 - 415 - register_syscore_ops(&olpc_syscore_ops); 416 - setup_debugfs(); 417 461 418 462 return 0; 419 463 }
+1
drivers/net/wireless/libertas/if_usb.c
··· 10 10 #include <linux/netdevice.h> 11 11 #include <linux/slab.h> 12 12 #include <linux/usb.h> 13 + #include <linux/olpc-ec.h> 13 14 14 15 #ifdef CONFIG_OLPC 15 16 #include <asm/olpc.h>
+1
drivers/platform/Makefile
··· 3 3 # 4 4 5 5 obj-$(CONFIG_X86) += x86/ 6 + obj-$(CONFIG_OLPC) += olpc/
+4
drivers/platform/olpc/Makefile
··· 1 + # 2 + # OLPC XO platform-specific drivers 3 + # 4 + obj-$(CONFIG_OLPC) += olpc-ec.o
+336
drivers/platform/olpc/olpc-ec.c
··· 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");
+1 -2
drivers/platform/x86/xo1-rfkill.c
··· 12 12 #include <linux/module.h> 13 13 #include <linux/platform_device.h> 14 14 #include <linux/rfkill.h> 15 - 16 - #include <asm/olpc.h> 15 + #include <linux/olpc-ec.h> 17 16 18 17 static bool card_blocked; 19 18
+1
drivers/power/olpc_battery.c
··· 17 17 #include <linux/power_supply.h> 18 18 #include <linux/jiffies.h> 19 19 #include <linux/sched.h> 20 + #include <linux/olpc-ec.h> 20 21 #include <asm/olpc.h> 21 22 22 23
+1
drivers/staging/olpc_dcon/olpc_dcon.c
··· 27 27 #include <linux/uaccess.h> 28 28 #include <linux/ctype.h> 29 29 #include <linux/reboot.h> 30 + #include <linux/olpc-ec.h> 30 31 #include <asm/tsc.h> 31 32 #include <asm/olpc.h> 32 33
+41
include/linux/olpc-ec.h
··· 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 */