]>
Commit | Line | Data |
---|---|---|
52af9545 BP |
1 | /* |
2 | * usb-serial driver for Quatech SSU-100 | |
3 | * | |
4 | * based on ftdi_sio.c and the original serqt_usb.c from Quatech | |
5 | * | |
6 | */ | |
7 | ||
8 | #include <linux/errno.h> | |
9 | #include <linux/init.h> | |
10 | #include <linux/slab.h> | |
11 | #include <linux/tty.h> | |
12 | #include <linux/tty_driver.h> | |
13 | #include <linux/tty_flip.h> | |
14 | #include <linux/module.h> | |
15 | #include <linux/serial.h> | |
16 | #include <linux/usb.h> | |
17 | #include <linux/usb/serial.h> | |
79f203a2 | 18 | #include <linux/serial_reg.h> |
52af9545 BP |
19 | #include <linux/uaccess.h> |
20 | ||
21 | #define QT_OPEN_CLOSE_CHANNEL 0xca | |
22 | #define QT_SET_GET_DEVICE 0xc2 | |
23 | #define QT_SET_GET_REGISTER 0xc0 | |
24 | #define QT_GET_SET_PREBUF_TRIG_LVL 0xcc | |
25 | #define QT_SET_ATF 0xcd | |
26 | #define QT_GET_SET_UART 0xc1 | |
27 | #define QT_TRANSFER_IN 0xc0 | |
28 | #define QT_HW_FLOW_CONTROL_MASK 0xc5 | |
29 | #define QT_SW_FLOW_CONTROL_MASK 0xc6 | |
30 | ||
52af9545 BP |
31 | #define SERIAL_MSR_MASK 0xf0 |
32 | ||
79f203a2 | 33 | #define SERIAL_CRTSCTS ((UART_MCR_RTS << 8) | UART_MSR_CTS) |
52af9545 | 34 | |
79f203a2 | 35 | #define SERIAL_EVEN_PARITY (UART_LCR_PARITY | UART_LCR_EPAR) |
52af9545 BP |
36 | |
37 | #define MAX_BAUD_RATE 460800 | |
38 | ||
39 | #define ATC_DISABLED 0x00 | |
40 | #define DUPMODE_BITS 0xc0 | |
41 | #define RR_BITS 0x03 | |
42 | #define LOOPMODE_BITS 0x41 | |
43 | #define RS232_MODE 0x00 | |
44 | #define RTSCTS_TO_CONNECTOR 0x40 | |
45 | #define CLKS_X4 0x02 | |
46 | #define FULLPWRBIT 0x00000080 | |
47 | #define NEXT_BOARD_POWER_BIT 0x00000004 | |
48 | ||
49 | static int debug = 1; | |
50 | ||
51 | /* Version Information */ | |
52 | #define DRIVER_VERSION "v0.1" | |
53 | #define DRIVER_DESC "Quatech SSU-100 USB to Serial Driver" | |
54 | ||
55 | #define USB_VENDOR_ID_QUATECH 0x061d /* Quatech VID */ | |
56 | #define QUATECH_SSU100 0xC020 /* SSU100 */ | |
57 | ||
58 | static const struct usb_device_id id_table[] = { | |
59 | {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_SSU100)}, | |
60 | {} /* Terminating entry */ | |
61 | }; | |
62 | ||
63 | MODULE_DEVICE_TABLE(usb, id_table); | |
64 | ||
65 | ||
66 | static struct usb_driver ssu100_driver = { | |
67 | .name = "ssu100", | |
68 | .probe = usb_serial_probe, | |
69 | .disconnect = usb_serial_disconnect, | |
70 | .id_table = id_table, | |
71 | .suspend = usb_serial_suspend, | |
72 | .resume = usb_serial_resume, | |
73 | .no_dynamic_id = 1, | |
74 | .supports_autosuspend = 1, | |
75 | }; | |
76 | ||
77 | struct ssu100_port_private { | |
17523058 | 78 | spinlock_t status_lock; |
52af9545 BP |
79 | u8 shadowLSR; |
80 | u8 shadowMSR; | |
81 | wait_queue_head_t delta_msr_wait; /* Used for TIOCMIWAIT */ | |
82 | unsigned short max_packet_size; | |
83 | }; | |
84 | ||
85 | static void ssu100_release(struct usb_serial *serial) | |
86 | { | |
87 | struct ssu100_port_private *priv = usb_get_serial_port_data(*serial->port); | |
88 | ||
89 | dbg("%s", __func__); | |
90 | kfree(priv); | |
91 | } | |
92 | ||
93 | static inline int ssu100_control_msg(struct usb_device *dev, | |
94 | u8 request, u16 data, u16 index) | |
95 | { | |
96 | return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), | |
97 | request, 0x40, data, index, | |
98 | NULL, 0, 300); | |
99 | } | |
100 | ||
101 | static inline int ssu100_setdevice(struct usb_device *dev, u8 *data) | |
102 | { | |
103 | u16 x = ((u16)(data[1] << 8) | (u16)(data[0])); | |
104 | ||
105 | return ssu100_control_msg(dev, QT_SET_GET_DEVICE, x, 0); | |
106 | } | |
107 | ||
108 | ||
109 | static inline int ssu100_getdevice(struct usb_device *dev, u8 *data) | |
110 | { | |
111 | return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), | |
112 | QT_SET_GET_DEVICE, 0xc0, 0, 0, | |
113 | data, 3, 300); | |
114 | } | |
115 | ||
116 | static inline int ssu100_getregister(struct usb_device *dev, | |
117 | unsigned short uart, | |
118 | unsigned short reg, | |
119 | u8 *data) | |
120 | { | |
121 | return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), | |
122 | QT_SET_GET_REGISTER, 0xc0, reg, | |
123 | uart, data, sizeof(*data), 300); | |
124 | ||
125 | } | |
126 | ||
127 | ||
128 | static inline int ssu100_setregister(struct usb_device *dev, | |
129 | unsigned short uart, | |
556f1a0e | 130 | unsigned short reg, |
52af9545 BP |
131 | u16 data) |
132 | { | |
556f1a0e | 133 | u16 value = (data << 8) | reg; |
52af9545 BP |
134 | |
135 | return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), | |
136 | QT_SET_GET_REGISTER, 0x40, value, uart, | |
137 | NULL, 0, 300); | |
138 | ||
139 | } | |
140 | ||
141 | #define set_mctrl(dev, set) update_mctrl((dev), (set), 0) | |
142 | #define clear_mctrl(dev, clear) update_mctrl((dev), 0, (clear)) | |
143 | ||
144 | /* these do not deal with device that have more than 1 port */ | |
145 | static inline int update_mctrl(struct usb_device *dev, unsigned int set, | |
146 | unsigned int clear) | |
147 | { | |
148 | unsigned urb_value; | |
149 | int result; | |
150 | ||
151 | if (((set | clear) & (TIOCM_DTR | TIOCM_RTS)) == 0) { | |
152 | dbg("%s - DTR|RTS not being set|cleared", __func__); | |
153 | return 0; /* no change */ | |
154 | } | |
155 | ||
156 | clear &= ~set; /* 'set' takes precedence over 'clear' */ | |
157 | urb_value = 0; | |
158 | if (set & TIOCM_DTR) | |
79f203a2 | 159 | urb_value |= UART_MCR_DTR; |
52af9545 | 160 | if (set & TIOCM_RTS) |
79f203a2 | 161 | urb_value |= UART_MCR_RTS; |
52af9545 | 162 | |
556f1a0e | 163 | result = ssu100_setregister(dev, 0, UART_MCR, urb_value); |
52af9545 BP |
164 | if (result < 0) |
165 | dbg("%s Error from MODEM_CTRL urb", __func__); | |
166 | ||
167 | return result; | |
168 | } | |
169 | ||
170 | static int ssu100_initdevice(struct usb_device *dev) | |
171 | { | |
172 | u8 *data; | |
173 | int result = 0; | |
174 | ||
175 | dbg("%s", __func__); | |
176 | ||
177 | data = kzalloc(3, GFP_KERNEL); | |
178 | if (!data) | |
179 | return -ENOMEM; | |
180 | ||
181 | result = ssu100_getdevice(dev, data); | |
182 | if (result < 0) { | |
183 | dbg("%s - get_device failed %i", __func__, result); | |
184 | goto out; | |
185 | } | |
186 | ||
187 | data[1] &= ~FULLPWRBIT; | |
188 | ||
189 | result = ssu100_setdevice(dev, data); | |
190 | if (result < 0) { | |
191 | dbg("%s - setdevice failed %i", __func__, result); | |
192 | goto out; | |
193 | } | |
194 | ||
195 | result = ssu100_control_msg(dev, QT_GET_SET_PREBUF_TRIG_LVL, 128, 0); | |
196 | if (result < 0) { | |
197 | dbg("%s - set prebuffer level failed %i", __func__, result); | |
198 | goto out; | |
199 | } | |
200 | ||
201 | result = ssu100_control_msg(dev, QT_SET_ATF, ATC_DISABLED, 0); | |
202 | if (result < 0) { | |
203 | dbg("%s - set ATFprebuffer level failed %i", __func__, result); | |
204 | goto out; | |
205 | } | |
206 | ||
207 | result = ssu100_getdevice(dev, data); | |
208 | if (result < 0) { | |
209 | dbg("%s - get_device failed %i", __func__, result); | |
210 | goto out; | |
211 | } | |
212 | ||
213 | data[0] &= ~(RR_BITS | DUPMODE_BITS); | |
214 | data[0] |= CLKS_X4; | |
215 | data[1] &= ~(LOOPMODE_BITS); | |
216 | data[1] |= RS232_MODE; | |
217 | ||
218 | result = ssu100_setdevice(dev, data); | |
219 | if (result < 0) { | |
220 | dbg("%s - setdevice failed %i", __func__, result); | |
221 | goto out; | |
222 | } | |
223 | ||
224 | out: kfree(data); | |
225 | return result; | |
226 | ||
227 | } | |
228 | ||
229 | ||
230 | static void ssu100_set_termios(struct tty_struct *tty, | |
231 | struct usb_serial_port *port, | |
232 | struct ktermios *old_termios) | |
233 | { | |
234 | struct usb_device *dev = port->serial->dev; | |
235 | struct ktermios *termios = tty->termios; | |
236 | u16 baud, divisor, remainder; | |
237 | unsigned int cflag = termios->c_cflag; | |
238 | u16 urb_value = 0; /* will hold the new flags */ | |
239 | int result; | |
240 | ||
241 | dbg("%s", __func__); | |
242 | ||
243 | if (cflag & PARENB) { | |
244 | if (cflag & PARODD) | |
79f203a2 | 245 | urb_value |= UART_LCR_PARITY; |
52af9545 BP |
246 | else |
247 | urb_value |= SERIAL_EVEN_PARITY; | |
248 | } | |
249 | ||
250 | switch (cflag & CSIZE) { | |
251 | case CS5: | |
79f203a2 | 252 | urb_value |= UART_LCR_WLEN5; |
52af9545 BP |
253 | break; |
254 | case CS6: | |
79f203a2 | 255 | urb_value |= UART_LCR_WLEN6; |
52af9545 BP |
256 | break; |
257 | case CS7: | |
79f203a2 | 258 | urb_value |= UART_LCR_WLEN7; |
52af9545 BP |
259 | break; |
260 | default: | |
261 | case CS8: | |
79f203a2 | 262 | urb_value |= UART_LCR_WLEN8; |
52af9545 BP |
263 | break; |
264 | } | |
265 | ||
266 | baud = tty_get_baud_rate(tty); | |
267 | if (!baud) | |
268 | baud = 9600; | |
269 | ||
270 | dbg("%s - got baud = %d\n", __func__, baud); | |
271 | ||
272 | ||
273 | divisor = MAX_BAUD_RATE / baud; | |
274 | remainder = MAX_BAUD_RATE % baud; | |
275 | if (((remainder * 2) >= baud) && (baud != 110)) | |
276 | divisor++; | |
277 | ||
278 | urb_value = urb_value << 8; | |
279 | ||
280 | result = ssu100_control_msg(dev, QT_GET_SET_UART, divisor, urb_value); | |
281 | if (result < 0) | |
282 | dbg("%s - set uart failed", __func__); | |
283 | ||
284 | if (cflag & CRTSCTS) | |
285 | result = ssu100_control_msg(dev, QT_HW_FLOW_CONTROL_MASK, | |
286 | SERIAL_CRTSCTS, 0); | |
287 | else | |
288 | result = ssu100_control_msg(dev, QT_HW_FLOW_CONTROL_MASK, | |
289 | 0, 0); | |
290 | if (result < 0) | |
291 | dbg("%s - set HW flow control failed", __func__); | |
292 | ||
293 | if (I_IXOFF(tty) || I_IXON(tty)) { | |
294 | u16 x = ((u16)(START_CHAR(tty) << 8) | (u16)(STOP_CHAR(tty))); | |
295 | ||
296 | result = ssu100_control_msg(dev, QT_SW_FLOW_CONTROL_MASK, | |
297 | x, 0); | |
298 | } else | |
299 | result = ssu100_control_msg(dev, QT_SW_FLOW_CONTROL_MASK, | |
300 | 0, 0); | |
301 | ||
302 | if (result < 0) | |
303 | dbg("%s - set SW flow control failed", __func__); | |
304 | ||
305 | } | |
306 | ||
307 | ||
308 | static int ssu100_open(struct tty_struct *tty, struct usb_serial_port *port) | |
309 | { | |
310 | struct usb_device *dev = port->serial->dev; | |
311 | struct ssu100_port_private *priv = usb_get_serial_port_data(port); | |
312 | u8 *data; | |
313 | int result; | |
17523058 | 314 | unsigned long flags; |
52af9545 BP |
315 | |
316 | dbg("%s - port %d", __func__, port->number); | |
317 | ||
318 | data = kzalloc(2, GFP_KERNEL); | |
319 | if (!data) | |
320 | return -ENOMEM; | |
321 | ||
322 | result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), | |
323 | QT_OPEN_CLOSE_CHANNEL, | |
324 | QT_TRANSFER_IN, 0x01, | |
325 | 0, data, 2, 300); | |
326 | if (result < 0) { | |
327 | dbg("%s - open failed %i", __func__, result); | |
328 | kfree(data); | |
329 | return result; | |
330 | } | |
331 | ||
17523058 | 332 | spin_lock_irqsave(&priv->status_lock, flags); |
79f203a2 BP |
333 | priv->shadowLSR = data[0] & (UART_LSR_OE | UART_LSR_PE | |
334 | UART_LSR_FE | UART_LSR_BI); | |
52af9545 | 335 | |
79f203a2 BP |
336 | priv->shadowMSR = data[1] & (UART_MSR_CTS | UART_MSR_DSR | |
337 | UART_MSR_RI | UART_MSR_DCD); | |
17523058 | 338 | spin_unlock_irqrestore(&priv->status_lock, flags); |
52af9545 BP |
339 | |
340 | kfree(data); | |
341 | ||
342 | /* set to 9600 */ | |
343 | result = ssu100_control_msg(dev, QT_GET_SET_UART, 0x30, 0x0300); | |
344 | if (result < 0) | |
345 | dbg("%s - set uart failed", __func__); | |
346 | ||
347 | if (tty) | |
348 | ssu100_set_termios(tty, port, tty->termios); | |
349 | ||
350 | return usb_serial_generic_open(tty, port); | |
351 | } | |
352 | ||
353 | static void ssu100_close(struct usb_serial_port *port) | |
354 | { | |
355 | dbg("%s", __func__); | |
356 | usb_serial_generic_close(port); | |
357 | } | |
358 | ||
359 | static int get_serial_info(struct usb_serial_port *port, | |
360 | struct serial_struct __user *retinfo) | |
361 | { | |
362 | struct serial_struct tmp; | |
363 | ||
364 | if (!retinfo) | |
365 | return -EFAULT; | |
366 | ||
367 | memset(&tmp, 0, sizeof(tmp)); | |
368 | tmp.line = port->serial->minor; | |
369 | tmp.port = 0; | |
370 | tmp.irq = 0; | |
371 | tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ; | |
372 | tmp.xmit_fifo_size = port->bulk_out_size; | |
373 | tmp.baud_base = 9600; | |
374 | tmp.close_delay = 5*HZ; | |
375 | tmp.closing_wait = 30*HZ; | |
376 | ||
377 | if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) | |
378 | return -EFAULT; | |
379 | return 0; | |
380 | } | |
381 | ||
382 | static int ssu100_ioctl(struct tty_struct *tty, struct file *file, | |
383 | unsigned int cmd, unsigned long arg) | |
384 | { | |
385 | struct usb_serial_port *port = tty->driver_data; | |
386 | struct ssu100_port_private *priv = usb_get_serial_port_data(port); | |
387 | ||
388 | dbg("%s cmd 0x%04x", __func__, cmd); | |
389 | ||
390 | switch (cmd) { | |
391 | case TIOCGSERIAL: | |
392 | return get_serial_info(port, | |
393 | (struct serial_struct __user *) arg); | |
394 | ||
395 | case TIOCMIWAIT: | |
396 | while (priv != NULL) { | |
397 | u8 prevMSR = priv->shadowMSR & SERIAL_MSR_MASK; | |
398 | interruptible_sleep_on(&priv->delta_msr_wait); | |
399 | /* see if a signal did it */ | |
400 | if (signal_pending(current)) | |
401 | return -ERESTARTSYS; | |
402 | else { | |
403 | u8 diff = (priv->shadowMSR & SERIAL_MSR_MASK) ^ prevMSR; | |
404 | if (!diff) | |
405 | return -EIO; /* no change => error */ | |
406 | ||
407 | /* Return 0 if caller wanted to know about | |
408 | these bits */ | |
409 | ||
79f203a2 BP |
410 | if (((arg & TIOCM_RNG) && (diff & UART_MSR_RI)) || |
411 | ((arg & TIOCM_DSR) && (diff & UART_MSR_DSR)) || | |
412 | ((arg & TIOCM_CD) && (diff & UART_MSR_DCD)) || | |
413 | ((arg & TIOCM_CTS) && (diff & UART_MSR_CTS))) | |
52af9545 BP |
414 | return 0; |
415 | } | |
416 | } | |
417 | return 0; | |
418 | ||
419 | default: | |
420 | break; | |
421 | } | |
422 | ||
423 | dbg("%s arg not supported", __func__); | |
424 | ||
425 | return -ENOIOCTLCMD; | |
426 | } | |
427 | ||
428 | static void ssu100_set_max_packet_size(struct usb_serial_port *port) | |
429 | { | |
430 | struct ssu100_port_private *priv = usb_get_serial_port_data(port); | |
431 | struct usb_serial *serial = port->serial; | |
432 | struct usb_device *udev = serial->dev; | |
433 | ||
434 | struct usb_interface *interface = serial->interface; | |
435 | struct usb_endpoint_descriptor *ep_desc = &interface->cur_altsetting->endpoint[1].desc; | |
436 | ||
437 | unsigned num_endpoints; | |
438 | int i; | |
17523058 | 439 | unsigned long flags; |
52af9545 BP |
440 | |
441 | num_endpoints = interface->cur_altsetting->desc.bNumEndpoints; | |
442 | dev_info(&udev->dev, "Number of endpoints %d\n", num_endpoints); | |
443 | ||
444 | for (i = 0; i < num_endpoints; i++) { | |
445 | dev_info(&udev->dev, "Endpoint %d MaxPacketSize %d\n", i+1, | |
446 | interface->cur_altsetting->endpoint[i].desc.wMaxPacketSize); | |
447 | ep_desc = &interface->cur_altsetting->endpoint[i].desc; | |
448 | } | |
449 | ||
450 | /* set max packet size based on descriptor */ | |
17523058 | 451 | spin_lock_irqsave(&priv->status_lock, flags); |
52af9545 | 452 | priv->max_packet_size = ep_desc->wMaxPacketSize; |
17523058 | 453 | spin_unlock_irqrestore(&priv->status_lock, flags); |
52af9545 BP |
454 | |
455 | dev_info(&udev->dev, "Setting MaxPacketSize %d\n", priv->max_packet_size); | |
456 | } | |
457 | ||
458 | static int ssu100_attach(struct usb_serial *serial) | |
459 | { | |
460 | struct ssu100_port_private *priv; | |
461 | struct usb_serial_port *port = *serial->port; | |
462 | ||
463 | dbg("%s", __func__); | |
464 | ||
465 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); | |
466 | if (!priv) { | |
467 | dev_err(&port->dev, "%s- kmalloc(%Zd) failed.\n", __func__, | |
468 | sizeof(*priv)); | |
469 | return -ENOMEM; | |
470 | } | |
471 | ||
17523058 | 472 | spin_lock_init(&priv->status_lock); |
52af9545 BP |
473 | init_waitqueue_head(&priv->delta_msr_wait); |
474 | usb_set_serial_port_data(port, priv); | |
52af9545 BP |
475 | ssu100_set_max_packet_size(port); |
476 | ||
477 | return ssu100_initdevice(serial->dev); | |
478 | } | |
479 | ||
480 | static int ssu100_tiocmget(struct tty_struct *tty, struct file *file) | |
481 | { | |
482 | struct usb_serial_port *port = tty->driver_data; | |
483 | struct usb_device *dev = port->serial->dev; | |
484 | u8 *d; | |
485 | int r; | |
486 | ||
487 | dbg("%s\n", __func__); | |
488 | ||
489 | d = kzalloc(2, GFP_KERNEL); | |
490 | if (!d) | |
491 | return -ENOMEM; | |
492 | ||
79f203a2 | 493 | r = ssu100_getregister(dev, 0, UART_MCR, d); |
52af9545 BP |
494 | if (r < 0) |
495 | goto mget_out; | |
496 | ||
79f203a2 | 497 | r = ssu100_getregister(dev, 0, UART_MSR, d+1); |
52af9545 BP |
498 | if (r < 0) |
499 | goto mget_out; | |
500 | ||
79f203a2 BP |
501 | r = (d[0] & UART_MCR_DTR ? TIOCM_DTR : 0) | |
502 | (d[0] & UART_MCR_RTS ? TIOCM_RTS : 0) | | |
503 | (d[1] & UART_MSR_CTS ? TIOCM_CTS : 0) | | |
504 | (d[1] & UART_MSR_DCD ? TIOCM_CAR : 0) | | |
505 | (d[1] & UART_MSR_RI ? TIOCM_RI : 0) | | |
506 | (d[1] & UART_MSR_DSR ? TIOCM_DSR : 0); | |
52af9545 BP |
507 | |
508 | mget_out: | |
509 | kfree(d); | |
510 | return r; | |
511 | } | |
512 | ||
513 | static int ssu100_tiocmset(struct tty_struct *tty, struct file *file, | |
514 | unsigned int set, unsigned int clear) | |
515 | { | |
516 | struct usb_serial_port *port = tty->driver_data; | |
517 | struct usb_device *dev = port->serial->dev; | |
518 | ||
519 | dbg("%s\n", __func__); | |
520 | return update_mctrl(dev, set, clear); | |
521 | } | |
522 | ||
523 | static void ssu100_dtr_rts(struct usb_serial_port *port, int on) | |
524 | { | |
525 | struct usb_device *dev = port->serial->dev; | |
526 | ||
527 | dbg("%s\n", __func__); | |
528 | ||
529 | mutex_lock(&port->serial->disc_mutex); | |
530 | if (!port->serial->disconnected) { | |
531 | /* Disable flow control */ | |
532 | if (!on && | |
556f1a0e | 533 | ssu100_setregister(dev, 0, UART_MCR, 0) < 0) |
52af9545 BP |
534 | dev_err(&port->dev, "error from flowcontrol urb\n"); |
535 | /* drop RTS and DTR */ | |
536 | if (on) | |
537 | set_mctrl(dev, TIOCM_DTR | TIOCM_RTS); | |
538 | else | |
539 | clear_mctrl(dev, TIOCM_DTR | TIOCM_RTS); | |
540 | } | |
541 | mutex_unlock(&port->serial->disc_mutex); | |
542 | } | |
543 | ||
544 | static int ssu100_process_packet(struct tty_struct *tty, | |
545 | struct usb_serial_port *port, | |
546 | struct ssu100_port_private *priv, | |
547 | char *packet, int len) | |
548 | { | |
549 | int i; | |
550 | char flag; | |
551 | char *ch; | |
552 | ||
553 | dbg("%s - port %d", __func__, port->number); | |
554 | ||
9b2cef31 BP |
555 | if ((len >= 4) && |
556 | (packet[0] == 0x1b) && (packet[1] == 0x1b) && | |
52af9545 BP |
557 | ((packet[2] == 0x00) || (packet[2] == 0x01))) { |
558 | if (packet[2] == 0x00) | |
79f203a2 BP |
559 | priv->shadowLSR = packet[3] & (UART_LSR_OE | |
560 | UART_LSR_PE | | |
561 | UART_LSR_FE | | |
562 | UART_LSR_BI); | |
52af9545 BP |
563 | |
564 | if (packet[2] == 0x01) { | |
565 | priv->shadowMSR = packet[3]; | |
566 | wake_up_interruptible(&priv->delta_msr_wait); | |
567 | } | |
568 | ||
569 | len -= 4; | |
570 | ch = packet + 4; | |
571 | } else | |
572 | ch = packet; | |
573 | ||
574 | if (!len) | |
575 | return 0; /* status only */ | |
576 | ||
577 | if (port->port.console && port->sysrq) { | |
578 | for (i = 0; i < len; i++, ch++) { | |
579 | if (!usb_serial_handle_sysrq_char(tty, port, *ch)) | |
580 | tty_insert_flip_char(tty, *ch, flag); | |
581 | } | |
582 | } else | |
583 | tty_insert_flip_string_fixed_flag(tty, ch, flag, len); | |
584 | ||
585 | return len; | |
586 | } | |
587 | ||
588 | static void ssu100_process_read_urb(struct urb *urb) | |
589 | { | |
590 | struct usb_serial_port *port = urb->context; | |
591 | struct ssu100_port_private *priv = usb_get_serial_port_data(port); | |
592 | char *data = (char *)urb->transfer_buffer; | |
593 | struct tty_struct *tty; | |
594 | int count = 0; | |
595 | int i; | |
596 | int len; | |
597 | ||
598 | dbg("%s", __func__); | |
599 | ||
600 | tty = tty_port_tty_get(&port->port); | |
601 | if (!tty) | |
602 | return; | |
603 | ||
604 | for (i = 0; i < urb->actual_length; i += priv->max_packet_size) { | |
605 | len = min_t(int, urb->actual_length - i, priv->max_packet_size); | |
606 | count += ssu100_process_packet(tty, port, priv, &data[i], len); | |
607 | } | |
608 | ||
609 | if (count) | |
610 | tty_flip_buffer_push(tty); | |
611 | tty_kref_put(tty); | |
612 | } | |
613 | ||
614 | ||
615 | static struct usb_serial_driver ssu100_device = { | |
616 | .driver = { | |
617 | .owner = THIS_MODULE, | |
618 | .name = "ssu100", | |
619 | }, | |
620 | .description = DRIVER_DESC, | |
621 | .id_table = id_table, | |
622 | .usb_driver = &ssu100_driver, | |
623 | .num_ports = 1, | |
624 | .bulk_in_size = 256, | |
625 | .bulk_out_size = 256, | |
626 | .open = ssu100_open, | |
627 | .close = ssu100_close, | |
628 | .attach = ssu100_attach, | |
629 | .release = ssu100_release, | |
630 | .dtr_rts = ssu100_dtr_rts, | |
631 | .process_read_urb = ssu100_process_read_urb, | |
632 | .tiocmget = ssu100_tiocmget, | |
633 | .tiocmset = ssu100_tiocmset, | |
634 | .ioctl = ssu100_ioctl, | |
635 | .set_termios = ssu100_set_termios, | |
636 | }; | |
637 | ||
638 | static int __init ssu100_init(void) | |
639 | { | |
640 | int retval; | |
641 | ||
642 | dbg("%s", __func__); | |
643 | ||
644 | /* register with usb-serial */ | |
645 | retval = usb_serial_register(&ssu100_device); | |
646 | ||
647 | if (retval) | |
648 | goto failed_usb_sio_register; | |
649 | ||
650 | retval = usb_register(&ssu100_driver); | |
651 | if (retval) | |
652 | goto failed_usb_register; | |
653 | ||
654 | printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":" | |
655 | DRIVER_DESC "\n"); | |
656 | ||
657 | return 0; | |
658 | ||
659 | failed_usb_register: | |
660 | usb_serial_deregister(&ssu100_device); | |
661 | failed_usb_sio_register: | |
662 | return retval; | |
663 | } | |
664 | ||
665 | static void __exit ssu100_exit(void) | |
666 | { | |
667 | usb_deregister(&ssu100_driver); | |
668 | usb_serial_deregister(&ssu100_device); | |
669 | } | |
670 | ||
671 | module_init(ssu100_init); | |
672 | module_exit(ssu100_exit); | |
673 | ||
674 | MODULE_DESCRIPTION(DRIVER_DESC); | |
675 | MODULE_LICENSE("GPL"); | |
676 | ||
677 | module_param(debug, bool, S_IRUGO | S_IWUSR); | |
678 | MODULE_PARM_DESC(debug, "Debug enabled or not"); |