diff options
Diffstat (limited to 'drivers/usb/serial')
-rw-r--r-- | drivers/usb/serial/Kconfig | 25 | ||||
-rw-r--r-- | drivers/usb/serial/Makefile | 2 | ||||
-rw-r--r-- | drivers/usb/serial/aircable.c | 625 | ||||
-rw-r--r-- | drivers/usb/serial/airprime.c | 261 | ||||
-rw-r--r-- | drivers/usb/serial/ark3116.c | 233 | ||||
-rw-r--r-- | drivers/usb/serial/cypress_m8.c | 129 | ||||
-rw-r--r-- | drivers/usb/serial/ftdi_sio.c | 30 | ||||
-rw-r--r-- | drivers/usb/serial/garmin_gps.c | 219 | ||||
-rw-r--r-- | drivers/usb/serial/ipaq.c | 38 | ||||
-rw-r--r-- | drivers/usb/serial/mos7840.c | 2962 | ||||
-rw-r--r-- | drivers/usb/serial/pl2303.c | 827 | ||||
-rw-r--r-- | drivers/usb/serial/pl2303.h | 4 | ||||
-rw-r--r-- | drivers/usb/serial/usb-serial.c | 28 |
13 files changed, 4719 insertions, 664 deletions
diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig index f5b9438c94f0..5076b9d97057 100644 --- a/drivers/usb/serial/Kconfig +++ b/drivers/usb/serial/Kconfig | |||
@@ -53,6 +53,15 @@ config USB_SERIAL_GENERIC | |||
53 | support" be compiled as a module for this driver to be used | 53 | support" be compiled as a module for this driver to be used |
54 | properly. | 54 | properly. |
55 | 55 | ||
56 | config USB_SERIAL_AIRCABLE | ||
57 | tristate "AIRcable USB Bluetooth Dongle Driver (EXPERIMENTAL)" | ||
58 | depends on USB_SERIAL && EXPERIMENTAL | ||
59 | help | ||
60 | Say Y here if you want to use AIRcable USB Bluetoot Dongle. | ||
61 | |||
62 | To compile this driver as a module, choose M here: the module | ||
63 | will be called aircable. | ||
64 | |||
56 | config USB_SERIAL_AIRPRIME | 65 | config USB_SERIAL_AIRPRIME |
57 | tristate "USB AirPrime CDMA Wireless Driver" | 66 | tristate "USB AirPrime CDMA Wireless Driver" |
58 | depends on USB_SERIAL | 67 | depends on USB_SERIAL |
@@ -413,6 +422,21 @@ config USB_SERIAL_MCT_U232 | |||
413 | To compile this driver as a module, choose M here: the | 422 | To compile this driver as a module, choose M here: the |
414 | module will be called mct_u232. | 423 | module will be called mct_u232. |
415 | 424 | ||
425 | config USB_SERIAL_MOS7840 | ||
426 | tristate "USB Moschip 7840/7820 USB Serial Driver" | ||
427 | depends on USB_SERIAL | ||
428 | ---help--- | ||
429 | Say Y here if you want to use a MCS7840 Quad-Serial or MCS7820 | ||
430 | Dual-Serial port device from MosChip Semiconductor. | ||
431 | |||
432 | The MCS7840 and MCS7820 have been developed to connect a wide range | ||
433 | of standard serial devices to a USB host. The MCS7840 has a USB | ||
434 | device controller connected to four (4) individual UARTs while the | ||
435 | MCS7820 controller connects to two (2) individual UARTs. | ||
436 | |||
437 | To compile this driver as a module, choose M here: the | ||
438 | module will be called mos7840. If unsure, choose N. | ||
439 | |||
416 | config USB_SERIAL_NAVMAN | 440 | config USB_SERIAL_NAVMAN |
417 | tristate "USB Navman GPS device" | 441 | tristate "USB Navman GPS device" |
418 | depends on USB_SERIAL | 442 | depends on USB_SERIAL |
@@ -526,5 +550,6 @@ config USB_EZUSB | |||
526 | depends on USB_SERIAL_KEYSPAN_PDA || USB_SERIAL_XIRCOM || USB_SERIAL_KEYSPAN || USB_SERIAL_WHITEHEAT | 550 | depends on USB_SERIAL_KEYSPAN_PDA || USB_SERIAL_XIRCOM || USB_SERIAL_KEYSPAN || USB_SERIAL_WHITEHEAT |
527 | default y | 551 | default y |
528 | 552 | ||
553 | |||
529 | endmenu | 554 | endmenu |
530 | 555 | ||
diff --git a/drivers/usb/serial/Makefile b/drivers/usb/serial/Makefile index 8efed2ce1ba3..8dce83340e31 100644 --- a/drivers/usb/serial/Makefile +++ b/drivers/usb/serial/Makefile | |||
@@ -11,6 +11,7 @@ usbserial-obj-$(CONFIG_USB_EZUSB) += ezusb.o | |||
11 | 11 | ||
12 | usbserial-objs := usb-serial.o generic.o bus.o $(usbserial-obj-y) | 12 | usbserial-objs := usb-serial.o generic.o bus.o $(usbserial-obj-y) |
13 | 13 | ||
14 | obj-$(CONFIG_USB_SERIAL_AIRCABLE) += aircable.o | ||
14 | obj-$(CONFIG_USB_SERIAL_AIRPRIME) += airprime.o | 15 | obj-$(CONFIG_USB_SERIAL_AIRPRIME) += airprime.o |
15 | obj-$(CONFIG_USB_SERIAL_ARK3116) += ark3116.o | 16 | obj-$(CONFIG_USB_SERIAL_ARK3116) += ark3116.o |
16 | obj-$(CONFIG_USB_SERIAL_BELKIN) += belkin_sa.o | 17 | obj-$(CONFIG_USB_SERIAL_BELKIN) += belkin_sa.o |
@@ -33,6 +34,7 @@ obj-$(CONFIG_USB_SERIAL_KEYSPAN_PDA) += keyspan_pda.o | |||
33 | obj-$(CONFIG_USB_SERIAL_KLSI) += kl5kusb105.o | 34 | obj-$(CONFIG_USB_SERIAL_KLSI) += kl5kusb105.o |
34 | obj-$(CONFIG_USB_SERIAL_KOBIL_SCT) += kobil_sct.o | 35 | obj-$(CONFIG_USB_SERIAL_KOBIL_SCT) += kobil_sct.o |
35 | obj-$(CONFIG_USB_SERIAL_MCT_U232) += mct_u232.o | 36 | obj-$(CONFIG_USB_SERIAL_MCT_U232) += mct_u232.o |
37 | obj-$(CONFIG_USB_SERIAL_MOS7840) += mos7840.o | ||
36 | obj-$(CONFIG_USB_SERIAL_NAVMAN) += navman.o | 38 | obj-$(CONFIG_USB_SERIAL_NAVMAN) += navman.o |
37 | obj-$(CONFIG_USB_SERIAL_OMNINET) += omninet.o | 39 | obj-$(CONFIG_USB_SERIAL_OMNINET) += omninet.o |
38 | obj-$(CONFIG_USB_SERIAL_OPTION) += option.o | 40 | obj-$(CONFIG_USB_SERIAL_OPTION) += option.o |
diff --git a/drivers/usb/serial/aircable.c b/drivers/usb/serial/aircable.c new file mode 100644 index 000000000000..2ccd9ded52a5 --- /dev/null +++ b/drivers/usb/serial/aircable.c | |||
@@ -0,0 +1,625 @@ | |||
1 | /* | ||
2 | * AIRcable USB Bluetooth Dongle Driver. | ||
3 | * | ||
4 | * Copyright (C) 2006 Manuel Francisco Naranjo (naranjo.manuel@gmail.com) | ||
5 | * This program is free software; you can redistribute it and/or modify it under | ||
6 | * the terms of the GNU General Public License version 2 as published by the | ||
7 | * Free Software Foundation. | ||
8 | * | ||
9 | * The device works as an standard CDC device, it has 2 interfaces, the first | ||
10 | * one is for firmware access and the second is the serial one. | ||
11 | * The protocol is very simply, there are two posibilities reading or writing. | ||
12 | * When writting the first urb must have a Header that starts with 0x20 0x29 the | ||
13 | * next two bytes must say how much data will be sended. | ||
14 | * When reading the process is almost equal except that the header starts with | ||
15 | * 0x00 0x20. | ||
16 | * | ||
17 | * The device simply need some stuff to understand data comming from the usb | ||
18 | * buffer: The First and Second byte is used for a Header, the Third and Fourth | ||
19 | * tells the device the amount of information the package holds. | ||
20 | * Packages are 60 bytes long Header Stuff. | ||
21 | * When writting to the device the first two bytes of the header are 0x20 0x29 | ||
22 | * When reading the bytes are 0x00 0x20, or 0x00 0x10, there is an strange | ||
23 | * situation, when too much data arrives to the device because it sends the data | ||
24 | * but with out the header. I will use a simply hack to override this situation, | ||
25 | * if there is data coming that does not contain any header, then that is data | ||
26 | * that must go directly to the tty, as there is no documentation about if there | ||
27 | * is any other control code, I will simply check for the first | ||
28 | * one. | ||
29 | * | ||
30 | * The driver registers himself with the USB-serial core and the USB Core. I had | ||
31 | * to implement a probe function agains USB-serial, because other way, the | ||
32 | * driver was attaching himself to both interfaces. I have tryed with different | ||
33 | * configurations of usb_serial_driver with out exit, only the probe function | ||
34 | * could handle this correctly. | ||
35 | * | ||
36 | * I have taken some info from a Greg Kroah-Hartman article: | ||
37 | * http://www.linuxjournal.com/article/6573 | ||
38 | * And from Linux Device Driver Kit CD, which is a great work, the authors taken | ||
39 | * the work to recompile lots of information an knowladge in drivers development | ||
40 | * and made it all avaible inside a cd. | ||
41 | * URL: http://kernel.org/pub/linux/kernel/people/gregkh/ddk/ | ||
42 | * | ||
43 | */ | ||
44 | |||
45 | #include <linux/tty.h> | ||
46 | #include <linux/tty_flip.h> | ||
47 | #include <linux/circ_buf.h> | ||
48 | #include <linux/usb.h> | ||
49 | #include <linux/usb/serial.h> | ||
50 | |||
51 | static int debug; | ||
52 | |||
53 | /* Vendor and Product ID */ | ||
54 | #define AIRCABLE_VID 0x16CA | ||
55 | #define AIRCABLE_USB_PID 0x1502 | ||
56 | |||
57 | /* write buffer size defines */ | ||
58 | #define AIRCABLE_BUF_SIZE 2048 | ||
59 | |||
60 | /* Protocol Stuff */ | ||
61 | #define HCI_HEADER_LENGTH 0x4 | ||
62 | #define TX_HEADER_0 0x20 | ||
63 | #define TX_HEADER_1 0x29 | ||
64 | #define RX_HEADER_0 0x00 | ||
65 | #define RX_HEADER_1 0x20 | ||
66 | #define MAX_HCI_FRAMESIZE 60 | ||
67 | #define HCI_COMPLETE_FRAME 64 | ||
68 | |||
69 | /* rx_flags */ | ||
70 | #define THROTTLED 0x01 | ||
71 | #define ACTUALLY_THROTTLED 0x02 | ||
72 | |||
73 | /* | ||
74 | * Version Information | ||
75 | */ | ||
76 | #define DRIVER_VERSION "v1.0b2" | ||
77 | #define DRIVER_AUTHOR "Naranjo, Manuel Francisco <naranjo.manuel@gmail.com>" | ||
78 | #define DRIVER_DESC "AIRcable USB Driver" | ||
79 | |||
80 | /* ID table that will be registered with USB core */ | ||
81 | static struct usb_device_id id_table [] = { | ||
82 | { USB_DEVICE(AIRCABLE_VID, AIRCABLE_USB_PID) }, | ||
83 | { }, | ||
84 | }; | ||
85 | MODULE_DEVICE_TABLE(usb, id_table); | ||
86 | |||
87 | |||
88 | /* Internal Structure */ | ||
89 | struct aircable_private { | ||
90 | spinlock_t rx_lock; /* spinlock for the receive lines */ | ||
91 | struct circ_buf *tx_buf; /* write buffer */ | ||
92 | struct circ_buf *rx_buf; /* read buffer */ | ||
93 | int rx_flags; /* for throttilng */ | ||
94 | struct work_struct rx_work; /* work cue for the receiving line */ | ||
95 | }; | ||
96 | |||
97 | /* Private methods */ | ||
98 | |||
99 | /* Circular Buffer Methods, code from ti_usb_3410_5052 used */ | ||
100 | /* | ||
101 | * serial_buf_clear | ||
102 | * | ||
103 | * Clear out all data in the circular buffer. | ||
104 | */ | ||
105 | static void serial_buf_clear(struct circ_buf *cb) | ||
106 | { | ||
107 | cb->head = cb->tail = 0; | ||
108 | } | ||
109 | |||
110 | /* | ||
111 | * serial_buf_alloc | ||
112 | * | ||
113 | * Allocate a circular buffer and all associated memory. | ||
114 | */ | ||
115 | static struct circ_buf *serial_buf_alloc(void) | ||
116 | { | ||
117 | struct circ_buf *cb; | ||
118 | cb = kmalloc(sizeof(struct circ_buf), GFP_KERNEL); | ||
119 | if (cb == NULL) | ||
120 | return NULL; | ||
121 | cb->buf = kmalloc(AIRCABLE_BUF_SIZE, GFP_KERNEL); | ||
122 | if (cb->buf == NULL) { | ||
123 | kfree(cb); | ||
124 | return NULL; | ||
125 | } | ||
126 | serial_buf_clear(cb); | ||
127 | return cb; | ||
128 | } | ||
129 | |||
130 | /* | ||
131 | * serial_buf_free | ||
132 | * | ||
133 | * Free the buffer and all associated memory. | ||
134 | */ | ||
135 | static void serial_buf_free(struct circ_buf *cb) | ||
136 | { | ||
137 | kfree(cb->buf); | ||
138 | kfree(cb); | ||
139 | } | ||
140 | |||
141 | /* | ||
142 | * serial_buf_data_avail | ||
143 | * | ||
144 | * Return the number of bytes of data available in the circular | ||
145 | * buffer. | ||
146 | */ | ||
147 | static int serial_buf_data_avail(struct circ_buf *cb) | ||
148 | { | ||
149 | return CIRC_CNT(cb->head,cb->tail,AIRCABLE_BUF_SIZE); | ||
150 | } | ||
151 | |||
152 | /* | ||
153 | * serial_buf_put | ||
154 | * | ||
155 | * Copy data data from a user buffer and put it into the circular buffer. | ||
156 | * Restrict to the amount of space available. | ||
157 | * | ||
158 | * Return the number of bytes copied. | ||
159 | */ | ||
160 | static int serial_buf_put(struct circ_buf *cb, const char *buf, int count) | ||
161 | { | ||
162 | int c, ret = 0; | ||
163 | while (1) { | ||
164 | c = CIRC_SPACE_TO_END(cb->head, cb->tail, AIRCABLE_BUF_SIZE); | ||
165 | if (count < c) | ||
166 | c = count; | ||
167 | if (c <= 0) | ||
168 | break; | ||
169 | memcpy(cb->buf + cb->head, buf, c); | ||
170 | cb->head = (cb->head + c) & (AIRCABLE_BUF_SIZE-1); | ||
171 | buf += c; | ||
172 | count -= c; | ||
173 | ret= c; | ||
174 | } | ||
175 | return ret; | ||
176 | } | ||
177 | |||
178 | /* | ||
179 | * serial_buf_get | ||
180 | * | ||
181 | * Get data from the circular buffer and copy to the given buffer. | ||
182 | * Restrict to the amount of data available. | ||
183 | * | ||
184 | * Return the number of bytes copied. | ||
185 | */ | ||
186 | static int serial_buf_get(struct circ_buf *cb, char *buf, int count) | ||
187 | { | ||
188 | int c, ret = 0; | ||
189 | while (1) { | ||
190 | c = CIRC_CNT_TO_END(cb->head, cb->tail, AIRCABLE_BUF_SIZE); | ||
191 | if (count < c) | ||
192 | c = count; | ||
193 | if (c <= 0) | ||
194 | break; | ||
195 | memcpy(buf, cb->buf + cb->tail, c); | ||
196 | cb->tail = (cb->tail + c) & (AIRCABLE_BUF_SIZE-1); | ||
197 | buf += c; | ||
198 | count -= c; | ||
199 | ret= c; | ||
200 | } | ||
201 | return ret; | ||
202 | } | ||
203 | |||
204 | /* End of circula buffer methods */ | ||
205 | |||
206 | static void aircable_send(struct usb_serial_port *port) | ||
207 | { | ||
208 | int count, result; | ||
209 | struct aircable_private *priv = usb_get_serial_port_data(port); | ||
210 | unsigned char* buf; | ||
211 | dbg("%s - port %d", __FUNCTION__, port->number); | ||
212 | if (port->write_urb_busy) | ||
213 | return; | ||
214 | |||
215 | count = min(serial_buf_data_avail(priv->tx_buf), MAX_HCI_FRAMESIZE); | ||
216 | if (count == 0) | ||
217 | return; | ||
218 | |||
219 | buf = kzalloc(count + HCI_HEADER_LENGTH, GFP_ATOMIC); | ||
220 | if (!buf) { | ||
221 | err("%s- kzalloc(%d) failed.", __FUNCTION__, | ||
222 | count + HCI_HEADER_LENGTH); | ||
223 | return; | ||
224 | } | ||
225 | |||
226 | buf[0] = TX_HEADER_0; | ||
227 | buf[1] = TX_HEADER_1; | ||
228 | buf[2] = (unsigned char)count; | ||
229 | buf[3] = (unsigned char)(count >> 8); | ||
230 | serial_buf_get(priv->tx_buf,buf + HCI_HEADER_LENGTH, MAX_HCI_FRAMESIZE); | ||
231 | |||
232 | memcpy(port->write_urb->transfer_buffer, buf, | ||
233 | count + HCI_HEADER_LENGTH); | ||
234 | |||
235 | kfree(buf); | ||
236 | port->write_urb_busy = 1; | ||
237 | usb_serial_debug_data(debug, &port->dev, __FUNCTION__, | ||
238 | count + HCI_HEADER_LENGTH, | ||
239 | port->write_urb->transfer_buffer); | ||
240 | port->write_urb->transfer_buffer_length = count + HCI_HEADER_LENGTH; | ||
241 | port->write_urb->dev = port->serial->dev; | ||
242 | result = usb_submit_urb(port->write_urb, GFP_ATOMIC); | ||
243 | |||
244 | if (result) { | ||
245 | dev_err(&port->dev, | ||
246 | "%s - failed submitting write urb, error %d\n", | ||
247 | __FUNCTION__, result); | ||
248 | port->write_urb_busy = 0; | ||
249 | } | ||
250 | |||
251 | schedule_work(&port->work); | ||
252 | } | ||
253 | |||
254 | static void aircable_read(void *params) | ||
255 | { | ||
256 | struct usb_serial_port *port = params; | ||
257 | struct aircable_private *priv = usb_get_serial_port_data(port); | ||
258 | struct tty_struct *tty; | ||
259 | unsigned char *data; | ||
260 | int count; | ||
261 | if (priv->rx_flags & THROTTLED){ | ||
262 | if (priv->rx_flags & ACTUALLY_THROTTLED) | ||
263 | schedule_work(&priv->rx_work); | ||
264 | return; | ||
265 | } | ||
266 | |||
267 | /* By now I will flush data to the tty in packages of no more than | ||
268 | * 64 bytes, to ensure I do not get throttled. | ||
269 | * Ask USB mailing list for better aproach. | ||
270 | */ | ||
271 | tty = port->tty; | ||
272 | |||
273 | if (!tty) | ||
274 | schedule_work(&priv->rx_work); | ||
275 | |||
276 | count = min(64, serial_buf_data_avail(priv->rx_buf)); | ||
277 | |||
278 | if (count <= 0) | ||
279 | return; //We have finished sending everything. | ||
280 | |||
281 | tty_prepare_flip_string(tty, &data, count); | ||
282 | if (!data){ | ||
283 | err("%s- kzalloc(%d) failed.", __FUNCTION__, count); | ||
284 | return; | ||
285 | } | ||
286 | |||
287 | serial_buf_get(priv->rx_buf, data, count); | ||
288 | |||
289 | tty_flip_buffer_push(tty); | ||
290 | |||
291 | if (serial_buf_data_avail(priv->rx_buf)) | ||
292 | schedule_work(&priv->rx_work); | ||
293 | |||
294 | return; | ||
295 | } | ||
296 | /* End of private methods */ | ||
297 | |||
298 | static int aircable_probe(struct usb_serial *serial, | ||
299 | const struct usb_device_id *id) | ||
300 | { | ||
301 | struct usb_host_interface *iface_desc = serial->interface->cur_altsetting; | ||
302 | struct usb_endpoint_descriptor *endpoint; | ||
303 | int num_bulk_out=0; | ||
304 | int i; | ||
305 | |||
306 | for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) { | ||
307 | endpoint = &iface_desc->endpoint[i].desc; | ||
308 | if (((endpoint->bEndpointAddress & 0x80) == 0x00) && | ||
309 | ((endpoint->bmAttributes & 3) == 0x02)) { | ||
310 | /* we found our bulk out endpoint */ | ||
311 | dbg("found bulk out on endpoint %d", i); | ||
312 | ++num_bulk_out; | ||
313 | } | ||
314 | } | ||
315 | |||
316 | if (num_bulk_out == 0) { | ||
317 | dbg("Invalid interface, discarding"); | ||
318 | return -ENODEV; | ||
319 | } | ||
320 | |||
321 | return 0; | ||
322 | } | ||
323 | |||
324 | static int aircable_attach (struct usb_serial *serial) | ||
325 | { | ||
326 | struct usb_serial_port *port = serial->port[0]; | ||
327 | struct aircable_private *priv; | ||
328 | |||
329 | priv = kzalloc(sizeof(struct aircable_private), GFP_KERNEL); | ||
330 | if (!priv){ | ||
331 | err("%s- kmalloc(%Zd) failed.", __FUNCTION__, | ||
332 | sizeof(struct aircable_private)); | ||
333 | return -ENOMEM; | ||
334 | } | ||
335 | |||
336 | /* Allocation of Circular Buffers */ | ||
337 | priv->tx_buf = serial_buf_alloc(); | ||
338 | if (priv->tx_buf == NULL) { | ||
339 | kfree(priv); | ||
340 | return -ENOMEM; | ||
341 | } | ||
342 | |||
343 | priv->rx_buf = serial_buf_alloc(); | ||
344 | if (priv->rx_buf == NULL) { | ||
345 | kfree(priv->tx_buf); | ||
346 | kfree(priv); | ||
347 | return -ENOMEM; | ||
348 | } | ||
349 | |||
350 | priv->rx_flags &= ~(THROTTLED | ACTUALLY_THROTTLED); | ||
351 | INIT_WORK(&priv->rx_work, aircable_read, port); | ||
352 | |||
353 | usb_set_serial_port_data(serial->port[0], priv); | ||
354 | |||
355 | return 0; | ||
356 | } | ||
357 | |||
358 | static void aircable_shutdown(struct usb_serial *serial) | ||
359 | { | ||
360 | |||
361 | struct usb_serial_port *port = serial->port[0]; | ||
362 | struct aircable_private *priv = usb_get_serial_port_data(port); | ||
363 | |||
364 | dbg("%s", __FUNCTION__); | ||
365 | |||
366 | if (priv) { | ||
367 | serial_buf_free(priv->tx_buf); | ||
368 | serial_buf_free(priv->rx_buf); | ||
369 | usb_set_serial_port_data(port, NULL); | ||
370 | kfree(priv); | ||
371 | } | ||
372 | } | ||
373 | |||
374 | static int aircable_write_room(struct usb_serial_port *port) | ||
375 | { | ||
376 | struct aircable_private *priv = usb_get_serial_port_data(port); | ||
377 | return serial_buf_data_avail(priv->tx_buf); | ||
378 | } | ||
379 | |||
380 | static int aircable_write(struct usb_serial_port *port, | ||
381 | const unsigned char *source, int count) | ||
382 | { | ||
383 | struct aircable_private *priv = usb_get_serial_port_data(port); | ||
384 | int temp; | ||
385 | |||
386 | dbg("%s - port %d, %d bytes", __FUNCTION__, port->number, count); | ||
387 | |||
388 | usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, source); | ||
389 | |||
390 | if (!count){ | ||
391 | dbg("%s - write request of 0 bytes", __FUNCTION__); | ||
392 | return count; | ||
393 | } | ||
394 | |||
395 | temp = serial_buf_put(priv->tx_buf, source, count); | ||
396 | |||
397 | aircable_send(port); | ||
398 | |||
399 | if (count > AIRCABLE_BUF_SIZE) | ||
400 | count = AIRCABLE_BUF_SIZE; | ||
401 | |||
402 | return count; | ||
403 | |||
404 | } | ||
405 | |||
406 | static void aircable_write_bulk_callback(struct urb *urb, struct pt_regs *regs) | ||
407 | { | ||
408 | struct usb_serial_port *port = urb->context; | ||
409 | int result; | ||
410 | |||
411 | dbg("%s - urb->status: %d", __FUNCTION__ , urb->status); | ||
412 | |||
413 | /* This has been taken from cypress_m8.c cypress_write_int_callback */ | ||
414 | switch (urb->status) { | ||
415 | case 0: | ||
416 | /* success */ | ||
417 | break; | ||
418 | case -ECONNRESET: | ||
419 | case -ENOENT: | ||
420 | case -ESHUTDOWN: | ||
421 | /* this urb is terminated, clean up */ | ||
422 | dbg("%s - urb shutting down with status: %d", | ||
423 | __FUNCTION__, urb->status); | ||
424 | port->write_urb_busy = 0; | ||
425 | return; | ||
426 | default: | ||
427 | /* error in the urb, so we have to resubmit it */ | ||
428 | dbg("%s - Overflow in write", __FUNCTION__); | ||
429 | dbg("%s - nonzero write bulk status received: %d", | ||
430 | __FUNCTION__, urb->status); | ||
431 | port->write_urb->transfer_buffer_length = 1; | ||
432 | port->write_urb->dev = port->serial->dev; | ||
433 | result = usb_submit_urb(port->write_urb, GFP_KERNEL); | ||
434 | if (result) | ||
435 | dev_err(&urb->dev->dev, | ||
436 | "%s - failed resubmitting write urb, error %d\n", | ||
437 | __FUNCTION__, result); | ||
438 | else | ||
439 | return; | ||
440 | } | ||
441 | |||
442 | port->write_urb_busy = 0; | ||
443 | |||
444 | aircable_send(port); | ||
445 | } | ||
446 | |||
447 | static void aircable_read_bulk_callback(struct urb *urb, struct pt_regs *regs) | ||
448 | { | ||
449 | struct usb_serial_port *port = urb->context; | ||
450 | struct aircable_private *priv = usb_get_serial_port_data(port); | ||
451 | struct tty_struct *tty; | ||
452 | unsigned long no_packages, remaining, package_length, i; | ||
453 | int result, shift = 0; | ||
454 | unsigned char *temp; | ||
455 | |||
456 | dbg("%s - port %d", __FUNCTION__, port->number); | ||
457 | |||
458 | if (urb->status) { | ||
459 | dbg("%s - urb->status = %d", __FUNCTION__, urb->status); | ||
460 | if (!port->open_count) { | ||
461 | dbg("%s - port is closed, exiting.", __FUNCTION__); | ||
462 | return; | ||
463 | } | ||
464 | if (urb->status == -EPROTO) { | ||
465 | dbg("%s - caught -EPROTO, resubmitting the urb", | ||
466 | __FUNCTION__); | ||
467 | usb_fill_bulk_urb(port->read_urb, port->serial->dev, | ||
468 | usb_rcvbulkpipe(port->serial->dev, | ||
469 | port->bulk_in_endpointAddress), | ||
470 | port->read_urb->transfer_buffer, | ||
471 | port->read_urb->transfer_buffer_length, | ||
472 | aircable_read_bulk_callback, port); | ||
473 | |||
474 | result = usb_submit_urb(urb, GFP_ATOMIC); | ||
475 | if (result) | ||
476 | dev_err(&urb->dev->dev, | ||
477 | "%s - failed resubmitting read urb, error %d\n", | ||
478 | __FUNCTION__, result); | ||
479 | return; | ||
480 | } | ||
481 | dbg("%s - unable to handle the error, exiting.", __FUNCTION__); | ||
482 | return; | ||
483 | } | ||
484 | |||
485 | usb_serial_debug_data(debug, &port->dev, __FUNCTION__, | ||
486 | urb->actual_length,urb->transfer_buffer); | ||
487 | |||
488 | tty = port->tty; | ||
489 | if (tty && urb->actual_length) { | ||
490 | if (urb->actual_length <= 2) { | ||
491 | /* This is an incomplete package */ | ||
492 | serial_buf_put(priv->rx_buf, urb->transfer_buffer, | ||
493 | urb->actual_length); | ||
494 | } else { | ||
495 | temp = urb->transfer_buffer; | ||
496 | if (temp[0] == RX_HEADER_0) | ||
497 | shift = HCI_HEADER_LENGTH; | ||
498 | |||
499 | remaining = urb->actual_length; | ||
500 | no_packages = urb->actual_length / (HCI_COMPLETE_FRAME); | ||
501 | |||
502 | if (urb->actual_length % HCI_COMPLETE_FRAME != 0) | ||
503 | no_packages+=1; | ||
504 | |||
505 | for (i = 0; i < no_packages ;i++) { | ||
506 | if (remaining > (HCI_COMPLETE_FRAME)) | ||
507 | package_length = HCI_COMPLETE_FRAME; | ||
508 | else | ||
509 | package_length = remaining; | ||
510 | remaining -= package_length; | ||
511 | |||
512 | serial_buf_put(priv->rx_buf, | ||
513 | urb->transfer_buffer + shift + | ||
514 | (HCI_COMPLETE_FRAME) * (i), | ||
515 | package_length - shift); | ||
516 | } | ||
517 | } | ||
518 | aircable_read(port); | ||
519 | } | ||
520 | |||
521 | /* Schedule the next read _if_ we are still open */ | ||
522 | if (port->open_count) { | ||
523 | usb_fill_bulk_urb(port->read_urb, port->serial->dev, | ||
524 | usb_rcvbulkpipe(port->serial->dev, | ||
525 | port->bulk_in_endpointAddress), | ||
526 | port->read_urb->transfer_buffer, | ||
527 | port->read_urb->transfer_buffer_length, | ||
528 | aircable_read_bulk_callback, port); | ||
529 | |||
530 | result = usb_submit_urb(urb, GFP_ATOMIC); | ||
531 | if (result) | ||
532 | dev_err(&urb->dev->dev, | ||
533 | "%s - failed resubmitting read urb, error %d\n", | ||
534 | __FUNCTION__, result); | ||
535 | } | ||
536 | |||
537 | return; | ||
538 | } | ||
539 | |||
540 | /* Based on ftdi_sio.c throttle */ | ||
541 | static void aircable_throttle(struct usb_serial_port *port) | ||
542 | { | ||
543 | struct aircable_private *priv = usb_get_serial_port_data(port); | ||
544 | unsigned long flags; | ||
545 | |||
546 | dbg("%s - port %d", __FUNCTION__, port->number); | ||
547 | |||
548 | spin_lock_irqsave(&priv->rx_lock, flags); | ||
549 | priv->rx_flags |= THROTTLED; | ||
550 | spin_unlock_irqrestore(&priv->rx_lock, flags); | ||
551 | } | ||
552 | |||
553 | /* Based on ftdi_sio.c unthrottle */ | ||
554 | static void aircable_unthrottle(struct usb_serial_port *port) | ||
555 | { | ||
556 | struct aircable_private *priv = usb_get_serial_port_data(port); | ||
557 | int actually_throttled; | ||
558 | unsigned long flags; | ||
559 | |||
560 | dbg("%s - port %d", __FUNCTION__, port->number); | ||
561 | |||
562 | spin_lock_irqsave(&priv->rx_lock, flags); | ||
563 | actually_throttled = priv->rx_flags & ACTUALLY_THROTTLED; | ||
564 | priv->rx_flags &= ~(THROTTLED | ACTUALLY_THROTTLED); | ||
565 | spin_unlock_irqrestore(&priv->rx_lock, flags); | ||
566 | |||
567 | if (actually_throttled) | ||
568 | schedule_work(&priv->rx_work); | ||
569 | } | ||
570 | |||
571 | static struct usb_serial_driver aircable_device = { | ||
572 | .description = "aircable", | ||
573 | .id_table = id_table, | ||
574 | .num_ports = 1, | ||
575 | .attach = aircable_attach, | ||
576 | .probe = aircable_probe, | ||
577 | .shutdown = aircable_shutdown, | ||
578 | .write = aircable_write, | ||
579 | .write_room = aircable_write_room, | ||
580 | .write_bulk_callback = aircable_write_bulk_callback, | ||
581 | .read_bulk_callback = aircable_read_bulk_callback, | ||
582 | .throttle = aircable_throttle, | ||
583 | .unthrottle = aircable_unthrottle, | ||
584 | }; | ||
585 | |||
586 | static struct usb_driver aircable_driver = { | ||
587 | .name = "aircable", | ||
588 | .probe = usb_serial_probe, | ||
589 | .disconnect = usb_serial_disconnect, | ||
590 | .id_table = id_table, | ||
591 | }; | ||
592 | |||
593 | static int __init aircable_init (void) | ||
594 | { | ||
595 | int retval; | ||
596 | retval = usb_serial_register(&aircable_device); | ||
597 | if (retval) | ||
598 | goto failed_serial_register; | ||
599 | retval = usb_register(&aircable_driver); | ||
600 | if (retval) | ||
601 | goto failed_usb_register; | ||
602 | return 0; | ||
603 | |||
604 | failed_serial_register: | ||
605 | usb_serial_deregister(&aircable_device); | ||
606 | failed_usb_register: | ||
607 | return retval; | ||
608 | } | ||
609 | |||
610 | static void __exit aircable_exit (void) | ||
611 | { | ||
612 | usb_deregister(&aircable_driver); | ||
613 | usb_serial_deregister(&aircable_device); | ||
614 | } | ||
615 | |||
616 | MODULE_AUTHOR(DRIVER_AUTHOR); | ||
617 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
618 | MODULE_VERSION(DRIVER_VERSION); | ||
619 | MODULE_LICENSE("GPL"); | ||
620 | |||
621 | module_init(aircable_init); | ||
622 | module_exit(aircable_exit); | ||
623 | |||
624 | module_param(debug, bool, S_IRUGO | S_IWUSR); | ||
625 | MODULE_PARM_DESC(debug, "Debug enabled or not"); | ||
diff --git a/drivers/usb/serial/airprime.c b/drivers/usb/serial/airprime.c index 62082532a8b3..6e1a84a858d4 100644 --- a/drivers/usb/serial/airprime.c +++ b/drivers/usb/serial/airprime.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * AirPrime CDMA Wireless Serial USB driver | 2 | * AirPrime CDMA Wireless Serial USB driver |
3 | * | 3 | * |
4 | * Copyright (C) 2005 Greg Kroah-Hartman <gregkh@suse.de> | 4 | * Copyright (C) 2005-2006 Greg Kroah-Hartman <gregkh@suse.de> |
5 | * | 5 | * |
6 | * This program is free software; you can redistribute it and/or | 6 | * This program is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU General Public License version | 7 | * modify it under the terms of the GNU General Public License version |
@@ -11,26 +11,264 @@ | |||
11 | #include <linux/kernel.h> | 11 | #include <linux/kernel.h> |
12 | #include <linux/init.h> | 12 | #include <linux/init.h> |
13 | #include <linux/tty.h> | 13 | #include <linux/tty.h> |
14 | #include <linux/tty_flip.h> | ||
14 | #include <linux/module.h> | 15 | #include <linux/module.h> |
15 | #include <linux/usb.h> | 16 | #include <linux/usb.h> |
16 | #include <linux/usb/serial.h> | 17 | #include <linux/usb/serial.h> |
17 | 18 | ||
18 | static struct usb_device_id id_table [] = { | 19 | static struct usb_device_id id_table [] = { |
19 | { USB_DEVICE(0x0c88, 0x17da) }, /* Kyocera Wireless KPC650/Passport */ | 20 | { USB_DEVICE(0x0c88, 0x17da) }, /* Kyocera Wireless KPC650/Passport */ |
20 | { USB_DEVICE(0xf3d, 0x0112) }, /* AirPrime CDMA Wireless PC Card */ | 21 | { USB_DEVICE(0x0f3d, 0x0112) }, /* AirPrime CDMA Wireless PC Card */ |
21 | { USB_DEVICE(0x1410, 0x1110) }, /* Novatel Wireless Merlin CDMA */ | 22 | { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */ |
23 | { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */ | ||
22 | { USB_DEVICE(0x1199, 0x0112) }, /* Sierra Wireless Aircard 580 */ | 24 | { USB_DEVICE(0x1199, 0x0112) }, /* Sierra Wireless Aircard 580 */ |
23 | { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */ | 25 | { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */ |
26 | { USB_DEVICE(0x1410, 0x1110) }, /* Novatel Wireless Merlin CDMA */ | ||
24 | { }, | 27 | { }, |
25 | }; | 28 | }; |
26 | MODULE_DEVICE_TABLE(usb, id_table); | 29 | MODULE_DEVICE_TABLE(usb, id_table); |
27 | 30 | ||
31 | #define URB_TRANSFER_BUFFER_SIZE 4096 | ||
32 | #define NUM_READ_URBS 4 | ||
33 | #define NUM_WRITE_URBS 4 | ||
34 | #define NUM_BULK_EPS 3 | ||
35 | #define MAX_BULK_EPS 6 | ||
36 | |||
37 | /* if overridden by the user, then use their value for the size of the | ||
38 | * read and write urbs, and the number of endpoints */ | ||
39 | static int buffer_size = URB_TRANSFER_BUFFER_SIZE; | ||
40 | static int endpoints = NUM_BULK_EPS; | ||
41 | static int debug; | ||
42 | struct airprime_private { | ||
43 | spinlock_t lock; | ||
44 | int outstanding_urbs; | ||
45 | int throttled; | ||
46 | struct urb *read_urbp[NUM_READ_URBS]; | ||
47 | }; | ||
48 | |||
49 | static void airprime_read_bulk_callback(struct urb *urb, struct pt_regs *regs) | ||
50 | { | ||
51 | struct usb_serial_port *port = urb->context; | ||
52 | unsigned char *data = urb->transfer_buffer; | ||
53 | struct tty_struct *tty; | ||
54 | int result; | ||
55 | |||
56 | dbg("%s - port %d", __FUNCTION__, port->number); | ||
57 | |||
58 | if (urb->status) { | ||
59 | dbg("%s - nonzero read bulk status received: %d", | ||
60 | __FUNCTION__, urb->status); | ||
61 | /* something happened, so free up the memory for this urb */ | ||
62 | if (urb->transfer_buffer) { | ||
63 | kfree (urb->transfer_buffer); | ||
64 | urb->transfer_buffer = NULL; | ||
65 | } | ||
66 | return; | ||
67 | } | ||
68 | usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data); | ||
69 | |||
70 | tty = port->tty; | ||
71 | if (tty && urb->actual_length) { | ||
72 | tty_insert_flip_string (tty, data, urb->actual_length); | ||
73 | tty_flip_buffer_push (tty); | ||
74 | } | ||
75 | |||
76 | result = usb_submit_urb (urb, GFP_ATOMIC); | ||
77 | if (result) | ||
78 | dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", | ||
79 | __FUNCTION__, result); | ||
80 | return; | ||
81 | } | ||
82 | |||
83 | static void airprime_write_bulk_callback(struct urb *urb, struct pt_regs *regs) | ||
84 | { | ||
85 | struct usb_serial_port *port = urb->context; | ||
86 | struct airprime_private *priv = usb_get_serial_port_data(port); | ||
87 | unsigned long flags; | ||
88 | |||
89 | dbg("%s - port %d", __FUNCTION__, port->number); | ||
90 | |||
91 | /* free up the transfer buffer, as usb_free_urb() does not do this */ | ||
92 | kfree (urb->transfer_buffer); | ||
93 | |||
94 | if (urb->status) | ||
95 | dbg("%s - nonzero write bulk status received: %d", | ||
96 | __FUNCTION__, urb->status); | ||
97 | spin_lock_irqsave(&priv->lock, flags); | ||
98 | --priv->outstanding_urbs; | ||
99 | spin_unlock_irqrestore(&priv->lock, flags); | ||
100 | |||
101 | usb_serial_port_softint(port); | ||
102 | } | ||
103 | |||
104 | static int airprime_open(struct usb_serial_port *port, struct file *filp) | ||
105 | { | ||
106 | struct airprime_private *priv = usb_get_serial_port_data(port); | ||
107 | struct usb_serial *serial = port->serial; | ||
108 | struct urb *urb; | ||
109 | char *buffer = NULL; | ||
110 | int i; | ||
111 | int result = 0; | ||
112 | |||
113 | dbg("%s - port %d", __FUNCTION__, port->number); | ||
114 | |||
115 | /* initialize our private data structure if it isn't already created */ | ||
116 | if (!priv) { | ||
117 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); | ||
118 | if (!priv) { | ||
119 | result = -ENOMEM; | ||
120 | goto out; | ||
121 | } | ||
122 | spin_lock_init(&priv->lock); | ||
123 | usb_set_serial_port_data(port, priv); | ||
124 | } | ||
125 | |||
126 | for (i = 0; i < NUM_READ_URBS; ++i) { | ||
127 | buffer = kmalloc(buffer_size, GFP_KERNEL); | ||
128 | if (!buffer) { | ||
129 | dev_err(&port->dev, "%s - out of memory.\n", | ||
130 | __FUNCTION__); | ||
131 | result = -ENOMEM; | ||
132 | goto errout; | ||
133 | } | ||
134 | urb = usb_alloc_urb(0, GFP_KERNEL); | ||
135 | if (!urb) { | ||
136 | dev_err(&port->dev, "%s - no more urbs?\n", | ||
137 | __FUNCTION__); | ||
138 | result = -ENOMEM; | ||
139 | goto errout; | ||
140 | } | ||
141 | usb_fill_bulk_urb(urb, serial->dev, | ||
142 | usb_rcvbulkpipe(serial->dev, | ||
143 | port->bulk_out_endpointAddress), | ||
144 | buffer, buffer_size, | ||
145 | airprime_read_bulk_callback, port); | ||
146 | result = usb_submit_urb(urb, GFP_KERNEL); | ||
147 | if (result) { | ||
148 | dev_err(&port->dev, | ||
149 | "%s - failed submitting read urb %d for port %d, error %d\n", | ||
150 | __FUNCTION__, i, port->number, result); | ||
151 | goto errout; | ||
152 | } | ||
153 | /* remember this urb so we can kill it when the port is closed */ | ||
154 | priv->read_urbp[i] = urb; | ||
155 | } | ||
156 | goto out; | ||
157 | |||
158 | errout: | ||
159 | /* some error happened, cancel any submitted urbs and clean up anything that | ||
160 | got allocated successfully */ | ||
161 | |||
162 | for ( ; i >= 0; --i) { | ||
163 | urb = priv->read_urbp[i]; | ||
164 | if (urb) { | ||
165 | /* This urb was submitted successfully. So we have to | ||
166 | cancel it. | ||
167 | Unlinking the urb will invoke read_bulk_callback() | ||
168 | with an error status, so its transfer buffer will | ||
169 | be freed there */ | ||
170 | if (usb_unlink_urb (urb) != -EINPROGRESS) { | ||
171 | /* comments in drivers/usb/core/urb.c say this | ||
172 | can only happen if the urb was never submitted, | ||
173 | or has completed already. | ||
174 | Either way we may have to free the transfer | ||
175 | buffer here. */ | ||
176 | if (urb->transfer_buffer) { | ||
177 | kfree (urb->transfer_buffer); | ||
178 | urb->transfer_buffer = NULL; | ||
179 | } | ||
180 | } | ||
181 | usb_free_urb (urb); | ||
182 | } | ||
183 | } | ||
184 | |||
185 | out: | ||
186 | return result; | ||
187 | } | ||
188 | |||
189 | static void airprime_close(struct usb_serial_port *port, struct file * filp) | ||
190 | { | ||
191 | struct airprime_private *priv = usb_get_serial_port_data(port); | ||
192 | int i; | ||
193 | |||
194 | dbg("%s - port %d", __FUNCTION__, port->number); | ||
195 | |||
196 | /* killing the urb will invoke read_bulk_callback() with an error status, | ||
197 | so the transfer buffer will be freed there */ | ||
198 | for (i = 0; i < NUM_READ_URBS; ++i) { | ||
199 | usb_kill_urb (priv->read_urbp[i]); | ||
200 | usb_free_urb (priv->read_urbp[i]); | ||
201 | } | ||
202 | |||
203 | /* free up private structure */ | ||
204 | kfree (priv); | ||
205 | usb_set_serial_port_data(port, NULL); | ||
206 | } | ||
207 | |||
208 | static int airprime_write(struct usb_serial_port *port, | ||
209 | const unsigned char *buf, int count) | ||
210 | { | ||
211 | struct airprime_private *priv = usb_get_serial_port_data(port); | ||
212 | struct usb_serial *serial = port->serial; | ||
213 | struct urb *urb; | ||
214 | unsigned char *buffer; | ||
215 | unsigned long flags; | ||
216 | int status; | ||
217 | dbg("%s - port %d", __FUNCTION__, port->number); | ||
218 | |||
219 | spin_lock_irqsave(&priv->lock, flags); | ||
220 | if (priv->outstanding_urbs > NUM_WRITE_URBS) { | ||
221 | spin_unlock_irqrestore(&priv->lock, flags); | ||
222 | dbg("%s - write limit hit\n", __FUNCTION__); | ||
223 | return 0; | ||
224 | } | ||
225 | spin_unlock_irqrestore(&priv->lock, flags); | ||
226 | buffer = kmalloc(count, GFP_ATOMIC); | ||
227 | if (!buffer) { | ||
228 | dev_err(&port->dev, "out of memory\n"); | ||
229 | return -ENOMEM; | ||
230 | } | ||
231 | urb = usb_alloc_urb(0, GFP_ATOMIC); | ||
232 | if (!urb) { | ||
233 | dev_err(&port->dev, "no more free urbs\n"); | ||
234 | kfree (buffer); | ||
235 | return -ENOMEM; | ||
236 | } | ||
237 | memcpy (buffer, buf, count); | ||
238 | |||
239 | usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, buffer); | ||
240 | |||
241 | usb_fill_bulk_urb(urb, serial->dev, | ||
242 | usb_sndbulkpipe(serial->dev, | ||
243 | port->bulk_out_endpointAddress), | ||
244 | buffer, count, | ||
245 | airprime_write_bulk_callback, port); | ||
246 | |||
247 | /* send it down the pipe */ | ||
248 | status = usb_submit_urb(urb, GFP_ATOMIC); | ||
249 | if (status) { | ||
250 | dev_err(&port->dev, | ||
251 | "%s - usb_submit_urb(write bulk) failed with status = %d\n", | ||
252 | __FUNCTION__, status); | ||
253 | count = status; | ||
254 | kfree (buffer); | ||
255 | } else { | ||
256 | spin_lock_irqsave(&priv->lock, flags); | ||
257 | ++priv->outstanding_urbs; | ||
258 | spin_unlock_irqrestore(&priv->lock, flags); | ||
259 | } | ||
260 | /* we are done with this urb, so let the host driver | ||
261 | * really free it when it is finished with it */ | ||
262 | usb_free_urb (urb); | ||
263 | return count; | ||
264 | } | ||
265 | |||
28 | static struct usb_driver airprime_driver = { | 266 | static struct usb_driver airprime_driver = { |
29 | .name = "airprime", | 267 | .name = "airprime", |
30 | .probe = usb_serial_probe, | 268 | .probe = usb_serial_probe, |
31 | .disconnect = usb_serial_disconnect, | 269 | .disconnect = usb_serial_disconnect, |
32 | .id_table = id_table, | 270 | .id_table = id_table, |
33 | .no_dynamic_id = 1, | 271 | .no_dynamic_id = 1, |
34 | }; | 272 | }; |
35 | 273 | ||
36 | static struct usb_serial_driver airprime_device = { | 274 | static struct usb_serial_driver airprime_device = { |
@@ -42,13 +280,17 @@ static struct usb_serial_driver airprime_device = { | |||
42 | .num_interrupt_in = NUM_DONT_CARE, | 280 | .num_interrupt_in = NUM_DONT_CARE, |
43 | .num_bulk_in = NUM_DONT_CARE, | 281 | .num_bulk_in = NUM_DONT_CARE, |
44 | .num_bulk_out = NUM_DONT_CARE, | 282 | .num_bulk_out = NUM_DONT_CARE, |
45 | .num_ports = 1, | 283 | .open = airprime_open, |
284 | .close = airprime_close, | ||
285 | .write = airprime_write, | ||
46 | }; | 286 | }; |
47 | 287 | ||
48 | static int __init airprime_init(void) | 288 | static int __init airprime_init(void) |
49 | { | 289 | { |
50 | int retval; | 290 | int retval; |
51 | 291 | ||
292 | airprime_device.num_ports = | ||
293 | (endpoints > 0 && endpoints <= MAX_BULK_EPS) ? endpoints : NUM_BULK_EPS; | ||
52 | retval = usb_serial_register(&airprime_device); | 294 | retval = usb_serial_register(&airprime_device); |
53 | if (retval) | 295 | if (retval) |
54 | return retval; | 296 | return retval; |
@@ -60,6 +302,8 @@ static int __init airprime_init(void) | |||
60 | 302 | ||
61 | static void __exit airprime_exit(void) | 303 | static void __exit airprime_exit(void) |
62 | { | 304 | { |
305 | dbg("%s", __FUNCTION__); | ||
306 | |||
63 | usb_deregister(&airprime_driver); | 307 | usb_deregister(&airprime_driver); |
64 | usb_serial_deregister(&airprime_device); | 308 | usb_serial_deregister(&airprime_device); |
65 | } | 309 | } |
@@ -67,3 +311,10 @@ static void __exit airprime_exit(void) | |||
67 | module_init(airprime_init); | 311 | module_init(airprime_init); |
68 | module_exit(airprime_exit); | 312 | module_exit(airprime_exit); |
69 | MODULE_LICENSE("GPL"); | 313 | MODULE_LICENSE("GPL"); |
314 | |||
315 | module_param(debug, bool, S_IRUGO | S_IWUSR); | ||
316 | MODULE_PARM_DESC(debug, "Debug enabled"); | ||
317 | module_param(buffer_size, int, 0); | ||
318 | MODULE_PARM_DESC(buffer_size, "Size of the transfer buffers in bytes (default 4096)"); | ||
319 | module_param(endpoints, int, 0); | ||
320 | MODULE_PARM_DESC(endpoints, "Number of bulk EPs to configure (default 3)"); | ||
diff --git a/drivers/usb/serial/ark3116.c b/drivers/usb/serial/ark3116.c index 970d9ef0a7a5..ca52f12f0e24 100644 --- a/drivers/usb/serial/ark3116.c +++ b/drivers/usb/serial/ark3116.c | |||
@@ -1,4 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2006 | ||
3 | * Simon Schulz (ark3116_driver <at> auctionant.de) | ||
4 | * | ||
2 | * ark3116 | 5 | * ark3116 |
3 | * - implements a driver for the arkmicro ark3116 chipset (vendor=0x6547, | 6 | * - implements a driver for the arkmicro ark3116 chipset (vendor=0x6547, |
4 | * productid=0x0232) (used in a datacable called KQ-U8A) | 7 | * productid=0x0232) (used in a datacable called KQ-U8A) |
@@ -8,8 +11,6 @@ | |||
8 | * | 11 | * |
9 | * - based on logs created by usbsnoopy | 12 | * - based on logs created by usbsnoopy |
10 | * | 13 | * |
11 | * Author : Simon Schulz [ark3116_driver<AT>auctionant.de] | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or modify it | 14 | * This program is free software; you can redistribute it and/or modify it |
14 | * under the terms of the GNU General Public License as published by the | 15 | * under the terms of the GNU General Public License as published by the |
15 | * Free Software Foundation; either version 2 of the License, or (at your | 16 | * Free Software Foundation; either version 2 of the License, or (at your |
@@ -22,6 +23,8 @@ | |||
22 | #include <linux/module.h> | 23 | #include <linux/module.h> |
23 | #include <linux/usb.h> | 24 | #include <linux/usb.h> |
24 | #include <linux/usb/serial.h> | 25 | #include <linux/usb/serial.h> |
26 | #include <linux/serial.h> | ||
27 | #include <asm/uaccess.h> | ||
25 | 28 | ||
26 | 29 | ||
27 | static int debug; | 30 | static int debug; |
@@ -43,10 +46,10 @@ static inline void ARK3116_SND(struct usb_serial *serial, int seq, | |||
43 | { | 46 | { |
44 | int result; | 47 | int result; |
45 | result = usb_control_msg(serial->dev, | 48 | result = usb_control_msg(serial->dev, |
46 | usb_sndctrlpipe(serial->dev,0), | 49 | usb_sndctrlpipe(serial->dev, 0), |
47 | request, requesttype, value, index, | 50 | request, requesttype, value, index, |
48 | NULL,0x00, 1000); | 51 | NULL, 0x00, 1000); |
49 | dbg("%03d > ok",seq); | 52 | dbg("%03d > ok", seq); |
50 | } | 53 | } |
51 | 54 | ||
52 | static inline void ARK3116_RCV(struct usb_serial *serial, int seq, | 55 | static inline void ARK3116_RCV(struct usb_serial *serial, int seq, |
@@ -56,27 +59,25 @@ static inline void ARK3116_RCV(struct usb_serial *serial, int seq, | |||
56 | { | 59 | { |
57 | int result; | 60 | int result; |
58 | result = usb_control_msg(serial->dev, | 61 | result = usb_control_msg(serial->dev, |
59 | usb_rcvctrlpipe(serial->dev,0), | 62 | usb_rcvctrlpipe(serial->dev, 0), |
60 | request, requesttype, value, index, | 63 | request, requesttype, value, index, |
61 | buf, 0x0000001, 1000); | 64 | buf, 0x0000001, 1000); |
62 | if (result) | 65 | if (result) |
63 | dbg("%03d < %d bytes [0x%02X]",seq, result, buf[0]); | 66 | dbg("%03d < %d bytes [0x%02X]", seq, result, buf[0]); |
64 | else | 67 | else |
65 | dbg("%03d < 0 bytes", seq); | 68 | dbg("%03d < 0 bytes", seq); |
66 | } | 69 | } |
67 | 70 | ||
68 | |||
69 | static inline void ARK3116_RCV_QUIET(struct usb_serial *serial, | 71 | static inline void ARK3116_RCV_QUIET(struct usb_serial *serial, |
70 | __u8 request, __u8 requesttype, | 72 | __u8 request, __u8 requesttype, |
71 | __u16 value, __u16 index, char *buf) | 73 | __u16 value, __u16 index, char *buf) |
72 | { | 74 | { |
73 | usb_control_msg(serial->dev, | 75 | usb_control_msg(serial->dev, |
74 | usb_rcvctrlpipe(serial->dev,0), | 76 | usb_rcvctrlpipe(serial->dev, 0), |
75 | request, requesttype, value, index, | 77 | request, requesttype, value, index, |
76 | buf, 0x0000001, 1000); | 78 | buf, 0x0000001, 1000); |
77 | } | 79 | } |
78 | 80 | ||
79 | |||
80 | static int ark3116_attach(struct usb_serial *serial) | 81 | static int ark3116_attach(struct usb_serial *serial) |
81 | { | 82 | { |
82 | char *buf; | 83 | char *buf; |
@@ -84,10 +85,10 @@ static int ark3116_attach(struct usb_serial *serial) | |||
84 | int i; | 85 | int i; |
85 | 86 | ||
86 | for (i = 0; i < serial->num_ports; ++i) { | 87 | for (i = 0; i < serial->num_ports; ++i) { |
87 | priv = kmalloc (sizeof (struct ark3116_private), GFP_KERNEL); | 88 | priv = kmalloc(sizeof (struct ark3116_private), GFP_KERNEL); |
88 | if (!priv) | 89 | if (!priv) |
89 | goto cleanup; | 90 | goto cleanup; |
90 | memset (priv, 0x00, sizeof (struct ark3116_private)); | 91 | memset(priv, 0x00, sizeof (struct ark3116_private)); |
91 | spin_lock_init(&priv->lock); | 92 | spin_lock_init(&priv->lock); |
92 | 93 | ||
93 | usb_set_serial_port_data(serial->port[i], priv); | 94 | usb_set_serial_port_data(serial->port[i], priv); |
@@ -95,63 +96,62 @@ static int ark3116_attach(struct usb_serial *serial) | |||
95 | 96 | ||
96 | buf = kmalloc(1, GFP_KERNEL); | 97 | buf = kmalloc(1, GFP_KERNEL); |
97 | if (!buf) { | 98 | if (!buf) { |
98 | dbg("error kmalloc -> out of mem ?"); | 99 | dbg("error kmalloc -> out of mem?"); |
99 | goto cleanup; | 100 | goto cleanup; |
100 | } | 101 | } |
101 | 102 | ||
102 | /* 3 */ | 103 | /* 3 */ |
103 | ARK3116_SND(serial, 3,0xFE,0x40,0x0008,0x0002); | 104 | ARK3116_SND(serial, 3, 0xFE, 0x40, 0x0008, 0x0002); |
104 | ARK3116_SND(serial, 4,0xFE,0x40,0x0008,0x0001); | 105 | ARK3116_SND(serial, 4, 0xFE, 0x40, 0x0008, 0x0001); |
105 | ARK3116_SND(serial, 5,0xFE,0x40,0x0000,0x0008); | 106 | ARK3116_SND(serial, 5, 0xFE, 0x40, 0x0000, 0x0008); |
106 | ARK3116_SND(serial, 6,0xFE,0x40,0x0000,0x000B); | 107 | ARK3116_SND(serial, 6, 0xFE, 0x40, 0x0000, 0x000B); |
107 | 108 | ||
108 | /* <-- seq7 */ | 109 | /* <-- seq7 */ |
109 | ARK3116_RCV(serial, 7,0xFE,0xC0,0x0000,0x0003, 0x00, buf); | 110 | ARK3116_RCV(serial, 7, 0xFE, 0xC0, 0x0000, 0x0003, 0x00, buf); |
110 | ARK3116_SND(serial, 8,0xFE,0x40,0x0080,0x0003); | 111 | ARK3116_SND(serial, 8, 0xFE, 0x40, 0x0080, 0x0003); |
111 | ARK3116_SND(serial, 9,0xFE,0x40,0x001A,0x0000); | 112 | ARK3116_SND(serial, 9, 0xFE, 0x40, 0x001A, 0x0000); |
112 | ARK3116_SND(serial,10,0xFE,0x40,0x0000,0x0001); | 113 | ARK3116_SND(serial, 10, 0xFE, 0x40, 0x0000, 0x0001); |
113 | ARK3116_SND(serial,11,0xFE,0x40,0x0000,0x0003); | 114 | ARK3116_SND(serial, 11, 0xFE, 0x40, 0x0000, 0x0003); |
114 | 115 | ||
115 | /* <-- seq12 */ | 116 | /* <-- seq12 */ |
116 | ARK3116_RCV(serial,12,0xFE,0xC0,0x0000,0x0004, 0x00, buf); | 117 | ARK3116_RCV(serial, 12, 0xFE, 0xC0, 0x0000, 0x0004, 0x00, buf); |
117 | ARK3116_SND(serial,13,0xFE,0x40,0x0000,0x0004); | 118 | ARK3116_SND(serial, 13, 0xFE, 0x40, 0x0000, 0x0004); |
118 | 119 | ||
119 | /* 14 */ | 120 | /* 14 */ |
120 | ARK3116_RCV(serial,14,0xFE,0xC0,0x0000,0x0004, 0x00, buf); | 121 | ARK3116_RCV(serial, 14, 0xFE, 0xC0, 0x0000, 0x0004, 0x00, buf); |
121 | ARK3116_SND(serial,15,0xFE,0x40,0x0000,0x0004); | 122 | ARK3116_SND(serial, 15, 0xFE, 0x40, 0x0000, 0x0004); |
122 | 123 | ||
123 | /* 16 */ | 124 | /* 16 */ |
124 | ARK3116_RCV(serial,16,0xFE,0xC0,0x0000,0x0004, 0x00, buf); | 125 | ARK3116_RCV(serial, 16, 0xFE, 0xC0, 0x0000, 0x0004, 0x00, buf); |
125 | /* --> seq17 */ | 126 | /* --> seq17 */ |
126 | ARK3116_SND(serial,17,0xFE,0x40,0x0001,0x0004); | 127 | ARK3116_SND(serial, 17, 0xFE, 0x40, 0x0001, 0x0004); |
127 | 128 | ||
128 | /* <-- seq18 */ | 129 | /* <-- seq18 */ |
129 | ARK3116_RCV(serial,18,0xFE,0xC0,0x0000,0x0004, 0x01, buf); | 130 | ARK3116_RCV(serial, 18, 0xFE, 0xC0, 0x0000, 0x0004, 0x01, buf); |
130 | 131 | ||
131 | /* --> seq19 */ | 132 | /* --> seq19 */ |
132 | ARK3116_SND(serial,19,0xFE,0x40,0x0003,0x0004); | 133 | ARK3116_SND(serial, 19, 0xFE, 0x40, 0x0003, 0x0004); |
133 | |||
134 | 134 | ||
135 | /* <-- seq20 */ | 135 | /* <-- seq20 */ |
136 | /* seems like serial port status info (RTS, CTS,...) */ | 136 | /* seems like serial port status info (RTS, CTS, ...) */ |
137 | /* returns modem control line status ?! */ | 137 | /* returns modem control line status?! */ |
138 | ARK3116_RCV(serial,20,0xFE,0xC0,0x0000,0x0006, 0xFF, buf); | 138 | ARK3116_RCV(serial, 20, 0xFE, 0xC0, 0x0000, 0x0006, 0xFF, buf); |
139 | 139 | ||
140 | /* set 9600 baud & do some init ?! */ | 140 | /* set 9600 baud & do some init?! */ |
141 | ARK3116_SND(serial,147,0xFE,0x40,0x0083,0x0003); | 141 | ARK3116_SND(serial, 147, 0xFE, 0x40, 0x0083, 0x0003); |
142 | ARK3116_SND(serial,148,0xFE,0x40,0x0038,0x0000); | 142 | ARK3116_SND(serial, 148, 0xFE, 0x40, 0x0038, 0x0000); |
143 | ARK3116_SND(serial,149,0xFE,0x40,0x0001,0x0001); | 143 | ARK3116_SND(serial, 149, 0xFE, 0x40, 0x0001, 0x0001); |
144 | ARK3116_SND(serial,150,0xFE,0x40,0x0003,0x0003); | 144 | ARK3116_SND(serial, 150, 0xFE, 0x40, 0x0003, 0x0003); |
145 | ARK3116_RCV(serial,151,0xFE,0xC0,0x0000,0x0004,0x03, buf); | 145 | ARK3116_RCV(serial, 151, 0xFE, 0xC0, 0x0000, 0x0004, 0x03, buf); |
146 | ARK3116_SND(serial,152,0xFE,0x40,0x0000,0x0003); | 146 | ARK3116_SND(serial, 152, 0xFE, 0x40, 0x0000, 0x0003); |
147 | ARK3116_RCV(serial,153,0xFE,0xC0,0x0000,0x0003,0x00, buf); | 147 | ARK3116_RCV(serial, 153, 0xFE, 0xC0, 0x0000, 0x0003, 0x00, buf); |
148 | ARK3116_SND(serial,154,0xFE,0x40,0x0003,0x0003); | 148 | ARK3116_SND(serial, 154, 0xFE, 0x40, 0x0003, 0x0003); |
149 | 149 | ||
150 | kfree(buf); | 150 | kfree(buf); |
151 | return(0); | 151 | return 0; |
152 | 152 | ||
153 | cleanup: | 153 | cleanup: |
154 | for (--i; i>=0; --i) | 154 | for (--i; i >= 0; --i) |
155 | usb_set_serial_port_data(serial->port[i], NULL); | 155 | usb_set_serial_port_data(serial->port[i], NULL); |
156 | return -ENOMEM; | 156 | return -ENOMEM; |
157 | } | 157 | } |
@@ -180,7 +180,8 @@ static void ark3116_set_termios(struct usb_serial_port *port, | |||
180 | spin_lock_irqsave(&priv->lock, flags); | 180 | spin_lock_irqsave(&priv->lock, flags); |
181 | if (!priv->termios_initialized) { | 181 | if (!priv->termios_initialized) { |
182 | *(port->tty->termios) = tty_std_termios; | 182 | *(port->tty->termios) = tty_std_termios; |
183 | port->tty->termios->c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; | 183 | port->tty->termios->c_cflag = B9600 | CS8 |
184 | | CREAD | HUPCL | CLOCAL; | ||
184 | priv->termios_initialized = 1; | 185 | priv->termios_initialized = 1; |
185 | } | 186 | } |
186 | spin_unlock_irqrestore(&priv->lock, flags); | 187 | spin_unlock_irqrestore(&priv->lock, flags); |
@@ -204,8 +205,8 @@ static void ark3116_set_termios(struct usb_serial_port *port, | |||
204 | } | 205 | } |
205 | 206 | ||
206 | /* set data bit count (8/7/6/5) */ | 207 | /* set data bit count (8/7/6/5) */ |
207 | if (cflag & CSIZE){ | 208 | if (cflag & CSIZE) { |
208 | switch (cflag & CSIZE){ | 209 | switch (cflag & CSIZE) { |
209 | case CS5: | 210 | case CS5: |
210 | config |= 0x00; | 211 | config |= 0x00; |
211 | dbg("setting CS5"); | 212 | dbg("setting CS5"); |
@@ -219,7 +220,8 @@ static void ark3116_set_termios(struct usb_serial_port *port, | |||
219 | dbg("setting CS7"); | 220 | dbg("setting CS7"); |
220 | break; | 221 | break; |
221 | default: | 222 | default: |
222 | err ("CSIZE was set but not CS5-CS8, using CS8!"); | 223 | err("CSIZE was set but not CS5-CS8, using CS8!"); |
224 | /* fall through */ | ||
223 | case CS8: | 225 | case CS8: |
224 | config |= 0x03; | 226 | config |= 0x03; |
225 | dbg("setting CS8"); | 227 | dbg("setting CS8"); |
@@ -227,8 +229,8 @@ static void ark3116_set_termios(struct usb_serial_port *port, | |||
227 | } | 229 | } |
228 | } | 230 | } |
229 | 231 | ||
230 | /* set parity (NONE,EVEN,ODD) */ | 232 | /* set parity (NONE/EVEN/ODD) */ |
231 | if (cflag & PARENB){ | 233 | if (cflag & PARENB) { |
232 | if (cflag & PARODD) { | 234 | if (cflag & PARODD) { |
233 | config |= 0x08; | 235 | config |= 0x08; |
234 | dbg("setting parity to ODD"); | 236 | dbg("setting parity to ODD"); |
@@ -240,20 +242,19 @@ static void ark3116_set_termios(struct usb_serial_port *port, | |||
240 | dbg("setting parity to NONE"); | 242 | dbg("setting parity to NONE"); |
241 | } | 243 | } |
242 | 244 | ||
243 | /* SET STOPBIT (1/2) */ | 245 | /* set stop bit (1/2) */ |
244 | if (cflag & CSTOPB) { | 246 | if (cflag & CSTOPB) { |
245 | config |= 0x04; | 247 | config |= 0x04; |
246 | dbg ("setting 2 stop bits"); | 248 | dbg("setting 2 stop bits"); |
247 | } else { | 249 | } else { |
248 | dbg ("setting 1 stop bit"); | 250 | dbg("setting 1 stop bit"); |
249 | } | 251 | } |
250 | 252 | ||
251 | 253 | /* set baudrate */ | |
252 | /* set baudrate: */ | ||
253 | baud = 0; | 254 | baud = 0; |
254 | switch (cflag & CBAUD){ | 255 | switch (cflag & CBAUD) { |
255 | case B0: | 256 | case B0: |
256 | err("can't set 0baud, using 9600 instead"); | 257 | err("can't set 0 baud, using 9600 instead"); |
257 | break; | 258 | break; |
258 | case B75: baud = 75; break; | 259 | case B75: baud = 75; break; |
259 | case B150: baud = 150; break; | 260 | case B150: baud = 150; break; |
@@ -285,38 +286,40 @@ static void ark3116_set_termios(struct usb_serial_port *port, | |||
285 | */ | 286 | */ |
286 | if (baud == 460800) | 287 | if (baud == 460800) |
287 | /* strange, for 460800 the formula is wrong | 288 | /* strange, for 460800 the formula is wrong |
288 | * (dont use round(), then 9600baud is wrong) */ | 289 | * if using round() then 9600baud is wrong) */ |
289 | ark3116_baud = 7; | 290 | ark3116_baud = 7; |
290 | else | 291 | else |
291 | ark3116_baud = 3000000 / baud; | 292 | ark3116_baud = 3000000 / baud; |
292 | 293 | ||
293 | /* ? */ | 294 | /* ? */ |
294 | ARK3116_RCV(serial,0,0xFE,0xC0,0x0000,0x0003, 0x03, buf); | 295 | ARK3116_RCV(serial, 0, 0xFE, 0xC0, 0x0000, 0x0003, 0x03, buf); |
296 | |||
295 | /* offset = buf[0]; */ | 297 | /* offset = buf[0]; */ |
296 | /* offset = 0x03; */ | 298 | /* offset = 0x03; */ |
297 | /* dbg("using 0x%04X as target for 0x0003:",0x0080+offset); */ | 299 | /* dbg("using 0x%04X as target for 0x0003:", 0x0080 + offset); */ |
298 | |||
299 | 300 | ||
300 | /* set baudrate */ | 301 | /* set baudrate */ |
301 | dbg("setting baudrate to %d (->reg=%d)",baud,ark3116_baud); | 302 | dbg("setting baudrate to %d (->reg=%d)", baud, ark3116_baud); |
302 | ARK3116_SND(serial,147,0xFE,0x40,0x0083,0x0003); | 303 | ARK3116_SND(serial, 147, 0xFE, 0x40, 0x0083, 0x0003); |
303 | ARK3116_SND(serial,148,0xFE,0x40,(ark3116_baud & 0x00FF) ,0x0000); | 304 | ARK3116_SND(serial, 148, 0xFE, 0x40, |
304 | ARK3116_SND(serial,149,0xFE,0x40,(ark3116_baud & 0xFF00)>>8,0x0001); | 305 | (ark3116_baud & 0x00FF), 0x0000); |
305 | ARK3116_SND(serial,150,0xFE,0x40,0x0003,0x0003); | 306 | ARK3116_SND(serial, 149, 0xFE, 0x40, |
307 | (ark3116_baud & 0xFF00) >> 8, 0x0001); | ||
308 | ARK3116_SND(serial, 150, 0xFE, 0x40, 0x0003, 0x0003); | ||
306 | 309 | ||
307 | /* ? */ | 310 | /* ? */ |
308 | ARK3116_RCV(serial,151,0xFE,0xC0,0x0000,0x0004,0x03, buf); | 311 | ARK3116_RCV(serial, 151, 0xFE, 0xC0, 0x0000, 0x0004, 0x03, buf); |
309 | ARK3116_SND(serial,152,0xFE,0x40,0x0000,0x0003); | 312 | ARK3116_SND(serial, 152, 0xFE, 0x40, 0x0000, 0x0003); |
310 | 313 | ||
311 | /* set data bit count, stop bit count & parity: */ | 314 | /* set data bit count, stop bit count & parity: */ |
312 | dbg("updating bit count, stop bit or parity (cfg=0x%02X)", config); | 315 | dbg("updating bit count, stop bit or parity (cfg=0x%02X)", config); |
313 | ARK3116_RCV(serial,153,0xFE,0xC0,0x0000,0x0003,0x00, buf); | 316 | ARK3116_RCV(serial, 153, 0xFE, 0xC0, 0x0000, 0x0003, 0x00, buf); |
314 | ARK3116_SND(serial,154,0xFE,0x40,config,0x0003); | 317 | ARK3116_SND(serial, 154, 0xFE, 0x40, config, 0x0003); |
315 | 318 | ||
316 | if (cflag & CRTSCTS) | 319 | if (cflag & CRTSCTS) |
317 | dbg("CRTSCTS not supported by chipset ?!"); | 320 | dbg("CRTSCTS not supported by chipset?!"); |
318 | 321 | ||
319 | /* TEST ARK3116_SND(154,0xFE,0x40,0xFFFF, 0x0006); */ | 322 | /* TEST ARK3116_SND(154, 0xFE, 0x40, 0xFFFF, 0x0006); */ |
320 | 323 | ||
321 | kfree(buf); | 324 | kfree(buf); |
322 | return; | 325 | return; |
@@ -329,11 +332,11 @@ static int ark3116_open(struct usb_serial_port *port, struct file *filp) | |||
329 | char *buf; | 332 | char *buf; |
330 | int result = 0; | 333 | int result = 0; |
331 | 334 | ||
332 | dbg("%s - port %d", __FUNCTION__, port->number); | 335 | dbg("%s - port %d", __FUNCTION__, port->number); |
333 | 336 | ||
334 | buf = kmalloc(1, GFP_KERNEL); | 337 | buf = kmalloc(1, GFP_KERNEL); |
335 | if (!buf) { | 338 | if (!buf) { |
336 | dbg("error kmalloc -> out of mem ?"); | 339 | dbg("error kmalloc -> out of mem?"); |
337 | return -ENOMEM; | 340 | return -ENOMEM; |
338 | } | 341 | } |
339 | 342 | ||
@@ -342,44 +345,68 @@ static int ark3116_open(struct usb_serial_port *port, struct file *filp) | |||
342 | return result; | 345 | return result; |
343 | 346 | ||
344 | /* open */ | 347 | /* open */ |
345 | ARK3116_RCV(serial,111,0xFE,0xC0,0x0000,0x0003, 0x02, buf); | 348 | ARK3116_RCV(serial, 111, 0xFE, 0xC0, 0x0000, 0x0003, 0x02, buf); |
346 | 349 | ||
347 | ARK3116_SND(serial,112,0xFE,0x40,0x0082,0x0003); | 350 | ARK3116_SND(serial, 112, 0xFE, 0x40, 0x0082, 0x0003); |
348 | ARK3116_SND(serial,113,0xFE,0x40,0x001A,0x0000); | 351 | ARK3116_SND(serial, 113, 0xFE, 0x40, 0x001A, 0x0000); |
349 | ARK3116_SND(serial,114,0xFE,0x40,0x0000,0x0001); | 352 | ARK3116_SND(serial, 114, 0xFE, 0x40, 0x0000, 0x0001); |
350 | ARK3116_SND(serial,115,0xFE,0x40,0x0002,0x0003); | 353 | ARK3116_SND(serial, 115, 0xFE, 0x40, 0x0002, 0x0003); |
351 | 354 | ||
352 | ARK3116_RCV(serial,116,0xFE,0xC0,0x0000,0x0004, 0x03, buf); | 355 | ARK3116_RCV(serial, 116, 0xFE, 0xC0, 0x0000, 0x0004, 0x03, buf); |
353 | ARK3116_SND(serial,117,0xFE,0x40,0x0002,0x0004); | 356 | ARK3116_SND(serial, 117, 0xFE, 0x40, 0x0002, 0x0004); |
354 | 357 | ||
355 | ARK3116_RCV(serial,118,0xFE,0xC0,0x0000,0x0004, 0x02, buf); | 358 | ARK3116_RCV(serial, 118, 0xFE, 0xC0, 0x0000, 0x0004, 0x02, buf); |
356 | ARK3116_SND(serial,119,0xFE,0x40,0x0000,0x0004); | 359 | ARK3116_SND(serial, 119, 0xFE, 0x40, 0x0000, 0x0004); |
357 | 360 | ||
358 | ARK3116_RCV(serial,120,0xFE,0xC0,0x0000,0x0004, 0x00, buf); | 361 | ARK3116_RCV(serial, 120, 0xFE, 0xC0, 0x0000, 0x0004, 0x00, buf); |
359 | 362 | ||
360 | ARK3116_SND(serial,121,0xFE,0x40,0x0001,0x0004); | 363 | ARK3116_SND(serial, 121, 0xFE, 0x40, 0x0001, 0x0004); |
361 | 364 | ||
362 | ARK3116_RCV(serial,122,0xFE,0xC0,0x0000,0x0004, 0x01, buf); | 365 | ARK3116_RCV(serial, 122, 0xFE, 0xC0, 0x0000, 0x0004, 0x01, buf); |
363 | 366 | ||
364 | ARK3116_SND(serial,123,0xFE,0x40,0x0003,0x0004); | 367 | ARK3116_SND(serial, 123, 0xFE, 0x40, 0x0003, 0x0004); |
365 | 368 | ||
366 | /* returns different values (control lines ?!) */ | 369 | /* returns different values (control lines?!) */ |
367 | ARK3116_RCV(serial,124,0xFE,0xC0,0x0000,0x0006, 0xFF, buf); | 370 | ARK3116_RCV(serial, 124, 0xFE, 0xC0, 0x0000, 0x0006, 0xFF, buf); |
368 | 371 | ||
369 | /* initialise termios: */ | 372 | /* initialise termios */ |
370 | if (port->tty) | 373 | if (port->tty) |
371 | ark3116_set_termios(port, &tmp_termios); | 374 | ark3116_set_termios(port, &tmp_termios); |
372 | 375 | ||
373 | kfree(buf); | 376 | kfree(buf); |
374 | 377 | ||
375 | return result; | 378 | return result; |
376 | |||
377 | } | 379 | } |
378 | 380 | ||
379 | static int ark3116_ioctl(struct usb_serial_port *port, struct file *file, | 381 | static int ark3116_ioctl(struct usb_serial_port *port, struct file *file, |
380 | unsigned int cmd, unsigned long arg) | 382 | unsigned int cmd, unsigned long arg) |
381 | { | 383 | { |
382 | dbg("ioctl not supported yet..."); | 384 | struct serial_struct serstruct; |
385 | void __user *user_arg = (void __user *)arg; | ||
386 | |||
387 | switch (cmd) { | ||
388 | case TIOCGSERIAL: | ||
389 | /* XXX: Some of these values are probably wrong. */ | ||
390 | memset(&serstruct, 0, sizeof (serstruct)); | ||
391 | serstruct.type = PORT_16654; | ||
392 | serstruct.line = port->serial->minor; | ||
393 | serstruct.port = port->number; | ||
394 | serstruct.custom_divisor = 0; | ||
395 | serstruct.baud_base = 460800; | ||
396 | |||
397 | if (copy_to_user(user_arg, &serstruct, sizeof (serstruct))) | ||
398 | return -EFAULT; | ||
399 | |||
400 | return 0; | ||
401 | case TIOCSSERIAL: | ||
402 | if (copy_from_user(&serstruct, user_arg, sizeof (serstruct))) | ||
403 | return -EFAULT; | ||
404 | return 0; | ||
405 | default: | ||
406 | dbg("%s cmd 0x%04x not supported", __FUNCTION__, cmd); | ||
407 | break; | ||
408 | } | ||
409 | |||
383 | return -ENOIOCTLCMD; | 410 | return -ENOIOCTLCMD; |
384 | } | 411 | } |
385 | 412 | ||
@@ -389,7 +416,7 @@ static int ark3116_tiocmget(struct usb_serial_port *port, struct file *file) | |||
389 | char *buf; | 416 | char *buf; |
390 | char temp; | 417 | char temp; |
391 | 418 | ||
392 | /* seems like serial port status info (RTS, CTS,...) is stored | 419 | /* seems like serial port status info (RTS, CTS, ...) is stored |
393 | * in reg(?) 0x0006 | 420 | * in reg(?) 0x0006 |
394 | * pcb connection point 11 = GND -> sets bit4 of response | 421 | * pcb connection point 11 = GND -> sets bit4 of response |
395 | * pcb connection point 7 = GND -> sets bit6 of response | 422 | * pcb connection point 7 = GND -> sets bit6 of response |
@@ -401,16 +428,16 @@ static int ark3116_tiocmget(struct usb_serial_port *port, struct file *file) | |||
401 | return -ENOMEM; | 428 | return -ENOMEM; |
402 | } | 429 | } |
403 | 430 | ||
404 | /* read register: */ | 431 | /* read register */ |
405 | ARK3116_RCV_QUIET(serial,0xFE,0xC0,0x0000,0x0006,buf); | 432 | ARK3116_RCV_QUIET(serial, 0xFE, 0xC0, 0x0000, 0x0006, buf); |
406 | temp = buf[0]; | 433 | temp = buf[0]; |
407 | kfree(buf); | 434 | kfree(buf); |
408 | 435 | ||
409 | /* i do not really know if bit4=CTS and bit6=DSR... was just a | 436 | /* i do not really know if bit4=CTS and bit6=DSR... just a |
410 | * quick guess !! | 437 | * quick guess! |
411 | */ | 438 | */ |
412 | return (temp & (1<<4) ? TIOCM_CTS : 0) | | 439 | return (temp & (1<<4) ? TIOCM_CTS : 0) |
413 | (temp & (1<<6) ? TIOCM_DSR : 0); | 440 | | (temp & (1<<6) ? TIOCM_DSR : 0); |
414 | } | 441 | } |
415 | 442 | ||
416 | static struct usb_driver ark3116_driver = { | 443 | static struct usb_driver ark3116_driver = { |
diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c index ee70fddcab60..e1173c1aee37 100644 --- a/drivers/usb/serial/cypress_m8.c +++ b/drivers/usb/serial/cypress_m8.c | |||
@@ -129,6 +129,9 @@ struct cypress_private { | |||
129 | int cmd_ctrl; /* always set this to 1 before issuing a command */ | 129 | int cmd_ctrl; /* always set this to 1 before issuing a command */ |
130 | struct cypress_buf *buf; /* write buffer */ | 130 | struct cypress_buf *buf; /* write buffer */ |
131 | int write_urb_in_use; /* write urb in use indicator */ | 131 | int write_urb_in_use; /* write urb in use indicator */ |
132 | int write_urb_interval; /* interval to use for write urb */ | ||
133 | int read_urb_interval; /* interval to use for read urb */ | ||
134 | int comm_is_ok; /* true if communication is (still) ok */ | ||
132 | int termios_initialized; | 135 | int termios_initialized; |
133 | __u8 line_control; /* holds dtr / rts value */ | 136 | __u8 line_control; /* holds dtr / rts value */ |
134 | __u8 current_status; /* received from last read - info on dsr,cts,cd,ri,etc */ | 137 | __u8 current_status; /* received from last read - info on dsr,cts,cd,ri,etc */ |
@@ -168,6 +171,7 @@ static int cypress_tiocmset (struct usb_serial_port *port, struct file *file, | |||
168 | static int cypress_chars_in_buffer (struct usb_serial_port *port); | 171 | static int cypress_chars_in_buffer (struct usb_serial_port *port); |
169 | static void cypress_throttle (struct usb_serial_port *port); | 172 | static void cypress_throttle (struct usb_serial_port *port); |
170 | static void cypress_unthrottle (struct usb_serial_port *port); | 173 | static void cypress_unthrottle (struct usb_serial_port *port); |
174 | static void cypress_set_dead (struct usb_serial_port *port); | ||
171 | static void cypress_read_int_callback (struct urb *urb, struct pt_regs *regs); | 175 | static void cypress_read_int_callback (struct urb *urb, struct pt_regs *regs); |
172 | static void cypress_write_int_callback (struct urb *urb, struct pt_regs *regs); | 176 | static void cypress_write_int_callback (struct urb *urb, struct pt_regs *regs); |
173 | /* baud helper functions */ | 177 | /* baud helper functions */ |
@@ -288,6 +292,9 @@ static int cypress_serial_control (struct usb_serial_port *port, unsigned baud_m | |||
288 | 292 | ||
289 | priv = usb_get_serial_port_data(port); | 293 | priv = usb_get_serial_port_data(port); |
290 | 294 | ||
295 | if (!priv->comm_is_ok) | ||
296 | return -ENODEV; | ||
297 | |||
291 | switch(cypress_request_type) { | 298 | switch(cypress_request_type) { |
292 | case CYPRESS_SET_CONFIG: | 299 | case CYPRESS_SET_CONFIG: |
293 | 300 | ||
@@ -365,13 +372,12 @@ static int cypress_serial_control (struct usb_serial_port *port, unsigned baud_m | |||
365 | if (tries++ >= 3) | 372 | if (tries++ >= 3) |
366 | break; | 373 | break; |
367 | 374 | ||
368 | if (retval == EPIPE) | 375 | } while (retval != 8 && retval != -ENODEV); |
369 | usb_clear_halt(port->serial->dev, 0x00); | ||
370 | } while (retval != 8 && retval != ENODEV); | ||
371 | 376 | ||
372 | if (retval != 8) | 377 | if (retval != 8) { |
373 | err("%s - failed sending serial line settings - %d", __FUNCTION__, retval); | 378 | err("%s - failed sending serial line settings - %d", __FUNCTION__, retval); |
374 | else { | 379 | cypress_set_dead(port); |
380 | } else { | ||
375 | spin_lock_irqsave(&priv->lock, flags); | 381 | spin_lock_irqsave(&priv->lock, flags); |
376 | priv->baud_rate = new_baudrate; | 382 | priv->baud_rate = new_baudrate; |
377 | priv->cbr_mask = baud_mask; | 383 | priv->cbr_mask = baud_mask; |
@@ -392,12 +398,11 @@ static int cypress_serial_control (struct usb_serial_port *port, unsigned baud_m | |||
392 | if (tries++ >= 3) | 398 | if (tries++ >= 3) |
393 | break; | 399 | break; |
394 | 400 | ||
395 | if (retval == EPIPE) | 401 | } while (retval != 5 && retval != -ENODEV); |
396 | usb_clear_halt(port->serial->dev, 0x00); | ||
397 | } while (retval != 5 && retval != ENODEV); | ||
398 | 402 | ||
399 | if (retval != 5) { | 403 | if (retval != 5) { |
400 | err("%s - failed to retrieve serial line settings - %d", __FUNCTION__, retval); | 404 | err("%s - failed to retrieve serial line settings - %d", __FUNCTION__, retval); |
405 | cypress_set_dead(port); | ||
401 | return retval; | 406 | return retval; |
402 | } else { | 407 | } else { |
403 | spin_lock_irqsave(&priv->lock, flags); | 408 | spin_lock_irqsave(&priv->lock, flags); |
@@ -419,6 +424,24 @@ static int cypress_serial_control (struct usb_serial_port *port, unsigned baud_m | |||
419 | } /* cypress_serial_control */ | 424 | } /* cypress_serial_control */ |
420 | 425 | ||
421 | 426 | ||
427 | static void cypress_set_dead(struct usb_serial_port *port) | ||
428 | { | ||
429 | struct cypress_private *priv = usb_get_serial_port_data(port); | ||
430 | unsigned long flags; | ||
431 | |||
432 | spin_lock_irqsave(&priv->lock, flags); | ||
433 | if (!priv->comm_is_ok) { | ||
434 | spin_unlock_irqrestore(&priv->lock, flags); | ||
435 | return; | ||
436 | } | ||
437 | priv->comm_is_ok = 0; | ||
438 | spin_unlock_irqrestore(&priv->lock, flags); | ||
439 | |||
440 | err("cypress_m8 suspending failing port %d - interval might be too short", | ||
441 | port->number); | ||
442 | } | ||
443 | |||
444 | |||
422 | /* given a baud mask, it will return integer baud on success */ | 445 | /* given a baud mask, it will return integer baud on success */ |
423 | static int mask_to_rate (unsigned mask) | 446 | static int mask_to_rate (unsigned mask) |
424 | { | 447 | { |
@@ -472,13 +495,15 @@ static unsigned rate_to_mask (int rate) | |||
472 | static int generic_startup (struct usb_serial *serial) | 495 | static int generic_startup (struct usb_serial *serial) |
473 | { | 496 | { |
474 | struct cypress_private *priv; | 497 | struct cypress_private *priv; |
498 | struct usb_serial_port *port = serial->port[0]; | ||
475 | 499 | ||
476 | dbg("%s - port %d", __FUNCTION__, serial->port[0]->number); | 500 | dbg("%s - port %d", __FUNCTION__, port->number); |
477 | 501 | ||
478 | priv = kzalloc(sizeof (struct cypress_private), GFP_KERNEL); | 502 | priv = kzalloc(sizeof (struct cypress_private), GFP_KERNEL); |
479 | if (!priv) | 503 | if (!priv) |
480 | return -ENOMEM; | 504 | return -ENOMEM; |
481 | 505 | ||
506 | priv->comm_is_ok = !0; | ||
482 | spin_lock_init(&priv->lock); | 507 | spin_lock_init(&priv->lock); |
483 | priv->buf = cypress_buf_alloc(CYPRESS_BUF_SIZE); | 508 | priv->buf = cypress_buf_alloc(CYPRESS_BUF_SIZE); |
484 | if (priv->buf == NULL) { | 509 | if (priv->buf == NULL) { |
@@ -489,13 +514,24 @@ static int generic_startup (struct usb_serial *serial) | |||
489 | 514 | ||
490 | usb_reset_configuration (serial->dev); | 515 | usb_reset_configuration (serial->dev); |
491 | 516 | ||
492 | interval = 1; | ||
493 | priv->cmd_ctrl = 0; | 517 | priv->cmd_ctrl = 0; |
494 | priv->line_control = 0; | 518 | priv->line_control = 0; |
495 | priv->termios_initialized = 0; | 519 | priv->termios_initialized = 0; |
496 | priv->rx_flags = 0; | 520 | priv->rx_flags = 0; |
497 | priv->cbr_mask = B300; | 521 | priv->cbr_mask = B300; |
498 | usb_set_serial_port_data(serial->port[0], priv); | 522 | if (interval > 0) { |
523 | priv->write_urb_interval = interval; | ||
524 | priv->read_urb_interval = interval; | ||
525 | dbg("%s - port %d read & write intervals forced to %d", | ||
526 | __FUNCTION__,port->number,interval); | ||
527 | } else { | ||
528 | priv->write_urb_interval = port->interrupt_out_urb->interval; | ||
529 | priv->read_urb_interval = port->interrupt_in_urb->interval; | ||
530 | dbg("%s - port %d intervals: read=%d write=%d", | ||
531 | __FUNCTION__,port->number, | ||
532 | priv->read_urb_interval,priv->write_urb_interval); | ||
533 | } | ||
534 | usb_set_serial_port_data(port, priv); | ||
499 | 535 | ||
500 | return 0; | 536 | return 0; |
501 | } | 537 | } |
@@ -585,6 +621,9 @@ static int cypress_open (struct usb_serial_port *port, struct file *filp) | |||
585 | 621 | ||
586 | dbg("%s - port %d", __FUNCTION__, port->number); | 622 | dbg("%s - port %d", __FUNCTION__, port->number); |
587 | 623 | ||
624 | if (!priv->comm_is_ok) | ||
625 | return -EIO; | ||
626 | |||
588 | /* clear halts before open */ | 627 | /* clear halts before open */ |
589 | usb_clear_halt(serial->dev, 0x81); | 628 | usb_clear_halt(serial->dev, 0x81); |
590 | usb_clear_halt(serial->dev, 0x02); | 629 | usb_clear_halt(serial->dev, 0x02); |
@@ -624,11 +663,12 @@ static int cypress_open (struct usb_serial_port *port, struct file *filp) | |||
624 | usb_fill_int_urb(port->interrupt_in_urb, serial->dev, | 663 | usb_fill_int_urb(port->interrupt_in_urb, serial->dev, |
625 | usb_rcvintpipe(serial->dev, port->interrupt_in_endpointAddress), | 664 | usb_rcvintpipe(serial->dev, port->interrupt_in_endpointAddress), |
626 | port->interrupt_in_urb->transfer_buffer, port->interrupt_in_urb->transfer_buffer_length, | 665 | port->interrupt_in_urb->transfer_buffer, port->interrupt_in_urb->transfer_buffer_length, |
627 | cypress_read_int_callback, port, interval); | 666 | cypress_read_int_callback, port, priv->read_urb_interval); |
628 | result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); | 667 | result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); |
629 | 668 | ||
630 | if (result){ | 669 | if (result){ |
631 | dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __FUNCTION__, result); | 670 | dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __FUNCTION__, result); |
671 | cypress_set_dead(port); | ||
632 | } | 672 | } |
633 | 673 | ||
634 | return result; | 674 | return result; |
@@ -733,6 +773,9 @@ static void cypress_send(struct usb_serial_port *port) | |||
733 | struct cypress_private *priv = usb_get_serial_port_data(port); | 773 | struct cypress_private *priv = usb_get_serial_port_data(port); |
734 | unsigned long flags; | 774 | unsigned long flags; |
735 | 775 | ||
776 | if (!priv->comm_is_ok) | ||
777 | return; | ||
778 | |||
736 | dbg("%s - port %d", __FUNCTION__, port->number); | 779 | dbg("%s - port %d", __FUNCTION__, port->number); |
737 | dbg("%s - interrupt out size is %d", __FUNCTION__, port->interrupt_out_size); | 780 | dbg("%s - interrupt out size is %d", __FUNCTION__, port->interrupt_out_size); |
738 | 781 | ||
@@ -806,14 +849,16 @@ send: | |||
806 | usb_serial_debug_data(debug, &port->dev, __FUNCTION__, port->interrupt_out_size, | 849 | usb_serial_debug_data(debug, &port->dev, __FUNCTION__, port->interrupt_out_size, |
807 | port->interrupt_out_urb->transfer_buffer); | 850 | port->interrupt_out_urb->transfer_buffer); |
808 | 851 | ||
809 | port->interrupt_out_urb->transfer_buffer_length = actual_size; | 852 | usb_fill_int_urb(port->interrupt_out_urb, port->serial->dev, |
810 | port->interrupt_out_urb->dev = port->serial->dev; | 853 | usb_sndintpipe(port->serial->dev, port->interrupt_out_endpointAddress), |
811 | port->interrupt_out_urb->interval = interval; | 854 | port->interrupt_out_buffer, port->interrupt_out_size, |
855 | cypress_write_int_callback, port, priv->write_urb_interval); | ||
812 | result = usb_submit_urb (port->interrupt_out_urb, GFP_ATOMIC); | 856 | result = usb_submit_urb (port->interrupt_out_urb, GFP_ATOMIC); |
813 | if (result) { | 857 | if (result) { |
814 | dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __FUNCTION__, | 858 | dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __FUNCTION__, |
815 | result); | 859 | result); |
816 | priv->write_urb_in_use = 0; | 860 | priv->write_urb_in_use = 0; |
861 | cypress_set_dead(port); | ||
817 | } | 862 | } |
818 | 863 | ||
819 | spin_lock_irqsave(&priv->lock, flags); | 864 | spin_lock_irqsave(&priv->lock, flags); |
@@ -1214,13 +1259,18 @@ static void cypress_unthrottle (struct usb_serial_port *port) | |||
1214 | priv->rx_flags = 0; | 1259 | priv->rx_flags = 0; |
1215 | spin_unlock_irqrestore(&priv->lock, flags); | 1260 | spin_unlock_irqrestore(&priv->lock, flags); |
1216 | 1261 | ||
1262 | if (!priv->comm_is_ok) | ||
1263 | return; | ||
1264 | |||
1217 | if (actually_throttled) { | 1265 | if (actually_throttled) { |
1218 | port->interrupt_in_urb->dev = port->serial->dev; | 1266 | port->interrupt_in_urb->dev = port->serial->dev; |
1219 | 1267 | ||
1220 | result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); | 1268 | result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); |
1221 | if (result) | 1269 | if (result) { |
1222 | dev_err(&port->dev, "%s - failed submitting read urb, " | 1270 | dev_err(&port->dev, "%s - failed submitting read urb, " |
1223 | "error %d\n", __FUNCTION__, result); | 1271 | "error %d\n", __FUNCTION__, result); |
1272 | cypress_set_dead(port); | ||
1273 | } | ||
1224 | } | 1274 | } |
1225 | } | 1275 | } |
1226 | 1276 | ||
@@ -1240,9 +1290,22 @@ static void cypress_read_int_callback(struct urb *urb, struct pt_regs *regs) | |||
1240 | 1290 | ||
1241 | dbg("%s - port %d", __FUNCTION__, port->number); | 1291 | dbg("%s - port %d", __FUNCTION__, port->number); |
1242 | 1292 | ||
1243 | if (urb->status) { | 1293 | switch (urb->status) { |
1244 | dbg("%s - nonzero read status received: %d", __FUNCTION__, | 1294 | case 0: /* success */ |
1245 | urb->status); | 1295 | break; |
1296 | case -ECONNRESET: | ||
1297 | case -ENOENT: | ||
1298 | case -ESHUTDOWN: | ||
1299 | /* precursor to disconnect so just go away */ | ||
1300 | return; | ||
1301 | case -EPIPE: | ||
1302 | usb_clear_halt(port->serial->dev,0x81); | ||
1303 | break; | ||
1304 | default: | ||
1305 | /* something ugly is going on... */ | ||
1306 | dev_err(&urb->dev->dev,"%s - unexpected nonzero read status received: %d\n", | ||
1307 | __FUNCTION__,urb->status); | ||
1308 | cypress_set_dead(port); | ||
1246 | return; | 1309 | return; |
1247 | } | 1310 | } |
1248 | 1311 | ||
@@ -1343,18 +1406,20 @@ continue_read: | |||
1343 | 1406 | ||
1344 | /* Continue trying to always read... unless the port has closed. */ | 1407 | /* Continue trying to always read... unless the port has closed. */ |
1345 | 1408 | ||
1346 | if (port->open_count > 0) { | 1409 | if (port->open_count > 0 && priv->comm_is_ok) { |
1347 | usb_fill_int_urb(port->interrupt_in_urb, port->serial->dev, | 1410 | usb_fill_int_urb(port->interrupt_in_urb, port->serial->dev, |
1348 | usb_rcvintpipe(port->serial->dev, | 1411 | usb_rcvintpipe(port->serial->dev, |
1349 | port->interrupt_in_endpointAddress), | 1412 | port->interrupt_in_endpointAddress), |
1350 | port->interrupt_in_urb->transfer_buffer, | 1413 | port->interrupt_in_urb->transfer_buffer, |
1351 | port->interrupt_in_urb->transfer_buffer_length, | 1414 | port->interrupt_in_urb->transfer_buffer_length, |
1352 | cypress_read_int_callback, port, interval); | 1415 | cypress_read_int_callback, port, priv->read_urb_interval); |
1353 | result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); | 1416 | result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); |
1354 | if (result) | 1417 | if (result) { |
1355 | dev_err(&urb->dev->dev, "%s - failed resubmitting " | 1418 | dev_err(&urb->dev->dev, "%s - failed resubmitting " |
1356 | "read urb, error %d\n", __FUNCTION__, | 1419 | "read urb, error %d\n", __FUNCTION__, |
1357 | result); | 1420 | result); |
1421 | cypress_set_dead(port); | ||
1422 | } | ||
1358 | } | 1423 | } |
1359 | 1424 | ||
1360 | return; | 1425 | return; |
@@ -1380,20 +1445,26 @@ static void cypress_write_int_callback(struct urb *urb, struct pt_regs *regs) | |||
1380 | dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status); | 1445 | dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status); |
1381 | priv->write_urb_in_use = 0; | 1446 | priv->write_urb_in_use = 0; |
1382 | return; | 1447 | return; |
1383 | case -EPIPE: /* no break needed */ | 1448 | case -EPIPE: /* no break needed; clear halt and resubmit */ |
1449 | if (!priv->comm_is_ok) | ||
1450 | break; | ||
1384 | usb_clear_halt(port->serial->dev, 0x02); | 1451 | usb_clear_halt(port->serial->dev, 0x02); |
1385 | default: | ||
1386 | /* error in the urb, so we have to resubmit it */ | 1452 | /* error in the urb, so we have to resubmit it */ |
1387 | dbg("%s - Overflow in write", __FUNCTION__); | ||
1388 | dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status); | 1453 | dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status); |
1389 | port->interrupt_out_urb->transfer_buffer_length = 1; | 1454 | port->interrupt_out_urb->transfer_buffer_length = 1; |
1390 | port->interrupt_out_urb->dev = port->serial->dev; | 1455 | port->interrupt_out_urb->dev = port->serial->dev; |
1391 | result = usb_submit_urb(port->interrupt_out_urb, GFP_ATOMIC); | 1456 | result = usb_submit_urb(port->interrupt_out_urb, GFP_ATOMIC); |
1392 | if (result) | 1457 | if (!result) |
1393 | dev_err(&urb->dev->dev, "%s - failed resubmitting write urb, error %d\n", | ||
1394 | __FUNCTION__, result); | ||
1395 | else | ||
1396 | return; | 1458 | return; |
1459 | dev_err(&urb->dev->dev, "%s - failed resubmitting write urb, error %d\n", | ||
1460 | __FUNCTION__, result); | ||
1461 | cypress_set_dead(port); | ||
1462 | break; | ||
1463 | default: | ||
1464 | dev_err(&urb->dev->dev,"%s - unexpected nonzero write status received: %d\n", | ||
1465 | __FUNCTION__,urb->status); | ||
1466 | cypress_set_dead(port); | ||
1467 | break; | ||
1397 | } | 1468 | } |
1398 | 1469 | ||
1399 | priv->write_urb_in_use = 0; | 1470 | priv->write_urb_in_use = 0; |
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c index c6115aa1b445..1f7b72553f37 100644 --- a/drivers/usb/serial/ftdi_sio.c +++ b/drivers/usb/serial/ftdi_sio.c | |||
@@ -1101,25 +1101,29 @@ static ssize_t store_event_char(struct device *dev, struct device_attribute *att | |||
1101 | static DEVICE_ATTR(latency_timer, S_IWUSR | S_IRUGO, show_latency_timer, store_latency_timer); | 1101 | static DEVICE_ATTR(latency_timer, S_IWUSR | S_IRUGO, show_latency_timer, store_latency_timer); |
1102 | static DEVICE_ATTR(event_char, S_IWUSR, NULL, store_event_char); | 1102 | static DEVICE_ATTR(event_char, S_IWUSR, NULL, store_event_char); |
1103 | 1103 | ||
1104 | static void create_sysfs_attrs(struct usb_serial *serial) | 1104 | static int create_sysfs_attrs(struct usb_serial *serial) |
1105 | { | 1105 | { |
1106 | struct ftdi_private *priv; | 1106 | struct ftdi_private *priv; |
1107 | struct usb_device *udev; | 1107 | struct usb_device *udev; |
1108 | int retval = 0; | ||
1108 | 1109 | ||
1109 | dbg("%s",__FUNCTION__); | 1110 | dbg("%s",__FUNCTION__); |
1110 | 1111 | ||
1111 | priv = usb_get_serial_port_data(serial->port[0]); | 1112 | priv = usb_get_serial_port_data(serial->port[0]); |
1112 | udev = serial->dev; | 1113 | udev = serial->dev; |
1113 | 1114 | ||
1114 | /* XXX I've no idea if the original SIO supports the event_char | 1115 | /* XXX I've no idea if the original SIO supports the event_char |
1115 | * sysfs parameter, so I'm playing it safe. */ | 1116 | * sysfs parameter, so I'm playing it safe. */ |
1116 | if (priv->chip_type != SIO) { | 1117 | if (priv->chip_type != SIO) { |
1117 | dbg("sysfs attributes for %s", ftdi_chip_name[priv->chip_type]); | 1118 | dbg("sysfs attributes for %s", ftdi_chip_name[priv->chip_type]); |
1118 | device_create_file(&udev->dev, &dev_attr_event_char); | 1119 | retval = device_create_file(&udev->dev, &dev_attr_event_char); |
1119 | if (priv->chip_type == FT232BM || priv->chip_type == FT2232C) { | 1120 | if ((!retval) && |
1120 | device_create_file(&udev->dev, &dev_attr_latency_timer); | 1121 | (priv->chip_type == FT232BM || priv->chip_type == FT2232C)) { |
1122 | retval = device_create_file(&udev->dev, | ||
1123 | &dev_attr_latency_timer); | ||
1121 | } | 1124 | } |
1122 | } | 1125 | } |
1126 | return retval; | ||
1123 | } | 1127 | } |
1124 | 1128 | ||
1125 | static void remove_sysfs_attrs(struct usb_serial *serial) | 1129 | static void remove_sysfs_attrs(struct usb_serial *serial) |
@@ -1162,7 +1166,8 @@ static int ftdi_sio_attach (struct usb_serial *serial) | |||
1162 | struct usb_serial_port *port = serial->port[0]; | 1166 | struct usb_serial_port *port = serial->port[0]; |
1163 | struct ftdi_private *priv; | 1167 | struct ftdi_private *priv; |
1164 | struct ftdi_sio_quirk *quirk; | 1168 | struct ftdi_sio_quirk *quirk; |
1165 | 1169 | int retval; | |
1170 | |||
1166 | dbg("%s",__FUNCTION__); | 1171 | dbg("%s",__FUNCTION__); |
1167 | 1172 | ||
1168 | priv = kzalloc(sizeof(struct ftdi_private), GFP_KERNEL); | 1173 | priv = kzalloc(sizeof(struct ftdi_private), GFP_KERNEL); |
@@ -1203,15 +1208,18 @@ static int ftdi_sio_attach (struct usb_serial *serial) | |||
1203 | usb_set_serial_port_data(serial->port[0], priv); | 1208 | usb_set_serial_port_data(serial->port[0], priv); |
1204 | 1209 | ||
1205 | ftdi_determine_type (serial->port[0]); | 1210 | ftdi_determine_type (serial->port[0]); |
1206 | create_sysfs_attrs(serial); | 1211 | retval = create_sysfs_attrs(serial); |
1212 | if (retval) | ||
1213 | dev_err(&serial->dev->dev, "Error creating sysfs files, " | ||
1214 | "continuing\n"); | ||
1207 | 1215 | ||
1208 | /* Check for device requiring special set up. */ | 1216 | /* Check for device requiring special set up. */ |
1209 | quirk = (struct ftdi_sio_quirk *)usb_get_serial_data(serial); | 1217 | quirk = (struct ftdi_sio_quirk *)usb_get_serial_data(serial); |
1210 | if (quirk && quirk->setup) { | 1218 | if (quirk && quirk->setup) { |
1211 | quirk->setup(serial); | 1219 | quirk->setup(serial); |
1212 | } | 1220 | } |
1213 | 1221 | ||
1214 | return (0); | 1222 | return 0; |
1215 | } /* ftdi_sio_attach */ | 1223 | } /* ftdi_sio_attach */ |
1216 | 1224 | ||
1217 | 1225 | ||
diff --git a/drivers/usb/serial/garmin_gps.c b/drivers/usb/serial/garmin_gps.c index 727852634be9..4b1196a8b09e 100644 --- a/drivers/usb/serial/garmin_gps.c +++ b/drivers/usb/serial/garmin_gps.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * Garmin GPS driver | 2 | * Garmin GPS driver |
3 | * | 3 | * |
4 | * Copyright (C) 2004 Hermann Kneissel herkne@users.sourceforge.net | 4 | * Copyright (C) 2006 Hermann Kneissel herkne@users.sourceforge.net |
5 | * | 5 | * |
6 | * The latest version of the driver can be found at | 6 | * The latest version of the driver can be found at |
7 | * http://sourceforge.net/projects/garmin-gps/ | 7 | * http://sourceforge.net/projects/garmin-gps/ |
@@ -37,6 +37,8 @@ | |||
37 | #include <linux/usb.h> | 37 | #include <linux/usb.h> |
38 | #include <linux/usb/serial.h> | 38 | #include <linux/usb/serial.h> |
39 | 39 | ||
40 | #include <linux/version.h> | ||
41 | |||
40 | /* the mode to be set when the port ist opened */ | 42 | /* the mode to be set when the port ist opened */ |
41 | static int initial_mode = 1; | 43 | static int initial_mode = 1; |
42 | 44 | ||
@@ -50,7 +52,7 @@ static int debug = 0; | |||
50 | */ | 52 | */ |
51 | 53 | ||
52 | #define VERSION_MAJOR 0 | 54 | #define VERSION_MAJOR 0 |
53 | #define VERSION_MINOR 23 | 55 | #define VERSION_MINOR 28 |
54 | 56 | ||
55 | #define _STR(s) #s | 57 | #define _STR(s) #s |
56 | #define _DRIVER_VERSION(a,b) "v" _STR(a) "." _STR(b) | 58 | #define _DRIVER_VERSION(a,b) "v" _STR(a) "." _STR(b) |
@@ -164,7 +166,8 @@ struct garmin_data { | |||
164 | #define FLAGS_SESSION_REPLY1_SEEN 0x0080 | 166 | #define FLAGS_SESSION_REPLY1_SEEN 0x0080 |
165 | #define FLAGS_SESSION_REPLY2_SEEN 0x0040 | 167 | #define FLAGS_SESSION_REPLY2_SEEN 0x0040 |
166 | #define FLAGS_BULK_IN_ACTIVE 0x0020 | 168 | #define FLAGS_BULK_IN_ACTIVE 0x0020 |
167 | #define FLAGS_THROTTLED 0x0010 | 169 | #define FLAGS_BULK_IN_RESTART 0x0010 |
170 | #define FLAGS_THROTTLED 0x0008 | ||
168 | #define CLEAR_HALT_REQUIRED 0x0001 | 171 | #define CLEAR_HALT_REQUIRED 0x0001 |
169 | 172 | ||
170 | #define FLAGS_QUEUING 0x0100 | 173 | #define FLAGS_QUEUING 0x0100 |
@@ -224,7 +227,7 @@ static struct usb_driver garmin_driver = { | |||
224 | .probe = usb_serial_probe, | 227 | .probe = usb_serial_probe, |
225 | .disconnect = usb_serial_disconnect, | 228 | .disconnect = usb_serial_disconnect, |
226 | .id_table = id_table, | 229 | .id_table = id_table, |
227 | .no_dynamic_id = 1, | 230 | .no_dynamic_id = 1, |
228 | }; | 231 | }; |
229 | 232 | ||
230 | 233 | ||
@@ -270,7 +273,7 @@ static inline int isAbortTrfCmnd(const unsigned char *buf) | |||
270 | 273 | ||
271 | 274 | ||
272 | static void send_to_tty(struct usb_serial_port *port, | 275 | static void send_to_tty(struct usb_serial_port *port, |
273 | char *data, unsigned int actual_length) | 276 | char *data, unsigned int actual_length) |
274 | { | 277 | { |
275 | struct tty_struct *tty = port->tty; | 278 | struct tty_struct *tty = port->tty; |
276 | 279 | ||
@@ -294,15 +297,15 @@ static void send_to_tty(struct usb_serial_port *port, | |||
294 | * queue a received (usb-)packet for later processing | 297 | * queue a received (usb-)packet for later processing |
295 | */ | 298 | */ |
296 | static int pkt_add(struct garmin_data * garmin_data_p, | 299 | static int pkt_add(struct garmin_data * garmin_data_p, |
297 | unsigned char *data, unsigned int data_length) | 300 | unsigned char *data, unsigned int data_length) |
298 | { | 301 | { |
302 | int state = 0; | ||
299 | int result = 0; | 303 | int result = 0; |
300 | unsigned long flags; | 304 | unsigned long flags; |
301 | struct garmin_packet *pkt; | 305 | struct garmin_packet *pkt; |
302 | 306 | ||
303 | /* process only packets containg data ... */ | 307 | /* process only packets containg data ... */ |
304 | if (data_length) { | 308 | if (data_length) { |
305 | garmin_data_p->flags |= FLAGS_QUEUING; | ||
306 | pkt = kmalloc(sizeof(struct garmin_packet)+data_length, | 309 | pkt = kmalloc(sizeof(struct garmin_packet)+data_length, |
307 | GFP_ATOMIC); | 310 | GFP_ATOMIC); |
308 | if (pkt == NULL) { | 311 | if (pkt == NULL) { |
@@ -313,14 +316,16 @@ static int pkt_add(struct garmin_data * garmin_data_p, | |||
313 | memcpy(pkt->data, data, data_length); | 316 | memcpy(pkt->data, data, data_length); |
314 | 317 | ||
315 | spin_lock_irqsave(&garmin_data_p->lock, flags); | 318 | spin_lock_irqsave(&garmin_data_p->lock, flags); |
319 | garmin_data_p->flags |= FLAGS_QUEUING; | ||
316 | result = list_empty(&garmin_data_p->pktlist); | 320 | result = list_empty(&garmin_data_p->pktlist); |
317 | pkt->seq = garmin_data_p->seq_counter++; | 321 | pkt->seq = garmin_data_p->seq_counter++; |
318 | list_add_tail(&pkt->list, &garmin_data_p->pktlist); | 322 | list_add_tail(&pkt->list, &garmin_data_p->pktlist); |
323 | state = garmin_data_p->state; | ||
319 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); | 324 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); |
320 | 325 | ||
321 | /* in serial mode, if someone is waiting for data from | 326 | /* in serial mode, if someone is waiting for data from |
322 | the device, iconvert and send the next packet to tty. */ | 327 | the device, iconvert and send the next packet to tty. */ |
323 | if (result && (garmin_data_p->state == STATE_GSP_WAIT_DATA)) { | 328 | if (result && (state == STATE_GSP_WAIT_DATA)) { |
324 | gsp_next_packet(garmin_data_p); | 329 | gsp_next_packet(garmin_data_p); |
325 | } | 330 | } |
326 | } | 331 | } |
@@ -370,9 +375,9 @@ static void pkt_clear(struct garmin_data * garmin_data_p) | |||
370 | static int gsp_send_ack(struct garmin_data * garmin_data_p, __u8 pkt_id) | 375 | static int gsp_send_ack(struct garmin_data * garmin_data_p, __u8 pkt_id) |
371 | { | 376 | { |
372 | __u8 pkt[10]; | 377 | __u8 pkt[10]; |
373 | __u8 cksum = 0; | 378 | __u8 cksum = 0; |
374 | __u8 *ptr = pkt; | 379 | __u8 *ptr = pkt; |
375 | unsigned l = 0; | 380 | unsigned l = 0; |
376 | 381 | ||
377 | dbg("%s - pkt-id: 0x%X.", __FUNCTION__, 0xFF & pkt_id); | 382 | dbg("%s - pkt-id: 0x%X.", __FUNCTION__, 0xFF & pkt_id); |
378 | 383 | ||
@@ -416,7 +421,7 @@ static int gsp_send_ack(struct garmin_data * garmin_data_p, __u8 pkt_id) | |||
416 | static int gsp_rec_packet(struct garmin_data * garmin_data_p, int count) | 421 | static int gsp_rec_packet(struct garmin_data * garmin_data_p, int count) |
417 | { | 422 | { |
418 | const __u8* recpkt = garmin_data_p->inbuffer+GSP_INITIAL_OFFSET; | 423 | const __u8* recpkt = garmin_data_p->inbuffer+GSP_INITIAL_OFFSET; |
419 | __le32 *usbdata = (__le32 *) garmin_data_p->inbuffer; | 424 | __le32 *usbdata = (__le32 *) garmin_data_p->inbuffer; |
420 | 425 | ||
421 | int cksum = 0; | 426 | int cksum = 0; |
422 | int n = 0; | 427 | int n = 0; |
@@ -447,11 +452,11 @@ static int gsp_rec_packet(struct garmin_data * garmin_data_p, int count) | |||
447 | n++; | 452 | n++; |
448 | } | 453 | } |
449 | 454 | ||
450 | if ((0xff & (cksum + *recpkt)) != 0) { | 455 | if ((0xff & (cksum + *recpkt)) != 0) { |
451 | dbg("%s - invalid checksum, expected %02x, got %02x", | 456 | dbg("%s - invalid checksum, expected %02x, got %02x", |
452 | __FUNCTION__, 0xff & -cksum, 0xff & *recpkt); | 457 | __FUNCTION__, 0xff & -cksum, 0xff & *recpkt); |
453 | return -EINVPKT; | 458 | return -EINVPKT; |
454 | } | 459 | } |
455 | 460 | ||
456 | usbdata[0] = __cpu_to_le32(GARMIN_LAYERID_APPL); | 461 | usbdata[0] = __cpu_to_le32(GARMIN_LAYERID_APPL); |
457 | usbdata[1] = __cpu_to_le32(pktid); | 462 | usbdata[1] = __cpu_to_le32(pktid); |
@@ -491,20 +496,28 @@ static int gsp_rec_packet(struct garmin_data * garmin_data_p, int count) | |||
491 | */ | 496 | */ |
492 | 497 | ||
493 | static int gsp_receive(struct garmin_data * garmin_data_p, | 498 | static int gsp_receive(struct garmin_data * garmin_data_p, |
494 | const unsigned char *buf, int count) | 499 | const unsigned char *buf, int count) |
495 | { | 500 | { |
501 | unsigned long flags; | ||
496 | int offs = 0; | 502 | int offs = 0; |
497 | int ack_or_nak_seen = 0; | 503 | int ack_or_nak_seen = 0; |
498 | int i = 0; | 504 | int i = 0; |
499 | __u8 *dest = garmin_data_p->inbuffer; | 505 | __u8 *dest; |
500 | int size = garmin_data_p->insize; | 506 | int size; |
501 | // dleSeen: set if last byte read was a DLE | 507 | // dleSeen: set if last byte read was a DLE |
502 | int dleSeen = garmin_data_p->flags & FLAGS_GSP_DLESEEN; | 508 | int dleSeen; |
503 | // skip: if set, skip incoming data until possible start of | 509 | // skip: if set, skip incoming data until possible start of |
504 | // new packet | 510 | // new packet |
505 | int skip = garmin_data_p->flags & FLAGS_GSP_SKIP; | 511 | int skip; |
506 | __u8 data; | 512 | __u8 data; |
507 | 513 | ||
514 | spin_lock_irqsave(&garmin_data_p->lock, flags); | ||
515 | dest = garmin_data_p->inbuffer; | ||
516 | size = garmin_data_p->insize; | ||
517 | dleSeen = garmin_data_p->flags & FLAGS_GSP_DLESEEN; | ||
518 | skip = garmin_data_p->flags & FLAGS_GSP_SKIP; | ||
519 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); | ||
520 | |||
508 | dbg("%s - dle=%d skip=%d size=%d count=%d", | 521 | dbg("%s - dle=%d skip=%d size=%d count=%d", |
509 | __FUNCTION__, dleSeen, skip, size, count); | 522 | __FUNCTION__, dleSeen, skip, size, count); |
510 | 523 | ||
@@ -572,6 +585,8 @@ static int gsp_receive(struct garmin_data * garmin_data_p, | |||
572 | } | 585 | } |
573 | } | 586 | } |
574 | 587 | ||
588 | spin_lock_irqsave(&garmin_data_p->lock, flags); | ||
589 | |||
575 | garmin_data_p->insize = size; | 590 | garmin_data_p->insize = size; |
576 | 591 | ||
577 | // copy flags back to structure | 592 | // copy flags back to structure |
@@ -587,6 +602,11 @@ static int gsp_receive(struct garmin_data * garmin_data_p, | |||
587 | 602 | ||
588 | if (ack_or_nak_seen) { | 603 | if (ack_or_nak_seen) { |
589 | garmin_data_p->state = STATE_GSP_WAIT_DATA; | 604 | garmin_data_p->state = STATE_GSP_WAIT_DATA; |
605 | } | ||
606 | |||
607 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); | ||
608 | |||
609 | if (ack_or_nak_seen) { | ||
590 | gsp_next_packet(garmin_data_p); | 610 | gsp_next_packet(garmin_data_p); |
591 | } | 611 | } |
592 | 612 | ||
@@ -676,7 +696,7 @@ static int gsp_send(struct garmin_data * garmin_data_p, | |||
676 | src = garmin_data_p->outbuffer+GARMIN_PKTHDR_LENGTH; | 696 | src = garmin_data_p->outbuffer+GARMIN_PKTHDR_LENGTH; |
677 | if (k > (GARMIN_PKTHDR_LENGTH-2)) { | 697 | if (k > (GARMIN_PKTHDR_LENGTH-2)) { |
678 | /* can't add stuffing DLEs in place, move data to end | 698 | /* can't add stuffing DLEs in place, move data to end |
679 | of buffer ... */ | 699 | of buffer ... */ |
680 | dst = garmin_data_p->outbuffer+GPS_OUT_BUFSIZ-datalen; | 700 | dst = garmin_data_p->outbuffer+GPS_OUT_BUFSIZ-datalen; |
681 | memcpy(dst, src, datalen); | 701 | memcpy(dst, src, datalen); |
682 | src = dst; | 702 | src = dst; |
@@ -755,8 +775,9 @@ static void gsp_next_packet(struct garmin_data * garmin_data_p) | |||
755 | * or even incomplete packets | 775 | * or even incomplete packets |
756 | */ | 776 | */ |
757 | static int nat_receive(struct garmin_data * garmin_data_p, | 777 | static int nat_receive(struct garmin_data * garmin_data_p, |
758 | const unsigned char *buf, int count) | 778 | const unsigned char *buf, int count) |
759 | { | 779 | { |
780 | unsigned long flags; | ||
760 | __u8 * dest; | 781 | __u8 * dest; |
761 | int offs = 0; | 782 | int offs = 0; |
762 | int result = count; | 783 | int result = count; |
@@ -803,7 +824,9 @@ static int nat_receive(struct garmin_data * garmin_data_p, | |||
803 | /* if this was an abort-transfer command, | 824 | /* if this was an abort-transfer command, |
804 | flush all queued data. */ | 825 | flush all queued data. */ |
805 | if (isAbortTrfCmnd(garmin_data_p->inbuffer)) { | 826 | if (isAbortTrfCmnd(garmin_data_p->inbuffer)) { |
827 | spin_lock_irqsave(&garmin_data_p->lock, flags); | ||
806 | garmin_data_p->flags |= FLAGS_DROP_DATA; | 828 | garmin_data_p->flags |= FLAGS_DROP_DATA; |
829 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); | ||
807 | pkt_clear(garmin_data_p); | 830 | pkt_clear(garmin_data_p); |
808 | } | 831 | } |
809 | } | 832 | } |
@@ -839,12 +862,15 @@ static void priv_status_resp(struct usb_serial_port *port) | |||
839 | 862 | ||
840 | static int process_resetdev_request(struct usb_serial_port *port) | 863 | static int process_resetdev_request(struct usb_serial_port *port) |
841 | { | 864 | { |
865 | unsigned long flags; | ||
842 | int status; | 866 | int status; |
843 | struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); | 867 | struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); |
844 | 868 | ||
869 | spin_lock_irqsave(&garmin_data_p->lock, flags); | ||
845 | garmin_data_p->flags &= ~(CLEAR_HALT_REQUIRED); | 870 | garmin_data_p->flags &= ~(CLEAR_HALT_REQUIRED); |
846 | garmin_data_p->state = STATE_RESET; | 871 | garmin_data_p->state = STATE_RESET; |
847 | garmin_data_p->serial_num = 0; | 872 | garmin_data_p->serial_num = 0; |
873 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); | ||
848 | 874 | ||
849 | usb_kill_urb (port->interrupt_in_urb); | 875 | usb_kill_urb (port->interrupt_in_urb); |
850 | dbg("%s - usb_reset_device", __FUNCTION__ ); | 876 | dbg("%s - usb_reset_device", __FUNCTION__ ); |
@@ -862,6 +888,7 @@ static int process_resetdev_request(struct usb_serial_port *port) | |||
862 | */ | 888 | */ |
863 | static int garmin_clear(struct garmin_data * garmin_data_p) | 889 | static int garmin_clear(struct garmin_data * garmin_data_p) |
864 | { | 890 | { |
891 | unsigned long flags; | ||
865 | int status = 0; | 892 | int status = 0; |
866 | 893 | ||
867 | struct usb_serial_port *port = garmin_data_p->port; | 894 | struct usb_serial_port *port = garmin_data_p->port; |
@@ -875,8 +902,10 @@ static int garmin_clear(struct garmin_data * garmin_data_p) | |||
875 | /* flush all queued data */ | 902 | /* flush all queued data */ |
876 | pkt_clear(garmin_data_p); | 903 | pkt_clear(garmin_data_p); |
877 | 904 | ||
905 | spin_lock_irqsave(&garmin_data_p->lock, flags); | ||
878 | garmin_data_p->insize = 0; | 906 | garmin_data_p->insize = 0; |
879 | garmin_data_p->outsize = 0; | 907 | garmin_data_p->outsize = 0; |
908 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); | ||
880 | 909 | ||
881 | return status; | 910 | return status; |
882 | } | 911 | } |
@@ -888,6 +917,7 @@ static int garmin_clear(struct garmin_data * garmin_data_p) | |||
888 | 917 | ||
889 | static int garmin_init_session(struct usb_serial_port *port) | 918 | static int garmin_init_session(struct usb_serial_port *port) |
890 | { | 919 | { |
920 | unsigned long flags; | ||
891 | struct usb_serial *serial = port->serial; | 921 | struct usb_serial *serial = port->serial; |
892 | struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); | 922 | struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); |
893 | int status = 0; | 923 | int status = 0; |
@@ -913,7 +943,9 @@ static int garmin_init_session(struct usb_serial_port *port) | |||
913 | 943 | ||
914 | if (status >= 0) { | 944 | if (status >= 0) { |
915 | 945 | ||
946 | spin_lock_irqsave(&garmin_data_p->lock, flags); | ||
916 | garmin_data_p->ignorePkts++; | 947 | garmin_data_p->ignorePkts++; |
948 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); | ||
917 | 949 | ||
918 | /* not needed, but the win32 driver does it too ... */ | 950 | /* not needed, but the win32 driver does it too ... */ |
919 | status = garmin_write_bulk(port, | 951 | status = garmin_write_bulk(port, |
@@ -921,7 +953,9 @@ static int garmin_init_session(struct usb_serial_port *port) | |||
921 | sizeof(GARMIN_START_SESSION_REQ2)); | 953 | sizeof(GARMIN_START_SESSION_REQ2)); |
922 | if (status >= 0) { | 954 | if (status >= 0) { |
923 | status = 0; | 955 | status = 0; |
956 | spin_lock_irqsave(&garmin_data_p->lock, flags); | ||
924 | garmin_data_p->ignorePkts++; | 957 | garmin_data_p->ignorePkts++; |
958 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); | ||
925 | } | 959 | } |
926 | } | 960 | } |
927 | } | 961 | } |
@@ -935,6 +969,7 @@ static int garmin_init_session(struct usb_serial_port *port) | |||
935 | 969 | ||
936 | static int garmin_open (struct usb_serial_port *port, struct file *filp) | 970 | static int garmin_open (struct usb_serial_port *port, struct file *filp) |
937 | { | 971 | { |
972 | unsigned long flags; | ||
938 | int status = 0; | 973 | int status = 0; |
939 | struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); | 974 | struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); |
940 | 975 | ||
@@ -948,9 +983,11 @@ static int garmin_open (struct usb_serial_port *port, struct file *filp) | |||
948 | if (port->tty) | 983 | if (port->tty) |
949 | port->tty->low_latency = 1; | 984 | port->tty->low_latency = 1; |
950 | 985 | ||
986 | spin_lock_irqsave(&garmin_data_p->lock, flags); | ||
951 | garmin_data_p->mode = initial_mode; | 987 | garmin_data_p->mode = initial_mode; |
952 | garmin_data_p->count = 0; | 988 | garmin_data_p->count = 0; |
953 | garmin_data_p->flags = 0; | 989 | garmin_data_p->flags = 0; |
990 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); | ||
954 | 991 | ||
955 | /* shutdown any bulk reads that might be going on */ | 992 | /* shutdown any bulk reads that might be going on */ |
956 | usb_kill_urb (port->write_urb); | 993 | usb_kill_urb (port->write_urb); |
@@ -996,6 +1033,7 @@ static void garmin_close (struct usb_serial_port *port, struct file * filp) | |||
996 | 1033 | ||
997 | static void garmin_write_bulk_callback (struct urb *urb, struct pt_regs *regs) | 1034 | static void garmin_write_bulk_callback (struct urb *urb, struct pt_regs *regs) |
998 | { | 1035 | { |
1036 | unsigned long flags; | ||
999 | struct usb_serial_port *port = (struct usb_serial_port *)urb->context; | 1037 | struct usb_serial_port *port = (struct usb_serial_port *)urb->context; |
1000 | struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); | 1038 | struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); |
1001 | 1039 | ||
@@ -1007,7 +1045,9 @@ static void garmin_write_bulk_callback (struct urb *urb, struct pt_regs *regs) | |||
1007 | if (urb->status) { | 1045 | if (urb->status) { |
1008 | dbg("%s - nonzero write bulk status received: %d", | 1046 | dbg("%s - nonzero write bulk status received: %d", |
1009 | __FUNCTION__, urb->status); | 1047 | __FUNCTION__, urb->status); |
1048 | spin_lock_irqsave(&garmin_data_p->lock, flags); | ||
1010 | garmin_data_p->flags |= CLEAR_HALT_REQUIRED; | 1049 | garmin_data_p->flags |= CLEAR_HALT_REQUIRED; |
1050 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); | ||
1011 | } | 1051 | } |
1012 | 1052 | ||
1013 | usb_serial_port_softint(port); | 1053 | usb_serial_port_softint(port); |
@@ -1015,8 +1055,9 @@ static void garmin_write_bulk_callback (struct urb *urb, struct pt_regs *regs) | |||
1015 | 1055 | ||
1016 | 1056 | ||
1017 | static int garmin_write_bulk (struct usb_serial_port *port, | 1057 | static int garmin_write_bulk (struct usb_serial_port *port, |
1018 | const unsigned char *buf, int count) | 1058 | const unsigned char *buf, int count) |
1019 | { | 1059 | { |
1060 | unsigned long flags; | ||
1020 | struct usb_serial *serial = port->serial; | 1061 | struct usb_serial *serial = port->serial; |
1021 | struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); | 1062 | struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); |
1022 | struct urb *urb; | 1063 | struct urb *urb; |
@@ -1026,7 +1067,9 @@ static int garmin_write_bulk (struct usb_serial_port *port, | |||
1026 | dbg("%s - port %d, state %d", __FUNCTION__, port->number, | 1067 | dbg("%s - port %d, state %d", __FUNCTION__, port->number, |
1027 | garmin_data_p->state); | 1068 | garmin_data_p->state); |
1028 | 1069 | ||
1070 | spin_lock_irqsave(&garmin_data_p->lock, flags); | ||
1029 | garmin_data_p->flags &= ~FLAGS_DROP_DATA; | 1071 | garmin_data_p->flags &= ~FLAGS_DROP_DATA; |
1072 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); | ||
1030 | 1073 | ||
1031 | buffer = kmalloc (count, GFP_ATOMIC); | 1074 | buffer = kmalloc (count, GFP_ATOMIC); |
1032 | if (!buffer) { | 1075 | if (!buffer) { |
@@ -1053,7 +1096,9 @@ static int garmin_write_bulk (struct usb_serial_port *port, | |||
1053 | urb->transfer_flags |= URB_ZERO_PACKET; | 1096 | urb->transfer_flags |= URB_ZERO_PACKET; |
1054 | 1097 | ||
1055 | if (GARMIN_LAYERID_APPL == getLayerId(buffer)) { | 1098 | if (GARMIN_LAYERID_APPL == getLayerId(buffer)) { |
1099 | spin_lock_irqsave(&garmin_data_p->lock, flags); | ||
1056 | garmin_data_p->flags |= FLAGS_APP_REQ_SEEN; | 1100 | garmin_data_p->flags |= FLAGS_APP_REQ_SEEN; |
1101 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); | ||
1057 | if (garmin_data_p->mode == MODE_GARMIN_SERIAL) { | 1102 | if (garmin_data_p->mode == MODE_GARMIN_SERIAL) { |
1058 | pkt_clear(garmin_data_p); | 1103 | pkt_clear(garmin_data_p); |
1059 | garmin_data_p->state = STATE_GSP_WAIT_DATA; | 1104 | garmin_data_p->state = STATE_GSP_WAIT_DATA; |
@@ -1087,8 +1132,9 @@ static int garmin_write_bulk (struct usb_serial_port *port, | |||
1087 | 1132 | ||
1088 | 1133 | ||
1089 | static int garmin_write (struct usb_serial_port *port, | 1134 | static int garmin_write (struct usb_serial_port *port, |
1090 | const unsigned char *buf, int count) | 1135 | const unsigned char *buf, int count) |
1091 | { | 1136 | { |
1137 | unsigned long flags; | ||
1092 | int pktid, pktsiz, len; | 1138 | int pktid, pktsiz, len; |
1093 | struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); | 1139 | struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); |
1094 | __le32 *privpkt = (__le32 *)garmin_data_p->privpkt; | 1140 | __le32 *privpkt = (__le32 *)garmin_data_p->privpkt; |
@@ -1139,7 +1185,9 @@ static int garmin_write (struct usb_serial_port *port, | |||
1139 | break; | 1185 | break; |
1140 | 1186 | ||
1141 | case PRIV_PKTID_RESET_REQ: | 1187 | case PRIV_PKTID_RESET_REQ: |
1188 | spin_lock_irqsave(&garmin_data_p->lock, flags); | ||
1142 | garmin_data_p->flags |= FLAGS_APP_REQ_SEEN; | 1189 | garmin_data_p->flags |= FLAGS_APP_REQ_SEEN; |
1190 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); | ||
1143 | break; | 1191 | break; |
1144 | 1192 | ||
1145 | case PRIV_PKTID_SET_DEF_MODE: | 1193 | case PRIV_PKTID_SET_DEF_MODE: |
@@ -1155,6 +1203,8 @@ static int garmin_write (struct usb_serial_port *port, | |||
1155 | } | 1203 | } |
1156 | } | 1204 | } |
1157 | 1205 | ||
1206 | garmin_data_p->ignorePkts = 0; | ||
1207 | |||
1158 | if (garmin_data_p->mode == MODE_GARMIN_SERIAL) { | 1208 | if (garmin_data_p->mode == MODE_GARMIN_SERIAL) { |
1159 | return gsp_receive(garmin_data_p, buf, count); | 1209 | return gsp_receive(garmin_data_p, buf, count); |
1160 | } else { /* MODE_NATIVE */ | 1210 | } else { /* MODE_NATIVE */ |
@@ -1177,10 +1227,10 @@ static int garmin_chars_in_buffer (struct usb_serial_port *port) | |||
1177 | { | 1227 | { |
1178 | /* | 1228 | /* |
1179 | * Report back the number of bytes currently in our input buffer. | 1229 | * Report back the number of bytes currently in our input buffer. |
1180 | * Will this lock up the driver - the buffer contains an incomplete | 1230 | * Will this lock up the driver - the buffer contains an incomplete |
1181 | * package which will not be written to the device until it | 1231 | * package which will not be written to the device until it |
1182 | * has been completed ? | 1232 | * has been completed ? |
1183 | */ | 1233 | */ |
1184 | //struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); | 1234 | //struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); |
1185 | //return garmin_data_p->insize; | 1235 | //return garmin_data_p->insize; |
1186 | return 0; | 1236 | return 0; |
@@ -1190,6 +1240,8 @@ static int garmin_chars_in_buffer (struct usb_serial_port *port) | |||
1190 | static void garmin_read_process(struct garmin_data * garmin_data_p, | 1240 | static void garmin_read_process(struct garmin_data * garmin_data_p, |
1191 | unsigned char *data, unsigned data_length) | 1241 | unsigned char *data, unsigned data_length) |
1192 | { | 1242 | { |
1243 | unsigned long flags; | ||
1244 | |||
1193 | if (garmin_data_p->flags & FLAGS_DROP_DATA) { | 1245 | if (garmin_data_p->flags & FLAGS_DROP_DATA) { |
1194 | /* abort-transfer cmd is actice */ | 1246 | /* abort-transfer cmd is actice */ |
1195 | dbg("%s - pkt dropped", __FUNCTION__); | 1247 | dbg("%s - pkt dropped", __FUNCTION__); |
@@ -1200,11 +1252,14 @@ static void garmin_read_process(struct garmin_data * garmin_data_p, | |||
1200 | if a reset is required or not when closing | 1252 | if a reset is required or not when closing |
1201 | the device */ | 1253 | the device */ |
1202 | if (0 == memcmp(data, GARMIN_APP_LAYER_REPLY, | 1254 | if (0 == memcmp(data, GARMIN_APP_LAYER_REPLY, |
1203 | sizeof(GARMIN_APP_LAYER_REPLY))) | 1255 | sizeof(GARMIN_APP_LAYER_REPLY))) { |
1256 | spin_lock_irqsave(&garmin_data_p->lock, flags); | ||
1204 | garmin_data_p->flags |= FLAGS_APP_RESP_SEEN; | 1257 | garmin_data_p->flags |= FLAGS_APP_RESP_SEEN; |
1258 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); | ||
1259 | } | ||
1205 | 1260 | ||
1206 | /* if throttling is active or postprecessing is required | 1261 | /* if throttling is active or postprecessing is required |
1207 | put the received data in th input queue, otherwise | 1262 | put the received data in the input queue, otherwise |
1208 | send it directly to the tty port */ | 1263 | send it directly to the tty port */ |
1209 | if (garmin_data_p->flags & FLAGS_QUEUING) { | 1264 | if (garmin_data_p->flags & FLAGS_QUEUING) { |
1210 | pkt_add(garmin_data_p, data, data_length); | 1265 | pkt_add(garmin_data_p, data, data_length); |
@@ -1221,6 +1276,7 @@ static void garmin_read_process(struct garmin_data * garmin_data_p, | |||
1221 | 1276 | ||
1222 | static void garmin_read_bulk_callback (struct urb *urb, struct pt_regs *regs) | 1277 | static void garmin_read_bulk_callback (struct urb *urb, struct pt_regs *regs) |
1223 | { | 1278 | { |
1279 | unsigned long flags; | ||
1224 | struct usb_serial_port *port = (struct usb_serial_port *)urb->context; | 1280 | struct usb_serial_port *port = (struct usb_serial_port *)urb->context; |
1225 | struct usb_serial *serial = port->serial; | 1281 | struct usb_serial *serial = port->serial; |
1226 | struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); | 1282 | struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); |
@@ -1245,19 +1301,30 @@ static void garmin_read_bulk_callback (struct urb *urb, struct pt_regs *regs) | |||
1245 | 1301 | ||
1246 | garmin_read_process(garmin_data_p, data, urb->actual_length); | 1302 | garmin_read_process(garmin_data_p, data, urb->actual_length); |
1247 | 1303 | ||
1248 | /* Continue trying to read until nothing more is received */ | 1304 | if (urb->actual_length == 0 && |
1249 | if (urb->actual_length > 0) { | 1305 | 0 != (garmin_data_p->flags & FLAGS_BULK_IN_RESTART)) { |
1250 | usb_fill_bulk_urb (port->read_urb, serial->dev, | 1306 | spin_lock_irqsave(&garmin_data_p->lock, flags); |
1251 | usb_rcvbulkpipe (serial->dev, | 1307 | garmin_data_p->flags &= ~FLAGS_BULK_IN_RESTART; |
1252 | port->bulk_in_endpointAddress), | 1308 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); |
1253 | port->read_urb->transfer_buffer, | ||
1254 | port->read_urb->transfer_buffer_length, | ||
1255 | garmin_read_bulk_callback, port); | ||
1256 | status = usb_submit_urb(port->read_urb, GFP_ATOMIC); | 1309 | status = usb_submit_urb(port->read_urb, GFP_ATOMIC); |
1257 | if (status) | 1310 | if (status) |
1258 | dev_err(&port->dev, | 1311 | dev_err(&port->dev, |
1259 | "%s - failed resubmitting read urb, error %d\n", | 1312 | "%s - failed resubmitting read urb, error %d\n", |
1260 | __FUNCTION__, status); | 1313 | __FUNCTION__, status); |
1314 | } else if (urb->actual_length > 0) { | ||
1315 | /* Continue trying to read until nothing more is received */ | ||
1316 | if (0 == (garmin_data_p->flags & FLAGS_THROTTLED)) { | ||
1317 | status = usb_submit_urb(port->read_urb, GFP_ATOMIC); | ||
1318 | if (status) | ||
1319 | dev_err(&port->dev, | ||
1320 | "%s - failed resubmitting read urb, error %d\n", | ||
1321 | __FUNCTION__, status); | ||
1322 | } | ||
1323 | } else { | ||
1324 | dbg("%s - end of bulk data", __FUNCTION__); | ||
1325 | spin_lock_irqsave(&garmin_data_p->lock, flags); | ||
1326 | garmin_data_p->flags &= ~FLAGS_BULK_IN_ACTIVE; | ||
1327 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); | ||
1261 | } | 1328 | } |
1262 | return; | 1329 | return; |
1263 | } | 1330 | } |
@@ -1265,6 +1332,7 @@ static void garmin_read_bulk_callback (struct urb *urb, struct pt_regs *regs) | |||
1265 | 1332 | ||
1266 | static void garmin_read_int_callback (struct urb *urb, struct pt_regs *regs) | 1333 | static void garmin_read_int_callback (struct urb *urb, struct pt_regs *regs) |
1267 | { | 1334 | { |
1335 | unsigned long flags; | ||
1268 | int status; | 1336 | int status; |
1269 | struct usb_serial_port *port = (struct usb_serial_port *)urb->context; | 1337 | struct usb_serial_port *port = (struct usb_serial_port *)urb->context; |
1270 | struct usb_serial *serial = port->serial; | 1338 | struct usb_serial *serial = port->serial; |
@@ -1297,25 +1365,41 @@ static void garmin_read_int_callback (struct urb *urb, struct pt_regs *regs) | |||
1297 | 1365 | ||
1298 | dbg("%s - bulk data available.", __FUNCTION__); | 1366 | dbg("%s - bulk data available.", __FUNCTION__); |
1299 | 1367 | ||
1300 | /* bulk data available */ | 1368 | if (0 == (garmin_data_p->flags & FLAGS_BULK_IN_ACTIVE)) { |
1301 | usb_fill_bulk_urb (port->read_urb, serial->dev, | 1369 | |
1302 | usb_rcvbulkpipe (serial->dev, | 1370 | /* bulk data available */ |
1303 | port->bulk_in_endpointAddress), | 1371 | usb_fill_bulk_urb (port->read_urb, serial->dev, |
1304 | port->read_urb->transfer_buffer, | 1372 | usb_rcvbulkpipe (serial->dev, |
1305 | port->read_urb->transfer_buffer_length, | 1373 | port->bulk_in_endpointAddress), |
1306 | garmin_read_bulk_callback, port); | 1374 | port->read_urb->transfer_buffer, |
1307 | status = usb_submit_urb(port->read_urb, GFP_KERNEL); | 1375 | port->read_urb->transfer_buffer_length, |
1308 | if (status) { | 1376 | garmin_read_bulk_callback, port); |
1309 | dev_err(&port->dev, | 1377 | status = usb_submit_urb(port->read_urb, GFP_ATOMIC); |
1310 | "%s - failed submitting read urb, error %d\n", | 1378 | if (status) { |
1311 | __FUNCTION__, status); | 1379 | dev_err(&port->dev, |
1380 | "%s - failed submitting read urb, error %d\n", | ||
1381 | __FUNCTION__, status); | ||
1382 | } else { | ||
1383 | spin_lock_irqsave(&garmin_data_p->lock, flags); | ||
1384 | garmin_data_p->flags |= FLAGS_BULK_IN_ACTIVE; | ||
1385 | /* do not send this packet to the user */ | ||
1386 | garmin_data_p->ignorePkts = 1; | ||
1387 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); | ||
1388 | } | ||
1389 | } else { | ||
1390 | /* bulk-in transfer still active */ | ||
1391 | spin_lock_irqsave(&garmin_data_p->lock, flags); | ||
1392 | garmin_data_p->flags |= FLAGS_BULK_IN_RESTART; | ||
1393 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); | ||
1312 | } | 1394 | } |
1313 | 1395 | ||
1314 | } else if (urb->actual_length == (4+sizeof(GARMIN_START_SESSION_REPLY)) | 1396 | } else if (urb->actual_length == (4+sizeof(GARMIN_START_SESSION_REPLY)) |
1315 | && 0 == memcmp(data, GARMIN_START_SESSION_REPLY, | 1397 | && 0 == memcmp(data, GARMIN_START_SESSION_REPLY, |
1316 | sizeof(GARMIN_START_SESSION_REPLY))) { | 1398 | sizeof(GARMIN_START_SESSION_REPLY))) { |
1317 | 1399 | ||
1400 | spin_lock_irqsave(&garmin_data_p->lock, flags); | ||
1318 | garmin_data_p->flags |= FLAGS_SESSION_REPLY1_SEEN; | 1401 | garmin_data_p->flags |= FLAGS_SESSION_REPLY1_SEEN; |
1402 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); | ||
1319 | 1403 | ||
1320 | /* save the serial number */ | 1404 | /* save the serial number */ |
1321 | garmin_data_p->serial_num | 1405 | garmin_data_p->serial_num |
@@ -1330,7 +1414,9 @@ static void garmin_read_int_callback (struct urb *urb, struct pt_regs *regs) | |||
1330 | ignore it. */ | 1414 | ignore it. */ |
1331 | dbg("%s - pkt ignored (%d)", | 1415 | dbg("%s - pkt ignored (%d)", |
1332 | __FUNCTION__, garmin_data_p->ignorePkts); | 1416 | __FUNCTION__, garmin_data_p->ignorePkts); |
1417 | spin_lock_irqsave(&garmin_data_p->lock, flags); | ||
1333 | garmin_data_p->ignorePkts--; | 1418 | garmin_data_p->ignorePkts--; |
1419 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); | ||
1334 | } else { | 1420 | } else { |
1335 | garmin_read_process(garmin_data_p, data, urb->actual_length); | 1421 | garmin_read_process(garmin_data_p, data, urb->actual_length); |
1336 | } | 1422 | } |
@@ -1351,18 +1437,20 @@ static void garmin_read_int_callback (struct urb *urb, struct pt_regs *regs) | |||
1351 | */ | 1437 | */ |
1352 | static int garmin_flush_queue(struct garmin_data * garmin_data_p) | 1438 | static int garmin_flush_queue(struct garmin_data * garmin_data_p) |
1353 | { | 1439 | { |
1440 | unsigned long flags; | ||
1354 | struct garmin_packet *pkt; | 1441 | struct garmin_packet *pkt; |
1355 | 1442 | ||
1356 | if ((garmin_data_p->flags & FLAGS_THROTTLED) == 0) { | 1443 | if ((garmin_data_p->flags & FLAGS_THROTTLED) == 0) { |
1357 | pkt = pkt_pop(garmin_data_p); | 1444 | pkt = pkt_pop(garmin_data_p); |
1358 | if (pkt != NULL) { | 1445 | if (pkt != NULL) { |
1359 | |||
1360 | send_to_tty(garmin_data_p->port, pkt->data, pkt->size); | 1446 | send_to_tty(garmin_data_p->port, pkt->data, pkt->size); |
1361 | kfree(pkt); | 1447 | kfree(pkt); |
1362 | mod_timer(&garmin_data_p->timer, (1)+jiffies); | 1448 | mod_timer(&garmin_data_p->timer, (1)+jiffies); |
1363 | 1449 | ||
1364 | } else { | 1450 | } else { |
1451 | spin_lock_irqsave(&garmin_data_p->lock, flags); | ||
1365 | garmin_data_p->flags &= ~FLAGS_QUEUING; | 1452 | garmin_data_p->flags &= ~FLAGS_QUEUING; |
1453 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); | ||
1366 | } | 1454 | } |
1367 | } | 1455 | } |
1368 | return 0; | 1456 | return 0; |
@@ -1371,26 +1459,41 @@ static int garmin_flush_queue(struct garmin_data * garmin_data_p) | |||
1371 | 1459 | ||
1372 | static void garmin_throttle (struct usb_serial_port *port) | 1460 | static void garmin_throttle (struct usb_serial_port *port) |
1373 | { | 1461 | { |
1462 | unsigned long flags; | ||
1374 | struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); | 1463 | struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); |
1375 | 1464 | ||
1376 | dbg("%s - port %d", __FUNCTION__, port->number); | 1465 | dbg("%s - port %d", __FUNCTION__, port->number); |
1377 | /* set flag, data received will be put into a queue | 1466 | /* set flag, data received will be put into a queue |
1378 | for later processing */ | 1467 | for later processing */ |
1468 | spin_lock_irqsave(&garmin_data_p->lock, flags); | ||
1379 | garmin_data_p->flags |= FLAGS_QUEUING|FLAGS_THROTTLED; | 1469 | garmin_data_p->flags |= FLAGS_QUEUING|FLAGS_THROTTLED; |
1470 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); | ||
1380 | } | 1471 | } |
1381 | 1472 | ||
1382 | 1473 | ||
1383 | static void garmin_unthrottle (struct usb_serial_port *port) | 1474 | static void garmin_unthrottle (struct usb_serial_port *port) |
1384 | { | 1475 | { |
1476 | unsigned long flags; | ||
1385 | struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); | 1477 | struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); |
1478 | int status; | ||
1386 | 1479 | ||
1387 | dbg("%s - port %d", __FUNCTION__, port->number); | 1480 | dbg("%s - port %d", __FUNCTION__, port->number); |
1481 | spin_lock_irqsave(&garmin_data_p->lock, flags); | ||
1388 | garmin_data_p->flags &= ~FLAGS_THROTTLED; | 1482 | garmin_data_p->flags &= ~FLAGS_THROTTLED; |
1483 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); | ||
1389 | 1484 | ||
1390 | /* in native mode send queued data to tty, in | 1485 | /* in native mode send queued data to tty, in |
1391 | serial mode nothing needs to be done here */ | 1486 | serial mode nothing needs to be done here */ |
1392 | if (garmin_data_p->mode == MODE_NATIVE) | 1487 | if (garmin_data_p->mode == MODE_NATIVE) |
1393 | garmin_flush_queue(garmin_data_p); | 1488 | garmin_flush_queue(garmin_data_p); |
1489 | |||
1490 | if (0 != (garmin_data_p->flags & FLAGS_BULK_IN_ACTIVE)) { | ||
1491 | status = usb_submit_urb(port->read_urb, GFP_ATOMIC); | ||
1492 | if (status) | ||
1493 | dev_err(&port->dev, | ||
1494 | "%s - failed resubmitting read urb, error %d\n", | ||
1495 | __FUNCTION__, status); | ||
1496 | } | ||
1394 | } | 1497 | } |
1395 | 1498 | ||
1396 | 1499 | ||
@@ -1420,11 +1523,12 @@ static int garmin_attach (struct usb_serial *serial) | |||
1420 | 1523 | ||
1421 | dbg("%s", __FUNCTION__); | 1524 | dbg("%s", __FUNCTION__); |
1422 | 1525 | ||
1423 | garmin_data_p = kzalloc(sizeof(struct garmin_data), GFP_KERNEL); | 1526 | garmin_data_p = kmalloc (sizeof(struct garmin_data), GFP_KERNEL); |
1424 | if (garmin_data_p == NULL) { | 1527 | if (garmin_data_p == NULL) { |
1425 | dev_err(&port->dev, "%s - Out of memory\n", __FUNCTION__); | 1528 | dev_err(&port->dev, "%s - Out of memory\n", __FUNCTION__); |
1426 | return -ENOMEM; | 1529 | return -ENOMEM; |
1427 | } | 1530 | } |
1531 | memset (garmin_data_p, 0, sizeof(struct garmin_data)); | ||
1428 | init_timer(&garmin_data_p->timer); | 1532 | init_timer(&garmin_data_p->timer); |
1429 | spin_lock_init(&garmin_data_p->lock); | 1533 | spin_lock_init(&garmin_data_p->lock); |
1430 | INIT_LIST_HEAD(&garmin_data_p->pktlist); | 1534 | INIT_LIST_HEAD(&garmin_data_p->pktlist); |
@@ -1459,10 +1563,10 @@ static void garmin_shutdown (struct usb_serial *serial) | |||
1459 | /* All of the device info needed */ | 1563 | /* All of the device info needed */ |
1460 | static struct usb_serial_driver garmin_device = { | 1564 | static struct usb_serial_driver garmin_device = { |
1461 | .driver = { | 1565 | .driver = { |
1462 | .owner = THIS_MODULE, | 1566 | .owner = THIS_MODULE, |
1463 | .name = "garmin_gps", | 1567 | .name = "garmin_gps", |
1464 | }, | 1568 | }, |
1465 | .description = "Garmin GPS usb/tty", | 1569 | .description = "Garmin GPS usb/tty", |
1466 | .id_table = id_table, | 1570 | .id_table = id_table, |
1467 | .num_interrupt_in = 1, | 1571 | .num_interrupt_in = 1, |
1468 | .num_bulk_in = 1, | 1572 | .num_bulk_in = 1, |
@@ -1483,6 +1587,7 @@ static struct usb_serial_driver garmin_device = { | |||
1483 | }; | 1587 | }; |
1484 | 1588 | ||
1485 | 1589 | ||
1590 | |||
1486 | static int __init garmin_init (void) | 1591 | static int __init garmin_init (void) |
1487 | { | 1592 | { |
1488 | int retval; | 1593 | int retval; |
diff --git a/drivers/usb/serial/ipaq.c b/drivers/usb/serial/ipaq.c index 9840bade79f9..bfc6998cd16f 100644 --- a/drivers/usb/serial/ipaq.c +++ b/drivers/usb/serial/ipaq.c | |||
@@ -652,11 +652,6 @@ static int ipaq_open(struct usb_serial_port *port, struct file *filp) | |||
652 | port->bulk_out_size = port->write_urb->transfer_buffer_length = URBDATA_SIZE; | 652 | port->bulk_out_size = port->write_urb->transfer_buffer_length = URBDATA_SIZE; |
653 | 653 | ||
654 | msleep(1000*initial_wait); | 654 | msleep(1000*initial_wait); |
655 | /* Start reading from the device */ | ||
656 | usb_fill_bulk_urb(port->read_urb, serial->dev, | ||
657 | usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), | ||
658 | port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, | ||
659 | ipaq_read_bulk_callback, port); | ||
660 | 655 | ||
661 | /* | 656 | /* |
662 | * Send out control message observed in win98 sniffs. Not sure what | 657 | * Send out control message observed in win98 sniffs. Not sure what |
@@ -670,18 +665,31 @@ static int ipaq_open(struct usb_serial_port *port, struct file *filp) | |||
670 | result = usb_control_msg(serial->dev, | 665 | result = usb_control_msg(serial->dev, |
671 | usb_sndctrlpipe(serial->dev, 0), 0x22, 0x21, | 666 | usb_sndctrlpipe(serial->dev, 0), 0x22, 0x21, |
672 | 0x1, 0, NULL, 0, 100); | 667 | 0x1, 0, NULL, 0, 100); |
673 | if (result == 0) { | 668 | if (!result) |
674 | result = usb_submit_urb(port->read_urb, GFP_KERNEL); | 669 | break; |
675 | if (result) { | 670 | |
676 | err("%s - failed submitting read urb, error %d", __FUNCTION__, result); | ||
677 | goto error; | ||
678 | } | ||
679 | return 0; | ||
680 | } | ||
681 | msleep(1000); | 671 | msleep(1000); |
682 | } | 672 | } |
683 | err("%s - failed doing control urb, error %d", __FUNCTION__, result); | 673 | |
684 | goto error; | 674 | if (!retries && result) { |
675 | err("%s - failed doing control urb, error %d", __FUNCTION__, | ||
676 | result); | ||
677 | goto error; | ||
678 | } | ||
679 | |||
680 | /* Start reading from the device */ | ||
681 | usb_fill_bulk_urb(port->read_urb, serial->dev, | ||
682 | usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), | ||
683 | port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, | ||
684 | ipaq_read_bulk_callback, port); | ||
685 | |||
686 | result = usb_submit_urb(port->read_urb, GFP_KERNEL); | ||
687 | if (result) { | ||
688 | err("%s - failed submitting read urb, error %d", __FUNCTION__, result); | ||
689 | goto error; | ||
690 | } | ||
691 | |||
692 | return 0; | ||
685 | 693 | ||
686 | enomem: | 694 | enomem: |
687 | result = -ENOMEM; | 695 | result = -ENOMEM; |
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c new file mode 100644 index 000000000000..95bf57166c59 --- /dev/null +++ b/drivers/usb/serial/mos7840.c | |||
@@ -0,0 +1,2962 @@ | |||
1 | /* | ||
2 | * This program is free software; you can redistribute it and/or modify | ||
3 | * it under the terms of the GNU General Public License as published by | ||
4 | * the Free Software Foundation; either version 2 of the License, or | ||
5 | * (at your option) any later version. | ||
6 | * | ||
7 | * This program is distributed in the hope that it will be useful, | ||
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
10 | * GNU General Public License for more details. | ||
11 | * | ||
12 | * You should have received a copy of the GNU General Public License | ||
13 | * along with this program; if not, write to the Free Software | ||
14 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
15 | * | ||
16 | * Clean ups from Moschip version and a few ioctl implementations by: | ||
17 | * Paul B Schroeder <pschroeder "at" uplogix "dot" com> | ||
18 | * | ||
19 | * Originally based on drivers/usb/serial/io_edgeport.c which is: | ||
20 | * Copyright (C) 2000 Inside Out Networks, All rights reserved. | ||
21 | * Copyright (C) 2001-2002 Greg Kroah-Hartman <greg@kroah.com> | ||
22 | * | ||
23 | */ | ||
24 | |||
25 | #include <linux/kernel.h> | ||
26 | #include <linux/errno.h> | ||
27 | #include <linux/init.h> | ||
28 | #include <linux/slab.h> | ||
29 | #include <linux/tty.h> | ||
30 | #include <linux/tty_driver.h> | ||
31 | #include <linux/tty_flip.h> | ||
32 | #include <linux/module.h> | ||
33 | #include <linux/serial.h> | ||
34 | #include <linux/usb.h> | ||
35 | #include <linux/usb/serial.h> | ||
36 | #include <asm/uaccess.h> | ||
37 | |||
38 | /* | ||
39 | * Version Information | ||
40 | */ | ||
41 | #define DRIVER_VERSION "1.3.1" | ||
42 | #define DRIVER_DESC "Moschip 7840/7820 USB Serial Driver" | ||
43 | |||
44 | /* | ||
45 | * 16C50 UART register defines | ||
46 | */ | ||
47 | |||
48 | #define LCR_BITS_5 0x00 /* 5 bits/char */ | ||
49 | #define LCR_BITS_6 0x01 /* 6 bits/char */ | ||
50 | #define LCR_BITS_7 0x02 /* 7 bits/char */ | ||
51 | #define LCR_BITS_8 0x03 /* 8 bits/char */ | ||
52 | #define LCR_BITS_MASK 0x03 /* Mask for bits/char field */ | ||
53 | |||
54 | #define LCR_STOP_1 0x00 /* 1 stop bit */ | ||
55 | #define LCR_STOP_1_5 0x04 /* 1.5 stop bits (if 5 bits/char) */ | ||
56 | #define LCR_STOP_2 0x04 /* 2 stop bits (if 6-8 bits/char) */ | ||
57 | #define LCR_STOP_MASK 0x04 /* Mask for stop bits field */ | ||
58 | |||
59 | #define LCR_PAR_NONE 0x00 /* No parity */ | ||
60 | #define LCR_PAR_ODD 0x08 /* Odd parity */ | ||
61 | #define LCR_PAR_EVEN 0x18 /* Even parity */ | ||
62 | #define LCR_PAR_MARK 0x28 /* Force parity bit to 1 */ | ||
63 | #define LCR_PAR_SPACE 0x38 /* Force parity bit to 0 */ | ||
64 | #define LCR_PAR_MASK 0x38 /* Mask for parity field */ | ||
65 | |||
66 | #define LCR_SET_BREAK 0x40 /* Set Break condition */ | ||
67 | #define LCR_DL_ENABLE 0x80 /* Enable access to divisor latch */ | ||
68 | |||
69 | #define MCR_DTR 0x01 /* Assert DTR */ | ||
70 | #define MCR_RTS 0x02 /* Assert RTS */ | ||
71 | #define MCR_OUT1 0x04 /* Loopback only: Sets state of RI */ | ||
72 | #define MCR_MASTER_IE 0x08 /* Enable interrupt outputs */ | ||
73 | #define MCR_LOOPBACK 0x10 /* Set internal (digital) loopback mode */ | ||
74 | #define MCR_XON_ANY 0x20 /* Enable any char to exit XOFF mode */ | ||
75 | |||
76 | #define MOS7840_MSR_CTS 0x10 /* Current state of CTS */ | ||
77 | #define MOS7840_MSR_DSR 0x20 /* Current state of DSR */ | ||
78 | #define MOS7840_MSR_RI 0x40 /* Current state of RI */ | ||
79 | #define MOS7840_MSR_CD 0x80 /* Current state of CD */ | ||
80 | |||
81 | /* | ||
82 | * Defines used for sending commands to port | ||
83 | */ | ||
84 | |||
85 | #define WAIT_FOR_EVER (HZ * 0 ) /* timeout urb is wait for ever */ | ||
86 | #define MOS_WDR_TIMEOUT (HZ * 5 ) /* default urb timeout */ | ||
87 | |||
88 | #define MOS_PORT1 0x0200 | ||
89 | #define MOS_PORT2 0x0300 | ||
90 | #define MOS_VENREG 0x0000 | ||
91 | #define MOS_MAX_PORT 0x02 | ||
92 | #define MOS_WRITE 0x0E | ||
93 | #define MOS_READ 0x0D | ||
94 | |||
95 | /* Requests */ | ||
96 | #define MCS_RD_RTYPE 0xC0 | ||
97 | #define MCS_WR_RTYPE 0x40 | ||
98 | #define MCS_RDREQ 0x0D | ||
99 | #define MCS_WRREQ 0x0E | ||
100 | #define MCS_CTRL_TIMEOUT 500 | ||
101 | #define VENDOR_READ_LENGTH (0x01) | ||
102 | |||
103 | #define MAX_NAME_LEN 64 | ||
104 | |||
105 | #define ZLP_REG1 0x3A //Zero_Flag_Reg1 58 | ||
106 | #define ZLP_REG5 0x3E //Zero_Flag_Reg5 62 | ||
107 | |||
108 | /* For higher baud Rates use TIOCEXBAUD */ | ||
109 | #define TIOCEXBAUD 0x5462 | ||
110 | |||
111 | /* vendor id and device id defines */ | ||
112 | |||
113 | #define USB_VENDOR_ID_MOSCHIP 0x9710 | ||
114 | #define MOSCHIP_DEVICE_ID_7840 0x7840 | ||
115 | #define MOSCHIP_DEVICE_ID_7820 0x7820 | ||
116 | |||
117 | /* Interrupt Rotinue Defines */ | ||
118 | |||
119 | #define SERIAL_IIR_RLS 0x06 | ||
120 | #define SERIAL_IIR_MS 0x00 | ||
121 | |||
122 | /* | ||
123 | * Emulation of the bit mask on the LINE STATUS REGISTER. | ||
124 | */ | ||
125 | #define SERIAL_LSR_DR 0x0001 | ||
126 | #define SERIAL_LSR_OE 0x0002 | ||
127 | #define SERIAL_LSR_PE 0x0004 | ||
128 | #define SERIAL_LSR_FE 0x0008 | ||
129 | #define SERIAL_LSR_BI 0x0010 | ||
130 | |||
131 | #define MOS_MSR_DELTA_CTS 0x10 | ||
132 | #define MOS_MSR_DELTA_DSR 0x20 | ||
133 | #define MOS_MSR_DELTA_RI 0x40 | ||
134 | #define MOS_MSR_DELTA_CD 0x80 | ||
135 | |||
136 | // Serial Port register Address | ||
137 | #define INTERRUPT_ENABLE_REGISTER ((__u16)(0x01)) | ||
138 | #define FIFO_CONTROL_REGISTER ((__u16)(0x02)) | ||
139 | #define LINE_CONTROL_REGISTER ((__u16)(0x03)) | ||
140 | #define MODEM_CONTROL_REGISTER ((__u16)(0x04)) | ||
141 | #define LINE_STATUS_REGISTER ((__u16)(0x05)) | ||
142 | #define MODEM_STATUS_REGISTER ((__u16)(0x06)) | ||
143 | #define SCRATCH_PAD_REGISTER ((__u16)(0x07)) | ||
144 | #define DIVISOR_LATCH_LSB ((__u16)(0x00)) | ||
145 | #define DIVISOR_LATCH_MSB ((__u16)(0x01)) | ||
146 | |||
147 | #define CLK_MULTI_REGISTER ((__u16)(0x02)) | ||
148 | #define CLK_START_VALUE_REGISTER ((__u16)(0x03)) | ||
149 | |||
150 | #define SERIAL_LCR_DLAB ((__u16)(0x0080)) | ||
151 | |||
152 | /* | ||
153 | * URB POOL related defines | ||
154 | */ | ||
155 | #define NUM_URBS 16 /* URB Count */ | ||
156 | #define URB_TRANSFER_BUFFER_SIZE 32 /* URB Size */ | ||
157 | |||
158 | |||
159 | static struct usb_device_id moschip_port_id_table[] = { | ||
160 | {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7840)}, | ||
161 | {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7820)}, | ||
162 | {} /* terminating entry */ | ||
163 | }; | ||
164 | |||
165 | static __devinitdata struct usb_device_id moschip_id_table_combined[] = { | ||
166 | {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7840)}, | ||
167 | {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7820)}, | ||
168 | {} /* terminating entry */ | ||
169 | }; | ||
170 | |||
171 | MODULE_DEVICE_TABLE(usb, moschip_id_table_combined); | ||
172 | |||
173 | /* This structure holds all of the local port information */ | ||
174 | |||
175 | struct moschip_port { | ||
176 | int port_num; /*Actual port number in the device(1,2,etc) */ | ||
177 | struct urb *write_urb; /* write URB for this port */ | ||
178 | struct urb *read_urb; /* read URB for this port */ | ||
179 | __u8 shadowLCR; /* last LCR value received */ | ||
180 | __u8 shadowMCR; /* last MCR value received */ | ||
181 | char open; | ||
182 | wait_queue_head_t wait_chase; /* for handling sleeping while waiting for chase to finish */ | ||
183 | wait_queue_head_t delta_msr_wait; /* for handling sleeping while waiting for msr change to happen */ | ||
184 | int delta_msr_cond; | ||
185 | struct async_icount icount; | ||
186 | struct usb_serial_port *port; /* loop back to the owner of this object */ | ||
187 | |||
188 | /*Offsets */ | ||
189 | __u8 SpRegOffset; | ||
190 | __u8 ControlRegOffset; | ||
191 | __u8 DcrRegOffset; | ||
192 | //for processing control URBS in interrupt context | ||
193 | struct urb *control_urb; | ||
194 | char *ctrl_buf; | ||
195 | int MsrLsr; | ||
196 | |||
197 | struct urb *write_urb_pool[NUM_URBS]; | ||
198 | }; | ||
199 | |||
200 | |||
201 | static int debug; | ||
202 | static int mos7840_num_ports; //this says the number of ports in the device | ||
203 | static int mos7840_num_open_ports; | ||
204 | |||
205 | |||
206 | /* | ||
207 | * mos7840_set_reg_sync | ||
208 | * To set the Control register by calling usb_fill_control_urb function | ||
209 | * by passing usb_sndctrlpipe function as parameter. | ||
210 | */ | ||
211 | |||
212 | static int mos7840_set_reg_sync(struct usb_serial_port *port, __u16 reg, | ||
213 | __u16 val) | ||
214 | { | ||
215 | struct usb_device *dev = port->serial->dev; | ||
216 | val = val & 0x00ff; | ||
217 | dbg("mos7840_set_reg_sync offset is %x, value %x\n", reg, val); | ||
218 | |||
219 | return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), MCS_WRREQ, | ||
220 | MCS_WR_RTYPE, val, reg, NULL, 0, | ||
221 | MOS_WDR_TIMEOUT); | ||
222 | } | ||
223 | |||
224 | /* | ||
225 | * mos7840_get_reg_sync | ||
226 | * To set the Uart register by calling usb_fill_control_urb function by | ||
227 | * passing usb_rcvctrlpipe function as parameter. | ||
228 | */ | ||
229 | |||
230 | static int mos7840_get_reg_sync(struct usb_serial_port *port, __u16 reg, | ||
231 | __u16 * val) | ||
232 | { | ||
233 | struct usb_device *dev = port->serial->dev; | ||
234 | int ret = 0; | ||
235 | |||
236 | ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), MCS_RDREQ, | ||
237 | MCS_RD_RTYPE, 0, reg, val, VENDOR_READ_LENGTH, | ||
238 | MOS_WDR_TIMEOUT); | ||
239 | dbg("mos7840_get_reg_sync offset is %x, return val %x\n", reg, *val); | ||
240 | *val = (*val) & 0x00ff; | ||
241 | return ret; | ||
242 | } | ||
243 | |||
244 | /* | ||
245 | * mos7840_set_uart_reg | ||
246 | * To set the Uart register by calling usb_fill_control_urb function by | ||
247 | * passing usb_sndctrlpipe function as parameter. | ||
248 | */ | ||
249 | |||
250 | static int mos7840_set_uart_reg(struct usb_serial_port *port, __u16 reg, | ||
251 | __u16 val) | ||
252 | { | ||
253 | |||
254 | struct usb_device *dev = port->serial->dev; | ||
255 | val = val & 0x00ff; | ||
256 | // For the UART control registers, the application number need to be Or'ed | ||
257 | if (mos7840_num_ports == 4) { | ||
258 | val |= | ||
259 | (((__u16) port->number - (__u16) (port->serial->minor)) + | ||
260 | 1) << 8; | ||
261 | dbg("mos7840_set_uart_reg application number is %x\n", val); | ||
262 | } else { | ||
263 | if (((__u16) port->number - (__u16) (port->serial->minor)) == 0) { | ||
264 | val |= | ||
265 | (((__u16) port->number - | ||
266 | (__u16) (port->serial->minor)) + 1) << 8; | ||
267 | dbg("mos7840_set_uart_reg application number is %x\n", | ||
268 | val); | ||
269 | } else { | ||
270 | val |= | ||
271 | (((__u16) port->number - | ||
272 | (__u16) (port->serial->minor)) + 2) << 8; | ||
273 | dbg("mos7840_set_uart_reg application number is %x\n", | ||
274 | val); | ||
275 | } | ||
276 | } | ||
277 | return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), MCS_WRREQ, | ||
278 | MCS_WR_RTYPE, val, reg, NULL, 0, | ||
279 | MOS_WDR_TIMEOUT); | ||
280 | |||
281 | } | ||
282 | |||
283 | /* | ||
284 | * mos7840_get_uart_reg | ||
285 | * To set the Control register by calling usb_fill_control_urb function | ||
286 | * by passing usb_rcvctrlpipe function as parameter. | ||
287 | */ | ||
288 | static int mos7840_get_uart_reg(struct usb_serial_port *port, __u16 reg, | ||
289 | __u16 * val) | ||
290 | { | ||
291 | struct usb_device *dev = port->serial->dev; | ||
292 | int ret = 0; | ||
293 | __u16 Wval; | ||
294 | |||
295 | //dbg("application number is %4x \n",(((__u16)port->number - (__u16)(port->serial->minor))+1)<<8); | ||
296 | /*Wval is same as application number */ | ||
297 | if (mos7840_num_ports == 4) { | ||
298 | Wval = | ||
299 | (((__u16) port->number - (__u16) (port->serial->minor)) + | ||
300 | 1) << 8; | ||
301 | dbg("mos7840_get_uart_reg application number is %x\n", Wval); | ||
302 | } else { | ||
303 | if (((__u16) port->number - (__u16) (port->serial->minor)) == 0) { | ||
304 | Wval = | ||
305 | (((__u16) port->number - | ||
306 | (__u16) (port->serial->minor)) + 1) << 8; | ||
307 | dbg("mos7840_get_uart_reg application number is %x\n", | ||
308 | Wval); | ||
309 | } else { | ||
310 | Wval = | ||
311 | (((__u16) port->number - | ||
312 | (__u16) (port->serial->minor)) + 2) << 8; | ||
313 | dbg("mos7840_get_uart_reg application number is %x\n", | ||
314 | Wval); | ||
315 | } | ||
316 | } | ||
317 | ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), MCS_RDREQ, | ||
318 | MCS_RD_RTYPE, Wval, reg, val, VENDOR_READ_LENGTH, | ||
319 | MOS_WDR_TIMEOUT); | ||
320 | *val = (*val) & 0x00ff; | ||
321 | return ret; | ||
322 | } | ||
323 | |||
324 | static void mos7840_dump_serial_port(struct moschip_port *mos7840_port) | ||
325 | { | ||
326 | |||
327 | dbg("***************************************\n"); | ||
328 | dbg("SpRegOffset is %2x\n", mos7840_port->SpRegOffset); | ||
329 | dbg("ControlRegOffset is %2x \n", mos7840_port->ControlRegOffset); | ||
330 | dbg("DCRRegOffset is %2x \n", mos7840_port->DcrRegOffset); | ||
331 | dbg("***************************************\n"); | ||
332 | |||
333 | } | ||
334 | |||
335 | /************************************************************************/ | ||
336 | /************************************************************************/ | ||
337 | /* I N T E R F A C E F U N C T I O N S */ | ||
338 | /* I N T E R F A C E F U N C T I O N S */ | ||
339 | /************************************************************************/ | ||
340 | /************************************************************************/ | ||
341 | |||
342 | static inline void mos7840_set_port_private(struct usb_serial_port *port, | ||
343 | struct moschip_port *data) | ||
344 | { | ||
345 | usb_set_serial_port_data(port, (void *)data); | ||
346 | } | ||
347 | |||
348 | static inline struct moschip_port *mos7840_get_port_private(struct | ||
349 | usb_serial_port | ||
350 | *port) | ||
351 | { | ||
352 | return (struct moschip_port *)usb_get_serial_port_data(port); | ||
353 | } | ||
354 | |||
355 | static int mos7840_handle_new_msr(struct moschip_port *port, __u8 new_msr) | ||
356 | { | ||
357 | struct moschip_port *mos7840_port; | ||
358 | struct async_icount *icount; | ||
359 | mos7840_port = port; | ||
360 | icount = &mos7840_port->icount; | ||
361 | if (new_msr & | ||
362 | (MOS_MSR_DELTA_CTS | MOS_MSR_DELTA_DSR | MOS_MSR_DELTA_RI | | ||
363 | MOS_MSR_DELTA_CD)) { | ||
364 | icount = &mos7840_port->icount; | ||
365 | |||
366 | /* update input line counters */ | ||
367 | if (new_msr & MOS_MSR_DELTA_CTS) { | ||
368 | icount->cts++; | ||
369 | } | ||
370 | if (new_msr & MOS_MSR_DELTA_DSR) { | ||
371 | icount->dsr++; | ||
372 | } | ||
373 | if (new_msr & MOS_MSR_DELTA_CD) { | ||
374 | icount->dcd++; | ||
375 | } | ||
376 | if (new_msr & MOS_MSR_DELTA_RI) { | ||
377 | icount->rng++; | ||
378 | } | ||
379 | } | ||
380 | |||
381 | return 0; | ||
382 | } | ||
383 | |||
384 | static int mos7840_handle_new_lsr(struct moschip_port *port, __u8 new_lsr) | ||
385 | { | ||
386 | struct async_icount *icount; | ||
387 | |||
388 | dbg("%s - %02x", __FUNCTION__, new_lsr); | ||
389 | |||
390 | if (new_lsr & SERIAL_LSR_BI) { | ||
391 | // | ||
392 | // Parity and Framing errors only count if they | ||
393 | // occur exclusive of a break being | ||
394 | // received. | ||
395 | // | ||
396 | new_lsr &= (__u8) (SERIAL_LSR_OE | SERIAL_LSR_BI); | ||
397 | } | ||
398 | |||
399 | /* update input line counters */ | ||
400 | icount = &port->icount; | ||
401 | if (new_lsr & SERIAL_LSR_BI) { | ||
402 | icount->brk++; | ||
403 | } | ||
404 | if (new_lsr & SERIAL_LSR_OE) { | ||
405 | icount->overrun++; | ||
406 | } | ||
407 | if (new_lsr & SERIAL_LSR_PE) { | ||
408 | icount->parity++; | ||
409 | } | ||
410 | if (new_lsr & SERIAL_LSR_FE) { | ||
411 | icount->frame++; | ||
412 | } | ||
413 | |||
414 | return 0; | ||
415 | } | ||
416 | |||
417 | /************************************************************************/ | ||
418 | /************************************************************************/ | ||
419 | /* U S B C A L L B A C K F U N C T I O N S */ | ||
420 | /* U S B C A L L B A C K F U N C T I O N S */ | ||
421 | /************************************************************************/ | ||
422 | /************************************************************************/ | ||
423 | |||
424 | static void mos7840_control_callback(struct urb *urb, struct pt_regs *regs) | ||
425 | { | ||
426 | unsigned char *data; | ||
427 | struct moschip_port *mos7840_port; | ||
428 | __u8 regval = 0x0; | ||
429 | |||
430 | if (!urb) { | ||
431 | dbg("%s", "Invalid Pointer !!!!:\n"); | ||
432 | return; | ||
433 | } | ||
434 | |||
435 | switch (urb->status) { | ||
436 | case 0: | ||
437 | /* success */ | ||
438 | break; | ||
439 | case -ECONNRESET: | ||
440 | case -ENOENT: | ||
441 | case -ESHUTDOWN: | ||
442 | /* this urb is terminated, clean up */ | ||
443 | dbg("%s - urb shutting down with status: %d", __FUNCTION__, | ||
444 | urb->status); | ||
445 | return; | ||
446 | default: | ||
447 | dbg("%s - nonzero urb status received: %d", __FUNCTION__, | ||
448 | urb->status); | ||
449 | goto exit; | ||
450 | } | ||
451 | |||
452 | mos7840_port = (struct moschip_port *)urb->context; | ||
453 | |||
454 | dbg("%s urb buffer size is %d\n", __FUNCTION__, urb->actual_length); | ||
455 | dbg("%s mos7840_port->MsrLsr is %d port %d\n", __FUNCTION__, | ||
456 | mos7840_port->MsrLsr, mos7840_port->port_num); | ||
457 | data = urb->transfer_buffer; | ||
458 | regval = (__u8) data[0]; | ||
459 | dbg("%s data is %x\n", __FUNCTION__, regval); | ||
460 | if (mos7840_port->MsrLsr == 0) | ||
461 | mos7840_handle_new_msr(mos7840_port, regval); | ||
462 | else if (mos7840_port->MsrLsr == 1) | ||
463 | mos7840_handle_new_lsr(mos7840_port, regval); | ||
464 | |||
465 | exit: | ||
466 | return; | ||
467 | } | ||
468 | |||
469 | static int mos7840_get_reg(struct moschip_port *mcs, __u16 Wval, __u16 reg, | ||
470 | __u16 * val) | ||
471 | { | ||
472 | struct usb_device *dev = mcs->port->serial->dev; | ||
473 | struct usb_ctrlrequest *dr = NULL; | ||
474 | unsigned char *buffer = NULL; | ||
475 | int ret = 0; | ||
476 | buffer = (__u8 *) mcs->ctrl_buf; | ||
477 | |||
478 | // dr=(struct usb_ctrlrequest *)(buffer); | ||
479 | dr = (void *)(buffer + 2); | ||
480 | dr->bRequestType = MCS_RD_RTYPE; | ||
481 | dr->bRequest = MCS_RDREQ; | ||
482 | dr->wValue = cpu_to_le16(Wval); //0; | ||
483 | dr->wIndex = cpu_to_le16(reg); | ||
484 | dr->wLength = cpu_to_le16(2); | ||
485 | |||
486 | usb_fill_control_urb(mcs->control_urb, dev, usb_rcvctrlpipe(dev, 0), | ||
487 | (unsigned char *)dr, buffer, 2, | ||
488 | mos7840_control_callback, mcs); | ||
489 | mcs->control_urb->transfer_buffer_length = 2; | ||
490 | ret = usb_submit_urb(mcs->control_urb, GFP_ATOMIC); | ||
491 | return ret; | ||
492 | } | ||
493 | |||
494 | /***************************************************************************** | ||
495 | * mos7840_interrupt_callback | ||
496 | * this is the callback function for when we have received data on the | ||
497 | * interrupt endpoint. | ||
498 | *****************************************************************************/ | ||
499 | |||
500 | static void mos7840_interrupt_callback(struct urb *urb, struct pt_regs *regs) | ||
501 | { | ||
502 | int result; | ||
503 | int length; | ||
504 | struct moschip_port *mos7840_port; | ||
505 | struct usb_serial *serial; | ||
506 | __u16 Data; | ||
507 | unsigned char *data; | ||
508 | __u8 sp[5], st; | ||
509 | int i; | ||
510 | __u16 wval; | ||
511 | |||
512 | dbg("%s", " : Entering\n"); | ||
513 | if (!urb) { | ||
514 | dbg("%s", "Invalid Pointer !!!!:\n"); | ||
515 | return; | ||
516 | } | ||
517 | |||
518 | switch (urb->status) { | ||
519 | case 0: | ||
520 | /* success */ | ||
521 | break; | ||
522 | case -ECONNRESET: | ||
523 | case -ENOENT: | ||
524 | case -ESHUTDOWN: | ||
525 | /* this urb is terminated, clean up */ | ||
526 | dbg("%s - urb shutting down with status: %d", __FUNCTION__, | ||
527 | urb->status); | ||
528 | return; | ||
529 | default: | ||
530 | dbg("%s - nonzero urb status received: %d", __FUNCTION__, | ||
531 | urb->status); | ||
532 | goto exit; | ||
533 | } | ||
534 | |||
535 | length = urb->actual_length; | ||
536 | data = urb->transfer_buffer; | ||
537 | |||
538 | serial = (struct usb_serial *)urb->context; | ||
539 | |||
540 | /* Moschip get 5 bytes | ||
541 | * Byte 1 IIR Port 1 (port.number is 0) | ||
542 | * Byte 2 IIR Port 2 (port.number is 1) | ||
543 | * Byte 3 IIR Port 3 (port.number is 2) | ||
544 | * Byte 4 IIR Port 4 (port.number is 3) | ||
545 | * Byte 5 FIFO status for both */ | ||
546 | |||
547 | if (length && length > 5) { | ||
548 | dbg("%s \n", "Wrong data !!!"); | ||
549 | return; | ||
550 | } | ||
551 | |||
552 | sp[0] = (__u8) data[0]; | ||
553 | sp[1] = (__u8) data[1]; | ||
554 | sp[2] = (__u8) data[2]; | ||
555 | sp[3] = (__u8) data[3]; | ||
556 | st = (__u8) data[4]; | ||
557 | |||
558 | for (i = 0; i < serial->num_ports; i++) { | ||
559 | mos7840_port = mos7840_get_port_private(serial->port[i]); | ||
560 | wval = | ||
561 | (((__u16) serial->port[i]->number - | ||
562 | (__u16) (serial->minor)) + 1) << 8; | ||
563 | if (mos7840_port->open) { | ||
564 | if (sp[i] & 0x01) { | ||
565 | dbg("SP%d No Interrupt !!!\n", i); | ||
566 | } else { | ||
567 | switch (sp[i] & 0x0f) { | ||
568 | case SERIAL_IIR_RLS: | ||
569 | dbg("Serial Port %d: Receiver status error or ", i); | ||
570 | dbg("address bit detected in 9-bit mode\n"); | ||
571 | mos7840_port->MsrLsr = 1; | ||
572 | mos7840_get_reg(mos7840_port, wval, | ||
573 | LINE_STATUS_REGISTER, | ||
574 | &Data); | ||
575 | break; | ||
576 | case SERIAL_IIR_MS: | ||
577 | dbg("Serial Port %d: Modem status change\n", i); | ||
578 | mos7840_port->MsrLsr = 0; | ||
579 | mos7840_get_reg(mos7840_port, wval, | ||
580 | MODEM_STATUS_REGISTER, | ||
581 | &Data); | ||
582 | break; | ||
583 | } | ||
584 | } | ||
585 | } | ||
586 | } | ||
587 | exit: | ||
588 | result = usb_submit_urb(urb, GFP_ATOMIC); | ||
589 | if (result) { | ||
590 | dev_err(&urb->dev->dev, | ||
591 | "%s - Error %d submitting interrupt urb\n", | ||
592 | __FUNCTION__, result); | ||
593 | } | ||
594 | |||
595 | return; | ||
596 | |||
597 | } | ||
598 | |||
599 | static int mos7840_port_paranoia_check(struct usb_serial_port *port, | ||
600 | const char *function) | ||
601 | { | ||
602 | if (!port) { | ||
603 | dbg("%s - port == NULL", function); | ||
604 | return -1; | ||
605 | } | ||
606 | if (!port->serial) { | ||
607 | dbg("%s - port->serial == NULL", function); | ||
608 | return -1; | ||
609 | } | ||
610 | |||
611 | return 0; | ||
612 | } | ||
613 | |||
614 | /* Inline functions to check the sanity of a pointer that is passed to us */ | ||
615 | static int mos7840_serial_paranoia_check(struct usb_serial *serial, | ||
616 | const char *function) | ||
617 | { | ||
618 | if (!serial) { | ||
619 | dbg("%s - serial == NULL", function); | ||
620 | return -1; | ||
621 | } | ||
622 | if (!serial->type) { | ||
623 | dbg("%s - serial->type == NULL!", function); | ||
624 | return -1; | ||
625 | } | ||
626 | |||
627 | return 0; | ||
628 | } | ||
629 | |||
630 | static struct usb_serial *mos7840_get_usb_serial(struct usb_serial_port *port, | ||
631 | const char *function) | ||
632 | { | ||
633 | /* if no port was specified, or it fails a paranoia check */ | ||
634 | if (!port || | ||
635 | mos7840_port_paranoia_check(port, function) || | ||
636 | mos7840_serial_paranoia_check(port->serial, function)) { | ||
637 | /* then say that we don't have a valid usb_serial thing, which will * end up genrating -ENODEV return values */ | ||
638 | return NULL; | ||
639 | } | ||
640 | |||
641 | return port->serial; | ||
642 | } | ||
643 | |||
644 | /***************************************************************************** | ||
645 | * mos7840_bulk_in_callback | ||
646 | * this is the callback function for when we have received data on the | ||
647 | * bulk in endpoint. | ||
648 | *****************************************************************************/ | ||
649 | |||
650 | static void mos7840_bulk_in_callback(struct urb *urb, struct pt_regs *regs) | ||
651 | { | ||
652 | int status; | ||
653 | unsigned char *data; | ||
654 | struct usb_serial *serial; | ||
655 | struct usb_serial_port *port; | ||
656 | struct moschip_port *mos7840_port; | ||
657 | struct tty_struct *tty; | ||
658 | |||
659 | if (!urb) { | ||
660 | dbg("%s", "Invalid Pointer !!!!:\n"); | ||
661 | return; | ||
662 | } | ||
663 | |||
664 | if (urb->status) { | ||
665 | dbg("nonzero read bulk status received: %d", urb->status); | ||
666 | return; | ||
667 | } | ||
668 | |||
669 | mos7840_port = (struct moschip_port *)urb->context; | ||
670 | if (!mos7840_port) { | ||
671 | dbg("%s", "NULL mos7840_port pointer \n"); | ||
672 | return; | ||
673 | } | ||
674 | |||
675 | port = (struct usb_serial_port *)mos7840_port->port; | ||
676 | if (mos7840_port_paranoia_check(port, __FUNCTION__)) { | ||
677 | dbg("%s", "Port Paranoia failed \n"); | ||
678 | return; | ||
679 | } | ||
680 | |||
681 | serial = mos7840_get_usb_serial(port, __FUNCTION__); | ||
682 | if (!serial) { | ||
683 | dbg("%s\n", "Bad serial pointer "); | ||
684 | return; | ||
685 | } | ||
686 | |||
687 | dbg("%s\n", "Entering... \n"); | ||
688 | |||
689 | data = urb->transfer_buffer; | ||
690 | |||
691 | dbg("%s", "Entering ........... \n"); | ||
692 | |||
693 | if (urb->actual_length) { | ||
694 | tty = mos7840_port->port->tty; | ||
695 | if (tty) { | ||
696 | tty_buffer_request_room(tty, urb->actual_length); | ||
697 | tty_insert_flip_string(tty, data, urb->actual_length); | ||
698 | dbg(" %s \n", data); | ||
699 | tty_flip_buffer_push(tty); | ||
700 | } | ||
701 | mos7840_port->icount.rx += urb->actual_length; | ||
702 | dbg("mos7840_port->icount.rx is %d:\n", | ||
703 | mos7840_port->icount.rx); | ||
704 | } | ||
705 | |||
706 | if (!mos7840_port->read_urb) { | ||
707 | dbg("%s", "URB KILLED !!!\n"); | ||
708 | return; | ||
709 | } | ||
710 | |||
711 | if (mos7840_port->read_urb->status != -EINPROGRESS) { | ||
712 | mos7840_port->read_urb->dev = serial->dev; | ||
713 | |||
714 | status = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC); | ||
715 | |||
716 | if (status) { | ||
717 | dbg(" usb_submit_urb(read bulk) failed, status = %d", | ||
718 | status); | ||
719 | } | ||
720 | } | ||
721 | } | ||
722 | |||
723 | /***************************************************************************** | ||
724 | * mos7840_bulk_out_data_callback | ||
725 | * this is the callback function for when we have finished sending serial data | ||
726 | * on the bulk out endpoint. | ||
727 | *****************************************************************************/ | ||
728 | |||
729 | static void mos7840_bulk_out_data_callback(struct urb *urb, | ||
730 | struct pt_regs *regs) | ||
731 | { | ||
732 | struct moschip_port *mos7840_port; | ||
733 | struct tty_struct *tty; | ||
734 | if (!urb) { | ||
735 | dbg("%s", "Invalid Pointer !!!!:\n"); | ||
736 | return; | ||
737 | } | ||
738 | |||
739 | if (urb->status) { | ||
740 | dbg("nonzero write bulk status received:%d\n", urb->status); | ||
741 | return; | ||
742 | } | ||
743 | |||
744 | mos7840_port = (struct moschip_port *)urb->context; | ||
745 | if (!mos7840_port) { | ||
746 | dbg("%s", "NULL mos7840_port pointer \n"); | ||
747 | return; | ||
748 | } | ||
749 | |||
750 | if (mos7840_port_paranoia_check(mos7840_port->port, __FUNCTION__)) { | ||
751 | dbg("%s", "Port Paranoia failed \n"); | ||
752 | return; | ||
753 | } | ||
754 | |||
755 | dbg("%s \n", "Entering ........."); | ||
756 | |||
757 | tty = mos7840_port->port->tty; | ||
758 | |||
759 | if (tty && mos7840_port->open) { | ||
760 | /* let the tty driver wakeup if it has a special * | ||
761 | * write_wakeup function */ | ||
762 | |||
763 | if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) | ||
764 | && tty->ldisc.write_wakeup) { | ||
765 | (tty->ldisc.write_wakeup) (tty); | ||
766 | } | ||
767 | |||
768 | /* tell the tty driver that something has changed */ | ||
769 | wake_up_interruptible(&tty->write_wait); | ||
770 | } | ||
771 | |||
772 | } | ||
773 | |||
774 | /************************************************************************/ | ||
775 | /* D R I V E R T T Y I N T E R F A C E F U N C T I O N S */ | ||
776 | /************************************************************************/ | ||
777 | #ifdef MCSSerialProbe | ||
778 | static int mos7840_serial_probe(struct usb_serial *serial, | ||
779 | const struct usb_device_id *id) | ||
780 | { | ||
781 | |||
782 | /*need to implement the mode_reg reading and updating\ | ||
783 | structures usb_serial_ device_type\ | ||
784 | (i.e num_ports, num_bulkin,bulkout etc) */ | ||
785 | /* Also we can update the changes attach */ | ||
786 | return 1; | ||
787 | } | ||
788 | #endif | ||
789 | |||
790 | /***************************************************************************** | ||
791 | * mos7840_open | ||
792 | * this function is called by the tty driver when a port is opened | ||
793 | * If successful, we return 0 | ||
794 | * Otherwise we return a negative error number. | ||
795 | *****************************************************************************/ | ||
796 | |||
797 | static int mos7840_open(struct usb_serial_port *port, struct file *filp) | ||
798 | { | ||
799 | int response; | ||
800 | int j; | ||
801 | struct usb_serial *serial; | ||
802 | struct urb *urb; | ||
803 | __u16 Data; | ||
804 | int status; | ||
805 | struct moschip_port *mos7840_port; | ||
806 | |||
807 | if (mos7840_port_paranoia_check(port, __FUNCTION__)) { | ||
808 | dbg("%s", "Port Paranoia failed \n"); | ||
809 | return -ENODEV; | ||
810 | } | ||
811 | |||
812 | mos7840_num_open_ports++; | ||
813 | serial = port->serial; | ||
814 | |||
815 | if (mos7840_serial_paranoia_check(serial, __FUNCTION__)) { | ||
816 | dbg("%s", "Serial Paranoia failed \n"); | ||
817 | return -ENODEV; | ||
818 | } | ||
819 | |||
820 | mos7840_port = mos7840_get_port_private(port); | ||
821 | |||
822 | if (mos7840_port == NULL) | ||
823 | return -ENODEV; | ||
824 | |||
825 | usb_clear_halt(serial->dev, port->write_urb->pipe); | ||
826 | usb_clear_halt(serial->dev, port->read_urb->pipe); | ||
827 | |||
828 | /* Initialising the write urb pool */ | ||
829 | for (j = 0; j < NUM_URBS; ++j) { | ||
830 | urb = usb_alloc_urb(0, SLAB_ATOMIC); | ||
831 | mos7840_port->write_urb_pool[j] = urb; | ||
832 | |||
833 | if (urb == NULL) { | ||
834 | err("No more urbs???"); | ||
835 | continue; | ||
836 | } | ||
837 | |||
838 | urb->transfer_buffer = NULL; | ||
839 | urb->transfer_buffer = | ||
840 | kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL); | ||
841 | if (!urb->transfer_buffer) { | ||
842 | err("%s-out of memory for urb buffers.", __FUNCTION__); | ||
843 | continue; | ||
844 | } | ||
845 | } | ||
846 | |||
847 | /***************************************************************************** | ||
848 | * Initialize MCS7840 -- Write Init values to corresponding Registers | ||
849 | * | ||
850 | * Register Index | ||
851 | * 1 : IER | ||
852 | * 2 : FCR | ||
853 | * 3 : LCR | ||
854 | * 4 : MCR | ||
855 | * | ||
856 | * 0x08 : SP1/2 Control Reg | ||
857 | *****************************************************************************/ | ||
858 | |||
859 | //NEED to check the following Block | ||
860 | |||
861 | status = 0; | ||
862 | Data = 0x0; | ||
863 | status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data); | ||
864 | if (status < 0) { | ||
865 | dbg("Reading Spreg failed\n"); | ||
866 | return -1; | ||
867 | } | ||
868 | Data |= 0x80; | ||
869 | status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data); | ||
870 | if (status < 0) { | ||
871 | dbg("writing Spreg failed\n"); | ||
872 | return -1; | ||
873 | } | ||
874 | |||
875 | Data &= ~0x80; | ||
876 | status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data); | ||
877 | if (status < 0) { | ||
878 | dbg("writing Spreg failed\n"); | ||
879 | return -1; | ||
880 | } | ||
881 | //End of block to be checked | ||
882 | |||
883 | status = 0; | ||
884 | Data = 0x0; | ||
885 | status = | ||
886 | mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset, &Data); | ||
887 | if (status < 0) { | ||
888 | dbg("Reading Controlreg failed\n"); | ||
889 | return -1; | ||
890 | } | ||
891 | Data |= 0x08; //Driver done bit | ||
892 | Data |= 0x20; //rx_disable | ||
893 | status = 0; | ||
894 | status = | ||
895 | mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset, Data); | ||
896 | if (status < 0) { | ||
897 | dbg("writing Controlreg failed\n"); | ||
898 | return -1; | ||
899 | } | ||
900 | //do register settings here | ||
901 | // Set all regs to the device default values. | ||
902 | //////////////////////////////////// | ||
903 | // First Disable all interrupts. | ||
904 | //////////////////////////////////// | ||
905 | |||
906 | Data = 0x00; | ||
907 | status = 0; | ||
908 | status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data); | ||
909 | if (status < 0) { | ||
910 | dbg("disableing interrupts failed\n"); | ||
911 | return -1; | ||
912 | } | ||
913 | // Set FIFO_CONTROL_REGISTER to the default value | ||
914 | Data = 0x00; | ||
915 | status = 0; | ||
916 | status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data); | ||
917 | if (status < 0) { | ||
918 | dbg("Writing FIFO_CONTROL_REGISTER failed\n"); | ||
919 | return -1; | ||
920 | } | ||
921 | |||
922 | Data = 0xcf; | ||
923 | status = 0; | ||
924 | status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data); | ||
925 | if (status < 0) { | ||
926 | dbg("Writing FIFO_CONTROL_REGISTER failed\n"); | ||
927 | return -1; | ||
928 | } | ||
929 | |||
930 | Data = 0x03; | ||
931 | status = 0; | ||
932 | status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); | ||
933 | mos7840_port->shadowLCR = Data; | ||
934 | |||
935 | Data = 0x0b; | ||
936 | status = 0; | ||
937 | status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); | ||
938 | mos7840_port->shadowMCR = Data; | ||
939 | |||
940 | Data = 0x00; | ||
941 | status = 0; | ||
942 | status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data); | ||
943 | mos7840_port->shadowLCR = Data; | ||
944 | |||
945 | Data |= SERIAL_LCR_DLAB; //data latch enable in LCR 0x80 | ||
946 | status = 0; | ||
947 | status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); | ||
948 | |||
949 | Data = 0x0c; | ||
950 | status = 0; | ||
951 | status = mos7840_set_uart_reg(port, DIVISOR_LATCH_LSB, Data); | ||
952 | |||
953 | Data = 0x0; | ||
954 | status = 0; | ||
955 | status = mos7840_set_uart_reg(port, DIVISOR_LATCH_MSB, Data); | ||
956 | |||
957 | Data = 0x00; | ||
958 | status = 0; | ||
959 | status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data); | ||
960 | |||
961 | Data = Data & ~SERIAL_LCR_DLAB; | ||
962 | status = 0; | ||
963 | status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); | ||
964 | mos7840_port->shadowLCR = Data; | ||
965 | |||
966 | //clearing Bulkin and Bulkout Fifo | ||
967 | Data = 0x0; | ||
968 | status = 0; | ||
969 | status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data); | ||
970 | |||
971 | Data = Data | 0x0c; | ||
972 | status = 0; | ||
973 | status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data); | ||
974 | |||
975 | Data = Data & ~0x0c; | ||
976 | status = 0; | ||
977 | status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data); | ||
978 | //Finally enable all interrupts | ||
979 | Data = 0x0; | ||
980 | Data = 0x0c; | ||
981 | status = 0; | ||
982 | status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data); | ||
983 | |||
984 | //clearing rx_disable | ||
985 | Data = 0x0; | ||
986 | status = 0; | ||
987 | status = | ||
988 | mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset, &Data); | ||
989 | Data = Data & ~0x20; | ||
990 | status = 0; | ||
991 | status = | ||
992 | mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset, Data); | ||
993 | |||
994 | // rx_negate | ||
995 | Data = 0x0; | ||
996 | status = 0; | ||
997 | status = | ||
998 | mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset, &Data); | ||
999 | Data = Data | 0x10; | ||
1000 | status = 0; | ||
1001 | status = | ||
1002 | mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset, Data); | ||
1003 | |||
1004 | /* force low_latency on so that our tty_push actually forces * | ||
1005 | * the data through,otherwise it is scheduled, and with * | ||
1006 | * high data rates (like with OHCI) data can get lost. */ | ||
1007 | |||
1008 | if (port->tty) | ||
1009 | port->tty->low_latency = 1; | ||
1010 | /* Check to see if we've set up our endpoint info yet * | ||
1011 | * (can't set it up in mos7840_startup as the structures * | ||
1012 | * were not set up at that time.) */ | ||
1013 | if (mos7840_num_open_ports == 1) { | ||
1014 | if (serial->port[0]->interrupt_in_buffer == NULL) { | ||
1015 | |||
1016 | /* set up interrupt urb */ | ||
1017 | |||
1018 | usb_fill_int_urb(serial->port[0]->interrupt_in_urb, | ||
1019 | serial->dev, | ||
1020 | usb_rcvintpipe(serial->dev, | ||
1021 | serial->port[0]-> | ||
1022 | interrupt_in_endpointAddress), | ||
1023 | serial->port[0]->interrupt_in_buffer, | ||
1024 | serial->port[0]->interrupt_in_urb-> | ||
1025 | transfer_buffer_length, | ||
1026 | mos7840_interrupt_callback, | ||
1027 | serial, | ||
1028 | serial->port[0]->interrupt_in_urb-> | ||
1029 | interval); | ||
1030 | |||
1031 | /* start interrupt read for mos7840 * | ||
1032 | * will continue as long as mos7840 is connected */ | ||
1033 | |||
1034 | response = | ||
1035 | usb_submit_urb(serial->port[0]->interrupt_in_urb, | ||
1036 | GFP_KERNEL); | ||
1037 | if (response) { | ||
1038 | err("%s - Error %d submitting interrupt urb", | ||
1039 | __FUNCTION__, response); | ||
1040 | } | ||
1041 | |||
1042 | } | ||
1043 | |||
1044 | } | ||
1045 | |||
1046 | /* see if we've set up our endpoint info yet * | ||
1047 | * (can't set it up in mos7840_startup as the * | ||
1048 | * structures were not set up at that time.) */ | ||
1049 | |||
1050 | dbg("port number is %d \n", port->number); | ||
1051 | dbg("serial number is %d \n", port->serial->minor); | ||
1052 | dbg("Bulkin endpoint is %d \n", port->bulk_in_endpointAddress); | ||
1053 | dbg("BulkOut endpoint is %d \n", port->bulk_out_endpointAddress); | ||
1054 | dbg("Interrupt endpoint is %d \n", port->interrupt_in_endpointAddress); | ||
1055 | dbg("port's number in the device is %d\n", mos7840_port->port_num); | ||
1056 | mos7840_port->read_urb = port->read_urb; | ||
1057 | |||
1058 | /* set up our bulk in urb */ | ||
1059 | |||
1060 | usb_fill_bulk_urb(mos7840_port->read_urb, | ||
1061 | serial->dev, | ||
1062 | usb_rcvbulkpipe(serial->dev, | ||
1063 | port->bulk_in_endpointAddress), | ||
1064 | port->bulk_in_buffer, | ||
1065 | mos7840_port->read_urb->transfer_buffer_length, | ||
1066 | mos7840_bulk_in_callback, mos7840_port); | ||
1067 | |||
1068 | dbg("mos7840_open: bulkin endpoint is %d\n", | ||
1069 | port->bulk_in_endpointAddress); | ||
1070 | response = usb_submit_urb(mos7840_port->read_urb, GFP_KERNEL); | ||
1071 | if (response) { | ||
1072 | err("%s - Error %d submitting control urb", __FUNCTION__, | ||
1073 | response); | ||
1074 | } | ||
1075 | |||
1076 | /* initialize our wait queues */ | ||
1077 | init_waitqueue_head(&mos7840_port->wait_chase); | ||
1078 | init_waitqueue_head(&mos7840_port->delta_msr_wait); | ||
1079 | |||
1080 | /* initialize our icount structure */ | ||
1081 | memset(&(mos7840_port->icount), 0x00, sizeof(mos7840_port->icount)); | ||
1082 | |||
1083 | /* initialize our port settings */ | ||
1084 | mos7840_port->shadowMCR = MCR_MASTER_IE; /* Must set to enable ints! */ | ||
1085 | /* send a open port command */ | ||
1086 | mos7840_port->open = 1; | ||
1087 | //mos7840_change_port_settings(mos7840_port,old_termios); | ||
1088 | mos7840_port->icount.tx = 0; | ||
1089 | mos7840_port->icount.rx = 0; | ||
1090 | |||
1091 | dbg("\n\nusb_serial serial:%x mos7840_port:%x\n usb_serial_port port:%x\n\n", (unsigned int)serial, (unsigned int)mos7840_port, (unsigned int)port); | ||
1092 | |||
1093 | return 0; | ||
1094 | |||
1095 | } | ||
1096 | |||
1097 | /***************************************************************************** | ||
1098 | * mos7840_chars_in_buffer | ||
1099 | * this function is called by the tty driver when it wants to know how many | ||
1100 | * bytes of data we currently have outstanding in the port (data that has | ||
1101 | * been written, but hasn't made it out the port yet) | ||
1102 | * If successful, we return the number of bytes left to be written in the | ||
1103 | * system, | ||
1104 | * Otherwise we return a negative error number. | ||
1105 | *****************************************************************************/ | ||
1106 | |||
1107 | static int mos7840_chars_in_buffer(struct usb_serial_port *port) | ||
1108 | { | ||
1109 | int i; | ||
1110 | int chars = 0; | ||
1111 | struct moschip_port *mos7840_port; | ||
1112 | |||
1113 | dbg("%s \n", " mos7840_chars_in_buffer:entering ..........."); | ||
1114 | |||
1115 | if (mos7840_port_paranoia_check(port, __FUNCTION__)) { | ||
1116 | dbg("%s", "Invalid port \n"); | ||
1117 | return -1; | ||
1118 | } | ||
1119 | |||
1120 | mos7840_port = mos7840_get_port_private(port); | ||
1121 | if (mos7840_port == NULL) { | ||
1122 | dbg("%s \n", "mos7840_break:leaving ..........."); | ||
1123 | return -1; | ||
1124 | } | ||
1125 | |||
1126 | for (i = 0; i < NUM_URBS; ++i) { | ||
1127 | if (mos7840_port->write_urb_pool[i]->status == -EINPROGRESS) { | ||
1128 | chars += URB_TRANSFER_BUFFER_SIZE; | ||
1129 | } | ||
1130 | } | ||
1131 | dbg("%s - returns %d", __FUNCTION__, chars); | ||
1132 | return (chars); | ||
1133 | |||
1134 | } | ||
1135 | |||
1136 | /************************************************************************ | ||
1137 | * | ||
1138 | * mos7840_block_until_tx_empty | ||
1139 | * | ||
1140 | * This function will block the close until one of the following: | ||
1141 | * 1. TX count are 0 | ||
1142 | * 2. The mos7840 has stopped | ||
1143 | * 3. A timout of 3 seconds without activity has expired | ||
1144 | * | ||
1145 | ************************************************************************/ | ||
1146 | static void mos7840_block_until_tx_empty(struct moschip_port *mos7840_port) | ||
1147 | { | ||
1148 | int timeout = HZ / 10; | ||
1149 | int wait = 30; | ||
1150 | int count; | ||
1151 | |||
1152 | while (1) { | ||
1153 | |||
1154 | count = mos7840_chars_in_buffer(mos7840_port->port); | ||
1155 | |||
1156 | /* Check for Buffer status */ | ||
1157 | if (count <= 0) { | ||
1158 | return; | ||
1159 | } | ||
1160 | |||
1161 | /* Block the thread for a while */ | ||
1162 | interruptible_sleep_on_timeout(&mos7840_port->wait_chase, | ||
1163 | timeout); | ||
1164 | |||
1165 | /* No activity.. count down section */ | ||
1166 | wait--; | ||
1167 | if (wait == 0) { | ||
1168 | dbg("%s - TIMEOUT", __FUNCTION__); | ||
1169 | return; | ||
1170 | } else { | ||
1171 | /* Reset timout value back to seconds */ | ||
1172 | wait = 30; | ||
1173 | } | ||
1174 | } | ||
1175 | } | ||
1176 | |||
1177 | /***************************************************************************** | ||
1178 | * mos7840_close | ||
1179 | * this function is called by the tty driver when a port is closed | ||
1180 | *****************************************************************************/ | ||
1181 | |||
1182 | static void mos7840_close(struct usb_serial_port *port, struct file *filp) | ||
1183 | { | ||
1184 | struct usb_serial *serial; | ||
1185 | struct moschip_port *mos7840_port; | ||
1186 | int j; | ||
1187 | __u16 Data; | ||
1188 | |||
1189 | dbg("%s\n", "mos7840_close:entering..."); | ||
1190 | |||
1191 | if (mos7840_port_paranoia_check(port, __FUNCTION__)) { | ||
1192 | dbg("%s", "Port Paranoia failed \n"); | ||
1193 | return; | ||
1194 | } | ||
1195 | |||
1196 | serial = mos7840_get_usb_serial(port, __FUNCTION__); | ||
1197 | if (!serial) { | ||
1198 | dbg("%s", "Serial Paranoia failed \n"); | ||
1199 | return; | ||
1200 | } | ||
1201 | |||
1202 | mos7840_port = mos7840_get_port_private(port); | ||
1203 | |||
1204 | if (mos7840_port == NULL) { | ||
1205 | return; | ||
1206 | } | ||
1207 | |||
1208 | for (j = 0; j < NUM_URBS; ++j) | ||
1209 | usb_kill_urb(mos7840_port->write_urb_pool[j]); | ||
1210 | |||
1211 | /* Freeing Write URBs */ | ||
1212 | for (j = 0; j < NUM_URBS; ++j) { | ||
1213 | if (mos7840_port->write_urb_pool[j]) { | ||
1214 | if (mos7840_port->write_urb_pool[j]->transfer_buffer) | ||
1215 | kfree(mos7840_port->write_urb_pool[j]-> | ||
1216 | transfer_buffer); | ||
1217 | |||
1218 | usb_free_urb(mos7840_port->write_urb_pool[j]); | ||
1219 | } | ||
1220 | } | ||
1221 | |||
1222 | if (serial->dev) { | ||
1223 | /* flush and block until tx is empty */ | ||
1224 | mos7840_block_until_tx_empty(mos7840_port); | ||
1225 | } | ||
1226 | |||
1227 | /* While closing port, shutdown all bulk read, write * | ||
1228 | * and interrupt read if they exists */ | ||
1229 | if (serial->dev) { | ||
1230 | |||
1231 | if (mos7840_port->write_urb) { | ||
1232 | dbg("%s", "Shutdown bulk write\n"); | ||
1233 | usb_kill_urb(mos7840_port->write_urb); | ||
1234 | } | ||
1235 | |||
1236 | if (mos7840_port->read_urb) { | ||
1237 | dbg("%s", "Shutdown bulk read\n"); | ||
1238 | usb_kill_urb(mos7840_port->read_urb); | ||
1239 | } | ||
1240 | if ((&mos7840_port->control_urb)) { | ||
1241 | dbg("%s", "Shutdown control read\n"); | ||
1242 | // usb_kill_urb (mos7840_port->control_urb); | ||
1243 | |||
1244 | } | ||
1245 | } | ||
1246 | // if(mos7840_port->ctrl_buf != NULL) | ||
1247 | // kfree(mos7840_port->ctrl_buf); | ||
1248 | mos7840_num_open_ports--; | ||
1249 | dbg("mos7840_num_open_ports in close%d:in port%d\n", | ||
1250 | mos7840_num_open_ports, port->number); | ||
1251 | if (mos7840_num_open_ports == 0) { | ||
1252 | if (serial->port[0]->interrupt_in_urb) { | ||
1253 | dbg("%s", "Shutdown interrupt_in_urb\n"); | ||
1254 | } | ||
1255 | } | ||
1256 | |||
1257 | if (mos7840_port->write_urb) { | ||
1258 | /* if this urb had a transfer buffer already (old tx) free it */ | ||
1259 | |||
1260 | if (mos7840_port->write_urb->transfer_buffer != NULL) { | ||
1261 | kfree(mos7840_port->write_urb->transfer_buffer); | ||
1262 | } | ||
1263 | usb_free_urb(mos7840_port->write_urb); | ||
1264 | } | ||
1265 | |||
1266 | Data = 0x0; | ||
1267 | mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); | ||
1268 | |||
1269 | Data = 0x00; | ||
1270 | mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data); | ||
1271 | |||
1272 | mos7840_port->open = 0; | ||
1273 | |||
1274 | dbg("%s \n", "Leaving ............"); | ||
1275 | } | ||
1276 | |||
1277 | /************************************************************************ | ||
1278 | * | ||
1279 | * mos7840_block_until_chase_response | ||
1280 | * | ||
1281 | * This function will block the close until one of the following: | ||
1282 | * 1. Response to our Chase comes from mos7840 | ||
1283 | * 2. A timout of 10 seconds without activity has expired | ||
1284 | * (1K of mos7840 data @ 2400 baud ==> 4 sec to empty) | ||
1285 | * | ||
1286 | ************************************************************************/ | ||
1287 | |||
1288 | static void mos7840_block_until_chase_response(struct moschip_port | ||
1289 | *mos7840_port) | ||
1290 | { | ||
1291 | int timeout = 1 * HZ; | ||
1292 | int wait = 10; | ||
1293 | int count; | ||
1294 | |||
1295 | while (1) { | ||
1296 | count = mos7840_chars_in_buffer(mos7840_port->port); | ||
1297 | |||
1298 | /* Check for Buffer status */ | ||
1299 | if (count <= 0) { | ||
1300 | return; | ||
1301 | } | ||
1302 | |||
1303 | /* Block the thread for a while */ | ||
1304 | interruptible_sleep_on_timeout(&mos7840_port->wait_chase, | ||
1305 | timeout); | ||
1306 | /* No activity.. count down section */ | ||
1307 | wait--; | ||
1308 | if (wait == 0) { | ||
1309 | dbg("%s - TIMEOUT", __FUNCTION__); | ||
1310 | return; | ||
1311 | } else { | ||
1312 | /* Reset timout value back to seconds */ | ||
1313 | wait = 10; | ||
1314 | } | ||
1315 | } | ||
1316 | |||
1317 | } | ||
1318 | |||
1319 | /***************************************************************************** | ||
1320 | * mos7840_break | ||
1321 | * this function sends a break to the port | ||
1322 | *****************************************************************************/ | ||
1323 | static void mos7840_break(struct usb_serial_port *port, int break_state) | ||
1324 | { | ||
1325 | unsigned char data; | ||
1326 | struct usb_serial *serial; | ||
1327 | struct moschip_port *mos7840_port; | ||
1328 | |||
1329 | dbg("%s \n", "Entering ..........."); | ||
1330 | dbg("mos7840_break: Start\n"); | ||
1331 | |||
1332 | if (mos7840_port_paranoia_check(port, __FUNCTION__)) { | ||
1333 | dbg("%s", "Port Paranoia failed \n"); | ||
1334 | return; | ||
1335 | } | ||
1336 | |||
1337 | serial = mos7840_get_usb_serial(port, __FUNCTION__); | ||
1338 | if (!serial) { | ||
1339 | dbg("%s", "Serial Paranoia failed \n"); | ||
1340 | return; | ||
1341 | } | ||
1342 | |||
1343 | mos7840_port = mos7840_get_port_private(port); | ||
1344 | |||
1345 | if (mos7840_port == NULL) { | ||
1346 | return; | ||
1347 | } | ||
1348 | |||
1349 | if (serial->dev) { | ||
1350 | |||
1351 | /* flush and block until tx is empty */ | ||
1352 | mos7840_block_until_chase_response(mos7840_port); | ||
1353 | } | ||
1354 | |||
1355 | if (break_state == -1) { | ||
1356 | data = mos7840_port->shadowLCR | LCR_SET_BREAK; | ||
1357 | } else { | ||
1358 | data = mos7840_port->shadowLCR & ~LCR_SET_BREAK; | ||
1359 | } | ||
1360 | |||
1361 | mos7840_port->shadowLCR = data; | ||
1362 | dbg("mcs7840_break mos7840_port->shadowLCR is %x\n", | ||
1363 | mos7840_port->shadowLCR); | ||
1364 | mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, | ||
1365 | mos7840_port->shadowLCR); | ||
1366 | |||
1367 | return; | ||
1368 | } | ||
1369 | |||
1370 | /***************************************************************************** | ||
1371 | * mos7840_write_room | ||
1372 | * this function is called by the tty driver when it wants to know how many | ||
1373 | * bytes of data we can accept for a specific port. | ||
1374 | * If successful, we return the amount of room that we have for this port | ||
1375 | * Otherwise we return a negative error number. | ||
1376 | *****************************************************************************/ | ||
1377 | |||
1378 | static int mos7840_write_room(struct usb_serial_port *port) | ||
1379 | { | ||
1380 | int i; | ||
1381 | int room = 0; | ||
1382 | struct moschip_port *mos7840_port; | ||
1383 | |||
1384 | dbg("%s \n", " mos7840_write_room:entering ..........."); | ||
1385 | |||
1386 | if (mos7840_port_paranoia_check(port, __FUNCTION__)) { | ||
1387 | dbg("%s", "Invalid port \n"); | ||
1388 | dbg("%s \n", " mos7840_write_room:leaving ..........."); | ||
1389 | return -1; | ||
1390 | } | ||
1391 | |||
1392 | mos7840_port = mos7840_get_port_private(port); | ||
1393 | if (mos7840_port == NULL) { | ||
1394 | dbg("%s \n", "mos7840_break:leaving ..........."); | ||
1395 | return -1; | ||
1396 | } | ||
1397 | |||
1398 | for (i = 0; i < NUM_URBS; ++i) { | ||
1399 | if (mos7840_port->write_urb_pool[i]->status != -EINPROGRESS) { | ||
1400 | room += URB_TRANSFER_BUFFER_SIZE; | ||
1401 | } | ||
1402 | } | ||
1403 | |||
1404 | dbg("%s - returns %d", __FUNCTION__, room); | ||
1405 | return (room); | ||
1406 | |||
1407 | } | ||
1408 | |||
1409 | /***************************************************************************** | ||
1410 | * mos7840_write | ||
1411 | * this function is called by the tty driver when data should be written to | ||
1412 | * the port. | ||
1413 | * If successful, we return the number of bytes written, otherwise we | ||
1414 | * return a negative error number. | ||
1415 | *****************************************************************************/ | ||
1416 | |||
1417 | static int mos7840_write(struct usb_serial_port *port, | ||
1418 | const unsigned char *data, int count) | ||
1419 | { | ||
1420 | int status; | ||
1421 | int i; | ||
1422 | int bytes_sent = 0; | ||
1423 | int transfer_size; | ||
1424 | int from_user = 0; | ||
1425 | |||
1426 | struct moschip_port *mos7840_port; | ||
1427 | struct usb_serial *serial; | ||
1428 | struct urb *urb; | ||
1429 | //__u16 Data; | ||
1430 | const unsigned char *current_position = data; | ||
1431 | unsigned char *data1; | ||
1432 | dbg("%s \n", "entering ..........."); | ||
1433 | //dbg("mos7840_write: mos7840_port->shadowLCR is %x\n",mos7840_port->shadowLCR); | ||
1434 | |||
1435 | #ifdef NOTMOS7840 | ||
1436 | Data = 0x00; | ||
1437 | status = 0; | ||
1438 | status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data); | ||
1439 | mos7840_port->shadowLCR = Data; | ||
1440 | dbg("mos7840_write: LINE_CONTROL_REGISTER is %x\n", Data); | ||
1441 | dbg("mos7840_write: mos7840_port->shadowLCR is %x\n", | ||
1442 | mos7840_port->shadowLCR); | ||
1443 | |||
1444 | //Data = 0x03; | ||
1445 | //status = mos7840_set_uart_reg(port,LINE_CONTROL_REGISTER,Data); | ||
1446 | //mos7840_port->shadowLCR=Data;//Need to add later | ||
1447 | |||
1448 | Data |= SERIAL_LCR_DLAB; //data latch enable in LCR 0x80 | ||
1449 | status = 0; | ||
1450 | status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); | ||
1451 | |||
1452 | //Data = 0x0c; | ||
1453 | //status = mos7840_set_uart_reg(port,DIVISOR_LATCH_LSB,Data); | ||
1454 | Data = 0x00; | ||
1455 | status = 0; | ||
1456 | status = mos7840_get_uart_reg(port, DIVISOR_LATCH_LSB, &Data); | ||
1457 | dbg("mos7840_write:DLL value is %x\n", Data); | ||
1458 | |||
1459 | Data = 0x0; | ||
1460 | status = 0; | ||
1461 | status = mos7840_get_uart_reg(port, DIVISOR_LATCH_MSB, &Data); | ||
1462 | dbg("mos7840_write:DLM value is %x\n", Data); | ||
1463 | |||
1464 | Data = Data & ~SERIAL_LCR_DLAB; | ||
1465 | dbg("mos7840_write: mos7840_port->shadowLCR is %x\n", | ||
1466 | mos7840_port->shadowLCR); | ||
1467 | status = 0; | ||
1468 | status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); | ||
1469 | #endif | ||
1470 | |||
1471 | if (mos7840_port_paranoia_check(port, __FUNCTION__)) { | ||
1472 | dbg("%s", "Port Paranoia failed \n"); | ||
1473 | return -1; | ||
1474 | } | ||
1475 | |||
1476 | serial = port->serial; | ||
1477 | if (mos7840_serial_paranoia_check(serial, __FUNCTION__)) { | ||
1478 | dbg("%s", "Serial Paranoia failed \n"); | ||
1479 | return -1; | ||
1480 | } | ||
1481 | |||
1482 | mos7840_port = mos7840_get_port_private(port); | ||
1483 | if (mos7840_port == NULL) { | ||
1484 | dbg("%s", "mos7840_port is NULL\n"); | ||
1485 | return -1; | ||
1486 | } | ||
1487 | |||
1488 | /* try to find a free urb in the list */ | ||
1489 | urb = NULL; | ||
1490 | |||
1491 | for (i = 0; i < NUM_URBS; ++i) { | ||
1492 | if (mos7840_port->write_urb_pool[i]->status != -EINPROGRESS) { | ||
1493 | urb = mos7840_port->write_urb_pool[i]; | ||
1494 | dbg("\nURB:%d", i); | ||
1495 | break; | ||
1496 | } | ||
1497 | } | ||
1498 | |||
1499 | if (urb == NULL) { | ||
1500 | dbg("%s - no more free urbs", __FUNCTION__); | ||
1501 | goto exit; | ||
1502 | } | ||
1503 | |||
1504 | if (urb->transfer_buffer == NULL) { | ||
1505 | urb->transfer_buffer = | ||
1506 | kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL); | ||
1507 | |||
1508 | if (urb->transfer_buffer == NULL) { | ||
1509 | err("%s no more kernel memory...", __FUNCTION__); | ||
1510 | goto exit; | ||
1511 | } | ||
1512 | } | ||
1513 | transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE); | ||
1514 | |||
1515 | if (from_user) { | ||
1516 | if (copy_from_user | ||
1517 | (urb->transfer_buffer, current_position, transfer_size)) { | ||
1518 | bytes_sent = -EFAULT; | ||
1519 | goto exit; | ||
1520 | } | ||
1521 | } else { | ||
1522 | memcpy(urb->transfer_buffer, current_position, transfer_size); | ||
1523 | } | ||
1524 | |||
1525 | /* fill urb with data and submit */ | ||
1526 | usb_fill_bulk_urb(urb, | ||
1527 | serial->dev, | ||
1528 | usb_sndbulkpipe(serial->dev, | ||
1529 | port->bulk_out_endpointAddress), | ||
1530 | urb->transfer_buffer, | ||
1531 | transfer_size, | ||
1532 | mos7840_bulk_out_data_callback, mos7840_port); | ||
1533 | |||
1534 | data1 = urb->transfer_buffer; | ||
1535 | dbg("\nbulkout endpoint is %d", port->bulk_out_endpointAddress); | ||
1536 | |||
1537 | /* send it down the pipe */ | ||
1538 | status = usb_submit_urb(urb, GFP_ATOMIC); | ||
1539 | |||
1540 | if (status) { | ||
1541 | err("%s - usb_submit_urb(write bulk) failed with status = %d", | ||
1542 | __FUNCTION__, status); | ||
1543 | bytes_sent = status; | ||
1544 | goto exit; | ||
1545 | } | ||
1546 | bytes_sent = transfer_size; | ||
1547 | mos7840_port->icount.tx += transfer_size; | ||
1548 | dbg("mos7840_port->icount.tx is %d:\n", mos7840_port->icount.tx); | ||
1549 | exit: | ||
1550 | |||
1551 | return bytes_sent; | ||
1552 | |||
1553 | } | ||
1554 | |||
1555 | /***************************************************************************** | ||
1556 | * mos7840_throttle | ||
1557 | * this function is called by the tty driver when it wants to stop the data | ||
1558 | * being read from the port. | ||
1559 | *****************************************************************************/ | ||
1560 | |||
1561 | static void mos7840_throttle(struct usb_serial_port *port) | ||
1562 | { | ||
1563 | struct moschip_port *mos7840_port; | ||
1564 | struct tty_struct *tty; | ||
1565 | int status; | ||
1566 | |||
1567 | if (mos7840_port_paranoia_check(port, __FUNCTION__)) { | ||
1568 | dbg("%s", "Invalid port \n"); | ||
1569 | return; | ||
1570 | } | ||
1571 | |||
1572 | dbg("- port %d\n", port->number); | ||
1573 | |||
1574 | mos7840_port = mos7840_get_port_private(port); | ||
1575 | |||
1576 | if (mos7840_port == NULL) | ||
1577 | return; | ||
1578 | |||
1579 | if (!mos7840_port->open) { | ||
1580 | dbg("%s\n", "port not opened"); | ||
1581 | return; | ||
1582 | } | ||
1583 | |||
1584 | dbg("%s", "Entering .......... \n"); | ||
1585 | |||
1586 | tty = port->tty; | ||
1587 | if (!tty) { | ||
1588 | dbg("%s - no tty available", __FUNCTION__); | ||
1589 | return; | ||
1590 | } | ||
1591 | |||
1592 | /* if we are implementing XON/XOFF, send the stop character */ | ||
1593 | if (I_IXOFF(tty)) { | ||
1594 | unsigned char stop_char = STOP_CHAR(tty); | ||
1595 | status = mos7840_write(port, &stop_char, 1); | ||
1596 | if (status <= 0) { | ||
1597 | return; | ||
1598 | } | ||
1599 | } | ||
1600 | |||
1601 | /* if we are implementing RTS/CTS, toggle that line */ | ||
1602 | if (tty->termios->c_cflag & CRTSCTS) { | ||
1603 | mos7840_port->shadowMCR &= ~MCR_RTS; | ||
1604 | status = 0; | ||
1605 | status = | ||
1606 | mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, | ||
1607 | mos7840_port->shadowMCR); | ||
1608 | |||
1609 | if (status < 0) { | ||
1610 | return; | ||
1611 | } | ||
1612 | } | ||
1613 | |||
1614 | return; | ||
1615 | } | ||
1616 | |||
1617 | /***************************************************************************** | ||
1618 | * mos7840_unthrottle | ||
1619 | * this function is called by the tty driver when it wants to resume the data | ||
1620 | * being read from the port (called after SerialThrottle is called) | ||
1621 | *****************************************************************************/ | ||
1622 | static void mos7840_unthrottle(struct usb_serial_port *port) | ||
1623 | { | ||
1624 | struct tty_struct *tty; | ||
1625 | int status; | ||
1626 | struct moschip_port *mos7840_port = mos7840_get_port_private(port); | ||
1627 | |||
1628 | if (mos7840_port_paranoia_check(port, __FUNCTION__)) { | ||
1629 | dbg("%s", "Invalid port \n"); | ||
1630 | return; | ||
1631 | } | ||
1632 | |||
1633 | if (mos7840_port == NULL) | ||
1634 | return; | ||
1635 | |||
1636 | if (!mos7840_port->open) { | ||
1637 | dbg("%s - port not opened", __FUNCTION__); | ||
1638 | return; | ||
1639 | } | ||
1640 | |||
1641 | dbg("%s", "Entering .......... \n"); | ||
1642 | |||
1643 | tty = port->tty; | ||
1644 | if (!tty) { | ||
1645 | dbg("%s - no tty available", __FUNCTION__); | ||
1646 | return; | ||
1647 | } | ||
1648 | |||
1649 | /* if we are implementing XON/XOFF, send the start character */ | ||
1650 | if (I_IXOFF(tty)) { | ||
1651 | unsigned char start_char = START_CHAR(tty); | ||
1652 | status = mos7840_write(port, &start_char, 1); | ||
1653 | if (status <= 0) { | ||
1654 | return; | ||
1655 | } | ||
1656 | } | ||
1657 | |||
1658 | /* if we are implementing RTS/CTS, toggle that line */ | ||
1659 | if (tty->termios->c_cflag & CRTSCTS) { | ||
1660 | mos7840_port->shadowMCR |= MCR_RTS; | ||
1661 | status = 0; | ||
1662 | status = | ||
1663 | mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, | ||
1664 | mos7840_port->shadowMCR); | ||
1665 | if (status < 0) { | ||
1666 | return; | ||
1667 | } | ||
1668 | } | ||
1669 | |||
1670 | return; | ||
1671 | } | ||
1672 | |||
1673 | static int mos7840_tiocmget(struct usb_serial_port *port, struct file *file) | ||
1674 | { | ||
1675 | struct moschip_port *mos7840_port; | ||
1676 | unsigned int result; | ||
1677 | __u16 msr; | ||
1678 | __u16 mcr; | ||
1679 | int status = 0; | ||
1680 | mos7840_port = mos7840_get_port_private(port); | ||
1681 | |||
1682 | dbg("%s - port %d", __FUNCTION__, port->number); | ||
1683 | |||
1684 | if (mos7840_port == NULL) | ||
1685 | return -ENODEV; | ||
1686 | |||
1687 | status = mos7840_get_uart_reg(port, MODEM_STATUS_REGISTER, &msr); | ||
1688 | status = mos7840_get_uart_reg(port, MODEM_CONTROL_REGISTER, &mcr); | ||
1689 | result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0) | ||
1690 | | ((mcr & MCR_RTS) ? TIOCM_RTS : 0) | ||
1691 | | ((mcr & MCR_LOOPBACK) ? TIOCM_LOOP : 0) | ||
1692 | | ((msr & MOS7840_MSR_CTS) ? TIOCM_CTS : 0) | ||
1693 | | ((msr & MOS7840_MSR_CD) ? TIOCM_CAR : 0) | ||
1694 | | ((msr & MOS7840_MSR_RI) ? TIOCM_RI : 0) | ||
1695 | | ((msr & MOS7840_MSR_DSR) ? TIOCM_DSR : 0); | ||
1696 | |||
1697 | dbg("%s - 0x%04X", __FUNCTION__, result); | ||
1698 | |||
1699 | return result; | ||
1700 | } | ||
1701 | |||
1702 | static int mos7840_tiocmset(struct usb_serial_port *port, struct file *file, | ||
1703 | unsigned int set, unsigned int clear) | ||
1704 | { | ||
1705 | struct moschip_port *mos7840_port; | ||
1706 | unsigned int mcr; | ||
1707 | unsigned int status; | ||
1708 | |||
1709 | dbg("%s - port %d", __FUNCTION__, port->number); | ||
1710 | |||
1711 | mos7840_port = mos7840_get_port_private(port); | ||
1712 | |||
1713 | if (mos7840_port == NULL) | ||
1714 | return -ENODEV; | ||
1715 | |||
1716 | mcr = mos7840_port->shadowMCR; | ||
1717 | if (clear & TIOCM_RTS) | ||
1718 | mcr &= ~MCR_RTS; | ||
1719 | if (clear & TIOCM_DTR) | ||
1720 | mcr &= ~MCR_DTR; | ||
1721 | if (clear & TIOCM_LOOP) | ||
1722 | mcr &= ~MCR_LOOPBACK; | ||
1723 | |||
1724 | if (set & TIOCM_RTS) | ||
1725 | mcr |= MCR_RTS; | ||
1726 | if (set & TIOCM_DTR) | ||
1727 | mcr |= MCR_DTR; | ||
1728 | if (set & TIOCM_LOOP) | ||
1729 | mcr |= MCR_LOOPBACK; | ||
1730 | |||
1731 | mos7840_port->shadowMCR = mcr; | ||
1732 | |||
1733 | status = 0; | ||
1734 | status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, mcr); | ||
1735 | if (status < 0) { | ||
1736 | dbg("setting MODEM_CONTROL_REGISTER Failed\n"); | ||
1737 | return -1; | ||
1738 | } | ||
1739 | |||
1740 | return 0; | ||
1741 | } | ||
1742 | |||
1743 | /***************************************************************************** | ||
1744 | * mos7840_calc_baud_rate_divisor | ||
1745 | * this function calculates the proper baud rate divisor for the specified | ||
1746 | * baud rate. | ||
1747 | *****************************************************************************/ | ||
1748 | static int mos7840_calc_baud_rate_divisor(int baudRate, int *divisor, | ||
1749 | __u16 * clk_sel_val) | ||
1750 | { | ||
1751 | |||
1752 | dbg("%s - %d", __FUNCTION__, baudRate); | ||
1753 | |||
1754 | if (baudRate <= 115200) { | ||
1755 | *divisor = 115200 / baudRate; | ||
1756 | *clk_sel_val = 0x0; | ||
1757 | } | ||
1758 | if ((baudRate > 115200) && (baudRate <= 230400)) { | ||
1759 | *divisor = 230400 / baudRate; | ||
1760 | *clk_sel_val = 0x10; | ||
1761 | } else if ((baudRate > 230400) && (baudRate <= 403200)) { | ||
1762 | *divisor = 403200 / baudRate; | ||
1763 | *clk_sel_val = 0x20; | ||
1764 | } else if ((baudRate > 403200) && (baudRate <= 460800)) { | ||
1765 | *divisor = 460800 / baudRate; | ||
1766 | *clk_sel_val = 0x30; | ||
1767 | } else if ((baudRate > 460800) && (baudRate <= 806400)) { | ||
1768 | *divisor = 806400 / baudRate; | ||
1769 | *clk_sel_val = 0x40; | ||
1770 | } else if ((baudRate > 806400) && (baudRate <= 921600)) { | ||
1771 | *divisor = 921600 / baudRate; | ||
1772 | *clk_sel_val = 0x50; | ||
1773 | } else if ((baudRate > 921600) && (baudRate <= 1572864)) { | ||
1774 | *divisor = 1572864 / baudRate; | ||
1775 | *clk_sel_val = 0x60; | ||
1776 | } else if ((baudRate > 1572864) && (baudRate <= 3145728)) { | ||
1777 | *divisor = 3145728 / baudRate; | ||
1778 | *clk_sel_val = 0x70; | ||
1779 | } | ||
1780 | return 0; | ||
1781 | |||
1782 | #ifdef NOTMCS7840 | ||
1783 | |||
1784 | for (i = 0; i < ARRAY_SIZE(mos7840_divisor_table); i++) { | ||
1785 | if (mos7840_divisor_table[i].BaudRate == baudrate) { | ||
1786 | *divisor = mos7840_divisor_table[i].Divisor; | ||
1787 | return 0; | ||
1788 | } | ||
1789 | } | ||
1790 | |||
1791 | /* After trying for all the standard baud rates * | ||
1792 | * Try calculating the divisor for this baud rate */ | ||
1793 | |||
1794 | if (baudrate > 75 && baudrate < 230400) { | ||
1795 | /* get the divisor */ | ||
1796 | custom = (__u16) (230400L / baudrate); | ||
1797 | |||
1798 | /* Check for round off */ | ||
1799 | round1 = (__u16) (2304000L / baudrate); | ||
1800 | round = (__u16) (round1 - (custom * 10)); | ||
1801 | if (round > 4) { | ||
1802 | custom++; | ||
1803 | } | ||
1804 | *divisor = custom; | ||
1805 | |||
1806 | dbg(" Baud %d = %d\n", baudrate, custom); | ||
1807 | return 0; | ||
1808 | } | ||
1809 | |||
1810 | dbg("%s\n", " Baud calculation Failed..."); | ||
1811 | return -1; | ||
1812 | #endif | ||
1813 | } | ||
1814 | |||
1815 | /***************************************************************************** | ||
1816 | * mos7840_send_cmd_write_baud_rate | ||
1817 | * this function sends the proper command to change the baud rate of the | ||
1818 | * specified port. | ||
1819 | *****************************************************************************/ | ||
1820 | |||
1821 | static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port, | ||
1822 | int baudRate) | ||
1823 | { | ||
1824 | int divisor = 0; | ||
1825 | int status; | ||
1826 | __u16 Data; | ||
1827 | unsigned char number; | ||
1828 | __u16 clk_sel_val; | ||
1829 | struct usb_serial_port *port; | ||
1830 | |||
1831 | if (mos7840_port == NULL) | ||
1832 | return -1; | ||
1833 | |||
1834 | port = (struct usb_serial_port *)mos7840_port->port; | ||
1835 | if (mos7840_port_paranoia_check(port, __FUNCTION__)) { | ||
1836 | dbg("%s", "Invalid port \n"); | ||
1837 | return -1; | ||
1838 | } | ||
1839 | |||
1840 | if (mos7840_serial_paranoia_check(port->serial, __FUNCTION__)) { | ||
1841 | dbg("%s", "Invalid Serial \n"); | ||
1842 | return -1; | ||
1843 | } | ||
1844 | |||
1845 | dbg("%s", "Entering .......... \n"); | ||
1846 | |||
1847 | number = mos7840_port->port->number - mos7840_port->port->serial->minor; | ||
1848 | |||
1849 | dbg("%s - port = %d, baud = %d", __FUNCTION__, | ||
1850 | mos7840_port->port->number, baudRate); | ||
1851 | //reset clk_uart_sel in spregOffset | ||
1852 | if (baudRate > 115200) { | ||
1853 | #ifdef HW_flow_control | ||
1854 | //NOTE: need to see the pther register to modify | ||
1855 | //setting h/w flow control bit to 1; | ||
1856 | status = 0; | ||
1857 | Data = 0x2b; | ||
1858 | mos7840_port->shadowMCR = Data; | ||
1859 | status = | ||
1860 | mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); | ||
1861 | if (status < 0) { | ||
1862 | dbg("Writing spreg failed in set_serial_baud\n"); | ||
1863 | return -1; | ||
1864 | } | ||
1865 | #endif | ||
1866 | |||
1867 | } else { | ||
1868 | #ifdef HW_flow_control | ||
1869 | //setting h/w flow control bit to 0; | ||
1870 | status = 0; | ||
1871 | Data = 0xb; | ||
1872 | mos7840_port->shadowMCR = Data; | ||
1873 | status = | ||
1874 | mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); | ||
1875 | if (status < 0) { | ||
1876 | dbg("Writing spreg failed in set_serial_baud\n"); | ||
1877 | return -1; | ||
1878 | } | ||
1879 | #endif | ||
1880 | |||
1881 | } | ||
1882 | |||
1883 | if (1) //baudRate <= 115200) | ||
1884 | { | ||
1885 | clk_sel_val = 0x0; | ||
1886 | Data = 0x0; | ||
1887 | status = 0; | ||
1888 | status = | ||
1889 | mos7840_calc_baud_rate_divisor(baudRate, &divisor, | ||
1890 | &clk_sel_val); | ||
1891 | status = | ||
1892 | mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, | ||
1893 | &Data); | ||
1894 | if (status < 0) { | ||
1895 | dbg("reading spreg failed in set_serial_baud\n"); | ||
1896 | return -1; | ||
1897 | } | ||
1898 | Data = (Data & 0x8f) | clk_sel_val; | ||
1899 | status = 0; | ||
1900 | status = | ||
1901 | mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data); | ||
1902 | if (status < 0) { | ||
1903 | dbg("Writing spreg failed in set_serial_baud\n"); | ||
1904 | return -1; | ||
1905 | } | ||
1906 | /* Calculate the Divisor */ | ||
1907 | |||
1908 | if (status) { | ||
1909 | err("%s - bad baud rate", __FUNCTION__); | ||
1910 | dbg("%s\n", "bad baud rate"); | ||
1911 | return status; | ||
1912 | } | ||
1913 | /* Enable access to divisor latch */ | ||
1914 | Data = mos7840_port->shadowLCR | SERIAL_LCR_DLAB; | ||
1915 | mos7840_port->shadowLCR = Data; | ||
1916 | mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); | ||
1917 | |||
1918 | /* Write the divisor */ | ||
1919 | Data = (unsigned char)(divisor & 0xff); | ||
1920 | dbg("set_serial_baud Value to write DLL is %x\n", Data); | ||
1921 | mos7840_set_uart_reg(port, DIVISOR_LATCH_LSB, Data); | ||
1922 | |||
1923 | Data = (unsigned char)((divisor & 0xff00) >> 8); | ||
1924 | dbg("set_serial_baud Value to write DLM is %x\n", Data); | ||
1925 | mos7840_set_uart_reg(port, DIVISOR_LATCH_MSB, Data); | ||
1926 | |||
1927 | /* Disable access to divisor latch */ | ||
1928 | Data = mos7840_port->shadowLCR & ~SERIAL_LCR_DLAB; | ||
1929 | mos7840_port->shadowLCR = Data; | ||
1930 | mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); | ||
1931 | |||
1932 | } | ||
1933 | |||
1934 | return status; | ||
1935 | } | ||
1936 | |||
1937 | /***************************************************************************** | ||
1938 | * mos7840_change_port_settings | ||
1939 | * This routine is called to set the UART on the device to match | ||
1940 | * the specified new settings. | ||
1941 | *****************************************************************************/ | ||
1942 | |||
1943 | static void mos7840_change_port_settings(struct moschip_port *mos7840_port, | ||
1944 | struct termios *old_termios) | ||
1945 | { | ||
1946 | struct tty_struct *tty; | ||
1947 | int baud; | ||
1948 | unsigned cflag; | ||
1949 | unsigned iflag; | ||
1950 | __u8 lData; | ||
1951 | __u8 lParity; | ||
1952 | __u8 lStop; | ||
1953 | int status; | ||
1954 | __u16 Data; | ||
1955 | struct usb_serial_port *port; | ||
1956 | struct usb_serial *serial; | ||
1957 | |||
1958 | if (mos7840_port == NULL) | ||
1959 | return; | ||
1960 | |||
1961 | port = (struct usb_serial_port *)mos7840_port->port; | ||
1962 | |||
1963 | if (mos7840_port_paranoia_check(port, __FUNCTION__)) { | ||
1964 | dbg("%s", "Invalid port \n"); | ||
1965 | return; | ||
1966 | } | ||
1967 | |||
1968 | if (mos7840_serial_paranoia_check(port->serial, __FUNCTION__)) { | ||
1969 | dbg("%s", "Invalid Serial \n"); | ||
1970 | return; | ||
1971 | } | ||
1972 | |||
1973 | serial = port->serial; | ||
1974 | |||
1975 | dbg("%s - port %d", __FUNCTION__, mos7840_port->port->number); | ||
1976 | |||
1977 | if (!mos7840_port->open) { | ||
1978 | dbg("%s - port not opened", __FUNCTION__); | ||
1979 | return; | ||
1980 | } | ||
1981 | |||
1982 | tty = mos7840_port->port->tty; | ||
1983 | |||
1984 | if ((!tty) || (!tty->termios)) { | ||
1985 | dbg("%s - no tty structures", __FUNCTION__); | ||
1986 | return; | ||
1987 | } | ||
1988 | |||
1989 | dbg("%s", "Entering .......... \n"); | ||
1990 | |||
1991 | lData = LCR_BITS_8; | ||
1992 | lStop = LCR_STOP_1; | ||
1993 | lParity = LCR_PAR_NONE; | ||
1994 | |||
1995 | cflag = tty->termios->c_cflag; | ||
1996 | iflag = tty->termios->c_iflag; | ||
1997 | |||
1998 | /* Change the number of bits */ | ||
1999 | if (cflag & CSIZE) { | ||
2000 | switch (cflag & CSIZE) { | ||
2001 | case CS5: | ||
2002 | lData = LCR_BITS_5; | ||
2003 | break; | ||
2004 | |||
2005 | case CS6: | ||
2006 | lData = LCR_BITS_6; | ||
2007 | break; | ||
2008 | |||
2009 | case CS7: | ||
2010 | lData = LCR_BITS_7; | ||
2011 | break; | ||
2012 | default: | ||
2013 | case CS8: | ||
2014 | lData = LCR_BITS_8; | ||
2015 | break; | ||
2016 | } | ||
2017 | } | ||
2018 | /* Change the Parity bit */ | ||
2019 | if (cflag & PARENB) { | ||
2020 | if (cflag & PARODD) { | ||
2021 | lParity = LCR_PAR_ODD; | ||
2022 | dbg("%s - parity = odd", __FUNCTION__); | ||
2023 | } else { | ||
2024 | lParity = LCR_PAR_EVEN; | ||
2025 | dbg("%s - parity = even", __FUNCTION__); | ||
2026 | } | ||
2027 | |||
2028 | } else { | ||
2029 | dbg("%s - parity = none", __FUNCTION__); | ||
2030 | } | ||
2031 | |||
2032 | if (cflag & CMSPAR) { | ||
2033 | lParity = lParity | 0x20; | ||
2034 | } | ||
2035 | |||
2036 | /* Change the Stop bit */ | ||
2037 | if (cflag & CSTOPB) { | ||
2038 | lStop = LCR_STOP_2; | ||
2039 | dbg("%s - stop bits = 2", __FUNCTION__); | ||
2040 | } else { | ||
2041 | lStop = LCR_STOP_1; | ||
2042 | dbg("%s - stop bits = 1", __FUNCTION__); | ||
2043 | } | ||
2044 | |||
2045 | /* Update the LCR with the correct value */ | ||
2046 | mos7840_port->shadowLCR &= | ||
2047 | ~(LCR_BITS_MASK | LCR_STOP_MASK | LCR_PAR_MASK); | ||
2048 | mos7840_port->shadowLCR |= (lData | lParity | lStop); | ||
2049 | |||
2050 | dbg("mos7840_change_port_settings mos7840_port->shadowLCR is %x\n", | ||
2051 | mos7840_port->shadowLCR); | ||
2052 | /* Disable Interrupts */ | ||
2053 | Data = 0x00; | ||
2054 | mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data); | ||
2055 | |||
2056 | Data = 0x00; | ||
2057 | mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data); | ||
2058 | |||
2059 | Data = 0xcf; | ||
2060 | mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data); | ||
2061 | |||
2062 | /* Send the updated LCR value to the mos7840 */ | ||
2063 | Data = mos7840_port->shadowLCR; | ||
2064 | |||
2065 | mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); | ||
2066 | |||
2067 | Data = 0x00b; | ||
2068 | mos7840_port->shadowMCR = Data; | ||
2069 | mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); | ||
2070 | Data = 0x00b; | ||
2071 | mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); | ||
2072 | |||
2073 | /* set up the MCR register and send it to the mos7840 */ | ||
2074 | |||
2075 | mos7840_port->shadowMCR = MCR_MASTER_IE; | ||
2076 | if (cflag & CBAUD) { | ||
2077 | mos7840_port->shadowMCR |= (MCR_DTR | MCR_RTS); | ||
2078 | } | ||
2079 | |||
2080 | if (cflag & CRTSCTS) { | ||
2081 | mos7840_port->shadowMCR |= (MCR_XON_ANY); | ||
2082 | |||
2083 | } else { | ||
2084 | mos7840_port->shadowMCR &= ~(MCR_XON_ANY); | ||
2085 | } | ||
2086 | |||
2087 | Data = mos7840_port->shadowMCR; | ||
2088 | mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); | ||
2089 | |||
2090 | /* Determine divisor based on baud rate */ | ||
2091 | baud = tty_get_baud_rate(tty); | ||
2092 | |||
2093 | if (!baud) { | ||
2094 | /* pick a default, any default... */ | ||
2095 | dbg("%s\n", "Picked default baud..."); | ||
2096 | baud = 9600; | ||
2097 | } | ||
2098 | |||
2099 | dbg("%s - baud rate = %d", __FUNCTION__, baud); | ||
2100 | status = mos7840_send_cmd_write_baud_rate(mos7840_port, baud); | ||
2101 | |||
2102 | /* Enable Interrupts */ | ||
2103 | Data = 0x0c; | ||
2104 | mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data); | ||
2105 | |||
2106 | if (mos7840_port->read_urb->status != -EINPROGRESS) { | ||
2107 | mos7840_port->read_urb->dev = serial->dev; | ||
2108 | |||
2109 | status = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC); | ||
2110 | |||
2111 | if (status) { | ||
2112 | dbg(" usb_submit_urb(read bulk) failed, status = %d", | ||
2113 | status); | ||
2114 | } | ||
2115 | } | ||
2116 | wake_up(&mos7840_port->delta_msr_wait); | ||
2117 | mos7840_port->delta_msr_cond = 1; | ||
2118 | dbg("mos7840_change_port_settings mos7840_port->shadowLCR is End %x\n", | ||
2119 | mos7840_port->shadowLCR); | ||
2120 | |||
2121 | return; | ||
2122 | } | ||
2123 | |||
2124 | /***************************************************************************** | ||
2125 | * mos7840_set_termios | ||
2126 | * this function is called by the tty driver when it wants to change | ||
2127 | * the termios structure | ||
2128 | *****************************************************************************/ | ||
2129 | |||
2130 | static void mos7840_set_termios(struct usb_serial_port *port, | ||
2131 | struct termios *old_termios) | ||
2132 | { | ||
2133 | int status; | ||
2134 | unsigned int cflag; | ||
2135 | struct usb_serial *serial; | ||
2136 | struct moschip_port *mos7840_port; | ||
2137 | struct tty_struct *tty; | ||
2138 | dbg("mos7840_set_termios: START\n"); | ||
2139 | if (mos7840_port_paranoia_check(port, __FUNCTION__)) { | ||
2140 | dbg("%s", "Invalid port \n"); | ||
2141 | return; | ||
2142 | } | ||
2143 | |||
2144 | serial = port->serial; | ||
2145 | |||
2146 | if (mos7840_serial_paranoia_check(serial, __FUNCTION__)) { | ||
2147 | dbg("%s", "Invalid Serial \n"); | ||
2148 | return; | ||
2149 | } | ||
2150 | |||
2151 | mos7840_port = mos7840_get_port_private(port); | ||
2152 | |||
2153 | if (mos7840_port == NULL) | ||
2154 | return; | ||
2155 | |||
2156 | tty = port->tty; | ||
2157 | |||
2158 | if (!port->tty || !port->tty->termios) { | ||
2159 | dbg("%s - no tty or termios", __FUNCTION__); | ||
2160 | return; | ||
2161 | } | ||
2162 | |||
2163 | if (!mos7840_port->open) { | ||
2164 | dbg("%s - port not opened", __FUNCTION__); | ||
2165 | return; | ||
2166 | } | ||
2167 | |||
2168 | dbg("%s\n", "setting termios - "); | ||
2169 | |||
2170 | cflag = tty->termios->c_cflag; | ||
2171 | |||
2172 | if (!cflag) { | ||
2173 | dbg("%s %s\n", __FUNCTION__, "cflag is NULL"); | ||
2174 | return; | ||
2175 | } | ||
2176 | |||
2177 | /* check that they really want us to change something */ | ||
2178 | if (old_termios) { | ||
2179 | if ((cflag == old_termios->c_cflag) && | ||
2180 | (RELEVANT_IFLAG(tty->termios->c_iflag) == | ||
2181 | RELEVANT_IFLAG(old_termios->c_iflag))) { | ||
2182 | dbg("%s\n", "Nothing to change"); | ||
2183 | return; | ||
2184 | } | ||
2185 | } | ||
2186 | |||
2187 | dbg("%s - clfag %08x iflag %08x", __FUNCTION__, | ||
2188 | tty->termios->c_cflag, RELEVANT_IFLAG(tty->termios->c_iflag)); | ||
2189 | |||
2190 | if (old_termios) { | ||
2191 | dbg("%s - old clfag %08x old iflag %08x", __FUNCTION__, | ||
2192 | old_termios->c_cflag, RELEVANT_IFLAG(old_termios->c_iflag)); | ||
2193 | } | ||
2194 | |||
2195 | dbg("%s - port %d", __FUNCTION__, port->number); | ||
2196 | |||
2197 | /* change the port settings to the new ones specified */ | ||
2198 | |||
2199 | mos7840_change_port_settings(mos7840_port, old_termios); | ||
2200 | |||
2201 | if (!mos7840_port->read_urb) { | ||
2202 | dbg("%s", "URB KILLED !!!!!\n"); | ||
2203 | return; | ||
2204 | } | ||
2205 | |||
2206 | if (mos7840_port->read_urb->status != -EINPROGRESS) { | ||
2207 | mos7840_port->read_urb->dev = serial->dev; | ||
2208 | status = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC); | ||
2209 | if (status) { | ||
2210 | dbg(" usb_submit_urb(read bulk) failed, status = %d", | ||
2211 | status); | ||
2212 | } | ||
2213 | } | ||
2214 | return; | ||
2215 | } | ||
2216 | |||
2217 | /***************************************************************************** | ||
2218 | * mos7840_get_lsr_info - get line status register info | ||
2219 | * | ||
2220 | * Purpose: Let user call ioctl() to get info when the UART physically | ||
2221 | * is emptied. On bus types like RS485, the transmitter must | ||
2222 | * release the bus after transmitting. This must be done when | ||
2223 | * the transmit shift register is empty, not be done when the | ||
2224 | * transmit holding register is empty. This functionality | ||
2225 | * allows an RS485 driver to be written in user space. | ||
2226 | *****************************************************************************/ | ||
2227 | |||
2228 | static int mos7840_get_lsr_info(struct moschip_port *mos7840_port, | ||
2229 | unsigned int *value) | ||
2230 | { | ||
2231 | int count; | ||
2232 | unsigned int result = 0; | ||
2233 | |||
2234 | count = mos7840_chars_in_buffer(mos7840_port->port); | ||
2235 | if (count == 0) { | ||
2236 | dbg("%s -- Empty", __FUNCTION__); | ||
2237 | result = TIOCSER_TEMT; | ||
2238 | } | ||
2239 | |||
2240 | if (copy_to_user(value, &result, sizeof(int))) | ||
2241 | return -EFAULT; | ||
2242 | return 0; | ||
2243 | } | ||
2244 | |||
2245 | /***************************************************************************** | ||
2246 | * mos7840_get_bytes_avail - get number of bytes available | ||
2247 | * | ||
2248 | * Purpose: Let user call ioctl to get the count of number of bytes available. | ||
2249 | *****************************************************************************/ | ||
2250 | |||
2251 | static int mos7840_get_bytes_avail(struct moschip_port *mos7840_port, | ||
2252 | unsigned int *value) | ||
2253 | { | ||
2254 | unsigned int result = 0; | ||
2255 | struct tty_struct *tty = mos7840_port->port->tty; | ||
2256 | |||
2257 | if (!tty) | ||
2258 | return -ENOIOCTLCMD; | ||
2259 | |||
2260 | result = tty->read_cnt; | ||
2261 | |||
2262 | dbg("%s(%d) = %d", __FUNCTION__, mos7840_port->port->number, result); | ||
2263 | if (copy_to_user(value, &result, sizeof(int))) | ||
2264 | return -EFAULT; | ||
2265 | |||
2266 | return -ENOIOCTLCMD; | ||
2267 | } | ||
2268 | |||
2269 | /***************************************************************************** | ||
2270 | * mos7840_set_modem_info | ||
2271 | * function to set modem info | ||
2272 | *****************************************************************************/ | ||
2273 | |||
2274 | static int mos7840_set_modem_info(struct moschip_port *mos7840_port, | ||
2275 | unsigned int cmd, unsigned int *value) | ||
2276 | { | ||
2277 | unsigned int mcr; | ||
2278 | unsigned int arg; | ||
2279 | __u16 Data; | ||
2280 | int status; | ||
2281 | struct usb_serial_port *port; | ||
2282 | |||
2283 | if (mos7840_port == NULL) | ||
2284 | return -1; | ||
2285 | |||
2286 | port = (struct usb_serial_port *)mos7840_port->port; | ||
2287 | if (mos7840_port_paranoia_check(port, __FUNCTION__)) { | ||
2288 | dbg("%s", "Invalid port \n"); | ||
2289 | return -1; | ||
2290 | } | ||
2291 | |||
2292 | mcr = mos7840_port->shadowMCR; | ||
2293 | |||
2294 | if (copy_from_user(&arg, value, sizeof(int))) | ||
2295 | return -EFAULT; | ||
2296 | |||
2297 | switch (cmd) { | ||
2298 | case TIOCMBIS: | ||
2299 | if (arg & TIOCM_RTS) | ||
2300 | mcr |= MCR_RTS; | ||
2301 | if (arg & TIOCM_DTR) | ||
2302 | mcr |= MCR_RTS; | ||
2303 | if (arg & TIOCM_LOOP) | ||
2304 | mcr |= MCR_LOOPBACK; | ||
2305 | break; | ||
2306 | |||
2307 | case TIOCMBIC: | ||
2308 | if (arg & TIOCM_RTS) | ||
2309 | mcr &= ~MCR_RTS; | ||
2310 | if (arg & TIOCM_DTR) | ||
2311 | mcr &= ~MCR_RTS; | ||
2312 | if (arg & TIOCM_LOOP) | ||
2313 | mcr &= ~MCR_LOOPBACK; | ||
2314 | break; | ||
2315 | |||
2316 | case TIOCMSET: | ||
2317 | /* turn off the RTS and DTR and LOOPBACK | ||
2318 | * and then only turn on what was asked to */ | ||
2319 | mcr &= ~(MCR_RTS | MCR_DTR | MCR_LOOPBACK); | ||
2320 | mcr |= ((arg & TIOCM_RTS) ? MCR_RTS : 0); | ||
2321 | mcr |= ((arg & TIOCM_DTR) ? MCR_DTR : 0); | ||
2322 | mcr |= ((arg & TIOCM_LOOP) ? MCR_LOOPBACK : 0); | ||
2323 | break; | ||
2324 | } | ||
2325 | |||
2326 | mos7840_port->shadowMCR = mcr; | ||
2327 | |||
2328 | Data = mos7840_port->shadowMCR; | ||
2329 | status = 0; | ||
2330 | status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); | ||
2331 | if (status < 0) { | ||
2332 | dbg("setting MODEM_CONTROL_REGISTER Failed\n"); | ||
2333 | return -1; | ||
2334 | } | ||
2335 | |||
2336 | return 0; | ||
2337 | } | ||
2338 | |||
2339 | /***************************************************************************** | ||
2340 | * mos7840_get_modem_info | ||
2341 | * function to get modem info | ||
2342 | *****************************************************************************/ | ||
2343 | |||
2344 | static int mos7840_get_modem_info(struct moschip_port *mos7840_port, | ||
2345 | unsigned int *value) | ||
2346 | { | ||
2347 | unsigned int result = 0; | ||
2348 | __u16 msr; | ||
2349 | unsigned int mcr = mos7840_port->shadowMCR; | ||
2350 | int status = 0; | ||
2351 | status = | ||
2352 | mos7840_get_uart_reg(mos7840_port->port, MODEM_STATUS_REGISTER, | ||
2353 | &msr); | ||
2354 | result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0) /* 0x002 */ | ||
2355 | |((mcr & MCR_RTS) ? TIOCM_RTS : 0) /* 0x004 */ | ||
2356 | |((msr & MOS7840_MSR_CTS) ? TIOCM_CTS : 0) /* 0x020 */ | ||
2357 | |((msr & MOS7840_MSR_CD) ? TIOCM_CAR : 0) /* 0x040 */ | ||
2358 | |((msr & MOS7840_MSR_RI) ? TIOCM_RI : 0) /* 0x080 */ | ||
2359 | |((msr & MOS7840_MSR_DSR) ? TIOCM_DSR : 0); /* 0x100 */ | ||
2360 | |||
2361 | dbg("%s -- %x", __FUNCTION__, result); | ||
2362 | |||
2363 | if (copy_to_user(value, &result, sizeof(int))) | ||
2364 | return -EFAULT; | ||
2365 | return 0; | ||
2366 | } | ||
2367 | |||
2368 | /***************************************************************************** | ||
2369 | * mos7840_get_serial_info | ||
2370 | * function to get information about serial port | ||
2371 | *****************************************************************************/ | ||
2372 | |||
2373 | static int mos7840_get_serial_info(struct moschip_port *mos7840_port, | ||
2374 | struct serial_struct *retinfo) | ||
2375 | { | ||
2376 | struct serial_struct tmp; | ||
2377 | |||
2378 | if (mos7840_port == NULL) | ||
2379 | return -1; | ||
2380 | |||
2381 | if (!retinfo) | ||
2382 | return -EFAULT; | ||
2383 | |||
2384 | memset(&tmp, 0, sizeof(tmp)); | ||
2385 | |||
2386 | tmp.type = PORT_16550A; | ||
2387 | tmp.line = mos7840_port->port->serial->minor; | ||
2388 | tmp.port = mos7840_port->port->number; | ||
2389 | tmp.irq = 0; | ||
2390 | tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ; | ||
2391 | tmp.xmit_fifo_size = NUM_URBS * URB_TRANSFER_BUFFER_SIZE; | ||
2392 | tmp.baud_base = 9600; | ||
2393 | tmp.close_delay = 5 * HZ; | ||
2394 | tmp.closing_wait = 30 * HZ; | ||
2395 | |||
2396 | if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) | ||
2397 | return -EFAULT; | ||
2398 | return 0; | ||
2399 | } | ||
2400 | |||
2401 | /***************************************************************************** | ||
2402 | * SerialIoctl | ||
2403 | * this function handles any ioctl calls to the driver | ||
2404 | *****************************************************************************/ | ||
2405 | |||
2406 | static int mos7840_ioctl(struct usb_serial_port *port, struct file *file, | ||
2407 | unsigned int cmd, unsigned long arg) | ||
2408 | { | ||
2409 | struct moschip_port *mos7840_port; | ||
2410 | struct tty_struct *tty; | ||
2411 | |||
2412 | struct async_icount cnow; | ||
2413 | struct async_icount cprev; | ||
2414 | struct serial_icounter_struct icount; | ||
2415 | int mosret = 0; | ||
2416 | int retval; | ||
2417 | struct tty_ldisc *ld; | ||
2418 | |||
2419 | if (mos7840_port_paranoia_check(port, __FUNCTION__)) { | ||
2420 | dbg("%s", "Invalid port \n"); | ||
2421 | return -1; | ||
2422 | } | ||
2423 | |||
2424 | mos7840_port = mos7840_get_port_private(port); | ||
2425 | tty = mos7840_port->port->tty; | ||
2426 | |||
2427 | if (mos7840_port == NULL) | ||
2428 | return -1; | ||
2429 | |||
2430 | dbg("%s - port %d, cmd = 0x%x", __FUNCTION__, port->number, cmd); | ||
2431 | |||
2432 | switch (cmd) { | ||
2433 | /* return number of bytes available */ | ||
2434 | |||
2435 | case TIOCINQ: | ||
2436 | dbg("%s (%d) TIOCINQ", __FUNCTION__, port->number); | ||
2437 | return mos7840_get_bytes_avail(mos7840_port, | ||
2438 | (unsigned int *)arg); | ||
2439 | break; | ||
2440 | |||
2441 | case TIOCOUTQ: | ||
2442 | dbg("%s (%d) TIOCOUTQ", __FUNCTION__, port->number); | ||
2443 | return put_user(tty->driver->chars_in_buffer ? | ||
2444 | tty->driver->chars_in_buffer(tty) : 0, | ||
2445 | (int __user *)arg); | ||
2446 | break; | ||
2447 | |||
2448 | case TCFLSH: | ||
2449 | retval = tty_check_change(tty); | ||
2450 | if (retval) | ||
2451 | return retval; | ||
2452 | |||
2453 | ld = tty_ldisc_ref(tty); | ||
2454 | switch (arg) { | ||
2455 | case TCIFLUSH: | ||
2456 | if (ld && ld->flush_buffer) | ||
2457 | ld->flush_buffer(tty); | ||
2458 | break; | ||
2459 | case TCIOFLUSH: | ||
2460 | if (ld && ld->flush_buffer) | ||
2461 | ld->flush_buffer(tty); | ||
2462 | /* fall through */ | ||
2463 | case TCOFLUSH: | ||
2464 | if (tty->driver->flush_buffer) | ||
2465 | tty->driver->flush_buffer(tty); | ||
2466 | break; | ||
2467 | default: | ||
2468 | tty_ldisc_deref(ld); | ||
2469 | return -EINVAL; | ||
2470 | } | ||
2471 | tty_ldisc_deref(ld); | ||
2472 | return 0; | ||
2473 | |||
2474 | case TCGETS: | ||
2475 | if (kernel_termios_to_user_termios | ||
2476 | ((struct termios __user *)arg, tty->termios)) | ||
2477 | return -EFAULT; | ||
2478 | return 0; | ||
2479 | |||
2480 | case TIOCSERGETLSR: | ||
2481 | dbg("%s (%d) TIOCSERGETLSR", __FUNCTION__, port->number); | ||
2482 | return mos7840_get_lsr_info(mos7840_port, (unsigned int *)arg); | ||
2483 | return 0; | ||
2484 | |||
2485 | case TIOCMBIS: | ||
2486 | case TIOCMBIC: | ||
2487 | case TIOCMSET: | ||
2488 | dbg("%s (%d) TIOCMSET/TIOCMBIC/TIOCMSET", __FUNCTION__, | ||
2489 | port->number); | ||
2490 | mosret = | ||
2491 | mos7840_set_modem_info(mos7840_port, cmd, | ||
2492 | (unsigned int *)arg); | ||
2493 | return mosret; | ||
2494 | |||
2495 | case TIOCMGET: | ||
2496 | dbg("%s (%d) TIOCMGET", __FUNCTION__, port->number); | ||
2497 | return mos7840_get_modem_info(mos7840_port, | ||
2498 | (unsigned int *)arg); | ||
2499 | |||
2500 | case TIOCGSERIAL: | ||
2501 | dbg("%s (%d) TIOCGSERIAL", __FUNCTION__, port->number); | ||
2502 | return mos7840_get_serial_info(mos7840_port, | ||
2503 | (struct serial_struct *)arg); | ||
2504 | |||
2505 | case TIOCSSERIAL: | ||
2506 | dbg("%s (%d) TIOCSSERIAL", __FUNCTION__, port->number); | ||
2507 | break; | ||
2508 | |||
2509 | case TIOCMIWAIT: | ||
2510 | dbg("%s (%d) TIOCMIWAIT", __FUNCTION__, port->number); | ||
2511 | cprev = mos7840_port->icount; | ||
2512 | while (1) { | ||
2513 | //interruptible_sleep_on(&mos7840_port->delta_msr_wait); | ||
2514 | mos7840_port->delta_msr_cond = 0; | ||
2515 | wait_event_interruptible(mos7840_port->delta_msr_wait, | ||
2516 | (mos7840_port-> | ||
2517 | delta_msr_cond == 1)); | ||
2518 | |||
2519 | /* see if a signal did it */ | ||
2520 | if (signal_pending(current)) | ||
2521 | return -ERESTARTSYS; | ||
2522 | cnow = mos7840_port->icount; | ||
2523 | if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr && | ||
2524 | cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) | ||
2525 | return -EIO; /* no change => error */ | ||
2526 | if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) || | ||
2527 | ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) || | ||
2528 | ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) || | ||
2529 | ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) { | ||
2530 | return 0; | ||
2531 | } | ||
2532 | cprev = cnow; | ||
2533 | } | ||
2534 | /* NOTREACHED */ | ||
2535 | break; | ||
2536 | |||
2537 | case TIOCGICOUNT: | ||
2538 | cnow = mos7840_port->icount; | ||
2539 | icount.cts = cnow.cts; | ||
2540 | icount.dsr = cnow.dsr; | ||
2541 | icount.rng = cnow.rng; | ||
2542 | icount.dcd = cnow.dcd; | ||
2543 | icount.rx = cnow.rx; | ||
2544 | icount.tx = cnow.tx; | ||
2545 | icount.frame = cnow.frame; | ||
2546 | icount.overrun = cnow.overrun; | ||
2547 | icount.parity = cnow.parity; | ||
2548 | icount.brk = cnow.brk; | ||
2549 | icount.buf_overrun = cnow.buf_overrun; | ||
2550 | |||
2551 | dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __FUNCTION__, | ||
2552 | port->number, icount.rx, icount.tx); | ||
2553 | if (copy_to_user((void *)arg, &icount, sizeof(icount))) | ||
2554 | return -EFAULT; | ||
2555 | return 0; | ||
2556 | |||
2557 | case TIOCEXBAUD: | ||
2558 | return 0; | ||
2559 | default: | ||
2560 | break; | ||
2561 | } | ||
2562 | |||
2563 | return -ENOIOCTLCMD; | ||
2564 | } | ||
2565 | |||
2566 | static int mos7840_calc_num_ports(struct usb_serial *serial) | ||
2567 | { | ||
2568 | |||
2569 | dbg("numberofendpoints: %d \n", | ||
2570 | (int)serial->interface->cur_altsetting->desc.bNumEndpoints); | ||
2571 | dbg("numberofendpoints: %d \n", | ||
2572 | (int)serial->interface->altsetting->desc.bNumEndpoints); | ||
2573 | if (serial->interface->cur_altsetting->desc.bNumEndpoints == 5) { | ||
2574 | mos7840_num_ports = 2; | ||
2575 | serial->type->num_ports = 2; | ||
2576 | } else if (serial->interface->cur_altsetting->desc.bNumEndpoints == 9) { | ||
2577 | mos7840_num_ports = 4; | ||
2578 | serial->type->num_bulk_in = 4; | ||
2579 | serial->type->num_bulk_out = 4; | ||
2580 | serial->type->num_ports = 4; | ||
2581 | } | ||
2582 | |||
2583 | return mos7840_num_ports; | ||
2584 | } | ||
2585 | |||
2586 | /**************************************************************************** | ||
2587 | * mos7840_startup | ||
2588 | ****************************************************************************/ | ||
2589 | |||
2590 | static int mos7840_startup(struct usb_serial *serial) | ||
2591 | { | ||
2592 | struct moschip_port *mos7840_port; | ||
2593 | struct usb_device *dev; | ||
2594 | int i, status; | ||
2595 | |||
2596 | __u16 Data; | ||
2597 | dbg("%s \n", " mos7840_startup :entering.........."); | ||
2598 | |||
2599 | if (!serial) { | ||
2600 | dbg("%s\n", "Invalid Handler"); | ||
2601 | return -1; | ||
2602 | } | ||
2603 | |||
2604 | dev = serial->dev; | ||
2605 | |||
2606 | dbg("%s\n", "Entering..."); | ||
2607 | |||
2608 | /* we set up the pointers to the endpoints in the mos7840_open * | ||
2609 | * function, as the structures aren't created yet. */ | ||
2610 | |||
2611 | /* set up port private structures */ | ||
2612 | for (i = 0; i < serial->num_ports; ++i) { | ||
2613 | mos7840_port = kmalloc(sizeof(struct moschip_port), GFP_KERNEL); | ||
2614 | if (mos7840_port == NULL) { | ||
2615 | err("%s - Out of memory", __FUNCTION__); | ||
2616 | return -ENOMEM; | ||
2617 | } | ||
2618 | memset(mos7840_port, 0, sizeof(struct moschip_port)); | ||
2619 | |||
2620 | /* Initialize all port interrupt end point to port 0 int endpoint * | ||
2621 | * Our device has only one interrupt end point comman to all port */ | ||
2622 | |||
2623 | mos7840_port->port = serial->port[i]; | ||
2624 | mos7840_set_port_private(serial->port[i], mos7840_port); | ||
2625 | |||
2626 | mos7840_port->port_num = ((serial->port[i]->number - | ||
2627 | (serial->port[i]->serial->minor)) + | ||
2628 | 1); | ||
2629 | |||
2630 | if (mos7840_port->port_num == 1) { | ||
2631 | mos7840_port->SpRegOffset = 0x0; | ||
2632 | mos7840_port->ControlRegOffset = 0x1; | ||
2633 | mos7840_port->DcrRegOffset = 0x4; | ||
2634 | } else if ((mos7840_port->port_num == 2) | ||
2635 | && (mos7840_num_ports == 4)) { | ||
2636 | mos7840_port->SpRegOffset = 0x8; | ||
2637 | mos7840_port->ControlRegOffset = 0x9; | ||
2638 | mos7840_port->DcrRegOffset = 0x16; | ||
2639 | } else if ((mos7840_port->port_num == 2) | ||
2640 | && (mos7840_num_ports == 2)) { | ||
2641 | mos7840_port->SpRegOffset = 0xa; | ||
2642 | mos7840_port->ControlRegOffset = 0xb; | ||
2643 | mos7840_port->DcrRegOffset = 0x19; | ||
2644 | } else if ((mos7840_port->port_num == 3) | ||
2645 | && (mos7840_num_ports == 4)) { | ||
2646 | mos7840_port->SpRegOffset = 0xa; | ||
2647 | mos7840_port->ControlRegOffset = 0xb; | ||
2648 | mos7840_port->DcrRegOffset = 0x19; | ||
2649 | } else if ((mos7840_port->port_num == 4) | ||
2650 | && (mos7840_num_ports == 4)) { | ||
2651 | mos7840_port->SpRegOffset = 0xc; | ||
2652 | mos7840_port->ControlRegOffset = 0xd; | ||
2653 | mos7840_port->DcrRegOffset = 0x1c; | ||
2654 | } | ||
2655 | mos7840_dump_serial_port(mos7840_port); | ||
2656 | |||
2657 | mos7840_set_port_private(serial->port[i], mos7840_port); | ||
2658 | |||
2659 | //enable rx_disable bit in control register | ||
2660 | |||
2661 | status = | ||
2662 | mos7840_get_reg_sync(serial->port[i], | ||
2663 | mos7840_port->ControlRegOffset, &Data); | ||
2664 | if (status < 0) { | ||
2665 | dbg("Reading ControlReg failed status-0x%x\n", status); | ||
2666 | break; | ||
2667 | } else | ||
2668 | dbg("ControlReg Reading success val is %x, status%d\n", | ||
2669 | Data, status); | ||
2670 | Data |= 0x08; //setting driver done bit | ||
2671 | Data |= 0x04; //sp1_bit to have cts change reflect in modem status reg | ||
2672 | |||
2673 | //Data |= 0x20; //rx_disable bit | ||
2674 | status = 0; | ||
2675 | status = | ||
2676 | mos7840_set_reg_sync(serial->port[i], | ||
2677 | mos7840_port->ControlRegOffset, Data); | ||
2678 | if (status < 0) { | ||
2679 | dbg("Writing ControlReg failed(rx_disable) status-0x%x\n", status); | ||
2680 | break; | ||
2681 | } else | ||
2682 | dbg("ControlReg Writing success(rx_disable) status%d\n", | ||
2683 | status); | ||
2684 | |||
2685 | //Write default values in DCR (i.e 0x01 in DCR0, 0x05 in DCR2 and 0x24 in DCR3 | ||
2686 | Data = 0x01; | ||
2687 | status = 0; | ||
2688 | status = | ||
2689 | mos7840_set_reg_sync(serial->port[i], | ||
2690 | (__u16) (mos7840_port->DcrRegOffset + | ||
2691 | 0), Data); | ||
2692 | if (status < 0) { | ||
2693 | dbg("Writing DCR0 failed status-0x%x\n", status); | ||
2694 | break; | ||
2695 | } else | ||
2696 | dbg("DCR0 Writing success status%d\n", status); | ||
2697 | |||
2698 | Data = 0x05; | ||
2699 | status = 0; | ||
2700 | status = | ||
2701 | mos7840_set_reg_sync(serial->port[i], | ||
2702 | (__u16) (mos7840_port->DcrRegOffset + | ||
2703 | 1), Data); | ||
2704 | if (status < 0) { | ||
2705 | dbg("Writing DCR1 failed status-0x%x\n", status); | ||
2706 | break; | ||
2707 | } else | ||
2708 | dbg("DCR1 Writing success status%d\n", status); | ||
2709 | |||
2710 | Data = 0x24; | ||
2711 | status = 0; | ||
2712 | status = | ||
2713 | mos7840_set_reg_sync(serial->port[i], | ||
2714 | (__u16) (mos7840_port->DcrRegOffset + | ||
2715 | 2), Data); | ||
2716 | if (status < 0) { | ||
2717 | dbg("Writing DCR2 failed status-0x%x\n", status); | ||
2718 | break; | ||
2719 | } else | ||
2720 | dbg("DCR2 Writing success status%d\n", status); | ||
2721 | |||
2722 | // write values in clkstart0x0 and clkmulti 0x20 | ||
2723 | Data = 0x0; | ||
2724 | status = 0; | ||
2725 | status = | ||
2726 | mos7840_set_reg_sync(serial->port[i], | ||
2727 | CLK_START_VALUE_REGISTER, Data); | ||
2728 | if (status < 0) { | ||
2729 | dbg("Writing CLK_START_VALUE_REGISTER failed status-0x%x\n", status); | ||
2730 | break; | ||
2731 | } else | ||
2732 | dbg("CLK_START_VALUE_REGISTER Writing success status%d\n", status); | ||
2733 | |||
2734 | Data = 0x20; | ||
2735 | status = 0; | ||
2736 | status = | ||
2737 | mos7840_set_reg_sync(serial->port[i], CLK_MULTI_REGISTER, | ||
2738 | Data); | ||
2739 | if (status < 0) { | ||
2740 | dbg("Writing CLK_MULTI_REGISTER failed status-0x%x\n", | ||
2741 | status); | ||
2742 | break; | ||
2743 | } else | ||
2744 | dbg("CLK_MULTI_REGISTER Writing success status%d\n", | ||
2745 | status); | ||
2746 | |||
2747 | //write value 0x0 to scratchpad register | ||
2748 | Data = 0x00; | ||
2749 | status = 0; | ||
2750 | status = | ||
2751 | mos7840_set_uart_reg(serial->port[i], SCRATCH_PAD_REGISTER, | ||
2752 | Data); | ||
2753 | if (status < 0) { | ||
2754 | dbg("Writing SCRATCH_PAD_REGISTER failed status-0x%x\n", | ||
2755 | status); | ||
2756 | break; | ||
2757 | } else | ||
2758 | dbg("SCRATCH_PAD_REGISTER Writing success status%d\n", | ||
2759 | status); | ||
2760 | |||
2761 | //Zero Length flag register | ||
2762 | if ((mos7840_port->port_num != 1) | ||
2763 | && (mos7840_num_ports == 2)) { | ||
2764 | |||
2765 | Data = 0xff; | ||
2766 | status = 0; | ||
2767 | status = mos7840_set_reg_sync(serial->port[i], | ||
2768 | (__u16) (ZLP_REG1 + | ||
2769 | ((__u16) | ||
2770 | mos7840_port-> | ||
2771 | port_num)), | ||
2772 | Data); | ||
2773 | dbg("ZLIP offset%x\n", | ||
2774 | (__u16) (ZLP_REG1 + | ||
2775 | ((__u16) mos7840_port->port_num))); | ||
2776 | if (status < 0) { | ||
2777 | dbg("Writing ZLP_REG%d failed status-0x%x\n", | ||
2778 | i + 2, status); | ||
2779 | break; | ||
2780 | } else | ||
2781 | dbg("ZLP_REG%d Writing success status%d\n", | ||
2782 | i + 2, status); | ||
2783 | } else { | ||
2784 | Data = 0xff; | ||
2785 | status = 0; | ||
2786 | status = mos7840_set_reg_sync(serial->port[i], | ||
2787 | (__u16) (ZLP_REG1 + | ||
2788 | ((__u16) | ||
2789 | mos7840_port-> | ||
2790 | port_num) - | ||
2791 | 0x1), Data); | ||
2792 | dbg("ZLIP offset%x\n", | ||
2793 | (__u16) (ZLP_REG1 + | ||
2794 | ((__u16) mos7840_port->port_num) - 0x1)); | ||
2795 | if (status < 0) { | ||
2796 | dbg("Writing ZLP_REG%d failed status-0x%x\n", | ||
2797 | i + 1, status); | ||
2798 | break; | ||
2799 | } else | ||
2800 | dbg("ZLP_REG%d Writing success status%d\n", | ||
2801 | i + 1, status); | ||
2802 | |||
2803 | } | ||
2804 | mos7840_port->control_urb = usb_alloc_urb(0, SLAB_ATOMIC); | ||
2805 | mos7840_port->ctrl_buf = kmalloc(16, GFP_KERNEL); | ||
2806 | |||
2807 | } | ||
2808 | |||
2809 | //Zero Length flag enable | ||
2810 | Data = 0x0f; | ||
2811 | status = 0; | ||
2812 | status = mos7840_set_reg_sync(serial->port[0], ZLP_REG5, Data); | ||
2813 | if (status < 0) { | ||
2814 | dbg("Writing ZLP_REG5 failed status-0x%x\n", status); | ||
2815 | return -1; | ||
2816 | } else | ||
2817 | dbg("ZLP_REG5 Writing success status%d\n", status); | ||
2818 | |||
2819 | /* setting configuration feature to one */ | ||
2820 | usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), | ||
2821 | (__u8) 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 5 * HZ); | ||
2822 | return 0; | ||
2823 | } | ||
2824 | |||
2825 | /**************************************************************************** | ||
2826 | * mos7840_shutdown | ||
2827 | * This function is called whenever the device is removed from the usb bus. | ||
2828 | ****************************************************************************/ | ||
2829 | |||
2830 | static void mos7840_shutdown(struct usb_serial *serial) | ||
2831 | { | ||
2832 | int i; | ||
2833 | struct moschip_port *mos7840_port; | ||
2834 | dbg("%s \n", " shutdown :entering.........."); | ||
2835 | |||
2836 | if (!serial) { | ||
2837 | dbg("%s", "Invalid Handler \n"); | ||
2838 | return; | ||
2839 | } | ||
2840 | |||
2841 | /* check for the ports to be closed,close the ports and disconnect */ | ||
2842 | |||
2843 | /* free private structure allocated for serial port * | ||
2844 | * stop reads and writes on all ports */ | ||
2845 | |||
2846 | for (i = 0; i < serial->num_ports; ++i) { | ||
2847 | mos7840_port = mos7840_get_port_private(serial->port[i]); | ||
2848 | kfree(mos7840_port->ctrl_buf); | ||
2849 | usb_kill_urb(mos7840_port->control_urb); | ||
2850 | kfree(mos7840_port); | ||
2851 | mos7840_set_port_private(serial->port[i], NULL); | ||
2852 | } | ||
2853 | |||
2854 | dbg("%s\n", "Thank u :: "); | ||
2855 | |||
2856 | } | ||
2857 | |||
2858 | static struct usb_serial_driver moschip7840_4port_device = { | ||
2859 | .driver = { | ||
2860 | .owner = THIS_MODULE, | ||
2861 | .name = "mos7840", | ||
2862 | }, | ||
2863 | .description = DRIVER_DESC, | ||
2864 | .id_table = moschip_port_id_table, | ||
2865 | .num_interrupt_in = 1, //NUM_DONT_CARE,//1, | ||
2866 | #ifdef check | ||
2867 | .num_bulk_in = 4, | ||
2868 | .num_bulk_out = 4, | ||
2869 | .num_ports = 4, | ||
2870 | #endif | ||
2871 | .open = mos7840_open, | ||
2872 | .close = mos7840_close, | ||
2873 | .write = mos7840_write, | ||
2874 | .write_room = mos7840_write_room, | ||
2875 | .chars_in_buffer = mos7840_chars_in_buffer, | ||
2876 | .throttle = mos7840_throttle, | ||
2877 | .unthrottle = mos7840_unthrottle, | ||
2878 | .calc_num_ports = mos7840_calc_num_ports, | ||
2879 | #ifdef MCSSerialProbe | ||
2880 | .probe = mos7840_serial_probe, | ||
2881 | #endif | ||
2882 | .ioctl = mos7840_ioctl, | ||
2883 | .set_termios = mos7840_set_termios, | ||
2884 | .break_ctl = mos7840_break, | ||
2885 | .tiocmget = mos7840_tiocmget, | ||
2886 | .tiocmset = mos7840_tiocmset, | ||
2887 | .attach = mos7840_startup, | ||
2888 | .shutdown = mos7840_shutdown, | ||
2889 | .read_bulk_callback = mos7840_bulk_in_callback, | ||
2890 | .read_int_callback = mos7840_interrupt_callback, | ||
2891 | }; | ||
2892 | |||
2893 | static struct usb_driver io_driver = { | ||
2894 | .name = "mos7840", | ||
2895 | .probe = usb_serial_probe, | ||
2896 | .disconnect = usb_serial_disconnect, | ||
2897 | .id_table = moschip_id_table_combined, | ||
2898 | }; | ||
2899 | |||
2900 | /**************************************************************************** | ||
2901 | * moschip7840_init | ||
2902 | * This is called by the module subsystem, or on startup to initialize us | ||
2903 | ****************************************************************************/ | ||
2904 | static int __init moschip7840_init(void) | ||
2905 | { | ||
2906 | int retval; | ||
2907 | |||
2908 | dbg("%s \n", " mos7840_init :entering.........."); | ||
2909 | |||
2910 | /* Register with the usb serial */ | ||
2911 | retval = usb_serial_register(&moschip7840_4port_device); | ||
2912 | |||
2913 | if (retval) | ||
2914 | goto failed_port_device_register; | ||
2915 | |||
2916 | dbg("%s\n", "Entring..."); | ||
2917 | info(DRIVER_DESC " " DRIVER_VERSION); | ||
2918 | |||
2919 | /* Register with the usb */ | ||
2920 | retval = usb_register(&io_driver); | ||
2921 | |||
2922 | if (retval) | ||
2923 | goto failed_usb_register; | ||
2924 | |||
2925 | if (retval == 0) { | ||
2926 | dbg("%s\n", "Leaving..."); | ||
2927 | return 0; | ||
2928 | } | ||
2929 | |||
2930 | failed_usb_register: | ||
2931 | usb_serial_deregister(&moschip7840_4port_device); | ||
2932 | |||
2933 | failed_port_device_register: | ||
2934 | |||
2935 | return retval; | ||
2936 | } | ||
2937 | |||
2938 | /**************************************************************************** | ||
2939 | * moschip7840_exit | ||
2940 | * Called when the driver is about to be unloaded. | ||
2941 | ****************************************************************************/ | ||
2942 | static void __exit moschip7840_exit(void) | ||
2943 | { | ||
2944 | |||
2945 | dbg("%s \n", " mos7840_exit :entering.........."); | ||
2946 | |||
2947 | usb_deregister(&io_driver); | ||
2948 | |||
2949 | usb_serial_deregister(&moschip7840_4port_device); | ||
2950 | |||
2951 | dbg("%s\n", "Entring..."); | ||
2952 | } | ||
2953 | |||
2954 | module_init(moschip7840_init); | ||
2955 | module_exit(moschip7840_exit); | ||
2956 | |||
2957 | /* Module information */ | ||
2958 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
2959 | MODULE_LICENSE("GPL"); | ||
2960 | |||
2961 | module_param(debug, bool, S_IRUGO | S_IWUSR); | ||
2962 | MODULE_PARM_DESC(debug, "Debug enabled or not"); | ||
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c index 65e4d046951a..1036d436ed23 100644 --- a/drivers/usb/serial/pl2303.c +++ b/drivers/usb/serial/pl2303.c | |||
@@ -81,10 +81,11 @@ static struct usb_device_id id_table [] = { | |||
81 | { USB_DEVICE(SPEEDDRAGON_VENDOR_ID, SPEEDDRAGON_PRODUCT_ID) }, | 81 | { USB_DEVICE(SPEEDDRAGON_VENDOR_ID, SPEEDDRAGON_PRODUCT_ID) }, |
82 | { USB_DEVICE(DATAPILOT_U2_VENDOR_ID, DATAPILOT_U2_PRODUCT_ID) }, | 82 | { USB_DEVICE(DATAPILOT_U2_VENDOR_ID, DATAPILOT_U2_PRODUCT_ID) }, |
83 | { USB_DEVICE(BELKIN_VENDOR_ID, BELKIN_PRODUCT_ID) }, | 83 | { USB_DEVICE(BELKIN_VENDOR_ID, BELKIN_PRODUCT_ID) }, |
84 | { USB_DEVICE(ALCOR_VENDOR_ID, ALCOR_PRODUCT_ID) }, | ||
84 | { } /* Terminating entry */ | 85 | { } /* Terminating entry */ |
85 | }; | 86 | }; |
86 | 87 | ||
87 | MODULE_DEVICE_TABLE (usb, id_table); | 88 | MODULE_DEVICE_TABLE(usb, id_table); |
88 | 89 | ||
89 | static struct usb_driver pl2303_driver = { | 90 | static struct usb_driver pl2303_driver = { |
90 | .name = "pl2303", | 91 | .name = "pl2303", |
@@ -127,65 +128,6 @@ static struct usb_driver pl2303_driver = { | |||
127 | #define UART_OVERRUN_ERROR 0x40 | 128 | #define UART_OVERRUN_ERROR 0x40 |
128 | #define UART_CTS 0x80 | 129 | #define UART_CTS 0x80 |
129 | 130 | ||
130 | /* function prototypes for a PL2303 serial converter */ | ||
131 | static int pl2303_open (struct usb_serial_port *port, struct file *filp); | ||
132 | static void pl2303_close (struct usb_serial_port *port, struct file *filp); | ||
133 | static void pl2303_set_termios (struct usb_serial_port *port, | ||
134 | struct termios *old); | ||
135 | static int pl2303_ioctl (struct usb_serial_port *port, struct file *file, | ||
136 | unsigned int cmd, unsigned long arg); | ||
137 | static void pl2303_read_int_callback (struct urb *urb, struct pt_regs *regs); | ||
138 | static void pl2303_read_bulk_callback (struct urb *urb, struct pt_regs *regs); | ||
139 | static void pl2303_write_bulk_callback (struct urb *urb, struct pt_regs *regs); | ||
140 | static int pl2303_write (struct usb_serial_port *port, | ||
141 | const unsigned char *buf, int count); | ||
142 | static void pl2303_send (struct usb_serial_port *port); | ||
143 | static int pl2303_write_room(struct usb_serial_port *port); | ||
144 | static int pl2303_chars_in_buffer(struct usb_serial_port *port); | ||
145 | static void pl2303_break_ctl(struct usb_serial_port *port,int break_state); | ||
146 | static int pl2303_tiocmget (struct usb_serial_port *port, struct file *file); | ||
147 | static int pl2303_tiocmset (struct usb_serial_port *port, struct file *file, | ||
148 | unsigned int set, unsigned int clear); | ||
149 | static int pl2303_startup (struct usb_serial *serial); | ||
150 | static void pl2303_shutdown (struct usb_serial *serial); | ||
151 | static struct pl2303_buf *pl2303_buf_alloc(unsigned int size); | ||
152 | static void pl2303_buf_free(struct pl2303_buf *pb); | ||
153 | static void pl2303_buf_clear(struct pl2303_buf *pb); | ||
154 | static unsigned int pl2303_buf_data_avail(struct pl2303_buf *pb); | ||
155 | static unsigned int pl2303_buf_space_avail(struct pl2303_buf *pb); | ||
156 | static unsigned int pl2303_buf_put(struct pl2303_buf *pb, const char *buf, | ||
157 | unsigned int count); | ||
158 | static unsigned int pl2303_buf_get(struct pl2303_buf *pb, char *buf, | ||
159 | unsigned int count); | ||
160 | |||
161 | |||
162 | /* All of the device info needed for the PL2303 SIO serial converter */ | ||
163 | static struct usb_serial_driver pl2303_device = { | ||
164 | .driver = { | ||
165 | .owner = THIS_MODULE, | ||
166 | .name = "pl2303", | ||
167 | }, | ||
168 | .id_table = id_table, | ||
169 | .num_interrupt_in = NUM_DONT_CARE, | ||
170 | .num_bulk_in = 1, | ||
171 | .num_bulk_out = 1, | ||
172 | .num_ports = 1, | ||
173 | .open = pl2303_open, | ||
174 | .close = pl2303_close, | ||
175 | .write = pl2303_write, | ||
176 | .ioctl = pl2303_ioctl, | ||
177 | .break_ctl = pl2303_break_ctl, | ||
178 | .set_termios = pl2303_set_termios, | ||
179 | .tiocmget = pl2303_tiocmget, | ||
180 | .tiocmset = pl2303_tiocmset, | ||
181 | .read_bulk_callback = pl2303_read_bulk_callback, | ||
182 | .read_int_callback = pl2303_read_int_callback, | ||
183 | .write_bulk_callback = pl2303_write_bulk_callback, | ||
184 | .write_room = pl2303_write_room, | ||
185 | .chars_in_buffer = pl2303_chars_in_buffer, | ||
186 | .attach = pl2303_startup, | ||
187 | .shutdown = pl2303_shutdown, | ||
188 | }; | ||
189 | 131 | ||
190 | enum pl2303_type { | 132 | enum pl2303_type { |
191 | type_0, /* don't know the difference between type 0 and */ | 133 | type_0, /* don't know the difference between type 0 and */ |
@@ -204,8 +146,166 @@ struct pl2303_private { | |||
204 | enum pl2303_type type; | 146 | enum pl2303_type type; |
205 | }; | 147 | }; |
206 | 148 | ||
149 | /* | ||
150 | * pl2303_buf_alloc | ||
151 | * | ||
152 | * Allocate a circular buffer and all associated memory. | ||
153 | */ | ||
154 | static struct pl2303_buf *pl2303_buf_alloc(unsigned int size) | ||
155 | { | ||
156 | struct pl2303_buf *pb; | ||
157 | |||
158 | if (size == 0) | ||
159 | return NULL; | ||
160 | |||
161 | pb = (struct pl2303_buf *)kmalloc(sizeof(struct pl2303_buf), GFP_KERNEL); | ||
162 | if (pb == NULL) | ||
163 | return NULL; | ||
164 | |||
165 | pb->buf_buf = kmalloc(size, GFP_KERNEL); | ||
166 | if (pb->buf_buf == NULL) { | ||
167 | kfree(pb); | ||
168 | return NULL; | ||
169 | } | ||
170 | |||
171 | pb->buf_size = size; | ||
172 | pb->buf_get = pb->buf_put = pb->buf_buf; | ||
207 | 173 | ||
208 | static int pl2303_startup (struct usb_serial *serial) | 174 | return pb; |
175 | } | ||
176 | |||
177 | /* | ||
178 | * pl2303_buf_free | ||
179 | * | ||
180 | * Free the buffer and all associated memory. | ||
181 | */ | ||
182 | static void pl2303_buf_free(struct pl2303_buf *pb) | ||
183 | { | ||
184 | if (pb) { | ||
185 | kfree(pb->buf_buf); | ||
186 | kfree(pb); | ||
187 | } | ||
188 | } | ||
189 | |||
190 | /* | ||
191 | * pl2303_buf_clear | ||
192 | * | ||
193 | * Clear out all data in the circular buffer. | ||
194 | */ | ||
195 | static void pl2303_buf_clear(struct pl2303_buf *pb) | ||
196 | { | ||
197 | if (pb != NULL) | ||
198 | pb->buf_get = pb->buf_put; | ||
199 | /* equivalent to a get of all data available */ | ||
200 | } | ||
201 | |||
202 | /* | ||
203 | * pl2303_buf_data_avail | ||
204 | * | ||
205 | * Return the number of bytes of data available in the circular | ||
206 | * buffer. | ||
207 | */ | ||
208 | static unsigned int pl2303_buf_data_avail(struct pl2303_buf *pb) | ||
209 | { | ||
210 | if (pb == NULL) | ||
211 | return 0; | ||
212 | |||
213 | return ((pb->buf_size + pb->buf_put - pb->buf_get) % pb->buf_size); | ||
214 | } | ||
215 | |||
216 | /* | ||
217 | * pl2303_buf_space_avail | ||
218 | * | ||
219 | * Return the number of bytes of space available in the circular | ||
220 | * buffer. | ||
221 | */ | ||
222 | static unsigned int pl2303_buf_space_avail(struct pl2303_buf *pb) | ||
223 | { | ||
224 | if (pb == NULL) | ||
225 | return 0; | ||
226 | |||
227 | return ((pb->buf_size + pb->buf_get - pb->buf_put - 1) % pb->buf_size); | ||
228 | } | ||
229 | |||
230 | /* | ||
231 | * pl2303_buf_put | ||
232 | * | ||
233 | * Copy data data from a user buffer and put it into the circular buffer. | ||
234 | * Restrict to the amount of space available. | ||
235 | * | ||
236 | * Return the number of bytes copied. | ||
237 | */ | ||
238 | static unsigned int pl2303_buf_put(struct pl2303_buf *pb, const char *buf, | ||
239 | unsigned int count) | ||
240 | { | ||
241 | unsigned int len; | ||
242 | |||
243 | if (pb == NULL) | ||
244 | return 0; | ||
245 | |||
246 | len = pl2303_buf_space_avail(pb); | ||
247 | if (count > len) | ||
248 | count = len; | ||
249 | |||
250 | if (count == 0) | ||
251 | return 0; | ||
252 | |||
253 | len = pb->buf_buf + pb->buf_size - pb->buf_put; | ||
254 | if (count > len) { | ||
255 | memcpy(pb->buf_put, buf, len); | ||
256 | memcpy(pb->buf_buf, buf+len, count - len); | ||
257 | pb->buf_put = pb->buf_buf + count - len; | ||
258 | } else { | ||
259 | memcpy(pb->buf_put, buf, count); | ||
260 | if (count < len) | ||
261 | pb->buf_put += count; | ||
262 | else /* count == len */ | ||
263 | pb->buf_put = pb->buf_buf; | ||
264 | } | ||
265 | |||
266 | return count; | ||
267 | } | ||
268 | |||
269 | /* | ||
270 | * pl2303_buf_get | ||
271 | * | ||
272 | * Get data from the circular buffer and copy to the given buffer. | ||
273 | * Restrict to the amount of data available. | ||
274 | * | ||
275 | * Return the number of bytes copied. | ||
276 | */ | ||
277 | static unsigned int pl2303_buf_get(struct pl2303_buf *pb, char *buf, | ||
278 | unsigned int count) | ||
279 | { | ||
280 | unsigned int len; | ||
281 | |||
282 | if (pb == NULL) | ||
283 | return 0; | ||
284 | |||
285 | len = pl2303_buf_data_avail(pb); | ||
286 | if (count > len) | ||
287 | count = len; | ||
288 | |||
289 | if (count == 0) | ||
290 | return 0; | ||
291 | |||
292 | len = pb->buf_buf + pb->buf_size - pb->buf_get; | ||
293 | if (count > len) { | ||
294 | memcpy(buf, pb->buf_get, len); | ||
295 | memcpy(buf+len, pb->buf_buf, count - len); | ||
296 | pb->buf_get = pb->buf_buf + count - len; | ||
297 | } else { | ||
298 | memcpy(buf, pb->buf_get, count); | ||
299 | if (count < len) | ||
300 | pb->buf_get += count; | ||
301 | else /* count == len */ | ||
302 | pb->buf_get = pb->buf_buf; | ||
303 | } | ||
304 | |||
305 | return count; | ||
306 | } | ||
307 | |||
308 | static int pl2303_startup(struct usb_serial *serial) | ||
209 | { | 309 | { |
210 | struct pl2303_private *priv; | 310 | struct pl2303_private *priv; |
211 | enum pl2303_type type = type_0; | 311 | enum pl2303_type type = type_0; |
@@ -247,36 +347,17 @@ cleanup: | |||
247 | return -ENOMEM; | 347 | return -ENOMEM; |
248 | } | 348 | } |
249 | 349 | ||
250 | static int set_control_lines (struct usb_device *dev, u8 value) | 350 | static int set_control_lines(struct usb_device *dev, u8 value) |
251 | { | 351 | { |
252 | int retval; | 352 | int retval; |
253 | 353 | ||
254 | retval = usb_control_msg (dev, usb_sndctrlpipe (dev, 0), | 354 | retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), |
255 | SET_CONTROL_REQUEST, SET_CONTROL_REQUEST_TYPE, | 355 | SET_CONTROL_REQUEST, SET_CONTROL_REQUEST_TYPE, |
256 | value, 0, NULL, 0, 100); | 356 | value, 0, NULL, 0, 100); |
257 | dbg("%s - value = %d, retval = %d", __FUNCTION__, value, retval); | 357 | dbg("%s - value = %d, retval = %d", __FUNCTION__, value, retval); |
258 | return retval; | 358 | return retval; |
259 | } | 359 | } |
260 | 360 | ||
261 | static int pl2303_write (struct usb_serial_port *port, const unsigned char *buf, int count) | ||
262 | { | ||
263 | struct pl2303_private *priv = usb_get_serial_port_data(port); | ||
264 | unsigned long flags; | ||
265 | |||
266 | dbg("%s - port %d, %d bytes", __FUNCTION__, port->number, count); | ||
267 | |||
268 | if (!count) | ||
269 | return count; | ||
270 | |||
271 | spin_lock_irqsave(&priv->lock, flags); | ||
272 | count = pl2303_buf_put(priv->buf, buf, count); | ||
273 | spin_unlock_irqrestore(&priv->lock, flags); | ||
274 | |||
275 | pl2303_send(port); | ||
276 | |||
277 | return count; | ||
278 | } | ||
279 | |||
280 | static void pl2303_send(struct usb_serial_port *port) | 361 | static void pl2303_send(struct usb_serial_port *port) |
281 | { | 362 | { |
282 | int count, result; | 363 | int count, result; |
@@ -293,7 +374,7 @@ static void pl2303_send(struct usb_serial_port *port) | |||
293 | } | 374 | } |
294 | 375 | ||
295 | count = pl2303_buf_get(priv->buf, port->write_urb->transfer_buffer, | 376 | count = pl2303_buf_get(priv->buf, port->write_urb->transfer_buffer, |
296 | port->bulk_out_size); | 377 | port->bulk_out_size); |
297 | 378 | ||
298 | if (count == 0) { | 379 | if (count == 0) { |
299 | spin_unlock_irqrestore(&priv->lock, flags); | 380 | spin_unlock_irqrestore(&priv->lock, flags); |
@@ -304,13 +385,15 @@ static void pl2303_send(struct usb_serial_port *port) | |||
304 | 385 | ||
305 | spin_unlock_irqrestore(&priv->lock, flags); | 386 | spin_unlock_irqrestore(&priv->lock, flags); |
306 | 387 | ||
307 | usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, port->write_urb->transfer_buffer); | 388 | usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, |
389 | port->write_urb->transfer_buffer); | ||
308 | 390 | ||
309 | port->write_urb->transfer_buffer_length = count; | 391 | port->write_urb->transfer_buffer_length = count; |
310 | port->write_urb->dev = port->serial->dev; | 392 | port->write_urb->dev = port->serial->dev; |
311 | result = usb_submit_urb (port->write_urb, GFP_ATOMIC); | 393 | result = usb_submit_urb(port->write_urb, GFP_ATOMIC); |
312 | if (result) { | 394 | if (result) { |
313 | dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __FUNCTION__, result); | 395 | dev_err(&port->dev, "%s - failed submitting write urb," |
396 | " error %d\n", __FUNCTION__, result); | ||
314 | priv->write_urb_in_use = 0; | 397 | priv->write_urb_in_use = 0; |
315 | // TODO: reschedule pl2303_send | 398 | // TODO: reschedule pl2303_send |
316 | } | 399 | } |
@@ -318,6 +401,26 @@ static void pl2303_send(struct usb_serial_port *port) | |||
318 | usb_serial_port_softint(port); | 401 | usb_serial_port_softint(port); |
319 | } | 402 | } |
320 | 403 | ||
404 | static int pl2303_write(struct usb_serial_port *port, const unsigned char *buf, | ||
405 | int count) | ||
406 | { | ||
407 | struct pl2303_private *priv = usb_get_serial_port_data(port); | ||
408 | unsigned long flags; | ||
409 | |||
410 | dbg("%s - port %d, %d bytes", __FUNCTION__, port->number, count); | ||
411 | |||
412 | if (!count) | ||
413 | return count; | ||
414 | |||
415 | spin_lock_irqsave(&priv->lock, flags); | ||
416 | count = pl2303_buf_put(priv->buf, buf, count); | ||
417 | spin_unlock_irqrestore(&priv->lock, flags); | ||
418 | |||
419 | pl2303_send(port); | ||
420 | |||
421 | return count; | ||
422 | } | ||
423 | |||
321 | static int pl2303_write_room(struct usb_serial_port *port) | 424 | static int pl2303_write_room(struct usb_serial_port *port) |
322 | { | 425 | { |
323 | struct pl2303_private *priv = usb_get_serial_port_data(port); | 426 | struct pl2303_private *priv = usb_get_serial_port_data(port); |
@@ -350,7 +453,8 @@ static int pl2303_chars_in_buffer(struct usb_serial_port *port) | |||
350 | return chars; | 453 | return chars; |
351 | } | 454 | } |
352 | 455 | ||
353 | static void pl2303_set_termios (struct usb_serial_port *port, struct termios *old_termios) | 456 | static void pl2303_set_termios(struct usb_serial_port *port, |
457 | struct termios *old_termios) | ||
354 | { | 458 | { |
355 | struct usb_serial *serial = port->serial; | 459 | struct usb_serial *serial = port->serial; |
356 | struct pl2303_private *priv = usb_get_serial_port_data(port); | 460 | struct pl2303_private *priv = usb_get_serial_port_data(port); |
@@ -371,7 +475,8 @@ static void pl2303_set_termios (struct usb_serial_port *port, struct termios *ol | |||
371 | spin_lock_irqsave(&priv->lock, flags); | 475 | spin_lock_irqsave(&priv->lock, flags); |
372 | if (!priv->termios_initialized) { | 476 | if (!priv->termios_initialized) { |
373 | *(port->tty->termios) = tty_std_termios; | 477 | *(port->tty->termios) = tty_std_termios; |
374 | port->tty->termios->c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; | 478 | port->tty->termios->c_cflag = B9600 | CS8 | CREAD | |
479 | HUPCL | CLOCAL; | ||
375 | priv->termios_initialized = 1; | 480 | priv->termios_initialized = 1; |
376 | } | 481 | } |
377 | spin_unlock_irqrestore(&priv->lock, flags); | 482 | spin_unlock_irqrestore(&priv->lock, flags); |
@@ -380,24 +485,24 @@ static void pl2303_set_termios (struct usb_serial_port *port, struct termios *ol | |||
380 | /* check that they really want us to change something */ | 485 | /* check that they really want us to change something */ |
381 | if (old_termios) { | 486 | if (old_termios) { |
382 | if ((cflag == old_termios->c_cflag) && | 487 | if ((cflag == old_termios->c_cflag) && |
383 | (RELEVANT_IFLAG(port->tty->termios->c_iflag) == RELEVANT_IFLAG(old_termios->c_iflag))) { | 488 | (RELEVANT_IFLAG(port->tty->termios->c_iflag) == |
384 | dbg("%s - nothing to change...", __FUNCTION__); | 489 | RELEVANT_IFLAG(old_termios->c_iflag))) { |
385 | return; | 490 | dbg("%s - nothing to change...", __FUNCTION__); |
491 | return; | ||
386 | } | 492 | } |
387 | } | 493 | } |
388 | 494 | ||
389 | buf = kzalloc (7, GFP_KERNEL); | 495 | buf = kzalloc(7, GFP_KERNEL); |
390 | if (!buf) { | 496 | if (!buf) { |
391 | dev_err(&port->dev, "%s - out of memory.\n", __FUNCTION__); | 497 | dev_err(&port->dev, "%s - out of memory.\n", __FUNCTION__); |
392 | return; | 498 | return; |
393 | } | 499 | } |
394 | |||
395 | i = usb_control_msg (serial->dev, usb_rcvctrlpipe (serial->dev, 0), | ||
396 | GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE, | ||
397 | 0, 0, buf, 7, 100); | ||
398 | dbg ("0xa1:0x21:0:0 %d - %x %x %x %x %x %x %x", i, | ||
399 | buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]); | ||
400 | 500 | ||
501 | i = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), | ||
502 | GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE, | ||
503 | 0, 0, buf, 7, 100); | ||
504 | dbg("0xa1:0x21:0:0 %d - %x %x %x %x %x %x %x", i, | ||
505 | buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]); | ||
401 | 506 | ||
402 | if (cflag & CSIZE) { | 507 | if (cflag & CSIZE) { |
403 | switch (cflag & CSIZE) { | 508 | switch (cflag & CSIZE) { |
@@ -429,7 +534,8 @@ static void pl2303_set_termios (struct usb_serial_port *port, struct termios *ol | |||
429 | case B230400: baud = 230400; break; | 534 | case B230400: baud = 230400; break; |
430 | case B460800: baud = 460800; break; | 535 | case B460800: baud = 460800; break; |
431 | default: | 536 | default: |
432 | dev_err(&port->dev, "pl2303 driver does not support the baudrate requested (fix it)\n"); | 537 | dev_err(&port->dev, "pl2303 driver does not support" |
538 | " the baudrate requested (fix it)\n"); | ||
433 | break; | 539 | break; |
434 | } | 540 | } |
435 | dbg("%s - baud = %d", __FUNCTION__, baud); | 541 | dbg("%s - baud = %d", __FUNCTION__, baud); |
@@ -469,10 +575,10 @@ static void pl2303_set_termios (struct usb_serial_port *port, struct termios *ol | |||
469 | dbg("%s - parity = none", __FUNCTION__); | 575 | dbg("%s - parity = none", __FUNCTION__); |
470 | } | 576 | } |
471 | 577 | ||
472 | i = usb_control_msg (serial->dev, usb_sndctrlpipe (serial->dev, 0), | 578 | i = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), |
473 | SET_LINE_REQUEST, SET_LINE_REQUEST_TYPE, | 579 | SET_LINE_REQUEST, SET_LINE_REQUEST_TYPE, |
474 | 0, 0, buf, 7, 100); | 580 | 0, 0, buf, 7, 100); |
475 | dbg ("0x21:0x20:0:0 %d", i); | 581 | dbg("0x21:0x20:0:0 %d", i); |
476 | 582 | ||
477 | /* change control lines if we are switching to or from B0 */ | 583 | /* change control lines if we are switching to or from B0 */ |
478 | spin_lock_irqsave(&priv->lock, flags); | 584 | spin_lock_irqsave(&priv->lock, flags); |
@@ -488,13 +594,13 @@ static void pl2303_set_termios (struct usb_serial_port *port, struct termios *ol | |||
488 | } else { | 594 | } else { |
489 | spin_unlock_irqrestore(&priv->lock, flags); | 595 | spin_unlock_irqrestore(&priv->lock, flags); |
490 | } | 596 | } |
491 | 597 | ||
492 | buf[0] = buf[1] = buf[2] = buf[3] = buf[4] = buf[5] = buf[6] = 0; | 598 | buf[0] = buf[1] = buf[2] = buf[3] = buf[4] = buf[5] = buf[6] = 0; |
493 | 599 | ||
494 | i = usb_control_msg (serial->dev, usb_rcvctrlpipe (serial->dev, 0), | 600 | i = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), |
495 | GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE, | 601 | GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE, |
496 | 0, 0, buf, 7, 100); | 602 | 0, 0, buf, 7, 100); |
497 | dbg ("0xa1:0x21:0:0 %d - %x %x %x %x %x %x %x", i, | 603 | dbg("0xa1:0x21:0:0 %d - %x %x %x %x %x %x %x", i, |
498 | buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]); | 604 | buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]); |
499 | 605 | ||
500 | if (cflag & CRTSCTS) { | 606 | if (cflag & CRTSCTS) { |
@@ -503,18 +609,82 @@ static void pl2303_set_termios (struct usb_serial_port *port, struct termios *ol | |||
503 | index = 0x61; | 609 | index = 0x61; |
504 | else | 610 | else |
505 | index = 0x41; | 611 | index = 0x41; |
506 | i = usb_control_msg(serial->dev, | 612 | i = usb_control_msg(serial->dev, |
507 | usb_sndctrlpipe(serial->dev, 0), | 613 | usb_sndctrlpipe(serial->dev, 0), |
508 | VENDOR_WRITE_REQUEST, | 614 | VENDOR_WRITE_REQUEST, |
509 | VENDOR_WRITE_REQUEST_TYPE, | 615 | VENDOR_WRITE_REQUEST_TYPE, |
510 | 0x0, index, NULL, 0, 100); | 616 | 0x0, index, NULL, 0, 100); |
511 | dbg ("0x40:0x1:0x0:0x%x %d", index, i); | 617 | dbg("0x40:0x1:0x0:0x%x %d", index, i); |
618 | } | ||
619 | |||
620 | kfree(buf); | ||
621 | } | ||
622 | |||
623 | static void pl2303_close(struct usb_serial_port *port, struct file *filp) | ||
624 | { | ||
625 | struct pl2303_private *priv = usb_get_serial_port_data(port); | ||
626 | unsigned long flags; | ||
627 | unsigned int c_cflag; | ||
628 | int bps; | ||
629 | long timeout; | ||
630 | wait_queue_t wait; | ||
631 | |||
632 | dbg("%s - port %d", __FUNCTION__, port->number); | ||
633 | |||
634 | /* wait for data to drain from the buffer */ | ||
635 | spin_lock_irqsave(&priv->lock, flags); | ||
636 | timeout = PL2303_CLOSING_WAIT; | ||
637 | init_waitqueue_entry(&wait, current); | ||
638 | add_wait_queue(&port->tty->write_wait, &wait); | ||
639 | for (;;) { | ||
640 | set_current_state(TASK_INTERRUPTIBLE); | ||
641 | if (pl2303_buf_data_avail(priv->buf) == 0 || | ||
642 | timeout == 0 || signal_pending(current) || | ||
643 | !usb_get_intfdata(port->serial->interface)) /* disconnect */ | ||
644 | break; | ||
645 | spin_unlock_irqrestore(&priv->lock, flags); | ||
646 | timeout = schedule_timeout(timeout); | ||
647 | spin_lock_irqsave(&priv->lock, flags); | ||
512 | } | 648 | } |
649 | set_current_state(TASK_RUNNING); | ||
650 | remove_wait_queue(&port->tty->write_wait, &wait); | ||
651 | /* clear out any remaining data in the buffer */ | ||
652 | pl2303_buf_clear(priv->buf); | ||
653 | spin_unlock_irqrestore(&priv->lock, flags); | ||
654 | |||
655 | /* wait for characters to drain from the device */ | ||
656 | /* (this is long enough for the entire 256 byte */ | ||
657 | /* pl2303 hardware buffer to drain with no flow */ | ||
658 | /* control for data rates of 1200 bps or more, */ | ||
659 | /* for lower rates we should really know how much */ | ||
660 | /* data is in the buffer to compute a delay */ | ||
661 | /* that is not unnecessarily long) */ | ||
662 | bps = tty_get_baud_rate(port->tty); | ||
663 | if (bps > 1200) | ||
664 | timeout = max((HZ*2560)/bps,HZ/10); | ||
665 | else | ||
666 | timeout = 2*HZ; | ||
667 | schedule_timeout_interruptible(timeout); | ||
513 | 668 | ||
514 | kfree (buf); | 669 | /* shutdown our urbs */ |
670 | dbg("%s - shutting down urbs", __FUNCTION__); | ||
671 | usb_kill_urb(port->write_urb); | ||
672 | usb_kill_urb(port->read_urb); | ||
673 | usb_kill_urb(port->interrupt_in_urb); | ||
674 | |||
675 | if (port->tty) { | ||
676 | c_cflag = port->tty->termios->c_cflag; | ||
677 | if (c_cflag & HUPCL) { | ||
678 | /* drop DTR and RTS */ | ||
679 | spin_lock_irqsave(&priv->lock, flags); | ||
680 | priv->line_control = 0; | ||
681 | spin_unlock_irqrestore(&priv->lock, flags); | ||
682 | set_control_lines(port->serial->dev, 0); | ||
683 | } | ||
684 | } | ||
515 | } | 685 | } |
516 | 686 | ||
517 | static int pl2303_open (struct usb_serial_port *port, struct file *filp) | 687 | static int pl2303_open(struct usb_serial_port *port, struct file *filp) |
518 | { | 688 | { |
519 | struct termios tmp_termios; | 689 | struct termios tmp_termios; |
520 | struct usb_serial *serial = port->serial; | 690 | struct usb_serial *serial = port->serial; |
@@ -568,98 +738,35 @@ static int pl2303_open (struct usb_serial_port *port, struct file *filp) | |||
568 | 738 | ||
569 | /* Setup termios */ | 739 | /* Setup termios */ |
570 | if (port->tty) { | 740 | if (port->tty) { |
571 | pl2303_set_termios (port, &tmp_termios); | 741 | pl2303_set_termios(port, &tmp_termios); |
572 | } | 742 | } |
573 | 743 | ||
574 | //FIXME: need to assert RTS and DTR if CRTSCTS off | 744 | //FIXME: need to assert RTS and DTR if CRTSCTS off |
575 | 745 | ||
576 | dbg("%s - submitting read urb", __FUNCTION__); | 746 | dbg("%s - submitting read urb", __FUNCTION__); |
577 | port->read_urb->dev = serial->dev; | 747 | port->read_urb->dev = serial->dev; |
578 | result = usb_submit_urb (port->read_urb, GFP_KERNEL); | 748 | result = usb_submit_urb(port->read_urb, GFP_KERNEL); |
579 | if (result) { | 749 | if (result) { |
580 | dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __FUNCTION__, result); | 750 | dev_err(&port->dev, "%s - failed submitting read urb," |
581 | pl2303_close (port, NULL); | 751 | " error %d\n", __FUNCTION__, result); |
752 | pl2303_close(port, NULL); | ||
582 | return -EPROTO; | 753 | return -EPROTO; |
583 | } | 754 | } |
584 | 755 | ||
585 | dbg("%s - submitting interrupt urb", __FUNCTION__); | 756 | dbg("%s - submitting interrupt urb", __FUNCTION__); |
586 | port->interrupt_in_urb->dev = serial->dev; | 757 | port->interrupt_in_urb->dev = serial->dev; |
587 | result = usb_submit_urb (port->interrupt_in_urb, GFP_KERNEL); | 758 | result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); |
588 | if (result) { | 759 | if (result) { |
589 | dev_err(&port->dev, "%s - failed submitting interrupt urb, error %d\n", __FUNCTION__, result); | 760 | dev_err(&port->dev, "%s - failed submitting interrupt urb," |
590 | pl2303_close (port, NULL); | 761 | " error %d\n", __FUNCTION__, result); |
762 | pl2303_close(port, NULL); | ||
591 | return -EPROTO; | 763 | return -EPROTO; |
592 | } | 764 | } |
593 | return 0; | 765 | return 0; |
594 | } | 766 | } |
595 | 767 | ||
596 | 768 | static int pl2303_tiocmset(struct usb_serial_port *port, struct file *file, | |
597 | static void pl2303_close (struct usb_serial_port *port, struct file *filp) | 769 | unsigned int set, unsigned int clear) |
598 | { | ||
599 | struct pl2303_private *priv = usb_get_serial_port_data(port); | ||
600 | unsigned long flags; | ||
601 | unsigned int c_cflag; | ||
602 | int bps; | ||
603 | long timeout; | ||
604 | wait_queue_t wait; | ||
605 | |||
606 | dbg("%s - port %d", __FUNCTION__, port->number); | ||
607 | |||
608 | /* wait for data to drain from the buffer */ | ||
609 | spin_lock_irqsave(&priv->lock, flags); | ||
610 | timeout = PL2303_CLOSING_WAIT; | ||
611 | init_waitqueue_entry(&wait, current); | ||
612 | add_wait_queue(&port->tty->write_wait, &wait); | ||
613 | for (;;) { | ||
614 | set_current_state(TASK_INTERRUPTIBLE); | ||
615 | if (pl2303_buf_data_avail(priv->buf) == 0 | ||
616 | || timeout == 0 || signal_pending(current) | ||
617 | || !usb_get_intfdata(port->serial->interface)) /* disconnect */ | ||
618 | break; | ||
619 | spin_unlock_irqrestore(&priv->lock, flags); | ||
620 | timeout = schedule_timeout(timeout); | ||
621 | spin_lock_irqsave(&priv->lock, flags); | ||
622 | } | ||
623 | set_current_state(TASK_RUNNING); | ||
624 | remove_wait_queue(&port->tty->write_wait, &wait); | ||
625 | /* clear out any remaining data in the buffer */ | ||
626 | pl2303_buf_clear(priv->buf); | ||
627 | spin_unlock_irqrestore(&priv->lock, flags); | ||
628 | |||
629 | /* wait for characters to drain from the device */ | ||
630 | /* (this is long enough for the entire 256 byte */ | ||
631 | /* pl2303 hardware buffer to drain with no flow */ | ||
632 | /* control for data rates of 1200 bps or more, */ | ||
633 | /* for lower rates we should really know how much */ | ||
634 | /* data is in the buffer to compute a delay */ | ||
635 | /* that is not unnecessarily long) */ | ||
636 | bps = tty_get_baud_rate(port->tty); | ||
637 | if (bps > 1200) | ||
638 | timeout = max((HZ*2560)/bps,HZ/10); | ||
639 | else | ||
640 | timeout = 2*HZ; | ||
641 | schedule_timeout_interruptible(timeout); | ||
642 | |||
643 | /* shutdown our urbs */ | ||
644 | dbg("%s - shutting down urbs", __FUNCTION__); | ||
645 | usb_kill_urb(port->write_urb); | ||
646 | usb_kill_urb(port->read_urb); | ||
647 | usb_kill_urb(port->interrupt_in_urb); | ||
648 | |||
649 | if (port->tty) { | ||
650 | c_cflag = port->tty->termios->c_cflag; | ||
651 | if (c_cflag & HUPCL) { | ||
652 | /* drop DTR and RTS */ | ||
653 | spin_lock_irqsave(&priv->lock, flags); | ||
654 | priv->line_control = 0; | ||
655 | spin_unlock_irqrestore (&priv->lock, flags); | ||
656 | set_control_lines (port->serial->dev, 0); | ||
657 | } | ||
658 | } | ||
659 | } | ||
660 | |||
661 | static int pl2303_tiocmset (struct usb_serial_port *port, struct file *file, | ||
662 | unsigned int set, unsigned int clear) | ||
663 | { | 770 | { |
664 | struct pl2303_private *priv = usb_get_serial_port_data(port); | 771 | struct pl2303_private *priv = usb_get_serial_port_data(port); |
665 | unsigned long flags; | 772 | unsigned long flags; |
@@ -668,7 +775,7 @@ static int pl2303_tiocmset (struct usb_serial_port *port, struct file *file, | |||
668 | if (!usb_get_intfdata(port->serial->interface)) | 775 | if (!usb_get_intfdata(port->serial->interface)) |
669 | return -ENODEV; | 776 | return -ENODEV; |
670 | 777 | ||
671 | spin_lock_irqsave (&priv->lock, flags); | 778 | spin_lock_irqsave(&priv->lock, flags); |
672 | if (set & TIOCM_RTS) | 779 | if (set & TIOCM_RTS) |
673 | priv->line_control |= CONTROL_RTS; | 780 | priv->line_control |= CONTROL_RTS; |
674 | if (set & TIOCM_DTR) | 781 | if (set & TIOCM_DTR) |
@@ -678,12 +785,12 @@ static int pl2303_tiocmset (struct usb_serial_port *port, struct file *file, | |||
678 | if (clear & TIOCM_DTR) | 785 | if (clear & TIOCM_DTR) |
679 | priv->line_control &= ~CONTROL_DTR; | 786 | priv->line_control &= ~CONTROL_DTR; |
680 | control = priv->line_control; | 787 | control = priv->line_control; |
681 | spin_unlock_irqrestore (&priv->lock, flags); | 788 | spin_unlock_irqrestore(&priv->lock, flags); |
682 | 789 | ||
683 | return set_control_lines (port->serial->dev, control); | 790 | return set_control_lines(port->serial->dev, control); |
684 | } | 791 | } |
685 | 792 | ||
686 | static int pl2303_tiocmget (struct usb_serial_port *port, struct file *file) | 793 | static int pl2303_tiocmget(struct usb_serial_port *port, struct file *file) |
687 | { | 794 | { |
688 | struct pl2303_private *priv = usb_get_serial_port_data(port); | 795 | struct pl2303_private *priv = usb_get_serial_port_data(port); |
689 | unsigned long flags; | 796 | unsigned long flags; |
@@ -696,10 +803,10 @@ static int pl2303_tiocmget (struct usb_serial_port *port, struct file *file) | |||
696 | if (!usb_get_intfdata(port->serial->interface)) | 803 | if (!usb_get_intfdata(port->serial->interface)) |
697 | return -ENODEV; | 804 | return -ENODEV; |
698 | 805 | ||
699 | spin_lock_irqsave (&priv->lock, flags); | 806 | spin_lock_irqsave(&priv->lock, flags); |
700 | mcr = priv->line_control; | 807 | mcr = priv->line_control; |
701 | status = priv->line_status; | 808 | status = priv->line_status; |
702 | spin_unlock_irqrestore (&priv->lock, flags); | 809 | spin_unlock_irqrestore(&priv->lock, flags); |
703 | 810 | ||
704 | result = ((mcr & CONTROL_DTR) ? TIOCM_DTR : 0) | 811 | result = ((mcr & CONTROL_DTR) ? TIOCM_DTR : 0) |
705 | | ((mcr & CONTROL_RTS) ? TIOCM_RTS : 0) | 812 | | ((mcr & CONTROL_RTS) ? TIOCM_RTS : 0) |
@@ -721,22 +828,22 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg) | |||
721 | unsigned int status; | 828 | unsigned int status; |
722 | unsigned int changed; | 829 | unsigned int changed; |
723 | 830 | ||
724 | spin_lock_irqsave (&priv->lock, flags); | 831 | spin_lock_irqsave(&priv->lock, flags); |
725 | prevstatus = priv->line_status; | 832 | prevstatus = priv->line_status; |
726 | spin_unlock_irqrestore (&priv->lock, flags); | 833 | spin_unlock_irqrestore(&priv->lock, flags); |
727 | 834 | ||
728 | while (1) { | 835 | while (1) { |
729 | interruptible_sleep_on(&priv->delta_msr_wait); | 836 | interruptible_sleep_on(&priv->delta_msr_wait); |
730 | /* see if a signal did it */ | 837 | /* see if a signal did it */ |
731 | if (signal_pending(current)) | 838 | if (signal_pending(current)) |
732 | return -ERESTARTSYS; | 839 | return -ERESTARTSYS; |
733 | 840 | ||
734 | spin_lock_irqsave (&priv->lock, flags); | 841 | spin_lock_irqsave(&priv->lock, flags); |
735 | status = priv->line_status; | 842 | status = priv->line_status; |
736 | spin_unlock_irqrestore (&priv->lock, flags); | 843 | spin_unlock_irqrestore(&priv->lock, flags); |
737 | 844 | ||
738 | changed=prevstatus^status; | 845 | changed=prevstatus^status; |
739 | 846 | ||
740 | if (((arg & TIOCM_RNG) && (changed & UART_RING)) || | 847 | if (((arg & TIOCM_RNG) && (changed & UART_RING)) || |
741 | ((arg & TIOCM_DSR) && (changed & UART_DSR)) || | 848 | ((arg & TIOCM_DSR) && (changed & UART_DSR)) || |
742 | ((arg & TIOCM_CD) && (changed & UART_DCD)) || | 849 | ((arg & TIOCM_CD) && (changed & UART_DCD)) || |
@@ -749,7 +856,8 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg) | |||
749 | return 0; | 856 | return 0; |
750 | } | 857 | } |
751 | 858 | ||
752 | static int pl2303_ioctl (struct usb_serial_port *port, struct file *file, unsigned int cmd, unsigned long arg) | 859 | static int pl2303_ioctl(struct usb_serial_port *port, struct file *file, |
860 | unsigned int cmd, unsigned long arg) | ||
753 | { | 861 | { |
754 | dbg("%s (%d) cmd = 0x%04x", __FUNCTION__, port->number, cmd); | 862 | dbg("%s (%d) cmd = 0x%04x", __FUNCTION__, port->number, cmd); |
755 | 863 | ||
@@ -766,7 +874,7 @@ static int pl2303_ioctl (struct usb_serial_port *port, struct file *file, unsign | |||
766 | return -ENOIOCTLCMD; | 874 | return -ENOIOCTLCMD; |
767 | } | 875 | } |
768 | 876 | ||
769 | static void pl2303_break_ctl (struct usb_serial_port *port, int break_state) | 877 | static void pl2303_break_ctl(struct usb_serial_port *port, int break_state) |
770 | { | 878 | { |
771 | struct usb_serial *serial = port->serial; | 879 | struct usb_serial *serial = port->serial; |
772 | u16 state; | 880 | u16 state; |
@@ -780,15 +888,14 @@ static void pl2303_break_ctl (struct usb_serial_port *port, int break_state) | |||
780 | state = BREAK_ON; | 888 | state = BREAK_ON; |
781 | dbg("%s - turning break %s", __FUNCTION__, state==BREAK_OFF ? "off" : "on"); | 889 | dbg("%s - turning break %s", __FUNCTION__, state==BREAK_OFF ? "off" : "on"); |
782 | 890 | ||
783 | result = usb_control_msg (serial->dev, usb_sndctrlpipe (serial->dev, 0), | 891 | result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), |
784 | BREAK_REQUEST, BREAK_REQUEST_TYPE, state, | 892 | BREAK_REQUEST, BREAK_REQUEST_TYPE, state, |
785 | 0, NULL, 0, 100); | 893 | 0, NULL, 0, 100); |
786 | if (result) | 894 | if (result) |
787 | dbg("%s - error sending break = %d", __FUNCTION__, result); | 895 | dbg("%s - error sending break = %d", __FUNCTION__, result); |
788 | } | 896 | } |
789 | 897 | ||
790 | 898 | static void pl2303_shutdown(struct usb_serial *serial) | |
791 | static void pl2303_shutdown (struct usb_serial *serial) | ||
792 | { | 899 | { |
793 | int i; | 900 | int i; |
794 | struct pl2303_private *priv; | 901 | struct pl2303_private *priv; |
@@ -802,7 +909,7 @@ static void pl2303_shutdown (struct usb_serial *serial) | |||
802 | kfree(priv); | 909 | kfree(priv); |
803 | usb_set_serial_port_data(serial->port[i], NULL); | 910 | usb_set_serial_port_data(serial->port[i], NULL); |
804 | } | 911 | } |
805 | } | 912 | } |
806 | } | 913 | } |
807 | 914 | ||
808 | static void pl2303_update_line_status(struct usb_serial_port *port, | 915 | static void pl2303_update_line_status(struct usb_serial_port *port, |
@@ -814,29 +921,33 @@ static void pl2303_update_line_status(struct usb_serial_port *port, | |||
814 | unsigned long flags; | 921 | unsigned long flags; |
815 | u8 status_idx = UART_STATE; | 922 | u8 status_idx = UART_STATE; |
816 | u8 length = UART_STATE + 1; | 923 | u8 length = UART_STATE + 1; |
924 | u16 idv, idp; | ||
925 | |||
926 | idv = le16_to_cpu(port->serial->dev->descriptor.idVendor); | ||
927 | idp = le16_to_cpu(port->serial->dev->descriptor.idProduct); | ||
817 | 928 | ||
818 | if ((le16_to_cpu(port->serial->dev->descriptor.idVendor) == SIEMENS_VENDOR_ID) && | 929 | |
819 | (le16_to_cpu(port->serial->dev->descriptor.idProduct) == SIEMENS_PRODUCT_ID_X65 || | 930 | if (idv == SIEMENS_VENDOR_ID) { |
820 | le16_to_cpu(port->serial->dev->descriptor.idProduct) == SIEMENS_PRODUCT_ID_SX1 || | 931 | if (idp == SIEMENS_PRODUCT_ID_X65 || |
821 | le16_to_cpu(port->serial->dev->descriptor.idProduct) == SIEMENS_PRODUCT_ID_X75)) { | 932 | idp == SIEMENS_PRODUCT_ID_SX1 || |
822 | length = 1; | 933 | idp == SIEMENS_PRODUCT_ID_X75) { |
823 | status_idx = 0; | 934 | |
935 | length = 1; | ||
936 | status_idx = 0; | ||
937 | } | ||
824 | } | 938 | } |
825 | 939 | ||
826 | if (actual_length < length) | 940 | if (actual_length < length) |
827 | goto exit; | 941 | return; |
828 | 942 | ||
829 | /* Save off the uart status for others to look at */ | 943 | /* Save off the uart status for others to look at */ |
830 | spin_lock_irqsave(&priv->lock, flags); | 944 | spin_lock_irqsave(&priv->lock, flags); |
831 | priv->line_status = data[status_idx]; | 945 | priv->line_status = data[status_idx]; |
832 | spin_unlock_irqrestore(&priv->lock, flags); | 946 | spin_unlock_irqrestore(&priv->lock, flags); |
833 | wake_up_interruptible (&priv->delta_msr_wait); | 947 | wake_up_interruptible(&priv->delta_msr_wait); |
834 | |||
835 | exit: | ||
836 | return; | ||
837 | } | 948 | } |
838 | 949 | ||
839 | static void pl2303_read_int_callback (struct urb *urb, struct pt_regs *regs) | 950 | static void pl2303_read_int_callback(struct urb *urb, struct pt_regs *regs) |
840 | { | 951 | { |
841 | struct usb_serial_port *port = (struct usb_serial_port *) urb->context; | 952 | struct usb_serial_port *port = (struct usb_serial_port *) urb->context; |
842 | unsigned char *data = urb->transfer_buffer; | 953 | unsigned char *data = urb->transfer_buffer; |
@@ -853,25 +964,29 @@ static void pl2303_read_int_callback (struct urb *urb, struct pt_regs *regs) | |||
853 | case -ENOENT: | 964 | case -ENOENT: |
854 | case -ESHUTDOWN: | 965 | case -ESHUTDOWN: |
855 | /* this urb is terminated, clean up */ | 966 | /* this urb is terminated, clean up */ |
856 | dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status); | 967 | dbg("%s - urb shutting down with status: %d", __FUNCTION__, |
968 | urb->status); | ||
857 | return; | 969 | return; |
858 | default: | 970 | default: |
859 | dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status); | 971 | dbg("%s - nonzero urb status received: %d", __FUNCTION__, |
972 | urb->status); | ||
860 | goto exit; | 973 | goto exit; |
861 | } | 974 | } |
862 | 975 | ||
863 | usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, urb->transfer_buffer); | 976 | usb_serial_debug_data(debug, &port->dev, __FUNCTION__, |
977 | urb->actual_length, urb->transfer_buffer); | ||
978 | |||
864 | pl2303_update_line_status(port, data, actual_length); | 979 | pl2303_update_line_status(port, data, actual_length); |
865 | 980 | ||
866 | exit: | 981 | exit: |
867 | status = usb_submit_urb (urb, GFP_ATOMIC); | 982 | status = usb_submit_urb(urb, GFP_ATOMIC); |
868 | if (status) | 983 | if (status) |
869 | dev_err(&urb->dev->dev, "%s - usb_submit_urb failed with result %d\n", | 984 | dev_err(&urb->dev->dev, |
985 | "%s - usb_submit_urb failed with result %d\n", | ||
870 | __FUNCTION__, status); | 986 | __FUNCTION__, status); |
871 | } | 987 | } |
872 | 988 | ||
873 | 989 | static void pl2303_read_bulk_callback(struct urb *urb, struct pt_regs *regs) | |
874 | static void pl2303_read_bulk_callback (struct urb *urb, struct pt_regs *regs) | ||
875 | { | 990 | { |
876 | struct usb_serial_port *port = (struct usb_serial_port *) urb->context; | 991 | struct usb_serial_port *port = (struct usb_serial_port *) urb->context; |
877 | struct pl2303_private *priv = usb_get_serial_port_data(port); | 992 | struct pl2303_private *priv = usb_get_serial_port_data(port); |
@@ -892,20 +1007,25 @@ static void pl2303_read_bulk_callback (struct urb *urb, struct pt_regs *regs) | |||
892 | return; | 1007 | return; |
893 | } | 1008 | } |
894 | if (urb->status == -EPROTO) { | 1009 | if (urb->status == -EPROTO) { |
895 | /* PL2303 mysteriously fails with -EPROTO reschedule the read */ | 1010 | /* PL2303 mysteriously fails with -EPROTO reschedule |
896 | dbg("%s - caught -EPROTO, resubmitting the urb", __FUNCTION__); | 1011 | * the read */ |
1012 | dbg("%s - caught -EPROTO, resubmitting the urb", | ||
1013 | __FUNCTION__); | ||
897 | urb->status = 0; | 1014 | urb->status = 0; |
898 | urb->dev = port->serial->dev; | 1015 | urb->dev = port->serial->dev; |
899 | result = usb_submit_urb(urb, GFP_ATOMIC); | 1016 | result = usb_submit_urb(urb, GFP_ATOMIC); |
900 | if (result) | 1017 | if (result) |
901 | dev_err(&urb->dev->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result); | 1018 | dev_err(&urb->dev->dev, "%s - failed" |
1019 | " resubmitting read urb, error %d\n", | ||
1020 | __FUNCTION__, result); | ||
902 | return; | 1021 | return; |
903 | } | 1022 | } |
904 | dbg("%s - unable to handle the error, exiting.", __FUNCTION__); | 1023 | dbg("%s - unable to handle the error, exiting.", __FUNCTION__); |
905 | return; | 1024 | return; |
906 | } | 1025 | } |
907 | 1026 | ||
908 | usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data); | 1027 | usb_serial_debug_data(debug, &port->dev, __FUNCTION__, |
1028 | urb->actual_length, data); | ||
909 | 1029 | ||
910 | /* get tty_flag from status */ | 1030 | /* get tty_flag from status */ |
911 | tty_flag = TTY_NORMAL; | 1031 | tty_flag = TTY_NORMAL; |
@@ -914,7 +1034,7 @@ static void pl2303_read_bulk_callback (struct urb *urb, struct pt_regs *regs) | |||
914 | status = priv->line_status; | 1034 | status = priv->line_status; |
915 | priv->line_status &= ~UART_STATE_TRANSIENT_MASK; | 1035 | priv->line_status &= ~UART_STATE_TRANSIENT_MASK; |
916 | spin_unlock_irqrestore(&priv->lock, flags); | 1036 | spin_unlock_irqrestore(&priv->lock, flags); |
917 | wake_up_interruptible (&priv->delta_msr_wait); | 1037 | wake_up_interruptible(&priv->delta_msr_wait); |
918 | 1038 | ||
919 | /* break takes precedence over parity, */ | 1039 | /* break takes precedence over parity, */ |
920 | /* which takes precedence over framing errors */ | 1040 | /* which takes precedence over framing errors */ |
@@ -933,8 +1053,8 @@ static void pl2303_read_bulk_callback (struct urb *urb, struct pt_regs *regs) | |||
933 | if (status & UART_OVERRUN_ERROR) | 1053 | if (status & UART_OVERRUN_ERROR) |
934 | tty_insert_flip_char(tty, 0, TTY_OVERRUN); | 1054 | tty_insert_flip_char(tty, 0, TTY_OVERRUN); |
935 | for (i = 0; i < urb->actual_length; ++i) | 1055 | for (i = 0; i < urb->actual_length; ++i) |
936 | tty_insert_flip_char (tty, data[i], tty_flag); | 1056 | tty_insert_flip_char(tty, data[i], tty_flag); |
937 | tty_flip_buffer_push (tty); | 1057 | tty_flip_buffer_push(tty); |
938 | } | 1058 | } |
939 | 1059 | ||
940 | /* Schedule the next read _if_ we are still open */ | 1060 | /* Schedule the next read _if_ we are still open */ |
@@ -942,15 +1062,14 @@ static void pl2303_read_bulk_callback (struct urb *urb, struct pt_regs *regs) | |||
942 | urb->dev = port->serial->dev; | 1062 | urb->dev = port->serial->dev; |
943 | result = usb_submit_urb(urb, GFP_ATOMIC); | 1063 | result = usb_submit_urb(urb, GFP_ATOMIC); |
944 | if (result) | 1064 | if (result) |
945 | dev_err(&urb->dev->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result); | 1065 | dev_err(&urb->dev->dev, "%s - failed resubmitting" |
1066 | " read urb, error %d\n", __FUNCTION__, result); | ||
946 | } | 1067 | } |
947 | 1068 | ||
948 | return; | 1069 | return; |
949 | } | 1070 | } |
950 | 1071 | ||
951 | 1072 | static void pl2303_write_bulk_callback(struct urb *urb, struct pt_regs *regs) | |
952 | |||
953 | static void pl2303_write_bulk_callback (struct urb *urb, struct pt_regs *regs) | ||
954 | { | 1073 | { |
955 | struct usb_serial_port *port = (struct usb_serial_port *) urb->context; | 1074 | struct usb_serial_port *port = (struct usb_serial_port *) urb->context; |
956 | struct pl2303_private *priv = usb_get_serial_port_data(port); | 1075 | struct pl2303_private *priv = usb_get_serial_port_data(port); |
@@ -966,18 +1085,21 @@ static void pl2303_write_bulk_callback (struct urb *urb, struct pt_regs *regs) | |||
966 | case -ENOENT: | 1085 | case -ENOENT: |
967 | case -ESHUTDOWN: | 1086 | case -ESHUTDOWN: |
968 | /* this urb is terminated, clean up */ | 1087 | /* this urb is terminated, clean up */ |
969 | dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status); | 1088 | dbg("%s - urb shutting down with status: %d", __FUNCTION__, |
1089 | urb->status); | ||
970 | priv->write_urb_in_use = 0; | 1090 | priv->write_urb_in_use = 0; |
971 | return; | 1091 | return; |
972 | default: | 1092 | default: |
973 | /* error in the urb, so we have to resubmit it */ | 1093 | /* error in the urb, so we have to resubmit it */ |
974 | dbg("%s - Overflow in write", __FUNCTION__); | 1094 | dbg("%s - Overflow in write", __FUNCTION__); |
975 | dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status); | 1095 | dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, |
1096 | urb->status); | ||
976 | port->write_urb->transfer_buffer_length = 1; | 1097 | port->write_urb->transfer_buffer_length = 1; |
977 | port->write_urb->dev = port->serial->dev; | 1098 | port->write_urb->dev = port->serial->dev; |
978 | result = usb_submit_urb (port->write_urb, GFP_ATOMIC); | 1099 | result = usb_submit_urb(port->write_urb, GFP_ATOMIC); |
979 | if (result) | 1100 | if (result) |
980 | dev_err(&urb->dev->dev, "%s - failed resubmitting write urb, error %d\n", __FUNCTION__, result); | 1101 | dev_err(&urb->dev->dev, "%s - failed resubmitting write" |
1102 | " urb, error %d\n", __FUNCTION__, result); | ||
981 | else | 1103 | else |
982 | return; | 1104 | return; |
983 | } | 1105 | } |
@@ -988,191 +1110,38 @@ static void pl2303_write_bulk_callback (struct urb *urb, struct pt_regs *regs) | |||
988 | pl2303_send(port); | 1110 | pl2303_send(port); |
989 | } | 1111 | } |
990 | 1112 | ||
1113 | /* All of the device info needed for the PL2303 SIO serial converter */ | ||
1114 | static struct usb_serial_driver pl2303_device = { | ||
1115 | .driver = { | ||
1116 | .owner = THIS_MODULE, | ||
1117 | .name = "pl2303", | ||
1118 | }, | ||
1119 | .id_table = id_table, | ||
1120 | .num_interrupt_in = NUM_DONT_CARE, | ||
1121 | .num_bulk_in = 1, | ||
1122 | .num_bulk_out = 1, | ||
1123 | .num_ports = 1, | ||
1124 | .open = pl2303_open, | ||
1125 | .close = pl2303_close, | ||
1126 | .write = pl2303_write, | ||
1127 | .ioctl = pl2303_ioctl, | ||
1128 | .break_ctl = pl2303_break_ctl, | ||
1129 | .set_termios = pl2303_set_termios, | ||
1130 | .tiocmget = pl2303_tiocmget, | ||
1131 | .tiocmset = pl2303_tiocmset, | ||
1132 | .read_bulk_callback = pl2303_read_bulk_callback, | ||
1133 | .read_int_callback = pl2303_read_int_callback, | ||
1134 | .write_bulk_callback = pl2303_write_bulk_callback, | ||
1135 | .write_room = pl2303_write_room, | ||
1136 | .chars_in_buffer = pl2303_chars_in_buffer, | ||
1137 | .attach = pl2303_startup, | ||
1138 | .shutdown = pl2303_shutdown, | ||
1139 | }; | ||
991 | 1140 | ||
992 | /* | 1141 | static int __init pl2303_init(void) |
993 | * pl2303_buf_alloc | ||
994 | * | ||
995 | * Allocate a circular buffer and all associated memory. | ||
996 | */ | ||
997 | |||
998 | static struct pl2303_buf *pl2303_buf_alloc(unsigned int size) | ||
999 | { | ||
1000 | |||
1001 | struct pl2303_buf *pb; | ||
1002 | |||
1003 | |||
1004 | if (size == 0) | ||
1005 | return NULL; | ||
1006 | |||
1007 | pb = (struct pl2303_buf *)kmalloc(sizeof(struct pl2303_buf), GFP_KERNEL); | ||
1008 | if (pb == NULL) | ||
1009 | return NULL; | ||
1010 | |||
1011 | pb->buf_buf = kmalloc(size, GFP_KERNEL); | ||
1012 | if (pb->buf_buf == NULL) { | ||
1013 | kfree(pb); | ||
1014 | return NULL; | ||
1015 | } | ||
1016 | |||
1017 | pb->buf_size = size; | ||
1018 | pb->buf_get = pb->buf_put = pb->buf_buf; | ||
1019 | |||
1020 | return pb; | ||
1021 | |||
1022 | } | ||
1023 | |||
1024 | |||
1025 | /* | ||
1026 | * pl2303_buf_free | ||
1027 | * | ||
1028 | * Free the buffer and all associated memory. | ||
1029 | */ | ||
1030 | |||
1031 | static void pl2303_buf_free(struct pl2303_buf *pb) | ||
1032 | { | ||
1033 | if (pb) { | ||
1034 | kfree(pb->buf_buf); | ||
1035 | kfree(pb); | ||
1036 | } | ||
1037 | } | ||
1038 | |||
1039 | |||
1040 | /* | ||
1041 | * pl2303_buf_clear | ||
1042 | * | ||
1043 | * Clear out all data in the circular buffer. | ||
1044 | */ | ||
1045 | |||
1046 | static void pl2303_buf_clear(struct pl2303_buf *pb) | ||
1047 | { | ||
1048 | if (pb != NULL) | ||
1049 | pb->buf_get = pb->buf_put; | ||
1050 | /* equivalent to a get of all data available */ | ||
1051 | } | ||
1052 | |||
1053 | |||
1054 | /* | ||
1055 | * pl2303_buf_data_avail | ||
1056 | * | ||
1057 | * Return the number of bytes of data available in the circular | ||
1058 | * buffer. | ||
1059 | */ | ||
1060 | |||
1061 | static unsigned int pl2303_buf_data_avail(struct pl2303_buf *pb) | ||
1062 | { | ||
1063 | if (pb != NULL) | ||
1064 | return ((pb->buf_size + pb->buf_put - pb->buf_get) % pb->buf_size); | ||
1065 | else | ||
1066 | return 0; | ||
1067 | } | ||
1068 | |||
1069 | |||
1070 | /* | ||
1071 | * pl2303_buf_space_avail | ||
1072 | * | ||
1073 | * Return the number of bytes of space available in the circular | ||
1074 | * buffer. | ||
1075 | */ | ||
1076 | |||
1077 | static unsigned int pl2303_buf_space_avail(struct pl2303_buf *pb) | ||
1078 | { | ||
1079 | if (pb != NULL) | ||
1080 | return ((pb->buf_size + pb->buf_get - pb->buf_put - 1) % pb->buf_size); | ||
1081 | else | ||
1082 | return 0; | ||
1083 | } | ||
1084 | |||
1085 | |||
1086 | /* | ||
1087 | * pl2303_buf_put | ||
1088 | * | ||
1089 | * Copy data data from a user buffer and put it into the circular buffer. | ||
1090 | * Restrict to the amount of space available. | ||
1091 | * | ||
1092 | * Return the number of bytes copied. | ||
1093 | */ | ||
1094 | |||
1095 | static unsigned int pl2303_buf_put(struct pl2303_buf *pb, const char *buf, | ||
1096 | unsigned int count) | ||
1097 | { | ||
1098 | |||
1099 | unsigned int len; | ||
1100 | |||
1101 | |||
1102 | if (pb == NULL) | ||
1103 | return 0; | ||
1104 | |||
1105 | len = pl2303_buf_space_avail(pb); | ||
1106 | if (count > len) | ||
1107 | count = len; | ||
1108 | |||
1109 | if (count == 0) | ||
1110 | return 0; | ||
1111 | |||
1112 | len = pb->buf_buf + pb->buf_size - pb->buf_put; | ||
1113 | if (count > len) { | ||
1114 | memcpy(pb->buf_put, buf, len); | ||
1115 | memcpy(pb->buf_buf, buf+len, count - len); | ||
1116 | pb->buf_put = pb->buf_buf + count - len; | ||
1117 | } else { | ||
1118 | memcpy(pb->buf_put, buf, count); | ||
1119 | if (count < len) | ||
1120 | pb->buf_put += count; | ||
1121 | else /* count == len */ | ||
1122 | pb->buf_put = pb->buf_buf; | ||
1123 | } | ||
1124 | |||
1125 | return count; | ||
1126 | |||
1127 | } | ||
1128 | |||
1129 | |||
1130 | /* | ||
1131 | * pl2303_buf_get | ||
1132 | * | ||
1133 | * Get data from the circular buffer and copy to the given buffer. | ||
1134 | * Restrict to the amount of data available. | ||
1135 | * | ||
1136 | * Return the number of bytes copied. | ||
1137 | */ | ||
1138 | |||
1139 | static unsigned int pl2303_buf_get(struct pl2303_buf *pb, char *buf, | ||
1140 | unsigned int count) | ||
1141 | { | ||
1142 | |||
1143 | unsigned int len; | ||
1144 | |||
1145 | |||
1146 | if (pb == NULL) | ||
1147 | return 0; | ||
1148 | |||
1149 | len = pl2303_buf_data_avail(pb); | ||
1150 | if (count > len) | ||
1151 | count = len; | ||
1152 | |||
1153 | if (count == 0) | ||
1154 | return 0; | ||
1155 | |||
1156 | len = pb->buf_buf + pb->buf_size - pb->buf_get; | ||
1157 | if (count > len) { | ||
1158 | memcpy(buf, pb->buf_get, len); | ||
1159 | memcpy(buf+len, pb->buf_buf, count - len); | ||
1160 | pb->buf_get = pb->buf_buf + count - len; | ||
1161 | } else { | ||
1162 | memcpy(buf, pb->buf_get, count); | ||
1163 | if (count < len) | ||
1164 | pb->buf_get += count; | ||
1165 | else /* count == len */ | ||
1166 | pb->buf_get = pb->buf_buf; | ||
1167 | } | ||
1168 | |||
1169 | return count; | ||
1170 | |||
1171 | } | ||
1172 | |||
1173 | static int __init pl2303_init (void) | ||
1174 | { | 1142 | { |
1175 | int retval; | 1143 | int retval; |
1144 | |||
1176 | retval = usb_serial_register(&pl2303_device); | 1145 | retval = usb_serial_register(&pl2303_device); |
1177 | if (retval) | 1146 | if (retval) |
1178 | goto failed_usb_serial_register; | 1147 | goto failed_usb_serial_register; |
@@ -1187,14 +1156,12 @@ failed_usb_serial_register: | |||
1187 | return retval; | 1156 | return retval; |
1188 | } | 1157 | } |
1189 | 1158 | ||
1190 | 1159 | static void __exit pl2303_exit(void) | |
1191 | static void __exit pl2303_exit (void) | ||
1192 | { | 1160 | { |
1193 | usb_deregister (&pl2303_driver); | 1161 | usb_deregister(&pl2303_driver); |
1194 | usb_serial_deregister (&pl2303_device); | 1162 | usb_serial_deregister(&pl2303_device); |
1195 | } | 1163 | } |
1196 | 1164 | ||
1197 | |||
1198 | module_init(pl2303_init); | 1165 | module_init(pl2303_init); |
1199 | module_exit(pl2303_exit); | 1166 | module_exit(pl2303_exit); |
1200 | 1167 | ||
diff --git a/drivers/usb/serial/pl2303.h b/drivers/usb/serial/pl2303.h index 55195e76eb6f..762cc290ef58 100644 --- a/drivers/usb/serial/pl2303.h +++ b/drivers/usb/serial/pl2303.h | |||
@@ -89,3 +89,7 @@ | |||
89 | /* Belkin "F5U257" Serial Adapter */ | 89 | /* Belkin "F5U257" Serial Adapter */ |
90 | #define BELKIN_VENDOR_ID 0x050d | 90 | #define BELKIN_VENDOR_ID 0x050d |
91 | #define BELKIN_PRODUCT_ID 0x0257 | 91 | #define BELKIN_PRODUCT_ID 0x0257 |
92 | |||
93 | /* Alcor Micro Corp. USB 2.0 TO RS-232 */ | ||
94 | #define ALCOR_VENDOR_ID 0x058F | ||
95 | #define ALCOR_PRODUCT_ID 0x9720 | ||
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c index e06a41bd0f3b..0222d92842b8 100644 --- a/drivers/usb/serial/usb-serial.c +++ b/drivers/usb/serial/usb-serial.c | |||
@@ -676,33 +676,29 @@ int usb_serial_probe(struct usb_interface *interface, | |||
676 | iface_desc = interface->cur_altsetting; | 676 | iface_desc = interface->cur_altsetting; |
677 | for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { | 677 | for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { |
678 | endpoint = &iface_desc->endpoint[i].desc; | 678 | endpoint = &iface_desc->endpoint[i].desc; |
679 | 679 | ||
680 | if ((endpoint->bEndpointAddress & 0x80) && | 680 | if (usb_endpoint_is_bulk_in(endpoint)) { |
681 | ((endpoint->bmAttributes & 3) == 0x02)) { | ||
682 | /* we found a bulk in endpoint */ | 681 | /* we found a bulk in endpoint */ |
683 | dbg("found bulk in on endpoint %d", i); | 682 | dbg("found bulk in on endpoint %d", i); |
684 | bulk_in_endpoint[num_bulk_in] = endpoint; | 683 | bulk_in_endpoint[num_bulk_in] = endpoint; |
685 | ++num_bulk_in; | 684 | ++num_bulk_in; |
686 | } | 685 | } |
687 | 686 | ||
688 | if (((endpoint->bEndpointAddress & 0x80) == 0x00) && | 687 | if (usb_endpoint_is_bulk_out(endpoint)) { |
689 | ((endpoint->bmAttributes & 3) == 0x02)) { | ||
690 | /* we found a bulk out endpoint */ | 688 | /* we found a bulk out endpoint */ |
691 | dbg("found bulk out on endpoint %d", i); | 689 | dbg("found bulk out on endpoint %d", i); |
692 | bulk_out_endpoint[num_bulk_out] = endpoint; | 690 | bulk_out_endpoint[num_bulk_out] = endpoint; |
693 | ++num_bulk_out; | 691 | ++num_bulk_out; |
694 | } | 692 | } |
695 | 693 | ||
696 | if ((endpoint->bEndpointAddress & 0x80) && | 694 | if (usb_endpoint_is_int_in(endpoint)) { |
697 | ((endpoint->bmAttributes & 3) == 0x03)) { | ||
698 | /* we found a interrupt in endpoint */ | 695 | /* we found a interrupt in endpoint */ |
699 | dbg("found interrupt in on endpoint %d", i); | 696 | dbg("found interrupt in on endpoint %d", i); |
700 | interrupt_in_endpoint[num_interrupt_in] = endpoint; | 697 | interrupt_in_endpoint[num_interrupt_in] = endpoint; |
701 | ++num_interrupt_in; | 698 | ++num_interrupt_in; |
702 | } | 699 | } |
703 | 700 | ||
704 | if (((endpoint->bEndpointAddress & 0x80) == 0x00) && | 701 | if (usb_endpoint_is_int_out(endpoint)) { |
705 | ((endpoint->bmAttributes & 3) == 0x03)) { | ||
706 | /* we found an interrupt out endpoint */ | 702 | /* we found an interrupt out endpoint */ |
707 | dbg("found interrupt out on endpoint %d", i); | 703 | dbg("found interrupt out on endpoint %d", i); |
708 | interrupt_out_endpoint[num_interrupt_out] = endpoint; | 704 | interrupt_out_endpoint[num_interrupt_out] = endpoint; |
@@ -716,14 +712,15 @@ int usb_serial_probe(struct usb_interface *interface, | |||
716 | if (((le16_to_cpu(dev->descriptor.idVendor) == PL2303_VENDOR_ID) && | 712 | if (((le16_to_cpu(dev->descriptor.idVendor) == PL2303_VENDOR_ID) && |
717 | (le16_to_cpu(dev->descriptor.idProduct) == PL2303_PRODUCT_ID)) || | 713 | (le16_to_cpu(dev->descriptor.idProduct) == PL2303_PRODUCT_ID)) || |
718 | ((le16_to_cpu(dev->descriptor.idVendor) == ATEN_VENDOR_ID) && | 714 | ((le16_to_cpu(dev->descriptor.idVendor) == ATEN_VENDOR_ID) && |
719 | (le16_to_cpu(dev->descriptor.idProduct) == ATEN_PRODUCT_ID))) { | 715 | (le16_to_cpu(dev->descriptor.idProduct) == ATEN_PRODUCT_ID)) || |
716 | ((le16_to_cpu(dev->descriptor.idVendor) == ALCOR_VENDOR_ID) && | ||
717 | (le16_to_cpu(dev->descriptor.idProduct) == ALCOR_PRODUCT_ID))) { | ||
720 | if (interface != dev->actconfig->interface[0]) { | 718 | if (interface != dev->actconfig->interface[0]) { |
721 | /* check out the endpoints of the other interface*/ | 719 | /* check out the endpoints of the other interface*/ |
722 | iface_desc = dev->actconfig->interface[0]->cur_altsetting; | 720 | iface_desc = dev->actconfig->interface[0]->cur_altsetting; |
723 | for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { | 721 | for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { |
724 | endpoint = &iface_desc->endpoint[i].desc; | 722 | endpoint = &iface_desc->endpoint[i].desc; |
725 | if ((endpoint->bEndpointAddress & 0x80) && | 723 | if (usb_endpoint_is_int_in(endpoint)) { |
726 | ((endpoint->bmAttributes & 3) == 0x03)) { | ||
727 | /* we found a interrupt in endpoint */ | 724 | /* we found a interrupt in endpoint */ |
728 | dbg("found interrupt in for Prolific device on separate interface"); | 725 | dbg("found interrupt in for Prolific device on separate interface"); |
729 | interrupt_in_endpoint[num_interrupt_in] = endpoint; | 726 | interrupt_in_endpoint[num_interrupt_in] = endpoint; |
@@ -937,7 +934,10 @@ int usb_serial_probe(struct usb_interface *interface, | |||
937 | 934 | ||
938 | snprintf (&port->dev.bus_id[0], sizeof(port->dev.bus_id), "ttyUSB%d", port->number); | 935 | snprintf (&port->dev.bus_id[0], sizeof(port->dev.bus_id), "ttyUSB%d", port->number); |
939 | dbg ("%s - registering %s", __FUNCTION__, port->dev.bus_id); | 936 | dbg ("%s - registering %s", __FUNCTION__, port->dev.bus_id); |
940 | device_register (&port->dev); | 937 | retval = device_register(&port->dev); |
938 | if (retval) | ||
939 | dev_err(&port->dev, "Error registering port device, " | ||
940 | "continuing\n"); | ||
941 | } | 941 | } |
942 | 942 | ||
943 | usb_serial_console_init (debug, minor); | 943 | usb_serial_console_init (debug, minor); |