aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial
diff options
context:
space:
mode:
authorJohan Hovold <jhovold@gmail.com>2013-03-21 07:37:26 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-03-25 16:52:27 -0400
commit2d816ac6f5e0a0dc03be752c1599ed9588b403d2 (patch)
tree0d3b934cc613947907313bc4cc0a39e641252104 /drivers/usb/serial
parent23bd364dcf90de36f470e5a29f1684e128b53f38 (diff)
USB: spcp8x5: clean up code
Clean up this driver somewhat. Signed-off-by: Johan Hovold <jhovold@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb/serial')
-rw-r--r--drivers/usb/serial/spcp8x5.c72
1 files changed, 37 insertions, 35 deletions
diff --git a/drivers/usb/serial/spcp8x5.c b/drivers/usb/serial/spcp8x5.c
index f34930cda68d..a5c3a3684dc2 100644
--- a/drivers/usb/serial/spcp8x5.c
+++ b/drivers/usb/serial/spcp8x5.c
@@ -13,8 +13,6 @@
13 * it under the terms of the GNU General Public License as published by 13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or 14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version. 15 * (at your option) any later version.
16 *
17 *
18 */ 16 */
19#include <linux/kernel.h> 17#include <linux/kernel.h>
20#include <linux/errno.h> 18#include <linux/errno.h>
@@ -28,7 +26,7 @@
28#include <linux/usb.h> 26#include <linux/usb.h>
29#include <linux/usb/serial.h> 27#include <linux/usb/serial.h>
30 28
31#define DRIVER_DESC "SPCP8x5 USB to serial adaptor driver" 29#define DRIVER_DESC "SPCP8x5 USB to serial adaptor driver"
32 30
33#define SPCP8x5_007_VID 0x04FC 31#define SPCP8x5_007_VID 0x04FC
34#define SPCP8x5_007_PID 0x0201 32#define SPCP8x5_007_PID 0x0201
@@ -52,7 +50,7 @@ static const struct usb_device_id id_table[] = {
52MODULE_DEVICE_TABLE(usb, id_table); 50MODULE_DEVICE_TABLE(usb, id_table);
53 51
54struct spcp8x5_usb_ctrl_arg { 52struct spcp8x5_usb_ctrl_arg {
55 u8 type; 53 u8 type;
56 u8 cmd; 54 u8 cmd;
57 u8 cmd_type; 55 u8 cmd_type;
58 u16 value; 56 u16 value;
@@ -147,10 +145,10 @@ enum spcp8x5_type {
147}; 145};
148 146
149struct spcp8x5_private { 147struct spcp8x5_private {
150 spinlock_t lock; 148 spinlock_t lock;
151 enum spcp8x5_type type; 149 enum spcp8x5_type type;
152 u8 line_control; 150 u8 line_control;
153 u8 line_status; 151 u8 line_status;
154}; 152};
155 153
156static int spcp8x5_port_probe(struct usb_serial_port *port) 154static int spcp8x5_port_probe(struct usb_serial_port *port)
@@ -180,7 +178,7 @@ static int spcp8x5_port_probe(struct usb_serial_port *port)
180 spin_lock_init(&priv->lock); 178 spin_lock_init(&priv->lock);
181 priv->type = type; 179 priv->type = type;
182 180
183 usb_set_serial_port_data(port , priv); 181 usb_set_serial_port_data(port, priv);
184 182
185 return 0; 183 return 0;
186} 184}
@@ -195,13 +193,16 @@ static int spcp8x5_port_remove(struct usb_serial_port *port)
195 return 0; 193 return 0;
196} 194}
197 195
198/* set the modem control line of the device. 196/*
199 * NOTE spcp825-007 not supported this */ 197 * Set the modem control line of the device.
200static int spcp8x5_set_ctrlLine(struct usb_device *dev, u8 value, 198 *
199 * NOTE: not supported by spcp825-007
200 */
201static int spcp8x5_set_ctrl_line(struct usb_device *dev, u8 value,
201 enum spcp8x5_type type) 202 enum spcp8x5_type type)
202{ 203{
203 int retval; 204 int retval;
204 u8 mcr = 0 ; 205 u8 mcr = 0;
205 206
206 if (type == SPCP825_007_TYPE) 207 if (type == SPCP825_007_TYPE)
207 return -EPERM; 208 return -EPERM;
@@ -215,8 +216,11 @@ static int spcp8x5_set_ctrlLine(struct usb_device *dev, u8 value,
215 return retval; 216 return retval;
216} 217}
217 218
218/* get the modem status register of the device 219/*
219 * NOTE spcp825-007 not supported this */ 220 * Get the modem status register of the device.
221 *
222 * NOTE: not supported by spcp825-007
223 */
220static int spcp8x5_get_msr(struct usb_device *dev, u8 *status, 224static int spcp8x5_get_msr(struct usb_device *dev, u8 *status,
221 enum spcp8x5_type type) 225 enum spcp8x5_type type)
222{ 226{
@@ -249,9 +253,12 @@ static int spcp8x5_get_msr(struct usb_device *dev, u8 *status,
249 return ret; 253 return ret;
250} 254}
251 255
252/* select the work mode. 256/*
253 * NOTE this function not supported by spcp825-007 */ 257 * Select the work mode.
254static void spcp8x5_set_workMode(struct usb_device *dev, u16 value, 258 *
259 * NOTE: not supported by spcp825-007
260 */
261static void spcp8x5_set_work_mode(struct usb_device *dev, u16 value,
255 u16 index, enum spcp8x5_type type) 262 u16 index, enum spcp8x5_type type)
256{ 263{
257 int ret; 264 int ret;
@@ -273,8 +280,10 @@ static void spcp8x5_set_workMode(struct usb_device *dev, u16 value,
273static int spcp8x5_carrier_raised(struct usb_serial_port *port) 280static int spcp8x5_carrier_raised(struct usb_serial_port *port)
274{ 281{
275 struct spcp8x5_private *priv = usb_get_serial_port_data(port); 282 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
283
276 if (priv->line_status & MSR_STATUS_LINE_DCD) 284 if (priv->line_status & MSR_STATUS_LINE_DCD)
277 return 1; 285 return 1;
286
278 return 0; 287 return 0;
279} 288}
280 289
@@ -293,20 +302,17 @@ static void spcp8x5_dtr_rts(struct usb_serial_port *port, int on)
293 | MCR_CONTROL_LINE_RTS); 302 | MCR_CONTROL_LINE_RTS);
294 control = priv->line_control; 303 control = priv->line_control;
295 spin_unlock_irqrestore(&priv->lock, flags); 304 spin_unlock_irqrestore(&priv->lock, flags);
296 spcp8x5_set_ctrlLine(port->serial->dev, control , priv->type); 305 spcp8x5_set_ctrl_line(port->serial->dev, control, priv->type);
297} 306}
298 307
299static void spcp8x5_init_termios(struct tty_struct *tty) 308static void spcp8x5_init_termios(struct tty_struct *tty)
300{ 309{
301 /* for the 1st time call this function */
302 tty->termios = tty_std_termios; 310 tty->termios = tty_std_termios;
303 tty->termios.c_cflag = B115200 | CS8 | CREAD | HUPCL | CLOCAL; 311 tty->termios.c_cflag = B115200 | CS8 | CREAD | HUPCL | CLOCAL;
304 tty->termios.c_ispeed = 115200; 312 tty->termios.c_ispeed = 115200;
305 tty->termios.c_ospeed = 115200; 313 tty->termios.c_ospeed = 115200;
306} 314}
307 315
308/* set the serial param for transfer. we should check if we really need to
309 * transfer. if we set flow control we should do this too. */
310static void spcp8x5_set_termios(struct tty_struct *tty, 316static void spcp8x5_set_termios(struct tty_struct *tty,
311 struct usb_serial_port *port, struct ktermios *old_termios) 317 struct usb_serial_port *port, struct ktermios *old_termios)
312{ 318{
@@ -321,7 +327,6 @@ static void spcp8x5_set_termios(struct tty_struct *tty,
321 int i; 327 int i;
322 u8 control; 328 u8 control;
323 329
324
325 /* check that they really want us to change something */ 330 /* check that they really want us to change something */
326 if (!tty_termios_hw_change(&tty->termios, old_termios)) 331 if (!tty_termios_hw_change(&tty->termios, old_termios))
327 return; 332 return;
@@ -337,7 +342,7 @@ static void spcp8x5_set_termios(struct tty_struct *tty,
337 if (control != priv->line_control) { 342 if (control != priv->line_control) {
338 control = priv->line_control; 343 control = priv->line_control;
339 spin_unlock_irqrestore(&priv->lock, flags); 344 spin_unlock_irqrestore(&priv->lock, flags);
340 spcp8x5_set_ctrlLine(serial->dev, control , priv->type); 345 spcp8x5_set_ctrl_line(serial->dev, control , priv->type);
341 } else { 346 } else {
342 spin_unlock_irqrestore(&priv->lock, flags); 347 spin_unlock_irqrestore(&priv->lock, flags);
343 } 348 }
@@ -397,9 +402,9 @@ static void spcp8x5_set_termios(struct tty_struct *tty,
397 if (cflag & PARENB) { 402 if (cflag & PARENB) {
398 buf[1] |= (cflag & PARODD) ? 403 buf[1] |= (cflag & PARODD) ?
399 SET_UART_FORMAT_PAR_ODD : SET_UART_FORMAT_PAR_EVEN ; 404 SET_UART_FORMAT_PAR_ODD : SET_UART_FORMAT_PAR_EVEN ;
400 } else 405 } else {
401 buf[1] |= SET_UART_FORMAT_PAR_NONE; 406 buf[1] |= SET_UART_FORMAT_PAR_NONE;
402 407 }
403 uartdata = buf[0] | buf[1]<<8; 408 uartdata = buf[0] | buf[1]<<8;
404 409
405 i = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 410 i = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
@@ -412,13 +417,11 @@ static void spcp8x5_set_termios(struct tty_struct *tty,
412 417
413 if (cflag & CRTSCTS) { 418 if (cflag & CRTSCTS) {
414 /* enable hardware flow control */ 419 /* enable hardware flow control */
415 spcp8x5_set_workMode(serial->dev, 0x000a, 420 spcp8x5_set_work_mode(serial->dev, 0x000a,
416 SET_WORKING_MODE_U2C, priv->type); 421 SET_WORKING_MODE_U2C, priv->type);
417 } 422 }
418} 423}
419 424
420/* open the serial port. do some usb system call. set termios and get the line
421 * status of the device. */
422static int spcp8x5_open(struct tty_struct *tty, struct usb_serial_port *port) 425static int spcp8x5_open(struct tty_struct *tty, struct usb_serial_port *port)
423{ 426{
424 struct ktermios tmp_termios; 427 struct ktermios tmp_termios;
@@ -438,7 +441,7 @@ static int spcp8x5_open(struct tty_struct *tty, struct usb_serial_port *port)
438 if (ret) 441 if (ret)
439 return ret; 442 return ret;
440 443
441 spcp8x5_set_ctrlLine(serial->dev, priv->line_control , priv->type); 444 spcp8x5_set_ctrl_line(serial->dev, priv->line_control, priv->type);
442 445
443 /* Setup termios */ 446 /* Setup termios */
444 if (tty) 447 if (tty)
@@ -476,7 +479,7 @@ static int spcp8x5_tiocmset(struct tty_struct *tty,
476 control = priv->line_control; 479 control = priv->line_control;
477 spin_unlock_irqrestore(&priv->lock, flags); 480 spin_unlock_irqrestore(&priv->lock, flags);
478 481
479 return spcp8x5_set_ctrlLine(port->serial->dev, control , priv->type); 482 return spcp8x5_set_ctrl_line(port->serial->dev, control, priv->type);
480} 483}
481 484
482static int spcp8x5_tiocmget(struct tty_struct *tty) 485static int spcp8x5_tiocmget(struct tty_struct *tty)
@@ -503,7 +506,6 @@ static int spcp8x5_tiocmget(struct tty_struct *tty)
503 return result; 506 return result;
504} 507}
505 508
506/* All of the device info needed for the spcp8x5 SIO serial converter */
507static struct usb_serial_driver spcp8x5_device = { 509static struct usb_serial_driver spcp8x5_device = {
508 .driver = { 510 .driver = {
509 .owner = THIS_MODULE, 511 .owner = THIS_MODULE,
@@ -511,13 +513,13 @@ static struct usb_serial_driver spcp8x5_device = {
511 }, 513 },
512 .id_table = id_table, 514 .id_table = id_table,
513 .num_ports = 1, 515 .num_ports = 1,
514 .open = spcp8x5_open, 516 .open = spcp8x5_open,
515 .dtr_rts = spcp8x5_dtr_rts, 517 .dtr_rts = spcp8x5_dtr_rts,
516 .carrier_raised = spcp8x5_carrier_raised, 518 .carrier_raised = spcp8x5_carrier_raised,
517 .set_termios = spcp8x5_set_termios, 519 .set_termios = spcp8x5_set_termios,
518 .init_termios = spcp8x5_init_termios, 520 .init_termios = spcp8x5_init_termios,
519 .tiocmget = spcp8x5_tiocmget, 521 .tiocmget = spcp8x5_tiocmget,
520 .tiocmset = spcp8x5_tiocmset, 522 .tiocmset = spcp8x5_tiocmset,
521 .port_probe = spcp8x5_port_probe, 523 .port_probe = spcp8x5_port_probe,
522 .port_remove = spcp8x5_port_remove, 524 .port_remove = spcp8x5_port_remove,
523}; 525};