static irqreturn_t usb_detect_handler(int irq, void *dev_id)
{
	struct gadget_wrapper *d;
	int value = 0;

#ifndef DWC_DEVICE_ONLY
	/*
	 *if otg cable is connected , id state =0
	 *as host turn on vbus, in this case shouldn't call this handler
	 */
	if(!usb_get_id_state())
		return IRQ_HANDLED;
#endif
	d = gadget_wrapper;
	if (d->driver == NULL) {
		pr_info("too early, no gadget drive\n");
		return IRQ_HANDLED;
	}

	value = usb_get_vbus_state();
	if (value){
		pr_debug("usb detect plug in\n");
		usb_set_vbus_irq_type(irq, VBUS_PLUG_OUT);
	} else {
		pr_debug("usb detect plug out\n");
		usb_set_vbus_irq_type(irq, VBUS_PLUG_IN);
	}

	d->vbus = value;
	queue_work(d->detect_wq, &d->detect_work);

	return IRQ_HANDLED;
}
Beispiel #2
0
static int pullup(struct usb_gadget *gadget, int is_on)
{
	struct gadget_wrapper *d;
	int action = is_on;

#ifndef DWC_DEVICE_ONLY	
	if(!usb_get_id_state())
		return 0;
#endif
	if (gadget == 0)
		return -ENODEV;
	else
		d = container_of(gadget, struct gadget_wrapper, gadget);
	d->softconnect = is_on;
#ifdef CONFIG_USB_EXTERNAL_DETECT
	if (!d->enabled || !d->vbus)
	{
		printk("usb: %s, d->enable = %d,  d->vbus=%d \r\n",__func__, d->enabled, d->vbus);
		return 0;
	}
	mutex_lock(&udc_lock);
	if (action) {
		__udc_startup();
	} else {
		__udc_shutdown();
	}
	mutex_unlock(&udc_lock);
#else
	if (!d->enabled || !d->vbus)
		action = 0;

	mutex_lock(&udc_lock);
	if (action) {
		queue_delayed_work(d->cable2pc_wq, &d->cable2pc,CABLE_TIMEOUT);
		__udc_startup();
	} else {
		/*
		 *this is soft disconnct, and maybe the timer started
		 *by plugin still work, need cancel this timer like plugout
		 */
		cancel_delayed_work_sync(&d->cable2pc);
		__udc_shutdown();
	}
	mutex_unlock(&udc_lock);
#endif
	return 0;
}
int epmic_event_handler(int level)
{
	struct gadget_wrapper *d;

#ifndef DWC_DEVICE_ONLY
	/*
	 *if otg cable is connected , id state =0
	 *as host turn on vbus, in this case shouldn't call this handler
	 */
	if(!usb_get_id_state())
		return 0;
#endif
	d = gadget_wrapper;
	d->vbus = level;
	queue_work(d->detect_wq, &d->detect_work);
	return 0;
}
static int pullup(struct usb_gadget *gadget, int is_on)
{
	struct gadget_wrapper *d;
	int action = is_on;

#ifndef DWC_DEVICE_ONLY	
	if(!usb_get_id_state())
		return 0;
#endif
	if (gadget == 0)
		return -ENODEV;
	else
		d = container_of(gadget, struct gadget_wrapper, gadget);

#ifdef CONFIG_USB_INTERRUPT_BY_MUIC	// need to check vbus again
	if (!d->enabled)
		action = 0;
#else
	if (!d->enabled || !d->vbus)
		action = 0;
#endif

	mutex_lock(&udc_lock);
	if (action) {
		queue_delayed_work(d->cable2pc_wq, &d->cable2pc,CABLE_TIMEOUT);
		__udc_startup();
	} else {
		/*
		 *this is soft disconnct, and maybe the timer started
		 *by plugin still work, need cancel this timer like plugout
		 */
		cancel_delayed_work_sync(&d->cable2pc);
		__udc_shutdown();
	}
	mutex_unlock(&udc_lock);

	return 0;
}