Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
David Brownell | a7707ad | 2008-06-19 17:52:07 -0700 | [diff] [blame] | 2 | * serial.c -- USB gadget serial driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
David Brownell | a7707ad | 2008-06-19 17:52:07 -0700 | [diff] [blame] | 4 | * Copyright (C) 2003 Al Borchers (alborchers@steinerpoint.com) |
| 5 | * Copyright (C) 2008 by David Brownell |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 6 | * Copyright (C) 2008 by Nokia Corporation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
| 8 | * This software is distributed under the terms of the GNU General |
| 9 | * Public License ("GPL") as published by the Free Software Foundation, |
| 10 | * either version 2 of that License or (at your option) any later version. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | */ |
| 12 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/device.h> |
| 15 | #include <linux/tty.h> |
| 16 | #include <linux/tty_flip.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
David Brownell | a7707ad | 2008-06-19 17:52:07 -0700 | [diff] [blame] | 18 | #include "u_serial.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include "gadget_chips.h" |
| 20 | |
| 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | /* Defines */ |
| 23 | |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 24 | #define GS_VERSION_STR "v2.4" |
| 25 | #define GS_VERSION_NUM 0x2400 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
| 27 | #define GS_LONG_NAME "Gadget Serial" |
David Brownell | a7707ad | 2008-06-19 17:52:07 -0700 | [diff] [blame] | 28 | #define GS_VERSION_NAME GS_LONG_NAME " " GS_VERSION_STR |
| 29 | |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 30 | /*-------------------------------------------------------------------------*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
David Brownell | 4e9ba51 | 2008-08-18 17:41:02 -0700 | [diff] [blame] | 32 | /* |
| 33 | * Kbuild is not very cooperative with respect to linking separately |
| 34 | * compiled library objects into one module. So for now we won't use |
| 35 | * separate compilation ... ensuring init/exit sections work to shrink |
| 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. |
| 38 | */ |
Felipe Balbi | 3086775 | 2008-08-18 17:39:30 -0700 | [diff] [blame] | 39 | #include "f_obex.c" |
David Brownell | 4e9ba51 | 2008-08-18 17:41:02 -0700 | [diff] [blame] | 40 | #include "f_serial.c" |
David Brownell | 4e9ba51 | 2008-08-18 17:41:02 -0700 | [diff] [blame] | 41 | |
| 42 | /*-------------------------------------------------------------------------*/ |
Sebastian Andrzej Siewior | 7d16e8d | 2012-09-10 15:01:53 +0200 | [diff] [blame] | 43 | USB_GADGET_COMPOSITE_OPTIONS(); |
David Brownell | 4e9ba51 | 2008-08-18 17:41:02 -0700 | [diff] [blame] | 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | /* Thanks to NetChip Technologies for donating this product ID. |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 46 | * |
| 47 | * DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!! |
| 48 | * Instead: allocate your own, using normal USB-IF procedures. |
| 49 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #define GS_VENDOR_ID 0x0525 /* NetChip */ |
| 51 | #define GS_PRODUCT_ID 0xa4a6 /* Linux-USB Serial Gadget */ |
| 52 | #define GS_CDC_PRODUCT_ID 0xa4a7 /* ... as CDC-ACM */ |
Felipe Balbi | 3086775 | 2008-08-18 17:39:30 -0700 | [diff] [blame] | 53 | #define GS_CDC_OBEX_PRODUCT_ID 0xa4a9 /* ... as CDC-OBEX */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 55 | /* string IDs are assigned dynamically */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
Sebastian Andrzej Siewior | 276e2e4 | 2012-09-06 20:11:21 +0200 | [diff] [blame] | 57 | #define STRING_DESCRIPTION_IDX USB_GADGET_FIRST_AVAIL_IDX |
David Brownell | a7707ad | 2008-06-19 17:52:07 -0700 | [diff] [blame] | 58 | |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 59 | static struct usb_string strings_dev[] = { |
Sebastian Andrzej Siewior | cc2683c | 2012-09-10 15:01:58 +0200 | [diff] [blame] | 60 | [USB_GADGET_MANUFACTURER_IDX].s = "", |
Sebastian Andrzej Siewior | 276e2e4 | 2012-09-06 20:11:21 +0200 | [diff] [blame] | 61 | [USB_GADGET_PRODUCT_IDX].s = GS_VERSION_NAME, |
| 62 | [USB_GADGET_SERIAL_IDX].s = "", |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 63 | [STRING_DESCRIPTION_IDX].s = NULL /* updated; f(use_acm) */, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | { } /* end of list */ |
| 65 | }; |
| 66 | |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 67 | static struct usb_gadget_strings stringtab_dev = { |
| 68 | .language = 0x0409, /* en-us */ |
| 69 | .strings = strings_dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | }; |
| 71 | |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 72 | static struct usb_gadget_strings *dev_strings[] = { |
| 73 | &stringtab_dev, |
| 74 | NULL, |
| 75 | }; |
| 76 | |
| 77 | static struct usb_device_descriptor device_desc = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | .bLength = USB_DT_DEVICE_SIZE, |
| 79 | .bDescriptorType = USB_DT_DEVICE, |
Harvey Harrison | 551509d | 2009-02-11 14:11:36 -0800 | [diff] [blame] | 80 | .bcdUSB = cpu_to_le16(0x0200), |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 81 | /* .bDeviceClass = f(use_acm) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | .bDeviceSubClass = 0, |
| 83 | .bDeviceProtocol = 0, |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 84 | /* .bMaxPacketSize0 = f(hardware) */ |
Harvey Harrison | 551509d | 2009-02-11 14:11:36 -0800 | [diff] [blame] | 85 | .idVendor = cpu_to_le16(GS_VENDOR_ID), |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 86 | /* .idProduct = f(use_acm) */ |
Sebastian Andrzej Siewior | 5c4d46e | 2012-09-10 19:06:44 +0200 | [diff] [blame] | 87 | .bcdDevice = cpu_to_le16(GS_VERSION_NUM), |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 88 | /* .iManufacturer = DYNAMIC */ |
| 89 | /* .iProduct = DYNAMIC */ |
| 90 | .bNumConfigurations = 1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | }; |
| 92 | |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 93 | static struct usb_otg_descriptor otg_descriptor = { |
| 94 | .bLength = sizeof otg_descriptor, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | .bDescriptorType = USB_DT_OTG, |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 96 | |
| 97 | /* REVISIT SRP-only hardware is possible, although |
| 98 | * it would not be called "OTG" ... |
| 99 | */ |
| 100 | .bmAttributes = USB_OTG_SRP | USB_OTG_HNP, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | }; |
| 102 | |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 103 | static const struct usb_descriptor_header *otg_desc[] = { |
| 104 | (struct usb_descriptor_header *) &otg_descriptor, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | NULL, |
| 106 | }; |
| 107 | |
David Brownell | 9079e91 | 2008-05-07 16:00:36 -0700 | [diff] [blame] | 108 | /*-------------------------------------------------------------------------*/ |
| 109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | /* Module */ |
David Brownell | a7707ad | 2008-06-19 17:52:07 -0700 | [diff] [blame] | 111 | MODULE_DESCRIPTION(GS_VERSION_NAME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | MODULE_AUTHOR("Al Borchers"); |
David Brownell | a7707ad | 2008-06-19 17:52:07 -0700 | [diff] [blame] | 113 | MODULE_AUTHOR("David Brownell"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | MODULE_LICENSE("GPL"); |
| 115 | |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 116 | static bool use_acm = true; |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 117 | module_param(use_acm, bool, 0); |
| 118 | MODULE_PARM_DESC(use_acm, "Use CDC ACM, default=yes"); |
| 119 | |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 120 | static bool use_obex = false; |
Felipe Balbi | 3086775 | 2008-08-18 17:39:30 -0700 | [diff] [blame] | 121 | module_param(use_obex, bool, 0); |
| 122 | MODULE_PARM_DESC(use_obex, "Use CDC OBEX, default=no"); |
| 123 | |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 124 | static unsigned n_ports = 1; |
| 125 | module_param(n_ports, uint, 0); |
| 126 | MODULE_PARM_DESC(n_ports, "number of ports to create, default=1"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | |
David Brownell | 9079e91 | 2008-05-07 16:00:36 -0700 | [diff] [blame] | 128 | /*-------------------------------------------------------------------------*/ |
Sebastian Andrzej Siewior | 19b10a8 | 2012-12-23 21:10:06 +0100 | [diff] [blame] | 129 | static unsigned char tty_lines[MAX_U_SERIAL_PORTS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
Sebastian Andrzej Siewior | 48177cd | 2012-12-23 21:10:03 +0100 | [diff] [blame] | 131 | static int __init serial_bind_obex_config(struct usb_configuration *c) |
| 132 | { |
| 133 | unsigned i; |
| 134 | int status = 0; |
| 135 | |
| 136 | for (i = 0; i < n_ports && status == 0; i++) |
Sebastian Andrzej Siewior | 19b10a8 | 2012-12-23 21:10:06 +0100 | [diff] [blame] | 137 | status = obex_bind_config(c, tty_lines[i]); |
Sebastian Andrzej Siewior | 48177cd | 2012-12-23 21:10:03 +0100 | [diff] [blame] | 138 | return status; |
| 139 | } |
| 140 | |
| 141 | static int __init serial_bind_gser_config(struct usb_configuration *c) |
| 142 | { |
| 143 | unsigned i; |
| 144 | int status = 0; |
| 145 | |
| 146 | for (i = 0; i < n_ports && status == 0; i++) |
Sebastian Andrzej Siewior | 19b10a8 | 2012-12-23 21:10:06 +0100 | [diff] [blame] | 147 | status = gser_bind_config(c, tty_lines[i]); |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 148 | return status; |
David Brownell | 9079e91 | 2008-05-07 16:00:36 -0700 | [diff] [blame] | 149 | } |
| 150 | |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 151 | static struct usb_configuration serial_config_driver = { |
| 152 | /* .label = f(use_acm) */ |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 153 | /* .bConfigurationValue = f(use_acm) */ |
| 154 | /* .iConfiguration = DYNAMIC */ |
| 155 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, |
David Brownell | 9079e91 | 2008-05-07 16:00:36 -0700 | [diff] [blame] | 156 | }; |
| 157 | |
Sebastian Andrzej Siewior | ff47f59 | 2012-12-23 21:10:07 +0100 | [diff] [blame] | 158 | static struct usb_function_instance *fi_serial[MAX_U_SERIAL_PORTS]; |
| 159 | static struct usb_function *f_serial[MAX_U_SERIAL_PORTS]; |
| 160 | |
| 161 | static int serial_register_ports(struct usb_composite_dev *cdev, |
| 162 | struct usb_configuration *c, const char *f_name) |
Sebastian Andrzej Siewior | 19b10a8 | 2012-12-23 21:10:06 +0100 | [diff] [blame] | 163 | { |
| 164 | int i; |
Sebastian Andrzej Siewior | ff47f59 | 2012-12-23 21:10:07 +0100 | [diff] [blame] | 165 | int ret; |
Sebastian Andrzej Siewior | 19b10a8 | 2012-12-23 21:10:06 +0100 | [diff] [blame] | 166 | |
Sebastian Andrzej Siewior | ff47f59 | 2012-12-23 21:10:07 +0100 | [diff] [blame] | 167 | ret = usb_add_config_only(cdev, c); |
| 168 | if (ret) |
| 169 | goto out; |
| 170 | |
| 171 | for (i = 0; i < n_ports; i++) { |
| 172 | struct f_serial_opts *opts; |
| 173 | |
| 174 | fi_serial[i] = usb_get_function_instance(f_name); |
| 175 | if (IS_ERR(fi_serial[i])) { |
| 176 | ret = PTR_ERR(fi_serial[i]); |
| 177 | goto fail; |
| 178 | } |
| 179 | opts = container_of(fi_serial[i], struct f_serial_opts, func_inst); |
| 180 | opts->port_num = tty_lines[i]; |
| 181 | |
| 182 | f_serial[i] = usb_get_function(fi_serial[i]); |
| 183 | if (IS_ERR(f_serial[i])) { |
| 184 | ret = PTR_ERR(f_serial[i]); |
| 185 | goto err_get_func; |
| 186 | } |
| 187 | |
| 188 | ret = usb_add_function(c, f_serial[i]); |
| 189 | if (ret) |
| 190 | goto err_add_func; |
| 191 | } |
| 192 | |
Sebastian Andrzej Siewior | 19b10a8 | 2012-12-23 21:10:06 +0100 | [diff] [blame] | 193 | return 0; |
Sebastian Andrzej Siewior | ff47f59 | 2012-12-23 21:10:07 +0100 | [diff] [blame] | 194 | |
| 195 | err_add_func: |
| 196 | usb_put_function(f_serial[i]); |
| 197 | err_get_func: |
| 198 | usb_put_function_instance(fi_serial[i]); |
| 199 | |
| 200 | fail: |
| 201 | i--; |
| 202 | while (i >= 0) { |
| 203 | usb_remove_function(c, f_serial[i]); |
| 204 | usb_put_function(f_serial[i]); |
| 205 | usb_put_function_instance(fi_serial[i]); |
| 206 | i--; |
| 207 | } |
| 208 | out: |
| 209 | return ret; |
Sebastian Andrzej Siewior | 19b10a8 | 2012-12-23 21:10:06 +0100 | [diff] [blame] | 210 | } |
| 211 | |
Michal Nazarewicz | e12995e | 2010-08-12 17:43:52 +0200 | [diff] [blame] | 212 | static int __init gs_bind(struct usb_composite_dev *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | { |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 214 | int status; |
Sebastian Andrzej Siewior | 19b10a8 | 2012-12-23 21:10:06 +0100 | [diff] [blame] | 215 | int cur_line; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
Sebastian Andrzej Siewior | 19b10a8 | 2012-12-23 21:10:06 +0100 | [diff] [blame] | 217 | for (cur_line = 0; cur_line < n_ports; cur_line++) { |
| 218 | status = gserial_alloc_line(&tty_lines[cur_line]); |
| 219 | if (status) |
| 220 | goto fail; |
| 221 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 223 | /* Allocate string descriptor numbers ... note that string |
| 224 | * contents can be overridden by the composite_dev glue. |
David Brownell | f371e75 | 2008-04-18 17:37:49 -0700 | [diff] [blame] | 225 | */ |
| 226 | |
Sebastian Andrzej Siewior | e1f15cc | 2012-09-06 20:11:16 +0200 | [diff] [blame] | 227 | status = usb_string_ids_tab(cdev, strings_dev); |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 228 | if (status < 0) |
| 229 | goto fail; |
Sebastian Andrzej Siewior | 276e2e4 | 2012-09-06 20:11:21 +0200 | [diff] [blame] | 230 | device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id; |
| 231 | device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id; |
Sebastian Andrzej Siewior | e1f15cc | 2012-09-06 20:11:16 +0200 | [diff] [blame] | 232 | status = strings_dev[STRING_DESCRIPTION_IDX].id; |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 233 | serial_config_driver.iConfiguration = status; |
| 234 | |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 235 | if (gadget_is_otg(cdev->gadget)) { |
| 236 | serial_config_driver.descriptors = otg_desc; |
| 237 | serial_config_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; |
| 238 | } |
| 239 | |
| 240 | /* register our configuration */ |
Sebastian Andrzej Siewior | ff47f59 | 2012-12-23 21:10:07 +0100 | [diff] [blame] | 241 | if (use_acm) { |
| 242 | status = serial_register_ports(cdev, &serial_config_driver, |
| 243 | "acm"); |
| 244 | usb_ep_autoconfig_reset(cdev->gadget); |
| 245 | } else if (use_obex) |
Sebastian Andrzej Siewior | 48177cd | 2012-12-23 21:10:03 +0100 | [diff] [blame] | 246 | status = usb_add_config(cdev, &serial_config_driver, |
| 247 | serial_bind_obex_config); |
| 248 | else |
| 249 | status = usb_add_config(cdev, &serial_config_driver, |
| 250 | serial_bind_gser_config); |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 251 | if (status < 0) |
| 252 | goto fail; |
| 253 | |
Sebastian Andrzej Siewior | 7d16e8d | 2012-09-10 15:01:53 +0200 | [diff] [blame] | 254 | usb_composite_overwrite_options(cdev, &coverwrite); |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 255 | INFO(cdev, "%s\n", GS_VERSION_NAME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | |
| 257 | return 0; |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 258 | |
| 259 | fail: |
Sebastian Andrzej Siewior | 19b10a8 | 2012-12-23 21:10:06 +0100 | [diff] [blame] | 260 | cur_line--; |
| 261 | while (cur_line >= 0) |
| 262 | gserial_free_line(tty_lines[cur_line--]); |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 263 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Sebastian Andrzej Siewior | ff47f59 | 2012-12-23 21:10:07 +0100 | [diff] [blame] | 266 | static int gs_unbind(struct usb_composite_dev *cdev) |
| 267 | { |
| 268 | int i; |
| 269 | |
| 270 | for (i = 0; i < n_ports; i++) { |
| 271 | usb_put_function(f_serial[i]); |
| 272 | usb_put_function_instance(fi_serial[i]); |
| 273 | gserial_free_line(tty_lines[i]); |
| 274 | } |
| 275 | return 0; |
| 276 | } |
| 277 | |
Sebastian Andrzej Siewior | c2ec75c | 2012-09-06 20:11:03 +0200 | [diff] [blame] | 278 | static __refdata struct usb_composite_driver gserial_driver = { |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 279 | .name = "g_serial", |
| 280 | .dev = &device_desc, |
| 281 | .strings = dev_strings, |
Sebastian Andrzej Siewior | 6fecfb0 | 2012-02-06 18:46:36 +0100 | [diff] [blame] | 282 | .max_speed = USB_SPEED_SUPER, |
Sebastian Andrzej Siewior | 03e42bd | 2012-09-06 20:11:04 +0200 | [diff] [blame] | 283 | .bind = gs_bind, |
Sebastian Andrzej Siewior | 19b10a8 | 2012-12-23 21:10:06 +0100 | [diff] [blame] | 284 | .unbind = gs_unbind, |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 285 | }; |
| 286 | |
| 287 | static int __init init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | { |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 289 | /* We *could* export two configs; that'd be much cleaner... |
| 290 | * but neither of these product IDs was defined that way. |
| 291 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | if (use_acm) { |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 293 | serial_config_driver.label = "CDC ACM config"; |
| 294 | serial_config_driver.bConfigurationValue = 2; |
| 295 | device_desc.bDeviceClass = USB_CLASS_COMM; |
| 296 | device_desc.idProduct = |
Harvey Harrison | 551509d | 2009-02-11 14:11:36 -0800 | [diff] [blame] | 297 | cpu_to_le16(GS_CDC_PRODUCT_ID); |
Felipe Balbi | 3086775 | 2008-08-18 17:39:30 -0700 | [diff] [blame] | 298 | } else if (use_obex) { |
| 299 | serial_config_driver.label = "CDC OBEX config"; |
| 300 | serial_config_driver.bConfigurationValue = 3; |
| 301 | device_desc.bDeviceClass = USB_CLASS_COMM; |
| 302 | device_desc.idProduct = |
Harvey Harrison | 551509d | 2009-02-11 14:11:36 -0800 | [diff] [blame] | 303 | cpu_to_le16(GS_CDC_OBEX_PRODUCT_ID); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | } else { |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 305 | serial_config_driver.label = "Generic Serial config"; |
| 306 | serial_config_driver.bConfigurationValue = 1; |
| 307 | device_desc.bDeviceClass = USB_CLASS_VENDOR_SPEC; |
| 308 | device_desc.idProduct = |
Harvey Harrison | 551509d | 2009-02-11 14:11:36 -0800 | [diff] [blame] | 309 | cpu_to_le16(GS_PRODUCT_ID); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | } |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 311 | strings_dev[STRING_DESCRIPTION_IDX].s = serial_config_driver.label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
Sebastian Andrzej Siewior | 03e42bd | 2012-09-06 20:11:04 +0200 | [diff] [blame] | 313 | return usb_composite_probe(&gserial_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | } |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 315 | module_init(init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 317 | static void __exit cleanup(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | { |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 319 | usb_composite_unregister(&gserial_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | } |
David Brownell | 7bb5ea5 | 2008-06-19 18:19:03 -0700 | [diff] [blame] | 321 | module_exit(cleanup); |