This patch series adds support to set basic usb gadget properties via
devicetree.
I takes into account the sugestions from Rob Herring and Mitch Bradley.
This was only tested on ARM LPC32XX SOC. I'm including patches to other soc's as
an reference.
Alexandre Pereira da Silva (5):
usb: gadget: lpc32xx_udc: Propagate devicetree to gadget drivers
usb: gadget: s3c-hsotg: Propagate devicetree to gadget drivers
usb: gadget: fsl_udc: Propagate devicetree to gadget drivers
usb: gadget: at91_udc: Propagate devicetree to gadget drivers
usb: gadget: composite: parse dt overrides
Documentation/devicetree/bindings/usb/gadget.txt | 20 +++++++++++
drivers/usb/gadget/at91_udc.c | 1 +
drivers/usb/gadget/composite.c | 39 ++++++++++++++++++++++
drivers/usb/gadget/fsl_udc_core.c | 1 +
drivers/usb/gadget/lpc32xx_udc.c | 1 +
drivers/usb/gadget/s3c-hsotg.c | 1 +
6 files changed, 63 insertions(+)
create mode 100644 Documentation/devicetree/bindings/usb/gadget.txt
--
1.7.10
Fill dev.of_node of gadget drivers, so they can use devicetree
Signed-off-by: Alexandre Pereira da Silva <[email protected]>
---
drivers/usb/gadget/lpc32xx_udc.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/usb/gadget/lpc32xx_udc.c b/drivers/usb/gadget/lpc32xx_udc.c
index 93a901b..551c0e9 100644
--- a/drivers/usb/gadget/lpc32xx_udc.c
+++ b/drivers/usb/gadget/lpc32xx_udc.c
@@ -3005,6 +3005,7 @@ static int lpc32xx_start(struct usb_gadget_driver *driver,
udc->driver = driver;
udc->gadget.dev.driver = &driver->driver;
+ udc->gadget.dev.of_node = udc->dev->of_node;
udc->enabled = 1;
udc->selfpowered = 1;
udc->vbus = 0;
--
1.7.10
Fill dev.of_node of gadget drivers, so they can use devicetree
Signed-off-by: Alexandre Pereira da Silva <[email protected]>
---
drivers/usb/gadget/fsl_udc_core.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
index bc6f9bb..a65ca0f 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -2560,6 +2560,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
dev_set_name(&udc_controller->gadget.dev, "gadget");
udc_controller->gadget.dev.release = fsl_udc_release;
udc_controller->gadget.dev.parent = &pdev->dev;
+ udc_controller->gadget.dev.of_node = pdev->dev.of_node;
ret = device_register(&udc_controller->gadget.dev);
if (ret < 0)
goto err_free_irq;
--
1.7.10
Grab the devicetree node properties to override VendorId, ProductId,
bcdDevice, Manucacturer, Product and SerialNumber
Signed-off-by: Alexandre Pereira da Silva <[email protected]>
---
Documentation/devicetree/bindings/usb/gadget.txt | 20 +++++++++++
drivers/usb/gadget/composite.c | 39 ++++++++++++++++++++++
2 files changed, 59 insertions(+)
create mode 100644 Documentation/devicetree/bindings/usb/gadget.txt
diff --git a/Documentation/devicetree/bindings/usb/gadget.txt b/Documentation/devicetree/bindings/usb/gadget.txt
new file mode 100644
index 0000000..93388d3
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/gadget.txt
@@ -0,0 +1,20 @@
+Usb Gadget DeviceTree bindings
+
+These optional properties inside the usb device controller node are used to
+change some of the gadget drivers configuration:
+- vendor-id: Usb vendor id
+- product-id: Usb product id
+- release: Version of this device
+- vendor: Textual description of the vendor
+- device: Textual description of this device
+- serial: Textual representation of the device's serial number
+
+Binding Example:
+ usbd@31020000 {
+ vendor-id = <0x0525>;
+ product-id = <0xa4a6>;
+ release = <1>;
+ vendor = "Some Corp";
+ device = "Test Device";
+ serial = "12345";
+ };
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 390749b..b39aef4 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>
@@ -1419,10 +1420,44 @@ static u8 override_id(struct usb_composite_dev *cdev, u8 *desc)
return *desc;
}
+static void composite_parse_dt(struct usb_composite_dev *cdev,
+ struct device_node *np)
+{
+ u32 reg;
+
+ if (!idVendor && of_property_read_u32(np, "vendor-id", ®) == 0)
+ idVendor = reg;
+
+ if (!idProduct && of_property_read_u32(np, "product-id", ®) == 0)
+ idProduct = reg;
+
+ if (!bcdDevice && of_property_read_u32(np, "release", ®) == 0)
+ bcdDevice = reg;
+
+ if (!iManufacturer)
+ if (of_property_read_string(np, "vendor",
+ &composite->iManufacturer) == 0)
+ cdev->manufacturer_override = override_id(cdev,
+ &cdev->desc.iManufacturer);
+
+ if (!iProduct)
+ if (of_property_read_string(np, "device",
+ &composite->iProduct) == 0)
+ cdev->product_override = override_id(cdev,
+ &cdev->desc.iProduct);
+
+ if (!iSerialNumber)
+ if (of_property_read_string(np, "serial",
+ &composite->iSerialNumber) == 0)
+ cdev->serial_override = override_id(cdev,
+ &cdev->desc.iSerialNumber);
+}
+
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 +1505,10 @@ static int composite_bind(struct usb_gadget *gadget)
cdev->desc = *composite->dev;
+ /* grab overrides from devicetree */
+ if (np)
+ composite_parse_dt(cdev, np);
+
/* standardized runtime overrides for device ID data */
if (idVendor)
cdev->desc.idVendor = cpu_to_le16(idVendor);
--
1.7.10
Fill dev.of_node of gadget drivers, so they can use devicetree
Signed-off-by: Alexandre Pereira da Silva <[email protected]>
---
drivers/usb/gadget/s3c-hsotg.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/usb/gadget/s3c-hsotg.c b/drivers/usb/gadget/s3c-hsotg.c
index f4abb0e..fed2f28 100644
--- a/drivers/usb/gadget/s3c-hsotg.c
+++ b/drivers/usb/gadget/s3c-hsotg.c
@@ -2954,6 +2954,7 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,
driver->driver.bus = NULL;
hsotg->driver = driver;
hsotg->gadget.dev.driver = &driver->driver;
+ hsotg->gadget.dev.of_node = hsotg->dev->of_node;
hsotg->gadget.dev.dma_mask = hsotg->dev->dma_mask;
hsotg->gadget.speed = USB_SPEED_UNKNOWN;
--
1.7.10
Fill dev.of_node of gadget drivers, so they can use devicetree
Signed-off-by: Alexandre Pereira da Silva <[email protected]>
---
drivers/usb/gadget/at91_udc.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index 1a4430f..c9e66df 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -1634,6 +1634,7 @@ static int at91_start(struct usb_gadget *gadget,
udc = container_of(gadget, struct at91_udc, gadget);
udc->driver = driver;
udc->gadget.dev.driver = &driver->driver;
+ udc->gadget.dev.of_node = udc->pdev->dev.of_node;
dev_set_drvdata(&udc->gadget.dev, &driver->driver);
udc->enabled = 1;
udc->selfpowered = 1;
--
1.7.10
On 06/26/2012 09:27 AM, Alexandre Pereira da Silva wrote:
> Grab the devicetree node properties to override VendorId, ProductId,
> bcdDevice, Manucacturer, Product and SerialNumber
I'm still confused about what is the order of priority for the 2
possible sources of these values. The way it is written, the DT value is
a default, not an override.
Rob
>
> Signed-off-by: Alexandre Pereira da Silva <[email protected]>
> ---
> Documentation/devicetree/bindings/usb/gadget.txt | 20 +++++++++++
> drivers/usb/gadget/composite.c | 39 ++++++++++++++++++++++
> 2 files changed, 59 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/usb/gadget.txt
>
> diff --git a/Documentation/devicetree/bindings/usb/gadget.txt b/Documentation/devicetree/bindings/usb/gadget.txt
> new file mode 100644
> index 0000000..93388d3
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/usb/gadget.txt
> @@ -0,0 +1,20 @@
> +Usb Gadget DeviceTree bindings
> +
> +These optional properties inside the usb device controller node are used to
> +change some of the gadget drivers configuration:
> +- vendor-id: Usb vendor id
> +- product-id: Usb product id
> +- release: Version of this device
> +- vendor: Textual description of the vendor
> +- device: Textual description of this device
> +- serial: Textual representation of the device's serial number
> +
> +Binding Example:
> + usbd@31020000 {
> + vendor-id = <0x0525>;
> + product-id = <0xa4a6>;
> + release = <1>;
> + vendor = "Some Corp";
> + device = "Test Device";
> + serial = "12345";
> + };
> diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
> index 390749b..b39aef4 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>
> @@ -1419,10 +1420,44 @@ static u8 override_id(struct usb_composite_dev *cdev, u8 *desc)
> return *desc;
> }
>
> +static void composite_parse_dt(struct usb_composite_dev *cdev,
> + struct device_node *np)
> +{
> + u32 reg;
> +
> + if (!idVendor && of_property_read_u32(np, "vendor-id", ®) == 0)
> + idVendor = reg;
> +
> + if (!idProduct && of_property_read_u32(np, "product-id", ®) == 0)
> + idProduct = reg;
> +
> + if (!bcdDevice && of_property_read_u32(np, "release", ®) == 0)
> + bcdDevice = reg;
> +
> + if (!iManufacturer)
> + if (of_property_read_string(np, "vendor",
> + &composite->iManufacturer) == 0)
> + cdev->manufacturer_override = override_id(cdev,
> + &cdev->desc.iManufacturer);
> +
> + if (!iProduct)
> + if (of_property_read_string(np, "device",
> + &composite->iProduct) == 0)
> + cdev->product_override = override_id(cdev,
> + &cdev->desc.iProduct);
> +
> + if (!iSerialNumber)
> + if (of_property_read_string(np, "serial",
> + &composite->iSerialNumber) == 0)
> + cdev->serial_override = override_id(cdev,
> + &cdev->desc.iSerialNumber);
> +}
> +
> 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 +1505,10 @@ static int composite_bind(struct usb_gadget *gadget)
>
> cdev->desc = *composite->dev;
>
> + /* grab overrides from devicetree */
> + if (np)
> + composite_parse_dt(cdev, np);
> +
> /* standardized runtime overrides for device ID data */
> if (idVendor)
> cdev->desc.idVendor = cpu_to_le16(idVendor);
> On 06/26/2012 09:27 AM, Alexandre Pereira da Silva wrote:
>> Grab the devicetree node properties to override VendorId, ProductId,
>> bcdDevice, Manucacturer, Product and SerialNumber
Like before, the code looks good to me:
Acked-by: Michal Nazarewicz <[email protected]>
Not commenting on the other aspects of the business logic though.
On Tue, 26 Jun 2012 20:43:03 +0200, Rob Herring <[email protected]> wrote:
> I'm still confused about what is the order of priority for the 2
> possible sources of these values. The way it is written, the DT value is
> a default, not an override.
They are overwritten by module parameter but they are overwriting anything that
composite gadget might be providing.
--
Best regards, _ _
.o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michał “mina86” Nazarewicz (o o)
ooo +----<email/xmpp: [email protected]>--------------ooO--(_)--Ooo--