From patchwork Tue Jun 26 14:27:13 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Pereira da Silva X-Patchwork-Id: 167416 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [IPv6:::1]) by ozlabs.org (Postfix) with ESMTP id BEF22B7069 for ; Wed, 27 Jun 2012 00:38:48 +1000 (EST) Received: from mail-gh0-f179.google.com (mail-gh0-f179.google.com [209.85.160.179]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id EE735B6EE9; Wed, 27 Jun 2012 00:27:42 +1000 (EST) Received: by mail-gh0-f179.google.com with SMTP id g24so3797085ghb.38 for ; Tue, 26 Jun 2012 07:27:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:x-mailer:in-reply-to:references; bh=I2GOpB2nmyNSen9D1XLLRXJyf0Y3sNYN3ZIND6lm99w=; b=EvcZcuyVrCoxxYRmUQstNeGtzouvgxGYXf/dWDuc6Vpjmm6OMtbkxOHGpqRss5T/t2 vwkUzxcSSYz3vafVlb6WaoYclcAvYHwgmOkoGdGMmOsgHlwX5QbCcZ2uV0Cz6LtHMmYU pEB6RVHbsKlbeGyDh7qYabeB3Tui+RbnskgF1enGkNio8Yl6iqV8bqHfv+ocj23EW+lY dKTkOLmnHEelWA+qHkb9IclliidckvQXlJY/nVz2DuYpdagyqcz97uQHl+vKf870bJp/ 8ARlhdI5DDEhbp4f1ISdMvRH+IAYPrVTOECLXu0cIwYyrvQ2SSm3EEmRAfPIeqodj5fK qw4w== Received: by 10.236.76.133 with SMTP id b5mr18067109yhe.91.1340720862516; Tue, 26 Jun 2012 07:27:42 -0700 (PDT) Received: from localhost.localdomain (c934e329.virtua.com.br. [201.52.227.41]) by mx.google.com with ESMTPS id c28sm104164811yhk.2.2012.06.26.07.27.39 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 26 Jun 2012 07:27:41 -0700 (PDT) From: Alexandre Pereira da Silva To: Grant Likely , Rob Herring , Rob Landley , Felipe Balbi , Greg Kroah-Hartman , Li Yang , Alexandre Pereira da Silva , devicetree-discuss@lists.ozlabs.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Roland Stigge Subject: [PATCH 5/5] usb: gadget: composite: parse dt overrides Date: Tue, 26 Jun 2012 11:27:13 -0300 Message-Id: <1340720833-781-6-git-send-email-aletes.xgr@gmail.com> X-Mailer: git-send-email 1.7.10 In-Reply-To: <1340720833-781-1-git-send-email-aletes.xgr@gmail.com> References: <1340720833-781-1-git-send-email-aletes.xgr@gmail.com> X-Mailman-Approved-At: Wed, 27 Jun 2012 00:31:27 +1000 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.15rc1 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Grab the devicetree node properties to override VendorId, ProductId, bcdDevice, Manucacturer, Product and SerialNumber Signed-off-by: Alexandre Pereira da Silva Acked-by: Michal Nazarewicz Acked-by: Rob Herring --- 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 #include #include +#include #include #include @@ -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);