diff options
author | Andrzej Pietrasiewicz <andrzej.p@samsung.com> | 2013-03-18 04:52:57 -0400 |
---|---|---|
committer | Felipe Balbi <balbi@ti.com> | 2013-04-03 07:43:33 -0400 |
commit | 60540ea2c51fa4feb475f689adce56297cb52010 (patch) | |
tree | a9e0d34def7bed8b18b590592d8623563bb20dde /drivers/usb/gadget | |
parent | 81f886cb7a5157d1b6562084a2ed96328e39f288 (diff) |
usb: gadget: f_serial: convert to new function interface with backward compatibility
Converting f_serial to the new function interface requires converting
the f_serial's function code and its users.
This patch converts the f_serial.c to the new function interface.
The file is now compiled into a separate usb_f_serial.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/usb/gadget')
-rw-r--r-- | drivers/usb/gadget/Kconfig | 3 | ||||
-rw-r--r-- | drivers/usb/gadget/Makefile | 2 | ||||
-rw-r--r-- | drivers/usb/gadget/f_serial.c | 131 | ||||
-rw-r--r-- | drivers/usb/gadget/serial.c | 1 |
4 files changed, 110 insertions, 27 deletions
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index 74a29de8f254..8a08efbb11e7 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig | |||
@@ -505,6 +505,9 @@ config USB_F_SS_LB | |||
505 | config USB_U_SERIAL | 505 | config USB_U_SERIAL |
506 | tristate | 506 | tristate |
507 | 507 | ||
508 | config USB_F_SERIAL | ||
509 | tristate | ||
510 | |||
508 | choice | 511 | choice |
509 | tristate "USB Gadget Drivers" | 512 | tristate "USB Gadget Drivers" |
510 | default USB_ETH | 513 | default USB_ETH |
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile index b938e06382b7..34bb49a131e9 100644 --- a/drivers/usb/gadget/Makefile +++ b/drivers/usb/gadget/Makefile | |||
@@ -41,6 +41,8 @@ obj-$(CONFIG_USB_F_ACM) += usb_f_acm.o | |||
41 | usb_f_ss_lb-y := f_loopback.o f_sourcesink.o | 41 | usb_f_ss_lb-y := f_loopback.o f_sourcesink.o |
42 | obj-$(CONFIG_USB_F_SS_LB) += usb_f_ss_lb.o | 42 | obj-$(CONFIG_USB_F_SS_LB) += usb_f_ss_lb.o |
43 | obj-$(CONFIG_USB_U_SERIAL) += u_serial.o | 43 | obj-$(CONFIG_USB_U_SERIAL) += u_serial.o |
44 | usb_f_serial-y := f_serial.o | ||
45 | obj-$(CONFIG_USB_F_SERIAL) += usb_f_serial.o | ||
44 | 46 | ||
45 | # | 47 | # |
46 | # USB gadget drivers | 48 | # USB gadget drivers |
diff --git a/drivers/usb/gadget/f_serial.c b/drivers/usb/gadget/f_serial.c index da33cfb3031d..465789bd5c91 100644 --- a/drivers/usb/gadget/f_serial.c +++ b/drivers/usb/gadget/f_serial.c | |||
@@ -12,6 +12,7 @@ | |||
12 | 12 | ||
13 | #include <linux/slab.h> | 13 | #include <linux/slab.h> |
14 | #include <linux/kernel.h> | 14 | #include <linux/kernel.h> |
15 | #include <linux/module.h> | ||
15 | #include <linux/device.h> | 16 | #include <linux/device.h> |
16 | 17 | ||
17 | #include "u_serial.h" | 18 | #include "u_serial.h" |
@@ -42,7 +43,7 @@ static inline struct f_gser *func_to_gser(struct usb_function *f) | |||
42 | 43 | ||
43 | /* interface descriptor: */ | 44 | /* interface descriptor: */ |
44 | 45 | ||
45 | static struct usb_interface_descriptor gser_interface_desc __initdata = { | 46 | static struct usb_interface_descriptor gser_interface_desc = { |
46 | .bLength = USB_DT_INTERFACE_SIZE, | 47 | .bLength = USB_DT_INTERFACE_SIZE, |
47 | .bDescriptorType = USB_DT_INTERFACE, | 48 | .bDescriptorType = USB_DT_INTERFACE, |
48 | /* .bInterfaceNumber = DYNAMIC */ | 49 | /* .bInterfaceNumber = DYNAMIC */ |
@@ -55,21 +56,21 @@ static struct usb_interface_descriptor gser_interface_desc __initdata = { | |||
55 | 56 | ||
56 | /* full speed support: */ | 57 | /* full speed support: */ |
57 | 58 | ||
58 | static struct usb_endpoint_descriptor gser_fs_in_desc __initdata = { | 59 | static struct usb_endpoint_descriptor gser_fs_in_desc = { |
59 | .bLength = USB_DT_ENDPOINT_SIZE, | 60 | .bLength = USB_DT_ENDPOINT_SIZE, |
60 | .bDescriptorType = USB_DT_ENDPOINT, | 61 | .bDescriptorType = USB_DT_ENDPOINT, |
61 | .bEndpointAddress = USB_DIR_IN, | 62 | .bEndpointAddress = USB_DIR_IN, |
62 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | 63 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
63 | }; | 64 | }; |
64 | 65 | ||
65 | static struct usb_endpoint_descriptor gser_fs_out_desc __initdata = { | 66 | static struct usb_endpoint_descriptor gser_fs_out_desc = { |
66 | .bLength = USB_DT_ENDPOINT_SIZE, | 67 | .bLength = USB_DT_ENDPOINT_SIZE, |
67 | .bDescriptorType = USB_DT_ENDPOINT, | 68 | .bDescriptorType = USB_DT_ENDPOINT, |
68 | .bEndpointAddress = USB_DIR_OUT, | 69 | .bEndpointAddress = USB_DIR_OUT, |
69 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | 70 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
70 | }; | 71 | }; |
71 | 72 | ||
72 | static struct usb_descriptor_header *gser_fs_function[] __initdata = { | 73 | static struct usb_descriptor_header *gser_fs_function[] = { |
73 | (struct usb_descriptor_header *) &gser_interface_desc, | 74 | (struct usb_descriptor_header *) &gser_interface_desc, |
74 | (struct usb_descriptor_header *) &gser_fs_in_desc, | 75 | (struct usb_descriptor_header *) &gser_fs_in_desc, |
75 | (struct usb_descriptor_header *) &gser_fs_out_desc, | 76 | (struct usb_descriptor_header *) &gser_fs_out_desc, |
@@ -78,47 +79,47 @@ static struct usb_descriptor_header *gser_fs_function[] __initdata = { | |||
78 | 79 | ||
79 | /* high speed support: */ | 80 | /* high speed support: */ |
80 | 81 | ||
81 | static struct usb_endpoint_descriptor gser_hs_in_desc __initdata = { | 82 | static struct usb_endpoint_descriptor gser_hs_in_desc = { |
82 | .bLength = USB_DT_ENDPOINT_SIZE, | 83 | .bLength = USB_DT_ENDPOINT_SIZE, |
83 | .bDescriptorType = USB_DT_ENDPOINT, | 84 | .bDescriptorType = USB_DT_ENDPOINT, |
84 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | 85 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
85 | .wMaxPacketSize = cpu_to_le16(512), | 86 | .wMaxPacketSize = cpu_to_le16(512), |
86 | }; | 87 | }; |
87 | 88 | ||
88 | static struct usb_endpoint_descriptor gser_hs_out_desc __initdata = { | 89 | static struct usb_endpoint_descriptor gser_hs_out_desc = { |
89 | .bLength = USB_DT_ENDPOINT_SIZE, | 90 | .bLength = USB_DT_ENDPOINT_SIZE, |
90 | .bDescriptorType = USB_DT_ENDPOINT, | 91 | .bDescriptorType = USB_DT_ENDPOINT, |
91 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | 92 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
92 | .wMaxPacketSize = cpu_to_le16(512), | 93 | .wMaxPacketSize = cpu_to_le16(512), |
93 | }; | 94 | }; |
94 | 95 | ||
95 | static struct usb_descriptor_header *gser_hs_function[] __initdata = { | 96 | static struct usb_descriptor_header *gser_hs_function[] = { |
96 | (struct usb_descriptor_header *) &gser_interface_desc, | 97 | (struct usb_descriptor_header *) &gser_interface_desc, |
97 | (struct usb_descriptor_header *) &gser_hs_in_desc, | 98 | (struct usb_descriptor_header *) &gser_hs_in_desc, |
98 | (struct usb_descriptor_header *) &gser_hs_out_desc, | 99 | (struct usb_descriptor_header *) &gser_hs_out_desc, |
99 | NULL, | 100 | NULL, |
100 | }; | 101 | }; |
101 | 102 | ||
102 | static struct usb_endpoint_descriptor gser_ss_in_desc __initdata = { | 103 | static struct usb_endpoint_descriptor gser_ss_in_desc = { |
103 | .bLength = USB_DT_ENDPOINT_SIZE, | 104 | .bLength = USB_DT_ENDPOINT_SIZE, |
104 | .bDescriptorType = USB_DT_ENDPOINT, | 105 | .bDescriptorType = USB_DT_ENDPOINT, |
105 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | 106 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
106 | .wMaxPacketSize = cpu_to_le16(1024), | 107 | .wMaxPacketSize = cpu_to_le16(1024), |
107 | }; | 108 | }; |
108 | 109 | ||
109 | static struct usb_endpoint_descriptor gser_ss_out_desc __initdata = { | 110 | static struct usb_endpoint_descriptor gser_ss_out_desc = { |
110 | .bLength = USB_DT_ENDPOINT_SIZE, | 111 | .bLength = USB_DT_ENDPOINT_SIZE, |
111 | .bDescriptorType = USB_DT_ENDPOINT, | 112 | .bDescriptorType = USB_DT_ENDPOINT, |
112 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | 113 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
113 | .wMaxPacketSize = cpu_to_le16(1024), | 114 | .wMaxPacketSize = cpu_to_le16(1024), |
114 | }; | 115 | }; |
115 | 116 | ||
116 | static struct usb_ss_ep_comp_descriptor gser_ss_bulk_comp_desc __initdata = { | 117 | static struct usb_ss_ep_comp_descriptor gser_ss_bulk_comp_desc = { |
117 | .bLength = sizeof gser_ss_bulk_comp_desc, | 118 | .bLength = sizeof gser_ss_bulk_comp_desc, |
118 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | 119 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, |
119 | }; | 120 | }; |
120 | 121 | ||
121 | static struct usb_descriptor_header *gser_ss_function[] __initdata = { | 122 | static struct usb_descriptor_header *gser_ss_function[] = { |
122 | (struct usb_descriptor_header *) &gser_interface_desc, | 123 | (struct usb_descriptor_header *) &gser_interface_desc, |
123 | (struct usb_descriptor_header *) &gser_ss_in_desc, | 124 | (struct usb_descriptor_header *) &gser_ss_in_desc, |
124 | (struct usb_descriptor_header *) &gser_ss_bulk_comp_desc, | 125 | (struct usb_descriptor_header *) &gser_ss_bulk_comp_desc, |
@@ -183,14 +184,25 @@ static void gser_disable(struct usb_function *f) | |||
183 | 184 | ||
184 | /* serial function driver setup/binding */ | 185 | /* serial function driver setup/binding */ |
185 | 186 | ||
186 | static int __init | 187 | static int gser_bind(struct usb_configuration *c, struct usb_function *f) |
187 | gser_bind(struct usb_configuration *c, struct usb_function *f) | ||
188 | { | 188 | { |
189 | struct usb_composite_dev *cdev = c->cdev; | 189 | struct usb_composite_dev *cdev = c->cdev; |
190 | struct f_gser *gser = func_to_gser(f); | 190 | struct f_gser *gser = func_to_gser(f); |
191 | int status; | 191 | int status; |
192 | struct usb_ep *ep; | 192 | struct usb_ep *ep; |
193 | 193 | ||
194 | /* REVISIT might want instance-specific strings to help | ||
195 | * distinguish instances ... | ||
196 | */ | ||
197 | |||
198 | /* maybe allocate device-global string ID */ | ||
199 | if (gser_string_defs[0].id == 0) { | ||
200 | status = usb_string_id(c->cdev); | ||
201 | if (status < 0) | ||
202 | return status; | ||
203 | gser_string_defs[0].id = status; | ||
204 | } | ||
205 | |||
194 | /* allocate instance-specific interface IDs */ | 206 | /* allocate instance-specific interface IDs */ |
195 | status = usb_interface_id(c, f); | 207 | status = usb_interface_id(c, f); |
196 | if (status < 0) | 208 | if (status < 0) |
@@ -246,8 +258,10 @@ fail: | |||
246 | return status; | 258 | return status; |
247 | } | 259 | } |
248 | 260 | ||
261 | #ifdef USB_FSERIAL_INCLUDED | ||
262 | |||
249 | static void | 263 | static void |
250 | gser_unbind(struct usb_configuration *c, struct usb_function *f) | 264 | gser_old_unbind(struct usb_configuration *c, struct usb_function *f) |
251 | { | 265 | { |
252 | usb_free_all_descriptors(f); | 266 | usb_free_all_descriptors(f); |
253 | kfree(func_to_gser(f)); | 267 | kfree(func_to_gser(f)); |
@@ -266,18 +280,6 @@ int __init gser_bind_config(struct usb_configuration *c, u8 port_num) | |||
266 | struct f_gser *gser; | 280 | struct f_gser *gser; |
267 | int status; | 281 | int status; |
268 | 282 | ||
269 | /* REVISIT might want instance-specific strings to help | ||
270 | * distinguish instances ... | ||
271 | */ | ||
272 | |||
273 | /* maybe allocate device-global string ID */ | ||
274 | if (gser_string_defs[0].id == 0) { | ||
275 | status = usb_string_id(c->cdev); | ||
276 | if (status < 0) | ||
277 | return status; | ||
278 | gser_string_defs[0].id = status; | ||
279 | } | ||
280 | |||
281 | /* allocate and initialize one new instance */ | 283 | /* allocate and initialize one new instance */ |
282 | gser = kzalloc(sizeof *gser, GFP_KERNEL); | 284 | gser = kzalloc(sizeof *gser, GFP_KERNEL); |
283 | if (!gser) | 285 | if (!gser) |
@@ -288,7 +290,7 @@ int __init gser_bind_config(struct usb_configuration *c, u8 port_num) | |||
288 | gser->port.func.name = "gser"; | 290 | gser->port.func.name = "gser"; |
289 | gser->port.func.strings = gser_strings; | 291 | gser->port.func.strings = gser_strings; |
290 | gser->port.func.bind = gser_bind; | 292 | gser->port.func.bind = gser_bind; |
291 | gser->port.func.unbind = gser_unbind; | 293 | gser->port.func.unbind = gser_old_unbind; |
292 | gser->port.func.set_alt = gser_set_alt; | 294 | gser->port.func.set_alt = gser_set_alt; |
293 | gser->port.func.disable = gser_disable; | 295 | gser->port.func.disable = gser_disable; |
294 | 296 | ||
@@ -297,3 +299,78 @@ int __init gser_bind_config(struct usb_configuration *c, u8 port_num) | |||
297 | kfree(gser); | 299 | kfree(gser); |
298 | return status; | 300 | return status; |
299 | } | 301 | } |
302 | |||
303 | #else | ||
304 | |||
305 | static void gser_free_inst(struct usb_function_instance *f) | ||
306 | { | ||
307 | struct f_serial_opts *opts; | ||
308 | |||
309 | opts = container_of(f, struct f_serial_opts, func_inst); | ||
310 | gserial_free_line(opts->port_num); | ||
311 | kfree(opts); | ||
312 | } | ||
313 | |||
314 | static struct usb_function_instance *gser_alloc_inst(void) | ||
315 | { | ||
316 | struct f_serial_opts *opts; | ||
317 | int ret; | ||
318 | |||
319 | opts = kzalloc(sizeof(*opts), GFP_KERNEL); | ||
320 | if (!opts) | ||
321 | return ERR_PTR(-ENOMEM); | ||
322 | |||
323 | opts->func_inst.free_func_inst = gser_free_inst; | ||
324 | ret = gserial_alloc_line(&opts->port_num); | ||
325 | if (ret) { | ||
326 | kfree(opts); | ||
327 | return ERR_PTR(ret); | ||
328 | } | ||
329 | |||
330 | return &opts->func_inst; | ||
331 | } | ||
332 | |||
333 | static void gser_free(struct usb_function *f) | ||
334 | { | ||
335 | struct f_gser *serial; | ||
336 | |||
337 | serial = func_to_gser(f); | ||
338 | kfree(serial); | ||
339 | } | ||
340 | |||
341 | static void gser_unbind(struct usb_configuration *c, struct usb_function *f) | ||
342 | { | ||
343 | usb_free_all_descriptors(f); | ||
344 | } | ||
345 | |||
346 | struct usb_function *gser_alloc(struct usb_function_instance *fi) | ||
347 | { | ||
348 | struct f_gser *gser; | ||
349 | struct f_serial_opts *opts; | ||
350 | |||
351 | /* allocate and initialize one new instance */ | ||
352 | gser = kzalloc(sizeof(*gser), GFP_KERNEL); | ||
353 | if (!gser) | ||
354 | return ERR_PTR(-ENOMEM); | ||
355 | |||
356 | opts = container_of(fi, struct f_serial_opts, func_inst); | ||
357 | |||
358 | gser->port_num = opts->port_num; | ||
359 | |||
360 | gser->port.func.name = "gser"; | ||
361 | gser->port.func.strings = gser_strings; | ||
362 | gser->port.func.bind = gser_bind; | ||
363 | gser->port.func.unbind = gser_unbind; | ||
364 | gser->port.func.set_alt = gser_set_alt; | ||
365 | gser->port.func.disable = gser_disable; | ||
366 | gser->port.func.free_func = gser_free; | ||
367 | |||
368 | return &gser->port.func; | ||
369 | } | ||
370 | |||
371 | DECLARE_USB_FUNCTION_INIT(gser, gser_alloc_inst, gser_alloc); | ||
372 | MODULE_LICENSE("GPL"); | ||
373 | MODULE_AUTHOR("Al Borchers"); | ||
374 | MODULE_AUTHOR("David Brownell"); | ||
375 | |||
376 | #endif | ||
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c index c48ca1eb5442..07c1e802f917 100644 --- a/drivers/usb/gadget/serial.c +++ b/drivers/usb/gadget/serial.c | |||
@@ -37,6 +37,7 @@ | |||
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 | #include "f_obex.c" | 39 | #include "f_obex.c" |
40 | #define USB_FSERIAL_INCLUDED | ||
40 | #include "f_serial.c" | 41 | #include "f_serial.c" |
41 | 42 | ||
42 | /*-------------------------------------------------------------------------*/ | 43 | /*-------------------------------------------------------------------------*/ |