diff options
author | Peter Chen <peter.chen@freescale.com> | 2013-08-14 05:44:11 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-08-14 15:37:20 -0400 |
commit | a107f8c505cd8606ae192d24c70b380e980fbe67 (patch) | |
tree | c1451c9051588fe93537c83c034d62def233ed8f /drivers/usb/chipidea/otg.c | |
parent | cbec6bd55a45fa88218ec5ea5ae91f9b96d158d0 (diff) |
usb: chipidea: add vbus interrupt handler
We add vbus interrupt handler at ci_otg_work, it uses OTGSC_BSV(at otgsc)
to know it is connect or disconnet event.
Meanwhile, we introduce two flags id_event and b_sess_valid_event to
indicate it is an id interrupt or a vbus interrupt.
Tested-by: Marek Vasut <marex@denx.de>
Signed-off-by: Peter Chen <peter.chen@freescale.com>
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb/chipidea/otg.c')
-rw-r--r-- | drivers/usb/chipidea/otg.c | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/drivers/usb/chipidea/otg.c b/drivers/usb/chipidea/otg.c index 3b66cbe58d52..7f37484ca362 100644 --- a/drivers/usb/chipidea/otg.c +++ b/drivers/usb/chipidea/otg.c | |||
@@ -37,13 +37,23 @@ enum ci_role ci_otg_role(struct ci_hdrc *ci) | |||
37 | return role; | 37 | return role; |
38 | } | 38 | } |
39 | 39 | ||
40 | /** | 40 | void ci_handle_vbus_change(struct ci_hdrc *ci) |
41 | * ci_role_work - perform role changing based on ID pin | 41 | { |
42 | * @work: work struct | 42 | u32 otgsc; |
43 | */ | 43 | |
44 | static void ci_role_work(struct work_struct *work) | 44 | if (!ci->is_otg) |
45 | return; | ||
46 | |||
47 | otgsc = hw_read(ci, OP_OTGSC, ~0); | ||
48 | |||
49 | if (otgsc & OTGSC_BSV) | ||
50 | usb_gadget_vbus_connect(&ci->gadget); | ||
51 | else | ||
52 | usb_gadget_vbus_disconnect(&ci->gadget); | ||
53 | } | ||
54 | |||
55 | static void ci_handle_id_switch(struct ci_hdrc *ci) | ||
45 | { | 56 | { |
46 | struct ci_hdrc *ci = container_of(work, struct ci_hdrc, work); | ||
47 | enum ci_role role = ci_otg_role(ci); | 57 | enum ci_role role = ci_otg_role(ci); |
48 | 58 | ||
49 | if (role != ci->role) { | 59 | if (role != ci->role) { |
@@ -53,17 +63,35 @@ static void ci_role_work(struct work_struct *work) | |||
53 | ci_role_stop(ci); | 63 | ci_role_stop(ci); |
54 | ci_role_start(ci, role); | 64 | ci_role_start(ci, role); |
55 | } | 65 | } |
66 | } | ||
67 | /** | ||
68 | * ci_otg_work - perform otg (vbus/id) event handle | ||
69 | * @work: work struct | ||
70 | */ | ||
71 | static void ci_otg_work(struct work_struct *work) | ||
72 | { | ||
73 | struct ci_hdrc *ci = container_of(work, struct ci_hdrc, work); | ||
74 | |||
75 | if (ci->id_event) { | ||
76 | ci->id_event = false; | ||
77 | ci_handle_id_switch(ci); | ||
78 | } else if (ci->b_sess_valid_event) { | ||
79 | ci->b_sess_valid_event = false; | ||
80 | ci_handle_vbus_change(ci); | ||
81 | } else | ||
82 | dev_err(ci->dev, "unexpected event occurs at %s\n", __func__); | ||
56 | 83 | ||
57 | enable_irq(ci->irq); | 84 | enable_irq(ci->irq); |
58 | } | 85 | } |
59 | 86 | ||
87 | |||
60 | /** | 88 | /** |
61 | * ci_hdrc_otg_init - initialize otg struct | 89 | * ci_hdrc_otg_init - initialize otg struct |
62 | * ci: the controller | 90 | * ci: the controller |
63 | */ | 91 | */ |
64 | int ci_hdrc_otg_init(struct ci_hdrc *ci) | 92 | int ci_hdrc_otg_init(struct ci_hdrc *ci) |
65 | { | 93 | { |
66 | INIT_WORK(&ci->work, ci_role_work); | 94 | INIT_WORK(&ci->work, ci_otg_work); |
67 | ci->wq = create_singlethread_workqueue("ci_otg"); | 95 | ci->wq = create_singlethread_workqueue("ci_otg"); |
68 | if (!ci->wq) { | 96 | if (!ci->wq) { |
69 | dev_err(ci->dev, "can't create workqueue\n"); | 97 | dev_err(ci->dev, "can't create workqueue\n"); |