22 #include <linux/types.h>
23 #include <linux/errno.h>
24 #include <linux/kernel.h>
26 #include <linux/sched.h>
29 #include <linux/pci.h>
30 #include <linux/slab.h>
31 #include <linux/poll.h>
32 #include <linux/adb.h>
33 #include <linux/pmu.h>
34 #include <linux/cuda.h>
35 #include <linux/module.h>
42 #include <linux/device.h>
50 #include <asm/machdep.h>
52 #include <asm/pgtable.h>
53 #include <asm/sections.h>
58 #include <asm/uaccess.h>
59 #include <asm/mmu_context.h>
60 #include <asm/cputable.h>
73 #define BATTERY_POLLING_COUNT 2
76 static volatile unsigned char __iomem *via;
133 static int interrupt_data_len[2];
134 static int int_data_last;
135 static unsigned char *reply_ptr;
136 static int data_index;
138 static volatile int adb_int_pending;
139 static volatile int disable_poll;
142 static int pmu_fully_inited;
143 static int pmu_has_adb;
145 static unsigned char __iomem *gpio_reg;
146 static int gpio_irq =
NO_IRQ;
147 static int gpio_irq_enabled = -1;
148 static volatile int pmu_suspended;
150 static u8 pmu_intr_mask;
151 static int pmu_version;
152 static int drop_interrupts;
153 #if defined(CONFIG_SUSPEND) && defined(CONFIG_PPC32)
154 static int option_lid_wakeup = 1;
156 static unsigned long async_req_locks;
157 static unsigned int pmu_irq_stats[11];
163 static int option_server_mode;
177 static int adb_dev_map;
178 static int pmu_adb_flags;
180 static int pmu_probe(
void);
181 static int pmu_init(
void);
183 static int pmu_adb_autopoll(
int devs);
184 static int pmu_adb_reset_bus(
void);
187 static int init_pmu(
void);
188 static void pmu_start(
void);
193 static void pmu_pass_intr(
unsigned char *
data,
int len);
215 void pmu_blink(
int n);
225 static const s8 pmu_data_len[256][2] = {
227 {-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
228 {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
229 { 1, 0},{ 1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
230 { 0, 1},{ 0, 1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{ 0, 0},
231 {-1, 0},{ 0, 0},{ 2, 0},{ 1, 0},{ 1, 0},{-1, 0},{-1, 0},{-1, 0},
232 { 0,-1},{ 0,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{ 0,-1},
233 { 4, 0},{20, 0},{-1, 0},{ 3, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
234 { 0, 4},{ 0,20},{ 2,-1},{ 2, 1},{ 3,-1},{-1,-1},{-1,-1},{ 4, 0},
235 { 1, 0},{ 1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
236 { 0, 1},{ 0, 1},{-1,-1},{ 1, 0},{ 1, 0},{-1,-1},{-1,-1},{-1,-1},
237 { 1, 0},{ 0, 0},{ 2, 0},{ 2, 0},{-1, 0},{ 1, 0},{ 3, 0},{ 1, 0},
238 { 0, 1},{ 1, 0},{ 0, 2},{ 0, 2},{ 0,-1},{-1,-1},{-1,-1},{-1,-1},
239 { 2, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
240 { 0, 3},{ 0, 3},{ 0, 2},{ 0, 8},{ 0,-1},{ 0,-1},{-1,-1},{-1,-1},
241 { 1, 0},{ 1, 0},{ 1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
242 { 0,-1},{ 0,-1},{-1,-1},{-1,-1},{-1,-1},{ 5, 1},{ 4, 1},{ 4, 1},
243 { 4, 0},{-1, 0},{ 0, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
244 { 0, 5},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
245 { 1, 0},{ 2, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
246 { 0, 1},{ 0, 1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
247 { 2, 0},{ 2, 0},{ 2, 0},{ 4, 0},{-1, 0},{ 0, 0},{-1, 0},{-1, 0},
248 { 1, 1},{ 1, 0},{ 3, 0},{ 2, 0},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
249 {-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
250 {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
251 {-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
252 {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
253 { 0, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
254 { 1, 1},{ 1, 1},{-1,-1},{-1,-1},{ 0, 1},{ 0,-1},{-1,-1},{-1,-1},
255 {-1, 0},{ 4, 0},{ 0, 1},{-1, 0},{-1, 0},{ 4, 0},{-1, 0},{-1, 0},
256 { 3,-1},{-1,-1},{ 0, 1},{-1,-1},{ 0,-1},{-1,-1},{-1,-1},{ 0, 0},
257 {-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
258 {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
261 static char *pbook_type[] = {
263 "PowerBook 2400/3400/3500(G3)",
264 "PowerBook G3 Series",
286 if (taddr == OF_BAD_ADDR) {
311 u64 gaddr = OF_BAD_ADDR;
315 pmu_has_adb = (adbp !=
NULL);
328 if (gaddr != OF_BAD_ADDR)
329 gpio_reg =
ioremap(gaddr, 0x10);
331 if (gpio_reg ==
NULL) {
354 printk(
KERN_INFO "PMU driver v%d initialized for %s, firmware: %02x\n",
370 static int pmu_probe(
void)
375 static int __init pmu_init(
void)
390 static int __init via_pmu_start(
void)
397 batt_req.complete = 1;
409 "VIA-PMU", (
void *)0)) {
416 if (gpio_node ==
NULL)
424 "GPIO1 ADB", (
void *)0))
426 " (GPIO1)\n", gpio_irq);
428 gpio_irq_enabled = 1;
435 pmu_fully_inited = 1;
457 static int __init via_pmu_dev_init(
void)
462 #ifdef CONFIG_PMAC_BACKLIGHT
470 int mb = pmac_call_feature(PMAC_FTR_GET_MB_INFO,
471 NULL, PMAC_MB_INFO_MODEL, 0);
473 if (mb == PMAC_TYPE_COMET)
506 sprintf(title,
"battery_%ld", i);
508 &pmu_battery_proc_fops, (
void *)i);
511 proc_pmu_info = proc_create(
"info", 0, proc_pmu_root, &pmu_info_proc_fops);
512 proc_pmu_irqstats = proc_create(
"interrupts", 0, proc_pmu_root,
513 &pmu_irqstats_proc_fops);
514 proc_pmu_options = proc_create(
"options", 0600, proc_pmu_root,
515 &pmu_options_proc_fops);
533 while (!
req.complete) {
552 via_pmu_interrupt(0,
NULL);
559 while (!
req.complete)
566 if (
req.reply_len > 0)
567 pmu_version =
req.reply[0];
574 if (
req.reply_len == 2) {
576 option_server_mode = 1;
578 option_server_mode ?
"enabled" :
"disabled");
590 static void pmu_set_server_mode(
int server_mode)
597 option_server_mode = server_mode;
600 if (
req.reply_len < 2)
638 long pcharge, charge, vb, vmax, lmax;
639 long vmax_charging, vmax_charged;
640 long amperage, voltage,
time,
max;
641 int mb = pmac_call_feature(PMAC_FTR_GET_MB_INFO,
642 NULL, PMAC_MB_INFO_MODEL, 0);
644 if (req->
reply[0] & 0x01)
649 if (mb == PMAC_TYPE_COMET) {
661 if (req->
reply[0] & 0x04) {
663 if (req->
reply[0] & 0x02)
666 voltage = (vb * 265 + 72665) / 10;
667 amperage = req->
reply[5];
668 if ((req->
reply[0] & 0x01) == 0) {
670 vb += ((amperage - 200) * 15)/100;
671 }
else if (req->
reply[0] & 0x02) {
672 vb = (vb * 97) / 100;
673 vmax = vmax_charging;
675 charge = (100 * vb) / vmax;
676 if (req->
reply[0] & 0x40) {
677 pcharge = (req->
reply[6] << 8) + req->
reply[7];
681 pcharge = 100 - pcharge / lmax;
682 if (pcharge < charge)
686 time = (charge * 16440) / amperage;
690 amperage = -amperage;
692 charge = max = amperage = voltage = time = 0;
728 unsigned int capa,
max, voltage;
730 if (req->
reply[1] & 0x01)
736 capa = max = amperage = voltage = 0;
738 if (req->
reply[1] & 0x04) {
740 switch(req->
reply[0]) {
742 case 4: capa = req->
reply[2];
744 amperage = *((
signed char *)&req->
reply[4]);
745 voltage = req->
reply[5];
747 case 5: capa = (req->
reply[2] << 8) | req->
reply[3];
749 amperage = *((
signed short *)&req->
reply[6]);
750 voltage = (req->
reply[8] << 8) | req->
reply[9];
753 printk(
KERN_WARNING "pmu.c : unrecognized battery info, len: %d, %02x %02x %02x %02x\n",
759 if ((req->
reply[1] & 0x01) && (amperage > 0))
768 if ((req->
reply[1] & 0x01) && (amperage > 0))
770 = ((max-capa) * 3600) / amperage;
773 = (capa * 3600) / (-amperage);
783 query_battery_state(
void)
795 static int pmu_info_proc_show(
struct seq_file *
m,
void *
v)
798 seq_printf(m,
"PMU firmware version : %02x\n", pmu_version);
813 .open = pmu_info_proc_open,
819 static int pmu_irqstats_proc_show(
struct seq_file *m,
void *v)
822 static const char *irq_names[] = {
823 "Total CB1 triggered events",
824 "Total GPIO1 triggered events",
825 "PC-Card eject button",
826 "Sound/Brightness button",
828 "Battery state change",
829 "Environment interrupt",
831 "Ghost interrupt (zero len)",
832 "Empty interrupt (empty mask)",
836 for (i=0; i<11; i++) {
838 i, pmu_irq_stats[i], irq_names[i]);
850 .open = pmu_irqstats_proc_open,
856 static int pmu_battery_proc_show(
struct seq_file *m,
void *v)
877 .open = pmu_battery_proc_open,
883 static int pmu_options_proc_show(
struct seq_file *m,
void *v)
885 #if defined(CONFIG_SUSPEND) && defined(CONFIG_PPC32)
887 pmac_call_feature(PMAC_FTR_SLEEP_STATE,
NULL,0,-1) >= 0)
888 seq_printf(m,
"lid_wakeup=%d\n", option_lid_wakeup);
891 seq_printf(m,
"server_mode=%d\n", option_server_mode);
896 static int pmu_options_proc_open(
struct inode *inode,
struct file *file)
901 static ssize_t pmu_options_proc_write(
struct file *file,
906 size_t fcount =
count;
920 while(*val && (*val !=
'=')) {
930 #if defined(CONFIG_SUSPEND) && defined(CONFIG_PPC32)
932 pmac_call_feature(PMAC_FTR_SLEEP_STATE,
NULL,0,-1) >= 0)
933 if (!
strcmp(label,
"lid_wakeup"))
934 option_lid_wakeup = ((*val) ==
'1');
938 new_value = ((*val) ==
'1');
939 if (new_value != option_server_mode)
940 pmu_set_server_mode(new_value);
947 .open = pmu_options_proc_open,
951 .write = pmu_options_proc_write,
960 if ((vias ==
NULL) || (!pmu_fully_inited)) {
967 switch (req->
data[0]) {
969 for (i = 0; i < req->
nbytes - 1; ++
i)
972 if (pmu_data_len[req->
data[0]][1] != 0) {
980 switch (req->
data[1]) {
997 for (i = 1; i <= 4; ++
i)
1010 for (i = req->
nbytes - 1; i > 1; --i)
1013 req->
data[2] = pmu_adb_flags;
1035 static int __pmu_adb_autopoll(
int devs)
1041 adb_dev_map >> 8, adb_dev_map);
1052 static int pmu_adb_autopoll(
int devs)
1054 if ((vias ==
NULL) || (!pmu_fully_inited) || !pmu_has_adb)
1058 return __pmu_adb_autopoll(devs);
1062 static int pmu_adb_reset_bus(
void)
1065 int save_autopoll = adb_dev_map;
1067 if ((vias ==
NULL) || (!pmu_fully_inited) || !pmu_has_adb)
1071 __pmu_adb_autopoll(0);
1083 printk(
KERN_ERR "pmu_adb_reset_bus: pmu_queue_request failed\n");
1088 if (save_autopoll != 0)
1089 __pmu_adb_autopoll(save_autopoll);
1106 if (nbytes < 0 || nbytes > 32) {
1125 unsigned long flags;
1136 nsend = pmu_data_len[req->
data[0]][0];
1137 if (nsend >= 0 && req->
nbytes != nsend + 1) {
1147 if (current_req != 0) {
1156 spin_unlock_irqrestore(&pmu_lock, flags);
1169 if (--timeout < 0) {
1182 volatile unsigned char __iomem *v = via;
1193 volatile unsigned char __iomem *v = via;
1223 || (req_awaiting_reply))
1235 send_byte(req->
data[0]);
1245 via_pmu_interrupt(0,
NULL);
1256 adb_int_pending = 1;
1258 via_pmu_interrupt(0,
NULL);
1259 }
while (pmu_suspended && (adb_int_pending ||
pmu_state !=
idle
1260 || req_awaiting_reply));
1269 via_pmu_interrupt(0,
NULL);
1280 unsigned long flags;
1287 if (pmu_suspended > 1) {
1288 spin_unlock_irqrestore(&pmu_lock, flags);
1293 spin_unlock_irqrestore(&pmu_lock, flags);
1294 if (req_awaiting_reply)
1295 adb_int_pending = 1;
1296 via_pmu_interrupt(0,
NULL);
1298 if (!adb_int_pending &&
pmu_state ==
idle && !req_awaiting_reply) {
1302 spin_unlock_irqrestore(&pmu_lock, flags);
1311 unsigned long flags;
1313 if (!via || (pmu_suspended < 1))
1318 if (pmu_suspended > 0) {
1319 spin_unlock_irqrestore(&pmu_lock, flags);
1322 adb_int_pending = 1;
1326 spin_unlock_irqrestore(&pmu_lock, flags);
1332 pmu_handle_data(
unsigned char *
data,
int len)
1334 unsigned char ints, pirq;
1338 if (drop_interrupts || len < 1) {
1339 adb_int_pending = 0;
1358 if (i > pmu_irq_stats[10])
1359 pmu_irq_stats[10] =
i;
1363 for (pirq = 0; pirq < 8; pirq++)
1364 if (ints & (1 << pirq))
1366 pmu_irq_stats[pirq]++;
1368 ints &= ~(1 << pirq);
1381 req_awaiting_reply =
NULL;
1390 if (len == 4 && data[1] == 0x2c) {
1392 if (xmon_wants_key) {
1393 xmon_adb_keycode = data[2];
1405 && data[1] == 0x2c && data[3] == 0xff
1406 && (data[2] & ~1) == 0xf4))
1413 #ifdef CONFIG_PMAC_BACKLIGHT
1422 if ((--query_batt_timer) == 0) {
1423 query_battery_state();
1430 query_battery_state();
1431 pmu_pass_intr(data, len);
1439 pmu_pass_intr(data, len);
1450 if (via[B] &
TREQ) {
1456 while ((
in_8(&via[B]) & TACK) != 0)
1476 send_byte(req->
data[data_index++]);
1483 current_req = req->
next;
1485 req_awaiting_reply =
req;
1502 if (gpio_irq >= 0 && !gpio_irq_enabled) {
1504 gpio_irq_enabled = 1;
1514 }
else if (data_index < 32) {
1515 reply_ptr[data_index++] =
bite;
1525 interrupt_data_len[int_data_last] =
data_len;
1533 current_req = req->
next;
1551 via_pmu_interrupt(
int irq,
void *
arg)
1553 unsigned long flags;
1569 if (++nloop > 1000) {
1571 "intr=%x, ier=%x pmu_state=%d\n",
1577 adb_int_pending = 1;
1581 req = pmu_sr_intr();
1589 if (adb_int_pending) {
1603 adb_int_pending = 0;
1604 }
else if (current_req)
1611 int_data = !int_data_last;
1614 int_data = int_data_last;
1617 spin_unlock_irqrestore(&pmu_lock, flags);
1626 if (int_data >= 0) {
1627 pmu_handle_data(
interrupt_data[int_data], interrupt_data_len[int_data]);
1641 unsigned long flags;
1646 adb_int_pending = 1;
1647 spin_unlock_irqrestore(&pmu_lock, flags);
1652 gpio1_interrupt(
int irq,
void *arg)
1654 unsigned long flags;
1656 if ((
in_8(gpio_reg + 0x9) & 0x02) == 0) {
1658 if (gpio_irq_enabled > 0) {
1660 gpio_irq_enabled = 0;
1663 adb_int_pending = 1;
1664 spin_unlock_irqrestore(&pmu_lock, flags);
1665 via_pmu_interrupt(0,
NULL);
1696 drop_interrupts = 1;
1721 drop_interrupts = 1;
1731 pmu_set_server_mode(0);
1735 'M',
'A',
'T',
'T');
1747 #if defined(CONFIG_SUSPEND) && defined(CONFIG_PPC32)
1752 static u32 save_via[8];
1755 save_via_state(
void)
1757 save_via[0] =
in_8(&via[
ANH]);
1759 save_via[2] =
in_8(&via[B]);
1760 save_via[3] =
in_8(&via[DIRB]);
1761 save_via[4] =
in_8(&via[
PCR]);
1762 save_via[5] =
in_8(&via[ACR]);
1767 restore_via_state(
void)
1771 out_8(&via[B], save_via[2]);
1772 out_8(&via[DIRB], save_via[3]);
1774 out_8(&via[ACR], save_via[5]);
1782 #define GRACKLE_PM (1<<7)
1783 #define GRACKLE_DOZE (1<<5)
1784 #define GRACKLE_NAP (1<<4)
1785 #define GRACKLE_SLEEP (1<<3)
1787 static int powerbook_sleep_grackle(
void)
1789 unsigned long save_l2cr;
1790 unsigned short pmcr1;
1806 save_l2cr = _get_L2CR();
1817 pmac_call_feature(PMAC_FTR_SLEEP_STATE,
NULL,0,1);
1819 pci_read_config_word(grackle, 0x70, &pmcr1);
1821 pmcr1 &= ~(GRACKLE_DOZE|GRACKLE_SLEEP);
1822 pmcr1 |= GRACKLE_PM|GRACKLE_NAP;
1823 pci_write_config_word(grackle, 0x70, pmcr1);
1832 pci_read_config_word(grackle, 0x70, &pmcr1);
1833 pmcr1 &= ~(GRACKLE_PM|GRACKLE_DOZE|GRACKLE_SLEEP|GRACKLE_NAP);
1834 pci_write_config_word(grackle, 0x70, pmcr1);
1839 pmac_call_feature(PMAC_FTR_SLEEP_STATE,
NULL,0,0);
1840 restore_via_state();
1843 if (save_l2cr != 0xffffffff && (save_l2cr & L2CR_L2E) != 0)
1844 _set_L2CR(save_l2cr);
1864 powerbook_sleep_Core99(
void)
1866 unsigned long save_l2cr;
1867 unsigned long save_l3cr;
1870 if (pmac_call_feature(PMAC_FTR_SLEEP_STATE,
NULL,0,-1) < 0) {
1892 save_l3cr = _get_L3CR();
1893 save_l2cr = _get_L2CR();
1908 pmac_call_feature(PMAC_FTR_SLEEP_STATE,
NULL, 0, 1);
1917 pmac_call_feature(PMAC_FTR_SLEEP_STATE,
NULL, 0, 0);
1920 restore_via_state();
1929 if (save_l2cr != 0xffffffff && (save_l2cr & L2CR_L2E) != 0)
1930 _set_L2CR(save_l2cr);
1932 if (save_l3cr != 0xffffffff && (save_l3cr & L3CR_L3E) != 0)
1933 _set_L3CR(save_l3cr);
1951 #define PB3400_MEM_CTRL 0xf8000000
1952 #define PB3400_MEM_CTRL_SLEEP 0x70
1954 static void __iomem *pb3400_mem_ctrl;
1956 static void powerbook_sleep_init_3400(
void)
1959 pb3400_mem_ctrl =
ioremap(PB3400_MEM_CTRL, 0x100);
1960 if (pb3400_mem_ctrl ==
NULL)
1964 static int powerbook_sleep_3400(
void)
1970 unsigned int __iomem *mem_ctrl_sleep;
1972 if (pb3400_mem_ctrl ==
NULL)
1974 mem_ctrl_sleep = pb3400_mem_ctrl + PB3400_MEM_CTRL_SLEEP;
1978 for (i = 0x403f; i >= 0x4000; --
i) {
1981 x = (
in_be32(mem_ctrl_sleep) >> 16) & 0x3ff;
1992 pmac_call_feature(PMAC_FTR_SLEEP_STATE,
NULL, 0, 1);
1997 hid0 =
mfspr(SPRN_HID0);
1998 hid0 = (hid0 & ~(HID0_NAP | HID0_DOZE)) | HID0_SLEEP;
1999 mtspr(SPRN_HID0, hid0);
2001 msr = mfmsr() | MSR_POW;
2011 pmac_call_feature(PMAC_FTR_SLEEP_STATE,
NULL, 0, 0);
2021 #define RB_SIZE 0x10
2028 unsigned char data[16];
2032 #if defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT)
2033 int backlight_locker;
2041 pmu_pass_intr(
unsigned char *data,
int len)
2046 unsigned long flags;
2048 if (len >
sizeof(pp->
rb_buf[0].data))
2049 len =
sizeof(pp->
rb_buf[0].data);
2051 for (list = &all_pmu_pvt; (list = list->
next) != &all_pmu_pvt; ) {
2053 spin_lock(&pp->
lock);
2060 memcpy(rp->data, data, len);
2064 spin_unlock(&pp->
lock);
2066 spin_unlock_irqrestore(&all_pvt_lock, flags);
2070 pmu_open(
struct inode *inode,
struct file *file)
2073 unsigned long flags;
2083 #if defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT)
2084 pp->backlight_locker = 0;
2086 list_add(&pp->
list, &all_pmu_pvt);
2087 spin_unlock_irqrestore(&all_pvt_lock, flags);
2095 size_t count, loff_t *ppos)
2099 unsigned long flags;
2102 if (count < 1 || pp == 0)
2117 spin_unlock_irqrestore(&pp->
lock, flags);
2134 spin_unlock_irqrestore(&pp->
lock, flags);
2140 spin_unlock_irqrestore(&pp->
lock, flags);
2146 pmu_write(
struct file *file,
const char __user *buf,
2147 size_t count, loff_t *ppos)
2156 unsigned int mask = 0;
2157 unsigned long flags;
2161 poll_wait(filp, &pp->
wait, wait);
2165 spin_unlock_irqrestore(&pp->
lock, flags);
2170 pmu_release(
struct inode *inode,
struct file *file)
2173 unsigned long flags;
2179 spin_unlock_irqrestore(&all_pvt_lock, flags);
2181 #if defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT)
2182 if (pp->backlight_locker)
2191 #if defined(CONFIG_SUSPEND) && defined(CONFIG_PPC32)
2192 static void pmac_suspend_disable_irqs(
void)
2204 while (!batt_req.complete)
2212 #ifdef CONFIG_ALTIVEC
2219 error = powerbook_sleep_3400();
2223 error = powerbook_sleep_grackle();
2226 error = powerbook_sleep_Core99();
2240 static void pmac_suspend_enable_irqs(
void)
2243 adb_int_pending = 1;
2244 via_pmu_interrupt(0,
NULL);
2256 && (pmac_call_feature(PMAC_FTR_SLEEP_STATE,
NULL, 0, -1) >= 0);
2260 .
enter = powerbook_sleep,
2261 .valid = pmu_sleep_valid,
2264 static int register_pmu_pm_ops(
void)
2267 powerbook_sleep_init_3400();
2268 ppc_md.suspend_disable_irqs = pmac_suspend_disable_irqs;
2269 ppc_md.suspend_enable_irqs = pmac_suspend_enable_irqs;
2278 static int pmu_ioctl(
struct file *filp,
2290 if (pmac_call_feature(PMAC_FTR_SLEEP_STATE,
NULL, 0, -1) < 0)
2295 #ifdef CONFIG_PMAC_BACKLIGHT_LEGACY
2312 error =
get_user(brightness, argp);
2318 #ifdef CONFIG_INPUT_ADBHID
2322 if (pp->backlight_locker)
2325 pp->backlight_locker = 1;
2336 return put_user(pmu_has_adb, argp);
2341 static long pmu_unlocked_ioctl(
struct file *filp,
2347 ret = pmu_ioctl(filp, cmd, arg);
2353 #ifdef CONFIG_COMPAT
2354 #define PMU_IOC_GET_BACKLIGHT32 _IOR('B', 1, compat_size_t)
2355 #define PMU_IOC_SET_BACKLIGHT32 _IOW('B', 2, compat_size_t)
2356 #define PMU_IOC_GET_MODEL32 _IOR('B', 3, compat_size_t)
2357 #define PMU_IOC_HAS_ADB32 _IOR('B', 4, compat_size_t)
2358 #define PMU_IOC_CAN_SLEEP32 _IOR('B', 5, compat_size_t)
2359 #define PMU_IOC_GRAB_BACKLIGHT32 _IOR('B', 6, compat_size_t)
2361 static long compat_pmu_ioctl (
struct file *filp,
u_int cmd,
u_long arg)
2366 case PMU_IOC_GET_BACKLIGHT32:
2369 case PMU_IOC_SET_BACKLIGHT32:
2372 case PMU_IOC_GET_MODEL32:
2375 case PMU_IOC_HAS_ADB32:
2378 case PMU_IOC_CAN_SLEEP32:
2381 case PMU_IOC_GRAB_BACKLIGHT32:
2387 return pmu_unlocked_ioctl(filp, cmd, (
unsigned long)compat_ptr(arg));
2395 .unlocked_ioctl = pmu_unlocked_ioctl,
2396 #ifdef CONFIG_COMPAT
2397 .compat_ioctl = compat_pmu_ioctl,
2400 .release = pmu_release,
2408 static int pmu_device_init(
void)
2421 polled_handshake(
volatile unsigned char __iomem *via)
2423 via[
B] &= ~TREQ;
eieio();
2424 while ((via[B] & TACK) != 0)
2427 while ((via[B] & TACK) == 0)
2432 polled_send_byte(
volatile unsigned char __iomem *via,
int x)
2436 polled_handshake(via);
2440 polled_recv_byte(
volatile unsigned char __iomem *via)
2446 polled_handshake(via);
2454 unsigned long flags;
2456 volatile unsigned char __iomem *v = via;
2460 l = pmu_data_len[
c][0];
2461 if (l >= 0 && req->
nbytes != l + 1)
2468 while ((via[B] & TACK) == 0)
2470 polled_send_byte(v, c);
2473 polled_send_byte(v, l);
2475 for (i = 1; i <=
l; ++
i)
2476 polled_send_byte(v, req->
data[i]);
2478 l = pmu_data_len[
c][1];
2480 l = polled_recv_byte(v);
2481 for (i = 0; i <
l; ++
i)
2492 void pmu_blink(
int n)
2496 memset(&req, 0,
sizeof(req));
2498 for (; n > 0; --
n) {
2508 pmu_polled_request(&req);
2519 pmu_polled_request(&req);
2526 #if defined(CONFIG_SUSPEND) && defined(CONFIG_PPC32)
2529 static int pmu_syscore_suspend(
void)
2533 pmu_sys_suspended = 1;
2535 #ifdef CONFIG_PMAC_BACKLIGHT
2543 static void pmu_syscore_resume(
void)
2547 if (!pmu_sys_suspended)
2554 #ifdef CONFIG_PMAC_BACKLIGHT
2560 pmu_sys_suspended = 0;
2564 .
suspend = pmu_syscore_suspend,
2565 .resume = pmu_syscore_resume,
2568 static int pmu_syscore_register(
void)
2585 #if defined(CONFIG_PPC32)