From b547e39d1482eeccf5a2b8f63151d2eb187aa85d Mon Sep 17 00:00:00 2001 From: Krzysztof Opasiak Date: Mon, 12 Sep 2016 22:19:31 +0200 Subject: [PATCH] usb: gadget: g_ffs: Allow to set bmAttributes of configuration 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 --- drivers/usb/gadget/g_ffs.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/g_ffs.c b/drivers/usb/gadget/g_ffs.c index 6576186..ee513fb 100644 --- a/drivers/usb/gadget/g_ffs.c +++ b/drivers/usb/gadget/g_ffs.c @@ -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; } -- 2.7.4