/* udc_startup_events
 *
 * Enable the specified device
 */
void udc_startup_events (struct usb_device_instance *device)
{
	udc_enable (device);
	if (udc_state == STATE_READY) {
		usbd_device_event_irq (device, DEVICE_CREATE, 0);
	}
}
Ejemplo n.º 2
0
/**
 * udc_startup - allow udc code to do any additional startup
 */
void udc_startup_events (struct usb_device_instance *device)
{
	/* The DEVICE_INIT event puts the USB device in the state STATE_INIT. */
	usbd_device_event_irq (device, DEVICE_INIT, 0);

	/* The DEVICE_CREATE event puts the USB device in the state
	 * STATE_ATTACHED.
	 */
	usbd_device_event_irq (device, DEVICE_CREATE, 0);

	/* Some USB controller driver implementations signal
	 * DEVICE_HUB_CONFIGURED and DEVICE_RESET events here.
	 * DEVICE_HUB_CONFIGURED causes a transition to the state STATE_POWERED,
	 * and DEVICE_RESET causes a transition to the state STATE_DEFAULT.
	 * The OMAP USB client controller has the capability to detect when the
	 * USB cable is connected to a powered USB bus via the ATT bit in the
	 * DEVSTAT register, so we will defer the DEVICE_HUB_CONFIGURED and
	 * DEVICE_RESET events until later.
	 */

	/* The GTA01 can detect usb device attachment, but we just assume being
	 * attached for now (go to STATE_POWERED) */
	usbd_device_event_irq (device, DEVICE_HUB_CONFIGURED, 0);

	udc_enable (device);
}
Ejemplo n.º 3
0
static int
bi_udc_resume(struct device *dev, u32 level)
{
	int ret = 0;
	struct usb_device_instance *device = device_array[0];

	switch (level) {
	case RESUME_POWER_ON:
		dbg_pm (0, "RESUME_POWER_ON");
		if (udc_init ()) {
			dbg_init (0, "udc_init failed");
		}
		if (device) {
			udc_enable (device);		/* enable UDC */
			udc_all_interrupts (device);	/* enable interrupts */
		}
		udc_connect ();			/* enable USB pullup */

		dbg_init (1, "MOD_INC_USE_COUNT %d", 
			GET_USE_COUNT (THIS_MODULE));
		dbg_pm (0, "RESUME_POWER_ON: finished");
		break;
	}

	return ret;
}
Ejemplo n.º 4
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 up s3c-udc power & enable otg clock
 */ 
void s3c_udc_power_up(void)
{
	struct s3c_udc *dev = the_controller;

	printk("[%s] \n", __FUNCTION__);
	
	//fsa9480_s3c_udc_on();

	clk_enable(otg_clock);
	udc_enable(dev);
}
Ejemplo n.º 6
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_startup(void)
{
	struct gadget_wrapper *d;

	d = gadget_wrapper;

	pr_info("USB:startup udc\n");
	if (!d->udc_startup) {
		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;
	}
}
Ejemplo n.º 9
0
void udc_startup_events(struct usb_device_instance *device)
{
	/* The DEVICE_INIT event puts the USB device in the state STATE_INIT. */
	usbd_device_event_irq(device, DEVICE_INIT, 0);

	/*
	 * The DEVICE_CREATE event puts the USB device in the state
	 * STATE_ATTACHED.
	 */
	usbd_device_event_irq(device, DEVICE_CREATE, 0);

	/* Resets the address to 0 */
	usbd_device_event_irq(device, DEVICE_RESET, 0);

	udc_enable(device);
}
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.º 11
0
/* Allow udc code to do any additional startup */
void udc_startup_events(struct usb_device_instance *device)
{
	/* The DEVICE_INIT event puts the USB device in the state STATE_INIT */
	usbd_device_event_irq(device, DEVICE_INIT, 0);

	/* The DEVICE_CREATE event puts the USB device in the state
	 * STATE_ATTACHED */
	usbd_device_event_irq(device, DEVICE_CREATE, 0);

	/* Some USB controller driver implementations signal
	 * DEVICE_HUB_CONFIGURED and DEVICE_RESET events here.
	 * DEVICE_HUB_CONFIGURED causes a transition to the state
	 * STATE_POWERED, and DEVICE_RESET causes a transition to
	 * the state STATE_DEFAULT.
	 */
	udc_enable(device);
}
Ejemplo n.º 12
0
/*
  Register entry point for the peripheral controller driver.
*/
int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
		int (*bind)(struct usb_gadget *))
{
	struct lh7a40x_udc *dev = the_controller;
	int retval;

	DEBUG("%s: %s\n", __func__, driver->driver.name);

	if (!driver
			|| driver->speed != USB_SPEED_FULL
			|| !bind
			|| !driver->disconnect
			|| !driver->setup)
		return -EINVAL;
	if (!dev)
		return -ENODEV;
	if (dev->driver)
		return -EBUSY;

	/* first hook up the driver ... */
	dev->driver = driver;
	dev->gadget.dev.driver = &driver->driver;

	device_add(&dev->gadget.dev);
	retval = bind(&dev->gadget);
	if (retval) {
		printk(KERN_WARNING "%s: bind to driver %s --> error %d\n",
		       dev->gadget.name, driver->driver.name, retval);
		device_del(&dev->gadget.dev);

		dev->driver = 0;
		dev->gadget.dev.driver = 0;
		return retval;
	}

	/* ... then enable host detection and ep0; and we're ready
	 * for set_configuration as well as eventual disconnect.
	 * NOTE:  this shouldn't power up until later.
	 */
	printk(KERN_WARNING "%s: registered gadget driver '%s'\n",
	       dev->gadget.name, driver->driver.name);

	udc_enable(dev);

	return 0;
}
Ejemplo n.º 13
0
/*
  Register entry point for the peripheral controller driver.
*/
int usb_gadget_register_driver(struct usb_gadget_driver *driver)
{
	struct s3c_udc *dev = the_controller;
	int retval;

	DEBUG_SETUP("%s: %s\n", __FUNCTION__, driver->driver.name);

	if (!driver
	    || (driver->speed != USB_SPEED_FULL && driver->speed != USB_SPEED_HIGH)
	    || !driver->bind
	    || !driver->unbind || !driver->disconnect || !driver->setup)
		return -EINVAL;
	if (!dev)
		return -ENODEV;
	if (dev->driver)
		return -EBUSY;

	/* first hook up the driver ... */
	dev->driver = driver;
	dev->gadget.dev.driver = &driver->driver;
	retval = device_add(&dev->gadget.dev);

	if(retval) { /* TODO */
		printk("target device_add failed, error %d\n", retval);
		return retval;
	}

	retval = driver->bind(&dev->gadget);
	if (retval) {
		printk("%s: bind to driver %s --> error %d\n", dev->gadget.name,
		       driver->driver.name, retval);
		device_del(&dev->gadget.dev);

		dev->driver = 0;
		dev->gadget.dev.driver = 0;
		return retval;
	}

	enable_irq(IRQ_USBD);

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

	return 0;
}
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;
}
/*
 * usb_gadget_register_driver
 * Register entry point for the peripheral controller driver.
*/
int usb_gadget_register_driver(struct usb_gadget_driver *driver)
{
	struct s3c_udc *dev = the_controller;
	int retval;

	DEBUG_SETUP("%s: %s\n", __FUNCTION__, driver->driver.name);
#if 1
/*
	adb composite fail to !driver->unbind in composite.c as below
	static struct usb_gadget_driver composite_driver = {
		.speed		= USB_SPEED_HIGH,

		.bind		= composite_bind,
		.unbind		= __exit_p(composite_unbind),
*/
	if (!driver
	    || (driver->speed != USB_SPEED_FULL && driver->speed != USB_SPEED_HIGH)
	    || !driver->bind
	    || !driver->disconnect || !driver->setup)
		return -EINVAL;		
#else	
if (!driver
	|| (driver->speed != USB_SPEED_FULL && driver->speed != USB_SPEED_HIGH)
	|| !driver->bind
	|| !driver->unbind || !driver->disconnect || !driver->setup)
	return -EINVAL;
#endif
	
	if (!dev)
		return -ENODEV;

	if (dev->driver)
		return -EBUSY;

	/* first hook up the driver ... */
	dev->driver = driver;
	dev->gadget.dev.driver = &driver->driver;
	retval = device_add(&dev->gadget.dev);

	if(retval) { /* TODO */
		printk("target device_add failed, error %d\n", retval);
		return retval;
	}
	
	retval = driver->bind(&dev->gadget);
	if (retval) {
		printk("%s: bind to driver %s --> error %d\n", dev->gadget.name,
		       driver->driver.name, retval);
		device_del(&dev->gadget.dev);

		dev->driver = 0;
		dev->gadget.dev.driver = 0;
		return retval;
	}
	enable_irq(IRQ_OTG);
	
	printk("Registered gadget driver '%s'\n", driver->driver.name);
	udc_enable(dev);

	//in case of rndis, will be chaned at the time of SET_CONFIGURATION
	if (strcmp(driver->driver.name, "g_ether") == 0)
		dev->config_gadget_driver = ETHER_CDC;	
	
	else if (strcmp(driver->driver.name, "android_adb") == 0)
		dev->config_gadget_driver = ANDROID_ADB;
	
	else if (strcmp(driver->driver.name, "android_usb") == 0)
		dev->config_gadget_driver = ANDROID_ADB_UMS;
	
	else if (strcmp(driver->driver.name, "android_adb_ums_acm") == 0)
		dev->config_gadget_driver = ANDROID_ADB_UMS_ACM;
	
	else if (strcmp(driver->driver.name, "g_serial") == 0)
		dev->config_gadget_driver = SERIAL;
	
	else if (strcmp(driver->driver.name, "g_cdc") == 0)
		dev->config_gadget_driver = CDC2;
	
	else if (strcmp(driver->driver.name, "g_file_storage") == 0)
		dev->config_gadget_driver = FILE_STORAGE;

	else
		printk("Not recognized driver's name '%s'\n", driver->driver.name);
		
	return 0;
}