via-pmu.c (4e0c1159d83a658d1ffba5bc3442f4ec4cadb436) | via-pmu.c (14cf11af6cf608eb8c23e989ddb17a715ddce109) |
---|---|
1/* 2 * Device driver for the via-pmu on Apple Powermacs. 3 * 4 * The VIA (versatile interface adapter) interfaces to the PMU, 5 * a 6805 microprocessor core whose primary function is to control 6 * battery charging and system power on the PowerBook 3400 and 2400. 7 * The PMU also controls the ADB (Apple Desktop Bus) which connects 8 * to the keyboard and mouse, as well as the non-volatile RAM --- 230 unchanged lines hidden (view full) --- 239 240/* 241 * This table indicates for each PMU opcode: 242 * - the number of data bytes to be sent with the command, or -1 243 * if a length byte should be sent, 244 * - the number of response bytes which the PMU will return, or 245 * -1 if it will send a length byte. 246 */ | 1/* 2 * Device driver for the via-pmu on Apple Powermacs. 3 * 4 * The VIA (versatile interface adapter) interfaces to the PMU, 5 * a 6805 microprocessor core whose primary function is to control 6 * battery charging and system power on the PowerBook 3400 and 2400. 7 * The PMU also controls the ADB (Apple Desktop Bus) which connects 8 * to the keyboard and mouse, as well as the non-volatile RAM --- 230 unchanged lines hidden (view full) --- 239 240/* 241 * This table indicates for each PMU opcode: 242 * - the number of data bytes to be sent with the command, or -1 243 * if a length byte should be sent, 244 * - the number of response bytes which the PMU will return, or 245 * -1 if it will send a length byte. 246 */ |
247static const s8 pmu_data_len[256][2] __openfirmwaredata = { | 247static const s8 pmu_data_len[256][2] = { |
248/* 0 1 2 3 4 5 6 7 */ 249/*00*/ {-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0}, 250/*08*/ {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1}, 251/*10*/ { 1, 0},{ 1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0}, 252/*18*/ { 0, 1},{ 0, 1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{ 0, 0}, 253/*20*/ {-1, 0},{ 0, 0},{ 2, 0},{ 1, 0},{ 1, 0},{-1, 0},{-1, 0},{-1, 0}, 254/*28*/ { 0,-1},{ 0,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{ 0,-1}, 255/*30*/ { 4, 0},{20, 0},{-1, 0},{ 3, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0}, --- 34 unchanged lines hidden (view full) --- 290 291#ifdef CONFIG_PMAC_BACKLIGHT 292static struct backlight_controller pmu_backlight_controller = { 293 pmu_set_backlight_enable, 294 pmu_set_backlight_level 295}; 296#endif /* CONFIG_PMAC_BACKLIGHT */ 297 | 248/* 0 1 2 3 4 5 6 7 */ 249/*00*/ {-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0}, 250/*08*/ {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1}, 251/*10*/ { 1, 0},{ 1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0}, 252/*18*/ { 0, 1},{ 0, 1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{ 0, 0}, 253/*20*/ {-1, 0},{ 0, 0},{ 2, 0},{ 1, 0},{ 1, 0},{-1, 0},{-1, 0},{-1, 0}, 254/*28*/ { 0,-1},{ 0,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{ 0,-1}, 255/*30*/ { 4, 0},{20, 0},{-1, 0},{ 3, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0}, --- 34 unchanged lines hidden (view full) --- 290 291#ifdef CONFIG_PMAC_BACKLIGHT 292static struct backlight_controller pmu_backlight_controller = { 293 pmu_set_backlight_enable, 294 pmu_set_backlight_level 295}; 296#endif /* CONFIG_PMAC_BACKLIGHT */ 297 |
298int __openfirmware | 298int |
299find_via_pmu(void) 300{ 301 if (via != 0) 302 return 1; 303 vias = find_devices("via-pmu"); 304 if (vias == 0) 305 return 0; 306 if (vias->next != 0) --- 62 unchanged lines hidden (view full) --- 369 PMU_DRIVER_VERSION, pbook_type[pmu_kind], pmu_version); 370 371 sys_ctrler = SYS_CTRLER_PMU; 372 373 return 1; 374} 375 376#ifdef CONFIG_ADB | 299find_via_pmu(void) 300{ 301 if (via != 0) 302 return 1; 303 vias = find_devices("via-pmu"); 304 if (vias == 0) 305 return 0; 306 if (vias->next != 0) --- 62 unchanged lines hidden (view full) --- 369 PMU_DRIVER_VERSION, pbook_type[pmu_kind], pmu_version); 370 371 sys_ctrler = SYS_CTRLER_PMU; 372 373 return 1; 374} 375 376#ifdef CONFIG_ADB |
377static int __openfirmware | 377static int |
378pmu_probe(void) 379{ 380 return vias == NULL? -ENODEV: 0; 381} 382 383static int __init 384pmu_init(void) 385{ --- 14 unchanged lines hidden (view full) --- 400{ 401 if (vias == NULL) 402 return -ENODEV; 403 404 bright_req_1.complete = 1; 405 bright_req_2.complete = 1; 406 batt_req.complete = 1; 407 | 378pmu_probe(void) 379{ 380 return vias == NULL? -ENODEV: 0; 381} 382 383static int __init 384pmu_init(void) 385{ --- 14 unchanged lines hidden (view full) --- 400{ 401 if (vias == NULL) 402 return -ENODEV; 403 404 bright_req_1.complete = 1; 405 bright_req_2.complete = 1; 406 batt_req.complete = 1; 407 |
408#ifdef CONFIG_PPC32 | 408#if defined(CONFIG_PPC32) && !defined(CONFIG_PPC_MERGE) |
409 if (pmu_kind == PMU_KEYLARGO_BASED) 410 openpic_set_irq_priority(vias->intrs[0].line, 411 OPENPIC_PRIORITY_DEFAULT + 1); 412#endif 413 414 if (request_irq(vias->intrs[0].line, via_pmu_interrupt, 0, "VIA-PMU", 415 (void *)0)) { 416 printk(KERN_ERR "VIA-PMU: can't get irq %d\n", --- 98 unchanged lines hidden (view full) --- 515 proc_pmu_options->write_proc = proc_write_options; 516 } 517 } 518 return 0; 519} 520 521device_initcall(via_pmu_dev_init); 522 | 409 if (pmu_kind == PMU_KEYLARGO_BASED) 410 openpic_set_irq_priority(vias->intrs[0].line, 411 OPENPIC_PRIORITY_DEFAULT + 1); 412#endif 413 414 if (request_irq(vias->intrs[0].line, via_pmu_interrupt, 0, "VIA-PMU", 415 (void *)0)) { 416 printk(KERN_ERR "VIA-PMU: can't get irq %d\n", --- 98 unchanged lines hidden (view full) --- 515 proc_pmu_options->write_proc = proc_write_options; 516 } 517 } 518 return 0; 519} 520 521device_initcall(via_pmu_dev_init); 522 |
523static int __openfirmware | 523static int |
524init_pmu(void) 525{ 526 int timeout; 527 struct adb_request req; 528 529 out_8(&via[B], via[B] | TREQ); /* negate TREQ */ 530 out_8(&via[DIRB], (via[DIRB] | TREQ) & ~TACK); /* TACK in, TREQ out */ 531 --- 88 unchanged lines hidden (view full) --- 620 PMU_PWR_CLR_POWERUP_EVENTS, 621 req.reply[0], PMU_PWR_WAKEUP_AC_INSERT); 622 pmu_wait_complete(&req); 623} 624 625/* This new version of the code for 2400/3400/3500 powerbooks 626 * is inspired from the implementation in gkrellm-pmu 627 */ | 524init_pmu(void) 525{ 526 int timeout; 527 struct adb_request req; 528 529 out_8(&via[B], via[B] | TREQ); /* negate TREQ */ 530 out_8(&via[DIRB], (via[DIRB] | TREQ) & ~TACK); /* TACK in, TREQ out */ 531 --- 88 unchanged lines hidden (view full) --- 620 PMU_PWR_CLR_POWERUP_EVENTS, 621 req.reply[0], PMU_PWR_WAKEUP_AC_INSERT); 622 pmu_wait_complete(&req); 623} 624 625/* This new version of the code for 2400/3400/3500 powerbooks 626 * is inspired from the implementation in gkrellm-pmu 627 */ |
628static void __pmac | 628static void |
629done_battery_state_ohare(struct adb_request* req) 630{ 631 /* format: 632 * [0] : flags 633 * 0x01 : AC indicator 634 * 0x02 : charging 635 * 0x04 : battery exist 636 * 0x08 : --- 71 unchanged lines hidden (view full) --- 708 pmu_batteries[pmu_cur_battery].max_charge = max; 709 pmu_batteries[pmu_cur_battery].amperage = amperage; 710 pmu_batteries[pmu_cur_battery].voltage = voltage; 711 pmu_batteries[pmu_cur_battery].time_remaining = time; 712 713 clear_bit(0, &async_req_locks); 714} 715 | 629done_battery_state_ohare(struct adb_request* req) 630{ 631 /* format: 632 * [0] : flags 633 * 0x01 : AC indicator 634 * 0x02 : charging 635 * 0x04 : battery exist 636 * 0x08 : --- 71 unchanged lines hidden (view full) --- 708 pmu_batteries[pmu_cur_battery].max_charge = max; 709 pmu_batteries[pmu_cur_battery].amperage = amperage; 710 pmu_batteries[pmu_cur_battery].voltage = voltage; 711 pmu_batteries[pmu_cur_battery].time_remaining = time; 712 713 clear_bit(0, &async_req_locks); 714} 715 |
716static void __pmac | 716static void |
717done_battery_state_smart(struct adb_request* req) 718{ 719 /* format: 720 * [0] : format of this structure (known: 3,4,5) 721 * [1] : flags 722 * 723 * format 3 & 4: 724 * --- 61 unchanged lines hidden (view full) --- 786 } else 787 pmu_batteries[pmu_cur_battery].time_remaining = 0; 788 789 pmu_cur_battery = (pmu_cur_battery + 1) % pmu_battery_count; 790 791 clear_bit(0, &async_req_locks); 792} 793 | 717done_battery_state_smart(struct adb_request* req) 718{ 719 /* format: 720 * [0] : format of this structure (known: 3,4,5) 721 * [1] : flags 722 * 723 * format 3 & 4: 724 * --- 61 unchanged lines hidden (view full) --- 786 } else 787 pmu_batteries[pmu_cur_battery].time_remaining = 0; 788 789 pmu_cur_battery = (pmu_cur_battery + 1) % pmu_battery_count; 790 791 clear_bit(0, &async_req_locks); 792} 793 |
794static void __pmac | 794static void |
795query_battery_state(void) 796{ 797 if (test_and_set_bit(0, &async_req_locks)) 798 return; 799 if (pmu_kind == PMU_OHARE_BASED) 800 pmu_request(&batt_req, done_battery_state_ohare, 801 1, PMU_BATTERY_STATE); 802 else 803 pmu_request(&batt_req, done_battery_state_smart, 804 2, PMU_SMART_BATTERY_STATE, pmu_cur_battery+1); 805} 806 | 795query_battery_state(void) 796{ 797 if (test_and_set_bit(0, &async_req_locks)) 798 return; 799 if (pmu_kind == PMU_OHARE_BASED) 800 pmu_request(&batt_req, done_battery_state_ohare, 801 1, PMU_BATTERY_STATE); 802 else 803 pmu_request(&batt_req, done_battery_state_smart, 804 2, PMU_SMART_BATTERY_STATE, pmu_cur_battery+1); 805} 806 |
807static int __pmac | 807static int |
808proc_get_info(char *page, char **start, off_t off, 809 int count, int *eof, void *data) 810{ 811 char* p = page; 812 813 p += sprintf(p, "PMU driver version : %d\n", PMU_DRIVER_VERSION); 814 p += sprintf(p, "PMU firmware version : %02x\n", pmu_version); 815 p += sprintf(p, "AC Power : %d\n", 816 ((pmu_power_flags & PMU_PWR_AC_PRESENT) != 0)); 817 p += sprintf(p, "Battery count : %d\n", pmu_battery_count); 818 819 return p - page; 820} 821 | 808proc_get_info(char *page, char **start, off_t off, 809 int count, int *eof, void *data) 810{ 811 char* p = page; 812 813 p += sprintf(p, "PMU driver version : %d\n", PMU_DRIVER_VERSION); 814 p += sprintf(p, "PMU firmware version : %02x\n", pmu_version); 815 p += sprintf(p, "AC Power : %d\n", 816 ((pmu_power_flags & PMU_PWR_AC_PRESENT) != 0)); 817 p += sprintf(p, "Battery count : %d\n", pmu_battery_count); 818 819 return p - page; 820} 821 |
822static int __pmac | 822static int |
823proc_get_irqstats(char *page, char **start, off_t off, 824 int count, int *eof, void *data) 825{ 826 int i; 827 char* p = page; 828 static const char *irq_names[] = { 829 "Total CB1 triggered events", 830 "Total GPIO1 triggered events", --- 10 unchanged lines hidden (view full) --- 841 842 for (i=0; i<11; i++) { 843 p += sprintf(p, " %2u: %10u (%s)\n", 844 i, pmu_irq_stats[i], irq_names[i]); 845 } 846 return p - page; 847} 848 | 823proc_get_irqstats(char *page, char **start, off_t off, 824 int count, int *eof, void *data) 825{ 826 int i; 827 char* p = page; 828 static const char *irq_names[] = { 829 "Total CB1 triggered events", 830 "Total GPIO1 triggered events", --- 10 unchanged lines hidden (view full) --- 841 842 for (i=0; i<11; i++) { 843 p += sprintf(p, " %2u: %10u (%s)\n", 844 i, pmu_irq_stats[i], irq_names[i]); 845 } 846 return p - page; 847} 848 |
849static int __pmac | 849static int |
850proc_get_batt(char *page, char **start, off_t off, 851 int count, int *eof, void *data) 852{ 853 long batnum = (long)data; 854 char *p = page; 855 856 p += sprintf(p, "\n"); 857 p += sprintf(p, "flags : %08x\n", --- 7 unchanged lines hidden (view full) --- 865 p += sprintf(p, "voltage : %d\n", 866 pmu_batteries[batnum].voltage); 867 p += sprintf(p, "time rem. : %d\n", 868 pmu_batteries[batnum].time_remaining); 869 870 return p - page; 871} 872 | 850proc_get_batt(char *page, char **start, off_t off, 851 int count, int *eof, void *data) 852{ 853 long batnum = (long)data; 854 char *p = page; 855 856 p += sprintf(p, "\n"); 857 p += sprintf(p, "flags : %08x\n", --- 7 unchanged lines hidden (view full) --- 865 p += sprintf(p, "voltage : %d\n", 866 pmu_batteries[batnum].voltage); 867 p += sprintf(p, "time rem. : %d\n", 868 pmu_batteries[batnum].time_remaining); 869 870 return p - page; 871} 872 |
873static int __pmac | 873static int |
874proc_read_options(char *page, char **start, off_t off, 875 int count, int *eof, void *data) 876{ 877 char *p = page; 878 879#ifdef CONFIG_PM 880 if (pmu_kind == PMU_KEYLARGO_BASED && 881 pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) >= 0) 882 p += sprintf(p, "lid_wakeup=%d\n", option_lid_wakeup); 883#endif 884 if (pmu_kind == PMU_KEYLARGO_BASED) 885 p += sprintf(p, "server_mode=%d\n", option_server_mode); 886 887 return p - page; 888} 889 | 874proc_read_options(char *page, char **start, off_t off, 875 int count, int *eof, void *data) 876{ 877 char *p = page; 878 879#ifdef CONFIG_PM 880 if (pmu_kind == PMU_KEYLARGO_BASED && 881 pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) >= 0) 882 p += sprintf(p, "lid_wakeup=%d\n", option_lid_wakeup); 883#endif 884 if (pmu_kind == PMU_KEYLARGO_BASED) 885 p += sprintf(p, "server_mode=%d\n", option_server_mode); 886 887 return p - page; 888} 889 |
890static int __pmac | 890static int |
891proc_write_options(struct file *file, const char __user *buffer, 892 unsigned long count, void *data) 893{ 894 char tmp[33]; 895 char *label, *val; 896 unsigned long fcount = count; 897 898 if (!count) --- 30 unchanged lines hidden (view full) --- 929 if (new_value != option_server_mode) 930 pmu_set_server_mode(new_value); 931 } 932 return fcount; 933} 934 935#ifdef CONFIG_ADB 936/* Send an ADB command */ | 891proc_write_options(struct file *file, const char __user *buffer, 892 unsigned long count, void *data) 893{ 894 char tmp[33]; 895 char *label, *val; 896 unsigned long fcount = count; 897 898 if (!count) --- 30 unchanged lines hidden (view full) --- 929 if (new_value != option_server_mode) 930 pmu_set_server_mode(new_value); 931 } 932 return fcount; 933} 934 935#ifdef CONFIG_ADB 936/* Send an ADB command */ |
937static int __pmac | 937static int |
938pmu_send_request(struct adb_request *req, int sync) 939{ 940 int i, ret; 941 942 if ((vias == NULL) || (!pmu_fully_inited)) { 943 req->complete = 1; 944 return -ENXIO; 945 } --- 63 unchanged lines hidden (view full) --- 1009 if (sync) 1010 while (!req->complete) 1011 pmu_poll(); 1012 1013 return 0; 1014} 1015 1016/* Enable/disable autopolling */ | 938pmu_send_request(struct adb_request *req, int sync) 939{ 940 int i, ret; 941 942 if ((vias == NULL) || (!pmu_fully_inited)) { 943 req->complete = 1; 944 return -ENXIO; 945 } --- 63 unchanged lines hidden (view full) --- 1009 if (sync) 1010 while (!req->complete) 1011 pmu_poll(); 1012 1013 return 0; 1014} 1015 1016/* Enable/disable autopolling */ |
1017static int __pmac | 1017static int |
1018pmu_adb_autopoll(int devs) 1019{ 1020 struct adb_request req; 1021 1022 if ((vias == NULL) || (!pmu_fully_inited) || !pmu_has_adb) 1023 return -ENXIO; 1024 1025 if (devs) { --- 6 unchanged lines hidden (view full) --- 1032 pmu_adb_flags = 0; 1033 } 1034 while (!req.complete) 1035 pmu_poll(); 1036 return 0; 1037} 1038 1039/* Reset the ADB bus */ | 1018pmu_adb_autopoll(int devs) 1019{ 1020 struct adb_request req; 1021 1022 if ((vias == NULL) || (!pmu_fully_inited) || !pmu_has_adb) 1023 return -ENXIO; 1024 1025 if (devs) { --- 6 unchanged lines hidden (view full) --- 1032 pmu_adb_flags = 0; 1033 } 1034 while (!req.complete) 1035 pmu_poll(); 1036 return 0; 1037} 1038 1039/* Reset the ADB bus */ |
1040static int __pmac | 1040static int |
1041pmu_adb_reset_bus(void) 1042{ 1043 struct adb_request req; 1044 int save_autopoll = adb_dev_map; 1045 1046 if ((vias == NULL) || (!pmu_fully_inited) || !pmu_has_adb) 1047 return -ENXIO; 1048 --- 18 unchanged lines hidden (view full) --- 1067 if (save_autopoll != 0) 1068 pmu_adb_autopoll(save_autopoll); 1069 1070 return 0; 1071} 1072#endif /* CONFIG_ADB */ 1073 1074/* Construct and send a pmu request */ | 1041pmu_adb_reset_bus(void) 1042{ 1043 struct adb_request req; 1044 int save_autopoll = adb_dev_map; 1045 1046 if ((vias == NULL) || (!pmu_fully_inited) || !pmu_has_adb) 1047 return -ENXIO; 1048 --- 18 unchanged lines hidden (view full) --- 1067 if (save_autopoll != 0) 1068 pmu_adb_autopoll(save_autopoll); 1069 1070 return 0; 1071} 1072#endif /* CONFIG_ADB */ 1073 1074/* Construct and send a pmu request */ |
1075int __openfirmware | 1075int |
1076pmu_request(struct adb_request *req, void (*done)(struct adb_request *), 1077 int nbytes, ...) 1078{ 1079 va_list list; 1080 int i; 1081 1082 if (vias == NULL) 1083 return -ENXIO; --- 9 unchanged lines hidden (view full) --- 1093 for (i = 0; i < nbytes; ++i) 1094 req->data[i] = va_arg(list, int); 1095 va_end(list); 1096 req->reply_len = 0; 1097 req->reply_expected = 0; 1098 return pmu_queue_request(req); 1099} 1100 | 1076pmu_request(struct adb_request *req, void (*done)(struct adb_request *), 1077 int nbytes, ...) 1078{ 1079 va_list list; 1080 int i; 1081 1082 if (vias == NULL) 1083 return -ENXIO; --- 9 unchanged lines hidden (view full) --- 1093 for (i = 0; i < nbytes; ++i) 1094 req->data[i] = va_arg(list, int); 1095 va_end(list); 1096 req->reply_len = 0; 1097 req->reply_expected = 0; 1098 return pmu_queue_request(req); 1099} 1100 |
1101int __pmac | 1101int |
1102pmu_queue_request(struct adb_request *req) 1103{ 1104 unsigned long flags; 1105 int nsend; 1106 1107 if (via == NULL) { 1108 req->complete = 1; 1109 return -ENXIO; --- 75 unchanged lines hidden (view full) --- 1185 req->complete = 1; 1186 /* Here, we assume that if the request has a done member, the 1187 * struct request will survive to setting req->complete to 1 1188 */ 1189 if (done) 1190 (*done)(req); 1191} 1192 | 1102pmu_queue_request(struct adb_request *req) 1103{ 1104 unsigned long flags; 1105 int nsend; 1106 1107 if (via == NULL) { 1108 req->complete = 1; 1109 return -ENXIO; --- 75 unchanged lines hidden (view full) --- 1185 req->complete = 1; 1186 /* Here, we assume that if the request has a done member, the 1187 * struct request will survive to setting req->complete to 1 1188 */ 1189 if (done) 1190 (*done)(req); 1191} 1192 |
1193static void __pmac | 1193static void |
1194pmu_start(void) 1195{ 1196 struct adb_request *req; 1197 1198 /* assert pmu_state == idle */ 1199 /* get the packet to send */ 1200 req = current_req; 1201 if (req == 0 || pmu_state != idle --- 7 unchanged lines hidden (view full) --- 1209 /* Sounds safer to make sure ACK is high before writing. This helped 1210 * kill a problem with ADB and some iBooks 1211 */ 1212 wait_for_ack(); 1213 /* set the shift register to shift out and send a byte */ 1214 send_byte(req->data[0]); 1215} 1216 | 1194pmu_start(void) 1195{ 1196 struct adb_request *req; 1197 1198 /* assert pmu_state == idle */ 1199 /* get the packet to send */ 1200 req = current_req; 1201 if (req == 0 || pmu_state != idle --- 7 unchanged lines hidden (view full) --- 1209 /* Sounds safer to make sure ACK is high before writing. This helped 1210 * kill a problem with ADB and some iBooks 1211 */ 1212 wait_for_ack(); 1213 /* set the shift register to shift out and send a byte */ 1214 send_byte(req->data[0]); 1215} 1216 |
1217void __openfirmware | 1217void |
1218pmu_poll(void) 1219{ 1220 if (!via) 1221 return; 1222 if (disable_poll) 1223 return; 1224 via_pmu_interrupt(0, NULL, NULL); 1225} 1226 | 1218pmu_poll(void) 1219{ 1220 if (!via) 1221 return; 1222 if (disable_poll) 1223 return; 1224 via_pmu_interrupt(0, NULL, NULL); 1225} 1226 |
1227void __openfirmware | 1227void |
1228pmu_poll_adb(void) 1229{ 1230 if (!via) 1231 return; 1232 if (disable_poll) 1233 return; 1234 /* Kicks ADB read when PMU is suspended */ 1235 adb_int_pending = 1; 1236 do { 1237 via_pmu_interrupt(0, NULL, NULL); 1238 } while (pmu_suspended && (adb_int_pending || pmu_state != idle 1239 || req_awaiting_reply)); 1240} 1241 | 1228pmu_poll_adb(void) 1229{ 1230 if (!via) 1231 return; 1232 if (disable_poll) 1233 return; 1234 /* Kicks ADB read when PMU is suspended */ 1235 adb_int_pending = 1; 1236 do { 1237 via_pmu_interrupt(0, NULL, NULL); 1238 } while (pmu_suspended && (adb_int_pending || pmu_state != idle 1239 || req_awaiting_reply)); 1240} 1241 |
1242void __openfirmware | 1242void |
1243pmu_wait_complete(struct adb_request *req) 1244{ 1245 if (!via) 1246 return; 1247 while((pmu_state != idle && pmu_state != locked) || !req->complete) 1248 via_pmu_interrupt(0, NULL, NULL); 1249} 1250 1251/* This function loops until the PMU is idle and prevents it from 1252 * anwsering to ADB interrupts. pmu_request can still be called. 1253 * This is done to avoid spurrious shutdowns when we know we'll have 1254 * interrupts switched off for a long time 1255 */ | 1243pmu_wait_complete(struct adb_request *req) 1244{ 1245 if (!via) 1246 return; 1247 while((pmu_state != idle && pmu_state != locked) || !req->complete) 1248 via_pmu_interrupt(0, NULL, NULL); 1249} 1250 1251/* This function loops until the PMU is idle and prevents it from 1252 * anwsering to ADB interrupts. pmu_request can still be called. 1253 * This is done to avoid spurrious shutdowns when we know we'll have 1254 * interrupts switched off for a long time 1255 */ |
1256void __openfirmware | 1256void |
1257pmu_suspend(void) 1258{ 1259 unsigned long flags; 1260#ifdef SUSPEND_USES_PMU 1261 struct adb_request *req; 1262#endif 1263 if (!via) 1264 return; --- 23 unchanged lines hidden (view full) --- 1288 out_8(&via[IER], CB1_INT | IER_CLR); 1289 spin_unlock_irqrestore(&pmu_lock, flags); 1290#endif /* SUSPEND_USES_PMU */ 1291 break; 1292 } 1293 } while (1); 1294} 1295 | 1257pmu_suspend(void) 1258{ 1259 unsigned long flags; 1260#ifdef SUSPEND_USES_PMU 1261 struct adb_request *req; 1262#endif 1263 if (!via) 1264 return; --- 23 unchanged lines hidden (view full) --- 1288 out_8(&via[IER], CB1_INT | IER_CLR); 1289 spin_unlock_irqrestore(&pmu_lock, flags); 1290#endif /* SUSPEND_USES_PMU */ 1291 break; 1292 } 1293 } while (1); 1294} 1295 |
1296void __openfirmware | 1296void |
1297pmu_resume(void) 1298{ 1299 unsigned long flags; 1300 1301 if (!via || (pmu_suspended < 1)) 1302 return; 1303 1304 spin_lock_irqsave(&pmu_lock, flags); --- 13 unchanged lines hidden (view full) --- 1318 enable_irq(gpio_irq); 1319 out_8(&via[IER], CB1_INT | IER_SET); 1320 spin_unlock_irqrestore(&pmu_lock, flags); 1321 pmu_poll(); 1322#endif /* SUSPEND_USES_PMU */ 1323} 1324 1325/* Interrupt data could be the result data from an ADB cmd */ | 1297pmu_resume(void) 1298{ 1299 unsigned long flags; 1300 1301 if (!via || (pmu_suspended < 1)) 1302 return; 1303 1304 spin_lock_irqsave(&pmu_lock, flags); --- 13 unchanged lines hidden (view full) --- 1318 enable_irq(gpio_irq); 1319 out_8(&via[IER], CB1_INT | IER_SET); 1320 spin_unlock_irqrestore(&pmu_lock, flags); 1321 pmu_poll(); 1322#endif /* SUSPEND_USES_PMU */ 1323} 1324 1325/* Interrupt data could be the result data from an ADB cmd */ |
1326static void __pmac | 1326static void |
1327pmu_handle_data(unsigned char *data, int len, struct pt_regs *regs) 1328{ 1329 unsigned char ints, pirq; 1330 int i = 0; 1331 1332 asleep = 0; 1333 if (drop_interrupts || len < 1) { 1334 adb_int_pending = 0; --- 95 unchanged lines hidden (view full) --- 1430 query_battery_state(); 1431 pmu_pass_intr(data, len); 1432 } else { 1433 pmu_pass_intr(data, len); 1434 } 1435 goto next; 1436} 1437 | 1327pmu_handle_data(unsigned char *data, int len, struct pt_regs *regs) 1328{ 1329 unsigned char ints, pirq; 1330 int i = 0; 1331 1332 asleep = 0; 1333 if (drop_interrupts || len < 1) { 1334 adb_int_pending = 0; --- 95 unchanged lines hidden (view full) --- 1430 query_battery_state(); 1431 pmu_pass_intr(data, len); 1432 } else { 1433 pmu_pass_intr(data, len); 1434 } 1435 goto next; 1436} 1437 |
1438static struct adb_request* __pmac | 1438static struct adb_request* |
1439pmu_sr_intr(struct pt_regs *regs) 1440{ 1441 struct adb_request *req; 1442 int bite = 0; 1443 1444 if (via[B] & TREQ) { 1445 printk(KERN_ERR "PMU: spurious SR intr (%x)\n", via[B]); 1446 out_8(&via[IFR], SR_INT); --- 89 unchanged lines hidden (view full) --- 1536 1537 default: 1538 printk(KERN_ERR "via_pmu_interrupt: unknown state %d?\n", 1539 pmu_state); 1540 } 1541 return NULL; 1542} 1543 | 1439pmu_sr_intr(struct pt_regs *regs) 1440{ 1441 struct adb_request *req; 1442 int bite = 0; 1443 1444 if (via[B] & TREQ) { 1445 printk(KERN_ERR "PMU: spurious SR intr (%x)\n", via[B]); 1446 out_8(&via[IFR], SR_INT); --- 89 unchanged lines hidden (view full) --- 1536 1537 default: 1538 printk(KERN_ERR "via_pmu_interrupt: unknown state %d?\n", 1539 pmu_state); 1540 } 1541 return NULL; 1542} 1543 |
1544static irqreturn_t __pmac | 1544static irqreturn_t |
1545via_pmu_interrupt(int irq, void *arg, struct pt_regs *regs) 1546{ 1547 unsigned long flags; 1548 int intr; 1549 int nloop = 0; 1550 int int_data = -1; 1551 struct adb_request *req = NULL; 1552 int handled = 0; --- 71 unchanged lines hidden (view full) --- 1624 int_data_state[int_data] = int_data_empty; 1625 int_data = -1; 1626 goto recheck; 1627 } 1628 1629 return IRQ_RETVAL(handled); 1630} 1631 | 1545via_pmu_interrupt(int irq, void *arg, struct pt_regs *regs) 1546{ 1547 unsigned long flags; 1548 int intr; 1549 int nloop = 0; 1550 int int_data = -1; 1551 struct adb_request *req = NULL; 1552 int handled = 0; --- 71 unchanged lines hidden (view full) --- 1624 int_data_state[int_data] = int_data_empty; 1625 int_data = -1; 1626 goto recheck; 1627 } 1628 1629 return IRQ_RETVAL(handled); 1630} 1631 |
1632void __pmac | 1632void |
1633pmu_unlock(void) 1634{ 1635 unsigned long flags; 1636 1637 spin_lock_irqsave(&pmu_lock, flags); 1638 if (pmu_state == locked) 1639 pmu_state = idle; 1640 adb_int_pending = 1; 1641 spin_unlock_irqrestore(&pmu_lock, flags); 1642} 1643 1644 | 1633pmu_unlock(void) 1634{ 1635 unsigned long flags; 1636 1637 spin_lock_irqsave(&pmu_lock, flags); 1638 if (pmu_state == locked) 1639 pmu_state = idle; 1640 adb_int_pending = 1; 1641 spin_unlock_irqrestore(&pmu_lock, flags); 1642} 1643 1644 |
1645static irqreturn_t __pmac | 1645static irqreturn_t |
1646gpio1_interrupt(int irq, void *arg, struct pt_regs *regs) 1647{ 1648 unsigned long flags; 1649 1650 if ((in_8(gpio_reg + 0x9) & 0x02) == 0) { 1651 spin_lock_irqsave(&pmu_lock, flags); 1652 if (gpio_irq_enabled > 0) { 1653 disable_irq_nosync(gpio_irq); --- 4 unchanged lines hidden (view full) --- 1658 spin_unlock_irqrestore(&pmu_lock, flags); 1659 via_pmu_interrupt(0, NULL, NULL); 1660 return IRQ_HANDLED; 1661 } 1662 return IRQ_NONE; 1663} 1664 1665#ifdef CONFIG_PMAC_BACKLIGHT | 1646gpio1_interrupt(int irq, void *arg, struct pt_regs *regs) 1647{ 1648 unsigned long flags; 1649 1650 if ((in_8(gpio_reg + 0x9) & 0x02) == 0) { 1651 spin_lock_irqsave(&pmu_lock, flags); 1652 if (gpio_irq_enabled > 0) { 1653 disable_irq_nosync(gpio_irq); --- 4 unchanged lines hidden (view full) --- 1658 spin_unlock_irqrestore(&pmu_lock, flags); 1659 via_pmu_interrupt(0, NULL, NULL); 1660 return IRQ_HANDLED; 1661 } 1662 return IRQ_NONE; 1663} 1664 1665#ifdef CONFIG_PMAC_BACKLIGHT |
1666static int backlight_to_bright[] __pmacdata = { | 1666static int backlight_to_bright[] = { |
1667 0x7f, 0x46, 0x42, 0x3e, 0x3a, 0x36, 0x32, 0x2e, 1668 0x2a, 0x26, 0x22, 0x1e, 0x1a, 0x16, 0x12, 0x0e 1669}; 1670 | 1667 0x7f, 0x46, 0x42, 0x3e, 0x3a, 0x36, 0x32, 0x2e, 1668 0x2a, 0x26, 0x22, 0x1e, 0x1a, 0x16, 0x12, 0x0e 1669}; 1670 |
1671static int __openfirmware | 1671static int |
1672pmu_set_backlight_enable(int on, int level, void* data) 1673{ 1674 struct adb_request req; 1675 1676 if (vias == NULL) 1677 return -ENODEV; 1678 1679 if (on) { 1680 pmu_request(&req, NULL, 2, PMU_BACKLIGHT_BRIGHT, 1681 backlight_to_bright[level]); 1682 pmu_wait_complete(&req); 1683 } 1684 pmu_request(&req, NULL, 2, PMU_POWER_CTRL, 1685 PMU_POW_BACKLIGHT | (on ? PMU_POW_ON : PMU_POW_OFF)); 1686 pmu_wait_complete(&req); 1687 1688 return 0; 1689} 1690 | 1672pmu_set_backlight_enable(int on, int level, void* data) 1673{ 1674 struct adb_request req; 1675 1676 if (vias == NULL) 1677 return -ENODEV; 1678 1679 if (on) { 1680 pmu_request(&req, NULL, 2, PMU_BACKLIGHT_BRIGHT, 1681 backlight_to_bright[level]); 1682 pmu_wait_complete(&req); 1683 } 1684 pmu_request(&req, NULL, 2, PMU_POWER_CTRL, 1685 PMU_POW_BACKLIGHT | (on ? PMU_POW_ON : PMU_POW_OFF)); 1686 pmu_wait_complete(&req); 1687 1688 return 0; 1689} 1690 |
1691static void __openfirmware | 1691static void |
1692pmu_bright_complete(struct adb_request *req) 1693{ 1694 if (req == &bright_req_1) 1695 clear_bit(1, &async_req_locks); 1696 if (req == &bright_req_2) 1697 clear_bit(2, &async_req_locks); 1698} 1699 | 1692pmu_bright_complete(struct adb_request *req) 1693{ 1694 if (req == &bright_req_1) 1695 clear_bit(1, &async_req_locks); 1696 if (req == &bright_req_2) 1697 clear_bit(2, &async_req_locks); 1698} 1699 |
1700static int __openfirmware | 1700static int |
1701pmu_set_backlight_level(int level, void* data) 1702{ 1703 if (vias == NULL) 1704 return -ENODEV; 1705 1706 if (test_and_set_bit(1, &async_req_locks)) 1707 return -EAGAIN; 1708 pmu_request(&bright_req_1, pmu_bright_complete, 2, PMU_BACKLIGHT_BRIGHT, 1709 backlight_to_bright[level]); 1710 if (test_and_set_bit(2, &async_req_locks)) 1711 return -EAGAIN; 1712 pmu_request(&bright_req_2, pmu_bright_complete, 2, PMU_POWER_CTRL, 1713 PMU_POW_BACKLIGHT | (level > BACKLIGHT_OFF ? 1714 PMU_POW_ON : PMU_POW_OFF)); 1715 1716 return 0; 1717} 1718#endif /* CONFIG_PMAC_BACKLIGHT */ 1719 | 1701pmu_set_backlight_level(int level, void* data) 1702{ 1703 if (vias == NULL) 1704 return -ENODEV; 1705 1706 if (test_and_set_bit(1, &async_req_locks)) 1707 return -EAGAIN; 1708 pmu_request(&bright_req_1, pmu_bright_complete, 2, PMU_BACKLIGHT_BRIGHT, 1709 backlight_to_bright[level]); 1710 if (test_and_set_bit(2, &async_req_locks)) 1711 return -EAGAIN; 1712 pmu_request(&bright_req_2, pmu_bright_complete, 2, PMU_POWER_CTRL, 1713 PMU_POW_BACKLIGHT | (level > BACKLIGHT_OFF ? 1714 PMU_POW_ON : PMU_POW_OFF)); 1715 1716 return 0; 1717} 1718#endif /* CONFIG_PMAC_BACKLIGHT */ 1719 |
1720void __pmac | 1720void |
1721pmu_enable_irled(int on) 1722{ 1723 struct adb_request req; 1724 1725 if (vias == NULL) 1726 return ; 1727 if (pmu_kind == PMU_KEYLARGO_BASED) 1728 return ; 1729 1730 pmu_request(&req, NULL, 2, PMU_POWER_CTRL, PMU_POW_IRLED | 1731 (on ? PMU_POW_ON : PMU_POW_OFF)); 1732 pmu_wait_complete(&req); 1733} 1734 | 1721pmu_enable_irled(int on) 1722{ 1723 struct adb_request req; 1724 1725 if (vias == NULL) 1726 return ; 1727 if (pmu_kind == PMU_KEYLARGO_BASED) 1728 return ; 1729 1730 pmu_request(&req, NULL, 2, PMU_POWER_CTRL, PMU_POW_IRLED | 1731 (on ? PMU_POW_ON : PMU_POW_OFF)); 1732 pmu_wait_complete(&req); 1733} 1734 |
1735void __pmac | 1735void |
1736pmu_restart(void) 1737{ 1738 struct adb_request req; 1739 1740 if (via == NULL) 1741 return; 1742 1743 local_irq_disable(); --- 8 unchanged lines hidden (view full) --- 1752 } 1753 1754 pmu_request(&req, NULL, 1, PMU_RESET); 1755 pmu_wait_complete(&req); 1756 for (;;) 1757 ; 1758} 1759 | 1736pmu_restart(void) 1737{ 1738 struct adb_request req; 1739 1740 if (via == NULL) 1741 return; 1742 1743 local_irq_disable(); --- 8 unchanged lines hidden (view full) --- 1752 } 1753 1754 pmu_request(&req, NULL, 1, PMU_RESET); 1755 pmu_wait_complete(&req); 1756 for (;;) 1757 ; 1758} 1759 |
1760void __pmac | 1760void |
1761pmu_shutdown(void) 1762{ 1763 struct adb_request req; 1764 1765 if (via == NULL) 1766 return; 1767 1768 local_irq_disable(); --- 302 unchanged lines hidden (view full) --- 2071 if (n->list.next == 0) 2072 return -ENOENT; 2073 list_del(&n->list); 2074 n->list.next = NULL; 2075 return 0; 2076} 2077 2078/* Sleep is broadcast last-to-first */ | 1761pmu_shutdown(void) 1762{ 1763 struct adb_request req; 1764 1765 if (via == NULL) 1766 return; 1767 1768 local_irq_disable(); --- 302 unchanged lines hidden (view full) --- 2071 if (n->list.next == 0) 2072 return -ENOENT; 2073 list_del(&n->list); 2074 n->list.next = NULL; 2075 return 0; 2076} 2077 2078/* Sleep is broadcast last-to-first */ |
2079static int __pmac | 2079static int |
2080broadcast_sleep(int when, int fallback) 2081{ 2082 int ret = PBOOK_SLEEP_OK; 2083 struct list_head *list; 2084 struct pmu_sleep_notifier *notifier; 2085 2086 for (list = sleep_notifiers.prev; list != &sleep_notifiers; 2087 list = list->prev) { --- 8 unchanged lines hidden (view full) --- 2096 } 2097 return ret; 2098 } 2099 } 2100 return ret; 2101} 2102 2103/* Wake is broadcast first-to-last */ | 2080broadcast_sleep(int when, int fallback) 2081{ 2082 int ret = PBOOK_SLEEP_OK; 2083 struct list_head *list; 2084 struct pmu_sleep_notifier *notifier; 2085 2086 for (list = sleep_notifiers.prev; list != &sleep_notifiers; 2087 list = list->prev) { --- 8 unchanged lines hidden (view full) --- 2096 } 2097 return ret; 2098 } 2099 } 2100 return ret; 2101} 2102 2103/* Wake is broadcast first-to-last */ |
2104static int __pmac | 2104static int |
2105broadcast_wake(void) 2106{ 2107 int ret = PBOOK_SLEEP_OK; 2108 struct list_head *list; 2109 struct pmu_sleep_notifier *notifier; 2110 2111 for (list = sleep_notifiers.next; list != &sleep_notifiers; 2112 list = list->next) { --- 14 unchanged lines hidden (view full) --- 2127 u16 intr; 2128 u32 rom_address; 2129#else 2130 u32 config[16]; 2131#endif 2132} *pbook_pci_saves; 2133static int pbook_npci_saves; 2134 | 2105broadcast_wake(void) 2106{ 2107 int ret = PBOOK_SLEEP_OK; 2108 struct list_head *list; 2109 struct pmu_sleep_notifier *notifier; 2110 2111 for (list = sleep_notifiers.next; list != &sleep_notifiers; 2112 list = list->next) { --- 14 unchanged lines hidden (view full) --- 2127 u16 intr; 2128 u32 rom_address; 2129#else 2130 u32 config[16]; 2131#endif 2132} *pbook_pci_saves; 2133static int pbook_npci_saves; 2134 |
2135static void __pmac | 2135static void |
2136pbook_alloc_pci_save(void) 2137{ 2138 int npci; 2139 struct pci_dev *pd = NULL; 2140 2141 npci = 0; 2142 while ((pd = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pd)) != NULL) { 2143 ++npci; 2144 } 2145 if (npci == 0) 2146 return; 2147 pbook_pci_saves = (struct pci_save *) 2148 kmalloc(npci * sizeof(struct pci_save), GFP_KERNEL); 2149 pbook_npci_saves = npci; 2150} 2151 | 2136pbook_alloc_pci_save(void) 2137{ 2138 int npci; 2139 struct pci_dev *pd = NULL; 2140 2141 npci = 0; 2142 while ((pd = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pd)) != NULL) { 2143 ++npci; 2144 } 2145 if (npci == 0) 2146 return; 2147 pbook_pci_saves = (struct pci_save *) 2148 kmalloc(npci * sizeof(struct pci_save), GFP_KERNEL); 2149 pbook_npci_saves = npci; 2150} 2151 |
2152static void __pmac | 2152static void |
2153pbook_free_pci_save(void) 2154{ 2155 if (pbook_pci_saves == NULL) 2156 return; 2157 kfree(pbook_pci_saves); 2158 pbook_pci_saves = NULL; 2159 pbook_npci_saves = 0; 2160} 2161 | 2153pbook_free_pci_save(void) 2154{ 2155 if (pbook_pci_saves == NULL) 2156 return; 2157 kfree(pbook_pci_saves); 2158 pbook_pci_saves = NULL; 2159 pbook_npci_saves = 0; 2160} 2161 |
2162static void __pmac | 2162static void |
2163pbook_pci_save(void) 2164{ 2165 struct pci_save *ps = pbook_pci_saves; 2166 struct pci_dev *pd = NULL; 2167 int npci = pbook_npci_saves; 2168 2169 if (ps == NULL) 2170 return; --- 14 unchanged lines hidden (view full) --- 2185 ++ps; 2186 } 2187} 2188 2189/* For this to work, we must take care of a few things: If gmac was enabled 2190 * during boot, it will be in the pci dev list. If it's disabled at this point 2191 * (and it will probably be), then you can't access it's config space. 2192 */ | 2163pbook_pci_save(void) 2164{ 2165 struct pci_save *ps = pbook_pci_saves; 2166 struct pci_dev *pd = NULL; 2167 int npci = pbook_npci_saves; 2168 2169 if (ps == NULL) 2170 return; --- 14 unchanged lines hidden (view full) --- 2185 ++ps; 2186 } 2187} 2188 2189/* For this to work, we must take care of a few things: If gmac was enabled 2190 * during boot, it will be in the pci dev list. If it's disabled at this point 2191 * (and it will probably be), then you can't access it's config space. 2192 */ |
2193static void __pmac | 2193static void |
2194pbook_pci_restore(void) 2195{ 2196 u16 cmd; 2197 struct pci_save *ps = pbook_pci_saves - 1; 2198 struct pci_dev *pd = NULL; 2199 int npci = pbook_npci_saves; 2200 int j; 2201 --- 31 unchanged lines hidden (view full) --- 2233 break; 2234 } 2235#endif 2236 } 2237} 2238 2239#ifdef DEBUG_SLEEP 2240/* N.B. This doesn't work on the 3400 */ | 2194pbook_pci_restore(void) 2195{ 2196 u16 cmd; 2197 struct pci_save *ps = pbook_pci_saves - 1; 2198 struct pci_dev *pd = NULL; 2199 int npci = pbook_npci_saves; 2200 int j; 2201 --- 31 unchanged lines hidden (view full) --- 2233 break; 2234 } 2235#endif 2236 } 2237} 2238 2239#ifdef DEBUG_SLEEP 2240/* N.B. This doesn't work on the 3400 */ |
2241void __pmac | 2241void |
2242pmu_blink(int n) 2243{ 2244 struct adb_request req; 2245 2246 memset(&req, 0, sizeof(req)); 2247 2248 for (; n > 0; --n) { 2249 req.nbytes = 4; --- 22 unchanged lines hidden (view full) --- 2272 mdelay(50); 2273} 2274#endif 2275 2276/* 2277 * Put the powerbook to sleep. 2278 */ 2279 | 2242pmu_blink(int n) 2243{ 2244 struct adb_request req; 2245 2246 memset(&req, 0, sizeof(req)); 2247 2248 for (; n > 0; --n) { 2249 req.nbytes = 4; --- 22 unchanged lines hidden (view full) --- 2272 mdelay(50); 2273} 2274#endif 2275 2276/* 2277 * Put the powerbook to sleep. 2278 */ 2279 |
2280static u32 save_via[8] __pmacdata; | 2280static u32 save_via[8]; |
2281 | 2281 |
2282static void __pmac | 2282static void |
2283save_via_state(void) 2284{ 2285 save_via[0] = in_8(&via[ANH]); 2286 save_via[1] = in_8(&via[DIRA]); 2287 save_via[2] = in_8(&via[B]); 2288 save_via[3] = in_8(&via[DIRB]); 2289 save_via[4] = in_8(&via[PCR]); 2290 save_via[5] = in_8(&via[ACR]); 2291 save_via[6] = in_8(&via[T1CL]); 2292 save_via[7] = in_8(&via[T1CH]); 2293} | 2283save_via_state(void) 2284{ 2285 save_via[0] = in_8(&via[ANH]); 2286 save_via[1] = in_8(&via[DIRA]); 2287 save_via[2] = in_8(&via[B]); 2288 save_via[3] = in_8(&via[DIRB]); 2289 save_via[4] = in_8(&via[PCR]); 2290 save_via[5] = in_8(&via[ACR]); 2291 save_via[6] = in_8(&via[T1CL]); 2292 save_via[7] = in_8(&via[T1CH]); 2293} |
2294static void __pmac | 2294static void |
2295restore_via_state(void) 2296{ 2297 out_8(&via[ANH], save_via[0]); 2298 out_8(&via[DIRA], save_via[1]); 2299 out_8(&via[B], save_via[2]); 2300 out_8(&via[DIRB], save_via[3]); 2301 out_8(&via[PCR], save_via[4]); 2302 out_8(&via[ACR], save_via[5]); 2303 out_8(&via[T1CL], save_via[6]); 2304 out_8(&via[T1CH], save_via[7]); 2305 out_8(&via[IER], IER_CLR | 0x7f); /* disable all intrs */ 2306 out_8(&via[IFR], 0x7f); /* clear IFR */ 2307 out_8(&via[IER], IER_SET | SR_INT | CB1_INT); 2308} 2309 | 2295restore_via_state(void) 2296{ 2297 out_8(&via[ANH], save_via[0]); 2298 out_8(&via[DIRA], save_via[1]); 2299 out_8(&via[B], save_via[2]); 2300 out_8(&via[DIRB], save_via[3]); 2301 out_8(&via[PCR], save_via[4]); 2302 out_8(&via[ACR], save_via[5]); 2303 out_8(&via[T1CL], save_via[6]); 2304 out_8(&via[T1CH], save_via[7]); 2305 out_8(&via[IER], IER_CLR | 0x7f); /* disable all intrs */ 2306 out_8(&via[IFR], 0x7f); /* clear IFR */ 2307 out_8(&via[IER], IER_SET | SR_INT | CB1_INT); 2308} 2309 |
2310static int __pmac | 2310static int |
2311pmac_suspend_devices(void) 2312{ 2313 int ret; 2314 2315 pm_prepare_console(); 2316 2317 /* Notify old-style device drivers & userland */ 2318 ret = broadcast_sleep(PBOOK_SLEEP_REQUEST, PBOOK_SLEEP_REJECT); --- 73 unchanged lines hidden (view full) --- 2392#ifdef CONFIG_ALTIVEC 2393 if (cpu_has_feature(CPU_FTR_ALTIVEC)) 2394 enable_kernel_altivec(); 2395#endif /* CONFIG_ALTIVEC */ 2396 2397 return 0; 2398} 2399 | 2311pmac_suspend_devices(void) 2312{ 2313 int ret; 2314 2315 pm_prepare_console(); 2316 2317 /* Notify old-style device drivers & userland */ 2318 ret = broadcast_sleep(PBOOK_SLEEP_REQUEST, PBOOK_SLEEP_REJECT); --- 73 unchanged lines hidden (view full) --- 2392#ifdef CONFIG_ALTIVEC 2393 if (cpu_has_feature(CPU_FTR_ALTIVEC)) 2394 enable_kernel_altivec(); 2395#endif /* CONFIG_ALTIVEC */ 2396 2397 return 0; 2398} 2399 |
2400static int __pmac | 2400static int |
2401pmac_wakeup_devices(void) 2402{ 2403 mdelay(100); 2404 2405 /* Power back up system devices (including the PIC) */ 2406 device_power_up(); 2407 2408 /* Force a poll of ADB interrupts */ --- 22 unchanged lines hidden (view full) --- 2431 return 0; 2432} 2433 2434#define GRACKLE_PM (1<<7) 2435#define GRACKLE_DOZE (1<<5) 2436#define GRACKLE_NAP (1<<4) 2437#define GRACKLE_SLEEP (1<<3) 2438 | 2401pmac_wakeup_devices(void) 2402{ 2403 mdelay(100); 2404 2405 /* Power back up system devices (including the PIC) */ 2406 device_power_up(); 2407 2408 /* Force a poll of ADB interrupts */ --- 22 unchanged lines hidden (view full) --- 2431 return 0; 2432} 2433 2434#define GRACKLE_PM (1<<7) 2435#define GRACKLE_DOZE (1<<5) 2436#define GRACKLE_NAP (1<<4) 2437#define GRACKLE_SLEEP (1<<3) 2438 |
2439int __pmac | 2439int |
2440powerbook_sleep_grackle(void) 2441{ 2442 unsigned long save_l2cr; 2443 unsigned short pmcr1; 2444 struct adb_request req; 2445 int ret; 2446 struct pci_dev *grackle; 2447 --- 67 unchanged lines hidden (view full) --- 2515 PMU_POW_ON|PMU_POW_BACKLIGHT|PMU_POW_CHARGER|PMU_POW_IRLED|PMU_POW_MEDIABAY); 2516 pmu_wait_complete(&req); 2517 2518 pmac_wakeup_devices(); 2519 2520 return 0; 2521} 2522 | 2440powerbook_sleep_grackle(void) 2441{ 2442 unsigned long save_l2cr; 2443 unsigned short pmcr1; 2444 struct adb_request req; 2445 int ret; 2446 struct pci_dev *grackle; 2447 --- 67 unchanged lines hidden (view full) --- 2515 PMU_POW_ON|PMU_POW_BACKLIGHT|PMU_POW_CHARGER|PMU_POW_IRLED|PMU_POW_MEDIABAY); 2516 pmu_wait_complete(&req); 2517 2518 pmac_wakeup_devices(); 2519 2520 return 0; 2521} 2522 |
2523static int __pmac | 2523static int |
2524powerbook_sleep_Core99(void) 2525{ 2526 unsigned long save_l2cr; 2527 unsigned long save_l3cr; 2528 struct adb_request req; 2529 int ret; 2530 2531 if (pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) < 0) { --- 83 unchanged lines hidden (view full) --- 2615 pmac_wakeup_devices(); 2616 2617 return 0; 2618} 2619 2620#define PB3400_MEM_CTRL 0xf8000000 2621#define PB3400_MEM_CTRL_SLEEP 0x70 2622 | 2524powerbook_sleep_Core99(void) 2525{ 2526 unsigned long save_l2cr; 2527 unsigned long save_l3cr; 2528 struct adb_request req; 2529 int ret; 2530 2531 if (pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) < 0) { --- 83 unchanged lines hidden (view full) --- 2615 pmac_wakeup_devices(); 2616 2617 return 0; 2618} 2619 2620#define PB3400_MEM_CTRL 0xf8000000 2621#define PB3400_MEM_CTRL_SLEEP 0x70 2622 |
2623static int __pmac | 2623static int |
2624powerbook_sleep_3400(void) 2625{ 2626 int ret, i, x; 2627 unsigned int hid0; 2628 unsigned long p; 2629 struct adb_request sleep_req; 2630 void __iomem *mem_ctrl; 2631 unsigned int __iomem *mem_ctrl_sleep; --- 83 unchanged lines hidden (view full) --- 2715 wait_queue_head_t wait; 2716 spinlock_t lock; 2717#if defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT) 2718 int backlight_locker; 2719#endif /* defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT) */ 2720}; 2721 2722static LIST_HEAD(all_pmu_pvt); | 2624powerbook_sleep_3400(void) 2625{ 2626 int ret, i, x; 2627 unsigned int hid0; 2628 unsigned long p; 2629 struct adb_request sleep_req; 2630 void __iomem *mem_ctrl; 2631 unsigned int __iomem *mem_ctrl_sleep; --- 83 unchanged lines hidden (view full) --- 2715 wait_queue_head_t wait; 2716 spinlock_t lock; 2717#if defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT) 2718 int backlight_locker; 2719#endif /* defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT) */ 2720}; 2721 2722static LIST_HEAD(all_pmu_pvt); |
2723static DEFINE_SPINLOCK(all_pvt_lock __pmacdata); | 2723static DEFINE_SPINLOCK(all_pvt_lock); |
2724 | 2724 |
2725static void __pmac | 2725static void |
2726pmu_pass_intr(unsigned char *data, int len) 2727{ 2728 struct pmu_private *pp; 2729 struct list_head *list; 2730 int i; 2731 unsigned long flags; 2732 2733 if (len > sizeof(pp->rb_buf[0].data)) --- 12 unchanged lines hidden (view full) --- 2746 pp->rb_put = i; 2747 wake_up_interruptible(&pp->wait); 2748 } 2749 spin_unlock(&pp->lock); 2750 } 2751 spin_unlock_irqrestore(&all_pvt_lock, flags); 2752} 2753 | 2726pmu_pass_intr(unsigned char *data, int len) 2727{ 2728 struct pmu_private *pp; 2729 struct list_head *list; 2730 int i; 2731 unsigned long flags; 2732 2733 if (len > sizeof(pp->rb_buf[0].data)) --- 12 unchanged lines hidden (view full) --- 2746 pp->rb_put = i; 2747 wake_up_interruptible(&pp->wait); 2748 } 2749 spin_unlock(&pp->lock); 2750 } 2751 spin_unlock_irqrestore(&all_pvt_lock, flags); 2752} 2753 |
2754static int __pmac | 2754static int |
2755pmu_open(struct inode *inode, struct file *file) 2756{ 2757 struct pmu_private *pp; 2758 unsigned long flags; 2759 2760 pp = kmalloc(sizeof(struct pmu_private), GFP_KERNEL); 2761 if (pp == 0) 2762 return -ENOMEM; --- 5 unchanged lines hidden (view full) --- 2768 pp->backlight_locker = 0; 2769#endif /* defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT) */ 2770 list_add(&pp->list, &all_pmu_pvt); 2771 spin_unlock_irqrestore(&all_pvt_lock, flags); 2772 file->private_data = pp; 2773 return 0; 2774} 2775 | 2755pmu_open(struct inode *inode, struct file *file) 2756{ 2757 struct pmu_private *pp; 2758 unsigned long flags; 2759 2760 pp = kmalloc(sizeof(struct pmu_private), GFP_KERNEL); 2761 if (pp == 0) 2762 return -ENOMEM; --- 5 unchanged lines hidden (view full) --- 2768 pp->backlight_locker = 0; 2769#endif /* defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT) */ 2770 list_add(&pp->list, &all_pmu_pvt); 2771 spin_unlock_irqrestore(&all_pvt_lock, flags); 2772 file->private_data = pp; 2773 return 0; 2774} 2775 |
2776static ssize_t __pmac | 2776static ssize_t |
2777pmu_read(struct file *file, char __user *buf, 2778 size_t count, loff_t *ppos) 2779{ 2780 struct pmu_private *pp = file->private_data; 2781 DECLARE_WAITQUEUE(wait, current); 2782 unsigned long flags; 2783 int ret = 0; 2784 --- 35 unchanged lines hidden (view full) --- 2820 } 2821 current->state = TASK_RUNNING; 2822 remove_wait_queue(&pp->wait, &wait); 2823 spin_unlock_irqrestore(&pp->lock, flags); 2824 2825 return ret; 2826} 2827 | 2777pmu_read(struct file *file, char __user *buf, 2778 size_t count, loff_t *ppos) 2779{ 2780 struct pmu_private *pp = file->private_data; 2781 DECLARE_WAITQUEUE(wait, current); 2782 unsigned long flags; 2783 int ret = 0; 2784 --- 35 unchanged lines hidden (view full) --- 2820 } 2821 current->state = TASK_RUNNING; 2822 remove_wait_queue(&pp->wait, &wait); 2823 spin_unlock_irqrestore(&pp->lock, flags); 2824 2825 return ret; 2826} 2827 |
2828static ssize_t __pmac | 2828static ssize_t |
2829pmu_write(struct file *file, const char __user *buf, 2830 size_t count, loff_t *ppos) 2831{ 2832 return 0; 2833} 2834 | 2829pmu_write(struct file *file, const char __user *buf, 2830 size_t count, loff_t *ppos) 2831{ 2832 return 0; 2833} 2834 |
2835static unsigned int __pmac | 2835static unsigned int |
2836pmu_fpoll(struct file *filp, poll_table *wait) 2837{ 2838 struct pmu_private *pp = filp->private_data; 2839 unsigned int mask = 0; 2840 unsigned long flags; 2841 2842 if (pp == 0) 2843 return 0; 2844 poll_wait(filp, &pp->wait, wait); 2845 spin_lock_irqsave(&pp->lock, flags); 2846 if (pp->rb_get != pp->rb_put) 2847 mask |= POLLIN; 2848 spin_unlock_irqrestore(&pp->lock, flags); 2849 return mask; 2850} 2851 | 2836pmu_fpoll(struct file *filp, poll_table *wait) 2837{ 2838 struct pmu_private *pp = filp->private_data; 2839 unsigned int mask = 0; 2840 unsigned long flags; 2841 2842 if (pp == 0) 2843 return 0; 2844 poll_wait(filp, &pp->wait, wait); 2845 spin_lock_irqsave(&pp->lock, flags); 2846 if (pp->rb_get != pp->rb_put) 2847 mask |= POLLIN; 2848 spin_unlock_irqrestore(&pp->lock, flags); 2849 return mask; 2850} 2851 |
2852static int __pmac | 2852static int |
2853pmu_release(struct inode *inode, struct file *file) 2854{ 2855 struct pmu_private *pp = file->private_data; 2856 unsigned long flags; 2857 2858 lock_kernel(); 2859 if (pp != 0) { 2860 file->private_data = NULL; --- 8 unchanged lines hidden (view full) --- 2869 } 2870#endif /* defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT) */ 2871 kfree(pp); 2872 } 2873 unlock_kernel(); 2874 return 0; 2875} 2876 | 2853pmu_release(struct inode *inode, struct file *file) 2854{ 2855 struct pmu_private *pp = file->private_data; 2856 unsigned long flags; 2857 2858 lock_kernel(); 2859 if (pp != 0) { 2860 file->private_data = NULL; --- 8 unchanged lines hidden (view full) --- 2869 } 2870#endif /* defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT) */ 2871 kfree(pp); 2872 } 2873 unlock_kernel(); 2874 return 0; 2875} 2876 |
2877/* Note: removed __openfirmware here since it causes link errors */ 2878static int __pmac | 2877static int |
2879pmu_ioctl(struct inode * inode, struct file *filp, 2880 u_int cmd, u_long arg) 2881{ 2882 __u32 __user *argp = (__u32 __user *)arg; 2883 int error = -EINVAL; 2884 2885 switch (cmd) { 2886#ifdef CONFIG_PM --- 65 unchanged lines hidden (view full) --- 2952 case PMU_IOC_GET_MODEL: 2953 return put_user(pmu_kind, argp); 2954 case PMU_IOC_HAS_ADB: 2955 return put_user(pmu_has_adb, argp); 2956 } 2957 return error; 2958} 2959 | 2878pmu_ioctl(struct inode * inode, struct file *filp, 2879 u_int cmd, u_long arg) 2880{ 2881 __u32 __user *argp = (__u32 __user *)arg; 2882 int error = -EINVAL; 2883 2884 switch (cmd) { 2885#ifdef CONFIG_PM --- 65 unchanged lines hidden (view full) --- 2951 case PMU_IOC_GET_MODEL: 2952 return put_user(pmu_kind, argp); 2953 case PMU_IOC_HAS_ADB: 2954 return put_user(pmu_has_adb, argp); 2955 } 2956 return error; 2957} 2958 |
2960static struct file_operations pmu_device_fops __pmacdata = { | 2959static struct file_operations pmu_device_fops = { |
2961 .read = pmu_read, 2962 .write = pmu_write, 2963 .poll = pmu_fpoll, 2964 .ioctl = pmu_ioctl, 2965 .open = pmu_open, 2966 .release = pmu_release, 2967}; 2968 | 2960 .read = pmu_read, 2961 .write = pmu_write, 2962 .poll = pmu_fpoll, 2963 .ioctl = pmu_ioctl, 2964 .open = pmu_open, 2965 .release = pmu_release, 2966}; 2967 |
2969static struct miscdevice pmu_device __pmacdata = { | 2968static struct miscdevice pmu_device = { |
2970 PMU_MINOR, "pmu", &pmu_device_fops 2971}; 2972 2973static int pmu_device_init(void) 2974{ 2975 if (!via) 2976 return 0; 2977 if (misc_register(&pmu_device) < 0) 2978 printk(KERN_ERR "via-pmu: cannot register misc device.\n"); 2979 return 0; 2980} 2981device_initcall(pmu_device_init); 2982 2983 2984#ifdef DEBUG_SLEEP | 2969 PMU_MINOR, "pmu", &pmu_device_fops 2970}; 2971 2972static int pmu_device_init(void) 2973{ 2974 if (!via) 2975 return 0; 2976 if (misc_register(&pmu_device) < 0) 2977 printk(KERN_ERR "via-pmu: cannot register misc device.\n"); 2978 return 0; 2979} 2980device_initcall(pmu_device_init); 2981 2982 2983#ifdef DEBUG_SLEEP |
2985static inline void __pmac | 2984static inline void |
2986polled_handshake(volatile unsigned char __iomem *via) 2987{ 2988 via[B] &= ~TREQ; eieio(); 2989 while ((via[B] & TACK) != 0) 2990 ; 2991 via[B] |= TREQ; eieio(); 2992 while ((via[B] & TACK) == 0) 2993 ; 2994} 2995 | 2985polled_handshake(volatile unsigned char __iomem *via) 2986{ 2987 via[B] &= ~TREQ; eieio(); 2988 while ((via[B] & TACK) != 0) 2989 ; 2990 via[B] |= TREQ; eieio(); 2991 while ((via[B] & TACK) == 0) 2992 ; 2993} 2994 |
2996static inline void __pmac | 2995static inline void |
2997polled_send_byte(volatile unsigned char __iomem *via, int x) 2998{ 2999 via[ACR] |= SR_OUT | SR_EXT; eieio(); 3000 via[SR] = x; eieio(); 3001 polled_handshake(via); 3002} 3003 | 2996polled_send_byte(volatile unsigned char __iomem *via, int x) 2997{ 2998 via[ACR] |= SR_OUT | SR_EXT; eieio(); 2999 via[SR] = x; eieio(); 3000 polled_handshake(via); 3001} 3002 |
3004static inline int __pmac | 3003static inline int |
3005polled_recv_byte(volatile unsigned char __iomem *via) 3006{ 3007 int x; 3008 3009 via[ACR] = (via[ACR] & ~SR_OUT) | SR_EXT; eieio(); 3010 x = via[SR]; eieio(); 3011 polled_handshake(via); 3012 x = via[SR]; eieio(); 3013 return x; 3014} 3015 | 3004polled_recv_byte(volatile unsigned char __iomem *via) 3005{ 3006 int x; 3007 3008 via[ACR] = (via[ACR] & ~SR_OUT) | SR_EXT; eieio(); 3009 x = via[SR]; eieio(); 3010 polled_handshake(via); 3011 x = via[SR]; eieio(); 3012 return x; 3013} 3014 |
3016int __pmac | 3015int |
3017pmu_polled_request(struct adb_request *req) 3018{ 3019 unsigned long flags; 3020 int i, l, c; 3021 volatile unsigned char __iomem *v = via; 3022 3023 req->complete = 1; 3024 c = req->data[0]; --- 134 unchanged lines hidden --- | 3016pmu_polled_request(struct adb_request *req) 3017{ 3018 unsigned long flags; 3019 int i, l, c; 3020 volatile unsigned char __iomem *v = via; 3021 3022 req->complete = 1; 3023 c = req->data[0]; --- 134 unchanged lines hidden --- |