usb, g_dnl: make iSerialNumber board configurable
authorHeiko Schocher <hs@denx.de>
Mon, 4 Nov 2013 13:05:01 +0000 (14:05 +0100)
committerChanho Park <chanho61.park@samsung.com>
Fri, 24 Jul 2015 07:29:51 +0000 (16:29 +0900)
add the possibility to set the iSerialNumber board specific.
Default value for iSerialNumber is 0x0. This value can
changed board specific through the new function
g_dnl_set_serialnumber() which must be called from the
board specific function g_dnl_bind_fixup().

Signed-off-by: Heiko Schocher <hs@denx.de>
Cc: Marek Vasut <marek.vasut@gmail.com>
Cc: Lukasz Majewski <l.majewski@samsung.com>
Cc: Kyungmin Park <kyungmin.park@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
drivers/usb/gadget/g_dnl.c
include/g_dnl.h

index 15239d98955b92c6521591a320ffcae202f61f23..83ea9dfcda57f90b85c40e859273d335a0f7529d 100644 (file)
@@ -45,6 +45,9 @@
 #define STRING_PRODUCT 2
 /* Index of String Descriptor describing this configuration */
 #define STRING_USBDOWN 2
+/* Index of String serial */
+#define STRING_SERIAL  3
+#define MAX_STRING_SERIAL      32
 /* Number of supported configurations */
 #define CONFIGURATION_NUMBER 1
 
 
 static const char shortname[] = "usb_dnl_";
 static const char product[] = "USB download gadget";
+static char g_dnl_serial[MAX_STRING_SERIAL];
 static const char manufacturer[] = CONFIG_G_DNL_MANUFACTURER;
 
+void g_dnl_set_serialnumber(char *s)
+{
+       memset(g_dnl_serial, 0, MAX_STRING_SERIAL);
+       if (strlen(s) < MAX_STRING_SERIAL)
+               strncpy(g_dnl_serial, s, strlen(s));
+}
+
 static struct usb_device_descriptor device_desc = {
        .bLength = sizeof device_desc,
        .bDescriptorType = USB_DT_DEVICE,
@@ -65,6 +76,7 @@ static struct usb_device_descriptor device_desc = {
        .idVendor = __constant_cpu_to_le16(CONFIG_G_DNL_VENDOR_NUM),
        .idProduct = __constant_cpu_to_le16(CONFIG_G_DNL_PRODUCT_NUM),
        .iProduct = STRING_PRODUCT,
+       .iSerialNumber = STRING_SERIAL,
        .bNumConfigurations = 1,
 };
 
@@ -75,6 +87,7 @@ static struct usb_device_descriptor device_desc = {
 static struct usb_string g_dnl_string_defs[] = {
        {.s = manufacturer},
        {.s = product},
+       {.s = g_dnl_serial},
        { }             /* end of list */
 };
 
@@ -168,6 +181,13 @@ static int g_dnl_bind(struct usb_composite_dev *cdev)
        g_dnl_string_defs[1].id = id;
        device_desc.iProduct = id;
 
+       id = usb_string_id(cdev);
+       if (id < 0)
+               return id;
+
+       g_dnl_string_defs[2].id = id;
+       device_desc.iSerialNumber = id;
+
        g_dnl_bind_fixup(&device_desc, cdev->driver->name);
        ret = g_dnl_config_register(cdev);
        if (ret)
index 01e32e36aee3edb75ab6182ceae4b848ef5af6e2..91ee52eb5f80ea475dc930e77ea761aac88f0fc6 100644 (file)
@@ -26,6 +26,7 @@
 int g_dnl_bind_fixup(struct usb_device_descriptor *, const char *);
 int g_dnl_register(const char *s);
 void g_dnl_unregister(void);
+void g_dnl_set_serialnumber(char *);
 
 /* USB initialization declaration - board specific */
 void board_usb_init(void);