hh.org updates
[hh.org.git] / arch / arm / mach-pxa / htcapache / htcapache-power.c
blob01ba5838753e0469b052efd5dc31c7a96825c364
1 /*
2 * Support for power detection code on the HTC Apache phone.
4 * (c) Copyright 2006 Kevin O'Connor <kevin@koconnor.net>
6 * This file may be distributed under the terms of the GNU GPL license.
7 */
9 #include <linux/kernel.h>
10 #include <linux/interrupt.h> // request_irq
12 #include <asm/arch/htcapache-gpio.h>
15 /****************************************************************
16 * Plug in/out events
17 ****************************************************************/
19 // Interrupt handler called when plugging/unplugging mini-usb port
20 static irqreturn_t
21 power_isr(int irq, void *dev_id, struct pt_regs *regs)
23 int haspower = !htcapache_egpio_isset(EGPIO_NR_HTCAPACHE_PWR_IN_PWR);
24 int hashigh = !htcapache_egpio_isset(EGPIO_NR_HTCAPACHE_PWR_IN_HIGHPWR);
25 if (haspower && !hashigh) {
26 // USB plug - activate usb transceiver.
27 htcapache_egpio_set(EGPIO_NR_HTCAPACHE_USB_PWR);
28 } else {
29 htcapache_egpio_clear(EGPIO_NR_HTCAPACHE_USB_PWR);
31 printk("USB mini plug event (pwr=%d ac=%d)\n"
32 , haspower, hashigh);
33 return IRQ_HANDLED;
37 /****************************************************************
38 * Setup
39 ****************************************************************/
41 void
42 htcapache_power_init(void)
44 int result;
46 // Setup plug interrupt
47 result = request_irq(IRQ_EGPIO(EGPIO_NR_HTCAPACHE_PWR_IN_PWR)
48 , power_isr, SA_SAMPLE_RANDOM,
49 "usb_plug", NULL);
50 if (result)
51 printk("unable to claim irq %d for usb plug event. Got %d\n"
52 , IRQ_EGPIO(EGPIO_NR_HTCAPACHE_PWR_IN_PWR), result);
54 // Run the interrupt handler to initialize.
55 power_isr(0, NULL, NULL);