From: 黄涛 Date: Wed, 1 Feb 2012 11:41:34 +0000 (+0800) Subject: rk: move usb_detect.c from mach-rk29 to plat-rk X-Git-Tag: firefly_0821_release~9595^2~195 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=c9b0d6e85cbed884db965e47014c8aef85c15b56;p=firefly-linux-kernel-4.4.55.git rk: move usb_detect.c from mach-rk29 to plat-rk --- diff --git a/arch/arm/mach-rk29/Makefile b/arch/arm/mach-rk29/Makefile index 65898f2e3bcd..088080d55947 100644 --- a/arch/arm/mach-rk29/Makefile +++ b/arch/arm/mach-rk29/Makefile @@ -4,7 +4,6 @@ obj-y += early_printk.o ifndef CONFIG_DEBUG_LL obj-y += ../kernel/debug.o endif -obj-$(CONFIG_USB_GADGET) += usb_detect.o obj-$(CONFIG_PM) += pm.o obj-$(CONFIG_CPU_FREQ) += cpufreq.o obj-$(CONFIG_DDR_FREQ) += ddrfreq.o diff --git a/arch/arm/mach-rk29/usb_detect.c b/arch/arm/mach-rk29/usb_detect.c deleted file mode 100644 index a71a60c8a823..000000000000 --- a/arch/arm/mach-rk29/usb_detect.c +++ /dev/null @@ -1,74 +0,0 @@ -#include -#include -#include -#include -#include - -static irqreturn_t usb_detect_irq_handler(int irq, void *dev_id); -static int detect_gpio = INVALID_GPIO; - -static void usb_detect_do_wakeup(struct work_struct *work) -{ - int ret; - int irq = gpio_to_irq(detect_gpio); - unsigned long flags; - - rk28_send_wakeup_key(); - free_irq(irq, NULL); - flags = gpio_get_value(detect_gpio) ? IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING; - ret = request_irq(irq, usb_detect_irq_handler, flags, "usb_detect", NULL); - if (ret < 0) { - pr_err("%s: request_irq(%d) failed\n", __func__, irq); - } -} - -static DECLARE_DELAYED_WORK(wakeup_work, usb_detect_do_wakeup); -static bool wakelock_inited; -static struct wake_lock usb_wakelock; - -static irqreturn_t usb_detect_irq_handler(int irq, void *dev_id) -{ - wake_lock_timeout(&usb_wakelock, 10 * HZ); - schedule_delayed_work(&wakeup_work, HZ / 10); - return IRQ_HANDLED; -} - -int board_usb_detect_init(unsigned gpio) -{ - int ret; - int irq = gpio_to_irq(gpio); - unsigned long flags; - - if (detect_gpio != INVALID_GPIO) { - pr_err("only support call %s once\n", __func__); - return -EINVAL; - } - - ret = gpio_request(gpio, "usb_detect"); - if (ret < 0) { - pr_err("%s: gpio_request(%d) failed\n", __func__, gpio); - return ret; - } - - if (!wakelock_inited) { - wake_lock_init(&usb_wakelock, WAKE_LOCK_SUSPEND, "usb_detect"); - wakelock_inited = true; - } - - gpio_direction_input(gpio); - - detect_gpio = gpio; - - flags = gpio_get_value(gpio) ? IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING; - ret = request_irq(irq, usb_detect_irq_handler, flags, "usb_detect", NULL); - if (ret < 0) { - pr_err("%s: request_irq(%d) failed\n", __func__, irq); - gpio_free(gpio); - detect_gpio = INVALID_GPIO; - return ret; - } - enable_irq_wake(irq); - - return 0; -} - diff --git a/arch/arm/plat-rk/Makefile b/arch/arm/plat-rk/Makefile index fd1f267c0c89..4df221a38c8e 100644 --- a/arch/arm/plat-rk/Makefile +++ b/arch/arm/plat-rk/Makefile @@ -1 +1,2 @@ obj-$(CONFIG_RK29_LAST_LOG) += last_log.o +obj-$(CONFIG_USB_GADGET) += usb_detect.o diff --git a/arch/arm/plat-rk/usb_detect.c b/arch/arm/plat-rk/usb_detect.c new file mode 100644 index 000000000000..a71a60c8a823 --- /dev/null +++ b/arch/arm/plat-rk/usb_detect.c @@ -0,0 +1,74 @@ +#include +#include +#include +#include +#include + +static irqreturn_t usb_detect_irq_handler(int irq, void *dev_id); +static int detect_gpio = INVALID_GPIO; + +static void usb_detect_do_wakeup(struct work_struct *work) +{ + int ret; + int irq = gpio_to_irq(detect_gpio); + unsigned long flags; + + rk28_send_wakeup_key(); + free_irq(irq, NULL); + flags = gpio_get_value(detect_gpio) ? IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING; + ret = request_irq(irq, usb_detect_irq_handler, flags, "usb_detect", NULL); + if (ret < 0) { + pr_err("%s: request_irq(%d) failed\n", __func__, irq); + } +} + +static DECLARE_DELAYED_WORK(wakeup_work, usb_detect_do_wakeup); +static bool wakelock_inited; +static struct wake_lock usb_wakelock; + +static irqreturn_t usb_detect_irq_handler(int irq, void *dev_id) +{ + wake_lock_timeout(&usb_wakelock, 10 * HZ); + schedule_delayed_work(&wakeup_work, HZ / 10); + return IRQ_HANDLED; +} + +int board_usb_detect_init(unsigned gpio) +{ + int ret; + int irq = gpio_to_irq(gpio); + unsigned long flags; + + if (detect_gpio != INVALID_GPIO) { + pr_err("only support call %s once\n", __func__); + return -EINVAL; + } + + ret = gpio_request(gpio, "usb_detect"); + if (ret < 0) { + pr_err("%s: gpio_request(%d) failed\n", __func__, gpio); + return ret; + } + + if (!wakelock_inited) { + wake_lock_init(&usb_wakelock, WAKE_LOCK_SUSPEND, "usb_detect"); + wakelock_inited = true; + } + + gpio_direction_input(gpio); + + detect_gpio = gpio; + + flags = gpio_get_value(gpio) ? IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING; + ret = request_irq(irq, usb_detect_irq_handler, flags, "usb_detect", NULL); + if (ret < 0) { + pr_err("%s: request_irq(%d) failed\n", __func__, irq); + gpio_free(gpio); + detect_gpio = INVALID_GPIO; + return ret; + } + enable_irq_wake(irq); + + return 0; +} +