aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorAndrzej Pietrasiewicz <andrzej.p@samsung.com>2013-03-21 10:33:42 -0400
committerFelipe Balbi <balbi@ti.com>2013-04-03 07:43:35 -0400
commit1d8fc2518c1cddef0902b0a2c51946732a0982fc (patch)
tree82c5c070b7fc699c7f1dad0de2ef37b000357ab9 /drivers
parent0b6a1e6ff7e62a1ab5a8924bffb12c17c183308a (diff)
usb: gadget: f_obex: convert to new function interface with backward compatibility
Converting f_obex to the new function interface requires converting the f_obex's function code and its users. This patch converts the f_obex.c to the new function interface. The file is now compiled into a separate usb_f_obex.ko module. The old function interface is provided by means of preprocessor conditional directives. After all users are converted, the old interface can be removed. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@samsung.com> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com> Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/usb/gadget/Kconfig3
-rw-r--r--drivers/usb/gadget/Makefile2
-rw-r--r--drivers/usb/gadget/f_obex.c171
-rw-r--r--drivers/usb/gadget/nokia.c2
-rw-r--r--drivers/usb/gadget/serial.c1
5 files changed, 132 insertions, 47 deletions
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 93217fc86c12..a5f67e14daf2 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -508,6 +508,9 @@ config USB_U_SERIAL
508config USB_F_SERIAL 508config USB_F_SERIAL
509 tristate 509 tristate
510 510
511config USB_F_OBEX
512 tristate
513
511choice 514choice
512 tristate "USB Gadget Drivers" 515 tristate "USB Gadget Drivers"
513 default USB_ETH 516 default USB_ETH
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 34bb49a131e9..6afd16659e78 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -43,6 +43,8 @@ obj-$(CONFIG_USB_F_SS_LB) += usb_f_ss_lb.o
43obj-$(CONFIG_USB_U_SERIAL) += u_serial.o 43obj-$(CONFIG_USB_U_SERIAL) += u_serial.o
44usb_f_serial-y := f_serial.o 44usb_f_serial-y := f_serial.o
45obj-$(CONFIG_USB_F_SERIAL) += usb_f_serial.o 45obj-$(CONFIG_USB_F_SERIAL) += usb_f_serial.o
46usb_f_obex-y := f_obex.o
47obj-$(CONFIG_USB_F_OBEX) += usb_f_obex.o
46 48
47# 49#
48# USB gadget drivers 50# USB gadget drivers
diff --git a/drivers/usb/gadget/f_obex.c b/drivers/usb/gadget/f_obex.c
index 36a004563b82..439b666120c2 100644
--- a/drivers/usb/gadget/f_obex.c
+++ b/drivers/usb/gadget/f_obex.c
@@ -72,7 +72,7 @@ static struct usb_gadget_strings *obex_strings[] = {
72 72
73/*-------------------------------------------------------------------------*/ 73/*-------------------------------------------------------------------------*/
74 74
75static struct usb_interface_descriptor obex_control_intf __initdata = { 75static struct usb_interface_descriptor obex_control_intf = {
76 .bLength = sizeof(obex_control_intf), 76 .bLength = sizeof(obex_control_intf),
77 .bDescriptorType = USB_DT_INTERFACE, 77 .bDescriptorType = USB_DT_INTERFACE,
78 .bInterfaceNumber = 0, 78 .bInterfaceNumber = 0,
@@ -83,7 +83,7 @@ static struct usb_interface_descriptor obex_control_intf __initdata = {
83 .bInterfaceSubClass = USB_CDC_SUBCLASS_OBEX, 83 .bInterfaceSubClass = USB_CDC_SUBCLASS_OBEX,
84}; 84};
85 85
86static struct usb_interface_descriptor obex_data_nop_intf __initdata = { 86static struct usb_interface_descriptor obex_data_nop_intf = {
87 .bLength = sizeof(obex_data_nop_intf), 87 .bLength = sizeof(obex_data_nop_intf),
88 .bDescriptorType = USB_DT_INTERFACE, 88 .bDescriptorType = USB_DT_INTERFACE,
89 .bInterfaceNumber = 1, 89 .bInterfaceNumber = 1,
@@ -93,7 +93,7 @@ static struct usb_interface_descriptor obex_data_nop_intf __initdata = {
93 .bInterfaceClass = USB_CLASS_CDC_DATA, 93 .bInterfaceClass = USB_CLASS_CDC_DATA,
94}; 94};
95 95
96static struct usb_interface_descriptor obex_data_intf __initdata = { 96static struct usb_interface_descriptor obex_data_intf = {
97 .bLength = sizeof(obex_data_intf), 97 .bLength = sizeof(obex_data_intf),
98 .bDescriptorType = USB_DT_INTERFACE, 98 .bDescriptorType = USB_DT_INTERFACE,
99 .bInterfaceNumber = 2, 99 .bInterfaceNumber = 2,
@@ -103,14 +103,14 @@ static struct usb_interface_descriptor obex_data_intf __initdata = {
103 .bInterfaceClass = USB_CLASS_CDC_DATA, 103 .bInterfaceClass = USB_CLASS_CDC_DATA,
104}; 104};
105 105
106static struct usb_cdc_header_desc obex_cdc_header_desc __initdata = { 106static struct usb_cdc_header_desc obex_cdc_header_desc = {
107 .bLength = sizeof(obex_cdc_header_desc), 107 .bLength = sizeof(obex_cdc_header_desc),
108 .bDescriptorType = USB_DT_CS_INTERFACE, 108 .bDescriptorType = USB_DT_CS_INTERFACE,
109 .bDescriptorSubType = USB_CDC_HEADER_TYPE, 109 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
110 .bcdCDC = cpu_to_le16(0x0120), 110 .bcdCDC = cpu_to_le16(0x0120),
111}; 111};
112 112
113static struct usb_cdc_union_desc obex_cdc_union_desc __initdata = { 113static struct usb_cdc_union_desc obex_cdc_union_desc = {
114 .bLength = sizeof(obex_cdc_union_desc), 114 .bLength = sizeof(obex_cdc_union_desc),
115 .bDescriptorType = USB_DT_CS_INTERFACE, 115 .bDescriptorType = USB_DT_CS_INTERFACE,
116 .bDescriptorSubType = USB_CDC_UNION_TYPE, 116 .bDescriptorSubType = USB_CDC_UNION_TYPE,
@@ -118,7 +118,7 @@ static struct usb_cdc_union_desc obex_cdc_union_desc __initdata = {
118 .bSlaveInterface0 = 2, 118 .bSlaveInterface0 = 2,
119}; 119};
120 120
121static struct usb_cdc_obex_desc obex_desc __initdata = { 121static struct usb_cdc_obex_desc obex_desc = {
122 .bLength = sizeof(obex_desc), 122 .bLength = sizeof(obex_desc),
123 .bDescriptorType = USB_DT_CS_INTERFACE, 123 .bDescriptorType = USB_DT_CS_INTERFACE,
124 .bDescriptorSubType = USB_CDC_OBEX_TYPE, 124 .bDescriptorSubType = USB_CDC_OBEX_TYPE,
@@ -127,7 +127,7 @@ static struct usb_cdc_obex_desc obex_desc __initdata = {
127 127
128/* High-Speed Support */ 128/* High-Speed Support */
129 129
130static struct usb_endpoint_descriptor obex_hs_ep_out_desc __initdata = { 130static struct usb_endpoint_descriptor obex_hs_ep_out_desc = {
131 .bLength = USB_DT_ENDPOINT_SIZE, 131 .bLength = USB_DT_ENDPOINT_SIZE,
132 .bDescriptorType = USB_DT_ENDPOINT, 132 .bDescriptorType = USB_DT_ENDPOINT,
133 133
@@ -136,7 +136,7 @@ static struct usb_endpoint_descriptor obex_hs_ep_out_desc __initdata = {
136 .wMaxPacketSize = cpu_to_le16(512), 136 .wMaxPacketSize = cpu_to_le16(512),
137}; 137};
138 138
139static struct usb_endpoint_descriptor obex_hs_ep_in_desc __initdata = { 139static struct usb_endpoint_descriptor obex_hs_ep_in_desc = {
140 .bLength = USB_DT_ENDPOINT_SIZE, 140 .bLength = USB_DT_ENDPOINT_SIZE,
141 .bDescriptorType = USB_DT_ENDPOINT, 141 .bDescriptorType = USB_DT_ENDPOINT,
142 142
@@ -145,7 +145,7 @@ static struct usb_endpoint_descriptor obex_hs_ep_in_desc __initdata = {
145 .wMaxPacketSize = cpu_to_le16(512), 145 .wMaxPacketSize = cpu_to_le16(512),
146}; 146};
147 147
148static struct usb_descriptor_header *hs_function[] __initdata = { 148static struct usb_descriptor_header *hs_function[] = {
149 (struct usb_descriptor_header *) &obex_control_intf, 149 (struct usb_descriptor_header *) &obex_control_intf,
150 (struct usb_descriptor_header *) &obex_cdc_header_desc, 150 (struct usb_descriptor_header *) &obex_cdc_header_desc,
151 (struct usb_descriptor_header *) &obex_desc, 151 (struct usb_descriptor_header *) &obex_desc,
@@ -160,7 +160,7 @@ static struct usb_descriptor_header *hs_function[] __initdata = {
160 160
161/* Full-Speed Support */ 161/* Full-Speed Support */
162 162
163static struct usb_endpoint_descriptor obex_fs_ep_in_desc __initdata = { 163static struct usb_endpoint_descriptor obex_fs_ep_in_desc = {
164 .bLength = USB_DT_ENDPOINT_SIZE, 164 .bLength = USB_DT_ENDPOINT_SIZE,
165 .bDescriptorType = USB_DT_ENDPOINT, 165 .bDescriptorType = USB_DT_ENDPOINT,
166 166
@@ -168,7 +168,7 @@ static struct usb_endpoint_descriptor obex_fs_ep_in_desc __initdata = {
168 .bmAttributes = USB_ENDPOINT_XFER_BULK, 168 .bmAttributes = USB_ENDPOINT_XFER_BULK,
169}; 169};
170 170
171static struct usb_endpoint_descriptor obex_fs_ep_out_desc __initdata = { 171static struct usb_endpoint_descriptor obex_fs_ep_out_desc = {
172 .bLength = USB_DT_ENDPOINT_SIZE, 172 .bLength = USB_DT_ENDPOINT_SIZE,
173 .bDescriptorType = USB_DT_ENDPOINT, 173 .bDescriptorType = USB_DT_ENDPOINT,
174 174
@@ -176,7 +176,7 @@ static struct usb_endpoint_descriptor obex_fs_ep_out_desc __initdata = {
176 .bmAttributes = USB_ENDPOINT_XFER_BULK, 176 .bmAttributes = USB_ENDPOINT_XFER_BULK,
177}; 177};
178 178
179static struct usb_descriptor_header *fs_function[] __initdata = { 179static struct usb_descriptor_header *fs_function[] = {
180 (struct usb_descriptor_header *) &obex_control_intf, 180 (struct usb_descriptor_header *) &obex_control_intf,
181 (struct usb_descriptor_header *) &obex_cdc_header_desc, 181 (struct usb_descriptor_header *) &obex_cdc_header_desc,
182 (struct usb_descriptor_header *) &obex_desc, 182 (struct usb_descriptor_header *) &obex_desc,
@@ -290,14 +290,43 @@ static void obex_disconnect(struct gserial *g)
290 290
291/*-------------------------------------------------------------------------*/ 291/*-------------------------------------------------------------------------*/
292 292
293static int __init 293/* Some controllers can't support CDC OBEX ... */
294obex_bind(struct usb_configuration *c, struct usb_function *f) 294static inline bool can_support_obex(struct usb_configuration *c)
295{
296 /* Since the first interface is a NOP, we can ignore the
297 * issue of multi-interface support on most controllers.
298 *
299 * Altsettings are mandatory, however...
300 */
301 if (!gadget_supports_altsettings(c->cdev->gadget))
302 return false;
303
304 /* everything else is *probably* fine ... */
305 return true;
306}
307
308static int obex_bind(struct usb_configuration *c, struct usb_function *f)
295{ 309{
296 struct usb_composite_dev *cdev = c->cdev; 310 struct usb_composite_dev *cdev = c->cdev;
297 struct f_obex *obex = func_to_obex(f); 311 struct f_obex *obex = func_to_obex(f);
298 int status; 312 int status;
299 struct usb_ep *ep; 313 struct usb_ep *ep;
300 314
315 if (!can_support_obex(c))
316 return -EINVAL;
317
318 if (obex_string_defs[OBEX_CTRL_IDX].id == 0) {
319 status = usb_string_ids_tab(c->cdev, obex_string_defs);
320 if (status < 0)
321 return status;
322 obex_control_intf.iInterface =
323 obex_string_defs[OBEX_CTRL_IDX].id;
324
325 status = obex_string_defs[OBEX_DATA_IDX].id;
326 obex_data_nop_intf.iInterface = status;
327 obex_data_intf.iInterface = status;
328 }
329
301 /* allocate instance-specific interface IDs, and patch descriptors */ 330 /* allocate instance-specific interface IDs, and patch descriptors */
302 331
303 status = usb_interface_id(c, f); 332 status = usb_interface_id(c, f);
@@ -376,29 +405,16 @@ fail:
376 return status; 405 return status;
377} 406}
378 407
408#ifdef USBF_OBEX_INCLUDED
409
379static void 410static void
380obex_unbind(struct usb_configuration *c, struct usb_function *f) 411obex_old_unbind(struct usb_configuration *c, struct usb_function *f)
381{ 412{
382 obex_string_defs[OBEX_CTRL_IDX].id = 0; 413 obex_string_defs[OBEX_CTRL_IDX].id = 0;
383 usb_free_all_descriptors(f); 414 usb_free_all_descriptors(f);
384 kfree(func_to_obex(f)); 415 kfree(func_to_obex(f));
385} 416}
386 417
387/* Some controllers can't support CDC OBEX ... */
388static inline bool can_support_obex(struct usb_configuration *c)
389{
390 /* Since the first interface is a NOP, we can ignore the
391 * issue of multi-interface support on most controllers.
392 *
393 * Altsettings are mandatory, however...
394 */
395 if (!gadget_supports_altsettings(c->cdev->gadget))
396 return false;
397
398 /* everything else is *probably* fine ... */
399 return true;
400}
401
402/** 418/**
403 * obex_bind_config - add a CDC OBEX function to a configuration 419 * obex_bind_config - add a CDC OBEX function to a configuration
404 * @c: the configuration to support the CDC OBEX instance 420 * @c: the configuration to support the CDC OBEX instance
@@ -412,21 +428,6 @@ int __init obex_bind_config(struct usb_configuration *c, u8 port_num)
412 struct f_obex *obex; 428 struct f_obex *obex;
413 int status; 429 int status;
414 430
415 if (!can_support_obex(c))
416 return -EINVAL;
417
418 if (obex_string_defs[OBEX_CTRL_IDX].id == 0) {
419 status = usb_string_ids_tab(c->cdev, obex_string_defs);
420 if (status < 0)
421 return status;
422 obex_control_intf.iInterface =
423 obex_string_defs[OBEX_CTRL_IDX].id;
424
425 status = obex_string_defs[OBEX_DATA_IDX].id;
426 obex_data_nop_intf.iInterface = status;
427 obex_data_intf.iInterface = status;
428 }
429
430 /* allocate and initialize one new instance */ 431 /* allocate and initialize one new instance */
431 obex = kzalloc(sizeof *obex, GFP_KERNEL); 432 obex = kzalloc(sizeof *obex, GFP_KERNEL);
432 if (!obex) 433 if (!obex)
@@ -441,7 +442,7 @@ int __init obex_bind_config(struct usb_configuration *c, u8 port_num)
441 obex->port.func.strings = obex_strings; 442 obex->port.func.strings = obex_strings;
442 /* descriptors are per-instance copies */ 443 /* descriptors are per-instance copies */
443 obex->port.func.bind = obex_bind; 444 obex->port.func.bind = obex_bind;
444 obex->port.func.unbind = obex_unbind; 445 obex->port.func.unbind = obex_old_unbind;
445 obex->port.func.set_alt = obex_set_alt; 446 obex->port.func.set_alt = obex_set_alt;
446 obex->port.func.get_alt = obex_get_alt; 447 obex->port.func.get_alt = obex_get_alt;
447 obex->port.func.disable = obex_disable; 448 obex->port.func.disable = obex_disable;
@@ -453,5 +454,83 @@ int __init obex_bind_config(struct usb_configuration *c, u8 port_num)
453 return status; 454 return status;
454} 455}
455 456
457#else
458
459static void obex_free_inst(struct usb_function_instance *f)
460{
461 struct f_serial_opts *opts;
462
463 opts = container_of(f, struct f_serial_opts, func_inst);
464 gserial_free_line(opts->port_num);
465 kfree(opts);
466}
467
468static struct usb_function_instance *obex_alloc_inst(void)
469{
470 struct f_serial_opts *opts;
471 int ret;
472
473 opts = kzalloc(sizeof(*opts), GFP_KERNEL);
474 if (!opts)
475 return ERR_PTR(-ENOMEM);
476
477 opts->func_inst.free_func_inst = obex_free_inst;
478 ret = gserial_alloc_line(&opts->port_num);
479 if (ret) {
480 kfree(opts);
481 return ERR_PTR(ret);
482 }
483
484 return &opts->func_inst;
485}
486
487static void obex_free(struct usb_function *f)
488{
489 struct f_obex *obex;
490
491 obex = func_to_obex(f);
492 kfree(obex);
493}
494
495static void obex_unbind(struct usb_configuration *c, struct usb_function *f)
496{
497 obex_string_defs[OBEX_CTRL_IDX].id = 0;
498 usb_free_all_descriptors(f);
499}
500
501struct usb_function *obex_alloc(struct usb_function_instance *fi)
502{
503 struct f_obex *obex;
504 struct f_serial_opts *opts;
505
506 /* allocate and initialize one new instance */
507 obex = kzalloc(sizeof(*obex), GFP_KERNEL);
508 if (!obex)
509 return ERR_PTR(-ENOMEM);
510
511 opts = container_of(fi, struct f_serial_opts, func_inst);
512
513 obex->port_num = opts->port_num;
514
515 obex->port.connect = obex_connect;
516 obex->port.disconnect = obex_disconnect;
517
518 obex->port.func.name = "obex";
519 obex->port.func.strings = obex_strings;
520 /* descriptors are per-instance copies */
521 obex->port.func.bind = obex_bind;
522 obex->port.func.unbind = obex_unbind;
523 obex->port.func.set_alt = obex_set_alt;
524 obex->port.func.get_alt = obex_get_alt;
525 obex->port.func.disable = obex_disable;
526 obex->port.func.free_func = obex_free;
527
528 return &obex->port.func;
529}
530
531DECLARE_USB_FUNCTION_INIT(obex, obex_alloc_inst, obex_alloc);
532
533#endif
534
456MODULE_AUTHOR("Felipe Balbi"); 535MODULE_AUTHOR("Felipe Balbi");
457MODULE_LICENSE("GPL"); 536MODULE_LICENSE("GPL");
diff --git a/drivers/usb/gadget/nokia.c b/drivers/usb/gadget/nokia.c
index f829a80f27f6..eebdd0e0b1d6 100644
--- a/drivers/usb/gadget/nokia.c
+++ b/drivers/usb/gadget/nokia.c
@@ -37,7 +37,7 @@
37 * the runtime footprint, and giving us at least some parts of what 37 * the runtime footprint, and giving us at least some parts of what
38 * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 38 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
39 */ 39 */
40#include "f_ecm.c" 40#define USBF_OBEX_INCLUDED
41#include "f_obex.c" 41#include "f_obex.c"
42#include "f_phonet.c" 42#include "f_phonet.c"
43#include "u_ether.c" 43#include "u_ether.c"
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index 9d215c4c2275..664da6493239 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -36,6 +36,7 @@
36 * the runtime footprint, and giving us at least some parts of what 36 * the runtime footprint, and giving us at least some parts of what
37 * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 37 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
38 */ 38 */
39#define USBF_OBEX_INCLUDED
39#include "f_obex.c" 40#include "f_obex.c"
40 41
41/*-------------------------------------------------------------------------*/ 42/*-------------------------------------------------------------------------*/