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