aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget/f_obex.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/gadget/f_obex.c')
-rw-r--r--drivers/usb/gadget/f_obex.c75
1 files changed, 8 insertions, 67 deletions
diff --git a/drivers/usb/gadget/f_obex.c b/drivers/usb/gadget/f_obex.c
index 8aa2be5329bc..ad39f1dacba3 100644
--- a/drivers/usb/gadget/f_obex.c
+++ b/drivers/usb/gadget/f_obex.c
@@ -309,23 +309,20 @@ static int obex_bind(struct usb_configuration *c, struct usb_function *f)
309{ 309{
310 struct usb_composite_dev *cdev = c->cdev; 310 struct usb_composite_dev *cdev = c->cdev;
311 struct f_obex *obex = func_to_obex(f); 311 struct f_obex *obex = func_to_obex(f);
312 struct usb_string *us;
312 int status; 313 int status;
313 struct usb_ep *ep; 314 struct usb_ep *ep;
314 315
315 if (!can_support_obex(c)) 316 if (!can_support_obex(c))
316 return -EINVAL; 317 return -EINVAL;
317 318
318 if (obex_string_defs[OBEX_CTRL_IDX].id == 0) { 319 us = usb_gstrings_attach(cdev, obex_strings,
319 status = usb_string_ids_tab(c->cdev, obex_string_defs); 320 ARRAY_SIZE(obex_string_defs));
320 if (status < 0) 321 if (IS_ERR(us))
321 return status; 322 return PTR_ERR(us);
322 obex_control_intf.iInterface = 323 obex_control_intf.iInterface = us[OBEX_CTRL_IDX].id;
323 obex_string_defs[OBEX_CTRL_IDX].id; 324 obex_data_nop_intf.iInterface = us[OBEX_DATA_IDX].id;
324 325 obex_data_intf.iInterface = us[OBEX_DATA_IDX].id;
325 status = obex_string_defs[OBEX_DATA_IDX].id;
326 obex_data_nop_intf.iInterface = status;
327 obex_data_intf.iInterface = status;
328 }
329 326
330 /* allocate instance-specific interface IDs, and patch descriptors */ 327 /* allocate instance-specific interface IDs, and patch descriptors */
331 328
@@ -406,57 +403,6 @@ fail:
406 return status; 403 return status;
407} 404}
408 405
409#ifdef USBF_OBEX_INCLUDED
410
411static void
412obex_old_unbind(struct usb_configuration *c, struct usb_function *f)
413{
414 obex_string_defs[OBEX_CTRL_IDX].id = 0;
415 usb_free_all_descriptors(f);
416 kfree(func_to_obex(f));
417}
418
419/**
420 * obex_bind_config - add a CDC OBEX function to a configuration
421 * @c: the configuration to support the CDC OBEX instance
422 * @port_num: /dev/ttyGS* port this interface will use
423 * Context: single threaded during gadget setup
424 *
425 * Returns zero on success, else negative errno.
426 */
427int __init obex_bind_config(struct usb_configuration *c, u8 port_num)
428{
429 struct f_obex *obex;
430 int status;
431
432 /* allocate and initialize one new instance */
433 obex = kzalloc(sizeof *obex, GFP_KERNEL);
434 if (!obex)
435 return -ENOMEM;
436
437 obex->port_num = port_num;
438
439 obex->port.connect = obex_connect;
440 obex->port.disconnect = obex_disconnect;
441
442 obex->port.func.name = "obex";
443 obex->port.func.strings = obex_strings;
444 /* descriptors are per-instance copies */
445 obex->port.func.bind = obex_bind;
446 obex->port.func.unbind = obex_old_unbind;
447 obex->port.func.set_alt = obex_set_alt;
448 obex->port.func.get_alt = obex_get_alt;
449 obex->port.func.disable = obex_disable;
450
451 status = usb_add_function(c, &obex->port.func);
452 if (status)
453 kfree(obex);
454
455 return status;
456}
457
458#else
459
460static inline struct f_serial_opts *to_f_serial_opts(struct config_item *item) 406static inline struct f_serial_opts *to_f_serial_opts(struct config_item *item)
461{ 407{
462 return container_of(to_config_group(item), struct f_serial_opts, 408 return container_of(to_config_group(item), struct f_serial_opts,
@@ -550,7 +496,6 @@ static void obex_free(struct usb_function *f)
550 496
551static void obex_unbind(struct usb_configuration *c, struct usb_function *f) 497static void obex_unbind(struct usb_configuration *c, struct usb_function *f)
552{ 498{
553 obex_string_defs[OBEX_CTRL_IDX].id = 0;
554 usb_free_all_descriptors(f); 499 usb_free_all_descriptors(f);
555} 500}
556 501
@@ -572,7 +517,6 @@ struct usb_function *obex_alloc(struct usb_function_instance *fi)
572 obex->port.disconnect = obex_disconnect; 517 obex->port.disconnect = obex_disconnect;
573 518
574 obex->port.func.name = "obex"; 519 obex->port.func.name = "obex";
575 obex->port.func.strings = obex_strings;
576 /* descriptors are per-instance copies */ 520 /* descriptors are per-instance copies */
577 obex->port.func.bind = obex_bind; 521 obex->port.func.bind = obex_bind;
578 obex->port.func.unbind = obex_unbind; 522 obex->port.func.unbind = obex_unbind;
@@ -585,8 +529,5 @@ struct usb_function *obex_alloc(struct usb_function_instance *fi)
585} 529}
586 530
587DECLARE_USB_FUNCTION_INIT(obex, obex_alloc_inst, obex_alloc); 531DECLARE_USB_FUNCTION_INIT(obex, obex_alloc_inst, obex_alloc);
588
589#endif
590
591MODULE_AUTHOR("Felipe Balbi"); 532MODULE_AUTHOR("Felipe Balbi");
592MODULE_LICENSE("GPL"); 533MODULE_LICENSE("GPL");