diff options
| -rw-r--r-- | arch/x86/platform/olpc/olpc.c | 97 | ||||
| -rw-r--r-- | drivers/platform/olpc/olpc-ec.c | 117 |
2 files changed, 117 insertions, 97 deletions
diff --git a/arch/x86/platform/olpc/olpc.c b/arch/x86/platform/olpc/olpc.c index 45900968fb89..ed41b437b37b 100644 --- a/arch/x86/platform/olpc/olpc.c +++ b/arch/x86/platform/olpc/olpc.c | |||
| @@ -19,7 +19,6 @@ | |||
| 19 | #include <linux/platform_device.h> | 19 | #include <linux/platform_device.h> |
| 20 | #include <linux/of.h> | 20 | #include <linux/of.h> |
| 21 | #include <linux/syscore_ops.h> | 21 | #include <linux/syscore_ops.h> |
| 22 | #include <linux/debugfs.h> | ||
| 23 | #include <linux/mutex.h> | 22 | #include <linux/mutex.h> |
| 24 | #include <linux/olpc-ec.h> | 23 | #include <linux/olpc-ec.h> |
| 25 | 24 | ||
| @@ -31,15 +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 | /* 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 | |||
| 43 | /* EC event mask to be applied during suspend (defining wakeup sources). */ | 33 | /* EC event mask to be applied during suspend (defining wakeup sources). */ |
| 44 | static u16 ec_wakeup_mask; | 34 | static u16 ec_wakeup_mask; |
| 45 | 35 | ||
| @@ -273,91 +263,6 @@ int olpc_ec_sci_query(u16 *sci_value) | |||
| 273 | } | 263 | } |
| 274 | EXPORT_SYMBOL_GPL(olpc_ec_sci_query); | 264 | EXPORT_SYMBOL_GPL(olpc_ec_sci_query); |
| 275 | 265 | ||
| 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 | |||
| 361 | static int olpc_ec_suspend(struct platform_device *pdev) | 266 | static int olpc_ec_suspend(struct platform_device *pdev) |
| 362 | { | 267 | { |
| 363 | return olpc_ec_mask_write(ec_wakeup_mask); | 268 | return olpc_ec_mask_write(ec_wakeup_mask); |
| @@ -470,8 +375,6 @@ static int __init olpc_init(void) | |||
| 470 | return r; | 375 | return r; |
| 471 | } | 376 | } |
| 472 | 377 | ||
| 473 | setup_debugfs(); | ||
| 474 | |||
| 475 | return 0; | 378 | return 0; |
| 476 | } | 379 | } |
| 477 | 380 | ||
diff --git a/drivers/platform/olpc/olpc-ec.c b/drivers/platform/olpc/olpc-ec.c index a3d32c2eeb1a..1a15a79fff05 100644 --- a/drivers/platform/olpc/olpc-ec.c +++ b/drivers/platform/olpc/olpc-ec.c | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | * Licensed under the GPL v2 or later. | 6 | * Licensed under the GPL v2 or later. |
| 7 | */ | 7 | */ |
| 8 | #include <linux/completion.h> | 8 | #include <linux/completion.h> |
| 9 | #include <linux/debugfs.h> | ||
| 9 | #include <linux/spinlock.h> | 10 | #include <linux/spinlock.h> |
| 10 | #include <linux/mutex.h> | 11 | #include <linux/mutex.h> |
| 11 | #include <linux/platform_device.h> | 12 | #include <linux/platform_device.h> |
| @@ -31,6 +32,8 @@ struct ec_cmd_desc { | |||
| 31 | struct olpc_ec_priv { | 32 | struct olpc_ec_priv { |
| 32 | struct olpc_ec_driver *drv; | 33 | struct olpc_ec_driver *drv; |
| 33 | 34 | ||
| 35 | struct dentry *dbgfs_dir; | ||
| 36 | |||
| 34 | /* | 37 | /* |
| 35 | * Running an EC command while suspending means we don't always finish | 38 | * Running an EC command while suspending means we don't always finish |
| 36 | * the command before the machine suspends. This means that the EC | 39 | * the command before the machine suspends. This means that the EC |
| @@ -144,6 +147,114 @@ int olpc_ec_cmd(u8 cmd, u8 *inbuf, size_t inlen, u8 *outbuf, size_t outlen) | |||
| 144 | } | 147 | } |
| 145 | EXPORT_SYMBOL_GPL(olpc_ec_cmd); | 148 | EXPORT_SYMBOL_GPL(olpc_ec_cmd); |
| 146 | 149 | ||
| 150 | #ifdef CONFIG_DEBUG_FS | ||
| 151 | |||
| 152 | /* | ||
| 153 | * debugfs support for "generic commands", to allow sending | ||
| 154 | * arbitrary EC commands from userspace. | ||
| 155 | */ | ||
| 156 | |||
| 157 | #define EC_MAX_CMD_ARGS (5 + 1) /* cmd byte + 5 args */ | ||
| 158 | #define EC_MAX_CMD_REPLY (8) | ||
| 159 | |||
| 160 | static DEFINE_MUTEX(ec_dbgfs_lock); | ||
| 161 | static unsigned char ec_dbgfs_resp[EC_MAX_CMD_REPLY]; | ||
| 162 | static unsigned int ec_dbgfs_resp_bytes; | ||
| 163 | |||
| 164 | static ssize_t ec_dbgfs_cmd_write(struct file *file, const char __user *buf, | ||
| 165 | size_t size, loff_t *ppos) | ||
| 166 | { | ||
| 167 | int i, m; | ||
| 168 | unsigned char ec_cmd[EC_MAX_CMD_ARGS]; | ||
| 169 | unsigned int ec_cmd_int[EC_MAX_CMD_ARGS]; | ||
| 170 | char cmdbuf[64]; | ||
| 171 | int ec_cmd_bytes; | ||
| 172 | |||
| 173 | mutex_lock(&ec_dbgfs_lock); | ||
| 174 | |||
| 175 | size = simple_write_to_buffer(cmdbuf, sizeof(cmdbuf), ppos, buf, size); | ||
| 176 | |||
| 177 | m = sscanf(cmdbuf, "%x:%u %x %x %x %x %x", &ec_cmd_int[0], | ||
| 178 | &ec_dbgfs_resp_bytes, &ec_cmd_int[1], &ec_cmd_int[2], | ||
| 179 | &ec_cmd_int[3], &ec_cmd_int[4], &ec_cmd_int[5]); | ||
| 180 | if (m < 2 || ec_dbgfs_resp_bytes > EC_MAX_CMD_REPLY) { | ||
| 181 | /* reset to prevent overflow on read */ | ||
| 182 | ec_dbgfs_resp_bytes = 0; | ||
| 183 | |||
| 184 | pr_debug("olpc-ec: bad ec cmd: cmd:response-count [arg1 [arg2 ...]]\n"); | ||
| 185 | size = -EINVAL; | ||
| 186 | goto out; | ||
| 187 | } | ||
| 188 | |||
| 189 | /* convert scanf'd ints to char */ | ||
| 190 | ec_cmd_bytes = m - 2; | ||
| 191 | for (i = 0; i <= ec_cmd_bytes; i++) | ||
| 192 | ec_cmd[i] = ec_cmd_int[i]; | ||
| 193 | |||
| 194 | pr_debug("olpc-ec: debugfs cmd 0x%02x with %d args %02x %02x %02x %02x %02x, want %d returns\n", | ||
| 195 | ec_cmd[0], ec_cmd_bytes, ec_cmd[1], ec_cmd[2], | ||
| 196 | ec_cmd[3], ec_cmd[4], ec_cmd[5], ec_dbgfs_resp_bytes); | ||
| 197 | |||
| 198 | olpc_ec_cmd(ec_cmd[0], (ec_cmd_bytes == 0) ? NULL : &ec_cmd[1], | ||
| 199 | ec_cmd_bytes, ec_dbgfs_resp, ec_dbgfs_resp_bytes); | ||
| 200 | |||
| 201 | pr_debug("olpc-ec: response %02x %02x %02x %02x %02x %02x %02x %02x (%d bytes expected)\n", | ||
| 202 | ec_dbgfs_resp[0], ec_dbgfs_resp[1], ec_dbgfs_resp[2], | ||
| 203 | ec_dbgfs_resp[3], ec_dbgfs_resp[4], ec_dbgfs_resp[5], | ||
| 204 | ec_dbgfs_resp[6], ec_dbgfs_resp[7], | ||
| 205 | ec_dbgfs_resp_bytes); | ||
| 206 | |||
| 207 | out: | ||
| 208 | mutex_unlock(&ec_dbgfs_lock); | ||
| 209 | return size; | ||
| 210 | } | ||
| 211 | |||
| 212 | static ssize_t ec_dbgfs_cmd_read(struct file *file, char __user *buf, | ||
| 213 | size_t size, loff_t *ppos) | ||
| 214 | { | ||
| 215 | unsigned int i, r; | ||
| 216 | char *rp; | ||
| 217 | char respbuf[64]; | ||
| 218 | |||
| 219 | mutex_lock(&ec_dbgfs_lock); | ||
| 220 | rp = respbuf; | ||
| 221 | rp += sprintf(rp, "%02x", ec_dbgfs_resp[0]); | ||
| 222 | for (i = 1; i < ec_dbgfs_resp_bytes; i++) | ||
| 223 | rp += sprintf(rp, ", %02x", ec_dbgfs_resp[i]); | ||
| 224 | mutex_unlock(&ec_dbgfs_lock); | ||
| 225 | rp += sprintf(rp, "\n"); | ||
| 226 | |||
| 227 | r = rp - respbuf; | ||
| 228 | return simple_read_from_buffer(buf, size, ppos, respbuf, r); | ||
| 229 | } | ||
| 230 | |||
| 231 | static const struct file_operations ec_dbgfs_ops = { | ||
| 232 | .write = ec_dbgfs_cmd_write, | ||
| 233 | .read = ec_dbgfs_cmd_read, | ||
| 234 | }; | ||
| 235 | |||
| 236 | static struct dentry *olpc_ec_setup_debugfs(void) | ||
| 237 | { | ||
| 238 | struct dentry *dbgfs_dir; | ||
| 239 | |||
| 240 | dbgfs_dir = debugfs_create_dir("olpc-ec", NULL); | ||
| 241 | if (IS_ERR_OR_NULL(dbgfs_dir)) | ||
| 242 | return NULL; | ||
| 243 | |||
| 244 | debugfs_create_file("cmd", 0600, dbgfs_dir, NULL, &ec_dbgfs_ops); | ||
| 245 | |||
| 246 | return dbgfs_dir; | ||
| 247 | } | ||
| 248 | |||
| 249 | #else | ||
| 250 | |||
| 251 | static struct dentry *olpc_ec_setup_debugfs(void) | ||
| 252 | { | ||
| 253 | return NULL; | ||
| 254 | } | ||
| 255 | |||
| 256 | #endif /* CONFIG_DEBUG_FS */ | ||
| 257 | |||
| 147 | static int olpc_ec_probe(struct platform_device *pdev) | 258 | static int olpc_ec_probe(struct platform_device *pdev) |
| 148 | { | 259 | { |
| 149 | struct olpc_ec_priv *ec; | 260 | struct olpc_ec_priv *ec; |
| @@ -160,6 +271,12 @@ static int olpc_ec_probe(struct platform_device *pdev) | |||
| 160 | platform_set_drvdata(pdev, ec); | 271 | platform_set_drvdata(pdev, ec); |
| 161 | 272 | ||
| 162 | err = ec_driver->probe ? ec_driver->probe(pdev) : 0; | 273 | err = ec_driver->probe ? ec_driver->probe(pdev) : 0; |
| 274 | if (err) { | ||
| 275 | ec_priv = NULL; | ||
| 276 | kfree(ec); | ||
| 277 | } else { | ||
| 278 | ec->dbgfs_dir = olpc_ec_setup_debugfs(); | ||
| 279 | } | ||
| 163 | 280 | ||
| 164 | return err; | 281 | return err; |
| 165 | } | 282 | } |
