2 * Device driver for the via-pmu on Apple Powermacs.
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
9 * and the RTC (real time clock) chip.
11 * Copyright (C) 1998 Paul Mackerras and Fabio Riccardi.
12 * Copyright (C) 2001-2002 Benjamin Herrenschmidt
14 * THIS DRIVER IS BECOMING A TOTAL MESS !
15 * - Cleanup atomically disabling reply to PMU events after
16 * a sleep or a freq. switch
17 * - Move sleep code out of here to pmac_pm, merge into new
18 * common PM infrastructure
19 * - Save/Restore PCI space properly
23 #include <linux/types.h>
24 #include <linux/errno.h>
25 #include <linux/kernel.h>
26 #include <linux/delay.h>
27 #include <linux/sched.h>
28 #include <linux/miscdevice.h>
29 #include <linux/blkdev.h>
30 #include <linux/pci.h>
31 #include <linux/slab.h>
32 #include <linux/poll.h>
33 #include <linux/adb.h>
34 #include <linux/pmu.h>
35 #include <linux/cuda.h>
36 #include <linux/module.h>
37 #include <linux/spinlock.h>
39 #include <linux/proc_fs.h>
40 #include <linux/init.h>
41 #include <linux/interrupt.h>
42 #include <linux/device.h>
43 #include <linux/sysdev.h>
44 #include <linux/freezer.h>
45 #include <linux/syscalls.h>
46 #include <linux/suspend.h>
47 #include <linux/cpu.h>
49 #include <asm/machdep.h>
51 #include <asm/pgtable.h>
52 #include <asm/system.h>
53 #include <asm/sections.h>
55 #include <asm/pmac_feature.h>
56 #include <asm/pmac_pfunc.h>
57 #include <asm/pmac_low_i2c.h>
58 #include <asm/uaccess.h>
59 #include <asm/mmu_context.h>
60 #include <asm/cputable.h>
62 #include <asm/backlight.h>
64 #include "via-pmu-event.h"
66 /* Some compile options */
69 /* Misc minor number allocated for /dev/pmu */
72 /* How many iterations between battery polls */
73 #define BATTERY_POLLING_COUNT 2
75 static volatile unsigned char __iomem *via;
77 /* VIA registers - spaced 0x200 bytes apart */
78 #define RS 0x200 /* skip between registers */
79 #define B 0 /* B-side data */
80 #define A RS /* A-side data */
81 #define DIRB (2*RS) /* B-side direction (1=output) */
82 #define DIRA (3*RS) /* A-side direction (1=output) */
83 #define T1CL (4*RS) /* Timer 1 ctr/latch (low 8 bits) */
84 #define T1CH (5*RS) /* Timer 1 counter (high 8 bits) */
85 #define T1LL (6*RS) /* Timer 1 latch (low 8 bits) */
86 #define T1LH (7*RS) /* Timer 1 latch (high 8 bits) */
87 #define T2CL (8*RS) /* Timer 2 ctr/latch (low 8 bits) */
88 #define T2CH (9*RS) /* Timer 2 counter (high 8 bits) */
89 #define SR (10*RS) /* Shift register */
90 #define ACR (11*RS) /* Auxiliary control register */
91 #define PCR (12*RS) /* Peripheral control register */
92 #define IFR (13*RS) /* Interrupt flag register */
93 #define IER (14*RS) /* Interrupt enable register */
94 #define ANH (15*RS) /* A-side data, no handshake */
96 /* Bits in B data register: both active low */
97 #define TACK 0x08 /* Transfer acknowledge (input) */
98 #define TREQ 0x10 /* Transfer request (output) */
101 #define SR_CTRL 0x1c /* Shift register control bits */
102 #define SR_EXT 0x0c /* Shift on external clock */
103 #define SR_OUT 0x10 /* Shift out if 1 */
105 /* Bits in IFR and IER */
106 #define IER_SET 0x80 /* set bits in IER */
107 #define IER_CLR 0 /* clear bits in IER */
108 #define SR_INT 0x04 /* Shift register full/empty */
110 #define CB1_INT 0x10 /* transition on CB1 input */
112 static volatile enum pmu_state {
121 static volatile enum int_data_state {
126 } int_data_state[2] = { int_data_empty, int_data_empty };
128 static struct adb_request *current_req;
129 static struct adb_request *last_req;
130 static struct adb_request *req_awaiting_reply;
131 static unsigned char interrupt_data[2][32];
132 static int interrupt_data_len[2];
133 static int int_data_last;
134 static unsigned char *reply_ptr;
135 static int data_index;
137 static volatile int adb_int_pending;
138 static volatile int disable_poll;
139 static struct device_node *vias;
140 static int pmu_kind = PMU_UNKNOWN;
141 static int pmu_fully_inited;
142 static int pmu_has_adb;
143 static struct device_node *gpio_node;
144 static unsigned char __iomem *gpio_reg;
145 static int gpio_irq = NO_IRQ;
146 static int gpio_irq_enabled = -1;
147 static volatile int pmu_suspended;
148 static spinlock_t pmu_lock;
149 static u8 pmu_intr_mask;
150 static int pmu_version;
151 static int drop_interrupts;
152 #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_PPC32)
153 static int option_lid_wakeup = 1;
154 #endif /* CONFIG_PM_SLEEP && CONFIG_PPC32 */
155 #if (defined(CONFIG_PM_SLEEP)&&defined(CONFIG_PPC32))||defined(CONFIG_PMAC_BACKLIGHT_LEGACY)
156 static int sleep_in_progress;
158 static unsigned long async_req_locks;
159 static unsigned int pmu_irq_stats[11];
161 static struct proc_dir_entry *proc_pmu_root;
162 static struct proc_dir_entry *proc_pmu_info;
163 static struct proc_dir_entry *proc_pmu_irqstats;
164 static struct proc_dir_entry *proc_pmu_options;
165 static int option_server_mode;
167 int pmu_battery_count;
169 unsigned int pmu_power_flags = PMU_PWR_AC_PRESENT;
170 struct pmu_battery_info pmu_batteries[PMU_MAX_BATTERIES];
171 static int query_batt_timer = BATTERY_POLLING_COUNT;
172 static struct adb_request batt_req;
173 static struct proc_dir_entry *proc_pmu_batt[PMU_MAX_BATTERIES];
179 static int adb_dev_map;
180 static int pmu_adb_flags;
182 static int pmu_probe(void);
183 static int pmu_init(void);
184 static int pmu_send_request(struct adb_request *req, int sync);
185 static int pmu_adb_autopoll(int devs);
186 static int pmu_adb_reset_bus(void);
187 #endif /* CONFIG_ADB */
189 static int init_pmu(void);
190 static void pmu_start(void);
191 static irqreturn_t via_pmu_interrupt(int irq, void *arg);
192 static irqreturn_t gpio1_interrupt(int irq, void *arg);
193 static int proc_get_info(char *page, char **start, off_t off,
194 int count, int *eof, void *data);
195 static int proc_get_irqstats(char *page, char **start, off_t off,
196 int count, int *eof, void *data);
197 static void pmu_pass_intr(unsigned char *data, int len);
198 static int proc_get_batt(char *page, char **start, off_t off,
199 int count, int *eof, void *data);
200 static int proc_read_options(char *page, char **start, off_t off,
201 int count, int *eof, void *data);
202 static int proc_write_options(struct file *file, const char __user *buffer,
203 unsigned long count, void *data);
205 #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_PPC32)
206 static void powerbook_sleep_init_3400(void);
208 #define powerbook_sleep_init_3400() do { } while (0)
212 struct adb_driver via_pmu_driver = {
221 #endif /* CONFIG_ADB */
223 extern void low_sleep_handler(void);
224 extern void enable_kernel_altivec(void);
225 extern void enable_kernel_fp(void);
228 int pmu_polled_request(struct adb_request *req);
229 int pmu_wink(struct adb_request *req);
233 * This table indicates for each PMU opcode:
234 * - the number of data bytes to be sent with the command, or -1
235 * if a length byte should be sent,
236 * - the number of response bytes which the PMU will return, or
237 * -1 if it will send a length byte.
239 static const s8 pmu_data_len[256][2] = {
240 /* 0 1 2 3 4 5 6 7 */
241 /*00*/ {-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
242 /*08*/ {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
243 /*10*/ { 1, 0},{ 1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
244 /*18*/ { 0, 1},{ 0, 1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{ 0, 0},
245 /*20*/ {-1, 0},{ 0, 0},{ 2, 0},{ 1, 0},{ 1, 0},{-1, 0},{-1, 0},{-1, 0},
246 /*28*/ { 0,-1},{ 0,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{ 0,-1},
247 /*30*/ { 4, 0},{20, 0},{-1, 0},{ 3, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
248 /*38*/ { 0, 4},{ 0,20},{ 2,-1},{ 2, 1},{ 3,-1},{-1,-1},{-1,-1},{ 4, 0},
249 /*40*/ { 1, 0},{ 1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
250 /*48*/ { 0, 1},{ 0, 1},{-1,-1},{ 1, 0},{ 1, 0},{-1,-1},{-1,-1},{-1,-1},
251 /*50*/ { 1, 0},{ 0, 0},{ 2, 0},{ 2, 0},{-1, 0},{ 1, 0},{ 3, 0},{ 1, 0},
252 /*58*/ { 0, 1},{ 1, 0},{ 0, 2},{ 0, 2},{ 0,-1},{-1,-1},{-1,-1},{-1,-1},
253 /*60*/ { 2, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
254 /*68*/ { 0, 3},{ 0, 3},{ 0, 2},{ 0, 8},{ 0,-1},{ 0,-1},{-1,-1},{-1,-1},
255 /*70*/ { 1, 0},{ 1, 0},{ 1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
256 /*78*/ { 0,-1},{ 0,-1},{-1,-1},{-1,-1},{-1,-1},{ 5, 1},{ 4, 1},{ 4, 1},
257 /*80*/ { 4, 0},{-1, 0},{ 0, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
258 /*88*/ { 0, 5},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
259 /*90*/ { 1, 0},{ 2, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
260 /*98*/ { 0, 1},{ 0, 1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
261 /*a0*/ { 2, 0},{ 2, 0},{ 2, 0},{ 4, 0},{-1, 0},{ 0, 0},{-1, 0},{-1, 0},
262 /*a8*/ { 1, 1},{ 1, 0},{ 3, 0},{ 2, 0},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
263 /*b0*/ {-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
264 /*b8*/ {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
265 /*c0*/ {-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
266 /*c8*/ {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
267 /*d0*/ { 0, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
268 /*d8*/ { 1, 1},{ 1, 1},{-1,-1},{-1,-1},{ 0, 1},{ 0,-1},{-1,-1},{-1,-1},
269 /*e0*/ {-1, 0},{ 4, 0},{ 0, 1},{-1, 0},{-1, 0},{ 4, 0},{-1, 0},{-1, 0},
270 /*e8*/ { 3,-1},{-1,-1},{ 0, 1},{-1,-1},{ 0,-1},{-1,-1},{-1,-1},{ 0, 0},
271 /*f0*/ {-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
272 /*f8*/ {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
275 static char *pbook_type[] = {
277 "PowerBook 2400/3400/3500(G3)",
278 "PowerBook G3 Series",
283 int __init find_via_pmu(void)
290 vias = of_find_node_by_name(NULL, "via-pmu");
294 reg = of_get_property(vias, "reg", NULL);
296 printk(KERN_ERR "via-pmu: No \"reg\" property !\n");
299 taddr = of_translate_address(vias, reg);
300 if (taddr == OF_BAD_ADDR) {
301 printk(KERN_ERR "via-pmu: Can't translate address !\n");
305 spin_lock_init(&pmu_lock);
309 pmu_intr_mask = PMU_INT_PCEJECT |
314 if (vias->parent->name && ((strcmp(vias->parent->name, "ohare") == 0)
315 || of_device_is_compatible(vias->parent, "ohare")))
316 pmu_kind = PMU_OHARE_BASED;
317 else if (of_device_is_compatible(vias->parent, "paddington"))
318 pmu_kind = PMU_PADDINGTON_BASED;
319 else if (of_device_is_compatible(vias->parent, "heathrow"))
320 pmu_kind = PMU_HEATHROW_BASED;
321 else if (of_device_is_compatible(vias->parent, "Keylargo")
322 || of_device_is_compatible(vias->parent, "K2-Keylargo")) {
323 struct device_node *gpiop;
324 struct device_node *adbp;
325 u64 gaddr = OF_BAD_ADDR;
327 pmu_kind = PMU_KEYLARGO_BASED;
328 adbp = of_find_node_by_type(NULL, "adb");
329 pmu_has_adb = (adbp != NULL);
331 pmu_intr_mask = PMU_INT_PCEJECT |
337 gpiop = of_find_node_by_name(NULL, "gpio");
339 reg = of_get_property(gpiop, "reg", NULL);
341 gaddr = of_translate_address(gpiop, reg);
342 if (gaddr != OF_BAD_ADDR)
343 gpio_reg = ioremap(gaddr, 0x10);
345 if (gpio_reg == NULL) {
346 printk(KERN_ERR "via-pmu: Can't find GPIO reg !\n");
350 pmu_kind = PMU_UNKNOWN;
352 via = ioremap(taddr, 0x2000);
354 printk(KERN_ERR "via-pmu: Can't map address !\n");
358 out_8(&via[IER], IER_CLR | 0x7f); /* disable all intrs */
359 out_8(&via[IFR], 0x7f); /* clear IFR */
368 printk(KERN_INFO "PMU driver v%d initialized for %s, firmware: %02x\n",
369 PMU_DRIVER_VERSION, pbook_type[pmu_kind], pmu_version);
371 sys_ctrler = SYS_CTRLER_PMU;
384 static int pmu_probe(void)
386 return vias == NULL? -ENODEV: 0;
389 static int __init pmu_init(void)
395 #endif /* CONFIG_ADB */
398 * We can't wait until pmu_init gets called, that happens too late.
399 * It happens after IDE and SCSI initialization, which can take a few
400 * seconds, and by that time the PMU could have given up on us and
402 * Thus this is called with arch_initcall rather than device_initcall.
404 static int __init via_pmu_start(void)
411 batt_req.complete = 1;
413 irq = irq_of_parse_and_map(vias, 0);
415 printk(KERN_ERR "via-pmu: can't map interrupt\n");
418 if (request_irq(irq, via_pmu_interrupt, 0, "VIA-PMU", (void *)0)) {
419 printk(KERN_ERR "via-pmu: can't request irq %d\n", irq);
423 if (pmu_kind == PMU_KEYLARGO_BASED) {
424 gpio_node = of_find_node_by_name(NULL, "extint-gpio1");
425 if (gpio_node == NULL)
426 gpio_node = of_find_node_by_name(NULL,
429 gpio_irq = irq_of_parse_and_map(gpio_node, 0);
431 if (gpio_irq != NO_IRQ) {
432 if (request_irq(gpio_irq, gpio1_interrupt, 0,
433 "GPIO1 ADB", (void *)0))
434 printk(KERN_ERR "pmu: can't get irq %d"
435 " (GPIO1)\n", gpio_irq);
437 gpio_irq_enabled = 1;
441 /* Enable interrupts */
442 out_8(&via[IER], IER_SET | SR_INT | CB1_INT);
444 pmu_fully_inited = 1;
446 /* Make sure PMU settle down before continuing. This is _very_ important
447 * since the IDE probe may shut interrupts down for quite a bit of time. If
448 * a PMU communication is pending while this happens, the PMU may timeout
449 * Not that on Core99 machines, the PMU keeps sending us environement
450 * messages, we should find a way to either fix IDE or make it call
451 * pmu_suspend() before masking interrupts. This can also happens while
452 * scolling with some fbdevs.
456 } while (pmu_state != idle);
458 /* Do allocations and ioremaps that will be needed for sleep */
459 if (pmu_kind == PMU_OHARE_BASED)
460 powerbook_sleep_init_3400();
465 arch_initcall(via_pmu_start);
468 * This has to be done after pci_init, which is a subsys_initcall.
470 static int __init via_pmu_dev_init(void)
475 #ifdef CONFIG_PMAC_BACKLIGHT
476 /* Initialize backlight */
477 pmu_backlight_init();
481 if (machine_is_compatible("AAPL,3400/2400") ||
482 machine_is_compatible("AAPL,3500")) {
483 int mb = pmac_call_feature(PMAC_FTR_GET_MB_INFO,
484 NULL, PMAC_MB_INFO_MODEL, 0);
485 pmu_battery_count = 1;
486 if (mb == PMAC_TYPE_COMET)
487 pmu_batteries[0].flags |= PMU_BATT_TYPE_COMET;
489 pmu_batteries[0].flags |= PMU_BATT_TYPE_HOOPER;
490 } else if (machine_is_compatible("AAPL,PowerBook1998") ||
491 machine_is_compatible("PowerBook1,1")) {
492 pmu_battery_count = 2;
493 pmu_batteries[0].flags |= PMU_BATT_TYPE_SMART;
494 pmu_batteries[1].flags |= PMU_BATT_TYPE_SMART;
496 struct device_node* prim =
497 of_find_node_by_name(NULL, "power-mgt");
498 const u32 *prim_info = NULL;
500 prim_info = of_get_property(prim, "prim-info", NULL);
502 /* Other stuffs here yet unknown */
503 pmu_battery_count = (prim_info[6] >> 16) & 0xff;
504 pmu_batteries[0].flags |= PMU_BATT_TYPE_SMART;
505 if (pmu_battery_count > 1)
506 pmu_batteries[1].flags |= PMU_BATT_TYPE_SMART;
510 #endif /* CONFIG_PPC32 */
512 /* Create /proc/pmu */
513 proc_pmu_root = proc_mkdir("pmu", NULL);
517 for (i=0; i<pmu_battery_count; i++) {
519 sprintf(title, "battery_%ld", i);
520 proc_pmu_batt[i] = create_proc_read_entry(title, 0, proc_pmu_root,
521 proc_get_batt, (void *)i);
524 proc_pmu_info = create_proc_read_entry("info", 0, proc_pmu_root,
525 proc_get_info, NULL);
526 proc_pmu_irqstats = create_proc_read_entry("interrupts", 0, proc_pmu_root,
527 proc_get_irqstats, NULL);
528 proc_pmu_options = create_proc_entry("options", 0600, proc_pmu_root);
529 if (proc_pmu_options) {
530 proc_pmu_options->read_proc = proc_read_options;
531 proc_pmu_options->write_proc = proc_write_options;
537 device_initcall(via_pmu_dev_init);
543 struct adb_request req;
545 out_8(&via[B], via[B] | TREQ); /* negate TREQ */
546 out_8(&via[DIRB], (via[DIRB] | TREQ) & ~TACK); /* TACK in, TREQ out */
548 pmu_request(&req, NULL, 2, PMU_SET_INTR_MASK, pmu_intr_mask);
550 while (!req.complete) {
552 printk(KERN_ERR "init_pmu: no response from PMU\n");
559 /* ack all pending interrupts */
561 interrupt_data[0][0] = 1;
562 while (interrupt_data[0][0] || pmu_state != idle) {
564 printk(KERN_ERR "init_pmu: timed out acking intrs\n");
567 if (pmu_state == idle)
569 via_pmu_interrupt(0, NULL);
573 /* Tell PMU we are ready. */
574 if (pmu_kind == PMU_KEYLARGO_BASED) {
575 pmu_request(&req, NULL, 2, PMU_SYSTEM_READY, 2);
576 while (!req.complete)
580 /* Read PMU version */
581 pmu_request(&req, NULL, 1, PMU_GET_VERSION);
582 pmu_wait_complete(&req);
583 if (req.reply_len > 0)
584 pmu_version = req.reply[0];
586 /* Read server mode setting */
587 if (pmu_kind == PMU_KEYLARGO_BASED) {
588 pmu_request(&req, NULL, 2, PMU_POWER_EVENTS,
589 PMU_PWR_GET_POWERUP_EVENTS);
590 pmu_wait_complete(&req);
591 if (req.reply_len == 2) {
592 if (req.reply[1] & PMU_PWR_WAKEUP_AC_INSERT)
593 option_server_mode = 1;
594 printk(KERN_INFO "via-pmu: Server Mode is %s\n",
595 option_server_mode ? "enabled" : "disabled");
607 static void pmu_set_server_mode(int server_mode)
609 struct adb_request req;
611 if (pmu_kind != PMU_KEYLARGO_BASED)
614 option_server_mode = server_mode;
615 pmu_request(&req, NULL, 2, PMU_POWER_EVENTS, PMU_PWR_GET_POWERUP_EVENTS);
616 pmu_wait_complete(&req);
617 if (req.reply_len < 2)
620 pmu_request(&req, NULL, 4, PMU_POWER_EVENTS,
621 PMU_PWR_SET_POWERUP_EVENTS,
622 req.reply[0], PMU_PWR_WAKEUP_AC_INSERT);
624 pmu_request(&req, NULL, 4, PMU_POWER_EVENTS,
625 PMU_PWR_CLR_POWERUP_EVENTS,
626 req.reply[0], PMU_PWR_WAKEUP_AC_INSERT);
627 pmu_wait_complete(&req);
630 /* This new version of the code for 2400/3400/3500 powerbooks
631 * is inspired from the implementation in gkrellm-pmu
634 done_battery_state_ohare(struct adb_request* req)
638 * 0x01 : AC indicator
640 * 0x04 : battery exist
643 * 0x20 : full charged
644 * 0x40 : pcharge reset
645 * 0x80 : battery exist
647 * [1][2] : battery voltage
648 * [3] : CPU temperature
649 * [4] : battery temperature
654 unsigned int bat_flags = PMU_BATT_TYPE_HOOPER;
655 long pcharge, charge, vb, vmax, lmax;
656 long vmax_charging, vmax_charged;
657 long amperage, voltage, time, max;
658 int mb = pmac_call_feature(PMAC_FTR_GET_MB_INFO,
659 NULL, PMAC_MB_INFO_MODEL, 0);
661 if (req->reply[0] & 0x01)
662 pmu_power_flags |= PMU_PWR_AC_PRESENT;
664 pmu_power_flags &= ~PMU_PWR_AC_PRESENT;
666 if (mb == PMAC_TYPE_COMET) {
677 /* If battery installed */
678 if (req->reply[0] & 0x04) {
679 bat_flags |= PMU_BATT_PRESENT;
680 if (req->reply[0] & 0x02)
681 bat_flags |= PMU_BATT_CHARGING;
682 vb = (req->reply[1] << 8) | req->reply[2];
683 voltage = (vb * 265 + 72665) / 10;
684 amperage = req->reply[5];
685 if ((req->reply[0] & 0x01) == 0) {
687 vb += ((amperage - 200) * 15)/100;
688 } else if (req->reply[0] & 0x02) {
689 vb = (vb * 97) / 100;
690 vmax = vmax_charging;
692 charge = (100 * vb) / vmax;
693 if (req->reply[0] & 0x40) {
694 pcharge = (req->reply[6] << 8) + req->reply[7];
698 pcharge = 100 - pcharge / lmax;
699 if (pcharge < charge)
703 time = (charge * 16440) / amperage;
707 amperage = -amperage;
709 charge = max = amperage = voltage = time = 0;
711 pmu_batteries[pmu_cur_battery].flags = bat_flags;
712 pmu_batteries[pmu_cur_battery].charge = charge;
713 pmu_batteries[pmu_cur_battery].max_charge = max;
714 pmu_batteries[pmu_cur_battery].amperage = amperage;
715 pmu_batteries[pmu_cur_battery].voltage = voltage;
716 pmu_batteries[pmu_cur_battery].time_remaining = time;
718 clear_bit(0, &async_req_locks);
722 done_battery_state_smart(struct adb_request* req)
725 * [0] : format of this structure (known: 3,4,5)
738 * [4][5] : max charge
743 unsigned int bat_flags = PMU_BATT_TYPE_SMART;
745 unsigned int capa, max, voltage;
747 if (req->reply[1] & 0x01)
748 pmu_power_flags |= PMU_PWR_AC_PRESENT;
750 pmu_power_flags &= ~PMU_PWR_AC_PRESENT;
753 capa = max = amperage = voltage = 0;
755 if (req->reply[1] & 0x04) {
756 bat_flags |= PMU_BATT_PRESENT;
757 switch(req->reply[0]) {
759 case 4: capa = req->reply[2];
761 amperage = *((signed char *)&req->reply[4]);
762 voltage = req->reply[5];
764 case 5: capa = (req->reply[2] << 8) | req->reply[3];
765 max = (req->reply[4] << 8) | req->reply[5];
766 amperage = *((signed short *)&req->reply[6]);
767 voltage = (req->reply[8] << 8) | req->reply[9];
770 printk(KERN_WARNING "pmu.c : unrecognized battery info, len: %d, %02x %02x %02x %02x\n",
771 req->reply_len, req->reply[0], req->reply[1], req->reply[2], req->reply[3]);
776 if ((req->reply[1] & 0x01) && (amperage > 0))
777 bat_flags |= PMU_BATT_CHARGING;
779 pmu_batteries[pmu_cur_battery].flags = bat_flags;
780 pmu_batteries[pmu_cur_battery].charge = capa;
781 pmu_batteries[pmu_cur_battery].max_charge = max;
782 pmu_batteries[pmu_cur_battery].amperage = amperage;
783 pmu_batteries[pmu_cur_battery].voltage = voltage;
785 if ((req->reply[1] & 0x01) && (amperage > 0))
786 pmu_batteries[pmu_cur_battery].time_remaining
787 = ((max-capa) * 3600) / amperage;
789 pmu_batteries[pmu_cur_battery].time_remaining
790 = (capa * 3600) / (-amperage);
792 pmu_batteries[pmu_cur_battery].time_remaining = 0;
794 pmu_cur_battery = (pmu_cur_battery + 1) % pmu_battery_count;
796 clear_bit(0, &async_req_locks);
800 query_battery_state(void)
802 if (test_and_set_bit(0, &async_req_locks))
804 if (pmu_kind == PMU_OHARE_BASED)
805 pmu_request(&batt_req, done_battery_state_ohare,
806 1, PMU_BATTERY_STATE);
808 pmu_request(&batt_req, done_battery_state_smart,
809 2, PMU_SMART_BATTERY_STATE, pmu_cur_battery+1);
813 proc_get_info(char *page, char **start, off_t off,
814 int count, int *eof, void *data)
818 p += sprintf(p, "PMU driver version : %d\n", PMU_DRIVER_VERSION);
819 p += sprintf(p, "PMU firmware version : %02x\n", pmu_version);
820 p += sprintf(p, "AC Power : %d\n",
821 ((pmu_power_flags & PMU_PWR_AC_PRESENT) != 0) || pmu_battery_count == 0);
822 p += sprintf(p, "Battery count : %d\n", pmu_battery_count);
828 proc_get_irqstats(char *page, char **start, off_t off,
829 int count, int *eof, void *data)
833 static const char *irq_names[] = {
834 "Total CB1 triggered events",
835 "Total GPIO1 triggered events",
836 "PC-Card eject button",
837 "Sound/Brightness button",
839 "Battery state change",
840 "Environment interrupt",
842 "Ghost interrupt (zero len)",
843 "Empty interrupt (empty mask)",
847 for (i=0; i<11; i++) {
848 p += sprintf(p, " %2u: %10u (%s)\n",
849 i, pmu_irq_stats[i], irq_names[i]);
855 proc_get_batt(char *page, char **start, off_t off,
856 int count, int *eof, void *data)
858 long batnum = (long)data;
861 p += sprintf(p, "\n");
862 p += sprintf(p, "flags : %08x\n",
863 pmu_batteries[batnum].flags);
864 p += sprintf(p, "charge : %d\n",
865 pmu_batteries[batnum].charge);
866 p += sprintf(p, "max_charge : %d\n",
867 pmu_batteries[batnum].max_charge);
868 p += sprintf(p, "current : %d\n",
869 pmu_batteries[batnum].amperage);
870 p += sprintf(p, "voltage : %d\n",
871 pmu_batteries[batnum].voltage);
872 p += sprintf(p, "time rem. : %d\n",
873 pmu_batteries[batnum].time_remaining);
879 proc_read_options(char *page, char **start, off_t off,
880 int count, int *eof, void *data)
884 #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_PPC32)
885 if (pmu_kind == PMU_KEYLARGO_BASED &&
886 pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) >= 0)
887 p += sprintf(p, "lid_wakeup=%d\n", option_lid_wakeup);
889 if (pmu_kind == PMU_KEYLARGO_BASED)
890 p += sprintf(p, "server_mode=%d\n", option_server_mode);
896 proc_write_options(struct file *file, const char __user *buffer,
897 unsigned long count, void *data)
901 unsigned long fcount = count;
907 if (copy_from_user(tmp, buffer, count))
915 while(*val && (*val != '=')) {
925 #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_PPC32)
926 if (pmu_kind == PMU_KEYLARGO_BASED &&
927 pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) >= 0)
928 if (!strcmp(label, "lid_wakeup"))
929 option_lid_wakeup = ((*val) == '1');
931 if (pmu_kind == PMU_KEYLARGO_BASED && !strcmp(label, "server_mode")) {
933 new_value = ((*val) == '1');
934 if (new_value != option_server_mode)
935 pmu_set_server_mode(new_value);
941 /* Send an ADB command */
943 pmu_send_request(struct adb_request *req, int sync)
947 if ((vias == NULL) || (!pmu_fully_inited)) {
954 switch (req->data[0]) {
956 for (i = 0; i < req->nbytes - 1; ++i)
957 req->data[i] = req->data[i+1];
959 if (pmu_data_len[req->data[0]][1] != 0) {
960 req->reply[0] = ADB_RET_OK;
964 ret = pmu_queue_request(req);
967 switch (req->data[1]) {
969 if (req->nbytes != 2)
971 req->data[0] = PMU_READ_RTC;
974 req->reply[0] = CUDA_PACKET;
976 req->reply[2] = CUDA_GET_TIME;
977 ret = pmu_queue_request(req);
980 if (req->nbytes != 6)
982 req->data[0] = PMU_SET_RTC;
984 for (i = 1; i <= 4; ++i)
985 req->data[i] = req->data[i+1];
987 req->reply[0] = CUDA_PACKET;
989 req->reply[2] = CUDA_SET_TIME;
990 ret = pmu_queue_request(req);
997 for (i = req->nbytes - 1; i > 1; --i)
998 req->data[i+2] = req->data[i];
999 req->data[3] = req->nbytes - 2;
1000 req->data[2] = pmu_adb_flags;
1001 /*req->data[1] = req->data[1];*/
1002 req->data[0] = PMU_ADB_CMD;
1004 req->reply_expected = 1;
1006 ret = pmu_queue_request(req);
1015 while (!req->complete)
1021 /* Enable/disable autopolling */
1023 pmu_adb_autopoll(int devs)
1025 struct adb_request req;
1027 if ((vias == NULL) || (!pmu_fully_inited) || !pmu_has_adb)
1032 pmu_request(&req, NULL, 5, PMU_ADB_CMD, 0, 0x86,
1033 adb_dev_map >> 8, adb_dev_map);
1036 pmu_request(&req, NULL, 1, PMU_ADB_POLL_OFF);
1039 while (!req.complete)
1044 /* Reset the ADB bus */
1046 pmu_adb_reset_bus(void)
1048 struct adb_request req;
1049 int save_autopoll = adb_dev_map;
1051 if ((vias == NULL) || (!pmu_fully_inited) || !pmu_has_adb)
1054 /* anyone got a better idea?? */
1055 pmu_adb_autopoll(0);
1059 req.data[0] = PMU_ADB_CMD;
1061 req.data[2] = ADB_BUSRESET;
1065 req.reply_expected = 1;
1066 if (pmu_queue_request(&req) != 0) {
1067 printk(KERN_ERR "pmu_adb_reset_bus: pmu_queue_request failed\n");
1070 pmu_wait_complete(&req);
1072 if (save_autopoll != 0)
1073 pmu_adb_autopoll(save_autopoll);
1077 #endif /* CONFIG_ADB */
1079 /* Construct and send a pmu request */
1081 pmu_request(struct adb_request *req, void (*done)(struct adb_request *),
1090 if (nbytes < 0 || nbytes > 32) {
1091 printk(KERN_ERR "pmu_request: bad nbytes (%d)\n", nbytes);
1095 req->nbytes = nbytes;
1097 va_start(list, nbytes);
1098 for (i = 0; i < nbytes; ++i)
1099 req->data[i] = va_arg(list, int);
1102 req->reply_expected = 0;
1103 return pmu_queue_request(req);
1107 pmu_queue_request(struct adb_request *req)
1109 unsigned long flags;
1116 if (req->nbytes <= 0) {
1120 nsend = pmu_data_len[req->data[0]][0];
1121 if (nsend >= 0 && req->nbytes != nsend + 1) {
1130 spin_lock_irqsave(&pmu_lock, flags);
1131 if (current_req != 0) {
1132 last_req->next = req;
1137 if (pmu_state == idle)
1140 spin_unlock_irqrestore(&pmu_lock, flags);
1148 /* Sightly increased the delay, I had one occurrence of the message
1152 while ((in_8(&via[B]) & TACK) == 0) {
1153 if (--timeout < 0) {
1154 printk(KERN_ERR "PMU not responding (!ack)\n");
1161 /* New PMU seems to be very sensitive to those timings, so we make sure
1162 * PCI is flushed immediately */
1166 volatile unsigned char __iomem *v = via;
1168 out_8(&v[ACR], in_8(&v[ACR]) | SR_OUT | SR_EXT);
1170 out_8(&v[B], in_8(&v[B]) & ~TREQ); /* assert TREQ */
1177 volatile unsigned char __iomem *v = via;
1179 out_8(&v[ACR], (in_8(&v[ACR]) & ~SR_OUT) | SR_EXT);
1180 in_8(&v[SR]); /* resets SR */
1181 out_8(&v[B], in_8(&v[B]) & ~TREQ);
1186 pmu_done(struct adb_request *req)
1188 void (*done)(struct adb_request *) = req->done;
1191 /* Here, we assume that if the request has a done member, the
1192 * struct request will survive to setting req->complete to 1
1201 struct adb_request *req;
1203 /* assert pmu_state == idle */
1204 /* get the packet to send */
1206 if (req == 0 || pmu_state != idle
1207 || (/*req->reply_expected && */req_awaiting_reply))
1210 pmu_state = sending;
1212 data_len = pmu_data_len[req->data[0]][0];
1214 /* Sounds safer to make sure ACK is high before writing. This helped
1215 * kill a problem with ADB and some iBooks
1218 /* set the shift register to shift out and send a byte */
1219 send_byte(req->data[0]);
1229 via_pmu_interrupt(0, NULL);
1239 /* Kicks ADB read when PMU is suspended */
1240 adb_int_pending = 1;
1242 via_pmu_interrupt(0, NULL);
1243 } while (pmu_suspended && (adb_int_pending || pmu_state != idle
1244 || req_awaiting_reply));
1248 pmu_wait_complete(struct adb_request *req)
1252 while((pmu_state != idle && pmu_state != locked) || !req->complete)
1253 via_pmu_interrupt(0, NULL);
1256 /* This function loops until the PMU is idle and prevents it from
1257 * anwsering to ADB interrupts. pmu_request can still be called.
1258 * This is done to avoid spurrious shutdowns when we know we'll have
1259 * interrupts switched off for a long time
1264 unsigned long flags;
1269 spin_lock_irqsave(&pmu_lock, flags);
1271 if (pmu_suspended > 1) {
1272 spin_unlock_irqrestore(&pmu_lock, flags);
1277 spin_unlock_irqrestore(&pmu_lock, flags);
1278 if (req_awaiting_reply)
1279 adb_int_pending = 1;
1280 via_pmu_interrupt(0, NULL);
1281 spin_lock_irqsave(&pmu_lock, flags);
1282 if (!adb_int_pending && pmu_state == idle && !req_awaiting_reply) {
1284 disable_irq_nosync(gpio_irq);
1285 out_8(&via[IER], CB1_INT | IER_CLR);
1286 spin_unlock_irqrestore(&pmu_lock, flags);
1295 unsigned long flags;
1297 if (!via || (pmu_suspended < 1))
1300 spin_lock_irqsave(&pmu_lock, flags);
1302 if (pmu_suspended > 0) {
1303 spin_unlock_irqrestore(&pmu_lock, flags);
1306 adb_int_pending = 1;
1308 enable_irq(gpio_irq);
1309 out_8(&via[IER], CB1_INT | IER_SET);
1310 spin_unlock_irqrestore(&pmu_lock, flags);
1314 /* Interrupt data could be the result data from an ADB cmd */
1316 pmu_handle_data(unsigned char *data, int len)
1318 unsigned char ints, pirq;
1322 if (drop_interrupts || len < 1) {
1323 adb_int_pending = 0;
1328 /* Get PMU interrupt mask */
1331 /* Record zero interrupts for stats */
1335 /* Hack to deal with ADB autopoll flag */
1336 if (ints & PMU_INT_ADB)
1337 ints &= ~(PMU_INT_ADB_AUTO | PMU_INT_AUTO_SRQ_POLL);
1342 if (i > pmu_irq_stats[10])
1343 pmu_irq_stats[10] = i;
1347 for (pirq = 0; pirq < 8; pirq++)
1348 if (ints & (1 << pirq))
1350 pmu_irq_stats[pirq]++;
1352 ints &= ~(1 << pirq);
1354 /* Note: for some reason, we get an interrupt with len=1,
1355 * data[0]==0 after each normal ADB interrupt, at least
1356 * on the Pismo. Still investigating... --BenH
1358 if ((1 << pirq) & PMU_INT_ADB) {
1359 if ((data[0] & PMU_INT_ADB_AUTO) == 0) {
1360 struct adb_request *req = req_awaiting_reply;
1362 printk(KERN_ERR "PMU: extra ADB reply\n");
1365 req_awaiting_reply = NULL;
1369 memcpy(req->reply, data + 1, len - 1);
1370 req->reply_len = len - 1;
1374 if (len == 4 && data[1] == 0x2c) {
1375 extern int xmon_wants_key, xmon_adb_keycode;
1376 if (xmon_wants_key) {
1377 xmon_adb_keycode = data[2];
1383 * XXX On the [23]400 the PMU gives us an up
1384 * event for keycodes 0x74 or 0x75 when the PC
1385 * card eject buttons are released, so we
1386 * ignore those events.
1388 if (!(pmu_kind == PMU_OHARE_BASED && len == 4
1389 && data[1] == 0x2c && data[3] == 0xff
1390 && (data[2] & ~1) == 0xf4))
1391 adb_input(data+1, len-1, 1);
1392 #endif /* CONFIG_ADB */
1395 /* Sound/brightness button pressed */
1396 else if ((1 << pirq) & PMU_INT_SNDBRT) {
1397 #ifdef CONFIG_PMAC_BACKLIGHT
1399 pmac_backlight_set_legacy_brightness_pmu(data[1] >> 4);
1402 /* Tick interrupt */
1403 else if ((1 << pirq) & PMU_INT_TICK) {
1404 /* Environement or tick interrupt, query batteries */
1405 if (pmu_battery_count) {
1406 if ((--query_batt_timer) == 0) {
1407 query_battery_state();
1408 query_batt_timer = BATTERY_POLLING_COUNT;
1412 else if ((1 << pirq) & PMU_INT_ENVIRONMENT) {
1413 if (pmu_battery_count)
1414 query_battery_state();
1415 pmu_pass_intr(data, len);
1416 /* len == 6 is probably a bad check. But how do I
1417 * know what PMU versions send what events here? */
1419 via_pmu_event(PMU_EVT_POWER, !!(data[1]&8));
1420 via_pmu_event(PMU_EVT_LID, data[1]&1);
1423 pmu_pass_intr(data, len);
1428 static struct adb_request*
1431 struct adb_request *req;
1434 if (via[B] & TREQ) {
1435 printk(KERN_ERR "PMU: spurious SR intr (%x)\n", via[B]);
1436 out_8(&via[IFR], SR_INT);
1439 /* The ack may not yet be low when we get the interrupt */
1440 while ((in_8(&via[B]) & TACK) != 0)
1443 /* if reading grab the byte, and reset the interrupt */
1444 if (pmu_state == reading || pmu_state == reading_intr)
1445 bite = in_8(&via[SR]);
1447 /* reset TREQ and wait for TACK to go high */
1448 out_8(&via[B], in_8(&via[B]) | TREQ);
1451 switch (pmu_state) {
1455 data_len = req->nbytes - 1;
1456 send_byte(data_len);
1459 if (data_index <= data_len) {
1460 send_byte(req->data[data_index++]);
1464 data_len = pmu_data_len[req->data[0]][1];
1465 if (data_len == 0) {
1467 current_req = req->next;
1468 if (req->reply_expected)
1469 req_awaiting_reply = req;
1473 pmu_state = reading;
1475 reply_ptr = req->reply + req->reply_len;
1483 pmu_state = reading_intr;
1484 reply_ptr = interrupt_data[int_data_last];
1486 if (gpio_irq >= 0 && !gpio_irq_enabled) {
1487 enable_irq(gpio_irq);
1488 gpio_irq_enabled = 1;
1494 if (data_len == -1) {
1497 printk(KERN_ERR "PMU: bad reply len %d\n", bite);
1498 } else if (data_index < 32) {
1499 reply_ptr[data_index++] = bite;
1501 if (data_index < data_len) {
1506 if (pmu_state == reading_intr) {
1508 int_data_state[int_data_last] = int_data_ready;
1509 interrupt_data_len[int_data_last] = data_len;
1513 * For PMU sleep and freq change requests, we lock the
1514 * PMU until it's explicitly unlocked. This avoids any
1515 * spurrious event polling getting in
1517 current_req = req->next;
1518 req->reply_len += data_index;
1519 if (req->data[0] == PMU_SLEEP || req->data[0] == PMU_CPU_SPEED)
1528 printk(KERN_ERR "via_pmu_interrupt: unknown state %d?\n",
1535 via_pmu_interrupt(int irq, void *arg)
1537 unsigned long flags;
1541 struct adb_request *req = NULL;
1544 /* This is a bit brutal, we can probably do better */
1545 spin_lock_irqsave(&pmu_lock, flags);
1549 intr = in_8(&via[IFR]) & (SR_INT | CB1_INT);
1553 if (++nloop > 1000) {
1554 printk(KERN_DEBUG "PMU: stuck in intr loop, "
1555 "intr=%x, ier=%x pmu_state=%d\n",
1556 intr, in_8(&via[IER]), pmu_state);
1559 out_8(&via[IFR], intr);
1560 if (intr & CB1_INT) {
1561 adb_int_pending = 1;
1564 if (intr & SR_INT) {
1565 req = pmu_sr_intr();
1572 if (pmu_state == idle) {
1573 if (adb_int_pending) {
1574 if (int_data_state[0] == int_data_empty)
1576 else if (int_data_state[1] == int_data_empty)
1581 int_data_state[int_data_last] = int_data_fill;
1582 /* Sounds safer to make sure ACK is high before writing.
1583 * This helped kill a problem with ADB and some iBooks
1586 send_byte(PMU_INT_ACK);
1587 adb_int_pending = 0;
1588 } else if (current_req)
1592 /* Mark the oldest buffer for flushing */
1593 if (int_data_state[!int_data_last] == int_data_ready) {
1594 int_data_state[!int_data_last] = int_data_flush;
1595 int_data = !int_data_last;
1596 } else if (int_data_state[int_data_last] == int_data_ready) {
1597 int_data_state[int_data_last] = int_data_flush;
1598 int_data = int_data_last;
1601 spin_unlock_irqrestore(&pmu_lock, flags);
1603 /* Deal with completed PMU requests outside of the lock */
1609 /* Deal with interrupt datas outside of the lock */
1610 if (int_data >= 0) {
1611 pmu_handle_data(interrupt_data[int_data], interrupt_data_len[int_data]);
1612 spin_lock_irqsave(&pmu_lock, flags);
1614 int_data_state[int_data] = int_data_empty;
1619 return IRQ_RETVAL(handled);
1625 unsigned long flags;
1627 spin_lock_irqsave(&pmu_lock, flags);
1628 if (pmu_state == locked)
1630 adb_int_pending = 1;
1631 spin_unlock_irqrestore(&pmu_lock, flags);
1636 gpio1_interrupt(int irq, void *arg)
1638 unsigned long flags;
1640 if ((in_8(gpio_reg + 0x9) & 0x02) == 0) {
1641 spin_lock_irqsave(&pmu_lock, flags);
1642 if (gpio_irq_enabled > 0) {
1643 disable_irq_nosync(gpio_irq);
1644 gpio_irq_enabled = 0;
1647 adb_int_pending = 1;
1648 spin_unlock_irqrestore(&pmu_lock, flags);
1649 via_pmu_interrupt(0, NULL);
1656 pmu_enable_irled(int on)
1658 struct adb_request req;
1662 if (pmu_kind == PMU_KEYLARGO_BASED)
1665 pmu_request(&req, NULL, 2, PMU_POWER_CTRL, PMU_POW_IRLED |
1666 (on ? PMU_POW_ON : PMU_POW_OFF));
1667 pmu_wait_complete(&req);
1673 struct adb_request req;
1678 local_irq_disable();
1680 drop_interrupts = 1;
1682 if (pmu_kind != PMU_KEYLARGO_BASED) {
1683 pmu_request(&req, NULL, 2, PMU_SET_INTR_MASK, PMU_INT_ADB |
1685 while(!req.complete)
1689 pmu_request(&req, NULL, 1, PMU_RESET);
1690 pmu_wait_complete(&req);
1698 struct adb_request req;
1703 local_irq_disable();
1705 drop_interrupts = 1;
1707 if (pmu_kind != PMU_KEYLARGO_BASED) {
1708 pmu_request(&req, NULL, 2, PMU_SET_INTR_MASK, PMU_INT_ADB |
1710 pmu_wait_complete(&req);
1712 /* Disable server mode on shutdown or we'll just
1715 pmu_set_server_mode(0);
1718 pmu_request(&req, NULL, 5, PMU_SHUTDOWN,
1719 'M', 'A', 'T', 'T');
1720 pmu_wait_complete(&req);
1731 #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_PPC32)
1733 /* N.B. This doesn't work on the 3400 */
1737 struct adb_request req;
1739 memset(&req, 0, sizeof(req));
1741 for (; n > 0; --n) {
1748 req.reply[0] = ADB_RET_OK;
1750 req.reply_expected = 0;
1751 pmu_polled_request(&req);
1759 req.reply[0] = ADB_RET_OK;
1761 req.reply_expected = 0;
1762 pmu_polled_request(&req);
1770 * Put the powerbook to sleep.
1773 static u32 save_via[8];
1776 save_via_state(void)
1778 save_via[0] = in_8(&via[ANH]);
1779 save_via[1] = in_8(&via[DIRA]);
1780 save_via[2] = in_8(&via[B]);
1781 save_via[3] = in_8(&via[DIRB]);
1782 save_via[4] = in_8(&via[PCR]);
1783 save_via[5] = in_8(&via[ACR]);
1784 save_via[6] = in_8(&via[T1CL]);
1785 save_via[7] = in_8(&via[T1CH]);
1788 restore_via_state(void)
1790 out_8(&via[ANH], save_via[0]);
1791 out_8(&via[DIRA], save_via[1]);
1792 out_8(&via[B], save_via[2]);
1793 out_8(&via[DIRB], save_via[3]);
1794 out_8(&via[PCR], save_via[4]);
1795 out_8(&via[ACR], save_via[5]);
1796 out_8(&via[T1CL], save_via[6]);
1797 out_8(&via[T1CH], save_via[7]);
1798 out_8(&via[IER], IER_CLR | 0x7f); /* disable all intrs */
1799 out_8(&via[IFR], 0x7f); /* clear IFR */
1800 out_8(&via[IER], IER_SET | SR_INT | CB1_INT);
1803 extern void pmu_backlight_set_sleep(int sleep);
1806 pmac_suspend_devices(void)
1810 pm_prepare_console();
1812 /* Sync the disks. */
1813 /* XXX It would be nice to have some way to ensure that
1814 * nobody is dirtying any new buffers while we wait. That
1815 * could be achieved using the refrigerator for processes
1820 /* Send suspend call to devices, hold the device core's dpm_sem */
1821 ret = device_suspend(PMSG_SUSPEND);
1823 printk(KERN_ERR "Driver sleep failed\n");
1827 #ifdef CONFIG_PMAC_BACKLIGHT
1828 /* Tell backlight code not to muck around with the chip anymore */
1829 pmu_backlight_set_sleep(1);
1832 /* Call platform functions marked "on sleep" */
1833 pmac_pfunc_i2c_suspend();
1834 pmac_pfunc_base_suspend();
1836 /* Stop preemption */
1839 /* Make sure the decrementer won't interrupt us */
1840 asm volatile("mtdec %0" : : "r" (0x7fffffff));
1841 /* Make sure any pending DEC interrupt occurring while we did
1842 * the above didn't re-enable the DEC */
1844 asm volatile("mtdec %0" : : "r" (0x7fffffff));
1846 /* We can now disable MSR_EE. This code of course works properly only
1847 * on UP machines... For SMP, if we ever implement sleep, we'll have to
1848 * stop the "other" CPUs way before we do all that stuff.
1850 local_irq_disable();
1852 /* Broadcast power down irq
1853 * This isn't that useful in most cases (only directly wired devices can
1854 * use this but still... This will take care of sysdev's as well, so
1855 * we exit from here with local irqs disabled and PIC off.
1857 ret = device_power_down(PMSG_SUSPEND);
1859 wakeup_decrementer();
1863 printk(KERN_ERR "Driver powerdown failed\n");
1867 /* Wait for completion of async requests */
1868 while (!batt_req.complete)
1871 /* Giveup the lazy FPU & vec so we don't have to back them
1872 * up from the low level code
1876 #ifdef CONFIG_ALTIVEC
1877 if (cpu_has_feature(CPU_FTR_ALTIVEC))
1878 enable_kernel_altivec();
1879 #endif /* CONFIG_ALTIVEC */
1885 pmac_wakeup_devices(void)
1889 #ifdef CONFIG_PMAC_BACKLIGHT
1890 /* Tell backlight code it can use the chip again */
1891 pmu_backlight_set_sleep(0);
1894 /* Power back up system devices (including the PIC) */
1897 /* Force a poll of ADB interrupts */
1898 adb_int_pending = 1;
1899 via_pmu_interrupt(0, NULL);
1901 /* Restart jiffies & scheduling */
1902 wakeup_decrementer();
1904 /* Re-enable local CPU interrupts */
1909 /* Call platform functions marked "on wake" */
1910 pmac_pfunc_base_resume();
1911 pmac_pfunc_i2c_resume();
1913 /* Resume devices */
1916 pm_restore_console();
1921 #define GRACKLE_PM (1<<7)
1922 #define GRACKLE_DOZE (1<<5)
1923 #define GRACKLE_NAP (1<<4)
1924 #define GRACKLE_SLEEP (1<<3)
1926 static int powerbook_sleep_grackle(void)
1928 unsigned long save_l2cr;
1929 unsigned short pmcr1;
1930 struct adb_request req;
1932 struct pci_dev *grackle;
1934 grackle = pci_get_bus_and_slot(0, 0);
1938 ret = pmac_suspend_devices();
1940 printk(KERN_ERR "Sleep rejected by devices\n");
1944 /* Turn off various things. Darwin does some retry tests here... */
1945 pmu_request(&req, NULL, 2, PMU_POWER_CTRL0, PMU_POW0_OFF|PMU_POW0_HARD_DRIVE);
1946 pmu_wait_complete(&req);
1947 pmu_request(&req, NULL, 2, PMU_POWER_CTRL,
1948 PMU_POW_OFF|PMU_POW_BACKLIGHT|PMU_POW_IRLED|PMU_POW_MEDIABAY);
1949 pmu_wait_complete(&req);
1951 /* For 750, save backside cache setting and disable it */
1952 save_l2cr = _get_L2CR(); /* (returns -1 if not available) */
1954 if (!__fake_sleep) {
1955 /* Ask the PMU to put us to sleep */
1956 pmu_request(&req, NULL, 5, PMU_SLEEP, 'M', 'A', 'T', 'T');
1957 pmu_wait_complete(&req);
1960 /* The VIA is supposed not to be restored correctly*/
1962 /* We shut down some HW */
1963 pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,1);
1965 pci_read_config_word(grackle, 0x70, &pmcr1);
1966 /* Apparently, MacOS uses NAP mode for Grackle ??? */
1967 pmcr1 &= ~(GRACKLE_DOZE|GRACKLE_SLEEP);
1968 pmcr1 |= GRACKLE_PM|GRACKLE_NAP;
1969 pci_write_config_word(grackle, 0x70, pmcr1);
1971 /* Call low-level ASM sleep handler */
1975 low_sleep_handler();
1977 /* We're awake again, stop grackle PM */
1978 pci_read_config_word(grackle, 0x70, &pmcr1);
1979 pmcr1 &= ~(GRACKLE_PM|GRACKLE_DOZE|GRACKLE_SLEEP|GRACKLE_NAP);
1980 pci_write_config_word(grackle, 0x70, pmcr1);
1982 pci_dev_put(grackle);
1984 /* Make sure the PMU is idle */
1985 pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,0);
1986 restore_via_state();
1988 /* Restore L2 cache */
1989 if (save_l2cr != 0xffffffff && (save_l2cr & L2CR_L2E) != 0)
1990 _set_L2CR(save_l2cr);
1992 /* Restore userland MMU context */
1993 set_context(current->active_mm->context.id, current->active_mm->pgd);
1995 /* Power things up */
1997 pmu_request(&req, NULL, 2, PMU_SET_INTR_MASK, pmu_intr_mask);
1998 pmu_wait_complete(&req);
1999 pmu_request(&req, NULL, 2, PMU_POWER_CTRL0,
2000 PMU_POW0_ON|PMU_POW0_HARD_DRIVE);
2001 pmu_wait_complete(&req);
2002 pmu_request(&req, NULL, 2, PMU_POWER_CTRL,
2003 PMU_POW_ON|PMU_POW_BACKLIGHT|PMU_POW_CHARGER|PMU_POW_IRLED|PMU_POW_MEDIABAY);
2004 pmu_wait_complete(&req);
2006 pmac_wakeup_devices();
2012 powerbook_sleep_Core99(void)
2014 unsigned long save_l2cr;
2015 unsigned long save_l3cr;
2016 struct adb_request req;
2019 if (pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) < 0) {
2020 printk(KERN_ERR "Sleep mode not supported on this machine\n");
2024 if (num_online_cpus() > 1 || cpu_is_offline(0))
2027 ret = pmac_suspend_devices();
2029 printk(KERN_ERR "Sleep rejected by devices\n");
2033 /* Stop environment and ADB interrupts */
2034 pmu_request(&req, NULL, 2, PMU_SET_INTR_MASK, 0);
2035 pmu_wait_complete(&req);
2037 /* Tell PMU what events will wake us up */
2038 pmu_request(&req, NULL, 4, PMU_POWER_EVENTS, PMU_PWR_CLR_WAKEUP_EVENTS,
2040 pmu_wait_complete(&req);
2041 pmu_request(&req, NULL, 4, PMU_POWER_EVENTS, PMU_PWR_SET_WAKEUP_EVENTS,
2042 0, PMU_PWR_WAKEUP_KEY |
2043 (option_lid_wakeup ? PMU_PWR_WAKEUP_LID_OPEN : 0));
2044 pmu_wait_complete(&req);
2046 /* Save the state of the L2 and L3 caches */
2047 save_l3cr = _get_L3CR(); /* (returns -1 if not available) */
2048 save_l2cr = _get_L2CR(); /* (returns -1 if not available) */
2050 if (!__fake_sleep) {
2051 /* Ask the PMU to put us to sleep */
2052 pmu_request(&req, NULL, 5, PMU_SLEEP, 'M', 'A', 'T', 'T');
2053 pmu_wait_complete(&req);
2056 /* The VIA is supposed not to be restored correctly*/
2059 /* Shut down various ASICs. There's a chance that we can no longer
2060 * talk to the PMU after this, so I moved it to _after_ sending the
2061 * sleep command to it. Still need to be checked.
2063 pmac_call_feature(PMAC_FTR_SLEEP_STATE, NULL, 0, 1);
2065 /* Call low-level ASM sleep handler */
2069 low_sleep_handler();
2071 /* Restore Apple core ASICs state */
2072 pmac_call_feature(PMAC_FTR_SLEEP_STATE, NULL, 0, 0);
2075 restore_via_state();
2077 /* tweak LPJ before cpufreq is there */
2078 loops_per_jiffy *= 2;
2081 pmac_call_early_video_resume();
2083 /* Restore L2 cache */
2084 if (save_l2cr != 0xffffffff && (save_l2cr & L2CR_L2E) != 0)
2085 _set_L2CR(save_l2cr);
2086 /* Restore L3 cache */
2087 if (save_l3cr != 0xffffffff && (save_l3cr & L3CR_L3E) != 0)
2088 _set_L3CR(save_l3cr);
2090 /* Restore userland MMU context */
2091 set_context(current->active_mm->context.id, current->active_mm->pgd);
2093 /* Tell PMU we are ready */
2095 pmu_request(&req, NULL, 2, PMU_SYSTEM_READY, 2);
2096 pmu_wait_complete(&req);
2097 pmu_request(&req, NULL, 2, PMU_SET_INTR_MASK, pmu_intr_mask);
2098 pmu_wait_complete(&req);
2100 /* Restore LPJ, cpufreq will adjust the cpu frequency */
2101 loops_per_jiffy /= 2;
2103 pmac_wakeup_devices();
2108 #define PB3400_MEM_CTRL 0xf8000000
2109 #define PB3400_MEM_CTRL_SLEEP 0x70
2111 static void __iomem *pb3400_mem_ctrl;
2113 static void powerbook_sleep_init_3400(void)
2115 /* map in the memory controller registers */
2116 pb3400_mem_ctrl = ioremap(PB3400_MEM_CTRL, 0x100);
2117 if (pb3400_mem_ctrl == NULL)
2118 printk(KERN_WARNING "ioremap failed: sleep won't be possible");
2121 static int powerbook_sleep_3400(void)
2126 struct adb_request sleep_req;
2127 unsigned int __iomem *mem_ctrl_sleep;
2129 if (pb3400_mem_ctrl == NULL)
2131 mem_ctrl_sleep = pb3400_mem_ctrl + PB3400_MEM_CTRL_SLEEP;
2133 ret = pmac_suspend_devices();
2135 printk(KERN_ERR "Sleep rejected by devices\n");
2139 /* Set the memory controller to keep the memory refreshed
2140 while we're asleep */
2141 for (i = 0x403f; i >= 0x4000; --i) {
2142 out_be32(mem_ctrl_sleep, i);
2144 x = (in_be32(mem_ctrl_sleep) >> 16) & 0x3ff;
2150 /* Ask the PMU to put us to sleep */
2151 pmu_request(&sleep_req, NULL, 5, PMU_SLEEP, 'M', 'A', 'T', 'T');
2152 pmu_wait_complete(&sleep_req);
2155 pmac_call_feature(PMAC_FTR_SLEEP_STATE, NULL, 0, 1);
2159 /* Put the CPU into sleep mode */
2160 hid0 = mfspr(SPRN_HID0);
2161 hid0 = (hid0 & ~(HID0_NAP | HID0_DOZE)) | HID0_SLEEP;
2162 mtspr(SPRN_HID0, hid0);
2164 msr = mfmsr() | MSR_POW;
2170 local_irq_disable();
2172 /* OK, we're awake again, start restoring things */
2173 out_be32(mem_ctrl_sleep, 0x3f);
2174 pmac_call_feature(PMAC_FTR_SLEEP_STATE, NULL, 0, 0);
2176 pmac_wakeup_devices();
2181 #endif /* CONFIG_PM_SLEEP && CONFIG_PPC32 */
2184 * Support for /dev/pmu device
2186 #define RB_SIZE 0x10
2187 struct pmu_private {
2188 struct list_head list;
2193 unsigned char data[16];
2195 wait_queue_head_t wait;
2197 #if defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT)
2198 int backlight_locker;
2202 static LIST_HEAD(all_pmu_pvt);
2203 static DEFINE_SPINLOCK(all_pvt_lock);
2206 pmu_pass_intr(unsigned char *data, int len)
2208 struct pmu_private *pp;
2209 struct list_head *list;
2211 unsigned long flags;
2213 if (len > sizeof(pp->rb_buf[0].data))
2214 len = sizeof(pp->rb_buf[0].data);
2215 spin_lock_irqsave(&all_pvt_lock, flags);
2216 for (list = &all_pmu_pvt; (list = list->next) != &all_pmu_pvt; ) {
2217 pp = list_entry(list, struct pmu_private, list);
2218 spin_lock(&pp->lock);
2222 if (i != pp->rb_get) {
2223 struct rb_entry *rp = &pp->rb_buf[pp->rb_put];
2225 memcpy(rp->data, data, len);
2227 wake_up_interruptible(&pp->wait);
2229 spin_unlock(&pp->lock);
2231 spin_unlock_irqrestore(&all_pvt_lock, flags);
2235 pmu_open(struct inode *inode, struct file *file)
2237 struct pmu_private *pp;
2238 unsigned long flags;
2240 pp = kmalloc(sizeof(struct pmu_private), GFP_KERNEL);
2243 pp->rb_get = pp->rb_put = 0;
2244 spin_lock_init(&pp->lock);
2245 init_waitqueue_head(&pp->wait);
2246 spin_lock_irqsave(&all_pvt_lock, flags);
2247 #if defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT)
2248 pp->backlight_locker = 0;
2250 list_add(&pp->list, &all_pmu_pvt);
2251 spin_unlock_irqrestore(&all_pvt_lock, flags);
2252 file->private_data = pp;
2257 pmu_read(struct file *file, char __user *buf,
2258 size_t count, loff_t *ppos)
2260 struct pmu_private *pp = file->private_data;
2261 DECLARE_WAITQUEUE(wait, current);
2262 unsigned long flags;
2265 if (count < 1 || pp == 0)
2267 if (!access_ok(VERIFY_WRITE, buf, count))
2270 spin_lock_irqsave(&pp->lock, flags);
2271 add_wait_queue(&pp->wait, &wait);
2272 current->state = TASK_INTERRUPTIBLE;
2276 if (pp->rb_get != pp->rb_put) {
2278 struct rb_entry *rp = &pp->rb_buf[i];
2280 spin_unlock_irqrestore(&pp->lock, flags);
2283 if (ret > 0 && copy_to_user(buf, rp->data, ret))
2287 spin_lock_irqsave(&pp->lock, flags);
2292 if (file->f_flags & O_NONBLOCK)
2295 if (signal_pending(current))
2297 spin_unlock_irqrestore(&pp->lock, flags);
2299 spin_lock_irqsave(&pp->lock, flags);
2301 current->state = TASK_RUNNING;
2302 remove_wait_queue(&pp->wait, &wait);
2303 spin_unlock_irqrestore(&pp->lock, flags);
2309 pmu_write(struct file *file, const char __user *buf,
2310 size_t count, loff_t *ppos)
2316 pmu_fpoll(struct file *filp, poll_table *wait)
2318 struct pmu_private *pp = filp->private_data;
2319 unsigned int mask = 0;
2320 unsigned long flags;
2324 poll_wait(filp, &pp->wait, wait);
2325 spin_lock_irqsave(&pp->lock, flags);
2326 if (pp->rb_get != pp->rb_put)
2328 spin_unlock_irqrestore(&pp->lock, flags);
2333 pmu_release(struct inode *inode, struct file *file)
2335 struct pmu_private *pp = file->private_data;
2336 unsigned long flags;
2339 file->private_data = NULL;
2340 spin_lock_irqsave(&all_pvt_lock, flags);
2341 list_del(&pp->list);
2342 spin_unlock_irqrestore(&all_pvt_lock, flags);
2344 #if defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT)
2345 if (pp->backlight_locker)
2346 pmac_backlight_enable();
2355 pmu_ioctl(struct inode * inode, struct file *filp,
2356 u_int cmd, u_long arg)
2358 __u32 __user *argp = (__u32 __user *)arg;
2359 int error = -EINVAL;
2362 #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_PPC32)
2364 if (!capable(CAP_SYS_ADMIN))
2366 if (sleep_in_progress)
2368 sleep_in_progress = 1;
2370 case PMU_OHARE_BASED:
2371 error = powerbook_sleep_3400();
2373 case PMU_HEATHROW_BASED:
2374 case PMU_PADDINGTON_BASED:
2375 error = powerbook_sleep_grackle();
2377 case PMU_KEYLARGO_BASED:
2378 error = powerbook_sleep_Core99();
2383 sleep_in_progress = 0;
2385 case PMU_IOC_CAN_SLEEP:
2386 if (pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) < 0)
2387 return put_user(0, argp);
2389 return put_user(1, argp);
2390 #endif /* CONFIG_PM_SLEEP && CONFIG_PPC32 */
2392 #ifdef CONFIG_PMAC_BACKLIGHT_LEGACY
2393 /* Compatibility ioctl's for backlight */
2394 case PMU_IOC_GET_BACKLIGHT:
2398 if (sleep_in_progress)
2401 brightness = pmac_backlight_get_legacy_brightness();
2405 return put_user(brightness, argp);
2408 case PMU_IOC_SET_BACKLIGHT:
2412 if (sleep_in_progress)
2415 error = get_user(brightness, argp);
2419 return pmac_backlight_set_legacy_brightness(brightness);
2421 #ifdef CONFIG_INPUT_ADBHID
2422 case PMU_IOC_GRAB_BACKLIGHT: {
2423 struct pmu_private *pp = filp->private_data;
2425 if (pp->backlight_locker)
2428 pp->backlight_locker = 1;
2429 pmac_backlight_disable();
2433 #endif /* CONFIG_INPUT_ADBHID */
2434 #endif /* CONFIG_PMAC_BACKLIGHT_LEGACY */
2436 case PMU_IOC_GET_MODEL:
2437 return put_user(pmu_kind, argp);
2438 case PMU_IOC_HAS_ADB:
2439 return put_user(pmu_has_adb, argp);
2444 static const struct file_operations pmu_device_fops = {
2450 .release = pmu_release,
2453 static struct miscdevice pmu_device = {
2454 PMU_MINOR, "pmu", &pmu_device_fops
2457 static int pmu_device_init(void)
2461 if (misc_register(&pmu_device) < 0)
2462 printk(KERN_ERR "via-pmu: cannot register misc device.\n");
2465 device_initcall(pmu_device_init);
2470 polled_handshake(volatile unsigned char __iomem *via)
2472 via[B] &= ~TREQ; eieio();
2473 while ((via[B] & TACK) != 0)
2475 via[B] |= TREQ; eieio();
2476 while ((via[B] & TACK) == 0)
2481 polled_send_byte(volatile unsigned char __iomem *via, int x)
2483 via[ACR] |= SR_OUT | SR_EXT; eieio();
2484 via[SR] = x; eieio();
2485 polled_handshake(via);
2489 polled_recv_byte(volatile unsigned char __iomem *via)
2493 via[ACR] = (via[ACR] & ~SR_OUT) | SR_EXT; eieio();
2494 x = via[SR]; eieio();
2495 polled_handshake(via);
2496 x = via[SR]; eieio();
2501 pmu_polled_request(struct adb_request *req)
2503 unsigned long flags;
2505 volatile unsigned char __iomem *v = via;
2509 l = pmu_data_len[c][0];
2510 if (l >= 0 && req->nbytes != l + 1)
2513 local_irq_save(flags);
2514 while (pmu_state != idle)
2517 while ((via[B] & TACK) == 0)
2519 polled_send_byte(v, c);
2521 l = req->nbytes - 1;
2522 polled_send_byte(v, l);
2524 for (i = 1; i <= l; ++i)
2525 polled_send_byte(v, req->data[i]);
2527 l = pmu_data_len[c][1];
2529 l = polled_recv_byte(v);
2530 for (i = 0; i < l; ++i)
2531 req->reply[i + req->reply_len] = polled_recv_byte(v);
2536 local_irq_restore(flags);
2539 #endif /* DEBUG_SLEEP */
2542 /* FIXME: This is a temporary set of callbacks to enable us
2543 * to do suspend-to-disk.
2546 #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_PPC32)
2548 int pmu_sys_suspended;
2550 static int pmu_sys_suspend(struct sys_device *sysdev, pm_message_t state)
2552 if (state.event != PM_EVENT_SUSPEND || pmu_sys_suspended)
2555 /* Suspend PMU event interrupts */
2558 pmu_sys_suspended = 1;
2562 static int pmu_sys_resume(struct sys_device *sysdev)
2564 struct adb_request req;
2566 if (!pmu_sys_suspended)
2569 /* Tell PMU we are ready */
2570 pmu_request(&req, NULL, 2, PMU_SYSTEM_READY, 2);
2571 pmu_wait_complete(&req);
2573 /* Resume PMU event interrupts */
2576 pmu_sys_suspended = 0;
2581 #endif /* CONFIG_PM_SLEEP && CONFIG_PPC32 */
2583 static struct sysdev_class pmu_sysclass = {
2584 set_kset_name("pmu"),
2587 static struct sys_device device_pmu = {
2588 .cls = &pmu_sysclass,
2591 static struct sysdev_driver driver_pmu = {
2592 #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_PPC32)
2593 .suspend = &pmu_sys_suspend,
2594 .resume = &pmu_sys_resume,
2595 #endif /* CONFIG_PM_SLEEP && CONFIG_PPC32 */
2598 static int __init init_pmu_sysfs(void)
2602 rc = sysdev_class_register(&pmu_sysclass);
2604 printk(KERN_ERR "Failed registering PMU sys class\n");
2607 rc = sysdev_register(&device_pmu);
2609 printk(KERN_ERR "Failed registering PMU sys device\n");
2612 rc = sysdev_driver_register(&pmu_sysclass, &driver_pmu);
2614 printk(KERN_ERR "Failed registering PMU sys driver\n");
2620 subsys_initcall(init_pmu_sysfs);
2622 EXPORT_SYMBOL(pmu_request);
2623 EXPORT_SYMBOL(pmu_queue_request);
2624 EXPORT_SYMBOL(pmu_poll);
2625 EXPORT_SYMBOL(pmu_poll_adb);
2626 EXPORT_SYMBOL(pmu_wait_complete);
2627 EXPORT_SYMBOL(pmu_suspend);
2628 EXPORT_SYMBOL(pmu_resume);
2629 EXPORT_SYMBOL(pmu_unlock);
2630 #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_PPC32)
2631 EXPORT_SYMBOL(pmu_enable_irled);
2632 EXPORT_SYMBOL(pmu_battery_count);
2633 EXPORT_SYMBOL(pmu_batteries);
2634 EXPORT_SYMBOL(pmu_power_flags);
2635 #endif /* CONFIG_PM_SLEEP && CONFIG_PPC32 */