devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC 2/2] usb: gadget: composite: parse dt overrides
@ 2012-06-25 20:23 Alexandre Pereira da Silva
  2012-06-25 21:30 ` Michal Nazarewicz
  2012-06-25 23:49 ` Rob Herring
  0 siblings, 2 replies; 6+ messages in thread
From: Alexandre Pereira da Silva @ 2012-06-25 20:23 UTC (permalink / raw)
  To: Felipe Balbi, Greg Kroah-Hartman, linux-usb, linux-kernel,
	Grant Likely, Rob Herring, devicetree-discuss
  Cc: Alexandre Pereira da Silva

Grab the devicetree node properties to override VendorId, ProductId,
bcdDevice, Manucacturer, Product and SerialNumber

Signed-off-by: Alexandre Pereira da Silva <aletes.xgr@gmail.com>
---
 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 390749b..f3b480e 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -17,6 +17,7 @@
 #include <linux/module.h>
 #include <linux/device.h>
 #include <linux/utsname.h>
+#include <linux/of.h>
 
 #include <linux/usb/composite.h>
 #include <asm/unaligned.h>
@@ -1423,6 +1424,7 @@ static int composite_bind(struct usb_gadget *gadget)
 {
 	struct usb_composite_dev	*cdev;
 	int				status = -ENOMEM;
+	struct device_node		*np = gadget->dev.of_node;
 
 	cdev = kzalloc(sizeof *cdev, GFP_KERNEL);
 	if (!cdev)
@@ -1470,6 +1472,35 @@ static int composite_bind(struct usb_gadget *gadget)
 
 	cdev->desc = *composite->dev;
 
+	/* grab overrides from devicetree */
+	if (np) {
+		u32 reg;
+
+		if (!idVendor &&
+			of_property_read_u32(np, "vendor_id", &reg) == 0)
+			idVendor = reg;
+
+		if (!idProduct &&
+			of_property_read_u32(np, "product_id", &reg) == 0)
+			idProduct = reg;
+
+		if (!bcdDevice &&
+			of_property_read_u32(np, "bcd_device", &reg) == 0)
+			bcdDevice = reg;
+
+		if (!iManufacturer)
+			of_property_read_string(np, "manufacturer",
+				&iManufacturer);
+
+		if (!iProduct)
+			of_property_read_string(np, "product",
+				&iProduct);
+
+		if (!iSerialNumber)
+			of_property_read_string(np, "serial_number",
+				&iSerialNumber);
+	}
+
 	/* standardized runtime overrides for device ID data */
 	if (idVendor)
 		cdev->desc.idVendor = cpu_to_le16(idVendor);
-- 
1.7.10

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-06-26 14:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-25 20:23 [RFC 2/2] usb: gadget: composite: parse dt overrides Alexandre Pereira da Silva
2012-06-25 21:30 ` Michal Nazarewicz
2012-06-25 23:49 ` Rob Herring
     [not found]   ` <4FE8F90B.2010303-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2012-06-26  1:12     ` Alexandre Pereira da Silva
2012-06-26  5:38   ` Mitch Bradley
2012-06-26 14:04     ` Rob Herring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).