/*
 * Unregister entry point for the peripheral controller driver.
*/
int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
{
	struct s3c_udc *dev = the_controller;
	unsigned long flags;

	if (!dev)
		return -ENODEV;
	if (!driver || driver != dev->driver)
		return -EINVAL;
	
	disable_irq(IRQ_OTG);

	spin_lock_irqsave(&dev->lock, flags);
	stop_activity(dev, driver);
	spin_unlock_irqrestore(&dev->lock, flags);

	driver->unbind(&dev->gadget);
	device_del(&dev->gadget.dev);

	printk("Unregistered gadget driver '%s'\n", driver->driver.name);

	udc_disable(dev);

	dev->gadget.dev.driver = NULL;
	dev->driver = NULL;
	dev->config_gadget_driver = NO_GADGET_DRIVER;

	return 0;
}
Ejemplo n.º 2
0
int dwc_peripheral_start(void *data, bool enable)
{
	struct gadget_wrapper *d;
	d = gadget_wrapper;

	pr_info("usb: %s d->vbus=%d, enable=%d\n", __func__, d->vbus, enable);

	mutex_lock(&udc_lock);
	d->vbus = enable;
	if ( !d->softconnect )
	{
		printk("usb: %s , d->softconnect is %d / udc don't start now \r\n",__func__, d->softconnect );
		mutex_unlock(&udc_lock);
		return 0;
	}

	if(enable) {
		wake_lock(&usb_wake_lock);
		udc_enable();
		dwc_otg_core_init(GET_CORE_IF(d->pcd));
		dwc_otg_enable_global_interrupts(GET_CORE_IF(d->pcd));
		dwc_otg_core_dev_init(GET_CORE_IF(d->pcd));
		d->udc_startup = 1;
	} else {
		dwc_otg_disable_global_interrupts(GET_CORE_IF(d->pcd));
		dwc_otg_clear_all_int(GET_CORE_IF(d->pcd));
		dwc_otg_pcd_stop(d->pcd);
		udc_disable();
		d->udc_startup = 0;
		wake_unlock(&usb_wake_lock);
	}
	mutex_unlock(&udc_lock);
	return 0;
}
/*
 * power down s3c-udc power & disable otg clock
 */ 
void s3c_udc_power_down(void)
{
	struct s3c_udc *dev = the_controller;
	printk("[%s] \n", __FUNCTION__);

	udc_disable(dev);
	clk_disable(otg_clock);

	//fsa9480_s3c_udc_off();
}
Ejemplo n.º 4
0
/*
 * usbd_pm_callback
 * @dev:
 * @rqst:
 * @unused:
 *
 * Used to signal power management events.
 */
static int bi_pm_event (struct pm_dev *pm_dev, pm_request_t request, void *unused)
{
	struct usb_device_instance *device;

	dbg_pm (0, "request: %d pm_dev: %p data: %p", request, pm_dev, pm_dev->data);

	if (!(device = pm_dev->data)) {
		dbg_pm (0, "DATA NULL, NO DEVICE");
		return 0;
	}

	switch (request) {
#if defined(CONFIG_IRIS)
	case PM_STANDBY:
	case PM_BLANK:
#endif
	case PM_SUSPEND:
		dbg_pm (0, "PM_SUSPEND");
		if (!pm_suspended) {
			pm_suspended = 1;
			dbg_init (1, "MOD_INC_USE_COUNT %d", GET_USE_COUNT (THIS_MODULE));
			udc_disconnect ();	// disable USB pullup if we can
			udc_disable_interrupts (device);	// disable interupts
			udc_disable ();	// disable UDC
			dbg_pm (0, "PM_SUSPEND: finished");
		}
		break;
#if defined(CONFIG_IRIS)
	case PM_UNBLANK:
#endif
	case PM_RESUME:
		dbg_pm (0, "PM_RESUME");
		if (pm_suspended) {
			// probe for device
			if (udc_init ()) {
				dbg_init (0, "udc_init failed");
				//return -EINVAL;
			}
			udc_enable (device);	// enable UDC
			udc_all_interrupts (device);	// enable interrupts
			udc_connect ();	// enable USB pullup if we can
			//udc_set_address(device->address);
			//udc_reset_ep(0);

			pm_suspended = 0;
			dbg_init (1, "MOD_INC_USE_COUNT %d", GET_USE_COUNT (THIS_MODULE));
			dbg_pm (0, "PM_RESUME: finished");
		}
		break;
	}
	return 0;
}
int sprd_charger_is_adapter(struct sprd_battery_data *data)
{
	uint32_t ret;
	volatile uint32_t i;
	unsigned long irq_flag = 0;

	gpio_request(USB_DM_GPIO, "sprd_charge");
	gpio_request(USB_DP_GPIO, "sprd_charge");
	gpio_direction_input(USB_DM_GPIO);
	gpio_direction_input(USB_DP_GPIO);

	udc_enable();
	udc_phy_down();
	local_irq_save(irq_flag);

	sprd_greg_clear_bits(REG_TYPE_AHB_GLOBAL,
			     (USB_DM_PULLDOWN_BIT | USB_DP_PULLDOWN_BIT),
			     USB_PHY_CTRL);

	/* Identify USB charger */
	sprd_greg_set_bits(REG_TYPE_AHB_GLOBAL, USB_DM_PULLUP_BIT,
			   USB_PHY_CTRL);
	mdelay(10);
	ret = gpio_get_value(USB_DM_GPIO);
	sprd_greg_clear_bits(REG_TYPE_AHB_GLOBAL, (USB_DM_PULLUP_BIT),
			     USB_PHY_CTRL);

	/* normal charger */
	if (ret) {
		/* Identify standard adapter */
		sprd_greg_set_bits(REG_TYPE_AHB_GLOBAL, USB_DM_PULLDOWN_BIT,
				   USB_PHY_CTRL);
		for (i = 0; i < 200; i++) {;
		}
		if ((gpio_get_value(USB_DM_GPIO) & BIT(1))
		    && (gpio_get_value(USB_DP_GPIO) & BIT(2))) {
			ret = 1;	/* adapter */
		} else {
			ret = 1;	/* non standard adapter */
		}
		sprd_greg_clear_bits(REG_TYPE_AHB_GLOBAL, (USB_DM_PULLDOWN_BIT),
				     USB_PHY_CTRL);
	}

	local_irq_restore(irq_flag);
	udc_disable();
	gpio_free(USB_DM_GPIO);
	gpio_free(USB_DP_GPIO);
	return ret;
}
static void __udc_shutdown(void)
{
	struct gadget_wrapper *d;

	d = gadget_wrapper;

	pr_info("USB:shutdown udc\n");
	if (d->udc_startup) {
		dwc_otg_pcd_stop(d->pcd);
		udc_disable();
		d->udc_startup = 0;
		wake_unlock(&usb_wake_lock);
	}
}
static void __udc_shutdown(void)
{
	struct gadget_wrapper *d;

	d = gadget_wrapper;

	pr_info("USB:shutdown udc\n");
	if (d->udc_startup) {
		dwc_otg_disable_global_interrupts(GET_CORE_IF(d->pcd));
		dwc_otg_clear_all_int(GET_CORE_IF(d->pcd));
		dwc_otg_pcd_stop(d->pcd);
		udc_disable();
		d->udc_startup = 0;
		wake_unlock(&usb_wake_lock);
	}
}
int sprd_charger_is_adapter(struct sprd_battery_data *data)
{
	uint32_t ret;
	volatile uint32_t i;
	unsigned long irq_flag = 0;

	mdelay(300);

	gpio_request(USB_DM_GPIO, "sprd_charge");
	gpio_request(USB_DP_GPIO, "sprd_charge");
	gpio_direction_input(USB_DM_GPIO);
	gpio_direction_input(USB_DP_GPIO);

	udc_enable();
	udc_phy_down();
	local_irq_save(irq_flag);

	sci_glb_clr(REG_AHB_USB_PHY_CTRL, (BIT_DMPULLDOWN | BIT_DPPULLDOWN));

	/* Identify USB charger */
	sci_glb_set(REG_AHB_USB_PHY_CTRL, BIT_DMPULLUP);
	mdelay(10);
	ret = gpio_get_value(USB_DM_GPIO);
	sci_glb_clr(REG_AHB_USB_PHY_CTRL, (BIT_DMPULLUP));
#if 0
	/* normal charger */
	if (ret) {
		/* Identify standard adapter */
		sci_glb_set(REG_AHB_USB_PHY_CTRL, BIT_DMPULLDOWN);
		for (i = 0; i < 1000; i++) {;
		}
		if (gpio_get_value(USB_DM_GPIO)
		    == gpio_get_value(USB_DP_GPIO)) {
			ret = 1;	/* adapter */
		} else {
			ret = 1;	/* non standard adapter */
		}
		sci_glb_clr(REG_AHB_USB_PHY_CTRL, (BIT_DMPULLDOWN));
	}
#endif
	local_irq_restore(irq_flag);
	udc_disable();
	gpio_free(USB_DM_GPIO);
	gpio_free(USB_DP_GPIO);
	return ret;
}
Ejemplo n.º 9
0
/**
 * bi_udc_exit - Stop using the USB Device Controller
 *
 * Stop using the USB Device Controller.
 *
 * Shutdown and free dma channels, de-register the interrupt handler.
 */
void bi_udc_exit(void)
{
    int i;

    dbg_init(1, "Unloading %s", udc_name());

    for (i = 0; i < udc_max_endpoints(); i++) {
        udc_disable_ep(i);
    }

    // free io and irq
    udc_disconnect();
    udc_disable();
    udc_release_io();
    udc_release_udc_irq();

    if (have_cable_irq) {
        udc_release_cable_irq();
    }
}
Ejemplo n.º 10
0
static int
bi_udc_suspend(struct device *dev, u32 state, u32 level)
{
	struct usb_device_instance *device = device_array[0];

	switch (level) {
	case SUSPEND_POWER_DOWN:
		dbg_pm (0, "SUSPEND_POWER_DOWN");
		dbg_init (1, "MOD_INC_USE_COUNT %d", 
			GET_USE_COUNT (THIS_MODULE));
		udc_disconnect ();		/* disable USB pullup */
		if (device)
			udc_disable_interrupts (device);	/* disable interrupts */
		udc_disable ();			/* disable UDC */
		dbg_pm (0, "SUSPEND_POWER_DOWN: finished");
		break;
	}

	return 0;
}
Ejemplo n.º 11
0
/*
  Unregister entry point for the peripheral controller driver.
*/
int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
{
	struct lh7a40x_udc *dev = the_controller;
	unsigned long flags;

	if (!dev)
		return -ENODEV;
	if (!driver || driver != dev->driver || !driver->unbind)
		return -EINVAL;

	spin_lock_irqsave(&dev->lock, flags);
	dev->driver = 0;
	stop_activity(dev, driver);
	spin_unlock_irqrestore(&dev->lock, flags);

	driver->unbind(&dev->gadget);
	device_del(&dev->gadget.dev);

	udc_disable(dev);

	DEBUG("unregistered gadget driver '%s'\n", driver->driver.name);
	return 0;
}
Ejemplo n.º 12
0
int udc_destroy(void)
{
	udc_disable();
	mxc_udc_destroy();
	return 0;
}
Ejemplo n.º 13
0
/* bi_modexit - decommission bus interface driver
 */
void __exit bi_modexit(void)
{
    struct usb_bus_instance *bus;
    struct usb_device_instance *device;
    struct bi_data *data;

    dbgENTER(dbgflg_usbdbi_init,1);

    if ((device = device_array[0])) {

        // XXX moved to usbd_deregister_device()
        //device->status = USBD_CLOSING;

        udc_disconnect();
        udc_disable();

        // XXX XXX
        if (dbgflg_usbdbi_tick > 0) {
            ticker_killoff();
        }

        bus = device->bus;
        data = bus->privdata;

        // XXX
        usbd_device_event(device, DEVICE_RESET, 0);
        usbd_device_event(device, DEVICE_POWER_INTERRUPTION, 0);
        usbd_device_event(device, DEVICE_HUB_RESET, 0);

        dbg_init(1,"DEVICE_DESTROY");
        usbd_device_event(device, DEVICE_DESTROY, 0);

        dbg_init(1,"DISABLE ENDPOINTS");
        bi_disable_endpoints(device);

        dbg_init(1,"UDC_DISABLE");
        //udc_disable();

        dbg_init(1,"BI_UDC_EXIT");
        bi_udc_exit();

        device_array[0] = NULL;
        bus->privdata = NULL;


#ifdef CONFIG_PM
        dbg_init(1,"PM_UNREGISTER(pm_dev#%p)",pm_dev);
        if (pm_dev) {
            pm_unregister(pm_dev);
        }
#endif
        dbg_init(1,"DEREGISTER DEVICE");
        usbd_deregister_device(device);
        bus->device = NULL;

        dbg_init(1,"kfree(data#%p)",data);
        if (data) {
            kfree(data);
        }

        if (bus->serial_number_str) {
            kfree(bus->serial_number_str);
        }

        dbg_init(1,"DEREGISTER BUS");
        usbd_deregister_bus(bus);

    }
    else {
        dbg_init(0,"device is NULL");
    }
    dbg_init(1,"BI_EXIT");
    bi_exit();
    dbgLEAVE(dbgflg_usbdbi_init,1);
}
Ejemplo n.º 14
0
/**
 * bi_device_event - handle generic bus event
 * @device: device pointer
 * @event: interrupt event
 *
 * Called by usb core layer to inform bus of an event.
 */
int bi_device_event(struct usb_device_instance *device, usb_device_event_t event, int data)
{
    sie_info * sie_data;
    cy_priv_t * cy_priv;
    otg_t * otg;

    sie_data = (sie_info *) device->bus->privdata;
    cy_priv = (cy_priv_t *) sie_data->cy_priv;
    otg = (otg_t *) cy_priv->otg;

    //printk(KERN_DEBUG "bi_device_event: event: %d\n", event);

    if (!device) {
        return 0;
    }
    switch (event) {
    case DEVICE_UNKNOWN:
        break;
    case DEVICE_INIT:
        break;
    case DEVICE_CREATE:         // XXX should this stuff be in DEVICE_INIT?

        bi_config(device);

        // enable udc, enable interrupts, enable connect
        udc_enable(device);
        udc_all_interrupts(device);
        udc_connect();
        break;

    case DEVICE_HUB_CONFIGURED:
        break;

    case DEVICE_RESET:
        device->address = 0;
        udc_set_address(device->address, device);
        udc_reset_ep(0, device);
        udc_all_interrupts(device); // XXX
        break;


    case DEVICE_ADDRESS_ASSIGNED:
        udc_set_address(device->address, device);
        device->status = USBD_OK;
        break;

    case DEVICE_CONFIGURED:
        bi_config(device);
        break;

    case DEVICE_DE_CONFIGURED:
        udc_reset_ep(1, device);
        udc_reset_ep(2, device);
        udc_reset_ep(3, device);
        break;

    case DEVICE_SET_INTERFACE:
        bi_config(device);
        break;

    case DEVICE_SET_FEATURE:
        break;

    case DEVICE_CLEAR_FEATURE:
        break;

    case DEVICE_BUS_INACTIVE:
        // disable suspend interrupt
        udc_suspended_interrupts(device);

        // XXX check on linkup and sl11
        // if we are no longer connected then force a reset
        if (!udc_connected()) {
            usbd_device_event_irq(device, DEVICE_RESET, 0);
        }
        break;

    case DEVICE_BUS_ACTIVITY:
        // enable suspend interrupt
        udc_all_interrupts(device);
        break;

    case DEVICE_POWER_INTERRUPTION:
        break;

    case DEVICE_HUB_RESET:
        break;

    case DEVICE_DESTROY:
        udc_disconnect();
        bi_disable_endpoints(device);
        udc_disable_interrupts(device);
        udc_disable();
        break;

    case DEVICE_BUS_REQUEST:
        otg->b_bus_req = TRUE;
        update_otg_state(otg);
        break;

    case DEVICE_BUS_RELEASE:
        otg->b_bus_req = FALSE;
        update_otg_state(otg);
        break;

    case DEVICE_RCV_URB_RECYCLED:
        udc_rcv_urb_recycled();
        break;

    case DEVICE_ACCEPT_HNP:
        otg->b_hnp_en = TRUE;
        update_otg_state(otg);
    break;

    case DEVICE_REQUEST_SRP:
        //otg->srp_start_flag = TRUE;
        otg->b_bus_req = TRUE;
        otg->b_se0_srp = TRUE;
        update_otg_state(otg);
    break;

    case DEVICE_FUNCTION_PRIVATE:
        break;
    }

    return 0;
}
Ejemplo n.º 15
0
/**
 * bi_device_event - handle generic bus event
 * @device: device pointer
 * @event: interrupt event
 *
 * Called by usb core layer to inform bus of an event.
 */
int bi_device_event (struct usb_device_instance *device, usb_device_event_t event, int data)
{

	//printk(KERN_DEBUG "bi_device_event: event: %d\n", event);

	if (!device) {
		return 0;
	}

        dbg_usbe (1,"%s", USBD_DEVICE_EVENTS(event));

	switch (event) {
	case DEVICE_UNKNOWN:
		break;
	case DEVICE_INIT:
		break;
	case DEVICE_CREATE:	// XXX should this stuff be in DEVICE_INIT?
		// enable upstream port

		//ep0_enable(device);

		// for net_create
		bi_config (device);

		// enable udc, enable interrupts, enable connect
                printk(KERN_INFO"bi_device_event: call udc_enable\n");
		udc_enable (device);
                printk(KERN_INFO"bi_device_event: call udc_all_interrupts\n");

                // XXX verify
		udc_suspended_interrupts (device);
		//udc_all_interrupts (device);

		dbg_usbe (1, "CREATE done");
		break;

	case DEVICE_HUB_CONFIGURED:
		udc_connect ();
		break;

	case DEVICE_RESET:
		device->address = 0;
		udc_set_address (device->address);
		udc_reset_ep (0);
                
                // XXX verify
		udc_suspended_interrupts (device);
		dbg_usbe (1, "DEVICE RESET done: %d", device->address);
		break;


	case DEVICE_ADDRESS_ASSIGNED:
		udc_set_address (device->address);
		device->status = USBD_OK;

                // XXX verify
		udc_all_interrupts (device);	// XXX
		break;

	case DEVICE_CONFIGURED:
		device->status = USBD_OK;
		bi_config (device);
		break;

	case DEVICE_DE_CONFIGURED:
		{
			int ep;

			for (ep = 1; ep < udc_max_endpoints (); ep++)
				udc_reset_ep (ep);
		}
		break;


	case DEVICE_SET_INTERFACE:
		bi_config (device);
		break;

	case DEVICE_SET_FEATURE:
		break;

	case DEVICE_CLEAR_FEATURE:
		break;

	case DEVICE_BUS_INACTIVE:
		// disable suspend interrupt
		udc_suspended_interrupts (device);

		// XXX check on linkup and sl11
		// if we are no longer connected then force a reset
		if (!udc_connected ()) {
			usbd_device_event_irq (device, DEVICE_RESET, 0);
		}
		break;

	case DEVICE_BUS_ACTIVITY:
		// enable suspend interrupt
		udc_all_interrupts (device);
		break;

	case DEVICE_POWER_INTERRUPTION:
		break;

	case DEVICE_HUB_RESET:
		break;

	case DEVICE_DESTROY:
		udc_disconnect ();
		bi_disable_endpoints (device);
		udc_disable_interrupts (device);
		udc_disable ();
		break;

	case DEVICE_FUNCTION_PRIVATE:
		break;
	}
	return 0;
}
Ejemplo n.º 16
0
void udc_power_off(void)
{
	udc_disable();
}