[PATCH 4/9] usb: gdaget: composite: override OTG capabilities when add config

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Macpaul Lin <macpaul@xxxxxxxxx>

Update usb_otg_descriptor for ADP/SRP/HNP features if usb HW has any
configrations of them.

Signed-off-by: Macpaul Lin <macpaul@xxxxxxxxx>
Signed-off-by: Li Jun <jun.li@xxxxxxxxxxxxx>
---
 drivers/usb/gadget/composite.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 4e3447b..707959c 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -610,6 +610,36 @@ static void device_qual(struct usb_composite_dev *cdev)
 	qual->bRESERVED = 0;
 }
 
+static int usb_gadget_otg_desc_override(struct usb_gadget *gadget,
+					struct usb_configuration *config)
+{
+	struct usb_otg_descriptor *otg_desc;
+
+	if (!gadget_is_otg(gadget))
+		return -EOPNOTSUPP;
+
+	otg_desc = (struct usb_otg_descriptor *)config->descriptors[0];
+#ifdef CONFIG_USB_OTG_VERSION
+#if CONFIG_USB_OTG_VERSION >= 20
+	otg_desc->bcdOTG = cpu_to_le16(((CONFIG_USB_OTG_VERSION / 10) << 8) +
+						(CONFIG_USB_OTG_VERSION % 10));
+#endif
+#endif
+	/* Override OTG attributes if defined by HW */
+	if (gadget->adp_support || gadget->hnp_support ||
+					gadget->srp_support) {
+		otg_desc->bmAttributes = 0;
+		if (gadget->adp_support)
+			otg_desc->bmAttributes |= USB_OTG_ADP;
+		if (gadget->hnp_support)
+			otg_desc->bmAttributes |= USB_OTG_HNP;
+		if (gadget->srp_support)
+			otg_desc->bmAttributes |= USB_OTG_SRP;
+	}
+
+	return 0;
+}
+
 /*-------------------------------------------------------------------------*/
 
 static void reset_config(struct usb_composite_dev *cdev)
@@ -837,6 +867,7 @@ int usb_add_config(struct usb_composite_dev *cdev,
 	 */
 	usb_ep_autoconfig_reset(cdev->gadget);
 
+	usb_gadget_otg_desc_override(cdev->gadget, config);
 done:
 	if (status)
 		DBG(cdev, "added config '%s'/%u --> %d\n", config->label,
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux