diff options
author | Michal Nazarewicz <m.nazarewicz@samsung.com> | 2010-06-25 10:29:27 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-08-10 17:35:37 -0400 |
commit | f8dae531ec78ed34f8a845e5f4ff75f0adeb6b13 (patch) | |
tree | 6b51e0cb760b11887d1b16be6f964e9258c95122 /drivers/usb/gadget/g_ffs.c | |
parent | 541c7d432f76771079e7c295d596ea47cc6a3030 (diff) |
USB: gadget: g_fs: code cleanup
This commit cleans the g_fs gadget hopefully making it more
readable. This is achieved by usage of the usb_string_ids_tab()
function for batch string IDs registration as well as
generalising configuration so that a single routine is
used to add each configuration and bind interfaces. As an
effect, the code is shorter and has fewer #ifdefs.
Moreover, in some circumstances previous code #defined
CONFIG_USB_FUNCTIONFS_GENERIC macro to prevent a situation
where gadget with no configurations is built. This code removes
the #define form source code and achieves the same effect using
select in Kconfig.
This patch also changes wording and names of the Kconfig options.
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>
Diffstat (limited to 'drivers/usb/gadget/g_ffs.c')
-rw-r--r-- | drivers/usb/gadget/g_ffs.c | 174 |
1 files changed, 48 insertions, 126 deletions
diff --git a/drivers/usb/gadget/g_ffs.c b/drivers/usb/gadget/g_ffs.c index da3a9e403497..a9474f8d5325 100644 --- a/drivers/usb/gadget/g_ffs.c +++ b/drivers/usb/gadget/g_ffs.c | |||
@@ -32,12 +32,13 @@ | |||
32 | # include "u_ether.c" | 32 | # include "u_ether.c" |
33 | 33 | ||
34 | static u8 gfs_hostaddr[ETH_ALEN]; | 34 | static u8 gfs_hostaddr[ETH_ALEN]; |
35 | #else | 35 | # ifdef CONFIG_USB_FUNCTIONFS_ETH |
36 | # if !defined CONFIG_USB_FUNCTIONFS_GENERIC | 36 | static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); |
37 | # define CONFIG_USB_FUNCTIONFS_GENERIC | ||
38 | # endif | 37 | # endif |
38 | #else | ||
39 | # define gether_cleanup() do { } while (0) | 39 | # define gether_cleanup() do { } while (0) |
40 | # define gether_setup(gadget, hostaddr) ((int)0) | 40 | # define gether_setup(gadget, hostaddr) ((int)0) |
41 | # define gfs_hostaddr NULL | ||
41 | #endif | 42 | #endif |
42 | 43 | ||
43 | #include "f_fs.c" | 44 | #include "f_fs.c" |
@@ -107,15 +108,7 @@ static const struct usb_descriptor_header *gfs_otg_desc[] = { | |||
107 | enum { | 108 | enum { |
108 | GFS_STRING_MANUFACTURER_IDX, | 109 | GFS_STRING_MANUFACTURER_IDX, |
109 | GFS_STRING_PRODUCT_IDX, | 110 | GFS_STRING_PRODUCT_IDX, |
110 | #ifdef CONFIG_USB_FUNCTIONFS_RNDIS | 111 | GFS_STRING_FIRST_CONFIG_IDX, |
111 | GFS_STRING_RNDIS_CONFIG_IDX, | ||
112 | #endif | ||
113 | #ifdef CONFIG_USB_FUNCTIONFS_ETH | ||
114 | GFS_STRING_ECM_CONFIG_IDX, | ||
115 | #endif | ||
116 | #ifdef CONFIG_USB_FUNCTIONFS_GENERIC | ||
117 | GFS_STRING_GENERIC_CONFIG_IDX, | ||
118 | #endif | ||
119 | }; | 112 | }; |
120 | 113 | ||
121 | static char gfs_manufacturer[50]; | 114 | static char gfs_manufacturer[50]; |
@@ -126,13 +119,13 @@ static struct usb_string gfs_strings[] = { | |||
126 | [GFS_STRING_MANUFACTURER_IDX].s = gfs_manufacturer, | 119 | [GFS_STRING_MANUFACTURER_IDX].s = gfs_manufacturer, |
127 | [GFS_STRING_PRODUCT_IDX].s = gfs_driver_desc, | 120 | [GFS_STRING_PRODUCT_IDX].s = gfs_driver_desc, |
128 | #ifdef CONFIG_USB_FUNCTIONFS_RNDIS | 121 | #ifdef CONFIG_USB_FUNCTIONFS_RNDIS |
129 | [GFS_STRING_RNDIS_CONFIG_IDX].s = "FunctionFS + RNDIS", | 122 | { .s = "FunctionFS + RNDIS" }, |
130 | #endif | 123 | #endif |
131 | #ifdef CONFIG_USB_FUNCTIONFS_ETH | 124 | #ifdef CONFIG_USB_FUNCTIONFS_ETH |
132 | [GFS_STRING_ECM_CONFIG_IDX].s = "FunctionFS + ECM", | 125 | { .s = "FunctionFS + ECM" }, |
133 | #endif | 126 | #endif |
134 | #ifdef CONFIG_USB_FUNCTIONFS_GENERIC | 127 | #ifdef CONFIG_USB_FUNCTIONFS_GENERIC |
135 | [GFS_STRING_GENERIC_CONFIG_IDX].s = "FunctionFS", | 128 | { .s = "FunctionFS" }, |
136 | #endif | 129 | #endif |
137 | { } /* end of list */ | 130 | { } /* end of list */ |
138 | }; | 131 | }; |
@@ -146,59 +139,33 @@ static struct usb_gadget_strings *gfs_dev_strings[] = { | |||
146 | }; | 139 | }; |
147 | 140 | ||
148 | 141 | ||
142 | |||
143 | struct gfs_configuration { | ||
144 | struct usb_configuration c; | ||
145 | int (*eth)(struct usb_configuration *c, u8 *ethaddr); | ||
146 | } gfs_configurations[] = { | ||
149 | #ifdef CONFIG_USB_FUNCTIONFS_RNDIS | 147 | #ifdef CONFIG_USB_FUNCTIONFS_RNDIS |
150 | static int gfs_do_rndis_config(struct usb_configuration *c); | 148 | { |
151 | 149 | .eth = rndis_bind_config, | |
152 | static struct usb_configuration gfs_rndis_config_driver = { | 150 | }, |
153 | .label = "FunctionFS + RNDIS", | ||
154 | .bind = gfs_do_rndis_config, | ||
155 | .bConfigurationValue = 1, | ||
156 | /* .iConfiguration = DYNAMIC */ | ||
157 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, | ||
158 | }; | ||
159 | # define gfs_add_rndis_config(cdev) \ | ||
160 | usb_add_config(cdev, &gfs_rndis_config_driver) | ||
161 | #else | ||
162 | # define gfs_add_rndis_config(cdev) 0 | ||
163 | #endif | 151 | #endif |
164 | 152 | ||
165 | |||
166 | #ifdef CONFIG_USB_FUNCTIONFS_ETH | 153 | #ifdef CONFIG_USB_FUNCTIONFS_ETH |
167 | static int gfs_do_ecm_config(struct usb_configuration *c); | 154 | { |
168 | 155 | .eth = eth_bind_config, | |
169 | static struct usb_configuration gfs_ecm_config_driver = { | 156 | }, |
170 | .label = "FunctionFS + ECM", | ||
171 | .bind = gfs_do_ecm_config, | ||
172 | .bConfigurationValue = 1, | ||
173 | /* .iConfiguration = DYNAMIC */ | ||
174 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, | ||
175 | }; | ||
176 | # define gfs_add_ecm_config(cdev) \ | ||
177 | usb_add_config(cdev, &gfs_ecm_config_driver) | ||
178 | #else | ||
179 | # define gfs_add_ecm_config(cdev) 0 | ||
180 | #endif | 157 | #endif |
181 | 158 | ||
182 | |||
183 | #ifdef CONFIG_USB_FUNCTIONFS_GENERIC | 159 | #ifdef CONFIG_USB_FUNCTIONFS_GENERIC |
184 | static int gfs_do_generic_config(struct usb_configuration *c); | 160 | { |
185 | 161 | }, | |
186 | static struct usb_configuration gfs_generic_config_driver = { | ||
187 | .label = "FunctionFS", | ||
188 | .bind = gfs_do_generic_config, | ||
189 | .bConfigurationValue = 2, | ||
190 | /* .iConfiguration = DYNAMIC */ | ||
191 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, | ||
192 | }; | ||
193 | # define gfs_add_generic_config(cdev) \ | ||
194 | usb_add_config(cdev, &gfs_generic_config_driver) | ||
195 | #else | ||
196 | # define gfs_add_generic_config(cdev) 0 | ||
197 | #endif | 162 | #endif |
163 | }; | ||
198 | 164 | ||
199 | 165 | ||
200 | static int gfs_bind(struct usb_composite_dev *cdev); | 166 | static int gfs_bind(struct usb_composite_dev *cdev); |
201 | static int gfs_unbind(struct usb_composite_dev *cdev); | 167 | static int gfs_unbind(struct usb_composite_dev *cdev); |
168 | static int gfs_do_config(struct usb_configuration *c); | ||
202 | 169 | ||
203 | static struct usb_composite_driver gfs_driver = { | 170 | static struct usb_composite_driver gfs_driver = { |
204 | .name = gfs_short_name, | 171 | .name = gfs_short_name, |
@@ -267,7 +234,7 @@ static int functionfs_check_dev_callback(const char *dev_name) | |||
267 | 234 | ||
268 | static int gfs_bind(struct usb_composite_dev *cdev) | 235 | static int gfs_bind(struct usb_composite_dev *cdev) |
269 | { | 236 | { |
270 | int ret; | 237 | int ret, i; |
271 | 238 | ||
272 | ENTER(); | 239 | ENTER(); |
273 | 240 | ||
@@ -284,57 +251,32 @@ static int gfs_bind(struct usb_composite_dev *cdev) | |||
284 | snprintf(gfs_manufacturer, sizeof gfs_manufacturer, "%s %s with %s", | 251 | snprintf(gfs_manufacturer, sizeof gfs_manufacturer, "%s %s with %s", |
285 | init_utsname()->sysname, init_utsname()->release, | 252 | init_utsname()->sysname, init_utsname()->release, |
286 | cdev->gadget->name); | 253 | cdev->gadget->name); |
287 | ret = usb_string_id(cdev); | ||
288 | if (unlikely(ret < 0)) | ||
289 | goto error; | ||
290 | gfs_strings[GFS_STRING_MANUFACTURER_IDX].id = ret; | ||
291 | gfs_dev_desc.iManufacturer = ret; | ||
292 | |||
293 | ret = usb_string_id(cdev); | ||
294 | if (unlikely(ret < 0)) | ||
295 | goto error; | ||
296 | gfs_strings[GFS_STRING_PRODUCT_IDX].id = ret; | ||
297 | gfs_dev_desc.iProduct = ret; | ||
298 | |||
299 | #ifdef CONFIG_USB_FUNCTIONFS_RNDIS | ||
300 | ret = usb_string_id(cdev); | ||
301 | if (unlikely(ret < 0)) | ||
302 | goto error; | ||
303 | gfs_strings[GFS_STRING_RNDIS_CONFIG_IDX].id = ret; | ||
304 | gfs_rndis_config_driver.iConfiguration = ret; | ||
305 | #endif | ||
306 | 254 | ||
307 | #ifdef CONFIG_USB_FUNCTIONFS_ETH | 255 | ret = usb_string_ids_tab(cdev, gfs_strings); |
308 | ret = usb_string_id(cdev); | ||
309 | if (unlikely(ret < 0)) | 256 | if (unlikely(ret < 0)) |
310 | goto error; | 257 | goto error; |
311 | gfs_strings[GFS_STRING_ECM_CONFIG_IDX].id = ret; | ||
312 | gfs_ecm_config_driver.iConfiguration = ret; | ||
313 | #endif | ||
314 | 258 | ||
315 | #ifdef CONFIG_USB_FUNCTIONFS_GENERIC | 259 | gfs_dev_desc.iManufacturer = gfs_strings[GFS_STRING_MANUFACTURER_IDX].id; |
316 | ret = usb_string_id(cdev); | 260 | gfs_dev_desc.iProduct = gfs_strings[GFS_STRING_PRODUCT_IDX].id; |
317 | if (unlikely(ret < 0)) | ||
318 | goto error; | ||
319 | gfs_strings[GFS_STRING_GENERIC_CONFIG_IDX].id = ret; | ||
320 | gfs_generic_config_driver.iConfiguration = ret; | ||
321 | #endif | ||
322 | 261 | ||
323 | ret = functionfs_bind(gfs_ffs_data, cdev); | 262 | ret = functionfs_bind(gfs_ffs_data, cdev); |
324 | if (unlikely(ret < 0)) | 263 | if (unlikely(ret < 0)) |
325 | goto error; | 264 | goto error; |
326 | 265 | ||
327 | ret = gfs_add_rndis_config(cdev); | 266 | for (i = 0; i < ARRAY_SIZE(gfs_configurations); ++i) { |
328 | if (unlikely(ret < 0)) | 267 | struct gfs_configuration *c = gfs_configurations + i; |
329 | goto error_unbind; | ||
330 | 268 | ||
331 | ret = gfs_add_ecm_config(cdev); | 269 | ret = GFS_STRING_FIRST_CONFIG_IDX + i; |
332 | if (unlikely(ret < 0)) | 270 | c->c.label = gfs_strings[ret].s; |
333 | goto error_unbind; | 271 | c->c.iConfiguration = gfs_strings[ret].id; |
272 | c->c.bind = gfs_do_config; | ||
273 | c->c.bConfigurationValue = 1 + i; | ||
274 | c->c.bmAttributes = USB_CONFIG_ATT_SELFPOWER; | ||
334 | 275 | ||
335 | ret = gfs_add_generic_config(cdev); | 276 | ret = usb_add_config(cdev, &c->c); |
336 | if (unlikely(ret < 0)) | 277 | if (unlikely(ret < 0)) |
337 | goto error_unbind; | 278 | goto error_unbind; |
279 | } | ||
338 | 280 | ||
339 | return 0; | 281 | return 0; |
340 | 282 | ||
@@ -368,10 +310,10 @@ static int gfs_unbind(struct usb_composite_dev *cdev) | |||
368 | } | 310 | } |
369 | 311 | ||
370 | 312 | ||
371 | static int __gfs_do_config(struct usb_configuration *c, | 313 | static int gfs_do_config(struct usb_configuration *c) |
372 | int (*eth)(struct usb_configuration *c, u8 *ethaddr), | ||
373 | u8 *ethaddr) | ||
374 | { | 314 | { |
315 | struct gfs_configuration *gc = | ||
316 | container_of(c, struct gfs_configuration, c); | ||
375 | int ret; | 317 | int ret; |
376 | 318 | ||
377 | if (WARN_ON(!gfs_ffs_data)) | 319 | if (WARN_ON(!gfs_ffs_data)) |
@@ -382,8 +324,8 @@ static int __gfs_do_config(struct usb_configuration *c, | |||
382 | c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; | 324 | c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; |
383 | } | 325 | } |
384 | 326 | ||
385 | if (eth) { | 327 | if (gc->eth) { |
386 | ret = eth(c, ethaddr); | 328 | ret = gc->eth(c, gfs_hostaddr); |
387 | if (unlikely(ret < 0)) | 329 | if (unlikely(ret < 0)) |
388 | return ret; | 330 | return ret; |
389 | } | 331 | } |
@@ -406,32 +348,12 @@ static int __gfs_do_config(struct usb_configuration *c, | |||
406 | return 0; | 348 | return 0; |
407 | } | 349 | } |
408 | 350 | ||
409 | #ifdef CONFIG_USB_FUNCTIONFS_RNDIS | ||
410 | static int gfs_do_rndis_config(struct usb_configuration *c) | ||
411 | { | ||
412 | ENTER(); | ||
413 | |||
414 | return __gfs_do_config(c, rndis_bind_config, gfs_hostaddr); | ||
415 | } | ||
416 | #endif | ||
417 | 351 | ||
418 | #ifdef CONFIG_USB_FUNCTIONFS_ETH | 352 | #ifdef CONFIG_USB_FUNCTIONFS_ETH |
419 | static int gfs_do_ecm_config(struct usb_configuration *c) | 353 | static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) |
420 | { | ||
421 | ENTER(); | ||
422 | |||
423 | return __gfs_do_config(c, | ||
424 | can_support_ecm(c->cdev->gadget) | ||
425 | ? ecm_bind_config : geth_bind_config, | ||
426 | gfs_hostaddr); | ||
427 | } | ||
428 | #endif | ||
429 | |||
430 | #ifdef CONFIG_USB_FUNCTIONFS_GENERIC | ||
431 | static int gfs_do_generic_config(struct usb_configuration *c) | ||
432 | { | 354 | { |
433 | ENTER(); | 355 | return can_support_ecm(c->cdev->gadget) |
434 | 356 | ? ecm_bind_config(c, ethaddr) | |
435 | return __gfs_do_config(c, NULL, NULL); | 357 | : geth_bind_config(c, ethaddr); |
436 | } | 358 | } |
437 | #endif | 359 | #endif |