aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/macintosh/via-pmu.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/macintosh/via-pmu.c')
-rw-r--r--drivers/macintosh/via-pmu.c78
1 files changed, 39 insertions, 39 deletions
diff --git a/drivers/macintosh/via-pmu.c b/drivers/macintosh/via-pmu.c
index b941ee220997..4a0a0ad2d03c 100644
--- a/drivers/macintosh/via-pmu.c
+++ b/drivers/macintosh/via-pmu.c
@@ -63,6 +63,10 @@
63#include <asm/backlight.h> 63#include <asm/backlight.h>
64#endif 64#endif
65 65
66#ifdef CONFIG_PPC32
67#include <asm/open_pic.h>
68#endif
69
66/* Some compile options */ 70/* Some compile options */
67#undef SUSPEND_USES_PMU 71#undef SUSPEND_USES_PMU
68#define DEBUG_SLEEP 72#define DEBUG_SLEEP
@@ -151,10 +155,10 @@ static spinlock_t pmu_lock;
151static u8 pmu_intr_mask; 155static u8 pmu_intr_mask;
152static int pmu_version; 156static int pmu_version;
153static int drop_interrupts; 157static int drop_interrupts;
154#ifdef CONFIG_PMAC_PBOOK 158#ifdef CONFIG_PM
155static int option_lid_wakeup = 1; 159static int option_lid_wakeup = 1;
156static int sleep_in_progress; 160static int sleep_in_progress;
157#endif /* CONFIG_PMAC_PBOOK */ 161#endif /* CONFIG_PM */
158static unsigned long async_req_locks; 162static unsigned long async_req_locks;
159static unsigned int pmu_irq_stats[11]; 163static unsigned int pmu_irq_stats[11];
160 164
@@ -164,7 +168,6 @@ static struct proc_dir_entry *proc_pmu_irqstats;
164static struct proc_dir_entry *proc_pmu_options; 168static struct proc_dir_entry *proc_pmu_options;
165static int option_server_mode; 169static int option_server_mode;
166 170
167#ifdef CONFIG_PMAC_PBOOK
168int pmu_battery_count; 171int pmu_battery_count;
169int pmu_cur_battery; 172int pmu_cur_battery;
170unsigned int pmu_power_flags; 173unsigned int pmu_power_flags;
@@ -172,7 +175,6 @@ struct pmu_battery_info pmu_batteries[PMU_MAX_BATTERIES];
172static int query_batt_timer = BATTERY_POLLING_COUNT; 175static int query_batt_timer = BATTERY_POLLING_COUNT;
173static struct adb_request batt_req; 176static struct adb_request batt_req;
174static struct proc_dir_entry *proc_pmu_batt[PMU_MAX_BATTERIES]; 177static struct proc_dir_entry *proc_pmu_batt[PMU_MAX_BATTERIES];
175#endif /* CONFIG_PMAC_PBOOK */
176 178
177#if defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT) 179#if defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT)
178extern int disable_kernel_backlight; 180extern int disable_kernel_backlight;
@@ -206,11 +208,9 @@ static int proc_get_irqstats(char *page, char **start, off_t off,
206static int pmu_set_backlight_level(int level, void* data); 208static int pmu_set_backlight_level(int level, void* data);
207static int pmu_set_backlight_enable(int on, int level, void* data); 209static int pmu_set_backlight_enable(int on, int level, void* data);
208#endif /* CONFIG_PMAC_BACKLIGHT */ 210#endif /* CONFIG_PMAC_BACKLIGHT */
209#ifdef CONFIG_PMAC_PBOOK
210static void pmu_pass_intr(unsigned char *data, int len); 211static void pmu_pass_intr(unsigned char *data, int len);
211static int proc_get_batt(char *page, char **start, off_t off, 212static int proc_get_batt(char *page, char **start, off_t off,
212 int count, int *eof, void *data); 213 int count, int *eof, void *data);
213#endif /* CONFIG_PMAC_PBOOK */
214static int proc_read_options(char *page, char **start, off_t off, 214static int proc_read_options(char *page, char **start, off_t off,
215 int count, int *eof, void *data); 215 int count, int *eof, void *data);
216static int proc_write_options(struct file *file, const char __user *buffer, 216static int proc_write_options(struct file *file, const char __user *buffer,
@@ -403,8 +403,12 @@ static int __init via_pmu_start(void)
403 403
404 bright_req_1.complete = 1; 404 bright_req_1.complete = 1;
405 bright_req_2.complete = 1; 405 bright_req_2.complete = 1;
406#ifdef CONFIG_PMAC_PBOOK
407 batt_req.complete = 1; 406 batt_req.complete = 1;
407
408#ifdef CONFIG_PPC32
409 if (pmu_kind == PMU_KEYLARGO_BASED)
410 openpic_set_irq_priority(vias->intrs[0].line,
411 OPENPIC_PRIORITY_DEFAULT + 1);
408#endif 412#endif
409 413
410 if (request_irq(vias->intrs[0].line, via_pmu_interrupt, 0, "VIA-PMU", 414 if (request_irq(vias->intrs[0].line, via_pmu_interrupt, 0, "VIA-PMU",
@@ -458,7 +462,7 @@ static int __init via_pmu_dev_init(void)
458 register_backlight_controller(&pmu_backlight_controller, NULL, "pmu"); 462 register_backlight_controller(&pmu_backlight_controller, NULL, "pmu");
459#endif /* CONFIG_PMAC_BACKLIGHT */ 463#endif /* CONFIG_PMAC_BACKLIGHT */
460 464
461#ifdef CONFIG_PMAC_PBOOK 465#ifdef CONFIG_PPC32
462 if (machine_is_compatible("AAPL,3400/2400") || 466 if (machine_is_compatible("AAPL,3400/2400") ||
463 machine_is_compatible("AAPL,3500")) { 467 machine_is_compatible("AAPL,3500")) {
464 int mb = pmac_call_feature(PMAC_FTR_GET_MB_INFO, 468 int mb = pmac_call_feature(PMAC_FTR_GET_MB_INFO,
@@ -486,20 +490,19 @@ static int __init via_pmu_dev_init(void)
486 pmu_batteries[1].flags |= PMU_BATT_TYPE_SMART; 490 pmu_batteries[1].flags |= PMU_BATT_TYPE_SMART;
487 } 491 }
488 } 492 }
489#endif /* CONFIG_PMAC_PBOOK */ 493#endif /* CONFIG_PPC32 */
494
490 /* Create /proc/pmu */ 495 /* Create /proc/pmu */
491 proc_pmu_root = proc_mkdir("pmu", NULL); 496 proc_pmu_root = proc_mkdir("pmu", NULL);
492 if (proc_pmu_root) { 497 if (proc_pmu_root) {
493#ifdef CONFIG_PMAC_PBOOK 498 long i;
494 int i;
495 499
496 for (i=0; i<pmu_battery_count; i++) { 500 for (i=0; i<pmu_battery_count; i++) {
497 char title[16]; 501 char title[16];
498 sprintf(title, "battery_%d", i); 502 sprintf(title, "battery_%ld", i);
499 proc_pmu_batt[i] = create_proc_read_entry(title, 0, proc_pmu_root, 503 proc_pmu_batt[i] = create_proc_read_entry(title, 0, proc_pmu_root,
500 proc_get_batt, (void *)i); 504 proc_get_batt, (void *)i);
501 } 505 }
502#endif /* CONFIG_PMAC_PBOOK */
503 506
504 proc_pmu_info = create_proc_read_entry("info", 0, proc_pmu_root, 507 proc_pmu_info = create_proc_read_entry("info", 0, proc_pmu_root,
505 proc_get_info, NULL); 508 proc_get_info, NULL);
@@ -619,8 +622,6 @@ static void pmu_set_server_mode(int server_mode)
619 pmu_wait_complete(&req); 622 pmu_wait_complete(&req);
620} 623}
621 624
622#ifdef CONFIG_PMAC_PBOOK
623
624/* This new version of the code for 2400/3400/3500 powerbooks 625/* This new version of the code for 2400/3400/3500 powerbooks
625 * is inspired from the implementation in gkrellm-pmu 626 * is inspired from the implementation in gkrellm-pmu
626 */ 627 */
@@ -803,8 +804,6 @@ query_battery_state(void)
803 2, PMU_SMART_BATTERY_STATE, pmu_cur_battery+1); 804 2, PMU_SMART_BATTERY_STATE, pmu_cur_battery+1);
804} 805}
805 806
806#endif /* CONFIG_PMAC_PBOOK */
807
808static int __pmac 807static int __pmac
809proc_get_info(char *page, char **start, off_t off, 808proc_get_info(char *page, char **start, off_t off,
810 int count, int *eof, void *data) 809 int count, int *eof, void *data)
@@ -813,11 +812,9 @@ proc_get_info(char *page, char **start, off_t off,
813 812
814 p += sprintf(p, "PMU driver version : %d\n", PMU_DRIVER_VERSION); 813 p += sprintf(p, "PMU driver version : %d\n", PMU_DRIVER_VERSION);
815 p += sprintf(p, "PMU firmware version : %02x\n", pmu_version); 814 p += sprintf(p, "PMU firmware version : %02x\n", pmu_version);
816#ifdef CONFIG_PMAC_PBOOK
817 p += sprintf(p, "AC Power : %d\n", 815 p += sprintf(p, "AC Power : %d\n",
818 ((pmu_power_flags & PMU_PWR_AC_PRESENT) != 0)); 816 ((pmu_power_flags & PMU_PWR_AC_PRESENT) != 0));
819 p += sprintf(p, "Battery count : %d\n", pmu_battery_count); 817 p += sprintf(p, "Battery count : %d\n", pmu_battery_count);
820#endif /* CONFIG_PMAC_PBOOK */
821 818
822 return p - page; 819 return p - page;
823} 820}
@@ -849,12 +846,11 @@ proc_get_irqstats(char *page, char **start, off_t off,
849 return p - page; 846 return p - page;
850} 847}
851 848
852#ifdef CONFIG_PMAC_PBOOK
853static int __pmac 849static int __pmac
854proc_get_batt(char *page, char **start, off_t off, 850proc_get_batt(char *page, char **start, off_t off,
855 int count, int *eof, void *data) 851 int count, int *eof, void *data)
856{ 852{
857 int batnum = (int)data; 853 long batnum = (long)data;
858 char *p = page; 854 char *p = page;
859 855
860 p += sprintf(p, "\n"); 856 p += sprintf(p, "\n");
@@ -873,7 +869,6 @@ proc_get_batt(char *page, char **start, off_t off,
873 869
874 return p - page; 870 return p - page;
875} 871}
876#endif /* CONFIG_PMAC_PBOOK */
877 872
878static int __pmac 873static int __pmac
879proc_read_options(char *page, char **start, off_t off, 874proc_read_options(char *page, char **start, off_t off,
@@ -881,11 +876,11 @@ proc_read_options(char *page, char **start, off_t off,
881{ 876{
882 char *p = page; 877 char *p = page;
883 878
884#ifdef CONFIG_PMAC_PBOOK 879#ifdef CONFIG_PM
885 if (pmu_kind == PMU_KEYLARGO_BASED && 880 if (pmu_kind == PMU_KEYLARGO_BASED &&
886 pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) >= 0) 881 pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) >= 0)
887 p += sprintf(p, "lid_wakeup=%d\n", option_lid_wakeup); 882 p += sprintf(p, "lid_wakeup=%d\n", option_lid_wakeup);
888#endif /* CONFIG_PMAC_PBOOK */ 883#endif
889 if (pmu_kind == PMU_KEYLARGO_BASED) 884 if (pmu_kind == PMU_KEYLARGO_BASED)
890 p += sprintf(p, "server_mode=%d\n", option_server_mode); 885 p += sprintf(p, "server_mode=%d\n", option_server_mode);
891 886
@@ -922,12 +917,12 @@ proc_write_options(struct file *file, const char __user *buffer,
922 *(val++) = 0; 917 *(val++) = 0;
923 while(*val == ' ') 918 while(*val == ' ')
924 val++; 919 val++;
925#ifdef CONFIG_PMAC_PBOOK 920#ifdef CONFIG_PM
926 if (pmu_kind == PMU_KEYLARGO_BASED && 921 if (pmu_kind == PMU_KEYLARGO_BASED &&
927 pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) >= 0) 922 pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) >= 0)
928 if (!strcmp(label, "lid_wakeup")) 923 if (!strcmp(label, "lid_wakeup"))
929 option_lid_wakeup = ((*val) == '1'); 924 option_lid_wakeup = ((*val) == '1');
930#endif /* CONFIG_PMAC_PBOOK */ 925#endif
931 if (pmu_kind == PMU_KEYLARGO_BASED && !strcmp(label, "server_mode")) { 926 if (pmu_kind == PMU_KEYLARGO_BASED && !strcmp(label, "server_mode")) {
932 int new_value; 927 int new_value;
933 new_value = ((*val) == '1'); 928 new_value = ((*val) == '1');
@@ -1422,7 +1417,6 @@ next:
1422 } 1417 }
1423 /* Tick interrupt */ 1418 /* Tick interrupt */
1424 else if ((1 << pirq) & PMU_INT_TICK) { 1419 else if ((1 << pirq) & PMU_INT_TICK) {
1425#ifdef CONFIG_PMAC_PBOOK
1426 /* Environement or tick interrupt, query batteries */ 1420 /* Environement or tick interrupt, query batteries */
1427 if (pmu_battery_count) { 1421 if (pmu_battery_count) {
1428 if ((--query_batt_timer) == 0) { 1422 if ((--query_batt_timer) == 0) {
@@ -1437,7 +1431,6 @@ next:
1437 pmu_pass_intr(data, len); 1431 pmu_pass_intr(data, len);
1438 } else { 1432 } else {
1439 pmu_pass_intr(data, len); 1433 pmu_pass_intr(data, len);
1440#endif /* CONFIG_PMAC_PBOOK */
1441 } 1434 }
1442 goto next; 1435 goto next;
1443} 1436}
@@ -2052,7 +2045,7 @@ pmu_i2c_simple_write(int bus, int addr, u8* data, int len)
2052 return -1; 2045 return -1;
2053} 2046}
2054 2047
2055#ifdef CONFIG_PMAC_PBOOK 2048#ifdef CONFIG_PM
2056 2049
2057static LIST_HEAD(sleep_notifiers); 2050static LIST_HEAD(sleep_notifiers);
2058 2051
@@ -2705,6 +2698,8 @@ powerbook_sleep_3400(void)
2705 return 0; 2698 return 0;
2706} 2699}
2707 2700
2701#endif /* CONFIG_PM */
2702
2708/* 2703/*
2709 * Support for /dev/pmu device 2704 * Support for /dev/pmu device
2710 */ 2705 */
@@ -2884,11 +2879,11 @@ static int __pmac
2884pmu_ioctl(struct inode * inode, struct file *filp, 2879pmu_ioctl(struct inode * inode, struct file *filp,
2885 u_int cmd, u_long arg) 2880 u_int cmd, u_long arg)
2886{ 2881{
2887 struct pmu_private *pp = filp->private_data;
2888 __u32 __user *argp = (__u32 __user *)arg; 2882 __u32 __user *argp = (__u32 __user *)arg;
2889 int error; 2883 int error = -EINVAL;
2890 2884
2891 switch (cmd) { 2885 switch (cmd) {
2886#ifdef CONFIG_PM
2892 case PMU_IOC_SLEEP: 2887 case PMU_IOC_SLEEP:
2893 if (!capable(CAP_SYS_ADMIN)) 2888 if (!capable(CAP_SYS_ADMIN))
2894 return -EACCES; 2889 return -EACCES;
@@ -2910,12 +2905,13 @@ pmu_ioctl(struct inode * inode, struct file *filp,
2910 error = -ENOSYS; 2905 error = -ENOSYS;
2911 } 2906 }
2912 sleep_in_progress = 0; 2907 sleep_in_progress = 0;
2913 return error; 2908 break;
2914 case PMU_IOC_CAN_SLEEP: 2909 case PMU_IOC_CAN_SLEEP:
2915 if (pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) < 0) 2910 if (pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) < 0)
2916 return put_user(0, argp); 2911 return put_user(0, argp);
2917 else 2912 else
2918 return put_user(1, argp); 2913 return put_user(1, argp);
2914#endif /* CONFIG_PM */
2919 2915
2920#ifdef CONFIG_PMAC_BACKLIGHT 2916#ifdef CONFIG_PMAC_BACKLIGHT
2921 /* Backlight should have its own device or go via 2917 /* Backlight should have its own device or go via
@@ -2936,11 +2932,13 @@ pmu_ioctl(struct inode * inode, struct file *filp,
2936 error = get_user(value, argp); 2932 error = get_user(value, argp);
2937 if (!error) 2933 if (!error)
2938 error = set_backlight_level(value); 2934 error = set_backlight_level(value);
2939 return error; 2935 break;
2940 } 2936 }
2941#ifdef CONFIG_INPUT_ADBHID 2937#ifdef CONFIG_INPUT_ADBHID
2942 case PMU_IOC_GRAB_BACKLIGHT: { 2938 case PMU_IOC_GRAB_BACKLIGHT: {
2939 struct pmu_private *pp = filp->private_data;
2943 unsigned long flags; 2940 unsigned long flags;
2941
2944 if (pp->backlight_locker) 2942 if (pp->backlight_locker)
2945 return 0; 2943 return 0;
2946 pp->backlight_locker = 1; 2944 pp->backlight_locker = 1;
@@ -2956,7 +2954,7 @@ pmu_ioctl(struct inode * inode, struct file *filp,
2956 case PMU_IOC_HAS_ADB: 2954 case PMU_IOC_HAS_ADB:
2957 return put_user(pmu_has_adb, argp); 2955 return put_user(pmu_has_adb, argp);
2958 } 2956 }
2959 return -EINVAL; 2957 return error;
2960} 2958}
2961 2959
2962static struct file_operations pmu_device_fops __pmacdata = { 2960static struct file_operations pmu_device_fops __pmacdata = {
@@ -2972,14 +2970,16 @@ static struct miscdevice pmu_device __pmacdata = {
2972 PMU_MINOR, "pmu", &pmu_device_fops 2970 PMU_MINOR, "pmu", &pmu_device_fops
2973}; 2971};
2974 2972
2975void pmu_device_init(void) 2973static int pmu_device_init(void)
2976{ 2974{
2977 if (!via) 2975 if (!via)
2978 return; 2976 return 0;
2979 if (misc_register(&pmu_device) < 0) 2977 if (misc_register(&pmu_device) < 0)
2980 printk(KERN_ERR "via-pmu: cannot register misc device.\n"); 2978 printk(KERN_ERR "via-pmu: cannot register misc device.\n");
2979 return 0;
2981} 2980}
2982#endif /* CONFIG_PMAC_PBOOK */ 2981device_initcall(pmu_device_init);
2982
2983 2983
2984#ifdef DEBUG_SLEEP 2984#ifdef DEBUG_SLEEP
2985static inline void __pmac 2985static inline void __pmac
@@ -3147,12 +3147,12 @@ EXPORT_SYMBOL(pmu_i2c_combined_read);
3147EXPORT_SYMBOL(pmu_i2c_stdsub_write); 3147EXPORT_SYMBOL(pmu_i2c_stdsub_write);
3148EXPORT_SYMBOL(pmu_i2c_simple_read); 3148EXPORT_SYMBOL(pmu_i2c_simple_read);
3149EXPORT_SYMBOL(pmu_i2c_simple_write); 3149EXPORT_SYMBOL(pmu_i2c_simple_write);
3150#ifdef CONFIG_PMAC_PBOOK 3150#ifdef CONFIG_PM
3151EXPORT_SYMBOL(pmu_register_sleep_notifier); 3151EXPORT_SYMBOL(pmu_register_sleep_notifier);
3152EXPORT_SYMBOL(pmu_unregister_sleep_notifier); 3152EXPORT_SYMBOL(pmu_unregister_sleep_notifier);
3153EXPORT_SYMBOL(pmu_enable_irled); 3153EXPORT_SYMBOL(pmu_enable_irled);
3154EXPORT_SYMBOL(pmu_battery_count); 3154EXPORT_SYMBOL(pmu_battery_count);
3155EXPORT_SYMBOL(pmu_batteries); 3155EXPORT_SYMBOL(pmu_batteries);
3156EXPORT_SYMBOL(pmu_power_flags); 3156EXPORT_SYMBOL(pmu_power_flags);
3157#endif /* CONFIG_PMAC_PBOOK */ 3157#endif /* CONFIG_PM */
3158 3158