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