diff options
author | Alexey Dobriyan <adobriyan@gmail.com> | 2009-11-26 15:53:06 -0500 |
---|---|---|
committer | Benjamin Herrenschmidt <benh@kernel.crashing.org> | 2009-12-07 23:59:34 -0500 |
commit | 9d2f7342d08896338890904351490739c1035d43 (patch) | |
tree | 22e47eaaf8c5fe307397f6993dd89f98eb49365b /drivers/macintosh/via-pmu.c | |
parent | d28513bc7f675d28b479db666d572e078ecf182d (diff) |
powerpc/via-pmu: Convert to proc_fops/seq_file
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Diffstat (limited to 'drivers/macintosh/via-pmu.c')
-rw-r--r-- | drivers/macintosh/via-pmu.c | 160 |
1 files changed, 91 insertions, 69 deletions
diff --git a/drivers/macintosh/via-pmu.c b/drivers/macintosh/via-pmu.c index 6f308a4757e..db379c38143 100644 --- a/drivers/macintosh/via-pmu.c +++ b/drivers/macintosh/via-pmu.c | |||
@@ -36,6 +36,7 @@ | |||
36 | #include <linux/spinlock.h> | 36 | #include <linux/spinlock.h> |
37 | #include <linux/pm.h> | 37 | #include <linux/pm.h> |
38 | #include <linux/proc_fs.h> | 38 | #include <linux/proc_fs.h> |
39 | #include <linux/seq_file.h> | ||
39 | #include <linux/init.h> | 40 | #include <linux/init.h> |
40 | #include <linux/interrupt.h> | 41 | #include <linux/interrupt.h> |
41 | #include <linux/device.h> | 42 | #include <linux/device.h> |
@@ -186,17 +187,11 @@ static int init_pmu(void); | |||
186 | static void pmu_start(void); | 187 | static void pmu_start(void); |
187 | static irqreturn_t via_pmu_interrupt(int irq, void *arg); | 188 | static irqreturn_t via_pmu_interrupt(int irq, void *arg); |
188 | static irqreturn_t gpio1_interrupt(int irq, void *arg); | 189 | static irqreturn_t gpio1_interrupt(int irq, void *arg); |
189 | static int proc_get_info(char *page, char **start, off_t off, | 190 | static const struct file_operations pmu_info_proc_fops; |
190 | int count, int *eof, void *data); | 191 | static const struct file_operations pmu_irqstats_proc_fops; |
191 | static int proc_get_irqstats(char *page, char **start, off_t off, | ||
192 | int count, int *eof, void *data); | ||
193 | static void pmu_pass_intr(unsigned char *data, int len); | 192 | static void pmu_pass_intr(unsigned char *data, int len); |
194 | static int proc_get_batt(char *page, char **start, off_t off, | 193 | static const struct file_operations pmu_battery_proc_fops; |
195 | int count, int *eof, void *data); | 194 | static const struct file_operations pmu_options_proc_fops; |
196 | static int proc_read_options(char *page, char **start, off_t off, | ||
197 | int count, int *eof, void *data); | ||
198 | static int proc_write_options(struct file *file, const char __user *buffer, | ||
199 | unsigned long count, void *data); | ||
200 | 195 | ||
201 | #ifdef CONFIG_ADB | 196 | #ifdef CONFIG_ADB |
202 | struct adb_driver via_pmu_driver = { | 197 | struct adb_driver via_pmu_driver = { |
@@ -507,19 +502,15 @@ static int __init via_pmu_dev_init(void) | |||
507 | for (i=0; i<pmu_battery_count; i++) { | 502 | for (i=0; i<pmu_battery_count; i++) { |
508 | char title[16]; | 503 | char title[16]; |
509 | sprintf(title, "battery_%ld", i); | 504 | sprintf(title, "battery_%ld", i); |
510 | proc_pmu_batt[i] = create_proc_read_entry(title, 0, proc_pmu_root, | 505 | proc_pmu_batt[i] = proc_create_data(title, 0, proc_pmu_root, |
511 | proc_get_batt, (void *)i); | 506 | &pmu_battery_proc_fops, (void *)i); |
512 | } | 507 | } |
513 | 508 | ||
514 | proc_pmu_info = create_proc_read_entry("info", 0, proc_pmu_root, | 509 | proc_pmu_info = proc_create("info", 0, proc_pmu_root, &pmu_info_proc_fops); |
515 | proc_get_info, NULL); | 510 | proc_pmu_irqstats = proc_create("interrupts", 0, proc_pmu_root, |
516 | proc_pmu_irqstats = create_proc_read_entry("interrupts", 0, proc_pmu_root, | 511 | &pmu_irqstats_proc_fops); |
517 | proc_get_irqstats, NULL); | 512 | proc_pmu_options = proc_create("options", 0600, proc_pmu_root, |
518 | proc_pmu_options = create_proc_entry("options", 0600, proc_pmu_root); | 513 | &pmu_options_proc_fops); |
519 | if (proc_pmu_options) { | ||
520 | proc_pmu_options->read_proc = proc_read_options; | ||
521 | proc_pmu_options->write_proc = proc_write_options; | ||
522 | } | ||
523 | } | 514 | } |
524 | return 0; | 515 | return 0; |
525 | } | 516 | } |
@@ -799,27 +790,33 @@ query_battery_state(void) | |||
799 | 2, PMU_SMART_BATTERY_STATE, pmu_cur_battery+1); | 790 | 2, PMU_SMART_BATTERY_STATE, pmu_cur_battery+1); |
800 | } | 791 | } |
801 | 792 | ||
802 | static int | 793 | static int pmu_info_proc_show(struct seq_file *m, void *v) |
803 | proc_get_info(char *page, char **start, off_t off, | ||
804 | int count, int *eof, void *data) | ||
805 | { | 794 | { |
806 | char* p = page; | 795 | seq_printf(m, "PMU driver version : %d\n", PMU_DRIVER_VERSION); |
807 | 796 | seq_printf(m, "PMU firmware version : %02x\n", pmu_version); | |
808 | p += sprintf(p, "PMU driver version : %d\n", PMU_DRIVER_VERSION); | 797 | seq_printf(m, "AC Power : %d\n", |
809 | p += sprintf(p, "PMU firmware version : %02x\n", pmu_version); | ||
810 | p += sprintf(p, "AC Power : %d\n", | ||
811 | ((pmu_power_flags & PMU_PWR_AC_PRESENT) != 0) || pmu_battery_count == 0); | 798 | ((pmu_power_flags & PMU_PWR_AC_PRESENT) != 0) || pmu_battery_count == 0); |
812 | p += sprintf(p, "Battery count : %d\n", pmu_battery_count); | 799 | seq_printf(m, "Battery count : %d\n", pmu_battery_count); |
800 | |||
801 | return 0; | ||
802 | } | ||
813 | 803 | ||
814 | return p - page; | 804 | static int pmu_info_proc_open(struct inode *inode, struct file *file) |
805 | { | ||
806 | return single_open(file, pmu_info_proc_show, NULL); | ||
815 | } | 807 | } |
816 | 808 | ||
817 | static int | 809 | static const struct file_operations pmu_info_proc_fops = { |
818 | proc_get_irqstats(char *page, char **start, off_t off, | 810 | .owner = THIS_MODULE, |
819 | int count, int *eof, void *data) | 811 | .open = pmu_info_proc_open, |
812 | .read = seq_read, | ||
813 | .llseek = seq_lseek, | ||
814 | .release = single_release, | ||
815 | }; | ||
816 | |||
817 | static int pmu_irqstats_proc_show(struct seq_file *m, void *v) | ||
820 | { | 818 | { |
821 | int i; | 819 | int i; |
822 | char* p = page; | ||
823 | static const char *irq_names[] = { | 820 | static const char *irq_names[] = { |
824 | "Total CB1 triggered events", | 821 | "Total CB1 triggered events", |
825 | "Total GPIO1 triggered events", | 822 | "Total GPIO1 triggered events", |
@@ -835,60 +832,76 @@ proc_get_irqstats(char *page, char **start, off_t off, | |||
835 | }; | 832 | }; |
836 | 833 | ||
837 | for (i=0; i<11; i++) { | 834 | for (i=0; i<11; i++) { |
838 | p += sprintf(p, " %2u: %10u (%s)\n", | 835 | seq_printf(m, " %2u: %10u (%s)\n", |
839 | i, pmu_irq_stats[i], irq_names[i]); | 836 | i, pmu_irq_stats[i], irq_names[i]); |
840 | } | 837 | } |
841 | return p - page; | 838 | return 0; |
842 | } | 839 | } |
843 | 840 | ||
844 | static int | 841 | static int pmu_irqstats_proc_open(struct inode *inode, struct file *file) |
845 | proc_get_batt(char *page, char **start, off_t off, | ||
846 | int count, int *eof, void *data) | ||
847 | { | 842 | { |
848 | long batnum = (long)data; | 843 | return single_open(file, pmu_irqstats_proc_show, NULL); |
849 | char *p = page; | 844 | } |
845 | |||
846 | static const struct file_operations pmu_irqstats_proc_fops = { | ||
847 | .owner = THIS_MODULE, | ||
848 | .open = pmu_irqstats_proc_open, | ||
849 | .read = seq_read, | ||
850 | .llseek = seq_lseek, | ||
851 | .release = single_release, | ||
852 | }; | ||
853 | |||
854 | static int pmu_battery_proc_show(struct seq_file *m, void *v) | ||
855 | { | ||
856 | long batnum = (long)m->private; | ||
850 | 857 | ||
851 | p += sprintf(p, "\n"); | 858 | seq_putc(m, '\n'); |
852 | p += sprintf(p, "flags : %08x\n", | 859 | seq_printf(m, "flags : %08x\n", pmu_batteries[batnum].flags); |
853 | pmu_batteries[batnum].flags); | 860 | seq_printf(m, "charge : %d\n", pmu_batteries[batnum].charge); |
854 | p += sprintf(p, "charge : %d\n", | 861 | seq_printf(m, "max_charge : %d\n", pmu_batteries[batnum].max_charge); |
855 | pmu_batteries[batnum].charge); | 862 | seq_printf(m, "current : %d\n", pmu_batteries[batnum].amperage); |
856 | p += sprintf(p, "max_charge : %d\n", | 863 | seq_printf(m, "voltage : %d\n", pmu_batteries[batnum].voltage); |
857 | pmu_batteries[batnum].max_charge); | 864 | seq_printf(m, "time rem. : %d\n", pmu_batteries[batnum].time_remaining); |
858 | p += sprintf(p, "current : %d\n", | 865 | return 0; |
859 | pmu_batteries[batnum].amperage); | ||
860 | p += sprintf(p, "voltage : %d\n", | ||
861 | pmu_batteries[batnum].voltage); | ||
862 | p += sprintf(p, "time rem. : %d\n", | ||
863 | pmu_batteries[batnum].time_remaining); | ||
864 | |||
865 | return p - page; | ||
866 | } | 866 | } |
867 | 867 | ||
868 | static int | 868 | static int pmu_battery_proc_open(struct inode *inode, struct file *file) |
869 | proc_read_options(char *page, char **start, off_t off, | ||
870 | int count, int *eof, void *data) | ||
871 | { | 869 | { |
872 | char *p = page; | 870 | return single_open(file, pmu_battery_proc_show, PDE(inode)->data); |
871 | } | ||
873 | 872 | ||
873 | static const struct file_operations pmu_battery_proc_fops = { | ||
874 | .owner = THIS_MODULE, | ||
875 | .open = pmu_battery_proc_open, | ||
876 | .read = seq_read, | ||
877 | .llseek = seq_lseek, | ||
878 | .release = single_release, | ||
879 | }; | ||
880 | |||
881 | static int pmu_options_proc_show(struct seq_file *m, void *v) | ||
882 | { | ||
874 | #if defined(CONFIG_SUSPEND) && defined(CONFIG_PPC32) | 883 | #if defined(CONFIG_SUSPEND) && defined(CONFIG_PPC32) |
875 | if (pmu_kind == PMU_KEYLARGO_BASED && | 884 | if (pmu_kind == PMU_KEYLARGO_BASED && |
876 | pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) >= 0) | 885 | pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) >= 0) |
877 | p += sprintf(p, "lid_wakeup=%d\n", option_lid_wakeup); | 886 | seq_printf(m, "lid_wakeup=%d\n", option_lid_wakeup); |
878 | #endif | 887 | #endif |
879 | if (pmu_kind == PMU_KEYLARGO_BASED) | 888 | if (pmu_kind == PMU_KEYLARGO_BASED) |
880 | p += sprintf(p, "server_mode=%d\n", option_server_mode); | 889 | seq_printf(m, "server_mode=%d\n", option_server_mode); |
881 | 890 | ||
882 | return p - page; | 891 | return 0; |
883 | } | 892 | } |
884 | 893 | ||
885 | static int | 894 | static int pmu_options_proc_open(struct inode *inode, struct file *file) |
886 | proc_write_options(struct file *file, const char __user *buffer, | 895 | { |
887 | unsigned long count, void *data) | 896 | return single_open(file, pmu_options_proc_show, NULL); |
897 | } | ||
898 | |||
899 | static ssize_t pmu_options_proc_write(struct file *file, | ||
900 | const char __user *buffer, size_t count, loff_t *pos) | ||
888 | { | 901 | { |
889 | char tmp[33]; | 902 | char tmp[33]; |
890 | char *label, *val; | 903 | char *label, *val; |
891 | unsigned long fcount = count; | 904 | size_t fcount = count; |
892 | 905 | ||
893 | if (!count) | 906 | if (!count) |
894 | return -EINVAL; | 907 | return -EINVAL; |
@@ -927,6 +940,15 @@ proc_write_options(struct file *file, const char __user *buffer, | |||
927 | return fcount; | 940 | return fcount; |
928 | } | 941 | } |
929 | 942 | ||
943 | static const struct file_operations pmu_options_proc_fops = { | ||
944 | .owner = THIS_MODULE, | ||
945 | .open = pmu_options_proc_open, | ||
946 | .read = seq_read, | ||
947 | .llseek = seq_lseek, | ||
948 | .release = single_release, | ||
949 | .write = pmu_options_proc_write, | ||
950 | }; | ||
951 | |||
930 | #ifdef CONFIG_ADB | 952 | #ifdef CONFIG_ADB |
931 | /* Send an ADB command */ | 953 | /* Send an ADB command */ |
932 | static int pmu_send_request(struct adb_request *req, int sync) | 954 | static int pmu_send_request(struct adb_request *req, int sync) |