aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Nazarewicz <m.nazarewicz@samsung.com>2010-08-12 11:43:48 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2010-10-22 13:21:22 -0400
commitfc19de61ef5c17b6e19766052c6ac85cf31de876 (patch)
tree62c25db2b0792779226daa3141057808d494ae4f
parent9cfe745e652eacf57ffc7862b7b3ccbdf336ad19 (diff)
USB: gadget: functionfs: code cleanup
This patch removes some of the string registration from the FunctionFS Gadget as composite layer can handle the iManufacturer and iProduct for us. It also removes some of the module parameters which were redundant as well as changes the name of others to better much the module parameter of the composite layer. Other then that, it also fixes formatting of multiline comments to match the coding style. Signed-off-by: Michal Nazarewicz <m.nazarewicz@samsung.com> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--drivers/usb/gadget/g_ffs.c85
1 files changed, 28 insertions, 57 deletions
diff --git a/drivers/usb/gadget/g_ffs.c b/drivers/usb/gadget/g_ffs.c
index 3c2f0a43c9c6..52fd3fa0d130 100644
--- a/drivers/usb/gadget/g_ffs.c
+++ b/drivers/usb/gadget/g_ffs.c
@@ -52,9 +52,8 @@ MODULE_DESCRIPTION(DRIVER_DESC);
52MODULE_AUTHOR("Michal Nazarewicz"); 52MODULE_AUTHOR("Michal Nazarewicz");
53MODULE_LICENSE("GPL"); 53MODULE_LICENSE("GPL");
54 54
55 55#define GFS_VENDOR_ID 0x1d6b /* Linux Foundation */
56static unsigned short gfs_vendor_id = 0x1d6b; /* Linux Foundation */ 56#define GFS_PRODUCT_ID 0x0105 /* FunctionFS Gadget */
57static unsigned short gfs_product_id = 0x0105; /* FunctionFS Gadget */
58 57
59static struct usb_device_descriptor gfs_dev_desc = { 58static struct usb_device_descriptor gfs_dev_desc = {
60 .bLength = sizeof gfs_dev_desc, 59 .bLength = sizeof gfs_dev_desc,
@@ -63,29 +62,16 @@ static struct usb_device_descriptor gfs_dev_desc = {
63 .bcdUSB = cpu_to_le16(0x0200), 62 .bcdUSB = cpu_to_le16(0x0200),
64 .bDeviceClass = USB_CLASS_PER_INTERFACE, 63 .bDeviceClass = USB_CLASS_PER_INTERFACE,
65 64
66 /* Vendor and product id can be overridden by module parameters. */ 65 .idVendor = cpu_to_le16(GFS_VENDOR_ID),
67 /* .idVendor = cpu_to_le16(gfs_vendor_id), */ 66 .idProduct = cpu_to_le16(GFS_PRODUCT_ID),
68 /* .idProduct = cpu_to_le16(gfs_product_id), */
69 /* .bcdDevice = f(hardware) */
70 /* .iManufacturer = DYNAMIC */
71 /* .iProduct = DYNAMIC */
72 /* NO SERIAL NUMBER */
73 .bNumConfigurations = 1,
74}; 67};
75 68
76#define GFS_MODULE_PARAM_DESC(name, field) \ 69module_param_named(bDeviceClass, gfs_dev_desc.bDeviceClass, byte, 0644);
77 MODULE_PARM_DESC(name, "Value of the " #field " field of the device descriptor sent to the host. Takes effect only prior to the user-space driver registering to the FunctionFS.") 70MODULE_PARM_DESC(bDeviceClass, "USB Device class");
78 71module_param_named(bDeviceSubClass, gfs_dev_desc.bDeviceSubClass, byte, 0644);
79module_param_named(usb_class, gfs_dev_desc.bDeviceClass, byte, 0644); 72MODULE_PARM_DESC(bDeviceSubClass, "USB Device subclass");
80GFS_MODULE_PARAM_DESC(usb_class, bDeviceClass); 73module_param_named(bDeviceProtocol, gfs_dev_desc.bDeviceProtocol, byte, 0644);
81module_param_named(usb_subclass, gfs_dev_desc.bDeviceSubClass, byte, 0644); 74MODULE_PARM_DESC(bDeviceProtocol, "USB Device protocol");
82GFS_MODULE_PARAM_DESC(usb_subclass, bDeviceSubClass);
83module_param_named(usb_protocol, gfs_dev_desc.bDeviceProtocol, byte, 0644);
84GFS_MODULE_PARAM_DESC(usb_protocol, bDeviceProtocol);
85module_param_named(usb_vendor, gfs_vendor_id, ushort, 0644);
86GFS_MODULE_PARAM_DESC(usb_vendor, idVendor);
87module_param_named(usb_product, gfs_product_id, ushort, 0644);
88GFS_MODULE_PARAM_DESC(usb_product, idProduct);
89 75
90 76
91 77
@@ -95,8 +81,10 @@ static const struct usb_descriptor_header *gfs_otg_desc[] = {
95 .bLength = sizeof(struct usb_otg_descriptor), 81 .bLength = sizeof(struct usb_otg_descriptor),
96 .bDescriptorType = USB_DT_OTG, 82 .bDescriptorType = USB_DT_OTG,
97 83
98 /* REVISIT SRP-only hardware is possible, although 84 /*
99 * it would not be called "OTG" ... */ 85 * REVISIT SRP-only hardware is possible, although
86 * it would not be called "OTG" ...
87 */
100 .bmAttributes = USB_OTG_SRP | USB_OTG_HNP, 88 .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
101 }, 89 },
102 90
@@ -105,19 +93,7 @@ static const struct usb_descriptor_header *gfs_otg_desc[] = {
105 93
106/* string IDs are assigned dynamically */ 94/* string IDs are assigned dynamically */
107 95
108enum {
109 GFS_STRING_MANUFACTURER_IDX,
110 GFS_STRING_PRODUCT_IDX,
111 GFS_STRING_FIRST_CONFIG_IDX,
112};
113
114static char gfs_manufacturer[50];
115static const char gfs_driver_desc[] = DRIVER_DESC;
116static const char gfs_short_name[] = DRIVER_NAME;
117
118static struct usb_string gfs_strings[] = { 96static struct usb_string gfs_strings[] = {
119 [GFS_STRING_MANUFACTURER_IDX].s = gfs_manufacturer,
120 [GFS_STRING_PRODUCT_IDX].s = gfs_driver_desc,
121#ifdef CONFIG_USB_FUNCTIONFS_RNDIS 97#ifdef CONFIG_USB_FUNCTIONFS_RNDIS
122 { .s = "FunctionFS + RNDIS" }, 98 { .s = "FunctionFS + RNDIS" },
123#endif 99#endif
@@ -168,11 +144,12 @@ static int gfs_unbind(struct usb_composite_dev *cdev);
168static int gfs_do_config(struct usb_configuration *c); 144static int gfs_do_config(struct usb_configuration *c);
169 145
170static struct usb_composite_driver gfs_driver = { 146static struct usb_composite_driver gfs_driver = {
171 .name = gfs_short_name, 147 .name = DRIVER_NAME,
172 .dev = &gfs_dev_desc, 148 .dev = &gfs_dev_desc,
173 .strings = gfs_dev_strings, 149 .strings = gfs_dev_strings,
174 .bind = gfs_bind, 150 .bind = gfs_bind,
175 .unbind = gfs_unbind, 151 .unbind = gfs_unbind,
152 .iProduct = DRIVER_DESC,
176}; 153};
177 154
178 155
@@ -245,20 +222,10 @@ static int gfs_bind(struct usb_composite_dev *cdev)
245 if (unlikely(ret < 0)) 222 if (unlikely(ret < 0))
246 goto error_quick; 223 goto error_quick;
247 224
248 gfs_dev_desc.idVendor = cpu_to_le16(gfs_vendor_id);
249 gfs_dev_desc.idProduct = cpu_to_le16(gfs_product_id);
250
251 snprintf(gfs_manufacturer, sizeof gfs_manufacturer, "%s %s with %s",
252 init_utsname()->sysname, init_utsname()->release,
253 cdev->gadget->name);
254
255 ret = usb_string_ids_tab(cdev, gfs_strings); 225 ret = usb_string_ids_tab(cdev, gfs_strings);
256 if (unlikely(ret < 0)) 226 if (unlikely(ret < 0))
257 goto error; 227 goto error;
258 228
259 gfs_dev_desc.iManufacturer = gfs_strings[GFS_STRING_MANUFACTURER_IDX].id;
260 gfs_dev_desc.iProduct = gfs_strings[GFS_STRING_PRODUCT_IDX].id;
261
262 ret = functionfs_bind(gfs_ffs_data, cdev); 229 ret = functionfs_bind(gfs_ffs_data, cdev);
263 if (unlikely(ret < 0)) 230 if (unlikely(ret < 0))
264 goto error; 231 goto error;
@@ -266,9 +233,8 @@ static int gfs_bind(struct usb_composite_dev *cdev)
266 for (i = 0; i < ARRAY_SIZE(gfs_configurations); ++i) { 233 for (i = 0; i < ARRAY_SIZE(gfs_configurations); ++i) {
267 struct gfs_configuration *c = gfs_configurations + i; 234 struct gfs_configuration *c = gfs_configurations + i;
268 235
269 ret = GFS_STRING_FIRST_CONFIG_IDX + i; 236 c->c.label = gfs_strings[i].s;
270 c->c.label = gfs_strings[ret].s; 237 c->c.iConfiguration = gfs_strings[i].id;
271 c->c.iConfiguration = gfs_strings[ret].id;
272 c->c.bind = gfs_do_config; 238 c->c.bind = gfs_do_config;
273 c->c.bConfigurationValue = 1 + i; 239 c->c.bConfigurationValue = 1 + i;
274 c->c.bmAttributes = USB_CONFIG_ATT_SELFPOWER; 240 c->c.bmAttributes = USB_CONFIG_ATT_SELFPOWER;
@@ -293,13 +259,14 @@ static int gfs_unbind(struct usb_composite_dev *cdev)
293{ 259{
294 ENTER(); 260 ENTER();
295 261
296 /* We may have been called in an error recovery frem 262 /*
263 * We may have been called in an error recovery from
297 * composite_bind() after gfs_unbind() failure so we need to 264 * composite_bind() after gfs_unbind() failure so we need to
298 * check if gfs_ffs_data is not NULL since gfs_bind() handles 265 * check if gfs_ffs_data is not NULL since gfs_bind() handles
299 * all error recovery itself. I'd rather we werent called 266 * all error recovery itself. I'd rather we werent called
300 * from composite on orror recovery, but what you're gonna 267 * from composite on orror recovery, but what you're gonna
301 * do...? */ 268 * do...?
302 269 */
303 if (gfs_ffs_data) { 270 if (gfs_ffs_data) {
304 gether_cleanup(); 271 gether_cleanup();
305 functionfs_unbind(gfs_ffs_data); 272 functionfs_unbind(gfs_ffs_data);
@@ -334,14 +301,16 @@ static int gfs_do_config(struct usb_configuration *c)
334 if (unlikely(ret < 0)) 301 if (unlikely(ret < 0))
335 return ret; 302 return ret;
336 303
337 /* After previous do_configs there may be some invalid 304 /*
305 * After previous do_configs there may be some invalid
338 * pointers in c->interface array. This happens every time 306 * pointers in c->interface array. This happens every time
339 * a user space function with fewer interfaces than a user 307 * a user space function with fewer interfaces than a user
340 * space function that was run before the new one is run. The 308 * space function that was run before the new one is run. The
341 * compasit's set_config() assumes that if there is no more 309 * compasit's set_config() assumes that if there is no more
342 * then MAX_CONFIG_INTERFACES interfaces in a configuration 310 * then MAX_CONFIG_INTERFACES interfaces in a configuration
343 * then there is a NULL pointer after the last interface in 311 * then there is a NULL pointer after the last interface in
344 * c->interface array. We need to make sure this is true. */ 312 * c->interface array. We need to make sure this is true.
313 */
345 if (c->next_interface_id < ARRAY_SIZE(c->interface)) 314 if (c->next_interface_id < ARRAY_SIZE(c->interface))
346 c->interface[c->next_interface_id] = NULL; 315 c->interface[c->next_interface_id] = NULL;
347 316
@@ -350,10 +319,12 @@ static int gfs_do_config(struct usb_configuration *c)
350 319
351 320
352#ifdef CONFIG_USB_FUNCTIONFS_ETH 321#ifdef CONFIG_USB_FUNCTIONFS_ETH
322
353static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) 323static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
354{ 324{
355 return can_support_ecm(c->cdev->gadget) 325 return can_support_ecm(c->cdev->gadget)
356 ? ecm_bind_config(c, ethaddr) 326 ? ecm_bind_config(c, ethaddr)
357 : geth_bind_config(c, ethaddr); 327 : geth_bind_config(c, ethaddr);
358} 328}
329
359#endif 330#endif