[PATCH 16/25] USB Client Maximum Power Consumption function

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

 



From: JiebingLi <jiebing.li@xxxxxxxxx>

Get Maximum power consumption function in USB clent driver. This is used by
the power manager.

Signed-off-by: JiebingLi <jiebing.li@xxxxxxxxx>
Signed-off-by: Alan Cox <alan@xxxxxxxxxxxxxxx>
---

 drivers/usb/gadget/langwell_udc.c |   49 +++++++++++++++++++++++++++++++++++++
 include/linux/usb/langwell_udc.h  |    6 +++++
 2 files changed, 55 insertions(+), 0 deletions(-)


diff --git a/drivers/usb/gadget/langwell_udc.c b/drivers/usb/gadget/langwell_udc.c
index 3b3e5ba..6251c3c 100644
--- a/drivers/usb/gadget/langwell_udc.c
+++ b/drivers/usb/gadget/langwell_udc.c
@@ -1974,6 +1974,55 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
 EXPORT_SYMBOL(usb_gadget_unregister_driver);
 
 
+/* gets the maximum power consumption */
+int langwell_udc_maxpower(int *mA)
+{
+	struct langwell_udc	*dev = the_controller;
+	u32			usbmode, portsc1, usbcmd;
+
+	/* fatal error */
+	if (!dev) {
+		*mA = 0;
+		return -EINVAL;
+	}
+
+	dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
+
+	/* contrller is not in device mode */
+	usbmode = readl(&dev->op_regs->usbmode);
+	if (MODE_CM(usbmode) != MODE_DEVICE) {
+		*mA = 0;
+		return -EINVAL;
+	}
+
+	/* can't get maximum power */
+	usbcmd = readl(&dev->op_regs->usbcmd);
+	if (!(usbcmd & CMD_RUNSTOP)) {
+		*mA = 0;
+		return -EINVAL;
+	}
+
+	/* disconnect to USB host */
+	portsc1 = readl(&dev->op_regs->portsc1);
+	if (!(portsc1 & PORTS_CCS)) {
+		*mA = 0;
+		return -EINVAL;
+	}
+
+	/* set max power capability */
+	*mA = CONFIG_USB_GADGET_VBUS_DRAW;
+
+	if ((*mA < 8) || (*mA > 500)) {
+		*mA = 0;
+		return -EINVAL;
+	}
+
+	dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(langwell_udc_maxpower);
+
+
 /*-------------------------------------------------------------------------*/
 
 /*
diff --git a/include/linux/usb/langwell_udc.h b/include/linux/usb/langwell_udc.h
index 2d2d1bb..090d94f 100644
--- a/include/linux/usb/langwell_udc.h
+++ b/include/linux/usb/langwell_udc.h
@@ -306,5 +306,11 @@ struct langwell_op_regs {
 #define	EPCTRL_RXS	BIT(0)	/* RX endpoint STALL */
 } __attribute__ ((packed));
 
+
+/* export function declaration */
+
+/* gets the maximum power consumption */
+extern int langwell_udc_maxpower(int *mA);
+
 #endif /* __LANGWELL_UDC_H */
 

--
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