aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/specialix.txt8
-rw-r--r--MAINTAINERS7
-rw-r--r--Makefile3
-rw-r--r--drivers/char/Kconfig10
-rw-r--r--drivers/char/Makefile2
-rw-r--r--drivers/char/amiserial.c3
-rw-r--r--drivers/char/cyclades.c8
-rw-r--r--drivers/char/epca.c58
-rw-r--r--drivers/char/esp.c5
-rw-r--r--drivers/char/isicom.c30
-rw-r--r--drivers/char/istallion.c14
-rw-r--r--drivers/char/moxa.c3
-rw-r--r--drivers/char/mxser.c49
-rw-r--r--drivers/char/n_hdlc.c4
-rw-r--r--drivers/char/pcmcia/synclink_cs.c5
-rw-r--r--drivers/char/riscom8.c27
-rw-r--r--drivers/char/rocket.c5
-rw-r--r--drivers/char/specialix.c803
-rw-r--r--drivers/char/stallion.c16
-rw-r--r--drivers/char/sx.c3
-rw-r--r--drivers/char/synclink.c7
-rw-r--r--drivers/char/synclink_gt.c154
-rw-r--r--drivers/char/synclinkmp.c9
-rw-r--r--drivers/char/tty_io.c707
-rw-r--r--drivers/char/tty_ldisc.c714
-rw-r--r--drivers/char/vme_scc.c5
-rw-r--r--drivers/gpio/Kconfig11
-rw-r--r--drivers/gpio/Makefile1
-rw-r--r--drivers/gpio/max7301.c339
-rw-r--r--drivers/gpio/pcf857x.c33
-rw-r--r--drivers/isdn/capi/capi.c3
-rw-r--r--drivers/serial/8250.c8
-rw-r--r--drivers/serial/cpm_uart/cpm_uart_core.c2
-rw-r--r--drivers/serial/icom.c2
-rw-r--r--drivers/serial/samsung.c2
-rw-r--r--drivers/serial/serial_core.c3
-rw-r--r--drivers/serial/serial_txx9.c2
-rw-r--r--drivers/usb/class/cdc-acm.c9
-rw-r--r--drivers/usb/serial/aircable.c19
-rw-r--r--drivers/usb/serial/airprime.c355
-rw-r--r--drivers/usb/serial/ark3116.c32
-rw-r--r--drivers/usb/serial/belkin_sa.c201
-rw-r--r--drivers/usb/serial/belkin_sa.h15
-rw-r--r--drivers/usb/serial/bus.c20
-rw-r--r--drivers/usb/serial/ch341.c10
-rw-r--r--drivers/usb/serial/console.c136
-rw-r--r--drivers/usb/serial/cp2101.c379
-rw-r--r--drivers/usb/serial/cyberjack.c176
-rw-r--r--drivers/usb/serial/cypress_m8.c703
-rw-r--r--drivers/usb/serial/cypress_m8.h2
-rw-r--r--drivers/usb/serial/digi_acceleport.c457
-rw-r--r--drivers/usb/serial/empeg.c257
-rw-r--r--drivers/usb/serial/ezusb.c22
-rw-r--r--drivers/usb/serial/ftdi_sio.c1247
-rw-r--r--drivers/usb/serial/ftdi_sio.h126
-rw-r--r--drivers/usb/serial/funsoft.c2
-rw-r--r--drivers/usb/serial/garmin_gps.c400
-rw-r--r--drivers/usb/serial/generic.c122
-rw-r--r--drivers/usb/serial/hp4x.c3
-rw-r--r--drivers/usb/serial/io_edgeport.c1964
-rw-r--r--drivers/usb/serial/io_tables.h6
-rw-r--r--drivers/usb/serial/io_ti.c109
-rw-r--r--drivers/usb/serial/ipaq.c143
-rw-r--r--drivers/usb/serial/ipw.c294
-rw-r--r--drivers/usb/serial/ir-usb.c81
-rw-r--r--drivers/usb/serial/iuu_phoenix.c58
-rw-r--r--drivers/usb/serial/keyspan.c955
-rw-r--r--drivers/usb/serial/keyspan.h39
-rw-r--r--drivers/usb/serial/keyspan_pda.c231
-rw-r--r--drivers/usb/serial/kl5kusb105.c415
-rw-r--r--drivers/usb/serial/kobil_sct.c617
-rw-r--r--drivers/usb/serial/mct_u232.c364
-rw-r--r--drivers/usb/serial/mos7720.c308
-rw-r--r--drivers/usb/serial/mos7840.c557
-rw-r--r--drivers/usb/serial/navman.c10
-rw-r--r--drivers/usb/serial/omninet.c171
-rw-r--r--drivers/usb/serial/option.c166
-rw-r--r--drivers/usb/serial/oti6858.c255
-rw-r--r--drivers/usb/serial/pl2303.c140
-rw-r--r--drivers/usb/serial/safe_serial.c298
-rw-r--r--drivers/usb/serial/sierra.c95
-rw-r--r--drivers/usb/serial/spcp8x5.c73
-rw-r--r--drivers/usb/serial/ti_usb_3410_5052.c449
-rw-r--r--drivers/usb/serial/usb-serial.c387
-rw-r--r--drivers/usb/serial/usb_debug.c5
-rw-r--r--drivers/usb/serial/visor.c384
-rw-r--r--drivers/usb/serial/whiteheat.c441
-rw-r--r--drivers/usb/serial/whiteheat.h78
-rw-r--r--fs/binfmt_elf.c1
-rw-r--r--fs/proc/task_mmu.c2
-rw-r--r--include/linux/auxvec.h4
-rw-r--r--include/linux/spi/max7301.h9
-rw-r--r--include/linux/synclink.h1
-rw-r--r--include/linux/tty.h11
-rw-r--r--include/linux/tty_driver.h14
-rw-r--r--include/linux/usb/serial.h56
-rw-r--r--kernel/cpuset.c4
-rw-r--r--kernel/sys_ni.c1
-rw-r--r--scripts/Makefile.modpost1
-rw-r--r--scripts/mod/modpost.c3
100 files changed, 9030 insertions, 7928 deletions
diff --git a/Documentation/specialix.txt b/Documentation/specialix.txt
index 4a4b428ce8f6..6eb6f3a3331c 100644
--- a/Documentation/specialix.txt
+++ b/Documentation/specialix.txt
@@ -270,8 +270,8 @@ The pinout of the connectors on the IO8+ is:
270Hardware handshaking issues. 270Hardware handshaking issues.
271============================ 271============================
272 272
273The driver can be compiled in two different ways. The default 273The driver can be told to operate in two different ways. The default
274("Specialix DTR/RTS pin is RTS" is off) the pin behaves as DTR when 274behaviour is specialix.sx_rtscts = 0 where the pin behaves as DTR when
275hardware handshaking is off. It behaves as the RTS hardware 275hardware handshaking is off. It behaves as the RTS hardware
276handshaking signal when hardware handshaking is selected. 276handshaking signal when hardware handshaking is selected.
277 277
@@ -280,7 +280,7 @@ cable will either be compatible with hardware handshaking or with
280software handshaking. So switching on the fly is not really an 280software handshaking. So switching on the fly is not really an
281option. 281option.
282 282
283I actually prefer to use the "Specialix DTR/RTS pin is RTS" option. 283I actually prefer to use the "specialix.sx_rtscts=1" option.
284This makes the DTR/RTS pin always an RTS pin, and ioctls to 284This makes the DTR/RTS pin always an RTS pin, and ioctls to
285change DTR are always ignored. I have a cable that is configured 285change DTR are always ignored. I have a cable that is configured
286for this. 286for this.
@@ -379,7 +379,5 @@ it doesn't fit in your computer, bring back the card.
379 You have to WRITE to the address register to even 379 You have to WRITE to the address register to even
380 read-probe a CD186x register. Disable autodetection? 380 read-probe a CD186x register. Disable autodetection?
381 -- Specialix: any suggestions? 381 -- Specialix: any suggestions?
382 - Arbitrary baud rates are not implemented yet.
383 If you need this, bug me about it.
384 382
385 383
diff --git a/MAINTAINERS b/MAINTAINERS
index df3fa0e42f2e..11944b44c2ff 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4047,9 +4047,10 @@ W: http://www.buzzard.org.uk/toshiba/
4047S: Maintained 4047S: Maintained
4048 4048
4049TPM DEVICE DRIVER 4049TPM DEVICE DRIVER
4050P: Debora Velarde 4050P: Debora Velarde
4051P: Rajiv Andrade 4051M: debora@linux.vnet.ibm.com
4052M: tpmdd-devel@lists.sourceforge.net 4052P: Rajiv Andrade
4053M: srajiv@linux.vnet.ibm.com
4053W: http://tpmdd.sourceforge.net 4054W: http://tpmdd.sourceforge.net
4054P: Marcel Selhorst 4055P: Marcel Selhorst
4055M: tpm@selhorst.net 4056M: tpm@selhorst.net
diff --git a/Makefile b/Makefile
index 6192922de9c0..4bcd1cf90cb1 100644
--- a/Makefile
+++ b/Makefile
@@ -1148,7 +1148,8 @@ clean: archclean $(clean-dirs)
1148 @find . $(RCS_FIND_IGNORE) \ 1148 @find . $(RCS_FIND_IGNORE) \
1149 \( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \ 1149 \( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
1150 -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \ 1150 -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
1151 -o -name '*.symtypes' -o -name 'modules.order' \) \ 1151 -o -name '*.symtypes' -o -name 'modules.order' \
1152 -o -name 'Module.markers' \) \
1152 -type f -print | xargs rm -f 1153 -type f -print | xargs rm -f
1153 1154
1154# mrproper - Delete all generated files, including .config 1155# mrproper - Delete all generated files, including .config
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 650e6b44ce65..e0bbbfb6a36b 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -300,16 +300,6 @@ config SPECIALIX
300 and compile this driver as kernel loadable module which will be 300 and compile this driver as kernel loadable module which will be
301 called specialix. 301 called specialix.
302 302
303config SPECIALIX_RTSCTS
304 bool "Specialix DTR/RTS pin is RTS"
305 depends on SPECIALIX
306 help
307 The Specialix IO8+ card can only support either RTS or DTR. If you
308 say N here, the driver will use the pin as "DTR" when the tty is in
309 software handshake mode. If you say Y here or hardware handshake is
310 on, it will always be RTS. Read the file
311 <file:Documentation/specialix.txt> for more information.
312
313config SX 303config SX
314 tristate "Specialix SX (and SI) card support" 304 tristate "Specialix SX (and SI) card support"
315 depends on SERIAL_NONSTANDARD && (PCI || EISA || ISA) 305 depends on SERIAL_NONSTANDARD && (PCI || EISA || ISA)
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index 0e0d12a06462..dc5a327d72d5 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -7,7 +7,7 @@
7# 7#
8FONTMAPFILE = cp437.uni 8FONTMAPFILE = cp437.uni
9 9
10obj-y += mem.o random.o tty_io.o n_tty.o tty_ioctl.o 10obj-y += mem.o random.o tty_io.o n_tty.o tty_ioctl.o tty_ldisc.o
11 11
12obj-$(CONFIG_LEGACY_PTYS) += pty.o 12obj-$(CONFIG_LEGACY_PTYS) += pty.o
13obj-$(CONFIG_UNIX98_PTYS) += pty.o 13obj-$(CONFIG_UNIX98_PTYS) += pty.o
diff --git a/drivers/char/amiserial.c b/drivers/char/amiserial.c
index 37457e5a4f2b..3530ff417a51 100644
--- a/drivers/char/amiserial.c
+++ b/drivers/char/amiserial.c
@@ -1248,7 +1248,7 @@ static int rs_tiocmset(struct tty_struct *tty, struct file *file,
1248/* 1248/*
1249 * rs_break() --- routine which turns the break handling on or off 1249 * rs_break() --- routine which turns the break handling on or off
1250 */ 1250 */
1251static void rs_break(struct tty_struct *tty, int break_state) 1251static int rs_break(struct tty_struct *tty, int break_state)
1252{ 1252{
1253 struct async_struct * info = (struct async_struct *)tty->driver_data; 1253 struct async_struct * info = (struct async_struct *)tty->driver_data;
1254 unsigned long flags; 1254 unsigned long flags;
@@ -1263,6 +1263,7 @@ static void rs_break(struct tty_struct *tty, int break_state)
1263 custom.adkcon = AC_UARTBRK; 1263 custom.adkcon = AC_UARTBRK;
1264 mb(); 1264 mb();
1265 local_irq_restore(flags); 1265 local_irq_restore(flags);
1266 return 0;
1266} 1267}
1267 1268
1268 1269
diff --git a/drivers/char/cyclades.c b/drivers/char/cyclades.c
index e991dc85f2fb..fe6d774fe2e4 100644
--- a/drivers/char/cyclades.c
+++ b/drivers/char/cyclades.c
@@ -3700,14 +3700,15 @@ cy_tiocmset(struct tty_struct *tty, struct file *file,
3700/* 3700/*
3701 * cy_break() --- routine which turns the break handling on or off 3701 * cy_break() --- routine which turns the break handling on or off
3702 */ 3702 */
3703static void cy_break(struct tty_struct *tty, int break_state) 3703static int cy_break(struct tty_struct *tty, int break_state)
3704{ 3704{
3705 struct cyclades_port *info = tty->driver_data; 3705 struct cyclades_port *info = tty->driver_data;
3706 struct cyclades_card *card; 3706 struct cyclades_card *card;
3707 unsigned long flags; 3707 unsigned long flags;
3708 int retval = 0;
3708 3709
3709 if (serial_paranoia_check(info, tty->name, "cy_break")) 3710 if (serial_paranoia_check(info, tty->name, "cy_break"))
3710 return; 3711 return -EINVAL;
3711 3712
3712 card = info->card; 3713 card = info->card;
3713 3714
@@ -3736,8 +3737,6 @@ static void cy_break(struct tty_struct *tty, int break_state)
3736 } 3737 }
3737 } 3738 }
3738 } else { 3739 } else {
3739 int retval;
3740
3741 if (break_state == -1) { 3740 if (break_state == -1) {
3742 retval = cyz_issue_cmd(card, 3741 retval = cyz_issue_cmd(card,
3743 info->line - card->first_line, 3742 info->line - card->first_line,
@@ -3758,6 +3757,7 @@ static void cy_break(struct tty_struct *tty, int break_state)
3758 } 3757 }
3759 } 3758 }
3760 spin_unlock_irqrestore(&card->card_lock, flags); 3759 spin_unlock_irqrestore(&card->card_lock, flags);
3760 return retval;
3761} /* cy_break */ 3761} /* cy_break */
3762 3762
3763static int get_mon_info(struct cyclades_port *info, 3763static int get_mon_info(struct cyclades_port *info,
diff --git a/drivers/char/epca.c b/drivers/char/epca.c
index ac9995f6578b..456e4ede049f 100644
--- a/drivers/char/epca.c
+++ b/drivers/char/epca.c
@@ -184,9 +184,8 @@ static void pc_stop(struct tty_struct *);
184static void pc_start(struct tty_struct *); 184static void pc_start(struct tty_struct *);
185static void pc_throttle(struct tty_struct *tty); 185static void pc_throttle(struct tty_struct *tty);
186static void pc_unthrottle(struct tty_struct *tty); 186static void pc_unthrottle(struct tty_struct *tty);
187static void digi_send_break(struct channel *ch, int msec); 187static int pc_send_break(struct tty_struct *tty, int msec);
188static void setup_empty_event(struct tty_struct *tty, struct channel *ch); 188static void setup_empty_event(struct tty_struct *tty, struct channel *ch);
189static void epca_setup(char *, int *);
190 189
191static int pc_write(struct tty_struct *, const unsigned char *, int); 190static int pc_write(struct tty_struct *, const unsigned char *, int);
192static int pc_init(void); 191static int pc_init(void);
@@ -1040,6 +1039,7 @@ static const struct tty_operations pc_ops = {
1040 .throttle = pc_throttle, 1039 .throttle = pc_throttle,
1041 .unthrottle = pc_unthrottle, 1040 .unthrottle = pc_unthrottle,
1042 .hangup = pc_hangup, 1041 .hangup = pc_hangup,
1042 .break_ctl = pc_send_break
1043}; 1043};
1044 1044
1045static int info_open(struct tty_struct *tty, struct file *filp) 1045static int info_open(struct tty_struct *tty, struct file *filp)
@@ -1132,7 +1132,7 @@ static int __init pc_init(void)
1132 pc_driver->init_termios.c_lflag = 0; 1132 pc_driver->init_termios.c_lflag = 0;
1133 pc_driver->init_termios.c_ispeed = 9600; 1133 pc_driver->init_termios.c_ispeed = 9600;
1134 pc_driver->init_termios.c_ospeed = 9600; 1134 pc_driver->init_termios.c_ospeed = 9600;
1135 pc_driver->flags = TTY_DRIVER_REAL_RAW; 1135 pc_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_HARDWARE_BREAK;
1136 tty_set_operations(pc_driver, &pc_ops); 1136 tty_set_operations(pc_driver, &pc_ops);
1137 1137
1138 pc_info->owner = THIS_MODULE; 1138 pc_info->owner = THIS_MODULE;
@@ -2177,7 +2177,6 @@ static int pc_ioctl(struct tty_struct *tty, struct file *file,
2177 unsigned int cmd, unsigned long arg) 2177 unsigned int cmd, unsigned long arg)
2178{ 2178{
2179 digiflow_t dflow; 2179 digiflow_t dflow;
2180 int retval;
2181 unsigned long flags; 2180 unsigned long flags;
2182 unsigned int mflag, mstat; 2181 unsigned int mflag, mstat;
2183 unsigned char startc, stopc; 2182 unsigned char startc, stopc;
@@ -2189,37 +2188,7 @@ static int pc_ioctl(struct tty_struct *tty, struct file *file,
2189 bc = ch->brdchan; 2188 bc = ch->brdchan;
2190 else 2189 else
2191 return -EINVAL; 2190 return -EINVAL;
2192 /*
2193 * For POSIX compliance we need to add more ioctls. See tty_ioctl.c in
2194 * /usr/src/linux/drivers/char for a good example. In particular think
2195 * about adding TCSETAF, TCSETAW, TCSETA, TCSETSF, TCSETSW, TCSETS.
2196 */
2197 switch (cmd) { 2191 switch (cmd) {
2198 case TCSBRK: /* SVID version: non-zero arg --> no break */
2199 retval = tty_check_change(tty);
2200 if (retval)
2201 return retval;
2202 /* Setup an event to indicate when the transmit
2203 buffer empties */
2204 spin_lock_irqsave(&epca_lock, flags);
2205 setup_empty_event(tty, ch);
2206 spin_unlock_irqrestore(&epca_lock, flags);
2207 tty_wait_until_sent(tty, 0);
2208 if (!arg)
2209 digi_send_break(ch, HZ / 4); /* 1/4 second */
2210 return 0;
2211 case TCSBRKP: /* support for POSIX tcsendbreak() */
2212 retval = tty_check_change(tty);
2213 if (retval)
2214 return retval;
2215 /* Setup an event to indicate when the transmit buffer
2216 empties */
2217 spin_lock_irqsave(&epca_lock, flags);
2218 setup_empty_event(tty, ch);
2219 spin_unlock_irqrestore(&epca_lock, flags);
2220 tty_wait_until_sent(tty, 0);
2221 digi_send_break(ch, arg ? arg*(HZ/10) : HZ/4);
2222 return 0;
2223 case TIOCMODG: 2192 case TIOCMODG:
2224 mflag = pc_tiocmget(tty, file); 2193 mflag = pc_tiocmget(tty, file);
2225 if (put_user(mflag, (unsigned long __user *)argp)) 2194 if (put_user(mflag, (unsigned long __user *)argp))
@@ -2505,10 +2474,14 @@ static void pc_unthrottle(struct tty_struct *tty)
2505 } 2474 }
2506} 2475}
2507 2476
2508static void digi_send_break(struct channel *ch, int msec) 2477static int pc_send_break(struct tty_struct *tty, int msec)
2509{ 2478{
2479 struct channel *ch = (struct channel *) tty->driver_data;
2510 unsigned long flags; 2480 unsigned long flags;
2511 2481
2482 if (msec == -1)
2483 return -EOPNOTSUPP;
2484
2512 spin_lock_irqsave(&epca_lock, flags); 2485 spin_lock_irqsave(&epca_lock, flags);
2513 globalwinon(ch); 2486 globalwinon(ch);
2514 /* 2487 /*
@@ -2521,6 +2494,7 @@ static void digi_send_break(struct channel *ch, int msec)
2521 fepcmd(ch, SENDBREAK, msec, 0, 10, 0); 2494 fepcmd(ch, SENDBREAK, msec, 0, 10, 0);
2522 memoff(ch); 2495 memoff(ch);
2523 spin_unlock_irqrestore(&epca_lock, flags); 2496 spin_unlock_irqrestore(&epca_lock, flags);
2497 return 0;
2524} 2498}
2525 2499
2526/* Caller MUST hold the lock */ 2500/* Caller MUST hold the lock */
@@ -2538,7 +2512,8 @@ static void setup_empty_event(struct tty_struct *tty, struct channel *ch)
2538 memoff(ch); 2512 memoff(ch);
2539} 2513}
2540 2514
2541static void epca_setup(char *str, int *ints) 2515#ifndef MODULE
2516static void __init epca_setup(char *str, int *ints)
2542{ 2517{
2543 struct board_info board; 2518 struct board_info board;
2544 int index, loop, last; 2519 int index, loop, last;
@@ -2792,6 +2767,17 @@ static void epca_setup(char *str, int *ints)
2792 num_cards++; 2767 num_cards++;
2793} 2768}
2794 2769
2770static int __init epca_real_setup(char *str)
2771{
2772 int ints[11];
2773
2774 epca_setup(get_options(str, 11, ints), ints);
2775 return 1;
2776}
2777
2778__setup("digiepca", epca_real_setup);
2779#endif
2780
2795enum epic_board_types { 2781enum epic_board_types {
2796 brd_xr = 0, 2782 brd_xr = 0,
2797 brd_xem, 2783 brd_xem,
diff --git a/drivers/char/esp.c b/drivers/char/esp.c
index 2eaf09f93e3d..7f077c0097f6 100644
--- a/drivers/char/esp.c
+++ b/drivers/char/esp.c
@@ -1725,13 +1725,13 @@ static int esp_tiocmset(struct tty_struct *tty, struct file *file,
1725/* 1725/*
1726 * rs_break() --- routine which turns the break handling on or off 1726 * rs_break() --- routine which turns the break handling on or off
1727 */ 1727 */
1728static void esp_break(struct tty_struct *tty, int break_state) 1728static int esp_break(struct tty_struct *tty, int break_state)
1729{ 1729{
1730 struct esp_struct *info = tty->driver_data; 1730 struct esp_struct *info = tty->driver_data;
1731 unsigned long flags; 1731 unsigned long flags;
1732 1732
1733 if (serial_paranoia_check(info, tty->name, "esp_break")) 1733 if (serial_paranoia_check(info, tty->name, "esp_break"))
1734 return; 1734 return -EINVAL;
1735 1735
1736 if (break_state == -1) { 1736 if (break_state == -1) {
1737 spin_lock_irqsave(&info->lock, flags); 1737 spin_lock_irqsave(&info->lock, flags);
@@ -1747,6 +1747,7 @@ static void esp_break(struct tty_struct *tty, int break_state)
1747 serial_out(info, UART_ESI_CMD2, 0x00); 1747 serial_out(info, UART_ESI_CMD2, 0x00);
1748 spin_unlock_irqrestore(&info->lock, flags); 1748 spin_unlock_irqrestore(&info->lock, flags);
1749 } 1749 }
1750 return 0;
1750} 1751}
1751 1752
1752static int rs_ioctl(struct tty_struct *tty, struct file *file, 1753static int rs_ioctl(struct tty_struct *tty, struct file *file,
diff --git a/drivers/char/isicom.c b/drivers/char/isicom.c
index d4281df10c22..8f7cc190b62d 100644
--- a/drivers/char/isicom.c
+++ b/drivers/char/isicom.c
@@ -1181,14 +1181,17 @@ static int isicom_chars_in_buffer(struct tty_struct *tty)
1181} 1181}
1182 1182
1183/* ioctl et all */ 1183/* ioctl et all */
1184static inline void isicom_send_break(struct isi_port *port, 1184static int isicom_send_break(struct tty_struct *tty, int length)
1185 unsigned long length)
1186{ 1185{
1186 struct isi_port *port = tty->driver_data;
1187 struct isi_board *card = port->card; 1187 struct isi_board *card = port->card;
1188 unsigned long base = card->base; 1188 unsigned long base = card->base;
1189 1189
1190 if (length == -1)
1191 return -EOPNOTSUPP;
1192
1190 if (!lock_card(card)) 1193 if (!lock_card(card))
1191 return; 1194 return -EINVAL;
1192 1195
1193 outw(0x8000 | ((port->channel) << (card->shift_count)) | 0x3, base); 1196 outw(0x8000 | ((port->channel) << (card->shift_count)) | 0x3, base);
1194 outw((length & 0xff) << 8 | 0x00, base); 1197 outw((length & 0xff) << 8 | 0x00, base);
@@ -1196,6 +1199,7 @@ static inline void isicom_send_break(struct isi_port *port,
1196 InterruptTheCard(base); 1199 InterruptTheCard(base);
1197 1200
1198 unlock_card(card); 1201 unlock_card(card);
1202 return 0;
1199} 1203}
1200 1204
1201static int isicom_tiocmget(struct tty_struct *tty, struct file *file) 1205static int isicom_tiocmget(struct tty_struct *tty, struct file *file)
@@ -1305,28 +1309,11 @@ static int isicom_ioctl(struct tty_struct *tty, struct file *filp,
1305{ 1309{
1306 struct isi_port *port = tty->driver_data; 1310 struct isi_port *port = tty->driver_data;
1307 void __user *argp = (void __user *)arg; 1311 void __user *argp = (void __user *)arg;
1308 int retval;
1309 1312
1310 if (isicom_paranoia_check(port, tty->name, "isicom_ioctl")) 1313 if (isicom_paranoia_check(port, tty->name, "isicom_ioctl"))
1311 return -ENODEV; 1314 return -ENODEV;
1312 1315
1313 switch (cmd) { 1316 switch (cmd) {
1314 case TCSBRK:
1315 retval = tty_check_change(tty);
1316 if (retval)
1317 return retval;
1318 tty_wait_until_sent(tty, 0);
1319 if (!arg)
1320 isicom_send_break(port, HZ/4);
1321 return 0;
1322
1323 case TCSBRKP:
1324 retval = tty_check_change(tty);
1325 if (retval)
1326 return retval;
1327 tty_wait_until_sent(tty, 0);
1328 isicom_send_break(port, arg ? arg * (HZ/10) : HZ/4);
1329 return 0;
1330 case TIOCGSERIAL: 1317 case TIOCGSERIAL:
1331 return isicom_get_serial_info(port, argp); 1318 return isicom_get_serial_info(port, argp);
1332 1319
@@ -1459,6 +1446,7 @@ static const struct tty_operations isicom_ops = {
1459 .flush_buffer = isicom_flush_buffer, 1446 .flush_buffer = isicom_flush_buffer,
1460 .tiocmget = isicom_tiocmget, 1447 .tiocmget = isicom_tiocmget,
1461 .tiocmset = isicom_tiocmset, 1448 .tiocmset = isicom_tiocmset,
1449 .break_ctl = isicom_send_break,
1462}; 1450};
1463 1451
1464static int __devinit reset_card(struct pci_dev *pdev, 1452static int __devinit reset_card(struct pci_dev *pdev,
@@ -1832,7 +1820,7 @@ static int __init isicom_init(void)
1832 isicom_normal->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | 1820 isicom_normal->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL |
1833 CLOCAL; 1821 CLOCAL;
1834 isicom_normal->flags = TTY_DRIVER_REAL_RAW | 1822 isicom_normal->flags = TTY_DRIVER_REAL_RAW |
1835 TTY_DRIVER_DYNAMIC_DEV; 1823 TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_HARDWARE_BREAK;
1836 tty_set_operations(isicom_normal, &isicom_ops); 1824 tty_set_operations(isicom_normal, &isicom_ops);
1837 1825
1838 retval = tty_register_driver(isicom_normal); 1826 retval = tty_register_driver(isicom_normal);
diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c
index 24637bbf02f7..843a2afaf204 100644
--- a/drivers/char/istallion.c
+++ b/drivers/char/istallion.c
@@ -609,7 +609,7 @@ static void stli_unthrottle(struct tty_struct *tty);
609static void stli_stop(struct tty_struct *tty); 609static void stli_stop(struct tty_struct *tty);
610static void stli_start(struct tty_struct *tty); 610static void stli_start(struct tty_struct *tty);
611static void stli_flushbuffer(struct tty_struct *tty); 611static void stli_flushbuffer(struct tty_struct *tty);
612static void stli_breakctl(struct tty_struct *tty, int state); 612static int stli_breakctl(struct tty_struct *tty, int state);
613static void stli_waituntilsent(struct tty_struct *tty, int timeout); 613static void stli_waituntilsent(struct tty_struct *tty, int timeout);
614static void stli_sendxchar(struct tty_struct *tty, char ch); 614static void stli_sendxchar(struct tty_struct *tty, char ch);
615static void stli_hangup(struct tty_struct *tty); 615static void stli_hangup(struct tty_struct *tty);
@@ -925,8 +925,7 @@ static void stli_close(struct tty_struct *tty, struct file *filp)
925 clear_bit(ST_TXBUSY, &portp->state); 925 clear_bit(ST_TXBUSY, &portp->state);
926 clear_bit(ST_RXSTOP, &portp->state); 926 clear_bit(ST_RXSTOP, &portp->state);
927 set_bit(TTY_IO_ERROR, &tty->flags); 927 set_bit(TTY_IO_ERROR, &tty->flags);
928 if (tty->ldisc.ops->flush_buffer) 928 tty_ldisc_flush(tty);
929 (tty->ldisc.ops->flush_buffer)(tty);
930 set_bit(ST_DOFLUSHRX, &portp->state); 929 set_bit(ST_DOFLUSHRX, &portp->state);
931 stli_flushbuffer(tty); 930 stli_flushbuffer(tty);
932 931
@@ -1909,7 +1908,7 @@ static void stli_flushbuffer(struct tty_struct *tty)
1909 1908
1910/*****************************************************************************/ 1909/*****************************************************************************/
1911 1910
1912static void stli_breakctl(struct tty_struct *tty, int state) 1911static int stli_breakctl(struct tty_struct *tty, int state)
1913{ 1912{
1914 struct stlibrd *brdp; 1913 struct stlibrd *brdp;
1915 struct stliport *portp; 1914 struct stliport *portp;
@@ -1917,15 +1916,16 @@ static void stli_breakctl(struct tty_struct *tty, int state)
1917 1916
1918 portp = tty->driver_data; 1917 portp = tty->driver_data;
1919 if (portp == NULL) 1918 if (portp == NULL)
1920 return; 1919 return -EINVAL;
1921 if (portp->brdnr >= stli_nrbrds) 1920 if (portp->brdnr >= stli_nrbrds)
1922 return; 1921 return -EINVAL;
1923 brdp = stli_brds[portp->brdnr]; 1922 brdp = stli_brds[portp->brdnr];
1924 if (brdp == NULL) 1923 if (brdp == NULL)
1925 return; 1924 return -EINVAL;
1926 1925
1927 arg = (state == -1) ? BREAKON : BREAKOFF; 1926 arg = (state == -1) ? BREAKON : BREAKOFF;
1928 stli_cmdwait(brdp, portp, A_BREAK, &arg, sizeof(long), 0); 1927 stli_cmdwait(brdp, portp, A_BREAK, &arg, sizeof(long), 0);
1928 return 0;
1929} 1929}
1930 1930
1931/*****************************************************************************/ 1931/*****************************************************************************/
diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c
index 2bba250ffc8e..d3d7864e0c1e 100644
--- a/drivers/char/moxa.c
+++ b/drivers/char/moxa.c
@@ -374,12 +374,13 @@ copy:
374 return ret; 374 return ret;
375} 375}
376 376
377static void moxa_break_ctl(struct tty_struct *tty, int state) 377static int moxa_break_ctl(struct tty_struct *tty, int state)
378{ 378{
379 struct moxa_port *port = tty->driver_data; 379 struct moxa_port *port = tty->driver_data;
380 380
381 moxafunc(port->tableAddr, state ? FC_SendBreak : FC_StopBreak, 381 moxafunc(port->tableAddr, state ? FC_SendBreak : FC_StopBreak,
382 Magic_code); 382 Magic_code);
383 return 0;
383} 384}
384 385
385static const struct tty_operations moxa_ops = { 386static const struct tty_operations moxa_ops = {
diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c
index 6307e301bd26..4c756bbba948 100644
--- a/drivers/char/mxser.c
+++ b/drivers/char/mxser.c
@@ -47,7 +47,7 @@
47 47
48#include "mxser.h" 48#include "mxser.h"
49 49
50#define MXSER_VERSION "2.0.3" /* 1.11 */ 50#define MXSER_VERSION "2.0.4" /* 1.12 */
51#define MXSERMAJOR 174 51#define MXSERMAJOR 174
52#define MXSERCUMAJOR 175 52#define MXSERCUMAJOR 175
53 53
@@ -71,12 +71,13 @@
71#define UART_MCR_AFE 0x20 71#define UART_MCR_AFE 0x20
72#define UART_LSR_SPECIAL 0x1E 72#define UART_LSR_SPECIAL 0x1E
73 73
74#define PCI_DEVICE_ID_POS104UL 0x1044
74#define PCI_DEVICE_ID_CB108 0x1080 75#define PCI_DEVICE_ID_CB108 0x1080
76#define PCI_DEVICE_ID_CP102UF 0x1023
75#define PCI_DEVICE_ID_CB114 0x1142 77#define PCI_DEVICE_ID_CB114 0x1142
76#define PCI_DEVICE_ID_CP114UL 0x1143 78#define PCI_DEVICE_ID_CP114UL 0x1143
77#define PCI_DEVICE_ID_CB134I 0x1341 79#define PCI_DEVICE_ID_CB134I 0x1341
78#define PCI_DEVICE_ID_CP138U 0x1380 80#define PCI_DEVICE_ID_CP138U 0x1380
79#define PCI_DEVICE_ID_POS104UL 0x1044
80 81
81 82
82#define C168_ASIC_ID 1 83#define C168_ASIC_ID 1
@@ -142,7 +143,8 @@ static const struct mxser_cardinfo mxser_cards[] = {
142 { "CB-134I series", 4, }, 143 { "CB-134I series", 4, },
143 { "CP-138U series", 8, }, 144 { "CP-138U series", 8, },
144 { "POS-104UL series", 4, }, 145 { "POS-104UL series", 4, },
145 { "CP-114UL series", 4, } 146 { "CP-114UL series", 4, },
147/*30*/ { "CP-102UF series", 2, }
146}; 148};
147 149
148/* driver_data correspond to the lines in the structure above 150/* driver_data correspond to the lines in the structure above
@@ -172,6 +174,7 @@ static struct pci_device_id mxser_pcibrds[] = {
172 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CP138U), .driver_data = 27 }, 174 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CP138U), .driver_data = 27 },
173 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_POS104UL), .driver_data = 28 }, 175 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_POS104UL), .driver_data = 28 },
174 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CP114UL), .driver_data = 29 }, 176 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CP114UL), .driver_data = 29 },
177 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CP102UF), .driver_data = 30 },
175 { } 178 { }
176}; 179};
177MODULE_DEVICE_TABLE(pci, mxser_pcibrds); 180MODULE_DEVICE_TABLE(pci, mxser_pcibrds);
@@ -1414,7 +1417,6 @@ static int mxser_set_serial_info(struct mxser_port *info,
1414 info->port.closing_wait = new_serial.closing_wait * HZ / 100; 1417 info->port.closing_wait = new_serial.closing_wait * HZ / 100;
1415 info->port.tty->low_latency = 1418 info->port.tty->low_latency =
1416 (info->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0; 1419 (info->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
1417 info->port.tty->low_latency = 0;
1418 if ((info->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST && 1420 if ((info->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST &&
1419 (new_serial.baud_base != info->baud_base || 1421 (new_serial.baud_base != info->baud_base ||
1420 new_serial.custom_divisor != 1422 new_serial.custom_divisor !=
@@ -1464,27 +1466,6 @@ static int mxser_get_lsr_info(struct mxser_port *info,
1464 return put_user(result, value); 1466 return put_user(result, value);
1465} 1467}
1466 1468
1467/*
1468 * This routine sends a break character out the serial port.
1469 */
1470static void mxser_send_break(struct mxser_port *info, int duration)
1471{
1472 unsigned long flags;
1473
1474 if (!info->ioaddr)
1475 return;
1476 set_current_state(TASK_INTERRUPTIBLE);
1477 spin_lock_irqsave(&info->slock, flags);
1478 outb(inb(info->ioaddr + UART_LCR) | UART_LCR_SBC,
1479 info->ioaddr + UART_LCR);
1480 spin_unlock_irqrestore(&info->slock, flags);
1481 schedule_timeout(duration);
1482 spin_lock_irqsave(&info->slock, flags);
1483 outb(inb(info->ioaddr + UART_LCR) & ~UART_LCR_SBC,
1484 info->ioaddr + UART_LCR);
1485 spin_unlock_irqrestore(&info->slock, flags);
1486}
1487
1488static int mxser_tiocmget(struct tty_struct *tty, struct file *file) 1469static int mxser_tiocmget(struct tty_struct *tty, struct file *file)
1489{ 1470{
1490 struct mxser_port *info = tty->driver_data; 1471 struct mxser_port *info = tty->driver_data;
@@ -1872,21 +1853,6 @@ static int mxser_ioctl(struct tty_struct *tty, struct file *file,
1872 return -EIO; 1853 return -EIO;
1873 1854
1874 switch (cmd) { 1855 switch (cmd) {
1875 case TCSBRK: /* SVID version: non-zero arg --> no break */
1876 retval = tty_check_change(tty);
1877 if (retval)
1878 return retval;
1879 tty_wait_until_sent(tty, 0);
1880 if (!arg)
1881 mxser_send_break(info, HZ / 4); /* 1/4 second */
1882 return 0;
1883 case TCSBRKP: /* support for POSIX tcsendbreak() */
1884 retval = tty_check_change(tty);
1885 if (retval)
1886 return retval;
1887 tty_wait_until_sent(tty, 0);
1888 mxser_send_break(info, arg ? arg * (HZ / 10) : HZ / 4);
1889 return 0;
1890 case TIOCGSERIAL: 1856 case TIOCGSERIAL:
1891 lock_kernel(); 1857 lock_kernel();
1892 retval = mxser_get_serial_info(info, argp); 1858 retval = mxser_get_serial_info(info, argp);
@@ -2219,7 +2185,7 @@ static void mxser_hangup(struct tty_struct *tty)
2219/* 2185/*
2220 * mxser_rs_break() --- routine which turns the break handling on or off 2186 * mxser_rs_break() --- routine which turns the break handling on or off
2221 */ 2187 */
2222static void mxser_rs_break(struct tty_struct *tty, int break_state) 2188static int mxser_rs_break(struct tty_struct *tty, int break_state)
2223{ 2189{
2224 struct mxser_port *info = tty->driver_data; 2190 struct mxser_port *info = tty->driver_data;
2225 unsigned long flags; 2191 unsigned long flags;
@@ -2232,6 +2198,7 @@ static void mxser_rs_break(struct tty_struct *tty, int break_state)
2232 outb(inb(info->ioaddr + UART_LCR) & ~UART_LCR_SBC, 2198 outb(inb(info->ioaddr + UART_LCR) & ~UART_LCR_SBC,
2233 info->ioaddr + UART_LCR); 2199 info->ioaddr + UART_LCR);
2234 spin_unlock_irqrestore(&info->slock, flags); 2200 spin_unlock_irqrestore(&info->slock, flags);
2201 return 0;
2235} 2202}
2236 2203
2237static void mxser_receive_chars(struct mxser_port *port, int *status) 2204static void mxser_receive_chars(struct mxser_port *port, int *status)
diff --git a/drivers/char/n_hdlc.c b/drivers/char/n_hdlc.c
index ed4e03333ab4..69ec6399c714 100644
--- a/drivers/char/n_hdlc.c
+++ b/drivers/char/n_hdlc.c
@@ -677,6 +677,10 @@ static ssize_t n_hdlc_tty_write(struct tty_struct *tty, struct file *file,
677 /* Allocate transmit buffer */ 677 /* Allocate transmit buffer */
678 /* sleep until transmit buffer available */ 678 /* sleep until transmit buffer available */
679 while (!(tbuf = n_hdlc_buf_get(&n_hdlc->tx_free_buf_list))) { 679 while (!(tbuf = n_hdlc_buf_get(&n_hdlc->tx_free_buf_list))) {
680 if (file->f_flags & O_NONBLOCK) {
681 error = -EAGAIN;
682 break;
683 }
680 schedule(); 684 schedule();
681 685
682 n_hdlc = tty2n_hdlc (tty); 686 n_hdlc = tty2n_hdlc (tty);
diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
index b694d430f10e..d1fceabe3aef 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -2230,7 +2230,7 @@ static int tiocmset(struct tty_struct *tty, struct file *file,
2230 * Arguments: tty pointer to tty instance data 2230 * Arguments: tty pointer to tty instance data
2231 * break_state -1=set break condition, 0=clear 2231 * break_state -1=set break condition, 0=clear
2232 */ 2232 */
2233static void mgslpc_break(struct tty_struct *tty, int break_state) 2233static int mgslpc_break(struct tty_struct *tty, int break_state)
2234{ 2234{
2235 MGSLPC_INFO * info = (MGSLPC_INFO *)tty->driver_data; 2235 MGSLPC_INFO * info = (MGSLPC_INFO *)tty->driver_data;
2236 unsigned long flags; 2236 unsigned long flags;
@@ -2240,7 +2240,7 @@ static void mgslpc_break(struct tty_struct *tty, int break_state)
2240 __FILE__,__LINE__, info->device_name, break_state); 2240 __FILE__,__LINE__, info->device_name, break_state);
2241 2241
2242 if (mgslpc_paranoia_check(info, tty->name, "mgslpc_break")) 2242 if (mgslpc_paranoia_check(info, tty->name, "mgslpc_break"))
2243 return; 2243 return -EINVAL;
2244 2244
2245 spin_lock_irqsave(&info->lock,flags); 2245 spin_lock_irqsave(&info->lock,flags);
2246 if (break_state == -1) 2246 if (break_state == -1)
@@ -2248,6 +2248,7 @@ static void mgslpc_break(struct tty_struct *tty, int break_state)
2248 else 2248 else
2249 clear_reg_bits(info, CHA+DAFO, BIT6); 2249 clear_reg_bits(info, CHA+DAFO, BIT6);
2250 spin_unlock_irqrestore(&info->lock,flags); 2250 spin_unlock_irqrestore(&info->lock,flags);
2251 return 0;
2251} 2252}
2252 2253
2253/* Service an IOCTL request 2254/* Service an IOCTL request
diff --git a/drivers/char/riscom8.c b/drivers/char/riscom8.c
index 724b2b20f4b2..2c6c8f33d6b4 100644
--- a/drivers/char/riscom8.c
+++ b/drivers/char/riscom8.c
@@ -1250,11 +1250,15 @@ static int rc_tiocmset(struct tty_struct *tty, struct file *file,
1250 return 0; 1250 return 0;
1251} 1251}
1252 1252
1253static void rc_send_break(struct riscom_port *port, unsigned long length) 1253static int rc_send_break(struct tty_struct *tty, int length)
1254{ 1254{
1255 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1255 struct riscom_board *bp = port_Board(port); 1256 struct riscom_board *bp = port_Board(port);
1256 unsigned long flags; 1257 unsigned long flags;
1257 1258
1259 if (length == 0 || length == -1)
1260 return -EOPNOTSUPP;
1261
1258 spin_lock_irqsave(&riscom_lock, flags); 1262 spin_lock_irqsave(&riscom_lock, flags);
1259 1263
1260 port->break_length = RISCOM_TPS / HZ * length; 1264 port->break_length = RISCOM_TPS / HZ * length;
@@ -1268,6 +1272,7 @@ static void rc_send_break(struct riscom_port *port, unsigned long length)
1268 rc_wait_CCR(bp); 1272 rc_wait_CCR(bp);
1269 1273
1270 spin_unlock_irqrestore(&riscom_lock, flags); 1274 spin_unlock_irqrestore(&riscom_lock, flags);
1275 return 0;
1271} 1276}
1272 1277
1273static int rc_set_serial_info(struct riscom_port *port, 1278static int rc_set_serial_info(struct riscom_port *port,
@@ -1342,27 +1347,12 @@ static int rc_ioctl(struct tty_struct *tty, struct file *filp,
1342{ 1347{
1343 struct riscom_port *port = (struct riscom_port *)tty->driver_data; 1348 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1344 void __user *argp = (void __user *)arg; 1349 void __user *argp = (void __user *)arg;
1345 int retval = 0; 1350 int retval;
1346 1351
1347 if (rc_paranoia_check(port, tty->name, "rc_ioctl")) 1352 if (rc_paranoia_check(port, tty->name, "rc_ioctl"))
1348 return -ENODEV; 1353 return -ENODEV;
1349 1354
1350 switch (cmd) { 1355 switch (cmd) {
1351 case TCSBRK: /* SVID version: non-zero arg --> no break */
1352 retval = tty_check_change(tty);
1353 if (retval)
1354 return retval;
1355 tty_wait_until_sent(tty, 0);
1356 if (!arg)
1357 rc_send_break(port, HZ/4); /* 1/4 second */
1358 break;
1359 case TCSBRKP: /* support for POSIX tcsendbreak() */
1360 retval = tty_check_change(tty);
1361 if (retval)
1362 return retval;
1363 tty_wait_until_sent(tty, 0);
1364 rc_send_break(port, arg ? arg*(HZ/10) : HZ/4);
1365 break;
1366 case TIOCGSERIAL: 1356 case TIOCGSERIAL:
1367 lock_kernel(); 1357 lock_kernel();
1368 retval = rc_get_serial_info(port, argp); 1358 retval = rc_get_serial_info(port, argp);
@@ -1517,6 +1507,7 @@ static const struct tty_operations riscom_ops = {
1517 .hangup = rc_hangup, 1507 .hangup = rc_hangup,
1518 .tiocmget = rc_tiocmget, 1508 .tiocmget = rc_tiocmget,
1519 .tiocmset = rc_tiocmset, 1509 .tiocmset = rc_tiocmset,
1510 .break_ctl = rc_send_break,
1520}; 1511};
1521 1512
1522static int __init rc_init_drivers(void) 1513static int __init rc_init_drivers(void)
@@ -1538,7 +1529,7 @@ static int __init rc_init_drivers(void)
1538 B9600 | CS8 | CREAD | HUPCL | CLOCAL; 1529 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
1539 riscom_driver->init_termios.c_ispeed = 9600; 1530 riscom_driver->init_termios.c_ispeed = 9600;
1540 riscom_driver->init_termios.c_ospeed = 9600; 1531 riscom_driver->init_termios.c_ospeed = 9600;
1541 riscom_driver->flags = TTY_DRIVER_REAL_RAW; 1532 riscom_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_HARDWARE_BREAK;
1542 tty_set_operations(riscom_driver, &riscom_ops); 1533 tty_set_operations(riscom_driver, &riscom_ops);
1543 error = tty_register_driver(riscom_driver); 1534 error = tty_register_driver(riscom_driver);
1544 if (error != 0) { 1535 if (error != 0) {
diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c
index e670eae2f510..584d791e84a6 100644
--- a/drivers/char/rocket.c
+++ b/drivers/char/rocket.c
@@ -1236,13 +1236,13 @@ static void rp_set_termios(struct tty_struct *tty,
1236 } 1236 }
1237} 1237}
1238 1238
1239static void rp_break(struct tty_struct *tty, int break_state) 1239static int rp_break(struct tty_struct *tty, int break_state)
1240{ 1240{
1241 struct r_port *info = (struct r_port *) tty->driver_data; 1241 struct r_port *info = (struct r_port *) tty->driver_data;
1242 unsigned long flags; 1242 unsigned long flags;
1243 1243
1244 if (rocket_paranoia_check(info, "rp_break")) 1244 if (rocket_paranoia_check(info, "rp_break"))
1245 return; 1245 return -EINVAL;
1246 1246
1247 spin_lock_irqsave(&info->slock, flags); 1247 spin_lock_irqsave(&info->slock, flags);
1248 if (break_state == -1) 1248 if (break_state == -1)
@@ -1250,6 +1250,7 @@ static void rp_break(struct tty_struct *tty, int break_state)
1250 else 1250 else
1251 sClrBreak(&info->channel); 1251 sClrBreak(&info->channel);
1252 spin_unlock_irqrestore(&info->slock, flags); 1252 spin_unlock_irqrestore(&info->slock, flags);
1253 return 0;
1253} 1254}
1254 1255
1255/* 1256/*
diff --git a/drivers/char/specialix.c b/drivers/char/specialix.c
index 037dc47e4cb1..242fd46fda22 100644
--- a/drivers/char/specialix.c
+++ b/drivers/char/specialix.c
@@ -77,7 +77,7 @@
77 77
78#include <linux/module.h> 78#include <linux/module.h>
79 79
80#include <asm/io.h> 80#include <linux/io.h>
81#include <linux/kernel.h> 81#include <linux/kernel.h>
82#include <linux/sched.h> 82#include <linux/sched.h>
83#include <linux/ioport.h> 83#include <linux/ioport.h>
@@ -92,7 +92,7 @@
92#include <linux/delay.h> 92#include <linux/delay.h>
93#include <linux/pci.h> 93#include <linux/pci.h>
94#include <linux/init.h> 94#include <linux/init.h>
95#include <asm/uaccess.h> 95#include <linux/uaccess.h>
96 96
97#include "specialix_io8.h" 97#include "specialix_io8.h"
98#include "cd1865.h" 98#include "cd1865.h"
@@ -110,9 +110,10 @@
110 110
111static int sx_debug; 111static int sx_debug;
112static int sx_rxfifo = SPECIALIX_RXFIFO; 112static int sx_rxfifo = SPECIALIX_RXFIFO;
113static int sx_rtscts;
113 114
114#ifdef DEBUG 115#ifdef DEBUG
115#define dprintk(f, str...) if (sx_debug & f) printk (str) 116#define dprintk(f, str...) if (sx_debug & f) printk(str)
116#else 117#else
117#define dprintk(f, str...) /* nothing */ 118#define dprintk(f, str...) /* nothing */
118#endif 119#endif
@@ -131,10 +132,8 @@ static int sx_rxfifo = SPECIALIX_RXFIFO;
131#define SX_DEBUG_FIFO 0x0800 132#define SX_DEBUG_FIFO 0x0800
132 133
133 134
134#define func_enter() dprintk (SX_DEBUG_FLOW, "io8: enter %s\n",__func__) 135#define func_enter() dprintk(SX_DEBUG_FLOW, "io8: enter %s\n", __func__)
135#define func_exit() dprintk (SX_DEBUG_FLOW, "io8: exit %s\n", __func__) 136#define func_exit() dprintk(SX_DEBUG_FLOW, "io8: exit %s\n", __func__)
136
137#define jiffies_from_ms(a) ((((a) * HZ)/1000)+1)
138 137
139 138
140/* Configurable options: */ 139/* Configurable options: */
@@ -142,17 +141,6 @@ static int sx_rxfifo = SPECIALIX_RXFIFO;
142/* Am I paranoid or not ? ;-) */ 141/* Am I paranoid or not ? ;-) */
143#define SPECIALIX_PARANOIA_CHECK 142#define SPECIALIX_PARANOIA_CHECK
144 143
145/* Do I trust the IRQ from the card? (enabeling it doesn't seem to help)
146 When the IRQ routine leaves the chip in a state that is keeps on
147 requiring attention, the timer doesn't help either. */
148#undef SPECIALIX_TIMER
149
150#ifdef SPECIALIX_TIMER
151static int sx_poll = HZ;
152#endif
153
154
155
156/* 144/*
157 * The following defines are mostly for testing purposes. But if you need 145 * The following defines are mostly for testing purposes. But if you need
158 * some nice reporting in your syslog, you can define them also. 146 * some nice reporting in your syslog, you can define them also.
@@ -162,16 +150,6 @@ static int sx_poll = HZ;
162 150
163 151
164 152
165#ifdef CONFIG_SPECIALIX_RTSCTS
166#define SX_CRTSCTS(bla) 1
167#else
168#define SX_CRTSCTS(tty) C_CRTSCTS(tty)
169#endif
170
171
172/* Used to be outb (0xff, 0x80); */
173#define short_pause() udelay (1)
174
175 153
176#define SPECIALIX_LEGAL_FLAGS \ 154#define SPECIALIX_LEGAL_FLAGS \
177 (ASYNC_HUP_NOTIFY | ASYNC_SAK | ASYNC_SPLIT_TERMIOS | \ 155 (ASYNC_HUP_NOTIFY | ASYNC_SAK | ASYNC_SPLIT_TERMIOS | \
@@ -190,21 +168,14 @@ static struct specialix_board sx_board[SX_NBOARD] = {
190static struct specialix_port sx_port[SX_NBOARD * SX_NPORT]; 168static struct specialix_port sx_port[SX_NBOARD * SX_NPORT];
191 169
192 170
193#ifdef SPECIALIX_TIMER 171static int sx_paranoia_check(struct specialix_port const *port,
194static struct timer_list missed_irq_timer;
195static irqreturn_t sx_interrupt(int irq, void * dev_id);
196#endif
197
198
199
200static inline int sx_paranoia_check(struct specialix_port const * port,
201 char *name, const char *routine) 172 char *name, const char *routine)
202{ 173{
203#ifdef SPECIALIX_PARANOIA_CHECK 174#ifdef SPECIALIX_PARANOIA_CHECK
204 static const char *badmagic = 175 static const char *badmagic = KERN_ERR
205 KERN_ERR "sx: Warning: bad specialix port magic number for device %s in %s\n"; 176 "sx: Warning: bad specialix port magic number for device %s in %s\n";
206 static const char *badinfo = 177 static const char *badinfo = KERN_ERR
207 KERN_ERR "sx: Warning: null specialix port for device %s in %s\n"; 178 "sx: Warning: null specialix port for device %s in %s\n";
208 179
209 if (!port) { 180 if (!port) {
210 printk(badinfo, name, routine); 181 printk(badinfo, name, routine);
@@ -226,66 +197,69 @@ static inline int sx_paranoia_check(struct specialix_port const * port,
226 */ 197 */
227 198
228/* Get board number from pointer */ 199/* Get board number from pointer */
229static inline int board_No (struct specialix_board * bp) 200static inline int board_No(struct specialix_board *bp)
230{ 201{
231 return bp - sx_board; 202 return bp - sx_board;
232} 203}
233 204
234 205
235/* Get port number from pointer */ 206/* Get port number from pointer */
236static inline int port_No (struct specialix_port const * port) 207static inline int port_No(struct specialix_port const *port)
237{ 208{
238 return SX_PORT(port - sx_port); 209 return SX_PORT(port - sx_port);
239} 210}
240 211
241 212
242/* Get pointer to board from pointer to port */ 213/* Get pointer to board from pointer to port */
243static inline struct specialix_board * port_Board(struct specialix_port const * port) 214static inline struct specialix_board *port_Board(
215 struct specialix_port const *port)
244{ 216{
245 return &sx_board[SX_BOARD(port - sx_port)]; 217 return &sx_board[SX_BOARD(port - sx_port)];
246} 218}
247 219
248 220
249/* Input Byte from CL CD186x register */ 221/* Input Byte from CL CD186x register */
250static inline unsigned char sx_in(struct specialix_board * bp, unsigned short reg) 222static inline unsigned char sx_in(struct specialix_board *bp,
223 unsigned short reg)
251{ 224{
252 bp->reg = reg | 0x80; 225 bp->reg = reg | 0x80;
253 outb (reg | 0x80, bp->base + SX_ADDR_REG); 226 outb(reg | 0x80, bp->base + SX_ADDR_REG);
254 return inb (bp->base + SX_DATA_REG); 227 return inb(bp->base + SX_DATA_REG);
255} 228}
256 229
257 230
258/* Output Byte to CL CD186x register */ 231/* Output Byte to CL CD186x register */
259static inline void sx_out(struct specialix_board * bp, unsigned short reg, 232static inline void sx_out(struct specialix_board *bp, unsigned short reg,
260 unsigned char val) 233 unsigned char val)
261{ 234{
262 bp->reg = reg | 0x80; 235 bp->reg = reg | 0x80;
263 outb (reg | 0x80, bp->base + SX_ADDR_REG); 236 outb(reg | 0x80, bp->base + SX_ADDR_REG);
264 outb (val, bp->base + SX_DATA_REG); 237 outb(val, bp->base + SX_DATA_REG);
265} 238}
266 239
267 240
268/* Input Byte from CL CD186x register */ 241/* Input Byte from CL CD186x register */
269static inline unsigned char sx_in_off(struct specialix_board * bp, unsigned short reg) 242static inline unsigned char sx_in_off(struct specialix_board *bp,
243 unsigned short reg)
270{ 244{
271 bp->reg = reg; 245 bp->reg = reg;
272 outb (reg, bp->base + SX_ADDR_REG); 246 outb(reg, bp->base + SX_ADDR_REG);
273 return inb (bp->base + SX_DATA_REG); 247 return inb(bp->base + SX_DATA_REG);
274} 248}
275 249
276 250
277/* Output Byte to CL CD186x register */ 251/* Output Byte to CL CD186x register */
278static inline void sx_out_off(struct specialix_board * bp, unsigned short reg, 252static inline void sx_out_off(struct specialix_board *bp,
279 unsigned char val) 253 unsigned short reg, unsigned char val)
280{ 254{
281 bp->reg = reg; 255 bp->reg = reg;
282 outb (reg, bp->base + SX_ADDR_REG); 256 outb(reg, bp->base + SX_ADDR_REG);
283 outb (val, bp->base + SX_DATA_REG); 257 outb(val, bp->base + SX_DATA_REG);
284} 258}
285 259
286 260
287/* Wait for Channel Command Register ready */ 261/* Wait for Channel Command Register ready */
288static inline void sx_wait_CCR(struct specialix_board * bp) 262static void sx_wait_CCR(struct specialix_board *bp)
289{ 263{
290 unsigned long delay, flags; 264 unsigned long delay, flags;
291 unsigned char ccr; 265 unsigned char ccr;
@@ -296,7 +270,7 @@ static inline void sx_wait_CCR(struct specialix_board * bp)
296 spin_unlock_irqrestore(&bp->lock, flags); 270 spin_unlock_irqrestore(&bp->lock, flags);
297 if (!ccr) 271 if (!ccr)
298 return; 272 return;
299 udelay (1); 273 udelay(1);
300 } 274 }
301 275
302 printk(KERN_ERR "sx%d: Timeout waiting for CCR.\n", board_No(bp)); 276 printk(KERN_ERR "sx%d: Timeout waiting for CCR.\n", board_No(bp));
@@ -304,7 +278,7 @@ static inline void sx_wait_CCR(struct specialix_board * bp)
304 278
305 279
306/* Wait for Channel Command Register ready */ 280/* Wait for Channel Command Register ready */
307static inline void sx_wait_CCR_off(struct specialix_board * bp) 281static void sx_wait_CCR_off(struct specialix_board *bp)
308{ 282{
309 unsigned long delay; 283 unsigned long delay;
310 unsigned char crr; 284 unsigned char crr;
@@ -316,7 +290,7 @@ static inline void sx_wait_CCR_off(struct specialix_board * bp)
316 spin_unlock_irqrestore(&bp->lock, flags); 290 spin_unlock_irqrestore(&bp->lock, flags);
317 if (!crr) 291 if (!crr)
318 return; 292 return;
319 udelay (1); 293 udelay(1);
320 } 294 }
321 295
322 printk(KERN_ERR "sx%d: Timeout waiting for CCR.\n", board_No(bp)); 296 printk(KERN_ERR "sx%d: Timeout waiting for CCR.\n", board_No(bp));
@@ -327,7 +301,7 @@ static inline void sx_wait_CCR_off(struct specialix_board * bp)
327 * specialix IO8+ IO range functions. 301 * specialix IO8+ IO range functions.
328 */ 302 */
329 303
330static inline int sx_request_io_range(struct specialix_board * bp) 304static int sx_request_io_range(struct specialix_board *bp)
331{ 305{
332 return request_region(bp->base, 306 return request_region(bp->base,
333 bp->flags & SX_BOARD_IS_PCI ? SX_PCI_IO_SPACE : SX_IO_SPACE, 307 bp->flags & SX_BOARD_IS_PCI ? SX_PCI_IO_SPACE : SX_IO_SPACE,
@@ -335,15 +309,15 @@ static inline int sx_request_io_range(struct specialix_board * bp)
335} 309}
336 310
337 311
338static inline void sx_release_io_range(struct specialix_board * bp) 312static void sx_release_io_range(struct specialix_board *bp)
339{ 313{
340 release_region(bp->base, 314 release_region(bp->base, bp->flags & SX_BOARD_IS_PCI ?
341 bp->flags&SX_BOARD_IS_PCI?SX_PCI_IO_SPACE:SX_IO_SPACE); 315 SX_PCI_IO_SPACE : SX_IO_SPACE);
342} 316}
343 317
344 318
345/* Set the IRQ using the RTS lines that run to the PAL on the board.... */ 319/* Set the IRQ using the RTS lines that run to the PAL on the board.... */
346static int sx_set_irq ( struct specialix_board *bp) 320static int sx_set_irq(struct specialix_board *bp)
347{ 321{
348 int virq; 322 int virq;
349 int i; 323 int i;
@@ -353,15 +327,24 @@ static int sx_set_irq ( struct specialix_board *bp)
353 return 1; 327 return 1;
354 switch (bp->irq) { 328 switch (bp->irq) {
355 /* In the same order as in the docs... */ 329 /* In the same order as in the docs... */
356 case 15: virq = 0;break; 330 case 15:
357 case 12: virq = 1;break; 331 virq = 0;
358 case 11: virq = 2;break; 332 break;
359 case 9: virq = 3;break; 333 case 12:
360 default: printk (KERN_ERR "Speclialix: cannot set irq to %d.\n", bp->irq); 334 virq = 1;
361 return 0; 335 break;
336 case 11:
337 virq = 2;
338 break;
339 case 9:
340 virq = 3;
341 break;
342 default:printk(KERN_ERR
343 "Speclialix: cannot set irq to %d.\n", bp->irq);
344 return 0;
362 } 345 }
363 spin_lock_irqsave(&bp->lock, flags); 346 spin_lock_irqsave(&bp->lock, flags);
364 for (i=0;i<2;i++) { 347 for (i = 0; i < 2; i++) {
365 sx_out(bp, CD186x_CAR, i); 348 sx_out(bp, CD186x_CAR, i);
366 sx_out(bp, CD186x_MSVRTS, ((virq >> i) & 0x1)? MSVR_RTS:0); 349 sx_out(bp, CD186x_MSVRTS, ((virq >> i) & 0x1)? MSVR_RTS:0);
367 } 350 }
@@ -371,7 +354,7 @@ static int sx_set_irq ( struct specialix_board *bp)
371 354
372 355
373/* Reset and setup CD186x chip */ 356/* Reset and setup CD186x chip */
374static int sx_init_CD186x(struct specialix_board * bp) 357static int sx_init_CD186x(struct specialix_board *bp)
375{ 358{
376 unsigned long flags; 359 unsigned long flags;
377 int scaler; 360 int scaler;
@@ -390,7 +373,7 @@ static int sx_init_CD186x(struct specialix_board * bp)
390 sx_out_off(bp, CD186x_PILR2, SX_ACK_TINT); /* Prio for transmitter intr */ 373 sx_out_off(bp, CD186x_PILR2, SX_ACK_TINT); /* Prio for transmitter intr */
391 sx_out_off(bp, CD186x_PILR3, SX_ACK_RINT); /* Prio for receiver intr */ 374 sx_out_off(bp, CD186x_PILR3, SX_ACK_RINT); /* Prio for receiver intr */
392 /* Set RegAckEn */ 375 /* Set RegAckEn */
393 sx_out_off(bp, CD186x_SRCR, sx_in (bp, CD186x_SRCR) | SRCR_REGACKEN); 376 sx_out_off(bp, CD186x_SRCR, sx_in(bp, CD186x_SRCR) | SRCR_REGACKEN);
394 377
395 /* Setting up prescaler. We need 4 ticks per 1 ms */ 378 /* Setting up prescaler. We need 4 ticks per 1 ms */
396 scaler = SX_OSCFREQ/SPECIALIX_TPS; 379 scaler = SX_OSCFREQ/SPECIALIX_TPS;
@@ -399,9 +382,9 @@ static int sx_init_CD186x(struct specialix_board * bp)
399 sx_out_off(bp, CD186x_PPRL, scaler & 0xff); 382 sx_out_off(bp, CD186x_PPRL, scaler & 0xff);
400 spin_unlock_irqrestore(&bp->lock, flags); 383 spin_unlock_irqrestore(&bp->lock, flags);
401 384
402 if (!sx_set_irq (bp)) { 385 if (!sx_set_irq(bp)) {
403 /* Figure out how to pass this along... */ 386 /* Figure out how to pass this along... */
404 printk (KERN_ERR "Cannot set irq to %d.\n", bp->irq); 387 printk(KERN_ERR "Cannot set irq to %d.\n", bp->irq);
405 rv = 0; 388 rv = 0;
406 } 389 }
407 390
@@ -410,16 +393,16 @@ static int sx_init_CD186x(struct specialix_board * bp)
410} 393}
411 394
412 395
413static int read_cross_byte (struct specialix_board *bp, int reg, int bit) 396static int read_cross_byte(struct specialix_board *bp, int reg, int bit)
414{ 397{
415 int i; 398 int i;
416 int t; 399 int t;
417 unsigned long flags; 400 unsigned long flags;
418 401
419 spin_lock_irqsave(&bp->lock, flags); 402 spin_lock_irqsave(&bp->lock, flags);
420 for (i=0, t=0;i<8;i++) { 403 for (i = 0, t = 0; i < 8; i++) {
421 sx_out_off (bp, CD186x_CAR, i); 404 sx_out_off(bp, CD186x_CAR, i);
422 if (sx_in_off (bp, reg) & bit) 405 if (sx_in_off(bp, reg) & bit)
423 t |= 1 << i; 406 t |= 1 << i;
424 } 407 }
425 spin_unlock_irqrestore(&bp->lock, flags); 408 spin_unlock_irqrestore(&bp->lock, flags);
@@ -428,37 +411,10 @@ static int read_cross_byte (struct specialix_board *bp, int reg, int bit)
428} 411}
429 412
430 413
431#ifdef SPECIALIX_TIMER
432void missed_irq (unsigned long data)
433{
434 unsigned char irq;
435 unsigned long flags;
436 struct specialix_board *bp = (struct specialix_board *)data;
437
438 spin_lock_irqsave(&bp->lock, flags);
439 irq = sx_in ((struct specialix_board *)data, CD186x_SRSR) &
440 (SRSR_RREQint |
441 SRSR_TREQint |
442 SRSR_MREQint);
443 spin_unlock_irqrestore(&bp->lock, flags);
444 if (irq) {
445 printk (KERN_INFO "Missed interrupt... Calling int from timer. \n");
446 sx_interrupt (-1, bp);
447 }
448 mod_timer(&missed_irq_timer, jiffies + sx_poll);
449}
450#endif
451
452
453
454/* Main probing routine, also sets irq. */ 414/* Main probing routine, also sets irq. */
455static int sx_probe(struct specialix_board *bp) 415static int sx_probe(struct specialix_board *bp)
456{ 416{
457 unsigned char val1, val2; 417 unsigned char val1, val2;
458#if 0
459 int irqs = 0;
460 int retries;
461#endif
462 int rev; 418 int rev;
463 int chip; 419 int chip;
464 420
@@ -471,17 +427,18 @@ static int sx_probe(struct specialix_board *bp)
471 427
472 /* Are the I/O ports here ? */ 428 /* Are the I/O ports here ? */
473 sx_out_off(bp, CD186x_PPRL, 0x5a); 429 sx_out_off(bp, CD186x_PPRL, 0x5a);
474 short_pause (); 430 udelay(1);
475 val1 = sx_in_off(bp, CD186x_PPRL); 431 val1 = sx_in_off(bp, CD186x_PPRL);
476 432
477 sx_out_off(bp, CD186x_PPRL, 0xa5); 433 sx_out_off(bp, CD186x_PPRL, 0xa5);
478 short_pause (); 434 udelay(1);
479 val2 = sx_in_off(bp, CD186x_PPRL); 435 val2 = sx_in_off(bp, CD186x_PPRL);
480 436
481 437
482 if ((val1 != 0x5a) || (val2 != 0xa5)) { 438 if (val1 != 0x5a || val2 != 0xa5) {
483 printk(KERN_INFO "sx%d: specialix IO8+ Board at 0x%03x not found.\n", 439 printk(KERN_INFO
484 board_No(bp), bp->base); 440 "sx%d: specialix IO8+ Board at 0x%03x not found.\n",
441 board_No(bp), bp->base);
485 sx_release_io_range(bp); 442 sx_release_io_range(bp);
486 func_exit(); 443 func_exit();
487 return 1; 444 return 1;
@@ -489,10 +446,11 @@ static int sx_probe(struct specialix_board *bp)
489 446
490 /* Check the DSR lines that Specialix uses as board 447 /* Check the DSR lines that Specialix uses as board
491 identification */ 448 identification */
492 val1 = read_cross_byte (bp, CD186x_MSVR, MSVR_DSR); 449 val1 = read_cross_byte(bp, CD186x_MSVR, MSVR_DSR);
493 val2 = read_cross_byte (bp, CD186x_MSVR, MSVR_RTS); 450 val2 = read_cross_byte(bp, CD186x_MSVR, MSVR_RTS);
494 dprintk (SX_DEBUG_INIT, "sx%d: DSR lines are: %02x, rts lines are: %02x\n", 451 dprintk(SX_DEBUG_INIT,
495 board_No(bp), val1, val2); 452 "sx%d: DSR lines are: %02x, rts lines are: %02x\n",
453 board_No(bp), val1, val2);
496 454
497 /* They managed to switch the bit order between the docs and 455 /* They managed to switch the bit order between the docs and
498 the IO8+ card. The new PCI card now conforms to old docs. 456 the IO8+ card. The new PCI card now conforms to old docs.
@@ -500,7 +458,8 @@ static int sx_probe(struct specialix_board *bp)
500 old card. */ 458 old card. */
501 val2 = (bp->flags & SX_BOARD_IS_PCI)?0x4d : 0xb2; 459 val2 = (bp->flags & SX_BOARD_IS_PCI)?0x4d : 0xb2;
502 if (val1 != val2) { 460 if (val1 != val2) {
503 printk(KERN_INFO "sx%d: specialix IO8+ ID %02x at 0x%03x not found (%02x).\n", 461 printk(KERN_INFO
462 "sx%d: specialix IO8+ ID %02x at 0x%03x not found (%02x).\n",
504 board_No(bp), val2, bp->base, val1); 463 board_No(bp), val2, bp->base, val1);
505 sx_release_io_range(bp); 464 sx_release_io_range(bp);
506 func_exit(); 465 func_exit();
@@ -508,47 +467,6 @@ static int sx_probe(struct specialix_board *bp)
508 } 467 }
509 468
510 469
511#if 0
512 /* It's time to find IRQ for this board */
513 for (retries = 0; retries < 5 && irqs <= 0; retries++) {
514 irqs = probe_irq_on();
515 sx_init_CD186x(bp); /* Reset CD186x chip */
516 sx_out(bp, CD186x_CAR, 2); /* Select port 2 */
517 sx_wait_CCR(bp);
518 sx_out(bp, CD186x_CCR, CCR_TXEN); /* Enable transmitter */
519 sx_out(bp, CD186x_IER, IER_TXRDY); /* Enable tx empty intr */
520 msleep(50);
521 irqs = probe_irq_off(irqs);
522
523 dprintk (SX_DEBUG_INIT, "SRSR = %02x, ", sx_in(bp, CD186x_SRSR));
524 dprintk (SX_DEBUG_INIT, "TRAR = %02x, ", sx_in(bp, CD186x_TRAR));
525 dprintk (SX_DEBUG_INIT, "GIVR = %02x, ", sx_in(bp, CD186x_GIVR));
526 dprintk (SX_DEBUG_INIT, "GICR = %02x, ", sx_in(bp, CD186x_GICR));
527 dprintk (SX_DEBUG_INIT, "\n");
528
529 /* Reset CD186x again */
530 if (!sx_init_CD186x(bp)) {
531 /* Hmmm. This is dead code anyway. */
532 }
533
534 dprintk (SX_DEBUG_INIT "val1 = %02x, val2 = %02x, val3 = %02x.\n",
535 val1, val2, val3);
536
537 }
538
539#if 0
540 if (irqs <= 0) {
541 printk(KERN_ERR "sx%d: Can't find IRQ for specialix IO8+ board at 0x%03x.\n",
542 board_No(bp), bp->base);
543 sx_release_io_range(bp);
544 func_exit();
545 return 1;
546 }
547#endif
548 printk (KERN_INFO "Started with irq=%d, but now have irq=%d.\n", bp->irq, irqs);
549 if (irqs > 0)
550 bp->irq = irqs;
551#endif
552 /* Reset CD186x again */ 470 /* Reset CD186x again */
553 if (!sx_init_CD186x(bp)) { 471 if (!sx_init_CD186x(bp)) {
554 sx_release_io_range(bp); 472 sx_release_io_range(bp);
@@ -560,7 +478,7 @@ static int sx_probe(struct specialix_board *bp)
560 bp->flags |= SX_BOARD_PRESENT; 478 bp->flags |= SX_BOARD_PRESENT;
561 479
562 /* Chip revcode pkgtype 480 /* Chip revcode pkgtype
563 GFRCR SRCR bit 7 481 GFRCR SRCR bit 7
564 CD180 rev B 0x81 0 482 CD180 rev B 0x81 0
565 CD180 rev C 0x82 0 483 CD180 rev C 0x82 0
566 CD1864 rev A 0x82 1 484 CD1864 rev A 0x82 1
@@ -570,24 +488,32 @@ static int sx_probe(struct specialix_board *bp)
570 */ 488 */
571 489
572 switch (sx_in_off(bp, CD186x_GFRCR)) { 490 switch (sx_in_off(bp, CD186x_GFRCR)) {
573 case 0x82:chip = 1864;rev='A';break; 491 case 0x82:
574 case 0x83:chip = 1865;rev='A';break; 492 chip = 1864;
575 case 0x84:chip = 1865;rev='B';break; 493 rev = 'A';
576 case 0x85:chip = 1865;rev='C';break; /* Does not exist at this time */ 494 break;
577 default:chip=-1;rev='x'; 495 case 0x83:
496 chip = 1865;
497 rev = 'A';
498 break;
499 case 0x84:
500 chip = 1865;
501 rev = 'B';
502 break;
503 case 0x85:
504 chip = 1865;
505 rev = 'C';
506 break; /* Does not exist at this time */
507 default:
508 chip = -1;
509 rev = 'x';
578 } 510 }
579 511
580 dprintk (SX_DEBUG_INIT, " GFCR = 0x%02x\n", sx_in_off(bp, CD186x_GFRCR) ); 512 dprintk(SX_DEBUG_INIT, " GFCR = 0x%02x\n", sx_in_off(bp, CD186x_GFRCR));
581
582#ifdef SPECIALIX_TIMER
583 setup_timer(&missed_irq_timer, missed_irq, (unsigned long)bp);
584 mod_timer(&missed_irq_timer, jiffies + sx_poll);
585#endif
586 513
587 printk(KERN_INFO"sx%d: specialix IO8+ board detected at 0x%03x, IRQ %d, CD%d Rev. %c.\n", 514 printk(KERN_INFO
588 board_No(bp), 515 "sx%d: specialix IO8+ board detected at 0x%03x, IRQ %d, CD%d Rev. %c.\n",
589 bp->base, bp->irq, 516 board_No(bp), bp->base, bp->irq, chip, rev);
590 chip, rev);
591 517
592 func_exit(); 518 func_exit();
593 return 0; 519 return 0;
@@ -598,20 +524,22 @@ static int sx_probe(struct specialix_board *bp)
598 * Interrupt processing routines. 524 * Interrupt processing routines.
599 * */ 525 * */
600 526
601static inline struct specialix_port * sx_get_port(struct specialix_board * bp, 527static struct specialix_port *sx_get_port(struct specialix_board *bp,
602 unsigned char const * what) 528 unsigned char const *what)
603{ 529{
604 unsigned char channel; 530 unsigned char channel;
605 struct specialix_port * port = NULL; 531 struct specialix_port *port = NULL;
606 532
607 channel = sx_in(bp, CD186x_GICR) >> GICR_CHAN_OFF; 533 channel = sx_in(bp, CD186x_GICR) >> GICR_CHAN_OFF;
608 dprintk (SX_DEBUG_CHAN, "channel: %d\n", channel); 534 dprintk(SX_DEBUG_CHAN, "channel: %d\n", channel);
609 if (channel < CD186x_NCH) { 535 if (channel < CD186x_NCH) {
610 port = &sx_port[board_No(bp) * SX_NPORT + channel]; 536 port = &sx_port[board_No(bp) * SX_NPORT + channel];
611 dprintk (SX_DEBUG_CHAN, "port: %d %p flags: 0x%lx\n",board_No(bp) * SX_NPORT + channel, port, port->port.flags & ASYNC_INITIALIZED); 537 dprintk(SX_DEBUG_CHAN, "port: %d %p flags: 0x%lx\n",
538 board_No(bp) * SX_NPORT + channel, port,
539 port->port.flags & ASYNC_INITIALIZED);
612 540
613 if (port->port.flags & ASYNC_INITIALIZED) { 541 if (port->port.flags & ASYNC_INITIALIZED) {
614 dprintk (SX_DEBUG_CHAN, "port: %d %p\n", channel, port); 542 dprintk(SX_DEBUG_CHAN, "port: %d %p\n", channel, port);
615 func_exit(); 543 func_exit();
616 return port; 544 return port;
617 } 545 }
@@ -622,7 +550,7 @@ static inline struct specialix_port * sx_get_port(struct specialix_board * bp,
622} 550}
623 551
624 552
625static inline void sx_receive_exc(struct specialix_board * bp) 553static void sx_receive_exc(struct specialix_board *bp)
626{ 554{
627 struct specialix_port *port; 555 struct specialix_port *port;
628 struct tty_struct *tty; 556 struct tty_struct *tty;
@@ -633,7 +561,7 @@ static inline void sx_receive_exc(struct specialix_board * bp)
633 561
634 port = sx_get_port(bp, "Receive"); 562 port = sx_get_port(bp, "Receive");
635 if (!port) { 563 if (!port) {
636 dprintk (SX_DEBUG_RX, "Hmm, couldn't find port.\n"); 564 dprintk(SX_DEBUG_RX, "Hmm, couldn't find port.\n");
637 func_exit(); 565 func_exit();
638 return; 566 return;
639 } 567 }
@@ -641,19 +569,21 @@ static inline void sx_receive_exc(struct specialix_board * bp)
641 569
642 status = sx_in(bp, CD186x_RCSR); 570 status = sx_in(bp, CD186x_RCSR);
643 571
644 dprintk (SX_DEBUG_RX, "status: 0x%x\n", status); 572 dprintk(SX_DEBUG_RX, "status: 0x%x\n", status);
645 if (status & RCSR_OE) { 573 if (status & RCSR_OE) {
646 port->overrun++; 574 port->overrun++;
647 dprintk(SX_DEBUG_FIFO, "sx%d: port %d: Overrun. Total %ld overruns.\n", 575 dprintk(SX_DEBUG_FIFO,
648 board_No(bp), port_No(port), port->overrun); 576 "sx%d: port %d: Overrun. Total %ld overruns.\n",
577 board_No(bp), port_No(port), port->overrun);
649 } 578 }
650 status &= port->mark_mask; 579 status &= port->mark_mask;
651 580
652 /* This flip buffer check needs to be below the reading of the 581 /* This flip buffer check needs to be below the reading of the
653 status register to reset the chip's IRQ.... */ 582 status register to reset the chip's IRQ.... */
654 if (tty_buffer_request_room(tty, 1) == 0) { 583 if (tty_buffer_request_room(tty, 1) == 0) {
655 dprintk(SX_DEBUG_FIFO, "sx%d: port %d: Working around flip buffer overflow.\n", 584 dprintk(SX_DEBUG_FIFO,
656 board_No(bp), port_No(port)); 585 "sx%d: port %d: Working around flip buffer overflow.\n",
586 board_No(bp), port_No(port));
657 func_exit(); 587 func_exit();
658 return; 588 return;
659 } 589 }
@@ -664,8 +594,9 @@ static inline void sx_receive_exc(struct specialix_board * bp)
664 return; 594 return;
665 } 595 }
666 if (status & RCSR_TOUT) { 596 if (status & RCSR_TOUT) {
667 printk(KERN_INFO "sx%d: port %d: Receiver timeout. Hardware problems ?\n", 597 printk(KERN_INFO
668 board_No(bp), port_No(port)); 598 "sx%d: port %d: Receiver timeout. Hardware problems ?\n",
599 board_No(bp), port_No(port));
669 func_exit(); 600 func_exit();
670 return; 601 return;
671 602
@@ -688,13 +619,13 @@ static inline void sx_receive_exc(struct specialix_board * bp)
688 else 619 else
689 flag = TTY_NORMAL; 620 flag = TTY_NORMAL;
690 621
691 if(tty_insert_flip_char(tty, ch, flag)) 622 if (tty_insert_flip_char(tty, ch, flag))
692 tty_flip_buffer_push(tty); 623 tty_flip_buffer_push(tty);
693 func_exit(); 624 func_exit();
694} 625}
695 626
696 627
697static inline void sx_receive(struct specialix_board * bp) 628static void sx_receive(struct specialix_board *bp)
698{ 629{
699 struct specialix_port *port; 630 struct specialix_port *port;
700 struct tty_struct *tty; 631 struct tty_struct *tty;
@@ -702,15 +633,16 @@ static inline void sx_receive(struct specialix_board * bp)
702 633
703 func_enter(); 634 func_enter();
704 635
705 if (!(port = sx_get_port(bp, "Receive"))) { 636 port = sx_get_port(bp, "Receive");
706 dprintk (SX_DEBUG_RX, "Hmm, couldn't find port.\n"); 637 if (port == NULL) {
638 dprintk(SX_DEBUG_RX, "Hmm, couldn't find port.\n");
707 func_exit(); 639 func_exit();
708 return; 640 return;
709 } 641 }
710 tty = port->port.tty; 642 tty = port->port.tty;
711 643
712 count = sx_in(bp, CD186x_RDCR); 644 count = sx_in(bp, CD186x_RDCR);
713 dprintk (SX_DEBUG_RX, "port: %p: count: %d\n", port, count); 645 dprintk(SX_DEBUG_RX, "port: %p: count: %d\n", port, count);
714 port->hits[count > 8 ? 9 : count]++; 646 port->hits[count > 8 ? 9 : count]++;
715 647
716 tty_buffer_request_room(tty, count); 648 tty_buffer_request_room(tty, count);
@@ -722,18 +654,19 @@ static inline void sx_receive(struct specialix_board * bp)
722} 654}
723 655
724 656
725static inline void sx_transmit(struct specialix_board * bp) 657static void sx_transmit(struct specialix_board *bp)
726{ 658{
727 struct specialix_port *port; 659 struct specialix_port *port;
728 struct tty_struct *tty; 660 struct tty_struct *tty;
729 unsigned char count; 661 unsigned char count;
730 662
731 func_enter(); 663 func_enter();
732 if (!(port = sx_get_port(bp, "Transmit"))) { 664 port = sx_get_port(bp, "Transmit");
665 if (port == NULL) {
733 func_exit(); 666 func_exit();
734 return; 667 return;
735 } 668 }
736 dprintk (SX_DEBUG_TX, "port: %p\n", port); 669 dprintk(SX_DEBUG_TX, "port: %p\n", port);
737 tty = port->port.tty; 670 tty = port->port.tty;
738 671
739 if (port->IER & IER_TXEMPTY) { 672 if (port->IER & IER_TXEMPTY) {
@@ -765,7 +698,8 @@ static inline void sx_transmit(struct specialix_board * bp)
765 sx_out(bp, CD186x_TDR, CD186x_C_ESC); 698 sx_out(bp, CD186x_TDR, CD186x_C_ESC);
766 sx_out(bp, CD186x_TDR, CD186x_C_DELAY); 699 sx_out(bp, CD186x_TDR, CD186x_C_DELAY);
767 sx_out(bp, CD186x_TDR, count); 700 sx_out(bp, CD186x_TDR, count);
768 if (!(port->break_length -= count)) 701 port->break_length -= count;
702 if (port->break_length == 0)
769 port->break_length--; 703 port->break_length--;
770 } else { 704 } else {
771 sx_out(bp, CD186x_TDR, CD186x_C_ESC); 705 sx_out(bp, CD186x_TDR, CD186x_C_ESC);
@@ -794,36 +728,36 @@ static inline void sx_transmit(struct specialix_board * bp)
794 sx_out(bp, CD186x_IER, port->IER); 728 sx_out(bp, CD186x_IER, port->IER);
795 } 729 }
796 if (port->xmit_cnt <= port->wakeup_chars) 730 if (port->xmit_cnt <= port->wakeup_chars)
797 tty_wakeup(tty); 731 tty_wakeup(tty);
798 732
799 func_exit(); 733 func_exit();
800} 734}
801 735
802 736
803static inline void sx_check_modem(struct specialix_board * bp) 737static void sx_check_modem(struct specialix_board *bp)
804{ 738{
805 struct specialix_port *port; 739 struct specialix_port *port;
806 struct tty_struct *tty; 740 struct tty_struct *tty;
807 unsigned char mcr; 741 unsigned char mcr;
808 int msvr_cd; 742 int msvr_cd;
809 743
810 dprintk (SX_DEBUG_SIGNALS, "Modem intr. "); 744 dprintk(SX_DEBUG_SIGNALS, "Modem intr. ");
811 if (!(port = sx_get_port(bp, "Modem"))) 745 port = sx_get_port(bp, "Modem");
746 if (port == NULL)
812 return; 747 return;
813 748
814 tty = port->port.tty; 749 tty = port->port.tty;
815 750
816 mcr = sx_in(bp, CD186x_MCR); 751 mcr = sx_in(bp, CD186x_MCR);
817 printk ("mcr = %02x.\n", mcr);
818 752
819 if ((mcr & MCR_CDCHG)) { 753 if ((mcr & MCR_CDCHG)) {
820 dprintk (SX_DEBUG_SIGNALS, "CD just changed... "); 754 dprintk(SX_DEBUG_SIGNALS, "CD just changed... ");
821 msvr_cd = sx_in(bp, CD186x_MSVR) & MSVR_CD; 755 msvr_cd = sx_in(bp, CD186x_MSVR) & MSVR_CD;
822 if (msvr_cd) { 756 if (msvr_cd) {
823 dprintk (SX_DEBUG_SIGNALS, "Waking up guys in open.\n"); 757 dprintk(SX_DEBUG_SIGNALS, "Waking up guys in open.\n");
824 wake_up_interruptible(&port->port.open_wait); 758 wake_up_interruptible(&port->port.open_wait);
825 } else { 759 } else {
826 dprintk (SX_DEBUG_SIGNALS, "Sending HUP.\n"); 760 dprintk(SX_DEBUG_SIGNALS, "Sending HUP.\n");
827 tty_hangup(tty); 761 tty_hangup(tty);
828 } 762 }
829 } 763 }
@@ -874,9 +808,12 @@ static irqreturn_t sx_interrupt(int dummy, void *dev_id)
874 808
875 spin_lock_irqsave(&bp->lock, flags); 809 spin_lock_irqsave(&bp->lock, flags);
876 810
877 dprintk (SX_DEBUG_FLOW, "enter %s port %d room: %ld\n", __func__, port_No(sx_get_port(bp, "INT")), SERIAL_XMIT_SIZE - sx_get_port(bp, "ITN")->xmit_cnt - 1); 811 dprintk(SX_DEBUG_FLOW, "enter %s port %d room: %ld\n", __func__,
812 port_No(sx_get_port(bp, "INT")),
813 SERIAL_XMIT_SIZE - sx_get_port(bp, "ITN")->xmit_cnt - 1);
878 if (!(bp->flags & SX_BOARD_ACTIVE)) { 814 if (!(bp->flags & SX_BOARD_ACTIVE)) {
879 dprintk (SX_DEBUG_IRQ, "sx: False interrupt. irq %d.\n", bp->irq); 815 dprintk(SX_DEBUG_IRQ, "sx: False interrupt. irq %d.\n",
816 bp->irq);
880 spin_unlock_irqrestore(&bp->lock, flags); 817 spin_unlock_irqrestore(&bp->lock, flags);
881 func_exit(); 818 func_exit();
882 return IRQ_NONE; 819 return IRQ_NONE;
@@ -884,10 +821,11 @@ static irqreturn_t sx_interrupt(int dummy, void *dev_id)
884 821
885 saved_reg = bp->reg; 822 saved_reg = bp->reg;
886 823
887 while ((++loop < 16) && (status = (sx_in(bp, CD186x_SRSR) & 824 while (++loop < 16) {
888 (SRSR_RREQint | 825 status = sx_in(bp, CD186x_SRSR) &
889 SRSR_TREQint | 826 (SRSR_RREQint | SRSR_TREQint | SRSR_MREQint);
890 SRSR_MREQint)))) { 827 if (status == 0)
828 break;
891 if (status & SRSR_RREQint) { 829 if (status & SRSR_RREQint) {
892 ack = sx_in(bp, CD186x_RRAR); 830 ack = sx_in(bp, CD186x_RRAR);
893 831
@@ -896,8 +834,9 @@ static irqreturn_t sx_interrupt(int dummy, void *dev_id)
896 else if (ack == (SX_ID | GIVR_IT_REXC)) 834 else if (ack == (SX_ID | GIVR_IT_REXC))
897 sx_receive_exc(bp); 835 sx_receive_exc(bp);
898 else 836 else
899 printk(KERN_ERR "sx%d: status: 0x%x Bad receive ack 0x%02x.\n", 837 printk(KERN_ERR
900 board_No(bp), status, ack); 838 "sx%d: status: 0x%x Bad receive ack 0x%02x.\n",
839 board_No(bp), status, ack);
901 840
902 } else if (status & SRSR_TREQint) { 841 } else if (status & SRSR_TREQint) {
903 ack = sx_in(bp, CD186x_TRAR); 842 ack = sx_in(bp, CD186x_TRAR);
@@ -906,14 +845,16 @@ static irqreturn_t sx_interrupt(int dummy, void *dev_id)
906 sx_transmit(bp); 845 sx_transmit(bp);
907 else 846 else
908 printk(KERN_ERR "sx%d: status: 0x%x Bad transmit ack 0x%02x. port: %d\n", 847 printk(KERN_ERR "sx%d: status: 0x%x Bad transmit ack 0x%02x. port: %d\n",
909 board_No(bp), status, ack, port_No (sx_get_port (bp, "Int"))); 848 board_No(bp), status, ack,
849 port_No(sx_get_port(bp, "Int")));
910 } else if (status & SRSR_MREQint) { 850 } else if (status & SRSR_MREQint) {
911 ack = sx_in(bp, CD186x_MRAR); 851 ack = sx_in(bp, CD186x_MRAR);
912 852
913 if (ack == (SX_ID | GIVR_IT_MODEM)) 853 if (ack == (SX_ID | GIVR_IT_MODEM))
914 sx_check_modem(bp); 854 sx_check_modem(bp);
915 else 855 else
916 printk(KERN_ERR "sx%d: status: 0x%x Bad modem ack 0x%02x.\n", 856 printk(KERN_ERR
857 "sx%d: status: 0x%x Bad modem ack 0x%02x.\n",
917 board_No(bp), status, ack); 858 board_No(bp), status, ack);
918 859
919 } 860 }
@@ -921,7 +862,7 @@ static irqreturn_t sx_interrupt(int dummy, void *dev_id)
921 sx_out(bp, CD186x_EOIR, 0); /* Mark end of interrupt */ 862 sx_out(bp, CD186x_EOIR, 0); /* Mark end of interrupt */
922 } 863 }
923 bp->reg = saved_reg; 864 bp->reg = saved_reg;
924 outb (bp->reg, bp->base + SX_ADDR_REG); 865 outb(bp->reg, bp->base + SX_ADDR_REG);
925 spin_unlock_irqrestore(&bp->lock, flags); 866 spin_unlock_irqrestore(&bp->lock, flags);
926 func_exit(); 867 func_exit();
927 return IRQ_HANDLED; 868 return IRQ_HANDLED;
@@ -932,36 +873,26 @@ static irqreturn_t sx_interrupt(int dummy, void *dev_id)
932 * Routines for open & close processing. 873 * Routines for open & close processing.
933 */ 874 */
934 875
935static void turn_ints_off (struct specialix_board *bp) 876static void turn_ints_off(struct specialix_board *bp)
936{ 877{
937 unsigned long flags; 878 unsigned long flags;
938 879
939 func_enter(); 880 func_enter();
940 if (bp->flags & SX_BOARD_IS_PCI) {
941 /* This was intended for enabeling the interrupt on the
942 * PCI card. However it seems that it's already enabled
943 * and as PCI interrupts can be shared, there is no real
944 * reason to have to turn it off. */
945 }
946
947 spin_lock_irqsave(&bp->lock, flags); 881 spin_lock_irqsave(&bp->lock, flags);
948 (void) sx_in_off (bp, 0); /* Turn off interrupts. */ 882 (void) sx_in_off(bp, 0); /* Turn off interrupts. */
949 spin_unlock_irqrestore(&bp->lock, flags); 883 spin_unlock_irqrestore(&bp->lock, flags);
950 884
951 func_exit(); 885 func_exit();
952} 886}
953 887
954static void turn_ints_on (struct specialix_board *bp) 888static void turn_ints_on(struct specialix_board *bp)
955{ 889{
956 unsigned long flags; 890 unsigned long flags;
957 891
958 func_enter(); 892 func_enter();
959 893
960 if (bp->flags & SX_BOARD_IS_PCI) {
961 /* play with the PCI chip. See comment above. */
962 }
963 spin_lock_irqsave(&bp->lock, flags); 894 spin_lock_irqsave(&bp->lock, flags);
964 (void) sx_in (bp, 0); /* Turn ON interrupts. */ 895 (void) sx_in(bp, 0); /* Turn ON interrupts. */
965 spin_unlock_irqrestore(&bp->lock, flags); 896 spin_unlock_irqrestore(&bp->lock, flags);
966 897
967 func_exit(); 898 func_exit();
@@ -969,7 +900,7 @@ static void turn_ints_on (struct specialix_board *bp)
969 900
970 901
971/* Called with disabled interrupts */ 902/* Called with disabled interrupts */
972static inline int sx_setup_board(struct specialix_board * bp) 903static int sx_setup_board(struct specialix_board *bp)
973{ 904{
974 int error; 905 int error;
975 906
@@ -977,14 +908,16 @@ static inline int sx_setup_board(struct specialix_board * bp)
977 return 0; 908 return 0;
978 909
979 if (bp->flags & SX_BOARD_IS_PCI) 910 if (bp->flags & SX_BOARD_IS_PCI)
980 error = request_irq(bp->irq, sx_interrupt, IRQF_DISABLED | IRQF_SHARED, "specialix IO8+", bp); 911 error = request_irq(bp->irq, sx_interrupt,
912 IRQF_DISABLED | IRQF_SHARED, "specialix IO8+", bp);
981 else 913 else
982 error = request_irq(bp->irq, sx_interrupt, IRQF_DISABLED, "specialix IO8+", bp); 914 error = request_irq(bp->irq, sx_interrupt,
915 IRQF_DISABLED, "specialix IO8+", bp);
983 916
984 if (error) 917 if (error)
985 return error; 918 return error;
986 919
987 turn_ints_on (bp); 920 turn_ints_on(bp);
988 bp->flags |= SX_BOARD_ACTIVE; 921 bp->flags |= SX_BOARD_ACTIVE;
989 922
990 return 0; 923 return 0;
@@ -992,7 +925,7 @@ static inline int sx_setup_board(struct specialix_board * bp)
992 925
993 926
994/* Called with disabled interrupts */ 927/* Called with disabled interrupts */
995static inline void sx_shutdown_board(struct specialix_board *bp) 928static void sx_shutdown_board(struct specialix_board *bp)
996{ 929{
997 func_enter(); 930 func_enter();
998 931
@@ -1003,22 +936,26 @@ static inline void sx_shutdown_board(struct specialix_board *bp)
1003 936
1004 bp->flags &= ~SX_BOARD_ACTIVE; 937 bp->flags &= ~SX_BOARD_ACTIVE;
1005 938
1006 dprintk (SX_DEBUG_IRQ, "Freeing IRQ%d for board %d.\n", 939 dprintk(SX_DEBUG_IRQ, "Freeing IRQ%d for board %d.\n",
1007 bp->irq, board_No (bp)); 940 bp->irq, board_No(bp));
1008 free_irq(bp->irq, bp); 941 free_irq(bp->irq, bp);
1009 942 turn_ints_off(bp);
1010 turn_ints_off (bp);
1011
1012
1013 func_exit(); 943 func_exit();
1014} 944}
1015 945
946static unsigned int sx_crtscts(struct tty_struct *tty)
947{
948 if (sx_rtscts)
949 return C_CRTSCTS(tty);
950 return 1;
951}
1016 952
1017/* 953/*
1018 * Setting up port characteristics. 954 * Setting up port characteristics.
1019 * Must be called with disabled interrupts 955 * Must be called with disabled interrupts
1020 */ 956 */
1021static void sx_change_speed(struct specialix_board *bp, struct specialix_port *port) 957static void sx_change_speed(struct specialix_board *bp,
958 struct specialix_port *port)
1022{ 959{
1023 struct tty_struct *tty; 960 struct tty_struct *tty;
1024 unsigned long baud; 961 unsigned long baud;
@@ -1030,7 +967,8 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p
1030 967
1031 func_enter(); 968 func_enter();
1032 969
1033 if (!(tty = port->port.tty) || !tty->termios) { 970 tty = port->port.tty;
971 if (!tty || !tty->termios) {
1034 func_exit(); 972 func_exit();
1035 return; 973 return;
1036 } 974 }
@@ -1043,12 +981,12 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p
1043 981
1044 /* The Specialix board doens't implement the RTS lines. 982 /* The Specialix board doens't implement the RTS lines.
1045 They are used to set the IRQ level. Don't touch them. */ 983 They are used to set the IRQ level. Don't touch them. */
1046 if (SX_CRTSCTS(tty)) 984 if (sx_crtscts(tty))
1047 port->MSVR = MSVR_DTR | (sx_in(bp, CD186x_MSVR) & MSVR_RTS); 985 port->MSVR = MSVR_DTR | (sx_in(bp, CD186x_MSVR) & MSVR_RTS);
1048 else 986 else
1049 port->MSVR = (sx_in(bp, CD186x_MSVR) & MSVR_RTS); 987 port->MSVR = (sx_in(bp, CD186x_MSVR) & MSVR_RTS);
1050 spin_unlock_irqrestore(&bp->lock, flags); 988 spin_unlock_irqrestore(&bp->lock, flags);
1051 dprintk (SX_DEBUG_TERMIOS, "sx: got MSVR=%02x.\n", port->MSVR); 989 dprintk(SX_DEBUG_TERMIOS, "sx: got MSVR=%02x.\n", port->MSVR);
1052 baud = tty_get_baud_rate(tty); 990 baud = tty_get_baud_rate(tty);
1053 991
1054 if (baud == 38400) { 992 if (baud == 38400) {
@@ -1060,21 +998,19 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p
1060 998
1061 if (!baud) { 999 if (!baud) {
1062 /* Drop DTR & exit */ 1000 /* Drop DTR & exit */
1063 dprintk (SX_DEBUG_TERMIOS, "Dropping DTR... Hmm....\n"); 1001 dprintk(SX_DEBUG_TERMIOS, "Dropping DTR... Hmm....\n");
1064 if (!SX_CRTSCTS (tty)) { 1002 if (!sx_crtscts(tty)) {
1065 port -> MSVR &= ~ MSVR_DTR; 1003 port->MSVR &= ~MSVR_DTR;
1066 spin_lock_irqsave(&bp->lock, flags); 1004 spin_lock_irqsave(&bp->lock, flags);
1067 sx_out(bp, CD186x_MSVR, port->MSVR ); 1005 sx_out(bp, CD186x_MSVR, port->MSVR);
1068 spin_unlock_irqrestore(&bp->lock, flags); 1006 spin_unlock_irqrestore(&bp->lock, flags);
1069 } 1007 } else
1070 else 1008 dprintk(SX_DEBUG_TERMIOS, "Can't drop DTR: no DTR.\n");
1071 dprintk (SX_DEBUG_TERMIOS, "Can't drop DTR: no DTR.\n");
1072 return; 1009 return;
1073 } else { 1010 } else {
1074 /* Set DTR on */ 1011 /* Set DTR on */
1075 if (!SX_CRTSCTS (tty)) { 1012 if (!sx_crtscts(tty))
1076 port ->MSVR |= MSVR_DTR; 1013 port->MSVR |= MSVR_DTR;
1077 }
1078 } 1014 }
1079 1015
1080 /* 1016 /*
@@ -1083,28 +1019,27 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p
1083 1019
1084 /* Set baud rate for port */ 1020 /* Set baud rate for port */
1085 tmp = port->custom_divisor ; 1021 tmp = port->custom_divisor ;
1086 if ( tmp ) 1022 if (tmp)
1087 printk (KERN_INFO "sx%d: Using custom baud rate divisor %ld. \n" 1023 printk(KERN_INFO
1088 "This is an untested option, please be carefull.\n", 1024 "sx%d: Using custom baud rate divisor %ld. \n"
1089 port_No (port), tmp); 1025 "This is an untested option, please be careful.\n",
1026 port_No(port), tmp);
1090 else 1027 else
1091 tmp = (((SX_OSCFREQ + baud/2) / baud + 1028 tmp = (((SX_OSCFREQ + baud/2) / baud + CD186x_TPC/2) /
1092 CD186x_TPC/2) / CD186x_TPC); 1029 CD186x_TPC);
1093 1030
1094 if ((tmp < 0x10) && time_before(again, jiffies)) { 1031 if (tmp < 0x10 && time_before(again, jiffies)) {
1095 again = jiffies + HZ * 60; 1032 again = jiffies + HZ * 60;
1096 /* Page 48 of version 2.0 of the CL-CD1865 databook */ 1033 /* Page 48 of version 2.0 of the CL-CD1865 databook */
1097 if (tmp >= 12) { 1034 if (tmp >= 12) {
1098 printk (KERN_INFO "sx%d: Baud rate divisor is %ld. \n" 1035 printk(KERN_INFO "sx%d: Baud rate divisor is %ld. \n"
1099 "Performance degradation is possible.\n" 1036 "Performance degradation is possible.\n"
1100 "Read specialix.txt for more info.\n", 1037 "Read specialix.txt for more info.\n",
1101 port_No (port), tmp); 1038 port_No(port), tmp);
1102 } else { 1039 } else {
1103 printk (KERN_INFO "sx%d: Baud rate divisor is %ld. \n" 1040 printk(KERN_INFO "sx%d: Baud rate divisor is %ld. \n"
1104 "Warning: overstressing Cirrus chip. " 1041 "Warning: overstressing Cirrus chip. This might not work.\n"
1105 "This might not work.\n" 1042 "Read specialix.txt for more info.\n", port_No(port), tmp);
1106 "Read specialix.txt for more info.\n",
1107 port_No (port), tmp);
1108 } 1043 }
1109 } 1044 }
1110 spin_lock_irqsave(&bp->lock, flags); 1045 spin_lock_irqsave(&bp->lock, flags);
@@ -1114,7 +1049,8 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p
1114 sx_out(bp, CD186x_TBPRL, tmp & 0xff); 1049 sx_out(bp, CD186x_TBPRL, tmp & 0xff);
1115 spin_unlock_irqrestore(&bp->lock, flags); 1050 spin_unlock_irqrestore(&bp->lock, flags);
1116 if (port->custom_divisor) 1051 if (port->custom_divisor)
1117 baud = (SX_OSCFREQ + port->custom_divisor/2) / port->custom_divisor; 1052 baud = (SX_OSCFREQ + port->custom_divisor/2) /
1053 port->custom_divisor;
1118 baud = (baud + 5) / 10; /* Estimated CPS */ 1054 baud = (baud + 5) / 10; /* Estimated CPS */
1119 1055
1120 /* Two timer ticks seems enough to wakeup something like SLIP driver */ 1056 /* Two timer ticks seems enough to wakeup something like SLIP driver */
@@ -1129,16 +1065,16 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p
1129 sx_out(bp, CD186x_RTPR, tmp); 1065 sx_out(bp, CD186x_RTPR, tmp);
1130 spin_unlock_irqrestore(&bp->lock, flags); 1066 spin_unlock_irqrestore(&bp->lock, flags);
1131 switch (C_CSIZE(tty)) { 1067 switch (C_CSIZE(tty)) {
1132 case CS5: 1068 case CS5:
1133 cor1 |= COR1_5BITS; 1069 cor1 |= COR1_5BITS;
1134 break; 1070 break;
1135 case CS6: 1071 case CS6:
1136 cor1 |= COR1_6BITS; 1072 cor1 |= COR1_6BITS;
1137 break; 1073 break;
1138 case CS7: 1074 case CS7:
1139 cor1 |= COR1_7BITS; 1075 cor1 |= COR1_7BITS;
1140 break; 1076 break;
1141 case CS8: 1077 case CS8:
1142 cor1 |= COR1_8BITS; 1078 cor1 |= COR1_8BITS;
1143 break; 1079 break;
1144 } 1080 }
@@ -1175,7 +1111,8 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p
1175 mcor1 |= MCOR1_DSRZD | MCOR1_CTSZD; 1111 mcor1 |= MCOR1_DSRZD | MCOR1_CTSZD;
1176 mcor2 |= MCOR2_DSROD | MCOR2_CTSOD; 1112 mcor2 |= MCOR2_DSROD | MCOR2_CTSOD;
1177 spin_lock_irqsave(&bp->lock, flags); 1113 spin_lock_irqsave(&bp->lock, flags);
1178 tty->hw_stopped = !(sx_in(bp, CD186x_MSVR) & (MSVR_CTS|MSVR_DSR)); 1114 tty->hw_stopped = !(sx_in(bp, CD186x_MSVR) &
1115 (MSVR_CTS|MSVR_DSR));
1179 spin_unlock_irqrestore(&bp->lock, flags); 1116 spin_unlock_irqrestore(&bp->lock, flags);
1180#else 1117#else
1181 port->COR2 |= COR2_CTSAE; 1118 port->COR2 |= COR2_CTSAE;
@@ -1219,7 +1156,8 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p
1219 spin_lock_irqsave(&bp->lock, flags); 1156 spin_lock_irqsave(&bp->lock, flags);
1220 sx_out(bp, CD186x_CCR, CCR_CORCHG1 | CCR_CORCHG2 | CCR_CORCHG3); 1157 sx_out(bp, CD186x_CCR, CCR_CORCHG1 | CCR_CORCHG2 | CCR_CORCHG3);
1221 /* Setting up modem option registers */ 1158 /* Setting up modem option registers */
1222 dprintk (SX_DEBUG_TERMIOS, "Mcor1 = %02x, mcor2 = %02x.\n", mcor1, mcor2); 1159 dprintk(SX_DEBUG_TERMIOS, "Mcor1 = %02x, mcor2 = %02x.\n",
1160 mcor1, mcor2);
1223 sx_out(bp, CD186x_MCOR1, mcor1); 1161 sx_out(bp, CD186x_MCOR1, mcor1);
1224 sx_out(bp, CD186x_MCOR2, mcor2); 1162 sx_out(bp, CD186x_MCOR2, mcor2);
1225 spin_unlock_irqrestore(&bp->lock, flags); 1163 spin_unlock_irqrestore(&bp->lock, flags);
@@ -1238,7 +1176,8 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p
1238 1176
1239 1177
1240/* Must be called with interrupts enabled */ 1178/* Must be called with interrupts enabled */
1241static int sx_setup_port(struct specialix_board *bp, struct specialix_port *port) 1179static int sx_setup_port(struct specialix_board *bp,
1180 struct specialix_port *port)
1242{ 1181{
1243 unsigned long flags; 1182 unsigned long flags;
1244 1183
@@ -1253,7 +1192,8 @@ static int sx_setup_port(struct specialix_board *bp, struct specialix_port *port
1253 /* We may sleep in get_zeroed_page() */ 1192 /* We may sleep in get_zeroed_page() */
1254 unsigned long tmp; 1193 unsigned long tmp;
1255 1194
1256 if (!(tmp = get_zeroed_page(GFP_KERNEL))) { 1195 tmp = get_zeroed_page(GFP_KERNEL);
1196 if (tmp == 0L) {
1257 func_exit(); 1197 func_exit();
1258 return -ENOMEM; 1198 return -ENOMEM;
1259 } 1199 }
@@ -1284,7 +1224,8 @@ static int sx_setup_port(struct specialix_board *bp, struct specialix_port *port
1284 1224
1285 1225
1286/* Must be called with interrupts disabled */ 1226/* Must be called with interrupts disabled */
1287static void sx_shutdown_port(struct specialix_board *bp, struct specialix_port *port) 1227static void sx_shutdown_port(struct specialix_board *bp,
1228 struct specialix_port *port)
1288{ 1229{
1289 struct tty_struct *tty; 1230 struct tty_struct *tty;
1290 int i; 1231 int i;
@@ -1298,11 +1239,11 @@ static void sx_shutdown_port(struct specialix_board *bp, struct specialix_port *
1298 } 1239 }
1299 1240
1300 if (sx_debug & SX_DEBUG_FIFO) { 1241 if (sx_debug & SX_DEBUG_FIFO) {
1301 dprintk(SX_DEBUG_FIFO, "sx%d: port %d: %ld overruns, FIFO hits [ ", 1242 dprintk(SX_DEBUG_FIFO,
1302 board_No(bp), port_No(port), port->overrun); 1243 "sx%d: port %d: %ld overruns, FIFO hits [ ",
1303 for (i = 0; i < 10; i++) { 1244 board_No(bp), port_No(port), port->overrun);
1245 for (i = 0; i < 10; i++)
1304 dprintk(SX_DEBUG_FIFO, "%ld ", port->hits[i]); 1246 dprintk(SX_DEBUG_FIFO, "%ld ", port->hits[i]);
1305 }
1306 dprintk(SX_DEBUG_FIFO, "].\n"); 1247 dprintk(SX_DEBUG_FIFO, "].\n");
1307 } 1248 }
1308 1249
@@ -1315,7 +1256,8 @@ static void sx_shutdown_port(struct specialix_board *bp, struct specialix_port *
1315 spin_lock_irqsave(&bp->lock, flags); 1256 spin_lock_irqsave(&bp->lock, flags);
1316 sx_out(bp, CD186x_CAR, port_No(port)); 1257 sx_out(bp, CD186x_CAR, port_No(port));
1317 1258
1318 if (!(tty = port->port.tty) || C_HUPCL(tty)) { 1259 tty = port->port.tty;
1260 if (tty == NULL || C_HUPCL(tty)) {
1319 /* Drop DTR */ 1261 /* Drop DTR */
1320 sx_out(bp, CD186x_MSVDTR, 0); 1262 sx_out(bp, CD186x_MSVDTR, 0);
1321 } 1263 }
@@ -1338,8 +1280,8 @@ static void sx_shutdown_port(struct specialix_board *bp, struct specialix_port *
1338} 1280}
1339 1281
1340 1282
1341static int block_til_ready(struct tty_struct *tty, struct file * filp, 1283static int block_til_ready(struct tty_struct *tty, struct file *filp,
1342 struct specialix_port *port) 1284 struct specialix_port *port)
1343{ 1285{
1344 DECLARE_WAITQUEUE(wait, current); 1286 DECLARE_WAITQUEUE(wait, current);
1345 struct specialix_board *bp = port_Board(port); 1287 struct specialix_board *bp = port_Board(port);
@@ -1389,23 +1331,22 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
1389 retval = 0; 1331 retval = 0;
1390 add_wait_queue(&port->port.open_wait, &wait); 1332 add_wait_queue(&port->port.open_wait, &wait);
1391 spin_lock_irqsave(&port->lock, flags); 1333 spin_lock_irqsave(&port->lock, flags);
1392 if (!tty_hung_up_p(filp)) { 1334 if (!tty_hung_up_p(filp))
1393 port->port.count--; 1335 port->port.count--;
1394 }
1395 spin_unlock_irqrestore(&port->lock, flags); 1336 spin_unlock_irqrestore(&port->lock, flags);
1396 port->port.blocked_open++; 1337 port->port.blocked_open++;
1397 while (1) { 1338 while (1) {
1398 spin_lock_irqsave(&bp->lock, flags); 1339 spin_lock_irqsave(&bp->lock, flags);
1399 sx_out(bp, CD186x_CAR, port_No(port)); 1340 sx_out(bp, CD186x_CAR, port_No(port));
1400 CD = sx_in(bp, CD186x_MSVR) & MSVR_CD; 1341 CD = sx_in(bp, CD186x_MSVR) & MSVR_CD;
1401 if (SX_CRTSCTS (tty)) { 1342 if (sx_crtscts(tty)) {
1402 /* Activate RTS */ 1343 /* Activate RTS */
1403 port->MSVR |= MSVR_DTR; /* WTF? */ 1344 port->MSVR |= MSVR_DTR; /* WTF? */
1404 sx_out (bp, CD186x_MSVR, port->MSVR); 1345 sx_out(bp, CD186x_MSVR, port->MSVR);
1405 } else { 1346 } else {
1406 /* Activate DTR */ 1347 /* Activate DTR */
1407 port->MSVR |= MSVR_DTR; 1348 port->MSVR |= MSVR_DTR;
1408 sx_out (bp, CD186x_MSVR, port->MSVR); 1349 sx_out(bp, CD186x_MSVR, port->MSVR);
1409 } 1350 }
1410 spin_unlock_irqrestore(&bp->lock, flags); 1351 spin_unlock_irqrestore(&bp->lock, flags);
1411 set_current_state(TASK_INTERRUPTIBLE); 1352 set_current_state(TASK_INTERRUPTIBLE);
@@ -1430,9 +1371,8 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
1430 set_current_state(TASK_RUNNING); 1371 set_current_state(TASK_RUNNING);
1431 remove_wait_queue(&port->port.open_wait, &wait); 1372 remove_wait_queue(&port->port.open_wait, &wait);
1432 spin_lock_irqsave(&port->lock, flags); 1373 spin_lock_irqsave(&port->lock, flags);
1433 if (!tty_hung_up_p(filp)) { 1374 if (!tty_hung_up_p(filp))
1434 port->port.count++; 1375 port->port.count++;
1435 }
1436 port->port.blocked_open--; 1376 port->port.blocked_open--;
1437 spin_unlock_irqrestore(&port->lock, flags); 1377 spin_unlock_irqrestore(&port->lock, flags);
1438 if (retval) { 1378 if (retval) {
@@ -1446,12 +1386,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
1446} 1386}
1447 1387
1448 1388
1449static int sx_open(struct tty_struct * tty, struct file * filp) 1389static int sx_open(struct tty_struct *tty, struct file *filp)
1450{ 1390{
1451 int board; 1391 int board;
1452 int error; 1392 int error;
1453 struct specialix_port * port; 1393 struct specialix_port *port;
1454 struct specialix_board * bp; 1394 struct specialix_board *bp;
1455 int i; 1395 int i;
1456 unsigned long flags; 1396 unsigned long flags;
1457 1397
@@ -1468,17 +1408,19 @@ static int sx_open(struct tty_struct * tty, struct file * filp)
1468 port = sx_port + board * SX_NPORT + SX_PORT(tty->index); 1408 port = sx_port + board * SX_NPORT + SX_PORT(tty->index);
1469 port->overrun = 0; 1409 port->overrun = 0;
1470 for (i = 0; i < 10; i++) 1410 for (i = 0; i < 10; i++)
1471 port->hits[i]=0; 1411 port->hits[i] = 0;
1472 1412
1473 dprintk (SX_DEBUG_OPEN, "Board = %d, bp = %p, port = %p, portno = %d.\n", 1413 dprintk(SX_DEBUG_OPEN,
1474 board, bp, port, SX_PORT(tty->index)); 1414 "Board = %d, bp = %p, port = %p, portno = %d.\n",
1415 board, bp, port, SX_PORT(tty->index));
1475 1416
1476 if (sx_paranoia_check(port, tty->name, "sx_open")) { 1417 if (sx_paranoia_check(port, tty->name, "sx_open")) {
1477 func_enter(); 1418 func_enter();
1478 return -ENODEV; 1419 return -ENODEV;
1479 } 1420 }
1480 1421
1481 if ((error = sx_setup_board(bp))) { 1422 error = sx_setup_board(bp);
1423 if (error) {
1482 func_exit(); 1424 func_exit();
1483 return error; 1425 return error;
1484 } 1426 }
@@ -1490,12 +1432,14 @@ static int sx_open(struct tty_struct * tty, struct file * filp)
1490 port->port.tty = tty; 1432 port->port.tty = tty;
1491 spin_unlock_irqrestore(&bp->lock, flags); 1433 spin_unlock_irqrestore(&bp->lock, flags);
1492 1434
1493 if ((error = sx_setup_port(bp, port))) { 1435 error = sx_setup_port(bp, port);
1436 if (error) {
1494 func_enter(); 1437 func_enter();
1495 return error; 1438 return error;
1496 } 1439 }
1497 1440
1498 if ((error = block_til_ready(tty, filp, port))) { 1441 error = block_til_ready(tty, filp, port);
1442 if (error) {
1499 func_enter(); 1443 func_enter();
1500 return error; 1444 return error;
1501 } 1445 }
@@ -1508,7 +1452,7 @@ static void sx_flush_buffer(struct tty_struct *tty)
1508{ 1452{
1509 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 1453 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
1510 unsigned long flags; 1454 unsigned long flags;
1511 struct specialix_board * bp; 1455 struct specialix_board *bp;
1512 1456
1513 func_enter(); 1457 func_enter();
1514 1458
@@ -1526,9 +1470,9 @@ static void sx_flush_buffer(struct tty_struct *tty)
1526 func_exit(); 1470 func_exit();
1527} 1471}
1528 1472
1529static void sx_close(struct tty_struct * tty, struct file * filp) 1473static void sx_close(struct tty_struct *tty, struct file *filp)
1530{ 1474{
1531 struct specialix_port *port = (struct specialix_port *) tty->driver_data; 1475 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
1532 struct specialix_board *bp; 1476 struct specialix_board *bp;
1533 unsigned long flags; 1477 unsigned long flags;
1534 unsigned long timeout; 1478 unsigned long timeout;
@@ -1547,7 +1491,7 @@ static void sx_close(struct tty_struct * tty, struct file * filp)
1547 } 1491 }
1548 1492
1549 bp = port_Board(port); 1493 bp = port_Board(port);
1550 if ((tty->count == 1) && (port->port.count != 1)) { 1494 if (tty->count == 1 && port->port.count != 1) {
1551 printk(KERN_ERR "sx%d: sx_close: bad port count;" 1495 printk(KERN_ERR "sx%d: sx_close: bad port count;"
1552 " tty->count is 1, port count is %d\n", 1496 " tty->count is 1, port count is %d\n",
1553 board_No(bp), port->port.count); 1497 board_No(bp), port->port.count);
@@ -1570,17 +1514,16 @@ static void sx_close(struct tty_struct * tty, struct file * filp)
1570 */ 1514 */
1571 tty->closing = 1; 1515 tty->closing = 1;
1572 spin_unlock_irqrestore(&port->lock, flags); 1516 spin_unlock_irqrestore(&port->lock, flags);
1573 dprintk (SX_DEBUG_OPEN, "Closing\n"); 1517 dprintk(SX_DEBUG_OPEN, "Closing\n");
1574 if (port->port.closing_wait != ASYNC_CLOSING_WAIT_NONE) { 1518 if (port->port.closing_wait != ASYNC_CLOSING_WAIT_NONE)
1575 tty_wait_until_sent(tty, port->port.closing_wait); 1519 tty_wait_until_sent(tty, port->port.closing_wait);
1576 }
1577 /* 1520 /*
1578 * At this point we stop accepting input. To do this, we 1521 * At this point we stop accepting input. To do this, we
1579 * disable the receive line status interrupts, and tell the 1522 * disable the receive line status interrupts, and tell the
1580 * interrupt driver to stop checking the data ready bit in the 1523 * interrupt driver to stop checking the data ready bit in the
1581 * line status register. 1524 * line status register.
1582 */ 1525 */
1583 dprintk (SX_DEBUG_OPEN, "Closed\n"); 1526 dprintk(SX_DEBUG_OPEN, "Closed\n");
1584 port->IER &= ~IER_RXD; 1527 port->IER &= ~IER_RXD;
1585 if (port->port.flags & ASYNC_INITIALIZED) { 1528 if (port->port.flags & ASYNC_INITIALIZED) {
1586 port->IER &= ~IER_TXRDY; 1529 port->IER &= ~IER_TXRDY;
@@ -1595,11 +1538,11 @@ static void sx_close(struct tty_struct * tty, struct file * filp)
1595 * important if there is a transmit FIFO! 1538 * important if there is a transmit FIFO!
1596 */ 1539 */
1597 timeout = jiffies+HZ; 1540 timeout = jiffies+HZ;
1598 while(port->IER & IER_TXEMPTY) { 1541 while (port->IER & IER_TXEMPTY) {
1599 set_current_state (TASK_INTERRUPTIBLE); 1542 set_current_state(TASK_INTERRUPTIBLE);
1600 msleep_interruptible(jiffies_to_msecs(port->timeout)); 1543 msleep_interruptible(jiffies_to_msecs(port->timeout));
1601 if (time_after(jiffies, timeout)) { 1544 if (time_after(jiffies, timeout)) {
1602 printk (KERN_INFO "Timeout waiting for close\n"); 1545 printk(KERN_INFO "Timeout waiting for close\n");
1603 break; 1546 break;
1604 } 1547 }
1605 } 1548 }
@@ -1607,13 +1550,15 @@ static void sx_close(struct tty_struct * tty, struct file * filp)
1607 } 1550 }
1608 1551
1609 if (--bp->count < 0) { 1552 if (--bp->count < 0) {
1610 printk(KERN_ERR "sx%d: sx_shutdown_port: bad board count: %d port: %d\n", 1553 printk(KERN_ERR
1611 board_No(bp), bp->count, tty->index); 1554 "sx%d: sx_shutdown_port: bad board count: %d port: %d\n",
1555 board_No(bp), bp->count, tty->index);
1612 bp->count = 0; 1556 bp->count = 0;
1613 } 1557 }
1614 if (--port->port.count < 0) { 1558 if (--port->port.count < 0) {
1615 printk(KERN_ERR "sx%d: sx_close: bad port count for tty%d: %d\n", 1559 printk(KERN_ERR
1616 board_No(bp), port_No(port), port->port.count); 1560 "sx%d: sx_close: bad port count for tty%d: %d\n",
1561 board_No(bp), port_No(port), port->port.count);
1617 port->port.count = 0; 1562 port->port.count = 0;
1618 } 1563 }
1619 1564
@@ -1625,9 +1570,9 @@ static void sx_close(struct tty_struct * tty, struct file * filp)
1625 port->port.tty = NULL; 1570 port->port.tty = NULL;
1626 spin_unlock_irqrestore(&port->lock, flags); 1571 spin_unlock_irqrestore(&port->lock, flags);
1627 if (port->port.blocked_open) { 1572 if (port->port.blocked_open) {
1628 if (port->port.close_delay) { 1573 if (port->port.close_delay)
1629 msleep_interruptible(jiffies_to_msecs(port->port.close_delay)); 1574 msleep_interruptible(
1630 } 1575 jiffies_to_msecs(port->port.close_delay));
1631 wake_up_interruptible(&port->port.open_wait); 1576 wake_up_interruptible(&port->port.open_wait);
1632 } 1577 }
1633 port->port.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); 1578 port->port.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
@@ -1637,8 +1582,8 @@ static void sx_close(struct tty_struct * tty, struct file * filp)
1637} 1582}
1638 1583
1639 1584
1640static int sx_write(struct tty_struct * tty, 1585static int sx_write(struct tty_struct *tty,
1641 const unsigned char *buf, int count) 1586 const unsigned char *buf, int count)
1642{ 1587{
1643 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 1588 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
1644 struct specialix_board *bp; 1589 struct specialix_board *bp;
@@ -1690,11 +1635,11 @@ static int sx_write(struct tty_struct * tty,
1690} 1635}
1691 1636
1692 1637
1693static int sx_put_char(struct tty_struct * tty, unsigned char ch) 1638static int sx_put_char(struct tty_struct *tty, unsigned char ch)
1694{ 1639{
1695 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 1640 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
1696 unsigned long flags; 1641 unsigned long flags;
1697 struct specialix_board * bp; 1642 struct specialix_board *bp;
1698 1643
1699 func_enter(); 1644 func_enter();
1700 1645
@@ -1702,7 +1647,7 @@ static int sx_put_char(struct tty_struct * tty, unsigned char ch)
1702 func_exit(); 1647 func_exit();
1703 return 0; 1648 return 0;
1704 } 1649 }
1705 dprintk (SX_DEBUG_TX, "check tty: %p %p\n", tty, port->xmit_buf); 1650 dprintk(SX_DEBUG_TX, "check tty: %p %p\n", tty, port->xmit_buf);
1706 if (!port->xmit_buf) { 1651 if (!port->xmit_buf) {
1707 func_exit(); 1652 func_exit();
1708 return 0; 1653 return 0;
@@ -1710,14 +1655,15 @@ static int sx_put_char(struct tty_struct * tty, unsigned char ch)
1710 bp = port_Board(port); 1655 bp = port_Board(port);
1711 spin_lock_irqsave(&port->lock, flags); 1656 spin_lock_irqsave(&port->lock, flags);
1712 1657
1713 dprintk (SX_DEBUG_TX, "xmit_cnt: %d xmit_buf: %p\n", port->xmit_cnt, port->xmit_buf); 1658 dprintk(SX_DEBUG_TX, "xmit_cnt: %d xmit_buf: %p\n",
1714 if ((port->xmit_cnt >= SERIAL_XMIT_SIZE - 1) || (!port->xmit_buf)) { 1659 port->xmit_cnt, port->xmit_buf);
1660 if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1 || !port->xmit_buf) {
1715 spin_unlock_irqrestore(&port->lock, flags); 1661 spin_unlock_irqrestore(&port->lock, flags);
1716 dprintk (SX_DEBUG_TX, "Exit size\n"); 1662 dprintk(SX_DEBUG_TX, "Exit size\n");
1717 func_exit(); 1663 func_exit();
1718 return 0; 1664 return 0;
1719 } 1665 }
1720 dprintk (SX_DEBUG_TX, "Handle xmit: %p %p\n", port, port->xmit_buf); 1666 dprintk(SX_DEBUG_TX, "Handle xmit: %p %p\n", port, port->xmit_buf);
1721 port->xmit_buf[port->xmit_head++] = ch; 1667 port->xmit_buf[port->xmit_head++] = ch;
1722 port->xmit_head &= SERIAL_XMIT_SIZE - 1; 1668 port->xmit_head &= SERIAL_XMIT_SIZE - 1;
1723 port->xmit_cnt++; 1669 port->xmit_cnt++;
@@ -1728,11 +1674,11 @@ static int sx_put_char(struct tty_struct * tty, unsigned char ch)
1728} 1674}
1729 1675
1730 1676
1731static void sx_flush_chars(struct tty_struct * tty) 1677static void sx_flush_chars(struct tty_struct *tty)
1732{ 1678{
1733 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 1679 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
1734 unsigned long flags; 1680 unsigned long flags;
1735 struct specialix_board * bp = port_Board(port); 1681 struct specialix_board *bp = port_Board(port);
1736 1682
1737 func_enter(); 1683 func_enter();
1738 1684
@@ -1755,7 +1701,7 @@ static void sx_flush_chars(struct tty_struct * tty)
1755} 1701}
1756 1702
1757 1703
1758static int sx_write_room(struct tty_struct * tty) 1704static int sx_write_room(struct tty_struct *tty)
1759{ 1705{
1760 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 1706 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
1761 int ret; 1707 int ret;
@@ -1790,12 +1736,10 @@ static int sx_chars_in_buffer(struct tty_struct *tty)
1790 return port->xmit_cnt; 1736 return port->xmit_cnt;
1791} 1737}
1792 1738
1793
1794
1795static int sx_tiocmget(struct tty_struct *tty, struct file *file) 1739static int sx_tiocmget(struct tty_struct *tty, struct file *file)
1796{ 1740{
1797 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 1741 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
1798 struct specialix_board * bp; 1742 struct specialix_board *bp;
1799 unsigned char status; 1743 unsigned char status;
1800 unsigned int result; 1744 unsigned int result;
1801 unsigned long flags; 1745 unsigned long flags;
@@ -1808,25 +1752,23 @@ static int sx_tiocmget(struct tty_struct *tty, struct file *file)
1808 } 1752 }
1809 1753
1810 bp = port_Board(port); 1754 bp = port_Board(port);
1811 spin_lock_irqsave (&bp->lock, flags); 1755 spin_lock_irqsave(&bp->lock, flags);
1812 sx_out(bp, CD186x_CAR, port_No(port)); 1756 sx_out(bp, CD186x_CAR, port_No(port));
1813 status = sx_in(bp, CD186x_MSVR); 1757 status = sx_in(bp, CD186x_MSVR);
1814 spin_unlock_irqrestore(&bp->lock, flags); 1758 spin_unlock_irqrestore(&bp->lock, flags);
1815 dprintk (SX_DEBUG_INIT, "Got msvr[%d] = %02x, car = %d.\n", 1759 dprintk(SX_DEBUG_INIT, "Got msvr[%d] = %02x, car = %d.\n",
1816 port_No(port), status, sx_in (bp, CD186x_CAR)); 1760 port_No(port), status, sx_in(bp, CD186x_CAR));
1817 dprintk (SX_DEBUG_INIT, "sx_port = %p, port = %p\n", sx_port, port); 1761 dprintk(SX_DEBUG_INIT, "sx_port = %p, port = %p\n", sx_port, port);
1818 if (SX_CRTSCTS(port->port.tty)) { 1762 if (sx_crtscts(port->port.tty)) {
1819 result = /* (status & MSVR_RTS) ? */ TIOCM_DTR /* : 0) */ 1763 result = TIOCM_DTR | TIOCM_DSR
1820 | ((status & MSVR_DTR) ? TIOCM_RTS : 0) 1764 | ((status & MSVR_DTR) ? TIOCM_RTS : 0)
1821 | ((status & MSVR_CD) ? TIOCM_CAR : 0) 1765 | ((status & MSVR_CD) ? TIOCM_CAR : 0)
1822 |/* ((status & MSVR_DSR) ? */ TIOCM_DSR /* : 0) */ 1766 | ((status & MSVR_CTS) ? TIOCM_CTS : 0);
1823 | ((status & MSVR_CTS) ? TIOCM_CTS : 0);
1824 } else { 1767 } else {
1825 result = /* (status & MSVR_RTS) ? */ TIOCM_RTS /* : 0) */ 1768 result = TIOCM_RTS | TIOCM_DSR
1826 | ((status & MSVR_DTR) ? TIOCM_DTR : 0) 1769 | ((status & MSVR_DTR) ? TIOCM_DTR : 0)
1827 | ((status & MSVR_CD) ? TIOCM_CAR : 0) 1770 | ((status & MSVR_CD) ? TIOCM_CAR : 0)
1828 |/* ((status & MSVR_DSR) ? */ TIOCM_DSR /* : 0) */ 1771 | ((status & MSVR_CTS) ? TIOCM_CTS : 0);
1829 | ((status & MSVR_CTS) ? TIOCM_CTS : 0);
1830 } 1772 }
1831 1773
1832 func_exit(); 1774 func_exit();
@@ -1852,24 +1794,14 @@ static int sx_tiocmset(struct tty_struct *tty, struct file *file,
1852 bp = port_Board(port); 1794 bp = port_Board(port);
1853 1795
1854 spin_lock_irqsave(&port->lock, flags); 1796 spin_lock_irqsave(&port->lock, flags);
1855 /* if (set & TIOCM_RTS) 1797 if (sx_crtscts(port->port.tty)) {
1856 port->MSVR |= MSVR_RTS; */
1857 /* if (set & TIOCM_DTR)
1858 port->MSVR |= MSVR_DTR; */
1859
1860 if (SX_CRTSCTS(port->port.tty)) {
1861 if (set & TIOCM_RTS) 1798 if (set & TIOCM_RTS)
1862 port->MSVR |= MSVR_DTR; 1799 port->MSVR |= MSVR_DTR;
1863 } else { 1800 } else {
1864 if (set & TIOCM_DTR) 1801 if (set & TIOCM_DTR)
1865 port->MSVR |= MSVR_DTR; 1802 port->MSVR |= MSVR_DTR;
1866 } 1803 }
1867 1804 if (sx_crtscts(port->port.tty)) {
1868 /* if (clear & TIOCM_RTS)
1869 port->MSVR &= ~MSVR_RTS; */
1870 /* if (clear & TIOCM_DTR)
1871 port->MSVR &= ~MSVR_DTR; */
1872 if (SX_CRTSCTS(port->port.tty)) {
1873 if (clear & TIOCM_RTS) 1805 if (clear & TIOCM_RTS)
1874 port->MSVR &= ~MSVR_DTR; 1806 port->MSVR &= ~MSVR_DTR;
1875 } else { 1807 } else {
@@ -1886,14 +1818,17 @@ static int sx_tiocmset(struct tty_struct *tty, struct file *file,
1886} 1818}
1887 1819
1888 1820
1889static inline void sx_send_break(struct specialix_port * port, unsigned long length) 1821static int sx_send_break(struct tty_struct *tty, int length)
1890{ 1822{
1823 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
1891 struct specialix_board *bp = port_Board(port); 1824 struct specialix_board *bp = port_Board(port);
1892 unsigned long flags; 1825 unsigned long flags;
1893 1826
1894 func_enter(); 1827 func_enter();
1828 if (length == 0 || length == -1)
1829 return -EOPNOTSUPP;
1895 1830
1896 spin_lock_irqsave (&port->lock, flags); 1831 spin_lock_irqsave(&port->lock, flags);
1897 port->break_length = SPECIALIX_TPS / HZ * length; 1832 port->break_length = SPECIALIX_TPS / HZ * length;
1898 port->COR2 |= COR2_ETC; 1833 port->COR2 |= COR2_ETC;
1899 port->IER |= IER_TXRDY; 1834 port->IER |= IER_TXRDY;
@@ -1902,7 +1837,7 @@ static inline void sx_send_break(struct specialix_port * port, unsigned long len
1902 sx_out(bp, CD186x_COR2, port->COR2); 1837 sx_out(bp, CD186x_COR2, port->COR2);
1903 sx_out(bp, CD186x_IER, port->IER); 1838 sx_out(bp, CD186x_IER, port->IER);
1904 spin_unlock_irqrestore(&bp->lock, flags); 1839 spin_unlock_irqrestore(&bp->lock, flags);
1905 spin_unlock_irqrestore (&port->lock, flags); 1840 spin_unlock_irqrestore(&port->lock, flags);
1906 sx_wait_CCR(bp); 1841 sx_wait_CCR(bp);
1907 spin_lock_irqsave(&bp->lock, flags); 1842 spin_lock_irqsave(&bp->lock, flags);
1908 sx_out(bp, CD186x_CCR, CCR_CORCHG2); 1843 sx_out(bp, CD186x_CCR, CCR_CORCHG2);
@@ -1910,11 +1845,12 @@ static inline void sx_send_break(struct specialix_port * port, unsigned long len
1910 sx_wait_CCR(bp); 1845 sx_wait_CCR(bp);
1911 1846
1912 func_exit(); 1847 func_exit();
1848 return 0;
1913} 1849}
1914 1850
1915 1851
1916static inline int sx_set_serial_info(struct specialix_port * port, 1852static int sx_set_serial_info(struct specialix_port *port,
1917 struct serial_struct __user * newinfo) 1853 struct serial_struct __user *newinfo)
1918{ 1854{
1919 struct serial_struct tmp; 1855 struct serial_struct tmp;
1920 struct specialix_board *bp = port_Board(port); 1856 struct specialix_board *bp = port_Board(port);
@@ -1943,25 +1879,25 @@ static inline int sx_set_serial_info(struct specialix_port * port,
1943 return -EPERM; 1879 return -EPERM;
1944 } 1880 }
1945 port->port.flags = ((port->port.flags & ~ASYNC_USR_MASK) | 1881 port->port.flags = ((port->port.flags & ~ASYNC_USR_MASK) |
1946 (tmp.flags & ASYNC_USR_MASK)); 1882 (tmp.flags & ASYNC_USR_MASK));
1947 port->custom_divisor = tmp.custom_divisor; 1883 port->custom_divisor = tmp.custom_divisor;
1948 } else { 1884 } else {
1949 port->port.flags = ((port->port.flags & ~ASYNC_FLAGS) | 1885 port->port.flags = ((port->port.flags & ~ASYNC_FLAGS) |
1950 (tmp.flags & ASYNC_FLAGS)); 1886 (tmp.flags & ASYNC_FLAGS));
1951 port->port.close_delay = tmp.close_delay; 1887 port->port.close_delay = tmp.close_delay;
1952 port->port.closing_wait = tmp.closing_wait; 1888 port->port.closing_wait = tmp.closing_wait;
1953 port->custom_divisor = tmp.custom_divisor; 1889 port->custom_divisor = tmp.custom_divisor;
1954 } 1890 }
1955 if (change_speed) { 1891 if (change_speed)
1956 sx_change_speed(bp, port); 1892 sx_change_speed(bp, port);
1957 } 1893
1958 func_exit(); 1894 func_exit();
1959 unlock_kernel(); 1895 unlock_kernel();
1960 return 0; 1896 return 0;
1961} 1897}
1962 1898
1963 1899
1964static inline int sx_get_serial_info(struct specialix_port * port, 1900static int sx_get_serial_info(struct specialix_port *port,
1965 struct serial_struct __user *retinfo) 1901 struct serial_struct __user *retinfo)
1966{ 1902{
1967 struct serial_struct tmp; 1903 struct serial_struct tmp;
@@ -1992,11 +1928,10 @@ static inline int sx_get_serial_info(struct specialix_port * port,
1992} 1928}
1993 1929
1994 1930
1995static int sx_ioctl(struct tty_struct * tty, struct file * filp, 1931static int sx_ioctl(struct tty_struct *tty, struct file *filp,
1996 unsigned int cmd, unsigned long arg) 1932 unsigned int cmd, unsigned long arg)
1997{ 1933{
1998 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 1934 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
1999 int retval;
2000 void __user *argp = (void __user *)arg; 1935 void __user *argp = (void __user *)arg;
2001 1936
2002 func_enter(); 1937 func_enter();
@@ -2007,34 +1942,14 @@ static int sx_ioctl(struct tty_struct * tty, struct file * filp,
2007 } 1942 }
2008 1943
2009 switch (cmd) { 1944 switch (cmd) {
2010 case TCSBRK: /* SVID version: non-zero arg --> no break */ 1945 case TIOCGSERIAL:
2011 retval = tty_check_change(tty);
2012 if (retval) {
2013 func_exit();
2014 return retval;
2015 }
2016 tty_wait_until_sent(tty, 0);
2017 if (!arg)
2018 sx_send_break(port, HZ/4); /* 1/4 second */
2019 return 0;
2020 case TCSBRKP: /* support for POSIX tcsendbreak() */
2021 retval = tty_check_change(tty);
2022 if (retval) {
2023 func_exit();
2024 return retval;
2025 }
2026 tty_wait_until_sent(tty, 0);
2027 sx_send_break(port, arg ? arg*(HZ/10) : HZ/4);
2028 func_exit(); 1946 func_exit();
2029 return 0;
2030 case TIOCGSERIAL:
2031 func_exit();
2032 return sx_get_serial_info(port, argp); 1947 return sx_get_serial_info(port, argp);
2033 case TIOCSSERIAL: 1948 case TIOCSSERIAL:
2034 func_exit(); 1949 func_exit();
2035 return sx_set_serial_info(port, argp); 1950 return sx_set_serial_info(port, argp);
2036 default: 1951 default:
2037 func_exit(); 1952 func_exit();
2038 return -ENOIOCTLCMD; 1953 return -ENOIOCTLCMD;
2039 } 1954 }
2040 func_exit(); 1955 func_exit();
@@ -2042,7 +1957,7 @@ static int sx_ioctl(struct tty_struct * tty, struct file * filp,
2042} 1957}
2043 1958
2044 1959
2045static void sx_throttle(struct tty_struct * tty) 1960static void sx_throttle(struct tty_struct *tty)
2046{ 1961{
2047 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 1962 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
2048 struct specialix_board *bp; 1963 struct specialix_board *bp;
@@ -2058,15 +1973,16 @@ static void sx_throttle(struct tty_struct * tty)
2058 bp = port_Board(port); 1973 bp = port_Board(port);
2059 1974
2060 /* Use DTR instead of RTS ! */ 1975 /* Use DTR instead of RTS ! */
2061 if (SX_CRTSCTS (tty)) 1976 if (sx_crtscts(tty))
2062 port->MSVR &= ~MSVR_DTR; 1977 port->MSVR &= ~MSVR_DTR;
2063 else { 1978 else {
2064 /* Auch!!! I think the system shouldn't call this then. */ 1979 /* Auch!!! I think the system shouldn't call this then. */
2065 /* Or maybe we're supposed (allowed?) to do our side of hw 1980 /* Or maybe we're supposed (allowed?) to do our side of hw
2066 handshake anyway, even when hardware handshake is off. 1981 handshake anyway, even when hardware handshake is off.
2067 When you see this in your logs, please report.... */ 1982 When you see this in your logs, please report.... */
2068 printk (KERN_ERR "sx%d: Need to throttle, but can't (hardware hs is off)\n", 1983 printk(KERN_ERR
2069 port_No (port)); 1984 "sx%d: Need to throttle, but can't (hardware hs is off)\n",
1985 port_No(port));
2070 } 1986 }
2071 spin_lock_irqsave(&bp->lock, flags); 1987 spin_lock_irqsave(&bp->lock, flags);
2072 sx_out(bp, CD186x_CAR, port_No(port)); 1988 sx_out(bp, CD186x_CAR, port_No(port));
@@ -2086,7 +2002,7 @@ static void sx_throttle(struct tty_struct * tty)
2086} 2002}
2087 2003
2088 2004
2089static void sx_unthrottle(struct tty_struct * tty) 2005static void sx_unthrottle(struct tty_struct *tty)
2090{ 2006{
2091 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 2007 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
2092 struct specialix_board *bp; 2008 struct specialix_board *bp;
@@ -2103,9 +2019,9 @@ static void sx_unthrottle(struct tty_struct * tty)
2103 2019
2104 spin_lock_irqsave(&port->lock, flags); 2020 spin_lock_irqsave(&port->lock, flags);
2105 /* XXXX Use DTR INSTEAD???? */ 2021 /* XXXX Use DTR INSTEAD???? */
2106 if (SX_CRTSCTS(tty)) { 2022 if (sx_crtscts(tty))
2107 port->MSVR |= MSVR_DTR; 2023 port->MSVR |= MSVR_DTR;
2108 } /* Else clause: see remark in "sx_throttle"... */ 2024 /* Else clause: see remark in "sx_throttle"... */
2109 spin_lock_irqsave(&bp->lock, flags); 2025 spin_lock_irqsave(&bp->lock, flags);
2110 sx_out(bp, CD186x_CAR, port_No(port)); 2026 sx_out(bp, CD186x_CAR, port_No(port));
2111 spin_unlock_irqrestore(&bp->lock, flags); 2027 spin_unlock_irqrestore(&bp->lock, flags);
@@ -2127,7 +2043,7 @@ static void sx_unthrottle(struct tty_struct * tty)
2127} 2043}
2128 2044
2129 2045
2130static void sx_stop(struct tty_struct * tty) 2046static void sx_stop(struct tty_struct *tty)
2131{ 2047{
2132 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 2048 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
2133 struct specialix_board *bp; 2049 struct specialix_board *bp;
@@ -2154,7 +2070,7 @@ static void sx_stop(struct tty_struct * tty)
2154} 2070}
2155 2071
2156 2072
2157static void sx_start(struct tty_struct * tty) 2073static void sx_start(struct tty_struct *tty)
2158{ 2074{
2159 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 2075 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
2160 struct specialix_board *bp; 2076 struct specialix_board *bp;
@@ -2182,7 +2098,7 @@ static void sx_start(struct tty_struct * tty)
2182 func_exit(); 2098 func_exit();
2183} 2099}
2184 2100
2185static void sx_hangup(struct tty_struct * tty) 2101static void sx_hangup(struct tty_struct *tty)
2186{ 2102{
2187 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 2103 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
2188 struct specialix_board *bp; 2104 struct specialix_board *bp;
@@ -2201,8 +2117,9 @@ static void sx_hangup(struct tty_struct * tty)
2201 spin_lock_irqsave(&port->lock, flags); 2117 spin_lock_irqsave(&port->lock, flags);
2202 bp->count -= port->port.count; 2118 bp->count -= port->port.count;
2203 if (bp->count < 0) { 2119 if (bp->count < 0) {
2204 printk(KERN_ERR "sx%d: sx_hangup: bad board count: %d port: %d\n", 2120 printk(KERN_ERR
2205 board_No(bp), bp->count, tty->index); 2121 "sx%d: sx_hangup: bad board count: %d port: %d\n",
2122 board_No(bp), bp->count, tty->index);
2206 bp->count = 0; 2123 bp->count = 0;
2207 } 2124 }
2208 port->port.count = 0; 2125 port->port.count = 0;
@@ -2215,11 +2132,12 @@ static void sx_hangup(struct tty_struct * tty)
2215} 2132}
2216 2133
2217 2134
2218static void sx_set_termios(struct tty_struct * tty, struct ktermios * old_termios) 2135static void sx_set_termios(struct tty_struct *tty,
2136 struct ktermios *old_termios)
2219{ 2137{
2220 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 2138 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
2221 unsigned long flags; 2139 unsigned long flags;
2222 struct specialix_board * bp; 2140 struct specialix_board *bp;
2223 2141
2224 if (sx_paranoia_check(port, tty->name, "sx_set_termios")) 2142 if (sx_paranoia_check(port, tty->name, "sx_set_termios"))
2225 return; 2143 return;
@@ -2254,6 +2172,7 @@ static const struct tty_operations sx_ops = {
2254 .hangup = sx_hangup, 2172 .hangup = sx_hangup,
2255 .tiocmget = sx_tiocmget, 2173 .tiocmget = sx_tiocmget,
2256 .tiocmset = sx_tiocmset, 2174 .tiocmset = sx_tiocmset,
2175 .break_ctl = sx_send_break,
2257}; 2176};
2258 2177
2259static int sx_init_drivers(void) 2178static int sx_init_drivers(void)
@@ -2280,13 +2199,16 @@ static int sx_init_drivers(void)
2280 B9600 | CS8 | CREAD | HUPCL | CLOCAL; 2199 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2281 specialix_driver->init_termios.c_ispeed = 9600; 2200 specialix_driver->init_termios.c_ispeed = 9600;
2282 specialix_driver->init_termios.c_ospeed = 9600; 2201 specialix_driver->init_termios.c_ospeed = 9600;
2283 specialix_driver->flags = TTY_DRIVER_REAL_RAW; 2202 specialix_driver->flags = TTY_DRIVER_REAL_RAW |
2203 TTY_DRIVER_HARDWARE_BREAK;
2284 tty_set_operations(specialix_driver, &sx_ops); 2204 tty_set_operations(specialix_driver, &sx_ops);
2285 2205
2286 if ((error = tty_register_driver(specialix_driver))) { 2206 error = tty_register_driver(specialix_driver);
2207 if (error) {
2287 put_tty_driver(specialix_driver); 2208 put_tty_driver(specialix_driver);
2288 printk(KERN_ERR "sx: Couldn't register specialix IO8+ driver, error = %d\n", 2209 printk(KERN_ERR
2289 error); 2210 "sx: Couldn't register specialix IO8+ driver, error = %d\n",
2211 error);
2290 func_exit(); 2212 func_exit();
2291 return 1; 2213 return 1;
2292 } 2214 }
@@ -2322,11 +2244,11 @@ static int __init specialix_init(void)
2322 2244
2323 printk(KERN_INFO "sx: Specialix IO8+ driver v" VERSION ", (c) R.E.Wolff 1997/1998.\n"); 2245 printk(KERN_INFO "sx: Specialix IO8+ driver v" VERSION ", (c) R.E.Wolff 1997/1998.\n");
2324 printk(KERN_INFO "sx: derived from work (c) D.Gorodchanin 1994-1996.\n"); 2246 printk(KERN_INFO "sx: derived from work (c) D.Gorodchanin 1994-1996.\n");
2325#ifdef CONFIG_SPECIALIX_RTSCTS 2247 if (sx_rtscts)
2326 printk (KERN_INFO "sx: DTR/RTS pin is always RTS.\n"); 2248 printk(KERN_INFO
2327#else 2249 "sx: DTR/RTS pin is RTS when CRTSCTS is on.\n");
2328 printk (KERN_INFO "sx: DTR/RTS pin is RTS when CRTSCTS is on.\n"); 2250 else
2329#endif 2251 printk(KERN_INFO "sx: DTR/RTS pin is always RTS.\n");
2330 2252
2331 for (i = 0; i < SX_NBOARD; i++) 2253 for (i = 0; i < SX_NBOARD; i++)
2332 spin_lock_init(&sx_board[i].lock); 2254 spin_lock_init(&sx_board[i].lock);
@@ -2344,27 +2266,27 @@ static int __init specialix_init(void)
2344 { 2266 {
2345 struct pci_dev *pdev = NULL; 2267 struct pci_dev *pdev = NULL;
2346 2268
2347 i=0; 2269 i = 0;
2348 while (i < SX_NBOARD) { 2270 while (i < SX_NBOARD) {
2349 if (sx_board[i].flags & SX_BOARD_PRESENT) { 2271 if (sx_board[i].flags & SX_BOARD_PRESENT) {
2350 i++; 2272 i++;
2351 continue; 2273 continue;
2352 } 2274 }
2353 pdev = pci_get_device (PCI_VENDOR_ID_SPECIALIX, 2275 pdev = pci_get_device(PCI_VENDOR_ID_SPECIALIX,
2354 PCI_DEVICE_ID_SPECIALIX_IO8, 2276 PCI_DEVICE_ID_SPECIALIX_IO8, pdev);
2355 pdev); 2277 if (!pdev)
2356 if (!pdev) break; 2278 break;
2357 2279
2358 if (pci_enable_device(pdev)) 2280 if (pci_enable_device(pdev))
2359 continue; 2281 continue;
2360 2282
2361 sx_board[i].irq = pdev->irq; 2283 sx_board[i].irq = pdev->irq;
2362 2284
2363 sx_board[i].base = pci_resource_start (pdev, 2); 2285 sx_board[i].base = pci_resource_start(pdev, 2);
2364 2286
2365 sx_board[i].flags |= SX_BOARD_IS_PCI; 2287 sx_board[i].flags |= SX_BOARD_IS_PCI;
2366 if (!sx_probe(&sx_board[i])) 2288 if (!sx_probe(&sx_board[i]))
2367 found ++; 2289 found++;
2368 } 2290 }
2369 /* May exit pci_get sequence early with lots of boards */ 2291 /* May exit pci_get sequence early with lots of boards */
2370 if (pdev != NULL) 2292 if (pdev != NULL)
@@ -2384,16 +2306,13 @@ static int __init specialix_init(void)
2384} 2306}
2385 2307
2386static int iobase[SX_NBOARD] = {0,}; 2308static int iobase[SX_NBOARD] = {0,};
2387 2309static int irq[SX_NBOARD] = {0,};
2388static int irq [SX_NBOARD] = {0,};
2389 2310
2390module_param_array(iobase, int, NULL, 0); 2311module_param_array(iobase, int, NULL, 0);
2391module_param_array(irq, int, NULL, 0); 2312module_param_array(irq, int, NULL, 0);
2392module_param(sx_debug, int, 0); 2313module_param(sx_debug, int, 0);
2314module_param(sx_rtscts, int, 0);
2393module_param(sx_rxfifo, int, 0); 2315module_param(sx_rxfifo, int, 0);
2394#ifdef SPECIALIX_TIMER
2395module_param(sx_poll, int, 0);
2396#endif
2397 2316
2398/* 2317/*
2399 * You can setup up to 4 boards. 2318 * You can setup up to 4 boards.
@@ -2411,10 +2330,10 @@ static int __init specialix_init_module(void)
2411 func_enter(); 2330 func_enter();
2412 2331
2413 if (iobase[0] || iobase[1] || iobase[2] || iobase[3]) { 2332 if (iobase[0] || iobase[1] || iobase[2] || iobase[3]) {
2414 for(i = 0; i < SX_NBOARD; i++) { 2333 for (i = 0; i < SX_NBOARD; i++) {
2415 sx_board[i].base = iobase[i]; 2334 sx_board[i].base = iobase[i];
2416 sx_board[i].irq = irq[i]; 2335 sx_board[i].irq = irq[i];
2417 sx_board[i].count= 0; 2336 sx_board[i].count = 0;
2418 } 2337 }
2419 } 2338 }
2420 2339
@@ -2433,10 +2352,6 @@ static void __exit specialix_exit_module(void)
2433 for (i = 0; i < SX_NBOARD; i++) 2352 for (i = 0; i < SX_NBOARD; i++)
2434 if (sx_board[i].flags & SX_BOARD_PRESENT) 2353 if (sx_board[i].flags & SX_BOARD_PRESENT)
2435 sx_release_io_range(&sx_board[i]); 2354 sx_release_io_range(&sx_board[i]);
2436#ifdef SPECIALIX_TIMER
2437 del_timer_sync(&missed_irq_timer);
2438#endif
2439
2440 func_exit(); 2355 func_exit();
2441} 2356}
2442 2357
diff --git a/drivers/char/stallion.c b/drivers/char/stallion.c
index 45aeeeab9f4a..b976248e1072 100644
--- a/drivers/char/stallion.c
+++ b/drivers/char/stallion.c
@@ -1025,7 +1025,7 @@ static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count
1025 1025
1026/*****************************************************************************/ 1026/*****************************************************************************/
1027 1027
1028static void stl_putchar(struct tty_struct *tty, unsigned char ch) 1028static int stl_putchar(struct tty_struct *tty, unsigned char ch)
1029{ 1029{
1030 struct stlport *portp; 1030 struct stlport *portp;
1031 unsigned int len; 1031 unsigned int len;
@@ -1034,12 +1034,12 @@ static void stl_putchar(struct tty_struct *tty, unsigned char ch)
1034 pr_debug("stl_putchar(tty=%p,ch=%x)\n", tty, ch); 1034 pr_debug("stl_putchar(tty=%p,ch=%x)\n", tty, ch);
1035 1035
1036 if (tty == NULL) 1036 if (tty == NULL)
1037 return; 1037 return -EINVAL;
1038 portp = tty->driver_data; 1038 portp = tty->driver_data;
1039 if (portp == NULL) 1039 if (portp == NULL)
1040 return; 1040 return -EINVAL;
1041 if (portp->tx.buf == NULL) 1041 if (portp->tx.buf == NULL)
1042 return; 1042 return -EINVAL;
1043 1043
1044 head = portp->tx.head; 1044 head = portp->tx.head;
1045 tail = portp->tx.tail; 1045 tail = portp->tx.tail;
@@ -1053,6 +1053,7 @@ static void stl_putchar(struct tty_struct *tty, unsigned char ch)
1053 head = portp->tx.buf; 1053 head = portp->tx.buf;
1054 } 1054 }
1055 portp->tx.head = head; 1055 portp->tx.head = head;
1056 return 0;
1056} 1057}
1057 1058
1058/*****************************************************************************/ 1059/*****************************************************************************/
@@ -1460,19 +1461,20 @@ static void stl_hangup(struct tty_struct *tty)
1460 1461
1461/*****************************************************************************/ 1462/*****************************************************************************/
1462 1463
1463static void stl_breakctl(struct tty_struct *tty, int state) 1464static int stl_breakctl(struct tty_struct *tty, int state)
1464{ 1465{
1465 struct stlport *portp; 1466 struct stlport *portp;
1466 1467
1467 pr_debug("stl_breakctl(tty=%p,state=%d)\n", tty, state); 1468 pr_debug("stl_breakctl(tty=%p,state=%d)\n", tty, state);
1468 1469
1469 if (tty == NULL) 1470 if (tty == NULL)
1470 return; 1471 return -EINVAL;
1471 portp = tty->driver_data; 1472 portp = tty->driver_data;
1472 if (portp == NULL) 1473 if (portp == NULL)
1473 return; 1474 return -EINVAL;
1474 1475
1475 stl_sendbreak(portp, ((state == -1) ? 1 : 2)); 1476 stl_sendbreak(portp, ((state == -1) ? 1 : 2));
1477 return 0;
1476} 1478}
1477 1479
1478/*****************************************************************************/ 1480/*****************************************************************************/
diff --git a/drivers/char/sx.c b/drivers/char/sx.c
index d5cffcd6a572..2162439bbe48 100644
--- a/drivers/char/sx.c
+++ b/drivers/char/sx.c
@@ -1840,7 +1840,7 @@ static int sx_fw_ioctl(struct inode *inode, struct file *filp,
1840 return rc; 1840 return rc;
1841} 1841}
1842 1842
1843static void sx_break(struct tty_struct *tty, int flag) 1843static int sx_break(struct tty_struct *tty, int flag)
1844{ 1844{
1845 struct sx_port *port = tty->driver_data; 1845 struct sx_port *port = tty->driver_data;
1846 int rv; 1846 int rv;
@@ -1857,6 +1857,7 @@ static void sx_break(struct tty_struct *tty, int flag)
1857 read_sx_byte(port->board, CHAN_OFFSET(port, hi_hstat))); 1857 read_sx_byte(port->board, CHAN_OFFSET(port, hi_hstat)));
1858 unlock_kernel(); 1858 unlock_kernel();
1859 func_exit(); 1859 func_exit();
1860 return 0;
1860} 1861}
1861 1862
1862static int sx_tiocmget(struct tty_struct *tty, struct file *file) 1863static int sx_tiocmget(struct tty_struct *tty, struct file *file)
diff --git a/drivers/char/synclink.c b/drivers/char/synclink.c
index 527d220aa4aa..ef6706f09061 100644
--- a/drivers/char/synclink.c
+++ b/drivers/char/synclink.c
@@ -2897,9 +2897,9 @@ static int tiocmset(struct tty_struct *tty, struct file *file,
2897 * 2897 *
2898 * Arguments: tty pointer to tty instance data 2898 * Arguments: tty pointer to tty instance data
2899 * break_state -1=set break condition, 0=clear 2899 * break_state -1=set break condition, 0=clear
2900 * Return Value: None 2900 * Return Value: error code
2901 */ 2901 */
2902static void mgsl_break(struct tty_struct *tty, int break_state) 2902static int mgsl_break(struct tty_struct *tty, int break_state)
2903{ 2903{
2904 struct mgsl_struct * info = (struct mgsl_struct *)tty->driver_data; 2904 struct mgsl_struct * info = (struct mgsl_struct *)tty->driver_data;
2905 unsigned long flags; 2905 unsigned long flags;
@@ -2909,7 +2909,7 @@ static void mgsl_break(struct tty_struct *tty, int break_state)
2909 __FILE__,__LINE__, info->device_name, break_state); 2909 __FILE__,__LINE__, info->device_name, break_state);
2910 2910
2911 if (mgsl_paranoia_check(info, tty->name, "mgsl_break")) 2911 if (mgsl_paranoia_check(info, tty->name, "mgsl_break"))
2912 return; 2912 return -EINVAL;
2913 2913
2914 spin_lock_irqsave(&info->irq_spinlock,flags); 2914 spin_lock_irqsave(&info->irq_spinlock,flags);
2915 if (break_state == -1) 2915 if (break_state == -1)
@@ -2917,6 +2917,7 @@ static void mgsl_break(struct tty_struct *tty, int break_state)
2917 else 2917 else
2918 usc_OutReg(info,IOCR,(u16)(usc_InReg(info,IOCR) & ~BIT7)); 2918 usc_OutReg(info,IOCR,(u16)(usc_InReg(info,IOCR) & ~BIT7));
2919 spin_unlock_irqrestore(&info->irq_spinlock,flags); 2919 spin_unlock_irqrestore(&info->irq_spinlock,flags);
2920 return 0;
2920 2921
2921} /* end of mgsl_break() */ 2922} /* end of mgsl_break() */
2922 2923
diff --git a/drivers/char/synclink_gt.c b/drivers/char/synclink_gt.c
index 2c3e43bb2cc9..3e9058993e41 100644
--- a/drivers/char/synclink_gt.c
+++ b/drivers/char/synclink_gt.c
@@ -165,7 +165,7 @@ static int read_proc(char *page, char **start, off_t off, int count,int *eof, v
165static int chars_in_buffer(struct tty_struct *tty); 165static int chars_in_buffer(struct tty_struct *tty);
166static void throttle(struct tty_struct * tty); 166static void throttle(struct tty_struct * tty);
167static void unthrottle(struct tty_struct * tty); 167static void unthrottle(struct tty_struct * tty);
168static void set_break(struct tty_struct *tty, int break_state); 168static int set_break(struct tty_struct *tty, int break_state);
169 169
170/* 170/*
171 * generic HDLC support and callbacks 171 * generic HDLC support and callbacks
@@ -214,6 +214,7 @@ struct slgt_desc
214 char *buf; /* virtual address of data buffer */ 214 char *buf; /* virtual address of data buffer */
215 unsigned int pdesc; /* physical address of this descriptor */ 215 unsigned int pdesc; /* physical address of this descriptor */
216 dma_addr_t buf_dma_addr; 216 dma_addr_t buf_dma_addr;
217 unsigned short buf_count;
217}; 218};
218 219
219#define set_desc_buffer(a,b) (a).pbuf = cpu_to_le32((unsigned int)(b)) 220#define set_desc_buffer(a,b) (a).pbuf = cpu_to_le32((unsigned int)(b))
@@ -302,7 +303,7 @@ struct slgt_info {
302 u32 idle_mode; 303 u32 idle_mode;
303 u32 max_frame_size; /* as set by device config */ 304 u32 max_frame_size; /* as set by device config */
304 305
305 unsigned int raw_rx_size; 306 unsigned int rbuf_fill_level;
306 unsigned int if_mode; 307 unsigned int if_mode;
307 308
308 /* device status */ 309 /* device status */
@@ -466,6 +467,7 @@ static void tx_start(struct slgt_info *info);
466static void tx_stop(struct slgt_info *info); 467static void tx_stop(struct slgt_info *info);
467static void tx_set_idle(struct slgt_info *info); 468static void tx_set_idle(struct slgt_info *info);
468static unsigned int free_tbuf_count(struct slgt_info *info); 469static unsigned int free_tbuf_count(struct slgt_info *info);
470static unsigned int tbuf_bytes(struct slgt_info *info);
469static void reset_tbufs(struct slgt_info *info); 471static void reset_tbufs(struct slgt_info *info);
470static void tdma_reset(struct slgt_info *info); 472static void tdma_reset(struct slgt_info *info);
471static void tdma_start(struct slgt_info *info); 473static void tdma_start(struct slgt_info *info);
@@ -513,7 +515,7 @@ static int wait_mgsl_event(struct slgt_info *info, int __user *mask_ptr);
513static int tiocmget(struct tty_struct *tty, struct file *file); 515static int tiocmget(struct tty_struct *tty, struct file *file);
514static int tiocmset(struct tty_struct *tty, struct file *file, 516static int tiocmset(struct tty_struct *tty, struct file *file,
515 unsigned int set, unsigned int clear); 517 unsigned int set, unsigned int clear);
516static void set_break(struct tty_struct *tty, int break_state); 518static int set_break(struct tty_struct *tty, int break_state);
517static int get_interface(struct slgt_info *info, int __user *if_mode); 519static int get_interface(struct slgt_info *info, int __user *if_mode);
518static int set_interface(struct slgt_info *info, int if_mode); 520static int set_interface(struct slgt_info *info, int if_mode);
519static int set_gpio(struct slgt_info *info, struct gpio_desc __user *gpio); 521static int set_gpio(struct slgt_info *info, struct gpio_desc __user *gpio);
@@ -849,6 +851,7 @@ static int write(struct tty_struct *tty,
849 int ret = 0; 851 int ret = 0;
850 struct slgt_info *info = tty->driver_data; 852 struct slgt_info *info = tty->driver_data;
851 unsigned long flags; 853 unsigned long flags;
854 unsigned int bufs_needed;
852 855
853 if (sanity_check(info, tty->name, "write")) 856 if (sanity_check(info, tty->name, "write"))
854 goto cleanup; 857 goto cleanup;
@@ -865,25 +868,16 @@ static int write(struct tty_struct *tty,
865 if (!count) 868 if (!count)
866 goto cleanup; 869 goto cleanup;
867 870
868 if (info->params.mode == MGSL_MODE_RAW || 871 if (!info->tx_active && info->tx_count) {
869 info->params.mode == MGSL_MODE_MONOSYNC || 872 /* send accumulated data from send_char() */
870 info->params.mode == MGSL_MODE_BISYNC) { 873 tx_load(info, info->tx_buf, info->tx_count);
871 unsigned int bufs_needed = (count/DMABUFSIZE); 874 goto start;
872 unsigned int bufs_free = free_tbuf_count(info);
873 if (count % DMABUFSIZE)
874 ++bufs_needed;
875 if (bufs_needed > bufs_free)
876 goto cleanup;
877 } else {
878 if (info->tx_active)
879 goto cleanup;
880 if (info->tx_count) {
881 /* send accumulated data from send_char() calls */
882 /* as frame and wait before accepting more data. */
883 tx_load(info, info->tx_buf, info->tx_count);
884 goto start;
885 }
886 } 875 }
876 bufs_needed = (count/DMABUFSIZE);
877 if (count % DMABUFSIZE)
878 ++bufs_needed;
879 if (bufs_needed > free_tbuf_count(info))
880 goto cleanup;
887 881
888 ret = info->tx_count = count; 882 ret = info->tx_count = count;
889 tx_load(info, buf, count); 883 tx_load(info, buf, count);
@@ -1396,10 +1390,12 @@ done:
1396static int chars_in_buffer(struct tty_struct *tty) 1390static int chars_in_buffer(struct tty_struct *tty)
1397{ 1391{
1398 struct slgt_info *info = tty->driver_data; 1392 struct slgt_info *info = tty->driver_data;
1393 int count;
1399 if (sanity_check(info, tty->name, "chars_in_buffer")) 1394 if (sanity_check(info, tty->name, "chars_in_buffer"))
1400 return 0; 1395 return 0;
1401 DBGINFO(("%s chars_in_buffer()=%d\n", info->device_name, info->tx_count)); 1396 count = tbuf_bytes(info);
1402 return info->tx_count; 1397 DBGINFO(("%s chars_in_buffer()=%d\n", info->device_name, count));
1398 return count;
1403} 1399}
1404 1400
1405/* 1401/*
@@ -1452,14 +1448,14 @@ static void unthrottle(struct tty_struct * tty)
1452 * set or clear transmit break condition 1448 * set or clear transmit break condition
1453 * break_state -1=set break condition, 0=clear 1449 * break_state -1=set break condition, 0=clear
1454 */ 1450 */
1455static void set_break(struct tty_struct *tty, int break_state) 1451static int set_break(struct tty_struct *tty, int break_state)
1456{ 1452{
1457 struct slgt_info *info = tty->driver_data; 1453 struct slgt_info *info = tty->driver_data;
1458 unsigned short value; 1454 unsigned short value;
1459 unsigned long flags; 1455 unsigned long flags;
1460 1456
1461 if (sanity_check(info, tty->name, "set_break")) 1457 if (sanity_check(info, tty->name, "set_break"))
1462 return; 1458 return -EINVAL;
1463 DBGINFO(("%s set_break(%d)\n", info->device_name, break_state)); 1459 DBGINFO(("%s set_break(%d)\n", info->device_name, break_state));
1464 1460
1465 spin_lock_irqsave(&info->lock,flags); 1461 spin_lock_irqsave(&info->lock,flags);
@@ -1470,6 +1466,7 @@ static void set_break(struct tty_struct *tty, int break_state)
1470 value &= ~BIT6; 1466 value &= ~BIT6;
1471 wr_reg16(info, TCR, value); 1467 wr_reg16(info, TCR, value);
1472 spin_unlock_irqrestore(&info->lock,flags); 1468 spin_unlock_irqrestore(&info->lock,flags);
1469 return 0;
1473} 1470}
1474 1471
1475#if SYNCLINK_GENERIC_HDLC 1472#if SYNCLINK_GENERIC_HDLC
@@ -2679,8 +2676,31 @@ static int tx_abort(struct slgt_info *info)
2679static int rx_enable(struct slgt_info *info, int enable) 2676static int rx_enable(struct slgt_info *info, int enable)
2680{ 2677{
2681 unsigned long flags; 2678 unsigned long flags;
2682 DBGINFO(("%s rx_enable(%d)\n", info->device_name, enable)); 2679 unsigned int rbuf_fill_level;
2680 DBGINFO(("%s rx_enable(%08x)\n", info->device_name, enable));
2683 spin_lock_irqsave(&info->lock,flags); 2681 spin_lock_irqsave(&info->lock,flags);
2682 /*
2683 * enable[31..16] = receive DMA buffer fill level
2684 * 0 = noop (leave fill level unchanged)
2685 * fill level must be multiple of 4 and <= buffer size
2686 */
2687 rbuf_fill_level = ((unsigned int)enable) >> 16;
2688 if (rbuf_fill_level) {
2689 if ((rbuf_fill_level > DMABUFSIZE) || (rbuf_fill_level % 4)) {
2690 spin_unlock_irqrestore(&info->lock, flags);
2691 return -EINVAL;
2692 }
2693 info->rbuf_fill_level = rbuf_fill_level;
2694 rx_stop(info); /* restart receiver to use new fill level */
2695 }
2696
2697 /*
2698 * enable[1..0] = receiver enable command
2699 * 0 = disable
2700 * 1 = enable
2701 * 2 = enable or force hunt mode if already enabled
2702 */
2703 enable &= 3;
2684 if (enable) { 2704 if (enable) {
2685 if (!info->rx_enabled) 2705 if (!info->rx_enabled)
2686 rx_start(info); 2706 rx_start(info);
@@ -3447,7 +3467,7 @@ static struct slgt_info *alloc_dev(int adapter_num, int port_num, struct pci_dev
3447 info->magic = MGSL_MAGIC; 3467 info->magic = MGSL_MAGIC;
3448 INIT_WORK(&info->task, bh_handler); 3468 INIT_WORK(&info->task, bh_handler);
3449 info->max_frame_size = 4096; 3469 info->max_frame_size = 4096;
3450 info->raw_rx_size = DMABUFSIZE; 3470 info->rbuf_fill_level = DMABUFSIZE;
3451 info->port.close_delay = 5*HZ/10; 3471 info->port.close_delay = 5*HZ/10;
3452 info->port.closing_wait = 30*HZ; 3472 info->port.closing_wait = 30*HZ;
3453 init_waitqueue_head(&info->status_event_wait_q); 3473 init_waitqueue_head(&info->status_event_wait_q);
@@ -3934,15 +3954,7 @@ static void tdma_start(struct slgt_info *info)
3934 3954
3935 /* set 1st descriptor address */ 3955 /* set 1st descriptor address */
3936 wr_reg32(info, TDDAR, info->tbufs[info->tbuf_start].pdesc); 3956 wr_reg32(info, TDDAR, info->tbufs[info->tbuf_start].pdesc);
3937 switch(info->params.mode) { 3957 wr_reg32(info, TDCSR, BIT2 + BIT0); /* IRQ + DMA enable */
3938 case MGSL_MODE_RAW:
3939 case MGSL_MODE_MONOSYNC:
3940 case MGSL_MODE_BISYNC:
3941 wr_reg32(info, TDCSR, BIT2 + BIT0); /* IRQ + DMA enable */
3942 break;
3943 default:
3944 wr_reg32(info, TDCSR, BIT0); /* DMA enable */
3945 }
3946} 3958}
3947 3959
3948static void tx_stop(struct slgt_info *info) 3960static void tx_stop(struct slgt_info *info)
@@ -4145,7 +4157,7 @@ static void sync_mode(struct slgt_info *info)
4145 * 01 enable 4157 * 01 enable
4146 * 00 auto-CTS enable 4158 * 00 auto-CTS enable
4147 */ 4159 */
4148 val = 0; 4160 val = BIT2;
4149 4161
4150 switch(info->params.mode) { 4162 switch(info->params.mode) {
4151 case MGSL_MODE_MONOSYNC: val |= BIT14 + BIT13; break; 4163 case MGSL_MODE_MONOSYNC: val |= BIT14 + BIT13; break;
@@ -4418,6 +4430,8 @@ static void msc_set_vcr(struct slgt_info *info)
4418 break; 4430 break;
4419 } 4431 }
4420 4432
4433 if (info->if_mode & MGSL_INTERFACE_MSB_FIRST)
4434 val |= BIT4;
4421 if (info->signals & SerialSignal_DTR) 4435 if (info->signals & SerialSignal_DTR)
4422 val |= BIT3; 4436 val |= BIT3;
4423 if (info->signals & SerialSignal_RTS) 4437 if (info->signals & SerialSignal_RTS)
@@ -4456,16 +4470,7 @@ static void free_rbufs(struct slgt_info *info, unsigned int i, unsigned int last
4456 while(!done) { 4470 while(!done) {
4457 /* reset current buffer for reuse */ 4471 /* reset current buffer for reuse */
4458 info->rbufs[i].status = 0; 4472 info->rbufs[i].status = 0;
4459 switch(info->params.mode) { 4473 set_desc_count(info->rbufs[i], info->rbuf_fill_level);
4460 case MGSL_MODE_RAW:
4461 case MGSL_MODE_MONOSYNC:
4462 case MGSL_MODE_BISYNC:
4463 set_desc_count(info->rbufs[i], info->raw_rx_size);
4464 break;
4465 default:
4466 set_desc_count(info->rbufs[i], DMABUFSIZE);
4467 }
4468
4469 if (i == last) 4474 if (i == last)
4470 done = 1; 4475 done = 1;
4471 if (++i == info->rbuf_count) 4476 if (++i == info->rbuf_count)
@@ -4572,7 +4577,7 @@ check_again:
4572 4577
4573 DBGBH(("%s rx frame status=%04X size=%d\n", 4578 DBGBH(("%s rx frame status=%04X size=%d\n",
4574 info->device_name, status, framesize)); 4579 info->device_name, status, framesize));
4575 DBGDATA(info, info->rbufs[start].buf, min_t(int, framesize, DMABUFSIZE), "rx"); 4580 DBGDATA(info, info->rbufs[start].buf, min_t(int, framesize, info->rbuf_fill_level), "rx");
4576 4581
4577 if (framesize) { 4582 if (framesize) {
4578 if (!(info->params.crc_type & HDLC_CRC_RETURN_EX)) { 4583 if (!(info->params.crc_type & HDLC_CRC_RETURN_EX)) {
@@ -4592,7 +4597,7 @@ check_again:
4592 info->icount.rxok++; 4597 info->icount.rxok++;
4593 4598
4594 while(copy_count) { 4599 while(copy_count) {
4595 int partial_count = min(copy_count, DMABUFSIZE); 4600 int partial_count = min_t(int, copy_count, info->rbuf_fill_level);
4596 memcpy(p, info->rbufs[i].buf, partial_count); 4601 memcpy(p, info->rbufs[i].buf, partial_count);
4597 p += partial_count; 4602 p += partial_count;
4598 copy_count -= partial_count; 4603 copy_count -= partial_count;
@@ -4684,6 +4689,56 @@ static unsigned int free_tbuf_count(struct slgt_info *info)
4684} 4689}
4685 4690
4686/* 4691/*
4692 * return number of bytes in unsent transmit DMA buffers
4693 * and the serial controller tx FIFO
4694 */
4695static unsigned int tbuf_bytes(struct slgt_info *info)
4696{
4697 unsigned int total_count = 0;
4698 unsigned int i = info->tbuf_current;
4699 unsigned int reg_value;
4700 unsigned int count;
4701 unsigned int active_buf_count = 0;
4702
4703 /*
4704 * Add descriptor counts for all tx DMA buffers.
4705 * If count is zero (cleared by DMA controller after read),
4706 * the buffer is complete or is actively being read from.
4707 *
4708 * Record buf_count of last buffer with zero count starting
4709 * from current ring position. buf_count is mirror
4710 * copy of count and is not cleared by serial controller.
4711 * If DMA controller is active, that buffer is actively
4712 * being read so add to total.
4713 */
4714 do {
4715 count = desc_count(info->tbufs[i]);
4716 if (count)
4717 total_count += count;
4718 else if (!total_count)
4719 active_buf_count = info->tbufs[i].buf_count;
4720 if (++i == info->tbuf_count)
4721 i = 0;
4722 } while (i != info->tbuf_current);
4723
4724 /* read tx DMA status register */
4725 reg_value = rd_reg32(info, TDCSR);
4726
4727 /* if tx DMA active, last zero count buffer is in use */
4728 if (reg_value & BIT0)
4729 total_count += active_buf_count;
4730
4731 /* add tx FIFO count = reg_value[15..8] */
4732 total_count += (reg_value >> 8) & 0xff;
4733
4734 /* if transmitter active add one byte for shift register */
4735 if (info->tx_active)
4736 total_count++;
4737
4738 return total_count;
4739}
4740
4741/*
4687 * load transmit DMA buffer(s) with data 4742 * load transmit DMA buffer(s) with data
4688 */ 4743 */
4689static void tx_load(struct slgt_info *info, const char *buf, unsigned int size) 4744static void tx_load(struct slgt_info *info, const char *buf, unsigned int size)
@@ -4721,6 +4776,7 @@ static void tx_load(struct slgt_info *info, const char *buf, unsigned int size)
4721 set_desc_eof(*d, 0); 4776 set_desc_eof(*d, 0);
4722 4777
4723 set_desc_count(*d, count); 4778 set_desc_count(*d, count);
4779 d->buf_count = count;
4724 } 4780 }
4725 4781
4726 info->tbuf_current = i; 4782 info->tbuf_current = i;
diff --git a/drivers/char/synclinkmp.c b/drivers/char/synclinkmp.c
index 5768c4136342..c0490cbd0db2 100644
--- a/drivers/char/synclinkmp.c
+++ b/drivers/char/synclinkmp.c
@@ -527,7 +527,7 @@ static int read_proc(char *page, char **start, off_t off, int count,int *eof, v
527static int chars_in_buffer(struct tty_struct *tty); 527static int chars_in_buffer(struct tty_struct *tty);
528static void throttle(struct tty_struct * tty); 528static void throttle(struct tty_struct * tty);
529static void unthrottle(struct tty_struct * tty); 529static void unthrottle(struct tty_struct * tty);
530static void set_break(struct tty_struct *tty, int break_state); 530static int set_break(struct tty_struct *tty, int break_state);
531 531
532#if SYNCLINK_GENERIC_HDLC 532#if SYNCLINK_GENERIC_HDLC
533#define dev_to_port(D) (dev_to_hdlc(D)->priv) 533#define dev_to_port(D) (dev_to_hdlc(D)->priv)
@@ -552,7 +552,7 @@ static int wait_mgsl_event(SLMP_INFO *info, int __user *mask_ptr);
552static int tiocmget(struct tty_struct *tty, struct file *file); 552static int tiocmget(struct tty_struct *tty, struct file *file);
553static int tiocmset(struct tty_struct *tty, struct file *file, 553static int tiocmset(struct tty_struct *tty, struct file *file,
554 unsigned int set, unsigned int clear); 554 unsigned int set, unsigned int clear);
555static void set_break(struct tty_struct *tty, int break_state); 555static int set_break(struct tty_struct *tty, int break_state);
556 556
557static void add_device(SLMP_INFO *info); 557static void add_device(SLMP_INFO *info);
558static void device_init(int adapter_num, struct pci_dev *pdev); 558static void device_init(int adapter_num, struct pci_dev *pdev);
@@ -1587,7 +1587,7 @@ static void unthrottle(struct tty_struct * tty)
1587/* set or clear transmit break condition 1587/* set or clear transmit break condition
1588 * break_state -1=set break condition, 0=clear 1588 * break_state -1=set break condition, 0=clear
1589 */ 1589 */
1590static void set_break(struct tty_struct *tty, int break_state) 1590static int set_break(struct tty_struct *tty, int break_state)
1591{ 1591{
1592 unsigned char RegValue; 1592 unsigned char RegValue;
1593 SLMP_INFO * info = (SLMP_INFO *)tty->driver_data; 1593 SLMP_INFO * info = (SLMP_INFO *)tty->driver_data;
@@ -1598,7 +1598,7 @@ static void set_break(struct tty_struct *tty, int break_state)
1598 __FILE__,__LINE__, info->device_name, break_state); 1598 __FILE__,__LINE__, info->device_name, break_state);
1599 1599
1600 if (sanity_check(info, tty->name, "set_break")) 1600 if (sanity_check(info, tty->name, "set_break"))
1601 return; 1601 return -EINVAL;
1602 1602
1603 spin_lock_irqsave(&info->lock,flags); 1603 spin_lock_irqsave(&info->lock,flags);
1604 RegValue = read_reg(info, CTL); 1604 RegValue = read_reg(info, CTL);
@@ -1608,6 +1608,7 @@ static void set_break(struct tty_struct *tty, int break_state)
1608 RegValue &= ~BIT3; 1608 RegValue &= ~BIT3;
1609 write_reg(info, CTL, RegValue); 1609 write_reg(info, CTL, RegValue);
1610 spin_unlock_irqrestore(&info->lock,flags); 1610 spin_unlock_irqrestore(&info->lock,flags);
1611 return 0;
1611} 1612}
1612 1613
1613#if SYNCLINK_GENERIC_HDLC 1614#if SYNCLINK_GENERIC_HDLC
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index dc9202d2dd63..15e597d03002 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -656,558 +656,6 @@ EXPORT_SYMBOL_GPL(tty_prepare_flip_string_flags);
656 656
657 657
658/** 658/**
659 * tty_set_termios_ldisc - set ldisc field
660 * @tty: tty structure
661 * @num: line discipline number
662 *
663 * This is probably overkill for real world processors but
664 * they are not on hot paths so a little discipline won't do
665 * any harm.
666 *
667 * Locking: takes termios_mutex
668 */
669
670static void tty_set_termios_ldisc(struct tty_struct *tty, int num)
671{
672 mutex_lock(&tty->termios_mutex);
673 tty->termios->c_line = num;
674 mutex_unlock(&tty->termios_mutex);
675}
676
677/*
678 * This guards the refcounted line discipline lists. The lock
679 * must be taken with irqs off because there are hangup path
680 * callers who will do ldisc lookups and cannot sleep.
681 */
682
683static DEFINE_SPINLOCK(tty_ldisc_lock);
684static DECLARE_WAIT_QUEUE_HEAD(tty_ldisc_wait);
685/* Line disc dispatch table */
686static struct tty_ldisc_ops *tty_ldiscs[NR_LDISCS];
687
688/**
689 * tty_register_ldisc - install a line discipline
690 * @disc: ldisc number
691 * @new_ldisc: pointer to the ldisc object
692 *
693 * Installs a new line discipline into the kernel. The discipline
694 * is set up as unreferenced and then made available to the kernel
695 * from this point onwards.
696 *
697 * Locking:
698 * takes tty_ldisc_lock to guard against ldisc races
699 */
700
701int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
702{
703 unsigned long flags;
704 int ret = 0;
705
706 if (disc < N_TTY || disc >= NR_LDISCS)
707 return -EINVAL;
708
709 spin_lock_irqsave(&tty_ldisc_lock, flags);
710 tty_ldiscs[disc] = new_ldisc;
711 new_ldisc->num = disc;
712 new_ldisc->refcount = 0;
713 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
714
715 return ret;
716}
717EXPORT_SYMBOL(tty_register_ldisc);
718
719/**
720 * tty_unregister_ldisc - unload a line discipline
721 * @disc: ldisc number
722 * @new_ldisc: pointer to the ldisc object
723 *
724 * Remove a line discipline from the kernel providing it is not
725 * currently in use.
726 *
727 * Locking:
728 * takes tty_ldisc_lock to guard against ldisc races
729 */
730
731int tty_unregister_ldisc(int disc)
732{
733 unsigned long flags;
734 int ret = 0;
735
736 if (disc < N_TTY || disc >= NR_LDISCS)
737 return -EINVAL;
738
739 spin_lock_irqsave(&tty_ldisc_lock, flags);
740 if (tty_ldiscs[disc]->refcount)
741 ret = -EBUSY;
742 else
743 tty_ldiscs[disc] = NULL;
744 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
745
746 return ret;
747}
748EXPORT_SYMBOL(tty_unregister_ldisc);
749
750
751/**
752 * tty_ldisc_try_get - try and reference an ldisc
753 * @disc: ldisc number
754 * @ld: tty ldisc structure to complete
755 *
756 * Attempt to open and lock a line discipline into place. Return
757 * the line discipline refcounted and assigned in ld. On an error
758 * report the error code back
759 */
760
761static int tty_ldisc_try_get(int disc, struct tty_ldisc *ld)
762{
763 unsigned long flags;
764 struct tty_ldisc_ops *ldops;
765 int err = -EINVAL;
766
767 spin_lock_irqsave(&tty_ldisc_lock, flags);
768 ld->ops = NULL;
769 ldops = tty_ldiscs[disc];
770 /* Check the entry is defined */
771 if (ldops) {
772 /* If the module is being unloaded we can't use it */
773 if (!try_module_get(ldops->owner))
774 err = -EAGAIN;
775 else {
776 /* lock it */
777 ldops->refcount++;
778 ld->ops = ldops;
779 err = 0;
780 }
781 }
782 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
783 return err;
784}
785
786/**
787 * tty_ldisc_get - take a reference to an ldisc
788 * @disc: ldisc number
789 * @ld: tty line discipline structure to use
790 *
791 * Takes a reference to a line discipline. Deals with refcounts and
792 * module locking counts. Returns NULL if the discipline is not available.
793 * Returns a pointer to the discipline and bumps the ref count if it is
794 * available
795 *
796 * Locking:
797 * takes tty_ldisc_lock to guard against ldisc races
798 */
799
800static int tty_ldisc_get(int disc, struct tty_ldisc *ld)
801{
802 int err;
803
804 if (disc < N_TTY || disc >= NR_LDISCS)
805 return -EINVAL;
806 err = tty_ldisc_try_get(disc, ld);
807 if (err == -EAGAIN) {
808 request_module("tty-ldisc-%d", disc);
809 err = tty_ldisc_try_get(disc, ld);
810 }
811 return err;
812}
813
814/**
815 * tty_ldisc_put - drop ldisc reference
816 * @disc: ldisc number
817 *
818 * Drop a reference to a line discipline. Manage refcounts and
819 * module usage counts
820 *
821 * Locking:
822 * takes tty_ldisc_lock to guard against ldisc races
823 */
824
825static void tty_ldisc_put(struct tty_ldisc_ops *ld)
826{
827 unsigned long flags;
828 int disc = ld->num;
829
830 BUG_ON(disc < N_TTY || disc >= NR_LDISCS);
831
832 spin_lock_irqsave(&tty_ldisc_lock, flags);
833 ld = tty_ldiscs[disc];
834 BUG_ON(ld->refcount == 0);
835 ld->refcount--;
836 module_put(ld->owner);
837 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
838}
839
840static void * tty_ldiscs_seq_start(struct seq_file *m, loff_t *pos)
841{
842 return (*pos < NR_LDISCS) ? pos : NULL;
843}
844
845static void * tty_ldiscs_seq_next(struct seq_file *m, void *v, loff_t *pos)
846{
847 (*pos)++;
848 return (*pos < NR_LDISCS) ? pos : NULL;
849}
850
851static void tty_ldiscs_seq_stop(struct seq_file *m, void *v)
852{
853}
854
855static int tty_ldiscs_seq_show(struct seq_file *m, void *v)
856{
857 int i = *(loff_t *)v;
858 struct tty_ldisc ld;
859
860 if (tty_ldisc_get(i, &ld) < 0)
861 return 0;
862 seq_printf(m, "%-10s %2d\n", ld.ops->name ? ld.ops->name : "???", i);
863 tty_ldisc_put(ld.ops);
864 return 0;
865}
866
867static const struct seq_operations tty_ldiscs_seq_ops = {
868 .start = tty_ldiscs_seq_start,
869 .next = tty_ldiscs_seq_next,
870 .stop = tty_ldiscs_seq_stop,
871 .show = tty_ldiscs_seq_show,
872};
873
874static int proc_tty_ldiscs_open(struct inode *inode, struct file *file)
875{
876 return seq_open(file, &tty_ldiscs_seq_ops);
877}
878
879const struct file_operations tty_ldiscs_proc_fops = {
880 .owner = THIS_MODULE,
881 .open = proc_tty_ldiscs_open,
882 .read = seq_read,
883 .llseek = seq_lseek,
884 .release = seq_release,
885};
886
887/**
888 * tty_ldisc_assign - set ldisc on a tty
889 * @tty: tty to assign
890 * @ld: line discipline
891 *
892 * Install an instance of a line discipline into a tty structure. The
893 * ldisc must have a reference count above zero to ensure it remains/
894 * The tty instance refcount starts at zero.
895 *
896 * Locking:
897 * Caller must hold references
898 */
899
900static void tty_ldisc_assign(struct tty_struct *tty, struct tty_ldisc *ld)
901{
902 ld->refcount = 0;
903 tty->ldisc = *ld;
904}
905
906/**
907 * tty_ldisc_try - internal helper
908 * @tty: the tty
909 *
910 * Make a single attempt to grab and bump the refcount on
911 * the tty ldisc. Return 0 on failure or 1 on success. This is
912 * used to implement both the waiting and non waiting versions
913 * of tty_ldisc_ref
914 *
915 * Locking: takes tty_ldisc_lock
916 */
917
918static int tty_ldisc_try(struct tty_struct *tty)
919{
920 unsigned long flags;
921 struct tty_ldisc *ld;
922 int ret = 0;
923
924 spin_lock_irqsave(&tty_ldisc_lock, flags);
925 ld = &tty->ldisc;
926 if (test_bit(TTY_LDISC, &tty->flags)) {
927 ld->refcount++;
928 ret = 1;
929 }
930 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
931 return ret;
932}
933
934/**
935 * tty_ldisc_ref_wait - wait for the tty ldisc
936 * @tty: tty device
937 *
938 * Dereference the line discipline for the terminal and take a
939 * reference to it. If the line discipline is in flux then
940 * wait patiently until it changes.
941 *
942 * Note: Must not be called from an IRQ/timer context. The caller
943 * must also be careful not to hold other locks that will deadlock
944 * against a discipline change, such as an existing ldisc reference
945 * (which we check for)
946 *
947 * Locking: call functions take tty_ldisc_lock
948 */
949
950struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *tty)
951{
952 /* wait_event is a macro */
953 wait_event(tty_ldisc_wait, tty_ldisc_try(tty));
954 if (tty->ldisc.refcount == 0)
955 printk(KERN_ERR "tty_ldisc_ref_wait\n");
956 return &tty->ldisc;
957}
958
959EXPORT_SYMBOL_GPL(tty_ldisc_ref_wait);
960
961/**
962 * tty_ldisc_ref - get the tty ldisc
963 * @tty: tty device
964 *
965 * Dereference the line discipline for the terminal and take a
966 * reference to it. If the line discipline is in flux then
967 * return NULL. Can be called from IRQ and timer functions.
968 *
969 * Locking: called functions take tty_ldisc_lock
970 */
971
972struct tty_ldisc *tty_ldisc_ref(struct tty_struct *tty)
973{
974 if (tty_ldisc_try(tty))
975 return &tty->ldisc;
976 return NULL;
977}
978
979EXPORT_SYMBOL_GPL(tty_ldisc_ref);
980
981/**
982 * tty_ldisc_deref - free a tty ldisc reference
983 * @ld: reference to free up
984 *
985 * Undoes the effect of tty_ldisc_ref or tty_ldisc_ref_wait. May
986 * be called in IRQ context.
987 *
988 * Locking: takes tty_ldisc_lock
989 */
990
991void tty_ldisc_deref(struct tty_ldisc *ld)
992{
993 unsigned long flags;
994
995 BUG_ON(ld == NULL);
996
997 spin_lock_irqsave(&tty_ldisc_lock, flags);
998 if (ld->refcount == 0)
999 printk(KERN_ERR "tty_ldisc_deref: no references.\n");
1000 else
1001 ld->refcount--;
1002 if (ld->refcount == 0)
1003 wake_up(&tty_ldisc_wait);
1004 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
1005}
1006
1007EXPORT_SYMBOL_GPL(tty_ldisc_deref);
1008
1009/**
1010 * tty_ldisc_enable - allow ldisc use
1011 * @tty: terminal to activate ldisc on
1012 *
1013 * Set the TTY_LDISC flag when the line discipline can be called
1014 * again. Do necessary wakeups for existing sleepers.
1015 *
1016 * Note: nobody should set this bit except via this function. Clearing
1017 * directly is allowed.
1018 */
1019
1020static void tty_ldisc_enable(struct tty_struct *tty)
1021{
1022 set_bit(TTY_LDISC, &tty->flags);
1023 wake_up(&tty_ldisc_wait);
1024}
1025
1026/**
1027 * tty_ldisc_restore - helper for tty ldisc change
1028 * @tty: tty to recover
1029 * @old: previous ldisc
1030 *
1031 * Restore the previous line discipline or N_TTY when a line discipline
1032 * change fails due to an open error
1033 */
1034
1035static void tty_ldisc_restore(struct tty_struct *tty, struct tty_ldisc *old)
1036{
1037 char buf[64];
1038 struct tty_ldisc new_ldisc;
1039
1040 /* There is an outstanding reference here so this is safe */
1041 tty_ldisc_get(old->ops->num, old);
1042 tty_ldisc_assign(tty, old);
1043 tty_set_termios_ldisc(tty, old->ops->num);
1044 if (old->ops->open && (old->ops->open(tty) < 0)) {
1045 tty_ldisc_put(old->ops);
1046 /* This driver is always present */
1047 if (tty_ldisc_get(N_TTY, &new_ldisc) < 0)
1048 panic("n_tty: get");
1049 tty_ldisc_assign(tty, &new_ldisc);
1050 tty_set_termios_ldisc(tty, N_TTY);
1051 if (new_ldisc.ops->open) {
1052 int r = new_ldisc.ops->open(tty);
1053 if (r < 0)
1054 panic("Couldn't open N_TTY ldisc for "
1055 "%s --- error %d.",
1056 tty_name(tty, buf), r);
1057 }
1058 }
1059}
1060
1061/**
1062 * tty_set_ldisc - set line discipline
1063 * @tty: the terminal to set
1064 * @ldisc: the line discipline
1065 *
1066 * Set the discipline of a tty line. Must be called from a process
1067 * context.
1068 *
1069 * Locking: takes tty_ldisc_lock.
1070 * called functions take termios_mutex
1071 */
1072
1073static int tty_set_ldisc(struct tty_struct *tty, int ldisc)
1074{
1075 int retval;
1076 struct tty_ldisc o_ldisc, new_ldisc;
1077 int work;
1078 unsigned long flags;
1079 struct tty_struct *o_tty;
1080
1081restart:
1082 /* This is a bit ugly for now but means we can break the 'ldisc
1083 is part of the tty struct' assumption later */
1084 retval = tty_ldisc_get(ldisc, &new_ldisc);
1085 if (retval)
1086 return retval;
1087
1088 /*
1089 * Problem: What do we do if this blocks ?
1090 */
1091
1092 tty_wait_until_sent(tty, 0);
1093
1094 if (tty->ldisc.ops->num == ldisc) {
1095 tty_ldisc_put(new_ldisc.ops);
1096 return 0;
1097 }
1098
1099 /*
1100 * No more input please, we are switching. The new ldisc
1101 * will update this value in the ldisc open function
1102 */
1103
1104 tty->receive_room = 0;
1105
1106 o_ldisc = tty->ldisc;
1107 o_tty = tty->link;
1108
1109 /*
1110 * Make sure we don't change while someone holds a
1111 * reference to the line discipline. The TTY_LDISC bit
1112 * prevents anyone taking a reference once it is clear.
1113 * We need the lock to avoid racing reference takers.
1114 */
1115
1116 spin_lock_irqsave(&tty_ldisc_lock, flags);
1117 if (tty->ldisc.refcount || (o_tty && o_tty->ldisc.refcount)) {
1118 if (tty->ldisc.refcount) {
1119 /* Free the new ldisc we grabbed. Must drop the lock
1120 first. */
1121 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
1122 tty_ldisc_put(o_ldisc.ops);
1123 /*
1124 * There are several reasons we may be busy, including
1125 * random momentary I/O traffic. We must therefore
1126 * retry. We could distinguish between blocking ops
1127 * and retries if we made tty_ldisc_wait() smarter.
1128 * That is up for discussion.
1129 */
1130 if (wait_event_interruptible(tty_ldisc_wait, tty->ldisc.refcount == 0) < 0)
1131 return -ERESTARTSYS;
1132 goto restart;
1133 }
1134 if (o_tty && o_tty->ldisc.refcount) {
1135 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
1136 tty_ldisc_put(o_tty->ldisc.ops);
1137 if (wait_event_interruptible(tty_ldisc_wait, o_tty->ldisc.refcount == 0) < 0)
1138 return -ERESTARTSYS;
1139 goto restart;
1140 }
1141 }
1142 /*
1143 * If the TTY_LDISC bit is set, then we are racing against
1144 * another ldisc change
1145 */
1146 if (!test_bit(TTY_LDISC, &tty->flags)) {
1147 struct tty_ldisc *ld;
1148 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
1149 tty_ldisc_put(new_ldisc.ops);
1150 ld = tty_ldisc_ref_wait(tty);
1151 tty_ldisc_deref(ld);
1152 goto restart;
1153 }
1154
1155 clear_bit(TTY_LDISC, &tty->flags);
1156 if (o_tty)
1157 clear_bit(TTY_LDISC, &o_tty->flags);
1158 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
1159
1160 /*
1161 * From this point on we know nobody has an ldisc
1162 * usage reference, nor can they obtain one until
1163 * we say so later on.
1164 */
1165
1166 work = cancel_delayed_work(&tty->buf.work);
1167 /*
1168 * Wait for ->hangup_work and ->buf.work handlers to terminate
1169 * MUST NOT hold locks here.
1170 */
1171 flush_scheduled_work();
1172 /* Shutdown the current discipline. */
1173 if (o_ldisc.ops->close)
1174 (o_ldisc.ops->close)(tty);
1175
1176 /* Now set up the new line discipline. */
1177 tty_ldisc_assign(tty, &new_ldisc);
1178 tty_set_termios_ldisc(tty, ldisc);
1179 if (new_ldisc.ops->open)
1180 retval = (new_ldisc.ops->open)(tty);
1181 if (retval < 0) {
1182 tty_ldisc_put(new_ldisc.ops);
1183 tty_ldisc_restore(tty, &o_ldisc);
1184 }
1185 /* At this point we hold a reference to the new ldisc and a
1186 a reference to the old ldisc. If we ended up flipping back
1187 to the existing ldisc we have two references to it */
1188
1189 if (tty->ldisc.ops->num != o_ldisc.ops->num && tty->ops->set_ldisc)
1190 tty->ops->set_ldisc(tty);
1191
1192 tty_ldisc_put(o_ldisc.ops);
1193
1194 /*
1195 * Allow ldisc referencing to occur as soon as the driver
1196 * ldisc callback completes.
1197 */
1198
1199 tty_ldisc_enable(tty);
1200 if (o_tty)
1201 tty_ldisc_enable(o_tty);
1202
1203 /* Restart it in case no characters kick it off. Safe if
1204 already running */
1205 if (work)
1206 schedule_delayed_work(&tty->buf.work, 1);
1207 return retval;
1208}
1209
1210/**
1211 * get_tty_driver - find device of a tty 659 * get_tty_driver - find device of a tty
1212 * @dev_t: device identifier 660 * @dev_t: device identifier
1213 * @index: returns the index of the tty 661 * @index: returns the index of the tty
@@ -2193,7 +1641,6 @@ static int init_dev(struct tty_driver *driver, int idx,
2193 struct ktermios *tp, **tp_loc, *o_tp, **o_tp_loc; 1641 struct ktermios *tp, **tp_loc, *o_tp, **o_tp_loc;
2194 struct ktermios *ltp, **ltp_loc, *o_ltp, **o_ltp_loc; 1642 struct ktermios *ltp, **ltp_loc, *o_ltp, **o_ltp_loc;
2195 int retval = 0; 1643 int retval = 0;
2196 struct tty_ldisc *ld;
2197 1644
2198 /* check whether we're reopening an existing tty */ 1645 /* check whether we're reopening an existing tty */
2199 if (driver->flags & TTY_DRIVER_DEVPTS_MEM) { 1646 if (driver->flags & TTY_DRIVER_DEVPTS_MEM) {
@@ -2342,25 +1789,12 @@ static int init_dev(struct tty_driver *driver, int idx,
2342 * If we fail here just call release_tty to clean up. No need 1789 * If we fail here just call release_tty to clean up. No need
2343 * to decrement the use counts, as release_tty doesn't care. 1790 * to decrement the use counts, as release_tty doesn't care.
2344 */ 1791 */
2345
2346 ld = &tty->ldisc;
2347 1792
2348 if (ld->ops->open) { 1793 retval = tty_ldisc_setup(tty, o_tty);
2349 retval = (ld->ops->open)(tty); 1794
2350 if (retval) 1795 if (retval)
2351 goto release_mem_out; 1796 goto release_mem_out;
2352 } 1797 goto success;
2353 if (o_tty && o_tty->ldisc.ops->open) {
2354 retval = (o_tty->ldisc.ops->open)(o_tty);
2355 if (retval) {
2356 if (ld->ops->close)
2357 (ld->ops->close)(tty);
2358 goto release_mem_out;
2359 }
2360 tty_ldisc_enable(o_tty);
2361 }
2362 tty_ldisc_enable(tty);
2363 goto success;
2364 1798
2365 /* 1799 /*
2366 * This fast open can be used if the tty is already open. 1800 * This fast open can be used if the tty is already open.
@@ -2498,12 +1932,10 @@ static void release_tty(struct tty_struct *tty, int idx)
2498static void release_dev(struct file *filp) 1932static void release_dev(struct file *filp)
2499{ 1933{
2500 struct tty_struct *tty, *o_tty; 1934 struct tty_struct *tty, *o_tty;
2501 struct tty_ldisc ld;
2502 int pty_master, tty_closing, o_tty_closing, do_sleep; 1935 int pty_master, tty_closing, o_tty_closing, do_sleep;
2503 int devpts; 1936 int devpts;
2504 int idx; 1937 int idx;
2505 char buf[64]; 1938 char buf[64];
2506 unsigned long flags;
2507 1939
2508 tty = (struct tty_struct *)filp->private_data; 1940 tty = (struct tty_struct *)filp->private_data;
2509 if (tty_paranoia_check(tty, filp->f_path.dentry->d_inode, 1941 if (tty_paranoia_check(tty, filp->f_path.dentry->d_inode,
@@ -2705,56 +2137,9 @@ static void release_dev(struct file *filp)
2705 printk(KERN_DEBUG "freeing tty structure..."); 2137 printk(KERN_DEBUG "freeing tty structure...");
2706#endif 2138#endif
2707 /* 2139 /*
2708 * Prevent flush_to_ldisc() from rescheduling the work for later. Then 2140 * Ask the line discipline code to release its structures
2709 * kill any delayed work. As this is the final close it does not
2710 * race with the set_ldisc code path.
2711 */ 2141 */
2712 clear_bit(TTY_LDISC, &tty->flags); 2142 tty_ldisc_release(tty, o_tty);
2713 cancel_delayed_work(&tty->buf.work);
2714
2715 /*
2716 * Wait for ->hangup_work and ->buf.work handlers to terminate
2717 */
2718
2719 flush_scheduled_work();
2720
2721 /*
2722 * Wait for any short term users (we know they are just driver
2723 * side waiters as the file is closing so user count on the file
2724 * side is zero.
2725 */
2726 spin_lock_irqsave(&tty_ldisc_lock, flags);
2727 while (tty->ldisc.refcount) {
2728 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
2729 wait_event(tty_ldisc_wait, tty->ldisc.refcount == 0);
2730 spin_lock_irqsave(&tty_ldisc_lock, flags);
2731 }
2732 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
2733 /*
2734 * Shutdown the current line discipline, and reset it to N_TTY.
2735 *
2736 * FIXME: this MUST get fixed for the new reflocking
2737 */
2738 if (tty->ldisc.ops->close)
2739 (tty->ldisc.ops->close)(tty);
2740 tty_ldisc_put(tty->ldisc.ops);
2741
2742 /*
2743 * Switch the line discipline back
2744 */
2745 WARN_ON(tty_ldisc_get(N_TTY, &ld));
2746 tty_ldisc_assign(tty, &ld);
2747 tty_set_termios_ldisc(tty, N_TTY);
2748 if (o_tty) {
2749 /* FIXME: could o_tty be in setldisc here ? */
2750 clear_bit(TTY_LDISC, &o_tty->flags);
2751 if (o_tty->ldisc.ops->close)
2752 (o_tty->ldisc.ops->close)(o_tty);
2753 tty_ldisc_put(o_tty->ldisc.ops);
2754 WARN_ON(tty_ldisc_get(N_TTY, &ld));
2755 tty_ldisc_assign(o_tty, &ld);
2756 tty_set_termios_ldisc(o_tty, N_TTY);
2757 }
2758 /* 2143 /*
2759 * The release_tty function takes care of the details of clearing 2144 * The release_tty function takes care of the details of clearing
2760 * the slots and preserving the termios structure. 2145 * the slots and preserving the termios structure.
@@ -3464,16 +2849,29 @@ static int tiocsetd(struct tty_struct *tty, int __user *p)
3464 2849
3465static int send_break(struct tty_struct *tty, unsigned int duration) 2850static int send_break(struct tty_struct *tty, unsigned int duration)
3466{ 2851{
3467 if (tty_write_lock(tty, 0) < 0) 2852 int retval;
3468 return -EINTR; 2853
3469 tty->ops->break_ctl(tty, -1); 2854 if (tty->ops->break_ctl == NULL)
3470 if (!signal_pending(current)) 2855 return 0;
3471 msleep_interruptible(duration); 2856
3472 tty->ops->break_ctl(tty, 0); 2857 if (tty->driver->flags & TTY_DRIVER_HARDWARE_BREAK)
3473 tty_write_unlock(tty); 2858 retval = tty->ops->break_ctl(tty, duration);
3474 if (signal_pending(current)) 2859 else {
3475 return -EINTR; 2860 /* Do the work ourselves */
3476 return 0; 2861 if (tty_write_lock(tty, 0) < 0)
2862 return -EINTR;
2863 retval = tty->ops->break_ctl(tty, -1);
2864 if (retval)
2865 goto out;
2866 if (!signal_pending(current))
2867 msleep_interruptible(duration);
2868 retval = tty->ops->break_ctl(tty, 0);
2869out:
2870 tty_write_unlock(tty);
2871 if (signal_pending(current))
2872 retval = -EINTR;
2873 }
2874 return retval;
3477} 2875}
3478 2876
3479/** 2877/**
@@ -3564,36 +2962,6 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
3564 tty->driver->subtype == PTY_TYPE_MASTER) 2962 tty->driver->subtype == PTY_TYPE_MASTER)
3565 real_tty = tty->link; 2963 real_tty = tty->link;
3566 2964
3567 /*
3568 * Break handling by driver
3569 */
3570
3571 retval = -EINVAL;
3572
3573 if (!tty->ops->break_ctl) {
3574 switch (cmd) {
3575 case TIOCSBRK:
3576 case TIOCCBRK:
3577 if (tty->ops->ioctl)
3578 retval = tty->ops->ioctl(tty, file, cmd, arg);
3579 if (retval != -EINVAL && retval != -ENOIOCTLCMD)
3580 printk(KERN_WARNING "tty: driver %s needs updating to use break_ctl\n", tty->driver->name);
3581 return retval;
3582
3583 /* These two ioctl's always return success; even if */
3584 /* the driver doesn't support them. */
3585 case TCSBRK:
3586 case TCSBRKP:
3587 if (!tty->ops->ioctl)
3588 return 0;
3589 retval = tty->ops->ioctl(tty, file, cmd, arg);
3590 if (retval != -EINVAL && retval != -ENOIOCTLCMD)
3591 printk(KERN_WARNING "tty: driver %s needs updating to use break_ctl\n", tty->driver->name);
3592 if (retval == -ENOIOCTLCMD)
3593 retval = 0;
3594 return retval;
3595 }
3596 }
3597 2965
3598 /* 2966 /*
3599 * Factor out some common prep work 2967 * Factor out some common prep work
@@ -3615,6 +2983,9 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
3615 break; 2983 break;
3616 } 2984 }
3617 2985
2986 /*
2987 * Now do the stuff.
2988 */
3618 switch (cmd) { 2989 switch (cmd) {
3619 case TIOCSTI: 2990 case TIOCSTI:
3620 return tiocsti(tty, p); 2991 return tiocsti(tty, p);
@@ -3658,12 +3029,11 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
3658 */ 3029 */
3659 case TIOCSBRK: /* Turn break on, unconditionally */ 3030 case TIOCSBRK: /* Turn break on, unconditionally */
3660 if (tty->ops->break_ctl) 3031 if (tty->ops->break_ctl)
3661 tty->ops->break_ctl(tty, -1); 3032 return tty->ops->break_ctl(tty, -1);
3662 return 0; 3033 return 0;
3663
3664 case TIOCCBRK: /* Turn break off, unconditionally */ 3034 case TIOCCBRK: /* Turn break off, unconditionally */
3665 if (tty->ops->break_ctl) 3035 if (tty->ops->break_ctl)
3666 tty->ops->break_ctl(tty, 0); 3036 return tty->ops->break_ctl(tty, 0);
3667 return 0; 3037 return 0;
3668 case TCSBRK: /* SVID version: non-zero arg --> no break */ 3038 case TCSBRK: /* SVID version: non-zero arg --> no break */
3669 /* non-zero arg means wait for all output data 3039 /* non-zero arg means wait for all output data
@@ -3962,12 +3332,9 @@ EXPORT_SYMBOL(tty_flip_buffer_push);
3962 3332
3963static void initialize_tty_struct(struct tty_struct *tty) 3333static void initialize_tty_struct(struct tty_struct *tty)
3964{ 3334{
3965 struct tty_ldisc ld;
3966 memset(tty, 0, sizeof(struct tty_struct)); 3335 memset(tty, 0, sizeof(struct tty_struct));
3967 tty->magic = TTY_MAGIC; 3336 tty->magic = TTY_MAGIC;
3968 if (tty_ldisc_get(N_TTY, &ld) < 0) 3337 tty_ldisc_init(tty);
3969 panic("n_tty: init_tty");
3970 tty_ldisc_assign(tty, &ld);
3971 tty->session = NULL; 3338 tty->session = NULL;
3972 tty->pgrp = NULL; 3339 tty->pgrp = NULL;
3973 tty->overrun_time = jiffies; 3340 tty->overrun_time = jiffies;
@@ -4280,7 +3647,7 @@ void __init console_init(void)
4280 initcall_t *call; 3647 initcall_t *call;
4281 3648
4282 /* Setup the default TTY line discipline. */ 3649 /* Setup the default TTY line discipline. */
4283 (void) tty_register_ldisc(N_TTY, &tty_ldisc_N_TTY); 3650 tty_ldisc_begin();
4284 3651
4285 /* 3652 /*
4286 * set up the console device so that later boot sequences can 3653 * set up the console device so that later boot sequences can
diff --git a/drivers/char/tty_ldisc.c b/drivers/char/tty_ldisc.c
new file mode 100644
index 000000000000..241cbdea65ab
--- /dev/null
+++ b/drivers/char/tty_ldisc.c
@@ -0,0 +1,714 @@
1#include <linux/types.h>
2#include <linux/major.h>
3#include <linux/errno.h>
4#include <linux/signal.h>
5#include <linux/fcntl.h>
6#include <linux/sched.h>
7#include <linux/interrupt.h>
8#include <linux/tty.h>
9#include <linux/tty_driver.h>
10#include <linux/tty_flip.h>
11#include <linux/devpts_fs.h>
12#include <linux/file.h>
13#include <linux/fdtable.h>
14#include <linux/console.h>
15#include <linux/timer.h>
16#include <linux/ctype.h>
17#include <linux/kd.h>
18#include <linux/mm.h>
19#include <linux/string.h>
20#include <linux/slab.h>
21#include <linux/poll.h>
22#include <linux/proc_fs.h>
23#include <linux/init.h>
24#include <linux/module.h>
25#include <linux/smp_lock.h>
26#include <linux/device.h>
27#include <linux/wait.h>
28#include <linux/bitops.h>
29#include <linux/delay.h>
30#include <linux/seq_file.h>
31
32#include <linux/uaccess.h>
33#include <asm/system.h>
34
35#include <linux/kbd_kern.h>
36#include <linux/vt_kern.h>
37#include <linux/selection.h>
38
39#include <linux/kmod.h>
40#include <linux/nsproxy.h>
41
42/*
43 * This guards the refcounted line discipline lists. The lock
44 * must be taken with irqs off because there are hangup path
45 * callers who will do ldisc lookups and cannot sleep.
46 */
47
48static DEFINE_SPINLOCK(tty_ldisc_lock);
49static DECLARE_WAIT_QUEUE_HEAD(tty_ldisc_wait);
50/* Line disc dispatch table */
51static struct tty_ldisc_ops *tty_ldiscs[NR_LDISCS];
52
53/**
54 * tty_register_ldisc - install a line discipline
55 * @disc: ldisc number
56 * @new_ldisc: pointer to the ldisc object
57 *
58 * Installs a new line discipline into the kernel. The discipline
59 * is set up as unreferenced and then made available to the kernel
60 * from this point onwards.
61 *
62 * Locking:
63 * takes tty_ldisc_lock to guard against ldisc races
64 */
65
66int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
67{
68 unsigned long flags;
69 int ret = 0;
70
71 if (disc < N_TTY || disc >= NR_LDISCS)
72 return -EINVAL;
73
74 spin_lock_irqsave(&tty_ldisc_lock, flags);
75 tty_ldiscs[disc] = new_ldisc;
76 new_ldisc->num = disc;
77 new_ldisc->refcount = 0;
78 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
79
80 return ret;
81}
82EXPORT_SYMBOL(tty_register_ldisc);
83
84/**
85 * tty_unregister_ldisc - unload a line discipline
86 * @disc: ldisc number
87 * @new_ldisc: pointer to the ldisc object
88 *
89 * Remove a line discipline from the kernel providing it is not
90 * currently in use.
91 *
92 * Locking:
93 * takes tty_ldisc_lock to guard against ldisc races
94 */
95
96int tty_unregister_ldisc(int disc)
97{
98 unsigned long flags;
99 int ret = 0;
100
101 if (disc < N_TTY || disc >= NR_LDISCS)
102 return -EINVAL;
103
104 spin_lock_irqsave(&tty_ldisc_lock, flags);
105 if (tty_ldiscs[disc]->refcount)
106 ret = -EBUSY;
107 else
108 tty_ldiscs[disc] = NULL;
109 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
110
111 return ret;
112}
113EXPORT_SYMBOL(tty_unregister_ldisc);
114
115
116/**
117 * tty_ldisc_try_get - try and reference an ldisc
118 * @disc: ldisc number
119 * @ld: tty ldisc structure to complete
120 *
121 * Attempt to open and lock a line discipline into place. Return
122 * the line discipline refcounted and assigned in ld. On an error
123 * report the error code back
124 */
125
126static int tty_ldisc_try_get(int disc, struct tty_ldisc *ld)
127{
128 unsigned long flags;
129 struct tty_ldisc_ops *ldops;
130 int err = -EINVAL;
131
132 spin_lock_irqsave(&tty_ldisc_lock, flags);
133 ld->ops = NULL;
134 ldops = tty_ldiscs[disc];
135 /* Check the entry is defined */
136 if (ldops) {
137 /* If the module is being unloaded we can't use it */
138 if (!try_module_get(ldops->owner))
139 err = -EAGAIN;
140 else {
141 /* lock it */
142 ldops->refcount++;
143 ld->ops = ldops;
144 err = 0;
145 }
146 }
147 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
148 return err;
149}
150
151/**
152 * tty_ldisc_get - take a reference to an ldisc
153 * @disc: ldisc number
154 * @ld: tty line discipline structure to use
155 *
156 * Takes a reference to a line discipline. Deals with refcounts and
157 * module locking counts. Returns NULL if the discipline is not available.
158 * Returns a pointer to the discipline and bumps the ref count if it is
159 * available
160 *
161 * Locking:
162 * takes tty_ldisc_lock to guard against ldisc races
163 */
164
165static int tty_ldisc_get(int disc, struct tty_ldisc *ld)
166{
167 int err;
168
169 if (disc < N_TTY || disc >= NR_LDISCS)
170 return -EINVAL;
171 err = tty_ldisc_try_get(disc, ld);
172 if (err == -EAGAIN) {
173 request_module("tty-ldisc-%d", disc);
174 err = tty_ldisc_try_get(disc, ld);
175 }
176 return err;
177}
178
179/**
180 * tty_ldisc_put - drop ldisc reference
181 * @disc: ldisc number
182 *
183 * Drop a reference to a line discipline. Manage refcounts and
184 * module usage counts
185 *
186 * Locking:
187 * takes tty_ldisc_lock to guard against ldisc races
188 */
189
190static void tty_ldisc_put(struct tty_ldisc_ops *ld)
191{
192 unsigned long flags;
193 int disc = ld->num;
194
195 BUG_ON(disc < N_TTY || disc >= NR_LDISCS);
196
197 spin_lock_irqsave(&tty_ldisc_lock, flags);
198 ld = tty_ldiscs[disc];
199 BUG_ON(ld->refcount == 0);
200 ld->refcount--;
201 module_put(ld->owner);
202 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
203}
204
205static void * tty_ldiscs_seq_start(struct seq_file *m, loff_t *pos)
206{
207 return (*pos < NR_LDISCS) ? pos : NULL;
208}
209
210static void * tty_ldiscs_seq_next(struct seq_file *m, void *v, loff_t *pos)
211{
212 (*pos)++;
213 return (*pos < NR_LDISCS) ? pos : NULL;
214}
215
216static void tty_ldiscs_seq_stop(struct seq_file *m, void *v)
217{
218}
219
220static int tty_ldiscs_seq_show(struct seq_file *m, void *v)
221{
222 int i = *(loff_t *)v;
223 struct tty_ldisc ld;
224
225 if (tty_ldisc_get(i, &ld) < 0)
226 return 0;
227 seq_printf(m, "%-10s %2d\n", ld.ops->name ? ld.ops->name : "???", i);
228 tty_ldisc_put(ld.ops);
229 return 0;
230}
231
232static const struct seq_operations tty_ldiscs_seq_ops = {
233 .start = tty_ldiscs_seq_start,
234 .next = tty_ldiscs_seq_next,
235 .stop = tty_ldiscs_seq_stop,
236 .show = tty_ldiscs_seq_show,
237};
238
239static int proc_tty_ldiscs_open(struct inode *inode, struct file *file)
240{
241 return seq_open(file, &tty_ldiscs_seq_ops);
242}
243
244const struct file_operations tty_ldiscs_proc_fops = {
245 .owner = THIS_MODULE,
246 .open = proc_tty_ldiscs_open,
247 .read = seq_read,
248 .llseek = seq_lseek,
249 .release = seq_release,
250};
251
252/**
253 * tty_ldisc_assign - set ldisc on a tty
254 * @tty: tty to assign
255 * @ld: line discipline
256 *
257 * Install an instance of a line discipline into a tty structure. The
258 * ldisc must have a reference count above zero to ensure it remains/
259 * The tty instance refcount starts at zero.
260 *
261 * Locking:
262 * Caller must hold references
263 */
264
265static void tty_ldisc_assign(struct tty_struct *tty, struct tty_ldisc *ld)
266{
267 ld->refcount = 0;
268 tty->ldisc = *ld;
269}
270
271/**
272 * tty_ldisc_try - internal helper
273 * @tty: the tty
274 *
275 * Make a single attempt to grab and bump the refcount on
276 * the tty ldisc. Return 0 on failure or 1 on success. This is
277 * used to implement both the waiting and non waiting versions
278 * of tty_ldisc_ref
279 *
280 * Locking: takes tty_ldisc_lock
281 */
282
283static int tty_ldisc_try(struct tty_struct *tty)
284{
285 unsigned long flags;
286 struct tty_ldisc *ld;
287 int ret = 0;
288
289 spin_lock_irqsave(&tty_ldisc_lock, flags);
290 ld = &tty->ldisc;
291 if (test_bit(TTY_LDISC, &tty->flags)) {
292 ld->refcount++;
293 ret = 1;
294 }
295 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
296 return ret;
297}
298
299/**
300 * tty_ldisc_ref_wait - wait for the tty ldisc
301 * @tty: tty device
302 *
303 * Dereference the line discipline for the terminal and take a
304 * reference to it. If the line discipline is in flux then
305 * wait patiently until it changes.
306 *
307 * Note: Must not be called from an IRQ/timer context. The caller
308 * must also be careful not to hold other locks that will deadlock
309 * against a discipline change, such as an existing ldisc reference
310 * (which we check for)
311 *
312 * Locking: call functions take tty_ldisc_lock
313 */
314
315struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *tty)
316{
317 /* wait_event is a macro */
318 wait_event(tty_ldisc_wait, tty_ldisc_try(tty));
319 if (tty->ldisc.refcount == 0)
320 printk(KERN_ERR "tty_ldisc_ref_wait\n");
321 return &tty->ldisc;
322}
323
324EXPORT_SYMBOL_GPL(tty_ldisc_ref_wait);
325
326/**
327 * tty_ldisc_ref - get the tty ldisc
328 * @tty: tty device
329 *
330 * Dereference the line discipline for the terminal and take a
331 * reference to it. If the line discipline is in flux then
332 * return NULL. Can be called from IRQ and timer functions.
333 *
334 * Locking: called functions take tty_ldisc_lock
335 */
336
337struct tty_ldisc *tty_ldisc_ref(struct tty_struct *tty)
338{
339 if (tty_ldisc_try(tty))
340 return &tty->ldisc;
341 return NULL;
342}
343
344EXPORT_SYMBOL_GPL(tty_ldisc_ref);
345
346/**
347 * tty_ldisc_deref - free a tty ldisc reference
348 * @ld: reference to free up
349 *
350 * Undoes the effect of tty_ldisc_ref or tty_ldisc_ref_wait. May
351 * be called in IRQ context.
352 *
353 * Locking: takes tty_ldisc_lock
354 */
355
356void tty_ldisc_deref(struct tty_ldisc *ld)
357{
358 unsigned long flags;
359
360 BUG_ON(ld == NULL);
361
362 spin_lock_irqsave(&tty_ldisc_lock, flags);
363 if (ld->refcount == 0)
364 printk(KERN_ERR "tty_ldisc_deref: no references.\n");
365 else
366 ld->refcount--;
367 if (ld->refcount == 0)
368 wake_up(&tty_ldisc_wait);
369 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
370}
371
372EXPORT_SYMBOL_GPL(tty_ldisc_deref);
373
374/**
375 * tty_ldisc_enable - allow ldisc use
376 * @tty: terminal to activate ldisc on
377 *
378 * Set the TTY_LDISC flag when the line discipline can be called
379 * again. Do necessary wakeups for existing sleepers.
380 *
381 * Note: nobody should set this bit except via this function. Clearing
382 * directly is allowed.
383 */
384
385void tty_ldisc_enable(struct tty_struct *tty)
386{
387 set_bit(TTY_LDISC, &tty->flags);
388 wake_up(&tty_ldisc_wait);
389}
390
391/**
392 * tty_set_termios_ldisc - set ldisc field
393 * @tty: tty structure
394 * @num: line discipline number
395 *
396 * This is probably overkill for real world processors but
397 * they are not on hot paths so a little discipline won't do
398 * any harm.
399 *
400 * Locking: takes termios_mutex
401 */
402
403static void tty_set_termios_ldisc(struct tty_struct *tty, int num)
404{
405 mutex_lock(&tty->termios_mutex);
406 tty->termios->c_line = num;
407 mutex_unlock(&tty->termios_mutex);
408}
409
410
411/**
412 * tty_ldisc_restore - helper for tty ldisc change
413 * @tty: tty to recover
414 * @old: previous ldisc
415 *
416 * Restore the previous line discipline or N_TTY when a line discipline
417 * change fails due to an open error
418 */
419
420static void tty_ldisc_restore(struct tty_struct *tty, struct tty_ldisc *old)
421{
422 char buf[64];
423 struct tty_ldisc new_ldisc;
424
425 /* There is an outstanding reference here so this is safe */
426 tty_ldisc_get(old->ops->num, old);
427 tty_ldisc_assign(tty, old);
428 tty_set_termios_ldisc(tty, old->ops->num);
429 if (old->ops->open && (old->ops->open(tty) < 0)) {
430 tty_ldisc_put(old->ops);
431 /* This driver is always present */
432 if (tty_ldisc_get(N_TTY, &new_ldisc) < 0)
433 panic("n_tty: get");
434 tty_ldisc_assign(tty, &new_ldisc);
435 tty_set_termios_ldisc(tty, N_TTY);
436 if (new_ldisc.ops->open) {
437 int r = new_ldisc.ops->open(tty);
438 if (r < 0)
439 panic("Couldn't open N_TTY ldisc for "
440 "%s --- error %d.",
441 tty_name(tty, buf), r);
442 }
443 }
444}
445
446/**
447 * tty_set_ldisc - set line discipline
448 * @tty: the terminal to set
449 * @ldisc: the line discipline
450 *
451 * Set the discipline of a tty line. Must be called from a process
452 * context.
453 *
454 * Locking: takes tty_ldisc_lock.
455 * called functions take termios_mutex
456 */
457
458int tty_set_ldisc(struct tty_struct *tty, int ldisc)
459{
460 int retval;
461 struct tty_ldisc o_ldisc, new_ldisc;
462 int work;
463 unsigned long flags;
464 struct tty_struct *o_tty;
465
466restart:
467 /* This is a bit ugly for now but means we can break the 'ldisc
468 is part of the tty struct' assumption later */
469 retval = tty_ldisc_get(ldisc, &new_ldisc);
470 if (retval)
471 return retval;
472
473 /*
474 * Problem: What do we do if this blocks ?
475 */
476
477 tty_wait_until_sent(tty, 0);
478
479 if (tty->ldisc.ops->num == ldisc) {
480 tty_ldisc_put(new_ldisc.ops);
481 return 0;
482 }
483
484 /*
485 * No more input please, we are switching. The new ldisc
486 * will update this value in the ldisc open function
487 */
488
489 tty->receive_room = 0;
490
491 o_ldisc = tty->ldisc;
492 o_tty = tty->link;
493
494 /*
495 * Make sure we don't change while someone holds a
496 * reference to the line discipline. The TTY_LDISC bit
497 * prevents anyone taking a reference once it is clear.
498 * We need the lock to avoid racing reference takers.
499 */
500
501 spin_lock_irqsave(&tty_ldisc_lock, flags);
502 if (tty->ldisc.refcount || (o_tty && o_tty->ldisc.refcount)) {
503 if (tty->ldisc.refcount) {
504 /* Free the new ldisc we grabbed. Must drop the lock
505 first. */
506 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
507 tty_ldisc_put(o_ldisc.ops);
508 /*
509 * There are several reasons we may be busy, including
510 * random momentary I/O traffic. We must therefore
511 * retry. We could distinguish between blocking ops
512 * and retries if we made tty_ldisc_wait() smarter.
513 * That is up for discussion.
514 */
515 if (wait_event_interruptible(tty_ldisc_wait, tty->ldisc.refcount == 0) < 0)
516 return -ERESTARTSYS;
517 goto restart;
518 }
519 if (o_tty && o_tty->ldisc.refcount) {
520 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
521 tty_ldisc_put(o_tty->ldisc.ops);
522 if (wait_event_interruptible(tty_ldisc_wait, o_tty->ldisc.refcount == 0) < 0)
523 return -ERESTARTSYS;
524 goto restart;
525 }
526 }
527 /*
528 * If the TTY_LDISC bit is set, then we are racing against
529 * another ldisc change
530 */
531 if (!test_bit(TTY_LDISC, &tty->flags)) {
532 struct tty_ldisc *ld;
533 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
534 tty_ldisc_put(new_ldisc.ops);
535 ld = tty_ldisc_ref_wait(tty);
536 tty_ldisc_deref(ld);
537 goto restart;
538 }
539
540 clear_bit(TTY_LDISC, &tty->flags);
541 if (o_tty)
542 clear_bit(TTY_LDISC, &o_tty->flags);
543 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
544
545 /*
546 * From this point on we know nobody has an ldisc
547 * usage reference, nor can they obtain one until
548 * we say so later on.
549 */
550
551 work = cancel_delayed_work(&tty->buf.work);
552 /*
553 * Wait for ->hangup_work and ->buf.work handlers to terminate
554 * MUST NOT hold locks here.
555 */
556 flush_scheduled_work();
557 /* Shutdown the current discipline. */
558 if (o_ldisc.ops->close)
559 (o_ldisc.ops->close)(tty);
560
561 /* Now set up the new line discipline. */
562 tty_ldisc_assign(tty, &new_ldisc);
563 tty_set_termios_ldisc(tty, ldisc);
564 if (new_ldisc.ops->open)
565 retval = (new_ldisc.ops->open)(tty);
566 if (retval < 0) {
567 tty_ldisc_put(new_ldisc.ops);
568 tty_ldisc_restore(tty, &o_ldisc);
569 }
570 /* At this point we hold a reference to the new ldisc and a
571 a reference to the old ldisc. If we ended up flipping back
572 to the existing ldisc we have two references to it */
573
574 if (tty->ldisc.ops->num != o_ldisc.ops->num && tty->ops->set_ldisc)
575 tty->ops->set_ldisc(tty);
576
577 tty_ldisc_put(o_ldisc.ops);
578
579 /*
580 * Allow ldisc referencing to occur as soon as the driver
581 * ldisc callback completes.
582 */
583
584 tty_ldisc_enable(tty);
585 if (o_tty)
586 tty_ldisc_enable(o_tty);
587
588 /* Restart it in case no characters kick it off. Safe if
589 already running */
590 if (work)
591 schedule_delayed_work(&tty->buf.work, 1);
592 return retval;
593}
594
595
596/**
597 * tty_ldisc_setup - open line discipline
598 * @tty: tty being shut down
599 * @o_tty: pair tty for pty/tty pairs
600 *
601 * Called during the initial open of a tty/pty pair in order to set up the
602 * line discplines and bind them to the tty.
603 */
604
605int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty)
606{
607 struct tty_ldisc *ld = &tty->ldisc;
608 int retval;
609
610 if (ld->ops->open) {
611 retval = (ld->ops->open)(tty);
612 if (retval)
613 return retval;
614 }
615 if (o_tty && o_tty->ldisc.ops->open) {
616 retval = (o_tty->ldisc.ops->open)(o_tty);
617 if (retval) {
618 if (ld->ops->close)
619 (ld->ops->close)(tty);
620 return retval;
621 }
622 tty_ldisc_enable(o_tty);
623 }
624 tty_ldisc_enable(tty);
625 return 0;
626}
627
628/**
629 * tty_ldisc_release - release line discipline
630 * @tty: tty being shut down
631 * @o_tty: pair tty for pty/tty pairs
632 *
633 * Called during the final close of a tty/pty pair in order to shut down the
634 * line discpline layer.
635 */
636
637void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty)
638{
639 unsigned long flags;
640 struct tty_ldisc ld;
641 /*
642 * Prevent flush_to_ldisc() from rescheduling the work for later. Then
643 * kill any delayed work. As this is the final close it does not
644 * race with the set_ldisc code path.
645 */
646 clear_bit(TTY_LDISC, &tty->flags);
647 cancel_delayed_work(&tty->buf.work);
648
649 /*
650 * Wait for ->hangup_work and ->buf.work handlers to terminate
651 */
652
653 flush_scheduled_work();
654
655 /*
656 * Wait for any short term users (we know they are just driver
657 * side waiters as the file is closing so user count on the file
658 * side is zero.
659 */
660 spin_lock_irqsave(&tty_ldisc_lock, flags);
661 while (tty->ldisc.refcount) {
662 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
663 wait_event(tty_ldisc_wait, tty->ldisc.refcount == 0);
664 spin_lock_irqsave(&tty_ldisc_lock, flags);
665 }
666 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
667 /*
668 * Shutdown the current line discipline, and reset it to N_TTY.
669 *
670 * FIXME: this MUST get fixed for the new reflocking
671 */
672 if (tty->ldisc.ops->close)
673 (tty->ldisc.ops->close)(tty);
674 tty_ldisc_put(tty->ldisc.ops);
675
676 /*
677 * Switch the line discipline back
678 */
679 WARN_ON(tty_ldisc_get(N_TTY, &ld));
680 tty_ldisc_assign(tty, &ld);
681 tty_set_termios_ldisc(tty, N_TTY);
682 if (o_tty) {
683 /* FIXME: could o_tty be in setldisc here ? */
684 clear_bit(TTY_LDISC, &o_tty->flags);
685 if (o_tty->ldisc.ops->close)
686 (o_tty->ldisc.ops->close)(o_tty);
687 tty_ldisc_put(o_tty->ldisc.ops);
688 WARN_ON(tty_ldisc_get(N_TTY, &ld));
689 tty_ldisc_assign(o_tty, &ld);
690 tty_set_termios_ldisc(o_tty, N_TTY);
691 }
692}
693
694/**
695 * tty_ldisc_init - ldisc setup for new tty
696 * @tty: tty being allocated
697 *
698 * Set up the line discipline objects for a newly allocated tty. Note that
699 * the tty structure is not completely set up when this call is made.
700 */
701
702void tty_ldisc_init(struct tty_struct *tty)
703{
704 struct tty_ldisc ld;
705 if (tty_ldisc_get(N_TTY, &ld) < 0)
706 panic("n_tty: init_tty");
707 tty_ldisc_assign(tty, &ld);
708}
709
710void tty_ldisc_begin(void)
711{
712 /* Setup the default TTY line discipline. */
713 (void) tty_register_ldisc(N_TTY, &tty_ldisc_N_TTY);
714}
diff --git a/drivers/char/vme_scc.c b/drivers/char/vme_scc.c
index f17ac043b551..69c5afe97f19 100644
--- a/drivers/char/vme_scc.c
+++ b/drivers/char/vme_scc.c
@@ -85,7 +85,7 @@ static irqreturn_t scc_rx_int(int irq, void *data);
85static irqreturn_t scc_stat_int(int irq, void *data); 85static irqreturn_t scc_stat_int(int irq, void *data);
86static irqreturn_t scc_spcond_int(int irq, void *data); 86static irqreturn_t scc_spcond_int(int irq, void *data);
87static void scc_setsignals(struct scc_port *port, int dtr, int rts); 87static void scc_setsignals(struct scc_port *port, int dtr, int rts);
88static void scc_break_ctl(struct tty_struct *tty, int break_state); 88static int scc_break_ctl(struct tty_struct *tty, int break_state);
89 89
90static struct tty_driver *scc_driver; 90static struct tty_driver *scc_driver;
91 91
@@ -942,7 +942,7 @@ static int scc_ioctl(struct tty_struct *tty, struct file *file,
942} 942}
943 943
944 944
945static void scc_break_ctl(struct tty_struct *tty, int break_state) 945static int scc_break_ctl(struct tty_struct *tty, int break_state)
946{ 946{
947 struct scc_port *port = (struct scc_port *)tty->driver_data; 947 struct scc_port *port = (struct scc_port *)tty->driver_data;
948 unsigned long flags; 948 unsigned long flags;
@@ -952,6 +952,7 @@ static void scc_break_ctl(struct tty_struct *tty, int break_state)
952 SCCmod(TX_CTRL_REG, ~TCR_SEND_BREAK, 952 SCCmod(TX_CTRL_REG, ~TCR_SEND_BREAK,
953 break_state ? TCR_SEND_BREAK : 0); 953 break_state ? TCR_SEND_BREAK : 0);
954 local_irq_restore(flags); 954 local_irq_restore(flags);
955 return 0;
955} 956}
956 957
957 958
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 008c38ba774f..fced1909cbba 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -45,7 +45,7 @@ config GPIO_PCA953X
45 will be called pca953x. 45 will be called pca953x.
46 46
47config GPIO_PCF857X 47config GPIO_PCF857X
48 tristate "PCF857x, PCA857x, and PCA967x I2C GPIO expanders" 48 tristate "PCF857x, PCA{85,96}7x, and MAX732[89] I2C GPIO expanders"
49 depends on I2C 49 depends on I2C
50 help 50 help
51 Say yes here to provide access to most "quasi-bidirectional" I2C 51 Say yes here to provide access to most "quasi-bidirectional" I2C
@@ -54,7 +54,8 @@ config GPIO_PCF857X
54 some of them. Compatible models include: 54 some of them. Compatible models include:
55 55
56 8 bits: pcf8574, pcf8574a, pca8574, pca8574a, 56 8 bits: pcf8574, pcf8574a, pca8574, pca8574a,
57 pca9670, pca9672, pca9674, pca9674a 57 pca9670, pca9672, pca9674, pca9674a,
58 max7328, max7329
58 59
59 16 bits: pcf8575, pcf8575c, pca8575, 60 16 bits: pcf8575, pcf8575c, pca8575,
60 pca9671, pca9673, pca9675 61 pca9671, pca9673, pca9675
@@ -69,6 +70,12 @@ config GPIO_PCF857X
69 70
70comment "SPI GPIO expanders:" 71comment "SPI GPIO expanders:"
71 72
73config GPIO_MAX7301
74 tristate "Maxim MAX7301 GPIO expander"
75 depends on SPI_MASTER
76 help
77 gpio driver for Maxim MAX7301 SPI GPIO expander.
78
72config GPIO_MCP23S08 79config GPIO_MCP23S08
73 tristate "Microchip MCP23S08 I/O expander" 80 tristate "Microchip MCP23S08 I/O expander"
74 depends on SPI_MASTER 81 depends on SPI_MASTER
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index fdde9923cf33..16e796dc5410 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -4,6 +4,7 @@ ccflags-$(CONFIG_DEBUG_GPIO) += -DDEBUG
4 4
5obj-$(CONFIG_HAVE_GPIO_LIB) += gpiolib.o 5obj-$(CONFIG_HAVE_GPIO_LIB) += gpiolib.o
6 6
7obj-$(CONFIG_GPIO_MAX7301) += max7301.o
7obj-$(CONFIG_GPIO_MCP23S08) += mcp23s08.o 8obj-$(CONFIG_GPIO_MCP23S08) += mcp23s08.o
8obj-$(CONFIG_GPIO_PCA953X) += pca953x.o 9obj-$(CONFIG_GPIO_PCA953X) += pca953x.o
9obj-$(CONFIG_GPIO_PCF857X) += pcf857x.o 10obj-$(CONFIG_GPIO_PCF857X) += pcf857x.o
diff --git a/drivers/gpio/max7301.c b/drivers/gpio/max7301.c
new file mode 100644
index 000000000000..39c795ad8312
--- /dev/null
+++ b/drivers/gpio/max7301.c
@@ -0,0 +1,339 @@
1/**
2 * drivers/gpio/max7301.c
3 *
4 * Copyright (C) 2006 Juergen Beisert, Pengutronix
5 * Copyright (C) 2008 Guennadi Liakhovetski, Pengutronix
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * The Maxim's MAX7301 device is an SPI driven GPIO expander. There are
12 * 28 GPIOs. 8 of them can trigger an interrupt. See datasheet for more
13 * details
14 * Note:
15 * - DIN must be stable at the rising edge of clock.
16 * - when writing:
17 * - always clock in 16 clocks at once
18 * - at DIN: D15 first, D0 last
19 * - D0..D7 = databyte, D8..D14 = commandbyte
20 * - D15 = low -> write command
21 * - when reading
22 * - always clock in 16 clocks at once
23 * - at DIN: D15 first, D0 last
24 * - D0..D7 = dummy, D8..D14 = register address
25 * - D15 = high -> read command
26 * - raise CS and assert it again
27 * - always clock in 16 clocks at once
28 * - at DOUT: D15 first, D0 last
29 * - D0..D7 contains the data from the first cycle
30 *
31 * The driver exports a standard gpiochip interface
32 */
33
34#include <linux/init.h>
35#include <linux/platform_device.h>
36#include <linux/mutex.h>
37#include <linux/spi/spi.h>
38#include <linux/spi/max7301.h>
39#include <linux/gpio.h>
40
41#define DRIVER_NAME "max7301"
42
43/*
44 * Pin configurations, see MAX7301 datasheet page 6
45 */
46#define PIN_CONFIG_MASK 0x03
47#define PIN_CONFIG_IN_PULLUP 0x03
48#define PIN_CONFIG_IN_WO_PULLUP 0x02
49#define PIN_CONFIG_OUT 0x01
50
51#define PIN_NUMBER 28
52
53
54/*
55 * Some registers must be read back to modify.
56 * To save time we cache them here in memory
57 */
58struct max7301 {
59 struct mutex lock;
60 u8 port_config[8]; /* field 0 is unused */
61 u32 out_level; /* cached output levels */
62 struct gpio_chip chip;
63 struct spi_device *spi;
64};
65
66/**
67 * max7301_write - Write a new register content
68 * @spi: The SPI device
69 * @reg: Register offset
70 * @val: Value to write
71 *
72 * A write to the MAX7301 means one message with one transfer
73 *
74 * Returns 0 if successful or a negative value on error
75 */
76static int max7301_write(struct spi_device *spi, unsigned int reg, unsigned int val)
77{
78 u16 word = ((reg & 0x7F) << 8) | (val & 0xFF);
79 return spi_write(spi, (const u8 *)&word, sizeof(word));
80}
81
82/**
83 * max7301_read - Read back register content
84 * @spi: The SPI device
85 * @reg: Register offset
86 *
87 * A read from the MAX7301 means two transfers; here, one message each
88 *
89 * Returns positive 8 bit value from device if successful or a
90 * negative value on error
91 */
92static int max7301_read(struct spi_device *spi, unsigned int reg)
93{
94 int ret;
95 u16 word;
96
97 word = 0x8000 | (reg << 8);
98 ret = spi_write(spi, (const u8 *)&word, sizeof(word));
99 if (ret)
100 return ret;
101 /*
102 * This relies on the fact, that a transfer with NULL tx_buf shifts out
103 * zero bytes (=NOOP for MAX7301)
104 */
105 ret = spi_read(spi, (u8 *)&word, sizeof(word));
106 if (ret)
107 return ret;
108 return word & 0xff;
109}
110
111static int max7301_direction_input(struct gpio_chip *chip, unsigned offset)
112{
113 struct max7301 *ts = container_of(chip, struct max7301, chip);
114 u8 *config;
115 int ret;
116
117 /* First 4 pins are unused in the controller */
118 offset += 4;
119
120 config = &ts->port_config[offset >> 2];
121
122 mutex_lock(&ts->lock);
123
124 /* Standard GPIO API doesn't support pull-ups, has to be extended.
125 * Hard-coding no pollup for now. */
126 *config = (*config & ~(3 << (offset & 3))) | (1 << (offset & 3));
127
128 ret = max7301_write(ts->spi, 0x08 + (offset >> 2), *config);
129
130 mutex_unlock(&ts->lock);
131
132 return ret;
133}
134
135static int __max7301_set(struct max7301 *ts, unsigned offset, int value)
136{
137 if (value) {
138 ts->out_level |= 1 << offset;
139 return max7301_write(ts->spi, 0x20 + offset, 0x01);
140 } else {
141 ts->out_level &= ~(1 << offset);
142 return max7301_write(ts->spi, 0x20 + offset, 0x00);
143 }
144}
145
146static int max7301_direction_output(struct gpio_chip *chip, unsigned offset,
147 int value)
148{
149 struct max7301 *ts = container_of(chip, struct max7301, chip);
150 u8 *config;
151 int ret;
152
153 /* First 4 pins are unused in the controller */
154 offset += 4;
155
156 config = &ts->port_config[offset >> 2];
157
158 mutex_lock(&ts->lock);
159
160 *config = (*config & ~(3 << (offset & 3))) | (1 << (offset & 3));
161
162 ret = __max7301_set(ts, offset, value);
163
164 if (!ret)
165 ret = max7301_write(ts->spi, 0x08 + (offset >> 2), *config);
166
167 mutex_unlock(&ts->lock);
168
169 return ret;
170}
171
172static int max7301_get(struct gpio_chip *chip, unsigned offset)
173{
174 struct max7301 *ts = container_of(chip, struct max7301, chip);
175 int config, level = -EINVAL;
176
177 /* First 4 pins are unused in the controller */
178 offset += 4;
179
180 mutex_lock(&ts->lock);
181
182 config = (ts->port_config[offset >> 2] >> ((offset & 3) * 2)) & 3;
183
184 switch (config) {
185 case 1:
186 /* Output: return cached level */
187 level = !!(ts->out_level & (1 << offset));
188 break;
189 case 2:
190 case 3:
191 /* Input: read out */
192 level = max7301_read(ts->spi, 0x20 + offset) & 0x01;
193 }
194 mutex_unlock(&ts->lock);
195
196 return level;
197}
198
199static void max7301_set(struct gpio_chip *chip, unsigned offset, int value)
200{
201 struct max7301 *ts = container_of(chip, struct max7301, chip);
202
203 /* First 4 pins are unused in the controller */
204 offset += 4;
205
206 mutex_lock(&ts->lock);
207
208 __max7301_set(ts, offset, value);
209
210 mutex_unlock(&ts->lock);
211}
212
213static int __devinit max7301_probe(struct spi_device *spi)
214{
215 struct max7301 *ts;
216 struct max7301_platform_data *pdata;
217 int i, ret;
218
219 pdata = spi->dev.platform_data;
220 if (!pdata || !pdata->base)
221 return -ENODEV;
222
223 /*
224 * bits_per_word cannot be configured in platform data
225 */
226 spi->bits_per_word = 16;
227
228 ret = spi_setup(spi);
229 if (ret < 0)
230 return ret;
231
232 ts = kzalloc(sizeof(struct max7301), GFP_KERNEL);
233 if (!ts)
234 return -ENOMEM;
235
236 mutex_init(&ts->lock);
237
238 dev_set_drvdata(&spi->dev, ts);
239
240 /* Power up the chip and disable IRQ output */
241 max7301_write(spi, 0x04, 0x01);
242
243 ts->spi = spi;
244
245 ts->chip.label = DRIVER_NAME,
246
247 ts->chip.direction_input = max7301_direction_input;
248 ts->chip.get = max7301_get;
249 ts->chip.direction_output = max7301_direction_output;
250 ts->chip.set = max7301_set;
251
252 ts->chip.base = pdata->base;
253 ts->chip.ngpio = PIN_NUMBER;
254 ts->chip.can_sleep = 1;
255 ts->chip.dev = &spi->dev;
256 ts->chip.owner = THIS_MODULE;
257
258 ret = gpiochip_add(&ts->chip);
259 if (ret)
260 goto exit_destroy;
261
262 /*
263 * tristate all pins in hardware and cache the
264 * register values for later use.
265 */
266 for (i = 1; i < 8; i++) {
267 int j;
268 /* 0xAA means input with internal pullup disabled */
269 max7301_write(spi, 0x08 + i, 0xAA);
270 ts->port_config[i] = 0xAA;
271 for (j = 0; j < 4; j++) {
272 int idx = ts->chip.base + (i - 1) * 4 + j;
273 ret = gpio_direction_input(idx);
274 if (ret)
275 goto exit_remove;
276 gpio_free(idx);
277 }
278 }
279 return ret;
280
281exit_remove:
282 gpiochip_remove(&ts->chip);
283exit_destroy:
284 dev_set_drvdata(&spi->dev, NULL);
285 mutex_destroy(&ts->lock);
286 kfree(ts);
287 return ret;
288}
289
290static int max7301_remove(struct spi_device *spi)
291{
292 struct max7301 *ts;
293 int ret;
294
295 ts = dev_get_drvdata(&spi->dev);
296 if (ts == NULL)
297 return -ENODEV;
298
299 dev_set_drvdata(&spi->dev, NULL);
300
301 /* Power down the chip and disable IRQ output */
302 max7301_write(spi, 0x04, 0x00);
303
304 ret = gpiochip_remove(&ts->chip);
305 if (!ret) {
306 mutex_destroy(&ts->lock);
307 kfree(ts);
308 } else
309 dev_err(&spi->dev, "Failed to remove the GPIO controller: %d\n",
310 ret);
311
312 return ret;
313}
314
315static struct spi_driver max7301_driver = {
316 .driver = {
317 .name = DRIVER_NAME,
318 .owner = THIS_MODULE,
319 },
320 .probe = max7301_probe,
321 .remove = __devexit_p(max7301_remove),
322};
323
324static int __init max7301_init(void)
325{
326 return spi_register_driver(&max7301_driver);
327}
328
329static void __exit max7301_exit(void)
330{
331 spi_unregister_driver(&max7301_driver);
332}
333
334module_init(max7301_init);
335module_exit(max7301_exit);
336
337MODULE_AUTHOR("Juergen Beisert");
338MODULE_LICENSE("GPL v2");
339MODULE_DESCRIPTION("MAX7301 SPI based GPIO-Expander");
diff --git a/drivers/gpio/pcf857x.c b/drivers/gpio/pcf857x.c
index aa6cc8b2a2bc..d25d356c4f20 100644
--- a/drivers/gpio/pcf857x.c
+++ b/drivers/gpio/pcf857x.c
@@ -37,6 +37,8 @@ static const struct i2c_device_id pcf857x_id[] = {
37 { "pca9671", 16 }, 37 { "pca9671", 16 },
38 { "pca9673", 16 }, 38 { "pca9673", 16 },
39 { "pca9675", 16 }, 39 { "pca9675", 16 },
40 { "max7328", 8 },
41 { "max7329", 8 },
40 { } 42 { }
41}; 43};
42MODULE_DEVICE_TABLE(i2c, pcf857x_id); 44MODULE_DEVICE_TABLE(i2c, pcf857x_id);
@@ -56,6 +58,7 @@ MODULE_DEVICE_TABLE(i2c, pcf857x_id);
56struct pcf857x { 58struct pcf857x {
57 struct gpio_chip chip; 59 struct gpio_chip chip;
58 struct i2c_client *client; 60 struct i2c_client *client;
61 struct mutex lock; /* protect 'out' */
59 unsigned out; /* software latch */ 62 unsigned out; /* software latch */
60}; 63};
61 64
@@ -66,9 +69,14 @@ struct pcf857x {
66static int pcf857x_input8(struct gpio_chip *chip, unsigned offset) 69static int pcf857x_input8(struct gpio_chip *chip, unsigned offset)
67{ 70{
68 struct pcf857x *gpio = container_of(chip, struct pcf857x, chip); 71 struct pcf857x *gpio = container_of(chip, struct pcf857x, chip);
72 int status;
69 73
74 mutex_lock(&gpio->lock);
70 gpio->out |= (1 << offset); 75 gpio->out |= (1 << offset);
71 return i2c_smbus_write_byte(gpio->client, gpio->out); 76 status = i2c_smbus_write_byte(gpio->client, gpio->out);
77 mutex_unlock(&gpio->lock);
78
79 return status;
72} 80}
73 81
74static int pcf857x_get8(struct gpio_chip *chip, unsigned offset) 82static int pcf857x_get8(struct gpio_chip *chip, unsigned offset)
@@ -84,12 +92,17 @@ static int pcf857x_output8(struct gpio_chip *chip, unsigned offset, int value)
84{ 92{
85 struct pcf857x *gpio = container_of(chip, struct pcf857x, chip); 93 struct pcf857x *gpio = container_of(chip, struct pcf857x, chip);
86 unsigned bit = 1 << offset; 94 unsigned bit = 1 << offset;
95 int status;
87 96
97 mutex_lock(&gpio->lock);
88 if (value) 98 if (value)
89 gpio->out |= bit; 99 gpio->out |= bit;
90 else 100 else
91 gpio->out &= ~bit; 101 gpio->out &= ~bit;
92 return i2c_smbus_write_byte(gpio->client, gpio->out); 102 status = i2c_smbus_write_byte(gpio->client, gpio->out);
103 mutex_unlock(&gpio->lock);
104
105 return status;
93} 106}
94 107
95static void pcf857x_set8(struct gpio_chip *chip, unsigned offset, int value) 108static void pcf857x_set8(struct gpio_chip *chip, unsigned offset, int value)
@@ -124,9 +137,14 @@ static int i2c_read_le16(struct i2c_client *client)
124static int pcf857x_input16(struct gpio_chip *chip, unsigned offset) 137static int pcf857x_input16(struct gpio_chip *chip, unsigned offset)
125{ 138{
126 struct pcf857x *gpio = container_of(chip, struct pcf857x, chip); 139 struct pcf857x *gpio = container_of(chip, struct pcf857x, chip);
140 int status;
127 141
142 mutex_lock(&gpio->lock);
128 gpio->out |= (1 << offset); 143 gpio->out |= (1 << offset);
129 return i2c_write_le16(gpio->client, gpio->out); 144 status = i2c_write_le16(gpio->client, gpio->out);
145 mutex_unlock(&gpio->lock);
146
147 return status;
130} 148}
131 149
132static int pcf857x_get16(struct gpio_chip *chip, unsigned offset) 150static int pcf857x_get16(struct gpio_chip *chip, unsigned offset)
@@ -142,12 +160,17 @@ static int pcf857x_output16(struct gpio_chip *chip, unsigned offset, int value)
142{ 160{
143 struct pcf857x *gpio = container_of(chip, struct pcf857x, chip); 161 struct pcf857x *gpio = container_of(chip, struct pcf857x, chip);
144 unsigned bit = 1 << offset; 162 unsigned bit = 1 << offset;
163 int status;
145 164
165 mutex_lock(&gpio->lock);
146 if (value) 166 if (value)
147 gpio->out |= bit; 167 gpio->out |= bit;
148 else 168 else
149 gpio->out &= ~bit; 169 gpio->out &= ~bit;
150 return i2c_write_le16(gpio->client, gpio->out); 170 status = i2c_write_le16(gpio->client, gpio->out);
171 mutex_unlock(&gpio->lock);
172
173 return status;
151} 174}
152 175
153static void pcf857x_set16(struct gpio_chip *chip, unsigned offset, int value) 176static void pcf857x_set16(struct gpio_chip *chip, unsigned offset, int value)
@@ -173,6 +196,8 @@ static int pcf857x_probe(struct i2c_client *client,
173 if (!gpio) 196 if (!gpio)
174 return -ENOMEM; 197 return -ENOMEM;
175 198
199 mutex_init(&gpio->lock);
200
176 gpio->chip.base = pdata->gpio_base; 201 gpio->chip.base = pdata->gpio_base;
177 gpio->chip.can_sleep = 1; 202 gpio->chip.can_sleep = 1;
178 gpio->chip.owner = THIS_MODULE; 203 gpio->chip.owner = THIS_MODULE;
diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
index 0dcfbfba9d35..871b0cbca5e4 100644
--- a/drivers/isdn/capi/capi.c
+++ b/drivers/isdn/capi/capi.c
@@ -1302,11 +1302,12 @@ static void capinc_tty_hangup(struct tty_struct *tty)
1302#endif 1302#endif
1303} 1303}
1304 1304
1305static void capinc_tty_break_ctl(struct tty_struct *tty, int state) 1305static int capinc_tty_break_ctl(struct tty_struct *tty, int state)
1306{ 1306{
1307#ifdef _DEBUG_TTYFUNCS 1307#ifdef _DEBUG_TTYFUNCS
1308 printk(KERN_DEBUG "capinc_tty_break_ctl(%d)\n", state); 1308 printk(KERN_DEBUG "capinc_tty_break_ctl(%d)\n", state);
1309#endif 1309#endif
1310 return 0;
1310} 1311}
1311 1312
1312static void capinc_tty_flush_buffer(struct tty_struct *tty) 1313static void capinc_tty_flush_buffer(struct tty_struct *tty)
diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c
index ce948b66bbd4..27f34a9f9cb7 100644
--- a/drivers/serial/8250.c
+++ b/drivers/serial/8250.c
@@ -1874,7 +1874,9 @@ static int serial8250_startup(struct uart_port *port)
1874 * the interrupt is enabled. Delays are necessary to 1874 * the interrupt is enabled. Delays are necessary to
1875 * allow register changes to become visible. 1875 * allow register changes to become visible.
1876 */ 1876 */
1877 spin_lock_irqsave(&up->port.lock, flags); 1877 spin_lock(&up->port.lock);
1878 if (up->port.flags & UPF_SHARE_IRQ)
1879 disable_irq_nosync(up->port.irq);
1878 1880
1879 wait_for_xmitr(up, UART_LSR_THRE); 1881 wait_for_xmitr(up, UART_LSR_THRE);
1880 serial_out_sync(up, UART_IER, UART_IER_THRI); 1882 serial_out_sync(up, UART_IER, UART_IER_THRI);
@@ -1886,7 +1888,9 @@ static int serial8250_startup(struct uart_port *port)
1886 iir = serial_in(up, UART_IIR); 1888 iir = serial_in(up, UART_IIR);
1887 serial_out(up, UART_IER, 0); 1889 serial_out(up, UART_IER, 0);
1888 1890
1889 spin_unlock_irqrestore(&up->port.lock, flags); 1891 if (up->port.flags & UPF_SHARE_IRQ)
1892 enable_irq(up->port.irq);
1893 spin_unlock(&up->port.lock);
1890 1894
1891 /* 1895 /*
1892 * If the interrupt is not reasserted, setup a timer to 1896 * If the interrupt is not reasserted, setup a timer to
diff --git a/drivers/serial/cpm_uart/cpm_uart_core.c b/drivers/serial/cpm_uart/cpm_uart_core.c
index abe129cc927a..93e407ee08b9 100644
--- a/drivers/serial/cpm_uart/cpm_uart_core.c
+++ b/drivers/serial/cpm_uart/cpm_uart_core.c
@@ -209,7 +209,7 @@ static void cpm_uart_int_rx(struct uart_port *port)
209 int i; 209 int i;
210 unsigned char ch; 210 unsigned char ch;
211 u8 *cp; 211 u8 *cp;
212 struct tty_struct *tty = port->info->tty; 212 struct tty_struct *tty = port->info->port.tty;
213 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; 213 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
214 cbd_t __iomem *bdp; 214 cbd_t __iomem *bdp;
215 u16 status; 215 u16 status;
diff --git a/drivers/serial/icom.c b/drivers/serial/icom.c
index 9c2df5c857cf..2b7531d9f6ab 100644
--- a/drivers/serial/icom.c
+++ b/drivers/serial/icom.c
@@ -730,7 +730,7 @@ static void xmit_interrupt(u16 port_int_reg, struct icom_port *icom_port)
730static void recv_interrupt(u16 port_int_reg, struct icom_port *icom_port) 730static void recv_interrupt(u16 port_int_reg, struct icom_port *icom_port)
731{ 731{
732 short int count, rcv_buff; 732 short int count, rcv_buff;
733 struct tty_struct *tty = icom_port->uart_port.info->tty; 733 struct tty_struct *tty = icom_port->uart_port.info->port.tty;
734 unsigned short int status; 734 unsigned short int status;
735 struct uart_icount *icount; 735 struct uart_icount *icount;
736 unsigned long offset; 736 unsigned long offset;
diff --git a/drivers/serial/samsung.c b/drivers/serial/samsung.c
index 4a3ecaa629e6..d852f83f8900 100644
--- a/drivers/serial/samsung.c
+++ b/drivers/serial/samsung.c
@@ -202,7 +202,7 @@ s3c24xx_serial_rx_chars(int irq, void *dev_id)
202{ 202{
203 struct s3c24xx_uart_port *ourport = dev_id; 203 struct s3c24xx_uart_port *ourport = dev_id;
204 struct uart_port *port = &ourport->port; 204 struct uart_port *port = &ourport->port;
205 struct tty_struct *tty = port->info->tty; 205 struct tty_struct *tty = port->info->port.tty;
206 unsigned int ufcon, ch, flag, ufstat, uerstat; 206 unsigned int ufcon, ch, flag, ufstat, uerstat;
207 int max_count = 64; 207 int max_count = 64;
208 208
diff --git a/drivers/serial/serial_core.c b/drivers/serial/serial_core.c
index 0bce1fe2c62a..f977c98cfa95 100644
--- a/drivers/serial/serial_core.c
+++ b/drivers/serial/serial_core.c
@@ -934,7 +934,7 @@ uart_tiocmset(struct tty_struct *tty, struct file *file,
934 return ret; 934 return ret;
935} 935}
936 936
937static void uart_break_ctl(struct tty_struct *tty, int break_state) 937static int uart_break_ctl(struct tty_struct *tty, int break_state)
938{ 938{
939 struct uart_state *state = tty->driver_data; 939 struct uart_state *state = tty->driver_data;
940 struct uart_port *port = state->port; 940 struct uart_port *port = state->port;
@@ -945,6 +945,7 @@ static void uart_break_ctl(struct tty_struct *tty, int break_state)
945 port->ops->break_ctl(port, break_state); 945 port->ops->break_ctl(port, break_state);
946 946
947 mutex_unlock(&state->mutex); 947 mutex_unlock(&state->mutex);
948 return 0;
948} 949}
949 950
950static int uart_do_autoconfig(struct uart_state *state) 951static int uart_do_autoconfig(struct uart_state *state)
diff --git a/drivers/serial/serial_txx9.c b/drivers/serial/serial_txx9.c
index 7ad21925869a..8fcb4c5b9a26 100644
--- a/drivers/serial/serial_txx9.c
+++ b/drivers/serial/serial_txx9.c
@@ -272,7 +272,7 @@ static void serial_txx9_initialize(struct uart_port *port)
272static inline void 272static inline void
273receive_chars(struct uart_txx9_port *up, unsigned int *status) 273receive_chars(struct uart_txx9_port *up, unsigned int *status)
274{ 274{
275 struct tty_struct *tty = up->port.info->tty; 275 struct tty_struct *tty = up->port.info->port.tty;
276 unsigned char ch; 276 unsigned char ch;
277 unsigned int disr = *status; 277 unsigned int disr = *status;
278 int max_count = 256; 278 int max_count = 256;
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 95ae6377d7e5..0725b1871f23 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -732,13 +732,16 @@ static void acm_tty_unthrottle(struct tty_struct *tty)
732 tasklet_schedule(&acm->urb_task); 732 tasklet_schedule(&acm->urb_task);
733} 733}
734 734
735static void acm_tty_break_ctl(struct tty_struct *tty, int state) 735static int acm_tty_break_ctl(struct tty_struct *tty, int state)
736{ 736{
737 struct acm *acm = tty->driver_data; 737 struct acm *acm = tty->driver_data;
738 int retval;
738 if (!ACM_READY(acm)) 739 if (!ACM_READY(acm))
739 return; 740 return -EINVAL;
740 if (acm_send_break(acm, state ? 0xffff : 0)) 741 retval = acm_send_break(acm, state ? 0xffff : 0);
742 if (retval < 0)
741 dbg("send break failed"); 743 dbg("send break failed");
744 return retval;
742} 745}
743 746
744static int acm_tty_tiocmget(struct tty_struct *tty, struct file *file) 747static int acm_tty_tiocmget(struct tty_struct *tty, struct file *file)
diff --git a/drivers/usb/serial/aircable.c b/drivers/usb/serial/aircable.c
index db6f97a93c02..79ea98c66fa8 100644
--- a/drivers/usb/serial/aircable.c
+++ b/drivers/usb/serial/aircable.c
@@ -272,7 +272,7 @@ static void aircable_read(struct work_struct *work)
272 * 64 bytes, to ensure I do not get throttled. 272 * 64 bytes, to ensure I do not get throttled.
273 * Ask USB mailing list for better aproach. 273 * Ask USB mailing list for better aproach.
274 */ 274 */
275 tty = port->tty; 275 tty = port->port.tty;
276 276
277 if (!tty) { 277 if (!tty) {
278 schedule_work(&priv->rx_work); 278 schedule_work(&priv->rx_work);
@@ -378,13 +378,14 @@ static void aircable_shutdown(struct usb_serial *serial)
378 } 378 }
379} 379}
380 380
381static int aircable_write_room(struct usb_serial_port *port) 381static int aircable_write_room(struct tty_struct *tty)
382{ 382{
383 struct usb_serial_port *port = tty->driver_data;
383 struct aircable_private *priv = usb_get_serial_port_data(port); 384 struct aircable_private *priv = usb_get_serial_port_data(port);
384 return serial_buf_data_avail(priv->tx_buf); 385 return serial_buf_data_avail(priv->tx_buf);
385} 386}
386 387
387static int aircable_write(struct usb_serial_port *port, 388static int aircable_write(struct tty_struct *tty, struct usb_serial_port *port,
388 const unsigned char *source, int count) 389 const unsigned char *source, int count)
389{ 390{
390 struct aircable_private *priv = usb_get_serial_port_data(port); 391 struct aircable_private *priv = usb_get_serial_port_data(port);
@@ -466,7 +467,7 @@ static void aircable_read_bulk_callback(struct urb *urb)
466 467
467 if (status) { 468 if (status) {
468 dbg("%s - urb status = %d", __func__, status); 469 dbg("%s - urb status = %d", __func__, status);
469 if (!port->open_count) { 470 if (!port->port.count) {
470 dbg("%s - port is closed, exiting.", __func__); 471 dbg("%s - port is closed, exiting.", __func__);
471 return; 472 return;
472 } 473 }
@@ -494,7 +495,7 @@ static void aircable_read_bulk_callback(struct urb *urb)
494 usb_serial_debug_data(debug, &port->dev, __func__, 495 usb_serial_debug_data(debug, &port->dev, __func__,
495 urb->actual_length, urb->transfer_buffer); 496 urb->actual_length, urb->transfer_buffer);
496 497
497 tty = port->tty; 498 tty = port->port.tty;
498 if (tty && urb->actual_length) { 499 if (tty && urb->actual_length) {
499 if (urb->actual_length <= 2) { 500 if (urb->actual_length <= 2) {
500 /* This is an incomplete package */ 501 /* This is an incomplete package */
@@ -528,7 +529,7 @@ static void aircable_read_bulk_callback(struct urb *urb)
528 } 529 }
529 530
530 /* Schedule the next read _if_ we are still open */ 531 /* Schedule the next read _if_ we are still open */
531 if (port->open_count) { 532 if (port->port.count) {
532 usb_fill_bulk_urb(port->read_urb, port->serial->dev, 533 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
533 usb_rcvbulkpipe(port->serial->dev, 534 usb_rcvbulkpipe(port->serial->dev,
534 port->bulk_in_endpointAddress), 535 port->bulk_in_endpointAddress),
@@ -547,8 +548,9 @@ static void aircable_read_bulk_callback(struct urb *urb)
547} 548}
548 549
549/* Based on ftdi_sio.c throttle */ 550/* Based on ftdi_sio.c throttle */
550static void aircable_throttle(struct usb_serial_port *port) 551static void aircable_throttle(struct tty_struct *tty)
551{ 552{
553 struct usb_serial_port *port = tty->driver_data;
552 struct aircable_private *priv = usb_get_serial_port_data(port); 554 struct aircable_private *priv = usb_get_serial_port_data(port);
553 unsigned long flags; 555 unsigned long flags;
554 556
@@ -560,8 +562,9 @@ static void aircable_throttle(struct usb_serial_port *port)
560} 562}
561 563
562/* Based on ftdi_sio.c unthrottle */ 564/* Based on ftdi_sio.c unthrottle */
563static void aircable_unthrottle(struct usb_serial_port *port) 565static void aircable_unthrottle(struct tty_struct *tty)
564{ 566{
567 struct usb_serial_port *port = tty->driver_data;
565 struct aircable_private *priv = usb_get_serial_port_data(port); 568 struct aircable_private *priv = usb_get_serial_port_data(port);
566 int actually_throttled; 569 int actually_throttled;
567 unsigned long flags; 570 unsigned long flags;
diff --git a/drivers/usb/serial/airprime.c b/drivers/usb/serial/airprime.c
new file mode 100644
index 000000000000..b3f1d1e82468
--- /dev/null
+++ b/drivers/usb/serial/airprime.c
@@ -0,0 +1,355 @@
1/*
2 * AirPrime CDMA Wireless Serial USB driver
3 *
4 * Copyright (C) 2005-2006 Greg Kroah-Hartman <gregkh@suse.de>
5 *
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
8 * 2 as published by the Free Software Foundation.
9 */
10
11#include <linux/kernel.h>
12#include <linux/init.h>
13#include <linux/tty.h>
14#include <linux/tty_flip.h>
15#include <linux/module.h>
16#include <linux/usb.h>
17#include <linux/usb/serial.h>
18
19static struct usb_device_id id_table [] = {
20 { USB_DEVICE(0x0c88, 0x17da) }, /* Kyocera Wireless KPC650/Passport */
21 { },
22};
23MODULE_DEVICE_TABLE(usb, id_table);
24
25#define URB_TRANSFER_BUFFER_SIZE 4096
26#define NUM_READ_URBS 4
27#define NUM_WRITE_URBS 4
28#define NUM_BULK_EPS 3
29#define MAX_BULK_EPS 6
30
31/* if overridden by the user, then use their value for the size of the
32 * read and write urbs, and the number of endpoints */
33static int buffer_size = URB_TRANSFER_BUFFER_SIZE;
34static int endpoints = NUM_BULK_EPS;
35static int debug;
36struct airprime_private {
37 spinlock_t lock;
38 int outstanding_urbs;
39 int throttled;
40 struct urb *read_urbp[NUM_READ_URBS];
41
42 /* Settings for the port */
43 int rts_state; /* Handshaking pins (outputs) */
44 int dtr_state;
45 int cts_state; /* Handshaking pins (inputs) */
46 int dsr_state;
47 int dcd_state;
48 int ri_state;
49};
50
51static int airprime_send_setup(struct usb_serial_port *port)
52{
53 struct usb_serial *serial = port->serial;
54 struct airprime_private *priv;
55
56 dbg("%s", __func__);
57
58 if (port->number != 0)
59 return 0;
60
61 priv = usb_get_serial_port_data(port);
62
63 if (port->port.tty) {
64 int val = 0;
65 if (priv->dtr_state)
66 val |= 0x01;
67 if (priv->rts_state)
68 val |= 0x02;
69
70 return usb_control_msg(serial->dev,
71 usb_rcvctrlpipe(serial->dev, 0),
72 0x22, 0x21, val, 0, NULL, 0,
73 USB_CTRL_SET_TIMEOUT);
74 }
75
76 return 0;
77}
78
79static void airprime_read_bulk_callback(struct urb *urb)
80{
81 struct usb_serial_port *port = urb->context;
82 unsigned char *data = urb->transfer_buffer;
83 struct tty_struct *tty;
84 int result;
85 int status = urb->status;
86
87 dbg("%s - port %d", __func__, port->number);
88
89 if (status) {
90 dbg("%s - nonzero read bulk status received: %d",
91 __func__, status);
92 return;
93 }
94 usb_serial_debug_data(debug, &port->dev, __func__,
95 urb->actual_length, data);
96
97 tty = port->port.tty;
98 if (tty && urb->actual_length) {
99 tty_insert_flip_string(tty, data, urb->actual_length);
100 tty_flip_buffer_push(tty);
101 }
102
103 result = usb_submit_urb(urb, GFP_ATOMIC);
104 if (result)
105 dev_err(&port->dev,
106 "%s - failed resubmitting read urb, error %d\n",
107 __func__, result);
108 return;
109}
110
111static void airprime_write_bulk_callback(struct urb *urb)
112{
113 struct usb_serial_port *port = urb->context;
114 struct airprime_private *priv = usb_get_serial_port_data(port);
115 int status = urb->status;
116 unsigned long flags;
117
118 dbg("%s - port %d", __func__, port->number);
119
120 /* free up the transfer buffer, as usb_free_urb() does not do this */
121 kfree(urb->transfer_buffer);
122
123 if (status)
124 dbg("%s - nonzero write bulk status received: %d",
125 __func__, status);
126 spin_lock_irqsave(&priv->lock, flags);
127 --priv->outstanding_urbs;
128 spin_unlock_irqrestore(&priv->lock, flags);
129
130 usb_serial_port_softint(port);
131}
132
133static int airprime_open(struct tty_struct *tty, struct usb_serial_port *port,
134 struct file *filp)
135{
136 struct airprime_private *priv = usb_get_serial_port_data(port);
137 struct usb_serial *serial = port->serial;
138 struct urb *urb;
139 char *buffer = NULL;
140 int i;
141 int result = 0;
142
143 dbg("%s - port %d", __func__, port->number);
144
145 /* initialize our private data structure if it isn't already created */
146 if (!priv) {
147 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
148 if (!priv) {
149 result = -ENOMEM;
150 goto out;
151 }
152 spin_lock_init(&priv->lock);
153 usb_set_serial_port_data(port, priv);
154 }
155
156 /* Set some sane defaults */
157 priv->rts_state = 1;
158 priv->dtr_state = 1;
159
160 for (i = 0; i < NUM_READ_URBS; ++i) {
161 buffer = kmalloc(buffer_size, GFP_KERNEL);
162 if (!buffer) {
163 dev_err(&port->dev, "%s - out of memory.\n",
164 __func__);
165 result = -ENOMEM;
166 goto errout;
167 }
168 urb = usb_alloc_urb(0, GFP_KERNEL);
169 if (!urb) {
170 kfree(buffer);
171 dev_err(&port->dev, "%s - no more urbs?\n",
172 __func__);
173 result = -ENOMEM;
174 goto errout;
175 }
176 usb_fill_bulk_urb(urb, serial->dev,
177 usb_rcvbulkpipe(serial->dev,
178 port->bulk_out_endpointAddress),
179 buffer, buffer_size,
180 airprime_read_bulk_callback, port);
181 result = usb_submit_urb(urb, GFP_KERNEL);
182 if (result) {
183 usb_free_urb(urb);
184 kfree(buffer);
185 dev_err(&port->dev,
186 "%s - failed submitting read urb %d for port %d, error %d\n",
187 __func__, i, port->number, result);
188 goto errout;
189 }
190 /* remember this urb so we can kill it when the
191 port is closed */
192 priv->read_urbp[i] = urb;
193 }
194
195 airprime_send_setup(port);
196
197 goto out;
198
199 errout:
200 /* some error happened, cancel any submitted urbs and clean up
201 anything that got allocated successfully */
202
203 while (i-- != 0) {
204 urb = priv->read_urbp[i];
205 buffer = urb->transfer_buffer;
206 usb_kill_urb(urb);
207 usb_free_urb(urb);
208 kfree(buffer);
209 }
210
211 out:
212 return result;
213}
214
215static void airprime_close(struct tty_struct *tty,
216 struct usb_serial_port *port, struct file *filp)
217{
218 struct airprime_private *priv = usb_get_serial_port_data(port);
219 int i;
220
221 dbg("%s - port %d", __func__, port->number);
222
223 priv->rts_state = 0;
224 priv->dtr_state = 0;
225
226 mutex_lock(&port->serial->disc_mutex);
227 if (!port->serial->disconnected)
228 airprime_send_setup(port);
229 mutex_unlock(&port->serial->disc_mutex);
230
231 for (i = 0; i < NUM_READ_URBS; ++i) {
232 usb_kill_urb(priv->read_urbp[i]);
233 kfree(priv->read_urbp[i]->transfer_buffer);
234 usb_free_urb(priv->read_urbp[i]);
235 }
236
237 /* free up private structure */
238 kfree(priv);
239 usb_set_serial_port_data(port, NULL);
240}
241
242static int airprime_write(struct tty_struct *tty, struct usb_serial_port *port,
243 const unsigned char *buf, int count)
244{
245 struct airprime_private *priv = usb_get_serial_port_data(port);
246 struct usb_serial *serial = port->serial;
247 struct urb *urb;
248 unsigned char *buffer;
249 unsigned long flags;
250 int status;
251 dbg("%s - port %d", __func__, port->number);
252
253 spin_lock_irqsave(&priv->lock, flags);
254 if (priv->outstanding_urbs > NUM_WRITE_URBS) {
255 spin_unlock_irqrestore(&priv->lock, flags);
256 dbg("%s - write limit hit\n", __func__);
257 return 0;
258 }
259 spin_unlock_irqrestore(&priv->lock, flags);
260 buffer = kmalloc(count, GFP_ATOMIC);
261 if (!buffer) {
262 dev_err(&port->dev, "out of memory\n");
263 return -ENOMEM;
264 }
265 urb = usb_alloc_urb(0, GFP_ATOMIC);
266 if (!urb) {
267 dev_err(&port->dev, "no more free urbs\n");
268 kfree(buffer);
269 return -ENOMEM;
270 }
271 memcpy(buffer, buf, count);
272
273 usb_serial_debug_data(debug, &port->dev, __func__, count, buffer);
274
275 usb_fill_bulk_urb(urb, serial->dev,
276 usb_sndbulkpipe(serial->dev,
277 port->bulk_out_endpointAddress),
278 buffer, count,
279 airprime_write_bulk_callback, port);
280
281 /* send it down the pipe */
282 status = usb_submit_urb(urb, GFP_ATOMIC);
283 if (status) {
284 dev_err(&port->dev,
285 "%s - usb_submit_urb(write bulk) failed with status = %d\n",
286 __func__, status);
287 count = status;
288 kfree(buffer);
289 } else {
290 spin_lock_irqsave(&priv->lock, flags);
291 ++priv->outstanding_urbs;
292 spin_unlock_irqrestore(&priv->lock, flags);
293 }
294 /* we are done with this urb, so let the host driver
295 * really free it when it is finished with it */
296 usb_free_urb(urb);
297 return count;
298}
299
300static struct usb_driver airprime_driver = {
301 .name = "airprime",
302 .probe = usb_serial_probe,
303 .disconnect = usb_serial_disconnect,
304 .id_table = id_table,
305 .no_dynamic_id = 1,
306};
307
308static struct usb_serial_driver airprime_device = {
309 .driver = {
310 .owner = THIS_MODULE,
311 .name = "airprime",
312 },
313 .usb_driver = &airprime_driver,
314 .id_table = id_table,
315 .open = airprime_open,
316 .close = airprime_close,
317 .write = airprime_write,
318};
319
320static int __init airprime_init(void)
321{
322 int retval;
323
324 airprime_device.num_ports = endpoints;
325 if (endpoints < 0 || endpoints >= MAX_BULK_EPS)
326 airprime_device.num_ports = NUM_BULK_EPS;
327
328 retval = usb_serial_register(&airprime_device);
329 if (retval)
330 return retval;
331 retval = usb_register(&airprime_driver);
332 if (retval)
333 usb_serial_deregister(&airprime_device);
334 return retval;
335}
336
337static void __exit airprime_exit(void)
338{
339 dbg("%s", __func__);
340
341 usb_deregister(&airprime_driver);
342 usb_serial_deregister(&airprime_device);
343}
344
345module_init(airprime_init);
346module_exit(airprime_exit);
347MODULE_LICENSE("GPL");
348
349module_param(debug, bool, S_IRUGO | S_IWUSR);
350MODULE_PARM_DESC(debug, "Debug enabled");
351module_param(buffer_size, int, 0);
352MODULE_PARM_DESC(buffer_size,
353 "Size of the transfer buffers in bytes (default 4096)");
354module_param(endpoints, int, 0);
355MODULE_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 77895c8f8f31..aec61880f36c 100644
--- a/drivers/usb/serial/ark3116.c
+++ b/drivers/usb/serial/ark3116.c
@@ -158,12 +158,13 @@ cleanup:
158 return -ENOMEM; 158 return -ENOMEM;
159} 159}
160 160
161static void ark3116_set_termios(struct usb_serial_port *port, 161static void ark3116_set_termios(struct tty_struct *tty,
162 struct usb_serial_port *port,
162 struct ktermios *old_termios) 163 struct ktermios *old_termios)
163{ 164{
164 struct usb_serial *serial = port->serial; 165 struct usb_serial *serial = port->serial;
165 struct ark3116_private *priv = usb_get_serial_port_data(port); 166 struct ark3116_private *priv = usb_get_serial_port_data(port);
166 struct ktermios *termios = port->tty->termios; 167 struct ktermios *termios = tty->termios;
167 unsigned int cflag = termios->c_cflag; 168 unsigned int cflag = termios->c_cflag;
168 unsigned long flags; 169 unsigned long flags;
169 int baud; 170 int baud;
@@ -177,8 +178,8 @@ static void ark3116_set_termios(struct usb_serial_port *port,
177 178
178 spin_lock_irqsave(&priv->lock, flags); 179 spin_lock_irqsave(&priv->lock, flags);
179 if (!priv->termios_initialized) { 180 if (!priv->termios_initialized) {
180 *(port->tty->termios) = tty_std_termios; 181 *termios = tty_std_termios;
181 port->tty->termios->c_cflag = B9600 | CS8 182 termios->c_cflag = B9600 | CS8
182 | CREAD | HUPCL | CLOCAL; 183 | CREAD | HUPCL | CLOCAL;
183 termios->c_ispeed = 9600; 184 termios->c_ispeed = 9600;
184 termios->c_ospeed = 9600; 185 termios->c_ospeed = 9600;
@@ -192,7 +193,7 @@ static void ark3116_set_termios(struct usb_serial_port *port,
192 buf = kmalloc(1, GFP_KERNEL); 193 buf = kmalloc(1, GFP_KERNEL);
193 if (!buf) { 194 if (!buf) {
194 dbg("error kmalloc"); 195 dbg("error kmalloc");
195 *port->tty->termios = *old_termios; 196 *termios = *old_termios;
196 return; 197 return;
197 } 198 }
198 199
@@ -243,7 +244,7 @@ static void ark3116_set_termios(struct usb_serial_port *port,
243 } 244 }
244 245
245 /* set baudrate */ 246 /* set baudrate */
246 baud = tty_get_baud_rate(port->tty); 247 baud = tty_get_baud_rate(tty);
247 248
248 switch (baud) { 249 switch (baud) {
249 case 75: 250 case 75:
@@ -262,11 +263,11 @@ static void ark3116_set_termios(struct usb_serial_port *port,
262 case 230400: 263 case 230400:
263 case 460800: 264 case 460800:
264 /* Report the resulting rate back to the caller */ 265 /* Report the resulting rate back to the caller */
265 tty_encode_baud_rate(port->tty, baud, baud); 266 tty_encode_baud_rate(tty, baud, baud);
266 break; 267 break;
267 /* set 9600 as default (if given baudrate is invalid for example) */ 268 /* set 9600 as default (if given baudrate is invalid for example) */
268 default: 269 default:
269 tty_encode_baud_rate(port->tty, 9600, 9600); 270 tty_encode_baud_rate(tty, 9600, 9600);
270 case 0: 271 case 0:
271 baud = 9600; 272 baud = 9600;
272 } 273 }
@@ -317,7 +318,8 @@ static void ark3116_set_termios(struct usb_serial_port *port,
317 return; 318 return;
318} 319}
319 320
320static int ark3116_open(struct usb_serial_port *port, struct file *filp) 321static int ark3116_open(struct tty_struct *tty, struct usb_serial_port *port,
322 struct file *filp)
321{ 323{
322 struct ktermios tmp_termios; 324 struct ktermios tmp_termios;
323 struct usb_serial *serial = port->serial; 325 struct usb_serial *serial = port->serial;
@@ -332,7 +334,7 @@ static int ark3116_open(struct usb_serial_port *port, struct file *filp)
332 return -ENOMEM; 334 return -ENOMEM;
333 } 335 }
334 336
335 result = usb_serial_generic_open(port, filp); 337 result = usb_serial_generic_open(tty, port, filp);
336 if (result) 338 if (result)
337 goto err_out; 339 goto err_out;
338 340
@@ -362,8 +364,8 @@ static int ark3116_open(struct usb_serial_port *port, struct file *filp)
362 ARK3116_RCV(serial, 124, 0xFE, 0xC0, 0x0000, 0x0006, 0xFF, buf); 364 ARK3116_RCV(serial, 124, 0xFE, 0xC0, 0x0000, 0x0006, 0xFF, buf);
363 365
364 /* initialise termios */ 366 /* initialise termios */
365 if (port->tty) 367 if (tty)
366 ark3116_set_termios(port, &tmp_termios); 368 ark3116_set_termios(tty, port, &tmp_termios);
367 369
368err_out: 370err_out:
369 kfree(buf); 371 kfree(buf);
@@ -371,9 +373,10 @@ err_out:
371 return result; 373 return result;
372} 374}
373 375
374static int ark3116_ioctl(struct usb_serial_port *port, struct file *file, 376static int ark3116_ioctl(struct tty_struct *tty, struct file *file,
375 unsigned int cmd, unsigned long arg) 377 unsigned int cmd, unsigned long arg)
376{ 378{
379 struct usb_serial_port *port = tty->driver_data;
377 struct serial_struct serstruct; 380 struct serial_struct serstruct;
378 void __user *user_arg = (void __user *)arg; 381 void __user *user_arg = (void __user *)arg;
379 382
@@ -403,8 +406,9 @@ static int ark3116_ioctl(struct usb_serial_port *port, struct file *file,
403 return -ENOIOCTLCMD; 406 return -ENOIOCTLCMD;
404} 407}
405 408
406static int ark3116_tiocmget(struct usb_serial_port *port, struct file *file) 409static int ark3116_tiocmget(struct tty_struct *tty, struct file *file)
407{ 410{
411 struct usb_serial_port *port = tty->driver_data;
408 struct usb_serial *serial = port->serial; 412 struct usb_serial *serial = port->serial;
409 char *buf; 413 char *buf;
410 char temp; 414 char temp;
diff --git a/drivers/usb/serial/belkin_sa.c b/drivers/usb/serial/belkin_sa.c
index 0a322fc53d6e..2ebe06c3405a 100644
--- a/drivers/usb/serial/belkin_sa.c
+++ b/drivers/usb/serial/belkin_sa.c
@@ -7,13 +7,14 @@
7 * This program is largely derived from work by the linux-usb group 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 8 * and associated source files. Please see the usb/serial files for
9 * individual credits and copyrights. 9 * individual credits and copyrights.
10 * 10 *
11 * This program is free software; you can redistribute it and/or modify 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 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 13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version. 14 * (at your option) any later version.
15 * 15 *
16 * See Documentation/usb/usb-serial.txt for more information on using this driver 16 * See Documentation/usb/usb-serial.txt for more information on using this
17 * driver
17 * 18 *
18 * TODO: 19 * TODO:
19 * -- Add true modem contol line query capability. Currently we track the 20 * -- Add true modem contol line query capability. Currently we track the
@@ -28,7 +29,8 @@
28 * compressed all the differnent device entries into 1. 29 * compressed all the differnent device entries into 1.
29 * 30 *
30 * 30-May-2001 gkh 31 * 30-May-2001 gkh
31 * switched from using spinlock to a semaphore, which fixes lots of problems. 32 * switched from using spinlock to a semaphore, which fixes lots of
33 * problems.
32 * 34 *
33 * 08-Apr-2001 gb 35 * 08-Apr-2001 gb
34 * - Identify version on module load. 36 * - Identify version on module load.
@@ -41,7 +43,7 @@
41 * - Added support for the old Belkin and Peracom devices. 43 * - Added support for the old Belkin and Peracom devices.
42 * - Made the port able to be opened multiple times. 44 * - Made the port able to be opened multiple times.
43 * - Added some defaults incase the line settings are things these devices 45 * - Added some defaults incase the line settings are things these devices
44 * can't support. 46 * can't support.
45 * 47 *
46 * 18-Oct-2000 William Greathouse 48 * 18-Oct-2000 William Greathouse
47 * Released into the wild (linux-usb-devel) 49 * Released into the wild (linux-usb-devel)
@@ -72,7 +74,7 @@
72#include <linux/tty_flip.h> 74#include <linux/tty_flip.h>
73#include <linux/module.h> 75#include <linux/module.h>
74#include <linux/spinlock.h> 76#include <linux/spinlock.h>
75#include <asm/uaccess.h> 77#include <linux/uaccess.h>
76#include <linux/usb.h> 78#include <linux/usb.h>
77#include <linux/usb/serial.h> 79#include <linux/usb/serial.h>
78#include "belkin_sa.h" 80#include "belkin_sa.h"
@@ -87,16 +89,19 @@ static int debug;
87#define DRIVER_DESC "USB Belkin Serial converter driver" 89#define DRIVER_DESC "USB Belkin Serial converter driver"
88 90
89/* function prototypes for a Belkin USB Serial Adapter F5U103 */ 91/* function prototypes for a Belkin USB Serial Adapter F5U103 */
90static int belkin_sa_startup (struct usb_serial *serial); 92static int belkin_sa_startup(struct usb_serial *serial);
91static void belkin_sa_shutdown (struct usb_serial *serial); 93static void belkin_sa_shutdown(struct usb_serial *serial);
92static int belkin_sa_open (struct usb_serial_port *port, struct file *filp); 94static int belkin_sa_open(struct tty_struct *tty,
93static void belkin_sa_close (struct usb_serial_port *port, struct file *filp); 95 struct usb_serial_port *port, struct file *filp);
94static void belkin_sa_read_int_callback (struct urb *urb); 96static void belkin_sa_close(struct tty_struct *tty,
95static void belkin_sa_set_termios (struct usb_serial_port *port, struct ktermios * old); 97 struct usb_serial_port *port, struct file *filp);
96static int belkin_sa_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg); 98static void belkin_sa_read_int_callback(struct urb *urb);
97static void belkin_sa_break_ctl (struct usb_serial_port *port, int break_state ); 99static void belkin_sa_set_termios(struct tty_struct *tty,
98static int belkin_sa_tiocmget (struct usb_serial_port *port, struct file *file); 100 struct usb_serial_port *port, struct ktermios * old);
99static int belkin_sa_tiocmset (struct usb_serial_port *port, struct file *file, unsigned int set, unsigned int clear); 101static void belkin_sa_break_ctl(struct tty_struct *tty, int break_state);
102static int belkin_sa_tiocmget(struct tty_struct *tty, struct file *file);
103static int belkin_sa_tiocmset(struct tty_struct *tty, struct file *file,
104 unsigned int set, unsigned int clear);
100 105
101 106
102static struct usb_device_id id_table_combined [] = { 107static struct usb_device_id id_table_combined [] = {
@@ -106,10 +111,10 @@ static struct usb_device_id id_table_combined [] = {
106 { USB_DEVICE(GOHUBS_VID, GOHUBS_PID) }, 111 { USB_DEVICE(GOHUBS_VID, GOHUBS_PID) },
107 { USB_DEVICE(GOHUBS_VID, HANDYLINK_PID) }, 112 { USB_DEVICE(GOHUBS_VID, HANDYLINK_PID) },
108 { USB_DEVICE(BELKIN_DOCKSTATION_VID, BELKIN_DOCKSTATION_PID) }, 113 { USB_DEVICE(BELKIN_DOCKSTATION_VID, BELKIN_DOCKSTATION_PID) },
109 { } /* Terminating entry */ 114 { } /* Terminating entry */
110}; 115};
111 116
112MODULE_DEVICE_TABLE (usb, id_table_combined); 117MODULE_DEVICE_TABLE(usb, id_table_combined);
113 118
114static struct usb_driver belkin_driver = { 119static struct usb_driver belkin_driver = {
115 .name = "belkin", 120 .name = "belkin",
@@ -131,8 +136,8 @@ static struct usb_serial_driver belkin_device = {
131 .num_ports = 1, 136 .num_ports = 1,
132 .open = belkin_sa_open, 137 .open = belkin_sa_open,
133 .close = belkin_sa_close, 138 .close = belkin_sa_close,
134 .read_int_callback = belkin_sa_read_int_callback, /* How we get the status info */ 139 .read_int_callback = belkin_sa_read_int_callback,
135 .ioctl = belkin_sa_ioctl, 140 /* How we get the status info */
136 .set_termios = belkin_sa_set_termios, 141 .set_termios = belkin_sa_set_termios,
137 .break_ctl = belkin_sa_break_ctl, 142 .break_ctl = belkin_sa_break_ctl,
138 .tiocmget = belkin_sa_tiocmget, 143 .tiocmget = belkin_sa_tiocmget,
@@ -160,12 +165,12 @@ struct belkin_sa_private {
160#define WDR_TIMEOUT 5000 /* default urb timeout */ 165#define WDR_TIMEOUT 5000 /* default urb timeout */
161 166
162/* assumes that struct usb_serial *serial is available */ 167/* assumes that struct usb_serial *serial is available */
163#define BSA_USB_CMD(c,v) usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), \ 168#define BSA_USB_CMD(c, v) usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), \
164 (c), BELKIN_SA_SET_REQUEST_TYPE, \ 169 (c), BELKIN_SA_SET_REQUEST_TYPE, \
165 (v), 0, NULL, 0, WDR_TIMEOUT) 170 (v), 0, NULL, 0, WDR_TIMEOUT)
166 171
167/* do some startup allocations not currently performed by usb_serial_probe() */ 172/* do some startup allocations not currently performed by usb_serial_probe() */
168static int belkin_sa_startup (struct usb_serial *serial) 173static int belkin_sa_startup(struct usb_serial *serial)
169{ 174{
170 struct usb_device *dev = serial->dev; 175 struct usb_device *dev = serial->dev;
171 struct belkin_sa_private *priv; 176 struct belkin_sa_private *priv;
@@ -173,32 +178,35 @@ static int belkin_sa_startup (struct usb_serial *serial)
173 /* allocate the private data structure */ 178 /* allocate the private data structure */
174 priv = kmalloc(sizeof(struct belkin_sa_private), GFP_KERNEL); 179 priv = kmalloc(sizeof(struct belkin_sa_private), GFP_KERNEL);
175 if (!priv) 180 if (!priv)
176 return (-1); /* error */ 181 return -1; /* error */
177 /* set initial values for control structures */ 182 /* set initial values for control structures */
178 spin_lock_init(&priv->lock); 183 spin_lock_init(&priv->lock);
179 priv->control_state = 0; 184 priv->control_state = 0;
180 priv->last_lsr = 0; 185 priv->last_lsr = 0;
181 priv->last_msr = 0; 186 priv->last_msr = 0;
182 /* see comments at top of file */ 187 /* see comments at top of file */
183 priv->bad_flow_control = (le16_to_cpu(dev->descriptor.bcdDevice) <= 0x0206) ? 1 : 0; 188 priv->bad_flow_control =
184 info("bcdDevice: %04x, bfc: %d", le16_to_cpu(dev->descriptor.bcdDevice), priv->bad_flow_control); 189 (le16_to_cpu(dev->descriptor.bcdDevice) <= 0x0206) ? 1 : 0;
190 info("bcdDevice: %04x, bfc: %d",
191 le16_to_cpu(dev->descriptor.bcdDevice),
192 priv->bad_flow_control);
185 193
186 init_waitqueue_head(&serial->port[0]->write_wait); 194 init_waitqueue_head(&serial->port[0]->write_wait);
187 usb_set_serial_port_data(serial->port[0], priv); 195 usb_set_serial_port_data(serial->port[0], priv);
188 196
189 return (0); 197 return 0;
190} 198}
191 199
192 200
193static void belkin_sa_shutdown (struct usb_serial *serial) 201static void belkin_sa_shutdown(struct usb_serial *serial)
194{ 202{
195 struct belkin_sa_private *priv; 203 struct belkin_sa_private *priv;
196 int i; 204 int i;
197 205
198 dbg ("%s", __func__); 206 dbg("%s", __func__);
199 207
200 /* stop reads and writes on all ports */ 208 /* stop reads and writes on all ports */
201 for (i=0; i < serial->num_ports; ++i) { 209 for (i = 0; i < serial->num_ports; ++i) {
202 /* My special items, the standard routines free my urbs */ 210 /* My special items, the standard routines free my urbs */
203 priv = usb_get_serial_port_data(serial->port[i]); 211 priv = usb_get_serial_port_data(serial->port[i]);
204 kfree(priv); 212 kfree(priv);
@@ -206,7 +214,8 @@ static void belkin_sa_shutdown (struct usb_serial *serial)
206} 214}
207 215
208 216
209static int belkin_sa_open (struct usb_serial_port *port, struct file *filp) 217static int belkin_sa_open(struct tty_struct *tty,
218 struct usb_serial_port *port, struct file *filp)
210{ 219{
211 int retval = 0; 220 int retval = 0;
212 221
@@ -235,7 +244,8 @@ exit:
235} /* belkin_sa_open */ 244} /* belkin_sa_open */
236 245
237 246
238static void belkin_sa_close (struct usb_serial_port *port, struct file *filp) 247static void belkin_sa_close(struct tty_struct *tty,
248 struct usb_serial_port *port, struct file *filp)
239{ 249{
240 dbg("%s port %d", __func__, port->number); 250 dbg("%s port %d", __func__, port->number);
241 251
@@ -246,7 +256,7 @@ static void belkin_sa_close (struct usb_serial_port *port, struct file *filp)
246} /* belkin_sa_close */ 256} /* belkin_sa_close */
247 257
248 258
249static void belkin_sa_read_int_callback (struct urb *urb) 259static void belkin_sa_read_int_callback(struct urb *urb)
250{ 260{
251 struct usb_serial_port *port = urb->context; 261 struct usb_serial_port *port = urb->context;
252 struct belkin_sa_private *priv; 262 struct belkin_sa_private *priv;
@@ -272,7 +282,8 @@ static void belkin_sa_read_int_callback (struct urb *urb)
272 goto exit; 282 goto exit;
273 } 283 }
274 284
275 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); 285 usb_serial_debug_data(debug, &port->dev, __func__,
286 urb->actual_length, data);
276 287
277 /* Handle known interrupt data */ 288 /* Handle known interrupt data */
278 /* ignore data[0] and data[1] */ 289 /* ignore data[0] and data[1] */
@@ -280,7 +291,7 @@ static void belkin_sa_read_int_callback (struct urb *urb)
280 priv = usb_get_serial_port_data(port); 291 priv = usb_get_serial_port_data(port);
281 spin_lock_irqsave(&priv->lock, flags); 292 spin_lock_irqsave(&priv->lock, flags);
282 priv->last_msr = data[BELKIN_SA_MSR_INDEX]; 293 priv->last_msr = data[BELKIN_SA_MSR_INDEX];
283 294
284 /* Record Control Line states */ 295 /* Record Control Line states */
285 if (priv->last_msr & BELKIN_SA_MSR_DSR) 296 if (priv->last_msr & BELKIN_SA_MSR_DSR)
286 priv->control_state |= TIOCM_DSR; 297 priv->control_state |= TIOCM_DSR;
@@ -311,7 +322,7 @@ static void belkin_sa_read_int_callback (struct urb *urb)
311 * to look in to this before committing any code. 322 * to look in to this before committing any code.
312 */ 323 */
313 if (priv->last_lsr & BELKIN_SA_LSR_ERR) { 324 if (priv->last_lsr & BELKIN_SA_LSR_ERR) {
314 tty = port->tty; 325 tty = port->port.tty;
315 /* Overrun Error */ 326 /* Overrun Error */
316 if (priv->last_lsr & BELKIN_SA_LSR_OE) { 327 if (priv->last_lsr & BELKIN_SA_LSR_OE) {
317 } 328 }
@@ -328,13 +339,14 @@ static void belkin_sa_read_int_callback (struct urb *urb)
328#endif 339#endif
329 spin_unlock_irqrestore(&priv->lock, flags); 340 spin_unlock_irqrestore(&priv->lock, flags);
330exit: 341exit:
331 retval = usb_submit_urb (urb, GFP_ATOMIC); 342 retval = usb_submit_urb(urb, GFP_ATOMIC);
332 if (retval) 343 if (retval)
333 err ("%s - usb_submit_urb failed with result %d", 344 err("%s - usb_submit_urb failed with result %d",
334 __func__, retval); 345 __func__, retval);
335} 346}
336 347
337static void belkin_sa_set_termios (struct usb_serial_port *port, struct ktermios *old_termios) 348static void belkin_sa_set_termios(struct tty_struct *tty,
349 struct usb_serial_port *port, struct ktermios *old_termios)
338{ 350{
339 struct usb_serial *serial = port->serial; 351 struct usb_serial *serial = port->serial;
340 struct belkin_sa_private *priv = usb_get_serial_port_data(port); 352 struct belkin_sa_private *priv = usb_get_serial_port_data(port);
@@ -347,8 +359,8 @@ static void belkin_sa_set_termios (struct usb_serial_port *port, struct ktermios
347 unsigned long control_state; 359 unsigned long control_state;
348 int bad_flow_control; 360 int bad_flow_control;
349 speed_t baud; 361 speed_t baud;
350 struct ktermios *termios = port->tty->termios; 362 struct ktermios *termios = tty->termios;
351 363
352 iflag = termios->c_iflag; 364 iflag = termios->c_iflag;
353 cflag = termios->c_cflag; 365 cflag = termios->c_cflag;
354 366
@@ -359,25 +371,26 @@ static void belkin_sa_set_termios (struct usb_serial_port *port, struct ktermios
359 control_state = priv->control_state; 371 control_state = priv->control_state;
360 bad_flow_control = priv->bad_flow_control; 372 bad_flow_control = priv->bad_flow_control;
361 spin_unlock_irqrestore(&priv->lock, flags); 373 spin_unlock_irqrestore(&priv->lock, flags);
362 374
363 old_iflag = old_termios->c_iflag; 375 old_iflag = old_termios->c_iflag;
364 old_cflag = old_termios->c_cflag; 376 old_cflag = old_termios->c_cflag;
365 377
366 /* Set the baud rate */ 378 /* Set the baud rate */
367 if ((cflag & CBAUD) != (old_cflag & CBAUD)) { 379 if ((cflag & CBAUD) != (old_cflag & CBAUD)) {
368 /* reassert DTR and (maybe) RTS on transition from B0 */ 380 /* reassert DTR and (maybe) RTS on transition from B0 */
369 if( (old_cflag&CBAUD) == B0 ) { 381 if ((old_cflag & CBAUD) == B0) {
370 control_state |= (TIOCM_DTR|TIOCM_RTS); 382 control_state |= (TIOCM_DTR|TIOCM_RTS);
371 if (BSA_USB_CMD(BELKIN_SA_SET_DTR_REQUEST, 1) < 0) 383 if (BSA_USB_CMD(BELKIN_SA_SET_DTR_REQUEST, 1) < 0)
372 err("Set DTR error"); 384 err("Set DTR error");
373 /* don't set RTS if using hardware flow control */ 385 /* don't set RTS if using hardware flow control */
374 if (!(old_cflag & CRTSCTS)) 386 if (!(old_cflag & CRTSCTS))
375 if (BSA_USB_CMD(BELKIN_SA_SET_RTS_REQUEST, 1) < 0) 387 if (BSA_USB_CMD(BELKIN_SA_SET_RTS_REQUEST
388 , 1) < 0)
376 err("Set RTS error"); 389 err("Set RTS error");
377 } 390 }
378 } 391 }
379 392
380 baud = tty_get_baud_rate(port->tty); 393 baud = tty_get_baud_rate(tty);
381 if (baud) { 394 if (baud) {
382 urb_value = BELKIN_SA_BAUD(baud); 395 urb_value = BELKIN_SA_BAUD(baud);
383 /* Clip to maximum speed */ 396 /* Clip to maximum speed */
@@ -387,12 +400,13 @@ static void belkin_sa_set_termios (struct usb_serial_port *port, struct ktermios
387 baud = BELKIN_SA_BAUD(urb_value); 400 baud = BELKIN_SA_BAUD(urb_value);
388 401
389 /* Report the actual baud rate back to the caller */ 402 /* Report the actual baud rate back to the caller */
390 tty_encode_baud_rate(port->tty, baud, baud); 403 tty_encode_baud_rate(tty, baud, baud);
391 if (BSA_USB_CMD(BELKIN_SA_SET_BAUDRATE_REQUEST, urb_value) < 0) 404 if (BSA_USB_CMD(BELKIN_SA_SET_BAUDRATE_REQUEST, urb_value) < 0)
392 err("Set baudrate error"); 405 err("Set baudrate error");
393 } else { 406 } else {
394 /* Disable flow control */ 407 /* Disable flow control */
395 if (BSA_USB_CMD(BELKIN_SA_SET_FLOW_CTRL_REQUEST, BELKIN_SA_FLOW_NONE) < 0) 408 if (BSA_USB_CMD(BELKIN_SA_SET_FLOW_CTRL_REQUEST,
409 BELKIN_SA_FLOW_NONE) < 0)
396 err("Disable flowcontrol error"); 410 err("Disable flowcontrol error");
397 /* Drop RTS and DTR */ 411 /* Drop RTS and DTR */
398 control_state &= ~(TIOCM_DTR | TIOCM_RTS); 412 control_state &= ~(TIOCM_DTR | TIOCM_RTS);
@@ -403,9 +417,10 @@ static void belkin_sa_set_termios (struct usb_serial_port *port, struct ktermios
403 } 417 }
404 418
405 /* set the parity */ 419 /* set the parity */
406 if( (cflag&(PARENB|PARODD)) != (old_cflag&(PARENB|PARODD)) ) { 420 if ((cflag ^ old_cflag) & (PARENB | PARODD)) {
407 if (cflag & PARENB) 421 if (cflag & PARENB)
408 urb_value = (cflag & PARODD) ? BELKIN_SA_PARITY_ODD : BELKIN_SA_PARITY_EVEN; 422 urb_value = (cflag & PARODD) ? BELKIN_SA_PARITY_ODD
423 : BELKIN_SA_PARITY_EVEN;
409 else 424 else
410 urb_value = BELKIN_SA_PARITY_NONE; 425 urb_value = BELKIN_SA_PARITY_NONE;
411 if (BSA_USB_CMD(BELKIN_SA_SET_PARITY_REQUEST, urb_value) < 0) 426 if (BSA_USB_CMD(BELKIN_SA_SET_PARITY_REQUEST, urb_value) < 0)
@@ -413,31 +428,40 @@ static void belkin_sa_set_termios (struct usb_serial_port *port, struct ktermios
413 } 428 }
414 429
415 /* set the number of data bits */ 430 /* set the number of data bits */
416 if( (cflag&CSIZE) != (old_cflag&CSIZE) ) { 431 if ((cflag & CSIZE) != (old_cflag & CSIZE)) {
417 switch (cflag & CSIZE) { 432 switch (cflag & CSIZE) {
418 case CS5: urb_value = BELKIN_SA_DATA_BITS(5); break; 433 case CS5:
419 case CS6: urb_value = BELKIN_SA_DATA_BITS(6); break; 434 urb_value = BELKIN_SA_DATA_BITS(5);
420 case CS7: urb_value = BELKIN_SA_DATA_BITS(7); break; 435 break;
421 case CS8: urb_value = BELKIN_SA_DATA_BITS(8); break; 436 case CS6:
422 default: dbg("CSIZE was not CS5-CS8, using default of 8"); 437 urb_value = BELKIN_SA_DATA_BITS(6);
423 urb_value = BELKIN_SA_DATA_BITS(8); 438 break;
424 break; 439 case CS7:
440 urb_value = BELKIN_SA_DATA_BITS(7);
441 break;
442 case CS8:
443 urb_value = BELKIN_SA_DATA_BITS(8);
444 break;
445 default: dbg("CSIZE was not CS5-CS8, using default of 8");
446 urb_value = BELKIN_SA_DATA_BITS(8);
447 break;
425 } 448 }
426 if (BSA_USB_CMD(BELKIN_SA_SET_DATA_BITS_REQUEST, urb_value) < 0) 449 if (BSA_USB_CMD(BELKIN_SA_SET_DATA_BITS_REQUEST, urb_value) < 0)
427 err("Set data bits error"); 450 err("Set data bits error");
428 } 451 }
429 452
430 /* set the number of stop bits */ 453 /* set the number of stop bits */
431 if( (cflag&CSTOPB) != (old_cflag&CSTOPB) ) { 454 if ((cflag & CSTOPB) != (old_cflag & CSTOPB)) {
432 urb_value = (cflag & CSTOPB) ? BELKIN_SA_STOP_BITS(2) : BELKIN_SA_STOP_BITS(1); 455 urb_value = (cflag & CSTOPB) ? BELKIN_SA_STOP_BITS(2)
433 if (BSA_USB_CMD(BELKIN_SA_SET_STOP_BITS_REQUEST, urb_value) < 0) 456 : BELKIN_SA_STOP_BITS(1);
457 if (BSA_USB_CMD(BELKIN_SA_SET_STOP_BITS_REQUEST,
458 urb_value) < 0)
434 err("Set stop bits error"); 459 err("Set stop bits error");
435 } 460 }
436 461
437 /* Set flow control */ 462 /* Set flow control */
438 if( (iflag&IXOFF) != (old_iflag&IXOFF) 463 if (((iflag ^ old_iflag) & (IXOFF | IXON)) ||
439 || (iflag&IXON) != (old_iflag&IXON) 464 ((cflag ^ old_cflag) & CRTSCTS)) {
440 || (cflag&CRTSCTS) != (old_cflag&CRTSCTS) ) {
441 urb_value = 0; 465 urb_value = 0;
442 if ((iflag & IXOFF) || (iflag & IXON)) 466 if ((iflag & IXOFF) || (iflag & IXON))
443 urb_value |= (BELKIN_SA_FLOW_OXON | BELKIN_SA_FLOW_IXON); 467 urb_value |= (BELKIN_SA_FLOW_OXON | BELKIN_SA_FLOW_IXON);
@@ -463,8 +487,9 @@ static void belkin_sa_set_termios (struct usb_serial_port *port, struct ktermios
463} /* belkin_sa_set_termios */ 487} /* belkin_sa_set_termios */
464 488
465 489
466static void belkin_sa_break_ctl( struct usb_serial_port *port, int break_state ) 490static void belkin_sa_break_ctl(struct tty_struct *tty, int break_state)
467{ 491{
492 struct usb_serial_port *port = tty->driver_data;
468 struct usb_serial *serial = port->serial; 493 struct usb_serial *serial = port->serial;
469 494
470 if (BSA_USB_CMD(BELKIN_SA_SET_BREAK_REQUEST, break_state ? 1 : 0) < 0) 495 if (BSA_USB_CMD(BELKIN_SA_SET_BREAK_REQUEST, break_state ? 1 : 0) < 0)
@@ -472,12 +497,13 @@ static void belkin_sa_break_ctl( struct usb_serial_port *port, int break_state )
472} 497}
473 498
474 499
475static int belkin_sa_tiocmget (struct usb_serial_port *port, struct file *file) 500static int belkin_sa_tiocmget(struct tty_struct *tty, struct file *file)
476{ 501{
502 struct usb_serial_port *port = tty->driver_data;
477 struct belkin_sa_private *priv = usb_get_serial_port_data(port); 503 struct belkin_sa_private *priv = usb_get_serial_port_data(port);
478 unsigned long control_state; 504 unsigned long control_state;
479 unsigned long flags; 505 unsigned long flags;
480 506
481 dbg("%s", __func__); 507 dbg("%s", __func__);
482 508
483 spin_lock_irqsave(&priv->lock, flags); 509 spin_lock_irqsave(&priv->lock, flags);
@@ -488,9 +514,10 @@ static int belkin_sa_tiocmget (struct usb_serial_port *port, struct file *file)
488} 514}
489 515
490 516
491static int belkin_sa_tiocmset (struct usb_serial_port *port, struct file *file, 517static int belkin_sa_tiocmset(struct tty_struct *tty, struct file *file,
492 unsigned int set, unsigned int clear) 518 unsigned int set, unsigned int clear)
493{ 519{
520 struct usb_serial_port *port = tty->driver_data;
494 struct usb_serial *serial = port->serial; 521 struct usb_serial *serial = port->serial;
495 struct belkin_sa_private *priv = usb_get_serial_port_data(port); 522 struct belkin_sa_private *priv = usb_get_serial_port_data(port);
496 unsigned long control_state; 523 unsigned long control_state;
@@ -498,7 +525,7 @@ static int belkin_sa_tiocmset (struct usb_serial_port *port, struct file *file,
498 int retval; 525 int retval;
499 int rts = 0; 526 int rts = 0;
500 int dtr = 0; 527 int dtr = 0;
501 528
502 dbg("%s", __func__); 529 dbg("%s", __func__);
503 530
504 spin_lock_irqsave(&priv->lock, flags); 531 spin_lock_irqsave(&priv->lock, flags);
@@ -540,29 +567,7 @@ exit:
540} 567}
541 568
542 569
543static int belkin_sa_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg) 570static int __init belkin_sa_init(void)
544{
545 switch (cmd) {
546 case TIOCMIWAIT:
547 /* wait for any of the 4 modem inputs (DCD,RI,DSR,CTS)*/
548 /* TODO */
549 return( 0 );
550
551 case TIOCGICOUNT:
552 /* return count of modemline transitions */
553 /* TODO */
554 return 0;
555
556 default:
557 dbg("belkin_sa_ioctl arg not supported - 0x%04x",cmd);
558 return(-ENOIOCTLCMD);
559 break;
560 }
561 return 0;
562} /* belkin_sa_ioctl */
563
564
565static int __init belkin_sa_init (void)
566{ 571{
567 int retval; 572 int retval;
568 retval = usb_serial_register(&belkin_device); 573 retval = usb_serial_register(&belkin_device);
@@ -582,17 +587,17 @@ failed_usb_serial_register:
582 587
583static void __exit belkin_sa_exit (void) 588static void __exit belkin_sa_exit (void)
584{ 589{
585 usb_deregister (&belkin_driver); 590 usb_deregister(&belkin_driver);
586 usb_serial_deregister (&belkin_device); 591 usb_serial_deregister(&belkin_device);
587} 592}
588 593
589 594
590module_init (belkin_sa_init); 595module_init(belkin_sa_init);
591module_exit (belkin_sa_exit); 596module_exit(belkin_sa_exit);
592 597
593MODULE_AUTHOR( DRIVER_AUTHOR ); 598MODULE_AUTHOR(DRIVER_AUTHOR);
594MODULE_DESCRIPTION( DRIVER_DESC ); 599MODULE_DESCRIPTION(DRIVER_DESC);
595MODULE_VERSION( DRIVER_VERSION ); 600MODULE_VERSION(DRIVER_VERSION);
596MODULE_LICENSE("GPL"); 601MODULE_LICENSE("GPL");
597 602
598module_param(debug, bool, S_IRUGO | S_IWUSR); 603module_param(debug, bool, S_IRUGO | S_IWUSR);
diff --git a/drivers/usb/serial/belkin_sa.h b/drivers/usb/serial/belkin_sa.h
index 9116b92f4622..c66a6730d38c 100644
--- a/drivers/usb/serial/belkin_sa.h
+++ b/drivers/usb/serial/belkin_sa.h
@@ -7,13 +7,14 @@
7 * This program is largely derived from work by the linux-usb group 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 8 * and associated source files. Please see the usb/serial files for
9 * individual credits and copyrights. 9 * individual credits and copyrights.
10 * 10 *
11 * This program is free software; you can redistribute it and/or modify 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 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 13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version. 14 * (at your option) any later version.
15 * 15 *
16 * See Documentation/usb/usb-serial.txt for more information on using this driver 16 * See Documentation/usb/usb-serial.txt for more information on using this
17 * driver
17 * 18 *
18 * 12-Mar-2001 gkh 19 * 12-Mar-2001 gkh
19 * Added GoHubs GO-COM232 device id. 20 * Added GoHubs GO-COM232 device id.
@@ -27,7 +28,7 @@
27 * adapter, so pardon any stupid mistakes. All of the information 28 * adapter, so pardon any stupid mistakes. All of the information
28 * I am using to write this driver was acquired by using a modified 29 * I am using to write this driver was acquired by using a modified
29 * UsbSnoop on Windows2000. 30 * UsbSnoop on Windows2000.
30 * 31 *
31 */ 32 */
32 33
33#ifndef __LINUX_USB_SERIAL_BSA_H 34#ifndef __LINUX_USB_SERIAL_BSA_H
@@ -96,20 +97,20 @@
96 97
97/* 98/*
98 * It seems that the interrupt pipe is closely modelled after the 99 * It seems that the interrupt pipe is closely modelled after the
99 * 16550 register layout. This is probably because the adapter can 100 * 16550 register layout. This is probably because the adapter can
100 * be used in a "DOS" environment to simulate a standard hardware port. 101 * be used in a "DOS" environment to simulate a standard hardware port.
101 */ 102 */
102#define BELKIN_SA_LSR_INDEX 2 /* Line Status Register */ 103#define BELKIN_SA_LSR_INDEX 2 /* Line Status Register */
103#define BELKIN_SA_LSR_RDR 0x01 /* receive data ready */ 104#define BELKIN_SA_LSR_RDR 0x01 /* receive data ready */
104#define BELKIN_SA_LSR_OE 0x02 /* overrun error */ 105#define BELKIN_SA_LSR_OE 0x02 /* overrun error */
105#define BELKIN_SA_LSR_PE 0x04 /* parity error */ 106#define BELKIN_SA_LSR_PE 0x04 /* parity error */
106#define BELKIN_SA_LSR_FE 0x08 /* framing error */ 107#define BELKIN_SA_LSR_FE 0x08 /* framing error */
107#define BELKIN_SA_LSR_BI 0x10 /* break indicator */ 108#define BELKIN_SA_LSR_BI 0x10 /* break indicator */
108#define BELKIN_SA_LSR_THE 0x20 /* transmit holding register empty */ 109#define BELKIN_SA_LSR_THE 0x20 /* tx holding register empty */
109#define BELKIN_SA_LSR_TE 0x40 /* transmit register empty */ 110#define BELKIN_SA_LSR_TE 0x40 /* transmit register empty */
110#define BELKIN_SA_LSR_ERR 0x80 /* OE | PE | FE | BI */ 111#define BELKIN_SA_LSR_ERR 0x80 /* OE | PE | FE | BI */
111 112
112#define BELKIN_SA_MSR_INDEX 3 /* Modem Status Register */ 113#define BELKIN_SA_MSR_INDEX 3 /* Modem Status Register */
113#define BELKIN_SA_MSR_DCTS 0x01 /* Delta CTS */ 114#define BELKIN_SA_MSR_DCTS 0x01 /* Delta CTS */
114#define BELKIN_SA_MSR_DDSR 0x02 /* Delta DSR */ 115#define BELKIN_SA_MSR_DDSR 0x02 /* Delta DSR */
115#define BELKIN_SA_MSR_DRI 0x04 /* Delta RI */ 116#define BELKIN_SA_MSR_DRI 0x04 /* Delta RI */
diff --git a/drivers/usb/serial/bus.c b/drivers/usb/serial/bus.c
index 0b14aea8ebd5..83bbb5bca2ef 100644
--- a/drivers/usb/serial/bus.c
+++ b/drivers/usb/serial/bus.c
@@ -15,7 +15,8 @@
15#include <linux/usb.h> 15#include <linux/usb.h>
16#include <linux/usb/serial.h> 16#include <linux/usb/serial.h>
17 17
18static int usb_serial_device_match (struct device *dev, struct device_driver *drv) 18static int usb_serial_device_match(struct device *dev,
19 struct device_driver *drv)
19{ 20{
20 struct usb_serial_driver *driver; 21 struct usb_serial_driver *driver;
21 const struct usb_serial_port *port; 22 const struct usb_serial_port *port;
@@ -46,7 +47,7 @@ static ssize_t show_port_number(struct device *dev,
46 47
47static DEVICE_ATTR(port_number, S_IRUGO, show_port_number, NULL); 48static DEVICE_ATTR(port_number, S_IRUGO, show_port_number, NULL);
48 49
49static int usb_serial_device_probe (struct device *dev) 50static int usb_serial_device_probe(struct device *dev)
50{ 51{
51 struct usb_serial_driver *driver; 52 struct usb_serial_driver *driver;
52 struct usb_serial_port *port; 53 struct usb_serial_port *port;
@@ -66,7 +67,7 @@ static int usb_serial_device_probe (struct device *dev)
66 retval = -EIO; 67 retval = -EIO;
67 goto exit; 68 goto exit;
68 } 69 }
69 retval = driver->port_probe (port); 70 retval = driver->port_probe(port);
70 module_put(driver->driver.owner); 71 module_put(driver->driver.owner);
71 if (retval) 72 if (retval)
72 goto exit; 73 goto exit;
@@ -77,8 +78,8 @@ static int usb_serial_device_probe (struct device *dev)
77 goto exit; 78 goto exit;
78 79
79 minor = port->number; 80 minor = port->number;
80 tty_register_device (usb_serial_tty_driver, minor, dev); 81 tty_register_device(usb_serial_tty_driver, minor, dev);
81 dev_info(&port->serial->dev->dev, 82 dev_info(&port->serial->dev->dev,
82 "%s converter now attached to ttyUSB%d\n", 83 "%s converter now attached to ttyUSB%d\n",
83 driver->description, minor); 84 driver->description, minor);
84 85
@@ -86,7 +87,7 @@ exit:
86 return retval; 87 return retval;
87} 88}
88 89
89static int usb_serial_device_remove (struct device *dev) 90static int usb_serial_device_remove(struct device *dev)
90{ 91{
91 struct usb_serial_driver *driver; 92 struct usb_serial_driver *driver;
92 struct usb_serial_port *port; 93 struct usb_serial_port *port;
@@ -94,9 +95,8 @@ static int usb_serial_device_remove (struct device *dev)
94 int minor; 95 int minor;
95 96
96 port = to_usb_serial_port(dev); 97 port = to_usb_serial_port(dev);
97 if (!port) { 98 if (!port)
98 return -ENODEV; 99 return -ENODEV;
99 }
100 100
101 device_remove_file(&port->dev, &dev_attr_port_number); 101 device_remove_file(&port->dev, &dev_attr_port_number);
102 102
@@ -107,12 +107,12 @@ static int usb_serial_device_remove (struct device *dev)
107 retval = -EIO; 107 retval = -EIO;
108 goto exit; 108 goto exit;
109 } 109 }
110 retval = driver->port_remove (port); 110 retval = driver->port_remove(port);
111 module_put(driver->driver.owner); 111 module_put(driver->driver.owner);
112 } 112 }
113exit: 113exit:
114 minor = port->number; 114 minor = port->number;
115 tty_unregister_device (usb_serial_tty_driver, minor); 115 tty_unregister_device(usb_serial_tty_driver, minor);
116 dev_info(dev, "%s converter now disconnected from ttyUSB%d\n", 116 dev_info(dev, "%s converter now disconnected from ttyUSB%d\n",
117 driver->description, minor); 117 driver->description, minor);
118 118
diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c
index 1f7c86bd8297..f61e3ca64305 100644
--- a/drivers/usb/serial/ch341.c
+++ b/drivers/usb/serial/ch341.c
@@ -232,7 +232,8 @@ error: kfree(priv);
232} 232}
233 233
234/* open this device, set default parameters */ 234/* open this device, set default parameters */
235static int ch341_open(struct usb_serial_port *port, struct file *filp) 235static int ch341_open(struct tty_struct *tty, struct usb_serial_port *port,
236 struct file *filp)
236{ 237{
237 struct usb_serial *serial = port->serial; 238 struct usb_serial *serial = port->serial;
238 struct ch341_private *priv = usb_get_serial_port_data(serial->port[0]); 239 struct ch341_private *priv = usb_get_serial_port_data(serial->port[0]);
@@ -256,7 +257,7 @@ static int ch341_open(struct usb_serial_port *port, struct file *filp)
256 if (r) 257 if (r)
257 goto out; 258 goto out;
258 259
259 r = usb_serial_generic_open(port, filp); 260 r = usb_serial_generic_open(tty, port, filp);
260 261
261out: return r; 262out: return r;
262} 263}
@@ -264,11 +265,10 @@ out: return r;
264/* Old_termios contains the original termios settings and 265/* Old_termios contains the original termios settings and
265 * tty->termios contains the new setting to be used. 266 * tty->termios contains the new setting to be used.
266 */ 267 */
267static void ch341_set_termios(struct usb_serial_port *port, 268static void ch341_set_termios(struct tty_struct *tty,
268 struct ktermios *old_termios) 269 struct usb_serial_port *port, struct ktermios *old_termios)
269{ 270{
270 struct ch341_private *priv = usb_get_serial_port_data(port); 271 struct ch341_private *priv = usb_get_serial_port_data(port);
271 struct tty_struct *tty = port->tty;
272 unsigned baud_rate; 272 unsigned baud_rate;
273 273
274 dbg("ch341_set_termios()"); 274 dbg("ch341_set_termios()");
diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
index 201184c3fb87..7b74238ad1c7 100644
--- a/drivers/usb/serial/console.c
+++ b/drivers/usb/serial/console.c
@@ -6,7 +6,7 @@
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
8 * 2 as published by the Free Software Foundation. 8 * 2 as published by the Free Software Foundation.
9 * 9 *
10 * Thanks to Randy Dunlap for the original version of this code. 10 * Thanks to Randy Dunlap for the original version of this code.
11 * 11 *
12 */ 12 */
@@ -67,7 +67,7 @@ static int usb_console_setup(struct console *co, char *options)
67 struct tty_struct *tty = NULL; 67 struct tty_struct *tty = NULL;
68 struct ktermios *termios = NULL, dummy; 68 struct ktermios *termios = NULL, dummy;
69 69
70 dbg ("%s", __func__); 70 dbg("%s", __func__);
71 71
72 if (options) { 72 if (options) {
73 baud = simple_strtoul(options, NULL, 10); 73 baud = simple_strtoul(options, NULL, 10);
@@ -81,55 +81,27 @@ static int usb_console_setup(struct console *co, char *options)
81 if (*s) 81 if (*s)
82 doflow = (*s++ == 'r'); 82 doflow = (*s++ == 'r');
83 } 83 }
84
85 /* Sane default */
86 if (baud == 0)
87 baud = 9600;
84 88
85 /* build a cflag setting */
86 switch (baud) {
87 case 1200:
88 cflag |= B1200;
89 break;
90 case 2400:
91 cflag |= B2400;
92 break;
93 case 4800:
94 cflag |= B4800;
95 break;
96 case 19200:
97 cflag |= B19200;
98 break;
99 case 38400:
100 cflag |= B38400;
101 break;
102 case 57600:
103 cflag |= B57600;
104 break;
105 case 115200:
106 cflag |= B115200;
107 break;
108 case 9600:
109 default:
110 cflag |= B9600;
111 /*
112 * Set this to a sane value to prevent a divide error
113 */
114 baud = 9600;
115 break;
116 }
117 switch (bits) { 89 switch (bits) {
118 case 7: 90 case 7:
119 cflag |= CS7; 91 cflag |= CS7;
120 break; 92 break;
121 default: 93 default:
122 case 8: 94 case 8:
123 cflag |= CS8; 95 cflag |= CS8;
124 break; 96 break;
125 } 97 }
126 switch (parity) { 98 switch (parity) {
127 case 'o': case 'O': 99 case 'o': case 'O':
128 cflag |= PARODD; 100 cflag |= PARODD;
129 break; 101 break;
130 case 'e': case 'E': 102 case 'e': case 'E':
131 cflag |= PARENB; 103 cflag |= PARENB;
132 break; 104 break;
133 } 105 }
134 co->cflag = cflag; 106 co->cflag = cflag;
135 107
@@ -140,17 +112,17 @@ static int usb_console_setup(struct console *co, char *options)
140 serial = usb_serial_get_by_index(co->index); 112 serial = usb_serial_get_by_index(co->index);
141 if (serial == NULL) { 113 if (serial == NULL) {
142 /* no device is connected yet, sorry :( */ 114 /* no device is connected yet, sorry :( */
143 err ("No USB device connected to ttyUSB%i", co->index); 115 err("No USB device connected to ttyUSB%i", co->index);
144 return -ENODEV; 116 return -ENODEV;
145 } 117 }
146 118
147 port = serial->port[0]; 119 port = serial->port[0];
148 port->tty = NULL; 120 port->port.tty = NULL;
149 121
150 info->port = port; 122 info->port = port;
151 123
152 ++port->open_count; 124 ++port->port.count;
153 if (port->open_count == 1) { 125 if (port->port.count == 1) {
154 if (serial->type->set_termios) { 126 if (serial->type->set_termios) {
155 /* 127 /*
156 * allocate a fake tty so the driver can initialize 128 * allocate a fake tty so the driver can initialize
@@ -171,15 +143,15 @@ static int usb_console_setup(struct console *co, char *options)
171 } 143 }
172 memset(&dummy, 0, sizeof(struct ktermios)); 144 memset(&dummy, 0, sizeof(struct ktermios));
173 tty->termios = termios; 145 tty->termios = termios;
174 port->tty = tty; 146 port->port.tty = tty;
175 } 147 }
176 148
177 /* only call the device specific open if this 149 /* only call the device specific open if this
178 * is the first time the port is opened */ 150 * is the first time the port is opened */
179 if (serial->type->open) 151 if (serial->type->open)
180 retval = serial->type->open(port, NULL); 152 retval = serial->type->open(NULL, port, NULL);
181 else 153 else
182 retval = usb_serial_generic_open(port, NULL); 154 retval = usb_serial_generic_open(NULL, port, NULL);
183 155
184 if (retval) { 156 if (retval) {
185 err("could not open USB console port"); 157 err("could not open USB console port");
@@ -188,9 +160,10 @@ static int usb_console_setup(struct console *co, char *options)
188 160
189 if (serial->type->set_termios) { 161 if (serial->type->set_termios) {
190 termios->c_cflag = cflag; 162 termios->c_cflag = cflag;
191 serial->type->set_termios(port, &dummy); 163 tty_termios_encode_baud_rate(termios, baud, baud);
164 serial->type->set_termios(NULL, port, &dummy);
192 165
193 port->tty = NULL; 166 port->port.tty = NULL;
194 kfree(termios); 167 kfree(termios);
195 kfree(tty); 168 kfree(tty);
196 } 169 }
@@ -203,15 +176,16 @@ out:
203 return retval; 176 return retval;
204free_termios: 177free_termios:
205 kfree(termios); 178 kfree(termios);
206 port->tty = NULL; 179 port->port.tty = NULL;
207free_tty: 180free_tty:
208 kfree(tty); 181 kfree(tty);
209reset_open_count: 182reset_open_count:
210 port->open_count = 0; 183 port->port.count = 0;
211goto out; 184goto out;
212} 185}
213 186
214static void usb_console_write(struct console *co, const char *buf, unsigned count) 187static void usb_console_write(struct console *co,
188 const char *buf, unsigned count)
215{ 189{
216 static struct usbcons_info *info = &usbcons_info; 190 static struct usbcons_info *info = &usbcons_info;
217 struct usb_serial_port *port = info->port; 191 struct usb_serial_port *port = info->port;
@@ -227,8 +201,8 @@ static void usb_console_write(struct console *co, const char *buf, unsigned coun
227 201
228 dbg("%s - port %d, %d byte(s)", __func__, port->number, count); 202 dbg("%s - port %d, %d byte(s)", __func__, port->number, count);
229 203
230 if (!port->open_count) { 204 if (!port->port.count) {
231 dbg ("%s - port not opened", __func__); 205 dbg("%s - port not opened", __func__);
232 return; 206 return;
233 } 207 }
234 208
@@ -236,26 +210,29 @@ static void usb_console_write(struct console *co, const char *buf, unsigned coun
236 unsigned int i; 210 unsigned int i;
237 unsigned int lf; 211 unsigned int lf;
238 /* search for LF so we can insert CR if necessary */ 212 /* search for LF so we can insert CR if necessary */
239 for (i=0, lf=0 ; i < count ; i++) { 213 for (i = 0, lf = 0 ; i < count ; i++) {
240 if (*(buf + i) == 10) { 214 if (*(buf + i) == 10) {
241 lf = 1; 215 lf = 1;
242 i++; 216 i++;
243 break; 217 break;
244 } 218 }
245 } 219 }
246 /* pass on to the driver specific version of this function if it is available */ 220 /* pass on to the driver specific version of this function if
221 it is available */
247 if (serial->type->write) 222 if (serial->type->write)
248 retval = serial->type->write(port, buf, i); 223 retval = serial->type->write(NULL, port, buf, i);
249 else 224 else
250 retval = usb_serial_generic_write(port, buf, i); 225 retval = usb_serial_generic_write(NULL, port, buf, i);
251 dbg("%s - return value : %d", __func__, retval); 226 dbg("%s - return value : %d", __func__, retval);
252 if (lf) { 227 if (lf) {
253 /* append CR after LF */ 228 /* append CR after LF */
254 unsigned char cr = 13; 229 unsigned char cr = 13;
255 if (serial->type->write) 230 if (serial->type->write)
256 retval = serial->type->write(port, &cr, 1); 231 retval = serial->type->write(NULL,
232 port, &cr, 1);
257 else 233 else
258 retval = usb_serial_generic_write(port, &cr, 1); 234 retval = usb_serial_generic_write(NULL,
235 port, &cr, 1);
259 dbg("%s - return value : %d", __func__, retval); 236 dbg("%s - return value : %d", __func__, retval);
260 } 237 }
261 buf += i; 238 buf += i;
@@ -273,18 +250,19 @@ static struct console usbcons = {
273 250
274void usb_serial_console_disconnect(struct usb_serial *serial) 251void usb_serial_console_disconnect(struct usb_serial *serial)
275{ 252{
276 if (serial && serial->port && serial->port[0] && serial->port[0] == usbcons_info.port) { 253 if (serial && serial->port && serial->port[0]
254 && serial->port[0] == usbcons_info.port) {
277 usb_serial_console_exit(); 255 usb_serial_console_exit();
278 usb_serial_put(serial); 256 usb_serial_put(serial);
279 } 257 }
280} 258}
281 259
282void usb_serial_console_init (int serial_debug, int minor) 260void usb_serial_console_init(int serial_debug, int minor)
283{ 261{
284 debug = serial_debug; 262 debug = serial_debug;
285 263
286 if (minor == 0) { 264 if (minor == 0) {
287 /* 265 /*
288 * Call register_console() if this is the first device plugged 266 * Call register_console() if this is the first device plugged
289 * in. If we call it earlier, then the callback to 267 * in. If we call it earlier, then the callback to
290 * console_setup() will fail, as there is not a device seen by 268 * console_setup() will fail, as there is not a device seen by
@@ -293,21 +271,21 @@ void usb_serial_console_init (int serial_debug, int minor)
293 /* 271 /*
294 * Register console. 272 * Register console.
295 * NOTES: 273 * NOTES:
296 * console_setup() is called (back) immediately (from register_console). 274 * console_setup() is called (back) immediately (from
297 * console_write() is called immediately from register_console iff 275 * register_console). console_write() is called immediately
298 * CON_PRINTBUFFER is set in flags. 276 * from register_console iff CON_PRINTBUFFER is set in flags.
299 */ 277 */
300 dbg ("registering the USB serial console."); 278 dbg("registering the USB serial console.");
301 register_console(&usbcons); 279 register_console(&usbcons);
302 } 280 }
303} 281}
304 282
305void usb_serial_console_exit (void) 283void usb_serial_console_exit(void)
306{ 284{
307 if (usbcons_info.port) { 285 if (usbcons_info.port) {
308 unregister_console(&usbcons); 286 unregister_console(&usbcons);
309 if (usbcons_info.port->open_count) 287 if (usbcons_info.port->port.count)
310 usbcons_info.port->open_count--; 288 usbcons_info.port->port.count--;
311 usbcons_info.port = NULL; 289 usbcons_info.port = NULL;
312 } 290 }
313} 291}
diff --git a/drivers/usb/serial/cp2101.c b/drivers/usb/serial/cp2101.c
index 2bc5576c443a..442cba69cce5 100644
--- a/drivers/usb/serial/cp2101.c
+++ b/drivers/usb/serial/cp2101.c
@@ -25,7 +25,7 @@
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/moduleparam.h> 26#include <linux/moduleparam.h>
27#include <linux/usb.h> 27#include <linux/usb.h>
28#include <asm/uaccess.h> 28#include <linux/uaccess.h>
29#include <linux/usb/serial.h> 29#include <linux/usb/serial.h>
30 30
31/* 31/*
@@ -37,17 +37,20 @@
37/* 37/*
38 * Function Prototypes 38 * Function Prototypes
39 */ 39 */
40static int cp2101_open(struct usb_serial_port*, struct file*); 40static int cp2101_open(struct tty_struct *, struct usb_serial_port *,
41static void cp2101_cleanup(struct usb_serial_port*); 41 struct file *);
42static void cp2101_close(struct usb_serial_port*, struct file*); 42static void cp2101_cleanup(struct usb_serial_port *);
43static void cp2101_get_termios(struct usb_serial_port*); 43static void cp2101_close(struct tty_struct *, struct usb_serial_port *,
44static void cp2101_set_termios(struct usb_serial_port*, struct ktermios*); 44 struct file*);
45static int cp2101_tiocmget (struct usb_serial_port *, struct file *); 45static void cp2101_get_termios(struct tty_struct *);
46static int cp2101_tiocmset (struct usb_serial_port *, struct file *, 46static void cp2101_set_termios(struct tty_struct *, struct usb_serial_port *,
47 struct ktermios*);
48static int cp2101_tiocmget(struct tty_struct *, struct file *);
49static int cp2101_tiocmset(struct tty_struct *, struct file *,
47 unsigned int, unsigned int); 50 unsigned int, unsigned int);
48static void cp2101_break_ctl(struct usb_serial_port*, int); 51static void cp2101_break_ctl(struct tty_struct *, int);
49static int cp2101_startup (struct usb_serial *); 52static int cp2101_startup(struct usb_serial *);
50static void cp2101_shutdown(struct usb_serial*); 53static void cp2101_shutdown(struct usb_serial *);
51 54
52 55
53static int debug; 56static int debug;
@@ -93,7 +96,7 @@ static struct usb_device_id id_table [] = {
93 { } /* Terminating Entry */ 96 { } /* Terminating Entry */
94}; 97};
95 98
96MODULE_DEVICE_TABLE (usb, id_table); 99MODULE_DEVICE_TABLE(usb, id_table);
97 100
98static struct usb_driver cp2101_driver = { 101static struct usb_driver cp2101_driver = {
99 .name = "cp2101", 102 .name = "cp2101",
@@ -182,7 +185,7 @@ static struct usb_serial_driver cp2101_device = {
182 * 'data' is a pointer to a pre-allocated array of integers large 185 * 'data' is a pointer to a pre-allocated array of integers large
183 * enough to hold 'size' bytes (with 4 bytes to each integer) 186 * enough to hold 'size' bytes (with 4 bytes to each integer)
184 */ 187 */
185static int cp2101_get_config(struct usb_serial_port* port, u8 request, 188static int cp2101_get_config(struct usb_serial_port *port, u8 request,
186 unsigned int *data, int size) 189 unsigned int *data, int size)
187{ 190{
188 struct usb_serial *serial = port->serial; 191 struct usb_serial *serial = port->serial;
@@ -202,12 +205,12 @@ static int cp2101_get_config(struct usb_serial_port* port, u8 request,
202 request++; 205 request++;
203 206
204 /* Issue the request, attempting to read 'size' bytes */ 207 /* Issue the request, attempting to read 'size' bytes */
205 result = usb_control_msg (serial->dev,usb_rcvctrlpipe (serial->dev, 0), 208 result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
206 request, REQTYPE_DEVICE_TO_HOST, 0x0000, 209 request, REQTYPE_DEVICE_TO_HOST, 0x0000,
207 0, buf, size, 300); 210 0, buf, size, 300);
208 211
209 /* Convert data into an array of integers */ 212 /* Convert data into an array of integers */
210 for (i=0; i<length; i++) 213 for (i = 0; i < length; i++)
211 data[i] = le32_to_cpu(buf[i]); 214 data[i] = le32_to_cpu(buf[i]);
212 215
213 kfree(buf); 216 kfree(buf);
@@ -228,7 +231,7 @@ static int cp2101_get_config(struct usb_serial_port* port, u8 request,
228 * Values less than 16 bits wide are sent directly 231 * Values less than 16 bits wide are sent directly
229 * 'size' is specified in bytes. 232 * 'size' is specified in bytes.
230 */ 233 */
231static int cp2101_set_config(struct usb_serial_port* port, u8 request, 234static int cp2101_set_config(struct usb_serial_port *port, u8 request,
232 unsigned int *data, int size) 235 unsigned int *data, int size)
233{ 236{
234 struct usb_serial *serial = port->serial; 237 struct usb_serial *serial = port->serial;
@@ -250,12 +253,12 @@ static int cp2101_set_config(struct usb_serial_port* port, u8 request,
250 buf[i] = cpu_to_le32(data[i]); 253 buf[i] = cpu_to_le32(data[i]);
251 254
252 if (size > 2) { 255 if (size > 2) {
253 result = usb_control_msg (serial->dev, 256 result = usb_control_msg(serial->dev,
254 usb_sndctrlpipe(serial->dev, 0), 257 usb_sndctrlpipe(serial->dev, 0),
255 request, REQTYPE_HOST_TO_DEVICE, 0x0000, 258 request, REQTYPE_HOST_TO_DEVICE, 0x0000,
256 0, buf, size, 300); 259 0, buf, size, 300);
257 } else { 260 } else {
258 result = usb_control_msg (serial->dev, 261 result = usb_control_msg(serial->dev,
259 usb_sndctrlpipe(serial->dev, 0), 262 usb_sndctrlpipe(serial->dev, 0),
260 request, REQTYPE_HOST_TO_DEVICE, data[0], 263 request, REQTYPE_HOST_TO_DEVICE, data[0],
261 0, NULL, 0, 300); 264 0, NULL, 0, 300);
@@ -271,7 +274,7 @@ static int cp2101_set_config(struct usb_serial_port* port, u8 request,
271 } 274 }
272 275
273 /* Single data value */ 276 /* Single data value */
274 result = usb_control_msg (serial->dev, 277 result = usb_control_msg(serial->dev,
275 usb_sndctrlpipe(serial->dev, 0), 278 usb_sndctrlpipe(serial->dev, 0),
276 request, REQTYPE_HOST_TO_DEVICE, data[0], 279 request, REQTYPE_HOST_TO_DEVICE, data[0],
277 0, NULL, 0, 300); 280 0, NULL, 0, 300);
@@ -283,13 +286,14 @@ static int cp2101_set_config(struct usb_serial_port* port, u8 request,
283 * Convenience function for calling cp2101_set_config on single data values 286 * Convenience function for calling cp2101_set_config on single data values
284 * without requiring an integer pointer 287 * without requiring an integer pointer
285 */ 288 */
286static inline int cp2101_set_config_single(struct usb_serial_port* port, 289static inline int cp2101_set_config_single(struct usb_serial_port *port,
287 u8 request, unsigned int data) 290 u8 request, unsigned int data)
288{ 291{
289 return cp2101_set_config(port, request, &data, 2); 292 return cp2101_set_config(port, request, &data, 2);
290} 293}
291 294
292static int cp2101_open (struct usb_serial_port *port, struct file *filp) 295static int cp2101_open(struct tty_struct *tty, struct usb_serial_port *port,
296 struct file *filp)
293{ 297{
294 struct usb_serial *serial = port->serial; 298 struct usb_serial *serial = port->serial;
295 int result; 299 int result;
@@ -303,7 +307,7 @@ static int cp2101_open (struct usb_serial_port *port, struct file *filp)
303 } 307 }
304 308
305 /* Start reading from the device */ 309 /* Start reading from the device */
306 usb_fill_bulk_urb (port->read_urb, serial->dev, 310 usb_fill_bulk_urb(port->read_urb, serial->dev,
307 usb_rcvbulkpipe(serial->dev, 311 usb_rcvbulkpipe(serial->dev,
308 port->bulk_in_endpointAddress), 312 port->bulk_in_endpointAddress),
309 port->read_urb->transfer_buffer, 313 port->read_urb->transfer_buffer,
@@ -318,15 +322,15 @@ static int cp2101_open (struct usb_serial_port *port, struct file *filp)
318 } 322 }
319 323
320 /* Configure the termios structure */ 324 /* Configure the termios structure */
321 cp2101_get_termios(port); 325 cp2101_get_termios(tty);
322 326
323 /* Set the DTR and RTS pins low */ 327 /* Set the DTR and RTS pins low */
324 cp2101_tiocmset(port, NULL, TIOCM_DTR | TIOCM_RTS, 0); 328 cp2101_tiocmset(tty, NULL, TIOCM_DTR | TIOCM_RTS, 0);
325 329
326 return 0; 330 return 0;
327} 331}
328 332
329static void cp2101_cleanup (struct usb_serial_port *port) 333static void cp2101_cleanup(struct usb_serial_port *port)
330{ 334{
331 struct usb_serial *serial = port->serial; 335 struct usb_serial *serial = port->serial;
332 336
@@ -341,7 +345,8 @@ static void cp2101_cleanup (struct usb_serial_port *port)
341 } 345 }
342} 346}
343 347
344static void cp2101_close (struct usb_serial_port *port, struct file * filp) 348static void cp2101_close(struct tty_struct *tty, struct usb_serial_port *port,
349 struct file *filp)
345{ 350{
346 dbg("%s - port %d", __func__, port->number); 351 dbg("%s - port %d", __func__, port->number);
347 352
@@ -362,19 +367,15 @@ static void cp2101_close (struct usb_serial_port *port, struct file * filp)
362 * from the device, corrects any unsupported values, and configures the 367 * from the device, corrects any unsupported values, and configures the
363 * termios structure to reflect the state of the device 368 * termios structure to reflect the state of the device
364 */ 369 */
365static void cp2101_get_termios (struct usb_serial_port *port) 370static void cp2101_get_termios (struct tty_struct *tty)
366{ 371{
372 struct usb_serial_port *port = tty->driver_data;
367 unsigned int cflag, modem_ctl[4]; 373 unsigned int cflag, modem_ctl[4];
368 unsigned int baud; 374 unsigned int baud;
369 unsigned int bits; 375 unsigned int bits;
370 376
371 dbg("%s - port %d", __func__, port->number); 377 dbg("%s - port %d", __func__, port->number);
372 378
373 if (!port->tty || !port->tty->termios) {
374 dbg("%s - no tty structures", __func__);
375 return;
376 }
377
378 cp2101_get_config(port, CP2101_BAUDRATE, &baud, 2); 379 cp2101_get_config(port, CP2101_BAUDRATE, &baud, 2);
379 /* Convert to baudrate */ 380 /* Convert to baudrate */
380 if (baud) 381 if (baud)
@@ -382,104 +383,102 @@ static void cp2101_get_termios (struct usb_serial_port *port)
382 383
383 dbg("%s - baud rate = %d", __func__, baud); 384 dbg("%s - baud rate = %d", __func__, baud);
384 385
385 tty_encode_baud_rate(port->tty, baud, baud); 386 tty_encode_baud_rate(tty, baud, baud);
386 cflag = port->tty->termios->c_cflag; 387 cflag = tty->termios->c_cflag;
387 388
388 cp2101_get_config(port, CP2101_BITS, &bits, 2); 389 cp2101_get_config(port, CP2101_BITS, &bits, 2);
389 cflag &= ~CSIZE; 390 cflag &= ~CSIZE;
390 switch(bits & BITS_DATA_MASK) { 391 switch (bits & BITS_DATA_MASK) {
391 case BITS_DATA_5: 392 case BITS_DATA_5:
392 dbg("%s - data bits = 5", __func__); 393 dbg("%s - data bits = 5", __func__);
393 cflag |= CS5; 394 cflag |= CS5;
394 break; 395 break;
395 case BITS_DATA_6: 396 case BITS_DATA_6:
396 dbg("%s - data bits = 6", __func__); 397 dbg("%s - data bits = 6", __func__);
397 cflag |= CS6; 398 cflag |= CS6;
398 break; 399 break;
399 case BITS_DATA_7: 400 case BITS_DATA_7:
400 dbg("%s - data bits = 7", __func__); 401 dbg("%s - data bits = 7", __func__);
401 cflag |= CS7; 402 cflag |= CS7;
402 break; 403 break;
403 case BITS_DATA_8: 404 case BITS_DATA_8:
404 dbg("%s - data bits = 8", __func__); 405 dbg("%s - data bits = 8", __func__);
405 cflag |= CS8; 406 cflag |= CS8;
406 break; 407 break;
407 case BITS_DATA_9: 408 case BITS_DATA_9:
408 dbg("%s - data bits = 9 (not supported, " 409 dbg("%s - data bits = 9 (not supported, using 8 data bits)",
409 "using 8 data bits)", __func__); 410 __func__);
410 cflag |= CS8; 411 cflag |= CS8;
411 bits &= ~BITS_DATA_MASK; 412 bits &= ~BITS_DATA_MASK;
412 bits |= BITS_DATA_8; 413 bits |= BITS_DATA_8;
413 cp2101_set_config(port, CP2101_BITS, &bits, 2); 414 cp2101_set_config(port, CP2101_BITS, &bits, 2);
414 break; 415 break;
415 default: 416 default:
416 dbg("%s - Unknown number of data bits, " 417 dbg("%s - Unknown number of data bits, using 8", __func__);
417 "using 8", __func__); 418 cflag |= CS8;
418 cflag |= CS8; 419 bits &= ~BITS_DATA_MASK;
419 bits &= ~BITS_DATA_MASK; 420 bits |= BITS_DATA_8;
420 bits |= BITS_DATA_8; 421 cp2101_set_config(port, CP2101_BITS, &bits, 2);
421 cp2101_set_config(port, CP2101_BITS, &bits, 2); 422 break;
422 break;
423 } 423 }
424 424
425 switch(bits & BITS_PARITY_MASK) { 425 switch (bits & BITS_PARITY_MASK) {
426 case BITS_PARITY_NONE: 426 case BITS_PARITY_NONE:
427 dbg("%s - parity = NONE", __func__); 427 dbg("%s - parity = NONE", __func__);
428 cflag &= ~PARENB; 428 cflag &= ~PARENB;
429 break; 429 break;
430 case BITS_PARITY_ODD: 430 case BITS_PARITY_ODD:
431 dbg("%s - parity = ODD", __func__); 431 dbg("%s - parity = ODD", __func__);
432 cflag |= (PARENB|PARODD); 432 cflag |= (PARENB|PARODD);
433 break; 433 break;
434 case BITS_PARITY_EVEN: 434 case BITS_PARITY_EVEN:
435 dbg("%s - parity = EVEN", __func__); 435 dbg("%s - parity = EVEN", __func__);
436 cflag &= ~PARODD; 436 cflag &= ~PARODD;
437 cflag |= PARENB; 437 cflag |= PARENB;
438 break; 438 break;
439 case BITS_PARITY_MARK: 439 case BITS_PARITY_MARK:
440 dbg("%s - parity = MARK (not supported, " 440 dbg("%s - parity = MARK (not supported, disabling parity)",
441 "disabling parity)", __func__); 441 __func__);
442 cflag &= ~PARENB; 442 cflag &= ~PARENB;
443 bits &= ~BITS_PARITY_MASK; 443 bits &= ~BITS_PARITY_MASK;
444 cp2101_set_config(port, CP2101_BITS, &bits, 2); 444 cp2101_set_config(port, CP2101_BITS, &bits, 2);
445 break; 445 break;
446 case BITS_PARITY_SPACE: 446 case BITS_PARITY_SPACE:
447 dbg("%s - parity = SPACE (not supported, " 447 dbg("%s - parity = SPACE (not supported, disabling parity)",
448 "disabling parity)", __func__); 448 __func__);
449 cflag &= ~PARENB; 449 cflag &= ~PARENB;
450 bits &= ~BITS_PARITY_MASK; 450 bits &= ~BITS_PARITY_MASK;
451 cp2101_set_config(port, CP2101_BITS, &bits, 2); 451 cp2101_set_config(port, CP2101_BITS, &bits, 2);
452 break; 452 break;
453 default: 453 default:
454 dbg("%s - Unknown parity mode, " 454 dbg("%s - Unknown parity mode, disabling parity", __func__);
455 "disabling parity", __func__); 455 cflag &= ~PARENB;
456 cflag &= ~PARENB; 456 bits &= ~BITS_PARITY_MASK;
457 bits &= ~BITS_PARITY_MASK; 457 cp2101_set_config(port, CP2101_BITS, &bits, 2);
458 cp2101_set_config(port, CP2101_BITS, &bits, 2); 458 break;
459 break;
460 } 459 }
461 460
462 cflag &= ~CSTOPB; 461 cflag &= ~CSTOPB;
463 switch(bits & BITS_STOP_MASK) { 462 switch (bits & BITS_STOP_MASK) {
464 case BITS_STOP_1: 463 case BITS_STOP_1:
465 dbg("%s - stop bits = 1", __func__); 464 dbg("%s - stop bits = 1", __func__);
466 break; 465 break;
467 case BITS_STOP_1_5: 466 case BITS_STOP_1_5:
468 dbg("%s - stop bits = 1.5 (not supported, " 467 dbg("%s - stop bits = 1.5 (not supported, using 1 stop bit)",
469 "using 1 stop bit)", __func__); 468 __func__);
470 bits &= ~BITS_STOP_MASK; 469 bits &= ~BITS_STOP_MASK;
471 cp2101_set_config(port, CP2101_BITS, &bits, 2); 470 cp2101_set_config(port, CP2101_BITS, &bits, 2);
472 break; 471 break;
473 case BITS_STOP_2: 472 case BITS_STOP_2:
474 dbg("%s - stop bits = 2", __func__); 473 dbg("%s - stop bits = 2", __func__);
475 cflag |= CSTOPB; 474 cflag |= CSTOPB;
476 break; 475 break;
477 default: 476 default:
478 dbg("%s - Unknown number of stop bits, " 477 dbg("%s - Unknown number of stop bits, using 1 stop bit",
479 "using 1 stop bit", __func__); 478 __func__);
480 bits &= ~BITS_STOP_MASK; 479 bits &= ~BITS_STOP_MASK;
481 cp2101_set_config(port, CP2101_BITS, &bits, 2); 480 cp2101_set_config(port, CP2101_BITS, &bits, 2);
482 break; 481 break;
483 } 482 }
484 483
485 cp2101_get_config(port, CP2101_MODEMCTL, modem_ctl, 16); 484 cp2101_get_config(port, CP2101_MODEMCTL, modem_ctl, 16);
@@ -491,11 +490,11 @@ static void cp2101_get_termios (struct usb_serial_port *port)
491 cflag &= ~CRTSCTS; 490 cflag &= ~CRTSCTS;
492 } 491 }
493 492
494 port->tty->termios->c_cflag = cflag; 493 tty->termios->c_cflag = cflag;
495} 494}
496 495
497static void cp2101_set_termios (struct usb_serial_port *port, 496static void cp2101_set_termios(struct tty_struct *tty,
498 struct ktermios *old_termios) 497 struct usb_serial_port *port, struct ktermios *old_termios)
499{ 498{
500 unsigned int cflag, old_cflag; 499 unsigned int cflag, old_cflag;
501 unsigned int baud = 0, bits; 500 unsigned int baud = 0, bits;
@@ -503,43 +502,41 @@ static void cp2101_set_termios (struct usb_serial_port *port,
503 502
504 dbg("%s - port %d", __func__, port->number); 503 dbg("%s - port %d", __func__, port->number);
505 504
506 if (!port->tty || !port->tty->termios) { 505 if (!tty)
507 dbg("%s - no tty structures", __func__);
508 return; 506 return;
509 }
510 port->tty->termios->c_cflag &= ~CMSPAR;
511 507
512 cflag = port->tty->termios->c_cflag; 508 tty->termios->c_cflag &= ~CMSPAR;
509 cflag = tty->termios->c_cflag;
513 old_cflag = old_termios->c_cflag; 510 old_cflag = old_termios->c_cflag;
514 baud = tty_get_baud_rate(port->tty); 511 baud = tty_get_baud_rate(tty);
515 512
516 /* If the baud rate is to be updated*/ 513 /* If the baud rate is to be updated*/
517 if (baud != tty_termios_baud_rate(old_termios)) { 514 if (baud != tty_termios_baud_rate(old_termios)) {
518 switch (baud) { 515 switch (baud) {
519 case 0: 516 case 0:
520 case 600: 517 case 600:
521 case 1200: 518 case 1200:
522 case 1800: 519 case 1800:
523 case 2400: 520 case 2400:
524 case 4800: 521 case 4800:
525 case 7200: 522 case 7200:
526 case 9600: 523 case 9600:
527 case 14400: 524 case 14400:
528 case 19200: 525 case 19200:
529 case 28800: 526 case 28800:
530 case 38400: 527 case 38400:
531 case 55854: 528 case 55854:
532 case 57600: 529 case 57600:
533 case 115200: 530 case 115200:
534 case 127117: 531 case 127117:
535 case 230400: 532 case 230400:
536 case 460800: 533 case 460800:
537 case 921600: 534 case 921600:
538 case 3686400: 535 case 3686400:
539 break; 536 break;
540 default: 537 default:
541 baud = 9600; 538 baud = 9600;
542 break; 539 break;
543 } 540 }
544 541
545 if (baud) { 542 if (baud) {
@@ -554,35 +551,35 @@ static void cp2101_set_termios (struct usb_serial_port *port,
554 } 551 }
555 } 552 }
556 /* Report back the resulting baud rate */ 553 /* Report back the resulting baud rate */
557 tty_encode_baud_rate(port->tty, baud, baud); 554 tty_encode_baud_rate(tty, baud, baud);
558 555
559 /* If the number of data bits is to be updated */ 556 /* If the number of data bits is to be updated */
560 if ((cflag & CSIZE) != (old_cflag & CSIZE)) { 557 if ((cflag & CSIZE) != (old_cflag & CSIZE)) {
561 cp2101_get_config(port, CP2101_BITS, &bits, 2); 558 cp2101_get_config(port, CP2101_BITS, &bits, 2);
562 bits &= ~BITS_DATA_MASK; 559 bits &= ~BITS_DATA_MASK;
563 switch (cflag & CSIZE) { 560 switch (cflag & CSIZE) {
564 case CS5: 561 case CS5:
565 bits |= BITS_DATA_5; 562 bits |= BITS_DATA_5;
566 dbg("%s - data bits = 5", __func__); 563 dbg("%s - data bits = 5", __func__);
567 break; 564 break;
568 case CS6: 565 case CS6:
569 bits |= BITS_DATA_6; 566 bits |= BITS_DATA_6;
570 dbg("%s - data bits = 6", __func__); 567 dbg("%s - data bits = 6", __func__);
571 break; 568 break;
572 case CS7: 569 case CS7:
573 bits |= BITS_DATA_7; 570 bits |= BITS_DATA_7;
574 dbg("%s - data bits = 7", __func__); 571 dbg("%s - data bits = 7", __func__);
575 break; 572 break;
576 case CS8: 573 case CS8:
577 bits |= BITS_DATA_8; 574 bits |= BITS_DATA_8;
578 dbg("%s - data bits = 8", __func__); 575 dbg("%s - data bits = 8", __func__);
579 break; 576 break;
580 /*case CS9: 577 /*case CS9:
581 bits |= BITS_DATA_9; 578 bits |= BITS_DATA_9;
582 dbg("%s - data bits = 9", __func__); 579 dbg("%s - data bits = 9", __func__);
583 break;*/ 580 break;*/
584 default: 581 default:
585 dev_err(&port->dev, "cp2101 driver does not " 582 dev_err(&port->dev, "cp2101 driver does not "
586 "support the number of bits requested," 583 "support the number of bits requested,"
587 " using 8 bit mode\n"); 584 " using 8 bit mode\n");
588 bits |= BITS_DATA_8; 585 bits |= BITS_DATA_8;
@@ -651,9 +648,10 @@ static void cp2101_set_termios (struct usb_serial_port *port,
651 648
652} 649}
653 650
654static int cp2101_tiocmset (struct usb_serial_port *port, struct file *file, 651static int cp2101_tiocmset (struct tty_struct *tty, struct file *file,
655 unsigned int set, unsigned int clear) 652 unsigned int set, unsigned int clear)
656{ 653{
654 struct usb_serial_port *port = tty->driver_data;
657 unsigned int control = 0; 655 unsigned int control = 0;
658 656
659 dbg("%s - port %d", __func__, port->number); 657 dbg("%s - port %d", __func__, port->number);
@@ -681,8 +679,9 @@ static int cp2101_tiocmset (struct usb_serial_port *port, struct file *file,
681 679
682} 680}
683 681
684static int cp2101_tiocmget (struct usb_serial_port *port, struct file *file) 682static int cp2101_tiocmget (struct tty_struct *tty, struct file *file)
685{ 683{
684 struct usb_serial_port *port = tty->driver_data;
686 unsigned int control; 685 unsigned int control;
687 int result; 686 int result;
688 687
@@ -702,8 +701,9 @@ static int cp2101_tiocmget (struct usb_serial_port *port, struct file *file)
702 return result; 701 return result;
703} 702}
704 703
705static void cp2101_break_ctl (struct usb_serial_port *port, int break_state) 704static void cp2101_break_ctl (struct tty_struct *tty, int break_state)
706{ 705{
706 struct usb_serial_port *port = tty->driver_data;
707 unsigned int state; 707 unsigned int state;
708 708
709 dbg("%s - port %d", __func__, port->number); 709 dbg("%s - port %d", __func__, port->number);
@@ -712,30 +712,29 @@ static void cp2101_break_ctl (struct usb_serial_port *port, int break_state)
712 else 712 else
713 state = BREAK_ON; 713 state = BREAK_ON;
714 dbg("%s - turning break %s", __func__, 714 dbg("%s - turning break %s", __func__,
715 state==BREAK_OFF ? "off" : "on"); 715 state == BREAK_OFF ? "off" : "on");
716 cp2101_set_config(port, CP2101_BREAK, &state, 2); 716 cp2101_set_config(port, CP2101_BREAK, &state, 2);
717} 717}
718 718
719static int cp2101_startup (struct usb_serial *serial) 719static int cp2101_startup(struct usb_serial *serial)
720{ 720{
721 /* CP2101 buffers behave strangely unless device is reset */ 721 /* CP2101 buffers behave strangely unless device is reset */
722 usb_reset_device(serial->dev); 722 usb_reset_device(serial->dev);
723 return 0; 723 return 0;
724} 724}
725 725
726static void cp2101_shutdown (struct usb_serial *serial) 726static void cp2101_shutdown(struct usb_serial *serial)
727{ 727{
728 int i; 728 int i;
729 729
730 dbg("%s", __func__); 730 dbg("%s", __func__);
731 731
732 /* Stop reads and writes on all ports */ 732 /* Stop reads and writes on all ports */
733 for (i=0; i < serial->num_ports; ++i) { 733 for (i = 0; i < serial->num_ports; ++i)
734 cp2101_cleanup(serial->port[i]); 734 cp2101_cleanup(serial->port[i]);
735 }
736} 735}
737 736
738static int __init cp2101_init (void) 737static int __init cp2101_init(void)
739{ 738{
740 int retval; 739 int retval;
741 740
@@ -755,10 +754,10 @@ static int __init cp2101_init (void)
755 return 0; 754 return 0;
756} 755}
757 756
758static void __exit cp2101_exit (void) 757static void __exit cp2101_exit(void)
759{ 758{
760 usb_deregister (&cp2101_driver); 759 usb_deregister(&cp2101_driver);
761 usb_serial_deregister (&cp2101_device); 760 usb_serial_deregister(&cp2101_device);
762} 761}
763 762
764module_init(cp2101_init); 763module_init(cp2101_init);
diff --git a/drivers/usb/serial/cyberjack.c b/drivers/usb/serial/cyberjack.c
index c164e2cf2752..b4d72351cb96 100644
--- a/drivers/usb/serial/cyberjack.c
+++ b/drivers/usb/serial/cyberjack.c
@@ -37,7 +37,7 @@
37#include <linux/tty_flip.h> 37#include <linux/tty_flip.h>
38#include <linux/module.h> 38#include <linux/module.h>
39#include <linux/spinlock.h> 39#include <linux/spinlock.h>
40#include <asm/uaccess.h> 40#include <linux/uaccess.h>
41#include <linux/usb.h> 41#include <linux/usb.h>
42#include <linux/usb/serial.h> 42#include <linux/usb/serial.h>
43 43
@@ -57,22 +57,25 @@ static int debug;
57#define CYBERJACK_PRODUCT_ID 0x0100 57#define CYBERJACK_PRODUCT_ID 0x0100
58 58
59/* Function prototypes */ 59/* Function prototypes */
60static int cyberjack_startup (struct usb_serial *serial); 60static int cyberjack_startup(struct usb_serial *serial);
61static void cyberjack_shutdown (struct usb_serial *serial); 61static void cyberjack_shutdown(struct usb_serial *serial);
62static int cyberjack_open (struct usb_serial_port *port, struct file *filp); 62static int cyberjack_open(struct tty_struct *tty,
63static void cyberjack_close (struct usb_serial_port *port, struct file *filp); 63 struct usb_serial_port *port, struct file *filp);
64static int cyberjack_write (struct usb_serial_port *port, const unsigned char *buf, int count); 64static void cyberjack_close(struct tty_struct *tty,
65static int cyberjack_write_room( struct usb_serial_port *port ); 65 struct usb_serial_port *port, struct file *filp);
66static void cyberjack_read_int_callback (struct urb *urb); 66static int cyberjack_write(struct tty_struct *tty,
67static void cyberjack_read_bulk_callback (struct urb *urb); 67 struct usb_serial_port *port, const unsigned char *buf, int count);
68static void cyberjack_write_bulk_callback (struct urb *urb); 68static int cyberjack_write_room(struct tty_struct *tty);
69static void cyberjack_read_int_callback(struct urb *urb);
70static void cyberjack_read_bulk_callback(struct urb *urb);
71static void cyberjack_write_bulk_callback(struct urb *urb);
69 72
70static struct usb_device_id id_table [] = { 73static struct usb_device_id id_table [] = {
71 { USB_DEVICE(CYBERJACK_VENDOR_ID, CYBERJACK_PRODUCT_ID) }, 74 { USB_DEVICE(CYBERJACK_VENDOR_ID, CYBERJACK_PRODUCT_ID) },
72 { } /* Terminating entry */ 75 { } /* Terminating entry */
73}; 76};
74 77
75MODULE_DEVICE_TABLE (usb, id_table); 78MODULE_DEVICE_TABLE(usb, id_table);
76 79
77static struct usb_driver cyberjack_driver = { 80static struct usb_driver cyberjack_driver = {
78 .name = "cyberjack", 81 .name = "cyberjack",
@@ -111,7 +114,7 @@ struct cyberjack_private {
111}; 114};
112 115
113/* do some startup allocations not currently performed by usb_serial_probe() */ 116/* do some startup allocations not currently performed by usb_serial_probe() */
114static int cyberjack_startup (struct usb_serial *serial) 117static int cyberjack_startup(struct usb_serial *serial)
115{ 118{
116 struct cyberjack_private *priv; 119 struct cyberjack_private *priv;
117 int i; 120 int i;
@@ -135,20 +138,20 @@ static int cyberjack_startup (struct usb_serial *serial)
135 for (i = 0; i < serial->num_ports; ++i) { 138 for (i = 0; i < serial->num_ports; ++i) {
136 int result; 139 int result;
137 serial->port[i]->interrupt_in_urb->dev = serial->dev; 140 serial->port[i]->interrupt_in_urb->dev = serial->dev;
138 result = usb_submit_urb(serial->port[i]->interrupt_in_urb, 141 result = usb_submit_urb(serial->port[i]->interrupt_in_urb,
139 GFP_KERNEL); 142 GFP_KERNEL);
140 if (result) 143 if (result)
141 err(" usb_submit_urb(read int) failed"); 144 err(" usb_submit_urb(read int) failed");
142 dbg("%s - usb_submit_urb(int urb)", __func__); 145 dbg("%s - usb_submit_urb(int urb)", __func__);
143 } 146 }
144 147
145 return( 0 ); 148 return 0;
146} 149}
147 150
148static void cyberjack_shutdown (struct usb_serial *serial) 151static void cyberjack_shutdown(struct usb_serial *serial)
149{ 152{
150 int i; 153 int i;
151 154
152 dbg("%s", __func__); 155 dbg("%s", __func__);
153 156
154 for (i = 0; i < serial->num_ports; ++i) { 157 for (i = 0; i < serial->num_ports; ++i) {
@@ -158,8 +161,9 @@ static void cyberjack_shutdown (struct usb_serial *serial)
158 usb_set_serial_port_data(serial->port[i], NULL); 161 usb_set_serial_port_data(serial->port[i], NULL);
159 } 162 }
160} 163}
161 164
162static int cyberjack_open (struct usb_serial_port *port, struct file *filp) 165static int cyberjack_open(struct tty_struct *tty,
166 struct usb_serial_port *port, struct file *filp)
163{ 167{
164 struct cyberjack_private *priv; 168 struct cyberjack_private *priv;
165 unsigned long flags; 169 unsigned long flags;
@@ -167,14 +171,15 @@ static int cyberjack_open (struct usb_serial_port *port, struct file *filp)
167 171
168 dbg("%s - port %d", __func__, port->number); 172 dbg("%s - port %d", __func__, port->number);
169 173
170 dbg("%s - usb_clear_halt", __func__ ); 174 dbg("%s - usb_clear_halt", __func__);
171 usb_clear_halt(port->serial->dev, port->write_urb->pipe); 175 usb_clear_halt(port->serial->dev, port->write_urb->pipe);
172 176
173 /* force low_latency on so that our tty_push actually forces 177 /* force low_latency on so that our tty_push actually forces
174 * the data through, otherwise it is scheduled, and with high 178 * the data through, otherwise it is scheduled, and with high
175 * data rates (like with OHCI) data can get lost. 179 * data rates (like with OHCI) data can get lost.
176 */ 180 */
177 port->tty->low_latency = 1; 181 if (tty)
182 tty->low_latency = 1;
178 183
179 priv = usb_get_serial_port_data(port); 184 priv = usb_get_serial_port_data(port);
180 spin_lock_irqsave(&priv->lock, flags); 185 spin_lock_irqsave(&priv->lock, flags);
@@ -186,7 +191,8 @@ static int cyberjack_open (struct usb_serial_port *port, struct file *filp)
186 return result; 191 return result;
187} 192}
188 193
189static void cyberjack_close (struct usb_serial_port *port, struct file *filp) 194static void cyberjack_close(struct tty_struct *tty,
195 struct usb_serial_port *port, struct file *filp)
190{ 196{
191 dbg("%s - port %d", __func__, port->number); 197 dbg("%s - port %d", __func__, port->number);
192 198
@@ -197,7 +203,8 @@ static void cyberjack_close (struct usb_serial_port *port, struct file *filp)
197 } 203 }
198} 204}
199 205
200static int cyberjack_write (struct usb_serial_port *port, const unsigned char *buf, int count) 206static int cyberjack_write(struct tty_struct *tty,
207 struct usb_serial_port *port, const unsigned char *buf, int count)
201{ 208{
202 struct usb_serial *serial = port->serial; 209 struct usb_serial *serial = port->serial;
203 struct cyberjack_private *priv = usb_get_serial_port_data(port); 210 struct cyberjack_private *priv = usb_get_serial_port_data(port);
@@ -223,7 +230,7 @@ static int cyberjack_write (struct usb_serial_port *port, const unsigned char *b
223 230
224 spin_lock_irqsave(&priv->lock, flags); 231 spin_lock_irqsave(&priv->lock, flags);
225 232
226 if( (count+priv->wrfilled) > sizeof(priv->wrbuf) ) { 233 if (count+priv->wrfilled > sizeof(priv->wrbuf)) {
227 /* To much data for buffer. Reset buffer. */ 234 /* To much data for buffer. Reset buffer. */
228 priv->wrfilled = 0; 235 priv->wrfilled = 0;
229 port->write_urb_busy = 0; 236 port->write_urb_busy = 0;
@@ -232,42 +239,43 @@ static int cyberjack_write (struct usb_serial_port *port, const unsigned char *b
232 } 239 }
233 240
234 /* Copy data */ 241 /* Copy data */
235 memcpy (priv->wrbuf+priv->wrfilled, buf, count); 242 memcpy(priv->wrbuf + priv->wrfilled, buf, count);
236 243
237 usb_serial_debug_data(debug, &port->dev, __func__, count, 244 usb_serial_debug_data(debug, &port->dev, __func__, count,
238 priv->wrbuf+priv->wrfilled); 245 priv->wrbuf + priv->wrfilled);
239 priv->wrfilled += count; 246 priv->wrfilled += count;
240 247
241 if( priv->wrfilled >= 3 ) { 248 if (priv->wrfilled >= 3) {
242 wrexpected = ((int)priv->wrbuf[2]<<8)+priv->wrbuf[1]+3; 249 wrexpected = ((int)priv->wrbuf[2]<<8)+priv->wrbuf[1]+3;
243 dbg("%s - expected data: %d", __func__, wrexpected); 250 dbg("%s - expected data: %d", __func__, wrexpected);
244 } else { 251 } else
245 wrexpected = sizeof(priv->wrbuf); 252 wrexpected = sizeof(priv->wrbuf);
246 }
247 253
248 if( priv->wrfilled >= wrexpected ) { 254 if (priv->wrfilled >= wrexpected) {
249 /* We have enough data to begin transmission */ 255 /* We have enough data to begin transmission */
250 int length; 256 int length;
251 257
252 dbg("%s - transmitting data (frame 1)", __func__); 258 dbg("%s - transmitting data (frame 1)", __func__);
253 length = (wrexpected > port->bulk_out_size) ? port->bulk_out_size : wrexpected; 259 length = (wrexpected > port->bulk_out_size) ?
260 port->bulk_out_size : wrexpected;
254 261
255 memcpy (port->write_urb->transfer_buffer, priv->wrbuf, length ); 262 memcpy(port->write_urb->transfer_buffer, priv->wrbuf, length);
256 priv->wrsent=length; 263 priv->wrsent = length;
257 264
258 /* set up our urb */ 265 /* set up our urb */
259 usb_fill_bulk_urb(port->write_urb, serial->dev, 266 usb_fill_bulk_urb(port->write_urb, serial->dev,
260 usb_sndbulkpipe(serial->dev, port->bulk_out_endpointAddress), 267 usb_sndbulkpipe(serial->dev, port->bulk_out_endpointAddress),
261 port->write_urb->transfer_buffer, length, 268 port->write_urb->transfer_buffer, length,
262 ((serial->type->write_bulk_callback) ? 269 ((serial->type->write_bulk_callback) ?
263 serial->type->write_bulk_callback : 270 serial->type->write_bulk_callback :
264 cyberjack_write_bulk_callback), 271 cyberjack_write_bulk_callback),
265 port); 272 port);
266 273
267 /* send the data out the bulk port */ 274 /* send the data out the bulk port */
268 result = usb_submit_urb(port->write_urb, GFP_ATOMIC); 275 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
269 if (result) { 276 if (result) {
270 err("%s - failed submitting write urb, error %d", __func__, result); 277 err("%s - failed submitting write urb, error %d",
278 __func__, result);
271 /* Throw away data. No better idea what to do with it. */ 279 /* Throw away data. No better idea what to do with it. */
272 priv->wrfilled = 0; 280 priv->wrfilled = 0;
273 priv->wrsent = 0; 281 priv->wrsent = 0;
@@ -276,12 +284,12 @@ static int cyberjack_write (struct usb_serial_port *port, const unsigned char *b
276 return 0; 284 return 0;
277 } 285 }
278 286
279 dbg("%s - priv->wrsent=%d", __func__,priv->wrsent); 287 dbg("%s - priv->wrsent=%d", __func__, priv->wrsent);
280 dbg("%s - priv->wrfilled=%d", __func__,priv->wrfilled); 288 dbg("%s - priv->wrfilled=%d", __func__, priv->wrfilled);
281 289
282 if( priv->wrsent>=priv->wrfilled ) { 290 if (priv->wrsent >= priv->wrfilled) {
283 dbg("%s - buffer cleaned", __func__); 291 dbg("%s - buffer cleaned", __func__);
284 memset( priv->wrbuf, 0, sizeof(priv->wrbuf) ); 292 memset(priv->wrbuf, 0, sizeof(priv->wrbuf));
285 priv->wrfilled = 0; 293 priv->wrfilled = 0;
286 priv->wrsent = 0; 294 priv->wrsent = 0;
287 } 295 }
@@ -289,16 +297,16 @@ static int cyberjack_write (struct usb_serial_port *port, const unsigned char *b
289 297
290 spin_unlock_irqrestore(&priv->lock, flags); 298 spin_unlock_irqrestore(&priv->lock, flags);
291 299
292 return (count); 300 return count;
293} 301}
294 302
295static int cyberjack_write_room( struct usb_serial_port *port ) 303static int cyberjack_write_room(struct tty_struct *tty)
296{ 304{
297 /* FIXME: .... */ 305 /* FIXME: .... */
298 return CYBERJACK_LOCAL_BUF_SIZE; 306 return CYBERJACK_LOCAL_BUF_SIZE;
299} 307}
300 308
301static void cyberjack_read_int_callback( struct urb *urb ) 309static void cyberjack_read_int_callback(struct urb *urb)
302{ 310{
303 struct usb_serial_port *port = urb->context; 311 struct usb_serial_port *port = urb->context;
304 struct cyberjack_private *priv = usb_get_serial_port_data(port); 312 struct cyberjack_private *priv = usb_get_serial_port_data(port);
@@ -312,10 +320,11 @@ static void cyberjack_read_int_callback( struct urb *urb )
312 if (status) 320 if (status)
313 return; 321 return;
314 322
315 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); 323 usb_serial_debug_data(debug, &port->dev, __func__,
324 urb->actual_length, data);
316 325
317 /* React only to interrupts signaling a bulk_in transfer */ 326 /* React only to interrupts signaling a bulk_in transfer */
318 if( (urb->actual_length == 4) && (data[0] == 0x01) ) { 327 if (urb->actual_length == 4 && data[0] == 0x01) {
319 short old_rdtodo; 328 short old_rdtodo;
320 329
321 /* This is a announcement of coming bulk_ins. */ 330 /* This is a announcement of coming bulk_ins. */
@@ -325,8 +334,8 @@ static void cyberjack_read_int_callback( struct urb *urb )
325 334
326 old_rdtodo = priv->rdtodo; 335 old_rdtodo = priv->rdtodo;
327 336
328 if( (old_rdtodo+size)<(old_rdtodo) ) { 337 if (old_rdtodo + size < old_rdtodo) {
329 dbg( "To many bulk_in urbs to do." ); 338 dbg("To many bulk_in urbs to do.");
330 spin_unlock(&priv->lock); 339 spin_unlock(&priv->lock);
331 goto resubmit; 340 goto resubmit;
332 } 341 }
@@ -338,10 +347,10 @@ static void cyberjack_read_int_callback( struct urb *urb )
338 347
339 spin_unlock(&priv->lock); 348 spin_unlock(&priv->lock);
340 349
341 if( !old_rdtodo ) { 350 if (!old_rdtodo) {
342 port->read_urb->dev = port->serial->dev; 351 port->read_urb->dev = port->serial->dev;
343 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 352 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
344 if( result ) 353 if (result)
345 err("%s - failed resubmitting read urb, error %d", __func__, result); 354 err("%s - failed resubmitting read urb, error %d", __func__, result);
346 dbg("%s - usb_submit_urb(read urb)", __func__); 355 dbg("%s - usb_submit_urb(read urb)", __func__);
347 } 356 }
@@ -355,7 +364,7 @@ resubmit:
355 dbg("%s - usb_submit_urb(int urb)", __func__); 364 dbg("%s - usb_submit_urb(int urb)", __func__);
356} 365}
357 366
358static void cyberjack_read_bulk_callback (struct urb *urb) 367static void cyberjack_read_bulk_callback(struct urb *urb)
359{ 368{
360 struct usb_serial_port *port = urb->context; 369 struct usb_serial_port *port = urb->context;
361 struct cyberjack_private *priv = usb_get_serial_port_data(port); 370 struct cyberjack_private *priv = usb_get_serial_port_data(port);
@@ -367,14 +376,15 @@ static void cyberjack_read_bulk_callback (struct urb *urb)
367 376
368 dbg("%s - port %d", __func__, port->number); 377 dbg("%s - port %d", __func__, port->number);
369 378
370 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); 379 usb_serial_debug_data(debug, &port->dev, __func__,
380 urb->actual_length, data);
371 if (status) { 381 if (status) {
372 dbg("%s - nonzero read bulk status received: %d", 382 dbg("%s - nonzero read bulk status received: %d",
373 __func__, status); 383 __func__, status);
374 return; 384 return;
375 } 385 }
376 386
377 tty = port->tty; 387 tty = port->port.tty;
378 if (!tty) { 388 if (!tty) {
379 dbg("%s - ignoring since device not open\n", __func__); 389 dbg("%s - ignoring since device not open\n", __func__);
380 return; 390 return;
@@ -382,15 +392,16 @@ static void cyberjack_read_bulk_callback (struct urb *urb)
382 if (urb->actual_length) { 392 if (urb->actual_length) {
383 tty_buffer_request_room(tty, urb->actual_length); 393 tty_buffer_request_room(tty, urb->actual_length);
384 tty_insert_flip_string(tty, data, urb->actual_length); 394 tty_insert_flip_string(tty, data, urb->actual_length);
385 tty_flip_buffer_push(tty); 395 tty_flip_buffer_push(tty);
386 } 396 }
387 397
388 spin_lock(&priv->lock); 398 spin_lock(&priv->lock);
389 399
390 /* Reduce urbs to do by one. */ 400 /* Reduce urbs to do by one. */
391 priv->rdtodo-=urb->actual_length; 401 priv->rdtodo -= urb->actual_length;
392 /* Just to be sure */ 402 /* Just to be sure */
393 if ( priv->rdtodo<0 ) priv->rdtodo = 0; 403 if (priv->rdtodo < 0)
404 priv->rdtodo = 0;
394 todo = priv->rdtodo; 405 todo = priv->rdtodo;
395 406
396 spin_unlock(&priv->lock); 407 spin_unlock(&priv->lock);
@@ -398,16 +409,17 @@ static void cyberjack_read_bulk_callback (struct urb *urb)
398 dbg("%s - rdtodo: %d", __func__, todo); 409 dbg("%s - rdtodo: %d", __func__, todo);
399 410
400 /* Continue to read if we have still urbs to do. */ 411 /* Continue to read if we have still urbs to do. */
401 if( todo /* || (urb->actual_length==port->bulk_in_endpointAddress)*/ ) { 412 if (todo /* || (urb->actual_length==port->bulk_in_endpointAddress)*/) {
402 port->read_urb->dev = port->serial->dev; 413 port->read_urb->dev = port->serial->dev;
403 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 414 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
404 if (result) 415 if (result)
405 err("%s - failed resubmitting read urb, error %d", __func__, result); 416 err("%s - failed resubmitting read urb, error %d",
417 __func__, result);
406 dbg("%s - usb_submit_urb(read urb)", __func__); 418 dbg("%s - usb_submit_urb(read urb)", __func__);
407 } 419 }
408} 420}
409 421
410static void cyberjack_write_bulk_callback (struct urb *urb) 422static void cyberjack_write_bulk_callback(struct urb *urb)
411{ 423{
412 struct usb_serial_port *port = urb->context; 424 struct usb_serial_port *port = urb->context;
413 struct cyberjack_private *priv = usb_get_serial_port_data(port); 425 struct cyberjack_private *priv = usb_get_serial_port_data(port);
@@ -425,7 +437,7 @@ static void cyberjack_write_bulk_callback (struct urb *urb)
425 spin_lock(&priv->lock); 437 spin_lock(&priv->lock);
426 438
427 /* only do something if we have more data to send */ 439 /* only do something if we have more data to send */
428 if( priv->wrfilled ) { 440 if (priv->wrfilled) {
429 int length, blksize, result; 441 int length, blksize, result;
430 442
431 dbg("%s - transmitting data (frame n)", __func__); 443 dbg("%s - transmitting data (frame n)", __func__);
@@ -433,37 +445,39 @@ static void cyberjack_write_bulk_callback (struct urb *urb)
433 length = ((priv->wrfilled - priv->wrsent) > port->bulk_out_size) ? 445 length = ((priv->wrfilled - priv->wrsent) > port->bulk_out_size) ?
434 port->bulk_out_size : (priv->wrfilled - priv->wrsent); 446 port->bulk_out_size : (priv->wrfilled - priv->wrsent);
435 447
436 memcpy (port->write_urb->transfer_buffer, priv->wrbuf + priv->wrsent, 448 memcpy(port->write_urb->transfer_buffer,
437 length ); 449 priv->wrbuf + priv->wrsent, length);
438 priv->wrsent+=length; 450 priv->wrsent += length;
439 451
440 /* set up our urb */ 452 /* set up our urb */
441 usb_fill_bulk_urb(port->write_urb, port->serial->dev, 453 usb_fill_bulk_urb(port->write_urb, port->serial->dev,
442 usb_sndbulkpipe(port->serial->dev, port->bulk_out_endpointAddress), 454 usb_sndbulkpipe(port->serial->dev, port->bulk_out_endpointAddress),
443 port->write_urb->transfer_buffer, length, 455 port->write_urb->transfer_buffer, length,
444 ((port->serial->type->write_bulk_callback) ? 456 ((port->serial->type->write_bulk_callback) ?
445 port->serial->type->write_bulk_callback : 457 port->serial->type->write_bulk_callback :
446 cyberjack_write_bulk_callback), 458 cyberjack_write_bulk_callback),
447 port); 459 port);
448 460
449 /* send the data out the bulk port */ 461 /* send the data out the bulk port */
450 result = usb_submit_urb(port->write_urb, GFP_ATOMIC); 462 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
451 if (result) { 463 if (result) {
452 err("%s - failed submitting write urb, error %d", __func__, result); 464 err("%s - failed submitting write urb, error %d",
465 __func__, result);
453 /* Throw away data. No better idea what to do with it. */ 466 /* Throw away data. No better idea what to do with it. */
454 priv->wrfilled = 0; 467 priv->wrfilled = 0;
455 priv->wrsent = 0; 468 priv->wrsent = 0;
456 goto exit; 469 goto exit;
457 } 470 }
458 471
459 dbg("%s - priv->wrsent=%d", __func__,priv->wrsent); 472 dbg("%s - priv->wrsent=%d", __func__, priv->wrsent);
460 dbg("%s - priv->wrfilled=%d", __func__,priv->wrfilled); 473 dbg("%s - priv->wrfilled=%d", __func__, priv->wrfilled);
461 474
462 blksize = ((int)priv->wrbuf[2]<<8)+priv->wrbuf[1]+3; 475 blksize = ((int)priv->wrbuf[2]<<8)+priv->wrbuf[1]+3;
463 476
464 if( (priv->wrsent>=priv->wrfilled) || (priv->wrsent>=blksize) ) { 477 if (priv->wrsent >= priv->wrfilled ||
478 priv->wrsent >= blksize) {
465 dbg("%s - buffer cleaned", __func__); 479 dbg("%s - buffer cleaned", __func__);
466 memset( priv->wrbuf, 0, sizeof(priv->wrbuf) ); 480 memset(priv->wrbuf, 0, sizeof(priv->wrbuf));
467 priv->wrfilled = 0; 481 priv->wrfilled = 0;
468 priv->wrsent = 0; 482 priv->wrsent = 0;
469 } 483 }
@@ -474,14 +488,14 @@ exit:
474 usb_serial_port_softint(port); 488 usb_serial_port_softint(port);
475} 489}
476 490
477static int __init cyberjack_init (void) 491static int __init cyberjack_init(void)
478{ 492{
479 int retval; 493 int retval;
480 retval = usb_serial_register(&cyberjack_device); 494 retval = usb_serial_register(&cyberjack_device);
481 if (retval) 495 if (retval)
482 goto failed_usb_serial_register; 496 goto failed_usb_serial_register;
483 retval = usb_register(&cyberjack_driver); 497 retval = usb_register(&cyberjack_driver);
484 if (retval) 498 if (retval)
485 goto failed_usb_register; 499 goto failed_usb_register;
486 500
487 info(DRIVER_VERSION " " DRIVER_AUTHOR); 501 info(DRIVER_VERSION " " DRIVER_AUTHOR);
@@ -494,18 +508,18 @@ failed_usb_serial_register:
494 return retval; 508 return retval;
495} 509}
496 510
497static void __exit cyberjack_exit (void) 511static void __exit cyberjack_exit(void)
498{ 512{
499 usb_deregister (&cyberjack_driver); 513 usb_deregister(&cyberjack_driver);
500 usb_serial_deregister (&cyberjack_device); 514 usb_serial_deregister(&cyberjack_device);
501} 515}
502 516
503module_init(cyberjack_init); 517module_init(cyberjack_init);
504module_exit(cyberjack_exit); 518module_exit(cyberjack_exit);
505 519
506MODULE_AUTHOR( DRIVER_AUTHOR ); 520MODULE_AUTHOR(DRIVER_AUTHOR);
507MODULE_DESCRIPTION( DRIVER_DESC ); 521MODULE_DESCRIPTION(DRIVER_DESC);
508MODULE_VERSION( DRIVER_VERSION ); 522MODULE_VERSION(DRIVER_VERSION);
509MODULE_LICENSE("GPL"); 523MODULE_LICENSE("GPL");
510 524
511module_param(debug, bool, S_IRUGO | S_IWUSR); 525module_param(debug, bool, S_IRUGO | S_IWUSR);
diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c
index 0230d3c0888a..22837a3f2f89 100644
--- a/drivers/usb/serial/cypress_m8.c
+++ b/drivers/usb/serial/cypress_m8.c
@@ -2,7 +2,7 @@
2 * USB Cypress M8 driver 2 * USB Cypress M8 driver
3 * 3 *
4 * Copyright (C) 2004 4 * Copyright (C) 2004
5 * Lonnie Mendez (dignome@gmail.com) 5 * Lonnie Mendez (dignome@gmail.com)
6 * Copyright (C) 2003,2004 6 * Copyright (C) 2003,2004
7 * Neil Whelchel (koyama@firstlight.net) 7 * Neil Whelchel (koyama@firstlight.net)
8 * 8 *
@@ -11,19 +11,21 @@
11 * the Free Software Foundation; either version 2 of the License, or 11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version. 12 * (at your option) any later version.
13 * 13 *
14 * See Documentation/usb/usb-serial.txt for more information on using this driver 14 * See Documentation/usb/usb-serial.txt for more information on using this
15 * driver
15 * 16 *
16 * See http://geocities.com/i0xox0i for information on this driver and the 17 * See http://geocities.com/i0xox0i for information on this driver and the
17 * earthmate usb device. 18 * earthmate usb device.
18 * 19 *
19 * Lonnie Mendez <dignome@gmail.com> 20 * Lonnie Mendez <dignome@gmail.com>
20 * 4-29-2005 21 * 4-29-2005
21 * Fixed problem where setting or retreiving the serial config would fail with 22 * Fixed problem where setting or retreiving the serial config would fail
22 * EPIPE. Removed CRTS toggling so the driver behaves more like other usbserial 23 * with EPIPE. Removed CRTS toggling so the driver behaves more like
23 * adapters. Issued new interval of 1ms instead of the default 10ms. As a 24 * other usbserial adapters. Issued new interval of 1ms instead of the
24 * result, transfer speed has been substantially increased. From avg. 850bps to 25 * default 10ms. As a result, transfer speed has been substantially
25 * avg. 3300bps. initial termios has also been modified. Cleaned up code and 26 * increased from avg. 850bps to avg. 3300bps. initial termios has also
26 * formatting issues so it is more readable. Replaced the C++ style comments. 27 * been modified. Cleaned up code and formatting issues so it is more
28 * readable. Replaced the C++ style comments.
27 * 29 *
28 * Lonnie Mendez <dignome@gmail.com> 30 * Lonnie Mendez <dignome@gmail.com>
29 * 12-15-2004 31 * 12-15-2004
@@ -42,10 +44,11 @@
42 * 44 *
43 */ 45 */
44 46
45/* Thanks to Neil Whelchel for writing the first cypress m8 implementation for linux. */ 47/* Thanks to Neil Whelchel for writing the first cypress m8 implementation
48 for linux. */
46/* Thanks to cypress for providing references for the hid reports. */ 49/* Thanks to cypress for providing references for the hid reports. */
47/* Thanks to Jiang Zhang for providing links and for general help. */ 50/* Thanks to Jiang Zhang for providing links and for general help. */
48/* Code originates and was built up from ftdi_sio, belkin, pl2303 and others. */ 51/* Code originates and was built up from ftdi_sio, belkin, pl2303 and others.*/
49 52
50 53
51#include <linux/kernel.h> 54#include <linux/kernel.h>
@@ -62,7 +65,7 @@
62#include <linux/usb/serial.h> 65#include <linux/usb/serial.h>
63#include <linux/serial.h> 66#include <linux/serial.h>
64#include <linux/delay.h> 67#include <linux/delay.h>
65#include <asm/uaccess.h> 68#include <linux/uaccess.h>
66 69
67#include "cypress_m8.h" 70#include "cypress_m8.h"
68 71
@@ -112,7 +115,7 @@ static struct usb_device_id id_table_combined [] = {
112 { } /* Terminating entry */ 115 { } /* Terminating entry */
113}; 116};
114 117
115MODULE_DEVICE_TABLE (usb, id_table_combined); 118MODULE_DEVICE_TABLE(usb, id_table_combined);
116 119
117static struct usb_driver cypress_driver = { 120static struct usb_driver cypress_driver = {
118 .name = "cypress", 121 .name = "cypress",
@@ -146,11 +149,13 @@ struct cypress_private {
146 __u8 rx_flags; /* throttling - used from whiteheat/ftdi_sio */ 149 __u8 rx_flags; /* throttling - used from whiteheat/ftdi_sio */
147 enum packet_format pkt_fmt; /* format to use for packet send / receive */ 150 enum packet_format pkt_fmt; /* format to use for packet send / receive */
148 int get_cfg_unsafe; /* If true, the CYPRESS_GET_CONFIG is unsafe */ 151 int get_cfg_unsafe; /* If true, the CYPRESS_GET_CONFIG is unsafe */
149 int baud_rate; /* stores current baud rate in integer form */ 152 int baud_rate; /* stores current baud rate in
153 integer form */
150 int isthrottled; /* if throttled, discard reads */ 154 int isthrottled; /* if throttled, discard reads */
151 wait_queue_head_t delta_msr_wait; /* used for TIOCMIWAIT */ 155 wait_queue_head_t delta_msr_wait; /* used for TIOCMIWAIT */
152 char prev_status, diff_status; /* used for TIOCMIWAIT */ 156 char prev_status, diff_status; /* used for TIOCMIWAIT */
153 /* we pass a pointer to this as the arguement sent to cypress_set_termios old_termios */ 157 /* we pass a pointer to this as the arguement sent to
158 cypress_set_termios old_termios */
154 struct ktermios tmp_termios; /* stores the old termios settings */ 159 struct ktermios tmp_termios; /* stores the old termios settings */
155}; 160};
156 161
@@ -163,33 +168,41 @@ struct cypress_buf {
163}; 168};
164 169
165/* function prototypes for the Cypress USB to serial device */ 170/* function prototypes for the Cypress USB to serial device */
166static int cypress_earthmate_startup (struct usb_serial *serial); 171static int cypress_earthmate_startup(struct usb_serial *serial);
167static int cypress_hidcom_startup (struct usb_serial *serial); 172static int cypress_hidcom_startup(struct usb_serial *serial);
168static int cypress_ca42v2_startup (struct usb_serial *serial); 173static int cypress_ca42v2_startup(struct usb_serial *serial);
169static void cypress_shutdown (struct usb_serial *serial); 174static void cypress_shutdown(struct usb_serial *serial);
170static int cypress_open (struct usb_serial_port *port, struct file *filp); 175static int cypress_open(struct tty_struct *tty,
171static void cypress_close (struct usb_serial_port *port, struct file *filp); 176 struct usb_serial_port *port, struct file *filp);
172static int cypress_write (struct usb_serial_port *port, const unsigned char *buf, int count); 177static void cypress_close(struct tty_struct *tty,
173static void cypress_send (struct usb_serial_port *port); 178 struct usb_serial_port *port, struct file *filp);
174static int cypress_write_room (struct usb_serial_port *port); 179static int cypress_write(struct tty_struct *tty, struct usb_serial_port *port,
175static int cypress_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg); 180 const unsigned char *buf, int count);
176static void cypress_set_termios (struct usb_serial_port *port, struct ktermios * old); 181static void cypress_send(struct usb_serial_port *port);
177static int cypress_tiocmget (struct usb_serial_port *port, struct file *file); 182static int cypress_write_room(struct tty_struct *tty);
178static int cypress_tiocmset (struct usb_serial_port *port, struct file *file, unsigned int set, unsigned int clear); 183static int cypress_ioctl(struct tty_struct *tty, struct file *file,
179static int cypress_chars_in_buffer (struct usb_serial_port *port); 184 unsigned int cmd, unsigned long arg);
180static void cypress_throttle (struct usb_serial_port *port); 185static void cypress_set_termios(struct tty_struct *tty,
181static void cypress_unthrottle (struct usb_serial_port *port); 186 struct usb_serial_port *port, struct ktermios *old);
182static void cypress_set_dead (struct usb_serial_port *port); 187static int cypress_tiocmget(struct tty_struct *tty, struct file *file);
183static void cypress_read_int_callback (struct urb *urb); 188static int cypress_tiocmset(struct tty_struct *tty, struct file *file,
184static void cypress_write_int_callback (struct urb *urb); 189 unsigned int set, unsigned int clear);
190static int cypress_chars_in_buffer(struct tty_struct *tty);
191static void cypress_throttle(struct tty_struct *tty);
192static void cypress_unthrottle(struct tty_struct *tty);
193static void cypress_set_dead(struct usb_serial_port *port);
194static void cypress_read_int_callback(struct urb *urb);
195static void cypress_write_int_callback(struct urb *urb);
185/* write buffer functions */ 196/* write buffer functions */
186static struct cypress_buf *cypress_buf_alloc(unsigned int size); 197static struct cypress_buf *cypress_buf_alloc(unsigned int size);
187static void cypress_buf_free(struct cypress_buf *cb); 198static void cypress_buf_free(struct cypress_buf *cb);
188static void cypress_buf_clear(struct cypress_buf *cb); 199static void cypress_buf_clear(struct cypress_buf *cb);
189static unsigned int cypress_buf_data_avail(struct cypress_buf *cb); 200static unsigned int cypress_buf_data_avail(struct cypress_buf *cb);
190static unsigned int cypress_buf_space_avail(struct cypress_buf *cb); 201static unsigned int cypress_buf_space_avail(struct cypress_buf *cb);
191static unsigned int cypress_buf_put(struct cypress_buf *cb, const char *buf, unsigned int count); 202static unsigned int cypress_buf_put(struct cypress_buf *cb,
192static unsigned int cypress_buf_get(struct cypress_buf *cb, char *buf, unsigned int count); 203 const char *buf, unsigned int count);
204static unsigned int cypress_buf_get(struct cypress_buf *cb,
205 char *buf, unsigned int count);
193 206
194 207
195static struct usb_serial_driver cypress_earthmate_device = { 208static struct usb_serial_driver cypress_earthmate_device = {
@@ -247,7 +260,7 @@ static struct usb_serial_driver cypress_hidcom_device = {
247static struct usb_serial_driver cypress_ca42v2_device = { 260static struct usb_serial_driver cypress_ca42v2_device = {
248 .driver = { 261 .driver = {
249 .owner = THIS_MODULE, 262 .owner = THIS_MODULE,
250 .name = "nokiaca42v2", 263 .name = "nokiaca42v2",
251 }, 264 },
252 .description = "Nokia CA-42 V2 Adapter", 265 .description = "Nokia CA-42 V2 Adapter",
253 .usb_driver = &cypress_driver, 266 .usb_driver = &cypress_driver,
@@ -322,8 +335,10 @@ static int analyze_baud_rate(struct usb_serial_port *port, speed_t new_rate)
322 335
323 336
324/* This function can either set or retrieve the current serial line settings */ 337/* This function can either set or retrieve the current serial line settings */
325static int cypress_serial_control (struct usb_serial_port *port, speed_t baud_rate, int data_bits, int stop_bits, 338static int cypress_serial_control(struct tty_struct *tty,
326 int parity_enable, int parity_type, int reset, int cypress_request_type) 339 struct usb_serial_port *port, speed_t baud_rate, int data_bits,
340 int stop_bits, int parity_enable, int parity_type, int reset,
341 int cypress_request_type)
327{ 342{
328 int new_baudrate = 0, retval = 0, tries = 0; 343 int new_baudrate = 0, retval = 0, tries = 0;
329 struct cypress_private *priv; 344 struct cypress_private *priv;
@@ -331,111 +346,114 @@ static int cypress_serial_control (struct usb_serial_port *port, speed_t baud_ra
331 unsigned long flags; 346 unsigned long flags;
332 347
333 dbg("%s", __func__); 348 dbg("%s", __func__);
334 349
335 priv = usb_get_serial_port_data(port); 350 priv = usb_get_serial_port_data(port);
336 351
337 if (!priv->comm_is_ok) 352 if (!priv->comm_is_ok)
338 return -ENODEV; 353 return -ENODEV;
339 354
340 switch(cypress_request_type) { 355 switch (cypress_request_type) {
341 case CYPRESS_SET_CONFIG: 356 case CYPRESS_SET_CONFIG:
357 new_baudrate = priv->baud_rate;
358 /* 0 means 'Hang up' so doesn't change the true bit rate */
359 if (baud_rate == 0)
342 new_baudrate = priv->baud_rate; 360 new_baudrate = priv->baud_rate;
343 /* 0 means 'Hang up' so doesn't change the true bit rate */ 361 /* Change of speed ? */
344 if (baud_rate == 0) 362 else if (baud_rate != priv->baud_rate) {
345 new_baudrate = priv->baud_rate; 363 dbg("%s - baud rate is changing", __func__);
346 /* Change of speed ? */ 364 retval = analyze_baud_rate(port, baud_rate);
347 else if (baud_rate != priv->baud_rate) { 365 if (retval >= 0) {
348 dbg("%s - baud rate is changing", __func__); 366 new_baudrate = retval;
349 retval = analyze_baud_rate(port, baud_rate); 367 dbg("%s - New baud rate set to %d",
350 if (retval >= 0) { 368 __func__, new_baudrate);
351 new_baudrate = retval;
352 dbg("%s - New baud rate set to %d",
353 __func__, new_baudrate);
354 }
355 }
356 dbg("%s - baud rate is being sent as %d", __func__, new_baudrate);
357
358 memset(feature_buffer, 0, sizeof(feature_buffer));
359 /* fill the feature_buffer with new configuration */
360 *((u_int32_t *)feature_buffer) = new_baudrate;
361
362 feature_buffer[4] |= data_bits; /* assign data bits in 2 bit space ( max 3 ) */
363 /* 1 bit gap */
364 feature_buffer[4] |= (stop_bits << 3); /* assign stop bits in 1 bit space */
365 feature_buffer[4] |= (parity_enable << 4); /* assign parity flag in 1 bit space */
366 feature_buffer[4] |= (parity_type << 5); /* assign parity type in 1 bit space */
367 /* 1 bit gap */
368 feature_buffer[4] |= (reset << 7); /* assign reset at end of byte, 1 bit space */
369
370 dbg("%s - device is being sent this feature report:", __func__);
371 dbg("%s - %02X - %02X - %02X - %02X - %02X", __func__, feature_buffer[0], feature_buffer[1],
372 feature_buffer[2], feature_buffer[3], feature_buffer[4]);
373
374 do {
375 retval = usb_control_msg(port->serial->dev,
376 usb_sndctrlpipe(port->serial->dev, 0),
377 HID_REQ_SET_REPORT,
378 USB_DIR_OUT | USB_RECIP_INTERFACE | USB_TYPE_CLASS,
379 0x0300, 0, feature_buffer,
380 sizeof(feature_buffer), 500);
381
382 if (tries++ >= 3)
383 break;
384
385 } while (retval != sizeof(feature_buffer) &&
386 retval != -ENODEV);
387
388 if (retval != sizeof(feature_buffer)) {
389 err("%s - failed sending serial line settings - %d", __func__, retval);
390 cypress_set_dead(port);
391 } else {
392 spin_lock_irqsave(&priv->lock, flags);
393 priv->baud_rate = new_baudrate;
394 priv->current_config = feature_buffer[4];
395 spin_unlock_irqrestore(&priv->lock, flags);
396 /* If we asked for a speed change encode it */
397 if (baud_rate)
398 tty_encode_baud_rate(port->tty,
399 new_baudrate, new_baudrate);
400 }
401 break;
402 case CYPRESS_GET_CONFIG:
403 if (priv->get_cfg_unsafe) {
404 /* Not implemented for this device,
405 and if we try to do it we're likely
406 to crash the hardware. */
407 return -ENOTTY;
408 }
409 dbg("%s - retreiving serial line settings", __func__);
410 /* set initial values in feature buffer */
411 memset(feature_buffer, 0, sizeof(feature_buffer));
412
413 do {
414 retval = usb_control_msg(port->serial->dev,
415 usb_rcvctrlpipe(port->serial->dev, 0),
416 HID_REQ_GET_REPORT,
417 USB_DIR_IN | USB_RECIP_INTERFACE | USB_TYPE_CLASS,
418 0x0300, 0, feature_buffer,
419 sizeof(feature_buffer), 500);
420
421 if (tries++ >= 3)
422 break;
423
424 } while (retval != sizeof(feature_buffer) &&
425 retval != -ENODEV);
426
427 if (retval != sizeof(feature_buffer)) {
428 err("%s - failed to retrieve serial line settings - %d", __func__, retval);
429 cypress_set_dead(port);
430 return retval;
431 } else {
432 spin_lock_irqsave(&priv->lock, flags);
433
434 /* store the config in one byte, and later use bit masks to check values */
435 priv->current_config = feature_buffer[4];
436 priv->baud_rate = *((u_int32_t *)feature_buffer);
437 spin_unlock_irqrestore(&priv->lock, flags);
438 } 369 }
370 }
371 dbg("%s - baud rate is being sent as %d",
372 __func__, new_baudrate);
373
374 memset(feature_buffer, 0, sizeof(feature_buffer));
375 /* fill the feature_buffer with new configuration */
376 *((u_int32_t *)feature_buffer) = new_baudrate;
377 feature_buffer[4] |= data_bits; /* assign data bits in 2 bit space ( max 3 ) */
378 /* 1 bit gap */
379 feature_buffer[4] |= (stop_bits << 3); /* assign stop bits in 1 bit space */
380 feature_buffer[4] |= (parity_enable << 4); /* assign parity flag in 1 bit space */
381 feature_buffer[4] |= (parity_type << 5); /* assign parity type in 1 bit space */
382 /* 1 bit gap */
383 feature_buffer[4] |= (reset << 7); /* assign reset at end of byte, 1 bit space */
384
385 dbg("%s - device is being sent this feature report:",
386 __func__);
387 dbg("%s - %02X - %02X - %02X - %02X - %02X", __func__,
388 feature_buffer[0], feature_buffer[1],
389 feature_buffer[2], feature_buffer[3],
390 feature_buffer[4]);
391
392 do {
393 retval = usb_control_msg(port->serial->dev,
394 usb_sndctrlpipe(port->serial->dev, 0),
395 HID_REQ_SET_REPORT,
396 USB_DIR_OUT | USB_RECIP_INTERFACE | USB_TYPE_CLASS,
397 0x0300, 0, feature_buffer,
398 sizeof(feature_buffer), 500);
399
400 if (tries++ >= 3)
401 break;
402
403 } while (retval != sizeof(feature_buffer) &&
404 retval != -ENODEV);
405
406 if (retval != sizeof(feature_buffer)) {
407 err("%s - failed sending serial line settings - %d",
408 __func__, retval);
409 cypress_set_dead(port);
410 } else {
411 spin_lock_irqsave(&priv->lock, flags);
412 priv->baud_rate = new_baudrate;
413 priv->current_config = feature_buffer[4];
414 spin_unlock_irqrestore(&priv->lock, flags);
415 /* If we asked for a speed change encode it */
416 if (baud_rate)
417 tty_encode_baud_rate(tty,
418 new_baudrate, new_baudrate);
419 }
420 break;
421 case CYPRESS_GET_CONFIG:
422 if (priv->get_cfg_unsafe) {
423 /* Not implemented for this device,
424 and if we try to do it we're likely
425 to crash the hardware. */
426 return -ENOTTY;
427 }
428 dbg("%s - retreiving serial line settings", __func__);
429 /* set initial values in feature buffer */
430 memset(feature_buffer, 0, sizeof(feature_buffer));
431
432 do {
433 retval = usb_control_msg(port->serial->dev,
434 usb_rcvctrlpipe(port->serial->dev, 0),
435 HID_REQ_GET_REPORT,
436 USB_DIR_IN | USB_RECIP_INTERFACE | USB_TYPE_CLASS,
437 0x0300, 0, feature_buffer,
438 sizeof(feature_buffer), 500);
439
440 if (tries++ >= 3)
441 break;
442 } while (retval != sizeof(feature_buffer)
443 && retval != -ENODEV);
444
445 if (retval != sizeof(feature_buffer)) {
446 err("%s - failed to retrieve serial line settings - %d", __func__, retval);
447 cypress_set_dead(port);
448 return retval;
449 } else {
450 spin_lock_irqsave(&priv->lock, flags);
451 /* store the config in one byte, and later
452 use bit masks to check values */
453 priv->current_config = feature_buffer[4];
454 priv->baud_rate = *((u_int32_t *)feature_buffer);
455 spin_unlock_irqrestore(&priv->lock, flags);
456 }
439 } 457 }
440 spin_lock_irqsave(&priv->lock, flags); 458 spin_lock_irqsave(&priv->lock, flags);
441 ++priv->cmd_count; 459 ++priv->cmd_count;
@@ -468,14 +486,14 @@ static void cypress_set_dead(struct usb_serial_port *port)
468 *****************************************************************************/ 486 *****************************************************************************/
469 487
470 488
471static int generic_startup (struct usb_serial *serial) 489static int generic_startup(struct usb_serial *serial)
472{ 490{
473 struct cypress_private *priv; 491 struct cypress_private *priv;
474 struct usb_serial_port *port = serial->port[0]; 492 struct usb_serial_port *port = serial->port[0];
475 493
476 dbg("%s - port %d", __func__, port->number); 494 dbg("%s - port %d", __func__, port->number);
477 495
478 priv = kzalloc(sizeof (struct cypress_private), GFP_KERNEL); 496 priv = kzalloc(sizeof(struct cypress_private), GFP_KERNEL);
479 if (!priv) 497 if (!priv)
480 return -ENOMEM; 498 return -ENOMEM;
481 499
@@ -487,9 +505,9 @@ static int generic_startup (struct usb_serial *serial)
487 return -ENOMEM; 505 return -ENOMEM;
488 } 506 }
489 init_waitqueue_head(&priv->delta_msr_wait); 507 init_waitqueue_head(&priv->delta_msr_wait);
490 508
491 usb_reset_configuration (serial->dev); 509 usb_reset_configuration(serial->dev);
492 510
493 priv->cmd_ctrl = 0; 511 priv->cmd_ctrl = 0;
494 priv->line_control = 0; 512 priv->line_control = 0;
495 priv->termios_initialized = 0; 513 priv->termios_initialized = 0;
@@ -500,30 +518,30 @@ static int generic_startup (struct usb_serial *serial)
500 small. Otherwise we can use the slightly more compact 518 small. Otherwise we can use the slightly more compact
501 format. This is in accordance with the cypress_m8 serial 519 format. This is in accordance with the cypress_m8 serial
502 converter app note. */ 520 converter app note. */
503 if (port->interrupt_out_size > 9) { 521 if (port->interrupt_out_size > 9)
504 priv->pkt_fmt = packet_format_1; 522 priv->pkt_fmt = packet_format_1;
505 } else { 523 else
506 priv->pkt_fmt = packet_format_2; 524 priv->pkt_fmt = packet_format_2;
507 } 525
508 if (interval > 0) { 526 if (interval > 0) {
509 priv->write_urb_interval = interval; 527 priv->write_urb_interval = interval;
510 priv->read_urb_interval = interval; 528 priv->read_urb_interval = interval;
511 dbg("%s - port %d read & write intervals forced to %d", 529 dbg("%s - port %d read & write intervals forced to %d",
512 __func__,port->number,interval); 530 __func__, port->number, interval);
513 } else { 531 } else {
514 priv->write_urb_interval = port->interrupt_out_urb->interval; 532 priv->write_urb_interval = port->interrupt_out_urb->interval;
515 priv->read_urb_interval = port->interrupt_in_urb->interval; 533 priv->read_urb_interval = port->interrupt_in_urb->interval;
516 dbg("%s - port %d intervals: read=%d write=%d", 534 dbg("%s - port %d intervals: read=%d write=%d",
517 __func__,port->number, 535 __func__, port->number,
518 priv->read_urb_interval,priv->write_urb_interval); 536 priv->read_urb_interval, priv->write_urb_interval);
519 } 537 }
520 usb_set_serial_port_data(port, priv); 538 usb_set_serial_port_data(port, priv);
521 539
522 return 0; 540 return 0;
523} 541}
524 542
525 543
526static int cypress_earthmate_startup (struct usb_serial *serial) 544static int cypress_earthmate_startup(struct usb_serial *serial)
527{ 545{
528 struct cypress_private *priv; 546 struct cypress_private *priv;
529 struct usb_serial_port *port = serial->port[0]; 547 struct usb_serial_port *port = serial->port[0];
@@ -541,7 +559,8 @@ static int cypress_earthmate_startup (struct usb_serial *serial)
541 /* All Earthmate devices use the separated-count packet 559 /* All Earthmate devices use the separated-count packet
542 format! Idiotic. */ 560 format! Idiotic. */
543 priv->pkt_fmt = packet_format_1; 561 priv->pkt_fmt = packet_format_1;
544 if (serial->dev->descriptor.idProduct != cpu_to_le16(PRODUCT_ID_EARTHMATEUSB)) { 562 if (serial->dev->descriptor.idProduct !=
563 cpu_to_le16(PRODUCT_ID_EARTHMATEUSB)) {
545 /* The old original USB Earthmate seemed able to 564 /* The old original USB Earthmate seemed able to
546 handle GET_CONFIG requests; everything they've 565 handle GET_CONFIG requests; everything they've
547 produced since that time crashes if this command is 566 produced since that time crashes if this command is
@@ -555,7 +574,7 @@ static int cypress_earthmate_startup (struct usb_serial *serial)
555} /* cypress_earthmate_startup */ 574} /* cypress_earthmate_startup */
556 575
557 576
558static int cypress_hidcom_startup (struct usb_serial *serial) 577static int cypress_hidcom_startup(struct usb_serial *serial)
559{ 578{
560 struct cypress_private *priv; 579 struct cypress_private *priv;
561 580
@@ -569,12 +588,12 @@ static int cypress_hidcom_startup (struct usb_serial *serial)
569 588
570 priv = usb_get_serial_port_data(serial->port[0]); 589 priv = usb_get_serial_port_data(serial->port[0]);
571 priv->chiptype = CT_CYPHIDCOM; 590 priv->chiptype = CT_CYPHIDCOM;
572 591
573 return 0; 592 return 0;
574} /* cypress_hidcom_startup */ 593} /* cypress_hidcom_startup */
575 594
576 595
577static int cypress_ca42v2_startup (struct usb_serial *serial) 596static int cypress_ca42v2_startup(struct usb_serial *serial)
578{ 597{
579 struct cypress_private *priv; 598 struct cypress_private *priv;
580 599
@@ -593,11 +612,11 @@ static int cypress_ca42v2_startup (struct usb_serial *serial)
593} /* cypress_ca42v2_startup */ 612} /* cypress_ca42v2_startup */
594 613
595 614
596static void cypress_shutdown (struct usb_serial *serial) 615static void cypress_shutdown(struct usb_serial *serial)
597{ 616{
598 struct cypress_private *priv; 617 struct cypress_private *priv;
599 618
600 dbg ("%s - port %d", __func__, serial->port[0]->number); 619 dbg("%s - port %d", __func__, serial->port[0]->number);
601 620
602 /* all open ports are closed at this point */ 621 /* all open ports are closed at this point */
603 622
@@ -611,7 +630,8 @@ static void cypress_shutdown (struct usb_serial *serial)
611} 630}
612 631
613 632
614static int cypress_open (struct usb_serial_port *port, struct file *filp) 633static int cypress_open(struct tty_struct *tty,
634 struct usb_serial_port *port, struct file *filp)
615{ 635{
616 struct cypress_private *priv = usb_get_serial_port_data(port); 636 struct cypress_private *priv = usb_get_serial_port_data(port);
617 struct usb_serial *serial = port->serial; 637 struct usb_serial *serial = port->serial;
@@ -636,37 +656,44 @@ static int cypress_open (struct usb_serial_port *port, struct file *filp)
636 spin_unlock_irqrestore(&priv->lock, flags); 656 spin_unlock_irqrestore(&priv->lock, flags);
637 657
638 /* setting to zero could cause data loss */ 658 /* setting to zero could cause data loss */
639 port->tty->low_latency = 1; 659 if (tty)
660 tty->low_latency = 1;
640 661
641 /* raise both lines and set termios */ 662 /* raise both lines and set termios */
642 spin_lock_irqsave(&priv->lock, flags); 663 spin_lock_irqsave(&priv->lock, flags);
643 priv->line_control = CONTROL_DTR | CONTROL_RTS; 664 priv->line_control = CONTROL_DTR | CONTROL_RTS;
644 priv->cmd_ctrl = 1; 665 priv->cmd_ctrl = 1;
645 spin_unlock_irqrestore(&priv->lock, flags); 666 spin_unlock_irqrestore(&priv->lock, flags);
646 result = cypress_write(port, NULL, 0); 667 result = cypress_write(tty, port, NULL, 0);
647 668
648 if (result) { 669 if (result) {
649 dev_err(&port->dev, "%s - failed setting the control lines - error %d\n", __func__, result); 670 dev_err(&port->dev,
671 "%s - failed setting the control lines - error %d\n",
672 __func__, result);
650 return result; 673 return result;
651 } else 674 } else
652 dbg("%s - success setting the control lines", __func__); 675 dbg("%s - success setting the control lines", __func__);
653 676
654 cypress_set_termios(port, &priv->tmp_termios); 677 if (tty)
678 cypress_set_termios(tty, port, &priv->tmp_termios);
655 679
656 /* setup the port and start reading from the device */ 680 /* setup the port and start reading from the device */
657 if(!port->interrupt_in_urb){ 681 if (!port->interrupt_in_urb) {
658 err("%s - interrupt_in_urb is empty!", __func__); 682 err("%s - interrupt_in_urb is empty!", __func__);
659 return(-1); 683 return -1;
660 } 684 }
661 685
662 usb_fill_int_urb(port->interrupt_in_urb, serial->dev, 686 usb_fill_int_urb(port->interrupt_in_urb, serial->dev,
663 usb_rcvintpipe(serial->dev, port->interrupt_in_endpointAddress), 687 usb_rcvintpipe(serial->dev, port->interrupt_in_endpointAddress),
664 port->interrupt_in_urb->transfer_buffer, port->interrupt_in_urb->transfer_buffer_length, 688 port->interrupt_in_urb->transfer_buffer,
689 port->interrupt_in_urb->transfer_buffer_length,
665 cypress_read_int_callback, port, priv->read_urb_interval); 690 cypress_read_int_callback, port, priv->read_urb_interval);
666 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 691 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
667 692
668 if (result){ 693 if (result) {
669 dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __func__, result); 694 dev_err(&port->dev,
695 "%s - failed submitting read urb, error %d\n",
696 __func__, result);
670 cypress_set_dead(port); 697 cypress_set_dead(port);
671 } 698 }
672 699
@@ -674,7 +701,8 @@ static int cypress_open (struct usb_serial_port *port, struct file *filp)
674} /* cypress_open */ 701} /* cypress_open */
675 702
676 703
677static void cypress_close(struct usb_serial_port *port, struct file * filp) 704static void cypress_close(struct tty_struct *tty,
705 struct usb_serial_port *port, struct file *filp)
678{ 706{
679 struct cypress_private *priv = usb_get_serial_port_data(port); 707 struct cypress_private *priv = usb_get_serial_port_data(port);
680 unsigned int c_cflag; 708 unsigned int c_cflag;
@@ -688,7 +716,7 @@ static void cypress_close(struct usb_serial_port *port, struct file * filp)
688 spin_lock_irq(&priv->lock); 716 spin_lock_irq(&priv->lock);
689 timeout = CYPRESS_CLOSING_WAIT; 717 timeout = CYPRESS_CLOSING_WAIT;
690 init_waitqueue_entry(&wait, current); 718 init_waitqueue_entry(&wait, current);
691 add_wait_queue(&port->tty->write_wait, &wait); 719 add_wait_queue(&tty->write_wait, &wait);
692 for (;;) { 720 for (;;) {
693 set_current_state(TASK_INTERRUPTIBLE); 721 set_current_state(TASK_INTERRUPTIBLE);
694 if (cypress_buf_data_avail(priv->buf) == 0 722 if (cypress_buf_data_avail(priv->buf) == 0
@@ -701,7 +729,7 @@ static void cypress_close(struct usb_serial_port *port, struct file * filp)
701 spin_lock_irq(&priv->lock); 729 spin_lock_irq(&priv->lock);
702 } 730 }
703 set_current_state(TASK_RUNNING); 731 set_current_state(TASK_RUNNING);
704 remove_wait_queue(&port->tty->write_wait, &wait); 732 remove_wait_queue(&tty->write_wait, &wait);
705 /* clear out any remaining data in the buffer */ 733 /* clear out any remaining data in the buffer */
706 cypress_buf_clear(priv->buf); 734 cypress_buf_clear(priv->buf);
707 spin_unlock_irq(&priv->lock); 735 spin_unlock_irq(&priv->lock);
@@ -713,19 +741,21 @@ static void cypress_close(struct usb_serial_port *port, struct file * filp)
713 return; 741 return;
714 } 742 }
715 /* wait for characters to drain from device */ 743 /* wait for characters to drain from device */
716 bps = tty_get_baud_rate(port->tty); 744 if (tty) {
717 if (bps > 1200) 745 bps = tty_get_baud_rate(tty);
718 timeout = max((HZ*2560)/bps,HZ/10); 746 if (bps > 1200)
719 else 747 timeout = max((HZ * 2560) / bps, HZ / 10);
720 timeout = 2*HZ; 748 else
721 schedule_timeout_interruptible(timeout); 749 timeout = 2 * HZ;
750 schedule_timeout_interruptible(timeout);
751 }
722 752
723 dbg("%s - stopping urbs", __func__); 753 dbg("%s - stopping urbs", __func__);
724 usb_kill_urb (port->interrupt_in_urb); 754 usb_kill_urb(port->interrupt_in_urb);
725 usb_kill_urb (port->interrupt_out_urb); 755 usb_kill_urb(port->interrupt_out_urb);
726 756
727 if (port->tty) { 757 if (tty) {
728 c_cflag = port->tty->termios->c_cflag; 758 c_cflag = tty->termios->c_cflag;
729 if (c_cflag & HUPCL) { 759 if (c_cflag & HUPCL) {
730 /* drop dtr and rts */ 760 /* drop dtr and rts */
731 priv = usb_get_serial_port_data(port); 761 priv = usb_get_serial_port_data(port);
@@ -733,22 +763,23 @@ static void cypress_close(struct usb_serial_port *port, struct file * filp)
733 priv->line_control = 0; 763 priv->line_control = 0;
734 priv->cmd_ctrl = 1; 764 priv->cmd_ctrl = 1;
735 spin_unlock_irq(&priv->lock); 765 spin_unlock_irq(&priv->lock);
736 cypress_write(port, NULL, 0); 766 cypress_write(tty, port, NULL, 0);
737 } 767 }
738 } 768 }
739 769
740 if (stats) 770 if (stats)
741 dev_info (&port->dev, "Statistics: %d Bytes In | %d Bytes Out | %d Commands Issued\n", 771 dev_info(&port->dev, "Statistics: %d Bytes In | %d Bytes Out | %d Commands Issued\n",
742 priv->bytes_in, priv->bytes_out, priv->cmd_count); 772 priv->bytes_in, priv->bytes_out, priv->cmd_count);
743 mutex_unlock(&port->serial->disc_mutex); 773 mutex_unlock(&port->serial->disc_mutex);
744} /* cypress_close */ 774} /* cypress_close */
745 775
746 776
747static int cypress_write(struct usb_serial_port *port, const unsigned char *buf, int count) 777static int cypress_write(struct tty_struct *tty, struct usb_serial_port *port,
778 const unsigned char *buf, int count)
748{ 779{
749 struct cypress_private *priv = usb_get_serial_port_data(port); 780 struct cypress_private *priv = usb_get_serial_port_data(port);
750 unsigned long flags; 781 unsigned long flags;
751 782
752 dbg("%s - port %d, %d bytes", __func__, port->number, count); 783 dbg("%s - port %d, %d bytes", __func__, port->number, count);
753 784
754 /* line control commands, which need to be executed immediately, 785 /* line control commands, which need to be executed immediately,
@@ -758,10 +789,10 @@ static int cypress_write(struct usb_serial_port *port, const unsigned char *buf,
758 count = 0; 789 count = 0;
759 goto finish; 790 goto finish;
760 } 791 }
761 792
762 if (!count) 793 if (!count)
763 return count; 794 return count;
764 795
765 spin_lock_irqsave(&priv->lock, flags); 796 spin_lock_irqsave(&priv->lock, flags);
766 count = cypress_buf_put(priv->buf, buf, count); 797 count = cypress_buf_put(priv->buf, buf, count);
767 spin_unlock_irqrestore(&priv->lock, flags); 798 spin_unlock_irqrestore(&priv->lock, flags);
@@ -778,13 +809,14 @@ static void cypress_send(struct usb_serial_port *port)
778 int count = 0, result, offset, actual_size; 809 int count = 0, result, offset, actual_size;
779 struct cypress_private *priv = usb_get_serial_port_data(port); 810 struct cypress_private *priv = usb_get_serial_port_data(port);
780 unsigned long flags; 811 unsigned long flags;
781 812
782 if (!priv->comm_is_ok) 813 if (!priv->comm_is_ok)
783 return; 814 return;
784 815
785 dbg("%s - port %d", __func__, port->number); 816 dbg("%s - port %d", __func__, port->number);
786 dbg("%s - interrupt out size is %d", __func__, port->interrupt_out_size); 817 dbg("%s - interrupt out size is %d", __func__,
787 818 port->interrupt_out_size);
819
788 spin_lock_irqsave(&priv->lock, flags); 820 spin_lock_irqsave(&priv->lock, flags);
789 if (priv->write_urb_in_use) { 821 if (priv->write_urb_in_use) {
790 dbg("%s - can't write, urb in use", __func__); 822 dbg("%s - can't write, urb in use", __func__);
@@ -794,7 +826,8 @@ static void cypress_send(struct usb_serial_port *port)
794 spin_unlock_irqrestore(&priv->lock, flags); 826 spin_unlock_irqrestore(&priv->lock, flags);
795 827
796 /* clear buffer */ 828 /* clear buffer */
797 memset(port->interrupt_out_urb->transfer_buffer, 0, port->interrupt_out_size); 829 memset(port->interrupt_out_urb->transfer_buffer, 0,
830 port->interrupt_out_size);
798 831
799 spin_lock_irqsave(&priv->lock, flags); 832 spin_lock_irqsave(&priv->lock, flags);
800 switch (priv->pkt_fmt) { 833 switch (priv->pkt_fmt) {
@@ -825,9 +858,8 @@ static void cypress_send(struct usb_serial_port *port)
825 count = cypress_buf_get(priv->buf, &port->interrupt_out_buffer[offset], 858 count = cypress_buf_get(priv->buf, &port->interrupt_out_buffer[offset],
826 port->interrupt_out_size-offset); 859 port->interrupt_out_size-offset);
827 860
828 if (count == 0) { 861 if (count == 0)
829 return; 862 return;
830 }
831 863
832 switch (priv->pkt_fmt) { 864 switch (priv->pkt_fmt) {
833 default: 865 default:
@@ -851,26 +883,29 @@ send:
851 actual_size = count + 883 actual_size = count +
852 (priv->pkt_fmt == packet_format_1 ? 2 : 1); 884 (priv->pkt_fmt == packet_format_1 ? 2 : 1);
853 885
854 usb_serial_debug_data(debug, &port->dev, __func__, port->interrupt_out_size, 886 usb_serial_debug_data(debug, &port->dev, __func__,
855 port->interrupt_out_urb->transfer_buffer); 887 port->interrupt_out_size,
888 port->interrupt_out_urb->transfer_buffer);
856 889
857 usb_fill_int_urb(port->interrupt_out_urb, port->serial->dev, 890 usb_fill_int_urb(port->interrupt_out_urb, port->serial->dev,
858 usb_sndintpipe(port->serial->dev, port->interrupt_out_endpointAddress), 891 usb_sndintpipe(port->serial->dev, port->interrupt_out_endpointAddress),
859 port->interrupt_out_buffer, port->interrupt_out_size, 892 port->interrupt_out_buffer, port->interrupt_out_size,
860 cypress_write_int_callback, port, priv->write_urb_interval); 893 cypress_write_int_callback, port, priv->write_urb_interval);
861 result = usb_submit_urb (port->interrupt_out_urb, GFP_ATOMIC); 894 result = usb_submit_urb(port->interrupt_out_urb, GFP_ATOMIC);
862 if (result) { 895 if (result) {
863 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __func__, 896 dev_err(&port->dev,
864 result); 897 "%s - failed submitting write urb, error %d\n",
898 __func__, result);
865 priv->write_urb_in_use = 0; 899 priv->write_urb_in_use = 0;
866 cypress_set_dead(port); 900 cypress_set_dead(port);
867 } 901 }
868 902
869 spin_lock_irqsave(&priv->lock, flags); 903 spin_lock_irqsave(&priv->lock, flags);
870 if (priv->cmd_ctrl) { 904 if (priv->cmd_ctrl)
871 priv->cmd_ctrl = 0; 905 priv->cmd_ctrl = 0;
872 } 906
873 priv->bytes_out += count; /* do not count the line control and size bytes */ 907 /* do not count the line control and size bytes */
908 priv->bytes_out += count;
874 spin_unlock_irqrestore(&priv->lock, flags); 909 spin_unlock_irqrestore(&priv->lock, flags);
875 910
876 usb_serial_port_softint(port); 911 usb_serial_port_softint(port);
@@ -878,8 +913,9 @@ send:
878 913
879 914
880/* returns how much space is available in the soft buffer */ 915/* returns how much space is available in the soft buffer */
881static int cypress_write_room(struct usb_serial_port *port) 916static int cypress_write_room(struct tty_struct *tty)
882{ 917{
918 struct usb_serial_port *port = tty->driver_data;
883 struct cypress_private *priv = usb_get_serial_port_data(port); 919 struct cypress_private *priv = usb_get_serial_port_data(port);
884 int room = 0; 920 int room = 0;
885 unsigned long flags; 921 unsigned long flags;
@@ -895,13 +931,14 @@ static int cypress_write_room(struct usb_serial_port *port)
895} 931}
896 932
897 933
898static int cypress_tiocmget (struct usb_serial_port *port, struct file *file) 934static int cypress_tiocmget(struct tty_struct *tty, struct file *file)
899{ 935{
936 struct usb_serial_port *port = tty->driver_data;
900 struct cypress_private *priv = usb_get_serial_port_data(port); 937 struct cypress_private *priv = usb_get_serial_port_data(port);
901 __u8 status, control; 938 __u8 status, control;
902 unsigned int result = 0; 939 unsigned int result = 0;
903 unsigned long flags; 940 unsigned long flags;
904 941
905 dbg("%s - port %d", __func__, port->number); 942 dbg("%s - port %d", __func__, port->number);
906 943
907 spin_lock_irqsave(&priv->lock, flags); 944 spin_lock_irqsave(&priv->lock, flags);
@@ -922,12 +959,13 @@ static int cypress_tiocmget (struct usb_serial_port *port, struct file *file)
922} 959}
923 960
924 961
925static int cypress_tiocmset (struct usb_serial_port *port, struct file *file, 962static int cypress_tiocmset(struct tty_struct *tty, struct file *file,
926 unsigned int set, unsigned int clear) 963 unsigned int set, unsigned int clear)
927{ 964{
965 struct usb_serial_port *port = tty->driver_data;
928 struct cypress_private *priv = usb_get_serial_port_data(port); 966 struct cypress_private *priv = usb_get_serial_port_data(port);
929 unsigned long flags; 967 unsigned long flags;
930 968
931 dbg("%s - port %d", __func__, port->number); 969 dbg("%s - port %d", __func__, port->number);
932 970
933 spin_lock_irqsave(&priv->lock, flags); 971 spin_lock_irqsave(&priv->lock, flags);
@@ -942,63 +980,60 @@ static int cypress_tiocmset (struct usb_serial_port *port, struct file *file,
942 priv->cmd_ctrl = 1; 980 priv->cmd_ctrl = 1;
943 spin_unlock_irqrestore(&priv->lock, flags); 981 spin_unlock_irqrestore(&priv->lock, flags);
944 982
945 return cypress_write(port, NULL, 0); 983 return cypress_write(tty, port, NULL, 0);
946} 984}
947 985
948 986
949static int cypress_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg) 987static int cypress_ioctl(struct tty_struct *tty, struct file *file,
988 unsigned int cmd, unsigned long arg)
950{ 989{
990 struct usb_serial_port *port = tty->driver_data;
951 struct cypress_private *priv = usb_get_serial_port_data(port); 991 struct cypress_private *priv = usb_get_serial_port_data(port);
952 992
953 dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd); 993 dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd);
954 994
955 switch (cmd) { 995 switch (cmd) {
956 /* This code comes from drivers/char/serial.c and ftdi_sio.c */ 996 /* This code comes from drivers/char/serial.c and ftdi_sio.c */
957 case TIOCMIWAIT: 997 case TIOCMIWAIT:
958 while (priv != NULL) { 998 while (priv != NULL) {
959 interruptible_sleep_on(&priv->delta_msr_wait); 999 interruptible_sleep_on(&priv->delta_msr_wait);
960 /* see if a signal did it */ 1000 /* see if a signal did it */
961 if (signal_pending(current)) 1001 if (signal_pending(current))
962 return -ERESTARTSYS; 1002 return -ERESTARTSYS;
963 else { 1003 else {
964 char diff = priv->diff_status; 1004 char diff = priv->diff_status;
965 1005 if (diff == 0)
966 if (diff == 0) { 1006 return -EIO; /* no change => error */
967 return -EIO; /* no change => error */ 1007
968 } 1008 /* consume all events */
969 1009 priv->diff_status = 0;
970 /* consume all events */ 1010
971 priv->diff_status = 0; 1011 /* return 0 if caller wanted to know about
972 1012 these bits */
973 /* return 0 if caller wanted to know about these bits */ 1013 if (((arg & TIOCM_RNG) && (diff & UART_RI)) ||
974 if ( ((arg & TIOCM_RNG) && (diff & UART_RI)) || 1014 ((arg & TIOCM_DSR) && (diff & UART_DSR)) ||
975 ((arg & TIOCM_DSR) && (diff & UART_DSR)) || 1015 ((arg & TIOCM_CD) && (diff & UART_CD)) ||
976 ((arg & TIOCM_CD) && (diff & UART_CD)) || 1016 ((arg & TIOCM_CTS) && (diff & UART_CTS)))
977 ((arg & TIOCM_CTS) && (diff & UART_CTS)) ) { 1017 return 0;
978 return 0; 1018 /* otherwise caller can't care less about what
979 } 1019 * happened, and so we continue to wait for
980 /* otherwise caller can't care less about what happened, 1020 * more events.
981 * and so we continue to wait for more events. 1021 */
982 */
983 }
984 } 1022 }
985 return 0; 1023 }
986 break; 1024 return 0;
987 default: 1025 default:
988 break; 1026 break;
989 } 1027 }
990
991 dbg("%s - arg not supported - it was 0x%04x - check include/asm/ioctls.h", __func__, cmd); 1028 dbg("%s - arg not supported - it was 0x%04x - check include/asm/ioctls.h", __func__, cmd);
992
993 return -ENOIOCTLCMD; 1029 return -ENOIOCTLCMD;
994} /* cypress_ioctl */ 1030} /* cypress_ioctl */
995 1031
996 1032
997static void cypress_set_termios (struct usb_serial_port *port, 1033static void cypress_set_termios(struct tty_struct *tty,
998 struct ktermios *old_termios) 1034 struct usb_serial_port *port, struct ktermios *old_termios)
999{ 1035{
1000 struct cypress_private *priv = usb_get_serial_port_data(port); 1036 struct cypress_private *priv = usb_get_serial_port_data(port);
1001 struct tty_struct *tty;
1002 int data_bits, stop_bits, parity_type, parity_enable; 1037 int data_bits, stop_bits, parity_type, parity_enable;
1003 unsigned cflag, iflag; 1038 unsigned cflag, iflag;
1004 unsigned long flags; 1039 unsigned long flags;
@@ -1007,8 +1042,6 @@ static void cypress_set_termios (struct usb_serial_port *port,
1007 1042
1008 dbg("%s - port %d", __func__, port->number); 1043 dbg("%s - port %d", __func__, port->number);
1009 1044
1010 tty = port->tty;
1011
1012 spin_lock_irqsave(&priv->lock, flags); 1045 spin_lock_irqsave(&priv->lock, flags);
1013 if (!priv->termios_initialized) { 1046 if (!priv->termios_initialized) {
1014 if (priv->chiptype == CT_EARTHMATE) { 1047 if (priv->chiptype == CT_EARTHMATE) {
@@ -1060,28 +1093,24 @@ static void cypress_set_termios (struct usb_serial_port *port,
1060 } else 1093 } else
1061 parity_enable = parity_type = 0; 1094 parity_enable = parity_type = 0;
1062 1095
1063 if (cflag & CSIZE) { 1096 switch (cflag & CSIZE) {
1064 switch (cflag & CSIZE) { 1097 case CS5:
1065 case CS5: 1098 data_bits = 0;
1066 data_bits = 0; 1099 break;
1067 break; 1100 case CS6:
1068 case CS6: 1101 data_bits = 1;
1069 data_bits = 1; 1102 break;
1070 break; 1103 case CS7:
1071 case CS7: 1104 data_bits = 2;
1072 data_bits = 2; 1105 break;
1073 break; 1106 case CS8:
1074 case CS8:
1075 data_bits = 3;
1076 break;
1077 default:
1078 err("%s - CSIZE was set, but not CS5-CS8",
1079 __func__);
1080 data_bits = 3;
1081 }
1082 } else
1083 data_bits = 3; 1107 data_bits = 3;
1084 1108 break;
1109 default:
1110 err("%s - CSIZE was set, but not CS5-CS8",
1111 __func__);
1112 data_bits = 3;
1113 }
1085 spin_lock_irqsave(&priv->lock, flags); 1114 spin_lock_irqsave(&priv->lock, flags);
1086 oldlines = priv->line_control; 1115 oldlines = priv->line_control;
1087 if ((cflag & CBAUD) == B0) { 1116 if ((cflag & CBAUD) == B0) {
@@ -1096,19 +1125,21 @@ static void cypress_set_termios (struct usb_serial_port *port,
1096 "%d data_bits (+5)", __func__, stop_bits, 1125 "%d data_bits (+5)", __func__, stop_bits,
1097 parity_enable, parity_type, data_bits); 1126 parity_enable, parity_type, data_bits);
1098 1127
1099 cypress_serial_control(port, tty_get_baud_rate(tty), data_bits, stop_bits, 1128 cypress_serial_control(tty, port, tty_get_baud_rate(tty),
1100 parity_enable, parity_type, 0, CYPRESS_SET_CONFIG); 1129 data_bits, stop_bits,
1130 parity_enable, parity_type,
1131 0, CYPRESS_SET_CONFIG);
1101 1132
1102 /* we perform a CYPRESS_GET_CONFIG so that the current settings are 1133 /* we perform a CYPRESS_GET_CONFIG so that the current settings are
1103 * filled into the private structure this should confirm that all is 1134 * filled into the private structure this should confirm that all is
1104 * working if it returns what we just set */ 1135 * working if it returns what we just set */
1105 cypress_serial_control(port, 0, 0, 0, 0, 0, 0, CYPRESS_GET_CONFIG); 1136 cypress_serial_control(tty, port, 0, 0, 0, 0, 0, 0, CYPRESS_GET_CONFIG);
1106 1137
1107 /* Here we can define custom tty settings for devices; the main tty 1138 /* Here we can define custom tty settings for devices; the main tty
1108 * termios flag base comes from empeg.c */ 1139 * termios flag base comes from empeg.c */
1109 1140
1110 spin_lock_irqsave(&priv->lock, flags); 1141 spin_lock_irqsave(&priv->lock, flags);
1111 if ( (priv->chiptype == CT_EARTHMATE) && (priv->baud_rate == 4800) ) { 1142 if (priv->chiptype == CT_EARTHMATE && priv->baud_rate == 4800) {
1112 dbg("Using custom termios settings for a baud rate of " 1143 dbg("Using custom termios settings for a baud rate of "
1113 "4800bps."); 1144 "4800bps.");
1114 /* define custom termios settings for NMEA protocol */ 1145 /* define custom termios settings for NMEA protocol */
@@ -1142,20 +1173,21 @@ static void cypress_set_termios (struct usb_serial_port *port,
1142 /* if necessary, set lines */ 1173 /* if necessary, set lines */
1143 if (linechange) { 1174 if (linechange) {
1144 priv->cmd_ctrl = 1; 1175 priv->cmd_ctrl = 1;
1145 cypress_write(port, NULL, 0); 1176 cypress_write(tty, port, NULL, 0);
1146 } 1177 }
1147} /* cypress_set_termios */ 1178} /* cypress_set_termios */
1148 1179
1149 1180
1150/* returns amount of data still left in soft buffer */ 1181/* returns amount of data still left in soft buffer */
1151static int cypress_chars_in_buffer(struct usb_serial_port *port) 1182static int cypress_chars_in_buffer(struct tty_struct *tty)
1152{ 1183{
1184 struct usb_serial_port *port = tty->driver_data;
1153 struct cypress_private *priv = usb_get_serial_port_data(port); 1185 struct cypress_private *priv = usb_get_serial_port_data(port);
1154 int chars = 0; 1186 int chars = 0;
1155 unsigned long flags; 1187 unsigned long flags;
1156 1188
1157 dbg("%s - port %d", __func__, port->number); 1189 dbg("%s - port %d", __func__, port->number);
1158 1190
1159 spin_lock_irqsave(&priv->lock, flags); 1191 spin_lock_irqsave(&priv->lock, flags);
1160 chars = cypress_buf_data_avail(priv->buf); 1192 chars = cypress_buf_data_avail(priv->buf);
1161 spin_unlock_irqrestore(&priv->lock, flags); 1193 spin_unlock_irqrestore(&priv->lock, flags);
@@ -1165,8 +1197,9 @@ static int cypress_chars_in_buffer(struct usb_serial_port *port)
1165} 1197}
1166 1198
1167 1199
1168static void cypress_throttle (struct usb_serial_port *port) 1200static void cypress_throttle(struct tty_struct *tty)
1169{ 1201{
1202 struct usb_serial_port *port = tty->driver_data;
1170 struct cypress_private *priv = usb_get_serial_port_data(port); 1203 struct cypress_private *priv = usb_get_serial_port_data(port);
1171 unsigned long flags; 1204 unsigned long flags;
1172 1205
@@ -1178,8 +1211,9 @@ static void cypress_throttle (struct usb_serial_port *port)
1178} 1211}
1179 1212
1180 1213
1181static void cypress_unthrottle (struct usb_serial_port *port) 1214static void cypress_unthrottle(struct tty_struct *tty)
1182{ 1215{
1216 struct usb_serial_port *port = tty->driver_data;
1183 struct cypress_private *priv = usb_get_serial_port_data(port); 1217 struct cypress_private *priv = usb_get_serial_port_data(port);
1184 int actually_throttled, result; 1218 int actually_throttled, result;
1185 unsigned long flags; 1219 unsigned long flags;
@@ -1232,12 +1266,13 @@ static void cypress_read_int_callback(struct urb *urb)
1232 /* precursor to disconnect so just go away */ 1266 /* precursor to disconnect so just go away */
1233 return; 1267 return;
1234 case -EPIPE: 1268 case -EPIPE:
1235 usb_clear_halt(port->serial->dev,0x81); 1269 usb_clear_halt(port->serial->dev, 0x81);
1236 break; 1270 break;
1237 default: 1271 default:
1238 /* something ugly is going on... */ 1272 /* something ugly is going on... */
1239 dev_err(&urb->dev->dev,"%s - unexpected nonzero read status received: %d\n", 1273 dev_err(&urb->dev->dev,
1240 __func__, status); 1274 "%s - unexpected nonzero read status received: %d\n",
1275 __func__, status);
1241 cypress_set_dead(port); 1276 cypress_set_dead(port);
1242 return; 1277 return;
1243 } 1278 }
@@ -1251,7 +1286,7 @@ static void cypress_read_int_callback(struct urb *urb)
1251 } 1286 }
1252 spin_unlock_irqrestore(&priv->lock, flags); 1287 spin_unlock_irqrestore(&priv->lock, flags);
1253 1288
1254 tty = port->tty; 1289 tty = port->port.tty;
1255 if (!tty) { 1290 if (!tty) {
1256 dbg("%s - bad tty pointer - exiting", __func__); 1291 dbg("%s - bad tty pointer - exiting", __func__);
1257 return; 1292 return;
@@ -1285,8 +1320,8 @@ static void cypress_read_int_callback(struct urb *urb)
1285 goto continue_read; 1320 goto continue_read;
1286 } 1321 }
1287 1322
1288 usb_serial_debug_data (debug, &port->dev, __func__, 1323 usb_serial_debug_data(debug, &port->dev, __func__,
1289 urb->actual_length, data); 1324 urb->actual_length, data);
1290 1325
1291 spin_lock_irqsave(&priv->lock, flags); 1326 spin_lock_irqsave(&priv->lock, flags);
1292 /* check to see if status has changed */ 1327 /* check to see if status has changed */
@@ -1327,7 +1362,7 @@ static void cypress_read_int_callback(struct urb *urb)
1327 data[i]); 1362 data[i]);
1328 tty_insert_flip_char(tty, data[i], tty_flag); 1363 tty_insert_flip_char(tty, data[i], tty_flag);
1329 } 1364 }
1330 tty_flip_buffer_push(port->tty); 1365 tty_flip_buffer_push(port->port.tty);
1331 } 1366 }
1332 1367
1333 spin_lock_irqsave(&priv->lock, flags); 1368 spin_lock_irqsave(&priv->lock, flags);
@@ -1339,13 +1374,14 @@ continue_read:
1339 1374
1340 /* Continue trying to always read... unless the port has closed. */ 1375 /* Continue trying to always read... unless the port has closed. */
1341 1376
1342 if (port->open_count > 0 && priv->comm_is_ok) { 1377 if (port->port.count > 0 && priv->comm_is_ok) {
1343 usb_fill_int_urb(port->interrupt_in_urb, port->serial->dev, 1378 usb_fill_int_urb(port->interrupt_in_urb, port->serial->dev,
1344 usb_rcvintpipe(port->serial->dev, 1379 usb_rcvintpipe(port->serial->dev,
1345 port->interrupt_in_endpointAddress), 1380 port->interrupt_in_endpointAddress),
1346 port->interrupt_in_urb->transfer_buffer, 1381 port->interrupt_in_urb->transfer_buffer,
1347 port->interrupt_in_urb->transfer_buffer_length, 1382 port->interrupt_in_urb->transfer_buffer_length,
1348 cypress_read_int_callback, port, priv->read_urb_interval); 1383 cypress_read_int_callback, port,
1384 priv->read_urb_interval);
1349 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); 1385 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
1350 if (result) { 1386 if (result) {
1351 dev_err(&urb->dev->dev, "%s - failed resubmitting " 1387 dev_err(&urb->dev->dev, "%s - failed resubmitting "
@@ -1369,42 +1405,43 @@ static void cypress_write_int_callback(struct urb *urb)
1369 dbg("%s - port %d", __func__, port->number); 1405 dbg("%s - port %d", __func__, port->number);
1370 1406
1371 switch (status) { 1407 switch (status) {
1372 case 0: 1408 case 0:
1373 /* success */ 1409 /* success */
1410 break;
1411 case -ECONNRESET:
1412 case -ENOENT:
1413 case -ESHUTDOWN:
1414 /* this urb is terminated, clean up */
1415 dbg("%s - urb shutting down with status: %d",
1416 __func__, status);
1417 priv->write_urb_in_use = 0;
1418 return;
1419 case -EPIPE: /* no break needed; clear halt and resubmit */
1420 if (!priv->comm_is_ok)
1374 break; 1421 break;
1375 case -ECONNRESET: 1422 usb_clear_halt(port->serial->dev, 0x02);
1376 case -ENOENT: 1423 /* error in the urb, so we have to resubmit it */
1377 case -ESHUTDOWN: 1424 dbg("%s - nonzero write bulk status received: %d",
1378 /* this urb is terminated, clean up */ 1425 __func__, status);
1379 dbg("%s - urb shutting down with status: %d", 1426 port->interrupt_out_urb->transfer_buffer_length = 1;
1380 __func__, status); 1427 port->interrupt_out_urb->dev = port->serial->dev;
1381 priv->write_urb_in_use = 0; 1428 result = usb_submit_urb(port->interrupt_out_urb, GFP_ATOMIC);
1429 if (!result)
1382 return; 1430 return;
1383 case -EPIPE: /* no break needed; clear halt and resubmit */ 1431 dev_err(&urb->dev->dev,
1384 if (!priv->comm_is_ok) 1432 "%s - failed resubmitting write urb, error %d\n",
1385 break; 1433 __func__, result);
1386 usb_clear_halt(port->serial->dev, 0x02); 1434 cypress_set_dead(port);
1387 /* error in the urb, so we have to resubmit it */ 1435 break;
1388 dbg("%s - nonzero write bulk status received: %d", 1436 default:
1389 __func__, status); 1437 dev_err(&urb->dev->dev,
1390 port->interrupt_out_urb->transfer_buffer_length = 1; 1438 "%s - unexpected nonzero write status received: %d\n",
1391 port->interrupt_out_urb->dev = port->serial->dev; 1439 __func__, status);
1392 result = usb_submit_urb(port->interrupt_out_urb, GFP_ATOMIC); 1440 cypress_set_dead(port);
1393 if (!result) 1441 break;
1394 return;
1395 dev_err(&urb->dev->dev, "%s - failed resubmitting write urb, error %d\n",
1396 __func__, result);
1397 cypress_set_dead(port);
1398 break;
1399 default:
1400 dev_err(&urb->dev->dev,"%s - unexpected nonzero write status received: %d\n",
1401 __func__, status);
1402 cypress_set_dead(port);
1403 break;
1404 } 1442 }
1405
1406 priv->write_urb_in_use = 0; 1443 priv->write_urb_in_use = 0;
1407 1444
1408 /* send any buffered data */ 1445 /* send any buffered data */
1409 cypress_send(port); 1446 cypress_send(port);
1410} 1447}
@@ -1486,7 +1523,8 @@ static void cypress_buf_clear(struct cypress_buf *cb)
1486static unsigned int cypress_buf_data_avail(struct cypress_buf *cb) 1523static unsigned int cypress_buf_data_avail(struct cypress_buf *cb)
1487{ 1524{
1488 if (cb != NULL) 1525 if (cb != NULL)
1489 return ((cb->buf_size + cb->buf_put - cb->buf_get) % cb->buf_size); 1526 return (cb->buf_size + cb->buf_put - cb->buf_get)
1527 % cb->buf_size;
1490 else 1528 else
1491 return 0; 1529 return 0;
1492} 1530}
@@ -1502,7 +1540,8 @@ static unsigned int cypress_buf_data_avail(struct cypress_buf *cb)
1502static unsigned int cypress_buf_space_avail(struct cypress_buf *cb) 1540static unsigned int cypress_buf_space_avail(struct cypress_buf *cb)
1503{ 1541{
1504 if (cb != NULL) 1542 if (cb != NULL)
1505 return ((cb->buf_size + cb->buf_get - cb->buf_put - 1) % cb->buf_size); 1543 return (cb->buf_size + cb->buf_get - cb->buf_put - 1)
1544 % cb->buf_size;
1506 else 1545 else
1507 return 0; 1546 return 0;
1508} 1547}
@@ -1602,9 +1641,9 @@ static unsigned int cypress_buf_get(struct cypress_buf *cb, char *buf,
1602static int __init cypress_init(void) 1641static int __init cypress_init(void)
1603{ 1642{
1604 int retval; 1643 int retval;
1605 1644
1606 dbg("%s", __func__); 1645 dbg("%s", __func__);
1607 1646
1608 retval = usb_serial_register(&cypress_earthmate_device); 1647 retval = usb_serial_register(&cypress_earthmate_device);
1609 if (retval) 1648 if (retval)
1610 goto failed_em_register; 1649 goto failed_em_register;
@@ -1632,23 +1671,23 @@ failed_em_register:
1632} 1671}
1633 1672
1634 1673
1635static void __exit cypress_exit (void) 1674static void __exit cypress_exit(void)
1636{ 1675{
1637 dbg("%s", __func__); 1676 dbg("%s", __func__);
1638 1677
1639 usb_deregister (&cypress_driver); 1678 usb_deregister(&cypress_driver);
1640 usb_serial_deregister (&cypress_earthmate_device); 1679 usb_serial_deregister(&cypress_earthmate_device);
1641 usb_serial_deregister (&cypress_hidcom_device); 1680 usb_serial_deregister(&cypress_hidcom_device);
1642 usb_serial_deregister (&cypress_ca42v2_device); 1681 usb_serial_deregister(&cypress_ca42v2_device);
1643} 1682}
1644 1683
1645 1684
1646module_init(cypress_init); 1685module_init(cypress_init);
1647module_exit(cypress_exit); 1686module_exit(cypress_exit);
1648 1687
1649MODULE_AUTHOR( DRIVER_AUTHOR ); 1688MODULE_AUTHOR(DRIVER_AUTHOR);
1650MODULE_DESCRIPTION( DRIVER_DESC ); 1689MODULE_DESCRIPTION(DRIVER_DESC);
1651MODULE_VERSION( DRIVER_VERSION ); 1690MODULE_VERSION(DRIVER_VERSION);
1652MODULE_LICENSE("GPL"); 1691MODULE_LICENSE("GPL");
1653 1692
1654module_param(debug, bool, S_IRUGO | S_IWUSR); 1693module_param(debug, bool, S_IRUGO | S_IWUSR);
diff --git a/drivers/usb/serial/cypress_m8.h b/drivers/usb/serial/cypress_m8.h
index 0388065bb794..e772b01ac3ac 100644
--- a/drivers/usb/serial/cypress_m8.h
+++ b/drivers/usb/serial/cypress_m8.h
@@ -54,7 +54,7 @@
54#define UART_DSR 0x20 /* data set ready - flow control - device to host */ 54#define UART_DSR 0x20 /* data set ready - flow control - device to host */
55#define CONTROL_RTS 0x10 /* request to send - flow control - host to device */ 55#define CONTROL_RTS 0x10 /* request to send - flow control - host to device */
56#define UART_CTS 0x10 /* clear to send - flow control - device to host */ 56#define UART_CTS 0x10 /* clear to send - flow control - device to host */
57#define UART_RI 0x10 /* ring indicator - modem - device to host */ 57#define UART_RI 0x10 /* ring indicator - modem - device to host */
58#define UART_CD 0x40 /* carrier detect - modem - device to host */ 58#define UART_CD 0x40 /* carrier detect - modem - device to host */
59#define CYP_ERROR 0x08 /* received from input report - device to host */ 59#define CYP_ERROR 0x08 /* received from input report - device to host */
60/* Note - the below has nothing to to with the "feature report" reset */ 60/* Note - the below has nothing to to with the "feature report" reset */
diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c
index 28bc6fcf44f0..240aad1acaab 100644
--- a/drivers/usb/serial/digi_acceleport.c
+++ b/drivers/usb/serial/digi_acceleport.c
@@ -15,7 +15,7 @@
15* Al Borchers (borchers@steinerpoint.com) 15* Al Borchers (borchers@steinerpoint.com)
16* 16*
17* (12/03/2001) gkh 17* (12/03/2001) gkh
18* switched to using port->open_count instead of private version. 18* switched to using port->port.count instead of private version.
19* Removed port->active 19* Removed port->active
20* 20*
21* (04/08/2001) gb 21* (04/08/2001) gb
@@ -241,7 +241,7 @@
241#include <linux/module.h> 241#include <linux/module.h>
242#include <linux/spinlock.h> 242#include <linux/spinlock.h>
243#include <linux/workqueue.h> 243#include <linux/workqueue.h>
244#include <asm/uaccess.h> 244#include <linux/uaccess.h>
245#include <linux/usb.h> 245#include <linux/usb.h>
246#include <linux/wait.h> 246#include <linux/wait.h>
247#include <linux/usb/serial.h> 247#include <linux/usb/serial.h>
@@ -441,22 +441,23 @@ static int digi_set_modem_signals(struct usb_serial_port *port,
441 unsigned int modem_signals, int interruptible); 441 unsigned int modem_signals, int interruptible);
442static int digi_transmit_idle(struct usb_serial_port *port, 442static int digi_transmit_idle(struct usb_serial_port *port,
443 unsigned long timeout); 443 unsigned long timeout);
444static void digi_rx_throttle (struct usb_serial_port *port); 444static void digi_rx_throttle(struct tty_struct *tty);
445static void digi_rx_unthrottle (struct usb_serial_port *port); 445static void digi_rx_unthrottle(struct tty_struct *tty);
446static void digi_set_termios(struct usb_serial_port *port, 446static void digi_set_termios(struct tty_struct *tty,
447 struct ktermios *old_termios); 447 struct usb_serial_port *port, struct ktermios *old_termios);
448static void digi_break_ctl(struct usb_serial_port *port, int break_state); 448static void digi_break_ctl(struct tty_struct *tty, int break_state);
449static int digi_ioctl(struct usb_serial_port *port, struct file *file, 449static int digi_tiocmget(struct tty_struct *tty, struct file *file);
450 unsigned int cmd, unsigned long arg); 450static int digi_tiocmset(struct tty_struct *tty, struct file *file,
451static int digi_tiocmget(struct usb_serial_port *port, struct file *file);
452static int digi_tiocmset(struct usb_serial_port *port, struct file *file,
453 unsigned int set, unsigned int clear); 451 unsigned int set, unsigned int clear);
454static int digi_write(struct usb_serial_port *port, const unsigned char *buf, int count); 452static int digi_write(struct tty_struct *tty, struct usb_serial_port *port,
453 const unsigned char *buf, int count);
455static void digi_write_bulk_callback(struct urb *urb); 454static void digi_write_bulk_callback(struct urb *urb);
456static int digi_write_room(struct usb_serial_port *port); 455static int digi_write_room(struct tty_struct *tty);
457static int digi_chars_in_buffer(struct usb_serial_port *port); 456static int digi_chars_in_buffer(struct tty_struct *tty);
458static int digi_open(struct usb_serial_port *port, struct file *filp); 457static int digi_open(struct tty_struct *tty, struct usb_serial_port *port,
459static void digi_close(struct usb_serial_port *port, struct file *filp); 458 struct file *filp);
459static void digi_close(struct tty_struct *tty, struct usb_serial_port *port,
460 struct file *filp);
460static int digi_startup_device(struct usb_serial *serial); 461static int digi_startup_device(struct usb_serial *serial);
461static int digi_startup(struct usb_serial *serial); 462static int digi_startup(struct usb_serial *serial);
462static void digi_shutdown(struct usb_serial *serial); 463static void digi_shutdown(struct usb_serial *serial);
@@ -485,7 +486,7 @@ static struct usb_device_id id_table_4 [] = {
485 { } /* Terminating entry */ 486 { } /* Terminating entry */
486}; 487};
487 488
488MODULE_DEVICE_TABLE (usb, id_table_combined); 489MODULE_DEVICE_TABLE(usb, id_table_combined);
489 490
490static struct usb_driver digi_driver = { 491static struct usb_driver digi_driver = {
491 .name = "digi_acceleport", 492 .name = "digi_acceleport",
@@ -516,7 +517,6 @@ static struct usb_serial_driver digi_acceleport_2_device = {
516 .chars_in_buffer = digi_chars_in_buffer, 517 .chars_in_buffer = digi_chars_in_buffer,
517 .throttle = digi_rx_throttle, 518 .throttle = digi_rx_throttle,
518 .unthrottle = digi_rx_unthrottle, 519 .unthrottle = digi_rx_unthrottle,
519 .ioctl = digi_ioctl,
520 .set_termios = digi_set_termios, 520 .set_termios = digi_set_termios,
521 .break_ctl = digi_break_ctl, 521 .break_ctl = digi_break_ctl,
522 .tiocmget = digi_tiocmget, 522 .tiocmget = digi_tiocmget,
@@ -543,7 +543,6 @@ static struct usb_serial_driver digi_acceleport_4_device = {
543 .chars_in_buffer = digi_chars_in_buffer, 543 .chars_in_buffer = digi_chars_in_buffer,
544 .throttle = digi_rx_throttle, 544 .throttle = digi_rx_throttle,
545 .unthrottle = digi_rx_unthrottle, 545 .unthrottle = digi_rx_unthrottle,
546 .ioctl = digi_ioctl,
547 .set_termios = digi_set_termios, 546 .set_termios = digi_set_termios,
548 .break_ctl = digi_break_ctl, 547 .break_ctl = digi_break_ctl,
549 .tiocmget = digi_tiocmget, 548 .tiocmget = digi_tiocmget,
@@ -556,17 +555,17 @@ static struct usb_serial_driver digi_acceleport_4_device = {
556/* Functions */ 555/* Functions */
557 556
558/* 557/*
559* Cond Wait Interruptible Timeout Irqrestore 558 * Cond Wait Interruptible Timeout Irqrestore
560* 559 *
561* Do spin_unlock_irqrestore and interruptible_sleep_on_timeout 560 * Do spin_unlock_irqrestore and interruptible_sleep_on_timeout
562* so that wake ups are not lost if they occur between the unlock 561 * so that wake ups are not lost if they occur between the unlock
563* and the sleep. In other words, spin_unlock_irqrestore and 562 * and the sleep. In other words, spin_unlock_irqrestore and
564* interruptible_sleep_on_timeout are "atomic" with respect to 563 * interruptible_sleep_on_timeout are "atomic" with respect to
565* wake ups. This is used to implement condition variables. 564 * wake ups. This is used to implement condition variables.
566* 565 *
567* interruptible_sleep_on_timeout is deprecated and has been replaced 566 * interruptible_sleep_on_timeout is deprecated and has been replaced
568* with the equivalent code. 567 * with the equivalent code.
569*/ 568 */
570 569
571static long cond_wait_interruptible_timeout_irqrestore( 570static long cond_wait_interruptible_timeout_irqrestore(
572 wait_queue_head_t *q, long timeout, 571 wait_queue_head_t *q, long timeout,
@@ -585,15 +584,16 @@ __releases(lock)
585 584
586 585
587/* 586/*
588* Digi Wakeup Write 587 * Digi Wakeup Write
589* 588 *
590* Wake up port, line discipline, and tty processes sleeping 589 * Wake up port, line discipline, and tty processes sleeping
591* on writes. 590 * on writes.
592*/ 591 */
593 592
594static void digi_wakeup_write_lock(struct work_struct *work) 593static void digi_wakeup_write_lock(struct work_struct *work)
595{ 594{
596 struct digi_port *priv = container_of(work, struct digi_port, dp_wakeup_work); 595 struct digi_port *priv =
596 container_of(work, struct digi_port, dp_wakeup_work);
597 struct usb_serial_port *port = priv->dp_port; 597 struct usb_serial_port *port = priv->dp_port;
598 unsigned long flags; 598 unsigned long flags;
599 599
@@ -604,20 +604,20 @@ static void digi_wakeup_write_lock(struct work_struct *work)
604 604
605static void digi_wakeup_write(struct usb_serial_port *port) 605static void digi_wakeup_write(struct usb_serial_port *port)
606{ 606{
607 tty_wakeup(port->tty); 607 tty_wakeup(port->port.tty);
608} 608}
609 609
610 610
611/* 611/*
612* Digi Write OOB Command 612 * Digi Write OOB Command
613* 613 *
614* Write commands on the out of band port. Commands are 4 614 * Write commands on the out of band port. Commands are 4
615* bytes each, multiple commands can be sent at once, and 615 * bytes each, multiple commands can be sent at once, and
616* no command will be split across USB packets. Returns 0 616 * no command will be split across USB packets. Returns 0
617* if successful, -EINTR if interrupted while sleeping and 617 * if successful, -EINTR if interrupted while sleeping and
618* the interruptible flag is true, or a negative error 618 * the interruptible flag is true, or a negative error
619* returned by usb_submit_urb. 619 * returned by usb_submit_urb.
620*/ 620 */
621 621
622static int digi_write_oob_command(struct usb_serial_port *port, 622static int digi_write_oob_command(struct usb_serial_port *port,
623 unsigned char *buf, int count, int interruptible) 623 unsigned char *buf, int count, int interruptible)
@@ -632,8 +632,8 @@ static int digi_write_oob_command(struct usb_serial_port *port,
632 dbg("digi_write_oob_command: TOP: port=%d, count=%d", oob_priv->dp_port_num, count); 632 dbg("digi_write_oob_command: TOP: port=%d, count=%d", oob_priv->dp_port_num, count);
633 633
634 spin_lock_irqsave(&oob_priv->dp_port_lock, flags); 634 spin_lock_irqsave(&oob_priv->dp_port_lock, flags);
635 while(count > 0) { 635 while (count > 0) {
636 while(oob_port->write_urb->status == -EINPROGRESS 636 while (oob_port->write_urb->status == -EINPROGRESS
637 || oob_priv->dp_write_urb_in_use) { 637 || oob_priv->dp_write_urb_in_use) {
638 cond_wait_interruptible_timeout_irqrestore( 638 cond_wait_interruptible_timeout_irqrestore(
639 &oob_port->write_wait, DIGI_RETRY_TIMEOUT, 639 &oob_port->write_wait, DIGI_RETRY_TIMEOUT,
@@ -650,7 +650,8 @@ static int digi_write_oob_command(struct usb_serial_port *port,
650 memcpy(oob_port->write_urb->transfer_buffer, buf, len); 650 memcpy(oob_port->write_urb->transfer_buffer, buf, len);
651 oob_port->write_urb->transfer_buffer_length = len; 651 oob_port->write_urb->transfer_buffer_length = len;
652 oob_port->write_urb->dev = port->serial->dev; 652 oob_port->write_urb->dev = port->serial->dev;
653 if ((ret = usb_submit_urb(oob_port->write_urb, GFP_ATOMIC)) == 0) { 653 ret = usb_submit_urb(oob_port->write_urb, GFP_ATOMIC);
654 if (ret == 0) {
654 oob_priv->dp_write_urb_in_use = 1; 655 oob_priv->dp_write_urb_in_use = 1;
655 count -= len; 656 count -= len;
656 buf += len; 657 buf += len;
@@ -665,16 +666,16 @@ static int digi_write_oob_command(struct usb_serial_port *port,
665 666
666 667
667/* 668/*
668* Digi Write In Band Command 669 * Digi Write In Band Command
669* 670 *
670* Write commands on the given port. Commands are 4 671 * Write commands on the given port. Commands are 4
671* bytes each, multiple commands can be sent at once, and 672 * bytes each, multiple commands can be sent at once, and
672* no command will be split across USB packets. If timeout 673 * no command will be split across USB packets. If timeout
673* is non-zero, write in band command will return after 674 * is non-zero, write in band command will return after
674* waiting unsuccessfully for the URB status to clear for 675 * waiting unsuccessfully for the URB status to clear for
675* timeout ticks. Returns 0 if successful, or a negative 676 * timeout ticks. Returns 0 if successful, or a negative
676* error returned by digi_write. 677 * error returned by digi_write.
677*/ 678 */
678 679
679static int digi_write_inb_command(struct usb_serial_port *port, 680static int digi_write_inb_command(struct usb_serial_port *port,
680 unsigned char *buf, int count, unsigned long timeout) 681 unsigned char *buf, int count, unsigned long timeout)
@@ -694,9 +695,10 @@ static int digi_write_inb_command(struct usb_serial_port *port,
694 timeout = ULONG_MAX; 695 timeout = ULONG_MAX;
695 696
696 spin_lock_irqsave(&priv->dp_port_lock, flags); 697 spin_lock_irqsave(&priv->dp_port_lock, flags);
697 while(count > 0 && ret == 0) { 698 while (count > 0 && ret == 0) {
698 while((port->write_urb->status == -EINPROGRESS 699 while ((port->write_urb->status == -EINPROGRESS
699 || priv->dp_write_urb_in_use) && time_before(jiffies, timeout)) { 700 || priv->dp_write_urb_in_use)
701 && time_before(jiffies, timeout)) {
700 cond_wait_interruptible_timeout_irqrestore( 702 cond_wait_interruptible_timeout_irqrestore(
701 &port->write_wait, DIGI_RETRY_TIMEOUT, 703 &port->write_wait, DIGI_RETRY_TIMEOUT,
702 &priv->dp_port_lock, flags); 704 &priv->dp_port_lock, flags);
@@ -727,7 +729,8 @@ static int digi_write_inb_command(struct usb_serial_port *port,
727 } 729 }
728 port->write_urb->dev = port->serial->dev; 730 port->write_urb->dev = port->serial->dev;
729 731
730 if ((ret = usb_submit_urb(port->write_urb, GFP_ATOMIC)) == 0) { 732 ret = usb_submit_urb(port->write_urb, GFP_ATOMIC);
733 if (ret == 0) {
731 priv->dp_write_urb_in_use = 1; 734 priv->dp_write_urb_in_use = 1;
732 priv->dp_out_buf_len = 0; 735 priv->dp_out_buf_len = 0;
733 count -= len; 736 count -= len;
@@ -745,14 +748,14 @@ static int digi_write_inb_command(struct usb_serial_port *port,
745 748
746 749
747/* 750/*
748* Digi Set Modem Signals 751 * Digi Set Modem Signals
749* 752 *
750* Sets or clears DTR and RTS on the port, according to the 753 * Sets or clears DTR and RTS on the port, according to the
751* modem_signals argument. Use TIOCM_DTR and TIOCM_RTS flags 754 * modem_signals argument. Use TIOCM_DTR and TIOCM_RTS flags
752* for the modem_signals argument. Returns 0 if successful, 755 * for the modem_signals argument. Returns 0 if successful,
753* -EINTR if interrupted while sleeping, or a non-zero error 756 * -EINTR if interrupted while sleeping, or a non-zero error
754* returned by usb_submit_urb. 757 * returned by usb_submit_urb.
755*/ 758 */
756 759
757static int digi_set_modem_signals(struct usb_serial_port *port, 760static int digi_set_modem_signals(struct usb_serial_port *port,
758 unsigned int modem_signals, int interruptible) 761 unsigned int modem_signals, int interruptible)
@@ -760,7 +763,7 @@ static int digi_set_modem_signals(struct usb_serial_port *port,
760 763
761 int ret; 764 int ret;
762 struct digi_port *port_priv = usb_get_serial_port_data(port); 765 struct digi_port *port_priv = usb_get_serial_port_data(port);
763 struct usb_serial_port *oob_port = (struct usb_serial_port *)((struct digi_serial *)(usb_get_serial_data(port->serial)))->ds_oob_port; 766 struct usb_serial_port *oob_port = (struct usb_serial_port *) ((struct digi_serial *)(usb_get_serial_data(port->serial)))->ds_oob_port;
764 struct digi_port *oob_priv = usb_get_serial_port_data(oob_port); 767 struct digi_port *oob_priv = usb_get_serial_port_data(oob_port);
765 unsigned char *data = oob_port->write_urb->transfer_buffer; 768 unsigned char *data = oob_port->write_urb->transfer_buffer;
766 unsigned long flags = 0; 769 unsigned long flags = 0;
@@ -772,7 +775,8 @@ static int digi_set_modem_signals(struct usb_serial_port *port,
772 spin_lock_irqsave(&oob_priv->dp_port_lock, flags); 775 spin_lock_irqsave(&oob_priv->dp_port_lock, flags);
773 spin_lock(&port_priv->dp_port_lock); 776 spin_lock(&port_priv->dp_port_lock);
774 777
775 while(oob_port->write_urb->status == -EINPROGRESS || oob_priv->dp_write_urb_in_use) { 778 while (oob_port->write_urb->status == -EINPROGRESS ||
779 oob_priv->dp_write_urb_in_use) {
776 spin_unlock(&port_priv->dp_port_lock); 780 spin_unlock(&port_priv->dp_port_lock);
777 cond_wait_interruptible_timeout_irqrestore( 781 cond_wait_interruptible_timeout_irqrestore(
778 &oob_port->write_wait, DIGI_RETRY_TIMEOUT, 782 &oob_port->write_wait, DIGI_RETRY_TIMEOUT,
@@ -784,17 +788,20 @@ static int digi_set_modem_signals(struct usb_serial_port *port,
784 } 788 }
785 data[0] = DIGI_CMD_SET_DTR_SIGNAL; 789 data[0] = DIGI_CMD_SET_DTR_SIGNAL;
786 data[1] = port_priv->dp_port_num; 790 data[1] = port_priv->dp_port_num;
787 data[2] = (modem_signals&TIOCM_DTR) ? DIGI_DTR_ACTIVE : DIGI_DTR_INACTIVE; 791 data[2] = (modem_signals & TIOCM_DTR) ?
792 DIGI_DTR_ACTIVE : DIGI_DTR_INACTIVE;
788 data[3] = 0; 793 data[3] = 0;
789 data[4] = DIGI_CMD_SET_RTS_SIGNAL; 794 data[4] = DIGI_CMD_SET_RTS_SIGNAL;
790 data[5] = port_priv->dp_port_num; 795 data[5] = port_priv->dp_port_num;
791 data[6] = (modem_signals&TIOCM_RTS) ? DIGI_RTS_ACTIVE : DIGI_RTS_INACTIVE; 796 data[6] = (modem_signals & TIOCM_RTS) ?
797 DIGI_RTS_ACTIVE : DIGI_RTS_INACTIVE;
792 data[7] = 0; 798 data[7] = 0;
793 799
794 oob_port->write_urb->transfer_buffer_length = 8; 800 oob_port->write_urb->transfer_buffer_length = 8;
795 oob_port->write_urb->dev = port->serial->dev; 801 oob_port->write_urb->dev = port->serial->dev;
796 802
797 if ((ret = usb_submit_urb(oob_port->write_urb, GFP_ATOMIC)) == 0) { 803 ret = usb_submit_urb(oob_port->write_urb, GFP_ATOMIC);
804 if (ret == 0) {
798 oob_priv->dp_write_urb_in_use = 1; 805 oob_priv->dp_write_urb_in_use = 1;
799 port_priv->dp_modem_signals = 806 port_priv->dp_modem_signals =
800 (port_priv->dp_modem_signals&~(TIOCM_DTR|TIOCM_RTS)) 807 (port_priv->dp_modem_signals&~(TIOCM_DTR|TIOCM_RTS))
@@ -808,16 +815,16 @@ static int digi_set_modem_signals(struct usb_serial_port *port,
808} 815}
809 816
810/* 817/*
811* Digi Transmit Idle 818 * Digi Transmit Idle
812* 819 *
813* Digi transmit idle waits, up to timeout ticks, for the transmitter 820 * Digi transmit idle waits, up to timeout ticks, for the transmitter
814* to go idle. It returns 0 if successful or a negative error. 821 * to go idle. It returns 0 if successful or a negative error.
815* 822 *
816* There are race conditions here if more than one process is calling 823 * There are race conditions here if more than one process is calling
817* digi_transmit_idle on the same port at the same time. However, this 824 * digi_transmit_idle on the same port at the same time. However, this
818* is only called from close, and only one process can be in close on a 825 * is only called from close, and only one process can be in close on a
819* port at a time, so its ok. 826 * port at a time, so its ok.
820*/ 827 */
821 828
822static int digi_transmit_idle(struct usb_serial_port *port, 829static int digi_transmit_idle(struct usb_serial_port *port,
823 unsigned long timeout) 830 unsigned long timeout)
@@ -836,12 +843,13 @@ static int digi_transmit_idle(struct usb_serial_port *port,
836 843
837 timeout += jiffies; 844 timeout += jiffies;
838 845
839 if ((ret = digi_write_inb_command(port, buf, 2, timeout - jiffies)) != 0) 846 ret = digi_write_inb_command(port, buf, 2, timeout - jiffies);
847 if (ret != 0)
840 return ret; 848 return ret;
841 849
842 spin_lock_irqsave(&priv->dp_port_lock, flags); 850 spin_lock_irqsave(&priv->dp_port_lock, flags);
843 851
844 while(time_before(jiffies, timeout) && !priv->dp_transmit_idle) { 852 while (time_before(jiffies, timeout) && !priv->dp_transmit_idle) {
845 cond_wait_interruptible_timeout_irqrestore( 853 cond_wait_interruptible_timeout_irqrestore(
846 &priv->dp_transmit_idle_wait, DIGI_RETRY_TIMEOUT, 854 &priv->dp_transmit_idle_wait, DIGI_RETRY_TIMEOUT,
847 &priv->dp_port_lock, flags); 855 &priv->dp_port_lock, flags);
@@ -856,9 +864,10 @@ static int digi_transmit_idle(struct usb_serial_port *port,
856} 864}
857 865
858 866
859static void digi_rx_throttle(struct usb_serial_port *port) 867static void digi_rx_throttle(struct tty_struct *tty)
860{ 868{
861 unsigned long flags; 869 unsigned long flags;
870 struct usb_serial_port *port = tty->driver_data;
862 struct digi_port *priv = usb_get_serial_port_data(port); 871 struct digi_port *priv = usb_get_serial_port_data(port);
863 872
864 873
@@ -872,10 +881,11 @@ static void digi_rx_throttle(struct usb_serial_port *port)
872} 881}
873 882
874 883
875static void digi_rx_unthrottle(struct usb_serial_port *port) 884static void digi_rx_unthrottle(struct tty_struct *tty)
876{ 885{
877 int ret = 0; 886 int ret = 0;
878 unsigned long flags; 887 unsigned long flags;
888 struct usb_serial_port *port = tty->driver_data;
879 struct digi_port *priv = usb_get_serial_port_data(port); 889 struct digi_port *priv = usb_get_serial_port_data(port);
880 890
881 dbg("digi_rx_unthrottle: TOP: port=%d", priv->dp_port_num); 891 dbg("digi_rx_unthrottle: TOP: port=%d", priv->dp_port_num);
@@ -900,26 +910,25 @@ static void digi_rx_unthrottle(struct usb_serial_port *port)
900} 910}
901 911
902 912
903static void digi_set_termios(struct usb_serial_port *port, 913static void digi_set_termios(struct tty_struct *tty,
904 struct ktermios *old_termios) 914 struct usb_serial_port *port, struct ktermios *old_termios)
905{ 915{
906
907 struct digi_port *priv = usb_get_serial_port_data(port); 916 struct digi_port *priv = usb_get_serial_port_data(port);
908 struct tty_struct *tty = port->tty;
909 unsigned int iflag = tty->termios->c_iflag; 917 unsigned int iflag = tty->termios->c_iflag;
910 unsigned int cflag = tty->termios->c_cflag; 918 unsigned int cflag = tty->termios->c_cflag;
911 unsigned int old_iflag = old_termios->c_iflag; 919 unsigned int old_iflag = old_termios->c_iflag;
912 unsigned int old_cflag = old_termios->c_cflag; 920 unsigned int old_cflag = old_termios->c_cflag;
913 unsigned char buf[32]; 921 unsigned char buf[32];
914 unsigned int modem_signals; 922 unsigned int modem_signals;
915 int arg,ret; 923 int arg, ret;
916 int i = 0; 924 int i = 0;
917 speed_t baud; 925 speed_t baud;
918 926
919 dbg("digi_set_termios: TOP: port=%d, iflag=0x%x, old_iflag=0x%x, cflag=0x%x, old_cflag=0x%x", priv->dp_port_num, iflag, old_iflag, cflag, old_cflag); 927 dbg("digi_set_termios: TOP: port=%d, iflag=0x%x, old_iflag=0x%x, cflag=0x%x, old_cflag=0x%x", priv->dp_port_num, iflag, old_iflag, cflag, old_cflag);
920 928
921 /* set baud rate */ 929 /* set baud rate */
922 if ((baud = tty_get_baud_rate(tty)) != tty_termios_baud_rate(old_termios)) { 930 baud = tty_get_baud_rate(tty);
931 if (baud != tty_termios_baud_rate(old_termios)) {
923 arg = -1; 932 arg = -1;
924 933
925 /* reassert DTR and (maybe) RTS on transition from B0 */ 934 /* reassert DTR and (maybe) RTS on transition from B0 */
@@ -933,30 +942,30 @@ static void digi_set_termios(struct usb_serial_port *port,
933 digi_set_modem_signals(port, modem_signals, 1); 942 digi_set_modem_signals(port, modem_signals, 1);
934 } 943 }
935 switch (baud) { 944 switch (baud) {
936 /* drop DTR and RTS on transition to B0 */ 945 /* drop DTR and RTS on transition to B0 */
937 case 0: digi_set_modem_signals(port, 0, 1); break; 946 case 0: digi_set_modem_signals(port, 0, 1); break;
938 case 50: arg = DIGI_BAUD_50; break; 947 case 50: arg = DIGI_BAUD_50; break;
939 case 75: arg = DIGI_BAUD_75; break; 948 case 75: arg = DIGI_BAUD_75; break;
940 case 110: arg = DIGI_BAUD_110; break; 949 case 110: arg = DIGI_BAUD_110; break;
941 case 150: arg = DIGI_BAUD_150; break; 950 case 150: arg = DIGI_BAUD_150; break;
942 case 200: arg = DIGI_BAUD_200; break; 951 case 200: arg = DIGI_BAUD_200; break;
943 case 300: arg = DIGI_BAUD_300; break; 952 case 300: arg = DIGI_BAUD_300; break;
944 case 600: arg = DIGI_BAUD_600; break; 953 case 600: arg = DIGI_BAUD_600; break;
945 case 1200: arg = DIGI_BAUD_1200; break; 954 case 1200: arg = DIGI_BAUD_1200; break;
946 case 1800: arg = DIGI_BAUD_1800; break; 955 case 1800: arg = DIGI_BAUD_1800; break;
947 case 2400: arg = DIGI_BAUD_2400; break; 956 case 2400: arg = DIGI_BAUD_2400; break;
948 case 4800: arg = DIGI_BAUD_4800; break; 957 case 4800: arg = DIGI_BAUD_4800; break;
949 case 9600: arg = DIGI_BAUD_9600; break; 958 case 9600: arg = DIGI_BAUD_9600; break;
950 case 19200: arg = DIGI_BAUD_19200; break; 959 case 19200: arg = DIGI_BAUD_19200; break;
951 case 38400: arg = DIGI_BAUD_38400; break; 960 case 38400: arg = DIGI_BAUD_38400; break;
952 case 57600: arg = DIGI_BAUD_57600; break; 961 case 57600: arg = DIGI_BAUD_57600; break;
953 case 115200: arg = DIGI_BAUD_115200; break; 962 case 115200: arg = DIGI_BAUD_115200; break;
954 case 230400: arg = DIGI_BAUD_230400; break; 963 case 230400: arg = DIGI_BAUD_230400; break;
955 case 460800: arg = DIGI_BAUD_460800; break; 964 case 460800: arg = DIGI_BAUD_460800; break;
956 default: 965 default:
957 arg = DIGI_BAUD_9600; 966 arg = DIGI_BAUD_9600;
958 baud = 9600; 967 baud = 9600;
959 break; 968 break;
960 } 969 }
961 if (arg != -1) { 970 if (arg != -1) {
962 buf[i++] = DIGI_CMD_SET_BAUD_RATE; 971 buf[i++] = DIGI_CMD_SET_BAUD_RATE;
@@ -1082,14 +1091,16 @@ static void digi_set_termios(struct usb_serial_port *port,
1082 buf[i++] = arg; 1091 buf[i++] = arg;
1083 buf[i++] = 0; 1092 buf[i++] = 0;
1084 } 1093 }
1085 if ((ret = digi_write_oob_command(port, buf, i, 1)) != 0) 1094 ret = digi_write_oob_command(port, buf, i, 1);
1095 if (ret != 0)
1086 dbg("digi_set_termios: write oob failed, ret=%d", ret); 1096 dbg("digi_set_termios: write oob failed, ret=%d", ret);
1087 tty_encode_baud_rate(tty, baud, baud); 1097 tty_encode_baud_rate(tty, baud, baud);
1088} 1098}
1089 1099
1090 1100
1091static void digi_break_ctl(struct usb_serial_port *port, int break_state) 1101static void digi_break_ctl(struct tty_struct *tty, int break_state)
1092{ 1102{
1103 struct usb_serial_port *port = tty->driver_data;
1093 unsigned char buf[4]; 1104 unsigned char buf[4];
1094 1105
1095 buf[0] = DIGI_CMD_BREAK_CONTROL; 1106 buf[0] = DIGI_CMD_BREAK_CONTROL;
@@ -1100,8 +1111,9 @@ static void digi_break_ctl(struct usb_serial_port *port, int break_state)
1100} 1111}
1101 1112
1102 1113
1103static int digi_tiocmget(struct usb_serial_port *port, struct file *file) 1114static int digi_tiocmget(struct tty_struct *tty, struct file *file)
1104{ 1115{
1116 struct usb_serial_port *port = tty->driver_data;
1105 struct digi_port *priv = usb_get_serial_port_data(port); 1117 struct digi_port *priv = usb_get_serial_port_data(port);
1106 unsigned int val; 1118 unsigned int val;
1107 unsigned long flags; 1119 unsigned long flags;
@@ -1115,9 +1127,10 @@ static int digi_tiocmget(struct usb_serial_port *port, struct file *file)
1115} 1127}
1116 1128
1117 1129
1118static int digi_tiocmset(struct usb_serial_port *port, struct file *file, 1130static int digi_tiocmset(struct tty_struct *tty, struct file *file,
1119 unsigned int set, unsigned int clear) 1131 unsigned int set, unsigned int clear)
1120{ 1132{
1133 struct usb_serial_port *port = tty->driver_data;
1121 struct digi_port *priv = usb_get_serial_port_data(port); 1134 struct digi_port *priv = usb_get_serial_port_data(port);
1122 unsigned int val; 1135 unsigned int val;
1123 unsigned long flags; 1136 unsigned long flags;
@@ -1131,30 +1144,11 @@ static int digi_tiocmset(struct usb_serial_port *port, struct file *file,
1131} 1144}
1132 1145
1133 1146
1134static int digi_ioctl(struct usb_serial_port *port, struct file *file, 1147static int digi_write(struct tty_struct *tty, struct usb_serial_port *port,
1135 unsigned int cmd, unsigned long arg) 1148 const unsigned char *buf, int count)
1136{
1137 struct digi_port *priv = usb_get_serial_port_data(port);
1138 dbg("digi_ioctl: TOP: port=%d, cmd=0x%x", priv->dp_port_num, cmd);
1139
1140 switch (cmd) {
1141 case TIOCMIWAIT:
1142 /* wait for any of the 4 modem inputs (DCD,RI,DSR,CTS)*/
1143 /* TODO */
1144 return 0;
1145 case TIOCGICOUNT:
1146 /* return count of modemline transitions */
1147 /* TODO */
1148 return 0;
1149 }
1150 return -ENOIOCTLCMD;
1151
1152}
1153
1154static int digi_write(struct usb_serial_port *port, const unsigned char *buf, int count)
1155{ 1149{
1156 1150
1157 int ret,data_len,new_len; 1151 int ret, data_len, new_len;
1158 struct digi_port *priv = usb_get_serial_port_data(port); 1152 struct digi_port *priv = usb_get_serial_port_data(port);
1159 unsigned char *data = port->write_urb->transfer_buffer; 1153 unsigned char *data = port->write_urb->transfer_buffer;
1160 unsigned long flags = 0; 1154 unsigned long flags = 0;
@@ -1172,7 +1166,8 @@ static int digi_write(struct usb_serial_port *port, const unsigned char *buf, in
1172 spin_lock_irqsave(&priv->dp_port_lock, flags); 1166 spin_lock_irqsave(&priv->dp_port_lock, flags);
1173 1167
1174 /* wait for urb status clear to submit another urb */ 1168 /* wait for urb status clear to submit another urb */
1175 if (port->write_urb->status == -EINPROGRESS || priv->dp_write_urb_in_use) { 1169 if (port->write_urb->status == -EINPROGRESS ||
1170 priv->dp_write_urb_in_use) {
1176 /* buffer data if count is 1 (probably put_char) if possible */ 1171 /* buffer data if count is 1 (probably put_char) if possible */
1177 if (count == 1 && priv->dp_out_buf_len < DIGI_OUT_BUF_SIZE) { 1172 if (count == 1 && priv->dp_out_buf_len < DIGI_OUT_BUF_SIZE) {
1178 priv->dp_out_buf[priv->dp_out_buf_len++] = *buf; 1173 priv->dp_out_buf[priv->dp_out_buf_len++] = *buf;
@@ -1207,7 +1202,8 @@ static int digi_write(struct usb_serial_port *port, const unsigned char *buf, in
1207 /* copy in new data */ 1202 /* copy in new data */
1208 memcpy(data, buf, new_len); 1203 memcpy(data, buf, new_len);
1209 1204
1210 if ((ret = usb_submit_urb(port->write_urb, GFP_ATOMIC)) == 0) { 1205 ret = usb_submit_urb(port->write_urb, GFP_ATOMIC);
1206 if (ret == 0) {
1211 priv->dp_write_urb_in_use = 1; 1207 priv->dp_write_urb_in_use = 1;
1212 ret = new_len; 1208 ret = new_len;
1213 priv->dp_out_buf_len = 0; 1209 priv->dp_out_buf_len = 0;
@@ -1221,7 +1217,7 @@ static int digi_write(struct usb_serial_port *port, const unsigned char *buf, in
1221 dbg("digi_write: returning %d", ret); 1217 dbg("digi_write: returning %d", ret);
1222 return ret; 1218 return ret;
1223 1219
1224} 1220}
1225 1221
1226static void digi_write_bulk_callback(struct urb *urb) 1222static void digi_write_bulk_callback(struct urb *urb)
1227{ 1223{
@@ -1236,13 +1232,13 @@ static void digi_write_bulk_callback(struct urb *urb)
1236 dbg("digi_write_bulk_callback: TOP, urb->status=%d", status); 1232 dbg("digi_write_bulk_callback: TOP, urb->status=%d", status);
1237 1233
1238 /* port and serial sanity check */ 1234 /* port and serial sanity check */
1239 if (port == NULL || (priv=usb_get_serial_port_data(port)) == NULL) { 1235 if (port == NULL || (priv = usb_get_serial_port_data(port)) == NULL) {
1240 err("%s: port or port->private is NULL, status=%d", 1236 err("%s: port or port->private is NULL, status=%d",
1241 __func__, status); 1237 __func__, status);
1242 return; 1238 return;
1243 } 1239 }
1244 serial = port->serial; 1240 serial = port->serial;
1245 if (serial == NULL || (serial_priv=usb_get_serial_data(serial)) == NULL) { 1241 if (serial == NULL || (serial_priv = usb_get_serial_data(serial)) == NULL) {
1246 err("%s: serial or serial->private is NULL, status=%d", 1242 err("%s: serial or serial->private is NULL, status=%d",
1247 __func__, status); 1243 __func__, status);
1248 return; 1244 return;
@@ -1261,17 +1257,19 @@ static void digi_write_bulk_callback(struct urb *urb)
1261 /* try to send any buffered data on this port, if it is open */ 1257 /* try to send any buffered data on this port, if it is open */
1262 spin_lock(&priv->dp_port_lock); 1258 spin_lock(&priv->dp_port_lock);
1263 priv->dp_write_urb_in_use = 0; 1259 priv->dp_write_urb_in_use = 0;
1264 if (port->open_count && port->write_urb->status != -EINPROGRESS 1260 if (port->port.count && port->write_urb->status != -EINPROGRESS
1265 && priv->dp_out_buf_len > 0) { 1261 && priv->dp_out_buf_len > 0) {
1266 *((unsigned char *)(port->write_urb->transfer_buffer)) 1262 *((unsigned char *)(port->write_urb->transfer_buffer))
1267 = (unsigned char)DIGI_CMD_SEND_DATA; 1263 = (unsigned char)DIGI_CMD_SEND_DATA;
1268 *((unsigned char *)(port->write_urb->transfer_buffer)+1) 1264 *((unsigned char *)(port->write_urb->transfer_buffer) + 1)
1269 = (unsigned char)priv->dp_out_buf_len; 1265 = (unsigned char)priv->dp_out_buf_len;
1270 port->write_urb->transfer_buffer_length = priv->dp_out_buf_len+2; 1266 port->write_urb->transfer_buffer_length =
1267 priv->dp_out_buf_len + 2;
1271 port->write_urb->dev = serial->dev; 1268 port->write_urb->dev = serial->dev;
1272 memcpy(port->write_urb->transfer_buffer+2, priv->dp_out_buf, 1269 memcpy(port->write_urb->transfer_buffer + 2, priv->dp_out_buf,
1273 priv->dp_out_buf_len); 1270 priv->dp_out_buf_len);
1274 if ((ret = usb_submit_urb(port->write_urb, GFP_ATOMIC)) == 0) { 1271 ret = usb_submit_urb(port->write_urb, GFP_ATOMIC);
1272 if (ret == 0) {
1275 priv->dp_write_urb_in_use = 1; 1273 priv->dp_write_urb_in_use = 1;
1276 priv->dp_out_buf_len = 0; 1274 priv->dp_out_buf_len = 0;
1277 } 1275 }
@@ -1288,16 +1286,17 @@ static void digi_write_bulk_callback(struct urb *urb)
1288 __func__, ret, priv->dp_port_num); 1286 __func__, ret, priv->dp_port_num);
1289} 1287}
1290 1288
1291static int digi_write_room(struct usb_serial_port *port) 1289static int digi_write_room(struct tty_struct *tty)
1292{ 1290{
1293 1291 struct usb_serial_port *port = tty->driver_data;
1294 int room;
1295 struct digi_port *priv = usb_get_serial_port_data(port); 1292 struct digi_port *priv = usb_get_serial_port_data(port);
1293 int room;
1296 unsigned long flags = 0; 1294 unsigned long flags = 0;
1297 1295
1298 spin_lock_irqsave(&priv->dp_port_lock, flags); 1296 spin_lock_irqsave(&priv->dp_port_lock, flags);
1299 1297
1300 if (port->write_urb->status == -EINPROGRESS || priv->dp_write_urb_in_use) 1298 if (port->write_urb->status == -EINPROGRESS ||
1299 priv->dp_write_urb_in_use)
1301 room = 0; 1300 room = 0;
1302 else 1301 else
1303 room = port->bulk_out_size - 2 - priv->dp_out_buf_len; 1302 room = port->bulk_out_size - 2 - priv->dp_out_buf_len;
@@ -1308,12 +1307,11 @@ static int digi_write_room(struct usb_serial_port *port)
1308 1307
1309} 1308}
1310 1309
1311static int digi_chars_in_buffer(struct usb_serial_port *port) 1310static int digi_chars_in_buffer(struct tty_struct *tty)
1312{ 1311{
1313 1312 struct usb_serial_port *port = tty->driver_data;
1314 struct digi_port *priv = usb_get_serial_port_data(port); 1313 struct digi_port *priv = usb_get_serial_port_data(port);
1315 1314
1316
1317 if (port->write_urb->status == -EINPROGRESS 1315 if (port->write_urb->status == -EINPROGRESS
1318 || priv->dp_write_urb_in_use) { 1316 || priv->dp_write_urb_in_use) {
1319 dbg("digi_chars_in_buffer: port=%d, chars=%d", 1317 dbg("digi_chars_in_buffer: port=%d, chars=%d",
@@ -1329,7 +1327,8 @@ static int digi_chars_in_buffer(struct usb_serial_port *port)
1329} 1327}
1330 1328
1331 1329
1332static int digi_open(struct usb_serial_port *port, struct file *filp) 1330static int digi_open(struct tty_struct *tty, struct usb_serial_port *port,
1331 struct file *filp)
1333{ 1332{
1334 int ret; 1333 int ret;
1335 unsigned char buf[32]; 1334 unsigned char buf[32];
@@ -1338,7 +1337,7 @@ static int digi_open(struct usb_serial_port *port, struct file *filp)
1338 unsigned long flags = 0; 1337 unsigned long flags = 0;
1339 1338
1340 dbg("digi_open: TOP: port=%d, open_count=%d", 1339 dbg("digi_open: TOP: port=%d, open_count=%d",
1341 priv->dp_port_num, port->open_count); 1340 priv->dp_port_num, port->port.count);
1342 1341
1343 /* be sure the device is started up */ 1342 /* be sure the device is started up */
1344 if (digi_startup_device(port->serial) != 0) 1343 if (digi_startup_device(port->serial) != 0)
@@ -1353,7 +1352,7 @@ static int digi_open(struct usb_serial_port *port, struct file *filp)
1353 } 1352 }
1354 1353
1355 /* wait for a close in progress to finish */ 1354 /* wait for a close in progress to finish */
1356 while(priv->dp_in_close) { 1355 while (priv->dp_in_close) {
1357 cond_wait_interruptible_timeout_irqrestore( 1356 cond_wait_interruptible_timeout_irqrestore(
1358 &priv->dp_close_wait, DIGI_RETRY_TIMEOUT, 1357 &priv->dp_close_wait, DIGI_RETRY_TIMEOUT,
1359 &priv->dp_port_lock, flags); 1358 &priv->dp_port_lock, flags);
@@ -1363,7 +1362,7 @@ static int digi_open(struct usb_serial_port *port, struct file *filp)
1363 } 1362 }
1364 1363
1365 spin_unlock_irqrestore(&priv->dp_port_lock, flags); 1364 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
1366 1365
1367 /* read modem signals automatically whenever they change */ 1366 /* read modem signals automatically whenever they change */
1368 buf[0] = DIGI_CMD_READ_INPUT_SIGNALS; 1367 buf[0] = DIGI_CMD_READ_INPUT_SIGNALS;
1369 buf[1] = priv->dp_port_num; 1368 buf[1] = priv->dp_port_num;
@@ -1376,13 +1375,16 @@ static int digi_open(struct usb_serial_port *port, struct file *filp)
1376 buf[6] = DIGI_FLUSH_TX | DIGI_FLUSH_RX; 1375 buf[6] = DIGI_FLUSH_TX | DIGI_FLUSH_RX;
1377 buf[7] = 0; 1376 buf[7] = 0;
1378 1377
1379 if ((ret = digi_write_oob_command(port, buf, 8, 1)) != 0) 1378 ret = digi_write_oob_command(port, buf, 8, 1);
1379 if (ret != 0)
1380 dbg("digi_open: write oob failed, ret=%d", ret); 1380 dbg("digi_open: write oob failed, ret=%d", ret);
1381 1381
1382 /* set termios settings */ 1382 /* set termios settings */
1383 not_termios.c_cflag = ~port->tty->termios->c_cflag; 1383 if (tty) {
1384 not_termios.c_iflag = ~port->tty->termios->c_iflag; 1384 not_termios.c_cflag = ~tty->termios->c_cflag;
1385 digi_set_termios(port, &not_termios); 1385 not_termios.c_iflag = ~tty->termios->c_iflag;
1386 digi_set_termios(tty, port, &not_termios);
1387 }
1386 1388
1387 /* set DTR and RTS */ 1389 /* set DTR and RTS */
1388 digi_set_modem_signals(port, TIOCM_DTR|TIOCM_RTS, 1); 1390 digi_set_modem_signals(port, TIOCM_DTR|TIOCM_RTS, 1);
@@ -1391,16 +1393,16 @@ static int digi_open(struct usb_serial_port *port, struct file *filp)
1391} 1393}
1392 1394
1393 1395
1394static void digi_close(struct usb_serial_port *port, struct file *filp) 1396static void digi_close(struct tty_struct *tty, struct usb_serial_port *port,
1397 struct file *filp)
1395{ 1398{
1396 DEFINE_WAIT(wait); 1399 DEFINE_WAIT(wait);
1397 int ret; 1400 int ret;
1398 unsigned char buf[32]; 1401 unsigned char buf[32];
1399 struct tty_struct *tty = port->tty;
1400 struct digi_port *priv = usb_get_serial_port_data(port); 1402 struct digi_port *priv = usb_get_serial_port_data(port);
1401 1403
1402 dbg("digi_close: TOP: port=%d, open_count=%d", 1404 dbg("digi_close: TOP: port=%d, open_count=%d",
1403 priv->dp_port_num, port->open_count); 1405 priv->dp_port_num, port->port.count);
1404 1406
1405 mutex_lock(&port->serial->disc_mutex); 1407 mutex_lock(&port->serial->disc_mutex);
1406 /* if disconnected, just clear flags */ 1408 /* if disconnected, just clear flags */
@@ -1425,9 +1427,8 @@ static void digi_close(struct usb_serial_port *port, struct file *filp)
1425 1427
1426 if (port->serial->dev) { 1428 if (port->serial->dev) {
1427 /* wait for transmit idle */ 1429 /* wait for transmit idle */
1428 if ((filp->f_flags&(O_NDELAY|O_NONBLOCK)) == 0) { 1430 if ((filp->f_flags&(O_NDELAY|O_NONBLOCK)) == 0)
1429 digi_transmit_idle(port, DIGI_CLOSE_TIMEOUT); 1431 digi_transmit_idle(port, DIGI_CLOSE_TIMEOUT);
1430 }
1431 /* drop DTR and RTS */ 1432 /* drop DTR and RTS */
1432 digi_set_modem_signals(port, 0, 0); 1433 digi_set_modem_signals(port, 0, 0);
1433 1434
@@ -1461,11 +1462,13 @@ static void digi_close(struct usb_serial_port *port, struct file *filp)
1461 buf[18] = DIGI_FLUSH_TX | DIGI_FLUSH_RX; 1462 buf[18] = DIGI_FLUSH_TX | DIGI_FLUSH_RX;
1462 buf[19] = 0; 1463 buf[19] = 0;
1463 1464
1464 if ((ret = digi_write_oob_command(port, buf, 20, 0)) != 0) 1465 ret = digi_write_oob_command(port, buf, 20, 0);
1466 if (ret != 0)
1465 dbg("digi_close: write oob failed, ret=%d", ret); 1467 dbg("digi_close: write oob failed, ret=%d", ret);
1466 1468
1467 /* wait for final commands on oob port to complete */ 1469 /* wait for final commands on oob port to complete */
1468 prepare_to_wait(&priv->dp_flush_wait, &wait, TASK_INTERRUPTIBLE); 1470 prepare_to_wait(&priv->dp_flush_wait, &wait,
1471 TASK_INTERRUPTIBLE);
1469 schedule_timeout(DIGI_CLOSE_TIMEOUT); 1472 schedule_timeout(DIGI_CLOSE_TIMEOUT);
1470 finish_wait(&priv->dp_flush_wait, &wait); 1473 finish_wait(&priv->dp_flush_wait, &wait);
1471 1474
@@ -1485,15 +1488,15 @@ exit:
1485 1488
1486 1489
1487/* 1490/*
1488* Digi Startup Device 1491 * Digi Startup Device
1489* 1492 *
1490* Starts reads on all ports. Must be called AFTER startup, with 1493 * Starts reads on all ports. Must be called AFTER startup, with
1491* urbs initialized. Returns 0 if successful, non-zero error otherwise. 1494 * urbs initialized. Returns 0 if successful, non-zero error otherwise.
1492*/ 1495 */
1493 1496
1494static int digi_startup_device(struct usb_serial *serial) 1497static int digi_startup_device(struct usb_serial *serial)
1495{ 1498{
1496 int i,ret = 0; 1499 int i, ret = 0;
1497 struct digi_serial *serial_priv = usb_get_serial_data(serial); 1500 struct digi_serial *serial_priv = usb_get_serial_data(serial);
1498 struct usb_serial_port *port; 1501 struct usb_serial_port *port;
1499 1502
@@ -1511,7 +1514,8 @@ static int digi_startup_device(struct usb_serial *serial)
1511 for (i = 0; i < serial->type->num_ports + 1; i++) { 1514 for (i = 0; i < serial->type->num_ports + 1; i++) {
1512 port = serial->port[i]; 1515 port = serial->port[i];
1513 port->write_urb->dev = port->serial->dev; 1516 port->write_urb->dev = port->serial->dev;
1514 if ((ret = usb_submit_urb(port->read_urb, GFP_KERNEL)) != 0) { 1517 ret = usb_submit_urb(port->read_urb, GFP_KERNEL);
1518 if (ret != 0) {
1515 err("%s: usb_submit_urb failed, ret=%d, port=%d", 1519 err("%s: usb_submit_urb failed, ret=%d, port=%d",
1516 __func__, ret, i); 1520 __func__, ret, i);
1517 break; 1521 break;
@@ -1532,7 +1536,7 @@ static int digi_startup(struct usb_serial *serial)
1532 1536
1533 /* allocate the private data structures for all ports */ 1537 /* allocate the private data structures for all ports */
1534 /* number of regular ports + 1 for the out-of-band port */ 1538 /* number of regular ports + 1 for the out-of-band port */
1535 for(i = 0; i < serial->type->num_ports + 1; i++) { 1539 for (i = 0; i < serial->type->num_ports + 1; i++) {
1536 /* allocate port private structure */ 1540 /* allocate port private structure */
1537 priv = kmalloc(sizeof(struct digi_port), GFP_KERNEL); 1541 priv = kmalloc(sizeof(struct digi_port), GFP_KERNEL);
1538 if (priv == NULL) { 1542 if (priv == NULL) {
@@ -1595,7 +1599,7 @@ static void digi_shutdown(struct usb_serial *serial)
1595 1599
1596 /* free the private data structures for all ports */ 1600 /* free the private data structures for all ports */
1597 /* number of regular ports + 1 for the out-of-band port */ 1601 /* number of regular ports + 1 for the out-of-band port */
1598 for(i = 0; i < serial->type->num_ports + 1; i++) 1602 for (i = 0; i < serial->type->num_ports + 1; i++)
1599 kfree(usb_get_serial_port_data(serial->port[i])); 1603 kfree(usb_get_serial_port_data(serial->port[i]));
1600 kfree(usb_get_serial_data(serial)); 1604 kfree(usb_get_serial_data(serial));
1601} 1605}
@@ -1618,7 +1622,7 @@ static void digi_read_bulk_callback(struct urb *urb)
1618 return; 1622 return;
1619 } 1623 }
1620 if (port->serial == NULL || 1624 if (port->serial == NULL ||
1621 (serial_priv=usb_get_serial_data(port->serial)) == NULL) { 1625 (serial_priv = usb_get_serial_data(port->serial)) == NULL) {
1622 err("%s: serial is bad or serial->private is NULL, status=%d", 1626 err("%s: serial is bad or serial->private is NULL, status=%d",
1623 __func__, status); 1627 __func__, status);
1624 return; 1628 return;
@@ -1642,45 +1646,46 @@ static void digi_read_bulk_callback(struct urb *urb)
1642 1646
1643 /* continue read */ 1647 /* continue read */
1644 urb->dev = port->serial->dev; 1648 urb->dev = port->serial->dev;
1645 if ((ret = usb_submit_urb(urb, GFP_ATOMIC)) != 0) { 1649 ret = usb_submit_urb(urb, GFP_ATOMIC);
1650 if (ret != 0) {
1646 err("%s: failed resubmitting urb, ret=%d, port=%d", 1651 err("%s: failed resubmitting urb, ret=%d, port=%d",
1647 __func__, ret, priv->dp_port_num); 1652 __func__, ret, priv->dp_port_num);
1648 } 1653 }
1649 1654
1650} 1655}
1651 1656
1652/* 1657/*
1653* Digi Read INB Callback 1658 * Digi Read INB Callback
1654* 1659 *
1655* Digi Read INB Callback handles reads on the in band ports, sending 1660 * Digi Read INB Callback handles reads on the in band ports, sending
1656* the data on to the tty subsystem. When called we know port and 1661 * the data on to the tty subsystem. When called we know port and
1657* port->private are not NULL and port->serial has been validated. 1662 * port->private are not NULL and port->serial has been validated.
1658* It returns 0 if successful, 1 if successful but the port is 1663 * It returns 0 if successful, 1 if successful but the port is
1659* throttled, and -1 if the sanity checks failed. 1664 * throttled, and -1 if the sanity checks failed.
1660*/ 1665 */
1661 1666
1662static int digi_read_inb_callback(struct urb *urb) 1667static int digi_read_inb_callback(struct urb *urb)
1663{ 1668{
1664 1669
1665 struct usb_serial_port *port = urb->context; 1670 struct usb_serial_port *port = urb->context;
1666 struct tty_struct *tty = port->tty; 1671 struct tty_struct *tty = port->port.tty;
1667 struct digi_port *priv = usb_get_serial_port_data(port); 1672 struct digi_port *priv = usb_get_serial_port_data(port);
1668 int opcode = ((unsigned char *)urb->transfer_buffer)[0]; 1673 int opcode = ((unsigned char *)urb->transfer_buffer)[0];
1669 int len = ((unsigned char *)urb->transfer_buffer)[1]; 1674 int len = ((unsigned char *)urb->transfer_buffer)[1];
1670 int port_status = ((unsigned char *)urb->transfer_buffer)[2]; 1675 int port_status = ((unsigned char *)urb->transfer_buffer)[2];
1671 unsigned char *data = ((unsigned char *)urb->transfer_buffer)+3; 1676 unsigned char *data = ((unsigned char *)urb->transfer_buffer) + 3;
1672 int flag,throttled; 1677 int flag, throttled;
1673 int i; 1678 int i;
1674 int status = urb->status; 1679 int status = urb->status;
1675 1680
1676 /* do not process callbacks on closed ports */ 1681 /* do not process callbacks on closed ports */
1677 /* but do continue the read chain */ 1682 /* but do continue the read chain */
1678 if (port->open_count == 0) 1683 if (port->port.count == 0)
1679 return 0; 1684 return 0;
1680 1685
1681 /* short/multiple packet check */ 1686 /* short/multiple packet check */
1682 if (urb->actual_length != len + 2) { 1687 if (urb->actual_length != len + 2) {
1683 err("%s: INCOMPLETE OR MULTIPLE PACKET, urb->status=%d, " 1688 err("%s: INCOMPLETE OR MULTIPLE PACKET, urb->status=%d, "
1684 "port=%d, opcode=%d, len=%d, actual_length=%d, " 1689 "port=%d, opcode=%d, len=%d, actual_length=%d, "
1685 "status=%d", __func__, status, priv->dp_port_num, 1690 "status=%d", __func__, status, priv->dp_port_num,
1686 opcode, len, urb->actual_length, port_status); 1691 opcode, len, urb->actual_length, port_status);
@@ -1722,8 +1727,9 @@ static int digi_read_inb_callback(struct urb *urb)
1722 if (flag == TTY_NORMAL) 1727 if (flag == TTY_NORMAL)
1723 tty_insert_flip_string(tty, data, len); 1728 tty_insert_flip_string(tty, data, len);
1724 else { 1729 else {
1725 for(i = 0; i < len; i++) 1730 for (i = 0; i < len; i++)
1726 tty_insert_flip_char(tty, data[i], flag); 1731 tty_insert_flip_char(tty,
1732 data[i], flag);
1727 } 1733 }
1728 tty_flip_buffer_push(tty); 1734 tty_flip_buffer_push(tty);
1729 } 1735 }
@@ -1735,19 +1741,19 @@ static int digi_read_inb_callback(struct urb *urb)
1735 else if (opcode != DIGI_CMD_RECEIVE_DATA) 1741 else if (opcode != DIGI_CMD_RECEIVE_DATA)
1736 dbg("%s: unknown opcode: %d", __func__, opcode); 1742 dbg("%s: unknown opcode: %d", __func__, opcode);
1737 1743
1738 return(throttled ? 1 : 0); 1744 return throttled ? 1 : 0;
1739 1745
1740} 1746}
1741 1747
1742 1748
1743/* 1749/*
1744* Digi Read OOB Callback 1750 * Digi Read OOB Callback
1745* 1751 *
1746* Digi Read OOB Callback handles reads on the out of band port. 1752 * Digi Read OOB Callback handles reads on the out of band port.
1747* When called we know port and port->private are not NULL and 1753 * When called we know port and port->private are not NULL and
1748* the port->serial is valid. It returns 0 if successful, and 1754 * the port->serial is valid. It returns 0 if successful, and
1749* -1 if the sanity checks failed. 1755 * -1 if the sanity checks failed.
1750*/ 1756 */
1751 1757
1752static int digi_read_oob_callback(struct urb *urb) 1758static int digi_read_oob_callback(struct urb *urb)
1753{ 1759{
@@ -1757,12 +1763,13 @@ static int digi_read_oob_callback(struct urb *urb)
1757 struct digi_port *priv = usb_get_serial_port_data(port); 1763 struct digi_port *priv = usb_get_serial_port_data(port);
1758 int opcode, line, status, val; 1764 int opcode, line, status, val;
1759 int i; 1765 int i;
1766 unsigned int rts;
1760 1767
1761 dbg("digi_read_oob_callback: port=%d, len=%d", 1768 dbg("digi_read_oob_callback: port=%d, len=%d",
1762 priv->dp_port_num, urb->actual_length); 1769 priv->dp_port_num, urb->actual_length);
1763 1770
1764 /* handle each oob command */ 1771 /* handle each oob command */
1765 for(i = 0; i < urb->actual_length - 3;) { 1772 for (i = 0; i < urb->actual_length - 3;) {
1766 opcode = ((unsigned char *)urb->transfer_buffer)[i++]; 1773 opcode = ((unsigned char *)urb->transfer_buffer)[i++];
1767 line = ((unsigned char *)urb->transfer_buffer)[i++]; 1774 line = ((unsigned char *)urb->transfer_buffer)[i++];
1768 status = ((unsigned char *)urb->transfer_buffer)[i++]; 1775 status = ((unsigned char *)urb->transfer_buffer)[i++];
@@ -1776,27 +1783,29 @@ static int digi_read_oob_callback(struct urb *urb)
1776 1783
1777 port = serial->port[line]; 1784 port = serial->port[line];
1778 1785
1779 if ((priv=usb_get_serial_port_data(port)) == NULL) 1786 priv = usb_get_serial_port_data(port);
1787 if (priv == NULL)
1780 return -1; 1788 return -1;
1781 1789
1790 rts = 0;
1791 if (port->port.count)
1792 rts = port->port.tty->termios->c_cflag & CRTSCTS;
1793
1782 if (opcode == DIGI_CMD_READ_INPUT_SIGNALS) { 1794 if (opcode == DIGI_CMD_READ_INPUT_SIGNALS) {
1783 spin_lock(&priv->dp_port_lock); 1795 spin_lock(&priv->dp_port_lock);
1784 /* convert from digi flags to termiox flags */ 1796 /* convert from digi flags to termiox flags */
1785 if (val & DIGI_READ_INPUT_SIGNALS_CTS) { 1797 if (val & DIGI_READ_INPUT_SIGNALS_CTS) {
1786 priv->dp_modem_signals |= TIOCM_CTS; 1798 priv->dp_modem_signals |= TIOCM_CTS;
1787 /* port must be open to use tty struct */ 1799 /* port must be open to use tty struct */
1788 if (port->open_count 1800 if (rts) {
1789 && port->tty->termios->c_cflag & CRTSCTS) { 1801 port->port.tty->hw_stopped = 0;
1790 port->tty->hw_stopped = 0;
1791 digi_wakeup_write(port); 1802 digi_wakeup_write(port);
1792 } 1803 }
1793 } else { 1804 } else {
1794 priv->dp_modem_signals &= ~TIOCM_CTS; 1805 priv->dp_modem_signals &= ~TIOCM_CTS;
1795 /* port must be open to use tty struct */ 1806 /* port must be open to use tty struct */
1796 if (port->open_count 1807 if (rts)
1797 && port->tty->termios->c_cflag & CRTSCTS) { 1808 port->port.tty->hw_stopped = 1;
1798 port->tty->hw_stopped = 1;
1799 }
1800 } 1809 }
1801 if (val & DIGI_READ_INPUT_SIGNALS_DSR) 1810 if (val & DIGI_READ_INPUT_SIGNALS_DSR)
1802 priv->dp_modem_signals |= TIOCM_DSR; 1811 priv->dp_modem_signals |= TIOCM_DSR;
@@ -1833,7 +1842,7 @@ static int __init digi_init(void)
1833 if (retval) 1842 if (retval)
1834 goto failed_acceleport_2_device; 1843 goto failed_acceleport_2_device;
1835 retval = usb_serial_register(&digi_acceleport_4_device); 1844 retval = usb_serial_register(&digi_acceleport_4_device);
1836 if (retval) 1845 if (retval)
1837 goto failed_acceleport_4_device; 1846 goto failed_acceleport_4_device;
1838 retval = usb_register(&digi_driver); 1847 retval = usb_register(&digi_driver);
1839 if (retval) 1848 if (retval)
diff --git a/drivers/usb/serial/empeg.c b/drivers/usb/serial/empeg.c
index c5ec309a3cb1..a6ab5b58d9ca 100644
--- a/drivers/usb/serial/empeg.c
+++ b/drivers/usb/serial/empeg.c
@@ -11,36 +11,39 @@
11 * it under the terms of the GNU General Public License, as published by 11 * it under the terms of the GNU General Public License, as published by
12 * the Free Software Foundation, version 2. 12 * the Free Software Foundation, version 2.
13 * 13 *
14 * See Documentation/usb/usb-serial.txt for more information on using this driver 14 * See Documentation/usb/usb-serial.txt for more information on using this
15 * 15 * driver
16 *
16 * (07/16/2001) gb 17 * (07/16/2001) gb
17 * remove unused code in empeg_close() (thanks to Oliver Neukum for pointing this 18 * remove unused code in empeg_close() (thanks to Oliver Neukum for
18 * out) and rewrote empeg_set_termios(). 19 * pointing this out) and rewrote empeg_set_termios().
19 * 20 *
20 * (05/30/2001) gkh 21 * (05/30/2001) gkh
21 * switched from using spinlock to a semaphore, which fixes lots of problems. 22 * switched from using spinlock to a semaphore, which fixes lots of
23 * problems.
22 * 24 *
23 * (04/08/2001) gb 25 * (04/08/2001) gb
24 * Identify version on module load. 26 * Identify version on module load.
25 * 27 *
26 * (01/22/2001) gb 28 * (01/22/2001) gb
27 * Added write_room() and chars_in_buffer() support. 29 * Added write_room() and chars_in_buffer() support.
28 * 30 *
29 * (12/21/2000) gb 31 * (12/21/2000) gb
30 * Moved termio stuff inside the port->active check. 32 * Moved termio stuff inside the port->active check.
31 * Moved MOD_DEC_USE_COUNT to end of empeg_close(). 33 * Moved MOD_DEC_USE_COUNT to end of empeg_close().
32 * 34 *
33 * (12/03/2000) gb 35 * (12/03/2000) gb
34 * Added port->tty->ldisc.set_termios(port->tty, NULL) to empeg_open() 36 * Added port->port.tty->ldisc.set_termios(port->port.tty, NULL) to
35 * This notifies the tty driver that the termios have changed. 37 * empeg_open(). This notifies the tty driver that the termios have
36 * 38 * changed.
39 *
37 * (11/13/2000) gb 40 * (11/13/2000) gb
38 * Moved tty->low_latency = 1 from empeg_read_bulk_callback() to empeg_open() 41 * Moved tty->low_latency = 1 from empeg_read_bulk_callback() to
39 * (It only needs to be set once - Doh!) 42 * empeg_open() (It only needs to be set once - Doh!)
40 * 43 *
41 * (11/11/2000) gb 44 * (11/11/2000) gb
42 * Updated to work with id_table structure. 45 * Updated to work with id_table structure.
43 * 46 *
44 * (11/04/2000) gb 47 * (11/04/2000) gb
45 * Forked this from visor.c, and hacked it up to work with an 48 * Forked this from visor.c, and hacked it up to work with an
46 * Empeg ltd. empeg-car player. Constructive criticism welcomed. 49 * Empeg ltd. empeg-car player. Constructive criticism welcomed.
@@ -48,7 +51,7 @@
48 * use of his code, and for his guidance, advice and patience. :) 51 * use of his code, and for his guidance, advice and patience. :)
49 * A 'Thank You' is in order for John Ripley of Empeg ltd for his 52 * A 'Thank You' is in order for John Ripley of Empeg ltd for his
50 * advice, and patience too. 53 * advice, and patience too.
51 * 54 *
52 */ 55 */
53 56
54#include <linux/kernel.h> 57#include <linux/kernel.h>
@@ -60,7 +63,7 @@
60#include <linux/tty_flip.h> 63#include <linux/tty_flip.h>
61#include <linux/module.h> 64#include <linux/module.h>
62#include <linux/spinlock.h> 65#include <linux/spinlock.h>
63#include <asm/uaccess.h> 66#include <linux/uaccess.h>
64#include <linux/usb.h> 67#include <linux/usb.h>
65#include <linux/usb/serial.h> 68#include <linux/usb/serial.h>
66 69
@@ -77,31 +80,30 @@ static int debug;
77#define EMPEG_PRODUCT_ID 0x0001 80#define EMPEG_PRODUCT_ID 0x0001
78 81
79/* function prototypes for an empeg-car player */ 82/* function prototypes for an empeg-car player */
80static int empeg_open (struct usb_serial_port *port, struct file *filp); 83static int empeg_open(struct tty_struct *tty, struct usb_serial_port *port,
81static void empeg_close (struct usb_serial_port *port, struct file *filp); 84 struct file *filp);
82static int empeg_write (struct usb_serial_port *port, 85static void empeg_close(struct tty_struct *tty, struct usb_serial_port *port,
83 const unsigned char *buf, 86 struct file *filp);
84 int count); 87static int empeg_write(struct tty_struct *tty, struct usb_serial_port *port,
85static int empeg_write_room (struct usb_serial_port *port); 88 const unsigned char *buf,
86static int empeg_chars_in_buffer (struct usb_serial_port *port); 89 int count);
87static void empeg_throttle (struct usb_serial_port *port); 90static int empeg_write_room(struct tty_struct *tty);
88static void empeg_unthrottle (struct usb_serial_port *port); 91static int empeg_chars_in_buffer(struct tty_struct *tty);
89static int empeg_startup (struct usb_serial *serial); 92static void empeg_throttle(struct tty_struct *tty);
90static void empeg_shutdown (struct usb_serial *serial); 93static void empeg_unthrottle(struct tty_struct *tty);
91static int empeg_ioctl (struct usb_serial_port *port, 94static int empeg_startup(struct usb_serial *serial);
92 struct file * file, 95static void empeg_shutdown(struct usb_serial *serial);
93 unsigned int cmd, 96static void empeg_set_termios(struct tty_struct *tty,
94 unsigned long arg); 97 struct usb_serial_port *port, struct ktermios *old_termios);
95static void empeg_set_termios (struct usb_serial_port *port, struct ktermios *old_termios); 98static void empeg_write_bulk_callback(struct urb *urb);
96static void empeg_write_bulk_callback (struct urb *urb); 99static void empeg_read_bulk_callback(struct urb *urb);
97static void empeg_read_bulk_callback (struct urb *urb);
98 100
99static struct usb_device_id id_table [] = { 101static struct usb_device_id id_table [] = {
100 { USB_DEVICE(EMPEG_VENDOR_ID, EMPEG_PRODUCT_ID) }, 102 { USB_DEVICE(EMPEG_VENDOR_ID, EMPEG_PRODUCT_ID) },
101 { } /* Terminating entry */ 103 { } /* Terminating entry */
102}; 104};
103 105
104MODULE_DEVICE_TABLE (usb, id_table); 106MODULE_DEVICE_TABLE(usb, id_table);
105 107
106static struct usb_driver empeg_driver = { 108static struct usb_driver empeg_driver = {
107 .name = "empeg", 109 .name = "empeg",
@@ -125,7 +127,6 @@ static struct usb_serial_driver empeg_device = {
125 .unthrottle = empeg_unthrottle, 127 .unthrottle = empeg_unthrottle,
126 .attach = empeg_startup, 128 .attach = empeg_startup,
127 .shutdown = empeg_shutdown, 129 .shutdown = empeg_shutdown,
128 .ioctl = empeg_ioctl,
129 .set_termios = empeg_set_termios, 130 .set_termios = empeg_set_termios,
130 .write = empeg_write, 131 .write = empeg_write,
131 .write_room = empeg_write_room, 132 .write_room = empeg_write_room,
@@ -145,7 +146,8 @@ static int bytes_out;
145/****************************************************************************** 146/******************************************************************************
146 * Empeg specific driver functions 147 * Empeg specific driver functions
147 ******************************************************************************/ 148 ******************************************************************************/
148static int empeg_open (struct usb_serial_port *port, struct file *filp) 149static int empeg_open(struct tty_struct *tty, struct usb_serial_port *port,
150 struct file *filp)
149{ 151{
150 struct usb_serial *serial = port->serial; 152 struct usb_serial *serial = port->serial;
151 int result = 0; 153 int result = 0;
@@ -153,7 +155,7 @@ static int empeg_open (struct usb_serial_port *port, struct file *filp)
153 dbg("%s - port %d", __func__, port->number); 155 dbg("%s - port %d", __func__, port->number);
154 156
155 /* Force default termio settings */ 157 /* Force default termio settings */
156 empeg_set_termios (port, NULL) ; 158 empeg_set_termios(tty, port, NULL) ;
157 159
158 bytes_in = 0; 160 bytes_in = 0;
159 bytes_out = 0; 161 bytes_out = 0;
@@ -161,7 +163,7 @@ static int empeg_open (struct usb_serial_port *port, struct file *filp)
161 /* Start reading from the device */ 163 /* Start reading from the device */
162 usb_fill_bulk_urb( 164 usb_fill_bulk_urb(
163 port->read_urb, 165 port->read_urb,
164 serial->dev, 166 serial->dev,
165 usb_rcvbulkpipe(serial->dev, 167 usb_rcvbulkpipe(serial->dev,
166 port->bulk_in_endpointAddress), 168 port->bulk_in_endpointAddress),
167 port->read_urb->transfer_buffer, 169 port->read_urb->transfer_buffer,
@@ -172,13 +174,16 @@ static int empeg_open (struct usb_serial_port *port, struct file *filp)
172 result = usb_submit_urb(port->read_urb, GFP_KERNEL); 174 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
173 175
174 if (result) 176 if (result)
175 dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __func__, result); 177 dev_err(&port->dev,
178 "%s - failed submitting read urb, error %d\n",
179 __func__, result);
176 180
177 return result; 181 return result;
178} 182}
179 183
180 184
181static void empeg_close (struct usb_serial_port *port, struct file * filp) 185static void empeg_close(struct tty_struct *tty, struct usb_serial_port *port,
186 struct file *filp)
182{ 187{
183 dbg("%s - port %d", __func__, port->number); 188 dbg("%s - port %d", __func__, port->number);
184 189
@@ -189,7 +194,8 @@ static void empeg_close (struct usb_serial_port *port, struct file * filp)
189} 194}
190 195
191 196
192static int empeg_write (struct usb_serial_port *port, const unsigned char *buf, int count) 197static int empeg_write(struct tty_struct *tty, struct usb_serial_port *port,
198 const unsigned char *buf, int count)
193{ 199{
194 struct usb_serial *serial = port->serial; 200 struct usb_serial *serial = port->serial;
195 struct urb *urb; 201 struct urb *urb;
@@ -203,11 +209,10 @@ static int empeg_write (struct usb_serial_port *port, const unsigned char *buf,
203 dbg("%s - port %d", __func__, port->number); 209 dbg("%s - port %d", __func__, port->number);
204 210
205 while (count > 0) { 211 while (count > 0) {
206
207 /* try to find a free urb in our list of them */ 212 /* try to find a free urb in our list of them */
208 urb = NULL; 213 urb = NULL;
209 214
210 spin_lock_irqsave (&write_urb_pool_lock, flags); 215 spin_lock_irqsave(&write_urb_pool_lock, flags);
211 216
212 for (i = 0; i < NUM_URBS; ++i) { 217 for (i = 0; i < NUM_URBS; ++i) {
213 if (write_urb_pool[i]->status != -EINPROGRESS) { 218 if (write_urb_pool[i]->status != -EINPROGRESS) {
@@ -216,7 +221,7 @@ static int empeg_write (struct usb_serial_port *port, const unsigned char *buf,
216 } 221 }
217 } 222 }
218 223
219 spin_unlock_irqrestore (&write_urb_pool_lock, flags); 224 spin_unlock_irqrestore(&write_urb_pool_lock, flags);
220 225
221 if (urb == NULL) { 226 if (urb == NULL) {
222 dbg("%s - no more free urbs", __func__); 227 dbg("%s - no more free urbs", __func__);
@@ -224,25 +229,27 @@ static int empeg_write (struct usb_serial_port *port, const unsigned char *buf,
224 } 229 }
225 230
226 if (urb->transfer_buffer == NULL) { 231 if (urb->transfer_buffer == NULL) {
227 urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE, GFP_ATOMIC); 232 urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_ATOMIC);
228 if (urb->transfer_buffer == NULL) { 233 if (urb->transfer_buffer == NULL) {
229 dev_err(&port->dev, "%s no more kernel memory...\n", __func__); 234 dev_err(&port->dev,
235 "%s no more kernel memory...\n",
236 __func__);
230 goto exit; 237 goto exit;
231 } 238 }
232 } 239 }
233 240
234 transfer_size = min (count, URB_TRANSFER_BUFFER_SIZE); 241 transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE);
235 242
236 memcpy (urb->transfer_buffer, current_position, transfer_size); 243 memcpy(urb->transfer_buffer, current_position, transfer_size);
237 244
238 usb_serial_debug_data(debug, &port->dev, __func__, transfer_size, urb->transfer_buffer); 245 usb_serial_debug_data(debug, &port->dev, __func__, transfer_size, urb->transfer_buffer);
239 246
240 /* build up our urb */ 247 /* build up our urb */
241 usb_fill_bulk_urb ( 248 usb_fill_bulk_urb(
242 urb, 249 urb,
243 serial->dev, 250 serial->dev,
244 usb_sndbulkpipe(serial->dev, 251 usb_sndbulkpipe(serial->dev,
245 port->bulk_out_endpointAddress), 252 port->bulk_out_endpointAddress),
246 urb->transfer_buffer, 253 urb->transfer_buffer,
247 transfer_size, 254 transfer_size,
248 empeg_write_bulk_callback, 255 empeg_write_bulk_callback,
@@ -262,66 +269,57 @@ static int empeg_write (struct usb_serial_port *port, const unsigned char *buf,
262 bytes_out += transfer_size; 269 bytes_out += transfer_size;
263 270
264 } 271 }
265
266exit: 272exit:
267 return bytes_sent; 273 return bytes_sent;
268 274}
269}
270 275
271 276
272static int empeg_write_room (struct usb_serial_port *port) 277static int empeg_write_room(struct tty_struct *tty)
273{ 278{
279 struct usb_serial_port *port = tty->driver_data;
274 unsigned long flags; 280 unsigned long flags;
275 int i; 281 int i;
276 int room = 0; 282 int room = 0;
277 283
278 dbg("%s - port %d", __func__, port->number); 284 dbg("%s - port %d", __func__, port->number);
279 285
280 spin_lock_irqsave (&write_urb_pool_lock, flags); 286 spin_lock_irqsave(&write_urb_pool_lock, flags);
281
282 /* tally up the number of bytes available */ 287 /* tally up the number of bytes available */
283 for (i = 0; i < NUM_URBS; ++i) { 288 for (i = 0; i < NUM_URBS; ++i) {
284 if (write_urb_pool[i]->status != -EINPROGRESS) { 289 if (write_urb_pool[i]->status != -EINPROGRESS)
285 room += URB_TRANSFER_BUFFER_SIZE; 290 room += URB_TRANSFER_BUFFER_SIZE;
286 } 291 }
287 } 292 spin_unlock_irqrestore(&write_urb_pool_lock, flags);
288
289 spin_unlock_irqrestore (&write_urb_pool_lock, flags);
290
291 dbg("%s - returns %d", __func__, room); 293 dbg("%s - returns %d", __func__, room);
292 294 return room;
293 return (room);
294 295
295} 296}
296 297
297 298
298static int empeg_chars_in_buffer (struct usb_serial_port *port) 299static int empeg_chars_in_buffer(struct tty_struct *tty)
299{ 300{
301 struct usb_serial_port *port = tty->driver_data;
300 unsigned long flags; 302 unsigned long flags;
301 int i; 303 int i;
302 int chars = 0; 304 int chars = 0;
303 305
304 dbg("%s - port %d", __func__, port->number); 306 dbg("%s - port %d", __func__, port->number);
305 307
306 spin_lock_irqsave (&write_urb_pool_lock, flags); 308 spin_lock_irqsave(&write_urb_pool_lock, flags);
307 309
308 /* tally up the number of bytes waiting */ 310 /* tally up the number of bytes waiting */
309 for (i = 0; i < NUM_URBS; ++i) { 311 for (i = 0; i < NUM_URBS; ++i) {
310 if (write_urb_pool[i]->status == -EINPROGRESS) { 312 if (write_urb_pool[i]->status == -EINPROGRESS)
311 chars += URB_TRANSFER_BUFFER_SIZE; 313 chars += URB_TRANSFER_BUFFER_SIZE;
312 }
313 } 314 }
314 315
315 spin_unlock_irqrestore (&write_urb_pool_lock, flags); 316 spin_unlock_irqrestore(&write_urb_pool_lock, flags);
316
317 dbg("%s - returns %d", __func__, chars); 317 dbg("%s - returns %d", __func__, chars);
318 318 return chars;
319 return (chars);
320
321} 319}
322 320
323 321
324static void empeg_write_bulk_callback (struct urb *urb) 322static void empeg_write_bulk_callback(struct urb *urb)
325{ 323{
326 struct usb_serial_port *port = urb->context; 324 struct usb_serial_port *port = urb->context;
327 int status = urb->status; 325 int status = urb->status;
@@ -338,7 +336,7 @@ static void empeg_write_bulk_callback (struct urb *urb)
338} 336}
339 337
340 338
341static void empeg_read_bulk_callback (struct urb *urb) 339static void empeg_read_bulk_callback(struct urb *urb)
342{ 340{
343 struct usb_serial_port *port = urb->context; 341 struct usb_serial_port *port = urb->context;
344 struct tty_struct *tty; 342 struct tty_struct *tty;
@@ -354,9 +352,9 @@ static void empeg_read_bulk_callback (struct urb *urb)
354 return; 352 return;
355 } 353 }
356 354
357 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); 355 usb_serial_debug_data(debug, &port->dev, __func__,
358 356 urb->actual_length, data);
359 tty = port->tty; 357 tty = port->port.tty;
360 358
361 if (urb->actual_length) { 359 if (urb->actual_length) {
362 tty_buffer_request_room(tty, urb->actual_length); 360 tty_buffer_request_room(tty, urb->actual_length);
@@ -368,7 +366,7 @@ static void empeg_read_bulk_callback (struct urb *urb)
368 /* Continue trying to always read */ 366 /* Continue trying to always read */
369 usb_fill_bulk_urb( 367 usb_fill_bulk_urb(
370 port->read_urb, 368 port->read_urb,
371 port->serial->dev, 369 port->serial->dev,
372 usb_rcvbulkpipe(port->serial->dev, 370 usb_rcvbulkpipe(port->serial->dev,
373 port->bulk_in_endpointAddress), 371 port->bulk_in_endpointAddress),
374 port->read_urb->transfer_buffer, 372 port->read_urb->transfer_buffer,
@@ -379,38 +377,39 @@ static void empeg_read_bulk_callback (struct urb *urb)
379 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 377 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
380 378
381 if (result) 379 if (result)
382 dev_err(&urb->dev->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result); 380 dev_err(&urb->dev->dev,
381 "%s - failed resubmitting read urb, error %d\n",
382 __func__, result);
383 383
384 return; 384 return;
385 385
386} 386}
387 387
388 388
389static void empeg_throttle (struct usb_serial_port *port) 389static void empeg_throttle(struct tty_struct *tty)
390{ 390{
391 struct usb_serial_port *port = tty->driver_data;
391 dbg("%s - port %d", __func__, port->number); 392 dbg("%s - port %d", __func__, port->number);
392 usb_kill_urb(port->read_urb); 393 usb_kill_urb(port->read_urb);
393} 394}
394 395
395 396
396static void empeg_unthrottle (struct usb_serial_port *port) 397static void empeg_unthrottle(struct tty_struct *tty)
397{ 398{
399 struct usb_serial_port *port = tty->driver_data;
398 int result; 400 int result;
399
400 dbg("%s - port %d", __func__, port->number); 401 dbg("%s - port %d", __func__, port->number);
401 402
402 port->read_urb->dev = port->serial->dev; 403 port->read_urb->dev = port->serial->dev;
403
404 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 404 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
405
406 if (result) 405 if (result)
407 dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __func__, result); 406 dev_err(&port->dev,
408 407 "%s - failed submitting read urb, error %d\n",
409 return; 408 __func__, result);
410} 409}
411 410
412 411
413static int empeg_startup (struct usb_serial *serial) 412static int empeg_startup(struct usb_serial *serial)
414{ 413{
415 int r; 414 int r;
416 415
@@ -422,7 +421,7 @@ static int empeg_startup (struct usb_serial *serial)
422 return -ENODEV; 421 return -ENODEV;
423 } 422 }
424 dbg("%s - reset config", __func__); 423 dbg("%s - reset config", __func__);
425 r = usb_reset_configuration (serial->dev); 424 r = usb_reset_configuration(serial->dev);
426 425
427 /* continue on with initialization */ 426 /* continue on with initialization */
428 return r; 427 return r;
@@ -430,34 +429,27 @@ static int empeg_startup (struct usb_serial *serial)
430} 429}
431 430
432 431
433static void empeg_shutdown (struct usb_serial *serial) 432static void empeg_shutdown(struct usb_serial *serial)
434{ 433{
435 dbg ("%s", __func__); 434 dbg("%s", __func__);
436}
437
438
439static int empeg_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg)
440{
441 dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd);
442
443 return -ENOIOCTLCMD;
444} 435}
445 436
446 437
447static void empeg_set_termios (struct usb_serial_port *port, struct ktermios *old_termios) 438static void empeg_set_termios(struct tty_struct *tty,
439 struct usb_serial_port *port, struct ktermios *old_termios)
448{ 440{
449 struct ktermios *termios = port->tty->termios; 441 struct ktermios *termios = tty->termios;
450 dbg("%s - port %d", __func__, port->number); 442 dbg("%s - port %d", __func__, port->number);
451 443
452 /* 444 /*
453 * The empeg-car player wants these particular tty settings. 445 * The empeg-car player wants these particular tty settings.
454 * You could, for example, change the baud rate, however the 446 * You could, for example, change the baud rate, however the
455 * player only supports 115200 (currently), so there is really 447 * player only supports 115200 (currently), so there is really
456 * no point in support for changes to the tty settings. 448 * no point in support for changes to the tty settings.
457 * (at least for now) 449 * (at least for now)
458 * 450 *
459 * The default requirements for this device are: 451 * The default requirements for this device are:
460 */ 452 */
461 termios->c_iflag 453 termios->c_iflag
462 &= ~(IGNBRK /* disable ignore break */ 454 &= ~(IGNBRK /* disable ignore break */
463 | BRKINT /* disable break causes interrupt */ 455 | BRKINT /* disable break causes interrupt */
@@ -491,18 +483,18 @@ static void empeg_set_termios (struct usb_serial_port *port, struct ktermios *ol
491 * this is bad as it opens up the possibility of dropping bytes 483 * this is bad as it opens up the possibility of dropping bytes
492 * on the floor. We don't want to drop bytes on the floor. :) 484 * on the floor. We don't want to drop bytes on the floor. :)
493 */ 485 */
494 port->tty->low_latency = 1; 486 tty->low_latency = 1;
495 tty_encode_baud_rate(port->tty, 115200, 115200); 487 tty_encode_baud_rate(tty, 115200, 115200);
496} 488}
497 489
498 490
499static int __init empeg_init (void) 491static int __init empeg_init(void)
500{ 492{
501 struct urb *urb; 493 struct urb *urb;
502 int i, retval; 494 int i, retval;
503 495
504 /* create our write urb pool and transfer buffers */ 496 /* create our write urb pool and transfer buffers */
505 spin_lock_init (&write_urb_pool_lock); 497 spin_lock_init(&write_urb_pool_lock);
506 for (i = 0; i < NUM_URBS; ++i) { 498 for (i = 0; i < NUM_URBS; ++i) {
507 urb = usb_alloc_urb(0, GFP_KERNEL); 499 urb = usb_alloc_urb(0, GFP_KERNEL);
508 write_urb_pool[i] = urb; 500 write_urb_pool[i] = urb;
@@ -511,9 +503,10 @@ static int __init empeg_init (void)
511 continue; 503 continue;
512 } 504 }
513 505
514 urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL); 506 urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE,
507 GFP_KERNEL);
515 if (!urb->transfer_buffer) { 508 if (!urb->transfer_buffer) {
516 err("%s - out of memory for urb buffers.", 509 err("%s - out of memory for urb buffers.",
517 __func__); 510 __func__);
518 continue; 511 continue;
519 } 512 }
@@ -542,36 +535,36 @@ failed_usb_serial_register:
542} 535}
543 536
544 537
545static void __exit empeg_exit (void) 538static void __exit empeg_exit(void)
546{ 539{
547 int i; 540 int i;
548 unsigned long flags; 541 unsigned long flags;
549 542
550 usb_deregister(&empeg_driver); 543 usb_deregister(&empeg_driver);
551 usb_serial_deregister (&empeg_device); 544 usb_serial_deregister(&empeg_device);
552 545
553 spin_lock_irqsave (&write_urb_pool_lock, flags); 546 spin_lock_irqsave(&write_urb_pool_lock, flags);
554 547
555 for (i = 0; i < NUM_URBS; ++i) { 548 for (i = 0; i < NUM_URBS; ++i) {
556 if (write_urb_pool[i]) { 549 if (write_urb_pool[i]) {
557 /* FIXME - uncomment the following usb_kill_urb call when 550 /* FIXME - uncomment the following usb_kill_urb call
558 * the host controllers get fixed to set urb->dev = NULL after 551 * when the host controllers get fixed to set urb->dev
559 * the urb is finished. Otherwise this call oopses. */ 552 * = NULL after the urb is finished. Otherwise this
553 * call oopses. */
560 /* usb_kill_urb(write_urb_pool[i]); */ 554 /* usb_kill_urb(write_urb_pool[i]); */
561 kfree(write_urb_pool[i]->transfer_buffer); 555 kfree(write_urb_pool[i]->transfer_buffer);
562 usb_free_urb (write_urb_pool[i]); 556 usb_free_urb(write_urb_pool[i]);
563 } 557 }
564 } 558 }
565 559 spin_unlock_irqrestore(&write_urb_pool_lock, flags);
566 spin_unlock_irqrestore (&write_urb_pool_lock, flags);
567} 560}
568 561
569 562
570module_init(empeg_init); 563module_init(empeg_init);
571module_exit(empeg_exit); 564module_exit(empeg_exit);
572 565
573MODULE_AUTHOR( DRIVER_AUTHOR ); 566MODULE_AUTHOR(DRIVER_AUTHOR);
574MODULE_DESCRIPTION( DRIVER_DESC ); 567MODULE_DESCRIPTION(DRIVER_DESC);
575MODULE_LICENSE("GPL"); 568MODULE_LICENSE("GPL");
576 569
577module_param(debug, bool, S_IRUGO | S_IWUSR); 570module_param(debug, bool, S_IRUGO | S_IWUSR);
diff --git a/drivers/usb/serial/ezusb.c b/drivers/usb/serial/ezusb.c
index cc4fbd9d60be..711e84f6ed82 100644
--- a/drivers/usb/serial/ezusb.c
+++ b/drivers/usb/serial/ezusb.c
@@ -20,7 +20,8 @@
20/* EZ-USB Control and Status Register. Bit 0 controls 8051 reset */ 20/* EZ-USB Control and Status Register. Bit 0 controls 8051 reset */
21#define CPUCS_REG 0x7F92 21#define CPUCS_REG 0x7F92
22 22
23int ezusb_writememory (struct usb_serial *serial, int address, unsigned char *data, int length, __u8 bRequest) 23int ezusb_writememory(struct usb_serial *serial, int address,
24 unsigned char *data, int length, __u8 request)
24{ 25{
25 int result; 26 int result;
26 unsigned char *transfer_buffer; 27 unsigned char *transfer_buffer;
@@ -33,26 +34,27 @@ int ezusb_writememory (struct usb_serial *serial, int address, unsigned char *da
33 34
34 transfer_buffer = kmemdup(data, length, GFP_KERNEL); 35 transfer_buffer = kmemdup(data, length, GFP_KERNEL);
35 if (!transfer_buffer) { 36 if (!transfer_buffer) {
36 dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n", __func__, length); 37 dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n",
38 __func__, length);
37 return -ENOMEM; 39 return -ENOMEM;
38 } 40 }
39 result = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0), bRequest, 0x40, address, 0, transfer_buffer, length, 3000); 41 result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
40 kfree (transfer_buffer); 42 request, 0x40, address, 0, transfer_buffer, length, 3000);
43 kfree(transfer_buffer);
41 return result; 44 return result;
42} 45}
46EXPORT_SYMBOL_GPL(ezusb_writememory);
43 47
44int ezusb_set_reset (struct usb_serial *serial, unsigned char reset_bit) 48int ezusb_set_reset(struct usb_serial *serial, unsigned char reset_bit)
45{ 49{
46 int response; 50 int response;
47 51
48 /* dbg("%s - %d", __func__, reset_bit); */ 52 /* dbg("%s - %d", __func__, reset_bit); */
49 response = ezusb_writememory (serial, CPUCS_REG, &reset_bit, 1, 0xa0); 53 response = ezusb_writememory(serial, CPUCS_REG, &reset_bit, 1, 0xa0);
50 if (response < 0) 54 if (response < 0)
51 dev_err(&serial->dev->dev, "%s- %d failed\n", __func__, reset_bit); 55 dev_err(&serial->dev->dev, "%s- %d failed\n",
56 __func__, reset_bit);
52 return response; 57 return response;
53} 58}
54
55
56EXPORT_SYMBOL_GPL(ezusb_writememory);
57EXPORT_SYMBOL_GPL(ezusb_set_reset); 59EXPORT_SYMBOL_GPL(ezusb_set_reset);
58 60
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 0ff4a3971e45..838717250145 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -12,7 +12,8 @@
12 * the Free Software Foundation; either version 2 of the License, or 12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. 13 * (at your option) any later version.
14 * 14 *
15 * See Documentation/usb/usb-serial.txt for more information on using this driver 15 * See Documentation/usb/usb-serial.txt for more information on using this
16 * driver
16 * 17 *
17 * See http://ftdi-usb-sio.sourceforge.net for upto date testing info 18 * See http://ftdi-usb-sio.sourceforge.net for upto date testing info
18 * and extra documentation 19 * and extra documentation
@@ -25,7 +26,8 @@
25/* Bill Ryder - bryder@sgi.com - wrote the FTDI_SIO implementation */ 26/* Bill Ryder - bryder@sgi.com - wrote the FTDI_SIO implementation */
26/* Thanx to FTDI for so kindly providing details of the protocol required */ 27/* Thanx to FTDI for so kindly providing details of the protocol required */
27/* to talk to the device */ 28/* to talk to the device */
28/* Thanx to gkh and the rest of the usb dev group for all code I have assimilated :-) */ 29/* Thanx to gkh and the rest of the usb dev group for all code I have
30 assimilated :-) */
29 31
30#include <linux/kernel.h> 32#include <linux/kernel.h>
31#include <linux/errno.h> 33#include <linux/errno.h>
@@ -36,7 +38,7 @@
36#include <linux/tty_flip.h> 38#include <linux/tty_flip.h>
37#include <linux/module.h> 39#include <linux/module.h>
38#include <linux/spinlock.h> 40#include <linux/spinlock.h>
39#include <asm/uaccess.h> 41#include <linux/uaccess.h>
40#include <linux/usb.h> 42#include <linux/usb.h>
41#include <linux/serial.h> 43#include <linux/serial.h>
42#include <linux/usb/serial.h> 44#include <linux/usb/serial.h>
@@ -55,17 +57,22 @@ static __u16 product;
55 57
56struct ftdi_private { 58struct ftdi_private {
57 ftdi_chip_type_t chip_type; 59 ftdi_chip_type_t chip_type;
58 /* type of the device, either SIO or FT8U232AM */ 60 /* type of device, either SIO or FT8U232AM */
59 int baud_base; /* baud base clock for divisor setting */ 61 int baud_base; /* baud base clock for divisor setting */
60 int custom_divisor; /* custom_divisor kludge, this is for baud_base (different from what goes to the chip!) */ 62 int custom_divisor; /* custom_divisor kludge, this is for
63 baud_base (different from what goes to the
64 chip!) */
61 __u16 last_set_data_urb_value ; 65 __u16 last_set_data_urb_value ;
62 /* the last data state set - needed for doing a break */ 66 /* the last data state set - needed for doing
63 int write_offset; /* This is the offset in the usb data block to write the serial data - 67 * a break
64 * it is different between devices 68 */
69 int write_offset; /* This is the offset in the usb data block to
70 * write the serial data - it varies between
71 * devices
65 */ 72 */
66 int flags; /* some ASYNC_xxxx flags are supported */ 73 int flags; /* some ASYNC_xxxx flags are supported */
67 unsigned long last_dtr_rts; /* saved modem control outputs */ 74 unsigned long last_dtr_rts; /* saved modem control outputs */
68 wait_queue_head_t delta_msr_wait; /* Used for TIOCMIWAIT */ 75 wait_queue_head_t delta_msr_wait; /* Used for TIOCMIWAIT */
69 char prev_status, diff_status; /* Used for TIOCMIWAIT */ 76 char prev_status, diff_status; /* Used for TIOCMIWAIT */
70 __u8 rx_flags; /* receive state flags (throttling) */ 77 __u8 rx_flags; /* receive state flags (throttling) */
71 spinlock_t rx_lock; /* spinlock for receive state */ 78 spinlock_t rx_lock; /* spinlock for receive state */
@@ -76,8 +83,10 @@ struct ftdi_private {
76 83
77 __u16 interface; /* FT2232C port interface (0 for FT232/245) */ 84 __u16 interface; /* FT2232C port interface (0 for FT232/245) */
78 85
79 speed_t force_baud; /* if non-zero, force the baud rate to this value */ 86 speed_t force_baud; /* if non-zero, force the baud rate to
80 int force_rtscts; /* if non-zero, force RTS-CTS to always be enabled */ 87 this value */
88 int force_rtscts; /* if non-zero, force RTS-CTS to always
89 be enabled */
81 90
82 spinlock_t tx_lock; /* spinlock for transmit state */ 91 spinlock_t tx_lock; /* spinlock for transmit state */
83 unsigned long tx_bytes; 92 unsigned long tx_bytes;
@@ -88,13 +97,14 @@ struct ftdi_private {
88/* struct ftdi_sio_quirk is used by devices requiring special attention. */ 97/* struct ftdi_sio_quirk is used by devices requiring special attention. */
89struct ftdi_sio_quirk { 98struct ftdi_sio_quirk {
90 int (*probe)(struct usb_serial *); 99 int (*probe)(struct usb_serial *);
91 void (*port_probe)(struct ftdi_private *); /* Special settings for probed ports. */ 100 /* Special settings for probed ports. */
101 void (*port_probe)(struct ftdi_private *);
92}; 102};
93 103
94static int ftdi_jtag_probe (struct usb_serial *serial); 104static int ftdi_jtag_probe(struct usb_serial *serial);
95static int ftdi_mtxorb_hack_setup (struct usb_serial *serial); 105static int ftdi_mtxorb_hack_setup(struct usb_serial *serial);
96static void ftdi_USB_UIRT_setup (struct ftdi_private *priv); 106static void ftdi_USB_UIRT_setup(struct ftdi_private *priv);
97static void ftdi_HE_TIRA1_setup (struct ftdi_private *priv); 107static void ftdi_HE_TIRA1_setup(struct ftdi_private *priv);
98 108
99static struct ftdi_sio_quirk ftdi_jtag_quirk = { 109static struct ftdi_sio_quirk ftdi_jtag_quirk = {
100 .probe = ftdi_jtag_probe, 110 .probe = ftdi_jtag_probe,
@@ -174,270 +184,270 @@ static struct usb_device_id id_table_combined [] = {
174 { USB_DEVICE(FTDI_VID, FTDI_MTXORB_4_PID) }, 184 { USB_DEVICE(FTDI_VID, FTDI_MTXORB_4_PID) },
175 { USB_DEVICE(FTDI_VID, FTDI_MTXORB_5_PID) }, 185 { USB_DEVICE(FTDI_VID, FTDI_MTXORB_5_PID) },
176 { USB_DEVICE(FTDI_VID, FTDI_MTXORB_6_PID) }, 186 { USB_DEVICE(FTDI_VID, FTDI_MTXORB_6_PID) },
177 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0100_PID) }, 187 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0100_PID) },
178 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0101_PID) }, 188 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0101_PID) },
179 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0102_PID) }, 189 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0102_PID) },
180 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0103_PID) }, 190 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0103_PID) },
181 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0104_PID) }, 191 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0104_PID) },
182 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0105_PID) }, 192 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0105_PID) },
183 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0106_PID) }, 193 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0106_PID) },
184 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0107_PID) }, 194 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0107_PID) },
185 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0108_PID) }, 195 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0108_PID) },
186 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0109_PID) }, 196 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0109_PID) },
187 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_010A_PID) }, 197 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_010A_PID) },
188 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_010B_PID) }, 198 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_010B_PID) },
189 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_010C_PID) }, 199 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_010C_PID) },
190 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_010D_PID) }, 200 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_010D_PID) },
191 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_010E_PID) }, 201 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_010E_PID) },
192 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_010F_PID) }, 202 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_010F_PID) },
193 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0110_PID) }, 203 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0110_PID) },
194 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0111_PID) }, 204 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0111_PID) },
195 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0112_PID) }, 205 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0112_PID) },
196 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0113_PID) }, 206 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0113_PID) },
197 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0114_PID) }, 207 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0114_PID) },
198 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0115_PID) }, 208 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0115_PID) },
199 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0116_PID) }, 209 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0116_PID) },
200 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0117_PID) }, 210 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0117_PID) },
201 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0118_PID) }, 211 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0118_PID) },
202 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0119_PID) }, 212 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0119_PID) },
203 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_011A_PID) }, 213 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_011A_PID) },
204 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_011B_PID) }, 214 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_011B_PID) },
205 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_011C_PID) }, 215 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_011C_PID) },
206 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_011D_PID) }, 216 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_011D_PID) },
207 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_011E_PID) }, 217 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_011E_PID) },
208 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_011F_PID) }, 218 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_011F_PID) },
209 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0120_PID) }, 219 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0120_PID) },
210 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0121_PID) }, 220 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0121_PID) },
211 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0122_PID) }, 221 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0122_PID) },
212 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0123_PID) }, 222 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0123_PID) },
213 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0124_PID) }, 223 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0124_PID) },
214 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0125_PID) }, 224 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0125_PID) },
215 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0126_PID) }, 225 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0126_PID) },
216 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0127_PID), 226 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0127_PID),
217 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk }, 227 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
218 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0128_PID) }, 228 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0128_PID) },
219 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0129_PID) }, 229 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0129_PID) },
220 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_012A_PID) }, 230 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_012A_PID) },
221 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_012B_PID) }, 231 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_012B_PID) },
222 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_012C_PID), 232 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_012C_PID),
223 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk }, 233 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
224 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_012D_PID) }, 234 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_012D_PID) },
225 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_012E_PID) }, 235 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_012E_PID) },
226 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_012F_PID) }, 236 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_012F_PID) },
227 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0130_PID) }, 237 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0130_PID) },
228 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0131_PID) }, 238 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0131_PID) },
229 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0132_PID) }, 239 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0132_PID) },
230 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0133_PID) }, 240 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0133_PID) },
231 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0134_PID) }, 241 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0134_PID) },
232 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0135_PID) }, 242 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0135_PID) },
233 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0136_PID) }, 243 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0136_PID) },
234 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0137_PID) }, 244 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0137_PID) },
235 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0138_PID) }, 245 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0138_PID) },
236 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0139_PID) }, 246 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0139_PID) },
237 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_013A_PID) }, 247 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_013A_PID) },
238 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_013B_PID) }, 248 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_013B_PID) },
239 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_013C_PID) }, 249 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_013C_PID) },
240 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_013D_PID) }, 250 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_013D_PID) },
241 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_013E_PID) }, 251 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_013E_PID) },
242 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_013F_PID) }, 252 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_013F_PID) },
243 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0140_PID) }, 253 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0140_PID) },
244 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0141_PID) }, 254 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0141_PID) },
245 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0142_PID) }, 255 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0142_PID) },
246 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0143_PID) }, 256 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0143_PID) },
247 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0144_PID) }, 257 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0144_PID) },
248 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0145_PID) }, 258 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0145_PID) },
249 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0146_PID) }, 259 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0146_PID) },
250 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0147_PID) }, 260 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0147_PID) },
251 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0148_PID) }, 261 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0148_PID) },
252 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0149_PID) }, 262 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0149_PID) },
253 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_014A_PID) }, 263 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_014A_PID) },
254 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_014B_PID) }, 264 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_014B_PID) },
255 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_014C_PID) }, 265 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_014C_PID) },
256 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_014D_PID) }, 266 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_014D_PID) },
257 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_014E_PID) }, 267 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_014E_PID) },
258 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_014F_PID) }, 268 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_014F_PID) },
259 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0150_PID) }, 269 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0150_PID) },
260 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0151_PID) }, 270 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0151_PID) },
261 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0152_PID) }, 271 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0152_PID) },
262 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0153_PID), 272 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0153_PID),
263 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk }, 273 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
264 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0154_PID), 274 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0154_PID),
265 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk }, 275 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
266 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0155_PID), 276 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0155_PID),
267 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk }, 277 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
268 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0156_PID), 278 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0156_PID),
269 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk }, 279 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
270 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0157_PID), 280 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0157_PID),
271 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk }, 281 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
272 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0158_PID), 282 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0158_PID),
273 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk }, 283 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
274 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0159_PID) }, 284 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0159_PID) },
275 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_015A_PID) }, 285 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_015A_PID) },
276 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_015B_PID) }, 286 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_015B_PID) },
277 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_015C_PID) }, 287 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_015C_PID) },
278 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_015D_PID) }, 288 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_015D_PID) },
279 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_015E_PID) }, 289 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_015E_PID) },
280 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_015F_PID) }, 290 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_015F_PID) },
281 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0160_PID) }, 291 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0160_PID) },
282 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0161_PID) }, 292 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0161_PID) },
283 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0162_PID) }, 293 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0162_PID) },
284 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0163_PID) }, 294 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0163_PID) },
285 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0164_PID) }, 295 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0164_PID) },
286 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0165_PID) }, 296 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0165_PID) },
287 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0166_PID) }, 297 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0166_PID) },
288 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0167_PID) }, 298 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0167_PID) },
289 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0168_PID) }, 299 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0168_PID) },
290 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0169_PID) }, 300 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0169_PID) },
291 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_016A_PID) }, 301 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_016A_PID) },
292 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_016B_PID) }, 302 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_016B_PID) },
293 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_016C_PID) }, 303 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_016C_PID) },
294 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_016D_PID) }, 304 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_016D_PID) },
295 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_016E_PID) }, 305 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_016E_PID) },
296 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_016F_PID) }, 306 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_016F_PID) },
297 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0170_PID) }, 307 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0170_PID) },
298 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0171_PID) }, 308 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0171_PID) },
299 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0172_PID) }, 309 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0172_PID) },
300 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0173_PID) }, 310 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0173_PID) },
301 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0174_PID) }, 311 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0174_PID) },
302 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0175_PID) }, 312 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0175_PID) },
303 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0176_PID) }, 313 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0176_PID) },
304 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0177_PID) }, 314 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0177_PID) },
305 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0178_PID) }, 315 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0178_PID) },
306 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0179_PID) }, 316 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0179_PID) },
307 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_017A_PID) }, 317 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_017A_PID) },
308 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_017B_PID) }, 318 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_017B_PID) },
309 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_017C_PID) }, 319 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_017C_PID) },
310 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_017D_PID) }, 320 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_017D_PID) },
311 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_017E_PID) }, 321 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_017E_PID) },
312 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_017F_PID) }, 322 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_017F_PID) },
313 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0180_PID) }, 323 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0180_PID) },
314 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0181_PID) }, 324 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0181_PID) },
315 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0182_PID) }, 325 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0182_PID) },
316 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0183_PID) }, 326 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0183_PID) },
317 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0184_PID) }, 327 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0184_PID) },
318 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0185_PID) }, 328 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0185_PID) },
319 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0186_PID) }, 329 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0186_PID) },
320 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0187_PID) }, 330 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0187_PID) },
321 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0188_PID) }, 331 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0188_PID) },
322 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0189_PID) }, 332 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0189_PID) },
323 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_018A_PID) }, 333 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_018A_PID) },
324 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_018B_PID) }, 334 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_018B_PID) },
325 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_018C_PID) }, 335 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_018C_PID) },
326 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_018D_PID) }, 336 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_018D_PID) },
327 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_018E_PID) }, 337 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_018E_PID) },
328 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_018F_PID) }, 338 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_018F_PID) },
329 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0190_PID) }, 339 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0190_PID) },
330 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0191_PID) }, 340 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0191_PID) },
331 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0192_PID) }, 341 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0192_PID) },
332 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0193_PID) }, 342 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0193_PID) },
333 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0194_PID) }, 343 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0194_PID) },
334 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0195_PID) }, 344 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0195_PID) },
335 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0196_PID) }, 345 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0196_PID) },
336 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0197_PID) }, 346 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0197_PID) },
337 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0198_PID) }, 347 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0198_PID) },
338 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0199_PID) }, 348 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0199_PID) },
339 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_019A_PID) }, 349 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_019A_PID) },
340 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_019B_PID) }, 350 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_019B_PID) },
341 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_019C_PID) }, 351 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_019C_PID) },
342 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_019D_PID) }, 352 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_019D_PID) },
343 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_019E_PID) }, 353 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_019E_PID) },
344 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_019F_PID) }, 354 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_019F_PID) },
345 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01A0_PID) }, 355 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A0_PID) },
346 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01A1_PID) }, 356 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A1_PID) },
347 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01A2_PID) }, 357 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A2_PID) },
348 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01A3_PID) }, 358 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A3_PID) },
349 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01A4_PID) }, 359 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A4_PID) },
350 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01A5_PID) }, 360 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A5_PID) },
351 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01A6_PID) }, 361 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A6_PID) },
352 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01A7_PID) }, 362 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A7_PID) },
353 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01A8_PID) }, 363 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A8_PID) },
354 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01A9_PID) }, 364 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A9_PID) },
355 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01AA_PID) }, 365 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01AA_PID) },
356 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01AB_PID) }, 366 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01AB_PID) },
357 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01AC_PID) }, 367 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01AC_PID) },
358 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01AD_PID) }, 368 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01AD_PID) },
359 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01AE_PID) }, 369 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01AE_PID) },
360 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01AF_PID) }, 370 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01AF_PID) },
361 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01B0_PID) }, 371 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B0_PID) },
362 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01B1_PID) }, 372 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B1_PID) },
363 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01B2_PID) }, 373 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B2_PID) },
364 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01B3_PID) }, 374 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B3_PID) },
365 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01B4_PID) }, 375 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B4_PID) },
366 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01B5_PID) }, 376 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B5_PID) },
367 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01B6_PID) }, 377 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B6_PID) },
368 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01B7_PID) }, 378 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B7_PID) },
369 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01B8_PID) }, 379 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B8_PID) },
370 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01B9_PID) }, 380 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B9_PID) },
371 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01BA_PID) }, 381 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01BA_PID) },
372 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01BB_PID) }, 382 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01BB_PID) },
373 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01BC_PID) }, 383 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01BC_PID) },
374 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01BD_PID) }, 384 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01BD_PID) },
375 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01BE_PID) }, 385 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01BE_PID) },
376 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01BF_PID) }, 386 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01BF_PID) },
377 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01C0_PID) }, 387 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C0_PID) },
378 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01C1_PID) }, 388 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C1_PID) },
379 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01C2_PID) }, 389 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C2_PID) },
380 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01C3_PID) }, 390 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C3_PID) },
381 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01C4_PID) }, 391 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C4_PID) },
382 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01C5_PID) }, 392 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C5_PID) },
383 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01C6_PID) }, 393 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C6_PID) },
384 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01C7_PID) }, 394 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C7_PID) },
385 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01C8_PID) }, 395 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C8_PID) },
386 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01C9_PID) }, 396 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C9_PID) },
387 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01CA_PID) }, 397 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01CA_PID) },
388 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01CB_PID) }, 398 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01CB_PID) },
389 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01CC_PID) }, 399 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01CC_PID) },
390 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01CD_PID) }, 400 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01CD_PID) },
391 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01CE_PID) }, 401 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01CE_PID) },
392 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01CF_PID) }, 402 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01CF_PID) },
393 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01D0_PID) }, 403 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D0_PID) },
394 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01D1_PID) }, 404 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D1_PID) },
395 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01D2_PID) }, 405 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D2_PID) },
396 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01D3_PID) }, 406 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D3_PID) },
397 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01D4_PID) }, 407 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D4_PID) },
398 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01D5_PID) }, 408 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D5_PID) },
399 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01D6_PID) }, 409 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D6_PID) },
400 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01D7_PID) }, 410 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D7_PID) },
401 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01D8_PID) }, 411 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D8_PID) },
402 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01D9_PID) }, 412 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D9_PID) },
403 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01DA_PID) }, 413 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01DA_PID) },
404 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01DB_PID) }, 414 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01DB_PID) },
405 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01DC_PID) }, 415 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01DC_PID) },
406 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01DD_PID) }, 416 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01DD_PID) },
407 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01DE_PID) }, 417 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01DE_PID) },
408 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01DF_PID) }, 418 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01DF_PID) },
409 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01E0_PID) }, 419 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E0_PID) },
410 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01E1_PID) }, 420 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E1_PID) },
411 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01E2_PID) }, 421 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E2_PID) },
412 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01E3_PID) }, 422 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E3_PID) },
413 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01E4_PID) }, 423 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E4_PID) },
414 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01E5_PID) }, 424 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E5_PID) },
415 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01E6_PID) }, 425 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E6_PID) },
416 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01E7_PID) }, 426 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E7_PID) },
417 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01E8_PID) }, 427 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E8_PID) },
418 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01E9_PID) }, 428 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E9_PID) },
419 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01EA_PID) }, 429 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01EA_PID) },
420 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01EB_PID) }, 430 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01EB_PID) },
421 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01EC_PID) }, 431 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01EC_PID) },
422 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01ED_PID) }, 432 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01ED_PID) },
423 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01EE_PID) }, 433 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01EE_PID) },
424 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01EF_PID) }, 434 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01EF_PID) },
425 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01F0_PID) }, 435 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F0_PID) },
426 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01F1_PID) }, 436 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F1_PID) },
427 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01F2_PID) }, 437 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F2_PID) },
428 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01F3_PID) }, 438 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F3_PID) },
429 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01F4_PID) }, 439 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F4_PID) },
430 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01F5_PID) }, 440 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F5_PID) },
431 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01F6_PID) }, 441 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F6_PID) },
432 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01F7_PID) }, 442 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F7_PID) },
433 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01F8_PID) }, 443 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F8_PID) },
434 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01F9_PID) }, 444 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F9_PID) },
435 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01FA_PID) }, 445 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01FA_PID) },
436 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01FB_PID) }, 446 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01FB_PID) },
437 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01FC_PID) }, 447 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01FC_PID) },
438 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01FD_PID) }, 448 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01FD_PID) },
439 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01FE_PID) }, 449 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01FE_PID) },
440 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01FF_PID) }, 450 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01FF_PID) },
441 { USB_DEVICE(FTDI_VID, FTDI_PERLE_ULTRAPORT_PID) }, 451 { USB_DEVICE(FTDI_VID, FTDI_PERLE_ULTRAPORT_PID) },
442 { USB_DEVICE(FTDI_VID, FTDI_PIEGROUP_PID) }, 452 { USB_DEVICE(FTDI_VID, FTDI_PIEGROUP_PID) },
443 { USB_DEVICE(FTDI_VID, FTDI_TNC_X_PID) }, 453 { USB_DEVICE(FTDI_VID, FTDI_TNC_X_PID) },
@@ -642,7 +652,7 @@ static struct usb_device_id id_table_combined [] = {
642 { } /* Terminating entry */ 652 { } /* Terminating entry */
643}; 653};
644 654
645MODULE_DEVICE_TABLE (usb, id_table_combined); 655MODULE_DEVICE_TABLE(usb, id_table_combined);
646 656
647static struct usb_driver ftdi_driver = { 657static struct usb_driver ftdi_driver = {
648 .name = "ftdi_sio", 658 .name = "ftdi_sio",
@@ -678,30 +688,37 @@ static const char *ftdi_chip_name[] = {
678 | ASYNC_SPD_CUST | ASYNC_SPD_SHI | ASYNC_SPD_WARP) 688 | ASYNC_SPD_CUST | ASYNC_SPD_SHI | ASYNC_SPD_WARP)
679 689
680/* function prototypes for a FTDI serial converter */ 690/* function prototypes for a FTDI serial converter */
681static int ftdi_sio_probe (struct usb_serial *serial, const struct usb_device_id *id); 691static int ftdi_sio_probe(struct usb_serial *serial,
682static void ftdi_shutdown (struct usb_serial *serial); 692 const struct usb_device_id *id);
683static int ftdi_sio_port_probe (struct usb_serial_port *port); 693static void ftdi_shutdown(struct usb_serial *serial);
684static int ftdi_sio_port_remove (struct usb_serial_port *port); 694static int ftdi_sio_port_probe(struct usb_serial_port *port);
685static int ftdi_open (struct usb_serial_port *port, struct file *filp); 695static int ftdi_sio_port_remove(struct usb_serial_port *port);
686static void ftdi_close (struct usb_serial_port *port, struct file *filp); 696static int ftdi_open(struct tty_struct *tty,
687static int ftdi_write (struct usb_serial_port *port, const unsigned char *buf, int count); 697 struct usb_serial_port *port, struct file *filp);
688static int ftdi_write_room (struct usb_serial_port *port); 698static void ftdi_close(struct tty_struct *tty,
689static int ftdi_chars_in_buffer (struct usb_serial_port *port); 699 struct usb_serial_port *port, struct file *filp);
690static void ftdi_write_bulk_callback (struct urb *urb); 700static int ftdi_write(struct tty_struct *tty, struct usb_serial_port *port,
691static void ftdi_read_bulk_callback (struct urb *urb); 701 const unsigned char *buf, int count);
692static void ftdi_process_read (struct work_struct *work); 702static int ftdi_write_room(struct tty_struct *tty);
693static void ftdi_set_termios (struct usb_serial_port *port, struct ktermios * old); 703static int ftdi_chars_in_buffer(struct tty_struct *tty);
694static int ftdi_tiocmget (struct usb_serial_port *port, struct file *file); 704static void ftdi_write_bulk_callback(struct urb *urb);
695static int ftdi_tiocmset (struct usb_serial_port *port, struct file * file, unsigned int set, unsigned int clear); 705static void ftdi_read_bulk_callback(struct urb *urb);
696static int ftdi_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg); 706static void ftdi_process_read(struct work_struct *work);
697static void ftdi_break_ctl (struct usb_serial_port *port, int break_state ); 707static void ftdi_set_termios(struct tty_struct *tty,
698static void ftdi_throttle (struct usb_serial_port *port); 708 struct usb_serial_port *port, struct ktermios *old);
699static void ftdi_unthrottle (struct usb_serial_port *port); 709static int ftdi_tiocmget(struct tty_struct *tty, struct file *file);
700 710static int ftdi_tiocmset(struct tty_struct *tty, struct file *file,
701static unsigned short int ftdi_232am_baud_base_to_divisor (int baud, int base); 711 unsigned int set, unsigned int clear);
702static unsigned short int ftdi_232am_baud_to_divisor (int baud); 712static int ftdi_ioctl(struct tty_struct *tty, struct file *file,
703static __u32 ftdi_232bm_baud_base_to_divisor (int baud, int base); 713 unsigned int cmd, unsigned long arg);
704static __u32 ftdi_232bm_baud_to_divisor (int baud); 714static void ftdi_break_ctl(struct tty_struct *tty, int break_state);
715static void ftdi_throttle(struct tty_struct *tty);
716static void ftdi_unthrottle(struct tty_struct *tty);
717
718static unsigned short int ftdi_232am_baud_base_to_divisor(int baud, int base);
719static unsigned short int ftdi_232am_baud_to_divisor(int baud);
720static __u32 ftdi_232bm_baud_base_to_divisor(int baud, int base);
721static __u32 ftdi_232bm_baud_to_divisor(int baud);
705 722
706static struct usb_serial_driver ftdi_sio_device = { 723static struct usb_serial_driver ftdi_sio_device = {
707 .driver = { 724 .driver = {
@@ -752,44 +769,54 @@ static struct usb_serial_driver ftdi_sio_device = {
752static unsigned short int ftdi_232am_baud_base_to_divisor(int baud, int base) 769static unsigned short int ftdi_232am_baud_base_to_divisor(int baud, int base)
753{ 770{
754 unsigned short int divisor; 771 unsigned short int divisor;
755 int divisor3 = base / 2 / baud; // divisor shifted 3 bits to the left 772 /* divisor shifted 3 bits to the left */
756 if ((divisor3 & 0x7) == 7) divisor3 ++; // round x.7/8 up to x+1 773 int divisor3 = base / 2 / baud;
774 if ((divisor3 & 0x7) == 7)
775 divisor3++; /* round x.7/8 up to x+1 */
757 divisor = divisor3 >> 3; 776 divisor = divisor3 >> 3;
758 divisor3 &= 0x7; 777 divisor3 &= 0x7;
759 if (divisor3 == 1) divisor |= 0xc000; else // 0.125 778 if (divisor3 == 1)
760 if (divisor3 >= 4) divisor |= 0x4000; else // 0.5 779 divisor |= 0xc000;
761 if (divisor3 != 0) divisor |= 0x8000; // 0.25 780 else if (divisor3 >= 4)
762 if (divisor == 1) divisor = 0; /* special case for maximum baud rate */ 781 divisor |= 0x4000;
782 else if (divisor3 != 0)
783 divisor |= 0x8000;
784 else if (divisor == 1)
785 divisor = 0; /* special case for maximum baud rate */
763 return divisor; 786 return divisor;
764} 787}
765 788
766static unsigned short int ftdi_232am_baud_to_divisor(int baud) 789static unsigned short int ftdi_232am_baud_to_divisor(int baud)
767{ 790{
768 return(ftdi_232am_baud_base_to_divisor(baud, 48000000)); 791 return ftdi_232am_baud_base_to_divisor(baud, 48000000);
769} 792}
770 793
771static __u32 ftdi_232bm_baud_base_to_divisor(int baud, int base) 794static __u32 ftdi_232bm_baud_base_to_divisor(int baud, int base)
772{ 795{
773 static const unsigned char divfrac[8] = { 0, 3, 2, 4, 1, 5, 6, 7 }; 796 static const unsigned char divfrac[8] = { 0, 3, 2, 4, 1, 5, 6, 7 };
774 __u32 divisor; 797 __u32 divisor;
775 int divisor3 = base / 2 / baud; // divisor shifted 3 bits to the left 798 /* divisor shifted 3 bits to the left */
799 int divisor3 = base / 2 / baud;
776 divisor = divisor3 >> 3; 800 divisor = divisor3 >> 3;
777 divisor |= (__u32)divfrac[divisor3 & 0x7] << 14; 801 divisor |= (__u32)divfrac[divisor3 & 0x7] << 14;
778 /* Deal with special cases for highest baud rates. */ 802 /* Deal with special cases for highest baud rates. */
779 if (divisor == 1) divisor = 0; else // 1.0 803 if (divisor == 1)
780 if (divisor == 0x4001) divisor = 1; // 1.5 804 divisor = 0;
805 else if (divisor == 0x4001)
806 divisor = 1;
781 return divisor; 807 return divisor;
782} 808}
783 809
784static __u32 ftdi_232bm_baud_to_divisor(int baud) 810static __u32 ftdi_232bm_baud_to_divisor(int baud)
785{ 811{
786 return(ftdi_232bm_baud_base_to_divisor(baud, 48000000)); 812 return ftdi_232bm_baud_base_to_divisor(baud, 48000000);
787} 813}
788 814
789#define set_mctrl(port, set) update_mctrl((port), (set), 0) 815#define set_mctrl(port, set) update_mctrl((port), (set), 0)
790#define clear_mctrl(port, clear) update_mctrl((port), 0, (clear)) 816#define clear_mctrl(port, clear) update_mctrl((port), 0, (clear))
791 817
792static int update_mctrl(struct usb_serial_port *port, unsigned int set, unsigned int clear) 818static int update_mctrl(struct usb_serial_port *port, unsigned int set,
819 unsigned int clear)
793{ 820{
794 struct ftdi_private *priv = usb_get_serial_port_data(port); 821 struct ftdi_private *priv = usb_get_serial_port_data(port);
795 char *buf; 822 char *buf;
@@ -843,42 +870,8 @@ static int update_mctrl(struct usb_serial_port *port, unsigned int set, unsigned
843} 870}
844 871
845 872
846static __u32 get_ftdi_divisor(struct usb_serial_port * port); 873static __u32 get_ftdi_divisor(struct tty_struct *tty,
847 874 struct usb_serial_port *port)
848
849static int change_speed(struct usb_serial_port *port)
850{
851 struct ftdi_private *priv = usb_get_serial_port_data(port);
852 char *buf;
853 __u16 urb_value;
854 __u16 urb_index;
855 __u32 urb_index_value;
856 int rv;
857
858 buf = kmalloc(1, GFP_NOIO);
859 if (!buf)
860 return -ENOMEM;
861
862 urb_index_value = get_ftdi_divisor(port);
863 urb_value = (__u16)urb_index_value;
864 urb_index = (__u16)(urb_index_value >> 16);
865 if (priv->interface) { /* FT2232C */
866 urb_index = (__u16)((urb_index << 8) | priv->interface);
867 }
868
869 rv = usb_control_msg(port->serial->dev,
870 usb_sndctrlpipe(port->serial->dev, 0),
871 FTDI_SIO_SET_BAUDRATE_REQUEST,
872 FTDI_SIO_SET_BAUDRATE_REQUEST_TYPE,
873 urb_value, urb_index,
874 buf, 0, WDR_SHORT_TIMEOUT);
875
876 kfree(buf);
877 return rv;
878}
879
880
881static __u32 get_ftdi_divisor(struct usb_serial_port * port)
882{ /* get_ftdi_divisor */ 875{ /* get_ftdi_divisor */
883 struct ftdi_private *priv = usb_get_serial_port_data(port); 876 struct ftdi_private *priv = usb_get_serial_port_data(port);
884 __u32 div_value = 0; 877 __u32 div_value = 0;
@@ -886,48 +879,56 @@ static __u32 get_ftdi_divisor(struct usb_serial_port * port)
886 int baud; 879 int baud;
887 880
888 /* 881 /*
889 * The logic involved in setting the baudrate can be cleanly split in 3 steps. 882 * The logic involved in setting the baudrate can be cleanly split into
890 * Obtaining the actual baud rate is a little tricky since unix traditionally 883 * 3 steps.
891 * somehow ignored the possibility to set non-standard baud rates.
892 * 1. Standard baud rates are set in tty->termios->c_cflag 884 * 1. Standard baud rates are set in tty->termios->c_cflag
893 * 2. If these are not enough, you can set any speed using alt_speed as follows: 885 * 2. If these are not enough, you can set any speed using alt_speed as
886 * follows:
894 * - set tty->termios->c_cflag speed to B38400 887 * - set tty->termios->c_cflag speed to B38400
895 * - set your real speed in tty->alt_speed; it gets ignored when 888 * - set your real speed in tty->alt_speed; it gets ignored when
896 * alt_speed==0, (or) 889 * alt_speed==0, (or)
897 * - call TIOCSSERIAL ioctl with (struct serial_struct) set as follows: 890 * - call TIOCSSERIAL ioctl with (struct serial_struct) set as
898 * flags & ASYNC_SPD_MASK == ASYNC_SPD_[HI, VHI, SHI, WARP], this just 891 * follows:
899 * sets alt_speed to (HI: 57600, VHI: 115200, SHI: 230400, WARP: 460800) 892 * flags & ASYNC_SPD_MASK == ASYNC_SPD_[HI, VHI, SHI, WARP],
893 * this just sets alt_speed to (HI: 57600, VHI: 115200,
894 * SHI: 230400, WARP: 460800)
900 * ** Steps 1, 2 are done courtesy of tty_get_baud_rate 895 * ** Steps 1, 2 are done courtesy of tty_get_baud_rate
901 * 3. You can also set baud rate by setting custom divisor as follows 896 * 3. You can also set baud rate by setting custom divisor as follows
902 * - set tty->termios->c_cflag speed to B38400 897 * - set tty->termios->c_cflag speed to B38400
903 * - call TIOCSSERIAL ioctl with (struct serial_struct) set as follows: 898 * - call TIOCSSERIAL ioctl with (struct serial_struct) set as
899 * follows:
904 * o flags & ASYNC_SPD_MASK == ASYNC_SPD_CUST 900 * o flags & ASYNC_SPD_MASK == ASYNC_SPD_CUST
905 * o custom_divisor set to baud_base / your_new_baudrate 901 * o custom_divisor set to baud_base / your_new_baudrate
906 * ** Step 3 is done courtesy of code borrowed from serial.c - I should really 902 * ** Step 3 is done courtesy of code borrowed from serial.c
907 * spend some time and separate+move this common code to serial.c, it is 903 * I should really spend some time and separate + move this common
908 * replicated in nearly every serial driver you see. 904 * code to serial.c, it is replicated in nearly every serial driver
905 * you see.
909 */ 906 */
910 907
911 /* 1. Get the baud rate from the tty settings, this observes alt_speed hack */ 908 /* 1. Get the baud rate from the tty settings, this observes
909 alt_speed hack */
912 910
913 baud = tty_get_baud_rate(port->tty); 911 baud = tty_get_baud_rate(tty);
914 dbg("%s - tty_get_baud_rate reports speed %d", __func__, baud); 912 dbg("%s - tty_get_baud_rate reports speed %d", __func__, baud);
915 913
916 /* 2. Observe async-compatible custom_divisor hack, update baudrate if needed */ 914 /* 2. Observe async-compatible custom_divisor hack, update baudrate
915 if needed */
917 916
918 if (baud == 38400 && 917 if (baud == 38400 &&
919 ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) && 918 ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) &&
920 (priv->custom_divisor)) { 919 (priv->custom_divisor)) {
921 baud = priv->baud_base / priv->custom_divisor; 920 baud = priv->baud_base / priv->custom_divisor;
922 dbg("%s - custom divisor %d sets baud rate to %d", __func__, priv->custom_divisor, baud); 921 dbg("%s - custom divisor %d sets baud rate to %d",
922 __func__, priv->custom_divisor, baud);
923 } 923 }
924 924
925 /* 3. Convert baudrate to device-specific divisor */ 925 /* 3. Convert baudrate to device-specific divisor */
926 926
927 if (!baud) baud = 9600; 927 if (!baud)
928 switch(priv->chip_type) { 928 baud = 9600;
929 switch (priv->chip_type) {
929 case SIO: /* SIO chip */ 930 case SIO: /* SIO chip */
930 switch(baud) { 931 switch (baud) {
931 case 300: div_value = ftdi_sio_b300; break; 932 case 300: div_value = ftdi_sio_b300; break;
932 case 600: div_value = ftdi_sio_b600; break; 933 case 600: div_value = ftdi_sio_b600; break;
933 case 1200: div_value = ftdi_sio_b1200; break; 934 case 1200: div_value = ftdi_sio_b1200; break;
@@ -940,7 +941,8 @@ static __u32 get_ftdi_divisor(struct usb_serial_port * port)
940 case 115200: div_value = ftdi_sio_b115200; break; 941 case 115200: div_value = ftdi_sio_b115200; break;
941 } /* baud */ 942 } /* baud */
942 if (div_value == 0) { 943 if (div_value == 0) {
943 dbg("%s - Baudrate (%d) requested is not supported", __func__, baud); 944 dbg("%s - Baudrate (%d) requested is not supported",
945 __func__, baud);
944 div_value = ftdi_sio_b9600; 946 div_value = ftdi_sio_b9600;
945 baud = 9600; 947 baud = 9600;
946 div_okay = 0; 948 div_okay = 0;
@@ -950,7 +952,7 @@ static __u32 get_ftdi_divisor(struct usb_serial_port * port)
950 if (baud <= 3000000) { 952 if (baud <= 3000000) {
951 div_value = ftdi_232am_baud_to_divisor(baud); 953 div_value = ftdi_232am_baud_to_divisor(baud);
952 } else { 954 } else {
953 dbg("%s - Baud rate too high!", __func__); 955 dbg("%s - Baud rate too high!", __func__);
954 baud = 9600; 956 baud = 9600;
955 div_value = ftdi_232am_baud_to_divisor(9600); 957 div_value = ftdi_232am_baud_to_divisor(9600);
956 div_okay = 0; 958 div_okay = 0;
@@ -962,7 +964,7 @@ static __u32 get_ftdi_divisor(struct usb_serial_port * port)
962 if (baud <= 3000000) { 964 if (baud <= 3000000) {
963 div_value = ftdi_232bm_baud_to_divisor(baud); 965 div_value = ftdi_232bm_baud_to_divisor(baud);
964 } else { 966 } else {
965 dbg("%s - Baud rate too high!", __func__); 967 dbg("%s - Baud rate too high!", __func__);
966 div_value = ftdi_232bm_baud_to_divisor(9600); 968 div_value = ftdi_232bm_baud_to_divisor(9600);
967 div_okay = 0; 969 div_okay = 0;
968 baud = 9600; 970 baud = 9600;
@@ -976,12 +978,45 @@ static __u32 get_ftdi_divisor(struct usb_serial_port * port)
976 ftdi_chip_name[priv->chip_type]); 978 ftdi_chip_name[priv->chip_type]);
977 } 979 }
978 980
979 tty_encode_baud_rate(port->tty, baud, baud); 981 tty_encode_baud_rate(tty, baud, baud);
980 return(div_value); 982 return div_value;
983}
984
985static int change_speed(struct tty_struct *tty, struct usb_serial_port *port)
986{
987 struct ftdi_private *priv = usb_get_serial_port_data(port);
988 char *buf;
989 __u16 urb_value;
990 __u16 urb_index;
991 __u32 urb_index_value;
992 int rv;
993
994 buf = kmalloc(1, GFP_NOIO);
995 if (!buf)
996 return -ENOMEM;
997
998 urb_index_value = get_ftdi_divisor(tty, port);
999 urb_value = (__u16)urb_index_value;
1000 urb_index = (__u16)(urb_index_value >> 16);
1001 if (priv->interface) { /* FT2232C */
1002 urb_index = (__u16)((urb_index << 8) | priv->interface);
1003 }
1004
1005 rv = usb_control_msg(port->serial->dev,
1006 usb_sndctrlpipe(port->serial->dev, 0),
1007 FTDI_SIO_SET_BAUDRATE_REQUEST,
1008 FTDI_SIO_SET_BAUDRATE_REQUEST_TYPE,
1009 urb_value, urb_index,
1010 buf, 0, WDR_SHORT_TIMEOUT);
1011
1012 kfree(buf);
1013 return rv;
981} 1014}
982 1015
983 1016
984static int get_serial_info(struct usb_serial_port * port, struct serial_struct __user * retinfo) 1017
1018static int get_serial_info(struct usb_serial_port *port,
1019 struct serial_struct __user *retinfo)
985{ 1020{
986 struct ftdi_private *priv = usb_get_serial_port_data(port); 1021 struct ftdi_private *priv = usb_get_serial_port_data(port);
987 struct serial_struct tmp; 1022 struct serial_struct tmp;
@@ -998,7 +1033,8 @@ static int get_serial_info(struct usb_serial_port * port, struct serial_struct _
998} /* get_serial_info */ 1033} /* get_serial_info */
999 1034
1000 1035
1001static int set_serial_info(struct usb_serial_port * port, struct serial_struct __user * newinfo) 1036static int set_serial_info(struct tty_struct *tty,
1037 struct usb_serial_port *port, struct serial_struct __user *newinfo)
1002{ /* set_serial_info */ 1038{ /* set_serial_info */
1003 struct ftdi_private *priv = usb_get_serial_port_data(port); 1039 struct ftdi_private *priv = usb_get_serial_port_data(port);
1004 struct serial_struct new_serial; 1040 struct serial_struct new_serial;
@@ -1006,7 +1042,7 @@ static int set_serial_info(struct usb_serial_port * port, struct serial_struct _
1006 1042
1007 if (copy_from_user(&new_serial, newinfo, sizeof(new_serial))) 1043 if (copy_from_user(&new_serial, newinfo, sizeof(new_serial)))
1008 return -EFAULT; 1044 return -EFAULT;
1009 old_priv = * priv; 1045 old_priv = *priv;
1010 1046
1011 /* Do error checking and permission checking */ 1047 /* Do error checking and permission checking */
1012 1048
@@ -1027,33 +1063,32 @@ static int set_serial_info(struct usb_serial_port * port, struct serial_struct _
1027 /* Make the changes - these are privileged changes! */ 1063 /* Make the changes - these are privileged changes! */
1028 1064
1029 priv->flags = ((priv->flags & ~ASYNC_FLAGS) | 1065 priv->flags = ((priv->flags & ~ASYNC_FLAGS) |
1030 (new_serial.flags & ASYNC_FLAGS)); 1066 (new_serial.flags & ASYNC_FLAGS));
1031 priv->custom_divisor = new_serial.custom_divisor; 1067 priv->custom_divisor = new_serial.custom_divisor;
1032 1068
1033 port->tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0; 1069 tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
1034 1070
1035check_and_exit: 1071check_and_exit:
1036 if ((old_priv.flags & ASYNC_SPD_MASK) != 1072 if ((old_priv.flags & ASYNC_SPD_MASK) !=
1037 (priv->flags & ASYNC_SPD_MASK)) { 1073 (priv->flags & ASYNC_SPD_MASK)) {
1038 if ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI) 1074 if ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
1039 port->tty->alt_speed = 57600; 1075 tty->alt_speed = 57600;
1040 else if ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI) 1076 else if ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
1041 port->tty->alt_speed = 115200; 1077 tty->alt_speed = 115200;
1042 else if ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI) 1078 else if ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
1043 port->tty->alt_speed = 230400; 1079 tty->alt_speed = 230400;
1044 else if ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP) 1080 else if ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
1045 port->tty->alt_speed = 460800; 1081 tty->alt_speed = 460800;
1046 else 1082 else
1047 port->tty->alt_speed = 0; 1083 tty->alt_speed = 0;
1048 } 1084 }
1049 if (((old_priv.flags & ASYNC_SPD_MASK) != 1085 if (((old_priv.flags & ASYNC_SPD_MASK) !=
1050 (priv->flags & ASYNC_SPD_MASK)) || 1086 (priv->flags & ASYNC_SPD_MASK)) ||
1051 (((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) && 1087 (((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) &&
1052 (old_priv.custom_divisor != priv->custom_divisor))) { 1088 (old_priv.custom_divisor != priv->custom_divisor))) {
1053 change_speed(port); 1089 change_speed(tty, port);
1054 } 1090 }
1055 1091 return 0;
1056 return (0);
1057 1092
1058} /* set_serial_info */ 1093} /* set_serial_info */
1059 1094
@@ -1082,11 +1117,10 @@ static void ftdi_determine_type(struct usb_serial_port *port)
1082 priv->chip_type = FT2232C; 1117 priv->chip_type = FT2232C;
1083 /* Determine interface code. */ 1118 /* Determine interface code. */
1084 inter = serial->interface->altsetting->desc.bInterfaceNumber; 1119 inter = serial->interface->altsetting->desc.bInterfaceNumber;
1085 if (inter == 0) { 1120 if (inter == 0)
1086 priv->interface = PIT_SIOA; 1121 priv->interface = PIT_SIOA;
1087 } else { 1122 else
1088 priv->interface = PIT_SIOB; 1123 priv->interface = PIT_SIOB;
1089 }
1090 /* BM-type devices have a bug where bcdDevice gets set 1124 /* BM-type devices have a bug where bcdDevice gets set
1091 * to 0x200 when iSerialNumber is 0. */ 1125 * to 0x200 when iSerialNumber is 0. */
1092 if (version < 0x500) { 1126 if (version < 0x500) {
@@ -1120,7 +1154,8 @@ static void ftdi_determine_type(struct usb_serial_port *port)
1120 * *************************************************************************** 1154 * ***************************************************************************
1121 */ 1155 */
1122 1156
1123static ssize_t show_latency_timer(struct device *dev, struct device_attribute *attr, char *buf) 1157static ssize_t show_latency_timer(struct device *dev,
1158 struct device_attribute *attr, char *buf)
1124{ 1159{
1125 struct usb_serial_port *port = to_usb_serial_port(dev); 1160 struct usb_serial_port *port = to_usb_serial_port(dev);
1126 struct ftdi_private *priv = usb_get_serial_port_data(port); 1161 struct ftdi_private *priv = usb_get_serial_port_data(port);
@@ -1129,14 +1164,14 @@ static ssize_t show_latency_timer(struct device *dev, struct device_attribute *a
1129 int rv = 0; 1164 int rv = 0;
1130 1165
1131 1166
1132 dbg("%s",__func__); 1167 dbg("%s", __func__);
1133 1168
1134 rv = usb_control_msg(udev, 1169 rv = usb_control_msg(udev,
1135 usb_rcvctrlpipe(udev, 0), 1170 usb_rcvctrlpipe(udev, 0),
1136 FTDI_SIO_GET_LATENCY_TIMER_REQUEST, 1171 FTDI_SIO_GET_LATENCY_TIMER_REQUEST,
1137 FTDI_SIO_GET_LATENCY_TIMER_REQUEST_TYPE, 1172 FTDI_SIO_GET_LATENCY_TIMER_REQUEST_TYPE,
1138 0, priv->interface, 1173 0, priv->interface,
1139 (char*) &latency, 1, WDR_TIMEOUT); 1174 (char *) &latency, 1, WDR_TIMEOUT);
1140 1175
1141 if (rv < 0) { 1176 if (rv < 0) {
1142 dev_err(dev, "Unable to read latency timer: %i\n", rv); 1177 dev_err(dev, "Unable to read latency timer: %i\n", rv);
@@ -1146,8 +1181,9 @@ static ssize_t show_latency_timer(struct device *dev, struct device_attribute *a
1146} 1181}
1147 1182
1148/* Write a new value of the latency timer, in units of milliseconds. */ 1183/* Write a new value of the latency timer, in units of milliseconds. */
1149static ssize_t store_latency_timer(struct device *dev, struct device_attribute *attr, const char *valbuf, 1184static ssize_t store_latency_timer(struct device *dev,
1150 size_t count) 1185 struct device_attribute *attr, const char *valbuf,
1186 size_t count)
1151{ 1187{
1152 struct usb_serial_port *port = to_usb_serial_port(dev); 1188 struct usb_serial_port *port = to_usb_serial_port(dev);
1153 struct ftdi_private *priv = usb_get_serial_port_data(port); 1189 struct ftdi_private *priv = usb_get_serial_port_data(port);
@@ -1175,8 +1211,8 @@ static ssize_t store_latency_timer(struct device *dev, struct device_attribute *
1175 1211
1176/* Write an event character directly to the FTDI register. The ASCII 1212/* Write an event character directly to the FTDI register. The ASCII
1177 value is in the low 8 bits, with the enable bit in the 9th bit. */ 1213 value is in the low 8 bits, with the enable bit in the 9th bit. */
1178static ssize_t store_event_char(struct device *dev, struct device_attribute *attr, const char *valbuf, 1214static ssize_t store_event_char(struct device *dev,
1179 size_t count) 1215 struct device_attribute *attr, const char *valbuf, size_t count)
1180{ 1216{
1181 struct usb_serial_port *port = to_usb_serial_port(dev); 1217 struct usb_serial_port *port = to_usb_serial_port(dev);
1182 struct ftdi_private *priv = usb_get_serial_port_data(port); 1218 struct ftdi_private *priv = usb_get_serial_port_data(port);
@@ -1202,7 +1238,8 @@ static ssize_t store_event_char(struct device *dev, struct device_attribute *att
1202 return count; 1238 return count;
1203} 1239}
1204 1240
1205static DEVICE_ATTR(latency_timer, S_IWUSR | S_IRUGO, show_latency_timer, store_latency_timer); 1241static DEVICE_ATTR(latency_timer, S_IWUSR | S_IRUGO, show_latency_timer,
1242 store_latency_timer);
1206static DEVICE_ATTR(event_char, S_IWUSR, NULL, store_event_char); 1243static DEVICE_ATTR(event_char, S_IWUSR, NULL, store_event_char);
1207 1244
1208static int create_sysfs_attrs(struct usb_serial_port *port) 1245static int create_sysfs_attrs(struct usb_serial_port *port)
@@ -1210,7 +1247,7 @@ static int create_sysfs_attrs(struct usb_serial_port *port)
1210 struct ftdi_private *priv = usb_get_serial_port_data(port); 1247 struct ftdi_private *priv = usb_get_serial_port_data(port);
1211 int retval = 0; 1248 int retval = 0;
1212 1249
1213 dbg("%s",__func__); 1250 dbg("%s", __func__);
1214 1251
1215 /* XXX I've no idea if the original SIO supports the event_char 1252 /* XXX I've no idea if the original SIO supports the event_char
1216 * sysfs parameter, so I'm playing it safe. */ 1253 * sysfs parameter, so I'm playing it safe. */
@@ -1232,7 +1269,7 @@ static void remove_sysfs_attrs(struct usb_serial_port *port)
1232{ 1269{
1233 struct ftdi_private *priv = usb_get_serial_port_data(port); 1270 struct ftdi_private *priv = usb_get_serial_port_data(port);
1234 1271
1235 dbg("%s",__func__); 1272 dbg("%s", __func__);
1236 1273
1237 /* XXX see create_sysfs_attrs */ 1274 /* XXX see create_sysfs_attrs */
1238 if (priv->chip_type != SIO) { 1275 if (priv->chip_type != SIO) {
@@ -1253,9 +1290,11 @@ static void remove_sysfs_attrs(struct usb_serial_port *port)
1253 */ 1290 */
1254 1291
1255/* Probe function to check for special devices */ 1292/* Probe function to check for special devices */
1256static int ftdi_sio_probe (struct usb_serial *serial, const struct usb_device_id *id) 1293static int ftdi_sio_probe(struct usb_serial *serial,
1294 const struct usb_device_id *id)
1257{ 1295{
1258 struct ftdi_sio_quirk *quirk = (struct ftdi_sio_quirk *)id->driver_info; 1296 struct ftdi_sio_quirk *quirk =
1297 (struct ftdi_sio_quirk *)id->driver_info;
1259 1298
1260 if (quirk && quirk->probe) { 1299 if (quirk && quirk->probe) {
1261 int ret = quirk->probe(serial); 1300 int ret = quirk->probe(serial);
@@ -1274,17 +1313,18 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port)
1274 struct ftdi_sio_quirk *quirk = usb_get_serial_data(port->serial); 1313 struct ftdi_sio_quirk *quirk = usb_get_serial_data(port->serial);
1275 1314
1276 1315
1277 dbg("%s",__func__); 1316 dbg("%s", __func__);
1278 1317
1279 priv = kzalloc(sizeof(struct ftdi_private), GFP_KERNEL); 1318 priv = kzalloc(sizeof(struct ftdi_private), GFP_KERNEL);
1280 if (!priv){ 1319 if (!priv) {
1281 err("%s- kmalloc(%Zd) failed.", __func__, sizeof(struct ftdi_private)); 1320 err("%s- kmalloc(%Zd) failed.", __func__,
1321 sizeof(struct ftdi_private));
1282 return -ENOMEM; 1322 return -ENOMEM;
1283 } 1323 }
1284 1324
1285 spin_lock_init(&priv->rx_lock); 1325 spin_lock_init(&priv->rx_lock);
1286 spin_lock_init(&priv->tx_lock); 1326 spin_lock_init(&priv->tx_lock);
1287 init_waitqueue_head(&priv->delta_msr_wait); 1327 init_waitqueue_head(&priv->delta_msr_wait);
1288 /* This will push the characters through immediately rather 1328 /* This will push the characters through immediately rather
1289 than queue a task to deliver them */ 1329 than queue a task to deliver them */
1290 priv->flags = ASYNC_LOW_LATENCY; 1330 priv->flags = ASYNC_LOW_LATENCY;
@@ -1294,9 +1334,9 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port)
1294 1334
1295 /* Increase the size of read buffers */ 1335 /* Increase the size of read buffers */
1296 kfree(port->bulk_in_buffer); 1336 kfree(port->bulk_in_buffer);
1297 port->bulk_in_buffer = kmalloc (BUFSZ, GFP_KERNEL); 1337 port->bulk_in_buffer = kmalloc(BUFSZ, GFP_KERNEL);
1298 if (!port->bulk_in_buffer) { 1338 if (!port->bulk_in_buffer) {
1299 kfree (priv); 1339 kfree(priv);
1300 return -ENOMEM; 1340 return -ENOMEM;
1301 } 1341 }
1302 if (port->read_urb) { 1342 if (port->read_urb) {
@@ -1309,7 +1349,7 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port)
1309 1349
1310 /* Free port's existing write urb and transfer buffer. */ 1350 /* Free port's existing write urb and transfer buffer. */
1311 if (port->write_urb) { 1351 if (port->write_urb) {
1312 usb_free_urb (port->write_urb); 1352 usb_free_urb(port->write_urb);
1313 port->write_urb = NULL; 1353 port->write_urb = NULL;
1314 } 1354 }
1315 kfree(port->bulk_out_buffer); 1355 kfree(port->bulk_out_buffer);
@@ -1317,7 +1357,7 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port)
1317 1357
1318 usb_set_serial_port_data(port, priv); 1358 usb_set_serial_port_data(port, priv);
1319 1359
1320 ftdi_determine_type (port); 1360 ftdi_determine_type(port);
1321 create_sysfs_attrs(port); 1361 create_sysfs_attrs(port);
1322 return 0; 1362 return 0;
1323} 1363}
@@ -1325,9 +1365,9 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port)
1325/* Setup for the USB-UIRT device, which requires hardwired 1365/* Setup for the USB-UIRT device, which requires hardwired
1326 * baudrate (38400 gets mapped to 312500) */ 1366 * baudrate (38400 gets mapped to 312500) */
1327/* Called from usbserial:serial_probe */ 1367/* Called from usbserial:serial_probe */
1328static void ftdi_USB_UIRT_setup (struct ftdi_private *priv) 1368static void ftdi_USB_UIRT_setup(struct ftdi_private *priv)
1329{ 1369{
1330 dbg("%s",__func__); 1370 dbg("%s", __func__);
1331 1371
1332 priv->flags |= ASYNC_SPD_CUST; 1372 priv->flags |= ASYNC_SPD_CUST;
1333 priv->custom_divisor = 77; 1373 priv->custom_divisor = 77;
@@ -1336,9 +1376,10 @@ static void ftdi_USB_UIRT_setup (struct ftdi_private *priv)
1336 1376
1337/* Setup for the HE-TIRA1 device, which requires hardwired 1377/* Setup for the HE-TIRA1 device, which requires hardwired
1338 * baudrate (38400 gets mapped to 100000) and RTS-CTS enabled. */ 1378 * baudrate (38400 gets mapped to 100000) and RTS-CTS enabled. */
1339static void ftdi_HE_TIRA1_setup (struct ftdi_private *priv) 1379
1380static void ftdi_HE_TIRA1_setup(struct ftdi_private *priv)
1340{ 1381{
1341 dbg("%s",__func__); 1382 dbg("%s", __func__);
1342 1383
1343 priv->flags |= ASYNC_SPD_CUST; 1384 priv->flags |= ASYNC_SPD_CUST;
1344 priv->custom_divisor = 240; 1385 priv->custom_divisor = 240;
@@ -1356,7 +1397,7 @@ static int ftdi_jtag_probe(struct usb_serial *serial)
1356 struct usb_device *udev = serial->dev; 1397 struct usb_device *udev = serial->dev;
1357 struct usb_interface *interface = serial->interface; 1398 struct usb_interface *interface = serial->interface;
1358 1399
1359 dbg("%s",__func__); 1400 dbg("%s", __func__);
1360 1401
1361 if (interface == udev->actconfig->interface[0]) { 1402 if (interface == udev->actconfig->interface[0]) {
1362 info("Ignoring serial port reserved for JTAG"); 1403 info("Ignoring serial port reserved for JTAG");
@@ -1390,7 +1431,7 @@ static int ftdi_mtxorb_hack_setup(struct usb_serial *serial)
1390 * calls __serial_close for each open of the port 1431 * calls __serial_close for each open of the port
1391 * shutdown is called then (ie ftdi_shutdown) 1432 * shutdown is called then (ie ftdi_shutdown)
1392 */ 1433 */
1393static void ftdi_shutdown (struct usb_serial *serial) 1434static void ftdi_shutdown(struct usb_serial *serial)
1394{ 1435{
1395 dbg("%s", __func__); 1436 dbg("%s", __func__);
1396} 1437}
@@ -1404,7 +1445,7 @@ static int ftdi_sio_port_remove(struct usb_serial_port *port)
1404 remove_sysfs_attrs(port); 1445 remove_sysfs_attrs(port);
1405 1446
1406 /* all open ports are closed at this point 1447 /* all open ports are closed at this point
1407 * (by usbserial.c:__serial_close, which calls ftdi_close) 1448 * (by usbserial.c:__serial_close, which calls ftdi_close)
1408 */ 1449 */
1409 1450
1410 if (priv) { 1451 if (priv) {
@@ -1415,7 +1456,8 @@ static int ftdi_sio_port_remove(struct usb_serial_port *port)
1415 return 0; 1456 return 0;
1416} 1457}
1417 1458
1418static int ftdi_open (struct usb_serial_port *port, struct file *filp) 1459static int ftdi_open(struct tty_struct *tty,
1460 struct usb_serial_port *port, struct file *filp)
1419{ /* ftdi_open */ 1461{ /* ftdi_open */
1420 struct usb_device *dev = port->serial->dev; 1462 struct usb_device *dev = port->serial->dev;
1421 struct ftdi_private *priv = usb_get_serial_port_data(port); 1463 struct ftdi_private *priv = usb_get_serial_port_data(port);
@@ -1433,8 +1475,8 @@ static int ftdi_open (struct usb_serial_port *port, struct file *filp)
1433 priv->rx_bytes = 0; 1475 priv->rx_bytes = 0;
1434 spin_unlock_irqrestore(&priv->rx_lock, flags); 1476 spin_unlock_irqrestore(&priv->rx_lock, flags);
1435 1477
1436 if (port->tty) 1478 if (tty)
1437 port->tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0; 1479 tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
1438 1480
1439 /* No error checking for this (will get errors later anyway) */ 1481 /* No error checking for this (will get errors later anyway) */
1440 /* See ftdi_sio.h for description of what is reset */ 1482 /* See ftdi_sio.h for description of what is reset */
@@ -1448,8 +1490,8 @@ static int ftdi_open (struct usb_serial_port *port, struct file *filp)
1448 This is same behaviour as serial.c/rs_open() - Kuba */ 1490 This is same behaviour as serial.c/rs_open() - Kuba */
1449 1491
1450 /* ftdi_set_termios will send usb control messages */ 1492 /* ftdi_set_termios will send usb control messages */
1451 if (port->tty) 1493 if (tty)
1452 ftdi_set_termios(port, port->tty->termios); 1494 ftdi_set_termios(tty, port, tty->termios);
1453 1495
1454 /* FIXME: Flow control might be enabled, so it should be checked - 1496 /* FIXME: Flow control might be enabled, so it should be checked -
1455 we have no control of defaults! */ 1497 we have no control of defaults! */
@@ -1464,12 +1506,14 @@ static int ftdi_open (struct usb_serial_port *port, struct file *filp)
1464 /* Start reading from the device */ 1506 /* Start reading from the device */
1465 priv->rx_processed = 0; 1507 priv->rx_processed = 0;
1466 usb_fill_bulk_urb(port->read_urb, dev, 1508 usb_fill_bulk_urb(port->read_urb, dev,
1467 usb_rcvbulkpipe(dev, port->bulk_in_endpointAddress), 1509 usb_rcvbulkpipe(dev, port->bulk_in_endpointAddress),
1468 port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, 1510 port->read_urb->transfer_buffer,
1469 ftdi_read_bulk_callback, port); 1511 port->read_urb->transfer_buffer_length,
1512 ftdi_read_bulk_callback, port);
1470 result = usb_submit_urb(port->read_urb, GFP_KERNEL); 1513 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
1471 if (result) 1514 if (result)
1472 err("%s - failed submitting read urb, error %d", __func__, result); 1515 err("%s - failed submitting read urb, error %d",
1516 __func__, result);
1473 1517
1474 1518
1475 return result; 1519 return result;
@@ -1485,16 +1529,17 @@ static int ftdi_open (struct usb_serial_port *port, struct file *filp)
1485 * 1529 *
1486 */ 1530 */
1487 1531
1488static void ftdi_close (struct usb_serial_port *port, struct file *filp) 1532static void ftdi_close(struct tty_struct *tty,
1533 struct usb_serial_port *port, struct file *filp)
1489{ /* ftdi_close */ 1534{ /* ftdi_close */
1490 unsigned int c_cflag = port->tty->termios->c_cflag; 1535 unsigned int c_cflag = tty->termios->c_cflag;
1491 struct ftdi_private *priv = usb_get_serial_port_data(port); 1536 struct ftdi_private *priv = usb_get_serial_port_data(port);
1492 char buf[1]; 1537 char buf[1];
1493 1538
1494 dbg("%s", __func__); 1539 dbg("%s", __func__);
1495 1540
1496 mutex_lock(&port->serial->disc_mutex); 1541 mutex_lock(&port->serial->disc_mutex);
1497 if (c_cflag & HUPCL && !port->serial->disconnected){ 1542 if (c_cflag & HUPCL && !port->serial->disconnected) {
1498 /* Disable flow control */ 1543 /* Disable flow control */
1499 if (usb_control_msg(port->serial->dev, 1544 if (usb_control_msg(port->serial->dev,
1500 usb_sndctrlpipe(port->serial->dev, 0), 1545 usb_sndctrlpipe(port->serial->dev, 0),
@@ -1527,7 +1572,7 @@ static void ftdi_close (struct usb_serial_port *port, struct file *filp)
1527 * 1572 *
1528 * The new devices do not require this byte 1573 * The new devices do not require this byte
1529 */ 1574 */
1530static int ftdi_write (struct usb_serial_port *port, 1575static int ftdi_write(struct tty_struct *tty, struct usb_serial_port *port,
1531 const unsigned char *buf, int count) 1576 const unsigned char *buf, int count)
1532{ /* ftdi_write */ 1577{ /* ftdi_write */
1533 struct ftdi_private *priv = usb_get_serial_port_data(port); 1578 struct ftdi_private *priv = usb_get_serial_port_data(port);
@@ -1554,7 +1599,7 @@ static int ftdi_write (struct usb_serial_port *port,
1554 spin_unlock_irqrestore(&priv->tx_lock, flags); 1599 spin_unlock_irqrestore(&priv->tx_lock, flags);
1555 1600
1556 data_offset = priv->write_offset; 1601 data_offset = priv->write_offset;
1557 dbg("data_offset set to %d",data_offset); 1602 dbg("data_offset set to %d", data_offset);
1558 1603
1559 /* Determine total transfer size */ 1604 /* Determine total transfer size */
1560 transfer_size = count; 1605 transfer_size = count;
@@ -1565,7 +1610,7 @@ static int ftdi_write (struct usb_serial_port *port,
1565 (PKTSZ - data_offset))); 1610 (PKTSZ - data_offset)));
1566 } 1611 }
1567 1612
1568 buffer = kmalloc (transfer_size, GFP_ATOMIC); 1613 buffer = kmalloc(transfer_size, GFP_ATOMIC);
1569 if (!buffer) { 1614 if (!buffer) {
1570 err("%s ran out of kernel memory for urb ...", __func__); 1615 err("%s ran out of kernel memory for urb ...", __func__);
1571 count = -ENOMEM; 1616 count = -ENOMEM;
@@ -1581,20 +1626,20 @@ static int ftdi_write (struct usb_serial_port *port,
1581 1626
1582 /* Copy data */ 1627 /* Copy data */
1583 if (data_offset > 0) { 1628 if (data_offset > 0) {
1584 /* Original sio requires control byte at start of each packet. */ 1629 /* Original sio requires control byte at start of
1630 each packet. */
1585 int user_pktsz = PKTSZ - data_offset; 1631 int user_pktsz = PKTSZ - data_offset;
1586 int todo = count; 1632 int todo = count;
1587 unsigned char *first_byte = buffer; 1633 unsigned char *first_byte = buffer;
1588 const unsigned char *current_position = buf; 1634 const unsigned char *current_position = buf;
1589 1635
1590 while (todo > 0) { 1636 while (todo > 0) {
1591 if (user_pktsz > todo) { 1637 if (user_pktsz > todo)
1592 user_pktsz = todo; 1638 user_pktsz = todo;
1593 }
1594 /* Write the control byte at the front of the packet*/ 1639 /* Write the control byte at the front of the packet*/
1595 *first_byte = 1 | ((user_pktsz) << 2); 1640 *first_byte = 1 | ((user_pktsz) << 2);
1596 /* Copy data for packet */ 1641 /* Copy data for packet */
1597 memcpy (first_byte + data_offset, 1642 memcpy(first_byte + data_offset,
1598 current_position, user_pktsz); 1643 current_position, user_pktsz);
1599 first_byte += user_pktsz + data_offset; 1644 first_byte += user_pktsz + data_offset;
1600 current_position += user_pktsz; 1645 current_position += user_pktsz;
@@ -1603,20 +1648,23 @@ static int ftdi_write (struct usb_serial_port *port,
1603 } else { 1648 } else {
1604 /* No control byte required. */ 1649 /* No control byte required. */
1605 /* Copy in the data to send */ 1650 /* Copy in the data to send */
1606 memcpy (buffer, buf, count); 1651 memcpy(buffer, buf, count);
1607 } 1652 }
1608 1653
1609 usb_serial_debug_data(debug, &port->dev, __func__, transfer_size, buffer); 1654 usb_serial_debug_data(debug, &port->dev, __func__,
1655 transfer_size, buffer);
1610 1656
1611 /* fill the buffer and send it */ 1657 /* fill the buffer and send it */
1612 usb_fill_bulk_urb(urb, port->serial->dev, 1658 usb_fill_bulk_urb(urb, port->serial->dev,
1613 usb_sndbulkpipe(port->serial->dev, port->bulk_out_endpointAddress), 1659 usb_sndbulkpipe(port->serial->dev,
1614 buffer, transfer_size, 1660 port->bulk_out_endpointAddress),
1615 ftdi_write_bulk_callback, port); 1661 buffer, transfer_size,
1662 ftdi_write_bulk_callback, port);
1616 1663
1617 status = usb_submit_urb(urb, GFP_ATOMIC); 1664 status = usb_submit_urb(urb, GFP_ATOMIC);
1618 if (status) { 1665 if (status) {
1619 err("%s - failed submitting write urb, error %d", __func__, status); 1666 err("%s - failed submitting write urb, error %d",
1667 __func__, status);
1620 count = status; 1668 count = status;
1621 goto error; 1669 goto error;
1622 } else { 1670 } else {
@@ -1635,7 +1683,7 @@ static int ftdi_write (struct usb_serial_port *port,
1635error: 1683error:
1636 usb_free_urb(urb); 1684 usb_free_urb(urb);
1637error_no_urb: 1685error_no_urb:
1638 kfree (buffer); 1686 kfree(buffer);
1639error_no_buffer: 1687error_no_buffer:
1640 spin_lock_irqsave(&priv->tx_lock, flags); 1688 spin_lock_irqsave(&priv->tx_lock, flags);
1641 priv->tx_outstanding_urbs--; 1689 priv->tx_outstanding_urbs--;
@@ -1646,7 +1694,7 @@ error_no_buffer:
1646 1694
1647/* This function may get called when the device is closed */ 1695/* This function may get called when the device is closed */
1648 1696
1649static void ftdi_write_bulk_callback (struct urb *urb) 1697static void ftdi_write_bulk_callback(struct urb *urb)
1650{ 1698{
1651 unsigned long flags; 1699 unsigned long flags;
1652 struct usb_serial_port *port = urb->context; 1700 struct usb_serial_port *port = urb->context;
@@ -1656,7 +1704,7 @@ static void ftdi_write_bulk_callback (struct urb *urb)
1656 int status = urb->status; 1704 int status = urb->status;
1657 1705
1658 /* free up the transfer buffer, as usb_free_urb() does not do this */ 1706 /* free up the transfer buffer, as usb_free_urb() does not do this */
1659 kfree (urb->transfer_buffer); 1707 kfree(urb->transfer_buffer);
1660 1708
1661 dbg("%s - port %d", __func__, port->number); 1709 dbg("%s - port %d", __func__, port->number);
1662 1710
@@ -1686,8 +1734,9 @@ static void ftdi_write_bulk_callback (struct urb *urb)
1686} /* ftdi_write_bulk_callback */ 1734} /* ftdi_write_bulk_callback */
1687 1735
1688 1736
1689static int ftdi_write_room( struct usb_serial_port *port ) 1737static int ftdi_write_room(struct tty_struct *tty)
1690{ 1738{
1739 struct usb_serial_port *port = tty->driver_data;
1691 struct ftdi_private *priv = usb_get_serial_port_data(port); 1740 struct ftdi_private *priv = usb_get_serial_port_data(port);
1692 int room; 1741 int room;
1693 unsigned long flags; 1742 unsigned long flags;
@@ -1707,11 +1756,11 @@ static int ftdi_write_room( struct usb_serial_port *port )
1707 } 1756 }
1708 spin_unlock_irqrestore(&priv->tx_lock, flags); 1757 spin_unlock_irqrestore(&priv->tx_lock, flags);
1709 return room; 1758 return room;
1710} /* ftdi_write_room */ 1759}
1711
1712 1760
1713static int ftdi_chars_in_buffer (struct usb_serial_port *port) 1761static int ftdi_chars_in_buffer(struct tty_struct *tty)
1714{ /* ftdi_chars_in_buffer */ 1762{
1763 struct usb_serial_port *port = tty->driver_data;
1715 struct ftdi_private *priv = usb_get_serial_port_data(port); 1764 struct ftdi_private *priv = usb_get_serial_port_data(port);
1716 int buffered; 1765 int buffered;
1717 unsigned long flags; 1766 unsigned long flags;
@@ -1726,12 +1775,10 @@ static int ftdi_chars_in_buffer (struct usb_serial_port *port)
1726 buffered = 0; 1775 buffered = 0;
1727 } 1776 }
1728 return buffered; 1777 return buffered;
1729} /* ftdi_chars_in_buffer */ 1778}
1730
1731
1732 1779
1733static void ftdi_read_bulk_callback (struct urb *urb) 1780static void ftdi_read_bulk_callback(struct urb *urb)
1734{ /* ftdi_read_bulk_callback */ 1781{
1735 struct usb_serial_port *port = urb->context; 1782 struct usb_serial_port *port = urb->context;
1736 struct tty_struct *tty; 1783 struct tty_struct *tty;
1737 struct ftdi_private *priv; 1784 struct ftdi_private *priv;
@@ -1740,19 +1787,21 @@ static void ftdi_read_bulk_callback (struct urb *urb)
1740 int status = urb->status; 1787 int status = urb->status;
1741 1788
1742 if (urb->number_of_packets > 0) { 1789 if (urb->number_of_packets > 0) {
1743 err("%s transfer_buffer_length %d actual_length %d number of packets %d",__func__, 1790 err("%s transfer_buffer_length %d actual_length %d number of packets %d",
1744 urb->transfer_buffer_length, urb->actual_length, urb->number_of_packets ); 1791 __func__,
1745 err("%s transfer_flags %x ", __func__,urb->transfer_flags ); 1792 urb->transfer_buffer_length,
1793 urb->actual_length, urb->number_of_packets);
1794 err("%s transfer_flags %x ", __func__, urb->transfer_flags);
1746 } 1795 }
1747 1796
1748 dbg("%s - port %d", __func__, port->number); 1797 dbg("%s - port %d", __func__, port->number);
1749 1798
1750 if (port->open_count <= 0) 1799 if (port->port.count <= 0)
1751 return; 1800 return;
1752 1801
1753 tty = port->tty; 1802 tty = port->port.tty;
1754 if (!tty) { 1803 if (!tty) {
1755 dbg("%s - bad tty pointer - exiting",__func__); 1804 dbg("%s - bad tty pointer - exiting", __func__);
1756 return; 1805 return;
1757 } 1806 }
1758 1807
@@ -1762,14 +1811,13 @@ static void ftdi_read_bulk_callback (struct urb *urb)
1762 return; 1811 return;
1763 } 1812 }
1764 1813
1765 if (urb != port->read_urb) { 1814 if (urb != port->read_urb)
1766 err("%s - Not my urb!", __func__); 1815 err("%s - Not my urb!", __func__);
1767 }
1768 1816
1769 if (status) { 1817 if (status) {
1770 /* This will happen at close every time so it is a dbg not an err */ 1818 /* This will happen at close every time so it is a dbg not an
1771 dbg("(this is ok on close) nonzero read bulk status received: " 1819 err */
1772 "%d", status); 1820 dbg("(this is ok on close) nonzero read bulk status received: %d", status);
1773 return; 1821 return;
1774 } 1822 }
1775 1823
@@ -1785,7 +1833,7 @@ static void ftdi_read_bulk_callback (struct urb *urb)
1785} /* ftdi_read_bulk_callback */ 1833} /* ftdi_read_bulk_callback */
1786 1834
1787 1835
1788static void ftdi_process_read (struct work_struct *work) 1836static void ftdi_process_read(struct work_struct *work)
1789{ /* ftdi_process_read */ 1837{ /* ftdi_process_read */
1790 struct ftdi_private *priv = 1838 struct ftdi_private *priv =
1791 container_of(work, struct ftdi_private, rx_work.work); 1839 container_of(work, struct ftdi_private, rx_work.work);
@@ -1803,12 +1851,12 @@ static void ftdi_process_read (struct work_struct *work)
1803 1851
1804 dbg("%s - port %d", __func__, port->number); 1852 dbg("%s - port %d", __func__, port->number);
1805 1853
1806 if (port->open_count <= 0) 1854 if (port->port.count <= 0)
1807 return; 1855 return;
1808 1856
1809 tty = port->tty; 1857 tty = port->port.tty;
1810 if (!tty) { 1858 if (!tty) {
1811 dbg("%s - bad tty pointer - exiting",__func__); 1859 dbg("%s - bad tty pointer - exiting", __func__);
1812 return; 1860 return;
1813 } 1861 }
1814 1862
@@ -1832,11 +1880,11 @@ static void ftdi_process_read (struct work_struct *work)
1832 urb->actual_length - priv->rx_processed); 1880 urb->actual_length - priv->rx_processed);
1833 } else { 1881 } else {
1834 /* The first two bytes of every read packet are status */ 1882 /* The first two bytes of every read packet are status */
1835 if (urb->actual_length > 2) { 1883 if (urb->actual_length > 2)
1836 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); 1884 usb_serial_debug_data(debug, &port->dev, __func__,
1837 } else { 1885 urb->actual_length, data);
1838 dbg("Status only: %03oo %03oo",data[0],data[1]); 1886 else
1839 } 1887 dbg("Status only: %03oo %03oo", data[0], data[1]);
1840 } 1888 }
1841 1889
1842 1890
@@ -1846,16 +1894,19 @@ static void ftdi_process_read (struct work_struct *work)
1846 /* if CD is dropped and the line is not CLOCAL then we should hangup */ 1894 /* if CD is dropped and the line is not CLOCAL then we should hangup */
1847 1895
1848 need_flip = 0; 1896 need_flip = 0;
1849 for (packet_offset = priv->rx_processed; packet_offset < urb->actual_length; packet_offset += PKTSZ) { 1897 for (packet_offset = priv->rx_processed;
1898 packet_offset < urb->actual_length; packet_offset += PKTSZ) {
1850 int length; 1899 int length;
1851 1900
1852 /* Compare new line status to the old one, signal if different */ 1901 /* Compare new line status to the old one, signal if different/
1853 /* N.B. packet may be processed more than once, but differences 1902 N.B. packet may be processed more than once, but differences
1854 * are only processed once. */ 1903 are only processed once. */
1855 if (priv != NULL) { 1904 if (priv != NULL) {
1856 char new_status = data[packet_offset+0] & FTDI_STATUS_B0_MASK; 1905 char new_status = data[packet_offset + 0] &
1906 FTDI_STATUS_B0_MASK;
1857 if (new_status != priv->prev_status) { 1907 if (new_status != priv->prev_status) {
1858 priv->diff_status |= new_status ^ priv->prev_status; 1908 priv->diff_status |=
1909 new_status ^ priv->prev_status;
1859 wake_up_interruptible(&priv->delta_msr_wait); 1910 wake_up_interruptible(&priv->delta_msr_wait);
1860 priv->prev_status = new_status; 1911 priv->prev_status = new_status;
1861 } 1912 }
@@ -1872,30 +1923,31 @@ static void ftdi_process_read (struct work_struct *work)
1872 break; 1923 break;
1873 } 1924 }
1874 if (tty_buffer_request_room(tty, length) < length) { 1925 if (tty_buffer_request_room(tty, length) < length) {
1875 /* break out & wait for throttling/unthrottling to happen */ 1926 /* break out & wait for throttling/unthrottling to
1927 happen */
1876 dbg("%s - receive room low", __func__); 1928 dbg("%s - receive room low", __func__);
1877 break; 1929 break;
1878 } 1930 }
1879 1931
1880 /* Handle errors and break */ 1932 /* Handle errors and break */
1881 error_flag = TTY_NORMAL; 1933 error_flag = TTY_NORMAL;
1882 /* Although the device uses a bitmask and hence can have multiple */ 1934 /* Although the device uses a bitmask and hence can have
1883 /* errors on a packet - the order here sets the priority the */ 1935 multiple errors on a packet - the order here sets the
1884 /* error is returned to the tty layer */ 1936 priority the error is returned to the tty layer */
1885 1937
1886 if ( data[packet_offset+1] & FTDI_RS_OE ) { 1938 if (data[packet_offset+1] & FTDI_RS_OE) {
1887 error_flag = TTY_OVERRUN; 1939 error_flag = TTY_OVERRUN;
1888 dbg("OVERRRUN error"); 1940 dbg("OVERRRUN error");
1889 } 1941 }
1890 if ( data[packet_offset+1] & FTDI_RS_BI ) { 1942 if (data[packet_offset+1] & FTDI_RS_BI) {
1891 error_flag = TTY_BREAK; 1943 error_flag = TTY_BREAK;
1892 dbg("BREAK received"); 1944 dbg("BREAK received");
1893 } 1945 }
1894 if ( data[packet_offset+1] & FTDI_RS_PE ) { 1946 if (data[packet_offset+1] & FTDI_RS_PE) {
1895 error_flag = TTY_PARITY; 1947 error_flag = TTY_PARITY;
1896 dbg("PARITY error"); 1948 dbg("PARITY error");
1897 } 1949 }
1898 if ( data[packet_offset+1] & FTDI_RS_FE ) { 1950 if (data[packet_offset+1] & FTDI_RS_FE) {
1899 error_flag = TTY_FRAME; 1951 error_flag = TTY_FRAME;
1900 dbg("FRAMING error"); 1952 dbg("FRAMING error");
1901 } 1953 }
@@ -1904,7 +1956,8 @@ static void ftdi_process_read (struct work_struct *work)
1904 /* Note that the error flag is duplicated for 1956 /* Note that the error flag is duplicated for
1905 every character received since we don't know 1957 every character received since we don't know
1906 which character it applied to */ 1958 which character it applied to */
1907 tty_insert_flip_char(tty, data[packet_offset+i], error_flag); 1959 tty_insert_flip_char(tty,
1960 data[packet_offset + i], error_flag);
1908 } 1961 }
1909 need_flip = 1; 1962 need_flip = 1;
1910 } 1963 }
@@ -1912,19 +1965,19 @@ static void ftdi_process_read (struct work_struct *work)
1912#ifdef NOT_CORRECT_BUT_KEEPING_IT_FOR_NOW 1965#ifdef NOT_CORRECT_BUT_KEEPING_IT_FOR_NOW
1913 /* if a parity error is detected you get status packets forever 1966 /* if a parity error is detected you get status packets forever
1914 until a character is sent without a parity error. 1967 until a character is sent without a parity error.
1915 This doesn't work well since the application receives a never 1968 This doesn't work well since the application receives a
1916 ending stream of bad data - even though new data hasn't been sent. 1969 never ending stream of bad data - even though new data
1917 Therefore I (bill) have taken this out. 1970 hasn't been sent. Therefore I (bill) have taken this out.
1918 However - this might make sense for framing errors and so on 1971 However - this might make sense for framing errors and so on
1919 so I am leaving the code in for now. 1972 so I am leaving the code in for now.
1920 */ 1973 */
1921 else { 1974 else {
1922 if (error_flag != TTY_NORMAL){ 1975 if (error_flag != TTY_NORMAL) {
1923 dbg("error_flag is not normal"); 1976 dbg("error_flag is not normal");
1924 /* In this case it is just status - if that is an error send a bad character */ 1977 /* In this case it is just status - if that is
1925 if(tty->flip.count >= TTY_FLIPBUF_SIZE) { 1978 an error send a bad character */
1979 if (tty->flip.count >= TTY_FLIPBUF_SIZE)
1926 tty_flip_buffer_push(tty); 1980 tty_flip_buffer_push(tty);
1927 }
1928 tty_insert_flip_char(tty, 0xff, error_flag); 1981 tty_insert_flip_char(tty, 0xff, error_flag);
1929 need_flip = 1; 1982 need_flip = 1;
1930 } 1983 }
@@ -1933,9 +1986,8 @@ static void ftdi_process_read (struct work_struct *work)
1933 } /* "for(packet_offset=0..." */ 1986 } /* "for(packet_offset=0..." */
1934 1987
1935 /* Low latency */ 1988 /* Low latency */
1936 if (need_flip) { 1989 if (need_flip)
1937 tty_flip_buffer_push(tty); 1990 tty_flip_buffer_push(tty);
1938 }
1939 1991
1940 if (packet_offset < urb->actual_length) { 1992 if (packet_offset < urb->actual_length) {
1941 /* not completely processed - record progress */ 1993 /* not completely processed - record progress */
@@ -1954,12 +2006,11 @@ static void ftdi_process_read (struct work_struct *work)
1954 } 2006 }
1955 spin_unlock_irqrestore(&priv->rx_lock, flags); 2007 spin_unlock_irqrestore(&priv->rx_lock, flags);
1956 /* if the port is closed stop trying to read */ 2008 /* if the port is closed stop trying to read */
1957 if (port->open_count > 0){ 2009 if (port->port.count > 0)
1958 /* delay processing of remainder */ 2010 /* delay processing of remainder */
1959 schedule_delayed_work(&priv->rx_work, 1); 2011 schedule_delayed_work(&priv->rx_work, 1);
1960 } else { 2012 else
1961 dbg("%s - port is closed", __func__); 2013 dbg("%s - port is closed", __func__);
1962 }
1963 return; 2014 return;
1964 } 2015 }
1965 2016
@@ -1967,24 +2018,26 @@ static void ftdi_process_read (struct work_struct *work)
1967 priv->rx_processed = 0; 2018 priv->rx_processed = 0;
1968 2019
1969 /* if the port is closed stop trying to read */ 2020 /* if the port is closed stop trying to read */
1970 if (port->open_count > 0){ 2021 if (port->port.count > 0) {
1971 /* Continue trying to always read */ 2022 /* Continue trying to always read */
1972 usb_fill_bulk_urb(port->read_urb, port->serial->dev, 2023 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
1973 usb_rcvbulkpipe(port->serial->dev, port->bulk_in_endpointAddress), 2024 usb_rcvbulkpipe(port->serial->dev,
1974 port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, 2025 port->bulk_in_endpointAddress),
1975 ftdi_read_bulk_callback, port); 2026 port->read_urb->transfer_buffer,
2027 port->read_urb->transfer_buffer_length,
2028 ftdi_read_bulk_callback, port);
1976 2029
1977 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 2030 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
1978 if (result) 2031 if (result)
1979 err("%s - failed resubmitting read urb, error %d", __func__, result); 2032 err("%s - failed resubmitting read urb, error %d",
2033 __func__, result);
1980 } 2034 }
1981
1982 return;
1983} /* ftdi_process_read */ 2035} /* ftdi_process_read */
1984 2036
1985 2037
1986static void ftdi_break_ctl( struct usb_serial_port *port, int break_state ) 2038static void ftdi_break_ctl(struct tty_struct *tty, int break_state)
1987{ 2039{
2040 struct usb_serial_port *port = tty->driver_data;
1988 struct ftdi_private *priv = usb_get_serial_port_data(port); 2041 struct ftdi_private *priv = usb_get_serial_port_data(port);
1989 __u16 urb_value = 0; 2042 __u16 urb_value = 0;
1990 char buf[1]; 2043 char buf[1];
@@ -1993,22 +2046,23 @@ static void ftdi_break_ctl( struct usb_serial_port *port, int break_state )
1993 /* see drivers/char/tty_io.c to see it used */ 2046 /* see drivers/char/tty_io.c to see it used */
1994 /* last_set_data_urb_value NEVER has the break bit set in it */ 2047 /* last_set_data_urb_value NEVER has the break bit set in it */
1995 2048
1996 if (break_state) { 2049 if (break_state)
1997 urb_value = priv->last_set_data_urb_value | FTDI_SIO_SET_BREAK; 2050 urb_value = priv->last_set_data_urb_value | FTDI_SIO_SET_BREAK;
1998 } else { 2051 else
1999 urb_value = priv->last_set_data_urb_value; 2052 urb_value = priv->last_set_data_urb_value;
2000 }
2001 2053
2002 2054 if (usb_control_msg(port->serial->dev,
2003 if (usb_control_msg(port->serial->dev, usb_sndctrlpipe(port->serial->dev, 0), 2055 usb_sndctrlpipe(port->serial->dev, 0),
2004 FTDI_SIO_SET_DATA_REQUEST, 2056 FTDI_SIO_SET_DATA_REQUEST,
2005 FTDI_SIO_SET_DATA_REQUEST_TYPE, 2057 FTDI_SIO_SET_DATA_REQUEST_TYPE,
2006 urb_value , priv->interface, 2058 urb_value , priv->interface,
2007 buf, 0, WDR_TIMEOUT) < 0) { 2059 buf, 0, WDR_TIMEOUT) < 0) {
2008 err("%s FAILED to enable/disable break state (state was %d)", __func__,break_state); 2060 err("%s FAILED to enable/disable break state (state was %d)",
2061 __func__, break_state);
2009 } 2062 }
2010 2063
2011 dbg("%s break state is %d - urb is %d", __func__,break_state, urb_value); 2064 dbg("%s break state is %d - urb is %d", __func__,
2065 break_state, urb_value);
2012 2066
2013} 2067}
2014 2068
@@ -2018,26 +2072,28 @@ static void ftdi_break_ctl( struct usb_serial_port *port, int break_state )
2018 * WARNING: set_termios calls this with old_termios in kernel space 2072 * WARNING: set_termios calls this with old_termios in kernel space
2019 */ 2073 */
2020 2074
2021static void ftdi_set_termios (struct usb_serial_port *port, struct ktermios *old_termios) 2075static void ftdi_set_termios(struct tty_struct *tty,
2076 struct usb_serial_port *port, struct ktermios *old_termios)
2022{ /* ftdi_termios */ 2077{ /* ftdi_termios */
2023 struct usb_device *dev = port->serial->dev; 2078 struct usb_device *dev = port->serial->dev;
2024 struct ftdi_private *priv = usb_get_serial_port_data(port); 2079 struct ftdi_private *priv = usb_get_serial_port_data(port);
2025 struct ktermios *termios = port->tty->termios; 2080 struct ktermios *termios = tty->termios;
2026 unsigned int cflag = termios->c_cflag; 2081 unsigned int cflag = termios->c_cflag;
2027 __u16 urb_value; /* will hold the new flags */ 2082 __u16 urb_value; /* will hold the new flags */
2028 char buf[1]; /* Perhaps I should dynamically alloc this? */ 2083 char buf[1]; /* Perhaps I should dynamically alloc this? */
2029 2084
2030 // Added for xon/xoff support 2085 /* Added for xon/xoff support */
2031 unsigned int iflag = termios->c_iflag; 2086 unsigned int iflag = termios->c_iflag;
2032 unsigned char vstop; 2087 unsigned char vstop;
2033 unsigned char vstart; 2088 unsigned char vstart;
2034 2089
2035 dbg("%s", __func__); 2090 dbg("%s", __func__);
2036 2091
2037 /* Force baud rate if this device requires it, unless it is set to B0. */ 2092 /* Force baud rate if this device requires it, unless it is set to
2093 B0. */
2038 if (priv->force_baud && ((termios->c_cflag & CBAUD) != B0)) { 2094 if (priv->force_baud && ((termios->c_cflag & CBAUD) != B0)) {
2039 dbg("%s: forcing baud rate for this device", __func__); 2095 dbg("%s: forcing baud rate for this device", __func__);
2040 tty_encode_baud_rate(port->tty, priv->force_baud, 2096 tty_encode_baud_rate(tty, priv->force_baud,
2041 priv->force_baud); 2097 priv->force_baud);
2042 } 2098 }
2043 2099
@@ -2053,8 +2109,8 @@ static void ftdi_set_termios (struct usb_serial_port *port, struct ktermios *old
2053 not - so just do the change regardless - should be able to 2109 not - so just do the change regardless - should be able to
2054 compare old_termios and tty->termios */ 2110 compare old_termios and tty->termios */
2055 /* NOTE These routines can get interrupted by 2111 /* NOTE These routines can get interrupted by
2056 ftdi_sio_read_bulk_callback - need to examine what this 2112 ftdi_sio_read_bulk_callback - need to examine what this means -
2057 means - don't see any problems yet */ 2113 don't see any problems yet */
2058 2114
2059 /* Set number of data bits, parity, stop bits */ 2115 /* Set number of data bits, parity, stop bits */
2060 2116
@@ -2078,8 +2134,8 @@ static void ftdi_set_termios (struct usb_serial_port *port, struct ktermios *old
2078 } 2134 }
2079 } 2135 }
2080 2136
2081 /* This is needed by the break command since it uses the same command - but is 2137 /* This is needed by the break command since it uses the same command
2082 * or'ed with this value */ 2138 - but is or'ed with this value */
2083 priv->last_set_data_urb_value = urb_value; 2139 priv->last_set_data_urb_value = urb_value;
2084 2140
2085 if (usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 2141 if (usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
@@ -2091,7 +2147,7 @@ static void ftdi_set_termios (struct usb_serial_port *port, struct ktermios *old
2091 } 2147 }
2092 2148
2093 /* Now do the baudrate */ 2149 /* Now do the baudrate */
2094 if ((cflag & CBAUD) == B0 ) { 2150 if ((cflag & CBAUD) == B0) {
2095 /* Disable flow control */ 2151 /* Disable flow control */
2096 if (usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 2152 if (usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
2097 FTDI_SIO_SET_FLOW_CTRL_REQUEST, 2153 FTDI_SIO_SET_FLOW_CTRL_REQUEST,
@@ -2104,13 +2160,11 @@ static void ftdi_set_termios (struct usb_serial_port *port, struct ktermios *old
2104 clear_mctrl(port, TIOCM_DTR | TIOCM_RTS); 2160 clear_mctrl(port, TIOCM_DTR | TIOCM_RTS);
2105 } else { 2161 } else {
2106 /* set the baudrate determined before */ 2162 /* set the baudrate determined before */
2107 if (change_speed(port)) { 2163 if (change_speed(tty, port))
2108 err("%s urb failed to set baudrate", __func__); 2164 err("%s urb failed to set baudrate", __func__);
2109 }
2110 /* Ensure RTS and DTR are raised when baudrate changed from 0 */ 2165 /* Ensure RTS and DTR are raised when baudrate changed from 0 */
2111 if (!old_termios || (old_termios->c_cflag & CBAUD) == B0) { 2166 if (!old_termios || (old_termios->c_cflag & CBAUD) == B0)
2112 set_mctrl(port, TIOCM_DTR | TIOCM_RTS); 2167 set_mctrl(port, TIOCM_DTR | TIOCM_RTS);
2113 }
2114 } 2168 }
2115 2169
2116 /* Set flow control */ 2170 /* Set flow control */
@@ -2130,18 +2184,22 @@ static void ftdi_set_termios (struct usb_serial_port *port, struct ktermios *old
2130 /* 2184 /*
2131 * Xon/Xoff code 2185 * Xon/Xoff code
2132 * 2186 *
2133 * Check the IXOFF status in the iflag component of the termios structure 2187 * Check the IXOFF status in the iflag component of the
2134 * if IXOFF is not set, the pre-xon/xoff code is executed. 2188 * termios structure. If IXOFF is not set, the pre-xon/xoff
2135 */ 2189 * code is executed.
2190 */
2136 if (iflag & IXOFF) { 2191 if (iflag & IXOFF) {
2137 dbg("%s request to enable xonxoff iflag=%04x",__func__,iflag); 2192 dbg("%s request to enable xonxoff iflag=%04x",
2138 // Try to enable the XON/XOFF on the ftdi_sio 2193 __func__, iflag);
2139 // Set the vstart and vstop -- could have been done up above where 2194 /* Try to enable the XON/XOFF on the ftdi_sio
2140 // a lot of other dereferencing is done but that would be very 2195 * Set the vstart and vstop -- could have been done up
2141 // inefficient as vstart and vstop are not always needed 2196 * above where a lot of other dereferencing is done but
2197 * that would be very inefficient as vstart and vstop
2198 * are not always needed.
2199 */
2142 vstart = termios->c_cc[VSTART]; 2200 vstart = termios->c_cc[VSTART];
2143 vstop = termios->c_cc[VSTOP]; 2201 vstop = termios->c_cc[VSTOP];
2144 urb_value=(vstop << 8) | (vstart); 2202 urb_value = (vstop << 8) | (vstart);
2145 2203
2146 if (usb_control_msg(dev, 2204 if (usb_control_msg(dev,
2147 usb_sndctrlpipe(dev, 0), 2205 usb_sndctrlpipe(dev, 0),
@@ -2153,8 +2211,9 @@ static void ftdi_set_termios (struct usb_serial_port *port, struct ktermios *old
2153 err("urb failed to set to xon/xoff flow control"); 2211 err("urb failed to set to xon/xoff flow control");
2154 } 2212 }
2155 } else { 2213 } else {
2156 /* else clause to only run if cfag ! CRTSCTS and iflag ! XOFF */ 2214 /* else clause to only run if cflag ! CRTSCTS and iflag
2157 /* CHECKME Assuming XON/XOFF handled by tty stack - not by device */ 2215 * ! XOFF. CHECKME Assuming XON/XOFF handled by tty
2216 * stack - not by device */
2158 dbg("%s Turning off hardware flow control", __func__); 2217 dbg("%s Turning off hardware flow control", __func__);
2159 if (usb_control_msg(dev, 2218 if (usb_control_msg(dev,
2160 usb_sndctrlpipe(dev, 0), 2219 usb_sndctrlpipe(dev, 0),
@@ -2168,11 +2227,11 @@ static void ftdi_set_termios (struct usb_serial_port *port, struct ktermios *old
2168 2227
2169 } 2228 }
2170 return; 2229 return;
2171} /* ftdi_termios */ 2230}
2172
2173 2231
2174static int ftdi_tiocmget (struct usb_serial_port *port, struct file *file) 2232static int ftdi_tiocmget(struct tty_struct *tty, struct file *file)
2175{ 2233{
2234 struct usb_serial_port *port = tty->driver_data;
2176 struct ftdi_private *priv = usb_get_serial_port_data(port); 2235 struct ftdi_private *priv = usb_get_serial_port_data(port);
2177 unsigned char buf[2]; 2236 unsigned char buf[2];
2178 int ret; 2237 int ret;
@@ -2181,32 +2240,35 @@ static int ftdi_tiocmget (struct usb_serial_port *port, struct file *file)
2181 switch (priv->chip_type) { 2240 switch (priv->chip_type) {
2182 case SIO: 2241 case SIO:
2183 /* Request the status from the device */ 2242 /* Request the status from the device */
2184 if ((ret = usb_control_msg(port->serial->dev, 2243 ret = usb_control_msg(port->serial->dev,
2185 usb_rcvctrlpipe(port->serial->dev, 0), 2244 usb_rcvctrlpipe(port->serial->dev, 0),
2186 FTDI_SIO_GET_MODEM_STATUS_REQUEST, 2245 FTDI_SIO_GET_MODEM_STATUS_REQUEST,
2187 FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE, 2246 FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE,
2188 0, 0, 2247 0, 0,
2189 buf, 1, WDR_TIMEOUT)) < 0 ) { 2248 buf, 1, WDR_TIMEOUT);
2249 if (ret < 0) {
2190 err("%s Could not get modem status of device - err: %d", __func__, 2250 err("%s Could not get modem status of device - err: %d", __func__,
2191 ret); 2251 ret);
2192 return(ret); 2252 return ret;
2193 } 2253 }
2194 break; 2254 break;
2195 case FT8U232AM: 2255 case FT8U232AM:
2196 case FT232BM: 2256 case FT232BM:
2197 case FT2232C: 2257 case FT2232C:
2198 case FT232RL: 2258 case FT232RL:
2199 /* the 8U232AM returns a two byte value (the sio is a 1 byte value) - in the same 2259 /* the 8U232AM returns a two byte value (the sio is a 1 byte
2200 format as the data returned from the in point */ 2260 value) - in the same format as the data returned from the in
2201 if ((ret = usb_control_msg(port->serial->dev, 2261 point */
2202 usb_rcvctrlpipe(port->serial->dev, 0), 2262 ret = usb_control_msg(port->serial->dev,
2203 FTDI_SIO_GET_MODEM_STATUS_REQUEST, 2263 usb_rcvctrlpipe(port->serial->dev, 0),
2204 FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE, 2264 FTDI_SIO_GET_MODEM_STATUS_REQUEST,
2205 0, priv->interface, 2265 FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE,
2206 buf, 2, WDR_TIMEOUT)) < 0 ) { 2266 0, priv->interface,
2267 buf, 2, WDR_TIMEOUT);
2268 if (ret < 0) {
2207 err("%s Could not get modem status of device - err: %d", __func__, 2269 err("%s Could not get modem status of device - err: %d", __func__,
2208 ret); 2270 ret);
2209 return(ret); 2271 return ret;
2210 } 2272 }
2211 break; 2273 break;
2212 default: 2274 default:
@@ -2221,15 +2283,19 @@ static int ftdi_tiocmget (struct usb_serial_port *port, struct file *file)
2221 priv->last_dtr_rts; 2283 priv->last_dtr_rts;
2222} 2284}
2223 2285
2224static int ftdi_tiocmset(struct usb_serial_port *port, struct file * file, unsigned int set, unsigned int clear) 2286static int ftdi_tiocmset(struct tty_struct *tty, struct file *file,
2287 unsigned int set, unsigned int clear)
2225{ 2288{
2289 struct usb_serial_port *port = tty->driver_data;
2226 dbg("%s TIOCMSET", __func__); 2290 dbg("%s TIOCMSET", __func__);
2227 return update_mctrl(port, set, clear); 2291 return update_mctrl(port, set, clear);
2228} 2292}
2229 2293
2230 2294
2231static int ftdi_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg) 2295static int ftdi_ioctl(struct tty_struct *tty, struct file *file,
2296 unsigned int cmd, unsigned long arg)
2232{ 2297{
2298 struct usb_serial_port *port = tty->driver_data;
2233 struct ftdi_private *priv = usb_get_serial_port_data(port); 2299 struct ftdi_private *priv = usb_get_serial_port_data(port);
2234 2300
2235 dbg("%s cmd 0x%04x", __func__, cmd); 2301 dbg("%s cmd 0x%04x", __func__, cmd);
@@ -2238,10 +2304,12 @@ static int ftdi_ioctl (struct usb_serial_port *port, struct file * file, unsigne
2238 switch (cmd) { 2304 switch (cmd) {
2239 2305
2240 case TIOCGSERIAL: /* gets serial port data */ 2306 case TIOCGSERIAL: /* gets serial port data */
2241 return get_serial_info(port, (struct serial_struct __user *) arg); 2307 return get_serial_info(port,
2308 (struct serial_struct __user *) arg);
2242 2309
2243 case TIOCSSERIAL: /* sets serial port data */ 2310 case TIOCSSERIAL: /* sets serial port data */
2244 return set_serial_info(port, (struct serial_struct __user *) arg); 2311 return set_serial_info(tty, port,
2312 (struct serial_struct __user *) arg);
2245 2313
2246 /* 2314 /*
2247 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change 2315 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
@@ -2260,45 +2328,41 @@ static int ftdi_ioctl (struct usb_serial_port *port, struct file * file, unsigne
2260 else { 2328 else {
2261 char diff = priv->diff_status; 2329 char diff = priv->diff_status;
2262 2330
2263 if (diff == 0) { 2331 if (diff == 0)
2264 return -EIO; /* no change => error */ 2332 return -EIO; /* no change => error */
2265 }
2266 2333
2267 /* Consume all events */ 2334 /* Consume all events */
2268 priv->diff_status = 0; 2335 priv->diff_status = 0;
2269 2336
2270 /* Return 0 if caller wanted to know about these bits */ 2337 /* Return 0 if caller wanted to know about
2271 if ( ((arg & TIOCM_RNG) && (diff & FTDI_RS0_RI)) || 2338 these bits */
2272 ((arg & TIOCM_DSR) && (diff & FTDI_RS0_DSR)) || 2339 if (((arg & TIOCM_RNG) && (diff & FTDI_RS0_RI)) ||
2273 ((arg & TIOCM_CD) && (diff & FTDI_RS0_RLSD)) || 2340 ((arg & TIOCM_DSR) && (diff & FTDI_RS0_DSR)) ||
2274 ((arg & TIOCM_CTS) && (diff & FTDI_RS0_CTS)) ) { 2341 ((arg & TIOCM_CD) && (diff & FTDI_RS0_RLSD)) ||
2342 ((arg & TIOCM_CTS) && (diff & FTDI_RS0_CTS))) {
2275 return 0; 2343 return 0;
2276 } 2344 }
2277 /* 2345 /*
2278 * Otherwise caller can't care less about what happened, 2346 * Otherwise caller can't care less about what
2279 * and so we continue to wait for more events. 2347 * happened,and so we continue to wait for more
2348 * events.
2280 */ 2349 */
2281 } 2350 }
2282 } 2351 }
2283 return(0); 2352 return 0;
2284 break;
2285 default: 2353 default:
2286 break; 2354 break;
2287
2288 } 2355 }
2289 2356 /* This is not necessarily an error - turns out the higher layers
2290 2357 * will do some ioctls themselves (see comment above)
2291 /* This is not necessarily an error - turns out the higher layers will do
2292 * some ioctls itself (see comment above)
2293 */ 2358 */
2294 dbg("%s arg not supported - it was 0x%04x - check /usr/include/asm/ioctls.h", __func__, cmd); 2359 dbg("%s arg not supported - it was 0x%04x - check /usr/include/asm/ioctls.h", __func__, cmd);
2360 return -ENOIOCTLCMD;
2361}
2295 2362
2296 return(-ENOIOCTLCMD); 2363static void ftdi_throttle(struct tty_struct *tty)
2297} /* ftdi_ioctl */
2298
2299
2300static void ftdi_throttle (struct usb_serial_port *port)
2301{ 2364{
2365 struct usb_serial_port *port = tty->driver_data;
2302 struct ftdi_private *priv = usb_get_serial_port_data(port); 2366 struct ftdi_private *priv = usb_get_serial_port_data(port);
2303 unsigned long flags; 2367 unsigned long flags;
2304 2368
@@ -2310,8 +2374,9 @@ static void ftdi_throttle (struct usb_serial_port *port)
2310} 2374}
2311 2375
2312 2376
2313static void ftdi_unthrottle (struct usb_serial_port *port) 2377static void ftdi_unthrottle(struct tty_struct *tty)
2314{ 2378{
2379 struct usb_serial_port *port = tty->driver_data;
2315 struct ftdi_private *priv = usb_get_serial_port_data(port); 2380 struct ftdi_private *priv = usb_get_serial_port_data(port);
2316 int actually_throttled; 2381 int actually_throttled;
2317 unsigned long flags; 2382 unsigned long flags;
@@ -2327,7 +2392,7 @@ static void ftdi_unthrottle (struct usb_serial_port *port)
2327 schedule_delayed_work(&priv->rx_work, 0); 2392 schedule_delayed_work(&priv->rx_work, 0);
2328} 2393}
2329 2394
2330static int __init ftdi_init (void) 2395static int __init ftdi_init(void)
2331{ 2396{
2332 int retval; 2397 int retval;
2333 2398
@@ -2357,13 +2422,13 @@ failed_sio_register:
2357} 2422}
2358 2423
2359 2424
2360static void __exit ftdi_exit (void) 2425static void __exit ftdi_exit(void)
2361{ 2426{
2362 2427
2363 dbg("%s", __func__); 2428 dbg("%s", __func__);
2364 2429
2365 usb_deregister (&ftdi_driver); 2430 usb_deregister(&ftdi_driver);
2366 usb_serial_deregister (&ftdi_sio_device); 2431 usb_serial_deregister(&ftdi_sio_device);
2367 2432
2368} 2433}
2369 2434
@@ -2371,8 +2436,8 @@ static void __exit ftdi_exit (void)
2371module_init(ftdi_init); 2436module_init(ftdi_init);
2372module_exit(ftdi_exit); 2437module_exit(ftdi_exit);
2373 2438
2374MODULE_AUTHOR( DRIVER_AUTHOR ); 2439MODULE_AUTHOR(DRIVER_AUTHOR);
2375MODULE_DESCRIPTION( DRIVER_DESC ); 2440MODULE_DESCRIPTION(DRIVER_DESC);
2376MODULE_LICENSE("GPL"); 2441MODULE_LICENSE("GPL");
2377 2442
2378module_param(debug, bool, S_IRUGO | S_IWUSR); 2443module_param(debug, bool, S_IRUGO | S_IWUSR);
diff --git a/drivers/usb/serial/ftdi_sio.h b/drivers/usb/serial/ftdi_sio.h
index 8302eca893ea..a577ea44dcf9 100644
--- a/drivers/usb/serial/ftdi_sio.h
+++ b/drivers/usb/serial/ftdi_sio.h
@@ -1,20 +1,20 @@
1/* 1/*
2 * Definitions for the FTDI USB Single Port Serial Converter - 2 * Definitions for the FTDI USB Single Port Serial Converter -
3 * known as FTDI_SIO (Serial Input/Output application of the chipset) 3 * known as FTDI_SIO (Serial Input/Output application of the chipset)
4 * 4 *
5 * The example I have is known as the USC-1000 which is available from 5 * The example I have is known as the USC-1000 which is available from
6 * http://www.dse.co.nz - cat no XH4214 It looks similar to this: 6 * http://www.dse.co.nz - cat no XH4214 It looks similar to this:
7 * http://www.dansdata.com/usbser.htm but I can't be sure There are other 7 * http://www.dansdata.com/usbser.htm but I can't be sure There are other
8 * USC-1000s which don't look like my device though so beware! 8 * USC-1000s which don't look like my device though so beware!
9 * 9 *
10 * The device is based on the FTDI FT8U100AX chip. It has a DB25 on one side, 10 * The device is based on the FTDI FT8U100AX chip. It has a DB25 on one side,
11 * USB on the other. 11 * USB on the other.
12 * 12 *
13 * Thanx to FTDI (http://www.ftdi.co.uk) for so kindly providing details 13 * Thanx to FTDI (http://www.ftdi.co.uk) for so kindly providing details
14 * of the protocol required to talk to the device and ongoing assistence 14 * of the protocol required to talk to the device and ongoing assistence
15 * during development. 15 * during development.
16 * 16 *
17 * Bill Ryder - bryder@sgi.com formerly of Silicon Graphics, Inc.- wrote the 17 * Bill Ryder - bryder@sgi.com formerly of Silicon Graphics, Inc.- wrote the
18 * FTDI_SIO implementation. 18 * FTDI_SIO implementation.
19 * 19 *
20 * Philipp Gühring - pg@futureware.at - added the Device ID of the USB relais 20 * Philipp Gühring - pg@futureware.at - added the Device ID of the USB relais
@@ -472,7 +472,7 @@
472/* 472/*
473 * DSS-20 Sync Station for Sony Ericsson P800 473 * DSS-20 Sync Station for Sony Ericsson P800
474 */ 474 */
475#define FTDI_DSS20_PID 0xFC82 475#define FTDI_DSS20_PID 0xFC82
476 476
477/* 477/*
478 * Home Electronics (www.home-electro.com) USB gadgets 478 * Home Electronics (www.home-electro.com) USB gadgets
@@ -884,7 +884,7 @@
884/* 884/*
885 * BmRequestType: 0100 0000B 885 * BmRequestType: 0100 0000B
886 * bRequest: FTDI_SIO_RESET 886 * bRequest: FTDI_SIO_RESET
887 * wValue: Control Value 887 * wValue: Control Value
888 * 0 = Reset SIO 888 * 0 = Reset SIO
889 * 1 = Purge RX buffer 889 * 1 = Purge RX buffer
890 * 2 = Purge TX buffer 890 * 2 = Purge TX buffer
@@ -952,7 +952,7 @@
952 * 101 - add .625 to divisor 952 * 101 - add .625 to divisor
953 * 110 - add .750 to divisor 953 * 110 - add .750 to divisor
954 * 111 - add .875 to divisor 954 * 111 - add .875 to divisor
955 * Bits 15 to 0 of the 17-bit divisor are placed in the urb value. Bit 16 is 955 * Bits 15 to 0 of the 17-bit divisor are placed in the urb value. Bit 16 is
956 * placed in bit 0 of the urb index. 956 * placed in bit 0 of the urb index.
957 * 957 *
958 * Note that there are a couple of special cases to support the highest baud 958 * Note that there are a couple of special cases to support the highest baud
@@ -971,8 +971,8 @@ typedef enum {
971} ftdi_chip_type_t; 971} ftdi_chip_type_t;
972 972
973typedef enum { 973typedef enum {
974 ftdi_sio_b300 = 0, 974 ftdi_sio_b300 = 0,
975 ftdi_sio_b600 = 1, 975 ftdi_sio_b600 = 1,
976 ftdi_sio_b1200 = 2, 976 ftdi_sio_b1200 = 2,
977 ftdi_sio_b2400 = 3, 977 ftdi_sio_b2400 = 3,
978 ftdi_sio_b4800 = 4, 978 ftdi_sio_b4800 = 4,
@@ -981,7 +981,7 @@ typedef enum {
981 ftdi_sio_b38400 = 7, 981 ftdi_sio_b38400 = 7,
982 ftdi_sio_b57600 = 8, 982 ftdi_sio_b57600 = 8,
983 ftdi_sio_b115200 = 9 983 ftdi_sio_b115200 = 9
984} FTDI_SIO_baudrate_t ; 984} FTDI_SIO_baudrate_t;
985 985
986/* 986/*
987 * The ftdi_8U232AM_xxMHz_byyy constants have been removed. The encoded divisor values 987 * The ftdi_8U232AM_xxMHz_byyy constants have been removed. The encoded divisor values
@@ -990,19 +990,19 @@ typedef enum {
990 990
991#define FTDI_SIO_SET_DATA_REQUEST FTDI_SIO_SET_DATA 991#define FTDI_SIO_SET_DATA_REQUEST FTDI_SIO_SET_DATA
992#define FTDI_SIO_SET_DATA_REQUEST_TYPE 0x40 992#define FTDI_SIO_SET_DATA_REQUEST_TYPE 0x40
993#define FTDI_SIO_SET_DATA_PARITY_NONE (0x0 << 8 ) 993#define FTDI_SIO_SET_DATA_PARITY_NONE (0x0 << 8)
994#define FTDI_SIO_SET_DATA_PARITY_ODD (0x1 << 8 ) 994#define FTDI_SIO_SET_DATA_PARITY_ODD (0x1 << 8)
995#define FTDI_SIO_SET_DATA_PARITY_EVEN (0x2 << 8 ) 995#define FTDI_SIO_SET_DATA_PARITY_EVEN (0x2 << 8)
996#define FTDI_SIO_SET_DATA_PARITY_MARK (0x3 << 8 ) 996#define FTDI_SIO_SET_DATA_PARITY_MARK (0x3 << 8)
997#define FTDI_SIO_SET_DATA_PARITY_SPACE (0x4 << 8 ) 997#define FTDI_SIO_SET_DATA_PARITY_SPACE (0x4 << 8)
998#define FTDI_SIO_SET_DATA_STOP_BITS_1 (0x0 << 11 ) 998#define FTDI_SIO_SET_DATA_STOP_BITS_1 (0x0 << 11)
999#define FTDI_SIO_SET_DATA_STOP_BITS_15 (0x1 << 11 ) 999#define FTDI_SIO_SET_DATA_STOP_BITS_15 (0x1 << 11)
1000#define FTDI_SIO_SET_DATA_STOP_BITS_2 (0x2 << 11 ) 1000#define FTDI_SIO_SET_DATA_STOP_BITS_2 (0x2 << 11)
1001#define FTDI_SIO_SET_BREAK (0x1 << 14) 1001#define FTDI_SIO_SET_BREAK (0x1 << 14)
1002/* FTDI_SIO_SET_DATA */ 1002/* FTDI_SIO_SET_DATA */
1003 1003
1004/* 1004/*
1005 * BmRequestType: 0100 0000B 1005 * BmRequestType: 0100 0000B
1006 * bRequest: FTDI_SIO_SET_DATA 1006 * bRequest: FTDI_SIO_SET_DATA
1007 * wValue: Data characteristics (see below) 1007 * wValue: Data characteristics (see below)
1008 * wIndex: Port 1008 * wIndex: Port
@@ -1035,7 +1035,7 @@ typedef enum {
1035#define FTDI_SIO_SET_MODEM_CTRL_REQUEST_TYPE 0x40 1035#define FTDI_SIO_SET_MODEM_CTRL_REQUEST_TYPE 0x40
1036#define FTDI_SIO_SET_MODEM_CTRL_REQUEST FTDI_SIO_MODEM_CTRL 1036#define FTDI_SIO_SET_MODEM_CTRL_REQUEST FTDI_SIO_MODEM_CTRL
1037 1037
1038/* 1038/*
1039 * BmRequestType: 0100 0000B 1039 * BmRequestType: 0100 0000B
1040 * bRequest: FTDI_SIO_MODEM_CTRL 1040 * bRequest: FTDI_SIO_MODEM_CTRL
1041 * wValue: ControlValue (see below) 1041 * wValue: ControlValue (see below)
@@ -1049,11 +1049,11 @@ typedef enum {
1049 */ 1049 */
1050 1050
1051#define FTDI_SIO_SET_DTR_MASK 0x1 1051#define FTDI_SIO_SET_DTR_MASK 0x1
1052#define FTDI_SIO_SET_DTR_HIGH ( 1 | ( FTDI_SIO_SET_DTR_MASK << 8)) 1052#define FTDI_SIO_SET_DTR_HIGH (1 | (FTDI_SIO_SET_DTR_MASK << 8))
1053#define FTDI_SIO_SET_DTR_LOW ( 0 | ( FTDI_SIO_SET_DTR_MASK << 8)) 1053#define FTDI_SIO_SET_DTR_LOW (0 | (FTDI_SIO_SET_DTR_MASK << 8))
1054#define FTDI_SIO_SET_RTS_MASK 0x2 1054#define FTDI_SIO_SET_RTS_MASK 0x2
1055#define FTDI_SIO_SET_RTS_HIGH ( 2 | ( FTDI_SIO_SET_RTS_MASK << 8 )) 1055#define FTDI_SIO_SET_RTS_HIGH (2 | (FTDI_SIO_SET_RTS_MASK << 8))
1056#define FTDI_SIO_SET_RTS_LOW ( 0 | ( FTDI_SIO_SET_RTS_MASK << 8 )) 1056#define FTDI_SIO_SET_RTS_LOW (0 | (FTDI_SIO_SET_RTS_MASK << 8))
1057 1057
1058/* 1058/*
1059 * ControlValue 1059 * ControlValue
@@ -1076,7 +1076,7 @@ typedef enum {
1076/* FTDI_SIO_SET_FLOW_CTRL */ 1076/* FTDI_SIO_SET_FLOW_CTRL */
1077#define FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE 0x40 1077#define FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE 0x40
1078#define FTDI_SIO_SET_FLOW_CTRL_REQUEST FTDI_SIO_SET_FLOW_CTRL 1078#define FTDI_SIO_SET_FLOW_CTRL_REQUEST FTDI_SIO_SET_FLOW_CTRL
1079#define FTDI_SIO_DISABLE_FLOW_CTRL 0x0 1079#define FTDI_SIO_DISABLE_FLOW_CTRL 0x0
1080#define FTDI_SIO_RTS_CTS_HS (0x1 << 8) 1080#define FTDI_SIO_RTS_CTS_HS (0x1 << 8)
1081#define FTDI_SIO_DTR_DSR_HS (0x2 << 8) 1081#define FTDI_SIO_DTR_DSR_HS (0x2 << 8)
1082#define FTDI_SIO_XON_XOFF_HS (0x4 << 8) 1082#define FTDI_SIO_XON_XOFF_HS (0x4 << 8)
@@ -1085,7 +1085,7 @@ typedef enum {
1085 * bRequest: FTDI_SIO_SET_FLOW_CTRL 1085 * bRequest: FTDI_SIO_SET_FLOW_CTRL
1086 * wValue: Xoff/Xon 1086 * wValue: Xoff/Xon
1087 * wIndex: Protocol/Port - hIndex is protocl / lIndex is port 1087 * wIndex: Protocol/Port - hIndex is protocl / lIndex is port
1088 * wLength: 0 1088 * wLength: 0
1089 * Data: None 1089 * Data: None
1090 * 1090 *
1091 * hIndex protocol is: 1091 * hIndex protocol is:
@@ -1101,10 +1101,10 @@ typedef enum {
1101 * 1101 *
1102 * A value of zero in the hIndex field disables handshaking 1102 * A value of zero in the hIndex field disables handshaking
1103 * 1103 *
1104 * If Xon/Xoff handshaking is specified, the hValue field should contain the XOFF character 1104 * If Xon/Xoff handshaking is specified, the hValue field should contain the XOFF character
1105 * and the lValue field contains the XON character. 1105 * and the lValue field contains the XON character.
1106 */ 1106 */
1107 1107
1108/* 1108/*
1109 * FTDI_SIO_GET_LATENCY_TIMER 1109 * FTDI_SIO_GET_LATENCY_TIMER
1110 * 1110 *
@@ -1118,7 +1118,7 @@ typedef enum {
1118#define FTDI_SIO_GET_LATENCY_TIMER_REQUEST FTDI_SIO_GET_LATENCY_TIMER 1118#define FTDI_SIO_GET_LATENCY_TIMER_REQUEST FTDI_SIO_GET_LATENCY_TIMER
1119#define FTDI_SIO_GET_LATENCY_TIMER_REQUEST_TYPE 0xC0 1119#define FTDI_SIO_GET_LATENCY_TIMER_REQUEST_TYPE 0xC0
1120 1120
1121/* 1121/*
1122 * BmRequestType: 1100 0000b 1122 * BmRequestType: 1100 0000b
1123 * bRequest: FTDI_SIO_GET_LATENCY_TIMER 1123 * bRequest: FTDI_SIO_GET_LATENCY_TIMER
1124 * wValue: 0 1124 * wValue: 0
@@ -1127,7 +1127,7 @@ typedef enum {
1127 * Data: latency (on return) 1127 * Data: latency (on return)
1128 */ 1128 */
1129 1129
1130/* 1130/*
1131 * FTDI_SIO_SET_LATENCY_TIMER 1131 * FTDI_SIO_SET_LATENCY_TIMER
1132 * 1132 *
1133 * Set the timeout interval. The FTDI collects data from the slave 1133 * Set the timeout interval. The FTDI collects data from the slave
@@ -1140,7 +1140,7 @@ typedef enum {
1140#define FTDI_SIO_SET_LATENCY_TIMER_REQUEST FTDI_SIO_SET_LATENCY_TIMER 1140#define FTDI_SIO_SET_LATENCY_TIMER_REQUEST FTDI_SIO_SET_LATENCY_TIMER
1141#define FTDI_SIO_SET_LATENCY_TIMER_REQUEST_TYPE 0x40 1141#define FTDI_SIO_SET_LATENCY_TIMER_REQUEST_TYPE 0x40
1142 1142
1143/* 1143/*
1144 * BmRequestType: 0100 0000b 1144 * BmRequestType: 0100 0000b
1145 * bRequest: FTDI_SIO_SET_LATENCY_TIMER 1145 * bRequest: FTDI_SIO_SET_LATENCY_TIMER
1146 * wValue: Latency (milliseconds) 1146 * wValue: Latency (milliseconds)
@@ -1155,7 +1155,7 @@ typedef enum {
1155 */ 1155 */
1156 1156
1157/* 1157/*
1158 * FTDI_SIO_SET_EVENT_CHAR 1158 * FTDI_SIO_SET_EVENT_CHAR
1159 * 1159 *
1160 * Set the special event character for the specified communications port. 1160 * Set the special event character for the specified communications port.
1161 * If the device sees this character it will immediately return the 1161 * If the device sees this character it will immediately return the
@@ -1168,7 +1168,7 @@ typedef enum {
1168#define FTDI_SIO_SET_EVENT_CHAR_REQUEST_TYPE 0x40 1168#define FTDI_SIO_SET_EVENT_CHAR_REQUEST_TYPE 0x40
1169 1169
1170 1170
1171/* 1171/*
1172 * BmRequestType: 0100 0000b 1172 * BmRequestType: 0100 0000b
1173 * bRequest: FTDI_SIO_SET_EVENT_CHAR 1173 * bRequest: FTDI_SIO_SET_EVENT_CHAR
1174 * wValue: EventChar 1174 * wValue: EventChar
@@ -1184,12 +1184,12 @@ typedef enum {
1184 * B9..15 Reserved 1184 * B9..15 Reserved
1185 * 1185 *
1186 */ 1186 */
1187 1187
1188/* FTDI_SIO_SET_ERROR_CHAR */ 1188/* FTDI_SIO_SET_ERROR_CHAR */
1189 1189
1190/* Set the parity error replacement character for the specified communications port */ 1190/* Set the parity error replacement character for the specified communications port */
1191 1191
1192/* 1192/*
1193 * BmRequestType: 0100 0000b 1193 * BmRequestType: 0100 0000b
1194 * bRequest: FTDI_SIO_SET_EVENT_CHAR 1194 * bRequest: FTDI_SIO_SET_EVENT_CHAR
1195 * wValue: Error Char 1195 * wValue: Error Char
@@ -1215,15 +1215,15 @@ typedef enum {
1215#define FTDI_SIO_DSR_MASK 0x20 1215#define FTDI_SIO_DSR_MASK 0x20
1216#define FTDI_SIO_RI_MASK 0x40 1216#define FTDI_SIO_RI_MASK 0x40
1217#define FTDI_SIO_RLSD_MASK 0x80 1217#define FTDI_SIO_RLSD_MASK 0x80
1218/* 1218/*
1219 * BmRequestType: 1100 0000b 1219 * BmRequestType: 1100 0000b
1220 * bRequest: FTDI_SIO_GET_MODEM_STATUS 1220 * bRequest: FTDI_SIO_GET_MODEM_STATUS
1221 * wValue: zero 1221 * wValue: zero
1222 * wIndex: Port 1222 * wIndex: Port
1223 * wLength: 1 1223 * wLength: 1
1224 * Data: Status 1224 * Data: Status
1225 * 1225 *
1226 * One byte of data is returned 1226 * One byte of data is returned
1227 * B0..3 0 1227 * B0..3 0
1228 * B4 CTS 1228 * B4 CTS
1229 * 0 = inactive 1229 * 0 = inactive
@@ -1236,15 +1236,15 @@ typedef enum {
1236 * 1 = active 1236 * 1 = active
1237 * B7 Receive Line Signal Detect (RLSD) 1237 * B7 Receive Line Signal Detect (RLSD)
1238 * 0 = inactive 1238 * 0 = inactive
1239 * 1 = active 1239 * 1 = active
1240 */ 1240 */
1241 1241
1242 1242
1243 1243
1244/* Descriptors returned by the device 1244/* Descriptors returned by the device
1245 * 1245 *
1246 * Device Descriptor 1246 * Device Descriptor
1247 * 1247 *
1248 * Offset Field Size Value Description 1248 * Offset Field Size Value Description
1249 * 0 bLength 1 0x12 Size of descriptor in bytes 1249 * 0 bLength 1 0x12 Size of descriptor in bytes
1250 * 1 bDescriptorType 1 0x01 DEVICE Descriptor Type 1250 * 1 bDescriptorType 1 0x01 DEVICE Descriptor Type
@@ -1260,9 +1260,9 @@ typedef enum {
1260 * 15 iProduct 1 0x02 Index of prod string desc 1260 * 15 iProduct 1 0x02 Index of prod string desc
1261 * 16 iSerialNumber 1 0x02 Index of serial nmr string desc 1261 * 16 iSerialNumber 1 0x02 Index of serial nmr string desc
1262 * 17 bNumConfigurations 1 0x01 Number of possible configurations 1262 * 17 bNumConfigurations 1 0x01 Number of possible configurations
1263 * 1263 *
1264 * Configuration Descriptor 1264 * Configuration Descriptor
1265 * 1265 *
1266 * Offset Field Size Value 1266 * Offset Field Size Value
1267 * 0 bLength 1 0x09 Size of descriptor in bytes 1267 * 0 bLength 1 0x09 Size of descriptor in bytes
1268 * 1 bDescriptorType 1 0x02 CONFIGURATION Descriptor Type 1268 * 1 bDescriptorType 1 0x02 CONFIGURATION Descriptor Type
@@ -1272,9 +1272,9 @@ typedef enum {
1272 * 6 iConfiguration 1 0x02 Index of config string descriptor 1272 * 6 iConfiguration 1 0x02 Index of config string descriptor
1273 * 7 bmAttributes 1 0x20 Config characteristics Remote Wakeup 1273 * 7 bmAttributes 1 0x20 Config characteristics Remote Wakeup
1274 * 8 MaxPower 1 0x1E Max power consumption 1274 * 8 MaxPower 1 0x1E Max power consumption
1275 * 1275 *
1276 * Interface Descriptor 1276 * Interface Descriptor
1277 * 1277 *
1278 * Offset Field Size Value 1278 * Offset Field Size Value
1279 * 0 bLength 1 0x09 Size of descriptor in bytes 1279 * 0 bLength 1 0x09 Size of descriptor in bytes
1280 * 1 bDescriptorType 1 0x04 INTERFACE Descriptor Type 1280 * 1 bDescriptorType 1 0x04 INTERFACE Descriptor Type
@@ -1285,9 +1285,9 @@ typedef enum {
1285 * 6 bInterfaceSubClass 1 0xFF Subclass Code 1285 * 6 bInterfaceSubClass 1 0xFF Subclass Code
1286 * 7 bInterfaceProtocol 1 0xFF Protocol Code 1286 * 7 bInterfaceProtocol 1 0xFF Protocol Code
1287 * 8 iInterface 1 0x02 Index of interface string description 1287 * 8 iInterface 1 0x02 Index of interface string description
1288 * 1288 *
1289 * IN Endpoint Descriptor 1289 * IN Endpoint Descriptor
1290 * 1290 *
1291 * Offset Field Size Value 1291 * Offset Field Size Value
1292 * 0 bLength 1 0x07 Size of descriptor in bytes 1292 * 0 bLength 1 0x07 Size of descriptor in bytes
1293 * 1 bDescriptorType 1 0x05 ENDPOINT descriptor type 1293 * 1 bDescriptorType 1 0x05 ENDPOINT descriptor type
@@ -1295,9 +1295,9 @@ typedef enum {
1295 * 3 bmAttributes 1 0x02 Endpoint attributes - Bulk 1295 * 3 bmAttributes 1 0x02 Endpoint attributes - Bulk
1296 * 4 bNumEndpoints 2 0x0040 maximum packet size 1296 * 4 bNumEndpoints 2 0x0040 maximum packet size
1297 * 5 bInterval 1 0x00 Interval for polling endpoint 1297 * 5 bInterval 1 0x00 Interval for polling endpoint
1298 * 1298 *
1299 * OUT Endpoint Descriptor 1299 * OUT Endpoint Descriptor
1300 * 1300 *
1301 * Offset Field Size Value 1301 * Offset Field Size Value
1302 * 0 bLength 1 0x07 Size of descriptor in bytes 1302 * 0 bLength 1 0x07 Size of descriptor in bytes
1303 * 1 bDescriptorType 1 0x05 ENDPOINT descriptor type 1303 * 1 bDescriptorType 1 0x05 ENDPOINT descriptor type
@@ -1305,17 +1305,17 @@ typedef enum {
1305 * 3 bmAttributes 1 0x02 Endpoint attributes - Bulk 1305 * 3 bmAttributes 1 0x02 Endpoint attributes - Bulk
1306 * 4 bNumEndpoints 2 0x0040 maximum packet size 1306 * 4 bNumEndpoints 2 0x0040 maximum packet size
1307 * 5 bInterval 1 0x00 Interval for polling endpoint 1307 * 5 bInterval 1 0x00 Interval for polling endpoint
1308 * 1308 *
1309 * DATA FORMAT 1309 * DATA FORMAT
1310 * 1310 *
1311 * IN Endpoint 1311 * IN Endpoint
1312 * 1312 *
1313 * The device reserves the first two bytes of data on this endpoint to contain the current 1313 * The device reserves the first two bytes of data on this endpoint to contain the current
1314 * values of the modem and line status registers. In the absence of data, the device 1314 * values of the modem and line status registers. In the absence of data, the device
1315 * generates a message consisting of these two status bytes every 40 ms 1315 * generates a message consisting of these two status bytes every 40 ms
1316 * 1316 *
1317 * Byte 0: Modem Status 1317 * Byte 0: Modem Status
1318 * 1318 *
1319 * Offset Description 1319 * Offset Description
1320 * B0 Reserved - must be 1 1320 * B0 Reserved - must be 1
1321 * B1 Reserved - must be 0 1321 * B1 Reserved - must be 0
@@ -1325,9 +1325,9 @@ typedef enum {
1325 * B5 Data Set Ready (DSR) 1325 * B5 Data Set Ready (DSR)
1326 * B6 Ring Indicator (RI) 1326 * B6 Ring Indicator (RI)
1327 * B7 Receive Line Signal Detect (RLSD) 1327 * B7 Receive Line Signal Detect (RLSD)
1328 * 1328 *
1329 * Byte 1: Line Status 1329 * Byte 1: Line Status
1330 * 1330 *
1331 * Offset Description 1331 * Offset Description
1332 * B0 Data Ready (DR) 1332 * B0 Data Ready (DR)
1333 * B1 Overrun Error (OE) 1333 * B1 Overrun Error (OE)
@@ -1337,7 +1337,7 @@ typedef enum {
1337 * B5 Transmitter Holding Register (THRE) 1337 * B5 Transmitter Holding Register (THRE)
1338 * B6 Transmitter Empty (TEMT) 1338 * B6 Transmitter Empty (TEMT)
1339 * B7 Error in RCVR FIFO 1339 * B7 Error in RCVR FIFO
1340 * 1340 *
1341 */ 1341 */
1342#define FTDI_RS0_CTS (1 << 4) 1342#define FTDI_RS0_CTS (1 << 4)
1343#define FTDI_RS0_DSR (1 << 5) 1343#define FTDI_RS0_DSR (1 << 5)
@@ -1355,17 +1355,17 @@ typedef enum {
1355 1355
1356/* 1356/*
1357 * OUT Endpoint 1357 * OUT Endpoint
1358 * 1358 *
1359 * This device reserves the first bytes of data on this endpoint contain the length 1359 * This device reserves the first bytes of data on this endpoint contain the length
1360 * and port identifier of the message. For the FTDI USB Serial converter the port 1360 * and port identifier of the message. For the FTDI USB Serial converter the port
1361 * identifier is always 1. 1361 * identifier is always 1.
1362 * 1362 *
1363 * Byte 0: Line Status 1363 * Byte 0: Line Status
1364 * 1364 *
1365 * Offset Description 1365 * Offset Description
1366 * B0 Reserved - must be 1 1366 * B0 Reserved - must be 1
1367 * B1 Reserved - must be 0 1367 * B1 Reserved - must be 0
1368 * B2..7 Length of message - (not including Byte 0) 1368 * B2..7 Length of message - (not including Byte 0)
1369 * 1369 *
1370 */ 1370 */
1371 1371
diff --git a/drivers/usb/serial/funsoft.c b/drivers/usb/serial/funsoft.c
index e8ba2cb5995d..d30f736d2cc5 100644
--- a/drivers/usb/serial/funsoft.c
+++ b/drivers/usb/serial/funsoft.c
@@ -14,7 +14,7 @@
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/usb.h> 15#include <linux/usb.h>
16#include <linux/usb/serial.h> 16#include <linux/usb/serial.h>
17#include <asm/uaccess.h> 17#include <linux/uaccess.h>
18 18
19static int debug; 19static int debug;
20 20
diff --git a/drivers/usb/serial/garmin_gps.c b/drivers/usb/serial/garmin_gps.c
index 8ce5a56a48e3..2e663f1afd5e 100644
--- a/drivers/usb/serial/garmin_gps.c
+++ b/drivers/usb/serial/garmin_gps.c
@@ -33,7 +33,7 @@
33#include <linux/tty_flip.h> 33#include <linux/tty_flip.h>
34#include <linux/module.h> 34#include <linux/module.h>
35#include <linux/spinlock.h> 35#include <linux/spinlock.h>
36#include <asm/uaccess.h> 36#include <linux/uaccess.h>
37#include <asm/atomic.h> 37#include <asm/atomic.h>
38#include <linux/usb.h> 38#include <linux/usb.h>
39#include <linux/usb/serial.h> 39#include <linux/usb/serial.h>
@@ -44,7 +44,7 @@
44static int initial_mode = 1; 44static int initial_mode = 1;
45 45
46/* debug flag */ 46/* debug flag */
47static int debug = 0; 47static int debug;
48 48
49#define GARMIN_VENDOR_ID 0x091E 49#define GARMIN_VENDOR_ID 0x091E
50 50
@@ -56,7 +56,7 @@ static int debug = 0;
56#define VERSION_MINOR 31 56#define VERSION_MINOR 31
57 57
58#define _STR(s) #s 58#define _STR(s) #s
59#define _DRIVER_VERSION(a,b) "v" _STR(a) "." _STR(b) 59#define _DRIVER_VERSION(a, b) "v" _STR(a) "." _STR(b)
60#define DRIVER_VERSION _DRIVER_VERSION(VERSION_MAJOR, VERSION_MINOR) 60#define DRIVER_VERSION _DRIVER_VERSION(VERSION_MAJOR, VERSION_MINOR)
61#define DRIVER_AUTHOR "hermann kneissel" 61#define DRIVER_AUTHOR "hermann kneissel"
62#define DRIVER_DESC "garmin gps driver" 62#define DRIVER_DESC "garmin gps driver"
@@ -65,37 +65,37 @@ static int debug = 0;
65#define EINVPKT 1000 /* invalid packet structure */ 65#define EINVPKT 1000 /* invalid packet structure */
66 66
67 67
68// size of the header of a packet using the usb protocol 68/* size of the header of a packet using the usb protocol */
69#define GARMIN_PKTHDR_LENGTH 12 69#define GARMIN_PKTHDR_LENGTH 12
70 70
71// max. possible size of a packet using the serial protocol 71/* max. possible size of a packet using the serial protocol */
72#define MAX_SERIAL_PKT_SIZ (3+255+3) 72#define MAX_SERIAL_PKT_SIZ (3 + 255 + 3)
73 73
74// max. possible size of a packet with worst case stuffing 74/* max. possible size of a packet with worst case stuffing */
75#define MAX_SERIAL_PKT_SIZ_STUFFED MAX_SERIAL_PKT_SIZ+256 75#define MAX_SERIAL_PKT_SIZ_STUFFED (MAX_SERIAL_PKT_SIZ + 256)
76 76
77// size of a buffer able to hold a complete (no stuffing) packet 77/* size of a buffer able to hold a complete (no stuffing) packet
78// (the document protocol does not contain packets with a larger 78 * (the document protocol does not contain packets with a larger
79// size, but in theory a packet may be 64k+12 bytes - if in 79 * size, but in theory a packet may be 64k+12 bytes - if in
80// later protocol versions larger packet sizes occur, this value 80 * later protocol versions larger packet sizes occur, this value
81// should be increased accordingly, so the input buffer is always 81 * should be increased accordingly, so the input buffer is always
82// large enough the store a complete packet inclusive header) 82 * large enough the store a complete packet inclusive header) */
83#define GPS_IN_BUFSIZ (GARMIN_PKTHDR_LENGTH+MAX_SERIAL_PKT_SIZ) 83#define GPS_IN_BUFSIZ (GARMIN_PKTHDR_LENGTH+MAX_SERIAL_PKT_SIZ)
84 84
85// size of a buffer able to hold a complete (incl. stuffing) packet 85/* size of a buffer able to hold a complete (incl. stuffing) packet */
86#define GPS_OUT_BUFSIZ (GARMIN_PKTHDR_LENGTH+MAX_SERIAL_PKT_SIZ_STUFFED) 86#define GPS_OUT_BUFSIZ (GARMIN_PKTHDR_LENGTH+MAX_SERIAL_PKT_SIZ_STUFFED)
87 87
88// where to place the packet id of a serial packet, so we can 88/* where to place the packet id of a serial packet, so we can
89// prepend the usb-packet header without the need to move the 89 * prepend the usb-packet header without the need to move the
90// packets data 90 * packets data */
91#define GSP_INITIAL_OFFSET (GARMIN_PKTHDR_LENGTH-2) 91#define GSP_INITIAL_OFFSET (GARMIN_PKTHDR_LENGTH-2)
92 92
93// max. size of incoming private packets (header+1 param) 93/* max. size of incoming private packets (header+1 param) */
94#define PRIVPKTSIZ (GARMIN_PKTHDR_LENGTH+4) 94#define PRIVPKTSIZ (GARMIN_PKTHDR_LENGTH+4)
95 95
96#define GARMIN_LAYERID_TRANSPORT 0 96#define GARMIN_LAYERID_TRANSPORT 0
97#define GARMIN_LAYERID_APPL 20 97#define GARMIN_LAYERID_APPL 20
98// our own layer-id to use for some control mechanisms 98/* our own layer-id to use for some control mechanisms */
99#define GARMIN_LAYERID_PRIVATE 0x01106E4B 99#define GARMIN_LAYERID_PRIVATE 0x01106E4B
100 100
101#define GARMIN_PKTID_PVT_DATA 51 101#define GARMIN_PKTID_PVT_DATA 51
@@ -103,7 +103,7 @@ static int debug = 0;
103 103
104#define CMND_ABORT_TRANSFER 0 104#define CMND_ABORT_TRANSFER 0
105 105
106// packet ids used in private layer 106/* packet ids used in private layer */
107#define PRIV_PKTID_SET_DEBUG 1 107#define PRIV_PKTID_SET_DEBUG 1
108#define PRIV_PKTID_SET_MODE 2 108#define PRIV_PKTID_SET_MODE 2
109#define PRIV_PKTID_INFO_REQ 3 109#define PRIV_PKTID_INFO_REQ 3
@@ -121,7 +121,8 @@ static int debug = 0;
121struct garmin_packet { 121struct garmin_packet {
122 struct list_head list; 122 struct list_head list;
123 int seq; 123 int seq;
124 int size; // the real size of the data array, always > 0 124 /* the real size of the data array, always > 0 */
125 int size;
125 __u8 data[1]; 126 __u8 data[1];
126}; 127};
127 128
@@ -164,7 +165,7 @@ struct garmin_data {
164#define MODE_NATIVE 0 165#define MODE_NATIVE 0
165#define MODE_GARMIN_SERIAL 1 166#define MODE_GARMIN_SERIAL 1
166 167
167// Flags used in garmin_data.flags: 168/* Flags used in garmin_data.flags: */
168#define FLAGS_SESSION_REPLY_MASK 0x00C0 169#define FLAGS_SESSION_REPLY_MASK 0x00C0
169#define FLAGS_SESSION_REPLY1_SEEN 0x0080 170#define FLAGS_SESSION_REPLY1_SEEN 0x0080
170#define FLAGS_SESSION_REPLY2_SEEN 0x0040 171#define FLAGS_SESSION_REPLY2_SEEN 0x0040
@@ -185,7 +186,7 @@ struct garmin_data {
185 186
186 187
187/* function prototypes */ 188/* function prototypes */
188static void gsp_next_packet(struct garmin_data * garmin_data_p); 189static void gsp_next_packet(struct garmin_data *garmin_data_p);
189static int garmin_write_bulk(struct usb_serial_port *port, 190static int garmin_write_bulk(struct usb_serial_port *port,
190 const unsigned char *buf, int count, 191 const unsigned char *buf, int count,
191 int dismiss_ack); 192 int dismiss_ack);
@@ -217,12 +218,13 @@ static unsigned char const PRIVATE_REQ[]
217 218
218 219
219static struct usb_device_id id_table [] = { 220static struct usb_device_id id_table [] = {
220 /* the same device id seems to be used by all usb enabled gps devices */ 221 /* the same device id seems to be used by all
221 { USB_DEVICE(GARMIN_VENDOR_ID, 3 ) }, 222 usb enabled GPS devices */
223 { USB_DEVICE(GARMIN_VENDOR_ID, 3) },
222 { } /* Terminating entry */ 224 { } /* Terminating entry */
223}; 225};
224 226
225MODULE_DEVICE_TABLE (usb, id_table); 227MODULE_DEVICE_TABLE(usb, id_table);
226 228
227static struct usb_driver garmin_driver = { 229static struct usb_driver garmin_driver = {
228 .name = "garmin_gps", 230 .name = "garmin_gps",
@@ -233,9 +235,10 @@ static struct usb_driver garmin_driver = {
233}; 235};
234 236
235 237
236static inline int noResponseFromAppLayer(struct garmin_data * garmin_data_p) 238static inline int noResponseFromAppLayer(struct garmin_data *garmin_data_p)
237{ 239{
238 return atomic_read(&garmin_data_p->req_count) == atomic_read(&garmin_data_p->resp_count); 240 return atomic_read(&garmin_data_p->req_count) ==
241 atomic_read(&garmin_data_p->resp_count);
239} 242}
240 243
241 244
@@ -261,10 +264,10 @@ static inline int getDataLength(const __u8 *usbPacket)
261 */ 264 */
262static inline int isAbortTrfCmnd(const unsigned char *buf) 265static inline int isAbortTrfCmnd(const unsigned char *buf)
263{ 266{
264 if (0 == memcmp(buf, GARMIN_STOP_TRANSFER_REQ, 267 if (0 == memcmp(buf, GARMIN_STOP_TRANSFER_REQ,
265 sizeof(GARMIN_STOP_TRANSFER_REQ)) || 268 sizeof(GARMIN_STOP_TRANSFER_REQ)) ||
266 0 == memcmp(buf, GARMIN_STOP_TRANSFER_REQ_V2, 269 0 == memcmp(buf, GARMIN_STOP_TRANSFER_REQ_V2,
267 sizeof(GARMIN_STOP_TRANSFER_REQ_V2))) 270 sizeof(GARMIN_STOP_TRANSFER_REQ_V2)))
268 return 1; 271 return 1;
269 else 272 else
270 return 0; 273 return 0;
@@ -275,11 +278,11 @@ static inline int isAbortTrfCmnd(const unsigned char *buf)
275static void send_to_tty(struct usb_serial_port *port, 278static void send_to_tty(struct usb_serial_port *port,
276 char *data, unsigned int actual_length) 279 char *data, unsigned int actual_length)
277{ 280{
278 struct tty_struct *tty = port->tty; 281 struct tty_struct *tty = port->port.tty;
279 282
280 if (tty && actual_length) { 283 if (tty && actual_length) {
281 284
282 usb_serial_debug_data(debug, &port->dev, 285 usb_serial_debug_data(debug, &port->dev,
283 __func__, actual_length, data); 286 __func__, actual_length, data);
284 287
285 tty_buffer_request_room(tty, actual_length); 288 tty_buffer_request_room(tty, actual_length);
@@ -296,7 +299,7 @@ static void send_to_tty(struct usb_serial_port *port,
296/* 299/*
297 * queue a received (usb-)packet for later processing 300 * queue a received (usb-)packet for later processing
298 */ 301 */
299static int pkt_add(struct garmin_data * garmin_data_p, 302static int pkt_add(struct garmin_data *garmin_data_p,
300 unsigned char *data, unsigned int data_length) 303 unsigned char *data, unsigned int data_length)
301{ 304{
302 int state = 0; 305 int state = 0;
@@ -307,7 +310,7 @@ static int pkt_add(struct garmin_data * garmin_data_p,
307 /* process only packets containg data ... */ 310 /* process only packets containg data ... */
308 if (data_length) { 311 if (data_length) {
309 pkt = kmalloc(sizeof(struct garmin_packet)+data_length, 312 pkt = kmalloc(sizeof(struct garmin_packet)+data_length,
310 GFP_ATOMIC); 313 GFP_ATOMIC);
311 if (pkt == NULL) { 314 if (pkt == NULL) {
312 dev_err(&garmin_data_p->port->dev, "out of memory\n"); 315 dev_err(&garmin_data_p->port->dev, "out of memory\n");
313 return 0; 316 return 0;
@@ -325,16 +328,15 @@ static int pkt_add(struct garmin_data * garmin_data_p,
325 328
326 /* in serial mode, if someone is waiting for data from 329 /* in serial mode, if someone is waiting for data from
327 the device, iconvert and send the next packet to tty. */ 330 the device, iconvert and send the next packet to tty. */
328 if (result && (state == STATE_GSP_WAIT_DATA)) { 331 if (result && (state == STATE_GSP_WAIT_DATA))
329 gsp_next_packet(garmin_data_p); 332 gsp_next_packet(garmin_data_p);
330 }
331 } 333 }
332 return result; 334 return result;
333} 335}
334 336
335 337
336/* get the next pending packet */ 338/* get the next pending packet */
337static struct garmin_packet *pkt_pop(struct garmin_data * garmin_data_p) 339static struct garmin_packet *pkt_pop(struct garmin_data *garmin_data_p)
338{ 340{
339 unsigned long flags; 341 unsigned long flags;
340 struct garmin_packet *result = NULL; 342 struct garmin_packet *result = NULL;
@@ -350,7 +352,7 @@ static struct garmin_packet *pkt_pop(struct garmin_data * garmin_data_p)
350 352
351 353
352/* free up all queued data */ 354/* free up all queued data */
353static void pkt_clear(struct garmin_data * garmin_data_p) 355static void pkt_clear(struct garmin_data *garmin_data_p)
354{ 356{
355 unsigned long flags; 357 unsigned long flags;
356 struct garmin_packet *result = NULL; 358 struct garmin_packet *result = NULL;
@@ -372,7 +374,7 @@ static void pkt_clear(struct garmin_data * garmin_data_p)
372 ******************************************************************************/ 374 ******************************************************************************/
373 375
374/* send an ack packet back to the tty */ 376/* send an ack packet back to the tty */
375static int gsp_send_ack(struct garmin_data * garmin_data_p, __u8 pkt_id) 377static int gsp_send_ack(struct garmin_data *garmin_data_p, __u8 pkt_id)
376{ 378{
377 __u8 pkt[10]; 379 __u8 pkt[10];
378 __u8 cksum = 0; 380 __u8 cksum = 0;
@@ -391,9 +393,8 @@ static int gsp_send_ack(struct garmin_data * garmin_data_p, __u8 pkt_id)
391 *ptr++ = pkt_id; 393 *ptr++ = pkt_id;
392 cksum += pkt_id; 394 cksum += pkt_id;
393 395
394 if (pkt_id == DLE) { 396 if (pkt_id == DLE)
395 *ptr++ = DLE; 397 *ptr++ = DLE;
396 }
397 398
398 *ptr++ = 0; 399 *ptr++ = 0;
399 *ptr++ = 0xFF & (-cksum); 400 *ptr++ = 0xFF & (-cksum);
@@ -415,12 +416,12 @@ static int gsp_send_ack(struct garmin_data * garmin_data_p, __u8 pkt_id)
415 * at GSP_INITIAL_OFFSET. 416 * at GSP_INITIAL_OFFSET.
416 * 417 *
417 * count - number of bytes in the input buffer including space reserved for 418 * count - number of bytes in the input buffer including space reserved for
418 * the usb header: GSP_INITIAL_OFFSET + number of bytes in packet 419 * the usb header: GSP_INITIAL_OFFSET + number of bytes in packet
419 * (including pkt-id, data-length a. cksum) 420 * (including pkt-id, data-length a. cksum)
420 */ 421 */
421static int gsp_rec_packet(struct garmin_data * garmin_data_p, int count) 422static int gsp_rec_packet(struct garmin_data *garmin_data_p, int count)
422{ 423{
423 const __u8* recpkt = garmin_data_p->inbuffer+GSP_INITIAL_OFFSET; 424 const __u8 *recpkt = garmin_data_p->inbuffer+GSP_INITIAL_OFFSET;
424 __le32 *usbdata = (__le32 *) garmin_data_p->inbuffer; 425 __le32 *usbdata = (__le32 *) garmin_data_p->inbuffer;
425 426
426 int cksum = 0; 427 int cksum = 0;
@@ -440,8 +441,8 @@ static int gsp_rec_packet(struct garmin_data * garmin_data_p, int count)
440 cksum += *recpkt++; 441 cksum += *recpkt++;
441 cksum += *recpkt++; 442 cksum += *recpkt++;
442 443
443 // sanity check, remove after test ... 444 /* sanity check, remove after test ... */
444 if ((__u8*)&(usbdata[3]) != recpkt) { 445 if ((__u8 *)&(usbdata[3]) != recpkt) {
445 dbg("%s - ptr mismatch %p - %p", 446 dbg("%s - ptr mismatch %p - %p",
446 __func__, &(usbdata[4]), recpkt); 447 __func__, &(usbdata[4]), recpkt);
447 return -EINVPKT; 448 return -EINVPKT;
@@ -462,7 +463,7 @@ static int gsp_rec_packet(struct garmin_data * garmin_data_p, int count)
462 usbdata[1] = __cpu_to_le32(pktid); 463 usbdata[1] = __cpu_to_le32(pktid);
463 usbdata[2] = __cpu_to_le32(size); 464 usbdata[2] = __cpu_to_le32(size);
464 465
465 garmin_write_bulk (garmin_data_p->port, garmin_data_p->inbuffer, 466 garmin_write_bulk(garmin_data_p->port, garmin_data_p->inbuffer,
466 GARMIN_PKTHDR_LENGTH+size, 0); 467 GARMIN_PKTHDR_LENGTH+size, 0);
467 468
468 /* if this was an abort-transfer command, flush all 469 /* if this was an abort-transfer command, flush all
@@ -495,7 +496,7 @@ static int gsp_rec_packet(struct garmin_data * garmin_data_p, int count)
495 * if the input is an abort command, drop all queued data. 496 * if the input is an abort command, drop all queued data.
496 */ 497 */
497 498
498static int gsp_receive(struct garmin_data * garmin_data_p, 499static int gsp_receive(struct garmin_data *garmin_data_p,
499 const unsigned char *buf, int count) 500 const unsigned char *buf, int count)
500{ 501{
501 unsigned long flags; 502 unsigned long flags;
@@ -504,10 +505,11 @@ static int gsp_receive(struct garmin_data * garmin_data_p,
504 int i = 0; 505 int i = 0;
505 __u8 *dest; 506 __u8 *dest;
506 int size; 507 int size;
507 // dleSeen: set if last byte read was a DLE 508 /* dleSeen: set if last byte read was a DLE */
508 int dleSeen; 509 int dleSeen;
509 // skip: if set, skip incoming data until possible start of 510 /* skip: if set, skip incoming data until possible start of
510 // new packet 511 * new packet
512 */
511 int skip; 513 int skip;
512 __u8 data; 514 __u8 data;
513 515
@@ -521,14 +523,13 @@ static int gsp_receive(struct garmin_data * garmin_data_p,
521 dbg("%s - dle=%d skip=%d size=%d count=%d", 523 dbg("%s - dle=%d skip=%d size=%d count=%d",
522 __func__, dleSeen, skip, size, count); 524 __func__, dleSeen, skip, size, count);
523 525
524 if (size == 0) { 526 if (size == 0)
525 size = GSP_INITIAL_OFFSET; 527 size = GSP_INITIAL_OFFSET;
526 }
527 528
528 while (offs < count) { 529 while (offs < count) {
529 530
530 data = *(buf+offs); 531 data = *(buf+offs);
531 offs ++; 532 offs++;
532 533
533 if (data == DLE) { 534 if (data == DLE) {
534 if (skip) { /* start of a new pkt */ 535 if (skip) { /* start of a new pkt */
@@ -554,9 +555,8 @@ static int gsp_receive(struct garmin_data * garmin_data_p,
554 ack_or_nak_seen = NAK; 555 ack_or_nak_seen = NAK;
555 dbg("NAK packet complete."); 556 dbg("NAK packet complete.");
556 } else { 557 } else {
557 dbg("packet complete " 558 dbg("packet complete - id=0x%X.",
558 "- id=0x%X.", 559 0xFF & data);
559 0xFF & data);
560 gsp_rec_packet(garmin_data_p, size); 560 gsp_rec_packet(garmin_data_p, size);
561 } 561 }
562 562
@@ -589,7 +589,7 @@ static int gsp_receive(struct garmin_data * garmin_data_p,
589 589
590 garmin_data_p->insize = size; 590 garmin_data_p->insize = size;
591 591
592 // copy flags back to structure 592 /* copy flags back to structure */
593 if (skip) 593 if (skip)
594 garmin_data_p->flags |= FLAGS_GSP_SKIP; 594 garmin_data_p->flags |= FLAGS_GSP_SKIP;
595 else 595 else
@@ -600,16 +600,13 @@ static int gsp_receive(struct garmin_data * garmin_data_p,
600 else 600 else
601 garmin_data_p->flags &= ~FLAGS_GSP_DLESEEN; 601 garmin_data_p->flags &= ~FLAGS_GSP_DLESEEN;
602 602
603 if (ack_or_nak_seen) { 603 if (ack_or_nak_seen)
604 garmin_data_p->state = STATE_GSP_WAIT_DATA; 604 garmin_data_p->state = STATE_GSP_WAIT_DATA;
605 }
606 605
607 spin_unlock_irqrestore(&garmin_data_p->lock, flags); 606 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
608 607
609 if (ack_or_nak_seen) { 608 if (ack_or_nak_seen)
610 gsp_next_packet(garmin_data_p); 609 gsp_next_packet(garmin_data_p);
611 }
612
613 return count; 610 return count;
614} 611}
615 612
@@ -623,7 +620,7 @@ static int gsp_receive(struct garmin_data * garmin_data_p,
623 * 620 *
624 * return <0 on error, 0 if packet is incomplete or > 0 if packet was sent 621 * return <0 on error, 0 if packet is incomplete or > 0 if packet was sent
625 */ 622 */
626static int gsp_send(struct garmin_data * garmin_data_p, 623static int gsp_send(struct garmin_data *garmin_data_p,
627 const unsigned char *buf, int count) 624 const unsigned char *buf, int count)
628{ 625{
629 const unsigned char *src; 626 const unsigned char *src;
@@ -631,11 +628,11 @@ static int gsp_send(struct garmin_data * garmin_data_p,
631 int pktid = 0; 628 int pktid = 0;
632 int datalen = 0; 629 int datalen = 0;
633 int cksum = 0; 630 int cksum = 0;
634 int i=0; 631 int i = 0;
635 int k; 632 int k;
636 633
637 dbg("%s - state %d - %d bytes.", __func__, 634 dbg("%s - state %d - %d bytes.", __func__,
638 garmin_data_p->state, count); 635 garmin_data_p->state, count);
639 636
640 k = garmin_data_p->outsize; 637 k = garmin_data_p->outsize;
641 if ((k+count) > GPS_OUT_BUFSIZ) { 638 if ((k+count) > GPS_OUT_BUFSIZ) {
@@ -650,7 +647,7 @@ static int gsp_send(struct garmin_data * garmin_data_p,
650 647
651 if (k >= GARMIN_PKTHDR_LENGTH) { 648 if (k >= GARMIN_PKTHDR_LENGTH) {
652 pktid = getPacketId(garmin_data_p->outbuffer); 649 pktid = getPacketId(garmin_data_p->outbuffer);
653 datalen= getDataLength(garmin_data_p->outbuffer); 650 datalen = getDataLength(garmin_data_p->outbuffer);
654 i = GARMIN_PKTHDR_LENGTH + datalen; 651 i = GARMIN_PKTHDR_LENGTH + datalen;
655 if (k < i) 652 if (k < i)
656 return 0; 653 return 0;
@@ -658,19 +655,18 @@ static int gsp_send(struct garmin_data * garmin_data_p,
658 return 0; 655 return 0;
659 } 656 }
660 657
661 dbg("%s - %d bytes in buffer, %d bytes in pkt.", __func__, 658 dbg("%s - %d bytes in buffer, %d bytes in pkt.", __func__, k, i);
662 k, i);
663 659
664 /* garmin_data_p->outbuffer now contains a complete packet */ 660 /* garmin_data_p->outbuffer now contains a complete packet */
665 661
666 usb_serial_debug_data(debug, &garmin_data_p->port->dev, 662 usb_serial_debug_data(debug, &garmin_data_p->port->dev,
667 __func__, k, garmin_data_p->outbuffer); 663 __func__, k, garmin_data_p->outbuffer);
668 664
669 garmin_data_p->outsize = 0; 665 garmin_data_p->outsize = 0;
670 666
671 if (GARMIN_LAYERID_APPL != getLayerId(garmin_data_p->outbuffer)) { 667 if (GARMIN_LAYERID_APPL != getLayerId(garmin_data_p->outbuffer)) {
672 dbg("not an application packet (%d)", 668 dbg("not an application packet (%d)",
673 getLayerId(garmin_data_p->outbuffer)); 669 getLayerId(garmin_data_p->outbuffer));
674 return -1; 670 return -1;
675 } 671 }
676 672
@@ -688,14 +684,14 @@ static int gsp_send(struct garmin_data * garmin_data_p,
688 684
689 k = 0; 685 k = 0;
690 src = garmin_data_p->outbuffer+GARMIN_PKTHDR_LENGTH; 686 src = garmin_data_p->outbuffer+GARMIN_PKTHDR_LENGTH;
691 for (i=0; i<datalen; i++) { 687 for (i = 0; i < datalen; i++) {
692 if (*src++ == DLE) 688 if (*src++ == DLE)
693 k++; 689 k++;
694 } 690 }
695 691
696 src = garmin_data_p->outbuffer+GARMIN_PKTHDR_LENGTH; 692 src = garmin_data_p->outbuffer+GARMIN_PKTHDR_LENGTH;
697 if (k > (GARMIN_PKTHDR_LENGTH-2)) { 693 if (k > (GARMIN_PKTHDR_LENGTH-2)) {
698 /* can't add stuffing DLEs in place, move data to end 694 /* can't add stuffing DLEs in place, move data to end
699 of buffer ... */ 695 of buffer ... */
700 dst = garmin_data_p->outbuffer+GPS_OUT_BUFSIZ-datalen; 696 dst = garmin_data_p->outbuffer+GPS_OUT_BUFSIZ-datalen;
701 memcpy(dst, src, datalen); 697 memcpy(dst, src, datalen);
@@ -712,14 +708,14 @@ static int gsp_send(struct garmin_data * garmin_data_p,
712 if (datalen == DLE) 708 if (datalen == DLE)
713 *dst++ = DLE; 709 *dst++ = DLE;
714 710
715 for (i=0; i<datalen; i++) { 711 for (i = 0; i < datalen; i++) {
716 __u8 c = *src++; 712 __u8 c = *src++;
717 *dst++ = c; 713 *dst++ = c;
718 cksum += c; 714 cksum += c;
719 if (c == DLE) 715 if (c == DLE)
720 *dst++ = DLE; 716 *dst++ = DLE;
721 } 717 }
722 718
723 cksum = 0xFF & -cksum; 719 cksum = 0xFF & -cksum;
724 *dst++ = cksum; 720 *dst++ = cksum;
725 if (cksum == DLE) 721 if (cksum == DLE)
@@ -744,7 +740,7 @@ static int gsp_send(struct garmin_data * garmin_data_p,
744/* 740/*
745 * Process the next pending data packet - if there is one 741 * Process the next pending data packet - if there is one
746 */ 742 */
747static void gsp_next_packet(struct garmin_data * garmin_data_p) 743static void gsp_next_packet(struct garmin_data *garmin_data_p)
748{ 744{
749 struct garmin_packet *pkt = NULL; 745 struct garmin_packet *pkt = NULL;
750 746
@@ -774,17 +770,17 @@ static void gsp_next_packet(struct garmin_data * garmin_data_p)
774 * buf contains the data read, it may span more than one packet 770 * buf contains the data read, it may span more than one packet
775 * or even incomplete packets 771 * or even incomplete packets
776 */ 772 */
777static int nat_receive(struct garmin_data * garmin_data_p, 773static int nat_receive(struct garmin_data *garmin_data_p,
778 const unsigned char *buf, int count) 774 const unsigned char *buf, int count)
779{ 775{
780 unsigned long flags; 776 unsigned long flags;
781 __u8 * dest; 777 __u8 *dest;
782 int offs = 0; 778 int offs = 0;
783 int result = count; 779 int result = count;
784 int len; 780 int len;
785 781
786 while (offs < count) { 782 while (offs < count) {
787 // if buffer contains header, copy rest of data 783 /* if buffer contains header, copy rest of data */
788 if (garmin_data_p->insize >= GARMIN_PKTHDR_LENGTH) 784 if (garmin_data_p->insize >= GARMIN_PKTHDR_LENGTH)
789 len = GARMIN_PKTHDR_LENGTH 785 len = GARMIN_PKTHDR_LENGTH
790 +getDataLength(garmin_data_p->inbuffer); 786 +getDataLength(garmin_data_p->inbuffer);
@@ -792,9 +788,9 @@ static int nat_receive(struct garmin_data * garmin_data_p,
792 len = GARMIN_PKTHDR_LENGTH; 788 len = GARMIN_PKTHDR_LENGTH;
793 789
794 if (len >= GPS_IN_BUFSIZ) { 790 if (len >= GPS_IN_BUFSIZ) {
795 /* seem to be an invalid packet, ignore rest of input */ 791 /* seems to be an invalid packet, ignore rest
796 dbg("%s - packet size too large: %d", 792 of input */
797 __func__, len); 793 dbg("%s - packet size too large: %d", __func__, len);
798 garmin_data_p->insize = 0; 794 garmin_data_p->insize = 0;
799 count = 0; 795 count = 0;
800 result = -EINVPKT; 796 result = -EINVPKT;
@@ -804,7 +800,7 @@ static int nat_receive(struct garmin_data * garmin_data_p,
804 len = (count-offs); 800 len = (count-offs);
805 if (len > 0) { 801 if (len > 0) {
806 dest = garmin_data_p->inbuffer 802 dest = garmin_data_p->inbuffer
807 +garmin_data_p->insize; 803 + garmin_data_p->insize;
808 memcpy(dest, buf+offs, len); 804 memcpy(dest, buf+offs, len);
809 garmin_data_p->insize += len; 805 garmin_data_p->insize += len;
810 offs += len; 806 offs += len;
@@ -816,17 +812,19 @@ static int nat_receive(struct garmin_data * garmin_data_p,
816 len = GARMIN_PKTHDR_LENGTH+ 812 len = GARMIN_PKTHDR_LENGTH+
817 getDataLength(garmin_data_p->inbuffer); 813 getDataLength(garmin_data_p->inbuffer);
818 if (garmin_data_p->insize >= len) { 814 if (garmin_data_p->insize >= len) {
819 garmin_write_bulk (garmin_data_p->port, 815 garmin_write_bulk(garmin_data_p->port,
820 garmin_data_p->inbuffer, 816 garmin_data_p->inbuffer,
821 len, 0); 817 len, 0);
822 garmin_data_p->insize = 0; 818 garmin_data_p->insize = 0;
823 819
824 /* if this was an abort-transfer command, 820 /* if this was an abort-transfer command,
825 flush all queued data. */ 821 flush all queued data. */
826 if (isAbortTrfCmnd(garmin_data_p->inbuffer)) { 822 if (isAbortTrfCmnd(garmin_data_p->inbuffer)) {
827 spin_lock_irqsave(&garmin_data_p->lock, flags); 823 spin_lock_irqsave(&garmin_data_p->lock,
824 flags);
828 garmin_data_p->flags |= FLAGS_DROP_DATA; 825 garmin_data_p->flags |= FLAGS_DROP_DATA;
829 spin_unlock_irqrestore(&garmin_data_p->lock, flags); 826 spin_unlock_irqrestore(
827 &garmin_data_p->lock, flags);
830 pkt_clear(garmin_data_p); 828 pkt_clear(garmin_data_p);
831 } 829 }
832 } 830 }
@@ -842,7 +840,7 @@ static int nat_receive(struct garmin_data * garmin_data_p,
842 840
843static void priv_status_resp(struct usb_serial_port *port) 841static void priv_status_resp(struct usb_serial_port *port)
844{ 842{
845 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 843 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
846 __le32 *pkt = (__le32 *)garmin_data_p->privpkt; 844 __le32 *pkt = (__le32 *)garmin_data_p->privpkt;
847 845
848 pkt[0] = __cpu_to_le32(GARMIN_LAYERID_PRIVATE); 846 pkt[0] = __cpu_to_le32(GARMIN_LAYERID_PRIVATE);
@@ -852,7 +850,7 @@ static void priv_status_resp(struct usb_serial_port *port)
852 pkt[4] = __cpu_to_le32(garmin_data_p->mode); 850 pkt[4] = __cpu_to_le32(garmin_data_p->mode);
853 pkt[5] = __cpu_to_le32(garmin_data_p->serial_num); 851 pkt[5] = __cpu_to_le32(garmin_data_p->serial_num);
854 852
855 send_to_tty(port, (__u8*)pkt, 6*4); 853 send_to_tty(port, (__u8 *)pkt, 6 * 4);
856} 854}
857 855
858 856
@@ -864,7 +862,7 @@ static int process_resetdev_request(struct usb_serial_port *port)
864{ 862{
865 unsigned long flags; 863 unsigned long flags;
866 int status; 864 int status;
867 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 865 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
868 866
869 spin_lock_irqsave(&garmin_data_p->lock, flags); 867 spin_lock_irqsave(&garmin_data_p->lock, flags);
870 garmin_data_p->flags &= ~(CLEAR_HALT_REQUIRED); 868 garmin_data_p->flags &= ~(CLEAR_HALT_REQUIRED);
@@ -872,8 +870,8 @@ static int process_resetdev_request(struct usb_serial_port *port)
872 garmin_data_p->serial_num = 0; 870 garmin_data_p->serial_num = 0;
873 spin_unlock_irqrestore(&garmin_data_p->lock, flags); 871 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
874 872
875 usb_kill_urb (port->interrupt_in_urb); 873 usb_kill_urb(port->interrupt_in_urb);
876 dbg("%s - usb_reset_device", __func__ ); 874 dbg("%s - usb_reset_device", __func__);
877 status = usb_reset_device(port->serial->dev); 875 status = usb_reset_device(port->serial->dev);
878 if (status) 876 if (status)
879 dbg("%s - usb_reset_device failed: %d", 877 dbg("%s - usb_reset_device failed: %d",
@@ -886,7 +884,7 @@ static int process_resetdev_request(struct usb_serial_port *port)
886/* 884/*
887 * clear all cached data 885 * clear all cached data
888 */ 886 */
889static int garmin_clear(struct garmin_data * garmin_data_p) 887static int garmin_clear(struct garmin_data *garmin_data_p)
890{ 888{
891 unsigned long flags; 889 unsigned long flags;
892 int status = 0; 890 int status = 0;
@@ -896,8 +894,7 @@ static int garmin_clear(struct garmin_data * garmin_data_p)
896 if (port != NULL && atomic_read(&garmin_data_p->resp_count)) { 894 if (port != NULL && atomic_read(&garmin_data_p->resp_count)) {
897 /* send a terminate command */ 895 /* send a terminate command */
898 status = garmin_write_bulk(port, GARMIN_STOP_TRANSFER_REQ, 896 status = garmin_write_bulk(port, GARMIN_STOP_TRANSFER_REQ,
899 sizeof(GARMIN_STOP_TRANSFER_REQ), 897 sizeof(GARMIN_STOP_TRANSFER_REQ), 1);
900 1);
901 } 898 }
902 899
903 /* flush all queued data */ 900 /* flush all queued data */
@@ -920,28 +917,26 @@ static int garmin_init_session(struct usb_serial_port *port)
920{ 917{
921 unsigned long flags; 918 unsigned long flags;
922 struct usb_serial *serial = port->serial; 919 struct usb_serial *serial = port->serial;
923 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 920 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
924 int status = 0; 921 int status = 0;
925 922
926 if (status == 0) { 923 if (status == 0) {
927 usb_kill_urb (port->interrupt_in_urb); 924 usb_kill_urb(port->interrupt_in_urb);
928 925
929 dbg("%s - adding interrupt input", __func__); 926 dbg("%s - adding interrupt input", __func__);
930 port->interrupt_in_urb->dev = serial->dev; 927 port->interrupt_in_urb->dev = serial->dev;
931 status = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 928 status = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
932 if (status) 929 if (status)
933 dev_err(&serial->dev->dev, 930 dev_err(&serial->dev->dev,
934 "%s - failed submitting interrupt urb," 931 "%s - failed submitting interrupt urb, error %d\n",
935 " error %d\n", 932 __func__, status);
936 __func__, status);
937 } 933 }
938 934
939 if (status == 0) { 935 if (status == 0) {
940 dbg("%s - starting session ...", __func__); 936 dbg("%s - starting session ...", __func__);
941 garmin_data_p->state = STATE_ACTIVE; 937 garmin_data_p->state = STATE_ACTIVE;
942 status = garmin_write_bulk(port, GARMIN_START_SESSION_REQ, 938 status = garmin_write_bulk(port, GARMIN_START_SESSION_REQ,
943 sizeof(GARMIN_START_SESSION_REQ), 939 sizeof(GARMIN_START_SESSION_REQ), 0);
944 0);
945 940
946 if (status >= 0) { 941 if (status >= 0) {
947 942
@@ -951,14 +946,14 @@ static int garmin_init_session(struct usb_serial_port *port)
951 946
952 /* not needed, but the win32 driver does it too ... */ 947 /* not needed, but the win32 driver does it too ... */
953 status = garmin_write_bulk(port, 948 status = garmin_write_bulk(port,
954 GARMIN_START_SESSION_REQ2, 949 GARMIN_START_SESSION_REQ2,
955 sizeof(GARMIN_START_SESSION_REQ2), 950 sizeof(GARMIN_START_SESSION_REQ2), 0);
956 0);
957 if (status >= 0) { 951 if (status >= 0) {
958 status = 0; 952 status = 0;
959 spin_lock_irqsave(&garmin_data_p->lock, flags); 953 spin_lock_irqsave(&garmin_data_p->lock, flags);
960 garmin_data_p->ignorePkts++; 954 garmin_data_p->ignorePkts++;
961 spin_unlock_irqrestore(&garmin_data_p->lock, flags); 955 spin_unlock_irqrestore(&garmin_data_p->lock,
956 flags);
962 } 957 }
963 } 958 }
964 } 959 }
@@ -970,11 +965,12 @@ static int garmin_init_session(struct usb_serial_port *port)
970 965
971 966
972 967
973static int garmin_open (struct usb_serial_port *port, struct file *filp) 968static int garmin_open(struct tty_struct *tty,
969 struct usb_serial_port *port, struct file *filp)
974{ 970{
975 unsigned long flags; 971 unsigned long flags;
976 int status = 0; 972 int status = 0;
977 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 973 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
978 974
979 dbg("%s - port %d", __func__, port->number); 975 dbg("%s - port %d", __func__, port->number);
980 976
@@ -983,8 +979,8 @@ static int garmin_open (struct usb_serial_port *port, struct file *filp)
983 * through, otherwise it is scheduled, and with high data rates (like 979 * through, otherwise it is scheduled, and with high data rates (like
984 * with OHCI) data can get lost. 980 * with OHCI) data can get lost.
985 */ 981 */
986 if (port->tty) 982 if (tty)
987 port->tty->low_latency = 1; 983 tty->low_latency = 1;
988 984
989 spin_lock_irqsave(&garmin_data_p->lock, flags); 985 spin_lock_irqsave(&garmin_data_p->lock, flags);
990 garmin_data_p->mode = initial_mode; 986 garmin_data_p->mode = initial_mode;
@@ -995,23 +991,22 @@ static int garmin_open (struct usb_serial_port *port, struct file *filp)
995 spin_unlock_irqrestore(&garmin_data_p->lock, flags); 991 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
996 992
997 /* shutdown any bulk reads that might be going on */ 993 /* shutdown any bulk reads that might be going on */
998 usb_kill_urb (port->write_urb); 994 usb_kill_urb(port->write_urb);
999 usb_kill_urb (port->read_urb); 995 usb_kill_urb(port->read_urb);
1000 996
1001 if (garmin_data_p->state == STATE_RESET) { 997 if (garmin_data_p->state == STATE_RESET)
1002 status = garmin_init_session(port); 998 status = garmin_init_session(port);
1003 }
1004 999
1005 garmin_data_p->state = STATE_ACTIVE; 1000 garmin_data_p->state = STATE_ACTIVE;
1006
1007 return status; 1001 return status;
1008} 1002}
1009 1003
1010 1004
1011static void garmin_close (struct usb_serial_port *port, struct file * filp) 1005static void garmin_close(struct tty_struct *tty,
1006 struct usb_serial_port *port, struct file *filp)
1012{ 1007{
1013 struct usb_serial *serial = port->serial; 1008 struct usb_serial *serial = port->serial;
1014 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 1009 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1015 1010
1016 dbg("%s - port %d - mode=%d state=%d flags=0x%X", __func__, 1011 dbg("%s - port %d - mode=%d state=%d flags=0x%X", __func__,
1017 port->number, garmin_data_p->mode, 1012 port->number, garmin_data_p->mode,
@@ -1025,8 +1020,8 @@ static void garmin_close (struct usb_serial_port *port, struct file * filp)
1025 garmin_clear(garmin_data_p); 1020 garmin_clear(garmin_data_p);
1026 1021
1027 /* shutdown our urbs */ 1022 /* shutdown our urbs */
1028 usb_kill_urb (port->read_urb); 1023 usb_kill_urb(port->read_urb);
1029 usb_kill_urb (port->write_urb); 1024 usb_kill_urb(port->write_urb);
1030 1025
1031 if (!port->serial->disconnected) { 1026 if (!port->serial->disconnected) {
1032 if (noResponseFromAppLayer(garmin_data_p) || 1027 if (noResponseFromAppLayer(garmin_data_p) ||
@@ -1042,21 +1037,22 @@ static void garmin_close (struct usb_serial_port *port, struct file * filp)
1042 mutex_unlock(&port->serial->disc_mutex); 1037 mutex_unlock(&port->serial->disc_mutex);
1043} 1038}
1044 1039
1045 1040static void garmin_write_bulk_callback(struct urb *urb)
1046static void garmin_write_bulk_callback (struct urb *urb)
1047{ 1041{
1048 unsigned long flags; 1042 unsigned long flags;
1049 struct usb_serial_port *port = urb->context; 1043 struct usb_serial_port *port = urb->context;
1050 int status = urb->status; 1044 int status = urb->status;
1051 1045
1052 if (port) { 1046 if (port) {
1053 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 1047 struct garmin_data *garmin_data_p =
1048 usb_get_serial_port_data(port);
1054 1049
1055 dbg("%s - port %d", __func__, port->number); 1050 dbg("%s - port %d", __func__, port->number);
1056 1051
1057 if (GARMIN_LAYERID_APPL == getLayerId(urb->transfer_buffer) 1052 if (GARMIN_LAYERID_APPL == getLayerId(urb->transfer_buffer)
1058 && (garmin_data_p->mode == MODE_GARMIN_SERIAL)) { 1053 && (garmin_data_p->mode == MODE_GARMIN_SERIAL)) {
1059 gsp_send_ack(garmin_data_p, ((__u8 *)urb->transfer_buffer)[4]); 1054 gsp_send_ack(garmin_data_p,
1055 ((__u8 *)urb->transfer_buffer)[4]);
1060 } 1056 }
1061 1057
1062 if (status) { 1058 if (status) {
@@ -1070,20 +1066,21 @@ static void garmin_write_bulk_callback (struct urb *urb)
1070 usb_serial_port_softint(port); 1066 usb_serial_port_softint(port);
1071 } 1067 }
1072 1068
1073 /* Ignore errors that resulted from garmin_write_bulk with dismiss_ack=1 */ 1069 /* Ignore errors that resulted from garmin_write_bulk with
1070 dismiss_ack = 1 */
1074 1071
1075 /* free up the transfer buffer, as usb_free_urb() does not do this */ 1072 /* free up the transfer buffer, as usb_free_urb() does not do this */
1076 kfree (urb->transfer_buffer); 1073 kfree(urb->transfer_buffer);
1077} 1074}
1078 1075
1079 1076
1080static int garmin_write_bulk (struct usb_serial_port *port, 1077static int garmin_write_bulk(struct usb_serial_port *port,
1081 const unsigned char *buf, int count, 1078 const unsigned char *buf, int count,
1082 int dismiss_ack) 1079 int dismiss_ack)
1083{ 1080{
1084 unsigned long flags; 1081 unsigned long flags;
1085 struct usb_serial *serial = port->serial; 1082 struct usb_serial *serial = port->serial;
1086 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 1083 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1087 struct urb *urb; 1084 struct urb *urb;
1088 unsigned char *buffer; 1085 unsigned char *buffer;
1089 int status; 1086 int status;
@@ -1095,7 +1092,7 @@ static int garmin_write_bulk (struct usb_serial_port *port,
1095 garmin_data_p->flags &= ~FLAGS_DROP_DATA; 1092 garmin_data_p->flags &= ~FLAGS_DROP_DATA;
1096 spin_unlock_irqrestore(&garmin_data_p->lock, flags); 1093 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1097 1094
1098 buffer = kmalloc (count, GFP_ATOMIC); 1095 buffer = kmalloc(count, GFP_ATOMIC);
1099 if (!buffer) { 1096 if (!buffer) {
1100 dev_err(&port->dev, "out of memory\n"); 1097 dev_err(&port->dev, "out of memory\n");
1101 return -ENOMEM; 1098 return -ENOMEM;
@@ -1104,17 +1101,17 @@ static int garmin_write_bulk (struct usb_serial_port *port,
1104 urb = usb_alloc_urb(0, GFP_ATOMIC); 1101 urb = usb_alloc_urb(0, GFP_ATOMIC);
1105 if (!urb) { 1102 if (!urb) {
1106 dev_err(&port->dev, "no more free urbs\n"); 1103 dev_err(&port->dev, "no more free urbs\n");
1107 kfree (buffer); 1104 kfree(buffer);
1108 return -ENOMEM; 1105 return -ENOMEM;
1109 } 1106 }
1110 1107
1111 memcpy (buffer, buf, count); 1108 memcpy(buffer, buf, count);
1112 1109
1113 usb_serial_debug_data(debug, &port->dev, __func__, count, buffer); 1110 usb_serial_debug_data(debug, &port->dev, __func__, count, buffer);
1114 1111
1115 usb_fill_bulk_urb (urb, serial->dev, 1112 usb_fill_bulk_urb(urb, serial->dev,
1116 usb_sndbulkpipe (serial->dev, 1113 usb_sndbulkpipe(serial->dev,
1117 port->bulk_out_endpointAddress), 1114 port->bulk_out_endpointAddress),
1118 buffer, count, 1115 buffer, count,
1119 garmin_write_bulk_callback, 1116 garmin_write_bulk_callback,
1120 dismiss_ack ? NULL : port); 1117 dismiss_ack ? NULL : port);
@@ -1132,33 +1129,29 @@ static int garmin_write_bulk (struct usb_serial_port *port,
1132 status = usb_submit_urb(urb, GFP_ATOMIC); 1129 status = usb_submit_urb(urb, GFP_ATOMIC);
1133 if (status) { 1130 if (status) {
1134 dev_err(&port->dev, 1131 dev_err(&port->dev,
1135 "%s - usb_submit_urb(write bulk) " 1132 "%s - usb_submit_urb(write bulk) failed with status = %d\n",
1136 "failed with status = %d\n",
1137 __func__, status); 1133 __func__, status);
1138 count = status; 1134 count = status;
1139 } 1135 }
1140 1136
1141 /* we are done with this urb, so let the host driver 1137 /* we are done with this urb, so let the host driver
1142 * really free it when it is finished with it */ 1138 * really free it when it is finished with it */
1143 usb_free_urb (urb); 1139 usb_free_urb(urb);
1144 1140
1145 return count; 1141 return count;
1146} 1142}
1147 1143
1148 1144static int garmin_write(struct tty_struct *tty, struct usb_serial_port *port,
1149 1145 const unsigned char *buf, int count)
1150static int garmin_write (struct usb_serial_port *port,
1151 const unsigned char *buf, int count)
1152{ 1146{
1153 int pktid, pktsiz, len; 1147 int pktid, pktsiz, len;
1154 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 1148 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1155 __le32 *privpkt = (__le32 *)garmin_data_p->privpkt; 1149 __le32 *privpkt = (__le32 *)garmin_data_p->privpkt;
1156 1150
1157 usb_serial_debug_data(debug, &port->dev, __func__, count, buf); 1151 usb_serial_debug_data(debug, &port->dev, __func__, count, buf);
1158 1152
1159 /* check for our private packets */ 1153 /* check for our private packets */
1160 if (count >= GARMIN_PKTHDR_LENGTH) { 1154 if (count >= GARMIN_PKTHDR_LENGTH) {
1161
1162 len = PRIVPKTSIZ; 1155 len = PRIVPKTSIZ;
1163 if (count < len) 1156 if (count < len)
1164 len = count; 1157 len = count;
@@ -1169,15 +1162,16 @@ static int garmin_write (struct usb_serial_port *port,
1169 pktid = getPacketId(garmin_data_p->privpkt); 1162 pktid = getPacketId(garmin_data_p->privpkt);
1170 1163
1171 if (count == (GARMIN_PKTHDR_LENGTH+pktsiz) 1164 if (count == (GARMIN_PKTHDR_LENGTH+pktsiz)
1172 && GARMIN_LAYERID_PRIVATE == getLayerId(garmin_data_p->privpkt)) { 1165 && GARMIN_LAYERID_PRIVATE ==
1166 getLayerId(garmin_data_p->privpkt)) {
1173 1167
1174 dbg("%s - processing private request %d", 1168 dbg("%s - processing private request %d",
1175 __func__, pktid); 1169 __func__, pktid);
1176 1170
1177 // drop all unfinished transfers 1171 /* drop all unfinished transfers */
1178 garmin_clear(garmin_data_p); 1172 garmin_clear(garmin_data_p);
1179 1173
1180 switch(pktid) { 1174 switch (pktid) {
1181 1175
1182 case PRIV_PKTID_SET_DEBUG: 1176 case PRIV_PKTID_SET_DEBUG:
1183 if (pktsiz != 4) 1177 if (pktsiz != 4)
@@ -1226,44 +1220,31 @@ static int garmin_write (struct usb_serial_port *port,
1226} 1220}
1227 1221
1228 1222
1229static int garmin_write_room (struct usb_serial_port *port) 1223static int garmin_write_room(struct tty_struct *tty)
1230{ 1224{
1225 struct usb_serial_port *port = tty->driver_data;
1231 /* 1226 /*
1232 * Report back the bytes currently available in the output buffer. 1227 * Report back the bytes currently available in the output buffer.
1233 */ 1228 */
1234 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 1229 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1235 return GPS_OUT_BUFSIZ-garmin_data_p->outsize; 1230 return GPS_OUT_BUFSIZ-garmin_data_p->outsize;
1236} 1231}
1237 1232
1238 1233
1239static int garmin_chars_in_buffer (struct usb_serial_port *port) 1234static void garmin_read_process(struct garmin_data *garmin_data_p,
1240{
1241 /*
1242 * Report back the number of bytes currently in our input buffer.
1243 * Will this lock up the driver - the buffer contains an incomplete
1244 * package which will not be written to the device until it
1245 * has been completed ?
1246 */
1247 //struct garmin_data * garmin_data_p = usb_get_serial_port_data(port);
1248 //return garmin_data_p->insize;
1249 return 0;
1250}
1251
1252
1253static void garmin_read_process(struct garmin_data * garmin_data_p,
1254 unsigned char *data, unsigned data_length) 1235 unsigned char *data, unsigned data_length)
1255{ 1236{
1256 if (garmin_data_p->flags & FLAGS_DROP_DATA) { 1237 if (garmin_data_p->flags & FLAGS_DROP_DATA) {
1257 /* abort-transfer cmd is actice */ 1238 /* abort-transfer cmd is actice */
1258 dbg("%s - pkt dropped", __func__); 1239 dbg("%s - pkt dropped", __func__);
1259 } else if (garmin_data_p->state != STATE_DISCONNECTED && 1240 } else if (garmin_data_p->state != STATE_DISCONNECTED &&
1260 garmin_data_p->state != STATE_RESET ) { 1241 garmin_data_p->state != STATE_RESET) {
1261 1242
1262 /* remember any appl.layer packets, so we know 1243 /* remember any appl.layer packets, so we know
1263 if a reset is required or not when closing 1244 if a reset is required or not when closing
1264 the device */ 1245 the device */
1265 if (0 == memcmp(data, GARMIN_APP_LAYER_REPLY, 1246 if (0 == memcmp(data, GARMIN_APP_LAYER_REPLY,
1266 sizeof(GARMIN_APP_LAYER_REPLY))) { 1247 sizeof(GARMIN_APP_LAYER_REPLY))) {
1267 atomic_inc(&garmin_data_p->resp_count); 1248 atomic_inc(&garmin_data_p->resp_count);
1268 } 1249 }
1269 1250
@@ -1273,9 +1254,8 @@ static void garmin_read_process(struct garmin_data * garmin_data_p,
1273 if (garmin_data_p->flags & FLAGS_QUEUING) { 1254 if (garmin_data_p->flags & FLAGS_QUEUING) {
1274 pkt_add(garmin_data_p, data, data_length); 1255 pkt_add(garmin_data_p, data, data_length);
1275 } else if (garmin_data_p->mode == MODE_GARMIN_SERIAL) { 1256 } else if (garmin_data_p->mode == MODE_GARMIN_SERIAL) {
1276 if (getLayerId(data) == GARMIN_LAYERID_APPL) { 1257 if (getLayerId(data) == GARMIN_LAYERID_APPL)
1277 pkt_add(garmin_data_p, data, data_length); 1258 pkt_add(garmin_data_p, data, data_length);
1278 }
1279 } else { 1259 } else {
1280 send_to_tty(garmin_data_p->port, data, data_length); 1260 send_to_tty(garmin_data_p->port, data, data_length);
1281 } 1261 }
@@ -1283,12 +1263,12 @@ static void garmin_read_process(struct garmin_data * garmin_data_p,
1283} 1263}
1284 1264
1285 1265
1286static void garmin_read_bulk_callback (struct urb *urb) 1266static void garmin_read_bulk_callback(struct urb *urb)
1287{ 1267{
1288 unsigned long flags; 1268 unsigned long flags;
1289 struct usb_serial_port *port = urb->context; 1269 struct usb_serial_port *port = urb->context;
1290 struct usb_serial *serial = port->serial; 1270 struct usb_serial *serial = port->serial;
1291 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 1271 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1292 unsigned char *data = urb->transfer_buffer; 1272 unsigned char *data = urb->transfer_buffer;
1293 int status = urb->status; 1273 int status = urb->status;
1294 int retval; 1274 int retval;
@@ -1306,7 +1286,7 @@ static void garmin_read_bulk_callback (struct urb *urb)
1306 return; 1286 return;
1307 } 1287 }
1308 1288
1309 usb_serial_debug_data(debug, &port->dev, 1289 usb_serial_debug_data(debug, &port->dev,
1310 __func__, urb->actual_length, data); 1290 __func__, urb->actual_length, data);
1311 1291
1312 garmin_read_process(garmin_data_p, data, urb->actual_length); 1292 garmin_read_process(garmin_data_p, data, urb->actual_length);
@@ -1340,13 +1320,13 @@ static void garmin_read_bulk_callback (struct urb *urb)
1340} 1320}
1341 1321
1342 1322
1343static void garmin_read_int_callback (struct urb *urb) 1323static void garmin_read_int_callback(struct urb *urb)
1344{ 1324{
1345 unsigned long flags; 1325 unsigned long flags;
1346 int retval; 1326 int retval;
1347 struct usb_serial_port *port = urb->context; 1327 struct usb_serial_port *port = urb->context;
1348 struct usb_serial *serial = port->serial; 1328 struct usb_serial *serial = port->serial;
1349 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 1329 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1350 unsigned char *data = urb->transfer_buffer; 1330 unsigned char *data = urb->transfer_buffer;
1351 int status = urb->status; 1331 int status = urb->status;
1352 1332
@@ -1372,30 +1352,31 @@ static void garmin_read_int_callback (struct urb *urb)
1372 1352
1373 if (urb->actual_length == sizeof(GARMIN_BULK_IN_AVAIL_REPLY) && 1353 if (urb->actual_length == sizeof(GARMIN_BULK_IN_AVAIL_REPLY) &&
1374 0 == memcmp(data, GARMIN_BULK_IN_AVAIL_REPLY, 1354 0 == memcmp(data, GARMIN_BULK_IN_AVAIL_REPLY,
1375 sizeof(GARMIN_BULK_IN_AVAIL_REPLY))) { 1355 sizeof(GARMIN_BULK_IN_AVAIL_REPLY))) {
1376 1356
1377 dbg("%s - bulk data available.", __func__); 1357 dbg("%s - bulk data available.", __func__);
1378 1358
1379 if (0 == (garmin_data_p->flags & FLAGS_BULK_IN_ACTIVE)) { 1359 if (0 == (garmin_data_p->flags & FLAGS_BULK_IN_ACTIVE)) {
1380 1360
1381 /* bulk data available */ 1361 /* bulk data available */
1382 usb_fill_bulk_urb (port->read_urb, serial->dev, 1362 usb_fill_bulk_urb(port->read_urb, serial->dev,
1383 usb_rcvbulkpipe (serial->dev, 1363 usb_rcvbulkpipe(serial->dev,
1384 port->bulk_in_endpointAddress), 1364 port->bulk_in_endpointAddress),
1385 port->read_urb->transfer_buffer, 1365 port->read_urb->transfer_buffer,
1386 port->read_urb->transfer_buffer_length, 1366 port->read_urb->transfer_buffer_length,
1387 garmin_read_bulk_callback, port); 1367 garmin_read_bulk_callback, port);
1388 retval = usb_submit_urb(port->read_urb, GFP_ATOMIC); 1368 retval = usb_submit_urb(port->read_urb, GFP_ATOMIC);
1389 if (retval) { 1369 if (retval) {
1390 dev_err(&port->dev, 1370 dev_err(&port->dev,
1391 "%s - failed submitting read urb, error %d\n", 1371 "%s - failed submitting read urb, error %d\n",
1392 __func__, retval); 1372 __func__, retval);
1393 } else { 1373 } else {
1394 spin_lock_irqsave(&garmin_data_p->lock, flags); 1374 spin_lock_irqsave(&garmin_data_p->lock, flags);
1395 garmin_data_p->flags |= FLAGS_BULK_IN_ACTIVE; 1375 garmin_data_p->flags |= FLAGS_BULK_IN_ACTIVE;
1396 /* do not send this packet to the user */ 1376 /* do not send this packet to the user */
1397 garmin_data_p->ignorePkts = 1; 1377 garmin_data_p->ignorePkts = 1;
1398 spin_unlock_irqrestore(&garmin_data_p->lock, flags); 1378 spin_unlock_irqrestore(&garmin_data_p->lock,
1379 flags);
1399 } 1380 }
1400 } else { 1381 } else {
1401 /* bulk-in transfer still active */ 1382 /* bulk-in transfer still active */
@@ -1406,15 +1387,15 @@ static void garmin_read_int_callback (struct urb *urb)
1406 1387
1407 } else if (urb->actual_length == (4+sizeof(GARMIN_START_SESSION_REPLY)) 1388 } else if (urb->actual_length == (4+sizeof(GARMIN_START_SESSION_REPLY))
1408 && 0 == memcmp(data, GARMIN_START_SESSION_REPLY, 1389 && 0 == memcmp(data, GARMIN_START_SESSION_REPLY,
1409 sizeof(GARMIN_START_SESSION_REPLY))) { 1390 sizeof(GARMIN_START_SESSION_REPLY))) {
1410 1391
1411 spin_lock_irqsave(&garmin_data_p->lock, flags); 1392 spin_lock_irqsave(&garmin_data_p->lock, flags);
1412 garmin_data_p->flags |= FLAGS_SESSION_REPLY1_SEEN; 1393 garmin_data_p->flags |= FLAGS_SESSION_REPLY1_SEEN;
1413 spin_unlock_irqrestore(&garmin_data_p->lock, flags); 1394 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1414 1395
1415 /* save the serial number */ 1396 /* save the serial number */
1416 garmin_data_p->serial_num 1397 garmin_data_p->serial_num = __le32_to_cpup(
1417 = __le32_to_cpup((__le32*)(data+GARMIN_PKTHDR_LENGTH)); 1398 (__le32 *)(data+GARMIN_PKTHDR_LENGTH));
1418 1399
1419 dbg("%s - start-of-session reply seen - serial %u.", 1400 dbg("%s - start-of-session reply seen - serial %u.",
1420 __func__, garmin_data_p->serial_num); 1401 __func__, garmin_data_p->serial_num);
@@ -1433,7 +1414,7 @@ static void garmin_read_int_callback (struct urb *urb)
1433 } 1414 }
1434 1415
1435 port->interrupt_in_urb->dev = port->serial->dev; 1416 port->interrupt_in_urb->dev = port->serial->dev;
1436 retval = usb_submit_urb (urb, GFP_ATOMIC); 1417 retval = usb_submit_urb(urb, GFP_ATOMIC);
1437 if (retval) 1418 if (retval)
1438 dev_err(&urb->dev->dev, 1419 dev_err(&urb->dev->dev,
1439 "%s - Error %d submitting interrupt urb\n", 1420 "%s - Error %d submitting interrupt urb\n",
@@ -1446,7 +1427,7 @@ static void garmin_read_int_callback (struct urb *urb)
1446 * and then sets a timer to call itself again until all queued data 1427 * and then sets a timer to call itself again until all queued data
1447 * is sent. 1428 * is sent.
1448 */ 1429 */
1449static int garmin_flush_queue(struct garmin_data * garmin_data_p) 1430static int garmin_flush_queue(struct garmin_data *garmin_data_p)
1450{ 1431{
1451 unsigned long flags; 1432 unsigned long flags;
1452 struct garmin_packet *pkt; 1433 struct garmin_packet *pkt;
@@ -1468,10 +1449,11 @@ static int garmin_flush_queue(struct garmin_data * garmin_data_p)
1468} 1449}
1469 1450
1470 1451
1471static void garmin_throttle (struct usb_serial_port *port) 1452static void garmin_throttle(struct tty_struct *tty)
1472{ 1453{
1454 struct usb_serial_port *port = tty->driver_data;
1455 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1473 unsigned long flags; 1456 unsigned long flags;
1474 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port);
1475 1457
1476 dbg("%s - port %d", __func__, port->number); 1458 dbg("%s - port %d", __func__, port->number);
1477 /* set flag, data received will be put into a queue 1459 /* set flag, data received will be put into a queue
@@ -1482,10 +1464,11 @@ static void garmin_throttle (struct usb_serial_port *port)
1482} 1464}
1483 1465
1484 1466
1485static void garmin_unthrottle (struct usb_serial_port *port) 1467static void garmin_unthrottle(struct tty_struct *tty)
1486{ 1468{
1469 struct usb_serial_port *port = tty->driver_data;
1470 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1487 unsigned long flags; 1471 unsigned long flags;
1488 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port);
1489 int status; 1472 int status;
1490 1473
1491 dbg("%s - port %d", __func__, port->number); 1474 dbg("%s - port %d", __func__, port->number);
@@ -1507,8 +1490,6 @@ static void garmin_unthrottle (struct usb_serial_port *port)
1507 } 1490 }
1508} 1491}
1509 1492
1510
1511
1512/* 1493/*
1513 * The timer is currently only used to send queued packets to 1494 * The timer is currently only used to send queued packets to
1514 * the tty in cases where the protocol provides no own handshaking 1495 * the tty in cases where the protocol provides no own handshaking
@@ -1526,11 +1507,11 @@ static void timeout_handler(unsigned long data)
1526 1507
1527 1508
1528 1509
1529static int garmin_attach (struct usb_serial *serial) 1510static int garmin_attach(struct usb_serial *serial)
1530{ 1511{
1531 int status = 0; 1512 int status = 0;
1532 struct usb_serial_port *port = serial->port[0]; 1513 struct usb_serial_port *port = serial->port[0];
1533 struct garmin_data * garmin_data_p = NULL; 1514 struct garmin_data *garmin_data_p = NULL;
1534 1515
1535 dbg("%s", __func__); 1516 dbg("%s", __func__);
1536 1517
@@ -1542,7 +1523,7 @@ static int garmin_attach (struct usb_serial *serial)
1542 init_timer(&garmin_data_p->timer); 1523 init_timer(&garmin_data_p->timer);
1543 spin_lock_init(&garmin_data_p->lock); 1524 spin_lock_init(&garmin_data_p->lock);
1544 INIT_LIST_HEAD(&garmin_data_p->pktlist); 1525 INIT_LIST_HEAD(&garmin_data_p->pktlist);
1545 //garmin_data_p->timer.expires = jiffies + session_timeout; 1526 /* garmin_data_p->timer.expires = jiffies + session_timeout; */
1546 garmin_data_p->timer.data = (unsigned long)garmin_data_p; 1527 garmin_data_p->timer.data = (unsigned long)garmin_data_p;
1547 garmin_data_p->timer.function = timeout_handler; 1528 garmin_data_p->timer.function = timeout_handler;
1548 garmin_data_p->port = port; 1529 garmin_data_p->port = port;
@@ -1556,16 +1537,16 @@ static int garmin_attach (struct usb_serial *serial)
1556} 1537}
1557 1538
1558 1539
1559static void garmin_shutdown (struct usb_serial *serial) 1540static void garmin_shutdown(struct usb_serial *serial)
1560{ 1541{
1561 struct usb_serial_port *port = serial->port[0]; 1542 struct usb_serial_port *port = serial->port[0];
1562 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 1543 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1563 1544
1564 dbg("%s", __func__); 1545 dbg("%s", __func__);
1565 1546
1566 usb_kill_urb (port->interrupt_in_urb); 1547 usb_kill_urb(port->interrupt_in_urb);
1567 del_timer_sync(&garmin_data_p->timer); 1548 del_timer_sync(&garmin_data_p->timer);
1568 kfree (garmin_data_p); 1549 kfree(garmin_data_p);
1569 usb_set_serial_port_data(port, NULL); 1550 usb_set_serial_port_data(port, NULL);
1570} 1551}
1571 1552
@@ -1588,7 +1569,6 @@ static struct usb_serial_driver garmin_device = {
1588 .shutdown = garmin_shutdown, 1569 .shutdown = garmin_shutdown,
1589 .write = garmin_write, 1570 .write = garmin_write,
1590 .write_room = garmin_write_room, 1571 .write_room = garmin_write_room,
1591 .chars_in_buffer = garmin_chars_in_buffer,
1592 .write_bulk_callback = garmin_write_bulk_callback, 1572 .write_bulk_callback = garmin_write_bulk_callback,
1593 .read_bulk_callback = garmin_read_bulk_callback, 1573 .read_bulk_callback = garmin_read_bulk_callback,
1594 .read_int_callback = garmin_read_int_callback, 1574 .read_int_callback = garmin_read_int_callback,
@@ -1596,7 +1576,7 @@ static struct usb_serial_driver garmin_device = {
1596 1576
1597 1577
1598 1578
1599static int __init garmin_init (void) 1579static int __init garmin_init(void)
1600{ 1580{
1601 int retval; 1581 int retval;
1602 1582
@@ -1616,10 +1596,10 @@ failed_garmin_register:
1616} 1596}
1617 1597
1618 1598
1619static void __exit garmin_exit (void) 1599static void __exit garmin_exit(void)
1620{ 1600{
1621 usb_deregister (&garmin_driver); 1601 usb_deregister(&garmin_driver);
1622 usb_serial_deregister (&garmin_device); 1602 usb_serial_deregister(&garmin_device);
1623} 1603}
1624 1604
1625 1605
@@ -1628,8 +1608,8 @@ static void __exit garmin_exit (void)
1628module_init(garmin_init); 1608module_init(garmin_init);
1629module_exit(garmin_exit); 1609module_exit(garmin_exit);
1630 1610
1631MODULE_AUTHOR( DRIVER_AUTHOR ); 1611MODULE_AUTHOR(DRIVER_AUTHOR);
1632MODULE_DESCRIPTION( DRIVER_DESC ); 1612MODULE_DESCRIPTION(DRIVER_DESC);
1633MODULE_LICENSE("GPL"); 1613MODULE_LICENSE("GPL");
1634 1614
1635module_param(debug, bool, S_IWUSR | S_IRUGO); 1615module_param(debug, bool, S_IWUSR | S_IRUGO);
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index 537f12a027c2..fe84c88ec20c 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -18,7 +18,7 @@
18#include <linux/moduleparam.h> 18#include <linux/moduleparam.h>
19#include <linux/usb.h> 19#include <linux/usb.h>
20#include <linux/usb/serial.h> 20#include <linux/usb/serial.h>
21#include <asm/uaccess.h> 21#include <linux/uaccess.h>
22 22
23 23
24static int debug; 24static int debug;
@@ -81,7 +81,7 @@ static int generic_probe(struct usb_interface *interface,
81} 81}
82#endif 82#endif
83 83
84int usb_serial_generic_register (int _debug) 84int usb_serial_generic_register(int _debug)
85{ 85{
86 int retval = 0; 86 int retval = 0;
87 87
@@ -89,10 +89,11 @@ int usb_serial_generic_register (int _debug)
89#ifdef CONFIG_USB_SERIAL_GENERIC 89#ifdef CONFIG_USB_SERIAL_GENERIC
90 generic_device_ids[0].idVendor = vendor; 90 generic_device_ids[0].idVendor = vendor;
91 generic_device_ids[0].idProduct = product; 91 generic_device_ids[0].idProduct = product;
92 generic_device_ids[0].match_flags = USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT; 92 generic_device_ids[0].match_flags =
93 USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT;
93 94
94 /* register our generic driver with ourselves */ 95 /* register our generic driver with ourselves */
95 retval = usb_serial_register (&usb_serial_generic_device); 96 retval = usb_serial_register(&usb_serial_generic_device);
96 if (retval) 97 if (retval)
97 goto exit; 98 goto exit;
98 retval = usb_register(&generic_driver); 99 retval = usb_register(&generic_driver);
@@ -103,16 +104,17 @@ exit:
103 return retval; 104 return retval;
104} 105}
105 106
106void usb_serial_generic_deregister (void) 107void usb_serial_generic_deregister(void)
107{ 108{
108#ifdef CONFIG_USB_SERIAL_GENERIC 109#ifdef CONFIG_USB_SERIAL_GENERIC
109 /* remove our generic driver */ 110 /* remove our generic driver */
110 usb_deregister(&generic_driver); 111 usb_deregister(&generic_driver);
111 usb_serial_deregister (&usb_serial_generic_device); 112 usb_serial_deregister(&usb_serial_generic_device);
112#endif 113#endif
113} 114}
114 115
115int usb_serial_generic_open (struct usb_serial_port *port, struct file *filp) 116int usb_serial_generic_open(struct tty_struct *tty,
117 struct usb_serial_port *port, struct file *filp)
116{ 118{
117 struct usb_serial *serial = port->serial; 119 struct usb_serial *serial = port->serial;
118 int result = 0; 120 int result = 0;
@@ -120,11 +122,11 @@ int usb_serial_generic_open (struct usb_serial_port *port, struct file *filp)
120 122
121 dbg("%s - port %d", __func__, port->number); 123 dbg("%s - port %d", __func__, port->number);
122 124
123 /* force low_latency on so that our tty_push actually forces the data through, 125 /* force low_latency on so that our tty_push actually forces the data
124 otherwise it is scheduled, and with high data rates (like with OHCI) data 126 through, otherwise it is scheduled, and with high data rates (like
125 can get lost. */ 127 with OHCI) data can get lost. */
126 if (port->tty) 128 if (tty)
127 port->tty->low_latency = 1; 129 tty->low_latency = 1;
128 130
129 /* clear the throttle flags */ 131 /* clear the throttle flags */
130 spin_lock_irqsave(&port->lock, flags); 132 spin_lock_irqsave(&port->lock, flags);
@@ -135,8 +137,9 @@ int usb_serial_generic_open (struct usb_serial_port *port, struct file *filp)
135 /* if we have a bulk endpoint, start reading from it */ 137 /* if we have a bulk endpoint, start reading from it */
136 if (serial->num_bulk_in) { 138 if (serial->num_bulk_in) {
137 /* Start reading from the device */ 139 /* Start reading from the device */
138 usb_fill_bulk_urb (port->read_urb, serial->dev, 140 usb_fill_bulk_urb(port->read_urb, serial->dev,
139 usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), 141 usb_rcvbulkpipe(serial->dev,
142 port->bulk_in_endpointAddress),
140 port->read_urb->transfer_buffer, 143 port->read_urb->transfer_buffer,
141 port->read_urb->transfer_buffer_length, 144 port->read_urb->transfer_buffer_length,
142 ((serial->type->read_bulk_callback) ? 145 ((serial->type->read_bulk_callback) ?
@@ -145,14 +148,16 @@ int usb_serial_generic_open (struct usb_serial_port *port, struct file *filp)
145 port); 148 port);
146 result = usb_submit_urb(port->read_urb, GFP_KERNEL); 149 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
147 if (result) 150 if (result)
148 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result); 151 dev_err(&port->dev,
152 "%s - failed resubmitting read urb, error %d\n",
153 __func__, result);
149 } 154 }
150 155
151 return result; 156 return result;
152} 157}
153EXPORT_SYMBOL_GPL(usb_serial_generic_open); 158EXPORT_SYMBOL_GPL(usb_serial_generic_open);
154 159
155static void generic_cleanup (struct usb_serial_port *port) 160static void generic_cleanup(struct usb_serial_port *port)
156{ 161{
157 struct usb_serial *serial = port->serial; 162 struct usb_serial *serial = port->serial;
158 163
@@ -182,7 +187,7 @@ int usb_serial_generic_resume(struct usb_serial *serial)
182#endif 187#endif
183 for (i = 0; i < serial->num_ports; i++) { 188 for (i = 0; i < serial->num_ports; i++) {
184 port = serial->port[i]; 189 port = serial->port[i];
185 if (port->open_count && port->read_urb) { 190 if (port->port.count && port->read_urb) {
186 r = usb_submit_urb(port->read_urb, GFP_NOIO); 191 r = usb_submit_urb(port->read_urb, GFP_NOIO);
187 if (r < 0) 192 if (r < 0)
188 c++; 193 c++;
@@ -192,13 +197,15 @@ int usb_serial_generic_resume(struct usb_serial *serial)
192 return c ? -EIO : 0; 197 return c ? -EIO : 0;
193} 198}
194 199
195void usb_serial_generic_close (struct usb_serial_port *port, struct file * filp) 200void usb_serial_generic_close(struct tty_struct *tty,
201 struct usb_serial_port *port, struct file *filp)
196{ 202{
197 dbg("%s - port %d", __func__, port->number); 203 dbg("%s - port %d", __func__, port->number);
198 generic_cleanup (port); 204 generic_cleanup(port);
199} 205}
200 206
201int usb_serial_generic_write(struct usb_serial_port *port, const unsigned char *buf, int count) 207int usb_serial_generic_write(struct tty_struct *tty,
208 struct usb_serial_port *port, const unsigned char *buf, int count)
202{ 209{
203 struct usb_serial *serial = port->serial; 210 struct usb_serial *serial = port->serial;
204 int result; 211 int result;
@@ -208,7 +215,7 @@ int usb_serial_generic_write(struct usb_serial_port *port, const unsigned char *
208 215
209 if (count == 0) { 216 if (count == 0) {
210 dbg("%s - write request of 0 bytes", __func__); 217 dbg("%s - write request of 0 bytes", __func__);
211 return (0); 218 return 0;
212 } 219 }
213 220
214 /* only do something if we have a bulk out endpoint */ 221 /* only do something if we have a bulk out endpoint */
@@ -223,27 +230,32 @@ int usb_serial_generic_write(struct usb_serial_port *port, const unsigned char *
223 port->write_urb_busy = 1; 230 port->write_urb_busy = 1;
224 spin_unlock_irqrestore(&port->lock, flags); 231 spin_unlock_irqrestore(&port->lock, flags);
225 232
226 count = (count > port->bulk_out_size) ? port->bulk_out_size : count; 233 count = (count > port->bulk_out_size) ?
234 port->bulk_out_size : count;
227 235
228 memcpy (port->write_urb->transfer_buffer, buf, count); 236 memcpy(port->write_urb->transfer_buffer, buf, count);
229 data = port->write_urb->transfer_buffer; 237 data = port->write_urb->transfer_buffer;
230 usb_serial_debug_data(debug, &port->dev, __func__, count, data); 238 usb_serial_debug_data(debug, &port->dev, __func__, count, data);
231 239
232 /* set up our urb */ 240 /* set up our urb */
233 usb_fill_bulk_urb (port->write_urb, serial->dev, 241 usb_fill_bulk_urb(port->write_urb, serial->dev,
234 usb_sndbulkpipe (serial->dev, 242 usb_sndbulkpipe(serial->dev,
235 port->bulk_out_endpointAddress), 243 port->bulk_out_endpointAddress),
236 port->write_urb->transfer_buffer, count, 244 port->write_urb->transfer_buffer, count,
237 ((serial->type->write_bulk_callback) ? 245 ((serial->type->write_bulk_callback) ?
238 serial->type->write_bulk_callback : 246 serial->type->write_bulk_callback :
239 usb_serial_generic_write_bulk_callback), port); 247 usb_serial_generic_write_bulk_callback),
248 port);
240 249
241 /* send the data out the bulk port */ 250 /* send the data out the bulk port */
242 port->write_urb_busy = 1; 251 port->write_urb_busy = 1;
243 result = usb_submit_urb(port->write_urb, GFP_ATOMIC); 252 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
244 if (result) { 253 if (result) {
245 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __func__, result); 254 dev_err(&port->dev,
246 /* don't have to grab the lock here, as we will retry if != 0 */ 255 "%s - failed submitting write urb, error %d\n",
256 __func__, result);
257 /* don't have to grab the lock here, as we will
258 retry if != 0 */
247 port->write_urb_busy = 0; 259 port->write_urb_busy = 0;
248 } else 260 } else
249 result = count; 261 result = count;
@@ -255,8 +267,9 @@ int usb_serial_generic_write(struct usb_serial_port *port, const unsigned char *
255 return 0; 267 return 0;
256} 268}
257 269
258int usb_serial_generic_write_room (struct usb_serial_port *port) 270int usb_serial_generic_write_room(struct tty_struct *tty)
259{ 271{
272 struct usb_serial_port *port = tty->driver_data;
260 struct usb_serial *serial = port->serial; 273 struct usb_serial *serial = port->serial;
261 int room = 0; 274 int room = 0;
262 275
@@ -272,8 +285,9 @@ int usb_serial_generic_write_room (struct usb_serial_port *port)
272 return room; 285 return room;
273} 286}
274 287
275int usb_serial_generic_chars_in_buffer (struct usb_serial_port *port) 288int usb_serial_generic_chars_in_buffer(struct tty_struct *tty)
276{ 289{
290 struct usb_serial_port *port = tty->driver_data;
277 struct usb_serial *serial = port->serial; 291 struct usb_serial *serial = port->serial;
278 int chars = 0; 292 int chars = 0;
279 293
@@ -286,7 +300,7 @@ int usb_serial_generic_chars_in_buffer (struct usb_serial_port *port)
286 } 300 }
287 301
288 dbg("%s - returns %d", __func__, chars); 302 dbg("%s - returns %d", __func__, chars);
289 return (chars); 303 return chars;
290} 304}
291 305
292 306
@@ -297,24 +311,26 @@ static void resubmit_read_urb(struct usb_serial_port *port, gfp_t mem_flags)
297 int result; 311 int result;
298 312
299 /* Continue reading from device */ 313 /* Continue reading from device */
300 usb_fill_bulk_urb (urb, serial->dev, 314 usb_fill_bulk_urb(urb, serial->dev,
301 usb_rcvbulkpipe (serial->dev, 315 usb_rcvbulkpipe(serial->dev,
302 port->bulk_in_endpointAddress), 316 port->bulk_in_endpointAddress),
303 urb->transfer_buffer, 317 urb->transfer_buffer,
304 urb->transfer_buffer_length, 318 urb->transfer_buffer_length,
305 ((serial->type->read_bulk_callback) ? 319 ((serial->type->read_bulk_callback) ?
306 serial->type->read_bulk_callback : 320 serial->type->read_bulk_callback :
307 usb_serial_generic_read_bulk_callback), port); 321 usb_serial_generic_read_bulk_callback), port);
308 result = usb_submit_urb(urb, mem_flags); 322 result = usb_submit_urb(urb, mem_flags);
309 if (result) 323 if (result)
310 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result); 324 dev_err(&port->dev,
325 "%s - failed resubmitting read urb, error %d\n",
326 __func__, result);
311} 327}
312 328
313/* Push data to tty layer and resubmit the bulk read URB */ 329/* Push data to tty layer and resubmit the bulk read URB */
314static void flush_and_resubmit_read_urb (struct usb_serial_port *port) 330static void flush_and_resubmit_read_urb(struct usb_serial_port *port)
315{ 331{
316 struct urb *urb = port->read_urb; 332 struct urb *urb = port->read_urb;
317 struct tty_struct *tty = port->tty; 333 struct tty_struct *tty = port->port.tty;
318 int room; 334 int room;
319 335
320 /* Push data to tty */ 336 /* Push data to tty */
@@ -329,7 +345,7 @@ static void flush_and_resubmit_read_urb (struct usb_serial_port *port)
329 resubmit_read_urb(port, GFP_ATOMIC); 345 resubmit_read_urb(port, GFP_ATOMIC);
330} 346}
331 347
332void usb_serial_generic_read_bulk_callback (struct urb *urb) 348void usb_serial_generic_read_bulk_callback(struct urb *urb)
333{ 349{
334 struct usb_serial_port *port = urb->context; 350 struct usb_serial_port *port = urb->context;
335 unsigned char *data = urb->transfer_buffer; 351 unsigned char *data = urb->transfer_buffer;
@@ -344,20 +360,21 @@ void usb_serial_generic_read_bulk_callback (struct urb *urb)
344 return; 360 return;
345 } 361 }
346 362
347 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); 363 usb_serial_debug_data(debug, &port->dev, __func__,
364 urb->actual_length, data);
348 365
349 /* Throttle the device if requested by tty */ 366 /* Throttle the device if requested by tty */
350 spin_lock_irqsave(&port->lock, flags); 367 spin_lock_irqsave(&port->lock, flags);
351 if (!(port->throttled = port->throttle_req)) { 368 port->throttled = port->throttle_req;
369 if (!port->throttled) {
352 spin_unlock_irqrestore(&port->lock, flags); 370 spin_unlock_irqrestore(&port->lock, flags);
353 flush_and_resubmit_read_urb(port); 371 flush_and_resubmit_read_urb(port);
354 } else { 372 } else
355 spin_unlock_irqrestore(&port->lock, flags); 373 spin_unlock_irqrestore(&port->lock, flags);
356 }
357} 374}
358EXPORT_SYMBOL_GPL(usb_serial_generic_read_bulk_callback); 375EXPORT_SYMBOL_GPL(usb_serial_generic_read_bulk_callback);
359 376
360void usb_serial_generic_write_bulk_callback (struct urb *urb) 377void usb_serial_generic_write_bulk_callback(struct urb *urb)
361{ 378{
362 struct usb_serial_port *port = urb->context; 379 struct usb_serial_port *port = urb->context;
363 int status = urb->status; 380 int status = urb->status;
@@ -374,8 +391,9 @@ void usb_serial_generic_write_bulk_callback (struct urb *urb)
374} 391}
375EXPORT_SYMBOL_GPL(usb_serial_generic_write_bulk_callback); 392EXPORT_SYMBOL_GPL(usb_serial_generic_write_bulk_callback);
376 393
377void usb_serial_generic_throttle (struct usb_serial_port *port) 394void usb_serial_generic_throttle(struct tty_struct *tty)
378{ 395{
396 struct usb_serial_port *port = tty->driver_data;
379 unsigned long flags; 397 unsigned long flags;
380 398
381 dbg("%s - port %d", __func__, port->number); 399 dbg("%s - port %d", __func__, port->number);
@@ -387,8 +405,9 @@ void usb_serial_generic_throttle (struct usb_serial_port *port)
387 spin_unlock_irqrestore(&port->lock, flags); 405 spin_unlock_irqrestore(&port->lock, flags);
388} 406}
389 407
390void usb_serial_generic_unthrottle (struct usb_serial_port *port) 408void usb_serial_generic_unthrottle(struct tty_struct *tty)
391{ 409{
410 struct usb_serial_port *port = tty->driver_data;
392 int was_throttled; 411 int was_throttled;
393 unsigned long flags; 412 unsigned long flags;
394 413
@@ -406,15 +425,14 @@ void usb_serial_generic_unthrottle (struct usb_serial_port *port)
406 } 425 }
407} 426}
408 427
409void usb_serial_generic_shutdown (struct usb_serial *serial) 428void usb_serial_generic_shutdown(struct usb_serial *serial)
410{ 429{
411 int i; 430 int i;
412 431
413 dbg("%s", __func__); 432 dbg("%s", __func__);
414 433
415 /* stop reads and writes on all ports */ 434 /* stop reads and writes on all ports */
416 for (i=0; i < serial->num_ports; ++i) { 435 for (i = 0; i < serial->num_ports; ++i)
417 generic_cleanup(serial->port[i]); 436 generic_cleanup(serial->port[i]);
418 }
419} 437}
420 438
diff --git a/drivers/usb/serial/hp4x.c b/drivers/usb/serial/hp4x.c
index 75b88b356ebc..ab905869e959 100644
--- a/drivers/usb/serial/hp4x.c
+++ b/drivers/usb/serial/hp4x.c
@@ -9,7 +9,8 @@
9 * the Free Software Foundation; either version 2 of the License, or 9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version. 10 * (at your option) any later version.
11 * 11 *
12 * See Documentation/usb/usb-serial.txt for more information on using this driver 12 * See Documentation/usb/usb-serial.txt for more information on using this
13 * driver
13 */ 14 */
14 15
15#include <linux/kernel.h> 16#include <linux/kernel.h>
diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c
index 2fd449bcfa35..bfa508ddb0fe 100644
--- a/drivers/usb/serial/io_edgeport.c
+++ b/drivers/usb/serial/io_edgeport.c
@@ -44,7 +44,7 @@
44#include <linux/wait.h> 44#include <linux/wait.h>
45#include <linux/firmware.h> 45#include <linux/firmware.h>
46#include <linux/ihex.h> 46#include <linux/ihex.h>
47#include <asm/uaccess.h> 47#include <linux/uaccess.h>
48#include <linux/usb.h> 48#include <linux/usb.h>
49#include <linux/usb/serial.h> 49#include <linux/usb/serial.h>
50#include "io_edgeport.h" 50#include "io_edgeport.h"
@@ -66,16 +66,16 @@
66 66
67/* receive port state */ 67/* receive port state */
68enum RXSTATE { 68enum RXSTATE {
69 EXPECT_HDR1 = 0, /* Expect header byte 1 */ 69 EXPECT_HDR1 = 0, /* Expect header byte 1 */
70 EXPECT_HDR2 = 1, /* Expect header byte 2 */ 70 EXPECT_HDR2 = 1, /* Expect header byte 2 */
71 EXPECT_DATA = 2, /* Expect 'RxBytesRemaining' data */ 71 EXPECT_DATA = 2, /* Expect 'RxBytesRemaining' data */
72 EXPECT_HDR3 = 3, /* Expect header byte 3 (for status hdrs only) */ 72 EXPECT_HDR3 = 3, /* Expect header byte 3 (for status hdrs only) */
73}; 73};
74 74
75 75
76/* Transmit Fifo 76/* Transmit Fifo
77 * This Transmit queue is an extension of the edgeport Rx buffer. 77 * This Transmit queue is an extension of the edgeport Rx buffer.
78 * The maximum amount of data buffered in both the edgeport 78 * The maximum amount of data buffered in both the edgeport
79 * Rx buffer (maxTxCredits) and this buffer will never exceed maxTxCredits. 79 * Rx buffer (maxTxCredits) and this buffer will never exceed maxTxCredits.
80 */ 80 */
81struct TxFifo { 81struct TxFifo {
@@ -132,12 +132,12 @@ struct edgeport_serial {
132 int is_epic; /* flag if EPiC device or not */ 132 int is_epic; /* flag if EPiC device or not */
133 133
134 __u8 interrupt_in_endpoint; /* the interrupt endpoint handle */ 134 __u8 interrupt_in_endpoint; /* the interrupt endpoint handle */
135 unsigned char * interrupt_in_buffer; /* the buffer we use for the interrupt endpoint */ 135 unsigned char *interrupt_in_buffer; /* the buffer we use for the interrupt endpoint */
136 struct urb * interrupt_read_urb; /* our interrupt urb */ 136 struct urb *interrupt_read_urb; /* our interrupt urb */
137 137
138 __u8 bulk_in_endpoint; /* the bulk in endpoint handle */ 138 __u8 bulk_in_endpoint; /* the bulk in endpoint handle */
139 unsigned char * bulk_in_buffer; /* the buffer we use for the bulk in endpoint */ 139 unsigned char *bulk_in_buffer; /* the buffer we use for the bulk in endpoint */
140 struct urb * read_urb; /* our bulk read urb */ 140 struct urb *read_urb; /* our bulk read urb */
141 bool read_in_progress; 141 bool read_in_progress;
142 spinlock_t es_lock; 142 spinlock_t es_lock;
143 143
@@ -162,16 +162,17 @@ struct divisor_table_entry {
162 __u16 Divisor; 162 __u16 Divisor;
163}; 163};
164 164
165// 165/*
166// Define table of divisors for Rev A EdgePort/4 hardware 166 * Define table of divisors for Rev A EdgePort/4 hardware
167// These assume a 3.6864MHz crystal, the standard /16, and 167 * These assume a 3.6864MHz crystal, the standard /16, and
168// MCR.7 = 0. 168 * MCR.7 = 0.
169// 169 */
170
170static const struct divisor_table_entry divisor_table[] = { 171static const struct divisor_table_entry divisor_table[] = {
171 { 50, 4608}, 172 { 50, 4608},
172 { 75, 3072}, 173 { 75, 3072},
173 { 110, 2095}, /* 2094.545455 => 230450 => .0217 % over */ 174 { 110, 2095}, /* 2094.545455 => 230450 => .0217 % over */
174 { 134, 1713}, /* 1713.011152 => 230398.5 => .00065% under */ 175 { 134, 1713}, /* 1713.011152 => 230398.5 => .00065% under */
175 { 150, 1536}, 176 { 150, 1536},
176 { 300, 768}, 177 { 300, 768},
177 { 600, 384}, 178 { 600, 384},
@@ -194,64 +195,86 @@ static int debug;
194 195
195static int low_latency = 1; /* tty low latency flag, on by default */ 196static int low_latency = 1; /* tty low latency flag, on by default */
196 197
197static atomic_t CmdUrbs; /* Number of outstanding Command Write Urbs */ 198static atomic_t CmdUrbs; /* Number of outstanding Command Write Urbs */
198 199
199 200
200/* local function prototypes */ 201/* local function prototypes */
201 202
202/* function prototypes for all URB callbacks */ 203/* function prototypes for all URB callbacks */
203static void edge_interrupt_callback (struct urb *urb); 204static void edge_interrupt_callback(struct urb *urb);
204static void edge_bulk_in_callback (struct urb *urb); 205static void edge_bulk_in_callback(struct urb *urb);
205static void edge_bulk_out_data_callback (struct urb *urb); 206static void edge_bulk_out_data_callback(struct urb *urb);
206static void edge_bulk_out_cmd_callback (struct urb *urb); 207static void edge_bulk_out_cmd_callback(struct urb *urb);
207 208
208/* function prototypes for the usbserial callbacks */ 209/* function prototypes for the usbserial callbacks */
209static int edge_open (struct usb_serial_port *port, struct file *filp); 210static int edge_open(struct tty_struct *tty, struct usb_serial_port *port,
210static void edge_close (struct usb_serial_port *port, struct file *filp); 211 struct file *filp);
211static int edge_write (struct usb_serial_port *port, const unsigned char *buf, int count); 212static void edge_close(struct tty_struct *tty, struct usb_serial_port *port,
212static int edge_write_room (struct usb_serial_port *port); 213 struct file *filp);
213static int edge_chars_in_buffer (struct usb_serial_port *port); 214static int edge_write(struct tty_struct *tty, struct usb_serial_port *port,
214static void edge_throttle (struct usb_serial_port *port); 215 const unsigned char *buf, int count);
215static void edge_unthrottle (struct usb_serial_port *port); 216static int edge_write_room(struct tty_struct *tty);
216static void edge_set_termios (struct usb_serial_port *port, struct ktermios *old_termios); 217static int edge_chars_in_buffer(struct tty_struct *tty);
217static int edge_ioctl (struct usb_serial_port *port, struct file *file, unsigned int cmd, unsigned long arg); 218static void edge_throttle(struct tty_struct *tty);
218static void edge_break (struct usb_serial_port *port, int break_state); 219static void edge_unthrottle(struct tty_struct *tty);
219static int edge_tiocmget (struct usb_serial_port *port, struct file *file); 220static void edge_set_termios(struct tty_struct *tty,
220static int edge_tiocmset (struct usb_serial_port *port, struct file *file, unsigned int set, unsigned int clear); 221 struct usb_serial_port *port,
221static int edge_startup (struct usb_serial *serial); 222 struct ktermios *old_termios);
222static void edge_shutdown (struct usb_serial *serial); 223static int edge_ioctl(struct tty_struct *tty, struct file *file,
223 224 unsigned int cmd, unsigned long arg);
225static void edge_break(struct tty_struct *tty, int break_state);
226static int edge_tiocmget(struct tty_struct *tty, struct file *file);
227static int edge_tiocmset(struct tty_struct *tty, struct file *file,
228 unsigned int set, unsigned int clear);
229static int edge_startup(struct usb_serial *serial);
230static void edge_shutdown(struct usb_serial *serial);
224 231
225#include "io_tables.h" /* all of the devices that this driver supports */ 232#include "io_tables.h" /* all of the devices that this driver supports */
226 233
227/* function prototypes for all of our local functions */ 234/* function prototypes for all of our local functions */
228static void process_rcvd_data (struct edgeport_serial *edge_serial, unsigned char *buffer, __u16 bufferLength); 235
229static void process_rcvd_status (struct edgeport_serial *edge_serial, __u8 byte2, __u8 byte3); 236static void process_rcvd_data(struct edgeport_serial *edge_serial,
230static void edge_tty_recv (struct device *dev, struct tty_struct *tty, unsigned char *data, int length); 237 unsigned char *buffer, __u16 bufferLength);
231static void handle_new_msr (struct edgeport_port *edge_port, __u8 newMsr); 238static void process_rcvd_status(struct edgeport_serial *edge_serial,
232static void handle_new_lsr (struct edgeport_port *edge_port, __u8 lsrData, __u8 lsr, __u8 data); 239 __u8 byte2, __u8 byte3);
233static int send_iosp_ext_cmd (struct edgeport_port *edge_port, __u8 command, __u8 param); 240static void edge_tty_recv(struct device *dev, struct tty_struct *tty,
234static int calc_baud_rate_divisor (int baud_rate, int *divisor); 241 unsigned char *data, int length);
235static int send_cmd_write_baud_rate (struct edgeport_port *edge_port, int baudRate); 242static void handle_new_msr(struct edgeport_port *edge_port, __u8 newMsr);
236static void change_port_settings (struct edgeport_port *edge_port, struct ktermios *old_termios); 243static void handle_new_lsr(struct edgeport_port *edge_port, __u8 lsrData,
237static int send_cmd_write_uart_register (struct edgeport_port *edge_port, __u8 regNum, __u8 regValue); 244 __u8 lsr, __u8 data);
238static int write_cmd_usb (struct edgeport_port *edge_port, unsigned char *buffer, int writeLength); 245static int send_iosp_ext_cmd(struct edgeport_port *edge_port, __u8 command,
239static void send_more_port_data (struct edgeport_serial *edge_serial, struct edgeport_port *edge_port); 246 __u8 param);
240 247static int calc_baud_rate_divisor(int baud_rate, int *divisor);
241static int sram_write (struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16 length, const __u8 *data); 248static int send_cmd_write_baud_rate(struct edgeport_port *edge_port,
242static int rom_read (struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16 length, __u8 *data); 249 int baudRate);
243static int rom_write (struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16 length, const __u8 *data); 250static void change_port_settings(struct tty_struct *tty,
244static void get_manufacturing_desc (struct edgeport_serial *edge_serial); 251 struct edgeport_port *edge_port,
245static void get_boot_desc (struct edgeport_serial *edge_serial); 252 struct ktermios *old_termios);
246static void load_application_firmware (struct edgeport_serial *edge_serial); 253static int send_cmd_write_uart_register(struct edgeport_port *edge_port,
247 254 __u8 regNum, __u8 regValue);
248static void unicode_to_ascii(char *string, int buflen, __le16 *unicode, int unicode_size); 255static int write_cmd_usb(struct edgeport_port *edge_port,
249 256 unsigned char *buffer, int writeLength);
250 257static void send_more_port_data(struct edgeport_serial *edge_serial,
251// ************************************************************************ 258 struct edgeport_port *edge_port);
252// ************************************************************************ 259
253// ************************************************************************ 260static int sram_write(struct usb_serial *serial, __u16 extAddr, __u16 addr,
254// ************************************************************************ 261 __u16 length, const __u8 *data);
262static int rom_read(struct usb_serial *serial, __u16 extAddr, __u16 addr,
263 __u16 length, __u8 *data);
264static int rom_write(struct usb_serial *serial, __u16 extAddr, __u16 addr,
265 __u16 length, const __u8 *data);
266static void get_manufacturing_desc(struct edgeport_serial *edge_serial);
267static void get_boot_desc(struct edgeport_serial *edge_serial);
268static void load_application_firmware(struct edgeport_serial *edge_serial);
269
270static void unicode_to_ascii(char *string, int buflen,
271 __le16 *unicode, int unicode_size);
272
273
274/* ************************************************************************ */
275/* ************************************************************************ */
276/* ************************************************************************ */
277/* ************************************************************************ */
255 278
256/************************************************************************ 279/************************************************************************
257 * * 280 * *
@@ -261,7 +284,7 @@ static void unicode_to_ascii(char *string, int buflen, __le16 *unicode, int unic
261 * embedded in this driver * 284 * embedded in this driver *
262 * * 285 * *
263 ************************************************************************/ 286 ************************************************************************/
264static void update_edgeport_E2PROM (struct edgeport_serial *edge_serial) 287static void update_edgeport_E2PROM(struct edgeport_serial *edge_serial)
265{ 288{
266 __u32 BootCurVer; 289 __u32 BootCurVer;
267 __u32 BootNewVer; 290 __u32 BootNewVer;
@@ -275,16 +298,14 @@ static void update_edgeport_E2PROM (struct edgeport_serial *edge_serial)
275 int response; 298 int response;
276 299
277 switch (edge_serial->product_info.iDownloadFile) { 300 switch (edge_serial->product_info.iDownloadFile) {
278 case EDGE_DOWNLOAD_FILE_I930: 301 case EDGE_DOWNLOAD_FILE_I930:
279 fw_name = "edgeport/boot.fw"; 302 fw_name = "edgeport/boot.fw";
280 break; 303 break;
281 304 case EDGE_DOWNLOAD_FILE_80251:
282 case EDGE_DOWNLOAD_FILE_80251: 305 fw_name = "edgeport/boot2.fw";
283 fw_name = "edgeport/boot2.fw"; 306 break;
284 break; 307 default:
285 308 return;
286 default:
287 return;
288 } 309 }
289 310
290 response = request_ihex_firmware(&fw, fw_name, 311 response = request_ihex_firmware(&fw, fw_name,
@@ -300,7 +321,7 @@ static void update_edgeport_E2PROM (struct edgeport_serial *edge_serial)
300 BootMinorVersion = rec->data[1]; 321 BootMinorVersion = rec->data[1];
301 BootBuildNumber = (rec->data[2] << 8) | rec->data[3]; 322 BootBuildNumber = (rec->data[2] << 8) | rec->data[3];
302 323
303 // Check Boot Image Version 324 /* Check Boot Image Version */
304 BootCurVer = (edge_serial->boot_descriptor.MajorVersion << 24) + 325 BootCurVer = (edge_serial->boot_descriptor.MajorVersion << 24) +
305 (edge_serial->boot_descriptor.MinorVersion << 16) + 326 (edge_serial->boot_descriptor.MinorVersion << 16) +
306 le16_to_cpu(edge_serial->boot_descriptor.BuildNumber); 327 le16_to_cpu(edge_serial->boot_descriptor.BuildNumber);
@@ -352,29 +373,29 @@ static void update_edgeport_E2PROM (struct edgeport_serial *edge_serial)
352 * Get string descriptor from device * 373 * Get string descriptor from device *
353 * * 374 * *
354 ************************************************************************/ 375 ************************************************************************/
355static int get_string (struct usb_device *dev, int Id, char *string, int buflen) 376static int get_string(struct usb_device *dev, int Id, char *string, int buflen)
356{ 377{
357 struct usb_string_descriptor StringDesc; 378 struct usb_string_descriptor StringDesc;
358 struct usb_string_descriptor *pStringDesc; 379 struct usb_string_descriptor *pStringDesc;
359 380
360 dbg("%s - USB String ID = %d", __func__, Id ); 381 dbg("%s - USB String ID = %d", __func__, Id);
361 382
362 if (!usb_get_descriptor(dev, USB_DT_STRING, Id, &StringDesc, sizeof(StringDesc))) { 383 if (!usb_get_descriptor(dev, USB_DT_STRING, Id,
384 &StringDesc, sizeof(StringDesc)))
363 return 0; 385 return 0;
364 }
365 386
366 pStringDesc = kmalloc (StringDesc.bLength, GFP_KERNEL); 387 pStringDesc = kmalloc(StringDesc.bLength, GFP_KERNEL);
367 388 if (!pStringDesc)
368 if (!pStringDesc) {
369 return 0; 389 return 0;
370 }
371 390
372 if (!usb_get_descriptor(dev, USB_DT_STRING, Id, pStringDesc, StringDesc.bLength )) { 391 if (!usb_get_descriptor(dev, USB_DT_STRING, Id,
392 pStringDesc, StringDesc.bLength)) {
373 kfree(pStringDesc); 393 kfree(pStringDesc);
374 return 0; 394 return 0;
375 } 395 }
376 396
377 unicode_to_ascii(string, buflen, pStringDesc->wData, pStringDesc->bLength/2); 397 unicode_to_ascii(string, buflen,
398 pStringDesc->wData, pStringDesc->bLength/2);
378 399
379 kfree(pStringDesc); 400 kfree(pStringDesc);
380 dbg("%s - USB String %s", __func__, string); 401 dbg("%s - USB String %s", __func__, string);
@@ -388,24 +409,24 @@ static int get_string (struct usb_device *dev, int Id, char *string, int buflen)
388 * Get string descriptor from device 409 * Get string descriptor from device
389 * 410 *
390 ************************************************************************/ 411 ************************************************************************/
391static int get_string_desc (struct usb_device *dev, int Id, struct usb_string_descriptor **pRetDesc) 412static int get_string_desc(struct usb_device *dev, int Id,
413 struct usb_string_descriptor **pRetDesc)
392{ 414{
393 struct usb_string_descriptor StringDesc; 415 struct usb_string_descriptor StringDesc;
394 struct usb_string_descriptor *pStringDesc; 416 struct usb_string_descriptor *pStringDesc;
395 417
396 dbg("%s - USB String ID = %d", __func__, Id ); 418 dbg("%s - USB String ID = %d", __func__, Id);
397 419
398 if (!usb_get_descriptor(dev, USB_DT_STRING, Id, &StringDesc, sizeof(StringDesc))) { 420 if (!usb_get_descriptor(dev, USB_DT_STRING, Id, &StringDesc,
421 sizeof(StringDesc)))
399 return 0; 422 return 0;
400 }
401 423
402 pStringDesc = kmalloc (StringDesc.bLength, GFP_KERNEL); 424 pStringDesc = kmalloc(StringDesc.bLength, GFP_KERNEL);
403 425 if (!pStringDesc)
404 if (!pStringDesc) {
405 return -1; 426 return -1;
406 }
407 427
408 if (!usb_get_descriptor(dev, USB_DT_STRING, Id, pStringDesc, StringDesc.bLength )) { 428 if (!usb_get_descriptor(dev, USB_DT_STRING, Id, pStringDesc,
429 StringDesc.bLength)) {
409 kfree(pStringDesc); 430 kfree(pStringDesc);
410 return -1; 431 return -1;
411 } 432 }
@@ -417,25 +438,30 @@ static int get_string_desc (struct usb_device *dev, int Id, struct usb_string_de
417 438
418static void dump_product_info(struct edgeport_product_info *product_info) 439static void dump_product_info(struct edgeport_product_info *product_info)
419{ 440{
420 // Dump Product Info structure 441 /* Dump Product Info structure */
421 dbg("**Product Information:"); 442 dbg("**Product Information:");
422 dbg(" ProductId %x", product_info->ProductId ); 443 dbg(" ProductId %x", product_info->ProductId);
423 dbg(" NumPorts %d", product_info->NumPorts ); 444 dbg(" NumPorts %d", product_info->NumPorts);
424 dbg(" ProdInfoVer %d", product_info->ProdInfoVer ); 445 dbg(" ProdInfoVer %d", product_info->ProdInfoVer);
425 dbg(" IsServer %d", product_info->IsServer); 446 dbg(" IsServer %d", product_info->IsServer);
426 dbg(" IsRS232 %d", product_info->IsRS232 ); 447 dbg(" IsRS232 %d", product_info->IsRS232);
427 dbg(" IsRS422 %d", product_info->IsRS422 ); 448 dbg(" IsRS422 %d", product_info->IsRS422);
428 dbg(" IsRS485 %d", product_info->IsRS485 ); 449 dbg(" IsRS485 %d", product_info->IsRS485);
429 dbg(" RomSize %d", product_info->RomSize ); 450 dbg(" RomSize %d", product_info->RomSize);
430 dbg(" RamSize %d", product_info->RamSize ); 451 dbg(" RamSize %d", product_info->RamSize);
431 dbg(" CpuRev %x", product_info->CpuRev ); 452 dbg(" CpuRev %x", product_info->CpuRev);
432 dbg(" BoardRev %x", product_info->BoardRev); 453 dbg(" BoardRev %x", product_info->BoardRev);
433 dbg(" BootMajorVersion %d.%d.%d", product_info->BootMajorVersion, 454 dbg(" BootMajorVersion %d.%d.%d", product_info->BootMajorVersion,
434 product_info->BootMinorVersion, 455 product_info->BootMinorVersion,
435 le16_to_cpu(product_info->BootBuildNumber)); 456 le16_to_cpu(product_info->BootBuildNumber));
436 dbg(" ManufactureDescDate %d/%d/%d", product_info->ManufactureDescDate[0], 457 dbg(" FirmwareMajorVersion %d.%d.%d",
437 product_info->ManufactureDescDate[1], 458 product_info->FirmwareMajorVersion,
438 product_info->ManufactureDescDate[2]+1900); 459 product_info->FirmwareMinorVersion,
460 le16_to_cpu(product_info->FirmwareBuildNumber));
461 dbg(" ManufactureDescDate %d/%d/%d",
462 product_info->ManufactureDescDate[0],
463 product_info->ManufactureDescDate[1],
464 product_info->ManufactureDescDate[2]+1900);
439 dbg(" iDownloadFile 0x%x", product_info->iDownloadFile); 465 dbg(" iDownloadFile 0x%x", product_info->iDownloadFile);
440 dbg(" EpicVer %d", product_info->EpicVer); 466 dbg(" EpicVer %d", product_info->EpicVer);
441} 467}
@@ -444,55 +470,60 @@ static void get_product_info(struct edgeport_serial *edge_serial)
444{ 470{
445 struct edgeport_product_info *product_info = &edge_serial->product_info; 471 struct edgeport_product_info *product_info = &edge_serial->product_info;
446 472
447 memset (product_info, 0, sizeof(struct edgeport_product_info)); 473 memset(product_info, 0, sizeof(struct edgeport_product_info));
448 474
449 product_info->ProductId = (__u16)(le16_to_cpu(edge_serial->serial->dev->descriptor.idProduct) & ~ION_DEVICE_ID_80251_NETCHIP); 475 product_info->ProductId = (__u16)(le16_to_cpu(edge_serial->serial->dev->descriptor.idProduct) & ~ION_DEVICE_ID_80251_NETCHIP);
450 product_info->NumPorts = edge_serial->manuf_descriptor.NumPorts; 476 product_info->NumPorts = edge_serial->manuf_descriptor.NumPorts;
451 product_info->ProdInfoVer = 0; 477 product_info->ProdInfoVer = 0;
452 478
453 product_info->RomSize = edge_serial->manuf_descriptor.RomSize; 479 product_info->RomSize = edge_serial->manuf_descriptor.RomSize;
454 product_info->RamSize = edge_serial->manuf_descriptor.RamSize; 480 product_info->RamSize = edge_serial->manuf_descriptor.RamSize;
455 product_info->CpuRev = edge_serial->manuf_descriptor.CpuRev; 481 product_info->CpuRev = edge_serial->manuf_descriptor.CpuRev;
456 product_info->BoardRev = edge_serial->manuf_descriptor.BoardRev; 482 product_info->BoardRev = edge_serial->manuf_descriptor.BoardRev;
457 483
458 product_info->BootMajorVersion = edge_serial->boot_descriptor.MajorVersion; 484 product_info->BootMajorVersion =
459 product_info->BootMinorVersion = edge_serial->boot_descriptor.MinorVersion; 485 edge_serial->boot_descriptor.MajorVersion;
460 product_info->BootBuildNumber = edge_serial->boot_descriptor.BuildNumber; 486 product_info->BootMinorVersion =
461 487 edge_serial->boot_descriptor.MinorVersion;
462 memcpy(product_info->ManufactureDescDate, edge_serial->manuf_descriptor.DescDate, sizeof(edge_serial->manuf_descriptor.DescDate)); 488 product_info->BootBuildNumber =
463 489 edge_serial->boot_descriptor.BuildNumber;
464 // check if this is 2nd generation hardware 490
465 if (le16_to_cpu(edge_serial->serial->dev->descriptor.idProduct) & ION_DEVICE_ID_80251_NETCHIP) { 491 memcpy(product_info->ManufactureDescDate,
466 product_info->iDownloadFile = EDGE_DOWNLOAD_FILE_80251; 492 edge_serial->manuf_descriptor.DescDate,
467 } else { 493 sizeof(edge_serial->manuf_descriptor.DescDate));
468 product_info->iDownloadFile = EDGE_DOWNLOAD_FILE_I930; 494
469 } 495 /* check if this is 2nd generation hardware */
470 496 if (le16_to_cpu(edge_serial->serial->dev->descriptor.idProduct)
471 // Determine Product type and set appropriate flags 497 & ION_DEVICE_ID_80251_NETCHIP)
498 product_info->iDownloadFile = EDGE_DOWNLOAD_FILE_80251;
499 else
500 product_info->iDownloadFile = EDGE_DOWNLOAD_FILE_I930;
501
502 /* Determine Product type and set appropriate flags */
472 switch (DEVICE_ID_FROM_USB_PRODUCT_ID(product_info->ProductId)) { 503 switch (DEVICE_ID_FROM_USB_PRODUCT_ID(product_info->ProductId)) {
473 case ION_DEVICE_ID_EDGEPORT_COMPATIBLE: 504 case ION_DEVICE_ID_EDGEPORT_COMPATIBLE:
474 case ION_DEVICE_ID_EDGEPORT_4T: 505 case ION_DEVICE_ID_EDGEPORT_4T:
475 case ION_DEVICE_ID_EDGEPORT_4: 506 case ION_DEVICE_ID_EDGEPORT_4:
476 case ION_DEVICE_ID_EDGEPORT_2: 507 case ION_DEVICE_ID_EDGEPORT_2:
477 case ION_DEVICE_ID_EDGEPORT_8_DUAL_CPU: 508 case ION_DEVICE_ID_EDGEPORT_8_DUAL_CPU:
478 case ION_DEVICE_ID_EDGEPORT_8: 509 case ION_DEVICE_ID_EDGEPORT_8:
479 case ION_DEVICE_ID_EDGEPORT_421: 510 case ION_DEVICE_ID_EDGEPORT_421:
480 case ION_DEVICE_ID_EDGEPORT_21: 511 case ION_DEVICE_ID_EDGEPORT_21:
481 case ION_DEVICE_ID_EDGEPORT_2_DIN: 512 case ION_DEVICE_ID_EDGEPORT_2_DIN:
482 case ION_DEVICE_ID_EDGEPORT_4_DIN: 513 case ION_DEVICE_ID_EDGEPORT_4_DIN:
483 case ION_DEVICE_ID_EDGEPORT_16_DUAL_CPU: 514 case ION_DEVICE_ID_EDGEPORT_16_DUAL_CPU:
484 product_info->IsRS232 = 1; 515 product_info->IsRS232 = 1;
485 break; 516 break;
486 517
487 case ION_DEVICE_ID_EDGEPORT_2I: // Edgeport/2 RS422/RS485 518 case ION_DEVICE_ID_EDGEPORT_2I: /* Edgeport/2 RS422/RS485 */
488 product_info->IsRS422 = 1; 519 product_info->IsRS422 = 1;
489 product_info->IsRS485 = 1; 520 product_info->IsRS485 = 1;
490 break; 521 break;
491 522
492 case ION_DEVICE_ID_EDGEPORT_8I: // Edgeport/4 RS422 523 case ION_DEVICE_ID_EDGEPORT_8I: /* Edgeport/4 RS422 */
493 case ION_DEVICE_ID_EDGEPORT_4I: // Edgeport/4 RS422 524 case ION_DEVICE_ID_EDGEPORT_4I: /* Edgeport/4 RS422 */
494 product_info->IsRS422 = 1; 525 product_info->IsRS422 = 1;
495 break; 526 break;
496 } 527 }
497 528
498 dump_product_info(product_info); 529 dump_product_info(product_info);
@@ -520,32 +551,32 @@ static int get_epic_descriptor(struct edgeport_serial *ep)
520 ep->is_epic = 1; 551 ep->is_epic = 1;
521 memset(product_info, 0, sizeof(struct edgeport_product_info)); 552 memset(product_info, 0, sizeof(struct edgeport_product_info));
522 553
523 product_info->NumPorts = epic->NumPorts; 554 product_info->NumPorts = epic->NumPorts;
524 product_info->ProdInfoVer = 0; 555 product_info->ProdInfoVer = 0;
525 product_info->FirmwareMajorVersion = epic->MajorVersion; 556 product_info->FirmwareMajorVersion = epic->MajorVersion;
526 product_info->FirmwareMinorVersion = epic->MinorVersion; 557 product_info->FirmwareMinorVersion = epic->MinorVersion;
527 product_info->FirmwareBuildNumber = epic->BuildNumber; 558 product_info->FirmwareBuildNumber = epic->BuildNumber;
528 product_info->iDownloadFile = epic->iDownloadFile; 559 product_info->iDownloadFile = epic->iDownloadFile;
529 product_info->EpicVer = epic->EpicVer; 560 product_info->EpicVer = epic->EpicVer;
530 product_info->Epic = epic->Supports; 561 product_info->Epic = epic->Supports;
531 product_info->ProductId = ION_DEVICE_ID_EDGEPORT_COMPATIBLE; 562 product_info->ProductId = ION_DEVICE_ID_EDGEPORT_COMPATIBLE;
532 dump_product_info(product_info); 563 dump_product_info(product_info);
533 564
534 bits = &ep->epic_descriptor.Supports; 565 bits = &ep->epic_descriptor.Supports;
535 dbg("**EPIC descriptor:"); 566 dbg("**EPIC descriptor:");
536 dbg(" VendEnableSuspend: %s", bits->VendEnableSuspend ? "TRUE": "FALSE"); 567 dbg(" VendEnableSuspend: %s", bits->VendEnableSuspend ? "TRUE": "FALSE");
537 dbg(" IOSPOpen : %s", bits->IOSPOpen ? "TRUE": "FALSE" ); 568 dbg(" IOSPOpen : %s", bits->IOSPOpen ? "TRUE": "FALSE");
538 dbg(" IOSPClose : %s", bits->IOSPClose ? "TRUE": "FALSE" ); 569 dbg(" IOSPClose : %s", bits->IOSPClose ? "TRUE": "FALSE");
539 dbg(" IOSPChase : %s", bits->IOSPChase ? "TRUE": "FALSE" ); 570 dbg(" IOSPChase : %s", bits->IOSPChase ? "TRUE": "FALSE");
540 dbg(" IOSPSetRxFlow : %s", bits->IOSPSetRxFlow ? "TRUE": "FALSE" ); 571 dbg(" IOSPSetRxFlow : %s", bits->IOSPSetRxFlow ? "TRUE": "FALSE");
541 dbg(" IOSPSetTxFlow : %s", bits->IOSPSetTxFlow ? "TRUE": "FALSE" ); 572 dbg(" IOSPSetTxFlow : %s", bits->IOSPSetTxFlow ? "TRUE": "FALSE");
542 dbg(" IOSPSetXChar : %s", bits->IOSPSetXChar ? "TRUE": "FALSE" ); 573 dbg(" IOSPSetXChar : %s", bits->IOSPSetXChar ? "TRUE": "FALSE");
543 dbg(" IOSPRxCheck : %s", bits->IOSPRxCheck ? "TRUE": "FALSE" ); 574 dbg(" IOSPRxCheck : %s", bits->IOSPRxCheck ? "TRUE": "FALSE");
544 dbg(" IOSPSetClrBreak : %s", bits->IOSPSetClrBreak ? "TRUE": "FALSE" ); 575 dbg(" IOSPSetClrBreak : %s", bits->IOSPSetClrBreak ? "TRUE": "FALSE");
545 dbg(" IOSPWriteMCR : %s", bits->IOSPWriteMCR ? "TRUE": "FALSE" ); 576 dbg(" IOSPWriteMCR : %s", bits->IOSPWriteMCR ? "TRUE": "FALSE");
546 dbg(" IOSPWriteLCR : %s", bits->IOSPWriteLCR ? "TRUE": "FALSE" ); 577 dbg(" IOSPWriteLCR : %s", bits->IOSPWriteLCR ? "TRUE": "FALSE");
547 dbg(" IOSPSetBaudRate : %s", bits->IOSPSetBaudRate ? "TRUE": "FALSE" ); 578 dbg(" IOSPSetBaudRate : %s", bits->IOSPSetBaudRate ? "TRUE": "FALSE");
548 dbg(" TrueEdgeport : %s", bits->TrueEdgeport ? "TRUE": "FALSE" ); 579 dbg(" TrueEdgeport : %s", bits->TrueEdgeport ? "TRUE": "FALSE");
549 } 580 }
550 581
551 return result; 582 return result;
@@ -561,10 +592,10 @@ static int get_epic_descriptor(struct edgeport_serial *ep)
561 592
562/***************************************************************************** 593/*****************************************************************************
563 * edge_interrupt_callback 594 * edge_interrupt_callback
564 * this is the callback function for when we have received data on the 595 * this is the callback function for when we have received data on the
565 * interrupt endpoint. 596 * interrupt endpoint.
566 *****************************************************************************/ 597 *****************************************************************************/
567static void edge_interrupt_callback (struct urb *urb) 598static void edge_interrupt_callback(struct urb *urb)
568{ 599{
569 struct edgeport_serial *edge_serial = urb->context; 600 struct edgeport_serial *edge_serial = urb->context;
570 struct edgeport_port *edge_port; 601 struct edgeport_port *edge_port;
@@ -589,17 +620,17 @@ static void edge_interrupt_callback (struct urb *urb)
589 case -ESHUTDOWN: 620 case -ESHUTDOWN:
590 /* this urb is terminated, clean up */ 621 /* this urb is terminated, clean up */
591 dbg("%s - urb shutting down with status: %d", 622 dbg("%s - urb shutting down with status: %d",
592 __func__, status); 623 __func__, status);
593 return; 624 return;
594 default: 625 default:
595 dbg("%s - nonzero urb status received: %d", 626 dbg("%s - nonzero urb status received: %d", __func__, status);
596 __func__, status);
597 goto exit; 627 goto exit;
598 } 628 }
599 629
600 // process this interrupt-read even if there are no ports open 630 /* process this interrupt-read even if there are no ports open */
601 if (length) { 631 if (length) {
602 usb_serial_debug_data(debug, &edge_serial->serial->dev->dev, __func__, length, data); 632 usb_serial_debug_data(debug, &edge_serial->serial->dev->dev,
633 __func__, length, data);
603 634
604 if (length > 1) { 635 if (length > 1) {
605 bytes_avail = data[0] | (data[1] << 8); 636 bytes_avail = data[0] | (data[1] << 8);
@@ -613,7 +644,8 @@ static void edge_interrupt_callback (struct urb *urb)
613 dbg("%s - posting a read", __func__); 644 dbg("%s - posting a read", __func__);
614 edge_serial->read_in_progress = true; 645 edge_serial->read_in_progress = true;
615 646
616 /* we have pending bytes on the bulk in pipe, send a request */ 647 /* we have pending bytes on the
648 bulk in pipe, send a request */
617 edge_serial->read_urb->dev = edge_serial->serial->dev; 649 edge_serial->read_urb->dev = edge_serial->serial->dev;
618 result = usb_submit_urb(edge_serial->read_urb, GFP_ATOMIC); 650 result = usb_submit_urb(edge_serial->read_urb, GFP_ATOMIC);
619 if (result) { 651 if (result) {
@@ -627,7 +659,8 @@ static void edge_interrupt_callback (struct urb *urb)
627 /* grab the txcredits for the ports if available */ 659 /* grab the txcredits for the ports if available */
628 position = 2; 660 position = 2;
629 portNumber = 0; 661 portNumber = 0;
630 while ((position < length) && (portNumber < edge_serial->serial->num_ports)) { 662 while ((position < length) &&
663 (portNumber < edge_serial->serial->num_ports)) {
631 txCredits = data[position] | (data[position+1] << 8); 664 txCredits = data[position] | (data[position+1] << 8);
632 if (txCredits) { 665 if (txCredits) {
633 port = edge_serial->serial->port[portNumber]; 666 port = edge_serial->serial->port[portNumber];
@@ -636,14 +669,19 @@ static void edge_interrupt_callback (struct urb *urb)
636 spin_lock(&edge_port->ep_lock); 669 spin_lock(&edge_port->ep_lock);
637 edge_port->txCredits += txCredits; 670 edge_port->txCredits += txCredits;
638 spin_unlock(&edge_port->ep_lock); 671 spin_unlock(&edge_port->ep_lock);
639 dbg("%s - txcredits for port%d = %d", __func__, portNumber, edge_port->txCredits); 672 dbg("%s - txcredits for port%d = %d",
640 673 __func__, portNumber,
641 /* tell the tty driver that something has changed */ 674 edge_port->txCredits);
642 if (edge_port->port->tty) 675
643 tty_wakeup(edge_port->port->tty); 676 /* tell the tty driver that something
644 677 has changed */
645 // Since we have more credit, check if more data can be sent 678 if (edge_port->port->port.tty)
646 send_more_port_data(edge_serial, edge_port); 679 tty_wakeup(edge_port->port->port.tty);
680
681 /* Since we have more credit, check
682 if more data can be sent */
683 send_more_port_data(edge_serial,
684 edge_port);
647 } 685 }
648 } 686 }
649 position += 2; 687 position += 2;
@@ -652,19 +690,20 @@ static void edge_interrupt_callback (struct urb *urb)
652 } 690 }
653 691
654exit: 692exit:
655 result = usb_submit_urb (urb, GFP_ATOMIC); 693 result = usb_submit_urb(urb, GFP_ATOMIC);
656 if (result) { 694 if (result)
657 dev_err(&urb->dev->dev, "%s - Error %d submitting control urb\n", __func__, result); 695 dev_err(&urb->dev->dev,
658 } 696 "%s - Error %d submitting control urb\n",
697 __func__, result);
659} 698}
660 699
661 700
662/***************************************************************************** 701/*****************************************************************************
663 * edge_bulk_in_callback 702 * edge_bulk_in_callback
664 * this is the callback function for when we have received data on the 703 * this is the callback function for when we have received data on the
665 * bulk in endpoint. 704 * bulk in endpoint.
666 *****************************************************************************/ 705 *****************************************************************************/
667static void edge_bulk_in_callback (struct urb *urb) 706static void edge_bulk_in_callback(struct urb *urb)
668{ 707{
669 struct edgeport_serial *edge_serial = urb->context; 708 struct edgeport_serial *edge_serial = urb->context;
670 unsigned char *data = urb->transfer_buffer; 709 unsigned char *data = urb->transfer_buffer;
@@ -689,16 +728,18 @@ static void edge_bulk_in_callback (struct urb *urb)
689 728
690 raw_data_length = urb->actual_length; 729 raw_data_length = urb->actual_length;
691 730
692 usb_serial_debug_data(debug, &edge_serial->serial->dev->dev, __func__, raw_data_length, data); 731 usb_serial_debug_data(debug, &edge_serial->serial->dev->dev,
732 __func__, raw_data_length, data);
693 733
694 spin_lock(&edge_serial->es_lock); 734 spin_lock(&edge_serial->es_lock);
695 735
696 /* decrement our rxBytes available by the number that we just got */ 736 /* decrement our rxBytes available by the number that we just got */
697 edge_serial->rxBytesAvail -= raw_data_length; 737 edge_serial->rxBytesAvail -= raw_data_length;
698 738
699 dbg("%s - Received = %d, rxBytesAvail %d", __func__, raw_data_length, edge_serial->rxBytesAvail); 739 dbg("%s - Received = %d, rxBytesAvail %d", __func__,
740 raw_data_length, edge_serial->rxBytesAvail);
700 741
701 process_rcvd_data (edge_serial, data, urb->actual_length); 742 process_rcvd_data(edge_serial, data, urb->actual_length);
702 743
703 /* check to see if there's any more data for us to read */ 744 /* check to see if there's any more data for us to read */
704 if (edge_serial->rxBytesAvail > 0) { 745 if (edge_serial->rxBytesAvail > 0) {
@@ -721,10 +762,10 @@ static void edge_bulk_in_callback (struct urb *urb)
721 762
722/***************************************************************************** 763/*****************************************************************************
723 * edge_bulk_out_data_callback 764 * edge_bulk_out_data_callback
724 * this is the callback function for when we have finished sending serial data 765 * this is the callback function for when we have finished sending
725 * on the bulk out endpoint. 766 * serial data on the bulk out endpoint.
726 *****************************************************************************/ 767 *****************************************************************************/
727static void edge_bulk_out_data_callback (struct urb *urb) 768static void edge_bulk_out_data_callback(struct urb *urb)
728{ 769{
729 struct edgeport_port *edge_port = urb->context; 770 struct edgeport_port *edge_port = urb->context;
730 struct tty_struct *tty; 771 struct tty_struct *tty;
@@ -737,27 +778,29 @@ static void edge_bulk_out_data_callback (struct urb *urb)
737 __func__, status); 778 __func__, status);
738 } 779 }
739 780
740 tty = edge_port->port->tty; 781 tty = edge_port->port->port.tty;
741 782
742 if (tty && edge_port->open) { 783 if (tty && edge_port->open) {
743 /* let the tty driver wakeup if it has a special write_wakeup function */ 784 /* let the tty driver wakeup if it has a special
785 write_wakeup function */
744 tty_wakeup(tty); 786 tty_wakeup(tty);
745 } 787 }
746 788
747 // Release the Write URB 789 /* Release the Write URB */
748 edge_port->write_in_progress = false; 790 edge_port->write_in_progress = false;
749 791
750 // Check if more data needs to be sent 792 /* Check if more data needs to be sent */
751 send_more_port_data((struct edgeport_serial *)(usb_get_serial_data(edge_port->port->serial)), edge_port); 793 send_more_port_data((struct edgeport_serial *)
794 (usb_get_serial_data(edge_port->port->serial)), edge_port);
752} 795}
753 796
754 797
755/***************************************************************************** 798/*****************************************************************************
756 * BulkOutCmdCallback 799 * BulkOutCmdCallback
757 * this is the callback function for when we have finished sending a command 800 * this is the callback function for when we have finished sending a
758 * on the bulk out endpoint. 801 * command on the bulk out endpoint.
759 *****************************************************************************/ 802 *****************************************************************************/
760static void edge_bulk_out_cmd_callback (struct urb *urb) 803static void edge_bulk_out_cmd_callback(struct urb *urb)
761{ 804{
762 struct edgeport_port *edge_port = urb->context; 805 struct edgeport_port *edge_port = urb->context;
763 struct tty_struct *tty; 806 struct tty_struct *tty;
@@ -766,22 +809,24 @@ static void edge_bulk_out_cmd_callback (struct urb *urb)
766 dbg("%s", __func__); 809 dbg("%s", __func__);
767 810
768 atomic_dec(&CmdUrbs); 811 atomic_dec(&CmdUrbs);
769 dbg("%s - FREE URB %p (outstanding %d)", __func__, urb, atomic_read(&CmdUrbs)); 812 dbg("%s - FREE URB %p (outstanding %d)", __func__,
813 urb, atomic_read(&CmdUrbs));
770 814
771 815
772 /* clean up the transfer buffer */ 816 /* clean up the transfer buffer */
773 kfree(urb->transfer_buffer); 817 kfree(urb->transfer_buffer);
774 818
775 /* Free the command urb */ 819 /* Free the command urb */
776 usb_free_urb (urb); 820 usb_free_urb(urb);
777 821
778 if (status) { 822 if (status) {
779 dbg("%s - nonzero write bulk status received: %d", __func__, status); 823 dbg("%s - nonzero write bulk status received: %d",
824 __func__, status);
780 return; 825 return;
781 } 826 }
782 827
783 /* Get pointer to tty */ 828 /* Get pointer to tty */
784 tty = edge_port->port->tty; 829 tty = edge_port->port->port.tty;
785 830
786 /* tell the tty driver that something has changed */ 831 /* tell the tty driver that something has changed */
787 if (tty && edge_port->open) 832 if (tty && edge_port->open)
@@ -803,7 +848,8 @@ static void edge_bulk_out_cmd_callback (struct urb *urb)
803 * If successful, we return 0 848 * If successful, we return 0
804 * Otherwise we return a negative error number. 849 * Otherwise we return a negative error number.
805 *****************************************************************************/ 850 *****************************************************************************/
806static int edge_open (struct usb_serial_port *port, struct file * filp) 851static int edge_open(struct tty_struct *tty,
852 struct usb_serial_port *port, struct file *filp)
807{ 853{
808 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 854 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
809 struct usb_serial *serial; 855 struct usb_serial *serial;
@@ -815,55 +861,62 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
815 if (edge_port == NULL) 861 if (edge_port == NULL)
816 return -ENODEV; 862 return -ENODEV;
817 863
818 if (port->tty) 864 if (tty)
819 port->tty->low_latency = low_latency; 865 tty->low_latency = low_latency;
820 866
821 /* see if we've set up our endpoint info yet (can't set it up in edge_startup 867 /* see if we've set up our endpoint info yet (can't set it up
822 as the structures were not set up at that time.) */ 868 in edge_startup as the structures were not set up at that time.) */
823 serial = port->serial; 869 serial = port->serial;
824 edge_serial = usb_get_serial_data(serial); 870 edge_serial = usb_get_serial_data(serial);
825 if (edge_serial == NULL) { 871 if (edge_serial == NULL)
826 return -ENODEV; 872 return -ENODEV;
827 }
828 if (edge_serial->interrupt_in_buffer == NULL) { 873 if (edge_serial->interrupt_in_buffer == NULL) {
829 struct usb_serial_port *port0 = serial->port[0]; 874 struct usb_serial_port *port0 = serial->port[0];
830 875
831 /* not set up yet, so do it now */ 876 /* not set up yet, so do it now */
832 edge_serial->interrupt_in_buffer = port0->interrupt_in_buffer; 877 edge_serial->interrupt_in_buffer =
833 edge_serial->interrupt_in_endpoint = port0->interrupt_in_endpointAddress; 878 port0->interrupt_in_buffer;
879 edge_serial->interrupt_in_endpoint =
880 port0->interrupt_in_endpointAddress;
834 edge_serial->interrupt_read_urb = port0->interrupt_in_urb; 881 edge_serial->interrupt_read_urb = port0->interrupt_in_urb;
835 edge_serial->bulk_in_buffer = port0->bulk_in_buffer; 882 edge_serial->bulk_in_buffer = port0->bulk_in_buffer;
836 edge_serial->bulk_in_endpoint = port0->bulk_in_endpointAddress; 883 edge_serial->bulk_in_endpoint =
884 port0->bulk_in_endpointAddress;
837 edge_serial->read_urb = port0->read_urb; 885 edge_serial->read_urb = port0->read_urb;
838 edge_serial->bulk_out_endpoint = port0->bulk_out_endpointAddress; 886 edge_serial->bulk_out_endpoint =
839 887 port0->bulk_out_endpointAddress;
888
840 /* set up our interrupt urb */ 889 /* set up our interrupt urb */
841 usb_fill_int_urb(edge_serial->interrupt_read_urb, 890 usb_fill_int_urb(edge_serial->interrupt_read_urb,
842 serial->dev, 891 serial->dev,
843 usb_rcvintpipe(serial->dev, 892 usb_rcvintpipe(serial->dev,
844 port0->interrupt_in_endpointAddress), 893 port0->interrupt_in_endpointAddress),
845 port0->interrupt_in_buffer, 894 port0->interrupt_in_buffer,
846 edge_serial->interrupt_read_urb->transfer_buffer_length, 895 edge_serial->interrupt_read_urb->transfer_buffer_length,
847 edge_interrupt_callback, edge_serial, 896 edge_interrupt_callback, edge_serial,
848 edge_serial->interrupt_read_urb->interval); 897 edge_serial->interrupt_read_urb->interval);
849 898
850 /* set up our bulk in urb */ 899 /* set up our bulk in urb */
851 usb_fill_bulk_urb(edge_serial->read_urb, serial->dev, 900 usb_fill_bulk_urb(edge_serial->read_urb, serial->dev,
852 usb_rcvbulkpipe(serial->dev, 901 usb_rcvbulkpipe(serial->dev,
853 port0->bulk_in_endpointAddress), 902 port0->bulk_in_endpointAddress),
854 port0->bulk_in_buffer, 903 port0->bulk_in_buffer,
855 edge_serial->read_urb->transfer_buffer_length, 904 edge_serial->read_urb->transfer_buffer_length,
856 edge_bulk_in_callback, edge_serial); 905 edge_bulk_in_callback, edge_serial);
857 edge_serial->read_in_progress = false; 906 edge_serial->read_in_progress = false;
858 907
859 /* start interrupt read for this edgeport 908 /* start interrupt read for this edgeport
860 * this interrupt will continue as long as the edgeport is connected */ 909 * this interrupt will continue as long
861 response = usb_submit_urb (edge_serial->interrupt_read_urb, GFP_KERNEL); 910 * as the edgeport is connected */
911 response = usb_submit_urb(edge_serial->interrupt_read_urb,
912 GFP_KERNEL);
862 if (response) { 913 if (response) {
863 dev_err(&port->dev, "%s - Error %d submitting control urb\n", __func__, response); 914 dev_err(&port->dev,
915 "%s - Error %d submitting control urb\n",
916 __func__, response);
864 } 917 }
865 } 918 }
866 919
867 /* initialize our wait queues */ 920 /* initialize our wait queues */
868 init_waitqueue_head(&edge_port->wait_open); 921 init_waitqueue_head(&edge_port->wait_open);
869 init_waitqueue_head(&edge_port->wait_chase); 922 init_waitqueue_head(&edge_port->wait_chase);
@@ -871,26 +924,29 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
871 init_waitqueue_head(&edge_port->wait_command); 924 init_waitqueue_head(&edge_port->wait_command);
872 925
873 /* initialize our icount structure */ 926 /* initialize our icount structure */
874 memset (&(edge_port->icount), 0x00, sizeof(edge_port->icount)); 927 memset(&(edge_port->icount), 0x00, sizeof(edge_port->icount));
875 928
876 /* initialize our port settings */ 929 /* initialize our port settings */
877 edge_port->txCredits = 0; /* Can't send any data yet */ 930 edge_port->txCredits = 0; /* Can't send any data yet */
878 edge_port->shadowMCR = MCR_MASTER_IE; /* Must always set this bit to enable ints! */ 931 /* Must always set this bit to enable ints! */
932 edge_port->shadowMCR = MCR_MASTER_IE;
879 edge_port->chaseResponsePending = false; 933 edge_port->chaseResponsePending = false;
880 934
881 /* send a open port command */ 935 /* send a open port command */
882 edge_port->openPending = true; 936 edge_port->openPending = true;
883 edge_port->open = false; 937 edge_port->open = false;
884 response = send_iosp_ext_cmd (edge_port, IOSP_CMD_OPEN_PORT, 0); 938 response = send_iosp_ext_cmd(edge_port, IOSP_CMD_OPEN_PORT, 0);
885 939
886 if (response < 0) { 940 if (response < 0) {
887 dev_err(&port->dev, "%s - error sending open port command\n", __func__); 941 dev_err(&port->dev, "%s - error sending open port command\n",
942 __func__);
888 edge_port->openPending = false; 943 edge_port->openPending = false;
889 return -ENODEV; 944 return -ENODEV;
890 } 945 }
891 946
892 /* now wait for the port to be completely opened */ 947 /* now wait for the port to be completely opened */
893 wait_event_timeout(edge_port->wait_open, !edge_port->openPending, OPEN_TIMEOUT); 948 wait_event_timeout(edge_port->wait_open, !edge_port->openPending,
949 OPEN_TIMEOUT);
894 950
895 if (!edge_port->open) { 951 if (!edge_port->open) {
896 /* open timed out */ 952 /* open timed out */
@@ -904,25 +960,26 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
904 edge_port->txfifo.tail = 0; 960 edge_port->txfifo.tail = 0;
905 edge_port->txfifo.count = 0; 961 edge_port->txfifo.count = 0;
906 edge_port->txfifo.size = edge_port->maxTxCredits; 962 edge_port->txfifo.size = edge_port->maxTxCredits;
907 edge_port->txfifo.fifo = kmalloc (edge_port->maxTxCredits, GFP_KERNEL); 963 edge_port->txfifo.fifo = kmalloc(edge_port->maxTxCredits, GFP_KERNEL);
908 964
909 if (!edge_port->txfifo.fifo) { 965 if (!edge_port->txfifo.fifo) {
910 dbg("%s - no memory", __func__); 966 dbg("%s - no memory", __func__);
911 edge_close (port, filp); 967 edge_close(tty, port, filp);
912 return -ENOMEM; 968 return -ENOMEM;
913 } 969 }
914 970
915 /* Allocate a URB for the write */ 971 /* Allocate a URB for the write */
916 edge_port->write_urb = usb_alloc_urb (0, GFP_KERNEL); 972 edge_port->write_urb = usb_alloc_urb(0, GFP_KERNEL);
917 edge_port->write_in_progress = false; 973 edge_port->write_in_progress = false;
918 974
919 if (!edge_port->write_urb) { 975 if (!edge_port->write_urb) {
920 dbg("%s - no memory", __func__); 976 dbg("%s - no memory", __func__);
921 edge_close (port, filp); 977 edge_close(tty, port, filp);
922 return -ENOMEM; 978 return -ENOMEM;
923 } 979 }
924 980
925 dbg("%s(%d) - Initialize TX fifo to %d bytes", __func__, port->number, edge_port->maxTxCredits); 981 dbg("%s(%d) - Initialize TX fifo to %d bytes",
982 __func__, port->number, edge_port->maxTxCredits);
926 983
927 dbg("%s exited", __func__); 984 dbg("%s exited", __func__);
928 985
@@ -948,27 +1005,28 @@ static void block_until_chase_response(struct edgeport_port *edge_port)
948 int loop = 10; 1005 int loop = 10;
949 1006
950 while (1) { 1007 while (1) {
951 // Save Last credits 1008 /* Save Last credits */
952 lastCredits = edge_port->txCredits; 1009 lastCredits = edge_port->txCredits;
953 1010
954 // Did we get our Chase response 1011 /* Did we get our Chase response */
955 if (!edge_port->chaseResponsePending) { 1012 if (!edge_port->chaseResponsePending) {
956 dbg("%s - Got Chase Response", __func__); 1013 dbg("%s - Got Chase Response", __func__);
957 1014
958 // did we get all of our credit back? 1015 /* did we get all of our credit back? */
959 if (edge_port->txCredits == edge_port->maxTxCredits ) { 1016 if (edge_port->txCredits == edge_port->maxTxCredits) {
960 dbg("%s - Got all credits", __func__); 1017 dbg("%s - Got all credits", __func__);
961 return; 1018 return;
962 } 1019 }
963 } 1020 }
964 1021
965 // Block the thread for a while 1022 /* Block the thread for a while */
966 prepare_to_wait(&edge_port->wait_chase, &wait, TASK_UNINTERRUPTIBLE); 1023 prepare_to_wait(&edge_port->wait_chase, &wait,
1024 TASK_UNINTERRUPTIBLE);
967 schedule_timeout(timeout); 1025 schedule_timeout(timeout);
968 finish_wait(&edge_port->wait_chase, &wait); 1026 finish_wait(&edge_port->wait_chase, &wait);
969 1027
970 if (lastCredits == edge_port->txCredits) { 1028 if (lastCredits == edge_port->txCredits) {
971 // No activity.. count down. 1029 /* No activity.. count down. */
972 loop--; 1030 loop--;
973 if (loop == 0) { 1031 if (loop == 0) {
974 edge_port->chaseResponsePending = false; 1032 edge_port->chaseResponsePending = false;
@@ -976,8 +1034,9 @@ static void block_until_chase_response(struct edgeport_port *edge_port)
976 return; 1034 return;
977 } 1035 }
978 } else { 1036 } else {
979 // Reset timeout value back to 10 seconds 1037 /* Reset timeout value back to 10 seconds */
980 dbg("%s - Last %d, Current %d", __func__, lastCredits, edge_port->txCredits); 1038 dbg("%s - Last %d, Current %d", __func__,
1039 lastCredits, edge_port->txCredits);
981 loop = 10; 1040 loop = 10;
982 } 1041 }
983 } 1042 }
@@ -994,7 +1053,7 @@ static void block_until_chase_response(struct edgeport_port *edge_port)
994 * 3. A timeout of 3 seconds without activity has expired 1053 * 3. A timeout of 3 seconds without activity has expired
995 * 1054 *
996 ************************************************************************/ 1055 ************************************************************************/
997static void block_until_tx_empty (struct edgeport_port *edge_port) 1056static void block_until_tx_empty(struct edgeport_port *edge_port)
998{ 1057{
999 DEFINE_WAIT(wait); 1058 DEFINE_WAIT(wait);
1000 struct TxFifo *fifo = &edge_port->txfifo; 1059 struct TxFifo *fifo = &edge_port->txfifo;
@@ -1003,31 +1062,32 @@ static void block_until_tx_empty (struct edgeport_port *edge_port)
1003 int loop = 30; 1062 int loop = 30;
1004 1063
1005 while (1) { 1064 while (1) {
1006 // Save Last count 1065 /* Save Last count */
1007 lastCount = fifo->count; 1066 lastCount = fifo->count;
1008 1067
1009 // Is the Edgeport Buffer empty? 1068 /* Is the Edgeport Buffer empty? */
1010 if (lastCount == 0) { 1069 if (lastCount == 0) {
1011 dbg("%s - TX Buffer Empty", __func__); 1070 dbg("%s - TX Buffer Empty", __func__);
1012 return; 1071 return;
1013 } 1072 }
1014 1073
1015 // Block the thread for a while 1074 /* Block the thread for a while */
1016 prepare_to_wait (&edge_port->wait_chase, &wait, TASK_UNINTERRUPTIBLE); 1075 prepare_to_wait(&edge_port->wait_chase, &wait,
1076 TASK_UNINTERRUPTIBLE);
1017 schedule_timeout(timeout); 1077 schedule_timeout(timeout);
1018 finish_wait(&edge_port->wait_chase, &wait); 1078 finish_wait(&edge_port->wait_chase, &wait);
1019 1079
1020 dbg("%s wait", __func__); 1080 dbg("%s wait", __func__);
1021 1081
1022 if (lastCount == fifo->count) { 1082 if (lastCount == fifo->count) {
1023 // No activity.. count down. 1083 /* No activity.. count down. */
1024 loop--; 1084 loop--;
1025 if (loop == 0) { 1085 if (loop == 0) {
1026 dbg("%s - TIMEOUT", __func__); 1086 dbg("%s - TIMEOUT", __func__);
1027 return; 1087 return;
1028 } 1088 }
1029 } else { 1089 } else {
1030 // Reset timeout value back to seconds 1090 /* Reset timeout value back to seconds */
1031 loop = 30; 1091 loop = 30;
1032 } 1092 }
1033 } 1093 }
@@ -1038,20 +1098,21 @@ static void block_until_tx_empty (struct edgeport_port *edge_port)
1038 * edge_close 1098 * edge_close
1039 * this function is called by the tty driver when a port is closed 1099 * this function is called by the tty driver when a port is closed
1040 *****************************************************************************/ 1100 *****************************************************************************/
1041static void edge_close (struct usb_serial_port *port, struct file * filp) 1101static void edge_close(struct tty_struct *tty,
1102 struct usb_serial_port *port, struct file *filp)
1042{ 1103{
1043 struct edgeport_serial *edge_serial; 1104 struct edgeport_serial *edge_serial;
1044 struct edgeport_port *edge_port; 1105 struct edgeport_port *edge_port;
1045 int status; 1106 int status;
1046 1107
1047 dbg("%s - port %d", __func__, port->number); 1108 dbg("%s - port %d", __func__, port->number);
1048 1109
1049 edge_serial = usb_get_serial_data(port->serial); 1110 edge_serial = usb_get_serial_data(port->serial);
1050 edge_port = usb_get_serial_port_data(port); 1111 edge_port = usb_get_serial_port_data(port);
1051 if ((edge_serial == NULL) || (edge_port == NULL)) 1112 if (edge_serial == NULL || edge_port == NULL)
1052 return; 1113 return;
1053 1114
1054 // block until tx is empty 1115 /* block until tx is empty */
1055 block_until_tx_empty(edge_port); 1116 block_until_tx_empty(edge_port);
1056 1117
1057 edge_port->closePending = true; 1118 edge_port->closePending = true;
@@ -1063,13 +1124,12 @@ static void edge_close (struct usb_serial_port *port, struct file * filp)
1063 edge_port->chaseResponsePending = true; 1124 edge_port->chaseResponsePending = true;
1064 1125
1065 dbg("%s - Sending IOSP_CMD_CHASE_PORT", __func__); 1126 dbg("%s - Sending IOSP_CMD_CHASE_PORT", __func__);
1066 status = send_iosp_ext_cmd (edge_port, IOSP_CMD_CHASE_PORT, 0); 1127 status = send_iosp_ext_cmd(edge_port, IOSP_CMD_CHASE_PORT, 0);
1067 if (status == 0) { 1128 if (status == 0)
1068 // block until chase finished 1129 /* block until chase finished */
1069 block_until_chase_response(edge_port); 1130 block_until_chase_response(edge_port);
1070 } else { 1131 else
1071 edge_port->chaseResponsePending = false; 1132 edge_port->chaseResponsePending = false;
1072 }
1073 } 1133 }
1074 1134
1075 if ((!edge_serial->is_epic) || 1135 if ((!edge_serial->is_epic) ||
@@ -1077,10 +1137,10 @@ static void edge_close (struct usb_serial_port *port, struct file * filp)
1077 (edge_serial->epic_descriptor.Supports.IOSPClose))) { 1137 (edge_serial->epic_descriptor.Supports.IOSPClose))) {
1078 /* close the port */ 1138 /* close the port */
1079 dbg("%s - Sending IOSP_CMD_CLOSE_PORT", __func__); 1139 dbg("%s - Sending IOSP_CMD_CLOSE_PORT", __func__);
1080 send_iosp_ext_cmd (edge_port, IOSP_CMD_CLOSE_PORT, 0); 1140 send_iosp_ext_cmd(edge_port, IOSP_CMD_CLOSE_PORT, 0);
1081 } 1141 }
1082 1142
1083 //port->close = true; 1143 /* port->close = true; */
1084 edge_port->closePending = false; 1144 edge_port->closePending = false;
1085 edge_port->open = false; 1145 edge_port->open = false;
1086 edge_port->openPending = false; 1146 edge_port->openPending = false;
@@ -1088,7 +1148,8 @@ static void edge_close (struct usb_serial_port *port, struct file * filp)
1088 usb_kill_urb(edge_port->write_urb); 1148 usb_kill_urb(edge_port->write_urb);
1089 1149
1090 if (edge_port->write_urb) { 1150 if (edge_port->write_urb) {
1091 /* if this urb had a transfer buffer already (old transfer) free it */ 1151 /* if this urb had a transfer buffer already
1152 (old transfer) free it */
1092 kfree(edge_port->write_urb->transfer_buffer); 1153 kfree(edge_port->write_urb->transfer_buffer);
1093 usb_free_urb(edge_port->write_urb); 1154 usb_free_urb(edge_port->write_urb);
1094 edge_port->write_urb = NULL; 1155 edge_port->write_urb = NULL;
@@ -1097,16 +1158,17 @@ static void edge_close (struct usb_serial_port *port, struct file * filp)
1097 edge_port->txfifo.fifo = NULL; 1158 edge_port->txfifo.fifo = NULL;
1098 1159
1099 dbg("%s exited", __func__); 1160 dbg("%s exited", __func__);
1100} 1161}
1101 1162
1102/***************************************************************************** 1163/*****************************************************************************
1103 * SerialWrite 1164 * SerialWrite
1104 * this function is called by the tty driver when data should be written to 1165 * this function is called by the tty driver when data should be written
1105 * the port. 1166 * to the port.
1106 * If successful, we return the number of bytes written, otherwise we return 1167 * If successful, we return the number of bytes written, otherwise we
1107 * a negative error number. 1168 * return a negative error number.
1108 *****************************************************************************/ 1169 *****************************************************************************/
1109static int edge_write (struct usb_serial_port *port, const unsigned char *data, int count) 1170static int edge_write(struct tty_struct *tty, struct usb_serial_port *port,
1171 const unsigned char *data, int count)
1110{ 1172{
1111 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1173 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1112 struct TxFifo *fifo; 1174 struct TxFifo *fifo;
@@ -1121,66 +1183,76 @@ static int edge_write (struct usb_serial_port *port, const unsigned char *data,
1121 if (edge_port == NULL) 1183 if (edge_port == NULL)
1122 return -ENODEV; 1184 return -ENODEV;
1123 1185
1124 // get a pointer to the Tx fifo 1186 /* get a pointer to the Tx fifo */
1125 fifo = &edge_port->txfifo; 1187 fifo = &edge_port->txfifo;
1126 1188
1127 spin_lock_irqsave(&edge_port->ep_lock, flags); 1189 spin_lock_irqsave(&edge_port->ep_lock, flags);
1128 1190
1129 // calculate number of bytes to put in fifo 1191 /* calculate number of bytes to put in fifo */
1130 copySize = min ((unsigned int)count, (edge_port->txCredits - fifo->count)); 1192 copySize = min((unsigned int)count,
1193 (edge_port->txCredits - fifo->count));
1131 1194
1132 dbg("%s(%d) of %d byte(s) Fifo room %d -- will copy %d bytes", __func__, 1195 dbg("%s(%d) of %d byte(s) Fifo room %d -- will copy %d bytes",
1133 port->number, count, edge_port->txCredits - fifo->count, copySize); 1196 __func__, port->number, count,
1197 edge_port->txCredits - fifo->count, copySize);
1134 1198
1135 /* catch writes of 0 bytes which the tty driver likes to give us, and when txCredits is empty */ 1199 /* catch writes of 0 bytes which the tty driver likes to give us,
1200 and when txCredits is empty */
1136 if (copySize == 0) { 1201 if (copySize == 0) {
1137 dbg("%s - copySize = Zero", __func__); 1202 dbg("%s - copySize = Zero", __func__);
1138 goto finish_write; 1203 goto finish_write;
1139 } 1204 }
1140 1205
1141 // queue the data 1206 /* queue the data
1142 // since we can never overflow the buffer we do not have to check for full condition 1207 * since we can never overflow the buffer we do not have to check for a
1143 1208 * full condition
1144 // the copy is done is two parts -- first fill to the end of the buffer 1209 *
1145 // then copy the reset from the start of the buffer 1210 * the copy is done is two parts -- first fill to the end of the buffer
1146 1211 * then copy the reset from the start of the buffer
1212 */
1147 bytesleft = fifo->size - fifo->head; 1213 bytesleft = fifo->size - fifo->head;
1148 firsthalf = min (bytesleft, copySize); 1214 firsthalf = min(bytesleft, copySize);
1149 dbg("%s - copy %d bytes of %d into fifo ", __func__, firsthalf, bytesleft); 1215 dbg("%s - copy %d bytes of %d into fifo ", __func__,
1216 firsthalf, bytesleft);
1150 1217
1151 /* now copy our data */ 1218 /* now copy our data */
1152 memcpy(&fifo->fifo[fifo->head], data, firsthalf); 1219 memcpy(&fifo->fifo[fifo->head], data, firsthalf);
1153 usb_serial_debug_data(debug, &port->dev, __func__, firsthalf, &fifo->fifo[fifo->head]); 1220 usb_serial_debug_data(debug, &port->dev, __func__,
1221 firsthalf, &fifo->fifo[fifo->head]);
1154 1222
1155 // update the index and size 1223 /* update the index and size */
1156 fifo->head += firsthalf; 1224 fifo->head += firsthalf;
1157 fifo->count += firsthalf; 1225 fifo->count += firsthalf;
1158 1226
1159 // wrap the index 1227 /* wrap the index */
1160 if (fifo->head == fifo->size) { 1228 if (fifo->head == fifo->size)
1161 fifo->head = 0; 1229 fifo->head = 0;
1162 }
1163 1230
1164 secondhalf = copySize-firsthalf; 1231 secondhalf = copySize-firsthalf;
1165 1232
1166 if (secondhalf) { 1233 if (secondhalf) {
1167 dbg("%s - copy rest of data %d", __func__, secondhalf); 1234 dbg("%s - copy rest of data %d", __func__, secondhalf);
1168 memcpy(&fifo->fifo[fifo->head], &data[firsthalf], secondhalf); 1235 memcpy(&fifo->fifo[fifo->head], &data[firsthalf], secondhalf);
1169 usb_serial_debug_data(debug, &port->dev, __func__, secondhalf, &fifo->fifo[fifo->head]); 1236 usb_serial_debug_data(debug, &port->dev, __func__,
1170 // update the index and size 1237 secondhalf, &fifo->fifo[fifo->head]);
1238 /* update the index and size */
1171 fifo->count += secondhalf; 1239 fifo->count += secondhalf;
1172 fifo->head += secondhalf; 1240 fifo->head += secondhalf;
1173 // No need to check for wrap since we can not get to end of fifo in this part 1241 /* No need to check for wrap since we can not get to end of
1242 * the fifo in this part
1243 */
1174 } 1244 }
1175 1245
1176finish_write: 1246finish_write:
1177 spin_unlock_irqrestore(&edge_port->ep_lock, flags); 1247 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
1178 1248
1179 send_more_port_data((struct edgeport_serial *)usb_get_serial_data(port->serial), edge_port); 1249 send_more_port_data((struct edgeport_serial *)
1250 usb_get_serial_data(port->serial), edge_port);
1180 1251
1181 dbg("%s wrote %d byte(s) TxCredits %d, Fifo %d", __func__, copySize, edge_port->txCredits, fifo->count); 1252 dbg("%s wrote %d byte(s) TxCredits %d, Fifo %d", __func__,
1253 copySize, edge_port->txCredits, fifo->count);
1182 1254
1183 return copySize; 1255 return copySize;
1184} 1256}
1185 1257
1186 1258
@@ -1197,7 +1269,8 @@ finish_write:
1197 * can transmit more. 1269 * can transmit more.
1198 * 1270 *
1199 ************************************************************************/ 1271 ************************************************************************/
1200static void send_more_port_data(struct edgeport_serial *edge_serial, struct edgeport_port *edge_port) 1272static void send_more_port_data(struct edgeport_serial *edge_serial,
1273 struct edgeport_port *edge_port)
1201{ 1274{
1202 struct TxFifo *fifo = &edge_port->txfifo; 1275 struct TxFifo *fifo = &edge_port->txfifo;
1203 struct urb *urb; 1276 struct urb *urb;
@@ -1216,67 +1289,78 @@ static void send_more_port_data(struct edgeport_serial *edge_serial, struct edge
1216 if (edge_port->write_in_progress || 1289 if (edge_port->write_in_progress ||
1217 !edge_port->open || 1290 !edge_port->open ||
1218 (fifo->count == 0)) { 1291 (fifo->count == 0)) {
1219 dbg("%s(%d) EXIT - fifo %d, PendingWrite = %d", __func__, edge_port->port->number, fifo->count, edge_port->write_in_progress); 1292 dbg("%s(%d) EXIT - fifo %d, PendingWrite = %d",
1293 __func__, edge_port->port->number,
1294 fifo->count, edge_port->write_in_progress);
1220 goto exit_send; 1295 goto exit_send;
1221 } 1296 }
1222 1297
1223 // since the amount of data in the fifo will always fit into the 1298 /* since the amount of data in the fifo will always fit into the
1224 // edgeport buffer we do not need to check the write length 1299 * edgeport buffer we do not need to check the write length
1225 1300 *
1226 // Do we have enough credits for this port to make it worthwhile 1301 * Do we have enough credits for this port to make it worthwhile
1227 // to bother queueing a write. If it's too small, say a few bytes, 1302 * to bother queueing a write. If it's too small, say a few bytes,
1228 // it's better to wait for more credits so we can do a larger 1303 * it's better to wait for more credits so we can do a larger write.
1229 // write. 1304 */
1230 if (edge_port->txCredits < EDGE_FW_GET_TX_CREDITS_SEND_THRESHOLD(edge_port->maxTxCredits,EDGE_FW_BULK_MAX_PACKET_SIZE)) { 1305 if (edge_port->txCredits < EDGE_FW_GET_TX_CREDITS_SEND_THRESHOLD(edge_port->maxTxCredits, EDGE_FW_BULK_MAX_PACKET_SIZE)) {
1231 dbg("%s(%d) Not enough credit - fifo %d TxCredit %d", __func__, edge_port->port->number, fifo->count, edge_port->txCredits ); 1306 dbg("%s(%d) Not enough credit - fifo %d TxCredit %d",
1307 __func__, edge_port->port->number, fifo->count,
1308 edge_port->txCredits);
1232 goto exit_send; 1309 goto exit_send;
1233 } 1310 }
1234 1311
1235 // lock this write 1312 /* lock this write */
1236 edge_port->write_in_progress = true; 1313 edge_port->write_in_progress = true;
1237 1314
1238 // get a pointer to the write_urb 1315 /* get a pointer to the write_urb */
1239 urb = edge_port->write_urb; 1316 urb = edge_port->write_urb;
1240 1317
1241 /* make sure transfer buffer is freed */ 1318 /* make sure transfer buffer is freed */
1242 kfree(urb->transfer_buffer); 1319 kfree(urb->transfer_buffer);
1243 urb->transfer_buffer = NULL; 1320 urb->transfer_buffer = NULL;
1244 1321
1245 /* build the data header for the buffer and port that we are about to send out */ 1322 /* build the data header for the buffer and port that we are about
1323 to send out */
1246 count = fifo->count; 1324 count = fifo->count;
1247 buffer = kmalloc (count+2, GFP_ATOMIC); 1325 buffer = kmalloc(count+2, GFP_ATOMIC);
1248 if (buffer == NULL) { 1326 if (buffer == NULL) {
1249 dev_err(&edge_port->port->dev, "%s - no more kernel memory...\n", __func__); 1327 dev_err(&edge_port->port->dev,
1328 "%s - no more kernel memory...\n", __func__);
1250 edge_port->write_in_progress = false; 1329 edge_port->write_in_progress = false;
1251 goto exit_send; 1330 goto exit_send;
1252 } 1331 }
1253 buffer[0] = IOSP_BUILD_DATA_HDR1 (edge_port->port->number - edge_port->port->serial->minor, count); 1332 buffer[0] = IOSP_BUILD_DATA_HDR1(edge_port->port->number
1254 buffer[1] = IOSP_BUILD_DATA_HDR2 (edge_port->port->number - edge_port->port->serial->minor, count); 1333 - edge_port->port->serial->minor, count);
1334 buffer[1] = IOSP_BUILD_DATA_HDR2(edge_port->port->number
1335 - edge_port->port->serial->minor, count);
1255 1336
1256 /* now copy our data */ 1337 /* now copy our data */
1257 bytesleft = fifo->size - fifo->tail; 1338 bytesleft = fifo->size - fifo->tail;
1258 firsthalf = min (bytesleft, count); 1339 firsthalf = min(bytesleft, count);
1259 memcpy(&buffer[2], &fifo->fifo[fifo->tail], firsthalf); 1340 memcpy(&buffer[2], &fifo->fifo[fifo->tail], firsthalf);
1260 fifo->tail += firsthalf; 1341 fifo->tail += firsthalf;
1261 fifo->count -= firsthalf; 1342 fifo->count -= firsthalf;
1262 if (fifo->tail == fifo->size) { 1343 if (fifo->tail == fifo->size)
1263 fifo->tail = 0; 1344 fifo->tail = 0;
1264 }
1265 1345
1266 secondhalf = count-firsthalf; 1346 secondhalf = count-firsthalf;
1267 if (secondhalf) { 1347 if (secondhalf) {
1268 memcpy(&buffer[2+firsthalf], &fifo->fifo[fifo->tail], secondhalf); 1348 memcpy(&buffer[2+firsthalf], &fifo->fifo[fifo->tail],
1349 secondhalf);
1269 fifo->tail += secondhalf; 1350 fifo->tail += secondhalf;
1270 fifo->count -= secondhalf; 1351 fifo->count -= secondhalf;
1271 } 1352 }
1272 1353
1273 if (count) 1354 if (count)
1274 usb_serial_debug_data(debug, &edge_port->port->dev, __func__, count, &buffer[2]); 1355 usb_serial_debug_data(debug, &edge_port->port->dev,
1356 __func__, count, &buffer[2]);
1275 1357
1276 /* fill up the urb with all of our data and submit it */ 1358 /* fill up the urb with all of our data and submit it */
1277 usb_fill_bulk_urb (urb, edge_serial->serial->dev, 1359 usb_fill_bulk_urb(urb, edge_serial->serial->dev,
1278 usb_sndbulkpipe(edge_serial->serial->dev, edge_serial->bulk_out_endpoint), 1360 usb_sndbulkpipe(edge_serial->serial->dev,
1279 buffer, count+2, edge_bulk_out_data_callback, edge_port); 1361 edge_serial->bulk_out_endpoint),
1362 buffer, count+2,
1363 edge_bulk_out_data_callback, edge_port);
1280 1364
1281 /* decrement the number of credits we have by the number we just sent */ 1365 /* decrement the number of credits we have by the number we just sent */
1282 edge_port->txCredits -= count; 1366 edge_port->txCredits -= count;
@@ -1286,14 +1370,17 @@ static void send_more_port_data(struct edgeport_serial *edge_serial, struct edge
1286 status = usb_submit_urb(urb, GFP_ATOMIC); 1370 status = usb_submit_urb(urb, GFP_ATOMIC);
1287 if (status) { 1371 if (status) {
1288 /* something went wrong */ 1372 /* something went wrong */
1289 dev_err(&edge_port->port->dev, "%s - usb_submit_urb(write bulk) failed, status = %d, data lost\n", __func__, status); 1373 dev_err(&edge_port->port->dev,
1374 "%s - usb_submit_urb(write bulk) failed, status = %d, data lost\n",
1375 __func__, status);
1290 edge_port->write_in_progress = false; 1376 edge_port->write_in_progress = false;
1291 1377
1292 /* revert the credits as something bad happened. */ 1378 /* revert the credits as something bad happened. */
1293 edge_port->txCredits += count; 1379 edge_port->txCredits += count;
1294 edge_port->icount.tx -= count; 1380 edge_port->icount.tx -= count;
1295 } 1381 }
1296 dbg("%s wrote %d byte(s) TxCredit %d, Fifo %d", __func__, count, edge_port->txCredits, fifo->count); 1382 dbg("%s wrote %d byte(s) TxCredit %d, Fifo %d",
1383 __func__, count, edge_port->txCredits, fifo->count);
1297 1384
1298exit_send: 1385exit_send:
1299 spin_unlock_irqrestore(&edge_port->ep_lock, flags); 1386 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
@@ -1302,14 +1389,14 @@ exit_send:
1302 1389
1303/***************************************************************************** 1390/*****************************************************************************
1304 * edge_write_room 1391 * edge_write_room
1305 * this function is called by the tty driver when it wants to know how many 1392 * this function is called by the tty driver when it wants to know how
1306 * bytes of data we can accept for a specific port. 1393 * many bytes of data we can accept for a specific port. If successful,
1307 * If successful, we return the amount of room that we have for this port 1394 * we return the amount of room that we have for this port (the txCredits)
1308 * (the txCredits), 1395 * otherwise we return a negative error number.
1309 * Otherwise we return a negative error number.
1310 *****************************************************************************/ 1396 *****************************************************************************/
1311static int edge_write_room (struct usb_serial_port *port) 1397static int edge_write_room(struct tty_struct *tty)
1312{ 1398{
1399 struct usb_serial_port *port = tty->driver_data;
1313 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1400 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1314 int room; 1401 int room;
1315 unsigned long flags; 1402 unsigned long flags;
@@ -1317,18 +1404,18 @@ static int edge_write_room (struct usb_serial_port *port)
1317 dbg("%s", __func__); 1404 dbg("%s", __func__);
1318 1405
1319 if (edge_port == NULL) 1406 if (edge_port == NULL)
1320 return -ENODEV; 1407 return 0;
1321 if (edge_port->closePending) 1408 if (edge_port->closePending)
1322 return -ENODEV; 1409 return 0;
1323 1410
1324 dbg("%s - port %d", __func__, port->number); 1411 dbg("%s - port %d", __func__, port->number);
1325 1412
1326 if (!edge_port->open) { 1413 if (!edge_port->open) {
1327 dbg("%s - port not opened", __func__); 1414 dbg("%s - port not opened", __func__);
1328 return -EINVAL; 1415 return 0;
1329 } 1416 }
1330 1417
1331 // total of both buffers is still txCredit 1418 /* total of both buffers is still txCredit */
1332 spin_lock_irqsave(&edge_port->ep_lock, flags); 1419 spin_lock_irqsave(&edge_port->ep_lock, flags);
1333 room = edge_port->txCredits - edge_port->txfifo.count; 1420 room = edge_port->txCredits - edge_port->txfifo.count;
1334 spin_unlock_irqrestore(&edge_port->ep_lock, flags); 1421 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
@@ -1340,15 +1427,16 @@ static int edge_write_room (struct usb_serial_port *port)
1340 1427
1341/***************************************************************************** 1428/*****************************************************************************
1342 * edge_chars_in_buffer 1429 * edge_chars_in_buffer
1343 * this function is called by the tty driver when it wants to know how many 1430 * this function is called by the tty driver when it wants to know how
1344 * bytes of data we currently have outstanding in the port (data that has 1431 * many bytes of data we currently have outstanding in the port (data that
1345 * been written, but hasn't made it out the port yet) 1432 * has been written, but hasn't made it out the port yet)
1346 * If successful, we return the number of bytes left to be written in the 1433 * If successful, we return the number of bytes left to be written in the
1347 * system, 1434 * system,
1348 * Otherwise we return a negative error number. 1435 * Otherwise we return a negative error number.
1349 *****************************************************************************/ 1436 *****************************************************************************/
1350static int edge_chars_in_buffer (struct usb_serial_port *port) 1437static int edge_chars_in_buffer(struct tty_struct *tty)
1351{ 1438{
1439 struct usb_serial_port *port = tty->driver_data;
1352 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1440 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1353 int num_chars; 1441 int num_chars;
1354 unsigned long flags; 1442 unsigned long flags;
@@ -1356,20 +1444,22 @@ static int edge_chars_in_buffer (struct usb_serial_port *port)
1356 dbg("%s", __func__); 1444 dbg("%s", __func__);
1357 1445
1358 if (edge_port == NULL) 1446 if (edge_port == NULL)
1359 return -ENODEV; 1447 return 0;
1360 if (edge_port->closePending) 1448 if (edge_port->closePending)
1361 return -ENODEV; 1449 return 0;
1362 1450
1363 if (!edge_port->open) { 1451 if (!edge_port->open) {
1364 dbg("%s - port not opened", __func__); 1452 dbg("%s - port not opened", __func__);
1365 return -EINVAL; 1453 return 0;
1366 } 1454 }
1367 1455
1368 spin_lock_irqsave(&edge_port->ep_lock, flags); 1456 spin_lock_irqsave(&edge_port->ep_lock, flags);
1369 num_chars = edge_port->maxTxCredits - edge_port->txCredits + edge_port->txfifo.count; 1457 num_chars = edge_port->maxTxCredits - edge_port->txCredits +
1458 edge_port->txfifo.count;
1370 spin_unlock_irqrestore(&edge_port->ep_lock, flags); 1459 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
1371 if (num_chars) { 1460 if (num_chars) {
1372 dbg("%s(port %d) - returns %d", __func__, port->number, num_chars); 1461 dbg("%s(port %d) - returns %d", __func__,
1462 port->number, num_chars);
1373 } 1463 }
1374 1464
1375 return num_chars; 1465 return num_chars;
@@ -1381,10 +1471,10 @@ static int edge_chars_in_buffer (struct usb_serial_port *port)
1381 * this function is called by the tty driver when it wants to stop the data 1471 * this function is called by the tty driver when it wants to stop the data
1382 * being read from the port. 1472 * being read from the port.
1383 *****************************************************************************/ 1473 *****************************************************************************/
1384static void edge_throttle (struct usb_serial_port *port) 1474static void edge_throttle(struct tty_struct *tty)
1385{ 1475{
1476 struct usb_serial_port *port = tty->driver_data;
1386 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1477 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1387 struct tty_struct *tty;
1388 int status; 1478 int status;
1389 1479
1390 dbg("%s - port %d", __func__, port->number); 1480 dbg("%s - port %d", __func__, port->number);
@@ -1397,28 +1487,21 @@ static void edge_throttle (struct usb_serial_port *port)
1397 return; 1487 return;
1398 } 1488 }
1399 1489
1400 tty = port->tty;
1401 if (!tty) {
1402 dbg ("%s - no tty available", __func__);
1403 return;
1404 }
1405
1406 /* if we are implementing XON/XOFF, send the stop character */ 1490 /* if we are implementing XON/XOFF, send the stop character */
1407 if (I_IXOFF(tty)) { 1491 if (I_IXOFF(tty)) {
1408 unsigned char stop_char = STOP_CHAR(tty); 1492 unsigned char stop_char = STOP_CHAR(tty);
1409 status = edge_write (port, &stop_char, 1); 1493 status = edge_write(tty, port, &stop_char, 1);
1410 if (status <= 0) { 1494 if (status <= 0)
1411 return; 1495 return;
1412 }
1413 } 1496 }
1414 1497
1415 /* if we are implementing RTS/CTS, toggle that line */ 1498 /* if we are implementing RTS/CTS, toggle that line */
1416 if (tty->termios->c_cflag & CRTSCTS) { 1499 if (tty->termios->c_cflag & CRTSCTS) {
1417 edge_port->shadowMCR &= ~MCR_RTS; 1500 edge_port->shadowMCR &= ~MCR_RTS;
1418 status = send_cmd_write_uart_register(edge_port, MCR, edge_port->shadowMCR); 1501 status = send_cmd_write_uart_register(edge_port, MCR,
1419 if (status != 0) { 1502 edge_port->shadowMCR);
1503 if (status != 0)
1420 return; 1504 return;
1421 }
1422 } 1505 }
1423 1506
1424 return; 1507 return;
@@ -1427,13 +1510,13 @@ static void edge_throttle (struct usb_serial_port *port)
1427 1510
1428/***************************************************************************** 1511/*****************************************************************************
1429 * edge_unthrottle 1512 * edge_unthrottle
1430 * this function is called by the tty driver when it wants to resume the data 1513 * this function is called by the tty driver when it wants to resume the
1431 * being read from the port (called after SerialThrottle is called) 1514 * data being read from the port (called after SerialThrottle is called)
1432 *****************************************************************************/ 1515 *****************************************************************************/
1433static void edge_unthrottle (struct usb_serial_port *port) 1516static void edge_unthrottle(struct tty_struct *tty)
1434{ 1517{
1518 struct usb_serial_port *port = tty->driver_data;
1435 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1519 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1436 struct tty_struct *tty;
1437 int status; 1520 int status;
1438 1521
1439 dbg("%s - port %d", __func__, port->number); 1522 dbg("%s - port %d", __func__, port->number);
@@ -1446,43 +1529,31 @@ static void edge_unthrottle (struct usb_serial_port *port)
1446 return; 1529 return;
1447 } 1530 }
1448 1531
1449 tty = port->tty;
1450 if (!tty) {
1451 dbg ("%s - no tty available", __func__);
1452 return;
1453 }
1454
1455 /* if we are implementing XON/XOFF, send the start character */ 1532 /* if we are implementing XON/XOFF, send the start character */
1456 if (I_IXOFF(tty)) { 1533 if (I_IXOFF(tty)) {
1457 unsigned char start_char = START_CHAR(tty); 1534 unsigned char start_char = START_CHAR(tty);
1458 status = edge_write (port, &start_char, 1); 1535 status = edge_write(tty, port, &start_char, 1);
1459 if (status <= 0) { 1536 if (status <= 0)
1460 return; 1537 return;
1461 }
1462 } 1538 }
1463
1464 /* if we are implementing RTS/CTS, toggle that line */ 1539 /* if we are implementing RTS/CTS, toggle that line */
1465 if (tty->termios->c_cflag & CRTSCTS) { 1540 if (tty->termios->c_cflag & CRTSCTS) {
1466 edge_port->shadowMCR |= MCR_RTS; 1541 edge_port->shadowMCR |= MCR_RTS;
1467 status = send_cmd_write_uart_register(edge_port, MCR, edge_port->shadowMCR); 1542 send_cmd_write_uart_register(edge_port, MCR,
1468 if (status != 0) { 1543 edge_port->shadowMCR);
1469 return;
1470 }
1471 } 1544 }
1472
1473 return;
1474} 1545}
1475 1546
1476 1547
1477/***************************************************************************** 1548/*****************************************************************************
1478 * SerialSetTermios 1549 * SerialSetTermios
1479 * this function is called by the tty driver when it wants to change the termios structure 1550 * this function is called by the tty driver when it wants to change
1551 * the termios structure
1480 *****************************************************************************/ 1552 *****************************************************************************/
1481static void edge_set_termios (struct usb_serial_port *port, struct ktermios *old_termios) 1553static void edge_set_termios(struct tty_struct *tty,
1554 struct usb_serial_port *port, struct ktermios *old_termios)
1482{ 1555{
1483 /* FIXME: This function appears unused ?? */
1484 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1556 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1485 struct tty_struct *tty = port->tty;
1486 unsigned int cflag; 1557 unsigned int cflag;
1487 1558
1488 cflag = tty->termios->c_cflag; 1559 cflag = tty->termios->c_cflag;
@@ -1502,9 +1573,7 @@ static void edge_set_termios (struct usb_serial_port *port, struct ktermios *old
1502 } 1573 }
1503 1574
1504 /* change the port settings to the new ones specified */ 1575 /* change the port settings to the new ones specified */
1505 change_port_settings (edge_port, old_termios); 1576 change_port_settings(tty, edge_port, old_termios);
1506
1507 return;
1508} 1577}
1509 1578
1510 1579
@@ -1516,9 +1585,10 @@ static void edge_set_termios (struct usb_serial_port *port, struct ktermios *old
1516 * release the bus after transmitting. This must be done when 1585 * release the bus after transmitting. This must be done when
1517 * the transmit shift register is empty, not be done when the 1586 * the transmit shift register is empty, not be done when the
1518 * transmit holding register is empty. This functionality 1587 * transmit holding register is empty. This functionality
1519 * allows an RS485 driver to be written in user space. 1588 * allows an RS485 driver to be written in user space.
1520 *****************************************************************************/ 1589 *****************************************************************************/
1521static int get_lsr_info(struct edgeport_port *edge_port, unsigned int __user *value) 1590static int get_lsr_info(struct edgeport_port *edge_port,
1591 unsigned int __user *value)
1522{ 1592{
1523 unsigned int result = 0; 1593 unsigned int result = 0;
1524 unsigned long flags; 1594 unsigned long flags;
@@ -1536,25 +1606,10 @@ static int get_lsr_info(struct edgeport_port *edge_port, unsigned int __user *va
1536 return 0; 1606 return 0;
1537} 1607}
1538 1608
1539static int get_number_bytes_avail(struct edgeport_port *edge_port, unsigned int __user *value) 1609static int edge_tiocmset(struct tty_struct *tty, struct file *file,
1540{ 1610 unsigned int set, unsigned int clear)
1541 unsigned int result = 0;
1542 struct tty_struct *tty = edge_port->port->tty;
1543
1544 if (!tty)
1545 return -ENOIOCTLCMD;
1546
1547 result = tty->read_cnt;
1548
1549 dbg("%s(%d) = %d", __func__, edge_port->port->number, result);
1550 if (copy_to_user(value, &result, sizeof(int)))
1551 return -EFAULT;
1552 //return 0;
1553 return -ENOIOCTLCMD;
1554}
1555
1556static int edge_tiocmset (struct usb_serial_port *port, struct file *file, unsigned int set, unsigned int clear)
1557{ 1611{
1612 struct usb_serial_port *port = tty->driver_data;
1558 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1613 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1559 unsigned int mcr; 1614 unsigned int mcr;
1560 1615
@@ -1582,8 +1637,9 @@ static int edge_tiocmset (struct usb_serial_port *port, struct file *file, unsig
1582 return 0; 1637 return 0;
1583} 1638}
1584 1639
1585static int edge_tiocmget(struct usb_serial_port *port, struct file *file) 1640static int edge_tiocmget(struct tty_struct *tty, struct file *file)
1586{ 1641{
1642 struct usb_serial_port *port = tty->driver_data;
1587 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1643 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1588 unsigned int result = 0; 1644 unsigned int result = 0;
1589 unsigned int msr; 1645 unsigned int msr;
@@ -1606,7 +1662,8 @@ static int edge_tiocmget(struct usb_serial_port *port, struct file *file)
1606 return result; 1662 return result;
1607} 1663}
1608 1664
1609static int get_serial_info(struct edgeport_port *edge_port, struct serial_struct __user *retinfo) 1665static int get_serial_info(struct edgeport_port *edge_port,
1666 struct serial_struct __user *retinfo)
1610{ 1667{
1611 struct serial_struct tmp; 1668 struct serial_struct tmp;
1612 1669
@@ -1624,9 +1681,6 @@ static int get_serial_info(struct edgeport_port *edge_port, struct serial_struct
1624 tmp.baud_base = 9600; 1681 tmp.baud_base = 9600;
1625 tmp.close_delay = 5*HZ; 1682 tmp.close_delay = 5*HZ;
1626 tmp.closing_wait = 30*HZ; 1683 tmp.closing_wait = 30*HZ;
1627// tmp.custom_divisor = state->custom_divisor;
1628// tmp.hub6 = state->hub6;
1629// tmp.io_type = state->io_type;
1630 1684
1631 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) 1685 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
1632 return -EFAULT; 1686 return -EFAULT;
@@ -1639,8 +1693,10 @@ static int get_serial_info(struct edgeport_port *edge_port, struct serial_struct
1639 * SerialIoctl 1693 * SerialIoctl
1640 * this function handles any ioctl calls to the driver 1694 * this function handles any ioctl calls to the driver
1641 *****************************************************************************/ 1695 *****************************************************************************/
1642static int edge_ioctl (struct usb_serial_port *port, struct file *file, unsigned int cmd, unsigned long arg) 1696static int edge_ioctl(struct tty_struct *tty, struct file *file,
1697 unsigned int cmd, unsigned long arg)
1643{ 1698{
1699 struct usb_serial_port *port = tty->driver_data;
1644 DEFINE_WAIT(wait); 1700 DEFINE_WAIT(wait);
1645 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1701 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1646 struct async_icount cnow; 1702 struct async_icount cnow;
@@ -1650,71 +1706,61 @@ static int edge_ioctl (struct usb_serial_port *port, struct file *file, unsigned
1650 dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd); 1706 dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd);
1651 1707
1652 switch (cmd) { 1708 switch (cmd) {
1653 // return number of bytes available 1709 case TIOCSERGETLSR:
1654 case TIOCINQ: 1710 dbg("%s (%d) TIOCSERGETLSR", __func__, port->number);
1655 dbg("%s (%d) TIOCINQ", __func__, port->number); 1711 return get_lsr_info(edge_port, (unsigned int __user *) arg);
1656 return get_number_bytes_avail(edge_port, (unsigned int __user *) arg); 1712
1657 break; 1713 case TIOCGSERIAL:
1658 1714 dbg("%s (%d) TIOCGSERIAL", __func__, port->number);
1659 case TIOCSERGETLSR: 1715 return get_serial_info(edge_port, (struct serial_struct __user *) arg);
1660 dbg("%s (%d) TIOCSERGETLSR", __func__, port->number); 1716
1661 return get_lsr_info(edge_port, (unsigned int __user *) arg); 1717 case TIOCMIWAIT:
1662 return 0; 1718 dbg("%s (%d) TIOCMIWAIT", __func__, port->number);
1663 1719 cprev = edge_port->icount;
1664 case TIOCGSERIAL: 1720 while (1) {
1665 dbg("%s (%d) TIOCGSERIAL", __func__, port->number); 1721 prepare_to_wait(&edge_port->delta_msr_wait,
1666 return get_serial_info(edge_port, (struct serial_struct __user *) arg); 1722 &wait, TASK_INTERRUPTIBLE);
1667 1723 schedule();
1668 case TIOCSSERIAL: 1724 finish_wait(&edge_port->delta_msr_wait, &wait);
1669 dbg("%s (%d) TIOCSSERIAL", __func__, port->number); 1725 /* see if a signal did it */
1670 break; 1726 if (signal_pending(current))
1671 1727 return -ERESTARTSYS;
1672 case TIOCMIWAIT: 1728 cnow = edge_port->icount;
1673 dbg("%s (%d) TIOCMIWAIT", __func__, port->number); 1729 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
1674 cprev = edge_port->icount; 1730 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
1675 while (1) { 1731 return -EIO; /* no change => error */
1676 prepare_to_wait(&edge_port->delta_msr_wait, &wait, TASK_INTERRUPTIBLE); 1732 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
1677 schedule(); 1733 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
1678 finish_wait(&edge_port->delta_msr_wait, &wait); 1734 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
1679 /* see if a signal did it */ 1735 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
1680 if (signal_pending(current)) 1736 return 0;
1681 return -ERESTARTSYS;
1682 cnow = edge_port->icount;
1683 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
1684 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
1685 return -EIO; /* no change => error */
1686 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
1687 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
1688 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
1689 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {
1690 return 0;
1691 }
1692 cprev = cnow;
1693 } 1737 }
1694 /* NOTREACHED */ 1738 cprev = cnow;
1695 break; 1739 }
1740 /* NOTREACHED */
1741 break;
1696 1742
1697 case TIOCGICOUNT: 1743 case TIOCGICOUNT:
1698 cnow = edge_port->icount; 1744 cnow = edge_port->icount;
1699 memset(&icount, 0, sizeof(icount)); 1745 memset(&icount, 0, sizeof(icount));
1700 icount.cts = cnow.cts; 1746 icount.cts = cnow.cts;
1701 icount.dsr = cnow.dsr; 1747 icount.dsr = cnow.dsr;
1702 icount.rng = cnow.rng; 1748 icount.rng = cnow.rng;
1703 icount.dcd = cnow.dcd; 1749 icount.dcd = cnow.dcd;
1704 icount.rx = cnow.rx; 1750 icount.rx = cnow.rx;
1705 icount.tx = cnow.tx; 1751 icount.tx = cnow.tx;
1706 icount.frame = cnow.frame; 1752 icount.frame = cnow.frame;
1707 icount.overrun = cnow.overrun; 1753 icount.overrun = cnow.overrun;
1708 icount.parity = cnow.parity; 1754 icount.parity = cnow.parity;
1709 icount.brk = cnow.brk; 1755 icount.brk = cnow.brk;
1710 icount.buf_overrun = cnow.buf_overrun; 1756 icount.buf_overrun = cnow.buf_overrun;
1711 1757
1712 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __func__, port->number, icount.rx, icount.tx ); 1758 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d",
1713 if (copy_to_user((void __user *)arg, &icount, sizeof(icount))) 1759 __func__, port->number, icount.rx, icount.tx);
1714 return -EFAULT; 1760 if (copy_to_user((void __user *)arg, &icount, sizeof(icount)))
1715 return 0; 1761 return -EFAULT;
1762 return 0;
1716 } 1763 }
1717
1718 return -ENOIOCTLCMD; 1764 return -ENOIOCTLCMD;
1719} 1765}
1720 1766
@@ -1723,8 +1769,9 @@ static int edge_ioctl (struct usb_serial_port *port, struct file *file, unsigned
1723 * SerialBreak 1769 * SerialBreak
1724 * this function sends a break to the port 1770 * this function sends a break to the port
1725 *****************************************************************************/ 1771 *****************************************************************************/
1726static void edge_break (struct usb_serial_port *port, int break_state) 1772static void edge_break(struct tty_struct *tty, int break_state)
1727{ 1773{
1774 struct usb_serial_port *port = tty->driver_data;
1728 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1775 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1729 struct edgeport_serial *edge_serial = usb_get_serial_data(port->serial); 1776 struct edgeport_serial *edge_serial = usb_get_serial_data(port->serial);
1730 int status; 1777 int status;
@@ -1736,9 +1783,9 @@ static void edge_break (struct usb_serial_port *port, int break_state)
1736 edge_port->chaseResponsePending = true; 1783 edge_port->chaseResponsePending = true;
1737 1784
1738 dbg("%s - Sending IOSP_CMD_CHASE_PORT", __func__); 1785 dbg("%s - Sending IOSP_CMD_CHASE_PORT", __func__);
1739 status = send_iosp_ext_cmd (edge_port, IOSP_CMD_CHASE_PORT, 0); 1786 status = send_iosp_ext_cmd(edge_port, IOSP_CMD_CHASE_PORT, 0);
1740 if (status == 0) { 1787 if (status == 0) {
1741 // block until chase finished 1788 /* block until chase finished */
1742 block_until_chase_response(edge_port); 1789 block_until_chase_response(edge_port);
1743 } else { 1790 } else {
1744 edge_port->chaseResponsePending = false; 1791 edge_port->chaseResponsePending = false;
@@ -1750,14 +1797,16 @@ static void edge_break (struct usb_serial_port *port, int break_state)
1750 (edge_serial->epic_descriptor.Supports.IOSPSetClrBreak))) { 1797 (edge_serial->epic_descriptor.Supports.IOSPSetClrBreak))) {
1751 if (break_state == -1) { 1798 if (break_state == -1) {
1752 dbg("%s - Sending IOSP_CMD_SET_BREAK", __func__); 1799 dbg("%s - Sending IOSP_CMD_SET_BREAK", __func__);
1753 status = send_iosp_ext_cmd (edge_port, IOSP_CMD_SET_BREAK, 0); 1800 status = send_iosp_ext_cmd(edge_port,
1801 IOSP_CMD_SET_BREAK, 0);
1754 } else { 1802 } else {
1755 dbg("%s - Sending IOSP_CMD_CLEAR_BREAK", __func__); 1803 dbg("%s - Sending IOSP_CMD_CLEAR_BREAK", __func__);
1756 status = send_iosp_ext_cmd (edge_port, IOSP_CMD_CLEAR_BREAK, 0); 1804 status = send_iosp_ext_cmd(edge_port,
1757 } 1805 IOSP_CMD_CLEAR_BREAK, 0);
1758 if (status) {
1759 dbg("%s - error sending break set/clear command.", __func__);
1760 } 1806 }
1807 if (status)
1808 dbg("%s - error sending break set/clear command.",
1809 __func__);
1761 } 1810 }
1762 1811
1763 return; 1812 return;
@@ -1768,7 +1817,8 @@ static void edge_break (struct usb_serial_port *port, int break_state)
1768 * process_rcvd_data 1817 * process_rcvd_data
1769 * this function handles the data received on the bulk in pipe. 1818 * this function handles the data received on the bulk in pipe.
1770 *****************************************************************************/ 1819 *****************************************************************************/
1771static void process_rcvd_data (struct edgeport_serial *edge_serial, unsigned char * buffer, __u16 bufferLength) 1820static void process_rcvd_data(struct edgeport_serial *edge_serial,
1821 unsigned char *buffer, __u16 bufferLength)
1772{ 1822{
1773 struct usb_serial_port *port; 1823 struct usb_serial_port *port;
1774 struct edgeport_port *edge_port; 1824 struct edgeport_port *edge_port;
@@ -1789,105 +1839,123 @@ static void process_rcvd_data (struct edgeport_serial *edge_serial, unsigned cha
1789 lastBufferLength = bufferLength; 1839 lastBufferLength = bufferLength;
1790 1840
1791 switch (edge_serial->rxState) { 1841 switch (edge_serial->rxState) {
1792 case EXPECT_HDR1: 1842 case EXPECT_HDR1:
1793 edge_serial->rxHeader1 = *buffer; 1843 edge_serial->rxHeader1 = *buffer;
1794 ++buffer; 1844 ++buffer;
1795 --bufferLength; 1845 --bufferLength;
1796 1846
1797 if (bufferLength == 0) { 1847 if (bufferLength == 0) {
1798 edge_serial->rxState = EXPECT_HDR2; 1848 edge_serial->rxState = EXPECT_HDR2;
1849 break;
1850 }
1851 /* otherwise, drop on through */
1852 case EXPECT_HDR2:
1853 edge_serial->rxHeader2 = *buffer;
1854 ++buffer;
1855 --bufferLength;
1856
1857 dbg("%s - Hdr1=%02X Hdr2=%02X", __func__,
1858 edge_serial->rxHeader1, edge_serial->rxHeader2);
1859 /* Process depending on whether this header is
1860 * data or status */
1861
1862 if (IS_CMD_STAT_HDR(edge_serial->rxHeader1)) {
1863 /* Decode this status header and go to
1864 * EXPECT_HDR1 (if we can process the status
1865 * with only 2 bytes), or go to EXPECT_HDR3 to
1866 * get the third byte. */
1867 edge_serial->rxPort =
1868 IOSP_GET_HDR_PORT(edge_serial->rxHeader1);
1869 edge_serial->rxStatusCode =
1870 IOSP_GET_STATUS_CODE(
1871 edge_serial->rxHeader1);
1872
1873 if (!IOSP_STATUS_IS_2BYTE(
1874 edge_serial->rxStatusCode)) {
1875 /* This status needs additional bytes.
1876 * Save what we have and then wait for
1877 * more data.
1878 */
1879 edge_serial->rxStatusParam
1880 = edge_serial->rxHeader2;
1881 edge_serial->rxState = EXPECT_HDR3;
1799 break; 1882 break;
1800 } 1883 }
1801 /* otherwise, drop on through */ 1884 /* We have all the header bytes, process the
1802 1885 status now */
1803 case EXPECT_HDR2: 1886 process_rcvd_status(edge_serial,
1804 edge_serial->rxHeader2 = *buffer; 1887 edge_serial->rxHeader2, 0);
1805 ++buffer; 1888 edge_serial->rxState = EXPECT_HDR1;
1806 --bufferLength; 1889 break;
1807 1890 } else {
1808 dbg("%s - Hdr1=%02X Hdr2=%02X", __func__, edge_serial->rxHeader1, edge_serial->rxHeader2); 1891 edge_serial->rxPort =
1809 1892 IOSP_GET_HDR_PORT(edge_serial->rxHeader1);
1810 // Process depending on whether this header is 1893 edge_serial->rxBytesRemaining =
1811 // data or status 1894 IOSP_GET_HDR_DATA_LEN(
1812 1895 edge_serial->rxHeader1,
1813 if (IS_CMD_STAT_HDR(edge_serial->rxHeader1)) { 1896 edge_serial->rxHeader2);
1814 // Decode this status header and goto EXPECT_HDR1 (if we 1897 dbg("%s - Data for Port %u Len %u",
1815 // can process the status with only 2 bytes), or goto 1898 __func__,
1816 // EXPECT_HDR3 to get the third byte. 1899 edge_serial->rxPort,
1817 1900 edge_serial->rxBytesRemaining);
1818 edge_serial->rxPort = IOSP_GET_HDR_PORT(edge_serial->rxHeader1); 1901
1819 edge_serial->rxStatusCode = IOSP_GET_STATUS_CODE(edge_serial->rxHeader1); 1902 /* ASSERT(DevExt->RxPort < DevExt->NumPorts);
1820 1903 * ASSERT(DevExt->RxBytesRemaining <
1821 if (!IOSP_STATUS_IS_2BYTE(edge_serial->rxStatusCode)) { 1904 * IOSP_MAX_DATA_LENGTH);
1822 // This status needs additional bytes. Save what we have 1905 */
1823 // and then wait for more data.
1824 edge_serial->rxStatusParam = edge_serial->rxHeader2;
1825
1826 edge_serial->rxState = EXPECT_HDR3;
1827 break;
1828 }
1829 1906
1830 // We have all the header bytes, process the status now 1907 if (bufferLength == 0) {
1831 process_rcvd_status (edge_serial, edge_serial->rxHeader2, 0); 1908 edge_serial->rxState = EXPECT_DATA;
1832 edge_serial->rxState = EXPECT_HDR1;
1833 break; 1909 break;
1834 } else {
1835 edge_serial->rxPort = IOSP_GET_HDR_PORT(edge_serial->rxHeader1);
1836 edge_serial->rxBytesRemaining = IOSP_GET_HDR_DATA_LEN(edge_serial->rxHeader1, edge_serial->rxHeader2);
1837
1838 dbg("%s - Data for Port %u Len %u", __func__, edge_serial->rxPort, edge_serial->rxBytesRemaining);
1839
1840 //ASSERT( DevExt->RxPort < DevExt->NumPorts );
1841 //ASSERT( DevExt->RxBytesRemaining < IOSP_MAX_DATA_LENGTH );
1842
1843 if (bufferLength == 0 ) {
1844 edge_serial->rxState = EXPECT_DATA;
1845 break;
1846 }
1847 // Else, drop through
1848 } 1910 }
1911 /* Else, drop through */
1912 }
1913 case EXPECT_DATA: /* Expect data */
1914 if (bufferLength < edge_serial->rxBytesRemaining) {
1915 rxLen = bufferLength;
1916 /* Expect data to start next buffer */
1917 edge_serial->rxState = EXPECT_DATA;
1918 } else {
1919 /* BufLen >= RxBytesRemaining */
1920 rxLen = edge_serial->rxBytesRemaining;
1921 /* Start another header next time */
1922 edge_serial->rxState = EXPECT_HDR1;
1923 }
1849 1924
1850 case EXPECT_DATA: // Expect data 1925 bufferLength -= rxLen;
1851 1926 edge_serial->rxBytesRemaining -= rxLen;
1852 if (bufferLength < edge_serial->rxBytesRemaining) {
1853 rxLen = bufferLength;
1854 edge_serial->rxState = EXPECT_DATA; // Expect data to start next buffer
1855 } else {
1856 // BufLen >= RxBytesRemaining
1857 rxLen = edge_serial->rxBytesRemaining;
1858 edge_serial->rxState = EXPECT_HDR1; // Start another header next time
1859 }
1860 1927
1861 bufferLength -= rxLen; 1928 /* spit this data back into the tty driver if this
1862 edge_serial->rxBytesRemaining -= rxLen; 1929 port is open */
1863 1930 if (rxLen) {
1864 /* spit this data back into the tty driver if this port is open */ 1931 port = edge_serial->serial->port[
1865 if (rxLen) { 1932 edge_serial->rxPort];
1866 port = edge_serial->serial->port[edge_serial->rxPort]; 1933 edge_port = usb_get_serial_port_data(port);
1867 edge_port = usb_get_serial_port_data(port); 1934 if (edge_port->open) {
1868 if (edge_port->open) { 1935 tty = edge_port->port->port.tty;
1869 tty = edge_port->port->tty; 1936 if (tty) {
1870 if (tty) { 1937 dbg("%s - Sending %d bytes to TTY for port %d",
1871 dbg("%s - Sending %d bytes to TTY for port %d", __func__, rxLen, edge_serial->rxPort); 1938 __func__, rxLen, edge_serial->rxPort);
1872 edge_tty_recv(&edge_serial->serial->dev->dev, tty, buffer, rxLen); 1939 edge_tty_recv(&edge_serial->serial->dev->dev, tty, buffer, rxLen);
1873 }
1874 edge_port->icount.rx += rxLen;
1875 } 1940 }
1876 buffer += rxLen; 1941 edge_port->icount.rx += rxLen;
1877 } 1942 }
1943 buffer += rxLen;
1944 }
1945 break;
1878 1946
1879 break; 1947 case EXPECT_HDR3: /* Expect 3rd byte of status header */
1880 1948 edge_serial->rxHeader3 = *buffer;
1881 case EXPECT_HDR3: // Expect 3rd byte of status header 1949 ++buffer;
1882 edge_serial->rxHeader3 = *buffer; 1950 --bufferLength;
1883 ++buffer; 1951
1884 --bufferLength; 1952 /* We have all the header bytes, process the
1885 1953 status now */
1886 // We have all the header bytes, process the status now 1954 process_rcvd_status(edge_serial,
1887 process_rcvd_status (edge_serial, edge_serial->rxStatusParam, edge_serial->rxHeader3); 1955 edge_serial->rxStatusParam,
1888 edge_serial->rxState = EXPECT_HDR1; 1956 edge_serial->rxHeader3);
1889 break; 1957 edge_serial->rxState = EXPECT_HDR1;
1890 1958 break;
1891 } 1959 }
1892 } 1960 }
1893} 1961}
@@ -1895,9 +1963,11 @@ static void process_rcvd_data (struct edgeport_serial *edge_serial, unsigned cha
1895 1963
1896/***************************************************************************** 1964/*****************************************************************************
1897 * process_rcvd_status 1965 * process_rcvd_status
1898 * this function handles the any status messages received on the bulk in pipe. 1966 * this function handles the any status messages received on the
1967 * bulk in pipe.
1899 *****************************************************************************/ 1968 *****************************************************************************/
1900static void process_rcvd_status (struct edgeport_serial *edge_serial, __u8 byte2, __u8 byte3) 1969static void process_rcvd_status(struct edgeport_serial *edge_serial,
1970 __u8 byte2, __u8 byte3)
1901{ 1971{
1902 struct usb_serial_port *port; 1972 struct usb_serial_port *port;
1903 struct edgeport_port *edge_port; 1973 struct edgeport_port *edge_port;
@@ -1907,7 +1977,9 @@ static void process_rcvd_status (struct edgeport_serial *edge_serial, __u8 byte2
1907 port = edge_serial->serial->port[edge_serial->rxPort]; 1977 port = edge_serial->serial->port[edge_serial->rxPort];
1908 edge_port = usb_get_serial_port_data(port); 1978 edge_port = usb_get_serial_port_data(port);
1909 if (edge_port == NULL) { 1979 if (edge_port == NULL) {
1910 dev_err(&edge_serial->serial->dev->dev, "%s - edge_port == NULL for port %d\n", __func__, edge_serial->rxPort); 1980 dev_err(&edge_serial->serial->dev->dev,
1981 "%s - edge_port == NULL for port %d\n",
1982 __func__, edge_serial->rxPort);
1911 return; 1983 return;
1912 } 1984 }
1913 1985
@@ -1915,22 +1987,28 @@ static void process_rcvd_status (struct edgeport_serial *edge_serial, __u8 byte2
1915 1987
1916 if (code == IOSP_EXT_STATUS) { 1988 if (code == IOSP_EXT_STATUS) {
1917 switch (byte2) { 1989 switch (byte2) {
1918 case IOSP_EXT_STATUS_CHASE_RSP: 1990 case IOSP_EXT_STATUS_CHASE_RSP:
1919 // we want to do EXT status regardless of port open/closed 1991 /* we want to do EXT status regardless of port
1920 dbg("%s - Port %u EXT CHASE_RSP Data = %02x", __func__, edge_serial->rxPort, byte3 ); 1992 * open/closed */
1921 // Currently, the only EXT_STATUS is Chase, so process here instead of one more call 1993 dbg("%s - Port %u EXT CHASE_RSP Data = %02x",
1922 // to one more subroutine. If/when more EXT_STATUS, there'll be more work to do. 1994 __func__, edge_serial->rxPort, byte3);
1923 // Also, we currently clear flag and close the port regardless of content of above's Byte3. 1995 /* Currently, the only EXT_STATUS is Chase, so process
1924 // We could choose to do something else when Byte3 says Timeout on Chase from Edgeport, 1996 * here instead of one more call to one more subroutine
1925 // like wait longer in block_until_chase_response, but for now we don't. 1997 * If/when more EXT_STATUS, there'll be more work to do
1926 edge_port->chaseResponsePending = false; 1998 * Also, we currently clear flag and close the port
1927 wake_up (&edge_port->wait_chase); 1999 * regardless of content of above's Byte3.
1928 return; 2000 * We could choose to do something else when Byte3 says
2001 * Timeout on Chase from Edgeport, like wait longer in
2002 * block_until_chase_response, but for now we don't.
2003 */
2004 edge_port->chaseResponsePending = false;
2005 wake_up(&edge_port->wait_chase);
2006 return;
1929 2007
1930 case IOSP_EXT_STATUS_RX_CHECK_RSP: 2008 case IOSP_EXT_STATUS_RX_CHECK_RSP:
1931 dbg("%s ========== Port %u CHECK_RSP Sequence = %02x =============\n", __func__, edge_serial->rxPort, byte3 ); 2009 dbg("%s ========== Port %u CHECK_RSP Sequence = %02x =============\n", __func__, edge_serial->rxPort, byte3);
1932 //Port->RxCheckRsp = true; 2010 /* Port->RxCheckRsp = true; */
1933 return; 2011 return;
1934 } 2012 }
1935 } 2013 }
1936 2014
@@ -1938,11 +2016,14 @@ static void process_rcvd_status (struct edgeport_serial *edge_serial, __u8 byte2
1938 edge_port->txCredits = GET_TX_BUFFER_SIZE(byte3); 2016 edge_port->txCredits = GET_TX_BUFFER_SIZE(byte3);
1939 edge_port->maxTxCredits = edge_port->txCredits; 2017 edge_port->maxTxCredits = edge_port->txCredits;
1940 dbg("%s - Port %u Open Response Inital MSR = %02x TxBufferSize = %d", __func__, edge_serial->rxPort, byte2, edge_port->txCredits); 2018 dbg("%s - Port %u Open Response Inital MSR = %02x TxBufferSize = %d", __func__, edge_serial->rxPort, byte2, edge_port->txCredits);
1941 handle_new_msr (edge_port, byte2); 2019 handle_new_msr(edge_port, byte2);
1942 2020
1943 /* send the current line settings to the port so we are in sync with any further termios calls */ 2021 /* send the current line settings to the port so we are
1944 if (edge_port->port->tty) 2022 in sync with any further termios calls */
1945 change_port_settings (edge_port, edge_port->port->tty->termios); 2023 /* FIXME: locking on tty */
2024 if (edge_port->port->port.tty)
2025 change_port_settings(edge_port->port->port.tty,
2026 edge_port, edge_port->port->port.tty->termios);
1946 2027
1947 /* we have completed the open */ 2028 /* we have completed the open */
1948 edge_port->openPending = false; 2029 edge_port->openPending = false;
@@ -1951,45 +2032,49 @@ static void process_rcvd_status (struct edgeport_serial *edge_serial, __u8 byte2
1951 return; 2032 return;
1952 } 2033 }
1953 2034
1954 // If port is closed, silently discard all rcvd status. We can 2035 /* If port is closed, silently discard all rcvd status. We can
1955 // have cases where buffered status is received AFTER the close 2036 * have cases where buffered status is received AFTER the close
1956 // port command is sent to the Edgeport. 2037 * port command is sent to the Edgeport.
1957 if (!edge_port->open || edge_port->closePending) { 2038 */
2039 if (!edge_port->open || edge_port->closePending)
1958 return; 2040 return;
1959 }
1960 2041
1961 switch (code) { 2042 switch (code) {
1962 // Not currently sent by Edgeport 2043 /* Not currently sent by Edgeport */
1963 case IOSP_STATUS_LSR: 2044 case IOSP_STATUS_LSR:
1964 dbg("%s - Port %u LSR Status = %02x", __func__, edge_serial->rxPort, byte2); 2045 dbg("%s - Port %u LSR Status = %02x",
1965 handle_new_lsr(edge_port, false, byte2, 0); 2046 __func__, edge_serial->rxPort, byte2);
1966 break; 2047 handle_new_lsr(edge_port, false, byte2, 0);
2048 break;
1967 2049
1968 case IOSP_STATUS_LSR_DATA: 2050 case IOSP_STATUS_LSR_DATA:
1969 dbg("%s - Port %u LSR Status = %02x, Data = %02x", __func__, edge_serial->rxPort, byte2, byte3); 2051 dbg("%s - Port %u LSR Status = %02x, Data = %02x",
1970 // byte2 is LSR Register 2052 __func__, edge_serial->rxPort, byte2, byte3);
1971 // byte3 is broken data byte 2053 /* byte2 is LSR Register */
1972 handle_new_lsr(edge_port, true, byte2, byte3); 2054 /* byte3 is broken data byte */
1973 break; 2055 handle_new_lsr(edge_port, true, byte2, byte3);
1974 // 2056 break;
1975 // case IOSP_EXT_4_STATUS: 2057 /*
1976 // dbg("%s - Port %u LSR Status = %02x Data = %02x", __func__, edge_serial->rxPort, byte2, byte3); 2058 * case IOSP_EXT_4_STATUS:
1977 // break; 2059 * dbg("%s - Port %u LSR Status = %02x Data = %02x",
1978 // 2060 * __func__, edge_serial->rxPort, byte2, byte3);
1979 case IOSP_STATUS_MSR: 2061 * break;
1980 dbg("%s - Port %u MSR Status = %02x", __func__, edge_serial->rxPort, byte2); 2062 */
1981 2063 case IOSP_STATUS_MSR:
1982 // Process this new modem status and generate appropriate 2064 dbg("%s - Port %u MSR Status = %02x",
1983 // events, etc, based on the new status. This routine 2065 __func__, edge_serial->rxPort, byte2);
1984 // also saves the MSR in Port->ShadowMsr. 2066 /*
1985 handle_new_msr(edge_port, byte2); 2067 * Process this new modem status and generate appropriate
1986 break; 2068 * events, etc, based on the new status. This routine
2069 * also saves the MSR in Port->ShadowMsr.
2070 */
2071 handle_new_msr(edge_port, byte2);
2072 break;
1987 2073
1988 default: 2074 default:
1989 dbg("%s - Unrecognized IOSP status code %u\n", __func__, code); 2075 dbg("%s - Unrecognized IOSP status code %u\n", __func__, code);
1990 break; 2076 break;
1991 } 2077 }
1992
1993 return; 2078 return;
1994} 2079}
1995 2080
@@ -1998,7 +2083,8 @@ static void process_rcvd_status (struct edgeport_serial *edge_serial, __u8 byte2
1998 * edge_tty_recv 2083 * edge_tty_recv
1999 * this function passes data on to the tty flip buffer 2084 * this function passes data on to the tty flip buffer
2000 *****************************************************************************/ 2085 *****************************************************************************/
2001static void edge_tty_recv(struct device *dev, struct tty_struct *tty, unsigned char *data, int length) 2086static void edge_tty_recv(struct device *dev, struct tty_struct *tty,
2087 unsigned char *data, int length)
2002{ 2088{
2003 int cnt; 2089 int cnt;
2004 2090
@@ -2007,7 +2093,7 @@ static void edge_tty_recv(struct device *dev, struct tty_struct *tty, unsigned c
2007 if (cnt < length) { 2093 if (cnt < length) {
2008 dev_err(dev, "%s - dropping data, %d bytes lost\n", 2094 dev_err(dev, "%s - dropping data, %d bytes lost\n",
2009 __func__, length - cnt); 2095 __func__, length - cnt);
2010 if(cnt == 0) 2096 if (cnt == 0)
2011 break; 2097 break;
2012 } 2098 }
2013 tty_insert_flip_string(tty, data, cnt); 2099 tty_insert_flip_string(tty, data, cnt);
@@ -2029,22 +2115,19 @@ static void handle_new_msr(struct edgeport_port *edge_port, __u8 newMsr)
2029 2115
2030 dbg("%s %02x", __func__, newMsr); 2116 dbg("%s %02x", __func__, newMsr);
2031 2117
2032 if (newMsr & (EDGEPORT_MSR_DELTA_CTS | EDGEPORT_MSR_DELTA_DSR | EDGEPORT_MSR_DELTA_RI | EDGEPORT_MSR_DELTA_CD)) { 2118 if (newMsr & (EDGEPORT_MSR_DELTA_CTS | EDGEPORT_MSR_DELTA_DSR |
2119 EDGEPORT_MSR_DELTA_RI | EDGEPORT_MSR_DELTA_CD)) {
2033 icount = &edge_port->icount; 2120 icount = &edge_port->icount;
2034 2121
2035 /* update input line counters */ 2122 /* update input line counters */
2036 if (newMsr & EDGEPORT_MSR_DELTA_CTS) { 2123 if (newMsr & EDGEPORT_MSR_DELTA_CTS)
2037 icount->cts++; 2124 icount->cts++;
2038 } 2125 if (newMsr & EDGEPORT_MSR_DELTA_DSR)
2039 if (newMsr & EDGEPORT_MSR_DELTA_DSR) {
2040 icount->dsr++; 2126 icount->dsr++;
2041 } 2127 if (newMsr & EDGEPORT_MSR_DELTA_CD)
2042 if (newMsr & EDGEPORT_MSR_DELTA_CD) {
2043 icount->dcd++; 2128 icount->dcd++;
2044 } 2129 if (newMsr & EDGEPORT_MSR_DELTA_RI)
2045 if (newMsr & EDGEPORT_MSR_DELTA_RI) {
2046 icount->rng++; 2130 icount->rng++;
2047 }
2048 wake_up_interruptible(&edge_port->delta_msr_wait); 2131 wake_up_interruptible(&edge_port->delta_msr_wait);
2049 } 2132 }
2050 2133
@@ -2059,42 +2142,41 @@ static void handle_new_msr(struct edgeport_port *edge_port, __u8 newMsr)
2059 * handle_new_lsr 2142 * handle_new_lsr
2060 * this function handles any change to the lsr register for a port. 2143 * this function handles any change to the lsr register for a port.
2061 *****************************************************************************/ 2144 *****************************************************************************/
2062static void handle_new_lsr(struct edgeport_port *edge_port, __u8 lsrData, __u8 lsr, __u8 data) 2145static void handle_new_lsr(struct edgeport_port *edge_port, __u8 lsrData,
2146 __u8 lsr, __u8 data)
2063{ 2147{
2064 __u8 newLsr = (__u8)(lsr & (__u8)(LSR_OVER_ERR | LSR_PAR_ERR | LSR_FRM_ERR | LSR_BREAK)); 2148 __u8 newLsr = (__u8) (lsr & (__u8)
2065 struct async_icount *icount; 2149 (LSR_OVER_ERR | LSR_PAR_ERR | LSR_FRM_ERR | LSR_BREAK));
2150 struct async_icount *icount;
2066 2151
2067 dbg("%s - %02x", __func__, newLsr); 2152 dbg("%s - %02x", __func__, newLsr);
2068 2153
2069 edge_port->shadowLSR = lsr; 2154 edge_port->shadowLSR = lsr;
2070 2155
2071 if (newLsr & LSR_BREAK) { 2156 if (newLsr & LSR_BREAK) {
2072 // 2157 /*
2073 // Parity and Framing errors only count if they 2158 * Parity and Framing errors only count if they
2074 // occur exclusive of a break being 2159 * occur exclusive of a break being
2075 // received. 2160 * received.
2076 // 2161 */
2077 newLsr &= (__u8)(LSR_OVER_ERR | LSR_BREAK); 2162 newLsr &= (__u8)(LSR_OVER_ERR | LSR_BREAK);
2078 } 2163 }
2079 2164
2080 /* Place LSR data byte into Rx buffer */ 2165 /* Place LSR data byte into Rx buffer */
2081 if (lsrData && edge_port->port->tty) 2166 if (lsrData && edge_port->port->port.tty)
2082 edge_tty_recv(&edge_port->port->dev, edge_port->port->tty, &data, 1); 2167 edge_tty_recv(&edge_port->port->dev,
2168 edge_port->port->port.tty, &data, 1);
2083 2169
2084 /* update input line counters */ 2170 /* update input line counters */
2085 icount = &edge_port->icount; 2171 icount = &edge_port->icount;
2086 if (newLsr & LSR_BREAK) { 2172 if (newLsr & LSR_BREAK)
2087 icount->brk++; 2173 icount->brk++;
2088 } 2174 if (newLsr & LSR_OVER_ERR)
2089 if (newLsr & LSR_OVER_ERR) {
2090 icount->overrun++; 2175 icount->overrun++;
2091 } 2176 if (newLsr & LSR_PAR_ERR)
2092 if (newLsr & LSR_PAR_ERR) {
2093 icount->parity++; 2177 icount->parity++;
2094 } 2178 if (newLsr & LSR_FRM_ERR)
2095 if (newLsr & LSR_FRM_ERR) {
2096 icount->frame++; 2179 icount->frame++;
2097 }
2098 2180
2099 return; 2181 return;
2100} 2182}
@@ -2102,12 +2184,13 @@ static void handle_new_lsr(struct edgeport_port *edge_port, __u8 lsrData, __u8 l
2102 2184
2103/**************************************************************************** 2185/****************************************************************************
2104 * sram_write 2186 * sram_write
2105 * writes a number of bytes to the Edgeport device's sram starting at the 2187 * writes a number of bytes to the Edgeport device's sram starting at the
2106 * given address. 2188 * given address.
2107 * If successful returns the number of bytes written, otherwise it returns 2189 * If successful returns the number of bytes written, otherwise it returns
2108 * a negative error number of the problem. 2190 * a negative error number of the problem.
2109 ****************************************************************************/ 2191 ****************************************************************************/
2110static int sram_write(struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16 length, const __u8 *data) 2192static int sram_write(struct usb_serial *serial, __u16 extAddr, __u16 addr,
2193 __u16 length, const __u8 *data)
2111{ 2194{
2112 int result; 2195 int result;
2113 __u16 current_length; 2196 __u16 current_length;
@@ -2115,32 +2198,37 @@ static int sram_write(struct usb_serial *serial, __u16 extAddr, __u16 addr, __u1
2115 2198
2116 dbg("%s - %x, %x, %d", __func__, extAddr, addr, length); 2199 dbg("%s - %x, %x, %d", __func__, extAddr, addr, length);
2117 2200
2118 transfer_buffer = kmalloc (64, GFP_KERNEL); 2201 transfer_buffer = kmalloc(64, GFP_KERNEL);
2119 if (!transfer_buffer) { 2202 if (!transfer_buffer) {
2120 dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n", __func__, 64); 2203 dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n",
2204 __func__, 64);
2121 return -ENOMEM; 2205 return -ENOMEM;
2122 } 2206 }
2123 2207
2124 /* need to split these writes up into 64 byte chunks */ 2208 /* need to split these writes up into 64 byte chunks */
2125 result = 0; 2209 result = 0;
2126 while (length > 0) { 2210 while (length > 0) {
2127 if (length > 64) { 2211 if (length > 64)
2128 current_length = 64; 2212 current_length = 64;
2129 } else { 2213 else
2130 current_length = length; 2214 current_length = length;
2131 } 2215
2132// dbg("%s - writing %x, %x, %d", __func__, extAddr, addr, current_length); 2216/* dbg("%s - writing %x, %x, %d", __func__,
2133 memcpy (transfer_buffer, data, current_length); 2217 extAddr, addr, current_length); */
2134 result = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0), USB_REQUEST_ION_WRITE_RAM, 2218 memcpy(transfer_buffer, data, current_length);
2135 0x40, addr, extAddr, transfer_buffer, current_length, 300); 2219 result = usb_control_msg(serial->dev,
2220 usb_sndctrlpipe(serial->dev, 0),
2221 USB_REQUEST_ION_WRITE_RAM,
2222 0x40, addr, extAddr, transfer_buffer,
2223 current_length, 300);
2136 if (result < 0) 2224 if (result < 0)
2137 break; 2225 break;
2138 length -= current_length; 2226 length -= current_length;
2139 addr += current_length; 2227 addr += current_length;
2140 data += current_length; 2228 data += current_length;
2141 } 2229 }
2142 2230
2143 kfree (transfer_buffer); 2231 kfree(transfer_buffer);
2144 return result; 2232 return result;
2145} 2233}
2146 2234
@@ -2152,40 +2240,45 @@ static int sram_write(struct usb_serial *serial, __u16 extAddr, __u16 addr, __u1
2152 * If successful returns the number of bytes written, otherwise it returns 2240 * If successful returns the number of bytes written, otherwise it returns
2153 * a negative error number of the problem. 2241 * a negative error number of the problem.
2154 ****************************************************************************/ 2242 ****************************************************************************/
2155static int rom_write(struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16 length, const __u8 *data) 2243static int rom_write(struct usb_serial *serial, __u16 extAddr, __u16 addr,
2244 __u16 length, const __u8 *data)
2156{ 2245{
2157 int result; 2246 int result;
2158 __u16 current_length; 2247 __u16 current_length;
2159 unsigned char *transfer_buffer; 2248 unsigned char *transfer_buffer;
2160 2249
2161// dbg("%s - %x, %x, %d", __func__, extAddr, addr, length); 2250/* dbg("%s - %x, %x, %d", __func__, extAddr, addr, length); */
2162 2251
2163 transfer_buffer = kmalloc (64, GFP_KERNEL); 2252 transfer_buffer = kmalloc(64, GFP_KERNEL);
2164 if (!transfer_buffer) { 2253 if (!transfer_buffer) {
2165 dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n", __func__, 64); 2254 dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n",
2255 __func__, 64);
2166 return -ENOMEM; 2256 return -ENOMEM;
2167 } 2257 }
2168 2258
2169 /* need to split these writes up into 64 byte chunks */ 2259 /* need to split these writes up into 64 byte chunks */
2170 result = 0; 2260 result = 0;
2171 while (length > 0) { 2261 while (length > 0) {
2172 if (length > 64) { 2262 if (length > 64)
2173 current_length = 64; 2263 current_length = 64;
2174 } else { 2264 else
2175 current_length = length; 2265 current_length = length;
2176 } 2266/* dbg("%s - writing %x, %x, %d", __func__,
2177// dbg("%s - writing %x, %x, %d", __func__, extAddr, addr, current_length); 2267 extAddr, addr, current_length); */
2178 memcpy (transfer_buffer, data, current_length); 2268 memcpy(transfer_buffer, data, current_length);
2179 result = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0), USB_REQUEST_ION_WRITE_ROM, 2269 result = usb_control_msg(serial->dev,
2180 0x40, addr, extAddr, transfer_buffer, current_length, 300); 2270 usb_sndctrlpipe(serial->dev, 0),
2271 USB_REQUEST_ION_WRITE_ROM, 0x40,
2272 addr, extAddr,
2273 transfer_buffer, current_length, 300);
2181 if (result < 0) 2274 if (result < 0)
2182 break; 2275 break;
2183 length -= current_length; 2276 length -= current_length;
2184 addr += current_length; 2277 addr += current_length;
2185 data += current_length; 2278 data += current_length;
2186 } 2279 }
2187 2280
2188 kfree (transfer_buffer); 2281 kfree(transfer_buffer);
2189 return result; 2282 return result;
2190} 2283}
2191 2284
@@ -2197,7 +2290,8 @@ static int rom_write(struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16
2197 * If successful returns the number of bytes read, otherwise it returns 2290 * If successful returns the number of bytes read, otherwise it returns
2198 * a negative error number of the problem. 2291 * a negative error number of the problem.
2199 ****************************************************************************/ 2292 ****************************************************************************/
2200static int rom_read (struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16 length, __u8 *data) 2293static int rom_read(struct usb_serial *serial, __u16 extAddr,
2294 __u16 addr, __u16 length, __u8 *data)
2201{ 2295{
2202 int result; 2296 int result;
2203 __u16 current_length; 2297 __u16 current_length;
@@ -2205,32 +2299,36 @@ static int rom_read (struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16
2205 2299
2206 dbg("%s - %x, %x, %d", __func__, extAddr, addr, length); 2300 dbg("%s - %x, %x, %d", __func__, extAddr, addr, length);
2207 2301
2208 transfer_buffer = kmalloc (64, GFP_KERNEL); 2302 transfer_buffer = kmalloc(64, GFP_KERNEL);
2209 if (!transfer_buffer) { 2303 if (!transfer_buffer) {
2210 dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n", __func__, 64); 2304 dev_err(&serial->dev->dev,
2305 "%s - kmalloc(%d) failed.\n", __func__, 64);
2211 return -ENOMEM; 2306 return -ENOMEM;
2212 } 2307 }
2213 2308
2214 /* need to split these reads up into 64 byte chunks */ 2309 /* need to split these reads up into 64 byte chunks */
2215 result = 0; 2310 result = 0;
2216 while (length > 0) { 2311 while (length > 0) {
2217 if (length > 64) { 2312 if (length > 64)
2218 current_length = 64; 2313 current_length = 64;
2219 } else { 2314 else
2220 current_length = length; 2315 current_length = length;
2221 } 2316/* dbg("%s - %x, %x, %d", __func__,
2222// dbg("%s - %x, %x, %d", __func__, extAddr, addr, current_length); 2317 extAddr, addr, current_length); */
2223 result = usb_control_msg (serial->dev, usb_rcvctrlpipe(serial->dev, 0), USB_REQUEST_ION_READ_ROM, 2318 result = usb_control_msg(serial->dev,
2224 0xC0, addr, extAddr, transfer_buffer, current_length, 300); 2319 usb_rcvctrlpipe(serial->dev, 0),
2320 USB_REQUEST_ION_READ_ROM,
2321 0xC0, addr, extAddr, transfer_buffer,
2322 current_length, 300);
2225 if (result < 0) 2323 if (result < 0)
2226 break; 2324 break;
2227 memcpy (data, transfer_buffer, current_length); 2325 memcpy(data, transfer_buffer, current_length);
2228 length -= current_length; 2326 length -= current_length;
2229 addr += current_length; 2327 addr += current_length;
2230 data += current_length; 2328 data += current_length;
2231 } 2329 }
2232 2330
2233 kfree (transfer_buffer); 2331 kfree(transfer_buffer);
2234 return result; 2332 return result;
2235} 2333}
2236 2334
@@ -2239,7 +2337,8 @@ static int rom_read (struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16
2239 * send_iosp_ext_cmd 2337 * send_iosp_ext_cmd
2240 * Is used to send a IOSP message to the Edgeport device 2338 * Is used to send a IOSP message to the Edgeport device
2241 ****************************************************************************/ 2339 ****************************************************************************/
2242static int send_iosp_ext_cmd (struct edgeport_port *edge_port, __u8 command, __u8 param) 2340static int send_iosp_ext_cmd(struct edgeport_port *edge_port,
2341 __u8 command, __u8 param)
2243{ 2342{
2244 unsigned char *buffer; 2343 unsigned char *buffer;
2245 unsigned char *currentCommand; 2344 unsigned char *currentCommand;
@@ -2248,19 +2347,20 @@ static int send_iosp_ext_cmd (struct edgeport_port *edge_port, __u8 command, __u
2248 2347
2249 dbg("%s - %d, %d", __func__, command, param); 2348 dbg("%s - %d, %d", __func__, command, param);
2250 2349
2251 buffer = kmalloc (10, GFP_ATOMIC); 2350 buffer = kmalloc(10, GFP_ATOMIC);
2252 if (!buffer) { 2351 if (!buffer) {
2253 dev_err(&edge_port->port->dev, "%s - kmalloc(%d) failed.\n", __func__, 10); 2352 dev_err(&edge_port->port->dev,
2353 "%s - kmalloc(%d) failed.\n", __func__, 10);
2254 return -ENOMEM; 2354 return -ENOMEM;
2255 } 2355 }
2256 2356
2257 currentCommand = buffer; 2357 currentCommand = buffer;
2258 2358
2259 MAKE_CMD_EXT_CMD (&currentCommand, &length, 2359 MAKE_CMD_EXT_CMD(&currentCommand, &length,
2260 edge_port->port->number - edge_port->port->serial->minor, 2360 edge_port->port->number - edge_port->port->serial->minor,
2261 command, param); 2361 command, param);
2262 2362
2263 status = write_cmd_usb (edge_port, buffer, length); 2363 status = write_cmd_usb(edge_port, buffer, length);
2264 if (status) { 2364 if (status) {
2265 /* something bad happened, let's free up the memory */ 2365 /* something bad happened, let's free up the memory */
2266 kfree(buffer); 2366 kfree(buffer);
@@ -2274,43 +2374,50 @@ static int send_iosp_ext_cmd (struct edgeport_port *edge_port, __u8 command, __u
2274 * write_cmd_usb 2374 * write_cmd_usb
2275 * this function writes the given buffer out to the bulk write endpoint. 2375 * this function writes the given buffer out to the bulk write endpoint.
2276 *****************************************************************************/ 2376 *****************************************************************************/
2277static int write_cmd_usb (struct edgeport_port *edge_port, unsigned char *buffer, int length) 2377static int write_cmd_usb(struct edgeport_port *edge_port,
2378 unsigned char *buffer, int length)
2278{ 2379{
2279 struct edgeport_serial *edge_serial = usb_get_serial_data(edge_port->port->serial); 2380 struct edgeport_serial *edge_serial =
2381 usb_get_serial_data(edge_port->port->serial);
2280 int status = 0; 2382 int status = 0;
2281 struct urb *urb; 2383 struct urb *urb;
2282 int timeout; 2384 int timeout;
2283 2385
2284 usb_serial_debug_data(debug, &edge_port->port->dev, __func__, length, buffer); 2386 usb_serial_debug_data(debug, &edge_port->port->dev,
2387 __func__, length, buffer);
2285 2388
2286 /* Allocate our next urb */ 2389 /* Allocate our next urb */
2287 urb = usb_alloc_urb (0, GFP_ATOMIC); 2390 urb = usb_alloc_urb(0, GFP_ATOMIC);
2288 if (!urb) 2391 if (!urb)
2289 return -ENOMEM; 2392 return -ENOMEM;
2290 2393
2291 atomic_inc(&CmdUrbs); 2394 atomic_inc(&CmdUrbs);
2292 dbg("%s - ALLOCATE URB %p (outstanding %d)", __func__, urb, atomic_read(&CmdUrbs)); 2395 dbg("%s - ALLOCATE URB %p (outstanding %d)",
2396 __func__, urb, atomic_read(&CmdUrbs));
2293 2397
2294 usb_fill_bulk_urb (urb, edge_serial->serial->dev, 2398 usb_fill_bulk_urb(urb, edge_serial->serial->dev,
2295 usb_sndbulkpipe(edge_serial->serial->dev, edge_serial->bulk_out_endpoint), 2399 usb_sndbulkpipe(edge_serial->serial->dev,
2296 buffer, length, edge_bulk_out_cmd_callback, edge_port); 2400 edge_serial->bulk_out_endpoint),
2401 buffer, length, edge_bulk_out_cmd_callback, edge_port);
2297 2402
2298 edge_port->commandPending = true; 2403 edge_port->commandPending = true;
2299 status = usb_submit_urb(urb, GFP_ATOMIC); 2404 status = usb_submit_urb(urb, GFP_ATOMIC);
2300 2405
2301 if (status) { 2406 if (status) {
2302 /* something went wrong */ 2407 /* something went wrong */
2303 dev_err(&edge_port->port->dev, "%s - usb_submit_urb(write command) failed, status = %d\n", __func__, status); 2408 dev_err(&edge_port->port->dev,
2409 "%s - usb_submit_urb(write command) failed, status = %d\n",
2410 __func__, status);
2304 usb_kill_urb(urb); 2411 usb_kill_urb(urb);
2305 usb_free_urb(urb); 2412 usb_free_urb(urb);
2306 atomic_dec(&CmdUrbs); 2413 atomic_dec(&CmdUrbs);
2307 return status; 2414 return status;
2308 } 2415 }
2309 2416
2310 // wait for command to finish 2417 /* wait for command to finish */
2311 timeout = COMMAND_TIMEOUT; 2418 timeout = COMMAND_TIMEOUT;
2312#if 0 2419#if 0
2313 wait_event (&edge_port->wait_command, !edge_port->commandPending); 2420 wait_event(&edge_port->wait_command, !edge_port->commandPending);
2314 2421
2315 if (edge_port->commandPending) { 2422 if (edge_port->commandPending) {
2316 /* command timed out */ 2423 /* command timed out */
@@ -2327,15 +2434,18 @@ static int write_cmd_usb (struct edgeport_port *edge_port, unsigned char *buffer
2327 * this function sends the proper command to change the baud rate of the 2434 * this function sends the proper command to change the baud rate of the
2328 * specified port. 2435 * specified port.
2329 *****************************************************************************/ 2436 *****************************************************************************/
2330static int send_cmd_write_baud_rate (struct edgeport_port *edge_port, int baudRate) 2437static int send_cmd_write_baud_rate(struct edgeport_port *edge_port,
2438 int baudRate)
2331{ 2439{
2332 struct edgeport_serial *edge_serial = usb_get_serial_data(edge_port->port->serial); 2440 struct edgeport_serial *edge_serial =
2441 usb_get_serial_data(edge_port->port->serial);
2333 unsigned char *cmdBuffer; 2442 unsigned char *cmdBuffer;
2334 unsigned char *currCmd; 2443 unsigned char *currCmd;
2335 int cmdLen = 0; 2444 int cmdLen = 0;
2336 int divisor; 2445 int divisor;
2337 int status; 2446 int status;
2338 unsigned char number = edge_port->port->number - edge_port->port->serial->minor; 2447 unsigned char number =
2448 edge_port->port->number - edge_port->port->serial->minor;
2339 2449
2340 if (edge_serial->is_epic && 2450 if (edge_serial->is_epic &&
2341 !edge_serial->epic_descriptor.Supports.IOSPSetBaudRate) { 2451 !edge_serial->epic_descriptor.Supports.IOSPSetBaudRate) {
@@ -2344,36 +2454,40 @@ static int send_cmd_write_baud_rate (struct edgeport_port *edge_port, int baudRa
2344 return 0; 2454 return 0;
2345 } 2455 }
2346 2456
2347 dbg("%s - port = %d, baud = %d", __func__, edge_port->port->number, baudRate); 2457 dbg("%s - port = %d, baud = %d", __func__,
2458 edge_port->port->number, baudRate);
2348 2459
2349 status = calc_baud_rate_divisor (baudRate, &divisor); 2460 status = calc_baud_rate_divisor(baudRate, &divisor);
2350 if (status) { 2461 if (status) {
2351 dev_err(&edge_port->port->dev, "%s - bad baud rate\n", __func__); 2462 dev_err(&edge_port->port->dev, "%s - bad baud rate\n",
2463 __func__);
2352 return status; 2464 return status;
2353 } 2465 }
2354 2466
2355 // Alloc memory for the string of commands. 2467 /* Alloc memory for the string of commands. */
2356 cmdBuffer = kmalloc (0x100, GFP_ATOMIC); 2468 cmdBuffer = kmalloc(0x100, GFP_ATOMIC);
2357 if (!cmdBuffer) { 2469 if (!cmdBuffer) {
2358 dev_err(&edge_port->port->dev, "%s - kmalloc(%d) failed.\n", __func__, 0x100); 2470 dev_err(&edge_port->port->dev,
2471 "%s - kmalloc(%d) failed.\n", __func__, 0x100);
2359 return -ENOMEM; 2472 return -ENOMEM;
2360 } 2473 }
2361 currCmd = cmdBuffer; 2474 currCmd = cmdBuffer;
2362 2475
2363 // Enable access to divisor latch 2476 /* Enable access to divisor latch */
2364 MAKE_CMD_WRITE_REG( &currCmd, &cmdLen, number, LCR, LCR_DL_ENABLE ); 2477 MAKE_CMD_WRITE_REG(&currCmd, &cmdLen, number, LCR, LCR_DL_ENABLE);
2365 2478
2366 // Write the divisor itself 2479 /* Write the divisor itself */
2367 MAKE_CMD_WRITE_REG( &currCmd, &cmdLen, number, DLL, LOW8 (divisor) ); 2480 MAKE_CMD_WRITE_REG(&currCmd, &cmdLen, number, DLL, LOW8(divisor));
2368 MAKE_CMD_WRITE_REG( &currCmd, &cmdLen, number, DLM, HIGH8(divisor) ); 2481 MAKE_CMD_WRITE_REG(&currCmd, &cmdLen, number, DLM, HIGH8(divisor));
2369 2482
2370 // Restore original value to disable access to divisor latch 2483 /* Restore original value to disable access to divisor latch */
2371 MAKE_CMD_WRITE_REG( &currCmd, &cmdLen, number, LCR, edge_port->shadowLCR); 2484 MAKE_CMD_WRITE_REG(&currCmd, &cmdLen, number, LCR,
2485 edge_port->shadowLCR);
2372 2486
2373 status = write_cmd_usb(edge_port, cmdBuffer, cmdLen ); 2487 status = write_cmd_usb(edge_port, cmdBuffer, cmdLen);
2374 if (status) { 2488 if (status) {
2375 /* something bad happened, let's free up the memory */ 2489 /* something bad happened, let's free up the memory */
2376 kfree (cmdBuffer); 2490 kfree(cmdBuffer);
2377 } 2491 }
2378 2492
2379 return status; 2493 return status;
@@ -2385,7 +2499,7 @@ static int send_cmd_write_baud_rate (struct edgeport_port *edge_port, int baudRa
2385 * this function calculates the proper baud rate divisor for the specified 2499 * this function calculates the proper baud rate divisor for the specified
2386 * baud rate. 2500 * baud rate.
2387 *****************************************************************************/ 2501 *****************************************************************************/
2388static int calc_baud_rate_divisor (int baudrate, int *divisor) 2502static int calc_baud_rate_divisor(int baudrate, int *divisor)
2389{ 2503{
2390 int i; 2504 int i;
2391 __u16 custom; 2505 __u16 custom;
@@ -2394,17 +2508,17 @@ static int calc_baud_rate_divisor (int baudrate, int *divisor)
2394 dbg("%s - %d", __func__, baudrate); 2508 dbg("%s - %d", __func__, baudrate);
2395 2509
2396 for (i = 0; i < ARRAY_SIZE(divisor_table); i++) { 2510 for (i = 0; i < ARRAY_SIZE(divisor_table); i++) {
2397 if ( divisor_table[i].BaudRate == baudrate ) { 2511 if (divisor_table[i].BaudRate == baudrate) {
2398 *divisor = divisor_table[i].Divisor; 2512 *divisor = divisor_table[i].Divisor;
2399 return 0; 2513 return 0;
2400 } 2514 }
2401 } 2515 }
2402 2516
2403 // We have tried all of the standard baud rates 2517 /* We have tried all of the standard baud rates
2404 // lets try to calculate the divisor for this baud rate 2518 * lets try to calculate the divisor for this baud rate
2405 // Make sure the baud rate is reasonable 2519 * Make sure the baud rate is reasonable */
2406 if (baudrate > 50 && baudrate < 230400) { 2520 if (baudrate > 50 && baudrate < 230400) {
2407 // get divisor 2521 /* get divisor */
2408 custom = (__u16)((230400L + baudrate/2) / baudrate); 2522 custom = (__u16)((230400L + baudrate/2) / baudrate);
2409 2523
2410 *divisor = custom; 2524 *divisor = custom;
@@ -2419,17 +2533,20 @@ static int calc_baud_rate_divisor (int baudrate, int *divisor)
2419 2533
2420/***************************************************************************** 2534/*****************************************************************************
2421 * send_cmd_write_uart_register 2535 * send_cmd_write_uart_register
2422 * this function builds up a uart register message and sends to to the device. 2536 * this function builds up a uart register message and sends to to the device.
2423 *****************************************************************************/ 2537 *****************************************************************************/
2424static int send_cmd_write_uart_register (struct edgeport_port *edge_port, __u8 regNum, __u8 regValue) 2538static int send_cmd_write_uart_register(struct edgeport_port *edge_port,
2539 __u8 regNum, __u8 regValue)
2425{ 2540{
2426 struct edgeport_serial *edge_serial = usb_get_serial_data(edge_port->port->serial); 2541 struct edgeport_serial *edge_serial =
2542 usb_get_serial_data(edge_port->port->serial);
2427 unsigned char *cmdBuffer; 2543 unsigned char *cmdBuffer;
2428 unsigned char *currCmd; 2544 unsigned char *currCmd;
2429 unsigned long cmdLen = 0; 2545 unsigned long cmdLen = 0;
2430 int status; 2546 int status;
2431 2547
2432 dbg("%s - write to %s register 0x%02x", (regNum == MCR) ? "MCR" : "LCR", __func__, regValue); 2548 dbg("%s - write to %s register 0x%02x",
2549 (regNum == MCR) ? "MCR" : "LCR", __func__, regValue);
2433 2550
2434 if (edge_serial->is_epic && 2551 if (edge_serial->is_epic &&
2435 !edge_serial->epic_descriptor.Supports.IOSPWriteMCR && 2552 !edge_serial->epic_descriptor.Supports.IOSPWriteMCR &&
@@ -2441,27 +2558,26 @@ static int send_cmd_write_uart_register (struct edgeport_port *edge_port, __u8 r
2441 if (edge_serial->is_epic && 2558 if (edge_serial->is_epic &&
2442 !edge_serial->epic_descriptor.Supports.IOSPWriteLCR && 2559 !edge_serial->epic_descriptor.Supports.IOSPWriteLCR &&
2443 regNum == LCR) { 2560 regNum == LCR) {
2444 dbg ("SendCmdWriteUartReg - Not writing to LCR Register"); 2561 dbg("SendCmdWriteUartReg - Not writing to LCR Register");
2445 return 0; 2562 return 0;
2446 } 2563 }
2447 2564
2448 // Alloc memory for the string of commands. 2565 /* Alloc memory for the string of commands. */
2449 cmdBuffer = kmalloc (0x10, GFP_ATOMIC); 2566 cmdBuffer = kmalloc(0x10, GFP_ATOMIC);
2450 if (cmdBuffer == NULL ) { 2567 if (cmdBuffer == NULL)
2451 return -ENOMEM; 2568 return -ENOMEM;
2452 }
2453 2569
2454 currCmd = cmdBuffer; 2570 currCmd = cmdBuffer;
2455 2571
2456 // Build a cmd in the buffer to write the given register 2572 /* Build a cmd in the buffer to write the given register */
2457 MAKE_CMD_WRITE_REG (&currCmd, &cmdLen, 2573 MAKE_CMD_WRITE_REG(&currCmd, &cmdLen,
2458 edge_port->port->number - edge_port->port->serial->minor, 2574 edge_port->port->number - edge_port->port->serial->minor,
2459 regNum, regValue); 2575 regNum, regValue);
2460 2576
2461 status = write_cmd_usb(edge_port, cmdBuffer, cmdLen); 2577 status = write_cmd_usb(edge_port, cmdBuffer, cmdLen);
2462 if (status) { 2578 if (status) {
2463 /* something bad happened, let's free up the memory */ 2579 /* something bad happened, let's free up the memory */
2464 kfree (cmdBuffer); 2580 kfree(cmdBuffer);
2465 } 2581 }
2466 2582
2467 return status; 2583 return status;
@@ -2470,16 +2586,15 @@ static int send_cmd_write_uart_register (struct edgeport_port *edge_port, __u8 r
2470 2586
2471/***************************************************************************** 2587/*****************************************************************************
2472 * change_port_settings 2588 * change_port_settings
2473 * This routine is called to set the UART on the device to match the specified 2589 * This routine is called to set the UART on the device to match the
2474 * new settings. 2590 * specified new settings.
2475 *****************************************************************************/ 2591 *****************************************************************************/
2476#ifndef CMSPAR 2592
2477#define CMSPAR 0 2593static void change_port_settings(struct tty_struct *tty,
2478#endif 2594 struct edgeport_port *edge_port, struct ktermios *old_termios)
2479static void change_port_settings (struct edgeport_port *edge_port, struct ktermios *old_termios)
2480{ 2595{
2481 struct edgeport_serial *edge_serial = usb_get_serial_data(edge_port->port->serial); 2596 struct edgeport_serial *edge_serial =
2482 struct tty_struct *tty; 2597 usb_get_serial_data(edge_port->port->serial);
2483 int baud; 2598 int baud;
2484 unsigned cflag; 2599 unsigned cflag;
2485 __u8 mask = 0xff; 2600 __u8 mask = 0xff;
@@ -2498,21 +2613,26 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
2498 return; 2613 return;
2499 } 2614 }
2500 2615
2501 tty = edge_port->port->tty;
2502 if ((!tty) ||
2503 (!tty->termios)) {
2504 dbg("%s - no tty structures", __func__);
2505 return;
2506 }
2507
2508 cflag = tty->termios->c_cflag; 2616 cflag = tty->termios->c_cflag;
2509 2617
2510 switch (cflag & CSIZE) { 2618 switch (cflag & CSIZE) {
2511 case CS5: lData = LCR_BITS_5; mask = 0x1f; dbg("%s - data bits = 5", __func__); break; 2619 case CS5:
2512 case CS6: lData = LCR_BITS_6; mask = 0x3f; dbg("%s - data bits = 6", __func__); break; 2620 lData = LCR_BITS_5; mask = 0x1f;
2513 case CS7: lData = LCR_BITS_7; mask = 0x7f; dbg("%s - data bits = 7", __func__); break; 2621 dbg("%s - data bits = 5", __func__);
2514 default: 2622 break;
2515 case CS8: lData = LCR_BITS_8; dbg("%s - data bits = 8", __func__); break; 2623 case CS6:
2624 lData = LCR_BITS_6; mask = 0x3f;
2625 dbg("%s - data bits = 6", __func__);
2626 break;
2627 case CS7:
2628 lData = LCR_BITS_7; mask = 0x7f;
2629 dbg("%s - data bits = 7", __func__);
2630 break;
2631 default:
2632 case CS8:
2633 lData = LCR_BITS_8;
2634 dbg("%s - data bits = 8", __func__);
2635 break;
2516 } 2636 }
2517 2637
2518 lParity = LCR_PAR_NONE; 2638 lParity = LCR_PAR_NONE;
@@ -2554,7 +2674,8 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
2554 dbg("%s - RTS/CTS is disabled", __func__); 2674 dbg("%s - RTS/CTS is disabled", __func__);
2555 } 2675 }
2556 2676
2557 /* if we are implementing XON/XOFF, set the start and stop character in the device */ 2677 /* if we are implementing XON/XOFF, set the start and stop character
2678 in the device */
2558 if (I_IXOFF(tty) || I_IXON(tty)) { 2679 if (I_IXOFF(tty) || I_IXON(tty)) {
2559 unsigned char stop_char = STOP_CHAR(tty); 2680 unsigned char stop_char = STOP_CHAR(tty);
2560 unsigned char start_char = START_CHAR(tty); 2681 unsigned char start_char = START_CHAR(tty);
@@ -2562,14 +2683,17 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
2562 if ((!edge_serial->is_epic) || 2683 if ((!edge_serial->is_epic) ||
2563 ((edge_serial->is_epic) && 2684 ((edge_serial->is_epic) &&
2564 (edge_serial->epic_descriptor.Supports.IOSPSetXChar))) { 2685 (edge_serial->epic_descriptor.Supports.IOSPSetXChar))) {
2565 send_iosp_ext_cmd(edge_port, IOSP_CMD_SET_XON_CHAR, start_char); 2686 send_iosp_ext_cmd(edge_port,
2566 send_iosp_ext_cmd(edge_port, IOSP_CMD_SET_XOFF_CHAR, stop_char); 2687 IOSP_CMD_SET_XON_CHAR, start_char);
2688 send_iosp_ext_cmd(edge_port,
2689 IOSP_CMD_SET_XOFF_CHAR, stop_char);
2567 } 2690 }
2568 2691
2569 /* if we are implementing INBOUND XON/XOFF */ 2692 /* if we are implementing INBOUND XON/XOFF */
2570 if (I_IXOFF(tty)) { 2693 if (I_IXOFF(tty)) {
2571 rxFlow |= IOSP_RX_FLOW_XON_XOFF; 2694 rxFlow |= IOSP_RX_FLOW_XON_XOFF;
2572 dbg("%s - INBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x", __func__, start_char, stop_char); 2695 dbg("%s - INBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x",
2696 __func__, start_char, stop_char);
2573 } else { 2697 } else {
2574 dbg("%s - INBOUND XON/XOFF is disabled", __func__); 2698 dbg("%s - INBOUND XON/XOFF is disabled", __func__);
2575 } 2699 }
@@ -2577,7 +2701,8 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
2577 /* if we are implementing OUTBOUND XON/XOFF */ 2701 /* if we are implementing OUTBOUND XON/XOFF */
2578 if (I_IXON(tty)) { 2702 if (I_IXON(tty)) {
2579 txFlow |= IOSP_TX_FLOW_XON_XOFF; 2703 txFlow |= IOSP_TX_FLOW_XON_XOFF;
2580 dbg("%s - OUTBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x", __func__, start_char, stop_char); 2704 dbg("%s - OUTBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x",
2705 __func__, start_char, stop_char);
2581 } else { 2706 } else {
2582 dbg("%s - OUTBOUND XON/XOFF is disabled", __func__); 2707 dbg("%s - OUTBOUND XON/XOFF is disabled", __func__);
2583 } 2708 }
@@ -2600,20 +2725,20 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
2600 edge_port->validDataMask = mask; 2725 edge_port->validDataMask = mask;
2601 2726
2602 /* Send the updated LCR value to the EdgePort */ 2727 /* Send the updated LCR value to the EdgePort */
2603 status = send_cmd_write_uart_register(edge_port, LCR, edge_port->shadowLCR); 2728 status = send_cmd_write_uart_register(edge_port, LCR,
2604 if (status != 0) { 2729 edge_port->shadowLCR);
2730 if (status != 0)
2605 return; 2731 return;
2606 }
2607 2732
2608 /* set up the MCR register and send it to the EdgePort */ 2733 /* set up the MCR register and send it to the EdgePort */
2609 edge_port->shadowMCR = MCR_MASTER_IE; 2734 edge_port->shadowMCR = MCR_MASTER_IE;
2610 if (cflag & CBAUD) { 2735 if (cflag & CBAUD)
2611 edge_port->shadowMCR |= (MCR_DTR | MCR_RTS); 2736 edge_port->shadowMCR |= (MCR_DTR | MCR_RTS);
2612 } 2737
2613 status = send_cmd_write_uart_register(edge_port, MCR, edge_port->shadowMCR); 2738 status = send_cmd_write_uart_register(edge_port, MCR,
2614 if (status != 0) { 2739 edge_port->shadowMCR);
2740 if (status != 0)
2615 return; 2741 return;
2616 }
2617 2742
2618 /* Determine divisor based on baud rate */ 2743 /* Determine divisor based on baud rate */
2619 baud = tty_get_baud_rate(tty); 2744 baud = tty_get_baud_rate(tty);
@@ -2623,7 +2748,7 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
2623 } 2748 }
2624 2749
2625 dbg("%s - baud rate = %d", __func__, baud); 2750 dbg("%s - baud rate = %d", __func__, baud);
2626 status = send_cmd_write_baud_rate (edge_port, baud); 2751 status = send_cmd_write_baud_rate(edge_port, baud);
2627 if (status == -1) { 2752 if (status == -1) {
2628 /* Speed change was not possible - put back the old speed */ 2753 /* Speed change was not possible - put back the old speed */
2629 baud = tty_termios_baud_rate(old_termios); 2754 baud = tty_termios_baud_rate(old_termios);
@@ -2640,7 +2765,8 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
2640 * ASCII range, but it's only for debugging... 2765 * ASCII range, but it's only for debugging...
2641 * NOTE: expects the unicode in LE format 2766 * NOTE: expects the unicode in LE format
2642 ****************************************************************************/ 2767 ****************************************************************************/
2643static void unicode_to_ascii(char *string, int buflen, __le16 *unicode, int unicode_size) 2768static void unicode_to_ascii(char *string, int buflen,
2769 __le16 *unicode, int unicode_size)
2644{ 2770{
2645 int i; 2771 int i;
2646 2772
@@ -2659,75 +2785,99 @@ static void unicode_to_ascii(char *string, int buflen, __le16 *unicode, int unic
2659 2785
2660/**************************************************************************** 2786/****************************************************************************
2661 * get_manufacturing_desc 2787 * get_manufacturing_desc
2662 * reads in the manufacturing descriptor and stores it into the serial 2788 * reads in the manufacturing descriptor and stores it into the serial
2663 * structure. 2789 * structure.
2664 ****************************************************************************/ 2790 ****************************************************************************/
2665static void get_manufacturing_desc (struct edgeport_serial *edge_serial) 2791static void get_manufacturing_desc(struct edgeport_serial *edge_serial)
2666{ 2792{
2667 int response; 2793 int response;
2668 2794
2669 dbg("getting manufacturer descriptor"); 2795 dbg("getting manufacturer descriptor");
2670 2796
2671 response = rom_read (edge_serial->serial, (EDGE_MANUF_DESC_ADDR & 0xffff0000) >> 16, 2797 response = rom_read(edge_serial->serial,
2672 (__u16)(EDGE_MANUF_DESC_ADDR & 0x0000ffff), EDGE_MANUF_DESC_LEN, 2798 (EDGE_MANUF_DESC_ADDR & 0xffff0000) >> 16,
2673 (__u8 *)(&edge_serial->manuf_descriptor)); 2799 (__u16)(EDGE_MANUF_DESC_ADDR & 0x0000ffff),
2800 EDGE_MANUF_DESC_LEN,
2801 (__u8 *)(&edge_serial->manuf_descriptor));
2674 2802
2675 if (response < 1) { 2803 if (response < 1)
2676 dev_err(&edge_serial->serial->dev->dev, "error in getting manufacturer descriptor\n"); 2804 dev_err(&edge_serial->serial->dev->dev,
2677 } else { 2805 "error in getting manufacturer descriptor\n");
2806 else {
2678 char string[30]; 2807 char string[30];
2679 dbg("**Manufacturer Descriptor"); 2808 dbg("**Manufacturer Descriptor");
2680 dbg(" RomSize: %dK", edge_serial->manuf_descriptor.RomSize); 2809 dbg(" RomSize: %dK",
2681 dbg(" RamSize: %dK", edge_serial->manuf_descriptor.RamSize); 2810 edge_serial->manuf_descriptor.RomSize);
2682 dbg(" CpuRev: %d", edge_serial->manuf_descriptor.CpuRev); 2811 dbg(" RamSize: %dK",
2683 dbg(" BoardRev: %d", edge_serial->manuf_descriptor.BoardRev); 2812 edge_serial->manuf_descriptor.RamSize);
2684 dbg(" NumPorts: %d", edge_serial->manuf_descriptor.NumPorts); 2813 dbg(" CpuRev: %d",
2685 dbg(" DescDate: %d/%d/%d", edge_serial->manuf_descriptor.DescDate[0], edge_serial->manuf_descriptor.DescDate[1], edge_serial->manuf_descriptor.DescDate[2]+1900); 2814 edge_serial->manuf_descriptor.CpuRev);
2815 dbg(" BoardRev: %d",
2816 edge_serial->manuf_descriptor.BoardRev);
2817 dbg(" NumPorts: %d",
2818 edge_serial->manuf_descriptor.NumPorts);
2819 dbg(" DescDate: %d/%d/%d",
2820 edge_serial->manuf_descriptor.DescDate[0],
2821 edge_serial->manuf_descriptor.DescDate[1],
2822 edge_serial->manuf_descriptor.DescDate[2]+1900);
2686 unicode_to_ascii(string, sizeof(string), 2823 unicode_to_ascii(string, sizeof(string),
2687 edge_serial->manuf_descriptor.SerialNumber, 2824 edge_serial->manuf_descriptor.SerialNumber,
2688 edge_serial->manuf_descriptor.SerNumLength/2); 2825 edge_serial->manuf_descriptor.SerNumLength/2);
2689 dbg(" SerialNumber: %s", string); 2826 dbg(" SerialNumber: %s", string);
2690 unicode_to_ascii(string, sizeof(string), 2827 unicode_to_ascii(string, sizeof(string),
2691 edge_serial->manuf_descriptor.AssemblyNumber, 2828 edge_serial->manuf_descriptor.AssemblyNumber,
2692 edge_serial->manuf_descriptor.AssemblyNumLength/2); 2829 edge_serial->manuf_descriptor.AssemblyNumLength/2);
2693 dbg(" AssemblyNumber: %s", string); 2830 dbg(" AssemblyNumber: %s", string);
2694 unicode_to_ascii(string, sizeof(string), 2831 unicode_to_ascii(string, sizeof(string),
2695 edge_serial->manuf_descriptor.OemAssyNumber, 2832 edge_serial->manuf_descriptor.OemAssyNumber,
2696 edge_serial->manuf_descriptor.OemAssyNumLength/2); 2833 edge_serial->manuf_descriptor.OemAssyNumLength/2);
2697 dbg(" OemAssyNumber: %s", string); 2834 dbg(" OemAssyNumber: %s", string);
2698 dbg(" UartType: %d", edge_serial->manuf_descriptor.UartType); 2835 dbg(" UartType: %d",
2699 dbg(" IonPid: %d", edge_serial->manuf_descriptor.IonPid); 2836 edge_serial->manuf_descriptor.UartType);
2700 dbg(" IonConfig: %d", edge_serial->manuf_descriptor.IonConfig); 2837 dbg(" IonPid: %d",
2838 edge_serial->manuf_descriptor.IonPid);
2839 dbg(" IonConfig: %d",
2840 edge_serial->manuf_descriptor.IonConfig);
2701 } 2841 }
2702} 2842}
2703 2843
2704 2844
2705/**************************************************************************** 2845/****************************************************************************
2706 * get_boot_desc 2846 * get_boot_desc
2707 * reads in the bootloader descriptor and stores it into the serial 2847 * reads in the bootloader descriptor and stores it into the serial
2708 * structure. 2848 * structure.
2709 ****************************************************************************/ 2849 ****************************************************************************/
2710static void get_boot_desc (struct edgeport_serial *edge_serial) 2850static void get_boot_desc(struct edgeport_serial *edge_serial)
2711{ 2851{
2712 int response; 2852 int response;
2713 2853
2714 dbg("getting boot descriptor"); 2854 dbg("getting boot descriptor");
2715 2855
2716 response = rom_read (edge_serial->serial, (EDGE_BOOT_DESC_ADDR & 0xffff0000) >> 16, 2856 response = rom_read(edge_serial->serial,
2717 (__u16)(EDGE_BOOT_DESC_ADDR & 0x0000ffff), EDGE_BOOT_DESC_LEN, 2857 (EDGE_BOOT_DESC_ADDR & 0xffff0000) >> 16,
2718 (__u8 *)(&edge_serial->boot_descriptor)); 2858 (__u16)(EDGE_BOOT_DESC_ADDR & 0x0000ffff),
2859 EDGE_BOOT_DESC_LEN,
2860 (__u8 *)(&edge_serial->boot_descriptor));
2719 2861
2720 if (response < 1) { 2862 if (response < 1)
2721 dev_err(&edge_serial->serial->dev->dev, "error in getting boot descriptor\n"); 2863 dev_err(&edge_serial->serial->dev->dev,
2722 } else { 2864 "error in getting boot descriptor\n");
2865 else {
2723 dbg("**Boot Descriptor:"); 2866 dbg("**Boot Descriptor:");
2724 dbg(" BootCodeLength: %d", le16_to_cpu(edge_serial->boot_descriptor.BootCodeLength)); 2867 dbg(" BootCodeLength: %d",
2725 dbg(" MajorVersion: %d", edge_serial->boot_descriptor.MajorVersion); 2868 le16_to_cpu(edge_serial->boot_descriptor.BootCodeLength));
2726 dbg(" MinorVersion: %d", edge_serial->boot_descriptor.MinorVersion); 2869 dbg(" MajorVersion: %d",
2727 dbg(" BuildNumber: %d", le16_to_cpu(edge_serial->boot_descriptor.BuildNumber)); 2870 edge_serial->boot_descriptor.MajorVersion);
2728 dbg(" Capabilities: 0x%x", le16_to_cpu(edge_serial->boot_descriptor.Capabilities)); 2871 dbg(" MinorVersion: %d",
2729 dbg(" UConfig0: %d", edge_serial->boot_descriptor.UConfig0); 2872 edge_serial->boot_descriptor.MinorVersion);
2730 dbg(" UConfig1: %d", edge_serial->boot_descriptor.UConfig1); 2873 dbg(" BuildNumber: %d",
2874 le16_to_cpu(edge_serial->boot_descriptor.BuildNumber));
2875 dbg(" Capabilities: 0x%x",
2876 le16_to_cpu(edge_serial->boot_descriptor.Capabilities));
2877 dbg(" UConfig0: %d",
2878 edge_serial->boot_descriptor.UConfig0);
2879 dbg(" UConfig1: %d",
2880 edge_serial->boot_descriptor.UConfig1);
2731 } 2881 }
2732} 2882}
2733 2883
@@ -2736,7 +2886,7 @@ static void get_boot_desc (struct edgeport_serial *edge_serial)
2736 * load_application_firmware 2886 * load_application_firmware
2737 * This is called to load the application firmware to the device 2887 * This is called to load the application firmware to the device
2738 ****************************************************************************/ 2888 ****************************************************************************/
2739static void load_application_firmware (struct edgeport_serial *edge_serial) 2889static void load_application_firmware(struct edgeport_serial *edge_serial)
2740{ 2890{
2741 const struct ihex_binrec *rec; 2891 const struct ihex_binrec *rec;
2742 const struct firmware *fw; 2892 const struct firmware *fw;
@@ -2813,7 +2963,7 @@ static void load_application_firmware (struct edgeport_serial *edge_serial)
2813/**************************************************************************** 2963/****************************************************************************
2814 * edge_startup 2964 * edge_startup
2815 ****************************************************************************/ 2965 ****************************************************************************/
2816static int edge_startup (struct usb_serial *serial) 2966static int edge_startup(struct usb_serial *serial)
2817{ 2967{
2818 struct edgeport_serial *edge_serial; 2968 struct edgeport_serial *edge_serial;
2819 struct edgeport_port *edge_port; 2969 struct edgeport_port *edge_port;
@@ -2855,10 +3005,10 @@ static int edge_startup (struct usb_serial *serial)
2855 sizeof(struct edge_compatibility_bits)); 3005 sizeof(struct edge_compatibility_bits));
2856 3006
2857 /* get the manufacturing descriptor for this device */ 3007 /* get the manufacturing descriptor for this device */
2858 get_manufacturing_desc (edge_serial); 3008 get_manufacturing_desc(edge_serial);
2859 3009
2860 /* get the boot descriptor */ 3010 /* get the boot descriptor */
2861 get_boot_desc (edge_serial); 3011 get_boot_desc(edge_serial);
2862 3012
2863 get_product_info(edge_serial); 3013 get_product_info(edge_serial);
2864 } 3014 }
@@ -2879,41 +3029,43 @@ static int edge_startup (struct usb_serial *serial)
2879 /* If not an EPiC device */ 3029 /* If not an EPiC device */
2880 if (!edge_serial->is_epic) { 3030 if (!edge_serial->is_epic) {
2881 /* now load the application firmware into this device */ 3031 /* now load the application firmware into this device */
2882 load_application_firmware (edge_serial); 3032 load_application_firmware(edge_serial);
2883 3033
2884 dbg("%s - time 2 %ld", __func__, jiffies); 3034 dbg("%s - time 2 %ld", __func__, jiffies);
2885 3035
2886 /* Check current Edgeport EEPROM and update if necessary */ 3036 /* Check current Edgeport EEPROM and update if necessary */
2887 update_edgeport_E2PROM (edge_serial); 3037 update_edgeport_E2PROM(edge_serial);
2888 3038
2889 dbg("%s - time 3 %ld", __func__, jiffies); 3039 dbg("%s - time 3 %ld", __func__, jiffies);
2890 3040
2891 /* set the configuration to use #1 */ 3041 /* set the configuration to use #1 */
2892// dbg("set_configuration 1"); 3042/* dbg("set_configuration 1"); */
2893// usb_set_configuration (dev, 1); 3043/* usb_set_configuration (dev, 1); */
2894 } 3044 }
2895 dbg(" FirmwareMajorVersion %d.%d.%d", 3045 dbg(" FirmwareMajorVersion %d.%d.%d",
2896 edge_serial->product_info.FirmwareMajorVersion, 3046 edge_serial->product_info.FirmwareMajorVersion,
2897 edge_serial->product_info.FirmwareMinorVersion, 3047 edge_serial->product_info.FirmwareMinorVersion,
2898 le16_to_cpu(edge_serial->product_info.FirmwareBuildNumber)); 3048 le16_to_cpu(edge_serial->product_info.FirmwareBuildNumber));
2899 3049
2900 /* we set up the pointers to the endpoints in the edge_open function, 3050 /* we set up the pointers to the endpoints in the edge_open function,
2901 * as the structures aren't created yet. */ 3051 * as the structures aren't created yet. */
2902 3052
2903 /* set up our port private structures */ 3053 /* set up our port private structures */
2904 for (i = 0; i < serial->num_ports; ++i) { 3054 for (i = 0; i < serial->num_ports; ++i) {
2905 edge_port = kmalloc (sizeof(struct edgeport_port), GFP_KERNEL); 3055 edge_port = kmalloc(sizeof(struct edgeport_port), GFP_KERNEL);
2906 if (edge_port == NULL) { 3056 if (edge_port == NULL) {
2907 dev_err(&serial->dev->dev, "%s - Out of memory\n", __func__); 3057 dev_err(&serial->dev->dev, "%s - Out of memory\n",
3058 __func__);
2908 for (j = 0; j < i; ++j) { 3059 for (j = 0; j < i; ++j) {
2909 kfree (usb_get_serial_port_data(serial->port[j])); 3060 kfree(usb_get_serial_port_data(serial->port[j]));
2910 usb_set_serial_port_data(serial->port[j], NULL); 3061 usb_set_serial_port_data(serial->port[j],
3062 NULL);
2911 } 3063 }
2912 usb_set_serial_data(serial, NULL); 3064 usb_set_serial_data(serial, NULL);
2913 kfree(edge_serial); 3065 kfree(edge_serial);
2914 return -ENOMEM; 3066 return -ENOMEM;
2915 } 3067 }
2916 memset (edge_port, 0, sizeof(struct edgeport_port)); 3068 memset(edge_port, 0, sizeof(struct edgeport_port));
2917 spin_lock_init(&edge_port->ep_lock); 3069 spin_lock_init(&edge_port->ep_lock);
2918 edge_port->port = serial->port[i]; 3070 edge_port->port = serial->port[i];
2919 usb_set_serial_port_data(serial->port[i], edge_port); 3071 usb_set_serial_port_data(serial->port[i], edge_port);
@@ -2922,14 +3074,16 @@ static int edge_startup (struct usb_serial *serial)
2922 response = 0; 3074 response = 0;
2923 3075
2924 if (edge_serial->is_epic) { 3076 if (edge_serial->is_epic) {
2925 /* EPIC thing, set up our interrupt polling now and our read urb, so 3077 /* EPIC thing, set up our interrupt polling now and our read
2926 * that the device knows it really is connected. */ 3078 * urb, so that the device knows it really is connected. */
2927 interrupt_in_found = bulk_in_found = bulk_out_found = false; 3079 interrupt_in_found = bulk_in_found = bulk_out_found = false;
2928 for (i = 0; i < serial->interface->altsetting[0].desc.bNumEndpoints; ++i) { 3080 for (i = 0; i < serial->interface->altsetting[0]
3081 .desc.bNumEndpoints; ++i) {
2929 struct usb_endpoint_descriptor *endpoint; 3082 struct usb_endpoint_descriptor *endpoint;
2930 int buffer_size; 3083 int buffer_size;
2931 3084
2932 endpoint = &serial->interface->altsetting[0].endpoint[i].desc; 3085 endpoint = &serial->interface->altsetting[0].
3086 endpoint[i].desc;
2933 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 3087 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
2934 if (!interrupt_in_found && 3088 if (!interrupt_in_found &&
2935 (usb_endpoint_is_int_in(endpoint))) { 3089 (usb_endpoint_is_int_in(endpoint))) {
@@ -2937,58 +3091,67 @@ static int edge_startup (struct usb_serial *serial)
2937 dbg("found interrupt in"); 3091 dbg("found interrupt in");
2938 3092
2939 /* not set up yet, so do it now */ 3093 /* not set up yet, so do it now */
2940 edge_serial->interrupt_read_urb = usb_alloc_urb(0, GFP_KERNEL); 3094 edge_serial->interrupt_read_urb =
3095 usb_alloc_urb(0, GFP_KERNEL);
2941 if (!edge_serial->interrupt_read_urb) { 3096 if (!edge_serial->interrupt_read_urb) {
2942 err("out of memory"); 3097 err("out of memory");
2943 return -ENOMEM; 3098 return -ENOMEM;
2944 } 3099 }
2945 edge_serial->interrupt_in_buffer = kmalloc(buffer_size, GFP_KERNEL); 3100 edge_serial->interrupt_in_buffer =
3101 kmalloc(buffer_size, GFP_KERNEL);
2946 if (!edge_serial->interrupt_in_buffer) { 3102 if (!edge_serial->interrupt_in_buffer) {
2947 err("out of memory"); 3103 err("out of memory");
2948 usb_free_urb(edge_serial->interrupt_read_urb); 3104 usb_free_urb(edge_serial->interrupt_read_urb);
2949 return -ENOMEM; 3105 return -ENOMEM;
2950 } 3106 }
2951 edge_serial->interrupt_in_endpoint = endpoint->bEndpointAddress; 3107 edge_serial->interrupt_in_endpoint =
3108 endpoint->bEndpointAddress;
2952 3109
2953 /* set up our interrupt urb */ 3110 /* set up our interrupt urb */
2954 usb_fill_int_urb(edge_serial->interrupt_read_urb, 3111 usb_fill_int_urb(
2955 dev, 3112 edge_serial->interrupt_read_urb,
2956 usb_rcvintpipe(dev, endpoint->bEndpointAddress), 3113 dev,
2957 edge_serial->interrupt_in_buffer, 3114 usb_rcvintpipe(dev,
2958 buffer_size, 3115 endpoint->bEndpointAddress),
2959 edge_interrupt_callback, 3116 edge_serial->interrupt_in_buffer,
2960 edge_serial, 3117 buffer_size,
2961 endpoint->bInterval); 3118 edge_interrupt_callback,
3119 edge_serial,
3120 endpoint->bInterval);
2962 3121
2963 interrupt_in_found = true; 3122 interrupt_in_found = true;
2964 } 3123 }
2965 3124
2966 if (!bulk_in_found && 3125 if (!bulk_in_found &&
2967 (usb_endpoint_is_bulk_in(endpoint))) { 3126 (usb_endpoint_is_bulk_in(endpoint))) {
2968 /* we found a bulk in endpoint */ 3127 /* we found a bulk in endpoint */
2969 dbg("found bulk in"); 3128 dbg("found bulk in");
2970 3129
2971 /* not set up yet, so do it now */ 3130 /* not set up yet, so do it now */
2972 edge_serial->read_urb = usb_alloc_urb(0, GFP_KERNEL); 3131 edge_serial->read_urb =
3132 usb_alloc_urb(0, GFP_KERNEL);
2973 if (!edge_serial->read_urb) { 3133 if (!edge_serial->read_urb) {
2974 err("out of memory"); 3134 err("out of memory");
2975 return -ENOMEM; 3135 return -ENOMEM;
2976 } 3136 }
2977 edge_serial->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL); 3137 edge_serial->bulk_in_buffer =
3138 kmalloc(buffer_size, GFP_KERNEL);
2978 if (!edge_serial->bulk_in_buffer) { 3139 if (!edge_serial->bulk_in_buffer) {
2979 err ("out of memory"); 3140 err("out of memory");
2980 usb_free_urb(edge_serial->read_urb); 3141 usb_free_urb(edge_serial->read_urb);
2981 return -ENOMEM; 3142 return -ENOMEM;
2982 } 3143 }
2983 edge_serial->bulk_in_endpoint = endpoint->bEndpointAddress; 3144 edge_serial->bulk_in_endpoint =
3145 endpoint->bEndpointAddress;
2984 3146
2985 /* set up our bulk in urb */ 3147 /* set up our bulk in urb */
2986 usb_fill_bulk_urb(edge_serial->read_urb, dev, 3148 usb_fill_bulk_urb(edge_serial->read_urb, dev,
2987 usb_rcvbulkpipe(dev, endpoint->bEndpointAddress), 3149 usb_rcvbulkpipe(dev,
2988 edge_serial->bulk_in_buffer, 3150 endpoint->bEndpointAddress),
2989 le16_to_cpu(endpoint->wMaxPacketSize), 3151 edge_serial->bulk_in_buffer,
2990 edge_bulk_in_callback, 3152 le16_to_cpu(endpoint->wMaxPacketSize),
2991 edge_serial); 3153 edge_bulk_in_callback,
3154 edge_serial);
2992 bulk_in_found = true; 3155 bulk_in_found = true;
2993 } 3156 }
2994 3157
@@ -2996,21 +3159,24 @@ static int edge_startup (struct usb_serial *serial)
2996 (usb_endpoint_is_bulk_out(endpoint))) { 3159 (usb_endpoint_is_bulk_out(endpoint))) {
2997 /* we found a bulk out endpoint */ 3160 /* we found a bulk out endpoint */
2998 dbg("found bulk out"); 3161 dbg("found bulk out");
2999 edge_serial->bulk_out_endpoint = endpoint->bEndpointAddress; 3162 edge_serial->bulk_out_endpoint =
3163 endpoint->bEndpointAddress;
3000 bulk_out_found = true; 3164 bulk_out_found = true;
3001 } 3165 }
3002 } 3166 }
3003 3167
3004 if (!interrupt_in_found || !bulk_in_found || !bulk_out_found) { 3168 if (!interrupt_in_found || !bulk_in_found || !bulk_out_found) {
3005 err ("Error - the proper endpoints were not found!"); 3169 err("Error - the proper endpoints were not found!");
3006 return -ENODEV; 3170 return -ENODEV;
3007 } 3171 }
3008 3172
3009 /* start interrupt read for this edgeport this interrupt will 3173 /* start interrupt read for this edgeport this interrupt will
3010 * continue as long as the edgeport is connected */ 3174 * continue as long as the edgeport is connected */
3011 response = usb_submit_urb(edge_serial->interrupt_read_urb, GFP_KERNEL); 3175 response = usb_submit_urb(edge_serial->interrupt_read_urb,
3176 GFP_KERNEL);
3012 if (response) 3177 if (response)
3013 err("%s - Error %d submitting control urb", __func__, response); 3178 err("%s - Error %d submitting control urb",
3179 __func__, response);
3014 } 3180 }
3015 return response; 3181 return response;
3016} 3182}
@@ -3020,7 +3186,7 @@ static int edge_startup (struct usb_serial *serial)
3020 * edge_shutdown 3186 * edge_shutdown
3021 * This function is called whenever the device is removed from the usb bus. 3187 * This function is called whenever the device is removed from the usb bus.
3022 ****************************************************************************/ 3188 ****************************************************************************/
3023static void edge_shutdown (struct usb_serial *serial) 3189static void edge_shutdown(struct usb_serial *serial)
3024{ 3190{
3025 struct edgeport_serial *edge_serial = usb_get_serial_data(serial); 3191 struct edgeport_serial *edge_serial = usb_get_serial_data(serial);
3026 int i; 3192 int i;
@@ -3028,8 +3194,8 @@ static void edge_shutdown (struct usb_serial *serial)
3028 dbg("%s", __func__); 3194 dbg("%s", __func__);
3029 3195
3030 /* stop reads and writes on all ports */ 3196 /* stop reads and writes on all ports */
3031 for (i=0; i < serial->num_ports; ++i) { 3197 for (i = 0; i < serial->num_ports; ++i) {
3032 kfree (usb_get_serial_port_data(serial->port[i])); 3198 kfree(usb_get_serial_port_data(serial->port[i]));
3033 usb_set_serial_port_data(serial->port[i], NULL); 3199 usb_set_serial_port_data(serial->port[i], NULL);
3034 } 3200 }
3035 /* free up our endpoint stuff */ 3201 /* free up our endpoint stuff */
@@ -3069,7 +3235,7 @@ static int __init edgeport_init(void)
3069 if (retval) 3235 if (retval)
3070 goto failed_epic_device_register; 3236 goto failed_epic_device_register;
3071 retval = usb_register(&io_driver); 3237 retval = usb_register(&io_driver);
3072 if (retval) 3238 if (retval)
3073 goto failed_usb_register; 3239 goto failed_usb_register;
3074 atomic_set(&CmdUrbs, 0); 3240 atomic_set(&CmdUrbs, 0);
3075 info(DRIVER_DESC " " DRIVER_VERSION); 3241 info(DRIVER_DESC " " DRIVER_VERSION);
@@ -3094,19 +3260,19 @@ failed_2port_device_register:
3094 ****************************************************************************/ 3260 ****************************************************************************/
3095static void __exit edgeport_exit (void) 3261static void __exit edgeport_exit (void)
3096{ 3262{
3097 usb_deregister (&io_driver); 3263 usb_deregister(&io_driver);
3098 usb_serial_deregister (&edgeport_2port_device); 3264 usb_serial_deregister(&edgeport_2port_device);
3099 usb_serial_deregister (&edgeport_4port_device); 3265 usb_serial_deregister(&edgeport_4port_device);
3100 usb_serial_deregister (&edgeport_8port_device); 3266 usb_serial_deregister(&edgeport_8port_device);
3101 usb_serial_deregister (&epic_device); 3267 usb_serial_deregister(&epic_device);
3102} 3268}
3103 3269
3104module_init(edgeport_init); 3270module_init(edgeport_init);
3105module_exit(edgeport_exit); 3271module_exit(edgeport_exit);
3106 3272
3107/* Module information */ 3273/* Module information */
3108MODULE_AUTHOR( DRIVER_AUTHOR ); 3274MODULE_AUTHOR(DRIVER_AUTHOR);
3109MODULE_DESCRIPTION( DRIVER_DESC ); 3275MODULE_DESCRIPTION(DRIVER_DESC);
3110MODULE_LICENSE("GPL"); 3276MODULE_LICENSE("GPL");
3111MODULE_FIRMWARE("edgeport/boot.fw"); 3277MODULE_FIRMWARE("edgeport/boot.fw");
3112MODULE_FIRMWARE("edgeport/boot2.fw"); 3278MODULE_FIRMWARE("edgeport/boot2.fw");
diff --git a/drivers/usb/serial/io_tables.h b/drivers/usb/serial/io_tables.h
index 2ec85893f27a..7eb9d67b81b6 100644
--- a/drivers/usb/serial/io_tables.h
+++ b/drivers/usb/serial/io_tables.h
@@ -8,7 +8,7 @@
8 * it under the terms of the GNU General Public License as published by 8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or 9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version. 10 * (at your option) any later version.
11 * 11 *
12 */ 12 */
13 13
14#ifndef IO_TABLES_H 14#ifndef IO_TABLES_H
@@ -90,10 +90,10 @@ static struct usb_device_id id_table_combined [] = {
90 { USB_DEVICE(USB_VENDOR_ID_AXIOHM, AXIOHM_DEVICE_ID_EPIC_A758) }, 90 { USB_DEVICE(USB_VENDOR_ID_AXIOHM, AXIOHM_DEVICE_ID_EPIC_A758) },
91 { USB_DEVICE(USB_VENDOR_ID_AXIOHM, AXIOHM_DEVICE_ID_EPIC_A794) }, 91 { USB_DEVICE(USB_VENDOR_ID_AXIOHM, AXIOHM_DEVICE_ID_EPIC_A794) },
92 { USB_DEVICE(USB_VENDOR_ID_AXIOHM, AXIOHM_DEVICE_ID_EPIC_A225) }, 92 { USB_DEVICE(USB_VENDOR_ID_AXIOHM, AXIOHM_DEVICE_ID_EPIC_A225) },
93 { } /* Terminating entry */ 93 { } /* Terminating entry */
94}; 94};
95 95
96MODULE_DEVICE_TABLE (usb, id_table_combined); 96MODULE_DEVICE_TABLE(usb, id_table_combined);
97 97
98static struct usb_driver io_driver = { 98static struct usb_driver io_driver = {
99 .name = "io_edgeport", 99 .name = "io_edgeport",
diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index a58822a14a87..cb4c54316cf5 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -243,9 +243,9 @@ static void edge_tty_recv(struct device *dev, struct tty_struct *tty,
243static void stop_read(struct edgeport_port *edge_port); 243static void stop_read(struct edgeport_port *edge_port);
244static int restart_read(struct edgeport_port *edge_port); 244static int restart_read(struct edgeport_port *edge_port);
245 245
246static void edge_set_termios(struct usb_serial_port *port, 246static void edge_set_termios(struct tty_struct *tty,
247 struct ktermios *old_termios); 247 struct usb_serial_port *port, struct ktermios *old_termios);
248static void edge_send(struct usb_serial_port *port); 248static void edge_send(struct tty_struct *tty);
249 249
250/* sysfs attributes */ 250/* sysfs attributes */
251static int edge_create_sysfs_attrs(struct usb_serial_port *port); 251static int edge_create_sysfs_attrs(struct usb_serial_port *port);
@@ -572,7 +572,7 @@ static void chase_port(struct edgeport_port *port, unsigned long timeout,
572 int flush) 572 int flush)
573{ 573{
574 int baud_rate; 574 int baud_rate;
575 struct tty_struct *tty = port->port->tty; 575 struct tty_struct *tty = port->port->port.tty;
576 wait_queue_t wait; 576 wait_queue_t wait;
577 unsigned long flags; 577 unsigned long flags;
578 578
@@ -1554,7 +1554,7 @@ static void handle_new_msr(struct edgeport_port *edge_port, __u8 msr)
1554 /* Save the new modem status */ 1554 /* Save the new modem status */
1555 edge_port->shadow_msr = msr & 0xf0; 1555 edge_port->shadow_msr = msr & 0xf0;
1556 1556
1557 tty = edge_port->port->tty; 1557 tty = edge_port->port->port.tty;
1558 /* handle CTS flow control */ 1558 /* handle CTS flow control */
1559 if (tty && C_CRTSCTS(tty)) { 1559 if (tty && C_CRTSCTS(tty)) {
1560 if (msr & EDGEPORT_MSR_CTS) { 1560 if (msr & EDGEPORT_MSR_CTS) {
@@ -1587,9 +1587,8 @@ static void handle_new_lsr(struct edgeport_port *edge_port, int lsr_data,
1587 new_lsr &= (__u8)(LSR_OVER_ERR | LSR_BREAK); 1587 new_lsr &= (__u8)(LSR_OVER_ERR | LSR_BREAK);
1588 1588
1589 /* Place LSR data byte into Rx buffer */ 1589 /* Place LSR data byte into Rx buffer */
1590 if (lsr_data && edge_port->port->tty) 1590 if (lsr_data && edge_port->port->port.tty)
1591 edge_tty_recv(&edge_port->port->dev, edge_port->port->tty, 1591 edge_tty_recv(&edge_port->port->dev, edge_port->port->port.tty, &data, 1);
1592 &data, 1);
1593 1592
1594 /* update input line counters */ 1593 /* update input line counters */
1595 icount = &edge_port->icount; 1594 icount = &edge_port->icount;
@@ -1750,7 +1749,7 @@ static void edge_bulk_in_callback(struct urb *urb)
1750 ++data; 1749 ++data;
1751 } 1750 }
1752 1751
1753 tty = edge_port->port->tty; 1752 tty = edge_port->port->port.tty;
1754 if (tty && urb->actual_length) { 1753 if (tty && urb->actual_length) {
1755 usb_serial_debug_data(debug, &edge_port->port->dev, 1754 usb_serial_debug_data(debug, &edge_port->port->dev,
1756 __func__, urb->actual_length, data); 1755 __func__, urb->actual_length, data);
@@ -1819,10 +1818,11 @@ static void edge_bulk_out_callback(struct urb *urb)
1819 } 1818 }
1820 1819
1821 /* send any buffered data */ 1820 /* send any buffered data */
1822 edge_send(port); 1821 edge_send(port->port.tty);
1823} 1822}
1824 1823
1825static int edge_open(struct usb_serial_port *port, struct file *filp) 1824static int edge_open(struct tty_struct *tty,
1825 struct usb_serial_port *port, struct file *filp)
1826{ 1826{
1827 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1827 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1828 struct edgeport_serial *edge_serial; 1828 struct edgeport_serial *edge_serial;
@@ -1838,7 +1838,8 @@ static int edge_open(struct usb_serial_port *port, struct file *filp)
1838 if (edge_port == NULL) 1838 if (edge_port == NULL)
1839 return -ENODEV; 1839 return -ENODEV;
1840 1840
1841 port->tty->low_latency = low_latency; 1841 if (tty)
1842 tty->low_latency = low_latency;
1842 1843
1843 port_number = port->number - port->serial->minor; 1844 port_number = port->number - port->serial->minor;
1844 switch (port_number) { 1845 switch (port_number) {
@@ -1874,7 +1875,8 @@ static int edge_open(struct usb_serial_port *port, struct file *filp)
1874 } 1875 }
1875 1876
1876 /* set up the port settings */ 1877 /* set up the port settings */
1877 edge_set_termios(port, port->tty->termios); 1878 if (tty)
1879 edge_set_termios(tty, port, port->port.tty->termios);
1878 1880
1879 /* open up the port */ 1881 /* open up the port */
1880 1882
@@ -2000,7 +2002,8 @@ release_es_lock:
2000 return status; 2002 return status;
2001} 2003}
2002 2004
2003static void edge_close(struct usb_serial_port *port, struct file *filp) 2005static void edge_close(struct tty_struct *tty,
2006 struct usb_serial_port *port, struct file *filp)
2004{ 2007{
2005 struct edgeport_serial *edge_serial; 2008 struct edgeport_serial *edge_serial;
2006 struct edgeport_port *edge_port; 2009 struct edgeport_port *edge_port;
@@ -2048,8 +2051,8 @@ static void edge_close(struct usb_serial_port *port, struct file *filp)
2048 dbg("%s - exited", __func__); 2051 dbg("%s - exited", __func__);
2049} 2052}
2050 2053
2051static int edge_write(struct usb_serial_port *port, const unsigned char *data, 2054static int edge_write(struct tty_struct *tty, struct usb_serial_port *port,
2052 int count) 2055 const unsigned char *data, int count)
2053{ 2056{
2054 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2057 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2055 unsigned long flags; 2058 unsigned long flags;
@@ -2070,16 +2073,16 @@ static int edge_write(struct usb_serial_port *port, const unsigned char *data,
2070 count = edge_buf_put(edge_port->ep_out_buf, data, count); 2073 count = edge_buf_put(edge_port->ep_out_buf, data, count);
2071 spin_unlock_irqrestore(&edge_port->ep_lock, flags); 2074 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2072 2075
2073 edge_send(port); 2076 edge_send(tty);
2074 2077
2075 return count; 2078 return count;
2076} 2079}
2077 2080
2078static void edge_send(struct usb_serial_port *port) 2081static void edge_send(struct tty_struct *tty)
2079{ 2082{
2083 struct usb_serial_port *port = tty->driver_data;
2080 int count, result; 2084 int count, result;
2081 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2085 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2082 struct tty_struct *tty = port->tty;
2083 unsigned long flags; 2086 unsigned long flags;
2084 2087
2085 2088
@@ -2133,8 +2136,9 @@ static void edge_send(struct usb_serial_port *port)
2133 tty_wakeup(tty); 2136 tty_wakeup(tty);
2134} 2137}
2135 2138
2136static int edge_write_room(struct usb_serial_port *port) 2139static int edge_write_room(struct tty_struct *tty)
2137{ 2140{
2141 struct usb_serial_port *port = tty->driver_data;
2138 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2142 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2139 int room = 0; 2143 int room = 0;
2140 unsigned long flags; 2144 unsigned long flags;
@@ -2154,8 +2158,9 @@ static int edge_write_room(struct usb_serial_port *port)
2154 return room; 2158 return room;
2155} 2159}
2156 2160
2157static int edge_chars_in_buffer(struct usb_serial_port *port) 2161static int edge_chars_in_buffer(struct tty_struct *tty)
2158{ 2162{
2163 struct usb_serial_port *port = tty->driver_data;
2159 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2164 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2160 int chars = 0; 2165 int chars = 0;
2161 unsigned long flags; 2166 unsigned long flags;
@@ -2175,10 +2180,10 @@ static int edge_chars_in_buffer(struct usb_serial_port *port)
2175 return chars; 2180 return chars;
2176} 2181}
2177 2182
2178static void edge_throttle(struct usb_serial_port *port) 2183static void edge_throttle(struct tty_struct *tty)
2179{ 2184{
2185 struct usb_serial_port *port = tty->driver_data;
2180 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2186 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2181 struct tty_struct *tty = port->tty;
2182 int status; 2187 int status;
2183 2188
2184 dbg("%s - port %d", __func__, port->number); 2189 dbg("%s - port %d", __func__, port->number);
@@ -2189,11 +2194,10 @@ static void edge_throttle(struct usb_serial_port *port)
2189 /* if we are implementing XON/XOFF, send the stop character */ 2194 /* if we are implementing XON/XOFF, send the stop character */
2190 if (I_IXOFF(tty)) { 2195 if (I_IXOFF(tty)) {
2191 unsigned char stop_char = STOP_CHAR(tty); 2196 unsigned char stop_char = STOP_CHAR(tty);
2192 status = edge_write(port, &stop_char, 1); 2197 status = edge_write(tty, port, &stop_char, 1);
2193 if (status <= 0) 2198 if (status <= 0) {
2194 dev_err(&port->dev, 2199 dev_err(&port->dev, "%s - failed to write stop character, %d\n", __func__, status);
2195 "%s - failed to write stop character, %d\n", 2200 }
2196 __func__, status);
2197 } 2201 }
2198 2202
2199 /* if we are implementing RTS/CTS, stop reads */ 2203 /* if we are implementing RTS/CTS, stop reads */
@@ -2203,10 +2207,10 @@ static void edge_throttle(struct usb_serial_port *port)
2203 2207
2204} 2208}
2205 2209
2206static void edge_unthrottle(struct usb_serial_port *port) 2210static void edge_unthrottle(struct tty_struct *tty)
2207{ 2211{
2212 struct usb_serial_port *port = tty->driver_data;
2208 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2213 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2209 struct tty_struct *tty = port->tty;
2210 int status; 2214 int status;
2211 2215
2212 dbg("%s - port %d", __func__, port->number); 2216 dbg("%s - port %d", __func__, port->number);
@@ -2217,11 +2221,10 @@ static void edge_unthrottle(struct usb_serial_port *port)
2217 /* if we are implementing XON/XOFF, send the start character */ 2221 /* if we are implementing XON/XOFF, send the start character */
2218 if (I_IXOFF(tty)) { 2222 if (I_IXOFF(tty)) {
2219 unsigned char start_char = START_CHAR(tty); 2223 unsigned char start_char = START_CHAR(tty);
2220 status = edge_write(port, &start_char, 1); 2224 status = edge_write(tty, port, &start_char, 1);
2221 if (status <= 0) 2225 if (status <= 0) {
2222 dev_err(&port->dev, 2226 dev_err(&port->dev, "%s - failed to write start character, %d\n", __func__, status);
2223 "%s - failed to write start character, %d\n", 2227 }
2224 __func__, status);
2225 } 2228 }
2226 /* if we are implementing RTS/CTS, restart reads */ 2229 /* if we are implementing RTS/CTS, restart reads */
2227 /* are the Edgeport will assert the RTS line */ 2230 /* are the Edgeport will assert the RTS line */
@@ -2271,11 +2274,10 @@ static int restart_read(struct edgeport_port *edge_port)
2271 return status; 2274 return status;
2272} 2275}
2273 2276
2274static void change_port_settings(struct edgeport_port *edge_port, 2277static void change_port_settings(struct tty_struct *tty,
2275 struct ktermios *old_termios) 2278 struct edgeport_port *edge_port, struct ktermios *old_termios)
2276{ 2279{
2277 struct ump_uart_config *config; 2280 struct ump_uart_config *config;
2278 struct tty_struct *tty;
2279 int baud; 2281 int baud;
2280 unsigned cflag; 2282 unsigned cflag;
2281 int status; 2283 int status;
@@ -2284,9 +2286,7 @@ static void change_port_settings(struct edgeport_port *edge_port,
2284 2286
2285 dbg("%s - port %d", __func__, edge_port->port->number); 2287 dbg("%s - port %d", __func__, edge_port->port->number);
2286 2288
2287 tty = edge_port->port->tty; 2289 config = kmalloc (sizeof (*config), GFP_KERNEL);
2288
2289 config = kmalloc(sizeof(*config), GFP_KERNEL);
2290 if (!config) { 2290 if (!config) {
2291 *tty->termios = *old_termios; 2291 *tty->termios = *old_termios;
2292 dev_err(&edge_port->port->dev, "%s - out of memory\n", 2292 dev_err(&edge_port->port->dev, "%s - out of memory\n",
@@ -2419,11 +2419,13 @@ static void change_port_settings(struct edgeport_port *edge_port,
2419 return; 2419 return;
2420} 2420}
2421 2421
2422static void edge_set_termios(struct usb_serial_port *port, 2422static void edge_set_termios(struct tty_struct *tty,
2423 struct ktermios *old_termios) 2423 struct usb_serial_port *port, struct ktermios *old_termios)
2424{ 2424{
2425 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2425 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2426 struct tty_struct *tty = port->tty; 2426 unsigned int cflag;
2427
2428 cflag = tty->termios->c_cflag;
2427 2429
2428 dbg("%s - clfag %08x iflag %08x", __func__, 2430 dbg("%s - clfag %08x iflag %08x", __func__,
2429 tty->termios->c_cflag, tty->termios->c_iflag); 2431 tty->termios->c_cflag, tty->termios->c_iflag);
@@ -2434,12 +2436,14 @@ static void edge_set_termios(struct usb_serial_port *port,
2434 if (edge_port == NULL) 2436 if (edge_port == NULL)
2435 return; 2437 return;
2436 /* change the port settings to the new ones specified */ 2438 /* change the port settings to the new ones specified */
2437 change_port_settings(edge_port, old_termios); 2439 change_port_settings(tty, edge_port, old_termios);
2440 return;
2438} 2441}
2439 2442
2440static int edge_tiocmset(struct usb_serial_port *port, struct file *file, 2443static int edge_tiocmset(struct tty_struct *tty, struct file *file,
2441 unsigned int set, unsigned int clear) 2444 unsigned int set, unsigned int clear)
2442{ 2445{
2446 struct usb_serial_port *port = tty->driver_data;
2443 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2447 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2444 unsigned int mcr; 2448 unsigned int mcr;
2445 unsigned long flags; 2449 unsigned long flags;
@@ -2469,8 +2473,9 @@ static int edge_tiocmset(struct usb_serial_port *port, struct file *file,
2469 return 0; 2473 return 0;
2470} 2474}
2471 2475
2472static int edge_tiocmget(struct usb_serial_port *port, struct file *file) 2476static int edge_tiocmget(struct tty_struct *tty, struct file *file)
2473{ 2477{
2478 struct usb_serial_port *port = tty->driver_data;
2474 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2479 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2475 unsigned int result = 0; 2480 unsigned int result = 0;
2476 unsigned int msr; 2481 unsigned int msr;
@@ -2522,9 +2527,10 @@ static int get_serial_info(struct edgeport_port *edge_port,
2522 return 0; 2527 return 0;
2523} 2528}
2524 2529
2525static int edge_ioctl(struct usb_serial_port *port, struct file *file, 2530static int edge_ioctl(struct tty_struct *tty, struct file *file,
2526 unsigned int cmd, unsigned long arg) 2531 unsigned int cmd, unsigned long arg)
2527{ 2532{
2533 struct usb_serial_port *port = tty->driver_data;
2528 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2534 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2529 struct async_icount cnow; 2535 struct async_icount cnow;
2530 struct async_icount cprev; 2536 struct async_icount cprev;
@@ -2569,18 +2575,19 @@ static int edge_ioctl(struct usb_serial_port *port, struct file *file,
2569 return -ENOIOCTLCMD; 2575 return -ENOIOCTLCMD;
2570} 2576}
2571 2577
2572static void edge_break(struct usb_serial_port *port, int on) 2578static void edge_break(struct tty_struct *tty, int break_state)
2573{ 2579{
2580 struct usb_serial_port *port = tty->driver_data;
2574 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2581 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2575 int status; 2582 int status;
2576 int bv = 0; /* Off */ 2583 int bv = 0; /* Off */
2577 2584
2578 dbg("%s - state = %d", __func__, on); 2585 dbg("%s - state = %d", __func__, break_state);
2579 2586
2580 /* chase the port close */ 2587 /* chase the port close */
2581 chase_port(edge_port, 0, 0); 2588 chase_port(edge_port, 0, 0);
2582 2589
2583 if (on == -1) 2590 if (break_state == -1)
2584 bv = 1; /* On */ 2591 bv = 1; /* On */
2585 status = ti_do_config(edge_port, UMPC_SET_CLR_BREAK, bv); 2592 status = ti_do_config(edge_port, UMPC_SET_CLR_BREAK, bv);
2586 if (status) 2593 if (status)
diff --git a/drivers/usb/serial/ipaq.c b/drivers/usb/serial/ipaq.c
index 80d9ec5570d6..832a5a4f3cb3 100644
--- a/drivers/usb/serial/ipaq.c
+++ b/drivers/usb/serial/ipaq.c
@@ -53,7 +53,7 @@
53#include <linux/tty_flip.h> 53#include <linux/tty_flip.h>
54#include <linux/module.h> 54#include <linux/module.h>
55#include <linux/spinlock.h> 55#include <linux/spinlock.h>
56#include <asm/uaccess.h> 56#include <linux/uaccess.h>
57#include <linux/usb.h> 57#include <linux/usb.h>
58#include <linux/usb/serial.h> 58#include <linux/usb/serial.h>
59#include "ipaq.h" 59#include "ipaq.h"
@@ -74,19 +74,21 @@ static int connect_retries = KP_RETRIES;
74static int initial_wait; 74static int initial_wait;
75 75
76/* Function prototypes for an ipaq */ 76/* Function prototypes for an ipaq */
77static int ipaq_open (struct usb_serial_port *port, struct file *filp); 77static int ipaq_open(struct tty_struct *tty,
78static void ipaq_close (struct usb_serial_port *port, struct file *filp); 78 struct usb_serial_port *port, struct file *filp);
79static int ipaq_startup (struct usb_serial *serial); 79static void ipaq_close(struct tty_struct *tty,
80static void ipaq_shutdown (struct usb_serial *serial); 80 struct usb_serial_port *port, struct file *filp);
81static int ipaq_write(struct usb_serial_port *port, const unsigned char *buf, 81static int ipaq_startup(struct usb_serial *serial);
82 int count); 82static void ipaq_shutdown(struct usb_serial *serial);
83static int ipaq_write_bulk(struct usb_serial_port *port, const unsigned char *buf, 83static int ipaq_write(struct tty_struct *tty, struct usb_serial_port *port,
84 int count); 84 const unsigned char *buf, int count);
85static int ipaq_write_bulk(struct usb_serial_port *port,
86 const unsigned char *buf, int count);
85static void ipaq_write_gather(struct usb_serial_port *port); 87static void ipaq_write_gather(struct usb_serial_port *port);
86static void ipaq_read_bulk_callback (struct urb *urb); 88static void ipaq_read_bulk_callback(struct urb *urb);
87static void ipaq_write_bulk_callback(struct urb *urb); 89static void ipaq_write_bulk_callback(struct urb *urb);
88static int ipaq_write_room(struct usb_serial_port *port); 90static int ipaq_write_room(struct tty_struct *tty);
89static int ipaq_chars_in_buffer(struct usb_serial_port *port); 91static int ipaq_chars_in_buffer(struct tty_struct *tty);
90static void ipaq_destroy_lists(struct usb_serial_port *port); 92static void ipaq_destroy_lists(struct usb_serial_port *port);
91 93
92 94
@@ -550,7 +552,7 @@ static struct usb_device_id ipaq_id_table [] = {
550 { } /* Terminating entry */ 552 { } /* Terminating entry */
551}; 553};
552 554
553MODULE_DEVICE_TABLE (usb, ipaq_id_table); 555MODULE_DEVICE_TABLE(usb, ipaq_id_table);
554 556
555static struct usb_driver ipaq_driver = { 557static struct usb_driver ipaq_driver = {
556 .name = "ipaq", 558 .name = "ipaq",
@@ -591,7 +593,8 @@ static spinlock_t write_list_lock;
591static int bytes_in; 593static int bytes_in;
592static int bytes_out; 594static int bytes_out;
593 595
594static int ipaq_open(struct usb_serial_port *port, struct file *filp) 596static int ipaq_open(struct tty_struct *tty,
597 struct usb_serial_port *port, struct file *filp)
595{ 598{
596 struct usb_serial *serial = port->serial; 599 struct usb_serial *serial = port->serial;
597 struct ipaq_private *priv; 600 struct ipaq_private *priv;
@@ -617,9 +620,9 @@ static int ipaq_open(struct usb_serial_port *port, struct file *filp)
617 620
618 for (i = 0; i < URBDATA_QUEUE_MAX / PACKET_SIZE; i++) { 621 for (i = 0; i < URBDATA_QUEUE_MAX / PACKET_SIZE; i++) {
619 pkt = kmalloc(sizeof(struct ipaq_packet), GFP_KERNEL); 622 pkt = kmalloc(sizeof(struct ipaq_packet), GFP_KERNEL);
620 if (pkt == NULL) { 623 if (pkt == NULL)
621 goto enomem; 624 goto enomem;
622 } 625
623 pkt->data = kmalloc(PACKET_SIZE, GFP_KERNEL); 626 pkt->data = kmalloc(PACKET_SIZE, GFP_KERNEL);
624 if (pkt->data == NULL) { 627 if (pkt->data == NULL) {
625 kfree(pkt); 628 kfree(pkt);
@@ -637,10 +640,12 @@ static int ipaq_open(struct usb_serial_port *port, struct file *filp)
637 * discipline instead of queueing. 640 * discipline instead of queueing.
638 */ 641 */
639 642
640 port->tty->low_latency = 1; 643 if (tty) {
641 port->tty->raw = 1; 644 tty->low_latency = 1;
642 port->tty->real_raw = 1; 645 /* FIXME: These two are bogus */
643 646 tty->raw = 1;
647 tty->real_raw = 1;
648 }
644 /* 649 /*
645 * Lose the small buffers usbserial provides. Make larger ones. 650 * Lose the small buffers usbserial provides. Make larger ones.
646 */ 651 */
@@ -662,8 +667,9 @@ static int ipaq_open(struct usb_serial_port *port, struct file *filp)
662 port->read_urb->transfer_buffer = port->bulk_in_buffer; 667 port->read_urb->transfer_buffer = port->bulk_in_buffer;
663 port->write_urb->transfer_buffer = port->bulk_out_buffer; 668 port->write_urb->transfer_buffer = port->bulk_out_buffer;
664 port->read_urb->transfer_buffer_length = URBDATA_SIZE; 669 port->read_urb->transfer_buffer_length = URBDATA_SIZE;
665 port->bulk_out_size = port->write_urb->transfer_buffer_length = URBDATA_SIZE; 670 port->bulk_out_size = port->write_urb->transfer_buffer_length
666 671 = URBDATA_SIZE;
672
667 msleep(1000*initial_wait); 673 msleep(1000*initial_wait);
668 674
669 /* 675 /*
@@ -692,13 +698,15 @@ static int ipaq_open(struct usb_serial_port *port, struct file *filp)
692 698
693 /* Start reading from the device */ 699 /* Start reading from the device */
694 usb_fill_bulk_urb(port->read_urb, serial->dev, 700 usb_fill_bulk_urb(port->read_urb, serial->dev,
695 usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), 701 usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress),
696 port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, 702 port->read_urb->transfer_buffer,
697 ipaq_read_bulk_callback, port); 703 port->read_urb->transfer_buffer_length,
704 ipaq_read_bulk_callback, port);
698 705
699 result = usb_submit_urb(port->read_urb, GFP_KERNEL); 706 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
700 if (result) { 707 if (result) {
701 err("%s - failed submitting read urb, error %d", __func__, result); 708 err("%s - failed submitting read urb, error %d",
709 __func__, result);
702 goto error; 710 goto error;
703 } 711 }
704 712
@@ -714,12 +722,13 @@ error:
714} 722}
715 723
716 724
717static void ipaq_close(struct usb_serial_port *port, struct file *filp) 725static void ipaq_close(struct tty_struct *tty,
726 struct usb_serial_port *port, struct file *filp)
718{ 727{
719 struct ipaq_private *priv = usb_get_serial_port_data(port); 728 struct ipaq_private *priv = usb_get_serial_port_data(port);
720 729
721 dbg("%s - port %d", __func__, port->number); 730 dbg("%s - port %d", __func__, port->number);
722 731
723 /* 732 /*
724 * shut down bulk read and write 733 * shut down bulk read and write
725 */ 734 */
@@ -729,7 +738,8 @@ static void ipaq_close(struct usb_serial_port *port, struct file *filp)
729 kfree(priv); 738 kfree(priv);
730 usb_set_serial_port_data(port, NULL); 739 usb_set_serial_port_data(port, NULL);
731 740
732 /* Uncomment the following line if you want to see some statistics in your syslog */ 741 /* Uncomment the following line if you want to see some statistics
742 * in your syslog */
733 /* info ("Bytes In = %d Bytes Out = %d", bytes_in, bytes_out); */ 743 /* info ("Bytes In = %d Bytes Out = %d", bytes_in, bytes_out); */
734} 744}
735 745
@@ -749,9 +759,10 @@ static void ipaq_read_bulk_callback(struct urb *urb)
749 return; 759 return;
750 } 760 }
751 761
752 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); 762 usb_serial_debug_data(debug, &port->dev, __func__,
763 urb->actual_length, data);
753 764
754 tty = port->tty; 765 tty = port->port.tty;
755 if (tty && urb->actual_length) { 766 if (tty && urb->actual_length) {
756 tty_buffer_request_room(tty, urb->actual_length); 767 tty_buffer_request_room(tty, urb->actual_length);
757 tty_insert_flip_string(tty, data, urb->actual_length); 768 tty_insert_flip_string(tty, data, urb->actual_length);
@@ -760,18 +771,20 @@ static void ipaq_read_bulk_callback(struct urb *urb)
760 } 771 }
761 772
762 /* Continue trying to always read */ 773 /* Continue trying to always read */
763 usb_fill_bulk_urb(port->read_urb, port->serial->dev, 774 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
764 usb_rcvbulkpipe(port->serial->dev, port->bulk_in_endpointAddress), 775 usb_rcvbulkpipe(port->serial->dev, port->bulk_in_endpointAddress),
765 port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, 776 port->read_urb->transfer_buffer,
766 ipaq_read_bulk_callback, port); 777 port->read_urb->transfer_buffer_length,
778 ipaq_read_bulk_callback, port);
767 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 779 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
768 if (result) 780 if (result)
769 err("%s - failed resubmitting read urb, error %d", __func__, result); 781 err("%s - failed resubmitting read urb, error %d",
782 __func__, result);
770 return; 783 return;
771} 784}
772 785
773static int ipaq_write(struct usb_serial_port *port, const unsigned char *buf, 786static int ipaq_write(struct tty_struct *tty, struct usb_serial_port *port,
774 int count) 787 const unsigned char *buf, int count)
775{ 788{
776 const unsigned char *current_position = buf; 789 const unsigned char *current_position = buf;
777 int bytes_sent = 0; 790 int bytes_sent = 0;
@@ -781,9 +794,8 @@ static int ipaq_write(struct usb_serial_port *port, const unsigned char *buf,
781 794
782 while (count > 0) { 795 while (count > 0) {
783 transfer_size = min(count, PACKET_SIZE); 796 transfer_size = min(count, PACKET_SIZE);
784 if (ipaq_write_bulk(port, current_position, transfer_size)) { 797 if (ipaq_write_bulk(port, current_position, transfer_size))
785 break; 798 break;
786 }
787 current_position += transfer_size; 799 current_position += transfer_size;
788 bytes_sent += transfer_size; 800 bytes_sent += transfer_size;
789 count -= transfer_size; 801 count -= transfer_size;
@@ -791,10 +803,10 @@ static int ipaq_write(struct usb_serial_port *port, const unsigned char *buf,
791 } 803 }
792 804
793 return bytes_sent; 805 return bytes_sent;
794} 806}
795 807
796static int ipaq_write_bulk(struct usb_serial_port *port, const unsigned char *buf, 808static int ipaq_write_bulk(struct usb_serial_port *port,
797 int count) 809 const unsigned char *buf, int count)
798{ 810{
799 struct ipaq_private *priv = usb_get_serial_port_data(port); 811 struct ipaq_private *priv = usb_get_serial_port_data(port);
800 struct ipaq_packet *pkt = NULL; 812 struct ipaq_packet *pkt = NULL;
@@ -831,9 +843,9 @@ static int ipaq_write_bulk(struct usb_serial_port *port, const unsigned char *bu
831 ipaq_write_gather(port); 843 ipaq_write_gather(port);
832 spin_unlock_irqrestore(&write_list_lock, flags); 844 spin_unlock_irqrestore(&write_list_lock, flags);
833 result = usb_submit_urb(port->write_urb, GFP_ATOMIC); 845 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
834 if (result) { 846 if (result)
835 err("%s - failed submitting write urb, error %d", __func__, result); 847 err("%s - failed submitting write urb, error %d",
836 } 848 __func__, result);
837 } else { 849 } else {
838 spin_unlock_irqrestore(&write_list_lock, flags); 850 spin_unlock_irqrestore(&write_list_lock, flags);
839 } 851 }
@@ -860,16 +872,15 @@ static void ipaq_write_gather(struct usb_serial_port *port)
860 list_move(&pkt->list, &priv->freelist); 872 list_move(&pkt->list, &priv->freelist);
861 priv->free_len += PACKET_SIZE; 873 priv->free_len += PACKET_SIZE;
862 } 874 }
863 if (room == 0) { 875 if (room == 0)
864 break; 876 break;
865 }
866 } 877 }
867 878
868 count = URBDATA_SIZE - room; 879 count = URBDATA_SIZE - room;
869 usb_fill_bulk_urb(port->write_urb, serial->dev, 880 usb_fill_bulk_urb(port->write_urb, serial->dev,
870 usb_sndbulkpipe(serial->dev, port->bulk_out_endpointAddress), 881 usb_sndbulkpipe(serial->dev, port->bulk_out_endpointAddress),
871 port->write_urb->transfer_buffer, count, ipaq_write_bulk_callback, 882 port->write_urb->transfer_buffer, count,
872 port); 883 ipaq_write_bulk_callback, port);
873 return; 884 return;
874} 885}
875 886
@@ -894,9 +905,9 @@ static void ipaq_write_bulk_callback(struct urb *urb)
894 ipaq_write_gather(port); 905 ipaq_write_gather(port);
895 spin_unlock_irqrestore(&write_list_lock, flags); 906 spin_unlock_irqrestore(&write_list_lock, flags);
896 result = usb_submit_urb(port->write_urb, GFP_ATOMIC); 907 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
897 if (result) { 908 if (result)
898 err("%s - failed submitting write urb, error %d", __func__, result); 909 err("%s - failed submitting write urb, error %d",
899 } 910 __func__, result);
900 } else { 911 } else {
901 priv->active = 0; 912 priv->active = 0;
902 spin_unlock_irqrestore(&write_list_lock, flags); 913 spin_unlock_irqrestore(&write_list_lock, flags);
@@ -905,16 +916,18 @@ static void ipaq_write_bulk_callback(struct urb *urb)
905 usb_serial_port_softint(port); 916 usb_serial_port_softint(port);
906} 917}
907 918
908static int ipaq_write_room(struct usb_serial_port *port) 919static int ipaq_write_room(struct tty_struct *tty)
909{ 920{
921 struct usb_serial_port *port = tty->driver_data;
910 struct ipaq_private *priv = usb_get_serial_port_data(port); 922 struct ipaq_private *priv = usb_get_serial_port_data(port);
911 923
912 dbg("%s - freelen %d", __func__, priv->free_len); 924 dbg("%s - freelen %d", __func__, priv->free_len);
913 return priv->free_len; 925 return priv->free_len;
914} 926}
915 927
916static int ipaq_chars_in_buffer(struct usb_serial_port *port) 928static int ipaq_chars_in_buffer(struct tty_struct *tty)
917{ 929{
930 struct usb_serial_port *port = tty->driver_data;
918 struct ipaq_private *priv = usb_get_serial_port_data(port); 931 struct ipaq_private *priv = usb_get_serial_port_data(port);
919 932
920 dbg("%s - queuelen %d", __func__, priv->queue_len); 933 dbg("%s - queuelen %d", __func__, priv->queue_len);
@@ -945,7 +958,7 @@ static int ipaq_startup(struct usb_serial *serial)
945 serial->dev->actconfig->desc.bConfigurationValue); 958 serial->dev->actconfig->desc.bConfigurationValue);
946 return -ENODEV; 959 return -ENODEV;
947 } 960 }
948 return usb_reset_configuration (serial->dev); 961 return usb_reset_configuration(serial->dev);
949} 962}
950 963
951static void ipaq_shutdown(struct usb_serial *serial) 964static void ipaq_shutdown(struct usb_serial *serial)
@@ -958,7 +971,7 @@ static int __init ipaq_init(void)
958 int retval; 971 int retval;
959 spin_lock_init(&write_list_lock); 972 spin_lock_init(&write_list_lock);
960 retval = usb_serial_register(&ipaq_device); 973 retval = usb_serial_register(&ipaq_device);
961 if (retval) 974 if (retval)
962 goto failed_usb_serial_register; 975 goto failed_usb_serial_register;
963 info(DRIVER_DESC " " DRIVER_VERSION); 976 info(DRIVER_DESC " " DRIVER_VERSION);
964 if (vendor) { 977 if (vendor) {
@@ -968,7 +981,7 @@ static int __init ipaq_init(void)
968 retval = usb_register(&ipaq_driver); 981 retval = usb_register(&ipaq_driver);
969 if (retval) 982 if (retval)
970 goto failed_usb_register; 983 goto failed_usb_register;
971 984
972 return 0; 985 return 0;
973failed_usb_register: 986failed_usb_register:
974 usb_serial_deregister(&ipaq_device); 987 usb_serial_deregister(&ipaq_device);
@@ -987,8 +1000,8 @@ static void __exit ipaq_exit(void)
987module_init(ipaq_init); 1000module_init(ipaq_init);
988module_exit(ipaq_exit); 1001module_exit(ipaq_exit);
989 1002
990MODULE_AUTHOR( DRIVER_AUTHOR ); 1003MODULE_AUTHOR(DRIVER_AUTHOR);
991MODULE_DESCRIPTION( DRIVER_DESC ); 1004MODULE_DESCRIPTION(DRIVER_DESC);
992MODULE_LICENSE("GPL"); 1005MODULE_LICENSE("GPL");
993 1006
994module_param(debug, bool, S_IRUGO | S_IWUSR); 1007module_param(debug, bool, S_IRUGO | S_IWUSR);
@@ -1001,7 +1014,9 @@ module_param(product, ushort, 0);
1001MODULE_PARM_DESC(product, "User specified USB idProduct"); 1014MODULE_PARM_DESC(product, "User specified USB idProduct");
1002 1015
1003module_param(connect_retries, int, S_IRUGO|S_IWUSR); 1016module_param(connect_retries, int, S_IRUGO|S_IWUSR);
1004MODULE_PARM_DESC(connect_retries, "Maximum number of connect retries (one second each)"); 1017MODULE_PARM_DESC(connect_retries,
1018 "Maximum number of connect retries (one second each)");
1005 1019
1006module_param(initial_wait, int, S_IRUGO|S_IWUSR); 1020module_param(initial_wait, int, S_IRUGO|S_IWUSR);
1007MODULE_PARM_DESC(initial_wait, "Time to wait before attempting a connection (in seconds)"); 1021MODULE_PARM_DESC(initial_wait,
1022 "Time to wait before attempting a connection (in seconds)");
diff --git a/drivers/usb/serial/ipw.c b/drivers/usb/serial/ipw.c
index bc85ca5c1c37..a842025b9b57 100644
--- a/drivers/usb/serial/ipw.c
+++ b/drivers/usb/serial/ipw.c
@@ -10,27 +10,27 @@
10 * (at your option) any later version. 10 * (at your option) any later version.
11 * 11 *
12 * All information about the device was acquired using SnoopyPro 12 * All information about the device was acquired using SnoopyPro
13 * on MSFT's O/S, and examing the MSFT drivers' debug output 13 * on MSFT's O/S, and examing the MSFT drivers' debug output
14 * (insanely left _on_ in the enduser version) 14 * (insanely left _on_ in the enduser version)
15 * 15 *
16 * It was written out of frustration with the IPWireless USB modem 16 * It was written out of frustration with the IPWireless USB modem
17 * supplied by Axity3G/Sentech South Africa not supporting 17 * supplied by Axity3G/Sentech South Africa not supporting
18 * Linux whatsoever. 18 * Linux whatsoever.
19 * 19 *
20 * Nobody provided any proprietary information that was not already 20 * Nobody provided any proprietary information that was not already
21 * available for this device. 21 * available for this device.
22 * 22 *
23 * The modem adheres to the "3GPP TS 27.007 AT command set for 3G 23 * The modem adheres to the "3GPP TS 27.007 AT command set for 3G
24 * User Equipment (UE)" standard, available from 24 * User Equipment (UE)" standard, available from
25 * http://www.3gpp.org/ftp/Specs/html-info/27007.htm 25 * http://www.3gpp.org/ftp/Specs/html-info/27007.htm
26 * 26 *
27 * The code was only tested the IPWireless handheld modem distributed 27 * The code was only tested the IPWireless handheld modem distributed
28 * in South Africa by Sentech. 28 * in South Africa by Sentech.
29 * 29 *
30 * It may work for Woosh Inc in .nz too, as it appears they use the 30 * It may work for Woosh Inc in .nz too, as it appears they use the
31 * same kit. 31 * same kit.
32 * 32 *
33 * There is still some work to be done in terms of handling 33 * There is still some work to be done in terms of handling
34 * DCD, DTR, RTS, CTS which are currently faked. 34 * DCD, DTR, RTS, CTS which are currently faked.
35 * It's good enough for PPP at this point. It's based off all kinds of 35 * It's good enough for PPP at this point. It's based off all kinds of
36 * code found in usb/serial and usb/class 36 * code found in usb/serial and usb/class
@@ -47,7 +47,7 @@
47#include <linux/spinlock.h> 47#include <linux/spinlock.h>
48#include <linux/usb.h> 48#include <linux/usb.h>
49#include <linux/usb/serial.h> 49#include <linux/usb/serial.h>
50#include <asm/uaccess.h> 50#include <linux/uaccess.h>
51 51
52/* 52/*
53 * Version Information 53 * Version Information
@@ -64,7 +64,7 @@
64 64
65/* Message sizes */ 65/* Message sizes */
66#define EVENT_BUFFER_SIZE 0xFF 66#define EVENT_BUFFER_SIZE 0xFF
67#define CHAR2INT16(c1,c0) (((u32)((c1) & 0xff) << 8) + (u32)((c0) & 0xff)) 67#define CHAR2INT16(c1, c0) (((u32)((c1) & 0xff) << 8) + (u32)((c0) & 0xff))
68#define NUM_BULK_URBS 24 68#define NUM_BULK_URBS 24
69#define NUM_CONTROL_URBS 16 69#define NUM_CONTROL_URBS 16
70 70
@@ -94,33 +94,34 @@ enum {
94 94
95/* data bits */ 95/* data bits */
96#define ipw_dtb_7 0x700 96#define ipw_dtb_7 0x700
97#define ipw_dtb_8 0x810 // ok so the define is misleading, I know, but forces 8,n,1 97#define ipw_dtb_8 0x810 /* ok so the define is misleading, I know, but forces 8,n,1 */
98 // I mean, is there a point to any other setting these days? :) 98 /* I mean, is there a point to any other setting these days? :) */
99 99
100/* usb control request types : */ 100/* usb control request types : */
101#define IPW_SIO_RXCTL 0x00 // control bulk rx channel transmissions, value=1/0 (on/off) 101#define IPW_SIO_RXCTL 0x00 /* control bulk rx channel transmissions, value=1/0 (on/off) */
102#define IPW_SIO_SET_BAUD 0x01 // set baud, value=requested ipw_sio_bxxxx 102#define IPW_SIO_SET_BAUD 0x01 /* set baud, value=requested ipw_sio_bxxxx */
103#define IPW_SIO_SET_LINE 0x03 // set databits, parity. value=ipw_dtb_x 103#define IPW_SIO_SET_LINE 0x03 /* set databits, parity. value=ipw_dtb_x */
104#define IPW_SIO_SET_PIN 0x03 // set/clear dtr/rts value=ipw_pin_xxx 104#define IPW_SIO_SET_PIN 0x03 /* set/clear dtr/rts value=ipw_pin_xxx */
105#define IPW_SIO_POLL 0x08 // get serial port status byte, call with value=0 105#define IPW_SIO_POLL 0x08 /* get serial port status byte, call with value=0 */
106#define IPW_SIO_INIT 0x11 // initializes ? value=0 (appears as first thing todo on open) 106#define IPW_SIO_INIT 0x11 /* initializes ? value=0 (appears as first thing todo on open) */
107#define IPW_SIO_PURGE 0x12 // purge all transmissions?, call with value=numchar_to_purge 107#define IPW_SIO_PURGE 0x12 /* purge all transmissions?, call with value=numchar_to_purge */
108#define IPW_SIO_HANDFLOW 0x13 // set xon/xoff limits value=0, and a buffer of 0x10 bytes 108#define IPW_SIO_HANDFLOW 0x13 /* set xon/xoff limits value=0, and a buffer of 0x10 bytes */
109#define IPW_SIO_SETCHARS 0x13 // set the flowcontrol special chars, value=0, buf=6 bytes, 109#define IPW_SIO_SETCHARS 0x13 /* set the flowcontrol special chars, value=0, buf=6 bytes, */
110 // last 2 bytes contain flowcontrol chars e.g. 00 00 00 00 11 13 110 /* last 2 bytes contain flowcontrol chars e.g. 00 00 00 00 11 13 */
111 111
112/* values used for request IPW_SIO_SET_PIN */ 112/* values used for request IPW_SIO_SET_PIN */
113#define IPW_PIN_SETDTR 0x101 113#define IPW_PIN_SETDTR 0x101
114#define IPW_PIN_SETRTS 0x202 114#define IPW_PIN_SETRTS 0x202
115#define IPW_PIN_CLRDTR 0x100 115#define IPW_PIN_CLRDTR 0x100
116#define IPW_PIN_CLRRTS 0x200 // unconfirmed 116#define IPW_PIN_CLRRTS 0x200 /* unconfirmed */
117 117
118/* values used for request IPW_SIO_RXCTL */ 118/* values used for request IPW_SIO_RXCTL */
119#define IPW_RXBULK_ON 1 119#define IPW_RXBULK_ON 1
120#define IPW_RXBULK_OFF 0 120#define IPW_RXBULK_OFF 0
121 121
122/* various 16 byte hardcoded transferbuffers used by flow control */ 122/* various 16 byte hardcoded transferbuffers used by flow control */
123#define IPW_BYTES_FLOWINIT { 0x01, 0, 0, 0, 0x40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } 123#define IPW_BYTES_FLOWINIT { 0x01, 0, 0, 0, 0x40, 0, 0, 0, \
124 0, 0, 0, 0, 0, 0, 0, 0 }
124 125
125/* Interpretation of modem status lines */ 126/* Interpretation of modem status lines */
126/* These need sorting out by individually connecting pins and checking 127/* These need sorting out by individually connecting pins and checking
@@ -132,17 +133,6 @@ enum {
132#define IPW_CTS ((1<<5) | (1<<4)) 133#define IPW_CTS ((1<<5) | (1<<4))
133 134
134#define IPW_WANTS_TO_SEND 0x30 135#define IPW_WANTS_TO_SEND 0x30
135//#define IPW_DTR /* Data Terminal Ready */
136//#define IPW_CTS /* Clear To Send */
137//#define IPW_CD /* Carrier Detect */
138//#define IPW_DSR /* Data Set Ready */
139//#define IPW_RxD /* Receive pin */
140
141//#define IPW_LE
142//#define IPW_RTS
143//#define IPW_ST
144//#define IPW_SR
145//#define IPW_RI /* Ring Indicator */
146 136
147static struct usb_device_id usb_ipw_ids[] = { 137static struct usb_device_id usb_ipw_ids[] = {
148 { USB_DEVICE(IPW_VID, IPW_PID) }, 138 { USB_DEVICE(IPW_VID, IPW_PID) },
@@ -177,9 +167,10 @@ static void ipw_read_bulk_callback(struct urb *urb)
177 return; 167 return;
178 } 168 }
179 169
180 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); 170 usb_serial_debug_data(debug, &port->dev, __func__,
171 urb->actual_length, data);
181 172
182 tty = port->tty; 173 tty = port->port.tty;
183 if (tty && urb->actual_length) { 174 if (tty && urb->actual_length) {
184 tty_buffer_request_room(tty, urb->actual_length); 175 tty_buffer_request_room(tty, urb->actual_length);
185 tty_insert_flip_string(tty, data, urb->actual_length); 176 tty_insert_flip_string(tty, data, urb->actual_length);
@@ -187,19 +178,22 @@ static void ipw_read_bulk_callback(struct urb *urb)
187 } 178 }
188 179
189 /* Continue trying to always read */ 180 /* Continue trying to always read */
190 usb_fill_bulk_urb (port->read_urb, port->serial->dev, 181 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
191 usb_rcvbulkpipe(port->serial->dev, 182 usb_rcvbulkpipe(port->serial->dev,
192 port->bulk_in_endpointAddress), 183 port->bulk_in_endpointAddress),
193 port->read_urb->transfer_buffer, 184 port->read_urb->transfer_buffer,
194 port->read_urb->transfer_buffer_length, 185 port->read_urb->transfer_buffer_length,
195 ipw_read_bulk_callback, port); 186 ipw_read_bulk_callback, port);
196 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 187 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
197 if (result) 188 if (result)
198 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result); 189 dev_err(&port->dev,
190 "%s - failed resubmitting read urb, error %d\n",
191 __func__, result);
199 return; 192 return;
200} 193}
201 194
202static int ipw_open(struct usb_serial_port *port, struct file *filp) 195static int ipw_open(struct tty_struct *tty,
196 struct usb_serial_port *port, struct file *filp)
203{ 197{
204 struct usb_device *dev = port->serial->dev; 198 struct usb_device *dev = port->serial->dev;
205 u8 buf_flow_static[16] = IPW_BYTES_FLOWINIT; 199 u8 buf_flow_static[16] = IPW_BYTES_FLOWINIT;
@@ -212,29 +206,33 @@ static int ipw_open(struct usb_serial_port *port, struct file *filp)
212 if (!buf_flow_init) 206 if (!buf_flow_init)
213 return -ENOMEM; 207 return -ENOMEM;
214 208
215 if (port->tty) 209 if (tty)
216 port->tty->low_latency = 1; 210 tty->low_latency = 1;
217 211
218 /* --1: Tell the modem to initialize (we think) From sniffs this is always the 212 /* --1: Tell the modem to initialize (we think) From sniffs this is
219 * first thing that gets sent to the modem during opening of the device */ 213 * always the first thing that gets sent to the modem during
220 dbg("%s: Sending SIO_INIT (we guess)",__func__); 214 * opening of the device */
221 result = usb_control_msg(dev, usb_sndctrlpipe(dev,0), 215 dbg("%s: Sending SIO_INIT (we guess)", __func__);
222 IPW_SIO_INIT, 216 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
223 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, 217 IPW_SIO_INIT,
224 0, 218 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
225 0, /* index */ 219 0,
226 NULL, 220 0, /* index */
227 0, 221 NULL,
228 100000); 222 0,
223 100000);
229 if (result < 0) 224 if (result < 0)
230 dev_err(&port->dev, "Init of modem failed (error = %d)\n", result); 225 dev_err(&port->dev,
226 "Init of modem failed (error = %d)\n", result);
231 227
232 /* reset the bulk pipes */ 228 /* reset the bulk pipes */
233 usb_clear_halt(dev, usb_rcvbulkpipe(dev, port->bulk_in_endpointAddress)); 229 usb_clear_halt(dev,
234 usb_clear_halt(dev, usb_sndbulkpipe(dev, port->bulk_out_endpointAddress)); 230 usb_rcvbulkpipe(dev, port->bulk_in_endpointAddress));
231 usb_clear_halt(dev,
232 usb_sndbulkpipe(dev, port->bulk_out_endpointAddress));
235 233
236 /*--2: Start reading from the device */ 234 /*--2: Start reading from the device */
237 dbg("%s: setting up bulk read callback",__func__); 235 dbg("%s: setting up bulk read callback", __func__);
238 usb_fill_bulk_urb(port->read_urb, dev, 236 usb_fill_bulk_urb(port->read_urb, dev,
239 usb_rcvbulkpipe(dev, port->bulk_in_endpointAddress), 237 usb_rcvbulkpipe(dev, port->bulk_in_endpointAddress),
240 port->bulk_in_buffer, 238 port->bulk_in_buffer,
@@ -242,66 +240,72 @@ static int ipw_open(struct usb_serial_port *port, struct file *filp)
242 ipw_read_bulk_callback, port); 240 ipw_read_bulk_callback, port);
243 result = usb_submit_urb(port->read_urb, GFP_KERNEL); 241 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
244 if (result < 0) 242 if (result < 0)
245 dbg("%s - usb_submit_urb(read bulk) failed with status %d", __func__, result); 243 dbg("%s - usb_submit_urb(read bulk) failed with status %d",
244 __func__, result);
246 245
247 /*--3: Tell the modem to open the floodgates on the rx bulk channel */ 246 /*--3: Tell the modem to open the floodgates on the rx bulk channel */
248 dbg("%s:asking modem for RxRead (RXBULK_ON)",__func__); 247 dbg("%s:asking modem for RxRead (RXBULK_ON)", __func__);
249 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 248 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
250 IPW_SIO_RXCTL, 249 IPW_SIO_RXCTL,
251 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, 250 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
252 IPW_RXBULK_ON, 251 IPW_RXBULK_ON,
253 0, /* index */ 252 0, /* index */
254 NULL, 253 NULL,
255 0, 254 0,
256 100000); 255 100000);
257 if (result < 0) 256 if (result < 0)
258 dev_err(&port->dev, "Enabling bulk RxRead failed (error = %d)\n", result); 257 dev_err(&port->dev,
258 "Enabling bulk RxRead failed (error = %d)\n", result);
259 259
260 /*--4: setup the initial flowcontrol */ 260 /*--4: setup the initial flowcontrol */
261 dbg("%s:setting init flowcontrol (%s)",__func__,buf_flow_init); 261 dbg("%s:setting init flowcontrol (%s)", __func__, buf_flow_init);
262 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 262 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
263 IPW_SIO_HANDFLOW, 263 IPW_SIO_HANDFLOW,
264 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, 264 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
265 0, 265 0,
266 0, 266 0,
267 buf_flow_init, 267 buf_flow_init,
268 0x10, 268 0x10,
269 200000); 269 200000);
270 if (result < 0) 270 if (result < 0)
271 dev_err(&port->dev, "initial flowcontrol failed (error = %d)\n", result); 271 dev_err(&port->dev,
272 "initial flowcontrol failed (error = %d)\n", result);
272 273
273 274
274 /*--5: raise the dtr */ 275 /*--5: raise the dtr */
275 dbg("%s:raising dtr",__func__); 276 dbg("%s:raising dtr", __func__);
276 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 277 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
277 IPW_SIO_SET_PIN, 278 IPW_SIO_SET_PIN,
278 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, 279 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
279 IPW_PIN_SETDTR, 280 IPW_PIN_SETDTR,
280 0, 281 0,
281 NULL, 282 NULL,
282 0, 283 0,
283 200000); 284 200000);
284 if (result < 0) 285 if (result < 0)
285 dev_err(&port->dev, "setting dtr failed (error = %d)\n", result); 286 dev_err(&port->dev,
287 "setting dtr failed (error = %d)\n", result);
286 288
287 /*--6: raise the rts */ 289 /*--6: raise the rts */
288 dbg("%s:raising rts",__func__); 290 dbg("%s:raising rts", __func__);
289 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 291 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
290 IPW_SIO_SET_PIN, 292 IPW_SIO_SET_PIN,
291 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, 293 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
292 IPW_PIN_SETRTS, 294 IPW_PIN_SETRTS,
293 0, 295 0,
294 NULL, 296 NULL,
295 0, 297 0,
296 200000); 298 200000);
297 if (result < 0) 299 if (result < 0)
298 dev_err(&port->dev, "setting dtr failed (error = %d)\n", result); 300 dev_err(&port->dev,
299 301 "setting dtr failed (error = %d)\n", result);
302
300 kfree(buf_flow_init); 303 kfree(buf_flow_init);
301 return 0; 304 return 0;
302} 305}
303 306
304static void ipw_close(struct usb_serial_port *port, struct file * filp) 307static void ipw_close(struct tty_struct *tty,
308 struct usb_serial_port *port, struct file *filp)
305{ 309{
306 struct usb_device *dev = port->serial->dev; 310 struct usb_device *dev = port->serial->dev;
307 int result; 311 int result;
@@ -312,56 +316,62 @@ static void ipw_close(struct usb_serial_port *port, struct file * filp)
312 } 316 }
313 317
314 /*--1: drop the dtr */ 318 /*--1: drop the dtr */
315 dbg("%s:dropping dtr",__func__); 319 dbg("%s:dropping dtr", __func__);
316 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 320 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
317 IPW_SIO_SET_PIN, 321 IPW_SIO_SET_PIN,
318 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, 322 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
319 IPW_PIN_CLRDTR, 323 IPW_PIN_CLRDTR,
320 0, 324 0,
321 NULL, 325 NULL,
322 0, 326 0,
323 200000); 327 200000);
324 if (result < 0) 328 if (result < 0)
325 dev_err(&port->dev, "dropping dtr failed (error = %d)\n", result); 329 dev_err(&port->dev, "dropping dtr failed (error = %d)\n",
330 result);
326 331
327 /*--2: drop the rts */ 332 /*--2: drop the rts */
328 dbg("%s:dropping rts",__func__); 333 dbg("%s:dropping rts", __func__);
329 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 334 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
330 IPW_SIO_SET_PIN, USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, 335 IPW_SIO_SET_PIN, USB_TYPE_VENDOR |
331 IPW_PIN_CLRRTS, 336 USB_RECIP_INTERFACE | USB_DIR_OUT,
332 0, 337 IPW_PIN_CLRRTS,
333 NULL, 338 0,
334 0, 339 NULL,
335 200000); 340 0,
341 200000);
336 if (result < 0) 342 if (result < 0)
337 dev_err(&port->dev, "dropping rts failed (error = %d)\n", result); 343 dev_err(&port->dev,
344 "dropping rts failed (error = %d)\n", result);
338 345
339 346
340 /*--3: purge */ 347 /*--3: purge */
341 dbg("%s:sending purge",__func__); 348 dbg("%s:sending purge", __func__);
342 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 349 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
343 IPW_SIO_PURGE, USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, 350 IPW_SIO_PURGE, USB_TYPE_VENDOR |
344 0x03, 351 USB_RECIP_INTERFACE | USB_DIR_OUT,
345 0, 352 0x03,
346 NULL, 353 0,
347 0, 354 NULL,
348 200000); 355 0,
356 200000);
349 if (result < 0) 357 if (result < 0)
350 dev_err(&port->dev, "purge failed (error = %d)\n", result); 358 dev_err(&port->dev, "purge failed (error = %d)\n", result);
351 359
352 360
353 /* send RXBULK_off (tell modem to stop transmitting bulk data on rx chan) */ 361 /* send RXBULK_off (tell modem to stop transmitting bulk data on
362 rx chan) */
354 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 363 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
355 IPW_SIO_RXCTL, 364 IPW_SIO_RXCTL,
356 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, 365 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
357 IPW_RXBULK_OFF, 366 IPW_RXBULK_OFF,
358 0, /* index */ 367 0, /* index */
359 NULL, 368 NULL,
360 0, 369 0,
361 100000); 370 100000);
362 371
363 if (result < 0) 372 if (result < 0)
364 dev_err(&port->dev, "Disabling bulk RxRead failed (error = %d)\n", result); 373 dev_err(&port->dev,
374 "Disabling bulk RxRead failed (error = %d)\n", result);
365 375
366 /* shutdown any in-flight urbs that we know about */ 376 /* shutdown any in-flight urbs that we know about */
367 usb_kill_urb(port->read_urb); 377 usb_kill_urb(port->read_urb);
@@ -384,13 +394,14 @@ static void ipw_write_bulk_callback(struct urb *urb)
384 usb_serial_port_softint(port); 394 usb_serial_port_softint(port);
385} 395}
386 396
387static int ipw_write(struct usb_serial_port *port, const unsigned char *buf, int count) 397static int ipw_write(struct tty_struct *tty, struct usb_serial_port *port,
398 const unsigned char *buf, int count)
388{ 399{
389 struct usb_device *dev = port->serial->dev; 400 struct usb_device *dev = port->serial->dev;
390 int ret; 401 int ret;
391 402
392 dbg("%s: TOP: count=%d, in_interrupt=%ld", __func__, 403 dbg("%s: TOP: count=%d, in_interrupt=%ld", __func__,
393 count, in_interrupt() ); 404 count, in_interrupt());
394 405
395 if (count == 0) { 406 if (count == 0) {
396 dbg("%s - write request of 0 bytes", __func__); 407 dbg("%s - write request of 0 bytes", __func__);
@@ -421,13 +432,14 @@ static int ipw_write(struct usb_serial_port *port, const unsigned char *buf, int
421 ret = usb_submit_urb(port->write_urb, GFP_ATOMIC); 432 ret = usb_submit_urb(port->write_urb, GFP_ATOMIC);
422 if (ret != 0) { 433 if (ret != 0) {
423 port->write_urb_busy = 0; 434 port->write_urb_busy = 0;
424 dbg("%s - usb_submit_urb(write bulk) failed with error = %d", __func__, ret); 435 dbg("%s - usb_submit_urb(write bulk) failed with error = %d",
436 __func__, ret);
425 return ret; 437 return ret;
426 } 438 }
427 439
428 dbg("%s returning %d", __func__, count); 440 dbg("%s returning %d", __func__, count);
429 return count; 441 return count;
430} 442}
431 443
432static int ipw_probe(struct usb_serial_port *port) 444static int ipw_probe(struct usb_serial_port *port)
433{ 445{
@@ -486,8 +498,8 @@ module_init(usb_ipw_init);
486module_exit(usb_ipw_exit); 498module_exit(usb_ipw_exit);
487 499
488/* Module information */ 500/* Module information */
489MODULE_AUTHOR( DRIVER_AUTHOR ); 501MODULE_AUTHOR(DRIVER_AUTHOR);
490MODULE_DESCRIPTION( DRIVER_DESC ); 502MODULE_DESCRIPTION(DRIVER_DESC);
491MODULE_LICENSE("GPL"); 503MODULE_LICENSE("GPL");
492 504
493module_param(debug, bool, S_IRUGO | S_IWUSR); 505module_param(debug, bool, S_IRUGO | S_IWUSR);
diff --git a/drivers/usb/serial/ir-usb.c b/drivers/usb/serial/ir-usb.c
index 0063c11c8081..e59155c6607d 100644
--- a/drivers/usb/serial/ir-usb.c
+++ b/drivers/usb/serial/ir-usb.c
@@ -85,15 +85,17 @@ static int buffer_size;
85/* if overridden by the user, then use the specified number of XBOFs */ 85/* if overridden by the user, then use the specified number of XBOFs */
86static int xbof = -1; 86static int xbof = -1;
87 87
88static int ir_startup(struct usb_serial *serial); 88static int ir_startup (struct usb_serial *serial);
89static int ir_open(struct usb_serial_port *port, struct file *filep); 89static int ir_open(struct tty_struct *tty, struct usb_serial_port *port,
90static void ir_close(struct usb_serial_port *port, struct file *filep); 90 struct file *filep);
91static int ir_write(struct usb_serial_port *port, 91static void ir_close(struct tty_struct *tty, struct usb_serial_port *port,
92 const unsigned char *buf, int count); 92 struct file *filep);
93static void ir_write_bulk_callback(struct urb *urb); 93static int ir_write(struct tty_struct *tty, struct usb_serial_port *port,
94static void ir_read_bulk_callback(struct urb *urb); 94 const unsigned char *buf, int count);
95static void ir_set_termios(struct usb_serial_port *port, 95static void ir_write_bulk_callback (struct urb *urb);
96 struct ktermios *old_termios); 96static void ir_read_bulk_callback (struct urb *urb);
97static void ir_set_termios(struct tty_struct *tty,
98 struct usb_serial_port *port, struct ktermios *old_termios);
97 99
98/* Not that this lot means you can only have one per system */ 100/* Not that this lot means you can only have one per system */
99static u8 ir_baud; 101static u8 ir_baud;
@@ -295,7 +297,8 @@ static int ir_startup(struct usb_serial *serial)
295 return 0; 297 return 0;
296} 298}
297 299
298static int ir_open(struct usb_serial_port *port, struct file *filp) 300static int ir_open(struct tty_struct *tty,
301 struct usb_serial_port *port, struct file *filp)
299{ 302{
300 char *buffer; 303 char *buffer;
301 int result = 0; 304 int result = 0;
@@ -343,7 +346,8 @@ static int ir_open(struct usb_serial_port *port, struct file *filp)
343 return result; 346 return result;
344} 347}
345 348
346static void ir_close(struct usb_serial_port *port, struct file *filp) 349static void ir_close(struct tty_struct *tty,
350 struct usb_serial_port *port, struct file * filp)
347{ 351{
348 dbg("%s - port %d", __func__, port->number); 352 dbg("%s - port %d", __func__, port->number);
349 353
@@ -351,8 +355,8 @@ static void ir_close(struct usb_serial_port *port, struct file *filp)
351 usb_kill_urb(port->read_urb); 355 usb_kill_urb(port->read_urb);
352} 356}
353 357
354static int ir_write(struct usb_serial_port *port, 358static int ir_write(struct tty_struct *tty, struct usb_serial_port *port,
355 const unsigned char *buf, int count) 359 const unsigned char *buf, int count)
356{ 360{
357 unsigned char *transfer_buffer; 361 unsigned char *transfer_buffer;
358 int result; 362 int result;
@@ -360,11 +364,6 @@ static int ir_write(struct usb_serial_port *port,
360 364
361 dbg("%s - port = %d, count = %d", __func__, port->number, count); 365 dbg("%s - port = %d, count = %d", __func__, port->number, count);
362 366
363 if (!port->tty) {
364 dev_err(&port->dev, "%s - no tty???\n", __func__);
365 return 0;
366 }
367
368 if (count == 0) 367 if (count == 0)
369 return 0; 368 return 0;
370 369
@@ -450,14 +449,13 @@ static void ir_read_bulk_callback(struct urb *urb)
450 449
451 dbg("%s - port %d", __func__, port->number); 450 dbg("%s - port %d", __func__, port->number);
452 451
453 if (!port->open_count) { 452 if (!port->port.count) {
454 dbg("%s - port closed.", __func__); 453 dbg("%s - port closed.", __func__);
455 return; 454 return;
456 } 455 }
457 456
458 switch (status) { 457 switch (status) {
459 case 0: /* Successful */ 458 case 0: /* Successful */
460
461 /* 459 /*
462 * The first byte of the packet we get from the device 460 * The first byte of the packet we get from the device
463 * contains a busy indicator and baud rate change. 461 * contains a busy indicator and baud rate change.
@@ -465,19 +463,11 @@ static void ir_read_bulk_callback(struct urb *urb)
465 */ 463 */
466 if ((*data & 0x0f) > 0) 464 if ((*data & 0x0f) > 0)
467 ir_baud = *data & 0x0f; 465 ir_baud = *data & 0x0f;
468 466 usb_serial_debug_data(debug, &port->dev, __func__,
469 usb_serial_debug_data( 467 urb->actual_length, data);
470 debug, 468 tty = port->port.tty;
471 &port->dev,
472 __func__,
473 urb->actual_length,
474 data);
475
476 tty = port->tty;
477
478 if (tty_buffer_request_room(tty, urb->actual_length - 1)) { 469 if (tty_buffer_request_room(tty, urb->actual_length - 1)) {
479 tty_insert_flip_string(tty, data + 1, 470 tty_insert_flip_string(tty, data+1, urb->actual_length - 1);
480 urb->actual_length - 1);
481 tty_flip_buffer_push(tty); 471 tty_flip_buffer_push(tty);
482 } 472 }
483 473
@@ -488,11 +478,10 @@ static void ir_read_bulk_callback(struct urb *urb)
488 */ 478 */
489 479
490 case -EPROTO: /* taking inspiration from pl2303.c */ 480 case -EPROTO: /* taking inspiration from pl2303.c */
491 481 /* Continue trying to always read */
492 /* Continue trying to always read */
493 usb_fill_bulk_urb( 482 usb_fill_bulk_urb(
494 port->read_urb, 483 port->read_urb,
495 port->serial->dev, 484 port->serial->dev,
496 usb_rcvbulkpipe(port->serial->dev, 485 usb_rcvbulkpipe(port->serial->dev,
497 port->bulk_in_endpointAddress), 486 port->bulk_in_endpointAddress),
498 port->read_urb->transfer_buffer, 487 port->read_urb->transfer_buffer,
@@ -502,23 +491,19 @@ static void ir_read_bulk_callback(struct urb *urb)
502 491
503 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 492 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
504 if (result) 493 if (result)
505 dev_err(&port->dev, 494 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n",
506 "%s - failed resubmitting read urb, error %d\n",
507 __func__, result); 495 __func__, result);
508 break; 496 break ;
509
510 default: 497 default:
511 dbg("%s - nonzero read bulk status received: %d", 498 dbg("%s - nonzero read bulk status received: %d",
512 __func__, 499 __func__, status);
513 status); 500 break ;
514 break;
515 } 501 }
516
517 return; 502 return;
518} 503}
519 504
520static void ir_set_termios(struct usb_serial_port *port, 505static void ir_set_termios(struct tty_struct *tty,
521 struct ktermios *old_termios) 506 struct usb_serial_port *port, struct ktermios *old_termios)
522{ 507{
523 unsigned char *transfer_buffer; 508 unsigned char *transfer_buffer;
524 int result; 509 int result;
@@ -527,7 +512,7 @@ static void ir_set_termios(struct usb_serial_port *port,
527 512
528 dbg("%s - port %d", __func__, port->number); 513 dbg("%s - port %d", __func__, port->number);
529 514
530 baud = tty_get_baud_rate(port->tty); 515 baud = tty_get_baud_rate(tty);
531 516
532 /* 517 /*
533 * FIXME, we should compare the baud request against the 518 * FIXME, we should compare the baud request against the
@@ -600,8 +585,8 @@ static void ir_set_termios(struct usb_serial_port *port,
600 __func__, result); 585 __func__, result);
601 586
602 /* Only speed changes are supported */ 587 /* Only speed changes are supported */
603 tty_termios_copy_hw(port->tty->termios, old_termios); 588 tty_termios_copy_hw(tty->termios, old_termios);
604 tty_encode_baud_rate(port->tty, baud, baud); 589 tty_encode_baud_rate(tty, baud, baud);
605} 590}
606 591
607static int __init ir_init(void) 592static int __init ir_init(void)
diff --git a/drivers/usb/serial/iuu_phoenix.c b/drivers/usb/serial/iuu_phoenix.c
index a01e987c7d32..ddff37fa6339 100644
--- a/drivers/usb/serial/iuu_phoenix.c
+++ b/drivers/usb/serial/iuu_phoenix.c
@@ -144,9 +144,10 @@ static void iuu_shutdown(struct usb_serial *serial)
144 } 144 }
145} 145}
146 146
147static int iuu_tiocmset(struct usb_serial_port *port, struct file *file, 147static int iuu_tiocmset(struct tty_struct *tty, struct file *file,
148 unsigned int set, unsigned int clear) 148 unsigned int set, unsigned int clear)
149{ 149{
150 struct usb_serial_port *port = tty->driver_data;
150 struct iuu_private *priv = usb_get_serial_port_data(port); 151 struct iuu_private *priv = usb_get_serial_port_data(port);
151 unsigned long flags; 152 unsigned long flags;
152 153
@@ -171,8 +172,9 @@ static int iuu_tiocmset(struct usb_serial_port *port, struct file *file,
171 * When no card , the reader respond with TIOCM_CD 172 * When no card , the reader respond with TIOCM_CD
172 * This is known as CD autodetect mechanism 173 * This is known as CD autodetect mechanism
173 */ 174 */
174static int iuu_tiocmget(struct usb_serial_port *port, struct file *file) 175static int iuu_tiocmget(struct tty_struct *tty, struct file *file)
175{ 176{
177 struct usb_serial_port *port = tty->driver_data;
176 struct iuu_private *priv = usb_get_serial_port_data(port); 178 struct iuu_private *priv = usb_get_serial_port_data(port);
177 unsigned long flags; 179 unsigned long flags;
178 int rc; 180 int rc;
@@ -316,11 +318,10 @@ static int bulk_immediate(struct usb_serial_port *port, u8 *buf, u8 count)
316 port->bulk_out_endpointAddress), buf, 318 port->bulk_out_endpointAddress), buf,
317 count, &actual, HZ * 1); 319 count, &actual, HZ * 1);
318 320
319 if (status != IUU_OPERATION_OK) { 321 if (status != IUU_OPERATION_OK)
320 dbg("%s - error = %2x", __func__, status); 322 dbg("%s - error = %2x", __func__, status);
321 } else { 323 else
322 dbg("%s - write OK !", __func__); 324 dbg("%s - write OK !", __func__);
323 }
324 return status; 325 return status;
325} 326}
326 327
@@ -340,12 +341,10 @@ static int read_immediate(struct usb_serial_port *port, u8 *buf, u8 count)
340 port->bulk_in_endpointAddress), buf, 341 port->bulk_in_endpointAddress), buf,
341 count, &actual, HZ * 1); 342 count, &actual, HZ * 1);
342 343
343 if (status != IUU_OPERATION_OK) { 344 if (status != IUU_OPERATION_OK)
344 dbg("%s - error = %2x", __func__, status); 345 dbg("%s - error = %2x", __func__, status);
345 } else { 346 else
346 dbg("%s - read OK !", __func__); 347 dbg("%s - read OK !", __func__);
347 }
348
349 return status; 348 return status;
350} 349}
351 350
@@ -630,7 +629,7 @@ static void read_buf_callback(struct urb *urb)
630 } 629 }
631 630
632 dbg("%s - %i chars to write", __func__, urb->actual_length); 631 dbg("%s - %i chars to write", __func__, urb->actual_length);
633 tty = port->tty; 632 tty = port->port.tty;
634 if (data == NULL) 633 if (data == NULL)
635 dbg("%s - data is NULL !!!", __func__); 634 dbg("%s - data is NULL !!!", __func__);
636 if (tty && urb->actual_length && data) { 635 if (tty && urb->actual_length && data) {
@@ -752,11 +751,10 @@ static void iuu_uart_read_callback(struct urb *urb)
752 /* if nothing to write call again rxcmd */ 751 /* if nothing to write call again rxcmd */
753 dbg("%s - rxcmd recall", __func__); 752 dbg("%s - rxcmd recall", __func__);
754 iuu_led_activity_off(urb); 753 iuu_led_activity_off(urb);
755 return;
756} 754}
757 755
758static int iuu_uart_write(struct usb_serial_port *port, const u8 *buf, 756static int iuu_uart_write(struct tty_struct *tty, struct usb_serial_port *port,
759 int count) 757 const u8 *buf, int count)
760{ 758{
761 struct iuu_private *priv = usb_get_serial_port_data(port); 759 struct iuu_private *priv = usb_get_serial_port_data(port);
762 unsigned long flags; 760 unsigned long flags;
@@ -769,14 +767,14 @@ static int iuu_uart_write(struct usb_serial_port *port, const u8 *buf,
769 if (priv->writelen > 0) { 767 if (priv->writelen > 0) {
770 /* buffer already filled but not commited */ 768 /* buffer already filled but not commited */
771 spin_unlock_irqrestore(&priv->lock, flags); 769 spin_unlock_irqrestore(&priv->lock, flags);
772 return (0); 770 return 0;
773 } 771 }
774 /* fill the buffer */ 772 /* fill the buffer */
775 memcpy(priv->writebuf, buf, count); 773 memcpy(priv->writebuf, buf, count);
776 priv->writelen = count; 774 priv->writelen = count;
777 spin_unlock_irqrestore(&priv->lock, flags); 775 spin_unlock_irqrestore(&priv->lock, flags);
778 776
779 return (count); 777 return count;
780} 778}
781 779
782static void read_rxcmd_callback(struct urb *urb) 780static void read_rxcmd_callback(struct urb *urb)
@@ -948,7 +946,8 @@ static int set_control_lines(struct usb_device *dev, u8 value)
948 return 0; 946 return 0;
949} 947}
950 948
951static void iuu_close(struct usb_serial_port *port, struct file *filp) 949static void iuu_close(struct tty_struct *tty,
950 struct usb_serial_port *port, struct file *filp)
952{ 951{
953 /* iuu_led (port,255,0,0,0); */ 952 /* iuu_led (port,255,0,0,0); */
954 struct usb_serial *serial; 953 struct usb_serial *serial;
@@ -964,8 +963,8 @@ static void iuu_close(struct usb_serial_port *port, struct file *filp)
964 963
965 iuu_uart_off(port); 964 iuu_uart_off(port);
966 if (serial->dev) { 965 if (serial->dev) {
967 if (port->tty) { 966 if (tty) {
968 c_cflag = port->tty->termios->c_cflag; 967 c_cflag = tty->termios->c_cflag;
969 if (c_cflag & HUPCL) { 968 if (c_cflag & HUPCL) {
970 /* drop DTR and RTS */ 969 /* drop DTR and RTS */
971 priv = usb_get_serial_port_data(port); 970 priv = usb_get_serial_port_data(port);
@@ -989,7 +988,8 @@ static void iuu_close(struct usb_serial_port *port, struct file *filp)
989 } 988 }
990} 989}
991 990
992static int iuu_open(struct usb_serial_port *port, struct file *filp) 991static int iuu_open(struct tty_struct *tty,
992 struct usb_serial_port *port, struct file *filp)
993{ 993{
994 struct usb_serial *serial = port->serial; 994 struct usb_serial *serial = port->serial;
995 u8 *buf; 995 u8 *buf;
@@ -1036,15 +1036,17 @@ static int iuu_open(struct usb_serial_port *port, struct file *filp)
1036 1036
1037 /* set the termios structure */ 1037 /* set the termios structure */
1038 spin_lock_irqsave(&priv->lock, flags); 1038 spin_lock_irqsave(&priv->lock, flags);
1039 if (!priv->termios_initialized) { 1039 if (tty && !priv->termios_initialized) {
1040 *(port->tty->termios) = tty_std_termios; 1040 *(tty->termios) = tty_std_termios;
1041 port->tty->termios->c_cflag = CLOCAL | CREAD | CS8 | B9600 1041 tty->termios->c_cflag = CLOCAL | CREAD | CS8 | B9600
1042 | TIOCM_CTS | CSTOPB | PARENB; 1042 | TIOCM_CTS | CSTOPB | PARENB;
1043 port->tty->termios->c_lflag = 0; 1043 tty->termios->c_ispeed = 9600;
1044 port->tty->termios->c_oflag = 0; 1044 tty->termios->c_ospeed = 9600;
1045 port->tty->termios->c_iflag = 0; 1045 tty->termios->c_lflag = 0;
1046 tty->termios->c_oflag = 0;
1047 tty->termios->c_iflag = 0;
1046 priv->termios_initialized = 1; 1048 priv->termios_initialized = 1;
1047 port->tty->low_latency = 1; 1049 tty->low_latency = 1;
1048 priv->poll = 0; 1050 priv->poll = 0;
1049 } 1051 }
1050 spin_unlock_irqrestore(&priv->lock, flags); 1052 spin_unlock_irqrestore(&priv->lock, flags);
@@ -1148,7 +1150,7 @@ static int iuu_open(struct usb_serial_port *port, struct file *filp)
1148 if (result) { 1150 if (result) {
1149 dev_err(&port->dev, "%s - failed submitting read urb," 1151 dev_err(&port->dev, "%s - failed submitting read urb,"
1150 " error %d\n", __func__, result); 1152 " error %d\n", __func__, result);
1151 iuu_close(port, NULL); 1153 iuu_close(tty, port, NULL);
1152 return -EPROTO; 1154 return -EPROTO;
1153 } else { 1155 } else {
1154 dbg("%s - rxcmd OK", __func__); 1156 dbg("%s - rxcmd OK", __func__);
diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c
index 11e439b90eac..704716f6f6d3 100644
--- a/drivers/usb/serial/keyspan.c
+++ b/drivers/usb/serial/keyspan.c
@@ -1,29 +1,29 @@
1/* 1/*
2 Keyspan USB to Serial Converter driver 2 Keyspan USB to Serial Converter driver
3 3
4 (C) Copyright (C) 2000-2001 Hugh Blemings <hugh@blemings.org> 4 (C) Copyright (C) 2000-2001 Hugh Blemings <hugh@blemings.org>
5 (C) Copyright (C) 2002 Greg Kroah-Hartman <greg@kroah.com> 5 (C) Copyright (C) 2002 Greg Kroah-Hartman <greg@kroah.com>
6 6
7 This program is free software; you can redistribute it and/or modify 7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or 9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 10 (at your option) any later version.
11 11
12 See http://misc.nu/hugh/keyspan.html for more information. 12 See http://misc.nu/hugh/keyspan.html for more information.
13 13
14 Code in this driver inspired by and in a number of places taken 14 Code in this driver inspired by and in a number of places taken
15 from Brian Warner's original Keyspan-PDA driver. 15 from Brian Warner's original Keyspan-PDA driver.
16 16
17 This driver has been put together with the support of Innosys, Inc. 17 This driver has been put together with the support of Innosys, Inc.
18 and Keyspan, Inc the manufacturers of the Keyspan USB-serial products. 18 and Keyspan, Inc the manufacturers of the Keyspan USB-serial products.
19 Thanks Guys :) 19 Thanks Guys :)
20 20
21 Thanks to Paulus for miscellaneous tidy ups, some largish chunks 21 Thanks to Paulus for miscellaneous tidy ups, some largish chunks
22 of much nicer and/or completely new code and (perhaps most uniquely) 22 of much nicer and/or completely new code and (perhaps most uniquely)
23 having the patience to sit down and explain why and where he'd changed 23 having the patience to sit down and explain why and where he'd changed
24 stuff. 24 stuff.
25 25
26 Tip 'o the hat to IBM (and previously Linuxcare :) for supporting 26 Tip 'o the hat to IBM (and previously Linuxcare :) for supporting
27 staff in their work on open source projects. 27 staff in their work on open source projects.
28 28
29 Change History 29 Change History
@@ -70,21 +70,21 @@
70 70
71 Thu May 31 11:56:42 PDT 2001 gkh 71 Thu May 31 11:56:42 PDT 2001 gkh
72 switched from using spinlock to a semaphore 72 switched from using spinlock to a semaphore
73 73
74 (04/08/2001) gb 74 (04/08/2001) gb
75 Identify version on module load. 75 Identify version on module load.
76 76
77 (11/01/2000) Adam J. Richter 77 (11/01/2000) Adam J. Richter
78 usb_device_id table support. 78 usb_device_id table support.
79 79
80 Tue Oct 10 23:15:33 EST 2000 Hugh 80 Tue Oct 10 23:15:33 EST 2000 Hugh
81 Merged Paul's changes with my USA-49W mods. Work in progress 81 Merged Paul's changes with my USA-49W mods. Work in progress
82 still... 82 still...
83 83
84 Wed Jul 19 14:00:42 EST 2000 gkh 84 Wed Jul 19 14:00:42 EST 2000 gkh
85 Added module_init and module_exit functions to handle the fact that 85 Added module_init and module_exit functions to handle the fact that
86 this driver is a loadable module now. 86 this driver is a loadable module now.
87 87
88 Tue Jul 18 16:14:52 EST 2000 Hugh 88 Tue Jul 18 16:14:52 EST 2000 Hugh
89 Basic character input/output for USA-19 now mostly works, 89 Basic character input/output for USA-19 now mostly works,
90 fixed at 9600 baud for the moment. 90 fixed at 9600 baud for the moment.
@@ -107,7 +107,7 @@
107#include <linux/spinlock.h> 107#include <linux/spinlock.h>
108#include <linux/firmware.h> 108#include <linux/firmware.h>
109#include <linux/ihex.h> 109#include <linux/ihex.h>
110#include <asm/uaccess.h> 110#include <linux/uaccess.h>
111#include <linux/usb.h> 111#include <linux/usb.h>
112#include <linux/usb/serial.h> 112#include <linux/usb/serial.h>
113#include "keyspan.h" 113#include "keyspan.h"
@@ -132,15 +132,15 @@ struct keyspan_serial_private {
132 struct urb *instat_urb; 132 struct urb *instat_urb;
133 char instat_buf[INSTAT_BUFLEN]; 133 char instat_buf[INSTAT_BUFLEN];
134 134
135 /* added to support 49wg, where data from all 4 ports comes in on 1 EP */ 135 /* added to support 49wg, where data from all 4 ports comes in
136 /* and high-speed supported */ 136 on 1 EP and high-speed supported */
137 struct urb *indat_urb; 137 struct urb *indat_urb;
138 char indat_buf[INDAT49W_BUFLEN]; 138 char indat_buf[INDAT49W_BUFLEN];
139 139
140 /* XXX this one probably will need a lock */ 140 /* XXX this one probably will need a lock */
141 struct urb *glocont_urb; 141 struct urb *glocont_urb;
142 char glocont_buf[GLOCONT_BUFLEN]; 142 char glocont_buf[GLOCONT_BUFLEN];
143 char ctrl_buf[8]; // for EP0 control message 143 char ctrl_buf[8]; /* for EP0 control message */
144}; 144};
145 145
146struct keyspan_port_private { 146struct keyspan_port_private {
@@ -186,19 +186,19 @@ struct keyspan_port_private {
186 int resend_cont; /* need to resend control packet */ 186 int resend_cont; /* need to resend control packet */
187}; 187};
188 188
189
190/* Include Keyspan message headers. All current Keyspan Adapters 189/* Include Keyspan message headers. All current Keyspan Adapters
191 make use of one of five message formats which are referred 190 make use of one of five message formats which are referred
192 to as USA-26, USA-28, USA-49, USA-90, USA-67 by Keyspan and within this driver. */ 191 to as USA-26, USA-28, USA-49, USA-90, USA-67 by Keyspan and
192 within this driver. */
193#include "keyspan_usa26msg.h" 193#include "keyspan_usa26msg.h"
194#include "keyspan_usa28msg.h" 194#include "keyspan_usa28msg.h"
195#include "keyspan_usa49msg.h" 195#include "keyspan_usa49msg.h"
196#include "keyspan_usa90msg.h" 196#include "keyspan_usa90msg.h"
197#include "keyspan_usa67msg.h" 197#include "keyspan_usa67msg.h"
198 198
199 199
200/* Functions used by new usb-serial code. */ 200/* Functions used by new usb-serial code. */
201static int __init keyspan_init (void) 201static int __init keyspan_init(void)
202{ 202{
203 int retval; 203 int retval;
204 retval = usb_serial_register(&keyspan_pre_device); 204 retval = usb_serial_register(&keyspan_pre_device);
@@ -214,7 +214,7 @@ static int __init keyspan_init (void)
214 if (retval) 214 if (retval)
215 goto failed_4port_device_register; 215 goto failed_4port_device_register;
216 retval = usb_register(&keyspan_driver); 216 retval = usb_register(&keyspan_driver);
217 if (retval) 217 if (retval)
218 goto failed_usb_register; 218 goto failed_usb_register;
219 219
220 info(DRIVER_VERSION ":" DRIVER_DESC); 220 info(DRIVER_VERSION ":" DRIVER_DESC);
@@ -232,35 +232,24 @@ failed_pre_device_register:
232 return retval; 232 return retval;
233} 233}
234 234
235static void __exit keyspan_exit (void) 235static void __exit keyspan_exit(void)
236{ 236{
237 usb_deregister (&keyspan_driver); 237 usb_deregister(&keyspan_driver);
238 usb_serial_deregister (&keyspan_pre_device); 238 usb_serial_deregister(&keyspan_pre_device);
239 usb_serial_deregister (&keyspan_1port_device); 239 usb_serial_deregister(&keyspan_1port_device);
240 usb_serial_deregister (&keyspan_2port_device); 240 usb_serial_deregister(&keyspan_2port_device);
241 usb_serial_deregister (&keyspan_4port_device); 241 usb_serial_deregister(&keyspan_4port_device);
242} 242}
243 243
244module_init(keyspan_init); 244module_init(keyspan_init);
245module_exit(keyspan_exit); 245module_exit(keyspan_exit);
246 246
247static void keyspan_rx_throttle (struct usb_serial_port *port) 247static void keyspan_break_ctl(struct tty_struct *tty, int break_state)
248{
249 dbg("%s - port %d", __func__, port->number);
250}
251
252
253static void keyspan_rx_unthrottle (struct usb_serial_port *port)
254{
255 dbg("%s - port %d", __func__, port->number);
256}
257
258
259static void keyspan_break_ctl (struct usb_serial_port *port, int break_state)
260{ 248{
249 struct usb_serial_port *port = tty->driver_data;
261 struct keyspan_port_private *p_priv; 250 struct keyspan_port_private *p_priv;
262 251
263 dbg("%s", __func__); 252 dbg("%s", __func__);
264 253
265 p_priv = usb_get_serial_port_data(port); 254 p_priv = usb_get_serial_port_data(port);
266 255
@@ -273,14 +262,13 @@ static void keyspan_break_ctl (struct usb_serial_port *port, int break_state)
273} 262}
274 263
275 264
276static void keyspan_set_termios (struct usb_serial_port *port, 265static void keyspan_set_termios(struct tty_struct *tty,
277 struct ktermios *old_termios) 266 struct usb_serial_port *port, struct ktermios *old_termios)
278{ 267{
279 int baud_rate, device_port; 268 int baud_rate, device_port;
280 struct keyspan_port_private *p_priv; 269 struct keyspan_port_private *p_priv;
281 const struct keyspan_device_details *d_details; 270 const struct keyspan_device_details *d_details;
282 unsigned int cflag; 271 unsigned int cflag;
283 struct tty_struct *tty = port->tty;
284 272
285 dbg("%s", __func__); 273 dbg("%s", __func__);
286 274
@@ -292,7 +280,7 @@ static void keyspan_set_termios (struct usb_serial_port *port,
292 /* Baud rate calculation takes baud rate as an integer 280 /* Baud rate calculation takes baud rate as an integer
293 so other rates can be generated if desired. */ 281 so other rates can be generated if desired. */
294 baud_rate = tty_get_baud_rate(tty); 282 baud_rate = tty_get_baud_rate(tty);
295 /* If no match or invalid, don't change */ 283 /* If no match or invalid, don't change */
296 if (d_details->calculate_baud_rate(baud_rate, d_details->baudclk, 284 if (d_details->calculate_baud_rate(baud_rate, d_details->baudclk,
297 NULL, NULL, NULL, device_port) == KEYSPAN_BAUD_RATE_OK) { 285 NULL, NULL, NULL, device_port) == KEYSPAN_BAUD_RATE_OK) {
298 /* FIXME - more to do here to ensure rate changes cleanly */ 286 /* FIXME - more to do here to ensure rate changes cleanly */
@@ -312,35 +300,32 @@ static void keyspan_set_termios (struct usb_serial_port *port,
312 keyspan_send_setup(port, 0); 300 keyspan_send_setup(port, 0);
313} 301}
314 302
315static int keyspan_tiocmget(struct usb_serial_port *port, struct file *file) 303static int keyspan_tiocmget(struct tty_struct *tty, struct file *file)
316{ 304{
305 struct usb_serial_port *port = tty->driver_data;
306 struct keyspan_port_private *p_priv = usb_get_serial_port_data(port);
317 unsigned int value; 307 unsigned int value;
318 struct keyspan_port_private *p_priv;
319 308
320 p_priv = usb_get_serial_port_data(port);
321
322 value = ((p_priv->rts_state) ? TIOCM_RTS : 0) | 309 value = ((p_priv->rts_state) ? TIOCM_RTS : 0) |
323 ((p_priv->dtr_state) ? TIOCM_DTR : 0) | 310 ((p_priv->dtr_state) ? TIOCM_DTR : 0) |
324 ((p_priv->cts_state) ? TIOCM_CTS : 0) | 311 ((p_priv->cts_state) ? TIOCM_CTS : 0) |
325 ((p_priv->dsr_state) ? TIOCM_DSR : 0) | 312 ((p_priv->dsr_state) ? TIOCM_DSR : 0) |
326 ((p_priv->dcd_state) ? TIOCM_CAR : 0) | 313 ((p_priv->dcd_state) ? TIOCM_CAR : 0) |
327 ((p_priv->ri_state) ? TIOCM_RNG : 0); 314 ((p_priv->ri_state) ? TIOCM_RNG : 0);
328 315
329 return value; 316 return value;
330} 317}
331 318
332static int keyspan_tiocmset(struct usb_serial_port *port, struct file *file, 319static int keyspan_tiocmset(struct tty_struct *tty, struct file *file,
333 unsigned int set, unsigned int clear) 320 unsigned int set, unsigned int clear)
334{ 321{
335 struct keyspan_port_private *p_priv; 322 struct usb_serial_port *port = tty->driver_data;
323 struct keyspan_port_private *p_priv = usb_get_serial_port_data(port);
336 324
337 p_priv = usb_get_serial_port_data(port);
338
339 if (set & TIOCM_RTS) 325 if (set & TIOCM_RTS)
340 p_priv->rts_state = 1; 326 p_priv->rts_state = 1;
341 if (set & TIOCM_DTR) 327 if (set & TIOCM_DTR)
342 p_priv->dtr_state = 1; 328 p_priv->dtr_state = 1;
343
344 if (clear & TIOCM_RTS) 329 if (clear & TIOCM_RTS)
345 p_priv->rts_state = 0; 330 p_priv->rts_state = 0;
346 if (clear & TIOCM_DTR) 331 if (clear & TIOCM_DTR)
@@ -349,35 +334,29 @@ static int keyspan_tiocmset(struct usb_serial_port *port, struct file *file,
349 return 0; 334 return 0;
350} 335}
351 336
352static int keyspan_ioctl(struct usb_serial_port *port, struct file *file, 337/* Write function is similar for the four protocols used
353 unsigned int cmd, unsigned long arg) 338 with only a minor change for usa90 (usa19hs) required */
354{ 339static int keyspan_write(struct tty_struct *tty,
355 return -ENOIOCTLCMD; 340 struct usb_serial_port *port, const unsigned char *buf, int count)
356}
357
358 /* Write function is similar for the four protocols used
359 with only a minor change for usa90 (usa19hs) required */
360static int keyspan_write(struct usb_serial_port *port,
361 const unsigned char *buf, int count)
362{ 341{
363 struct keyspan_port_private *p_priv; 342 struct keyspan_port_private *p_priv;
364 const struct keyspan_device_details *d_details; 343 const struct keyspan_device_details *d_details;
365 int flip; 344 int flip;
366 int left, todo; 345 int left, todo;
367 struct urb *this_urb; 346 struct urb *this_urb;
368 int err, maxDataLen, dataOffset; 347 int err, maxDataLen, dataOffset;
369 348
370 p_priv = usb_get_serial_port_data(port); 349 p_priv = usb_get_serial_port_data(port);
371 d_details = p_priv->device_details; 350 d_details = p_priv->device_details;
372 351
373 if (d_details->msg_format == msg_usa90) { 352 if (d_details->msg_format == msg_usa90) {
374 maxDataLen = 64; 353 maxDataLen = 64;
375 dataOffset = 0; 354 dataOffset = 0;
376 } else { 355 } else {
377 maxDataLen = 63; 356 maxDataLen = 63;
378 dataOffset = 1; 357 dataOffset = 1;
379 } 358 }
380 359
381 dbg("%s - for port %d (%d chars), flip=%d", 360 dbg("%s - for port %d (%d chars), flip=%d",
382 __func__, port->number, count, p_priv->out_flip); 361 __func__, port->number, count, p_priv->out_flip);
383 362
@@ -387,37 +366,40 @@ static int keyspan_write(struct usb_serial_port *port,
387 todo = maxDataLen; 366 todo = maxDataLen;
388 367
389 flip = p_priv->out_flip; 368 flip = p_priv->out_flip;
390 369
391 /* Check we have a valid urb/endpoint before we use it... */ 370 /* Check we have a valid urb/endpoint before we use it... */
392 if ((this_urb = p_priv->out_urbs[flip]) == NULL) { 371 this_urb = p_priv->out_urbs[flip];
372 if (this_urb == NULL) {
393 /* no bulk out, so return 0 bytes written */ 373 /* no bulk out, so return 0 bytes written */
394 dbg("%s - no output urb :(", __func__); 374 dbg("%s - no output urb :(", __func__);
395 return count; 375 return count;
396 } 376 }
397 377
398 dbg("%s - endpoint %d flip %d", __func__, usb_pipeendpoint(this_urb->pipe), flip); 378 dbg("%s - endpoint %d flip %d",
379 __func__, usb_pipeendpoint(this_urb->pipe), flip);
399 380
400 if (this_urb->status == -EINPROGRESS) { 381 if (this_urb->status == -EINPROGRESS) {
401 if (time_before(jiffies, p_priv->tx_start_time[flip] + 10 * HZ)) 382 if (time_before(jiffies,
383 p_priv->tx_start_time[flip] + 10 * HZ))
402 break; 384 break;
403 usb_unlink_urb(this_urb); 385 usb_unlink_urb(this_urb);
404 break; 386 break;
405 } 387 }
406 388
407 /* First byte in buffer is "last flag" (except for usa19hx) - unused so 389 /* First byte in buffer is "last flag" (except for usa19hx)
408 for now so set to zero */ 390 - unused so for now so set to zero */
409 ((char *)this_urb->transfer_buffer)[0] = 0; 391 ((char *)this_urb->transfer_buffer)[0] = 0;
410 392
411 memcpy (this_urb->transfer_buffer + dataOffset, buf, todo); 393 memcpy(this_urb->transfer_buffer + dataOffset, buf, todo);
412 buf += todo; 394 buf += todo;
413 395
414 /* send the data out the bulk port */ 396 /* send the data out the bulk port */
415 this_urb->transfer_buffer_length = todo + dataOffset; 397 this_urb->transfer_buffer_length = todo + dataOffset;
416 398
417 this_urb->dev = port->serial->dev; 399 this_urb->dev = port->serial->dev;
418 if ((err = usb_submit_urb(this_urb, GFP_ATOMIC)) != 0) { 400 err = usb_submit_urb(this_urb, GFP_ATOMIC);
401 if (err != 0)
419 dbg("usb_submit_urb(write bulk) failed (%d)", err); 402 dbg("usb_submit_urb(write bulk) failed (%d)", err);
420 }
421 p_priv->tx_start_time[flip] = jiffies; 403 p_priv->tx_start_time[flip] = jiffies;
422 404
423 /* Flip for next time if usa26 or usa28 interface 405 /* Flip for next time if usa26 or usa28 interface
@@ -437,7 +419,7 @@ static void usa26_indat_callback(struct urb *urb)
437 unsigned char *data = urb->transfer_buffer; 419 unsigned char *data = urb->transfer_buffer;
438 int status = urb->status; 420 int status = urb->status;
439 421
440 dbg ("%s", __func__); 422 dbg("%s", __func__);
441 423
442 endpoint = usb_pipeendpoint(urb->pipe); 424 endpoint = usb_pipeendpoint(urb->pipe);
443 425
@@ -448,17 +430,18 @@ static void usa26_indat_callback(struct urb *urb)
448 } 430 }
449 431
450 port = urb->context; 432 port = urb->context;
451 tty = port->tty; 433 tty = port->port.tty;
452 if (tty && urb->actual_length) { 434 if (tty && urb->actual_length) {
453 /* 0x80 bit is error flag */ 435 /* 0x80 bit is error flag */
454 if ((data[0] & 0x80) == 0) { 436 if ((data[0] & 0x80) == 0) {
455 /* no errors on individual bytes, only possible overrun err*/ 437 /* no errors on individual bytes, only
438 possible overrun err */
456 if (data[0] & RXERROR_OVERRUN) 439 if (data[0] & RXERROR_OVERRUN)
457 err = TTY_OVERRUN; 440 err = TTY_OVERRUN;
458 else err = 0; 441 else
459 for (i = 1; i < urb->actual_length ; ++i) { 442 err = 0;
443 for (i = 1; i < urb->actual_length ; ++i)
460 tty_insert_flip_char(tty, data[i], err); 444 tty_insert_flip_char(tty, data[i], err);
461 }
462 } else { 445 } else {
463 /* some bytes had errors, every byte has status */ 446 /* some bytes had errors, every byte has status */
464 dbg("%s - RX error!!!!", __func__); 447 dbg("%s - RX error!!!!", __func__);
@@ -476,17 +459,19 @@ static void usa26_indat_callback(struct urb *urb)
476 } 459 }
477 tty_flip_buffer_push(tty); 460 tty_flip_buffer_push(tty);
478 } 461 }
479 462
480 /* Resubmit urb so we continue receiving */ 463 /* Resubmit urb so we continue receiving */
481 urb->dev = port->serial->dev; 464 urb->dev = port->serial->dev;
482 if (port->open_count) 465 if (port->port.count) {
483 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) { 466 err = usb_submit_urb(urb, GFP_ATOMIC);
484 dbg("%s - resubmit read urb failed. (%d)", __func__, err); 467 if (err != 0)
485 } 468 dbg("%s - resubmit read urb failed. (%d)",
469 __func__, err);
470 }
486 return; 471 return;
487} 472}
488 473
489 /* Outdat handling is common for all devices */ 474/* Outdat handling is common for all devices */
490static void usa2x_outdat_callback(struct urb *urb) 475static void usa2x_outdat_callback(struct urb *urb)
491{ 476{
492 struct usb_serial_port *port; 477 struct usb_serial_port *port;
@@ -494,16 +479,16 @@ static void usa2x_outdat_callback(struct urb *urb)
494 479
495 port = urb->context; 480 port = urb->context;
496 p_priv = usb_get_serial_port_data(port); 481 p_priv = usb_get_serial_port_data(port);
497 dbg ("%s - urb %d", __func__, urb == p_priv->out_urbs[1]); 482 dbg("%s - urb %d", __func__, urb == p_priv->out_urbs[1]);
498 483
499 if (port->open_count) 484 if (port->port.count)
500 usb_serial_port_softint(port); 485 usb_serial_port_softint(port);
501} 486}
502 487
503static void usa26_inack_callback(struct urb *urb) 488static void usa26_inack_callback(struct urb *urb)
504{ 489{
505 dbg ("%s", __func__); 490 dbg("%s", __func__);
506 491
507} 492}
508 493
509static void usa26_outcont_callback(struct urb *urb) 494static void usa26_outcont_callback(struct urb *urb)
@@ -515,8 +500,9 @@ static void usa26_outcont_callback(struct urb *urb)
515 p_priv = usb_get_serial_port_data(port); 500 p_priv = usb_get_serial_port_data(port);
516 501
517 if (p_priv->resend_cont) { 502 if (p_priv->resend_cont) {
518 dbg ("%s - sending setup", __func__); 503 dbg("%s - sending setup", __func__);
519 keyspan_usa26_send_setup(port->serial, port, p_priv->resend_cont - 1); 504 keyspan_usa26_send_setup(port->serial, port,
505 p_priv->resend_cont - 1);
520 } 506 }
521} 507}
522 508
@@ -552,14 +538,14 @@ static void usa26_instat_callback(struct urb *urb)
552 /* Now do something useful with the data */ 538 /* Now do something useful with the data */
553 539
554 540
555 /* Check port number from message and retrieve private data */ 541 /* Check port number from message and retrieve private data */
556 if (msg->port >= serial->num_ports) { 542 if (msg->port >= serial->num_ports) {
557 dbg ("%s - Unexpected port number %d", __func__, msg->port); 543 dbg("%s - Unexpected port number %d", __func__, msg->port);
558 goto exit; 544 goto exit;
559 } 545 }
560 port = serial->port[msg->port]; 546 port = serial->port[msg->port];
561 p_priv = usb_get_serial_port_data(port); 547 p_priv = usb_get_serial_port_data(port);
562 548
563 /* Update handshaking pin state information */ 549 /* Update handshaking pin state information */
564 old_dcd_state = p_priv->dcd_state; 550 old_dcd_state = p_priv->dcd_state;
565 p_priv->cts_state = ((msg->hskia_cts) ? 1 : 0); 551 p_priv->cts_state = ((msg->hskia_cts) ? 1 : 0);
@@ -567,39 +553,38 @@ static void usa26_instat_callback(struct urb *urb)
567 p_priv->dcd_state = ((msg->gpia_dcd) ? 1 : 0); 553 p_priv->dcd_state = ((msg->gpia_dcd) ? 1 : 0);
568 p_priv->ri_state = ((msg->ri) ? 1 : 0); 554 p_priv->ri_state = ((msg->ri) ? 1 : 0);
569 555
570 if (port->tty && !C_CLOCAL(port->tty) 556 if (port->port.tty && !C_CLOCAL(port->port.tty)
571 && old_dcd_state != p_priv->dcd_state) { 557 && old_dcd_state != p_priv->dcd_state) {
572 if (old_dcd_state) 558 if (old_dcd_state)
573 tty_hangup(port->tty); 559 tty_hangup(port->port.tty);
574 /* else */ 560 /* else */
575 /* wake_up_interruptible(&p_priv->open_wait); */ 561 /* wake_up_interruptible(&p_priv->open_wait); */
576 } 562 }
577 563
578 /* Resubmit urb so we continue receiving */ 564 /* Resubmit urb so we continue receiving */
579 urb->dev = serial->dev; 565 urb->dev = serial->dev;
580 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) { 566 err = usb_submit_urb(urb, GFP_ATOMIC);
567 if (err != 0)
581 dbg("%s - resubmit read urb failed. (%d)", __func__, err); 568 dbg("%s - resubmit read urb failed. (%d)", __func__, err);
582 }
583exit: ; 569exit: ;
584} 570}
585 571
586static void usa26_glocont_callback(struct urb *urb) 572static void usa26_glocont_callback(struct urb *urb)
587{ 573{
588 dbg ("%s", __func__); 574 dbg("%s", __func__);
589
590} 575}
591 576
592 577
593static void usa28_indat_callback(struct urb *urb) 578static void usa28_indat_callback(struct urb *urb)
594{ 579{
595 int i, err; 580 int err;
596 struct usb_serial_port *port; 581 struct usb_serial_port *port;
597 struct tty_struct *tty; 582 struct tty_struct *tty;
598 unsigned char *data; 583 unsigned char *data;
599 struct keyspan_port_private *p_priv; 584 struct keyspan_port_private *p_priv;
600 int status = urb->status; 585 int status = urb->status;
601 586
602 dbg ("%s", __func__); 587 dbg("%s", __func__);
603 588
604 port = urb->context; 589 port = urb->context;
605 p_priv = usb_get_serial_port_data(port); 590 p_priv = usb_get_serial_port_data(port);
@@ -619,20 +604,20 @@ static void usa28_indat_callback(struct urb *urb)
619 p_priv = usb_get_serial_port_data(port); 604 p_priv = usb_get_serial_port_data(port);
620 data = urb->transfer_buffer; 605 data = urb->transfer_buffer;
621 606
622 tty = port->tty; 607 tty = port->port.tty;
623 if (urb->actual_length) { 608 if (urb->actual_length) {
624 for (i = 0; i < urb->actual_length ; ++i) { 609 tty_insert_flip_string(tty, data, urb->actual_length);
625 tty_insert_flip_char(tty, data[i], 0);
626 }
627 tty_flip_buffer_push(tty); 610 tty_flip_buffer_push(tty);
628 } 611 }
629 612
630 /* Resubmit urb so we continue receiving */ 613 /* Resubmit urb so we continue receiving */
631 urb->dev = port->serial->dev; 614 urb->dev = port->serial->dev;
632 if (port->open_count) 615 if (port->port.count) {
633 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) { 616 err = usb_submit_urb(urb, GFP_ATOMIC);
634 dbg("%s - resubmit read urb failed. (%d)", __func__, err); 617 if (err != 0)
635 } 618 dbg("%s - resubmit read urb failed. (%d)",
619 __func__, err);
620 }
636 p_priv->in_flip ^= 1; 621 p_priv->in_flip ^= 1;
637 622
638 urb = p_priv->in_urbs[p_priv->in_flip]; 623 urb = p_priv->in_urbs[p_priv->in_flip];
@@ -641,7 +626,7 @@ static void usa28_indat_callback(struct urb *urb)
641 626
642static void usa28_inack_callback(struct urb *urb) 627static void usa28_inack_callback(struct urb *urb)
643{ 628{
644 dbg ("%s", __func__); 629 dbg("%s", __func__);
645} 630}
646 631
647static void usa28_outcont_callback(struct urb *urb) 632static void usa28_outcont_callback(struct urb *urb)
@@ -653,8 +638,9 @@ static void usa28_outcont_callback(struct urb *urb)
653 p_priv = usb_get_serial_port_data(port); 638 p_priv = usb_get_serial_port_data(port);
654 639
655 if (p_priv->resend_cont) { 640 if (p_priv->resend_cont) {
656 dbg ("%s - sending setup", __func__); 641 dbg("%s - sending setup", __func__);
657 keyspan_usa28_send_setup(port->serial, port, p_priv->resend_cont - 1); 642 keyspan_usa28_send_setup(port->serial, port,
643 p_priv->resend_cont - 1);
658 } 644 }
659} 645}
660 646
@@ -684,19 +670,18 @@ static void usa28_instat_callback(struct urb *urb)
684 /*dbg("%s %x %x %x %x %x %x %x %x %x %x %x %x", __func__ 670 /*dbg("%s %x %x %x %x %x %x %x %x %x %x %x %x", __func__
685 data[0], data[1], data[2], data[3], data[4], data[5], 671 data[0], data[1], data[2], data[3], data[4], data[5],
686 data[6], data[7], data[8], data[9], data[10], data[11]);*/ 672 data[6], data[7], data[8], data[9], data[10], data[11]);*/
687
688 /* Now do something useful with the data */
689 msg = (struct keyspan_usa28_portStatusMessage *)data;
690 673
674 /* Now do something useful with the data */
675 msg = (struct keyspan_usa28_portStatusMessage *)data;
691 676
692 /* Check port number from message and retrieve private data */ 677 /* Check port number from message and retrieve private data */
693 if (msg->port >= serial->num_ports) { 678 if (msg->port >= serial->num_ports) {
694 dbg ("%s - Unexpected port number %d", __func__, msg->port); 679 dbg("%s - Unexpected port number %d", __func__, msg->port);
695 goto exit; 680 goto exit;
696 } 681 }
697 port = serial->port[msg->port]; 682 port = serial->port[msg->port];
698 p_priv = usb_get_serial_port_data(port); 683 p_priv = usb_get_serial_port_data(port);
699 684
700 /* Update handshaking pin state information */ 685 /* Update handshaking pin state information */
701 old_dcd_state = p_priv->dcd_state; 686 old_dcd_state = p_priv->dcd_state;
702 p_priv->cts_state = ((msg->cts) ? 1 : 0); 687 p_priv->cts_state = ((msg->cts) ? 1 : 0);
@@ -704,25 +689,25 @@ static void usa28_instat_callback(struct urb *urb)
704 p_priv->dcd_state = ((msg->dcd) ? 1 : 0); 689 p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
705 p_priv->ri_state = ((msg->ri) ? 1 : 0); 690 p_priv->ri_state = ((msg->ri) ? 1 : 0);
706 691
707 if (port->tty && !C_CLOCAL(port->tty) 692 if (port->port.tty && !C_CLOCAL(port->port.tty)
708 && old_dcd_state != p_priv->dcd_state) { 693 && old_dcd_state != p_priv->dcd_state) {
709 if (old_dcd_state) 694 if (old_dcd_state)
710 tty_hangup(port->tty); 695 tty_hangup(port->port.tty);
711 /* else */ 696 /* else */
712 /* wake_up_interruptible(&p_priv->open_wait); */ 697 /* wake_up_interruptible(&p_priv->open_wait); */
713 } 698 }
714 699
715 /* Resubmit urb so we continue receiving */ 700 /* Resubmit urb so we continue receiving */
716 urb->dev = serial->dev; 701 urb->dev = serial->dev;
717 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) { 702 err = usb_submit_urb(urb, GFP_ATOMIC);
703 if (err != 0)
718 dbg("%s - resubmit read urb failed. (%d)", __func__, err); 704 dbg("%s - resubmit read urb failed. (%d)", __func__, err);
719 }
720exit: ; 705exit: ;
721} 706}
722 707
723static void usa28_glocont_callback(struct urb *urb) 708static void usa28_glocont_callback(struct urb *urb)
724{ 709{
725 dbg ("%s", __func__); 710 dbg("%s", __func__);
726} 711}
727 712
728 713
@@ -733,7 +718,7 @@ static void usa49_glocont_callback(struct urb *urb)
733 struct keyspan_port_private *p_priv; 718 struct keyspan_port_private *p_priv;
734 int i; 719 int i;
735 720
736 dbg ("%s", __func__); 721 dbg("%s", __func__);
737 722
738 serial = urb->context; 723 serial = urb->context;
739 for (i = 0; i < serial->num_ports; ++i) { 724 for (i = 0; i < serial->num_ports; ++i) {
@@ -741,8 +726,9 @@ static void usa49_glocont_callback(struct urb *urb)
741 p_priv = usb_get_serial_port_data(port); 726 p_priv = usb_get_serial_port_data(port);
742 727
743 if (p_priv->resend_cont) { 728 if (p_priv->resend_cont) {
744 dbg ("%s - sending setup", __func__); 729 dbg("%s - sending setup", __func__);
745 keyspan_usa49_send_setup(serial, port, p_priv->resend_cont - 1); 730 keyspan_usa49_send_setup(serial, port,
731 p_priv->resend_cont - 1);
746 break; 732 break;
747 } 733 }
748 } 734 }
@@ -761,7 +747,7 @@ static void usa49_instat_callback(struct urb *urb)
761 int old_dcd_state; 747 int old_dcd_state;
762 int status = urb->status; 748 int status = urb->status;
763 749
764 dbg ("%s", __func__); 750 dbg("%s", __func__);
765 751
766 serial = urb->context; 752 serial = urb->context;
767 753
@@ -770,7 +756,8 @@ static void usa49_instat_callback(struct urb *urb)
770 return; 756 return;
771 } 757 }
772 758
773 if (urb->actual_length != sizeof(struct keyspan_usa49_portStatusMessage)) { 759 if (urb->actual_length !=
760 sizeof(struct keyspan_usa49_portStatusMessage)) {
774 dbg("%s - bad length %d", __func__, urb->actual_length); 761 dbg("%s - bad length %d", __func__, urb->actual_length);
775 goto exit; 762 goto exit;
776 } 763 }
@@ -778,18 +765,19 @@ static void usa49_instat_callback(struct urb *urb)
778 /*dbg(" %x %x %x %x %x %x %x %x %x %x %x", __func__, 765 /*dbg(" %x %x %x %x %x %x %x %x %x %x %x", __func__,
779 data[0], data[1], data[2], data[3], data[4], data[5], 766 data[0], data[1], data[2], data[3], data[4], data[5],
780 data[6], data[7], data[8], data[9], data[10]);*/ 767 data[6], data[7], data[8], data[9], data[10]);*/
781 768
782 /* Now do something useful with the data */ 769 /* Now do something useful with the data */
783 msg = (struct keyspan_usa49_portStatusMessage *)data; 770 msg = (struct keyspan_usa49_portStatusMessage *)data;
784 771
785 /* Check port number from message and retrieve private data */ 772 /* Check port number from message and retrieve private data */
786 if (msg->portNumber >= serial->num_ports) { 773 if (msg->portNumber >= serial->num_ports) {
787 dbg ("%s - Unexpected port number %d", __func__, msg->portNumber); 774 dbg("%s - Unexpected port number %d",
775 __func__, msg->portNumber);
788 goto exit; 776 goto exit;
789 } 777 }
790 port = serial->port[msg->portNumber]; 778 port = serial->port[msg->portNumber];
791 p_priv = usb_get_serial_port_data(port); 779 p_priv = usb_get_serial_port_data(port);
792 780
793 /* Update handshaking pin state information */ 781 /* Update handshaking pin state information */
794 old_dcd_state = p_priv->dcd_state; 782 old_dcd_state = p_priv->dcd_state;
795 p_priv->cts_state = ((msg->cts) ? 1 : 0); 783 p_priv->cts_state = ((msg->cts) ? 1 : 0);
@@ -797,26 +785,26 @@ static void usa49_instat_callback(struct urb *urb)
797 p_priv->dcd_state = ((msg->dcd) ? 1 : 0); 785 p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
798 p_priv->ri_state = ((msg->ri) ? 1 : 0); 786 p_priv->ri_state = ((msg->ri) ? 1 : 0);
799 787
800 if (port->tty && !C_CLOCAL(port->tty) 788 if (port->port.tty && !C_CLOCAL(port->port.tty)
801 && old_dcd_state != p_priv->dcd_state) { 789 && old_dcd_state != p_priv->dcd_state) {
802 if (old_dcd_state) 790 if (old_dcd_state)
803 tty_hangup(port->tty); 791 tty_hangup(port->port.tty);
804 /* else */ 792 /* else */
805 /* wake_up_interruptible(&p_priv->open_wait); */ 793 /* wake_up_interruptible(&p_priv->open_wait); */
806 } 794 }
807 795
808 /* Resubmit urb so we continue receiving */ 796 /* Resubmit urb so we continue receiving */
809 urb->dev = serial->dev; 797 urb->dev = serial->dev;
810 798
811 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) { 799 err = usb_submit_urb(urb, GFP_ATOMIC);
800 if (err != 0)
812 dbg("%s - resubmit read urb failed. (%d)", __func__, err); 801 dbg("%s - resubmit read urb failed. (%d)", __func__, err);
813 }
814exit: ; 802exit: ;
815} 803}
816 804
817static void usa49_inack_callback(struct urb *urb) 805static void usa49_inack_callback(struct urb *urb)
818{ 806{
819 dbg ("%s", __func__); 807 dbg("%s", __func__);
820} 808}
821 809
822static void usa49_indat_callback(struct urb *urb) 810static void usa49_indat_callback(struct urb *urb)
@@ -828,7 +816,7 @@ static void usa49_indat_callback(struct urb *urb)
828 unsigned char *data = urb->transfer_buffer; 816 unsigned char *data = urb->transfer_buffer;
829 int status = urb->status; 817 int status = urb->status;
830 818
831 dbg ("%s", __func__); 819 dbg("%s", __func__);
832 820
833 endpoint = usb_pipeendpoint(urb->pipe); 821 endpoint = usb_pipeendpoint(urb->pipe);
834 822
@@ -839,14 +827,13 @@ static void usa49_indat_callback(struct urb *urb)
839 } 827 }
840 828
841 port = urb->context; 829 port = urb->context;
842 tty = port->tty; 830 tty = port->port.tty;
843 if (tty && urb->actual_length) { 831 if (tty && urb->actual_length) {
844 /* 0x80 bit is error flag */ 832 /* 0x80 bit is error flag */
845 if ((data[0] & 0x80) == 0) { 833 if ((data[0] & 0x80) == 0) {
846 /* no error on any byte */ 834 /* no error on any byte */
847 for (i = 1; i < urb->actual_length ; ++i) { 835 tty_insert_flip_string(tty, data + 1,
848 tty_insert_flip_char(tty, data[i], 0); 836 urb->actual_length - 1);
849 }
850 } else { 837 } else {
851 /* some bytes had errors, every byte has status */ 838 /* some bytes had errors, every byte has status */
852 for (i = 0; i + 1 < urb->actual_length; i += 2) { 839 for (i = 0; i + 1 < urb->actual_length; i += 2) {
@@ -863,13 +850,15 @@ static void usa49_indat_callback(struct urb *urb)
863 } 850 }
864 tty_flip_buffer_push(tty); 851 tty_flip_buffer_push(tty);
865 } 852 }
866 853
867 /* Resubmit urb so we continue receiving */ 854 /* Resubmit urb so we continue receiving */
868 urb->dev = port->serial->dev; 855 urb->dev = port->serial->dev;
869 if (port->open_count) 856 if (port->port.count) {
870 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) { 857 err = usb_submit_urb(urb, GFP_ATOMIC);
871 dbg("%s - resubmit read urb failed. (%d)", __func__, err); 858 if (err != 0)
872 } 859 dbg("%s - resubmit read urb failed. (%d)",
860 __func__, err);
861 }
873} 862}
874 863
875static void usa49wg_indat_callback(struct urb *urb) 864static void usa49wg_indat_callback(struct urb *urb)
@@ -881,7 +870,7 @@ static void usa49wg_indat_callback(struct urb *urb)
881 unsigned char *data = urb->transfer_buffer; 870 unsigned char *data = urb->transfer_buffer;
882 int status = urb->status; 871 int status = urb->status;
883 872
884 dbg ("%s", __func__); 873 dbg("%s", __func__);
885 874
886 serial = urb->context; 875 serial = urb->context;
887 876
@@ -899,12 +888,12 @@ static void usa49wg_indat_callback(struct urb *urb)
899 888
900 /* Check port number from message*/ 889 /* Check port number from message*/
901 if (data[i] >= serial->num_ports) { 890 if (data[i] >= serial->num_ports) {
902 dbg ("%s - Unexpected port number %d", 891 dbg("%s - Unexpected port number %d",
903 __func__, data[i]); 892 __func__, data[i]);
904 return; 893 return;
905 } 894 }
906 port = serial->port[data[i++]]; 895 port = serial->port[data[i++]];
907 tty = port->tty; 896 tty = port->port.tty;
908 len = data[i++]; 897 len = data[i++];
909 898
910 /* 0x80 bit is error flag */ 899 /* 0x80 bit is error flag */
@@ -912,7 +901,7 @@ static void usa49wg_indat_callback(struct urb *urb)
912 /* no error on any byte */ 901 /* no error on any byte */
913 i++; 902 i++;
914 for (x = 1; x < len ; ++x) 903 for (x = 1; x < len ; ++x)
915 if (port->open_count) 904 if (port->port.count)
916 tty_insert_flip_char(tty, 905 tty_insert_flip_char(tty,
917 data[i++], 0); 906 data[i++], 0);
918 else 907 else
@@ -930,13 +919,13 @@ static void usa49wg_indat_callback(struct urb *urb)
930 if (stat & RXERROR_PARITY) 919 if (stat & RXERROR_PARITY)
931 flag |= TTY_PARITY; 920 flag |= TTY_PARITY;
932 /* XXX should handle break (0x10) */ 921 /* XXX should handle break (0x10) */
933 if (port->open_count) 922 if (port->port.count)
934 tty_insert_flip_char(tty, 923 tty_insert_flip_char(tty,
935 data[i+1], flag); 924 data[i+1], flag);
936 i += 2; 925 i += 2;
937 } 926 }
938 } 927 }
939 if (port->open_count) 928 if (port->port.count)
940 tty_flip_buffer_push(tty); 929 tty_flip_buffer_push(tty);
941 } 930 }
942 } 931 }
@@ -952,7 +941,7 @@ static void usa49wg_indat_callback(struct urb *urb)
952/* not used, usa-49 doesn't have per-port control endpoints */ 941/* not used, usa-49 doesn't have per-port control endpoints */
953static void usa49_outcont_callback(struct urb *urb) 942static void usa49_outcont_callback(struct urb *urb)
954{ 943{
955 dbg ("%s", __func__); 944 dbg("%s", __func__);
956} 945}
957 946
958static void usa90_indat_callback(struct urb *urb) 947static void usa90_indat_callback(struct urb *urb)
@@ -965,7 +954,7 @@ static void usa90_indat_callback(struct urb *urb)
965 unsigned char *data = urb->transfer_buffer; 954 unsigned char *data = urb->transfer_buffer;
966 int status = urb->status; 955 int status = urb->status;
967 956
968 dbg ("%s", __func__); 957 dbg("%s", __func__);
969 958
970 endpoint = usb_pipeendpoint(urb->pipe); 959 endpoint = usb_pipeendpoint(urb->pipe);
971 960
@@ -978,29 +967,26 @@ static void usa90_indat_callback(struct urb *urb)
978 port = urb->context; 967 port = urb->context;
979 p_priv = usb_get_serial_port_data(port); 968 p_priv = usb_get_serial_port_data(port);
980 969
981 tty = port->tty; 970 tty = port->port.tty;
982 if (urb->actual_length) { 971 if (urb->actual_length) {
983
984 /* if current mode is DMA, looks like usa28 format 972 /* if current mode is DMA, looks like usa28 format
985 otherwise looks like usa26 data format */ 973 otherwise looks like usa26 data format */
986 974
987 if (p_priv->baud > 57600) { 975 if (p_priv->baud > 57600)
988 for (i = 0; i < urb->actual_length ; ++i) 976 tty_insert_flip_string(tty, data, urb->actual_length);
989 tty_insert_flip_char(tty, data[i], 0);
990 }
991 else { 977 else {
992
993 /* 0x80 bit is error flag */ 978 /* 0x80 bit is error flag */
994 if ((data[0] & 0x80) == 0) { 979 if ((data[0] & 0x80) == 0) {
995 /* no errors on individual bytes, only possible overrun err*/ 980 /* no errors on individual bytes, only
981 possible overrun err*/
996 if (data[0] & RXERROR_OVERRUN) 982 if (data[0] & RXERROR_OVERRUN)
997 err = TTY_OVERRUN; 983 err = TTY_OVERRUN;
998 else err = 0; 984 else
999 for (i = 1; i < urb->actual_length ; ++i) 985 err = 0;
1000 tty_insert_flip_char(tty, data[i], err); 986 for (i = 1; i < urb->actual_length ; ++i)
1001 987 tty_insert_flip_char(tty, data[i],
1002 } 988 err);
1003 else { 989 } else {
1004 /* some bytes had errors, every byte has status */ 990 /* some bytes had errors, every byte has status */
1005 dbg("%s - RX error!!!!", __func__); 991 dbg("%s - RX error!!!!", __func__);
1006 for (i = 0; i + 1 < urb->actual_length; i += 2) { 992 for (i = 0; i + 1 < urb->actual_length; i += 2) {
@@ -1012,19 +998,22 @@ static void usa90_indat_callback(struct urb *urb)
1012 if (stat & RXERROR_PARITY) 998 if (stat & RXERROR_PARITY)
1013 flag |= TTY_PARITY; 999 flag |= TTY_PARITY;
1014 /* XXX should handle break (0x10) */ 1000 /* XXX should handle break (0x10) */
1015 tty_insert_flip_char(tty, data[i+1], flag); 1001 tty_insert_flip_char(tty, data[i+1],
1002 flag);
1016 } 1003 }
1017 } 1004 }
1018 } 1005 }
1019 tty_flip_buffer_push(tty); 1006 tty_flip_buffer_push(tty);
1020 } 1007 }
1021 1008
1022 /* Resubmit urb so we continue receiving */ 1009 /* Resubmit urb so we continue receiving */
1023 urb->dev = port->serial->dev; 1010 urb->dev = port->serial->dev;
1024 if (port->open_count) 1011 if (port->port.count) {
1025 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) { 1012 err = usb_submit_urb(urb, GFP_ATOMIC);
1026 dbg("%s - resubmit read urb failed. (%d)", __func__, err); 1013 if (err != 0)
1027 } 1014 dbg("%s - resubmit read urb failed. (%d)",
1015 __func__, err);
1016 }
1028 return; 1017 return;
1029} 1018}
1030 1019
@@ -1056,7 +1045,7 @@ static void usa90_instat_callback(struct urb *urb)
1056 1045
1057 port = serial->port[0]; 1046 port = serial->port[0];
1058 p_priv = usb_get_serial_port_data(port); 1047 p_priv = usb_get_serial_port_data(port);
1059 1048
1060 /* Update handshaking pin state information */ 1049 /* Update handshaking pin state information */
1061 old_dcd_state = p_priv->dcd_state; 1050 old_dcd_state = p_priv->dcd_state;
1062 p_priv->cts_state = ((msg->cts) ? 1 : 0); 1051 p_priv->cts_state = ((msg->cts) ? 1 : 0);
@@ -1064,19 +1053,19 @@ static void usa90_instat_callback(struct urb *urb)
1064 p_priv->dcd_state = ((msg->dcd) ? 1 : 0); 1053 p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
1065 p_priv->ri_state = ((msg->ri) ? 1 : 0); 1054 p_priv->ri_state = ((msg->ri) ? 1 : 0);
1066 1055
1067 if (port->tty && !C_CLOCAL(port->tty) 1056 if (port->port.tty && !C_CLOCAL(port->port.tty)
1068 && old_dcd_state != p_priv->dcd_state) { 1057 && old_dcd_state != p_priv->dcd_state) {
1069 if (old_dcd_state) 1058 if (old_dcd_state)
1070 tty_hangup(port->tty); 1059 tty_hangup(port->port.tty);
1071 /* else */ 1060 /* else */
1072 /* wake_up_interruptible(&p_priv->open_wait); */ 1061 /* wake_up_interruptible(&p_priv->open_wait); */
1073 } 1062 }
1074 1063
1075 /* Resubmit urb so we continue receiving */ 1064 /* Resubmit urb so we continue receiving */
1076 urb->dev = serial->dev; 1065 urb->dev = serial->dev;
1077 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) { 1066 err = usb_submit_urb(urb, GFP_ATOMIC);
1067 if (err != 0)
1078 dbg("%s - resubmit read urb failed. (%d)", __func__, err); 1068 dbg("%s - resubmit read urb failed. (%d)", __func__, err);
1079 }
1080exit: 1069exit:
1081 ; 1070 ;
1082} 1071}
@@ -1090,8 +1079,9 @@ static void usa90_outcont_callback(struct urb *urb)
1090 p_priv = usb_get_serial_port_data(port); 1079 p_priv = usb_get_serial_port_data(port);
1091 1080
1092 if (p_priv->resend_cont) { 1081 if (p_priv->resend_cont) {
1093 dbg ("%s - sending setup", __func__); 1082 dbg("%s - sending setup", __func__);
1094 keyspan_usa90_send_setup(port->serial, port, p_priv->resend_cont - 1); 1083 keyspan_usa90_send_setup(port->serial, port,
1084 p_priv->resend_cont - 1);
1095 } 1085 }
1096} 1086}
1097 1087
@@ -1107,7 +1097,7 @@ static void usa67_instat_callback(struct urb *urb)
1107 int old_dcd_state; 1097 int old_dcd_state;
1108 int status = urb->status; 1098 int status = urb->status;
1109 1099
1110 dbg ("%s", __func__); 1100 dbg("%s", __func__);
1111 1101
1112 serial = urb->context; 1102 serial = urb->context;
1113 1103
@@ -1116,7 +1106,8 @@ static void usa67_instat_callback(struct urb *urb)
1116 return; 1106 return;
1117 } 1107 }
1118 1108
1119 if (urb->actual_length != sizeof(struct keyspan_usa67_portStatusMessage)) { 1109 if (urb->actual_length !=
1110 sizeof(struct keyspan_usa67_portStatusMessage)) {
1120 dbg("%s - bad length %d", __func__, urb->actual_length); 1111 dbg("%s - bad length %d", __func__, urb->actual_length);
1121 return; 1112 return;
1122 } 1113 }
@@ -1127,7 +1118,7 @@ static void usa67_instat_callback(struct urb *urb)
1127 1118
1128 /* Check port number from message and retrieve private data */ 1119 /* Check port number from message and retrieve private data */
1129 if (msg->port >= serial->num_ports) { 1120 if (msg->port >= serial->num_ports) {
1130 dbg ("%s - Unexpected port number %d", __func__, msg->port); 1121 dbg("%s - Unexpected port number %d", __func__, msg->port);
1131 return; 1122 return;
1132 } 1123 }
1133 1124
@@ -1139,10 +1130,10 @@ static void usa67_instat_callback(struct urb *urb)
1139 p_priv->cts_state = ((msg->hskia_cts) ? 1 : 0); 1130 p_priv->cts_state = ((msg->hskia_cts) ? 1 : 0);
1140 p_priv->dcd_state = ((msg->gpia_dcd) ? 1 : 0); 1131 p_priv->dcd_state = ((msg->gpia_dcd) ? 1 : 0);
1141 1132
1142 if (port->tty && !C_CLOCAL(port->tty) 1133 if (port->port.tty && !C_CLOCAL(port->port.tty)
1143 && old_dcd_state != p_priv->dcd_state) { 1134 && old_dcd_state != p_priv->dcd_state) {
1144 if (old_dcd_state) 1135 if (old_dcd_state)
1145 tty_hangup(port->tty); 1136 tty_hangup(port->port.tty);
1146 /* else */ 1137 /* else */
1147 /* wake_up_interruptible(&p_priv->open_wait); */ 1138 /* wake_up_interruptible(&p_priv->open_wait); */
1148 } 1139 }
@@ -1161,7 +1152,7 @@ static void usa67_glocont_callback(struct urb *urb)
1161 struct keyspan_port_private *p_priv; 1152 struct keyspan_port_private *p_priv;
1162 int i; 1153 int i;
1163 1154
1164 dbg ("%s", __func__); 1155 dbg("%s", __func__);
1165 1156
1166 serial = urb->context; 1157 serial = urb->context;
1167 for (i = 0; i < serial->num_ports; ++i) { 1158 for (i = 0; i < serial->num_ports; ++i) {
@@ -1169,7 +1160,7 @@ static void usa67_glocont_callback(struct urb *urb)
1169 p_priv = usb_get_serial_port_data(port); 1160 p_priv = usb_get_serial_port_data(port);
1170 1161
1171 if (p_priv->resend_cont) { 1162 if (p_priv->resend_cont) {
1172 dbg ("%s - sending setup", __func__); 1163 dbg("%s - sending setup", __func__);
1173 keyspan_usa67_send_setup(serial, port, 1164 keyspan_usa67_send_setup(serial, port,
1174 p_priv->resend_cont - 1); 1165 p_priv->resend_cont - 1);
1175 break; 1166 break;
@@ -1177,8 +1168,9 @@ static void usa67_glocont_callback(struct urb *urb)
1177 } 1168 }
1178} 1169}
1179 1170
1180static int keyspan_write_room (struct usb_serial_port *port) 1171static int keyspan_write_room(struct tty_struct *tty)
1181{ 1172{
1173 struct usb_serial_port *port = tty->driver_data;
1182 struct keyspan_port_private *p_priv; 1174 struct keyspan_port_private *p_priv;
1183 const struct keyspan_device_details *d_details; 1175 const struct keyspan_device_details *d_details;
1184 int flip; 1176 int flip;
@@ -1191,32 +1183,30 @@ static int keyspan_write_room (struct usb_serial_port *port)
1191 1183
1192 /* FIXME: locking */ 1184 /* FIXME: locking */
1193 if (d_details->msg_format == msg_usa90) 1185 if (d_details->msg_format == msg_usa90)
1194 data_len = 64; 1186 data_len = 64;
1195 else 1187 else
1196 data_len = 63; 1188 data_len = 63;
1197 1189
1198 flip = p_priv->out_flip; 1190 flip = p_priv->out_flip;
1199 1191
1200 /* Check both endpoints to see if any are available. */ 1192 /* Check both endpoints to see if any are available. */
1201 if ((this_urb = p_priv->out_urbs[flip]) != NULL) { 1193 this_urb = p_priv->out_urbs[flip];
1194 if (this_urb != NULL) {
1202 if (this_urb->status != -EINPROGRESS) 1195 if (this_urb->status != -EINPROGRESS)
1203 return (data_len); 1196 return data_len;
1204 flip = (flip + 1) & d_details->outdat_endp_flip; 1197 flip = (flip + 1) & d_details->outdat_endp_flip;
1205 if ((this_urb = p_priv->out_urbs[flip]) != NULL) 1198 this_urb = p_priv->out_urbs[flip];
1199 if (this_urb != NULL) {
1206 if (this_urb->status != -EINPROGRESS) 1200 if (this_urb->status != -EINPROGRESS)
1207 return (data_len); 1201 return data_len;
1202 }
1208 } 1203 }
1209 return 0; 1204 return 0;
1210} 1205}
1211 1206
1212 1207
1213static int keyspan_chars_in_buffer (struct usb_serial_port *port) 1208static int keyspan_open(struct tty_struct *tty,
1214{ 1209 struct usb_serial_port *port, struct file *filp)
1215 return 0;
1216}
1217
1218
1219static int keyspan_open (struct usb_serial_port *port, struct file *filp)
1220{ 1210{
1221 struct keyspan_port_private *p_priv; 1211 struct keyspan_port_private *p_priv;
1222 struct keyspan_serial_private *s_priv; 1212 struct keyspan_serial_private *s_priv;
@@ -1225,7 +1215,7 @@ static int keyspan_open (struct usb_serial_port *port, struct file *filp)
1225 int i, err; 1215 int i, err;
1226 int baud_rate, device_port; 1216 int baud_rate, device_port;
1227 struct urb *urb; 1217 struct urb *urb;
1228 unsigned int cflag; 1218 unsigned int cflag = 0;
1229 1219
1230 s_priv = usb_get_serial_data(serial); 1220 s_priv = usb_get_serial_data(serial);
1231 p_priv = usb_get_serial_port_data(port); 1221 p_priv = usb_get_serial_port_data(port);
@@ -1247,50 +1237,53 @@ static int keyspan_open (struct usb_serial_port *port, struct file *filp)
1247 1237
1248 /* Reset low level data toggle and start reading from endpoints */ 1238 /* Reset low level data toggle and start reading from endpoints */
1249 for (i = 0; i < 2; i++) { 1239 for (i = 0; i < 2; i++) {
1250 if ((urb = p_priv->in_urbs[i]) == NULL) 1240 urb = p_priv->in_urbs[i];
1241 if (urb == NULL)
1251 continue; 1242 continue;
1252 urb->dev = serial->dev; 1243 urb->dev = serial->dev;
1253 1244
1254 /* make sure endpoint data toggle is synchronized with the device */ 1245 /* make sure endpoint data toggle is synchronized
1255 1246 with the device */
1256 usb_clear_halt(urb->dev, urb->pipe); 1247 usb_clear_halt(urb->dev, urb->pipe);
1257 1248 err = usb_submit_urb(urb, GFP_KERNEL);
1258 if ((err = usb_submit_urb(urb, GFP_KERNEL)) != 0) { 1249 if (err != 0)
1259 dbg("%s - submit urb %d failed (%d)", __func__, i, err); 1250 dbg("%s - submit urb %d failed (%d)",
1260 } 1251 __func__, i, err);
1261 } 1252 }
1262 1253
1263 /* Reset low level data toggle on out endpoints */ 1254 /* Reset low level data toggle on out endpoints */
1264 for (i = 0; i < 2; i++) { 1255 for (i = 0; i < 2; i++) {
1265 if ((urb = p_priv->out_urbs[i]) == NULL) 1256 urb = p_priv->out_urbs[i];
1257 if (urb == NULL)
1266 continue; 1258 continue;
1267 urb->dev = serial->dev; 1259 urb->dev = serial->dev;
1268 /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), usb_pipeout(urb->pipe), 0); */ 1260 /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
1261 usb_pipeout(urb->pipe), 0); */
1269 } 1262 }
1270 1263
1271 /* get the terminal config for the setup message now so we don't 1264 /* get the terminal config for the setup message now so we don't
1272 * need to send 2 of them */ 1265 * need to send 2 of them */
1273 1266
1274 cflag = port->tty->termios->c_cflag;
1275 device_port = port->number - port->serial->minor; 1267 device_port = port->number - port->serial->minor;
1276 1268 if (tty) {
1277 /* Baud rate calculation takes baud rate as an integer 1269 cflag = tty->termios->c_cflag;
1278 so other rates can be generated if desired. */ 1270 /* Baud rate calculation takes baud rate as an integer
1279 baud_rate = tty_get_baud_rate(port->tty); 1271 so other rates can be generated if desired. */
1280 /* If no match or invalid, leave as default */ 1272 baud_rate = tty_get_baud_rate(tty);
1281 if (baud_rate >= 0 1273 /* If no match or invalid, leave as default */
1282 && d_details->calculate_baud_rate(baud_rate, d_details->baudclk, 1274 if (baud_rate >= 0
1283 NULL, NULL, NULL, device_port) == KEYSPAN_BAUD_RATE_OK) { 1275 && d_details->calculate_baud_rate(baud_rate, d_details->baudclk,
1284 p_priv->baud = baud_rate; 1276 NULL, NULL, NULL, device_port) == KEYSPAN_BAUD_RATE_OK) {
1277 p_priv->baud = baud_rate;
1278 }
1285 } 1279 }
1286
1287 /* set CTS/RTS handshake etc. */ 1280 /* set CTS/RTS handshake etc. */
1288 p_priv->cflag = cflag; 1281 p_priv->cflag = cflag;
1289 p_priv->flow_control = (cflag & CRTSCTS)? flow_cts: flow_none; 1282 p_priv->flow_control = (cflag & CRTSCTS)? flow_cts: flow_none;
1290 1283
1291 keyspan_send_setup(port, 1); 1284 keyspan_send_setup(port, 1);
1292 //mdelay(100); 1285 /* mdelay(100); */
1293 //keyspan_set_termios(port, NULL); 1286 /* keyspan_set_termios(port, NULL); */
1294 1287
1295 return 0; 1288 return 0;
1296} 1289}
@@ -1301,7 +1294,8 @@ static inline void stop_urb(struct urb *urb)
1301 usb_kill_urb(urb); 1294 usb_kill_urb(urb);
1302} 1295}
1303 1296
1304static void keyspan_close(struct usb_serial_port *port, struct file *filp) 1297static void keyspan_close(struct tty_struct *tty,
1298 struct usb_serial_port *port, struct file *filp)
1305{ 1299{
1306 int i; 1300 int i;
1307 struct usb_serial *serial = port->serial; 1301 struct usb_serial *serial = port->serial;
@@ -1311,15 +1305,15 @@ static void keyspan_close(struct usb_serial_port *port, struct file *filp)
1311 dbg("%s", __func__); 1305 dbg("%s", __func__);
1312 s_priv = usb_get_serial_data(serial); 1306 s_priv = usb_get_serial_data(serial);
1313 p_priv = usb_get_serial_port_data(port); 1307 p_priv = usb_get_serial_port_data(port);
1314 1308
1315 p_priv->rts_state = 0; 1309 p_priv->rts_state = 0;
1316 p_priv->dtr_state = 0; 1310 p_priv->dtr_state = 0;
1317 1311
1318 if (serial->dev) { 1312 if (serial->dev) {
1319 keyspan_send_setup(port, 2); 1313 keyspan_send_setup(port, 2);
1320 /* pilot-xfer seems to work best with this delay */ 1314 /* pilot-xfer seems to work best with this delay */
1321 mdelay(100); 1315 mdelay(100);
1322 // keyspan_set_termios(port, NULL); 1316 /* keyspan_set_termios(port, NULL); */
1323 } 1317 }
1324 1318
1325 /*while (p_priv->outcont_urb->status == -EINPROGRESS) { 1319 /*while (p_priv->outcont_urb->status == -EINPROGRESS) {
@@ -1338,11 +1332,11 @@ static void keyspan_close(struct usb_serial_port *port, struct file *filp)
1338 stop_urb(p_priv->out_urbs[i]); 1332 stop_urb(p_priv->out_urbs[i]);
1339 } 1333 }
1340 } 1334 }
1341 port->tty = NULL; 1335 port->port.tty = NULL;
1342} 1336}
1343 1337
1344 /* download the firmware to a pre-renumeration device */ 1338/* download the firmware to a pre-renumeration device */
1345static int keyspan_fake_startup (struct usb_serial *serial) 1339static int keyspan_fake_startup(struct usb_serial *serial)
1346{ 1340{
1347 int response; 1341 int response;
1348 const struct ihex_binrec *record; 1342 const struct ihex_binrec *record;
@@ -1352,10 +1346,11 @@ static int keyspan_fake_startup (struct usb_serial *serial)
1352 dbg("Keyspan startup version %04x product %04x", 1346 dbg("Keyspan startup version %04x product %04x",
1353 le16_to_cpu(serial->dev->descriptor.bcdDevice), 1347 le16_to_cpu(serial->dev->descriptor.bcdDevice),
1354 le16_to_cpu(serial->dev->descriptor.idProduct)); 1348 le16_to_cpu(serial->dev->descriptor.idProduct));
1355 1349
1356 if ((le16_to_cpu(serial->dev->descriptor.bcdDevice) & 0x8000) != 0x8000) { 1350 if ((le16_to_cpu(serial->dev->descriptor.bcdDevice) & 0x8000)
1351 != 0x8000) {
1357 dbg("Firmware already loaded. Quitting."); 1352 dbg("Firmware already loaded. Quitting.");
1358 return(1); 1353 return 1;
1359 } 1354 }
1360 1355
1361 /* Select firmware image on the basis of idProduct */ 1356 /* Select firmware image on the basis of idProduct */
@@ -1379,11 +1374,11 @@ static int keyspan_fake_startup (struct usb_serial *serial)
1379 case keyspan_usa19_pre_product_id: 1374 case keyspan_usa19_pre_product_id:
1380 fw_name = "keyspan/usa19.fw"; 1375 fw_name = "keyspan/usa19.fw";
1381 break; 1376 break;
1382 1377
1383 case keyspan_usa19qi_pre_product_id: 1378 case keyspan_usa19qi_pre_product_id:
1384 fw_name = "keyspan/usa19qi.fw"; 1379 fw_name = "keyspan/usa19qi.fw";
1385 break; 1380 break;
1386 1381
1387 case keyspan_mpr_pre_product_id: 1382 case keyspan_mpr_pre_product_id:
1388 fw_name = "keyspan/mpr.fw"; 1383 fw_name = "keyspan/mpr.fw";
1389 break; 1384 break;
@@ -1391,15 +1386,15 @@ static int keyspan_fake_startup (struct usb_serial *serial)
1391 case keyspan_usa19qw_pre_product_id: 1386 case keyspan_usa19qw_pre_product_id:
1392 fw_name = "keyspan/usa19qw.fw"; 1387 fw_name = "keyspan/usa19qw.fw";
1393 break; 1388 break;
1394 1389
1395 case keyspan_usa18x_pre_product_id: 1390 case keyspan_usa18x_pre_product_id:
1396 fw_name = "keyspan/usa18x.fw"; 1391 fw_name = "keyspan/usa18x.fw";
1397 break; 1392 break;
1398 1393
1399 case keyspan_usa19w_pre_product_id: 1394 case keyspan_usa19w_pre_product_id:
1400 fw_name = "keyspan/usa19w.fw"; 1395 fw_name = "keyspan/usa19w.fw";
1401 break; 1396 break;
1402 1397
1403 case keyspan_usa49w_pre_product_id: 1398 case keyspan_usa49w_pre_product_id:
1404 fw_name = "keyspan/usa49w.fw"; 1399 fw_name = "keyspan/usa49w.fw";
1405 break; 1400 break;
@@ -1431,8 +1426,7 @@ static int keyspan_fake_startup (struct usb_serial *serial)
1431 (unsigned char *)record->data, 1426 (unsigned char *)record->data,
1432 be16_to_cpu(record->len), 0xa0); 1427 be16_to_cpu(record->len), 0xa0);
1433 if (response < 0) { 1428 if (response < 0) {
1434 dev_err(&serial->dev->dev, "ezusb_writememory failed for Keyspan" 1429 dev_err(&serial->dev->dev, "ezusb_writememory failed for Keyspan firmware (%d %04X %p %d)\n",
1435 "firmware (%d %04X %p %d)\n",
1436 response, be32_to_cpu(record->addr), 1430 response, be32_to_cpu(record->addr),
1437 record->data, be16_to_cpu(record->len)); 1431 record->data, be16_to_cpu(record->len));
1438 break; 1432 break;
@@ -1445,7 +1439,7 @@ static int keyspan_fake_startup (struct usb_serial *serial)
1445 response = ezusb_set_reset(serial, 0); 1439 response = ezusb_set_reset(serial, 0);
1446 1440
1447 /* we don't want this device to have a driver assigned to it. */ 1441 /* we don't want this device to have a driver assigned to it. */
1448 return (1); 1442 return 1;
1449} 1443}
1450 1444
1451/* Helper functions used by keyspan_setup_urbs */ 1445/* Helper functions used by keyspan_setup_urbs */
@@ -1467,7 +1461,7 @@ static struct usb_endpoint_descriptor const *find_ep(struct usb_serial const *se
1467 return NULL; 1461 return NULL;
1468} 1462}
1469 1463
1470static struct urb *keyspan_setup_urb (struct usb_serial *serial, int endpoint, 1464static struct urb *keyspan_setup_urb(struct usb_serial *serial, int endpoint,
1471 int dir, void *ctx, char *buf, int len, 1465 int dir, void *ctx, char *buf, int len,
1472 void (*callback)(struct urb *)) 1466 void (*callback)(struct urb *))
1473{ 1467{
@@ -1478,10 +1472,10 @@ static struct urb *keyspan_setup_urb (struct usb_serial *serial, int endpoint,
1478 if (endpoint == -1) 1472 if (endpoint == -1)
1479 return NULL; /* endpoint not needed */ 1473 return NULL; /* endpoint not needed */
1480 1474
1481 dbg ("%s - alloc for endpoint %d.", __func__, endpoint); 1475 dbg("%s - alloc for endpoint %d.", __func__, endpoint);
1482 urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */ 1476 urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */
1483 if (urb == NULL) { 1477 if (urb == NULL) {
1484 dbg ("%s - alloc for endpoint %d failed.", __func__, endpoint); 1478 dbg("%s - alloc for endpoint %d failed.", __func__, endpoint);
1485 return NULL; 1479 return NULL;
1486 } 1480 }
1487 1481
@@ -1554,7 +1548,7 @@ static struct callbacks {
1554 }, { 1548 }, {
1555 /* msg_usa90 callbacks */ 1549 /* msg_usa90 callbacks */
1556 .instat_callback = usa90_instat_callback, 1550 .instat_callback = usa90_instat_callback,
1557 .glocont_callback = usa28_glocont_callback, 1551 .glocont_callback = usa28_glocont_callback,
1558 .indat_callback = usa90_indat_callback, 1552 .indat_callback = usa90_indat_callback,
1559 .outdat_callback = usa2x_outdat_callback, 1553 .outdat_callback = usa2x_outdat_callback,
1560 .inack_callback = usa28_inack_callback, 1554 .inack_callback = usa28_inack_callback,
@@ -1582,16 +1576,16 @@ static void keyspan_setup_urbs(struct usb_serial *serial)
1582 struct callbacks *cback; 1576 struct callbacks *cback;
1583 int endp; 1577 int endp;
1584 1578
1585 dbg ("%s", __func__); 1579 dbg("%s", __func__);
1586 1580
1587 s_priv = usb_get_serial_data(serial); 1581 s_priv = usb_get_serial_data(serial);
1588 d_details = s_priv->device_details; 1582 d_details = s_priv->device_details;
1589 1583
1590 /* Setup values for the various callback routines */ 1584 /* Setup values for the various callback routines */
1591 cback = &keyspan_callbacks[d_details->msg_format]; 1585 cback = &keyspan_callbacks[d_details->msg_format];
1592 1586
1593 /* Allocate and set up urbs for each one that is in use, 1587 /* Allocate and set up urbs for each one that is in use,
1594 starting with instat endpoints */ 1588 starting with instat endpoints */
1595 s_priv->instat_urb = keyspan_setup_urb 1589 s_priv->instat_urb = keyspan_setup_urb
1596 (serial, d_details->instat_endpoint, USB_DIR_IN, 1590 (serial, d_details->instat_endpoint, USB_DIR_IN,
1597 serial, s_priv->instat_buf, INSTAT_BUFLEN, 1591 serial, s_priv->instat_buf, INSTAT_BUFLEN,
@@ -1607,8 +1601,8 @@ static void keyspan_setup_urbs(struct usb_serial *serial)
1607 serial, s_priv->glocont_buf, GLOCONT_BUFLEN, 1601 serial, s_priv->glocont_buf, GLOCONT_BUFLEN,
1608 cback->glocont_callback); 1602 cback->glocont_callback);
1609 1603
1610 /* Setup endpoints for each port specific thing */ 1604 /* Setup endpoints for each port specific thing */
1611 for (i = 0; i < d_details->num_ports; i ++) { 1605 for (i = 0; i < d_details->num_ports; i++) {
1612 port = serial->port[i]; 1606 port = serial->port[i];
1613 p_priv = usb_get_serial_port_data(port); 1607 p_priv = usb_get_serial_port_data(port);
1614 1608
@@ -1644,8 +1638,7 @@ static void keyspan_setup_urbs(struct usb_serial *serial)
1644 (serial, d_details->outcont_endpoints[i], USB_DIR_OUT, 1638 (serial, d_details->outcont_endpoints[i], USB_DIR_OUT,
1645 port, p_priv->outcont_buffer, 64, 1639 port, p_priv->outcont_buffer, 64,
1646 cback->outcont_callback); 1640 cback->outcont_callback);
1647 } 1641 }
1648
1649} 1642}
1650 1643
1651/* usa19 function doesn't require prescaler */ 1644/* usa19 function doesn't require prescaler */
@@ -1653,46 +1646,39 @@ static int keyspan_usa19_calc_baud(u32 baud_rate, u32 baudclk, u8 *rate_hi,
1653 u8 *rate_low, u8 *prescaler, int portnum) 1646 u8 *rate_low, u8 *prescaler, int portnum)
1654{ 1647{
1655 u32 b16, /* baud rate times 16 (actual rate used internally) */ 1648 u32 b16, /* baud rate times 16 (actual rate used internally) */
1656 div, /* divisor */ 1649 div, /* divisor */
1657 cnt; /* inverse of divisor (programmed into 8051) */ 1650 cnt; /* inverse of divisor (programmed into 8051) */
1658
1659 dbg ("%s - %d.", __func__, baud_rate);
1660
1661 /* prevent divide by zero... */
1662 if( (b16 = (baud_rate * 16L)) == 0) {
1663 return (KEYSPAN_INVALID_BAUD_RATE);
1664 }
1665 1651
1666 /* Any "standard" rate over 57k6 is marginal on the USA-19 1652 dbg("%s - %d.", __func__, baud_rate);
1667 as we run out of divisor resolution. */ 1653
1668 if (baud_rate > 57600) { 1654 /* prevent divide by zero... */
1669 return (KEYSPAN_INVALID_BAUD_RATE); 1655 b16 = baud_rate * 16L;
1670 } 1656 if (b16 == 0)
1671 1657 return KEYSPAN_INVALID_BAUD_RATE;
1672 /* calculate the divisor and the counter (its inverse) */ 1658 /* Any "standard" rate over 57k6 is marginal on the USA-19
1673 if( (div = (baudclk / b16)) == 0) { 1659 as we run out of divisor resolution. */
1674 return (KEYSPAN_INVALID_BAUD_RATE); 1660 if (baud_rate > 57600)
1675 } 1661 return KEYSPAN_INVALID_BAUD_RATE;
1676 else { 1662
1663 /* calculate the divisor and the counter (its inverse) */
1664 div = baudclk / b16;
1665 if (div == 0)
1666 return KEYSPAN_INVALID_BAUD_RATE;
1667 else
1677 cnt = 0 - div; 1668 cnt = 0 - div;
1678 }
1679 1669
1680 if(div > 0xffff) { 1670 if (div > 0xffff)
1681 return (KEYSPAN_INVALID_BAUD_RATE); 1671 return KEYSPAN_INVALID_BAUD_RATE;
1682 }
1683 1672
1684 /* return the counter values if non-null */ 1673 /* return the counter values if non-null */
1685 if (rate_low) { 1674 if (rate_low)
1686 *rate_low = (u8) (cnt & 0xff); 1675 *rate_low = (u8) (cnt & 0xff);
1687 } 1676 if (rate_hi)
1688 if (rate_hi) {
1689 *rate_hi = (u8) ((cnt >> 8) & 0xff); 1677 *rate_hi = (u8) ((cnt >> 8) & 0xff);
1690 } 1678 if (rate_low && rate_hi)
1691 if (rate_low && rate_hi) { 1679 dbg("%s - %d %02x %02x.",
1692 dbg ("%s - %d %02x %02x.", __func__, baud_rate, *rate_hi, *rate_low); 1680 __func__, baud_rate, *rate_hi, *rate_low);
1693 } 1681 return KEYSPAN_BAUD_RATE_OK;
1694
1695 return (KEYSPAN_BAUD_RATE_OK);
1696} 1682}
1697 1683
1698/* usa19hs function doesn't require prescaler */ 1684/* usa19hs function doesn't require prescaler */
@@ -1700,34 +1686,35 @@ static int keyspan_usa19hs_calc_baud(u32 baud_rate, u32 baudclk, u8 *rate_hi,
1700 u8 *rate_low, u8 *prescaler, int portnum) 1686 u8 *rate_low, u8 *prescaler, int portnum)
1701{ 1687{
1702 u32 b16, /* baud rate times 16 (actual rate used internally) */ 1688 u32 b16, /* baud rate times 16 (actual rate used internally) */
1703 div; /* divisor */ 1689 div; /* divisor */
1704
1705 dbg ("%s - %d.", __func__, baud_rate);
1706 1690
1707 /* prevent divide by zero... */ 1691 dbg("%s - %d.", __func__, baud_rate);
1708 if( (b16 = (baud_rate * 16L)) == 0)
1709 return (KEYSPAN_INVALID_BAUD_RATE);
1710
1711 1692
1693 /* prevent divide by zero... */
1694 b16 = baud_rate * 16L;
1695 if (b16 == 0)
1696 return KEYSPAN_INVALID_BAUD_RATE;
1712 1697
1713 /* calculate the divisor */ 1698 /* calculate the divisor */
1714 if( (div = (baudclk / b16)) == 0) 1699 div = baudclk / b16;
1715 return (KEYSPAN_INVALID_BAUD_RATE); 1700 if (div == 0)
1701 return KEYSPAN_INVALID_BAUD_RATE;
1716 1702
1717 if(div > 0xffff) 1703 if (div > 0xffff)
1718 return (KEYSPAN_INVALID_BAUD_RATE); 1704 return KEYSPAN_INVALID_BAUD_RATE;
1719 1705
1720 /* return the counter values if non-null */ 1706 /* return the counter values if non-null */
1721 if (rate_low) 1707 if (rate_low)
1722 *rate_low = (u8) (div & 0xff); 1708 *rate_low = (u8) (div & 0xff);
1723 1709
1724 if (rate_hi) 1710 if (rate_hi)
1725 *rate_hi = (u8) ((div >> 8) & 0xff); 1711 *rate_hi = (u8) ((div >> 8) & 0xff);
1726 1712
1727 if (rate_low && rate_hi) 1713 if (rate_low && rate_hi)
1728 dbg ("%s - %d %02x %02x.", __func__, baud_rate, *rate_hi, *rate_low); 1714 dbg("%s - %d %02x %02x.",
1729 1715 __func__, baud_rate, *rate_hi, *rate_low);
1730 return (KEYSPAN_BAUD_RATE_OK); 1716
1717 return KEYSPAN_BAUD_RATE_OK;
1731} 1718}
1732 1719
1733static int keyspan_usa19w_calc_baud(u32 baud_rate, u32 baudclk, u8 *rate_hi, 1720static int keyspan_usa19w_calc_baud(u32 baud_rate, u32 baudclk, u8 *rate_hi,
@@ -1735,64 +1722,61 @@ static int keyspan_usa19w_calc_baud(u32 baud_rate, u32 baudclk, u8 *rate_hi,
1735{ 1722{
1736 u32 b16, /* baud rate times 16 (actual rate used internally) */ 1723 u32 b16, /* baud rate times 16 (actual rate used internally) */
1737 clk, /* clock with 13/8 prescaler */ 1724 clk, /* clock with 13/8 prescaler */
1738 div, /* divisor using 13/8 prescaler */ 1725 div, /* divisor using 13/8 prescaler */
1739 res, /* resulting baud rate using 13/8 prescaler */ 1726 res, /* resulting baud rate using 13/8 prescaler */
1740 diff, /* error using 13/8 prescaler */ 1727 diff, /* error using 13/8 prescaler */
1741 smallest_diff; 1728 smallest_diff;
1742 u8 best_prescaler; 1729 u8 best_prescaler;
1743 int i; 1730 int i;
1744 1731
1745 dbg ("%s - %d.", __func__, baud_rate); 1732 dbg("%s - %d.", __func__, baud_rate);
1746 1733
1747 /* prevent divide by zero */ 1734 /* prevent divide by zero */
1748 if( (b16 = baud_rate * 16L) == 0) { 1735 b16 = baud_rate * 16L;
1749 return (KEYSPAN_INVALID_BAUD_RATE); 1736 if (b16 == 0)
1750 } 1737 return KEYSPAN_INVALID_BAUD_RATE;
1751 1738
1752 /* Calculate prescaler by trying them all and looking 1739 /* Calculate prescaler by trying them all and looking
1753 for best fit */ 1740 for best fit */
1754 1741
1755 /* start with largest possible difference */ 1742 /* start with largest possible difference */
1756 smallest_diff = 0xffffffff; 1743 smallest_diff = 0xffffffff;
1757 1744
1758 /* 0 is an invalid prescaler, used as a flag */ 1745 /* 0 is an invalid prescaler, used as a flag */
1759 best_prescaler = 0; 1746 best_prescaler = 0;
1760 1747
1761 for(i = 8; i <= 0xff; ++i) { 1748 for (i = 8; i <= 0xff; ++i) {
1762 clk = (baudclk * 8) / (u32) i; 1749 clk = (baudclk * 8) / (u32) i;
1763 1750
1764 if( (div = clk / b16) == 0) { 1751 div = clk / b16;
1752 if (div == 0)
1765 continue; 1753 continue;
1766 }
1767 1754
1768 res = clk / div; 1755 res = clk / div;
1769 diff= (res > b16) ? (res-b16) : (b16-res); 1756 diff = (res > b16) ? (res-b16) : (b16-res);
1770 1757
1771 if(diff < smallest_diff) { 1758 if (diff < smallest_diff) {
1772 best_prescaler = i; 1759 best_prescaler = i;
1773 smallest_diff = diff; 1760 smallest_diff = diff;
1774 } 1761 }
1775 } 1762 }
1776 1763
1777 if(best_prescaler == 0) { 1764 if (best_prescaler == 0)
1778 return (KEYSPAN_INVALID_BAUD_RATE); 1765 return KEYSPAN_INVALID_BAUD_RATE;
1779 }
1780 1766
1781 clk = (baudclk * 8) / (u32) best_prescaler; 1767 clk = (baudclk * 8) / (u32) best_prescaler;
1782 div = clk / b16; 1768 div = clk / b16;
1783 1769
1784 /* return the divisor and prescaler if non-null */ 1770 /* return the divisor and prescaler if non-null */
1785 if (rate_low) { 1771 if (rate_low)
1786 *rate_low = (u8) (div & 0xff); 1772 *rate_low = (u8) (div & 0xff);
1787 } 1773 if (rate_hi)
1788 if (rate_hi) {
1789 *rate_hi = (u8) ((div >> 8) & 0xff); 1774 *rate_hi = (u8) ((div >> 8) & 0xff);
1790 }
1791 if (prescaler) { 1775 if (prescaler) {
1792 *prescaler = best_prescaler; 1776 *prescaler = best_prescaler;
1793 /* dbg("%s - %d %d", __func__, *prescaler, div); */ 1777 /* dbg("%s - %d %d", __func__, *prescaler, div); */
1794 } 1778 }
1795 return (KEYSPAN_BAUD_RATE_OK); 1779 return KEYSPAN_BAUD_RATE_OK;
1796} 1780}
1797 1781
1798 /* USA-28 supports different maximum baud rates on each port */ 1782 /* USA-28 supports different maximum baud rates on each port */
@@ -1800,57 +1784,51 @@ static int keyspan_usa28_calc_baud(u32 baud_rate, u32 baudclk, u8 *rate_hi,
1800 u8 *rate_low, u8 *prescaler, int portnum) 1784 u8 *rate_low, u8 *prescaler, int portnum)
1801{ 1785{
1802 u32 b16, /* baud rate times 16 (actual rate used internally) */ 1786 u32 b16, /* baud rate times 16 (actual rate used internally) */
1803 div, /* divisor */ 1787 div, /* divisor */
1804 cnt; /* inverse of divisor (programmed into 8051) */ 1788 cnt; /* inverse of divisor (programmed into 8051) */
1805 1789
1806 dbg ("%s - %d.", __func__, baud_rate); 1790 dbg("%s - %d.", __func__, baud_rate);
1807 1791
1808 /* prevent divide by zero */ 1792 /* prevent divide by zero */
1809 if ((b16 = baud_rate * 16L) == 0) 1793 b16 = baud_rate * 16L;
1810 return (KEYSPAN_INVALID_BAUD_RATE); 1794 if (b16 == 0)
1811 1795 return KEYSPAN_INVALID_BAUD_RATE;
1812 /* calculate the divisor and the counter (its inverse) */ 1796
1813 if ((div = (KEYSPAN_USA28_BAUDCLK / b16)) == 0) { 1797 /* calculate the divisor and the counter (its inverse) */
1814 return (KEYSPAN_INVALID_BAUD_RATE); 1798 div = KEYSPAN_USA28_BAUDCLK / b16;
1815 } 1799 if (div == 0)
1816 else { 1800 return KEYSPAN_INVALID_BAUD_RATE;
1801 else
1817 cnt = 0 - div; 1802 cnt = 0 - div;
1818 }
1819 1803
1820 /* check for out of range, based on portnum, 1804 /* check for out of range, based on portnum,
1821 and return result */ 1805 and return result */
1822 if(portnum == 0) { 1806 if (portnum == 0) {
1823 if(div > 0xffff) 1807 if (div > 0xffff)
1824 return (KEYSPAN_INVALID_BAUD_RATE); 1808 return KEYSPAN_INVALID_BAUD_RATE;
1825 } 1809 } else {
1826 else { 1810 if (portnum == 1) {
1827 if(portnum == 1) { 1811 if (div > 0xff)
1828 if(div > 0xff) { 1812 return KEYSPAN_INVALID_BAUD_RATE;
1829 return (KEYSPAN_INVALID_BAUD_RATE); 1813 } else
1830 } 1814 return KEYSPAN_INVALID_BAUD_RATE;
1831 }
1832 else {
1833 return (KEYSPAN_INVALID_BAUD_RATE);
1834 }
1835 } 1815 }
1836 1816
1837 /* return the counter values if not NULL 1817 /* return the counter values if not NULL
1838 (port 1 will ignore retHi) */ 1818 (port 1 will ignore retHi) */
1839 if (rate_low) { 1819 if (rate_low)
1840 *rate_low = (u8) (cnt & 0xff); 1820 *rate_low = (u8) (cnt & 0xff);
1841 } 1821 if (rate_hi)
1842 if (rate_hi) {
1843 *rate_hi = (u8) ((cnt >> 8) & 0xff); 1822 *rate_hi = (u8) ((cnt >> 8) & 0xff);
1844 } 1823 dbg("%s - %d OK.", __func__, baud_rate);
1845 dbg ("%s - %d OK.", __func__, baud_rate); 1824 return KEYSPAN_BAUD_RATE_OK;
1846 return (KEYSPAN_BAUD_RATE_OK);
1847} 1825}
1848 1826
1849static int keyspan_usa26_send_setup(struct usb_serial *serial, 1827static int keyspan_usa26_send_setup(struct usb_serial *serial,
1850 struct usb_serial_port *port, 1828 struct usb_serial_port *port,
1851 int reset_port) 1829 int reset_port)
1852{ 1830{
1853 struct keyspan_usa26_portControlMessage msg; 1831 struct keyspan_usa26_portControlMessage msg;
1854 struct keyspan_serial_private *s_priv; 1832 struct keyspan_serial_private *s_priv;
1855 struct keyspan_port_private *p_priv; 1833 struct keyspan_port_private *p_priv;
1856 const struct keyspan_device_details *d_details; 1834 const struct keyspan_device_details *d_details;
@@ -1858,7 +1836,7 @@ static int keyspan_usa26_send_setup(struct usb_serial *serial,
1858 struct urb *this_urb; 1836 struct urb *this_urb;
1859 int device_port, err; 1837 int device_port, err;
1860 1838
1861 dbg ("%s reset=%d", __func__, reset_port); 1839 dbg("%s reset=%d", __func__, reset_port);
1862 1840
1863 s_priv = usb_get_serial_data(serial); 1841 s_priv = usb_get_serial_data(serial);
1864 p_priv = usb_get_serial_port_data(port); 1842 p_priv = usb_get_serial_port_data(port);
@@ -1881,22 +1859,22 @@ static int keyspan_usa26_send_setup(struct usb_serial *serial,
1881 if ((reset_port + 1) > p_priv->resend_cont) 1859 if ((reset_port + 1) > p_priv->resend_cont)
1882 p_priv->resend_cont = reset_port + 1; 1860 p_priv->resend_cont = reset_port + 1;
1883 if (this_urb->status == -EINPROGRESS) { 1861 if (this_urb->status == -EINPROGRESS) {
1884 /* dbg ("%s - already writing", __func__); */ 1862 /* dbg("%s - already writing", __func__); */
1885 mdelay(5); 1863 mdelay(5);
1886 return(-1); 1864 return -1;
1887 } 1865 }
1888 1866
1889 memset(&msg, 0, sizeof (struct keyspan_usa26_portControlMessage)); 1867 memset(&msg, 0, sizeof(struct keyspan_usa26_portControlMessage));
1890 1868
1891 /* Only set baud rate if it's changed */ 1869 /* Only set baud rate if it's changed */
1892 if (p_priv->old_baud != p_priv->baud) { 1870 if (p_priv->old_baud != p_priv->baud) {
1893 p_priv->old_baud = p_priv->baud; 1871 p_priv->old_baud = p_priv->baud;
1894 msg.setClocking = 0xff; 1872 msg.setClocking = 0xff;
1895 if (d_details->calculate_baud_rate 1873 if (d_details->calculate_baud_rate
1896 (p_priv->baud, d_details->baudclk, &msg.baudHi, 1874 (p_priv->baud, d_details->baudclk, &msg.baudHi,
1897 &msg.baudLo, &msg.prescaler, device_port) == KEYSPAN_INVALID_BAUD_RATE ) { 1875 &msg.baudLo, &msg.prescaler, device_port) == KEYSPAN_INVALID_BAUD_RATE) {
1898 dbg("%s - Invalid baud rate %d requested, using 9600.", __func__, 1876 dbg("%s - Invalid baud rate %d requested, using 9600.",
1899 p_priv->baud); 1877 __func__, p_priv->baud);
1900 msg.baudLo = 0; 1878 msg.baudLo = 0;
1901 msg.baudHi = 125; /* Values for 9600 baud */ 1879 msg.baudHi = 125; /* Values for 9600 baud */
1902 msg.prescaler = 10; 1880 msg.prescaler = 10;
@@ -1922,7 +1900,7 @@ static int keyspan_usa26_send_setup(struct usb_serial *serial,
1922 if (p_priv->cflag & PARENB) { 1900 if (p_priv->cflag & PARENB) {
1923 /* note USA_PARITY_NONE == 0 */ 1901 /* note USA_PARITY_NONE == 0 */
1924 msg.lcr |= (p_priv->cflag & PARODD)? 1902 msg.lcr |= (p_priv->cflag & PARODD)?
1925 USA_PARITY_ODD: USA_PARITY_EVEN; 1903 USA_PARITY_ODD : USA_PARITY_EVEN;
1926 } 1904 }
1927 msg.setLcr = 0xff; 1905 msg.setLcr = 0xff;
1928 1906
@@ -1963,7 +1941,7 @@ static int keyspan_usa26_send_setup(struct usb_serial *serial,
1963 1941
1964 /* Sending intermediate configs */ 1942 /* Sending intermediate configs */
1965 else { 1943 else {
1966 msg._txOn = (! p_priv->break_on); 1944 msg._txOn = (!p_priv->break_on);
1967 msg._txOff = 0; 1945 msg._txOff = 0;
1968 msg.txFlush = 0; 1946 msg.txFlush = 0;
1969 msg.txBreak = (p_priv->break_on); 1947 msg.txBreak = (p_priv->break_on);
@@ -1975,23 +1953,23 @@ static int keyspan_usa26_send_setup(struct usb_serial *serial,
1975 msg.resetDataToggle = 0x0; 1953 msg.resetDataToggle = 0x0;
1976 } 1954 }
1977 1955
1978 /* Do handshaking outputs */ 1956 /* Do handshaking outputs */
1979 msg.setTxTriState_setRts = 0xff; 1957 msg.setTxTriState_setRts = 0xff;
1980 msg.txTriState_rts = p_priv->rts_state; 1958 msg.txTriState_rts = p_priv->rts_state;
1981 1959
1982 msg.setHskoa_setDtr = 0xff; 1960 msg.setHskoa_setDtr = 0xff;
1983 msg.hskoa_dtr = p_priv->dtr_state; 1961 msg.hskoa_dtr = p_priv->dtr_state;
1984 1962
1985 p_priv->resend_cont = 0; 1963 p_priv->resend_cont = 0;
1986 memcpy (this_urb->transfer_buffer, &msg, sizeof(msg)); 1964 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
1987 1965
1988 /* send the data out the device on control endpoint */ 1966 /* send the data out the device on control endpoint */
1989 this_urb->transfer_buffer_length = sizeof(msg); 1967 this_urb->transfer_buffer_length = sizeof(msg);
1990 1968
1991 this_urb->dev = serial->dev; 1969 this_urb->dev = serial->dev;
1992 if ((err = usb_submit_urb(this_urb, GFP_ATOMIC)) != 0) { 1970 err = usb_submit_urb(this_urb, GFP_ATOMIC);
1971 if (err != 0)
1993 dbg("%s - usb_submit_urb(setup) failed (%d)", __func__, err); 1972 dbg("%s - usb_submit_urb(setup) failed (%d)", __func__, err);
1994 }
1995#if 0 1973#if 0
1996 else { 1974 else {
1997 dbg("%s - usb_submit_urb(%d) OK %d bytes (end %d)", __func__ 1975 dbg("%s - usb_submit_urb(%d) OK %d bytes (end %d)", __func__
@@ -2007,14 +1985,14 @@ static int keyspan_usa28_send_setup(struct usb_serial *serial,
2007 struct usb_serial_port *port, 1985 struct usb_serial_port *port,
2008 int reset_port) 1986 int reset_port)
2009{ 1987{
2010 struct keyspan_usa28_portControlMessage msg; 1988 struct keyspan_usa28_portControlMessage msg;
2011 struct keyspan_serial_private *s_priv; 1989 struct keyspan_serial_private *s_priv;
2012 struct keyspan_port_private *p_priv; 1990 struct keyspan_port_private *p_priv;
2013 const struct keyspan_device_details *d_details; 1991 const struct keyspan_device_details *d_details;
2014 struct urb *this_urb; 1992 struct urb *this_urb;
2015 int device_port, err; 1993 int device_port, err;
2016 1994
2017 dbg ("%s", __func__); 1995 dbg("%s", __func__);
2018 1996
2019 s_priv = usb_get_serial_data(serial); 1997 s_priv = usb_get_serial_data(serial);
2020 p_priv = usb_get_serial_port_data(port); 1998 p_priv = usb_get_serial_port_data(port);
@@ -2022,7 +2000,8 @@ static int keyspan_usa28_send_setup(struct usb_serial *serial,
2022 device_port = port->number - port->serial->minor; 2000 device_port = port->number - port->serial->minor;
2023 2001
2024 /* only do something if we have a bulk out endpoint */ 2002 /* only do something if we have a bulk out endpoint */
2025 if ((this_urb = p_priv->outcont_urb) == NULL) { 2003 this_urb = p_priv->outcont_urb;
2004 if (this_urb == NULL) {
2026 dbg("%s - oops no urb.", __func__); 2005 dbg("%s - oops no urb.", __func__);
2027 return -1; 2006 return -1;
2028 } 2007 }
@@ -2032,17 +2011,18 @@ static int keyspan_usa28_send_setup(struct usb_serial *serial,
2032 if ((reset_port + 1) > p_priv->resend_cont) 2011 if ((reset_port + 1) > p_priv->resend_cont)
2033 p_priv->resend_cont = reset_port + 1; 2012 p_priv->resend_cont = reset_port + 1;
2034 if (this_urb->status == -EINPROGRESS) { 2013 if (this_urb->status == -EINPROGRESS) {
2035 dbg ("%s already writing", __func__); 2014 dbg("%s already writing", __func__);
2036 mdelay(5); 2015 mdelay(5);
2037 return(-1); 2016 return -1;
2038 } 2017 }
2039 2018
2040 memset(&msg, 0, sizeof (struct keyspan_usa28_portControlMessage)); 2019 memset(&msg, 0, sizeof(struct keyspan_usa28_portControlMessage));
2041 2020
2042 msg.setBaudRate = 1; 2021 msg.setBaudRate = 1;
2043 if (d_details->calculate_baud_rate(p_priv->baud, d_details->baudclk, 2022 if (d_details->calculate_baud_rate(p_priv->baud, d_details->baudclk,
2044 &msg.baudHi, &msg.baudLo, NULL, device_port) == KEYSPAN_INVALID_BAUD_RATE ) { 2023 &msg.baudHi, &msg.baudLo, NULL, device_port) == KEYSPAN_INVALID_BAUD_RATE) {
2045 dbg("%s - Invalid baud rate requested %d.", __func__, p_priv->baud); 2024 dbg("%s - Invalid baud rate requested %d.",
2025 __func__, p_priv->baud);
2046 msg.baudLo = 0xff; 2026 msg.baudLo = 0xff;
2047 msg.baudHi = 0xb2; /* Values for 9600 baud */ 2027 msg.baudHi = 0xb2; /* Values for 9600 baud */
2048 } 2028 }
@@ -2053,7 +2033,7 @@ static int keyspan_usa28_send_setup(struct usb_serial *serial,
2053 msg.ctsFlowControl = (p_priv->flow_control == flow_cts); 2033 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
2054 msg.xonFlowControl = 0; 2034 msg.xonFlowControl = 0;
2055 2035
2056 /* Do handshaking outputs, DTR is inverted relative to RTS */ 2036 /* Do handshaking outputs, DTR is inverted relative to RTS */
2057 msg.rts = p_priv->rts_state; 2037 msg.rts = p_priv->rts_state;
2058 msg.dtr = p_priv->dtr_state; 2038 msg.dtr = p_priv->dtr_state;
2059 2039
@@ -2095,7 +2075,7 @@ static int keyspan_usa28_send_setup(struct usb_serial *serial,
2095 } 2075 }
2096 /* Sending intermediate configs */ 2076 /* Sending intermediate configs */
2097 else { 2077 else {
2098 msg._txOn = (! p_priv->break_on); 2078 msg._txOn = (!p_priv->break_on);
2099 msg._txOff = 0; 2079 msg._txOff = 0;
2100 msg.txFlush = 0; 2080 msg.txFlush = 0;
2101 msg.txForceXoff = 0; 2081 msg.txForceXoff = 0;
@@ -2109,15 +2089,15 @@ static int keyspan_usa28_send_setup(struct usb_serial *serial,
2109 } 2089 }
2110 2090
2111 p_priv->resend_cont = 0; 2091 p_priv->resend_cont = 0;
2112 memcpy (this_urb->transfer_buffer, &msg, sizeof(msg)); 2092 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
2113 2093
2114 /* send the data out the device on control endpoint */ 2094 /* send the data out the device on control endpoint */
2115 this_urb->transfer_buffer_length = sizeof(msg); 2095 this_urb->transfer_buffer_length = sizeof(msg);
2116 2096
2117 this_urb->dev = serial->dev; 2097 this_urb->dev = serial->dev;
2118 if ((err = usb_submit_urb(this_urb, GFP_ATOMIC)) != 0) { 2098 err = usb_submit_urb(this_urb, GFP_ATOMIC);
2099 if (err != 0)
2119 dbg("%s - usb_submit_urb(setup) failed", __func__); 2100 dbg("%s - usb_submit_urb(setup) failed", __func__);
2120 }
2121#if 0 2101#if 0
2122 else { 2102 else {
2123 dbg("%s - usb_submit_urb(setup) OK %d bytes", __func__, 2103 dbg("%s - usb_submit_urb(setup) OK %d bytes", __func__,
@@ -2140,7 +2120,7 @@ static int keyspan_usa49_send_setup(struct usb_serial *serial,
2140 struct urb *this_urb; 2120 struct urb *this_urb;
2141 int err, device_port; 2121 int err, device_port;
2142 2122
2143 dbg ("%s", __func__); 2123 dbg("%s", __func__);
2144 2124
2145 s_priv = usb_get_serial_data(serial); 2125 s_priv = usb_get_serial_data(serial);
2146 p_priv = usb_get_serial_port_data(port); 2126 p_priv = usb_get_serial_port_data(port);
@@ -2151,7 +2131,9 @@ static int keyspan_usa49_send_setup(struct usb_serial *serial,
2151 /* Work out which port within the device is being setup */ 2131 /* Work out which port within the device is being setup */
2152 device_port = port->number - port->serial->minor; 2132 device_port = port->number - port->serial->minor;
2153 2133
2154 dbg("%s - endpoint %d port %d (%d)",__func__, usb_pipeendpoint(this_urb->pipe), port->number, device_port); 2134 dbg("%s - endpoint %d port %d (%d)",
2135 __func__, usb_pipeendpoint(this_urb->pipe),
2136 port->number, device_port);
2155 2137
2156 /* Make sure we have an urb then send the message */ 2138 /* Make sure we have an urb then send the message */
2157 if (this_urb == NULL) { 2139 if (this_urb == NULL) {
@@ -2165,30 +2147,30 @@ static int keyspan_usa49_send_setup(struct usb_serial *serial,
2165 p_priv->resend_cont = reset_port + 1; 2147 p_priv->resend_cont = reset_port + 1;
2166 2148
2167 if (this_urb->status == -EINPROGRESS) { 2149 if (this_urb->status == -EINPROGRESS) {
2168 /* dbg ("%s - already writing", __func__); */ 2150 /* dbg("%s - already writing", __func__); */
2169 mdelay(5); 2151 mdelay(5);
2170 return(-1); 2152 return -1;
2171 } 2153 }
2172 2154
2173 memset(&msg, 0, sizeof (struct keyspan_usa49_portControlMessage)); 2155 memset(&msg, 0, sizeof(struct keyspan_usa49_portControlMessage));
2174 2156
2175 /*msg.portNumber = port->number;*/ 2157 /*msg.portNumber = port->number;*/
2176 msg.portNumber = device_port; 2158 msg.portNumber = device_port;
2177 2159
2178 /* Only set baud rate if it's changed */ 2160 /* Only set baud rate if it's changed */
2179 if (p_priv->old_baud != p_priv->baud) { 2161 if (p_priv->old_baud != p_priv->baud) {
2180 p_priv->old_baud = p_priv->baud; 2162 p_priv->old_baud = p_priv->baud;
2181 msg.setClocking = 0xff; 2163 msg.setClocking = 0xff;
2182 if (d_details->calculate_baud_rate 2164 if (d_details->calculate_baud_rate
2183 (p_priv->baud, d_details->baudclk, &msg.baudHi, 2165 (p_priv->baud, d_details->baudclk, &msg.baudHi,
2184 &msg.baudLo, &msg.prescaler, device_port) == KEYSPAN_INVALID_BAUD_RATE ) { 2166 &msg.baudLo, &msg.prescaler, device_port) == KEYSPAN_INVALID_BAUD_RATE) {
2185 dbg("%s - Invalid baud rate %d requested, using 9600.", __func__, 2167 dbg("%s - Invalid baud rate %d requested, using 9600.",
2186 p_priv->baud); 2168 __func__, p_priv->baud);
2187 msg.baudLo = 0; 2169 msg.baudLo = 0;
2188 msg.baudHi = 125; /* Values for 9600 baud */ 2170 msg.baudHi = 125; /* Values for 9600 baud */
2189 msg.prescaler = 10; 2171 msg.prescaler = 10;
2190 } 2172 }
2191 //msg.setPrescaler = 0xff; 2173 /* msg.setPrescaler = 0xff; */
2192 } 2174 }
2193 2175
2194 msg.lcr = (p_priv->cflag & CSTOPB)? STOPBITS_678_2: STOPBITS_5678_1; 2176 msg.lcr = (p_priv->cflag & CSTOPB)? STOPBITS_678_2: STOPBITS_5678_1;
@@ -2209,19 +2191,19 @@ static int keyspan_usa49_send_setup(struct usb_serial *serial,
2209 if (p_priv->cflag & PARENB) { 2191 if (p_priv->cflag & PARENB) {
2210 /* note USA_PARITY_NONE == 0 */ 2192 /* note USA_PARITY_NONE == 0 */
2211 msg.lcr |= (p_priv->cflag & PARODD)? 2193 msg.lcr |= (p_priv->cflag & PARODD)?
2212 USA_PARITY_ODD: USA_PARITY_EVEN; 2194 USA_PARITY_ODD : USA_PARITY_EVEN;
2213 } 2195 }
2214 msg.setLcr = 0xff; 2196 msg.setLcr = 0xff;
2215 2197
2216 msg.ctsFlowControl = (p_priv->flow_control == flow_cts); 2198 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
2217 msg.xonFlowControl = 0; 2199 msg.xonFlowControl = 0;
2218 msg.setFlowControl = 0xff; 2200 msg.setFlowControl = 0xff;
2219 2201
2220 msg.forwardingLength = 16; 2202 msg.forwardingLength = 16;
2221 msg.xonChar = 17; 2203 msg.xonChar = 17;
2222 msg.xoffChar = 19; 2204 msg.xoffChar = 19;
2223 2205
2224 /* Opening port */ 2206 /* Opening port */
2225 if (reset_port == 1) { 2207 if (reset_port == 1) {
2226 msg._txOn = 1; 2208 msg._txOn = 1;
2227 msg._txOff = 0; 2209 msg._txOff = 0;
@@ -2253,7 +2235,7 @@ static int keyspan_usa49_send_setup(struct usb_serial *serial,
2253 } 2235 }
2254 /* Sending intermediate configs */ 2236 /* Sending intermediate configs */
2255 else { 2237 else {
2256 msg._txOn = (! p_priv->break_on); 2238 msg._txOn = (!p_priv->break_on);
2257 msg._txOff = 0; 2239 msg._txOff = 0;
2258 msg.txFlush = 0; 2240 msg.txFlush = 0;
2259 msg.txBreak = (p_priv->break_on); 2241 msg.txBreak = (p_priv->break_on);
@@ -2267,16 +2249,17 @@ static int keyspan_usa49_send_setup(struct usb_serial *serial,
2267 msg.disablePort = 0; 2249 msg.disablePort = 0;
2268 } 2250 }
2269 2251
2270 /* Do handshaking outputs */ 2252 /* Do handshaking outputs */
2271 msg.setRts = 0xff; 2253 msg.setRts = 0xff;
2272 msg.rts = p_priv->rts_state; 2254 msg.rts = p_priv->rts_state;
2273 2255
2274 msg.setDtr = 0xff; 2256 msg.setDtr = 0xff;
2275 msg.dtr = p_priv->dtr_state; 2257 msg.dtr = p_priv->dtr_state;
2276 2258
2277 p_priv->resend_cont = 0; 2259 p_priv->resend_cont = 0;
2278 2260
2279 /* if the device is a 49wg, we send control message on usb control EP 0 */ 2261 /* if the device is a 49wg, we send control message on usb
2262 control EP 0 */
2280 2263
2281 if (d_details->product_id == keyspan_usa49wg_product_id) { 2264 if (d_details->product_id == keyspan_usa49wg_product_id) {
2282 dr = (void *)(s_priv->ctrl_buf); 2265 dr = (void *)(s_priv->ctrl_buf);
@@ -2286,23 +2269,24 @@ static int keyspan_usa49_send_setup(struct usb_serial *serial,
2286 dr->wIndex = 0; 2269 dr->wIndex = 0;
2287 dr->wLength = cpu_to_le16(sizeof(msg)); 2270 dr->wLength = cpu_to_le16(sizeof(msg));
2288 2271
2289 memcpy (s_priv->glocont_buf, &msg, sizeof(msg)); 2272 memcpy(s_priv->glocont_buf, &msg, sizeof(msg));
2290 2273
2291 usb_fill_control_urb(this_urb, serial->dev, usb_sndctrlpipe(serial->dev, 0), 2274 usb_fill_control_urb(this_urb, serial->dev,
2292 (unsigned char *)dr, s_priv->glocont_buf, sizeof(msg), 2275 usb_sndctrlpipe(serial->dev, 0),
2293 usa49_glocont_callback, serial); 2276 (unsigned char *)dr, s_priv->glocont_buf,
2277 sizeof(msg), usa49_glocont_callback, serial);
2294 2278
2295 } else { 2279 } else {
2296 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg)); 2280 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
2297 2281
2298 /* send the data out the device on control endpoint */ 2282 /* send the data out the device on control endpoint */
2299 this_urb->transfer_buffer_length = sizeof(msg); 2283 this_urb->transfer_buffer_length = sizeof(msg);
2300 2284
2301 this_urb->dev = serial->dev; 2285 this_urb->dev = serial->dev;
2302 } 2286 }
2303 if ((err = usb_submit_urb(this_urb, GFP_ATOMIC)) != 0) { 2287 err = usb_submit_urb(this_urb, GFP_ATOMIC);
2288 if (err != 0)
2304 dbg("%s - usb_submit_urb(setup) failed (%d)", __func__, err); 2289 dbg("%s - usb_submit_urb(setup) failed (%d)", __func__, err);
2305 }
2306#if 0 2290#if 0
2307 else { 2291 else {
2308 dbg("%s - usb_submit_urb(%d) OK %d bytes (end %d)", __func__, 2292 dbg("%s - usb_submit_urb(%d) OK %d bytes (end %d)", __func__,
@@ -2318,7 +2302,7 @@ static int keyspan_usa90_send_setup(struct usb_serial *serial,
2318 struct usb_serial_port *port, 2302 struct usb_serial_port *port,
2319 int reset_port) 2303 int reset_port)
2320{ 2304{
2321 struct keyspan_usa90_portControlMessage msg; 2305 struct keyspan_usa90_portControlMessage msg;
2322 struct keyspan_serial_private *s_priv; 2306 struct keyspan_serial_private *s_priv;
2323 struct keyspan_port_private *p_priv; 2307 struct keyspan_port_private *p_priv;
2324 const struct keyspan_device_details *d_details; 2308 const struct keyspan_device_details *d_details;
@@ -2326,14 +2310,15 @@ static int keyspan_usa90_send_setup(struct usb_serial *serial,
2326 int err; 2310 int err;
2327 u8 prescaler; 2311 u8 prescaler;
2328 2312
2329 dbg ("%s", __func__); 2313 dbg("%s", __func__);
2330 2314
2331 s_priv = usb_get_serial_data(serial); 2315 s_priv = usb_get_serial_data(serial);
2332 p_priv = usb_get_serial_port_data(port); 2316 p_priv = usb_get_serial_port_data(port);
2333 d_details = s_priv->device_details; 2317 d_details = s_priv->device_details;
2334 2318
2335 /* only do something if we have a bulk out endpoint */ 2319 /* only do something if we have a bulk out endpoint */
2336 if ((this_urb = p_priv->outcont_urb) == NULL) { 2320 this_urb = p_priv->outcont_urb;
2321 if (this_urb == NULL) {
2337 dbg("%s - oops no urb.", __func__); 2322 dbg("%s - oops no urb.", __func__);
2338 return -1; 2323 return -1;
2339 } 2324 }
@@ -2343,24 +2328,24 @@ static int keyspan_usa90_send_setup(struct usb_serial *serial,
2343 if ((reset_port + 1) > p_priv->resend_cont) 2328 if ((reset_port + 1) > p_priv->resend_cont)
2344 p_priv->resend_cont = reset_port + 1; 2329 p_priv->resend_cont = reset_port + 1;
2345 if (this_urb->status == -EINPROGRESS) { 2330 if (this_urb->status == -EINPROGRESS) {
2346 dbg ("%s already writing", __func__); 2331 dbg("%s already writing", __func__);
2347 mdelay(5); 2332 mdelay(5);
2348 return(-1); 2333 return -1;
2349 } 2334 }
2350 2335
2351 memset(&msg, 0, sizeof (struct keyspan_usa90_portControlMessage)); 2336 memset(&msg, 0, sizeof(struct keyspan_usa90_portControlMessage));
2352 2337
2353 /* Only set baud rate if it's changed */ 2338 /* Only set baud rate if it's changed */
2354 if (p_priv->old_baud != p_priv->baud) { 2339 if (p_priv->old_baud != p_priv->baud) {
2355 p_priv->old_baud = p_priv->baud; 2340 p_priv->old_baud = p_priv->baud;
2356 msg.setClocking = 0x01; 2341 msg.setClocking = 0x01;
2357 if (d_details->calculate_baud_rate 2342 if (d_details->calculate_baud_rate
2358 (p_priv->baud, d_details->baudclk, &msg.baudHi, 2343 (p_priv->baud, d_details->baudclk, &msg.baudHi,
2359 &msg.baudLo, &prescaler, 0) == KEYSPAN_INVALID_BAUD_RATE ) { 2344 &msg.baudLo, &prescaler, 0) == KEYSPAN_INVALID_BAUD_RATE) {
2360 dbg("%s - Invalid baud rate %d requested, using 9600.", __func__, 2345 dbg("%s - Invalid baud rate %d requested, using 9600.",
2361 p_priv->baud); 2346 __func__, p_priv->baud);
2362 p_priv->baud = 9600; 2347 p_priv->baud = 9600;
2363 d_details->calculate_baud_rate (p_priv->baud, d_details->baudclk, 2348 d_details->calculate_baud_rate(p_priv->baud, d_details->baudclk,
2364 &msg.baudHi, &msg.baudLo, &prescaler, 0); 2349 &msg.baudHi, &msg.baudLo, &prescaler, 0);
2365 } 2350 }
2366 msg.setRxMode = 1; 2351 msg.setRxMode = 1;
@@ -2368,13 +2353,10 @@ static int keyspan_usa90_send_setup(struct usb_serial *serial,
2368 } 2353 }
2369 2354
2370 /* modes must always be correctly specified */ 2355 /* modes must always be correctly specified */
2371 if (p_priv->baud > 57600) 2356 if (p_priv->baud > 57600) {
2372 {
2373 msg.rxMode = RXMODE_DMA; 2357 msg.rxMode = RXMODE_DMA;
2374 msg.txMode = TXMODE_DMA; 2358 msg.txMode = TXMODE_DMA;
2375 } 2359 } else {
2376 else
2377 {
2378 msg.rxMode = RXMODE_BYHAND; 2360 msg.rxMode = RXMODE_BYHAND;
2379 msg.txMode = TXMODE_BYHAND; 2361 msg.txMode = TXMODE_BYHAND;
2380 } 2362 }
@@ -2397,7 +2379,7 @@ static int keyspan_usa90_send_setup(struct usb_serial *serial,
2397 if (p_priv->cflag & PARENB) { 2379 if (p_priv->cflag & PARENB) {
2398 /* note USA_PARITY_NONE == 0 */ 2380 /* note USA_PARITY_NONE == 0 */
2399 msg.lcr |= (p_priv->cflag & PARODD)? 2381 msg.lcr |= (p_priv->cflag & PARODD)?
2400 USA_PARITY_ODD: USA_PARITY_EVEN; 2382 USA_PARITY_ODD : USA_PARITY_EVEN;
2401 } 2383 }
2402 if (p_priv->old_cflag != p_priv->cflag) { 2384 if (p_priv->old_cflag != p_priv->cflag) {
2403 p_priv->old_cflag = p_priv->cflag; 2385 p_priv->old_cflag = p_priv->cflag;
@@ -2408,47 +2390,46 @@ static int keyspan_usa90_send_setup(struct usb_serial *serial,
2408 msg.txFlowControl = TXFLOW_CTS; 2390 msg.txFlowControl = TXFLOW_CTS;
2409 msg.setTxFlowControl = 0x01; 2391 msg.setTxFlowControl = 0x01;
2410 msg.setRxFlowControl = 0x01; 2392 msg.setRxFlowControl = 0x01;
2411 2393
2412 msg.rxForwardingLength = 16; 2394 msg.rxForwardingLength = 16;
2413 msg.rxForwardingTimeout = 16; 2395 msg.rxForwardingTimeout = 16;
2414 msg.txAckSetting = 0; 2396 msg.txAckSetting = 0;
2415 msg.xonChar = 17; 2397 msg.xonChar = 17;
2416 msg.xoffChar = 19; 2398 msg.xoffChar = 19;
2417 2399
2418 /* Opening port */ 2400 /* Opening port */
2419 if (reset_port == 1) { 2401 if (reset_port == 1) {
2420 msg.portEnabled = 1; 2402 msg.portEnabled = 1;
2421 msg.rxFlush = 1; 2403 msg.rxFlush = 1;
2422 msg.txBreak = (p_priv->break_on); 2404 msg.txBreak = (p_priv->break_on);
2423 } 2405 }
2424 /* Closing port */ 2406 /* Closing port */
2425 else if (reset_port == 2) { 2407 else if (reset_port == 2)
2426 msg.portEnabled = 0; 2408 msg.portEnabled = 0;
2427 }
2428 /* Sending intermediate configs */ 2409 /* Sending intermediate configs */
2429 else { 2410 else {
2430 if (port->open_count) 2411 if (port->port.count)
2431 msg.portEnabled = 1; 2412 msg.portEnabled = 1;
2432 msg.txBreak = (p_priv->break_on); 2413 msg.txBreak = (p_priv->break_on);
2433 } 2414 }
2434 2415
2435 /* Do handshaking outputs */ 2416 /* Do handshaking outputs */
2436 msg.setRts = 0x01; 2417 msg.setRts = 0x01;
2437 msg.rts = p_priv->rts_state; 2418 msg.rts = p_priv->rts_state;
2438 2419
2439 msg.setDtr = 0x01; 2420 msg.setDtr = 0x01;
2440 msg.dtr = p_priv->dtr_state; 2421 msg.dtr = p_priv->dtr_state;
2441 2422
2442 p_priv->resend_cont = 0; 2423 p_priv->resend_cont = 0;
2443 memcpy (this_urb->transfer_buffer, &msg, sizeof(msg)); 2424 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
2444 2425
2445 /* send the data out the device on control endpoint */ 2426 /* send the data out the device on control endpoint */
2446 this_urb->transfer_buffer_length = sizeof(msg); 2427 this_urb->transfer_buffer_length = sizeof(msg);
2447 2428
2448 this_urb->dev = serial->dev; 2429 this_urb->dev = serial->dev;
2449 if ((err = usb_submit_urb(this_urb, GFP_ATOMIC)) != 0) { 2430 err = usb_submit_urb(this_urb, GFP_ATOMIC);
2431 if (err != 0)
2450 dbg("%s - usb_submit_urb(setup) failed (%d)", __func__, err); 2432 dbg("%s - usb_submit_urb(setup) failed (%d)", __func__, err);
2451 }
2452 return 0; 2433 return 0;
2453} 2434}
2454 2435
@@ -2463,7 +2444,7 @@ static int keyspan_usa67_send_setup(struct usb_serial *serial,
2463 struct urb *this_urb; 2444 struct urb *this_urb;
2464 int err, device_port; 2445 int err, device_port;
2465 2446
2466 dbg ("%s", __func__); 2447 dbg("%s", __func__);
2467 2448
2468 s_priv = usb_get_serial_data(serial); 2449 s_priv = usb_get_serial_data(serial);
2469 p_priv = usb_get_serial_port_data(port); 2450 p_priv = usb_get_serial_port_data(port);
@@ -2486,9 +2467,9 @@ static int keyspan_usa67_send_setup(struct usb_serial *serial,
2486 if ((reset_port + 1) > p_priv->resend_cont) 2467 if ((reset_port + 1) > p_priv->resend_cont)
2487 p_priv->resend_cont = reset_port + 1; 2468 p_priv->resend_cont = reset_port + 1;
2488 if (this_urb->status == -EINPROGRESS) { 2469 if (this_urb->status == -EINPROGRESS) {
2489 /* dbg ("%s - already writing", __func__); */ 2470 /* dbg("%s - already writing", __func__); */
2490 mdelay(5); 2471 mdelay(5);
2491 return(-1); 2472 return -1;
2492 } 2473 }
2493 2474
2494 memset(&msg, 0, sizeof(struct keyspan_usa67_portControlMessage)); 2475 memset(&msg, 0, sizeof(struct keyspan_usa67_portControlMessage));
@@ -2501,9 +2482,9 @@ static int keyspan_usa67_send_setup(struct usb_serial *serial,
2501 msg.setClocking = 0xff; 2482 msg.setClocking = 0xff;
2502 if (d_details->calculate_baud_rate 2483 if (d_details->calculate_baud_rate
2503 (p_priv->baud, d_details->baudclk, &msg.baudHi, 2484 (p_priv->baud, d_details->baudclk, &msg.baudHi,
2504 &msg.baudLo, &msg.prescaler, device_port) == KEYSPAN_INVALID_BAUD_RATE ) { 2485 &msg.baudLo, &msg.prescaler, device_port) == KEYSPAN_INVALID_BAUD_RATE) {
2505 dbg("%s - Invalid baud rate %d requested, using 9600.", __func__, 2486 dbg("%s - Invalid baud rate %d requested, using 9600.",
2506 p_priv->baud); 2487 __func__, p_priv->baud);
2507 msg.baudLo = 0; 2488 msg.baudLo = 0;
2508 msg.baudHi = 125; /* Values for 9600 baud */ 2489 msg.baudHi = 125; /* Values for 9600 baud */
2509 msg.prescaler = 10; 2490 msg.prescaler = 10;
@@ -2529,7 +2510,7 @@ static int keyspan_usa67_send_setup(struct usb_serial *serial,
2529 if (p_priv->cflag & PARENB) { 2510 if (p_priv->cflag & PARENB) {
2530 /* note USA_PARITY_NONE == 0 */ 2511 /* note USA_PARITY_NONE == 0 */
2531 msg.lcr |= (p_priv->cflag & PARODD)? 2512 msg.lcr |= (p_priv->cflag & PARODD)?
2532 USA_PARITY_ODD: USA_PARITY_EVEN; 2513 USA_PARITY_ODD : USA_PARITY_EVEN;
2533 } 2514 }
2534 msg.setLcr = 0xff; 2515 msg.setLcr = 0xff;
2535 2516
@@ -2566,7 +2547,7 @@ static int keyspan_usa67_send_setup(struct usb_serial *serial,
2566 msg.resetDataToggle = 0; 2547 msg.resetDataToggle = 0;
2567 } else { 2548 } else {
2568 /* Sending intermediate configs */ 2549 /* Sending intermediate configs */
2569 msg._txOn = (! p_priv->break_on); 2550 msg._txOn = (!p_priv->break_on);
2570 msg._txOff = 0; 2551 msg._txOff = 0;
2571 msg.txFlush = 0; 2552 msg.txFlush = 0;
2572 msg.txBreak = (p_priv->break_on); 2553 msg.txBreak = (p_priv->break_on);
@@ -2606,7 +2587,7 @@ static void keyspan_send_setup(struct usb_serial_port *port, int reset_port)
2606 struct keyspan_serial_private *s_priv; 2587 struct keyspan_serial_private *s_priv;
2607 const struct keyspan_device_details *d_details; 2588 const struct keyspan_device_details *d_details;
2608 2589
2609 dbg ("%s", __func__); 2590 dbg("%s", __func__);
2610 2591
2611 s_priv = usb_get_serial_data(serial); 2592 s_priv = usb_get_serial_data(serial);
2612 d_details = s_priv->device_details; 2593 d_details = s_priv->device_details;
@@ -2633,7 +2614,7 @@ static void keyspan_send_setup(struct usb_serial_port *port, int reset_port)
2633 2614
2634/* Gets called by the "real" driver (ie once firmware is loaded 2615/* Gets called by the "real" driver (ie once firmware is loaded
2635 and renumeration has taken place. */ 2616 and renumeration has taken place. */
2636static int keyspan_startup (struct usb_serial *serial) 2617static int keyspan_startup(struct usb_serial *serial)
2637{ 2618{
2638 int i, err; 2619 int i, err;
2639 struct usb_serial_port *port; 2620 struct usb_serial_port *port;
@@ -2644,17 +2625,20 @@ static int keyspan_startup (struct usb_serial *serial)
2644 dbg("%s", __func__); 2625 dbg("%s", __func__);
2645 2626
2646 for (i = 0; (d_details = keyspan_devices[i]) != NULL; ++i) 2627 for (i = 0; (d_details = keyspan_devices[i]) != NULL; ++i)
2647 if (d_details->product_id == le16_to_cpu(serial->dev->descriptor.idProduct)) 2628 if (d_details->product_id ==
2629 le16_to_cpu(serial->dev->descriptor.idProduct))
2648 break; 2630 break;
2649 if (d_details == NULL) { 2631 if (d_details == NULL) {
2650 dev_err(&serial->dev->dev, "%s - unknown product id %x\n", __func__, le16_to_cpu(serial->dev->descriptor.idProduct)); 2632 dev_err(&serial->dev->dev, "%s - unknown product id %x\n",
2633 __func__, le16_to_cpu(serial->dev->descriptor.idProduct));
2651 return 1; 2634 return 1;
2652 } 2635 }
2653 2636
2654 /* Setup private data for serial driver */ 2637 /* Setup private data for serial driver */
2655 s_priv = kzalloc(sizeof(struct keyspan_serial_private), GFP_KERNEL); 2638 s_priv = kzalloc(sizeof(struct keyspan_serial_private), GFP_KERNEL);
2656 if (!s_priv) { 2639 if (!s_priv) {
2657 dbg("%s - kmalloc for keyspan_serial_private failed.", __func__); 2640 dbg("%s - kmalloc for keyspan_serial_private failed.",
2641 __func__);
2658 return -ENOMEM; 2642 return -ENOMEM;
2659 } 2643 }
2660 2644
@@ -2664,10 +2648,11 @@ static int keyspan_startup (struct usb_serial *serial)
2664 /* Now setup per port private data */ 2648 /* Now setup per port private data */
2665 for (i = 0; i < serial->num_ports; i++) { 2649 for (i = 0; i < serial->num_ports; i++) {
2666 port = serial->port[i]; 2650 port = serial->port[i];
2667 p_priv = kzalloc(sizeof(struct keyspan_port_private), GFP_KERNEL); 2651 p_priv = kzalloc(sizeof(struct keyspan_port_private),
2652 GFP_KERNEL);
2668 if (!p_priv) { 2653 if (!p_priv) {
2669 dbg("%s - kmalloc for keyspan_port_private (%d) failed!.", __func__, i); 2654 dbg("%s - kmalloc for keyspan_port_private (%d) failed!.", __func__, i);
2670 return (1); 2655 return 1;
2671 } 2656 }
2672 p_priv->device_details = d_details; 2657 p_priv->device_details = d_details;
2673 usb_set_serial_port_data(port, p_priv); 2658 usb_set_serial_port_data(port, p_priv);
@@ -2689,11 +2674,11 @@ static int keyspan_startup (struct usb_serial *serial)
2689 dbg("%s - submit indat urb failed %d", __func__, 2674 dbg("%s - submit indat urb failed %d", __func__,
2690 err); 2675 err);
2691 } 2676 }
2692 2677
2693 return 0; 2678 return 0;
2694} 2679}
2695 2680
2696static void keyspan_shutdown (struct usb_serial *serial) 2681static void keyspan_shutdown(struct usb_serial *serial)
2697{ 2682{
2698 int i, j; 2683 int i, j;
2699 struct usb_serial_port *port; 2684 struct usb_serial_port *port;
@@ -2745,8 +2730,8 @@ static void keyspan_shutdown (struct usb_serial *serial)
2745 } 2730 }
2746} 2731}
2747 2732
2748MODULE_AUTHOR( DRIVER_AUTHOR ); 2733MODULE_AUTHOR(DRIVER_AUTHOR);
2749MODULE_DESCRIPTION( DRIVER_DESC ); 2734MODULE_DESCRIPTION(DRIVER_DESC);
2750MODULE_LICENSE("GPL"); 2735MODULE_LICENSE("GPL");
2751 2736
2752MODULE_FIRMWARE("keyspan/usa28.fw"); 2737MODULE_FIRMWARE("keyspan/usa28.fw");
diff --git a/drivers/usb/serial/keyspan.h b/drivers/usb/serial/keyspan.h
index 8bf72639b148..38b4582e0734 100644
--- a/drivers/usb/serial/keyspan.h
+++ b/drivers/usb/serial/keyspan.h
@@ -35,17 +35,18 @@
35 35
36 36
37/* Function prototypes for Keyspan serial converter */ 37/* Function prototypes for Keyspan serial converter */
38static int keyspan_open (struct usb_serial_port *port, 38static int keyspan_open (struct tty_struct *tty,
39 struct usb_serial_port *port,
39 struct file *filp); 40 struct file *filp);
40static void keyspan_close (struct usb_serial_port *port, 41static void keyspan_close (struct tty_struct *tty,
42 struct usb_serial_port *port,
41 struct file *filp); 43 struct file *filp);
42static int keyspan_startup (struct usb_serial *serial); 44static int keyspan_startup (struct usb_serial *serial);
43static void keyspan_shutdown (struct usb_serial *serial); 45static void keyspan_shutdown (struct usb_serial *serial);
44static void keyspan_rx_throttle (struct usb_serial_port *port); 46static int keyspan_write_room (struct tty_struct *tty);
45static void keyspan_rx_unthrottle (struct usb_serial_port *port);
46static int keyspan_write_room (struct usb_serial_port *port);
47 47
48static int keyspan_write (struct usb_serial_port *port, 48static int keyspan_write (struct tty_struct *tty,
49 struct usb_serial_port *port,
49 const unsigned char *buf, 50 const unsigned char *buf,
50 int count); 51 int count);
51 52
@@ -53,18 +54,14 @@ static void keyspan_send_setup (struct usb_serial_port *port,
53 int reset_port); 54 int reset_port);
54 55
55 56
56static int keyspan_chars_in_buffer (struct usb_serial_port *port); 57static void keyspan_set_termios (struct tty_struct *tty,
57static int keyspan_ioctl (struct usb_serial_port *port, 58 struct usb_serial_port *port,
58 struct file *file,
59 unsigned int cmd,
60 unsigned long arg);
61static void keyspan_set_termios (struct usb_serial_port *port,
62 struct ktermios *old); 59 struct ktermios *old);
63static void keyspan_break_ctl (struct usb_serial_port *port, 60static void keyspan_break_ctl (struct tty_struct *tty,
64 int break_state); 61 int break_state);
65static int keyspan_tiocmget (struct usb_serial_port *port, 62static int keyspan_tiocmget (struct tty_struct *tty,
66 struct file *file); 63 struct file *file);
67static int keyspan_tiocmset (struct usb_serial_port *port, 64static int keyspan_tiocmset (struct tty_struct *tty,
68 struct file *file, unsigned int set, 65 struct file *file, unsigned int set,
69 unsigned int clear); 66 unsigned int clear);
70static int keyspan_fake_startup (struct usb_serial *serial); 67static int keyspan_fake_startup (struct usb_serial *serial);
@@ -567,10 +564,6 @@ static struct usb_serial_driver keyspan_1port_device = {
567 .close = keyspan_close, 564 .close = keyspan_close,
568 .write = keyspan_write, 565 .write = keyspan_write,
569 .write_room = keyspan_write_room, 566 .write_room = keyspan_write_room,
570 .chars_in_buffer = keyspan_chars_in_buffer,
571 .throttle = keyspan_rx_throttle,
572 .unthrottle = keyspan_rx_unthrottle,
573 .ioctl = keyspan_ioctl,
574 .set_termios = keyspan_set_termios, 567 .set_termios = keyspan_set_termios,
575 .break_ctl = keyspan_break_ctl, 568 .break_ctl = keyspan_break_ctl,
576 .tiocmget = keyspan_tiocmget, 569 .tiocmget = keyspan_tiocmget,
@@ -591,10 +584,6 @@ static struct usb_serial_driver keyspan_2port_device = {
591 .close = keyspan_close, 584 .close = keyspan_close,
592 .write = keyspan_write, 585 .write = keyspan_write,
593 .write_room = keyspan_write_room, 586 .write_room = keyspan_write_room,
594 .chars_in_buffer = keyspan_chars_in_buffer,
595 .throttle = keyspan_rx_throttle,
596 .unthrottle = keyspan_rx_unthrottle,
597 .ioctl = keyspan_ioctl,
598 .set_termios = keyspan_set_termios, 587 .set_termios = keyspan_set_termios,
599 .break_ctl = keyspan_break_ctl, 588 .break_ctl = keyspan_break_ctl,
600 .tiocmget = keyspan_tiocmget, 589 .tiocmget = keyspan_tiocmget,
@@ -615,10 +604,6 @@ static struct usb_serial_driver keyspan_4port_device = {
615 .close = keyspan_close, 604 .close = keyspan_close,
616 .write = keyspan_write, 605 .write = keyspan_write,
617 .write_room = keyspan_write_room, 606 .write_room = keyspan_write_room,
618 .chars_in_buffer = keyspan_chars_in_buffer,
619 .throttle = keyspan_rx_throttle,
620 .unthrottle = keyspan_rx_unthrottle,
621 .ioctl = keyspan_ioctl,
622 .set_termios = keyspan_set_termios, 607 .set_termios = keyspan_set_termios,
623 .break_ctl = keyspan_break_ctl, 608 .break_ctl = keyspan_break_ctl,
624 .tiocmget = keyspan_tiocmget, 609 .tiocmget = keyspan_tiocmget,
diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c
index 60b3e22bd633..040040a267d9 100644
--- a/drivers/usb/serial/keyspan_pda.c
+++ b/drivers/usb/serial/keyspan_pda.c
@@ -10,8 +10,9 @@
10 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version. 11 * (at your option) any later version.
12 * 12 *
13 * See Documentation/usb/usb-serial.txt for more information on using this driver 13 * See Documentation/usb/usb-serial.txt for more information on using this
14 * 14 * driver
15 *
15 * (09/07/2001) gkh 16 * (09/07/2001) gkh
16 * cleaned up the Xircom support. Added ids for Entregra device which is 17 * cleaned up the Xircom support. Added ids for Entregra device which is
17 * the same as the Xircom device. Enabled the code to be compiled for 18 * the same as the Xircom device. Enabled the code to be compiled for
@@ -21,23 +22,24 @@
21 * support for Xircom PGSDB9 22 * support for Xircom PGSDB9
22 * 23 *
23 * (05/31/2001) gkh 24 * (05/31/2001) gkh
24 * switched from using spinlock to a semaphore, which fixes lots of problems. 25 * switched from using spinlock to a semaphore, which fixes lots of
26 * problems.
25 * 27 *
26 * (04/08/2001) gb 28 * (04/08/2001) gb
27 * Identify version on module load. 29 * Identify version on module load.
28 * 30 *
29 * (11/01/2000) Adam J. Richter 31 * (11/01/2000) Adam J. Richter
30 * usb_device_id table support 32 * usb_device_id table support
31 * 33 *
32 * (10/05/2000) gkh 34 * (10/05/2000) gkh
33 * Fixed bug with urb->dev not being set properly, now that the usb 35 * Fixed bug with urb->dev not being set properly, now that the usb
34 * core needs it. 36 * core needs it.
35 * 37 *
36 * (08/28/2000) gkh 38 * (08/28/2000) gkh
37 * Added locks for SMP safeness. 39 * Added locks for SMP safeness.
38 * Fixed MOD_INC and MOD_DEC logic and the ability to open a port more 40 * Fixed MOD_INC and MOD_DEC logic and the ability to open a port more
39 * than once. 41 * than once.
40 * 42 *
41 * (07/20/2000) borchers 43 * (07/20/2000) borchers
42 * - keyspan_pda_write no longer sleeps if it is called on interrupt time; 44 * - keyspan_pda_write no longer sleeps if it is called on interrupt time;
43 * PPP and the line discipline with stty echo on can call write on 45 * PPP and the line discipline with stty echo on can call write on
@@ -55,14 +57,14 @@
55 * than done directly from the callback to avoid the race in write_chan 57 * than done directly from the callback to avoid the race in write_chan
56 * - keyspan_pda_chars_in_buffer also indicates its buffer is full if the 58 * - keyspan_pda_chars_in_buffer also indicates its buffer is full if the
57 * urb status is -EINPROGRESS, meaning it cannot write at the moment 59 * urb status is -EINPROGRESS, meaning it cannot write at the moment
58 * 60 *
59 * (07/19/2000) gkh 61 * (07/19/2000) gkh
60 * Added module_init and module_exit functions to handle the fact that this 62 * Added module_init and module_exit functions to handle the fact that this
61 * driver is a loadable module now. 63 * driver is a loadable module now.
62 * 64 *
63 * (03/26/2000) gkh 65 * (03/26/2000) gkh
64 * Split driver up into device specific pieces. 66 * Split driver up into device specific pieces.
65 * 67 *
66 */ 68 */
67 69
68 70
@@ -78,7 +80,7 @@
78#include <linux/workqueue.h> 80#include <linux/workqueue.h>
79#include <linux/firmware.h> 81#include <linux/firmware.h>
80#include <linux/ihex.h> 82#include <linux/ihex.h>
81#include <asm/uaccess.h> 83#include <linux/uaccess.h>
82#include <linux/usb.h> 84#include <linux/usb.h>
83#include <linux/usb/serial.h> 85#include <linux/usb/serial.h>
84 86
@@ -135,7 +137,7 @@ static struct usb_device_id id_table_combined [] = {
135 { } /* Terminating entry */ 137 { } /* Terminating entry */
136}; 138};
137 139
138MODULE_DEVICE_TABLE (usb, id_table_combined); 140MODULE_DEVICE_TABLE(usb, id_table_combined);
139 141
140static struct usb_driver keyspan_pda_driver = { 142static struct usb_driver keyspan_pda_driver = {
141 .name = "keyspan_pda", 143 .name = "keyspan_pda",
@@ -159,9 +161,9 @@ static struct usb_device_id id_table_fake [] = {
159 161
160#ifdef XIRCOM 162#ifdef XIRCOM
161static struct usb_device_id id_table_fake_xircom [] = { 163static struct usb_device_id id_table_fake_xircom [] = {
162 { USB_DEVICE(XIRCOM_VENDOR_ID, XIRCOM_FAKE_ID) }, 164 { USB_DEVICE(XIRCOM_VENDOR_ID, XIRCOM_FAKE_ID) },
163 { USB_DEVICE(ENTREGRA_VENDOR_ID, ENTREGRA_FAKE_ID) }, 165 { USB_DEVICE(ENTREGRA_VENDOR_ID, ENTREGRA_FAKE_ID) },
164 { } 166 { }
165}; 167};
166#endif 168#endif
167 169
@@ -171,7 +173,7 @@ static void keyspan_pda_wakeup_write(struct work_struct *work)
171 container_of(work, struct keyspan_pda_private, wakeup_work); 173 container_of(work, struct keyspan_pda_private, wakeup_work);
172 struct usb_serial_port *port = priv->port; 174 struct usb_serial_port *port = priv->port;
173 175
174 tty_wakeup(port->tty); 176 tty_wakeup(port->port.tty);
175} 177}
176 178
177static void keyspan_pda_request_unthrottle(struct work_struct *work) 179static void keyspan_pda_request_unthrottle(struct work_struct *work)
@@ -184,7 +186,7 @@ static void keyspan_pda_request_unthrottle(struct work_struct *work)
184 dbg(" request_unthrottle"); 186 dbg(" request_unthrottle");
185 /* ask the device to tell us when the tx buffer becomes 187 /* ask the device to tell us when the tx buffer becomes
186 sufficiently empty */ 188 sufficiently empty */
187 result = usb_control_msg(serial->dev, 189 result = usb_control_msg(serial->dev,
188 usb_sndctrlpipe(serial->dev, 0), 190 usb_sndctrlpipe(serial->dev, 0),
189 7, /* request_unthrottle */ 191 7, /* request_unthrottle */
190 USB_TYPE_VENDOR | USB_RECIP_INTERFACE 192 USB_TYPE_VENDOR | USB_RECIP_INTERFACE
@@ -195,17 +197,16 @@ static void keyspan_pda_request_unthrottle(struct work_struct *work)
195 0, 197 0,
196 2000); 198 2000);
197 if (result < 0) 199 if (result < 0)
198 dbg("%s - error %d from usb_control_msg", 200 dbg("%s - error %d from usb_control_msg",
199 __func__, result); 201 __func__, result);
200} 202}
201 203
202 204
203static void keyspan_pda_rx_interrupt (struct urb *urb) 205static void keyspan_pda_rx_interrupt(struct urb *urb)
204{ 206{
205 struct usb_serial_port *port = urb->context; 207 struct usb_serial_port *port = urb->context;
206 struct tty_struct *tty = port->tty; 208 struct tty_struct *tty = port->port.tty;
207 unsigned char *data = urb->transfer_buffer; 209 unsigned char *data = urb->transfer_buffer;
208 int i;
209 int retval; 210 int retval;
210 int status = urb->status; 211 int status = urb->status;
211 struct keyspan_pda_private *priv; 212 struct keyspan_pda_private *priv;
@@ -228,14 +229,13 @@ static void keyspan_pda_rx_interrupt (struct urb *urb)
228 goto exit; 229 goto exit;
229 } 230 }
230 231
231 /* see if the message is data or a status interrupt */ 232 /* see if the message is data or a status interrupt */
232 switch (data[0]) { 233 switch (data[0]) {
233 case 0: 234 case 0:
234 /* rest of message is rx data */ 235 /* rest of message is rx data */
235 if (urb->actual_length) { 236 if (urb->actual_length) {
236 for (i = 1; i < urb->actual_length ; ++i) { 237 tty_insert_flip_string(tty, data + 1,
237 tty_insert_flip_char(tty, data[i], 0); 238 urb->actual_length - 1);
238 }
239 tty_flip_buffer_push(tty); 239 tty_flip_buffer_push(tty);
240 } 240 }
241 break; 241 break;
@@ -259,14 +259,14 @@ static void keyspan_pda_rx_interrupt (struct urb *urb)
259 } 259 }
260 260
261exit: 261exit:
262 retval = usb_submit_urb (urb, GFP_ATOMIC); 262 retval = usb_submit_urb(urb, GFP_ATOMIC);
263 if (retval) 263 if (retval)
264 err ("%s - usb_submit_urb failed with result %d", 264 err("%s - usb_submit_urb failed with result %d",
265 __func__, retval); 265 __func__, retval);
266} 266}
267 267
268 268
269static void keyspan_pda_rx_throttle (struct usb_serial_port *port) 269static void keyspan_pda_rx_throttle(struct tty_struct *tty)
270{ 270{
271 /* stop receiving characters. We just turn off the URB request, and 271 /* stop receiving characters. We just turn off the URB request, and
272 let chars pile up in the device. If we're doing hardware 272 let chars pile up in the device. If we're doing hardware
@@ -274,14 +274,15 @@ static void keyspan_pda_rx_throttle (struct usb_serial_port *port)
274 fills up. If we're doing XON/XOFF, this would be a good time to 274 fills up. If we're doing XON/XOFF, this would be a good time to
275 send an XOFF, although it might make sense to foist that off 275 send an XOFF, although it might make sense to foist that off
276 upon the device too. */ 276 upon the device too. */
277 277 struct usb_serial_port *port = tty->driver_data;
278 dbg("keyspan_pda_rx_throttle port %d", port->number); 278 dbg("keyspan_pda_rx_throttle port %d", port->number);
279 usb_kill_urb(port->interrupt_in_urb); 279 usb_kill_urb(port->interrupt_in_urb);
280} 280}
281 281
282 282
283static void keyspan_pda_rx_unthrottle (struct usb_serial_port *port) 283static void keyspan_pda_rx_unthrottle(struct tty_struct *tty)
284{ 284{
285 struct usb_serial_port *port = tty->driver_data;
285 /* just restart the receive interrupt URB */ 286 /* just restart the receive interrupt URB */
286 dbg("keyspan_pda_rx_unthrottle port %d", port->number); 287 dbg("keyspan_pda_rx_unthrottle port %d", port->number);
287 port->interrupt_in_urb->dev = port->serial->dev; 288 port->interrupt_in_urb->dev = port->serial->dev;
@@ -291,32 +292,52 @@ static void keyspan_pda_rx_unthrottle (struct usb_serial_port *port)
291} 292}
292 293
293 294
294static speed_t keyspan_pda_setbaud (struct usb_serial *serial, speed_t baud) 295static speed_t keyspan_pda_setbaud(struct usb_serial *serial, speed_t baud)
295{ 296{
296 int rc; 297 int rc;
297 int bindex; 298 int bindex;
298 299
299 switch(baud) { 300 switch (baud) {
300 case 110: bindex = 0; break; 301 case 110:
301 case 300: bindex = 1; break; 302 bindex = 0;
302 case 1200: bindex = 2; break; 303 break;
303 case 2400: bindex = 3; break; 304 case 300:
304 case 4800: bindex = 4; break; 305 bindex = 1;
305 case 9600: bindex = 5; break; 306 break;
306 case 19200: bindex = 6; break; 307 case 1200:
307 case 38400: bindex = 7; break; 308 bindex = 2;
308 case 57600: bindex = 8; break; 309 break;
309 case 115200: bindex = 9; break; 310 case 2400:
310 default: 311 bindex = 3;
311 bindex = 5; /* Default to 9600 */ 312 break;
312 baud = 9600; 313 case 4800:
314 bindex = 4;
315 break;
316 case 9600:
317 bindex = 5;
318 break;
319 case 19200:
320 bindex = 6;
321 break;
322 case 38400:
323 bindex = 7;
324 break;
325 case 57600:
326 bindex = 8;
327 break;
328 case 115200:
329 bindex = 9;
330 break;
331 default:
332 bindex = 5; /* Default to 9600 */
333 baud = 9600;
313 } 334 }
314 335
315 /* rather than figure out how to sleep while waiting for this 336 /* rather than figure out how to sleep while waiting for this
316 to complete, I just use the "legacy" API. */ 337 to complete, I just use the "legacy" API. */
317 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 338 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
318 0, /* set baud */ 339 0, /* set baud */
319 USB_TYPE_VENDOR 340 USB_TYPE_VENDOR
320 | USB_RECIP_INTERFACE 341 | USB_RECIP_INTERFACE
321 | USB_DIR_OUT, /* type */ 342 | USB_DIR_OUT, /* type */
322 bindex, /* value */ 343 bindex, /* value */
@@ -330,8 +351,9 @@ static speed_t keyspan_pda_setbaud (struct usb_serial *serial, speed_t baud)
330} 351}
331 352
332 353
333static void keyspan_pda_break_ctl (struct usb_serial_port *port, int break_state) 354static void keyspan_pda_break_ctl(struct tty_struct *tty, int break_state)
334{ 355{
356 struct usb_serial_port *port = tty->driver_data;
335 struct usb_serial *serial = port->serial; 357 struct usb_serial *serial = port->serial;
336 int value; 358 int value;
337 int result; 359 int result;
@@ -341,11 +363,11 @@ static void keyspan_pda_break_ctl (struct usb_serial_port *port, int break_state
341 else 363 else
342 value = 0; /* clear break */ 364 value = 0; /* clear break */
343 result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 365 result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
344 4, /* set break */ 366 4, /* set break */
345 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, 367 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
346 value, 0, NULL, 0, 2000); 368 value, 0, NULL, 0, 2000);
347 if (result < 0) 369 if (result < 0)
348 dbg("%s - error %d from usb_control_msg", 370 dbg("%s - error %d from usb_control_msg",
349 __func__, result); 371 __func__, result);
350 /* there is something funky about this.. the TCSBRK that 'cu' performs 372 /* there is something funky about this.. the TCSBRK that 'cu' performs
351 ought to translate into a break_ctl(-1),break_ctl(0) pair HZ/4 373 ought to translate into a break_ctl(-1),break_ctl(0) pair HZ/4
@@ -354,8 +376,8 @@ static void keyspan_pda_break_ctl (struct usb_serial_port *port, int break_state
354} 376}
355 377
356 378
357static void keyspan_pda_set_termios (struct usb_serial_port *port, 379static void keyspan_pda_set_termios(struct tty_struct *tty,
358 struct ktermios *old_termios) 380 struct usb_serial_port *port, struct ktermios *old_termios)
359{ 381{
360 struct usb_serial *serial = port->serial; 382 struct usb_serial *serial = port->serial;
361 speed_t speed; 383 speed_t speed;
@@ -380,7 +402,7 @@ static void keyspan_pda_set_termios (struct usb_serial_port *port,
380 402
381 For now, just do baud. */ 403 For now, just do baud. */
382 404
383 speed = tty_get_baud_rate(port->tty); 405 speed = tty_get_baud_rate(tty);
384 speed = keyspan_pda_setbaud(serial, speed); 406 speed = keyspan_pda_setbaud(serial, speed);
385 407
386 if (speed == 0) { 408 if (speed == 0) {
@@ -390,8 +412,8 @@ static void keyspan_pda_set_termios (struct usb_serial_port *port,
390 } 412 }
391 /* Only speed can change so copy the old h/w parameters 413 /* Only speed can change so copy the old h/w parameters
392 then encode the new speed */ 414 then encode the new speed */
393 tty_termios_copy_hw(port->tty->termios, old_termios); 415 tty_termios_copy_hw(tty->termios, old_termios);
394 tty_encode_baud_rate(port->tty, speed, speed); 416 tty_encode_baud_rate(tty, speed, speed);
395} 417}
396 418
397 419
@@ -425,8 +447,9 @@ static int keyspan_pda_set_modem_info(struct usb_serial *serial,
425 return rc; 447 return rc;
426} 448}
427 449
428static int keyspan_pda_tiocmget(struct usb_serial_port *port, struct file *file) 450static int keyspan_pda_tiocmget(struct tty_struct *tty, struct file *file)
429{ 451{
452 struct usb_serial_port *port = tty->driver_data;
430 struct usb_serial *serial = port->serial; 453 struct usb_serial *serial = port->serial;
431 int rc; 454 int rc;
432 unsigned char status; 455 unsigned char status;
@@ -445,9 +468,10 @@ static int keyspan_pda_tiocmget(struct usb_serial_port *port, struct file *file)
445 return value; 468 return value;
446} 469}
447 470
448static int keyspan_pda_tiocmset(struct usb_serial_port *port, struct file *file, 471static int keyspan_pda_tiocmset(struct tty_struct *tty, struct file *file,
449 unsigned int set, unsigned int clear) 472 unsigned int set, unsigned int clear)
450{ 473{
474 struct usb_serial_port *port = tty->driver_data;
451 struct usb_serial *serial = port->serial; 475 struct usb_serial *serial = port->serial;
452 int rc; 476 int rc;
453 unsigned char status; 477 unsigned char status;
@@ -469,23 +493,8 @@ static int keyspan_pda_tiocmset(struct usb_serial_port *port, struct file *file,
469 return rc; 493 return rc;
470} 494}
471 495
472static int keyspan_pda_ioctl(struct usb_serial_port *port, struct file *file, 496static int keyspan_pda_write(struct tty_struct *tty,
473 unsigned int cmd, unsigned long arg) 497 struct usb_serial_port *port, const unsigned char *buf, int count)
474{
475 switch (cmd) {
476 case TIOCMIWAIT:
477 /* wait for any of the 4 modem inputs (DCD,RI,DSR,CTS)*/
478 /* TODO */
479 case TIOCGICOUNT:
480 /* return count of modemline transitions */
481 return 0; /* TODO */
482 }
483
484 return -ENOIOCTLCMD;
485}
486
487static int keyspan_pda_write(struct usb_serial_port *port,
488 const unsigned char *buf, int count)
489{ 498{
490 struct usb_serial *serial = port->serial; 499 struct usb_serial *serial = port->serial;
491 int request_unthrottle = 0; 500 int request_unthrottle = 0;
@@ -501,10 +510,10 @@ static int keyspan_pda_write(struct usb_serial_port *port,
501 select() or poll() too) until we receive that unthrottle interrupt. 510 select() or poll() too) until we receive that unthrottle interrupt.
502 Block if we can't write anything at all, otherwise write as much as 511 Block if we can't write anything at all, otherwise write as much as
503 we can. */ 512 we can. */
504 dbg("keyspan_pda_write(%d)",count); 513 dbg("keyspan_pda_write(%d)", count);
505 if (count == 0) { 514 if (count == 0) {
506 dbg(" write request of 0 bytes"); 515 dbg(" write request of 0 bytes");
507 return (0); 516 return 0;
508 } 517 }
509 518
510 /* we might block because of: 519 /* we might block because of:
@@ -531,7 +540,7 @@ static int keyspan_pda_write(struct usb_serial_port *port,
531 scheduler time, since usb_control_msg() sleeps. */ 540 scheduler time, since usb_control_msg() sleeps. */
532 if (count > priv->tx_room && !in_interrupt()) { 541 if (count > priv->tx_room && !in_interrupt()) {
533 unsigned char room; 542 unsigned char room;
534 rc = usb_control_msg(serial->dev, 543 rc = usb_control_msg(serial->dev,
535 usb_rcvctrlpipe(serial->dev, 0), 544 usb_rcvctrlpipe(serial->dev, 0),
536 6, /* write_room */ 545 6, /* write_room */
537 USB_TYPE_VENDOR | USB_RECIP_INTERFACE 546 USB_TYPE_VENDOR | USB_RECIP_INTERFACE
@@ -562,7 +571,7 @@ static int keyspan_pda_write(struct usb_serial_port *port,
562 571
563 if (count) { 572 if (count) {
564 /* now transfer data */ 573 /* now transfer data */
565 memcpy (port->write_urb->transfer_buffer, buf, count); 574 memcpy(port->write_urb->transfer_buffer, buf, count);
566 /* send the data out the bulk port */ 575 /* send the data out the bulk port */
567 port->write_urb->transfer_buffer_length = count; 576 port->write_urb->transfer_buffer_length = count;
568 577
@@ -574,8 +583,7 @@ static int keyspan_pda_write(struct usb_serial_port *port,
574 dbg(" usb_submit_urb(write bulk) failed"); 583 dbg(" usb_submit_urb(write bulk) failed");
575 goto exit; 584 goto exit;
576 } 585 }
577 } 586 } else {
578 else {
579 /* There wasn't any room left, so we are throttled until 587 /* There wasn't any room left, so we are throttled until
580 the buffer empties a bit */ 588 the buffer empties a bit */
581 request_unthrottle = 1; 589 request_unthrottle = 1;
@@ -594,7 +602,7 @@ exit:
594} 602}
595 603
596 604
597static void keyspan_pda_write_bulk_callback (struct urb *urb) 605static void keyspan_pda_write_bulk_callback(struct urb *urb)
598{ 606{
599 struct usb_serial_port *port = urb->context; 607 struct usb_serial_port *port = urb->context;
600 struct keyspan_pda_private *priv; 608 struct keyspan_pda_private *priv;
@@ -607,22 +615,21 @@ static void keyspan_pda_write_bulk_callback (struct urb *urb)
607} 615}
608 616
609 617
610static int keyspan_pda_write_room (struct usb_serial_port *port) 618static int keyspan_pda_write_room(struct tty_struct *tty)
611{ 619{
620 struct usb_serial_port *port = tty->driver_data;
612 struct keyspan_pda_private *priv; 621 struct keyspan_pda_private *priv;
613
614 priv = usb_get_serial_port_data(port); 622 priv = usb_get_serial_port_data(port);
615
616 /* used by n_tty.c for processing of tabs and such. Giving it our 623 /* used by n_tty.c for processing of tabs and such. Giving it our
617 conservative guess is probably good enough, but needs testing by 624 conservative guess is probably good enough, but needs testing by
618 running a console through the device. */ 625 running a console through the device. */
619 626 return priv->tx_room;
620 return (priv->tx_room);
621} 627}
622 628
623 629
624static int keyspan_pda_chars_in_buffer (struct usb_serial_port *port) 630static int keyspan_pda_chars_in_buffer(struct tty_struct *tty)
625{ 631{
632 struct usb_serial_port *port = tty->driver_data;
626 struct keyspan_pda_private *priv; 633 struct keyspan_pda_private *priv;
627 unsigned long flags; 634 unsigned long flags;
628 int ret = 0; 635 int ret = 0;
@@ -640,7 +647,8 @@ static int keyspan_pda_chars_in_buffer (struct usb_serial_port *port)
640} 647}
641 648
642 649
643static int keyspan_pda_open (struct usb_serial_port *port, struct file *filp) 650static int keyspan_pda_open(struct tty_struct *tty,
651 struct usb_serial_port *port, struct file *filp)
644{ 652{
645 struct usb_serial *serial = port->serial; 653 struct usb_serial *serial = port->serial;
646 unsigned char room; 654 unsigned char room;
@@ -672,8 +680,8 @@ static int keyspan_pda_open (struct usb_serial_port *port, struct file *filp)
672 680
673 /* the normal serial device seems to always turn on DTR and RTS here, 681 /* the normal serial device seems to always turn on DTR and RTS here,
674 so do the same */ 682 so do the same */
675 if (port->tty->termios->c_cflag & CBAUD) 683 if (tty && (tty->termios->c_cflag & CBAUD))
676 keyspan_pda_set_modem_info(serial, (1<<7) | (1<<2) ); 684 keyspan_pda_set_modem_info(serial, (1<<7) | (1<<2));
677 else 685 else
678 keyspan_pda_set_modem_info(serial, 0); 686 keyspan_pda_set_modem_info(serial, 0);
679 687
@@ -690,13 +698,15 @@ error:
690} 698}
691 699
692 700
693static void keyspan_pda_close(struct usb_serial_port *port, struct file *filp) 701static void keyspan_pda_close(struct tty_struct *tty,
702 struct usb_serial_port *port, struct file *filp)
694{ 703{
695 struct usb_serial *serial = port->serial; 704 struct usb_serial *serial = port->serial;
696 705
697 if (serial->dev) { 706 if (serial->dev) {
698 /* the normal serial device seems to always shut off DTR and RTS now */ 707 /* the normal serial device seems to always shut
699 if (port->tty->termios->c_cflag & HUPCL) 708 off DTR and RTS now */
709 if (tty->termios->c_cflag & HUPCL)
700 keyspan_pda_set_modem_info(serial, 0); 710 keyspan_pda_set_modem_info(serial, 0);
701 711
702 /* shutdown our bulk reads and writes */ 712 /* shutdown our bulk reads and writes */
@@ -707,7 +717,7 @@ static void keyspan_pda_close(struct usb_serial_port *port, struct file *filp)
707 717
708 718
709/* download the firmware to a "fake" device (pre-renumeration) */ 719/* download the firmware to a "fake" device (pre-renumeration) */
710static int keyspan_pda_fake_startup (struct usb_serial *serial) 720static int keyspan_pda_fake_startup(struct usb_serial *serial)
711{ 721{
712 int response; 722 int response;
713 const char *fw_name; 723 const char *fw_name;
@@ -756,10 +766,10 @@ static int keyspan_pda_fake_startup (struct usb_serial *serial)
756 response = ezusb_set_reset(serial, 0); 766 response = ezusb_set_reset(serial, 0);
757 767
758 /* we want this device to fail to have a driver assigned to it. */ 768 /* we want this device to fail to have a driver assigned to it. */
759 return (1); 769 return 1;
760} 770}
761 771
762static int keyspan_pda_startup (struct usb_serial *serial) 772static int keyspan_pda_startup(struct usb_serial *serial)
763{ 773{
764 774
765 struct keyspan_pda_private *priv; 775 struct keyspan_pda_private *priv;
@@ -769,20 +779,20 @@ static int keyspan_pda_startup (struct usb_serial *serial)
769 779
770 priv = kmalloc(sizeof(struct keyspan_pda_private), GFP_KERNEL); 780 priv = kmalloc(sizeof(struct keyspan_pda_private), GFP_KERNEL);
771 if (!priv) 781 if (!priv)
772 return (1); /* error */ 782 return 1; /* error */
773 usb_set_serial_port_data(serial->port[0], priv); 783 usb_set_serial_port_data(serial->port[0], priv);
774 init_waitqueue_head(&serial->port[0]->write_wait); 784 init_waitqueue_head(&serial->port[0]->write_wait);
775 INIT_WORK(&priv->wakeup_work, keyspan_pda_wakeup_write); 785 INIT_WORK(&priv->wakeup_work, keyspan_pda_wakeup_write);
776 INIT_WORK(&priv->unthrottle_work, keyspan_pda_request_unthrottle); 786 INIT_WORK(&priv->unthrottle_work, keyspan_pda_request_unthrottle);
777 priv->serial = serial; 787 priv->serial = serial;
778 priv->port = serial->port[0]; 788 priv->port = serial->port[0];
779 return (0); 789 return 0;
780} 790}
781 791
782static void keyspan_pda_shutdown (struct usb_serial *serial) 792static void keyspan_pda_shutdown(struct usb_serial *serial)
783{ 793{
784 dbg("%s", __func__); 794 dbg("%s", __func__);
785 795
786 kfree(usb_get_serial_port_data(serial->port[0])); 796 kfree(usb_get_serial_port_data(serial->port[0]));
787} 797}
788 798
@@ -832,7 +842,6 @@ static struct usb_serial_driver keyspan_pda_device = {
832 .chars_in_buffer = keyspan_pda_chars_in_buffer, 842 .chars_in_buffer = keyspan_pda_chars_in_buffer,
833 .throttle = keyspan_pda_rx_throttle, 843 .throttle = keyspan_pda_rx_throttle,
834 .unthrottle = keyspan_pda_rx_unthrottle, 844 .unthrottle = keyspan_pda_rx_unthrottle,
835 .ioctl = keyspan_pda_ioctl,
836 .set_termios = keyspan_pda_set_termios, 845 .set_termios = keyspan_pda_set_termios,
837 .break_ctl = keyspan_pda_break_ctl, 846 .break_ctl = keyspan_pda_break_ctl,
838 .tiocmget = keyspan_pda_tiocmget, 847 .tiocmget = keyspan_pda_tiocmget,
@@ -842,7 +851,7 @@ static struct usb_serial_driver keyspan_pda_device = {
842}; 851};
843 852
844 853
845static int __init keyspan_pda_init (void) 854static int __init keyspan_pda_init(void)
846{ 855{
847 int retval; 856 int retval;
848 retval = usb_serial_register(&keyspan_pda_device); 857 retval = usb_serial_register(&keyspan_pda_device);
@@ -863,7 +872,7 @@ static int __init keyspan_pda_init (void)
863 goto failed_usb_register; 872 goto failed_usb_register;
864 info(DRIVER_DESC " " DRIVER_VERSION); 873 info(DRIVER_DESC " " DRIVER_VERSION);
865 return 0; 874 return 0;
866failed_usb_register: 875failed_usb_register:
867#ifdef XIRCOM 876#ifdef XIRCOM
868 usb_serial_deregister(&xircom_pgs_fake_device); 877 usb_serial_deregister(&xircom_pgs_fake_device);
869failed_xircom_register: 878failed_xircom_register:
@@ -880,15 +889,15 @@ failed_pda_register:
880} 889}
881 890
882 891
883static void __exit keyspan_pda_exit (void) 892static void __exit keyspan_pda_exit(void)
884{ 893{
885 usb_deregister (&keyspan_pda_driver); 894 usb_deregister(&keyspan_pda_driver);
886 usb_serial_deregister (&keyspan_pda_device); 895 usb_serial_deregister(&keyspan_pda_device);
887#ifdef KEYSPAN 896#ifdef KEYSPAN
888 usb_serial_deregister (&keyspan_pda_fake_device); 897 usb_serial_deregister(&keyspan_pda_fake_device);
889#endif 898#endif
890#ifdef XIRCOM 899#ifdef XIRCOM
891 usb_serial_deregister (&xircom_pgs_fake_device); 900 usb_serial_deregister(&xircom_pgs_fake_device);
892#endif 901#endif
893} 902}
894 903
@@ -896,8 +905,8 @@ static void __exit keyspan_pda_exit (void)
896module_init(keyspan_pda_init); 905module_init(keyspan_pda_init);
897module_exit(keyspan_pda_exit); 906module_exit(keyspan_pda_exit);
898 907
899MODULE_AUTHOR( DRIVER_AUTHOR ); 908MODULE_AUTHOR(DRIVER_AUTHOR);
900MODULE_DESCRIPTION( DRIVER_DESC ); 909MODULE_DESCRIPTION(DRIVER_DESC);
901MODULE_LICENSE("GPL"); 910MODULE_LICENSE("GPL");
902 911
903module_param(debug, bool, S_IRUGO | S_IWUSR); 912module_param(debug, bool, S_IRUGO | S_IWUSR);
diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c
index 79787eda9524..b84dddc71124 100644
--- a/drivers/usb/serial/kl5kusb105.c
+++ b/drivers/usb/serial/kl5kusb105.c
@@ -15,12 +15,12 @@
15 * Neither Palm, nor their contractor (MCCI) or their supplier (KLSI) provided 15 * Neither Palm, nor their contractor (MCCI) or their supplier (KLSI) provided
16 * information that was not already available. 16 * information that was not already available.
17 * 17 *
18 * It seems that KLSI bought some silicon-design information from ScanLogic, 18 * It seems that KLSI bought some silicon-design information from ScanLogic,
19 * whose SL11R processor is at the core of the KL5KUSB chipset from KLSI. 19 * whose SL11R processor is at the core of the KL5KUSB chipset from KLSI.
20 * KLSI has firmware available for their devices; it is probable that the 20 * KLSI has firmware available for their devices; it is probable that the
21 * firmware differs from that used by KLSI in their products. If you have an 21 * firmware differs from that used by KLSI in their products. If you have an
22 * original KLSI device and can provide some information on it, I would be 22 * original KLSI device and can provide some information on it, I would be
23 * most interested in adding support for it here. If you have any information 23 * most interested in adding support for it here. If you have any information
24 * on the protocol used (or find errors in my reverse-engineered stuff), please 24 * on the protocol used (or find errors in my reverse-engineered stuff), please
25 * let me know. 25 * let me know.
26 * 26 *
@@ -40,7 +40,7 @@
40 * 0.2 - TIOCMGET works, so autopilot(1) can be used! 40 * 0.2 - TIOCMGET works, so autopilot(1) can be used!
41 * 0.1 - can be used to to pilot-xfer -p /dev/ttyUSB0 -l 41 * 0.1 - can be used to to pilot-xfer -p /dev/ttyUSB0 -l
42 * 42 *
43 * The driver skeleton is mainly based on mct_u232.c and various other 43 * The driver skeleton is mainly based on mct_u232.c and various other
44 * pieces of code shamelessly copied from the drivers/usb/serial/ directory. 44 * pieces of code shamelessly copied from the drivers/usb/serial/ directory.
45 */ 45 */
46 46
@@ -53,7 +53,7 @@
53#include <linux/tty_driver.h> 53#include <linux/tty_driver.h>
54#include <linux/tty_flip.h> 54#include <linux/tty_flip.h>
55#include <linux/module.h> 55#include <linux/module.h>
56#include <asm/uaccess.h> 56#include <linux/uaccess.h>
57#include <asm/unaligned.h> 57#include <asm/unaligned.h>
58#include <linux/usb.h> 58#include <linux/usb.h>
59#include <linux/usb/serial.h> 59#include <linux/usb/serial.h>
@@ -72,33 +72,25 @@ static int debug;
72/* 72/*
73 * Function prototypes 73 * Function prototypes
74 */ 74 */
75static int klsi_105_startup (struct usb_serial *serial); 75static int klsi_105_startup(struct usb_serial *serial);
76static void klsi_105_shutdown (struct usb_serial *serial); 76static void klsi_105_shutdown(struct usb_serial *serial);
77static int klsi_105_open (struct usb_serial_port *port, 77static int klsi_105_open(struct tty_struct *tty,
78 struct file *filp); 78 struct usb_serial_port *port, struct file *filp);
79static void klsi_105_close (struct usb_serial_port *port, 79static void klsi_105_close(struct tty_struct *tty,
80 struct file *filp); 80 struct usb_serial_port *port, struct file *filp);
81static int klsi_105_write (struct usb_serial_port *port, 81static int klsi_105_write(struct tty_struct *tty,
82 const unsigned char *buf, 82 struct usb_serial_port *port, const unsigned char *buf, int count);
83 int count); 83static void klsi_105_write_bulk_callback(struct urb *urb);
84static void klsi_105_write_bulk_callback (struct urb *urb); 84static int klsi_105_chars_in_buffer(struct tty_struct *tty);
85static int klsi_105_chars_in_buffer (struct usb_serial_port *port); 85static int klsi_105_write_room(struct tty_struct *tty);
86static int klsi_105_write_room (struct usb_serial_port *port); 86static void klsi_105_read_bulk_callback(struct urb *urb);
87 87static void klsi_105_set_termios(struct tty_struct *tty,
88static void klsi_105_read_bulk_callback (struct urb *urb); 88 struct usb_serial_port *port, struct ktermios *old);
89static void klsi_105_set_termios (struct usb_serial_port *port, 89static void klsi_105_throttle(struct tty_struct *tty);
90 struct ktermios *old); 90static void klsi_105_unthrottle(struct tty_struct *tty);
91static void klsi_105_throttle (struct usb_serial_port *port); 91static int klsi_105_tiocmget(struct tty_struct *tty, struct file *file);
92static void klsi_105_unthrottle (struct usb_serial_port *port); 92static int klsi_105_tiocmset(struct tty_struct *tty, struct file *file,
93/* 93 unsigned int set, unsigned int clear);
94static void klsi_105_break_ctl (struct usb_serial_port *port,
95 int break_state );
96 */
97static int klsi_105_tiocmget (struct usb_serial_port *port,
98 struct file *file);
99static int klsi_105_tiocmset (struct usb_serial_port *port,
100 struct file *file, unsigned int set,
101 unsigned int clear);
102 94
103/* 95/*
104 * All of the device info needed for the KLSI converters. 96 * All of the device info needed for the KLSI converters.
@@ -109,7 +101,7 @@ static struct usb_device_id id_table [] = {
109 { } /* Terminating entry */ 101 { } /* Terminating entry */
110}; 102};
111 103
112MODULE_DEVICE_TABLE (usb, id_table); 104MODULE_DEVICE_TABLE(usb, id_table);
113 105
114static struct usb_driver kl5kusb105d_driver = { 106static struct usb_driver kl5kusb105d_driver = {
115 .name = "kl5kusb105d", 107 .name = "kl5kusb105d",
@@ -134,7 +126,7 @@ static struct usb_serial_driver kl5kusb105d_device = {
134 .write_bulk_callback = klsi_105_write_bulk_callback, 126 .write_bulk_callback = klsi_105_write_bulk_callback,
135 .chars_in_buffer = klsi_105_chars_in_buffer, 127 .chars_in_buffer = klsi_105_chars_in_buffer,
136 .write_room = klsi_105_write_room, 128 .write_room = klsi_105_write_room,
137 .read_bulk_callback =klsi_105_read_bulk_callback, 129 .read_bulk_callback = klsi_105_read_bulk_callback,
138 .set_termios = klsi_105_set_termios, 130 .set_termios = klsi_105_set_termios,
139 /*.break_ctl = klsi_105_break_ctl,*/ 131 /*.break_ctl = klsi_105_break_ctl,*/
140 .tiocmget = klsi_105_tiocmget, 132 .tiocmget = klsi_105_tiocmget,
@@ -161,7 +153,7 @@ struct klsi_105_private {
161 struct ktermios termios; 153 struct ktermios termios;
162 unsigned long line_state; /* modem line settings */ 154 unsigned long line_state; /* modem line settings */
163 /* write pool */ 155 /* write pool */
164 struct urb * write_urb_pool[NUM_URBS]; 156 struct urb *write_urb_pool[NUM_URBS];
165 spinlock_t lock; 157 spinlock_t lock;
166 unsigned long bytes_in; 158 unsigned long bytes_in;
167 unsigned long bytes_out; 159 unsigned long bytes_out;
@@ -180,15 +172,15 @@ static int klsi_105_chg_port_settings(struct usb_serial_port *port,
180{ 172{
181 int rc; 173 int rc;
182 174
183 rc = usb_control_msg(port->serial->dev, 175 rc = usb_control_msg(port->serial->dev,
184 usb_sndctrlpipe(port->serial->dev, 0), 176 usb_sndctrlpipe(port->serial->dev, 0),
185 KL5KUSB105A_SIO_SET_DATA, 177 KL5KUSB105A_SIO_SET_DATA,
186 USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_INTERFACE, 178 USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_INTERFACE,
187 0, /* value */ 179 0, /* value */
188 0, /* index */ 180 0, /* index */
189 settings, 181 settings,
190 sizeof(struct klsi_105_port_settings), 182 sizeof(struct klsi_105_port_settings),
191 KLSI_TIMEOUT); 183 KLSI_TIMEOUT);
192 if (rc < 0) 184 if (rc < 0)
193 err("Change port settings failed (error = %d)", rc); 185 err("Change port settings failed (error = %d)", rc);
194 info("%s - %d byte block, baudrate %x, databits %d, u1 %d, u2 %d", 186 info("%s - %d byte block, baudrate %x, databits %d, u1 %d, u2 %d",
@@ -196,7 +188,7 @@ static int klsi_105_chg_port_settings(struct usb_serial_port *port,
196 settings->pktlen, 188 settings->pktlen,
197 settings->baudrate, settings->databits, 189 settings->baudrate, settings->databits,
198 settings->unknown1, settings->unknown2); 190 settings->unknown1, settings->unknown2);
199 return rc; 191 return rc;
200} /* klsi_105_chg_port_settings */ 192} /* klsi_105_chg_port_settings */
201 193
202/* translate a 16-bit status value from the device to linux's TIO bits */ 194/* translate a 16-bit status value from the device to linux's TIO bits */
@@ -210,9 +202,9 @@ static unsigned long klsi_105_status2linestate(const __u16 status)
210 202
211 return res; 203 return res;
212} 204}
213/* 205/*
214 * Read line control via vendor command and return result through 206 * Read line control via vendor command and return result through
215 * *line_state_p 207 * *line_state_p
216 */ 208 */
217/* It seems that the status buffer has always only 2 bytes length */ 209/* It seems that the status buffer has always only 2 bytes length */
218#define KLSI_STATUSBUF_LEN 2 210#define KLSI_STATUSBUF_LEN 2
@@ -220,14 +212,14 @@ static int klsi_105_get_line_state(struct usb_serial_port *port,
220 unsigned long *line_state_p) 212 unsigned long *line_state_p)
221{ 213{
222 int rc; 214 int rc;
223 __u8 status_buf[KLSI_STATUSBUF_LEN] = { -1,-1}; 215 __u8 status_buf[KLSI_STATUSBUF_LEN] = { -1, -1};
224 __u16 status; 216 __u16 status;
225 217
226 info("%s - sending SIO Poll request", __func__); 218 info("%s - sending SIO Poll request", __func__);
227 rc = usb_control_msg(port->serial->dev, 219 rc = usb_control_msg(port->serial->dev,
228 usb_rcvctrlpipe(port->serial->dev, 0), 220 usb_rcvctrlpipe(port->serial->dev, 0),
229 KL5KUSB105A_SIO_POLL, 221 KL5KUSB105A_SIO_POLL,
230 USB_TYPE_VENDOR | USB_DIR_IN, 222 USB_TYPE_VENDOR | USB_DIR_IN,
231 0, /* value */ 223 0, /* value */
232 0, /* index */ 224 0, /* index */
233 status_buf, KLSI_STATUSBUF_LEN, 225 status_buf, KLSI_STATUSBUF_LEN,
@@ -243,8 +235,7 @@ static int klsi_105_get_line_state(struct usb_serial_port *port,
243 235
244 *line_state_p = klsi_105_status2linestate(status); 236 *line_state_p = klsi_105_status2linestate(status);
245 } 237 }
246 238 return rc;
247 return rc;
248} 239}
249 240
250 241
@@ -252,7 +243,7 @@ static int klsi_105_get_line_state(struct usb_serial_port *port,
252 * Driver's tty interface functions 243 * Driver's tty interface functions
253 */ 244 */
254 245
255static int klsi_105_startup (struct usb_serial *serial) 246static int klsi_105_startup(struct usb_serial *serial)
256{ 247{
257 struct klsi_105_private *priv; 248 struct klsi_105_private *priv;
258 int i, j; 249 int i, j;
@@ -262,7 +253,7 @@ static int klsi_105_startup (struct usb_serial *serial)
262 */ 253 */
263 254
264 /* allocate the private data structure */ 255 /* allocate the private data structure */
265 for (i=0; i<serial->num_ports; i++) { 256 for (i = 0; i < serial->num_ports; i++) {
266 priv = kmalloc(sizeof(struct klsi_105_private), 257 priv = kmalloc(sizeof(struct klsi_105_private),
267 GFP_KERNEL); 258 GFP_KERNEL);
268 if (!priv) { 259 if (!priv) {
@@ -283,9 +274,9 @@ static int klsi_105_startup (struct usb_serial *serial)
283 priv->bytes_out = 0; 274 priv->bytes_out = 0;
284 usb_set_serial_port_data(serial->port[i], priv); 275 usb_set_serial_port_data(serial->port[i], priv);
285 276
286 spin_lock_init (&priv->lock); 277 spin_lock_init(&priv->lock);
287 for (j=0; j<NUM_URBS; j++) { 278 for (j = 0; j < NUM_URBS; j++) {
288 struct urb* urb = usb_alloc_urb(0, GFP_KERNEL); 279 struct urb *urb = usb_alloc_urb(0, GFP_KERNEL);
289 280
290 priv->write_urb_pool[j] = urb; 281 priv->write_urb_pool[j] = urb;
291 if (urb == NULL) { 282 if (urb == NULL) {
@@ -293,10 +284,11 @@ static int klsi_105_startup (struct usb_serial *serial)
293 goto err_cleanup; 284 goto err_cleanup;
294 } 285 }
295 286
296 urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE, 287 urb->transfer_buffer =
297 GFP_KERNEL); 288 kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL);
298 if (!urb->transfer_buffer) { 289 if (!urb->transfer_buffer) {
299 err("%s - out of memory for urb buffers.", __func__); 290 err("%s - out of memory for urb buffers.",
291 __func__);
300 goto err_cleanup; 292 goto err_cleanup;
301 } 293 }
302 } 294 }
@@ -304,13 +296,13 @@ static int klsi_105_startup (struct usb_serial *serial)
304 /* priv->termios is left uninitalized until port opening */ 296 /* priv->termios is left uninitalized until port opening */
305 init_waitqueue_head(&serial->port[i]->write_wait); 297 init_waitqueue_head(&serial->port[i]->write_wait);
306 } 298 }
307 299
308 return 0; 300 return 0;
309 301
310err_cleanup: 302err_cleanup:
311 for (; i >= 0; i--) { 303 for (; i >= 0; i--) {
312 priv = usb_get_serial_port_data(serial->port[i]); 304 priv = usb_get_serial_port_data(serial->port[i]);
313 for (j=0; j < NUM_URBS; j++) { 305 for (j = 0; j < NUM_URBS; j++) {
314 if (priv->write_urb_pool[j]) { 306 if (priv->write_urb_pool[j]) {
315 kfree(priv->write_urb_pool[j]->transfer_buffer); 307 kfree(priv->write_urb_pool[j]->transfer_buffer);
316 usb_free_urb(priv->write_urb_pool[j]); 308 usb_free_urb(priv->write_urb_pool[j]);
@@ -322,22 +314,23 @@ err_cleanup:
322} /* klsi_105_startup */ 314} /* klsi_105_startup */
323 315
324 316
325static void klsi_105_shutdown (struct usb_serial *serial) 317static void klsi_105_shutdown(struct usb_serial *serial)
326{ 318{
327 int i; 319 int i;
328 320
329 dbg("%s", __func__); 321 dbg("%s", __func__);
330 322
331 /* stop reads and writes on all ports */ 323 /* stop reads and writes on all ports */
332 for (i=0; i < serial->num_ports; ++i) { 324 for (i = 0; i < serial->num_ports; ++i) {
333 struct klsi_105_private *priv = usb_get_serial_port_data(serial->port[i]); 325 struct klsi_105_private *priv =
326 usb_get_serial_port_data(serial->port[i]);
334 unsigned long flags; 327 unsigned long flags;
335 328
336 if (priv) { 329 if (priv) {
337 /* kill our write urb pool */ 330 /* kill our write urb pool */
338 int j; 331 int j;
339 struct urb **write_urbs = priv->write_urb_pool; 332 struct urb **write_urbs = priv->write_urb_pool;
340 spin_lock_irqsave(&priv->lock,flags); 333 spin_lock_irqsave(&priv->lock, flags);
341 334
342 for (j = 0; j < NUM_URBS; j++) { 335 for (j = 0; j < NUM_URBS; j++) {
343 if (write_urbs[j]) { 336 if (write_urbs[j]) {
@@ -349,19 +342,18 @@ static void klsi_105_shutdown (struct usb_serial *serial)
349 * oopses. */ 342 * oopses. */
350 /* usb_kill_urb(write_urbs[j]); */ 343 /* usb_kill_urb(write_urbs[j]); */
351 kfree(write_urbs[j]->transfer_buffer); 344 kfree(write_urbs[j]->transfer_buffer);
352 usb_free_urb (write_urbs[j]); 345 usb_free_urb(write_urbs[j]);
353 } 346 }
354 } 347 }
355 348 spin_unlock_irqrestore(&priv->lock, flags);
356 spin_unlock_irqrestore (&priv->lock, flags);
357
358 kfree(priv); 349 kfree(priv);
359 usb_set_serial_port_data(serial->port[i], NULL); 350 usb_set_serial_port_data(serial->port[i], NULL);
360 } 351 }
361 } 352 }
362} /* klsi_105_shutdown */ 353} /* klsi_105_shutdown */
363 354
364static int klsi_105_open (struct usb_serial_port *port, struct file *filp) 355static int klsi_105_open(struct tty_struct *tty,
356 struct usb_serial_port *port, struct file *filp)
365{ 357{
366 struct klsi_105_private *priv = usb_get_serial_port_data(port); 358 struct klsi_105_private *priv = usb_get_serial_port_data(port);
367 int retval = 0; 359 int retval = 0;
@@ -375,11 +367,11 @@ static int klsi_105_open (struct usb_serial_port *port, struct file *filp)
375 367
376 /* force low_latency on so that our tty_push actually forces 368 /* force low_latency on so that our tty_push actually forces
377 * the data through 369 * the data through
378 * port->tty->low_latency = 1; */ 370 * tty->low_latency = 1; */
379 371
380 /* Do a defined restart: 372 /* Do a defined restart:
381 * Set up sane default baud rate and send the 'READ_ON' 373 * Set up sane default baud rate and send the 'READ_ON'
382 * vendor command. 374 * vendor command.
383 * FIXME: set modem line control (how?) 375 * FIXME: set modem line control (how?)
384 * Then read the modem line control and store values in 376 * Then read the modem line control and store values in
385 * priv->line_state. 377 * priv->line_state.
@@ -390,24 +382,24 @@ static int klsi_105_open (struct usb_serial_port *port, struct file *filp)
390 cfg.unknown1 = 0; 382 cfg.unknown1 = 0;
391 cfg.unknown2 = 1; 383 cfg.unknown2 = 1;
392 klsi_105_chg_port_settings(port, &cfg); 384 klsi_105_chg_port_settings(port, &cfg);
393 385
394 /* set up termios structure */ 386 /* set up termios structure */
395 spin_lock_irqsave (&priv->lock, flags); 387 spin_lock_irqsave(&priv->lock, flags);
396 priv->termios.c_iflag = port->tty->termios->c_iflag; 388 priv->termios.c_iflag = tty->termios->c_iflag;
397 priv->termios.c_oflag = port->tty->termios->c_oflag; 389 priv->termios.c_oflag = tty->termios->c_oflag;
398 priv->termios.c_cflag = port->tty->termios->c_cflag; 390 priv->termios.c_cflag = tty->termios->c_cflag;
399 priv->termios.c_lflag = port->tty->termios->c_lflag; 391 priv->termios.c_lflag = tty->termios->c_lflag;
400 for (i=0; i<NCCS; i++) 392 for (i = 0; i < NCCS; i++)
401 priv->termios.c_cc[i] = port->tty->termios->c_cc[i]; 393 priv->termios.c_cc[i] = tty->termios->c_cc[i];
402 priv->cfg.pktlen = cfg.pktlen; 394 priv->cfg.pktlen = cfg.pktlen;
403 priv->cfg.baudrate = cfg.baudrate; 395 priv->cfg.baudrate = cfg.baudrate;
404 priv->cfg.databits = cfg.databits; 396 priv->cfg.databits = cfg.databits;
405 priv->cfg.unknown1 = cfg.unknown1; 397 priv->cfg.unknown1 = cfg.unknown1;
406 priv->cfg.unknown2 = cfg.unknown2; 398 priv->cfg.unknown2 = cfg.unknown2;
407 spin_unlock_irqrestore (&priv->lock, flags); 399 spin_unlock_irqrestore(&priv->lock, flags);
408 400
409 /* READ_ON and urb submission */ 401 /* READ_ON and urb submission */
410 usb_fill_bulk_urb(port->read_urb, port->serial->dev, 402 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
411 usb_rcvbulkpipe(port->serial->dev, 403 usb_rcvbulkpipe(port->serial->dev,
412 port->bulk_in_endpointAddress), 404 port->bulk_in_endpointAddress),
413 port->read_urb->transfer_buffer, 405 port->read_urb->transfer_buffer,
@@ -423,7 +415,7 @@ static int klsi_105_open (struct usb_serial_port *port, struct file *filp)
423 } 415 }
424 416
425 rc = usb_control_msg(port->serial->dev, 417 rc = usb_control_msg(port->serial->dev,
426 usb_sndctrlpipe(port->serial->dev,0), 418 usb_sndctrlpipe(port->serial->dev, 0),
427 KL5KUSB105A_SIO_CONFIGURE, 419 KL5KUSB105A_SIO_CONFIGURE,
428 USB_TYPE_VENDOR|USB_DIR_OUT|USB_RECIP_INTERFACE, 420 USB_TYPE_VENDOR|USB_DIR_OUT|USB_RECIP_INTERFACE,
429 KL5KUSB105A_SIO_CONFIGURE_READ_ON, 421 KL5KUSB105A_SIO_CONFIGURE_READ_ON,
@@ -434,14 +426,14 @@ static int klsi_105_open (struct usb_serial_port *port, struct file *filp)
434 if (rc < 0) { 426 if (rc < 0) {
435 err("Enabling read failed (error = %d)", rc); 427 err("Enabling read failed (error = %d)", rc);
436 retval = rc; 428 retval = rc;
437 } else 429 } else
438 dbg("%s - enabled reading", __func__); 430 dbg("%s - enabled reading", __func__);
439 431
440 rc = klsi_105_get_line_state(port, &line_state); 432 rc = klsi_105_get_line_state(port, &line_state);
441 if (rc >= 0) { 433 if (rc >= 0) {
442 spin_lock_irqsave (&priv->lock, flags); 434 spin_lock_irqsave(&priv->lock, flags);
443 priv->line_state = line_state; 435 priv->line_state = line_state;
444 spin_unlock_irqrestore (&priv->lock, flags); 436 spin_unlock_irqrestore(&priv->lock, flags);
445 dbg("%s - read line state 0x%lx", __func__, line_state); 437 dbg("%s - read line state 0x%lx", __func__, line_state);
446 retval = 0; 438 retval = 0;
447 } else 439 } else
@@ -452,7 +444,8 @@ exit:
452} /* klsi_105_open */ 444} /* klsi_105_open */
453 445
454 446
455static void klsi_105_close (struct usb_serial_port *port, struct file *filp) 447static void klsi_105_close(struct tty_struct *tty,
448 struct usb_serial_port *port, struct file *filp)
456{ 449{
457 struct klsi_105_private *priv = usb_get_serial_port_data(port); 450 struct klsi_105_private *priv = usb_get_serial_port_data(port);
458 int rc; 451 int rc;
@@ -462,14 +455,14 @@ static void klsi_105_close (struct usb_serial_port *port, struct file *filp)
462 mutex_lock(&port->serial->disc_mutex); 455 mutex_lock(&port->serial->disc_mutex);
463 if (!port->serial->disconnected) { 456 if (!port->serial->disconnected) {
464 /* send READ_OFF */ 457 /* send READ_OFF */
465 rc = usb_control_msg (port->serial->dev, 458 rc = usb_control_msg(port->serial->dev,
466 usb_sndctrlpipe(port->serial->dev, 0), 459 usb_sndctrlpipe(port->serial->dev, 0),
467 KL5KUSB105A_SIO_CONFIGURE, 460 KL5KUSB105A_SIO_CONFIGURE,
468 USB_TYPE_VENDOR | USB_DIR_OUT, 461 USB_TYPE_VENDOR | USB_DIR_OUT,
469 KL5KUSB105A_SIO_CONFIGURE_READ_OFF, 462 KL5KUSB105A_SIO_CONFIGURE_READ_OFF,
470 0, /* index */ 463 0, /* index */
471 NULL, 0, 464 NULL, 0,
472 KLSI_TIMEOUT); 465 KLSI_TIMEOUT);
473 if (rc < 0) 466 if (rc < 0)
474 err("Disabling read failed (error = %d)", rc); 467 err("Disabling read failed (error = %d)", rc);
475 } 468 }
@@ -482,23 +475,24 @@ static void klsi_105_close (struct usb_serial_port *port, struct file *filp)
482 /* FIXME */ 475 /* FIXME */
483 /* wgg - do I need this? I think so. */ 476 /* wgg - do I need this? I think so. */
484 usb_kill_urb(port->interrupt_in_urb); 477 usb_kill_urb(port->interrupt_in_urb);
485 info("kl5kusb105 port stats: %ld bytes in, %ld bytes out", priv->bytes_in, priv->bytes_out); 478 info("kl5kusb105 port stats: %ld bytes in, %ld bytes out",
479 priv->bytes_in, priv->bytes_out);
486} /* klsi_105_close */ 480} /* klsi_105_close */
487 481
488 482
489/* We need to write a complete 64-byte data block and encode the 483/* We need to write a complete 64-byte data block and encode the
490 * number actually sent in the first double-byte, LSB-order. That 484 * number actually sent in the first double-byte, LSB-order. That
491 * leaves at most 62 bytes of payload. 485 * leaves at most 62 bytes of payload.
492 */ 486 */
493#define KLSI_105_DATA_OFFSET 2 /* in the bulk urb data block */ 487#define KLSI_105_DATA_OFFSET 2 /* in the bulk urb data block */
494 488
495 489
496static int klsi_105_write (struct usb_serial_port *port, 490static int klsi_105_write(struct tty_struct *tty,
497 const unsigned char *buf, int count) 491 struct usb_serial_port *port, const unsigned char *buf, int count)
498{ 492{
499 struct klsi_105_private *priv = usb_get_serial_port_data(port); 493 struct klsi_105_private *priv = usb_get_serial_port_data(port);
500 int result, size; 494 int result, size;
501 int bytes_sent=0; 495 int bytes_sent = 0;
502 496
503 dbg("%s - port %d", __func__, port->number); 497 dbg("%s - port %d", __func__, port->number);
504 498
@@ -507,34 +501,37 @@ static int klsi_105_write (struct usb_serial_port *port,
507 struct urb *urb = NULL; 501 struct urb *urb = NULL;
508 unsigned long flags; 502 unsigned long flags;
509 int i; 503 int i;
510 /* since the pool is per-port we might not need the spin lock !? */ 504 /* since the pool is per-port we might not need
511 spin_lock_irqsave (&priv->lock, flags); 505 the spin lock !? */
512 for (i=0; i<NUM_URBS; i++) { 506 spin_lock_irqsave(&priv->lock, flags);
507 for (i = 0; i < NUM_URBS; i++) {
513 if (priv->write_urb_pool[i]->status != -EINPROGRESS) { 508 if (priv->write_urb_pool[i]->status != -EINPROGRESS) {
514 urb = priv->write_urb_pool[i]; 509 urb = priv->write_urb_pool[i];
515 dbg("%s - using pool URB %d", __func__, i); 510 dbg("%s - using pool URB %d", __func__, i);
516 break; 511 break;
517 } 512 }
518 } 513 }
519 spin_unlock_irqrestore (&priv->lock, flags); 514 spin_unlock_irqrestore(&priv->lock, flags);
520 515
521 if (urb==NULL) { 516 if (urb == NULL) {
522 dbg("%s - no more free urbs", __func__); 517 dbg("%s - no more free urbs", __func__);
523 goto exit; 518 goto exit;
524 } 519 }
525 520
526 if (urb->transfer_buffer == NULL) { 521 if (urb->transfer_buffer == NULL) {
527 urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE, GFP_ATOMIC); 522 urb->transfer_buffer =
523 kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_ATOMIC);
528 if (urb->transfer_buffer == NULL) { 524 if (urb->transfer_buffer == NULL) {
529 err("%s - no more kernel memory...", __func__); 525 err("%s - no more kernel memory...", __func__);
530 goto exit; 526 goto exit;
531 } 527 }
532 } 528 }
533 529
534 size = min (count, port->bulk_out_size - KLSI_105_DATA_OFFSET); 530 size = min(count, port->bulk_out_size - KLSI_105_DATA_OFFSET);
535 size = min (size, URB_TRANSFER_BUFFER_SIZE - KLSI_105_DATA_OFFSET); 531 size = min(size, URB_TRANSFER_BUFFER_SIZE -
532 KLSI_105_DATA_OFFSET);
536 533
537 memcpy (urb->transfer_buffer + KLSI_105_DATA_OFFSET, buf, size); 534 memcpy(urb->transfer_buffer + KLSI_105_DATA_OFFSET, buf, size);
538 535
539 /* write payload size into transfer buffer */ 536 /* write payload size into transfer buffer */
540 ((__u8 *)urb->transfer_buffer)[0] = (__u8) (size & 0xFF); 537 ((__u8 *)urb->transfer_buffer)[0] = (__u8) (size & 0xFF);
@@ -552,7 +549,8 @@ static int klsi_105_write (struct usb_serial_port *port,
552 /* send the data out the bulk port */ 549 /* send the data out the bulk port */
553 result = usb_submit_urb(urb, GFP_ATOMIC); 550 result = usb_submit_urb(urb, GFP_ATOMIC);
554 if (result) { 551 if (result) {
555 err("%s - failed submitting write urb, error %d", __func__, result); 552 err("%s - failed submitting write urb, error %d",
553 __func__, result);
556 goto exit; 554 goto exit;
557 } 555 }
558 buf += size; 556 buf += size;
@@ -561,12 +559,12 @@ static int klsi_105_write (struct usb_serial_port *port,
561 } 559 }
562exit: 560exit:
563 /* lockless, but it's for debug info only... */ 561 /* lockless, but it's for debug info only... */
564 priv->bytes_out+=bytes_sent; 562 priv->bytes_out += bytes_sent;
565 563
566 return bytes_sent; /* that's how much we wrote */ 564 return bytes_sent; /* that's how much we wrote */
567} /* klsi_105_write */ 565} /* klsi_105_write */
568 566
569static void klsi_105_write_bulk_callback ( struct urb *urb) 567static void klsi_105_write_bulk_callback(struct urb *urb)
570{ 568{
571 struct usb_serial_port *port = urb->context; 569 struct usb_serial_port *port = urb->context;
572 int status = urb->status; 570 int status = urb->status;
@@ -584,50 +582,50 @@ static void klsi_105_write_bulk_callback ( struct urb *urb)
584 582
585 583
586/* return number of characters currently in the writing process */ 584/* return number of characters currently in the writing process */
587static int klsi_105_chars_in_buffer (struct usb_serial_port *port) 585static int klsi_105_chars_in_buffer(struct tty_struct *tty)
588{ 586{
587 struct usb_serial_port *port = tty->driver_data;
589 int chars = 0; 588 int chars = 0;
590 int i; 589 int i;
591 unsigned long flags; 590 unsigned long flags;
592 struct klsi_105_private *priv = usb_get_serial_port_data(port); 591 struct klsi_105_private *priv = usb_get_serial_port_data(port);
593 592
594 spin_lock_irqsave (&priv->lock, flags); 593 spin_lock_irqsave(&priv->lock, flags);
595 594
596 for (i = 0; i < NUM_URBS; ++i) { 595 for (i = 0; i < NUM_URBS; ++i) {
597 if (priv->write_urb_pool[i]->status == -EINPROGRESS) { 596 if (priv->write_urb_pool[i]->status == -EINPROGRESS)
598 chars += URB_TRANSFER_BUFFER_SIZE; 597 chars += URB_TRANSFER_BUFFER_SIZE;
599 }
600 } 598 }
601 599
602 spin_unlock_irqrestore (&priv->lock, flags); 600 spin_unlock_irqrestore(&priv->lock, flags);
603 601
604 dbg("%s - returns %d", __func__, chars); 602 dbg("%s - returns %d", __func__, chars);
605 return (chars); 603 return chars;
606} 604}
607 605
608static int klsi_105_write_room (struct usb_serial_port *port) 606static int klsi_105_write_room(struct tty_struct *tty)
609{ 607{
608 struct usb_serial_port *port = tty->driver_data;
610 unsigned long flags; 609 unsigned long flags;
611 int i; 610 int i;
612 int room = 0; 611 int room = 0;
613 struct klsi_105_private *priv = usb_get_serial_port_data(port); 612 struct klsi_105_private *priv = usb_get_serial_port_data(port);
614 613
615 spin_lock_irqsave (&priv->lock, flags); 614 spin_lock_irqsave(&priv->lock, flags);
616 for (i = 0; i < NUM_URBS; ++i) { 615 for (i = 0; i < NUM_URBS; ++i) {
617 if (priv->write_urb_pool[i]->status != -EINPROGRESS) { 616 if (priv->write_urb_pool[i]->status != -EINPROGRESS)
618 room += URB_TRANSFER_BUFFER_SIZE; 617 room += URB_TRANSFER_BUFFER_SIZE;
619 }
620 } 618 }
621 619
622 spin_unlock_irqrestore (&priv->lock, flags); 620 spin_unlock_irqrestore(&priv->lock, flags);
623 621
624 dbg("%s - returns %d", __func__, room); 622 dbg("%s - returns %d", __func__, room);
625 return (room); 623 return room;
626} 624}
627 625
628 626
629 627
630static void klsi_105_read_bulk_callback (struct urb *urb) 628static void klsi_105_read_bulk_callback(struct urb *urb)
631{ 629{
632 struct usb_serial_port *port = urb->context; 630 struct usb_serial_port *port = urb->context;
633 struct klsi_105_private *priv = usb_get_serial_port_data(port); 631 struct klsi_105_private *priv = usb_get_serial_port_data(port);
@@ -660,13 +658,13 @@ static void klsi_105_read_bulk_callback (struct urb *urb)
660 } else { 658 } else {
661 int bytes_sent = ((__u8 *) data)[0] + 659 int bytes_sent = ((__u8 *) data)[0] +
662 ((unsigned int) ((__u8 *) data)[1] << 8); 660 ((unsigned int) ((__u8 *) data)[1] << 8);
663 tty = port->tty; 661 tty = port->port.tty;
664 /* we should immediately resubmit the URB, before attempting 662 /* we should immediately resubmit the URB, before attempting
665 * to pass the data on to the tty layer. But that needs locking 663 * to pass the data on to the tty layer. But that needs locking
666 * against re-entry an then mixed-up data because of 664 * against re-entry an then mixed-up data because of
667 * intermixed tty_flip_buffer_push()s 665 * intermixed tty_flip_buffer_push()s
668 * FIXME 666 * FIXME
669 */ 667 */
670 usb_serial_debug_data(debug, &port->dev, __func__, 668 usb_serial_debug_data(debug, &port->dev, __func__,
671 urb->actual_length, data); 669 urb->actual_length, data);
672 670
@@ -686,7 +684,7 @@ static void klsi_105_read_bulk_callback (struct urb *urb)
686 priv->bytes_in += bytes_sent; 684 priv->bytes_in += bytes_sent;
687 } 685 }
688 /* Continue trying to always read */ 686 /* Continue trying to always read */
689 usb_fill_bulk_urb(port->read_urb, port->serial->dev, 687 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
690 usb_rcvbulkpipe(port->serial->dev, 688 usb_rcvbulkpipe(port->serial->dev,
691 port->bulk_in_endpointAddress), 689 port->bulk_in_endpointAddress),
692 port->read_urb->transfer_buffer, 690 port->read_urb->transfer_buffer,
@@ -695,15 +693,16 @@ static void klsi_105_read_bulk_callback (struct urb *urb)
695 port); 693 port);
696 rc = usb_submit_urb(port->read_urb, GFP_ATOMIC); 694 rc = usb_submit_urb(port->read_urb, GFP_ATOMIC);
697 if (rc) 695 if (rc)
698 err("%s - failed resubmitting read urb, error %d", __func__, rc); 696 err("%s - failed resubmitting read urb, error %d",
697 __func__, rc);
699} /* klsi_105_read_bulk_callback */ 698} /* klsi_105_read_bulk_callback */
700 699
701 700
702static void klsi_105_set_termios (struct usb_serial_port *port, 701static void klsi_105_set_termios(struct tty_struct *tty,
703 struct ktermios *old_termios) 702 struct usb_serial_port *port,
703 struct ktermios *old_termios)
704{ 704{
705 struct klsi_105_private *priv = usb_get_serial_port_data(port); 705 struct klsi_105_private *priv = usb_get_serial_port_data(port);
706 struct tty_struct *tty = port->tty;
707 unsigned int iflag = tty->termios->c_iflag; 706 unsigned int iflag = tty->termios->c_iflag;
708 unsigned int old_iflag = old_termios->c_iflag; 707 unsigned int old_iflag = old_termios->c_iflag;
709 unsigned int cflag = tty->termios->c_cflag; 708 unsigned int cflag = tty->termios->c_cflag;
@@ -711,65 +710,63 @@ static void klsi_105_set_termios (struct usb_serial_port *port,
711 struct klsi_105_port_settings cfg; 710 struct klsi_105_port_settings cfg;
712 unsigned long flags; 711 unsigned long flags;
713 speed_t baud; 712 speed_t baud;
714 713
715 /* lock while we are modifying the settings */ 714 /* lock while we are modifying the settings */
716 spin_lock_irqsave (&priv->lock, flags); 715 spin_lock_irqsave(&priv->lock, flags);
717 716
718 /* 717 /*
719 * Update baud rate 718 * Update baud rate
720 */ 719 */
721 baud = tty_get_baud_rate(tty); 720 baud = tty_get_baud_rate(tty);
722 721
723 if( (cflag & CBAUD) != (old_cflag & CBAUD) ) { 722 if ((cflag & CBAUD) != (old_cflag & CBAUD)) {
724 /* reassert DTR and (maybe) RTS on transition from B0 */ 723 /* reassert DTR and (maybe) RTS on transition from B0 */
725 if( (old_cflag & CBAUD) == B0 ) { 724 if ((old_cflag & CBAUD) == B0) {
726 dbg("%s: baud was B0", __func__); 725 dbg("%s: baud was B0", __func__);
727#if 0 726#if 0
728 priv->control_state |= TIOCM_DTR; 727 priv->control_state |= TIOCM_DTR;
729 /* don't set RTS if using hardware flow control */ 728 /* don't set RTS if using hardware flow control */
730 if (!(old_cflag & CRTSCTS)) { 729 if (!(old_cflag & CRTSCTS))
731 priv->control_state |= TIOCM_RTS; 730 priv->control_state |= TIOCM_RTS;
732 }
733 mct_u232_set_modem_ctrl(serial, priv->control_state); 731 mct_u232_set_modem_ctrl(serial, priv->control_state);
734#endif 732#endif
735 } 733 }
736 } 734 }
737 switch(baud) { 735 switch (baud) {
738 case 0: /* handled below */ 736 case 0: /* handled below */
739 break; 737 break;
740 case 1200: 738 case 1200:
741 priv->cfg.baudrate = kl5kusb105a_sio_b1200; 739 priv->cfg.baudrate = kl5kusb105a_sio_b1200;
742 break; 740 break;
743 case 2400: 741 case 2400:
744 priv->cfg.baudrate = kl5kusb105a_sio_b2400; 742 priv->cfg.baudrate = kl5kusb105a_sio_b2400;
745 break; 743 break;
746 case 4800: 744 case 4800:
747 priv->cfg.baudrate = kl5kusb105a_sio_b4800; 745 priv->cfg.baudrate = kl5kusb105a_sio_b4800;
748 break; 746 break;
749 case 9600: 747 case 9600:
750 priv->cfg.baudrate = kl5kusb105a_sio_b9600; 748 priv->cfg.baudrate = kl5kusb105a_sio_b9600;
751 break; 749 break;
752 case 19200: 750 case 19200:
753 priv->cfg.baudrate = kl5kusb105a_sio_b19200; 751 priv->cfg.baudrate = kl5kusb105a_sio_b19200;
754 break; 752 break;
755 case 38400: 753 case 38400:
756 priv->cfg.baudrate = kl5kusb105a_sio_b38400; 754 priv->cfg.baudrate = kl5kusb105a_sio_b38400;
757 break; 755 break;
758 case 57600: 756 case 57600:
759 priv->cfg.baudrate = kl5kusb105a_sio_b57600; 757 priv->cfg.baudrate = kl5kusb105a_sio_b57600;
760 break; 758 break;
761 case 115200: 759 case 115200:
762 priv->cfg.baudrate = kl5kusb105a_sio_b115200; 760 priv->cfg.baudrate = kl5kusb105a_sio_b115200;
763 break; 761 break;
764 default: 762 default:
765 dbg("KLSI USB->Serial converter:" 763 dbg("KLSI USB->Serial converter:"
766 " unsupported baudrate request, using default" 764 " unsupported baudrate request, using default of 9600");
767 " of 9600");
768 priv->cfg.baudrate = kl5kusb105a_sio_b9600; 765 priv->cfg.baudrate = kl5kusb105a_sio_b9600;
769 baud = 9600; 766 baud = 9600;
770 break; 767 break;
771 } 768 }
772 if ((cflag & CBAUD) == B0 ) { 769 if ((cflag & CBAUD) == B0) {
773 dbg("%s: baud is B0", __func__); 770 dbg("%s: baud is B0", __func__);
774 /* Drop RTS and DTR */ 771 /* Drop RTS and DTR */
775 /* maybe this should be simulated by sending read 772 /* maybe this should be simulated by sending read
@@ -778,7 +775,7 @@ static void klsi_105_set_termios (struct usb_serial_port *port,
778 ; 775 ;
779#if 0 776#if 0
780 priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS); 777 priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
781 mct_u232_set_modem_ctrl(serial, priv->control_state); 778 mct_u232_set_modem_ctrl(serial, priv->control_state);
782#endif 779#endif
783 } 780 }
784 tty_encode_baud_rate(tty, baud, baud); 781 tty_encode_baud_rate(tty, baud, baud);
@@ -788,11 +785,11 @@ static void klsi_105_set_termios (struct usb_serial_port *port,
788 switch (cflag & CSIZE) { 785 switch (cflag & CSIZE) {
789 case CS5: 786 case CS5:
790 dbg("%s - 5 bits/byte not supported", __func__); 787 dbg("%s - 5 bits/byte not supported", __func__);
791 spin_unlock_irqrestore (&priv->lock, flags); 788 spin_unlock_irqrestore(&priv->lock, flags);
792 return ; 789 return ;
793 case CS6: 790 case CS6:
794 dbg("%s - 6 bits/byte not supported", __func__); 791 dbg("%s - 6 bits/byte not supported", __func__);
795 spin_unlock_irqrestore (&priv->lock, flags); 792 spin_unlock_irqrestore(&priv->lock, flags);
796 return ; 793 return ;
797 case CS7: 794 case CS7:
798 priv->cfg.databits = kl5kusb105a_dtb_7; 795 priv->cfg.databits = kl5kusb105a_dtb_7;
@@ -811,8 +808,7 @@ static void klsi_105_set_termios (struct usb_serial_port *port,
811 * Update line control register (LCR) 808 * Update line control register (LCR)
812 */ 809 */
813 if ((cflag & (PARENB|PARODD)) != (old_cflag & (PARENB|PARODD)) 810 if ((cflag & (PARENB|PARODD)) != (old_cflag & (PARENB|PARODD))
814 || (cflag & CSTOPB) != (old_cflag & CSTOPB) ) { 811 || (cflag & CSTOPB) != (old_cflag & CSTOPB)) {
815
816 /* Not currently supported */ 812 /* Not currently supported */
817 tty->termios->c_cflag &= ~(PARENB|PARODD|CSTOPB); 813 tty->termios->c_cflag &= ~(PARENB|PARODD|CSTOPB);
818#if 0 814#if 0
@@ -833,20 +829,18 @@ static void klsi_105_set_termios (struct usb_serial_port *port,
833#endif 829#endif
834 ; 830 ;
835 } 831 }
836
837 /* 832 /*
838 * Set flow control: well, I do not really now how to handle DTR/RTS. 833 * Set flow control: well, I do not really now how to handle DTR/RTS.
839 * Just do what we have seen with SniffUSB on Win98. 834 * Just do what we have seen with SniffUSB on Win98.
840 */ 835 */
841 if( (iflag & IXOFF) != (old_iflag & IXOFF) 836 if ((iflag & IXOFF) != (old_iflag & IXOFF)
842 || (iflag & IXON) != (old_iflag & IXON) 837 || (iflag & IXON) != (old_iflag & IXON)
843 || (cflag & CRTSCTS) != (old_cflag & CRTSCTS) ) { 838 || (cflag & CRTSCTS) != (old_cflag & CRTSCTS)) {
844
845 /* Not currently supported */ 839 /* Not currently supported */
846 tty->termios->c_cflag &= ~CRTSCTS; 840 tty->termios->c_cflag &= ~CRTSCTS;
847 /* Drop DTR/RTS if no flow control otherwise assert */ 841 /* Drop DTR/RTS if no flow control otherwise assert */
848#if 0 842#if 0
849 if ((iflag & IXOFF) || (iflag & IXON) || (cflag & CRTSCTS) ) 843 if ((iflag & IXOFF) || (iflag & IXON) || (cflag & CRTSCTS))
850 priv->control_state |= TIOCM_DTR | TIOCM_RTS; 844 priv->control_state |= TIOCM_DTR | TIOCM_RTS;
851 else 845 else
852 priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS); 846 priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
@@ -854,19 +848,21 @@ static void klsi_105_set_termios (struct usb_serial_port *port,
854#endif 848#endif
855 ; 849 ;
856 } 850 }
857 memcpy (&cfg, &priv->cfg, sizeof(cfg)); 851 memcpy(&cfg, &priv->cfg, sizeof(cfg));
858 spin_unlock_irqrestore (&priv->lock, flags); 852 spin_unlock_irqrestore(&priv->lock, flags);
859 853
860 /* now commit changes to device */ 854 /* now commit changes to device */
861 klsi_105_chg_port_settings(port, &cfg); 855 klsi_105_chg_port_settings(port, &cfg);
862} /* klsi_105_set_termios */ 856} /* klsi_105_set_termios */
863 857
864 858
865#if 0 859#if 0
866static void mct_u232_break_ctl( struct usb_serial_port *port, int break_state ) 860static void mct_u232_break_ctl(struct tty_struct *tty, int break_state)
867{ 861{
862 struct usb_serial_port *port = tty->driver_data;
868 struct usb_serial *serial = port->serial; 863 struct usb_serial *serial = port->serial;
869 struct mct_u232_private *priv = (struct mct_u232_private *)port->private; 864 struct mct_u232_private *priv =
865 (struct mct_u232_private *)port->private;
870 unsigned char lcr = priv->last_lcr; 866 unsigned char lcr = priv->last_lcr;
871 867
872 dbg("%sstate=%d", __func__, break_state); 868 dbg("%sstate=%d", __func__, break_state);
@@ -878,8 +874,9 @@ static void mct_u232_break_ctl( struct usb_serial_port *port, int break_state )
878} /* mct_u232_break_ctl */ 874} /* mct_u232_break_ctl */
879#endif 875#endif
880 876
881static int klsi_105_tiocmget (struct usb_serial_port *port, struct file *file) 877static int klsi_105_tiocmget(struct tty_struct *tty, struct file *file)
882{ 878{
879 struct usb_serial_port *port = tty->driver_data;
883 struct klsi_105_private *priv = usb_get_serial_port_data(port); 880 struct klsi_105_private *priv = usb_get_serial_port_data(port);
884 unsigned long flags; 881 unsigned long flags;
885 int rc; 882 int rc;
@@ -893,18 +890,18 @@ static int klsi_105_tiocmget (struct usb_serial_port *port, struct file *file)
893 return rc; 890 return rc;
894 } 891 }
895 892
896 spin_lock_irqsave (&priv->lock, flags); 893 spin_lock_irqsave(&priv->lock, flags);
897 priv->line_state = line_state; 894 priv->line_state = line_state;
898 spin_unlock_irqrestore (&priv->lock, flags); 895 spin_unlock_irqrestore(&priv->lock, flags);
899 dbg("%s - read line state 0x%lx", __func__, line_state); 896 dbg("%s - read line state 0x%lx", __func__, line_state);
900 return (int)line_state; 897 return (int)line_state;
901} 898}
902 899
903static int klsi_105_tiocmset (struct usb_serial_port *port, struct file *file, 900static int klsi_105_tiocmset(struct tty_struct *tty, struct file *file,
904 unsigned int set, unsigned int clear) 901 unsigned int set, unsigned int clear)
905{ 902{
906 int retval = -EINVAL; 903 int retval = -EINVAL;
907 904
908 dbg("%s", __func__); 905 dbg("%s", __func__);
909 906
910/* if this ever gets implemented, it should be done something like this: 907/* if this ever gets implemented, it should be done something like this:
@@ -929,14 +926,16 @@ static int klsi_105_tiocmset (struct usb_serial_port *port, struct file *file,
929 return retval; 926 return retval;
930} 927}
931 928
932static void klsi_105_throttle (struct usb_serial_port *port) 929static void klsi_105_throttle(struct tty_struct *tty)
933{ 930{
931 struct usb_serial_port *port = tty->driver_data;
934 dbg("%s - port %d", __func__, port->number); 932 dbg("%s - port %d", __func__, port->number);
935 usb_kill_urb(port->read_urb); 933 usb_kill_urb(port->read_urb);
936} 934}
937 935
938static void klsi_105_unthrottle (struct usb_serial_port *port) 936static void klsi_105_unthrottle(struct tty_struct *tty)
939{ 937{
938 struct usb_serial_port *port = tty->driver_data;
940 int result; 939 int result;
941 940
942 dbg("%s - port %d", __func__, port->number); 941 dbg("%s - port %d", __func__, port->number);
@@ -950,7 +949,7 @@ static void klsi_105_unthrottle (struct usb_serial_port *port)
950 949
951 950
952 951
953static int __init klsi_105_init (void) 952static int __init klsi_105_init(void)
954{ 953{
955 int retval; 954 int retval;
956 retval = usb_serial_register(&kl5kusb105d_device); 955 retval = usb_serial_register(&kl5kusb105d_device);
@@ -969,19 +968,19 @@ failed_usb_serial_register:
969} 968}
970 969
971 970
972static void __exit klsi_105_exit (void) 971static void __exit klsi_105_exit(void)
973{ 972{
974 usb_deregister (&kl5kusb105d_driver); 973 usb_deregister(&kl5kusb105d_driver);
975 usb_serial_deregister (&kl5kusb105d_device); 974 usb_serial_deregister(&kl5kusb105d_device);
976} 975}
977 976
978 977
979module_init (klsi_105_init); 978module_init(klsi_105_init);
980module_exit (klsi_105_exit); 979module_exit(klsi_105_exit);
981 980
982MODULE_AUTHOR( DRIVER_AUTHOR ); 981MODULE_AUTHOR(DRIVER_AUTHOR);
983MODULE_DESCRIPTION( DRIVER_DESC ); 982MODULE_DESCRIPTION(DRIVER_DESC);
984MODULE_LICENSE("GPL"); 983MODULE_LICENSE("GPL");
985 984
986 985
987module_param(debug, bool, S_IRUGO | S_IWUSR); 986module_param(debug, bool, S_IRUGO | S_IWUSR);
diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c
index 693f00da7c03..deba28ec77e8 100644
--- a/drivers/usb/serial/kobil_sct.c
+++ b/drivers/usb/serial/kobil_sct.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * KOBIL USB Smart Card Terminal Driver 2 * KOBIL USB Smart Card Terminal Driver
3 * 3 *
4 * Copyright (C) 2002 KOBIL Systems GmbH 4 * Copyright (C) 2002 KOBIL Systems GmbH
5 * Author: Thomas Wahrenbruch 5 * Author: Thomas Wahrenbruch
6 * 6 *
7 * Contact: linuxusb@kobil.de 7 * Contact: linuxusb@kobil.de
@@ -20,7 +20,7 @@
20 * 20 *
21 * Supported readers: USB TWIN, KAAN Standard Plus and SecOVID Reader Plus 21 * Supported readers: USB TWIN, KAAN Standard Plus and SecOVID Reader Plus
22 * (Adapter K), B1 Professional and KAAN Professional (Adapter B) 22 * (Adapter K), B1 Professional and KAAN Professional (Adapter B)
23 * 23 *
24 * (21/05/2004) tw 24 * (21/05/2004) tw
25 * Fix bug with P'n'P readers 25 * Fix bug with P'n'P readers
26 * 26 *
@@ -44,7 +44,7 @@
44#include <linux/tty_flip.h> 44#include <linux/tty_flip.h>
45#include <linux/module.h> 45#include <linux/module.h>
46#include <linux/spinlock.h> 46#include <linux/spinlock.h>
47#include <asm/uaccess.h> 47#include <linux/uaccess.h>
48#include <linux/usb.h> 48#include <linux/usb.h>
49#include <linux/usb/serial.h> 49#include <linux/usb/serial.h>
50#include <linux/ioctl.h> 50#include <linux/ioctl.h>
@@ -68,21 +68,24 @@ static int debug;
68 68
69 69
70/* Function prototypes */ 70/* Function prototypes */
71static int kobil_startup (struct usb_serial *serial); 71static int kobil_startup(struct usb_serial *serial);
72static void kobil_shutdown (struct usb_serial *serial); 72static void kobil_shutdown(struct usb_serial *serial);
73static int kobil_open (struct usb_serial_port *port, struct file *filp); 73static int kobil_open(struct tty_struct *tty,
74static void kobil_close (struct usb_serial_port *port, struct file *filp); 74 struct usb_serial_port *port, struct file *filp);
75static int kobil_write (struct usb_serial_port *port, 75static void kobil_close(struct tty_struct *tty, struct usb_serial_port *port,
76 struct file *filp);
77static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port,
76 const unsigned char *buf, int count); 78 const unsigned char *buf, int count);
77static int kobil_write_room(struct usb_serial_port *port); 79static int kobil_write_room(struct tty_struct *tty);
78static int kobil_ioctl(struct usb_serial_port *port, struct file *file, 80static int kobil_ioctl(struct tty_struct *tty, struct file *file,
79 unsigned int cmd, unsigned long arg); 81 unsigned int cmd, unsigned long arg);
80static int kobil_tiocmget(struct usb_serial_port *port, struct file *file); 82static int kobil_tiocmget(struct tty_struct *tty, struct file *file);
81static int kobil_tiocmset(struct usb_serial_port *port, struct file *file, 83static int kobil_tiocmset(struct tty_struct *tty, struct file *file,
82 unsigned int set, unsigned int clear); 84 unsigned int set, unsigned int clear);
83static void kobil_read_int_callback( struct urb *urb ); 85static void kobil_read_int_callback(struct urb *urb);
84static void kobil_write_callback( struct urb *purb ); 86static void kobil_write_callback(struct urb *purb);
85static void kobil_set_termios(struct usb_serial_port *port, struct ktermios *old); 87static void kobil_set_termios(struct tty_struct *tty,
88 struct usb_serial_port *port, struct ktermios *old);
86 89
87 90
88static struct usb_device_id id_table [] = { 91static struct usb_device_id id_table [] = {
@@ -94,7 +97,7 @@ static struct usb_device_id id_table [] = {
94}; 97};
95 98
96 99
97MODULE_DEVICE_TABLE (usb, id_table); 100MODULE_DEVICE_TABLE(usb, id_table);
98 101
99static struct usb_driver kobil_driver = { 102static struct usb_driver kobil_driver = {
100 .name = "kobil", 103 .name = "kobil",
@@ -131,14 +134,14 @@ static struct usb_serial_driver kobil_device = {
131struct kobil_private { 134struct kobil_private {
132 int write_int_endpoint_address; 135 int write_int_endpoint_address;
133 int read_int_endpoint_address; 136 int read_int_endpoint_address;
134 unsigned char buf[KOBIL_BUF_LENGTH]; // buffer for the APDU to send 137 unsigned char buf[KOBIL_BUF_LENGTH]; /* buffer for the APDU to send */
135 int filled; // index of the last char in buf 138 int filled; /* index of the last char in buf */
136 int cur_pos; // index of the next char to send in buf 139 int cur_pos; /* index of the next char to send in buf */
137 __u16 device_type; 140 __u16 device_type;
138}; 141};
139 142
140 143
141static int kobil_startup (struct usb_serial *serial) 144static int kobil_startup(struct usb_serial *serial)
142{ 145{
143 int i; 146 int i;
144 struct kobil_private *priv; 147 struct kobil_private *priv;
@@ -149,20 +152,20 @@ static int kobil_startup (struct usb_serial *serial)
149 struct usb_host_endpoint *endpoint; 152 struct usb_host_endpoint *endpoint;
150 153
151 priv = kmalloc(sizeof(struct kobil_private), GFP_KERNEL); 154 priv = kmalloc(sizeof(struct kobil_private), GFP_KERNEL);
152 if (!priv){ 155 if (!priv)
153 return -ENOMEM; 156 return -ENOMEM;
154 }
155 157
156 priv->filled = 0; 158 priv->filled = 0;
157 priv->cur_pos = 0; 159 priv->cur_pos = 0;
158 priv->device_type = le16_to_cpu(serial->dev->descriptor.idProduct); 160 priv->device_type = le16_to_cpu(serial->dev->descriptor.idProduct);
159 161
160 switch (priv->device_type){ 162 switch (priv->device_type) {
161 case KOBIL_ADAPTER_B_PRODUCT_ID: 163 case KOBIL_ADAPTER_B_PRODUCT_ID:
162 printk(KERN_DEBUG "KOBIL B1 PRO / KAAN PRO detected\n"); 164 printk(KERN_DEBUG "KOBIL B1 PRO / KAAN PRO detected\n");
163 break; 165 break;
164 case KOBIL_ADAPTER_K_PRODUCT_ID: 166 case KOBIL_ADAPTER_K_PRODUCT_ID:
165 printk(KERN_DEBUG "KOBIL KAAN Standard Plus / SecOVID Reader Plus detected\n"); 167 printk(KERN_DEBUG
168 "KOBIL KAAN Standard Plus / SecOVID Reader Plus detected\n");
166 break; 169 break;
167 case KOBIL_USBTWIN_PRODUCT_ID: 170 case KOBIL_USBTWIN_PRODUCT_ID:
168 printk(KERN_DEBUG "KOBIL USBTWIN detected\n"); 171 printk(KERN_DEBUG "KOBIL USBTWIN detected\n");
@@ -173,44 +176,48 @@ static int kobil_startup (struct usb_serial *serial)
173 } 176 }
174 usb_set_serial_port_data(serial->port[0], priv); 177 usb_set_serial_port_data(serial->port[0], priv);
175 178
176 // search for the necessary endpoints 179 /* search for the necessary endpoints */
177 pdev = serial->dev; 180 pdev = serial->dev;
178 actconfig = pdev->actconfig; 181 actconfig = pdev->actconfig;
179 interface = actconfig->interface[0]; 182 interface = actconfig->interface[0];
180 altsetting = interface->cur_altsetting; 183 altsetting = interface->cur_altsetting;
181 endpoint = altsetting->endpoint; 184 endpoint = altsetting->endpoint;
182 185
183 for (i = 0; i < altsetting->desc.bNumEndpoints; i++) { 186 for (i = 0; i < altsetting->desc.bNumEndpoints; i++) {
184 endpoint = &altsetting->endpoint[i]; 187 endpoint = &altsetting->endpoint[i];
185 if (usb_endpoint_is_int_out(&endpoint->desc)) { 188 if (usb_endpoint_is_int_out(&endpoint->desc)) {
186 dbg("%s Found interrupt out endpoint. Address: %d", __func__, endpoint->desc.bEndpointAddress); 189 dbg("%s Found interrupt out endpoint. Address: %d",
187 priv->write_int_endpoint_address = endpoint->desc.bEndpointAddress; 190 __func__, endpoint->desc.bEndpointAddress);
188 } 191 priv->write_int_endpoint_address =
192 endpoint->desc.bEndpointAddress;
193 }
189 if (usb_endpoint_is_int_in(&endpoint->desc)) { 194 if (usb_endpoint_is_int_in(&endpoint->desc)) {
190 dbg("%s Found interrupt in endpoint. Address: %d", __func__, endpoint->desc.bEndpointAddress); 195 dbg("%s Found interrupt in endpoint. Address: %d",
191 priv->read_int_endpoint_address = endpoint->desc.bEndpointAddress; 196 __func__, endpoint->desc.bEndpointAddress);
192 } 197 priv->read_int_endpoint_address =
198 endpoint->desc.bEndpointAddress;
199 }
193 } 200 }
194 return 0; 201 return 0;
195} 202}
196 203
197 204
198static void kobil_shutdown (struct usb_serial *serial) 205static void kobil_shutdown(struct usb_serial *serial)
199{ 206{
200 int i; 207 int i;
201 dbg("%s - port %d", __func__, serial->port[0]->number); 208 dbg("%s - port %d", __func__, serial->port[0]->number);
202 209
203 for (i=0; i < serial->num_ports; ++i) { 210 for (i = 0; i < serial->num_ports; ++i) {
204 while (serial->port[i]->open_count > 0) { 211 while (serial->port[i]->port.count > 0)
205 kobil_close (serial->port[i], NULL); 212 kobil_close(NULL, serial->port[i], NULL);
206 }
207 kfree(usb_get_serial_port_data(serial->port[i])); 213 kfree(usb_get_serial_port_data(serial->port[i]));
208 usb_set_serial_port_data(serial->port[i], NULL); 214 usb_set_serial_port_data(serial->port[i], NULL);
209 } 215 }
210} 216}
211 217
212 218
213static int kobil_open (struct usb_serial_port *port, struct file *filp) 219static int kobil_open(struct tty_struct *tty,
220 struct usb_serial_port *port, struct file *filp)
214{ 221{
215 int result = 0; 222 int result = 0;
216 struct kobil_private *priv; 223 struct kobil_private *priv;
@@ -221,7 +228,7 @@ static int kobil_open (struct usb_serial_port *port, struct file *filp)
221 dbg("%s - port %d", __func__, port->number); 228 dbg("%s - port %d", __func__, port->number);
222 priv = usb_get_serial_port_data(port); 229 priv = usb_get_serial_port_data(port);
223 230
224 // someone sets the dev to 0 if the close method has been called 231 /* someone sets the dev to 0 if the close method has been called */
225 port->interrupt_in_urb->dev = port->serial->dev; 232 port->interrupt_in_urb->dev = port->serial->dev;
226 233
227 234
@@ -229,100 +236,115 @@ static int kobil_open (struct usb_serial_port *port, struct file *filp)
229 * the data through, otherwise it is scheduled, and with high 236 * the data through, otherwise it is scheduled, and with high
230 * data rates (like with OHCI) data can get lost. 237 * data rates (like with OHCI) data can get lost.
231 */ 238 */
232 port->tty->low_latency = 1; 239 if (tty) {
233 240 tty->low_latency = 1;
234 // without this, every push_tty_char is echoed :-( 241
235 port->tty->termios->c_lflag = 0; 242 /* Default to echo off and other sane device settings */
236 port->tty->termios->c_lflag &= ~(ISIG | ICANON | ECHO | IEXTEN | XCASE); 243 tty->termios->c_lflag = 0;
237 port->tty->termios->c_iflag = IGNBRK | IGNPAR | IXOFF; 244 tty->termios->c_lflag &= ~(ISIG | ICANON | ECHO | IEXTEN |
238 port->tty->termios->c_oflag &= ~ONLCR; // do NOT translate CR to CR-NL (0x0A -> 0x0A 0x0D) 245 XCASE);
239 246 tty->termios->c_iflag = IGNBRK | IGNPAR | IXOFF;
240 // allocate memory for transfer buffer 247 /* do NOT translate CR to CR-NL (0x0A -> 0x0A 0x0D) */
248 tty->termios->c_oflag &= ~ONLCR;
249 }
250 /* allocate memory for transfer buffer */
241 transfer_buffer = kzalloc(transfer_buffer_length, GFP_KERNEL); 251 transfer_buffer = kzalloc(transfer_buffer_length, GFP_KERNEL);
242 if (! transfer_buffer) { 252 if (!transfer_buffer)
243 return -ENOMEM; 253 return -ENOMEM;
244 } 254
245 255 /* allocate write_urb */
246 // allocate write_urb 256 if (!port->write_urb) {
247 if (!port->write_urb) { 257 dbg("%s - port %d Allocating port->write_urb",
248 dbg("%s - port %d Allocating port->write_urb", __func__, port->number); 258 __func__, port->number);
249 port->write_urb = usb_alloc_urb(0, GFP_KERNEL); 259 port->write_urb = usb_alloc_urb(0, GFP_KERNEL);
250 if (!port->write_urb) { 260 if (!port->write_urb) {
251 dbg("%s - port %d usb_alloc_urb failed", __func__, port->number); 261 dbg("%s - port %d usb_alloc_urb failed",
262 __func__, port->number);
252 kfree(transfer_buffer); 263 kfree(transfer_buffer);
253 return -ENOMEM; 264 return -ENOMEM;
254 } 265 }
255 } 266 }
256 267
257 // allocate memory for write_urb transfer buffer 268 /* allocate memory for write_urb transfer buffer */
258 port->write_urb->transfer_buffer = kmalloc(write_urb_transfer_buffer_length, GFP_KERNEL); 269 port->write_urb->transfer_buffer =
259 if (! port->write_urb->transfer_buffer) { 270 kmalloc(write_urb_transfer_buffer_length, GFP_KERNEL);
271 if (!port->write_urb->transfer_buffer) {
260 kfree(transfer_buffer); 272 kfree(transfer_buffer);
261 usb_free_urb(port->write_urb); 273 usb_free_urb(port->write_urb);
262 port->write_urb = NULL; 274 port->write_urb = NULL;
263 return -ENOMEM; 275 return -ENOMEM;
264 } 276 }
265 277
266 // get hardware version 278 /* get hardware version */
267 result = usb_control_msg( port->serial->dev, 279 result = usb_control_msg(port->serial->dev,
268 usb_rcvctrlpipe(port->serial->dev, 0 ), 280 usb_rcvctrlpipe(port->serial->dev, 0),
269 SUSBCRequest_GetMisc, 281 SUSBCRequest_GetMisc,
270 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_IN, 282 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_IN,
271 SUSBCR_MSC_GetHWVersion, 283 SUSBCR_MSC_GetHWVersion,
272 0, 284 0,
273 transfer_buffer, 285 transfer_buffer,
274 transfer_buffer_length, 286 transfer_buffer_length,
275 KOBIL_TIMEOUT 287 KOBIL_TIMEOUT
288 );
289 dbg("%s - port %d Send get_HW_version URB returns: %i",
290 __func__, port->number, result);
291 dbg("Harware version: %i.%i.%i",
292 transfer_buffer[0], transfer_buffer[1], transfer_buffer[2]);
293
294 /* get firmware version */
295 result = usb_control_msg(port->serial->dev,
296 usb_rcvctrlpipe(port->serial->dev, 0),
297 SUSBCRequest_GetMisc,
298 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_IN,
299 SUSBCR_MSC_GetFWVersion,
300 0,
301 transfer_buffer,
302 transfer_buffer_length,
303 KOBIL_TIMEOUT
304 );
305 dbg("%s - port %d Send get_FW_version URB returns: %i",
306 __func__, port->number, result);
307 dbg("Firmware version: %i.%i.%i",
308 transfer_buffer[0], transfer_buffer[1], transfer_buffer[2]);
309
310 if (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID ||
311 priv->device_type == KOBIL_ADAPTER_K_PRODUCT_ID) {
312 /* Setting Baudrate, Parity and Stopbits */
313 result = usb_control_msg(port->serial->dev,
314 usb_rcvctrlpipe(port->serial->dev, 0),
315 SUSBCRequest_SetBaudRateParityAndStopBits,
316 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT,
317 SUSBCR_SBR_9600 | SUSBCR_SPASB_EvenParity |
318 SUSBCR_SPASB_1StopBit,
319 0,
320 transfer_buffer,
321 0,
322 KOBIL_TIMEOUT
276 ); 323 );
277 dbg("%s - port %d Send get_HW_version URB returns: %i", __func__, port->number, result); 324 dbg("%s - port %d Send set_baudrate URB returns: %i",
278 dbg("Harware version: %i.%i.%i", transfer_buffer[0], transfer_buffer[1], transfer_buffer[2] ); 325 __func__, port->number, result);
279 326
280 // get firmware version 327 /* reset all queues */
281 result = usb_control_msg( port->serial->dev, 328 result = usb_control_msg(port->serial->dev,
282 usb_rcvctrlpipe(port->serial->dev, 0 ), 329 usb_rcvctrlpipe(port->serial->dev, 0),
283 SUSBCRequest_GetMisc, 330 SUSBCRequest_Misc,
284 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_IN, 331 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT,
285 SUSBCR_MSC_GetFWVersion, 332 SUSBCR_MSC_ResetAllQueues,
286 0, 333 0,
287 transfer_buffer, 334 transfer_buffer,
288 transfer_buffer_length, 335 0,
289 KOBIL_TIMEOUT 336 KOBIL_TIMEOUT
290 ); 337 );
291 dbg("%s - port %d Send get_FW_version URB returns: %i", __func__, port->number, result); 338 dbg("%s - port %d Send reset_all_queues URB returns: %i",
292 dbg("Firmware version: %i.%i.%i", transfer_buffer[0], transfer_buffer[1], transfer_buffer[2] ); 339 __func__, port->number, result);
293
294 if (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID || priv->device_type == KOBIL_ADAPTER_K_PRODUCT_ID) {
295 // Setting Baudrate, Parity and Stopbits
296 result = usb_control_msg( port->serial->dev,
297 usb_rcvctrlpipe(port->serial->dev, 0 ),
298 SUSBCRequest_SetBaudRateParityAndStopBits,
299 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT,
300 SUSBCR_SBR_9600 | SUSBCR_SPASB_EvenParity | SUSBCR_SPASB_1StopBit,
301 0,
302 transfer_buffer,
303 0,
304 KOBIL_TIMEOUT
305 );
306 dbg("%s - port %d Send set_baudrate URB returns: %i", __func__, port->number, result);
307
308 // reset all queues
309 result = usb_control_msg( port->serial->dev,
310 usb_rcvctrlpipe(port->serial->dev, 0 ),
311 SUSBCRequest_Misc,
312 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT,
313 SUSBCR_MSC_ResetAllQueues,
314 0,
315 transfer_buffer,
316 0,
317 KOBIL_TIMEOUT
318 );
319 dbg("%s - port %d Send reset_all_queues URB returns: %i", __func__, port->number, result);
320 } 340 }
321 if (priv->device_type == KOBIL_USBTWIN_PRODUCT_ID || priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID || 341 if (priv->device_type == KOBIL_USBTWIN_PRODUCT_ID ||
342 priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID ||
322 priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID) { 343 priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID) {
323 // start reading (Adapter B 'cause PNP string) 344 /* start reading (Adapter B 'cause PNP string) */
324 result = usb_submit_urb( port->interrupt_in_urb, GFP_ATOMIC ); 345 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
325 dbg("%s - port %d Send read URB returns: %i", __func__, port->number, result); 346 dbg("%s - port %d Send read URB returns: %i",
347 __func__, port->number, result);
326 } 348 }
327 349
328 kfree(transfer_buffer); 350 kfree(transfer_buffer);
@@ -330,13 +352,14 @@ static int kobil_open (struct usb_serial_port *port, struct file *filp)
330} 352}
331 353
332 354
333static void kobil_close (struct usb_serial_port *port, struct file *filp) 355static void kobil_close(struct tty_struct *tty,
356 struct usb_serial_port *port, struct file *filp)
334{ 357{
335 dbg("%s - port %d", __func__, port->number); 358 dbg("%s - port %d", __func__, port->number);
336 359
337 if (port->write_urb) { 360 if (port->write_urb) {
338 usb_kill_urb(port->write_urb); 361 usb_kill_urb(port->write_urb);
339 usb_free_urb( port->write_urb ); 362 usb_free_urb(port->write_urb);
340 port->write_urb = NULL; 363 port->write_urb = NULL;
341 } 364 }
342 usb_kill_urb(port->interrupt_in_urb); 365 usb_kill_urb(port->interrupt_in_urb);
@@ -350,7 +373,7 @@ static void kobil_read_int_callback(struct urb *urb)
350 struct tty_struct *tty; 373 struct tty_struct *tty;
351 unsigned char *data = urb->transfer_buffer; 374 unsigned char *data = urb->transfer_buffer;
352 int status = urb->status; 375 int status = urb->status;
353// char *dbg_data; 376/* char *dbg_data; */
354 377
355 dbg("%s - port %d", __func__, port->number); 378 dbg("%s - port %d", __func__, port->number);
356 379
@@ -360,51 +383,53 @@ static void kobil_read_int_callback(struct urb *urb)
360 return; 383 return;
361 } 384 }
362 385
363 tty = port->tty; 386 tty = port->port.tty;
364 if (urb->actual_length) { 387 if (urb->actual_length) {
365 388
366 // BEGIN DEBUG 389 /* BEGIN DEBUG */
367 /* 390 /*
368 dbg_data = kzalloc((3 * purb->actual_length + 10) * sizeof(char), GFP_KERNEL); 391 dbg_data = kzalloc((3 * purb->actual_length + 10)
392 * sizeof(char), GFP_KERNEL);
369 if (! dbg_data) { 393 if (! dbg_data) {
370 return; 394 return;
371 } 395 }
372 for (i = 0; i < purb->actual_length; i++) { 396 for (i = 0; i < purb->actual_length; i++) {
373 sprintf(dbg_data +3*i, "%02X ", data[i]); 397 sprintf(dbg_data +3*i, "%02X ", data[i]);
374 } 398 }
375 dbg(" <-- %s", dbg_data ); 399 dbg(" <-- %s", dbg_data);
376 kfree(dbg_data); 400 kfree(dbg_data);
377 */ 401 */
378 // END DEBUG 402 /* END DEBUG */
379 403
380 tty_buffer_request_room(tty, urb->actual_length); 404 tty_buffer_request_room(tty, urb->actual_length);
381 tty_insert_flip_string(tty, data, urb->actual_length); 405 tty_insert_flip_string(tty, data, urb->actual_length);
382 tty_flip_buffer_push(tty); 406 tty_flip_buffer_push(tty);
383 } 407 }
384 408 /* someone sets the dev to 0 if the close method has been called */
385 // someone sets the dev to 0 if the close method has been called
386 port->interrupt_in_urb->dev = port->serial->dev; 409 port->interrupt_in_urb->dev = port->serial->dev;
387 410
388 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); 411 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
389 dbg("%s - port %d Send read URB returns: %i", __func__, port->number, result); 412 dbg("%s - port %d Send read URB returns: %i",
413 __func__, port->number, result);
390} 414}
391 415
392 416
393static void kobil_write_callback( struct urb *purb ) 417static void kobil_write_callback(struct urb *purb)
394{ 418{
395} 419}
396 420
397 421
398static int kobil_write (struct usb_serial_port *port, 422static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port,
399 const unsigned char *buf, int count) 423 const unsigned char *buf, int count)
400{ 424{
401 int length = 0; 425 int length = 0;
402 int result = 0; 426 int result = 0;
403 int todo = 0; 427 int todo = 0;
404 struct kobil_private * priv; 428 struct kobil_private *priv;
405 429
406 if (count == 0) { 430 if (count == 0) {
407 dbg("%s - port %d write request of 0 bytes", __func__, port->number); 431 dbg("%s - port %d write request of 0 bytes",
432 __func__, port->number);
408 return 0; 433 return 0;
409 } 434 }
410 435
@@ -415,106 +440,113 @@ static int kobil_write (struct usb_serial_port *port,
415 return -ENOMEM; 440 return -ENOMEM;
416 } 441 }
417 442
418 // Copy data to buffer 443 /* Copy data to buffer */
419 memcpy (priv->buf + priv->filled, buf, count); 444 memcpy(priv->buf + priv->filled, buf, count);
420 445 usb_serial_debug_data(debug, &port->dev, __func__, count,
421 usb_serial_debug_data(debug, &port->dev, __func__, count, priv->buf + priv->filled); 446 priv->buf + priv->filled);
422
423 priv->filled = priv->filled + count; 447 priv->filled = priv->filled + count;
424 448
425 449 /* only send complete block. TWIN, KAAN SIM and adapter K
426 // only send complete block. TWIN, KAAN SIM and adapter K use the same protocol. 450 use the same protocol. */
427 if ( ((priv->device_type != KOBIL_ADAPTER_B_PRODUCT_ID) && (priv->filled > 2) && (priv->filled >= (priv->buf[1] + 3))) || 451 if (((priv->device_type != KOBIL_ADAPTER_B_PRODUCT_ID) && (priv->filled > 2) && (priv->filled >= (priv->buf[1] + 3))) ||
428 ((priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID) && (priv->filled > 3) && (priv->filled >= (priv->buf[2] + 4))) ) { 452 ((priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID) && (priv->filled > 3) && (priv->filled >= (priv->buf[2] + 4)))) {
429 453 /* stop reading (except TWIN and KAAN SIM) */
430 // stop reading (except TWIN and KAAN SIM) 454 if ((priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID)
431 if ( (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID) || (priv->device_type == KOBIL_ADAPTER_K_PRODUCT_ID) ) 455 || (priv->device_type == KOBIL_ADAPTER_K_PRODUCT_ID))
432 usb_kill_urb(port->interrupt_in_urb); 456 usb_kill_urb(port->interrupt_in_urb);
433 457
434 todo = priv->filled - priv->cur_pos; 458 todo = priv->filled - priv->cur_pos;
435 459
436 while(todo > 0) { 460 while (todo > 0) {
437 // max 8 byte in one urb (endpoint size) 461 /* max 8 byte in one urb (endpoint size) */
438 length = (todo < 8) ? todo : 8; 462 length = (todo < 8) ? todo : 8;
439 // copy data to transfer buffer 463 /* copy data to transfer buffer */
440 memcpy(port->write_urb->transfer_buffer, priv->buf + priv->cur_pos, length ); 464 memcpy(port->write_urb->transfer_buffer,
441 usb_fill_int_urb( port->write_urb, 465 priv->buf + priv->cur_pos, length);
442 port->serial->dev, 466 usb_fill_int_urb(port->write_urb,
443 usb_sndintpipe(port->serial->dev, priv->write_int_endpoint_address), 467 port->serial->dev,
444 port->write_urb->transfer_buffer, 468 usb_sndintpipe(port->serial->dev,
445 length, 469 priv->write_int_endpoint_address),
446 kobil_write_callback, 470 port->write_urb->transfer_buffer,
447 port, 471 length,
448 8 472 kobil_write_callback,
449 ); 473 port,
474 8
475 );
450 476
451 priv->cur_pos = priv->cur_pos + length; 477 priv->cur_pos = priv->cur_pos + length;
452 result = usb_submit_urb( port->write_urb, GFP_NOIO ); 478 result = usb_submit_urb(port->write_urb, GFP_NOIO);
453 dbg("%s - port %d Send write URB returns: %i", __func__, port->number, result); 479 dbg("%s - port %d Send write URB returns: %i",
480 __func__, port->number, result);
454 todo = priv->filled - priv->cur_pos; 481 todo = priv->filled - priv->cur_pos;
455 482
456 if (todo > 0) { 483 if (todo > 0)
457 msleep(24); 484 msleep(24);
458 } 485 }
459 486
460 } // end while
461
462 priv->filled = 0; 487 priv->filled = 0;
463 priv->cur_pos = 0; 488 priv->cur_pos = 0;
464 489
465 // someone sets the dev to 0 if the close method has been called 490 /* someone sets the dev to 0 if the close method
491 has been called */
466 port->interrupt_in_urb->dev = port->serial->dev; 492 port->interrupt_in_urb->dev = port->serial->dev;
467 493
468 // start reading (except TWIN and KAAN SIM) 494 /* start reading (except TWIN and KAAN SIM) */
469 if ( (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID) || (priv->device_type == KOBIL_ADAPTER_K_PRODUCT_ID) ) { 495 if (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID ||
470 // someone sets the dev to 0 if the close method has been called 496 priv->device_type == KOBIL_ADAPTER_K_PRODUCT_ID) {
497 /* someone sets the dev to 0 if the close method has
498 been called */
471 port->interrupt_in_urb->dev = port->serial->dev; 499 port->interrupt_in_urb->dev = port->serial->dev;
472 500
473 result = usb_submit_urb( port->interrupt_in_urb, GFP_NOIO ); 501 result = usb_submit_urb(port->interrupt_in_urb,
474 dbg("%s - port %d Send read URB returns: %i", __func__, port->number, result); 502 GFP_NOIO);
503 dbg("%s - port %d Send read URB returns: %i",
504 __func__, port->number, result);
475 } 505 }
476 } 506 }
477 return count; 507 return count;
478} 508}
479 509
480 510
481static int kobil_write_room (struct usb_serial_port *port) 511static int kobil_write_room(struct tty_struct *tty)
482{ 512{
483 //dbg("%s - port %d", __func__, port->number); 513 /* dbg("%s - port %d", __func__, port->number); */
514 /* FIXME */
484 return 8; 515 return 8;
485} 516}
486 517
487 518
488static int kobil_tiocmget(struct usb_serial_port *port, struct file *file) 519static int kobil_tiocmget(struct tty_struct *tty, struct file *file)
489{ 520{
490 struct kobil_private * priv; 521 struct usb_serial_port *port = tty->driver_data;
522 struct kobil_private *priv;
491 int result; 523 int result;
492 unsigned char *transfer_buffer; 524 unsigned char *transfer_buffer;
493 int transfer_buffer_length = 8; 525 int transfer_buffer_length = 8;
494 526
495 priv = usb_get_serial_port_data(port); 527 priv = usb_get_serial_port_data(port);
496 if ((priv->device_type == KOBIL_USBTWIN_PRODUCT_ID) || (priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID)) { 528 if (priv->device_type == KOBIL_USBTWIN_PRODUCT_ID
497 // This device doesn't support ioctl calls 529 || priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID) {
530 /* This device doesn't support ioctl calls */
498 return -EINVAL; 531 return -EINVAL;
499 } 532 }
500 533
501 // allocate memory for transfer buffer 534 /* allocate memory for transfer buffer */
502 transfer_buffer = kzalloc(transfer_buffer_length, GFP_KERNEL); 535 transfer_buffer = kzalloc(transfer_buffer_length, GFP_KERNEL);
503 if (!transfer_buffer) { 536 if (!transfer_buffer)
504 return -ENOMEM; 537 return -ENOMEM;
505 }
506 538
507 result = usb_control_msg( port->serial->dev, 539 result = usb_control_msg(port->serial->dev,
508 usb_rcvctrlpipe(port->serial->dev, 0 ), 540 usb_rcvctrlpipe(port->serial->dev, 0),
509 SUSBCRequest_GetStatusLineState, 541 SUSBCRequest_GetStatusLineState,
510 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_IN, 542 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_IN,
511 0, 543 0,
512 0, 544 0,
513 transfer_buffer, 545 transfer_buffer,
514 transfer_buffer_length, 546 transfer_buffer_length,
515 KOBIL_TIMEOUT); 547 KOBIL_TIMEOUT);
516 548
517 dbg("%s - port %d Send get_status_line_state URB returns: %i. Statusline: %02x", 549 dbg("%s - port %d Send get_status_line_state URB returns: %i. Statusline: %02x",
518 __func__, port->number, result, transfer_buffer[0]); 550 __func__, port->number, result, transfer_buffer[0]);
519 551
520 result = 0; 552 result = 0;
@@ -524,10 +556,11 @@ static int kobil_tiocmget(struct usb_serial_port *port, struct file *file)
524 return result; 556 return result;
525} 557}
526 558
527static int kobil_tiocmset(struct usb_serial_port *port, struct file *file, 559static int kobil_tiocmset(struct tty_struct *tty, struct file *file,
528 unsigned int set, unsigned int clear) 560 unsigned int set, unsigned int clear)
529{ 561{
530 struct kobil_private * priv; 562 struct usb_serial_port *port = tty->driver_data;
563 struct kobil_private *priv;
531 int result; 564 int result;
532 int dtr = 0; 565 int dtr = 0;
533 int rts = 0; 566 int rts = 0;
@@ -536,16 +569,16 @@ static int kobil_tiocmset(struct usb_serial_port *port, struct file *file,
536 569
537 /* FIXME: locking ? */ 570 /* FIXME: locking ? */
538 priv = usb_get_serial_port_data(port); 571 priv = usb_get_serial_port_data(port);
539 if ((priv->device_type == KOBIL_USBTWIN_PRODUCT_ID) || (priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID)) { 572 if (priv->device_type == KOBIL_USBTWIN_PRODUCT_ID
540 // This device doesn't support ioctl calls 573 || priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID) {
574 /* This device doesn't support ioctl calls */
541 return -EINVAL; 575 return -EINVAL;
542 } 576 }
543 577
544 // allocate memory for transfer buffer 578 /* allocate memory for transfer buffer */
545 transfer_buffer = kzalloc(transfer_buffer_length, GFP_KERNEL); 579 transfer_buffer = kzalloc(transfer_buffer_length, GFP_KERNEL);
546 if (! transfer_buffer) { 580 if (!transfer_buffer)
547 return -ENOMEM; 581 return -ENOMEM;
548 }
549 582
550 if (set & TIOCM_RTS) 583 if (set & TIOCM_RTS)
551 rts = 1; 584 rts = 1;
@@ -558,66 +591,77 @@ static int kobil_tiocmset(struct usb_serial_port *port, struct file *file,
558 591
559 if (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID) { 592 if (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID) {
560 if (dtr != 0) 593 if (dtr != 0)
561 dbg("%s - port %d Setting DTR", __func__, port->number); 594 dbg("%s - port %d Setting DTR",
595 __func__, port->number);
562 else 596 else
563 dbg("%s - port %d Clearing DTR", __func__, port->number); 597 dbg("%s - port %d Clearing DTR",
564 result = usb_control_msg( port->serial->dev, 598 __func__, port->number);
565 usb_rcvctrlpipe(port->serial->dev, 0 ), 599 result = usb_control_msg(port->serial->dev,
566 SUSBCRequest_SetStatusLinesOrQueues, 600 usb_rcvctrlpipe(port->serial->dev, 0),
567 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, 601 SUSBCRequest_SetStatusLinesOrQueues,
568 ((dtr != 0) ? SUSBCR_SSL_SETDTR : SUSBCR_SSL_CLRDTR), 602 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT,
569 0, 603 ((dtr != 0) ? SUSBCR_SSL_SETDTR : SUSBCR_SSL_CLRDTR),
570 transfer_buffer, 604 0,
571 0, 605 transfer_buffer,
572 KOBIL_TIMEOUT); 606 0,
607 KOBIL_TIMEOUT);
573 } else { 608 } else {
574 if (rts != 0) 609 if (rts != 0)
575 dbg("%s - port %d Setting RTS", __func__, port->number); 610 dbg("%s - port %d Setting RTS",
611 __func__, port->number);
576 else 612 else
577 dbg("%s - port %d Clearing RTS", __func__, port->number); 613 dbg("%s - port %d Clearing RTS",
578 result = usb_control_msg( port->serial->dev, 614 __func__, port->number);
579 usb_rcvctrlpipe(port->serial->dev, 0 ), 615 result = usb_control_msg(port->serial->dev,
580 SUSBCRequest_SetStatusLinesOrQueues, 616 usb_rcvctrlpipe(port->serial->dev, 0),
581 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, 617 SUSBCRequest_SetStatusLinesOrQueues,
582 ((rts != 0) ? SUSBCR_SSL_SETRTS : SUSBCR_SSL_CLRRTS), 618 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT,
583 0, 619 ((rts != 0) ? SUSBCR_SSL_SETRTS : SUSBCR_SSL_CLRRTS),
584 transfer_buffer, 620 0,
585 0, 621 transfer_buffer,
586 KOBIL_TIMEOUT); 622 0,
623 KOBIL_TIMEOUT);
587 } 624 }
588 dbg("%s - port %d Send set_status_line URB returns: %i", __func__, port->number, result); 625 dbg("%s - port %d Send set_status_line URB returns: %i",
626 __func__, port->number, result);
589 kfree(transfer_buffer); 627 kfree(transfer_buffer);
590 return (result < 0) ? result : 0; 628 return (result < 0) ? result : 0;
591} 629}
592 630
593static void kobil_set_termios(struct usb_serial_port *port, struct ktermios *old) 631static void kobil_set_termios(struct tty_struct *tty,
632 struct usb_serial_port *port, struct ktermios *old)
594{ 633{
595 struct kobil_private * priv; 634 struct kobil_private *priv;
596 int result; 635 int result;
597 unsigned short urb_val = 0; 636 unsigned short urb_val = 0;
598 int c_cflag = port->tty->termios->c_cflag; 637 int c_cflag = tty->termios->c_cflag;
599 speed_t speed; 638 speed_t speed;
600 void * settings; 639 void *settings;
601 640
602 priv = usb_get_serial_port_data(port); 641 priv = usb_get_serial_port_data(port);
603 if (priv->device_type == KOBIL_USBTWIN_PRODUCT_ID || priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID) 642 if (priv->device_type == KOBIL_USBTWIN_PRODUCT_ID ||
604 // This device doesn't support ioctl calls 643 priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID) {
644 /* This device doesn't support ioctl calls */
645 *tty->termios = *old;
605 return; 646 return;
647 }
606 648
607 switch (speed = tty_get_baud_rate(port->tty)) { 649 speed = tty_get_baud_rate(tty);
608 case 1200: 650 switch (speed) {
609 urb_val = SUSBCR_SBR_1200; 651 case 1200:
610 break; 652 urb_val = SUSBCR_SBR_1200;
611 default: 653 break;
612 speed = 9600; 654 default:
613 case 9600: 655 speed = 9600;
614 urb_val = SUSBCR_SBR_9600; 656 case 9600:
615 break; 657 urb_val = SUSBCR_SBR_9600;
658 break;
616 } 659 }
617 urb_val |= (c_cflag & CSTOPB) ? SUSBCR_SPASB_2StopBits : SUSBCR_SPASB_1StopBit; 660 urb_val |= (c_cflag & CSTOPB) ? SUSBCR_SPASB_2StopBits :
661 SUSBCR_SPASB_1StopBit;
618 662
619 settings = kzalloc(50, GFP_KERNEL); 663 settings = kzalloc(50, GFP_KERNEL);
620 if (! settings) 664 if (!settings)
621 return; 665 return;
622 666
623 sprintf(settings, "%d ", speed); 667 sprintf(settings, "%d ", speed);
@@ -634,66 +678,69 @@ static void kobil_set_termios(struct usb_serial_port *port, struct ktermios *old
634 urb_val |= SUSBCR_SPASB_NoParity; 678 urb_val |= SUSBCR_SPASB_NoParity;
635 strcat(settings, "No Parity"); 679 strcat(settings, "No Parity");
636 } 680 }
637 port->tty->termios->c_cflag &= ~CMSPAR; 681 tty->termios->c_cflag &= ~CMSPAR;
638 tty_encode_baud_rate(port->tty, speed, speed); 682 tty_encode_baud_rate(tty, speed, speed);
639 683
640 result = usb_control_msg( port->serial->dev, 684 result = usb_control_msg(port->serial->dev,
641 usb_rcvctrlpipe(port->serial->dev, 0 ), 685 usb_rcvctrlpipe(port->serial->dev, 0),
642 SUSBCRequest_SetBaudRateParityAndStopBits, 686 SUSBCRequest_SetBaudRateParityAndStopBits,
643 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, 687 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT,
644 urb_val, 688 urb_val,
645 0, 689 0,
646 settings, 690 settings,
647 0, 691 0,
648 KOBIL_TIMEOUT 692 KOBIL_TIMEOUT
649 ); 693 );
650 kfree(settings); 694 kfree(settings);
651} 695}
652 696
653static int kobil_ioctl(struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg) 697static int kobil_ioctl(struct tty_struct *tty, struct file *file,
698 unsigned int cmd, unsigned long arg)
654{ 699{
655 struct kobil_private * priv = usb_get_serial_port_data(port); 700 struct usb_serial_port *port = tty->driver_data;
701 struct kobil_private *priv = usb_get_serial_port_data(port);
656 unsigned char *transfer_buffer; 702 unsigned char *transfer_buffer;
657 int transfer_buffer_length = 8; 703 int transfer_buffer_length = 8;
658 int result; 704 int result;
659 705
660 if (priv->device_type == KOBIL_USBTWIN_PRODUCT_ID || priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID) 706 if (priv->device_type == KOBIL_USBTWIN_PRODUCT_ID ||
661 // This device doesn't support ioctl calls 707 priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID)
662 return 0; 708 /* This device doesn't support ioctl calls */
709 return -ENOIOCTLCMD;
663 710
664 switch (cmd) { 711 switch (cmd) {
665 case TCFLSH: // 0x540B 712 case TCFLSH:
666 transfer_buffer = kmalloc(transfer_buffer_length, GFP_KERNEL); 713 transfer_buffer = kmalloc(transfer_buffer_length, GFP_KERNEL);
667 if (! transfer_buffer) 714 if (!transfer_buffer)
668 return -ENOBUFS; 715 return -ENOBUFS;
669 716
670 result = usb_control_msg( port->serial->dev, 717 result = usb_control_msg(port->serial->dev,
671 usb_rcvctrlpipe(port->serial->dev, 0 ), 718 usb_rcvctrlpipe(port->serial->dev, 0),
672 SUSBCRequest_Misc, 719 SUSBCRequest_Misc,
673 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, 720 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT,
674 SUSBCR_MSC_ResetAllQueues, 721 SUSBCR_MSC_ResetAllQueues,
675 0, 722 0,
676 NULL,//transfer_buffer, 723 NULL, /* transfer_buffer, */
677 0, 724 0,
678 KOBIL_TIMEOUT 725 KOBIL_TIMEOUT
679 ); 726 );
680 727
681 dbg("%s - port %d Send reset_all_queues (FLUSH) URB returns: %i", __func__, port->number, result); 728 dbg("%s - port %d Send reset_all_queues (FLUSH) URB returns: %i", __func__, port->number, result);
682 kfree(transfer_buffer); 729 kfree(transfer_buffer);
683 return (result < 0) ? -EFAULT : 0; 730 return (result < 0) ? -EIO: 0;
684 default: 731 default:
685 return -ENOIOCTLCMD; 732 return -ENOIOCTLCMD;
686 } 733 }
687} 734}
688 735
689static int __init kobil_init (void) 736static int __init kobil_init(void)
690{ 737{
691 int retval; 738 int retval;
692 retval = usb_serial_register(&kobil_device); 739 retval = usb_serial_register(&kobil_device);
693 if (retval) 740 if (retval)
694 goto failed_usb_serial_register; 741 goto failed_usb_serial_register;
695 retval = usb_register(&kobil_driver); 742 retval = usb_register(&kobil_driver);
696 if (retval) 743 if (retval)
697 goto failed_usb_register; 744 goto failed_usb_register;
698 745
699 info(DRIVER_VERSION " " DRIVER_AUTHOR); 746 info(DRIVER_VERSION " " DRIVER_AUTHOR);
@@ -707,18 +754,18 @@ failed_usb_serial_register:
707} 754}
708 755
709 756
710static void __exit kobil_exit (void) 757static void __exit kobil_exit(void)
711{ 758{
712 usb_deregister (&kobil_driver); 759 usb_deregister(&kobil_driver);
713 usb_serial_deregister (&kobil_device); 760 usb_serial_deregister(&kobil_device);
714} 761}
715 762
716module_init(kobil_init); 763module_init(kobil_init);
717module_exit(kobil_exit); 764module_exit(kobil_exit);
718 765
719MODULE_AUTHOR( DRIVER_AUTHOR ); 766MODULE_AUTHOR(DRIVER_AUTHOR);
720MODULE_DESCRIPTION( DRIVER_DESC ); 767MODULE_DESCRIPTION(DRIVER_DESC);
721MODULE_LICENSE( "GPL" ); 768MODULE_LICENSE("GPL");
722 769
723module_param(debug, bool, S_IRUGO | S_IWUSR); 770module_param(debug, bool, S_IRUGO | S_IWUSR);
724MODULE_PARM_DESC(debug, "Debug enabled or not"); 771MODULE_PARM_DESC(debug, "Debug enabled or not");
diff --git a/drivers/usb/serial/mct_u232.c b/drivers/usb/serial/mct_u232.c
index 5fc2cef30e39..0ded8bd6ec85 100644
--- a/drivers/usb/serial/mct_u232.c
+++ b/drivers/usb/serial/mct_u232.c
@@ -33,10 +33,11 @@
33 * - Fixed an endianess problem with the baudrate selection for PowerPC. 33 * - Fixed an endianess problem with the baudrate selection for PowerPC.
34 * 34 *
35 * 06-Dec-2001 Martin Hamilton <martinh@gnu.org> 35 * 06-Dec-2001 Martin Hamilton <martinh@gnu.org>
36 * Added support for the Belkin F5U109 DB9 adaptor 36 * - Added support for the Belkin F5U109 DB9 adaptor
37 * 37 *
38 * 30-May-2001 Greg Kroah-Hartman 38 * 30-May-2001 Greg Kroah-Hartman
39 * switched from using spinlock to a semaphore, which fixes lots of problems. 39 * - switched from using spinlock to a semaphore, which fixes lots of
40 * problems.
40 * 41 *
41 * 04-May-2001 Stelian Pop 42 * 04-May-2001 Stelian Pop
42 * - Set the maximum bulk output size for Sitecom U232-P25 model to 16 bytes 43 * - Set the maximum bulk output size for Sitecom U232-P25 model to 16 bytes
@@ -49,7 +50,7 @@
49 * 08-Apr-2001 gb 50 * 08-Apr-2001 gb
50 * - Identify version on module load. 51 * - Identify version on module load.
51 * 52 *
52 * 06-Jan-2001 Cornel Ciocirlan 53 * 06-Jan-2001 Cornel Ciocirlan
53 * - Added support for Sitecom U232-P25 model (Product Id 0x0230) 54 * - Added support for Sitecom U232-P25 model (Product Id 0x0230)
54 * - Added support for D-Link DU-H3SP USB BAY (Product Id 0x0200) 55 * - Added support for D-Link DU-H3SP USB BAY (Product Id 0x0200)
55 * 56 *
@@ -59,8 +60,8 @@
59 * (lots of things will change if/when the usb-serial core changes to 60 * (lots of things will change if/when the usb-serial core changes to
60 * handle these issues. 61 * handle these issues.
61 * 62 *
62 * 27-Nov-2000 Wolfgang Grandegger 63 * 27-Nov-2000 Wolfgang Grandegge
63 * A version for kernel 2.4.0-test10 released to the Linux community 64 * A version for kernel 2.4.0-test10 released to the Linux community
64 * (via linux-usb-devel). 65 * (via linux-usb-devel).
65 */ 66 */
66 67
@@ -73,7 +74,7 @@
73#include <linux/tty_flip.h> 74#include <linux/tty_flip.h>
74#include <linux/module.h> 75#include <linux/module.h>
75#include <linux/spinlock.h> 76#include <linux/spinlock.h>
76#include <asm/uaccess.h> 77#include <linux/uaccess.h>
77#include <linux/usb.h> 78#include <linux/usb.h>
78#include <linux/usb/serial.h> 79#include <linux/usb/serial.h>
79#include "mct_u232.h" 80#include "mct_u232.h"
@@ -90,28 +91,21 @@ static int debug;
90/* 91/*
91 * Function prototypes 92 * Function prototypes
92 */ 93 */
93static int mct_u232_startup (struct usb_serial *serial); 94static int mct_u232_startup(struct usb_serial *serial);
94static void mct_u232_shutdown (struct usb_serial *serial); 95static void mct_u232_shutdown(struct usb_serial *serial);
95static int mct_u232_open (struct usb_serial_port *port, 96static int mct_u232_open(struct tty_struct *tty,
96 struct file *filp); 97 struct usb_serial_port *port, struct file *filp);
97static void mct_u232_close (struct usb_serial_port *port, 98static void mct_u232_close(struct tty_struct *tty,
98 struct file *filp); 99 struct usb_serial_port *port, struct file *filp);
99static void mct_u232_read_int_callback (struct urb *urb); 100static void mct_u232_read_int_callback(struct urb *urb);
100static void mct_u232_set_termios (struct usb_serial_port *port, 101static void mct_u232_set_termios(struct tty_struct *tty,
101 struct ktermios * old); 102 struct usb_serial_port *port, struct ktermios *old);
102static int mct_u232_ioctl (struct usb_serial_port *port, 103static void mct_u232_break_ctl(struct tty_struct *tty, int break_state);
103 struct file * file, 104static int mct_u232_tiocmget(struct tty_struct *tty, struct file *file);
104 unsigned int cmd, 105static int mct_u232_tiocmset(struct tty_struct *tty, struct file *file,
105 unsigned long arg); 106 unsigned int set, unsigned int clear);
106static void mct_u232_break_ctl (struct usb_serial_port *port, 107static void mct_u232_throttle(struct tty_struct *tty);
107 int break_state ); 108static void mct_u232_unthrottle(struct tty_struct *tty);
108static int mct_u232_tiocmget (struct usb_serial_port *port,
109 struct file *file);
110static int mct_u232_tiocmset (struct usb_serial_port *port,
111 struct file *file, unsigned int set,
112 unsigned int clear);
113static void mct_u232_throttle (struct usb_serial_port *port);
114static void mct_u232_unthrottle (struct usb_serial_port *port);
115 109
116 110
117/* 111/*
@@ -125,7 +119,7 @@ static struct usb_device_id id_table_combined [] = {
125 { } /* Terminating entry */ 119 { } /* Terminating entry */
126}; 120};
127 121
128MODULE_DEVICE_TABLE (usb, id_table_combined); 122MODULE_DEVICE_TABLE(usb, id_table_combined);
129 123
130static struct usb_driver mct_u232_driver = { 124static struct usb_driver mct_u232_driver = {
131 .name = "mct_u232", 125 .name = "mct_u232",
@@ -149,7 +143,6 @@ static struct usb_serial_driver mct_u232_device = {
149 .throttle = mct_u232_throttle, 143 .throttle = mct_u232_throttle,
150 .unthrottle = mct_u232_unthrottle, 144 .unthrottle = mct_u232_unthrottle,
151 .read_int_callback = mct_u232_read_int_callback, 145 .read_int_callback = mct_u232_read_int_callback,
152 .ioctl = mct_u232_ioctl,
153 .set_termios = mct_u232_set_termios, 146 .set_termios = mct_u232_set_termios,
154 .break_ctl = mct_u232_break_ctl, 147 .break_ctl = mct_u232_break_ctl,
155 .tiocmget = mct_u232_tiocmget, 148 .tiocmget = mct_u232_tiocmget,
@@ -180,23 +173,34 @@ struct mct_u232_private {
180 * Later day 2.6.0-test kernels have new baud rates like B230400 which 173 * Later day 2.6.0-test kernels have new baud rates like B230400 which
181 * we do not know how to support. We ignore them for the moment. 174 * we do not know how to support. We ignore them for the moment.
182 */ 175 */
183static int mct_u232_calculate_baud_rate(struct usb_serial *serial, speed_t value, speed_t *result) 176static int mct_u232_calculate_baud_rate(struct usb_serial *serial,
177 speed_t value, speed_t *result)
184{ 178{
185 *result = value; 179 *result = value;
186 180
187 if (le16_to_cpu(serial->dev->descriptor.idProduct) == MCT_U232_SITECOM_PID 181 if (le16_to_cpu(serial->dev->descriptor.idProduct) == MCT_U232_SITECOM_PID
188 || le16_to_cpu(serial->dev->descriptor.idProduct) == MCT_U232_BELKIN_F5U109_PID) { 182 || le16_to_cpu(serial->dev->descriptor.idProduct) == MCT_U232_BELKIN_F5U109_PID) {
189 switch (value) { 183 switch (value) {
190 case 300: return 0x01; 184 case 300:
191 case 600: return 0x02; /* this one not tested */ 185 return 0x01;
192 case 1200: return 0x03; 186 case 600:
193 case 2400: return 0x04; 187 return 0x02; /* this one not tested */
194 case 4800: return 0x06; 188 case 1200:
195 case 9600: return 0x08; 189 return 0x03;
196 case 19200: return 0x09; 190 case 2400:
197 case 38400: return 0x0a; 191 return 0x04;
198 case 57600: return 0x0b; 192 case 4800:
199 case 115200: return 0x0c; 193 return 0x06;
194 case 9600:
195 return 0x08;
196 case 19200:
197 return 0x09;
198 case 38400:
199 return 0x0a;
200 case 57600:
201 return 0x0b;
202 case 115200:
203 return 0x0c;
200 default: 204 default:
201 *result = 9600; 205 *result = 9600;
202 return 0x08; 206 return 0x08;
@@ -224,26 +228,27 @@ static int mct_u232_calculate_baud_rate(struct usb_serial *serial, speed_t value
224 } 228 }
225} 229}
226 230
227static int mct_u232_set_baud_rate(struct usb_serial *serial, struct usb_serial_port *port, 231static int mct_u232_set_baud_rate(struct tty_struct *tty,
228 speed_t value) 232 struct usb_serial *serial, struct usb_serial_port *port, speed_t value)
229{ 233{
230 __le32 divisor; 234 __le32 divisor;
231 int rc; 235 int rc;
232 unsigned char zero_byte = 0; 236 unsigned char zero_byte = 0;
233 unsigned char cts_enable_byte = 0; 237 unsigned char cts_enable_byte = 0;
234 speed_t speed; 238 speed_t speed;
235 239
236 divisor = cpu_to_le32(mct_u232_calculate_baud_rate(serial, value, &speed)); 240 divisor = cpu_to_le32(mct_u232_calculate_baud_rate(serial, value,
237 241 &speed));
238 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 242
239 MCT_U232_SET_BAUD_RATE_REQUEST, 243 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
240 MCT_U232_SET_REQUEST_TYPE, 244 MCT_U232_SET_BAUD_RATE_REQUEST,
241 0, 0, &divisor, MCT_U232_SET_BAUD_RATE_SIZE, 245 MCT_U232_SET_REQUEST_TYPE,
242 WDR_TIMEOUT); 246 0, 0, &divisor, MCT_U232_SET_BAUD_RATE_SIZE,
247 WDR_TIMEOUT);
243 if (rc < 0) /*FIXME: What value speed results */ 248 if (rc < 0) /*FIXME: What value speed results */
244 err("Set BAUD RATE %d failed (error = %d)", value, rc); 249 err("Set BAUD RATE %d failed (error = %d)", value, rc);
245 else 250 else
246 tty_encode_baud_rate(port->tty, speed, speed); 251 tty_encode_baud_rate(tty, speed, speed);
247 dbg("set_baud_rate: value: 0x%x, divisor: 0x%x", value, divisor); 252 dbg("set_baud_rate: value: 0x%x, divisor: 0x%x", value, divisor);
248 253
249 /* Mimic the MCT-supplied Windows driver (version 1.21P.0104), which 254 /* Mimic the MCT-supplied Windows driver (version 1.21P.0104), which
@@ -258,55 +263,55 @@ static int mct_u232_set_baud_rate(struct usb_serial *serial, struct usb_serial_p
258 whether data will be transmitted to a device which is not asserting 263 whether data will be transmitted to a device which is not asserting
259 the 'CTS' signal. If the second message's data byte is zero, data 264 the 'CTS' signal. If the second message's data byte is zero, data
260 will be transmitted even if 'CTS' is not asserted (i.e. no hardware 265 will be transmitted even if 'CTS' is not asserted (i.e. no hardware
261 flow control). if the second message's data byte is nonzero (a value 266 flow control). if the second message's data byte is nonzero (a
262 of 1 is used by this driver), data will not be transmitted to a device 267 value of 1 is used by this driver), data will not be transmitted to
263 which is not asserting 'CTS'. 268 a device which is not asserting 'CTS'.
264 */ 269 */
265 270
266 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 271 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
267 MCT_U232_SET_UNKNOWN1_REQUEST, 272 MCT_U232_SET_UNKNOWN1_REQUEST,
268 MCT_U232_SET_REQUEST_TYPE, 273 MCT_U232_SET_REQUEST_TYPE,
269 0, 0, &zero_byte, MCT_U232_SET_UNKNOWN1_SIZE, 274 0, 0, &zero_byte, MCT_U232_SET_UNKNOWN1_SIZE,
270 WDR_TIMEOUT); 275 WDR_TIMEOUT);
271 if (rc < 0) 276 if (rc < 0)
272 err("Sending USB device request code %d failed (error = %d)", 277 err("Sending USB device request code %d failed (error = %d)",
273 MCT_U232_SET_UNKNOWN1_REQUEST, rc); 278 MCT_U232_SET_UNKNOWN1_REQUEST, rc);
274 279
275 if (port && C_CRTSCTS(port->tty)) { 280 if (port && C_CRTSCTS(tty))
276 cts_enable_byte = 1; 281 cts_enable_byte = 1;
277 }
278 282
279 dbg("set_baud_rate: send second control message, data = %02X", cts_enable_byte); 283 dbg("set_baud_rate: send second control message, data = %02X",
284 cts_enable_byte);
280 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 285 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
281 MCT_U232_SET_CTS_REQUEST, 286 MCT_U232_SET_CTS_REQUEST,
282 MCT_U232_SET_REQUEST_TYPE, 287 MCT_U232_SET_REQUEST_TYPE,
283 0, 0, &cts_enable_byte, MCT_U232_SET_CTS_SIZE, 288 0, 0, &cts_enable_byte, MCT_U232_SET_CTS_SIZE,
284 WDR_TIMEOUT); 289 WDR_TIMEOUT);
285 if (rc < 0) 290 if (rc < 0)
286 err("Sending USB device request code %d failed (error = %d)", 291 err("Sending USB device request code %d failed (error = %d)",
287 MCT_U232_SET_CTS_REQUEST, rc); 292 MCT_U232_SET_CTS_REQUEST, rc);
288 293
289 return rc; 294 return rc;
290} /* mct_u232_set_baud_rate */ 295} /* mct_u232_set_baud_rate */
291 296
292static int mct_u232_set_line_ctrl(struct usb_serial *serial, unsigned char lcr) 297static int mct_u232_set_line_ctrl(struct usb_serial *serial, unsigned char lcr)
293{ 298{
294 int rc; 299 int rc;
295 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 300 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
296 MCT_U232_SET_LINE_CTRL_REQUEST, 301 MCT_U232_SET_LINE_CTRL_REQUEST,
297 MCT_U232_SET_REQUEST_TYPE, 302 MCT_U232_SET_REQUEST_TYPE,
298 0, 0, &lcr, MCT_U232_SET_LINE_CTRL_SIZE, 303 0, 0, &lcr, MCT_U232_SET_LINE_CTRL_SIZE,
299 WDR_TIMEOUT); 304 WDR_TIMEOUT);
300 if (rc < 0) 305 if (rc < 0)
301 err("Set LINE CTRL 0x%x failed (error = %d)", lcr, rc); 306 err("Set LINE CTRL 0x%x failed (error = %d)", lcr, rc);
302 dbg("set_line_ctrl: 0x%x", lcr); 307 dbg("set_line_ctrl: 0x%x", lcr);
303 return rc; 308 return rc;
304} /* mct_u232_set_line_ctrl */ 309} /* mct_u232_set_line_ctrl */
305 310
306static int mct_u232_set_modem_ctrl(struct usb_serial *serial, 311static int mct_u232_set_modem_ctrl(struct usb_serial *serial,
307 unsigned int control_state) 312 unsigned int control_state)
308{ 313{
309 int rc; 314 int rc;
310 unsigned char mcr = MCT_U232_MCR_NONE; 315 unsigned char mcr = MCT_U232_MCR_NONE;
311 316
312 if (control_state & TIOCM_DTR) 317 if (control_state & TIOCM_DTR)
@@ -314,37 +319,39 @@ static int mct_u232_set_modem_ctrl(struct usb_serial *serial,
314 if (control_state & TIOCM_RTS) 319 if (control_state & TIOCM_RTS)
315 mcr |= MCT_U232_MCR_RTS; 320 mcr |= MCT_U232_MCR_RTS;
316 321
317 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 322 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
318 MCT_U232_SET_MODEM_CTRL_REQUEST, 323 MCT_U232_SET_MODEM_CTRL_REQUEST,
319 MCT_U232_SET_REQUEST_TYPE, 324 MCT_U232_SET_REQUEST_TYPE,
320 0, 0, &mcr, MCT_U232_SET_MODEM_CTRL_SIZE, 325 0, 0, &mcr, MCT_U232_SET_MODEM_CTRL_SIZE,
321 WDR_TIMEOUT); 326 WDR_TIMEOUT);
322 if (rc < 0) 327 if (rc < 0)
323 err("Set MODEM CTRL 0x%x failed (error = %d)", mcr, rc); 328 err("Set MODEM CTRL 0x%x failed (error = %d)", mcr, rc);
324 dbg("set_modem_ctrl: state=0x%x ==> mcr=0x%x", control_state, mcr); 329 dbg("set_modem_ctrl: state=0x%x ==> mcr=0x%x", control_state, mcr);
325 330
326 return rc; 331 return rc;
327} /* mct_u232_set_modem_ctrl */ 332} /* mct_u232_set_modem_ctrl */
328 333
329static int mct_u232_get_modem_stat(struct usb_serial *serial, unsigned char *msr) 334static int mct_u232_get_modem_stat(struct usb_serial *serial,
335 unsigned char *msr)
330{ 336{
331 int rc; 337 int rc;
332 rc = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), 338 rc = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
333 MCT_U232_GET_MODEM_STAT_REQUEST, 339 MCT_U232_GET_MODEM_STAT_REQUEST,
334 MCT_U232_GET_REQUEST_TYPE, 340 MCT_U232_GET_REQUEST_TYPE,
335 0, 0, msr, MCT_U232_GET_MODEM_STAT_SIZE, 341 0, 0, msr, MCT_U232_GET_MODEM_STAT_SIZE,
336 WDR_TIMEOUT); 342 WDR_TIMEOUT);
337 if (rc < 0) { 343 if (rc < 0) {
338 err("Get MODEM STATus failed (error = %d)", rc); 344 err("Get MODEM STATus failed (error = %d)", rc);
339 *msr = 0; 345 *msr = 0;
340 } 346 }
341 dbg("get_modem_stat: 0x%x", *msr); 347 dbg("get_modem_stat: 0x%x", *msr);
342 return rc; 348 return rc;
343} /* mct_u232_get_modem_stat */ 349} /* mct_u232_get_modem_stat */
344 350
345static void mct_u232_msr_to_state(unsigned int *control_state, unsigned char msr) 351static void mct_u232_msr_to_state(unsigned int *control_state,
352 unsigned char msr)
346{ 353{
347 /* Translate Control Line states */ 354 /* Translate Control Line states */
348 if (msr & MCT_U232_MSR_DSR) 355 if (msr & MCT_U232_MSR_DSR)
349 *control_state |= TIOCM_DSR; 356 *control_state |= TIOCM_DSR;
350 else 357 else
@@ -361,14 +368,14 @@ static void mct_u232_msr_to_state(unsigned int *control_state, unsigned char msr
361 *control_state |= TIOCM_CD; 368 *control_state |= TIOCM_CD;
362 else 369 else
363 *control_state &= ~TIOCM_CD; 370 *control_state &= ~TIOCM_CD;
364 dbg("msr_to_state: msr=0x%x ==> state=0x%x", msr, *control_state); 371 dbg("msr_to_state: msr=0x%x ==> state=0x%x", msr, *control_state);
365} /* mct_u232_msr_to_state */ 372} /* mct_u232_msr_to_state */
366 373
367/* 374/*
368 * Driver's tty interface functions 375 * Driver's tty interface functions
369 */ 376 */
370 377
371static int mct_u232_startup (struct usb_serial *serial) 378static int mct_u232_startup(struct usb_serial *serial)
372{ 379{
373 struct mct_u232_private *priv; 380 struct mct_u232_private *priv;
374 struct usb_serial_port *port, *rport; 381 struct usb_serial_port *port, *rport;
@@ -390,18 +397,18 @@ static int mct_u232_startup (struct usb_serial *serial)
390 rport->interrupt_in_urb = NULL; 397 rport->interrupt_in_urb = NULL;
391 port->read_urb->context = port; 398 port->read_urb->context = port;
392 399
393 return (0); 400 return 0;
394} /* mct_u232_startup */ 401} /* mct_u232_startup */
395 402
396 403
397static void mct_u232_shutdown (struct usb_serial *serial) 404static void mct_u232_shutdown(struct usb_serial *serial)
398{ 405{
399 struct mct_u232_private *priv; 406 struct mct_u232_private *priv;
400 int i; 407 int i;
401 408
402 dbg("%s", __func__); 409 dbg("%s", __func__);
403 410
404 for (i=0; i < serial->num_ports; ++i) { 411 for (i = 0; i < serial->num_ports; ++i) {
405 /* My special items, the standard routines free my urbs */ 412 /* My special items, the standard routines free my urbs */
406 priv = usb_get_serial_port_data(serial->port[i]); 413 priv = usb_get_serial_port_data(serial->port[i]);
407 if (priv) { 414 if (priv) {
@@ -411,7 +418,8 @@ static void mct_u232_shutdown (struct usb_serial *serial)
411 } 418 }
412} /* mct_u232_shutdown */ 419} /* mct_u232_shutdown */
413 420
414static int mct_u232_open (struct usb_serial_port *port, struct file *filp) 421static int mct_u232_open(struct tty_struct *tty,
422 struct usb_serial_port *port, struct file *filp)
415{ 423{
416 struct usb_serial *serial = port->serial; 424 struct usb_serial *serial = port->serial;
417 struct mct_u232_private *priv = usb_get_serial_port_data(port); 425 struct mct_u232_private *priv = usb_get_serial_port_data(port);
@@ -428,21 +436,22 @@ static int mct_u232_open (struct usb_serial_port *port, struct file *filp)
428 * it seems to be able to accept only 16 bytes (and that's what 436 * it seems to be able to accept only 16 bytes (and that's what
429 * SniffUSB says too...) 437 * SniffUSB says too...)
430 */ 438 */
431 if (le16_to_cpu(serial->dev->descriptor.idProduct) == MCT_U232_SITECOM_PID) 439 if (le16_to_cpu(serial->dev->descriptor.idProduct)
440 == MCT_U232_SITECOM_PID)
432 port->bulk_out_size = 16; 441 port->bulk_out_size = 16;
433 442
434 /* Do a defined restart: the normal serial device seems to 443 /* Do a defined restart: the normal serial device seems to
435 * always turn on DTR and RTS here, so do the same. I'm not 444 * always turn on DTR and RTS here, so do the same. I'm not
436 * sure if this is really necessary. But it should not harm 445 * sure if this is really necessary. But it should not harm
437 * either. 446 * either.
438 */ 447 */
439 spin_lock_irqsave(&priv->lock, flags); 448 spin_lock_irqsave(&priv->lock, flags);
440 if (port->tty->termios->c_cflag & CBAUD) 449 if (tty && (tty->termios->c_cflag & CBAUD))
441 priv->control_state = TIOCM_DTR | TIOCM_RTS; 450 priv->control_state = TIOCM_DTR | TIOCM_RTS;
442 else 451 else
443 priv->control_state = 0; 452 priv->control_state = 0;
444 453
445 priv->last_lcr = (MCT_U232_DATA_BITS_8 | 454 priv->last_lcr = (MCT_U232_DATA_BITS_8 |
446 MCT_U232_PARITY_NONE | 455 MCT_U232_PARITY_NONE |
447 MCT_U232_STOP_BITS_1); 456 MCT_U232_STOP_BITS_1);
448 control_state = priv->control_state; 457 control_state = priv->control_state;
@@ -481,15 +490,16 @@ error:
481} /* mct_u232_open */ 490} /* mct_u232_open */
482 491
483 492
484static void mct_u232_close (struct usb_serial_port *port, struct file *filp) 493static void mct_u232_close(struct tty_struct *tty,
494 struct usb_serial_port *port, struct file *filp)
485{ 495{
486 unsigned int c_cflag; 496 unsigned int c_cflag;
487 unsigned int control_state; 497 unsigned int control_state;
488 struct mct_u232_private *priv = usb_get_serial_port_data(port); 498 struct mct_u232_private *priv = usb_get_serial_port_data(port);
489 dbg("%s port %d", __func__, port->number); 499 dbg("%s port %d", __func__, port->number);
490 500
491 if (port->tty) { 501 if (tty) {
492 c_cflag = port->tty->termios->c_cflag; 502 c_cflag = tty->termios->c_cflag;
493 mutex_lock(&port->serial->disc_mutex); 503 mutex_lock(&port->serial->disc_mutex);
494 if (c_cflag & HUPCL && !port->serial->disconnected) { 504 if (c_cflag & HUPCL && !port->serial->disconnected) {
495 /* drop DTR and RTS */ 505 /* drop DTR and RTS */
@@ -512,7 +522,7 @@ static void mct_u232_close (struct usb_serial_port *port, struct file *filp)
512} /* mct_u232_close */ 522} /* mct_u232_close */
513 523
514 524
515static void mct_u232_read_int_callback (struct urb *urb) 525static void mct_u232_read_int_callback(struct urb *urb)
516{ 526{
517 struct usb_serial_port *port = urb->context; 527 struct usb_serial_port *port = urb->context;
518 struct mct_u232_private *priv = usb_get_serial_port_data(port); 528 struct mct_u232_private *priv = usb_get_serial_port_data(port);
@@ -545,36 +555,34 @@ static void mct_u232_read_int_callback (struct urb *urb)
545 return; 555 return;
546 } 556 }
547 557
548 dbg("%s - port %d", __func__, port->number); 558 dbg("%s - port %d", __func__, port->number);
549 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); 559 usb_serial_debug_data(debug, &port->dev, __func__,
560 urb->actual_length, data);
550 561
551 /* 562 /*
552 * Work-a-round: handle the 'usual' bulk-in pipe here 563 * Work-a-round: handle the 'usual' bulk-in pipe here
553 */ 564 */
554 if (urb->transfer_buffer_length > 2) { 565 if (urb->transfer_buffer_length > 2) {
555 int i; 566 tty = port->port.tty;
556 tty = port->tty;
557 if (urb->actual_length) { 567 if (urb->actual_length) {
558 for (i = 0; i < urb->actual_length ; ++i) { 568 tty_insert_flip_string(tty, data, urb->actual_length);
559 tty_insert_flip_char(tty, data[i], 0);
560 }
561 tty_flip_buffer_push(tty); 569 tty_flip_buffer_push(tty);
562 } 570 }
563 goto exit; 571 goto exit;
564 } 572 }
565 573
566 /* 574 /*
567 * The interrupt-in pipe signals exceptional conditions (modem line 575 * The interrupt-in pipe signals exceptional conditions (modem line
568 * signal changes and errors). data[0] holds MSR, data[1] holds LSR. 576 * signal changes and errors). data[0] holds MSR, data[1] holds LSR.
569 */ 577 */
570 spin_lock_irqsave(&priv->lock, flags); 578 spin_lock_irqsave(&priv->lock, flags);
571 priv->last_msr = data[MCT_U232_MSR_INDEX]; 579 priv->last_msr = data[MCT_U232_MSR_INDEX];
572 580
573 /* Record Control Line states */ 581 /* Record Control Line states */
574 mct_u232_msr_to_state(&priv->control_state, priv->last_msr); 582 mct_u232_msr_to_state(&priv->control_state, priv->last_msr);
575 583
576#if 0 584#if 0
577 /* Not yet handled. See belin_sa.c for further information */ 585 /* Not yet handled. See belkin_sa.c for further information */
578 /* Now to report any errors */ 586 /* Now to report any errors */
579 priv->last_lsr = data[MCT_U232_LSR_INDEX]; 587 priv->last_lsr = data[MCT_U232_LSR_INDEX];
580 /* 588 /*
@@ -583,7 +591,7 @@ static void mct_u232_read_int_callback (struct urb *urb)
583 * to look in to this before committing any code. 591 * to look in to this before committing any code.
584 */ 592 */
585 if (priv->last_lsr & MCT_U232_LSR_ERR) { 593 if (priv->last_lsr & MCT_U232_LSR_ERR) {
586 tty = port->tty; 594 tty = port->port.tty;
587 /* Overrun Error */ 595 /* Overrun Error */
588 if (priv->last_lsr & MCT_U232_LSR_OE) { 596 if (priv->last_lsr & MCT_U232_LSR_OE) {
589 } 597 }
@@ -600,18 +608,19 @@ static void mct_u232_read_int_callback (struct urb *urb)
600#endif 608#endif
601 spin_unlock_irqrestore(&priv->lock, flags); 609 spin_unlock_irqrestore(&priv->lock, flags);
602exit: 610exit:
603 retval = usb_submit_urb (urb, GFP_ATOMIC); 611 retval = usb_submit_urb(urb, GFP_ATOMIC);
604 if (retval) 612 if (retval)
605 err ("%s - usb_submit_urb failed with result %d", 613 err("%s - usb_submit_urb failed with result %d",
606 __func__, retval); 614 __func__, retval);
607} /* mct_u232_read_int_callback */ 615} /* mct_u232_read_int_callback */
608 616
609static void mct_u232_set_termios (struct usb_serial_port *port, 617static void mct_u232_set_termios(struct tty_struct *tty,
610 struct ktermios *old_termios) 618 struct usb_serial_port *port,
619 struct ktermios *old_termios)
611{ 620{
612 struct usb_serial *serial = port->serial; 621 struct usb_serial *serial = port->serial;
613 struct mct_u232_private *priv = usb_get_serial_port_data(port); 622 struct mct_u232_private *priv = usb_get_serial_port_data(port);
614 struct ktermios *termios = port->tty->termios; 623 struct ktermios *termios = tty->termios;
615 unsigned int cflag = termios->c_cflag; 624 unsigned int cflag = termios->c_cflag;
616 unsigned int old_cflag = old_termios->c_cflag; 625 unsigned int old_cflag = old_termios->c_cflag;
617 unsigned long flags; 626 unsigned long flags;
@@ -631,20 +640,20 @@ static void mct_u232_set_termios (struct usb_serial_port *port,
631 * Premature optimization is the root of all evil. 640 * Premature optimization is the root of all evil.
632 */ 641 */
633 642
634 /* reassert DTR and RTS on transition from B0 */ 643 /* reassert DTR and RTS on transition from B0 */
635 if ((old_cflag & CBAUD) == B0) { 644 if ((old_cflag & CBAUD) == B0) {
636 dbg("%s: baud was B0", __func__); 645 dbg("%s: baud was B0", __func__);
637 control_state |= TIOCM_DTR | TIOCM_RTS; 646 control_state |= TIOCM_DTR | TIOCM_RTS;
638 mct_u232_set_modem_ctrl(serial, control_state); 647 mct_u232_set_modem_ctrl(serial, control_state);
639 } 648 }
640 649
641 mct_u232_set_baud_rate(serial, port, tty_get_baud_rate(port->tty)); 650 mct_u232_set_baud_rate(tty, serial, port, tty_get_baud_rate(tty));
642 651
643 if ((cflag & CBAUD) == B0 ) { 652 if ((cflag & CBAUD) == B0) {
644 dbg("%s: baud is B0", __func__); 653 dbg("%s: baud is B0", __func__);
645 /* Drop RTS and DTR */ 654 /* Drop RTS and DTR */
646 control_state &= ~(TIOCM_DTR | TIOCM_RTS); 655 control_state &= ~(TIOCM_DTR | TIOCM_RTS);
647 mct_u232_set_modem_ctrl(serial, control_state); 656 mct_u232_set_modem_ctrl(serial, control_state);
648 } 657 }
649 658
650 /* 659 /*
@@ -689,8 +698,9 @@ static void mct_u232_set_termios (struct usb_serial_port *port,
689 spin_unlock_irqrestore(&priv->lock, flags); 698 spin_unlock_irqrestore(&priv->lock, flags);
690} /* mct_u232_set_termios */ 699} /* mct_u232_set_termios */
691 700
692static void mct_u232_break_ctl( struct usb_serial_port *port, int break_state ) 701static void mct_u232_break_ctl(struct tty_struct *tty, int break_state)
693{ 702{
703 struct usb_serial_port *port = tty->driver_data;
694 struct usb_serial *serial = port->serial; 704 struct usb_serial *serial = port->serial;
695 struct mct_u232_private *priv = usb_get_serial_port_data(port); 705 struct mct_u232_private *priv = usb_get_serial_port_data(port);
696 unsigned char lcr; 706 unsigned char lcr;
@@ -709,12 +719,13 @@ static void mct_u232_break_ctl( struct usb_serial_port *port, int break_state )
709} /* mct_u232_break_ctl */ 719} /* mct_u232_break_ctl */
710 720
711 721
712static int mct_u232_tiocmget (struct usb_serial_port *port, struct file *file) 722static int mct_u232_tiocmget(struct tty_struct *tty, struct file *file)
713{ 723{
724 struct usb_serial_port *port = tty->driver_data;
714 struct mct_u232_private *priv = usb_get_serial_port_data(port); 725 struct mct_u232_private *priv = usb_get_serial_port_data(port);
715 unsigned int control_state; 726 unsigned int control_state;
716 unsigned long flags; 727 unsigned long flags;
717 728
718 dbg("%s", __func__); 729 dbg("%s", __func__);
719 730
720 spin_lock_irqsave(&priv->lock, flags); 731 spin_lock_irqsave(&priv->lock, flags);
@@ -724,14 +735,15 @@ static int mct_u232_tiocmget (struct usb_serial_port *port, struct file *file)
724 return control_state; 735 return control_state;
725} 736}
726 737
727static int mct_u232_tiocmset (struct usb_serial_port *port, struct file *file, 738static int mct_u232_tiocmset(struct tty_struct *tty, struct file *file,
728 unsigned int set, unsigned int clear) 739 unsigned int set, unsigned int clear)
729{ 740{
741 struct usb_serial_port *port = tty->driver_data;
730 struct usb_serial *serial = port->serial; 742 struct usb_serial *serial = port->serial;
731 struct mct_u232_private *priv = usb_get_serial_port_data(port); 743 struct mct_u232_private *priv = usb_get_serial_port_data(port);
732 unsigned int control_state; 744 unsigned int control_state;
733 unsigned long flags; 745 unsigned long flags;
734 746
735 dbg("%s", __func__); 747 dbg("%s", __func__);
736 748
737 spin_lock_irqsave(&priv->lock, flags); 749 spin_lock_irqsave(&priv->lock, flags);
@@ -751,77 +763,50 @@ static int mct_u232_tiocmset (struct usb_serial_port *port, struct file *file,
751 return mct_u232_set_modem_ctrl(serial, control_state); 763 return mct_u232_set_modem_ctrl(serial, control_state);
752} 764}
753 765
754static int mct_u232_ioctl (struct usb_serial_port *port, struct file * file, 766static void mct_u232_throttle(struct tty_struct *tty)
755 unsigned int cmd, unsigned long arg)
756{
757 dbg("%scmd=0x%x", __func__, cmd);
758
759 /* Based on code from acm.c and others */
760 switch (cmd) {
761 case TIOCMIWAIT:
762 /* wait for any of the 4 modem inputs (DCD,RI,DSR,CTS)*/
763 /* TODO */
764 return( 0 );
765
766 case TIOCGICOUNT:
767 /* return count of modemline transitions */
768 /* TODO */
769 return 0;
770
771 default:
772 dbg("%s: arg not supported - 0x%04x", __func__,cmd);
773 return(-ENOIOCTLCMD);
774 break;
775 }
776 return 0;
777} /* mct_u232_ioctl */
778
779static void mct_u232_throttle (struct usb_serial_port *port)
780{ 767{
768 struct usb_serial_port *port = tty->driver_data;
781 struct mct_u232_private *priv = usb_get_serial_port_data(port); 769 struct mct_u232_private *priv = usb_get_serial_port_data(port);
782 unsigned long flags; 770 unsigned long flags;
783 unsigned int control_state; 771 unsigned int control_state;
784 struct tty_struct *tty;
785 772
786 tty = port->tty;
787 dbg("%s - port %d", __func__, port->number); 773 dbg("%s - port %d", __func__, port->number);
788 774
789 spin_lock_irqsave(&priv->lock, flags); 775 spin_lock_irqsave(&priv->lock, flags);
790 priv->rx_flags |= THROTTLED; 776 priv->rx_flags |= THROTTLED;
791 if (C_CRTSCTS(tty)) { 777 if (C_CRTSCTS(tty)) {
792 priv->control_state &= ~TIOCM_RTS; 778 priv->control_state &= ~TIOCM_RTS;
793 control_state = priv->control_state; 779 control_state = priv->control_state;
794 spin_unlock_irqrestore(&priv->lock, flags); 780 spin_unlock_irqrestore(&priv->lock, flags);
795 (void) mct_u232_set_modem_ctrl(port->serial, control_state); 781 (void) mct_u232_set_modem_ctrl(port->serial, control_state);
796 } else { 782 } else {
797 spin_unlock_irqrestore(&priv->lock, flags); 783 spin_unlock_irqrestore(&priv->lock, flags);
798 } 784 }
799} 785}
800 786
801 787
802static void mct_u232_unthrottle (struct usb_serial_port *port) 788static void mct_u232_unthrottle(struct tty_struct *tty)
803{ 789{
790 struct usb_serial_port *port = tty->driver_data;
804 struct mct_u232_private *priv = usb_get_serial_port_data(port); 791 struct mct_u232_private *priv = usb_get_serial_port_data(port);
805 unsigned long flags; 792 unsigned long flags;
806 unsigned int control_state; 793 unsigned int control_state;
807 struct tty_struct *tty;
808 794
809 dbg("%s - port %d", __func__, port->number); 795 dbg("%s - port %d", __func__, port->number);
810 796
811 tty = port->tty;
812 spin_lock_irqsave(&priv->lock, flags); 797 spin_lock_irqsave(&priv->lock, flags);
813 if ((priv->rx_flags & THROTTLED) && C_CRTSCTS(tty)) { 798 if ((priv->rx_flags & THROTTLED) && C_CRTSCTS(tty)) {
814 priv->rx_flags &= ~THROTTLED; 799 priv->rx_flags &= ~THROTTLED;
815 priv->control_state |= TIOCM_RTS; 800 priv->control_state |= TIOCM_RTS;
816 control_state = priv->control_state; 801 control_state = priv->control_state;
817 spin_unlock_irqrestore(&priv->lock, flags); 802 spin_unlock_irqrestore(&priv->lock, flags);
818 (void) mct_u232_set_modem_ctrl(port->serial, control_state); 803 (void) mct_u232_set_modem_ctrl(port->serial, control_state);
819 } else { 804 } else {
820 spin_unlock_irqrestore(&priv->lock, flags); 805 spin_unlock_irqrestore(&priv->lock, flags);
821 } 806 }
822} 807}
823 808
824static int __init mct_u232_init (void) 809static int __init mct_u232_init(void)
825{ 810{
826 int retval; 811 int retval;
827 retval = usb_serial_register(&mct_u232_device); 812 retval = usb_serial_register(&mct_u232_device);
@@ -839,18 +824,17 @@ failed_usb_serial_register:
839} 824}
840 825
841 826
842static void __exit mct_u232_exit (void) 827static void __exit mct_u232_exit(void)
843{ 828{
844 usb_deregister (&mct_u232_driver); 829 usb_deregister(&mct_u232_driver);
845 usb_serial_deregister (&mct_u232_device); 830 usb_serial_deregister(&mct_u232_device);
846} 831}
847 832
848 833module_init(mct_u232_init);
849module_init (mct_u232_init);
850module_exit(mct_u232_exit); 834module_exit(mct_u232_exit);
851 835
852MODULE_AUTHOR( DRIVER_AUTHOR ); 836MODULE_AUTHOR(DRIVER_AUTHOR);
853MODULE_DESCRIPTION( DRIVER_DESC ); 837MODULE_DESCRIPTION(DRIVER_DESC);
854MODULE_LICENSE("GPL"); 838MODULE_LICENSE("GPL");
855 839
856module_param(debug, bool, S_IRUGO | S_IWUSR); 840module_param(debug, bool, S_IRUGO | S_IWUSR);
diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c
index 50f1fe263338..7c4917d77c0a 100644
--- a/drivers/usb/serial/mos7720.c
+++ b/drivers/usb/serial/mos7720.c
@@ -33,7 +33,7 @@
33#include <linux/serial_reg.h> 33#include <linux/serial_reg.h>
34#include <linux/usb.h> 34#include <linux/usb.h>
35#include <linux/usb/serial.h> 35#include <linux/usb/serial.h>
36#include <asm/uaccess.h> 36#include <linux/uaccess.h>
37 37
38 38
39/* 39/*
@@ -64,8 +64,7 @@
64#define URB_TRANSFER_BUFFER_SIZE 32 /* URB Size */ 64#define URB_TRANSFER_BUFFER_SIZE 32 /* URB Size */
65 65
66/* This structure holds all of the local port information */ 66/* This structure holds all of the local port information */
67struct moschip_port 67struct moschip_port {
68{
69 __u8 shadowLCR; /* last LCR value received */ 68 __u8 shadowLCR; /* last LCR value received */
70 __u8 shadowMCR; /* last MCR value received */ 69 __u8 shadowMCR; /* last MCR value received */
71 __u8 shadowMSR; /* last MSR value received */ 70 __u8 shadowMSR; /* last MSR value received */
@@ -76,8 +75,7 @@ struct moschip_port
76}; 75};
77 76
78/* This structure holds all of the individual serial device information */ 77/* This structure holds all of the individual serial device information */
79struct moschip_serial 78struct moschip_serial {
80{
81 int interrupt_started; 79 int interrupt_started;
82}; 80};
83 81
@@ -88,7 +86,7 @@ static int debug;
88#define MOSCHIP_DEVICE_ID_7715 0x7715 86#define MOSCHIP_DEVICE_ID_7715 0x7715
89 87
90static struct usb_device_id moschip_port_id_table [] = { 88static struct usb_device_id moschip_port_id_table [] = {
91 { USB_DEVICE(USB_VENDOR_ID_MOSCHIP,MOSCHIP_DEVICE_ID_7720) }, 89 { USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7720) },
92 { } /* terminating entry */ 90 { } /* terminating entry */
93}; 91};
94MODULE_DEVICE_TABLE(usb, moschip_port_id_table); 92MODULE_DEVICE_TABLE(usb, moschip_port_id_table);
@@ -108,7 +106,7 @@ static void mos7720_interrupt_callback(struct urb *urb)
108 __u8 sp1; 106 __u8 sp1;
109 __u8 sp2; 107 __u8 sp2;
110 108
111 dbg("%s"," : Entering\n"); 109 dbg("%s", " : Entering\n");
112 110
113 switch (status) { 111 switch (status) {
114 case 0: 112 case 0:
@@ -208,7 +206,7 @@ static void mos7720_bulk_in_callback(struct urb *urb)
208 206
209 mos7720_port = urb->context; 207 mos7720_port = urb->context;
210 if (!mos7720_port) { 208 if (!mos7720_port) {
211 dbg("%s","NULL mos7720_port pointer \n"); 209 dbg("%s", "NULL mos7720_port pointer \n");
212 return ; 210 return ;
213 } 211 }
214 212
@@ -218,7 +216,7 @@ static void mos7720_bulk_in_callback(struct urb *urb)
218 216
219 data = urb->transfer_buffer; 217 data = urb->transfer_buffer;
220 218
221 tty = port->tty; 219 tty = port->port.tty;
222 if (tty && urb->actual_length) { 220 if (tty && urb->actual_length) {
223 tty_buffer_request_room(tty, urb->actual_length); 221 tty_buffer_request_room(tty, urb->actual_length);
224 tty_insert_flip_string(tty, data, urb->actual_length); 222 tty_insert_flip_string(tty, data, urb->actual_length);
@@ -264,7 +262,7 @@ static void mos7720_bulk_out_data_callback(struct urb *urb)
264 262
265 dbg("Entering ........."); 263 dbg("Entering .........");
266 264
267 tty = mos7720_port->port->tty; 265 tty = mos7720_port->port->port.tty;
268 266
269 if (tty && mos7720_port->open) 267 if (tty && mos7720_port->open)
270 tty_wakeup(tty); 268 tty_wakeup(tty);
@@ -284,17 +282,16 @@ static int send_mos_cmd(struct usb_serial *serial, __u8 request, __u16 value,
284 __u16 size = 0x0000; 282 __u16 size = 0x0000;
285 283
286 if (value < MOS_MAX_PORT) { 284 if (value < MOS_MAX_PORT) {
287 if (product == MOSCHIP_DEVICE_ID_7715) { 285 if (product == MOSCHIP_DEVICE_ID_7715)
288 value = value*0x100+0x100; 286 value = value*0x100+0x100;
289 } else { 287 else
290 value = value*0x100+0x200; 288 value = value*0x100+0x200;
291 }
292 } else { 289 } else {
293 value = 0x0000; 290 value = 0x0000;
294 if ((product == MOSCHIP_DEVICE_ID_7715) && 291 if ((product == MOSCHIP_DEVICE_ID_7715) &&
295 (index != 0x08)) { 292 (index != 0x08)) {
296 dbg("serial->product== MOSCHIP_DEVICE_ID_7715"); 293 dbg("serial->product== MOSCHIP_DEVICE_ID_7715");
297 //index = 0x01 ; 294 /* index = 0x01 ; */
298 } 295 }
299 } 296 }
300 297
@@ -308,19 +305,20 @@ static int send_mos_cmd(struct usb_serial *serial, __u8 request, __u16 value,
308 request = (__u8)MOS_READ; 305 request = (__u8)MOS_READ;
309 requesttype = (__u8)0xC0; 306 requesttype = (__u8)0xC0;
310 size = 0x01; 307 size = 0x01;
311 pipe = usb_rcvctrlpipe(serial->dev,0); 308 pipe = usb_rcvctrlpipe(serial->dev, 0);
312 } 309 }
313 310
314 status = usb_control_msg(serial->dev, pipe, request, requesttype, 311 status = usb_control_msg(serial->dev, pipe, request, requesttype,
315 value, index, data, size, MOS_WDR_TIMEOUT); 312 value, index, data, size, MOS_WDR_TIMEOUT);
316 313
317 if (status < 0) 314 if (status < 0)
318 dbg("Command Write failed Value %x index %x\n",value,index); 315 dbg("Command Write failed Value %x index %x\n", value, index);
319 316
320 return status; 317 return status;
321} 318}
322 319
323static int mos7720_open(struct usb_serial_port *port, struct file * filp) 320static int mos7720_open(struct tty_struct *tty,
321 struct usb_serial_port *port, struct file *filp)
324{ 322{
325 struct usb_serial *serial; 323 struct usb_serial *serial;
326 struct usb_serial_port *port0; 324 struct usb_serial_port *port0;
@@ -351,7 +349,7 @@ static int mos7720_open(struct usb_serial_port *port, struct file * filp)
351 349
352 /* Initialising the write urb pool */ 350 /* Initialising the write urb pool */
353 for (j = 0; j < NUM_URBS; ++j) { 351 for (j = 0; j < NUM_URBS; ++j) {
354 urb = usb_alloc_urb(0,GFP_KERNEL); 352 urb = usb_alloc_urb(0, GFP_KERNEL);
355 mos7720_port->write_urb_pool[j] = urb; 353 mos7720_port->write_urb_pool[j] = urb;
356 354
357 if (urb == NULL) { 355 if (urb == NULL) {
@@ -385,7 +383,7 @@ static int mos7720_open(struct usb_serial_port *port, struct file * filp)
385 */ 383 */
386 port_number = port->number - port->serial->minor; 384 port_number = port->number - port->serial->minor;
387 send_mos_cmd(port->serial, MOS_READ, port_number, UART_LSR, &data); 385 send_mos_cmd(port->serial, MOS_READ, port_number, UART_LSR, &data);
388 dbg("SS::%p LSR:%x\n",mos7720_port, data); 386 dbg("SS::%p LSR:%x\n", mos7720_port, data);
389 387
390 dbg("Check:Sending Command .........."); 388 dbg("Check:Sending Command ..........");
391 389
@@ -402,10 +400,10 @@ static int mos7720_open(struct usb_serial_port *port, struct file * filp)
402 data = 0xCF; 400 data = 0xCF;
403 send_mos_cmd(serial, MOS_WRITE, port_number, 0x02, &data); 401 send_mos_cmd(serial, MOS_WRITE, port_number, 0x02, &data);
404 data = 0x03; 402 data = 0x03;
405 mos7720_port->shadowLCR = data; 403 mos7720_port->shadowLCR = data;
406 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data); 404 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data);
407 data = 0x0b; 405 data = 0x0b;
408 mos7720_port->shadowMCR = data; 406 mos7720_port->shadowMCR = data;
409 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data); 407 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
410 data = 0x0b; 408 data = 0x0b;
411 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data); 409 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
@@ -420,7 +418,8 @@ static int mos7720_open(struct usb_serial_port *port, struct file * filp)
420 data = 0x03; 418 data = 0x03;
421 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, port_number + 1, &data); 419 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, port_number + 1, &data);
422 data = 0x00; 420 data = 0x00;
423 send_mos_cmd(port->serial, MOS_WRITE, MOS_MAX_PORT, port_number + 1, &data); 421 send_mos_cmd(port->serial, MOS_WRITE, MOS_MAX_PORT,
422 port_number + 1, &data);
424*/ 423*/
425 data = 0x00; 424 data = 0x00;
426 send_mos_cmd(serial, MOS_READ, MOS_MAX_PORT, 0x08, &data); 425 send_mos_cmd(serial, MOS_READ, MOS_MAX_PORT, 0x08, &data);
@@ -429,28 +428,26 @@ static int mos7720_open(struct usb_serial_port *port, struct file * filp)
429 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x08, &data); 428 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x08, &data);
430 429
431 data = 0x83; 430 data = 0x83;
432 mos7720_port->shadowLCR = data; 431 mos7720_port->shadowLCR = data;
433 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data); 432 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data);
434 data = 0x0c; 433 data = 0x0c;
435 send_mos_cmd(serial, MOS_WRITE, port_number, 0x00, &data); 434 send_mos_cmd(serial, MOS_WRITE, port_number, 0x00, &data);
436 data = 0x00; 435 data = 0x00;
437 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data); 436 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data);
438 data = 0x03; 437 data = 0x03;
439 mos7720_port->shadowLCR = data; 438 mos7720_port->shadowLCR = data;
440 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data); 439 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data);
441 data = 0x0c; 440 data = 0x0c;
442 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data); 441 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data);
443 data = 0x0c; 442 data = 0x0c;
444 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data); 443 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data);
445 444
446//Matrix
447
448 /* force low_latency on so that our tty_push actually forces * 445 /* force low_latency on so that our tty_push actually forces *
449 * the data through,otherwise it is scheduled, and with * 446 * the data through,otherwise it is scheduled, and with *
450 * high data rates (like with OHCI) data can get lost. */ 447 * high data rates (like with OHCI) data can get lost. */
451 448
452 if (port->tty) 449 if (tty)
453 port->tty->low_latency = 1; 450 tty->low_latency = 1;
454 451
455 /* see if we've set up our endpoint info yet * 452 /* see if we've set up our endpoint info yet *
456 * (can't set it up in mos7720_startup as the * 453 * (can't set it up in mos7720_startup as the *
@@ -465,15 +462,15 @@ static int mos7720_open(struct usb_serial_port *port, struct file * filp)
465 462
466 /* set up our interrupt urb */ 463 /* set up our interrupt urb */
467 usb_fill_int_urb(port0->interrupt_in_urb, serial->dev, 464 usb_fill_int_urb(port0->interrupt_in_urb, serial->dev,
468 usb_rcvintpipe(serial->dev, 465 usb_rcvintpipe(serial->dev,
469 port->interrupt_in_endpointAddress), 466 port->interrupt_in_endpointAddress),
470 port0->interrupt_in_buffer, 467 port0->interrupt_in_buffer,
471 port0->interrupt_in_urb->transfer_buffer_length, 468 port0->interrupt_in_urb->transfer_buffer_length,
472 mos7720_interrupt_callback, mos7720_port, 469 mos7720_interrupt_callback, mos7720_port,
473 port0->interrupt_in_urb->interval); 470 port0->interrupt_in_urb->interval);
474 471
475 /* start interrupt read for this mos7720 this interrupt * 472 /* start interrupt read for this mos7720 this interrupt *
476 * will continue as long as the mos7720 is connected */ 473 * will continue as long as the mos7720 is connected */
477 dbg("Submit URB over !!!"); 474 dbg("Submit URB over !!!");
478 response = usb_submit_urb(port0->interrupt_in_urb, GFP_KERNEL); 475 response = usb_submit_urb(port0->interrupt_in_urb, GFP_KERNEL);
479 if (response) 476 if (response)
@@ -485,14 +482,14 @@ static int mos7720_open(struct usb_serial_port *port, struct file * filp)
485 /* set up our bulk in urb */ 482 /* set up our bulk in urb */
486 usb_fill_bulk_urb(port->read_urb, serial->dev, 483 usb_fill_bulk_urb(port->read_urb, serial->dev,
487 usb_rcvbulkpipe(serial->dev, 484 usb_rcvbulkpipe(serial->dev,
488 port->bulk_in_endpointAddress), 485 port->bulk_in_endpointAddress),
489 port->bulk_in_buffer, 486 port->bulk_in_buffer,
490 port->read_urb->transfer_buffer_length, 487 port->read_urb->transfer_buffer_length,
491 mos7720_bulk_in_callback, mos7720_port); 488 mos7720_bulk_in_callback, mos7720_port);
492 response = usb_submit_urb(port->read_urb, GFP_KERNEL); 489 response = usb_submit_urb(port->read_urb, GFP_KERNEL);
493 if (response) 490 if (response)
494 dev_err(&port->dev, 491 dev_err(&port->dev, "%s - Error %d submitting read urb\n",
495 "%s - Error %d submitting read urb\n", __func__, response); 492 __func__, response);
496 493
497 /* initialize our icount structure */ 494 /* initialize our icount structure */
498 memset(&(mos7720_port->icount), 0x00, sizeof(mos7720_port->icount)); 495 memset(&(mos7720_port->icount), 0x00, sizeof(mos7720_port->icount));
@@ -515,8 +512,9 @@ static int mos7720_open(struct usb_serial_port *port, struct file * filp)
515 * system, 512 * system,
516 * Otherwise we return a negative error number. 513 * Otherwise we return a negative error number.
517 */ 514 */
518static int mos7720_chars_in_buffer(struct usb_serial_port *port) 515static int mos7720_chars_in_buffer(struct tty_struct *tty)
519{ 516{
517 struct usb_serial_port *port = tty->driver_data;
520 int i; 518 int i;
521 int chars = 0; 519 int chars = 0;
522 struct moschip_port *mos7720_port; 520 struct moschip_port *mos7720_port;
@@ -530,14 +528,16 @@ static int mos7720_chars_in_buffer(struct usb_serial_port *port)
530 } 528 }
531 529
532 for (i = 0; i < NUM_URBS; ++i) { 530 for (i = 0; i < NUM_URBS; ++i) {
533 if (mos7720_port->write_urb_pool[i] && mos7720_port->write_urb_pool[i]->status == -EINPROGRESS) 531 if (mos7720_port->write_urb_pool[i] &&
532 mos7720_port->write_urb_pool[i]->status == -EINPROGRESS)
534 chars += URB_TRANSFER_BUFFER_SIZE; 533 chars += URB_TRANSFER_BUFFER_SIZE;
535 } 534 }
536 dbg("%s - returns %d", __func__, chars); 535 dbg("%s - returns %d", __func__, chars);
537 return chars; 536 return chars;
538} 537}
539 538
540static void mos7720_close(struct usb_serial_port *port, struct file *filp) 539static void mos7720_close(struct tty_struct *tty,
540 struct usb_serial_port *port, struct file *filp)
541{ 541{
542 struct usb_serial *serial; 542 struct usb_serial *serial;
543 struct moschip_port *mos7720_port; 543 struct moschip_port *mos7720_port;
@@ -575,12 +575,12 @@ static void mos7720_close(struct usb_serial_port *port, struct file *filp)
575 * been disconnected */ 575 * been disconnected */
576 if (!serial->disconnected) { 576 if (!serial->disconnected) {
577 data = 0x00; 577 data = 0x00;
578 send_mos_cmd(serial, MOS_WRITE, port->number - port->serial->minor, 578 send_mos_cmd(serial, MOS_WRITE,
579 0x04, &data); 579 port->number - port->serial->minor, 0x04, &data);
580 580
581 data = 0x00; 581 data = 0x00;
582 send_mos_cmd(serial, MOS_WRITE, port->number - port->serial->minor, 582 send_mos_cmd(serial, MOS_WRITE,
583 0x01, &data); 583 port->number - port->serial->minor, 0x01, &data);
584 } 584 }
585 mutex_unlock(&serial->disc_mutex); 585 mutex_unlock(&serial->disc_mutex);
586 mos7720_port->open = 0; 586 mos7720_port->open = 0;
@@ -588,9 +588,10 @@ static void mos7720_close(struct usb_serial_port *port, struct file *filp)
588 dbg("Leaving %s", __func__); 588 dbg("Leaving %s", __func__);
589} 589}
590 590
591static void mos7720_break(struct usb_serial_port *port, int break_state) 591static void mos7720_break(struct tty_struct *tty, int break_state)
592{ 592{
593 unsigned char data; 593 struct usb_serial_port *port = tty->driver_data;
594 unsigned char data;
594 struct usb_serial *serial; 595 struct usb_serial *serial;
595 struct moschip_port *mos7720_port; 596 struct moschip_port *mos7720_port;
596 597
@@ -621,8 +622,9 @@ static void mos7720_break(struct usb_serial_port *port, int break_state)
621 * If successful, we return the amount of room that we have for this port 622 * If successful, we return the amount of room that we have for this port
622 * Otherwise we return a negative error number. 623 * Otherwise we return a negative error number.
623 */ 624 */
624static int mos7720_write_room(struct usb_serial_port *port) 625static int mos7720_write_room(struct tty_struct *tty)
625{ 626{
627 struct usb_serial_port *port = tty->driver_data;
626 struct moschip_port *mos7720_port; 628 struct moschip_port *mos7720_port;
627 int room = 0; 629 int room = 0;
628 int i; 630 int i;
@@ -637,7 +639,8 @@ static int mos7720_write_room(struct usb_serial_port *port)
637 639
638 /* FIXME: Locking */ 640 /* FIXME: Locking */
639 for (i = 0; i < NUM_URBS; ++i) { 641 for (i = 0; i < NUM_URBS; ++i) {
640 if (mos7720_port->write_urb_pool[i] && mos7720_port->write_urb_pool[i]->status != -EINPROGRESS) 642 if (mos7720_port->write_urb_pool[i] &&
643 mos7720_port->write_urb_pool[i]->status != -EINPROGRESS)
641 room += URB_TRANSFER_BUFFER_SIZE; 644 room += URB_TRANSFER_BUFFER_SIZE;
642 } 645 }
643 646
@@ -645,8 +648,8 @@ static int mos7720_write_room(struct usb_serial_port *port)
645 return room; 648 return room;
646} 649}
647 650
648static int mos7720_write(struct usb_serial_port *port, 651static int mos7720_write(struct tty_struct *tty, struct usb_serial_port *port,
649 const unsigned char *data, int count) 652 const unsigned char *data, int count)
650{ 653{
651 int status; 654 int status;
652 int i; 655 int i;
@@ -672,9 +675,10 @@ static int mos7720_write(struct usb_serial_port *port,
672 urb = NULL; 675 urb = NULL;
673 676
674 for (i = 0; i < NUM_URBS; ++i) { 677 for (i = 0; i < NUM_URBS; ++i) {
675 if (mos7720_port->write_urb_pool[i] && mos7720_port->write_urb_pool[i]->status != -EINPROGRESS) { 678 if (mos7720_port->write_urb_pool[i] &&
679 mos7720_port->write_urb_pool[i]->status != -EINPROGRESS) {
676 urb = mos7720_port->write_urb_pool[i]; 680 urb = mos7720_port->write_urb_pool[i];
677 dbg("URB:%d",i); 681 dbg("URB:%d", i);
678 break; 682 break;
679 } 683 }
680 } 684 }
@@ -692,7 +696,7 @@ static int mos7720_write(struct usb_serial_port *port,
692 goto exit; 696 goto exit;
693 } 697 }
694 } 698 }
695 transfer_size = min (count, URB_TRANSFER_BUFFER_SIZE); 699 transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE);
696 700
697 memcpy(urb->transfer_buffer, current_position, transfer_size); 701 memcpy(urb->transfer_buffer, current_position, transfer_size);
698 usb_serial_debug_data(debug, &port->dev, __func__, transfer_size, 702 usb_serial_debug_data(debug, &port->dev, __func__, transfer_size,
@@ -701,12 +705,12 @@ static int mos7720_write(struct usb_serial_port *port,
701 /* fill urb with data and submit */ 705 /* fill urb with data and submit */
702 usb_fill_bulk_urb(urb, serial->dev, 706 usb_fill_bulk_urb(urb, serial->dev,
703 usb_sndbulkpipe(serial->dev, 707 usb_sndbulkpipe(serial->dev,
704 port->bulk_out_endpointAddress), 708 port->bulk_out_endpointAddress),
705 urb->transfer_buffer, transfer_size, 709 urb->transfer_buffer, transfer_size,
706 mos7720_bulk_out_data_callback, mos7720_port); 710 mos7720_bulk_out_data_callback, mos7720_port);
707 711
708 /* send it down the pipe */ 712 /* send it down the pipe */
709 status = usb_submit_urb(urb,GFP_ATOMIC); 713 status = usb_submit_urb(urb, GFP_ATOMIC);
710 if (status) { 714 if (status) {
711 err("%s - usb_submit_urb(write bulk) failed with status = %d", 715 err("%s - usb_submit_urb(write bulk) failed with status = %d",
712 __func__, status); 716 __func__, status);
@@ -719,10 +723,10 @@ exit:
719 return bytes_sent; 723 return bytes_sent;
720} 724}
721 725
722static void mos7720_throttle(struct usb_serial_port *port) 726static void mos7720_throttle(struct tty_struct *tty)
723{ 727{
728 struct usb_serial_port *port = tty->driver_data;
724 struct moschip_port *mos7720_port; 729 struct moschip_port *mos7720_port;
725 struct tty_struct *tty;
726 int status; 730 int status;
727 731
728 dbg("%s- port %d\n", __func__, port->number); 732 dbg("%s- port %d\n", __func__, port->number);
@@ -739,16 +743,10 @@ static void mos7720_throttle(struct usb_serial_port *port)
739 743
740 dbg("%s: Entering ..........", __func__); 744 dbg("%s: Entering ..........", __func__);
741 745
742 tty = port->tty;
743 if (!tty) {
744 dbg("%s - no tty available", __func__);
745 return;
746 }
747
748 /* if we are implementing XON/XOFF, send the stop character */ 746 /* if we are implementing XON/XOFF, send the stop character */
749 if (I_IXOFF(tty)) { 747 if (I_IXOFF(tty)) {
750 unsigned char stop_char = STOP_CHAR(tty); 748 unsigned char stop_char = STOP_CHAR(tty);
751 status = mos7720_write(port, &stop_char, 1); 749 status = mos7720_write(tty, port, &stop_char, 1);
752 if (status <= 0) 750 if (status <= 0)
753 return; 751 return;
754 } 752 }
@@ -764,11 +762,11 @@ static void mos7720_throttle(struct usb_serial_port *port)
764 } 762 }
765} 763}
766 764
767static void mos7720_unthrottle(struct usb_serial_port *port) 765static void mos7720_unthrottle(struct tty_struct *tty)
768{ 766{
769 struct tty_struct *tty; 767 struct usb_serial_port *port = tty->driver_data;
770 int status;
771 struct moschip_port *mos7720_port = usb_get_serial_port_data(port); 768 struct moschip_port *mos7720_port = usb_get_serial_port_data(port);
769 int status;
772 770
773 if (mos7720_port == NULL) 771 if (mos7720_port == NULL)
774 return; 772 return;
@@ -780,16 +778,10 @@ static void mos7720_unthrottle(struct usb_serial_port *port)
780 778
781 dbg("%s: Entering ..........", __func__); 779 dbg("%s: Entering ..........", __func__);
782 780
783 tty = port->tty;
784 if (!tty) {
785 dbg("%s - no tty available", __func__);
786 return;
787 }
788
789 /* if we are implementing XON/XOFF, send the start character */ 781 /* if we are implementing XON/XOFF, send the start character */
790 if (I_IXOFF(tty)) { 782 if (I_IXOFF(tty)) {
791 unsigned char start_char = START_CHAR(tty); 783 unsigned char start_char = START_CHAR(tty);
792 status = mos7720_write(port, &start_char, 1); 784 status = mos7720_write(tty, port, &start_char, 1);
793 if (status <= 0) 785 if (status <= 0)
794 return; 786 return;
795 } 787 }
@@ -819,9 +811,9 @@ static int set_higher_rates(struct moschip_port *mos7720_port,
819 port = mos7720_port->port; 811 port = mos7720_port->port;
820 serial = port->serial; 812 serial = port->serial;
821 813
822 /*********************************************** 814 /***********************************************
823 * Init Sequence for higher rates 815 * Init Sequence for higher rates
824 ***********************************************/ 816 ***********************************************/
825 dbg("Sending Setting Commands .........."); 817 dbg("Sending Setting Commands ..........");
826 port_number = port->number - port->serial->minor; 818 port_number = port->number - port->serial->minor;
827 819
@@ -832,7 +824,7 @@ static int set_higher_rates(struct moschip_port *mos7720_port,
832 data = 0x0CF; 824 data = 0x0CF;
833 send_mos_cmd(serial, MOS_WRITE, port->number, 0x02, &data); 825 send_mos_cmd(serial, MOS_WRITE, port->number, 0x02, &data);
834 data = 0x00b; 826 data = 0x00b;
835 mos7720_port->shadowMCR = data; 827 mos7720_port->shadowMCR = data;
836 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data); 828 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
837 data = 0x00b; 829 data = 0x00b;
838 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data); 830 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
@@ -843,12 +835,12 @@ static int set_higher_rates(struct moschip_port *mos7720_port,
843 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x08, &data); 835 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x08, &data);
844 836
845 837
846 /*********************************************** 838 /***********************************************
847 * Set for higher rates * 839 * Set for higher rates *
848 ***********************************************/ 840 ***********************************************/
849 841
850 data = baud * 0x10; 842 data = baud * 0x10;
851 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, port_number + 1,&data); 843 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, port_number + 1, &data);
852 844
853 data = 0x003; 845 data = 0x003;
854 send_mos_cmd(serial, MOS_READ, MOS_MAX_PORT, 0x08, &data); 846 send_mos_cmd(serial, MOS_READ, MOS_MAX_PORT, 0x08, &data);
@@ -856,34 +848,33 @@ static int set_higher_rates(struct moschip_port *mos7720_port,
856 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x08, &data); 848 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x08, &data);
857 849
858 data = 0x02b; 850 data = 0x02b;
859 mos7720_port->shadowMCR = data; 851 mos7720_port->shadowMCR = data;
860 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data); 852 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
861 data = 0x02b; 853 data = 0x02b;
862 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data); 854 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
863 855
864 /*********************************************** 856 /***********************************************
865 * Set DLL/DLM 857 * Set DLL/DLM
866 ***********************************************/ 858 ***********************************************/
867 859
868 data = mos7720_port->shadowLCR | UART_LCR_DLAB; 860 data = mos7720_port->shadowLCR | UART_LCR_DLAB;
869 mos7720_port->shadowLCR = data; 861 mos7720_port->shadowLCR = data;
870 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data); 862 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data);
871 863
872 data = 0x001; /* DLL */ 864 data = 0x001; /* DLL */
873 send_mos_cmd(serial, MOS_WRITE, port_number, 0x00, &data); 865 send_mos_cmd(serial, MOS_WRITE, port_number, 0x00, &data);
874 data = 0x000; /* DLM */ 866 data = 0x000; /* DLM */
875 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data); 867 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data);
876 868
877 data = mos7720_port->shadowLCR & ~UART_LCR_DLAB; 869 data = mos7720_port->shadowLCR & ~UART_LCR_DLAB;
878 mos7720_port->shadowLCR = data; 870 mos7720_port->shadowLCR = data;
879 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data); 871 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data);
880 872
881 return 0; 873 return 0;
882} 874}
883 875
884/* baud rate information */ 876/* baud rate information */
885struct divisor_table_entry 877struct divisor_table_entry {
886{
887 __u32 baudrate; 878 __u32 baudrate;
888 __u16 divisor; 879 __u16 divisor;
889}; 880};
@@ -932,8 +923,8 @@ static int calc_baud_rate_divisor(int baudrate, int *divisor)
932 } 923 }
933 } 924 }
934 925
935 /* After trying for all the standard baud rates * 926 /* After trying for all the standard baud rates *
936 * Try calculating the divisor for this baud rate */ 927 * Try calculating the divisor for this baud rate */
937 if (baudrate > 75 && baudrate < 230400) { 928 if (baudrate > 75 && baudrate < 230400) {
938 /* get the divisor */ 929 /* get the divisor */
939 custom = (__u16)(230400L / baudrate); 930 custom = (__u16)(230400L / baudrate);
@@ -945,7 +936,7 @@ static int calc_baud_rate_divisor(int baudrate, int *divisor)
945 custom++; 936 custom++;
946 *divisor = custom; 937 *divisor = custom;
947 938
948 dbg("Baud %d = %d",baudrate, custom); 939 dbg("Baud %d = %d", baudrate, custom);
949 return 0; 940 return 0;
950 } 941 }
951 942
@@ -979,29 +970,29 @@ static int send_cmd_write_baud_rate(struct moschip_port *mos7720_port,
979 number = port->number - port->serial->minor; 970 number = port->number - port->serial->minor;
980 dbg("%s - port = %d, baud = %d", __func__, port->number, baudrate); 971 dbg("%s - port = %d, baud = %d", __func__, port->number, baudrate);
981 972
982 /* Calculate the Divisor */ 973 /* Calculate the Divisor */
983 status = calc_baud_rate_divisor(baudrate, &divisor); 974 status = calc_baud_rate_divisor(baudrate, &divisor);
984 if (status) { 975 if (status) {
985 err("%s - bad baud rate", __func__); 976 err("%s - bad baud rate", __func__);
986 return status; 977 return status;
987 } 978 }
988 979
989 /* Enable access to divisor latch */ 980 /* Enable access to divisor latch */
990 data = mos7720_port->shadowLCR | UART_LCR_DLAB; 981 data = mos7720_port->shadowLCR | UART_LCR_DLAB;
991 mos7720_port->shadowLCR = data; 982 mos7720_port->shadowLCR = data;
992 send_mos_cmd(serial, MOS_WRITE, number, UART_LCR, &data); 983 send_mos_cmd(serial, MOS_WRITE, number, UART_LCR, &data);
993 984
994 /* Write the divisor */ 985 /* Write the divisor */
995 data = ((unsigned char)(divisor & 0xff)); 986 data = ((unsigned char)(divisor & 0xff));
996 send_mos_cmd(serial, MOS_WRITE, number, 0x00, &data); 987 send_mos_cmd(serial, MOS_WRITE, number, 0x00, &data);
997 988
998 data = ((unsigned char)((divisor & 0xff00) >> 8)); 989 data = ((unsigned char)((divisor & 0xff00) >> 8));
999 send_mos_cmd(serial, MOS_WRITE, number, 0x01, &data); 990 send_mos_cmd(serial, MOS_WRITE, number, 0x01, &data);
1000 991
1001 /* Disable access to divisor latch */ 992 /* Disable access to divisor latch */
1002 data = mos7720_port->shadowLCR & ~UART_LCR_DLAB; 993 data = mos7720_port->shadowLCR & ~UART_LCR_DLAB;
1003 mos7720_port->shadowLCR = data; 994 mos7720_port->shadowLCR = data;
1004 send_mos_cmd(serial, MOS_WRITE, number, 0x03, &data); 995 send_mos_cmd(serial, MOS_WRITE, number, 0x03, &data);
1005 996
1006 return status; 997 return status;
1007} 998}
@@ -1011,12 +1002,12 @@ static int send_cmd_write_baud_rate(struct moschip_port *mos7720_port,
1011 * This routine is called to set the UART on the device to match 1002 * This routine is called to set the UART on the device to match
1012 * the specified new settings. 1003 * the specified new settings.
1013 */ 1004 */
1014static void change_port_settings(struct moschip_port *mos7720_port, 1005static void change_port_settings(struct tty_struct *tty,
1006 struct moschip_port *mos7720_port,
1015 struct ktermios *old_termios) 1007 struct ktermios *old_termios)
1016{ 1008{
1017 struct usb_serial_port *port; 1009 struct usb_serial_port *port;
1018 struct usb_serial *serial; 1010 struct usb_serial *serial;
1019 struct tty_struct *tty;
1020 int baud; 1011 int baud;
1021 unsigned cflag; 1012 unsigned cflag;
1022 unsigned iflag; 1013 unsigned iflag;
@@ -1042,8 +1033,6 @@ static void change_port_settings(struct moschip_port *mos7720_port,
1042 return; 1033 return;
1043 } 1034 }
1044 1035
1045 tty = mos7720_port->port->tty;
1046
1047 dbg("%s: Entering ..........", __func__); 1036 dbg("%s: Entering ..........", __func__);
1048 1037
1049 lData = UART_LCR_WLEN8; 1038 lData = UART_LCR_WLEN8;
@@ -1106,29 +1095,31 @@ static void change_port_settings(struct moschip_port *mos7720_port,
1106#define LCR_PAR_MASK 0x38 /* Mask for parity field */ 1095#define LCR_PAR_MASK 0x38 /* Mask for parity field */
1107 1096
1108 /* Update the LCR with the correct value */ 1097 /* Update the LCR with the correct value */
1109 mos7720_port->shadowLCR &= ~(LCR_BITS_MASK | LCR_STOP_MASK | LCR_PAR_MASK); 1098 mos7720_port->shadowLCR &=
1099 ~(LCR_BITS_MASK | LCR_STOP_MASK | LCR_PAR_MASK);
1110 mos7720_port->shadowLCR |= (lData | lParity | lStop); 1100 mos7720_port->shadowLCR |= (lData | lParity | lStop);
1111 1101
1112 1102
1113 /* Disable Interrupts */ 1103 /* Disable Interrupts */
1114 data = 0x00; 1104 data = 0x00;
1115 send_mos_cmd(serial,MOS_WRITE,port->number - port->serial->minor, UART_IER, &data); 1105 send_mos_cmd(serial, MOS_WRITE, port->number - port->serial->minor,
1106 UART_IER, &data);
1116 1107
1117 data = 0x00; 1108 data = 0x00;
1118 send_mos_cmd(serial, MOS_WRITE, port_number, UART_FCR, &data); 1109 send_mos_cmd(serial, MOS_WRITE, port_number, UART_FCR, &data);
1119 1110
1120 data = 0xcf; 1111 data = 0xcf;
1121 send_mos_cmd(serial, MOS_WRITE, port_number, UART_FCR, &data); 1112 send_mos_cmd(serial, MOS_WRITE, port_number, UART_FCR, &data);
1122 1113
1123 /* Send the updated LCR value to the mos7720 */ 1114 /* Send the updated LCR value to the mos7720 */
1124 data = mos7720_port->shadowLCR; 1115 data = mos7720_port->shadowLCR;
1125 send_mos_cmd(serial, MOS_WRITE, port_number, UART_LCR, &data); 1116 send_mos_cmd(serial, MOS_WRITE, port_number, UART_LCR, &data);
1126 1117
1127 data = 0x00b; 1118 data = 0x00b;
1128 mos7720_port->shadowMCR = data; 1119 mos7720_port->shadowMCR = data;
1129 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data); 1120 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
1130 data = 0x00b; 1121 data = 0x00b;
1131 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data); 1122 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
1132 1123
1133 /* set up the MCR register and send it to the mos7720 */ 1124 /* set up the MCR register and send it to the mos7720 */
1134 mos7720_port->shadowMCR = UART_MCR_OUT2; 1125 mos7720_port->shadowMCR = UART_MCR_OUT2;
@@ -1137,9 +1128,8 @@ static void change_port_settings(struct moschip_port *mos7720_port,
1137 1128
1138 if (cflag & CRTSCTS) { 1129 if (cflag & CRTSCTS) {
1139 mos7720_port->shadowMCR |= (UART_MCR_XONANY); 1130 mos7720_port->shadowMCR |= (UART_MCR_XONANY);
1140 1131 /* To set hardware flow control to the specified *
1141 /* To set hardware flow control to the specified * 1132 * serial port, in SP1/2_CONTROL_REG */
1142 * serial port, in SP1/2_CONTROL_REG */
1143 if (port->number) { 1133 if (port->number) {
1144 data = 0x001; 1134 data = 0x001;
1145 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 1135 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT,
@@ -1198,14 +1188,13 @@ static void change_port_settings(struct moschip_port *mos7720_port,
1198 * this function is called by the tty driver when it wants to change the 1188 * this function is called by the tty driver when it wants to change the
1199 * termios structure. 1189 * termios structure.
1200 */ 1190 */
1201static void mos7720_set_termios(struct usb_serial_port *port, 1191static void mos7720_set_termios(struct tty_struct *tty,
1202 struct ktermios *old_termios) 1192 struct usb_serial_port *port, struct ktermios *old_termios)
1203{ 1193{
1204 int status; 1194 int status;
1205 unsigned int cflag; 1195 unsigned int cflag;
1206 struct usb_serial *serial; 1196 struct usb_serial *serial;
1207 struct moschip_port *mos7720_port; 1197 struct moschip_port *mos7720_port;
1208 struct tty_struct *tty;
1209 1198
1210 serial = port->serial; 1199 serial = port->serial;
1211 1200
@@ -1214,15 +1203,12 @@ static void mos7720_set_termios(struct usb_serial_port *port,
1214 if (mos7720_port == NULL) 1203 if (mos7720_port == NULL)
1215 return; 1204 return;
1216 1205
1217 tty = port->tty;
1218
1219
1220 if (!mos7720_port->open) { 1206 if (!mos7720_port->open) {
1221 dbg("%s - port not opened", __func__); 1207 dbg("%s - port not opened", __func__);
1222 return; 1208 return;
1223 } 1209 }
1224 1210
1225 dbg("%s\n","setting termios - ASPIRE"); 1211 dbg("%s\n", "setting termios - ASPIRE");
1226 1212
1227 cflag = tty->termios->c_cflag; 1213 cflag = tty->termios->c_cflag;
1228 1214
@@ -1237,14 +1223,14 @@ static void mos7720_set_termios(struct usb_serial_port *port,
1237 dbg("%s - port %d", __func__, port->number); 1223 dbg("%s - port %d", __func__, port->number);
1238 1224
1239 /* change the port settings to the new ones specified */ 1225 /* change the port settings to the new ones specified */
1240 change_port_settings(mos7720_port, old_termios); 1226 change_port_settings(tty, mos7720_port, old_termios);
1241 1227
1242 if(!port->read_urb) { 1228 if (!port->read_urb) {
1243 dbg("%s","URB KILLED !!!!!\n"); 1229 dbg("%s", "URB KILLED !!!!!\n");
1244 return; 1230 return;
1245 } 1231 }
1246 1232
1247 if(port->read_urb->status != -EINPROGRESS) { 1233 if (port->read_urb->status != -EINPROGRESS) {
1248 port->read_urb->dev = serial->dev; 1234 port->read_urb->dev = serial->dev;
1249 status = usb_submit_urb(port->read_urb, GFP_ATOMIC); 1235 status = usb_submit_urb(port->read_urb, GFP_ATOMIC);
1250 if (status) 1236 if (status)
@@ -1264,13 +1250,13 @@ static void mos7720_set_termios(struct usb_serial_port *port,
1264 * transmit holding register is empty. This functionality 1250 * transmit holding register is empty. This functionality
1265 * allows an RS485 driver to be written in user space. 1251 * allows an RS485 driver to be written in user space.
1266 */ 1252 */
1267static int get_lsr_info(struct moschip_port *mos7720_port, 1253static int get_lsr_info(struct tty_struct *tty,
1268 unsigned int __user *value) 1254 struct moschip_port *mos7720_port, unsigned int __user *value)
1269{ 1255{
1270 int count; 1256 int count;
1271 unsigned int result = 0; 1257 unsigned int result = 0;
1272 1258
1273 count = mos7720_chars_in_buffer(mos7720_port->port); 1259 count = mos7720_chars_in_buffer(tty);
1274 if (count == 0) { 1260 if (count == 0) {
1275 dbg("%s -- Empty", __func__); 1261 dbg("%s -- Empty", __func__);
1276 result = TIOCSER_TEMT; 1262 result = TIOCSER_TEMT;
@@ -1290,7 +1276,7 @@ static int get_number_bytes_avail(struct moschip_port *mos7720_port,
1290 unsigned int __user *value) 1276 unsigned int __user *value)
1291{ 1277{
1292 unsigned int result = 0; 1278 unsigned int result = 0;
1293 struct tty_struct *tty = mos7720_port->port->tty; 1279 struct tty_struct *tty = mos7720_port->port->port.tty;
1294 1280
1295 if (!tty) 1281 if (!tty)
1296 return -ENOIOCTLCMD; 1282 return -ENOIOCTLCMD;
@@ -1316,7 +1302,7 @@ static int set_modem_info(struct moschip_port *mos7720_port, unsigned int cmd,
1316 if (mos7720_port == NULL) 1302 if (mos7720_port == NULL)
1317 return -1; 1303 return -1;
1318 1304
1319 port = (struct usb_serial_port*)mos7720_port->port; 1305 port = (struct usb_serial_port *)mos7720_port->port;
1320 mcr = mos7720_port->shadowMCR; 1306 mcr = mos7720_port->shadowMCR;
1321 1307
1322 if (copy_from_user(&arg, value, sizeof(int))) 1308 if (copy_from_user(&arg, value, sizeof(int)))
@@ -1397,7 +1383,7 @@ static int get_serial_info(struct moschip_port *mos7720_port,
1397 tmp.port = mos7720_port->port->number; 1383 tmp.port = mos7720_port->port->number;
1398 tmp.irq = 0; 1384 tmp.irq = 0;
1399 tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ; 1385 tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
1400 tmp.xmit_fifo_size = NUM_URBS * URB_TRANSFER_BUFFER_SIZE; 1386 tmp.xmit_fifo_size = NUM_URBS * URB_TRANSFER_BUFFER_SIZE;
1401 tmp.baud_base = 9600; 1387 tmp.baud_base = 9600;
1402 tmp.close_delay = 5*HZ; 1388 tmp.close_delay = 5*HZ;
1403 tmp.closing_wait = 30*HZ; 1389 tmp.closing_wait = 30*HZ;
@@ -1407,9 +1393,10 @@ static int get_serial_info(struct moschip_port *mos7720_port,
1407 return 0; 1393 return 0;
1408} 1394}
1409 1395
1410static int mos7720_ioctl(struct usb_serial_port *port, struct file *file, 1396static int mos7720_ioctl(struct tty_struct *tty, struct file *file,
1411 unsigned int cmd, unsigned long arg) 1397 unsigned int cmd, unsigned long arg)
1412{ 1398{
1399 struct usb_serial_port *port = tty->driver_data;
1413 struct moschip_port *mos7720_port; 1400 struct moschip_port *mos7720_port;
1414 struct async_icount cnow; 1401 struct async_icount cnow;
1415 struct async_icount cprev; 1402 struct async_icount cprev;
@@ -1431,14 +1418,16 @@ static int mos7720_ioctl(struct usb_serial_port *port, struct file *file,
1431 1418
1432 case TIOCSERGETLSR: 1419 case TIOCSERGETLSR:
1433 dbg("%s (%d) TIOCSERGETLSR", __func__, port->number); 1420 dbg("%s (%d) TIOCSERGETLSR", __func__, port->number);
1434 return get_lsr_info(mos7720_port, (unsigned int __user *)arg); 1421 return get_lsr_info(tty, mos7720_port,
1422 (unsigned int __user *)arg);
1435 return 0; 1423 return 0;
1436 1424
1425 /* FIXME: These should be using the mode methods */
1437 case TIOCMBIS: 1426 case TIOCMBIS:
1438 case TIOCMBIC: 1427 case TIOCMBIC:
1439 case TIOCMSET: 1428 case TIOCMSET:
1440 dbg("%s (%d) TIOCMSET/TIOCMBIC/TIOCMSET", __func__, 1429 dbg("%s (%d) TIOCMSET/TIOCMBIC/TIOCMSET",
1441 port->number); 1430 __func__, port->number);
1442 return set_modem_info(mos7720_port, cmd, 1431 return set_modem_info(mos7720_port, cmd,
1443 (unsigned int __user *)arg); 1432 (unsigned int __user *)arg);
1444 1433
@@ -1452,10 +1441,6 @@ static int mos7720_ioctl(struct usb_serial_port *port, struct file *file,
1452 return get_serial_info(mos7720_port, 1441 return get_serial_info(mos7720_port,
1453 (struct serial_struct __user *)arg); 1442 (struct serial_struct __user *)arg);
1454 1443
1455 case TIOCSSERIAL:
1456 dbg("%s (%d) TIOCSSERIAL", __func__, port->number);
1457 break;
1458
1459 case TIOCMIWAIT: 1444 case TIOCMIWAIT:
1460 dbg("%s (%d) TIOCMIWAIT", __func__, port->number); 1445 dbg("%s (%d) TIOCMIWAIT", __func__, port->number);
1461 cprev = mos7720_port->icount; 1446 cprev = mos7720_port->icount;
@@ -1469,7 +1454,7 @@ static int mos7720_ioctl(struct usb_serial_port *port, struct file *file,
1469 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) || 1454 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
1470 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) || 1455 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
1471 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) || 1456 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
1472 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) { 1457 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
1473 return 0; 1458 return 0;
1474 } 1459 }
1475 cprev = cnow; 1460 cprev = cnow;
@@ -1492,7 +1477,7 @@ static int mos7720_ioctl(struct usb_serial_port *port, struct file *file,
1492 icount.buf_overrun = cnow.buf_overrun; 1477 icount.buf_overrun = cnow.buf_overrun;
1493 1478
1494 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __func__, 1479 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __func__,
1495 port->number, icount.rx, icount.tx ); 1480 port->number, icount.rx, icount.tx);
1496 if (copy_to_user((void __user *)arg, &icount, sizeof(icount))) 1481 if (copy_to_user((void __user *)arg, &icount, sizeof(icount)))
1497 return -EFAULT; 1482 return -EFAULT;
1498 return 0; 1483 return 0;
@@ -1543,7 +1528,8 @@ static int mos7720_startup(struct usb_serial *serial)
1543 /* Initialize all port interrupt end point to port 0 int 1528 /* Initialize all port interrupt end point to port 0 int
1544 * endpoint. Our device has only one interrupt endpoint 1529 * endpoint. Our device has only one interrupt endpoint
1545 * comman to all ports */ 1530 * comman to all ports */
1546 serial->port[i]->interrupt_in_endpointAddress = serial->port[0]->interrupt_in_endpointAddress; 1531 serial->port[i]->interrupt_in_endpointAddress =
1532 serial->port[0]->interrupt_in_endpointAddress;
1547 1533
1548 mos7720_port->port = serial->port[i]; 1534 mos7720_port->port = serial->port[i];
1549 usb_set_serial_port_data(serial->port[i], mos7720_port); 1535 usb_set_serial_port_data(serial->port[i], mos7720_port);
@@ -1555,13 +1541,15 @@ static int mos7720_startup(struct usb_serial *serial)
1555 1541
1556 /* setting configuration feature to one */ 1542 /* setting configuration feature to one */
1557 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 1543 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
1558 (__u8)0x03, 0x00,0x01,0x00, NULL, 0x00, 5*HZ); 1544 (__u8)0x03, 0x00, 0x01, 0x00, NULL, 0x00, 5*HZ);
1559 1545
1560 send_mos_cmd(serial,MOS_READ,0x00, UART_LSR, &data); // LSR For Port 1 1546 /* LSR For Port 1 */
1561 dbg("LSR:%x",data); 1547 send_mos_cmd(serial, MOS_READ, 0x00, UART_LSR, &data);
1548 dbg("LSR:%x", data);
1562 1549
1563 send_mos_cmd(serial,MOS_READ,0x01, UART_LSR, &data); // LSR For Port 2 1550 /* LSR For Port 2 */
1564 dbg("LSR:%x",data); 1551 send_mos_cmd(serial, MOS_READ, 0x01, UART_LSR, &data);
1552 dbg("LSR:%x", data);
1565 1553
1566 return 0; 1554 return 0;
1567} 1555}
@@ -1571,7 +1559,7 @@ static void mos7720_shutdown(struct usb_serial *serial)
1571 int i; 1559 int i;
1572 1560
1573 /* free private structure allocated for serial port */ 1561 /* free private structure allocated for serial port */
1574 for (i=0; i < serial->num_ports; ++i) { 1562 for (i = 0; i < serial->num_ports; ++i) {
1575 kfree(usb_get_serial_port_data(serial->port[i])); 1563 kfree(usb_get_serial_port_data(serial->port[i]));
1576 usb_set_serial_port_data(serial->port[i], NULL); 1564 usb_set_serial_port_data(serial->port[i], NULL);
1577 } 1565 }
@@ -1651,8 +1639,8 @@ module_init(moschip7720_init);
1651module_exit(moschip7720_exit); 1639module_exit(moschip7720_exit);
1652 1640
1653/* Module information */ 1641/* Module information */
1654MODULE_AUTHOR( DRIVER_AUTHOR ); 1642MODULE_AUTHOR(DRIVER_AUTHOR);
1655MODULE_DESCRIPTION( DRIVER_DESC ); 1643MODULE_DESCRIPTION(DRIVER_DESC);
1656MODULE_LICENSE("GPL"); 1644MODULE_LICENSE("GPL");
1657 1645
1658module_param(debug, bool, S_IRUGO | S_IWUSR); 1646module_param(debug, bool, S_IRUGO | S_IWUSR);
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
index 78f2f6db494d..09d82062b973 100644
--- a/drivers/usb/serial/mos7840.c
+++ b/drivers/usb/serial/mos7840.c
@@ -33,7 +33,7 @@
33#include <linux/serial.h> 33#include <linux/serial.h>
34#include <linux/usb.h> 34#include <linux/usb.h>
35#include <linux/usb/serial.h> 35#include <linux/usb/serial.h>
36#include <asm/uaccess.h> 36#include <linux/uaccess.h>
37 37
38/* 38/*
39 * Version Information 39 * Version Information
@@ -82,8 +82,8 @@
82 * Defines used for sending commands to port 82 * Defines used for sending commands to port
83 */ 83 */
84 84
85#define WAIT_FOR_EVER (HZ * 0 ) /* timeout urb is wait for ever */ 85#define WAIT_FOR_EVER (HZ * 0) /* timeout urb is wait for ever */
86#define MOS_WDR_TIMEOUT (HZ * 5 ) /* default urb timeout */ 86#define MOS_WDR_TIMEOUT (HZ * 5) /* default urb timeout */
87 87
88#define MOS_PORT1 0x0200 88#define MOS_PORT1 0x0200
89#define MOS_PORT2 0x0300 89#define MOS_PORT2 0x0300
@@ -102,8 +102,8 @@
102 102
103#define MAX_NAME_LEN 64 103#define MAX_NAME_LEN 64
104 104
105#define ZLP_REG1 0x3A //Zero_Flag_Reg1 58 105#define ZLP_REG1 0x3A /* Zero_Flag_Reg1 58 */
106#define ZLP_REG5 0x3E //Zero_Flag_Reg5 62 106#define ZLP_REG5 0x3E /* Zero_Flag_Reg5 62 */
107 107
108/* For higher baud Rates use TIOCEXBAUD */ 108/* For higher baud Rates use TIOCEXBAUD */
109#define TIOCEXBAUD 0x5462 109#define TIOCEXBAUD 0x5462
@@ -142,7 +142,7 @@
142#define MOS_MSR_DELTA_RI 0x40 142#define MOS_MSR_DELTA_RI 0x40
143#define MOS_MSR_DELTA_CD 0x80 143#define MOS_MSR_DELTA_CD 0x80
144 144
145// Serial Port register Address 145/* Serial Port register Address */
146#define INTERRUPT_ENABLE_REGISTER ((__u16)(0x01)) 146#define INTERRUPT_ENABLE_REGISTER ((__u16)(0x01))
147#define FIFO_CONTROL_REGISTER ((__u16)(0x02)) 147#define FIFO_CONTROL_REGISTER ((__u16)(0x02))
148#define LINE_CONTROL_REGISTER ((__u16)(0x03)) 148#define LINE_CONTROL_REGISTER ((__u16)(0x03))
@@ -201,11 +201,11 @@ struct moschip_port {
201 struct async_icount icount; 201 struct async_icount icount;
202 struct usb_serial_port *port; /* loop back to the owner of this object */ 202 struct usb_serial_port *port; /* loop back to the owner of this object */
203 203
204 /*Offsets */ 204 /* Offsets */
205 __u8 SpRegOffset; 205 __u8 SpRegOffset;
206 __u8 ControlRegOffset; 206 __u8 ControlRegOffset;
207 __u8 DcrRegOffset; 207 __u8 DcrRegOffset;
208 //for processing control URBS in interrupt context 208 /* for processing control URBS in interrupt context */
209 struct urb *control_urb; 209 struct urb *control_urb;
210 struct usb_ctrlrequest *dr; 210 struct usb_ctrlrequest *dr;
211 char *ctrl_buf; 211 char *ctrl_buf;
@@ -244,7 +244,7 @@ static int mos7840_set_reg_sync(struct usb_serial_port *port, __u16 reg,
244 */ 244 */
245 245
246static int mos7840_get_reg_sync(struct usb_serial_port *port, __u16 reg, 246static int mos7840_get_reg_sync(struct usb_serial_port *port, __u16 reg,
247 __u16 * val) 247 __u16 *val)
248{ 248{
249 struct usb_device *dev = port->serial->dev; 249 struct usb_device *dev = port->serial->dev;
250 int ret = 0; 250 int ret = 0;
@@ -269,16 +269,15 @@ static int mos7840_set_uart_reg(struct usb_serial_port *port, __u16 reg,
269 269
270 struct usb_device *dev = port->serial->dev; 270 struct usb_device *dev = port->serial->dev;
271 val = val & 0x00ff; 271 val = val & 0x00ff;
272 // For the UART control registers, the application number need to be Or'ed 272 /* For the UART control registers, the application number need
273 to be Or'ed */
273 if (port->serial->num_ports == 4) { 274 if (port->serial->num_ports == 4) {
274 val |= 275 val |= (((__u16) port->number -
275 (((__u16) port->number - (__u16) (port->serial->minor)) + 276 (__u16) (port->serial->minor)) + 1) << 8;
276 1) << 8;
277 dbg("mos7840_set_uart_reg application number is %x\n", val); 277 dbg("mos7840_set_uart_reg application number is %x\n", val);
278 } else { 278 } else {
279 if (((__u16) port->number - (__u16) (port->serial->minor)) == 0) { 279 if (((__u16) port->number - (__u16) (port->serial->minor)) == 0) {
280 val |= 280 val |= (((__u16) port->number -
281 (((__u16) port->number -
282 (__u16) (port->serial->minor)) + 1) << 8; 281 (__u16) (port->serial->minor)) + 1) << 8;
283 dbg("mos7840_set_uart_reg application number is %x\n", 282 dbg("mos7840_set_uart_reg application number is %x\n",
284 val); 283 val);
@@ -302,14 +301,15 @@ static int mos7840_set_uart_reg(struct usb_serial_port *port, __u16 reg,
302 * by passing usb_rcvctrlpipe function as parameter. 301 * by passing usb_rcvctrlpipe function as parameter.
303 */ 302 */
304static int mos7840_get_uart_reg(struct usb_serial_port *port, __u16 reg, 303static int mos7840_get_uart_reg(struct usb_serial_port *port, __u16 reg,
305 __u16 * val) 304 __u16 *val)
306{ 305{
307 struct usb_device *dev = port->serial->dev; 306 struct usb_device *dev = port->serial->dev;
308 int ret = 0; 307 int ret = 0;
309 __u16 Wval; 308 __u16 Wval;
310 309
311 //dbg("application number is %4x \n",(((__u16)port->number - (__u16)(port->serial->minor))+1)<<8); 310 /* dbg("application number is %4x \n",
312 /*Wval is same as application number */ 311 (((__u16)port->number - (__u16)(port->serial->minor))+1)<<8); */
312 /* Wval is same as application number */
313 if (port->serial->num_ports == 4) { 313 if (port->serial->num_ports == 4) {
314 Wval = 314 Wval =
315 (((__u16) port->number - (__u16) (port->serial->minor)) + 315 (((__u16) port->number - (__u16) (port->serial->minor)) +
@@ -317,14 +317,12 @@ static int mos7840_get_uart_reg(struct usb_serial_port *port, __u16 reg,
317 dbg("mos7840_get_uart_reg application number is %x\n", Wval); 317 dbg("mos7840_get_uart_reg application number is %x\n", Wval);
318 } else { 318 } else {
319 if (((__u16) port->number - (__u16) (port->serial->minor)) == 0) { 319 if (((__u16) port->number - (__u16) (port->serial->minor)) == 0) {
320 Wval = 320 Wval = (((__u16) port->number -
321 (((__u16) port->number -
322 (__u16) (port->serial->minor)) + 1) << 8; 321 (__u16) (port->serial->minor)) + 1) << 8;
323 dbg("mos7840_get_uart_reg application number is %x\n", 322 dbg("mos7840_get_uart_reg application number is %x\n",
324 Wval); 323 Wval);
325 } else { 324 } else {
326 Wval = 325 Wval = (((__u16) port->number -
327 (((__u16) port->number -
328 (__u16) (port->serial->minor)) + 2) << 8; 326 (__u16) (port->serial->minor)) + 2) << 8;
329 dbg("mos7840_get_uart_reg application number is %x\n", 327 dbg("mos7840_get_uart_reg application number is %x\n",
330 Wval); 328 Wval);
@@ -406,11 +404,11 @@ static void mos7840_handle_new_lsr(struct moschip_port *port, __u8 new_lsr)
406 dbg("%s - %02x", __func__, new_lsr); 404 dbg("%s - %02x", __func__, new_lsr);
407 405
408 if (new_lsr & SERIAL_LSR_BI) { 406 if (new_lsr & SERIAL_LSR_BI) {
409 // 407 /*
410 // Parity and Framing errors only count if they 408 * Parity and Framing errors only count if they
411 // occur exclusive of a break being 409 * occur exclusive of a break being
412 // received. 410 * received.
413 // 411 */
414 new_lsr &= (__u8) (SERIAL_LSR_OE | SERIAL_LSR_BI); 412 new_lsr &= (__u8) (SERIAL_LSR_OE | SERIAL_LSR_BI);
415 } 413 }
416 414
@@ -492,7 +490,7 @@ exit:
492} 490}
493 491
494static int mos7840_get_reg(struct moschip_port *mcs, __u16 Wval, __u16 reg, 492static int mos7840_get_reg(struct moschip_port *mcs, __u16 Wval, __u16 reg,
495 __u16 * val) 493 __u16 *val)
496{ 494{
497 struct usb_device *dev = mcs->port->serial->dev; 495 struct usb_device *dev = mcs->port->serial->dev;
498 struct usb_ctrlrequest *dr = mcs->dr; 496 struct usb_ctrlrequest *dr = mcs->dr;
@@ -501,7 +499,7 @@ static int mos7840_get_reg(struct moschip_port *mcs, __u16 Wval, __u16 reg,
501 499
502 dr->bRequestType = MCS_RD_RTYPE; 500 dr->bRequestType = MCS_RD_RTYPE;
503 dr->bRequest = MCS_RDREQ; 501 dr->bRequest = MCS_RDREQ;
504 dr->wValue = cpu_to_le16(Wval); //0; 502 dr->wValue = cpu_to_le16(Wval); /* 0 */
505 dr->wIndex = cpu_to_le16(reg); 503 dr->wIndex = cpu_to_le16(reg);
506 dr->wLength = cpu_to_le16(2); 504 dr->wLength = cpu_to_le16(2);
507 505
@@ -607,7 +605,8 @@ static void mos7840_interrupt_callback(struct urb *urb)
607 } 605 }
608 } 606 }
609 } 607 }
610 if (!(rv < 0)) /* the completion handler for the control urb will resubmit */ 608 if (!(rv < 0))
609 /* the completion handler for the control urb will resubmit */
611 return; 610 return;
612exit: 611exit:
613 result = usb_submit_urb(urb, GFP_ATOMIC); 612 result = usb_submit_urb(urb, GFP_ATOMIC);
@@ -656,8 +655,8 @@ static struct usb_serial *mos7840_get_usb_serial(struct usb_serial_port *port,
656 if (!port || 655 if (!port ||
657 mos7840_port_paranoia_check(port, function) || 656 mos7840_port_paranoia_check(port, function) ||
658 mos7840_serial_paranoia_check(port->serial, function)) { 657 mos7840_serial_paranoia_check(port->serial, function)) {
659 /* then say that we don't have a valid usb_serial thing, which will 658 /* then say that we don't have a valid usb_serial thing,
660 * end up genrating -ENODEV return values */ 659 * which will end up genrating -ENODEV return values */
661 return NULL; 660 return NULL;
662 } 661 }
663 662
@@ -710,7 +709,7 @@ static void mos7840_bulk_in_callback(struct urb *urb)
710 dbg("%s", "Entering ........... \n"); 709 dbg("%s", "Entering ........... \n");
711 710
712 if (urb->actual_length) { 711 if (urb->actual_length) {
713 tty = mos7840_port->port->tty; 712 tty = mos7840_port->port->port.tty;
714 if (tty) { 713 if (tty) {
715 tty_buffer_request_room(tty, urb->actual_length); 714 tty_buffer_request_room(tty, urb->actual_length);
716 tty_insert_flip_string(tty, data, urb->actual_length); 715 tty_insert_flip_string(tty, data, urb->actual_length);
@@ -741,8 +740,8 @@ static void mos7840_bulk_in_callback(struct urb *urb)
741 740
742/***************************************************************************** 741/*****************************************************************************
743 * mos7840_bulk_out_data_callback 742 * mos7840_bulk_out_data_callback
744 * this is the callback function for when we have finished sending serial data 743 * this is the callback function for when we have finished sending
745 * on the bulk out endpoint. 744 * serial data on the bulk out endpoint.
746 *****************************************************************************/ 745 *****************************************************************************/
747 746
748static void mos7840_bulk_out_data_callback(struct urb *urb) 747static void mos7840_bulk_out_data_callback(struct urb *urb)
@@ -774,7 +773,7 @@ static void mos7840_bulk_out_data_callback(struct urb *urb)
774 773
775 dbg("%s \n", "Entering ........."); 774 dbg("%s \n", "Entering .........");
776 775
777 tty = mos7840_port->port->tty; 776 tty = mos7840_port->port->port.tty;
778 777
779 if (tty && mos7840_port->open) 778 if (tty && mos7840_port->open)
780 tty_wakeup(tty); 779 tty_wakeup(tty);
@@ -804,7 +803,8 @@ static int mos7840_serial_probe(struct usb_serial *serial,
804 * Otherwise we return a negative error number. 803 * Otherwise we return a negative error number.
805 *****************************************************************************/ 804 *****************************************************************************/
806 805
807static int mos7840_open(struct usb_serial_port *port, struct file *filp) 806static int mos7840_open(struct tty_struct *tty,
807 struct usb_serial_port *port, struct file *filp)
808{ 808{
809 int response; 809 int response;
810 int j; 810 int j;
@@ -847,7 +847,8 @@ static int mos7840_open(struct usb_serial_port *port, struct file *filp)
847 continue; 847 continue;
848 } 848 }
849 849
850 urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL); 850 urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE,
851 GFP_KERNEL);
851 if (!urb->transfer_buffer) { 852 if (!urb->transfer_buffer) {
852 usb_free_urb(urb); 853 usb_free_urb(urb);
853 mos7840_port->write_urb_pool[j] = NULL; 854 mos7840_port->write_urb_pool[j] = NULL;
@@ -868,9 +869,8 @@ static int mos7840_open(struct usb_serial_port *port, struct file *filp)
868 * 0x08 : SP1/2 Control Reg 869 * 0x08 : SP1/2 Control Reg
869 *****************************************************************************/ 870 *****************************************************************************/
870 871
871//NEED to check the following Block 872 /* NEED to check the following Block */
872 873
873 status = 0;
874 Data = 0x0; 874 Data = 0x0;
875 status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data); 875 status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data);
876 if (status < 0) { 876 if (status < 0) {
@@ -890,36 +890,35 @@ static int mos7840_open(struct usb_serial_port *port, struct file *filp)
890 dbg("writing Spreg failed\n"); 890 dbg("writing Spreg failed\n");
891 return -1; 891 return -1;
892 } 892 }
893//End of block to be checked 893 /* End of block to be checked */
894 894
895 status = 0;
896 Data = 0x0; 895 Data = 0x0;
897 status = 896 status = mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset,
898 mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset, &Data); 897 &Data);
899 if (status < 0) { 898 if (status < 0) {
900 dbg("Reading Controlreg failed\n"); 899 dbg("Reading Controlreg failed\n");
901 return -1; 900 return -1;
902 } 901 }
903 Data |= 0x08; //Driver done bit 902 Data |= 0x08; /* Driver done bit */
904 Data |= 0x20; //rx_disable 903 Data |= 0x20; /* rx_disable */
905 status = mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset, Data); 904 status = mos7840_set_reg_sync(port,
905 mos7840_port->ControlRegOffset, Data);
906 if (status < 0) { 906 if (status < 0) {
907 dbg("writing Controlreg failed\n"); 907 dbg("writing Controlreg failed\n");
908 return -1; 908 return -1;
909 } 909 }
910 //do register settings here 910 /* do register settings here */
911 // Set all regs to the device default values. 911 /* Set all regs to the device default values. */
912 //////////////////////////////////// 912 /***********************************
913 // First Disable all interrupts. 913 * First Disable all interrupts.
914 //////////////////////////////////// 914 ***********************************/
915
916 Data = 0x00; 915 Data = 0x00;
917 status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data); 916 status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
918 if (status < 0) { 917 if (status < 0) {
919 dbg("disableing interrupts failed\n"); 918 dbg("disableing interrupts failed\n");
920 return -1; 919 return -1;
921 } 920 }
922 // Set FIFO_CONTROL_REGISTER to the default value 921 /* Set FIFO_CONTROL_REGISTER to the default value */
923 Data = 0x00; 922 Data = 0x00;
924 status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data); 923 status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
925 if (status < 0) { 924 if (status < 0) {
@@ -946,90 +945,73 @@ static int mos7840_open(struct usb_serial_port *port, struct file *filp)
946 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data); 945 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
947 mos7840_port->shadowLCR = Data; 946 mos7840_port->shadowLCR = Data;
948 947
949 Data |= SERIAL_LCR_DLAB; //data latch enable in LCR 0x80 948 Data |= SERIAL_LCR_DLAB; /* data latch enable in LCR 0x80 */
950 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 949 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
951 950
952 Data = 0x0c; 951 Data = 0x0c;
953 status = 0;
954 status = mos7840_set_uart_reg(port, DIVISOR_LATCH_LSB, Data); 952 status = mos7840_set_uart_reg(port, DIVISOR_LATCH_LSB, Data);
955 953
956 Data = 0x0; 954 Data = 0x0;
957 status = 0;
958 status = mos7840_set_uart_reg(port, DIVISOR_LATCH_MSB, Data); 955 status = mos7840_set_uart_reg(port, DIVISOR_LATCH_MSB, Data);
959 956
960 Data = 0x00; 957 Data = 0x00;
961 status = 0;
962 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data); 958 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
963 959
964 Data = Data & ~SERIAL_LCR_DLAB; 960 Data = Data & ~SERIAL_LCR_DLAB;
965 status = 0;
966 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 961 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
967 mos7840_port->shadowLCR = Data; 962 mos7840_port->shadowLCR = Data;
968 963
969 //clearing Bulkin and Bulkout Fifo 964 /* clearing Bulkin and Bulkout Fifo */
970 Data = 0x0; 965 Data = 0x0;
971 status = 0;
972 status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data); 966 status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data);
973 967
974 Data = Data | 0x0c; 968 Data = Data | 0x0c;
975 status = 0;
976 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data); 969 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
977 970
978 Data = Data & ~0x0c; 971 Data = Data & ~0x0c;
979 status = 0;
980 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data); 972 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
981 //Finally enable all interrupts 973 /* Finally enable all interrupts */
982 Data = 0x0;
983 Data = 0x0c; 974 Data = 0x0c;
984 status = 0;
985 status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data); 975 status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
986 976
987 //clearing rx_disable 977 /* clearing rx_disable */
988 Data = 0x0; 978 Data = 0x0;
989 status = 0; 979 status = mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset,
990 status = 980 &Data);
991 mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset, &Data);
992 Data = Data & ~0x20; 981 Data = Data & ~0x20;
993 status = 0; 982 status = mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset,
994 status = 983 Data);
995 mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset, Data);
996 984
997 // rx_negate 985 /* rx_negate */
998 Data = 0x0; 986 Data = 0x0;
999 status = 0; 987 status = mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset,
1000 status = 988 &Data);
1001 mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset, &Data);
1002 Data = Data | 0x10; 989 Data = Data | 0x10;
1003 status = 0; 990 status = mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset,
1004 status = 991 Data);
1005 mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset, Data);
1006 992
1007 /* force low_latency on so that our tty_push actually forces * 993 /* force low_latency on so that our tty_push actually forces *
1008 * the data through,otherwise it is scheduled, and with * 994 * the data through,otherwise it is scheduled, and with *
1009 * high data rates (like with OHCI) data can get lost. */ 995 * high data rates (like with OHCI) data can get lost. */
996 if (tty)
997 tty->low_latency = 1;
1010 998
1011 if (port->tty) 999 /* Check to see if we've set up our endpoint info yet *
1012 port->tty->low_latency = 1; 1000 * (can't set it up in mos7840_startup as the structures *
1013/* Check to see if we've set up our endpoint info yet * 1001 * were not set up at that time.) */
1014 * (can't set it up in mos7840_startup as the structures *
1015 * were not set up at that time.) */
1016 if (port0->open_ports == 1) { 1002 if (port0->open_ports == 1) {
1017 if (serial->port[0]->interrupt_in_buffer == NULL) { 1003 if (serial->port[0]->interrupt_in_buffer == NULL) {
1018
1019 /* set up interrupt urb */ 1004 /* set up interrupt urb */
1020
1021 usb_fill_int_urb(serial->port[0]->interrupt_in_urb, 1005 usb_fill_int_urb(serial->port[0]->interrupt_in_urb,
1022 serial->dev, 1006 serial->dev,
1023 usb_rcvintpipe(serial->dev, 1007 usb_rcvintpipe(serial->dev,
1024 serial->port[0]-> 1008 serial->port[0]->interrupt_in_endpointAddress),
1025 interrupt_in_endpointAddress), 1009 serial->port[0]->interrupt_in_buffer,
1026 serial->port[0]->interrupt_in_buffer, 1010 serial->port[0]->interrupt_in_urb->
1027 serial->port[0]->interrupt_in_urb-> 1011 transfer_buffer_length,
1028 transfer_buffer_length, 1012 mos7840_interrupt_callback,
1029 mos7840_interrupt_callback, 1013 serial,
1030 serial, 1014 serial->port[0]->interrupt_in_urb->interval);
1031 serial->port[0]->interrupt_in_urb->
1032 interval);
1033 1015
1034 /* start interrupt read for mos7840 * 1016 /* start interrupt read for mos7840 *
1035 * will continue as long as mos7840 is connected */ 1017 * will continue as long as mos7840 is connected */
@@ -1084,14 +1066,16 @@ static int mos7840_open(struct usb_serial_port *port, struct file *filp)
1084 memset(&(mos7840_port->icount), 0x00, sizeof(mos7840_port->icount)); 1066 memset(&(mos7840_port->icount), 0x00, sizeof(mos7840_port->icount));
1085 1067
1086 /* initialize our port settings */ 1068 /* initialize our port settings */
1087 mos7840_port->shadowMCR = MCR_MASTER_IE; /* Must set to enable ints! */ 1069 /* Must set to enable ints! */
1070 mos7840_port->shadowMCR = MCR_MASTER_IE;
1088 /* send a open port command */ 1071 /* send a open port command */
1089 mos7840_port->open = 1; 1072 mos7840_port->open = 1;
1090 //mos7840_change_port_settings(mos7840_port,old_termios); 1073 /* mos7840_change_port_settings(mos7840_port,old_termios); */
1091 mos7840_port->icount.tx = 0; 1074 mos7840_port->icount.tx = 0;
1092 mos7840_port->icount.rx = 0; 1075 mos7840_port->icount.rx = 0;
1093 1076
1094 dbg("\n\nusb_serial serial:%p mos7840_port:%p\n usb_serial_port port:%p\n\n", serial, mos7840_port, port); 1077 dbg("\n\nusb_serial serial:%p mos7840_port:%p\n usb_serial_port port:%p\n\n",
1078 serial, mos7840_port, port);
1095 1079
1096 return 0; 1080 return 0;
1097 1081
@@ -1104,11 +1088,12 @@ static int mos7840_open(struct usb_serial_port *port, struct file *filp)
1104 * been written, but hasn't made it out the port yet) 1088 * been written, but hasn't made it out the port yet)
1105 * If successful, we return the number of bytes left to be written in the 1089 * If successful, we return the number of bytes left to be written in the
1106 * system, 1090 * system,
1107 * Otherwise we return a negative error number. 1091 * Otherwise we return zero.
1108 *****************************************************************************/ 1092 *****************************************************************************/
1109 1093
1110static int mos7840_chars_in_buffer(struct usb_serial_port *port) 1094static int mos7840_chars_in_buffer(struct tty_struct *tty)
1111{ 1095{
1096 struct usb_serial_port *port = tty->driver_data;
1112 int i; 1097 int i;
1113 int chars = 0; 1098 int chars = 0;
1114 unsigned long flags; 1099 unsigned long flags;
@@ -1118,22 +1103,20 @@ static int mos7840_chars_in_buffer(struct usb_serial_port *port)
1118 1103
1119 if (mos7840_port_paranoia_check(port, __func__)) { 1104 if (mos7840_port_paranoia_check(port, __func__)) {
1120 dbg("%s", "Invalid port \n"); 1105 dbg("%s", "Invalid port \n");
1121 return -1; 1106 return 0;
1122 } 1107 }
1123 1108
1124 mos7840_port = mos7840_get_port_private(port); 1109 mos7840_port = mos7840_get_port_private(port);
1125 if (mos7840_port == NULL) { 1110 if (mos7840_port == NULL) {
1126 dbg("%s \n", "mos7840_break:leaving ..........."); 1111 dbg("%s \n", "mos7840_break:leaving ...........");
1127 return -1; 1112 return 0;
1128 } 1113 }
1129 1114
1130 spin_lock_irqsave(&mos7840_port->pool_lock,flags); 1115 spin_lock_irqsave(&mos7840_port->pool_lock, flags);
1131 for (i = 0; i < NUM_URBS; ++i) { 1116 for (i = 0; i < NUM_URBS; ++i)
1132 if (mos7840_port->busy[i]) { 1117 if (mos7840_port->busy[i])
1133 chars += URB_TRANSFER_BUFFER_SIZE; 1118 chars += URB_TRANSFER_BUFFER_SIZE;
1134 } 1119 spin_unlock_irqrestore(&mos7840_port->pool_lock, flags);
1135 }
1136 spin_unlock_irqrestore(&mos7840_port->pool_lock,flags);
1137 dbg("%s - returns %d", __func__, chars); 1120 dbg("%s - returns %d", __func__, chars);
1138 return chars; 1121 return chars;
1139 1122
@@ -1149,7 +1132,8 @@ static int mos7840_chars_in_buffer(struct usb_serial_port *port)
1149 * 3. A timeout of 3 seconds without activity has expired 1132 * 3. A timeout of 3 seconds without activity has expired
1150 * 1133 *
1151 ************************************************************************/ 1134 ************************************************************************/
1152static void mos7840_block_until_tx_empty(struct moschip_port *mos7840_port) 1135static void mos7840_block_until_tx_empty(struct tty_struct *tty,
1136 struct moschip_port *mos7840_port)
1153{ 1137{
1154 int timeout = HZ / 10; 1138 int timeout = HZ / 10;
1155 int wait = 30; 1139 int wait = 30;
@@ -1157,12 +1141,11 @@ static void mos7840_block_until_tx_empty(struct moschip_port *mos7840_port)
1157 1141
1158 while (1) { 1142 while (1) {
1159 1143
1160 count = mos7840_chars_in_buffer(mos7840_port->port); 1144 count = mos7840_chars_in_buffer(tty);
1161 1145
1162 /* Check for Buffer status */ 1146 /* Check for Buffer status */
1163 if (count <= 0) { 1147 if (count <= 0)
1164 return; 1148 return;
1165 }
1166 1149
1167 /* Block the thread for a while */ 1150 /* Block the thread for a while */
1168 interruptible_sleep_on_timeout(&mos7840_port->wait_chase, 1151 interruptible_sleep_on_timeout(&mos7840_port->wait_chase,
@@ -1185,7 +1168,8 @@ static void mos7840_block_until_tx_empty(struct moschip_port *mos7840_port)
1185 * this function is called by the tty driver when a port is closed 1168 * this function is called by the tty driver when a port is closed
1186 *****************************************************************************/ 1169 *****************************************************************************/
1187 1170
1188static void mos7840_close(struct usb_serial_port *port, struct file *filp) 1171static void mos7840_close(struct tty_struct *tty,
1172 struct usb_serial_port *port, struct file *filp)
1189{ 1173{
1190 struct usb_serial *serial; 1174 struct usb_serial *serial;
1191 struct moschip_port *mos7840_port; 1175 struct moschip_port *mos7840_port;
@@ -1226,32 +1210,28 @@ static void mos7840_close(struct usb_serial_port *port, struct file *filp)
1226 } 1210 }
1227 } 1211 }
1228 1212
1229 if (serial->dev) { 1213 if (serial->dev)
1230 /* flush and block until tx is empty */ 1214 /* flush and block until tx is empty */
1231 mos7840_block_until_tx_empty(mos7840_port); 1215 mos7840_block_until_tx_empty(tty, mos7840_port);
1232 }
1233 1216
1234 /* While closing port, shutdown all bulk read, write * 1217 /* While closing port, shutdown all bulk read, write *
1235 * and interrupt read if they exists */ 1218 * and interrupt read if they exists */
1236 if (serial->dev) { 1219 if (serial->dev) {
1237
1238 if (mos7840_port->write_urb) { 1220 if (mos7840_port->write_urb) {
1239 dbg("%s", "Shutdown bulk write\n"); 1221 dbg("%s", "Shutdown bulk write\n");
1240 usb_kill_urb(mos7840_port->write_urb); 1222 usb_kill_urb(mos7840_port->write_urb);
1241 } 1223 }
1242
1243 if (mos7840_port->read_urb) { 1224 if (mos7840_port->read_urb) {
1244 dbg("%s", "Shutdown bulk read\n"); 1225 dbg("%s", "Shutdown bulk read\n");
1245 usb_kill_urb(mos7840_port->read_urb); 1226 usb_kill_urb(mos7840_port->read_urb);
1246 } 1227 }
1247 if ((&mos7840_port->control_urb)) { 1228 if ((&mos7840_port->control_urb)) {
1248 dbg("%s", "Shutdown control read\n"); 1229 dbg("%s", "Shutdown control read\n");
1249 // usb_kill_urb (mos7840_port->control_urb); 1230 /*/ usb_kill_urb (mos7840_port->control_urb); */
1250
1251 } 1231 }
1252 } 1232 }
1253// if(mos7840_port->ctrl_buf != NULL) 1233/* if(mos7840_port->ctrl_buf != NULL) */
1254// kfree(mos7840_port->ctrl_buf); 1234/* kfree(mos7840_port->ctrl_buf); */
1255 port0->open_ports--; 1235 port0->open_ports--;
1256 dbg("mos7840_num_open_ports in close%d:in port%d\n", 1236 dbg("mos7840_num_open_ports in close%d:in port%d\n",
1257 port0->open_ports, port->number); 1237 port0->open_ports, port->number);
@@ -1264,10 +1244,8 @@ static void mos7840_close(struct usb_serial_port *port, struct file *filp)
1264 1244
1265 if (mos7840_port->write_urb) { 1245 if (mos7840_port->write_urb) {
1266 /* if this urb had a transfer buffer already (old tx) free it */ 1246 /* if this urb had a transfer buffer already (old tx) free it */
1267 1247 if (mos7840_port->write_urb->transfer_buffer != NULL)
1268 if (mos7840_port->write_urb->transfer_buffer != NULL) {
1269 kfree(mos7840_port->write_urb->transfer_buffer); 1248 kfree(mos7840_port->write_urb->transfer_buffer);
1270 }
1271 usb_free_urb(mos7840_port->write_urb); 1249 usb_free_urb(mos7840_port->write_urb);
1272 } 1250 }
1273 1251
@@ -1293,20 +1271,19 @@ static void mos7840_close(struct usb_serial_port *port, struct file *filp)
1293 * 1271 *
1294 ************************************************************************/ 1272 ************************************************************************/
1295 1273
1296static void mos7840_block_until_chase_response(struct moschip_port 1274static void mos7840_block_until_chase_response(struct tty_struct *tty,
1297 *mos7840_port) 1275 struct moschip_port *mos7840_port)
1298{ 1276{
1299 int timeout = 1 * HZ; 1277 int timeout = 1 * HZ;
1300 int wait = 10; 1278 int wait = 10;
1301 int count; 1279 int count;
1302 1280
1303 while (1) { 1281 while (1) {
1304 count = mos7840_chars_in_buffer(mos7840_port->port); 1282 count = mos7840_chars_in_buffer(tty);
1305 1283
1306 /* Check for Buffer status */ 1284 /* Check for Buffer status */
1307 if (count <= 0) { 1285 if (count <= 0)
1308 return; 1286 return;
1309 }
1310 1287
1311 /* Block the thread for a while */ 1288 /* Block the thread for a while */
1312 interruptible_sleep_on_timeout(&mos7840_port->wait_chase, 1289 interruptible_sleep_on_timeout(&mos7840_port->wait_chase,
@@ -1328,8 +1305,9 @@ static void mos7840_block_until_chase_response(struct moschip_port
1328 * mos7840_break 1305 * mos7840_break
1329 * this function sends a break to the port 1306 * this function sends a break to the port
1330 *****************************************************************************/ 1307 *****************************************************************************/
1331static void mos7840_break(struct usb_serial_port *port, int break_state) 1308static void mos7840_break(struct tty_struct *tty, int break_state)
1332{ 1309{
1310 struct usb_serial_port *port = tty->driver_data;
1333 unsigned char data; 1311 unsigned char data;
1334 struct usb_serial *serial; 1312 struct usb_serial *serial;
1335 struct moschip_port *mos7840_port; 1313 struct moschip_port *mos7840_port;
@@ -1350,21 +1328,17 @@ static void mos7840_break(struct usb_serial_port *port, int break_state)
1350 1328
1351 mos7840_port = mos7840_get_port_private(port); 1329 mos7840_port = mos7840_get_port_private(port);
1352 1330
1353 if (mos7840_port == NULL) { 1331 if (mos7840_port == NULL)
1354 return; 1332 return;
1355 }
1356
1357 if (serial->dev) {
1358 1333
1334 if (serial->dev)
1359 /* flush and block until tx is empty */ 1335 /* flush and block until tx is empty */
1360 mos7840_block_until_chase_response(mos7840_port); 1336 mos7840_block_until_chase_response(tty, mos7840_port);
1361 }
1362 1337
1363 if (break_state == -1) { 1338 if (break_state == -1)
1364 data = mos7840_port->shadowLCR | LCR_SET_BREAK; 1339 data = mos7840_port->shadowLCR | LCR_SET_BREAK;
1365 } else { 1340 else
1366 data = mos7840_port->shadowLCR & ~LCR_SET_BREAK; 1341 data = mos7840_port->shadowLCR & ~LCR_SET_BREAK;
1367 }
1368 1342
1369 mos7840_port->shadowLCR = data; 1343 mos7840_port->shadowLCR = data;
1370 dbg("mcs7840_break mos7840_port->shadowLCR is %x\n", 1344 dbg("mcs7840_break mos7840_port->shadowLCR is %x\n",
@@ -1383,8 +1357,9 @@ static void mos7840_break(struct usb_serial_port *port, int break_state)
1383 * Otherwise we return a negative error number. 1357 * Otherwise we return a negative error number.
1384 *****************************************************************************/ 1358 *****************************************************************************/
1385 1359
1386static int mos7840_write_room(struct usb_serial_port *port) 1360static int mos7840_write_room(struct tty_struct *tty)
1387{ 1361{
1362 struct usb_serial_port *port = tty->driver_data;
1388 int i; 1363 int i;
1389 int room = 0; 1364 int room = 0;
1390 unsigned long flags; 1365 unsigned long flags;
@@ -1406,9 +1381,8 @@ static int mos7840_write_room(struct usb_serial_port *port)
1406 1381
1407 spin_lock_irqsave(&mos7840_port->pool_lock, flags); 1382 spin_lock_irqsave(&mos7840_port->pool_lock, flags);
1408 for (i = 0; i < NUM_URBS; ++i) { 1383 for (i = 0; i < NUM_URBS; ++i) {
1409 if (!mos7840_port->busy[i]) { 1384 if (!mos7840_port->busy[i])
1410 room += URB_TRANSFER_BUFFER_SIZE; 1385 room += URB_TRANSFER_BUFFER_SIZE;
1411 }
1412 } 1386 }
1413 spin_unlock_irqrestore(&mos7840_port->pool_lock, flags); 1387 spin_unlock_irqrestore(&mos7840_port->pool_lock, flags);
1414 1388
@@ -1426,7 +1400,7 @@ static int mos7840_write_room(struct usb_serial_port *port)
1426 * return a negative error number. 1400 * return a negative error number.
1427 *****************************************************************************/ 1401 *****************************************************************************/
1428 1402
1429static int mos7840_write(struct usb_serial_port *port, 1403static int mos7840_write(struct tty_struct *tty, struct usb_serial_port *port,
1430 const unsigned char *data, int count) 1404 const unsigned char *data, int count)
1431{ 1405{
1432 int status; 1406 int status;
@@ -1438,45 +1412,41 @@ static int mos7840_write(struct usb_serial_port *port,
1438 struct moschip_port *mos7840_port; 1412 struct moschip_port *mos7840_port;
1439 struct usb_serial *serial; 1413 struct usb_serial *serial;
1440 struct urb *urb; 1414 struct urb *urb;
1441 //__u16 Data; 1415 /* __u16 Data; */
1442 const unsigned char *current_position = data; 1416 const unsigned char *current_position = data;
1443 unsigned char *data1; 1417 unsigned char *data1;
1444 dbg("%s \n", "entering ..........."); 1418 dbg("%s \n", "entering ...........");
1445 //dbg("mos7840_write: mos7840_port->shadowLCR is %x\n",mos7840_port->shadowLCR); 1419 /* dbg("mos7840_write: mos7840_port->shadowLCR is %x\n",
1420 mos7840_port->shadowLCR); */
1446 1421
1447#ifdef NOTMOS7840 1422#ifdef NOTMOS7840
1448 Data = 0x00; 1423 Data = 0x00;
1449 status = 0;
1450 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data); 1424 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
1451 mos7840_port->shadowLCR = Data; 1425 mos7840_port->shadowLCR = Data;
1452 dbg("mos7840_write: LINE_CONTROL_REGISTER is %x\n", Data); 1426 dbg("mos7840_write: LINE_CONTROL_REGISTER is %x\n", Data);
1453 dbg("mos7840_write: mos7840_port->shadowLCR is %x\n", 1427 dbg("mos7840_write: mos7840_port->shadowLCR is %x\n",
1454 mos7840_port->shadowLCR); 1428 mos7840_port->shadowLCR);
1455 1429
1456 //Data = 0x03; 1430 /* Data = 0x03; */
1457 //status = mos7840_set_uart_reg(port,LINE_CONTROL_REGISTER,Data); 1431 /* status = mos7840_set_uart_reg(port,LINE_CONTROL_REGISTER,Data); */
1458 //mos7840_port->shadowLCR=Data;//Need to add later 1432 /* mos7840_port->shadowLCR=Data;//Need to add later */
1459 1433
1460 Data |= SERIAL_LCR_DLAB; //data latch enable in LCR 0x80 1434 Data |= SERIAL_LCR_DLAB; /* data latch enable in LCR 0x80 */
1461 status = 0;
1462 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 1435 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1463 1436
1464 //Data = 0x0c; 1437 /* Data = 0x0c; */
1465 //status = mos7840_set_uart_reg(port,DIVISOR_LATCH_LSB,Data); 1438 /* status = mos7840_set_uart_reg(port,DIVISOR_LATCH_LSB,Data); */
1466 Data = 0x00; 1439 Data = 0x00;
1467 status = 0;
1468 status = mos7840_get_uart_reg(port, DIVISOR_LATCH_LSB, &Data); 1440 status = mos7840_get_uart_reg(port, DIVISOR_LATCH_LSB, &Data);
1469 dbg("mos7840_write:DLL value is %x\n", Data); 1441 dbg("mos7840_write:DLL value is %x\n", Data);
1470 1442
1471 Data = 0x0; 1443 Data = 0x0;
1472 status = 0;
1473 status = mos7840_get_uart_reg(port, DIVISOR_LATCH_MSB, &Data); 1444 status = mos7840_get_uart_reg(port, DIVISOR_LATCH_MSB, &Data);
1474 dbg("mos7840_write:DLM value is %x\n", Data); 1445 dbg("mos7840_write:DLM value is %x\n", Data);
1475 1446
1476 Data = Data & ~SERIAL_LCR_DLAB; 1447 Data = Data & ~SERIAL_LCR_DLAB;
1477 dbg("mos7840_write: mos7840_port->shadowLCR is %x\n", 1448 dbg("mos7840_write: mos7840_port->shadowLCR is %x\n",
1478 mos7840_port->shadowLCR); 1449 mos7840_port->shadowLCR);
1479 status = 0;
1480 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 1450 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1481#endif 1451#endif
1482 1452
@@ -1555,8 +1525,7 @@ static int mos7840_write(struct usb_serial_port *port,
1555 mos7840_port->icount.tx += transfer_size; 1525 mos7840_port->icount.tx += transfer_size;
1556 smp_wmb(); 1526 smp_wmb();
1557 dbg("mos7840_port->icount.tx is %d:\n", mos7840_port->icount.tx); 1527 dbg("mos7840_port->icount.tx is %d:\n", mos7840_port->icount.tx);
1558 exit: 1528exit:
1559
1560 return bytes_sent; 1529 return bytes_sent;
1561 1530
1562} 1531}
@@ -1567,10 +1536,10 @@ static int mos7840_write(struct usb_serial_port *port,
1567 * being read from the port. 1536 * being read from the port.
1568 *****************************************************************************/ 1537 *****************************************************************************/
1569 1538
1570static void mos7840_throttle(struct usb_serial_port *port) 1539static void mos7840_throttle(struct tty_struct *tty)
1571{ 1540{
1541 struct usb_serial_port *port = tty->driver_data;
1572 struct moschip_port *mos7840_port; 1542 struct moschip_port *mos7840_port;
1573 struct tty_struct *tty;
1574 int status; 1543 int status;
1575 1544
1576 if (mos7840_port_paranoia_check(port, __func__)) { 1545 if (mos7840_port_paranoia_check(port, __func__)) {
@@ -1592,32 +1561,20 @@ static void mos7840_throttle(struct usb_serial_port *port)
1592 1561
1593 dbg("%s", "Entering .......... \n"); 1562 dbg("%s", "Entering .......... \n");
1594 1563
1595 tty = port->tty;
1596 if (!tty) {
1597 dbg("%s - no tty available", __func__);
1598 return;
1599 }
1600
1601 /* if we are implementing XON/XOFF, send the stop character */ 1564 /* if we are implementing XON/XOFF, send the stop character */
1602 if (I_IXOFF(tty)) { 1565 if (I_IXOFF(tty)) {
1603 unsigned char stop_char = STOP_CHAR(tty); 1566 unsigned char stop_char = STOP_CHAR(tty);
1604 status = mos7840_write(port, &stop_char, 1); 1567 status = mos7840_write(tty, port, &stop_char, 1);
1605 if (status <= 0) { 1568 if (status <= 0)
1606 return; 1569 return;
1607 }
1608 } 1570 }
1609
1610 /* if we are implementing RTS/CTS, toggle that line */ 1571 /* if we are implementing RTS/CTS, toggle that line */
1611 if (tty->termios->c_cflag & CRTSCTS) { 1572 if (tty->termios->c_cflag & CRTSCTS) {
1612 mos7840_port->shadowMCR &= ~MCR_RTS; 1573 mos7840_port->shadowMCR &= ~MCR_RTS;
1613 status = 0; 1574 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
1614 status =
1615 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
1616 mos7840_port->shadowMCR); 1575 mos7840_port->shadowMCR);
1617 1576 if (status < 0)
1618 if (status < 0) {
1619 return; 1577 return;
1620 }
1621 } 1578 }
1622 1579
1623 return; 1580 return;
@@ -1625,12 +1582,13 @@ static void mos7840_throttle(struct usb_serial_port *port)
1625 1582
1626/***************************************************************************** 1583/*****************************************************************************
1627 * mos7840_unthrottle 1584 * mos7840_unthrottle
1628 * this function is called by the tty driver when it wants to resume the data 1585 * this function is called by the tty driver when it wants to resume
1629 * being read from the port (called after SerialThrottle is called) 1586 * the data being read from the port (called after mos7840_throttle is
1587 * called)
1630 *****************************************************************************/ 1588 *****************************************************************************/
1631static void mos7840_unthrottle(struct usb_serial_port *port) 1589static void mos7840_unthrottle(struct tty_struct *tty)
1632{ 1590{
1633 struct tty_struct *tty; 1591 struct usb_serial_port *port = tty->driver_data;
1634 int status; 1592 int status;
1635 struct moschip_port *mos7840_port = mos7840_get_port_private(port); 1593 struct moschip_port *mos7840_port = mos7840_get_port_private(port);
1636 1594
@@ -1649,43 +1607,32 @@ static void mos7840_unthrottle(struct usb_serial_port *port)
1649 1607
1650 dbg("%s", "Entering .......... \n"); 1608 dbg("%s", "Entering .......... \n");
1651 1609
1652 tty = port->tty;
1653 if (!tty) {
1654 dbg("%s - no tty available", __func__);
1655 return;
1656 }
1657
1658 /* if we are implementing XON/XOFF, send the start character */ 1610 /* if we are implementing XON/XOFF, send the start character */
1659 if (I_IXOFF(tty)) { 1611 if (I_IXOFF(tty)) {
1660 unsigned char start_char = START_CHAR(tty); 1612 unsigned char start_char = START_CHAR(tty);
1661 status = mos7840_write(port, &start_char, 1); 1613 status = mos7840_write(tty, port, &start_char, 1);
1662 if (status <= 0) { 1614 if (status <= 0)
1663 return; 1615 return;
1664 }
1665 } 1616 }
1666 1617
1667 /* if we are implementing RTS/CTS, toggle that line */ 1618 /* if we are implementing RTS/CTS, toggle that line */
1668 if (tty->termios->c_cflag & CRTSCTS) { 1619 if (tty->termios->c_cflag & CRTSCTS) {
1669 mos7840_port->shadowMCR |= MCR_RTS; 1620 mos7840_port->shadowMCR |= MCR_RTS;
1670 status = 0; 1621 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
1671 status =
1672 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
1673 mos7840_port->shadowMCR); 1622 mos7840_port->shadowMCR);
1674 if (status < 0) { 1623 if (status < 0)
1675 return; 1624 return;
1676 }
1677 } 1625 }
1678
1679 return;
1680} 1626}
1681 1627
1682static int mos7840_tiocmget(struct usb_serial_port *port, struct file *file) 1628static int mos7840_tiocmget(struct tty_struct *tty, struct file *file)
1683{ 1629{
1630 struct usb_serial_port *port = tty->driver_data;
1684 struct moschip_port *mos7840_port; 1631 struct moschip_port *mos7840_port;
1685 unsigned int result; 1632 unsigned int result;
1686 __u16 msr; 1633 __u16 msr;
1687 __u16 mcr; 1634 __u16 mcr;
1688 int status = 0; 1635 int status;
1689 mos7840_port = mos7840_get_port_private(port); 1636 mos7840_port = mos7840_get_port_private(port);
1690 1637
1691 dbg("%s - port %d", __func__, port->number); 1638 dbg("%s - port %d", __func__, port->number);
@@ -1708,9 +1655,10 @@ static int mos7840_tiocmget(struct usb_serial_port *port, struct file *file)
1708 return result; 1655 return result;
1709} 1656}
1710 1657
1711static int mos7840_tiocmset(struct usb_serial_port *port, struct file *file, 1658static int mos7840_tiocmset(struct tty_struct *tty, struct file *file,
1712 unsigned int set, unsigned int clear) 1659 unsigned int set, unsigned int clear)
1713{ 1660{
1661 struct usb_serial_port *port = tty->driver_data;
1714 struct moschip_port *mos7840_port; 1662 struct moschip_port *mos7840_port;
1715 unsigned int mcr; 1663 unsigned int mcr;
1716 int status; 1664 int status;
@@ -1755,7 +1703,7 @@ static int mos7840_tiocmset(struct usb_serial_port *port, struct file *file,
1755 * baud rate. 1703 * baud rate.
1756 *****************************************************************************/ 1704 *****************************************************************************/
1757static int mos7840_calc_baud_rate_divisor(int baudRate, int *divisor, 1705static int mos7840_calc_baud_rate_divisor(int baudRate, int *divisor,
1758 __u16 * clk_sel_val) 1706 __u16 *clk_sel_val)
1759{ 1707{
1760 1708
1761 dbg("%s - %d", __func__, baudRate); 1709 dbg("%s - %d", __func__, baudRate);
@@ -1807,9 +1755,8 @@ static int mos7840_calc_baud_rate_divisor(int baudRate, int *divisor,
1807 /* Check for round off */ 1755 /* Check for round off */
1808 round1 = (__u16) (2304000L / baudrate); 1756 round1 = (__u16) (2304000L / baudrate);
1809 round = (__u16) (round1 - (custom * 10)); 1757 round = (__u16) (round1 - (custom * 10));
1810 if (round > 4) { 1758 if (round > 4)
1811 custom++; 1759 custom++;
1812 }
1813 *divisor = custom; 1760 *divisor = custom;
1814 1761
1815 dbg(" Baud %d = %d\n", baudrate, custom); 1762 dbg(" Baud %d = %d\n", baudrate, custom);
@@ -1857,16 +1804,15 @@ static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port,
1857 1804
1858 dbg("%s - port = %d, baud = %d", __func__, 1805 dbg("%s - port = %d, baud = %d", __func__,
1859 mos7840_port->port->number, baudRate); 1806 mos7840_port->port->number, baudRate);
1860 //reset clk_uart_sel in spregOffset 1807 /* reset clk_uart_sel in spregOffset */
1861 if (baudRate > 115200) { 1808 if (baudRate > 115200) {
1862#ifdef HW_flow_control 1809#ifdef HW_flow_control
1863 //NOTE: need to see the pther register to modify 1810 /* NOTE: need to see the pther register to modify */
1864 //setting h/w flow control bit to 1; 1811 /* setting h/w flow control bit to 1 */
1865 status = 0;
1866 Data = 0x2b; 1812 Data = 0x2b;
1867 mos7840_port->shadowMCR = Data; 1813 mos7840_port->shadowMCR = Data;
1868 status = 1814 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
1869 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); 1815 Data);
1870 if (status < 0) { 1816 if (status < 0) {
1871 dbg("Writing spreg failed in set_serial_baud\n"); 1817 dbg("Writing spreg failed in set_serial_baud\n");
1872 return -1; 1818 return -1;
@@ -1875,12 +1821,11 @@ static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port,
1875 1821
1876 } else { 1822 } else {
1877#ifdef HW_flow_control 1823#ifdef HW_flow_control
1878 //setting h/w flow control bit to 0; 1824 / *setting h/w flow control bit to 0 */
1879 status = 0;
1880 Data = 0xb; 1825 Data = 0xb;
1881 mos7840_port->shadowMCR = Data; 1826 mos7840_port->shadowMCR = Data;
1882 status = 1827 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
1883 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); 1828 Data);
1884 if (status < 0) { 1829 if (status < 0) {
1885 dbg("Writing spreg failed in set_serial_baud\n"); 1830 dbg("Writing spreg failed in set_serial_baud\n");
1886 return -1; 1831 return -1;
@@ -1889,25 +1834,20 @@ static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port,
1889 1834
1890 } 1835 }
1891 1836
1892 if (1) //baudRate <= 115200) 1837 if (1) { /* baudRate <= 115200) */
1893 {
1894 clk_sel_val = 0x0; 1838 clk_sel_val = 0x0;
1895 Data = 0x0; 1839 Data = 0x0;
1896 status = 0; 1840 status = mos7840_calc_baud_rate_divisor(baudRate, &divisor,
1897 status =
1898 mos7840_calc_baud_rate_divisor(baudRate, &divisor,
1899 &clk_sel_val); 1841 &clk_sel_val);
1900 status = 1842 status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset,
1901 mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, 1843 &Data);
1902 &Data);
1903 if (status < 0) { 1844 if (status < 0) {
1904 dbg("reading spreg failed in set_serial_baud\n"); 1845 dbg("reading spreg failed in set_serial_baud\n");
1905 return -1; 1846 return -1;
1906 } 1847 }
1907 Data = (Data & 0x8f) | clk_sel_val; 1848 Data = (Data & 0x8f) | clk_sel_val;
1908 status = 0; 1849 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset,
1909 status = 1850 Data);
1910 mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
1911 if (status < 0) { 1851 if (status < 0) {
1912 dbg("Writing spreg failed in set_serial_baud\n"); 1852 dbg("Writing spreg failed in set_serial_baud\n");
1913 return -1; 1853 return -1;
@@ -1939,7 +1879,6 @@ static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port,
1939 mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 1879 mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1940 1880
1941 } 1881 }
1942
1943 return status; 1882 return status;
1944} 1883}
1945 1884
@@ -1949,10 +1888,9 @@ static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port,
1949 * the specified new settings. 1888 * the specified new settings.
1950 *****************************************************************************/ 1889 *****************************************************************************/
1951 1890
1952static void mos7840_change_port_settings(struct moschip_port *mos7840_port, 1891static void mos7840_change_port_settings(struct tty_struct *tty,
1953 struct ktermios *old_termios) 1892 struct moschip_port *mos7840_port, struct ktermios *old_termios)
1954{ 1893{
1955 struct tty_struct *tty;
1956 int baud; 1894 int baud;
1957 unsigned cflag; 1895 unsigned cflag;
1958 unsigned iflag; 1896 unsigned iflag;
@@ -1988,8 +1926,6 @@ static void mos7840_change_port_settings(struct moschip_port *mos7840_port,
1988 return; 1926 return;
1989 } 1927 }
1990 1928
1991 tty = mos7840_port->port->tty;
1992
1993 dbg("%s", "Entering .......... \n"); 1929 dbg("%s", "Entering .......... \n");
1994 1930
1995 lData = LCR_BITS_8; 1931 lData = LCR_BITS_8;
@@ -2033,9 +1969,8 @@ static void mos7840_change_port_settings(struct moschip_port *mos7840_port,
2033 dbg("%s - parity = none", __func__); 1969 dbg("%s - parity = none", __func__);
2034 } 1970 }
2035 1971
2036 if (cflag & CMSPAR) { 1972 if (cflag & CMSPAR)
2037 lParity = lParity | 0x20; 1973 lParity = lParity | 0x20;
2038 }
2039 1974
2040 /* Change the Stop bit */ 1975 /* Change the Stop bit */
2041 if (cflag & CSTOPB) { 1976 if (cflag & CSTOPB) {
@@ -2077,16 +2012,13 @@ static void mos7840_change_port_settings(struct moschip_port *mos7840_port,
2077 /* set up the MCR register and send it to the mos7840 */ 2012 /* set up the MCR register and send it to the mos7840 */
2078 2013
2079 mos7840_port->shadowMCR = MCR_MASTER_IE; 2014 mos7840_port->shadowMCR = MCR_MASTER_IE;
2080 if (cflag & CBAUD) { 2015 if (cflag & CBAUD)
2081 mos7840_port->shadowMCR |= (MCR_DTR | MCR_RTS); 2016 mos7840_port->shadowMCR |= (MCR_DTR | MCR_RTS);
2082 }
2083 2017
2084 if (cflag & CRTSCTS) { 2018 if (cflag & CRTSCTS)
2085 mos7840_port->shadowMCR |= (MCR_XON_ANY); 2019 mos7840_port->shadowMCR |= (MCR_XON_ANY);
2086 2020 else
2087 } else {
2088 mos7840_port->shadowMCR &= ~(MCR_XON_ANY); 2021 mos7840_port->shadowMCR &= ~(MCR_XON_ANY);
2089 }
2090 2022
2091 Data = mos7840_port->shadowMCR; 2023 Data = mos7840_port->shadowMCR;
2092 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); 2024 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
@@ -2131,14 +2063,14 @@ static void mos7840_change_port_settings(struct moschip_port *mos7840_port,
2131 * the termios structure 2063 * the termios structure
2132 *****************************************************************************/ 2064 *****************************************************************************/
2133 2065
2134static void mos7840_set_termios(struct usb_serial_port *port, 2066static void mos7840_set_termios(struct tty_struct *tty,
2067 struct usb_serial_port *port,
2135 struct ktermios *old_termios) 2068 struct ktermios *old_termios)
2136{ 2069{
2137 int status; 2070 int status;
2138 unsigned int cflag; 2071 unsigned int cflag;
2139 struct usb_serial *serial; 2072 struct usb_serial *serial;
2140 struct moschip_port *mos7840_port; 2073 struct moschip_port *mos7840_port;
2141 struct tty_struct *tty;
2142 dbg("mos7840_set_termios: START\n"); 2074 dbg("mos7840_set_termios: START\n");
2143 if (mos7840_port_paranoia_check(port, __func__)) { 2075 if (mos7840_port_paranoia_check(port, __func__)) {
2144 dbg("%s", "Invalid port \n"); 2076 dbg("%s", "Invalid port \n");
@@ -2157,8 +2089,6 @@ static void mos7840_set_termios(struct usb_serial_port *port,
2157 if (mos7840_port == NULL) 2089 if (mos7840_port == NULL)
2158 return; 2090 return;
2159 2091
2160 tty = port->tty;
2161
2162 if (!mos7840_port->open) { 2092 if (!mos7840_port->open) {
2163 dbg("%s - port not opened", __func__); 2093 dbg("%s - port not opened", __func__);
2164 return; 2094 return;
@@ -2176,7 +2106,7 @@ static void mos7840_set_termios(struct usb_serial_port *port,
2176 2106
2177 /* change the port settings to the new ones specified */ 2107 /* change the port settings to the new ones specified */
2178 2108
2179 mos7840_change_port_settings(mos7840_port, old_termios); 2109 mos7840_change_port_settings(tty, mos7840_port, old_termios);
2180 2110
2181 if (!mos7840_port->read_urb) { 2111 if (!mos7840_port->read_urb) {
2182 dbg("%s", "URB KILLED !!!!!\n"); 2112 dbg("%s", "URB KILLED !!!!!\n");
@@ -2205,13 +2135,13 @@ static void mos7840_set_termios(struct usb_serial_port *port,
2205 * allows an RS485 driver to be written in user space. 2135 * allows an RS485 driver to be written in user space.
2206 *****************************************************************************/ 2136 *****************************************************************************/
2207 2137
2208static int mos7840_get_lsr_info(struct moschip_port *mos7840_port, 2138static int mos7840_get_lsr_info(struct tty_struct *tty,
2209 unsigned int __user *value) 2139 unsigned int __user *value)
2210{ 2140{
2211 int count; 2141 int count;
2212 unsigned int result = 0; 2142 unsigned int result = 0;
2213 2143
2214 count = mos7840_chars_in_buffer(mos7840_port->port); 2144 count = mos7840_chars_in_buffer(tty);
2215 if (count == 0) { 2145 if (count == 0) {
2216 dbg("%s -- Empty", __func__); 2146 dbg("%s -- Empty", __func__);
2217 result = TIOCSER_TEMT; 2147 result = TIOCSER_TEMT;
@@ -2227,6 +2157,8 @@ static int mos7840_get_lsr_info(struct moschip_port *mos7840_port,
2227 * function to set modem info 2157 * function to set modem info
2228 *****************************************************************************/ 2158 *****************************************************************************/
2229 2159
2160/* FIXME: Should be using the model control hooks */
2161
2230static int mos7840_set_modem_info(struct moschip_port *mos7840_port, 2162static int mos7840_set_modem_info(struct moschip_port *mos7840_port,
2231 unsigned int cmd, unsigned int __user *value) 2163 unsigned int cmd, unsigned int __user *value)
2232{ 2164{
@@ -2282,7 +2214,6 @@ static int mos7840_set_modem_info(struct moschip_port *mos7840_port,
2282 mos7840_port->shadowMCR = mcr; 2214 mos7840_port->shadowMCR = mcr;
2283 2215
2284 Data = mos7840_port->shadowMCR; 2216 Data = mos7840_port->shadowMCR;
2285 status = 0;
2286 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); 2217 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
2287 if (status < 0) { 2218 if (status < 0) {
2288 dbg("setting MODEM_CONTROL_REGISTER Failed\n"); 2219 dbg("setting MODEM_CONTROL_REGISTER Failed\n");
@@ -2303,10 +2234,8 @@ static int mos7840_get_modem_info(struct moschip_port *mos7840_port,
2303 unsigned int result = 0; 2234 unsigned int result = 0;
2304 __u16 msr; 2235 __u16 msr;
2305 unsigned int mcr = mos7840_port->shadowMCR; 2236 unsigned int mcr = mos7840_port->shadowMCR;
2306 int status = 0; 2237 mos7840_get_uart_reg(mos7840_port->port,
2307 status = 2238 MODEM_STATUS_REGISTER, &msr);
2308 mos7840_get_uart_reg(mos7840_port->port, MODEM_STATUS_REGISTER,
2309 &msr);
2310 result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0) /* 0x002 */ 2239 result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0) /* 0x002 */
2311 |((mcr & MCR_RTS) ? TIOCM_RTS : 0) /* 0x004 */ 2240 |((mcr & MCR_RTS) ? TIOCM_RTS : 0) /* 0x004 */
2312 |((msr & MOS7840_MSR_CTS) ? TIOCM_CTS : 0) /* 0x020 */ 2241 |((msr & MOS7840_MSR_CTS) ? TIOCM_CTS : 0) /* 0x020 */
@@ -2359,12 +2288,12 @@ static int mos7840_get_serial_info(struct moschip_port *mos7840_port,
2359 * this function handles any ioctl calls to the driver 2288 * this function handles any ioctl calls to the driver
2360 *****************************************************************************/ 2289 *****************************************************************************/
2361 2290
2362static int mos7840_ioctl(struct usb_serial_port *port, struct file *file, 2291static int mos7840_ioctl(struct tty_struct *tty, struct file *file,
2363 unsigned int cmd, unsigned long arg) 2292 unsigned int cmd, unsigned long arg)
2364{ 2293{
2294 struct usb_serial_port *port = tty->driver_data;
2365 void __user *argp = (void __user *)arg; 2295 void __user *argp = (void __user *)arg;
2366 struct moschip_port *mos7840_port; 2296 struct moschip_port *mos7840_port;
2367 struct tty_struct *tty;
2368 2297
2369 struct async_icount cnow; 2298 struct async_icount cnow;
2370 struct async_icount cprev; 2299 struct async_icount cprev;
@@ -2381,8 +2310,6 @@ static int mos7840_ioctl(struct usb_serial_port *port, struct file *file,
2381 if (mos7840_port == NULL) 2310 if (mos7840_port == NULL)
2382 return -1; 2311 return -1;
2383 2312
2384 tty = mos7840_port->port->tty;
2385
2386 dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd); 2313 dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd);
2387 2314
2388 switch (cmd) { 2315 switch (cmd) {
@@ -2390,9 +2317,10 @@ static int mos7840_ioctl(struct usb_serial_port *port, struct file *file,
2390 2317
2391 case TIOCSERGETLSR: 2318 case TIOCSERGETLSR:
2392 dbg("%s (%d) TIOCSERGETLSR", __func__, port->number); 2319 dbg("%s (%d) TIOCSERGETLSR", __func__, port->number);
2393 return mos7840_get_lsr_info(mos7840_port, argp); 2320 return mos7840_get_lsr_info(tty, argp);
2394 return 0; 2321 return 0;
2395 2322
2323 /* FIXME: use the modem hooks and remove this */
2396 case TIOCMBIS: 2324 case TIOCMBIS:
2397 case TIOCMBIC: 2325 case TIOCMBIC:
2398 case TIOCMSET: 2326 case TIOCMSET:
@@ -2418,7 +2346,7 @@ static int mos7840_ioctl(struct usb_serial_port *port, struct file *file,
2418 dbg("%s (%d) TIOCMIWAIT", __func__, port->number); 2346 dbg("%s (%d) TIOCMIWAIT", __func__, port->number);
2419 cprev = mos7840_port->icount; 2347 cprev = mos7840_port->icount;
2420 while (1) { 2348 while (1) {
2421 //interruptible_sleep_on(&mos7840_port->delta_msr_wait); 2349 /* interruptible_sleep_on(&mos7840_port->delta_msr_wait); */
2422 mos7840_port->delta_msr_cond = 0; 2350 mos7840_port->delta_msr_cond = 0;
2423 wait_event_interruptible(mos7840_port->delta_msr_wait, 2351 wait_event_interruptible(mos7840_port->delta_msr_wait,
2424 (mos7840_port-> 2352 (mos7840_port->
@@ -2463,13 +2391,9 @@ static int mos7840_ioctl(struct usb_serial_port *port, struct file *file,
2463 if (copy_to_user(argp, &icount, sizeof(icount))) 2391 if (copy_to_user(argp, &icount, sizeof(icount)))
2464 return -EFAULT; 2392 return -EFAULT;
2465 return 0; 2393 return 0;
2466
2467 case TIOCEXBAUD:
2468 return 0;
2469 default: 2394 default:
2470 break; 2395 break;
2471 } 2396 }
2472
2473 return -ENOIOCTLCMD; 2397 return -ENOIOCTLCMD;
2474} 2398}
2475 2399
@@ -2527,8 +2451,9 @@ static int mos7840_startup(struct usb_serial *serial)
2527 goto error; 2451 goto error;
2528 } 2452 }
2529 2453
2530 /* Initialize all port interrupt end point to port 0 int endpoint * 2454 /* Initialize all port interrupt end point to port 0 int
2531 * Our device has only one interrupt end point comman to all port */ 2455 * endpoint. Our device has only one interrupt end point
2456 * common to all port */
2532 2457
2533 mos7840_port->port = serial->port[i]; 2458 mos7840_port->port = serial->port[i];
2534 mos7840_set_port_private(serial->port[i], mos7840_port); 2459 mos7840_set_port_private(serial->port[i], mos7840_port);
@@ -2564,27 +2489,23 @@ static int mos7840_startup(struct usb_serial *serial)
2564 mos7840_port->DcrRegOffset = 0x1c; 2489 mos7840_port->DcrRegOffset = 0x1c;
2565 } 2490 }
2566 mos7840_dump_serial_port(mos7840_port); 2491 mos7840_dump_serial_port(mos7840_port);
2567
2568 mos7840_set_port_private(serial->port[i], mos7840_port); 2492 mos7840_set_port_private(serial->port[i], mos7840_port);
2569 2493
2570 //enable rx_disable bit in control register 2494 /* enable rx_disable bit in control register */
2571 2495 status = mos7840_get_reg_sync(serial->port[i],
2572 status = 2496 mos7840_port->ControlRegOffset, &Data);
2573 mos7840_get_reg_sync(serial->port[i],
2574 mos7840_port->ControlRegOffset, &Data);
2575 if (status < 0) { 2497 if (status < 0) {
2576 dbg("Reading ControlReg failed status-0x%x\n", status); 2498 dbg("Reading ControlReg failed status-0x%x\n", status);
2577 break; 2499 break;
2578 } else 2500 } else
2579 dbg("ControlReg Reading success val is %x, status%d\n", 2501 dbg("ControlReg Reading success val is %x, status%d\n",
2580 Data, status); 2502 Data, status);
2581 Data |= 0x08; //setting driver done bit 2503 Data |= 0x08; /* setting driver done bit */
2582 Data |= 0x04; //sp1_bit to have cts change reflect in modem status reg 2504 Data |= 0x04; /* sp1_bit to have cts change reflect in
2505 modem status reg */
2583 2506
2584 //Data |= 0x20; //rx_disable bit 2507 /* Data |= 0x20; //rx_disable bit */
2585 status = 0; 2508 status = mos7840_set_reg_sync(serial->port[i],
2586 status =
2587 mos7840_set_reg_sync(serial->port[i],
2588 mos7840_port->ControlRegOffset, Data); 2509 mos7840_port->ControlRegOffset, Data);
2589 if (status < 0) { 2510 if (status < 0) {
2590 dbg("Writing ControlReg failed(rx_disable) status-0x%x\n", status); 2511 dbg("Writing ControlReg failed(rx_disable) status-0x%x\n", status);
@@ -2593,13 +2514,11 @@ static int mos7840_startup(struct usb_serial *serial)
2593 dbg("ControlReg Writing success(rx_disable) status%d\n", 2514 dbg("ControlReg Writing success(rx_disable) status%d\n",
2594 status); 2515 status);
2595 2516
2596 //Write default values in DCR (i.e 0x01 in DCR0, 0x05 in DCR2 and 0x24 in DCR3 2517 /* Write default values in DCR (i.e 0x01 in DCR0, 0x05 in DCR2
2518 and 0x24 in DCR3 */
2597 Data = 0x01; 2519 Data = 0x01;
2598 status = 0; 2520 status = mos7840_set_reg_sync(serial->port[i],
2599 status = 2521 (__u16) (mos7840_port->DcrRegOffset + 0), Data);
2600 mos7840_set_reg_sync(serial->port[i],
2601 (__u16) (mos7840_port->DcrRegOffset +
2602 0), Data);
2603 if (status < 0) { 2522 if (status < 0) {
2604 dbg("Writing DCR0 failed status-0x%x\n", status); 2523 dbg("Writing DCR0 failed status-0x%x\n", status);
2605 break; 2524 break;
@@ -2607,11 +2526,8 @@ static int mos7840_startup(struct usb_serial *serial)
2607 dbg("DCR0 Writing success status%d\n", status); 2526 dbg("DCR0 Writing success status%d\n", status);
2608 2527
2609 Data = 0x05; 2528 Data = 0x05;
2610 status = 0; 2529 status = mos7840_set_reg_sync(serial->port[i],
2611 status = 2530 (__u16) (mos7840_port->DcrRegOffset + 1), Data);
2612 mos7840_set_reg_sync(serial->port[i],
2613 (__u16) (mos7840_port->DcrRegOffset +
2614 1), Data);
2615 if (status < 0) { 2531 if (status < 0) {
2616 dbg("Writing DCR1 failed status-0x%x\n", status); 2532 dbg("Writing DCR1 failed status-0x%x\n", status);
2617 break; 2533 break;
@@ -2619,22 +2535,17 @@ static int mos7840_startup(struct usb_serial *serial)
2619 dbg("DCR1 Writing success status%d\n", status); 2535 dbg("DCR1 Writing success status%d\n", status);
2620 2536
2621 Data = 0x24; 2537 Data = 0x24;
2622 status = 0; 2538 status = mos7840_set_reg_sync(serial->port[i],
2623 status = 2539 (__u16) (mos7840_port->DcrRegOffset + 2), Data);
2624 mos7840_set_reg_sync(serial->port[i],
2625 (__u16) (mos7840_port->DcrRegOffset +
2626 2), Data);
2627 if (status < 0) { 2540 if (status < 0) {
2628 dbg("Writing DCR2 failed status-0x%x\n", status); 2541 dbg("Writing DCR2 failed status-0x%x\n", status);
2629 break; 2542 break;
2630 } else 2543 } else
2631 dbg("DCR2 Writing success status%d\n", status); 2544 dbg("DCR2 Writing success status%d\n", status);
2632 2545
2633 // write values in clkstart0x0 and clkmulti 0x20 2546 /* write values in clkstart0x0 and clkmulti 0x20 */
2634 Data = 0x0; 2547 Data = 0x0;
2635 status = 0; 2548 status = mos7840_set_reg_sync(serial->port[i],
2636 status =
2637 mos7840_set_reg_sync(serial->port[i],
2638 CLK_START_VALUE_REGISTER, Data); 2549 CLK_START_VALUE_REGISTER, Data);
2639 if (status < 0) { 2550 if (status < 0) {
2640 dbg("Writing CLK_START_VALUE_REGISTER failed status-0x%x\n", status); 2551 dbg("Writing CLK_START_VALUE_REGISTER failed status-0x%x\n", status);
@@ -2643,9 +2554,8 @@ static int mos7840_startup(struct usb_serial *serial)
2643 dbg("CLK_START_VALUE_REGISTER Writing success status%d\n", status); 2554 dbg("CLK_START_VALUE_REGISTER Writing success status%d\n", status);
2644 2555
2645 Data = 0x20; 2556 Data = 0x20;
2646 status = 2557 status = mos7840_set_reg_sync(serial->port[i],
2647 mos7840_set_reg_sync(serial->port[i], CLK_MULTI_REGISTER, 2558 CLK_MULTI_REGISTER, Data);
2648 Data);
2649 if (status < 0) { 2559 if (status < 0) {
2650 dbg("Writing CLK_MULTI_REGISTER failed status-0x%x\n", 2560 dbg("Writing CLK_MULTI_REGISTER failed status-0x%x\n",
2651 status); 2561 status);
@@ -2654,11 +2564,10 @@ static int mos7840_startup(struct usb_serial *serial)
2654 dbg("CLK_MULTI_REGISTER Writing success status%d\n", 2564 dbg("CLK_MULTI_REGISTER Writing success status%d\n",
2655 status); 2565 status);
2656 2566
2657 //write value 0x0 to scratchpad register 2567 /* write value 0x0 to scratchpad register */
2658 Data = 0x00; 2568 Data = 0x00;
2659 status = 2569 status = mos7840_set_uart_reg(serial->port[i],
2660 mos7840_set_uart_reg(serial->port[i], SCRATCH_PAD_REGISTER, 2570 SCRATCH_PAD_REGISTER, Data);
2661 Data);
2662 if (status < 0) { 2571 if (status < 0) {
2663 dbg("Writing SCRATCH_PAD_REGISTER failed status-0x%x\n", 2572 dbg("Writing SCRATCH_PAD_REGISTER failed status-0x%x\n",
2664 status); 2573 status);
@@ -2667,21 +2576,17 @@ static int mos7840_startup(struct usb_serial *serial)
2667 dbg("SCRATCH_PAD_REGISTER Writing success status%d\n", 2576 dbg("SCRATCH_PAD_REGISTER Writing success status%d\n",
2668 status); 2577 status);
2669 2578
2670 //Zero Length flag register 2579 /* Zero Length flag register */
2671 if ((mos7840_port->port_num != 1) 2580 if ((mos7840_port->port_num != 1)
2672 && (serial->num_ports == 2)) { 2581 && (serial->num_ports == 2)) {
2673 2582
2674 Data = 0xff; 2583 Data = 0xff;
2675 status = 0;
2676 status = mos7840_set_reg_sync(serial->port[i], 2584 status = mos7840_set_reg_sync(serial->port[i],
2677 (__u16) (ZLP_REG1 + 2585 (__u16) (ZLP_REG1 +
2678 ((__u16) 2586 ((__u16)mos7840_port->port_num)), Data);
2679 mos7840_port->
2680 port_num)),
2681 Data);
2682 dbg("ZLIP offset%x\n", 2587 dbg("ZLIP offset%x\n",
2683 (__u16) (ZLP_REG1 + 2588 (__u16) (ZLP_REG1 +
2684 ((__u16) mos7840_port->port_num))); 2589 ((__u16) mos7840_port->port_num)));
2685 if (status < 0) { 2590 if (status < 0) {
2686 dbg("Writing ZLP_REG%d failed status-0x%x\n", 2591 dbg("Writing ZLP_REG%d failed status-0x%x\n",
2687 i + 2, status); 2592 i + 2, status);
@@ -2691,13 +2596,9 @@ static int mos7840_startup(struct usb_serial *serial)
2691 i + 2, status); 2596 i + 2, status);
2692 } else { 2597 } else {
2693 Data = 0xff; 2598 Data = 0xff;
2694 status = 0;
2695 status = mos7840_set_reg_sync(serial->port[i], 2599 status = mos7840_set_reg_sync(serial->port[i],
2696 (__u16) (ZLP_REG1 + 2600 (__u16) (ZLP_REG1 +
2697 ((__u16) 2601 ((__u16)mos7840_port->port_num) - 0x1), Data);
2698 mos7840_port->
2699 port_num) -
2700 0x1), Data);
2701 dbg("ZLIP offset%x\n", 2602 dbg("ZLIP offset%x\n",
2702 (__u16) (ZLP_REG1 + 2603 (__u16) (ZLP_REG1 +
2703 ((__u16) mos7840_port->port_num) - 0x1)); 2604 ((__u16) mos7840_port->port_num) - 0x1));
@@ -2712,14 +2613,16 @@ static int mos7840_startup(struct usb_serial *serial)
2712 } 2613 }
2713 mos7840_port->control_urb = usb_alloc_urb(0, GFP_KERNEL); 2614 mos7840_port->control_urb = usb_alloc_urb(0, GFP_KERNEL);
2714 mos7840_port->ctrl_buf = kmalloc(16, GFP_KERNEL); 2615 mos7840_port->ctrl_buf = kmalloc(16, GFP_KERNEL);
2715 mos7840_port->dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL); 2616 mos7840_port->dr = kmalloc(sizeof(struct usb_ctrlrequest),
2716 if (!mos7840_port->control_urb || !mos7840_port->ctrl_buf || !mos7840_port->dr) { 2617 GFP_KERNEL);
2618 if (!mos7840_port->control_urb || !mos7840_port->ctrl_buf ||
2619 !mos7840_port->dr) {
2717 status = -ENOMEM; 2620 status = -ENOMEM;
2718 goto error; 2621 goto error;
2719 } 2622 }
2720 } 2623 }
2721 2624
2722 //Zero Length flag enable 2625 /* Zero Length flag enable */
2723 Data = 0x0f; 2626 Data = 0x0f;
2724 status = mos7840_set_reg_sync(serial->port[0], ZLP_REG5, Data); 2627 status = mos7840_set_reg_sync(serial->port[0], ZLP_REG5, Data);
2725 if (status < 0) { 2628 if (status < 0) {
@@ -2762,7 +2665,7 @@ static void mos7840_shutdown(struct usb_serial *serial)
2762 return; 2665 return;
2763 } 2666 }
2764 2667
2765 /* check for the ports to be closed,close the ports and disconnect */ 2668 /* check for the ports to be closed,close the ports and disconnect */
2766 2669
2767 /* free private structure allocated for serial port * 2670 /* free private structure allocated for serial port *
2768 * stop reads and writes on all ports */ 2671 * stop reads and writes on all ports */
@@ -2843,20 +2746,12 @@ static int __init moschip7840_init(void)
2843 2746
2844 /* Register with the usb */ 2747 /* Register with the usb */
2845 retval = usb_register(&io_driver); 2748 retval = usb_register(&io_driver);
2846
2847 if (retval)
2848 goto failed_usb_register;
2849
2850 if (retval == 0) { 2749 if (retval == 0) {
2851 dbg("%s\n", "Leaving..."); 2750 dbg("%s\n", "Leaving...");
2852 return 0; 2751 return 0;
2853 } 2752 }
2854
2855 failed_usb_register:
2856 usb_serial_deregister(&moschip7840_4port_device); 2753 usb_serial_deregister(&moschip7840_4port_device);
2857 2754failed_port_device_register:
2858 failed_port_device_register:
2859
2860 return retval; 2755 return retval;
2861} 2756}
2862 2757
diff --git a/drivers/usb/serial/navman.c b/drivers/usb/serial/navman.c
index 43c8894353bf..d6736531a0fa 100644
--- a/drivers/usb/serial/navman.c
+++ b/drivers/usb/serial/navman.c
@@ -64,7 +64,7 @@ static void navman_read_int_callback(struct urb *urb)
64 usb_serial_debug_data(debug, &port->dev, __func__, 64 usb_serial_debug_data(debug, &port->dev, __func__,
65 urb->actual_length, data); 65 urb->actual_length, data);
66 66
67 tty = port->tty; 67 tty = port->port.tty;
68 if (tty && urb->actual_length) { 68 if (tty && urb->actual_length) {
69 tty_buffer_request_room(tty, urb->actual_length); 69 tty_buffer_request_room(tty, urb->actual_length);
70 tty_insert_flip_string(tty, data, urb->actual_length); 70 tty_insert_flip_string(tty, data, urb->actual_length);
@@ -79,7 +79,8 @@ exit:
79 __func__, result); 79 __func__, result);
80} 80}
81 81
82static int navman_open(struct usb_serial_port *port, struct file *filp) 82static int navman_open(struct tty_struct *tty,
83 struct usb_serial_port *port, struct file *filp)
83{ 84{
84 int result = 0; 85 int result = 0;
85 86
@@ -96,14 +97,15 @@ static int navman_open(struct usb_serial_port *port, struct file *filp)
96 return result; 97 return result;
97} 98}
98 99
99static void navman_close(struct usb_serial_port *port, struct file *filp) 100static void navman_close(struct tty_struct *tty,
101 struct usb_serial_port *port, struct file *filp)
100{ 102{
101 dbg("%s - port %d", __func__, port->number); 103 dbg("%s - port %d", __func__, port->number);
102 104
103 usb_kill_urb(port->interrupt_in_urb); 105 usb_kill_urb(port->interrupt_in_urb);
104} 106}
105 107
106static int navman_write(struct usb_serial_port *port, 108static int navman_write(struct tty_struct *tty, struct usb_serial_port *port,
107 const unsigned char *buf, int count) 109 const unsigned char *buf, int count)
108{ 110{
109 dbg("%s - port %d", __func__, port->number); 111 dbg("%s - port %d", __func__, port->number);
diff --git a/drivers/usb/serial/omninet.c b/drivers/usb/serial/omninet.c
index 7b7422f49478..ae8e227f3db2 100644
--- a/drivers/usb/serial/omninet.c
+++ b/drivers/usb/serial/omninet.c
@@ -5,26 +5,28 @@
5 * modify it under the terms of the GNU General Public License version 5 * modify it under the terms of the GNU General Public License version
6 * 2 as published by the Free Software Foundation. 6 * 2 as published by the Free Software Foundation.
7 * 7 *
8 * See Documentation/usb/usb-serial.txt for more information on using this driver 8 * See Documentation/usb/usb-serial.txt for more information on using this
9 * driver
9 * 10 *
10 * Please report both successes and troubles to the author at omninet@kroah.com 11 * Please report both successes and troubles to the author at omninet@kroah.com
11 * 12 *
12 * (05/30/2001) gkh 13 * (05/30/2001) gkh
13 * switched from using spinlock to a semaphore, which fixes lots of problems. 14 * switched from using spinlock to a semaphore, which fixes lots of
15 * problems.
14 * 16 *
15 * (04/08/2001) gb 17 * (04/08/2001) gb
16 * Identify version on module load. 18 * Identify version on module load.
17 * 19 *
18 * (11/01/2000) Adam J. Richter 20 * (11/01/2000) Adam J. Richter
19 * usb_device_id table support 21 * usb_device_id table support
20 * 22 *
21 * (10/05/2000) gkh 23 * (10/05/2000) gkh
22 * Fixed bug with urb->dev not being set properly, now that the usb 24 * Fixed bug with urb->dev not being set properly, now that the usb
23 * core needs it. 25 * core needs it.
24 * 26 *
25 * (08/28/2000) gkh 27 * (08/28/2000) gkh
26 * Added locks for SMP safeness. 28 * Added locks for SMP safeness.
27 * Fixed MOD_INC and MOD_DEC logic and the ability to open a port more 29 * Fixed MOD_INC and MOD_DEC logic and the ability to open a port more
28 * than once. 30 * than once.
29 * Fixed potential race in omninet_write_bulk_callback 31 * Fixed potential race in omninet_write_bulk_callback
30 * 32 *
@@ -43,7 +45,7 @@
43#include <linux/tty_flip.h> 45#include <linux/tty_flip.h>
44#include <linux/module.h> 46#include <linux/module.h>
45#include <linux/spinlock.h> 47#include <linux/spinlock.h>
46#include <asm/uaccess.h> 48#include <linux/uaccess.h>
47#include <linux/usb.h> 49#include <linux/usb.h>
48#include <linux/usb/serial.h> 50#include <linux/usb/serial.h>
49 51
@@ -58,25 +60,29 @@ static int debug;
58 60
59#define ZYXEL_VENDOR_ID 0x0586 61#define ZYXEL_VENDOR_ID 0x0586
60#define ZYXEL_OMNINET_ID 0x1000 62#define ZYXEL_OMNINET_ID 0x1000
61#define BT_IGNITIONPRO_ID 0x2000 /* This one seems to be a re-branded ZyXEL device */ 63/* This one seems to be a re-branded ZyXEL device */
64#define BT_IGNITIONPRO_ID 0x2000
62 65
63/* function prototypes */ 66/* function prototypes */
64static int omninet_open (struct usb_serial_port *port, struct file *filp); 67static int omninet_open(struct tty_struct *tty, struct usb_serial_port *port,
65static void omninet_close (struct usb_serial_port *port, struct file *filp); 68 struct file *filp);
66static void omninet_read_bulk_callback (struct urb *urb); 69static void omninet_close(struct tty_struct *tty, struct usb_serial_port *port,
67static void omninet_write_bulk_callback (struct urb *urb); 70 struct file *filp);
68static int omninet_write (struct usb_serial_port *port, const unsigned char *buf, int count); 71static void omninet_read_bulk_callback(struct urb *urb);
69static int omninet_write_room (struct usb_serial_port *port); 72static void omninet_write_bulk_callback(struct urb *urb);
70static void omninet_shutdown (struct usb_serial *serial); 73static int omninet_write(struct tty_struct *tty, struct usb_serial_port *port,
71static int omninet_attach (struct usb_serial *serial); 74 const unsigned char *buf, int count);
72 75static int omninet_write_room(struct tty_struct *tty);
73static struct usb_device_id id_table [] = { 76static void omninet_shutdown(struct usb_serial *serial);
77static int omninet_attach(struct usb_serial *serial);
78
79static struct usb_device_id id_table[] = {
74 { USB_DEVICE(ZYXEL_VENDOR_ID, ZYXEL_OMNINET_ID) }, 80 { USB_DEVICE(ZYXEL_VENDOR_ID, ZYXEL_OMNINET_ID) },
75 { USB_DEVICE(ZYXEL_VENDOR_ID, BT_IGNITIONPRO_ID) }, 81 { USB_DEVICE(ZYXEL_VENDOR_ID, BT_IGNITIONPRO_ID) },
76 { } /* Terminating entry */ 82 { } /* Terminating entry */
77}; 83};
78 84
79MODULE_DEVICE_TABLE (usb, id_table); 85MODULE_DEVICE_TABLE(usb, id_table);
80 86
81static struct usb_driver omninet_driver = { 87static struct usb_driver omninet_driver = {
82 .name = "omninet", 88 .name = "omninet",
@@ -130,34 +136,34 @@ static struct usb_serial_driver zyxel_omninet_device = {
130 * 136 *
131 */ 137 */
132 138
133struct omninet_header 139struct omninet_header {
134{
135 __u8 oh_seq; 140 __u8 oh_seq;
136 __u8 oh_len; 141 __u8 oh_len;
137 __u8 oh_xxx; 142 __u8 oh_xxx;
138 __u8 oh_pad; 143 __u8 oh_pad;
139}; 144};
140 145
141struct omninet_data 146struct omninet_data {
142{ 147 __u8 od_outseq; /* Sequence number for bulk_out URBs */
143 __u8 od_outseq; // Sequence number for bulk_out URBs
144}; 148};
145 149
146static int omninet_attach (struct usb_serial *serial) 150static int omninet_attach(struct usb_serial *serial)
147{ 151{
148 struct omninet_data *od; 152 struct omninet_data *od;
149 struct usb_serial_port *port = serial->port[0]; 153 struct usb_serial_port *port = serial->port[0];
150 154
151 od = kmalloc( sizeof(struct omninet_data), GFP_KERNEL ); 155 od = kmalloc(sizeof(struct omninet_data), GFP_KERNEL);
152 if( !od ) { 156 if (!od) {
153 err("%s- kmalloc(%Zd) failed.", __func__, sizeof(struct omninet_data)); 157 err("%s- kmalloc(%Zd) failed.",
158 __func__, sizeof(struct omninet_data));
154 return -ENOMEM; 159 return -ENOMEM;
155 } 160 }
156 usb_set_serial_port_data(port, od); 161 usb_set_serial_port_data(port, od);
157 return 0; 162 return 0;
158} 163}
159 164
160static int omninet_open (struct usb_serial_port *port, struct file *filp) 165static int omninet_open(struct tty_struct *tty,
166 struct usb_serial_port *port, struct file *filp)
161{ 167{
162 struct usb_serial *serial = port->serial; 168 struct usb_serial *serial = port->serial;
163 struct usb_serial_port *wport; 169 struct usb_serial_port *wport;
@@ -166,22 +172,24 @@ static int omninet_open (struct usb_serial_port *port, struct file *filp)
166 dbg("%s - port %d", __func__, port->number); 172 dbg("%s - port %d", __func__, port->number);
167 173
168 wport = serial->port[1]; 174 wport = serial->port[1];
169 wport->tty = port->tty; 175 wport->port.tty = tty; /* FIXME */
170 176
171 /* Start reading from the device */ 177 /* Start reading from the device */
172 usb_fill_bulk_urb(port->read_urb, serial->dev, 178 usb_fill_bulk_urb(port->read_urb, serial->dev,
173 usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), 179 usb_rcvbulkpipe(serial->dev,
174 port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, 180 port->bulk_in_endpointAddress),
175 omninet_read_bulk_callback, port); 181 port->read_urb->transfer_buffer,
182 port->read_urb->transfer_buffer_length,
183 omninet_read_bulk_callback, port);
176 result = usb_submit_urb(port->read_urb, GFP_KERNEL); 184 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
177 if (result) { 185 if (result)
178 err("%s - failed submitting read urb, error %d", __func__, result); 186 err("%s - failed submitting read urb, error %d",
179 } 187 __func__, result);
180
181 return result; 188 return result;
182} 189}
183 190
184static void omninet_close (struct usb_serial_port *port, struct file * filp) 191static void omninet_close(struct tty_struct *tty,
192 struct usb_serial_port *port, struct file *filp)
185{ 193{
186 dbg("%s - port %d", __func__, port->number); 194 dbg("%s - port %d", __func__, port->number);
187 usb_kill_urb(port->read_urb); 195 usb_kill_urb(port->read_urb);
@@ -192,14 +200,14 @@ static void omninet_close (struct usb_serial_port *port, struct file * filp)
192#define OMNINET_HEADERLEN sizeof(struct omninet_header) 200#define OMNINET_HEADERLEN sizeof(struct omninet_header)
193#define OMNINET_BULKOUTSIZE (64 - OMNINET_HEADERLEN) 201#define OMNINET_BULKOUTSIZE (64 - OMNINET_HEADERLEN)
194 202
195static void omninet_read_bulk_callback (struct urb *urb) 203static void omninet_read_bulk_callback(struct urb *urb)
196{ 204{
197 struct usb_serial_port *port = urb->context; 205 struct usb_serial_port *port = urb->context;
198 unsigned char *data = urb->transfer_buffer; 206 unsigned char *data = urb->transfer_buffer;
199 struct omninet_header *header = (struct omninet_header *) &data[0]; 207 struct omninet_header *header = (struct omninet_header *) &data[0];
200 int status = urb->status; 208 int status = urb->status;
201 int i;
202 int result; 209 int result;
210 int i;
203 211
204 dbg("%s - port %d", __func__, port->number); 212 dbg("%s - port %d", __func__, port->number);
205 213
@@ -209,42 +217,46 @@ static void omninet_read_bulk_callback (struct urb *urb)
209 return; 217 return;
210 } 218 }
211 219
212 if ((debug) && (header->oh_xxx != 0x30)) { 220 if (debug && header->oh_xxx != 0x30) {
213 if (urb->actual_length) { 221 if (urb->actual_length) {
214 printk (KERN_DEBUG __FILE__ ": omninet_read %d: ", header->oh_len); 222 printk(KERN_DEBUG __FILE__
215 for (i = 0; i < (header->oh_len + OMNINET_HEADERLEN); i++) { 223 ": omninet_read %d: ", header->oh_len);
216 printk ("%.2x ", data[i]); 224 for (i = 0; i < (header->oh_len +
217 } 225 OMNINET_HEADERLEN); i++)
218 printk ("\n"); 226 printk("%.2x ", data[i]);
227 printk("\n");
219 } 228 }
220 } 229 }
221 230
222 if (urb->actual_length && header->oh_len) { 231 if (urb->actual_length && header->oh_len) {
223 for (i = 0; i < header->oh_len; i++) { 232 tty_insert_flip_string(port->port.tty,
224 tty_insert_flip_char(port->tty, data[OMNINET_DATAOFFSET + i], 0); 233 data + OMNINET_DATAOFFSET, header->oh_len);
225 } 234 tty_flip_buffer_push(port->port.tty);
226 tty_flip_buffer_push(port->tty);
227 } 235 }
228 236
229 /* Continue trying to always read */ 237 /* Continue trying to always read */
230 usb_fill_bulk_urb(urb, port->serial->dev, 238 usb_fill_bulk_urb(urb, port->serial->dev,
231 usb_rcvbulkpipe(port->serial->dev, port->bulk_in_endpointAddress), 239 usb_rcvbulkpipe(port->serial->dev,
232 urb->transfer_buffer, urb->transfer_buffer_length, 240 port->bulk_in_endpointAddress),
233 omninet_read_bulk_callback, port); 241 urb->transfer_buffer, urb->transfer_buffer_length,
242 omninet_read_bulk_callback, port);
234 result = usb_submit_urb(urb, GFP_ATOMIC); 243 result = usb_submit_urb(urb, GFP_ATOMIC);
235 if (result) 244 if (result)
236 err("%s - failed resubmitting read urb, error %d", __func__, result); 245 err("%s - failed resubmitting read urb, error %d",
246 __func__, result);
237 247
238 return; 248 return;
239} 249}
240 250
241static int omninet_write (struct usb_serial_port *port, const unsigned char *buf, int count) 251static int omninet_write(struct tty_struct *tty, struct usb_serial_port *port,
252 const unsigned char *buf, int count)
242{ 253{
243 struct usb_serial *serial = port->serial; 254 struct usb_serial *serial = port->serial;
244 struct usb_serial_port *wport = serial->port[1]; 255 struct usb_serial_port *wport = serial->port[1];
245 256
246 struct omninet_data *od = usb_get_serial_port_data(port); 257 struct omninet_data *od = usb_get_serial_port_data(port);
247 struct omninet_header *header = (struct omninet_header *) wport->write_urb->transfer_buffer; 258 struct omninet_header *header = (struct omninet_header *)
259 wport->write_urb->transfer_buffer;
248 260
249 int result; 261 int result;
250 262
@@ -252,7 +264,7 @@ static int omninet_write (struct usb_serial_port *port, const unsigned char *buf
252 264
253 if (count == 0) { 265 if (count == 0) {
254 dbg("%s - write request of 0 bytes", __func__); 266 dbg("%s - write request of 0 bytes", __func__);
255 return (0); 267 return 0;
256 } 268 }
257 269
258 spin_lock_bh(&wport->lock); 270 spin_lock_bh(&wport->lock);
@@ -266,9 +278,11 @@ static int omninet_write (struct usb_serial_port *port, const unsigned char *buf
266 278
267 count = (count > OMNINET_BULKOUTSIZE) ? OMNINET_BULKOUTSIZE : count; 279 count = (count > OMNINET_BULKOUTSIZE) ? OMNINET_BULKOUTSIZE : count;
268 280
269 memcpy (wport->write_urb->transfer_buffer + OMNINET_DATAOFFSET, buf, count); 281 memcpy(wport->write_urb->transfer_buffer + OMNINET_DATAOFFSET,
282 buf, count);
270 283
271 usb_serial_debug_data(debug, &port->dev, __func__, count, wport->write_urb->transfer_buffer); 284 usb_serial_debug_data(debug, &port->dev, __func__, count,
285 wport->write_urb->transfer_buffer);
272 286
273 header->oh_seq = od->od_outseq++; 287 header->oh_seq = od->od_outseq++;
274 header->oh_len = count; 288 header->oh_len = count;
@@ -282,7 +296,8 @@ static int omninet_write (struct usb_serial_port *port, const unsigned char *buf
282 result = usb_submit_urb(wport->write_urb, GFP_ATOMIC); 296 result = usb_submit_urb(wport->write_urb, GFP_ATOMIC);
283 if (result) { 297 if (result) {
284 wport->write_urb_busy = 0; 298 wport->write_urb_busy = 0;
285 err("%s - failed submitting write urb, error %d", __func__, result); 299 err("%s - failed submitting write urb, error %d",
300 __func__, result);
286 } else 301 } else
287 result = count; 302 result = count;
288 303
@@ -290,8 +305,9 @@ static int omninet_write (struct usb_serial_port *port, const unsigned char *buf
290} 305}
291 306
292 307
293static int omninet_write_room (struct usb_serial_port *port) 308static int omninet_write_room(struct tty_struct *tty)
294{ 309{
310 struct usb_serial_port *port = tty->driver_data;
295 struct usb_serial *serial = port->serial; 311 struct usb_serial *serial = port->serial;
296 struct usb_serial_port *wport = serial->port[1]; 312 struct usb_serial_port *wport = serial->port[1];
297 313
@@ -303,12 +319,13 @@ static int omninet_write_room (struct usb_serial_port *port)
303 319
304 dbg("%s - returns %d", __func__, room); 320 dbg("%s - returns %d", __func__, room);
305 321
306 return (room); 322 return room;
307} 323}
308 324
309static void omninet_write_bulk_callback (struct urb *urb) 325static void omninet_write_bulk_callback(struct urb *urb)
310{ 326{
311/* struct omninet_header *header = (struct omninet_header *) urb->transfer_buffer; */ 327/* struct omninet_header *header = (struct omninet_header *)
328 urb->transfer_buffer; */
312 struct usb_serial_port *port = urb->context; 329 struct usb_serial_port *port = urb->context;
313 int status = urb->status; 330 int status = urb->status;
314 331
@@ -325,18 +342,18 @@ static void omninet_write_bulk_callback (struct urb *urb)
325} 342}
326 343
327 344
328static void omninet_shutdown (struct usb_serial *serial) 345static void omninet_shutdown(struct usb_serial *serial)
329{ 346{
330 struct usb_serial_port *wport = serial->port[1]; 347 struct usb_serial_port *wport = serial->port[1];
331 struct usb_serial_port *port = serial->port[0]; 348 struct usb_serial_port *port = serial->port[0];
332 dbg ("%s", __func__); 349 dbg("%s", __func__);
333 350
334 usb_kill_urb(wport->write_urb); 351 usb_kill_urb(wport->write_urb);
335 kfree(usb_get_serial_port_data(port)); 352 kfree(usb_get_serial_port_data(port));
336} 353}
337 354
338 355
339static int __init omninet_init (void) 356static int __init omninet_init(void)
340{ 357{
341 int retval; 358 int retval;
342 retval = usb_serial_register(&zyxel_omninet_device); 359 retval = usb_serial_register(&zyxel_omninet_device);
@@ -354,18 +371,18 @@ failed_usb_serial_register:
354} 371}
355 372
356 373
357static void __exit omninet_exit (void) 374static void __exit omninet_exit(void)
358{ 375{
359 usb_deregister (&omninet_driver); 376 usb_deregister(&omninet_driver);
360 usb_serial_deregister (&zyxel_omninet_device); 377 usb_serial_deregister(&zyxel_omninet_device);
361} 378}
362 379
363 380
364module_init(omninet_init); 381module_init(omninet_init);
365module_exit(omninet_exit); 382module_exit(omninet_exit);
366 383
367MODULE_AUTHOR( DRIVER_AUTHOR ); 384MODULE_AUTHOR(DRIVER_AUTHOR);
368MODULE_DESCRIPTION( DRIVER_DESC ); 385MODULE_DESCRIPTION(DRIVER_DESC);
369MODULE_LICENSE("GPL"); 386MODULE_LICENSE("GPL");
370 387
371module_param(debug, bool, S_IRUGO | S_IWUSR); 388module_param(debug, bool, S_IRUGO | S_IWUSR);
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index 1e936a1cbe0b..e4eca95f2b0f 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -43,29 +43,25 @@
43#include <linux/usb/serial.h> 43#include <linux/usb/serial.h>
44 44
45/* Function prototypes */ 45/* Function prototypes */
46static int option_open(struct usb_serial_port *port, struct file *filp); 46static int option_open(struct tty_struct *tty, struct usb_serial_port *port,
47static void option_close(struct usb_serial_port *port, struct file *filp); 47 struct file *filp);
48static void option_close(struct tty_struct *tty, struct usb_serial_port *port,
49 struct file *filp);
48static int option_startup(struct usb_serial *serial); 50static int option_startup(struct usb_serial *serial);
49static void option_shutdown(struct usb_serial *serial); 51static void option_shutdown(struct usb_serial *serial);
50static void option_rx_throttle(struct usb_serial_port *port); 52static int option_write_room(struct tty_struct *tty);
51static void option_rx_unthrottle(struct usb_serial_port *port);
52static int option_write_room(struct usb_serial_port *port);
53 53
54static void option_instat_callback(struct urb *urb); 54static void option_instat_callback(struct urb *urb);
55 55
56static int option_write(struct usb_serial_port *port, 56static int option_write(struct tty_struct *tty, struct usb_serial_port *port,
57 const unsigned char *buf, int count); 57 const unsigned char *buf, int count);
58 58static int option_chars_in_buffer(struct tty_struct *tty);
59static int option_chars_in_buffer(struct usb_serial_port *port); 59static void option_set_termios(struct tty_struct *tty,
60static int option_ioctl(struct usb_serial_port *port, struct file *file, 60 struct usb_serial_port *port, struct ktermios *old);
61 unsigned int cmd, unsigned long arg); 61static int option_tiocmget(struct tty_struct *tty, struct file *file);
62static void option_set_termios(struct usb_serial_port *port, 62static int option_tiocmset(struct tty_struct *tty, struct file *file,
63 struct ktermios *old);
64static void option_break_ctl(struct usb_serial_port *port, int break_state);
65static int option_tiocmget(struct usb_serial_port *port, struct file *file);
66static int option_tiocmset(struct usb_serial_port *port, struct file *file,
67 unsigned int set, unsigned int clear); 63 unsigned int set, unsigned int clear);
68static int option_send_setup(struct usb_serial_port *port); 64static int option_send_setup(struct tty_struct *tty, struct usb_serial_port *port);
69 65
70/* Vendor and product IDs */ 66/* Vendor and product IDs */
71#define OPTION_VENDOR_ID 0x0AF0 67#define OPTION_VENDOR_ID 0x0AF0
@@ -342,11 +338,7 @@ static struct usb_serial_driver option_1port_device = {
342 .write = option_write, 338 .write = option_write,
343 .write_room = option_write_room, 339 .write_room = option_write_room,
344 .chars_in_buffer = option_chars_in_buffer, 340 .chars_in_buffer = option_chars_in_buffer,
345 .throttle = option_rx_throttle,
346 .unthrottle = option_rx_unthrottle,
347 .ioctl = option_ioctl,
348 .set_termios = option_set_termios, 341 .set_termios = option_set_termios,
349 .break_ctl = option_break_ctl,
350 .tiocmget = option_tiocmget, 342 .tiocmget = option_tiocmget,
351 .tiocmset = option_tiocmset, 343 .tiocmset = option_tiocmset,
352 .attach = option_startup, 344 .attach = option_startup,
@@ -403,47 +395,32 @@ static int __init option_init(void)
403 return 0; 395 return 0;
404 396
405failed_driver_register: 397failed_driver_register:
406 usb_serial_deregister (&option_1port_device); 398 usb_serial_deregister(&option_1port_device);
407failed_1port_device_register: 399failed_1port_device_register:
408 return retval; 400 return retval;
409} 401}
410 402
411static void __exit option_exit(void) 403static void __exit option_exit(void)
412{ 404{
413 usb_deregister (&option_driver); 405 usb_deregister(&option_driver);
414 usb_serial_deregister (&option_1port_device); 406 usb_serial_deregister(&option_1port_device);
415} 407}
416 408
417module_init(option_init); 409module_init(option_init);
418module_exit(option_exit); 410module_exit(option_exit);
419 411
420static void option_rx_throttle(struct usb_serial_port *port) 412static void option_set_termios(struct tty_struct *tty,
421{ 413 struct usb_serial_port *port, struct ktermios *old_termios)
422 dbg("%s", __func__);
423}
424
425static void option_rx_unthrottle(struct usb_serial_port *port)
426{
427 dbg("%s", __func__);
428}
429
430static void option_break_ctl(struct usb_serial_port *port, int break_state)
431{
432 /* Unfortunately, I don't know how to send a break */
433 dbg("%s", __func__);
434}
435
436static void option_set_termios(struct usb_serial_port *port,
437 struct ktermios *old_termios)
438{ 414{
439 dbg("%s", __func__); 415 dbg("%s", __func__);
440 /* Doesn't support option setting */ 416 /* Doesn't support option setting */
441 tty_termios_copy_hw(port->tty->termios, old_termios); 417 tty_termios_copy_hw(tty->termios, old_termios);
442 option_send_setup(port); 418 option_send_setup(tty, port);
443} 419}
444 420
445static int option_tiocmget(struct usb_serial_port *port, struct file *file) 421static int option_tiocmget(struct tty_struct *tty, struct file *file)
446{ 422{
423 struct usb_serial_port *port = tty->driver_data;
447 unsigned int value; 424 unsigned int value;
448 struct option_port_private *portdata; 425 struct option_port_private *portdata;
449 426
@@ -459,9 +436,10 @@ static int option_tiocmget(struct usb_serial_port *port, struct file *file)
459 return value; 436 return value;
460} 437}
461 438
462static int option_tiocmset(struct usb_serial_port *port, struct file *file, 439static int option_tiocmset(struct tty_struct *tty, struct file *file,
463 unsigned int set, unsigned int clear) 440 unsigned int set, unsigned int clear)
464{ 441{
442 struct usb_serial_port *port = tty->driver_data;
465 struct option_port_private *portdata; 443 struct option_port_private *portdata;
466 444
467 portdata = usb_get_serial_port_data(port); 445 portdata = usb_get_serial_port_data(port);
@@ -476,17 +454,11 @@ static int option_tiocmset(struct usb_serial_port *port, struct file *file,
476 portdata->rts_state = 0; 454 portdata->rts_state = 0;
477 if (clear & TIOCM_DTR) 455 if (clear & TIOCM_DTR)
478 portdata->dtr_state = 0; 456 portdata->dtr_state = 0;
479 return option_send_setup(port); 457 return option_send_setup(tty, port);
480}
481
482static int option_ioctl(struct usb_serial_port *port, struct file *file,
483 unsigned int cmd, unsigned long arg)
484{
485 return -ENOIOCTLCMD;
486} 458}
487 459
488/* Write */ 460/* Write */
489static int option_write(struct usb_serial_port *port, 461static int option_write(struct tty_struct *tty, struct usb_serial_port *port,
490 const unsigned char *buf, int count) 462 const unsigned char *buf, int count)
491{ 463{
492 struct option_port_private *portdata; 464 struct option_port_private *portdata;
@@ -501,7 +473,7 @@ static int option_write(struct usb_serial_port *port,
501 473
502 i = 0; 474 i = 0;
503 left = count; 475 left = count;
504 for (i=0; left > 0 && i < N_OUT_URB; i++) { 476 for (i = 0; left > 0 && i < N_OUT_URB; i++) {
505 todo = left; 477 todo = left;
506 if (todo > OUT_BUFLEN) 478 if (todo > OUT_BUFLEN)
507 todo = OUT_BUFLEN; 479 todo = OUT_BUFLEN;
@@ -522,7 +494,7 @@ static int option_write(struct usb_serial_port *port,
522 usb_pipeendpoint(this_urb->pipe), i); 494 usb_pipeendpoint(this_urb->pipe), i);
523 495
524 /* send the data */ 496 /* send the data */
525 memcpy (this_urb->transfer_buffer, buf, todo); 497 memcpy(this_urb->transfer_buffer, buf, todo);
526 this_urb->transfer_buffer_length = todo; 498 this_urb->transfer_buffer_length = todo;
527 499
528 this_urb->dev = port->serial->dev; 500 this_urb->dev = port->serial->dev;
@@ -562,7 +534,7 @@ static void option_indat_callback(struct urb *urb)
562 dbg("%s: nonzero status: %d on endpoint %02x.", 534 dbg("%s: nonzero status: %d on endpoint %02x.",
563 __func__, status, endpoint); 535 __func__, status, endpoint);
564 } else { 536 } else {
565 tty = port->tty; 537 tty = port->port.tty;
566 if (urb->actual_length) { 538 if (urb->actual_length) {
567 tty_buffer_request_room(tty, urb->actual_length); 539 tty_buffer_request_room(tty, urb->actual_length);
568 tty_insert_flip_string(tty, data, urb->actual_length); 540 tty_insert_flip_string(tty, data, urb->actual_length);
@@ -572,7 +544,7 @@ static void option_indat_callback(struct urb *urb)
572 } 544 }
573 545
574 /* Resubmit urb so we continue receiving */ 546 /* Resubmit urb so we continue receiving */
575 if (port->open_count && status != -ESHUTDOWN) { 547 if (port->port.count && status != -ESHUTDOWN) {
576 err = usb_submit_urb(urb, GFP_ATOMIC); 548 err = usb_submit_urb(urb, GFP_ATOMIC);
577 if (err) 549 if (err)
578 printk(KERN_ERR "%s: resubmit read urb failed. " 550 printk(KERN_ERR "%s: resubmit read urb failed. "
@@ -613,7 +585,7 @@ static void option_instat_callback(struct urb *urb)
613 struct usb_serial *serial = port->serial; 585 struct usb_serial *serial = port->serial;
614 586
615 dbg("%s", __func__); 587 dbg("%s", __func__);
616 dbg("%s: urb %p port %p has data %p", __func__,urb,port,portdata); 588 dbg("%s: urb %p port %p has data %p", __func__, urb, port, portdata);
617 589
618 if (status == 0) { 590 if (status == 0) {
619 struct usb_ctrlrequest *req_pkt = 591 struct usb_ctrlrequest *req_pkt =
@@ -638,12 +610,12 @@ static void option_instat_callback(struct urb *urb)
638 portdata->dsr_state = ((signals & 0x02) ? 1 : 0); 610 portdata->dsr_state = ((signals & 0x02) ? 1 : 0);
639 portdata->ri_state = ((signals & 0x08) ? 1 : 0); 611 portdata->ri_state = ((signals & 0x08) ? 1 : 0);
640 612
641 if (port->tty && !C_CLOCAL(port->tty) && 613 if (port->port.tty && !C_CLOCAL(port->port.tty) &&
642 old_dcd_state && !portdata->dcd_state) 614 old_dcd_state && !portdata->dcd_state)
643 tty_hangup(port->tty); 615 tty_hangup(port->port.tty);
644 } else { 616 } else {
645 dbg("%s: type %x req %x", __func__, 617 dbg("%s: type %x req %x", __func__,
646 req_pkt->bRequestType,req_pkt->bRequest); 618 req_pkt->bRequestType, req_pkt->bRequest);
647 } 619 }
648 } else 620 } else
649 dbg("%s: error %d", __func__, status); 621 dbg("%s: error %d", __func__, status);
@@ -658,8 +630,9 @@ static void option_instat_callback(struct urb *urb)
658 } 630 }
659} 631}
660 632
661static int option_write_room(struct usb_serial_port *port) 633static int option_write_room(struct tty_struct *tty)
662{ 634{
635 struct usb_serial_port *port = tty->driver_data;
663 struct option_port_private *portdata; 636 struct option_port_private *portdata;
664 int i; 637 int i;
665 int data_len = 0; 638 int data_len = 0;
@@ -668,7 +641,7 @@ static int option_write_room(struct usb_serial_port *port)
668 portdata = usb_get_serial_port_data(port); 641 portdata = usb_get_serial_port_data(port);
669 642
670 643
671 for (i=0; i < N_OUT_URB; i++) { 644 for (i = 0; i < N_OUT_URB; i++) {
672 this_urb = portdata->out_urbs[i]; 645 this_urb = portdata->out_urbs[i];
673 if (this_urb && !test_bit(i, &portdata->out_busy)) 646 if (this_urb && !test_bit(i, &portdata->out_busy))
674 data_len += OUT_BUFLEN; 647 data_len += OUT_BUFLEN;
@@ -678,8 +651,9 @@ static int option_write_room(struct usb_serial_port *port)
678 return data_len; 651 return data_len;
679} 652}
680 653
681static int option_chars_in_buffer(struct usb_serial_port *port) 654static int option_chars_in_buffer(struct tty_struct *tty)
682{ 655{
656 struct usb_serial_port *port = tty->driver_data;
683 struct option_port_private *portdata; 657 struct option_port_private *portdata;
684 int i; 658 int i;
685 int data_len = 0; 659 int data_len = 0;
@@ -687,7 +661,7 @@ static int option_chars_in_buffer(struct usb_serial_port *port)
687 661
688 portdata = usb_get_serial_port_data(port); 662 portdata = usb_get_serial_port_data(port);
689 663
690 for (i=0; i < N_OUT_URB; i++) { 664 for (i = 0; i < N_OUT_URB; i++) {
691 this_urb = portdata->out_urbs[i]; 665 this_urb = portdata->out_urbs[i];
692 /* FIXME: This locking is insufficient as this_urb may 666 /* FIXME: This locking is insufficient as this_urb may
693 go unused during the test */ 667 go unused during the test */
@@ -698,7 +672,8 @@ static int option_chars_in_buffer(struct usb_serial_port *port)
698 return data_len; 672 return data_len;
699} 673}
700 674
701static int option_open(struct usb_serial_port *port, struct file *filp) 675static int option_open(struct tty_struct *tty,
676 struct usb_serial_port *port, struct file *filp)
702{ 677{
703 struct option_port_private *portdata; 678 struct option_port_private *portdata;
704 struct usb_serial *serial = port->serial; 679 struct usb_serial *serial = port->serial;
@@ -716,7 +691,7 @@ static int option_open(struct usb_serial_port *port, struct file *filp)
716 /* Reset low level data toggle and start reading from endpoints */ 691 /* Reset low level data toggle and start reading from endpoints */
717 for (i = 0; i < N_IN_URB; i++) { 692 for (i = 0; i < N_IN_URB; i++) {
718 urb = portdata->in_urbs[i]; 693 urb = portdata->in_urbs[i];
719 if (! urb) 694 if (!urb)
720 continue; 695 continue;
721 if (urb->dev != serial->dev) { 696 if (urb->dev != serial->dev) {
722 dbg("%s: dev %p != %p", __func__, 697 dbg("%s: dev %p != %p", __func__,
@@ -741,21 +716,23 @@ static int option_open(struct usb_serial_port *port, struct file *filp)
741 /* Reset low level data toggle on out endpoints */ 716 /* Reset low level data toggle on out endpoints */
742 for (i = 0; i < N_OUT_URB; i++) { 717 for (i = 0; i < N_OUT_URB; i++) {
743 urb = portdata->out_urbs[i]; 718 urb = portdata->out_urbs[i];
744 if (! urb) 719 if (!urb)
745 continue; 720 continue;
746 urb->dev = serial->dev; 721 urb->dev = serial->dev;
747 /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), 722 /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
748 usb_pipeout(urb->pipe), 0); */ 723 usb_pipeout(urb->pipe), 0); */
749 } 724 }
750 725
751 port->tty->low_latency = 1; 726 if (tty)
727 tty->low_latency = 1;
752 728
753 option_send_setup(port); 729 option_send_setup(tty, port);
754 730
755 return (0); 731 return 0;
756} 732}
757 733
758static void option_close(struct usb_serial_port *port, struct file *filp) 734static void option_close(struct tty_struct *tty,
735 struct usb_serial_port *port, struct file *filp)
759{ 736{
760 int i; 737 int i;
761 struct usb_serial *serial = port->serial; 738 struct usb_serial *serial = port->serial;
@@ -770,7 +747,7 @@ static void option_close(struct usb_serial_port *port, struct file *filp)
770 if (serial->dev) { 747 if (serial->dev) {
771 mutex_lock(&serial->disc_mutex); 748 mutex_lock(&serial->disc_mutex);
772 if (!serial->disconnected) 749 if (!serial->disconnected)
773 option_send_setup(port); 750 option_send_setup(tty, port);
774 mutex_unlock(&serial->disc_mutex); 751 mutex_unlock(&serial->disc_mutex);
775 752
776 /* Stop reading/writing urbs */ 753 /* Stop reading/writing urbs */
@@ -779,7 +756,7 @@ static void option_close(struct usb_serial_port *port, struct file *filp)
779 for (i = 0; i < N_OUT_URB; i++) 756 for (i = 0; i < N_OUT_URB; i++)
780 usb_kill_urb(portdata->out_urbs[i]); 757 usb_kill_urb(portdata->out_urbs[i]);
781 } 758 }
782 port->tty = NULL; 759 port->port.tty = NULL; /* FIXME */
783} 760}
784 761
785/* Helper functions used by option_setup_urbs */ 762/* Helper functions used by option_setup_urbs */
@@ -809,7 +786,7 @@ static struct urb *option_setup_urb(struct usb_serial *serial, int endpoint,
809/* Setup urbs */ 786/* Setup urbs */
810static void option_setup_urbs(struct usb_serial *serial) 787static void option_setup_urbs(struct usb_serial *serial)
811{ 788{
812 int i,j; 789 int i, j;
813 struct usb_serial_port *port; 790 struct usb_serial_port *port;
814 struct option_port_private *portdata; 791 struct option_port_private *portdata;
815 792
@@ -819,18 +796,22 @@ static void option_setup_urbs(struct usb_serial *serial)
819 port = serial->port[i]; 796 port = serial->port[i];
820 portdata = usb_get_serial_port_data(port); 797 portdata = usb_get_serial_port_data(port);
821 798
822 /* Do indat endpoints first */ 799 /* Do indat endpoints first */
823 for (j = 0; j < N_IN_URB; ++j) { 800 for (j = 0; j < N_IN_URB; ++j) {
824 portdata->in_urbs[j] = option_setup_urb (serial, 801 portdata->in_urbs[j] = option_setup_urb(serial,
825 port->bulk_in_endpointAddress, USB_DIR_IN, port, 802 port->bulk_in_endpointAddress,
826 portdata->in_buffer[j], IN_BUFLEN, option_indat_callback); 803 USB_DIR_IN, port,
804 portdata->in_buffer[j],
805 IN_BUFLEN, option_indat_callback);
827 } 806 }
828 807
829 /* outdat endpoints */ 808 /* outdat endpoints */
830 for (j = 0; j < N_OUT_URB; ++j) { 809 for (j = 0; j < N_OUT_URB; ++j) {
831 portdata->out_urbs[j] = option_setup_urb (serial, 810 portdata->out_urbs[j] = option_setup_urb(serial,
832 port->bulk_out_endpointAddress, USB_DIR_OUT, port, 811 port->bulk_out_endpointAddress,
833 portdata->out_buffer[j], OUT_BUFLEN, option_outdat_callback); 812 USB_DIR_OUT, port,
813 portdata->out_buffer[j],
814 OUT_BUFLEN, option_outdat_callback);
834 } 815 }
835 } 816 }
836} 817}
@@ -841,7 +822,8 @@ static void option_setup_urbs(struct usb_serial *serial)
841 * This is exactly the same as SET_CONTROL_LINE_STATE from the PSTN 822 * This is exactly the same as SET_CONTROL_LINE_STATE from the PSTN
842 * CDC. 823 * CDC.
843*/ 824*/
844static int option_send_setup(struct usb_serial_port *port) 825static int option_send_setup(struct tty_struct *tty,
826 struct usb_serial_port *port)
845{ 827{
846 struct usb_serial *serial = port->serial; 828 struct usb_serial *serial = port->serial;
847 struct option_port_private *portdata; 829 struct option_port_private *portdata;
@@ -850,7 +832,7 @@ static int option_send_setup(struct usb_serial_port *port)
850 832
851 portdata = usb_get_serial_port_data(port); 833 portdata = usb_get_serial_port_data(port);
852 834
853 if (port->tty) { 835 if (tty) {
854 int val = 0; 836 int val = 0;
855 if (portdata->dtr_state) 837 if (portdata->dtr_state)
856 val |= 0x01; 838 val |= 0x01;
@@ -858,10 +840,9 @@ static int option_send_setup(struct usb_serial_port *port)
858 val |= 0x02; 840 val |= 0x02;
859 841
860 return usb_control_msg(serial->dev, 842 return usb_control_msg(serial->dev,
861 usb_rcvctrlpipe(serial->dev, 0), 843 usb_rcvctrlpipe(serial->dev, 0),
862 0x22,0x21,val,ifNum,NULL,0,USB_CTRL_SET_TIMEOUT); 844 0x22, 0x21, val, ifNum, NULL, 0, USB_CTRL_SET_TIMEOUT);
863 } 845 }
864
865 return 0; 846 return 0;
866} 847}
867 848
@@ -881,7 +862,7 @@ static int option_startup(struct usb_serial *serial)
881 if (!portdata) { 862 if (!portdata) {
882 dbg("%s: kmalloc for option_port_private (%d) failed!.", 863 dbg("%s: kmalloc for option_port_private (%d) failed!.",
883 __func__, i); 864 __func__, i);
884 return (1); 865 return 1;
885 } 866 }
886 867
887 for (j = 0; j < N_IN_URB; j++) { 868 for (j = 0; j < N_IN_URB; j++) {
@@ -900,17 +881,15 @@ static int option_startup(struct usb_serial *serial)
900 881
901 usb_set_serial_port_data(port, portdata); 882 usb_set_serial_port_data(port, portdata);
902 883
903 if (! port->interrupt_in_urb) 884 if (!port->interrupt_in_urb)
904 continue; 885 continue;
905 err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 886 err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
906 if (err) 887 if (err)
907 dbg("%s: submit irq_in urb failed %d", 888 dbg("%s: submit irq_in urb failed %d",
908 __func__, err); 889 __func__, err);
909 } 890 }
910
911 option_setup_urbs(serial); 891 option_setup_urbs(serial);
912 892 return 0;
913 return (0);
914 893
915bail_out_error2: 894bail_out_error2:
916 for (j = 0; j < N_OUT_URB; j++) 895 for (j = 0; j < N_OUT_URB; j++)
@@ -949,7 +928,8 @@ static void option_shutdown(struct usb_serial *serial)
949 for (j = 0; j < N_IN_URB; j++) { 928 for (j = 0; j < N_IN_URB; j++) {
950 if (portdata->in_urbs[j]) { 929 if (portdata->in_urbs[j]) {
951 usb_free_urb(portdata->in_urbs[j]); 930 usb_free_urb(portdata->in_urbs[j]);
952 free_page((unsigned long)portdata->in_buffer[j]); 931 free_page((unsigned long)
932 portdata->in_buffer[j]);
953 portdata->in_urbs[j] = NULL; 933 portdata->in_urbs[j] = NULL;
954 } 934 }
955 } 935 }
diff --git a/drivers/usb/serial/oti6858.c b/drivers/usb/serial/oti6858.c
index a9625c180dc3..81db5715ee25 100644
--- a/drivers/usb/serial/oti6858.c
+++ b/drivers/usb/serial/oti6858.c
@@ -25,7 +25,8 @@
25 * it under the terms of the GNU General Public License as published by 25 * it under the terms of the GNU General Public License as published by
26 * the Free Software Foundation; either version 2 of the License. 26 * the Free Software Foundation; either version 2 of the License.
27 * 27 *
28 * See Documentation/usb/usb-serial.txt for more information on using this driver 28 * See Documentation/usb/usb-serial.txt for more information on using this
29 * driver
29 * 30 *
30 * TODO: 31 * TODO:
31 * - implement correct flushing for ioctls and oti6858_close() 32 * - implement correct flushing for ioctls and oti6858_close()
@@ -49,7 +50,7 @@
49#include <linux/spinlock.h> 50#include <linux/spinlock.h>
50#include <linux/usb.h> 51#include <linux/usb.h>
51#include <linux/usb/serial.h> 52#include <linux/usb/serial.h>
52#include <asm/uaccess.h> 53#include <linux/uaccess.h>
53#include "oti6858.h" 54#include "oti6858.h"
54 55
55#define OTI6858_DESCRIPTION \ 56#define OTI6858_DESCRIPTION \
@@ -135,27 +136,28 @@ struct oti6858_control_pkt {
135 136
136#define OTI6858_CTRL_PKT_SIZE sizeof(struct oti6858_control_pkt) 137#define OTI6858_CTRL_PKT_SIZE sizeof(struct oti6858_control_pkt)
137#define OTI6858_CTRL_EQUALS_PENDING(a, priv) \ 138#define OTI6858_CTRL_EQUALS_PENDING(a, priv) \
138 ( ((a)->divisor == (priv)->pending_setup.divisor) \ 139 (((a)->divisor == (priv)->pending_setup.divisor) \
139 && ((a)->control == (priv)->pending_setup.control) \ 140 && ((a)->control == (priv)->pending_setup.control) \
140 && ((a)->frame_fmt == (priv)->pending_setup.frame_fmt) ) 141 && ((a)->frame_fmt == (priv)->pending_setup.frame_fmt))
141 142
142/* function prototypes */ 143/* function prototypes */
143static int oti6858_open(struct usb_serial_port *port, struct file *filp); 144static int oti6858_open(struct tty_struct *tty,
144static void oti6858_close(struct usb_serial_port *port, struct file *filp); 145 struct usb_serial_port *port, struct file *filp);
145static void oti6858_set_termios(struct usb_serial_port *port, 146static void oti6858_close(struct tty_struct *tty,
146 struct ktermios *old); 147 struct usb_serial_port *port, struct file *filp);
147static int oti6858_ioctl(struct usb_serial_port *port, struct file *file, 148static void oti6858_set_termios(struct tty_struct *tty,
149 struct usb_serial_port *port, struct ktermios *old);
150static int oti6858_ioctl(struct tty_struct *tty, struct file *file,
148 unsigned int cmd, unsigned long arg); 151 unsigned int cmd, unsigned long arg);
149static void oti6858_read_int_callback(struct urb *urb); 152static void oti6858_read_int_callback(struct urb *urb);
150static void oti6858_read_bulk_callback(struct urb *urb); 153static void oti6858_read_bulk_callback(struct urb *urb);
151static void oti6858_write_bulk_callback(struct urb *urb); 154static void oti6858_write_bulk_callback(struct urb *urb);
152static int oti6858_write(struct usb_serial_port *port, 155static int oti6858_write(struct tty_struct *tty, struct usb_serial_port *port,
153 const unsigned char *buf, int count); 156 const unsigned char *buf, int count);
154static int oti6858_write_room(struct usb_serial_port *port); 157static int oti6858_write_room(struct tty_struct *tty);
155static void oti6858_break_ctl(struct usb_serial_port *port, int break_state); 158static int oti6858_chars_in_buffer(struct tty_struct *tty);
156static int oti6858_chars_in_buffer(struct usb_serial_port *port); 159static int oti6858_tiocmget(struct tty_struct *tty, struct file *file);
157static int oti6858_tiocmget(struct usb_serial_port *port, struct file *file); 160static int oti6858_tiocmset(struct tty_struct *tty, struct file *file,
158static int oti6858_tiocmset(struct usb_serial_port *port, struct file *file,
159 unsigned int set, unsigned int clear); 161 unsigned int set, unsigned int clear);
160static int oti6858_startup(struct usb_serial *serial); 162static int oti6858_startup(struct usb_serial *serial);
161static void oti6858_shutdown(struct usb_serial *serial); 163static void oti6858_shutdown(struct usb_serial *serial);
@@ -184,7 +186,6 @@ static struct usb_serial_driver oti6858_device = {
184 .close = oti6858_close, 186 .close = oti6858_close,
185 .write = oti6858_write, 187 .write = oti6858_write,
186 .ioctl = oti6858_ioctl, 188 .ioctl = oti6858_ioctl,
187 .break_ctl = oti6858_break_ctl,
188 .set_termios = oti6858_set_termios, 189 .set_termios = oti6858_set_termios,
189 .tiocmget = oti6858_tiocmget, 190 .tiocmget = oti6858_tiocmget,
190 .tiocmset = oti6858_tiocmset, 191 .tiocmset = oti6858_tiocmset,
@@ -220,7 +221,7 @@ struct oti6858_private {
220 struct delayed_work delayed_setup_work; 221 struct delayed_work delayed_setup_work;
221 222
222 wait_queue_head_t intr_wait; 223 wait_queue_head_t intr_wait;
223 struct usb_serial_port *port; /* USB port with which associated */ 224 struct usb_serial_port *port; /* USB port with which associated */
224}; 225};
225 226
226#undef dbg 227#undef dbg
@@ -229,7 +230,8 @@ struct oti6858_private {
229 230
230static void setup_line(struct work_struct *work) 231static void setup_line(struct work_struct *work)
231{ 232{
232 struct oti6858_private *priv = container_of(work, struct oti6858_private, delayed_setup_work.work); 233 struct oti6858_private *priv = container_of(work,
234 struct oti6858_private, delayed_setup_work.work);
233 struct usb_serial_port *port = priv->port; 235 struct usb_serial_port *port = priv->port;
234 struct oti6858_control_pkt *new_setup; 236 struct oti6858_control_pkt *new_setup;
235 unsigned long flags; 237 unsigned long flags;
@@ -237,10 +239,12 @@ static void setup_line(struct work_struct *work)
237 239
238 dbg("%s(port = %d)", __func__, port->number); 240 dbg("%s(port = %d)", __func__, port->number);
239 241
240 if ((new_setup = kmalloc(OTI6858_CTRL_PKT_SIZE, GFP_KERNEL)) == NULL) { 242 new_setup = kmalloc(OTI6858_CTRL_PKT_SIZE, GFP_KERNEL);
243 if (new_setup == NULL) {
241 dev_err(&port->dev, "%s(): out of memory!\n", __func__); 244 dev_err(&port->dev, "%s(): out of memory!\n", __func__);
242 /* we will try again */ 245 /* we will try again */
243 schedule_delayed_work(&priv->delayed_setup_work, msecs_to_jiffies(2)); 246 schedule_delayed_work(&priv->delayed_setup_work,
247 msecs_to_jiffies(2));
244 return; 248 return;
245 } 249 }
246 250
@@ -256,7 +260,8 @@ static void setup_line(struct work_struct *work)
256 dev_err(&port->dev, "%s(): error reading status\n", __func__); 260 dev_err(&port->dev, "%s(): error reading status\n", __func__);
257 kfree(new_setup); 261 kfree(new_setup);
258 /* we will try again */ 262 /* we will try again */
259 schedule_delayed_work(&priv->delayed_setup_work, msecs_to_jiffies(2)); 263 schedule_delayed_work(&priv->delayed_setup_work,
264 msecs_to_jiffies(2));
260 return; 265 return;
261 } 266 }
262 267
@@ -297,7 +302,8 @@ static void setup_line(struct work_struct *work)
297 302
298void send_data(struct work_struct *work) 303void send_data(struct work_struct *work)
299{ 304{
300 struct oti6858_private *priv = container_of(work, struct oti6858_private, delayed_write_work.work); 305 struct oti6858_private *priv = container_of(work,
306 struct oti6858_private, delayed_write_work.work);
301 struct usb_serial_port *port = priv->port; 307 struct usb_serial_port *port = priv->port;
302 int count = 0, result; 308 int count = 0, result;
303 unsigned long flags; 309 unsigned long flags;
@@ -308,7 +314,8 @@ void send_data(struct work_struct *work)
308 spin_lock_irqsave(&priv->lock, flags); 314 spin_lock_irqsave(&priv->lock, flags);
309 if (priv->flags.write_urb_in_use) { 315 if (priv->flags.write_urb_in_use) {
310 spin_unlock_irqrestore(&priv->lock, flags); 316 spin_unlock_irqrestore(&priv->lock, flags);
311 schedule_delayed_work(&priv->delayed_write_work, msecs_to_jiffies(2)); 317 schedule_delayed_work(&priv->delayed_write_work,
318 msecs_to_jiffies(2));
312 return; 319 return;
313 } 320 }
314 priv->flags.write_urb_in_use = 1; 321 priv->flags.write_urb_in_use = 1;
@@ -359,8 +366,8 @@ void send_data(struct work_struct *work)
359 366
360static int oti6858_startup(struct usb_serial *serial) 367static int oti6858_startup(struct usb_serial *serial)
361{ 368{
362 struct usb_serial_port *port = serial->port[0]; 369 struct usb_serial_port *port = serial->port[0];
363 struct oti6858_private *priv; 370 struct oti6858_private *priv;
364 int i; 371 int i;
365 372
366 for (i = 0; i < serial->num_ports; ++i) { 373 for (i = 0; i < serial->num_ports; ++i) {
@@ -375,8 +382,8 @@ static int oti6858_startup(struct usb_serial *serial)
375 382
376 spin_lock_init(&priv->lock); 383 spin_lock_init(&priv->lock);
377 init_waitqueue_head(&priv->intr_wait); 384 init_waitqueue_head(&priv->intr_wait);
378// INIT_WORK(&priv->setup_work, setup_line, serial->port[i]); 385/* INIT_WORK(&priv->setup_work, setup_line, serial->port[i]); */
379// INIT_WORK(&priv->write_work, send_data, serial->port[i]); 386/* INIT_WORK(&priv->write_work, send_data, serial->port[i]); */
380 priv->port = port; 387 priv->port = port;
381 INIT_DELAYED_WORK(&priv->delayed_setup_work, setup_line); 388 INIT_DELAYED_WORK(&priv->delayed_setup_work, setup_line);
382 INIT_DELAYED_WORK(&priv->delayed_write_work, send_data); 389 INIT_DELAYED_WORK(&priv->delayed_write_work, send_data);
@@ -395,7 +402,7 @@ static int oti6858_startup(struct usb_serial *serial)
395 return -ENOMEM; 402 return -ENOMEM;
396} 403}
397 404
398static int oti6858_write(struct usb_serial_port *port, 405static int oti6858_write(struct tty_struct *tty, struct usb_serial_port *port,
399 const unsigned char *buf, int count) 406 const unsigned char *buf, int count)
400{ 407{
401 struct oti6858_private *priv = usb_get_serial_port_data(port); 408 struct oti6858_private *priv = usb_get_serial_port_data(port);
@@ -413,8 +420,9 @@ static int oti6858_write(struct usb_serial_port *port,
413 return count; 420 return count;
414} 421}
415 422
416static int oti6858_write_room(struct usb_serial_port *port) 423static int oti6858_write_room(struct tty_struct *tty)
417{ 424{
425 struct usb_serial_port *port = tty->driver_data;
418 struct oti6858_private *priv = usb_get_serial_port_data(port); 426 struct oti6858_private *priv = usb_get_serial_port_data(port);
419 int room = 0; 427 int room = 0;
420 unsigned long flags; 428 unsigned long flags;
@@ -428,8 +436,9 @@ static int oti6858_write_room(struct usb_serial_port *port)
428 return room; 436 return room;
429} 437}
430 438
431static int oti6858_chars_in_buffer(struct usb_serial_port *port) 439static int oti6858_chars_in_buffer(struct tty_struct *tty)
432{ 440{
441 struct usb_serial_port *port = tty->driver_data;
433 struct oti6858_private *priv = usb_get_serial_port_data(port); 442 struct oti6858_private *priv = usb_get_serial_port_data(port);
434 int chars = 0; 443 int chars = 0;
435 unsigned long flags; 444 unsigned long flags;
@@ -443,8 +452,8 @@ static int oti6858_chars_in_buffer(struct usb_serial_port *port)
443 return chars; 452 return chars;
444} 453}
445 454
446static void oti6858_set_termios(struct usb_serial_port *port, 455static void oti6858_set_termios(struct tty_struct *tty,
447 struct ktermios *old_termios) 456 struct usb_serial_port *port, struct ktermios *old_termios)
448{ 457{
449 struct oti6858_private *priv = usb_get_serial_port_data(port); 458 struct oti6858_private *priv = usb_get_serial_port_data(port);
450 unsigned long flags; 459 unsigned long flags;
@@ -455,22 +464,22 @@ static void oti6858_set_termios(struct usb_serial_port *port,
455 464
456 dbg("%s(port = %d)", __func__, port->number); 465 dbg("%s(port = %d)", __func__, port->number);
457 466
458 if (!port->tty || !port->tty->termios) { 467 if (!tty) {
459 dbg("%s(): no tty structures", __func__); 468 dbg("%s(): no tty structures", __func__);
460 return; 469 return;
461 } 470 }
462 471
463 spin_lock_irqsave(&priv->lock, flags); 472 spin_lock_irqsave(&priv->lock, flags);
464 if (!priv->flags.termios_initialized) { 473 if (!priv->flags.termios_initialized) {
465 *(port->tty->termios) = tty_std_termios; 474 *(tty->termios) = tty_std_termios;
466 port->tty->termios->c_cflag = B38400 | CS8 | CREAD | HUPCL | CLOCAL; 475 tty->termios->c_cflag = B38400 | CS8 | CREAD | HUPCL | CLOCAL;
476 tty->termios->c_ispeed = 38400;
477 tty->termios->c_ospeed = 38400;
467 priv->flags.termios_initialized = 1; 478 priv->flags.termios_initialized = 1;
468 port->tty->termios->c_ispeed = 38400;
469 port->tty->termios->c_ospeed = 38400;
470 } 479 }
471 spin_unlock_irqrestore(&priv->lock, flags); 480 spin_unlock_irqrestore(&priv->lock, flags);
472 481
473 cflag = port->tty->termios->c_cflag; 482 cflag = tty->termios->c_cflag;
474 483
475 spin_lock_irqsave(&priv->lock, flags); 484 spin_lock_irqsave(&priv->lock, flags);
476 divisor = priv->pending_setup.divisor; 485 divisor = priv->pending_setup.divisor;
@@ -480,19 +489,19 @@ static void oti6858_set_termios(struct usb_serial_port *port,
480 489
481 frame_fmt &= ~FMT_DATA_BITS_MASK; 490 frame_fmt &= ~FMT_DATA_BITS_MASK;
482 switch (cflag & CSIZE) { 491 switch (cflag & CSIZE) {
483 case CS5: 492 case CS5:
484 frame_fmt |= FMT_DATA_BITS_5; 493 frame_fmt |= FMT_DATA_BITS_5;
485 break; 494 break;
486 case CS6: 495 case CS6:
487 frame_fmt |= FMT_DATA_BITS_6; 496 frame_fmt |= FMT_DATA_BITS_6;
488 break; 497 break;
489 case CS7: 498 case CS7:
490 frame_fmt |= FMT_DATA_BITS_7; 499 frame_fmt |= FMT_DATA_BITS_7;
491 break; 500 break;
492 default: 501 default:
493 case CS8: 502 case CS8:
494 frame_fmt |= FMT_DATA_BITS_8; 503 frame_fmt |= FMT_DATA_BITS_8;
495 break; 504 break;
496 } 505 }
497 506
498 /* manufacturer claims that this device can work with baud rates 507 /* manufacturer claims that this device can work with baud rates
@@ -500,7 +509,7 @@ static void oti6858_set_termios(struct usb_serial_port *port,
500 * guarantee that any other baud rate will work (especially 509 * guarantee that any other baud rate will work (especially
501 * the higher ones) 510 * the higher ones)
502 */ 511 */
503 br = tty_get_baud_rate(port->tty); 512 br = tty_get_baud_rate(tty);
504 if (br == 0) { 513 if (br == 0) {
505 divisor = 0; 514 divisor = 0;
506 } else { 515 } else {
@@ -511,23 +520,21 @@ static void oti6858_set_termios(struct usb_serial_port *port,
511 new_divisor = (96000000 + 8 * br) / (16 * br); 520 new_divisor = (96000000 + 8 * br) / (16 * br);
512 real_br = 96000000 / (16 * new_divisor); 521 real_br = 96000000 / (16 * new_divisor);
513 divisor = cpu_to_le16(new_divisor); 522 divisor = cpu_to_le16(new_divisor);
514 tty_encode_baud_rate(port->tty, real_br, real_br); 523 tty_encode_baud_rate(tty, real_br, real_br);
515 } 524 }
516 525
517 frame_fmt &= ~FMT_STOP_BITS_MASK; 526 frame_fmt &= ~FMT_STOP_BITS_MASK;
518 if ((cflag & CSTOPB) != 0) { 527 if ((cflag & CSTOPB) != 0)
519 frame_fmt |= FMT_STOP_BITS_2; 528 frame_fmt |= FMT_STOP_BITS_2;
520 } else { 529 else
521 frame_fmt |= FMT_STOP_BITS_1; 530 frame_fmt |= FMT_STOP_BITS_1;
522 }
523 531
524 frame_fmt &= ~FMT_PARITY_MASK; 532 frame_fmt &= ~FMT_PARITY_MASK;
525 if ((cflag & PARENB) != 0) { 533 if ((cflag & PARENB) != 0) {
526 if ((cflag & PARODD) != 0) { 534 if ((cflag & PARODD) != 0)
527 frame_fmt |= FMT_PARITY_ODD; 535 frame_fmt |= FMT_PARITY_ODD;
528 } else { 536 else
529 frame_fmt |= FMT_PARITY_EVEN; 537 frame_fmt |= FMT_PARITY_EVEN;
530 }
531 } else { 538 } else {
532 frame_fmt |= FMT_PARITY_NONE; 539 frame_fmt |= FMT_PARITY_NONE;
533 } 540 }
@@ -564,7 +571,8 @@ static void oti6858_set_termios(struct usb_serial_port *port,
564 spin_unlock_irqrestore(&priv->lock, flags); 571 spin_unlock_irqrestore(&priv->lock, flags);
565} 572}
566 573
567static int oti6858_open(struct usb_serial_port *port, struct file *filp) 574static int oti6858_open(struct tty_struct *tty,
575 struct usb_serial_port *port, struct file *filp)
568{ 576{
569 struct oti6858_private *priv = usb_get_serial_port_data(port); 577 struct oti6858_private *priv = usb_get_serial_port_data(port);
570 struct ktermios tmp_termios; 578 struct ktermios tmp_termios;
@@ -578,10 +586,11 @@ static int oti6858_open(struct usb_serial_port *port, struct file *filp)
578 usb_clear_halt(serial->dev, port->write_urb->pipe); 586 usb_clear_halt(serial->dev, port->write_urb->pipe);
579 usb_clear_halt(serial->dev, port->read_urb->pipe); 587 usb_clear_halt(serial->dev, port->read_urb->pipe);
580 588
581 if (port->open_count != 1) 589 if (port->port.count != 1)
582 return 0; 590 return 0;
583 591
584 if ((buf = kmalloc(OTI6858_CTRL_PKT_SIZE, GFP_KERNEL)) == NULL) { 592 buf = kmalloc(OTI6858_CTRL_PKT_SIZE, GFP_KERNEL);
593 if (buf == NULL) {
585 dev_err(&port->dev, "%s(): out of memory!\n", __func__); 594 dev_err(&port->dev, "%s(): out of memory!\n", __func__);
586 return -ENOMEM; 595 return -ENOMEM;
587 } 596 }
@@ -617,18 +626,19 @@ static int oti6858_open(struct usb_serial_port *port, struct file *filp)
617 if (result != 0) { 626 if (result != 0) {
618 dev_err(&port->dev, "%s(): usb_submit_urb() failed" 627 dev_err(&port->dev, "%s(): usb_submit_urb() failed"
619 " with error %d\n", __func__, result); 628 " with error %d\n", __func__, result);
620 oti6858_close(port, NULL); 629 oti6858_close(tty, port, NULL);
621 return -EPROTO; 630 return -EPROTO;
622 } 631 }
623 632
624 /* setup termios */ 633 /* setup termios */
625 if (port->tty) 634 if (tty)
626 oti6858_set_termios(port, &tmp_termios); 635 oti6858_set_termios(tty, port, &tmp_termios);
627 636
628 return 0; 637 return 0;
629} 638}
630 639
631static void oti6858_close(struct usb_serial_port *port, struct file *filp) 640static void oti6858_close(struct tty_struct *tty,
641 struct usb_serial_port *port, struct file *filp)
632{ 642{
633 struct oti6858_private *priv = usb_get_serial_port_data(port); 643 struct oti6858_private *priv = usb_get_serial_port_data(port);
634 unsigned long flags; 644 unsigned long flags;
@@ -641,7 +651,7 @@ static void oti6858_close(struct usb_serial_port *port, struct file *filp)
641 spin_lock_irqsave(&priv->lock, flags); 651 spin_lock_irqsave(&priv->lock, flags);
642 timeout = 30 * HZ; /* PL2303_CLOSING_WAIT */ 652 timeout = 30 * HZ; /* PL2303_CLOSING_WAIT */
643 init_waitqueue_entry(&wait, current); 653 init_waitqueue_entry(&wait, current);
644 add_wait_queue(&port->tty->write_wait, &wait); 654 add_wait_queue(&tty->write_wait, &wait);
645 dbg("%s(): entering wait loop", __func__); 655 dbg("%s(): entering wait loop", __func__);
646 for (;;) { 656 for (;;) {
647 set_current_state(TASK_INTERRUPTIBLE); 657 set_current_state(TASK_INTERRUPTIBLE);
@@ -654,7 +664,7 @@ static void oti6858_close(struct usb_serial_port *port, struct file *filp)
654 spin_lock_irqsave(&priv->lock, flags); 664 spin_lock_irqsave(&priv->lock, flags);
655 } 665 }
656 set_current_state(TASK_RUNNING); 666 set_current_state(TASK_RUNNING);
657 remove_wait_queue(&port->tty->write_wait, &wait); 667 remove_wait_queue(&tty->write_wait, &wait);
658 dbg("%s(): after wait loop", __func__); 668 dbg("%s(): after wait loop", __func__);
659 669
660 /* clear out any remaining data in the buffer */ 670 /* clear out any remaining data in the buffer */
@@ -669,7 +679,7 @@ static void oti6858_close(struct usb_serial_port *port, struct file *filp)
669 /* data is in the buffer to compute a delay */ 679 /* data is in the buffer to compute a delay */
670 /* that is not unnecessarily long) */ 680 /* that is not unnecessarily long) */
671 /* FIXME 681 /* FIXME
672 bps = tty_get_baud_rate(port->tty); 682 bps = tty_get_baud_rate(tty);
673 if (bps > 1200) 683 if (bps > 1200)
674 timeout = max((HZ*2560)/bps,HZ/10); 684 timeout = max((HZ*2560)/bps,HZ/10);
675 else 685 else
@@ -690,7 +700,7 @@ static void oti6858_close(struct usb_serial_port *port, struct file *filp)
690 usb_kill_urb(port->interrupt_in_urb); 700 usb_kill_urb(port->interrupt_in_urb);
691 701
692 /* 702 /*
693 if (port->tty && (port->tty->termios->c_cflag) & HUPCL) { 703 if (tty && (tty->termios->c_cflag) & HUPCL) {
694 // drop DTR and RTS 704 // drop DTR and RTS
695 spin_lock_irqsave(&priv->lock, flags); 705 spin_lock_irqsave(&priv->lock, flags);
696 priv->pending_setup.control &= ~CONTROL_MASK; 706 priv->pending_setup.control &= ~CONTROL_MASK;
@@ -699,9 +709,10 @@ static void oti6858_close(struct usb_serial_port *port, struct file *filp)
699 */ 709 */
700} 710}
701 711
702static int oti6858_tiocmset(struct usb_serial_port *port, struct file *file, 712static int oti6858_tiocmset(struct tty_struct *tty, struct file *file,
703 unsigned int set, unsigned int clear) 713 unsigned int set, unsigned int clear)
704{ 714{
715 struct usb_serial_port *port = tty->driver_data;
705 struct oti6858_private *priv = usb_get_serial_port_data(port); 716 struct oti6858_private *priv = usb_get_serial_port_data(port);
706 unsigned long flags; 717 unsigned long flags;
707 u8 control; 718 u8 control;
@@ -724,16 +735,16 @@ static int oti6858_tiocmset(struct usb_serial_port *port, struct file *file,
724 if ((clear & TIOCM_DTR) != 0) 735 if ((clear & TIOCM_DTR) != 0)
725 control &= ~CONTROL_DTR_HIGH; 736 control &= ~CONTROL_DTR_HIGH;
726 737
727 if (control != priv->pending_setup.control) { 738 if (control != priv->pending_setup.control)
728 priv->pending_setup.control = control; 739 priv->pending_setup.control = control;
729 }
730 spin_unlock_irqrestore(&priv->lock, flags);
731 740
741 spin_unlock_irqrestore(&priv->lock, flags);
732 return 0; 742 return 0;
733} 743}
734 744
735static int oti6858_tiocmget(struct usb_serial_port *port, struct file *file) 745static int oti6858_tiocmget(struct tty_struct *tty, struct file *file)
736{ 746{
747 struct usb_serial_port *port = tty->driver_data;
737 struct oti6858_private *priv = usb_get_serial_port_data(port); 748 struct oti6858_private *priv = usb_get_serial_port_data(port);
738 unsigned long flags; 749 unsigned long flags;
739 unsigned pin_state; 750 unsigned pin_state;
@@ -779,7 +790,8 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
779 spin_unlock_irqrestore(&priv->lock, flags); 790 spin_unlock_irqrestore(&priv->lock, flags);
780 791
781 while (1) { 792 while (1) {
782 wait_event_interruptible(priv->intr_wait, priv->status.pin_state != prev); 793 wait_event_interruptible(priv->intr_wait,
794 priv->status.pin_state != prev);
783 if (signal_pending(current)) 795 if (signal_pending(current))
784 return -ERESTARTSYS; 796 return -ERESTARTSYS;
785 797
@@ -789,12 +801,11 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
789 801
790 changed = prev ^ status; 802 changed = prev ^ status;
791 /* FIXME: check if this is correct (active high/low) */ 803 /* FIXME: check if this is correct (active high/low) */
792 if ( ((arg & TIOCM_RNG) && (changed & PIN_RI)) || 804 if (((arg & TIOCM_RNG) && (changed & PIN_RI)) ||
793 ((arg & TIOCM_DSR) && (changed & PIN_DSR)) || 805 ((arg & TIOCM_DSR) && (changed & PIN_DSR)) ||
794 ((arg & TIOCM_CD) && (changed & PIN_DCD)) || 806 ((arg & TIOCM_CD) && (changed & PIN_DCD)) ||
795 ((arg & TIOCM_CTS) && (changed & PIN_CTS))) { 807 ((arg & TIOCM_CTS) && (changed & PIN_CTS)))
796 return 0; 808 return 0;
797 }
798 prev = status; 809 prev = status;
799 } 810 }
800 811
@@ -802,56 +813,25 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
802 return 0; 813 return 0;
803} 814}
804 815
805static int oti6858_ioctl(struct usb_serial_port *port, struct file *file, 816static int oti6858_ioctl(struct tty_struct *tty, struct file *file,
806 unsigned int cmd, unsigned long arg) 817 unsigned int cmd, unsigned long arg)
807{ 818{
808 void __user *user_arg = (void __user *) arg; 819 struct usb_serial_port *port = tty->driver_data;
809 unsigned int x;
810 820
811 dbg("%s(port = %d, cmd = 0x%04x, arg = 0x%08lx)", 821 dbg("%s(port = %d, cmd = 0x%04x, arg = 0x%08lx)",
812 __func__, port->number, cmd, arg); 822 __func__, port->number, cmd, arg);
813 823
814 switch (cmd) { 824 switch (cmd) {
815 case TIOCMBIS: 825 case TIOCMIWAIT:
816 if (copy_from_user(&x, user_arg, sizeof(x))) 826 dbg("%s(): TIOCMIWAIT", __func__);
817 return -EFAULT; 827 return wait_modem_info(port, arg);
818 return oti6858_tiocmset(port, NULL, x, 0); 828 default:
819 829 dbg("%s(): 0x%04x not supported", __func__, cmd);
820 case TIOCMBIC: 830 break;
821 if (copy_from_user(&x, user_arg, sizeof(x)))
822 return -EFAULT;
823 return oti6858_tiocmset(port, NULL, 0, x);
824
825 case TIOCMIWAIT:
826 dbg("%s(): TIOCMIWAIT", __func__);
827 return wait_modem_info(port, arg);
828
829 default:
830 dbg("%s(): 0x%04x not supported", __func__, cmd);
831 break;
832 } 831 }
833
834 return -ENOIOCTLCMD; 832 return -ENOIOCTLCMD;
835} 833}
836 834
837static void oti6858_break_ctl(struct usb_serial_port *port, int break_state)
838{
839 int state;
840
841 dbg("%s(port = %d)", __func__, port->number);
842
843 state = (break_state == 0) ? 0 : 1;
844 dbg("%s(): turning break %s", __func__, state ? "on" : "off");
845
846 /* FIXME */
847/*
848 result = usb_control_msg (serial->dev, usb_sndctrlpipe (serial->dev, 0),
849 BREAK_REQUEST, BREAK_REQUEST_TYPE, state,
850 0, NULL, 0, 100);
851 if (result != 0)
852 dbg("%s(): error sending break", __func__);
853 */
854}
855 835
856static void oti6858_shutdown(struct usb_serial *serial) 836static void oti6858_shutdown(struct usb_serial *serial)
857{ 837{
@@ -964,7 +944,7 @@ static void oti6858_read_int_callback(struct urb *urb)
964 spin_lock_irqsave(&priv->lock, flags); 944 spin_lock_irqsave(&priv->lock, flags);
965 if (priv->flags.write_urb_in_use == 0 945 if (priv->flags.write_urb_in_use == 0
966 && oti6858_buf_data_avail(priv->buf) != 0) { 946 && oti6858_buf_data_avail(priv->buf) != 0) {
967 schedule_delayed_work(&priv->delayed_write_work,0); 947 schedule_delayed_work(&priv->delayed_write_work, 0);
968 resubmit = 0; 948 resubmit = 0;
969 } 949 }
970 spin_unlock_irqrestore(&priv->lock, flags); 950 spin_unlock_irqrestore(&priv->lock, flags);
@@ -973,7 +953,7 @@ static void oti6858_read_int_callback(struct urb *urb)
973 if (resubmit) { 953 if (resubmit) {
974 int result; 954 int result;
975 955
976// dbg("%s(): submitting interrupt urb", __func__); 956/* dbg("%s(): submitting interrupt urb", __func__); */
977 urb->dev = port->serial->dev; 957 urb->dev = port->serial->dev;
978 result = usb_submit_urb(urb, GFP_ATOMIC); 958 result = usb_submit_urb(urb, GFP_ATOMIC);
979 if (result != 0) { 959 if (result != 0) {
@@ -1002,14 +982,16 @@ static void oti6858_read_bulk_callback(struct urb *urb)
1002 spin_unlock_irqrestore(&priv->lock, flags); 982 spin_unlock_irqrestore(&priv->lock, flags);
1003 983
1004 if (status != 0) { 984 if (status != 0) {
1005 if (!port->open_count) { 985 if (!port->port.count) {
1006 dbg("%s(): port is closed, exiting", __func__); 986 dbg("%s(): port is closed, exiting", __func__);
1007 return; 987 return;
1008 } 988 }
1009 /* 989 /*
1010 if (status == -EPROTO) { 990 if (status == -EPROTO) {
1011 // PL2303 mysteriously fails with -EPROTO reschedule the read 991 * PL2303 mysteriously fails with -EPROTO reschedule
1012 dbg("%s - caught -EPROTO, resubmitting the urb", __func__); 992 the read *
993 dbg("%s - caught -EPROTO, resubmitting the urb",
994 __func__);
1013 result = usb_submit_urb(urb, GFP_ATOMIC); 995 result = usb_submit_urb(urb, GFP_ATOMIC);
1014 if (result) 996 if (result)
1015 dev_err(&urb->dev->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result); 997 dev_err(&urb->dev->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result);
@@ -1020,14 +1002,14 @@ static void oti6858_read_bulk_callback(struct urb *urb)
1020 return; 1002 return;
1021 } 1003 }
1022 1004
1023 tty = port->tty; 1005 tty = port->port.tty;
1024 if (tty != NULL && urb->actual_length > 0) { 1006 if (tty != NULL && urb->actual_length > 0) {
1025 tty_insert_flip_string(tty, data, urb->actual_length); 1007 tty_insert_flip_string(tty, data, urb->actual_length);
1026 tty_flip_buffer_push(tty); 1008 tty_flip_buffer_push(tty);
1027 } 1009 }
1028 1010
1029 // schedule the interrupt urb if we are still open */ 1011 /* schedule the interrupt urb if we are still open */
1030 if (port->open_count != 0) { 1012 if (port->port.count != 0) {
1031 port->interrupt_in_urb->dev = port->serial->dev; 1013 port->interrupt_in_urb->dev = port->serial->dev;
1032 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); 1014 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
1033 if (result != 0) { 1015 if (result != 0) {
@@ -1078,7 +1060,7 @@ static void oti6858_write_bulk_callback(struct urb *urb)
1078 1060
1079 priv->flags.write_urb_in_use = 0; 1061 priv->flags.write_urb_in_use = 0;
1080 1062
1081 // schedule the interrupt urb if we are still open */ 1063 /* schedule the interrupt urb if we are still open */
1082 port->interrupt_in_urb->dev = port->serial->dev; 1064 port->interrupt_in_urb->dev = port->serial->dev;
1083 dbg("%s(): submitting interrupt urb", __func__); 1065 dbg("%s(): submitting interrupt urb", __func__);
1084 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); 1066 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
@@ -1153,7 +1135,7 @@ static unsigned int oti6858_buf_data_avail(struct oti6858_buf *pb)
1153{ 1135{
1154 if (pb == NULL) 1136 if (pb == NULL)
1155 return 0; 1137 return 0;
1156 return ((pb->buf_size + pb->buf_put - pb->buf_get) % pb->buf_size); 1138 return (pb->buf_size + pb->buf_put - pb->buf_get) % pb->buf_size;
1157} 1139}
1158 1140
1159/* 1141/*
@@ -1166,7 +1148,7 @@ static unsigned int oti6858_buf_space_avail(struct oti6858_buf *pb)
1166{ 1148{
1167 if (pb == NULL) 1149 if (pb == NULL)
1168 return 0; 1150 return 0;
1169 return ((pb->buf_size + pb->buf_get - pb->buf_put - 1) % pb->buf_size); 1151 return (pb->buf_size + pb->buf_get - pb->buf_put - 1) % pb->buf_size;
1170} 1152}
1171 1153
1172/* 1154/*
@@ -1253,13 +1235,12 @@ static int __init oti6858_init(void)
1253{ 1235{
1254 int retval; 1236 int retval;
1255 1237
1256 if ((retval = usb_serial_register(&oti6858_device)) == 0) { 1238 retval = usb_serial_register(&oti6858_device);
1257 if ((retval = usb_register(&oti6858_driver)) != 0) 1239 if (retval == 0) {
1240 retval = usb_register(&oti6858_driver);
1241 if (retval)
1258 usb_serial_deregister(&oti6858_device); 1242 usb_serial_deregister(&oti6858_device);
1259 else
1260 return 0;
1261 } 1243 }
1262
1263 return retval; 1244 return retval;
1264} 1245}
1265 1246
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index 2a0dd1b50dc4..2c9c446ad625 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -10,7 +10,8 @@
10 * modify it under the terms of the GNU General Public License version 10 * modify it under the terms of the GNU General Public License version
11 * 2 as published by the Free Software Foundation. 11 * 2 as published by the Free Software Foundation.
12 * 12 *
13 * See Documentation/usb/usb-serial.txt for more information on using this driver 13 * See Documentation/usb/usb-serial.txt for more information on using this
14 * driver
14 * 15 *
15 */ 16 */
16 17
@@ -25,7 +26,7 @@
25#include <linux/module.h> 26#include <linux/module.h>
26#include <linux/moduleparam.h> 27#include <linux/moduleparam.h>
27#include <linux/spinlock.h> 28#include <linux/spinlock.h>
28#include <asm/uaccess.h> 29#include <linux/uaccess.h>
29#include <linux/usb.h> 30#include <linux/usb.h>
30#include <linux/usb/serial.h> 31#include <linux/usb/serial.h>
31#include "pl2303.h" 32#include "pl2303.h"
@@ -116,7 +117,7 @@ static struct usb_driver pl2303_driver = {
116#define CONTROL_RTS 0x02 117#define CONTROL_RTS 0x02
117 118
118#define BREAK_REQUEST_TYPE 0x21 119#define BREAK_REQUEST_TYPE 0x21
119#define BREAK_REQUEST 0x23 120#define BREAK_REQUEST 0x23
120#define BREAK_ON 0xffff 121#define BREAK_ON 0xffff
121#define BREAK_OFF 0x0000 122#define BREAK_OFF 0x0000
122 123
@@ -222,7 +223,7 @@ static unsigned int pl2303_buf_data_avail(struct pl2303_buf *pb)
222 if (pb == NULL) 223 if (pb == NULL)
223 return 0; 224 return 0;
224 225
225 return ((pb->buf_size + pb->buf_put - pb->buf_get) % pb->buf_size); 226 return (pb->buf_size + pb->buf_put - pb->buf_get) % pb->buf_size;
226} 227}
227 228
228/* 229/*
@@ -236,7 +237,7 @@ static unsigned int pl2303_buf_space_avail(struct pl2303_buf *pb)
236 if (pb == NULL) 237 if (pb == NULL)
237 return 0; 238 return 0;
238 239
239 return ((pb->buf_size + pb->buf_get - pb->buf_put - 1) % pb->buf_size); 240 return (pb->buf_size + pb->buf_get - pb->buf_put - 1) % pb->buf_size;
240} 241}
241 242
242/* 243/*
@@ -395,7 +396,7 @@ static int pl2303_startup(struct usb_serial *serial)
395 396
396cleanup: 397cleanup:
397 kfree(buf); 398 kfree(buf);
398 for (--i; i>=0; --i) { 399 for (--i; i >= 0; --i) {
399 priv = usb_get_serial_port_data(serial->port[i]); 400 priv = usb_get_serial_port_data(serial->port[i]);
400 pl2303_buf_free(priv->buf); 401 pl2303_buf_free(priv->buf);
401 kfree(priv); 402 kfree(priv);
@@ -407,7 +408,7 @@ cleanup:
407static int set_control_lines(struct usb_device *dev, u8 value) 408static int set_control_lines(struct usb_device *dev, u8 value)
408{ 409{
409 int retval; 410 int retval;
410 411
411 retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 412 retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
412 SET_CONTROL_REQUEST, SET_CONTROL_REQUEST_TYPE, 413 SET_CONTROL_REQUEST, SET_CONTROL_REQUEST_TYPE,
413 value, 0, NULL, 0, 100); 414 value, 0, NULL, 0, 100);
@@ -452,14 +453,14 @@ static void pl2303_send(struct usb_serial_port *port)
452 dev_err(&port->dev, "%s - failed submitting write urb," 453 dev_err(&port->dev, "%s - failed submitting write urb,"
453 " error %d\n", __func__, result); 454 " error %d\n", __func__, result);
454 priv->write_urb_in_use = 0; 455 priv->write_urb_in_use = 0;
455 // TODO: reschedule pl2303_send 456 /* TODO: reschedule pl2303_send */
456 } 457 }
457 458
458 usb_serial_port_softint(port); 459 usb_serial_port_softint(port);
459} 460}
460 461
461static int pl2303_write(struct usb_serial_port *port, const unsigned char *buf, 462static int pl2303_write(struct tty_struct *tty, struct usb_serial_port *port,
462 int count) 463 const unsigned char *buf, int count)
463{ 464{
464 struct pl2303_private *priv = usb_get_serial_port_data(port); 465 struct pl2303_private *priv = usb_get_serial_port_data(port);
465 unsigned long flags; 466 unsigned long flags;
@@ -478,8 +479,9 @@ static int pl2303_write(struct usb_serial_port *port, const unsigned char *buf,
478 return count; 479 return count;
479} 480}
480 481
481static int pl2303_write_room(struct usb_serial_port *port) 482static int pl2303_write_room(struct tty_struct *tty)
482{ 483{
484 struct usb_serial_port *port = tty->driver_data;
483 struct pl2303_private *priv = usb_get_serial_port_data(port); 485 struct pl2303_private *priv = usb_get_serial_port_data(port);
484 int room = 0; 486 int room = 0;
485 unsigned long flags; 487 unsigned long flags;
@@ -494,8 +496,9 @@ static int pl2303_write_room(struct usb_serial_port *port)
494 return room; 496 return room;
495} 497}
496 498
497static int pl2303_chars_in_buffer(struct usb_serial_port *port) 499static int pl2303_chars_in_buffer(struct tty_struct *tty)
498{ 500{
501 struct usb_serial_port *port = tty->driver_data;
499 struct pl2303_private *priv = usb_get_serial_port_data(port); 502 struct pl2303_private *priv = usb_get_serial_port_data(port);
500 int chars = 0; 503 int chars = 0;
501 unsigned long flags; 504 unsigned long flags;
@@ -510,8 +513,8 @@ static int pl2303_chars_in_buffer(struct usb_serial_port *port)
510 return chars; 513 return chars;
511} 514}
512 515
513static void pl2303_set_termios(struct usb_serial_port *port, 516static void pl2303_set_termios(struct tty_struct *tty,
514 struct ktermios *old_termios) 517 struct usb_serial_port *port, struct ktermios *old_termios)
515{ 518{
516 struct usb_serial *serial = port->serial; 519 struct usb_serial *serial = port->serial;
517 struct pl2303_private *priv = usb_get_serial_port_data(port); 520 struct pl2303_private *priv = usb_get_serial_port_data(port);
@@ -526,11 +529,10 @@ static void pl2303_set_termios(struct usb_serial_port *port,
526 529
527 spin_lock_irqsave(&priv->lock, flags); 530 spin_lock_irqsave(&priv->lock, flags);
528 if (!priv->termios_initialized) { 531 if (!priv->termios_initialized) {
529 *(port->tty->termios) = tty_std_termios; 532 *(tty->termios) = tty_std_termios;
530 port->tty->termios->c_cflag = B9600 | CS8 | CREAD | 533 tty->termios->c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
531 HUPCL | CLOCAL; 534 tty->termios->c_ispeed = 9600;
532 port->tty->termios->c_ispeed = 9600; 535 tty->termios->c_ospeed = 9600;
533 port->tty->termios->c_ospeed = 9600;
534 priv->termios_initialized = 1; 536 priv->termios_initialized = 1;
535 } 537 }
536 spin_unlock_irqrestore(&priv->lock, flags); 538 spin_unlock_irqrestore(&priv->lock, flags);
@@ -539,16 +541,16 @@ static void pl2303_set_termios(struct usb_serial_port *port,
539 serial settings even to the same values as before. Thus 541 serial settings even to the same values as before. Thus
540 we actually need to filter in this specific case */ 542 we actually need to filter in this specific case */
541 543
542 if (!tty_termios_hw_change(port->tty->termios, old_termios)) 544 if (!tty_termios_hw_change(tty->termios, old_termios))
543 return; 545 return;
544 546
545 cflag = port->tty->termios->c_cflag; 547 cflag = tty->termios->c_cflag;
546 548
547 buf = kzalloc(7, GFP_KERNEL); 549 buf = kzalloc(7, GFP_KERNEL);
548 if (!buf) { 550 if (!buf) {
549 dev_err(&port->dev, "%s - out of memory.\n", __func__); 551 dev_err(&port->dev, "%s - out of memory.\n", __func__);
550 /* Report back no change occurred */ 552 /* Report back no change occurred */
551 *port->tty->termios = *old_termios; 553 *tty->termios = *old_termios;
552 return; 554 return;
553 } 555 }
554 556
@@ -560,16 +562,24 @@ static void pl2303_set_termios(struct usb_serial_port *port,
560 562
561 if (cflag & CSIZE) { 563 if (cflag & CSIZE) {
562 switch (cflag & CSIZE) { 564 switch (cflag & CSIZE) {
563 case CS5: buf[6] = 5; break; 565 case CS5:
564 case CS6: buf[6] = 6; break; 566 buf[6] = 5;
565 case CS7: buf[6] = 7; break; 567 break;
566 default: 568 case CS6:
567 case CS8: buf[6] = 8; break; 569 buf[6] = 6;
570 break;
571 case CS7:
572 buf[6] = 7;
573 break;
574 default:
575 case CS8:
576 buf[6] = 8;
577 break;
568 } 578 }
569 dbg("%s - data bits = %d", __func__, buf[6]); 579 dbg("%s - data bits = %d", __func__, buf[6]);
570 } 580 }
571 581
572 baud = tty_get_baud_rate(port->tty);; 582 baud = tty_get_baud_rate(tty);
573 dbg("%s - baud = %d", __func__, baud); 583 dbg("%s - baud = %d", __func__, baud);
574 if (baud) { 584 if (baud) {
575 buf[0] = baud & 0xff; 585 buf[0] = baud & 0xff;
@@ -646,12 +656,13 @@ static void pl2303_set_termios(struct usb_serial_port *port,
646 656
647 /* FIXME: Need to read back resulting baud rate */ 657 /* FIXME: Need to read back resulting baud rate */
648 if (baud) 658 if (baud)
649 tty_encode_baud_rate(port->tty, baud, baud); 659 tty_encode_baud_rate(tty, baud, baud);
650 660
651 kfree(buf); 661 kfree(buf);
652} 662}
653 663
654static void pl2303_close(struct usb_serial_port *port, struct file *filp) 664static void pl2303_close(struct tty_struct *tty,
665 struct usb_serial_port *port, struct file *filp)
655{ 666{
656 struct pl2303_private *priv = usb_get_serial_port_data(port); 667 struct pl2303_private *priv = usb_get_serial_port_data(port);
657 unsigned long flags; 668 unsigned long flags;
@@ -666,7 +677,7 @@ static void pl2303_close(struct usb_serial_port *port, struct file *filp)
666 spin_lock_irqsave(&priv->lock, flags); 677 spin_lock_irqsave(&priv->lock, flags);
667 timeout = PL2303_CLOSING_WAIT; 678 timeout = PL2303_CLOSING_WAIT;
668 init_waitqueue_entry(&wait, current); 679 init_waitqueue_entry(&wait, current);
669 add_wait_queue(&port->tty->write_wait, &wait); 680 add_wait_queue(&tty->write_wait, &wait);
670 for (;;) { 681 for (;;) {
671 set_current_state(TASK_INTERRUPTIBLE); 682 set_current_state(TASK_INTERRUPTIBLE);
672 if (pl2303_buf_data_avail(priv->buf) == 0 || 683 if (pl2303_buf_data_avail(priv->buf) == 0 ||
@@ -678,7 +689,7 @@ static void pl2303_close(struct usb_serial_port *port, struct file *filp)
678 spin_lock_irqsave(&priv->lock, flags); 689 spin_lock_irqsave(&priv->lock, flags);
679 } 690 }
680 set_current_state(TASK_RUNNING); 691 set_current_state(TASK_RUNNING);
681 remove_wait_queue(&port->tty->write_wait, &wait); 692 remove_wait_queue(&tty->write_wait, &wait);
682 /* clear out any remaining data in the buffer */ 693 /* clear out any remaining data in the buffer */
683 pl2303_buf_clear(priv->buf); 694 pl2303_buf_clear(priv->buf);
684 spin_unlock_irqrestore(&priv->lock, flags); 695 spin_unlock_irqrestore(&priv->lock, flags);
@@ -690,9 +701,9 @@ static void pl2303_close(struct usb_serial_port *port, struct file *filp)
690 /* for lower rates we should really know how much */ 701 /* for lower rates we should really know how much */
691 /* data is in the buffer to compute a delay */ 702 /* data is in the buffer to compute a delay */
692 /* that is not unnecessarily long) */ 703 /* that is not unnecessarily long) */
693 bps = tty_get_baud_rate(port->tty); 704 bps = tty_get_baud_rate(tty);
694 if (bps > 1200) 705 if (bps > 1200)
695 timeout = max((HZ*2560)/bps,HZ/10); 706 timeout = max((HZ*2560)/bps, HZ/10);
696 else 707 else
697 timeout = 2*HZ; 708 timeout = 2*HZ;
698 schedule_timeout_interruptible(timeout); 709 schedule_timeout_interruptible(timeout);
@@ -703,8 +714,8 @@ static void pl2303_close(struct usb_serial_port *port, struct file *filp)
703 usb_kill_urb(port->read_urb); 714 usb_kill_urb(port->read_urb);
704 usb_kill_urb(port->interrupt_in_urb); 715 usb_kill_urb(port->interrupt_in_urb);
705 716
706 if (port->tty) { 717 if (tty) {
707 c_cflag = port->tty->termios->c_cflag; 718 c_cflag = tty->termios->c_cflag;
708 if (c_cflag & HUPCL) { 719 if (c_cflag & HUPCL) {
709 /* drop DTR and RTS */ 720 /* drop DTR and RTS */
710 spin_lock_irqsave(&priv->lock, flags); 721 spin_lock_irqsave(&priv->lock, flags);
@@ -715,7 +726,8 @@ static void pl2303_close(struct usb_serial_port *port, struct file *filp)
715 } 726 }
716} 727}
717 728
718static int pl2303_open(struct usb_serial_port *port, struct file *filp) 729static int pl2303_open(struct tty_struct *tty,
730 struct usb_serial_port *port, struct file *filp)
719{ 731{
720 struct ktermios tmp_termios; 732 struct ktermios tmp_termios;
721 struct usb_serial *serial = port->serial; 733 struct usb_serial *serial = port->serial;
@@ -734,11 +746,10 @@ static int pl2303_open(struct usb_serial_port *port, struct file *filp)
734 } 746 }
735 747
736 /* Setup termios */ 748 /* Setup termios */
737 if (port->tty) { 749 if (tty)
738 pl2303_set_termios(port, &tmp_termios); 750 pl2303_set_termios(tty, port, &tmp_termios);
739 }
740 751
741 //FIXME: need to assert RTS and DTR if CRTSCTS off 752 /* FIXME: need to assert RTS and DTR if CRTSCTS off */
742 753
743 dbg("%s - submitting read urb", __func__); 754 dbg("%s - submitting read urb", __func__);
744 port->read_urb->dev = serial->dev; 755 port->read_urb->dev = serial->dev;
@@ -746,7 +757,7 @@ static int pl2303_open(struct usb_serial_port *port, struct file *filp)
746 if (result) { 757 if (result) {
747 dev_err(&port->dev, "%s - failed submitting read urb," 758 dev_err(&port->dev, "%s - failed submitting read urb,"
748 " error %d\n", __func__, result); 759 " error %d\n", __func__, result);
749 pl2303_close(port, NULL); 760 pl2303_close(tty, port, NULL);
750 return -EPROTO; 761 return -EPROTO;
751 } 762 }
752 763
@@ -756,15 +767,16 @@ static int pl2303_open(struct usb_serial_port *port, struct file *filp)
756 if (result) { 767 if (result) {
757 dev_err(&port->dev, "%s - failed submitting interrupt urb," 768 dev_err(&port->dev, "%s - failed submitting interrupt urb,"
758 " error %d\n", __func__, result); 769 " error %d\n", __func__, result);
759 pl2303_close(port, NULL); 770 pl2303_close(tty, port, NULL);
760 return -EPROTO; 771 return -EPROTO;
761 } 772 }
762 return 0; 773 return 0;
763} 774}
764 775
765static int pl2303_tiocmset(struct usb_serial_port *port, struct file *file, 776static int pl2303_tiocmset(struct tty_struct *tty, struct file *file,
766 unsigned int set, unsigned int clear) 777 unsigned int set, unsigned int clear)
767{ 778{
779 struct usb_serial_port *port = tty->driver_data;
768 struct pl2303_private *priv = usb_get_serial_port_data(port); 780 struct pl2303_private *priv = usb_get_serial_port_data(port);
769 unsigned long flags; 781 unsigned long flags;
770 u8 control; 782 u8 control;
@@ -787,8 +799,9 @@ static int pl2303_tiocmset(struct usb_serial_port *port, struct file *file,
787 return set_control_lines(port->serial->dev, control); 799 return set_control_lines(port->serial->dev, control);
788} 800}
789 801
790static int pl2303_tiocmget(struct usb_serial_port *port, struct file *file) 802static int pl2303_tiocmget(struct tty_struct *tty, struct file *file)
791{ 803{
804 struct usb_serial_port *port = tty->driver_data;
792 struct pl2303_private *priv = usb_get_serial_port_data(port); 805 struct pl2303_private *priv = usb_get_serial_port_data(port);
793 unsigned long flags; 806 unsigned long flags;
794 unsigned int mcr; 807 unsigned int mcr;
@@ -839,12 +852,12 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
839 status = priv->line_status; 852 status = priv->line_status;
840 spin_unlock_irqrestore(&priv->lock, flags); 853 spin_unlock_irqrestore(&priv->lock, flags);
841 854
842 changed=prevstatus^status; 855 changed = prevstatus ^ status;
843 856
844 if (((arg & TIOCM_RNG) && (changed & UART_RING)) || 857 if (((arg & TIOCM_RNG) && (changed & UART_RING)) ||
845 ((arg & TIOCM_DSR) && (changed & UART_DSR)) || 858 ((arg & TIOCM_DSR) && (changed & UART_DSR)) ||
846 ((arg & TIOCM_CD) && (changed & UART_DCD)) || 859 ((arg & TIOCM_CD) && (changed & UART_DCD)) ||
847 ((arg & TIOCM_CTS) && (changed & UART_CTS)) ) { 860 ((arg & TIOCM_CTS) && (changed & UART_CTS))) {
848 return 0; 861 return 0;
849 } 862 }
850 prevstatus = status; 863 prevstatus = status;
@@ -853,26 +866,26 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
853 return 0; 866 return 0;
854} 867}
855 868
856static int pl2303_ioctl(struct usb_serial_port *port, struct file *file, 869static int pl2303_ioctl(struct tty_struct *tty, struct file *file,
857 unsigned int cmd, unsigned long arg) 870 unsigned int cmd, unsigned long arg)
858{ 871{
872 struct usb_serial_port *port = tty->driver_data;
859 dbg("%s (%d) cmd = 0x%04x", __func__, port->number, cmd); 873 dbg("%s (%d) cmd = 0x%04x", __func__, port->number, cmd);
860 874
861 switch (cmd) { 875 switch (cmd) {
862 case TIOCMIWAIT: 876 case TIOCMIWAIT:
863 dbg("%s (%d) TIOCMIWAIT", __func__, port->number); 877 dbg("%s (%d) TIOCMIWAIT", __func__, port->number);
864 return wait_modem_info(port, arg); 878 return wait_modem_info(port, arg);
865 879 default:
866 default: 880 dbg("%s not supported = 0x%04x", __func__, cmd);
867 dbg("%s not supported = 0x%04x", __func__, cmd); 881 break;
868 break;
869 } 882 }
870
871 return -ENOIOCTLCMD; 883 return -ENOIOCTLCMD;
872} 884}
873 885
874static void pl2303_break_ctl(struct usb_serial_port *port, int break_state) 886static void pl2303_break_ctl(struct tty_struct *tty, int break_state)
875{ 887{
888 struct usb_serial_port *port = tty->driver_data;
876 struct usb_serial *serial = port->serial; 889 struct usb_serial *serial = port->serial;
877 u16 state; 890 u16 state;
878 int result; 891 int result;
@@ -883,7 +896,8 @@ static void pl2303_break_ctl(struct usb_serial_port *port, int break_state)
883 state = BREAK_OFF; 896 state = BREAK_OFF;
884 else 897 else
885 state = BREAK_ON; 898 state = BREAK_ON;
886 dbg("%s - turning break %s", __func__, state==BREAK_OFF ? "off" : "on"); 899 dbg("%s - turning break %s", __func__,
900 state == BREAK_OFF ? "off" : "on");
887 901
888 result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 902 result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
889 BREAK_REQUEST, BREAK_REQUEST_TYPE, state, 903 BREAK_REQUEST, BREAK_REQUEST_TYPE, state,
@@ -937,7 +951,7 @@ static void pl2303_update_line_status(struct usb_serial_port *port,
937 if (actual_length < length) 951 if (actual_length < length)
938 return; 952 return;
939 953
940 /* Save off the uart status for others to look at */ 954 /* Save off the uart status for others to look at */
941 spin_lock_irqsave(&priv->lock, flags); 955 spin_lock_irqsave(&priv->lock, flags);
942 priv->line_status = data[status_idx]; 956 priv->line_status = data[status_idx];
943 spin_unlock_irqrestore(&priv->lock, flags); 957 spin_unlock_irqrestore(&priv->lock, flags);
@@ -1001,7 +1015,7 @@ static void pl2303_read_bulk_callback(struct urb *urb)
1001 1015
1002 if (status) { 1016 if (status) {
1003 dbg("%s - urb status = %d", __func__, status); 1017 dbg("%s - urb status = %d", __func__, status);
1004 if (!port->open_count) { 1018 if (!port->port.count) {
1005 dbg("%s - port is closed, exiting.", __func__); 1019 dbg("%s - port is closed, exiting.", __func__);
1006 return; 1020 return;
1007 } 1021 }
@@ -1036,7 +1050,7 @@ static void pl2303_read_bulk_callback(struct urb *urb)
1036 1050
1037 /* break takes precedence over parity, */ 1051 /* break takes precedence over parity, */
1038 /* which takes precedence over framing errors */ 1052 /* which takes precedence over framing errors */
1039 if (line_status & UART_BREAK_ERROR ) 1053 if (line_status & UART_BREAK_ERROR)
1040 tty_flag = TTY_BREAK; 1054 tty_flag = TTY_BREAK;
1041 else if (line_status & UART_PARITY_ERROR) 1055 else if (line_status & UART_PARITY_ERROR)
1042 tty_flag = TTY_PARITY; 1056 tty_flag = TTY_PARITY;
@@ -1044,7 +1058,7 @@ static void pl2303_read_bulk_callback(struct urb *urb)
1044 tty_flag = TTY_FRAME; 1058 tty_flag = TTY_FRAME;
1045 dbg("%s - tty_flag = %d", __func__, tty_flag); 1059 dbg("%s - tty_flag = %d", __func__, tty_flag);
1046 1060
1047 tty = port->tty; 1061 tty = port->port.tty;
1048 if (tty && urb->actual_length) { 1062 if (tty && urb->actual_length) {
1049 tty_buffer_request_room(tty, urb->actual_length + 1); 1063 tty_buffer_request_room(tty, urb->actual_length + 1);
1050 /* overrun is special, not associated with a char */ 1064 /* overrun is special, not associated with a char */
@@ -1056,7 +1070,7 @@ static void pl2303_read_bulk_callback(struct urb *urb)
1056 } 1070 }
1057 1071
1058 /* Schedule the next read _if_ we are still open */ 1072 /* Schedule the next read _if_ we are still open */
1059 if (port->open_count) { 1073 if (port->port.count) {
1060 urb->dev = port->serial->dev; 1074 urb->dev = port->serial->dev;
1061 result = usb_submit_urb(urb, GFP_ATOMIC); 1075 result = usb_submit_urb(urb, GFP_ATOMIC);
1062 if (result) 1076 if (result)
diff --git a/drivers/usb/serial/safe_serial.c b/drivers/usb/serial/safe_serial.c
index 94bddf06ea4f..def52d07a4ea 100644
--- a/drivers/usb/serial/safe_serial.c
+++ b/drivers/usb/serial/safe_serial.c
@@ -13,24 +13,25 @@
13 * Stuart Lynne <sl@lineo.com>, Tom Rushworth <tbr@lineo.com> 13 * Stuart Lynne <sl@lineo.com>, Tom Rushworth <tbr@lineo.com>
14 */ 14 */
15 15
16/* 16/*
17 * The encapsultaion is designed to overcome difficulties with some USB hardware. 17 * The encapsultaion is designed to overcome difficulties with some USB
18 * hardware.
18 * 19 *
19 * While the USB protocol has a CRC over the data while in transit, i.e. while 20 * While the USB protocol has a CRC over the data while in transit, i.e. while
20 * being carried over the bus, there is no end to end protection. If the hardware 21 * being carried over the bus, there is no end to end protection. If the
21 * has any problems getting the data into or out of the USB transmit and receive 22 * hardware has any problems getting the data into or out of the USB transmit
22 * FIFO's then data can be lost. 23 * and receive FIFO's then data can be lost.
23 * 24 *
24 * This protocol adds a two byte trailer to each USB packet to specify the number 25 * This protocol adds a two byte trailer to each USB packet to specify the
25 * of bytes of valid data and a 10 bit CRC that will allow the receiver to verify 26 * number of bytes of valid data and a 10 bit CRC that will allow the receiver
26 * that the entire USB packet was received without error. 27 * to verify that the entire USB packet was received without error.
27 * 28 *
28 * Because in this case the sender and receiver are the class and function drivers 29 * Because in this case the sender and receiver are the class and function
29 * there is now end to end protection. 30 * drivers there is now end to end protection.
30 * 31 *
31 * There is an additional option that can be used to force all transmitted packets 32 * There is an additional option that can be used to force all transmitted
32 * to be padded to the maximum packet size. This provides a work around for some 33 * packets to be padded to the maximum packet size. This provides a work
33 * devices which have problems with small USB packets. 34 * around for some devices which have problems with small USB packets.
34 * 35 *
35 * Assuming a packetsize of N: 36 * Assuming a packetsize of N:
36 * 37 *
@@ -44,11 +45,12 @@
44 * | Data Length | 10 bit CRC | 45 * | Data Length | 10 bit CRC |
45 * + 7 . 6 . 5 . 4 . 3 . 2 . 1 . 0 | 7 . 6 . 5 . 4 . 3 . 2 . 1 . 0 + 46 * + 7 . 6 . 5 . 4 . 3 . 2 . 1 . 0 | 7 . 6 . 5 . 4 . 3 . 2 . 1 . 0 +
46 * 47 *
47 * The 10 bit CRC is computed across the sent data, followed by the trailer with 48 * The 10 bit CRC is computed across the sent data, followed by the trailer
48 * the length set and the CRC set to zero. The CRC is then OR'd into the trailer. 49 * with the length set and the CRC set to zero. The CRC is then OR'd into
50 * the trailer.
49 * 51 *
50 * When received a 10 bit CRC is computed over the entire frame including the trailer 52 * When received a 10 bit CRC is computed over the entire frame including
51 * and should be equal to zero. 53 * the trailer and should be equal to zero.
52 * 54 *
53 * Two module parameters are used to control the encapsulation, if both are 55 * Two module parameters are used to control the encapsulation, if both are
54 * turned of the module works as a simple serial device with NO 56 * turned of the module works as a simple serial device with NO
@@ -69,7 +71,7 @@
69#include <linux/tty_flip.h> 71#include <linux/tty_flip.h>
70#include <linux/module.h> 72#include <linux/module.h>
71#include <linux/spinlock.h> 73#include <linux/spinlock.h>
72#include <asm/uaccess.h> 74#include <linux/uaccess.h>
73#include <linux/usb.h> 75#include <linux/usb.h>
74#include <linux/usb/serial.h> 76#include <linux/usb/serial.h>
75 77
@@ -86,12 +88,12 @@ static int padded = CONFIG_USB_SERIAL_SAFE_PADDED;
86#define DRIVER_AUTHOR "sl@lineo.com, tbr@lineo.com" 88#define DRIVER_AUTHOR "sl@lineo.com, tbr@lineo.com"
87#define DRIVER_DESC "USB Safe Encapsulated Serial" 89#define DRIVER_DESC "USB Safe Encapsulated Serial"
88 90
89MODULE_AUTHOR (DRIVER_AUTHOR); 91MODULE_AUTHOR(DRIVER_AUTHOR);
90MODULE_DESCRIPTION (DRIVER_DESC); 92MODULE_DESCRIPTION(DRIVER_DESC);
91MODULE_LICENSE("GPL"); 93MODULE_LICENSE("GPL");
92 94
93static __u16 vendor; // no default 95static __u16 vendor; /* no default */
94static __u16 product; // no default 96static __u16 product; /* no default */
95module_param(vendor, ushort, 0); 97module_param(vendor, ushort, 0);
96MODULE_PARM_DESC(vendor, "User specified USB idVendor (required)"); 98MODULE_PARM_DESC(vendor, "User specified USB idVendor (required)");
97module_param(product, ushort, 0); 99module_param(product, ushort, 0);
@@ -122,30 +124,31 @@ MODULE_PARM_DESC(padded, "Pad to full wMaxPacketSize On/Off");
122#define LINEO_SAFESERIAL_CRC_PADDED 0x02 124#define LINEO_SAFESERIAL_CRC_PADDED 0x02
123 125
124 126
125#define MY_USB_DEVICE(vend,prod,dc,ic,isc) \ 127#define MY_USB_DEVICE(vend, prod, dc, ic, isc) \
126 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_DEV_CLASS | \ 128 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
127 USB_DEVICE_ID_MATCH_INT_CLASS | USB_DEVICE_ID_MATCH_INT_SUBCLASS, \ 129 USB_DEVICE_ID_MATCH_DEV_CLASS | \
128 .idVendor = (vend), \ 130 USB_DEVICE_ID_MATCH_INT_CLASS | \
129 .idProduct = (prod),\ 131 USB_DEVICE_ID_MATCH_INT_SUBCLASS, \
130 .bDeviceClass = (dc),\ 132 .idVendor = (vend), \
131 .bInterfaceClass = (ic), \ 133 .idProduct = (prod),\
132 .bInterfaceSubClass = (isc), 134 .bDeviceClass = (dc),\
135 .bInterfaceClass = (ic), \
136 .bInterfaceSubClass = (isc),
133 137
134static struct usb_device_id id_table[] = { 138static struct usb_device_id id_table[] = {
135 {MY_USB_DEVICE (0x49f, 0xffff, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, // Itsy 139 {MY_USB_DEVICE(0x49f, 0xffff, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, /* Itsy */
136 {MY_USB_DEVICE (0x3f0, 0x2101, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, // Calypso 140 {MY_USB_DEVICE(0x3f0, 0x2101, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, /* Calypso */
137 {MY_USB_DEVICE (0x4dd, 0x8001, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, // Iris 141 {MY_USB_DEVICE(0x4dd, 0x8001, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, /* Iris */
138 {MY_USB_DEVICE (0x4dd, 0x8002, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, // Collie 142 {MY_USB_DEVICE(0x4dd, 0x8002, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, /* Collie */
139 {MY_USB_DEVICE (0x4dd, 0x8003, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, // Collie 143 {MY_USB_DEVICE(0x4dd, 0x8003, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, /* Collie */
140 {MY_USB_DEVICE (0x4dd, 0x8004, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, // Collie 144 {MY_USB_DEVICE(0x4dd, 0x8004, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, /* Collie */
141 {MY_USB_DEVICE (0x5f9, 0xffff, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, // Sharp tmp 145 {MY_USB_DEVICE(0x5f9, 0xffff, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, /* Sharp tmp */
142 // extra null entry for module 146 /* extra null entry for module vendor/produc parameters */
143 // vendor/produc parameters 147 {MY_USB_DEVICE(0, 0, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)},
144 {MY_USB_DEVICE (0, 0, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, 148 {} /* terminating entry */
145 {} // terminating entry
146}; 149};
147 150
148MODULE_DEVICE_TABLE (usb, id_table); 151MODULE_DEVICE_TABLE(usb, id_table);
149 152
150static struct usb_driver safe_driver = { 153static struct usb_driver safe_driver = {
151 .name = "safe_serial", 154 .name = "safe_serial",
@@ -156,29 +159,45 @@ static struct usb_driver safe_driver = {
156}; 159};
157 160
158static const __u16 crc10_table[256] = { 161static const __u16 crc10_table[256] = {
159 0x000, 0x233, 0x255, 0x066, 0x299, 0x0aa, 0x0cc, 0x2ff, 0x301, 0x132, 0x154, 0x367, 0x198, 0x3ab, 0x3cd, 0x1fe, 162 0x000, 0x233, 0x255, 0x066, 0x299, 0x0aa, 0x0cc, 0x2ff,
160 0x031, 0x202, 0x264, 0x057, 0x2a8, 0x09b, 0x0fd, 0x2ce, 0x330, 0x103, 0x165, 0x356, 0x1a9, 0x39a, 0x3fc, 0x1cf, 163 0x301, 0x132, 0x154, 0x367, 0x198, 0x3ab, 0x3cd, 0x1fe,
161 0x062, 0x251, 0x237, 0x004, 0x2fb, 0x0c8, 0x0ae, 0x29d, 0x363, 0x150, 0x136, 0x305, 0x1fa, 0x3c9, 0x3af, 0x19c, 164 0x031, 0x202, 0x264, 0x057, 0x2a8, 0x09b, 0x0fd, 0x2ce,
162 0x053, 0x260, 0x206, 0x035, 0x2ca, 0x0f9, 0x09f, 0x2ac, 0x352, 0x161, 0x107, 0x334, 0x1cb, 0x3f8, 0x39e, 0x1ad, 165 0x330, 0x103, 0x165, 0x356, 0x1a9, 0x39a, 0x3fc, 0x1cf,
163 0x0c4, 0x2f7, 0x291, 0x0a2, 0x25d, 0x06e, 0x008, 0x23b, 0x3c5, 0x1f6, 0x190, 0x3a3, 0x15c, 0x36f, 0x309, 0x13a, 166 0x062, 0x251, 0x237, 0x004, 0x2fb, 0x0c8, 0x0ae, 0x29d,
164 0x0f5, 0x2c6, 0x2a0, 0x093, 0x26c, 0x05f, 0x039, 0x20a, 0x3f4, 0x1c7, 0x1a1, 0x392, 0x16d, 0x35e, 0x338, 0x10b, 167 0x363, 0x150, 0x136, 0x305, 0x1fa, 0x3c9, 0x3af, 0x19c,
165 0x0a6, 0x295, 0x2f3, 0x0c0, 0x23f, 0x00c, 0x06a, 0x259, 0x3a7, 0x194, 0x1f2, 0x3c1, 0x13e, 0x30d, 0x36b, 0x158, 168 0x053, 0x260, 0x206, 0x035, 0x2ca, 0x0f9, 0x09f, 0x2ac,
166 0x097, 0x2a4, 0x2c2, 0x0f1, 0x20e, 0x03d, 0x05b, 0x268, 0x396, 0x1a5, 0x1c3, 0x3f0, 0x10f, 0x33c, 0x35a, 0x169, 169 0x352, 0x161, 0x107, 0x334, 0x1cb, 0x3f8, 0x39e, 0x1ad,
167 0x188, 0x3bb, 0x3dd, 0x1ee, 0x311, 0x122, 0x144, 0x377, 0x289, 0x0ba, 0x0dc, 0x2ef, 0x010, 0x223, 0x245, 0x076, 170 0x0c4, 0x2f7, 0x291, 0x0a2, 0x25d, 0x06e, 0x008, 0x23b,
168 0x1b9, 0x38a, 0x3ec, 0x1df, 0x320, 0x113, 0x175, 0x346, 0x2b8, 0x08b, 0x0ed, 0x2de, 0x021, 0x212, 0x274, 0x047, 171 0x3c5, 0x1f6, 0x190, 0x3a3, 0x15c, 0x36f, 0x309, 0x13a,
169 0x1ea, 0x3d9, 0x3bf, 0x18c, 0x373, 0x140, 0x126, 0x315, 0x2eb, 0x0d8, 0x0be, 0x28d, 0x072, 0x241, 0x227, 0x014, 172 0x0f5, 0x2c6, 0x2a0, 0x093, 0x26c, 0x05f, 0x039, 0x20a,
170 0x1db, 0x3e8, 0x38e, 0x1bd, 0x342, 0x171, 0x117, 0x324, 0x2da, 0x0e9, 0x08f, 0x2bc, 0x043, 0x270, 0x216, 0x025, 173 0x3f4, 0x1c7, 0x1a1, 0x392, 0x16d, 0x35e, 0x338, 0x10b,
171 0x14c, 0x37f, 0x319, 0x12a, 0x3d5, 0x1e6, 0x180, 0x3b3, 0x24d, 0x07e, 0x018, 0x22b, 0x0d4, 0x2e7, 0x281, 0x0b2, 174 0x0a6, 0x295, 0x2f3, 0x0c0, 0x23f, 0x00c, 0x06a, 0x259,
172 0x17d, 0x34e, 0x328, 0x11b, 0x3e4, 0x1d7, 0x1b1, 0x382, 0x27c, 0x04f, 0x029, 0x21a, 0x0e5, 0x2d6, 0x2b0, 0x083, 175 0x3a7, 0x194, 0x1f2, 0x3c1, 0x13e, 0x30d, 0x36b, 0x158,
173 0x12e, 0x31d, 0x37b, 0x148, 0x3b7, 0x184, 0x1e2, 0x3d1, 0x22f, 0x01c, 0x07a, 0x249, 0x0b6, 0x285, 0x2e3, 0x0d0, 176 0x097, 0x2a4, 0x2c2, 0x0f1, 0x20e, 0x03d, 0x05b, 0x268,
174 0x11f, 0x32c, 0x34a, 0x179, 0x386, 0x1b5, 0x1d3, 0x3e0, 0x21e, 0x02d, 0x04b, 0x278, 0x087, 0x2b4, 0x2d2, 0x0e1, 177 0x396, 0x1a5, 0x1c3, 0x3f0, 0x10f, 0x33c, 0x35a, 0x169,
178 0x188, 0x3bb, 0x3dd, 0x1ee, 0x311, 0x122, 0x144, 0x377,
179 0x289, 0x0ba, 0x0dc, 0x2ef, 0x010, 0x223, 0x245, 0x076,
180 0x1b9, 0x38a, 0x3ec, 0x1df, 0x320, 0x113, 0x175, 0x346,
181 0x2b8, 0x08b, 0x0ed, 0x2de, 0x021, 0x212, 0x274, 0x047,
182 0x1ea, 0x3d9, 0x3bf, 0x18c, 0x373, 0x140, 0x126, 0x315,
183 0x2eb, 0x0d8, 0x0be, 0x28d, 0x072, 0x241, 0x227, 0x014,
184 0x1db, 0x3e8, 0x38e, 0x1bd, 0x342, 0x171, 0x117, 0x324,
185 0x2da, 0x0e9, 0x08f, 0x2bc, 0x043, 0x270, 0x216, 0x025,
186 0x14c, 0x37f, 0x319, 0x12a, 0x3d5, 0x1e6, 0x180, 0x3b3,
187 0x24d, 0x07e, 0x018, 0x22b, 0x0d4, 0x2e7, 0x281, 0x0b2,
188 0x17d, 0x34e, 0x328, 0x11b, 0x3e4, 0x1d7, 0x1b1, 0x382,
189 0x27c, 0x04f, 0x029, 0x21a, 0x0e5, 0x2d6, 0x2b0, 0x083,
190 0x12e, 0x31d, 0x37b, 0x148, 0x3b7, 0x184, 0x1e2, 0x3d1,
191 0x22f, 0x01c, 0x07a, 0x249, 0x0b6, 0x285, 0x2e3, 0x0d0,
192 0x11f, 0x32c, 0x34a, 0x179, 0x386, 0x1b5, 0x1d3, 0x3e0,
193 0x21e, 0x02d, 0x04b, 0x278, 0x087, 0x2b4, 0x2d2, 0x0e1,
175}; 194};
176 195
177#define CRC10_INITFCS 0x000 // Initial FCS value 196#define CRC10_INITFCS 0x000 /* Initial FCS value */
178#define CRC10_GOODFCS 0x000 // Good final FCS value 197#define CRC10_GOODFCS 0x000 /* Good final FCS value */
179#define CRC10_FCS(fcs, c) ( (((fcs) << 8) & 0x3ff) ^ crc10_table[((fcs) >> 2) & 0xff] ^ (c)) 198#define CRC10_FCS(fcs, c) ((((fcs) << 8) & 0x3ff) ^ crc10_table[((fcs) >> 2) & 0xff] ^ (c))
180 199
181/** 200/**
182 * fcs_compute10 - memcpy and calculate 10 bit CRC across buffer 201 * fcs_compute10 - memcpy and calculate 10 bit CRC across buffer
183 * @sp: pointer to buffer 202 * @sp: pointer to buffer
184 * @len: number of bytes 203 * @len: number of bytes
@@ -187,13 +206,13 @@ static const __u16 crc10_table[256] = {
187 * Perform a memcpy and calculate fcs using ppp 10bit CRC algorithm. Return 206 * Perform a memcpy and calculate fcs using ppp 10bit CRC algorithm. Return
188 * new 10 bit FCS. 207 * new 10 bit FCS.
189 */ 208 */
190static __u16 __inline__ fcs_compute10 (unsigned char *sp, int len, __u16 fcs) 209static __u16 __inline__ fcs_compute10(unsigned char *sp, int len, __u16 fcs)
191{ 210{
192 for (; len-- > 0; fcs = CRC10_FCS (fcs, *sp++)); 211 for (; len-- > 0; fcs = CRC10_FCS(fcs, *sp++));
193 return fcs; 212 return fcs;
194} 213}
195 214
196static void safe_read_bulk_callback (struct urb *urb) 215static void safe_read_bulk_callback(struct urb *urb)
197{ 216{
198 struct usb_serial_port *port = urb->context; 217 struct usb_serial_port *port = urb->context;
199 unsigned char *data = urb->transfer_buffer; 218 unsigned char *data = urb->transfer_buffer;
@@ -201,7 +220,7 @@ static void safe_read_bulk_callback (struct urb *urb)
201 int result; 220 int result;
202 int status = urb->status; 221 int status = urb->status;
203 222
204 dbg ("%s", __func__); 223 dbg("%s", __func__);
205 224
206 if (status) { 225 if (status) {
207 dbg("%s - nonzero read bulk status received: %d", 226 dbg("%s - nonzero read bulk status received: %d",
@@ -209,76 +228,82 @@ static void safe_read_bulk_callback (struct urb *urb)
209 return; 228 return;
210 } 229 }
211 230
212 dbg ("safe_read_bulk_callback length: %d", port->read_urb->actual_length); 231 dbg("safe_read_bulk_callback length: %d",
232 port->read_urb->actual_length);
213#ifdef ECHO_RCV 233#ifdef ECHO_RCV
214 { 234 {
215 int i; 235 int i;
216 unsigned char *cp = port->read_urb->transfer_buffer; 236 unsigned char *cp = port->read_urb->transfer_buffer;
217 for (i = 0; i < port->read_urb->actual_length; i++) { 237 for (i = 0; i < port->read_urb->actual_length; i++) {
218 if ((i % 32) == 0) { 238 if ((i % 32) == 0)
219 printk ("\nru[%02x] ", i); 239 printk("\nru[%02x] ", i);
220 } 240 printk("%02x ", *cp++);
221 printk ("%02x ", *cp++);
222 } 241 }
223 printk ("\n"); 242 printk("\n");
224 } 243 }
225#endif 244#endif
226 if (safe) { 245 if (safe) {
227 __u16 fcs; 246 __u16 fcs;
228 if (!(fcs = fcs_compute10 (data, length, CRC10_INITFCS))) { 247 fcs = fcs_compute10(data, length, CRC10_INITFCS);
248 if (!fcs) {
229 int actual_length = data[length - 2] >> 2; 249 int actual_length = data[length - 2] >> 2;
230 if (actual_length <= (length - 2)) { 250 if (actual_length <= (length - 2)) {
231 info ("%s - actual: %d", __func__, actual_length); 251 info("%s - actual: %d", __func__,
232 tty_insert_flip_string(port->tty, data, actual_length); 252 actual_length);
233 tty_flip_buffer_push (port->tty); 253 tty_insert_flip_string(port->port.tty,
254 data, actual_length);
255 tty_flip_buffer_push(port->port.tty);
234 } else { 256 } else {
235 err ("%s - inconsistent lengths %d:%d", __func__, 257 err("%s - inconsistent lengths %d:%d",
236 actual_length, length); 258 __func__, actual_length, length);
237 } 259 }
238 } else { 260 } else {
239 err ("%s - bad CRC %x", __func__, fcs); 261 err("%s - bad CRC %x", __func__, fcs);
240 } 262 }
241 } else { 263 } else {
242 tty_insert_flip_string(port->tty, data, length); 264 tty_insert_flip_string(port->port.tty, data, length);
243 tty_flip_buffer_push (port->tty); 265 tty_flip_buffer_push(port->port.tty);
244 } 266 }
245 267
246 /* Continue trying to always read */ 268 /* Continue trying to always read */
247 usb_fill_bulk_urb (urb, port->serial->dev, 269 usb_fill_bulk_urb(urb, port->serial->dev,
248 usb_rcvbulkpipe (port->serial->dev, port->bulk_in_endpointAddress), 270 usb_rcvbulkpipe(port->serial->dev,
249 urb->transfer_buffer, urb->transfer_buffer_length, 271 port->bulk_in_endpointAddress),
250 safe_read_bulk_callback, port); 272 urb->transfer_buffer, urb->transfer_buffer_length,
251 273 safe_read_bulk_callback, port);
252 if ((result = usb_submit_urb (urb, GFP_ATOMIC))) { 274
253 err ("%s - failed resubmitting read urb, error %d", __func__, result); 275 result = usb_submit_urb(urb, GFP_ATOMIC);
276 if (result)
277 err("%s - failed resubmitting read urb, error %d",
278 __func__, result);
254 /* FIXME: Need a mechanism to retry later if this happens */ 279 /* FIXME: Need a mechanism to retry later if this happens */
255 }
256} 280}
257 281
258static int safe_write (struct usb_serial_port *port, const unsigned char *buf, int count) 282static int safe_write(struct tty_struct *tty, struct usb_serial_port *port,
283 const unsigned char *buf, int count)
259{ 284{
260 unsigned char *data; 285 unsigned char *data;
261 int result; 286 int result;
262 int i; 287 int i;
263 int packet_length; 288 int packet_length;
264 289
265 dbg ("safe_write port: %p %d urb: %p count: %d", port, port->number, port->write_urb, 290 dbg("safe_write port: %p %d urb: %p count: %d",
266 count); 291 port, port->number, port->write_urb, count);
267 292
268 if (!port->write_urb) { 293 if (!port->write_urb) {
269 dbg ("%s - write urb NULL", __func__); 294 dbg("%s - write urb NULL", __func__);
270 return 0; 295 return 0;
271 } 296 }
272 297
273 dbg ("safe_write write_urb: %d transfer_buffer_length", 298 dbg("safe_write write_urb: %d transfer_buffer_length",
274 port->write_urb->transfer_buffer_length); 299 port->write_urb->transfer_buffer_length);
275 300
276 if (!port->write_urb->transfer_buffer_length) { 301 if (!port->write_urb->transfer_buffer_length) {
277 dbg ("%s - write urb transfer_buffer_length zero", __func__); 302 dbg("%s - write urb transfer_buffer_length zero", __func__);
278 return 0; 303 return 0;
279 } 304 }
280 if (count == 0) { 305 if (count == 0) {
281 dbg ("%s - write request of 0 bytes", __func__); 306 dbg("%s - write request of 0 bytes", __func__);
282 return 0; 307 return 0;
283 } 308 }
284 spin_lock_bh(&port->lock); 309 spin_lock_bh(&port->lock);
@@ -290,85 +315,85 @@ static int safe_write (struct usb_serial_port *port, const unsigned char *buf, i
290 port->write_urb_busy = 1; 315 port->write_urb_busy = 1;
291 spin_unlock_bh(&port->lock); 316 spin_unlock_bh(&port->lock);
292 317
293 packet_length = port->bulk_out_size; // get max packetsize 318 packet_length = port->bulk_out_size; /* get max packetsize */
294 319
295 i = packet_length - (safe ? 2 : 0); // get bytes to send 320 i = packet_length - (safe ? 2 : 0); /* get bytes to send */
296 count = (count > i) ? i : count; 321 count = (count > i) ? i : count;
297 322
298 323
299 // get the data into the transfer buffer 324 /* get the data into the transfer buffer */
300 data = port->write_urb->transfer_buffer; 325 data = port->write_urb->transfer_buffer;
301 memset (data, '0', packet_length); 326 memset(data, '0', packet_length);
302 327
303 memcpy (data, buf, count); 328 memcpy(data, buf, count);
304 329
305 if (safe) { 330 if (safe) {
306 __u16 fcs; 331 __u16 fcs;
307 332
308 // pad if necessary 333 /* pad if necessary */
309 if (!padded) { 334 if (!padded)
310 packet_length = count + 2; 335 packet_length = count + 2;
311 } 336 /* set count */
312 // set count
313 data[packet_length - 2] = count << 2; 337 data[packet_length - 2] = count << 2;
314 data[packet_length - 1] = 0; 338 data[packet_length - 1] = 0;
315 339
316 // compute fcs and insert into trailer 340 /* compute fcs and insert into trailer */
317 fcs = fcs_compute10 (data, packet_length, CRC10_INITFCS); 341 fcs = fcs_compute10(data, packet_length, CRC10_INITFCS);
318 data[packet_length - 2] |= fcs >> 8; 342 data[packet_length - 2] |= fcs >> 8;
319 data[packet_length - 1] |= fcs & 0xff; 343 data[packet_length - 1] |= fcs & 0xff;
320 344
321 // set length to send 345 /* set length to send */
322 port->write_urb->transfer_buffer_length = packet_length; 346 port->write_urb->transfer_buffer_length = packet_length;
323 } else { 347 } else {
324 port->write_urb->transfer_buffer_length = count; 348 port->write_urb->transfer_buffer_length = count;
325 } 349 }
326 350
327 usb_serial_debug_data(debug, &port->dev, __func__, count, port->write_urb->transfer_buffer); 351 usb_serial_debug_data(debug, &port->dev, __func__, count,
352 port->write_urb->transfer_buffer);
328#ifdef ECHO_TX 353#ifdef ECHO_TX
329 { 354 {
330 int i; 355 int i;
331 unsigned char *cp = port->write_urb->transfer_buffer; 356 unsigned char *cp = port->write_urb->transfer_buffer;
332 for (i = 0; i < port->write_urb->transfer_buffer_length; i++) { 357 for (i = 0; i < port->write_urb->transfer_buffer_length; i++) {
333 if ((i % 32) == 0) { 358 if ((i % 32) == 0)
334 printk ("\nsu[%02x] ", i); 359 printk("\nsu[%02x] ", i);
335 } 360 printk("%02x ", *cp++);
336 printk ("%02x ", *cp++);
337 } 361 }
338 printk ("\n"); 362 printk("\n");
339 } 363 }
340#endif 364#endif
341 port->write_urb->dev = port->serial->dev; 365 port->write_urb->dev = port->serial->dev;
342 if ((result = usb_submit_urb (port->write_urb, GFP_KERNEL))) { 366 result = usb_submit_urb(port->write_urb, GFP_KERNEL);
367 if (result) {
343 port->write_urb_busy = 0; 368 port->write_urb_busy = 0;
344 err ("%s - failed submitting write urb, error %d", __func__, result); 369 err("%s - failed submitting write urb, error %d",
370 __func__, result);
345 return 0; 371 return 0;
346 } 372 }
347 dbg ("%s urb: %p submitted", __func__, port->write_urb); 373 dbg("%s urb: %p submitted", __func__, port->write_urb);
348 374
349 return (count); 375 return count;
350} 376}
351 377
352static int safe_write_room (struct usb_serial_port *port) 378static int safe_write_room(struct tty_struct *tty)
353{ 379{
380 struct usb_serial_port *port = tty->driver_data;
354 int room = 0; /* Default: no room */ 381 int room = 0; /* Default: no room */
355 unsigned long flags; 382 unsigned long flags;
356 383
357 dbg ("%s", __func__); 384 dbg("%s", __func__);
358 385
359 spin_lock_irqsave(&port->lock, flags); 386 spin_lock_irqsave(&port->lock, flags);
360 if (port->write_urb_busy) 387 if (port->write_urb_busy)
361 room = port->bulk_out_size - (safe ? 2 : 0); 388 room = port->bulk_out_size - (safe ? 2 : 0);
362 spin_unlock_irqrestore(&port->lock, flags); 389 spin_unlock_irqrestore(&port->lock, flags);
363 390
364 if (room) { 391 if (room)
365 dbg ("safe_write_room returns %d", room); 392 dbg("safe_write_room returns %d", room);
366 }
367
368 return room; 393 return room;
369} 394}
370 395
371static int safe_startup (struct usb_serial *serial) 396static int safe_startup(struct usb_serial *serial)
372{ 397{
373 switch (serial->interface->cur_altsetting->desc.bInterfaceProtocol) { 398 switch (serial->interface->cur_altsetting->desc.bInterfaceProtocol) {
374 case LINEO_SAFESERIAL_CRC: 399 case LINEO_SAFESERIAL_CRC:
@@ -396,17 +421,18 @@ static struct usb_serial_driver safe_device = {
396 .attach = safe_startup, 421 .attach = safe_startup,
397}; 422};
398 423
399static int __init safe_init (void) 424static int __init safe_init(void)
400{ 425{
401 int i, retval; 426 int i, retval;
402 427
403 info (DRIVER_VERSION " " DRIVER_AUTHOR); 428 info(DRIVER_VERSION " " DRIVER_AUTHOR);
404 info (DRIVER_DESC); 429 info(DRIVER_DESC);
405 info ("vendor: %x product: %x safe: %d padded: %d\n", vendor, product, safe, padded); 430 info("vendor: %x product: %x safe: %d padded: %d\n",
431 vendor, product, safe, padded);
406 432
407 // if we have vendor / product parameters patch them into id list 433 /* if we have vendor / product parameters patch them into id list */
408 if (vendor || product) { 434 if (vendor || product) {
409 info ("vendor: %x product: %x\n", vendor, product); 435 info("vendor: %x product: %x\n", vendor, product);
410 436
411 for (i = 0; i < ARRAY_SIZE(id_table); i++) { 437 for (i = 0; i < ARRAY_SIZE(id_table); i++) {
412 if (!id_table[i].idVendor && !id_table[i].idProduct) { 438 if (!id_table[i].idVendor && !id_table[i].idProduct) {
@@ -431,11 +457,11 @@ failed_usb_serial_register:
431 return retval; 457 return retval;
432} 458}
433 459
434static void __exit safe_exit (void) 460static void __exit safe_exit(void)
435{ 461{
436 usb_deregister (&safe_driver); 462 usb_deregister(&safe_driver);
437 usb_serial_deregister (&safe_device); 463 usb_serial_deregister(&safe_device);
438} 464}
439 465
440module_init (safe_init); 466module_init(safe_init);
441module_exit (safe_exit); 467module_exit(safe_exit);
diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c
index 29074c1ba22b..2f6f1523ec56 100644
--- a/drivers/usb/serial/sierra.c
+++ b/drivers/usb/serial/sierra.c
@@ -250,7 +250,8 @@ struct sierra_port_private {
250 int ri_state; 250 int ri_state;
251}; 251};
252 252
253static int sierra_send_setup(struct usb_serial_port *port) 253static int sierra_send_setup(struct tty_struct *tty,
254 struct usb_serial_port *port)
254{ 255{
255 struct usb_serial *serial = port->serial; 256 struct usb_serial *serial = port->serial;
256 struct sierra_port_private *portdata; 257 struct sierra_port_private *portdata;
@@ -260,7 +261,7 @@ static int sierra_send_setup(struct usb_serial_port *port)
260 261
261 portdata = usb_get_serial_port_data(port); 262 portdata = usb_get_serial_port_data(port);
262 263
263 if (port->tty) { 264 if (tty) {
264 int val = 0; 265 int val = 0;
265 if (portdata->dtr_state) 266 if (portdata->dtr_state)
266 val |= 0x01; 267 val |= 0x01;
@@ -284,32 +285,17 @@ static int sierra_send_setup(struct usb_serial_port *port)
284 return 0; 285 return 0;
285} 286}
286 287
287static void sierra_rx_throttle(struct usb_serial_port *port) 288static void sierra_set_termios(struct tty_struct *tty,
289 struct usb_serial_port *port, struct ktermios *old_termios)
288{ 290{
289 dbg("%s", __func__); 291 dbg("%s", __func__);
292 tty_termios_copy_hw(tty->termios, old_termios);
293 sierra_send_setup(tty, port);
290} 294}
291 295
292static void sierra_rx_unthrottle(struct usb_serial_port *port) 296static int sierra_tiocmget(struct tty_struct *tty, struct file *file)
293{
294 dbg("%s", __func__);
295}
296
297static void sierra_break_ctl(struct usb_serial_port *port, int break_state)
298{
299 /* Unfortunately, I don't know how to send a break */
300 dbg("%s", __func__);
301}
302
303static void sierra_set_termios(struct usb_serial_port *port,
304 struct ktermios *old_termios)
305{
306 dbg("%s", __func__);
307 tty_termios_copy_hw(port->tty->termios, old_termios);
308 sierra_send_setup(port);
309}
310
311static int sierra_tiocmget(struct usb_serial_port *port, struct file *file)
312{ 297{
298 struct usb_serial_port *port = tty->driver_data;
313 unsigned int value; 299 unsigned int value;
314 struct sierra_port_private *portdata; 300 struct sierra_port_private *portdata;
315 301
@@ -325,9 +311,10 @@ static int sierra_tiocmget(struct usb_serial_port *port, struct file *file)
325 return value; 311 return value;
326} 312}
327 313
328static int sierra_tiocmset(struct usb_serial_port *port, struct file *file, 314static int sierra_tiocmset(struct tty_struct *tty, struct file *file,
329 unsigned int set, unsigned int clear) 315 unsigned int set, unsigned int clear)
330{ 316{
317 struct usb_serial_port *port = tty->driver_data;
331 struct sierra_port_private *portdata; 318 struct sierra_port_private *portdata;
332 319
333 portdata = usb_get_serial_port_data(port); 320 portdata = usb_get_serial_port_data(port);
@@ -341,13 +328,7 @@ static int sierra_tiocmset(struct usb_serial_port *port, struct file *file,
341 portdata->rts_state = 0; 328 portdata->rts_state = 0;
342 if (clear & TIOCM_DTR) 329 if (clear & TIOCM_DTR)
343 portdata->dtr_state = 0; 330 portdata->dtr_state = 0;
344 return sierra_send_setup(port); 331 return sierra_send_setup(tty, port);
345}
346
347static int sierra_ioctl(struct usb_serial_port *port, struct file *file,
348 unsigned int cmd, unsigned long arg)
349{
350 return -ENOIOCTLCMD;
351} 332}
352 333
353static void sierra_outdat_callback(struct urb *urb) 334static void sierra_outdat_callback(struct urb *urb)
@@ -374,8 +355,8 @@ static void sierra_outdat_callback(struct urb *urb)
374} 355}
375 356
376/* Write */ 357/* Write */
377static int sierra_write(struct usb_serial_port *port, 358static int sierra_write(struct tty_struct *tty, struct usb_serial_port *port,
378 const unsigned char *buf, int count) 359 const unsigned char *buf, int count)
379{ 360{
380 struct sierra_port_private *portdata = usb_get_serial_port_data(port); 361 struct sierra_port_private *portdata = usb_get_serial_port_data(port);
381 struct usb_serial *serial = port->serial; 362 struct usb_serial *serial = port->serial;
@@ -463,7 +444,7 @@ static void sierra_indat_callback(struct urb *urb)
463 dbg("%s: nonzero status: %d on endpoint %02x.", 444 dbg("%s: nonzero status: %d on endpoint %02x.",
464 __func__, status, endpoint); 445 __func__, status, endpoint);
465 } else { 446 } else {
466 tty = port->tty; 447 tty = port->port.tty;
467 if (urb->actual_length) { 448 if (urb->actual_length) {
468 tty_buffer_request_room(tty, urb->actual_length); 449 tty_buffer_request_room(tty, urb->actual_length);
469 tty_insert_flip_string(tty, data, urb->actual_length); 450 tty_insert_flip_string(tty, data, urb->actual_length);
@@ -473,7 +454,7 @@ static void sierra_indat_callback(struct urb *urb)
473 } 454 }
474 455
475 /* Resubmit urb so we continue receiving */ 456 /* Resubmit urb so we continue receiving */
476 if (port->open_count && status != -ESHUTDOWN) { 457 if (port->port.count && status != -ESHUTDOWN) {
477 err = usb_submit_urb(urb, GFP_ATOMIC); 458 err = usb_submit_urb(urb, GFP_ATOMIC);
478 if (err) 459 if (err)
479 dev_err(&port->dev, "resubmit read urb failed." 460 dev_err(&port->dev, "resubmit read urb failed."
@@ -517,9 +498,9 @@ static void sierra_instat_callback(struct urb *urb)
517 portdata->dsr_state = ((signals & 0x02) ? 1 : 0); 498 portdata->dsr_state = ((signals & 0x02) ? 1 : 0);
518 portdata->ri_state = ((signals & 0x08) ? 1 : 0); 499 portdata->ri_state = ((signals & 0x08) ? 1 : 0);
519 500
520 if (port->tty && !C_CLOCAL(port->tty) && 501 if (port->port.tty && !C_CLOCAL(port->port.tty) &&
521 old_dcd_state && !portdata->dcd_state) 502 old_dcd_state && !portdata->dcd_state)
522 tty_hangup(port->tty); 503 tty_hangup(port->port.tty);
523 } else { 504 } else {
524 dbg("%s: type %x req %x", __func__, 505 dbg("%s: type %x req %x", __func__,
525 req_pkt->bRequestType, req_pkt->bRequest); 506 req_pkt->bRequestType, req_pkt->bRequest);
@@ -537,8 +518,9 @@ static void sierra_instat_callback(struct urb *urb)
537 } 518 }
538} 519}
539 520
540static int sierra_write_room(struct usb_serial_port *port) 521static int sierra_write_room(struct tty_struct *tty)
541{ 522{
523 struct usb_serial_port *port = tty->driver_data;
542 struct sierra_port_private *portdata = usb_get_serial_port_data(port); 524 struct sierra_port_private *portdata = usb_get_serial_port_data(port);
543 unsigned long flags; 525 unsigned long flags;
544 526
@@ -557,22 +539,8 @@ static int sierra_write_room(struct usb_serial_port *port)
557 return 2048; 539 return 2048;
558} 540}
559 541
560static int sierra_chars_in_buffer(struct usb_serial_port *port) 542static int sierra_open(struct tty_struct *tty,
561{ 543 struct usb_serial_port *port, struct file *filp)
562 dbg("%s - port %d", __func__, port->number);
563
564 /*
565 * We can't really account for how much data we
566 * have sent out, but hasn't made it through to the
567 * device as we can't see the backend here, so just
568 * tell the tty layer that everything is flushed.
569 *
570 * FIXME: should walk the outstanding urbs info
571 */
572 return 0;
573}
574
575static int sierra_open(struct usb_serial_port *port, struct file *filp)
576{ 544{
577 struct sierra_port_private *portdata; 545 struct sierra_port_private *portdata;
578 struct usb_serial *serial = port->serial; 546 struct usb_serial *serial = port->serial;
@@ -612,9 +580,10 @@ static int sierra_open(struct usb_serial_port *port, struct file *filp)
612 } 580 }
613 } 581 }
614 582
615 port->tty->low_latency = 1; 583 if (tty)
584 tty->low_latency = 1;
616 585
617 sierra_send_setup(port); 586 sierra_send_setup(tty, port);
618 587
619 /* start up the interrupt endpoint if we have one */ 588 /* start up the interrupt endpoint if we have one */
620 if (port->interrupt_in_urb) { 589 if (port->interrupt_in_urb) {
@@ -626,7 +595,8 @@ static int sierra_open(struct usb_serial_port *port, struct file *filp)
626 return 0; 595 return 0;
627} 596}
628 597
629static void sierra_close(struct usb_serial_port *port, struct file *filp) 598static void sierra_close(struct tty_struct *tty,
599 struct usb_serial_port *port, struct file *filp)
630{ 600{
631 int i; 601 int i;
632 struct usb_serial *serial = port->serial; 602 struct usb_serial *serial = port->serial;
@@ -641,7 +611,7 @@ static void sierra_close(struct usb_serial_port *port, struct file *filp)
641 if (serial->dev) { 611 if (serial->dev) {
642 mutex_lock(&serial->disc_mutex); 612 mutex_lock(&serial->disc_mutex);
643 if (!serial->disconnected) 613 if (!serial->disconnected)
644 sierra_send_setup(port); 614 sierra_send_setup(tty, port);
645 mutex_unlock(&serial->disc_mutex); 615 mutex_unlock(&serial->disc_mutex);
646 616
647 /* Stop reading/writing urbs */ 617 /* Stop reading/writing urbs */
@@ -651,7 +621,7 @@ static void sierra_close(struct usb_serial_port *port, struct file *filp)
651 621
652 usb_kill_urb(port->interrupt_in_urb); 622 usb_kill_urb(port->interrupt_in_urb);
653 623
654 port->tty = NULL; 624 port->port.tty = NULL; /* FIXME */
655} 625}
656 626
657static int sierra_startup(struct usb_serial *serial) 627static int sierra_startup(struct usb_serial *serial)
@@ -754,12 +724,7 @@ static struct usb_serial_driver sierra_device = {
754 .close = sierra_close, 724 .close = sierra_close,
755 .write = sierra_write, 725 .write = sierra_write,
756 .write_room = sierra_write_room, 726 .write_room = sierra_write_room,
757 .chars_in_buffer = sierra_chars_in_buffer,
758 .throttle = sierra_rx_throttle,
759 .unthrottle = sierra_rx_unthrottle,
760 .ioctl = sierra_ioctl,
761 .set_termios = sierra_set_termios, 727 .set_termios = sierra_set_termios,
762 .break_ctl = sierra_break_ctl,
763 .tiocmget = sierra_tiocmget, 728 .tiocmget = sierra_tiocmget,
764 .tiocmset = sierra_tiocmset, 729 .tiocmset = sierra_tiocmset,
765 .attach = sierra_startup, 730 .attach = sierra_startup,
@@ -792,7 +757,7 @@ failed_device_register:
792 757
793static void __exit sierra_exit(void) 758static void __exit sierra_exit(void)
794{ 759{
795 usb_deregister (&sierra_driver); 760 usb_deregister(&sierra_driver);
796 usb_serial_deregister(&sierra_device); 761 usb_serial_deregister(&sierra_device);
797} 762}
798 763
diff --git a/drivers/usb/serial/spcp8x5.c b/drivers/usb/serial/spcp8x5.c
index 55b2570b8b8b..283cf6b36b2c 100644
--- a/drivers/usb/serial/spcp8x5.c
+++ b/drivers/usb/serial/spcp8x5.c
@@ -208,7 +208,7 @@ static inline unsigned int ringbuf_avail_data(struct ringbuf *pb)
208{ 208{
209 if (pb == NULL) 209 if (pb == NULL)
210 return 0; 210 return 0;
211 return ((pb->buf_size + pb->buf_put - pb->buf_get) % pb->buf_size); 211 return (pb->buf_size + pb->buf_put - pb->buf_get) % pb->buf_size;
212} 212}
213 213
214/* get the number of space in the pipo */ 214/* get the number of space in the pipo */
@@ -216,7 +216,7 @@ static inline unsigned int ringbuf_avail_space(struct ringbuf *pb)
216{ 216{
217 if (pb == NULL) 217 if (pb == NULL)
218 return 0; 218 return 0;
219 return ((pb->buf_size + pb->buf_get - pb->buf_put - 1) % pb->buf_size); 219 return (pb->buf_size + pb->buf_get - pb->buf_put - 1) % pb->buf_size;
220} 220}
221 221
222/* put count data into pipo */ 222/* put count data into pipo */
@@ -448,7 +448,8 @@ static void spcp8x5_set_workMode(struct usb_device *dev, u16 value,
448 448
449/* close the serial port. We should wait for data sending to device 1st and 449/* close the serial port. We should wait for data sending to device 1st and
450 * then kill all urb. */ 450 * then kill all urb. */
451static void spcp8x5_close(struct usb_serial_port *port, struct file *filp) 451static void spcp8x5_close(struct tty_struct *tty,
452 struct usb_serial_port *port, struct file *filp)
452{ 453{
453 struct spcp8x5_private *priv = usb_get_serial_port_data(port); 454 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
454 unsigned long flags; 455 unsigned long flags;
@@ -464,7 +465,7 @@ static void spcp8x5_close(struct usb_serial_port *port, struct file *filp)
464 spin_lock_irqsave(&priv->lock, flags); 465 spin_lock_irqsave(&priv->lock, flags);
465 timeout = SPCP8x5_CLOSING_WAIT; 466 timeout = SPCP8x5_CLOSING_WAIT;
466 init_waitqueue_entry(&wait, current); 467 init_waitqueue_entry(&wait, current);
467 add_wait_queue(&port->tty->write_wait, &wait); 468 add_wait_queue(&tty->write_wait, &wait);
468 for (;;) { 469 for (;;) {
469 set_current_state(TASK_INTERRUPTIBLE); 470 set_current_state(TASK_INTERRUPTIBLE);
470 if (ringbuf_avail_data(priv->buf) == 0 || 471 if (ringbuf_avail_data(priv->buf) == 0 ||
@@ -475,7 +476,7 @@ static void spcp8x5_close(struct usb_serial_port *port, struct file *filp)
475 spin_lock_irqsave(&priv->lock, flags); 476 spin_lock_irqsave(&priv->lock, flags);
476 } 477 }
477 set_current_state(TASK_RUNNING); 478 set_current_state(TASK_RUNNING);
478 remove_wait_queue(&port->tty->write_wait, &wait); 479 remove_wait_queue(&tty->write_wait, &wait);
479 480
480 /* clear out any remaining data in the buffer */ 481 /* clear out any remaining data in the buffer */
481 clear_ringbuf(priv->buf); 482 clear_ringbuf(priv->buf);
@@ -486,7 +487,7 @@ static void spcp8x5_close(struct usb_serial_port *port, struct file *filp)
486 * flow control for data rates of 1200 bps or more, for lower rates we 487 * flow control for data rates of 1200 bps or more, for lower rates we
487 * should really know how much data is in the buffer to compute a delay 488 * should really know how much data is in the buffer to compute a delay
488 * that is not unnecessarily long) */ 489 * that is not unnecessarily long) */
489 bps = tty_get_baud_rate(port->tty); 490 bps = tty_get_baud_rate(tty);
490 if (bps > 1200) 491 if (bps > 1200)
491 timeout = max((HZ*2560) / bps, HZ/10); 492 timeout = max((HZ*2560) / bps, HZ/10);
492 else 493 else
@@ -495,8 +496,8 @@ static void spcp8x5_close(struct usb_serial_port *port, struct file *filp)
495 schedule_timeout(timeout); 496 schedule_timeout(timeout);
496 497
497 /* clear control lines */ 498 /* clear control lines */
498 if (port->tty) { 499 if (tty) {
499 c_cflag = port->tty->termios->c_cflag; 500 c_cflag = tty->termios->c_cflag;
500 if (c_cflag & HUPCL) { 501 if (c_cflag & HUPCL) {
501 spin_lock_irqsave(&priv->lock, flags); 502 spin_lock_irqsave(&priv->lock, flags);
502 priv->line_control = 0; 503 priv->line_control = 0;
@@ -518,14 +519,14 @@ static void spcp8x5_close(struct usb_serial_port *port, struct file *filp)
518} 519}
519 520
520/* set the serial param for transfer. we should check if we really need to 521/* set the serial param for transfer. we should check if we really need to
521 * transfer. then if be set flow contorl we should do this too. */ 522 * transfer. if we set flow control we should do this too. */
522static void spcp8x5_set_termios(struct usb_serial_port *port, 523static void spcp8x5_set_termios(struct tty_struct *tty,
523 struct ktermios *old_termios) 524 struct usb_serial_port *port, struct ktermios *old_termios)
524{ 525{
525 struct usb_serial *serial = port->serial; 526 struct usb_serial *serial = port->serial;
526 struct spcp8x5_private *priv = usb_get_serial_port_data(port); 527 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
527 unsigned long flags; 528 unsigned long flags;
528 unsigned int cflag = port->tty->termios->c_cflag; 529 unsigned int cflag = tty->termios->c_cflag;
529 unsigned int old_cflag = old_termios->c_cflag; 530 unsigned int old_cflag = old_termios->c_cflag;
530 unsigned short uartdata; 531 unsigned short uartdata;
531 unsigned char buf[2] = {0, 0}; 532 unsigned char buf[2] = {0, 0};
@@ -533,21 +534,19 @@ static void spcp8x5_set_termios(struct usb_serial_port *port,
533 int i; 534 int i;
534 u8 control; 535 u8 control;
535 536
536 if ((!port->tty) || (!port->tty->termios))
537 return;
538
539 /* for the 1st time call this function */ 537 /* for the 1st time call this function */
540 spin_lock_irqsave(&priv->lock, flags); 538 spin_lock_irqsave(&priv->lock, flags);
541 if (!priv->termios_initialized) { 539 if (!priv->termios_initialized) {
542 *(port->tty->termios) = tty_std_termios; 540 *(tty->termios) = tty_std_termios;
543 port->tty->termios->c_cflag = B115200 | CS8 | CREAD | 541 tty->termios->c_cflag = B115200 | CS8 | CREAD | HUPCL | CLOCAL;
544 HUPCL | CLOCAL; 542 tty->termios->c_ispeed = 115200;
543 tty->termios->c_ospeed = 115200;
545 priv->termios_initialized = 1; 544 priv->termios_initialized = 1;
546 } 545 }
547 spin_unlock_irqrestore(&priv->lock, flags); 546 spin_unlock_irqrestore(&priv->lock, flags);
548 547
549 /* check that they really want us to change something */ 548 /* check that they really want us to change something */
550 if (!tty_termios_hw_change(port->tty->termios, old_termios)) 549 if (!tty_termios_hw_change(tty->termios, old_termios))
551 return; 550 return;
552 551
553 /* set DTR/RTS active */ 552 /* set DTR/RTS active */
@@ -567,7 +566,7 @@ static void spcp8x5_set_termios(struct usb_serial_port *port,
567 } 566 }
568 567
569 /* Set Baud Rate */ 568 /* Set Baud Rate */
570 baud = tty_get_baud_rate(port->tty);; 569 baud = tty_get_baud_rate(tty);;
571 switch (baud) { 570 switch (baud) {
572 case 300: buf[0] = 0x00; break; 571 case 300: buf[0] = 0x00; break;
573 case 600: buf[0] = 0x01; break; 572 case 600: buf[0] = 0x01; break;
@@ -643,7 +642,8 @@ static void spcp8x5_set_termios(struct usb_serial_port *port,
643 642
644/* open the serial port. do some usb system call. set termios and get the line 643/* open the serial port. do some usb system call. set termios and get the line
645 * status of the device. then submit the read urb */ 644 * status of the device. then submit the read urb */
646static int spcp8x5_open(struct usb_serial_port *port, struct file *filp) 645static int spcp8x5_open(struct tty_struct *tty,
646 struct usb_serial_port *port, struct file *filp)
647{ 647{
648 struct ktermios tmp_termios; 648 struct ktermios tmp_termios;
649 struct usb_serial *serial = port->serial; 649 struct usb_serial *serial = port->serial;
@@ -665,7 +665,7 @@ static int spcp8x5_open(struct usb_serial_port *port, struct file *filp)
665 return ret; 665 return ret;
666 666
667 spin_lock_irqsave(&priv->lock, flags); 667 spin_lock_irqsave(&priv->lock, flags);
668 if (port->tty->termios->c_cflag & CBAUD) 668 if (tty && (tty->termios->c_cflag & CBAUD))
669 priv->line_control = MCR_DTR | MCR_RTS; 669 priv->line_control = MCR_DTR | MCR_RTS;
670 else 670 else
671 priv->line_control = 0; 671 priv->line_control = 0;
@@ -674,8 +674,8 @@ static int spcp8x5_open(struct usb_serial_port *port, struct file *filp)
674 spcp8x5_set_ctrlLine(serial->dev, priv->line_control , priv->type); 674 spcp8x5_set_ctrlLine(serial->dev, priv->line_control , priv->type);
675 675
676 /* Setup termios */ 676 /* Setup termios */
677 if (port->tty) 677 if (tty)
678 spcp8x5_set_termios(port, &tmp_termios); 678 spcp8x5_set_termios(tty, port, &tmp_termios);
679 679
680 spcp8x5_get_msr(serial->dev, &status, priv->type); 680 spcp8x5_get_msr(serial->dev, &status, priv->type);
681 681
@@ -690,7 +690,7 @@ static int spcp8x5_open(struct usb_serial_port *port, struct file *filp)
690 port->read_urb->dev = serial->dev; 690 port->read_urb->dev = serial->dev;
691 ret = usb_submit_urb(port->read_urb, GFP_KERNEL); 691 ret = usb_submit_urb(port->read_urb, GFP_KERNEL);
692 if (ret) { 692 if (ret) {
693 spcp8x5_close(port, NULL); 693 spcp8x5_close(tty, port, NULL);
694 return -EPROTO; 694 return -EPROTO;
695 } 695 }
696 return 0; 696 return 0;
@@ -717,7 +717,7 @@ static void spcp8x5_read_bulk_callback(struct urb *urb)
717 717
718 /* check the urb status */ 718 /* check the urb status */
719 if (urb->status) { 719 if (urb->status) {
720 if (!port->open_count) 720 if (!port->port.count)
721 return; 721 return;
722 if (urb->status == -EPROTO) { 722 if (urb->status == -EPROTO) {
723 /* spcp8x5 mysteriously fails with -EPROTO */ 723 /* spcp8x5 mysteriously fails with -EPROTO */
@@ -755,7 +755,7 @@ static void spcp8x5_read_bulk_callback(struct urb *urb)
755 tty_flag = TTY_FRAME; 755 tty_flag = TTY_FRAME;
756 dev_dbg(&port->dev, "tty_flag = %d\n", tty_flag); 756 dev_dbg(&port->dev, "tty_flag = %d\n", tty_flag);
757 757
758 tty = port->tty; 758 tty = port->port.tty;
759 if (tty && urb->actual_length) { 759 if (tty && urb->actual_length) {
760 tty_buffer_request_room(tty, urb->actual_length + 1); 760 tty_buffer_request_room(tty, urb->actual_length + 1);
761 /* overrun is special, not associated with a char */ 761 /* overrun is special, not associated with a char */
@@ -767,7 +767,7 @@ static void spcp8x5_read_bulk_callback(struct urb *urb)
767 } 767 }
768 768
769 /* Schedule the next read _if_ we are still open */ 769 /* Schedule the next read _if_ we are still open */
770 if (port->open_count) { 770 if (port->port.count) {
771 urb->dev = port->serial->dev; 771 urb->dev = port->serial->dev;
772 result = usb_submit_urb(urb , GFP_ATOMIC); 772 result = usb_submit_urb(urb , GFP_ATOMIC);
773 if (result) 773 if (result)
@@ -866,7 +866,7 @@ static void spcp8x5_write_bulk_callback(struct urb *urb)
866} 866}
867 867
868/* write data to ring buffer. and then start the write transfer */ 868/* write data to ring buffer. and then start the write transfer */
869static int spcp8x5_write(struct usb_serial_port *port, 869static int spcp8x5_write(struct tty_struct *tty, struct usb_serial_port *port,
870 const unsigned char *buf, int count) 870 const unsigned char *buf, int count)
871{ 871{
872 struct spcp8x5_private *priv = usb_get_serial_port_data(port); 872 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
@@ -925,9 +925,10 @@ static int spcp8x5_wait_modem_info(struct usb_serial_port *port,
925 return 0; 925 return 0;
926} 926}
927 927
928static int spcp8x5_ioctl(struct usb_serial_port *port, struct file *file, 928static int spcp8x5_ioctl(struct tty_struct *tty, struct file *file,
929 unsigned int cmd, unsigned long arg) 929 unsigned int cmd, unsigned long arg)
930{ 930{
931 struct usb_serial_port *port = tty->driver_data;
931 dbg("%s (%d) cmd = 0x%04x", __func__, port->number, cmd); 932 dbg("%s (%d) cmd = 0x%04x", __func__, port->number, cmd);
932 933
933 switch (cmd) { 934 switch (cmd) {
@@ -943,9 +944,10 @@ static int spcp8x5_ioctl(struct usb_serial_port *port, struct file *file,
943 return -ENOIOCTLCMD; 944 return -ENOIOCTLCMD;
944} 945}
945 946
946static int spcp8x5_tiocmset(struct usb_serial_port *port, struct file *file, 947static int spcp8x5_tiocmset(struct tty_struct *tty, struct file *file,
947 unsigned int set, unsigned int clear) 948 unsigned int set, unsigned int clear)
948{ 949{
950 struct usb_serial_port *port = tty->driver_data;
949 struct spcp8x5_private *priv = usb_get_serial_port_data(port); 951 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
950 unsigned long flags; 952 unsigned long flags;
951 u8 control; 953 u8 control;
@@ -965,8 +967,9 @@ static int spcp8x5_tiocmset(struct usb_serial_port *port, struct file *file,
965 return spcp8x5_set_ctrlLine(port->serial->dev, control , priv->type); 967 return spcp8x5_set_ctrlLine(port->serial->dev, control , priv->type);
966} 968}
967 969
968static int spcp8x5_tiocmget(struct usb_serial_port *port, struct file *file) 970static int spcp8x5_tiocmget(struct tty_struct *tty, struct file *file)
969{ 971{
972 struct usb_serial_port *port = tty->driver_data;
970 struct spcp8x5_private *priv = usb_get_serial_port_data(port); 973 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
971 unsigned long flags; 974 unsigned long flags;
972 unsigned int mcr; 975 unsigned int mcr;
@@ -989,8 +992,9 @@ static int spcp8x5_tiocmget(struct usb_serial_port *port, struct file *file)
989} 992}
990 993
991/* get the avail space room in ring buffer */ 994/* get the avail space room in ring buffer */
992static int spcp8x5_write_room(struct usb_serial_port *port) 995static int spcp8x5_write_room(struct tty_struct *tty)
993{ 996{
997 struct usb_serial_port *port = tty->driver_data;
994 struct spcp8x5_private *priv = usb_get_serial_port_data(port); 998 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
995 int room = 0; 999 int room = 0;
996 unsigned long flags; 1000 unsigned long flags;
@@ -1003,8 +1007,9 @@ static int spcp8x5_write_room(struct usb_serial_port *port)
1003} 1007}
1004 1008
1005/* get the number of avail data in write ring buffer */ 1009/* get the number of avail data in write ring buffer */
1006static int spcp8x5_chars_in_buffer(struct usb_serial_port *port) 1010static int spcp8x5_chars_in_buffer(struct tty_struct *tty)
1007{ 1011{
1012 struct usb_serial_port *port = tty->driver_data;
1008 struct spcp8x5_private *priv = usb_get_serial_port_data(port); 1013 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
1009 int chars = 0; 1014 int chars = 0;
1010 unsigned long flags; 1015 unsigned long flags;
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c
index a26a629dfc4f..e39c779e4160 100644
--- a/drivers/usb/serial/ti_usb_3410_5052.c
+++ b/drivers/usb/serial/ti_usb_3410_5052.c
@@ -16,7 +16,7 @@
16 * For questions or problems with this driver, contact Texas Instruments 16 * For questions or problems with this driver, contact Texas Instruments
17 * technical support, or Al Borchers <alborchers@steinerpoint.com>, or 17 * technical support, or Al Borchers <alborchers@steinerpoint.com>, or
18 * Peter Berger <pberger@brimson.com>. 18 * Peter Berger <pberger@brimson.com>.
19 * 19 *
20 * This driver needs this hotplug script in /etc/hotplug/usb/ti_usb_3410_5052 20 * This driver needs this hotplug script in /etc/hotplug/usb/ti_usb_3410_5052
21 * or in /etc/hotplug.d/usb/ti_usb_3410_5052.hotplug to set the device 21 * or in /etc/hotplug.d/usb/ti_usb_3410_5052.hotplug to set the device
22 * configuration. 22 * configuration.
@@ -70,6 +70,7 @@
70 70
71#include <linux/kernel.h> 71#include <linux/kernel.h>
72#include <linux/errno.h> 72#include <linux/errno.h>
73#include <linux/firmware.h>
73#include <linux/init.h> 74#include <linux/init.h>
74#include <linux/slab.h> 75#include <linux/slab.h>
75#include <linux/tty.h> 76#include <linux/tty.h>
@@ -81,7 +82,7 @@
81#include <linux/serial.h> 82#include <linux/serial.h>
82#include <linux/circ_buf.h> 83#include <linux/circ_buf.h>
83#include <linux/mutex.h> 84#include <linux/mutex.h>
84#include <asm/uaccess.h> 85#include <linux/uaccess.h>
85#include <linux/usb.h> 86#include <linux/usb.h>
86#include <linux/usb/serial.h> 87#include <linux/usb/serial.h>
87#include <linux/firmware.h> 88#include <linux/firmware.h>
@@ -149,21 +150,24 @@ struct ti_device {
149 150
150static int ti_startup(struct usb_serial *serial); 151static int ti_startup(struct usb_serial *serial);
151static void ti_shutdown(struct usb_serial *serial); 152static void ti_shutdown(struct usb_serial *serial);
152static int ti_open(struct usb_serial_port *port, struct file *file); 153static int ti_open(struct tty_struct *tty, struct usb_serial_port *port,
153static void ti_close(struct usb_serial_port *port, struct file *file); 154 struct file *file);
154static int ti_write(struct usb_serial_port *port, const unsigned char *data, 155static void ti_close(struct tty_struct *tty, struct usb_serial_port *port,
155 int count); 156 struct file *file);
156static int ti_write_room(struct usb_serial_port *port); 157static int ti_write(struct tty_struct *tty, struct usb_serial_port *port,
157static int ti_chars_in_buffer(struct usb_serial_port *port); 158 const unsigned char *data, int count);
158static void ti_throttle(struct usb_serial_port *port); 159static int ti_write_room(struct tty_struct *tty);
159static void ti_unthrottle(struct usb_serial_port *port); 160static int ti_chars_in_buffer(struct tty_struct *tty);
160static int ti_ioctl(struct usb_serial_port *port, struct file *file, unsigned int cmd, unsigned long arg); 161static void ti_throttle(struct tty_struct *tty);
161static void ti_set_termios(struct usb_serial_port *port, 162static void ti_unthrottle(struct tty_struct *tty);
162 struct ktermios *old_termios); 163static int ti_ioctl(struct tty_struct *tty, struct file *file,
163static int ti_tiocmget(struct usb_serial_port *port, struct file *file); 164 unsigned int cmd, unsigned long arg);
164static int ti_tiocmset(struct usb_serial_port *port, struct file *file, 165static void ti_set_termios(struct tty_struct *tty,
165 unsigned int set, unsigned int clear); 166 struct usb_serial_port *port, struct ktermios *old_termios);
166static void ti_break(struct usb_serial_port *port, int break_state); 167static int ti_tiocmget(struct tty_struct *tty, struct file *file);
168static int ti_tiocmset(struct tty_struct *tty, struct file *file,
169 unsigned int set, unsigned int clear);
170static void ti_break(struct tty_struct *tty, int break_state);
167static void ti_interrupt_callback(struct urb *urb); 171static void ti_interrupt_callback(struct urb *urb);
168static void ti_bulk_in_callback(struct urb *urb); 172static void ti_bulk_in_callback(struct urb *urb);
169static void ti_bulk_out_callback(struct urb *urb); 173static void ti_bulk_out_callback(struct urb *urb);
@@ -192,8 +196,7 @@ static int ti_command_in_sync(struct ti_device *tdev, __u8 command,
192static int ti_write_byte(struct ti_device *tdev, unsigned long addr, 196static int ti_write_byte(struct ti_device *tdev, unsigned long addr,
193 __u8 mask, __u8 byte); 197 __u8 mask, __u8 byte);
194 198
195static int ti_download_firmware(struct ti_device *tdev, char *fw_name); 199static int ti_download_firmware(struct ti_device *tdev, int type);
196
197 200
198/* circular buffer */ 201/* circular buffer */
199static struct circ_buf *ti_buf_alloc(void); 202static struct circ_buf *ti_buf_alloc(void);
@@ -325,19 +328,25 @@ module_param(debug, bool, S_IRUGO | S_IWUSR);
325MODULE_PARM_DESC(debug, "Enable debugging, 0=no, 1=yes"); 328MODULE_PARM_DESC(debug, "Enable debugging, 0=no, 1=yes");
326 329
327module_param(low_latency, bool, S_IRUGO | S_IWUSR); 330module_param(low_latency, bool, S_IRUGO | S_IWUSR);
328MODULE_PARM_DESC(low_latency, "TTY low_latency flag, 0=off, 1=on, default is off"); 331MODULE_PARM_DESC(low_latency,
332 "TTY low_latency flag, 0=off, 1=on, default is off");
329 333
330module_param(closing_wait, int, S_IRUGO | S_IWUSR); 334module_param(closing_wait, int, S_IRUGO | S_IWUSR);
331MODULE_PARM_DESC(closing_wait, "Maximum wait for data to drain in close, in .01 secs, default is 4000"); 335MODULE_PARM_DESC(closing_wait,
336 "Maximum wait for data to drain in close, in .01 secs, default is 4000");
332 337
333module_param_array(vendor_3410, ushort, &vendor_3410_count, S_IRUGO); 338module_param_array(vendor_3410, ushort, &vendor_3410_count, S_IRUGO);
334MODULE_PARM_DESC(vendor_3410, "Vendor ids for 3410 based devices, 1-5 short integers"); 339MODULE_PARM_DESC(vendor_3410,
340 "Vendor ids for 3410 based devices, 1-5 short integers");
335module_param_array(product_3410, ushort, &product_3410_count, S_IRUGO); 341module_param_array(product_3410, ushort, &product_3410_count, S_IRUGO);
336MODULE_PARM_DESC(product_3410, "Product ids for 3410 based devices, 1-5 short integers"); 342MODULE_PARM_DESC(product_3410,
343 "Product ids for 3410 based devices, 1-5 short integers");
337module_param_array(vendor_5052, ushort, &vendor_5052_count, S_IRUGO); 344module_param_array(vendor_5052, ushort, &vendor_5052_count, S_IRUGO);
338MODULE_PARM_DESC(vendor_5052, "Vendor ids for 5052 based devices, 1-5 short integers"); 345MODULE_PARM_DESC(vendor_5052,
346 "Vendor ids for 5052 based devices, 1-5 short integers");
339module_param_array(product_5052, ushort, &product_5052_count, S_IRUGO); 347module_param_array(product_5052, ushort, &product_5052_count, S_IRUGO);
340MODULE_PARM_DESC(product_5052, "Product ids for 5052 based devices, 1-5 short integers"); 348MODULE_PARM_DESC(product_5052,
349 "Product ids for 5052 based devices, 1-5 short integers");
341 350
342MODULE_DEVICE_TABLE(usb, ti_id_table_combined); 351MODULE_DEVICE_TABLE(usb, ti_id_table_combined);
343 352
@@ -346,18 +355,18 @@ MODULE_DEVICE_TABLE(usb, ti_id_table_combined);
346 355
347static int __init ti_init(void) 356static int __init ti_init(void)
348{ 357{
349 int i,j; 358 int i, j;
350 int ret; 359 int ret;
351 360
352 /* insert extra vendor and product ids */ 361 /* insert extra vendor and product ids */
353 j = ARRAY_SIZE(ti_id_table_3410) - TI_EXTRA_VID_PID_COUNT - 1; 362 j = ARRAY_SIZE(ti_id_table_3410) - TI_EXTRA_VID_PID_COUNT - 1;
354 for (i=0; i<min(vendor_3410_count,product_3410_count); i++,j++) { 363 for (i = 0; i < min(vendor_3410_count, product_3410_count); i++, j++) {
355 ti_id_table_3410[j].idVendor = vendor_3410[i]; 364 ti_id_table_3410[j].idVendor = vendor_3410[i];
356 ti_id_table_3410[j].idProduct = product_3410[i]; 365 ti_id_table_3410[j].idProduct = product_3410[i];
357 ti_id_table_3410[j].match_flags = USB_DEVICE_ID_MATCH_DEVICE; 366 ti_id_table_3410[j].match_flags = USB_DEVICE_ID_MATCH_DEVICE;
358 } 367 }
359 j = ARRAY_SIZE(ti_id_table_5052) - TI_EXTRA_VID_PID_COUNT - 1; 368 j = ARRAY_SIZE(ti_id_table_5052) - TI_EXTRA_VID_PID_COUNT - 1;
360 for (i=0; i<min(vendor_5052_count,product_5052_count); i++,j++) { 369 for (i = 0; i < min(vendor_5052_count, product_5052_count); i++, j++) {
361 ti_id_table_5052[j].idVendor = vendor_5052[i]; 370 ti_id_table_5052[j].idVendor = vendor_5052[i];
362 ti_id_table_5052[j].idProduct = product_5052[i]; 371 ti_id_table_5052[j].idProduct = product_5052[i];
363 ti_id_table_5052[j].match_flags = USB_DEVICE_ID_MATCH_DEVICE; 372 ti_id_table_5052[j].match_flags = USB_DEVICE_ID_MATCH_DEVICE;
@@ -426,15 +435,15 @@ static int ti_startup(struct usb_serial *serial)
426 /* determine device type */ 435 /* determine device type */
427 if (usb_match_id(serial->interface, ti_id_table_3410)) 436 if (usb_match_id(serial->interface, ti_id_table_3410))
428 tdev->td_is_3410 = 1; 437 tdev->td_is_3410 = 1;
429 dbg("%s - device type is %s", __func__, tdev->td_is_3410 ? "3410" : "5052"); 438 dbg("%s - device type is %s", __func__,
439 tdev->td_is_3410 ? "3410" : "5052");
430 440
431 /* if we have only 1 configuration, download firmware */ 441 /* if we have only 1 configuration, download firmware */
432 if (dev->descriptor.bNumConfigurations == 1) { 442 if (dev->descriptor.bNumConfigurations == 1) {
433
434 if (tdev->td_is_3410) 443 if (tdev->td_is_3410)
435 status = ti_download_firmware(tdev, "ti_3410.fw"); 444 status = ti_download_firmware(tdev, 3410);
436 else 445 else
437 status = ti_download_firmware(tdev, "ti_5052.fw"); 446 status = ti_download_firmware(tdev, 5052);
438 if (status) 447 if (status)
439 goto free_tdev; 448 goto free_tdev;
440 449
@@ -446,7 +455,7 @@ static int ti_startup(struct usb_serial *serial)
446 455
447 status = -ENODEV; 456 status = -ENODEV;
448 goto free_tdev; 457 goto free_tdev;
449 } 458 }
450 459
451 /* the second configuration must be set (in sysfs by hotplug script) */ 460 /* the second configuration must be set (in sysfs by hotplug script) */
452 if (dev->actconfig->desc.bConfigurationValue == TI_BOOT_CONFIG) { 461 if (dev->actconfig->desc.bConfigurationValue == TI_BOOT_CONFIG) {
@@ -463,7 +472,8 @@ static int ti_startup(struct usb_serial *serial)
463 goto free_tports; 472 goto free_tports;
464 } 473 }
465 spin_lock_init(&tport->tp_lock); 474 spin_lock_init(&tport->tp_lock);
466 tport->tp_uart_base_addr = (i == 0 ? TI_UART1_BASE_ADDR : TI_UART2_BASE_ADDR); 475 tport->tp_uart_base_addr = (i == 0 ?
476 TI_UART1_BASE_ADDR : TI_UART2_BASE_ADDR);
467 tport->tp_flags = low_latency ? ASYNC_LOW_LATENCY : 0; 477 tport->tp_flags = low_latency ? ASYNC_LOW_LATENCY : 0;
468 tport->tp_closing_wait = closing_wait; 478 tport->tp_closing_wait = closing_wait;
469 init_waitqueue_head(&tport->tp_msr_wait); 479 init_waitqueue_head(&tport->tp_msr_wait);
@@ -480,11 +490,11 @@ static int ti_startup(struct usb_serial *serial)
480 usb_set_serial_port_data(serial->port[i], tport); 490 usb_set_serial_port_data(serial->port[i], tport);
481 tport->tp_uart_mode = 0; /* default is RS232 */ 491 tport->tp_uart_mode = 0; /* default is RS232 */
482 } 492 }
483 493
484 return 0; 494 return 0;
485 495
486free_tports: 496free_tports:
487 for (--i; i>=0; --i) { 497 for (--i; i >= 0; --i) {
488 tport = usb_get_serial_port_data(serial->port[i]); 498 tport = usb_get_serial_port_data(serial->port[i]);
489 ti_buf_free(tport->tp_write_buf); 499 ti_buf_free(tport->tp_write_buf);
490 kfree(tport); 500 kfree(tport);
@@ -505,7 +515,7 @@ static void ti_shutdown(struct usb_serial *serial)
505 515
506 dbg("%s", __func__); 516 dbg("%s", __func__);
507 517
508 for (i=0; i < serial->num_ports; ++i) { 518 for (i = 0; i < serial->num_ports; ++i) {
509 tport = usb_get_serial_port_data(serial->port[i]); 519 tport = usb_get_serial_port_data(serial->port[i]);
510 if (tport) { 520 if (tport) {
511 ti_buf_free(tport->tp_write_buf); 521 ti_buf_free(tport->tp_write_buf);
@@ -519,7 +529,8 @@ static void ti_shutdown(struct usb_serial *serial)
519} 529}
520 530
521 531
522static int ti_open(struct usb_serial_port *port, struct file *file) 532static int ti_open(struct tty_struct *tty,
533 struct usb_serial_port *port, struct file *file)
523{ 534{
524 struct ti_port *tport = usb_get_serial_port_data(port); 535 struct ti_port *tport = usb_get_serial_port_data(port);
525 struct ti_device *tdev; 536 struct ti_device *tdev;
@@ -527,8 +538,8 @@ static int ti_open(struct usb_serial_port *port, struct file *file)
527 struct urb *urb; 538 struct urb *urb;
528 int port_number; 539 int port_number;
529 int status; 540 int status;
530 __u16 open_settings = (__u8)(TI_PIPE_MODE_CONTINOUS | 541 __u16 open_settings = (__u8)(TI_PIPE_MODE_CONTINOUS |
531 TI_PIPE_TIMEOUT_ENABLE | 542 TI_PIPE_TIMEOUT_ENABLE |
532 (TI_TRANSFER_TIMEOUT << 2)); 543 (TI_TRANSFER_TIMEOUT << 2));
533 544
534 dbg("%s - port %d", __func__, port->number); 545 dbg("%s - port %d", __func__, port->number);
@@ -543,9 +554,9 @@ static int ti_open(struct usb_serial_port *port, struct file *file)
543 if (mutex_lock_interruptible(&tdev->td_open_close_lock)) 554 if (mutex_lock_interruptible(&tdev->td_open_close_lock))
544 return -ERESTARTSYS; 555 return -ERESTARTSYS;
545 556
546 if (port->tty) 557 if (tty)
547 port->tty->low_latency = 558 tty->low_latency =
548 (tport->tp_flags & ASYNC_LOW_LATENCY) ? 1 : 0; 559 (tport->tp_flags & ASYNC_LOW_LATENCY) ? 1 : 0;
549 560
550 port_number = port->number - port->serial->minor; 561 port_number = port->number - port->serial->minor;
551 562
@@ -559,7 +570,8 @@ static int ti_open(struct usb_serial_port *port, struct file *file)
559 dbg("%s - start interrupt in urb", __func__); 570 dbg("%s - start interrupt in urb", __func__);
560 urb = tdev->td_serial->port[0]->interrupt_in_urb; 571 urb = tdev->td_serial->port[0]->interrupt_in_urb;
561 if (!urb) { 572 if (!urb) {
562 dev_err(&port->dev, "%s - no interrupt urb\n", __func__); 573 dev_err(&port->dev, "%s - no interrupt urb\n",
574 __func__);
563 status = -EINVAL; 575 status = -EINVAL;
564 goto release_lock; 576 goto release_lock;
565 } 577 }
@@ -568,18 +580,22 @@ static int ti_open(struct usb_serial_port *port, struct file *file)
568 urb->dev = dev; 580 urb->dev = dev;
569 status = usb_submit_urb(urb, GFP_KERNEL); 581 status = usb_submit_urb(urb, GFP_KERNEL);
570 if (status) { 582 if (status) {
571 dev_err(&port->dev, "%s - submit interrupt urb failed, %d\n", __func__, status); 583 dev_err(&port->dev,
584 "%s - submit interrupt urb failed, %d\n",
585 __func__, status);
572 goto release_lock; 586 goto release_lock;
573 } 587 }
574 } 588 }
575 589
576 ti_set_termios(port, port->tty->termios); 590 if (tty)
591 ti_set_termios(tty, port, tty->termios);
577 592
578 dbg("%s - sending TI_OPEN_PORT", __func__); 593 dbg("%s - sending TI_OPEN_PORT", __func__);
579 status = ti_command_out_sync(tdev, TI_OPEN_PORT, 594 status = ti_command_out_sync(tdev, TI_OPEN_PORT,
580 (__u8)(TI_UART1_PORT + port_number), open_settings, NULL, 0); 595 (__u8)(TI_UART1_PORT + port_number), open_settings, NULL, 0);
581 if (status) { 596 if (status) {
582 dev_err(&port->dev, "%s - cannot send open command, %d\n", __func__, status); 597 dev_err(&port->dev, "%s - cannot send open command, %d\n",
598 __func__, status);
583 goto unlink_int_urb; 599 goto unlink_int_urb;
584 } 600 }
585 601
@@ -587,7 +603,8 @@ static int ti_open(struct usb_serial_port *port, struct file *file)
587 status = ti_command_out_sync(tdev, TI_START_PORT, 603 status = ti_command_out_sync(tdev, TI_START_PORT,
588 (__u8)(TI_UART1_PORT + port_number), 0, NULL, 0); 604 (__u8)(TI_UART1_PORT + port_number), 0, NULL, 0);
589 if (status) { 605 if (status) {
590 dev_err(&port->dev, "%s - cannot send start command, %d\n", __func__, status); 606 dev_err(&port->dev, "%s - cannot send start command, %d\n",
607 __func__, status);
591 goto unlink_int_urb; 608 goto unlink_int_urb;
592 } 609 }
593 610
@@ -595,13 +612,15 @@ static int ti_open(struct usb_serial_port *port, struct file *file)
595 status = ti_command_out_sync(tdev, TI_PURGE_PORT, 612 status = ti_command_out_sync(tdev, TI_PURGE_PORT,
596 (__u8)(TI_UART1_PORT + port_number), TI_PURGE_INPUT, NULL, 0); 613 (__u8)(TI_UART1_PORT + port_number), TI_PURGE_INPUT, NULL, 0);
597 if (status) { 614 if (status) {
598 dev_err(&port->dev, "%s - cannot clear input buffers, %d\n", __func__, status); 615 dev_err(&port->dev, "%s - cannot clear input buffers, %d\n",
616 __func__, status);
599 goto unlink_int_urb; 617 goto unlink_int_urb;
600 } 618 }
601 status = ti_command_out_sync(tdev, TI_PURGE_PORT, 619 status = ti_command_out_sync(tdev, TI_PURGE_PORT,
602 (__u8)(TI_UART1_PORT + port_number), TI_PURGE_OUTPUT, NULL, 0); 620 (__u8)(TI_UART1_PORT + port_number), TI_PURGE_OUTPUT, NULL, 0);
603 if (status) { 621 if (status) {
604 dev_err(&port->dev, "%s - cannot clear output buffers, %d\n", __func__, status); 622 dev_err(&port->dev, "%s - cannot clear output buffers, %d\n",
623 __func__, status);
605 goto unlink_int_urb; 624 goto unlink_int_urb;
606 } 625 }
607 626
@@ -610,13 +629,15 @@ static int ti_open(struct usb_serial_port *port, struct file *file)
610 usb_clear_halt(dev, port->write_urb->pipe); 629 usb_clear_halt(dev, port->write_urb->pipe);
611 usb_clear_halt(dev, port->read_urb->pipe); 630 usb_clear_halt(dev, port->read_urb->pipe);
612 631
613 ti_set_termios(port, port->tty->termios); 632 if (tty)
633 ti_set_termios(tty, port, tty->termios);
614 634
615 dbg("%s - sending TI_OPEN_PORT (2)", __func__); 635 dbg("%s - sending TI_OPEN_PORT (2)", __func__);
616 status = ti_command_out_sync(tdev, TI_OPEN_PORT, 636 status = ti_command_out_sync(tdev, TI_OPEN_PORT,
617 (__u8)(TI_UART1_PORT + port_number), open_settings, NULL, 0); 637 (__u8)(TI_UART1_PORT + port_number), open_settings, NULL, 0);
618 if (status) { 638 if (status) {
619 dev_err(&port->dev, "%s - cannot send open command (2), %d\n", __func__, status); 639 dev_err(&port->dev, "%s - cannot send open command (2), %d\n",
640 __func__, status);
620 goto unlink_int_urb; 641 goto unlink_int_urb;
621 } 642 }
622 643
@@ -624,7 +645,8 @@ static int ti_open(struct usb_serial_port *port, struct file *file)
624 status = ti_command_out_sync(tdev, TI_START_PORT, 645 status = ti_command_out_sync(tdev, TI_START_PORT,
625 (__u8)(TI_UART1_PORT + port_number), 0, NULL, 0); 646 (__u8)(TI_UART1_PORT + port_number), 0, NULL, 0);
626 if (status) { 647 if (status) {
627 dev_err(&port->dev, "%s - cannot send start command (2), %d\n", __func__, status); 648 dev_err(&port->dev, "%s - cannot send start command (2), %d\n",
649 __func__, status);
628 goto unlink_int_urb; 650 goto unlink_int_urb;
629 } 651 }
630 652
@@ -642,7 +664,8 @@ static int ti_open(struct usb_serial_port *port, struct file *file)
642 urb->dev = dev; 664 urb->dev = dev;
643 status = usb_submit_urb(urb, GFP_KERNEL); 665 status = usb_submit_urb(urb, GFP_KERNEL);
644 if (status) { 666 if (status) {
645 dev_err(&port->dev, "%s - submit read urb failed, %d\n", __func__, status); 667 dev_err(&port->dev, "%s - submit read urb failed, %d\n",
668 __func__, status);
646 goto unlink_int_urb; 669 goto unlink_int_urb;
647 } 670 }
648 671
@@ -661,7 +684,8 @@ release_lock:
661} 684}
662 685
663 686
664static void ti_close(struct usb_serial_port *port, struct file *file) 687static void ti_close(struct tty_struct *tty, struct usb_serial_port *port,
688 struct file *file)
665{ 689{
666 struct ti_device *tdev; 690 struct ti_device *tdev;
667 struct ti_port *tport; 691 struct ti_port *tport;
@@ -670,7 +694,7 @@ static void ti_close(struct usb_serial_port *port, struct file *file)
670 int do_unlock; 694 int do_unlock;
671 695
672 dbg("%s - port %d", __func__, port->number); 696 dbg("%s - port %d", __func__, port->number);
673 697
674 tdev = usb_get_serial_data(port->serial); 698 tdev = usb_get_serial_data(port->serial);
675 tport = usb_get_serial_port_data(port); 699 tport = usb_get_serial_port_data(port);
676 if (tdev == NULL || tport == NULL) 700 if (tdev == NULL || tport == NULL)
@@ -690,7 +714,9 @@ static void ti_close(struct usb_serial_port *port, struct file *file)
690 status = ti_command_out_sync(tdev, TI_CLOSE_PORT, 714 status = ti_command_out_sync(tdev, TI_CLOSE_PORT,
691 (__u8)(TI_UART1_PORT + port_number), 0, NULL, 0); 715 (__u8)(TI_UART1_PORT + port_number), 0, NULL, 0);
692 if (status) 716 if (status)
693 dev_err(&port->dev, "%s - cannot send close port command, %d\n" , __func__, status); 717 dev_err(&port->dev,
718 "%s - cannot send close port command, %d\n"
719 , __func__, status);
694 720
695 /* if mutex_lock is interrupted, continue anyway */ 721 /* if mutex_lock is interrupted, continue anyway */
696 do_unlock = !mutex_lock_interruptible(&tdev->td_open_close_lock); 722 do_unlock = !mutex_lock_interruptible(&tdev->td_open_close_lock);
@@ -707,8 +733,8 @@ static void ti_close(struct usb_serial_port *port, struct file *file)
707} 733}
708 734
709 735
710static int ti_write(struct usb_serial_port *port, const unsigned char *data, 736static int ti_write(struct tty_struct *tty, struct usb_serial_port *port,
711 int count) 737 const unsigned char *data, int count)
712{ 738{
713 struct ti_port *tport = usb_get_serial_port_data(port); 739 struct ti_port *tport = usb_get_serial_port_data(port);
714 unsigned long flags; 740 unsigned long flags;
@@ -733,8 +759,9 @@ static int ti_write(struct usb_serial_port *port, const unsigned char *data,
733} 759}
734 760
735 761
736static int ti_write_room(struct usb_serial_port *port) 762static int ti_write_room(struct tty_struct *tty)
737{ 763{
764 struct usb_serial_port *port = tty->driver_data;
738 struct ti_port *tport = usb_get_serial_port_data(port); 765 struct ti_port *tport = usb_get_serial_port_data(port);
739 int room = 0; 766 int room = 0;
740 unsigned long flags; 767 unsigned long flags;
@@ -743,7 +770,7 @@ static int ti_write_room(struct usb_serial_port *port)
743 770
744 if (tport == NULL) 771 if (tport == NULL)
745 return -ENODEV; 772 return -ENODEV;
746 773
747 spin_lock_irqsave(&tport->tp_lock, flags); 774 spin_lock_irqsave(&tport->tp_lock, flags);
748 room = ti_buf_space_avail(tport->tp_write_buf); 775 room = ti_buf_space_avail(tport->tp_write_buf);
749 spin_unlock_irqrestore(&tport->tp_lock, flags); 776 spin_unlock_irqrestore(&tport->tp_lock, flags);
@@ -753,8 +780,9 @@ static int ti_write_room(struct usb_serial_port *port)
753} 780}
754 781
755 782
756static int ti_chars_in_buffer(struct usb_serial_port *port) 783static int ti_chars_in_buffer(struct tty_struct *tty)
757{ 784{
785 struct usb_serial_port *port = tty->driver_data;
758 struct ti_port *tport = usb_get_serial_port_data(port); 786 struct ti_port *tport = usb_get_serial_port_data(port);
759 int chars = 0; 787 int chars = 0;
760 unsigned long flags; 788 unsigned long flags;
@@ -773,32 +801,26 @@ static int ti_chars_in_buffer(struct usb_serial_port *port)
773} 801}
774 802
775 803
776static void ti_throttle(struct usb_serial_port *port) 804static void ti_throttle(struct tty_struct *tty)
777{ 805{
806 struct usb_serial_port *port = tty->driver_data;
778 struct ti_port *tport = usb_get_serial_port_data(port); 807 struct ti_port *tport = usb_get_serial_port_data(port);
779 struct tty_struct *tty;
780 808
781 dbg("%s - port %d", __func__, port->number); 809 dbg("%s - port %d", __func__, port->number);
782 810
783 if (tport == NULL) 811 if (tport == NULL)
784 return; 812 return;
785 813
786 tty = port->tty;
787 if (!tty) {
788 dbg("%s - no tty", __func__);
789 return;
790 }
791
792 if (I_IXOFF(tty) || C_CRTSCTS(tty)) 814 if (I_IXOFF(tty) || C_CRTSCTS(tty))
793 ti_stop_read(tport, tty); 815 ti_stop_read(tport, tty);
794 816
795} 817}
796 818
797 819
798static void ti_unthrottle(struct usb_serial_port *port) 820static void ti_unthrottle(struct tty_struct *tty)
799{ 821{
822 struct usb_serial_port *port = tty->driver_data;
800 struct ti_port *tport = usb_get_serial_port_data(port); 823 struct ti_port *tport = usb_get_serial_port_data(port);
801 struct tty_struct *tty;
802 int status; 824 int status;
803 825
804 dbg("%s - port %d", __func__, port->number); 826 dbg("%s - port %d", __func__, port->number);
@@ -806,23 +828,19 @@ static void ti_unthrottle(struct usb_serial_port *port)
806 if (tport == NULL) 828 if (tport == NULL)
807 return; 829 return;
808 830
809 tty = port->tty;
810 if (!tty) {
811 dbg("%s - no tty", __func__);
812 return;
813 }
814
815 if (I_IXOFF(tty) || C_CRTSCTS(tty)) { 831 if (I_IXOFF(tty) || C_CRTSCTS(tty)) {
816 status = ti_restart_read(tport, tty); 832 status = ti_restart_read(tport, tty);
817 if (status) 833 if (status)
818 dev_err(&port->dev, "%s - cannot restart read, %d\n", __func__, status); 834 dev_err(&port->dev, "%s - cannot restart read, %d\n",
835 __func__, status);
819 } 836 }
820} 837}
821 838
822 839
823static int ti_ioctl(struct usb_serial_port *port, struct file *file, 840static int ti_ioctl(struct tty_struct *tty, struct file *file,
824 unsigned int cmd, unsigned long arg) 841 unsigned int cmd, unsigned long arg)
825{ 842{
843 struct usb_serial_port *port = tty->driver_data;
826 struct ti_port *tport = usb_get_serial_port_data(port); 844 struct ti_port *tport = usb_get_serial_port_data(port);
827 struct async_icount cnow; 845 struct async_icount cnow;
828 struct async_icount cprev; 846 struct async_icount cprev;
@@ -833,55 +851,52 @@ static int ti_ioctl(struct usb_serial_port *port, struct file *file,
833 return -ENODEV; 851 return -ENODEV;
834 852
835 switch (cmd) { 853 switch (cmd) {
836 case TIOCGSERIAL: 854 case TIOCGSERIAL:
837 dbg("%s - (%d) TIOCGSERIAL", __func__, port->number); 855 dbg("%s - (%d) TIOCGSERIAL", __func__, port->number);
838 return ti_get_serial_info(tport, (struct serial_struct __user *)arg); 856 return ti_get_serial_info(tport,
839 break; 857 (struct serial_struct __user *)arg);
840 858 case TIOCSSERIAL:
841 case TIOCSSERIAL: 859 dbg("%s - (%d) TIOCSSERIAL", __func__, port->number);
842 dbg("%s - (%d) TIOCSSERIAL", __func__, port->number); 860 return ti_set_serial_info(tport,
843 return ti_set_serial_info(tport, (struct serial_struct __user *)arg); 861 (struct serial_struct __user *)arg);
844 break; 862 case TIOCMIWAIT:
845 863 dbg("%s - (%d) TIOCMIWAIT", __func__, port->number);
846 case TIOCMIWAIT: 864 cprev = tport->tp_icount;
847 dbg("%s - (%d) TIOCMIWAIT", __func__, port->number); 865 while (1) {
848 cprev = tport->tp_icount; 866 interruptible_sleep_on(&tport->tp_msr_wait);
849 while (1) { 867 if (signal_pending(current))
850 interruptible_sleep_on(&tport->tp_msr_wait); 868 return -ERESTARTSYS;
851 if (signal_pending(current)) 869 cnow = tport->tp_icount;
852 return -ERESTARTSYS; 870 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
853 cnow = tport->tp_icount; 871 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
854 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr && 872 return -EIO; /* no change => error */
855 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) 873 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
856 return -EIO; /* no change => error */ 874 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
857 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) || 875 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
858 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) || 876 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)))
859 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) || 877 return 0;
860 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) { 878 cprev = cnow;
861 return 0; 879 }
862 } 880 break;
863 cprev = cnow; 881 case TIOCGICOUNT:
864 } 882 dbg("%s - (%d) TIOCGICOUNT RX=%d, TX=%d",
865 break; 883 __func__, port->number,
866 884 tport->tp_icount.rx, tport->tp_icount.tx);
867 case TIOCGICOUNT: 885 if (copy_to_user((void __user *)arg, &tport->tp_icount,
868 dbg("%s - (%d) TIOCGICOUNT RX=%d, TX=%d", __func__, port->number, tport->tp_icount.rx, tport->tp_icount.tx); 886 sizeof(tport->tp_icount)))
869 if (copy_to_user((void __user *)arg, &tport->tp_icount, sizeof(tport->tp_icount))) 887 return -EFAULT;
870 return -EFAULT; 888 return 0;
871 return 0;
872 } 889 }
873
874 return -ENOIOCTLCMD; 890 return -ENOIOCTLCMD;
875} 891}
876 892
877 893
878static void ti_set_termios(struct usb_serial_port *port, 894static void ti_set_termios(struct tty_struct *tty,
879 struct ktermios *old_termios) 895 struct usb_serial_port *port, struct ktermios *old_termios)
880{ 896{
881 struct ti_port *tport = usb_get_serial_port_data(port); 897 struct ti_port *tport = usb_get_serial_port_data(port);
882 struct tty_struct *tty = port->tty;
883 struct ti_uart_config *config; 898 struct ti_uart_config *config;
884 tcflag_t cflag,iflag; 899 tcflag_t cflag, iflag;
885 int baud; 900 int baud;
886 int status; 901 int status;
887 int port_number = port->number - port->serial->minor; 902 int port_number = port->number - port->serial->minor;
@@ -893,7 +908,8 @@ static void ti_set_termios(struct usb_serial_port *port,
893 iflag = tty->termios->c_iflag; 908 iflag = tty->termios->c_iflag;
894 909
895 dbg("%s - cflag %08x, iflag %08x", __func__, cflag, iflag); 910 dbg("%s - cflag %08x, iflag %08x", __func__, cflag, iflag);
896 dbg("%s - old clfag %08x, old iflag %08x", __func__, old_termios->c_cflag, old_termios->c_iflag); 911 dbg("%s - old clfag %08x, old iflag %08x", __func__,
912 old_termios->c_cflag, old_termios->c_iflag);
897 913
898 if (tport == NULL) 914 if (tport == NULL)
899 return; 915 return;
@@ -912,19 +928,19 @@ static void ti_set_termios(struct usb_serial_port *port,
912 config->bUartMode = (__u8)(tport->tp_uart_mode); 928 config->bUartMode = (__u8)(tport->tp_uart_mode);
913 929
914 switch (cflag & CSIZE) { 930 switch (cflag & CSIZE) {
915 case CS5: 931 case CS5:
916 config->bDataBits = TI_UART_5_DATA_BITS; 932 config->bDataBits = TI_UART_5_DATA_BITS;
917 break; 933 break;
918 case CS6: 934 case CS6:
919 config->bDataBits = TI_UART_6_DATA_BITS; 935 config->bDataBits = TI_UART_6_DATA_BITS;
920 break; 936 break;
921 case CS7: 937 case CS7:
922 config->bDataBits = TI_UART_7_DATA_BITS; 938 config->bDataBits = TI_UART_7_DATA_BITS;
923 break; 939 break;
924 default: 940 default:
925 case CS8: 941 case CS8:
926 config->bDataBits = TI_UART_8_DATA_BITS; 942 config->bDataBits = TI_UART_8_DATA_BITS;
927 break; 943 break;
928 } 944 }
929 945
930 /* CMSPAR isn't supported by this driver */ 946 /* CMSPAR isn't supported by this driver */
@@ -940,7 +956,7 @@ static void ti_set_termios(struct usb_serial_port *port,
940 } 956 }
941 } else { 957 } else {
942 config->wFlags &= ~TI_UART_ENABLE_PARITY_CHECKING; 958 config->wFlags &= ~TI_UART_ENABLE_PARITY_CHECKING;
943 config->bParity = TI_UART_NO_PARITY; 959 config->bParity = TI_UART_NO_PARITY;
944 } 960 }
945 961
946 if (cflag & CSTOPB) 962 if (cflag & CSTOPB)
@@ -993,7 +1009,8 @@ static void ti_set_termios(struct usb_serial_port *port,
993 (__u8)(TI_UART1_PORT + port_number), 0, (__u8 *)config, 1009 (__u8)(TI_UART1_PORT + port_number), 0, (__u8 *)config,
994 sizeof(*config)); 1010 sizeof(*config));
995 if (status) 1011 if (status)
996 dev_err(&port->dev, "%s - cannot set config on port %d, %d\n", __func__, port_number, status); 1012 dev_err(&port->dev, "%s - cannot set config on port %d, %d\n",
1013 __func__, port_number, status);
997 1014
998 /* SET_CONFIG asserts RTS and DTR, reset them correctly */ 1015 /* SET_CONFIG asserts RTS and DTR, reset them correctly */
999 mcr = tport->tp_shadow_mcr; 1016 mcr = tport->tp_shadow_mcr;
@@ -1002,14 +1019,17 @@ static void ti_set_termios(struct usb_serial_port *port,
1002 mcr &= ~(TI_MCR_DTR | TI_MCR_RTS); 1019 mcr &= ~(TI_MCR_DTR | TI_MCR_RTS);
1003 status = ti_set_mcr(tport, mcr); 1020 status = ti_set_mcr(tport, mcr);
1004 if (status) 1021 if (status)
1005 dev_err(&port->dev, "%s - cannot set modem control on port %d, %d\n", __func__, port_number, status); 1022 dev_err(&port->dev,
1023 "%s - cannot set modem control on port %d, %d\n",
1024 __func__, port_number, status);
1006 1025
1007 kfree(config); 1026 kfree(config);
1008} 1027}
1009 1028
1010 1029
1011static int ti_tiocmget(struct usb_serial_port *port, struct file *file) 1030static int ti_tiocmget(struct tty_struct *tty, struct file *file)
1012{ 1031{
1032 struct usb_serial_port *port = tty->driver_data;
1013 struct ti_port *tport = usb_get_serial_port_data(port); 1033 struct ti_port *tport = usb_get_serial_port_data(port);
1014 unsigned int result; 1034 unsigned int result;
1015 unsigned int msr; 1035 unsigned int msr;
@@ -1040,9 +1060,10 @@ static int ti_tiocmget(struct usb_serial_port *port, struct file *file)
1040} 1060}
1041 1061
1042 1062
1043static int ti_tiocmset(struct usb_serial_port *port, struct file *file, 1063static int ti_tiocmset(struct tty_struct *tty, struct file *file,
1044 unsigned int set, unsigned int clear) 1064 unsigned int set, unsigned int clear)
1045{ 1065{
1066 struct usb_serial_port *port = tty->driver_data;
1046 struct ti_port *tport = usb_get_serial_port_data(port); 1067 struct ti_port *tport = usb_get_serial_port_data(port);
1047 unsigned int mcr; 1068 unsigned int mcr;
1048 unsigned long flags; 1069 unsigned long flags;
@@ -1074,8 +1095,9 @@ static int ti_tiocmset(struct usb_serial_port *port, struct file *file,
1074} 1095}
1075 1096
1076 1097
1077static void ti_break(struct usb_serial_port *port, int break_state) 1098static void ti_break(struct tty_struct *tty, int break_state)
1078{ 1099{
1100 struct usb_serial_port *port = tty->driver_data;
1079 struct ti_port *tport = usb_get_serial_port_data(port); 1101 struct ti_port *tport = usb_get_serial_port_data(port);
1080 int status; 1102 int status;
1081 1103
@@ -1141,10 +1163,12 @@ static void ti_interrupt_callback(struct urb *urb)
1141 port_number = TI_GET_PORT_FROM_CODE(data[0]); 1163 port_number = TI_GET_PORT_FROM_CODE(data[0]);
1142 function = TI_GET_FUNC_FROM_CODE(data[0]); 1164 function = TI_GET_FUNC_FROM_CODE(data[0]);
1143 1165
1144 dbg("%s - port_number %d, function %d, data 0x%02X", __func__, port_number, function, data[1]); 1166 dbg("%s - port_number %d, function %d, data 0x%02X",
1167 __func__, port_number, function, data[1]);
1145 1168
1146 if (port_number >= serial->num_ports) { 1169 if (port_number >= serial->num_ports) {
1147 dev_err(dev, "%s - bad port number, %d\n", __func__, port_number); 1170 dev_err(dev, "%s - bad port number, %d\n",
1171 __func__, port_number);
1148 goto exit; 1172 goto exit;
1149 } 1173 }
1150 1174
@@ -1156,7 +1180,8 @@ static void ti_interrupt_callback(struct urb *urb)
1156 1180
1157 switch (function) { 1181 switch (function) {
1158 case TI_CODE_DATA_ERROR: 1182 case TI_CODE_DATA_ERROR:
1159 dev_err(dev, "%s - DATA ERROR, port %d, data 0x%02X\n", __func__, port_number, data[1]); 1183 dev_err(dev, "%s - DATA ERROR, port %d, data 0x%02X\n",
1184 __func__, port_number, data[1]);
1160 break; 1185 break;
1161 1186
1162 case TI_CODE_MODEM_STATUS: 1187 case TI_CODE_MODEM_STATUS:
@@ -1166,7 +1191,8 @@ static void ti_interrupt_callback(struct urb *urb)
1166 break; 1191 break;
1167 1192
1168 default: 1193 default:
1169 dev_err(dev, "%s - unknown interrupt code, 0x%02X\n", __func__, data[1]); 1194 dev_err(dev, "%s - unknown interrupt code, 0x%02X\n",
1195 __func__, data[1]);
1170 break; 1196 break;
1171 } 1197 }
1172 1198
@@ -1200,7 +1226,7 @@ static void ti_bulk_in_callback(struct urb *urb)
1200 return; 1226 return;
1201 default: 1227 default:
1202 dev_err(dev, "%s - nonzero urb status, %d\n", 1228 dev_err(dev, "%s - nonzero urb status, %d\n",
1203 __func__, status ); 1229 __func__, status);
1204 tport->tp_tdev->td_urb_error = 1; 1230 tport->tp_tdev->td_urb_error = 1;
1205 wake_up_interruptible(&tport->tp_write_wait); 1231 wake_up_interruptible(&tport->tp_write_wait);
1206 } 1232 }
@@ -1213,15 +1239,16 @@ static void ti_bulk_in_callback(struct urb *urb)
1213 return; 1239 return;
1214 } 1240 }
1215 1241
1216 if (port->tty && urb->actual_length) { 1242 if (port->port.tty && urb->actual_length) {
1217 usb_serial_debug_data(debug, dev, __func__, 1243 usb_serial_debug_data(debug, dev, __func__,
1218 urb->actual_length, urb->transfer_buffer); 1244 urb->actual_length, urb->transfer_buffer);
1219 1245
1220 if (!tport->tp_is_open) 1246 if (!tport->tp_is_open)
1221 dbg("%s - port closed, dropping data", __func__); 1247 dbg("%s - port closed, dropping data", __func__);
1222 else 1248 else
1223 ti_recv(&urb->dev->dev, port->tty, urb->transfer_buffer, 1249 ti_recv(&urb->dev->dev, port->port.tty,
1224 urb->actual_length); 1250 urb->transfer_buffer,
1251 urb->actual_length);
1225 1252
1226 spin_lock(&tport->tp_lock); 1253 spin_lock(&tport->tp_lock);
1227 tport->tp_icount.rx += urb->actual_length; 1254 tport->tp_icount.rx += urb->actual_length;
@@ -1285,8 +1312,9 @@ static void ti_recv(struct device *dev, struct tty_struct *tty,
1285 do { 1312 do {
1286 cnt = tty_buffer_request_room(tty, length); 1313 cnt = tty_buffer_request_room(tty, length);
1287 if (cnt < length) { 1314 if (cnt < length) {
1288 dev_err(dev, "%s - dropping data, %d bytes lost\n", __func__, length - cnt); 1315 dev_err(dev, "%s - dropping data, %d bytes lost\n",
1289 if(cnt == 0) 1316 __func__, length - cnt);
1317 if (cnt == 0)
1290 break; 1318 break;
1291 } 1319 }
1292 tty_insert_flip_string(tty, data, cnt); 1320 tty_insert_flip_string(tty, data, cnt);
@@ -1302,7 +1330,7 @@ static void ti_send(struct ti_port *tport)
1302{ 1330{
1303 int count, result; 1331 int count, result;
1304 struct usb_serial_port *port = tport->tp_port; 1332 struct usb_serial_port *port = tport->tp_port;
1305 struct tty_struct *tty = port->tty; 1333 struct tty_struct *tty = port->port.tty; /* FIXME */
1306 unsigned long flags; 1334 unsigned long flags;
1307 1335
1308 1336
@@ -1328,7 +1356,8 @@ static void ti_send(struct ti_port *tport)
1328 1356
1329 spin_unlock_irqrestore(&tport->tp_lock, flags); 1357 spin_unlock_irqrestore(&tport->tp_lock, flags);
1330 1358
1331 usb_serial_debug_data(debug, &port->dev, __func__, count, port->write_urb->transfer_buffer); 1359 usb_serial_debug_data(debug, &port->dev, __func__, count,
1360 port->write_urb->transfer_buffer);
1332 1361
1333 usb_fill_bulk_urb(port->write_urb, port->serial->dev, 1362 usb_fill_bulk_urb(port->write_urb, port->serial->dev,
1334 usb_sndbulkpipe(port->serial->dev, 1363 usb_sndbulkpipe(port->serial->dev,
@@ -1338,8 +1367,9 @@ static void ti_send(struct ti_port *tport)
1338 1367
1339 result = usb_submit_urb(port->write_urb, GFP_ATOMIC); 1368 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
1340 if (result) { 1369 if (result) {
1341 dev_err(&port->dev, "%s - submit write urb failed, %d\n", __func__, result); 1370 dev_err(&port->dev, "%s - submit write urb failed, %d\n",
1342 tport->tp_write_urb_in_use = 0; 1371 __func__, result);
1372 tport->tp_write_urb_in_use = 0;
1343 /* TODO: reschedule ti_send */ 1373 /* TODO: reschedule ti_send */
1344 } else { 1374 } else {
1345 spin_lock_irqsave(&tport->tp_lock, flags); 1375 spin_lock_irqsave(&tport->tp_lock, flags);
@@ -1374,7 +1404,7 @@ static int ti_set_mcr(struct ti_port *tport, unsigned int mcr)
1374 1404
1375static int ti_get_lsr(struct ti_port *tport) 1405static int ti_get_lsr(struct ti_port *tport)
1376{ 1406{
1377 int size,status; 1407 int size, status;
1378 struct ti_device *tdev = tport->tp_tdev; 1408 struct ti_device *tdev = tport->tp_tdev;
1379 struct usb_serial_port *port = tport->tp_port; 1409 struct usb_serial_port *port = tport->tp_port;
1380 int port_number = port->number - port->serial->minor; 1410 int port_number = port->number - port->serial->minor;
@@ -1392,7 +1422,9 @@ static int ti_get_lsr(struct ti_port *tport)
1392 status = ti_command_in_sync(tdev, TI_GET_PORT_STATUS, 1422 status = ti_command_in_sync(tdev, TI_GET_PORT_STATUS,
1393 (__u8)(TI_UART1_PORT+port_number), 0, (__u8 *)data, size); 1423 (__u8)(TI_UART1_PORT+port_number), 0, (__u8 *)data, size);
1394 if (status) { 1424 if (status) {
1395 dev_err(&port->dev, "%s - get port status command failed, %d\n", __func__, status); 1425 dev_err(&port->dev,
1426 "%s - get port status command failed, %d\n",
1427 __func__, status);
1396 goto free_data; 1428 goto free_data;
1397 } 1429 }
1398 1430
@@ -1442,8 +1474,9 @@ static int ti_set_serial_info(struct ti_port *tport,
1442 return -EFAULT; 1474 return -EFAULT;
1443 1475
1444 tport->tp_flags = new_serial.flags & TI_SET_SERIAL_FLAGS; 1476 tport->tp_flags = new_serial.flags & TI_SET_SERIAL_FLAGS;
1445 if (port->tty) 1477 /* FIXME */
1446 port->tty->low_latency = 1478 if (port->port.tty)
1479 port->port.tty->low_latency =
1447 (tport->tp_flags & ASYNC_LOW_LATENCY) ? 1 : 0; 1480 (tport->tp_flags & ASYNC_LOW_LATENCY) ? 1 : 0;
1448 tport->tp_closing_wait = new_serial.closing_wait; 1481 tport->tp_closing_wait = new_serial.closing_wait;
1449 1482
@@ -1477,7 +1510,7 @@ static void ti_handle_new_msr(struct ti_port *tport, __u8 msr)
1477 tport->tp_msr = msr & TI_MSR_MASK; 1510 tport->tp_msr = msr & TI_MSR_MASK;
1478 1511
1479 /* handle CTS flow control */ 1512 /* handle CTS flow control */
1480 tty = tport->tp_port->tty; 1513 tty = tport->tp_port->port.tty;
1481 if (tty && C_CRTSCTS(tty)) { 1514 if (tty && C_CRTSCTS(tty)) {
1482 if (msr & TI_MSR_CTS) { 1515 if (msr & TI_MSR_CTS) {
1483 tty->hw_stopped = 0; 1516 tty->hw_stopped = 0;
@@ -1627,7 +1660,8 @@ static int ti_write_byte(struct ti_device *tdev, unsigned long addr,
1627 struct ti_write_data_bytes *data; 1660 struct ti_write_data_bytes *data;
1628 struct device *dev = &tdev->td_serial->dev->dev; 1661 struct device *dev = &tdev->td_serial->dev->dev;
1629 1662
1630 dbg("%s - addr 0x%08lX, mask 0x%02X, byte 0x%02X", __func__, addr, mask, byte); 1663 dbg("%s - addr 0x%08lX, mask 0x%02X, byte 0x%02X",
1664 __func__, addr, mask, byte);
1631 1665
1632 size = sizeof(struct ti_write_data_bytes) + 2; 1666 size = sizeof(struct ti_write_data_bytes) + 2;
1633 data = kmalloc(size, GFP_KERNEL); 1667 data = kmalloc(size, GFP_KERNEL);
@@ -1655,67 +1689,68 @@ static int ti_write_byte(struct ti_device *tdev, unsigned long addr,
1655 return status; 1689 return status;
1656} 1690}
1657 1691
1658 1692static int ti_do_download(struct usb_device *dev, int pipe,
1659static int ti_download_firmware(struct ti_device *tdev, 1693 u8 *buffer, int size)
1660 char *fw_name)
1661{ 1694{
1662 const struct firmware *fw;
1663 int status = 0;
1664 int buffer_size;
1665 int pos; 1695 int pos;
1666 int len; 1696 u8 cs = 0;
1667 int done; 1697 int done;
1668 __u8 cs = 0;
1669 __u8 *buffer;
1670 struct usb_device *dev = tdev->td_serial->dev;
1671 struct ti_firmware_header *header; 1698 struct ti_firmware_header *header;
1672 unsigned int pipe = usb_sndbulkpipe(dev, 1699 int status;
1673 tdev->td_serial->port[0]->bulk_out_endpointAddress); 1700 int len;
1674
1675 buffer_size = TI_FIRMWARE_BUF_SIZE + sizeof(struct ti_firmware_header);
1676
1677 if (request_firmware(&fw, fw_name, &dev->dev)) {
1678 dev_err(&dev->dev, "%s - failed to load firmware \"%s\"\n",
1679 __func__, fw_name);
1680 return -ENOENT;
1681 }
1682 if (fw->size > buffer_size) {
1683 dev_err(&dev->dev, "%s - firmware \"%s\" is too large\n",
1684 __func__, fw_name);
1685 release_firmware(fw);
1686 return -EINVAL;
1687 }
1688
1689 buffer = kmalloc(buffer_size, GFP_KERNEL);
1690 if (!buffer) {
1691 dev_err(&dev->dev, "%s - out of memory\n", __func__);
1692 release_firmware(fw);
1693 return -ENOMEM;
1694 }
1695
1696 memcpy(buffer, fw->data, fw->size);
1697 memset(buffer+fw->size, 0xff, buffer_size-fw->size);
1698 1701
1699 for(pos = sizeof(struct ti_firmware_header); pos < buffer_size; pos++) 1702 for (pos = sizeof(struct ti_firmware_header); pos < size; pos++)
1700 cs = (__u8)(cs + buffer[pos]); 1703 cs = (__u8)(cs + buffer[pos]);
1701 1704
1702 header = (struct ti_firmware_header *)buffer; 1705 header = (struct ti_firmware_header *)buffer;
1703 header->wLength = cpu_to_le16((__u16)(buffer_size - sizeof(struct ti_firmware_header))); 1706 header->wLength = cpu_to_le16((__u16)(size
1707 - sizeof(struct ti_firmware_header)));
1704 header->bCheckSum = cs; 1708 header->bCheckSum = cs;
1705 1709
1706 dbg("%s - downloading firmware", __func__); 1710 dbg("%s - downloading firmware", __func__);
1707 for (pos = 0; pos < buffer_size; pos += done) { 1711 for (pos = 0; pos < size; pos += done) {
1708 len = min(buffer_size - pos, TI_DOWNLOAD_MAX_PACKET_SIZE); 1712 len = min(size - pos, TI_DOWNLOAD_MAX_PACKET_SIZE);
1709 status = usb_bulk_msg(dev, pipe, buffer+pos, len, &done, 1000); 1713 status = usb_bulk_msg(dev, pipe, buffer + pos, len,
1714 &done, 1000);
1710 if (status) 1715 if (status)
1711 break; 1716 break;
1712 } 1717 }
1718 return status;
1719}
1713 1720
1714 kfree(buffer); 1721static int ti_download_firmware(struct ti_device *tdev, int type)
1715 release_firmware(fw); 1722{
1723 int status = -ENOMEM;
1724 int buffer_size;
1725 __u8 *buffer;
1726 struct usb_device *dev = tdev->td_serial->dev;
1727 unsigned int pipe = usb_sndbulkpipe(dev,
1728 tdev->td_serial->port[0]->bulk_out_endpointAddress);
1729 const struct firmware *fw_p;
1730 char buf[32];
1731 sprintf(buf, "ti_usb-%d.bin", type);
1716 1732
1733 if (request_firmware(&fw_p, buf, &dev->dev)) {
1734 dev_err(&dev->dev, "%s - firmware not found\n", __func__);
1735 return -ENOENT;
1736 }
1737 if (fw_p->size > TI_FIRMWARE_BUF_SIZE) {
1738 dev_err(&dev->dev, "%s - firmware too large\n", __func__);
1739 return -ENOENT;
1740 }
1741
1742 buffer_size = TI_FIRMWARE_BUF_SIZE + sizeof(struct ti_firmware_header);
1743 buffer = kmalloc(buffer_size, GFP_KERNEL);
1744 if (buffer) {
1745 memcpy(buffer, fw_p->data, fw_p->size);
1746 memset(buffer + fw_p->size, 0xff, buffer_size - fw_p->size);
1747 ti_do_download(dev, pipe, buffer, fw_p->size);
1748 kfree(buffer);
1749 }
1750 release_firmware(fw_p);
1717 if (status) { 1751 if (status) {
1718 dev_err(&dev->dev, "%s - error downloading firmware, %d\n", __func__, status); 1752 dev_err(&dev->dev, "%s - error downloading firmware, %d\n",
1753 __func__, status);
1719 return status; 1754 return status;
1720 } 1755 }
1721 1756
@@ -1787,7 +1822,7 @@ static void ti_buf_clear(struct circ_buf *cb)
1787 1822
1788static int ti_buf_data_avail(struct circ_buf *cb) 1823static int ti_buf_data_avail(struct circ_buf *cb)
1789{ 1824{
1790 return CIRC_CNT(cb->head,cb->tail,TI_WRITE_BUF_SIZE); 1825 return CIRC_CNT(cb->head, cb->tail, TI_WRITE_BUF_SIZE);
1791} 1826}
1792 1827
1793 1828
@@ -1800,7 +1835,7 @@ static int ti_buf_data_avail(struct circ_buf *cb)
1800 1835
1801static int ti_buf_space_avail(struct circ_buf *cb) 1836static int ti_buf_space_avail(struct circ_buf *cb)
1802{ 1837{
1803 return CIRC_SPACE(cb->head,cb->tail,TI_WRITE_BUF_SIZE); 1838 return CIRC_SPACE(cb->head, cb->tail, TI_WRITE_BUF_SIZE);
1804} 1839}
1805 1840
1806 1841
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index 353798631903..8c2d531eedea 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -12,7 +12,8 @@
12 * This driver was originally based on the ACM driver by Armin Fuerst (which was 12 * This driver was originally based on the ACM driver by Armin Fuerst (which was
13 * based on a driver by Brad Keryan) 13 * based on a driver by Brad Keryan)
14 * 14 *
15 * See Documentation/usb/usb-serial.txt for more information on using this driver 15 * See Documentation/usb/usb-serial.txt for more information on using this
16 * driver
16 * 17 *
17 */ 18 */
18 19
@@ -28,7 +29,7 @@
28#include <linux/spinlock.h> 29#include <linux/spinlock.h>
29#include <linux/mutex.h> 30#include <linux/mutex.h>
30#include <linux/list.h> 31#include <linux/list.h>
31#include <asm/uaccess.h> 32#include <linux/uaccess.h>
32#include <linux/usb.h> 33#include <linux/usb.h>
33#include <linux/usb/serial.h> 34#include <linux/usb/serial.h>
34#include "pl2303.h" 35#include "pl2303.h"
@@ -59,7 +60,8 @@ static struct usb_driver usb_serial_driver = {
59*/ 60*/
60 61
61static int debug; 62static int debug;
62static struct usb_serial *serial_table[SERIAL_TTY_MINORS]; /* initially all NULL */ 63/* initially all NULL */
64static struct usb_serial *serial_table[SERIAL_TTY_MINORS];
63static DEFINE_MUTEX(table_lock); 65static DEFINE_MUTEX(table_lock);
64static LIST_HEAD(usb_serial_driver_list); 66static LIST_HEAD(usb_serial_driver_list);
65 67
@@ -76,7 +78,8 @@ struct usb_serial *usb_serial_get_by_index(unsigned index)
76 return serial; 78 return serial;
77} 79}
78 80
79static struct usb_serial *get_free_serial (struct usb_serial *serial, int num_ports, unsigned int *minor) 81static struct usb_serial *get_free_serial(struct usb_serial *serial,
82 int num_ports, unsigned int *minor)
80{ 83{
81 unsigned int i, j; 84 unsigned int i, j;
82 int good_spot; 85 int good_spot;
@@ -122,9 +125,8 @@ static void return_serial(struct usb_serial *serial)
122 if (serial == NULL) 125 if (serial == NULL)
123 return; 126 return;
124 127
125 for (i = 0; i < serial->num_ports; ++i) { 128 for (i = 0; i < serial->num_ports; ++i)
126 serial_table[serial->minor + i] = NULL; 129 serial_table[serial->minor + i] = NULL;
127 }
128} 130}
129 131
130static void destroy_serial(struct kref *kref) 132static void destroy_serial(struct kref *kref)
@@ -143,7 +145,7 @@ static void destroy_serial(struct kref *kref)
143 return_serial(serial); 145 return_serial(serial);
144 146
145 for (i = 0; i < serial->num_ports; ++i) 147 for (i = 0; i < serial->num_ports; ++i)
146 serial->port[i]->open_count = 0; 148 serial->port[i]->port.count = 0;
147 149
148 /* the ports are cleaned up and released in port_release() */ 150 /* the ports are cleaned up and released in port_release() */
149 for (i = 0; i < serial->num_ports; ++i) 151 for (i = 0; i < serial->num_ports; ++i)
@@ -156,7 +158,8 @@ static void destroy_serial(struct kref *kref)
156 * not get cleaned up in port_release() as it was never registered with 158 * not get cleaned up in port_release() as it was never registered with
157 * the driver core */ 159 * the driver core */
158 if (serial->num_ports < serial->num_port_pointers) { 160 if (serial->num_ports < serial->num_port_pointers) {
159 for (i = serial->num_ports; i < serial->num_port_pointers; ++i) { 161 for (i = serial->num_ports;
162 i < serial->num_port_pointers; ++i) {
160 port = serial->port[i]; 163 port = serial->port[i];
161 if (!port) 164 if (!port)
162 continue; 165 continue;
@@ -167,7 +170,7 @@ static void destroy_serial(struct kref *kref)
167 usb_put_dev(serial->dev); 170 usb_put_dev(serial->dev);
168 171
169 /* free up any memory that we allocated */ 172 /* free up any memory that we allocated */
170 kfree (serial); 173 kfree(serial);
171} 174}
172 175
173void usb_serial_put(struct usb_serial *serial) 176void usb_serial_put(struct usb_serial *serial)
@@ -180,13 +183,13 @@ void usb_serial_put(struct usb_serial *serial)
180/***************************************************************************** 183/*****************************************************************************
181 * Driver tty interface functions 184 * Driver tty interface functions
182 *****************************************************************************/ 185 *****************************************************************************/
183static int serial_open (struct tty_struct *tty, struct file * filp) 186static int serial_open (struct tty_struct *tty, struct file *filp)
184{ 187{
185 struct usb_serial *serial; 188 struct usb_serial *serial;
186 struct usb_serial_port *port; 189 struct usb_serial_port *port;
187 unsigned int portNumber; 190 unsigned int portNumber;
188 int retval; 191 int retval;
189 192
190 dbg("%s", __func__); 193 dbg("%s", __func__);
191 194
192 /* get the serial object associated with this tty pointer */ 195 /* get the serial object associated with this tty pointer */
@@ -207,15 +210,15 @@ static int serial_open (struct tty_struct *tty, struct file * filp)
207 retval = -ERESTARTSYS; 210 retval = -ERESTARTSYS;
208 goto bailout_kref_put; 211 goto bailout_kref_put;
209 } 212 }
210 213
211 ++port->open_count; 214 ++port->port.count;
212 215
213 /* set up our port structure making the tty driver 216 /* set up our port structure making the tty driver
214 * remember our port object, and us it */ 217 * remember our port object, and us it */
215 tty->driver_data = port; 218 tty->driver_data = port;
216 port->tty = tty; 219 port->port.tty = tty;
217 220
218 if (port->open_count == 1) { 221 if (port->port.count == 1) {
219 222
220 /* lock this module before we call it 223 /* lock this module before we call it
221 * this may fail, which means we must bail out, 224 * this may fail, which means we must bail out,
@@ -228,9 +231,9 @@ static int serial_open (struct tty_struct *tty, struct file * filp)
228 retval = usb_autopm_get_interface(serial->interface); 231 retval = usb_autopm_get_interface(serial->interface);
229 if (retval) 232 if (retval)
230 goto bailout_module_put; 233 goto bailout_module_put;
231 /* only call the device specific open if this 234 /* only call the device specific open if this
232 * is the first time the port is opened */ 235 * is the first time the port is opened */
233 retval = serial->type->open(port, filp); 236 retval = serial->type->open(tty, port, filp);
234 if (retval) 237 if (retval)
235 goto bailout_interface_put; 238 goto bailout_interface_put;
236 } 239 }
@@ -243,16 +246,16 @@ bailout_interface_put:
243bailout_module_put: 246bailout_module_put:
244 module_put(serial->type->driver.owner); 247 module_put(serial->type->driver.owner);
245bailout_mutex_unlock: 248bailout_mutex_unlock:
246 port->open_count = 0; 249 port->port.count = 0;
247 tty->driver_data = NULL; 250 tty->driver_data = NULL;
248 port->tty = NULL; 251 port->port.tty = NULL;
249 mutex_unlock(&port->mutex); 252 mutex_unlock(&port->mutex);
250bailout_kref_put: 253bailout_kref_put:
251 usb_serial_put(serial); 254 usb_serial_put(serial);
252 return retval; 255 return retval;
253} 256}
254 257
255static void serial_close(struct tty_struct *tty, struct file * filp) 258static void serial_close(struct tty_struct *tty, struct file *filp)
256{ 259{
257 struct usb_serial_port *port = tty->driver_data; 260 struct usb_serial_port *port = tty->driver_data;
258 261
@@ -263,26 +266,26 @@ static void serial_close(struct tty_struct *tty, struct file * filp)
263 266
264 mutex_lock(&port->mutex); 267 mutex_lock(&port->mutex);
265 268
266 if (port->open_count == 0) { 269 if (port->port.count == 0) {
267 mutex_unlock(&port->mutex); 270 mutex_unlock(&port->mutex);
268 return; 271 return;
269 } 272 }
270 273
271 --port->open_count; 274 --port->port.count;
272 if (port->open_count == 0) 275 if (port->port.count == 0)
273 /* only call the device specific close if this 276 /* only call the device specific close if this
274 * port is being closed by the last owner */ 277 * port is being closed by the last owner */
275 port->serial->type->close(port, filp); 278 port->serial->type->close(tty, port, filp);
276 279
277 if (port->open_count == (port->console? 1 : 0)) { 280 if (port->port.count == (port->console? 1 : 0)) {
278 if (port->tty) { 281 if (port->port.tty) {
279 if (port->tty->driver_data) 282 if (port->port.tty->driver_data)
280 port->tty->driver_data = NULL; 283 port->port.tty->driver_data = NULL;
281 port->tty = NULL; 284 port->port.tty = NULL;
282 } 285 }
283 } 286 }
284 287
285 if (port->open_count == 0) { 288 if (port->port.count == 0) {
286 mutex_lock(&port->serial->disc_mutex); 289 mutex_lock(&port->serial->disc_mutex);
287 if (!port->serial->disconnected) 290 if (!port->serial->disconnected)
288 usb_autopm_put_interface(port->serial->interface); 291 usb_autopm_put_interface(port->serial->interface);
@@ -294,7 +297,8 @@ static void serial_close(struct tty_struct *tty, struct file * filp)
294 usb_serial_put(port->serial); 297 usb_serial_put(port->serial);
295} 298}
296 299
297static int serial_write (struct tty_struct * tty, const unsigned char *buf, int count) 300static int serial_write(struct tty_struct *tty, const unsigned char *buf,
301 int count)
298{ 302{
299 struct usb_serial_port *port = tty->driver_data; 303 struct usb_serial_port *port = tty->driver_data;
300 int retval = -ENODEV; 304 int retval = -ENODEV;
@@ -304,107 +308,112 @@ static int serial_write (struct tty_struct * tty, const unsigned char *buf, int
304 308
305 dbg("%s - port %d, %d byte(s)", __func__, port->number, count); 309 dbg("%s - port %d, %d byte(s)", __func__, port->number, count);
306 310
307 /* open_count is managed under the mutex lock for the tty so cannot 311 /* count is managed under the mutex lock for the tty so cannot
308 drop to zero until after the last close completes */ 312 drop to zero until after the last close completes */
309 WARN_ON(!port->open_count); 313 WARN_ON(!port->port.count);
310 314
311 /* pass on to the driver specific version of this function */ 315 /* pass on to the driver specific version of this function */
312 retval = port->serial->type->write(port, buf, count); 316 retval = port->serial->type->write(tty, port, buf, count);
313 317
314exit: 318exit:
315 return retval; 319 return retval;
316} 320}
317 321
318static int serial_write_room (struct tty_struct *tty) 322static int serial_write_room(struct tty_struct *tty)
319{ 323{
320 struct usb_serial_port *port = tty->driver_data; 324 struct usb_serial_port *port = tty->driver_data;
321 dbg("%s - port %d", __func__, port->number); 325 dbg("%s - port %d", __func__, port->number);
322 WARN_ON(!port->open_count); 326 WARN_ON(!port->port.count);
323 /* pass on to the driver specific version of this function */ 327 /* pass on to the driver specific version of this function */
324 return port->serial->type->write_room(port); 328 return port->serial->type->write_room(tty);
325} 329}
326 330
327static int serial_chars_in_buffer (struct tty_struct *tty) 331static int serial_chars_in_buffer(struct tty_struct *tty)
328{ 332{
329 struct usb_serial_port *port = tty->driver_data; 333 struct usb_serial_port *port = tty->driver_data;
330 dbg("%s = port %d", __func__, port->number); 334 dbg("%s = port %d", __func__, port->number);
331 335
332 WARN_ON(!port->open_count); 336 WARN_ON(!port->port.count);
333 /* pass on to the driver specific version of this function */ 337 /* pass on to the driver specific version of this function */
334 return port->serial->type->chars_in_buffer(port); 338 return port->serial->type->chars_in_buffer(tty);
335} 339}
336 340
337static void serial_throttle (struct tty_struct * tty) 341static void serial_throttle(struct tty_struct *tty)
338{ 342{
339 struct usb_serial_port *port = tty->driver_data; 343 struct usb_serial_port *port = tty->driver_data;
340 dbg("%s - port %d", __func__, port->number); 344 dbg("%s - port %d", __func__, port->number);
341 345
342 WARN_ON(!port->open_count); 346 WARN_ON(!port->port.count);
343 /* pass on to the driver specific version of this function */ 347 /* pass on to the driver specific version of this function */
344 if (port->serial->type->throttle) 348 if (port->serial->type->throttle)
345 port->serial->type->throttle(port); 349 port->serial->type->throttle(tty);
346} 350}
347 351
348static void serial_unthrottle (struct tty_struct * tty) 352static void serial_unthrottle(struct tty_struct *tty)
349{ 353{
350 struct usb_serial_port *port = tty->driver_data; 354 struct usb_serial_port *port = tty->driver_data;
351 dbg("%s - port %d", __func__, port->number); 355 dbg("%s - port %d", __func__, port->number);
352 356
353 WARN_ON(!port->open_count); 357 WARN_ON(!port->port.count);
354 /* pass on to the driver specific version of this function */ 358 /* pass on to the driver specific version of this function */
355 if (port->serial->type->unthrottle) 359 if (port->serial->type->unthrottle)
356 port->serial->type->unthrottle(port); 360 port->serial->type->unthrottle(tty);
357} 361}
358 362
359static int serial_ioctl (struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg) 363static int serial_ioctl(struct tty_struct *tty, struct file *file,
364 unsigned int cmd, unsigned long arg)
360{ 365{
361 struct usb_serial_port *port = tty->driver_data; 366 struct usb_serial_port *port = tty->driver_data;
362 int retval = -ENODEV; 367 int retval = -ENODEV;
363 368
364 dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd); 369 dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd);
365 370
366 WARN_ON(!port->open_count); 371 WARN_ON(!port->port.count);
367 372
368 /* pass on to the driver specific version of this function if it is available */ 373 /* pass on to the driver specific version of this function
374 if it is available */
369 if (port->serial->type->ioctl) { 375 if (port->serial->type->ioctl) {
370 lock_kernel(); 376 lock_kernel();
371 retval = port->serial->type->ioctl(port, file, cmd, arg); 377 retval = port->serial->type->ioctl(tty, file, cmd, arg);
372 unlock_kernel(); 378 unlock_kernel();
373 } 379 } else
374 else
375 retval = -ENOIOCTLCMD; 380 retval = -ENOIOCTLCMD;
376 return retval; 381 return retval;
377} 382}
378 383
379static void serial_set_termios (struct tty_struct *tty, struct ktermios * old) 384static void serial_set_termios(struct tty_struct *tty, struct ktermios *old)
380{ 385{
381 struct usb_serial_port *port = tty->driver_data; 386 struct usb_serial_port *port = tty->driver_data;
382 dbg("%s - port %d", __func__, port->number); 387 dbg("%s - port %d", __func__, port->number);
383 388
384 WARN_ON(!port->open_count); 389 WARN_ON(!port->port.count);
385 /* pass on to the driver specific version of this function if it is available */ 390 /* pass on to the driver specific version of this function
391 if it is available */
386 if (port->serial->type->set_termios) 392 if (port->serial->type->set_termios)
387 port->serial->type->set_termios(port, old); 393 port->serial->type->set_termios(tty, port, old);
388 else 394 else
389 tty_termios_copy_hw(tty->termios, old); 395 tty_termios_copy_hw(tty->termios, old);
390} 396}
391 397
392static void serial_break (struct tty_struct *tty, int break_state) 398static int serial_break(struct tty_struct *tty, int break_state)
393{ 399{
394 struct usb_serial_port *port = tty->driver_data; 400 struct usb_serial_port *port = tty->driver_data;
395 401
396 dbg("%s - port %d", __func__, port->number); 402 dbg("%s - port %d", __func__, port->number);
397 403
398 WARN_ON(!port->open_count); 404 WARN_ON(!port->port.count);
399 /* pass on to the driver specific version of this function if it is available */ 405 /* pass on to the driver specific version of this function
406 if it is available */
400 if (port->serial->type->break_ctl) { 407 if (port->serial->type->break_ctl) {
401 lock_kernel(); 408 lock_kernel();
402 port->serial->type->break_ctl(port, break_state); 409 port->serial->type->break_ctl(tty, break_state);
403 unlock_kernel(); 410 unlock_kernel();
404 } 411 }
412 return 0;
405} 413}
406 414
407static int serial_read_proc (char *page, char **start, off_t off, int count, int *eof, void *data) 415static int serial_read_proc(char *page, char **start, off_t off, int count,
416 int *eof, void *data)
408{ 417{
409 struct usb_serial *serial; 418 struct usb_serial *serial;
410 int length = 0; 419 int length = 0;
@@ -413,26 +422,29 @@ static int serial_read_proc (char *page, char **start, off_t off, int count, int
413 char tmp[40]; 422 char tmp[40];
414 423
415 dbg("%s", __func__); 424 dbg("%s", __func__);
416 length += sprintf (page, "usbserinfo:1.0 driver:2.0\n"); 425 length += sprintf(page, "usbserinfo:1.0 driver:2.0\n");
417 for (i = 0; i < SERIAL_TTY_MINORS && length < PAGE_SIZE; ++i) { 426 for (i = 0; i < SERIAL_TTY_MINORS && length < PAGE_SIZE; ++i) {
418 serial = usb_serial_get_by_index(i); 427 serial = usb_serial_get_by_index(i);
419 if (serial == NULL) 428 if (serial == NULL)
420 continue; 429 continue;
421 430
422 length += sprintf (page+length, "%d:", i); 431 length += sprintf(page+length, "%d:", i);
423 if (serial->type->driver.owner) 432 if (serial->type->driver.owner)
424 length += sprintf (page+length, " module:%s", module_name(serial->type->driver.owner)); 433 length += sprintf(page+length, " module:%s",
425 length += sprintf (page+length, " name:\"%s\"", serial->type->description); 434 module_name(serial->type->driver.owner));
426 length += sprintf (page+length, " vendor:%04x product:%04x", 435 length += sprintf(page+length, " name:\"%s\"",
427 le16_to_cpu(serial->dev->descriptor.idVendor), 436 serial->type->description);
428 le16_to_cpu(serial->dev->descriptor.idProduct)); 437 length += sprintf(page+length, " vendor:%04x product:%04x",
429 length += sprintf (page+length, " num_ports:%d", serial->num_ports); 438 le16_to_cpu(serial->dev->descriptor.idVendor),
430 length += sprintf (page+length, " port:%d", i - serial->minor + 1); 439 le16_to_cpu(serial->dev->descriptor.idProduct));
431 440 length += sprintf(page+length, " num_ports:%d",
441 serial->num_ports);
442 length += sprintf(page+length, " port:%d",
443 i - serial->minor + 1);
432 usb_make_path(serial->dev, tmp, sizeof(tmp)); 444 usb_make_path(serial->dev, tmp, sizeof(tmp));
433 length += sprintf (page+length, " path:%s", tmp); 445 length += sprintf(page+length, " path:%s", tmp);
434 446
435 length += sprintf (page+length, "\n"); 447 length += sprintf(page+length, "\n");
436 if ((length + begin) > (off + count)) { 448 if ((length + begin) > (off + count)) {
437 usb_serial_put(serial); 449 usb_serial_put(serial);
438 goto done; 450 goto done;
@@ -448,31 +460,31 @@ done:
448 if (off >= (length + begin)) 460 if (off >= (length + begin))
449 return 0; 461 return 0;
450 *start = page + (off-begin); 462 *start = page + (off-begin);
451 return ((count < begin+length-off) ? count : begin+length-off); 463 return (count < begin+length-off) ? count : begin+length-off;
452} 464}
453 465
454static int serial_tiocmget (struct tty_struct *tty, struct file *file) 466static int serial_tiocmget(struct tty_struct *tty, struct file *file)
455{ 467{
456 struct usb_serial_port *port = tty->driver_data; 468 struct usb_serial_port *port = tty->driver_data;
457 469
458 dbg("%s - port %d", __func__, port->number); 470 dbg("%s - port %d", __func__, port->number);
459 471
460 WARN_ON(!port->open_count); 472 WARN_ON(!port->port.count);
461 if (port->serial->type->tiocmget) 473 if (port->serial->type->tiocmget)
462 return port->serial->type->tiocmget(port, file); 474 return port->serial->type->tiocmget(tty, file);
463 return -EINVAL; 475 return -EINVAL;
464} 476}
465 477
466static int serial_tiocmset (struct tty_struct *tty, struct file *file, 478static int serial_tiocmset(struct tty_struct *tty, struct file *file,
467 unsigned int set, unsigned int clear) 479 unsigned int set, unsigned int clear)
468{ 480{
469 struct usb_serial_port *port = tty->driver_data; 481 struct usb_serial_port *port = tty->driver_data;
470 482
471 dbg("%s - port %d", __func__, port->number); 483 dbg("%s - port %d", __func__, port->number);
472 484
473 WARN_ON(!port->open_count); 485 WARN_ON(!port->port.count);
474 if (port->serial->type->tiocmset) 486 if (port->serial->type->tiocmset)
475 return port->serial->type->tiocmset(port, file, set, clear); 487 return port->serial->type->tiocmset(tty, file, set, clear);
476 return -EINVAL; 488 return -EINVAL;
477} 489}
478 490
@@ -485,6 +497,7 @@ void usb_serial_port_softint(struct usb_serial_port *port)
485{ 497{
486 schedule_work(&port->work); 498 schedule_work(&port->work);
487} 499}
500EXPORT_SYMBOL_GPL(usb_serial_port_softint);
488 501
489static void usb_serial_port_work(struct work_struct *work) 502static void usb_serial_port_work(struct work_struct *work)
490{ 503{
@@ -493,11 +506,11 @@ static void usb_serial_port_work(struct work_struct *work)
493 struct tty_struct *tty; 506 struct tty_struct *tty;
494 507
495 dbg("%s - port %d", __func__, port->number); 508 dbg("%s - port %d", __func__, port->number);
496 509
497 if (!port) 510 if (!port)
498 return; 511 return;
499 512
500 tty = port->tty; 513 tty = port->port.tty;
501 if (!tty) 514 if (!tty)
502 return; 515 return;
503 516
@@ -546,9 +559,9 @@ static void port_free(struct usb_serial_port *port)
546 kfree(port); 559 kfree(port);
547} 560}
548 561
549static struct usb_serial * create_serial (struct usb_device *dev, 562static struct usb_serial *create_serial(struct usb_device *dev,
550 struct usb_interface *interface, 563 struct usb_interface *interface,
551 struct usb_serial_driver *driver) 564 struct usb_serial_driver *driver)
552{ 565{
553 struct usb_serial *serial; 566 struct usb_serial *serial;
554 567
@@ -567,7 +580,7 @@ static struct usb_serial * create_serial (struct usb_device *dev,
567} 580}
568 581
569static const struct usb_device_id *match_dynamic_id(struct usb_interface *intf, 582static const struct usb_device_id *match_dynamic_id(struct usb_interface *intf,
570 struct usb_serial_driver *drv) 583 struct usb_serial_driver *drv)
571{ 584{
572 struct usb_dynid *dynid; 585 struct usb_dynid *dynid;
573 586
@@ -599,7 +612,8 @@ exit:
599 return id; 612 return id;
600} 613}
601 614
602static struct usb_serial_driver *search_serial_device(struct usb_interface *iface) 615static struct usb_serial_driver *search_serial_device(
616 struct usb_interface *iface)
603{ 617{
604 const struct usb_device_id *id; 618 const struct usb_device_id *id;
605 struct usb_serial_driver *drv; 619 struct usb_serial_driver *drv;
@@ -617,7 +631,7 @@ static struct usb_serial_driver *search_serial_device(struct usb_interface *ifac
617int usb_serial_probe(struct usb_interface *interface, 631int usb_serial_probe(struct usb_interface *interface,
618 const struct usb_device_id *id) 632 const struct usb_device_id *id)
619{ 633{
620 struct usb_device *dev = interface_to_usbdev (interface); 634 struct usb_device *dev = interface_to_usbdev(interface);
621 struct usb_serial *serial = NULL; 635 struct usb_serial *serial = NULL;
622 struct usb_serial_port *port; 636 struct usb_serial_port *port;
623 struct usb_host_interface *iface_desc; 637 struct usb_host_interface *iface_desc;
@@ -646,7 +660,7 @@ int usb_serial_probe(struct usb_interface *interface,
646 return -ENODEV; 660 return -ENODEV;
647 } 661 }
648 662
649 serial = create_serial (dev, interface, type); 663 serial = create_serial(dev, interface, type);
650 if (!serial) { 664 if (!serial) {
651 unlock_kernel(); 665 unlock_kernel();
652 dev_err(&interface->dev, "%s - out of memory\n", __func__); 666 dev_err(&interface->dev, "%s - out of memory\n", __func__);
@@ -659,8 +673,9 @@ int usb_serial_probe(struct usb_interface *interface,
659 673
660 if (!try_module_get(type->driver.owner)) { 674 if (!try_module_get(type->driver.owner)) {
661 unlock_kernel(); 675 unlock_kernel();
662 dev_err(&interface->dev, "module get failed, exiting\n"); 676 dev_err(&interface->dev,
663 kfree (serial); 677 "module get failed, exiting\n");
678 kfree(serial);
664 return -EIO; 679 return -EIO;
665 } 680 }
666 681
@@ -670,8 +685,8 @@ int usb_serial_probe(struct usb_interface *interface,
670 685
671 if (retval) { 686 if (retval) {
672 unlock_kernel(); 687 unlock_kernel();
673 dbg ("sub driver rejected device"); 688 dbg("sub driver rejected device");
674 kfree (serial); 689 kfree(serial);
675 return retval; 690 return retval;
676 } 691 }
677 } 692 }
@@ -712,7 +727,7 @@ int usb_serial_probe(struct usb_interface *interface,
712 } 727 }
713 728
714#if defined(CONFIG_USB_SERIAL_PL2303) || defined(CONFIG_USB_SERIAL_PL2303_MODULE) 729#if defined(CONFIG_USB_SERIAL_PL2303) || defined(CONFIG_USB_SERIAL_PL2303_MODULE)
715 /* BEGIN HORRIBLE HACK FOR PL2303 */ 730 /* BEGIN HORRIBLE HACK FOR PL2303 */
716 /* this is needed due to the looney way its endpoints are set up */ 731 /* this is needed due to the looney way its endpoints are set up */
717 if (((le16_to_cpu(dev->descriptor.idVendor) == PL2303_VENDOR_ID) && 732 if (((le16_to_cpu(dev->descriptor.idVendor) == PL2303_VENDOR_ID) &&
718 (le16_to_cpu(dev->descriptor.idProduct) == PL2303_PRODUCT_ID)) || 733 (le16_to_cpu(dev->descriptor.idProduct) == PL2303_PRODUCT_ID)) ||
@@ -741,7 +756,7 @@ int usb_serial_probe(struct usb_interface *interface,
741 if (num_bulk_in == 0 || num_bulk_out == 0) { 756 if (num_bulk_in == 0 || num_bulk_out == 0) {
742 unlock_kernel(); 757 unlock_kernel();
743 dev_info(&interface->dev, "PL-2303 hack: descriptors matched but endpoints did not\n"); 758 dev_info(&interface->dev, "PL-2303 hack: descriptors matched but endpoints did not\n");
744 kfree (serial); 759 kfree(serial);
745 return -ENODEV; 760 return -ENODEV;
746 } 761 }
747 } 762 }
@@ -753,8 +768,9 @@ int usb_serial_probe(struct usb_interface *interface,
753 num_ports = num_bulk_out; 768 num_ports = num_bulk_out;
754 if (num_ports == 0) { 769 if (num_ports == 0) {
755 unlock_kernel(); 770 unlock_kernel();
756 dev_err(&interface->dev, "Generic device with no bulk out, not allowed.\n"); 771 dev_err(&interface->dev,
757 kfree (serial); 772 "Generic device with no bulk out, not allowed.\n");
773 kfree(serial);
758 return -EIO; 774 return -EIO;
759 } 775 }
760 } 776 }
@@ -764,11 +780,12 @@ int usb_serial_probe(struct usb_interface *interface,
764 if (type->calc_num_ports) { 780 if (type->calc_num_ports) {
765 if (!try_module_get(type->driver.owner)) { 781 if (!try_module_get(type->driver.owner)) {
766 unlock_kernel(); 782 unlock_kernel();
767 dev_err(&interface->dev, "module get failed, exiting\n"); 783 dev_err(&interface->dev,
768 kfree (serial); 784 "module get failed, exiting\n");
785 kfree(serial);
769 return -EIO; 786 return -EIO;
770 } 787 }
771 num_ports = type->calc_num_ports (serial); 788 num_ports = type->calc_num_ports(serial);
772 module_put(type->driver.owner); 789 module_put(type->driver.owner);
773 } 790 }
774 if (!num_ports) 791 if (!num_ports)
@@ -786,7 +803,8 @@ int usb_serial_probe(struct usb_interface *interface,
786 type->description); 803 type->description);
787 804
788 /* create our ports, we need as many as the max endpoints */ 805 /* create our ports, we need as many as the max endpoints */
789 /* we don't use num_ports here cauz some devices have more endpoint pairs than ports */ 806 /* we don't use num_ports here because some devices have more
807 endpoint pairs than ports */
790 max_endpoints = max(num_bulk_in, num_bulk_out); 808 max_endpoints = max(num_bulk_in, num_bulk_out);
791 max_endpoints = max(max_endpoints, num_interrupt_in); 809 max_endpoints = max(max_endpoints, num_interrupt_in);
792 max_endpoints = max(max_endpoints, num_interrupt_out); 810 max_endpoints = max(max_endpoints, num_interrupt_out);
@@ -794,7 +812,8 @@ int usb_serial_probe(struct usb_interface *interface,
794 serial->num_port_pointers = max_endpoints; 812 serial->num_port_pointers = max_endpoints;
795 unlock_kernel(); 813 unlock_kernel();
796 814
797 dbg("%s - setting up %d port structures for this device", __func__, max_endpoints); 815 dbg("%s - setting up %d port structures for this device",
816 __func__, max_endpoints);
798 for (i = 0; i < max_endpoints; ++i) { 817 for (i = 0; i < max_endpoints; ++i) {
799 port = kzalloc(sizeof(struct usb_serial_port), GFP_KERNEL); 818 port = kzalloc(sizeof(struct usb_serial_port), GFP_KERNEL);
800 if (!port) 819 if (!port)
@@ -810,7 +829,7 @@ int usb_serial_probe(struct usb_interface *interface,
810 for (i = 0; i < num_bulk_in; ++i) { 829 for (i = 0; i < num_bulk_in; ++i) {
811 endpoint = bulk_in_endpoint[i]; 830 endpoint = bulk_in_endpoint[i];
812 port = serial->port[i]; 831 port = serial->port[i];
813 port->read_urb = usb_alloc_urb (0, GFP_KERNEL); 832 port->read_urb = usb_alloc_urb(0, GFP_KERNEL);
814 if (!port->read_urb) { 833 if (!port->read_urb) {
815 dev_err(&interface->dev, "No free urbs available\n"); 834 dev_err(&interface->dev, "No free urbs available\n");
816 goto probe_error; 835 goto probe_error;
@@ -818,17 +837,17 @@ int usb_serial_probe(struct usb_interface *interface,
818 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 837 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
819 port->bulk_in_size = buffer_size; 838 port->bulk_in_size = buffer_size;
820 port->bulk_in_endpointAddress = endpoint->bEndpointAddress; 839 port->bulk_in_endpointAddress = endpoint->bEndpointAddress;
821 port->bulk_in_buffer = kmalloc (buffer_size, GFP_KERNEL); 840 port->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL);
822 if (!port->bulk_in_buffer) { 841 if (!port->bulk_in_buffer) {
823 dev_err(&interface->dev, "Couldn't allocate bulk_in_buffer\n"); 842 dev_err(&interface->dev,
843 "Couldn't allocate bulk_in_buffer\n");
824 goto probe_error; 844 goto probe_error;
825 } 845 }
826 usb_fill_bulk_urb (port->read_urb, dev, 846 usb_fill_bulk_urb(port->read_urb, dev,
827 usb_rcvbulkpipe (dev, 847 usb_rcvbulkpipe(dev,
828 endpoint->bEndpointAddress), 848 endpoint->bEndpointAddress),
829 port->bulk_in_buffer, buffer_size, 849 port->bulk_in_buffer, buffer_size,
830 serial->type->read_bulk_callback, 850 serial->type->read_bulk_callback, port);
831 port);
832 } 851 }
833 852
834 for (i = 0; i < num_bulk_out; ++i) { 853 for (i = 0; i < num_bulk_out; ++i) {
@@ -842,17 +861,17 @@ int usb_serial_probe(struct usb_interface *interface,
842 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 861 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
843 port->bulk_out_size = buffer_size; 862 port->bulk_out_size = buffer_size;
844 port->bulk_out_endpointAddress = endpoint->bEndpointAddress; 863 port->bulk_out_endpointAddress = endpoint->bEndpointAddress;
845 port->bulk_out_buffer = kmalloc (buffer_size, GFP_KERNEL); 864 port->bulk_out_buffer = kmalloc(buffer_size, GFP_KERNEL);
846 if (!port->bulk_out_buffer) { 865 if (!port->bulk_out_buffer) {
847 dev_err(&interface->dev, "Couldn't allocate bulk_out_buffer\n"); 866 dev_err(&interface->dev,
867 "Couldn't allocate bulk_out_buffer\n");
848 goto probe_error; 868 goto probe_error;
849 } 869 }
850 usb_fill_bulk_urb (port->write_urb, dev, 870 usb_fill_bulk_urb(port->write_urb, dev,
851 usb_sndbulkpipe (dev, 871 usb_sndbulkpipe(dev,
852 endpoint->bEndpointAddress), 872 endpoint->bEndpointAddress),
853 port->bulk_out_buffer, buffer_size, 873 port->bulk_out_buffer, buffer_size,
854 serial->type->write_bulk_callback, 874 serial->type->write_bulk_callback, port);
855 port);
856 } 875 }
857 876
858 if (serial->type->read_int_callback) { 877 if (serial->type->read_int_callback) {
@@ -861,73 +880,82 @@ int usb_serial_probe(struct usb_interface *interface,
861 port = serial->port[i]; 880 port = serial->port[i];
862 port->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL); 881 port->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL);
863 if (!port->interrupt_in_urb) { 882 if (!port->interrupt_in_urb) {
864 dev_err(&interface->dev, "No free urbs available\n"); 883 dev_err(&interface->dev,
884 "No free urbs available\n");
865 goto probe_error; 885 goto probe_error;
866 } 886 }
867 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 887 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
868 port->interrupt_in_endpointAddress = endpoint->bEndpointAddress; 888 port->interrupt_in_endpointAddress =
869 port->interrupt_in_buffer = kmalloc (buffer_size, GFP_KERNEL); 889 endpoint->bEndpointAddress;
890 port->interrupt_in_buffer = kmalloc(buffer_size,
891 GFP_KERNEL);
870 if (!port->interrupt_in_buffer) { 892 if (!port->interrupt_in_buffer) {
871 dev_err(&interface->dev, "Couldn't allocate interrupt_in_buffer\n"); 893 dev_err(&interface->dev,
894 "Couldn't allocate interrupt_in_buffer\n");
872 goto probe_error; 895 goto probe_error;
873 } 896 }
874 usb_fill_int_urb (port->interrupt_in_urb, dev, 897 usb_fill_int_urb(port->interrupt_in_urb, dev,
875 usb_rcvintpipe (dev, 898 usb_rcvintpipe(dev,
876 endpoint->bEndpointAddress), 899 endpoint->bEndpointAddress),
877 port->interrupt_in_buffer, buffer_size, 900 port->interrupt_in_buffer, buffer_size,
878 serial->type->read_int_callback, port, 901 serial->type->read_int_callback, port,
879 endpoint->bInterval); 902 endpoint->bInterval);
880 } 903 }
881 } else if (num_interrupt_in) { 904 } else if (num_interrupt_in) {
882 dbg("the device claims to support interrupt in transfers, but read_int_callback is not defined"); 905 dbg("the device claims to support interrupt in transfers, but read_int_callback is not defined");
883 } 906 }
884 907
885 if (serial->type->write_int_callback) { 908 if (serial->type->write_int_callback) {
886 for (i = 0; i < num_interrupt_out; ++i) { 909 for (i = 0; i < num_interrupt_out; ++i) {
887 endpoint = interrupt_out_endpoint[i]; 910 endpoint = interrupt_out_endpoint[i];
888 port = serial->port[i]; 911 port = serial->port[i];
889 port->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL); 912 port->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL);
890 if (!port->interrupt_out_urb) { 913 if (!port->interrupt_out_urb) {
891 dev_err(&interface->dev, "No free urbs available\n"); 914 dev_err(&interface->dev,
915 "No free urbs available\n");
892 goto probe_error; 916 goto probe_error;
893 } 917 }
894 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 918 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
895 port->interrupt_out_size = buffer_size; 919 port->interrupt_out_size = buffer_size;
896 port->interrupt_out_endpointAddress = endpoint->bEndpointAddress; 920 port->interrupt_out_endpointAddress =
897 port->interrupt_out_buffer = kmalloc (buffer_size, GFP_KERNEL); 921 endpoint->bEndpointAddress;
922 port->interrupt_out_buffer = kmalloc(buffer_size,
923 GFP_KERNEL);
898 if (!port->interrupt_out_buffer) { 924 if (!port->interrupt_out_buffer) {
899 dev_err(&interface->dev, "Couldn't allocate interrupt_out_buffer\n"); 925 dev_err(&interface->dev,
926 "Couldn't allocate interrupt_out_buffer\n");
900 goto probe_error; 927 goto probe_error;
901 } 928 }
902 usb_fill_int_urb (port->interrupt_out_urb, dev, 929 usb_fill_int_urb(port->interrupt_out_urb, dev,
903 usb_sndintpipe (dev, 930 usb_sndintpipe(dev,
904 endpoint->bEndpointAddress), 931 endpoint->bEndpointAddress),
905 port->interrupt_out_buffer, buffer_size, 932 port->interrupt_out_buffer, buffer_size,
906 serial->type->write_int_callback, port, 933 serial->type->write_int_callback, port,
907 endpoint->bInterval); 934 endpoint->bInterval);
908 } 935 }
909 } else if (num_interrupt_out) { 936 } else if (num_interrupt_out) {
910 dbg("the device claims to support interrupt out transfers, but write_int_callback is not defined"); 937 dbg("the device claims to support interrupt out transfers, but write_int_callback is not defined");
911 } 938 }
912 939
913 /* if this device type has an attach function, call it */ 940 /* if this device type has an attach function, call it */
914 if (type->attach) { 941 if (type->attach) {
915 if (!try_module_get(type->driver.owner)) { 942 if (!try_module_get(type->driver.owner)) {
916 dev_err(&interface->dev, "module get failed, exiting\n"); 943 dev_err(&interface->dev,
944 "module get failed, exiting\n");
917 goto probe_error; 945 goto probe_error;
918 } 946 }
919 retval = type->attach (serial); 947 retval = type->attach(serial);
920 module_put(type->driver.owner); 948 module_put(type->driver.owner);
921 if (retval < 0) 949 if (retval < 0)
922 goto probe_error; 950 goto probe_error;
923 if (retval > 0) { 951 if (retval > 0) {
924 /* quietly accept this device, but don't bind to a serial port 952 /* quietly accept this device, but don't bind to a
925 * as it's about to disappear */ 953 serial port as it's about to disappear */
926 goto exit; 954 goto exit;
927 } 955 }
928 } 956 }
929 957
930 if (get_free_serial (serial, num_ports, &minor) == NULL) { 958 if (get_free_serial(serial, num_ports, &minor) == NULL) {
931 dev_err(&interface->dev, "No more free serial devices\n"); 959 dev_err(&interface->dev, "No more free serial devices\n");
932 goto probe_error; 960 goto probe_error;
933 } 961 }
@@ -949,11 +977,11 @@ int usb_serial_probe(struct usb_interface *interface,
949 "continuing\n"); 977 "continuing\n");
950 } 978 }
951 979
952 usb_serial_console_init (debug, minor); 980 usb_serial_console_init(debug, minor);
953 981
954exit: 982exit:
955 /* success */ 983 /* success */
956 usb_set_intfdata (interface, serial); 984 usb_set_intfdata(interface, serial);
957 return 0; 985 return 0;
958 986
959probe_error: 987probe_error:
@@ -989,29 +1017,30 @@ probe_error:
989 /* free up any memory that we allocated */ 1017 /* free up any memory that we allocated */
990 for (i = 0; i < serial->num_port_pointers; ++i) 1018 for (i = 0; i < serial->num_port_pointers; ++i)
991 kfree(serial->port[i]); 1019 kfree(serial->port[i]);
992 kfree (serial); 1020 kfree(serial);
993 return -EIO; 1021 return -EIO;
994} 1022}
1023EXPORT_SYMBOL_GPL(usb_serial_probe);
995 1024
996void usb_serial_disconnect(struct usb_interface *interface) 1025void usb_serial_disconnect(struct usb_interface *interface)
997{ 1026{
998 int i; 1027 int i;
999 struct usb_serial *serial = usb_get_intfdata (interface); 1028 struct usb_serial *serial = usb_get_intfdata(interface);
1000 struct device *dev = &interface->dev; 1029 struct device *dev = &interface->dev;
1001 struct usb_serial_port *port; 1030 struct usb_serial_port *port;
1002 1031
1003 usb_serial_console_disconnect(serial); 1032 usb_serial_console_disconnect(serial);
1004 dbg ("%s", __func__); 1033 dbg("%s", __func__);
1005 1034
1006 mutex_lock(&serial->disc_mutex); 1035 mutex_lock(&serial->disc_mutex);
1007 usb_set_intfdata (interface, NULL); 1036 usb_set_intfdata(interface, NULL);
1008 /* must set a flag, to signal subdrivers */ 1037 /* must set a flag, to signal subdrivers */
1009 serial->disconnected = 1; 1038 serial->disconnected = 1;
1010 for (i = 0; i < serial->num_ports; ++i) { 1039 for (i = 0; i < serial->num_ports; ++i) {
1011 port = serial->port[i]; 1040 port = serial->port[i];
1012 if (port) { 1041 if (port) {
1013 if (port->tty) 1042 if (port->port.tty)
1014 tty_hangup(port->tty); 1043 tty_hangup(port->port.tty);
1015 kill_traffic(port); 1044 kill_traffic(port);
1016 } 1045 }
1017 } 1046 }
@@ -1021,6 +1050,7 @@ void usb_serial_disconnect(struct usb_interface *interface)
1021 usb_serial_put(serial); 1050 usb_serial_put(serial);
1022 dev_info(dev, "device disconnected\n"); 1051 dev_info(dev, "device disconnected\n");
1023} 1052}
1053EXPORT_SYMBOL_GPL(usb_serial_disconnect);
1024 1054
1025int usb_serial_suspend(struct usb_interface *intf, pm_message_t message) 1055int usb_serial_suspend(struct usb_interface *intf, pm_message_t message)
1026{ 1056{
@@ -1079,9 +1109,8 @@ static int __init usb_serial_init(void)
1079 return -ENOMEM; 1109 return -ENOMEM;
1080 1110
1081 /* Initialize our global data */ 1111 /* Initialize our global data */
1082 for (i = 0; i < SERIAL_TTY_MINORS; ++i) { 1112 for (i = 0; i < SERIAL_TTY_MINORS; ++i)
1083 serial_table[i] = NULL; 1113 serial_table[i] = NULL;
1084 }
1085 1114
1086 result = bus_register(&usb_serial_bus_type); 1115 result = bus_register(&usb_serial_bus_type);
1087 if (result) { 1116 if (result) {
@@ -1096,9 +1125,11 @@ static int __init usb_serial_init(void)
1096 usb_serial_tty_driver->minor_start = 0; 1125 usb_serial_tty_driver->minor_start = 0;
1097 usb_serial_tty_driver->type = TTY_DRIVER_TYPE_SERIAL; 1126 usb_serial_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
1098 usb_serial_tty_driver->subtype = SERIAL_TYPE_NORMAL; 1127 usb_serial_tty_driver->subtype = SERIAL_TYPE_NORMAL;
1099 usb_serial_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; 1128 usb_serial_tty_driver->flags = TTY_DRIVER_REAL_RAW |
1129 TTY_DRIVER_DYNAMIC_DEV;
1100 usb_serial_tty_driver->init_termios = tty_std_termios; 1130 usb_serial_tty_driver->init_termios = tty_std_termios;
1101 usb_serial_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; 1131 usb_serial_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD
1132 | HUPCL | CLOCAL;
1102 usb_serial_tty_driver->init_termios.c_ispeed = 9600; 1133 usb_serial_tty_driver->init_termios.c_ispeed = 9600;
1103 usb_serial_tty_driver->init_termios.c_ospeed = 9600; 1134 usb_serial_tty_driver->init_termios.c_ospeed = 9600;
1104 tty_set_operations(usb_serial_tty_driver, &serial_ops); 1135 tty_set_operations(usb_serial_tty_driver, &serial_ops);
@@ -1136,7 +1167,7 @@ exit_reg_driver:
1136 bus_unregister(&usb_serial_bus_type); 1167 bus_unregister(&usb_serial_bus_type);
1137 1168
1138exit_bus: 1169exit_bus:
1139 err ("%s - returning with error %d", __func__, result); 1170 err("%s - returning with error %d", __func__, result);
1140 put_tty_driver(usb_serial_tty_driver); 1171 put_tty_driver(usb_serial_tty_driver);
1141 return result; 1172 return result;
1142} 1173}
@@ -1163,7 +1194,7 @@ module_exit(usb_serial_exit);
1163 if (!type->function) { \ 1194 if (!type->function) { \
1164 type->function = usb_serial_generic_##function; \ 1195 type->function = usb_serial_generic_##function; \
1165 dbg("Had to override the " #function \ 1196 dbg("Had to override the " #function \
1166 " usb serial operation with the generic one.");\ 1197 " usb serial operation with the generic one.");\
1167 } \ 1198 } \
1168 } while (0) 1199 } while (0)
1169 1200
@@ -1180,8 +1211,9 @@ static void fixup_generic(struct usb_serial_driver *device)
1180 set_to_generic_if_null(device, resume); 1211 set_to_generic_if_null(device, resume);
1181} 1212}
1182 1213
1183int usb_serial_register(struct usb_serial_driver *driver) /* must be called with BKL held */ 1214int usb_serial_register(struct usb_serial_driver *driver)
1184{ 1215{
1216 /* must be called with BKL held */
1185 int retval; 1217 int retval;
1186 1218
1187 fixup_generic(driver); 1219 fixup_generic(driver);
@@ -1194,37 +1226,30 @@ int usb_serial_register(struct usb_serial_driver *driver) /* must be called with
1194 1226
1195 retval = usb_serial_bus_register(driver); 1227 retval = usb_serial_bus_register(driver);
1196 if (retval) { 1228 if (retval) {
1197 err("problem %d when registering driver %s", retval, driver->description); 1229 err("problem %d when registering driver %s",
1230 retval, driver->description);
1198 list_del(&driver->driver_list); 1231 list_del(&driver->driver_list);
1199 } 1232 } else
1200 else 1233 info("USB Serial support registered for %s",
1201 info("USB Serial support registered for %s", driver->description); 1234 driver->description);
1202 1235
1203 return retval; 1236 return retval;
1204} 1237}
1238EXPORT_SYMBOL_GPL(usb_serial_register);
1205 1239
1206 1240
1207void usb_serial_deregister(struct usb_serial_driver *device) /* must be called with BKL held */ 1241void usb_serial_deregister(struct usb_serial_driver *device)
1208{ 1242{
1243 /* must be called with BKL held */
1209 info("USB Serial deregistering driver %s", device->description); 1244 info("USB Serial deregistering driver %s", device->description);
1210 list_del(&device->driver_list); 1245 list_del(&device->driver_list);
1211 usb_serial_bus_deregister(device); 1246 usb_serial_bus_deregister(device);
1212} 1247}
1213
1214
1215
1216/* If the usb-serial core is built into the core, the usb-serial drivers
1217 need these symbols to load properly as modules. */
1218EXPORT_SYMBOL_GPL(usb_serial_register);
1219EXPORT_SYMBOL_GPL(usb_serial_deregister); 1248EXPORT_SYMBOL_GPL(usb_serial_deregister);
1220EXPORT_SYMBOL_GPL(usb_serial_probe);
1221EXPORT_SYMBOL_GPL(usb_serial_disconnect);
1222EXPORT_SYMBOL_GPL(usb_serial_port_softint);
1223
1224 1249
1225/* Module information */ 1250/* Module information */
1226MODULE_AUTHOR( DRIVER_AUTHOR ); 1251MODULE_AUTHOR(DRIVER_AUTHOR);
1227MODULE_DESCRIPTION( DRIVER_DESC ); 1252MODULE_DESCRIPTION(DRIVER_DESC);
1228MODULE_LICENSE("GPL"); 1253MODULE_LICENSE("GPL");
1229 1254
1230module_param(debug, bool, S_IRUGO | S_IWUSR); 1255module_param(debug, bool, S_IRUGO | S_IWUSR);
diff --git a/drivers/usb/serial/usb_debug.c b/drivers/usb/serial/usb_debug.c
index 9ca4d4db1ddd..fc5d9952b03b 100644
--- a/drivers/usb/serial/usb_debug.c
+++ b/drivers/usb/serial/usb_debug.c
@@ -31,10 +31,11 @@ static struct usb_driver debug_driver = {
31 .no_dynamic_id = 1, 31 .no_dynamic_id = 1,
32}; 32};
33 33
34int usb_debug_open(struct usb_serial_port *port, struct file *filp) 34int usb_debug_open(struct tty_struct *tty, struct usb_serial_port *port,
35 struct file *filp)
35{ 36{
36 port->bulk_out_size = USB_DEBUG_MAX_PACKET_SIZE; 37 port->bulk_out_size = USB_DEBUG_MAX_PACKET_SIZE;
37 return usb_serial_generic_open(port, filp); 38 return usb_serial_generic_open(tty, port, filp);
38} 39}
39 40
40static struct usb_serial_driver debug_device = { 41static struct usb_serial_driver debug_device = {
diff --git a/drivers/usb/serial/visor.c b/drivers/usb/serial/visor.c
index 5fc20122145f..cf8924f9a2cc 100644
--- a/drivers/usb/serial/visor.c
+++ b/drivers/usb/serial/visor.c
@@ -9,7 +9,8 @@
9 * modify it under the terms of the GNU General Public License version 9 * modify it under the terms of the GNU General Public License version
10 * 2 as published by the Free Software Foundation. 10 * 2 as published by the Free Software Foundation.
11 * 11 *
12 * See Documentation/usb/usb-serial.txt for more information on using this driver 12 * See Documentation/usb/usb-serial.txt for more information on using this
13 * driver
13 * 14 *
14 */ 15 */
15 16
@@ -23,7 +24,7 @@
23#include <linux/module.h> 24#include <linux/module.h>
24#include <linux/moduleparam.h> 25#include <linux/moduleparam.h>
25#include <linux/spinlock.h> 26#include <linux/spinlock.h>
26#include <asm/uaccess.h> 27#include <linux/uaccess.h>
27#include <linux/usb.h> 28#include <linux/usb.h>
28#include <linux/usb/serial.h> 29#include <linux/usb/serial.h>
29#include "visor.h" 30#include "visor.h"
@@ -35,25 +36,29 @@
35#define DRIVER_DESC "USB HandSpring Visor / Palm OS driver" 36#define DRIVER_DESC "USB HandSpring Visor / Palm OS driver"
36 37
37/* function prototypes for a handspring visor */ 38/* function prototypes for a handspring visor */
38static int visor_open (struct usb_serial_port *port, struct file *filp); 39static int visor_open(struct tty_struct *tty, struct usb_serial_port *port,
39static void visor_close (struct usb_serial_port *port, struct file *filp); 40 struct file *filp);
40static int visor_write (struct usb_serial_port *port, const unsigned char *buf, int count); 41static void visor_close(struct tty_struct *tty, struct usb_serial_port *port,
41static int visor_write_room (struct usb_serial_port *port); 42 struct file *filp);
42static int visor_chars_in_buffer (struct usb_serial_port *port); 43static int visor_write(struct tty_struct *tty, struct usb_serial_port *port,
43static void visor_throttle (struct usb_serial_port *port); 44 const unsigned char *buf, int count);
44static void visor_unthrottle (struct usb_serial_port *port); 45static int visor_write_room(struct tty_struct *tty);
45static int visor_probe (struct usb_serial *serial, const struct usb_device_id *id); 46static void visor_throttle(struct tty_struct *tty);
47static void visor_unthrottle(struct tty_struct *tty);
48static int visor_probe(struct usb_serial *serial,
49 const struct usb_device_id *id);
46static int visor_calc_num_ports(struct usb_serial *serial); 50static int visor_calc_num_ports(struct usb_serial *serial);
47static void visor_shutdown (struct usb_serial *serial); 51static void visor_shutdown(struct usb_serial *serial);
48static int visor_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg); 52static void visor_write_bulk_callback(struct urb *urb);
49static void visor_write_bulk_callback (struct urb *urb); 53static void visor_read_bulk_callback(struct urb *urb);
50static void visor_read_bulk_callback (struct urb *urb); 54static void visor_read_int_callback(struct urb *urb);
51static void visor_read_int_callback (struct urb *urb); 55static int clie_3_5_startup(struct usb_serial *serial);
52static int clie_3_5_startup (struct usb_serial *serial); 56static int treo_attach(struct usb_serial *serial);
53static int treo_attach (struct usb_serial *serial); 57static int clie_5_attach(struct usb_serial *serial);
54static int clie_5_attach (struct usb_serial *serial); 58static int palm_os_3_probe(struct usb_serial *serial,
55static int palm_os_3_probe (struct usb_serial *serial, const struct usb_device_id *id); 59 const struct usb_device_id *id);
56static int palm_os_4_probe (struct usb_serial *serial, const struct usb_device_id *id); 60static int palm_os_4_probe(struct usb_serial *serial,
61 const struct usb_device_id *id);
57 62
58/* Parameters that may be passed into the module. */ 63/* Parameters that may be passed into the module. */
59static int debug; 64static int debug;
@@ -105,13 +110,13 @@ static struct usb_device_id id_table [] = {
105 .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 110 .driver_info = (kernel_ulong_t)&palm_os_4_probe },
106 { USB_DEVICE(ACER_VENDOR_ID, ACER_S10_ID), 111 { USB_DEVICE(ACER_VENDOR_ID, ACER_S10_ID),
107 .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 112 .driver_info = (kernel_ulong_t)&palm_os_4_probe },
108 { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_SCH_I330_ID), 113 { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_SCH_I330_ID),
109 .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 114 .driver_info = (kernel_ulong_t)&palm_os_4_probe },
110 { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_SPH_I500_ID), 115 { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_SPH_I500_ID),
111 .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 116 .driver_info = (kernel_ulong_t)&palm_os_4_probe },
112 { USB_DEVICE(TAPWAVE_VENDOR_ID, TAPWAVE_ZODIAC_ID), 117 { USB_DEVICE(TAPWAVE_VENDOR_ID, TAPWAVE_ZODIAC_ID),
113 .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 118 .driver_info = (kernel_ulong_t)&palm_os_4_probe },
114 { USB_DEVICE(GARMIN_VENDOR_ID, GARMIN_IQUE_3600_ID), 119 { USB_DEVICE(GARMIN_VENDOR_ID, GARMIN_IQUE_3600_ID),
115 .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 120 .driver_info = (kernel_ulong_t)&palm_os_4_probe },
116 { USB_DEVICE(ACEECA_VENDOR_ID, ACEECA_MEZ1000_ID), 121 { USB_DEVICE(ACEECA_VENDOR_ID, ACEECA_MEZ1000_ID),
117 .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 122 .driver_info = (kernel_ulong_t)&palm_os_4_probe },
@@ -170,7 +175,7 @@ static struct usb_device_id id_table_combined [] = {
170 { } /* Terminating entry */ 175 { } /* Terminating entry */
171}; 176};
172 177
173MODULE_DEVICE_TABLE (usb, id_table_combined); 178MODULE_DEVICE_TABLE(usb, id_table_combined);
174 179
175static struct usb_driver visor_driver = { 180static struct usb_driver visor_driver = {
176 .name = "visor", 181 .name = "visor",
@@ -180,7 +185,8 @@ static struct usb_driver visor_driver = {
180 .no_dynamic_id = 1, 185 .no_dynamic_id = 1,
181}; 186};
182 187
183/* All of the device info needed for the Handspring Visor, and Palm 4.0 devices */ 188/* All of the device info needed for the Handspring Visor,
189 and Palm 4.0 devices */
184static struct usb_serial_driver handspring_device = { 190static struct usb_serial_driver handspring_device = {
185 .driver = { 191 .driver = {
186 .owner = THIS_MODULE, 192 .owner = THIS_MODULE,
@@ -198,10 +204,8 @@ static struct usb_serial_driver handspring_device = {
198 .probe = visor_probe, 204 .probe = visor_probe,
199 .calc_num_ports = visor_calc_num_ports, 205 .calc_num_ports = visor_calc_num_ports,
200 .shutdown = visor_shutdown, 206 .shutdown = visor_shutdown,
201 .ioctl = visor_ioctl,
202 .write = visor_write, 207 .write = visor_write,
203 .write_room = visor_write_room, 208 .write_room = visor_write_room,
204 .chars_in_buffer = visor_chars_in_buffer,
205 .write_bulk_callback = visor_write_bulk_callback, 209 .write_bulk_callback = visor_write_bulk_callback,
206 .read_bulk_callback = visor_read_bulk_callback, 210 .read_bulk_callback = visor_read_bulk_callback,
207 .read_int_callback = visor_read_int_callback, 211 .read_int_callback = visor_read_int_callback,
@@ -225,10 +229,8 @@ static struct usb_serial_driver clie_5_device = {
225 .probe = visor_probe, 229 .probe = visor_probe,
226 .calc_num_ports = visor_calc_num_ports, 230 .calc_num_ports = visor_calc_num_ports,
227 .shutdown = visor_shutdown, 231 .shutdown = visor_shutdown,
228 .ioctl = visor_ioctl,
229 .write = visor_write, 232 .write = visor_write,
230 .write_room = visor_write_room, 233 .write_room = visor_write_room,
231 .chars_in_buffer = visor_chars_in_buffer,
232 .write_bulk_callback = visor_write_bulk_callback, 234 .write_bulk_callback = visor_write_bulk_callback,
233 .read_bulk_callback = visor_read_bulk_callback, 235 .read_bulk_callback = visor_read_bulk_callback,
234 .read_int_callback = visor_read_int_callback, 236 .read_int_callback = visor_read_int_callback,
@@ -249,10 +251,8 @@ static struct usb_serial_driver clie_3_5_device = {
249 .throttle = visor_throttle, 251 .throttle = visor_throttle,
250 .unthrottle = visor_unthrottle, 252 .unthrottle = visor_unthrottle,
251 .attach = clie_3_5_startup, 253 .attach = clie_3_5_startup,
252 .ioctl = visor_ioctl,
253 .write = visor_write, 254 .write = visor_write,
254 .write_room = visor_write_room, 255 .write_room = visor_write_room,
255 .chars_in_buffer = visor_chars_in_buffer,
256 .write_bulk_callback = visor_write_bulk_callback, 256 .write_bulk_callback = visor_write_bulk_callback,
257 .read_bulk_callback = visor_read_bulk_callback, 257 .read_bulk_callback = visor_read_bulk_callback,
258}; 258};
@@ -274,7 +274,8 @@ static int stats;
274/****************************************************************************** 274/******************************************************************************
275 * Handspring Visor specific driver functions 275 * Handspring Visor specific driver functions
276 ******************************************************************************/ 276 ******************************************************************************/
277static int visor_open (struct usb_serial_port *port, struct file *filp) 277static int visor_open(struct tty_struct *tty, struct usb_serial_port *port,
278 struct file *filp)
278{ 279{
279 struct usb_serial *serial = port->serial; 280 struct usb_serial *serial = port->serial;
280 struct visor_private *priv = usb_get_serial_port_data(port); 281 struct visor_private *priv = usb_get_serial_port_data(port);
@@ -300,42 +301,45 @@ static int visor_open (struct usb_serial_port *port, struct file *filp)
300 * through, otherwise it is scheduled, and with high data rates (like 301 * through, otherwise it is scheduled, and with high data rates (like
301 * with OHCI) data can get lost. 302 * with OHCI) data can get lost.
302 */ 303 */
303 if (port->tty) 304 if (tty)
304 port->tty->low_latency = 1; 305 tty->low_latency = 1;
305 306
306 /* Start reading from the device */ 307 /* Start reading from the device */
307 usb_fill_bulk_urb (port->read_urb, serial->dev, 308 usb_fill_bulk_urb(port->read_urb, serial->dev,
308 usb_rcvbulkpipe (serial->dev, 309 usb_rcvbulkpipe(serial->dev,
309 port->bulk_in_endpointAddress), 310 port->bulk_in_endpointAddress),
310 port->read_urb->transfer_buffer, 311 port->read_urb->transfer_buffer,
311 port->read_urb->transfer_buffer_length, 312 port->read_urb->transfer_buffer_length,
312 visor_read_bulk_callback, port); 313 visor_read_bulk_callback, port);
313 result = usb_submit_urb(port->read_urb, GFP_KERNEL); 314 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
314 if (result) { 315 if (result) {
315 dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", 316 dev_err(&port->dev,
316 __func__, result); 317 "%s - failed submitting read urb, error %d\n",
318 __func__, result);
317 goto exit; 319 goto exit;
318 } 320 }
319 321
320 if (port->interrupt_in_urb) { 322 if (port->interrupt_in_urb) {
321 dbg("%s - adding interrupt input for treo", __func__); 323 dbg("%s - adding interrupt input for treo", __func__);
322 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 324 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
323 if (result) 325 if (result)
324 dev_err(&port->dev, "%s - failed submitting interrupt urb, error %d\n", 326 dev_err(&port->dev,
325 __func__, result); 327 "%s - failed submitting interrupt urb, error %d\n",
328 __func__, result);
326 } 329 }
327exit: 330exit:
328 return result; 331 return result;
329} 332}
330 333
331 334
332static void visor_close (struct usb_serial_port *port, struct file * filp) 335static void visor_close(struct tty_struct *tty,
336 struct usb_serial_port *port, struct file *filp)
333{ 337{
334 struct visor_private *priv = usb_get_serial_port_data(port); 338 struct visor_private *priv = usb_get_serial_port_data(port);
335 unsigned char *transfer_buffer; 339 unsigned char *transfer_buffer;
336 340
337 dbg("%s - port %d", __func__, port->number); 341 dbg("%s - port %d", __func__, port->number);
338 342
339 /* shutdown our urbs */ 343 /* shutdown our urbs */
340 usb_kill_urb(port->read_urb); 344 usb_kill_urb(port->read_urb);
341 usb_kill_urb(port->interrupt_in_urb); 345 usb_kill_urb(port->interrupt_in_urb);
@@ -343,14 +347,14 @@ static void visor_close (struct usb_serial_port *port, struct file * filp)
343 mutex_lock(&port->serial->disc_mutex); 347 mutex_lock(&port->serial->disc_mutex);
344 if (!port->serial->disconnected) { 348 if (!port->serial->disconnected) {
345 /* Try to send shutdown message, unless the device is gone */ 349 /* Try to send shutdown message, unless the device is gone */
346 transfer_buffer = kmalloc (0x12, GFP_KERNEL); 350 transfer_buffer = kmalloc(0x12, GFP_KERNEL);
347 if (transfer_buffer) { 351 if (transfer_buffer) {
348 usb_control_msg (port->serial->dev, 352 usb_control_msg(port->serial->dev,
349 usb_rcvctrlpipe(port->serial->dev, 0), 353 usb_rcvctrlpipe(port->serial->dev, 0),
350 VISOR_CLOSE_NOTIFICATION, 0xc2, 354 VISOR_CLOSE_NOTIFICATION, 0xc2,
351 0x0000, 0x0000, 355 0x0000, 0x0000,
352 transfer_buffer, 0x12, 300); 356 transfer_buffer, 0x12, 300);
353 kfree (transfer_buffer); 357 kfree(transfer_buffer);
354 } 358 }
355 } 359 }
356 mutex_unlock(&port->serial->disc_mutex); 360 mutex_unlock(&port->serial->disc_mutex);
@@ -361,7 +365,8 @@ static void visor_close (struct usb_serial_port *port, struct file * filp)
361} 365}
362 366
363 367
364static int visor_write (struct usb_serial_port *port, const unsigned char *buf, int count) 368static int visor_write(struct tty_struct *tty, struct usb_serial_port *port,
369 const unsigned char *buf, int count)
365{ 370{
366 struct visor_private *priv = usb_get_serial_port_data(port); 371 struct visor_private *priv = usb_get_serial_port_data(port);
367 struct usb_serial *serial = port->serial; 372 struct usb_serial *serial = port->serial;
@@ -381,7 +386,7 @@ static int visor_write (struct usb_serial_port *port, const unsigned char *buf,
381 priv->outstanding_urbs++; 386 priv->outstanding_urbs++;
382 spin_unlock_irqrestore(&priv->lock, flags); 387 spin_unlock_irqrestore(&priv->lock, flags);
383 388
384 buffer = kmalloc (count, GFP_ATOMIC); 389 buffer = kmalloc(count, GFP_ATOMIC);
385 if (!buffer) { 390 if (!buffer) {
386 dev_err(&port->dev, "out of memory\n"); 391 dev_err(&port->dev, "out of memory\n");
387 count = -ENOMEM; 392 count = -ENOMEM;
@@ -395,21 +400,22 @@ static int visor_write (struct usb_serial_port *port, const unsigned char *buf,
395 goto error_no_urb; 400 goto error_no_urb;
396 } 401 }
397 402
398 memcpy (buffer, buf, count); 403 memcpy(buffer, buf, count);
399 404
400 usb_serial_debug_data(debug, &port->dev, __func__, count, buffer); 405 usb_serial_debug_data(debug, &port->dev, __func__, count, buffer);
401 406
402 usb_fill_bulk_urb (urb, serial->dev, 407 usb_fill_bulk_urb(urb, serial->dev,
403 usb_sndbulkpipe (serial->dev, 408 usb_sndbulkpipe(serial->dev,
404 port->bulk_out_endpointAddress), 409 port->bulk_out_endpointAddress),
405 buffer, count, 410 buffer, count,
406 visor_write_bulk_callback, port); 411 visor_write_bulk_callback, port);
407 412
408 /* send it down the pipe */ 413 /* send it down the pipe */
409 status = usb_submit_urb(urb, GFP_ATOMIC); 414 status = usb_submit_urb(urb, GFP_ATOMIC);
410 if (status) { 415 if (status) {
411 dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed with status = %d\n", 416 dev_err(&port->dev,
412 __func__, status); 417 "%s - usb_submit_urb(write bulk) failed with status = %d\n",
418 __func__, status);
413 count = status; 419 count = status;
414 goto error; 420 goto error;
415 } else { 421 } else {
@@ -435,8 +441,9 @@ error_no_buffer:
435} 441}
436 442
437 443
438static int visor_write_room (struct usb_serial_port *port) 444static int visor_write_room(struct tty_struct *tty)
439{ 445{
446 struct usb_serial_port *port = tty->driver_data;
440 struct visor_private *priv = usb_get_serial_port_data(port); 447 struct visor_private *priv = usb_get_serial_port_data(port);
441 unsigned long flags; 448 unsigned long flags;
442 449
@@ -460,23 +467,7 @@ static int visor_write_room (struct usb_serial_port *port)
460} 467}
461 468
462 469
463static int visor_chars_in_buffer (struct usb_serial_port *port) 470static void visor_write_bulk_callback(struct urb *urb)
464{
465 dbg("%s - port %d", __func__, port->number);
466
467 /*
468 * We can't really account for how much data we
469 * have sent out, but hasn't made it through to the
470 * device, so just tell the tty layer that everything
471 * is flushed.
472 *
473 * FIXME: Should walk outstanding_urbs
474 */
475 return 0;
476}
477
478
479static void visor_write_bulk_callback (struct urb *urb)
480{ 471{
481 struct usb_serial_port *port = urb->context; 472 struct usb_serial_port *port = urb->context;
482 struct visor_private *priv = usb_get_serial_port_data(port); 473 struct visor_private *priv = usb_get_serial_port_data(port);
@@ -484,7 +475,7 @@ static void visor_write_bulk_callback (struct urb *urb)
484 unsigned long flags; 475 unsigned long flags;
485 476
486 /* free up the transfer buffer, as usb_free_urb() does not do this */ 477 /* free up the transfer buffer, as usb_free_urb() does not do this */
487 kfree (urb->transfer_buffer); 478 kfree(urb->transfer_buffer);
488 479
489 dbg("%s - port %d", __func__, port->number); 480 dbg("%s - port %d", __func__, port->number);
490 481
@@ -500,7 +491,7 @@ static void visor_write_bulk_callback (struct urb *urb)
500} 491}
501 492
502 493
503static void visor_read_bulk_callback (struct urb *urb) 494static void visor_read_bulk_callback(struct urb *urb)
504{ 495{
505 struct usb_serial_port *port = urb->context; 496 struct usb_serial_port *port = urb->context;
506 struct visor_private *priv = usb_get_serial_port_data(port); 497 struct visor_private *priv = usb_get_serial_port_data(port);
@@ -518,11 +509,13 @@ static void visor_read_bulk_callback (struct urb *urb)
518 return; 509 return;
519 } 510 }
520 511
521 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); 512 usb_serial_debug_data(debug, &port->dev, __func__,
513 urb->actual_length, data);
522 514
523 tty = port->tty; 515 tty = port->port.tty;
524 if (tty && urb->actual_length) { 516 if (tty && urb->actual_length) {
525 available_room = tty_buffer_request_room(tty, urb->actual_length); 517 available_room = tty_buffer_request_room(tty,
518 urb->actual_length);
526 if (available_room) { 519 if (available_room) {
527 tty_insert_flip_string(tty, data, available_room); 520 tty_insert_flip_string(tty, data, available_room);
528 tty_flip_buffer_push(tty); 521 tty_flip_buffer_push(tty);
@@ -536,22 +529,23 @@ static void visor_read_bulk_callback (struct urb *urb)
536 529
537 /* Continue trying to always read if we should */ 530 /* Continue trying to always read if we should */
538 if (!priv->throttled) { 531 if (!priv->throttled) {
539 usb_fill_bulk_urb (port->read_urb, port->serial->dev, 532 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
540 usb_rcvbulkpipe(port->serial->dev, 533 usb_rcvbulkpipe(port->serial->dev,
541 port->bulk_in_endpointAddress), 534 port->bulk_in_endpointAddress),
542 port->read_urb->transfer_buffer, 535 port->read_urb->transfer_buffer,
543 port->read_urb->transfer_buffer_length, 536 port->read_urb->transfer_buffer_length,
544 visor_read_bulk_callback, port); 537 visor_read_bulk_callback, port);
545 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 538 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
546 if (result) 539 if (result)
547 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result); 540 dev_err(&port->dev,
548 } else { 541 "%s - failed resubmitting read urb, error %d\n",
542 __func__, result);
543 } else
549 priv->actually_throttled = 1; 544 priv->actually_throttled = 1;
550 }
551 spin_unlock(&priv->lock); 545 spin_unlock(&priv->lock);
552} 546}
553 547
554static void visor_read_int_callback (struct urb *urb) 548static void visor_read_int_callback(struct urb *urb)
555{ 549{
556 struct usb_serial_port *port = urb->context; 550 struct usb_serial_port *port = urb->context;
557 int status = urb->status; 551 int status = urb->status;
@@ -585,14 +579,16 @@ static void visor_read_int_callback (struct urb *urb)
585 urb->actual_length, urb->transfer_buffer); 579 urb->actual_length, urb->transfer_buffer);
586 580
587exit: 581exit:
588 result = usb_submit_urb (urb, GFP_ATOMIC); 582 result = usb_submit_urb(urb, GFP_ATOMIC);
589 if (result) 583 if (result)
590 dev_err(&urb->dev->dev, "%s - Error %d submitting interrupt urb\n", 584 dev_err(&urb->dev->dev,
591 __func__, result); 585 "%s - Error %d submitting interrupt urb\n",
586 __func__, result);
592} 587}
593 588
594static void visor_throttle (struct usb_serial_port *port) 589static void visor_throttle(struct tty_struct *tty)
595{ 590{
591 struct usb_serial_port *port = tty->driver_data;
596 struct visor_private *priv = usb_get_serial_port_data(port); 592 struct visor_private *priv = usb_get_serial_port_data(port);
597 unsigned long flags; 593 unsigned long flags;
598 594
@@ -603,8 +599,9 @@ static void visor_throttle (struct usb_serial_port *port)
603} 599}
604 600
605 601
606static void visor_unthrottle (struct usb_serial_port *port) 602static void visor_unthrottle(struct tty_struct *tty)
607{ 603{
604 struct usb_serial_port *port = tty->driver_data;
608 struct visor_private *priv = usb_get_serial_port_data(port); 605 struct visor_private *priv = usb_get_serial_port_data(port);
609 unsigned long flags; 606 unsigned long flags;
610 int result; 607 int result;
@@ -618,10 +615,13 @@ static void visor_unthrottle (struct usb_serial_port *port)
618 port->read_urb->dev = port->serial->dev; 615 port->read_urb->dev = port->serial->dev;
619 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 616 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
620 if (result) 617 if (result)
621 dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __func__, result); 618 dev_err(&port->dev,
619 "%s - failed submitting read urb, error %d\n",
620 __func__, result);
622} 621}
623 622
624static int palm_os_3_probe (struct usb_serial *serial, const struct usb_device_id *id) 623static int palm_os_3_probe(struct usb_serial *serial,
624 const struct usb_device_id *id)
625{ 625{
626 struct device *dev = &serial->dev->dev; 626 struct device *dev = &serial->dev->dev;
627 struct visor_connection_info *connection_info; 627 struct visor_connection_info *connection_info;
@@ -633,7 +633,7 @@ static int palm_os_3_probe (struct usb_serial *serial, const struct usb_device_i
633 633
634 dbg("%s", __func__); 634 dbg("%s", __func__);
635 635
636 transfer_buffer = kmalloc (sizeof (*connection_info), GFP_KERNEL); 636 transfer_buffer = kmalloc(sizeof(*connection_info), GFP_KERNEL);
637 if (!transfer_buffer) { 637 if (!transfer_buffer) {
638 dev_err(dev, "%s - kmalloc(%Zd) failed.\n", __func__, 638 dev_err(dev, "%s - kmalloc(%Zd) failed.\n", __func__,
639 sizeof(*connection_info)); 639 sizeof(*connection_info));
@@ -641,7 +641,7 @@ static int palm_os_3_probe (struct usb_serial *serial, const struct usb_device_i
641 } 641 }
642 642
643 /* send a get connection info request */ 643 /* send a get connection info request */
644 retval = usb_control_msg (serial->dev, 644 retval = usb_control_msg(serial->dev,
645 usb_rcvctrlpipe(serial->dev, 0), 645 usb_rcvctrlpipe(serial->dev, 0),
646 VISOR_GET_CONNECTION_INFORMATION, 646 VISOR_GET_CONNECTION_INFORMATION,
647 0xc2, 0x0000, 0x0000, transfer_buffer, 647 0xc2, 0x0000, 0x0000, transfer_buffer,
@@ -653,29 +653,31 @@ static int palm_os_3_probe (struct usb_serial *serial, const struct usb_device_i
653 } 653 }
654 654
655 if (retval == sizeof(*connection_info)) { 655 if (retval == sizeof(*connection_info)) {
656 connection_info = (struct visor_connection_info *)transfer_buffer; 656 connection_info = (struct visor_connection_info *)
657 transfer_buffer;
657 658
658 num_ports = le16_to_cpu(connection_info->num_ports); 659 num_ports = le16_to_cpu(connection_info->num_ports);
659 for (i = 0; i < num_ports; ++i) { 660 for (i = 0; i < num_ports; ++i) {
660 switch (connection_info->connections[i].port_function_id) { 661 switch (
661 case VISOR_FUNCTION_GENERIC: 662 connection_info->connections[i].port_function_id) {
662 string = "Generic"; 663 case VISOR_FUNCTION_GENERIC:
663 break; 664 string = "Generic";
664 case VISOR_FUNCTION_DEBUGGER: 665 break;
665 string = "Debugger"; 666 case VISOR_FUNCTION_DEBUGGER:
666 break; 667 string = "Debugger";
667 case VISOR_FUNCTION_HOTSYNC: 668 break;
668 string = "HotSync"; 669 case VISOR_FUNCTION_HOTSYNC:
669 break; 670 string = "HotSync";
670 case VISOR_FUNCTION_CONSOLE: 671 break;
671 string = "Console"; 672 case VISOR_FUNCTION_CONSOLE:
672 break; 673 string = "Console";
673 case VISOR_FUNCTION_REMOTE_FILE_SYS: 674 break;
674 string = "Remote File System"; 675 case VISOR_FUNCTION_REMOTE_FILE_SYS:
675 break; 676 string = "Remote File System";
676 default: 677 break;
677 string = "unknown"; 678 default:
678 break; 679 string = "unknown";
680 break;
679 } 681 }
680 dev_info(dev, "%s: port %d, is for %s use\n", 682 dev_info(dev, "%s: port %d, is for %s use\n",
681 serial->type->description, 683 serial->type->description,
@@ -686,11 +688,11 @@ static int palm_os_3_probe (struct usb_serial *serial, const struct usb_device_i
686 * Handle devices that report invalid stuff here. 688 * Handle devices that report invalid stuff here.
687 */ 689 */
688 if (num_ports == 0 || num_ports > 2) { 690 if (num_ports == 0 || num_ports > 2) {
689 dev_warn (dev, "%s: No valid connect info available\n", 691 dev_warn(dev, "%s: No valid connect info available\n",
690 serial->type->description); 692 serial->type->description);
691 num_ports = 2; 693 num_ports = 2;
692 } 694 }
693 695
694 dev_info(dev, "%s: Number of ports: %d\n", serial->type->description, 696 dev_info(dev, "%s: Number of ports: %d\n", serial->type->description,
695 num_ports); 697 num_ports);
696 698
@@ -700,8 +702,9 @@ static int palm_os_3_probe (struct usb_serial *serial, const struct usb_device_i
700 */ 702 */
701 usb_set_serial_data(serial, (void *)(long)num_ports); 703 usb_set_serial_data(serial, (void *)(long)num_ports);
702 704
703 /* ask for the number of bytes available, but ignore the response as it is broken */ 705 /* ask for the number of bytes available, but ignore the
704 retval = usb_control_msg (serial->dev, 706 response as it is broken */
707 retval = usb_control_msg(serial->dev,
705 usb_rcvctrlpipe(serial->dev, 0), 708 usb_rcvctrlpipe(serial->dev, 0),
706 VISOR_REQUEST_BYTES_AVAILABLE, 709 VISOR_REQUEST_BYTES_AVAILABLE,
707 0xc2, 0x0000, 0x0005, transfer_buffer, 710 0xc2, 0x0000, 0x0005, transfer_buffer,
@@ -712,12 +715,13 @@ static int palm_os_3_probe (struct usb_serial *serial, const struct usb_device_i
712 retval = 0; 715 retval = 0;
713 716
714exit: 717exit:
715 kfree (transfer_buffer); 718 kfree(transfer_buffer);
716 719
717 return retval; 720 return retval;
718} 721}
719 722
720static int palm_os_4_probe (struct usb_serial *serial, const struct usb_device_id *id) 723static int palm_os_4_probe(struct usb_serial *serial,
724 const struct usb_device_id *id)
721{ 725{
722 struct device *dev = &serial->dev->dev; 726 struct device *dev = &serial->dev->dev;
723 struct palm_ext_connection_info *connection_info; 727 struct palm_ext_connection_info *connection_info;
@@ -726,18 +730,18 @@ static int palm_os_4_probe (struct usb_serial *serial, const struct usb_device_i
726 730
727 dbg("%s", __func__); 731 dbg("%s", __func__);
728 732
729 transfer_buffer = kmalloc (sizeof (*connection_info), GFP_KERNEL); 733 transfer_buffer = kmalloc(sizeof(*connection_info), GFP_KERNEL);
730 if (!transfer_buffer) { 734 if (!transfer_buffer) {
731 dev_err(dev, "%s - kmalloc(%Zd) failed.\n", __func__, 735 dev_err(dev, "%s - kmalloc(%Zd) failed.\n", __func__,
732 sizeof(*connection_info)); 736 sizeof(*connection_info));
733 return -ENOMEM; 737 return -ENOMEM;
734 } 738 }
735 739
736 retval = usb_control_msg (serial->dev, 740 retval = usb_control_msg(serial->dev,
737 usb_rcvctrlpipe(serial->dev, 0), 741 usb_rcvctrlpipe(serial->dev, 0),
738 PALM_GET_EXT_CONNECTION_INFORMATION, 742 PALM_GET_EXT_CONNECTION_INFORMATION,
739 0xc2, 0x0000, 0x0000, transfer_buffer, 743 0xc2, 0x0000, 0x0000, transfer_buffer,
740 sizeof (*connection_info), 300); 744 sizeof(*connection_info), 300);
741 if (retval < 0) 745 if (retval < 0)
742 dev_err(dev, "%s - error %d getting connection info\n", 746 dev_err(dev, "%s - error %d getting connection info\n",
743 __func__, retval); 747 __func__, retval);
@@ -745,15 +749,17 @@ static int palm_os_4_probe (struct usb_serial *serial, const struct usb_device_i
745 usb_serial_debug_data(debug, &serial->dev->dev, __func__, 749 usb_serial_debug_data(debug, &serial->dev->dev, __func__,
746 retval, transfer_buffer); 750 retval, transfer_buffer);
747 751
748 kfree (transfer_buffer); 752 kfree(transfer_buffer);
749 return 0; 753 return 0;
750} 754}
751 755
752 756
753static int visor_probe (struct usb_serial *serial, const struct usb_device_id *id) 757static int visor_probe(struct usb_serial *serial,
758 const struct usb_device_id *id)
754{ 759{
755 int retval = 0; 760 int retval = 0;
756 int (*startup) (struct usb_serial *serial, const struct usb_device_id *id); 761 int (*startup)(struct usb_serial *serial,
762 const struct usb_device_id *id);
757 763
758 dbg("%s", __func__); 764 dbg("%s", __func__);
759 765
@@ -771,7 +777,7 @@ static int visor_probe (struct usb_serial *serial, const struct usb_device_id *i
771 return retval; 777 return retval;
772} 778}
773 779
774static int visor_calc_num_ports (struct usb_serial *serial) 780static int visor_calc_num_ports(struct usb_serial *serial)
775{ 781{
776 int num_ports = (int)(long)(usb_get_serial_data(serial)); 782 int num_ports = (int)(long)(usb_get_serial_data(serial));
777 783
@@ -788,7 +794,7 @@ static int generic_startup(struct usb_serial *serial)
788 int i; 794 int i;
789 795
790 for (i = 0; i < serial->num_ports; ++i) { 796 for (i = 0; i < serial->num_ports; ++i) {
791 priv = kzalloc (sizeof(*priv), GFP_KERNEL); 797 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
792 if (!priv) { 798 if (!priv) {
793 while (i-- != 0) { 799 while (i-- != 0) {
794 priv = usb_get_serial_port_data(ports[i]); 800 priv = usb_get_serial_port_data(ports[i]);
@@ -803,7 +809,7 @@ static int generic_startup(struct usb_serial *serial)
803 return 0; 809 return 0;
804} 810}
805 811
806static int clie_3_5_startup (struct usb_serial *serial) 812static int clie_3_5_startup(struct usb_serial *serial)
807{ 813{
808 struct device *dev = &serial->dev->dev; 814 struct device *dev = &serial->dev->dev;
809 int result; 815 int result;
@@ -816,62 +822,72 @@ static int clie_3_5_startup (struct usb_serial *serial)
816 */ 822 */
817 823
818 /* get the config number */ 824 /* get the config number */
819 result = usb_control_msg (serial->dev, usb_rcvctrlpipe(serial->dev, 0), 825 result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
820 USB_REQ_GET_CONFIGURATION, USB_DIR_IN, 826 USB_REQ_GET_CONFIGURATION, USB_DIR_IN,
821 0, 0, &data, 1, 3000); 827 0, 0, &data, 1, 3000);
822 if (result < 0) { 828 if (result < 0) {
823 dev_err(dev, "%s: get config number failed: %d\n", __func__, result); 829 dev_err(dev, "%s: get config number failed: %d\n",
830 __func__, result);
824 return result; 831 return result;
825 } 832 }
826 if (result != 1) { 833 if (result != 1) {
827 dev_err(dev, "%s: get config number bad return length: %d\n", __func__, result); 834 dev_err(dev, "%s: get config number bad return length: %d\n",
835 __func__, result);
828 return -EIO; 836 return -EIO;
829 } 837 }
830 838
831 /* get the interface number */ 839 /* get the interface number */
832 result = usb_control_msg (serial->dev, usb_rcvctrlpipe(serial->dev, 0), 840 result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
833 USB_REQ_GET_INTERFACE, 841 USB_REQ_GET_INTERFACE,
834 USB_DIR_IN | USB_RECIP_INTERFACE, 842 USB_DIR_IN | USB_RECIP_INTERFACE,
835 0, 0, &data, 1, 3000); 843 0, 0, &data, 1, 3000);
836 if (result < 0) { 844 if (result < 0) {
837 dev_err(dev, "%s: get interface number failed: %d\n", __func__, result); 845 dev_err(dev, "%s: get interface number failed: %d\n",
846 __func__, result);
838 return result; 847 return result;
839 } 848 }
840 if (result != 1) { 849 if (result != 1) {
841 dev_err(dev, "%s: get interface number bad return length: %d\n", __func__, result); 850 dev_err(dev,
851 "%s: get interface number bad return length: %d\n",
852 __func__, result);
842 return -EIO; 853 return -EIO;
843 } 854 }
844 855
845 return generic_startup(serial); 856 return generic_startup(serial);
846} 857}
847 858
848static int treo_attach (struct usb_serial *serial) 859static int treo_attach(struct usb_serial *serial)
849{ 860{
850 struct usb_serial_port *swap_port; 861 struct usb_serial_port *swap_port;
851 862
852 /* Only do this endpoint hack for the Handspring devices with 863 /* Only do this endpoint hack for the Handspring devices with
853 * interrupt in endpoints, which for now are the Treo devices. */ 864 * interrupt in endpoints, which for now are the Treo devices. */
854 if (!((le16_to_cpu(serial->dev->descriptor.idVendor) == HANDSPRING_VENDOR_ID) || 865 if (!((le16_to_cpu(serial->dev->descriptor.idVendor)
855 (le16_to_cpu(serial->dev->descriptor.idVendor) == KYOCERA_VENDOR_ID)) || 866 == HANDSPRING_VENDOR_ID) ||
856 (serial->num_interrupt_in == 0)) 867 (le16_to_cpu(serial->dev->descriptor.idVendor)
868 == KYOCERA_VENDOR_ID)) ||
869 (serial->num_interrupt_in == 0))
857 goto generic_startup; 870 goto generic_startup;
858 871
859 dbg("%s", __func__); 872 dbg("%s", __func__);
860 873
861 /* 874 /*
862 * It appears that Treos and Kyoceras want to use the 875 * It appears that Treos and Kyoceras want to use the
863 * 1st bulk in endpoint to communicate with the 2nd bulk out endpoint, 876 * 1st bulk in endpoint to communicate with the 2nd bulk out endpoint,
864 * so let's swap the 1st and 2nd bulk in and interrupt endpoints. 877 * so let's swap the 1st and 2nd bulk in and interrupt endpoints.
865 * Note that swapping the bulk out endpoints would break lots of 878 * Note that swapping the bulk out endpoints would break lots of
866 * apps that want to communicate on the second port. 879 * apps that want to communicate on the second port.
867 */ 880 */
868#define COPY_PORT(dest, src) \ 881#define COPY_PORT(dest, src) \
869 dest->read_urb = src->read_urb; \ 882 do { \
870 dest->bulk_in_endpointAddress = src->bulk_in_endpointAddress; \ 883 dest->read_urb = src->read_urb; \
871 dest->bulk_in_buffer = src->bulk_in_buffer; \ 884 dest->bulk_in_endpointAddress = src->bulk_in_endpointAddress;\
872 dest->interrupt_in_urb = src->interrupt_in_urb; \ 885 dest->bulk_in_buffer = src->bulk_in_buffer; \
873 dest->interrupt_in_endpointAddress = src->interrupt_in_endpointAddress; \ 886 dest->interrupt_in_urb = src->interrupt_in_urb; \
874 dest->interrupt_in_buffer = src->interrupt_in_buffer; 887 dest->interrupt_in_endpointAddress = \
888 src->interrupt_in_endpointAddress;\
889 dest->interrupt_in_buffer = src->interrupt_in_buffer; \
890 } while (0);
875 891
876 swap_port = kmalloc(sizeof(*swap_port), GFP_KERNEL); 892 swap_port = kmalloc(sizeof(*swap_port), GFP_KERNEL);
877 if (!swap_port) 893 if (!swap_port)
@@ -885,28 +901,30 @@ generic_startup:
885 return generic_startup(serial); 901 return generic_startup(serial);
886} 902}
887 903
888static int clie_5_attach (struct usb_serial *serial) 904static int clie_5_attach(struct usb_serial *serial)
889{ 905{
890 dbg("%s", __func__); 906 dbg("%s", __func__);
891 907
892 /* TH55 registers 2 ports. 908 /* TH55 registers 2 ports.
893 Communication in from the UX50/TH55 uses bulk_in_endpointAddress from port 0 909 Communication in from the UX50/TH55 uses bulk_in_endpointAddress
894 Communication out to the UX50/TH55 uses bulk_out_endpointAddress from port 1 910 from port 0. Communication out to the UX50/TH55 uses
895 911 bulk_out_endpointAddress from port 1
912
896 Lets do a quick and dirty mapping 913 Lets do a quick and dirty mapping
897 */ 914 */
898 915
899 /* some sanity check */ 916 /* some sanity check */
900 if (serial->num_ports < 2) 917 if (serial->num_ports < 2)
901 return -1; 918 return -1;
902 919
903 /* port 0 now uses the modified endpoint Address */ 920 /* port 0 now uses the modified endpoint Address */
904 serial->port[0]->bulk_out_endpointAddress = serial->port[1]->bulk_out_endpointAddress; 921 serial->port[0]->bulk_out_endpointAddress =
922 serial->port[1]->bulk_out_endpointAddress;
905 923
906 return generic_startup(serial); 924 return generic_startup(serial);
907} 925}
908 926
909static void visor_shutdown (struct usb_serial *serial) 927static void visor_shutdown(struct usb_serial *serial)
910{ 928{
911 struct visor_private *priv; 929 struct visor_private *priv;
912 int i; 930 int i;
@@ -922,37 +940,35 @@ static void visor_shutdown (struct usb_serial *serial)
922 } 940 }
923} 941}
924 942
925static int visor_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg) 943static int __init visor_init(void)
926{
927 dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd);
928
929 return -ENOIOCTLCMD;
930}
931
932static int __init visor_init (void)
933{ 944{
934 int i, retval; 945 int i, retval;
935 /* Only if parameters were passed to us */ 946 /* Only if parameters were passed to us */
936 if ((vendor>0) && (product>0)) { 947 if (vendor > 0 && product > 0) {
937 struct usb_device_id usb_dev_temp[]= 948 struct usb_device_id usb_dev_temp[] = {
938 {{USB_DEVICE(vendor, product), 949 {
939 .driver_info = (kernel_ulong_t)&palm_os_4_probe }}; 950 USB_DEVICE(vendor, product),
951 .driver_info =
952 (kernel_ulong_t) &palm_os_4_probe
953 }
954 };
940 955
941 /* Find the last entry in id_table */ 956 /* Find the last entry in id_table */
942 for (i=0; ; i++) { 957 for (i = 0;; i++) {
943 if (id_table[i].idVendor==0) { 958 if (id_table[i].idVendor == 0) {
944 id_table[i] = usb_dev_temp[0]; 959 id_table[i] = usb_dev_temp[0];
945 break; 960 break;
946 } 961 }
947 } 962 }
948 /* Find the last entry in id_table_combined */ 963 /* Find the last entry in id_table_combined */
949 for (i=0; ; i++) { 964 for (i = 0;; i++) {
950 if (id_table_combined[i].idVendor==0) { 965 if (id_table_combined[i].idVendor == 0) {
951 id_table_combined[i] = usb_dev_temp[0]; 966 id_table_combined[i] = usb_dev_temp[0];
952 break; 967 break;
953 } 968 }
954 } 969 }
955 info("Untested USB device specified at time of module insertion"); 970 info(
971 "Untested USB device specified at time of module insertion");
956 info("Warning: This is not guaranteed to work"); 972 info("Warning: This is not guaranteed to work");
957 info("Using a newer kernel is preferred to this method"); 973 info("Using a newer kernel is preferred to this method");
958 info("Adding Palm OS protocol 4.x support for unknown device: 0x%x/0x%x", 974 info("Adding Palm OS protocol 4.x support for unknown device: 0x%x/0x%x",
@@ -968,7 +984,7 @@ static int __init visor_init (void)
968 if (retval) 984 if (retval)
969 goto failed_clie_5_register; 985 goto failed_clie_5_register;
970 retval = usb_register(&visor_driver); 986 retval = usb_register(&visor_driver);
971 if (retval) 987 if (retval)
972 goto failed_usb_register; 988 goto failed_usb_register;
973 info(DRIVER_DESC); 989 info(DRIVER_DESC);
974 990
@@ -986,18 +1002,18 @@ failed_handspring_register:
986 1002
987static void __exit visor_exit (void) 1003static void __exit visor_exit (void)
988{ 1004{
989 usb_deregister (&visor_driver); 1005 usb_deregister(&visor_driver);
990 usb_serial_deregister (&handspring_device); 1006 usb_serial_deregister(&handspring_device);
991 usb_serial_deregister (&clie_3_5_device); 1007 usb_serial_deregister(&clie_3_5_device);
992 usb_serial_deregister (&clie_5_device); 1008 usb_serial_deregister(&clie_5_device);
993} 1009}
994 1010
995 1011
996module_init(visor_init); 1012module_init(visor_init);
997module_exit(visor_exit); 1013module_exit(visor_exit);
998 1014
999MODULE_AUTHOR( DRIVER_AUTHOR ); 1015MODULE_AUTHOR(DRIVER_AUTHOR);
1000MODULE_DESCRIPTION( DRIVER_DESC ); 1016MODULE_DESCRIPTION(DRIVER_DESC);
1001MODULE_LICENSE("GPL"); 1017MODULE_LICENSE("GPL");
1002 1018
1003module_param(debug, bool, S_IRUGO | S_IWUSR); 1019module_param(debug, bool, S_IRUGO | S_IWUSR);
diff --git a/drivers/usb/serial/whiteheat.c b/drivers/usb/serial/whiteheat.c
index 665aa77a917b..3a9d14384a43 100644
--- a/drivers/usb/serial/whiteheat.c
+++ b/drivers/usb/serial/whiteheat.c
@@ -12,29 +12,31 @@
12 * the Free Software Foundation; either version 2 of the License, or 12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. 13 * (at your option) any later version.
14 * 14 *
15 * See Documentation/usb/usb-serial.txt for more information on using this driver 15 * See Documentation/usb/usb-serial.txt for more information on using this
16 * driver
16 * 17 *
17 * (10/09/2002) Stuart MacDonald (stuartm@connecttech.com) 18 * (10/09/2002) Stuart MacDonald (stuartm@connecttech.com)
18 * Upgrade to full working driver 19 * Upgrade to full working driver
19 * 20 *
20 * (05/30/2001) gkh 21 * (05/30/2001) gkh
21 * switched from using spinlock to a semaphore, which fixes lots of problems. 22 * switched from using spinlock to a semaphore, which fixes lots of
23 * problems.
22 * 24 *
23 * (04/08/2001) gb 25 * (04/08/2001) gb
24 * Identify version on module load. 26 * Identify version on module load.
25 * 27 *
26 * 2001_Mar_19 gkh 28 * 2001_Mar_19 gkh
27 * Fixed MOD_INC and MOD_DEC logic, the ability to open a port more 29 * Fixed MOD_INC and MOD_DEC logic, the ability to open a port more
28 * than once, and the got the proper usb_device_id table entries so 30 * than once, and the got the proper usb_device_id table entries so
29 * the driver works again. 31 * the driver works again.
30 * 32 *
31 * (11/01/2000) Adam J. Richter 33 * (11/01/2000) Adam J. Richter
32 * usb_device_id table support 34 * usb_device_id table support
33 * 35 *
34 * (10/05/2000) gkh 36 * (10/05/2000) gkh
35 * Fixed bug with urb->dev not being set properly, now that the usb 37 * Fixed bug with urb->dev not being set properly, now that the usb
36 * core needs it. 38 * core needs it.
37 * 39 *
38 * (10/03/2000) smd 40 * (10/03/2000) smd
39 * firmware is improved to guard against crap sent to device 41 * firmware is improved to guard against crap sent to device
40 * firmware now replies CMD_FAILURE on bad things 42 * firmware now replies CMD_FAILURE on bad things
@@ -52,9 +54,9 @@
52 * Fixed bug with port->minor that was found by Al Borchers 54 * Fixed bug with port->minor that was found by Al Borchers
53 * 55 *
54 * (07/04/2000) gkh 56 * (07/04/2000) gkh
55 * Added support for port settings. Baud rate can now be changed. Line signals 57 * Added support for port settings. Baud rate can now be changed. Line
56 * are not transferred to and from the tty layer yet, but things seem to be 58 * signals are not transferred to and from the tty layer yet, but things
57 * working well now. 59 * seem to be working well now.
58 * 60 *
59 * (05/04/2000) gkh 61 * (05/04/2000) gkh
60 * First cut at open and close commands. Data can flow through the ports at 62 * First cut at open and close commands. Data can flow through the ports at
@@ -62,7 +64,7 @@
62 * 64 *
63 * (03/26/2000) gkh 65 * (03/26/2000) gkh
64 * Split driver up into device specific pieces. 66 * Split driver up into device specific pieces.
65 * 67 *
66 */ 68 */
67 69
68#include <linux/kernel.h> 70#include <linux/kernel.h>
@@ -75,7 +77,7 @@
75#include <linux/module.h> 77#include <linux/module.h>
76#include <linux/spinlock.h> 78#include <linux/spinlock.h>
77#include <linux/mutex.h> 79#include <linux/mutex.h>
78#include <asm/uaccess.h> 80#include <linux/uaccess.h>
79#include <asm/termbits.h> 81#include <asm/termbits.h>
80#include <linux/usb.h> 82#include <linux/usb.h>
81#include <linux/serial_reg.h> 83#include <linux/serial_reg.h>
@@ -125,7 +127,7 @@ static struct usb_device_id id_table_combined [] = {
125 { } /* Terminating entry */ 127 { } /* Terminating entry */
126}; 128};
127 129
128MODULE_DEVICE_TABLE (usb, id_table_combined); 130MODULE_DEVICE_TABLE(usb, id_table_combined);
129 131
130static struct usb_driver whiteheat_driver = { 132static struct usb_driver whiteheat_driver = {
131 .name = "whiteheat", 133 .name = "whiteheat",
@@ -136,26 +138,34 @@ static struct usb_driver whiteheat_driver = {
136}; 138};
137 139
138/* function prototypes for the Connect Tech WhiteHEAT prerenumeration device */ 140/* function prototypes for the Connect Tech WhiteHEAT prerenumeration device */
139static int whiteheat_firmware_download (struct usb_serial *serial, const struct usb_device_id *id); 141static int whiteheat_firmware_download(struct usb_serial *serial,
140static int whiteheat_firmware_attach (struct usb_serial *serial); 142 const struct usb_device_id *id);
143static int whiteheat_firmware_attach(struct usb_serial *serial);
141 144
142/* function prototypes for the Connect Tech WhiteHEAT serial converter */ 145/* function prototypes for the Connect Tech WhiteHEAT serial converter */
143static int whiteheat_attach (struct usb_serial *serial); 146static int whiteheat_attach(struct usb_serial *serial);
144static void whiteheat_shutdown (struct usb_serial *serial); 147static void whiteheat_shutdown(struct usb_serial *serial);
145static int whiteheat_open (struct usb_serial_port *port, struct file *filp); 148static int whiteheat_open(struct tty_struct *tty,
146static void whiteheat_close (struct usb_serial_port *port, struct file *filp); 149 struct usb_serial_port *port, struct file *filp);
147static int whiteheat_write (struct usb_serial_port *port, const unsigned char *buf, int count); 150static void whiteheat_close(struct tty_struct *tty,
148static int whiteheat_write_room (struct usb_serial_port *port); 151 struct usb_serial_port *port, struct file *filp);
149static int whiteheat_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg); 152static int whiteheat_write(struct tty_struct *tty,
150static void whiteheat_set_termios (struct usb_serial_port *port, struct ktermios * old); 153 struct usb_serial_port *port,
151static int whiteheat_tiocmget (struct usb_serial_port *port, struct file *file); 154 const unsigned char *buf, int count);
152static int whiteheat_tiocmset (struct usb_serial_port *port, struct file *file, unsigned int set, unsigned int clear); 155static int whiteheat_write_room(struct tty_struct *tty);
153static void whiteheat_break_ctl (struct usb_serial_port *port, int break_state); 156static int whiteheat_ioctl(struct tty_struct *tty, struct file *file,
154static int whiteheat_chars_in_buffer (struct usb_serial_port *port); 157 unsigned int cmd, unsigned long arg);
155static void whiteheat_throttle (struct usb_serial_port *port); 158static void whiteheat_set_termios(struct tty_struct *tty,
156static void whiteheat_unthrottle (struct usb_serial_port *port); 159 struct usb_serial_port *port, struct ktermios *old);
157static void whiteheat_read_callback (struct urb *urb); 160static int whiteheat_tiocmget(struct tty_struct *tty, struct file *file);
158static void whiteheat_write_callback (struct urb *urb); 161static int whiteheat_tiocmset(struct tty_struct *tty, struct file *file,
162 unsigned int set, unsigned int clear);
163static void whiteheat_break_ctl(struct tty_struct *tty, int break_state);
164static int whiteheat_chars_in_buffer(struct tty_struct *tty);
165static void whiteheat_throttle(struct tty_struct *tty);
166static void whiteheat_unthrottle(struct tty_struct *tty);
167static void whiteheat_read_callback(struct urb *urb);
168static void whiteheat_write_callback(struct urb *urb);
159 169
160static struct usb_serial_driver whiteheat_fake_device = { 170static struct usb_serial_driver whiteheat_fake_device = {
161 .driver = { 171 .driver = {
@@ -202,7 +212,9 @@ struct whiteheat_command_private {
202 struct mutex mutex; 212 struct mutex mutex;
203 __u8 port_running; 213 __u8 port_running;
204 __u8 command_finished; 214 __u8 command_finished;
205 wait_queue_head_t wait_command; /* for handling sleeping while waiting for a command to finish */ 215 wait_queue_head_t wait_command; /* for handling sleeping whilst
216 waiting for a command to
217 finish */
206 __u8 result_buffer[64]; 218 __u8 result_buffer[64];
207}; 219};
208 220
@@ -239,14 +251,16 @@ static void command_port_write_callback(struct urb *urb);
239static void command_port_read_callback(struct urb *urb); 251static void command_port_read_callback(struct urb *urb);
240 252
241static int start_port_read(struct usb_serial_port *port); 253static int start_port_read(struct usb_serial_port *port);
242static struct whiteheat_urb_wrap *urb_to_wrap(struct urb *urb, struct list_head *head); 254static struct whiteheat_urb_wrap *urb_to_wrap(struct urb *urb,
255 struct list_head *head);
243static struct list_head *list_first(struct list_head *head); 256static struct list_head *list_first(struct list_head *head);
244static void rx_data_softint(struct work_struct *work); 257static void rx_data_softint(struct work_struct *work);
245 258
246static int firm_send_command(struct usb_serial_port *port, __u8 command, __u8 *data, __u8 datasize); 259static int firm_send_command(struct usb_serial_port *port, __u8 command,
260 __u8 *data, __u8 datasize);
247static int firm_open(struct usb_serial_port *port); 261static int firm_open(struct usb_serial_port *port);
248static int firm_close(struct usb_serial_port *port); 262static int firm_close(struct usb_serial_port *port);
249static int firm_setup_port(struct usb_serial_port *port); 263static int firm_setup_port(struct tty_struct *tty);
250static int firm_set_rts(struct usb_serial_port *port, __u8 onoff); 264static int firm_set_rts(struct usb_serial_port *port, __u8 onoff);
251static int firm_set_dtr(struct usb_serial_port *port, __u8 onoff); 265static int firm_set_dtr(struct usb_serial_port *port, __u8 onoff);
252static int firm_set_break(struct usb_serial_port *port, __u8 onoff); 266static int firm_set_break(struct usb_serial_port *port, __u8 onoff);
@@ -278,7 +292,8 @@ static int firm_report_tx_done(struct usb_serial_port *port);
278 - device renumerated itself and comes up as new device id with all 292 - device renumerated itself and comes up as new device id with all
279 firmware download completed. 293 firmware download completed.
280*/ 294*/
281static int whiteheat_firmware_download (struct usb_serial *serial, const struct usb_device_id *id) 295static int whiteheat_firmware_download(struct usb_serial *serial,
296 const struct usb_device_id *id)
282{ 297{
283 int response, ret = -ENOENT; 298 int response, ret = -ENOENT;
284 const struct firmware *loader_fw = NULL, *firmware_fw = NULL; 299 const struct firmware *loader_fw = NULL, *firmware_fw = NULL;
@@ -313,7 +328,7 @@ static int whiteheat_firmware_download (struct usb_serial *serial, const struct
313 record = ihex_next_binrec(record); 328 record = ihex_next_binrec(record);
314 } 329 }
315 330
316 response = ezusb_set_reset (serial, 0); 331 response = ezusb_set_reset(serial, 0);
317 332
318 record = (const struct ihex_binrec *)firmware_fw->data; 333 record = (const struct ihex_binrec *)firmware_fw->data;
319 while (record && be32_to_cpu(record->addr) < 0x1b40) 334 while (record && be32_to_cpu(record->addr) < 0x1b40)
@@ -330,8 +345,8 @@ static int whiteheat_firmware_download (struct usb_serial *serial, const struct
330 } 345 }
331 ++record; 346 ++record;
332 } 347 }
333 348
334 response = ezusb_set_reset (serial, 1); 349 response = ezusb_set_reset(serial, 1);
335 350
336 record = (const struct ihex_binrec *)firmware_fw->data; 351 record = (const struct ihex_binrec *)firmware_fw->data;
337 while (record && be32_to_cpu(record->addr) < 0x1b40) { 352 while (record && be32_to_cpu(record->addr) < 0x1b40) {
@@ -355,7 +370,7 @@ static int whiteheat_firmware_download (struct usb_serial *serial, const struct
355} 370}
356 371
357 372
358static int whiteheat_firmware_attach (struct usb_serial *serial) 373static int whiteheat_firmware_attach(struct usb_serial *serial)
359{ 374{
360 /* We want this device to fail to have a driver assigned to it */ 375 /* We want this device to fail to have a driver assigned to it */
361 return 1; 376 return 1;
@@ -365,7 +380,7 @@ static int whiteheat_firmware_attach (struct usb_serial *serial)
365/***************************************************************************** 380/*****************************************************************************
366 * Connect Tech's White Heat serial driver functions 381 * Connect Tech's White Heat serial driver functions
367 *****************************************************************************/ 382 *****************************************************************************/
368static int whiteheat_attach (struct usb_serial *serial) 383static int whiteheat_attach(struct usb_serial *serial)
369{ 384{
370 struct usb_serial_port *command_port; 385 struct usb_serial_port *command_port;
371 struct whiteheat_command_private *command_info; 386 struct whiteheat_command_private *command_info;
@@ -386,43 +401,52 @@ static int whiteheat_attach (struct usb_serial *serial)
386 401
387 command_port = serial->port[COMMAND_PORT]; 402 command_port = serial->port[COMMAND_PORT];
388 403
389 pipe = usb_sndbulkpipe (serial->dev, command_port->bulk_out_endpointAddress); 404 pipe = usb_sndbulkpipe(serial->dev,
405 command_port->bulk_out_endpointAddress);
390 command = kmalloc(2, GFP_KERNEL); 406 command = kmalloc(2, GFP_KERNEL);
391 if (!command) 407 if (!command)
392 goto no_command_buffer; 408 goto no_command_buffer;
393 command[0] = WHITEHEAT_GET_HW_INFO; 409 command[0] = WHITEHEAT_GET_HW_INFO;
394 command[1] = 0; 410 command[1] = 0;
395 411
396 result = kmalloc(sizeof(*hw_info) + 1, GFP_KERNEL); 412 result = kmalloc(sizeof(*hw_info) + 1, GFP_KERNEL);
397 if (!result) 413 if (!result)
398 goto no_result_buffer; 414 goto no_result_buffer;
399 /* 415 /*
400 * When the module is reloaded the firmware is still there and 416 * When the module is reloaded the firmware is still there and
401 * the endpoints are still in the usb core unchanged. This is the 417 * the endpoints are still in the usb core unchanged. This is the
402 * unlinking bug in disguise. Same for the call below. 418 * unlinking bug in disguise. Same for the call below.
403 */ 419 */
404 usb_clear_halt(serial->dev, pipe); 420 usb_clear_halt(serial->dev, pipe);
405 ret = usb_bulk_msg (serial->dev, pipe, command, 2, &alen, COMMAND_TIMEOUT_MS); 421 ret = usb_bulk_msg(serial->dev, pipe, command, 2,
422 &alen, COMMAND_TIMEOUT_MS);
406 if (ret) { 423 if (ret) {
407 err("%s: Couldn't send command [%d]", serial->type->description, ret); 424 err("%s: Couldn't send command [%d]",
425 serial->type->description, ret);
408 goto no_firmware; 426 goto no_firmware;
409 } else if (alen != 2) { 427 } else if (alen != 2) {
410 err("%s: Send command incomplete [%d]", serial->type->description, alen); 428 err("%s: Send command incomplete [%d]",
429 serial->type->description, alen);
411 goto no_firmware; 430 goto no_firmware;
412 } 431 }
413 432
414 pipe = usb_rcvbulkpipe (serial->dev, command_port->bulk_in_endpointAddress); 433 pipe = usb_rcvbulkpipe(serial->dev,
434 command_port->bulk_in_endpointAddress);
415 /* See the comment on the usb_clear_halt() above */ 435 /* See the comment on the usb_clear_halt() above */
416 usb_clear_halt(serial->dev, pipe); 436 usb_clear_halt(serial->dev, pipe);
417 ret = usb_bulk_msg (serial->dev, pipe, result, sizeof(*hw_info) + 1, &alen, COMMAND_TIMEOUT_MS); 437 ret = usb_bulk_msg(serial->dev, pipe, result,
438 sizeof(*hw_info) + 1, &alen, COMMAND_TIMEOUT_MS);
418 if (ret) { 439 if (ret) {
419 err("%s: Couldn't get results [%d]", serial->type->description, ret); 440 err("%s: Couldn't get results [%d]",
441 serial->type->description, ret);
420 goto no_firmware; 442 goto no_firmware;
421 } else if (alen != sizeof(*hw_info) + 1) { 443 } else if (alen != sizeof(*hw_info) + 1) {
422 err("%s: Get results incomplete [%d]", serial->type->description, alen); 444 err("%s: Get results incomplete [%d]",
445 serial->type->description, alen);
423 goto no_firmware; 446 goto no_firmware;
424 } else if (result[0] != command[0]) { 447 } else if (result[0] != command[0]) {
425 err("%s: Command failed [%d]", serial->type->description, result[0]); 448 err("%s: Command failed [%d]",
449 serial->type->description, result[0]);
426 goto no_firmware; 450 goto no_firmware;
427 } 451 }
428 452
@@ -436,7 +460,8 @@ static int whiteheat_attach (struct usb_serial *serial)
436 460
437 info = kmalloc(sizeof(struct whiteheat_private), GFP_KERNEL); 461 info = kmalloc(sizeof(struct whiteheat_private), GFP_KERNEL);
438 if (info == NULL) { 462 if (info == NULL) {
439 err("%s: Out of memory for port structures\n", serial->type->description); 463 err("%s: Out of memory for port structures\n",
464 serial->type->description);
440 goto no_private; 465 goto no_private;
441 } 466 }
442 467
@@ -506,9 +531,11 @@ static int whiteheat_attach (struct usb_serial *serial)
506 usb_set_serial_port_data(port, info); 531 usb_set_serial_port_data(port, info);
507 } 532 }
508 533
509 command_info = kmalloc(sizeof(struct whiteheat_command_private), GFP_KERNEL); 534 command_info = kmalloc(sizeof(struct whiteheat_command_private),
535 GFP_KERNEL);
510 if (command_info == NULL) { 536 if (command_info == NULL) {
511 err("%s: Out of memory for port structures\n", serial->type->description); 537 err("%s: Out of memory for port structures\n",
538 serial->type->description);
512 goto no_command_private; 539 goto no_command_private;
513 } 540 }
514 541
@@ -525,9 +552,12 @@ static int whiteheat_attach (struct usb_serial *serial)
525 552
526no_firmware: 553no_firmware:
527 /* Firmware likely not running */ 554 /* Firmware likely not running */
528 err("%s: Unable to retrieve firmware version, try replugging\n", serial->type->description); 555 err("%s: Unable to retrieve firmware version, try replugging\n",
529 err("%s: If the firmware is not running (status led not blinking)\n", serial->type->description); 556 serial->type->description);
530 err("%s: please contact support@connecttech.com\n", serial->type->description); 557 err("%s: If the firmware is not running (status led not blinking)\n",
558 serial->type->description);
559 err("%s: please contact support@connecttech.com\n",
560 serial->type->description);
531 kfree(result); 561 kfree(result);
532 return -ENODEV; 562 return -ENODEV;
533 563
@@ -570,7 +600,7 @@ no_command_buffer:
570} 600}
571 601
572 602
573static void whiteheat_shutdown (struct usb_serial *serial) 603static void whiteheat_shutdown(struct usb_serial *serial)
574{ 604{
575 struct usb_serial_port *command_port; 605 struct usb_serial_port *command_port;
576 struct usb_serial_port *port; 606 struct usb_serial_port *port;
@@ -585,7 +615,7 @@ static void whiteheat_shutdown (struct usb_serial *serial)
585 615
586 /* free up our private data for our command port */ 616 /* free up our private data for our command port */
587 command_port = serial->port[COMMAND_PORT]; 617 command_port = serial->port[COMMAND_PORT];
588 kfree (usb_get_serial_port_data(command_port)); 618 kfree(usb_get_serial_port_data(command_port));
589 619
590 for (i = 0; i < serial->num_ports; i++) { 620 for (i = 0; i < serial->num_ports; i++) {
591 port = serial->port[i]; 621 port = serial->port[i];
@@ -612,11 +642,10 @@ static void whiteheat_shutdown (struct usb_serial *serial)
612 return; 642 return;
613} 643}
614 644
615 645static int whiteheat_open(struct tty_struct *tty,
616static int whiteheat_open (struct usb_serial_port *port, struct file *filp) 646 struct usb_serial_port *port, struct file *filp)
617{ 647{
618 int retval = 0; 648 int retval = 0;
619 struct ktermios old_term;
620 649
621 dbg("%s - port %d", __func__, port->number); 650 dbg("%s - port %d", __func__, port->number);
622 651
@@ -624,7 +653,8 @@ static int whiteheat_open (struct usb_serial_port *port, struct file *filp)
624 if (retval) 653 if (retval)
625 goto exit; 654 goto exit;
626 655
627 port->tty->low_latency = 1; 656 if (tty)
657 tty->low_latency = 1;
628 658
629 /* send an open port command */ 659 /* send an open port command */
630 retval = firm_open(port); 660 retval = firm_open(port);
@@ -640,9 +670,8 @@ static int whiteheat_open (struct usb_serial_port *port, struct file *filp)
640 goto exit; 670 goto exit;
641 } 671 }
642 672
643 old_term.c_cflag = ~port->tty->termios->c_cflag; 673 if (tty)
644 old_term.c_iflag = ~port->tty->termios->c_iflag; 674 firm_setup_port(tty);
645 whiteheat_set_termios(port, &old_term);
646 675
647 /* Work around HCD bugs */ 676 /* Work around HCD bugs */
648 usb_clear_halt(port->serial->dev, port->read_urb->pipe); 677 usb_clear_halt(port->serial->dev, port->read_urb->pipe);
@@ -651,7 +680,8 @@ static int whiteheat_open (struct usb_serial_port *port, struct file *filp)
651 /* Start reading from the device */ 680 /* Start reading from the device */
652 retval = start_port_read(port); 681 retval = start_port_read(port);
653 if (retval) { 682 if (retval) {
654 err("%s - failed submitting read urb, error %d", __func__, retval); 683 err("%s - failed submitting read urb, error %d",
684 __func__, retval);
655 firm_close(port); 685 firm_close(port);
656 stop_command_port(port->serial); 686 stop_command_port(port->serial);
657 goto exit; 687 goto exit;
@@ -663,7 +693,8 @@ exit:
663} 693}
664 694
665 695
666static void whiteheat_close(struct usb_serial_port *port, struct file * filp) 696static void whiteheat_close(struct tty_struct *tty,
697 struct usb_serial_port *port, struct file *filp)
667{ 698{
668 struct whiteheat_private *info = usb_get_serial_port_data(port); 699 struct whiteheat_private *info = usb_get_serial_port_data(port);
669 struct whiteheat_urb_wrap *wrap; 700 struct whiteheat_urb_wrap *wrap;
@@ -681,7 +712,7 @@ static void whiteheat_close(struct usb_serial_port *port, struct file * filp)
681 } 712 }
682 mutex_unlock(&port->serial->disc_mutex); 713 mutex_unlock(&port->serial->disc_mutex);
683 714
684 port->tty->closing = 1; 715 tty->closing = 1;
685 716
686/* 717/*
687 * Not currently in use; tty_wait_until_sent() calls 718 * Not currently in use; tty_wait_until_sent() calls
@@ -689,12 +720,12 @@ static void whiteheat_close(struct usb_serial_port *port, struct file * filp)
689 * acquisition. This should be fixed at some point. Greg's been 720 * acquisition. This should be fixed at some point. Greg's been
690 * notified. 721 * notified.
691 if ((filp->f_flags & (O_NDELAY | O_NONBLOCK)) == 0) { 722 if ((filp->f_flags & (O_NDELAY | O_NONBLOCK)) == 0) {
692 tty_wait_until_sent(port->tty, CLOSING_DELAY); 723 tty_wait_until_sent(tty, CLOSING_DELAY);
693 } 724 }
694*/ 725*/
695 726
696 tty_driver_flush_buffer(port->tty); 727 tty_driver_flush_buffer(tty);
697 tty_ldisc_flush(port->tty); 728 tty_ldisc_flush(tty);
698 729
699 firm_report_tx_done(port); 730 firm_report_tx_done(port);
700 731
@@ -728,11 +759,12 @@ static void whiteheat_close(struct usb_serial_port *port, struct file * filp)
728 759
729 stop_command_port(port->serial); 760 stop_command_port(port->serial);
730 761
731 port->tty->closing = 0; 762 tty->closing = 0;
732} 763}
733 764
734 765
735static int whiteheat_write(struct usb_serial_port *port, const unsigned char *buf, int count) 766static int whiteheat_write(struct tty_struct *tty,
767 struct usb_serial_port *port, const unsigned char *buf, int count)
736{ 768{
737 struct usb_serial *serial = port->serial; 769 struct usb_serial *serial = port->serial;
738 struct whiteheat_private *info = usb_get_serial_port_data(port); 770 struct whiteheat_private *info = usb_get_serial_port_data(port);
@@ -763,16 +795,19 @@ static int whiteheat_write(struct usb_serial_port *port, const unsigned char *bu
763 795
764 wrap = list_entry(tmp, struct whiteheat_urb_wrap, list); 796 wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
765 urb = wrap->urb; 797 urb = wrap->urb;
766 bytes = (count > port->bulk_out_size) ? port->bulk_out_size : count; 798 bytes = (count > port->bulk_out_size) ?
767 memcpy (urb->transfer_buffer, buf + sent, bytes); 799 port->bulk_out_size : count;
800 memcpy(urb->transfer_buffer, buf + sent, bytes);
768 801
769 usb_serial_debug_data(debug, &port->dev, __func__, bytes, urb->transfer_buffer); 802 usb_serial_debug_data(debug, &port->dev,
803 __func__, bytes, urb->transfer_buffer);
770 804
771 urb->dev = serial->dev; 805 urb->dev = serial->dev;
772 urb->transfer_buffer_length = bytes; 806 urb->transfer_buffer_length = bytes;
773 result = usb_submit_urb(urb, GFP_ATOMIC); 807 result = usb_submit_urb(urb, GFP_ATOMIC);
774 if (result) { 808 if (result) {
775 err("%s - failed submitting write urb, error %d", __func__, result); 809 err("%s - failed submitting write urb, error %d",
810 __func__, result);
776 sent = result; 811 sent = result;
777 spin_lock_irqsave(&info->lock, flags); 812 spin_lock_irqsave(&info->lock, flags);
778 list_add(tmp, &info->tx_urbs_free); 813 list_add(tmp, &info->tx_urbs_free);
@@ -790,16 +825,16 @@ static int whiteheat_write(struct usb_serial_port *port, const unsigned char *bu
790 return sent; 825 return sent;
791} 826}
792 827
793 828static int whiteheat_write_room(struct tty_struct *tty)
794static int whiteheat_write_room(struct usb_serial_port *port)
795{ 829{
830 struct usb_serial_port *port = tty->driver_data;
796 struct whiteheat_private *info = usb_get_serial_port_data(port); 831 struct whiteheat_private *info = usb_get_serial_port_data(port);
797 struct list_head *tmp; 832 struct list_head *tmp;
798 int room = 0; 833 int room = 0;
799 unsigned long flags; 834 unsigned long flags;
800 835
801 dbg("%s - port %d", __func__, port->number); 836 dbg("%s - port %d", __func__, port->number);
802 837
803 spin_lock_irqsave(&info->lock, flags); 838 spin_lock_irqsave(&info->lock, flags);
804 list_for_each(tmp, &info->tx_urbs_free) 839 list_for_each(tmp, &info->tx_urbs_free)
805 room++; 840 room++;
@@ -810,9 +845,9 @@ static int whiteheat_write_room(struct usb_serial_port *port)
810 return (room); 845 return (room);
811} 846}
812 847
813 848static int whiteheat_tiocmget(struct tty_struct *tty, struct file *file)
814static int whiteheat_tiocmget (struct usb_serial_port *port, struct file *file)
815{ 849{
850 struct usb_serial_port *port = tty->driver_data;
816 struct whiteheat_private *info = usb_get_serial_port_data(port); 851 struct whiteheat_private *info = usb_get_serial_port_data(port);
817 unsigned int modem_signals = 0; 852 unsigned int modem_signals = 0;
818 853
@@ -827,10 +862,10 @@ static int whiteheat_tiocmget (struct usb_serial_port *port, struct file *file)
827 return modem_signals; 862 return modem_signals;
828} 863}
829 864
830 865static int whiteheat_tiocmset(struct tty_struct *tty, struct file *file,
831static int whiteheat_tiocmset (struct usb_serial_port *port, struct file *file,
832 unsigned int set, unsigned int clear) 866 unsigned int set, unsigned int clear)
833{ 867{
868 struct usb_serial_port *port = tty->driver_data;
834 struct whiteheat_private *info = usb_get_serial_port_data(port); 869 struct whiteheat_private *info = usb_get_serial_port_data(port);
835 870
836 dbg("%s - port %d", __func__, port->number); 871 dbg("%s - port %d", __func__, port->number);
@@ -851,65 +886,55 @@ static int whiteheat_tiocmset (struct usb_serial_port *port, struct file *file,
851} 886}
852 887
853 888
854static int whiteheat_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg) 889static int whiteheat_ioctl(struct tty_struct *tty, struct file *file,
890 unsigned int cmd, unsigned long arg)
855{ 891{
892 struct usb_serial_port *port = tty->driver_data;
856 struct serial_struct serstruct; 893 struct serial_struct serstruct;
857 void __user *user_arg = (void __user *)arg; 894 void __user *user_arg = (void __user *)arg;
858 895
859 dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd); 896 dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd);
860 897
861 switch (cmd) { 898 switch (cmd) {
862 case TIOCGSERIAL: 899 case TIOCGSERIAL:
863 memset(&serstruct, 0, sizeof(serstruct)); 900 memset(&serstruct, 0, sizeof(serstruct));
864 serstruct.type = PORT_16654; 901 serstruct.type = PORT_16654;
865 serstruct.line = port->serial->minor; 902 serstruct.line = port->serial->minor;
866 serstruct.port = port->number; 903 serstruct.port = port->number;
867 serstruct.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ; 904 serstruct.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
868 serstruct.xmit_fifo_size = port->bulk_out_size; 905 serstruct.xmit_fifo_size = port->bulk_out_size;
869 serstruct.custom_divisor = 0; 906 serstruct.custom_divisor = 0;
870 serstruct.baud_base = 460800; 907 serstruct.baud_base = 460800;
871 serstruct.close_delay = CLOSING_DELAY; 908 serstruct.close_delay = CLOSING_DELAY;
872 serstruct.closing_wait = CLOSING_DELAY; 909 serstruct.closing_wait = CLOSING_DELAY;
873 910
874 if (copy_to_user(user_arg, &serstruct, sizeof(serstruct))) 911 if (copy_to_user(user_arg, &serstruct, sizeof(serstruct)))
875 return -EFAULT; 912 return -EFAULT;
876 913 break;
877 break; 914 default:
878 915 break;
879 case TIOCSSERIAL:
880 if (copy_from_user(&serstruct, user_arg, sizeof(serstruct)))
881 return -EFAULT;
882
883 /*
884 * For now this is ignored. dip sets the ASYNC_[V]HI flags
885 * but this isn't used by us at all. Maybe someone somewhere
886 * will need the custom_divisor setting.
887 */
888
889 break;
890
891 default:
892 break;
893 } 916 }
894 917
895 return -ENOIOCTLCMD; 918 return -ENOIOCTLCMD;
896} 919}
897 920
898 921
899static void whiteheat_set_termios(struct usb_serial_port *port, struct ktermios *old_termios) 922static void whiteheat_set_termios(struct tty_struct *tty,
923 struct usb_serial_port *port, struct ktermios *old_termios)
900{ 924{
901 dbg("%s -port %d", __func__, port->number); 925 firm_setup_port(tty);
902 firm_setup_port(port);
903} 926}
904 927
905 928static void whiteheat_break_ctl(struct tty_struct *tty, int break_state)
906static void whiteheat_break_ctl(struct usb_serial_port *port, int break_state) { 929{
930 struct usb_serial_port *port = tty->driver_data;
907 firm_set_break(port, break_state); 931 firm_set_break(port, break_state);
908} 932}
909 933
910 934
911static int whiteheat_chars_in_buffer(struct usb_serial_port *port) 935static int whiteheat_chars_in_buffer(struct tty_struct *tty)
912{ 936{
937 struct usb_serial_port *port = tty->driver_data;
913 struct whiteheat_private *info = usb_get_serial_port_data(port); 938 struct whiteheat_private *info = usb_get_serial_port_data(port);
914 struct list_head *tmp; 939 struct list_head *tmp;
915 struct whiteheat_urb_wrap *wrap; 940 struct whiteheat_urb_wrap *wrap;
@@ -925,13 +950,14 @@ static int whiteheat_chars_in_buffer(struct usb_serial_port *port)
925 } 950 }
926 spin_unlock_irqrestore(&info->lock, flags); 951 spin_unlock_irqrestore(&info->lock, flags);
927 952
928 dbg ("%s - returns %d", __func__, chars); 953 dbg("%s - returns %d", __func__, chars);
929 return chars; 954 return chars;
930} 955}
931 956
932 957
933static void whiteheat_throttle (struct usb_serial_port *port) 958static void whiteheat_throttle(struct tty_struct *tty)
934{ 959{
960 struct usb_serial_port *port = tty->driver_data;
935 struct whiteheat_private *info = usb_get_serial_port_data(port); 961 struct whiteheat_private *info = usb_get_serial_port_data(port);
936 unsigned long flags; 962 unsigned long flags;
937 963
@@ -945,8 +971,9 @@ static void whiteheat_throttle (struct usb_serial_port *port)
945} 971}
946 972
947 973
948static void whiteheat_unthrottle (struct usb_serial_port *port) 974static void whiteheat_unthrottle(struct tty_struct *tty)
949{ 975{
976 struct usb_serial_port *port = tty->driver_data;
950 struct whiteheat_private *info = usb_get_serial_port_data(port); 977 struct whiteheat_private *info = usb_get_serial_port_data(port);
951 int actually_throttled; 978 int actually_throttled;
952 unsigned long flags; 979 unsigned long flags;
@@ -993,7 +1020,7 @@ static void command_port_read_callback(struct urb *urb)
993 1020
994 command_info = usb_get_serial_port_data(command_port); 1021 command_info = usb_get_serial_port_data(command_port);
995 if (!command_info) { 1022 if (!command_info) {
996 dbg ("%s - command_info is NULL, exiting.", __func__); 1023 dbg("%s - command_info is NULL, exiting.", __func__);
997 return; 1024 return;
998 } 1025 }
999 if (status) { 1026 if (status) {
@@ -1004,7 +1031,8 @@ static void command_port_read_callback(struct urb *urb)
1004 return; 1031 return;
1005 } 1032 }
1006 1033
1007 usb_serial_debug_data(debug, &command_port->dev, __func__, urb->actual_length, data); 1034 usb_serial_debug_data(debug, &command_port->dev,
1035 __func__, urb->actual_length, data);
1008 1036
1009 if (data[0] == WHITEHEAT_CMD_COMPLETE) { 1037 if (data[0] == WHITEHEAT_CMD_COMPLETE) {
1010 command_info->command_finished = WHITEHEAT_CMD_COMPLETE; 1038 command_info->command_finished = WHITEHEAT_CMD_COMPLETE;
@@ -1013,21 +1041,23 @@ static void command_port_read_callback(struct urb *urb)
1013 command_info->command_finished = WHITEHEAT_CMD_FAILURE; 1041 command_info->command_finished = WHITEHEAT_CMD_FAILURE;
1014 wake_up(&command_info->wait_command); 1042 wake_up(&command_info->wait_command);
1015 } else if (data[0] == WHITEHEAT_EVENT) { 1043 } else if (data[0] == WHITEHEAT_EVENT) {
1016 /* These are unsolicited reports from the firmware, hence no waiting command to wakeup */ 1044 /* These are unsolicited reports from the firmware, hence no
1045 waiting command to wakeup */
1017 dbg("%s - event received", __func__); 1046 dbg("%s - event received", __func__);
1018 } else if (data[0] == WHITEHEAT_GET_DTR_RTS) { 1047 } else if (data[0] == WHITEHEAT_GET_DTR_RTS) {
1019 memcpy(command_info->result_buffer, &data[1], urb->actual_length - 1); 1048 memcpy(command_info->result_buffer, &data[1],
1049 urb->actual_length - 1);
1020 command_info->command_finished = WHITEHEAT_CMD_COMPLETE; 1050 command_info->command_finished = WHITEHEAT_CMD_COMPLETE;
1021 wake_up(&command_info->wait_command); 1051 wake_up(&command_info->wait_command);
1022 } else { 1052 } else
1023 dbg("%s - bad reply from firmware", __func__); 1053 dbg("%s - bad reply from firmware", __func__);
1024 } 1054
1025
1026 /* Continue trying to always read */ 1055 /* Continue trying to always read */
1027 command_port->read_urb->dev = command_port->serial->dev; 1056 command_port->read_urb->dev = command_port->serial->dev;
1028 result = usb_submit_urb(command_port->read_urb, GFP_ATOMIC); 1057 result = usb_submit_urb(command_port->read_urb, GFP_ATOMIC);
1029 if (result) 1058 if (result)
1030 dbg("%s - failed resubmitting read urb, error %d", __func__, result); 1059 dbg("%s - failed resubmitting read urb, error %d",
1060 __func__, result);
1031} 1061}
1032 1062
1033 1063
@@ -1060,7 +1090,8 @@ static void whiteheat_read_callback(struct urb *urb)
1060 return; 1090 return;
1061 } 1091 }
1062 1092
1063 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); 1093 usb_serial_debug_data(debug, &port->dev,
1094 __func__, urb->actual_length, data);
1064 1095
1065 spin_lock(&info->lock); 1096 spin_lock(&info->lock);
1066 list_add_tail(&wrap->list, &info->rx_urb_q); 1097 list_add_tail(&wrap->list, &info->rx_urb_q);
@@ -1107,7 +1138,8 @@ static void whiteheat_write_callback(struct urb *urb)
1107/***************************************************************************** 1138/*****************************************************************************
1108 * Connect Tech's White Heat firmware interface 1139 * Connect Tech's White Heat firmware interface
1109 *****************************************************************************/ 1140 *****************************************************************************/
1110static int firm_send_command(struct usb_serial_port *port, __u8 command, __u8 *data, __u8 datasize) 1141static int firm_send_command(struct usb_serial_port *port, __u8 command,
1142 __u8 *data, __u8 datasize)
1111{ 1143{
1112 struct usb_serial_port *command_port; 1144 struct usb_serial_port *command_port;
1113 struct whiteheat_command_private *command_info; 1145 struct whiteheat_command_private *command_info;
@@ -1122,13 +1154,13 @@ static int firm_send_command(struct usb_serial_port *port, __u8 command, __u8 *d
1122 command_info = usb_get_serial_port_data(command_port); 1154 command_info = usb_get_serial_port_data(command_port);
1123 mutex_lock(&command_info->mutex); 1155 mutex_lock(&command_info->mutex);
1124 command_info->command_finished = false; 1156 command_info->command_finished = false;
1125 1157
1126 transfer_buffer = (__u8 *)command_port->write_urb->transfer_buffer; 1158 transfer_buffer = (__u8 *)command_port->write_urb->transfer_buffer;
1127 transfer_buffer[0] = command; 1159 transfer_buffer[0] = command;
1128 memcpy (&transfer_buffer[1], data, datasize); 1160 memcpy(&transfer_buffer[1], data, datasize);
1129 command_port->write_urb->transfer_buffer_length = datasize + 1; 1161 command_port->write_urb->transfer_buffer_length = datasize + 1;
1130 command_port->write_urb->dev = port->serial->dev; 1162 command_port->write_urb->dev = port->serial->dev;
1131 retval = usb_submit_urb (command_port->write_urb, GFP_NOIO); 1163 retval = usb_submit_urb(command_port->write_urb, GFP_NOIO);
1132 if (retval) { 1164 if (retval) {
1133 dbg("%s - submit urb failed", __func__); 1165 dbg("%s - submit urb failed", __func__);
1134 goto exit; 1166 goto exit;
@@ -1155,51 +1187,57 @@ static int firm_send_command(struct usb_serial_port *port, __u8 command, __u8 *d
1155 if (command_info->command_finished == WHITEHEAT_CMD_COMPLETE) { 1187 if (command_info->command_finished == WHITEHEAT_CMD_COMPLETE) {
1156 dbg("%s - command completed.", __func__); 1188 dbg("%s - command completed.", __func__);
1157 switch (command) { 1189 switch (command) {
1158 case WHITEHEAT_GET_DTR_RTS: 1190 case WHITEHEAT_GET_DTR_RTS:
1159 info = usb_get_serial_port_data(port); 1191 info = usb_get_serial_port_data(port);
1160 memcpy(&info->mcr, command_info->result_buffer, sizeof(struct whiteheat_dr_info)); 1192 memcpy(&info->mcr, command_info->result_buffer,
1193 sizeof(struct whiteheat_dr_info));
1161 break; 1194 break;
1162 } 1195 }
1163 } 1196 }
1164
1165exit: 1197exit:
1166 mutex_unlock(&command_info->mutex); 1198 mutex_unlock(&command_info->mutex);
1167 return retval; 1199 return retval;
1168} 1200}
1169 1201
1170 1202
1171static int firm_open(struct usb_serial_port *port) { 1203static int firm_open(struct usb_serial_port *port)
1204{
1172 struct whiteheat_simple open_command; 1205 struct whiteheat_simple open_command;
1173 1206
1174 open_command.port = port->number - port->serial->minor + 1; 1207 open_command.port = port->number - port->serial->minor + 1;
1175 return firm_send_command(port, WHITEHEAT_OPEN, (__u8 *)&open_command, sizeof(open_command)); 1208 return firm_send_command(port, WHITEHEAT_OPEN,
1209 (__u8 *)&open_command, sizeof(open_command));
1176} 1210}
1177 1211
1178 1212
1179static int firm_close(struct usb_serial_port *port) { 1213static int firm_close(struct usb_serial_port *port)
1214{
1180 struct whiteheat_simple close_command; 1215 struct whiteheat_simple close_command;
1181 1216
1182 close_command.port = port->number - port->serial->minor + 1; 1217 close_command.port = port->number - port->serial->minor + 1;
1183 return firm_send_command(port, WHITEHEAT_CLOSE, (__u8 *)&close_command, sizeof(close_command)); 1218 return firm_send_command(port, WHITEHEAT_CLOSE,
1219 (__u8 *)&close_command, sizeof(close_command));
1184} 1220}
1185 1221
1186 1222
1187static int firm_setup_port(struct usb_serial_port *port) { 1223static int firm_setup_port(struct tty_struct *tty)
1224{
1225 struct usb_serial_port *port = tty->driver_data;
1188 struct whiteheat_port_settings port_settings; 1226 struct whiteheat_port_settings port_settings;
1189 unsigned int cflag = port->tty->termios->c_cflag; 1227 unsigned int cflag = tty->termios->c_cflag;
1190 1228
1191 port_settings.port = port->number + 1; 1229 port_settings.port = port->number + 1;
1192 1230
1193 /* get the byte size */ 1231 /* get the byte size */
1194 switch (cflag & CSIZE) { 1232 switch (cflag & CSIZE) {
1195 case CS5: port_settings.bits = 5; break; 1233 case CS5: port_settings.bits = 5; break;
1196 case CS6: port_settings.bits = 6; break; 1234 case CS6: port_settings.bits = 6; break;
1197 case CS7: port_settings.bits = 7; break; 1235 case CS7: port_settings.bits = 7; break;
1198 default: 1236 default:
1199 case CS8: port_settings.bits = 8; break; 1237 case CS8: port_settings.bits = 8; break;
1200 } 1238 }
1201 dbg("%s - data bits = %d", __func__, port_settings.bits); 1239 dbg("%s - data bits = %d", __func__, port_settings.bits);
1202 1240
1203 /* determine the parity */ 1241 /* determine the parity */
1204 if (cflag & PARENB) 1242 if (cflag & PARENB)
1205 if (cflag & CMSPAR) 1243 if (cflag & CMSPAR)
@@ -1225,7 +1263,8 @@ static int firm_setup_port(struct usb_serial_port *port) {
1225 1263
1226 /* figure out the flow control settings */ 1264 /* figure out the flow control settings */
1227 if (cflag & CRTSCTS) 1265 if (cflag & CRTSCTS)
1228 port_settings.hflow = (WHITEHEAT_HFLOW_CTS | WHITEHEAT_HFLOW_RTS); 1266 port_settings.hflow = (WHITEHEAT_HFLOW_CTS |
1267 WHITEHEAT_HFLOW_RTS);
1229 else 1268 else
1230 port_settings.hflow = WHITEHEAT_HFLOW_NONE; 1269 port_settings.hflow = WHITEHEAT_HFLOW_NONE;
1231 dbg("%s - hardware flow control = %s %s %s %s", __func__, 1270 dbg("%s - hardware flow control = %s %s %s %s", __func__,
@@ -1233,81 +1272,95 @@ static int firm_setup_port(struct usb_serial_port *port) {
1233 (port_settings.hflow & WHITEHEAT_HFLOW_RTS) ? "RTS" : "", 1272 (port_settings.hflow & WHITEHEAT_HFLOW_RTS) ? "RTS" : "",
1234 (port_settings.hflow & WHITEHEAT_HFLOW_DSR) ? "DSR" : "", 1273 (port_settings.hflow & WHITEHEAT_HFLOW_DSR) ? "DSR" : "",
1235 (port_settings.hflow & WHITEHEAT_HFLOW_DTR) ? "DTR" : ""); 1274 (port_settings.hflow & WHITEHEAT_HFLOW_DTR) ? "DTR" : "");
1236 1275
1237 /* determine software flow control */ 1276 /* determine software flow control */
1238 if (I_IXOFF(port->tty)) 1277 if (I_IXOFF(tty))
1239 port_settings.sflow = WHITEHEAT_SFLOW_RXTX; 1278 port_settings.sflow = WHITEHEAT_SFLOW_RXTX;
1240 else 1279 else
1241 port_settings.sflow = WHITEHEAT_SFLOW_NONE; 1280 port_settings.sflow = WHITEHEAT_SFLOW_NONE;
1242 dbg("%s - software flow control = %c", __func__, port_settings.sflow); 1281 dbg("%s - software flow control = %c", __func__, port_settings.sflow);
1243 1282
1244 port_settings.xon = START_CHAR(port->tty); 1283 port_settings.xon = START_CHAR(tty);
1245 port_settings.xoff = STOP_CHAR(port->tty); 1284 port_settings.xoff = STOP_CHAR(tty);
1246 dbg("%s - XON = %2x, XOFF = %2x", __func__, port_settings.xon, port_settings.xoff); 1285 dbg("%s - XON = %2x, XOFF = %2x",
1286 __func__, port_settings.xon, port_settings.xoff);
1247 1287
1248 /* get the baud rate wanted */ 1288 /* get the baud rate wanted */
1249 port_settings.baud = tty_get_baud_rate(port->tty); 1289 port_settings.baud = tty_get_baud_rate(tty);
1250 dbg("%s - baud rate = %d", __func__, port_settings.baud); 1290 dbg("%s - baud rate = %d", __func__, port_settings.baud);
1251 1291
1252 /* fixme: should set validated settings */ 1292 /* fixme: should set validated settings */
1253 tty_encode_baud_rate(port->tty, port_settings.baud, port_settings.baud); 1293 tty_encode_baud_rate(tty, port_settings.baud, port_settings.baud);
1254 /* handle any settings that aren't specified in the tty structure */ 1294 /* handle any settings that aren't specified in the tty structure */
1255 port_settings.lloop = 0; 1295 port_settings.lloop = 0;
1256 1296
1257 /* now send the message to the device */ 1297 /* now send the message to the device */
1258 return firm_send_command(port, WHITEHEAT_SETUP_PORT, (__u8 *)&port_settings, sizeof(port_settings)); 1298 return firm_send_command(port, WHITEHEAT_SETUP_PORT,
1299 (__u8 *)&port_settings, sizeof(port_settings));
1259} 1300}
1260 1301
1261 1302
1262static int firm_set_rts(struct usb_serial_port *port, __u8 onoff) { 1303static int firm_set_rts(struct usb_serial_port *port, __u8 onoff)
1304{
1263 struct whiteheat_set_rdb rts_command; 1305 struct whiteheat_set_rdb rts_command;
1264 1306
1265 rts_command.port = port->number - port->serial->minor + 1; 1307 rts_command.port = port->number - port->serial->minor + 1;
1266 rts_command.state = onoff; 1308 rts_command.state = onoff;
1267 return firm_send_command(port, WHITEHEAT_SET_RTS, (__u8 *)&rts_command, sizeof(rts_command)); 1309 return firm_send_command(port, WHITEHEAT_SET_RTS,
1310 (__u8 *)&rts_command, sizeof(rts_command));
1268} 1311}
1269 1312
1270 1313
1271static int firm_set_dtr(struct usb_serial_port *port, __u8 onoff) { 1314static int firm_set_dtr(struct usb_serial_port *port, __u8 onoff)
1315{
1272 struct whiteheat_set_rdb dtr_command; 1316 struct whiteheat_set_rdb dtr_command;
1273 1317
1274 dtr_command.port = port->number - port->serial->minor + 1; 1318 dtr_command.port = port->number - port->serial->minor + 1;
1275 dtr_command.state = onoff; 1319 dtr_command.state = onoff;
1276 return firm_send_command(port, WHITEHEAT_SET_RTS, (__u8 *)&dtr_command, sizeof(dtr_command)); 1320 return firm_send_command(port, WHITEHEAT_SET_DTR,
1321 (__u8 *)&dtr_command, sizeof(dtr_command));
1277} 1322}
1278 1323
1279 1324
1280static int firm_set_break(struct usb_serial_port *port, __u8 onoff) { 1325static int firm_set_break(struct usb_serial_port *port, __u8 onoff)
1326{
1281 struct whiteheat_set_rdb break_command; 1327 struct whiteheat_set_rdb break_command;
1282 1328
1283 break_command.port = port->number - port->serial->minor + 1; 1329 break_command.port = port->number - port->serial->minor + 1;
1284 break_command.state = onoff; 1330 break_command.state = onoff;
1285 return firm_send_command(port, WHITEHEAT_SET_RTS, (__u8 *)&break_command, sizeof(break_command)); 1331 return firm_send_command(port, WHITEHEAT_SET_BREAK,
1332 (__u8 *)&break_command, sizeof(break_command));
1286} 1333}
1287 1334
1288 1335
1289static int firm_purge(struct usb_serial_port *port, __u8 rxtx) { 1336static int firm_purge(struct usb_serial_port *port, __u8 rxtx)
1337{
1290 struct whiteheat_purge purge_command; 1338 struct whiteheat_purge purge_command;
1291 1339
1292 purge_command.port = port->number - port->serial->minor + 1; 1340 purge_command.port = port->number - port->serial->minor + 1;
1293 purge_command.what = rxtx; 1341 purge_command.what = rxtx;
1294 return firm_send_command(port, WHITEHEAT_PURGE, (__u8 *)&purge_command, sizeof(purge_command)); 1342 return firm_send_command(port, WHITEHEAT_PURGE,
1343 (__u8 *)&purge_command, sizeof(purge_command));
1295} 1344}
1296 1345
1297 1346
1298static int firm_get_dtr_rts(struct usb_serial_port *port) { 1347static int firm_get_dtr_rts(struct usb_serial_port *port)
1348{
1299 struct whiteheat_simple get_dr_command; 1349 struct whiteheat_simple get_dr_command;
1300 1350
1301 get_dr_command.port = port->number - port->serial->minor + 1; 1351 get_dr_command.port = port->number - port->serial->minor + 1;
1302 return firm_send_command(port, WHITEHEAT_GET_DTR_RTS, (__u8 *)&get_dr_command, sizeof(get_dr_command)); 1352 return firm_send_command(port, WHITEHEAT_GET_DTR_RTS,
1353 (__u8 *)&get_dr_command, sizeof(get_dr_command));
1303} 1354}
1304 1355
1305 1356
1306static int firm_report_tx_done(struct usb_serial_port *port) { 1357static int firm_report_tx_done(struct usb_serial_port *port)
1358{
1307 struct whiteheat_simple close_command; 1359 struct whiteheat_simple close_command;
1308 1360
1309 close_command.port = port->number - port->serial->minor + 1; 1361 close_command.port = port->number - port->serial->minor + 1;
1310 return firm_send_command(port, WHITEHEAT_REPORT_TX_DONE, (__u8 *)&close_command, sizeof(close_command)); 1362 return firm_send_command(port, WHITEHEAT_REPORT_TX_DONE,
1363 (__u8 *)&close_command, sizeof(close_command));
1311} 1364}
1312 1365
1313 1366
@@ -1319,7 +1372,7 @@ static int start_command_port(struct usb_serial *serial)
1319 struct usb_serial_port *command_port; 1372 struct usb_serial_port *command_port;
1320 struct whiteheat_command_private *command_info; 1373 struct whiteheat_command_private *command_info;
1321 int retval = 0; 1374 int retval = 0;
1322 1375
1323 command_port = serial->port[COMMAND_PORT]; 1376 command_port = serial->port[COMMAND_PORT];
1324 command_info = usb_get_serial_port_data(command_port); 1377 command_info = usb_get_serial_port_data(command_port);
1325 mutex_lock(&command_info->mutex); 1378 mutex_lock(&command_info->mutex);
@@ -1330,7 +1383,8 @@ static int start_command_port(struct usb_serial *serial)
1330 command_port->read_urb->dev = serial->dev; 1383 command_port->read_urb->dev = serial->dev;
1331 retval = usb_submit_urb(command_port->read_urb, GFP_KERNEL); 1384 retval = usb_submit_urb(command_port->read_urb, GFP_KERNEL);
1332 if (retval) { 1385 if (retval) {
1333 err("%s - failed submitting read urb, error %d", __func__, retval); 1386 err("%s - failed submitting read urb, error %d",
1387 __func__, retval);
1334 goto exit; 1388 goto exit;
1335 } 1389 }
1336 } 1390 }
@@ -1400,7 +1454,8 @@ static int start_port_read(struct usb_serial_port *port)
1400} 1454}
1401 1455
1402 1456
1403static struct whiteheat_urb_wrap *urb_to_wrap(struct urb* urb, struct list_head *head) 1457static struct whiteheat_urb_wrap *urb_to_wrap(struct urb *urb,
1458 struct list_head *head)
1404{ 1459{
1405 struct whiteheat_urb_wrap *wrap; 1460 struct whiteheat_urb_wrap *wrap;
1406 struct list_head *tmp; 1461 struct list_head *tmp;
@@ -1426,7 +1481,7 @@ static void rx_data_softint(struct work_struct *work)
1426 struct whiteheat_private *info = 1481 struct whiteheat_private *info =
1427 container_of(work, struct whiteheat_private, rx_work); 1482 container_of(work, struct whiteheat_private, rx_work);
1428 struct usb_serial_port *port = info->port; 1483 struct usb_serial_port *port = info->port;
1429 struct tty_struct *tty = port->tty; 1484 struct tty_struct *tty = port->port.tty;
1430 struct whiteheat_urb_wrap *wrap; 1485 struct whiteheat_urb_wrap *wrap;
1431 struct urb *urb; 1486 struct urb *urb;
1432 unsigned long flags; 1487 unsigned long flags;
@@ -1449,7 +1504,8 @@ static void rx_data_softint(struct work_struct *work)
1449 urb = wrap->urb; 1504 urb = wrap->urb;
1450 1505
1451 if (tty && urb->actual_length) { 1506 if (tty && urb->actual_length) {
1452 int len = tty_buffer_request_room(tty, urb->actual_length); 1507 int len = tty_buffer_request_room(tty,
1508 urb->actual_length);
1453 /* This stuff can go away now I suspect */ 1509 /* This stuff can go away now I suspect */
1454 if (unlikely(len < urb->actual_length)) { 1510 if (unlikely(len < urb->actual_length)) {
1455 spin_lock_irqsave(&info->lock, flags); 1511 spin_lock_irqsave(&info->lock, flags);
@@ -1466,7 +1522,8 @@ static void rx_data_softint(struct work_struct *work)
1466 urb->dev = port->serial->dev; 1522 urb->dev = port->serial->dev;
1467 result = usb_submit_urb(urb, GFP_ATOMIC); 1523 result = usb_submit_urb(urb, GFP_ATOMIC);
1468 if (result) { 1524 if (result) {
1469 err("%s - failed resubmitting read urb, error %d", __func__, result); 1525 err("%s - failed resubmitting read urb, error %d",
1526 __func__, result);
1470 spin_lock_irqsave(&info->lock, flags); 1527 spin_lock_irqsave(&info->lock, flags);
1471 list_add(tmp, &info->rx_urbs_free); 1528 list_add(tmp, &info->rx_urbs_free);
1472 continue; 1529 continue;
@@ -1485,7 +1542,7 @@ static void rx_data_softint(struct work_struct *work)
1485/***************************************************************************** 1542/*****************************************************************************
1486 * Connect Tech's White Heat module functions 1543 * Connect Tech's White Heat module functions
1487 *****************************************************************************/ 1544 *****************************************************************************/
1488static int __init whiteheat_init (void) 1545static int __init whiteheat_init(void)
1489{ 1546{
1490 int retval; 1547 int retval;
1491 retval = usb_serial_register(&whiteheat_fake_device); 1548 retval = usb_serial_register(&whiteheat_fake_device);
@@ -1508,19 +1565,19 @@ failed_fake_register:
1508} 1565}
1509 1566
1510 1567
1511static void __exit whiteheat_exit (void) 1568static void __exit whiteheat_exit(void)
1512{ 1569{
1513 usb_deregister (&whiteheat_driver); 1570 usb_deregister(&whiteheat_driver);
1514 usb_serial_deregister (&whiteheat_fake_device); 1571 usb_serial_deregister(&whiteheat_fake_device);
1515 usb_serial_deregister (&whiteheat_device); 1572 usb_serial_deregister(&whiteheat_device);
1516} 1573}
1517 1574
1518 1575
1519module_init(whiteheat_init); 1576module_init(whiteheat_init);
1520module_exit(whiteheat_exit); 1577module_exit(whiteheat_exit);
1521 1578
1522MODULE_AUTHOR( DRIVER_AUTHOR ); 1579MODULE_AUTHOR(DRIVER_AUTHOR);
1523MODULE_DESCRIPTION( DRIVER_DESC ); 1580MODULE_DESCRIPTION(DRIVER_DESC);
1524MODULE_LICENSE("GPL"); 1581MODULE_LICENSE("GPL");
1525 1582
1526MODULE_FIRMWARE("whiteheat.fw"); 1583MODULE_FIRMWARE("whiteheat.fw");
diff --git a/drivers/usb/serial/whiteheat.h b/drivers/usb/serial/whiteheat.h
index f16079705664..38065df4d2d8 100644
--- a/drivers/usb/serial/whiteheat.h
+++ b/drivers/usb/serial/whiteheat.h
@@ -2,7 +2,7 @@
2 * USB ConnectTech WhiteHEAT driver 2 * USB ConnectTech WhiteHEAT driver
3 * 3 *
4 * Copyright (C) 2002 4 * Copyright (C) 2002
5 * Connect Tech Inc. 5 * Connect Tech Inc.
6 * 6 *
7 * Copyright (C) 1999, 2000 7 * Copyright (C) 1999, 2000
8 * Greg Kroah-Hartman (greg@kroah.com) 8 * Greg Kroah-Hartman (greg@kroah.com)
@@ -12,7 +12,8 @@
12 * the Free Software Foundation; either version 2 of the License, or 12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. 13 * (at your option) any later version.
14 * 14 *
15 * See Documentation/usb/usb-serial.txt for more information on using this driver 15 * See Documentation/usb/usb-serial.txt for more information on using this
16 * driver
16 * 17 *
17 */ 18 */
18 19
@@ -30,13 +31,16 @@
30#define WHITEHEAT_DUMP 7 /* dump memory */ 31#define WHITEHEAT_DUMP 7 /* dump memory */
31#define WHITEHEAT_STATUS 8 /* get status */ 32#define WHITEHEAT_STATUS 8 /* get status */
32#define WHITEHEAT_PURGE 9 /* clear the UART fifos */ 33#define WHITEHEAT_PURGE 9 /* clear the UART fifos */
33#define WHITEHEAT_GET_DTR_RTS 10 /* get the state of DTR and RTS for a port */ 34#define WHITEHEAT_GET_DTR_RTS 10 /* get the state of DTR and RTS
34#define WHITEHEAT_GET_HW_INFO 11 /* get EEPROM info and hardware ID */ 35 for a port */
36#define WHITEHEAT_GET_HW_INFO 11 /* get EEPROM info and
37 hardware ID */
35#define WHITEHEAT_REPORT_TX_DONE 12 /* get the next TX done */ 38#define WHITEHEAT_REPORT_TX_DONE 12 /* get the next TX done */
36#define WHITEHEAT_EVENT 13 /* unsolicited status events */ 39#define WHITEHEAT_EVENT 13 /* unsolicited status events */
37#define WHITEHEAT_ECHO 14 /* send data to the indicated IN endpoint */ 40#define WHITEHEAT_ECHO 14 /* send data to the indicated
38#define WHITEHEAT_DO_TEST 15 /* perform the specified test */ 41 IN endpoint */
39#define WHITEHEAT_CMD_COMPLETE 16 /* reply for certain commands */ 42#define WHITEHEAT_DO_TEST 15 /* perform specified test */
43#define WHITEHEAT_CMD_COMPLETE 16 /* reply for some commands */
40#define WHITEHEAT_CMD_FAILURE 17 /* reply for failed commands */ 44#define WHITEHEAT_CMD_FAILURE 17 /* reply for failed commands */
41 45
42 46
@@ -67,20 +71,28 @@ struct whiteheat_simple {
67#define WHITEHEAT_PAR_MARK '1' /* mark (force 1) parity */ 71#define WHITEHEAT_PAR_MARK '1' /* mark (force 1) parity */
68 72
69#define WHITEHEAT_SFLOW_NONE 'n' /* no software flow control */ 73#define WHITEHEAT_SFLOW_NONE 'n' /* no software flow control */
70#define WHITEHEAT_SFLOW_RX 'r' /* XOFF/ON is sent when RX fills/empties */ 74#define WHITEHEAT_SFLOW_RX 'r' /* XOFF/ON is sent when RX
71#define WHITEHEAT_SFLOW_TX 't' /* when received XOFF/ON will stop/start TX */ 75 fills/empties */
76#define WHITEHEAT_SFLOW_TX 't' /* when received XOFF/ON will
77 stop/start TX */
72#define WHITEHEAT_SFLOW_RXTX 'b' /* both SFLOW_RX and SFLOW_TX */ 78#define WHITEHEAT_SFLOW_RXTX 'b' /* both SFLOW_RX and SFLOW_TX */
73 79
74#define WHITEHEAT_HFLOW_NONE 0x00 /* no hardware flow control */ 80#define WHITEHEAT_HFLOW_NONE 0x00 /* no hardware flow control */
75#define WHITEHEAT_HFLOW_RTS_TOGGLE 0x01 /* RTS is on during transmit, off otherwise */ 81#define WHITEHEAT_HFLOW_RTS_TOGGLE 0x01 /* RTS is on during transmit,
76#define WHITEHEAT_HFLOW_DTR 0x02 /* DTR is off/on when RX fills/empties */ 82 off otherwise */
77#define WHITEHEAT_HFLOW_CTS 0x08 /* when received CTS off/on will stop/start TX */ 83#define WHITEHEAT_HFLOW_DTR 0x02 /* DTR is off/on when RX
78#define WHITEHEAT_HFLOW_DSR 0x10 /* when received DSR off/on will stop/start TX */ 84 fills/empties */
79#define WHITEHEAT_HFLOW_RTS 0x80 /* RTS is off/on when RX fills/empties */ 85#define WHITEHEAT_HFLOW_CTS 0x08 /* when received CTS off/on
86 will stop/start TX */
87#define WHITEHEAT_HFLOW_DSR 0x10 /* when received DSR off/on
88 will stop/start TX */
89#define WHITEHEAT_HFLOW_RTS 0x80 /* RTS is off/on when RX
90 fills/empties */
80 91
81struct whiteheat_port_settings { 92struct whiteheat_port_settings {
82 __u8 port; /* port number (1 to N) */ 93 __u8 port; /* port number (1 to N) */
83 __u32 baud; /* any value 7 - 460800, firmware calculates best fit; arrives little endian */ 94 __u32 baud; /* any value 7 - 460800, firmware calculates
95 best fit; arrives little endian */
84 __u8 bits; /* 5, 6, 7, or 8 */ 96 __u8 bits; /* 5, 6, 7, or 8 */
85 __u8 stop; /* 1 or 2, default 1 (2 = 1.5 if bits = 5) */ 97 __u8 stop; /* 1 or 2, default 1 (2 = 1.5 if bits = 5) */
86 __u8 parity; /* see WHITEHEAT_PAR_* above */ 98 __u8 parity; /* see WHITEHEAT_PAR_* above */
@@ -167,12 +179,14 @@ struct whiteheat_echo {
167 */ 179 */
168#define WHITEHEAT_TEST_UART_RW 0x01 /* read/write uart registers */ 180#define WHITEHEAT_TEST_UART_RW 0x01 /* read/write uart registers */
169#define WHITEHEAT_TEST_UART_INTR 0x02 /* uart interrupt */ 181#define WHITEHEAT_TEST_UART_INTR 0x02 /* uart interrupt */
170#define WHITEHEAT_TEST_SETUP_CONT 0x03 /* setup for PORT_CONT/PORT_DISCONT */ 182#define WHITEHEAT_TEST_SETUP_CONT 0x03 /* setup for
183 PORT_CONT/PORT_DISCONT */
171#define WHITEHEAT_TEST_PORT_CONT 0x04 /* port connect */ 184#define WHITEHEAT_TEST_PORT_CONT 0x04 /* port connect */
172#define WHITEHEAT_TEST_PORT_DISCONT 0x05 /* port disconnect */ 185#define WHITEHEAT_TEST_PORT_DISCONT 0x05 /* port disconnect */
173#define WHITEHEAT_TEST_UART_CLK_START 0x06 /* uart clock test start */ 186#define WHITEHEAT_TEST_UART_CLK_START 0x06 /* uart clock test start */
174#define WHITEHEAT_TEST_UART_CLK_STOP 0x07 /* uart clock test stop */ 187#define WHITEHEAT_TEST_UART_CLK_STOP 0x07 /* uart clock test stop */
175#define WHITEHEAT_TEST_MODEM_FT 0x08 /* modem signals, requires a loopback cable/connector */ 188#define WHITEHEAT_TEST_MODEM_FT 0x08 /* modem signals, requires a
189 loopback cable/connector */
176#define WHITEHEAT_TEST_ERASE_EEPROM 0x09 /* erase eeprom */ 190#define WHITEHEAT_TEST_ERASE_EEPROM 0x09 /* erase eeprom */
177#define WHITEHEAT_TEST_READ_EEPROM 0x0a /* read eeprom */ 191#define WHITEHEAT_TEST_READ_EEPROM 0x0a /* read eeprom */
178#define WHITEHEAT_TEST_PROGRAM_EEPROM 0x0b /* program eeprom */ 192#define WHITEHEAT_TEST_PROGRAM_EEPROM 0x0b /* program eeprom */
@@ -198,19 +212,27 @@ struct whiteheat_test {
198#define WHITEHEAT_EVENT_CONNECT 0x08 /* connect field is valid */ 212#define WHITEHEAT_EVENT_CONNECT 0x08 /* connect field is valid */
199 213
200#define WHITEHEAT_FLOW_NONE 0x00 /* no flow control active */ 214#define WHITEHEAT_FLOW_NONE 0x00 /* no flow control active */
201#define WHITEHEAT_FLOW_HARD_OUT 0x01 /* TX is stopped by CTS (waiting for CTS to go on) */ 215#define WHITEHEAT_FLOW_HARD_OUT 0x01 /* TX is stopped by CTS
202#define WHITEHEAT_FLOW_HARD_IN 0x02 /* remote TX is stopped by RTS */ 216 (waiting for CTS to go on) */
203#define WHITEHEAT_FLOW_SOFT_OUT 0x04 /* TX is stopped by XOFF received (waiting for XON) */ 217#define WHITEHEAT_FLOW_HARD_IN 0x02 /* remote TX is stopped
204#define WHITEHEAT_FLOW_SOFT_IN 0x08 /* remote TX is stopped by XOFF transmitted */ 218 by RTS */
219#define WHITEHEAT_FLOW_SOFT_OUT 0x04 /* TX is stopped by XOFF
220 received (waiting for XON) */
221#define WHITEHEAT_FLOW_SOFT_IN 0x08 /* remote TX is stopped by XOFF
222 transmitted */
205#define WHITEHEAT_FLOW_TX_DONE 0x80 /* TX has completed */ 223#define WHITEHEAT_FLOW_TX_DONE 0x80 /* TX has completed */
206 224
207struct whiteheat_status_info { 225struct whiteheat_status_info {
208 __u8 port; /* port number (1 to N) */ 226 __u8 port; /* port number (1 to N) */
209 __u8 event; /* indicates what the current event is, see WHITEHEAT_EVENT_* above */ 227 __u8 event; /* indicates what the current event is,
210 __u8 modem; /* modem signal status (copy of uart's MSR register) */ 228 see WHITEHEAT_EVENT_* above */
229 __u8 modem; /* modem signal status (copy of uart's
230 MSR register) */
211 __u8 error; /* line status (copy of uart's LSR register) */ 231 __u8 error; /* line status (copy of uart's LSR register) */
212 __u8 flow; /* flow control state, see WHITEHEAT_FLOW_* above */ 232 __u8 flow; /* flow control state, see WHITEHEAT_FLOW_*
213 __u8 connect; /* 0 means not connected, non-zero means connected */ 233 above */
234 __u8 connect; /* 0 means not connected, non-zero means
235 connected */
214}; 236};
215 237
216 238
@@ -256,7 +278,8 @@ struct whiteheat_hw_info {
256struct whiteheat_event_info { 278struct whiteheat_event_info {
257 __u8 port; /* port number (1 to N) */ 279 __u8 port; /* port number (1 to N) */
258 __u8 event; /* see whiteheat_status_info.event */ 280 __u8 event; /* see whiteheat_status_info.event */
259 __u8 info; /* see whiteheat_status_info.modem, .error, .flow, .connect */ 281 __u8 info; /* see whiteheat_status_info.modem, .error,
282 .flow, .connect */
260}; 283};
261 284
262 285
@@ -269,7 +292,8 @@ struct whiteheat_event_info {
269 292
270struct whiteheat_test_info { 293struct whiteheat_test_info {
271 __u8 port; /* port number (1 to N) */ 294 __u8 port; /* port number (1 to N) */
272 __u8 test; /* indicates which test this is a response for, see WHITEHEAT_DO_TEST above */ 295 __u8 test; /* indicates which test this is a response for,
296 see WHITEHEAT_DO_TEST above */
273 __u8 status; /* see WHITEHEAT_TEST_* above */ 297 __u8 status; /* see WHITEHEAT_TEST_* above */
274 __u8 results[32]; /* test-dependent results */ 298 __u8 results[32]; /* test-dependent results */
275}; 299};
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index d48ff5f370f4..639d2d8b5710 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -204,6 +204,7 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
204 NEW_AUX_ENT(AT_GID, tsk->gid); 204 NEW_AUX_ENT(AT_GID, tsk->gid);
205 NEW_AUX_ENT(AT_EGID, tsk->egid); 205 NEW_AUX_ENT(AT_EGID, tsk->egid);
206 NEW_AUX_ENT(AT_SECURE, security_bprm_secureexec(bprm)); 206 NEW_AUX_ENT(AT_SECURE, security_bprm_secureexec(bprm));
207 NEW_AUX_ENT(AT_EXECFN, bprm->exec);
207 if (k_platform) { 208 if (k_platform) {
208 NEW_AUX_ENT(AT_PLATFORM, 209 NEW_AUX_ENT(AT_PLATFORM,
209 (elf_addr_t)(unsigned long)u_platform); 210 (elf_addr_t)(unsigned long)u_platform);
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 164bd9f9ede3..7546a918f790 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -636,7 +636,7 @@ static ssize_t pagemap_read(struct file *file, char __user *buf,
636 struct pagemapread pm; 636 struct pagemapread pm;
637 int pagecount; 637 int pagecount;
638 int ret = -ESRCH; 638 int ret = -ESRCH;
639 struct mm_walk pagemap_walk; 639 struct mm_walk pagemap_walk = {};
640 unsigned long src; 640 unsigned long src;
641 unsigned long svpfn; 641 unsigned long svpfn;
642 unsigned long start_vaddr; 642 unsigned long start_vaddr;
diff --git a/include/linux/auxvec.h b/include/linux/auxvec.h
index ad895455ab72..0da17d14fd13 100644
--- a/include/linux/auxvec.h
+++ b/include/linux/auxvec.h
@@ -26,8 +26,10 @@
26 26
27#define AT_SECURE 23 /* secure mode boolean */ 27#define AT_SECURE 23 /* secure mode boolean */
28 28
29#define AT_EXECFN 31 /* filename of program */
29#ifdef __KERNEL__ 30#ifdef __KERNEL__
30#define AT_VECTOR_SIZE_BASE (14 + 2) /* NEW_AUX_ENT entries in auxiliary table */ 31#define AT_VECTOR_SIZE_BASE 17 /* NEW_AUX_ENT entries in auxiliary table */
32 /* number of "#define AT_.*" above, minus {AT_NULL, AT_IGNORE, AT_NOTELF} */
31#endif 33#endif
32 34
33#endif /* _LINUX_AUXVEC_H */ 35#endif /* _LINUX_AUXVEC_H */
diff --git a/include/linux/spi/max7301.h b/include/linux/spi/max7301.h
new file mode 100644
index 000000000000..6dfd83f19b4b
--- /dev/null
+++ b/include/linux/spi/max7301.h
@@ -0,0 +1,9 @@
1#ifndef LINUX_SPI_MAX7301_H
2#define LINUX_SPI_MAX7301_H
3
4struct max7301_platform_data {
5 /* number assigned to the first GPIO */
6 unsigned base;
7};
8
9#endif
diff --git a/include/linux/synclink.h b/include/linux/synclink.h
index 45f6bc82d317..c844a229acc9 100644
--- a/include/linux/synclink.h
+++ b/include/linux/synclink.h
@@ -136,6 +136,7 @@
136#define MGSL_INTERFACE_RTS_EN 0x10 136#define MGSL_INTERFACE_RTS_EN 0x10
137#define MGSL_INTERFACE_LL 0x20 137#define MGSL_INTERFACE_LL 0x20
138#define MGSL_INTERFACE_RL 0x40 138#define MGSL_INTERFACE_RL 0x40
139#define MGSL_INTERFACE_MSB_FIRST 0x80
139 140
140typedef struct _MGSL_PARAMS 141typedef struct _MGSL_PARAMS
141{ 142{
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 4e5833073aa6..e3579cb086e0 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -317,8 +317,6 @@ extern void tty_wait_until_sent(struct tty_struct *tty, long timeout);
317extern int tty_check_change(struct tty_struct *tty); 317extern int tty_check_change(struct tty_struct *tty);
318extern void stop_tty(struct tty_struct *tty); 318extern void stop_tty(struct tty_struct *tty);
319extern void start_tty(struct tty_struct *tty); 319extern void start_tty(struct tty_struct *tty);
320extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
321extern int tty_unregister_ldisc(int disc);
322extern int tty_register_driver(struct tty_driver *driver); 320extern int tty_register_driver(struct tty_driver *driver);
323extern int tty_unregister_driver(struct tty_driver *driver); 321extern int tty_unregister_driver(struct tty_driver *driver);
324extern struct device *tty_register_device(struct tty_driver *driver, 322extern struct device *tty_register_device(struct tty_driver *driver,
@@ -383,6 +381,15 @@ extern void tty_port_init(struct tty_port *port);
383extern int tty_port_alloc_xmit_buf(struct tty_port *port); 381extern int tty_port_alloc_xmit_buf(struct tty_port *port);
384extern void tty_port_free_xmit_buf(struct tty_port *port); 382extern void tty_port_free_xmit_buf(struct tty_port *port);
385 383
384extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
385extern int tty_unregister_ldisc(int disc);
386extern int tty_set_ldisc(struct tty_struct *tty, int ldisc);
387extern int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty);
388extern void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty);
389extern void tty_ldisc_init(struct tty_struct *tty);
390extern void tty_ldisc_begin(void);
391/* This last one is just for the tty layer internals and shouldn't be used elsewhere */
392extern void tty_ldisc_enable(struct tty_struct *tty);
386 393
387 394
388/* n_tty.c */ 395/* n_tty.c */
diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
index d2a003586761..e1065ac0d922 100644
--- a/include/linux/tty_driver.h
+++ b/include/linux/tty_driver.h
@@ -135,7 +135,7 @@
135 * 135 *
136 * Optional: 136 * Optional:
137 * 137 *
138 * void (*break_ctl)(struct tty_stuct *tty, int state); 138 * int (*break_ctl)(struct tty_stuct *tty, int state);
139 * 139 *
140 * This optional routine requests the tty driver to turn on or 140 * This optional routine requests the tty driver to turn on or
141 * off BREAK status on the RS-232 port. If state is -1, 141 * off BREAK status on the RS-232 port. If state is -1,
@@ -146,6 +146,10 @@
146 * handle the following ioctls: TCSBRK, TCSBRKP, TIOCSBRK, 146 * handle the following ioctls: TCSBRK, TCSBRKP, TIOCSBRK,
147 * TIOCCBRK. 147 * TIOCCBRK.
148 * 148 *
149 * If the driver sets TTY_DRIVER_HARDWARE_BREAK then the interface
150 * will also be called with actual times and the hardware is expected
151 * to do the delay work itself. 0 and -1 are still used for on/off.
152 *
149 * Optional: Required for TCSBRK/BRKP/etc handling. 153 * Optional: Required for TCSBRK/BRKP/etc handling.
150 * 154 *
151 * void (*wait_until_sent)(struct tty_struct *tty, int timeout); 155 * void (*wait_until_sent)(struct tty_struct *tty, int timeout);
@@ -192,7 +196,7 @@ struct tty_operations {
192 void (*stop)(struct tty_struct *tty); 196 void (*stop)(struct tty_struct *tty);
193 void (*start)(struct tty_struct *tty); 197 void (*start)(struct tty_struct *tty);
194 void (*hangup)(struct tty_struct *tty); 198 void (*hangup)(struct tty_struct *tty);
195 void (*break_ctl)(struct tty_struct *tty, int state); 199 int (*break_ctl)(struct tty_struct *tty, int state);
196 void (*flush_buffer)(struct tty_struct *tty); 200 void (*flush_buffer)(struct tty_struct *tty);
197 void (*set_ldisc)(struct tty_struct *tty); 201 void (*set_ldisc)(struct tty_struct *tty);
198 void (*wait_until_sent)(struct tty_struct *tty, int timeout); 202 void (*wait_until_sent)(struct tty_struct *tty, int timeout);
@@ -285,12 +289,18 @@ extern struct tty_driver *tty_find_polling_driver(char *name, int *line);
285 * TTY_DRIVER_DEVPTS_MEM -- don't use the standard arrays, instead 289 * TTY_DRIVER_DEVPTS_MEM -- don't use the standard arrays, instead
286 * use dynamic memory keyed through the devpts filesystem. This 290 * use dynamic memory keyed through the devpts filesystem. This
287 * is only applicable to the pty driver. 291 * is only applicable to the pty driver.
292 *
293 * TTY_DRIVER_HARDWARE_BREAK -- hardware handles break signals. Pass
294 * the requested timeout to the caller instead of using a simple
295 * on/off interface.
296 *
288 */ 297 */
289#define TTY_DRIVER_INSTALLED 0x0001 298#define TTY_DRIVER_INSTALLED 0x0001
290#define TTY_DRIVER_RESET_TERMIOS 0x0002 299#define TTY_DRIVER_RESET_TERMIOS 0x0002
291#define TTY_DRIVER_REAL_RAW 0x0004 300#define TTY_DRIVER_REAL_RAW 0x0004
292#define TTY_DRIVER_DYNAMIC_DEV 0x0008 301#define TTY_DRIVER_DYNAMIC_DEV 0x0008
293#define TTY_DRIVER_DEVPTS_MEM 0x0010 302#define TTY_DRIVER_DEVPTS_MEM 0x0010
303#define TTY_DRIVER_HARDWARE_BREAK 0x0020
294 304
295/* tty driver types */ 305/* tty driver types */
296#define TTY_DRIVER_TYPE_SYSTEM 0x0001 306#define TTY_DRIVER_TYPE_SYSTEM 0x0001
diff --git a/include/linux/usb/serial.h b/include/linux/usb/serial.h
index 8f891cbaf9ab..09a3e6a7518f 100644
--- a/include/linux/usb/serial.h
+++ b/include/linux/usb/serial.h
@@ -62,7 +62,7 @@
62 */ 62 */
63struct usb_serial_port { 63struct usb_serial_port {
64 struct usb_serial *serial; 64 struct usb_serial *serial;
65 struct tty_struct *tty; 65 struct tty_port port;
66 spinlock_t lock; 66 spinlock_t lock;
67 struct mutex mutex; 67 struct mutex mutex;
68 unsigned char number; 68 unsigned char number;
@@ -89,7 +89,6 @@ struct usb_serial_port {
89 89
90 wait_queue_head_t write_wait; 90 wait_queue_head_t write_wait;
91 struct work_struct work; 91 struct work_struct work;
92 int open_count;
93 char throttled; 92 char throttled;
94 char throttle_req; 93 char throttle_req;
95 char console; 94 char console;
@@ -217,22 +216,27 @@ struct usb_serial_driver {
217 int (*resume)(struct usb_serial *serial); 216 int (*resume)(struct usb_serial *serial);
218 217
219 /* serial function calls */ 218 /* serial function calls */
220 int (*open)(struct usb_serial_port *port, struct file *filp); 219 /* Called by console with tty = NULL and by tty */
221 void (*close)(struct usb_serial_port *port, struct file *filp); 220 int (*open)(struct tty_struct *tty,
222 int (*write)(struct usb_serial_port *port, const unsigned char *buf, 221 struct usb_serial_port *port, struct file *filp);
223 int count); 222 void (*close)(struct tty_struct *tty,
224 int (*write_room)(struct usb_serial_port *port); 223 struct usb_serial_port *port, struct file *filp);
225 int (*ioctl)(struct usb_serial_port *port, struct file *file, 224 int (*write)(struct tty_struct *tty, struct usb_serial_port *port,
225 const unsigned char *buf, int count);
226 /* Called only by the tty layer */
227 int (*write_room)(struct tty_struct *tty);
228 int (*ioctl)(struct tty_struct *tty, struct file *file,
226 unsigned int cmd, unsigned long arg); 229 unsigned int cmd, unsigned long arg);
227 void (*set_termios)(struct usb_serial_port *port, struct ktermios *old); 230 void (*set_termios)(struct tty_struct *tty,
228 void (*break_ctl)(struct usb_serial_port *port, int break_state); 231 struct usb_serial_port *port, struct ktermios *old);
229 int (*chars_in_buffer)(struct usb_serial_port *port); 232 void (*break_ctl)(struct tty_struct *tty, int break_state);
230 void (*throttle)(struct usb_serial_port *port); 233 int (*chars_in_buffer)(struct tty_struct *tty);
231 void (*unthrottle)(struct usb_serial_port *port); 234 void (*throttle)(struct tty_struct *tty);
232 int (*tiocmget)(struct usb_serial_port *port, struct file *file); 235 void (*unthrottle)(struct tty_struct *tty);
233 int (*tiocmset)(struct usb_serial_port *port, struct file *file, 236 int (*tiocmget)(struct tty_struct *tty, struct file *file);
237 int (*tiocmset)(struct tty_struct *tty, struct file *file,
234 unsigned int set, unsigned int clear); 238 unsigned int set, unsigned int clear);
235 239 /* USB events */
236 void (*read_int_callback)(struct urb *urb); 240 void (*read_int_callback)(struct urb *urb);
237 void (*write_int_callback)(struct urb *urb); 241 void (*write_int_callback)(struct urb *urb);
238 void (*read_bulk_callback)(struct urb *urb); 242 void (*read_bulk_callback)(struct urb *urb);
@@ -270,19 +274,19 @@ static inline void usb_serial_console_disconnect(struct usb_serial *serial) {}
270/* Functions needed by other parts of the usbserial core */ 274/* Functions needed by other parts of the usbserial core */
271extern struct usb_serial *usb_serial_get_by_index(unsigned int minor); 275extern struct usb_serial *usb_serial_get_by_index(unsigned int minor);
272extern void usb_serial_put(struct usb_serial *serial); 276extern void usb_serial_put(struct usb_serial *serial);
273extern int usb_serial_generic_open(struct usb_serial_port *port, 277extern int usb_serial_generic_open(struct tty_struct *tty,
274 struct file *filp); 278 struct usb_serial_port *port, struct file *filp);
275extern int usb_serial_generic_write(struct usb_serial_port *port, 279extern int usb_serial_generic_write(struct tty_struct *tty,
276 const unsigned char *buf, int count); 280 struct usb_serial_port *port, const unsigned char *buf, int count);
277extern void usb_serial_generic_close(struct usb_serial_port *port, 281extern void usb_serial_generic_close(struct tty_struct *tty,
278 struct file *filp); 282 struct usb_serial_port *port, struct file *filp);
279extern int usb_serial_generic_resume(struct usb_serial *serial); 283extern int usb_serial_generic_resume(struct usb_serial *serial);
280extern int usb_serial_generic_write_room(struct usb_serial_port *port); 284extern int usb_serial_generic_write_room(struct tty_struct *tty);
281extern int usb_serial_generic_chars_in_buffer(struct usb_serial_port *port); 285extern int usb_serial_generic_chars_in_buffer(struct tty_struct *tty);
282extern void usb_serial_generic_read_bulk_callback(struct urb *urb); 286extern void usb_serial_generic_read_bulk_callback(struct urb *urb);
283extern void usb_serial_generic_write_bulk_callback(struct urb *urb); 287extern void usb_serial_generic_write_bulk_callback(struct urb *urb);
284extern void usb_serial_generic_throttle(struct usb_serial_port *port); 288extern void usb_serial_generic_throttle(struct tty_struct *tty);
285extern void usb_serial_generic_unthrottle(struct usb_serial_port *port); 289extern void usb_serial_generic_unthrottle(struct tty_struct *tty);
286extern void usb_serial_generic_shutdown(struct usb_serial *serial); 290extern void usb_serial_generic_shutdown(struct usb_serial *serial);
287extern int usb_serial_generic_register(int debug); 291extern int usb_serial_generic_register(int debug);
288extern void usb_serial_generic_deregister(void); 292extern void usb_serial_generic_deregister(void);
diff --git a/kernel/cpuset.c b/kernel/cpuset.c
index 459d601947a8..d2cc67dac8b1 100644
--- a/kernel/cpuset.c
+++ b/kernel/cpuset.c
@@ -679,7 +679,9 @@ restart:
679 if (apn == b->pn) { 679 if (apn == b->pn) {
680 cpus_or(*dp, *dp, b->cpus_allowed); 680 cpus_or(*dp, *dp, b->cpus_allowed);
681 b->pn = -1; 681 b->pn = -1;
682 update_domain_attr(dattr, b); 682 if (dattr)
683 update_domain_attr(dattr
684 + nslot, b);
683 } 685 }
684 } 686 }
685 nslot++; 687 nslot++;
diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c
index 5b9b467de070..0fea0ee12da9 100644
--- a/kernel/sys_ni.c
+++ b/kernel/sys_ni.c
@@ -59,6 +59,7 @@ cond_syscall(sys_epoll_create);
59cond_syscall(sys_epoll_ctl); 59cond_syscall(sys_epoll_ctl);
60cond_syscall(sys_epoll_wait); 60cond_syscall(sys_epoll_wait);
61cond_syscall(sys_epoll_pwait); 61cond_syscall(sys_epoll_pwait);
62cond_syscall(compat_sys_epoll_pwait);
62cond_syscall(sys_semget); 63cond_syscall(sys_semget);
63cond_syscall(sys_semop); 64cond_syscall(sys_semop);
64cond_syscall(sys_semtimedop); 65cond_syscall(sys_semtimedop);
diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost
index 17092d6c7db3..9ee9783aea57 100644
--- a/scripts/Makefile.modpost
+++ b/scripts/Makefile.modpost
@@ -101,6 +101,7 @@ quiet_cmd_kernel-mod = MODPOST $@
101 cmd_kernel-mod = $(modpost) $@ 101 cmd_kernel-mod = $(modpost) $@
102 102
103vmlinux.o: FORCE 103vmlinux.o: FORCE
104 @rm -fr $(kernelmarkersfile)
104 $(call cmd,kernel-mod) 105 $(call cmd,kernel-mod)
105 106
106# Declare generated files as targets for modpost 107# Declare generated files as targets for modpost
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index a07f91aac920..8f038e6d5f98 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -1992,7 +1992,8 @@ static void read_markers(const char *fname)
1992 mod->skip = 1; 1992 mod->skip = 1;
1993 } 1993 }
1994 1994
1995 add_marker(mod, marker, fmt); 1995 if (!mod->skip)
1996 add_marker(mod, marker, fmt);
1996 } 1997 }
1997 return; 1998 return;
1998fail: 1999fail: