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