return -ENODEV;
}
+/* Precondition: USB_FUNCTION_NONE */
static int usb_change_gadget(unsigned mode)
{
int ret;
return ret;
out:
- /* TODO. Maybe some default action here? */
+ /* Although this function has a USB_FUNCTION_NONE precondition, it is to protect against coding mistakes. */
(void)usb_state_set_current_mode(USB_FUNCTION_NONE); /* because usb does not work properly */
return ret;
}
(void)usb_state_set_current_mode(mode);
change_usb_state_notification_handler(mode);
- if (disp_plgn.pm_lock_internal)
- disp_plgn.pm_lock_internal(INTERNAL_LOCK_USB, LCD_OFF, STAY_CUR_STATE, 0);
-
return 0;
out:
+ /* Although this function has a USB_FUNCTION_NONE precondition, it is to protect against coding mistakes. */
(void)usb_state_set_current_mode(USB_FUNCTION_NONE); /* because usb does not work properly */
return ret;
}
else
; /* Do nothing: A send_usb_state_changed_event(VCONFKEY_SYSMAN_USB_DISCONNECTED) has already called by caller */
- (void)usb_state_set_current_mode(USB_FUNCTION_NONE); /* run unconditionally */
+ (void)usb_state_set_current_mode(USB_FUNCTION_NONE);
change_usb_state_notification_handler(USB_FUNCTION_NONE);
ret = usb_config_disable();
- if (ret != 0) {
+ if (ret < 0) {
_E("Failed to disable usb config: %d", ret);
- /* Important: You have to keep going to unlock disp_plgn.pm_unlock_internal */
+ return ret;
}
- if (disp_plgn.pm_unlock_internal)
- disp_plgn.pm_unlock_internal(INTERNAL_LOCK_USB, LCD_OFF, STAY_CUR_STATE);
-
- return ret;
+ return 0;
}
/* Precondition: USB_DISCONNECTED (Implicitly contains USB_FUNCTION_NONE) */
int ret;
unsigned int mode = usb_state_get_selected_mode();
+ if (disp_plgn.pm_lock_internal)
+ disp_plgn.pm_lock_internal(INTERNAL_LOCK_USB, LCD_OFF, STAY_CUR_STATE, 0);
+
usb_state_set_connection(USB_CONNECTED);
send_usb_state_changed_event(VCONFKEY_SYSMAN_USB_CONNECTED);
ret = usb_enable(mode);
if (ret < 0) {
- _E("Failed to enable usb gadget(%d): %d", mode, ret);
+ _E("Failed to enable usb gadget(0x%x): %d", mode, ret);
return ret;
}
/* Precondition: USB_CONNECTED */
static int usb_disconnected(void)
{
+ int ret;
+
usb_state_set_connection(USB_DISCONNECTED);
send_usb_state_changed_event(VCONFKEY_SYSMAN_USB_DISCONNECTED);
- return usb_disable();
+ ret = usb_disable();
+ if(ret < 0) {
+ _E("Failed to disable usb gadget: %d", ret);
+ /* Important: You have to keep going to unlock disp_plgn.pm_unlock_internal */
+ }
+
+ if (disp_plgn.pm_unlock_internal)
+ disp_plgn.pm_unlock_internal(INTERNAL_LOCK_USB, LCD_OFF, STAY_CUR_STATE);
+
+ return ret;
}
/* Called by dbus signal and vconf change(tethering, debug mode) */
/*
* You should always change the gadget once when the usb mode is changed.
- * In this state, usb_enable() is called when the usb cable is connected.
- * A usb_enable() is called when the usb cable is disconnected.
+ * In this state, usb_enable() is called when the usb cable is connected
+ * and usb_disable() is called when the usb cable is disconnected.
*/
ret = usb_change_gadget(new_mode);
if (ret < 0) {