1 #include <linux/wakelock.h>
2 #include <linux/workqueue.h>
3 #include <linux/interrupt.h>
4 #include <linux/gpio.h>
5 #include <mach/board.h>
7 static irqreturn_t usb_detect_irq_handler(int irq, void *dev_id);
8 static int detect_gpio = INVALID_GPIO;
10 static void usb_detect_do_wakeup(struct work_struct *work)
13 int irq = gpio_to_irq(detect_gpio);
16 rk28_send_wakeup_key();
18 flags = gpio_get_value(detect_gpio) ? IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING;
19 ret = request_irq(irq, usb_detect_irq_handler, flags, "usb_detect", NULL);
21 pr_err("%s: request_irq(%d) failed\n", __func__, irq);
25 static DECLARE_DELAYED_WORK(wakeup_work, usb_detect_do_wakeup);
26 static bool wakelock_inited;
27 static struct wake_lock usb_wakelock;
29 static irqreturn_t usb_detect_irq_handler(int irq, void *dev_id)
31 wake_lock_timeout(&usb_wakelock, 10 * HZ);
32 schedule_delayed_work(&wakeup_work, HZ / 10);
36 int board_usb_detect_init(unsigned gpio)
39 int irq = gpio_to_irq(gpio);
42 if (detect_gpio != INVALID_GPIO) {
43 pr_err("only support call %s once\n", __func__);
47 ret = gpio_request(gpio, "usb_detect");
49 pr_err("%s: gpio_request(%d) failed\n", __func__, gpio);
53 if (!wakelock_inited) {
54 wake_lock_init(&usb_wakelock, WAKE_LOCK_SUSPEND, "usb_detect");
55 wakelock_inited = true;
58 gpio_direction_input(gpio);
62 flags = gpio_get_value(gpio) ? IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING;
63 ret = request_irq(irq, usb_detect_irq_handler, flags, "usb_detect", NULL);
65 pr_err("%s: request_irq(%d) failed\n", __func__, irq);
67 detect_gpio = INVALID_GPIO;