static int tahvo_usb_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *gadget) { struct tahvo_usb *tu = container_of(otg, struct tahvo_usb, otg); dev_dbg(&tu->pt_dev->dev, "set_peripheral %p\n", gadget); if (!otg) return -ENODEV; #if defined(CONFIG_USB_OTG) || defined(CONFIG_USB_GADGET_OMAP) mutex_lock(&tu->serialize); if (!gadget) { if (TAHVO_MODE(tu) == TAHVO_MODE_PERIPHERAL) tahvo_usb_power_off(tu); tu->otg.gadget = NULL; mutex_unlock(&tu->serialize); return 0; } tu->otg.gadget = gadget; if (TAHVO_MODE(tu) == TAHVO_MODE_PERIPHERAL) tahvo_usb_become_peripheral(tu); mutex_unlock(&tu->serialize); #else /* No gadget mode configured, so do not allow host controlled to be set */ return -EINVAL; #endif return 0; }
static void tahvo_usb_power_off(struct tahvo_usb *tu) { u32 l; int id; /* Disable gadget controller if any */ if (tu->otg.gadget) usb_gadget_vbus_disconnect(tu->otg.gadget); /* Disable OTG and interrupts */ if (TAHVO_MODE(tu) == TAHVO_MODE_PERIPHERAL) id = OTG_ID; else id = 0; l = omap_readl(OTG_CTRL); l &= ~(OTG_CTRL_XCVR_MASK | OTG_CTRL_SYS_MASK | OTG_BSESSVLD); l |= id | OTG_BSESSEND; omap_writel(l, OTG_CTRL); omap_writew(0, OTG_IRQ_EN); l = omap_readl(OTG_SYSCON_2); l &= ~OTG_EN; omap_writel(l, OTG_SYSCON_2); l = omap_readl(OTG_SYSCON_1); l |= OTG_IDLE_EN; omap_writel(l, OTG_SYSCON_1); /* Power off transceiver */ tahvo_write_reg(tu->dev, TAHVO_REG_USBR, 0); tu->otg.state = OTG_STATE_UNDEFINED; }
static void tahvo_usb_power_off(struct tahvo_usb *tu) { u32 l; int id; /* Disable gadget controller if any */ if (tu->otg.gadget) usb_gadget_vbus_disconnect(tu->otg.gadget); host_suspend(tu); /* Disable OTG and interrupts */ if (TAHVO_MODE(tu) == TAHVO_MODE_PERIPHERAL) id = OTG_ID; else id = 0; l = OTG_CTRL_REG; l &= ~(OTG_CTRL_XCVR_MASK | OTG_CTRL_SYS_MASK | OTG_BSESSVLD); l |= id | OTG_BSESSEND; OTG_CTRL_REG = l; OTG_IRQ_EN_REG = 0; OTG_SYSCON_2_REG &= ~OTG_EN; OTG_SYSCON_1_REG |= OTG_IDLE_EN; /* Power off transceiver */ tahvo_write_reg(TAHVO_REG_USBR, 0); tu->otg.state = OTG_STATE_UNDEFINED; }
static int tahvo_usb_set_host(struct otg_transceiver *otg, struct usb_bus *host) { struct tahvo_usb *tu = container_of(otg, struct tahvo_usb, otg); u32 l; dev_dbg(&tu->pt_dev->dev, "set_host %p\n", host); if (otg == NULL) return -ENODEV; #if defined(CONFIG_USB_OTG) || !defined(CONFIG_USB_GADGET_OMAP) mutex_lock(&tu->serialize); if (host == NULL) { if (TAHVO_MODE(tu) == TAHVO_MODE_HOST) tahvo_usb_power_off(tu); tu->otg.host = NULL; mutex_unlock(&tu->serialize); return 0; } l = omap_readl(OTG_SYSCON_1); l &= ~(OTG_IDLE_EN | HST_IDLE_EN | DEV_IDLE_EN); omap_writel(l, OTG_SYSCON_1); if (TAHVO_MODE(tu) == TAHVO_MODE_HOST) { tu->otg.host = NULL; tahvo_usb_become_host(tu); } else host_suspend(tu); tu->otg.host = host; mutex_unlock(&tu->serialize); #else /* No host mode configured, so do not allow host controlled to be set */ return -EINVAL; #endif return 0; }