static int tahvo_usb_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget) { struct tahvo_usb *tu = container_of(otg->phy, struct tahvo_usb, phy); dev_dbg(&tu->pt_dev->dev, "%s %p\n", __func__, gadget); mutex_lock(&tu->serialize); if (!gadget) { if (tu->tahvo_mode == TAHVO_MODE_PERIPHERAL) tahvo_usb_power_off(tu); tu->phy.otg->gadget = NULL; mutex_unlock(&tu->serialize); return 0; } tu->phy.otg->gadget = gadget; if (tu->tahvo_mode == TAHVO_MODE_PERIPHERAL) tahvo_usb_become_peripheral(tu); mutex_unlock(&tu->serialize); return 0; }
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 ssize_t otg_mode_store(struct device *device, struct device_attribute *attr, const char *buf, size_t count) { struct tahvo_usb *tu = dev_get_drvdata(device); int r; mutex_lock(&tu->serialize); if (count >= 4 && strncmp(buf, "host", 4) == 0) { if (tu->tahvo_mode == TAHVO_MODE_PERIPHERAL) tahvo_usb_stop_peripheral(tu); tu->tahvo_mode = TAHVO_MODE_HOST; if (tu->phy.otg->host) { dev_info(device, "HOST mode: host controller present\n"); tahvo_usb_become_host(tu); } else { dev_info(device, "HOST mode: no host controller, powering off\n"); tahvo_usb_power_off(tu); } r = strlen(buf); } else if (count >= 10 && strncmp(buf, "peripheral", 10) == 0) { if (tu->tahvo_mode == TAHVO_MODE_HOST) tahvo_usb_stop_host(tu); tu->tahvo_mode = TAHVO_MODE_PERIPHERAL; if (tu->phy.otg->gadget) { dev_info(device, "PERIPHERAL mode: gadget driver present\n"); tahvo_usb_become_peripheral(tu); } else { dev_info(device, "PERIPHERAL mode: no gadget driver, powering off\n"); tahvo_usb_power_off(tu); } r = strlen(buf); } else { r = -EINVAL; } mutex_unlock(&tu->serialize); return r; }
static ssize_t otg_mode_store(struct device *device, struct device_attribute *attr, const char *buf, size_t count) { struct tahvo_usb *tu = (struct tahvo_usb*) device->driver_data; int r; r = strlen(buf); mutex_lock(&tu->serialize); if (strncmp(buf, "host", 4) == 0) { if (tu->tahvo_mode == TAHVO_MODE_PERIPHERAL) tahvo_usb_stop_peripheral(tu); tu->tahvo_mode = TAHVO_MODE_HOST; if (tu->otg.host) { printk(KERN_INFO "Selected HOST mode: host controller present.\n"); tahvo_usb_become_host(tu); } else { printk(KERN_INFO "Selected HOST mode: no host controller, powering off.\n"); tahvo_usb_power_off(tu); } } else if (strncmp(buf, "peripheral", 10) == 0) { if (tu->tahvo_mode == TAHVO_MODE_HOST) tahvo_usb_stop_host(tu); tu->tahvo_mode = TAHVO_MODE_PERIPHERAL; if (tu->otg.gadget) { printk(KERN_INFO "Selected PERIPHERAL mode: gadget driver present.\n"); tahvo_usb_become_peripheral(tu); } else { printk(KERN_INFO "Selected PERIPHERAL mode: no gadget driver, powering off.\n"); tahvo_usb_power_off(tu); } } else r = -EINVAL; mutex_unlock(&tu->serialize); return r; }