Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Belkin USB Serial Adapter Driver | |
3 | * | |
4 | * Copyright (C) 2000 William Greathouse (wgreathouse@smva.com) | |
5 | * Copyright (C) 2000-2001 Greg Kroah-Hartman (greg@kroah.com) | |
6 | * | |
7 | * This program is largely derived from work by the linux-usb group | |
8 | * and associated source files. Please see the usb/serial files for | |
9 | * individual credits and copyrights. | |
10 | * | |
11 | * This program is free software; you can redistribute it and/or modify | |
12 | * it under the terms of the GNU General Public License as published by | |
13 | * the Free Software Foundation; either version 2 of the License, or | |
14 | * (at your option) any later version. | |
15 | * | |
16 | * See Documentation/usb/usb-serial.txt for more information on using this driver | |
17 | * | |
18 | * TODO: | |
19 | * -- Add true modem contol line query capability. Currently we track the | |
20 | * states reported by the interrupt and the states we request. | |
21 | * -- Add error reporting back to application for UART error conditions. | |
22 | * Just point me at how to implement this and I'll do it. I've put the | |
23 | * framework in, but haven't analyzed the "tty_flip" interface yet. | |
24 | * -- Add support for flush commands | |
25 | * -- Add everything that is missing :) | |
26 | * | |
27 | * 27-Nov-2001 gkh | |
28 | * compressed all the differnent device entries into 1. | |
29 | * | |
30 | * 30-May-2001 gkh | |
31 | * switched from using spinlock to a semaphore, which fixes lots of problems. | |
32 | * | |
33 | * 08-Apr-2001 gb | |
34 | * - Identify version on module load. | |
35 | * | |
36 | * 12-Mar-2001 gkh | |
37 | * - Added support for the GoHubs GO-COM232 device which is the same as the | |
38 | * Peracom device. | |
39 | * | |
40 | * 06-Nov-2000 gkh | |
41 | * - Added support for the old Belkin and Peracom devices. | |
42 | * - Made the port able to be opened multiple times. | |
43 | * - Added some defaults incase the line settings are things these devices | |
44 | * can't support. | |
45 | * | |
46 | * 18-Oct-2000 William Greathouse | |
47 | * Released into the wild (linux-usb-devel) | |
48 | * | |
49 | * 17-Oct-2000 William Greathouse | |
50 | * Add code to recognize firmware version and set hardware flow control | |
51 | * appropriately. Belkin states that firmware prior to 3.05 does not | |
52 | * operate correctly in hardware handshake mode. I have verified this | |
53 | * on firmware 2.05 -- for both RTS and DTR input flow control, the control | |
54 | * line is not reset. The test performed by the Belkin Win* driver is | |
55 | * to enable hardware flow control for firmware 2.06 or greater and | |
56 | * for 1.00 or prior. I am only enabling for 2.06 or greater. | |
57 | * | |
58 | * 12-Oct-2000 William Greathouse | |
59 | * First cut at supporting Belkin USB Serial Adapter F5U103 | |
60 | * I did not have a copy of the original work to support this | |
61 | * adapter, so pardon any stupid mistakes. All of the information | |
62 | * I am using to write this driver was acquired by using a modified | |
63 | * UsbSnoop on Windows2000 and from examining the other USB drivers. | |
64 | */ | |
65 | ||
66 | #include <linux/config.h> | |
67 | #include <linux/kernel.h> | |
68 | #include <linux/errno.h> | |
69 | #include <linux/init.h> | |
70 | #include <linux/slab.h> | |
71 | #include <linux/tty.h> | |
72 | #include <linux/tty_driver.h> | |
73 | #include <linux/tty_flip.h> | |
74 | #include <linux/module.h> | |
75 | #include <linux/spinlock.h> | |
76 | #include <asm/uaccess.h> | |
77 | #include <linux/usb.h> | |
78 | #include "usb-serial.h" | |
79 | #include "belkin_sa.h" | |
80 | ||
81 | static int debug; | |
82 | ||
83 | /* | |
84 | * Version Information | |
85 | */ | |
86 | #define DRIVER_VERSION "v1.2" | |
87 | #define DRIVER_AUTHOR "William Greathouse <wgreathouse@smva.com>" | |
88 | #define DRIVER_DESC "USB Belkin Serial converter driver" | |
89 | ||
90 | /* function prototypes for a Belkin USB Serial Adapter F5U103 */ | |
91 | static int belkin_sa_startup (struct usb_serial *serial); | |
92 | static void belkin_sa_shutdown (struct usb_serial *serial); | |
93 | static int belkin_sa_open (struct usb_serial_port *port, struct file *filp); | |
94 | static void belkin_sa_close (struct usb_serial_port *port, struct file *filp); | |
95 | static void belkin_sa_read_int_callback (struct urb *urb, struct pt_regs *regs); | |
96 | static void belkin_sa_set_termios (struct usb_serial_port *port, struct termios * old); | |
97 | static int belkin_sa_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg); | |
98 | static void belkin_sa_break_ctl (struct usb_serial_port *port, int break_state ); | |
99 | static int belkin_sa_tiocmget (struct usb_serial_port *port, struct file *file); | |
100 | static int belkin_sa_tiocmset (struct usb_serial_port *port, struct file *file, unsigned int set, unsigned int clear); | |
101 | ||
102 | ||
103 | static struct usb_device_id id_table_combined [] = { | |
104 | { USB_DEVICE(BELKIN_SA_VID, BELKIN_SA_PID) }, | |
105 | { USB_DEVICE(BELKIN_OLD_VID, BELKIN_OLD_PID) }, | |
106 | { USB_DEVICE(PERACOM_VID, PERACOM_PID) }, | |
107 | { USB_DEVICE(GOHUBS_VID, GOHUBS_PID) }, | |
108 | { USB_DEVICE(GOHUBS_VID, HANDYLINK_PID) }, | |
109 | { USB_DEVICE(BELKIN_DOCKSTATION_VID, BELKIN_DOCKSTATION_PID) }, | |
110 | { } /* Terminating entry */ | |
111 | }; | |
112 | ||
113 | MODULE_DEVICE_TABLE (usb, id_table_combined); | |
114 | ||
115 | static struct usb_driver belkin_driver = { | |
116 | .owner = THIS_MODULE, | |
117 | .name = "belkin", | |
118 | .probe = usb_serial_probe, | |
119 | .disconnect = usb_serial_disconnect, | |
120 | .id_table = id_table_combined, | |
ba9dc657 | 121 | .no_dynamic_id = 1, |
1da177e4 LT |
122 | }; |
123 | ||
124 | /* All of the device info needed for the serial converters */ | |
ea65370d | 125 | static struct usb_serial_driver belkin_device = { |
18fcac35 GKH |
126 | .driver = { |
127 | .owner = THIS_MODULE, | |
269bda1c | 128 | .name = "belkin", |
18fcac35 | 129 | }, |
269bda1c | 130 | .description = "Belkin / Peracom / GoHubs USB Serial Adapter", |
1da177e4 LT |
131 | .id_table = id_table_combined, |
132 | .num_interrupt_in = 1, | |
133 | .num_bulk_in = 1, | |
134 | .num_bulk_out = 1, | |
135 | .num_ports = 1, | |
136 | .open = belkin_sa_open, | |
137 | .close = belkin_sa_close, | |
138 | .read_int_callback = belkin_sa_read_int_callback, /* How we get the status info */ | |
139 | .ioctl = belkin_sa_ioctl, | |
140 | .set_termios = belkin_sa_set_termios, | |
141 | .break_ctl = belkin_sa_break_ctl, | |
142 | .tiocmget = belkin_sa_tiocmget, | |
143 | .tiocmset = belkin_sa_tiocmset, | |
144 | .attach = belkin_sa_startup, | |
145 | .shutdown = belkin_sa_shutdown, | |
146 | }; | |
147 | ||
148 | ||
149 | struct belkin_sa_private { | |
150 | spinlock_t lock; | |
151 | unsigned long control_state; | |
152 | unsigned char last_lsr; | |
153 | unsigned char last_msr; | |
154 | int bad_flow_control; | |
155 | }; | |
156 | ||
157 | ||
158 | /* | |
159 | * *************************************************************************** | |
160 | * Belkin USB Serial Adapter F5U103 specific driver functions | |
161 | * *************************************************************************** | |
162 | */ | |
163 | ||
164 | #define WDR_TIMEOUT 5000 /* default urb timeout */ | |
165 | ||
166 | /* assumes that struct usb_serial *serial is available */ | |
167 | #define BSA_USB_CMD(c,v) usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), \ | |
168 | (c), BELKIN_SA_SET_REQUEST_TYPE, \ | |
169 | (v), 0, NULL, 0, WDR_TIMEOUT) | |
170 | ||
171 | /* do some startup allocations not currently performed by usb_serial_probe() */ | |
172 | static int belkin_sa_startup (struct usb_serial *serial) | |
173 | { | |
174 | struct usb_device *dev = serial->dev; | |
175 | struct belkin_sa_private *priv; | |
176 | ||
177 | /* allocate the private data structure */ | |
178 | priv = kmalloc(sizeof(struct belkin_sa_private), GFP_KERNEL); | |
179 | if (!priv) | |
180 | return (-1); /* error */ | |
181 | /* set initial values for control structures */ | |
182 | spin_lock_init(&priv->lock); | |
183 | priv->control_state = 0; | |
184 | priv->last_lsr = 0; | |
185 | priv->last_msr = 0; | |
186 | /* see comments at top of file */ | |
187 | priv->bad_flow_control = (le16_to_cpu(dev->descriptor.bcdDevice) <= 0x0206) ? 1 : 0; | |
188 | info("bcdDevice: %04x, bfc: %d", le16_to_cpu(dev->descriptor.bcdDevice), priv->bad_flow_control); | |
189 | ||
190 | init_waitqueue_head(&serial->port[0]->write_wait); | |
191 | usb_set_serial_port_data(serial->port[0], priv); | |
192 | ||
193 | return (0); | |
194 | } | |
195 | ||
196 | ||
197 | static void belkin_sa_shutdown (struct usb_serial *serial) | |
198 | { | |
199 | struct belkin_sa_private *priv; | |
200 | int i; | |
201 | ||
202 | dbg ("%s", __FUNCTION__); | |
203 | ||
204 | /* stop reads and writes on all ports */ | |
205 | for (i=0; i < serial->num_ports; ++i) { | |
206 | /* My special items, the standard routines free my urbs */ | |
207 | priv = usb_get_serial_port_data(serial->port[i]); | |
1bc3c9e1 | 208 | kfree(priv); |
1da177e4 LT |
209 | } |
210 | } | |
211 | ||
212 | ||
213 | static int belkin_sa_open (struct usb_serial_port *port, struct file *filp) | |
214 | { | |
215 | int retval = 0; | |
216 | ||
217 | dbg("%s port %d", __FUNCTION__, port->number); | |
218 | ||
219 | /*Start reading from the device*/ | |
220 | /* TODO: Look at possibility of submitting multiple URBs to device to | |
221 | * enhance buffering. Win trace shows 16 initial read URBs. | |
222 | */ | |
223 | port->read_urb->dev = port->serial->dev; | |
224 | retval = usb_submit_urb(port->read_urb, GFP_KERNEL); | |
225 | if (retval) { | |
226 | err("usb_submit_urb(read bulk) failed"); | |
227 | goto exit; | |
228 | } | |
229 | ||
230 | port->interrupt_in_urb->dev = port->serial->dev; | |
231 | retval = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); | |
232 | if (retval) { | |
233 | usb_kill_urb(port->read_urb); | |
234 | err(" usb_submit_urb(read int) failed"); | |
235 | } | |
236 | ||
237 | exit: | |
238 | return retval; | |
239 | } /* belkin_sa_open */ | |
240 | ||
241 | ||
242 | static void belkin_sa_close (struct usb_serial_port *port, struct file *filp) | |
243 | { | |
244 | dbg("%s port %d", __FUNCTION__, port->number); | |
245 | ||
246 | /* shutdown our bulk reads and writes */ | |
247 | usb_kill_urb(port->write_urb); | |
248 | usb_kill_urb(port->read_urb); | |
249 | usb_kill_urb(port->interrupt_in_urb); | |
250 | } /* belkin_sa_close */ | |
251 | ||
252 | ||
253 | static void belkin_sa_read_int_callback (struct urb *urb, struct pt_regs *regs) | |
254 | { | |
255 | struct usb_serial_port *port = (struct usb_serial_port *)urb->context; | |
256 | struct belkin_sa_private *priv; | |
257 | unsigned char *data = urb->transfer_buffer; | |
258 | int retval; | |
259 | unsigned long flags; | |
260 | ||
261 | switch (urb->status) { | |
262 | case 0: | |
263 | /* success */ | |
264 | break; | |
265 | case -ECONNRESET: | |
266 | case -ENOENT: | |
267 | case -ESHUTDOWN: | |
268 | /* this urb is terminated, clean up */ | |
269 | dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status); | |
270 | return; | |
271 | default: | |
272 | dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status); | |
273 | goto exit; | |
274 | } | |
275 | ||
276 | usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data); | |
277 | ||
278 | /* Handle known interrupt data */ | |
279 | /* ignore data[0] and data[1] */ | |
280 | ||
281 | priv = usb_get_serial_port_data(port); | |
282 | spin_lock_irqsave(&priv->lock, flags); | |
283 | priv->last_msr = data[BELKIN_SA_MSR_INDEX]; | |
284 | ||
285 | /* Record Control Line states */ | |
286 | if (priv->last_msr & BELKIN_SA_MSR_DSR) | |
287 | priv->control_state |= TIOCM_DSR; | |
288 | else | |
289 | priv->control_state &= ~TIOCM_DSR; | |
290 | ||
291 | if (priv->last_msr & BELKIN_SA_MSR_CTS) | |
292 | priv->control_state |= TIOCM_CTS; | |
293 | else | |
294 | priv->control_state &= ~TIOCM_CTS; | |
295 | ||
296 | if (priv->last_msr & BELKIN_SA_MSR_RI) | |
297 | priv->control_state |= TIOCM_RI; | |
298 | else | |
299 | priv->control_state &= ~TIOCM_RI; | |
300 | ||
301 | if (priv->last_msr & BELKIN_SA_MSR_CD) | |
302 | priv->control_state |= TIOCM_CD; | |
303 | else | |
304 | priv->control_state &= ~TIOCM_CD; | |
305 | ||
306 | /* Now to report any errors */ | |
307 | priv->last_lsr = data[BELKIN_SA_LSR_INDEX]; | |
308 | #if 0 | |
309 | /* | |
310 | * fill in the flip buffer here, but I do not know the relation | |
311 | * to the current/next receive buffer or characters. I need | |
312 | * to look in to this before committing any code. | |
313 | */ | |
314 | if (priv->last_lsr & BELKIN_SA_LSR_ERR) { | |
315 | tty = port->tty; | |
316 | /* Overrun Error */ | |
317 | if (priv->last_lsr & BELKIN_SA_LSR_OE) { | |
318 | } | |
319 | /* Parity Error */ | |
320 | if (priv->last_lsr & BELKIN_SA_LSR_PE) { | |
321 | } | |
322 | /* Framing Error */ | |
323 | if (priv->last_lsr & BELKIN_SA_LSR_FE) { | |
324 | } | |
325 | /* Break Indicator */ | |
326 | if (priv->last_lsr & BELKIN_SA_LSR_BI) { | |
327 | } | |
328 | } | |
329 | #endif | |
330 | spin_unlock_irqrestore(&priv->lock, flags); | |
331 | exit: | |
332 | retval = usb_submit_urb (urb, GFP_ATOMIC); | |
333 | if (retval) | |
334 | err ("%s - usb_submit_urb failed with result %d", | |
335 | __FUNCTION__, retval); | |
336 | } | |
337 | ||
338 | static void belkin_sa_set_termios (struct usb_serial_port *port, struct termios *old_termios) | |
339 | { | |
340 | struct usb_serial *serial = port->serial; | |
341 | struct belkin_sa_private *priv = usb_get_serial_port_data(port); | |
342 | unsigned int iflag; | |
343 | unsigned int cflag; | |
344 | unsigned int old_iflag = 0; | |
345 | unsigned int old_cflag = 0; | |
346 | __u16 urb_value = 0; /* Will hold the new flags */ | |
347 | unsigned long flags; | |
348 | unsigned long control_state; | |
349 | int bad_flow_control; | |
350 | ||
351 | if ((!port->tty) || (!port->tty->termios)) { | |
352 | dbg ("%s - no tty or termios structure", __FUNCTION__); | |
353 | return; | |
354 | } | |
355 | ||
356 | iflag = port->tty->termios->c_iflag; | |
357 | cflag = port->tty->termios->c_cflag; | |
358 | ||
359 | /* get a local copy of the current port settings */ | |
360 | spin_lock_irqsave(&priv->lock, flags); | |
361 | control_state = priv->control_state; | |
362 | bad_flow_control = priv->bad_flow_control; | |
363 | spin_unlock_irqrestore(&priv->lock, flags); | |
364 | ||
365 | /* check that they really want us to change something */ | |
366 | if (old_termios) { | |
367 | if ((cflag == old_termios->c_cflag) && | |
368 | (RELEVANT_IFLAG(port->tty->termios->c_iflag) == RELEVANT_IFLAG(old_termios->c_iflag))) { | |
369 | dbg("%s - nothing to change...", __FUNCTION__); | |
370 | return; | |
371 | } | |
372 | old_iflag = old_termios->c_iflag; | |
373 | old_cflag = old_termios->c_cflag; | |
374 | } | |
375 | ||
376 | /* Set the baud rate */ | |
377 | if( (cflag&CBAUD) != (old_cflag&CBAUD) ) { | |
378 | /* reassert DTR and (maybe) RTS on transition from B0 */ | |
379 | if( (old_cflag&CBAUD) == B0 ) { | |
380 | control_state |= (TIOCM_DTR|TIOCM_RTS); | |
381 | if (BSA_USB_CMD(BELKIN_SA_SET_DTR_REQUEST, 1) < 0) | |
382 | err("Set DTR error"); | |
383 | /* don't set RTS if using hardware flow control */ | |
384 | if (!(old_cflag&CRTSCTS) ) | |
385 | if (BSA_USB_CMD(BELKIN_SA_SET_RTS_REQUEST, 1) < 0) | |
386 | err("Set RTS error"); | |
387 | } | |
388 | ||
389 | switch(cflag & CBAUD) { | |
390 | case B0: /* handled below */ break; | |
391 | case B300: urb_value = BELKIN_SA_BAUD(300); break; | |
392 | case B600: urb_value = BELKIN_SA_BAUD(600); break; | |
393 | case B1200: urb_value = BELKIN_SA_BAUD(1200); break; | |
394 | case B2400: urb_value = BELKIN_SA_BAUD(2400); break; | |
395 | case B4800: urb_value = BELKIN_SA_BAUD(4800); break; | |
396 | case B9600: urb_value = BELKIN_SA_BAUD(9600); break; | |
397 | case B19200: urb_value = BELKIN_SA_BAUD(19200); break; | |
398 | case B38400: urb_value = BELKIN_SA_BAUD(38400); break; | |
399 | case B57600: urb_value = BELKIN_SA_BAUD(57600); break; | |
400 | case B115200: urb_value = BELKIN_SA_BAUD(115200); break; | |
401 | case B230400: urb_value = BELKIN_SA_BAUD(230400); break; | |
402 | default: err("BELKIN USB Serial Adapter: unsupported baudrate request, using default of 9600"); | |
403 | urb_value = BELKIN_SA_BAUD(9600); break; | |
404 | } | |
405 | if ((cflag & CBAUD) != B0 ) { | |
406 | if (BSA_USB_CMD(BELKIN_SA_SET_BAUDRATE_REQUEST, urb_value) < 0) | |
407 | err("Set baudrate error"); | |
408 | } else { | |
409 | /* Disable flow control */ | |
410 | if (BSA_USB_CMD(BELKIN_SA_SET_FLOW_CTRL_REQUEST, BELKIN_SA_FLOW_NONE) < 0) | |
411 | err("Disable flowcontrol error"); | |
412 | ||
413 | /* Drop RTS and DTR */ | |
414 | control_state &= ~(TIOCM_DTR | TIOCM_RTS); | |
415 | if (BSA_USB_CMD(BELKIN_SA_SET_DTR_REQUEST, 0) < 0) | |
416 | err("DTR LOW error"); | |
417 | if (BSA_USB_CMD(BELKIN_SA_SET_RTS_REQUEST, 0) < 0) | |
418 | err("RTS LOW error"); | |
419 | } | |
420 | } | |
421 | ||
422 | /* set the parity */ | |
423 | if( (cflag&(PARENB|PARODD)) != (old_cflag&(PARENB|PARODD)) ) { | |
424 | if (cflag & PARENB) | |
425 | urb_value = (cflag & PARODD) ? BELKIN_SA_PARITY_ODD : BELKIN_SA_PARITY_EVEN; | |
426 | else | |
427 | urb_value = BELKIN_SA_PARITY_NONE; | |
428 | if (BSA_USB_CMD(BELKIN_SA_SET_PARITY_REQUEST, urb_value) < 0) | |
429 | err("Set parity error"); | |
430 | } | |
431 | ||
432 | /* set the number of data bits */ | |
433 | if( (cflag&CSIZE) != (old_cflag&CSIZE) ) { | |
434 | switch (cflag & CSIZE) { | |
435 | case CS5: urb_value = BELKIN_SA_DATA_BITS(5); break; | |
436 | case CS6: urb_value = BELKIN_SA_DATA_BITS(6); break; | |
437 | case CS7: urb_value = BELKIN_SA_DATA_BITS(7); break; | |
438 | case CS8: urb_value = BELKIN_SA_DATA_BITS(8); break; | |
439 | default: err("CSIZE was not CS5-CS8, using default of 8"); | |
440 | urb_value = BELKIN_SA_DATA_BITS(8); | |
441 | break; | |
442 | } | |
443 | if (BSA_USB_CMD(BELKIN_SA_SET_DATA_BITS_REQUEST, urb_value) < 0) | |
444 | err("Set data bits error"); | |
445 | } | |
446 | ||
447 | /* set the number of stop bits */ | |
448 | if( (cflag&CSTOPB) != (old_cflag&CSTOPB) ) { | |
449 | urb_value = (cflag & CSTOPB) ? BELKIN_SA_STOP_BITS(2) : BELKIN_SA_STOP_BITS(1); | |
450 | if (BSA_USB_CMD(BELKIN_SA_SET_STOP_BITS_REQUEST, urb_value) < 0) | |
451 | err("Set stop bits error"); | |
452 | } | |
453 | ||
454 | /* Set flow control */ | |
455 | if( (iflag&IXOFF) != (old_iflag&IXOFF) | |
456 | || (iflag&IXON) != (old_iflag&IXON) | |
457 | || (cflag&CRTSCTS) != (old_cflag&CRTSCTS) ) { | |
458 | urb_value = 0; | |
459 | if ((iflag & IXOFF) || (iflag & IXON)) | |
460 | urb_value |= (BELKIN_SA_FLOW_OXON | BELKIN_SA_FLOW_IXON); | |
461 | else | |
462 | urb_value &= ~(BELKIN_SA_FLOW_OXON | BELKIN_SA_FLOW_IXON); | |
463 | ||
464 | if (cflag & CRTSCTS) | |
465 | urb_value |= (BELKIN_SA_FLOW_OCTS | BELKIN_SA_FLOW_IRTS); | |
466 | else | |
467 | urb_value &= ~(BELKIN_SA_FLOW_OCTS | BELKIN_SA_FLOW_IRTS); | |
468 | ||
469 | if (bad_flow_control) | |
470 | urb_value &= ~(BELKIN_SA_FLOW_IRTS); | |
471 | ||
472 | if (BSA_USB_CMD(BELKIN_SA_SET_FLOW_CTRL_REQUEST, urb_value) < 0) | |
473 | err("Set flow control error"); | |
474 | } | |
475 | ||
476 | /* save off the modified port settings */ | |
477 | spin_lock_irqsave(&priv->lock, flags); | |
478 | priv->control_state = control_state; | |
479 | spin_unlock_irqrestore(&priv->lock, flags); | |
480 | } /* belkin_sa_set_termios */ | |
481 | ||
482 | ||
483 | static void belkin_sa_break_ctl( struct usb_serial_port *port, int break_state ) | |
484 | { | |
485 | struct usb_serial *serial = port->serial; | |
486 | ||
487 | if (BSA_USB_CMD(BELKIN_SA_SET_BREAK_REQUEST, break_state ? 1 : 0) < 0) | |
488 | err("Set break_ctl %d", break_state); | |
489 | } | |
490 | ||
491 | ||
492 | static int belkin_sa_tiocmget (struct usb_serial_port *port, struct file *file) | |
493 | { | |
494 | struct belkin_sa_private *priv = usb_get_serial_port_data(port); | |
495 | unsigned long control_state; | |
496 | unsigned long flags; | |
497 | ||
498 | dbg("%s", __FUNCTION__); | |
499 | ||
500 | spin_lock_irqsave(&priv->lock, flags); | |
501 | control_state = priv->control_state; | |
502 | spin_unlock_irqrestore(&priv->lock, flags); | |
503 | ||
504 | return control_state; | |
505 | } | |
506 | ||
507 | ||
508 | static int belkin_sa_tiocmset (struct usb_serial_port *port, struct file *file, | |
509 | unsigned int set, unsigned int clear) | |
510 | { | |
511 | struct usb_serial *serial = port->serial; | |
512 | struct belkin_sa_private *priv = usb_get_serial_port_data(port); | |
513 | unsigned long control_state; | |
514 | unsigned long flags; | |
515 | int retval; | |
516 | int rts = 0; | |
517 | int dtr = 0; | |
518 | ||
519 | dbg("%s", __FUNCTION__); | |
520 | ||
521 | spin_lock_irqsave(&priv->lock, flags); | |
522 | control_state = priv->control_state; | |
523 | ||
524 | if (set & TIOCM_RTS) { | |
525 | control_state |= TIOCM_RTS; | |
526 | rts = 1; | |
527 | } | |
528 | if (set & TIOCM_DTR) { | |
529 | control_state |= TIOCM_DTR; | |
530 | dtr = 1; | |
531 | } | |
532 | if (clear & TIOCM_RTS) { | |
533 | control_state &= ~TIOCM_RTS; | |
534 | rts = 0; | |
535 | } | |
536 | if (clear & TIOCM_DTR) { | |
537 | control_state &= ~TIOCM_DTR; | |
538 | dtr = 0; | |
539 | } | |
540 | ||
541 | priv->control_state = control_state; | |
542 | spin_unlock_irqrestore(&priv->lock, flags); | |
543 | ||
544 | retval = BSA_USB_CMD(BELKIN_SA_SET_RTS_REQUEST, rts); | |
545 | if (retval < 0) { | |
546 | err("Set RTS error %d", retval); | |
547 | goto exit; | |
548 | } | |
549 | ||
550 | retval = BSA_USB_CMD(BELKIN_SA_SET_DTR_REQUEST, dtr); | |
551 | if (retval < 0) { | |
552 | err("Set DTR error %d", retval); | |
553 | goto exit; | |
554 | } | |
555 | exit: | |
556 | return retval; | |
557 | } | |
558 | ||
559 | ||
560 | static int belkin_sa_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg) | |
561 | { | |
562 | switch (cmd) { | |
563 | case TIOCMIWAIT: | |
564 | /* wait for any of the 4 modem inputs (DCD,RI,DSR,CTS)*/ | |
565 | /* TODO */ | |
566 | return( 0 ); | |
567 | ||
568 | case TIOCGICOUNT: | |
569 | /* return count of modemline transitions */ | |
570 | /* TODO */ | |
571 | return 0; | |
572 | ||
573 | default: | |
574 | dbg("belkin_sa_ioctl arg not supported - 0x%04x",cmd); | |
575 | return(-ENOIOCTLCMD); | |
576 | break; | |
577 | } | |
578 | return 0; | |
579 | } /* belkin_sa_ioctl */ | |
580 | ||
581 | ||
582 | static int __init belkin_sa_init (void) | |
583 | { | |
584 | int retval; | |
585 | retval = usb_serial_register(&belkin_device); | |
586 | if (retval) | |
587 | goto failed_usb_serial_register; | |
588 | retval = usb_register(&belkin_driver); | |
589 | if (retval) | |
590 | goto failed_usb_register; | |
591 | info(DRIVER_DESC " " DRIVER_VERSION); | |
592 | return 0; | |
593 | failed_usb_register: | |
594 | usb_serial_deregister(&belkin_device); | |
595 | failed_usb_serial_register: | |
596 | return retval; | |
597 | } | |
598 | ||
599 | ||
600 | static void __exit belkin_sa_exit (void) | |
601 | { | |
602 | usb_deregister (&belkin_driver); | |
603 | usb_serial_deregister (&belkin_device); | |
604 | } | |
605 | ||
606 | ||
607 | module_init (belkin_sa_init); | |
608 | module_exit (belkin_sa_exit); | |
609 | ||
610 | MODULE_AUTHOR( DRIVER_AUTHOR ); | |
611 | MODULE_DESCRIPTION( DRIVER_DESC ); | |
612 | MODULE_VERSION( DRIVER_VERSION ); | |
613 | MODULE_LICENSE("GPL"); | |
614 | ||
615 | module_param(debug, bool, S_IRUGO | S_IWUSR); | |
616 | MODULE_PARM_DESC(debug, "Debug enabled or not"); |