Andres Salomon | 3ef0e1f | 2008-04-29 00:59:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Support for the OLPC DCON and OLPC EC access |
| 3 | * |
| 4 | * Copyright © 2006 Advanced Micro Devices, Inc. |
| 5 | * Copyright © 2007-2008 Andres Salomon <dilinger@debian.org> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/delay.h> |
| 17 | #include <linux/spinlock.h> |
| 18 | #include <linux/io.h> |
| 19 | #include <linux/string.h> |
Daniel Drake | 447b1d4 | 2010-10-13 19:10:42 +0100 | [diff] [blame] | 20 | #include <linux/platform_device.h> |
Daniel Drake | 45bb167 | 2011-03-13 15:10:17 +0000 | [diff] [blame] | 21 | #include <linux/of.h> |
Daniel Drake | bc4ecd5 | 2011-06-25 17:34:13 +0100 | [diff] [blame] | 22 | #include <linux/syscore_ops.h> |
Daniel Drake | a3c8121 | 2012-03-27 16:07:40 +0100 | [diff] [blame] | 23 | #include <linux/debugfs.h> |
| 24 | #include <linux/mutex.h> |
Andres Salomon | 3bf9428 | 2012-07-11 01:16:29 -0700 | [diff] [blame^] | 25 | #include <linux/olpc-ec.h> |
Thomas Gleixner | d5d0e88 | 2010-02-22 05:42:04 -0800 | [diff] [blame] | 26 | |
Andres Salomon | 3ef0e1f | 2008-04-29 00:59:53 -0700 | [diff] [blame] | 27 | #include <asm/geode.h> |
Thomas Gleixner | d5d0e88 | 2010-02-22 05:42:04 -0800 | [diff] [blame] | 28 | #include <asm/setup.h> |
Andres Salomon | 3ef0e1f | 2008-04-29 00:59:53 -0700 | [diff] [blame] | 29 | #include <asm/olpc.h> |
Andres Salomon | fd699c7 | 2010-06-18 17:46:53 -0400 | [diff] [blame] | 30 | #include <asm/olpc_ofw.h> |
Andres Salomon | 3ef0e1f | 2008-04-29 00:59:53 -0700 | [diff] [blame] | 31 | |
| 32 | struct olpc_platform_t olpc_platform_info; |
| 33 | EXPORT_SYMBOL_GPL(olpc_platform_info); |
| 34 | |
| 35 | static DEFINE_SPINLOCK(ec_lock); |
| 36 | |
Daniel Drake | a3c8121 | 2012-03-27 16:07:40 +0100 | [diff] [blame] | 37 | /* debugfs interface to EC commands */ |
| 38 | #define EC_MAX_CMD_ARGS (5 + 1) /* cmd byte + 5 args */ |
| 39 | #define EC_MAX_CMD_REPLY (8) |
| 40 | |
| 41 | static struct dentry *ec_debugfs_dir; |
| 42 | static DEFINE_MUTEX(ec_debugfs_cmd_lock); |
| 43 | static unsigned char ec_debugfs_resp[EC_MAX_CMD_REPLY]; |
| 44 | static unsigned int ec_debugfs_resp_bytes; |
| 45 | |
Daniel Drake | bc4ecd5 | 2011-06-25 17:34:13 +0100 | [diff] [blame] | 46 | /* EC event mask to be applied during suspend (defining wakeup sources). */ |
| 47 | static u16 ec_wakeup_mask; |
| 48 | |
Andres Salomon | 3ef0e1f | 2008-04-29 00:59:53 -0700 | [diff] [blame] | 49 | /* what the timeout *should* be (in ms) */ |
| 50 | #define EC_BASE_TIMEOUT 20 |
| 51 | |
| 52 | /* the timeout that bugs in the EC might force us to actually use */ |
| 53 | static int ec_timeout = EC_BASE_TIMEOUT; |
| 54 | |
| 55 | static int __init olpc_ec_timeout_set(char *str) |
| 56 | { |
| 57 | if (get_option(&str, &ec_timeout) != 1) { |
| 58 | ec_timeout = EC_BASE_TIMEOUT; |
| 59 | printk(KERN_ERR "olpc-ec: invalid argument to " |
| 60 | "'olpc_ec_timeout=', ignoring!\n"); |
| 61 | } |
| 62 | printk(KERN_DEBUG "olpc-ec: using %d ms delay for EC commands.\n", |
| 63 | ec_timeout); |
| 64 | return 1; |
| 65 | } |
| 66 | __setup("olpc_ec_timeout=", olpc_ec_timeout_set); |
| 67 | |
| 68 | /* |
| 69 | * These {i,o}bf_status functions return whether the buffers are full or not. |
| 70 | */ |
| 71 | |
| 72 | static inline unsigned int ibf_status(unsigned int port) |
| 73 | { |
| 74 | return !!(inb(port) & 0x02); |
| 75 | } |
| 76 | |
| 77 | static inline unsigned int obf_status(unsigned int port) |
| 78 | { |
| 79 | return inb(port) & 0x01; |
| 80 | } |
| 81 | |
| 82 | #define wait_on_ibf(p, d) __wait_on_ibf(__LINE__, (p), (d)) |
| 83 | static int __wait_on_ibf(unsigned int line, unsigned int port, int desired) |
| 84 | { |
| 85 | unsigned int timeo; |
| 86 | int state = ibf_status(port); |
| 87 | |
| 88 | for (timeo = ec_timeout; state != desired && timeo; timeo--) { |
| 89 | mdelay(1); |
| 90 | state = ibf_status(port); |
| 91 | } |
| 92 | |
| 93 | if ((state == desired) && (ec_timeout > EC_BASE_TIMEOUT) && |
| 94 | timeo < (ec_timeout - EC_BASE_TIMEOUT)) { |
| 95 | printk(KERN_WARNING "olpc-ec: %d: waited %u ms for IBF!\n", |
| 96 | line, ec_timeout - timeo); |
| 97 | } |
| 98 | |
| 99 | return !(state == desired); |
| 100 | } |
| 101 | |
| 102 | #define wait_on_obf(p, d) __wait_on_obf(__LINE__, (p), (d)) |
| 103 | static int __wait_on_obf(unsigned int line, unsigned int port, int desired) |
| 104 | { |
| 105 | unsigned int timeo; |
| 106 | int state = obf_status(port); |
| 107 | |
| 108 | for (timeo = ec_timeout; state != desired && timeo; timeo--) { |
| 109 | mdelay(1); |
| 110 | state = obf_status(port); |
| 111 | } |
| 112 | |
| 113 | if ((state == desired) && (ec_timeout > EC_BASE_TIMEOUT) && |
| 114 | timeo < (ec_timeout - EC_BASE_TIMEOUT)) { |
| 115 | printk(KERN_WARNING "olpc-ec: %d: waited %u ms for OBF!\n", |
| 116 | line, ec_timeout - timeo); |
| 117 | } |
| 118 | |
| 119 | return !(state == desired); |
| 120 | } |
| 121 | |
| 122 | /* |
| 123 | * This allows the kernel to run Embedded Controller commands. The EC is |
| 124 | * documented at <http://wiki.laptop.org/go/Embedded_controller>, and the |
| 125 | * available EC commands are here: |
| 126 | * <http://wiki.laptop.org/go/Ec_specification>. Unfortunately, while |
| 127 | * OpenFirmware's source is available, the EC's is not. |
| 128 | */ |
Andres Salomon | 392a325 | 2012-07-10 19:31:51 -0700 | [diff] [blame] | 129 | int olpc_ec_cmd_x86(unsigned char cmd, unsigned char *inbuf, size_t inlen, |
Andres Salomon | 3ef0e1f | 2008-04-29 00:59:53 -0700 | [diff] [blame] | 130 | unsigned char *outbuf, size_t outlen) |
| 131 | { |
| 132 | unsigned long flags; |
| 133 | int ret = -EIO; |
| 134 | int i; |
Paul Fox | 286e5b9 | 2010-10-01 18:17:19 +0100 | [diff] [blame] | 135 | int restarts = 0; |
Andres Salomon | 3ef0e1f | 2008-04-29 00:59:53 -0700 | [diff] [blame] | 136 | |
| 137 | spin_lock_irqsave(&ec_lock, flags); |
| 138 | |
| 139 | /* Clear OBF */ |
| 140 | for (i = 0; i < 10 && (obf_status(0x6c) == 1); i++) |
| 141 | inb(0x68); |
| 142 | if (i == 10) { |
| 143 | printk(KERN_ERR "olpc-ec: timeout while attempting to " |
| 144 | "clear OBF flag!\n"); |
| 145 | goto err; |
| 146 | } |
| 147 | |
| 148 | if (wait_on_ibf(0x6c, 0)) { |
| 149 | printk(KERN_ERR "olpc-ec: timeout waiting for EC to " |
| 150 | "quiesce!\n"); |
| 151 | goto err; |
| 152 | } |
| 153 | |
| 154 | restart: |
| 155 | /* |
| 156 | * Note that if we time out during any IBF checks, that's a failure; |
| 157 | * we have to return. There's no way for the kernel to clear that. |
| 158 | * |
| 159 | * If we time out during an OBF check, we can restart the command; |
| 160 | * reissuing it will clear the OBF flag, and we should be alright. |
| 161 | * The OBF flag will sometimes misbehave due to what we believe |
| 162 | * is a hardware quirk.. |
| 163 | */ |
Andres Salomon | 2597186 | 2010-06-16 23:19:28 -0400 | [diff] [blame] | 164 | pr_devel("olpc-ec: running cmd 0x%x\n", cmd); |
Andres Salomon | 3ef0e1f | 2008-04-29 00:59:53 -0700 | [diff] [blame] | 165 | outb(cmd, 0x6c); |
| 166 | |
| 167 | if (wait_on_ibf(0x6c, 0)) { |
| 168 | printk(KERN_ERR "olpc-ec: timeout waiting for EC to read " |
| 169 | "command!\n"); |
| 170 | goto err; |
| 171 | } |
| 172 | |
| 173 | if (inbuf && inlen) { |
| 174 | /* write data to EC */ |
| 175 | for (i = 0; i < inlen; i++) { |
Paul Fox | a3ea14d | 2011-07-26 16:42:26 +0100 | [diff] [blame] | 176 | pr_devel("olpc-ec: sending cmd arg 0x%x\n", inbuf[i]); |
| 177 | outb(inbuf[i], 0x68); |
Andres Salomon | 3ef0e1f | 2008-04-29 00:59:53 -0700 | [diff] [blame] | 178 | if (wait_on_ibf(0x6c, 0)) { |
| 179 | printk(KERN_ERR "olpc-ec: timeout waiting for" |
| 180 | " EC accept data!\n"); |
| 181 | goto err; |
| 182 | } |
Andres Salomon | 3ef0e1f | 2008-04-29 00:59:53 -0700 | [diff] [blame] | 183 | } |
| 184 | } |
| 185 | if (outbuf && outlen) { |
| 186 | /* read data from EC */ |
| 187 | for (i = 0; i < outlen; i++) { |
| 188 | if (wait_on_obf(0x6c, 1)) { |
| 189 | printk(KERN_ERR "olpc-ec: timeout waiting for" |
| 190 | " EC to provide data!\n"); |
Paul Fox | 286e5b9 | 2010-10-01 18:17:19 +0100 | [diff] [blame] | 191 | if (restarts++ < 10) |
| 192 | goto restart; |
| 193 | goto err; |
Andres Salomon | 3ef0e1f | 2008-04-29 00:59:53 -0700 | [diff] [blame] | 194 | } |
| 195 | outbuf[i] = inb(0x68); |
Andres Salomon | 2597186 | 2010-06-16 23:19:28 -0400 | [diff] [blame] | 196 | pr_devel("olpc-ec: received 0x%x\n", outbuf[i]); |
Andres Salomon | 3ef0e1f | 2008-04-29 00:59:53 -0700 | [diff] [blame] | 197 | } |
| 198 | } |
| 199 | |
| 200 | ret = 0; |
| 201 | err: |
| 202 | spin_unlock_irqrestore(&ec_lock, flags); |
| 203 | return ret; |
| 204 | } |
Andres Salomon | 392a325 | 2012-07-10 19:31:51 -0700 | [diff] [blame] | 205 | EXPORT_SYMBOL_GPL(olpc_ec_cmd_x86); |
Andres Salomon | 3ef0e1f | 2008-04-29 00:59:53 -0700 | [diff] [blame] | 206 | |
Daniel Drake | bc4ecd5 | 2011-06-25 17:34:13 +0100 | [diff] [blame] | 207 | void olpc_ec_wakeup_set(u16 value) |
| 208 | { |
| 209 | ec_wakeup_mask |= value; |
| 210 | } |
| 211 | EXPORT_SYMBOL_GPL(olpc_ec_wakeup_set); |
| 212 | |
| 213 | void olpc_ec_wakeup_clear(u16 value) |
| 214 | { |
| 215 | ec_wakeup_mask &= ~value; |
| 216 | } |
| 217 | EXPORT_SYMBOL_GPL(olpc_ec_wakeup_clear); |
| 218 | |
| 219 | /* |
| 220 | * Returns true if the compile and runtime configurations allow for EC events |
| 221 | * to wake the system. |
| 222 | */ |
| 223 | bool olpc_ec_wakeup_available(void) |
| 224 | { |
| 225 | if (!machine_is_olpc()) |
| 226 | return false; |
| 227 | |
| 228 | /* |
| 229 | * XO-1 EC wakeups are available when olpc-xo1-sci driver is |
| 230 | * compiled in |
| 231 | */ |
| 232 | #ifdef CONFIG_OLPC_XO1_SCI |
| 233 | if (olpc_platform_info.boardrev < olpc_board_pre(0xd0)) /* XO-1 */ |
| 234 | return true; |
| 235 | #endif |
| 236 | |
Daniel Drake | a0f30f5 | 2011-06-25 17:34:18 +0100 | [diff] [blame] | 237 | /* |
| 238 | * XO-1.5 EC wakeups are available when olpc-xo15-sci driver is |
| 239 | * compiled in |
| 240 | */ |
| 241 | #ifdef CONFIG_OLPC_XO15_SCI |
| 242 | if (olpc_platform_info.boardrev >= olpc_board_pre(0xd0)) /* XO-1.5 */ |
| 243 | return true; |
| 244 | #endif |
| 245 | |
Daniel Drake | bc4ecd5 | 2011-06-25 17:34:13 +0100 | [diff] [blame] | 246 | return false; |
| 247 | } |
| 248 | EXPORT_SYMBOL_GPL(olpc_ec_wakeup_available); |
| 249 | |
| 250 | int olpc_ec_mask_write(u16 bits) |
| 251 | { |
| 252 | if (olpc_platform_info.flags & OLPC_F_EC_WIDE_SCI) { |
| 253 | __be16 ec_word = cpu_to_be16(bits); |
| 254 | return olpc_ec_cmd(EC_WRITE_EXT_SCI_MASK, (void *) &ec_word, 2, |
| 255 | NULL, 0); |
| 256 | } else { |
| 257 | unsigned char ec_byte = bits & 0xff; |
| 258 | return olpc_ec_cmd(EC_WRITE_SCI_MASK, &ec_byte, 1, NULL, 0); |
| 259 | } |
| 260 | } |
| 261 | EXPORT_SYMBOL_GPL(olpc_ec_mask_write); |
| 262 | |
| 263 | int olpc_ec_sci_query(u16 *sci_value) |
| 264 | { |
| 265 | int ret; |
| 266 | |
| 267 | if (olpc_platform_info.flags & OLPC_F_EC_WIDE_SCI) { |
| 268 | __be16 ec_word; |
| 269 | ret = olpc_ec_cmd(EC_EXT_SCI_QUERY, |
| 270 | NULL, 0, (void *) &ec_word, 2); |
| 271 | if (ret == 0) |
| 272 | *sci_value = be16_to_cpu(ec_word); |
| 273 | } else { |
| 274 | unsigned char ec_byte; |
| 275 | ret = olpc_ec_cmd(EC_SCI_QUERY, NULL, 0, &ec_byte, 1); |
| 276 | if (ret == 0) |
| 277 | *sci_value = ec_byte; |
| 278 | } |
| 279 | |
| 280 | return ret; |
| 281 | } |
| 282 | EXPORT_SYMBOL_GPL(olpc_ec_sci_query); |
| 283 | |
Daniel Drake | a3c8121 | 2012-03-27 16:07:40 +0100 | [diff] [blame] | 284 | static ssize_t ec_debugfs_cmd_write(struct file *file, const char __user *buf, |
| 285 | size_t size, loff_t *ppos) |
| 286 | { |
| 287 | int i, m; |
| 288 | unsigned char ec_cmd[EC_MAX_CMD_ARGS]; |
| 289 | unsigned int ec_cmd_int[EC_MAX_CMD_ARGS]; |
| 290 | char cmdbuf[64]; |
| 291 | int ec_cmd_bytes; |
| 292 | |
| 293 | mutex_lock(&ec_debugfs_cmd_lock); |
| 294 | |
| 295 | size = simple_write_to_buffer(cmdbuf, sizeof(cmdbuf), ppos, buf, size); |
| 296 | |
| 297 | m = sscanf(cmdbuf, "%x:%u %x %x %x %x %x", &ec_cmd_int[0], |
| 298 | &ec_debugfs_resp_bytes, |
| 299 | &ec_cmd_int[1], &ec_cmd_int[2], &ec_cmd_int[3], |
| 300 | &ec_cmd_int[4], &ec_cmd_int[5]); |
| 301 | if (m < 2 || ec_debugfs_resp_bytes > EC_MAX_CMD_REPLY) { |
| 302 | /* reset to prevent overflow on read */ |
| 303 | ec_debugfs_resp_bytes = 0; |
| 304 | |
| 305 | printk(KERN_DEBUG "olpc-ec: bad ec cmd: " |
| 306 | "cmd:response-count [arg1 [arg2 ...]]\n"); |
| 307 | size = -EINVAL; |
| 308 | goto out; |
| 309 | } |
| 310 | |
| 311 | /* convert scanf'd ints to char */ |
| 312 | ec_cmd_bytes = m - 2; |
| 313 | for (i = 0; i <= ec_cmd_bytes; i++) |
| 314 | ec_cmd[i] = ec_cmd_int[i]; |
| 315 | |
| 316 | printk(KERN_DEBUG "olpc-ec: debugfs cmd 0x%02x with %d args " |
| 317 | "%02x %02x %02x %02x %02x, want %d returns\n", |
| 318 | ec_cmd[0], ec_cmd_bytes, ec_cmd[1], ec_cmd[2], ec_cmd[3], |
| 319 | ec_cmd[4], ec_cmd[5], ec_debugfs_resp_bytes); |
| 320 | |
| 321 | olpc_ec_cmd(ec_cmd[0], (ec_cmd_bytes == 0) ? NULL : &ec_cmd[1], |
| 322 | ec_cmd_bytes, ec_debugfs_resp, ec_debugfs_resp_bytes); |
| 323 | |
| 324 | printk(KERN_DEBUG "olpc-ec: response " |
| 325 | "%02x %02x %02x %02x %02x %02x %02x %02x (%d bytes expected)\n", |
| 326 | ec_debugfs_resp[0], ec_debugfs_resp[1], ec_debugfs_resp[2], |
| 327 | ec_debugfs_resp[3], ec_debugfs_resp[4], ec_debugfs_resp[5], |
| 328 | ec_debugfs_resp[6], ec_debugfs_resp[7], ec_debugfs_resp_bytes); |
| 329 | |
| 330 | out: |
| 331 | mutex_unlock(&ec_debugfs_cmd_lock); |
| 332 | return size; |
| 333 | } |
| 334 | |
| 335 | static ssize_t ec_debugfs_cmd_read(struct file *file, char __user *buf, |
| 336 | size_t size, loff_t *ppos) |
| 337 | { |
| 338 | unsigned int i, r; |
| 339 | char *rp; |
| 340 | char respbuf[64]; |
| 341 | |
| 342 | mutex_lock(&ec_debugfs_cmd_lock); |
| 343 | rp = respbuf; |
| 344 | rp += sprintf(rp, "%02x", ec_debugfs_resp[0]); |
| 345 | for (i = 1; i < ec_debugfs_resp_bytes; i++) |
| 346 | rp += sprintf(rp, ", %02x", ec_debugfs_resp[i]); |
| 347 | mutex_unlock(&ec_debugfs_cmd_lock); |
| 348 | rp += sprintf(rp, "\n"); |
| 349 | |
| 350 | r = rp - respbuf; |
| 351 | return simple_read_from_buffer(buf, size, ppos, respbuf, r); |
| 352 | } |
| 353 | |
| 354 | static const struct file_operations ec_debugfs_genops = { |
| 355 | .write = ec_debugfs_cmd_write, |
| 356 | .read = ec_debugfs_cmd_read, |
| 357 | }; |
| 358 | |
| 359 | static void setup_debugfs(void) |
| 360 | { |
| 361 | ec_debugfs_dir = debugfs_create_dir("olpc-ec", 0); |
| 362 | if (ec_debugfs_dir == ERR_PTR(-ENODEV)) |
| 363 | return; |
| 364 | |
| 365 | debugfs_create_file("cmd", 0600, ec_debugfs_dir, NULL, |
| 366 | &ec_debugfs_genops); |
| 367 | } |
| 368 | |
Daniel Drake | bc4ecd5 | 2011-06-25 17:34:13 +0100 | [diff] [blame] | 369 | static int olpc_ec_suspend(void) |
| 370 | { |
| 371 | return olpc_ec_mask_write(ec_wakeup_mask); |
| 372 | } |
| 373 | |
Daniel Drake | 45bb167 | 2011-03-13 15:10:17 +0000 | [diff] [blame] | 374 | static bool __init check_ofw_architecture(struct device_node *root) |
Daniel Drake | 3e3c486 | 2010-09-23 17:28:46 +0100 | [diff] [blame] | 375 | { |
Daniel Drake | 45bb167 | 2011-03-13 15:10:17 +0000 | [diff] [blame] | 376 | const char *olpc_arch; |
| 377 | int propsize; |
Daniel Drake | 3e3c486 | 2010-09-23 17:28:46 +0100 | [diff] [blame] | 378 | |
Daniel Drake | 45bb167 | 2011-03-13 15:10:17 +0000 | [diff] [blame] | 379 | olpc_arch = of_get_property(root, "architecture", &propsize); |
Daniel Drake | 3e3c486 | 2010-09-23 17:28:46 +0100 | [diff] [blame] | 380 | return propsize == 5 && strncmp("OLPC", olpc_arch, 5) == 0; |
| 381 | } |
| 382 | |
Daniel Drake | 45bb167 | 2011-03-13 15:10:17 +0000 | [diff] [blame] | 383 | static u32 __init get_board_revision(struct device_node *root) |
Andres Salomon | 3ef0e1f | 2008-04-29 00:59:53 -0700 | [diff] [blame] | 384 | { |
Daniel Drake | 45bb167 | 2011-03-13 15:10:17 +0000 | [diff] [blame] | 385 | int propsize; |
| 386 | const __be32 *rev; |
Andres Salomon | 3ef0e1f | 2008-04-29 00:59:53 -0700 | [diff] [blame] | 387 | |
Daniel Drake | 45bb167 | 2011-03-13 15:10:17 +0000 | [diff] [blame] | 388 | rev = of_get_property(root, "board-revision-int", &propsize); |
| 389 | if (propsize != 4) |
| 390 | return 0; |
| 391 | |
| 392 | return be32_to_cpu(*rev); |
Andres Salomon | 3ef0e1f | 2008-04-29 00:59:53 -0700 | [diff] [blame] | 393 | } |
Daniel Drake | 3e3c486 | 2010-09-23 17:28:46 +0100 | [diff] [blame] | 394 | |
| 395 | static bool __init platform_detect(void) |
Andres Salomon | 3ef0e1f | 2008-04-29 00:59:53 -0700 | [diff] [blame] | 396 | { |
Daniel Drake | 45bb167 | 2011-03-13 15:10:17 +0000 | [diff] [blame] | 397 | struct device_node *root = of_find_node_by_path("/"); |
| 398 | bool success; |
| 399 | |
| 400 | if (!root) |
Daniel Drake | 3e3c486 | 2010-09-23 17:28:46 +0100 | [diff] [blame] | 401 | return false; |
Daniel Drake | 45bb167 | 2011-03-13 15:10:17 +0000 | [diff] [blame] | 402 | |
| 403 | success = check_ofw_architecture(root); |
| 404 | if (success) { |
| 405 | olpc_platform_info.boardrev = get_board_revision(root); |
| 406 | olpc_platform_info.flags |= OLPC_F_PRESENT; |
| 407 | } |
| 408 | |
| 409 | of_node_put(root); |
| 410 | return success; |
Andres Salomon | 3ef0e1f | 2008-04-29 00:59:53 -0700 | [diff] [blame] | 411 | } |
Andres Salomon | 3ef0e1f | 2008-04-29 00:59:53 -0700 | [diff] [blame] | 412 | |
Daniel Drake | 447b1d4 | 2010-10-13 19:10:42 +0100 | [diff] [blame] | 413 | static int __init add_xo1_platform_devices(void) |
| 414 | { |
| 415 | struct platform_device *pdev; |
| 416 | |
| 417 | pdev = platform_device_register_simple("xo1-rfkill", -1, NULL, 0); |
| 418 | if (IS_ERR(pdev)) |
| 419 | return PTR_ERR(pdev); |
| 420 | |
| 421 | pdev = platform_device_register_simple("olpc-xo1", -1, NULL, 0); |
| 422 | if (IS_ERR(pdev)) |
| 423 | return PTR_ERR(pdev); |
| 424 | |
| 425 | return 0; |
| 426 | } |
| 427 | |
Daniel Drake | bc4ecd5 | 2011-06-25 17:34:13 +0100 | [diff] [blame] | 428 | static struct syscore_ops olpc_syscore_ops = { |
| 429 | .suspend = olpc_ec_suspend, |
| 430 | }; |
| 431 | |
Andres Salomon | 3ef0e1f | 2008-04-29 00:59:53 -0700 | [diff] [blame] | 432 | static int __init olpc_init(void) |
| 433 | { |
Daniel Drake | 447b1d4 | 2010-10-13 19:10:42 +0100 | [diff] [blame] | 434 | int r = 0; |
| 435 | |
Daniel Drake | 3e3c486 | 2010-09-23 17:28:46 +0100 | [diff] [blame] | 436 | if (!olpc_ofw_present() || !platform_detect()) |
Andres Salomon | 3ef0e1f | 2008-04-29 00:59:53 -0700 | [diff] [blame] | 437 | return 0; |
| 438 | |
| 439 | spin_lock_init(&ec_lock); |
| 440 | |
Andres Salomon | 3ef0e1f | 2008-04-29 00:59:53 -0700 | [diff] [blame] | 441 | /* assume B1 and above models always have a DCON */ |
| 442 | if (olpc_board_at_least(olpc_board(0xb1))) |
| 443 | olpc_platform_info.flags |= OLPC_F_DCON; |
| 444 | |
| 445 | /* get the EC revision */ |
| 446 | olpc_ec_cmd(EC_FIRMWARE_REV, NULL, 0, |
| 447 | (unsigned char *) &olpc_platform_info.ecver, 1); |
| 448 | |
Thomas Gleixner | d5d0e88 | 2010-02-22 05:42:04 -0800 | [diff] [blame] | 449 | #ifdef CONFIG_PCI_OLPC |
Daniel Drake | 76fb657 | 2010-09-23 17:28:04 +0100 | [diff] [blame] | 450 | /* If the VSA exists let it emulate PCI, if not emulate in kernel. |
| 451 | * XO-1 only. */ |
| 452 | if (olpc_platform_info.boardrev < olpc_board_pre(0xd0) && |
| 453 | !cs5535_has_vsa2()) |
Thomas Gleixner | d5d0e88 | 2010-02-22 05:42:04 -0800 | [diff] [blame] | 454 | x86_init.pci.arch_init = pci_olpc_init; |
| 455 | #endif |
Daniel Drake | bc4ecd5 | 2011-06-25 17:34:13 +0100 | [diff] [blame] | 456 | /* EC version 0x5f adds support for wide SCI mask */ |
| 457 | if (olpc_platform_info.ecver >= 0x5f) |
| 458 | olpc_platform_info.flags |= OLPC_F_EC_WIDE_SCI; |
Andres Salomon | 3ef0e1f | 2008-04-29 00:59:53 -0700 | [diff] [blame] | 459 | |
| 460 | printk(KERN_INFO "OLPC board revision %s%X (EC=%x)\n", |
| 461 | ((olpc_platform_info.boardrev & 0xf) < 8) ? "pre" : "", |
| 462 | olpc_platform_info.boardrev >> 4, |
| 463 | olpc_platform_info.ecver); |
| 464 | |
Daniel Drake | 447b1d4 | 2010-10-13 19:10:42 +0100 | [diff] [blame] | 465 | if (olpc_platform_info.boardrev < olpc_board_pre(0xd0)) { /* XO-1 */ |
| 466 | r = add_xo1_platform_devices(); |
| 467 | if (r) |
| 468 | return r; |
| 469 | } |
| 470 | |
Daniel Drake | bc4ecd5 | 2011-06-25 17:34:13 +0100 | [diff] [blame] | 471 | register_syscore_ops(&olpc_syscore_ops); |
Daniel Drake | a3c8121 | 2012-03-27 16:07:40 +0100 | [diff] [blame] | 472 | setup_debugfs(); |
Daniel Drake | bc4ecd5 | 2011-06-25 17:34:13 +0100 | [diff] [blame] | 473 | |
Andres Salomon | 3ef0e1f | 2008-04-29 00:59:53 -0700 | [diff] [blame] | 474 | return 0; |
| 475 | } |
| 476 | |
| 477 | postcore_initcall(olpc_init); |