usb: gadget: g_ffs: Allow to set bmAttributes of configuration 36/88036/3 submit/tizen/20160920.104315
authorKrzysztof Opasiak <k.opasiak@samsung.com>
Mon, 12 Sep 2016 20:19:31 +0000 (22:19 +0200)
committerKrzysztof Opasiak <k.opasiak@samsung.com>
Tue, 20 Sep 2016 09:13:31 +0000 (11:13 +0200)
usb host tests expect configuration bmAttributes to have
a predefined value. As on 3.10 kernel we cannot use
ConfigFS to achieve this let's add a module parameter
which allows us to set it.

Change-Id: Iecf773d98c398ce1d3c529e7202155fb1e5e9ba6
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
drivers/usb/gadget/g_ffs.c

index 6576186..ee513fb 100644 (file)
@@ -137,6 +137,13 @@ module_param_named(generic_ffs_config_str,
 MODULE_PARM_DESC(generic_ffs_config_str,
                 "Configuration string of generic FFS config");
 #endif
+
+static int bmAttrs_overwrite = -1;
+
+module_param_named(bmAttrs_overwrite, bmAttrs_overwrite, int, 0644);
+MODULE_PARM_DESC(bmAttrs_overwrite,
+                "Overwrite default bmAttrributes value. -1 to use default.");
+
 static struct usb_gadget_strings *gfs_dev_strings[] = {
        &(struct usb_gadget_strings) {
                .language       = 0x0409,       /* en-us */
@@ -202,6 +209,11 @@ static int __init gfs_init(void)
                        break;
                }
 #endif
+       if (bmAttrs_overwrite > 255) {
+               pr_info("Invalid value of bmAttributes for configs.");
+               return -EINVAL;
+       }
+
        if (!func_num) {
                gfs_single_func = true;
                func_num = 1;
@@ -395,7 +407,9 @@ static int gfs_bind(struct usb_composite_dev *cdev)
                c->c.label                      = gfs_strings[sid].s;
                c->c.iConfiguration             = gfs_strings[sid].id;
                c->c.bConfigurationValue        = 1 + i;
-               c->c.bmAttributes               = USB_CONFIG_ATT_SELFPOWER;
+               c->c.bmAttributes               = bmAttrs_overwrite >= 0 ?
+                       (unsigned char)bmAttrs_overwrite
+                       : USB_CONFIG_ATT_SELFPOWER;
 
                ret = usb_add_config(cdev, &c->c, gfs_do_config);
                if (unlikely(ret < 0))
@@ -456,7 +470,7 @@ static int gfs_do_config(struct usb_configuration *c)
        if (missing_funcs)
                return -ENODEV;
 
-       if (gadget_is_otg(c->cdev->gadget)) {
+       if (gadget_is_otg(c->cdev->gadget) && bmAttrs_overwrite < 0) {
                c->descriptors = gfs_otg_desc;
                c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
        }