diff options
author | Alexey Dobriyan <adobriyan@gmail.com> | 2009-12-21 19:20:02 -0500 |
---|---|---|
committer | Len Brown <len.brown@intel.com> | 2009-12-24 00:15:10 -0500 |
commit | 936c8bcd7f5b418d0e040be539ceb4d2ac3bc0b8 (patch) | |
tree | ee491e83c38a12598e0b5af5882669b795b0bdc5 | |
parent | ff93be5dea548f16dcfe7b73ce5df7666efba92d (diff) |
toshiba_acpi: convert to seq_file
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Cc: John W. Linville <linville@tuxdriver.com>
Cc: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Len Brown <len.brown@intel.com>
-rw-r--r-- | drivers/platform/x86/toshiba_acpi.c | 259 |
1 files changed, 147 insertions, 112 deletions
diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c index 51c0a8bee414..77bf5d8f893a 100644 --- a/drivers/platform/x86/toshiba_acpi.c +++ b/drivers/platform/x86/toshiba_acpi.c | |||
@@ -42,6 +42,7 @@ | |||
42 | #include <linux/init.h> | 42 | #include <linux/init.h> |
43 | #include <linux/types.h> | 43 | #include <linux/types.h> |
44 | #include <linux/proc_fs.h> | 44 | #include <linux/proc_fs.h> |
45 | #include <linux/seq_file.h> | ||
45 | #include <linux/backlight.h> | 46 | #include <linux/backlight.h> |
46 | #include <linux/platform_device.h> | 47 | #include <linux/platform_device.h> |
47 | #include <linux/rfkill.h> | 48 | #include <linux/rfkill.h> |
@@ -357,63 +358,6 @@ static int force_fan; | |||
357 | static int last_key_event; | 358 | static int last_key_event; |
358 | static int key_event_valid; | 359 | static int key_event_valid; |
359 | 360 | ||
360 | typedef struct _ProcItem { | ||
361 | const char *name; | ||
362 | char *(*read_func) (char *); | ||
363 | unsigned long (*write_func) (const char *, unsigned long); | ||
364 | } ProcItem; | ||
365 | |||
366 | /* proc file handlers | ||
367 | */ | ||
368 | |||
369 | static int | ||
370 | dispatch_read(char *page, char **start, off_t off, int count, int *eof, | ||
371 | ProcItem * item) | ||
372 | { | ||
373 | char *p = page; | ||
374 | int len; | ||
375 | |||
376 | if (off == 0) | ||
377 | p = item->read_func(p); | ||
378 | |||
379 | /* ISSUE: I don't understand this code */ | ||
380 | len = (p - page); | ||
381 | if (len <= off + count) | ||
382 | *eof = 1; | ||
383 | *start = page + off; | ||
384 | len -= off; | ||
385 | if (len > count) | ||
386 | len = count; | ||
387 | if (len < 0) | ||
388 | len = 0; | ||
389 | return len; | ||
390 | } | ||
391 | |||
392 | static int | ||
393 | dispatch_write(struct file *file, const char __user * buffer, | ||
394 | unsigned long count, ProcItem * item) | ||
395 | { | ||
396 | int result; | ||
397 | char *tmp_buffer; | ||
398 | |||
399 | /* Arg buffer points to userspace memory, which can't be accessed | ||
400 | * directly. Since we're making a copy, zero-terminate the | ||
401 | * destination so that sscanf can be used on it safely. | ||
402 | */ | ||
403 | tmp_buffer = kmalloc(count + 1, GFP_KERNEL); | ||
404 | if (!tmp_buffer) | ||
405 | return -ENOMEM; | ||
406 | |||
407 | if (copy_from_user(tmp_buffer, buffer, count)) { | ||
408 | result = -EFAULT; | ||
409 | } else { | ||
410 | tmp_buffer[count] = 0; | ||
411 | result = item->write_func(tmp_buffer, count); | ||
412 | } | ||
413 | kfree(tmp_buffer); | ||
414 | return result; | ||
415 | } | ||
416 | |||
417 | static int get_lcd(struct backlight_device *bd) | 361 | static int get_lcd(struct backlight_device *bd) |
418 | { | 362 | { |
419 | u32 hci_result; | 363 | u32 hci_result; |
@@ -426,19 +370,24 @@ static int get_lcd(struct backlight_device *bd) | |||
426 | return -EFAULT; | 370 | return -EFAULT; |
427 | } | 371 | } |
428 | 372 | ||
429 | static char *read_lcd(char *p) | 373 | static int lcd_proc_show(struct seq_file *m, void *v) |
430 | { | 374 | { |
431 | int value = get_lcd(NULL); | 375 | int value = get_lcd(NULL); |
432 | 376 | ||
433 | if (value >= 0) { | 377 | if (value >= 0) { |
434 | p += sprintf(p, "brightness: %d\n", value); | 378 | seq_printf(m, "brightness: %d\n", value); |
435 | p += sprintf(p, "brightness_levels: %d\n", | 379 | seq_printf(m, "brightness_levels: %d\n", |
436 | HCI_LCD_BRIGHTNESS_LEVELS); | 380 | HCI_LCD_BRIGHTNESS_LEVELS); |
437 | } else { | 381 | } else { |
438 | printk(MY_ERR "Error reading LCD brightness\n"); | 382 | printk(MY_ERR "Error reading LCD brightness\n"); |
439 | } | 383 | } |
440 | 384 | ||
441 | return p; | 385 | return 0; |
386 | } | ||
387 | |||
388 | static int lcd_proc_open(struct inode *inode, struct file *file) | ||
389 | { | ||
390 | return single_open(file, lcd_proc_show, NULL); | ||
442 | } | 391 | } |
443 | 392 | ||
444 | static int set_lcd(int value) | 393 | static int set_lcd(int value) |
@@ -458,12 +407,20 @@ static int set_lcd_status(struct backlight_device *bd) | |||
458 | return set_lcd(bd->props.brightness); | 407 | return set_lcd(bd->props.brightness); |
459 | } | 408 | } |
460 | 409 | ||
461 | static unsigned long write_lcd(const char *buffer, unsigned long count) | 410 | static ssize_t lcd_proc_write(struct file *file, const char __user *buf, |
411 | size_t count, loff_t *pos) | ||
462 | { | 412 | { |
413 | char cmd[42]; | ||
414 | size_t len; | ||
463 | int value; | 415 | int value; |
464 | int ret; | 416 | int ret; |
465 | 417 | ||
466 | if (sscanf(buffer, " brightness : %i", &value) == 1 && | 418 | len = min(count, sizeof(cmd) - 1); |
419 | if (copy_from_user(cmd, buf, len)) | ||
420 | return -EFAULT; | ||
421 | cmd[len] = '\0'; | ||
422 | |||
423 | if (sscanf(cmd, " brightness : %i", &value) == 1 && | ||
467 | value >= 0 && value < HCI_LCD_BRIGHTNESS_LEVELS) { | 424 | value >= 0 && value < HCI_LCD_BRIGHTNESS_LEVELS) { |
468 | ret = set_lcd(value); | 425 | ret = set_lcd(value); |
469 | if (ret == 0) | 426 | if (ret == 0) |
@@ -474,7 +431,16 @@ static unsigned long write_lcd(const char *buffer, unsigned long count) | |||
474 | return ret; | 431 | return ret; |
475 | } | 432 | } |
476 | 433 | ||
477 | static char *read_video(char *p) | 434 | static const struct file_operations lcd_proc_fops = { |
435 | .owner = THIS_MODULE, | ||
436 | .open = lcd_proc_open, | ||
437 | .read = seq_read, | ||
438 | .llseek = seq_lseek, | ||
439 | .release = single_release, | ||
440 | .write = lcd_proc_write, | ||
441 | }; | ||
442 | |||
443 | static int video_proc_show(struct seq_file *m, void *v) | ||
478 | { | 444 | { |
479 | u32 hci_result; | 445 | u32 hci_result; |
480 | u32 value; | 446 | u32 value; |
@@ -484,18 +450,25 @@ static char *read_video(char *p) | |||
484 | int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0; | 450 | int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0; |
485 | int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0; | 451 | int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0; |
486 | int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0; | 452 | int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0; |
487 | p += sprintf(p, "lcd_out: %d\n", is_lcd); | 453 | seq_printf(m, "lcd_out: %d\n", is_lcd); |
488 | p += sprintf(p, "crt_out: %d\n", is_crt); | 454 | seq_printf(m, "crt_out: %d\n", is_crt); |
489 | p += sprintf(p, "tv_out: %d\n", is_tv); | 455 | seq_printf(m, "tv_out: %d\n", is_tv); |
490 | } else { | 456 | } else { |
491 | printk(MY_ERR "Error reading video out status\n"); | 457 | printk(MY_ERR "Error reading video out status\n"); |
492 | } | 458 | } |
493 | 459 | ||
494 | return p; | 460 | return 0; |
495 | } | 461 | } |
496 | 462 | ||
497 | static unsigned long write_video(const char *buffer, unsigned long count) | 463 | static int video_proc_open(struct inode *inode, struct file *file) |
498 | { | 464 | { |
465 | return single_open(file, video_proc_show, NULL); | ||
466 | } | ||
467 | |||
468 | static ssize_t video_proc_write(struct file *file, const char __user *buf, | ||
469 | size_t count, loff_t *pos) | ||
470 | { | ||
471 | char *cmd, *buffer; | ||
499 | int value; | 472 | int value; |
500 | int remain = count; | 473 | int remain = count; |
501 | int lcd_out = -1; | 474 | int lcd_out = -1; |
@@ -504,6 +477,17 @@ static unsigned long write_video(const char *buffer, unsigned long count) | |||
504 | u32 hci_result; | 477 | u32 hci_result; |
505 | u32 video_out; | 478 | u32 video_out; |
506 | 479 | ||
480 | cmd = kmalloc(count + 1, GFP_KERNEL); | ||
481 | if (!cmd) | ||
482 | return -ENOMEM; | ||
483 | if (copy_from_user(cmd, buf, count)) { | ||
484 | kfree(cmd); | ||
485 | return -EFAULT; | ||
486 | } | ||
487 | cmd[count] = '\0'; | ||
488 | |||
489 | buffer = cmd; | ||
490 | |||
507 | /* scan expression. Multiple expressions may be delimited with ; | 491 | /* scan expression. Multiple expressions may be delimited with ; |
508 | * | 492 | * |
509 | * NOTE: to keep scanning simple, invalid fields are ignored | 493 | * NOTE: to keep scanning simple, invalid fields are ignored |
@@ -523,6 +507,8 @@ static unsigned long write_video(const char *buffer, unsigned long count) | |||
523 | while (remain && *(buffer - 1) != ';'); | 507 | while (remain && *(buffer - 1) != ';'); |
524 | } | 508 | } |
525 | 509 | ||
510 | kfree(cmd); | ||
511 | |||
526 | hci_read1(HCI_VIDEO_OUT, &video_out, &hci_result); | 512 | hci_read1(HCI_VIDEO_OUT, &video_out, &hci_result); |
527 | if (hci_result == HCI_SUCCESS) { | 513 | if (hci_result == HCI_SUCCESS) { |
528 | unsigned int new_video_out = video_out; | 514 | unsigned int new_video_out = video_out; |
@@ -543,28 +529,50 @@ static unsigned long write_video(const char *buffer, unsigned long count) | |||
543 | return count; | 529 | return count; |
544 | } | 530 | } |
545 | 531 | ||
546 | static char *read_fan(char *p) | 532 | static const struct file_operations video_proc_fops = { |
533 | .owner = THIS_MODULE, | ||
534 | .open = video_proc_open, | ||
535 | .read = seq_read, | ||
536 | .llseek = seq_lseek, | ||
537 | .release = single_release, | ||
538 | .write = video_proc_write, | ||
539 | }; | ||
540 | |||
541 | static int fan_proc_show(struct seq_file *m, void *v) | ||
547 | { | 542 | { |
548 | u32 hci_result; | 543 | u32 hci_result; |
549 | u32 value; | 544 | u32 value; |
550 | 545 | ||
551 | hci_read1(HCI_FAN, &value, &hci_result); | 546 | hci_read1(HCI_FAN, &value, &hci_result); |
552 | if (hci_result == HCI_SUCCESS) { | 547 | if (hci_result == HCI_SUCCESS) { |
553 | p += sprintf(p, "running: %d\n", (value > 0)); | 548 | seq_printf(m, "running: %d\n", (value > 0)); |
554 | p += sprintf(p, "force_on: %d\n", force_fan); | 549 | seq_printf(m, "force_on: %d\n", force_fan); |
555 | } else { | 550 | } else { |
556 | printk(MY_ERR "Error reading fan status\n"); | 551 | printk(MY_ERR "Error reading fan status\n"); |
557 | } | 552 | } |
558 | 553 | ||
559 | return p; | 554 | return 0; |
555 | } | ||
556 | |||
557 | static int fan_proc_open(struct inode *inode, struct file *file) | ||
558 | { | ||
559 | return single_open(file, fan_proc_show, NULL); | ||
560 | } | 560 | } |
561 | 561 | ||
562 | static unsigned long write_fan(const char *buffer, unsigned long count) | 562 | static ssize_t fan_proc_write(struct file *file, const char __user *buf, |
563 | size_t count, loff_t *pos) | ||
563 | { | 564 | { |
565 | char cmd[42]; | ||
566 | size_t len; | ||
564 | int value; | 567 | int value; |
565 | u32 hci_result; | 568 | u32 hci_result; |
566 | 569 | ||
567 | if (sscanf(buffer, " force_on : %i", &value) == 1 && | 570 | len = min(count, sizeof(cmd) - 1); |
571 | if (copy_from_user(cmd, buf, len)) | ||
572 | return -EFAULT; | ||
573 | cmd[len] = '\0'; | ||
574 | |||
575 | if (sscanf(cmd, " force_on : %i", &value) == 1 && | ||
568 | value >= 0 && value <= 1) { | 576 | value >= 0 && value <= 1) { |
569 | hci_write1(HCI_FAN, value, &hci_result); | 577 | hci_write1(HCI_FAN, value, &hci_result); |
570 | if (hci_result != HCI_SUCCESS) | 578 | if (hci_result != HCI_SUCCESS) |
@@ -578,7 +586,16 @@ static unsigned long write_fan(const char *buffer, unsigned long count) | |||
578 | return count; | 586 | return count; |
579 | } | 587 | } |
580 | 588 | ||
581 | static char *read_keys(char *p) | 589 | static const struct file_operations fan_proc_fops = { |
590 | .owner = THIS_MODULE, | ||
591 | .open = fan_proc_open, | ||
592 | .read = seq_read, | ||
593 | .llseek = seq_lseek, | ||
594 | .release = single_release, | ||
595 | .write = fan_proc_write, | ||
596 | }; | ||
597 | |||
598 | static int keys_proc_show(struct seq_file *m, void *v) | ||
582 | { | 599 | { |
583 | u32 hci_result; | 600 | u32 hci_result; |
584 | u32 value; | 601 | u32 value; |
@@ -602,18 +619,30 @@ static char *read_keys(char *p) | |||
602 | } | 619 | } |
603 | } | 620 | } |
604 | 621 | ||
605 | p += sprintf(p, "hotkey_ready: %d\n", key_event_valid); | 622 | seq_printf(m, "hotkey_ready: %d\n", key_event_valid); |
606 | p += sprintf(p, "hotkey: 0x%04x\n", last_key_event); | 623 | seq_printf(m, "hotkey: 0x%04x\n", last_key_event); |
624 | end: | ||
625 | return 0; | ||
626 | } | ||
607 | 627 | ||
608 | end: | 628 | static int keys_proc_open(struct inode *inode, struct file *file) |
609 | return p; | 629 | { |
630 | return single_open(file, keys_proc_show, NULL); | ||
610 | } | 631 | } |
611 | 632 | ||
612 | static unsigned long write_keys(const char *buffer, unsigned long count) | 633 | static ssize_t keys_proc_write(struct file *file, const char __user *buf, |
634 | size_t count, loff_t *pos) | ||
613 | { | 635 | { |
636 | char cmd[42]; | ||
637 | size_t len; | ||
614 | int value; | 638 | int value; |
615 | 639 | ||
616 | if (sscanf(buffer, " hotkey_ready : %i", &value) == 1 && value == 0) { | 640 | len = min(count, sizeof(cmd) - 1); |
641 | if (copy_from_user(cmd, buf, len)) | ||
642 | return -EFAULT; | ||
643 | cmd[len] = '\0'; | ||
644 | |||
645 | if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0) { | ||
617 | key_event_valid = 0; | 646 | key_event_valid = 0; |
618 | } else { | 647 | } else { |
619 | return -EINVAL; | 648 | return -EINVAL; |
@@ -622,52 +651,58 @@ static unsigned long write_keys(const char *buffer, unsigned long count) | |||
622 | return count; | 651 | return count; |
623 | } | 652 | } |
624 | 653 | ||
625 | static char *read_version(char *p) | 654 | static const struct file_operations keys_proc_fops = { |
655 | .owner = THIS_MODULE, | ||
656 | .open = keys_proc_open, | ||
657 | .read = seq_read, | ||
658 | .llseek = seq_lseek, | ||
659 | .release = single_release, | ||
660 | .write = keys_proc_write, | ||
661 | }; | ||
662 | |||
663 | static int version_proc_show(struct seq_file *m, void *v) | ||
626 | { | 664 | { |
627 | p += sprintf(p, "driver: %s\n", TOSHIBA_ACPI_VERSION); | 665 | seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION); |
628 | p += sprintf(p, "proc_interface: %d\n", | 666 | seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION); |
629 | PROC_INTERFACE_VERSION); | 667 | return 0; |
630 | return p; | ||
631 | } | 668 | } |
632 | 669 | ||
670 | static int version_proc_open(struct inode *inode, struct file *file) | ||
671 | { | ||
672 | return single_open(file, version_proc_show, PDE(inode)->data); | ||
673 | } | ||
674 | |||
675 | static const struct file_operations version_proc_fops = { | ||
676 | .owner = THIS_MODULE, | ||
677 | .open = version_proc_open, | ||
678 | .read = seq_read, | ||
679 | .llseek = seq_lseek, | ||
680 | .release = single_release, | ||
681 | }; | ||
682 | |||
633 | /* proc and module init | 683 | /* proc and module init |
634 | */ | 684 | */ |
635 | 685 | ||
636 | #define PROC_TOSHIBA "toshiba" | 686 | #define PROC_TOSHIBA "toshiba" |
637 | 687 | ||
638 | static ProcItem proc_items[] = { | ||
639 | {"lcd", read_lcd, write_lcd}, | ||
640 | {"video", read_video, write_video}, | ||
641 | {"fan", read_fan, write_fan}, | ||
642 | {"keys", read_keys, write_keys}, | ||
643 | {"version", read_version, NULL}, | ||
644 | {NULL} | ||
645 | }; | ||
646 | |||
647 | static acpi_status __init add_device(void) | 688 | static acpi_status __init add_device(void) |
648 | { | 689 | { |
649 | struct proc_dir_entry *proc; | 690 | proc_create("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir, &lcd_proc_fops); |
650 | ProcItem *item; | 691 | proc_create("video", S_IRUGO | S_IWUSR, toshiba_proc_dir, &video_proc_fops); |
651 | 692 | proc_create("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir, &fan_proc_fops); | |
652 | for (item = proc_items; item->name; ++item) { | 693 | proc_create("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir, &keys_proc_fops); |
653 | proc = create_proc_read_entry(item->name, | 694 | proc_create("version", S_IRUGO, toshiba_proc_dir, &version_proc_fops); |
654 | S_IFREG | S_IRUGO | S_IWUSR, | ||
655 | toshiba_proc_dir, | ||
656 | (read_proc_t *) dispatch_read, | ||
657 | item); | ||
658 | if (proc && item->write_func) | ||
659 | proc->write_proc = (write_proc_t *) dispatch_write; | ||
660 | } | ||
661 | 695 | ||
662 | return AE_OK; | 696 | return AE_OK; |
663 | } | 697 | } |
664 | 698 | ||
665 | static acpi_status remove_device(void) | 699 | static acpi_status remove_device(void) |
666 | { | 700 | { |
667 | ProcItem *item; | 701 | remove_proc_entry("lcd", toshiba_proc_dir); |
668 | 702 | remove_proc_entry("video", toshiba_proc_dir); | |
669 | for (item = proc_items; item->name; ++item) | 703 | remove_proc_entry("fan", toshiba_proc_dir); |
670 | remove_proc_entry(item->name, toshiba_proc_dir); | 704 | remove_proc_entry("keys", toshiba_proc_dir); |
705 | remove_proc_entry("version", toshiba_proc_dir); | ||
671 | return AE_OK; | 706 | return AE_OK; |
672 | } | 707 | } |
673 | 708 | ||