blob: 3d6ceaa6e5677bccd65ca3cab2904b5c5bf1f54b [file] [log] [blame]
David Brownell61d8bae2008-06-19 18:18:50 -07001/*
2 * f_serial.c - generic USB serial function driver
3 *
4 * Copyright (C) 2003 Al Borchers (alborchers@steinerpoint.com)
5 * Copyright (C) 2008 by David Brownell
6 * Copyright (C) 2008 by Nokia Corporation
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.
11 */
12
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090013#include <linux/slab.h>
David Brownell61d8bae2008-06-19 18:18:50 -070014#include <linux/kernel.h>
15#include <linux/device.h>
Hemant Kumarbffd4142011-11-03 13:20:40 -070016#include <mach/usb_gadget_xport.h>
David Brownell61d8bae2008-06-19 18:18:50 -070017
18#include "u_serial.h"
19#include "gadget_chips.h"
20
21
22/*
23 * This function packages a simple "generic serial" port with no real
24 * control mechanisms, just raw data transfer over two bulk endpoints.
25 *
26 * Because it's not standardized, this isn't as interoperable as the
27 * CDC ACM driver. However, for many purposes it's just as functional
28 * if you can arrange appropriate host side drivers.
29 */
Vijayavardhan Vennapusaeb8d2392012-04-03 18:58:49 +053030#define GSERIAL_NO_PORTS 3
David Brownell61d8bae2008-06-19 18:18:50 -070031
David Brownell61d8bae2008-06-19 18:18:50 -070032struct f_gser {
33 struct gserial port;
34 u8 data_id;
35 u8 port_num;
36
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070037 u8 online;
38 enum transport_type transport;
39
40#ifdef CONFIG_MODEM_SUPPORT
41 u8 pending;
42 spinlock_t lock;
43 struct usb_ep *notify;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070044 struct usb_request *notify_req;
45
46 struct usb_cdc_line_coding port_line_coding;
47
48 /* SetControlLineState request */
49 u16 port_handshake_bits;
50#define ACM_CTRL_RTS (1 << 1) /* unused with full duplex */
51#define ACM_CTRL_DTR (1 << 0) /* host is ready for data r/w */
52
53 /* SerialState notification */
54 u16 serial_state;
55#define ACM_CTRL_OVERRUN (1 << 6)
56#define ACM_CTRL_PARITY (1 << 5)
57#define ACM_CTRL_FRAMING (1 << 4)
58#define ACM_CTRL_RI (1 << 3)
59#define ACM_CTRL_BRK (1 << 2)
60#define ACM_CTRL_DSR (1 << 1)
61#define ACM_CTRL_DCD (1 << 0)
62#endif
David Brownell61d8bae2008-06-19 18:18:50 -070063};
64
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070065static unsigned int no_tty_ports;
66static unsigned int no_sdio_ports;
67static unsigned int no_smd_ports;
Jack Pham427f6922011-11-23 19:42:00 -080068static unsigned int no_hsic_sports;
Vijayavardhan Vennapusaeb8d2392012-04-03 18:58:49 +053069static unsigned int no_hsuart_sports;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070070static unsigned int nr_ports;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070071
72static struct port_info {
73 enum transport_type transport;
74 unsigned port_num;
75 unsigned client_port_num;
76} gserial_ports[GSERIAL_NO_PORTS];
77
78static inline bool is_transport_sdio(enum transport_type t)
79{
Hemant Kumarbffd4142011-11-03 13:20:40 -070080 if (t == USB_GADGET_XPORT_SDIO)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070081 return 1;
82 return 0;
83}
84
David Brownell61d8bae2008-06-19 18:18:50 -070085static inline struct f_gser *func_to_gser(struct usb_function *f)
86{
87 return container_of(f, struct f_gser, port.func);
88}
89
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070090#ifdef CONFIG_MODEM_SUPPORT
91static inline struct f_gser *port_to_gser(struct gserial *p)
92{
93 return container_of(p, struct f_gser, port);
94}
95#define GS_LOG2_NOTIFY_INTERVAL 5 /* 1 << 5 == 32 msec */
96#define GS_NOTIFY_MAXPACKET 10 /* notification + 2 bytes */
97#endif
David Brownell61d8bae2008-06-19 18:18:50 -070098/*-------------------------------------------------------------------------*/
99
100/* interface descriptor: */
101
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700102static struct usb_interface_descriptor gser_interface_desc = {
David Brownell61d8bae2008-06-19 18:18:50 -0700103 .bLength = USB_DT_INTERFACE_SIZE,
104 .bDescriptorType = USB_DT_INTERFACE,
105 /* .bInterfaceNumber = DYNAMIC */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700106#ifdef CONFIG_MODEM_SUPPORT
107 .bNumEndpoints = 3,
108#else
David Brownell61d8bae2008-06-19 18:18:50 -0700109 .bNumEndpoints = 2,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700110#endif
David Brownell61d8bae2008-06-19 18:18:50 -0700111 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
112 .bInterfaceSubClass = 0,
113 .bInterfaceProtocol = 0,
114 /* .iInterface = DYNAMIC */
115};
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700116#ifdef CONFIG_MODEM_SUPPORT
117static struct usb_cdc_header_desc gser_header_desc = {
118 .bLength = sizeof(gser_header_desc),
119 .bDescriptorType = USB_DT_CS_INTERFACE,
120 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
121 .bcdCDC = __constant_cpu_to_le16(0x0110),
122};
David Brownell61d8bae2008-06-19 18:18:50 -0700123
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700124static struct usb_cdc_call_mgmt_descriptor
125gser_call_mgmt_descriptor = {
126 .bLength = sizeof(gser_call_mgmt_descriptor),
127 .bDescriptorType = USB_DT_CS_INTERFACE,
128 .bDescriptorSubType = USB_CDC_CALL_MANAGEMENT_TYPE,
129 .bmCapabilities = 0,
130 /* .bDataInterface = DYNAMIC */
131};
132
133static struct usb_cdc_acm_descriptor gser_descriptor = {
134 .bLength = sizeof(gser_descriptor),
135 .bDescriptorType = USB_DT_CS_INTERFACE,
136 .bDescriptorSubType = USB_CDC_ACM_TYPE,
137 .bmCapabilities = USB_CDC_CAP_LINE,
138};
139
140static struct usb_cdc_union_desc gser_union_desc = {
141 .bLength = sizeof(gser_union_desc),
142 .bDescriptorType = USB_DT_CS_INTERFACE,
143 .bDescriptorSubType = USB_CDC_UNION_TYPE,
144 /* .bMasterInterface0 = DYNAMIC */
145 /* .bSlaveInterface0 = DYNAMIC */
146};
147#endif
David Brownell61d8bae2008-06-19 18:18:50 -0700148/* full speed support: */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700149#ifdef CONFIG_MODEM_SUPPORT
150static struct usb_endpoint_descriptor gser_fs_notify_desc = {
151 .bLength = USB_DT_ENDPOINT_SIZE,
152 .bDescriptorType = USB_DT_ENDPOINT,
153 .bEndpointAddress = USB_DIR_IN,
154 .bmAttributes = USB_ENDPOINT_XFER_INT,
155 .wMaxPacketSize = __constant_cpu_to_le16(GS_NOTIFY_MAXPACKET),
156 .bInterval = 1 << GS_LOG2_NOTIFY_INTERVAL,
157};
158#endif
David Brownell61d8bae2008-06-19 18:18:50 -0700159
Manu Gautama4d993f2011-08-30 18:25:55 +0530160static struct usb_endpoint_descriptor gser_fs_in_desc = {
David Brownell61d8bae2008-06-19 18:18:50 -0700161 .bLength = USB_DT_ENDPOINT_SIZE,
162 .bDescriptorType = USB_DT_ENDPOINT,
163 .bEndpointAddress = USB_DIR_IN,
164 .bmAttributes = USB_ENDPOINT_XFER_BULK,
165};
166
Manu Gautama4d993f2011-08-30 18:25:55 +0530167static struct usb_endpoint_descriptor gser_fs_out_desc = {
David Brownell61d8bae2008-06-19 18:18:50 -0700168 .bLength = USB_DT_ENDPOINT_SIZE,
169 .bDescriptorType = USB_DT_ENDPOINT,
170 .bEndpointAddress = USB_DIR_OUT,
171 .bmAttributes = USB_ENDPOINT_XFER_BULK,
172};
173
Manu Gautama4d993f2011-08-30 18:25:55 +0530174static struct usb_descriptor_header *gser_fs_function[] = {
David Brownell61d8bae2008-06-19 18:18:50 -0700175 (struct usb_descriptor_header *) &gser_interface_desc,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700176#ifdef CONFIG_MODEM_SUPPORT
177 (struct usb_descriptor_header *) &gser_header_desc,
178 (struct usb_descriptor_header *) &gser_call_mgmt_descriptor,
179 (struct usb_descriptor_header *) &gser_descriptor,
180 (struct usb_descriptor_header *) &gser_union_desc,
181 (struct usb_descriptor_header *) &gser_fs_notify_desc,
182#endif
David Brownell61d8bae2008-06-19 18:18:50 -0700183 (struct usb_descriptor_header *) &gser_fs_in_desc,
184 (struct usb_descriptor_header *) &gser_fs_out_desc,
185 NULL,
186};
187
188/* high speed support: */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700189#ifdef CONFIG_MODEM_SUPPORT
190static struct usb_endpoint_descriptor gser_hs_notify_desc = {
191 .bLength = USB_DT_ENDPOINT_SIZE,
192 .bDescriptorType = USB_DT_ENDPOINT,
193 .bEndpointAddress = USB_DIR_IN,
194 .bmAttributes = USB_ENDPOINT_XFER_INT,
195 .wMaxPacketSize = __constant_cpu_to_le16(GS_NOTIFY_MAXPACKET),
196 .bInterval = GS_LOG2_NOTIFY_INTERVAL+4,
197};
198#endif
David Brownell61d8bae2008-06-19 18:18:50 -0700199
Manu Gautama4d993f2011-08-30 18:25:55 +0530200static struct usb_endpoint_descriptor gser_hs_in_desc = {
David Brownell61d8bae2008-06-19 18:18:50 -0700201 .bLength = USB_DT_ENDPOINT_SIZE,
202 .bDescriptorType = USB_DT_ENDPOINT,
203 .bmAttributes = USB_ENDPOINT_XFER_BULK,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700204 .wMaxPacketSize = __constant_cpu_to_le16(512),
David Brownell61d8bae2008-06-19 18:18:50 -0700205};
206
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700207static struct usb_endpoint_descriptor gser_hs_out_desc = {
David Brownell61d8bae2008-06-19 18:18:50 -0700208 .bLength = USB_DT_ENDPOINT_SIZE,
209 .bDescriptorType = USB_DT_ENDPOINT,
210 .bmAttributes = USB_ENDPOINT_XFER_BULK,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700211 .wMaxPacketSize = __constant_cpu_to_le16(512),
David Brownell61d8bae2008-06-19 18:18:50 -0700212};
213
Manu Gautama4d993f2011-08-30 18:25:55 +0530214static struct usb_descriptor_header *gser_hs_function[] = {
David Brownell61d8bae2008-06-19 18:18:50 -0700215 (struct usb_descriptor_header *) &gser_interface_desc,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700216#ifdef CONFIG_MODEM_SUPPORT
217 (struct usb_descriptor_header *) &gser_header_desc,
218 (struct usb_descriptor_header *) &gser_call_mgmt_descriptor,
219 (struct usb_descriptor_header *) &gser_descriptor,
220 (struct usb_descriptor_header *) &gser_union_desc,
221 (struct usb_descriptor_header *) &gser_hs_notify_desc,
222#endif
David Brownell61d8bae2008-06-19 18:18:50 -0700223 (struct usb_descriptor_header *) &gser_hs_in_desc,
224 (struct usb_descriptor_header *) &gser_hs_out_desc,
225 NULL,
226};
227
Sebastian Andrzej Siewior6fecfb02012-02-06 18:46:36 +0100228static struct usb_endpoint_descriptor gser_ss_in_desc __initdata = {
229 .bLength = USB_DT_ENDPOINT_SIZE,
230 .bDescriptorType = USB_DT_ENDPOINT,
231 .bmAttributes = USB_ENDPOINT_XFER_BULK,
232 .wMaxPacketSize = cpu_to_le16(1024),
233};
234
235static struct usb_endpoint_descriptor gser_ss_out_desc __initdata = {
236 .bLength = USB_DT_ENDPOINT_SIZE,
237 .bDescriptorType = USB_DT_ENDPOINT,
238 .bmAttributes = USB_ENDPOINT_XFER_BULK,
239 .wMaxPacketSize = cpu_to_le16(1024),
240};
241
242static struct usb_ss_ep_comp_descriptor gser_ss_bulk_comp_desc __initdata = {
243 .bLength = sizeof gser_ss_bulk_comp_desc,
244 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
245};
246
247static struct usb_descriptor_header *gser_ss_function[] __initdata = {
248 (struct usb_descriptor_header *) &gser_interface_desc,
249 (struct usb_descriptor_header *) &gser_ss_in_desc,
250 (struct usb_descriptor_header *) &gser_ss_bulk_comp_desc,
251 (struct usb_descriptor_header *) &gser_ss_out_desc,
252 (struct usb_descriptor_header *) &gser_ss_bulk_comp_desc,
253 NULL,
254};
255
David Brownell61d8bae2008-06-19 18:18:50 -0700256/* string descriptors: */
257
258static struct usb_string gser_string_defs[] = {
259 [0].s = "Generic Serial",
260 { } /* end of list */
261};
262
263static struct usb_gadget_strings gser_string_table = {
264 .language = 0x0409, /* en-us */
265 .strings = gser_string_defs,
266};
267
268static struct usb_gadget_strings *gser_strings[] = {
269 &gser_string_table,
270 NULL,
271};
272
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700273static int gport_setup(struct usb_configuration *c)
274{
275 int ret = 0;
Jack Pham427f6922011-11-23 19:42:00 -0800276 int port_idx;
277 int i;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700278
Jack Pham427f6922011-11-23 19:42:00 -0800279 pr_debug("%s: no_tty_ports: %u no_sdio_ports: %u"
Vijayavardhan Vennapusaeb8d2392012-04-03 18:58:49 +0530280 " no_smd_ports: %u no_hsic_sports: %u no_hsuart_ports: %u nr_ports: %u\n",
Jack Pham427f6922011-11-23 19:42:00 -0800281 __func__, no_tty_ports, no_sdio_ports, no_smd_ports,
Vijayavardhan Vennapusaeb8d2392012-04-03 18:58:49 +0530282 no_hsic_sports, no_hsuart_sports, nr_ports);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700283
284 if (no_tty_ports)
285 ret = gserial_setup(c->cdev->gadget, no_tty_ports);
286 if (no_sdio_ports)
287 ret = gsdio_setup(c->cdev->gadget, no_sdio_ports);
288 if (no_smd_ports)
289 ret = gsmd_setup(c->cdev->gadget, no_smd_ports);
Jack Pham427f6922011-11-23 19:42:00 -0800290 if (no_hsic_sports) {
291 port_idx = ghsic_data_setup(no_hsic_sports, USB_GADGET_SERIAL);
292 if (port_idx < 0)
293 return port_idx;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700294
Jack Pham427f6922011-11-23 19:42:00 -0800295 for (i = 0; i < nr_ports; i++) {
296 if (gserial_ports[i].transport ==
297 USB_GADGET_XPORT_HSIC) {
298 gserial_ports[i].client_port_num = port_idx;
299 port_idx++;
300 }
301 }
302
303 /*clinet port num is same for data setup and ctrl setup*/
304 ret = ghsic_ctrl_setup(no_hsic_sports, USB_GADGET_SERIAL);
305 if (ret < 0)
306 return ret;
307 return 0;
308 }
Vijayavardhan Vennapusaeb8d2392012-04-03 18:58:49 +0530309 if (no_hsuart_sports) {
310 port_idx = ghsuart_data_setup(no_hsuart_sports,
311 USB_GADGET_SERIAL);
312 if (port_idx < 0)
313 return port_idx;
314
315 for (i = 0; i < nr_ports; i++) {
316 if (gserial_ports[i].transport ==
317 USB_GADGET_XPORT_HSUART) {
318 gserial_ports[i].client_port_num = port_idx;
319 port_idx++;
320 }
321 }
322
323 return 0;
324 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700325 return ret;
326}
Manu Gautama4d993f2011-08-30 18:25:55 +0530327
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700328static int gport_connect(struct f_gser *gser)
329{
Jack Pham427f6922011-11-23 19:42:00 -0800330 unsigned port_num;
331 int ret;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700332
Jack Pham427f6922011-11-23 19:42:00 -0800333 pr_debug("%s: transport: %s f_gser: %p gserial: %p port_num: %d\n",
Hemant Kumar1b820d52011-11-03 15:08:28 -0700334 __func__, xport_to_str(gser->transport),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700335 gser, &gser->port, gser->port_num);
336
337 port_num = gserial_ports[gser->port_num].client_port_num;
338
339 switch (gser->transport) {
Hemant Kumarbffd4142011-11-03 13:20:40 -0700340 case USB_GADGET_XPORT_TTY:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700341 gserial_connect(&gser->port, port_num);
342 break;
Hemant Kumarbffd4142011-11-03 13:20:40 -0700343 case USB_GADGET_XPORT_SDIO:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700344 gsdio_connect(&gser->port, port_num);
345 break;
Hemant Kumarbffd4142011-11-03 13:20:40 -0700346 case USB_GADGET_XPORT_SMD:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700347 gsmd_connect(&gser->port, port_num);
348 break;
Jack Pham427f6922011-11-23 19:42:00 -0800349 case USB_GADGET_XPORT_HSIC:
350 ret = ghsic_ctrl_connect(&gser->port, port_num);
351 if (ret) {
352 pr_err("%s: ghsic_ctrl_connect failed: err:%d\n",
353 __func__, ret);
354 return ret;
355 }
356 ret = ghsic_data_connect(&gser->port, port_num);
357 if (ret) {
358 pr_err("%s: ghsic_data_connect failed: err:%d\n",
359 __func__, ret);
360 ghsic_ctrl_disconnect(&gser->port, port_num);
361 return ret;
362 }
363 break;
Vijayavardhan Vennapusaeb8d2392012-04-03 18:58:49 +0530364 case USB_GADGET_XPORT_HSUART:
365 ret = ghsuart_data_connect(&gser->port, port_num);
366 if (ret) {
367 pr_err("%s: ghsuart_data_connect failed: err:%d\n",
368 __func__, ret);
369 return ret;
370 }
371 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700372 default:
373 pr_err("%s: Un-supported transport: %s\n", __func__,
Hemant Kumar1b820d52011-11-03 15:08:28 -0700374 xport_to_str(gser->transport));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700375 return -ENODEV;
376 }
377
378 return 0;
379}
380
381static int gport_disconnect(struct f_gser *gser)
382{
383 unsigned port_num;
384
Jack Pham427f6922011-11-23 19:42:00 -0800385 pr_debug("%s: transport: %s f_gser: %p gserial: %p port_num: %d\n",
Hemant Kumar1b820d52011-11-03 15:08:28 -0700386 __func__, xport_to_str(gser->transport),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700387 gser, &gser->port, gser->port_num);
388
389 port_num = gserial_ports[gser->port_num].client_port_num;
390
391 switch (gser->transport) {
Hemant Kumarbffd4142011-11-03 13:20:40 -0700392 case USB_GADGET_XPORT_TTY:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700393 gserial_disconnect(&gser->port);
394 break;
Hemant Kumarbffd4142011-11-03 13:20:40 -0700395 case USB_GADGET_XPORT_SDIO:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700396 gsdio_disconnect(&gser->port, port_num);
397 break;
Hemant Kumarbffd4142011-11-03 13:20:40 -0700398 case USB_GADGET_XPORT_SMD:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700399 gsmd_disconnect(&gser->port, port_num);
400 break;
Jack Pham427f6922011-11-23 19:42:00 -0800401 case USB_GADGET_XPORT_HSIC:
402 ghsic_ctrl_disconnect(&gser->port, port_num);
403 ghsic_data_disconnect(&gser->port, port_num);
404 break;
Vijayavardhan Vennapusaeb8d2392012-04-03 18:58:49 +0530405 case USB_GADGET_XPORT_HSUART:
406 ghsuart_data_disconnect(&gser->port, port_num);
407 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700408 default:
409 pr_err("%s: Un-supported transport:%s\n", __func__,
Hemant Kumar1b820d52011-11-03 15:08:28 -0700410 xport_to_str(gser->transport));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700411 return -ENODEV;
412 }
413
414 return 0;
415}
416
417#ifdef CONFIG_MODEM_SUPPORT
418static void gser_complete_set_line_coding(struct usb_ep *ep,
419 struct usb_request *req)
420{
421 struct f_gser *gser = ep->driver_data;
422 struct usb_composite_dev *cdev = gser->port.func.config->cdev;
423
424 if (req->status != 0) {
425 DBG(cdev, "gser ttyGS%d completion, err %d\n",
426 gser->port_num, req->status);
427 return;
428 }
429
430 /* normal completion */
431 if (req->actual != sizeof(gser->port_line_coding)) {
432 DBG(cdev, "gser ttyGS%d short resp, len %d\n",
433 gser->port_num, req->actual);
434 usb_ep_set_halt(ep);
435 } else {
436 struct usb_cdc_line_coding *value = req->buf;
437 gser->port_line_coding = *value;
438 }
439}
David Brownell61d8bae2008-06-19 18:18:50 -0700440/*-------------------------------------------------------------------------*/
441
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700442static int
443gser_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
444{
445 struct f_gser *gser = func_to_gser(f);
446 struct usb_composite_dev *cdev = f->config->cdev;
447 struct usb_request *req = cdev->req;
448 int value = -EOPNOTSUPP;
449 u16 w_index = le16_to_cpu(ctrl->wIndex);
450 u16 w_value = le16_to_cpu(ctrl->wValue);
451 u16 w_length = le16_to_cpu(ctrl->wLength);
452
453 switch ((ctrl->bRequestType << 8) | ctrl->bRequest) {
454
455 /* SET_LINE_CODING ... just read and save what the host sends */
456 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
457 | USB_CDC_REQ_SET_LINE_CODING:
458 if (w_length != sizeof(struct usb_cdc_line_coding))
459 goto invalid;
460
461 value = w_length;
462 cdev->gadget->ep0->driver_data = gser;
463 req->complete = gser_complete_set_line_coding;
464 break;
465
466 /* GET_LINE_CODING ... return what host sent, or initial value */
467 case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
468 | USB_CDC_REQ_GET_LINE_CODING:
469 value = min_t(unsigned, w_length,
470 sizeof(struct usb_cdc_line_coding));
471 memcpy(req->buf, &gser->port_line_coding, value);
472 break;
473
474 /* SET_CONTROL_LINE_STATE ... save what the host sent */
475 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
476 | USB_CDC_REQ_SET_CONTROL_LINE_STATE:
477
478 value = 0;
479 gser->port_handshake_bits = w_value;
480 if (gser->port.notify_modem) {
481 unsigned port_num =
482 gserial_ports[gser->port_num].client_port_num;
483
484 gser->port.notify_modem(&gser->port,
485 port_num, w_value);
486 }
487 break;
488
489 default:
490invalid:
491 DBG(cdev, "invalid control req%02x.%02x v%04x i%04x l%d\n",
492 ctrl->bRequestType, ctrl->bRequest,
493 w_value, w_index, w_length);
494 }
495
496 /* respond with data transfer or status phase? */
497 if (value >= 0) {
498 DBG(cdev, "gser ttyGS%d req%02x.%02x v%04x i%04x l%d\n",
499 gser->port_num, ctrl->bRequestType, ctrl->bRequest,
500 w_value, w_index, w_length);
501 req->zero = 0;
502 req->length = value;
503 value = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC);
504 if (value < 0)
505 ERROR(cdev, "gser response on ttyGS%d, err %d\n",
506 gser->port_num, value);
507 }
508
509 /* device either stalls (value < 0) or reports success */
510 return value;
511}
512#endif
David Brownell61d8bae2008-06-19 18:18:50 -0700513static int gser_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
514{
515 struct f_gser *gser = func_to_gser(f);
516 struct usb_composite_dev *cdev = f->config->cdev;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700517 int rc = 0;
David Brownell61d8bae2008-06-19 18:18:50 -0700518
519 /* we know alt == 0, so this is an activation or a reset */
520
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700521#ifdef CONFIG_MODEM_SUPPORT
522 if (gser->notify->driver_data) {
523 DBG(cdev, "reset generic ctl ttyGS%d\n", gser->port_num);
524 usb_ep_disable(gser->notify);
David Brownell61d8bae2008-06-19 18:18:50 -0700525 }
Tatyana Brokhman31ac3522011-06-28 15:33:50 +0200526
527 if (!gser->notify->desc) {
528 if (config_ep_by_speed(cdev->gadget, f, gser->notify)) {
529 gser->notify->desc = NULL;
530 return -EINVAL;
531 }
532 }
Tatyana Brokhmancf709c12011-06-28 16:33:48 +0300533 rc = usb_ep_enable(gser->notify);
Tatyana Brokhman31ac3522011-06-28 15:33:50 +0200534
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700535 if (rc) {
536 ERROR(cdev, "can't enable %s, result %d\n",
537 gser->notify->name, rc);
538 return rc;
539 }
540 gser->notify->driver_data = gser;
541#endif
542
David Brownell61d8bae2008-06-19 18:18:50 -0700543 if (gser->port.in->driver_data) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700544 DBG(cdev, "reset generic data ttyGS%d\n", gser->port_num);
545 gport_disconnect(gser);
Tatyana Brokhmanea2a1df72011-06-28 16:33:50 +0300546 }
547 if (!gser->port.in->desc || !gser->port.out->desc) {
David Brownell61d8bae2008-06-19 18:18:50 -0700548 DBG(cdev, "activate generic ttyGS%d\n", gser->port_num);
Robert Jarzmikfef69642011-11-18 20:16:27 +0100549 if (config_ep_by_speed(cdev->gadget, f, gser->port.in) ||
550 config_ep_by_speed(cdev->gadget, f, gser->port.out)) {
Tatyana Brokhmanea2a1df72011-06-28 16:33:50 +0300551 gser->port.in->desc = NULL;
552 gser->port.out->desc = NULL;
553 return -EINVAL;
554 }
David Brownell61d8bae2008-06-19 18:18:50 -0700555 }
David Brownac5d1542012-02-06 10:37:22 -0800556
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700557 gport_connect(gser);
558
559 gser->online = 1;
560 return rc;
David Brownell61d8bae2008-06-19 18:18:50 -0700561}
562
563static void gser_disable(struct usb_function *f)
564{
565 struct f_gser *gser = func_to_gser(f);
566 struct usb_composite_dev *cdev = f->config->cdev;
567
568 DBG(cdev, "generic ttyGS%d deactivated\n", gser->port_num);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700569
570 gport_disconnect(gser);
571
572#ifdef CONFIG_MODEM_SUPPORT
573 usb_ep_fifo_flush(gser->notify);
574 usb_ep_disable(gser->notify);
Chiranjeevi Velempati4fd1c162012-08-01 09:41:22 +0530575 gser->notify->driver_data = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700576#endif
577 gser->online = 0;
578}
579#ifdef CONFIG_MODEM_SUPPORT
580static int gser_notify(struct f_gser *gser, u8 type, u16 value,
581 void *data, unsigned length)
582{
583 struct usb_ep *ep = gser->notify;
584 struct usb_request *req;
585 struct usb_cdc_notification *notify;
586 const unsigned len = sizeof(*notify) + length;
587 void *buf;
588 int status;
589 struct usb_composite_dev *cdev = gser->port.func.config->cdev;
590
591 req = gser->notify_req;
592 gser->notify_req = NULL;
593 gser->pending = false;
594
595 req->length = len;
596 notify = req->buf;
597 buf = notify + 1;
598
599 notify->bmRequestType = USB_DIR_IN | USB_TYPE_CLASS
600 | USB_RECIP_INTERFACE;
601 notify->bNotificationType = type;
602 notify->wValue = cpu_to_le16(value);
603 notify->wIndex = cpu_to_le16(gser->data_id);
604 notify->wLength = cpu_to_le16(length);
605 memcpy(buf, data, length);
606
607 status = usb_ep_queue(ep, req, GFP_ATOMIC);
608 if (status < 0) {
609 ERROR(cdev, "gser ttyGS%d can't notify serial state, %d\n",
610 gser->port_num, status);
611 gser->notify_req = req;
612 }
613
614 return status;
David Brownell61d8bae2008-06-19 18:18:50 -0700615}
616
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700617static int gser_notify_serial_state(struct f_gser *gser)
618{
619 int status;
620 unsigned long flags;
621 struct usb_composite_dev *cdev = gser->port.func.config->cdev;
622
623 spin_lock_irqsave(&gser->lock, flags);
624 if (gser->notify_req) {
625 DBG(cdev, "gser ttyGS%d serial state %04x\n",
626 gser->port_num, gser->serial_state);
627 status = gser_notify(gser, USB_CDC_NOTIFY_SERIAL_STATE,
628 0, &gser->serial_state,
629 sizeof(gser->serial_state));
630 } else {
631 gser->pending = true;
632 status = 0;
633 }
634 spin_unlock_irqrestore(&gser->lock, flags);
635 return status;
636}
637
638static void gser_notify_complete(struct usb_ep *ep, struct usb_request *req)
639{
640 struct f_gser *gser = req->context;
641 u8 doit = false;
642 unsigned long flags;
643
644 /* on this call path we do NOT hold the port spinlock,
645 * which is why ACM needs its own spinlock
646 */
647 spin_lock_irqsave(&gser->lock, flags);
648 if (req->status != -ESHUTDOWN)
649 doit = gser->pending;
650 gser->notify_req = req;
651 spin_unlock_irqrestore(&gser->lock, flags);
652
653 if (doit && gser->online)
654 gser_notify_serial_state(gser);
655}
656static void gser_connect(struct gserial *port)
657{
658 struct f_gser *gser = port_to_gser(port);
659
660 gser->serial_state |= ACM_CTRL_DSR | ACM_CTRL_DCD;
661 gser_notify_serial_state(gser);
662}
663
664unsigned int gser_get_dtr(struct gserial *port)
665{
666 struct f_gser *gser = port_to_gser(port);
667
668 if (gser->port_handshake_bits & ACM_CTRL_DTR)
669 return 1;
670 else
671 return 0;
672}
673
674unsigned int gser_get_rts(struct gserial *port)
675{
676 struct f_gser *gser = port_to_gser(port);
677
678 if (gser->port_handshake_bits & ACM_CTRL_RTS)
679 return 1;
680 else
681 return 0;
682}
683
684unsigned int gser_send_carrier_detect(struct gserial *port, unsigned int yes)
685{
686 struct f_gser *gser = port_to_gser(port);
687 u16 state;
688
689 state = gser->serial_state;
690 state &= ~ACM_CTRL_DCD;
691 if (yes)
692 state |= ACM_CTRL_DCD;
693
694 gser->serial_state = state;
695 return gser_notify_serial_state(gser);
696
697}
698
699unsigned int gser_send_ring_indicator(struct gserial *port, unsigned int yes)
700{
701 struct f_gser *gser = port_to_gser(port);
702 u16 state;
703
704 state = gser->serial_state;
705 state &= ~ACM_CTRL_RI;
706 if (yes)
707 state |= ACM_CTRL_RI;
708
709 gser->serial_state = state;
710 return gser_notify_serial_state(gser);
711
712}
713static void gser_disconnect(struct gserial *port)
714{
715 struct f_gser *gser = port_to_gser(port);
716
717 gser->serial_state &= ~(ACM_CTRL_DSR | ACM_CTRL_DCD);
718 gser_notify_serial_state(gser);
719}
720
721static int gser_send_break(struct gserial *port, int duration)
722{
723 struct f_gser *gser = port_to_gser(port);
724 u16 state;
725
726 state = gser->serial_state;
727 state &= ~ACM_CTRL_BRK;
728 if (duration)
729 state |= ACM_CTRL_BRK;
730
731 gser->serial_state = state;
732 return gser_notify_serial_state(gser);
733}
734
735static int gser_send_modem_ctrl_bits(struct gserial *port, int ctrl_bits)
736{
737 struct f_gser *gser = port_to_gser(port);
738
739 gser->serial_state = ctrl_bits;
740
741 return gser_notify_serial_state(gser);
742}
743#endif
David Brownell61d8bae2008-06-19 18:18:50 -0700744/*-------------------------------------------------------------------------*/
745
746/* serial function driver setup/binding */
747
Manu Gautama4d993f2011-08-30 18:25:55 +0530748static int
David Brownell61d8bae2008-06-19 18:18:50 -0700749gser_bind(struct usb_configuration *c, struct usb_function *f)
750{
751 struct usb_composite_dev *cdev = c->cdev;
752 struct f_gser *gser = func_to_gser(f);
753 int status;
754 struct usb_ep *ep;
755
756 /* allocate instance-specific interface IDs */
757 status = usb_interface_id(c, f);
758 if (status < 0)
759 goto fail;
760 gser->data_id = status;
761 gser_interface_desc.bInterfaceNumber = status;
762
763 status = -ENODEV;
764
765 /* allocate instance-specific endpoints */
766 ep = usb_ep_autoconfig(cdev->gadget, &gser_fs_in_desc);
767 if (!ep)
768 goto fail;
769 gser->port.in = ep;
770 ep->driver_data = cdev; /* claim */
771
772 ep = usb_ep_autoconfig(cdev->gadget, &gser_fs_out_desc);
773 if (!ep)
774 goto fail;
775 gser->port.out = ep;
776 ep->driver_data = cdev; /* claim */
777
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700778#ifdef CONFIG_MODEM_SUPPORT
779 ep = usb_ep_autoconfig(cdev->gadget, &gser_fs_notify_desc);
780 if (!ep)
781 goto fail;
782 gser->notify = ep;
783 ep->driver_data = cdev; /* claim */
784 /* allocate notification */
785 gser->notify_req = gs_alloc_req(ep,
786 sizeof(struct usb_cdc_notification) + 2,
787 GFP_KERNEL);
788 if (!gser->notify_req)
789 goto fail;
790
791 gser->notify_req->complete = gser_notify_complete;
792 gser->notify_req->context = gser;
793#endif
794
David Brownell61d8bae2008-06-19 18:18:50 -0700795 /* copy descriptors, and track endpoint copies */
796 f->descriptors = usb_copy_descriptors(gser_fs_function);
797
Pavankumar Kondetif0f95d82011-09-23 11:38:57 +0530798 if (!f->descriptors)
799 goto fail;
800
David Brownell61d8bae2008-06-19 18:18:50 -0700801 /* support all relevant hardware speeds... we expect that when
802 * hardware is dual speed, all bulk-capable endpoints work at
803 * both speeds
804 */
805 if (gadget_is_dualspeed(c->cdev->gadget)) {
806 gser_hs_in_desc.bEndpointAddress =
807 gser_fs_in_desc.bEndpointAddress;
808 gser_hs_out_desc.bEndpointAddress =
809 gser_fs_out_desc.bEndpointAddress;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700810#ifdef CONFIG_MODEM_SUPPORT
811 gser_hs_notify_desc.bEndpointAddress =
812 gser_fs_notify_desc.bEndpointAddress;
813#endif
David Brownell61d8bae2008-06-19 18:18:50 -0700814
815 /* copy descriptors, and track endpoint copies */
816 f->hs_descriptors = usb_copy_descriptors(gser_hs_function);
817
Pavankumar Kondetif0f95d82011-09-23 11:38:57 +0530818 if (!f->hs_descriptors)
819 goto fail;
820
David Brownell61d8bae2008-06-19 18:18:50 -0700821 }
Sebastian Andrzej Siewior6fecfb02012-02-06 18:46:36 +0100822 if (gadget_is_superspeed(c->cdev->gadget)) {
823 gser_ss_in_desc.bEndpointAddress =
824 gser_fs_in_desc.bEndpointAddress;
825 gser_ss_out_desc.bEndpointAddress =
826 gser_fs_out_desc.bEndpointAddress;
827
828 /* copy descriptors, and track endpoint copies */
829 f->ss_descriptors = usb_copy_descriptors(gser_ss_function);
830 if (!f->ss_descriptors)
831 goto fail;
832 }
David Brownell61d8bae2008-06-19 18:18:50 -0700833
834 DBG(cdev, "generic ttyGS%d: %s speed IN/%s OUT/%s\n",
835 gser->port_num,
Sebastian Andrzej Siewior6fecfb02012-02-06 18:46:36 +0100836 gadget_is_superspeed(c->cdev->gadget) ? "super" :
David Brownell61d8bae2008-06-19 18:18:50 -0700837 gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full",
838 gser->port.in->name, gser->port.out->name);
839 return 0;
840
841fail:
Pavankumar Kondetif0f95d82011-09-23 11:38:57 +0530842 if (f->descriptors)
843 usb_free_descriptors(f->descriptors);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700844#ifdef CONFIG_MODEM_SUPPORT
845 if (gser->notify_req)
846 gs_free_req(gser->notify, gser->notify_req);
847
848 /* we might as well release our claims on endpoints */
849 if (gser->notify)
850 gser->notify->driver_data = NULL;
851#endif
David Brownell61d8bae2008-06-19 18:18:50 -0700852 /* we might as well release our claims on endpoints */
853 if (gser->port.out)
854 gser->port.out->driver_data = NULL;
855 if (gser->port.in)
856 gser->port.in->driver_data = NULL;
857
858 ERROR(cdev, "%s: can't bind, err %d\n", f->name, status);
859
860 return status;
861}
862
863static void
864gser_unbind(struct usb_configuration *c, struct usb_function *f)
865{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700866#ifdef CONFIG_MODEM_SUPPORT
867 struct f_gser *gser = func_to_gser(f);
868#endif
David Brownell61d8bae2008-06-19 18:18:50 -0700869 if (gadget_is_dualspeed(c->cdev->gadget))
870 usb_free_descriptors(f->hs_descriptors);
Sebastian Andrzej Siewior6fecfb02012-02-06 18:46:36 +0100871 if (gadget_is_superspeed(c->cdev->gadget))
872 usb_free_descriptors(f->ss_descriptors);
David Brownell61d8bae2008-06-19 18:18:50 -0700873 usb_free_descriptors(f->descriptors);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700874#ifdef CONFIG_MODEM_SUPPORT
875 gs_free_req(gser->notify, gser->notify_req);
876#endif
David Brownell61d8bae2008-06-19 18:18:50 -0700877 kfree(func_to_gser(f));
878}
879
880/**
881 * gser_bind_config - add a generic serial function to a configuration
882 * @c: the configuration to support the serial instance
883 * @port_num: /dev/ttyGS* port this interface will use
884 * Context: single threaded during gadget setup
885 *
886 * Returns zero on success, else negative errno.
887 *
888 * Caller must have called @gserial_setup() with enough ports to
889 * handle all the ones it binds. Caller is also responsible
890 * for calling @gserial_cleanup() before module unload.
891 */
Manu Gautama4d993f2011-08-30 18:25:55 +0530892int gser_bind_config(struct usb_configuration *c, u8 port_num)
David Brownell61d8bae2008-06-19 18:18:50 -0700893{
894 struct f_gser *gser;
895 int status;
896
897 /* REVISIT might want instance-specific strings to help
898 * distinguish instances ...
899 */
900
901 /* maybe allocate device-global string ID */
902 if (gser_string_defs[0].id == 0) {
903 status = usb_string_id(c->cdev);
904 if (status < 0)
905 return status;
906 gser_string_defs[0].id = status;
907 }
908
909 /* allocate and initialize one new instance */
910 gser = kzalloc(sizeof *gser, GFP_KERNEL);
911 if (!gser)
912 return -ENOMEM;
913
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700914#ifdef CONFIG_MODEM_SUPPORT
915 spin_lock_init(&gser->lock);
916#endif
David Brownell61d8bae2008-06-19 18:18:50 -0700917 gser->port_num = port_num;
918
919 gser->port.func.name = "gser";
920 gser->port.func.strings = gser_strings;
921 gser->port.func.bind = gser_bind;
922 gser->port.func.unbind = gser_unbind;
923 gser->port.func.set_alt = gser_set_alt;
924 gser->port.func.disable = gser_disable;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700925 gser->transport = gserial_ports[port_num].transport;
926#ifdef CONFIG_MODEM_SUPPORT
Vijayavardhan Vennapusaeb8d2392012-04-03 18:58:49 +0530927 /* We support only three ports for now */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700928 if (port_num == 0)
929 gser->port.func.name = "modem";
Vijayavardhan Vennapusaeb8d2392012-04-03 18:58:49 +0530930 else if (port_num == 1)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700931 gser->port.func.name = "nmea";
Vijayavardhan Vennapusaeb8d2392012-04-03 18:58:49 +0530932 else
933 gser->port.func.name = "modem2";
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700934 gser->port.func.setup = gser_setup;
935 gser->port.connect = gser_connect;
936 gser->port.get_dtr = gser_get_dtr;
937 gser->port.get_rts = gser_get_rts;
938 gser->port.send_carrier_detect = gser_send_carrier_detect;
939 gser->port.send_ring_indicator = gser_send_ring_indicator;
940 gser->port.send_modem_ctrl_bits = gser_send_modem_ctrl_bits;
941 gser->port.disconnect = gser_disconnect;
942 gser->port.send_break = gser_send_break;
943#endif
David Brownell61d8bae2008-06-19 18:18:50 -0700944
945 status = usb_add_function(c, &gser->port.func);
946 if (status)
947 kfree(gser);
948 return status;
949}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700950
Manu Gautama4d993f2011-08-30 18:25:55 +0530951/**
952 * gserial_init_port - bind a gserial_port to its transport
953 */
954static int gserial_init_port(int port_num, const char *name)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700955{
Manu Gautama4d993f2011-08-30 18:25:55 +0530956 enum transport_type transport;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700957
Manu Gautama4d993f2011-08-30 18:25:55 +0530958 if (port_num >= GSERIAL_NO_PORTS)
959 return -ENODEV;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700960
Hemant Kumar1b820d52011-11-03 15:08:28 -0700961 transport = str_to_xport(name);
Manu Gautama4d993f2011-08-30 18:25:55 +0530962 pr_debug("%s, port:%d, transport:%s\n", __func__,
Jack Pham427f6922011-11-23 19:42:00 -0800963 port_num, xport_to_str(transport));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700964
Manu Gautama4d993f2011-08-30 18:25:55 +0530965 gserial_ports[port_num].transport = transport;
966 gserial_ports[port_num].port_num = port_num;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700967
Manu Gautama4d993f2011-08-30 18:25:55 +0530968 switch (transport) {
Hemant Kumarbffd4142011-11-03 13:20:40 -0700969 case USB_GADGET_XPORT_TTY:
Manu Gautama4d993f2011-08-30 18:25:55 +0530970 gserial_ports[port_num].client_port_num = no_tty_ports;
971 no_tty_ports++;
972 break;
Hemant Kumarbffd4142011-11-03 13:20:40 -0700973 case USB_GADGET_XPORT_SDIO:
Manu Gautama4d993f2011-08-30 18:25:55 +0530974 gserial_ports[port_num].client_port_num = no_sdio_ports;
975 no_sdio_ports++;
976 break;
Hemant Kumarbffd4142011-11-03 13:20:40 -0700977 case USB_GADGET_XPORT_SMD:
Manu Gautama4d993f2011-08-30 18:25:55 +0530978 gserial_ports[port_num].client_port_num = no_smd_ports;
979 no_smd_ports++;
980 break;
Jack Pham427f6922011-11-23 19:42:00 -0800981 case USB_GADGET_XPORT_HSIC:
982 /*client port number will be updated in gport_setup*/
983 no_hsic_sports++;
984 break;
Vijayavardhan Vennapusaeb8d2392012-04-03 18:58:49 +0530985 case USB_GADGET_XPORT_HSUART:
986 /*client port number will be updated in gport_setup*/
987 no_hsuart_sports++;
988 break;
Manu Gautama4d993f2011-08-30 18:25:55 +0530989 default:
990 pr_err("%s: Un-supported transport transport: %u\n",
991 __func__, gserial_ports[port_num].transport);
992 return -ENODEV;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700993 }
994
Manu Gautama4d993f2011-08-30 18:25:55 +0530995 nr_ports++;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700996
997 return 0;
998}