usb: otg: tegra: Notify USB events to otg core
Rakesh Bodla [Fri, 24 Aug 2012 12:43:55 +0000 (17:43 +0530)]
Notify USB connection events to otg core. These
notifications will be used by drivers (e.g. otg wakelock
driver) who registered for the events.

Bug 1031034
Bug 976849

Change-Id: I3655071af9226e3aef385681fcabc94b9def4233
Signed-off-by: Rakesh Bodla <rbodla@nvidia.com>
Reviewed-on: http://git-master/r/127137
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Alex Courbot <acourbot@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: Venkat Moganty <vmoganty@nvidia.com>

drivers/usb/otg/tegra-otg.c

index 9d614cb..22e303e 100644 (file)
@@ -182,6 +182,12 @@ static void tegra_stop_host(struct tegra_otg_data *tegra)
        DBG("%s(%d) End\n", __func__, __LINE__);
 }
 
+static void tegra_otg_notify_event(struct otg_transceiver *otg,
+                                       enum usb_xceiv_events event)
+{
+       otg->last_event = event;
+       atomic_notifier_call_chain(&otg->notifier, event, NULL);
+}
 
 static void tegra_change_otg_state(struct tegra_otg_data *tegra,
                                enum usb_otg_state to)
@@ -203,16 +209,24 @@ static void tegra_change_otg_state(struct tegra_otg_data *tegra,
                                              tegra_state_name(to));
 
                if (from == OTG_STATE_A_SUSPEND) {
-                       if (to == OTG_STATE_B_PERIPHERAL && otg->gadget)
+                       if (to == OTG_STATE_B_PERIPHERAL && otg->gadget) {
                                usb_gadget_vbus_connect(otg->gadget);
-                       else if (to == OTG_STATE_A_HOST)
+                               tegra_otg_notify_event(otg, USB_EVENT_VBUS);
+                       }
+                       else if (to == OTG_STATE_A_HOST) {
                                tegra_start_host(tegra);
+                               tegra_otg_notify_event(otg, USB_EVENT_ID);
+                       }
                } else if (from == OTG_STATE_A_HOST) {
-                       if (to == OTG_STATE_A_SUSPEND)
+                       if (to == OTG_STATE_A_SUSPEND) {
                                tegra_stop_host(tegra);
+                               tegra_otg_notify_event(otg, USB_EVENT_NONE);
+                       }
                } else if (from == OTG_STATE_B_PERIPHERAL && otg->gadget) {
-                       if (to == OTG_STATE_A_SUSPEND)
+                       if (to == OTG_STATE_A_SUSPEND) {
                                usb_gadget_vbus_disconnect(otg->gadget);
+                               tegra_otg_notify_event(otg, USB_EVENT_NONE);
+                       }
                }
        }
 }