spin_lock_irqsave(&cdev->lock, flags);
/* force reenumeration */
- if (cdev && cdev->gadget &&
- cdev->gadget->speed != USB_SPEED_UNKNOWN) {
- /* avoid sending a disconnect switch event until after we disconnect */
- cdev->mute_switch = 1;
+ if (cdev && cdev->gadget && cdev->gadget->speed != USB_SPEED_UNKNOWN) {
spin_unlock_irqrestore(&cdev->lock, flags);
usb_gadget_disconnect(cdev->gadget);
u16 w_length = le16_to_cpu(ctrl->wLength);
struct usb_function *f = NULL;
u8 endp;
+ unsigned long flags;
+
+ spin_lock_irqsave(&cdev->lock, flags);
+ if (!cdev->connected) {
+ cdev->connected = 1;
+ schedule_work(&cdev->switch_work);
+ }
+ spin_unlock_irqrestore(&cdev->lock, flags);
/* partial re-init of the response message; the function or the
* gadget might need to intercept e.g. a control-OUT completion
if (composite->disconnect)
composite->disconnect(cdev);
- if (cdev->mute_switch)
- cdev->mute_switch = 0;
- else
- schedule_work(&cdev->switch_work);
+ cdev->connected = 0;
+ schedule_work(&cdev->switch_work);
spin_unlock_irqrestore(&cdev->lock, flags);
}
kfree(cdev->req->buf);
usb_ep_free_request(gadget->ep0, cdev->req);
}
- switch_dev_unregister(&cdev->sdev);
+ switch_dev_unregister(&cdev->sw_connected);
+ switch_dev_unregister(&cdev->sw_config);
device_remove_file(&gadget->dev, &dev_attr_suspended);
kfree(cdev);
set_gadget_data(gadget, NULL);
struct usb_composite_dev *cdev =
container_of(data, struct usb_composite_dev, switch_work);
struct usb_configuration *config = cdev->config;
+ int connected;
+ unsigned long flags;
+
+ spin_lock_irqsave(&cdev->lock, flags);
+ if (cdev->connected != cdev->sw_connected.state) {
+ connected = cdev->connected;
+ spin_unlock_irqrestore(&cdev->lock, flags);
+ switch_set_state(&cdev->sw_connected, connected);
+ } else {
+ spin_unlock_irqrestore(&cdev->lock, flags);
+ }
if (config)
- switch_set_state(&cdev->sdev, config->bConfigurationValue);
+ switch_set_state(&cdev->sw_config, config->bConfigurationValue);
else
- switch_set_state(&cdev->sdev, 0);
+ switch_set_state(&cdev->sw_config, 0);
}
static int composite_bind(struct usb_gadget *gadget)
if (status < 0)
goto fail;
- cdev->sdev.name = "usb_configuration";
- status = switch_dev_register(&cdev->sdev);
+ cdev->sw_connected.name = "usb_connected";
+ status = switch_dev_register(&cdev->sw_connected);
+ if (status < 0)
+ goto fail;
+ cdev->sw_config.name = "usb_configuration";
+ status = switch_dev_register(&cdev->sw_config);
if (status < 0)
goto fail;
INIT_WORK(&cdev->switch_work, composite_switch_work);