diff options
95 files changed, 4438 insertions, 2714 deletions
diff --git a/MAINTAINERS b/MAINTAINERS index cf4abddfc8a4..84285b5ba359 100644 --- a/MAINTAINERS +++ b/MAINTAINERS | |||
@@ -71,7 +71,7 @@ P: Person | |||
71 | M: Mail patches to | 71 | M: Mail patches to |
72 | L: Mailing list that is relevant to this area | 72 | L: Mailing list that is relevant to this area |
73 | W: Web-page with status/info | 73 | W: Web-page with status/info |
74 | T: SCM tree type and location. Type is one of: git, hg, quilt. | 74 | T: SCM tree type and location. Type is one of: git, hg, quilt, stgit. |
75 | S: Status, one of the following: | 75 | S: Status, one of the following: |
76 | 76 | ||
77 | Supported: Someone is actually paid to look after this. | 77 | Supported: Someone is actually paid to look after this. |
@@ -159,7 +159,8 @@ F: drivers/net/r8169.c | |||
159 | 8250/16?50 (AND CLONE UARTS) SERIAL DRIVER | 159 | 8250/16?50 (AND CLONE UARTS) SERIAL DRIVER |
160 | L: linux-serial@vger.kernel.org | 160 | L: linux-serial@vger.kernel.org |
161 | W: http://serial.sourceforge.net | 161 | W: http://serial.sourceforge.net |
162 | S: Orphan | 162 | M: alan@lxorguk.ukuu.org.uk |
163 | S: Odd Fixes | ||
163 | F: drivers/serial/8250* | 164 | F: drivers/serial/8250* |
164 | F: include/linux/serial_8250.h | 165 | F: include/linux/serial_8250.h |
165 | 166 | ||
@@ -5629,6 +5630,7 @@ P: Alan Cox | |||
5629 | M: alan@lxorguk.ukuu.org.uk | 5630 | M: alan@lxorguk.ukuu.org.uk |
5630 | L: linux-kernel@vger.kernel.org | 5631 | L: linux-kernel@vger.kernel.org |
5631 | S: Maintained | 5632 | S: Maintained |
5633 | T: stgit http://zeniv.linux.org.uk/~alan/ttydev/ | ||
5632 | 5634 | ||
5633 | TULIP NETWORK DRIVERS | 5635 | TULIP NETWORK DRIVERS |
5634 | P: Grant Grundler | 5636 | P: Grant Grundler |
diff --git a/arch/arm/plat-mxc/include/mach/imx-uart.h b/arch/arm/plat-mxc/include/mach/imx-uart.h index 599217b2e13f..f9bd17dd8dd7 100644 --- a/arch/arm/plat-mxc/include/mach/imx-uart.h +++ b/arch/arm/plat-mxc/include/mach/imx-uart.h | |||
@@ -20,11 +20,16 @@ | |||
20 | #define ASMARM_ARCH_UART_H | 20 | #define ASMARM_ARCH_UART_H |
21 | 21 | ||
22 | #define IMXUART_HAVE_RTSCTS (1<<0) | 22 | #define IMXUART_HAVE_RTSCTS (1<<0) |
23 | #define IMXUART_IRDA (1<<1) | ||
23 | 24 | ||
24 | struct imxuart_platform_data { | 25 | struct imxuart_platform_data { |
25 | int (*init)(struct platform_device *pdev); | 26 | int (*init)(struct platform_device *pdev); |
26 | int (*exit)(struct platform_device *pdev); | 27 | int (*exit)(struct platform_device *pdev); |
27 | unsigned int flags; | 28 | unsigned int flags; |
29 | void (*irda_enable)(int enable); | ||
30 | unsigned int irda_inv_rx:1; | ||
31 | unsigned int irda_inv_tx:1; | ||
32 | unsigned short transceiver_delay; | ||
28 | }; | 33 | }; |
29 | 34 | ||
30 | #endif | 35 | #endif |
diff --git a/arch/x86/include/asm/termios.h b/arch/x86/include/asm/termios.h index f72956331c49..c4ee8056baca 100644 --- a/arch/x86/include/asm/termios.h +++ b/arch/x86/include/asm/termios.h | |||
@@ -67,6 +67,7 @@ static inline int user_termio_to_kernel_termios(struct ktermios *termios, | |||
67 | SET_LOW_TERMIOS_BITS(termios, termio, c_oflag); | 67 | SET_LOW_TERMIOS_BITS(termios, termio, c_oflag); |
68 | SET_LOW_TERMIOS_BITS(termios, termio, c_cflag); | 68 | SET_LOW_TERMIOS_BITS(termios, termio, c_cflag); |
69 | SET_LOW_TERMIOS_BITS(termios, termio, c_lflag); | 69 | SET_LOW_TERMIOS_BITS(termios, termio, c_lflag); |
70 | get_user(termios->c_line, &termio->c_line); | ||
70 | return copy_from_user(termios->c_cc, termio->c_cc, NCC); | 71 | return copy_from_user(termios->c_cc, termio->c_cc, NCC); |
71 | } | 72 | } |
72 | 73 | ||
diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c index af761dc434f6..4895f0e05322 100644 --- a/drivers/bluetooth/hci_ldisc.c +++ b/drivers/bluetooth/hci_ldisc.c | |||
@@ -277,8 +277,8 @@ static int hci_uart_tty_open(struct tty_struct *tty) | |||
277 | /* FIXME: why is this needed. Note don't use ldisc_ref here as the | 277 | /* FIXME: why is this needed. Note don't use ldisc_ref here as the |
278 | open path is before the ldisc is referencable */ | 278 | open path is before the ldisc is referencable */ |
279 | 279 | ||
280 | if (tty->ldisc.ops->flush_buffer) | 280 | if (tty->ldisc->ops->flush_buffer) |
281 | tty->ldisc.ops->flush_buffer(tty); | 281 | tty->ldisc->ops->flush_buffer(tty); |
282 | tty_driver_flush_buffer(tty); | 282 | tty_driver_flush_buffer(tty); |
283 | 283 | ||
284 | return 0; | 284 | return 0; |
@@ -463,7 +463,6 @@ static int hci_uart_tty_ioctl(struct tty_struct *tty, struct file * file, | |||
463 | clear_bit(HCI_UART_PROTO_SET, &hu->flags); | 463 | clear_bit(HCI_UART_PROTO_SET, &hu->flags); |
464 | return err; | 464 | return err; |
465 | } | 465 | } |
466 | tty->low_latency = 1; | ||
467 | } else | 466 | } else |
468 | return -EBUSY; | 467 | return -EBUSY; |
469 | break; | 468 | break; |
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig index 735bbe2be51a..02ecfd5fa61c 100644 --- a/drivers/char/Kconfig +++ b/drivers/char/Kconfig | |||
@@ -97,6 +97,19 @@ config DEVKMEM | |||
97 | kind of kernel debugging operations. | 97 | kind of kernel debugging operations. |
98 | When in doubt, say "N". | 98 | When in doubt, say "N". |
99 | 99 | ||
100 | config BFIN_JTAG_COMM | ||
101 | tristate "Blackfin JTAG Communication" | ||
102 | depends on BLACKFIN | ||
103 | help | ||
104 | Add support for emulating a TTY device over the Blackfin JTAG. | ||
105 | |||
106 | To compile this driver as a module, choose M here: the | ||
107 | module will be called bfin_jtag_comm. | ||
108 | |||
109 | config BFIN_JTAG_COMM_CONSOLE | ||
110 | bool "Console on Blackfin JTAG" | ||
111 | depends on BFIN_JTAG_COMM=y | ||
112 | |||
100 | config SERIAL_NONSTANDARD | 113 | config SERIAL_NONSTANDARD |
101 | bool "Non-standard serial port support" | 114 | bool "Non-standard serial port support" |
102 | depends on HAS_IOMEM | 115 | depends on HAS_IOMEM |
diff --git a/drivers/char/Makefile b/drivers/char/Makefile index 9caf5b5ad1c0..189efcff08ce 100644 --- a/drivers/char/Makefile +++ b/drivers/char/Makefile | |||
@@ -13,6 +13,7 @@ obj-$(CONFIG_LEGACY_PTYS) += pty.o | |||
13 | obj-$(CONFIG_UNIX98_PTYS) += pty.o | 13 | obj-$(CONFIG_UNIX98_PTYS) += pty.o |
14 | obj-y += misc.o | 14 | obj-y += misc.o |
15 | obj-$(CONFIG_VT) += vt_ioctl.o vc_screen.o selection.o keyboard.o | 15 | obj-$(CONFIG_VT) += vt_ioctl.o vc_screen.o selection.o keyboard.o |
16 | obj-$(CONFIG_BFIN_JTAG_COMM) += bfin_jtag_comm.o | ||
16 | obj-$(CONFIG_CONSOLE_TRANSLATIONS) += consolemap.o consolemap_deftbl.o | 17 | obj-$(CONFIG_CONSOLE_TRANSLATIONS) += consolemap.o consolemap_deftbl.o |
17 | obj-$(CONFIG_HW_CONSOLE) += vt.o defkeymap.o | 18 | obj-$(CONFIG_HW_CONSOLE) += vt.o defkeymap.o |
18 | obj-$(CONFIG_AUDIT) += tty_audit.o | 19 | obj-$(CONFIG_AUDIT) += tty_audit.o |
diff --git a/drivers/char/bfin_jtag_comm.c b/drivers/char/bfin_jtag_comm.c new file mode 100644 index 000000000000..44c113d56045 --- /dev/null +++ b/drivers/char/bfin_jtag_comm.c | |||
@@ -0,0 +1,365 @@ | |||
1 | /* | ||
2 | * TTY over Blackfin JTAG Communication | ||
3 | * | ||
4 | * Copyright 2008-2009 Analog Devices Inc. | ||
5 | * | ||
6 | * Enter bugs at http://blackfin.uclinux.org/ | ||
7 | * | ||
8 | * Licensed under the GPL-2 or later. | ||
9 | */ | ||
10 | |||
11 | #include <linux/circ_buf.h> | ||
12 | #include <linux/console.h> | ||
13 | #include <linux/delay.h> | ||
14 | #include <linux/err.h> | ||
15 | #include <linux/kernel.h> | ||
16 | #include <linux/kthread.h> | ||
17 | #include <linux/module.h> | ||
18 | #include <linux/mutex.h> | ||
19 | #include <linux/sched.h> | ||
20 | #include <linux/tty.h> | ||
21 | #include <linux/tty_driver.h> | ||
22 | #include <linux/tty_flip.h> | ||
23 | #include <asm/atomic.h> | ||
24 | |||
25 | /* See the Debug/Emulation chapter in the HRM */ | ||
26 | #define EMUDOF 0x00000001 /* EMUDAT_OUT full & valid */ | ||
27 | #define EMUDIF 0x00000002 /* EMUDAT_IN full & valid */ | ||
28 | #define EMUDOOVF 0x00000004 /* EMUDAT_OUT overflow */ | ||
29 | #define EMUDIOVF 0x00000008 /* EMUDAT_IN overflow */ | ||
30 | |||
31 | #define DRV_NAME "bfin-jtag-comm" | ||
32 | #define DEV_NAME "ttyBFJC" | ||
33 | |||
34 | #define pr_init(fmt, args...) ({ static const __initdata char __fmt[] = fmt; printk(__fmt, ## args); }) | ||
35 | #define debug(fmt, args...) pr_debug(DRV_NAME ": " fmt, ## args) | ||
36 | |||
37 | static inline uint32_t bfin_write_emudat(uint32_t emudat) | ||
38 | { | ||
39 | __asm__ __volatile__("emudat = %0;" : : "d"(emudat)); | ||
40 | return emudat; | ||
41 | } | ||
42 | |||
43 | static inline uint32_t bfin_read_emudat(void) | ||
44 | { | ||
45 | uint32_t emudat; | ||
46 | __asm__ __volatile__("%0 = emudat;" : "=d"(emudat)); | ||
47 | return emudat; | ||
48 | } | ||
49 | |||
50 | static inline uint32_t bfin_write_emudat_chars(char a, char b, char c, char d) | ||
51 | { | ||
52 | return bfin_write_emudat((a << 0) | (b << 8) | (c << 16) | (d << 24)); | ||
53 | } | ||
54 | |||
55 | #define CIRC_SIZE 2048 /* see comment in tty_io.c:do_tty_write() */ | ||
56 | #define CIRC_MASK (CIRC_SIZE - 1) | ||
57 | #define circ_empty(circ) ((circ)->head == (circ)->tail) | ||
58 | #define circ_free(circ) CIRC_SPACE((circ)->head, (circ)->tail, CIRC_SIZE) | ||
59 | #define circ_cnt(circ) CIRC_CNT((circ)->head, (circ)->tail, CIRC_SIZE) | ||
60 | #define circ_byte(circ, idx) ((circ)->buf[(idx) & CIRC_MASK]) | ||
61 | |||
62 | static struct tty_driver *bfin_jc_driver; | ||
63 | static struct task_struct *bfin_jc_kthread; | ||
64 | static struct tty_struct * volatile bfin_jc_tty; | ||
65 | static unsigned long bfin_jc_count; | ||
66 | static DEFINE_MUTEX(bfin_jc_tty_mutex); | ||
67 | static volatile struct circ_buf bfin_jc_write_buf; | ||
68 | |||
69 | static int | ||
70 | bfin_jc_emudat_manager(void *arg) | ||
71 | { | ||
72 | uint32_t inbound_len = 0, outbound_len = 0; | ||
73 | |||
74 | while (!kthread_should_stop()) { | ||
75 | /* no one left to give data to, so sleep */ | ||
76 | if (bfin_jc_tty == NULL && circ_empty(&bfin_jc_write_buf)) { | ||
77 | debug("waiting for readers\n"); | ||
78 | __set_current_state(TASK_UNINTERRUPTIBLE); | ||
79 | schedule(); | ||
80 | __set_current_state(TASK_RUNNING); | ||
81 | } | ||
82 | |||
83 | /* no data available, so just chill */ | ||
84 | if (!(bfin_read_DBGSTAT() & EMUDIF) && circ_empty(&bfin_jc_write_buf)) { | ||
85 | debug("waiting for data (in_len = %i) (circ: %i %i)\n", | ||
86 | inbound_len, bfin_jc_write_buf.tail, bfin_jc_write_buf.head); | ||
87 | if (inbound_len) | ||
88 | schedule(); | ||
89 | else | ||
90 | schedule_timeout_interruptible(HZ); | ||
91 | continue; | ||
92 | } | ||
93 | |||
94 | /* if incoming data is ready, eat it */ | ||
95 | if (bfin_read_DBGSTAT() & EMUDIF) { | ||
96 | struct tty_struct *tty; | ||
97 | mutex_lock(&bfin_jc_tty_mutex); | ||
98 | tty = (struct tty_struct *)bfin_jc_tty; | ||
99 | if (tty != NULL) { | ||
100 | uint32_t emudat = bfin_read_emudat(); | ||
101 | if (inbound_len == 0) { | ||
102 | debug("incoming length: 0x%08x\n", emudat); | ||
103 | inbound_len = emudat; | ||
104 | } else { | ||
105 | size_t num_chars = (4 <= inbound_len ? 4 : inbound_len); | ||
106 | debug(" incoming data: 0x%08x (pushing %zu)\n", emudat, num_chars); | ||
107 | inbound_len -= num_chars; | ||
108 | tty_insert_flip_string(tty, (unsigned char *)&emudat, num_chars); | ||
109 | tty_flip_buffer_push(tty); | ||
110 | } | ||
111 | } | ||
112 | mutex_unlock(&bfin_jc_tty_mutex); | ||
113 | } | ||
114 | |||
115 | /* if outgoing data is ready, post it */ | ||
116 | if (!(bfin_read_DBGSTAT() & EMUDOF) && !circ_empty(&bfin_jc_write_buf)) { | ||
117 | if (outbound_len == 0) { | ||
118 | outbound_len = circ_cnt(&bfin_jc_write_buf); | ||
119 | bfin_write_emudat(outbound_len); | ||
120 | debug("outgoing length: 0x%08x\n", outbound_len); | ||
121 | } else { | ||
122 | struct tty_struct *tty; | ||
123 | int tail = bfin_jc_write_buf.tail; | ||
124 | size_t ate = (4 <= outbound_len ? 4 : outbound_len); | ||
125 | uint32_t emudat = | ||
126 | bfin_write_emudat_chars( | ||
127 | circ_byte(&bfin_jc_write_buf, tail + 0), | ||
128 | circ_byte(&bfin_jc_write_buf, tail + 1), | ||
129 | circ_byte(&bfin_jc_write_buf, tail + 2), | ||
130 | circ_byte(&bfin_jc_write_buf, tail + 3) | ||
131 | ); | ||
132 | bfin_jc_write_buf.tail += ate; | ||
133 | outbound_len -= ate; | ||
134 | mutex_lock(&bfin_jc_tty_mutex); | ||
135 | tty = (struct tty_struct *)bfin_jc_tty; | ||
136 | if (tty) | ||
137 | tty_wakeup(tty); | ||
138 | mutex_unlock(&bfin_jc_tty_mutex); | ||
139 | debug(" outgoing data: 0x%08x (pushing %zu)\n", emudat, ate); | ||
140 | } | ||
141 | } | ||
142 | } | ||
143 | |||
144 | __set_current_state(TASK_RUNNING); | ||
145 | return 0; | ||
146 | } | ||
147 | |||
148 | static int | ||
149 | bfin_jc_open(struct tty_struct *tty, struct file *filp) | ||
150 | { | ||
151 | mutex_lock(&bfin_jc_tty_mutex); | ||
152 | debug("open %lu\n", bfin_jc_count); | ||
153 | ++bfin_jc_count; | ||
154 | bfin_jc_tty = tty; | ||
155 | wake_up_process(bfin_jc_kthread); | ||
156 | mutex_unlock(&bfin_jc_tty_mutex); | ||
157 | return 0; | ||
158 | } | ||
159 | |||
160 | static void | ||
161 | bfin_jc_close(struct tty_struct *tty, struct file *filp) | ||
162 | { | ||
163 | mutex_lock(&bfin_jc_tty_mutex); | ||
164 | debug("close %lu\n", bfin_jc_count); | ||
165 | if (--bfin_jc_count == 0) | ||
166 | bfin_jc_tty = NULL; | ||
167 | wake_up_process(bfin_jc_kthread); | ||
168 | mutex_unlock(&bfin_jc_tty_mutex); | ||
169 | } | ||
170 | |||
171 | /* XXX: we dont handle the put_char() case where we must handle count = 1 */ | ||
172 | static int | ||
173 | bfin_jc_circ_write(const unsigned char *buf, int count) | ||
174 | { | ||
175 | int i; | ||
176 | count = min(count, circ_free(&bfin_jc_write_buf)); | ||
177 | debug("going to write chunk of %i bytes\n", count); | ||
178 | for (i = 0; i < count; ++i) | ||
179 | circ_byte(&bfin_jc_write_buf, bfin_jc_write_buf.head + i) = buf[i]; | ||
180 | bfin_jc_write_buf.head += i; | ||
181 | return i; | ||
182 | } | ||
183 | |||
184 | #ifndef CONFIG_BFIN_JTAG_COMM_CONSOLE | ||
185 | # define acquire_console_sem() | ||
186 | # define release_console_sem() | ||
187 | #endif | ||
188 | static int | ||
189 | bfin_jc_write(struct tty_struct *tty, const unsigned char *buf, int count) | ||
190 | { | ||
191 | int i; | ||
192 | acquire_console_sem(); | ||
193 | i = bfin_jc_circ_write(buf, count); | ||
194 | release_console_sem(); | ||
195 | wake_up_process(bfin_jc_kthread); | ||
196 | return i; | ||
197 | } | ||
198 | |||
199 | static void | ||
200 | bfin_jc_flush_chars(struct tty_struct *tty) | ||
201 | { | ||
202 | wake_up_process(bfin_jc_kthread); | ||
203 | } | ||
204 | |||
205 | static int | ||
206 | bfin_jc_write_room(struct tty_struct *tty) | ||
207 | { | ||
208 | return circ_free(&bfin_jc_write_buf); | ||
209 | } | ||
210 | |||
211 | static int | ||
212 | bfin_jc_chars_in_buffer(struct tty_struct *tty) | ||
213 | { | ||
214 | return circ_cnt(&bfin_jc_write_buf); | ||
215 | } | ||
216 | |||
217 | static void | ||
218 | bfin_jc_wait_until_sent(struct tty_struct *tty, int timeout) | ||
219 | { | ||
220 | unsigned long expire = jiffies + timeout; | ||
221 | while (!circ_empty(&bfin_jc_write_buf)) { | ||
222 | if (signal_pending(current)) | ||
223 | break; | ||
224 | if (time_after(jiffies, expire)) | ||
225 | break; | ||
226 | } | ||
227 | } | ||
228 | |||
229 | static struct tty_operations bfin_jc_ops = { | ||
230 | .open = bfin_jc_open, | ||
231 | .close = bfin_jc_close, | ||
232 | .write = bfin_jc_write, | ||
233 | /*.put_char = bfin_jc_put_char,*/ | ||
234 | .flush_chars = bfin_jc_flush_chars, | ||
235 | .write_room = bfin_jc_write_room, | ||
236 | .chars_in_buffer = bfin_jc_chars_in_buffer, | ||
237 | .wait_until_sent = bfin_jc_wait_until_sent, | ||
238 | }; | ||
239 | |||
240 | static int __init bfin_jc_init(void) | ||
241 | { | ||
242 | int ret; | ||
243 | |||
244 | bfin_jc_kthread = kthread_create(bfin_jc_emudat_manager, NULL, DRV_NAME); | ||
245 | if (IS_ERR(bfin_jc_kthread)) | ||
246 | return PTR_ERR(bfin_jc_kthread); | ||
247 | |||
248 | ret = -ENOMEM; | ||
249 | |||
250 | bfin_jc_write_buf.head = bfin_jc_write_buf.tail = 0; | ||
251 | bfin_jc_write_buf.buf = kmalloc(CIRC_SIZE, GFP_KERNEL); | ||
252 | if (!bfin_jc_write_buf.buf) | ||
253 | goto err; | ||
254 | |||
255 | bfin_jc_driver = alloc_tty_driver(1); | ||
256 | if (!bfin_jc_driver) | ||
257 | goto err; | ||
258 | |||
259 | bfin_jc_driver->owner = THIS_MODULE; | ||
260 | bfin_jc_driver->driver_name = DRV_NAME; | ||
261 | bfin_jc_driver->name = DEV_NAME; | ||
262 | bfin_jc_driver->type = TTY_DRIVER_TYPE_SERIAL; | ||
263 | bfin_jc_driver->subtype = SERIAL_TYPE_NORMAL; | ||
264 | bfin_jc_driver->init_termios = tty_std_termios; | ||
265 | tty_set_operations(bfin_jc_driver, &bfin_jc_ops); | ||
266 | |||
267 | ret = tty_register_driver(bfin_jc_driver); | ||
268 | if (ret) | ||
269 | goto err; | ||
270 | |||
271 | pr_init(KERN_INFO DRV_NAME ": initialized\n"); | ||
272 | |||
273 | return 0; | ||
274 | |||
275 | err: | ||
276 | put_tty_driver(bfin_jc_driver); | ||
277 | kfree(bfin_jc_write_buf.buf); | ||
278 | kthread_stop(bfin_jc_kthread); | ||
279 | return ret; | ||
280 | } | ||
281 | module_init(bfin_jc_init); | ||
282 | |||
283 | static void __exit bfin_jc_exit(void) | ||
284 | { | ||
285 | kthread_stop(bfin_jc_kthread); | ||
286 | kfree(bfin_jc_write_buf.buf); | ||
287 | tty_unregister_driver(bfin_jc_driver); | ||
288 | put_tty_driver(bfin_jc_driver); | ||
289 | } | ||
290 | module_exit(bfin_jc_exit); | ||
291 | |||
292 | #if defined(CONFIG_BFIN_JTAG_COMM_CONSOLE) || defined(CONFIG_EARLY_PRINTK) | ||
293 | static void | ||
294 | bfin_jc_straight_buffer_write(const char *buf, unsigned count) | ||
295 | { | ||
296 | unsigned ate = 0; | ||
297 | while (bfin_read_DBGSTAT() & EMUDOF) | ||
298 | continue; | ||
299 | bfin_write_emudat(count); | ||
300 | while (ate < count) { | ||
301 | while (bfin_read_DBGSTAT() & EMUDOF) | ||
302 | continue; | ||
303 | bfin_write_emudat_chars(buf[ate], buf[ate+1], buf[ate+2], buf[ate+3]); | ||
304 | ate += 4; | ||
305 | } | ||
306 | } | ||
307 | #endif | ||
308 | |||
309 | #ifdef CONFIG_BFIN_JTAG_COMM_CONSOLE | ||
310 | static void | ||
311 | bfin_jc_console_write(struct console *co, const char *buf, unsigned count) | ||
312 | { | ||
313 | if (bfin_jc_kthread == NULL) | ||
314 | bfin_jc_straight_buffer_write(buf, count); | ||
315 | else | ||
316 | bfin_jc_circ_write(buf, count); | ||
317 | } | ||
318 | |||
319 | static struct tty_driver * | ||
320 | bfin_jc_console_device(struct console *co, int *index) | ||
321 | { | ||
322 | *index = co->index; | ||
323 | return bfin_jc_driver; | ||
324 | } | ||
325 | |||
326 | static struct console bfin_jc_console = { | ||
327 | .name = DEV_NAME, | ||
328 | .write = bfin_jc_console_write, | ||
329 | .device = bfin_jc_console_device, | ||
330 | .flags = CON_ANYTIME | CON_PRINTBUFFER, | ||
331 | .index = -1, | ||
332 | }; | ||
333 | |||
334 | static int __init bfin_jc_console_init(void) | ||
335 | { | ||
336 | register_console(&bfin_jc_console); | ||
337 | return 0; | ||
338 | } | ||
339 | console_initcall(bfin_jc_console_init); | ||
340 | #endif | ||
341 | |||
342 | #ifdef CONFIG_EARLY_PRINTK | ||
343 | static void __init | ||
344 | bfin_jc_early_write(struct console *co, const char *buf, unsigned int count) | ||
345 | { | ||
346 | bfin_jc_straight_buffer_write(buf, count); | ||
347 | } | ||
348 | |||
349 | static struct __initdata console bfin_jc_early_console = { | ||
350 | .name = "early_BFJC", | ||
351 | .write = bfin_jc_early_write, | ||
352 | .flags = CON_ANYTIME | CON_PRINTBUFFER, | ||
353 | .index = -1, | ||
354 | }; | ||
355 | |||
356 | struct console * __init | ||
357 | bfin_jc_early_init(unsigned int port, unsigned int cflag) | ||
358 | { | ||
359 | return &bfin_jc_early_console; | ||
360 | } | ||
361 | #endif | ||
362 | |||
363 | MODULE_AUTHOR("Mike Frysinger <vapier@gentoo.org>"); | ||
364 | MODULE_DESCRIPTION("TTY over Blackfin JTAG Communication"); | ||
365 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/char/cyclades.c b/drivers/char/cyclades.c index 1fdb9f657d8f..f3366d3f06cf 100644 --- a/drivers/char/cyclades.c +++ b/drivers/char/cyclades.c | |||
@@ -604,7 +604,6 @@ | |||
604 | 604 | ||
605 | #define NR_PORTS 256 | 605 | #define NR_PORTS 256 |
606 | 606 | ||
607 | #define ZE_V1_NPORTS 64 | ||
608 | #define ZO_V1 0 | 607 | #define ZO_V1 0 |
609 | #define ZO_V2 1 | 608 | #define ZO_V2 1 |
610 | #define ZE_V1 2 | 609 | #define ZE_V1 2 |
@@ -663,18 +662,6 @@ | |||
663 | static void cy_throttle(struct tty_struct *tty); | 662 | static void cy_throttle(struct tty_struct *tty); |
664 | static void cy_send_xchar(struct tty_struct *tty, char ch); | 663 | static void cy_send_xchar(struct tty_struct *tty, char ch); |
665 | 664 | ||
666 | #define IS_CYC_Z(card) ((card).num_chips == (unsigned int)-1) | ||
667 | |||
668 | #define Z_FPGA_CHECK(card) \ | ||
669 | ((readl(&((struct RUNTIME_9060 __iomem *) \ | ||
670 | ((card).ctl_addr))->init_ctrl) & (1<<17)) != 0) | ||
671 | |||
672 | #define ISZLOADED(card) (((ZO_V1 == readl(&((struct RUNTIME_9060 __iomem *) \ | ||
673 | ((card).ctl_addr))->mail_box_0)) || \ | ||
674 | Z_FPGA_CHECK(card)) && \ | ||
675 | (ZFIRM_ID == readl(&((struct FIRM_ID __iomem *) \ | ||
676 | ((card).base_addr+ID_ADDRESS))->signature))) | ||
677 | |||
678 | #ifndef SERIAL_XMIT_SIZE | 665 | #ifndef SERIAL_XMIT_SIZE |
679 | #define SERIAL_XMIT_SIZE (min(PAGE_SIZE, 4096)) | 666 | #define SERIAL_XMIT_SIZE (min(PAGE_SIZE, 4096)) |
680 | #endif | 667 | #endif |
@@ -687,8 +674,6 @@ static void cy_send_xchar(struct tty_struct *tty, char ch); | |||
687 | #define DRIVER_VERSION 0x02010203 | 674 | #define DRIVER_VERSION 0x02010203 |
688 | #define RAM_SIZE 0x80000 | 675 | #define RAM_SIZE 0x80000 |
689 | 676 | ||
690 | #define Z_FPGA_LOADED(X) ((readl(&(X)->init_ctrl) & (1<<17)) != 0) | ||
691 | |||
692 | enum zblock_type { | 677 | enum zblock_type { |
693 | ZBLOCK_PRG = 0, | 678 | ZBLOCK_PRG = 0, |
694 | ZBLOCK_FPGA = 1 | 679 | ZBLOCK_FPGA = 1 |
@@ -883,6 +868,29 @@ static void cyz_rx_restart(unsigned long); | |||
883 | static struct timer_list cyz_rx_full_timer[NR_PORTS]; | 868 | static struct timer_list cyz_rx_full_timer[NR_PORTS]; |
884 | #endif /* CONFIG_CYZ_INTR */ | 869 | #endif /* CONFIG_CYZ_INTR */ |
885 | 870 | ||
871 | static inline bool cy_is_Z(struct cyclades_card *card) | ||
872 | { | ||
873 | return card->num_chips == (unsigned int)-1; | ||
874 | } | ||
875 | |||
876 | static inline bool __cyz_fpga_loaded(struct RUNTIME_9060 __iomem *ctl_addr) | ||
877 | { | ||
878 | return readl(&ctl_addr->init_ctrl) & (1 << 17); | ||
879 | } | ||
880 | |||
881 | static inline bool cyz_fpga_loaded(struct cyclades_card *card) | ||
882 | { | ||
883 | return __cyz_fpga_loaded(card->ctl_addr.p9060); | ||
884 | } | ||
885 | |||
886 | static inline bool cyz_is_loaded(struct cyclades_card *card) | ||
887 | { | ||
888 | struct FIRM_ID __iomem *fw_id = card->base_addr + ID_ADDRESS; | ||
889 | |||
890 | return (card->hw_ver == ZO_V1 || cyz_fpga_loaded(card)) && | ||
891 | readl(&fw_id->signature) == ZFIRM_ID; | ||
892 | } | ||
893 | |||
886 | static inline int serial_paranoia_check(struct cyclades_port *info, | 894 | static inline int serial_paranoia_check(struct cyclades_port *info, |
887 | char *name, const char *routine) | 895 | char *name, const char *routine) |
888 | { | 896 | { |
@@ -1395,19 +1403,15 @@ cyz_fetch_msg(struct cyclades_card *cinfo, | |||
1395 | unsigned long loc_doorbell; | 1403 | unsigned long loc_doorbell; |
1396 | 1404 | ||
1397 | firm_id = cinfo->base_addr + ID_ADDRESS; | 1405 | firm_id = cinfo->base_addr + ID_ADDRESS; |
1398 | if (!ISZLOADED(*cinfo)) | ||
1399 | return -1; | ||
1400 | zfw_ctrl = cinfo->base_addr + (readl(&firm_id->zfwctrl_addr) & 0xfffff); | 1406 | zfw_ctrl = cinfo->base_addr + (readl(&firm_id->zfwctrl_addr) & 0xfffff); |
1401 | board_ctrl = &zfw_ctrl->board_ctrl; | 1407 | board_ctrl = &zfw_ctrl->board_ctrl; |
1402 | 1408 | ||
1403 | loc_doorbell = readl(&((struct RUNTIME_9060 __iomem *) | 1409 | loc_doorbell = readl(&cinfo->ctl_addr.p9060->loc_doorbell); |
1404 | (cinfo->ctl_addr))->loc_doorbell); | ||
1405 | if (loc_doorbell) { | 1410 | if (loc_doorbell) { |
1406 | *cmd = (char)(0xff & loc_doorbell); | 1411 | *cmd = (char)(0xff & loc_doorbell); |
1407 | *channel = readl(&board_ctrl->fwcmd_channel); | 1412 | *channel = readl(&board_ctrl->fwcmd_channel); |
1408 | *param = (__u32) readl(&board_ctrl->fwcmd_param); | 1413 | *param = (__u32) readl(&board_ctrl->fwcmd_param); |
1409 | cy_writel(&((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))-> | 1414 | cy_writel(&cinfo->ctl_addr.p9060->loc_doorbell, 0xffffffff); |
1410 | loc_doorbell, 0xffffffff); | ||
1411 | return 1; | 1415 | return 1; |
1412 | } | 1416 | } |
1413 | return 0; | 1417 | return 0; |
@@ -1424,15 +1428,14 @@ cyz_issue_cmd(struct cyclades_card *cinfo, | |||
1424 | unsigned int index; | 1428 | unsigned int index; |
1425 | 1429 | ||
1426 | firm_id = cinfo->base_addr + ID_ADDRESS; | 1430 | firm_id = cinfo->base_addr + ID_ADDRESS; |
1427 | if (!ISZLOADED(*cinfo)) | 1431 | if (!cyz_is_loaded(cinfo)) |
1428 | return -1; | 1432 | return -1; |
1429 | 1433 | ||
1430 | zfw_ctrl = cinfo->base_addr + (readl(&firm_id->zfwctrl_addr) & 0xfffff); | 1434 | zfw_ctrl = cinfo->base_addr + (readl(&firm_id->zfwctrl_addr) & 0xfffff); |
1431 | board_ctrl = &zfw_ctrl->board_ctrl; | 1435 | board_ctrl = &zfw_ctrl->board_ctrl; |
1432 | 1436 | ||
1433 | index = 0; | 1437 | index = 0; |
1434 | pci_doorbell = | 1438 | pci_doorbell = &cinfo->ctl_addr.p9060->pci_doorbell; |
1435 | &((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))->pci_doorbell; | ||
1436 | while ((readl(pci_doorbell) & 0xff) != 0) { | 1439 | while ((readl(pci_doorbell) & 0xff) != 0) { |
1437 | if (index++ == 1000) | 1440 | if (index++ == 1000) |
1438 | return (int)(readl(pci_doorbell) & 0xff); | 1441 | return (int)(readl(pci_doorbell) & 0xff); |
@@ -1624,10 +1627,8 @@ static void cyz_handle_cmd(struct cyclades_card *cinfo) | |||
1624 | static struct BOARD_CTRL __iomem *board_ctrl; | 1627 | static struct BOARD_CTRL __iomem *board_ctrl; |
1625 | static struct CH_CTRL __iomem *ch_ctrl; | 1628 | static struct CH_CTRL __iomem *ch_ctrl; |
1626 | static struct BUF_CTRL __iomem *buf_ctrl; | 1629 | static struct BUF_CTRL __iomem *buf_ctrl; |
1627 | __u32 channel; | 1630 | __u32 channel, param, fw_ver; |
1628 | __u8 cmd; | 1631 | __u8 cmd; |
1629 | __u32 param; | ||
1630 | __u32 hw_ver, fw_ver; | ||
1631 | int special_count; | 1632 | int special_count; |
1632 | int delta_count; | 1633 | int delta_count; |
1633 | 1634 | ||
@@ -1635,8 +1636,6 @@ static void cyz_handle_cmd(struct cyclades_card *cinfo) | |||
1635 | zfw_ctrl = cinfo->base_addr + (readl(&firm_id->zfwctrl_addr) & 0xfffff); | 1636 | zfw_ctrl = cinfo->base_addr + (readl(&firm_id->zfwctrl_addr) & 0xfffff); |
1636 | board_ctrl = &zfw_ctrl->board_ctrl; | 1637 | board_ctrl = &zfw_ctrl->board_ctrl; |
1637 | fw_ver = readl(&board_ctrl->fw_version); | 1638 | fw_ver = readl(&board_ctrl->fw_version); |
1638 | hw_ver = readl(&((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))-> | ||
1639 | mail_box_0); | ||
1640 | 1639 | ||
1641 | while (cyz_fetch_msg(cinfo, &channel, &cmd, ¶m) == 1) { | 1640 | while (cyz_fetch_msg(cinfo, &channel, &cmd, ¶m) == 1) { |
1642 | special_count = 0; | 1641 | special_count = 0; |
@@ -1737,15 +1736,7 @@ static irqreturn_t cyz_interrupt(int irq, void *dev_id) | |||
1737 | { | 1736 | { |
1738 | struct cyclades_card *cinfo = dev_id; | 1737 | struct cyclades_card *cinfo = dev_id; |
1739 | 1738 | ||
1740 | if (unlikely(cinfo == NULL)) { | 1739 | if (unlikely(!cyz_is_loaded(cinfo))) { |
1741 | #ifdef CY_DEBUG_INTERRUPTS | ||
1742 | printk(KERN_DEBUG "cyz_interrupt: spurious interrupt %d\n", | ||
1743 | irq); | ||
1744 | #endif | ||
1745 | return IRQ_NONE; /* spurious interrupt */ | ||
1746 | } | ||
1747 | |||
1748 | if (unlikely(!ISZLOADED(*cinfo))) { | ||
1749 | #ifdef CY_DEBUG_INTERRUPTS | 1740 | #ifdef CY_DEBUG_INTERRUPTS |
1750 | printk(KERN_DEBUG "cyz_interrupt: board not yet loaded " | 1741 | printk(KERN_DEBUG "cyz_interrupt: board not yet loaded " |
1751 | "(IRQ%d).\n", irq); | 1742 | "(IRQ%d).\n", irq); |
@@ -1785,7 +1776,6 @@ static void cyz_poll(unsigned long arg) | |||
1785 | struct tty_struct *tty; | 1776 | struct tty_struct *tty; |
1786 | struct FIRM_ID __iomem *firm_id; | 1777 | struct FIRM_ID __iomem *firm_id; |
1787 | struct ZFW_CTRL __iomem *zfw_ctrl; | 1778 | struct ZFW_CTRL __iomem *zfw_ctrl; |
1788 | struct BOARD_CTRL __iomem *board_ctrl; | ||
1789 | struct BUF_CTRL __iomem *buf_ctrl; | 1779 | struct BUF_CTRL __iomem *buf_ctrl; |
1790 | unsigned long expires = jiffies + HZ; | 1780 | unsigned long expires = jiffies + HZ; |
1791 | unsigned int port, card; | 1781 | unsigned int port, card; |
@@ -1793,19 +1783,17 @@ static void cyz_poll(unsigned long arg) | |||
1793 | for (card = 0; card < NR_CARDS; card++) { | 1783 | for (card = 0; card < NR_CARDS; card++) { |
1794 | cinfo = &cy_card[card]; | 1784 | cinfo = &cy_card[card]; |
1795 | 1785 | ||
1796 | if (!IS_CYC_Z(*cinfo)) | 1786 | if (!cy_is_Z(cinfo)) |
1797 | continue; | 1787 | continue; |
1798 | if (!ISZLOADED(*cinfo)) | 1788 | if (!cyz_is_loaded(cinfo)) |
1799 | continue; | 1789 | continue; |
1800 | 1790 | ||
1801 | firm_id = cinfo->base_addr + ID_ADDRESS; | 1791 | firm_id = cinfo->base_addr + ID_ADDRESS; |
1802 | zfw_ctrl = cinfo->base_addr + | 1792 | zfw_ctrl = cinfo->base_addr + |
1803 | (readl(&firm_id->zfwctrl_addr) & 0xfffff); | 1793 | (readl(&firm_id->zfwctrl_addr) & 0xfffff); |
1804 | board_ctrl = &(zfw_ctrl->board_ctrl); | ||
1805 | 1794 | ||
1806 | /* Skip first polling cycle to avoid racing conditions with the FW */ | 1795 | /* Skip first polling cycle to avoid racing conditions with the FW */ |
1807 | if (!cinfo->intr_enabled) { | 1796 | if (!cinfo->intr_enabled) { |
1808 | cinfo->nports = (int)readl(&board_ctrl->n_channel); | ||
1809 | cinfo->intr_enabled = 1; | 1797 | cinfo->intr_enabled = 1; |
1810 | continue; | 1798 | continue; |
1811 | } | 1799 | } |
@@ -1874,7 +1862,7 @@ static int startup(struct cyclades_port *info) | |||
1874 | 1862 | ||
1875 | set_line_char(info); | 1863 | set_line_char(info); |
1876 | 1864 | ||
1877 | if (!IS_CYC_Z(*card)) { | 1865 | if (!cy_is_Z(card)) { |
1878 | chip = channel >> 2; | 1866 | chip = channel >> 2; |
1879 | channel &= 0x03; | 1867 | channel &= 0x03; |
1880 | index = card->bus_index; | 1868 | index = card->bus_index; |
@@ -1931,7 +1919,7 @@ static int startup(struct cyclades_port *info) | |||
1931 | base_addr = card->base_addr; | 1919 | base_addr = card->base_addr; |
1932 | 1920 | ||
1933 | firm_id = base_addr + ID_ADDRESS; | 1921 | firm_id = base_addr + ID_ADDRESS; |
1934 | if (!ISZLOADED(*card)) | 1922 | if (!cyz_is_loaded(card)) |
1935 | return -ENODEV; | 1923 | return -ENODEV; |
1936 | 1924 | ||
1937 | zfw_ctrl = card->base_addr + | 1925 | zfw_ctrl = card->base_addr + |
@@ -2026,7 +2014,7 @@ static void start_xmit(struct cyclades_port *info) | |||
2026 | 2014 | ||
2027 | card = info->card; | 2015 | card = info->card; |
2028 | channel = info->line - card->first_line; | 2016 | channel = info->line - card->first_line; |
2029 | if (!IS_CYC_Z(*card)) { | 2017 | if (!cy_is_Z(card)) { |
2030 | chip = channel >> 2; | 2018 | chip = channel >> 2; |
2031 | channel &= 0x03; | 2019 | channel &= 0x03; |
2032 | index = card->bus_index; | 2020 | index = card->bus_index; |
@@ -2070,7 +2058,7 @@ static void shutdown(struct cyclades_port *info) | |||
2070 | 2058 | ||
2071 | card = info->card; | 2059 | card = info->card; |
2072 | channel = info->line - card->first_line; | 2060 | channel = info->line - card->first_line; |
2073 | if (!IS_CYC_Z(*card)) { | 2061 | if (!cy_is_Z(card)) { |
2074 | chip = channel >> 2; | 2062 | chip = channel >> 2; |
2075 | channel &= 0x03; | 2063 | channel &= 0x03; |
2076 | index = card->bus_index; | 2064 | index = card->bus_index; |
@@ -2126,7 +2114,7 @@ static void shutdown(struct cyclades_port *info) | |||
2126 | #endif | 2114 | #endif |
2127 | 2115 | ||
2128 | firm_id = base_addr + ID_ADDRESS; | 2116 | firm_id = base_addr + ID_ADDRESS; |
2129 | if (!ISZLOADED(*card)) | 2117 | if (!cyz_is_loaded(card)) |
2130 | return; | 2118 | return; |
2131 | 2119 | ||
2132 | zfw_ctrl = card->base_addr + | 2120 | zfw_ctrl = card->base_addr + |
@@ -2233,7 +2221,7 @@ block_til_ready(struct tty_struct *tty, struct file *filp, | |||
2233 | #endif | 2221 | #endif |
2234 | info->port.blocked_open++; | 2222 | info->port.blocked_open++; |
2235 | 2223 | ||
2236 | if (!IS_CYC_Z(*cinfo)) { | 2224 | if (!cy_is_Z(cinfo)) { |
2237 | chip = channel >> 2; | 2225 | chip = channel >> 2; |
2238 | channel &= 0x03; | 2226 | channel &= 0x03; |
2239 | index = cinfo->bus_index; | 2227 | index = cinfo->bus_index; |
@@ -2296,7 +2284,7 @@ block_til_ready(struct tty_struct *tty, struct file *filp, | |||
2296 | 2284 | ||
2297 | base_addr = cinfo->base_addr; | 2285 | base_addr = cinfo->base_addr; |
2298 | firm_id = base_addr + ID_ADDRESS; | 2286 | firm_id = base_addr + ID_ADDRESS; |
2299 | if (!ISZLOADED(*cinfo)) { | 2287 | if (!cyz_is_loaded(cinfo)) { |
2300 | __set_current_state(TASK_RUNNING); | 2288 | __set_current_state(TASK_RUNNING); |
2301 | remove_wait_queue(&info->port.open_wait, &wait); | 2289 | remove_wait_queue(&info->port.open_wait, &wait); |
2302 | return -EINVAL; | 2290 | return -EINVAL; |
@@ -2397,16 +2385,14 @@ static int cy_open(struct tty_struct *tty, struct file *filp) | |||
2397 | treat it as absent from the system. This | 2385 | treat it as absent from the system. This |
2398 | will make the user pay attention. | 2386 | will make the user pay attention. |
2399 | */ | 2387 | */ |
2400 | if (IS_CYC_Z(*info->card)) { | 2388 | if (cy_is_Z(info->card)) { |
2401 | struct cyclades_card *cinfo = info->card; | 2389 | struct cyclades_card *cinfo = info->card; |
2402 | struct FIRM_ID __iomem *firm_id = cinfo->base_addr + ID_ADDRESS; | 2390 | struct FIRM_ID __iomem *firm_id = cinfo->base_addr + ID_ADDRESS; |
2403 | 2391 | ||
2404 | if (!ISZLOADED(*cinfo)) { | 2392 | if (!cyz_is_loaded(cinfo)) { |
2405 | if (((ZE_V1 == readl(&((struct RUNTIME_9060 __iomem *) | 2393 | if (cinfo->hw_ver == ZE_V1 && cyz_fpga_loaded(cinfo) && |
2406 | (cinfo->ctl_addr))->mail_box_0)) && | 2394 | readl(&firm_id->signature) == |
2407 | Z_FPGA_CHECK(*cinfo)) && | 2395 | ZFIRM_HLT) { |
2408 | (ZFIRM_HLT == readl( | ||
2409 | &firm_id->signature))) { | ||
2410 | printk(KERN_ERR "cyc:Cyclades-Z Error: you " | 2396 | printk(KERN_ERR "cyc:Cyclades-Z Error: you " |
2411 | "need an external power supply for " | 2397 | "need an external power supply for " |
2412 | "this number of ports.\nFirmware " | 2398 | "this number of ports.\nFirmware " |
@@ -2423,18 +2409,13 @@ static int cy_open(struct tty_struct *tty, struct file *filp) | |||
2423 | interrupts should be enabled as soon as the first open | 2409 | interrupts should be enabled as soon as the first open |
2424 | happens to one of its ports. */ | 2410 | happens to one of its ports. */ |
2425 | if (!cinfo->intr_enabled) { | 2411 | if (!cinfo->intr_enabled) { |
2426 | struct ZFW_CTRL __iomem *zfw_ctrl; | 2412 | u16 intr; |
2427 | struct BOARD_CTRL __iomem *board_ctrl; | ||
2428 | |||
2429 | zfw_ctrl = cinfo->base_addr + | ||
2430 | (readl(&firm_id->zfwctrl_addr) & | ||
2431 | 0xfffff); | ||
2432 | |||
2433 | board_ctrl = &zfw_ctrl->board_ctrl; | ||
2434 | 2413 | ||
2435 | /* Enable interrupts on the PLX chip */ | 2414 | /* Enable interrupts on the PLX chip */ |
2436 | cy_writew(cinfo->ctl_addr + 0x68, | 2415 | intr = readw(&cinfo->ctl_addr.p9060-> |
2437 | readw(cinfo->ctl_addr + 0x68) | 0x0900); | 2416 | intr_ctrl_stat) | 0x0900; |
2417 | cy_writew(&cinfo->ctl_addr.p9060-> | ||
2418 | intr_ctrl_stat, intr); | ||
2438 | /* Enable interrupts on the FW */ | 2419 | /* Enable interrupts on the FW */ |
2439 | retval = cyz_issue_cmd(cinfo, 0, | 2420 | retval = cyz_issue_cmd(cinfo, 0, |
2440 | C_CM_IRQ_ENBL, 0L); | 2421 | C_CM_IRQ_ENBL, 0L); |
@@ -2442,8 +2423,6 @@ static int cy_open(struct tty_struct *tty, struct file *filp) | |||
2442 | printk(KERN_ERR "cyc:IRQ enable retval " | 2423 | printk(KERN_ERR "cyc:IRQ enable retval " |
2443 | "was %x\n", retval); | 2424 | "was %x\n", retval); |
2444 | } | 2425 | } |
2445 | cinfo->nports = | ||
2446 | (int)readl(&board_ctrl->n_channel); | ||
2447 | cinfo->intr_enabled = 1; | 2426 | cinfo->intr_enabled = 1; |
2448 | } | 2427 | } |
2449 | } | 2428 | } |
@@ -2556,7 +2535,7 @@ static void cy_wait_until_sent(struct tty_struct *tty, int timeout) | |||
2556 | #endif | 2535 | #endif |
2557 | card = info->card; | 2536 | card = info->card; |
2558 | channel = (info->line) - (card->first_line); | 2537 | channel = (info->line) - (card->first_line); |
2559 | if (!IS_CYC_Z(*card)) { | 2538 | if (!cy_is_Z(card)) { |
2560 | chip = channel >> 2; | 2539 | chip = channel >> 2; |
2561 | channel &= 0x03; | 2540 | channel &= 0x03; |
2562 | index = card->bus_index; | 2541 | index = card->bus_index; |
@@ -2601,7 +2580,7 @@ static void cy_flush_buffer(struct tty_struct *tty) | |||
2601 | info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; | 2580 | info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; |
2602 | spin_unlock_irqrestore(&card->card_lock, flags); | 2581 | spin_unlock_irqrestore(&card->card_lock, flags); |
2603 | 2582 | ||
2604 | if (IS_CYC_Z(*card)) { /* If it is a Z card, flush the on-board | 2583 | if (cy_is_Z(card)) { /* If it is a Z card, flush the on-board |
2605 | buffers as well */ | 2584 | buffers as well */ |
2606 | spin_lock_irqsave(&card->card_lock, flags); | 2585 | spin_lock_irqsave(&card->card_lock, flags); |
2607 | retval = cyz_issue_cmd(card, channel, C_CM_FLUSH_TX, 0L); | 2586 | retval = cyz_issue_cmd(card, channel, C_CM_FLUSH_TX, 0L); |
@@ -2682,7 +2661,7 @@ static void cy_close(struct tty_struct *tty, struct file *filp) | |||
2682 | 2661 | ||
2683 | spin_lock_irqsave(&card->card_lock, flags); | 2662 | spin_lock_irqsave(&card->card_lock, flags); |
2684 | 2663 | ||
2685 | if (!IS_CYC_Z(*card)) { | 2664 | if (!cy_is_Z(card)) { |
2686 | int channel = info->line - card->first_line; | 2665 | int channel = info->line - card->first_line; |
2687 | int index = card->bus_index; | 2666 | int index = card->bus_index; |
2688 | void __iomem *base_addr = card->base_addr + | 2667 | void __iomem *base_addr = card->base_addr + |
@@ -2902,7 +2881,7 @@ static int cy_chars_in_buffer(struct tty_struct *tty) | |||
2902 | channel = (info->line) - (card->first_line); | 2881 | channel = (info->line) - (card->first_line); |
2903 | 2882 | ||
2904 | #ifdef Z_EXT_CHARS_IN_BUFFER | 2883 | #ifdef Z_EXT_CHARS_IN_BUFFER |
2905 | if (!IS_CYC_Z(cy_card[card])) { | 2884 | if (!cy_is_Z(card)) { |
2906 | #endif /* Z_EXT_CHARS_IN_BUFFER */ | 2885 | #endif /* Z_EXT_CHARS_IN_BUFFER */ |
2907 | #ifdef CY_DEBUG_IO | 2886 | #ifdef CY_DEBUG_IO |
2908 | printk(KERN_DEBUG "cyc:cy_chars_in_buffer ttyC%d %d\n", | 2887 | printk(KERN_DEBUG "cyc:cy_chars_in_buffer ttyC%d %d\n", |
@@ -2984,7 +2963,6 @@ static void set_line_char(struct cyclades_port *info) | |||
2984 | void __iomem *base_addr; | 2963 | void __iomem *base_addr; |
2985 | int chip, channel, index; | 2964 | int chip, channel, index; |
2986 | unsigned cflag, iflag; | 2965 | unsigned cflag, iflag; |
2987 | unsigned short chip_number; | ||
2988 | int baud, baud_rate = 0; | 2966 | int baud, baud_rate = 0; |
2989 | int i; | 2967 | int i; |
2990 | 2968 | ||
@@ -3013,9 +2991,8 @@ static void set_line_char(struct cyclades_port *info) | |||
3013 | 2991 | ||
3014 | card = info->card; | 2992 | card = info->card; |
3015 | channel = info->line - card->first_line; | 2993 | channel = info->line - card->first_line; |
3016 | chip_number = channel / 4; | ||
3017 | 2994 | ||
3018 | if (!IS_CYC_Z(*card)) { | 2995 | if (!cy_is_Z(card)) { |
3019 | 2996 | ||
3020 | index = card->bus_index; | 2997 | index = card->bus_index; |
3021 | 2998 | ||
@@ -3233,21 +3210,17 @@ static void set_line_char(struct cyclades_port *info) | |||
3233 | } else { | 3210 | } else { |
3234 | struct FIRM_ID __iomem *firm_id; | 3211 | struct FIRM_ID __iomem *firm_id; |
3235 | struct ZFW_CTRL __iomem *zfw_ctrl; | 3212 | struct ZFW_CTRL __iomem *zfw_ctrl; |
3236 | struct BOARD_CTRL __iomem *board_ctrl; | ||
3237 | struct CH_CTRL __iomem *ch_ctrl; | 3213 | struct CH_CTRL __iomem *ch_ctrl; |
3238 | struct BUF_CTRL __iomem *buf_ctrl; | ||
3239 | __u32 sw_flow; | 3214 | __u32 sw_flow; |
3240 | int retval; | 3215 | int retval; |
3241 | 3216 | ||
3242 | firm_id = card->base_addr + ID_ADDRESS; | 3217 | firm_id = card->base_addr + ID_ADDRESS; |
3243 | if (!ISZLOADED(*card)) | 3218 | if (!cyz_is_loaded(card)) |
3244 | return; | 3219 | return; |
3245 | 3220 | ||
3246 | zfw_ctrl = card->base_addr + | 3221 | zfw_ctrl = card->base_addr + |
3247 | (readl(&firm_id->zfwctrl_addr) & 0xfffff); | 3222 | (readl(&firm_id->zfwctrl_addr) & 0xfffff); |
3248 | board_ctrl = &zfw_ctrl->board_ctrl; | ||
3249 | ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]); | 3223 | ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]); |
3250 | buf_ctrl = &zfw_ctrl->buf_ctrl[channel]; | ||
3251 | 3224 | ||
3252 | /* baud rate */ | 3225 | /* baud rate */ |
3253 | baud = tty_get_baud_rate(info->port.tty); | 3226 | baud = tty_get_baud_rate(info->port.tty); |
@@ -3457,7 +3430,7 @@ static int get_lsr_info(struct cyclades_port *info, unsigned int __user *value) | |||
3457 | 3430 | ||
3458 | card = info->card; | 3431 | card = info->card; |
3459 | channel = (info->line) - (card->first_line); | 3432 | channel = (info->line) - (card->first_line); |
3460 | if (!IS_CYC_Z(*card)) { | 3433 | if (!cy_is_Z(card)) { |
3461 | chip = channel >> 2; | 3434 | chip = channel >> 2; |
3462 | channel &= 0x03; | 3435 | channel &= 0x03; |
3463 | index = card->bus_index; | 3436 | index = card->bus_index; |
@@ -3497,7 +3470,7 @@ static int cy_tiocmget(struct tty_struct *tty, struct file *file) | |||
3497 | 3470 | ||
3498 | card = info->card; | 3471 | card = info->card; |
3499 | channel = info->line - card->first_line; | 3472 | channel = info->line - card->first_line; |
3500 | if (!IS_CYC_Z(*card)) { | 3473 | if (!cy_is_Z(card)) { |
3501 | chip = channel >> 2; | 3474 | chip = channel >> 2; |
3502 | channel &= 0x03; | 3475 | channel &= 0x03; |
3503 | index = card->bus_index; | 3476 | index = card->bus_index; |
@@ -3523,7 +3496,7 @@ static int cy_tiocmget(struct tty_struct *tty, struct file *file) | |||
3523 | } else { | 3496 | } else { |
3524 | base_addr = card->base_addr; | 3497 | base_addr = card->base_addr; |
3525 | firm_id = card->base_addr + ID_ADDRESS; | 3498 | firm_id = card->base_addr + ID_ADDRESS; |
3526 | if (ISZLOADED(*card)) { | 3499 | if (cyz_is_loaded(card)) { |
3527 | zfw_ctrl = card->base_addr + | 3500 | zfw_ctrl = card->base_addr + |
3528 | (readl(&firm_id->zfwctrl_addr) & 0xfffff); | 3501 | (readl(&firm_id->zfwctrl_addr) & 0xfffff); |
3529 | board_ctrl = &zfw_ctrl->board_ctrl; | 3502 | board_ctrl = &zfw_ctrl->board_ctrl; |
@@ -3566,7 +3539,7 @@ cy_tiocmset(struct tty_struct *tty, struct file *file, | |||
3566 | 3539 | ||
3567 | card = info->card; | 3540 | card = info->card; |
3568 | channel = (info->line) - (card->first_line); | 3541 | channel = (info->line) - (card->first_line); |
3569 | if (!IS_CYC_Z(*card)) { | 3542 | if (!cy_is_Z(card)) { |
3570 | chip = channel >> 2; | 3543 | chip = channel >> 2; |
3571 | channel &= 0x03; | 3544 | channel &= 0x03; |
3572 | index = card->bus_index; | 3545 | index = card->bus_index; |
@@ -3641,7 +3614,7 @@ cy_tiocmset(struct tty_struct *tty, struct file *file, | |||
3641 | base_addr = card->base_addr; | 3614 | base_addr = card->base_addr; |
3642 | 3615 | ||
3643 | firm_id = card->base_addr + ID_ADDRESS; | 3616 | firm_id = card->base_addr + ID_ADDRESS; |
3644 | if (ISZLOADED(*card)) { | 3617 | if (cyz_is_loaded(card)) { |
3645 | zfw_ctrl = card->base_addr + | 3618 | zfw_ctrl = card->base_addr + |
3646 | (readl(&firm_id->zfwctrl_addr) & 0xfffff); | 3619 | (readl(&firm_id->zfwctrl_addr) & 0xfffff); |
3647 | board_ctrl = &zfw_ctrl->board_ctrl; | 3620 | board_ctrl = &zfw_ctrl->board_ctrl; |
@@ -3713,7 +3686,7 @@ static int cy_break(struct tty_struct *tty, int break_state) | |||
3713 | card = info->card; | 3686 | card = info->card; |
3714 | 3687 | ||
3715 | spin_lock_irqsave(&card->card_lock, flags); | 3688 | spin_lock_irqsave(&card->card_lock, flags); |
3716 | if (!IS_CYC_Z(*card)) { | 3689 | if (!cy_is_Z(card)) { |
3717 | /* Let the transmit ISR take care of this (since it | 3690 | /* Let the transmit ISR take care of this (since it |
3718 | requires stuffing characters into the output stream). | 3691 | requires stuffing characters into the output stream). |
3719 | */ | 3692 | */ |
@@ -3782,7 +3755,7 @@ static int set_threshold(struct cyclades_port *info, unsigned long value) | |||
3782 | 3755 | ||
3783 | card = info->card; | 3756 | card = info->card; |
3784 | channel = info->line - card->first_line; | 3757 | channel = info->line - card->first_line; |
3785 | if (!IS_CYC_Z(*card)) { | 3758 | if (!cy_is_Z(card)) { |
3786 | chip = channel >> 2; | 3759 | chip = channel >> 2; |
3787 | channel &= 0x03; | 3760 | channel &= 0x03; |
3788 | index = card->bus_index; | 3761 | index = card->bus_index; |
@@ -3810,7 +3783,7 @@ static int get_threshold(struct cyclades_port *info, | |||
3810 | 3783 | ||
3811 | card = info->card; | 3784 | card = info->card; |
3812 | channel = info->line - card->first_line; | 3785 | channel = info->line - card->first_line; |
3813 | if (!IS_CYC_Z(*card)) { | 3786 | if (!cy_is_Z(card)) { |
3814 | chip = channel >> 2; | 3787 | chip = channel >> 2; |
3815 | channel &= 0x03; | 3788 | channel &= 0x03; |
3816 | index = card->bus_index; | 3789 | index = card->bus_index; |
@@ -3844,7 +3817,7 @@ static int set_timeout(struct cyclades_port *info, unsigned long value) | |||
3844 | 3817 | ||
3845 | card = info->card; | 3818 | card = info->card; |
3846 | channel = info->line - card->first_line; | 3819 | channel = info->line - card->first_line; |
3847 | if (!IS_CYC_Z(*card)) { | 3820 | if (!cy_is_Z(card)) { |
3848 | chip = channel >> 2; | 3821 | chip = channel >> 2; |
3849 | channel &= 0x03; | 3822 | channel &= 0x03; |
3850 | index = card->bus_index; | 3823 | index = card->bus_index; |
@@ -3867,7 +3840,7 @@ static int get_timeout(struct cyclades_port *info, | |||
3867 | 3840 | ||
3868 | card = info->card; | 3841 | card = info->card; |
3869 | channel = info->line - card->first_line; | 3842 | channel = info->line - card->first_line; |
3870 | if (!IS_CYC_Z(*card)) { | 3843 | if (!cy_is_Z(card)) { |
3871 | chip = channel >> 2; | 3844 | chip = channel >> 2; |
3872 | channel &= 0x03; | 3845 | channel &= 0x03; |
3873 | index = card->bus_index; | 3846 | index = card->bus_index; |
@@ -4121,7 +4094,7 @@ static void cy_send_xchar(struct tty_struct *tty, char ch) | |||
4121 | card = info->card; | 4094 | card = info->card; |
4122 | channel = info->line - card->first_line; | 4095 | channel = info->line - card->first_line; |
4123 | 4096 | ||
4124 | if (IS_CYC_Z(*card)) { | 4097 | if (cy_is_Z(card)) { |
4125 | if (ch == STOP_CHAR(tty)) | 4098 | if (ch == STOP_CHAR(tty)) |
4126 | cyz_issue_cmd(card, channel, C_CM_SENDXOFF, 0L); | 4099 | cyz_issue_cmd(card, channel, C_CM_SENDXOFF, 0L); |
4127 | else if (ch == START_CHAR(tty)) | 4100 | else if (ch == START_CHAR(tty)) |
@@ -4154,7 +4127,7 @@ static void cy_throttle(struct tty_struct *tty) | |||
4154 | card = info->card; | 4127 | card = info->card; |
4155 | 4128 | ||
4156 | if (I_IXOFF(tty)) { | 4129 | if (I_IXOFF(tty)) { |
4157 | if (!IS_CYC_Z(*card)) | 4130 | if (!cy_is_Z(card)) |
4158 | cy_send_xchar(tty, STOP_CHAR(tty)); | 4131 | cy_send_xchar(tty, STOP_CHAR(tty)); |
4159 | else | 4132 | else |
4160 | info->throttle = 1; | 4133 | info->throttle = 1; |
@@ -4162,7 +4135,7 @@ static void cy_throttle(struct tty_struct *tty) | |||
4162 | 4135 | ||
4163 | if (tty->termios->c_cflag & CRTSCTS) { | 4136 | if (tty->termios->c_cflag & CRTSCTS) { |
4164 | channel = info->line - card->first_line; | 4137 | channel = info->line - card->first_line; |
4165 | if (!IS_CYC_Z(*card)) { | 4138 | if (!cy_is_Z(card)) { |
4166 | chip = channel >> 2; | 4139 | chip = channel >> 2; |
4167 | channel &= 0x03; | 4140 | channel &= 0x03; |
4168 | index = card->bus_index; | 4141 | index = card->bus_index; |
@@ -4219,7 +4192,7 @@ static void cy_unthrottle(struct tty_struct *tty) | |||
4219 | if (tty->termios->c_cflag & CRTSCTS) { | 4192 | if (tty->termios->c_cflag & CRTSCTS) { |
4220 | card = info->card; | 4193 | card = info->card; |
4221 | channel = info->line - card->first_line; | 4194 | channel = info->line - card->first_line; |
4222 | if (!IS_CYC_Z(*card)) { | 4195 | if (!cy_is_Z(card)) { |
4223 | chip = channel >> 2; | 4196 | chip = channel >> 2; |
4224 | channel &= 0x03; | 4197 | channel &= 0x03; |
4225 | index = card->bus_index; | 4198 | index = card->bus_index; |
@@ -4263,7 +4236,7 @@ static void cy_stop(struct tty_struct *tty) | |||
4263 | 4236 | ||
4264 | cinfo = info->card; | 4237 | cinfo = info->card; |
4265 | channel = info->line - cinfo->first_line; | 4238 | channel = info->line - cinfo->first_line; |
4266 | if (!IS_CYC_Z(*cinfo)) { | 4239 | if (!cy_is_Z(cinfo)) { |
4267 | index = cinfo->bus_index; | 4240 | index = cinfo->bus_index; |
4268 | chip = channel >> 2; | 4241 | chip = channel >> 2; |
4269 | channel &= 0x03; | 4242 | channel &= 0x03; |
@@ -4296,7 +4269,7 @@ static void cy_start(struct tty_struct *tty) | |||
4296 | cinfo = info->card; | 4269 | cinfo = info->card; |
4297 | channel = info->line - cinfo->first_line; | 4270 | channel = info->line - cinfo->first_line; |
4298 | index = cinfo->bus_index; | 4271 | index = cinfo->bus_index; |
4299 | if (!IS_CYC_Z(*cinfo)) { | 4272 | if (!cy_is_Z(cinfo)) { |
4300 | chip = channel >> 2; | 4273 | chip = channel >> 2; |
4301 | channel &= 0x03; | 4274 | channel &= 0x03; |
4302 | base_addr = cinfo->base_addr + (cy_chip_offset[chip] << index); | 4275 | base_addr = cinfo->base_addr + (cy_chip_offset[chip] << index); |
@@ -4347,33 +4320,20 @@ static void cy_hangup(struct tty_struct *tty) | |||
4347 | static int __devinit cy_init_card(struct cyclades_card *cinfo) | 4320 | static int __devinit cy_init_card(struct cyclades_card *cinfo) |
4348 | { | 4321 | { |
4349 | struct cyclades_port *info; | 4322 | struct cyclades_port *info; |
4350 | u32 uninitialized_var(mailbox); | 4323 | unsigned int port; |
4351 | unsigned int nports, port; | ||
4352 | unsigned short chip_number; | 4324 | unsigned short chip_number; |
4353 | int uninitialized_var(index); | ||
4354 | 4325 | ||
4355 | spin_lock_init(&cinfo->card_lock); | 4326 | spin_lock_init(&cinfo->card_lock); |
4327 | cinfo->intr_enabled = 0; | ||
4356 | 4328 | ||
4357 | if (IS_CYC_Z(*cinfo)) { /* Cyclades-Z */ | 4329 | cinfo->ports = kcalloc(cinfo->nports, sizeof(*cinfo->ports), |
4358 | mailbox = readl(&((struct RUNTIME_9060 __iomem *) | 4330 | GFP_KERNEL); |
4359 | cinfo->ctl_addr)->mail_box_0); | ||
4360 | nports = (mailbox == ZE_V1) ? ZE_V1_NPORTS : 8; | ||
4361 | cinfo->intr_enabled = 0; | ||
4362 | cinfo->nports = 0; /* Will be correctly set later, after | ||
4363 | Z FW is loaded */ | ||
4364 | } else { | ||
4365 | index = cinfo->bus_index; | ||
4366 | nports = cinfo->nports = CyPORTS_PER_CHIP * cinfo->num_chips; | ||
4367 | } | ||
4368 | |||
4369 | cinfo->ports = kzalloc(sizeof(*cinfo->ports) * nports, GFP_KERNEL); | ||
4370 | if (cinfo->ports == NULL) { | 4331 | if (cinfo->ports == NULL) { |
4371 | printk(KERN_ERR "Cyclades: cannot allocate ports\n"); | 4332 | printk(KERN_ERR "Cyclades: cannot allocate ports\n"); |
4372 | cinfo->nports = 0; | ||
4373 | return -ENOMEM; | 4333 | return -ENOMEM; |
4374 | } | 4334 | } |
4375 | 4335 | ||
4376 | for (port = cinfo->first_line; port < cinfo->first_line + nports; | 4336 | for (port = cinfo->first_line; port < cinfo->first_line + cinfo->nports; |
4377 | port++) { | 4337 | port++) { |
4378 | info = &cinfo->ports[port - cinfo->first_line]; | 4338 | info = &cinfo->ports[port - cinfo->first_line]; |
4379 | tty_port_init(&info->port); | 4339 | tty_port_init(&info->port); |
@@ -4387,9 +4347,9 @@ static int __devinit cy_init_card(struct cyclades_card *cinfo) | |||
4387 | init_completion(&info->shutdown_wait); | 4347 | init_completion(&info->shutdown_wait); |
4388 | init_waitqueue_head(&info->delta_msr_wait); | 4348 | init_waitqueue_head(&info->delta_msr_wait); |
4389 | 4349 | ||
4390 | if (IS_CYC_Z(*cinfo)) { | 4350 | if (cy_is_Z(cinfo)) { |
4391 | info->type = PORT_STARTECH; | 4351 | info->type = PORT_STARTECH; |
4392 | if (mailbox == ZO_V1) | 4352 | if (cinfo->hw_ver == ZO_V1) |
4393 | info->xmit_fifo_size = CYZ_FIFO_SIZE; | 4353 | info->xmit_fifo_size = CYZ_FIFO_SIZE; |
4394 | else | 4354 | else |
4395 | info->xmit_fifo_size = 4 * CYZ_FIFO_SIZE; | 4355 | info->xmit_fifo_size = 4 * CYZ_FIFO_SIZE; |
@@ -4398,6 +4358,7 @@ static int __devinit cy_init_card(struct cyclades_card *cinfo) | |||
4398 | cyz_rx_restart, (unsigned long)info); | 4358 | cyz_rx_restart, (unsigned long)info); |
4399 | #endif | 4359 | #endif |
4400 | } else { | 4360 | } else { |
4361 | int index = cinfo->bus_index; | ||
4401 | info->type = PORT_CIRRUS; | 4362 | info->type = PORT_CIRRUS; |
4402 | info->xmit_fifo_size = CyMAX_CHAR_FIFO; | 4363 | info->xmit_fifo_size = CyMAX_CHAR_FIFO; |
4403 | info->cor1 = CyPARITY_NONE | Cy_1_STOP | Cy_8_BITS; | 4364 | info->cor1 = CyPARITY_NONE | Cy_1_STOP | Cy_8_BITS; |
@@ -4430,7 +4391,7 @@ static int __devinit cy_init_card(struct cyclades_card *cinfo) | |||
4430 | } | 4391 | } |
4431 | 4392 | ||
4432 | #ifndef CONFIG_CYZ_INTR | 4393 | #ifndef CONFIG_CYZ_INTR |
4433 | if (IS_CYC_Z(*cinfo) && !timer_pending(&cyz_timerlist)) { | 4394 | if (cy_is_Z(cinfo) && !timer_pending(&cyz_timerlist)) { |
4434 | mod_timer(&cyz_timerlist, jiffies + 1); | 4395 | mod_timer(&cyz_timerlist, jiffies + 1); |
4435 | #ifdef CY_PCI_DEBUG | 4396 | #ifdef CY_PCI_DEBUG |
4436 | printk(KERN_DEBUG "Cyclades-Z polling initialized\n"); | 4397 | printk(KERN_DEBUG "Cyclades-Z polling initialized\n"); |
@@ -4621,11 +4582,12 @@ static int __init cy_detect_isa(void) | |||
4621 | 4582 | ||
4622 | /* set cy_card */ | 4583 | /* set cy_card */ |
4623 | cy_card[j].base_addr = cy_isa_address; | 4584 | cy_card[j].base_addr = cy_isa_address; |
4624 | cy_card[j].ctl_addr = NULL; | 4585 | cy_card[j].ctl_addr.p9050 = NULL; |
4625 | cy_card[j].irq = (int)cy_isa_irq; | 4586 | cy_card[j].irq = (int)cy_isa_irq; |
4626 | cy_card[j].bus_index = 0; | 4587 | cy_card[j].bus_index = 0; |
4627 | cy_card[j].first_line = cy_next_channel; | 4588 | cy_card[j].first_line = cy_next_channel; |
4628 | cy_card[j].num_chips = cy_isa_nchan / 4; | 4589 | cy_card[j].num_chips = cy_isa_nchan / CyPORTS_PER_CHIP; |
4590 | cy_card[j].nports = cy_isa_nchan; | ||
4629 | if (cy_init_card(&cy_card[j])) { | 4591 | if (cy_init_card(&cy_card[j])) { |
4630 | cy_card[j].base_addr = NULL; | 4592 | cy_card[j].base_addr = NULL; |
4631 | free_irq(cy_isa_irq, &cy_card[j]); | 4593 | free_irq(cy_isa_irq, &cy_card[j]); |
@@ -4781,7 +4743,7 @@ static int __devinit cyz_load_fw(struct pci_dev *pdev, void __iomem *base_addr, | |||
4781 | struct CUSTOM_REG __iomem *cust = base_addr; | 4743 | struct CUSTOM_REG __iomem *cust = base_addr; |
4782 | struct ZFW_CTRL __iomem *pt_zfwctrl; | 4744 | struct ZFW_CTRL __iomem *pt_zfwctrl; |
4783 | void __iomem *tmp; | 4745 | void __iomem *tmp; |
4784 | u32 mailbox, status; | 4746 | u32 mailbox, status, nchan; |
4785 | unsigned int i; | 4747 | unsigned int i; |
4786 | int retval; | 4748 | int retval; |
4787 | 4749 | ||
@@ -4793,7 +4755,7 @@ static int __devinit cyz_load_fw(struct pci_dev *pdev, void __iomem *base_addr, | |||
4793 | 4755 | ||
4794 | /* Check whether the firmware is already loaded and running. If | 4756 | /* Check whether the firmware is already loaded and running. If |
4795 | positive, skip this board */ | 4757 | positive, skip this board */ |
4796 | if (Z_FPGA_LOADED(ctl_addr) && readl(&fid->signature) == ZFIRM_ID) { | 4758 | if (__cyz_fpga_loaded(ctl_addr) && readl(&fid->signature) == ZFIRM_ID) { |
4797 | u32 cntval = readl(base_addr + 0x190); | 4759 | u32 cntval = readl(base_addr + 0x190); |
4798 | 4760 | ||
4799 | udelay(100); | 4761 | udelay(100); |
@@ -4812,7 +4774,7 @@ static int __devinit cyz_load_fw(struct pci_dev *pdev, void __iomem *base_addr, | |||
4812 | 4774 | ||
4813 | mailbox = readl(&ctl_addr->mail_box_0); | 4775 | mailbox = readl(&ctl_addr->mail_box_0); |
4814 | 4776 | ||
4815 | if (mailbox == 0 || Z_FPGA_LOADED(ctl_addr)) { | 4777 | if (mailbox == 0 || __cyz_fpga_loaded(ctl_addr)) { |
4816 | /* stops CPU and set window to beginning of RAM */ | 4778 | /* stops CPU and set window to beginning of RAM */ |
4817 | cy_writel(&ctl_addr->loc_addr_base, WIN_CREG); | 4779 | cy_writel(&ctl_addr->loc_addr_base, WIN_CREG); |
4818 | cy_writel(&cust->cpu_stop, 0); | 4780 | cy_writel(&cust->cpu_stop, 0); |
@@ -4828,7 +4790,7 @@ static int __devinit cyz_load_fw(struct pci_dev *pdev, void __iomem *base_addr, | |||
4828 | base_addr); | 4790 | base_addr); |
4829 | if (retval) | 4791 | if (retval) |
4830 | goto err_rel; | 4792 | goto err_rel; |
4831 | if (!Z_FPGA_LOADED(ctl_addr)) { | 4793 | if (!__cyz_fpga_loaded(ctl_addr)) { |
4832 | dev_err(&pdev->dev, "fw upload successful, but fw is " | 4794 | dev_err(&pdev->dev, "fw upload successful, but fw is " |
4833 | "not loaded\n"); | 4795 | "not loaded\n"); |
4834 | goto err_rel; | 4796 | goto err_rel; |
@@ -4887,7 +4849,7 @@ static int __devinit cyz_load_fw(struct pci_dev *pdev, void __iomem *base_addr, | |||
4887 | "system before loading the new FW to the " | 4849 | "system before loading the new FW to the " |
4888 | "Cyclades-Z.\n"); | 4850 | "Cyclades-Z.\n"); |
4889 | 4851 | ||
4890 | if (Z_FPGA_LOADED(ctl_addr)) | 4852 | if (__cyz_fpga_loaded(ctl_addr)) |
4891 | plx_init(pdev, irq, ctl_addr); | 4853 | plx_init(pdev, irq, ctl_addr); |
4892 | 4854 | ||
4893 | retval = -EIO; | 4855 | retval = -EIO; |
@@ -4902,16 +4864,16 @@ static int __devinit cyz_load_fw(struct pci_dev *pdev, void __iomem *base_addr, | |||
4902 | base_addr + ID_ADDRESS, readl(&fid->zfwctrl_addr), | 4864 | base_addr + ID_ADDRESS, readl(&fid->zfwctrl_addr), |
4903 | base_addr + readl(&fid->zfwctrl_addr)); | 4865 | base_addr + readl(&fid->zfwctrl_addr)); |
4904 | 4866 | ||
4867 | nchan = readl(&pt_zfwctrl->board_ctrl.n_channel); | ||
4905 | dev_info(&pdev->dev, "Cyclades-Z FW loaded: version = %x, ports = %u\n", | 4868 | dev_info(&pdev->dev, "Cyclades-Z FW loaded: version = %x, ports = %u\n", |
4906 | readl(&pt_zfwctrl->board_ctrl.fw_version), | 4869 | readl(&pt_zfwctrl->board_ctrl.fw_version), nchan); |
4907 | readl(&pt_zfwctrl->board_ctrl.n_channel)); | ||
4908 | 4870 | ||
4909 | if (readl(&pt_zfwctrl->board_ctrl.n_channel) == 0) { | 4871 | if (nchan == 0) { |
4910 | dev_warn(&pdev->dev, "no Cyclades-Z ports were found. Please " | 4872 | dev_warn(&pdev->dev, "no Cyclades-Z ports were found. Please " |
4911 | "check the connection between the Z host card and the " | 4873 | "check the connection between the Z host card and the " |
4912 | "serial expanders.\n"); | 4874 | "serial expanders.\n"); |
4913 | 4875 | ||
4914 | if (Z_FPGA_LOADED(ctl_addr)) | 4876 | if (__cyz_fpga_loaded(ctl_addr)) |
4915 | plx_init(pdev, irq, ctl_addr); | 4877 | plx_init(pdev, irq, ctl_addr); |
4916 | 4878 | ||
4917 | dev_info(&pdev->dev, "Null number of ports detected. Board " | 4879 | dev_info(&pdev->dev, "Null number of ports detected. Board " |
@@ -4932,9 +4894,7 @@ static int __devinit cyz_load_fw(struct pci_dev *pdev, void __iomem *base_addr, | |||
4932 | cy_writel(&ctl_addr->intr_ctrl_stat, readl(&ctl_addr->intr_ctrl_stat) | | 4894 | cy_writel(&ctl_addr->intr_ctrl_stat, readl(&ctl_addr->intr_ctrl_stat) | |
4933 | 0x00030800UL); | 4895 | 0x00030800UL); |
4934 | 4896 | ||
4935 | plx_init(pdev, irq, ctl_addr); | 4897 | return nchan; |
4936 | |||
4937 | return 0; | ||
4938 | err_rel: | 4898 | err_rel: |
4939 | release_firmware(fw); | 4899 | release_firmware(fw); |
4940 | err: | 4900 | err: |
@@ -4946,7 +4906,7 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev, | |||
4946 | { | 4906 | { |
4947 | void __iomem *addr0 = NULL, *addr2 = NULL; | 4907 | void __iomem *addr0 = NULL, *addr2 = NULL; |
4948 | char *card_name = NULL; | 4908 | char *card_name = NULL; |
4949 | u32 mailbox; | 4909 | u32 uninitialized_var(mailbox); |
4950 | unsigned int device_id, nchan = 0, card_no, i; | 4910 | unsigned int device_id, nchan = 0, card_no, i; |
4951 | unsigned char plx_ver; | 4911 | unsigned char plx_ver; |
4952 | int retval, irq; | 4912 | int retval, irq; |
@@ -5023,11 +4983,12 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev, | |||
5023 | } | 4983 | } |
5024 | 4984 | ||
5025 | /* Disable interrupts on the PLX before resetting it */ | 4985 | /* Disable interrupts on the PLX before resetting it */ |
5026 | cy_writew(addr0 + 0x68, readw(addr0 + 0x68) & ~0x0900); | 4986 | cy_writew(&ctl_addr->intr_ctrl_stat, |
4987 | readw(&ctl_addr->intr_ctrl_stat) & ~0x0900); | ||
5027 | 4988 | ||
5028 | plx_init(pdev, irq, addr0); | 4989 | plx_init(pdev, irq, addr0); |
5029 | 4990 | ||
5030 | mailbox = (u32)readl(&ctl_addr->mail_box_0); | 4991 | mailbox = readl(&ctl_addr->mail_box_0); |
5031 | 4992 | ||
5032 | addr2 = ioremap_nocache(pci_resource_start(pdev, 2), | 4993 | addr2 = ioremap_nocache(pci_resource_start(pdev, 2), |
5033 | mailbox == ZE_V1 ? CyPCI_Ze_win : CyPCI_Zwin); | 4994 | mailbox == ZE_V1 ? CyPCI_Ze_win : CyPCI_Zwin); |
@@ -5038,12 +4999,8 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev, | |||
5038 | 4999 | ||
5039 | if (mailbox == ZE_V1) { | 5000 | if (mailbox == ZE_V1) { |
5040 | card_name = "Cyclades-Ze"; | 5001 | card_name = "Cyclades-Ze"; |
5041 | |||
5042 | readl(&ctl_addr->mail_box_0); | ||
5043 | nchan = ZE_V1_NPORTS; | ||
5044 | } else { | 5002 | } else { |
5045 | card_name = "Cyclades-8Zo"; | 5003 | card_name = "Cyclades-8Zo"; |
5046 | |||
5047 | #ifdef CY_PCI_DEBUG | 5004 | #ifdef CY_PCI_DEBUG |
5048 | if (mailbox == ZO_V1) { | 5005 | if (mailbox == ZO_V1) { |
5049 | cy_writel(&ctl_addr->loc_addr_base, WIN_CREG); | 5006 | cy_writel(&ctl_addr->loc_addr_base, WIN_CREG); |
@@ -5065,15 +5022,12 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev, | |||
5065 | */ | 5022 | */ |
5066 | if ((mailbox == ZO_V1) || (mailbox == ZO_V2)) | 5023 | if ((mailbox == ZO_V1) || (mailbox == ZO_V2)) |
5067 | cy_writel(addr2 + ID_ADDRESS, 0L); | 5024 | cy_writel(addr2 + ID_ADDRESS, 0L); |
5068 | |||
5069 | retval = cyz_load_fw(pdev, addr2, addr0, irq); | ||
5070 | if (retval) | ||
5071 | goto err_unmap; | ||
5072 | /* This must be a Cyclades-8Zo/PCI. The extendable | ||
5073 | version will have a different device_id and will | ||
5074 | be allocated its maximum number of ports. */ | ||
5075 | nchan = 8; | ||
5076 | } | 5025 | } |
5026 | |||
5027 | retval = cyz_load_fw(pdev, addr2, addr0, irq); | ||
5028 | if (retval <= 0) | ||
5029 | goto err_unmap; | ||
5030 | nchan = retval; | ||
5077 | } | 5031 | } |
5078 | 5032 | ||
5079 | if ((cy_next_channel + nchan) > NR_PORTS) { | 5033 | if ((cy_next_channel + nchan) > NR_PORTS) { |
@@ -5103,8 +5057,10 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev, | |||
5103 | dev_err(&pdev->dev, "could not allocate IRQ\n"); | 5057 | dev_err(&pdev->dev, "could not allocate IRQ\n"); |
5104 | goto err_unmap; | 5058 | goto err_unmap; |
5105 | } | 5059 | } |
5106 | cy_card[card_no].num_chips = nchan / 4; | 5060 | cy_card[card_no].num_chips = nchan / CyPORTS_PER_CHIP; |
5107 | } else { | 5061 | } else { |
5062 | cy_card[card_no].hw_ver = mailbox; | ||
5063 | cy_card[card_no].num_chips = (unsigned int)-1; | ||
5108 | #ifdef CONFIG_CYZ_INTR | 5064 | #ifdef CONFIG_CYZ_INTR |
5109 | /* allocate IRQ only if board has an IRQ */ | 5065 | /* allocate IRQ only if board has an IRQ */ |
5110 | if (irq != 0 && irq != 255) { | 5066 | if (irq != 0 && irq != 255) { |
@@ -5117,15 +5073,15 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev, | |||
5117 | } | 5073 | } |
5118 | } | 5074 | } |
5119 | #endif /* CONFIG_CYZ_INTR */ | 5075 | #endif /* CONFIG_CYZ_INTR */ |
5120 | cy_card[card_no].num_chips = (unsigned int)-1; | ||
5121 | } | 5076 | } |
5122 | 5077 | ||
5123 | /* set cy_card */ | 5078 | /* set cy_card */ |
5124 | cy_card[card_no].base_addr = addr2; | 5079 | cy_card[card_no].base_addr = addr2; |
5125 | cy_card[card_no].ctl_addr = addr0; | 5080 | cy_card[card_no].ctl_addr.p9050 = addr0; |
5126 | cy_card[card_no].irq = irq; | 5081 | cy_card[card_no].irq = irq; |
5127 | cy_card[card_no].bus_index = 1; | 5082 | cy_card[card_no].bus_index = 1; |
5128 | cy_card[card_no].first_line = cy_next_channel; | 5083 | cy_card[card_no].first_line = cy_next_channel; |
5084 | cy_card[card_no].nports = nchan; | ||
5129 | retval = cy_init_card(&cy_card[card_no]); | 5085 | retval = cy_init_card(&cy_card[card_no]); |
5130 | if (retval) | 5086 | if (retval) |
5131 | goto err_null; | 5087 | goto err_null; |
@@ -5138,17 +5094,20 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev, | |||
5138 | plx_ver = readb(addr2 + CyPLX_VER) & 0x0f; | 5094 | plx_ver = readb(addr2 + CyPLX_VER) & 0x0f; |
5139 | switch (plx_ver) { | 5095 | switch (plx_ver) { |
5140 | case PLX_9050: | 5096 | case PLX_9050: |
5141 | |||
5142 | cy_writeb(addr0 + 0x4c, 0x43); | 5097 | cy_writeb(addr0 + 0x4c, 0x43); |
5143 | break; | 5098 | break; |
5144 | 5099 | ||
5145 | case PLX_9060: | 5100 | case PLX_9060: |
5146 | case PLX_9080: | 5101 | case PLX_9080: |
5147 | default: /* Old boards, use PLX_9060 */ | 5102 | default: /* Old boards, use PLX_9060 */ |
5148 | plx_init(pdev, irq, addr0); | 5103 | { |
5149 | cy_writew(addr0 + 0x68, readw(addr0 + 0x68) | 0x0900); | 5104 | struct RUNTIME_9060 __iomem *ctl_addr = addr0; |
5105 | plx_init(pdev, irq, ctl_addr); | ||
5106 | cy_writew(&ctl_addr->intr_ctrl_stat, | ||
5107 | readw(&ctl_addr->intr_ctrl_stat) | 0x0900); | ||
5150 | break; | 5108 | break; |
5151 | } | 5109 | } |
5110 | } | ||
5152 | } | 5111 | } |
5153 | 5112 | ||
5154 | dev_info(&pdev->dev, "%s/PCI #%d found: %d channels starting from " | 5113 | dev_info(&pdev->dev, "%s/PCI #%d found: %d channels starting from " |
@@ -5179,22 +5138,23 @@ static void __devexit cy_pci_remove(struct pci_dev *pdev) | |||
5179 | unsigned int i; | 5138 | unsigned int i; |
5180 | 5139 | ||
5181 | /* non-Z with old PLX */ | 5140 | /* non-Z with old PLX */ |
5182 | if (!IS_CYC_Z(*cinfo) && (readb(cinfo->base_addr + CyPLX_VER) & 0x0f) == | 5141 | if (!cy_is_Z(cinfo) && (readb(cinfo->base_addr + CyPLX_VER) & 0x0f) == |
5183 | PLX_9050) | 5142 | PLX_9050) |
5184 | cy_writeb(cinfo->ctl_addr + 0x4c, 0); | 5143 | cy_writeb(cinfo->ctl_addr.p9050 + 0x4c, 0); |
5185 | else | 5144 | else |
5186 | #ifndef CONFIG_CYZ_INTR | 5145 | #ifndef CONFIG_CYZ_INTR |
5187 | if (!IS_CYC_Z(*cinfo)) | 5146 | if (!cy_is_Z(cinfo)) |
5188 | #endif | 5147 | #endif |
5189 | cy_writew(cinfo->ctl_addr + 0x68, | 5148 | cy_writew(&cinfo->ctl_addr.p9060->intr_ctrl_stat, |
5190 | readw(cinfo->ctl_addr + 0x68) & ~0x0900); | 5149 | readw(&cinfo->ctl_addr.p9060->intr_ctrl_stat) & |
5150 | ~0x0900); | ||
5191 | 5151 | ||
5192 | iounmap(cinfo->base_addr); | 5152 | iounmap(cinfo->base_addr); |
5193 | if (cinfo->ctl_addr) | 5153 | if (cinfo->ctl_addr.p9050) |
5194 | iounmap(cinfo->ctl_addr); | 5154 | iounmap(cinfo->ctl_addr.p9050); |
5195 | if (cinfo->irq | 5155 | if (cinfo->irq |
5196 | #ifndef CONFIG_CYZ_INTR | 5156 | #ifndef CONFIG_CYZ_INTR |
5197 | && !IS_CYC_Z(*cinfo) | 5157 | && !cy_is_Z(cinfo) |
5198 | #endif /* CONFIG_CYZ_INTR */ | 5158 | #endif /* CONFIG_CYZ_INTR */ |
5199 | ) | 5159 | ) |
5200 | free_irq(cinfo->irq, cinfo); | 5160 | free_irq(cinfo->irq, cinfo); |
@@ -5240,7 +5200,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v) | |||
5240 | (cur_jifs - info->idle_stats.recv_idle)/ | 5200 | (cur_jifs - info->idle_stats.recv_idle)/ |
5241 | HZ, info->idle_stats.overruns, | 5201 | HZ, info->idle_stats.overruns, |
5242 | /* FIXME: double check locking */ | 5202 | /* FIXME: double check locking */ |
5243 | (long)info->port.tty->ldisc.ops->num); | 5203 | (long)info->port.tty->ldisc->ops->num); |
5244 | else | 5204 | else |
5245 | seq_printf(m, "%3d %8lu %10lu %8lu " | 5205 | seq_printf(m, "%3d %8lu %10lu %8lu " |
5246 | "%10lu %8lu %9lu %6ld\n", | 5206 | "%10lu %8lu %9lu %6ld\n", |
@@ -5386,11 +5346,11 @@ static void __exit cy_cleanup_module(void) | |||
5386 | /* clear interrupt */ | 5346 | /* clear interrupt */ |
5387 | cy_writeb(card->base_addr + Cy_ClrIntr, 0); | 5347 | cy_writeb(card->base_addr + Cy_ClrIntr, 0); |
5388 | iounmap(card->base_addr); | 5348 | iounmap(card->base_addr); |
5389 | if (card->ctl_addr) | 5349 | if (card->ctl_addr.p9050) |
5390 | iounmap(card->ctl_addr); | 5350 | iounmap(card->ctl_addr.p9050); |
5391 | if (card->irq | 5351 | if (card->irq |
5392 | #ifndef CONFIG_CYZ_INTR | 5352 | #ifndef CONFIG_CYZ_INTR |
5393 | && !IS_CYC_Z(*card) | 5353 | && !cy_is_Z(card) |
5394 | #endif /* CONFIG_CYZ_INTR */ | 5354 | #endif /* CONFIG_CYZ_INTR */ |
5395 | ) | 5355 | ) |
5396 | free_irq(card->irq, card); | 5356 | free_irq(card->irq, card); |
diff --git a/drivers/char/epca.c b/drivers/char/epca.c index af7c13ca9493..abef1f7d84fe 100644 --- a/drivers/char/epca.c +++ b/drivers/char/epca.c | |||
@@ -745,7 +745,7 @@ static int epca_carrier_raised(struct tty_port *port) | |||
745 | return 0; | 745 | return 0; |
746 | } | 746 | } |
747 | 747 | ||
748 | static void epca_raise_dtr_rts(struct tty_port *port) | 748 | static void epca_dtr_rts(struct tty_port *port, int onoff) |
749 | { | 749 | { |
750 | } | 750 | } |
751 | 751 | ||
@@ -925,7 +925,7 @@ static const struct tty_operations pc_ops = { | |||
925 | 925 | ||
926 | static const struct tty_port_operations epca_port_ops = { | 926 | static const struct tty_port_operations epca_port_ops = { |
927 | .carrier_raised = epca_carrier_raised, | 927 | .carrier_raised = epca_carrier_raised, |
928 | .raise_dtr_rts = epca_raise_dtr_rts, | 928 | .dtr_rts = epca_dtr_rts, |
929 | }; | 929 | }; |
930 | 930 | ||
931 | static int info_open(struct tty_struct *tty, struct file *filp) | 931 | static int info_open(struct tty_struct *tty, struct file *filp) |
@@ -1518,7 +1518,7 @@ static void doevent(int crd) | |||
1518 | if (event & MODEMCHG_IND) { | 1518 | if (event & MODEMCHG_IND) { |
1519 | /* A modem signal change has been indicated */ | 1519 | /* A modem signal change has been indicated */ |
1520 | ch->imodem = mstat; | 1520 | ch->imodem = mstat; |
1521 | if (test_bit(ASYNC_CHECK_CD, &ch->port.flags)) { | 1521 | if (test_bit(ASYNCB_CHECK_CD, &ch->port.flags)) { |
1522 | /* We are now receiving dcd */ | 1522 | /* We are now receiving dcd */ |
1523 | if (mstat & ch->dcd) | 1523 | if (mstat & ch->dcd) |
1524 | wake_up_interruptible(&ch->port.open_wait); | 1524 | wake_up_interruptible(&ch->port.open_wait); |
@@ -1765,9 +1765,9 @@ static void epcaparam(struct tty_struct *tty, struct channel *ch) | |||
1765 | * that the driver will wait on carrier detect. | 1765 | * that the driver will wait on carrier detect. |
1766 | */ | 1766 | */ |
1767 | if (ts->c_cflag & CLOCAL) | 1767 | if (ts->c_cflag & CLOCAL) |
1768 | clear_bit(ASYNC_CHECK_CD, &ch->port.flags); | 1768 | clear_bit(ASYNCB_CHECK_CD, &ch->port.flags); |
1769 | else | 1769 | else |
1770 | set_bit(ASYNC_CHECK_CD, &ch->port.flags); | 1770 | set_bit(ASYNCB_CHECK_CD, &ch->port.flags); |
1771 | mval = ch->m_dtr | ch->m_rts; | 1771 | mval = ch->m_dtr | ch->m_rts; |
1772 | } /* End CBAUD not detected */ | 1772 | } /* End CBAUD not detected */ |
1773 | iflag = termios2digi_i(ch, ts->c_iflag); | 1773 | iflag = termios2digi_i(ch, ts->c_iflag); |
@@ -2114,8 +2114,8 @@ static int pc_ioctl(struct tty_struct *tty, struct file *file, | |||
2114 | tty_wait_until_sent(tty, 0); | 2114 | tty_wait_until_sent(tty, 0); |
2115 | } else { | 2115 | } else { |
2116 | /* ldisc lock already held in ioctl */ | 2116 | /* ldisc lock already held in ioctl */ |
2117 | if (tty->ldisc.ops->flush_buffer) | 2117 | if (tty->ldisc->ops->flush_buffer) |
2118 | tty->ldisc.ops->flush_buffer(tty); | 2118 | tty->ldisc->ops->flush_buffer(tty); |
2119 | } | 2119 | } |
2120 | unlock_kernel(); | 2120 | unlock_kernel(); |
2121 | /* Fall Thru */ | 2121 | /* Fall Thru */ |
@@ -2244,7 +2244,8 @@ static void do_softint(struct work_struct *work) | |||
2244 | if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) { | 2244 | if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) { |
2245 | tty_hangup(tty); | 2245 | tty_hangup(tty); |
2246 | wake_up_interruptible(&ch->port.open_wait); | 2246 | wake_up_interruptible(&ch->port.open_wait); |
2247 | clear_bit(ASYNC_NORMAL_ACTIVE, &ch->port.flags); | 2247 | clear_bit(ASYNCB_NORMAL_ACTIVE, |
2248 | &ch->port.flags); | ||
2248 | } | 2249 | } |
2249 | } | 2250 | } |
2250 | tty_kref_put(tty); | 2251 | tty_kref_put(tty); |
diff --git a/drivers/char/ip2/i2lib.c b/drivers/char/ip2/i2lib.c index 0061e18aff60..0d10b89218ed 100644 --- a/drivers/char/ip2/i2lib.c +++ b/drivers/char/ip2/i2lib.c | |||
@@ -868,11 +868,11 @@ i2Input(i2ChanStrPtr pCh) | |||
868 | amountToMove = count; | 868 | amountToMove = count; |
869 | } | 869 | } |
870 | // Move the first block | 870 | // Move the first block |
871 | pCh->pTTY->ldisc.ops->receive_buf( pCh->pTTY, | 871 | pCh->pTTY->ldisc->ops->receive_buf( pCh->pTTY, |
872 | &(pCh->Ibuf[stripIndex]), NULL, amountToMove ); | 872 | &(pCh->Ibuf[stripIndex]), NULL, amountToMove ); |
873 | // If we needed to wrap, do the second data move | 873 | // If we needed to wrap, do the second data move |
874 | if (count > amountToMove) { | 874 | if (count > amountToMove) { |
875 | pCh->pTTY->ldisc.ops->receive_buf( pCh->pTTY, | 875 | pCh->pTTY->ldisc->ops->receive_buf( pCh->pTTY, |
876 | pCh->Ibuf, NULL, count - amountToMove ); | 876 | pCh->Ibuf, NULL, count - amountToMove ); |
877 | } | 877 | } |
878 | // Bump and wrap the stripIndex all at once by the amount of data read. This | 878 | // Bump and wrap the stripIndex all at once by the amount of data read. This |
diff --git a/drivers/char/ip2/ip2main.c b/drivers/char/ip2/ip2main.c index afd9247cf082..517271c762e6 100644 --- a/drivers/char/ip2/ip2main.c +++ b/drivers/char/ip2/ip2main.c | |||
@@ -1315,8 +1315,8 @@ static inline void isig(int sig, struct tty_struct *tty, int flush) | |||
1315 | if (tty->pgrp) | 1315 | if (tty->pgrp) |
1316 | kill_pgrp(tty->pgrp, sig, 1); | 1316 | kill_pgrp(tty->pgrp, sig, 1); |
1317 | if (flush || !L_NOFLSH(tty)) { | 1317 | if (flush || !L_NOFLSH(tty)) { |
1318 | if ( tty->ldisc.ops->flush_buffer ) | 1318 | if ( tty->ldisc->ops->flush_buffer ) |
1319 | tty->ldisc.ops->flush_buffer(tty); | 1319 | tty->ldisc->ops->flush_buffer(tty); |
1320 | i2InputFlush( tty->driver_data ); | 1320 | i2InputFlush( tty->driver_data ); |
1321 | } | 1321 | } |
1322 | } | 1322 | } |
diff --git a/drivers/char/isicom.c b/drivers/char/isicom.c index a59eac584d16..4d745a89504f 100644 --- a/drivers/char/isicom.c +++ b/drivers/char/isicom.c | |||
@@ -329,7 +329,7 @@ static inline void drop_rts(struct isi_port *port) | |||
329 | 329 | ||
330 | /* card->lock MUST NOT be held */ | 330 | /* card->lock MUST NOT be held */ |
331 | 331 | ||
332 | static void isicom_raise_dtr_rts(struct tty_port *port) | 332 | static void isicom_dtr_rts(struct tty_port *port, int on) |
333 | { | 333 | { |
334 | struct isi_port *ip = container_of(port, struct isi_port, port); | 334 | struct isi_port *ip = container_of(port, struct isi_port, port); |
335 | struct isi_board *card = ip->card; | 335 | struct isi_board *card = ip->card; |
@@ -339,10 +339,17 @@ static void isicom_raise_dtr_rts(struct tty_port *port) | |||
339 | if (!lock_card(card)) | 339 | if (!lock_card(card)) |
340 | return; | 340 | return; |
341 | 341 | ||
342 | outw(0x8000 | (channel << card->shift_count) | 0x02, base); | 342 | if (on) { |
343 | outw(0x0f04, base); | 343 | outw(0x8000 | (channel << card->shift_count) | 0x02, base); |
344 | InterruptTheCard(base); | 344 | outw(0x0f04, base); |
345 | ip->status |= (ISI_DTR | ISI_RTS); | 345 | InterruptTheCard(base); |
346 | ip->status |= (ISI_DTR | ISI_RTS); | ||
347 | } else { | ||
348 | outw(0x8000 | (channel << card->shift_count) | 0x02, base); | ||
349 | outw(0x0C04, base); | ||
350 | InterruptTheCard(base); | ||
351 | ip->status &= ~(ISI_DTR | ISI_RTS); | ||
352 | } | ||
346 | unlock_card(card); | 353 | unlock_card(card); |
347 | } | 354 | } |
348 | 355 | ||
@@ -1339,7 +1346,7 @@ static const struct tty_operations isicom_ops = { | |||
1339 | 1346 | ||
1340 | static const struct tty_port_operations isicom_port_ops = { | 1347 | static const struct tty_port_operations isicom_port_ops = { |
1341 | .carrier_raised = isicom_carrier_raised, | 1348 | .carrier_raised = isicom_carrier_raised, |
1342 | .raise_dtr_rts = isicom_raise_dtr_rts, | 1349 | .dtr_rts = isicom_dtr_rts, |
1343 | }; | 1350 | }; |
1344 | 1351 | ||
1345 | static int __devinit reset_card(struct pci_dev *pdev, | 1352 | static int __devinit reset_card(struct pci_dev *pdev, |
diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c index fff19f7e29d2..e18800c400b1 100644 --- a/drivers/char/istallion.c +++ b/drivers/char/istallion.c | |||
@@ -1140,14 +1140,14 @@ static int stli_carrier_raised(struct tty_port *port) | |||
1140 | return (portp->sigs & TIOCM_CD) ? 1 : 0; | 1140 | return (portp->sigs & TIOCM_CD) ? 1 : 0; |
1141 | } | 1141 | } |
1142 | 1142 | ||
1143 | static void stli_raise_dtr_rts(struct tty_port *port) | 1143 | static void stli_dtr_rts(struct tty_port *port, int on) |
1144 | { | 1144 | { |
1145 | struct stliport *portp = container_of(port, struct stliport, port); | 1145 | struct stliport *portp = container_of(port, struct stliport, port); |
1146 | struct stlibrd *brdp = stli_brds[portp->brdnr]; | 1146 | struct stlibrd *brdp = stli_brds[portp->brdnr]; |
1147 | stli_mkasysigs(&portp->asig, 1, 1); | 1147 | stli_mkasysigs(&portp->asig, on, on); |
1148 | if (stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig, | 1148 | if (stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig, |
1149 | sizeof(asysigs_t), 0) < 0) | 1149 | sizeof(asysigs_t), 0) < 0) |
1150 | printk(KERN_WARNING "istallion: dtr raise failed.\n"); | 1150 | printk(KERN_WARNING "istallion: dtr set failed.\n"); |
1151 | } | 1151 | } |
1152 | 1152 | ||
1153 | 1153 | ||
@@ -4417,7 +4417,7 @@ static const struct tty_operations stli_ops = { | |||
4417 | 4417 | ||
4418 | static const struct tty_port_operations stli_port_ops = { | 4418 | static const struct tty_port_operations stli_port_ops = { |
4419 | .carrier_raised = stli_carrier_raised, | 4419 | .carrier_raised = stli_carrier_raised, |
4420 | .raise_dtr_rts = stli_raise_dtr_rts, | 4420 | .dtr_rts = stli_dtr_rts, |
4421 | }; | 4421 | }; |
4422 | 4422 | ||
4423 | /*****************************************************************************/ | 4423 | /*****************************************************************************/ |
diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c index 4a4cab73d0be..65b6ff2442c6 100644 --- a/drivers/char/moxa.c +++ b/drivers/char/moxa.c | |||
@@ -1184,6 +1184,11 @@ static int moxa_open(struct tty_struct *tty, struct file *filp) | |||
1184 | return -ENODEV; | 1184 | return -ENODEV; |
1185 | } | 1185 | } |
1186 | 1186 | ||
1187 | if (port % MAX_PORTS_PER_BOARD >= brd->numPorts) { | ||
1188 | mutex_unlock(&moxa_openlock); | ||
1189 | return -ENODEV; | ||
1190 | } | ||
1191 | |||
1187 | ch = &brd->ports[port % MAX_PORTS_PER_BOARD]; | 1192 | ch = &brd->ports[port % MAX_PORTS_PER_BOARD]; |
1188 | ch->port.count++; | 1193 | ch->port.count++; |
1189 | tty->driver_data = ch; | 1194 | tty->driver_data = ch; |
diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c index 13f8871e5b21..9533f43a30bb 100644 --- a/drivers/char/mxser.c +++ b/drivers/char/mxser.c | |||
@@ -547,14 +547,18 @@ static int mxser_carrier_raised(struct tty_port *port) | |||
547 | return (inb(mp->ioaddr + UART_MSR) & UART_MSR_DCD)?1:0; | 547 | return (inb(mp->ioaddr + UART_MSR) & UART_MSR_DCD)?1:0; |
548 | } | 548 | } |
549 | 549 | ||
550 | static void mxser_raise_dtr_rts(struct tty_port *port) | 550 | static void mxser_dtr_rts(struct tty_port *port, int on) |
551 | { | 551 | { |
552 | struct mxser_port *mp = container_of(port, struct mxser_port, port); | 552 | struct mxser_port *mp = container_of(port, struct mxser_port, port); |
553 | unsigned long flags; | 553 | unsigned long flags; |
554 | 554 | ||
555 | spin_lock_irqsave(&mp->slock, flags); | 555 | spin_lock_irqsave(&mp->slock, flags); |
556 | outb(inb(mp->ioaddr + UART_MCR) | | 556 | if (on) |
557 | UART_MCR_DTR | UART_MCR_RTS, mp->ioaddr + UART_MCR); | 557 | outb(inb(mp->ioaddr + UART_MCR) | |
558 | UART_MCR_DTR | UART_MCR_RTS, mp->ioaddr + UART_MCR); | ||
559 | else | ||
560 | outb(inb(mp->ioaddr + UART_MCR)&~(UART_MCR_DTR | UART_MCR_RTS), | ||
561 | mp->ioaddr + UART_MCR); | ||
558 | spin_unlock_irqrestore(&mp->slock, flags); | 562 | spin_unlock_irqrestore(&mp->slock, flags); |
559 | } | 563 | } |
560 | 564 | ||
@@ -2356,7 +2360,7 @@ static const struct tty_operations mxser_ops = { | |||
2356 | 2360 | ||
2357 | struct tty_port_operations mxser_port_ops = { | 2361 | struct tty_port_operations mxser_port_ops = { |
2358 | .carrier_raised = mxser_carrier_raised, | 2362 | .carrier_raised = mxser_carrier_raised, |
2359 | .raise_dtr_rts = mxser_raise_dtr_rts, | 2363 | .dtr_rts = mxser_dtr_rts, |
2360 | }; | 2364 | }; |
2361 | 2365 | ||
2362 | /* | 2366 | /* |
diff --git a/drivers/char/n_hdlc.c b/drivers/char/n_hdlc.c index bacb3e2872ae..461ece591a5b 100644 --- a/drivers/char/n_hdlc.c +++ b/drivers/char/n_hdlc.c | |||
@@ -342,8 +342,8 @@ static int n_hdlc_tty_open (struct tty_struct *tty) | |||
342 | #endif | 342 | #endif |
343 | 343 | ||
344 | /* Flush any pending characters in the driver and discipline. */ | 344 | /* Flush any pending characters in the driver and discipline. */ |
345 | if (tty->ldisc.ops->flush_buffer) | 345 | if (tty->ldisc->ops->flush_buffer) |
346 | tty->ldisc.ops->flush_buffer(tty); | 346 | tty->ldisc->ops->flush_buffer(tty); |
347 | 347 | ||
348 | tty_driver_flush_buffer(tty); | 348 | tty_driver_flush_buffer(tty); |
349 | 349 | ||
diff --git a/drivers/char/n_tty.c b/drivers/char/n_tty.c index f6f0e4ec2b51..94a5d5020abc 100644 --- a/drivers/char/n_tty.c +++ b/drivers/char/n_tty.c | |||
@@ -73,24 +73,6 @@ | |||
73 | #define ECHO_OP_SET_CANON_COL 0x81 | 73 | #define ECHO_OP_SET_CANON_COL 0x81 |
74 | #define ECHO_OP_ERASE_TAB 0x82 | 74 | #define ECHO_OP_ERASE_TAB 0x82 |
75 | 75 | ||
76 | static inline unsigned char *alloc_buf(void) | ||
77 | { | ||
78 | gfp_t prio = in_interrupt() ? GFP_ATOMIC : GFP_KERNEL; | ||
79 | |||
80 | if (PAGE_SIZE != N_TTY_BUF_SIZE) | ||
81 | return kmalloc(N_TTY_BUF_SIZE, prio); | ||
82 | else | ||
83 | return (unsigned char *)__get_free_page(prio); | ||
84 | } | ||
85 | |||
86 | static inline void free_buf(unsigned char *buf) | ||
87 | { | ||
88 | if (PAGE_SIZE != N_TTY_BUF_SIZE) | ||
89 | kfree(buf); | ||
90 | else | ||
91 | free_page((unsigned long) buf); | ||
92 | } | ||
93 | |||
94 | static inline int tty_put_user(struct tty_struct *tty, unsigned char x, | 76 | static inline int tty_put_user(struct tty_struct *tty, unsigned char x, |
95 | unsigned char __user *ptr) | 77 | unsigned char __user *ptr) |
96 | { | 78 | { |
@@ -1558,11 +1540,11 @@ static void n_tty_close(struct tty_struct *tty) | |||
1558 | { | 1540 | { |
1559 | n_tty_flush_buffer(tty); | 1541 | n_tty_flush_buffer(tty); |
1560 | if (tty->read_buf) { | 1542 | if (tty->read_buf) { |
1561 | free_buf(tty->read_buf); | 1543 | kfree(tty->read_buf); |
1562 | tty->read_buf = NULL; | 1544 | tty->read_buf = NULL; |
1563 | } | 1545 | } |
1564 | if (tty->echo_buf) { | 1546 | if (tty->echo_buf) { |
1565 | free_buf(tty->echo_buf); | 1547 | kfree(tty->echo_buf); |
1566 | tty->echo_buf = NULL; | 1548 | tty->echo_buf = NULL; |
1567 | } | 1549 | } |
1568 | } | 1550 | } |
@@ -1584,17 +1566,16 @@ static int n_tty_open(struct tty_struct *tty) | |||
1584 | 1566 | ||
1585 | /* These are ugly. Currently a malloc failure here can panic */ | 1567 | /* These are ugly. Currently a malloc failure here can panic */ |
1586 | if (!tty->read_buf) { | 1568 | if (!tty->read_buf) { |
1587 | tty->read_buf = alloc_buf(); | 1569 | tty->read_buf = kzalloc(N_TTY_BUF_SIZE, GFP_KERNEL); |
1588 | if (!tty->read_buf) | 1570 | if (!tty->read_buf) |
1589 | return -ENOMEM; | 1571 | return -ENOMEM; |
1590 | } | 1572 | } |
1591 | if (!tty->echo_buf) { | 1573 | if (!tty->echo_buf) { |
1592 | tty->echo_buf = alloc_buf(); | 1574 | tty->echo_buf = kzalloc(N_TTY_BUF_SIZE, GFP_KERNEL); |
1575 | |||
1593 | if (!tty->echo_buf) | 1576 | if (!tty->echo_buf) |
1594 | return -ENOMEM; | 1577 | return -ENOMEM; |
1595 | } | 1578 | } |
1596 | memset(tty->read_buf, 0, N_TTY_BUF_SIZE); | ||
1597 | memset(tty->echo_buf, 0, N_TTY_BUF_SIZE); | ||
1598 | reset_buffer_flags(tty); | 1579 | reset_buffer_flags(tty); |
1599 | tty->column = 0; | 1580 | tty->column = 0; |
1600 | n_tty_set_termios(tty, NULL); | 1581 | n_tty_set_termios(tty, NULL); |
diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c index 19d79fc54461..77b364889224 100644 --- a/drivers/char/pcmcia/synclink_cs.c +++ b/drivers/char/pcmcia/synclink_cs.c | |||
@@ -383,7 +383,7 @@ static void async_mode(MGSLPC_INFO *info); | |||
383 | static void tx_timeout(unsigned long context); | 383 | static void tx_timeout(unsigned long context); |
384 | 384 | ||
385 | static int carrier_raised(struct tty_port *port); | 385 | static int carrier_raised(struct tty_port *port); |
386 | static void raise_dtr_rts(struct tty_port *port); | 386 | static void dtr_rts(struct tty_port *port, int onoff); |
387 | 387 | ||
388 | #if SYNCLINK_GENERIC_HDLC | 388 | #if SYNCLINK_GENERIC_HDLC |
389 | #define dev_to_port(D) (dev_to_hdlc(D)->priv) | 389 | #define dev_to_port(D) (dev_to_hdlc(D)->priv) |
@@ -513,7 +513,7 @@ static void ldisc_receive_buf(struct tty_struct *tty, | |||
513 | 513 | ||
514 | static const struct tty_port_operations mgslpc_port_ops = { | 514 | static const struct tty_port_operations mgslpc_port_ops = { |
515 | .carrier_raised = carrier_raised, | 515 | .carrier_raised = carrier_raised, |
516 | .raise_dtr_rts = raise_dtr_rts | 516 | .dtr_rts = dtr_rts |
517 | }; | 517 | }; |
518 | 518 | ||
519 | static int mgslpc_probe(struct pcmcia_device *link) | 519 | static int mgslpc_probe(struct pcmcia_device *link) |
@@ -2528,13 +2528,16 @@ static int carrier_raised(struct tty_port *port) | |||
2528 | return 0; | 2528 | return 0; |
2529 | } | 2529 | } |
2530 | 2530 | ||
2531 | static void raise_dtr_rts(struct tty_port *port) | 2531 | static void dtr_rts(struct tty_port *port, int onoff) |
2532 | { | 2532 | { |
2533 | MGSLPC_INFO *info = container_of(port, MGSLPC_INFO, port); | 2533 | MGSLPC_INFO *info = container_of(port, MGSLPC_INFO, port); |
2534 | unsigned long flags; | 2534 | unsigned long flags; |
2535 | 2535 | ||
2536 | spin_lock_irqsave(&info->lock,flags); | 2536 | spin_lock_irqsave(&info->lock,flags); |
2537 | info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR; | 2537 | if (onoff) |
2538 | info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR; | ||
2539 | else | ||
2540 | info->serial_signals &= ~SerialSignal_RTS + SerialSignal_DTR; | ||
2538 | set_signals(info); | 2541 | set_signals(info); |
2539 | spin_unlock_irqrestore(&info->lock,flags); | 2542 | spin_unlock_irqrestore(&info->lock,flags); |
2540 | } | 2543 | } |
diff --git a/drivers/char/pty.c b/drivers/char/pty.c index 31038a0052a2..5acd29e6e043 100644 --- a/drivers/char/pty.c +++ b/drivers/char/pty.c | |||
@@ -30,7 +30,6 @@ | |||
30 | 30 | ||
31 | #include <asm/system.h> | 31 | #include <asm/system.h> |
32 | 32 | ||
33 | /* These are global because they are accessed in tty_io.c */ | ||
34 | #ifdef CONFIG_UNIX98_PTYS | 33 | #ifdef CONFIG_UNIX98_PTYS |
35 | static struct tty_driver *ptm_driver; | 34 | static struct tty_driver *ptm_driver; |
36 | static struct tty_driver *pts_driver; | 35 | static struct tty_driver *pts_driver; |
@@ -111,7 +110,7 @@ static int pty_write(struct tty_struct *tty, const unsigned char *buf, | |||
111 | c = to->receive_room; | 110 | c = to->receive_room; |
112 | if (c > count) | 111 | if (c > count) |
113 | c = count; | 112 | c = count; |
114 | to->ldisc.ops->receive_buf(to, buf, NULL, c); | 113 | to->ldisc->ops->receive_buf(to, buf, NULL, c); |
115 | 114 | ||
116 | return c; | 115 | return c; |
117 | } | 116 | } |
@@ -149,11 +148,11 @@ static int pty_chars_in_buffer(struct tty_struct *tty) | |||
149 | int count; | 148 | int count; |
150 | 149 | ||
151 | /* We should get the line discipline lock for "tty->link" */ | 150 | /* We should get the line discipline lock for "tty->link" */ |
152 | if (!to || !to->ldisc.ops->chars_in_buffer) | 151 | if (!to || !to->ldisc->ops->chars_in_buffer) |
153 | return 0; | 152 | return 0; |
154 | 153 | ||
155 | /* The ldisc must report 0 if no characters available to be read */ | 154 | /* The ldisc must report 0 if no characters available to be read */ |
156 | count = to->ldisc.ops->chars_in_buffer(to); | 155 | count = to->ldisc->ops->chars_in_buffer(to); |
157 | 156 | ||
158 | if (tty->driver->subtype == PTY_TYPE_SLAVE) | 157 | if (tty->driver->subtype == PTY_TYPE_SLAVE) |
159 | return count; | 158 | return count; |
@@ -187,8 +186,8 @@ static void pty_flush_buffer(struct tty_struct *tty) | |||
187 | if (!to) | 186 | if (!to) |
188 | return; | 187 | return; |
189 | 188 | ||
190 | if (to->ldisc.ops->flush_buffer) | 189 | if (to->ldisc->ops->flush_buffer) |
191 | to->ldisc.ops->flush_buffer(to); | 190 | to->ldisc->ops->flush_buffer(to); |
192 | 191 | ||
193 | if (to->packet) { | 192 | if (to->packet) { |
194 | spin_lock_irqsave(&tty->ctrl_lock, flags); | 193 | spin_lock_irqsave(&tty->ctrl_lock, flags); |
diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c index f59fc5cea067..63d5b628477a 100644 --- a/drivers/char/rocket.c +++ b/drivers/char/rocket.c | |||
@@ -872,11 +872,16 @@ static int carrier_raised(struct tty_port *port) | |||
872 | return (sGetChanStatusLo(&info->channel) & CD_ACT) ? 1 : 0; | 872 | return (sGetChanStatusLo(&info->channel) & CD_ACT) ? 1 : 0; |
873 | } | 873 | } |
874 | 874 | ||
875 | static void raise_dtr_rts(struct tty_port *port) | 875 | static void dtr_rts(struct tty_port *port, int on) |
876 | { | 876 | { |
877 | struct r_port *info = container_of(port, struct r_port, port); | 877 | struct r_port *info = container_of(port, struct r_port, port); |
878 | sSetDTR(&info->channel); | 878 | if (on) { |
879 | sSetRTS(&info->channel); | 879 | sSetDTR(&info->channel); |
880 | sSetRTS(&info->channel); | ||
881 | } else { | ||
882 | sClrDTR(&info->channel); | ||
883 | sClrRTS(&info->channel); | ||
884 | } | ||
880 | } | 885 | } |
881 | 886 | ||
882 | /* | 887 | /* |
@@ -934,7 +939,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp) | |||
934 | /* | 939 | /* |
935 | * Info->count is now 1; so it's safe to sleep now. | 940 | * Info->count is now 1; so it's safe to sleep now. |
936 | */ | 941 | */ |
937 | if (!test_bit(ASYNC_INITIALIZED, &port->flags)) { | 942 | if (!test_bit(ASYNCB_INITIALIZED, &port->flags)) { |
938 | cp = &info->channel; | 943 | cp = &info->channel; |
939 | sSetRxTrigger(cp, TRIG_1); | 944 | sSetRxTrigger(cp, TRIG_1); |
940 | if (sGetChanStatus(cp) & CD_ACT) | 945 | if (sGetChanStatus(cp) & CD_ACT) |
@@ -958,7 +963,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp) | |||
958 | sEnRxFIFO(cp); | 963 | sEnRxFIFO(cp); |
959 | sEnTransmit(cp); | 964 | sEnTransmit(cp); |
960 | 965 | ||
961 | set_bit(ASYNC_INITIALIZED, &info->port.flags); | 966 | set_bit(ASYNCB_INITIALIZED, &info->port.flags); |
962 | 967 | ||
963 | /* | 968 | /* |
964 | * Set up the tty->alt_speed kludge | 969 | * Set up the tty->alt_speed kludge |
@@ -1641,7 +1646,7 @@ static int rp_write(struct tty_struct *tty, | |||
1641 | /* Write remaining data into the port's xmit_buf */ | 1646 | /* Write remaining data into the port's xmit_buf */ |
1642 | while (1) { | 1647 | while (1) { |
1643 | /* Hung up ? */ | 1648 | /* Hung up ? */ |
1644 | if (!test_bit(ASYNC_NORMAL_ACTIVE, &info->port.flags)) | 1649 | if (!test_bit(ASYNCB_NORMAL_ACTIVE, &info->port.flags)) |
1645 | goto end; | 1650 | goto end; |
1646 | c = min(count, XMIT_BUF_SIZE - info->xmit_cnt - 1); | 1651 | c = min(count, XMIT_BUF_SIZE - info->xmit_cnt - 1); |
1647 | c = min(c, XMIT_BUF_SIZE - info->xmit_head); | 1652 | c = min(c, XMIT_BUF_SIZE - info->xmit_head); |
@@ -2250,7 +2255,7 @@ static const struct tty_operations rocket_ops = { | |||
2250 | 2255 | ||
2251 | static const struct tty_port_operations rocket_port_ops = { | 2256 | static const struct tty_port_operations rocket_port_ops = { |
2252 | .carrier_raised = carrier_raised, | 2257 | .carrier_raised = carrier_raised, |
2253 | .raise_dtr_rts = raise_dtr_rts, | 2258 | .dtr_rts = dtr_rts, |
2254 | }; | 2259 | }; |
2255 | 2260 | ||
2256 | /* | 2261 | /* |
diff --git a/drivers/char/selection.c b/drivers/char/selection.c index cb8ca5698963..f97b9e848064 100644 --- a/drivers/char/selection.c +++ b/drivers/char/selection.c | |||
@@ -327,7 +327,7 @@ int paste_selection(struct tty_struct *tty) | |||
327 | } | 327 | } |
328 | count = sel_buffer_lth - pasted; | 328 | count = sel_buffer_lth - pasted; |
329 | count = min(count, tty->receive_room); | 329 | count = min(count, tty->receive_room); |
330 | tty->ldisc.ops->receive_buf(tty, sel_buffer + pasted, | 330 | tty->ldisc->ops->receive_buf(tty, sel_buffer + pasted, |
331 | NULL, count); | 331 | NULL, count); |
332 | pasted += count; | 332 | pasted += count; |
333 | } | 333 | } |
diff --git a/drivers/char/stallion.c b/drivers/char/stallion.c index 2ad813a801dc..53e504f41b20 100644 --- a/drivers/char/stallion.c +++ b/drivers/char/stallion.c | |||
@@ -772,11 +772,11 @@ static int stl_carrier_raised(struct tty_port *port) | |||
772 | return (portp->sigs & TIOCM_CD) ? 1 : 0; | 772 | return (portp->sigs & TIOCM_CD) ? 1 : 0; |
773 | } | 773 | } |
774 | 774 | ||
775 | static void stl_raise_dtr_rts(struct tty_port *port) | 775 | static void stl_dtr_rts(struct tty_port *port, int on) |
776 | { | 776 | { |
777 | struct stlport *portp = container_of(port, struct stlport, port); | 777 | struct stlport *portp = container_of(port, struct stlport, port); |
778 | /* Takes brd_lock internally */ | 778 | /* Takes brd_lock internally */ |
779 | stl_setsignals(portp, 1, 1); | 779 | stl_setsignals(portp, on, on); |
780 | } | 780 | } |
781 | 781 | ||
782 | /*****************************************************************************/ | 782 | /*****************************************************************************/ |
@@ -2547,7 +2547,7 @@ static const struct tty_operations stl_ops = { | |||
2547 | 2547 | ||
2548 | static const struct tty_port_operations stl_port_ops = { | 2548 | static const struct tty_port_operations stl_port_ops = { |
2549 | .carrier_raised = stl_carrier_raised, | 2549 | .carrier_raised = stl_carrier_raised, |
2550 | .raise_dtr_rts = stl_raise_dtr_rts, | 2550 | .dtr_rts = stl_dtr_rts, |
2551 | }; | 2551 | }; |
2552 | 2552 | ||
2553 | /*****************************************************************************/ | 2553 | /*****************************************************************************/ |
diff --git a/drivers/char/synclink.c b/drivers/char/synclink.c index afd0b26ca056..afded3a2379c 100644 --- a/drivers/char/synclink.c +++ b/drivers/char/synclink.c | |||
@@ -3247,13 +3247,16 @@ static int carrier_raised(struct tty_port *port) | |||
3247 | return (info->serial_signals & SerialSignal_DCD) ? 1 : 0; | 3247 | return (info->serial_signals & SerialSignal_DCD) ? 1 : 0; |
3248 | } | 3248 | } |
3249 | 3249 | ||
3250 | static void raise_dtr_rts(struct tty_port *port) | 3250 | static void dtr_rts(struct tty_port *port, int on) |
3251 | { | 3251 | { |
3252 | struct mgsl_struct *info = container_of(port, struct mgsl_struct, port); | 3252 | struct mgsl_struct *info = container_of(port, struct mgsl_struct, port); |
3253 | unsigned long flags; | 3253 | unsigned long flags; |
3254 | 3254 | ||
3255 | spin_lock_irqsave(&info->irq_spinlock,flags); | 3255 | spin_lock_irqsave(&info->irq_spinlock,flags); |
3256 | info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR; | 3256 | if (on) |
3257 | info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR; | ||
3258 | else | ||
3259 | info->serial_signals &= ~(SerialSignal_RTS + SerialSignal_DTR); | ||
3257 | usc_set_serial_signals(info); | 3260 | usc_set_serial_signals(info); |
3258 | spin_unlock_irqrestore(&info->irq_spinlock,flags); | 3261 | spin_unlock_irqrestore(&info->irq_spinlock,flags); |
3259 | } | 3262 | } |
@@ -4258,7 +4261,7 @@ static void mgsl_add_device( struct mgsl_struct *info ) | |||
4258 | 4261 | ||
4259 | static const struct tty_port_operations mgsl_port_ops = { | 4262 | static const struct tty_port_operations mgsl_port_ops = { |
4260 | .carrier_raised = carrier_raised, | 4263 | .carrier_raised = carrier_raised, |
4261 | .raise_dtr_rts = raise_dtr_rts, | 4264 | .dtr_rts = dtr_rts, |
4262 | }; | 4265 | }; |
4263 | 4266 | ||
4264 | 4267 | ||
diff --git a/drivers/char/synclink_gt.c b/drivers/char/synclink_gt.c index 5e256494686a..1386625fc4ca 100644 --- a/drivers/char/synclink_gt.c +++ b/drivers/char/synclink_gt.c | |||
@@ -214,6 +214,7 @@ struct slgt_desc | |||
214 | #define set_desc_next(a,b) (a).next = cpu_to_le32((unsigned int)(b)) | 214 | #define set_desc_next(a,b) (a).next = cpu_to_le32((unsigned int)(b)) |
215 | #define set_desc_count(a,b)(a).count = cpu_to_le16((unsigned short)(b)) | 215 | #define set_desc_count(a,b)(a).count = cpu_to_le16((unsigned short)(b)) |
216 | #define set_desc_eof(a,b) (a).status = cpu_to_le16((b) ? (le16_to_cpu((a).status) | BIT0) : (le16_to_cpu((a).status) & ~BIT0)) | 216 | #define set_desc_eof(a,b) (a).status = cpu_to_le16((b) ? (le16_to_cpu((a).status) | BIT0) : (le16_to_cpu((a).status) & ~BIT0)) |
217 | #define set_desc_status(a, b) (a).status = cpu_to_le16((unsigned short)(b)) | ||
217 | #define desc_count(a) (le16_to_cpu((a).count)) | 218 | #define desc_count(a) (le16_to_cpu((a).count)) |
218 | #define desc_status(a) (le16_to_cpu((a).status)) | 219 | #define desc_status(a) (le16_to_cpu((a).status)) |
219 | #define desc_complete(a) (le16_to_cpu((a).status) & BIT15) | 220 | #define desc_complete(a) (le16_to_cpu((a).status) & BIT15) |
@@ -297,6 +298,7 @@ struct slgt_info { | |||
297 | u32 max_frame_size; /* as set by device config */ | 298 | u32 max_frame_size; /* as set by device config */ |
298 | 299 | ||
299 | unsigned int rbuf_fill_level; | 300 | unsigned int rbuf_fill_level; |
301 | unsigned int rx_pio; | ||
300 | unsigned int if_mode; | 302 | unsigned int if_mode; |
301 | unsigned int base_clock; | 303 | unsigned int base_clock; |
302 | 304 | ||
@@ -331,6 +333,8 @@ struct slgt_info { | |||
331 | struct slgt_desc *rbufs; | 333 | struct slgt_desc *rbufs; |
332 | unsigned int rbuf_current; | 334 | unsigned int rbuf_current; |
333 | unsigned int rbuf_index; | 335 | unsigned int rbuf_index; |
336 | unsigned int rbuf_fill_index; | ||
337 | unsigned short rbuf_fill_count; | ||
334 | 338 | ||
335 | unsigned int tbuf_count; | 339 | unsigned int tbuf_count; |
336 | struct slgt_desc *tbufs; | 340 | struct slgt_desc *tbufs; |
@@ -2110,6 +2114,40 @@ static void ri_change(struct slgt_info *info, unsigned short status) | |||
2110 | info->pending_bh |= BH_STATUS; | 2114 | info->pending_bh |= BH_STATUS; |
2111 | } | 2115 | } |
2112 | 2116 | ||
2117 | static void isr_rxdata(struct slgt_info *info) | ||
2118 | { | ||
2119 | unsigned int count = info->rbuf_fill_count; | ||
2120 | unsigned int i = info->rbuf_fill_index; | ||
2121 | unsigned short reg; | ||
2122 | |||
2123 | while (rd_reg16(info, SSR) & IRQ_RXDATA) { | ||
2124 | reg = rd_reg16(info, RDR); | ||
2125 | DBGISR(("isr_rxdata %s RDR=%04X\n", info->device_name, reg)); | ||
2126 | if (desc_complete(info->rbufs[i])) { | ||
2127 | /* all buffers full */ | ||
2128 | rx_stop(info); | ||
2129 | info->rx_restart = 1; | ||
2130 | continue; | ||
2131 | } | ||
2132 | info->rbufs[i].buf[count++] = (unsigned char)reg; | ||
2133 | /* async mode saves status byte to buffer for each data byte */ | ||
2134 | if (info->params.mode == MGSL_MODE_ASYNC) | ||
2135 | info->rbufs[i].buf[count++] = (unsigned char)(reg >> 8); | ||
2136 | if (count == info->rbuf_fill_level || (reg & BIT10)) { | ||
2137 | /* buffer full or end of frame */ | ||
2138 | set_desc_count(info->rbufs[i], count); | ||
2139 | set_desc_status(info->rbufs[i], BIT15 | (reg >> 8)); | ||
2140 | info->rbuf_fill_count = count = 0; | ||
2141 | if (++i == info->rbuf_count) | ||
2142 | i = 0; | ||
2143 | info->pending_bh |= BH_RECEIVE; | ||
2144 | } | ||
2145 | } | ||
2146 | |||
2147 | info->rbuf_fill_index = i; | ||
2148 | info->rbuf_fill_count = count; | ||
2149 | } | ||
2150 | |||
2113 | static void isr_serial(struct slgt_info *info) | 2151 | static void isr_serial(struct slgt_info *info) |
2114 | { | 2152 | { |
2115 | unsigned short status = rd_reg16(info, SSR); | 2153 | unsigned short status = rd_reg16(info, SSR); |
@@ -2125,6 +2163,8 @@ static void isr_serial(struct slgt_info *info) | |||
2125 | if (info->tx_count) | 2163 | if (info->tx_count) |
2126 | isr_txeom(info, status); | 2164 | isr_txeom(info, status); |
2127 | } | 2165 | } |
2166 | if (info->rx_pio && (status & IRQ_RXDATA)) | ||
2167 | isr_rxdata(info); | ||
2128 | if ((status & IRQ_RXBREAK) && (status & RXBREAK)) { | 2168 | if ((status & IRQ_RXBREAK) && (status & RXBREAK)) { |
2129 | info->icount.brk++; | 2169 | info->icount.brk++; |
2130 | /* process break detection if tty control allows */ | 2170 | /* process break detection if tty control allows */ |
@@ -2141,7 +2181,8 @@ static void isr_serial(struct slgt_info *info) | |||
2141 | } else { | 2181 | } else { |
2142 | if (status & (IRQ_TXIDLE + IRQ_TXUNDER)) | 2182 | if (status & (IRQ_TXIDLE + IRQ_TXUNDER)) |
2143 | isr_txeom(info, status); | 2183 | isr_txeom(info, status); |
2144 | 2184 | if (info->rx_pio && (status & IRQ_RXDATA)) | |
2185 | isr_rxdata(info); | ||
2145 | if (status & IRQ_RXIDLE) { | 2186 | if (status & IRQ_RXIDLE) { |
2146 | if (status & RXIDLE) | 2187 | if (status & RXIDLE) |
2147 | info->icount.rxidle++; | 2188 | info->icount.rxidle++; |
@@ -2642,6 +2683,10 @@ static int rx_enable(struct slgt_info *info, int enable) | |||
2642 | return -EINVAL; | 2683 | return -EINVAL; |
2643 | } | 2684 | } |
2644 | info->rbuf_fill_level = rbuf_fill_level; | 2685 | info->rbuf_fill_level = rbuf_fill_level; |
2686 | if (rbuf_fill_level < 128) | ||
2687 | info->rx_pio = 1; /* PIO mode */ | ||
2688 | else | ||
2689 | info->rx_pio = 0; /* DMA mode */ | ||
2645 | rx_stop(info); /* restart receiver to use new fill level */ | 2690 | rx_stop(info); /* restart receiver to use new fill level */ |
2646 | } | 2691 | } |
2647 | 2692 | ||
@@ -3099,13 +3144,16 @@ static int carrier_raised(struct tty_port *port) | |||
3099 | return (info->signals & SerialSignal_DCD) ? 1 : 0; | 3144 | return (info->signals & SerialSignal_DCD) ? 1 : 0; |
3100 | } | 3145 | } |
3101 | 3146 | ||
3102 | static void raise_dtr_rts(struct tty_port *port) | 3147 | static void dtr_rts(struct tty_port *port, int on) |
3103 | { | 3148 | { |
3104 | unsigned long flags; | 3149 | unsigned long flags; |
3105 | struct slgt_info *info = container_of(port, struct slgt_info, port); | 3150 | struct slgt_info *info = container_of(port, struct slgt_info, port); |
3106 | 3151 | ||
3107 | spin_lock_irqsave(&info->lock,flags); | 3152 | spin_lock_irqsave(&info->lock,flags); |
3108 | info->signals |= SerialSignal_RTS + SerialSignal_DTR; | 3153 | if (on) |
3154 | info->signals |= SerialSignal_RTS + SerialSignal_DTR; | ||
3155 | else | ||
3156 | info->signals &= ~(SerialSignal_RTS + SerialSignal_DTR); | ||
3109 | set_signals(info); | 3157 | set_signals(info); |
3110 | spin_unlock_irqrestore(&info->lock,flags); | 3158 | spin_unlock_irqrestore(&info->lock,flags); |
3111 | } | 3159 | } |
@@ -3419,7 +3467,7 @@ static void add_device(struct slgt_info *info) | |||
3419 | 3467 | ||
3420 | static const struct tty_port_operations slgt_port_ops = { | 3468 | static const struct tty_port_operations slgt_port_ops = { |
3421 | .carrier_raised = carrier_raised, | 3469 | .carrier_raised = carrier_raised, |
3422 | .raise_dtr_rts = raise_dtr_rts, | 3470 | .dtr_rts = dtr_rts, |
3423 | }; | 3471 | }; |
3424 | 3472 | ||
3425 | /* | 3473 | /* |
@@ -3841,15 +3889,27 @@ static void rx_start(struct slgt_info *info) | |||
3841 | rdma_reset(info); | 3889 | rdma_reset(info); |
3842 | reset_rbufs(info); | 3890 | reset_rbufs(info); |
3843 | 3891 | ||
3844 | /* set 1st descriptor address */ | 3892 | if (info->rx_pio) { |
3845 | wr_reg32(info, RDDAR, info->rbufs[0].pdesc); | 3893 | /* rx request when rx FIFO not empty */ |
3846 | 3894 | wr_reg16(info, SCR, (unsigned short)(rd_reg16(info, SCR) & ~BIT14)); | |
3847 | if (info->params.mode != MGSL_MODE_ASYNC) { | 3895 | slgt_irq_on(info, IRQ_RXDATA); |
3848 | /* enable rx DMA and DMA interrupt */ | 3896 | if (info->params.mode == MGSL_MODE_ASYNC) { |
3849 | wr_reg32(info, RDCSR, (BIT2 + BIT0)); | 3897 | /* enable saving of rx status */ |
3898 | wr_reg32(info, RDCSR, BIT6); | ||
3899 | } | ||
3850 | } else { | 3900 | } else { |
3851 | /* enable saving of rx status, rx DMA and DMA interrupt */ | 3901 | /* rx request when rx FIFO half full */ |
3852 | wr_reg32(info, RDCSR, (BIT6 + BIT2 + BIT0)); | 3902 | wr_reg16(info, SCR, (unsigned short)(rd_reg16(info, SCR) | BIT14)); |
3903 | /* set 1st descriptor address */ | ||
3904 | wr_reg32(info, RDDAR, info->rbufs[0].pdesc); | ||
3905 | |||
3906 | if (info->params.mode != MGSL_MODE_ASYNC) { | ||
3907 | /* enable rx DMA and DMA interrupt */ | ||
3908 | wr_reg32(info, RDCSR, (BIT2 + BIT0)); | ||
3909 | } else { | ||
3910 | /* enable saving of rx status, rx DMA and DMA interrupt */ | ||
3911 | wr_reg32(info, RDCSR, (BIT6 + BIT2 + BIT0)); | ||
3912 | } | ||
3853 | } | 3913 | } |
3854 | 3914 | ||
3855 | slgt_irq_on(info, IRQ_RXOVER); | 3915 | slgt_irq_on(info, IRQ_RXOVER); |
@@ -4467,6 +4527,8 @@ static void free_rbufs(struct slgt_info *info, unsigned int i, unsigned int last | |||
4467 | static void reset_rbufs(struct slgt_info *info) | 4527 | static void reset_rbufs(struct slgt_info *info) |
4468 | { | 4528 | { |
4469 | free_rbufs(info, 0, info->rbuf_count - 1); | 4529 | free_rbufs(info, 0, info->rbuf_count - 1); |
4530 | info->rbuf_fill_index = 0; | ||
4531 | info->rbuf_fill_count = 0; | ||
4470 | } | 4532 | } |
4471 | 4533 | ||
4472 | /* | 4534 | /* |
diff --git a/drivers/char/synclinkmp.c b/drivers/char/synclinkmp.c index 26de60efe4b2..6f727e3c53ad 100644 --- a/drivers/char/synclinkmp.c +++ b/drivers/char/synclinkmp.c | |||
@@ -3277,13 +3277,16 @@ static int carrier_raised(struct tty_port *port) | |||
3277 | return (info->serial_signals & SerialSignal_DCD) ? 1 : 0; | 3277 | return (info->serial_signals & SerialSignal_DCD) ? 1 : 0; |
3278 | } | 3278 | } |
3279 | 3279 | ||
3280 | static void raise_dtr_rts(struct tty_port *port) | 3280 | static void dtr_rts(struct tty_port *port, int on) |
3281 | { | 3281 | { |
3282 | SLMP_INFO *info = container_of(port, SLMP_INFO, port); | 3282 | SLMP_INFO *info = container_of(port, SLMP_INFO, port); |
3283 | unsigned long flags; | 3283 | unsigned long flags; |
3284 | 3284 | ||
3285 | spin_lock_irqsave(&info->lock,flags); | 3285 | spin_lock_irqsave(&info->lock,flags); |
3286 | info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR; | 3286 | if (on) |
3287 | info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR; | ||
3288 | else | ||
3289 | info->serial_signals &= ~(SerialSignal_RTS + SerialSignal_DTR); | ||
3287 | set_signals(info); | 3290 | set_signals(info); |
3288 | spin_unlock_irqrestore(&info->lock,flags); | 3291 | spin_unlock_irqrestore(&info->lock,flags); |
3289 | } | 3292 | } |
@@ -3746,7 +3749,7 @@ static void add_device(SLMP_INFO *info) | |||
3746 | 3749 | ||
3747 | static const struct tty_port_operations port_ops = { | 3750 | static const struct tty_port_operations port_ops = { |
3748 | .carrier_raised = carrier_raised, | 3751 | .carrier_raised = carrier_raised, |
3749 | .raise_dtr_rts = raise_dtr_rts, | 3752 | .dtr_rts = dtr_rts, |
3750 | }; | 3753 | }; |
3751 | 3754 | ||
3752 | /* Allocate and initialize a device instance structure | 3755 | /* Allocate and initialize a device instance structure |
diff --git a/drivers/char/tty_audit.c b/drivers/char/tty_audit.c index 55ba6f142883..ac16fbec72d0 100644 --- a/drivers/char/tty_audit.c +++ b/drivers/char/tty_audit.c | |||
@@ -29,10 +29,7 @@ static struct tty_audit_buf *tty_audit_buf_alloc(int major, int minor, | |||
29 | buf = kmalloc(sizeof(*buf), GFP_KERNEL); | 29 | buf = kmalloc(sizeof(*buf), GFP_KERNEL); |
30 | if (!buf) | 30 | if (!buf) |
31 | goto err; | 31 | goto err; |
32 | if (PAGE_SIZE != N_TTY_BUF_SIZE) | 32 | buf->data = kmalloc(N_TTY_BUF_SIZE, GFP_KERNEL); |
33 | buf->data = kmalloc(N_TTY_BUF_SIZE, GFP_KERNEL); | ||
34 | else | ||
35 | buf->data = (unsigned char *)__get_free_page(GFP_KERNEL); | ||
36 | if (!buf->data) | 33 | if (!buf->data) |
37 | goto err_buf; | 34 | goto err_buf; |
38 | atomic_set(&buf->count, 1); | 35 | atomic_set(&buf->count, 1); |
@@ -52,10 +49,7 @@ err: | |||
52 | static void tty_audit_buf_free(struct tty_audit_buf *buf) | 49 | static void tty_audit_buf_free(struct tty_audit_buf *buf) |
53 | { | 50 | { |
54 | WARN_ON(buf->valid != 0); | 51 | WARN_ON(buf->valid != 0); |
55 | if (PAGE_SIZE != N_TTY_BUF_SIZE) | 52 | kfree(buf->data); |
56 | kfree(buf->data); | ||
57 | else | ||
58 | free_page((unsigned long)buf->data); | ||
59 | kfree(buf); | 53 | kfree(buf); |
60 | } | 54 | } |
61 | 55 | ||
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c index 66b99a2049e3..939e198d7670 100644 --- a/drivers/char/tty_io.c +++ b/drivers/char/tty_io.c | |||
@@ -295,7 +295,7 @@ struct tty_driver *tty_find_polling_driver(char *name, int *line) | |||
295 | struct tty_driver *p, *res = NULL; | 295 | struct tty_driver *p, *res = NULL; |
296 | int tty_line = 0; | 296 | int tty_line = 0; |
297 | int len; | 297 | int len; |
298 | char *str; | 298 | char *str, *stp; |
299 | 299 | ||
300 | for (str = name; *str; str++) | 300 | for (str = name; *str; str++) |
301 | if ((*str >= '0' && *str <= '9') || *str == ',') | 301 | if ((*str >= '0' && *str <= '9') || *str == ',') |
@@ -311,13 +311,14 @@ struct tty_driver *tty_find_polling_driver(char *name, int *line) | |||
311 | list_for_each_entry(p, &tty_drivers, tty_drivers) { | 311 | list_for_each_entry(p, &tty_drivers, tty_drivers) { |
312 | if (strncmp(name, p->name, len) != 0) | 312 | if (strncmp(name, p->name, len) != 0) |
313 | continue; | 313 | continue; |
314 | if (*str == ',') | 314 | stp = str; |
315 | str++; | 315 | if (*stp == ',') |
316 | if (*str == '\0') | 316 | stp++; |
317 | str = NULL; | 317 | if (*stp == '\0') |
318 | stp = NULL; | ||
318 | 319 | ||
319 | if (tty_line >= 0 && tty_line <= p->num && p->ops && | 320 | if (tty_line >= 0 && tty_line <= p->num && p->ops && |
320 | p->ops->poll_init && !p->ops->poll_init(p, tty_line, str)) { | 321 | p->ops->poll_init && !p->ops->poll_init(p, tty_line, stp)) { |
321 | res = tty_driver_kref_get(p); | 322 | res = tty_driver_kref_get(p); |
322 | *line = tty_line; | 323 | *line = tty_line; |
323 | break; | 324 | break; |
@@ -470,43 +471,6 @@ void tty_wakeup(struct tty_struct *tty) | |||
470 | EXPORT_SYMBOL_GPL(tty_wakeup); | 471 | EXPORT_SYMBOL_GPL(tty_wakeup); |
471 | 472 | ||
472 | /** | 473 | /** |
473 | * tty_ldisc_flush - flush line discipline queue | ||
474 | * @tty: tty | ||
475 | * | ||
476 | * Flush the line discipline queue (if any) for this tty. If there | ||
477 | * is no line discipline active this is a no-op. | ||
478 | */ | ||
479 | |||
480 | void tty_ldisc_flush(struct tty_struct *tty) | ||
481 | { | ||
482 | struct tty_ldisc *ld = tty_ldisc_ref(tty); | ||
483 | if (ld) { | ||
484 | if (ld->ops->flush_buffer) | ||
485 | ld->ops->flush_buffer(tty); | ||
486 | tty_ldisc_deref(ld); | ||
487 | } | ||
488 | tty_buffer_flush(tty); | ||
489 | } | ||
490 | |||
491 | EXPORT_SYMBOL_GPL(tty_ldisc_flush); | ||
492 | |||
493 | /** | ||
494 | * tty_reset_termios - reset terminal state | ||
495 | * @tty: tty to reset | ||
496 | * | ||
497 | * Restore a terminal to the driver default state | ||
498 | */ | ||
499 | |||
500 | static void tty_reset_termios(struct tty_struct *tty) | ||
501 | { | ||
502 | mutex_lock(&tty->termios_mutex); | ||
503 | *tty->termios = tty->driver->init_termios; | ||
504 | tty->termios->c_ispeed = tty_termios_input_baud_rate(tty->termios); | ||
505 | tty->termios->c_ospeed = tty_termios_baud_rate(tty->termios); | ||
506 | mutex_unlock(&tty->termios_mutex); | ||
507 | } | ||
508 | |||
509 | /** | ||
510 | * do_tty_hangup - actual handler for hangup events | 474 | * do_tty_hangup - actual handler for hangup events |
511 | * @work: tty device | 475 | * @work: tty device |
512 | * | 476 | * |
@@ -535,7 +499,6 @@ static void do_tty_hangup(struct work_struct *work) | |||
535 | struct file *cons_filp = NULL; | 499 | struct file *cons_filp = NULL; |
536 | struct file *filp, *f = NULL; | 500 | struct file *filp, *f = NULL; |
537 | struct task_struct *p; | 501 | struct task_struct *p; |
538 | struct tty_ldisc *ld; | ||
539 | int closecount = 0, n; | 502 | int closecount = 0, n; |
540 | unsigned long flags; | 503 | unsigned long flags; |
541 | int refs = 0; | 504 | int refs = 0; |
@@ -566,40 +529,8 @@ static void do_tty_hangup(struct work_struct *work) | |||
566 | filp->f_op = &hung_up_tty_fops; | 529 | filp->f_op = &hung_up_tty_fops; |
567 | } | 530 | } |
568 | file_list_unlock(); | 531 | file_list_unlock(); |
569 | /* | ||
570 | * FIXME! What are the locking issues here? This may me overdoing | ||
571 | * things... This question is especially important now that we've | ||
572 | * removed the irqlock. | ||
573 | */ | ||
574 | ld = tty_ldisc_ref(tty); | ||
575 | if (ld != NULL) { | ||
576 | /* We may have no line discipline at this point */ | ||
577 | if (ld->ops->flush_buffer) | ||
578 | ld->ops->flush_buffer(tty); | ||
579 | tty_driver_flush_buffer(tty); | ||
580 | if ((test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) && | ||
581 | ld->ops->write_wakeup) | ||
582 | ld->ops->write_wakeup(tty); | ||
583 | if (ld->ops->hangup) | ||
584 | ld->ops->hangup(tty); | ||
585 | } | ||
586 | /* | ||
587 | * FIXME: Once we trust the LDISC code better we can wait here for | ||
588 | * ldisc completion and fix the driver call race | ||
589 | */ | ||
590 | wake_up_interruptible_poll(&tty->write_wait, POLLOUT); | ||
591 | wake_up_interruptible_poll(&tty->read_wait, POLLIN); | ||
592 | /* | ||
593 | * Shutdown the current line discipline, and reset it to | ||
594 | * N_TTY. | ||
595 | */ | ||
596 | if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) | ||
597 | tty_reset_termios(tty); | ||
598 | /* Defer ldisc switch */ | ||
599 | /* tty_deferred_ldisc_switch(N_TTY); | ||
600 | 532 | ||
601 | This should get done automatically when the port closes and | 533 | tty_ldisc_hangup(tty); |
602 | tty_release is called */ | ||
603 | 534 | ||
604 | read_lock(&tasklist_lock); | 535 | read_lock(&tasklist_lock); |
605 | if (tty->session) { | 536 | if (tty->session) { |
@@ -628,12 +559,15 @@ static void do_tty_hangup(struct work_struct *work) | |||
628 | read_unlock(&tasklist_lock); | 559 | read_unlock(&tasklist_lock); |
629 | 560 | ||
630 | spin_lock_irqsave(&tty->ctrl_lock, flags); | 561 | spin_lock_irqsave(&tty->ctrl_lock, flags); |
631 | tty->flags = 0; | 562 | clear_bit(TTY_THROTTLED, &tty->flags); |
563 | clear_bit(TTY_PUSH, &tty->flags); | ||
564 | clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); | ||
632 | put_pid(tty->session); | 565 | put_pid(tty->session); |
633 | put_pid(tty->pgrp); | 566 | put_pid(tty->pgrp); |
634 | tty->session = NULL; | 567 | tty->session = NULL; |
635 | tty->pgrp = NULL; | 568 | tty->pgrp = NULL; |
636 | tty->ctrl_status = 0; | 569 | tty->ctrl_status = 0; |
570 | set_bit(TTY_HUPPED, &tty->flags); | ||
637 | spin_unlock_irqrestore(&tty->ctrl_lock, flags); | 571 | spin_unlock_irqrestore(&tty->ctrl_lock, flags); |
638 | 572 | ||
639 | /* Account for the p->signal references we killed */ | 573 | /* Account for the p->signal references we killed */ |
@@ -659,10 +593,7 @@ static void do_tty_hangup(struct work_struct *work) | |||
659 | * can't yet guarantee all that. | 593 | * can't yet guarantee all that. |
660 | */ | 594 | */ |
661 | set_bit(TTY_HUPPED, &tty->flags); | 595 | set_bit(TTY_HUPPED, &tty->flags); |
662 | if (ld) { | 596 | tty_ldisc_enable(tty); |
663 | tty_ldisc_enable(tty); | ||
664 | tty_ldisc_deref(ld); | ||
665 | } | ||
666 | unlock_kernel(); | 597 | unlock_kernel(); |
667 | if (f) | 598 | if (f) |
668 | fput(f); | 599 | fput(f); |
@@ -2480,6 +2411,24 @@ static int tty_tiocmset(struct tty_struct *tty, struct file *file, unsigned int | |||
2480 | return tty->ops->tiocmset(tty, file, set, clear); | 2411 | return tty->ops->tiocmset(tty, file, set, clear); |
2481 | } | 2412 | } |
2482 | 2413 | ||
2414 | struct tty_struct *tty_pair_get_tty(struct tty_struct *tty) | ||
2415 | { | ||
2416 | if (tty->driver->type == TTY_DRIVER_TYPE_PTY && | ||
2417 | tty->driver->subtype == PTY_TYPE_MASTER) | ||
2418 | tty = tty->link; | ||
2419 | return tty; | ||
2420 | } | ||
2421 | EXPORT_SYMBOL(tty_pair_get_tty); | ||
2422 | |||
2423 | struct tty_struct *tty_pair_get_pty(struct tty_struct *tty) | ||
2424 | { | ||
2425 | if (tty->driver->type == TTY_DRIVER_TYPE_PTY && | ||
2426 | tty->driver->subtype == PTY_TYPE_MASTER) | ||
2427 | return tty; | ||
2428 | return tty->link; | ||
2429 | } | ||
2430 | EXPORT_SYMBOL(tty_pair_get_pty); | ||
2431 | |||
2483 | /* | 2432 | /* |
2484 | * Split this up, as gcc can choke on it otherwise.. | 2433 | * Split this up, as gcc can choke on it otherwise.. |
2485 | */ | 2434 | */ |
@@ -2495,11 +2444,7 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
2495 | if (tty_paranoia_check(tty, inode, "tty_ioctl")) | 2444 | if (tty_paranoia_check(tty, inode, "tty_ioctl")) |
2496 | return -EINVAL; | 2445 | return -EINVAL; |
2497 | 2446 | ||
2498 | real_tty = tty; | 2447 | real_tty = tty_pair_get_tty(tty); |
2499 | if (tty->driver->type == TTY_DRIVER_TYPE_PTY && | ||
2500 | tty->driver->subtype == PTY_TYPE_MASTER) | ||
2501 | real_tty = tty->link; | ||
2502 | |||
2503 | 2448 | ||
2504 | /* | 2449 | /* |
2505 | * Factor out some common prep work | 2450 | * Factor out some common prep work |
@@ -2555,7 +2500,7 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
2555 | case TIOCGSID: | 2500 | case TIOCGSID: |
2556 | return tiocgsid(tty, real_tty, p); | 2501 | return tiocgsid(tty, real_tty, p); |
2557 | case TIOCGETD: | 2502 | case TIOCGETD: |
2558 | return put_user(tty->ldisc.ops->num, (int __user *)p); | 2503 | return put_user(tty->ldisc->ops->num, (int __user *)p); |
2559 | case TIOCSETD: | 2504 | case TIOCSETD: |
2560 | return tiocsetd(tty, p); | 2505 | return tiocsetd(tty, p); |
2561 | /* | 2506 | /* |
@@ -2770,6 +2715,7 @@ void initialize_tty_struct(struct tty_struct *tty, | |||
2770 | tty->buf.head = tty->buf.tail = NULL; | 2715 | tty->buf.head = tty->buf.tail = NULL; |
2771 | tty_buffer_init(tty); | 2716 | tty_buffer_init(tty); |
2772 | mutex_init(&tty->termios_mutex); | 2717 | mutex_init(&tty->termios_mutex); |
2718 | mutex_init(&tty->ldisc_mutex); | ||
2773 | init_waitqueue_head(&tty->write_wait); | 2719 | init_waitqueue_head(&tty->write_wait); |
2774 | init_waitqueue_head(&tty->read_wait); | 2720 | init_waitqueue_head(&tty->read_wait); |
2775 | INIT_WORK(&tty->hangup_work, do_tty_hangup); | 2721 | INIT_WORK(&tty->hangup_work, do_tty_hangup); |
diff --git a/drivers/char/tty_ioctl.c b/drivers/char/tty_ioctl.c index 6f4c7d0a53bf..8116bb1c8f80 100644 --- a/drivers/char/tty_ioctl.c +++ b/drivers/char/tty_ioctl.c | |||
@@ -97,14 +97,19 @@ EXPORT_SYMBOL(tty_driver_flush_buffer); | |||
97 | * @tty: terminal | 97 | * @tty: terminal |
98 | * | 98 | * |
99 | * Indicate that a tty should stop transmitting data down the stack. | 99 | * Indicate that a tty should stop transmitting data down the stack. |
100 | * Takes the termios mutex to protect against parallel throttle/unthrottle | ||
101 | * and also to ensure the driver can consistently reference its own | ||
102 | * termios data at this point when implementing software flow control. | ||
100 | */ | 103 | */ |
101 | 104 | ||
102 | void tty_throttle(struct tty_struct *tty) | 105 | void tty_throttle(struct tty_struct *tty) |
103 | { | 106 | { |
107 | mutex_lock(&tty->termios_mutex); | ||
104 | /* check TTY_THROTTLED first so it indicates our state */ | 108 | /* check TTY_THROTTLED first so it indicates our state */ |
105 | if (!test_and_set_bit(TTY_THROTTLED, &tty->flags) && | 109 | if (!test_and_set_bit(TTY_THROTTLED, &tty->flags) && |
106 | tty->ops->throttle) | 110 | tty->ops->throttle) |
107 | tty->ops->throttle(tty); | 111 | tty->ops->throttle(tty); |
112 | mutex_unlock(&tty->termios_mutex); | ||
108 | } | 113 | } |
109 | EXPORT_SYMBOL(tty_throttle); | 114 | EXPORT_SYMBOL(tty_throttle); |
110 | 115 | ||
@@ -113,13 +118,21 @@ EXPORT_SYMBOL(tty_throttle); | |||
113 | * @tty: terminal | 118 | * @tty: terminal |
114 | * | 119 | * |
115 | * Indicate that a tty may continue transmitting data down the stack. | 120 | * Indicate that a tty may continue transmitting data down the stack. |
121 | * Takes the termios mutex to protect against parallel throttle/unthrottle | ||
122 | * and also to ensure the driver can consistently reference its own | ||
123 | * termios data at this point when implementing software flow control. | ||
124 | * | ||
125 | * Drivers should however remember that the stack can issue a throttle, | ||
126 | * then change flow control method, then unthrottle. | ||
116 | */ | 127 | */ |
117 | 128 | ||
118 | void tty_unthrottle(struct tty_struct *tty) | 129 | void tty_unthrottle(struct tty_struct *tty) |
119 | { | 130 | { |
131 | mutex_lock(&tty->termios_mutex); | ||
120 | if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) && | 132 | if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) && |
121 | tty->ops->unthrottle) | 133 | tty->ops->unthrottle) |
122 | tty->ops->unthrottle(tty); | 134 | tty->ops->unthrottle(tty); |
135 | mutex_unlock(&tty->termios_mutex); | ||
123 | } | 136 | } |
124 | EXPORT_SYMBOL(tty_unthrottle); | 137 | EXPORT_SYMBOL(tty_unthrottle); |
125 | 138 | ||
@@ -613,9 +626,25 @@ static int set_termios(struct tty_struct *tty, void __user *arg, int opt) | |||
613 | return 0; | 626 | return 0; |
614 | } | 627 | } |
615 | 628 | ||
629 | static void copy_termios(struct tty_struct *tty, struct ktermios *kterm) | ||
630 | { | ||
631 | mutex_lock(&tty->termios_mutex); | ||
632 | memcpy(kterm, tty->termios, sizeof(struct ktermios)); | ||
633 | mutex_unlock(&tty->termios_mutex); | ||
634 | } | ||
635 | |||
636 | static void copy_termios_locked(struct tty_struct *tty, struct ktermios *kterm) | ||
637 | { | ||
638 | mutex_lock(&tty->termios_mutex); | ||
639 | memcpy(kterm, tty->termios_locked, sizeof(struct ktermios)); | ||
640 | mutex_unlock(&tty->termios_mutex); | ||
641 | } | ||
642 | |||
616 | static int get_termio(struct tty_struct *tty, struct termio __user *termio) | 643 | static int get_termio(struct tty_struct *tty, struct termio __user *termio) |
617 | { | 644 | { |
618 | if (kernel_termios_to_user_termio(termio, tty->termios)) | 645 | struct ktermios kterm; |
646 | copy_termios(tty, &kterm); | ||
647 | if (kernel_termios_to_user_termio(termio, &kterm)) | ||
619 | return -EFAULT; | 648 | return -EFAULT; |
620 | return 0; | 649 | return 0; |
621 | } | 650 | } |
@@ -917,6 +946,8 @@ int tty_mode_ioctl(struct tty_struct *tty, struct file *file, | |||
917 | struct tty_struct *real_tty; | 946 | struct tty_struct *real_tty; |
918 | void __user *p = (void __user *)arg; | 947 | void __user *p = (void __user *)arg; |
919 | int ret = 0; | 948 | int ret = 0; |
949 | struct ktermios kterm; | ||
950 | struct termiox ktermx; | ||
920 | 951 | ||
921 | if (tty->driver->type == TTY_DRIVER_TYPE_PTY && | 952 | if (tty->driver->type == TTY_DRIVER_TYPE_PTY && |
922 | tty->driver->subtype == PTY_TYPE_MASTER) | 953 | tty->driver->subtype == PTY_TYPE_MASTER) |
@@ -952,23 +983,20 @@ int tty_mode_ioctl(struct tty_struct *tty, struct file *file, | |||
952 | return set_termios(real_tty, p, TERMIOS_OLD); | 983 | return set_termios(real_tty, p, TERMIOS_OLD); |
953 | #ifndef TCGETS2 | 984 | #ifndef TCGETS2 |
954 | case TCGETS: | 985 | case TCGETS: |
955 | mutex_lock(&real_tty->termios_mutex); | 986 | copy_termios(real_tty, &kterm); |
956 | if (kernel_termios_to_user_termios((struct termios __user *)arg, real_tty->termios)) | 987 | if (kernel_termios_to_user_termios((struct termios __user *)arg, &kterm)) |
957 | ret = -EFAULT; | 988 | ret = -EFAULT; |
958 | mutex_unlock(&real_tty->termios_mutex); | ||
959 | return ret; | 989 | return ret; |
960 | #else | 990 | #else |
961 | case TCGETS: | 991 | case TCGETS: |
962 | mutex_lock(&real_tty->termios_mutex); | 992 | copy_termios(real_tty, &kterm); |
963 | if (kernel_termios_to_user_termios_1((struct termios __user *)arg, real_tty->termios)) | 993 | if (kernel_termios_to_user_termios_1((struct termios __user *)arg, &kterm)) |
964 | ret = -EFAULT; | 994 | ret = -EFAULT; |
965 | mutex_unlock(&real_tty->termios_mutex); | ||
966 | return ret; | 995 | return ret; |
967 | case TCGETS2: | 996 | case TCGETS2: |
968 | mutex_lock(&real_tty->termios_mutex); | 997 | copy_termios(real_tty, &kterm); |
969 | if (kernel_termios_to_user_termios((struct termios2 __user *)arg, real_tty->termios)) | 998 | if (kernel_termios_to_user_termios((struct termios2 __user *)arg, &kterm)) |
970 | ret = -EFAULT; | 999 | ret = -EFAULT; |
971 | mutex_unlock(&real_tty->termios_mutex); | ||
972 | return ret; | 1000 | return ret; |
973 | case TCSETSF2: | 1001 | case TCSETSF2: |
974 | return set_termios(real_tty, p, TERMIOS_FLUSH | TERMIOS_WAIT); | 1002 | return set_termios(real_tty, p, TERMIOS_FLUSH | TERMIOS_WAIT); |
@@ -987,34 +1015,36 @@ int tty_mode_ioctl(struct tty_struct *tty, struct file *file, | |||
987 | return set_termios(real_tty, p, TERMIOS_TERMIO); | 1015 | return set_termios(real_tty, p, TERMIOS_TERMIO); |
988 | #ifndef TCGETS2 | 1016 | #ifndef TCGETS2 |
989 | case TIOCGLCKTRMIOS: | 1017 | case TIOCGLCKTRMIOS: |
990 | mutex_lock(&real_tty->termios_mutex); | 1018 | copy_termios_locked(real_tty, &kterm); |
991 | if (kernel_termios_to_user_termios((struct termios __user *)arg, real_tty->termios_locked)) | 1019 | if (kernel_termios_to_user_termios((struct termios __user *)arg, &kterm)) |
992 | ret = -EFAULT; | 1020 | ret = -EFAULT; |
993 | mutex_unlock(&real_tty->termios_mutex); | ||
994 | return ret; | 1021 | return ret; |
995 | case TIOCSLCKTRMIOS: | 1022 | case TIOCSLCKTRMIOS: |
996 | if (!capable(CAP_SYS_ADMIN)) | 1023 | if (!capable(CAP_SYS_ADMIN)) |
997 | return -EPERM; | 1024 | return -EPERM; |
998 | mutex_lock(&real_tty->termios_mutex); | 1025 | copy_termios_locked(real_tty, &kterm); |
999 | if (user_termios_to_kernel_termios(real_tty->termios_locked, | 1026 | if (user_termios_to_kernel_termios(&kterm, |
1000 | (struct termios __user *) arg)) | 1027 | (struct termios __user *) arg)) |
1001 | ret = -EFAULT; | 1028 | return -EFAULT; |
1029 | mutex_lock(&real_tty->termios_mutex); | ||
1030 | memcpy(real_tty->termios_locked, &kterm, sizeof(struct ktermios)); | ||
1002 | mutex_unlock(&real_tty->termios_mutex); | 1031 | mutex_unlock(&real_tty->termios_mutex); |
1003 | return ret; | 1032 | return 0; |
1004 | #else | 1033 | #else |
1005 | case TIOCGLCKTRMIOS: | 1034 | case TIOCGLCKTRMIOS: |
1006 | mutex_lock(&real_tty->termios_mutex); | 1035 | copy_termios_locked(real_tty, &kterm); |
1007 | if (kernel_termios_to_user_termios_1((struct termios __user *)arg, real_tty->termios_locked)) | 1036 | if (kernel_termios_to_user_termios_1((struct termios __user *)arg, &kterm)) |
1008 | ret = -EFAULT; | 1037 | ret = -EFAULT; |
1009 | mutex_unlock(&real_tty->termios_mutex); | ||
1010 | return ret; | 1038 | return ret; |
1011 | case TIOCSLCKTRMIOS: | 1039 | case TIOCSLCKTRMIOS: |
1012 | if (!capable(CAP_SYS_ADMIN)) | 1040 | if (!capable(CAP_SYS_ADMIN)) |
1013 | ret = -EPERM; | 1041 | return -EPERM; |
1014 | mutex_lock(&real_tty->termios_mutex); | 1042 | copy_termios_locked(real_tty, &kterm); |
1015 | if (user_termios_to_kernel_termios_1(real_tty->termios_locked, | 1043 | if (user_termios_to_kernel_termios_1(&kterm, |
1016 | (struct termios __user *) arg)) | 1044 | (struct termios __user *) arg)) |
1017 | ret = -EFAULT; | 1045 | return -EFAULT; |
1046 | mutex_lock(&real_tty->termios_mutex); | ||
1047 | memcpy(real_tty->termios_locked, &kterm, sizeof(struct ktermios)); | ||
1018 | mutex_unlock(&real_tty->termios_mutex); | 1048 | mutex_unlock(&real_tty->termios_mutex); |
1019 | return ret; | 1049 | return ret; |
1020 | #endif | 1050 | #endif |
@@ -1023,9 +1053,10 @@ int tty_mode_ioctl(struct tty_struct *tty, struct file *file, | |||
1023 | if (real_tty->termiox == NULL) | 1053 | if (real_tty->termiox == NULL) |
1024 | return -EINVAL; | 1054 | return -EINVAL; |
1025 | mutex_lock(&real_tty->termios_mutex); | 1055 | mutex_lock(&real_tty->termios_mutex); |
1026 | if (copy_to_user(p, real_tty->termiox, sizeof(struct termiox))) | 1056 | memcpy(&ktermx, real_tty->termiox, sizeof(struct termiox)); |
1027 | ret = -EFAULT; | ||
1028 | mutex_unlock(&real_tty->termios_mutex); | 1057 | mutex_unlock(&real_tty->termios_mutex); |
1058 | if (copy_to_user(p, &ktermx, sizeof(struct termiox))) | ||
1059 | ret = -EFAULT; | ||
1029 | return ret; | 1060 | return ret; |
1030 | case TCSETX: | 1061 | case TCSETX: |
1031 | return set_termiox(real_tty, p, 0); | 1062 | return set_termiox(real_tty, p, 0); |
@@ -1035,10 +1066,9 @@ int tty_mode_ioctl(struct tty_struct *tty, struct file *file, | |||
1035 | return set_termiox(real_tty, p, TERMIOS_FLUSH); | 1066 | return set_termiox(real_tty, p, TERMIOS_FLUSH); |
1036 | #endif | 1067 | #endif |
1037 | case TIOCGSOFTCAR: | 1068 | case TIOCGSOFTCAR: |
1038 | mutex_lock(&real_tty->termios_mutex); | 1069 | copy_termios(real_tty, &kterm); |
1039 | ret = put_user(C_CLOCAL(real_tty) ? 1 : 0, | 1070 | ret = put_user((kterm.c_cflag & CLOCAL) ? 1 : 0, |
1040 | (int __user *)arg); | 1071 | (int __user *)arg); |
1041 | mutex_unlock(&real_tty->termios_mutex); | ||
1042 | return ret; | 1072 | return ret; |
1043 | case TIOCSSOFTCAR: | 1073 | case TIOCSSOFTCAR: |
1044 | if (get_user(arg, (unsigned int __user *) arg)) | 1074 | if (get_user(arg, (unsigned int __user *) arg)) |
diff --git a/drivers/char/tty_ldisc.c b/drivers/char/tty_ldisc.c index f78f5b0127a8..39c8f86dedd4 100644 --- a/drivers/char/tty_ldisc.c +++ b/drivers/char/tty_ldisc.c | |||
@@ -115,19 +115,22 @@ EXPORT_SYMBOL(tty_unregister_ldisc); | |||
115 | /** | 115 | /** |
116 | * tty_ldisc_try_get - try and reference an ldisc | 116 | * tty_ldisc_try_get - try and reference an ldisc |
117 | * @disc: ldisc number | 117 | * @disc: ldisc number |
118 | * @ld: tty ldisc structure to complete | ||
119 | * | 118 | * |
120 | * Attempt to open and lock a line discipline into place. Return | 119 | * Attempt to open and lock a line discipline into place. Return |
121 | * the line discipline refcounted and assigned in ld. On an error | 120 | * the line discipline refcounted or an error. |
122 | * report the error code back | ||
123 | */ | 121 | */ |
124 | 122 | ||
125 | static int tty_ldisc_try_get(int disc, struct tty_ldisc *ld) | 123 | static struct tty_ldisc *tty_ldisc_try_get(int disc) |
126 | { | 124 | { |
127 | unsigned long flags; | 125 | unsigned long flags; |
126 | struct tty_ldisc *ld; | ||
128 | struct tty_ldisc_ops *ldops; | 127 | struct tty_ldisc_ops *ldops; |
129 | int err = -EINVAL; | 128 | int err = -EINVAL; |
130 | 129 | ||
130 | ld = kmalloc(sizeof(struct tty_ldisc), GFP_KERNEL); | ||
131 | if (ld == NULL) | ||
132 | return ERR_PTR(-ENOMEM); | ||
133 | |||
131 | spin_lock_irqsave(&tty_ldisc_lock, flags); | 134 | spin_lock_irqsave(&tty_ldisc_lock, flags); |
132 | ld->ops = NULL; | 135 | ld->ops = NULL; |
133 | ldops = tty_ldiscs[disc]; | 136 | ldops = tty_ldiscs[disc]; |
@@ -140,17 +143,19 @@ static int tty_ldisc_try_get(int disc, struct tty_ldisc *ld) | |||
140 | /* lock it */ | 143 | /* lock it */ |
141 | ldops->refcount++; | 144 | ldops->refcount++; |
142 | ld->ops = ldops; | 145 | ld->ops = ldops; |
146 | ld->refcount = 0; | ||
143 | err = 0; | 147 | err = 0; |
144 | } | 148 | } |
145 | } | 149 | } |
146 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); | 150 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); |
147 | return err; | 151 | if (err) |
152 | return ERR_PTR(err); | ||
153 | return ld; | ||
148 | } | 154 | } |
149 | 155 | ||
150 | /** | 156 | /** |
151 | * tty_ldisc_get - take a reference to an ldisc | 157 | * tty_ldisc_get - take a reference to an ldisc |
152 | * @disc: ldisc number | 158 | * @disc: ldisc number |
153 | * @ld: tty line discipline structure to use | ||
154 | * | 159 | * |
155 | * Takes a reference to a line discipline. Deals with refcounts and | 160 | * Takes a reference to a line discipline. Deals with refcounts and |
156 | * module locking counts. Returns NULL if the discipline is not available. | 161 | * module locking counts. Returns NULL if the discipline is not available. |
@@ -161,52 +166,54 @@ static int tty_ldisc_try_get(int disc, struct tty_ldisc *ld) | |||
161 | * takes tty_ldisc_lock to guard against ldisc races | 166 | * takes tty_ldisc_lock to guard against ldisc races |
162 | */ | 167 | */ |
163 | 168 | ||
164 | static int tty_ldisc_get(int disc, struct tty_ldisc *ld) | 169 | static struct tty_ldisc *tty_ldisc_get(int disc) |
165 | { | 170 | { |
166 | int err; | 171 | struct tty_ldisc *ld; |
167 | 172 | ||
168 | if (disc < N_TTY || disc >= NR_LDISCS) | 173 | if (disc < N_TTY || disc >= NR_LDISCS) |
169 | return -EINVAL; | 174 | return ERR_PTR(-EINVAL); |
170 | err = tty_ldisc_try_get(disc, ld); | 175 | ld = tty_ldisc_try_get(disc); |
171 | if (err < 0) { | 176 | if (IS_ERR(ld)) { |
172 | request_module("tty-ldisc-%d", disc); | 177 | request_module("tty-ldisc-%d", disc); |
173 | err = tty_ldisc_try_get(disc, ld); | 178 | ld = tty_ldisc_try_get(disc); |
174 | } | 179 | } |
175 | return err; | 180 | return ld; |
176 | } | 181 | } |
177 | 182 | ||
178 | /** | 183 | /** |
179 | * tty_ldisc_put - drop ldisc reference | 184 | * tty_ldisc_put - drop ldisc reference |
180 | * @disc: ldisc number | 185 | * @ld: ldisc |
181 | * | 186 | * |
182 | * Drop a reference to a line discipline. Manage refcounts and | 187 | * Drop a reference to a line discipline. Manage refcounts and |
183 | * module usage counts | 188 | * module usage counts. Free the ldisc once the recount hits zero. |
184 | * | 189 | * |
185 | * Locking: | 190 | * Locking: |
186 | * takes tty_ldisc_lock to guard against ldisc races | 191 | * takes tty_ldisc_lock to guard against ldisc races |
187 | */ | 192 | */ |
188 | 193 | ||
189 | static void tty_ldisc_put(struct tty_ldisc_ops *ld) | 194 | static void tty_ldisc_put(struct tty_ldisc *ld) |
190 | { | 195 | { |
191 | unsigned long flags; | 196 | unsigned long flags; |
192 | int disc = ld->num; | 197 | int disc = ld->ops->num; |
198 | struct tty_ldisc_ops *ldo; | ||
193 | 199 | ||
194 | BUG_ON(disc < N_TTY || disc >= NR_LDISCS); | 200 | BUG_ON(disc < N_TTY || disc >= NR_LDISCS); |
195 | 201 | ||
196 | spin_lock_irqsave(&tty_ldisc_lock, flags); | 202 | spin_lock_irqsave(&tty_ldisc_lock, flags); |
197 | ld = tty_ldiscs[disc]; | 203 | ldo = tty_ldiscs[disc]; |
198 | BUG_ON(ld->refcount == 0); | 204 | BUG_ON(ldo->refcount == 0); |
199 | ld->refcount--; | 205 | ldo->refcount--; |
200 | module_put(ld->owner); | 206 | module_put(ldo->owner); |
201 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); | 207 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); |
208 | kfree(ld); | ||
202 | } | 209 | } |
203 | 210 | ||
204 | static void * tty_ldiscs_seq_start(struct seq_file *m, loff_t *pos) | 211 | static void *tty_ldiscs_seq_start(struct seq_file *m, loff_t *pos) |
205 | { | 212 | { |
206 | return (*pos < NR_LDISCS) ? pos : NULL; | 213 | return (*pos < NR_LDISCS) ? pos : NULL; |
207 | } | 214 | } |
208 | 215 | ||
209 | static void * tty_ldiscs_seq_next(struct seq_file *m, void *v, loff_t *pos) | 216 | static void *tty_ldiscs_seq_next(struct seq_file *m, void *v, loff_t *pos) |
210 | { | 217 | { |
211 | (*pos)++; | 218 | (*pos)++; |
212 | return (*pos < NR_LDISCS) ? pos : NULL; | 219 | return (*pos < NR_LDISCS) ? pos : NULL; |
@@ -219,12 +226,13 @@ static void tty_ldiscs_seq_stop(struct seq_file *m, void *v) | |||
219 | static int tty_ldiscs_seq_show(struct seq_file *m, void *v) | 226 | static int tty_ldiscs_seq_show(struct seq_file *m, void *v) |
220 | { | 227 | { |
221 | int i = *(loff_t *)v; | 228 | int i = *(loff_t *)v; |
222 | struct tty_ldisc ld; | 229 | struct tty_ldisc *ld; |
223 | 230 | ||
224 | if (tty_ldisc_get(i, &ld) < 0) | 231 | ld = tty_ldisc_try_get(i); |
232 | if (IS_ERR(ld)) | ||
225 | return 0; | 233 | return 0; |
226 | seq_printf(m, "%-10s %2d\n", ld.ops->name ? ld.ops->name : "???", i); | 234 | seq_printf(m, "%-10s %2d\n", ld->ops->name ? ld->ops->name : "???", i); |
227 | tty_ldisc_put(ld.ops); | 235 | tty_ldisc_put(ld); |
228 | return 0; | 236 | return 0; |
229 | } | 237 | } |
230 | 238 | ||
@@ -263,8 +271,7 @@ const struct file_operations tty_ldiscs_proc_fops = { | |||
263 | 271 | ||
264 | static void tty_ldisc_assign(struct tty_struct *tty, struct tty_ldisc *ld) | 272 | static void tty_ldisc_assign(struct tty_struct *tty, struct tty_ldisc *ld) |
265 | { | 273 | { |
266 | ld->refcount = 0; | 274 | tty->ldisc = ld; |
267 | tty->ldisc = *ld; | ||
268 | } | 275 | } |
269 | 276 | ||
270 | /** | 277 | /** |
@@ -286,7 +293,7 @@ static int tty_ldisc_try(struct tty_struct *tty) | |||
286 | int ret = 0; | 293 | int ret = 0; |
287 | 294 | ||
288 | spin_lock_irqsave(&tty_ldisc_lock, flags); | 295 | spin_lock_irqsave(&tty_ldisc_lock, flags); |
289 | ld = &tty->ldisc; | 296 | ld = tty->ldisc; |
290 | if (test_bit(TTY_LDISC, &tty->flags)) { | 297 | if (test_bit(TTY_LDISC, &tty->flags)) { |
291 | ld->refcount++; | 298 | ld->refcount++; |
292 | ret = 1; | 299 | ret = 1; |
@@ -315,10 +322,9 @@ struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *tty) | |||
315 | { | 322 | { |
316 | /* wait_event is a macro */ | 323 | /* wait_event is a macro */ |
317 | wait_event(tty_ldisc_wait, tty_ldisc_try(tty)); | 324 | wait_event(tty_ldisc_wait, tty_ldisc_try(tty)); |
318 | WARN_ON(tty->ldisc.refcount == 0); | 325 | WARN_ON(tty->ldisc->refcount == 0); |
319 | return &tty->ldisc; | 326 | return tty->ldisc; |
320 | } | 327 | } |
321 | |||
322 | EXPORT_SYMBOL_GPL(tty_ldisc_ref_wait); | 328 | EXPORT_SYMBOL_GPL(tty_ldisc_ref_wait); |
323 | 329 | ||
324 | /** | 330 | /** |
@@ -335,10 +341,9 @@ EXPORT_SYMBOL_GPL(tty_ldisc_ref_wait); | |||
335 | struct tty_ldisc *tty_ldisc_ref(struct tty_struct *tty) | 341 | struct tty_ldisc *tty_ldisc_ref(struct tty_struct *tty) |
336 | { | 342 | { |
337 | if (tty_ldisc_try(tty)) | 343 | if (tty_ldisc_try(tty)) |
338 | return &tty->ldisc; | 344 | return tty->ldisc; |
339 | return NULL; | 345 | return NULL; |
340 | } | 346 | } |
341 | |||
342 | EXPORT_SYMBOL_GPL(tty_ldisc_ref); | 347 | EXPORT_SYMBOL_GPL(tty_ldisc_ref); |
343 | 348 | ||
344 | /** | 349 | /** |
@@ -366,7 +371,6 @@ void tty_ldisc_deref(struct tty_ldisc *ld) | |||
366 | wake_up(&tty_ldisc_wait); | 371 | wake_up(&tty_ldisc_wait); |
367 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); | 372 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); |
368 | } | 373 | } |
369 | |||
370 | EXPORT_SYMBOL_GPL(tty_ldisc_deref); | 374 | EXPORT_SYMBOL_GPL(tty_ldisc_deref); |
371 | 375 | ||
372 | /** | 376 | /** |
@@ -389,6 +393,26 @@ void tty_ldisc_enable(struct tty_struct *tty) | |||
389 | } | 393 | } |
390 | 394 | ||
391 | /** | 395 | /** |
396 | * tty_ldisc_flush - flush line discipline queue | ||
397 | * @tty: tty | ||
398 | * | ||
399 | * Flush the line discipline queue (if any) for this tty. If there | ||
400 | * is no line discipline active this is a no-op. | ||
401 | */ | ||
402 | |||
403 | void tty_ldisc_flush(struct tty_struct *tty) | ||
404 | { | ||
405 | struct tty_ldisc *ld = tty_ldisc_ref(tty); | ||
406 | if (ld) { | ||
407 | if (ld->ops->flush_buffer) | ||
408 | ld->ops->flush_buffer(tty); | ||
409 | tty_ldisc_deref(ld); | ||
410 | } | ||
411 | tty_buffer_flush(tty); | ||
412 | } | ||
413 | EXPORT_SYMBOL_GPL(tty_ldisc_flush); | ||
414 | |||
415 | /** | ||
392 | * tty_set_termios_ldisc - set ldisc field | 416 | * tty_set_termios_ldisc - set ldisc field |
393 | * @tty: tty structure | 417 | * @tty: tty structure |
394 | * @num: line discipline number | 418 | * @num: line discipline number |
@@ -407,6 +431,39 @@ static void tty_set_termios_ldisc(struct tty_struct *tty, int num) | |||
407 | mutex_unlock(&tty->termios_mutex); | 431 | mutex_unlock(&tty->termios_mutex); |
408 | } | 432 | } |
409 | 433 | ||
434 | /** | ||
435 | * tty_ldisc_open - open a line discipline | ||
436 | * @tty: tty we are opening the ldisc on | ||
437 | * @ld: discipline to open | ||
438 | * | ||
439 | * A helper opening method. Also a convenient debugging and check | ||
440 | * point. | ||
441 | */ | ||
442 | |||
443 | static int tty_ldisc_open(struct tty_struct *tty, struct tty_ldisc *ld) | ||
444 | { | ||
445 | WARN_ON(test_and_set_bit(TTY_LDISC_OPEN, &tty->flags)); | ||
446 | if (ld->ops->open) | ||
447 | return ld->ops->open(tty); | ||
448 | return 0; | ||
449 | } | ||
450 | |||
451 | /** | ||
452 | * tty_ldisc_close - close a line discipline | ||
453 | * @tty: tty we are opening the ldisc on | ||
454 | * @ld: discipline to close | ||
455 | * | ||
456 | * A helper close method. Also a convenient debugging and check | ||
457 | * point. | ||
458 | */ | ||
459 | |||
460 | static void tty_ldisc_close(struct tty_struct *tty, struct tty_ldisc *ld) | ||
461 | { | ||
462 | WARN_ON(!test_bit(TTY_LDISC_OPEN, &tty->flags)); | ||
463 | clear_bit(TTY_LDISC_OPEN, &tty->flags); | ||
464 | if (ld->ops->close) | ||
465 | ld->ops->close(tty); | ||
466 | } | ||
410 | 467 | ||
411 | /** | 468 | /** |
412 | * tty_ldisc_restore - helper for tty ldisc change | 469 | * tty_ldisc_restore - helper for tty ldisc change |
@@ -420,66 +477,136 @@ static void tty_set_termios_ldisc(struct tty_struct *tty, int num) | |||
420 | static void tty_ldisc_restore(struct tty_struct *tty, struct tty_ldisc *old) | 477 | static void tty_ldisc_restore(struct tty_struct *tty, struct tty_ldisc *old) |
421 | { | 478 | { |
422 | char buf[64]; | 479 | char buf[64]; |
423 | struct tty_ldisc new_ldisc; | 480 | struct tty_ldisc *new_ldisc; |
481 | int r; | ||
424 | 482 | ||
425 | /* There is an outstanding reference here so this is safe */ | 483 | /* There is an outstanding reference here so this is safe */ |
426 | tty_ldisc_get(old->ops->num, old); | 484 | old = tty_ldisc_get(old->ops->num); |
485 | WARN_ON(IS_ERR(old)); | ||
427 | tty_ldisc_assign(tty, old); | 486 | tty_ldisc_assign(tty, old); |
428 | tty_set_termios_ldisc(tty, old->ops->num); | 487 | tty_set_termios_ldisc(tty, old->ops->num); |
429 | if (old->ops->open && (old->ops->open(tty) < 0)) { | 488 | if (tty_ldisc_open(tty, old) < 0) { |
430 | tty_ldisc_put(old->ops); | 489 | tty_ldisc_put(old); |
431 | /* This driver is always present */ | 490 | /* This driver is always present */ |
432 | if (tty_ldisc_get(N_TTY, &new_ldisc) < 0) | 491 | new_ldisc = tty_ldisc_get(N_TTY); |
492 | if (IS_ERR(new_ldisc)) | ||
433 | panic("n_tty: get"); | 493 | panic("n_tty: get"); |
434 | tty_ldisc_assign(tty, &new_ldisc); | 494 | tty_ldisc_assign(tty, new_ldisc); |
435 | tty_set_termios_ldisc(tty, N_TTY); | 495 | tty_set_termios_ldisc(tty, N_TTY); |
436 | if (new_ldisc.ops->open) { | 496 | r = tty_ldisc_open(tty, new_ldisc); |
437 | int r = new_ldisc.ops->open(tty); | 497 | if (r < 0) |
438 | if (r < 0) | 498 | panic("Couldn't open N_TTY ldisc for " |
439 | panic("Couldn't open N_TTY ldisc for " | 499 | "%s --- error %d.", |
440 | "%s --- error %d.", | 500 | tty_name(tty, buf), r); |
441 | tty_name(tty, buf), r); | ||
442 | } | ||
443 | } | 501 | } |
444 | } | 502 | } |
445 | 503 | ||
446 | /** | 504 | /** |
505 | * tty_ldisc_halt - shut down the line discipline | ||
506 | * @tty: tty device | ||
507 | * | ||
508 | * Shut down the line discipline and work queue for this tty device. | ||
509 | * The TTY_LDISC flag being cleared ensures no further references can | ||
510 | * be obtained while the delayed work queue halt ensures that no more | ||
511 | * data is fed to the ldisc. | ||
512 | * | ||
513 | * In order to wait for any existing references to complete see | ||
514 | * tty_ldisc_wait_idle. | ||
515 | */ | ||
516 | |||
517 | static int tty_ldisc_halt(struct tty_struct *tty) | ||
518 | { | ||
519 | clear_bit(TTY_LDISC, &tty->flags); | ||
520 | return cancel_delayed_work(&tty->buf.work); | ||
521 | } | ||
522 | |||
523 | /** | ||
524 | * tty_ldisc_wait_idle - wait for the ldisc to become idle | ||
525 | * @tty: tty to wait for | ||
526 | * | ||
527 | * Wait for the line discipline to become idle. The discipline must | ||
528 | * have been halted for this to guarantee it remains idle. | ||
529 | * | ||
530 | * tty_ldisc_lock protects the ref counts currently. | ||
531 | */ | ||
532 | |||
533 | static int tty_ldisc_wait_idle(struct tty_struct *tty) | ||
534 | { | ||
535 | unsigned long flags; | ||
536 | spin_lock_irqsave(&tty_ldisc_lock, flags); | ||
537 | while (tty->ldisc->refcount) { | ||
538 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); | ||
539 | if (wait_event_timeout(tty_ldisc_wait, | ||
540 | tty->ldisc->refcount == 0, 5 * HZ) == 0) | ||
541 | return -EBUSY; | ||
542 | spin_lock_irqsave(&tty_ldisc_lock, flags); | ||
543 | } | ||
544 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); | ||
545 | return 0; | ||
546 | } | ||
547 | |||
548 | /** | ||
447 | * tty_set_ldisc - set line discipline | 549 | * tty_set_ldisc - set line discipline |
448 | * @tty: the terminal to set | 550 | * @tty: the terminal to set |
449 | * @ldisc: the line discipline | 551 | * @ldisc: the line discipline |
450 | * | 552 | * |
451 | * Set the discipline of a tty line. Must be called from a process | 553 | * Set the discipline of a tty line. Must be called from a process |
452 | * context. | 554 | * context. The ldisc change logic has to protect itself against any |
555 | * overlapping ldisc change (including on the other end of pty pairs), | ||
556 | * the close of one side of a tty/pty pair, and eventually hangup. | ||
453 | * | 557 | * |
454 | * Locking: takes tty_ldisc_lock. | 558 | * Locking: takes tty_ldisc_lock, termios_mutex |
455 | * called functions take termios_mutex | ||
456 | */ | 559 | */ |
457 | 560 | ||
458 | int tty_set_ldisc(struct tty_struct *tty, int ldisc) | 561 | int tty_set_ldisc(struct tty_struct *tty, int ldisc) |
459 | { | 562 | { |
460 | int retval; | 563 | int retval; |
461 | struct tty_ldisc o_ldisc, new_ldisc; | 564 | struct tty_ldisc *o_ldisc, *new_ldisc; |
462 | int work; | 565 | int work, o_work = 0; |
463 | unsigned long flags; | ||
464 | struct tty_struct *o_tty; | 566 | struct tty_struct *o_tty; |
465 | 567 | ||
466 | restart: | 568 | new_ldisc = tty_ldisc_get(ldisc); |
467 | /* This is a bit ugly for now but means we can break the 'ldisc | 569 | if (IS_ERR(new_ldisc)) |
468 | is part of the tty struct' assumption later */ | 570 | return PTR_ERR(new_ldisc); |
469 | retval = tty_ldisc_get(ldisc, &new_ldisc); | 571 | |
470 | if (retval) | 572 | /* |
471 | return retval; | 573 | * We need to look at the tty locking here for pty/tty pairs |
574 | * when both sides try to change in parallel. | ||
575 | */ | ||
576 | |||
577 | o_tty = tty->link; /* o_tty is the pty side or NULL */ | ||
578 | |||
579 | |||
580 | /* | ||
581 | * Check the no-op case | ||
582 | */ | ||
583 | |||
584 | if (tty->ldisc->ops->num == ldisc) { | ||
585 | tty_ldisc_put(new_ldisc); | ||
586 | return 0; | ||
587 | } | ||
472 | 588 | ||
473 | /* | 589 | /* |
474 | * Problem: What do we do if this blocks ? | 590 | * Problem: What do we do if this blocks ? |
591 | * We could deadlock here | ||
475 | */ | 592 | */ |
476 | 593 | ||
477 | tty_wait_until_sent(tty, 0); | 594 | tty_wait_until_sent(tty, 0); |
478 | 595 | ||
479 | if (tty->ldisc.ops->num == ldisc) { | 596 | mutex_lock(&tty->ldisc_mutex); |
480 | tty_ldisc_put(new_ldisc.ops); | 597 | |
481 | return 0; | 598 | /* |
599 | * We could be midstream of another ldisc change which has | ||
600 | * dropped the lock during processing. If so we need to wait. | ||
601 | */ | ||
602 | |||
603 | while (test_bit(TTY_LDISC_CHANGING, &tty->flags)) { | ||
604 | mutex_unlock(&tty->ldisc_mutex); | ||
605 | wait_event(tty_ldisc_wait, | ||
606 | test_bit(TTY_LDISC_CHANGING, &tty->flags) == 0); | ||
607 | mutex_lock(&tty->ldisc_mutex); | ||
482 | } | 608 | } |
609 | set_bit(TTY_LDISC_CHANGING, &tty->flags); | ||
483 | 610 | ||
484 | /* | 611 | /* |
485 | * No more input please, we are switching. The new ldisc | 612 | * No more input please, we are switching. The new ldisc |
@@ -489,8 +616,6 @@ restart: | |||
489 | tty->receive_room = 0; | 616 | tty->receive_room = 0; |
490 | 617 | ||
491 | o_ldisc = tty->ldisc; | 618 | o_ldisc = tty->ldisc; |
492 | o_tty = tty->link; | ||
493 | |||
494 | /* | 619 | /* |
495 | * Make sure we don't change while someone holds a | 620 | * Make sure we don't change while someone holds a |
496 | * reference to the line discipline. The TTY_LDISC bit | 621 | * reference to the line discipline. The TTY_LDISC bit |
@@ -501,108 +626,181 @@ restart: | |||
501 | * with a userspace app continually trying to use the tty in | 626 | * with a userspace app continually trying to use the tty in |
502 | * parallel to the change and re-referencing the tty. | 627 | * parallel to the change and re-referencing the tty. |
503 | */ | 628 | */ |
504 | clear_bit(TTY_LDISC, &tty->flags); | ||
505 | if (o_tty) | ||
506 | clear_bit(TTY_LDISC, &o_tty->flags); | ||
507 | 629 | ||
508 | spin_lock_irqsave(&tty_ldisc_lock, flags); | 630 | work = tty_ldisc_halt(tty); |
509 | if (tty->ldisc.refcount || (o_tty && o_tty->ldisc.refcount)) { | ||
510 | if (tty->ldisc.refcount) { | ||
511 | /* Free the new ldisc we grabbed. Must drop the lock | ||
512 | first. */ | ||
513 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); | ||
514 | tty_ldisc_put(o_ldisc.ops); | ||
515 | /* | ||
516 | * There are several reasons we may be busy, including | ||
517 | * random momentary I/O traffic. We must therefore | ||
518 | * retry. We could distinguish between blocking ops | ||
519 | * and retries if we made tty_ldisc_wait() smarter. | ||
520 | * That is up for discussion. | ||
521 | */ | ||
522 | if (wait_event_interruptible(tty_ldisc_wait, tty->ldisc.refcount == 0) < 0) | ||
523 | return -ERESTARTSYS; | ||
524 | goto restart; | ||
525 | } | ||
526 | if (o_tty && o_tty->ldisc.refcount) { | ||
527 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); | ||
528 | tty_ldisc_put(o_tty->ldisc.ops); | ||
529 | if (wait_event_interruptible(tty_ldisc_wait, o_tty->ldisc.refcount == 0) < 0) | ||
530 | return -ERESTARTSYS; | ||
531 | goto restart; | ||
532 | } | ||
533 | } | ||
534 | /* | ||
535 | * If the TTY_LDISC bit is set, then we are racing against | ||
536 | * another ldisc change | ||
537 | */ | ||
538 | if (test_bit(TTY_LDISC_CHANGING, &tty->flags)) { | ||
539 | struct tty_ldisc *ld; | ||
540 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); | ||
541 | tty_ldisc_put(new_ldisc.ops); | ||
542 | ld = tty_ldisc_ref_wait(tty); | ||
543 | tty_ldisc_deref(ld); | ||
544 | goto restart; | ||
545 | } | ||
546 | /* | ||
547 | * This flag is used to avoid two parallel ldisc changes. Once | ||
548 | * open and close are fine grained locked this may work better | ||
549 | * as a mutex shared with the open/close/hup paths | ||
550 | */ | ||
551 | set_bit(TTY_LDISC_CHANGING, &tty->flags); | ||
552 | if (o_tty) | 631 | if (o_tty) |
553 | set_bit(TTY_LDISC_CHANGING, &o_tty->flags); | 632 | o_work = tty_ldisc_halt(o_tty); |
554 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); | ||
555 | |||
556 | /* | ||
557 | * From this point on we know nobody has an ldisc | ||
558 | * usage reference, nor can they obtain one until | ||
559 | * we say so later on. | ||
560 | */ | ||
561 | 633 | ||
562 | work = cancel_delayed_work(&tty->buf.work); | ||
563 | /* | 634 | /* |
564 | * Wait for ->hangup_work and ->buf.work handlers to terminate | 635 | * Wait for ->hangup_work and ->buf.work handlers to terminate. |
565 | * MUST NOT hold locks here. | 636 | * We must drop the mutex here in case a hangup is also in process. |
566 | */ | 637 | */ |
638 | |||
639 | mutex_unlock(&tty->ldisc_mutex); | ||
640 | |||
567 | flush_scheduled_work(); | 641 | flush_scheduled_work(); |
642 | |||
643 | /* Let any existing reference holders finish */ | ||
644 | retval = tty_ldisc_wait_idle(tty); | ||
645 | if (retval < 0) { | ||
646 | clear_bit(TTY_LDISC_CHANGING, &tty->flags); | ||
647 | tty_ldisc_put(new_ldisc); | ||
648 | return retval; | ||
649 | } | ||
650 | |||
651 | mutex_lock(&tty->ldisc_mutex); | ||
652 | if (test_bit(TTY_HUPPED, &tty->flags)) { | ||
653 | /* We were raced by the hangup method. It will have stomped | ||
654 | the ldisc data and closed the ldisc down */ | ||
655 | clear_bit(TTY_LDISC_CHANGING, &tty->flags); | ||
656 | mutex_unlock(&tty->ldisc_mutex); | ||
657 | tty_ldisc_put(new_ldisc); | ||
658 | return -EIO; | ||
659 | } | ||
660 | |||
568 | /* Shutdown the current discipline. */ | 661 | /* Shutdown the current discipline. */ |
569 | if (o_ldisc.ops->close) | 662 | tty_ldisc_close(tty, o_ldisc); |
570 | (o_ldisc.ops->close)(tty); | ||
571 | 663 | ||
572 | /* Now set up the new line discipline. */ | 664 | /* Now set up the new line discipline. */ |
573 | tty_ldisc_assign(tty, &new_ldisc); | 665 | tty_ldisc_assign(tty, new_ldisc); |
574 | tty_set_termios_ldisc(tty, ldisc); | 666 | tty_set_termios_ldisc(tty, ldisc); |
575 | if (new_ldisc.ops->open) | 667 | |
576 | retval = (new_ldisc.ops->open)(tty); | 668 | retval = tty_ldisc_open(tty, new_ldisc); |
577 | if (retval < 0) { | 669 | if (retval < 0) { |
578 | tty_ldisc_put(new_ldisc.ops); | 670 | /* Back to the old one or N_TTY if we can't */ |
579 | tty_ldisc_restore(tty, &o_ldisc); | 671 | tty_ldisc_put(new_ldisc); |
672 | tty_ldisc_restore(tty, o_ldisc); | ||
580 | } | 673 | } |
674 | |||
581 | /* At this point we hold a reference to the new ldisc and a | 675 | /* At this point we hold a reference to the new ldisc and a |
582 | a reference to the old ldisc. If we ended up flipping back | 676 | a reference to the old ldisc. If we ended up flipping back |
583 | to the existing ldisc we have two references to it */ | 677 | to the existing ldisc we have two references to it */ |
584 | 678 | ||
585 | if (tty->ldisc.ops->num != o_ldisc.ops->num && tty->ops->set_ldisc) | 679 | if (tty->ldisc->ops->num != o_ldisc->ops->num && tty->ops->set_ldisc) |
586 | tty->ops->set_ldisc(tty); | 680 | tty->ops->set_ldisc(tty); |
587 | 681 | ||
588 | tty_ldisc_put(o_ldisc.ops); | 682 | tty_ldisc_put(o_ldisc); |
589 | 683 | ||
590 | /* | 684 | /* |
591 | * Allow ldisc referencing to occur as soon as the driver | 685 | * Allow ldisc referencing to occur again |
592 | * ldisc callback completes. | ||
593 | */ | 686 | */ |
594 | 687 | ||
595 | tty_ldisc_enable(tty); | 688 | tty_ldisc_enable(tty); |
596 | if (o_tty) | 689 | if (o_tty) |
597 | tty_ldisc_enable(o_tty); | 690 | tty_ldisc_enable(o_tty); |
598 | 691 | ||
599 | /* Restart it in case no characters kick it off. Safe if | 692 | /* Restart the work queue in case no characters kick it off. Safe if |
600 | already running */ | 693 | already running */ |
601 | if (work) | 694 | if (work) |
602 | schedule_delayed_work(&tty->buf.work, 1); | 695 | schedule_delayed_work(&tty->buf.work, 1); |
696 | if (o_work) | ||
697 | schedule_delayed_work(&o_tty->buf.work, 1); | ||
698 | mutex_unlock(&tty->ldisc_mutex); | ||
603 | return retval; | 699 | return retval; |
604 | } | 700 | } |
605 | 701 | ||
702 | /** | ||
703 | * tty_reset_termios - reset terminal state | ||
704 | * @tty: tty to reset | ||
705 | * | ||
706 | * Restore a terminal to the driver default state. | ||
707 | */ | ||
708 | |||
709 | static void tty_reset_termios(struct tty_struct *tty) | ||
710 | { | ||
711 | mutex_lock(&tty->termios_mutex); | ||
712 | *tty->termios = tty->driver->init_termios; | ||
713 | tty->termios->c_ispeed = tty_termios_input_baud_rate(tty->termios); | ||
714 | tty->termios->c_ospeed = tty_termios_baud_rate(tty->termios); | ||
715 | mutex_unlock(&tty->termios_mutex); | ||
716 | } | ||
717 | |||
718 | |||
719 | /** | ||
720 | * tty_ldisc_reinit - reinitialise the tty ldisc | ||
721 | * @tty: tty to reinit | ||
722 | * | ||
723 | * Switch the tty back to N_TTY line discipline and leave the | ||
724 | * ldisc state closed | ||
725 | */ | ||
726 | |||
727 | static void tty_ldisc_reinit(struct tty_struct *tty) | ||
728 | { | ||
729 | struct tty_ldisc *ld; | ||
730 | |||
731 | tty_ldisc_close(tty, tty->ldisc); | ||
732 | tty_ldisc_put(tty->ldisc); | ||
733 | tty->ldisc = NULL; | ||
734 | /* | ||
735 | * Switch the line discipline back | ||
736 | */ | ||
737 | ld = tty_ldisc_get(N_TTY); | ||
738 | BUG_ON(IS_ERR(ld)); | ||
739 | tty_ldisc_assign(tty, ld); | ||
740 | tty_set_termios_ldisc(tty, N_TTY); | ||
741 | } | ||
742 | |||
743 | /** | ||
744 | * tty_ldisc_hangup - hangup ldisc reset | ||
745 | * @tty: tty being hung up | ||
746 | * | ||
747 | * Some tty devices reset their termios when they receive a hangup | ||
748 | * event. In that situation we must also switch back to N_TTY properly | ||
749 | * before we reset the termios data. | ||
750 | * | ||
751 | * Locking: We can take the ldisc mutex as the rest of the code is | ||
752 | * careful to allow for this. | ||
753 | * | ||
754 | * In the pty pair case this occurs in the close() path of the | ||
755 | * tty itself so we must be careful about locking rules. | ||
756 | */ | ||
757 | |||
758 | void tty_ldisc_hangup(struct tty_struct *tty) | ||
759 | { | ||
760 | struct tty_ldisc *ld; | ||
761 | |||
762 | /* | ||
763 | * FIXME! What are the locking issues here? This may me overdoing | ||
764 | * things... This question is especially important now that we've | ||
765 | * removed the irqlock. | ||
766 | */ | ||
767 | ld = tty_ldisc_ref(tty); | ||
768 | if (ld != NULL) { | ||
769 | /* We may have no line discipline at this point */ | ||
770 | if (ld->ops->flush_buffer) | ||
771 | ld->ops->flush_buffer(tty); | ||
772 | tty_driver_flush_buffer(tty); | ||
773 | if ((test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) && | ||
774 | ld->ops->write_wakeup) | ||
775 | ld->ops->write_wakeup(tty); | ||
776 | if (ld->ops->hangup) | ||
777 | ld->ops->hangup(tty); | ||
778 | tty_ldisc_deref(ld); | ||
779 | } | ||
780 | /* | ||
781 | * FIXME: Once we trust the LDISC code better we can wait here for | ||
782 | * ldisc completion and fix the driver call race | ||
783 | */ | ||
784 | wake_up_interruptible_poll(&tty->write_wait, POLLOUT); | ||
785 | wake_up_interruptible_poll(&tty->read_wait, POLLIN); | ||
786 | /* | ||
787 | * Shutdown the current line discipline, and reset it to | ||
788 | * N_TTY. | ||
789 | */ | ||
790 | if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) { | ||
791 | /* Avoid racing set_ldisc */ | ||
792 | mutex_lock(&tty->ldisc_mutex); | ||
793 | /* Switch back to N_TTY */ | ||
794 | tty_ldisc_reinit(tty); | ||
795 | /* At this point we have a closed ldisc and we want to | ||
796 | reopen it. We could defer this to the next open but | ||
797 | it means auditing a lot of other paths so this is a FIXME */ | ||
798 | WARN_ON(tty_ldisc_open(tty, tty->ldisc)); | ||
799 | tty_ldisc_enable(tty); | ||
800 | mutex_unlock(&tty->ldisc_mutex); | ||
801 | tty_reset_termios(tty); | ||
802 | } | ||
803 | } | ||
606 | 804 | ||
607 | /** | 805 | /** |
608 | * tty_ldisc_setup - open line discipline | 806 | * tty_ldisc_setup - open line discipline |
@@ -610,24 +808,23 @@ restart: | |||
610 | * @o_tty: pair tty for pty/tty pairs | 808 | * @o_tty: pair tty for pty/tty pairs |
611 | * | 809 | * |
612 | * Called during the initial open of a tty/pty pair in order to set up the | 810 | * Called during the initial open of a tty/pty pair in order to set up the |
613 | * line discplines and bind them to the tty. | 811 | * line disciplines and bind them to the tty. This has no locking issues |
812 | * as the device isn't yet active. | ||
614 | */ | 813 | */ |
615 | 814 | ||
616 | int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty) | 815 | int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty) |
617 | { | 816 | { |
618 | struct tty_ldisc *ld = &tty->ldisc; | 817 | struct tty_ldisc *ld = tty->ldisc; |
619 | int retval; | 818 | int retval; |
620 | 819 | ||
621 | if (ld->ops->open) { | 820 | retval = tty_ldisc_open(tty, ld); |
622 | retval = (ld->ops->open)(tty); | 821 | if (retval) |
623 | if (retval) | 822 | return retval; |
624 | return retval; | 823 | |
625 | } | 824 | if (o_tty) { |
626 | if (o_tty && o_tty->ldisc.ops->open) { | 825 | retval = tty_ldisc_open(o_tty, o_tty->ldisc); |
627 | retval = (o_tty->ldisc.ops->open)(o_tty); | ||
628 | if (retval) { | 826 | if (retval) { |
629 | if (ld->ops->close) | 827 | tty_ldisc_close(tty, ld); |
630 | (ld->ops->close)(tty); | ||
631 | return retval; | 828 | return retval; |
632 | } | 829 | } |
633 | tty_ldisc_enable(o_tty); | 830 | tty_ldisc_enable(o_tty); |
@@ -635,32 +832,25 @@ int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty) | |||
635 | tty_ldisc_enable(tty); | 832 | tty_ldisc_enable(tty); |
636 | return 0; | 833 | return 0; |
637 | } | 834 | } |
638 | |||
639 | /** | 835 | /** |
640 | * tty_ldisc_release - release line discipline | 836 | * tty_ldisc_release - release line discipline |
641 | * @tty: tty being shut down | 837 | * @tty: tty being shut down |
642 | * @o_tty: pair tty for pty/tty pairs | 838 | * @o_tty: pair tty for pty/tty pairs |
643 | * | 839 | * |
644 | * Called during the final close of a tty/pty pair in order to shut down the | 840 | * Called during the final close of a tty/pty pair in order to shut down |
645 | * line discpline layer. | 841 | * the line discpline layer. On exit the ldisc assigned is N_TTY and the |
842 | * ldisc has not been opened. | ||
646 | */ | 843 | */ |
647 | 844 | ||
648 | void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty) | 845 | void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty) |
649 | { | 846 | { |
650 | unsigned long flags; | ||
651 | struct tty_ldisc ld; | ||
652 | /* | 847 | /* |
653 | * Prevent flush_to_ldisc() from rescheduling the work for later. Then | 848 | * Prevent flush_to_ldisc() from rescheduling the work for later. Then |
654 | * kill any delayed work. As this is the final close it does not | 849 | * kill any delayed work. As this is the final close it does not |
655 | * race with the set_ldisc code path. | 850 | * race with the set_ldisc code path. |
656 | */ | 851 | */ |
657 | clear_bit(TTY_LDISC, &tty->flags); | ||
658 | cancel_delayed_work(&tty->buf.work); | ||
659 | |||
660 | /* | ||
661 | * Wait for ->hangup_work and ->buf.work handlers to terminate | ||
662 | */ | ||
663 | 852 | ||
853 | tty_ldisc_halt(tty); | ||
664 | flush_scheduled_work(); | 854 | flush_scheduled_work(); |
665 | 855 | ||
666 | /* | 856 | /* |
@@ -668,38 +858,19 @@ void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty) | |||
668 | * side waiters as the file is closing so user count on the file | 858 | * side waiters as the file is closing so user count on the file |
669 | * side is zero. | 859 | * side is zero. |
670 | */ | 860 | */ |
671 | spin_lock_irqsave(&tty_ldisc_lock, flags); | 861 | |
672 | while (tty->ldisc.refcount) { | 862 | tty_ldisc_wait_idle(tty); |
673 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); | 863 | |
674 | wait_event(tty_ldisc_wait, tty->ldisc.refcount == 0); | ||
675 | spin_lock_irqsave(&tty_ldisc_lock, flags); | ||
676 | } | ||
677 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); | ||
678 | /* | 864 | /* |
679 | * Shutdown the current line discipline, and reset it to N_TTY. | 865 | * Shutdown the current line discipline, and reset it to N_TTY. |
680 | * | 866 | * |
681 | * FIXME: this MUST get fixed for the new reflocking | 867 | * FIXME: this MUST get fixed for the new reflocking |
682 | */ | 868 | */ |
683 | if (tty->ldisc.ops->close) | ||
684 | (tty->ldisc.ops->close)(tty); | ||
685 | tty_ldisc_put(tty->ldisc.ops); | ||
686 | 869 | ||
687 | /* | 870 | tty_ldisc_reinit(tty); |
688 | * Switch the line discipline back | 871 | /* This will need doing differently if we need to lock */ |
689 | */ | 872 | if (o_tty) |
690 | WARN_ON(tty_ldisc_get(N_TTY, &ld)); | 873 | tty_ldisc_release(o_tty, NULL); |
691 | tty_ldisc_assign(tty, &ld); | ||
692 | tty_set_termios_ldisc(tty, N_TTY); | ||
693 | if (o_tty) { | ||
694 | /* FIXME: could o_tty be in setldisc here ? */ | ||
695 | clear_bit(TTY_LDISC, &o_tty->flags); | ||
696 | if (o_tty->ldisc.ops->close) | ||
697 | (o_tty->ldisc.ops->close)(o_tty); | ||
698 | tty_ldisc_put(o_tty->ldisc.ops); | ||
699 | WARN_ON(tty_ldisc_get(N_TTY, &ld)); | ||
700 | tty_ldisc_assign(o_tty, &ld); | ||
701 | tty_set_termios_ldisc(o_tty, N_TTY); | ||
702 | } | ||
703 | } | 874 | } |
704 | 875 | ||
705 | /** | 876 | /** |
@@ -712,10 +883,10 @@ void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty) | |||
712 | 883 | ||
713 | void tty_ldisc_init(struct tty_struct *tty) | 884 | void tty_ldisc_init(struct tty_struct *tty) |
714 | { | 885 | { |
715 | struct tty_ldisc ld; | 886 | struct tty_ldisc *ld = tty_ldisc_get(N_TTY); |
716 | if (tty_ldisc_get(N_TTY, &ld) < 0) | 887 | if (IS_ERR(ld)) |
717 | panic("n_tty: init_tty"); | 888 | panic("n_tty: init_tty"); |
718 | tty_ldisc_assign(tty, &ld); | 889 | tty_ldisc_assign(tty, ld); |
719 | } | 890 | } |
720 | 891 | ||
721 | void tty_ldisc_begin(void) | 892 | void tty_ldisc_begin(void) |
diff --git a/drivers/char/tty_port.c b/drivers/char/tty_port.c index 9b8004c72686..62dadfc95e34 100644 --- a/drivers/char/tty_port.c +++ b/drivers/char/tty_port.c | |||
@@ -137,7 +137,7 @@ int tty_port_carrier_raised(struct tty_port *port) | |||
137 | EXPORT_SYMBOL(tty_port_carrier_raised); | 137 | EXPORT_SYMBOL(tty_port_carrier_raised); |
138 | 138 | ||
139 | /** | 139 | /** |
140 | * tty_port_raise_dtr_rts - Riase DTR/RTS | 140 | * tty_port_raise_dtr_rts - Raise DTR/RTS |
141 | * @port: tty port | 141 | * @port: tty port |
142 | * | 142 | * |
143 | * Wrapper for the DTR/RTS raise logic. For the moment this is used | 143 | * Wrapper for the DTR/RTS raise logic. For the moment this is used |
@@ -147,12 +147,28 @@ EXPORT_SYMBOL(tty_port_carrier_raised); | |||
147 | 147 | ||
148 | void tty_port_raise_dtr_rts(struct tty_port *port) | 148 | void tty_port_raise_dtr_rts(struct tty_port *port) |
149 | { | 149 | { |
150 | if (port->ops->raise_dtr_rts) | 150 | if (port->ops->dtr_rts) |
151 | port->ops->raise_dtr_rts(port); | 151 | port->ops->dtr_rts(port, 1); |
152 | } | 152 | } |
153 | EXPORT_SYMBOL(tty_port_raise_dtr_rts); | 153 | EXPORT_SYMBOL(tty_port_raise_dtr_rts); |
154 | 154 | ||
155 | /** | 155 | /** |
156 | * tty_port_lower_dtr_rts - Lower DTR/RTS | ||
157 | * @port: tty port | ||
158 | * | ||
159 | * Wrapper for the DTR/RTS raise logic. For the moment this is used | ||
160 | * to hide some internal details. This will eventually become entirely | ||
161 | * internal to the tty port. | ||
162 | */ | ||
163 | |||
164 | void tty_port_lower_dtr_rts(struct tty_port *port) | ||
165 | { | ||
166 | if (port->ops->dtr_rts) | ||
167 | port->ops->dtr_rts(port, 0); | ||
168 | } | ||
169 | EXPORT_SYMBOL(tty_port_lower_dtr_rts); | ||
170 | |||
171 | /** | ||
156 | * tty_port_block_til_ready - Waiting logic for tty open | 172 | * tty_port_block_til_ready - Waiting logic for tty open |
157 | * @port: the tty port being opened | 173 | * @port: the tty port being opened |
158 | * @tty: the tty device being bound | 174 | * @tty: the tty device being bound |
@@ -167,7 +183,7 @@ EXPORT_SYMBOL(tty_port_raise_dtr_rts); | |||
167 | * - port flags and counts | 183 | * - port flags and counts |
168 | * | 184 | * |
169 | * The passed tty_port must implement the carrier_raised method if it can | 185 | * The passed tty_port must implement the carrier_raised method if it can |
170 | * do carrier detect and the raise_dtr_rts method if it supports software | 186 | * do carrier detect and the dtr_rts method if it supports software |
171 | * management of these lines. Note that the dtr/rts raise is done each | 187 | * management of these lines. Note that the dtr/rts raise is done each |
172 | * iteration as a hangup may have previously dropped them while we wait. | 188 | * iteration as a hangup may have previously dropped them while we wait. |
173 | */ | 189 | */ |
@@ -182,7 +198,8 @@ int tty_port_block_til_ready(struct tty_port *port, | |||
182 | 198 | ||
183 | /* block if port is in the process of being closed */ | 199 | /* block if port is in the process of being closed */ |
184 | if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) { | 200 | if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) { |
185 | interruptible_sleep_on(&port->close_wait); | 201 | wait_event_interruptible(port->close_wait, |
202 | !(port->flags & ASYNC_CLOSING)); | ||
186 | if (port->flags & ASYNC_HUP_NOTIFY) | 203 | if (port->flags & ASYNC_HUP_NOTIFY) |
187 | return -EAGAIN; | 204 | return -EAGAIN; |
188 | else | 205 | else |
@@ -205,7 +222,6 @@ int tty_port_block_til_ready(struct tty_port *port, | |||
205 | before the next open may complete */ | 222 | before the next open may complete */ |
206 | 223 | ||
207 | retval = 0; | 224 | retval = 0; |
208 | add_wait_queue(&port->open_wait, &wait); | ||
209 | 225 | ||
210 | /* The port lock protects the port counts */ | 226 | /* The port lock protects the port counts */ |
211 | spin_lock_irqsave(&port->lock, flags); | 227 | spin_lock_irqsave(&port->lock, flags); |
@@ -219,7 +235,7 @@ int tty_port_block_til_ready(struct tty_port *port, | |||
219 | if (tty->termios->c_cflag & CBAUD) | 235 | if (tty->termios->c_cflag & CBAUD) |
220 | tty_port_raise_dtr_rts(port); | 236 | tty_port_raise_dtr_rts(port); |
221 | 237 | ||
222 | set_current_state(TASK_INTERRUPTIBLE); | 238 | prepare_to_wait(&port->open_wait, &wait, TASK_INTERRUPTIBLE); |
223 | /* Check for a hangup or uninitialised port. Return accordingly */ | 239 | /* Check for a hangup or uninitialised port. Return accordingly */ |
224 | if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) { | 240 | if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) { |
225 | if (port->flags & ASYNC_HUP_NOTIFY) | 241 | if (port->flags & ASYNC_HUP_NOTIFY) |
@@ -240,8 +256,7 @@ int tty_port_block_til_ready(struct tty_port *port, | |||
240 | } | 256 | } |
241 | schedule(); | 257 | schedule(); |
242 | } | 258 | } |
243 | set_current_state(TASK_RUNNING); | 259 | finish_wait(&port->open_wait, &wait); |
244 | remove_wait_queue(&port->open_wait, &wait); | ||
245 | 260 | ||
246 | /* Update counts. A parallel hangup will have set count to zero and | 261 | /* Update counts. A parallel hangup will have set count to zero and |
247 | we must not mess that up further */ | 262 | we must not mess that up further */ |
@@ -292,6 +307,17 @@ int tty_port_close_start(struct tty_port *port, struct tty_struct *tty, struct f | |||
292 | if (port->flags & ASYNC_INITIALIZED && | 307 | if (port->flags & ASYNC_INITIALIZED && |
293 | port->closing_wait != ASYNC_CLOSING_WAIT_NONE) | 308 | port->closing_wait != ASYNC_CLOSING_WAIT_NONE) |
294 | tty_wait_until_sent(tty, port->closing_wait); | 309 | tty_wait_until_sent(tty, port->closing_wait); |
310 | if (port->drain_delay) { | ||
311 | unsigned int bps = tty_get_baud_rate(tty); | ||
312 | long timeout; | ||
313 | |||
314 | if (bps > 1200) | ||
315 | timeout = max_t(long, (HZ * 10 * port->drain_delay) / bps, | ||
316 | HZ / 10); | ||
317 | else | ||
318 | timeout = 2 * HZ; | ||
319 | schedule_timeout_interruptible(timeout); | ||
320 | } | ||
295 | return 1; | 321 | return 1; |
296 | } | 322 | } |
297 | EXPORT_SYMBOL(tty_port_close_start); | 323 | EXPORT_SYMBOL(tty_port_close_start); |
@@ -302,6 +328,9 @@ void tty_port_close_end(struct tty_port *port, struct tty_struct *tty) | |||
302 | 328 | ||
303 | tty_ldisc_flush(tty); | 329 | tty_ldisc_flush(tty); |
304 | 330 | ||
331 | if (tty->termios->c_cflag & HUPCL) | ||
332 | tty_port_lower_dtr_rts(port); | ||
333 | |||
305 | spin_lock_irqsave(&port->lock, flags); | 334 | spin_lock_irqsave(&port->lock, flags); |
306 | tty->closing = 0; | 335 | tty->closing = 0; |
307 | 336 | ||
diff --git a/drivers/parport/parport_pc.c b/drivers/parport/parport_pc.c index 4e63cc9e2778..151bf5bc8afe 100644 --- a/drivers/parport/parport_pc.c +++ b/drivers/parport/parport_pc.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* Low-level parallel-port routines for 8255-based PC-style hardware. | 1 | /* Low-level parallel-port routines for 8255-based PC-style hardware. |
2 | * | 2 | * |
3 | * Authors: Phil Blundell <philb@gnu.org> | 3 | * Authors: Phil Blundell <philb@gnu.org> |
4 | * Tim Waugh <tim@cyberelk.demon.co.uk> | 4 | * Tim Waugh <tim@cyberelk.demon.co.uk> |
5 | * Jose Renau <renau@acm.org> | 5 | * Jose Renau <renau@acm.org> |
@@ -11,7 +11,7 @@ | |||
11 | * Cleaned up include files - Russell King <linux@arm.uk.linux.org> | 11 | * Cleaned up include files - Russell King <linux@arm.uk.linux.org> |
12 | * DMA support - Bert De Jonghe <bert@sophis.be> | 12 | * DMA support - Bert De Jonghe <bert@sophis.be> |
13 | * Many ECP bugs fixed. Fred Barnes & Jamie Lokier, 1999 | 13 | * Many ECP bugs fixed. Fred Barnes & Jamie Lokier, 1999 |
14 | * More PCI support now conditional on CONFIG_PCI, 03/2001, Paul G. | 14 | * More PCI support now conditional on CONFIG_PCI, 03/2001, Paul G. |
15 | * Various hacks, Fred Barnes, 04/2001 | 15 | * Various hacks, Fred Barnes, 04/2001 |
16 | * Updated probing logic - Adam Belay <ambx1@neo.rr.com> | 16 | * Updated probing logic - Adam Belay <ambx1@neo.rr.com> |
17 | */ | 17 | */ |
@@ -56,10 +56,10 @@ | |||
56 | #include <linux/pnp.h> | 56 | #include <linux/pnp.h> |
57 | #include <linux/platform_device.h> | 57 | #include <linux/platform_device.h> |
58 | #include <linux/sysctl.h> | 58 | #include <linux/sysctl.h> |
59 | #include <linux/io.h> | ||
60 | #include <linux/uaccess.h> | ||
59 | 61 | ||
60 | #include <asm/io.h> | ||
61 | #include <asm/dma.h> | 62 | #include <asm/dma.h> |
62 | #include <asm/uaccess.h> | ||
63 | 63 | ||
64 | #include <linux/parport.h> | 64 | #include <linux/parport.h> |
65 | #include <linux/parport_pc.h> | 65 | #include <linux/parport_pc.h> |
@@ -82,7 +82,7 @@ | |||
82 | #define ECR_TST 06 | 82 | #define ECR_TST 06 |
83 | #define ECR_CNF 07 | 83 | #define ECR_CNF 07 |
84 | #define ECR_MODE_MASK 0xe0 | 84 | #define ECR_MODE_MASK 0xe0 |
85 | #define ECR_WRITE(p,v) frob_econtrol((p),0xff,(v)) | 85 | #define ECR_WRITE(p, v) frob_econtrol((p), 0xff, (v)) |
86 | 86 | ||
87 | #undef DEBUG | 87 | #undef DEBUG |
88 | 88 | ||
@@ -109,27 +109,27 @@ static int pci_registered_parport; | |||
109 | static int pnp_registered_parport; | 109 | static int pnp_registered_parport; |
110 | 110 | ||
111 | /* frob_control, but for ECR */ | 111 | /* frob_control, but for ECR */ |
112 | static void frob_econtrol (struct parport *pb, unsigned char m, | 112 | static void frob_econtrol(struct parport *pb, unsigned char m, |
113 | unsigned char v) | 113 | unsigned char v) |
114 | { | 114 | { |
115 | unsigned char ectr = 0; | 115 | unsigned char ectr = 0; |
116 | 116 | ||
117 | if (m != 0xff) | 117 | if (m != 0xff) |
118 | ectr = inb (ECONTROL (pb)); | 118 | ectr = inb(ECONTROL(pb)); |
119 | 119 | ||
120 | DPRINTK (KERN_DEBUG "frob_econtrol(%02x,%02x): %02x -> %02x\n", | 120 | DPRINTK(KERN_DEBUG "frob_econtrol(%02x,%02x): %02x -> %02x\n", |
121 | m, v, ectr, (ectr & ~m) ^ v); | 121 | m, v, ectr, (ectr & ~m) ^ v); |
122 | 122 | ||
123 | outb ((ectr & ~m) ^ v, ECONTROL (pb)); | 123 | outb((ectr & ~m) ^ v, ECONTROL(pb)); |
124 | } | 124 | } |
125 | 125 | ||
126 | static __inline__ void frob_set_mode (struct parport *p, int mode) | 126 | static inline void frob_set_mode(struct parport *p, int mode) |
127 | { | 127 | { |
128 | frob_econtrol (p, ECR_MODE_MASK, mode << 5); | 128 | frob_econtrol(p, ECR_MODE_MASK, mode << 5); |
129 | } | 129 | } |
130 | 130 | ||
131 | #ifdef CONFIG_PARPORT_PC_FIFO | 131 | #ifdef CONFIG_PARPORT_PC_FIFO |
132 | /* Safely change the mode bits in the ECR | 132 | /* Safely change the mode bits in the ECR |
133 | Returns: | 133 | Returns: |
134 | 0 : Success | 134 | 0 : Success |
135 | -EBUSY: Could not drain FIFO in some finite amount of time, | 135 | -EBUSY: Could not drain FIFO in some finite amount of time, |
@@ -141,17 +141,18 @@ static int change_mode(struct parport *p, int m) | |||
141 | unsigned char oecr; | 141 | unsigned char oecr; |
142 | int mode; | 142 | int mode; |
143 | 143 | ||
144 | DPRINTK(KERN_INFO "parport change_mode ECP-ISA to mode 0x%02x\n",m); | 144 | DPRINTK(KERN_INFO "parport change_mode ECP-ISA to mode 0x%02x\n", m); |
145 | 145 | ||
146 | if (!priv->ecr) { | 146 | if (!priv->ecr) { |
147 | printk (KERN_DEBUG "change_mode: but there's no ECR!\n"); | 147 | printk(KERN_DEBUG "change_mode: but there's no ECR!\n"); |
148 | return 0; | 148 | return 0; |
149 | } | 149 | } |
150 | 150 | ||
151 | /* Bits <7:5> contain the mode. */ | 151 | /* Bits <7:5> contain the mode. */ |
152 | oecr = inb (ECONTROL (p)); | 152 | oecr = inb(ECONTROL(p)); |
153 | mode = (oecr >> 5) & 0x7; | 153 | mode = (oecr >> 5) & 0x7; |
154 | if (mode == m) return 0; | 154 | if (mode == m) |
155 | return 0; | ||
155 | 156 | ||
156 | if (mode >= 2 && !(priv->ctr & 0x20)) { | 157 | if (mode >= 2 && !(priv->ctr & 0x20)) { |
157 | /* This mode resets the FIFO, so we may | 158 | /* This mode resets the FIFO, so we may |
@@ -163,19 +164,21 @@ static int change_mode(struct parport *p, int m) | |||
163 | case ECR_ECP: /* ECP Parallel Port mode */ | 164 | case ECR_ECP: /* ECP Parallel Port mode */ |
164 | /* Busy wait for 200us */ | 165 | /* Busy wait for 200us */ |
165 | for (counter = 0; counter < 40; counter++) { | 166 | for (counter = 0; counter < 40; counter++) { |
166 | if (inb (ECONTROL (p)) & 0x01) | 167 | if (inb(ECONTROL(p)) & 0x01) |
168 | break; | ||
169 | if (signal_pending(current)) | ||
167 | break; | 170 | break; |
168 | if (signal_pending (current)) break; | 171 | udelay(5); |
169 | udelay (5); | ||
170 | } | 172 | } |
171 | 173 | ||
172 | /* Poll slowly. */ | 174 | /* Poll slowly. */ |
173 | while (!(inb (ECONTROL (p)) & 0x01)) { | 175 | while (!(inb(ECONTROL(p)) & 0x01)) { |
174 | if (time_after_eq (jiffies, expire)) | 176 | if (time_after_eq(jiffies, expire)) |
175 | /* The FIFO is stuck. */ | 177 | /* The FIFO is stuck. */ |
176 | return -EBUSY; | 178 | return -EBUSY; |
177 | schedule_timeout_interruptible(msecs_to_jiffies(10)); | 179 | schedule_timeout_interruptible( |
178 | if (signal_pending (current)) | 180 | msecs_to_jiffies(10)); |
181 | if (signal_pending(current)) | ||
179 | break; | 182 | break; |
180 | } | 183 | } |
181 | } | 184 | } |
@@ -185,20 +188,20 @@ static int change_mode(struct parport *p, int m) | |||
185 | /* We have to go through mode 001 */ | 188 | /* We have to go through mode 001 */ |
186 | oecr &= ~(7 << 5); | 189 | oecr &= ~(7 << 5); |
187 | oecr |= ECR_PS2 << 5; | 190 | oecr |= ECR_PS2 << 5; |
188 | ECR_WRITE (p, oecr); | 191 | ECR_WRITE(p, oecr); |
189 | } | 192 | } |
190 | 193 | ||
191 | /* Set the mode. */ | 194 | /* Set the mode. */ |
192 | oecr &= ~(7 << 5); | 195 | oecr &= ~(7 << 5); |
193 | oecr |= m << 5; | 196 | oecr |= m << 5; |
194 | ECR_WRITE (p, oecr); | 197 | ECR_WRITE(p, oecr); |
195 | return 0; | 198 | return 0; |
196 | } | 199 | } |
197 | 200 | ||
198 | #ifdef CONFIG_PARPORT_1284 | 201 | #ifdef CONFIG_PARPORT_1284 |
199 | /* Find FIFO lossage; FIFO is reset */ | 202 | /* Find FIFO lossage; FIFO is reset */ |
200 | #if 0 | 203 | #if 0 |
201 | static int get_fifo_residue (struct parport *p) | 204 | static int get_fifo_residue(struct parport *p) |
202 | { | 205 | { |
203 | int residue; | 206 | int residue; |
204 | int cnfga; | 207 | int cnfga; |
@@ -206,26 +209,26 @@ static int get_fifo_residue (struct parport *p) | |||
206 | 209 | ||
207 | /* Adjust for the contents of the FIFO. */ | 210 | /* Adjust for the contents of the FIFO. */ |
208 | for (residue = priv->fifo_depth; ; residue--) { | 211 | for (residue = priv->fifo_depth; ; residue--) { |
209 | if (inb (ECONTROL (p)) & 0x2) | 212 | if (inb(ECONTROL(p)) & 0x2) |
210 | /* Full up. */ | 213 | /* Full up. */ |
211 | break; | 214 | break; |
212 | 215 | ||
213 | outb (0, FIFO (p)); | 216 | outb(0, FIFO(p)); |
214 | } | 217 | } |
215 | 218 | ||
216 | printk (KERN_DEBUG "%s: %d PWords were left in FIFO\n", p->name, | 219 | printk(KERN_DEBUG "%s: %d PWords were left in FIFO\n", p->name, |
217 | residue); | 220 | residue); |
218 | 221 | ||
219 | /* Reset the FIFO. */ | 222 | /* Reset the FIFO. */ |
220 | frob_set_mode (p, ECR_PS2); | 223 | frob_set_mode(p, ECR_PS2); |
221 | 224 | ||
222 | /* Now change to config mode and clean up. FIXME */ | 225 | /* Now change to config mode and clean up. FIXME */ |
223 | frob_set_mode (p, ECR_CNF); | 226 | frob_set_mode(p, ECR_CNF); |
224 | cnfga = inb (CONFIGA (p)); | 227 | cnfga = inb(CONFIGA(p)); |
225 | printk (KERN_DEBUG "%s: cnfgA contains 0x%02x\n", p->name, cnfga); | 228 | printk(KERN_DEBUG "%s: cnfgA contains 0x%02x\n", p->name, cnfga); |
226 | 229 | ||
227 | if (!(cnfga & (1<<2))) { | 230 | if (!(cnfga & (1<<2))) { |
228 | printk (KERN_DEBUG "%s: Accounting for extra byte\n", p->name); | 231 | printk(KERN_DEBUG "%s: Accounting for extra byte\n", p->name); |
229 | residue++; | 232 | residue++; |
230 | } | 233 | } |
231 | 234 | ||
@@ -233,9 +236,11 @@ static int get_fifo_residue (struct parport *p) | |||
233 | * PWord != 1 byte. */ | 236 | * PWord != 1 byte. */ |
234 | 237 | ||
235 | /* Back to PS2 mode. */ | 238 | /* Back to PS2 mode. */ |
236 | frob_set_mode (p, ECR_PS2); | 239 | frob_set_mode(p, ECR_PS2); |
237 | 240 | ||
238 | DPRINTK (KERN_DEBUG "*** get_fifo_residue: done residue collecting (ecr = 0x%2.2x)\n", inb (ECONTROL (p))); | 241 | DPRINTK(KERN_DEBUG |
242 | "*** get_fifo_residue: done residue collecting (ecr = 0x%2.2x)\n", | ||
243 | inb(ECONTROL(p))); | ||
239 | return residue; | 244 | return residue; |
240 | } | 245 | } |
241 | #endif /* 0 */ | 246 | #endif /* 0 */ |
@@ -257,8 +262,8 @@ static int clear_epp_timeout(struct parport *pb) | |||
257 | /* To clear timeout some chips require double read */ | 262 | /* To clear timeout some chips require double read */ |
258 | parport_pc_read_status(pb); | 263 | parport_pc_read_status(pb); |
259 | r = parport_pc_read_status(pb); | 264 | r = parport_pc_read_status(pb); |
260 | outb (r | 0x01, STATUS (pb)); /* Some reset by writing 1 */ | 265 | outb(r | 0x01, STATUS(pb)); /* Some reset by writing 1 */ |
261 | outb (r & 0xfe, STATUS (pb)); /* Others by writing 0 */ | 266 | outb(r & 0xfe, STATUS(pb)); /* Others by writing 0 */ |
262 | r = parport_pc_read_status(pb); | 267 | r = parport_pc_read_status(pb); |
263 | 268 | ||
264 | return !(r & 0x01); | 269 | return !(r & 0x01); |
@@ -272,7 +277,8 @@ static int clear_epp_timeout(struct parport *pb) | |||
272 | * of these are in parport_pc.h. | 277 | * of these are in parport_pc.h. |
273 | */ | 278 | */ |
274 | 279 | ||
275 | static void parport_pc_init_state(struct pardevice *dev, struct parport_state *s) | 280 | static void parport_pc_init_state(struct pardevice *dev, |
281 | struct parport_state *s) | ||
276 | { | 282 | { |
277 | s->u.pc.ctr = 0xc; | 283 | s->u.pc.ctr = 0xc; |
278 | if (dev->irq_func && | 284 | if (dev->irq_func && |
@@ -289,22 +295,23 @@ static void parport_pc_save_state(struct parport *p, struct parport_state *s) | |||
289 | const struct parport_pc_private *priv = p->physport->private_data; | 295 | const struct parport_pc_private *priv = p->physport->private_data; |
290 | s->u.pc.ctr = priv->ctr; | 296 | s->u.pc.ctr = priv->ctr; |
291 | if (priv->ecr) | 297 | if (priv->ecr) |
292 | s->u.pc.ecr = inb (ECONTROL (p)); | 298 | s->u.pc.ecr = inb(ECONTROL(p)); |
293 | } | 299 | } |
294 | 300 | ||
295 | static void parport_pc_restore_state(struct parport *p, struct parport_state *s) | 301 | static void parport_pc_restore_state(struct parport *p, |
302 | struct parport_state *s) | ||
296 | { | 303 | { |
297 | struct parport_pc_private *priv = p->physport->private_data; | 304 | struct parport_pc_private *priv = p->physport->private_data; |
298 | register unsigned char c = s->u.pc.ctr & priv->ctr_writable; | 305 | register unsigned char c = s->u.pc.ctr & priv->ctr_writable; |
299 | outb (c, CONTROL (p)); | 306 | outb(c, CONTROL(p)); |
300 | priv->ctr = c; | 307 | priv->ctr = c; |
301 | if (priv->ecr) | 308 | if (priv->ecr) |
302 | ECR_WRITE (p, s->u.pc.ecr); | 309 | ECR_WRITE(p, s->u.pc.ecr); |
303 | } | 310 | } |
304 | 311 | ||
305 | #ifdef CONFIG_PARPORT_1284 | 312 | #ifdef CONFIG_PARPORT_1284 |
306 | static size_t parport_pc_epp_read_data (struct parport *port, void *buf, | 313 | static size_t parport_pc_epp_read_data(struct parport *port, void *buf, |
307 | size_t length, int flags) | 314 | size_t length, int flags) |
308 | { | 315 | { |
309 | size_t got = 0; | 316 | size_t got = 0; |
310 | 317 | ||
@@ -316,54 +323,52 @@ static size_t parport_pc_epp_read_data (struct parport *port, void *buf, | |||
316 | * nFault is 0 if there is at least 1 byte in the Warp's FIFO | 323 | * nFault is 0 if there is at least 1 byte in the Warp's FIFO |
317 | * pError is 1 if there are 16 bytes in the Warp's FIFO | 324 | * pError is 1 if there are 16 bytes in the Warp's FIFO |
318 | */ | 325 | */ |
319 | status = inb (STATUS (port)); | 326 | status = inb(STATUS(port)); |
320 | 327 | ||
321 | while (!(status & 0x08) && (got < length)) { | 328 | while (!(status & 0x08) && got < length) { |
322 | if ((left >= 16) && (status & 0x20) && !(status & 0x08)) { | 329 | if (left >= 16 && (status & 0x20) && !(status & 0x08)) { |
323 | /* can grab 16 bytes from warp fifo */ | 330 | /* can grab 16 bytes from warp fifo */ |
324 | if (!((long)buf & 0x03)) { | 331 | if (!((long)buf & 0x03)) |
325 | insl (EPPDATA (port), buf, 4); | 332 | insl(EPPDATA(port), buf, 4); |
326 | } else { | 333 | else |
327 | insb (EPPDATA (port), buf, 16); | 334 | insb(EPPDATA(port), buf, 16); |
328 | } | ||
329 | buf += 16; | 335 | buf += 16; |
330 | got += 16; | 336 | got += 16; |
331 | left -= 16; | 337 | left -= 16; |
332 | } else { | 338 | } else { |
333 | /* grab single byte from the warp fifo */ | 339 | /* grab single byte from the warp fifo */ |
334 | *((char *)buf) = inb (EPPDATA (port)); | 340 | *((char *)buf) = inb(EPPDATA(port)); |
335 | buf++; | 341 | buf++; |
336 | got++; | 342 | got++; |
337 | left--; | 343 | left--; |
338 | } | 344 | } |
339 | status = inb (STATUS (port)); | 345 | status = inb(STATUS(port)); |
340 | if (status & 0x01) { | 346 | if (status & 0x01) { |
341 | /* EPP timeout should never occur... */ | 347 | /* EPP timeout should never occur... */ |
342 | printk (KERN_DEBUG "%s: EPP timeout occurred while talking to " | 348 | printk(KERN_DEBUG |
343 | "w91284pic (should not have done)\n", port->name); | 349 | "%s: EPP timeout occurred while talking to w91284pic (should not have done)\n", port->name); |
344 | clear_epp_timeout (port); | 350 | clear_epp_timeout(port); |
345 | } | 351 | } |
346 | } | 352 | } |
347 | return got; | 353 | return got; |
348 | } | 354 | } |
349 | if ((flags & PARPORT_EPP_FAST) && (length > 1)) { | 355 | if ((flags & PARPORT_EPP_FAST) && (length > 1)) { |
350 | if (!(((long)buf | length) & 0x03)) { | 356 | if (!(((long)buf | length) & 0x03)) |
351 | insl (EPPDATA (port), buf, (length >> 2)); | 357 | insl(EPPDATA(port), buf, (length >> 2)); |
352 | } else { | 358 | else |
353 | insb (EPPDATA (port), buf, length); | 359 | insb(EPPDATA(port), buf, length); |
354 | } | 360 | if (inb(STATUS(port)) & 0x01) { |
355 | if (inb (STATUS (port)) & 0x01) { | 361 | clear_epp_timeout(port); |
356 | clear_epp_timeout (port); | ||
357 | return -EIO; | 362 | return -EIO; |
358 | } | 363 | } |
359 | return length; | 364 | return length; |
360 | } | 365 | } |
361 | for (; got < length; got++) { | 366 | for (; got < length; got++) { |
362 | *((char*)buf) = inb (EPPDATA(port)); | 367 | *((char *)buf) = inb(EPPDATA(port)); |
363 | buf++; | 368 | buf++; |
364 | if (inb (STATUS (port)) & 0x01) { | 369 | if (inb(STATUS(port)) & 0x01) { |
365 | /* EPP timeout */ | 370 | /* EPP timeout */ |
366 | clear_epp_timeout (port); | 371 | clear_epp_timeout(port); |
367 | break; | 372 | break; |
368 | } | 373 | } |
369 | } | 374 | } |
@@ -371,28 +376,27 @@ static size_t parport_pc_epp_read_data (struct parport *port, void *buf, | |||
371 | return got; | 376 | return got; |
372 | } | 377 | } |
373 | 378 | ||
374 | static size_t parport_pc_epp_write_data (struct parport *port, const void *buf, | 379 | static size_t parport_pc_epp_write_data(struct parport *port, const void *buf, |
375 | size_t length, int flags) | 380 | size_t length, int flags) |
376 | { | 381 | { |
377 | size_t written = 0; | 382 | size_t written = 0; |
378 | 383 | ||
379 | if ((flags & PARPORT_EPP_FAST) && (length > 1)) { | 384 | if ((flags & PARPORT_EPP_FAST) && (length > 1)) { |
380 | if (!(((long)buf | length) & 0x03)) { | 385 | if (!(((long)buf | length) & 0x03)) |
381 | outsl (EPPDATA (port), buf, (length >> 2)); | 386 | outsl(EPPDATA(port), buf, (length >> 2)); |
382 | } else { | 387 | else |
383 | outsb (EPPDATA (port), buf, length); | 388 | outsb(EPPDATA(port), buf, length); |
384 | } | 389 | if (inb(STATUS(port)) & 0x01) { |
385 | if (inb (STATUS (port)) & 0x01) { | 390 | clear_epp_timeout(port); |
386 | clear_epp_timeout (port); | ||
387 | return -EIO; | 391 | return -EIO; |
388 | } | 392 | } |
389 | return length; | 393 | return length; |
390 | } | 394 | } |
391 | for (; written < length; written++) { | 395 | for (; written < length; written++) { |
392 | outb (*((char*)buf), EPPDATA(port)); | 396 | outb(*((char *)buf), EPPDATA(port)); |
393 | buf++; | 397 | buf++; |
394 | if (inb (STATUS(port)) & 0x01) { | 398 | if (inb(STATUS(port)) & 0x01) { |
395 | clear_epp_timeout (port); | 399 | clear_epp_timeout(port); |
396 | break; | 400 | break; |
397 | } | 401 | } |
398 | } | 402 | } |
@@ -400,24 +404,24 @@ static size_t parport_pc_epp_write_data (struct parport *port, const void *buf, | |||
400 | return written; | 404 | return written; |
401 | } | 405 | } |
402 | 406 | ||
403 | static size_t parport_pc_epp_read_addr (struct parport *port, void *buf, | 407 | static size_t parport_pc_epp_read_addr(struct parport *port, void *buf, |
404 | size_t length, int flags) | 408 | size_t length, int flags) |
405 | { | 409 | { |
406 | size_t got = 0; | 410 | size_t got = 0; |
407 | 411 | ||
408 | if ((flags & PARPORT_EPP_FAST) && (length > 1)) { | 412 | if ((flags & PARPORT_EPP_FAST) && (length > 1)) { |
409 | insb (EPPADDR (port), buf, length); | 413 | insb(EPPADDR(port), buf, length); |
410 | if (inb (STATUS (port)) & 0x01) { | 414 | if (inb(STATUS(port)) & 0x01) { |
411 | clear_epp_timeout (port); | 415 | clear_epp_timeout(port); |
412 | return -EIO; | 416 | return -EIO; |
413 | } | 417 | } |
414 | return length; | 418 | return length; |
415 | } | 419 | } |
416 | for (; got < length; got++) { | 420 | for (; got < length; got++) { |
417 | *((char*)buf) = inb (EPPADDR (port)); | 421 | *((char *)buf) = inb(EPPADDR(port)); |
418 | buf++; | 422 | buf++; |
419 | if (inb (STATUS (port)) & 0x01) { | 423 | if (inb(STATUS(port)) & 0x01) { |
420 | clear_epp_timeout (port); | 424 | clear_epp_timeout(port); |
421 | break; | 425 | break; |
422 | } | 426 | } |
423 | } | 427 | } |
@@ -425,25 +429,25 @@ static size_t parport_pc_epp_read_addr (struct parport *port, void *buf, | |||
425 | return got; | 429 | return got; |
426 | } | 430 | } |
427 | 431 | ||
428 | static size_t parport_pc_epp_write_addr (struct parport *port, | 432 | static size_t parport_pc_epp_write_addr(struct parport *port, |
429 | const void *buf, size_t length, | 433 | const void *buf, size_t length, |
430 | int flags) | 434 | int flags) |
431 | { | 435 | { |
432 | size_t written = 0; | 436 | size_t written = 0; |
433 | 437 | ||
434 | if ((flags & PARPORT_EPP_FAST) && (length > 1)) { | 438 | if ((flags & PARPORT_EPP_FAST) && (length > 1)) { |
435 | outsb (EPPADDR (port), buf, length); | 439 | outsb(EPPADDR(port), buf, length); |
436 | if (inb (STATUS (port)) & 0x01) { | 440 | if (inb(STATUS(port)) & 0x01) { |
437 | clear_epp_timeout (port); | 441 | clear_epp_timeout(port); |
438 | return -EIO; | 442 | return -EIO; |
439 | } | 443 | } |
440 | return length; | 444 | return length; |
441 | } | 445 | } |
442 | for (; written < length; written++) { | 446 | for (; written < length; written++) { |
443 | outb (*((char*)buf), EPPADDR (port)); | 447 | outb(*((char *)buf), EPPADDR(port)); |
444 | buf++; | 448 | buf++; |
445 | if (inb (STATUS (port)) & 0x01) { | 449 | if (inb(STATUS(port)) & 0x01) { |
446 | clear_epp_timeout (port); | 450 | clear_epp_timeout(port); |
447 | break; | 451 | break; |
448 | } | 452 | } |
449 | } | 453 | } |
@@ -451,74 +455,74 @@ static size_t parport_pc_epp_write_addr (struct parport *port, | |||
451 | return written; | 455 | return written; |
452 | } | 456 | } |
453 | 457 | ||
454 | static size_t parport_pc_ecpepp_read_data (struct parport *port, void *buf, | 458 | static size_t parport_pc_ecpepp_read_data(struct parport *port, void *buf, |
455 | size_t length, int flags) | 459 | size_t length, int flags) |
456 | { | 460 | { |
457 | size_t got; | 461 | size_t got; |
458 | 462 | ||
459 | frob_set_mode (port, ECR_EPP); | 463 | frob_set_mode(port, ECR_EPP); |
460 | parport_pc_data_reverse (port); | 464 | parport_pc_data_reverse(port); |
461 | parport_pc_write_control (port, 0x4); | 465 | parport_pc_write_control(port, 0x4); |
462 | got = parport_pc_epp_read_data (port, buf, length, flags); | 466 | got = parport_pc_epp_read_data(port, buf, length, flags); |
463 | frob_set_mode (port, ECR_PS2); | 467 | frob_set_mode(port, ECR_PS2); |
464 | 468 | ||
465 | return got; | 469 | return got; |
466 | } | 470 | } |
467 | 471 | ||
468 | static size_t parport_pc_ecpepp_write_data (struct parport *port, | 472 | static size_t parport_pc_ecpepp_write_data(struct parport *port, |
469 | const void *buf, size_t length, | 473 | const void *buf, size_t length, |
470 | int flags) | 474 | int flags) |
471 | { | 475 | { |
472 | size_t written; | 476 | size_t written; |
473 | 477 | ||
474 | frob_set_mode (port, ECR_EPP); | 478 | frob_set_mode(port, ECR_EPP); |
475 | parport_pc_write_control (port, 0x4); | 479 | parport_pc_write_control(port, 0x4); |
476 | parport_pc_data_forward (port); | 480 | parport_pc_data_forward(port); |
477 | written = parport_pc_epp_write_data (port, buf, length, flags); | 481 | written = parport_pc_epp_write_data(port, buf, length, flags); |
478 | frob_set_mode (port, ECR_PS2); | 482 | frob_set_mode(port, ECR_PS2); |
479 | 483 | ||
480 | return written; | 484 | return written; |
481 | } | 485 | } |
482 | 486 | ||
483 | static size_t parport_pc_ecpepp_read_addr (struct parport *port, void *buf, | 487 | static size_t parport_pc_ecpepp_read_addr(struct parport *port, void *buf, |
484 | size_t length, int flags) | 488 | size_t length, int flags) |
485 | { | 489 | { |
486 | size_t got; | 490 | size_t got; |
487 | 491 | ||
488 | frob_set_mode (port, ECR_EPP); | 492 | frob_set_mode(port, ECR_EPP); |
489 | parport_pc_data_reverse (port); | 493 | parport_pc_data_reverse(port); |
490 | parport_pc_write_control (port, 0x4); | 494 | parport_pc_write_control(port, 0x4); |
491 | got = parport_pc_epp_read_addr (port, buf, length, flags); | 495 | got = parport_pc_epp_read_addr(port, buf, length, flags); |
492 | frob_set_mode (port, ECR_PS2); | 496 | frob_set_mode(port, ECR_PS2); |
493 | 497 | ||
494 | return got; | 498 | return got; |
495 | } | 499 | } |
496 | 500 | ||
497 | static size_t parport_pc_ecpepp_write_addr (struct parport *port, | 501 | static size_t parport_pc_ecpepp_write_addr(struct parport *port, |
498 | const void *buf, size_t length, | 502 | const void *buf, size_t length, |
499 | int flags) | 503 | int flags) |
500 | { | 504 | { |
501 | size_t written; | 505 | size_t written; |
502 | 506 | ||
503 | frob_set_mode (port, ECR_EPP); | 507 | frob_set_mode(port, ECR_EPP); |
504 | parport_pc_write_control (port, 0x4); | 508 | parport_pc_write_control(port, 0x4); |
505 | parport_pc_data_forward (port); | 509 | parport_pc_data_forward(port); |
506 | written = parport_pc_epp_write_addr (port, buf, length, flags); | 510 | written = parport_pc_epp_write_addr(port, buf, length, flags); |
507 | frob_set_mode (port, ECR_PS2); | 511 | frob_set_mode(port, ECR_PS2); |
508 | 512 | ||
509 | return written; | 513 | return written; |
510 | } | 514 | } |
511 | #endif /* IEEE 1284 support */ | 515 | #endif /* IEEE 1284 support */ |
512 | 516 | ||
513 | #ifdef CONFIG_PARPORT_PC_FIFO | 517 | #ifdef CONFIG_PARPORT_PC_FIFO |
514 | static size_t parport_pc_fifo_write_block_pio (struct parport *port, | 518 | static size_t parport_pc_fifo_write_block_pio(struct parport *port, |
515 | const void *buf, size_t length) | 519 | const void *buf, size_t length) |
516 | { | 520 | { |
517 | int ret = 0; | 521 | int ret = 0; |
518 | const unsigned char *bufp = buf; | 522 | const unsigned char *bufp = buf; |
519 | size_t left = length; | 523 | size_t left = length; |
520 | unsigned long expire = jiffies + port->physport->cad->timeout; | 524 | unsigned long expire = jiffies + port->physport->cad->timeout; |
521 | const int fifo = FIFO (port); | 525 | const int fifo = FIFO(port); |
522 | int poll_for = 8; /* 80 usecs */ | 526 | int poll_for = 8; /* 80 usecs */ |
523 | const struct parport_pc_private *priv = port->physport->private_data; | 527 | const struct parport_pc_private *priv = port->physport->private_data; |
524 | const int fifo_depth = priv->fifo_depth; | 528 | const int fifo_depth = priv->fifo_depth; |
@@ -526,25 +530,25 @@ static size_t parport_pc_fifo_write_block_pio (struct parport *port, | |||
526 | port = port->physport; | 530 | port = port->physport; |
527 | 531 | ||
528 | /* We don't want to be interrupted every character. */ | 532 | /* We don't want to be interrupted every character. */ |
529 | parport_pc_disable_irq (port); | 533 | parport_pc_disable_irq(port); |
530 | /* set nErrIntrEn and serviceIntr */ | 534 | /* set nErrIntrEn and serviceIntr */ |
531 | frob_econtrol (port, (1<<4) | (1<<2), (1<<4) | (1<<2)); | 535 | frob_econtrol(port, (1<<4) | (1<<2), (1<<4) | (1<<2)); |
532 | 536 | ||
533 | /* Forward mode. */ | 537 | /* Forward mode. */ |
534 | parport_pc_data_forward (port); /* Must be in PS2 mode */ | 538 | parport_pc_data_forward(port); /* Must be in PS2 mode */ |
535 | 539 | ||
536 | while (left) { | 540 | while (left) { |
537 | unsigned char byte; | 541 | unsigned char byte; |
538 | unsigned char ecrval = inb (ECONTROL (port)); | 542 | unsigned char ecrval = inb(ECONTROL(port)); |
539 | int i = 0; | 543 | int i = 0; |
540 | 544 | ||
541 | if (need_resched() && time_before (jiffies, expire)) | 545 | if (need_resched() && time_before(jiffies, expire)) |
542 | /* Can't yield the port. */ | 546 | /* Can't yield the port. */ |
543 | schedule (); | 547 | schedule(); |
544 | 548 | ||
545 | /* Anyone else waiting for the port? */ | 549 | /* Anyone else waiting for the port? */ |
546 | if (port->waithead) { | 550 | if (port->waithead) { |
547 | printk (KERN_DEBUG "Somebody wants the port\n"); | 551 | printk(KERN_DEBUG "Somebody wants the port\n"); |
548 | break; | 552 | break; |
549 | } | 553 | } |
550 | 554 | ||
@@ -552,21 +556,22 @@ static size_t parport_pc_fifo_write_block_pio (struct parport *port, | |||
552 | /* FIFO is full. Wait for interrupt. */ | 556 | /* FIFO is full. Wait for interrupt. */ |
553 | 557 | ||
554 | /* Clear serviceIntr */ | 558 | /* Clear serviceIntr */ |
555 | ECR_WRITE (port, ecrval & ~(1<<2)); | 559 | ECR_WRITE(port, ecrval & ~(1<<2)); |
556 | false_alarm: | 560 | false_alarm: |
557 | ret = parport_wait_event (port, HZ); | 561 | ret = parport_wait_event(port, HZ); |
558 | if (ret < 0) break; | 562 | if (ret < 0) |
563 | break; | ||
559 | ret = 0; | 564 | ret = 0; |
560 | if (!time_before (jiffies, expire)) { | 565 | if (!time_before(jiffies, expire)) { |
561 | /* Timed out. */ | 566 | /* Timed out. */ |
562 | printk (KERN_DEBUG "FIFO write timed out\n"); | 567 | printk(KERN_DEBUG "FIFO write timed out\n"); |
563 | break; | 568 | break; |
564 | } | 569 | } |
565 | ecrval = inb (ECONTROL (port)); | 570 | ecrval = inb(ECONTROL(port)); |
566 | if (!(ecrval & (1<<2))) { | 571 | if (!(ecrval & (1<<2))) { |
567 | if (need_resched() && | 572 | if (need_resched() && |
568 | time_before (jiffies, expire)) | 573 | time_before(jiffies, expire)) |
569 | schedule (); | 574 | schedule(); |
570 | 575 | ||
571 | goto false_alarm; | 576 | goto false_alarm; |
572 | } | 577 | } |
@@ -577,38 +582,38 @@ static size_t parport_pc_fifo_write_block_pio (struct parport *port, | |||
577 | /* Can't fail now. */ | 582 | /* Can't fail now. */ |
578 | expire = jiffies + port->cad->timeout; | 583 | expire = jiffies + port->cad->timeout; |
579 | 584 | ||
580 | poll: | 585 | poll: |
581 | if (signal_pending (current)) | 586 | if (signal_pending(current)) |
582 | break; | 587 | break; |
583 | 588 | ||
584 | if (ecrval & 0x01) { | 589 | if (ecrval & 0x01) { |
585 | /* FIFO is empty. Blast it full. */ | 590 | /* FIFO is empty. Blast it full. */ |
586 | const int n = left < fifo_depth ? left : fifo_depth; | 591 | const int n = left < fifo_depth ? left : fifo_depth; |
587 | outsb (fifo, bufp, n); | 592 | outsb(fifo, bufp, n); |
588 | bufp += n; | 593 | bufp += n; |
589 | left -= n; | 594 | left -= n; |
590 | 595 | ||
591 | /* Adjust the poll time. */ | 596 | /* Adjust the poll time. */ |
592 | if (i < (poll_for - 2)) poll_for--; | 597 | if (i < (poll_for - 2)) |
598 | poll_for--; | ||
593 | continue; | 599 | continue; |
594 | } else if (i++ < poll_for) { | 600 | } else if (i++ < poll_for) { |
595 | udelay (10); | 601 | udelay(10); |
596 | ecrval = inb (ECONTROL (port)); | 602 | ecrval = inb(ECONTROL(port)); |
597 | goto poll; | 603 | goto poll; |
598 | } | 604 | } |
599 | 605 | ||
600 | /* Half-full (call me an optimist) */ | 606 | /* Half-full(call me an optimist) */ |
601 | byte = *bufp++; | 607 | byte = *bufp++; |
602 | outb (byte, fifo); | 608 | outb(byte, fifo); |
603 | left--; | 609 | left--; |
604 | } | 610 | } |
605 | 611 | dump_parport_state("leave fifo_write_block_pio", port); | |
606 | dump_parport_state ("leave fifo_write_block_pio", port); | ||
607 | return length - left; | 612 | return length - left; |
608 | } | 613 | } |
609 | 614 | ||
610 | #ifdef HAS_DMA | 615 | #ifdef HAS_DMA |
611 | static size_t parport_pc_fifo_write_block_dma (struct parport *port, | 616 | static size_t parport_pc_fifo_write_block_dma(struct parport *port, |
612 | const void *buf, size_t length) | 617 | const void *buf, size_t length) |
613 | { | 618 | { |
614 | int ret = 0; | 619 | int ret = 0; |
@@ -621,7 +626,7 @@ static size_t parport_pc_fifo_write_block_dma (struct parport *port, | |||
621 | unsigned long start = (unsigned long) buf; | 626 | unsigned long start = (unsigned long) buf; |
622 | unsigned long end = (unsigned long) buf + length - 1; | 627 | unsigned long end = (unsigned long) buf + length - 1; |
623 | 628 | ||
624 | dump_parport_state ("enter fifo_write_block_dma", port); | 629 | dump_parport_state("enter fifo_write_block_dma", port); |
625 | if (end < MAX_DMA_ADDRESS) { | 630 | if (end < MAX_DMA_ADDRESS) { |
626 | /* If it would cross a 64k boundary, cap it at the end. */ | 631 | /* If it would cross a 64k boundary, cap it at the end. */ |
627 | if ((start ^ end) & ~0xffffUL) | 632 | if ((start ^ end) & ~0xffffUL) |
@@ -629,8 +634,9 @@ dump_parport_state ("enter fifo_write_block_dma", port); | |||
629 | 634 | ||
630 | dma_addr = dma_handle = dma_map_single(dev, (void *)buf, length, | 635 | dma_addr = dma_handle = dma_map_single(dev, (void *)buf, length, |
631 | DMA_TO_DEVICE); | 636 | DMA_TO_DEVICE); |
632 | } else { | 637 | } else { |
633 | /* above 16 MB we use a bounce buffer as ISA-DMA is not possible */ | 638 | /* above 16 MB we use a bounce buffer as ISA-DMA |
639 | is not possible */ | ||
634 | maxlen = PAGE_SIZE; /* sizeof(priv->dma_buf) */ | 640 | maxlen = PAGE_SIZE; /* sizeof(priv->dma_buf) */ |
635 | dma_addr = priv->dma_handle; | 641 | dma_addr = priv->dma_handle; |
636 | dma_handle = 0; | 642 | dma_handle = 0; |
@@ -639,12 +645,12 @@ dump_parport_state ("enter fifo_write_block_dma", port); | |||
639 | port = port->physport; | 645 | port = port->physport; |
640 | 646 | ||
641 | /* We don't want to be interrupted every character. */ | 647 | /* We don't want to be interrupted every character. */ |
642 | parport_pc_disable_irq (port); | 648 | parport_pc_disable_irq(port); |
643 | /* set nErrIntrEn and serviceIntr */ | 649 | /* set nErrIntrEn and serviceIntr */ |
644 | frob_econtrol (port, (1<<4) | (1<<2), (1<<4) | (1<<2)); | 650 | frob_econtrol(port, (1<<4) | (1<<2), (1<<4) | (1<<2)); |
645 | 651 | ||
646 | /* Forward mode. */ | 652 | /* Forward mode. */ |
647 | parport_pc_data_forward (port); /* Must be in PS2 mode */ | 653 | parport_pc_data_forward(port); /* Must be in PS2 mode */ |
648 | 654 | ||
649 | while (left) { | 655 | while (left) { |
650 | unsigned long expire = jiffies + port->physport->cad->timeout; | 656 | unsigned long expire = jiffies + port->physport->cad->timeout; |
@@ -665,10 +671,10 @@ dump_parport_state ("enter fifo_write_block_dma", port); | |||
665 | set_dma_count(port->dma, count); | 671 | set_dma_count(port->dma, count); |
666 | 672 | ||
667 | /* Set DMA mode */ | 673 | /* Set DMA mode */ |
668 | frob_econtrol (port, 1<<3, 1<<3); | 674 | frob_econtrol(port, 1<<3, 1<<3); |
669 | 675 | ||
670 | /* Clear serviceIntr */ | 676 | /* Clear serviceIntr */ |
671 | frob_econtrol (port, 1<<2, 0); | 677 | frob_econtrol(port, 1<<2, 0); |
672 | 678 | ||
673 | enable_dma(port->dma); | 679 | enable_dma(port->dma); |
674 | release_dma_lock(dmaflag); | 680 | release_dma_lock(dmaflag); |
@@ -676,20 +682,22 @@ dump_parport_state ("enter fifo_write_block_dma", port); | |||
676 | /* assume DMA will be successful */ | 682 | /* assume DMA will be successful */ |
677 | left -= count; | 683 | left -= count; |
678 | buf += count; | 684 | buf += count; |
679 | if (dma_handle) dma_addr += count; | 685 | if (dma_handle) |
686 | dma_addr += count; | ||
680 | 687 | ||
681 | /* Wait for interrupt. */ | 688 | /* Wait for interrupt. */ |
682 | false_alarm: | 689 | false_alarm: |
683 | ret = parport_wait_event (port, HZ); | 690 | ret = parport_wait_event(port, HZ); |
684 | if (ret < 0) break; | 691 | if (ret < 0) |
692 | break; | ||
685 | ret = 0; | 693 | ret = 0; |
686 | if (!time_before (jiffies, expire)) { | 694 | if (!time_before(jiffies, expire)) { |
687 | /* Timed out. */ | 695 | /* Timed out. */ |
688 | printk (KERN_DEBUG "DMA write timed out\n"); | 696 | printk(KERN_DEBUG "DMA write timed out\n"); |
689 | break; | 697 | break; |
690 | } | 698 | } |
691 | /* Is serviceIntr set? */ | 699 | /* Is serviceIntr set? */ |
692 | if (!(inb (ECONTROL (port)) & (1<<2))) { | 700 | if (!(inb(ECONTROL(port)) & (1<<2))) { |
693 | cond_resched(); | 701 | cond_resched(); |
694 | 702 | ||
695 | goto false_alarm; | 703 | goto false_alarm; |
@@ -705,14 +713,15 @@ dump_parport_state ("enter fifo_write_block_dma", port); | |||
705 | 713 | ||
706 | /* Anyone else waiting for the port? */ | 714 | /* Anyone else waiting for the port? */ |
707 | if (port->waithead) { | 715 | if (port->waithead) { |
708 | printk (KERN_DEBUG "Somebody wants the port\n"); | 716 | printk(KERN_DEBUG "Somebody wants the port\n"); |
709 | break; | 717 | break; |
710 | } | 718 | } |
711 | 719 | ||
712 | /* update for possible DMA residue ! */ | 720 | /* update for possible DMA residue ! */ |
713 | buf -= count; | 721 | buf -= count; |
714 | left += count; | 722 | left += count; |
715 | if (dma_handle) dma_addr -= count; | 723 | if (dma_handle) |
724 | dma_addr -= count; | ||
716 | } | 725 | } |
717 | 726 | ||
718 | /* Maybe got here through break, so adjust for DMA residue! */ | 727 | /* Maybe got here through break, so adjust for DMA residue! */ |
@@ -723,12 +732,12 @@ dump_parport_state ("enter fifo_write_block_dma", port); | |||
723 | release_dma_lock(dmaflag); | 732 | release_dma_lock(dmaflag); |
724 | 733 | ||
725 | /* Turn off DMA mode */ | 734 | /* Turn off DMA mode */ |
726 | frob_econtrol (port, 1<<3, 0); | 735 | frob_econtrol(port, 1<<3, 0); |
727 | 736 | ||
728 | if (dma_handle) | 737 | if (dma_handle) |
729 | dma_unmap_single(dev, dma_handle, length, DMA_TO_DEVICE); | 738 | dma_unmap_single(dev, dma_handle, length, DMA_TO_DEVICE); |
730 | 739 | ||
731 | dump_parport_state ("leave fifo_write_block_dma", port); | 740 | dump_parport_state("leave fifo_write_block_dma", port); |
732 | return length - left; | 741 | return length - left; |
733 | } | 742 | } |
734 | #endif | 743 | #endif |
@@ -738,13 +747,13 @@ static inline size_t parport_pc_fifo_write_block(struct parport *port, | |||
738 | { | 747 | { |
739 | #ifdef HAS_DMA | 748 | #ifdef HAS_DMA |
740 | if (port->dma != PARPORT_DMA_NONE) | 749 | if (port->dma != PARPORT_DMA_NONE) |
741 | return parport_pc_fifo_write_block_dma (port, buf, length); | 750 | return parport_pc_fifo_write_block_dma(port, buf, length); |
742 | #endif | 751 | #endif |
743 | return parport_pc_fifo_write_block_pio (port, buf, length); | 752 | return parport_pc_fifo_write_block_pio(port, buf, length); |
744 | } | 753 | } |
745 | 754 | ||
746 | /* Parallel Port FIFO mode (ECP chipsets) */ | 755 | /* Parallel Port FIFO mode (ECP chipsets) */ |
747 | static size_t parport_pc_compat_write_block_pio (struct parport *port, | 756 | static size_t parport_pc_compat_write_block_pio(struct parport *port, |
748 | const void *buf, size_t length, | 757 | const void *buf, size_t length, |
749 | int flags) | 758 | int flags) |
750 | { | 759 | { |
@@ -756,14 +765,16 @@ static size_t parport_pc_compat_write_block_pio (struct parport *port, | |||
756 | /* Special case: a timeout of zero means we cannot call schedule(). | 765 | /* Special case: a timeout of zero means we cannot call schedule(). |
757 | * Also if O_NONBLOCK is set then use the default implementation. */ | 766 | * Also if O_NONBLOCK is set then use the default implementation. */ |
758 | if (port->physport->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK) | 767 | if (port->physport->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK) |
759 | return parport_ieee1284_write_compat (port, buf, | 768 | return parport_ieee1284_write_compat(port, buf, |
760 | length, flags); | 769 | length, flags); |
761 | 770 | ||
762 | /* Set up parallel port FIFO mode.*/ | 771 | /* Set up parallel port FIFO mode.*/ |
763 | parport_pc_data_forward (port); /* Must be in PS2 mode */ | 772 | parport_pc_data_forward(port); /* Must be in PS2 mode */ |
764 | parport_pc_frob_control (port, PARPORT_CONTROL_STROBE, 0); | 773 | parport_pc_frob_control(port, PARPORT_CONTROL_STROBE, 0); |
765 | r = change_mode (port, ECR_PPF); /* Parallel port FIFO */ | 774 | r = change_mode(port, ECR_PPF); /* Parallel port FIFO */ |
766 | if (r) printk (KERN_DEBUG "%s: Warning change_mode ECR_PPF failed\n", port->name); | 775 | if (r) |
776 | printk(KERN_DEBUG "%s: Warning change_mode ECR_PPF failed\n", | ||
777 | port->name); | ||
767 | 778 | ||
768 | port->physport->ieee1284.phase = IEEE1284_PH_FWD_DATA; | 779 | port->physport->ieee1284.phase = IEEE1284_PH_FWD_DATA; |
769 | 780 | ||
@@ -775,40 +786,39 @@ static size_t parport_pc_compat_write_block_pio (struct parport *port, | |||
775 | * the FIFO is empty, so allow 4 seconds for each position | 786 | * the FIFO is empty, so allow 4 seconds for each position |
776 | * in the fifo. | 787 | * in the fifo. |
777 | */ | 788 | */ |
778 | expire = jiffies + (priv->fifo_depth * HZ * 4); | 789 | expire = jiffies + (priv->fifo_depth * HZ * 4); |
779 | do { | 790 | do { |
780 | /* Wait for the FIFO to empty */ | 791 | /* Wait for the FIFO to empty */ |
781 | r = change_mode (port, ECR_PS2); | 792 | r = change_mode(port, ECR_PS2); |
782 | if (r != -EBUSY) { | 793 | if (r != -EBUSY) |
783 | break; | 794 | break; |
784 | } | 795 | } while (time_before(jiffies, expire)); |
785 | } while (time_before (jiffies, expire)); | ||
786 | if (r == -EBUSY) { | 796 | if (r == -EBUSY) { |
787 | 797 | ||
788 | printk (KERN_DEBUG "%s: FIFO is stuck\n", port->name); | 798 | printk(KERN_DEBUG "%s: FIFO is stuck\n", port->name); |
789 | 799 | ||
790 | /* Prevent further data transfer. */ | 800 | /* Prevent further data transfer. */ |
791 | frob_set_mode (port, ECR_TST); | 801 | frob_set_mode(port, ECR_TST); |
792 | 802 | ||
793 | /* Adjust for the contents of the FIFO. */ | 803 | /* Adjust for the contents of the FIFO. */ |
794 | for (written -= priv->fifo_depth; ; written++) { | 804 | for (written -= priv->fifo_depth; ; written++) { |
795 | if (inb (ECONTROL (port)) & 0x2) { | 805 | if (inb(ECONTROL(port)) & 0x2) { |
796 | /* Full up. */ | 806 | /* Full up. */ |
797 | break; | 807 | break; |
798 | } | 808 | } |
799 | outb (0, FIFO (port)); | 809 | outb(0, FIFO(port)); |
800 | } | 810 | } |
801 | 811 | ||
802 | /* Reset the FIFO and return to PS2 mode. */ | 812 | /* Reset the FIFO and return to PS2 mode. */ |
803 | frob_set_mode (port, ECR_PS2); | 813 | frob_set_mode(port, ECR_PS2); |
804 | } | 814 | } |
805 | 815 | ||
806 | r = parport_wait_peripheral (port, | 816 | r = parport_wait_peripheral(port, |
807 | PARPORT_STATUS_BUSY, | 817 | PARPORT_STATUS_BUSY, |
808 | PARPORT_STATUS_BUSY); | 818 | PARPORT_STATUS_BUSY); |
809 | if (r) | 819 | if (r) |
810 | printk (KERN_DEBUG | 820 | printk(KERN_DEBUG |
811 | "%s: BUSY timeout (%d) in compat_write_block_pio\n", | 821 | "%s: BUSY timeout (%d) in compat_write_block_pio\n", |
812 | port->name, r); | 822 | port->name, r); |
813 | 823 | ||
814 | port->physport->ieee1284.phase = IEEE1284_PH_FWD_IDLE; | 824 | port->physport->ieee1284.phase = IEEE1284_PH_FWD_IDLE; |
@@ -818,7 +828,7 @@ static size_t parport_pc_compat_write_block_pio (struct parport *port, | |||
818 | 828 | ||
819 | /* ECP */ | 829 | /* ECP */ |
820 | #ifdef CONFIG_PARPORT_1284 | 830 | #ifdef CONFIG_PARPORT_1284 |
821 | static size_t parport_pc_ecp_write_block_pio (struct parport *port, | 831 | static size_t parport_pc_ecp_write_block_pio(struct parport *port, |
822 | const void *buf, size_t length, | 832 | const void *buf, size_t length, |
823 | int flags) | 833 | int flags) |
824 | { | 834 | { |
@@ -830,36 +840,38 @@ static size_t parport_pc_ecp_write_block_pio (struct parport *port, | |||
830 | /* Special case: a timeout of zero means we cannot call schedule(). | 840 | /* Special case: a timeout of zero means we cannot call schedule(). |
831 | * Also if O_NONBLOCK is set then use the default implementation. */ | 841 | * Also if O_NONBLOCK is set then use the default implementation. */ |
832 | if (port->physport->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK) | 842 | if (port->physport->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK) |
833 | return parport_ieee1284_ecp_write_data (port, buf, | 843 | return parport_ieee1284_ecp_write_data(port, buf, |
834 | length, flags); | 844 | length, flags); |
835 | 845 | ||
836 | /* Switch to forward mode if necessary. */ | 846 | /* Switch to forward mode if necessary. */ |
837 | if (port->physport->ieee1284.phase != IEEE1284_PH_FWD_IDLE) { | 847 | if (port->physport->ieee1284.phase != IEEE1284_PH_FWD_IDLE) { |
838 | /* Event 47: Set nInit high. */ | 848 | /* Event 47: Set nInit high. */ |
839 | parport_frob_control (port, | 849 | parport_frob_control(port, |
840 | PARPORT_CONTROL_INIT | 850 | PARPORT_CONTROL_INIT |
841 | | PARPORT_CONTROL_AUTOFD, | 851 | | PARPORT_CONTROL_AUTOFD, |
842 | PARPORT_CONTROL_INIT | 852 | PARPORT_CONTROL_INIT |
843 | | PARPORT_CONTROL_AUTOFD); | 853 | | PARPORT_CONTROL_AUTOFD); |
844 | 854 | ||
845 | /* Event 49: PError goes high. */ | 855 | /* Event 49: PError goes high. */ |
846 | r = parport_wait_peripheral (port, | 856 | r = parport_wait_peripheral(port, |
847 | PARPORT_STATUS_PAPEROUT, | 857 | PARPORT_STATUS_PAPEROUT, |
848 | PARPORT_STATUS_PAPEROUT); | 858 | PARPORT_STATUS_PAPEROUT); |
849 | if (r) { | 859 | if (r) { |
850 | printk (KERN_DEBUG "%s: PError timeout (%d) " | 860 | printk(KERN_DEBUG "%s: PError timeout (%d) " |
851 | "in ecp_write_block_pio\n", port->name, r); | 861 | "in ecp_write_block_pio\n", port->name, r); |
852 | } | 862 | } |
853 | } | 863 | } |
854 | 864 | ||
855 | /* Set up ECP parallel port mode.*/ | 865 | /* Set up ECP parallel port mode.*/ |
856 | parport_pc_data_forward (port); /* Must be in PS2 mode */ | 866 | parport_pc_data_forward(port); /* Must be in PS2 mode */ |
857 | parport_pc_frob_control (port, | 867 | parport_pc_frob_control(port, |
858 | PARPORT_CONTROL_STROBE | | 868 | PARPORT_CONTROL_STROBE | |
859 | PARPORT_CONTROL_AUTOFD, | 869 | PARPORT_CONTROL_AUTOFD, |
860 | 0); | 870 | 0); |
861 | r = change_mode (port, ECR_ECP); /* ECP FIFO */ | 871 | r = change_mode(port, ECR_ECP); /* ECP FIFO */ |
862 | if (r) printk (KERN_DEBUG "%s: Warning change_mode ECR_ECP failed\n", port->name); | 872 | if (r) |
873 | printk(KERN_DEBUG "%s: Warning change_mode ECR_ECP failed\n", | ||
874 | port->name); | ||
863 | port->physport->ieee1284.phase = IEEE1284_PH_FWD_DATA; | 875 | port->physport->ieee1284.phase = IEEE1284_PH_FWD_DATA; |
864 | 876 | ||
865 | /* Write the data to the FIFO. */ | 877 | /* Write the data to the FIFO. */ |
@@ -873,55 +885,54 @@ static size_t parport_pc_ecp_write_block_pio (struct parport *port, | |||
873 | expire = jiffies + (priv->fifo_depth * (HZ * 4)); | 885 | expire = jiffies + (priv->fifo_depth * (HZ * 4)); |
874 | do { | 886 | do { |
875 | /* Wait for the FIFO to empty */ | 887 | /* Wait for the FIFO to empty */ |
876 | r = change_mode (port, ECR_PS2); | 888 | r = change_mode(port, ECR_PS2); |
877 | if (r != -EBUSY) { | 889 | if (r != -EBUSY) |
878 | break; | 890 | break; |
879 | } | 891 | } while (time_before(jiffies, expire)); |
880 | } while (time_before (jiffies, expire)); | ||
881 | if (r == -EBUSY) { | 892 | if (r == -EBUSY) { |
882 | 893 | ||
883 | printk (KERN_DEBUG "%s: FIFO is stuck\n", port->name); | 894 | printk(KERN_DEBUG "%s: FIFO is stuck\n", port->name); |
884 | 895 | ||
885 | /* Prevent further data transfer. */ | 896 | /* Prevent further data transfer. */ |
886 | frob_set_mode (port, ECR_TST); | 897 | frob_set_mode(port, ECR_TST); |
887 | 898 | ||
888 | /* Adjust for the contents of the FIFO. */ | 899 | /* Adjust for the contents of the FIFO. */ |
889 | for (written -= priv->fifo_depth; ; written++) { | 900 | for (written -= priv->fifo_depth; ; written++) { |
890 | if (inb (ECONTROL (port)) & 0x2) { | 901 | if (inb(ECONTROL(port)) & 0x2) { |
891 | /* Full up. */ | 902 | /* Full up. */ |
892 | break; | 903 | break; |
893 | } | 904 | } |
894 | outb (0, FIFO (port)); | 905 | outb(0, FIFO(port)); |
895 | } | 906 | } |
896 | 907 | ||
897 | /* Reset the FIFO and return to PS2 mode. */ | 908 | /* Reset the FIFO and return to PS2 mode. */ |
898 | frob_set_mode (port, ECR_PS2); | 909 | frob_set_mode(port, ECR_PS2); |
899 | 910 | ||
900 | /* Host transfer recovery. */ | 911 | /* Host transfer recovery. */ |
901 | parport_pc_data_reverse (port); /* Must be in PS2 mode */ | 912 | parport_pc_data_reverse(port); /* Must be in PS2 mode */ |
902 | udelay (5); | 913 | udelay(5); |
903 | parport_frob_control (port, PARPORT_CONTROL_INIT, 0); | 914 | parport_frob_control(port, PARPORT_CONTROL_INIT, 0); |
904 | r = parport_wait_peripheral (port, PARPORT_STATUS_PAPEROUT, 0); | 915 | r = parport_wait_peripheral(port, PARPORT_STATUS_PAPEROUT, 0); |
905 | if (r) | 916 | if (r) |
906 | printk (KERN_DEBUG "%s: PE,1 timeout (%d) " | 917 | printk(KERN_DEBUG "%s: PE,1 timeout (%d) " |
907 | "in ecp_write_block_pio\n", port->name, r); | 918 | "in ecp_write_block_pio\n", port->name, r); |
908 | 919 | ||
909 | parport_frob_control (port, | 920 | parport_frob_control(port, |
910 | PARPORT_CONTROL_INIT, | 921 | PARPORT_CONTROL_INIT, |
911 | PARPORT_CONTROL_INIT); | 922 | PARPORT_CONTROL_INIT); |
912 | r = parport_wait_peripheral (port, | 923 | r = parport_wait_peripheral(port, |
913 | PARPORT_STATUS_PAPEROUT, | 924 | PARPORT_STATUS_PAPEROUT, |
914 | PARPORT_STATUS_PAPEROUT); | 925 | PARPORT_STATUS_PAPEROUT); |
915 | if (r) | 926 | if (r) |
916 | printk (KERN_DEBUG "%s: PE,2 timeout (%d) " | 927 | printk(KERN_DEBUG "%s: PE,2 timeout (%d) " |
917 | "in ecp_write_block_pio\n", port->name, r); | 928 | "in ecp_write_block_pio\n", port->name, r); |
918 | } | 929 | } |
919 | 930 | ||
920 | r = parport_wait_peripheral (port, | 931 | r = parport_wait_peripheral(port, |
921 | PARPORT_STATUS_BUSY, | 932 | PARPORT_STATUS_BUSY, |
922 | PARPORT_STATUS_BUSY); | 933 | PARPORT_STATUS_BUSY); |
923 | if(r) | 934 | if (r) |
924 | printk (KERN_DEBUG | 935 | printk(KERN_DEBUG |
925 | "%s: BUSY timeout (%d) in ecp_write_block_pio\n", | 936 | "%s: BUSY timeout (%d) in ecp_write_block_pio\n", |
926 | port->name, r); | 937 | port->name, r); |
927 | 938 | ||
@@ -931,7 +942,7 @@ static size_t parport_pc_ecp_write_block_pio (struct parport *port, | |||
931 | } | 942 | } |
932 | 943 | ||
933 | #if 0 | 944 | #if 0 |
934 | static size_t parport_pc_ecp_read_block_pio (struct parport *port, | 945 | static size_t parport_pc_ecp_read_block_pio(struct parport *port, |
935 | void *buf, size_t length, | 946 | void *buf, size_t length, |
936 | int flags) | 947 | int flags) |
937 | { | 948 | { |
@@ -944,13 +955,13 @@ static size_t parport_pc_ecp_read_block_pio (struct parport *port, | |||
944 | char *bufp = buf; | 955 | char *bufp = buf; |
945 | 956 | ||
946 | port = port->physport; | 957 | port = port->physport; |
947 | DPRINTK (KERN_DEBUG "parport_pc: parport_pc_ecp_read_block_pio\n"); | 958 | DPRINTK(KERN_DEBUG "parport_pc: parport_pc_ecp_read_block_pio\n"); |
948 | dump_parport_state ("enter fcn", port); | 959 | dump_parport_state("enter fcn", port); |
949 | 960 | ||
950 | /* Special case: a timeout of zero means we cannot call schedule(). | 961 | /* Special case: a timeout of zero means we cannot call schedule(). |
951 | * Also if O_NONBLOCK is set then use the default implementation. */ | 962 | * Also if O_NONBLOCK is set then use the default implementation. */ |
952 | if (port->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK) | 963 | if (port->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK) |
953 | return parport_ieee1284_ecp_read_data (port, buf, | 964 | return parport_ieee1284_ecp_read_data(port, buf, |
954 | length, flags); | 965 | length, flags); |
955 | 966 | ||
956 | if (port->ieee1284.mode == IEEE1284_MODE_ECPRLE) { | 967 | if (port->ieee1284.mode == IEEE1284_MODE_ECPRLE) { |
@@ -966,173 +977,178 @@ dump_parport_state ("enter fcn", port); | |||
966 | * go through software emulation. Otherwise we may have to throw | 977 | * go through software emulation. Otherwise we may have to throw |
967 | * away data. */ | 978 | * away data. */ |
968 | if (length < fifofull) | 979 | if (length < fifofull) |
969 | return parport_ieee1284_ecp_read_data (port, buf, | 980 | return parport_ieee1284_ecp_read_data(port, buf, |
970 | length, flags); | 981 | length, flags); |
971 | 982 | ||
972 | if (port->ieee1284.phase != IEEE1284_PH_REV_IDLE) { | 983 | if (port->ieee1284.phase != IEEE1284_PH_REV_IDLE) { |
973 | /* change to reverse-idle phase (must be in forward-idle) */ | 984 | /* change to reverse-idle phase (must be in forward-idle) */ |
974 | 985 | ||
975 | /* Event 38: Set nAutoFd low (also make sure nStrobe is high) */ | 986 | /* Event 38: Set nAutoFd low (also make sure nStrobe is high) */ |
976 | parport_frob_control (port, | 987 | parport_frob_control(port, |
977 | PARPORT_CONTROL_AUTOFD | 988 | PARPORT_CONTROL_AUTOFD |
978 | | PARPORT_CONTROL_STROBE, | 989 | | PARPORT_CONTROL_STROBE, |
979 | PARPORT_CONTROL_AUTOFD); | 990 | PARPORT_CONTROL_AUTOFD); |
980 | parport_pc_data_reverse (port); /* Must be in PS2 mode */ | 991 | parport_pc_data_reverse(port); /* Must be in PS2 mode */ |
981 | udelay (5); | 992 | udelay(5); |
982 | /* Event 39: Set nInit low to initiate bus reversal */ | 993 | /* Event 39: Set nInit low to initiate bus reversal */ |
983 | parport_frob_control (port, | 994 | parport_frob_control(port, |
984 | PARPORT_CONTROL_INIT, | 995 | PARPORT_CONTROL_INIT, |
985 | 0); | 996 | 0); |
986 | /* Event 40: Wait for nAckReverse (PError) to go low */ | 997 | /* Event 40: Wait for nAckReverse (PError) to go low */ |
987 | r = parport_wait_peripheral (port, PARPORT_STATUS_PAPEROUT, 0); | 998 | r = parport_wait_peripheral(port, PARPORT_STATUS_PAPEROUT, 0); |
988 | if (r) { | 999 | if (r) { |
989 | printk (KERN_DEBUG "%s: PE timeout Event 40 (%d) " | 1000 | printk(KERN_DEBUG "%s: PE timeout Event 40 (%d) " |
990 | "in ecp_read_block_pio\n", port->name, r); | 1001 | "in ecp_read_block_pio\n", port->name, r); |
991 | return 0; | 1002 | return 0; |
992 | } | 1003 | } |
993 | } | 1004 | } |
994 | 1005 | ||
995 | /* Set up ECP FIFO mode.*/ | 1006 | /* Set up ECP FIFO mode.*/ |
996 | /* parport_pc_frob_control (port, | 1007 | /* parport_pc_frob_control(port, |
997 | PARPORT_CONTROL_STROBE | | 1008 | PARPORT_CONTROL_STROBE | |
998 | PARPORT_CONTROL_AUTOFD, | 1009 | PARPORT_CONTROL_AUTOFD, |
999 | PARPORT_CONTROL_AUTOFD); */ | 1010 | PARPORT_CONTROL_AUTOFD); */ |
1000 | r = change_mode (port, ECR_ECP); /* ECP FIFO */ | 1011 | r = change_mode(port, ECR_ECP); /* ECP FIFO */ |
1001 | if (r) printk (KERN_DEBUG "%s: Warning change_mode ECR_ECP failed\n", port->name); | 1012 | if (r) |
1013 | printk(KERN_DEBUG "%s: Warning change_mode ECR_ECP failed\n", | ||
1014 | port->name); | ||
1002 | 1015 | ||
1003 | port->ieee1284.phase = IEEE1284_PH_REV_DATA; | 1016 | port->ieee1284.phase = IEEE1284_PH_REV_DATA; |
1004 | 1017 | ||
1005 | /* the first byte must be collected manually */ | 1018 | /* the first byte must be collected manually */ |
1006 | dump_parport_state ("pre 43", port); | 1019 | dump_parport_state("pre 43", port); |
1007 | /* Event 43: Wait for nAck to go low */ | 1020 | /* Event 43: Wait for nAck to go low */ |
1008 | r = parport_wait_peripheral (port, PARPORT_STATUS_ACK, 0); | 1021 | r = parport_wait_peripheral(port, PARPORT_STATUS_ACK, 0); |
1009 | if (r) { | 1022 | if (r) { |
1010 | /* timed out while reading -- no data */ | 1023 | /* timed out while reading -- no data */ |
1011 | printk (KERN_DEBUG "PIO read timed out (initial byte)\n"); | 1024 | printk(KERN_DEBUG "PIO read timed out (initial byte)\n"); |
1012 | goto out_no_data; | 1025 | goto out_no_data; |
1013 | } | 1026 | } |
1014 | /* read byte */ | 1027 | /* read byte */ |
1015 | *bufp++ = inb (DATA (port)); | 1028 | *bufp++ = inb(DATA(port)); |
1016 | left--; | 1029 | left--; |
1017 | dump_parport_state ("43-44", port); | 1030 | dump_parport_state("43-44", port); |
1018 | /* Event 44: nAutoFd (HostAck) goes high to acknowledge */ | 1031 | /* Event 44: nAutoFd (HostAck) goes high to acknowledge */ |
1019 | parport_pc_frob_control (port, | 1032 | parport_pc_frob_control(port, |
1020 | PARPORT_CONTROL_AUTOFD, | 1033 | PARPORT_CONTROL_AUTOFD, |
1021 | 0); | 1034 | 0); |
1022 | dump_parport_state ("pre 45", port); | 1035 | dump_parport_state("pre 45", port); |
1023 | /* Event 45: Wait for nAck to go high */ | 1036 | /* Event 45: Wait for nAck to go high */ |
1024 | /* r = parport_wait_peripheral (port, PARPORT_STATUS_ACK, PARPORT_STATUS_ACK); */ | 1037 | /* r = parport_wait_peripheral(port, PARPORT_STATUS_ACK, |
1025 | dump_parport_state ("post 45", port); | 1038 | PARPORT_STATUS_ACK); */ |
1026 | r = 0; | 1039 | dump_parport_state("post 45", port); |
1040 | r = 0; | ||
1027 | if (r) { | 1041 | if (r) { |
1028 | /* timed out while waiting for peripheral to respond to ack */ | 1042 | /* timed out while waiting for peripheral to respond to ack */ |
1029 | printk (KERN_DEBUG "ECP PIO read timed out (waiting for nAck)\n"); | 1043 | printk(KERN_DEBUG "ECP PIO read timed out (waiting for nAck)\n"); |
1030 | 1044 | ||
1031 | /* keep hold of the byte we've got already */ | 1045 | /* keep hold of the byte we've got already */ |
1032 | goto out_no_data; | 1046 | goto out_no_data; |
1033 | } | 1047 | } |
1034 | /* Event 46: nAutoFd (HostAck) goes low to accept more data */ | 1048 | /* Event 46: nAutoFd (HostAck) goes low to accept more data */ |
1035 | parport_pc_frob_control (port, | 1049 | parport_pc_frob_control(port, |
1036 | PARPORT_CONTROL_AUTOFD, | 1050 | PARPORT_CONTROL_AUTOFD, |
1037 | PARPORT_CONTROL_AUTOFD); | 1051 | PARPORT_CONTROL_AUTOFD); |
1038 | 1052 | ||
1039 | 1053 | ||
1040 | dump_parport_state ("rev idle", port); | 1054 | dump_parport_state("rev idle", port); |
1041 | /* Do the transfer. */ | 1055 | /* Do the transfer. */ |
1042 | while (left > fifofull) { | 1056 | while (left > fifofull) { |
1043 | int ret; | 1057 | int ret; |
1044 | unsigned long expire = jiffies + port->cad->timeout; | 1058 | unsigned long expire = jiffies + port->cad->timeout; |
1045 | unsigned char ecrval = inb (ECONTROL (port)); | 1059 | unsigned char ecrval = inb(ECONTROL(port)); |
1046 | 1060 | ||
1047 | if (need_resched() && time_before (jiffies, expire)) | 1061 | if (need_resched() && time_before(jiffies, expire)) |
1048 | /* Can't yield the port. */ | 1062 | /* Can't yield the port. */ |
1049 | schedule (); | 1063 | schedule(); |
1050 | 1064 | ||
1051 | /* At this point, the FIFO may already be full. In | 1065 | /* At this point, the FIFO may already be full. In |
1052 | * that case ECP is already holding back the | 1066 | * that case ECP is already holding back the |
1053 | * peripheral (assuming proper design) with a delayed | 1067 | * peripheral (assuming proper design) with a delayed |
1054 | * handshake. Work fast to avoid a peripheral | 1068 | * handshake. Work fast to avoid a peripheral |
1055 | * timeout. */ | 1069 | * timeout. */ |
1056 | 1070 | ||
1057 | if (ecrval & 0x01) { | 1071 | if (ecrval & 0x01) { |
1058 | /* FIFO is empty. Wait for interrupt. */ | 1072 | /* FIFO is empty. Wait for interrupt. */ |
1059 | dump_parport_state ("FIFO empty", port); | 1073 | dump_parport_state("FIFO empty", port); |
1060 | 1074 | ||
1061 | /* Anyone else waiting for the port? */ | 1075 | /* Anyone else waiting for the port? */ |
1062 | if (port->waithead) { | 1076 | if (port->waithead) { |
1063 | printk (KERN_DEBUG "Somebody wants the port\n"); | 1077 | printk(KERN_DEBUG "Somebody wants the port\n"); |
1064 | break; | 1078 | break; |
1065 | } | 1079 | } |
1066 | 1080 | ||
1067 | /* Clear serviceIntr */ | 1081 | /* Clear serviceIntr */ |
1068 | ECR_WRITE (port, ecrval & ~(1<<2)); | 1082 | ECR_WRITE(port, ecrval & ~(1<<2)); |
1069 | false_alarm: | 1083 | false_alarm: |
1070 | dump_parport_state ("waiting", port); | 1084 | dump_parport_state("waiting", port); |
1071 | ret = parport_wait_event (port, HZ); | 1085 | ret = parport_wait_event(port, HZ); |
1072 | DPRINTK (KERN_DEBUG "parport_wait_event returned %d\n", ret); | 1086 | DPRINTK(KERN_DEBUG "parport_wait_event returned %d\n", |
1087 | ret); | ||
1073 | if (ret < 0) | 1088 | if (ret < 0) |
1074 | break; | 1089 | break; |
1075 | ret = 0; | 1090 | ret = 0; |
1076 | if (!time_before (jiffies, expire)) { | 1091 | if (!time_before(jiffies, expire)) { |
1077 | /* Timed out. */ | 1092 | /* Timed out. */ |
1078 | dump_parport_state ("timeout", port); | 1093 | dump_parport_state("timeout", port); |
1079 | printk (KERN_DEBUG "PIO read timed out\n"); | 1094 | printk(KERN_DEBUG "PIO read timed out\n"); |
1080 | break; | 1095 | break; |
1081 | } | 1096 | } |
1082 | ecrval = inb (ECONTROL (port)); | 1097 | ecrval = inb(ECONTROL(port)); |
1083 | if (!(ecrval & (1<<2))) { | 1098 | if (!(ecrval & (1<<2))) { |
1084 | if (need_resched() && | 1099 | if (need_resched() && |
1085 | time_before (jiffies, expire)) { | 1100 | time_before(jiffies, expire)) { |
1086 | schedule (); | 1101 | schedule(); |
1087 | } | 1102 | } |
1088 | goto false_alarm; | 1103 | goto false_alarm; |
1089 | } | 1104 | } |
1090 | 1105 | ||
1091 | /* Depending on how the FIFO threshold was | 1106 | /* Depending on how the FIFO threshold was |
1092 | * set, how long interrupt service took, and | 1107 | * set, how long interrupt service took, and |
1093 | * how fast the peripheral is, we might be | 1108 | * how fast the peripheral is, we might be |
1094 | * lucky and have a just filled FIFO. */ | 1109 | * lucky and have a just filled FIFO. */ |
1095 | continue; | 1110 | continue; |
1096 | } | 1111 | } |
1097 | 1112 | ||
1098 | if (ecrval & 0x02) { | 1113 | if (ecrval & 0x02) { |
1099 | /* FIFO is full. */ | 1114 | /* FIFO is full. */ |
1100 | dump_parport_state ("FIFO full", port); | 1115 | dump_parport_state("FIFO full", port); |
1101 | insb (fifo, bufp, fifo_depth); | 1116 | insb(fifo, bufp, fifo_depth); |
1102 | bufp += fifo_depth; | 1117 | bufp += fifo_depth; |
1103 | left -= fifo_depth; | 1118 | left -= fifo_depth; |
1104 | continue; | 1119 | continue; |
1105 | } | 1120 | } |
1106 | 1121 | ||
1107 | DPRINTK (KERN_DEBUG "*** ecp_read_block_pio: reading one byte from the FIFO\n"); | 1122 | DPRINTK(KERN_DEBUG |
1123 | "*** ecp_read_block_pio: reading one byte from the FIFO\n"); | ||
1108 | 1124 | ||
1109 | /* FIFO not filled. We will cycle this loop for a while | 1125 | /* FIFO not filled. We will cycle this loop for a while |
1110 | * and either the peripheral will fill it faster, | 1126 | * and either the peripheral will fill it faster, |
1111 | * tripping a fast empty with insb, or we empty it. */ | 1127 | * tripping a fast empty with insb, or we empty it. */ |
1112 | *bufp++ = inb (fifo); | 1128 | *bufp++ = inb(fifo); |
1113 | left--; | 1129 | left--; |
1114 | } | 1130 | } |
1115 | 1131 | ||
1116 | /* scoop up anything left in the FIFO */ | 1132 | /* scoop up anything left in the FIFO */ |
1117 | while (left && !(inb (ECONTROL (port) & 0x01))) { | 1133 | while (left && !(inb(ECONTROL(port) & 0x01))) { |
1118 | *bufp++ = inb (fifo); | 1134 | *bufp++ = inb(fifo); |
1119 | left--; | 1135 | left--; |
1120 | } | 1136 | } |
1121 | 1137 | ||
1122 | port->ieee1284.phase = IEEE1284_PH_REV_IDLE; | 1138 | port->ieee1284.phase = IEEE1284_PH_REV_IDLE; |
1123 | dump_parport_state ("rev idle2", port); | 1139 | dump_parport_state("rev idle2", port); |
1124 | 1140 | ||
1125 | out_no_data: | 1141 | out_no_data: |
1126 | 1142 | ||
1127 | /* Go to forward idle mode to shut the peripheral up (event 47). */ | 1143 | /* Go to forward idle mode to shut the peripheral up (event 47). */ |
1128 | parport_frob_control (port, PARPORT_CONTROL_INIT, PARPORT_CONTROL_INIT); | 1144 | parport_frob_control(port, PARPORT_CONTROL_INIT, PARPORT_CONTROL_INIT); |
1129 | 1145 | ||
1130 | /* event 49: PError goes high */ | 1146 | /* event 49: PError goes high */ |
1131 | r = parport_wait_peripheral (port, | 1147 | r = parport_wait_peripheral(port, |
1132 | PARPORT_STATUS_PAPEROUT, | 1148 | PARPORT_STATUS_PAPEROUT, |
1133 | PARPORT_STATUS_PAPEROUT); | 1149 | PARPORT_STATUS_PAPEROUT); |
1134 | if (r) { | 1150 | if (r) { |
1135 | printk (KERN_DEBUG | 1151 | printk(KERN_DEBUG |
1136 | "%s: PE timeout FWDIDLE (%d) in ecp_read_block_pio\n", | 1152 | "%s: PE timeout FWDIDLE (%d) in ecp_read_block_pio\n", |
1137 | port->name, r); | 1153 | port->name, r); |
1138 | } | 1154 | } |
@@ -1141,14 +1157,14 @@ out_no_data: | |||
1141 | 1157 | ||
1142 | /* Finish up. */ | 1158 | /* Finish up. */ |
1143 | { | 1159 | { |
1144 | int lost = get_fifo_residue (port); | 1160 | int lost = get_fifo_residue(port); |
1145 | if (lost) | 1161 | if (lost) |
1146 | /* Shouldn't happen with compliant peripherals. */ | 1162 | /* Shouldn't happen with compliant peripherals. */ |
1147 | printk (KERN_DEBUG "%s: DATA LOSS (%d bytes)!\n", | 1163 | printk(KERN_DEBUG "%s: DATA LOSS (%d bytes)!\n", |
1148 | port->name, lost); | 1164 | port->name, lost); |
1149 | } | 1165 | } |
1150 | 1166 | ||
1151 | dump_parport_state ("fwd idle", port); | 1167 | dump_parport_state("fwd idle", port); |
1152 | return length - left; | 1168 | return length - left; |
1153 | } | 1169 | } |
1154 | #endif /* 0 */ | 1170 | #endif /* 0 */ |
@@ -1164,8 +1180,7 @@ dump_parport_state ("fwd idle", port); | |||
1164 | 1180 | ||
1165 | /* GCC is not inlining extern inline function later overwriten to non-inline, | 1181 | /* GCC is not inlining extern inline function later overwriten to non-inline, |
1166 | so we use outlined_ variants here. */ | 1182 | so we use outlined_ variants here. */ |
1167 | static const struct parport_operations parport_pc_ops = | 1183 | static const struct parport_operations parport_pc_ops = { |
1168 | { | ||
1169 | .write_data = parport_pc_write_data, | 1184 | .write_data = parport_pc_write_data, |
1170 | .read_data = parport_pc_read_data, | 1185 | .read_data = parport_pc_read_data, |
1171 | 1186 | ||
@@ -1202,88 +1217,107 @@ static const struct parport_operations parport_pc_ops = | |||
1202 | }; | 1217 | }; |
1203 | 1218 | ||
1204 | #ifdef CONFIG_PARPORT_PC_SUPERIO | 1219 | #ifdef CONFIG_PARPORT_PC_SUPERIO |
1220 | |||
1221 | static struct superio_struct *find_free_superio(void) | ||
1222 | { | ||
1223 | int i; | ||
1224 | for (i = 0; i < NR_SUPERIOS; i++) | ||
1225 | if (superios[i].io == 0) | ||
1226 | return &superios[i]; | ||
1227 | return NULL; | ||
1228 | } | ||
1229 | |||
1230 | |||
1205 | /* Super-IO chipset detection, Winbond, SMSC */ | 1231 | /* Super-IO chipset detection, Winbond, SMSC */ |
1206 | static void __devinit show_parconfig_smsc37c669(int io, int key) | 1232 | static void __devinit show_parconfig_smsc37c669(int io, int key) |
1207 | { | 1233 | { |
1208 | int cr1,cr4,cra,cr23,cr26,cr27,i=0; | 1234 | int cr1, cr4, cra, cr23, cr26, cr27; |
1209 | static const char *const modes[]={ | 1235 | struct superio_struct *s; |
1236 | |||
1237 | static const char *const modes[] = { | ||
1210 | "SPP and Bidirectional (PS/2)", | 1238 | "SPP and Bidirectional (PS/2)", |
1211 | "EPP and SPP", | 1239 | "EPP and SPP", |
1212 | "ECP", | 1240 | "ECP", |
1213 | "ECP and EPP" }; | 1241 | "ECP and EPP" }; |
1214 | 1242 | ||
1215 | outb(key,io); | 1243 | outb(key, io); |
1216 | outb(key,io); | 1244 | outb(key, io); |
1217 | outb(1,io); | 1245 | outb(1, io); |
1218 | cr1=inb(io+1); | 1246 | cr1 = inb(io + 1); |
1219 | outb(4,io); | 1247 | outb(4, io); |
1220 | cr4=inb(io+1); | 1248 | cr4 = inb(io + 1); |
1221 | outb(0x0a,io); | 1249 | outb(0x0a, io); |
1222 | cra=inb(io+1); | 1250 | cra = inb(io + 1); |
1223 | outb(0x23,io); | 1251 | outb(0x23, io); |
1224 | cr23=inb(io+1); | 1252 | cr23 = inb(io + 1); |
1225 | outb(0x26,io); | 1253 | outb(0x26, io); |
1226 | cr26=inb(io+1); | 1254 | cr26 = inb(io + 1); |
1227 | outb(0x27,io); | 1255 | outb(0x27, io); |
1228 | cr27=inb(io+1); | 1256 | cr27 = inb(io + 1); |
1229 | outb(0xaa,io); | 1257 | outb(0xaa, io); |
1230 | 1258 | ||
1231 | if (verbose_probing) { | 1259 | if (verbose_probing) { |
1232 | printk (KERN_INFO "SMSC 37c669 LPT Config: cr_1=0x%02x, 4=0x%02x, " | 1260 | printk(KERN_INFO |
1261 | "SMSC 37c669 LPT Config: cr_1=0x%02x, 4=0x%02x, " | ||
1233 | "A=0x%2x, 23=0x%02x, 26=0x%02x, 27=0x%02x\n", | 1262 | "A=0x%2x, 23=0x%02x, 26=0x%02x, 27=0x%02x\n", |
1234 | cr1,cr4,cra,cr23,cr26,cr27); | 1263 | cr1, cr4, cra, cr23, cr26, cr27); |
1235 | 1264 | ||
1236 | /* The documentation calls DMA and IRQ-Lines by letters, so | 1265 | /* The documentation calls DMA and IRQ-Lines by letters, so |
1237 | the board maker can/will wire them | 1266 | the board maker can/will wire them |
1238 | appropriately/randomly... G=reserved H=IDE-irq, */ | 1267 | appropriately/randomly... G=reserved H=IDE-irq, */ |
1239 | printk (KERN_INFO "SMSC LPT Config: io=0x%04x, irq=%c, dma=%c, " | 1268 | printk(KERN_INFO |
1240 | "fifo threshold=%d\n", cr23*4, | 1269 | "SMSC LPT Config: io=0x%04x, irq=%c, dma=%c, fifo threshold=%d\n", |
1241 | (cr27 &0x0f) ? 'A'-1+(cr27 &0x0f): '-', | 1270 | cr23 * 4, |
1242 | (cr26 &0x0f) ? 'A'-1+(cr26 &0x0f): '-', cra & 0x0f); | 1271 | (cr27 & 0x0f) ? 'A' - 1 + (cr27 & 0x0f) : '-', |
1272 | (cr26 & 0x0f) ? 'A' - 1 + (cr26 & 0x0f) : '-', | ||
1273 | cra & 0x0f); | ||
1243 | printk(KERN_INFO "SMSC LPT Config: enabled=%s power=%s\n", | 1274 | printk(KERN_INFO "SMSC LPT Config: enabled=%s power=%s\n", |
1244 | (cr23*4 >=0x100) ?"yes":"no", (cr1 & 4) ? "yes" : "no"); | 1275 | (cr23 * 4 >= 0x100) ? "yes" : "no", |
1245 | printk(KERN_INFO "SMSC LPT Config: Port mode=%s, EPP version =%s\n", | 1276 | (cr1 & 4) ? "yes" : "no"); |
1246 | (cr1 & 0x08 ) ? "Standard mode only (SPP)" : modes[cr4 & 0x03], | 1277 | printk(KERN_INFO |
1247 | (cr4 & 0x40) ? "1.7" : "1.9"); | 1278 | "SMSC LPT Config: Port mode=%s, EPP version =%s\n", |
1279 | (cr1 & 0x08) ? "Standard mode only (SPP)" | ||
1280 | : modes[cr4 & 0x03], | ||
1281 | (cr4 & 0x40) ? "1.7" : "1.9"); | ||
1248 | } | 1282 | } |
1249 | 1283 | ||
1250 | /* Heuristics ! BIOS setup for this mainboard device limits | 1284 | /* Heuristics ! BIOS setup for this mainboard device limits |
1251 | the choices to standard settings, i.e. io-address and IRQ | 1285 | the choices to standard settings, i.e. io-address and IRQ |
1252 | are related, however DMA can be 1 or 3, assume DMA_A=DMA1, | 1286 | are related, however DMA can be 1 or 3, assume DMA_A=DMA1, |
1253 | DMA_C=DMA3 (this is true e.g. for TYAN 1564D Tomcat IV) */ | 1287 | DMA_C=DMA3 (this is true e.g. for TYAN 1564D Tomcat IV) */ |
1254 | if(cr23*4 >=0x100) { /* if active */ | 1288 | if (cr23 * 4 >= 0x100) { /* if active */ |
1255 | while((superios[i].io!= 0) && (i<NR_SUPERIOS)) | 1289 | s = find_free_superio(); |
1256 | i++; | 1290 | if (s == NULL) |
1257 | if(i==NR_SUPERIOS) | ||
1258 | printk(KERN_INFO "Super-IO: too many chips!\n"); | 1291 | printk(KERN_INFO "Super-IO: too many chips!\n"); |
1259 | else { | 1292 | else { |
1260 | int d; | 1293 | int d; |
1261 | switch (cr23*4) { | 1294 | switch (cr23 * 4) { |
1262 | case 0x3bc: | 1295 | case 0x3bc: |
1263 | superios[i].io = 0x3bc; | 1296 | s->io = 0x3bc; |
1264 | superios[i].irq = 7; | 1297 | s->irq = 7; |
1265 | break; | 1298 | break; |
1266 | case 0x378: | 1299 | case 0x378: |
1267 | superios[i].io = 0x378; | 1300 | s->io = 0x378; |
1268 | superios[i].irq = 7; | 1301 | s->irq = 7; |
1269 | break; | 1302 | break; |
1270 | case 0x278: | 1303 | case 0x278: |
1271 | superios[i].io = 0x278; | 1304 | s->io = 0x278; |
1272 | superios[i].irq = 5; | 1305 | s->irq = 5; |
1273 | } | 1306 | } |
1274 | d=(cr26 &0x0f); | 1307 | d = (cr26 & 0x0f); |
1275 | if((d==1) || (d==3)) | 1308 | if (d == 1 || d == 3) |
1276 | superios[i].dma= d; | 1309 | s->dma = d; |
1277 | else | 1310 | else |
1278 | superios[i].dma= PARPORT_DMA_NONE; | 1311 | s->dma = PARPORT_DMA_NONE; |
1279 | } | 1312 | } |
1280 | } | 1313 | } |
1281 | } | 1314 | } |
1282 | 1315 | ||
1283 | 1316 | ||
1284 | static void __devinit show_parconfig_winbond(int io, int key) | 1317 | static void __devinit show_parconfig_winbond(int io, int key) |
1285 | { | 1318 | { |
1286 | int cr30,cr60,cr61,cr70,cr74,crf0,i=0; | 1319 | int cr30, cr60, cr61, cr70, cr74, crf0; |
1320 | struct superio_struct *s; | ||
1287 | static const char *const modes[] = { | 1321 | static const char *const modes[] = { |
1288 | "Standard (SPP) and Bidirectional(PS/2)", /* 0 */ | 1322 | "Standard (SPP) and Bidirectional(PS/2)", /* 0 */ |
1289 | "EPP-1.9 and SPP", | 1323 | "EPP-1.9 and SPP", |
@@ -1296,110 +1330,134 @@ static void __devinit show_parconfig_winbond(int io, int key) | |||
1296 | static char *const irqtypes[] = { | 1330 | static char *const irqtypes[] = { |
1297 | "pulsed low, high-Z", | 1331 | "pulsed low, high-Z", |
1298 | "follows nACK" }; | 1332 | "follows nACK" }; |
1299 | 1333 | ||
1300 | /* The registers are called compatible-PnP because the | 1334 | /* The registers are called compatible-PnP because the |
1301 | register layout is modelled after ISA-PnP, the access | 1335 | register layout is modelled after ISA-PnP, the access |
1302 | method is just another ... */ | 1336 | method is just another ... */ |
1303 | outb(key,io); | 1337 | outb(key, io); |
1304 | outb(key,io); | 1338 | outb(key, io); |
1305 | outb(0x07,io); /* Register 7: Select Logical Device */ | 1339 | outb(0x07, io); /* Register 7: Select Logical Device */ |
1306 | outb(0x01,io+1); /* LD1 is Parallel Port */ | 1340 | outb(0x01, io + 1); /* LD1 is Parallel Port */ |
1307 | outb(0x30,io); | 1341 | outb(0x30, io); |
1308 | cr30=inb(io+1); | 1342 | cr30 = inb(io + 1); |
1309 | outb(0x60,io); | 1343 | outb(0x60, io); |
1310 | cr60=inb(io+1); | 1344 | cr60 = inb(io + 1); |
1311 | outb(0x61,io); | 1345 | outb(0x61, io); |
1312 | cr61=inb(io+1); | 1346 | cr61 = inb(io + 1); |
1313 | outb(0x70,io); | 1347 | outb(0x70, io); |
1314 | cr70=inb(io+1); | 1348 | cr70 = inb(io + 1); |
1315 | outb(0x74,io); | 1349 | outb(0x74, io); |
1316 | cr74=inb(io+1); | 1350 | cr74 = inb(io + 1); |
1317 | outb(0xf0,io); | 1351 | outb(0xf0, io); |
1318 | crf0=inb(io+1); | 1352 | crf0 = inb(io + 1); |
1319 | outb(0xaa,io); | 1353 | outb(0xaa, io); |
1320 | 1354 | ||
1321 | if (verbose_probing) { | 1355 | if (verbose_probing) { |
1322 | printk(KERN_INFO "Winbond LPT Config: cr_30=%02x 60,61=%02x%02x " | 1356 | printk(KERN_INFO |
1323 | "70=%02x 74=%02x, f0=%02x\n", cr30,cr60,cr61,cr70,cr74,crf0); | 1357 | "Winbond LPT Config: cr_30=%02x 60,61=%02x%02x 70=%02x 74=%02x, f0=%02x\n", |
1324 | printk(KERN_INFO "Winbond LPT Config: active=%s, io=0x%02x%02x irq=%d, ", | 1358 | cr30, cr60, cr61, cr70, cr74, crf0); |
1325 | (cr30 & 0x01) ? "yes":"no", cr60,cr61,cr70&0x0f ); | 1359 | printk(KERN_INFO "Winbond LPT Config: active=%s, io=0x%02x%02x irq=%d, ", |
1360 | (cr30 & 0x01) ? "yes" : "no", cr60, cr61, cr70 & 0x0f); | ||
1326 | if ((cr74 & 0x07) > 3) | 1361 | if ((cr74 & 0x07) > 3) |
1327 | printk("dma=none\n"); | 1362 | printk("dma=none\n"); |
1328 | else | 1363 | else |
1329 | printk("dma=%d\n",cr74 & 0x07); | 1364 | printk("dma=%d\n", cr74 & 0x07); |
1330 | printk(KERN_INFO "Winbond LPT Config: irqtype=%s, ECP fifo threshold=%d\n", | 1365 | printk(KERN_INFO |
1331 | irqtypes[crf0>>7], (crf0>>3)&0x0f); | 1366 | "Winbond LPT Config: irqtype=%s, ECP fifo threshold=%d\n", |
1332 | printk(KERN_INFO "Winbond LPT Config: Port mode=%s\n", modes[crf0 & 0x07]); | 1367 | irqtypes[crf0>>7], (crf0>>3)&0x0f); |
1368 | printk(KERN_INFO "Winbond LPT Config: Port mode=%s\n", | ||
1369 | modes[crf0 & 0x07]); | ||
1333 | } | 1370 | } |
1334 | 1371 | ||
1335 | if(cr30 & 0x01) { /* the settings can be interrogated later ... */ | 1372 | if (cr30 & 0x01) { /* the settings can be interrogated later ... */ |
1336 | while((superios[i].io!= 0) && (i<NR_SUPERIOS)) | 1373 | s = find_free_superio(); |
1337 | i++; | 1374 | if (s == NULL) |
1338 | if(i==NR_SUPERIOS) | ||
1339 | printk(KERN_INFO "Super-IO: too many chips!\n"); | 1375 | printk(KERN_INFO "Super-IO: too many chips!\n"); |
1340 | else { | 1376 | else { |
1341 | superios[i].io = (cr60<<8)|cr61; | 1377 | s->io = (cr60 << 8) | cr61; |
1342 | superios[i].irq = cr70&0x0f; | 1378 | s->irq = cr70 & 0x0f; |
1343 | superios[i].dma = (((cr74 & 0x07) > 3) ? | 1379 | s->dma = (((cr74 & 0x07) > 3) ? |
1344 | PARPORT_DMA_NONE : (cr74 & 0x07)); | 1380 | PARPORT_DMA_NONE : (cr74 & 0x07)); |
1345 | } | 1381 | } |
1346 | } | 1382 | } |
1347 | } | 1383 | } |
1348 | 1384 | ||
1349 | static void __devinit decode_winbond(int efer, int key, int devid, int devrev, int oldid) | 1385 | static void __devinit decode_winbond(int efer, int key, int devid, |
1386 | int devrev, int oldid) | ||
1350 | { | 1387 | { |
1351 | const char *type = "unknown"; | 1388 | const char *type = "unknown"; |
1352 | int id,progif=2; | 1389 | int id, progif = 2; |
1353 | 1390 | ||
1354 | if (devid == devrev) | 1391 | if (devid == devrev) |
1355 | /* simple heuristics, we happened to read some | 1392 | /* simple heuristics, we happened to read some |
1356 | non-winbond register */ | 1393 | non-winbond register */ |
1357 | return; | 1394 | return; |
1358 | 1395 | ||
1359 | id=(devid<<8) | devrev; | 1396 | id = (devid << 8) | devrev; |
1360 | 1397 | ||
1361 | /* Values are from public data sheets pdf files, I can just | 1398 | /* Values are from public data sheets pdf files, I can just |
1362 | confirm 83977TF is correct :-) */ | 1399 | confirm 83977TF is correct :-) */ |
1363 | if (id == 0x9771) type="83977F/AF"; | 1400 | if (id == 0x9771) |
1364 | else if (id == 0x9773) type="83977TF / SMSC 97w33x/97w34x"; | 1401 | type = "83977F/AF"; |
1365 | else if (id == 0x9774) type="83977ATF"; | 1402 | else if (id == 0x9773) |
1366 | else if ((id & ~0x0f) == 0x5270) type="83977CTF / SMSC 97w36x"; | 1403 | type = "83977TF / SMSC 97w33x/97w34x"; |
1367 | else if ((id & ~0x0f) == 0x52f0) type="83977EF / SMSC 97w35x"; | 1404 | else if (id == 0x9774) |
1368 | else if ((id & ~0x0f) == 0x5210) type="83627"; | 1405 | type = "83977ATF"; |
1369 | else if ((id & ~0x0f) == 0x6010) type="83697HF"; | 1406 | else if ((id & ~0x0f) == 0x5270) |
1370 | else if ((oldid &0x0f ) == 0x0a) { type="83877F"; progif=1;} | 1407 | type = "83977CTF / SMSC 97w36x"; |
1371 | else if ((oldid &0x0f ) == 0x0b) { type="83877AF"; progif=1;} | 1408 | else if ((id & ~0x0f) == 0x52f0) |
1372 | else if ((oldid &0x0f ) == 0x0c) { type="83877TF"; progif=1;} | 1409 | type = "83977EF / SMSC 97w35x"; |
1373 | else if ((oldid &0x0f ) == 0x0d) { type="83877ATF"; progif=1;} | 1410 | else if ((id & ~0x0f) == 0x5210) |
1374 | else progif=0; | 1411 | type = "83627"; |
1412 | else if ((id & ~0x0f) == 0x6010) | ||
1413 | type = "83697HF"; | ||
1414 | else if ((oldid & 0x0f) == 0x0a) { | ||
1415 | type = "83877F"; | ||
1416 | progif = 1; | ||
1417 | } else if ((oldid & 0x0f) == 0x0b) { | ||
1418 | type = "83877AF"; | ||
1419 | progif = 1; | ||
1420 | } else if ((oldid & 0x0f) == 0x0c) { | ||
1421 | type = "83877TF"; | ||
1422 | progif = 1; | ||
1423 | } else if ((oldid & 0x0f) == 0x0d) { | ||
1424 | type = "83877ATF"; | ||
1425 | progif = 1; | ||
1426 | } else | ||
1427 | progif = 0; | ||
1375 | 1428 | ||
1376 | if (verbose_probing) | 1429 | if (verbose_probing) |
1377 | printk(KERN_INFO "Winbond chip at EFER=0x%x key=0x%02x " | 1430 | printk(KERN_INFO "Winbond chip at EFER=0x%x key=0x%02x " |
1378 | "devid=%02x devrev=%02x oldid=%02x type=%s\n", | 1431 | "devid=%02x devrev=%02x oldid=%02x type=%s\n", |
1379 | efer, key, devid, devrev, oldid, type); | 1432 | efer, key, devid, devrev, oldid, type); |
1380 | 1433 | ||
1381 | if (progif == 2) | 1434 | if (progif == 2) |
1382 | show_parconfig_winbond(efer,key); | 1435 | show_parconfig_winbond(efer, key); |
1383 | } | 1436 | } |
1384 | 1437 | ||
1385 | static void __devinit decode_smsc(int efer, int key, int devid, int devrev) | 1438 | static void __devinit decode_smsc(int efer, int key, int devid, int devrev) |
1386 | { | 1439 | { |
1387 | const char *type = "unknown"; | 1440 | const char *type = "unknown"; |
1388 | void (*func)(int io, int key); | 1441 | void (*func)(int io, int key); |
1389 | int id; | 1442 | int id; |
1390 | 1443 | ||
1391 | if (devid == devrev) | 1444 | if (devid == devrev) |
1392 | /* simple heuristics, we happened to read some | 1445 | /* simple heuristics, we happened to read some |
1393 | non-smsc register */ | 1446 | non-smsc register */ |
1394 | return; | 1447 | return; |
1395 | 1448 | ||
1396 | func=NULL; | 1449 | func = NULL; |
1397 | id=(devid<<8) | devrev; | 1450 | id = (devid << 8) | devrev; |
1398 | 1451 | ||
1399 | if (id==0x0302) {type="37c669"; func=show_parconfig_smsc37c669;} | 1452 | if (id == 0x0302) { |
1400 | else if (id==0x6582) type="37c665IR"; | 1453 | type = "37c669"; |
1401 | else if (devid==0x65) type="37c665GT"; | 1454 | func = show_parconfig_smsc37c669; |
1402 | else if (devid==0x66) type="37c666GT"; | 1455 | } else if (id == 0x6582) |
1456 | type = "37c665IR"; | ||
1457 | else if (devid == 0x65) | ||
1458 | type = "37c665GT"; | ||
1459 | else if (devid == 0x66) | ||
1460 | type = "37c666GT"; | ||
1403 | 1461 | ||
1404 | if (verbose_probing) | 1462 | if (verbose_probing) |
1405 | printk(KERN_INFO "SMSC chip at EFER=0x%x " | 1463 | printk(KERN_INFO "SMSC chip at EFER=0x%x " |
@@ -1407,138 +1465,138 @@ static void __devinit decode_smsc(int efer, int key, int devid, int devrev) | |||
1407 | efer, key, devid, devrev, type); | 1465 | efer, key, devid, devrev, type); |
1408 | 1466 | ||
1409 | if (func) | 1467 | if (func) |
1410 | func(efer,key); | 1468 | func(efer, key); |
1411 | } | 1469 | } |
1412 | 1470 | ||
1413 | 1471 | ||
1414 | static void __devinit winbond_check(int io, int key) | 1472 | static void __devinit winbond_check(int io, int key) |
1415 | { | 1473 | { |
1416 | int devid,devrev,oldid,x_devid,x_devrev,x_oldid; | 1474 | int devid, devrev, oldid, x_devid, x_devrev, x_oldid; |
1417 | 1475 | ||
1418 | if (!request_region(io, 3, __func__)) | 1476 | if (!request_region(io, 3, __func__)) |
1419 | return; | 1477 | return; |
1420 | 1478 | ||
1421 | /* First probe without key */ | 1479 | /* First probe without key */ |
1422 | outb(0x20,io); | 1480 | outb(0x20, io); |
1423 | x_devid=inb(io+1); | 1481 | x_devid = inb(io + 1); |
1424 | outb(0x21,io); | 1482 | outb(0x21, io); |
1425 | x_devrev=inb(io+1); | 1483 | x_devrev = inb(io + 1); |
1426 | outb(0x09,io); | 1484 | outb(0x09, io); |
1427 | x_oldid=inb(io+1); | 1485 | x_oldid = inb(io + 1); |
1428 | 1486 | ||
1429 | outb(key,io); | 1487 | outb(key, io); |
1430 | outb(key,io); /* Write Magic Sequence to EFER, extended | 1488 | outb(key, io); /* Write Magic Sequence to EFER, extended |
1431 | funtion enable register */ | 1489 | funtion enable register */ |
1432 | outb(0x20,io); /* Write EFIR, extended function index register */ | 1490 | outb(0x20, io); /* Write EFIR, extended function index register */ |
1433 | devid=inb(io+1); /* Read EFDR, extended function data register */ | 1491 | devid = inb(io + 1); /* Read EFDR, extended function data register */ |
1434 | outb(0x21,io); | 1492 | outb(0x21, io); |
1435 | devrev=inb(io+1); | 1493 | devrev = inb(io + 1); |
1436 | outb(0x09,io); | 1494 | outb(0x09, io); |
1437 | oldid=inb(io+1); | 1495 | oldid = inb(io + 1); |
1438 | outb(0xaa,io); /* Magic Seal */ | 1496 | outb(0xaa, io); /* Magic Seal */ |
1439 | 1497 | ||
1440 | if ((x_devid == devid) && (x_devrev == devrev) && (x_oldid == oldid)) | 1498 | if ((x_devid == devid) && (x_devrev == devrev) && (x_oldid == oldid)) |
1441 | goto out; /* protection against false positives */ | 1499 | goto out; /* protection against false positives */ |
1442 | 1500 | ||
1443 | decode_winbond(io,key,devid,devrev,oldid); | 1501 | decode_winbond(io, key, devid, devrev, oldid); |
1444 | out: | 1502 | out: |
1445 | release_region(io, 3); | 1503 | release_region(io, 3); |
1446 | } | 1504 | } |
1447 | 1505 | ||
1448 | static void __devinit winbond_check2(int io,int key) | 1506 | static void __devinit winbond_check2(int io, int key) |
1449 | { | 1507 | { |
1450 | int devid,devrev,oldid,x_devid,x_devrev,x_oldid; | 1508 | int devid, devrev, oldid, x_devid, x_devrev, x_oldid; |
1451 | 1509 | ||
1452 | if (!request_region(io, 3, __func__)) | 1510 | if (!request_region(io, 3, __func__)) |
1453 | return; | 1511 | return; |
1454 | 1512 | ||
1455 | /* First probe without the key */ | 1513 | /* First probe without the key */ |
1456 | outb(0x20,io+2); | 1514 | outb(0x20, io + 2); |
1457 | x_devid=inb(io+2); | 1515 | x_devid = inb(io + 2); |
1458 | outb(0x21,io+1); | 1516 | outb(0x21, io + 1); |
1459 | x_devrev=inb(io+2); | 1517 | x_devrev = inb(io + 2); |
1460 | outb(0x09,io+1); | 1518 | outb(0x09, io + 1); |
1461 | x_oldid=inb(io+2); | 1519 | x_oldid = inb(io + 2); |
1462 | 1520 | ||
1463 | outb(key,io); /* Write Magic Byte to EFER, extended | 1521 | outb(key, io); /* Write Magic Byte to EFER, extended |
1464 | funtion enable register */ | 1522 | funtion enable register */ |
1465 | outb(0x20,io+2); /* Write EFIR, extended function index register */ | 1523 | outb(0x20, io + 2); /* Write EFIR, extended function index register */ |
1466 | devid=inb(io+2); /* Read EFDR, extended function data register */ | 1524 | devid = inb(io + 2); /* Read EFDR, extended function data register */ |
1467 | outb(0x21,io+1); | 1525 | outb(0x21, io + 1); |
1468 | devrev=inb(io+2); | 1526 | devrev = inb(io + 2); |
1469 | outb(0x09,io+1); | 1527 | outb(0x09, io + 1); |
1470 | oldid=inb(io+2); | 1528 | oldid = inb(io + 2); |
1471 | outb(0xaa,io); /* Magic Seal */ | 1529 | outb(0xaa, io); /* Magic Seal */ |
1472 | 1530 | ||
1473 | if ((x_devid == devid) && (x_devrev == devrev) && (x_oldid == oldid)) | 1531 | if (x_devid == devid && x_devrev == devrev && x_oldid == oldid) |
1474 | goto out; /* protection against false positives */ | 1532 | goto out; /* protection against false positives */ |
1475 | 1533 | ||
1476 | decode_winbond(io,key,devid,devrev,oldid); | 1534 | decode_winbond(io, key, devid, devrev, oldid); |
1477 | out: | 1535 | out: |
1478 | release_region(io, 3); | 1536 | release_region(io, 3); |
1479 | } | 1537 | } |
1480 | 1538 | ||
1481 | static void __devinit smsc_check(int io, int key) | 1539 | static void __devinit smsc_check(int io, int key) |
1482 | { | 1540 | { |
1483 | int id,rev,oldid,oldrev,x_id,x_rev,x_oldid,x_oldrev; | 1541 | int id, rev, oldid, oldrev, x_id, x_rev, x_oldid, x_oldrev; |
1484 | 1542 | ||
1485 | if (!request_region(io, 3, __func__)) | 1543 | if (!request_region(io, 3, __func__)) |
1486 | return; | 1544 | return; |
1487 | 1545 | ||
1488 | /* First probe without the key */ | 1546 | /* First probe without the key */ |
1489 | outb(0x0d,io); | 1547 | outb(0x0d, io); |
1490 | x_oldid=inb(io+1); | 1548 | x_oldid = inb(io + 1); |
1491 | outb(0x0e,io); | 1549 | outb(0x0e, io); |
1492 | x_oldrev=inb(io+1); | 1550 | x_oldrev = inb(io + 1); |
1493 | outb(0x20,io); | 1551 | outb(0x20, io); |
1494 | x_id=inb(io+1); | 1552 | x_id = inb(io + 1); |
1495 | outb(0x21,io); | 1553 | outb(0x21, io); |
1496 | x_rev=inb(io+1); | 1554 | x_rev = inb(io + 1); |
1497 | 1555 | ||
1498 | outb(key,io); | 1556 | outb(key, io); |
1499 | outb(key,io); /* Write Magic Sequence to EFER, extended | 1557 | outb(key, io); /* Write Magic Sequence to EFER, extended |
1500 | funtion enable register */ | 1558 | funtion enable register */ |
1501 | outb(0x0d,io); /* Write EFIR, extended function index register */ | 1559 | outb(0x0d, io); /* Write EFIR, extended function index register */ |
1502 | oldid=inb(io+1); /* Read EFDR, extended function data register */ | 1560 | oldid = inb(io + 1); /* Read EFDR, extended function data register */ |
1503 | outb(0x0e,io); | 1561 | outb(0x0e, io); |
1504 | oldrev=inb(io+1); | 1562 | oldrev = inb(io + 1); |
1505 | outb(0x20,io); | 1563 | outb(0x20, io); |
1506 | id=inb(io+1); | 1564 | id = inb(io + 1); |
1507 | outb(0x21,io); | 1565 | outb(0x21, io); |
1508 | rev=inb(io+1); | 1566 | rev = inb(io + 1); |
1509 | outb(0xaa,io); /* Magic Seal */ | 1567 | outb(0xaa, io); /* Magic Seal */ |
1510 | 1568 | ||
1511 | if ((x_id == id) && (x_oldrev == oldrev) && | 1569 | if (x_id == id && x_oldrev == oldrev && |
1512 | (x_oldid == oldid) && (x_rev == rev)) | 1570 | x_oldid == oldid && x_rev == rev) |
1513 | goto out; /* protection against false positives */ | 1571 | goto out; /* protection against false positives */ |
1514 | 1572 | ||
1515 | decode_smsc(io,key,oldid,oldrev); | 1573 | decode_smsc(io, key, oldid, oldrev); |
1516 | out: | 1574 | out: |
1517 | release_region(io, 3); | 1575 | release_region(io, 3); |
1518 | } | 1576 | } |
1519 | 1577 | ||
1520 | 1578 | ||
1521 | static void __devinit detect_and_report_winbond (void) | 1579 | static void __devinit detect_and_report_winbond(void) |
1522 | { | 1580 | { |
1523 | if (verbose_probing) | 1581 | if (verbose_probing) |
1524 | printk(KERN_DEBUG "Winbond Super-IO detection, now testing ports 3F0,370,250,4E,2E ...\n"); | 1582 | printk(KERN_DEBUG "Winbond Super-IO detection, now testing ports 3F0,370,250,4E,2E ...\n"); |
1525 | winbond_check(0x3f0,0x87); | 1583 | winbond_check(0x3f0, 0x87); |
1526 | winbond_check(0x370,0x87); | 1584 | winbond_check(0x370, 0x87); |
1527 | winbond_check(0x2e ,0x87); | 1585 | winbond_check(0x2e , 0x87); |
1528 | winbond_check(0x4e ,0x87); | 1586 | winbond_check(0x4e , 0x87); |
1529 | winbond_check(0x3f0,0x86); | 1587 | winbond_check(0x3f0, 0x86); |
1530 | winbond_check2(0x250,0x88); | 1588 | winbond_check2(0x250, 0x88); |
1531 | winbond_check2(0x250,0x89); | 1589 | winbond_check2(0x250, 0x89); |
1532 | } | 1590 | } |
1533 | 1591 | ||
1534 | static void __devinit detect_and_report_smsc (void) | 1592 | static void __devinit detect_and_report_smsc(void) |
1535 | { | 1593 | { |
1536 | if (verbose_probing) | 1594 | if (verbose_probing) |
1537 | printk(KERN_DEBUG "SMSC Super-IO detection, now testing Ports 2F0, 370 ...\n"); | 1595 | printk(KERN_DEBUG "SMSC Super-IO detection, now testing Ports 2F0, 370 ...\n"); |
1538 | smsc_check(0x3f0,0x55); | 1596 | smsc_check(0x3f0, 0x55); |
1539 | smsc_check(0x370,0x55); | 1597 | smsc_check(0x370, 0x55); |
1540 | smsc_check(0x3f0,0x44); | 1598 | smsc_check(0x3f0, 0x44); |
1541 | smsc_check(0x370,0x44); | 1599 | smsc_check(0x370, 0x44); |
1542 | } | 1600 | } |
1543 | 1601 | ||
1544 | static void __devinit detect_and_report_it87(void) | 1602 | static void __devinit detect_and_report_it87(void) |
@@ -1573,34 +1631,39 @@ static void __devinit detect_and_report_it87(void) | |||
1573 | } | 1631 | } |
1574 | #endif /* CONFIG_PARPORT_PC_SUPERIO */ | 1632 | #endif /* CONFIG_PARPORT_PC_SUPERIO */ |
1575 | 1633 | ||
1576 | static int get_superio_dma (struct parport *p) | 1634 | static struct superio_struct *find_superio(struct parport *p) |
1577 | { | 1635 | { |
1578 | int i=0; | 1636 | int i; |
1579 | while( (superios[i].io != p->base) && (i<NR_SUPERIOS)) | 1637 | for (i = 0; i < NR_SUPERIOS; i++) |
1580 | i++; | 1638 | if (superios[i].io != p->base) |
1581 | if (i!=NR_SUPERIOS) | 1639 | return &superios[i]; |
1582 | return superios[i].dma; | 1640 | return NULL; |
1641 | } | ||
1642 | |||
1643 | static int get_superio_dma(struct parport *p) | ||
1644 | { | ||
1645 | struct superio_struct *s = find_superio(p); | ||
1646 | if (s) | ||
1647 | return s->dma; | ||
1583 | return PARPORT_DMA_NONE; | 1648 | return PARPORT_DMA_NONE; |
1584 | } | 1649 | } |
1585 | 1650 | ||
1586 | static int get_superio_irq (struct parport *p) | 1651 | static int get_superio_irq(struct parport *p) |
1587 | { | 1652 | { |
1588 | int i=0; | 1653 | struct superio_struct *s = find_superio(p); |
1589 | while( (superios[i].io != p->base) && (i<NR_SUPERIOS)) | 1654 | if (s) |
1590 | i++; | 1655 | return s->irq; |
1591 | if (i!=NR_SUPERIOS) | 1656 | return PARPORT_IRQ_NONE; |
1592 | return superios[i].irq; | ||
1593 | return PARPORT_IRQ_NONE; | ||
1594 | } | 1657 | } |
1595 | 1658 | ||
1596 | 1659 | ||
1597 | /* --- Mode detection ------------------------------------- */ | 1660 | /* --- Mode detection ------------------------------------- */ |
1598 | 1661 | ||
1599 | /* | 1662 | /* |
1600 | * Checks for port existence, all ports support SPP MODE | 1663 | * Checks for port existence, all ports support SPP MODE |
1601 | * Returns: | 1664 | * Returns: |
1602 | * 0 : No parallel port at this address | 1665 | * 0 : No parallel port at this address |
1603 | * PARPORT_MODE_PCSPP : SPP port detected | 1666 | * PARPORT_MODE_PCSPP : SPP port detected |
1604 | * (if the user specified an ioport himself, | 1667 | * (if the user specified an ioport himself, |
1605 | * this shall always be the case!) | 1668 | * this shall always be the case!) |
1606 | * | 1669 | * |
@@ -1610,7 +1673,7 @@ static int parport_SPP_supported(struct parport *pb) | |||
1610 | unsigned char r, w; | 1673 | unsigned char r, w; |
1611 | 1674 | ||
1612 | /* | 1675 | /* |
1613 | * first clear an eventually pending EPP timeout | 1676 | * first clear an eventually pending EPP timeout |
1614 | * I (sailer@ife.ee.ethz.ch) have an SMSC chipset | 1677 | * I (sailer@ife.ee.ethz.ch) have an SMSC chipset |
1615 | * that does not even respond to SPP cycles if an EPP | 1678 | * that does not even respond to SPP cycles if an EPP |
1616 | * timeout is pending | 1679 | * timeout is pending |
@@ -1619,19 +1682,19 @@ static int parport_SPP_supported(struct parport *pb) | |||
1619 | 1682 | ||
1620 | /* Do a simple read-write test to make sure the port exists. */ | 1683 | /* Do a simple read-write test to make sure the port exists. */ |
1621 | w = 0xc; | 1684 | w = 0xc; |
1622 | outb (w, CONTROL (pb)); | 1685 | outb(w, CONTROL(pb)); |
1623 | 1686 | ||
1624 | /* Is there a control register that we can read from? Some | 1687 | /* Is there a control register that we can read from? Some |
1625 | * ports don't allow reads, so read_control just returns a | 1688 | * ports don't allow reads, so read_control just returns a |
1626 | * software copy. Some ports _do_ allow reads, so bypass the | 1689 | * software copy. Some ports _do_ allow reads, so bypass the |
1627 | * software copy here. In addition, some bits aren't | 1690 | * software copy here. In addition, some bits aren't |
1628 | * writable. */ | 1691 | * writable. */ |
1629 | r = inb (CONTROL (pb)); | 1692 | r = inb(CONTROL(pb)); |
1630 | if ((r & 0xf) == w) { | 1693 | if ((r & 0xf) == w) { |
1631 | w = 0xe; | 1694 | w = 0xe; |
1632 | outb (w, CONTROL (pb)); | 1695 | outb(w, CONTROL(pb)); |
1633 | r = inb (CONTROL (pb)); | 1696 | r = inb(CONTROL(pb)); |
1634 | outb (0xc, CONTROL (pb)); | 1697 | outb(0xc, CONTROL(pb)); |
1635 | if ((r & 0xf) == w) | 1698 | if ((r & 0xf) == w) |
1636 | return PARPORT_MODE_PCSPP; | 1699 | return PARPORT_MODE_PCSPP; |
1637 | } | 1700 | } |
@@ -1639,18 +1702,18 @@ static int parport_SPP_supported(struct parport *pb) | |||
1639 | if (user_specified) | 1702 | if (user_specified) |
1640 | /* That didn't work, but the user thinks there's a | 1703 | /* That didn't work, but the user thinks there's a |
1641 | * port here. */ | 1704 | * port here. */ |
1642 | printk (KERN_INFO "parport 0x%lx (WARNING): CTR: " | 1705 | printk(KERN_INFO "parport 0x%lx (WARNING): CTR: " |
1643 | "wrote 0x%02x, read 0x%02x\n", pb->base, w, r); | 1706 | "wrote 0x%02x, read 0x%02x\n", pb->base, w, r); |
1644 | 1707 | ||
1645 | /* Try the data register. The data lines aren't tri-stated at | 1708 | /* Try the data register. The data lines aren't tri-stated at |
1646 | * this stage, so we expect back what we wrote. */ | 1709 | * this stage, so we expect back what we wrote. */ |
1647 | w = 0xaa; | 1710 | w = 0xaa; |
1648 | parport_pc_write_data (pb, w); | 1711 | parport_pc_write_data(pb, w); |
1649 | r = parport_pc_read_data (pb); | 1712 | r = parport_pc_read_data(pb); |
1650 | if (r == w) { | 1713 | if (r == w) { |
1651 | w = 0x55; | 1714 | w = 0x55; |
1652 | parport_pc_write_data (pb, w); | 1715 | parport_pc_write_data(pb, w); |
1653 | r = parport_pc_read_data (pb); | 1716 | r = parport_pc_read_data(pb); |
1654 | if (r == w) | 1717 | if (r == w) |
1655 | return PARPORT_MODE_PCSPP; | 1718 | return PARPORT_MODE_PCSPP; |
1656 | } | 1719 | } |
@@ -1658,9 +1721,9 @@ static int parport_SPP_supported(struct parport *pb) | |||
1658 | if (user_specified) { | 1721 | if (user_specified) { |
1659 | /* Didn't work, but the user is convinced this is the | 1722 | /* Didn't work, but the user is convinced this is the |
1660 | * place. */ | 1723 | * place. */ |
1661 | printk (KERN_INFO "parport 0x%lx (WARNING): DATA: " | 1724 | printk(KERN_INFO "parport 0x%lx (WARNING): DATA: " |
1662 | "wrote 0x%02x, read 0x%02x\n", pb->base, w, r); | 1725 | "wrote 0x%02x, read 0x%02x\n", pb->base, w, r); |
1663 | printk (KERN_INFO "parport 0x%lx: You gave this address, " | 1726 | printk(KERN_INFO "parport 0x%lx: You gave this address, " |
1664 | "but there is probably no parallel port there!\n", | 1727 | "but there is probably no parallel port there!\n", |
1665 | pb->base); | 1728 | pb->base); |
1666 | } | 1729 | } |
@@ -1691,33 +1754,33 @@ static int parport_ECR_present(struct parport *pb) | |||
1691 | struct parport_pc_private *priv = pb->private_data; | 1754 | struct parport_pc_private *priv = pb->private_data; |
1692 | unsigned char r = 0xc; | 1755 | unsigned char r = 0xc; |
1693 | 1756 | ||
1694 | outb (r, CONTROL (pb)); | 1757 | outb(r, CONTROL(pb)); |
1695 | if ((inb (ECONTROL (pb)) & 0x3) == (r & 0x3)) { | 1758 | if ((inb(ECONTROL(pb)) & 0x3) == (r & 0x3)) { |
1696 | outb (r ^ 0x2, CONTROL (pb)); /* Toggle bit 1 */ | 1759 | outb(r ^ 0x2, CONTROL(pb)); /* Toggle bit 1 */ |
1697 | 1760 | ||
1698 | r = inb (CONTROL (pb)); | 1761 | r = inb(CONTROL(pb)); |
1699 | if ((inb (ECONTROL (pb)) & 0x2) == (r & 0x2)) | 1762 | if ((inb(ECONTROL(pb)) & 0x2) == (r & 0x2)) |
1700 | goto no_reg; /* Sure that no ECR register exists */ | 1763 | goto no_reg; /* Sure that no ECR register exists */ |
1701 | } | 1764 | } |
1702 | 1765 | ||
1703 | if ((inb (ECONTROL (pb)) & 0x3 ) != 0x1) | 1766 | if ((inb(ECONTROL(pb)) & 0x3) != 0x1) |
1704 | goto no_reg; | 1767 | goto no_reg; |
1705 | 1768 | ||
1706 | ECR_WRITE (pb, 0x34); | 1769 | ECR_WRITE(pb, 0x34); |
1707 | if (inb (ECONTROL (pb)) != 0x35) | 1770 | if (inb(ECONTROL(pb)) != 0x35) |
1708 | goto no_reg; | 1771 | goto no_reg; |
1709 | 1772 | ||
1710 | priv->ecr = 1; | 1773 | priv->ecr = 1; |
1711 | outb (0xc, CONTROL (pb)); | 1774 | outb(0xc, CONTROL(pb)); |
1712 | 1775 | ||
1713 | /* Go to mode 000 */ | 1776 | /* Go to mode 000 */ |
1714 | frob_set_mode (pb, ECR_SPP); | 1777 | frob_set_mode(pb, ECR_SPP); |
1715 | 1778 | ||
1716 | return 1; | 1779 | return 1; |
1717 | 1780 | ||
1718 | no_reg: | 1781 | no_reg: |
1719 | outb (0xc, CONTROL (pb)); | 1782 | outb(0xc, CONTROL(pb)); |
1720 | return 0; | 1783 | return 0; |
1721 | } | 1784 | } |
1722 | 1785 | ||
1723 | #ifdef CONFIG_PARPORT_1284 | 1786 | #ifdef CONFIG_PARPORT_1284 |
@@ -1727,7 +1790,7 @@ static int parport_ECR_present(struct parport *pb) | |||
1727 | * allows us to read data from the data lines. In theory we would get back | 1790 | * allows us to read data from the data lines. In theory we would get back |
1728 | * 0xff but any peripheral attached to the port may drag some or all of the | 1791 | * 0xff but any peripheral attached to the port may drag some or all of the |
1729 | * lines down to zero. So if we get back anything that isn't the contents | 1792 | * lines down to zero. So if we get back anything that isn't the contents |
1730 | * of the data register we deem PS/2 support to be present. | 1793 | * of the data register we deem PS/2 support to be present. |
1731 | * | 1794 | * |
1732 | * Some SPP ports have "half PS/2" ability - you can't turn off the line | 1795 | * Some SPP ports have "half PS/2" ability - you can't turn off the line |
1733 | * drivers, but an external peripheral with sufficiently beefy drivers of | 1796 | * drivers, but an external peripheral with sufficiently beefy drivers of |
@@ -1735,26 +1798,28 @@ static int parport_ECR_present(struct parport *pb) | |||
1735 | * where they can then be read back as normal. Ports with this property | 1798 | * where they can then be read back as normal. Ports with this property |
1736 | * and the right type of device attached are likely to fail the SPP test, | 1799 | * and the right type of device attached are likely to fail the SPP test, |
1737 | * (as they will appear to have stuck bits) and so the fact that they might | 1800 | * (as they will appear to have stuck bits) and so the fact that they might |
1738 | * be misdetected here is rather academic. | 1801 | * be misdetected here is rather academic. |
1739 | */ | 1802 | */ |
1740 | 1803 | ||
1741 | static int parport_PS2_supported(struct parport *pb) | 1804 | static int parport_PS2_supported(struct parport *pb) |
1742 | { | 1805 | { |
1743 | int ok = 0; | 1806 | int ok = 0; |
1744 | 1807 | ||
1745 | clear_epp_timeout(pb); | 1808 | clear_epp_timeout(pb); |
1746 | 1809 | ||
1747 | /* try to tri-state the buffer */ | 1810 | /* try to tri-state the buffer */ |
1748 | parport_pc_data_reverse (pb); | 1811 | parport_pc_data_reverse(pb); |
1749 | 1812 | ||
1750 | parport_pc_write_data(pb, 0x55); | 1813 | parport_pc_write_data(pb, 0x55); |
1751 | if (parport_pc_read_data(pb) != 0x55) ok++; | 1814 | if (parport_pc_read_data(pb) != 0x55) |
1815 | ok++; | ||
1752 | 1816 | ||
1753 | parport_pc_write_data(pb, 0xaa); | 1817 | parport_pc_write_data(pb, 0xaa); |
1754 | if (parport_pc_read_data(pb) != 0xaa) ok++; | 1818 | if (parport_pc_read_data(pb) != 0xaa) |
1819 | ok++; | ||
1755 | 1820 | ||
1756 | /* cancel input mode */ | 1821 | /* cancel input mode */ |
1757 | parport_pc_data_forward (pb); | 1822 | parport_pc_data_forward(pb); |
1758 | 1823 | ||
1759 | if (ok) { | 1824 | if (ok) { |
1760 | pb->modes |= PARPORT_MODE_TRISTATE; | 1825 | pb->modes |= PARPORT_MODE_TRISTATE; |
@@ -1773,68 +1838,68 @@ static int parport_ECP_supported(struct parport *pb) | |||
1773 | int config, configb; | 1838 | int config, configb; |
1774 | int pword; | 1839 | int pword; |
1775 | struct parport_pc_private *priv = pb->private_data; | 1840 | struct parport_pc_private *priv = pb->private_data; |
1776 | /* Translate ECP intrLine to ISA irq value */ | 1841 | /* Translate ECP intrLine to ISA irq value */ |
1777 | static const int intrline[]= { 0, 7, 9, 10, 11, 14, 15, 5 }; | 1842 | static const int intrline[] = { 0, 7, 9, 10, 11, 14, 15, 5 }; |
1778 | 1843 | ||
1779 | /* If there is no ECR, we have no hope of supporting ECP. */ | 1844 | /* If there is no ECR, we have no hope of supporting ECP. */ |
1780 | if (!priv->ecr) | 1845 | if (!priv->ecr) |
1781 | return 0; | 1846 | return 0; |
1782 | 1847 | ||
1783 | /* Find out FIFO depth */ | 1848 | /* Find out FIFO depth */ |
1784 | ECR_WRITE (pb, ECR_SPP << 5); /* Reset FIFO */ | 1849 | ECR_WRITE(pb, ECR_SPP << 5); /* Reset FIFO */ |
1785 | ECR_WRITE (pb, ECR_TST << 5); /* TEST FIFO */ | 1850 | ECR_WRITE(pb, ECR_TST << 5); /* TEST FIFO */ |
1786 | for (i=0; i < 1024 && !(inb (ECONTROL (pb)) & 0x02); i++) | 1851 | for (i = 0; i < 1024 && !(inb(ECONTROL(pb)) & 0x02); i++) |
1787 | outb (0xaa, FIFO (pb)); | 1852 | outb(0xaa, FIFO(pb)); |
1788 | 1853 | ||
1789 | /* | 1854 | /* |
1790 | * Using LGS chipset it uses ECR register, but | 1855 | * Using LGS chipset it uses ECR register, but |
1791 | * it doesn't support ECP or FIFO MODE | 1856 | * it doesn't support ECP or FIFO MODE |
1792 | */ | 1857 | */ |
1793 | if (i == 1024) { | 1858 | if (i == 1024) { |
1794 | ECR_WRITE (pb, ECR_SPP << 5); | 1859 | ECR_WRITE(pb, ECR_SPP << 5); |
1795 | return 0; | 1860 | return 0; |
1796 | } | 1861 | } |
1797 | 1862 | ||
1798 | priv->fifo_depth = i; | 1863 | priv->fifo_depth = i; |
1799 | if (verbose_probing) | 1864 | if (verbose_probing) |
1800 | printk (KERN_DEBUG "0x%lx: FIFO is %d bytes\n", pb->base, i); | 1865 | printk(KERN_DEBUG "0x%lx: FIFO is %d bytes\n", pb->base, i); |
1801 | 1866 | ||
1802 | /* Find out writeIntrThreshold */ | 1867 | /* Find out writeIntrThreshold */ |
1803 | frob_econtrol (pb, 1<<2, 1<<2); | 1868 | frob_econtrol(pb, 1<<2, 1<<2); |
1804 | frob_econtrol (pb, 1<<2, 0); | 1869 | frob_econtrol(pb, 1<<2, 0); |
1805 | for (i = 1; i <= priv->fifo_depth; i++) { | 1870 | for (i = 1; i <= priv->fifo_depth; i++) { |
1806 | inb (FIFO (pb)); | 1871 | inb(FIFO(pb)); |
1807 | udelay (50); | 1872 | udelay(50); |
1808 | if (inb (ECONTROL (pb)) & (1<<2)) | 1873 | if (inb(ECONTROL(pb)) & (1<<2)) |
1809 | break; | 1874 | break; |
1810 | } | 1875 | } |
1811 | 1876 | ||
1812 | if (i <= priv->fifo_depth) { | 1877 | if (i <= priv->fifo_depth) { |
1813 | if (verbose_probing) | 1878 | if (verbose_probing) |
1814 | printk (KERN_DEBUG "0x%lx: writeIntrThreshold is %d\n", | 1879 | printk(KERN_DEBUG "0x%lx: writeIntrThreshold is %d\n", |
1815 | pb->base, i); | 1880 | pb->base, i); |
1816 | } else | 1881 | } else |
1817 | /* Number of bytes we know we can write if we get an | 1882 | /* Number of bytes we know we can write if we get an |
1818 | interrupt. */ | 1883 | interrupt. */ |
1819 | i = 0; | 1884 | i = 0; |
1820 | 1885 | ||
1821 | priv->writeIntrThreshold = i; | 1886 | priv->writeIntrThreshold = i; |
1822 | 1887 | ||
1823 | /* Find out readIntrThreshold */ | 1888 | /* Find out readIntrThreshold */ |
1824 | frob_set_mode (pb, ECR_PS2); /* Reset FIFO and enable PS2 */ | 1889 | frob_set_mode(pb, ECR_PS2); /* Reset FIFO and enable PS2 */ |
1825 | parport_pc_data_reverse (pb); /* Must be in PS2 mode */ | 1890 | parport_pc_data_reverse(pb); /* Must be in PS2 mode */ |
1826 | frob_set_mode (pb, ECR_TST); /* Test FIFO */ | 1891 | frob_set_mode(pb, ECR_TST); /* Test FIFO */ |
1827 | frob_econtrol (pb, 1<<2, 1<<2); | 1892 | frob_econtrol(pb, 1<<2, 1<<2); |
1828 | frob_econtrol (pb, 1<<2, 0); | 1893 | frob_econtrol(pb, 1<<2, 0); |
1829 | for (i = 1; i <= priv->fifo_depth; i++) { | 1894 | for (i = 1; i <= priv->fifo_depth; i++) { |
1830 | outb (0xaa, FIFO (pb)); | 1895 | outb(0xaa, FIFO(pb)); |
1831 | if (inb (ECONTROL (pb)) & (1<<2)) | 1896 | if (inb(ECONTROL(pb)) & (1<<2)) |
1832 | break; | 1897 | break; |
1833 | } | 1898 | } |
1834 | 1899 | ||
1835 | if (i <= priv->fifo_depth) { | 1900 | if (i <= priv->fifo_depth) { |
1836 | if (verbose_probing) | 1901 | if (verbose_probing) |
1837 | printk (KERN_INFO "0x%lx: readIntrThreshold is %d\n", | 1902 | printk(KERN_INFO "0x%lx: readIntrThreshold is %d\n", |
1838 | pb->base, i); | 1903 | pb->base, i); |
1839 | } else | 1904 | } else |
1840 | /* Number of bytes we can read if we get an interrupt. */ | 1905 | /* Number of bytes we can read if we get an interrupt. */ |
@@ -1842,23 +1907,23 @@ static int parport_ECP_supported(struct parport *pb) | |||
1842 | 1907 | ||
1843 | priv->readIntrThreshold = i; | 1908 | priv->readIntrThreshold = i; |
1844 | 1909 | ||
1845 | ECR_WRITE (pb, ECR_SPP << 5); /* Reset FIFO */ | 1910 | ECR_WRITE(pb, ECR_SPP << 5); /* Reset FIFO */ |
1846 | ECR_WRITE (pb, 0xf4); /* Configuration mode */ | 1911 | ECR_WRITE(pb, 0xf4); /* Configuration mode */ |
1847 | config = inb (CONFIGA (pb)); | 1912 | config = inb(CONFIGA(pb)); |
1848 | pword = (config >> 4) & 0x7; | 1913 | pword = (config >> 4) & 0x7; |
1849 | switch (pword) { | 1914 | switch (pword) { |
1850 | case 0: | 1915 | case 0: |
1851 | pword = 2; | 1916 | pword = 2; |
1852 | printk (KERN_WARNING "0x%lx: Unsupported pword size!\n", | 1917 | printk(KERN_WARNING "0x%lx: Unsupported pword size!\n", |
1853 | pb->base); | 1918 | pb->base); |
1854 | break; | 1919 | break; |
1855 | case 2: | 1920 | case 2: |
1856 | pword = 4; | 1921 | pword = 4; |
1857 | printk (KERN_WARNING "0x%lx: Unsupported pword size!\n", | 1922 | printk(KERN_WARNING "0x%lx: Unsupported pword size!\n", |
1858 | pb->base); | 1923 | pb->base); |
1859 | break; | 1924 | break; |
1860 | default: | 1925 | default: |
1861 | printk (KERN_WARNING "0x%lx: Unknown implementation ID\n", | 1926 | printk(KERN_WARNING "0x%lx: Unknown implementation ID\n", |
1862 | pb->base); | 1927 | pb->base); |
1863 | /* Assume 1 */ | 1928 | /* Assume 1 */ |
1864 | case 1: | 1929 | case 1: |
@@ -1867,28 +1932,29 @@ static int parport_ECP_supported(struct parport *pb) | |||
1867 | priv->pword = pword; | 1932 | priv->pword = pword; |
1868 | 1933 | ||
1869 | if (verbose_probing) { | 1934 | if (verbose_probing) { |
1870 | printk (KERN_DEBUG "0x%lx: PWord is %d bits\n", pb->base, 8 * pword); | 1935 | printk(KERN_DEBUG "0x%lx: PWord is %d bits\n", |
1871 | 1936 | pb->base, 8 * pword); | |
1872 | printk (KERN_DEBUG "0x%lx: Interrupts are ISA-%s\n", pb->base, | 1937 | |
1938 | printk(KERN_DEBUG "0x%lx: Interrupts are ISA-%s\n", pb->base, | ||
1873 | config & 0x80 ? "Level" : "Pulses"); | 1939 | config & 0x80 ? "Level" : "Pulses"); |
1874 | 1940 | ||
1875 | configb = inb (CONFIGB (pb)); | 1941 | configb = inb(CONFIGB(pb)); |
1876 | printk (KERN_DEBUG "0x%lx: ECP port cfgA=0x%02x cfgB=0x%02x\n", | 1942 | printk(KERN_DEBUG "0x%lx: ECP port cfgA=0x%02x cfgB=0x%02x\n", |
1877 | pb->base, config, configb); | 1943 | pb->base, config, configb); |
1878 | printk (KERN_DEBUG "0x%lx: ECP settings irq=", pb->base); | 1944 | printk(KERN_DEBUG "0x%lx: ECP settings irq=", pb->base); |
1879 | if ((configb >>3) & 0x07) | 1945 | if ((configb >> 3) & 0x07) |
1880 | printk("%d",intrline[(configb >>3) & 0x07]); | 1946 | printk("%d", intrline[(configb >> 3) & 0x07]); |
1881 | else | 1947 | else |
1882 | printk("<none or set by other means>"); | 1948 | printk("<none or set by other means>"); |
1883 | printk (" dma="); | 1949 | printk(" dma="); |
1884 | if( (configb & 0x03 ) == 0x00) | 1950 | if ((configb & 0x03) == 0x00) |
1885 | printk("<none or set by other means>\n"); | 1951 | printk("<none or set by other means>\n"); |
1886 | else | 1952 | else |
1887 | printk("%d\n",configb & 0x07); | 1953 | printk("%d\n", configb & 0x07); |
1888 | } | 1954 | } |
1889 | 1955 | ||
1890 | /* Go back to mode 000 */ | 1956 | /* Go back to mode 000 */ |
1891 | frob_set_mode (pb, ECR_SPP); | 1957 | frob_set_mode(pb, ECR_SPP); |
1892 | 1958 | ||
1893 | return 1; | 1959 | return 1; |
1894 | } | 1960 | } |
@@ -1903,10 +1969,10 @@ static int parport_ECPPS2_supported(struct parport *pb) | |||
1903 | if (!priv->ecr) | 1969 | if (!priv->ecr) |
1904 | return 0; | 1970 | return 0; |
1905 | 1971 | ||
1906 | oecr = inb (ECONTROL (pb)); | 1972 | oecr = inb(ECONTROL(pb)); |
1907 | ECR_WRITE (pb, ECR_PS2 << 5); | 1973 | ECR_WRITE(pb, ECR_PS2 << 5); |
1908 | result = parport_PS2_supported(pb); | 1974 | result = parport_PS2_supported(pb); |
1909 | ECR_WRITE (pb, oecr); | 1975 | ECR_WRITE(pb, oecr); |
1910 | return result; | 1976 | return result; |
1911 | } | 1977 | } |
1912 | 1978 | ||
@@ -1930,16 +1996,15 @@ static int parport_EPP_supported(struct parport *pb) | |||
1930 | */ | 1996 | */ |
1931 | 1997 | ||
1932 | /* If EPP timeout bit clear then EPP available */ | 1998 | /* If EPP timeout bit clear then EPP available */ |
1933 | if (!clear_epp_timeout(pb)) { | 1999 | if (!clear_epp_timeout(pb)) |
1934 | return 0; /* No way to clear timeout */ | 2000 | return 0; /* No way to clear timeout */ |
1935 | } | ||
1936 | 2001 | ||
1937 | /* Check for Intel bug. */ | 2002 | /* Check for Intel bug. */ |
1938 | if (priv->ecr) { | 2003 | if (priv->ecr) { |
1939 | unsigned char i; | 2004 | unsigned char i; |
1940 | for (i = 0x00; i < 0x80; i += 0x20) { | 2005 | for (i = 0x00; i < 0x80; i += 0x20) { |
1941 | ECR_WRITE (pb, i); | 2006 | ECR_WRITE(pb, i); |
1942 | if (clear_epp_timeout (pb)) { | 2007 | if (clear_epp_timeout(pb)) { |
1943 | /* Phony EPP in ECP. */ | 2008 | /* Phony EPP in ECP. */ |
1944 | return 0; | 2009 | return 0; |
1945 | } | 2010 | } |
@@ -1963,17 +2028,16 @@ static int parport_ECPEPP_supported(struct parport *pb) | |||
1963 | int result; | 2028 | int result; |
1964 | unsigned char oecr; | 2029 | unsigned char oecr; |
1965 | 2030 | ||
1966 | if (!priv->ecr) { | 2031 | if (!priv->ecr) |
1967 | return 0; | 2032 | return 0; |
1968 | } | ||
1969 | 2033 | ||
1970 | oecr = inb (ECONTROL (pb)); | 2034 | oecr = inb(ECONTROL(pb)); |
1971 | /* Search for SMC style EPP+ECP mode */ | 2035 | /* Search for SMC style EPP+ECP mode */ |
1972 | ECR_WRITE (pb, 0x80); | 2036 | ECR_WRITE(pb, 0x80); |
1973 | outb (0x04, CONTROL (pb)); | 2037 | outb(0x04, CONTROL(pb)); |
1974 | result = parport_EPP_supported(pb); | 2038 | result = parport_EPP_supported(pb); |
1975 | 2039 | ||
1976 | ECR_WRITE (pb, oecr); | 2040 | ECR_WRITE(pb, oecr); |
1977 | 2041 | ||
1978 | if (result) { | 2042 | if (result) { |
1979 | /* Set up access functions to use ECP+EPP hardware. */ | 2043 | /* Set up access functions to use ECP+EPP hardware. */ |
@@ -1991,11 +2055,25 @@ static int parport_ECPEPP_supported(struct parport *pb) | |||
1991 | /* Don't bother probing for modes we know we won't use. */ | 2055 | /* Don't bother probing for modes we know we won't use. */ |
1992 | static int __devinit parport_PS2_supported(struct parport *pb) { return 0; } | 2056 | static int __devinit parport_PS2_supported(struct parport *pb) { return 0; } |
1993 | #ifdef CONFIG_PARPORT_PC_FIFO | 2057 | #ifdef CONFIG_PARPORT_PC_FIFO |
1994 | static int parport_ECP_supported(struct parport *pb) { return 0; } | 2058 | static int parport_ECP_supported(struct parport *pb) |
2059 | { | ||
2060 | return 0; | ||
2061 | } | ||
1995 | #endif | 2062 | #endif |
1996 | static int __devinit parport_EPP_supported(struct parport *pb) { return 0; } | 2063 | static int __devinit parport_EPP_supported(struct parport *pb) |
1997 | static int __devinit parport_ECPEPP_supported(struct parport *pb){return 0;} | 2064 | { |
1998 | static int __devinit parport_ECPPS2_supported(struct parport *pb){return 0;} | 2065 | return 0; |
2066 | } | ||
2067 | |||
2068 | static int __devinit parport_ECPEPP_supported(struct parport *pb) | ||
2069 | { | ||
2070 | return 0; | ||
2071 | } | ||
2072 | |||
2073 | static int __devinit parport_ECPPS2_supported(struct parport *pb) | ||
2074 | { | ||
2075 | return 0; | ||
2076 | } | ||
1999 | 2077 | ||
2000 | #endif /* No IEEE 1284 support */ | 2078 | #endif /* No IEEE 1284 support */ |
2001 | 2079 | ||
@@ -2005,17 +2083,17 @@ static int __devinit parport_ECPPS2_supported(struct parport *pb){return 0;} | |||
2005 | static int programmable_irq_support(struct parport *pb) | 2083 | static int programmable_irq_support(struct parport *pb) |
2006 | { | 2084 | { |
2007 | int irq, intrLine; | 2085 | int irq, intrLine; |
2008 | unsigned char oecr = inb (ECONTROL (pb)); | 2086 | unsigned char oecr = inb(ECONTROL(pb)); |
2009 | static const int lookup[8] = { | 2087 | static const int lookup[8] = { |
2010 | PARPORT_IRQ_NONE, 7, 9, 10, 11, 14, 15, 5 | 2088 | PARPORT_IRQ_NONE, 7, 9, 10, 11, 14, 15, 5 |
2011 | }; | 2089 | }; |
2012 | 2090 | ||
2013 | ECR_WRITE (pb, ECR_CNF << 5); /* Configuration MODE */ | 2091 | ECR_WRITE(pb, ECR_CNF << 5); /* Configuration MODE */ |
2014 | 2092 | ||
2015 | intrLine = (inb (CONFIGB (pb)) >> 3) & 0x07; | 2093 | intrLine = (inb(CONFIGB(pb)) >> 3) & 0x07; |
2016 | irq = lookup[intrLine]; | 2094 | irq = lookup[intrLine]; |
2017 | 2095 | ||
2018 | ECR_WRITE (pb, oecr); | 2096 | ECR_WRITE(pb, oecr); |
2019 | return irq; | 2097 | return irq; |
2020 | } | 2098 | } |
2021 | 2099 | ||
@@ -2025,17 +2103,17 @@ static int irq_probe_ECP(struct parport *pb) | |||
2025 | unsigned long irqs; | 2103 | unsigned long irqs; |
2026 | 2104 | ||
2027 | irqs = probe_irq_on(); | 2105 | irqs = probe_irq_on(); |
2028 | 2106 | ||
2029 | ECR_WRITE (pb, ECR_SPP << 5); /* Reset FIFO */ | 2107 | ECR_WRITE(pb, ECR_SPP << 5); /* Reset FIFO */ |
2030 | ECR_WRITE (pb, (ECR_TST << 5) | 0x04); | 2108 | ECR_WRITE(pb, (ECR_TST << 5) | 0x04); |
2031 | ECR_WRITE (pb, ECR_TST << 5); | 2109 | ECR_WRITE(pb, ECR_TST << 5); |
2032 | 2110 | ||
2033 | /* If Full FIFO sure that writeIntrThreshold is generated */ | 2111 | /* If Full FIFO sure that writeIntrThreshold is generated */ |
2034 | for (i=0; i < 1024 && !(inb (ECONTROL (pb)) & 0x02) ; i++) | 2112 | for (i = 0; i < 1024 && !(inb(ECONTROL(pb)) & 0x02) ; i++) |
2035 | outb (0xaa, FIFO (pb)); | 2113 | outb(0xaa, FIFO(pb)); |
2036 | 2114 | ||
2037 | pb->irq = probe_irq_off(irqs); | 2115 | pb->irq = probe_irq_off(irqs); |
2038 | ECR_WRITE (pb, ECR_SPP << 5); | 2116 | ECR_WRITE(pb, ECR_SPP << 5); |
2039 | 2117 | ||
2040 | if (pb->irq <= 0) | 2118 | if (pb->irq <= 0) |
2041 | pb->irq = PARPORT_IRQ_NONE; | 2119 | pb->irq = PARPORT_IRQ_NONE; |
@@ -2045,7 +2123,7 @@ static int irq_probe_ECP(struct parport *pb) | |||
2045 | 2123 | ||
2046 | /* | 2124 | /* |
2047 | * This detection seems that only works in National Semiconductors | 2125 | * This detection seems that only works in National Semiconductors |
2048 | * This doesn't work in SMC, LGS, and Winbond | 2126 | * This doesn't work in SMC, LGS, and Winbond |
2049 | */ | 2127 | */ |
2050 | static int irq_probe_EPP(struct parport *pb) | 2128 | static int irq_probe_EPP(struct parport *pb) |
2051 | { | 2129 | { |
@@ -2056,16 +2134,16 @@ static int irq_probe_EPP(struct parport *pb) | |||
2056 | unsigned char oecr; | 2134 | unsigned char oecr; |
2057 | 2135 | ||
2058 | if (pb->modes & PARPORT_MODE_PCECR) | 2136 | if (pb->modes & PARPORT_MODE_PCECR) |
2059 | oecr = inb (ECONTROL (pb)); | 2137 | oecr = inb(ECONTROL(pb)); |
2060 | 2138 | ||
2061 | irqs = probe_irq_on(); | 2139 | irqs = probe_irq_on(); |
2062 | 2140 | ||
2063 | if (pb->modes & PARPORT_MODE_PCECR) | 2141 | if (pb->modes & PARPORT_MODE_PCECR) |
2064 | frob_econtrol (pb, 0x10, 0x10); | 2142 | frob_econtrol(pb, 0x10, 0x10); |
2065 | 2143 | ||
2066 | clear_epp_timeout(pb); | 2144 | clear_epp_timeout(pb); |
2067 | parport_pc_frob_control (pb, 0x20, 0x20); | 2145 | parport_pc_frob_control(pb, 0x20, 0x20); |
2068 | parport_pc_frob_control (pb, 0x10, 0x10); | 2146 | parport_pc_frob_control(pb, 0x10, 0x10); |
2069 | clear_epp_timeout(pb); | 2147 | clear_epp_timeout(pb); |
2070 | 2148 | ||
2071 | /* Device isn't expecting an EPP read | 2149 | /* Device isn't expecting an EPP read |
@@ -2074,9 +2152,9 @@ static int irq_probe_EPP(struct parport *pb) | |||
2074 | parport_pc_read_epp(pb); | 2152 | parport_pc_read_epp(pb); |
2075 | udelay(20); | 2153 | udelay(20); |
2076 | 2154 | ||
2077 | pb->irq = probe_irq_off (irqs); | 2155 | pb->irq = probe_irq_off(irqs); |
2078 | if (pb->modes & PARPORT_MODE_PCECR) | 2156 | if (pb->modes & PARPORT_MODE_PCECR) |
2079 | ECR_WRITE (pb, oecr); | 2157 | ECR_WRITE(pb, oecr); |
2080 | parport_pc_write_control(pb, 0xc); | 2158 | parport_pc_write_control(pb, 0xc); |
2081 | 2159 | ||
2082 | if (pb->irq <= 0) | 2160 | if (pb->irq <= 0) |
@@ -2133,28 +2211,28 @@ static int parport_irq_probe(struct parport *pb) | |||
2133 | /* --- DMA detection -------------------------------------- */ | 2211 | /* --- DMA detection -------------------------------------- */ |
2134 | 2212 | ||
2135 | /* Only if chipset conforms to ECP ISA Interface Standard */ | 2213 | /* Only if chipset conforms to ECP ISA Interface Standard */ |
2136 | static int programmable_dma_support (struct parport *p) | 2214 | static int programmable_dma_support(struct parport *p) |
2137 | { | 2215 | { |
2138 | unsigned char oecr = inb (ECONTROL (p)); | 2216 | unsigned char oecr = inb(ECONTROL(p)); |
2139 | int dma; | 2217 | int dma; |
2140 | 2218 | ||
2141 | frob_set_mode (p, ECR_CNF); | 2219 | frob_set_mode(p, ECR_CNF); |
2142 | 2220 | ||
2143 | dma = inb (CONFIGB(p)) & 0x07; | 2221 | dma = inb(CONFIGB(p)) & 0x07; |
2144 | /* 000: Indicates jumpered 8-bit DMA if read-only. | 2222 | /* 000: Indicates jumpered 8-bit DMA if read-only. |
2145 | 100: Indicates jumpered 16-bit DMA if read-only. */ | 2223 | 100: Indicates jumpered 16-bit DMA if read-only. */ |
2146 | if ((dma & 0x03) == 0) | 2224 | if ((dma & 0x03) == 0) |
2147 | dma = PARPORT_DMA_NONE; | 2225 | dma = PARPORT_DMA_NONE; |
2148 | 2226 | ||
2149 | ECR_WRITE (p, oecr); | 2227 | ECR_WRITE(p, oecr); |
2150 | return dma; | 2228 | return dma; |
2151 | } | 2229 | } |
2152 | 2230 | ||
2153 | static int parport_dma_probe (struct parport *p) | 2231 | static int parport_dma_probe(struct parport *p) |
2154 | { | 2232 | { |
2155 | const struct parport_pc_private *priv = p->private_data; | 2233 | const struct parport_pc_private *priv = p->private_data; |
2156 | if (priv->ecr) | 2234 | if (priv->ecr) /* ask ECP chipset first */ |
2157 | p->dma = programmable_dma_support(p); /* ask ECP chipset first */ | 2235 | p->dma = programmable_dma_support(p); |
2158 | if (p->dma == PARPORT_DMA_NONE) { | 2236 | if (p->dma == PARPORT_DMA_NONE) { |
2159 | /* ask known Super-IO chips proper, although these | 2237 | /* ask known Super-IO chips proper, although these |
2160 | claim ECP compatible, some don't report their DMA | 2238 | claim ECP compatible, some don't report their DMA |
@@ -2212,7 +2290,7 @@ struct parport *parport_pc_probe_port(unsigned long int base, | |||
2212 | if (!base_res) | 2290 | if (!base_res) |
2213 | goto out4; | 2291 | goto out4; |
2214 | 2292 | ||
2215 | memcpy(ops, &parport_pc_ops, sizeof (struct parport_operations)); | 2293 | memcpy(ops, &parport_pc_ops, sizeof(struct parport_operations)); |
2216 | priv->ctr = 0xc; | 2294 | priv->ctr = 0xc; |
2217 | priv->ctr_writable = ~0x10; | 2295 | priv->ctr_writable = ~0x10; |
2218 | priv->ecr = 0; | 2296 | priv->ecr = 0; |
@@ -2239,7 +2317,7 @@ struct parport *parport_pc_probe_port(unsigned long int base, | |||
2239 | if (!parport_EPP_supported(p)) | 2317 | if (!parport_EPP_supported(p)) |
2240 | parport_ECPEPP_supported(p); | 2318 | parport_ECPEPP_supported(p); |
2241 | } | 2319 | } |
2242 | if (!parport_SPP_supported (p)) | 2320 | if (!parport_SPP_supported(p)) |
2243 | /* No port. */ | 2321 | /* No port. */ |
2244 | goto out5; | 2322 | goto out5; |
2245 | if (priv->ecr) | 2323 | if (priv->ecr) |
@@ -2247,7 +2325,7 @@ struct parport *parport_pc_probe_port(unsigned long int base, | |||
2247 | else | 2325 | else |
2248 | parport_PS2_supported(p); | 2326 | parport_PS2_supported(p); |
2249 | 2327 | ||
2250 | p->size = (p->modes & PARPORT_MODE_EPP)?8:3; | 2328 | p->size = (p->modes & PARPORT_MODE_EPP) ? 8 : 3; |
2251 | 2329 | ||
2252 | printk(KERN_INFO "%s: PC-style at 0x%lx", p->name, p->base); | 2330 | printk(KERN_INFO "%s: PC-style at 0x%lx", p->name, p->base); |
2253 | if (p->base_hi && priv->ecr) | 2331 | if (p->base_hi && priv->ecr) |
@@ -2271,7 +2349,7 @@ struct parport *parport_pc_probe_port(unsigned long int base, | |||
2271 | } | 2349 | } |
2272 | } | 2350 | } |
2273 | if (p->dma == PARPORT_DMA_AUTO) /* To use DMA, giving the irq | 2351 | if (p->dma == PARPORT_DMA_AUTO) /* To use DMA, giving the irq |
2274 | is mandatory (see above) */ | 2352 | is mandatory (see above) */ |
2275 | p->dma = PARPORT_DMA_NONE; | 2353 | p->dma = PARPORT_DMA_NONE; |
2276 | 2354 | ||
2277 | #ifdef CONFIG_PARPORT_PC_FIFO | 2355 | #ifdef CONFIG_PARPORT_PC_FIFO |
@@ -2288,16 +2366,23 @@ struct parport *parport_pc_probe_port(unsigned long int base, | |||
2288 | if (p->dma != PARPORT_DMA_NONE) { | 2366 | if (p->dma != PARPORT_DMA_NONE) { |
2289 | printk(", dma %d", p->dma); | 2367 | printk(", dma %d", p->dma); |
2290 | p->modes |= PARPORT_MODE_DMA; | 2368 | p->modes |= PARPORT_MODE_DMA; |
2291 | } | 2369 | } else |
2292 | else printk(", using FIFO"); | 2370 | printk(", using FIFO"); |
2293 | } | 2371 | } else |
2294 | else | ||
2295 | /* We can't use the DMA channel after all. */ | 2372 | /* We can't use the DMA channel after all. */ |
2296 | p->dma = PARPORT_DMA_NONE; | 2373 | p->dma = PARPORT_DMA_NONE; |
2297 | #endif /* Allowed to use FIFO/DMA */ | 2374 | #endif /* Allowed to use FIFO/DMA */ |
2298 | 2375 | ||
2299 | printk(" ["); | 2376 | printk(" ["); |
2300 | #define printmode(x) {if(p->modes&PARPORT_MODE_##x){printk("%s%s",f?",":"",#x);f++;}} | 2377 | |
2378 | #define printmode(x) \ | ||
2379 | {\ | ||
2380 | if (p->modes & PARPORT_MODE_##x) {\ | ||
2381 | printk("%s%s", f ? "," : "", #x);\ | ||
2382 | f++;\ | ||
2383 | } \ | ||
2384 | } | ||
2385 | |||
2301 | { | 2386 | { |
2302 | int f = 0; | 2387 | int f = 0; |
2303 | printmode(PCSPP); | 2388 | printmode(PCSPP); |
@@ -2309,10 +2394,10 @@ struct parport *parport_pc_probe_port(unsigned long int base, | |||
2309 | } | 2394 | } |
2310 | #undef printmode | 2395 | #undef printmode |
2311 | #ifndef CONFIG_PARPORT_1284 | 2396 | #ifndef CONFIG_PARPORT_1284 |
2312 | printk ("(,...)"); | 2397 | printk("(,...)"); |
2313 | #endif /* CONFIG_PARPORT_1284 */ | 2398 | #endif /* CONFIG_PARPORT_1284 */ |
2314 | printk("]\n"); | 2399 | printk("]\n"); |
2315 | if (probedirq != PARPORT_IRQ_NONE) | 2400 | if (probedirq != PARPORT_IRQ_NONE) |
2316 | printk(KERN_INFO "%s: irq %d detected\n", p->name, probedirq); | 2401 | printk(KERN_INFO "%s: irq %d detected\n", p->name, probedirq); |
2317 | 2402 | ||
2318 | /* If No ECP release the ports grabbed above. */ | 2403 | /* If No ECP release the ports grabbed above. */ |
@@ -2328,7 +2413,7 @@ struct parport *parport_pc_probe_port(unsigned long int base, | |||
2328 | if (p->irq != PARPORT_IRQ_NONE) { | 2413 | if (p->irq != PARPORT_IRQ_NONE) { |
2329 | if (request_irq(p->irq, parport_irq_handler, | 2414 | if (request_irq(p->irq, parport_irq_handler, |
2330 | irqflags, p->name, p)) { | 2415 | irqflags, p->name, p)) { |
2331 | printk (KERN_WARNING "%s: irq %d in use, " | 2416 | printk(KERN_WARNING "%s: irq %d in use, " |
2332 | "resorting to polled operation\n", | 2417 | "resorting to polled operation\n", |
2333 | p->name, p->irq); | 2418 | p->name, p->irq); |
2334 | p->irq = PARPORT_IRQ_NONE; | 2419 | p->irq = PARPORT_IRQ_NONE; |
@@ -2338,8 +2423,8 @@ struct parport *parport_pc_probe_port(unsigned long int base, | |||
2338 | #ifdef CONFIG_PARPORT_PC_FIFO | 2423 | #ifdef CONFIG_PARPORT_PC_FIFO |
2339 | #ifdef HAS_DMA | 2424 | #ifdef HAS_DMA |
2340 | if (p->dma != PARPORT_DMA_NONE) { | 2425 | if (p->dma != PARPORT_DMA_NONE) { |
2341 | if (request_dma (p->dma, p->name)) { | 2426 | if (request_dma(p->dma, p->name)) { |
2342 | printk (KERN_WARNING "%s: dma %d in use, " | 2427 | printk(KERN_WARNING "%s: dma %d in use, " |
2343 | "resorting to PIO operation\n", | 2428 | "resorting to PIO operation\n", |
2344 | p->name, p->dma); | 2429 | p->name, p->dma); |
2345 | p->dma = PARPORT_DMA_NONE; | 2430 | p->dma = PARPORT_DMA_NONE; |
@@ -2349,8 +2434,8 @@ struct parport *parport_pc_probe_port(unsigned long int base, | |||
2349 | PAGE_SIZE, | 2434 | PAGE_SIZE, |
2350 | &priv->dma_handle, | 2435 | &priv->dma_handle, |
2351 | GFP_KERNEL); | 2436 | GFP_KERNEL); |
2352 | if (! priv->dma_buf) { | 2437 | if (!priv->dma_buf) { |
2353 | printk (KERN_WARNING "%s: " | 2438 | printk(KERN_WARNING "%s: " |
2354 | "cannot get buffer for DMA, " | 2439 | "cannot get buffer for DMA, " |
2355 | "resorting to PIO operation\n", | 2440 | "resorting to PIO operation\n", |
2356 | p->name); | 2441 | p->name); |
@@ -2369,10 +2454,10 @@ struct parport *parport_pc_probe_port(unsigned long int base, | |||
2369 | * Put the ECP detected port in PS2 mode. | 2454 | * Put the ECP detected port in PS2 mode. |
2370 | * Do this also for ports that have ECR but don't do ECP. | 2455 | * Do this also for ports that have ECR but don't do ECP. |
2371 | */ | 2456 | */ |
2372 | ECR_WRITE (p, 0x34); | 2457 | ECR_WRITE(p, 0x34); |
2373 | 2458 | ||
2374 | parport_pc_write_data(p, 0); | 2459 | parport_pc_write_data(p, 0); |
2375 | parport_pc_data_forward (p); | 2460 | parport_pc_data_forward(p); |
2376 | 2461 | ||
2377 | /* Now that we've told the sharing engine about the port, and | 2462 | /* Now that we've told the sharing engine about the port, and |
2378 | found out its characteristics, let the high-level drivers | 2463 | found out its characteristics, let the high-level drivers |
@@ -2380,7 +2465,7 @@ struct parport *parport_pc_probe_port(unsigned long int base, | |||
2380 | spin_lock(&ports_lock); | 2465 | spin_lock(&ports_lock); |
2381 | list_add(&priv->list, &ports_list); | 2466 | list_add(&priv->list, &ports_list); |
2382 | spin_unlock(&ports_lock); | 2467 | spin_unlock(&ports_lock); |
2383 | parport_announce_port (p); | 2468 | parport_announce_port(p); |
2384 | 2469 | ||
2385 | return p; | 2470 | return p; |
2386 | 2471 | ||
@@ -2393,18 +2478,17 @@ out5: | |||
2393 | out4: | 2478 | out4: |
2394 | parport_put_port(p); | 2479 | parport_put_port(p); |
2395 | out3: | 2480 | out3: |
2396 | kfree (priv); | 2481 | kfree(priv); |
2397 | out2: | 2482 | out2: |
2398 | kfree (ops); | 2483 | kfree(ops); |
2399 | out1: | 2484 | out1: |
2400 | if (pdev) | 2485 | if (pdev) |
2401 | platform_device_unregister(pdev); | 2486 | platform_device_unregister(pdev); |
2402 | return NULL; | 2487 | return NULL; |
2403 | } | 2488 | } |
2489 | EXPORT_SYMBOL(parport_pc_probe_port); | ||
2404 | 2490 | ||
2405 | EXPORT_SYMBOL (parport_pc_probe_port); | 2491 | void parport_pc_unregister_port(struct parport *p) |
2406 | |||
2407 | void parport_pc_unregister_port (struct parport *p) | ||
2408 | { | 2492 | { |
2409 | struct parport_pc_private *priv = p->private_data; | 2493 | struct parport_pc_private *priv = p->private_data; |
2410 | struct parport_operations *ops = p->ops; | 2494 | struct parport_operations *ops = p->ops; |
@@ -2430,17 +2514,16 @@ void parport_pc_unregister_port (struct parport *p) | |||
2430 | priv->dma_buf, | 2514 | priv->dma_buf, |
2431 | priv->dma_handle); | 2515 | priv->dma_handle); |
2432 | #endif | 2516 | #endif |
2433 | kfree (p->private_data); | 2517 | kfree(p->private_data); |
2434 | parport_put_port(p); | 2518 | parport_put_port(p); |
2435 | kfree (ops); /* hope no-one cached it */ | 2519 | kfree(ops); /* hope no-one cached it */ |
2436 | } | 2520 | } |
2437 | 2521 | EXPORT_SYMBOL(parport_pc_unregister_port); | |
2438 | EXPORT_SYMBOL (parport_pc_unregister_port); | ||
2439 | 2522 | ||
2440 | #ifdef CONFIG_PCI | 2523 | #ifdef CONFIG_PCI |
2441 | 2524 | ||
2442 | /* ITE support maintained by Rich Liu <richliu@poorman.org> */ | 2525 | /* ITE support maintained by Rich Liu <richliu@poorman.org> */ |
2443 | static int __devinit sio_ite_8872_probe (struct pci_dev *pdev, int autoirq, | 2526 | static int __devinit sio_ite_8872_probe(struct pci_dev *pdev, int autoirq, |
2444 | int autodma, | 2527 | int autodma, |
2445 | const struct parport_pc_via_data *via) | 2528 | const struct parport_pc_via_data *via) |
2446 | { | 2529 | { |
@@ -2452,73 +2535,74 @@ static int __devinit sio_ite_8872_probe (struct pci_dev *pdev, int autoirq, | |||
2452 | int irq; | 2535 | int irq; |
2453 | int i; | 2536 | int i; |
2454 | 2537 | ||
2455 | DPRINTK (KERN_DEBUG "sio_ite_8872_probe()\n"); | 2538 | DPRINTK(KERN_DEBUG "sio_ite_8872_probe()\n"); |
2456 | 2539 | ||
2457 | // make sure which one chip | 2540 | /* make sure which one chip */ |
2458 | for(i = 0; i < 5; i++) { | 2541 | for (i = 0; i < 5; i++) { |
2459 | base_res = request_region(inta_addr[i], 32, "it887x"); | 2542 | base_res = request_region(inta_addr[i], 32, "it887x"); |
2460 | if (base_res) { | 2543 | if (base_res) { |
2461 | int test; | 2544 | int test; |
2462 | pci_write_config_dword (pdev, 0x60, | 2545 | pci_write_config_dword(pdev, 0x60, |
2463 | 0xe5000000 | inta_addr[i]); | 2546 | 0xe5000000 | inta_addr[i]); |
2464 | pci_write_config_dword (pdev, 0x78, | 2547 | pci_write_config_dword(pdev, 0x78, |
2465 | 0x00000000 | inta_addr[i]); | 2548 | 0x00000000 | inta_addr[i]); |
2466 | test = inb (inta_addr[i]); | 2549 | test = inb(inta_addr[i]); |
2467 | if (test != 0xff) break; | 2550 | if (test != 0xff) |
2551 | break; | ||
2468 | release_region(inta_addr[i], 0x8); | 2552 | release_region(inta_addr[i], 0x8); |
2469 | } | 2553 | } |
2470 | } | 2554 | } |
2471 | if(i >= 5) { | 2555 | if (i >= 5) { |
2472 | printk (KERN_INFO "parport_pc: cannot find ITE8872 INTA\n"); | 2556 | printk(KERN_INFO "parport_pc: cannot find ITE8872 INTA\n"); |
2473 | return 0; | 2557 | return 0; |
2474 | } | 2558 | } |
2475 | 2559 | ||
2476 | type = inb (inta_addr[i] + 0x18); | 2560 | type = inb(inta_addr[i] + 0x18); |
2477 | type &= 0x0f; | 2561 | type &= 0x0f; |
2478 | 2562 | ||
2479 | switch (type) { | 2563 | switch (type) { |
2480 | case 0x2: | 2564 | case 0x2: |
2481 | printk (KERN_INFO "parport_pc: ITE8871 found (1P)\n"); | 2565 | printk(KERN_INFO "parport_pc: ITE8871 found (1P)\n"); |
2482 | ite8872set = 0x64200000; | 2566 | ite8872set = 0x64200000; |
2483 | break; | 2567 | break; |
2484 | case 0xa: | 2568 | case 0xa: |
2485 | printk (KERN_INFO "parport_pc: ITE8875 found (1P)\n"); | 2569 | printk(KERN_INFO "parport_pc: ITE8875 found (1P)\n"); |
2486 | ite8872set = 0x64200000; | 2570 | ite8872set = 0x64200000; |
2487 | break; | 2571 | break; |
2488 | case 0xe: | 2572 | case 0xe: |
2489 | printk (KERN_INFO "parport_pc: ITE8872 found (2S1P)\n"); | 2573 | printk(KERN_INFO "parport_pc: ITE8872 found (2S1P)\n"); |
2490 | ite8872set = 0x64e00000; | 2574 | ite8872set = 0x64e00000; |
2491 | break; | 2575 | break; |
2492 | case 0x6: | 2576 | case 0x6: |
2493 | printk (KERN_INFO "parport_pc: ITE8873 found (1S)\n"); | 2577 | printk(KERN_INFO "parport_pc: ITE8873 found (1S)\n"); |
2494 | return 0; | 2578 | return 0; |
2495 | case 0x8: | 2579 | case 0x8: |
2496 | DPRINTK (KERN_DEBUG "parport_pc: ITE8874 found (2S)\n"); | 2580 | DPRINTK(KERN_DEBUG "parport_pc: ITE8874 found (2S)\n"); |
2497 | return 0; | 2581 | return 0; |
2498 | default: | 2582 | default: |
2499 | printk (KERN_INFO "parport_pc: unknown ITE887x\n"); | 2583 | printk(KERN_INFO "parport_pc: unknown ITE887x\n"); |
2500 | printk (KERN_INFO "parport_pc: please mail 'lspci -nvv' " | 2584 | printk(KERN_INFO "parport_pc: please mail 'lspci -nvv' " |
2501 | "output to Rich.Liu@ite.com.tw\n"); | 2585 | "output to Rich.Liu@ite.com.tw\n"); |
2502 | return 0; | 2586 | return 0; |
2503 | } | 2587 | } |
2504 | 2588 | ||
2505 | pci_read_config_byte (pdev, 0x3c, &ite8872_irq); | 2589 | pci_read_config_byte(pdev, 0x3c, &ite8872_irq); |
2506 | pci_read_config_dword (pdev, 0x1c, &ite8872_lpt); | 2590 | pci_read_config_dword(pdev, 0x1c, &ite8872_lpt); |
2507 | ite8872_lpt &= 0x0000ff00; | 2591 | ite8872_lpt &= 0x0000ff00; |
2508 | pci_read_config_dword (pdev, 0x20, &ite8872_lpthi); | 2592 | pci_read_config_dword(pdev, 0x20, &ite8872_lpthi); |
2509 | ite8872_lpthi &= 0x0000ff00; | 2593 | ite8872_lpthi &= 0x0000ff00; |
2510 | pci_write_config_dword (pdev, 0x6c, 0xe3000000 | ite8872_lpt); | 2594 | pci_write_config_dword(pdev, 0x6c, 0xe3000000 | ite8872_lpt); |
2511 | pci_write_config_dword (pdev, 0x70, 0xe3000000 | ite8872_lpthi); | 2595 | pci_write_config_dword(pdev, 0x70, 0xe3000000 | ite8872_lpthi); |
2512 | pci_write_config_dword (pdev, 0x80, (ite8872_lpthi<<16) | ite8872_lpt); | 2596 | pci_write_config_dword(pdev, 0x80, (ite8872_lpthi<<16) | ite8872_lpt); |
2513 | // SET SPP&EPP , Parallel Port NO DMA , Enable All Function | 2597 | /* SET SPP&EPP , Parallel Port NO DMA , Enable All Function */ |
2514 | // SET Parallel IRQ | 2598 | /* SET Parallel IRQ */ |
2515 | pci_write_config_dword (pdev, 0x9c, | 2599 | pci_write_config_dword(pdev, 0x9c, |
2516 | ite8872set | (ite8872_irq * 0x11111)); | 2600 | ite8872set | (ite8872_irq * 0x11111)); |
2517 | 2601 | ||
2518 | DPRINTK (KERN_DEBUG "ITE887x: The IRQ is %d.\n", ite8872_irq); | 2602 | DPRINTK(KERN_DEBUG "ITE887x: The IRQ is %d.\n", ite8872_irq); |
2519 | DPRINTK (KERN_DEBUG "ITE887x: The PARALLEL I/O port is 0x%x.\n", | 2603 | DPRINTK(KERN_DEBUG "ITE887x: The PARALLEL I/O port is 0x%x.\n", |
2520 | ite8872_lpt); | 2604 | ite8872_lpt); |
2521 | DPRINTK (KERN_DEBUG "ITE887x: The PARALLEL I/O porthi is 0x%x.\n", | 2605 | DPRINTK(KERN_DEBUG "ITE887x: The PARALLEL I/O porthi is 0x%x.\n", |
2522 | ite8872_lpthi); | 2606 | ite8872_lpthi); |
2523 | 2607 | ||
2524 | /* Let the user (or defaults) steer us away from interrupts */ | 2608 | /* Let the user (or defaults) steer us away from interrupts */ |
@@ -2530,14 +2614,14 @@ static int __devinit sio_ite_8872_probe (struct pci_dev *pdev, int autoirq, | |||
2530 | * Release the resource so that parport_pc_probe_port can get it. | 2614 | * Release the resource so that parport_pc_probe_port can get it. |
2531 | */ | 2615 | */ |
2532 | release_resource(base_res); | 2616 | release_resource(base_res); |
2533 | if (parport_pc_probe_port (ite8872_lpt, ite8872_lpthi, | 2617 | if (parport_pc_probe_port(ite8872_lpt, ite8872_lpthi, |
2534 | irq, PARPORT_DMA_NONE, &pdev->dev, 0)) { | 2618 | irq, PARPORT_DMA_NONE, &pdev->dev, 0)) { |
2535 | printk (KERN_INFO | 2619 | printk(KERN_INFO |
2536 | "parport_pc: ITE 8872 parallel port: io=0x%X", | 2620 | "parport_pc: ITE 8872 parallel port: io=0x%X", |
2537 | ite8872_lpt); | 2621 | ite8872_lpt); |
2538 | if (irq != PARPORT_IRQ_NONE) | 2622 | if (irq != PARPORT_IRQ_NONE) |
2539 | printk (", irq=%d", irq); | 2623 | printk(", irq=%d", irq); |
2540 | printk ("\n"); | 2624 | printk("\n"); |
2541 | return 1; | 2625 | return 1; |
2542 | } | 2626 | } |
2543 | 2627 | ||
@@ -2546,7 +2630,7 @@ static int __devinit sio_ite_8872_probe (struct pci_dev *pdev, int autoirq, | |||
2546 | 2630 | ||
2547 | /* VIA 8231 support by Pavel Fedin <sonic_amiga@rambler.ru> | 2631 | /* VIA 8231 support by Pavel Fedin <sonic_amiga@rambler.ru> |
2548 | based on VIA 686a support code by Jeff Garzik <jgarzik@pobox.com> */ | 2632 | based on VIA 686a support code by Jeff Garzik <jgarzik@pobox.com> */ |
2549 | static int __devinitdata parport_init_mode = 0; | 2633 | static int __devinitdata parport_init_mode; |
2550 | 2634 | ||
2551 | /* Data for two known VIA chips */ | 2635 | /* Data for two known VIA chips */ |
2552 | static struct parport_pc_via_data via_686a_data __devinitdata = { | 2636 | static struct parport_pc_via_data via_686a_data __devinitdata = { |
@@ -2568,7 +2652,7 @@ static struct parport_pc_via_data via_8231_data __devinitdata = { | |||
2568 | 0xF6 | 2652 | 0xF6 |
2569 | }; | 2653 | }; |
2570 | 2654 | ||
2571 | static int __devinit sio_via_probe (struct pci_dev *pdev, int autoirq, | 2655 | static int __devinit sio_via_probe(struct pci_dev *pdev, int autoirq, |
2572 | int autodma, | 2656 | int autodma, |
2573 | const struct parport_pc_via_data *via) | 2657 | const struct parport_pc_via_data *via) |
2574 | { | 2658 | { |
@@ -2580,38 +2664,38 @@ static int __devinit sio_via_probe (struct pci_dev *pdev, int autoirq, | |||
2580 | 2664 | ||
2581 | printk(KERN_DEBUG "parport_pc: VIA 686A/8231 detected\n"); | 2665 | printk(KERN_DEBUG "parport_pc: VIA 686A/8231 detected\n"); |
2582 | 2666 | ||
2583 | switch(parport_init_mode) | 2667 | switch (parport_init_mode) { |
2584 | { | ||
2585 | case 1: | 2668 | case 1: |
2586 | printk(KERN_DEBUG "parport_pc: setting SPP mode\n"); | 2669 | printk(KERN_DEBUG "parport_pc: setting SPP mode\n"); |
2587 | siofunc = VIA_FUNCTION_PARPORT_SPP; | 2670 | siofunc = VIA_FUNCTION_PARPORT_SPP; |
2588 | break; | 2671 | break; |
2589 | case 2: | 2672 | case 2: |
2590 | printk(KERN_DEBUG "parport_pc: setting PS/2 mode\n"); | 2673 | printk(KERN_DEBUG "parport_pc: setting PS/2 mode\n"); |
2591 | siofunc = VIA_FUNCTION_PARPORT_SPP; | 2674 | siofunc = VIA_FUNCTION_PARPORT_SPP; |
2592 | ppcontrol = VIA_PARPORT_BIDIR; | 2675 | ppcontrol = VIA_PARPORT_BIDIR; |
2593 | break; | 2676 | break; |
2594 | case 3: | 2677 | case 3: |
2595 | printk(KERN_DEBUG "parport_pc: setting EPP mode\n"); | 2678 | printk(KERN_DEBUG "parport_pc: setting EPP mode\n"); |
2596 | siofunc = VIA_FUNCTION_PARPORT_EPP; | 2679 | siofunc = VIA_FUNCTION_PARPORT_EPP; |
2597 | ppcontrol = VIA_PARPORT_BIDIR; | 2680 | ppcontrol = VIA_PARPORT_BIDIR; |
2598 | have_epp = 1; | 2681 | have_epp = 1; |
2599 | break; | 2682 | break; |
2600 | case 4: | 2683 | case 4: |
2601 | printk(KERN_DEBUG "parport_pc: setting ECP mode\n"); | 2684 | printk(KERN_DEBUG "parport_pc: setting ECP mode\n"); |
2602 | siofunc = VIA_FUNCTION_PARPORT_ECP; | 2685 | siofunc = VIA_FUNCTION_PARPORT_ECP; |
2603 | ppcontrol = VIA_PARPORT_BIDIR; | 2686 | ppcontrol = VIA_PARPORT_BIDIR; |
2604 | break; | 2687 | break; |
2605 | case 5: | 2688 | case 5: |
2606 | printk(KERN_DEBUG "parport_pc: setting EPP+ECP mode\n"); | 2689 | printk(KERN_DEBUG "parport_pc: setting EPP+ECP mode\n"); |
2607 | siofunc = VIA_FUNCTION_PARPORT_ECP; | 2690 | siofunc = VIA_FUNCTION_PARPORT_ECP; |
2608 | ppcontrol = VIA_PARPORT_BIDIR|VIA_PARPORT_ECPEPP; | 2691 | ppcontrol = VIA_PARPORT_BIDIR|VIA_PARPORT_ECPEPP; |
2609 | have_epp = 1; | 2692 | have_epp = 1; |
2610 | break; | 2693 | break; |
2611 | default: | 2694 | default: |
2612 | printk(KERN_DEBUG "parport_pc: probing current configuration\n"); | 2695 | printk(KERN_DEBUG |
2613 | siofunc = VIA_FUNCTION_PROBE; | 2696 | "parport_pc: probing current configuration\n"); |
2614 | break; | 2697 | siofunc = VIA_FUNCTION_PROBE; |
2698 | break; | ||
2615 | } | 2699 | } |
2616 | /* | 2700 | /* |
2617 | * unlock super i/o configuration | 2701 | * unlock super i/o configuration |
@@ -2622,38 +2706,36 @@ static int __devinit sio_via_probe (struct pci_dev *pdev, int autoirq, | |||
2622 | 2706 | ||
2623 | /* Bits 1-0: Parallel Port Mode / Enable */ | 2707 | /* Bits 1-0: Parallel Port Mode / Enable */ |
2624 | outb(via->viacfg_function, VIA_CONFIG_INDEX); | 2708 | outb(via->viacfg_function, VIA_CONFIG_INDEX); |
2625 | tmp = inb (VIA_CONFIG_DATA); | 2709 | tmp = inb(VIA_CONFIG_DATA); |
2626 | /* Bit 5: EPP+ECP enable; bit 7: PS/2 bidirectional port enable */ | 2710 | /* Bit 5: EPP+ECP enable; bit 7: PS/2 bidirectional port enable */ |
2627 | outb(via->viacfg_parport_control, VIA_CONFIG_INDEX); | 2711 | outb(via->viacfg_parport_control, VIA_CONFIG_INDEX); |
2628 | tmp2 = inb (VIA_CONFIG_DATA); | 2712 | tmp2 = inb(VIA_CONFIG_DATA); |
2629 | if (siofunc == VIA_FUNCTION_PROBE) | 2713 | if (siofunc == VIA_FUNCTION_PROBE) { |
2630 | { | 2714 | siofunc = tmp & VIA_FUNCTION_PARPORT_DISABLE; |
2631 | siofunc = tmp & VIA_FUNCTION_PARPORT_DISABLE; | 2715 | ppcontrol = tmp2; |
2632 | ppcontrol = tmp2; | 2716 | } else { |
2717 | tmp &= ~VIA_FUNCTION_PARPORT_DISABLE; | ||
2718 | tmp |= siofunc; | ||
2719 | outb(via->viacfg_function, VIA_CONFIG_INDEX); | ||
2720 | outb(tmp, VIA_CONFIG_DATA); | ||
2721 | tmp2 &= ~(VIA_PARPORT_BIDIR|VIA_PARPORT_ECPEPP); | ||
2722 | tmp2 |= ppcontrol; | ||
2723 | outb(via->viacfg_parport_control, VIA_CONFIG_INDEX); | ||
2724 | outb(tmp2, VIA_CONFIG_DATA); | ||
2633 | } | 2725 | } |
2634 | else | 2726 | |
2635 | { | ||
2636 | tmp &= ~VIA_FUNCTION_PARPORT_DISABLE; | ||
2637 | tmp |= siofunc; | ||
2638 | outb(via->viacfg_function, VIA_CONFIG_INDEX); | ||
2639 | outb(tmp, VIA_CONFIG_DATA); | ||
2640 | tmp2 &= ~(VIA_PARPORT_BIDIR|VIA_PARPORT_ECPEPP); | ||
2641 | tmp2 |= ppcontrol; | ||
2642 | outb(via->viacfg_parport_control, VIA_CONFIG_INDEX); | ||
2643 | outb(tmp2, VIA_CONFIG_DATA); | ||
2644 | } | ||
2645 | |||
2646 | /* Parallel Port I/O Base Address, bits 9-2 */ | 2727 | /* Parallel Port I/O Base Address, bits 9-2 */ |
2647 | outb(via->viacfg_parport_base, VIA_CONFIG_INDEX); | 2728 | outb(via->viacfg_parport_base, VIA_CONFIG_INDEX); |
2648 | port1 = inb(VIA_CONFIG_DATA) << 2; | 2729 | port1 = inb(VIA_CONFIG_DATA) << 2; |
2649 | 2730 | ||
2650 | printk (KERN_DEBUG "parport_pc: Current parallel port base: 0x%X\n",port1); | 2731 | printk(KERN_DEBUG "parport_pc: Current parallel port base: 0x%X\n", |
2651 | if ((port1 == 0x3BC) && have_epp) | 2732 | port1); |
2652 | { | 2733 | if (port1 == 0x3BC && have_epp) { |
2653 | outb(via->viacfg_parport_base, VIA_CONFIG_INDEX); | 2734 | outb(via->viacfg_parport_base, VIA_CONFIG_INDEX); |
2654 | outb((0x378 >> 2), VIA_CONFIG_DATA); | 2735 | outb((0x378 >> 2), VIA_CONFIG_DATA); |
2655 | printk(KERN_DEBUG "parport_pc: Parallel port base changed to 0x378\n"); | 2736 | printk(KERN_DEBUG |
2656 | port1 = 0x378; | 2737 | "parport_pc: Parallel port base changed to 0x378\n"); |
2738 | port1 = 0x378; | ||
2657 | } | 2739 | } |
2658 | 2740 | ||
2659 | /* | 2741 | /* |
@@ -2667,36 +2749,39 @@ static int __devinit sio_via_probe (struct pci_dev *pdev, int autoirq, | |||
2667 | printk(KERN_INFO "parport_pc: VIA parallel port disabled in BIOS\n"); | 2749 | printk(KERN_INFO "parport_pc: VIA parallel port disabled in BIOS\n"); |
2668 | return 0; | 2750 | return 0; |
2669 | } | 2751 | } |
2670 | 2752 | ||
2671 | /* Bits 7-4: PnP Routing for Parallel Port IRQ */ | 2753 | /* Bits 7-4: PnP Routing for Parallel Port IRQ */ |
2672 | pci_read_config_byte(pdev, via->via_pci_parport_irq_reg, &tmp); | 2754 | pci_read_config_byte(pdev, via->via_pci_parport_irq_reg, &tmp); |
2673 | irq = ((tmp & VIA_IRQCONTROL_PARALLEL) >> 4); | 2755 | irq = ((tmp & VIA_IRQCONTROL_PARALLEL) >> 4); |
2674 | 2756 | ||
2675 | if (siofunc == VIA_FUNCTION_PARPORT_ECP) | 2757 | if (siofunc == VIA_FUNCTION_PARPORT_ECP) { |
2676 | { | 2758 | /* Bits 3-2: PnP Routing for Parallel Port DMA */ |
2677 | /* Bits 3-2: PnP Routing for Parallel Port DMA */ | 2759 | pci_read_config_byte(pdev, via->via_pci_parport_dma_reg, &tmp); |
2678 | pci_read_config_byte(pdev, via->via_pci_parport_dma_reg, &tmp); | 2760 | dma = ((tmp & VIA_DMACONTROL_PARALLEL) >> 2); |
2679 | dma = ((tmp & VIA_DMACONTROL_PARALLEL) >> 2); | 2761 | } else |
2680 | } | 2762 | /* if ECP not enabled, DMA is not enabled, assumed |
2681 | else | 2763 | bogus 'dma' value */ |
2682 | /* if ECP not enabled, DMA is not enabled, assumed bogus 'dma' value */ | 2764 | dma = PARPORT_DMA_NONE; |
2683 | dma = PARPORT_DMA_NONE; | ||
2684 | 2765 | ||
2685 | /* Let the user (or defaults) steer us away from interrupts and DMA */ | 2766 | /* Let the user (or defaults) steer us away from interrupts and DMA */ |
2686 | if (autoirq == PARPORT_IRQ_NONE) { | 2767 | if (autoirq == PARPORT_IRQ_NONE) { |
2687 | irq = PARPORT_IRQ_NONE; | 2768 | irq = PARPORT_IRQ_NONE; |
2688 | dma = PARPORT_DMA_NONE; | 2769 | dma = PARPORT_DMA_NONE; |
2689 | } | 2770 | } |
2690 | if (autodma == PARPORT_DMA_NONE) | 2771 | if (autodma == PARPORT_DMA_NONE) |
2691 | dma = PARPORT_DMA_NONE; | 2772 | dma = PARPORT_DMA_NONE; |
2692 | 2773 | ||
2693 | switch (port1) { | 2774 | switch (port1) { |
2694 | case 0x3bc: port2 = 0x7bc; break; | 2775 | case 0x3bc: |
2695 | case 0x378: port2 = 0x778; break; | 2776 | port2 = 0x7bc; break; |
2696 | case 0x278: port2 = 0x678; break; | 2777 | case 0x378: |
2778 | port2 = 0x778; break; | ||
2779 | case 0x278: | ||
2780 | port2 = 0x678; break; | ||
2697 | default: | 2781 | default: |
2698 | printk(KERN_INFO "parport_pc: Weird VIA parport base 0x%X, ignoring\n", | 2782 | printk(KERN_INFO |
2699 | port1); | 2783 | "parport_pc: Weird VIA parport base 0x%X, ignoring\n", |
2784 | port1); | ||
2700 | return 0; | 2785 | return 0; |
2701 | } | 2786 | } |
2702 | 2787 | ||
@@ -2714,17 +2799,17 @@ static int __devinit sio_via_probe (struct pci_dev *pdev, int autoirq, | |||
2714 | } | 2799 | } |
2715 | 2800 | ||
2716 | /* finally, do the probe with values obtained */ | 2801 | /* finally, do the probe with values obtained */ |
2717 | if (parport_pc_probe_port (port1, port2, irq, dma, &pdev->dev, 0)) { | 2802 | if (parport_pc_probe_port(port1, port2, irq, dma, &pdev->dev, 0)) { |
2718 | printk (KERN_INFO | 2803 | printk(KERN_INFO |
2719 | "parport_pc: VIA parallel port: io=0x%X", port1); | 2804 | "parport_pc: VIA parallel port: io=0x%X", port1); |
2720 | if (irq != PARPORT_IRQ_NONE) | 2805 | if (irq != PARPORT_IRQ_NONE) |
2721 | printk (", irq=%d", irq); | 2806 | printk(", irq=%d", irq); |
2722 | if (dma != PARPORT_DMA_NONE) | 2807 | if (dma != PARPORT_DMA_NONE) |
2723 | printk (", dma=%d", dma); | 2808 | printk(", dma=%d", dma); |
2724 | printk ("\n"); | 2809 | printk("\n"); |
2725 | return 1; | 2810 | return 1; |
2726 | } | 2811 | } |
2727 | 2812 | ||
2728 | printk(KERN_WARNING "parport_pc: Strange, can't probe VIA parallel port: io=0x%X, irq=%d, dma=%d\n", | 2813 | printk(KERN_WARNING "parport_pc: Strange, can't probe VIA parallel port: io=0x%X, irq=%d, dma=%d\n", |
2729 | port1, irq, dma); | 2814 | port1, irq, dma); |
2730 | return 0; | 2815 | return 0; |
@@ -2732,8 +2817,8 @@ static int __devinit sio_via_probe (struct pci_dev *pdev, int autoirq, | |||
2732 | 2817 | ||
2733 | 2818 | ||
2734 | enum parport_pc_sio_types { | 2819 | enum parport_pc_sio_types { |
2735 | sio_via_686a = 0, /* Via VT82C686A motherboard Super I/O */ | 2820 | sio_via_686a = 0, /* Via VT82C686A motherboard Super I/O */ |
2736 | sio_via_8231, /* Via VT8231 south bridge integrated Super IO */ | 2821 | sio_via_8231, /* Via VT8231 south bridge integrated Super IO */ |
2737 | sio_ite_8872, | 2822 | sio_ite_8872, |
2738 | last_sio | 2823 | last_sio |
2739 | }; | 2824 | }; |
@@ -2804,15 +2889,15 @@ enum parport_pc_pci_cards { | |||
2804 | }; | 2889 | }; |
2805 | 2890 | ||
2806 | 2891 | ||
2807 | /* each element directly indexed from enum list, above | 2892 | /* each element directly indexed from enum list, above |
2808 | * (but offset by last_sio) */ | 2893 | * (but offset by last_sio) */ |
2809 | static struct parport_pc_pci { | 2894 | static struct parport_pc_pci { |
2810 | int numports; | 2895 | int numports; |
2811 | struct { /* BAR (base address registers) numbers in the config | 2896 | struct { /* BAR (base address registers) numbers in the config |
2812 | space header */ | 2897 | space header */ |
2813 | int lo; | 2898 | int lo; |
2814 | int hi; /* -1 if not there, >6 for offset-method (max | 2899 | int hi; |
2815 | BAR is 6) */ | 2900 | /* -1 if not there, >6 for offset-method (max BAR is 6) */ |
2816 | } addr[4]; | 2901 | } addr[4]; |
2817 | 2902 | ||
2818 | /* If set, this is called immediately after pci_enable_device. | 2903 | /* If set, this is called immediately after pci_enable_device. |
@@ -2857,7 +2942,7 @@ static struct parport_pc_pci { | |||
2857 | /* timedia_4018 */ { 2, { { 0, 1 }, { 2, 3 }, } }, | 2942 | /* timedia_4018 */ { 2, { { 0, 1 }, { 2, 3 }, } }, |
2858 | /* timedia_9018a */ { 2, { { 0, 1 }, { 2, 3 }, } }, | 2943 | /* timedia_9018a */ { 2, { { 0, 1 }, { 2, 3 }, } }, |
2859 | /* SYBA uses fixed offsets in | 2944 | /* SYBA uses fixed offsets in |
2860 | a 1K io window */ | 2945 | a 1K io window */ |
2861 | /* syba_2p_epp AP138B */ { 2, { { 0, 0x078 }, { 0, 0x178 }, } }, | 2946 | /* syba_2p_epp AP138B */ { 2, { { 0, 0x078 }, { 0, 0x178 }, } }, |
2862 | /* syba_1p_ecp W83787 */ { 1, { { 0, 0x078 }, } }, | 2947 | /* syba_1p_ecp W83787 */ { 1, { { 0, 0x078 }, } }, |
2863 | /* titan_010l */ { 1, { { 3, -1 }, } }, | 2948 | /* titan_010l */ { 1, { { 3, -1 }, } }, |
@@ -2873,11 +2958,14 @@ static struct parport_pc_pci { | |||
2873 | /* oxsemi_pcie_pport */ { 1, { { 0, 1 }, } }, | 2958 | /* oxsemi_pcie_pport */ { 1, { { 0, 1 }, } }, |
2874 | /* aks_0100 */ { 1, { { 0, -1 }, } }, | 2959 | /* aks_0100 */ { 1, { { 0, -1 }, } }, |
2875 | /* mobility_pp */ { 1, { { 0, 1 }, } }, | 2960 | /* mobility_pp */ { 1, { { 0, 1 }, } }, |
2876 | /* netmos_9705 */ { 1, { { 0, -1 }, } }, /* untested */ | 2961 | |
2877 | /* netmos_9715 */ { 2, { { 0, 1 }, { 2, 3 },} }, /* untested */ | 2962 | /* The netmos entries below are untested */ |
2878 | /* netmos_9755 */ { 2, { { 0, 1 }, { 2, 3 },} }, /* untested */ | 2963 | /* netmos_9705 */ { 1, { { 0, -1 }, } }, |
2879 | /* netmos_9805 */ { 1, { { 0, -1 }, } }, /* untested */ | 2964 | /* netmos_9715 */ { 2, { { 0, 1 }, { 2, 3 },} }, |
2880 | /* netmos_9815 */ { 2, { { 0, -1 }, { 2, -1 }, } }, /* untested */ | 2965 | /* netmos_9755 */ { 2, { { 0, 1 }, { 2, 3 },} }, |
2966 | /* netmos_9805 */ { 1, { { 0, -1 }, } }, | ||
2967 | /* netmos_9815 */ { 2, { { 0, -1 }, { 2, -1 }, } }, | ||
2968 | |||
2881 | /* quatech_sppxp100 */ { 1, { { 0, 1 }, } }, | 2969 | /* quatech_sppxp100 */ { 1, { { 0, 1 }, } }, |
2882 | }; | 2970 | }; |
2883 | 2971 | ||
@@ -2906,7 +2994,7 @@ static const struct pci_device_id parport_pc_pci_tbl[] = { | |||
2906 | { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_BOCA_IOPPAR, | 2994 | { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_BOCA_IOPPAR, |
2907 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, boca_ioppar }, | 2995 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, boca_ioppar }, |
2908 | { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050, | 2996 | { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050, |
2909 | PCI_SUBVENDOR_ID_EXSYS, PCI_SUBDEVICE_ID_EXSYS_4014, 0,0, plx_9050 }, | 2997 | PCI_SUBVENDOR_ID_EXSYS, PCI_SUBDEVICE_ID_EXSYS_4014, 0, 0, plx_9050 }, |
2910 | /* PCI_VENDOR_ID_TIMEDIA/SUNIX has many differing cards ...*/ | 2998 | /* PCI_VENDOR_ID_TIMEDIA/SUNIX has many differing cards ...*/ |
2911 | { 0x1409, 0x7168, 0x1409, 0x4078, 0, 0, timedia_4078a }, | 2999 | { 0x1409, 0x7168, 0x1409, 0x4078, 0, 0, timedia_4078a }, |
2912 | { 0x1409, 0x7168, 0x1409, 0x4079, 0, 0, timedia_4079h }, | 3000 | { 0x1409, 0x7168, 0x1409, 0x4079, 0, 0, timedia_4079h }, |
@@ -2940,7 +3028,8 @@ static const struct pci_device_id parport_pc_pci_tbl[] = { | |||
2940 | { 0x9710, 0x9805, 0x1000, 0x0010, 0, 0, titan_1284p1 }, | 3028 | { 0x9710, 0x9805, 0x1000, 0x0010, 0, 0, titan_1284p1 }, |
2941 | { 0x9710, 0x9815, 0x1000, 0x0020, 0, 0, titan_1284p2 }, | 3029 | { 0x9710, 0x9815, 0x1000, 0x0020, 0, 0, titan_1284p2 }, |
2942 | /* PCI_VENDOR_ID_AVLAB/Intek21 has another bunch of cards ...*/ | 3030 | /* PCI_VENDOR_ID_AVLAB/Intek21 has another bunch of cards ...*/ |
2943 | { 0x14db, 0x2120, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1p}, /* AFAVLAB_TK9902 */ | 3031 | /* AFAVLAB_TK9902 */ |
3032 | { 0x14db, 0x2120, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1p}, | ||
2944 | { 0x14db, 0x2121, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2p}, | 3033 | { 0x14db, 0x2121, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2p}, |
2945 | { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI952PP, | 3034 | { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI952PP, |
2946 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_952 }, | 3035 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_952 }, |
@@ -2983,14 +3072,14 @@ static const struct pci_device_id parport_pc_pci_tbl[] = { | |||
2983 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, quatech_sppxp100 }, | 3072 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, quatech_sppxp100 }, |
2984 | { 0, } /* terminate list */ | 3073 | { 0, } /* terminate list */ |
2985 | }; | 3074 | }; |
2986 | MODULE_DEVICE_TABLE(pci,parport_pc_pci_tbl); | 3075 | MODULE_DEVICE_TABLE(pci, parport_pc_pci_tbl); |
2987 | 3076 | ||
2988 | struct pci_parport_data { | 3077 | struct pci_parport_data { |
2989 | int num; | 3078 | int num; |
2990 | struct parport *ports[2]; | 3079 | struct parport *ports[2]; |
2991 | }; | 3080 | }; |
2992 | 3081 | ||
2993 | static int parport_pc_pci_probe (struct pci_dev *dev, | 3082 | static int parport_pc_pci_probe(struct pci_dev *dev, |
2994 | const struct pci_device_id *id) | 3083 | const struct pci_device_id *id) |
2995 | { | 3084 | { |
2996 | int err, count, n, i = id->driver_data; | 3085 | int err, count, n, i = id->driver_data; |
@@ -3003,7 +3092,8 @@ static int parport_pc_pci_probe (struct pci_dev *dev, | |||
3003 | /* This is a PCI card */ | 3092 | /* This is a PCI card */ |
3004 | i -= last_sio; | 3093 | i -= last_sio; |
3005 | count = 0; | 3094 | count = 0; |
3006 | if ((err = pci_enable_device (dev)) != 0) | 3095 | err = pci_enable_device(dev); |
3096 | if (err) | ||
3007 | return err; | 3097 | return err; |
3008 | 3098 | ||
3009 | data = kmalloc(sizeof(struct pci_parport_data), GFP_KERNEL); | 3099 | data = kmalloc(sizeof(struct pci_parport_data), GFP_KERNEL); |
@@ -3011,7 +3101,7 @@ static int parport_pc_pci_probe (struct pci_dev *dev, | |||
3011 | return -ENOMEM; | 3101 | return -ENOMEM; |
3012 | 3102 | ||
3013 | if (cards[i].preinit_hook && | 3103 | if (cards[i].preinit_hook && |
3014 | cards[i].preinit_hook (dev, PARPORT_IRQ_NONE, PARPORT_DMA_NONE)) { | 3104 | cards[i].preinit_hook(dev, PARPORT_IRQ_NONE, PARPORT_DMA_NONE)) { |
3015 | kfree(data); | 3105 | kfree(data); |
3016 | return -ENODEV; | 3106 | return -ENODEV; |
3017 | } | 3107 | } |
@@ -3021,25 +3111,25 @@ static int parport_pc_pci_probe (struct pci_dev *dev, | |||
3021 | int hi = cards[i].addr[n].hi; | 3111 | int hi = cards[i].addr[n].hi; |
3022 | int irq; | 3112 | int irq; |
3023 | unsigned long io_lo, io_hi; | 3113 | unsigned long io_lo, io_hi; |
3024 | io_lo = pci_resource_start (dev, lo); | 3114 | io_lo = pci_resource_start(dev, lo); |
3025 | io_hi = 0; | 3115 | io_hi = 0; |
3026 | if ((hi >= 0) && (hi <= 6)) | 3116 | if ((hi >= 0) && (hi <= 6)) |
3027 | io_hi = pci_resource_start (dev, hi); | 3117 | io_hi = pci_resource_start(dev, hi); |
3028 | else if (hi > 6) | 3118 | else if (hi > 6) |
3029 | io_lo += hi; /* Reinterpret the meaning of | 3119 | io_lo += hi; /* Reinterpret the meaning of |
3030 | "hi" as an offset (see SYBA | 3120 | "hi" as an offset (see SYBA |
3031 | def.) */ | 3121 | def.) */ |
3032 | /* TODO: test if sharing interrupts works */ | 3122 | /* TODO: test if sharing interrupts works */ |
3033 | irq = dev->irq; | 3123 | irq = dev->irq; |
3034 | if (irq == IRQ_NONE) { | 3124 | if (irq == IRQ_NONE) { |
3035 | printk (KERN_DEBUG | 3125 | printk(KERN_DEBUG |
3036 | "PCI parallel port detected: %04x:%04x, I/O at %#lx(%#lx)\n", | 3126 | "PCI parallel port detected: %04x:%04x, I/O at %#lx(%#lx)\n", |
3037 | parport_pc_pci_tbl[i + last_sio].vendor, | 3127 | parport_pc_pci_tbl[i + last_sio].vendor, |
3038 | parport_pc_pci_tbl[i + last_sio].device, | 3128 | parport_pc_pci_tbl[i + last_sio].device, |
3039 | io_lo, io_hi); | 3129 | io_lo, io_hi); |
3040 | irq = PARPORT_IRQ_NONE; | 3130 | irq = PARPORT_IRQ_NONE; |
3041 | } else { | 3131 | } else { |
3042 | printk (KERN_DEBUG | 3132 | printk(KERN_DEBUG |
3043 | "PCI parallel port detected: %04x:%04x, I/O at %#lx(%#lx), IRQ %d\n", | 3133 | "PCI parallel port detected: %04x:%04x, I/O at %#lx(%#lx), IRQ %d\n", |
3044 | parport_pc_pci_tbl[i + last_sio].vendor, | 3134 | parport_pc_pci_tbl[i + last_sio].vendor, |
3045 | parport_pc_pci_tbl[i + last_sio].device, | 3135 | parport_pc_pci_tbl[i + last_sio].device, |
@@ -3056,7 +3146,7 @@ static int parport_pc_pci_probe (struct pci_dev *dev, | |||
3056 | data->num = count; | 3146 | data->num = count; |
3057 | 3147 | ||
3058 | if (cards[i].postinit_hook) | 3148 | if (cards[i].postinit_hook) |
3059 | cards[i].postinit_hook (dev, count == 0); | 3149 | cards[i].postinit_hook(dev, count == 0); |
3060 | 3150 | ||
3061 | if (count) { | 3151 | if (count) { |
3062 | pci_set_drvdata(dev, data); | 3152 | pci_set_drvdata(dev, data); |
@@ -3090,7 +3180,7 @@ static struct pci_driver parport_pc_pci_driver = { | |||
3090 | .remove = __devexit_p(parport_pc_pci_remove), | 3180 | .remove = __devexit_p(parport_pc_pci_remove), |
3091 | }; | 3181 | }; |
3092 | 3182 | ||
3093 | static int __init parport_pc_init_superio (int autoirq, int autodma) | 3183 | static int __init parport_pc_init_superio(int autoirq, int autodma) |
3094 | { | 3184 | { |
3095 | const struct pci_device_id *id; | 3185 | const struct pci_device_id *id; |
3096 | struct pci_dev *pdev = NULL; | 3186 | struct pci_dev *pdev = NULL; |
@@ -3101,8 +3191,9 @@ static int __init parport_pc_init_superio (int autoirq, int autodma) | |||
3101 | if (id == NULL || id->driver_data >= last_sio) | 3191 | if (id == NULL || id->driver_data >= last_sio) |
3102 | continue; | 3192 | continue; |
3103 | 3193 | ||
3104 | if (parport_pc_superio_info[id->driver_data].probe | 3194 | if (parport_pc_superio_info[id->driver_data].probe( |
3105 | (pdev, autoirq, autodma,parport_pc_superio_info[id->driver_data].via)) { | 3195 | pdev, autoirq, autodma, |
3196 | parport_pc_superio_info[id->driver_data].via)) { | ||
3106 | ret++; | 3197 | ret++; |
3107 | } | 3198 | } |
3108 | } | 3199 | } |
@@ -3111,7 +3202,10 @@ static int __init parport_pc_init_superio (int autoirq, int autodma) | |||
3111 | } | 3202 | } |
3112 | #else | 3203 | #else |
3113 | static struct pci_driver parport_pc_pci_driver; | 3204 | static struct pci_driver parport_pc_pci_driver; |
3114 | static int __init parport_pc_init_superio(int autoirq, int autodma) {return 0;} | 3205 | static int __init parport_pc_init_superio(int autoirq, int autodma) |
3206 | { | ||
3207 | return 0; | ||
3208 | } | ||
3115 | #endif /* CONFIG_PCI */ | 3209 | #endif /* CONFIG_PCI */ |
3116 | 3210 | ||
3117 | #ifdef CONFIG_PNP | 3211 | #ifdef CONFIG_PNP |
@@ -3124,44 +3218,45 @@ static const struct pnp_device_id parport_pc_pnp_tbl[] = { | |||
3124 | { } | 3218 | { } |
3125 | }; | 3219 | }; |
3126 | 3220 | ||
3127 | MODULE_DEVICE_TABLE(pnp,parport_pc_pnp_tbl); | 3221 | MODULE_DEVICE_TABLE(pnp, parport_pc_pnp_tbl); |
3128 | 3222 | ||
3129 | static int parport_pc_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *id) | 3223 | static int parport_pc_pnp_probe(struct pnp_dev *dev, |
3224 | const struct pnp_device_id *id) | ||
3130 | { | 3225 | { |
3131 | struct parport *pdata; | 3226 | struct parport *pdata; |
3132 | unsigned long io_lo, io_hi; | 3227 | unsigned long io_lo, io_hi; |
3133 | int dma, irq; | 3228 | int dma, irq; |
3134 | 3229 | ||
3135 | if (pnp_port_valid(dev,0) && | 3230 | if (pnp_port_valid(dev, 0) && |
3136 | !(pnp_port_flags(dev,0) & IORESOURCE_DISABLED)) { | 3231 | !(pnp_port_flags(dev, 0) & IORESOURCE_DISABLED)) { |
3137 | io_lo = pnp_port_start(dev,0); | 3232 | io_lo = pnp_port_start(dev, 0); |
3138 | } else | 3233 | } else |
3139 | return -EINVAL; | 3234 | return -EINVAL; |
3140 | 3235 | ||
3141 | if (pnp_port_valid(dev,1) && | 3236 | if (pnp_port_valid(dev, 1) && |
3142 | !(pnp_port_flags(dev,1) & IORESOURCE_DISABLED)) { | 3237 | !(pnp_port_flags(dev, 1) & IORESOURCE_DISABLED)) { |
3143 | io_hi = pnp_port_start(dev,1); | 3238 | io_hi = pnp_port_start(dev, 1); |
3144 | } else | 3239 | } else |
3145 | io_hi = 0; | 3240 | io_hi = 0; |
3146 | 3241 | ||
3147 | if (pnp_irq_valid(dev,0) && | 3242 | if (pnp_irq_valid(dev, 0) && |
3148 | !(pnp_irq_flags(dev,0) & IORESOURCE_DISABLED)) { | 3243 | !(pnp_irq_flags(dev, 0) & IORESOURCE_DISABLED)) { |
3149 | irq = pnp_irq(dev,0); | 3244 | irq = pnp_irq(dev, 0); |
3150 | } else | 3245 | } else |
3151 | irq = PARPORT_IRQ_NONE; | 3246 | irq = PARPORT_IRQ_NONE; |
3152 | 3247 | ||
3153 | if (pnp_dma_valid(dev,0) && | 3248 | if (pnp_dma_valid(dev, 0) && |
3154 | !(pnp_dma_flags(dev,0) & IORESOURCE_DISABLED)) { | 3249 | !(pnp_dma_flags(dev, 0) & IORESOURCE_DISABLED)) { |
3155 | dma = pnp_dma(dev,0); | 3250 | dma = pnp_dma(dev, 0); |
3156 | } else | 3251 | } else |
3157 | dma = PARPORT_DMA_NONE; | 3252 | dma = PARPORT_DMA_NONE; |
3158 | 3253 | ||
3159 | dev_info(&dev->dev, "reported by %s\n", dev->protocol->name); | 3254 | dev_info(&dev->dev, "reported by %s\n", dev->protocol->name); |
3160 | if (!(pdata = parport_pc_probe_port(io_lo, io_hi, | 3255 | pdata = parport_pc_probe_port(io_lo, io_hi, irq, dma, &dev->dev, 0); |
3161 | irq, dma, &dev->dev, 0))) | 3256 | if (pdata == NULL) |
3162 | return -ENODEV; | 3257 | return -ENODEV; |
3163 | 3258 | ||
3164 | pnp_set_drvdata(dev,pdata); | 3259 | pnp_set_drvdata(dev, pdata); |
3165 | return 0; | 3260 | return 0; |
3166 | } | 3261 | } |
3167 | 3262 | ||
@@ -3203,7 +3298,7 @@ static struct platform_driver parport_pc_platform_driver = { | |||
3203 | 3298 | ||
3204 | /* This is called by parport_pc_find_nonpci_ports (in asm/parport.h) */ | 3299 | /* This is called by parport_pc_find_nonpci_ports (in asm/parport.h) */ |
3205 | static int __devinit __attribute__((unused)) | 3300 | static int __devinit __attribute__((unused)) |
3206 | parport_pc_find_isa_ports (int autoirq, int autodma) | 3301 | parport_pc_find_isa_ports(int autoirq, int autodma) |
3207 | { | 3302 | { |
3208 | int count = 0; | 3303 | int count = 0; |
3209 | 3304 | ||
@@ -3227,7 +3322,7 @@ parport_pc_find_isa_ports (int autoirq, int autodma) | |||
3227 | * autoirq is PARPORT_IRQ_NONE, PARPORT_IRQ_AUTO, or PARPORT_IRQ_PROBEONLY | 3322 | * autoirq is PARPORT_IRQ_NONE, PARPORT_IRQ_AUTO, or PARPORT_IRQ_PROBEONLY |
3228 | * autodma is PARPORT_DMA_NONE or PARPORT_DMA_AUTO | 3323 | * autodma is PARPORT_DMA_NONE or PARPORT_DMA_AUTO |
3229 | */ | 3324 | */ |
3230 | static void __init parport_pc_find_ports (int autoirq, int autodma) | 3325 | static void __init parport_pc_find_ports(int autoirq, int autodma) |
3231 | { | 3326 | { |
3232 | int count = 0, err; | 3327 | int count = 0, err; |
3233 | 3328 | ||
@@ -3261,11 +3356,18 @@ static void __init parport_pc_find_ports (int autoirq, int autodma) | |||
3261 | * syntax and keep in mind that code below is a cleaned up version. | 3356 | * syntax and keep in mind that code below is a cleaned up version. |
3262 | */ | 3357 | */ |
3263 | 3358 | ||
3264 | static int __initdata io[PARPORT_PC_MAX_PORTS+1] = { [0 ... PARPORT_PC_MAX_PORTS] = 0 }; | 3359 | static int __initdata io[PARPORT_PC_MAX_PORTS+1] = { |
3265 | static int __initdata io_hi[PARPORT_PC_MAX_PORTS+1] = | 3360 | [0 ... PARPORT_PC_MAX_PORTS] = 0 |
3266 | { [0 ... PARPORT_PC_MAX_PORTS] = PARPORT_IOHI_AUTO }; | 3361 | }; |
3267 | static int __initdata dmaval[PARPORT_PC_MAX_PORTS] = { [0 ... PARPORT_PC_MAX_PORTS-1] = PARPORT_DMA_NONE }; | 3362 | static int __initdata io_hi[PARPORT_PC_MAX_PORTS+1] = { |
3268 | static int __initdata irqval[PARPORT_PC_MAX_PORTS] = { [0 ... PARPORT_PC_MAX_PORTS-1] = PARPORT_IRQ_PROBEONLY }; | 3363 | [0 ... PARPORT_PC_MAX_PORTS] = PARPORT_IOHI_AUTO |
3364 | }; | ||
3365 | static int __initdata dmaval[PARPORT_PC_MAX_PORTS] = { | ||
3366 | [0 ... PARPORT_PC_MAX_PORTS-1] = PARPORT_DMA_NONE | ||
3367 | }; | ||
3368 | static int __initdata irqval[PARPORT_PC_MAX_PORTS] = { | ||
3369 | [0 ... PARPORT_PC_MAX_PORTS-1] = PARPORT_IRQ_PROBEONLY | ||
3370 | }; | ||
3269 | 3371 | ||
3270 | static int __init parport_parse_param(const char *s, int *val, | 3372 | static int __init parport_parse_param(const char *s, int *val, |
3271 | int automatic, int none, int nofifo) | 3373 | int automatic, int none, int nofifo) |
@@ -3306,18 +3408,19 @@ static int __init parport_parse_dma(const char *dmastr, int *val) | |||
3306 | #ifdef CONFIG_PCI | 3408 | #ifdef CONFIG_PCI |
3307 | static int __init parport_init_mode_setup(char *str) | 3409 | static int __init parport_init_mode_setup(char *str) |
3308 | { | 3410 | { |
3309 | printk(KERN_DEBUG "parport_pc.c: Specified parameter parport_init_mode=%s\n", str); | 3411 | printk(KERN_DEBUG |
3310 | 3412 | "parport_pc.c: Specified parameter parport_init_mode=%s\n", str); | |
3311 | if (!strcmp (str, "spp")) | 3413 | |
3312 | parport_init_mode=1; | 3414 | if (!strcmp(str, "spp")) |
3313 | if (!strcmp (str, "ps2")) | 3415 | parport_init_mode = 1; |
3314 | parport_init_mode=2; | 3416 | if (!strcmp(str, "ps2")) |
3315 | if (!strcmp (str, "epp")) | 3417 | parport_init_mode = 2; |
3316 | parport_init_mode=3; | 3418 | if (!strcmp(str, "epp")) |
3317 | if (!strcmp (str, "ecp")) | 3419 | parport_init_mode = 3; |
3318 | parport_init_mode=4; | 3420 | if (!strcmp(str, "ecp")) |
3319 | if (!strcmp (str, "ecpepp")) | 3421 | parport_init_mode = 4; |
3320 | parport_init_mode=5; | 3422 | if (!strcmp(str, "ecpepp")) |
3423 | parport_init_mode = 5; | ||
3321 | return 1; | 3424 | return 1; |
3322 | } | 3425 | } |
3323 | #endif | 3426 | #endif |
@@ -3341,7 +3444,8 @@ module_param(verbose_probing, int, 0644); | |||
3341 | #endif | 3444 | #endif |
3342 | #ifdef CONFIG_PCI | 3445 | #ifdef CONFIG_PCI |
3343 | static char *init_mode; | 3446 | static char *init_mode; |
3344 | MODULE_PARM_DESC(init_mode, "Initialise mode for VIA VT8231 port (spp, ps2, epp, ecp or ecpepp)"); | 3447 | MODULE_PARM_DESC(init_mode, |
3448 | "Initialise mode for VIA VT8231 port (spp, ps2, epp, ecp or ecpepp)"); | ||
3345 | module_param(init_mode, charp, 0); | 3449 | module_param(init_mode, charp, 0); |
3346 | #endif | 3450 | #endif |
3347 | 3451 | ||
@@ -3372,7 +3476,7 @@ static int __init parse_parport_params(void) | |||
3372 | irqval[0] = val; | 3476 | irqval[0] = val; |
3373 | break; | 3477 | break; |
3374 | default: | 3478 | default: |
3375 | printk (KERN_WARNING | 3479 | printk(KERN_WARNING |
3376 | "parport_pc: irq specified " | 3480 | "parport_pc: irq specified " |
3377 | "without base address. Use 'io=' " | 3481 | "without base address. Use 'io=' " |
3378 | "to specify one\n"); | 3482 | "to specify one\n"); |
@@ -3385,7 +3489,7 @@ static int __init parse_parport_params(void) | |||
3385 | dmaval[0] = val; | 3489 | dmaval[0] = val; |
3386 | break; | 3490 | break; |
3387 | default: | 3491 | default: |
3388 | printk (KERN_WARNING | 3492 | printk(KERN_WARNING |
3389 | "parport_pc: dma specified " | 3493 | "parport_pc: dma specified " |
3390 | "without base address. Use 'io=' " | 3494 | "without base address. Use 'io=' " |
3391 | "to specify one\n"); | 3495 | "to specify one\n"); |
@@ -3396,7 +3500,7 @@ static int __init parse_parport_params(void) | |||
3396 | 3500 | ||
3397 | #else | 3501 | #else |
3398 | 3502 | ||
3399 | static int parport_setup_ptr __initdata = 0; | 3503 | static int parport_setup_ptr __initdata; |
3400 | 3504 | ||
3401 | /* | 3505 | /* |
3402 | * Acceptable parameters: | 3506 | * Acceptable parameters: |
@@ -3407,7 +3511,7 @@ static int parport_setup_ptr __initdata = 0; | |||
3407 | * | 3511 | * |
3408 | * IRQ/DMA may be numeric or 'auto' or 'none' | 3512 | * IRQ/DMA may be numeric or 'auto' or 'none' |
3409 | */ | 3513 | */ |
3410 | static int __init parport_setup (char *str) | 3514 | static int __init parport_setup(char *str) |
3411 | { | 3515 | { |
3412 | char *endptr; | 3516 | char *endptr; |
3413 | char *sep; | 3517 | char *sep; |
@@ -3419,15 +3523,15 @@ static int __init parport_setup (char *str) | |||
3419 | return 1; | 3523 | return 1; |
3420 | } | 3524 | } |
3421 | 3525 | ||
3422 | if (!strncmp (str, "auto", 4)) { | 3526 | if (!strncmp(str, "auto", 4)) { |
3423 | irqval[0] = PARPORT_IRQ_AUTO; | 3527 | irqval[0] = PARPORT_IRQ_AUTO; |
3424 | dmaval[0] = PARPORT_DMA_AUTO; | 3528 | dmaval[0] = PARPORT_DMA_AUTO; |
3425 | return 1; | 3529 | return 1; |
3426 | } | 3530 | } |
3427 | 3531 | ||
3428 | val = simple_strtoul (str, &endptr, 0); | 3532 | val = simple_strtoul(str, &endptr, 0); |
3429 | if (endptr == str) { | 3533 | if (endptr == str) { |
3430 | printk (KERN_WARNING "parport=%s not understood\n", str); | 3534 | printk(KERN_WARNING "parport=%s not understood\n", str); |
3431 | return 1; | 3535 | return 1; |
3432 | } | 3536 | } |
3433 | 3537 | ||
@@ -3461,7 +3565,7 @@ static int __init parse_parport_params(void) | |||
3461 | return io[0] == PARPORT_DISABLE; | 3565 | return io[0] == PARPORT_DISABLE; |
3462 | } | 3566 | } |
3463 | 3567 | ||
3464 | __setup ("parport=", parport_setup); | 3568 | __setup("parport=", parport_setup); |
3465 | 3569 | ||
3466 | /* | 3570 | /* |
3467 | * Acceptable parameters: | 3571 | * Acceptable parameters: |
@@ -3469,7 +3573,7 @@ __setup ("parport=", parport_setup); | |||
3469 | * parport_init_mode=[spp|ps2|epp|ecp|ecpepp] | 3573 | * parport_init_mode=[spp|ps2|epp|ecp|ecpepp] |
3470 | */ | 3574 | */ |
3471 | #ifdef CONFIG_PCI | 3575 | #ifdef CONFIG_PCI |
3472 | __setup("parport_init_mode=",parport_init_mode_setup); | 3576 | __setup("parport_init_mode=", parport_init_mode_setup); |
3473 | #endif | 3577 | #endif |
3474 | #endif | 3578 | #endif |
3475 | 3579 | ||
@@ -3493,13 +3597,13 @@ static int __init parport_pc_init(void) | |||
3493 | for (i = 0; i < PARPORT_PC_MAX_PORTS; i++) { | 3597 | for (i = 0; i < PARPORT_PC_MAX_PORTS; i++) { |
3494 | if (!io[i]) | 3598 | if (!io[i]) |
3495 | break; | 3599 | break; |
3496 | if ((io_hi[i]) == PARPORT_IOHI_AUTO) | 3600 | if (io_hi[i] == PARPORT_IOHI_AUTO) |
3497 | io_hi[i] = 0x400 + io[i]; | 3601 | io_hi[i] = 0x400 + io[i]; |
3498 | parport_pc_probe_port(io[i], io_hi[i], | 3602 | parport_pc_probe_port(io[i], io_hi[i], |
3499 | irqval[i], dmaval[i], NULL, 0); | 3603 | irqval[i], dmaval[i], NULL, 0); |
3500 | } | 3604 | } |
3501 | } else | 3605 | } else |
3502 | parport_pc_find_ports (irqval[0], dmaval[0]); | 3606 | parport_pc_find_ports(irqval[0], dmaval[0]); |
3503 | 3607 | ||
3504 | return 0; | 3608 | return 0; |
3505 | } | 3609 | } |
@@ -3507,9 +3611,9 @@ static int __init parport_pc_init(void) | |||
3507 | static void __exit parport_pc_exit(void) | 3611 | static void __exit parport_pc_exit(void) |
3508 | { | 3612 | { |
3509 | if (pci_registered_parport) | 3613 | if (pci_registered_parport) |
3510 | pci_unregister_driver (&parport_pc_pci_driver); | 3614 | pci_unregister_driver(&parport_pc_pci_driver); |
3511 | if (pnp_registered_parport) | 3615 | if (pnp_registered_parport) |
3512 | pnp_unregister_driver (&parport_pc_pnp_driver); | 3616 | pnp_unregister_driver(&parport_pc_pnp_driver); |
3513 | platform_driver_unregister(&parport_pc_platform_driver); | 3617 | platform_driver_unregister(&parport_pc_platform_driver); |
3514 | 3618 | ||
3515 | while (!list_empty(&ports_list)) { | 3619 | while (!list_empty(&ports_list)) { |
diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c index a0127e93ade0..fb867a9f55e9 100644 --- a/drivers/serial/8250.c +++ b/drivers/serial/8250.c | |||
@@ -287,6 +287,13 @@ static const struct serial8250_config uart_config[] = { | |||
287 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, | 287 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, |
288 | .flags = UART_CAP_FIFO, | 288 | .flags = UART_CAP_FIFO, |
289 | }, | 289 | }, |
290 | [PORT_AR7] = { | ||
291 | .name = "AR7", | ||
292 | .fifo_size = 16, | ||
293 | .tx_loadsz = 16, | ||
294 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_00, | ||
295 | .flags = UART_CAP_FIFO | UART_CAP_AFE, | ||
296 | }, | ||
290 | }; | 297 | }; |
291 | 298 | ||
292 | #if defined (CONFIG_SERIAL_8250_AU1X00) | 299 | #if defined (CONFIG_SERIAL_8250_AU1X00) |
diff --git a/drivers/serial/8250_pci.c b/drivers/serial/8250_pci.c index 938bc1b6c3fa..e371a9c15341 100644 --- a/drivers/serial/8250_pci.c +++ b/drivers/serial/8250_pci.c | |||
@@ -2776,6 +2776,9 @@ static struct pci_device_id serial_pci_tbl[] = { | |||
2776 | { PCI_VENDOR_ID_OXSEMI, 0x950a, | 2776 | { PCI_VENDOR_ID_OXSEMI, 0x950a, |
2777 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, | 2777 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, |
2778 | pbn_b0_2_1130000 }, | 2778 | pbn_b0_2_1130000 }, |
2779 | { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_C950, | ||
2780 | PCI_VENDOR_ID_OXSEMI, PCI_SUBDEVICE_ID_OXSEMI_C950, 0, 0, | ||
2781 | pbn_b0_1_921600 }, | ||
2779 | { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI954, | 2782 | { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI954, |
2780 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, | 2783 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, |
2781 | pbn_b0_4_115200 }, | 2784 | pbn_b0_4_115200 }, |
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig index 343e3a35b6a3..641e800ed693 100644 --- a/drivers/serial/Kconfig +++ b/drivers/serial/Kconfig | |||
@@ -833,6 +833,7 @@ config SERIAL_IMX | |||
833 | bool "IMX serial port support" | 833 | bool "IMX serial port support" |
834 | depends on ARM && (ARCH_IMX || ARCH_MXC) | 834 | depends on ARM && (ARCH_IMX || ARCH_MXC) |
835 | select SERIAL_CORE | 835 | select SERIAL_CORE |
836 | select RATIONAL | ||
836 | help | 837 | help |
837 | If you have a machine based on a Motorola IMX CPU you | 838 | If you have a machine based on a Motorola IMX CPU you |
838 | can enable its onboard serial port by enabling this option. | 839 | can enable its onboard serial port by enabling this option. |
@@ -1433,4 +1434,11 @@ config SPORT_BAUD_RATE | |||
1433 | default 19200 if (SERIAL_SPORT_BAUD_RATE_19200) | 1434 | default 19200 if (SERIAL_SPORT_BAUD_RATE_19200) |
1434 | default 9600 if (SERIAL_SPORT_BAUD_RATE_9600) | 1435 | default 9600 if (SERIAL_SPORT_BAUD_RATE_9600) |
1435 | 1436 | ||
1437 | config SERIAL_TIMBERDALE | ||
1438 | tristate "Support for timberdale UART" | ||
1439 | depends on MFD_TIMBERDALE | ||
1440 | select SERIAL_CORE | ||
1441 | ---help--- | ||
1442 | Add support for UART controller on timberdale. | ||
1443 | |||
1436 | endmenu | 1444 | endmenu |
diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile index d438eb2a73de..45a8658f54d5 100644 --- a/drivers/serial/Makefile +++ b/drivers/serial/Makefile | |||
@@ -77,3 +77,4 @@ obj-$(CONFIG_SERIAL_OF_PLATFORM_NWPSERIAL) += nwpserial.o | |||
77 | obj-$(CONFIG_SERIAL_KS8695) += serial_ks8695.o | 77 | obj-$(CONFIG_SERIAL_KS8695) += serial_ks8695.o |
78 | obj-$(CONFIG_KGDB_SERIAL_CONSOLE) += kgdboc.o | 78 | obj-$(CONFIG_KGDB_SERIAL_CONSOLE) += kgdboc.o |
79 | obj-$(CONFIG_SERIAL_QE) += ucc_uart.o | 79 | obj-$(CONFIG_SERIAL_QE) += ucc_uart.o |
80 | obj-$(CONFIG_SERIAL_TIMBERDALE) += timbuart.o | ||
diff --git a/drivers/serial/bfin_5xx.c b/drivers/serial/bfin_5xx.c index d86123e03391..e2f6b1bfac98 100644 --- a/drivers/serial/bfin_5xx.c +++ b/drivers/serial/bfin_5xx.c | |||
@@ -330,6 +330,11 @@ static void bfin_serial_tx_chars(struct bfin_serial_port *uart) | |||
330 | /* Clear TFI bit */ | 330 | /* Clear TFI bit */ |
331 | UART_PUT_LSR(uart, TFI); | 331 | UART_PUT_LSR(uart, TFI); |
332 | #endif | 332 | #endif |
333 | /* Anomaly notes: | ||
334 | * 05000215 - we always clear ETBEI within last UART TX | ||
335 | * interrupt to end a string. It is always set | ||
336 | * when start a new tx. | ||
337 | */ | ||
333 | UART_CLEAR_IER(uart, ETBEI); | 338 | UART_CLEAR_IER(uart, ETBEI); |
334 | return; | 339 | return; |
335 | } | 340 | } |
@@ -415,6 +420,7 @@ static void bfin_serial_dma_tx_chars(struct bfin_serial_port *uart) | |||
415 | set_dma_start_addr(uart->tx_dma_channel, (unsigned long)(xmit->buf+xmit->tail)); | 420 | set_dma_start_addr(uart->tx_dma_channel, (unsigned long)(xmit->buf+xmit->tail)); |
416 | set_dma_x_count(uart->tx_dma_channel, uart->tx_count); | 421 | set_dma_x_count(uart->tx_dma_channel, uart->tx_count); |
417 | set_dma_x_modify(uart->tx_dma_channel, 1); | 422 | set_dma_x_modify(uart->tx_dma_channel, 1); |
423 | SSYNC(); | ||
418 | enable_dma(uart->tx_dma_channel); | 424 | enable_dma(uart->tx_dma_channel); |
419 | 425 | ||
420 | UART_SET_IER(uart, ETBEI); | 426 | UART_SET_IER(uart, ETBEI); |
@@ -473,27 +479,41 @@ static void bfin_serial_dma_rx_chars(struct bfin_serial_port *uart) | |||
473 | void bfin_serial_rx_dma_timeout(struct bfin_serial_port *uart) | 479 | void bfin_serial_rx_dma_timeout(struct bfin_serial_port *uart) |
474 | { | 480 | { |
475 | int x_pos, pos; | 481 | int x_pos, pos; |
476 | unsigned long flags; | ||
477 | |||
478 | spin_lock_irqsave(&uart->port.lock, flags); | ||
479 | 482 | ||
483 | dma_disable_irq(uart->rx_dma_channel); | ||
484 | spin_lock_bh(&uart->port.lock); | ||
485 | |||
486 | /* 2D DMA RX buffer ring is used. Because curr_y_count and | ||
487 | * curr_x_count can't be read as an atomic operation, | ||
488 | * curr_y_count should be read before curr_x_count. When | ||
489 | * curr_x_count is read, curr_y_count may already indicate | ||
490 | * next buffer line. But, the position calculated here is | ||
491 | * still indicate the old line. The wrong position data may | ||
492 | * be smaller than current buffer tail, which cause garbages | ||
493 | * are received if it is not prohibit. | ||
494 | */ | ||
480 | uart->rx_dma_nrows = get_dma_curr_ycount(uart->rx_dma_channel); | 495 | uart->rx_dma_nrows = get_dma_curr_ycount(uart->rx_dma_channel); |
481 | x_pos = get_dma_curr_xcount(uart->rx_dma_channel); | 496 | x_pos = get_dma_curr_xcount(uart->rx_dma_channel); |
482 | uart->rx_dma_nrows = DMA_RX_YCOUNT - uart->rx_dma_nrows; | 497 | uart->rx_dma_nrows = DMA_RX_YCOUNT - uart->rx_dma_nrows; |
483 | if (uart->rx_dma_nrows == DMA_RX_YCOUNT) | 498 | if (uart->rx_dma_nrows == DMA_RX_YCOUNT || x_pos == 0) |
484 | uart->rx_dma_nrows = 0; | 499 | uart->rx_dma_nrows = 0; |
485 | x_pos = DMA_RX_XCOUNT - x_pos; | 500 | x_pos = DMA_RX_XCOUNT - x_pos; |
486 | if (x_pos == DMA_RX_XCOUNT) | 501 | if (x_pos == DMA_RX_XCOUNT) |
487 | x_pos = 0; | 502 | x_pos = 0; |
488 | 503 | ||
489 | pos = uart->rx_dma_nrows * DMA_RX_XCOUNT + x_pos; | 504 | pos = uart->rx_dma_nrows * DMA_RX_XCOUNT + x_pos; |
490 | if (pos != uart->rx_dma_buf.tail) { | 505 | /* Ignore receiving data if new position is in the same line of |
506 | * current buffer tail and small. | ||
507 | */ | ||
508 | if (pos > uart->rx_dma_buf.tail || | ||
509 | uart->rx_dma_nrows < (uart->rx_dma_buf.tail/DMA_RX_XCOUNT)) { | ||
491 | uart->rx_dma_buf.head = pos; | 510 | uart->rx_dma_buf.head = pos; |
492 | bfin_serial_dma_rx_chars(uart); | 511 | bfin_serial_dma_rx_chars(uart); |
493 | uart->rx_dma_buf.tail = uart->rx_dma_buf.head; | 512 | uart->rx_dma_buf.tail = uart->rx_dma_buf.head; |
494 | } | 513 | } |
495 | 514 | ||
496 | spin_unlock_irqrestore(&uart->port.lock, flags); | 515 | spin_unlock_bh(&uart->port.lock); |
516 | dma_enable_irq(uart->rx_dma_channel); | ||
497 | 517 | ||
498 | mod_timer(&(uart->rx_dma_timer), jiffies + DMA_RX_FLUSH_JIFFIES); | 518 | mod_timer(&(uart->rx_dma_timer), jiffies + DMA_RX_FLUSH_JIFFIES); |
499 | } | 519 | } |
@@ -514,6 +534,11 @@ static irqreturn_t bfin_serial_dma_tx_int(int irq, void *dev_id) | |||
514 | if (!(get_dma_curr_irqstat(uart->tx_dma_channel)&DMA_RUN)) { | 534 | if (!(get_dma_curr_irqstat(uart->tx_dma_channel)&DMA_RUN)) { |
515 | disable_dma(uart->tx_dma_channel); | 535 | disable_dma(uart->tx_dma_channel); |
516 | clear_dma_irqstat(uart->tx_dma_channel); | 536 | clear_dma_irqstat(uart->tx_dma_channel); |
537 | /* Anomaly notes: | ||
538 | * 05000215 - we always clear ETBEI within last UART TX | ||
539 | * interrupt to end a string. It is always set | ||
540 | * when start a new tx. | ||
541 | */ | ||
517 | UART_CLEAR_IER(uart, ETBEI); | 542 | UART_CLEAR_IER(uart, ETBEI); |
518 | xmit->tail = (xmit->tail + uart->tx_count) & (UART_XMIT_SIZE - 1); | 543 | xmit->tail = (xmit->tail + uart->tx_count) & (UART_XMIT_SIZE - 1); |
519 | uart->port.icount.tx += uart->tx_count; | 544 | uart->port.icount.tx += uart->tx_count; |
@@ -532,11 +557,26 @@ static irqreturn_t bfin_serial_dma_rx_int(int irq, void *dev_id) | |||
532 | { | 557 | { |
533 | struct bfin_serial_port *uart = dev_id; | 558 | struct bfin_serial_port *uart = dev_id; |
534 | unsigned short irqstat; | 559 | unsigned short irqstat; |
560 | int x_pos, pos; | ||
535 | 561 | ||
536 | spin_lock(&uart->port.lock); | 562 | spin_lock(&uart->port.lock); |
537 | irqstat = get_dma_curr_irqstat(uart->rx_dma_channel); | 563 | irqstat = get_dma_curr_irqstat(uart->rx_dma_channel); |
538 | clear_dma_irqstat(uart->rx_dma_channel); | 564 | clear_dma_irqstat(uart->rx_dma_channel); |
539 | bfin_serial_dma_rx_chars(uart); | 565 | |
566 | uart->rx_dma_nrows = get_dma_curr_ycount(uart->rx_dma_channel); | ||
567 | x_pos = get_dma_curr_xcount(uart->rx_dma_channel); | ||
568 | uart->rx_dma_nrows = DMA_RX_YCOUNT - uart->rx_dma_nrows; | ||
569 | if (uart->rx_dma_nrows == DMA_RX_YCOUNT || x_pos == 0) | ||
570 | uart->rx_dma_nrows = 0; | ||
571 | |||
572 | pos = uart->rx_dma_nrows * DMA_RX_XCOUNT; | ||
573 | if (pos > uart->rx_dma_buf.tail || | ||
574 | uart->rx_dma_nrows < (uart->rx_dma_buf.tail/DMA_RX_XCOUNT)) { | ||
575 | uart->rx_dma_buf.head = pos; | ||
576 | bfin_serial_dma_rx_chars(uart); | ||
577 | uart->rx_dma_buf.tail = uart->rx_dma_buf.head; | ||
578 | } | ||
579 | |||
540 | spin_unlock(&uart->port.lock); | 580 | spin_unlock(&uart->port.lock); |
541 | 581 | ||
542 | return IRQ_HANDLED; | 582 | return IRQ_HANDLED; |
@@ -789,8 +829,16 @@ bfin_serial_set_termios(struct uart_port *port, struct ktermios *termios, | |||
789 | __func__); | 829 | __func__); |
790 | } | 830 | } |
791 | 831 | ||
792 | if (termios->c_cflag & CSTOPB) | 832 | /* Anomaly notes: |
793 | lcr |= STB; | 833 | * 05000231 - STOP bit is always set to 1 whatever the user is set. |
834 | */ | ||
835 | if (termios->c_cflag & CSTOPB) { | ||
836 | if (ANOMALY_05000231) | ||
837 | printk(KERN_WARNING "STOP bits other than 1 is not " | ||
838 | "supported in case of anomaly 05000231.\n"); | ||
839 | else | ||
840 | lcr |= STB; | ||
841 | } | ||
794 | if (termios->c_cflag & PARENB) | 842 | if (termios->c_cflag & PARENB) |
795 | lcr |= PEN; | 843 | lcr |= PEN; |
796 | if (!(termios->c_cflag & PARODD)) | 844 | if (!(termios->c_cflag & PARODD)) |
@@ -940,6 +988,10 @@ static void bfin_serial_reset_irda(struct uart_port *port) | |||
940 | } | 988 | } |
941 | 989 | ||
942 | #ifdef CONFIG_CONSOLE_POLL | 990 | #ifdef CONFIG_CONSOLE_POLL |
991 | /* Anomaly notes: | ||
992 | * 05000099 - Because we only use THRE in poll_put and DR in poll_get, | ||
993 | * losing other bits of UART_LSR is not a problem here. | ||
994 | */ | ||
943 | static void bfin_serial_poll_put_char(struct uart_port *port, unsigned char chr) | 995 | static void bfin_serial_poll_put_char(struct uart_port *port, unsigned char chr) |
944 | { | 996 | { |
945 | struct bfin_serial_port *uart = (struct bfin_serial_port *)port; | 997 | struct bfin_serial_port *uart = (struct bfin_serial_port *)port; |
@@ -1245,12 +1297,17 @@ static __init void early_serial_write(struct console *con, const char *s, | |||
1245 | } | 1297 | } |
1246 | } | 1298 | } |
1247 | 1299 | ||
1300 | /* | ||
1301 | * This should have a .setup or .early_setup in it, but then things get called | ||
1302 | * without the command line options, and the baud rate gets messed up - so | ||
1303 | * don't let the common infrastructure play with things. (see calls to setup | ||
1304 | * & earlysetup in ./kernel/printk.c:register_console() | ||
1305 | */ | ||
1248 | static struct __initdata console bfin_early_serial_console = { | 1306 | static struct __initdata console bfin_early_serial_console = { |
1249 | .name = "early_BFuart", | 1307 | .name = "early_BFuart", |
1250 | .write = early_serial_write, | 1308 | .write = early_serial_write, |
1251 | .device = uart_console_device, | 1309 | .device = uart_console_device, |
1252 | .flags = CON_PRINTBUFFER, | 1310 | .flags = CON_PRINTBUFFER, |
1253 | .setup = bfin_serial_console_setup, | ||
1254 | .index = -1, | 1311 | .index = -1, |
1255 | .data = &bfin_serial_reg, | 1312 | .data = &bfin_serial_reg, |
1256 | }; | 1313 | }; |
diff --git a/drivers/serial/bfin_sport_uart.c b/drivers/serial/bfin_sport_uart.c index 529c0ff7952c..34b4ae0fe760 100644 --- a/drivers/serial/bfin_sport_uart.c +++ b/drivers/serial/bfin_sport_uart.c | |||
@@ -101,15 +101,16 @@ static inline void tx_one_byte(struct sport_uart_port *up, unsigned int value) | |||
101 | { | 101 | { |
102 | pr_debug("%s value:%x\n", __func__, value); | 102 | pr_debug("%s value:%x\n", __func__, value); |
103 | /* Place a Start and Stop bit */ | 103 | /* Place a Start and Stop bit */ |
104 | __asm__ volatile ( | 104 | __asm__ __volatile__ ( |
105 | "R2 = b#01111111100;\n\t" | 105 | "R2 = b#01111111100;" |
106 | "R3 = b#10000000001;\n\t" | 106 | "R3 = b#10000000001;" |
107 | "%0 <<= 2;\n\t" | 107 | "%0 <<= 2;" |
108 | "%0 = %0 & R2;\n\t" | 108 | "%0 = %0 & R2;" |
109 | "%0 = %0 | R3;\n\t" | 109 | "%0 = %0 | R3;" |
110 | :"=r"(value) | 110 | : "=d"(value) |
111 | :"0"(value) | 111 | : "d"(value) |
112 | :"R2", "R3"); | 112 | : "ASTAT", "R2", "R3" |
113 | ); | ||
113 | pr_debug("%s value:%x\n", __func__, value); | 114 | pr_debug("%s value:%x\n", __func__, value); |
114 | 115 | ||
115 | SPORT_PUT_TX(up, value); | 116 | SPORT_PUT_TX(up, value); |
@@ -118,27 +119,30 @@ static inline void tx_one_byte(struct sport_uart_port *up, unsigned int value) | |||
118 | static inline unsigned int rx_one_byte(struct sport_uart_port *up) | 119 | static inline unsigned int rx_one_byte(struct sport_uart_port *up) |
119 | { | 120 | { |
120 | unsigned int value, extract; | 121 | unsigned int value, extract; |
122 | u32 tmp_mask1, tmp_mask2, tmp_shift, tmp; | ||
121 | 123 | ||
122 | value = SPORT_GET_RX32(up); | 124 | value = SPORT_GET_RX32(up); |
123 | pr_debug("%s value:%x\n", __func__, value); | 125 | pr_debug("%s value:%x\n", __func__, value); |
124 | 126 | ||
125 | /* Extract 8 bits data */ | 127 | /* Extract 8 bits data */ |
126 | __asm__ volatile ( | 128 | __asm__ __volatile__ ( |
127 | "R5 = 0;\n\t" | 129 | "%[extr] = 0;" |
128 | "P0 = 8;\n\t" | 130 | "%[mask1] = 0x1801(Z);" |
129 | "R1 = 0x1801(Z);\n\t" | 131 | "%[mask2] = 0x0300(Z);" |
130 | "R3 = 0x0300(Z);\n\t" | 132 | "%[shift] = 0;" |
131 | "R4 = 0;\n\t" | 133 | "LSETUP(.Lloop_s, .Lloop_e) LC0 = %[lc];" |
132 | "LSETUP(loop_s, loop_e) LC0 = P0;\nloop_s:\t" | 134 | ".Lloop_s:" |
133 | "R2 = extract(%1, R1.L)(Z);\n\t" | 135 | "%[tmp] = extract(%[val], %[mask1].L)(Z);" |
134 | "R2 <<= R4;\n\t" | 136 | "%[tmp] <<= %[shift];" |
135 | "R5 = R5 | R2;\n\t" | 137 | "%[extr] = %[extr] | %[tmp];" |
136 | "R1 = R1 - R3;\nloop_e:\t" | 138 | "%[mask1] = %[mask1] - %[mask2];" |
137 | "R4 += 1;\n\t" | 139 | ".Lloop_e:" |
138 | "%0 = R5;\n\t" | 140 | "%[shift] += 1;" |
139 | :"=r"(extract) | 141 | : [val]"=d"(value), [extr]"=d"(extract), [shift]"=d"(tmp_shift), [tmp]"=d"(tmp), |
140 | :"r"(value) | 142 | [mask1]"=d"(tmp_mask1), [mask2]"=d"(tmp_mask2) |
141 | :"P0", "R1", "R2","R3","R4", "R5"); | 143 | : "d"(value), [lc]"a"(8) |
144 | : "ASTAT", "LB0", "LC0", "LT0" | ||
145 | ); | ||
142 | 146 | ||
143 | pr_debug(" extract:%x\n", extract); | 147 | pr_debug(" extract:%x\n", extract); |
144 | return extract; | 148 | return extract; |
@@ -149,7 +153,7 @@ static int sport_uart_setup(struct sport_uart_port *up, int sclk, int baud_rate) | |||
149 | int tclkdiv, tfsdiv, rclkdiv; | 153 | int tclkdiv, tfsdiv, rclkdiv; |
150 | 154 | ||
151 | /* Set TCR1 and TCR2 */ | 155 | /* Set TCR1 and TCR2 */ |
152 | SPORT_PUT_TCR1(up, (LTFS | ITFS | TFSR | TLSBIT | ITCLK)); | 156 | SPORT_PUT_TCR1(up, (LATFS | ITFS | TFSR | TLSBIT | ITCLK)); |
153 | SPORT_PUT_TCR2(up, 10); | 157 | SPORT_PUT_TCR2(up, 10); |
154 | pr_debug("%s TCR1:%x, TCR2:%x\n", __func__, SPORT_GET_TCR1(up), SPORT_GET_TCR2(up)); | 158 | pr_debug("%s TCR1:%x, TCR2:%x\n", __func__, SPORT_GET_TCR1(up), SPORT_GET_TCR2(up)); |
155 | 159 | ||
@@ -419,7 +423,7 @@ static void sport_shutdown(struct uart_port *port) | |||
419 | } | 423 | } |
420 | 424 | ||
421 | static void sport_set_termios(struct uart_port *port, | 425 | static void sport_set_termios(struct uart_port *port, |
422 | struct termios *termios, struct termios *old) | 426 | struct ktermios *termios, struct ktermios *old) |
423 | { | 427 | { |
424 | pr_debug("%s enter, c_cflag:%08x\n", __func__, termios->c_cflag); | 428 | pr_debug("%s enter, c_cflag:%08x\n", __func__, termios->c_cflag); |
425 | uart_update_timeout(port, CS8 ,port->uartclk); | 429 | uart_update_timeout(port, CS8 ,port->uartclk); |
diff --git a/drivers/serial/icom.c b/drivers/serial/icom.c index a461b3b2c72d..9f2891c2c4a2 100644 --- a/drivers/serial/icom.c +++ b/drivers/serial/icom.c | |||
@@ -137,7 +137,12 @@ static LIST_HEAD(icom_adapter_head); | |||
137 | static spinlock_t icom_lock; | 137 | static spinlock_t icom_lock; |
138 | 138 | ||
139 | #ifdef ICOM_TRACE | 139 | #ifdef ICOM_TRACE |
140 | static inline void trace(struct icom_port *, char *, unsigned long) {}; | 140 | static inline void trace(struct icom_port *icom_port, char *trace_pt, |
141 | unsigned long trace_data) | ||
142 | { | ||
143 | dev_info(&icom_port->adapter->pci_dev->dev, ":%d:%s - %lx\n", | ||
144 | icom_port->port, trace_pt, trace_data); | ||
145 | } | ||
141 | #else | 146 | #else |
142 | static inline void trace(struct icom_port *icom_port, char *trace_pt, unsigned long trace_data) {}; | 147 | static inline void trace(struct icom_port *icom_port, char *trace_pt, unsigned long trace_data) {}; |
143 | #endif | 148 | #endif |
@@ -408,7 +413,7 @@ static void load_code(struct icom_port *icom_port) | |||
408 | release_firmware(fw); | 413 | release_firmware(fw); |
409 | 414 | ||
410 | /* Set Hardware level */ | 415 | /* Set Hardware level */ |
411 | if ((icom_port->adapter->version | ADAPTER_V2) == ADAPTER_V2) | 416 | if (icom_port->adapter->version == ADAPTER_V2) |
412 | writeb(V2_HARDWARE, &(icom_port->dram->misc_flags)); | 417 | writeb(V2_HARDWARE, &(icom_port->dram->misc_flags)); |
413 | 418 | ||
414 | /* Start the processor in Adapter */ | 419 | /* Start the processor in Adapter */ |
@@ -861,7 +866,7 @@ static irqreturn_t icom_interrupt(int irq, void *dev_id) | |||
861 | /* find icom_port for this interrupt */ | 866 | /* find icom_port for this interrupt */ |
862 | icom_adapter = (struct icom_adapter *) dev_id; | 867 | icom_adapter = (struct icom_adapter *) dev_id; |
863 | 868 | ||
864 | if ((icom_adapter->version | ADAPTER_V2) == ADAPTER_V2) { | 869 | if (icom_adapter->version == ADAPTER_V2) { |
865 | int_reg = icom_adapter->base_addr + 0x8024; | 870 | int_reg = icom_adapter->base_addr + 0x8024; |
866 | 871 | ||
867 | adapter_interrupts = readl(int_reg); | 872 | adapter_interrupts = readl(int_reg); |
@@ -1647,15 +1652,6 @@ static void __exit icom_exit(void) | |||
1647 | module_init(icom_init); | 1652 | module_init(icom_init); |
1648 | module_exit(icom_exit); | 1653 | module_exit(icom_exit); |
1649 | 1654 | ||
1650 | #ifdef ICOM_TRACE | ||
1651 | static inline void trace(struct icom_port *icom_port, char *trace_pt, | ||
1652 | unsigned long trace_data) | ||
1653 | { | ||
1654 | dev_info(&icom_port->adapter->pci_dev->dev, ":%d:%s - %lx\n", | ||
1655 | icom_port->port, trace_pt, trace_data); | ||
1656 | } | ||
1657 | #endif | ||
1658 | |||
1659 | MODULE_AUTHOR("Michael Anderson <mjanders@us.ibm.com>"); | 1655 | MODULE_AUTHOR("Michael Anderson <mjanders@us.ibm.com>"); |
1660 | MODULE_DESCRIPTION("IBM iSeries Serial IOA driver"); | 1656 | MODULE_DESCRIPTION("IBM iSeries Serial IOA driver"); |
1661 | MODULE_SUPPORTED_DEVICE | 1657 | MODULE_SUPPORTED_DEVICE |
diff --git a/drivers/serial/imx.c b/drivers/serial/imx.c index 5f0be40dfdab..7b5d1de9cfe3 100644 --- a/drivers/serial/imx.c +++ b/drivers/serial/imx.c | |||
@@ -8,6 +8,9 @@ | |||
8 | * Author: Sascha Hauer <sascha@saschahauer.de> | 8 | * Author: Sascha Hauer <sascha@saschahauer.de> |
9 | * Copyright (C) 2004 Pengutronix | 9 | * Copyright (C) 2004 Pengutronix |
10 | * | 10 | * |
11 | * Copyright (C) 2009 emlix GmbH | ||
12 | * Author: Fabian Godehardt (added IrDA support for iMX) | ||
13 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | 14 | * 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 | 15 | * 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 | 16 | * the Free Software Foundation; either version 2 of the License, or |
@@ -41,6 +44,8 @@ | |||
41 | #include <linux/serial_core.h> | 44 | #include <linux/serial_core.h> |
42 | #include <linux/serial.h> | 45 | #include <linux/serial.h> |
43 | #include <linux/clk.h> | 46 | #include <linux/clk.h> |
47 | #include <linux/delay.h> | ||
48 | #include <linux/rational.h> | ||
44 | 49 | ||
45 | #include <asm/io.h> | 50 | #include <asm/io.h> |
46 | #include <asm/irq.h> | 51 | #include <asm/irq.h> |
@@ -148,6 +153,7 @@ | |||
148 | #define UCR4_DREN (1<<0) /* Recv data ready interrupt enable */ | 153 | #define UCR4_DREN (1<<0) /* Recv data ready interrupt enable */ |
149 | #define UFCR_RXTL_SHF 0 /* Receiver trigger level shift */ | 154 | #define UFCR_RXTL_SHF 0 /* Receiver trigger level shift */ |
150 | #define UFCR_RFDIV (7<<7) /* Reference freq divider mask */ | 155 | #define UFCR_RFDIV (7<<7) /* Reference freq divider mask */ |
156 | #define UFCR_RFDIV_REG(x) (((x) < 7 ? 6 - (x) : 6) << 7) | ||
151 | #define UFCR_TXTL_SHF 10 /* Transmitter trigger level shift */ | 157 | #define UFCR_TXTL_SHF 10 /* Transmitter trigger level shift */ |
152 | #define USR1_PARITYERR (1<<15) /* Parity error interrupt flag */ | 158 | #define USR1_PARITYERR (1<<15) /* Parity error interrupt flag */ |
153 | #define USR1_RTSS (1<<14) /* RTS pin status */ | 159 | #define USR1_RTSS (1<<14) /* RTS pin status */ |
@@ -211,10 +217,20 @@ struct imx_port { | |||
211 | struct timer_list timer; | 217 | struct timer_list timer; |
212 | unsigned int old_status; | 218 | unsigned int old_status; |
213 | int txirq,rxirq,rtsirq; | 219 | int txirq,rxirq,rtsirq; |
214 | int have_rtscts:1; | 220 | unsigned int have_rtscts:1; |
221 | unsigned int use_irda:1; | ||
222 | unsigned int irda_inv_rx:1; | ||
223 | unsigned int irda_inv_tx:1; | ||
224 | unsigned short trcv_delay; /* transceiver delay */ | ||
215 | struct clk *clk; | 225 | struct clk *clk; |
216 | }; | 226 | }; |
217 | 227 | ||
228 | #ifdef CONFIG_IRDA | ||
229 | #define USE_IRDA(sport) ((sport)->use_irda) | ||
230 | #else | ||
231 | #define USE_IRDA(sport) (0) | ||
232 | #endif | ||
233 | |||
218 | /* | 234 | /* |
219 | * Handle any change of modem status signal since we were last called. | 235 | * Handle any change of modem status signal since we were last called. |
220 | */ | 236 | */ |
@@ -268,6 +284,48 @@ static void imx_stop_tx(struct uart_port *port) | |||
268 | struct imx_port *sport = (struct imx_port *)port; | 284 | struct imx_port *sport = (struct imx_port *)port; |
269 | unsigned long temp; | 285 | unsigned long temp; |
270 | 286 | ||
287 | if (USE_IRDA(sport)) { | ||
288 | /* half duplex - wait for end of transmission */ | ||
289 | int n = 256; | ||
290 | while ((--n > 0) && | ||
291 | !(readl(sport->port.membase + USR2) & USR2_TXDC)) { | ||
292 | udelay(5); | ||
293 | barrier(); | ||
294 | } | ||
295 | /* | ||
296 | * irda transceiver - wait a bit more to avoid | ||
297 | * cutoff, hardware dependent | ||
298 | */ | ||
299 | udelay(sport->trcv_delay); | ||
300 | |||
301 | /* | ||
302 | * half duplex - reactivate receive mode, | ||
303 | * flush receive pipe echo crap | ||
304 | */ | ||
305 | if (readl(sport->port.membase + USR2) & USR2_TXDC) { | ||
306 | temp = readl(sport->port.membase + UCR1); | ||
307 | temp &= ~(UCR1_TXMPTYEN | UCR1_TRDYEN); | ||
308 | writel(temp, sport->port.membase + UCR1); | ||
309 | |||
310 | temp = readl(sport->port.membase + UCR4); | ||
311 | temp &= ~(UCR4_TCEN); | ||
312 | writel(temp, sport->port.membase + UCR4); | ||
313 | |||
314 | while (readl(sport->port.membase + URXD0) & | ||
315 | URXD_CHARRDY) | ||
316 | barrier(); | ||
317 | |||
318 | temp = readl(sport->port.membase + UCR1); | ||
319 | temp |= UCR1_RRDYEN; | ||
320 | writel(temp, sport->port.membase + UCR1); | ||
321 | |||
322 | temp = readl(sport->port.membase + UCR4); | ||
323 | temp |= UCR4_DREN; | ||
324 | writel(temp, sport->port.membase + UCR4); | ||
325 | } | ||
326 | return; | ||
327 | } | ||
328 | |||
271 | temp = readl(sport->port.membase + UCR1); | 329 | temp = readl(sport->port.membase + UCR1); |
272 | writel(temp & ~UCR1_TXMPTYEN, sport->port.membase + UCR1); | 330 | writel(temp & ~UCR1_TXMPTYEN, sport->port.membase + UCR1); |
273 | } | 331 | } |
@@ -302,13 +360,15 @@ static inline void imx_transmit_buffer(struct imx_port *sport) | |||
302 | /* send xmit->buf[xmit->tail] | 360 | /* send xmit->buf[xmit->tail] |
303 | * out the port here */ | 361 | * out the port here */ |
304 | writel(xmit->buf[xmit->tail], sport->port.membase + URTX0); | 362 | writel(xmit->buf[xmit->tail], sport->port.membase + URTX0); |
305 | xmit->tail = (xmit->tail + 1) & | 363 | xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); |
306 | (UART_XMIT_SIZE - 1); | ||
307 | sport->port.icount.tx++; | 364 | sport->port.icount.tx++; |
308 | if (uart_circ_empty(xmit)) | 365 | if (uart_circ_empty(xmit)) |
309 | break; | 366 | break; |
310 | } | 367 | } |
311 | 368 | ||
369 | if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) | ||
370 | uart_write_wakeup(&sport->port); | ||
371 | |||
312 | if (uart_circ_empty(xmit)) | 372 | if (uart_circ_empty(xmit)) |
313 | imx_stop_tx(&sport->port); | 373 | imx_stop_tx(&sport->port); |
314 | } | 374 | } |
@@ -321,9 +381,30 @@ static void imx_start_tx(struct uart_port *port) | |||
321 | struct imx_port *sport = (struct imx_port *)port; | 381 | struct imx_port *sport = (struct imx_port *)port; |
322 | unsigned long temp; | 382 | unsigned long temp; |
323 | 383 | ||
384 | if (USE_IRDA(sport)) { | ||
385 | /* half duplex in IrDA mode; have to disable receive mode */ | ||
386 | temp = readl(sport->port.membase + UCR4); | ||
387 | temp &= ~(UCR4_DREN); | ||
388 | writel(temp, sport->port.membase + UCR4); | ||
389 | |||
390 | temp = readl(sport->port.membase + UCR1); | ||
391 | temp &= ~(UCR1_RRDYEN); | ||
392 | writel(temp, sport->port.membase + UCR1); | ||
393 | } | ||
394 | |||
324 | temp = readl(sport->port.membase + UCR1); | 395 | temp = readl(sport->port.membase + UCR1); |
325 | writel(temp | UCR1_TXMPTYEN, sport->port.membase + UCR1); | 396 | writel(temp | UCR1_TXMPTYEN, sport->port.membase + UCR1); |
326 | 397 | ||
398 | if (USE_IRDA(sport)) { | ||
399 | temp = readl(sport->port.membase + UCR1); | ||
400 | temp |= UCR1_TRDYEN; | ||
401 | writel(temp, sport->port.membase + UCR1); | ||
402 | |||
403 | temp = readl(sport->port.membase + UCR4); | ||
404 | temp |= UCR4_TCEN; | ||
405 | writel(temp, sport->port.membase + UCR4); | ||
406 | } | ||
407 | |||
327 | if (readl(sport->port.membase + UTS) & UTS_TXEMPTY) | 408 | if (readl(sport->port.membase + UTS) & UTS_TXEMPTY) |
328 | imx_transmit_buffer(sport); | 409 | imx_transmit_buffer(sport); |
329 | } | 410 | } |
@@ -395,8 +476,7 @@ static irqreturn_t imx_rxint(int irq, void *dev_id) | |||
395 | continue; | 476 | continue; |
396 | } | 477 | } |
397 | 478 | ||
398 | if (uart_handle_sysrq_char | 479 | if (uart_handle_sysrq_char(&sport->port, (unsigned char)rx)) |
399 | (&sport->port, (unsigned char)rx)) | ||
400 | continue; | 480 | continue; |
401 | 481 | ||
402 | if (rx & (URXD_PRERR | URXD_OVRRUN | URXD_FRMERR) ) { | 482 | if (rx & (URXD_PRERR | URXD_OVRRUN | URXD_FRMERR) ) { |
@@ -471,26 +551,26 @@ static unsigned int imx_tx_empty(struct uart_port *port) | |||
471 | */ | 551 | */ |
472 | static unsigned int imx_get_mctrl(struct uart_port *port) | 552 | static unsigned int imx_get_mctrl(struct uart_port *port) |
473 | { | 553 | { |
474 | struct imx_port *sport = (struct imx_port *)port; | 554 | struct imx_port *sport = (struct imx_port *)port; |
475 | unsigned int tmp = TIOCM_DSR | TIOCM_CAR; | 555 | unsigned int tmp = TIOCM_DSR | TIOCM_CAR; |
476 | 556 | ||
477 | if (readl(sport->port.membase + USR1) & USR1_RTSS) | 557 | if (readl(sport->port.membase + USR1) & USR1_RTSS) |
478 | tmp |= TIOCM_CTS; | 558 | tmp |= TIOCM_CTS; |
479 | 559 | ||
480 | if (readl(sport->port.membase + UCR2) & UCR2_CTS) | 560 | if (readl(sport->port.membase + UCR2) & UCR2_CTS) |
481 | tmp |= TIOCM_RTS; | 561 | tmp |= TIOCM_RTS; |
482 | 562 | ||
483 | return tmp; | 563 | return tmp; |
484 | } | 564 | } |
485 | 565 | ||
486 | static void imx_set_mctrl(struct uart_port *port, unsigned int mctrl) | 566 | static void imx_set_mctrl(struct uart_port *port, unsigned int mctrl) |
487 | { | 567 | { |
488 | struct imx_port *sport = (struct imx_port *)port; | 568 | struct imx_port *sport = (struct imx_port *)port; |
489 | unsigned long temp; | 569 | unsigned long temp; |
490 | 570 | ||
491 | temp = readl(sport->port.membase + UCR2) & ~UCR2_CTS; | 571 | temp = readl(sport->port.membase + UCR2) & ~UCR2_CTS; |
492 | 572 | ||
493 | if (mctrl & TIOCM_RTS) | 573 | if (mctrl & TIOCM_RTS) |
494 | temp |= UCR2_CTS; | 574 | temp |= UCR2_CTS; |
495 | 575 | ||
496 | writel(temp, sport->port.membase + UCR2); | 576 | writel(temp, sport->port.membase + UCR2); |
@@ -534,12 +614,7 @@ static int imx_setup_ufcr(struct imx_port *sport, unsigned int mode) | |||
534 | if(!ufcr_rfdiv) | 614 | if(!ufcr_rfdiv) |
535 | ufcr_rfdiv = 1; | 615 | ufcr_rfdiv = 1; |
536 | 616 | ||
537 | if(ufcr_rfdiv >= 7) | 617 | val |= UFCR_RFDIV_REG(ufcr_rfdiv); |
538 | ufcr_rfdiv = 6; | ||
539 | else | ||
540 | ufcr_rfdiv = 6 - ufcr_rfdiv; | ||
541 | |||
542 | val |= UFCR_RFDIV & (ufcr_rfdiv << 7); | ||
543 | 618 | ||
544 | writel(val, sport->port.membase + UFCR); | 619 | writel(val, sport->port.membase + UFCR); |
545 | 620 | ||
@@ -558,8 +633,24 @@ static int imx_startup(struct uart_port *port) | |||
558 | * requesting IRQs | 633 | * requesting IRQs |
559 | */ | 634 | */ |
560 | temp = readl(sport->port.membase + UCR4); | 635 | temp = readl(sport->port.membase + UCR4); |
636 | |||
637 | if (USE_IRDA(sport)) | ||
638 | temp |= UCR4_IRSC; | ||
639 | |||
561 | writel(temp & ~UCR4_DREN, sport->port.membase + UCR4); | 640 | writel(temp & ~UCR4_DREN, sport->port.membase + UCR4); |
562 | 641 | ||
642 | if (USE_IRDA(sport)) { | ||
643 | /* reset fifo's and state machines */ | ||
644 | int i = 100; | ||
645 | temp = readl(sport->port.membase + UCR2); | ||
646 | temp &= ~UCR2_SRST; | ||
647 | writel(temp, sport->port.membase + UCR2); | ||
648 | while (!(readl(sport->port.membase + UCR2) & UCR2_SRST) && | ||
649 | (--i > 0)) { | ||
650 | udelay(1); | ||
651 | } | ||
652 | } | ||
653 | |||
563 | /* | 654 | /* |
564 | * Allocate the IRQ(s) i.MX1 has three interrupts whereas later | 655 | * Allocate the IRQ(s) i.MX1 has three interrupts whereas later |
565 | * chips only have one interrupt. | 656 | * chips only have one interrupt. |
@@ -575,12 +666,16 @@ static int imx_startup(struct uart_port *port) | |||
575 | if (retval) | 666 | if (retval) |
576 | goto error_out2; | 667 | goto error_out2; |
577 | 668 | ||
578 | retval = request_irq(sport->rtsirq, imx_rtsint, | 669 | /* do not use RTS IRQ on IrDA */ |
579 | (sport->rtsirq < MAX_INTERNAL_IRQ) ? 0 : | 670 | if (!USE_IRDA(sport)) { |
580 | IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, | 671 | retval = request_irq(sport->rtsirq, imx_rtsint, |
581 | DRIVER_NAME, sport); | 672 | (sport->rtsirq < MAX_INTERNAL_IRQ) ? 0 : |
582 | if (retval) | 673 | IRQF_TRIGGER_FALLING | |
583 | goto error_out3; | 674 | IRQF_TRIGGER_RISING, |
675 | DRIVER_NAME, sport); | ||
676 | if (retval) | ||
677 | goto error_out3; | ||
678 | } | ||
584 | } else { | 679 | } else { |
585 | retval = request_irq(sport->port.irq, imx_int, 0, | 680 | retval = request_irq(sport->port.irq, imx_int, 0, |
586 | DRIVER_NAME, sport); | 681 | DRIVER_NAME, sport); |
@@ -597,18 +692,49 @@ static int imx_startup(struct uart_port *port) | |||
597 | 692 | ||
598 | temp = readl(sport->port.membase + UCR1); | 693 | temp = readl(sport->port.membase + UCR1); |
599 | temp |= UCR1_RRDYEN | UCR1_RTSDEN | UCR1_UARTEN; | 694 | temp |= UCR1_RRDYEN | UCR1_RTSDEN | UCR1_UARTEN; |
695 | |||
696 | if (USE_IRDA(sport)) { | ||
697 | temp |= UCR1_IREN; | ||
698 | temp &= ~(UCR1_RTSDEN); | ||
699 | } | ||
700 | |||
600 | writel(temp, sport->port.membase + UCR1); | 701 | writel(temp, sport->port.membase + UCR1); |
601 | 702 | ||
602 | temp = readl(sport->port.membase + UCR2); | 703 | temp = readl(sport->port.membase + UCR2); |
603 | temp |= (UCR2_RXEN | UCR2_TXEN); | 704 | temp |= (UCR2_RXEN | UCR2_TXEN); |
604 | writel(temp, sport->port.membase + UCR2); | 705 | writel(temp, sport->port.membase + UCR2); |
605 | 706 | ||
707 | if (USE_IRDA(sport)) { | ||
708 | /* clear RX-FIFO */ | ||
709 | int i = 64; | ||
710 | while ((--i > 0) && | ||
711 | (readl(sport->port.membase + URXD0) & URXD_CHARRDY)) { | ||
712 | barrier(); | ||
713 | } | ||
714 | } | ||
715 | |||
606 | #if defined CONFIG_ARCH_MX2 || defined CONFIG_ARCH_MX3 | 716 | #if defined CONFIG_ARCH_MX2 || defined CONFIG_ARCH_MX3 |
607 | temp = readl(sport->port.membase + UCR3); | 717 | temp = readl(sport->port.membase + UCR3); |
608 | temp |= UCR3_RXDMUXSEL; | 718 | temp |= UCR3_RXDMUXSEL; |
609 | writel(temp, sport->port.membase + UCR3); | 719 | writel(temp, sport->port.membase + UCR3); |
610 | #endif | 720 | #endif |
611 | 721 | ||
722 | if (USE_IRDA(sport)) { | ||
723 | temp = readl(sport->port.membase + UCR4); | ||
724 | if (sport->irda_inv_rx) | ||
725 | temp |= UCR4_INVR; | ||
726 | else | ||
727 | temp &= ~(UCR4_INVR); | ||
728 | writel(temp | UCR4_DREN, sport->port.membase + UCR4); | ||
729 | |||
730 | temp = readl(sport->port.membase + UCR3); | ||
731 | if (sport->irda_inv_tx) | ||
732 | temp |= UCR3_INVT; | ||
733 | else | ||
734 | temp &= ~(UCR3_INVT); | ||
735 | writel(temp, sport->port.membase + UCR3); | ||
736 | } | ||
737 | |||
612 | /* | 738 | /* |
613 | * Enable modem status interrupts | 739 | * Enable modem status interrupts |
614 | */ | 740 | */ |
@@ -616,6 +742,16 @@ static int imx_startup(struct uart_port *port) | |||
616 | imx_enable_ms(&sport->port); | 742 | imx_enable_ms(&sport->port); |
617 | spin_unlock_irqrestore(&sport->port.lock,flags); | 743 | spin_unlock_irqrestore(&sport->port.lock,flags); |
618 | 744 | ||
745 | if (USE_IRDA(sport)) { | ||
746 | struct imxuart_platform_data *pdata; | ||
747 | pdata = sport->port.dev->platform_data; | ||
748 | sport->irda_inv_rx = pdata->irda_inv_rx; | ||
749 | sport->irda_inv_tx = pdata->irda_inv_tx; | ||
750 | sport->trcv_delay = pdata->transceiver_delay; | ||
751 | if (pdata->irda_enable) | ||
752 | pdata->irda_enable(1); | ||
753 | } | ||
754 | |||
619 | return 0; | 755 | return 0; |
620 | 756 | ||
621 | error_out3: | 757 | error_out3: |
@@ -633,6 +769,17 @@ static void imx_shutdown(struct uart_port *port) | |||
633 | struct imx_port *sport = (struct imx_port *)port; | 769 | struct imx_port *sport = (struct imx_port *)port; |
634 | unsigned long temp; | 770 | unsigned long temp; |
635 | 771 | ||
772 | temp = readl(sport->port.membase + UCR2); | ||
773 | temp &= ~(UCR2_TXEN); | ||
774 | writel(temp, sport->port.membase + UCR2); | ||
775 | |||
776 | if (USE_IRDA(sport)) { | ||
777 | struct imxuart_platform_data *pdata; | ||
778 | pdata = sport->port.dev->platform_data; | ||
779 | if (pdata->irda_enable) | ||
780 | pdata->irda_enable(0); | ||
781 | } | ||
782 | |||
636 | /* | 783 | /* |
637 | * Stop our timer. | 784 | * Stop our timer. |
638 | */ | 785 | */ |
@@ -642,7 +789,8 @@ static void imx_shutdown(struct uart_port *port) | |||
642 | * Free the interrupts | 789 | * Free the interrupts |
643 | */ | 790 | */ |
644 | if (sport->txirq > 0) { | 791 | if (sport->txirq > 0) { |
645 | free_irq(sport->rtsirq, sport); | 792 | if (!USE_IRDA(sport)) |
793 | free_irq(sport->rtsirq, sport); | ||
646 | free_irq(sport->txirq, sport); | 794 | free_irq(sport->txirq, sport); |
647 | free_irq(sport->rxirq, sport); | 795 | free_irq(sport->rxirq, sport); |
648 | } else | 796 | } else |
@@ -654,6 +802,9 @@ static void imx_shutdown(struct uart_port *port) | |||
654 | 802 | ||
655 | temp = readl(sport->port.membase + UCR1); | 803 | temp = readl(sport->port.membase + UCR1); |
656 | temp &= ~(UCR1_TXMPTYEN | UCR1_RRDYEN | UCR1_RTSDEN | UCR1_UARTEN); | 804 | temp &= ~(UCR1_TXMPTYEN | UCR1_RRDYEN | UCR1_RTSDEN | UCR1_UARTEN); |
805 | if (USE_IRDA(sport)) | ||
806 | temp &= ~(UCR1_IREN); | ||
807 | |||
657 | writel(temp, sport->port.membase + UCR1); | 808 | writel(temp, sport->port.membase + UCR1); |
658 | } | 809 | } |
659 | 810 | ||
@@ -665,7 +816,9 @@ imx_set_termios(struct uart_port *port, struct ktermios *termios, | |||
665 | unsigned long flags; | 816 | unsigned long flags; |
666 | unsigned int ucr2, old_ucr1, old_txrxen, baud, quot; | 817 | unsigned int ucr2, old_ucr1, old_txrxen, baud, quot; |
667 | unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8; | 818 | unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8; |
668 | unsigned int div, num, denom, ufcr; | 819 | unsigned int div, ufcr; |
820 | unsigned long num, denom; | ||
821 | uint64_t tdiv64; | ||
669 | 822 | ||
670 | /* | 823 | /* |
671 | * If we don't support modem control lines, don't allow | 824 | * If we don't support modem control lines, don't allow |
@@ -761,38 +914,39 @@ imx_set_termios(struct uart_port *port, struct ktermios *termios, | |||
761 | sport->port.membase + UCR2); | 914 | sport->port.membase + UCR2); |
762 | old_txrxen &= (UCR2_TXEN | UCR2_RXEN); | 915 | old_txrxen &= (UCR2_TXEN | UCR2_RXEN); |
763 | 916 | ||
764 | div = sport->port.uartclk / (baud * 16); | 917 | if (USE_IRDA(sport)) { |
765 | if (div > 7) | 918 | /* |
766 | div = 7; | 919 | * use maximum available submodule frequency to |
767 | if (!div) | 920 | * avoid missing short pulses due to low sampling rate |
921 | */ | ||
768 | div = 1; | 922 | div = 1; |
769 | 923 | } else { | |
770 | num = baud; | 924 | div = sport->port.uartclk / (baud * 16); |
771 | denom = port->uartclk / div / 16; | 925 | if (div > 7) |
772 | 926 | div = 7; | |
773 | /* shift num and denom right until they fit into 16 bits */ | 927 | if (!div) |
774 | while (num > 0x10000 || denom > 0x10000) { | 928 | div = 1; |
775 | num >>= 1; | ||
776 | denom >>= 1; | ||
777 | } | 929 | } |
778 | if (num > 0) | ||
779 | num -= 1; | ||
780 | if (denom > 0) | ||
781 | denom -= 1; | ||
782 | 930 | ||
783 | writel(num, sport->port.membase + UBIR); | 931 | rational_best_approximation(16 * div * baud, sport->port.uartclk, |
784 | writel(denom, sport->port.membase + UBMR); | 932 | 1 << 16, 1 << 16, &num, &denom); |
785 | 933 | ||
786 | if (div == 7) | 934 | tdiv64 = sport->port.uartclk; |
787 | div = 6; /* 6 in RFDIV means divide by 7 */ | 935 | tdiv64 *= num; |
788 | else | 936 | do_div(tdiv64, denom * 16 * div); |
789 | div = 6 - div; | 937 | tty_encode_baud_rate(sport->port.info->port.tty, |
938 | (speed_t)tdiv64, (speed_t)tdiv64); | ||
939 | |||
940 | num -= 1; | ||
941 | denom -= 1; | ||
790 | 942 | ||
791 | ufcr = readl(sport->port.membase + UFCR); | 943 | ufcr = readl(sport->port.membase + UFCR); |
792 | ufcr = (ufcr & (~UFCR_RFDIV)) | | 944 | ufcr = (ufcr & (~UFCR_RFDIV)) | UFCR_RFDIV_REG(div); |
793 | (div << 7); | ||
794 | writel(ufcr, sport->port.membase + UFCR); | 945 | writel(ufcr, sport->port.membase + UFCR); |
795 | 946 | ||
947 | writel(num, sport->port.membase + UBIR); | ||
948 | writel(denom, sport->port.membase + UBMR); | ||
949 | |||
796 | #ifdef ONEMS | 950 | #ifdef ONEMS |
797 | writel(sport->port.uartclk / div / 1000, sport->port.membase + ONEMS); | 951 | writel(sport->port.uartclk / div / 1000, sport->port.membase + ONEMS); |
798 | #endif | 952 | #endif |
@@ -1072,22 +1226,22 @@ static struct uart_driver imx_reg = { | |||
1072 | 1226 | ||
1073 | static int serial_imx_suspend(struct platform_device *dev, pm_message_t state) | 1227 | static int serial_imx_suspend(struct platform_device *dev, pm_message_t state) |
1074 | { | 1228 | { |
1075 | struct imx_port *sport = platform_get_drvdata(dev); | 1229 | struct imx_port *sport = platform_get_drvdata(dev); |
1076 | 1230 | ||
1077 | if (sport) | 1231 | if (sport) |
1078 | uart_suspend_port(&imx_reg, &sport->port); | 1232 | uart_suspend_port(&imx_reg, &sport->port); |
1079 | 1233 | ||
1080 | return 0; | 1234 | return 0; |
1081 | } | 1235 | } |
1082 | 1236 | ||
1083 | static int serial_imx_resume(struct platform_device *dev) | 1237 | static int serial_imx_resume(struct platform_device *dev) |
1084 | { | 1238 | { |
1085 | struct imx_port *sport = platform_get_drvdata(dev); | 1239 | struct imx_port *sport = platform_get_drvdata(dev); |
1086 | 1240 | ||
1087 | if (sport) | 1241 | if (sport) |
1088 | uart_resume_port(&imx_reg, &sport->port); | 1242 | uart_resume_port(&imx_reg, &sport->port); |
1089 | 1243 | ||
1090 | return 0; | 1244 | return 0; |
1091 | } | 1245 | } |
1092 | 1246 | ||
1093 | static int serial_imx_probe(struct platform_device *pdev) | 1247 | static int serial_imx_probe(struct platform_device *pdev) |
@@ -1143,19 +1297,29 @@ static int serial_imx_probe(struct platform_device *pdev) | |||
1143 | imx_ports[pdev->id] = sport; | 1297 | imx_ports[pdev->id] = sport; |
1144 | 1298 | ||
1145 | pdata = pdev->dev.platform_data; | 1299 | pdata = pdev->dev.platform_data; |
1146 | if(pdata && (pdata->flags & IMXUART_HAVE_RTSCTS)) | 1300 | if (pdata && (pdata->flags & IMXUART_HAVE_RTSCTS)) |
1147 | sport->have_rtscts = 1; | 1301 | sport->have_rtscts = 1; |
1148 | 1302 | ||
1303 | #ifdef CONFIG_IRDA | ||
1304 | if (pdata && (pdata->flags & IMXUART_IRDA)) | ||
1305 | sport->use_irda = 1; | ||
1306 | #endif | ||
1307 | |||
1149 | if (pdata->init) { | 1308 | if (pdata->init) { |
1150 | ret = pdata->init(pdev); | 1309 | ret = pdata->init(pdev); |
1151 | if (ret) | 1310 | if (ret) |
1152 | goto clkput; | 1311 | goto clkput; |
1153 | } | 1312 | } |
1154 | 1313 | ||
1155 | uart_add_one_port(&imx_reg, &sport->port); | 1314 | ret = uart_add_one_port(&imx_reg, &sport->port); |
1315 | if (ret) | ||
1316 | goto deinit; | ||
1156 | platform_set_drvdata(pdev, &sport->port); | 1317 | platform_set_drvdata(pdev, &sport->port); |
1157 | 1318 | ||
1158 | return 0; | 1319 | return 0; |
1320 | deinit: | ||
1321 | if (pdata->exit) | ||
1322 | pdata->exit(pdev); | ||
1159 | clkput: | 1323 | clkput: |
1160 | clk_put(sport->clk); | 1324 | clk_put(sport->clk); |
1161 | clk_disable(sport->clk); | 1325 | clk_disable(sport->clk); |
@@ -1193,13 +1357,13 @@ static int serial_imx_remove(struct platform_device *pdev) | |||
1193 | } | 1357 | } |
1194 | 1358 | ||
1195 | static struct platform_driver serial_imx_driver = { | 1359 | static struct platform_driver serial_imx_driver = { |
1196 | .probe = serial_imx_probe, | 1360 | .probe = serial_imx_probe, |
1197 | .remove = serial_imx_remove, | 1361 | .remove = serial_imx_remove, |
1198 | 1362 | ||
1199 | .suspend = serial_imx_suspend, | 1363 | .suspend = serial_imx_suspend, |
1200 | .resume = serial_imx_resume, | 1364 | .resume = serial_imx_resume, |
1201 | .driver = { | 1365 | .driver = { |
1202 | .name = "imx-uart", | 1366 | .name = "imx-uart", |
1203 | .owner = THIS_MODULE, | 1367 | .owner = THIS_MODULE, |
1204 | }, | 1368 | }, |
1205 | }; | 1369 | }; |
diff --git a/drivers/serial/jsm/jsm.h b/drivers/serial/jsm/jsm.h index c0a3e2734e24..4e5f3bde0461 100644 --- a/drivers/serial/jsm/jsm.h +++ b/drivers/serial/jsm/jsm.h | |||
@@ -61,6 +61,7 @@ enum { | |||
61 | if ((DBG_##nlevel & jsm_debug)) \ | 61 | if ((DBG_##nlevel & jsm_debug)) \ |
62 | dev_printk(KERN_##klevel, pdev->dev, fmt, ## args) | 62 | dev_printk(KERN_##klevel, pdev->dev, fmt, ## args) |
63 | 63 | ||
64 | #define MAXLINES 256 | ||
64 | #define MAXPORTS 8 | 65 | #define MAXPORTS 8 |
65 | #define MAX_STOPS_SENT 5 | 66 | #define MAX_STOPS_SENT 5 |
66 | 67 | ||
diff --git a/drivers/serial/jsm/jsm_tty.c b/drivers/serial/jsm/jsm_tty.c index 31496dc0a0d1..107ce2e187b8 100644 --- a/drivers/serial/jsm/jsm_tty.c +++ b/drivers/serial/jsm/jsm_tty.c | |||
@@ -33,6 +33,8 @@ | |||
33 | 33 | ||
34 | #include "jsm.h" | 34 | #include "jsm.h" |
35 | 35 | ||
36 | static DECLARE_BITMAP(linemap, MAXLINES); | ||
37 | |||
36 | static void jsm_carrier(struct jsm_channel *ch); | 38 | static void jsm_carrier(struct jsm_channel *ch); |
37 | 39 | ||
38 | static inline int jsm_get_mstat(struct jsm_channel *ch) | 40 | static inline int jsm_get_mstat(struct jsm_channel *ch) |
@@ -433,6 +435,7 @@ int __devinit jsm_tty_init(struct jsm_board *brd) | |||
433 | int __devinit jsm_uart_port_init(struct jsm_board *brd) | 435 | int __devinit jsm_uart_port_init(struct jsm_board *brd) |
434 | { | 436 | { |
435 | int i; | 437 | int i; |
438 | unsigned int line; | ||
436 | struct jsm_channel *ch; | 439 | struct jsm_channel *ch; |
437 | 440 | ||
438 | if (!brd) | 441 | if (!brd) |
@@ -459,9 +462,15 @@ int __devinit jsm_uart_port_init(struct jsm_board *brd) | |||
459 | brd->channels[i]->uart_port.membase = brd->re_map_membase; | 462 | brd->channels[i]->uart_port.membase = brd->re_map_membase; |
460 | brd->channels[i]->uart_port.fifosize = 16; | 463 | brd->channels[i]->uart_port.fifosize = 16; |
461 | brd->channels[i]->uart_port.ops = &jsm_ops; | 464 | brd->channels[i]->uart_port.ops = &jsm_ops; |
462 | brd->channels[i]->uart_port.line = brd->channels[i]->ch_portnum + brd->boardnum * 2; | 465 | line = find_first_zero_bit(linemap, MAXLINES); |
466 | if (line >= MAXLINES) { | ||
467 | printk(KERN_INFO "jsm: linemap is full, added device failed\n"); | ||
468 | continue; | ||
469 | } else | ||
470 | set_bit((int)line, linemap); | ||
471 | brd->channels[i]->uart_port.line = line; | ||
463 | if (uart_add_one_port (&jsm_uart_driver, &brd->channels[i]->uart_port)) | 472 | if (uart_add_one_port (&jsm_uart_driver, &brd->channels[i]->uart_port)) |
464 | printk(KERN_INFO "Added device failed\n"); | 473 | printk(KERN_INFO "jsm: add device failed\n"); |
465 | else | 474 | else |
466 | printk(KERN_INFO "Added device \n"); | 475 | printk(KERN_INFO "Added device \n"); |
467 | } | 476 | } |
@@ -494,6 +503,7 @@ int jsm_remove_uart_port(struct jsm_board *brd) | |||
494 | 503 | ||
495 | ch = brd->channels[i]; | 504 | ch = brd->channels[i]; |
496 | 505 | ||
506 | clear_bit((int)(ch->uart_port.line), linemap); | ||
497 | uart_remove_one_port(&jsm_uart_driver, &brd->channels[i]->uart_port); | 507 | uart_remove_one_port(&jsm_uart_driver, &brd->channels[i]->uart_port); |
498 | } | 508 | } |
499 | 509 | ||
diff --git a/drivers/serial/timbuart.c b/drivers/serial/timbuart.c new file mode 100644 index 000000000000..ac9e5d5f742e --- /dev/null +++ b/drivers/serial/timbuart.c | |||
@@ -0,0 +1,526 @@ | |||
1 | /* | ||
2 | * timbuart.c timberdale FPGA UART driver | ||
3 | * Copyright (c) 2009 Intel Corporation | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License version 2 as | ||
7 | * published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
17 | */ | ||
18 | |||
19 | /* Supports: | ||
20 | * Timberdale FPGA UART | ||
21 | */ | ||
22 | |||
23 | #include <linux/pci.h> | ||
24 | #include <linux/interrupt.h> | ||
25 | #include <linux/serial_core.h> | ||
26 | #include <linux/kernel.h> | ||
27 | #include <linux/platform_device.h> | ||
28 | #include <linux/ioport.h> | ||
29 | |||
30 | #include "timbuart.h" | ||
31 | |||
32 | struct timbuart_port { | ||
33 | struct uart_port port; | ||
34 | struct tasklet_struct tasklet; | ||
35 | int usedma; | ||
36 | u8 last_ier; | ||
37 | struct platform_device *dev; | ||
38 | }; | ||
39 | |||
40 | static int baudrates[] = {9600, 19200, 38400, 57600, 115200, 230400, 460800, | ||
41 | 921600, 1843200, 3250000}; | ||
42 | |||
43 | static void timbuart_mctrl_check(struct uart_port *port, u8 isr, u8 *ier); | ||
44 | |||
45 | static irqreturn_t timbuart_handleinterrupt(int irq, void *devid); | ||
46 | |||
47 | static void timbuart_stop_rx(struct uart_port *port) | ||
48 | { | ||
49 | /* spin lock held by upper layer, disable all RX interrupts */ | ||
50 | u8 ier = ioread8(port->membase + TIMBUART_IER) & ~RXFLAGS; | ||
51 | iowrite8(ier, port->membase + TIMBUART_IER); | ||
52 | } | ||
53 | |||
54 | static void timbuart_stop_tx(struct uart_port *port) | ||
55 | { | ||
56 | /* spinlock held by upper layer, disable TX interrupt */ | ||
57 | u8 ier = ioread8(port->membase + TIMBUART_IER) & ~TXBAE; | ||
58 | iowrite8(ier, port->membase + TIMBUART_IER); | ||
59 | } | ||
60 | |||
61 | static void timbuart_start_tx(struct uart_port *port) | ||
62 | { | ||
63 | struct timbuart_port *uart = | ||
64 | container_of(port, struct timbuart_port, port); | ||
65 | |||
66 | /* do not transfer anything here -> fire off the tasklet */ | ||
67 | tasklet_schedule(&uart->tasklet); | ||
68 | } | ||
69 | |||
70 | static void timbuart_flush_buffer(struct uart_port *port) | ||
71 | { | ||
72 | u8 ctl = ioread8(port->membase + TIMBUART_CTRL) | TIMBUART_CTRL_FLSHTX; | ||
73 | |||
74 | iowrite8(ctl, port->membase + TIMBUART_CTRL); | ||
75 | iowrite8(TXBF, port->membase + TIMBUART_ISR); | ||
76 | } | ||
77 | |||
78 | static void timbuart_rx_chars(struct uart_port *port) | ||
79 | { | ||
80 | struct tty_struct *tty = port->info->port.tty; | ||
81 | |||
82 | while (ioread8(port->membase + TIMBUART_ISR) & RXDP) { | ||
83 | u8 ch = ioread8(port->membase + TIMBUART_RXFIFO); | ||
84 | port->icount.rx++; | ||
85 | tty_insert_flip_char(tty, ch, TTY_NORMAL); | ||
86 | } | ||
87 | |||
88 | spin_unlock(&port->lock); | ||
89 | tty_flip_buffer_push(port->info->port.tty); | ||
90 | spin_lock(&port->lock); | ||
91 | |||
92 | dev_dbg(port->dev, "%s - total read %d bytes\n", | ||
93 | __func__, port->icount.rx); | ||
94 | } | ||
95 | |||
96 | static void timbuart_tx_chars(struct uart_port *port) | ||
97 | { | ||
98 | struct circ_buf *xmit = &port->info->xmit; | ||
99 | |||
100 | while (!(ioread8(port->membase + TIMBUART_ISR) & TXBF) && | ||
101 | !uart_circ_empty(xmit)) { | ||
102 | iowrite8(xmit->buf[xmit->tail], | ||
103 | port->membase + TIMBUART_TXFIFO); | ||
104 | xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); | ||
105 | port->icount.tx++; | ||
106 | } | ||
107 | |||
108 | dev_dbg(port->dev, | ||
109 | "%s - total written %d bytes, CTL: %x, RTS: %x, baud: %x\n", | ||
110 | __func__, | ||
111 | port->icount.tx, | ||
112 | ioread8(port->membase + TIMBUART_CTRL), | ||
113 | port->mctrl & TIOCM_RTS, | ||
114 | ioread8(port->membase + TIMBUART_BAUDRATE)); | ||
115 | } | ||
116 | |||
117 | static void timbuart_handle_tx_port(struct uart_port *port, u8 isr, u8 *ier) | ||
118 | { | ||
119 | struct timbuart_port *uart = | ||
120 | container_of(port, struct timbuart_port, port); | ||
121 | struct circ_buf *xmit = &port->info->xmit; | ||
122 | |||
123 | if (uart_circ_empty(xmit) || uart_tx_stopped(port)) | ||
124 | return; | ||
125 | |||
126 | if (port->x_char) | ||
127 | return; | ||
128 | |||
129 | if (isr & TXFLAGS) { | ||
130 | timbuart_tx_chars(port); | ||
131 | /* clear all TX interrupts */ | ||
132 | iowrite8(TXFLAGS, port->membase + TIMBUART_ISR); | ||
133 | |||
134 | if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) | ||
135 | uart_write_wakeup(port); | ||
136 | } else | ||
137 | /* Re-enable any tx interrupt */ | ||
138 | *ier |= uart->last_ier & TXFLAGS; | ||
139 | |||
140 | /* enable interrupts if there are chars in the transmit buffer, | ||
141 | * Or if we delivered some bytes and want the almost empty interrupt | ||
142 | * we wake up the upper layer later when we got the interrupt | ||
143 | * to give it some time to go out... | ||
144 | */ | ||
145 | if (!uart_circ_empty(xmit)) | ||
146 | *ier |= TXBAE; | ||
147 | |||
148 | dev_dbg(port->dev, "%s - leaving\n", __func__); | ||
149 | } | ||
150 | |||
151 | void timbuart_handle_rx_port(struct uart_port *port, u8 isr, u8 *ier) | ||
152 | { | ||
153 | if (isr & RXFLAGS) { | ||
154 | /* Some RX status is set */ | ||
155 | if (isr & RXBF) { | ||
156 | u8 ctl = ioread8(port->membase + TIMBUART_CTRL) | | ||
157 | TIMBUART_CTRL_FLSHRX; | ||
158 | iowrite8(ctl, port->membase + TIMBUART_CTRL); | ||
159 | port->icount.overrun++; | ||
160 | } else if (isr & (RXDP)) | ||
161 | timbuart_rx_chars(port); | ||
162 | |||
163 | /* ack all RX interrupts */ | ||
164 | iowrite8(RXFLAGS, port->membase + TIMBUART_ISR); | ||
165 | } | ||
166 | |||
167 | /* always have the RX interrupts enabled */ | ||
168 | *ier |= RXBAF | RXBF | RXTT; | ||
169 | |||
170 | dev_dbg(port->dev, "%s - leaving\n", __func__); | ||
171 | } | ||
172 | |||
173 | void timbuart_tasklet(unsigned long arg) | ||
174 | { | ||
175 | struct timbuart_port *uart = (struct timbuart_port *)arg; | ||
176 | u8 isr, ier = 0; | ||
177 | |||
178 | spin_lock(&uart->port.lock); | ||
179 | |||
180 | isr = ioread8(uart->port.membase + TIMBUART_ISR); | ||
181 | dev_dbg(uart->port.dev, "%s ISR: %x\n", __func__, isr); | ||
182 | |||
183 | if (!uart->usedma) | ||
184 | timbuart_handle_tx_port(&uart->port, isr, &ier); | ||
185 | |||
186 | timbuart_mctrl_check(&uart->port, isr, &ier); | ||
187 | |||
188 | if (!uart->usedma) | ||
189 | timbuart_handle_rx_port(&uart->port, isr, &ier); | ||
190 | |||
191 | iowrite8(ier, uart->port.membase + TIMBUART_IER); | ||
192 | |||
193 | spin_unlock(&uart->port.lock); | ||
194 | dev_dbg(uart->port.dev, "%s leaving\n", __func__); | ||
195 | } | ||
196 | |||
197 | static unsigned int timbuart_tx_empty(struct uart_port *port) | ||
198 | { | ||
199 | u8 isr = ioread8(port->membase + TIMBUART_ISR); | ||
200 | |||
201 | return (isr & TXBAE) ? TIOCSER_TEMT : 0; | ||
202 | } | ||
203 | |||
204 | static unsigned int timbuart_get_mctrl(struct uart_port *port) | ||
205 | { | ||
206 | u8 cts = ioread8(port->membase + TIMBUART_CTRL); | ||
207 | dev_dbg(port->dev, "%s - cts %x\n", __func__, cts); | ||
208 | |||
209 | if (cts & TIMBUART_CTRL_CTS) | ||
210 | return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR; | ||
211 | else | ||
212 | return TIOCM_DSR | TIOCM_CAR; | ||
213 | } | ||
214 | |||
215 | static void timbuart_set_mctrl(struct uart_port *port, unsigned int mctrl) | ||
216 | { | ||
217 | dev_dbg(port->dev, "%s - %x\n", __func__, mctrl); | ||
218 | |||
219 | if (mctrl & TIOCM_RTS) | ||
220 | iowrite8(TIMBUART_CTRL_RTS, port->membase + TIMBUART_CTRL); | ||
221 | else | ||
222 | iowrite8(TIMBUART_CTRL_RTS, port->membase + TIMBUART_CTRL); | ||
223 | } | ||
224 | |||
225 | static void timbuart_mctrl_check(struct uart_port *port, u8 isr, u8 *ier) | ||
226 | { | ||
227 | unsigned int cts; | ||
228 | |||
229 | if (isr & CTS_DELTA) { | ||
230 | /* ack */ | ||
231 | iowrite8(CTS_DELTA, port->membase + TIMBUART_ISR); | ||
232 | cts = timbuart_get_mctrl(port); | ||
233 | uart_handle_cts_change(port, cts & TIOCM_CTS); | ||
234 | wake_up_interruptible(&port->info->delta_msr_wait); | ||
235 | } | ||
236 | |||
237 | *ier |= CTS_DELTA; | ||
238 | } | ||
239 | |||
240 | static void timbuart_enable_ms(struct uart_port *port) | ||
241 | { | ||
242 | /* N/A */ | ||
243 | } | ||
244 | |||
245 | static void timbuart_break_ctl(struct uart_port *port, int ctl) | ||
246 | { | ||
247 | /* N/A */ | ||
248 | } | ||
249 | |||
250 | static int timbuart_startup(struct uart_port *port) | ||
251 | { | ||
252 | struct timbuart_port *uart = | ||
253 | container_of(port, struct timbuart_port, port); | ||
254 | |||
255 | dev_dbg(port->dev, "%s\n", __func__); | ||
256 | |||
257 | iowrite8(TIMBUART_CTRL_FLSHRX, port->membase + TIMBUART_CTRL); | ||
258 | iowrite8(0xff, port->membase + TIMBUART_ISR); | ||
259 | /* Enable all but TX interrupts */ | ||
260 | iowrite8(RXBAF | RXBF | RXTT | CTS_DELTA, | ||
261 | port->membase + TIMBUART_IER); | ||
262 | |||
263 | return request_irq(port->irq, timbuart_handleinterrupt, IRQF_SHARED, | ||
264 | "timb-uart", uart); | ||
265 | } | ||
266 | |||
267 | static void timbuart_shutdown(struct uart_port *port) | ||
268 | { | ||
269 | struct timbuart_port *uart = | ||
270 | container_of(port, struct timbuart_port, port); | ||
271 | dev_dbg(port->dev, "%s\n", __func__); | ||
272 | free_irq(port->irq, uart); | ||
273 | iowrite8(0, port->membase + TIMBUART_IER); | ||
274 | } | ||
275 | |||
276 | static int get_bindex(int baud) | ||
277 | { | ||
278 | int i; | ||
279 | |||
280 | for (i = 0; i < ARRAY_SIZE(baudrates); i++) | ||
281 | if (baud <= baudrates[i]) | ||
282 | return i; | ||
283 | |||
284 | return -1; | ||
285 | } | ||
286 | |||
287 | static void timbuart_set_termios(struct uart_port *port, | ||
288 | struct ktermios *termios, | ||
289 | struct ktermios *old) | ||
290 | { | ||
291 | unsigned int baud; | ||
292 | short bindex; | ||
293 | unsigned long flags; | ||
294 | |||
295 | baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16); | ||
296 | bindex = get_bindex(baud); | ||
297 | dev_dbg(port->dev, "%s - bindex %d\n", __func__, bindex); | ||
298 | |||
299 | if (bindex < 0) | ||
300 | bindex = 0; | ||
301 | baud = baudrates[bindex]; | ||
302 | |||
303 | /* The serial layer calls into this once with old = NULL when setting | ||
304 | up initially */ | ||
305 | if (old) | ||
306 | tty_termios_copy_hw(termios, old); | ||
307 | tty_termios_encode_baud_rate(termios, baud, baud); | ||
308 | |||
309 | spin_lock_irqsave(&port->lock, flags); | ||
310 | iowrite8((u8)bindex, port->membase + TIMBUART_BAUDRATE); | ||
311 | uart_update_timeout(port, termios->c_cflag, baud); | ||
312 | spin_unlock_irqrestore(&port->lock, flags); | ||
313 | } | ||
314 | |||
315 | static const char *timbuart_type(struct uart_port *port) | ||
316 | { | ||
317 | return port->type == PORT_UNKNOWN ? "timbuart" : NULL; | ||
318 | } | ||
319 | |||
320 | /* We do not request/release mappings of the registers here, | ||
321 | * currently it's done in the proble function. | ||
322 | */ | ||
323 | static void timbuart_release_port(struct uart_port *port) | ||
324 | { | ||
325 | struct platform_device *pdev = to_platform_device(port->dev); | ||
326 | int size = | ||
327 | resource_size(platform_get_resource(pdev, IORESOURCE_MEM, 0)); | ||
328 | |||
329 | if (port->flags & UPF_IOREMAP) { | ||
330 | iounmap(port->membase); | ||
331 | port->membase = NULL; | ||
332 | } | ||
333 | |||
334 | release_mem_region(port->mapbase, size); | ||
335 | } | ||
336 | |||
337 | static int timbuart_request_port(struct uart_port *port) | ||
338 | { | ||
339 | struct platform_device *pdev = to_platform_device(port->dev); | ||
340 | int size = | ||
341 | resource_size(platform_get_resource(pdev, IORESOURCE_MEM, 0)); | ||
342 | |||
343 | if (!request_mem_region(port->mapbase, size, "timb-uart")) | ||
344 | return -EBUSY; | ||
345 | |||
346 | if (port->flags & UPF_IOREMAP) { | ||
347 | port->membase = ioremap(port->mapbase, size); | ||
348 | if (port->membase == NULL) { | ||
349 | release_mem_region(port->mapbase, size); | ||
350 | return -ENOMEM; | ||
351 | } | ||
352 | } | ||
353 | |||
354 | return 0; | ||
355 | } | ||
356 | |||
357 | static irqreturn_t timbuart_handleinterrupt(int irq, void *devid) | ||
358 | { | ||
359 | struct timbuart_port *uart = (struct timbuart_port *)devid; | ||
360 | |||
361 | if (ioread8(uart->port.membase + TIMBUART_IPR)) { | ||
362 | uart->last_ier = ioread8(uart->port.membase + TIMBUART_IER); | ||
363 | |||
364 | /* disable interrupts, the tasklet enables them again */ | ||
365 | iowrite8(0, uart->port.membase + TIMBUART_IER); | ||
366 | |||
367 | /* fire off bottom half */ | ||
368 | tasklet_schedule(&uart->tasklet); | ||
369 | |||
370 | return IRQ_HANDLED; | ||
371 | } else | ||
372 | return IRQ_NONE; | ||
373 | } | ||
374 | |||
375 | /* | ||
376 | * Configure/autoconfigure the port. | ||
377 | */ | ||
378 | static void timbuart_config_port(struct uart_port *port, int flags) | ||
379 | { | ||
380 | if (flags & UART_CONFIG_TYPE) { | ||
381 | port->type = PORT_TIMBUART; | ||
382 | timbuart_request_port(port); | ||
383 | } | ||
384 | } | ||
385 | |||
386 | static int timbuart_verify_port(struct uart_port *port, | ||
387 | struct serial_struct *ser) | ||
388 | { | ||
389 | /* we don't want the core code to modify any port params */ | ||
390 | return -EINVAL; | ||
391 | } | ||
392 | |||
393 | static struct uart_ops timbuart_ops = { | ||
394 | .tx_empty = timbuart_tx_empty, | ||
395 | .set_mctrl = timbuart_set_mctrl, | ||
396 | .get_mctrl = timbuart_get_mctrl, | ||
397 | .stop_tx = timbuart_stop_tx, | ||
398 | .start_tx = timbuart_start_tx, | ||
399 | .flush_buffer = timbuart_flush_buffer, | ||
400 | .stop_rx = timbuart_stop_rx, | ||
401 | .enable_ms = timbuart_enable_ms, | ||
402 | .break_ctl = timbuart_break_ctl, | ||
403 | .startup = timbuart_startup, | ||
404 | .shutdown = timbuart_shutdown, | ||
405 | .set_termios = timbuart_set_termios, | ||
406 | .type = timbuart_type, | ||
407 | .release_port = timbuart_release_port, | ||
408 | .request_port = timbuart_request_port, | ||
409 | .config_port = timbuart_config_port, | ||
410 | .verify_port = timbuart_verify_port | ||
411 | }; | ||
412 | |||
413 | static struct uart_driver timbuart_driver = { | ||
414 | .owner = THIS_MODULE, | ||
415 | .driver_name = "timberdale_uart", | ||
416 | .dev_name = "ttyTU", | ||
417 | .major = TIMBUART_MAJOR, | ||
418 | .minor = TIMBUART_MINOR, | ||
419 | .nr = 1 | ||
420 | }; | ||
421 | |||
422 | static int timbuart_probe(struct platform_device *dev) | ||
423 | { | ||
424 | int err; | ||
425 | struct timbuart_port *uart; | ||
426 | struct resource *iomem; | ||
427 | |||
428 | dev_dbg(&dev->dev, "%s\n", __func__); | ||
429 | |||
430 | uart = kzalloc(sizeof(*uart), GFP_KERNEL); | ||
431 | if (!uart) { | ||
432 | err = -EINVAL; | ||
433 | goto err_mem; | ||
434 | } | ||
435 | |||
436 | uart->usedma = 0; | ||
437 | |||
438 | uart->port.uartclk = 3250000 * 16; | ||
439 | uart->port.fifosize = TIMBUART_FIFO_SIZE; | ||
440 | uart->port.regshift = 2; | ||
441 | uart->port.iotype = UPIO_MEM; | ||
442 | uart->port.ops = &timbuart_ops; | ||
443 | uart->port.irq = 0; | ||
444 | uart->port.flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP; | ||
445 | uart->port.line = 0; | ||
446 | uart->port.dev = &dev->dev; | ||
447 | |||
448 | iomem = platform_get_resource(dev, IORESOURCE_MEM, 0); | ||
449 | if (!iomem) { | ||
450 | err = -ENOMEM; | ||
451 | goto err_register; | ||
452 | } | ||
453 | uart->port.mapbase = iomem->start; | ||
454 | uart->port.membase = NULL; | ||
455 | |||
456 | uart->port.irq = platform_get_irq(dev, 0); | ||
457 | if (uart->port.irq < 0) { | ||
458 | err = -EINVAL; | ||
459 | goto err_register; | ||
460 | } | ||
461 | |||
462 | tasklet_init(&uart->tasklet, timbuart_tasklet, (unsigned long)uart); | ||
463 | |||
464 | err = uart_register_driver(&timbuart_driver); | ||
465 | if (err) | ||
466 | goto err_register; | ||
467 | |||
468 | err = uart_add_one_port(&timbuart_driver, &uart->port); | ||
469 | if (err) | ||
470 | goto err_add_port; | ||
471 | |||
472 | platform_set_drvdata(dev, uart); | ||
473 | |||
474 | return 0; | ||
475 | |||
476 | err_add_port: | ||
477 | uart_unregister_driver(&timbuart_driver); | ||
478 | err_register: | ||
479 | kfree(uart); | ||
480 | err_mem: | ||
481 | printk(KERN_ERR "timberdale: Failed to register Timberdale UART: %d\n", | ||
482 | err); | ||
483 | |||
484 | return err; | ||
485 | } | ||
486 | |||
487 | static int timbuart_remove(struct platform_device *dev) | ||
488 | { | ||
489 | struct timbuart_port *uart = platform_get_drvdata(dev); | ||
490 | |||
491 | tasklet_kill(&uart->tasklet); | ||
492 | uart_remove_one_port(&timbuart_driver, &uart->port); | ||
493 | uart_unregister_driver(&timbuart_driver); | ||
494 | kfree(uart); | ||
495 | |||
496 | return 0; | ||
497 | } | ||
498 | |||
499 | static struct platform_driver timbuart_platform_driver = { | ||
500 | .driver = { | ||
501 | .name = "timb-uart", | ||
502 | .owner = THIS_MODULE, | ||
503 | }, | ||
504 | .probe = timbuart_probe, | ||
505 | .remove = timbuart_remove, | ||
506 | }; | ||
507 | |||
508 | /*--------------------------------------------------------------------------*/ | ||
509 | |||
510 | static int __init timbuart_init(void) | ||
511 | { | ||
512 | return platform_driver_register(&timbuart_platform_driver); | ||
513 | } | ||
514 | |||
515 | static void __exit timbuart_exit(void) | ||
516 | { | ||
517 | platform_driver_unregister(&timbuart_platform_driver); | ||
518 | } | ||
519 | |||
520 | module_init(timbuart_init); | ||
521 | module_exit(timbuart_exit); | ||
522 | |||
523 | MODULE_DESCRIPTION("Timberdale UART driver"); | ||
524 | MODULE_LICENSE("GPL v2"); | ||
525 | MODULE_ALIAS("platform:timb-uart"); | ||
526 | |||
diff --git a/drivers/serial/timbuart.h b/drivers/serial/timbuart.h new file mode 100644 index 000000000000..7e566766bc43 --- /dev/null +++ b/drivers/serial/timbuart.h | |||
@@ -0,0 +1,58 @@ | |||
1 | /* | ||
2 | * timbuart.c timberdale FPGA GPIO driver | ||
3 | * Copyright (c) 2009 Intel Corporation | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License version 2 as | ||
7 | * published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
17 | */ | ||
18 | |||
19 | /* Supports: | ||
20 | * Timberdale FPGA UART | ||
21 | */ | ||
22 | |||
23 | #ifndef _TIMBUART_H | ||
24 | #define _TIMBUART_H | ||
25 | |||
26 | #define TIMBUART_FIFO_SIZE 2048 | ||
27 | |||
28 | #define TIMBUART_RXFIFO 0x08 | ||
29 | #define TIMBUART_TXFIFO 0x0c | ||
30 | #define TIMBUART_IER 0x10 | ||
31 | #define TIMBUART_IPR 0x14 | ||
32 | #define TIMBUART_ISR 0x18 | ||
33 | #define TIMBUART_CTRL 0x1c | ||
34 | #define TIMBUART_BAUDRATE 0x20 | ||
35 | |||
36 | #define TIMBUART_CTRL_RTS 0x01 | ||
37 | #define TIMBUART_CTRL_CTS 0x02 | ||
38 | #define TIMBUART_CTRL_FLSHTX 0x40 | ||
39 | #define TIMBUART_CTRL_FLSHRX 0x80 | ||
40 | |||
41 | #define TXBF 0x01 | ||
42 | #define TXBAE 0x02 | ||
43 | #define CTS_DELTA 0x04 | ||
44 | #define RXDP 0x08 | ||
45 | #define RXBAF 0x10 | ||
46 | #define RXBF 0x20 | ||
47 | #define RXTT 0x40 | ||
48 | #define RXBNAE 0x80 | ||
49 | #define TXBE 0x100 | ||
50 | |||
51 | #define RXFLAGS (RXDP | RXBAF | RXBF | RXTT | RXBNAE) | ||
52 | #define TXFLAGS (TXBF | TXBAE) | ||
53 | |||
54 | #define TIMBUART_MAJOR 204 | ||
55 | #define TIMBUART_MINOR 192 | ||
56 | |||
57 | #endif /* _TIMBUART_H */ | ||
58 | |||
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index 7a1164dd1d37..ddeb69192537 100644 --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c | |||
@@ -16,7 +16,8 @@ | |||
16 | * v0.9 - thorough cleaning, URBification, almost a rewrite | 16 | * v0.9 - thorough cleaning, URBification, almost a rewrite |
17 | * v0.10 - some more cleanups | 17 | * v0.10 - some more cleanups |
18 | * v0.11 - fixed flow control, read error doesn't stop reads | 18 | * v0.11 - fixed flow control, read error doesn't stop reads |
19 | * v0.12 - added TIOCM ioctls, added break handling, made struct acm kmalloced | 19 | * v0.12 - added TIOCM ioctls, added break handling, made struct acm |
20 | * kmalloced | ||
20 | * v0.13 - added termios, added hangup | 21 | * v0.13 - added termios, added hangup |
21 | * v0.14 - sized down struct acm | 22 | * v0.14 - sized down struct acm |
22 | * v0.15 - fixed flow control again - characters could be lost | 23 | * v0.15 - fixed flow control again - characters could be lost |
@@ -62,7 +63,7 @@ | |||
62 | #include <linux/tty_flip.h> | 63 | #include <linux/tty_flip.h> |
63 | #include <linux/module.h> | 64 | #include <linux/module.h> |
64 | #include <linux/mutex.h> | 65 | #include <linux/mutex.h> |
65 | #include <asm/uaccess.h> | 66 | #include <linux/uaccess.h> |
66 | #include <linux/usb.h> | 67 | #include <linux/usb.h> |
67 | #include <linux/usb/cdc.h> | 68 | #include <linux/usb/cdc.h> |
68 | #include <asm/byteorder.h> | 69 | #include <asm/byteorder.h> |
@@ -87,7 +88,10 @@ static struct acm *acm_table[ACM_TTY_MINORS]; | |||
87 | 88 | ||
88 | static DEFINE_MUTEX(open_mutex); | 89 | static DEFINE_MUTEX(open_mutex); |
89 | 90 | ||
90 | #define ACM_READY(acm) (acm && acm->dev && acm->used) | 91 | #define ACM_READY(acm) (acm && acm->dev && acm->port.count) |
92 | |||
93 | static const struct tty_port_operations acm_port_ops = { | ||
94 | }; | ||
91 | 95 | ||
92 | #ifdef VERBOSE_DEBUG | 96 | #ifdef VERBOSE_DEBUG |
93 | #define verbose 1 | 97 | #define verbose 1 |
@@ -99,13 +103,15 @@ static DEFINE_MUTEX(open_mutex); | |||
99 | * Functions for ACM control messages. | 103 | * Functions for ACM control messages. |
100 | */ | 104 | */ |
101 | 105 | ||
102 | static int acm_ctrl_msg(struct acm *acm, int request, int value, void *buf, int len) | 106 | static int acm_ctrl_msg(struct acm *acm, int request, int value, |
107 | void *buf, int len) | ||
103 | { | 108 | { |
104 | int retval = usb_control_msg(acm->dev, usb_sndctrlpipe(acm->dev, 0), | 109 | int retval = usb_control_msg(acm->dev, usb_sndctrlpipe(acm->dev, 0), |
105 | request, USB_RT_ACM, value, | 110 | request, USB_RT_ACM, value, |
106 | acm->control->altsetting[0].desc.bInterfaceNumber, | 111 | acm->control->altsetting[0].desc.bInterfaceNumber, |
107 | buf, len, 5000); | 112 | buf, len, 5000); |
108 | dbg("acm_control_msg: rq: 0x%02x val: %#x len: %#x result: %d", request, value, len, retval); | 113 | dbg("acm_control_msg: rq: 0x%02x val: %#x len: %#x result: %d", |
114 | request, value, len, retval); | ||
109 | return retval < 0 ? retval : 0; | 115 | return retval < 0 ? retval : 0; |
110 | } | 116 | } |
111 | 117 | ||
@@ -150,9 +156,8 @@ static int acm_wb_is_avail(struct acm *acm) | |||
150 | 156 | ||
151 | n = ACM_NW; | 157 | n = ACM_NW; |
152 | spin_lock_irqsave(&acm->write_lock, flags); | 158 | spin_lock_irqsave(&acm->write_lock, flags); |
153 | for (i = 0; i < ACM_NW; i++) { | 159 | for (i = 0; i < ACM_NW; i++) |
154 | n -= acm->wb[i].use; | 160 | n -= acm->wb[i].use; |
155 | } | ||
156 | spin_unlock_irqrestore(&acm->write_lock, flags); | 161 | spin_unlock_irqrestore(&acm->write_lock, flags); |
157 | return n; | 162 | return n; |
158 | } | 163 | } |
@@ -183,7 +188,8 @@ static int acm_start_wb(struct acm *acm, struct acm_wb *wb) | |||
183 | wb->urb->transfer_buffer_length = wb->len; | 188 | wb->urb->transfer_buffer_length = wb->len; |
184 | wb->urb->dev = acm->dev; | 189 | wb->urb->dev = acm->dev; |
185 | 190 | ||
186 | if ((rc = usb_submit_urb(wb->urb, GFP_ATOMIC)) < 0) { | 191 | rc = usb_submit_urb(wb->urb, GFP_ATOMIC); |
192 | if (rc < 0) { | ||
187 | dbg("usb_submit_urb(write bulk) failed: %d", rc); | 193 | dbg("usb_submit_urb(write bulk) failed: %d", rc); |
188 | acm_write_done(acm, wb); | 194 | acm_write_done(acm, wb); |
189 | } | 195 | } |
@@ -262,6 +268,7 @@ static void acm_ctrl_irq(struct urb *urb) | |||
262 | { | 268 | { |
263 | struct acm *acm = urb->context; | 269 | struct acm *acm = urb->context; |
264 | struct usb_cdc_notification *dr = urb->transfer_buffer; | 270 | struct usb_cdc_notification *dr = urb->transfer_buffer; |
271 | struct tty_struct *tty; | ||
265 | unsigned char *data; | 272 | unsigned char *data; |
266 | int newctrl; | 273 | int newctrl; |
267 | int retval; | 274 | int retval; |
@@ -287,40 +294,45 @@ static void acm_ctrl_irq(struct urb *urb) | |||
287 | 294 | ||
288 | data = (unsigned char *)(dr + 1); | 295 | data = (unsigned char *)(dr + 1); |
289 | switch (dr->bNotificationType) { | 296 | switch (dr->bNotificationType) { |
297 | case USB_CDC_NOTIFY_NETWORK_CONNECTION: | ||
298 | dbg("%s network", dr->wValue ? | ||
299 | "connected to" : "disconnected from"); | ||
300 | break; | ||
290 | 301 | ||
291 | case USB_CDC_NOTIFY_NETWORK_CONNECTION: | 302 | case USB_CDC_NOTIFY_SERIAL_STATE: |
292 | 303 | tty = tty_port_tty_get(&acm->port); | |
293 | dbg("%s network", dr->wValue ? "connected to" : "disconnected from"); | 304 | newctrl = get_unaligned_le16(data); |
294 | break; | ||
295 | |||
296 | case USB_CDC_NOTIFY_SERIAL_STATE: | ||
297 | |||
298 | newctrl = get_unaligned_le16(data); | ||
299 | 305 | ||
300 | if (acm->tty && !acm->clocal && (acm->ctrlin & ~newctrl & ACM_CTRL_DCD)) { | 306 | if (tty) { |
307 | if (!acm->clocal && | ||
308 | (acm->ctrlin & ~newctrl & ACM_CTRL_DCD)) { | ||
301 | dbg("calling hangup"); | 309 | dbg("calling hangup"); |
302 | tty_hangup(acm->tty); | 310 | tty_hangup(tty); |
303 | } | 311 | } |
312 | tty_kref_put(tty); | ||
313 | } | ||
304 | 314 | ||
305 | acm->ctrlin = newctrl; | 315 | acm->ctrlin = newctrl; |
306 | |||
307 | dbg("input control lines: dcd%c dsr%c break%c ring%c framing%c parity%c overrun%c", | ||
308 | acm->ctrlin & ACM_CTRL_DCD ? '+' : '-', acm->ctrlin & ACM_CTRL_DSR ? '+' : '-', | ||
309 | acm->ctrlin & ACM_CTRL_BRK ? '+' : '-', acm->ctrlin & ACM_CTRL_RI ? '+' : '-', | ||
310 | acm->ctrlin & ACM_CTRL_FRAMING ? '+' : '-', acm->ctrlin & ACM_CTRL_PARITY ? '+' : '-', | ||
311 | acm->ctrlin & ACM_CTRL_OVERRUN ? '+' : '-'); | ||
312 | 316 | ||
317 | dbg("input control lines: dcd%c dsr%c break%c ring%c framing%c parity%c overrun%c", | ||
318 | acm->ctrlin & ACM_CTRL_DCD ? '+' : '-', | ||
319 | acm->ctrlin & ACM_CTRL_DSR ? '+' : '-', | ||
320 | acm->ctrlin & ACM_CTRL_BRK ? '+' : '-', | ||
321 | acm->ctrlin & ACM_CTRL_RI ? '+' : '-', | ||
322 | acm->ctrlin & ACM_CTRL_FRAMING ? '+' : '-', | ||
323 | acm->ctrlin & ACM_CTRL_PARITY ? '+' : '-', | ||
324 | acm->ctrlin & ACM_CTRL_OVERRUN ? '+' : '-'); | ||
313 | break; | 325 | break; |
314 | 326 | ||
315 | default: | 327 | default: |
316 | dbg("unknown notification %d received: index %d len %d data0 %d data1 %d", | 328 | dbg("unknown notification %d received: index %d len %d data0 %d data1 %d", |
317 | dr->bNotificationType, dr->wIndex, | 329 | dr->bNotificationType, dr->wIndex, |
318 | dr->wLength, data[0], data[1]); | 330 | dr->wLength, data[0], data[1]); |
319 | break; | 331 | break; |
320 | } | 332 | } |
321 | exit: | 333 | exit: |
322 | usb_mark_last_busy(acm->dev); | 334 | usb_mark_last_busy(acm->dev); |
323 | retval = usb_submit_urb (urb, GFP_ATOMIC); | 335 | retval = usb_submit_urb(urb, GFP_ATOMIC); |
324 | if (retval) | 336 | if (retval) |
325 | dev_err(&urb->dev->dev, "%s - usb_submit_urb failed with " | 337 | dev_err(&urb->dev->dev, "%s - usb_submit_urb failed with " |
326 | "result %d", __func__, retval); | 338 | "result %d", __func__, retval); |
@@ -371,15 +383,14 @@ static void acm_rx_tasklet(unsigned long _acm) | |||
371 | { | 383 | { |
372 | struct acm *acm = (void *)_acm; | 384 | struct acm *acm = (void *)_acm; |
373 | struct acm_rb *buf; | 385 | struct acm_rb *buf; |
374 | struct tty_struct *tty = acm->tty; | 386 | struct tty_struct *tty; |
375 | struct acm_ru *rcv; | 387 | struct acm_ru *rcv; |
376 | unsigned long flags; | 388 | unsigned long flags; |
377 | unsigned char throttled; | 389 | unsigned char throttled; |
378 | 390 | ||
379 | dbg("Entering acm_rx_tasklet"); | 391 | dbg("Entering acm_rx_tasklet"); |
380 | 392 | ||
381 | if (!ACM_READY(acm)) | 393 | if (!ACM_READY(acm)) { |
382 | { | ||
383 | dbg("acm_rx_tasklet: ACM not ready"); | 394 | dbg("acm_rx_tasklet: ACM not ready"); |
384 | return; | 395 | return; |
385 | } | 396 | } |
@@ -387,12 +398,13 @@ static void acm_rx_tasklet(unsigned long _acm) | |||
387 | spin_lock_irqsave(&acm->throttle_lock, flags); | 398 | spin_lock_irqsave(&acm->throttle_lock, flags); |
388 | throttled = acm->throttle; | 399 | throttled = acm->throttle; |
389 | spin_unlock_irqrestore(&acm->throttle_lock, flags); | 400 | spin_unlock_irqrestore(&acm->throttle_lock, flags); |
390 | if (throttled) | 401 | if (throttled) { |
391 | { | ||
392 | dbg("acm_rx_tasklet: throttled"); | 402 | dbg("acm_rx_tasklet: throttled"); |
393 | return; | 403 | return; |
394 | } | 404 | } |
395 | 405 | ||
406 | tty = tty_port_tty_get(&acm->port); | ||
407 | |||
396 | next_buffer: | 408 | next_buffer: |
397 | spin_lock_irqsave(&acm->read_lock, flags); | 409 | spin_lock_irqsave(&acm->read_lock, flags); |
398 | if (list_empty(&acm->filled_read_bufs)) { | 410 | if (list_empty(&acm->filled_read_bufs)) { |
@@ -406,20 +418,22 @@ next_buffer: | |||
406 | 418 | ||
407 | dbg("acm_rx_tasklet: procesing buf 0x%p, size = %d", buf, buf->size); | 419 | dbg("acm_rx_tasklet: procesing buf 0x%p, size = %d", buf, buf->size); |
408 | 420 | ||
409 | tty_buffer_request_room(tty, buf->size); | 421 | if (tty) { |
410 | spin_lock_irqsave(&acm->throttle_lock, flags); | 422 | spin_lock_irqsave(&acm->throttle_lock, flags); |
411 | throttled = acm->throttle; | 423 | throttled = acm->throttle; |
412 | spin_unlock_irqrestore(&acm->throttle_lock, flags); | 424 | spin_unlock_irqrestore(&acm->throttle_lock, flags); |
413 | if (!throttled) | 425 | if (!throttled) { |
414 | tty_insert_flip_string(tty, buf->base, buf->size); | 426 | tty_buffer_request_room(tty, buf->size); |
415 | tty_flip_buffer_push(tty); | 427 | tty_insert_flip_string(tty, buf->base, buf->size); |
416 | 428 | tty_flip_buffer_push(tty); | |
417 | if (throttled) { | 429 | } else { |
418 | dbg("Throttling noticed"); | 430 | tty_kref_put(tty); |
419 | spin_lock_irqsave(&acm->read_lock, flags); | 431 | dbg("Throttling noticed"); |
420 | list_add(&buf->list, &acm->filled_read_bufs); | 432 | spin_lock_irqsave(&acm->read_lock, flags); |
421 | spin_unlock_irqrestore(&acm->read_lock, flags); | 433 | list_add(&buf->list, &acm->filled_read_bufs); |
422 | return; | 434 | spin_unlock_irqrestore(&acm->read_lock, flags); |
435 | return; | ||
436 | } | ||
423 | } | 437 | } |
424 | 438 | ||
425 | spin_lock_irqsave(&acm->read_lock, flags); | 439 | spin_lock_irqsave(&acm->read_lock, flags); |
@@ -428,6 +442,8 @@ next_buffer: | |||
428 | goto next_buffer; | 442 | goto next_buffer; |
429 | 443 | ||
430 | urbs: | 444 | urbs: |
445 | tty_kref_put(tty); | ||
446 | |||
431 | while (!list_empty(&acm->spare_read_bufs)) { | 447 | while (!list_empty(&acm->spare_read_bufs)) { |
432 | spin_lock_irqsave(&acm->read_lock, flags); | 448 | spin_lock_irqsave(&acm->read_lock, flags); |
433 | if (list_empty(&acm->spare_read_urbs)) { | 449 | if (list_empty(&acm->spare_read_urbs)) { |
@@ -454,10 +470,11 @@ urbs: | |||
454 | rcv->urb->transfer_dma = buf->dma; | 470 | rcv->urb->transfer_dma = buf->dma; |
455 | rcv->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | 471 | rcv->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
456 | 472 | ||
457 | /* This shouldn't kill the driver as unsuccessful URBs are returned to the | 473 | /* This shouldn't kill the driver as unsuccessful URBs are |
458 | free-urbs-pool and resubmited ASAP */ | 474 | returned to the free-urbs-pool and resubmited ASAP */ |
459 | spin_lock_irqsave(&acm->read_lock, flags); | 475 | spin_lock_irqsave(&acm->read_lock, flags); |
460 | if (acm->susp_count || usb_submit_urb(rcv->urb, GFP_ATOMIC) < 0) { | 476 | if (acm->susp_count || |
477 | usb_submit_urb(rcv->urb, GFP_ATOMIC) < 0) { | ||
461 | list_add(&buf->list, &acm->spare_read_bufs); | 478 | list_add(&buf->list, &acm->spare_read_bufs); |
462 | list_add(&rcv->list, &acm->spare_read_urbs); | 479 | list_add(&rcv->list, &acm->spare_read_urbs); |
463 | acm->processing = 0; | 480 | acm->processing = 0; |
@@ -499,11 +516,14 @@ static void acm_write_bulk(struct urb *urb) | |||
499 | static void acm_softint(struct work_struct *work) | 516 | static void acm_softint(struct work_struct *work) |
500 | { | 517 | { |
501 | struct acm *acm = container_of(work, struct acm, work); | 518 | struct acm *acm = container_of(work, struct acm, work); |
519 | struct tty_struct *tty; | ||
502 | 520 | ||
503 | dev_vdbg(&acm->data->dev, "tx work\n"); | 521 | dev_vdbg(&acm->data->dev, "tx work\n"); |
504 | if (!ACM_READY(acm)) | 522 | if (!ACM_READY(acm)) |
505 | return; | 523 | return; |
506 | tty_wakeup(acm->tty); | 524 | tty = tty_port_tty_get(&acm->port); |
525 | tty_wakeup(tty); | ||
526 | tty_kref_put(tty); | ||
507 | } | 527 | } |
508 | 528 | ||
509 | static void acm_waker(struct work_struct *waker) | 529 | static void acm_waker(struct work_struct *waker) |
@@ -543,8 +563,9 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp) | |||
543 | rv = 0; | 563 | rv = 0; |
544 | 564 | ||
545 | set_bit(TTY_NO_WRITE_SPLIT, &tty->flags); | 565 | set_bit(TTY_NO_WRITE_SPLIT, &tty->flags); |
566 | |||
546 | tty->driver_data = acm; | 567 | tty->driver_data = acm; |
547 | acm->tty = tty; | 568 | tty_port_tty_set(&acm->port, tty); |
548 | 569 | ||
549 | if (usb_autopm_get_interface(acm->control) < 0) | 570 | if (usb_autopm_get_interface(acm->control) < 0) |
550 | goto early_bail; | 571 | goto early_bail; |
@@ -552,11 +573,10 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp) | |||
552 | acm->control->needs_remote_wakeup = 1; | 573 | acm->control->needs_remote_wakeup = 1; |
553 | 574 | ||
554 | mutex_lock(&acm->mutex); | 575 | mutex_lock(&acm->mutex); |
555 | if (acm->used++) { | 576 | if (acm->port.count++) { |
556 | usb_autopm_put_interface(acm->control); | 577 | usb_autopm_put_interface(acm->control); |
557 | goto done; | 578 | goto done; |
558 | } | 579 | } |
559 | |||
560 | 580 | ||
561 | acm->ctrlurb->dev = acm->dev; | 581 | acm->ctrlurb->dev = acm->dev; |
562 | if (usb_submit_urb(acm->ctrlurb, GFP_KERNEL)) { | 582 | if (usb_submit_urb(acm->ctrlurb, GFP_KERNEL)) { |
@@ -567,22 +587,22 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp) | |||
567 | if (0 > acm_set_control(acm, acm->ctrlout = ACM_CTRL_DTR | ACM_CTRL_RTS) && | 587 | if (0 > acm_set_control(acm, acm->ctrlout = ACM_CTRL_DTR | ACM_CTRL_RTS) && |
568 | (acm->ctrl_caps & USB_CDC_CAP_LINE)) | 588 | (acm->ctrl_caps & USB_CDC_CAP_LINE)) |
569 | goto full_bailout; | 589 | goto full_bailout; |
590 | |||
570 | usb_autopm_put_interface(acm->control); | 591 | usb_autopm_put_interface(acm->control); |
571 | 592 | ||
572 | INIT_LIST_HEAD(&acm->spare_read_urbs); | 593 | INIT_LIST_HEAD(&acm->spare_read_urbs); |
573 | INIT_LIST_HEAD(&acm->spare_read_bufs); | 594 | INIT_LIST_HEAD(&acm->spare_read_bufs); |
574 | INIT_LIST_HEAD(&acm->filled_read_bufs); | 595 | INIT_LIST_HEAD(&acm->filled_read_bufs); |
575 | for (i = 0; i < acm->rx_buflimit; i++) { | 596 | |
597 | for (i = 0; i < acm->rx_buflimit; i++) | ||
576 | list_add(&(acm->ru[i].list), &acm->spare_read_urbs); | 598 | list_add(&(acm->ru[i].list), &acm->spare_read_urbs); |
577 | } | 599 | for (i = 0; i < acm->rx_buflimit; i++) |
578 | for (i = 0; i < acm->rx_buflimit; i++) { | ||
579 | list_add(&(acm->rb[i].list), &acm->spare_read_bufs); | 600 | list_add(&(acm->rb[i].list), &acm->spare_read_bufs); |
580 | } | ||
581 | 601 | ||
582 | acm->throttle = 0; | 602 | acm->throttle = 0; |
583 | 603 | ||
584 | tasklet_schedule(&acm->urb_task); | 604 | tasklet_schedule(&acm->urb_task); |
585 | 605 | rv = tty_port_block_til_ready(&acm->port, tty, filp); | |
586 | done: | 606 | done: |
587 | mutex_unlock(&acm->mutex); | 607 | mutex_unlock(&acm->mutex); |
588 | err_out: | 608 | err_out: |
@@ -593,16 +613,17 @@ full_bailout: | |||
593 | usb_kill_urb(acm->ctrlurb); | 613 | usb_kill_urb(acm->ctrlurb); |
594 | bail_out: | 614 | bail_out: |
595 | usb_autopm_put_interface(acm->control); | 615 | usb_autopm_put_interface(acm->control); |
596 | acm->used--; | 616 | acm->port.count--; |
597 | mutex_unlock(&acm->mutex); | 617 | mutex_unlock(&acm->mutex); |
598 | early_bail: | 618 | early_bail: |
599 | mutex_unlock(&open_mutex); | 619 | mutex_unlock(&open_mutex); |
620 | tty_port_tty_set(&acm->port, NULL); | ||
600 | return -EIO; | 621 | return -EIO; |
601 | } | 622 | } |
602 | 623 | ||
603 | static void acm_tty_unregister(struct acm *acm) | 624 | static void acm_tty_unregister(struct acm *acm) |
604 | { | 625 | { |
605 | int i,nr; | 626 | int i, nr; |
606 | 627 | ||
607 | nr = acm->rx_buflimit; | 628 | nr = acm->rx_buflimit; |
608 | tty_unregister_device(acm_tty_driver, acm->minor); | 629 | tty_unregister_device(acm_tty_driver, acm->minor); |
@@ -619,41 +640,56 @@ static void acm_tty_unregister(struct acm *acm) | |||
619 | 640 | ||
620 | static int acm_tty_chars_in_buffer(struct tty_struct *tty); | 641 | static int acm_tty_chars_in_buffer(struct tty_struct *tty); |
621 | 642 | ||
643 | static void acm_port_down(struct acm *acm, int drain) | ||
644 | { | ||
645 | int i, nr = acm->rx_buflimit; | ||
646 | mutex_lock(&open_mutex); | ||
647 | if (acm->dev) { | ||
648 | usb_autopm_get_interface(acm->control); | ||
649 | acm_set_control(acm, acm->ctrlout = 0); | ||
650 | /* try letting the last writes drain naturally */ | ||
651 | if (drain) { | ||
652 | wait_event_interruptible_timeout(acm->drain_wait, | ||
653 | (ACM_NW == acm_wb_is_avail(acm)) || !acm->dev, | ||
654 | ACM_CLOSE_TIMEOUT * HZ); | ||
655 | } | ||
656 | usb_kill_urb(acm->ctrlurb); | ||
657 | for (i = 0; i < ACM_NW; i++) | ||
658 | usb_kill_urb(acm->wb[i].urb); | ||
659 | for (i = 0; i < nr; i++) | ||
660 | usb_kill_urb(acm->ru[i].urb); | ||
661 | acm->control->needs_remote_wakeup = 0; | ||
662 | usb_autopm_put_interface(acm->control); | ||
663 | } | ||
664 | mutex_unlock(&open_mutex); | ||
665 | } | ||
666 | |||
667 | static void acm_tty_hangup(struct tty_struct *tty) | ||
668 | { | ||
669 | struct acm *acm = tty->driver_data; | ||
670 | tty_port_hangup(&acm->port); | ||
671 | acm_port_down(acm, 0); | ||
672 | } | ||
673 | |||
622 | static void acm_tty_close(struct tty_struct *tty, struct file *filp) | 674 | static void acm_tty_close(struct tty_struct *tty, struct file *filp) |
623 | { | 675 | { |
624 | struct acm *acm = tty->driver_data; | 676 | struct acm *acm = tty->driver_data; |
625 | int i,nr; | ||
626 | 677 | ||
627 | if (!acm || !acm->used) | 678 | /* Perform the closing process and see if we need to do the hardware |
679 | shutdown */ | ||
680 | if (tty_port_close_start(&acm->port, tty, filp) == 0) | ||
628 | return; | 681 | return; |
629 | 682 | acm_port_down(acm, 0); | |
630 | nr = acm->rx_buflimit; | 683 | tty_port_close_end(&acm->port, tty); |
631 | mutex_lock(&open_mutex); | 684 | mutex_lock(&open_mutex); |
632 | if (!--acm->used) { | 685 | tty_port_tty_set(&acm->port, NULL); |
633 | if (acm->dev) { | 686 | if (!acm->dev) |
634 | usb_autopm_get_interface(acm->control); | 687 | acm_tty_unregister(acm); |
635 | acm_set_control(acm, acm->ctrlout = 0); | ||
636 | |||
637 | /* try letting the last writes drain naturally */ | ||
638 | wait_event_interruptible_timeout(acm->drain_wait, | ||
639 | (ACM_NW == acm_wb_is_avail(acm)) | ||
640 | || !acm->dev, | ||
641 | ACM_CLOSE_TIMEOUT * HZ); | ||
642 | |||
643 | usb_kill_urb(acm->ctrlurb); | ||
644 | for (i = 0; i < ACM_NW; i++) | ||
645 | usb_kill_urb(acm->wb[i].urb); | ||
646 | for (i = 0; i < nr; i++) | ||
647 | usb_kill_urb(acm->ru[i].urb); | ||
648 | acm->control->needs_remote_wakeup = 0; | ||
649 | usb_autopm_put_interface(acm->control); | ||
650 | } else | ||
651 | acm_tty_unregister(acm); | ||
652 | } | ||
653 | mutex_unlock(&open_mutex); | 688 | mutex_unlock(&open_mutex); |
654 | } | 689 | } |
655 | 690 | ||
656 | static int acm_tty_write(struct tty_struct *tty, const unsigned char *buf, int count) | 691 | static int acm_tty_write(struct tty_struct *tty, |
692 | const unsigned char *buf, int count) | ||
657 | { | 693 | { |
658 | struct acm *acm = tty->driver_data; | 694 | struct acm *acm = tty->driver_data; |
659 | int stat; | 695 | int stat; |
@@ -669,7 +705,8 @@ static int acm_tty_write(struct tty_struct *tty, const unsigned char *buf, int c | |||
669 | return 0; | 705 | return 0; |
670 | 706 | ||
671 | spin_lock_irqsave(&acm->write_lock, flags); | 707 | spin_lock_irqsave(&acm->write_lock, flags); |
672 | if ((wbn = acm_wb_alloc(acm)) < 0) { | 708 | wbn = acm_wb_alloc(acm); |
709 | if (wbn < 0) { | ||
673 | spin_unlock_irqrestore(&acm->write_lock, flags); | 710 | spin_unlock_irqrestore(&acm->write_lock, flags); |
674 | return 0; | 711 | return 0; |
675 | } | 712 | } |
@@ -681,7 +718,8 @@ static int acm_tty_write(struct tty_struct *tty, const unsigned char *buf, int c | |||
681 | wb->len = count; | 718 | wb->len = count; |
682 | spin_unlock_irqrestore(&acm->write_lock, flags); | 719 | spin_unlock_irqrestore(&acm->write_lock, flags); |
683 | 720 | ||
684 | if ((stat = acm_write_start(acm, wbn)) < 0) | 721 | stat = acm_write_start(acm, wbn); |
722 | if (stat < 0) | ||
685 | return stat; | 723 | return stat; |
686 | return count; | 724 | return count; |
687 | } | 725 | } |
@@ -767,8 +805,10 @@ static int acm_tty_tiocmset(struct tty_struct *tty, struct file *file, | |||
767 | return -EINVAL; | 805 | return -EINVAL; |
768 | 806 | ||
769 | newctrl = acm->ctrlout; | 807 | newctrl = acm->ctrlout; |
770 | set = (set & TIOCM_DTR ? ACM_CTRL_DTR : 0) | (set & TIOCM_RTS ? ACM_CTRL_RTS : 0); | 808 | set = (set & TIOCM_DTR ? ACM_CTRL_DTR : 0) | |
771 | clear = (clear & TIOCM_DTR ? ACM_CTRL_DTR : 0) | (clear & TIOCM_RTS ? ACM_CTRL_RTS : 0); | 809 | (set & TIOCM_RTS ? ACM_CTRL_RTS : 0); |
810 | clear = (clear & TIOCM_DTR ? ACM_CTRL_DTR : 0) | | ||
811 | (clear & TIOCM_RTS ? ACM_CTRL_RTS : 0); | ||
772 | 812 | ||
773 | newctrl = (newctrl & ~clear) | set; | 813 | newctrl = (newctrl & ~clear) | set; |
774 | 814 | ||
@@ -777,7 +817,8 @@ static int acm_tty_tiocmset(struct tty_struct *tty, struct file *file, | |||
777 | return acm_set_control(acm, acm->ctrlout = newctrl); | 817 | return acm_set_control(acm, acm->ctrlout = newctrl); |
778 | } | 818 | } |
779 | 819 | ||
780 | static int acm_tty_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) | 820 | static int acm_tty_ioctl(struct tty_struct *tty, struct file *file, |
821 | unsigned int cmd, unsigned long arg) | ||
781 | { | 822 | { |
782 | struct acm *acm = tty->driver_data; | 823 | struct acm *acm = tty->driver_data; |
783 | 824 | ||
@@ -799,7 +840,8 @@ static const __u8 acm_tty_size[] = { | |||
799 | 5, 6, 7, 8 | 840 | 5, 6, 7, 8 |
800 | }; | 841 | }; |
801 | 842 | ||
802 | static void acm_tty_set_termios(struct tty_struct *tty, struct ktermios *termios_old) | 843 | static void acm_tty_set_termios(struct tty_struct *tty, |
844 | struct ktermios *termios_old) | ||
803 | { | 845 | { |
804 | struct acm *acm = tty->driver_data; | 846 | struct acm *acm = tty->driver_data; |
805 | struct ktermios *termios = tty->termios; | 847 | struct ktermios *termios = tty->termios; |
@@ -809,19 +851,23 @@ static void acm_tty_set_termios(struct tty_struct *tty, struct ktermios *termios | |||
809 | if (!ACM_READY(acm)) | 851 | if (!ACM_READY(acm)) |
810 | return; | 852 | return; |
811 | 853 | ||
854 | /* FIXME: Needs to support the tty_baud interface */ | ||
855 | /* FIXME: Broken on sparc */ | ||
812 | newline.dwDTERate = cpu_to_le32p(acm_tty_speed + | 856 | newline.dwDTERate = cpu_to_le32p(acm_tty_speed + |
813 | (termios->c_cflag & CBAUD & ~CBAUDEX) + (termios->c_cflag & CBAUDEX ? 15 : 0)); | 857 | (termios->c_cflag & CBAUD & ~CBAUDEX) + (termios->c_cflag & CBAUDEX ? 15 : 0)); |
814 | newline.bCharFormat = termios->c_cflag & CSTOPB ? 2 : 0; | 858 | newline.bCharFormat = termios->c_cflag & CSTOPB ? 2 : 0; |
815 | newline.bParityType = termios->c_cflag & PARENB ? | 859 | newline.bParityType = termios->c_cflag & PARENB ? |
816 | (termios->c_cflag & PARODD ? 1 : 2) + (termios->c_cflag & CMSPAR ? 2 : 0) : 0; | 860 | (termios->c_cflag & PARODD ? 1 : 2) + |
861 | (termios->c_cflag & CMSPAR ? 2 : 0) : 0; | ||
817 | newline.bDataBits = acm_tty_size[(termios->c_cflag & CSIZE) >> 4]; | 862 | newline.bDataBits = acm_tty_size[(termios->c_cflag & CSIZE) >> 4]; |
818 | 863 | /* FIXME: Needs to clear unsupported bits in the termios */ | |
819 | acm->clocal = ((termios->c_cflag & CLOCAL) != 0); | 864 | acm->clocal = ((termios->c_cflag & CLOCAL) != 0); |
820 | 865 | ||
821 | if (!newline.dwDTERate) { | 866 | if (!newline.dwDTERate) { |
822 | newline.dwDTERate = acm->line.dwDTERate; | 867 | newline.dwDTERate = acm->line.dwDTERate; |
823 | newctrl &= ~ACM_CTRL_DTR; | 868 | newctrl &= ~ACM_CTRL_DTR; |
824 | } else newctrl |= ACM_CTRL_DTR; | 869 | } else |
870 | newctrl |= ACM_CTRL_DTR; | ||
825 | 871 | ||
826 | if (newctrl != acm->ctrlout) | 872 | if (newctrl != acm->ctrlout) |
827 | acm_set_control(acm, acm->ctrlout = newctrl); | 873 | acm_set_control(acm, acm->ctrlout = newctrl); |
@@ -846,9 +892,8 @@ static void acm_write_buffers_free(struct acm *acm) | |||
846 | struct acm_wb *wb; | 892 | struct acm_wb *wb; |
847 | struct usb_device *usb_dev = interface_to_usbdev(acm->control); | 893 | struct usb_device *usb_dev = interface_to_usbdev(acm->control); |
848 | 894 | ||
849 | for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) { | 895 | for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) |
850 | usb_buffer_free(usb_dev, acm->writesize, wb->buf, wb->dmah); | 896 | usb_buffer_free(usb_dev, acm->writesize, wb->buf, wb->dmah); |
851 | } | ||
852 | } | 897 | } |
853 | 898 | ||
854 | static void acm_read_buffers_free(struct acm *acm) | 899 | static void acm_read_buffers_free(struct acm *acm) |
@@ -857,7 +902,8 @@ static void acm_read_buffers_free(struct acm *acm) | |||
857 | int i, n = acm->rx_buflimit; | 902 | int i, n = acm->rx_buflimit; |
858 | 903 | ||
859 | for (i = 0; i < n; i++) | 904 | for (i = 0; i < n; i++) |
860 | usb_buffer_free(usb_dev, acm->readsize, acm->rb[i].base, acm->rb[i].dma); | 905 | usb_buffer_free(usb_dev, acm->readsize, |
906 | acm->rb[i].base, acm->rb[i].dma); | ||
861 | } | 907 | } |
862 | 908 | ||
863 | /* Little helper: write buffers allocate */ | 909 | /* Little helper: write buffers allocate */ |
@@ -882,8 +928,8 @@ static int acm_write_buffers_alloc(struct acm *acm) | |||
882 | return 0; | 928 | return 0; |
883 | } | 929 | } |
884 | 930 | ||
885 | static int acm_probe (struct usb_interface *intf, | 931 | static int acm_probe(struct usb_interface *intf, |
886 | const struct usb_device_id *id) | 932 | const struct usb_device_id *id) |
887 | { | 933 | { |
888 | struct usb_cdc_union_desc *union_header = NULL; | 934 | struct usb_cdc_union_desc *union_header = NULL; |
889 | struct usb_cdc_country_functional_desc *cfd = NULL; | 935 | struct usb_cdc_country_functional_desc *cfd = NULL; |
@@ -897,7 +943,7 @@ static int acm_probe (struct usb_interface *intf, | |||
897 | struct usb_device *usb_dev = interface_to_usbdev(intf); | 943 | struct usb_device *usb_dev = interface_to_usbdev(intf); |
898 | struct acm *acm; | 944 | struct acm *acm; |
899 | int minor; | 945 | int minor; |
900 | int ctrlsize,readsize; | 946 | int ctrlsize, readsize; |
901 | u8 *buf; | 947 | u8 *buf; |
902 | u8 ac_management_function = 0; | 948 | u8 ac_management_function = 0; |
903 | u8 call_management_function = 0; | 949 | u8 call_management_function = 0; |
@@ -917,7 +963,7 @@ static int acm_probe (struct usb_interface *intf, | |||
917 | control_interface = usb_ifnum_to_if(usb_dev, 0); | 963 | control_interface = usb_ifnum_to_if(usb_dev, 0); |
918 | goto skip_normal_probe; | 964 | goto skip_normal_probe; |
919 | } | 965 | } |
920 | 966 | ||
921 | /* normal probing*/ | 967 | /* normal probing*/ |
922 | if (!buffer) { | 968 | if (!buffer) { |
923 | dev_err(&intf->dev, "Weird descriptor references\n"); | 969 | dev_err(&intf->dev, "Weird descriptor references\n"); |
@@ -925,8 +971,10 @@ static int acm_probe (struct usb_interface *intf, | |||
925 | } | 971 | } |
926 | 972 | ||
927 | if (!buflen) { | 973 | if (!buflen) { |
928 | if (intf->cur_altsetting->endpoint->extralen && intf->cur_altsetting->endpoint->extra) { | 974 | if (intf->cur_altsetting->endpoint->extralen && |
929 | dev_dbg(&intf->dev,"Seeking extra descriptors on endpoint\n"); | 975 | intf->cur_altsetting->endpoint->extra) { |
976 | dev_dbg(&intf->dev, | ||
977 | "Seeking extra descriptors on endpoint\n"); | ||
930 | buflen = intf->cur_altsetting->endpoint->extralen; | 978 | buflen = intf->cur_altsetting->endpoint->extralen; |
931 | buffer = intf->cur_altsetting->endpoint->extra; | 979 | buffer = intf->cur_altsetting->endpoint->extra; |
932 | } else { | 980 | } else { |
@@ -937,47 +985,43 @@ static int acm_probe (struct usb_interface *intf, | |||
937 | } | 985 | } |
938 | 986 | ||
939 | while (buflen > 0) { | 987 | while (buflen > 0) { |
940 | if (buffer [1] != USB_DT_CS_INTERFACE) { | 988 | if (buffer[1] != USB_DT_CS_INTERFACE) { |
941 | dev_err(&intf->dev, "skipping garbage\n"); | 989 | dev_err(&intf->dev, "skipping garbage\n"); |
942 | goto next_desc; | 990 | goto next_desc; |
943 | } | 991 | } |
944 | 992 | ||
945 | switch (buffer [2]) { | 993 | switch (buffer[2]) { |
946 | case USB_CDC_UNION_TYPE: /* we've found it */ | 994 | case USB_CDC_UNION_TYPE: /* we've found it */ |
947 | if (union_header) { | 995 | if (union_header) { |
948 | dev_err(&intf->dev, "More than one " | 996 | dev_err(&intf->dev, "More than one " |
949 | "union descriptor, " | 997 | "union descriptor, skipping ...\n"); |
950 | "skipping ...\n"); | 998 | goto next_desc; |
951 | goto next_desc; | ||
952 | } | ||
953 | union_header = (struct usb_cdc_union_desc *) | ||
954 | buffer; | ||
955 | break; | ||
956 | case USB_CDC_COUNTRY_TYPE: /* export through sysfs*/ | ||
957 | cfd = (struct usb_cdc_country_functional_desc *)buffer; | ||
958 | break; | ||
959 | case USB_CDC_HEADER_TYPE: /* maybe check version */ | ||
960 | break; /* for now we ignore it */ | ||
961 | case USB_CDC_ACM_TYPE: | ||
962 | ac_management_function = buffer[3]; | ||
963 | break; | ||
964 | case USB_CDC_CALL_MANAGEMENT_TYPE: | ||
965 | call_management_function = buffer[3]; | ||
966 | call_interface_num = buffer[4]; | ||
967 | if ((call_management_function & 3) != 3) | ||
968 | dev_err(&intf->dev, "This device " | ||
969 | "cannot do calls on its own. " | ||
970 | "It is no modem.\n"); | ||
971 | break; | ||
972 | default: | ||
973 | /* there are LOTS more CDC descriptors that | ||
974 | * could legitimately be found here. | ||
975 | */ | ||
976 | dev_dbg(&intf->dev, "Ignoring descriptor: " | ||
977 | "type %02x, length %d\n", | ||
978 | buffer[2], buffer[0]); | ||
979 | break; | ||
980 | } | 999 | } |
1000 | union_header = (struct usb_cdc_union_desc *)buffer; | ||
1001 | break; | ||
1002 | case USB_CDC_COUNTRY_TYPE: /* export through sysfs*/ | ||
1003 | cfd = (struct usb_cdc_country_functional_desc *)buffer; | ||
1004 | break; | ||
1005 | case USB_CDC_HEADER_TYPE: /* maybe check version */ | ||
1006 | break; /* for now we ignore it */ | ||
1007 | case USB_CDC_ACM_TYPE: | ||
1008 | ac_management_function = buffer[3]; | ||
1009 | break; | ||
1010 | case USB_CDC_CALL_MANAGEMENT_TYPE: | ||
1011 | call_management_function = buffer[3]; | ||
1012 | call_interface_num = buffer[4]; | ||
1013 | if ((call_management_function & 3) != 3) | ||
1014 | dev_err(&intf->dev, "This device cannot do calls on its own. It is not a modem.\n"); | ||
1015 | break; | ||
1016 | default: | ||
1017 | /* there are LOTS more CDC descriptors that | ||
1018 | * could legitimately be found here. | ||
1019 | */ | ||
1020 | dev_dbg(&intf->dev, "Ignoring descriptor: " | ||
1021 | "type %02x, length %d\n", | ||
1022 | buffer[2], buffer[0]); | ||
1023 | break; | ||
1024 | } | ||
981 | next_desc: | 1025 | next_desc: |
982 | buflen -= buffer[0]; | 1026 | buflen -= buffer[0]; |
983 | buffer += buffer[0]; | 1027 | buffer += buffer[0]; |
@@ -985,33 +1029,36 @@ next_desc: | |||
985 | 1029 | ||
986 | if (!union_header) { | 1030 | if (!union_header) { |
987 | if (call_interface_num > 0) { | 1031 | if (call_interface_num > 0) { |
988 | dev_dbg(&intf->dev,"No union descriptor, using call management descriptor\n"); | 1032 | dev_dbg(&intf->dev, "No union descriptor, using call management descriptor\n"); |
989 | data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = call_interface_num)); | 1033 | data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = call_interface_num)); |
990 | control_interface = intf; | 1034 | control_interface = intf; |
991 | } else { | 1035 | } else { |
992 | dev_dbg(&intf->dev,"No union descriptor, giving up\n"); | 1036 | dev_dbg(&intf->dev, |
1037 | "No union descriptor, giving up\n"); | ||
993 | return -ENODEV; | 1038 | return -ENODEV; |
994 | } | 1039 | } |
995 | } else { | 1040 | } else { |
996 | control_interface = usb_ifnum_to_if(usb_dev, union_header->bMasterInterface0); | 1041 | control_interface = usb_ifnum_to_if(usb_dev, union_header->bMasterInterface0); |
997 | data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = union_header->bSlaveInterface0)); | 1042 | data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = union_header->bSlaveInterface0)); |
998 | if (!control_interface || !data_interface) { | 1043 | if (!control_interface || !data_interface) { |
999 | dev_dbg(&intf->dev,"no interfaces\n"); | 1044 | dev_dbg(&intf->dev, "no interfaces\n"); |
1000 | return -ENODEV; | 1045 | return -ENODEV; |
1001 | } | 1046 | } |
1002 | } | 1047 | } |
1003 | 1048 | ||
1004 | if (data_interface_num != call_interface_num) | 1049 | if (data_interface_num != call_interface_num) |
1005 | dev_dbg(&intf->dev,"Separate call control interface. That is not fully supported.\n"); | 1050 | dev_dbg(&intf->dev, "Separate call control interface. That is not fully supported.\n"); |
1006 | 1051 | ||
1007 | skip_normal_probe: | 1052 | skip_normal_probe: |
1008 | 1053 | ||
1009 | /*workaround for switched interfaces */ | 1054 | /*workaround for switched interfaces */ |
1010 | if (data_interface->cur_altsetting->desc.bInterfaceClass != CDC_DATA_INTERFACE_TYPE) { | 1055 | if (data_interface->cur_altsetting->desc.bInterfaceClass |
1011 | if (control_interface->cur_altsetting->desc.bInterfaceClass == CDC_DATA_INTERFACE_TYPE) { | 1056 | != CDC_DATA_INTERFACE_TYPE) { |
1057 | if (control_interface->cur_altsetting->desc.bInterfaceClass | ||
1058 | == CDC_DATA_INTERFACE_TYPE) { | ||
1012 | struct usb_interface *t; | 1059 | struct usb_interface *t; |
1013 | dev_dbg(&intf->dev,"Your device has switched interfaces.\n"); | 1060 | dev_dbg(&intf->dev, |
1014 | 1061 | "Your device has switched interfaces.\n"); | |
1015 | t = control_interface; | 1062 | t = control_interface; |
1016 | control_interface = data_interface; | 1063 | control_interface = data_interface; |
1017 | data_interface = t; | 1064 | data_interface = t; |
@@ -1023,9 +1070,9 @@ skip_normal_probe: | |||
1023 | /* Accept probe requests only for the control interface */ | 1070 | /* Accept probe requests only for the control interface */ |
1024 | if (intf != control_interface) | 1071 | if (intf != control_interface) |
1025 | return -ENODEV; | 1072 | return -ENODEV; |
1026 | 1073 | ||
1027 | if (usb_interface_claimed(data_interface)) { /* valid in this context */ | 1074 | if (usb_interface_claimed(data_interface)) { /* valid in this context */ |
1028 | dev_dbg(&intf->dev,"The data interface isn't available\n"); | 1075 | dev_dbg(&intf->dev, "The data interface isn't available\n"); |
1029 | return -EBUSY; | 1076 | return -EBUSY; |
1030 | } | 1077 | } |
1031 | 1078 | ||
@@ -1042,8 +1089,8 @@ skip_normal_probe: | |||
1042 | if (!usb_endpoint_dir_in(epread)) { | 1089 | if (!usb_endpoint_dir_in(epread)) { |
1043 | /* descriptors are swapped */ | 1090 | /* descriptors are swapped */ |
1044 | struct usb_endpoint_descriptor *t; | 1091 | struct usb_endpoint_descriptor *t; |
1045 | dev_dbg(&intf->dev,"The data interface has switched endpoints\n"); | 1092 | dev_dbg(&intf->dev, |
1046 | 1093 | "The data interface has switched endpoints\n"); | |
1047 | t = epread; | 1094 | t = epread; |
1048 | epread = epwrite; | 1095 | epread = epwrite; |
1049 | epwrite = t; | 1096 | epwrite = t; |
@@ -1056,13 +1103,15 @@ skip_normal_probe: | |||
1056 | return -ENODEV; | 1103 | return -ENODEV; |
1057 | } | 1104 | } |
1058 | 1105 | ||
1059 | if (!(acm = kzalloc(sizeof(struct acm), GFP_KERNEL))) { | 1106 | acm = kzalloc(sizeof(struct acm), GFP_KERNEL); |
1107 | if (acm == NULL) { | ||
1060 | dev_dbg(&intf->dev, "out of memory (acm kzalloc)\n"); | 1108 | dev_dbg(&intf->dev, "out of memory (acm kzalloc)\n"); |
1061 | goto alloc_fail; | 1109 | goto alloc_fail; |
1062 | } | 1110 | } |
1063 | 1111 | ||
1064 | ctrlsize = le16_to_cpu(epctrl->wMaxPacketSize); | 1112 | ctrlsize = le16_to_cpu(epctrl->wMaxPacketSize); |
1065 | readsize = le16_to_cpu(epread->wMaxPacketSize)* ( quirks == SINGLE_RX_URB ? 1 : 2); | 1113 | readsize = le16_to_cpu(epread->wMaxPacketSize) * |
1114 | (quirks == SINGLE_RX_URB ? 1 : 2); | ||
1066 | acm->writesize = le16_to_cpu(epwrite->wMaxPacketSize) * 20; | 1115 | acm->writesize = le16_to_cpu(epwrite->wMaxPacketSize) * 20; |
1067 | acm->control = control_interface; | 1116 | acm->control = control_interface; |
1068 | acm->data = data_interface; | 1117 | acm->data = data_interface; |
@@ -1082,6 +1131,8 @@ skip_normal_probe: | |||
1082 | spin_lock_init(&acm->read_lock); | 1131 | spin_lock_init(&acm->read_lock); |
1083 | mutex_init(&acm->mutex); | 1132 | mutex_init(&acm->mutex); |
1084 | acm->rx_endpoint = usb_rcvbulkpipe(usb_dev, epread->bEndpointAddress); | 1133 | acm->rx_endpoint = usb_rcvbulkpipe(usb_dev, epread->bEndpointAddress); |
1134 | tty_port_init(&acm->port); | ||
1135 | acm->port.ops = &acm_port_ops; | ||
1085 | 1136 | ||
1086 | buf = usb_buffer_alloc(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma); | 1137 | buf = usb_buffer_alloc(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma); |
1087 | if (!buf) { | 1138 | if (!buf) { |
@@ -1103,8 +1154,10 @@ skip_normal_probe: | |||
1103 | for (i = 0; i < num_rx_buf; i++) { | 1154 | for (i = 0; i < num_rx_buf; i++) { |
1104 | struct acm_ru *rcv = &(acm->ru[i]); | 1155 | struct acm_ru *rcv = &(acm->ru[i]); |
1105 | 1156 | ||
1106 | if (!(rcv->urb = usb_alloc_urb(0, GFP_KERNEL))) { | 1157 | rcv->urb = usb_alloc_urb(0, GFP_KERNEL); |
1107 | dev_dbg(&intf->dev, "out of memory (read urbs usb_alloc_urb)\n"); | 1158 | if (rcv->urb == NULL) { |
1159 | dev_dbg(&intf->dev, | ||
1160 | "out of memory (read urbs usb_alloc_urb)\n"); | ||
1108 | goto alloc_fail7; | 1161 | goto alloc_fail7; |
1109 | } | 1162 | } |
1110 | 1163 | ||
@@ -1117,26 +1170,29 @@ skip_normal_probe: | |||
1117 | rb->base = usb_buffer_alloc(acm->dev, readsize, | 1170 | rb->base = usb_buffer_alloc(acm->dev, readsize, |
1118 | GFP_KERNEL, &rb->dma); | 1171 | GFP_KERNEL, &rb->dma); |
1119 | if (!rb->base) { | 1172 | if (!rb->base) { |
1120 | dev_dbg(&intf->dev, "out of memory (read bufs usb_buffer_alloc)\n"); | 1173 | dev_dbg(&intf->dev, |
1174 | "out of memory (read bufs usb_buffer_alloc)\n"); | ||
1121 | goto alloc_fail7; | 1175 | goto alloc_fail7; |
1122 | } | 1176 | } |
1123 | } | 1177 | } |
1124 | for(i = 0; i < ACM_NW; i++) | 1178 | for (i = 0; i < ACM_NW; i++) { |
1125 | { | ||
1126 | struct acm_wb *snd = &(acm->wb[i]); | 1179 | struct acm_wb *snd = &(acm->wb[i]); |
1127 | 1180 | ||
1128 | if (!(snd->urb = usb_alloc_urb(0, GFP_KERNEL))) { | 1181 | snd->urb = usb_alloc_urb(0, GFP_KERNEL); |
1129 | dev_dbg(&intf->dev, "out of memory (write urbs usb_alloc_urb)"); | 1182 | if (snd->urb == NULL) { |
1183 | dev_dbg(&intf->dev, | ||
1184 | "out of memory (write urbs usb_alloc_urb)"); | ||
1130 | goto alloc_fail7; | 1185 | goto alloc_fail7; |
1131 | } | 1186 | } |
1132 | 1187 | ||
1133 | usb_fill_bulk_urb(snd->urb, usb_dev, usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress), | 1188 | usb_fill_bulk_urb(snd->urb, usb_dev, |
1134 | NULL, acm->writesize, acm_write_bulk, snd); | 1189 | usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress), |
1190 | NULL, acm->writesize, acm_write_bulk, snd); | ||
1135 | snd->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | 1191 | snd->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
1136 | snd->instance = acm; | 1192 | snd->instance = acm; |
1137 | } | 1193 | } |
1138 | 1194 | ||
1139 | usb_set_intfdata (intf, acm); | 1195 | usb_set_intfdata(intf, acm); |
1140 | 1196 | ||
1141 | i = device_create_file(&intf->dev, &dev_attr_bmCapabilities); | 1197 | i = device_create_file(&intf->dev, &dev_attr_bmCapabilities); |
1142 | if (i < 0) | 1198 | if (i < 0) |
@@ -1147,7 +1203,8 @@ skip_normal_probe: | |||
1147 | if (!acm->country_codes) | 1203 | if (!acm->country_codes) |
1148 | goto skip_countries; | 1204 | goto skip_countries; |
1149 | acm->country_code_size = cfd->bLength - 4; | 1205 | acm->country_code_size = cfd->bLength - 4; |
1150 | memcpy(acm->country_codes, (u8 *)&cfd->wCountyCode0, cfd->bLength - 4); | 1206 | memcpy(acm->country_codes, (u8 *)&cfd->wCountyCode0, |
1207 | cfd->bLength - 4); | ||
1151 | acm->country_rel_date = cfd->iCountryCodeRelDate; | 1208 | acm->country_rel_date = cfd->iCountryCodeRelDate; |
1152 | 1209 | ||
1153 | i = device_create_file(&intf->dev, &dev_attr_wCountryCodes); | 1210 | i = device_create_file(&intf->dev, &dev_attr_wCountryCodes); |
@@ -1156,7 +1213,8 @@ skip_normal_probe: | |||
1156 | goto skip_countries; | 1213 | goto skip_countries; |
1157 | } | 1214 | } |
1158 | 1215 | ||
1159 | i = device_create_file(&intf->dev, &dev_attr_iCountryCodeRelDate); | 1216 | i = device_create_file(&intf->dev, |
1217 | &dev_attr_iCountryCodeRelDate); | ||
1160 | if (i < 0) { | 1218 | if (i < 0) { |
1161 | kfree(acm->country_codes); | 1219 | kfree(acm->country_codes); |
1162 | goto skip_countries; | 1220 | goto skip_countries; |
@@ -1164,8 +1222,10 @@ skip_normal_probe: | |||
1164 | } | 1222 | } |
1165 | 1223 | ||
1166 | skip_countries: | 1224 | skip_countries: |
1167 | usb_fill_int_urb(acm->ctrlurb, usb_dev, usb_rcvintpipe(usb_dev, epctrl->bEndpointAddress), | 1225 | usb_fill_int_urb(acm->ctrlurb, usb_dev, |
1168 | acm->ctrl_buffer, ctrlsize, acm_ctrl_irq, acm, epctrl->bInterval); | 1226 | usb_rcvintpipe(usb_dev, epctrl->bEndpointAddress), |
1227 | acm->ctrl_buffer, ctrlsize, acm_ctrl_irq, acm, | ||
1228 | epctrl->bInterval); | ||
1169 | acm->ctrlurb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | 1229 | acm->ctrlurb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
1170 | acm->ctrlurb->transfer_dma = acm->ctrl_dma; | 1230 | acm->ctrlurb->transfer_dma = acm->ctrl_dma; |
1171 | 1231 | ||
@@ -1212,7 +1272,7 @@ static void stop_data_traffic(struct acm *acm) | |||
1212 | tasklet_disable(&acm->urb_task); | 1272 | tasklet_disable(&acm->urb_task); |
1213 | 1273 | ||
1214 | usb_kill_urb(acm->ctrlurb); | 1274 | usb_kill_urb(acm->ctrlurb); |
1215 | for(i = 0; i < ACM_NW; i++) | 1275 | for (i = 0; i < ACM_NW; i++) |
1216 | usb_kill_urb(acm->wb[i].urb); | 1276 | usb_kill_urb(acm->wb[i].urb); |
1217 | for (i = 0; i < acm->rx_buflimit; i++) | 1277 | for (i = 0; i < acm->rx_buflimit; i++) |
1218 | usb_kill_urb(acm->ru[i].urb); | 1278 | usb_kill_urb(acm->ru[i].urb); |
@@ -1227,13 +1287,14 @@ static void acm_disconnect(struct usb_interface *intf) | |||
1227 | { | 1287 | { |
1228 | struct acm *acm = usb_get_intfdata(intf); | 1288 | struct acm *acm = usb_get_intfdata(intf); |
1229 | struct usb_device *usb_dev = interface_to_usbdev(intf); | 1289 | struct usb_device *usb_dev = interface_to_usbdev(intf); |
1290 | struct tty_struct *tty; | ||
1230 | 1291 | ||
1231 | /* sibling interface is already cleaning up */ | 1292 | /* sibling interface is already cleaning up */ |
1232 | if (!acm) | 1293 | if (!acm) |
1233 | return; | 1294 | return; |
1234 | 1295 | ||
1235 | mutex_lock(&open_mutex); | 1296 | mutex_lock(&open_mutex); |
1236 | if (acm->country_codes){ | 1297 | if (acm->country_codes) { |
1237 | device_remove_file(&acm->control->dev, | 1298 | device_remove_file(&acm->control->dev, |
1238 | &dev_attr_wCountryCodes); | 1299 | &dev_attr_wCountryCodes); |
1239 | device_remove_file(&acm->control->dev, | 1300 | device_remove_file(&acm->control->dev, |
@@ -1247,22 +1308,25 @@ static void acm_disconnect(struct usb_interface *intf) | |||
1247 | stop_data_traffic(acm); | 1308 | stop_data_traffic(acm); |
1248 | 1309 | ||
1249 | acm_write_buffers_free(acm); | 1310 | acm_write_buffers_free(acm); |
1250 | usb_buffer_free(usb_dev, acm->ctrlsize, acm->ctrl_buffer, acm->ctrl_dma); | 1311 | usb_buffer_free(usb_dev, acm->ctrlsize, acm->ctrl_buffer, |
1312 | acm->ctrl_dma); | ||
1251 | acm_read_buffers_free(acm); | 1313 | acm_read_buffers_free(acm); |
1252 | 1314 | ||
1253 | usb_driver_release_interface(&acm_driver, intf == acm->control ? | 1315 | usb_driver_release_interface(&acm_driver, intf == acm->control ? |
1254 | acm->data : acm->control); | 1316 | acm->data : acm->control); |
1255 | 1317 | ||
1256 | if (!acm->used) { | 1318 | if (acm->port.count == 0) { |
1257 | acm_tty_unregister(acm); | 1319 | acm_tty_unregister(acm); |
1258 | mutex_unlock(&open_mutex); | 1320 | mutex_unlock(&open_mutex); |
1259 | return; | 1321 | return; |
1260 | } | 1322 | } |
1261 | 1323 | ||
1262 | mutex_unlock(&open_mutex); | 1324 | mutex_unlock(&open_mutex); |
1263 | 1325 | tty = tty_port_tty_get(&acm->port); | |
1264 | if (acm->tty) | 1326 | if (tty) { |
1265 | tty_hangup(acm->tty); | 1327 | tty_hangup(tty); |
1328 | tty_kref_put(tty); | ||
1329 | } | ||
1266 | } | 1330 | } |
1267 | 1331 | ||
1268 | #ifdef CONFIG_PM | 1332 | #ifdef CONFIG_PM |
@@ -1297,7 +1361,7 @@ static int acm_suspend(struct usb_interface *intf, pm_message_t message) | |||
1297 | */ | 1361 | */ |
1298 | mutex_lock(&acm->mutex); | 1362 | mutex_lock(&acm->mutex); |
1299 | 1363 | ||
1300 | if (acm->used) | 1364 | if (acm->port.count) |
1301 | stop_data_traffic(acm); | 1365 | stop_data_traffic(acm); |
1302 | 1366 | ||
1303 | mutex_unlock(&acm->mutex); | 1367 | mutex_unlock(&acm->mutex); |
@@ -1319,7 +1383,7 @@ static int acm_resume(struct usb_interface *intf) | |||
1319 | return 0; | 1383 | return 0; |
1320 | 1384 | ||
1321 | mutex_lock(&acm->mutex); | 1385 | mutex_lock(&acm->mutex); |
1322 | if (acm->used) { | 1386 | if (acm->port.count) { |
1323 | rv = usb_submit_urb(acm->ctrlurb, GFP_NOIO); | 1387 | rv = usb_submit_urb(acm->ctrlurb, GFP_NOIO); |
1324 | if (rv < 0) | 1388 | if (rv < 0) |
1325 | goto err_out; | 1389 | goto err_out; |
@@ -1398,7 +1462,7 @@ static struct usb_device_id acm_ids[] = { | |||
1398 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, | 1462 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, |
1399 | USB_CDC_ACM_PROTO_AT_GSM) }, | 1463 | USB_CDC_ACM_PROTO_AT_GSM) }, |
1400 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, | 1464 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, |
1401 | USB_CDC_ACM_PROTO_AT_3G ) }, | 1465 | USB_CDC_ACM_PROTO_AT_3G) }, |
1402 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, | 1466 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, |
1403 | USB_CDC_ACM_PROTO_AT_CDMA) }, | 1467 | USB_CDC_ACM_PROTO_AT_CDMA) }, |
1404 | 1468 | ||
@@ -1406,7 +1470,7 @@ static struct usb_device_id acm_ids[] = { | |||
1406 | { } | 1470 | { } |
1407 | }; | 1471 | }; |
1408 | 1472 | ||
1409 | MODULE_DEVICE_TABLE (usb, acm_ids); | 1473 | MODULE_DEVICE_TABLE(usb, acm_ids); |
1410 | 1474 | ||
1411 | static struct usb_driver acm_driver = { | 1475 | static struct usb_driver acm_driver = { |
1412 | .name = "cdc_acm", | 1476 | .name = "cdc_acm", |
@@ -1429,6 +1493,7 @@ static struct usb_driver acm_driver = { | |||
1429 | static const struct tty_operations acm_ops = { | 1493 | static const struct tty_operations acm_ops = { |
1430 | .open = acm_tty_open, | 1494 | .open = acm_tty_open, |
1431 | .close = acm_tty_close, | 1495 | .close = acm_tty_close, |
1496 | .hangup = acm_tty_hangup, | ||
1432 | .write = acm_tty_write, | 1497 | .write = acm_tty_write, |
1433 | .write_room = acm_tty_write_room, | 1498 | .write_room = acm_tty_write_room, |
1434 | .ioctl = acm_tty_ioctl, | 1499 | .ioctl = acm_tty_ioctl, |
@@ -1460,7 +1525,8 @@ static int __init acm_init(void) | |||
1460 | acm_tty_driver->subtype = SERIAL_TYPE_NORMAL, | 1525 | acm_tty_driver->subtype = SERIAL_TYPE_NORMAL, |
1461 | acm_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; | 1526 | acm_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; |
1462 | acm_tty_driver->init_termios = tty_std_termios; | 1527 | acm_tty_driver->init_termios = tty_std_termios; |
1463 | acm_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; | 1528 | acm_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | |
1529 | HUPCL | CLOCAL; | ||
1464 | tty_set_operations(acm_tty_driver, &acm_ops); | 1530 | tty_set_operations(acm_tty_driver, &acm_ops); |
1465 | 1531 | ||
1466 | retval = tty_register_driver(acm_tty_driver); | 1532 | retval = tty_register_driver(acm_tty_driver); |
@@ -1492,7 +1558,7 @@ static void __exit acm_exit(void) | |||
1492 | module_init(acm_init); | 1558 | module_init(acm_init); |
1493 | module_exit(acm_exit); | 1559 | module_exit(acm_exit); |
1494 | 1560 | ||
1495 | MODULE_AUTHOR( DRIVER_AUTHOR ); | 1561 | MODULE_AUTHOR(DRIVER_AUTHOR); |
1496 | MODULE_DESCRIPTION( DRIVER_DESC ); | 1562 | MODULE_DESCRIPTION(DRIVER_DESC); |
1497 | MODULE_LICENSE("GPL"); | 1563 | MODULE_LICENSE("GPL"); |
1498 | MODULE_ALIAS_CHARDEV_MAJOR(ACM_TTY_MAJOR); | 1564 | MODULE_ALIAS_CHARDEV_MAJOR(ACM_TTY_MAJOR); |
diff --git a/drivers/usb/class/cdc-acm.h b/drivers/usb/class/cdc-acm.h index 1f95e7aa1b66..4c3856420add 100644 --- a/drivers/usb/class/cdc-acm.h +++ b/drivers/usb/class/cdc-acm.h | |||
@@ -89,8 +89,8 @@ struct acm { | |||
89 | struct usb_device *dev; /* the corresponding usb device */ | 89 | struct usb_device *dev; /* the corresponding usb device */ |
90 | struct usb_interface *control; /* control interface */ | 90 | struct usb_interface *control; /* control interface */ |
91 | struct usb_interface *data; /* data interface */ | 91 | struct usb_interface *data; /* data interface */ |
92 | struct tty_struct *tty; /* the corresponding tty */ | 92 | struct tty_port port; /* our tty port data */ |
93 | struct urb *ctrlurb; /* urbs */ | 93 | struct urb *ctrlurb; /* urbs */ |
94 | u8 *ctrl_buffer; /* buffers of urbs */ | 94 | u8 *ctrl_buffer; /* buffers of urbs */ |
95 | dma_addr_t ctrl_dma; /* dma handles of buffers */ | 95 | dma_addr_t ctrl_dma; /* dma handles of buffers */ |
96 | u8 *country_codes; /* country codes from device */ | 96 | u8 *country_codes; /* country codes from device */ |
@@ -120,7 +120,6 @@ struct acm { | |||
120 | unsigned int ctrlout; /* output control lines (DTR, RTS) */ | 120 | unsigned int ctrlout; /* output control lines (DTR, RTS) */ |
121 | unsigned int writesize; /* max packet size for the output bulk endpoint */ | 121 | unsigned int writesize; /* max packet size for the output bulk endpoint */ |
122 | unsigned int readsize,ctrlsize; /* buffer sizes for freeing */ | 122 | unsigned int readsize,ctrlsize; /* buffer sizes for freeing */ |
123 | unsigned int used; /* someone has this acm's device open */ | ||
124 | unsigned int minor; /* acm minor number */ | 123 | unsigned int minor; /* acm minor number */ |
125 | unsigned char throttle; /* throttled by tty layer */ | 124 | unsigned char throttle; /* throttled by tty layer */ |
126 | unsigned char clocal; /* termios CLOCAL */ | 125 | unsigned char clocal; /* termios CLOCAL */ |
diff --git a/drivers/usb/serial/belkin_sa.c b/drivers/usb/serial/belkin_sa.c index b7eacad4d48c..2bfd6dd85b5a 100644 --- a/drivers/usb/serial/belkin_sa.c +++ b/drivers/usb/serial/belkin_sa.c | |||
@@ -93,8 +93,7 @@ static int belkin_sa_startup(struct usb_serial *serial); | |||
93 | static void belkin_sa_shutdown(struct usb_serial *serial); | 93 | static void belkin_sa_shutdown(struct usb_serial *serial); |
94 | static int belkin_sa_open(struct tty_struct *tty, | 94 | static int belkin_sa_open(struct tty_struct *tty, |
95 | struct usb_serial_port *port, struct file *filp); | 95 | struct usb_serial_port *port, struct file *filp); |
96 | static void belkin_sa_close(struct tty_struct *tty, | 96 | static void belkin_sa_close(struct usb_serial_port *port); |
97 | struct usb_serial_port *port, struct file *filp); | ||
98 | static void belkin_sa_read_int_callback(struct urb *urb); | 97 | static void belkin_sa_read_int_callback(struct urb *urb); |
99 | static void belkin_sa_set_termios(struct tty_struct *tty, | 98 | static void belkin_sa_set_termios(struct tty_struct *tty, |
100 | struct usb_serial_port *port, struct ktermios * old); | 99 | struct usb_serial_port *port, struct ktermios * old); |
@@ -244,8 +243,7 @@ exit: | |||
244 | } /* belkin_sa_open */ | 243 | } /* belkin_sa_open */ |
245 | 244 | ||
246 | 245 | ||
247 | static void belkin_sa_close(struct tty_struct *tty, | 246 | static void belkin_sa_close(struct usb_serial_port *port) |
248 | struct usb_serial_port *port, struct file *filp) | ||
249 | { | 247 | { |
250 | dbg("%s port %d", __func__, port->number); | 248 | dbg("%s port %d", __func__, port->number); |
251 | 249 | ||
diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c index ab4cc277aa65..2830766f5b39 100644 --- a/drivers/usb/serial/ch341.c +++ b/drivers/usb/serial/ch341.c | |||
@@ -262,32 +262,40 @@ error: kfree(priv); | |||
262 | return r; | 262 | return r; |
263 | } | 263 | } |
264 | 264 | ||
265 | static void ch341_close(struct tty_struct *tty, struct usb_serial_port *port, | 265 | static int ch341_carrier_raised(struct usb_serial_port *port) |
266 | struct file *filp) | 266 | { |
267 | struct ch341_private *priv = usb_get_serial_port_data(port); | ||
268 | if (priv->line_status & CH341_BIT_DCD) | ||
269 | return 1; | ||
270 | return 0; | ||
271 | } | ||
272 | |||
273 | static void ch341_dtr_rts(struct usb_serial_port *port, int on) | ||
267 | { | 274 | { |
268 | struct ch341_private *priv = usb_get_serial_port_data(port); | 275 | struct ch341_private *priv = usb_get_serial_port_data(port); |
269 | unsigned long flags; | 276 | unsigned long flags; |
270 | unsigned int c_cflag; | ||
271 | 277 | ||
272 | dbg("%s - port %d", __func__, port->number); | 278 | dbg("%s - port %d", __func__, port->number); |
279 | /* drop DTR and RTS */ | ||
280 | spin_lock_irqsave(&priv->lock, flags); | ||
281 | if (on) | ||
282 | priv->line_control |= CH341_BIT_RTS | CH341_BIT_DTR; | ||
283 | else | ||
284 | priv->line_control &= ~(CH341_BIT_RTS | CH341_BIT_DTR); | ||
285 | spin_unlock_irqrestore(&priv->lock, flags); | ||
286 | ch341_set_handshake(port->serial->dev, priv->line_control); | ||
287 | wake_up_interruptible(&priv->delta_msr_wait); | ||
288 | } | ||
289 | |||
290 | static void ch341_close(struct usb_serial_port *port) | ||
291 | { | ||
292 | dbg("%s - port %d", __func__, port->number); | ||
273 | 293 | ||
274 | /* shutdown our urbs */ | 294 | /* shutdown our urbs */ |
275 | dbg("%s - shutting down urbs", __func__); | 295 | dbg("%s - shutting down urbs", __func__); |
276 | usb_kill_urb(port->write_urb); | 296 | usb_kill_urb(port->write_urb); |
277 | usb_kill_urb(port->read_urb); | 297 | usb_kill_urb(port->read_urb); |
278 | usb_kill_urb(port->interrupt_in_urb); | 298 | usb_kill_urb(port->interrupt_in_urb); |
279 | |||
280 | if (tty) { | ||
281 | c_cflag = tty->termios->c_cflag; | ||
282 | if (c_cflag & HUPCL) { | ||
283 | /* drop DTR and RTS */ | ||
284 | spin_lock_irqsave(&priv->lock, flags); | ||
285 | priv->line_control = 0; | ||
286 | spin_unlock_irqrestore(&priv->lock, flags); | ||
287 | ch341_set_handshake(port->serial->dev, 0); | ||
288 | } | ||
289 | } | ||
290 | wake_up_interruptible(&priv->delta_msr_wait); | ||
291 | } | 299 | } |
292 | 300 | ||
293 | 301 | ||
@@ -302,7 +310,6 @@ static int ch341_open(struct tty_struct *tty, struct usb_serial_port *port, | |||
302 | dbg("ch341_open()"); | 310 | dbg("ch341_open()"); |
303 | 311 | ||
304 | priv->baud_rate = DEFAULT_BAUD_RATE; | 312 | priv->baud_rate = DEFAULT_BAUD_RATE; |
305 | priv->line_control = CH341_BIT_RTS | CH341_BIT_DTR; | ||
306 | 313 | ||
307 | r = ch341_configure(serial->dev, priv); | 314 | r = ch341_configure(serial->dev, priv); |
308 | if (r) | 315 | if (r) |
@@ -322,7 +329,7 @@ static int ch341_open(struct tty_struct *tty, struct usb_serial_port *port, | |||
322 | if (r) { | 329 | if (r) { |
323 | dev_err(&port->dev, "%s - failed submitting interrupt urb," | 330 | dev_err(&port->dev, "%s - failed submitting interrupt urb," |
324 | " error %d\n", __func__, r); | 331 | " error %d\n", __func__, r); |
325 | ch341_close(tty, port, NULL); | 332 | ch341_close(port); |
326 | return -EPROTO; | 333 | return -EPROTO; |
327 | } | 334 | } |
328 | 335 | ||
@@ -343,9 +350,6 @@ static void ch341_set_termios(struct tty_struct *tty, | |||
343 | 350 | ||
344 | dbg("ch341_set_termios()"); | 351 | dbg("ch341_set_termios()"); |
345 | 352 | ||
346 | if (!tty || !tty->termios) | ||
347 | return; | ||
348 | |||
349 | baud_rate = tty_get_baud_rate(tty); | 353 | baud_rate = tty_get_baud_rate(tty); |
350 | 354 | ||
351 | priv->baud_rate = baud_rate; | 355 | priv->baud_rate = baud_rate; |
@@ -568,6 +572,8 @@ static struct usb_serial_driver ch341_device = { | |||
568 | .usb_driver = &ch341_driver, | 572 | .usb_driver = &ch341_driver, |
569 | .num_ports = 1, | 573 | .num_ports = 1, |
570 | .open = ch341_open, | 574 | .open = ch341_open, |
575 | .dtr_rts = ch341_dtr_rts, | ||
576 | .carrier_raised = ch341_carrier_raised, | ||
571 | .close = ch341_close, | 577 | .close = ch341_close, |
572 | .ioctl = ch341_ioctl, | 578 | .ioctl = ch341_ioctl, |
573 | .set_termios = ch341_set_termios, | 579 | .set_termios = ch341_set_termios, |
diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c index 19e24045b137..247b61bfb7f4 100644 --- a/drivers/usb/serial/console.c +++ b/drivers/usb/serial/console.c | |||
@@ -169,7 +169,9 @@ static int usb_console_setup(struct console *co, char *options) | |||
169 | kfree(tty); | 169 | kfree(tty); |
170 | } | 170 | } |
171 | } | 171 | } |
172 | 172 | /* So we know not to kill the hardware on a hangup on this | |
173 | port. We have also bumped the use count by one so it won't go | ||
174 | idle */ | ||
173 | port->console = 1; | 175 | port->console = 1; |
174 | retval = 0; | 176 | retval = 0; |
175 | 177 | ||
@@ -182,7 +184,7 @@ free_tty: | |||
182 | kfree(tty); | 184 | kfree(tty); |
183 | reset_open_count: | 185 | reset_open_count: |
184 | port->port.count = 0; | 186 | port->port.count = 0; |
185 | goto out; | 187 | goto out; |
186 | } | 188 | } |
187 | 189 | ||
188 | static void usb_console_write(struct console *co, | 190 | static void usb_console_write(struct console *co, |
diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c index e8d5133ce9c8..16a154d3b2fe 100644 --- a/drivers/usb/serial/cp210x.c +++ b/drivers/usb/serial/cp210x.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Silicon Laboratories CP2101/CP2102 USB to RS232 serial adaptor driver | 2 | * Silicon Laboratories CP210x USB to RS232 serial adaptor driver |
3 | * | 3 | * |
4 | * Copyright (C) 2005 Craig Shelley (craig@microtron.org.uk) | 4 | * Copyright (C) 2005 Craig Shelley (craig@microtron.org.uk) |
5 | * | 5 | * |
@@ -27,44 +27,46 @@ | |||
27 | /* | 27 | /* |
28 | * Version Information | 28 | * Version Information |
29 | */ | 29 | */ |
30 | #define DRIVER_VERSION "v0.08" | 30 | #define DRIVER_VERSION "v0.09" |
31 | #define DRIVER_DESC "Silicon Labs CP2101/CP2102 RS232 serial adaptor driver" | 31 | #define DRIVER_DESC "Silicon Labs CP210x RS232 serial adaptor driver" |
32 | 32 | ||
33 | /* | 33 | /* |
34 | * Function Prototypes | 34 | * Function Prototypes |
35 | */ | 35 | */ |
36 | static int cp2101_open(struct tty_struct *, struct usb_serial_port *, | 36 | static int cp210x_open(struct tty_struct *, struct usb_serial_port *, |
37 | struct file *); | 37 | struct file *); |
38 | static void cp2101_cleanup(struct usb_serial_port *); | 38 | static void cp210x_cleanup(struct usb_serial_port *); |
39 | static void cp2101_close(struct tty_struct *, struct usb_serial_port *, | 39 | static void cp210x_close(struct usb_serial_port *); |
40 | struct file*); | 40 | static void cp210x_get_termios(struct tty_struct *, |
41 | static void cp2101_get_termios(struct tty_struct *, | ||
42 | struct usb_serial_port *port); | 41 | struct usb_serial_port *port); |
43 | static void cp2101_get_termios_port(struct usb_serial_port *port, | 42 | static void cp210x_get_termios_port(struct usb_serial_port *port, |
44 | unsigned int *cflagp, unsigned int *baudp); | 43 | unsigned int *cflagp, unsigned int *baudp); |
45 | static void cp2101_set_termios(struct tty_struct *, struct usb_serial_port *, | 44 | static void cp210x_set_termios(struct tty_struct *, struct usb_serial_port *, |
46 | struct ktermios*); | 45 | struct ktermios*); |
47 | static int cp2101_tiocmget(struct tty_struct *, struct file *); | 46 | static int cp210x_tiocmget(struct tty_struct *, struct file *); |
48 | static int cp2101_tiocmset(struct tty_struct *, struct file *, | 47 | static int cp210x_tiocmset(struct tty_struct *, struct file *, |
49 | unsigned int, unsigned int); | 48 | unsigned int, unsigned int); |
50 | static int cp2101_tiocmset_port(struct usb_serial_port *port, struct file *, | 49 | static int cp210x_tiocmset_port(struct usb_serial_port *port, struct file *, |
51 | unsigned int, unsigned int); | 50 | unsigned int, unsigned int); |
52 | static void cp2101_break_ctl(struct tty_struct *, int); | 51 | static void cp210x_break_ctl(struct tty_struct *, int); |
53 | static int cp2101_startup(struct usb_serial *); | 52 | static int cp210x_startup(struct usb_serial *); |
54 | static void cp2101_shutdown(struct usb_serial *); | 53 | static void cp210x_shutdown(struct usb_serial *); |
55 | 54 | ||
56 | static int debug; | 55 | static int debug; |
57 | 56 | ||
58 | static struct usb_device_id id_table [] = { | 57 | static struct usb_device_id id_table [] = { |
59 | { USB_DEVICE(0x0471, 0x066A) }, /* AKTAKOM ACE-1001 cable */ | 58 | { USB_DEVICE(0x0471, 0x066A) }, /* AKTAKOM ACE-1001 cable */ |
60 | { USB_DEVICE(0x0489, 0xE000) }, /* Pirelli Broadband S.p.A, DP-L10 SIP/GSM Mobile */ | 59 | { USB_DEVICE(0x0489, 0xE000) }, /* Pirelli Broadband S.p.A, DP-L10 SIP/GSM Mobile */ |
60 | { USB_DEVICE(0x0745, 0x1000) }, /* CipherLab USB CCD Barcode Scanner 1000 */ | ||
61 | { USB_DEVICE(0x08e6, 0x5501) }, /* Gemalto Prox-PU/CU contactless smartcard reader */ | 61 | { USB_DEVICE(0x08e6, 0x5501) }, /* Gemalto Prox-PU/CU contactless smartcard reader */ |
62 | { USB_DEVICE(0x08FD, 0x000A) }, /* Digianswer A/S , ZigBee/802.15.4 MAC Device */ | ||
62 | { USB_DEVICE(0x0FCF, 0x1003) }, /* Dynastream ANT development board */ | 63 | { USB_DEVICE(0x0FCF, 0x1003) }, /* Dynastream ANT development board */ |
63 | { USB_DEVICE(0x0FCF, 0x1004) }, /* Dynastream ANT2USB */ | 64 | { USB_DEVICE(0x0FCF, 0x1004) }, /* Dynastream ANT2USB */ |
64 | { USB_DEVICE(0x0FCF, 0x1006) }, /* Dynastream ANT development board */ | 65 | { USB_DEVICE(0x0FCF, 0x1006) }, /* Dynastream ANT development board */ |
65 | { USB_DEVICE(0x10A6, 0xAA26) }, /* Knock-off DCU-11 cable */ | 66 | { USB_DEVICE(0x10A6, 0xAA26) }, /* Knock-off DCU-11 cable */ |
66 | { USB_DEVICE(0x10AB, 0x10C5) }, /* Siemens MC60 Cable */ | 67 | { USB_DEVICE(0x10AB, 0x10C5) }, /* Siemens MC60 Cable */ |
67 | { USB_DEVICE(0x10B5, 0xAC70) }, /* Nokia CA-42 USB */ | 68 | { USB_DEVICE(0x10B5, 0xAC70) }, /* Nokia CA-42 USB */ |
69 | { USB_DEVICE(0x10C4, 0x0F91) }, /* Vstabi */ | ||
68 | { USB_DEVICE(0x10C4, 0x800A) }, /* SPORTident BSM7-D-USB main station */ | 70 | { USB_DEVICE(0x10C4, 0x800A) }, /* SPORTident BSM7-D-USB main station */ |
69 | { USB_DEVICE(0x10C4, 0x803B) }, /* Pololu USB-serial converter */ | 71 | { USB_DEVICE(0x10C4, 0x803B) }, /* Pololu USB-serial converter */ |
70 | { USB_DEVICE(0x10C4, 0x8053) }, /* Enfora EDG1228 */ | 72 | { USB_DEVICE(0x10C4, 0x8053) }, /* Enfora EDG1228 */ |
@@ -85,10 +87,12 @@ static struct usb_device_id id_table [] = { | |||
85 | { USB_DEVICE(0x10C4, 0x81C8) }, /* Lipowsky Industrie Elektronik GmbH, Baby-JTAG */ | 87 | { USB_DEVICE(0x10C4, 0x81C8) }, /* Lipowsky Industrie Elektronik GmbH, Baby-JTAG */ |
86 | { USB_DEVICE(0x10C4, 0x81E2) }, /* Lipowsky Industrie Elektronik GmbH, Baby-LIN */ | 88 | { USB_DEVICE(0x10C4, 0x81E2) }, /* Lipowsky Industrie Elektronik GmbH, Baby-LIN */ |
87 | { USB_DEVICE(0x10C4, 0x81E7) }, /* Aerocomm Radio */ | 89 | { USB_DEVICE(0x10C4, 0x81E7) }, /* Aerocomm Radio */ |
90 | { USB_DEVICE(0x10C4, 0x81F2) }, /* C1007 HF band RFID controller */ | ||
88 | { USB_DEVICE(0x10C4, 0x8218) }, /* Lipowsky Industrie Elektronik GmbH, HARP-1 */ | 91 | { USB_DEVICE(0x10C4, 0x8218) }, /* Lipowsky Industrie Elektronik GmbH, HARP-1 */ |
89 | { USB_DEVICE(0x10C4, 0x822B) }, /* Modem EDGE(GSM) Comander 2 */ | 92 | { USB_DEVICE(0x10C4, 0x822B) }, /* Modem EDGE(GSM) Comander 2 */ |
90 | { USB_DEVICE(0x10C4, 0x826B) }, /* Cygnal Integrated Products, Inc., Fasttrax GPS demostration module */ | 93 | { USB_DEVICE(0x10C4, 0x826B) }, /* Cygnal Integrated Products, Inc., Fasttrax GPS demostration module */ |
91 | { USB_DEVICE(0x10c4, 0x8293) }, /* Telegesys ETRX2USB */ | 94 | { USB_DEVICE(0x10c4, 0x8293) }, /* Telegesys ETRX2USB */ |
95 | { USB_DEVICE(0x10C4, 0x82F9) }, /* Procyon AVS */ | ||
92 | { USB_DEVICE(0x10C4, 0x8341) }, /* Siemens MC35PU GPRS Modem */ | 96 | { USB_DEVICE(0x10C4, 0x8341) }, /* Siemens MC35PU GPRS Modem */ |
93 | { USB_DEVICE(0x10C4, 0x83A8) }, /* Amber Wireless AMB2560 */ | 97 | { USB_DEVICE(0x10C4, 0x83A8) }, /* Amber Wireless AMB2560 */ |
94 | { USB_DEVICE(0x10C4, 0x846E) }, /* BEI USB Sensor Interface (VCP) */ | 98 | { USB_DEVICE(0x10C4, 0x846E) }, /* BEI USB Sensor Interface (VCP) */ |
@@ -99,7 +103,9 @@ static struct usb_device_id id_table [] = { | |||
99 | { USB_DEVICE(0x10C4, 0xF003) }, /* Elan Digital Systems USBpulse100 */ | 103 | { USB_DEVICE(0x10C4, 0xF003) }, /* Elan Digital Systems USBpulse100 */ |
100 | { USB_DEVICE(0x10C4, 0xF004) }, /* Elan Digital Systems USBcount50 */ | 104 | { USB_DEVICE(0x10C4, 0xF004) }, /* Elan Digital Systems USBcount50 */ |
101 | { USB_DEVICE(0x10C5, 0xEA61) }, /* Silicon Labs MobiData GPRS USB Modem */ | 105 | { USB_DEVICE(0x10C5, 0xEA61) }, /* Silicon Labs MobiData GPRS USB Modem */ |
106 | { USB_DEVICE(0x10CE, 0xEA6A) }, /* Silicon Labs MobiData GPRS USB Modem 100EU */ | ||
102 | { USB_DEVICE(0x13AD, 0x9999) }, /* Baltech card reader */ | 107 | { USB_DEVICE(0x13AD, 0x9999) }, /* Baltech card reader */ |
108 | { USB_DEVICE(0x1555, 0x0004) }, /* Owen AC4 USB-RS485 Converter */ | ||
103 | { USB_DEVICE(0x166A, 0x0303) }, /* Clipsal 5500PCU C-Bus USB interface */ | 109 | { USB_DEVICE(0x166A, 0x0303) }, /* Clipsal 5500PCU C-Bus USB interface */ |
104 | { USB_DEVICE(0x16D6, 0x0001) }, /* Jablotron serial interface */ | 110 | { USB_DEVICE(0x16D6, 0x0001) }, /* Jablotron serial interface */ |
105 | { USB_DEVICE(0x18EF, 0xE00F) }, /* ELV USB-I2C-Interface */ | 111 | { USB_DEVICE(0x18EF, 0xE00F) }, /* ELV USB-I2C-Interface */ |
@@ -108,53 +114,70 @@ static struct usb_device_id id_table [] = { | |||
108 | 114 | ||
109 | MODULE_DEVICE_TABLE(usb, id_table); | 115 | MODULE_DEVICE_TABLE(usb, id_table); |
110 | 116 | ||
111 | static struct usb_driver cp2101_driver = { | 117 | static struct usb_driver cp210x_driver = { |
112 | .name = "cp2101", | 118 | .name = "cp210x", |
113 | .probe = usb_serial_probe, | 119 | .probe = usb_serial_probe, |
114 | .disconnect = usb_serial_disconnect, | 120 | .disconnect = usb_serial_disconnect, |
115 | .id_table = id_table, | 121 | .id_table = id_table, |
116 | .no_dynamic_id = 1, | 122 | .no_dynamic_id = 1, |
117 | }; | 123 | }; |
118 | 124 | ||
119 | static struct usb_serial_driver cp2101_device = { | 125 | static struct usb_serial_driver cp210x_device = { |
120 | .driver = { | 126 | .driver = { |
121 | .owner = THIS_MODULE, | 127 | .owner = THIS_MODULE, |
122 | .name = "cp2101", | 128 | .name = "cp210x", |
123 | }, | 129 | }, |
124 | .usb_driver = &cp2101_driver, | 130 | .usb_driver = &cp210x_driver, |
125 | .id_table = id_table, | 131 | .id_table = id_table, |
126 | .num_ports = 1, | 132 | .num_ports = 1, |
127 | .open = cp2101_open, | 133 | .open = cp210x_open, |
128 | .close = cp2101_close, | 134 | .close = cp210x_close, |
129 | .break_ctl = cp2101_break_ctl, | 135 | .break_ctl = cp210x_break_ctl, |
130 | .set_termios = cp2101_set_termios, | 136 | .set_termios = cp210x_set_termios, |
131 | .tiocmget = cp2101_tiocmget, | 137 | .tiocmget = cp210x_tiocmget, |
132 | .tiocmset = cp2101_tiocmset, | 138 | .tiocmset = cp210x_tiocmset, |
133 | .attach = cp2101_startup, | 139 | .attach = cp210x_startup, |
134 | .shutdown = cp2101_shutdown, | 140 | .shutdown = cp210x_shutdown, |
135 | }; | 141 | }; |
136 | 142 | ||
137 | /* Config request types */ | 143 | /* Config request types */ |
138 | #define REQTYPE_HOST_TO_DEVICE 0x41 | 144 | #define REQTYPE_HOST_TO_DEVICE 0x41 |
139 | #define REQTYPE_DEVICE_TO_HOST 0xc1 | 145 | #define REQTYPE_DEVICE_TO_HOST 0xc1 |
140 | 146 | ||
141 | /* Config SET requests. To GET, add 1 to the request number */ | 147 | /* Config request codes */ |
142 | #define CP2101_UART 0x00 /* Enable / Disable */ | 148 | #define CP210X_IFC_ENABLE 0x00 |
143 | #define CP2101_BAUDRATE 0x01 /* (BAUD_RATE_GEN_FREQ / baudrate) */ | 149 | #define CP210X_SET_BAUDDIV 0x01 |
144 | #define CP2101_BITS 0x03 /* 0x(0)(databits)(parity)(stopbits) */ | 150 | #define CP210X_GET_BAUDDIV 0x02 |
145 | #define CP2101_BREAK 0x05 /* On / Off */ | 151 | #define CP210X_SET_LINE_CTL 0x03 |
146 | #define CP2101_CONTROL 0x07 /* Flow control line states */ | 152 | #define CP210X_GET_LINE_CTL 0x04 |
147 | #define CP2101_MODEMCTL 0x13 /* Modem controls */ | 153 | #define CP210X_SET_BREAK 0x05 |
148 | #define CP2101_CONFIG_6 0x19 /* 6 bytes of config data ??? */ | 154 | #define CP210X_IMM_CHAR 0x06 |
149 | 155 | #define CP210X_SET_MHS 0x07 | |
150 | /* CP2101_UART */ | 156 | #define CP210X_GET_MDMSTS 0x08 |
157 | #define CP210X_SET_XON 0x09 | ||
158 | #define CP210X_SET_XOFF 0x0A | ||
159 | #define CP210X_SET_EVENTMASK 0x0B | ||
160 | #define CP210X_GET_EVENTMASK 0x0C | ||
161 | #define CP210X_SET_CHAR 0x0D | ||
162 | #define CP210X_GET_CHARS 0x0E | ||
163 | #define CP210X_GET_PROPS 0x0F | ||
164 | #define CP210X_GET_COMM_STATUS 0x10 | ||
165 | #define CP210X_RESET 0x11 | ||
166 | #define CP210X_PURGE 0x12 | ||
167 | #define CP210X_SET_FLOW 0x13 | ||
168 | #define CP210X_GET_FLOW 0x14 | ||
169 | #define CP210X_EMBED_EVENTS 0x15 | ||
170 | #define CP210X_GET_EVENTSTATE 0x16 | ||
171 | #define CP210X_SET_CHARS 0x19 | ||
172 | |||
173 | /* CP210X_IFC_ENABLE */ | ||
151 | #define UART_ENABLE 0x0001 | 174 | #define UART_ENABLE 0x0001 |
152 | #define UART_DISABLE 0x0000 | 175 | #define UART_DISABLE 0x0000 |
153 | 176 | ||
154 | /* CP2101_BAUDRATE */ | 177 | /* CP210X_(SET|GET)_BAUDDIV */ |
155 | #define BAUD_RATE_GEN_FREQ 0x384000 | 178 | #define BAUD_RATE_GEN_FREQ 0x384000 |
156 | 179 | ||
157 | /* CP2101_BITS */ | 180 | /* CP210X_(SET|GET)_LINE_CTL */ |
158 | #define BITS_DATA_MASK 0X0f00 | 181 | #define BITS_DATA_MASK 0X0f00 |
159 | #define BITS_DATA_5 0X0500 | 182 | #define BITS_DATA_5 0X0500 |
160 | #define BITS_DATA_6 0X0600 | 183 | #define BITS_DATA_6 0X0600 |
@@ -174,11 +197,11 @@ static struct usb_serial_driver cp2101_device = { | |||
174 | #define BITS_STOP_1_5 0x0001 | 197 | #define BITS_STOP_1_5 0x0001 |
175 | #define BITS_STOP_2 0x0002 | 198 | #define BITS_STOP_2 0x0002 |
176 | 199 | ||
177 | /* CP2101_BREAK */ | 200 | /* CP210X_SET_BREAK */ |
178 | #define BREAK_ON 0x0000 | 201 | #define BREAK_ON 0x0000 |
179 | #define BREAK_OFF 0x0001 | 202 | #define BREAK_OFF 0x0001 |
180 | 203 | ||
181 | /* CP2101_CONTROL */ | 204 | /* CP210X_(SET_MHS|GET_MDMSTS) */ |
182 | #define CONTROL_DTR 0x0001 | 205 | #define CONTROL_DTR 0x0001 |
183 | #define CONTROL_RTS 0x0002 | 206 | #define CONTROL_RTS 0x0002 |
184 | #define CONTROL_CTS 0x0010 | 207 | #define CONTROL_CTS 0x0010 |
@@ -189,13 +212,13 @@ static struct usb_serial_driver cp2101_device = { | |||
189 | #define CONTROL_WRITE_RTS 0x0200 | 212 | #define CONTROL_WRITE_RTS 0x0200 |
190 | 213 | ||
191 | /* | 214 | /* |
192 | * cp2101_get_config | 215 | * cp210x_get_config |
193 | * Reads from the CP2101 configuration registers | 216 | * Reads from the CP210x configuration registers |
194 | * 'size' is specified in bytes. | 217 | * 'size' is specified in bytes. |
195 | * 'data' is a pointer to a pre-allocated array of integers large | 218 | * 'data' is a pointer to a pre-allocated array of integers large |
196 | * enough to hold 'size' bytes (with 4 bytes to each integer) | 219 | * enough to hold 'size' bytes (with 4 bytes to each integer) |
197 | */ | 220 | */ |
198 | static int cp2101_get_config(struct usb_serial_port *port, u8 request, | 221 | static int cp210x_get_config(struct usb_serial_port *port, u8 request, |
199 | unsigned int *data, int size) | 222 | unsigned int *data, int size) |
200 | { | 223 | { |
201 | struct usb_serial *serial = port->serial; | 224 | struct usb_serial *serial = port->serial; |
@@ -211,9 +234,6 @@ static int cp2101_get_config(struct usb_serial_port *port, u8 request, | |||
211 | return -ENOMEM; | 234 | return -ENOMEM; |
212 | } | 235 | } |
213 | 236 | ||
214 | /* For get requests, the request number must be incremented */ | ||
215 | request++; | ||
216 | |||
217 | /* Issue the request, attempting to read 'size' bytes */ | 237 | /* Issue the request, attempting to read 'size' bytes */ |
218 | result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), | 238 | result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), |
219 | request, REQTYPE_DEVICE_TO_HOST, 0x0000, | 239 | request, REQTYPE_DEVICE_TO_HOST, 0x0000, |
@@ -236,12 +256,12 @@ static int cp2101_get_config(struct usb_serial_port *port, u8 request, | |||
236 | } | 256 | } |
237 | 257 | ||
238 | /* | 258 | /* |
239 | * cp2101_set_config | 259 | * cp210x_set_config |
240 | * Writes to the CP2101 configuration registers | 260 | * Writes to the CP210x configuration registers |
241 | * Values less than 16 bits wide are sent directly | 261 | * Values less than 16 bits wide are sent directly |
242 | * 'size' is specified in bytes. | 262 | * 'size' is specified in bytes. |
243 | */ | 263 | */ |
244 | static int cp2101_set_config(struct usb_serial_port *port, u8 request, | 264 | static int cp210x_set_config(struct usb_serial_port *port, u8 request, |
245 | unsigned int *data, int size) | 265 | unsigned int *data, int size) |
246 | { | 266 | { |
247 | struct usb_serial *serial = port->serial; | 267 | struct usb_serial *serial = port->serial; |
@@ -292,21 +312,21 @@ static int cp2101_set_config(struct usb_serial_port *port, u8 request, | |||
292 | } | 312 | } |
293 | 313 | ||
294 | /* | 314 | /* |
295 | * cp2101_set_config_single | 315 | * cp210x_set_config_single |
296 | * Convenience function for calling cp2101_set_config on single data values | 316 | * Convenience function for calling cp210x_set_config on single data values |
297 | * without requiring an integer pointer | 317 | * without requiring an integer pointer |
298 | */ | 318 | */ |
299 | static inline int cp2101_set_config_single(struct usb_serial_port *port, | 319 | static inline int cp210x_set_config_single(struct usb_serial_port *port, |
300 | u8 request, unsigned int data) | 320 | u8 request, unsigned int data) |
301 | { | 321 | { |
302 | return cp2101_set_config(port, request, &data, 2); | 322 | return cp210x_set_config(port, request, &data, 2); |
303 | } | 323 | } |
304 | 324 | ||
305 | /* | 325 | /* |
306 | * cp2101_quantise_baudrate | 326 | * cp210x_quantise_baudrate |
307 | * Quantises the baud rate as per AN205 Table 1 | 327 | * Quantises the baud rate as per AN205 Table 1 |
308 | */ | 328 | */ |
309 | static unsigned int cp2101_quantise_baudrate(unsigned int baud) { | 329 | static unsigned int cp210x_quantise_baudrate(unsigned int baud) { |
310 | if (baud <= 56) baud = 0; | 330 | if (baud <= 56) baud = 0; |
311 | else if (baud <= 300) baud = 300; | 331 | else if (baud <= 300) baud = 300; |
312 | else if (baud <= 600) baud = 600; | 332 | else if (baud <= 600) baud = 600; |
@@ -343,7 +363,7 @@ static unsigned int cp2101_quantise_baudrate(unsigned int baud) { | |||
343 | return baud; | 363 | return baud; |
344 | } | 364 | } |
345 | 365 | ||
346 | static int cp2101_open(struct tty_struct *tty, struct usb_serial_port *port, | 366 | static int cp210x_open(struct tty_struct *tty, struct usb_serial_port *port, |
347 | struct file *filp) | 367 | struct file *filp) |
348 | { | 368 | { |
349 | struct usb_serial *serial = port->serial; | 369 | struct usb_serial *serial = port->serial; |
@@ -351,7 +371,7 @@ static int cp2101_open(struct tty_struct *tty, struct usb_serial_port *port, | |||
351 | 371 | ||
352 | dbg("%s - port %d", __func__, port->number); | 372 | dbg("%s - port %d", __func__, port->number); |
353 | 373 | ||
354 | if (cp2101_set_config_single(port, CP2101_UART, UART_ENABLE)) { | 374 | if (cp210x_set_config_single(port, CP210X_IFC_ENABLE, UART_ENABLE)) { |
355 | dev_err(&port->dev, "%s - Unable to enable UART\n", | 375 | dev_err(&port->dev, "%s - Unable to enable UART\n", |
356 | __func__); | 376 | __func__); |
357 | return -EPROTO; | 377 | return -EPROTO; |
@@ -373,17 +393,17 @@ static int cp2101_open(struct tty_struct *tty, struct usb_serial_port *port, | |||
373 | } | 393 | } |
374 | 394 | ||
375 | /* Configure the termios structure */ | 395 | /* Configure the termios structure */ |
376 | cp2101_get_termios(tty, port); | 396 | cp210x_get_termios(tty, port); |
377 | 397 | ||
378 | /* Set the DTR and RTS pins low */ | 398 | /* Set the DTR and RTS pins low */ |
379 | cp2101_tiocmset_port(tty ? (struct usb_serial_port *) tty->driver_data | 399 | cp210x_tiocmset_port(tty ? (struct usb_serial_port *) tty->driver_data |
380 | : port, | 400 | : port, |
381 | NULL, TIOCM_DTR | TIOCM_RTS, 0); | 401 | NULL, TIOCM_DTR | TIOCM_RTS, 0); |
382 | 402 | ||
383 | return 0; | 403 | return 0; |
384 | } | 404 | } |
385 | 405 | ||
386 | static void cp2101_cleanup(struct usb_serial_port *port) | 406 | static void cp210x_cleanup(struct usb_serial_port *port) |
387 | { | 407 | { |
388 | struct usb_serial *serial = port->serial; | 408 | struct usb_serial *serial = port->serial; |
389 | 409 | ||
@@ -398,8 +418,7 @@ static void cp2101_cleanup(struct usb_serial_port *port) | |||
398 | } | 418 | } |
399 | } | 419 | } |
400 | 420 | ||
401 | static void cp2101_close(struct tty_struct *tty, struct usb_serial_port *port, | 421 | static void cp210x_close(struct usb_serial_port *port) |
402 | struct file *filp) | ||
403 | { | 422 | { |
404 | dbg("%s - port %d", __func__, port->number); | 423 | dbg("%s - port %d", __func__, port->number); |
405 | 424 | ||
@@ -410,23 +429,23 @@ static void cp2101_close(struct tty_struct *tty, struct usb_serial_port *port, | |||
410 | 429 | ||
411 | mutex_lock(&port->serial->disc_mutex); | 430 | mutex_lock(&port->serial->disc_mutex); |
412 | if (!port->serial->disconnected) | 431 | if (!port->serial->disconnected) |
413 | cp2101_set_config_single(port, CP2101_UART, UART_DISABLE); | 432 | cp210x_set_config_single(port, CP210X_IFC_ENABLE, UART_DISABLE); |
414 | mutex_unlock(&port->serial->disc_mutex); | 433 | mutex_unlock(&port->serial->disc_mutex); |
415 | } | 434 | } |
416 | 435 | ||
417 | /* | 436 | /* |
418 | * cp2101_get_termios | 437 | * cp210x_get_termios |
419 | * Reads the baud rate, data bits, parity, stop bits and flow control mode | 438 | * Reads the baud rate, data bits, parity, stop bits and flow control mode |
420 | * from the device, corrects any unsupported values, and configures the | 439 | * from the device, corrects any unsupported values, and configures the |
421 | * termios structure to reflect the state of the device | 440 | * termios structure to reflect the state of the device |
422 | */ | 441 | */ |
423 | static void cp2101_get_termios(struct tty_struct *tty, | 442 | static void cp210x_get_termios(struct tty_struct *tty, |
424 | struct usb_serial_port *port) | 443 | struct usb_serial_port *port) |
425 | { | 444 | { |
426 | unsigned int baud; | 445 | unsigned int baud; |
427 | 446 | ||
428 | if (tty) { | 447 | if (tty) { |
429 | cp2101_get_termios_port(tty->driver_data, | 448 | cp210x_get_termios_port(tty->driver_data, |
430 | &tty->termios->c_cflag, &baud); | 449 | &tty->termios->c_cflag, &baud); |
431 | tty_encode_baud_rate(tty, baud, baud); | 450 | tty_encode_baud_rate(tty, baud, baud); |
432 | } | 451 | } |
@@ -434,15 +453,15 @@ static void cp2101_get_termios(struct tty_struct *tty, | |||
434 | else { | 453 | else { |
435 | unsigned int cflag; | 454 | unsigned int cflag; |
436 | cflag = 0; | 455 | cflag = 0; |
437 | cp2101_get_termios_port(port, &cflag, &baud); | 456 | cp210x_get_termios_port(port, &cflag, &baud); |
438 | } | 457 | } |
439 | } | 458 | } |
440 | 459 | ||
441 | /* | 460 | /* |
442 | * cp2101_get_termios_port | 461 | * cp210x_get_termios_port |
443 | * This is the heart of cp2101_get_termios which always uses a &usb_serial_port. | 462 | * This is the heart of cp210x_get_termios which always uses a &usb_serial_port. |
444 | */ | 463 | */ |
445 | static void cp2101_get_termios_port(struct usb_serial_port *port, | 464 | static void cp210x_get_termios_port(struct usb_serial_port *port, |
446 | unsigned int *cflagp, unsigned int *baudp) | 465 | unsigned int *cflagp, unsigned int *baudp) |
447 | { | 466 | { |
448 | unsigned int cflag, modem_ctl[4]; | 467 | unsigned int cflag, modem_ctl[4]; |
@@ -451,17 +470,17 @@ static void cp2101_get_termios_port(struct usb_serial_port *port, | |||
451 | 470 | ||
452 | dbg("%s - port %d", __func__, port->number); | 471 | dbg("%s - port %d", __func__, port->number); |
453 | 472 | ||
454 | cp2101_get_config(port, CP2101_BAUDRATE, &baud, 2); | 473 | cp210x_get_config(port, CP210X_GET_BAUDDIV, &baud, 2); |
455 | /* Convert to baudrate */ | 474 | /* Convert to baudrate */ |
456 | if (baud) | 475 | if (baud) |
457 | baud = cp2101_quantise_baudrate((BAUD_RATE_GEN_FREQ + baud/2)/ baud); | 476 | baud = cp210x_quantise_baudrate((BAUD_RATE_GEN_FREQ + baud/2)/ baud); |
458 | 477 | ||
459 | dbg("%s - baud rate = %d", __func__, baud); | 478 | dbg("%s - baud rate = %d", __func__, baud); |
460 | *baudp = baud; | 479 | *baudp = baud; |
461 | 480 | ||
462 | cflag = *cflagp; | 481 | cflag = *cflagp; |
463 | 482 | ||
464 | cp2101_get_config(port, CP2101_BITS, &bits, 2); | 483 | cp210x_get_config(port, CP210X_GET_LINE_CTL, &bits, 2); |
465 | cflag &= ~CSIZE; | 484 | cflag &= ~CSIZE; |
466 | switch (bits & BITS_DATA_MASK) { | 485 | switch (bits & BITS_DATA_MASK) { |
467 | case BITS_DATA_5: | 486 | case BITS_DATA_5: |
@@ -486,14 +505,14 @@ static void cp2101_get_termios_port(struct usb_serial_port *port, | |||
486 | cflag |= CS8; | 505 | cflag |= CS8; |
487 | bits &= ~BITS_DATA_MASK; | 506 | bits &= ~BITS_DATA_MASK; |
488 | bits |= BITS_DATA_8; | 507 | bits |= BITS_DATA_8; |
489 | cp2101_set_config(port, CP2101_BITS, &bits, 2); | 508 | cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2); |
490 | break; | 509 | break; |
491 | default: | 510 | default: |
492 | dbg("%s - Unknown number of data bits, using 8", __func__); | 511 | dbg("%s - Unknown number of data bits, using 8", __func__); |
493 | cflag |= CS8; | 512 | cflag |= CS8; |
494 | bits &= ~BITS_DATA_MASK; | 513 | bits &= ~BITS_DATA_MASK; |
495 | bits |= BITS_DATA_8; | 514 | bits |= BITS_DATA_8; |
496 | cp2101_set_config(port, CP2101_BITS, &bits, 2); | 515 | cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2); |
497 | break; | 516 | break; |
498 | } | 517 | } |
499 | 518 | ||
@@ -516,20 +535,20 @@ static void cp2101_get_termios_port(struct usb_serial_port *port, | |||
516 | __func__); | 535 | __func__); |
517 | cflag &= ~PARENB; | 536 | cflag &= ~PARENB; |
518 | bits &= ~BITS_PARITY_MASK; | 537 | bits &= ~BITS_PARITY_MASK; |
519 | cp2101_set_config(port, CP2101_BITS, &bits, 2); | 538 | cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2); |
520 | break; | 539 | break; |
521 | case BITS_PARITY_SPACE: | 540 | case BITS_PARITY_SPACE: |
522 | dbg("%s - parity = SPACE (not supported, disabling parity)", | 541 | dbg("%s - parity = SPACE (not supported, disabling parity)", |
523 | __func__); | 542 | __func__); |
524 | cflag &= ~PARENB; | 543 | cflag &= ~PARENB; |
525 | bits &= ~BITS_PARITY_MASK; | 544 | bits &= ~BITS_PARITY_MASK; |
526 | cp2101_set_config(port, CP2101_BITS, &bits, 2); | 545 | cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2); |
527 | break; | 546 | break; |
528 | default: | 547 | default: |
529 | dbg("%s - Unknown parity mode, disabling parity", __func__); | 548 | dbg("%s - Unknown parity mode, disabling parity", __func__); |
530 | cflag &= ~PARENB; | 549 | cflag &= ~PARENB; |
531 | bits &= ~BITS_PARITY_MASK; | 550 | bits &= ~BITS_PARITY_MASK; |
532 | cp2101_set_config(port, CP2101_BITS, &bits, 2); | 551 | cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2); |
533 | break; | 552 | break; |
534 | } | 553 | } |
535 | 554 | ||
@@ -542,7 +561,7 @@ static void cp2101_get_termios_port(struct usb_serial_port *port, | |||
542 | dbg("%s - stop bits = 1.5 (not supported, using 1 stop bit)", | 561 | dbg("%s - stop bits = 1.5 (not supported, using 1 stop bit)", |
543 | __func__); | 562 | __func__); |
544 | bits &= ~BITS_STOP_MASK; | 563 | bits &= ~BITS_STOP_MASK; |
545 | cp2101_set_config(port, CP2101_BITS, &bits, 2); | 564 | cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2); |
546 | break; | 565 | break; |
547 | case BITS_STOP_2: | 566 | case BITS_STOP_2: |
548 | dbg("%s - stop bits = 2", __func__); | 567 | dbg("%s - stop bits = 2", __func__); |
@@ -552,11 +571,11 @@ static void cp2101_get_termios_port(struct usb_serial_port *port, | |||
552 | dbg("%s - Unknown number of stop bits, using 1 stop bit", | 571 | dbg("%s - Unknown number of stop bits, using 1 stop bit", |
553 | __func__); | 572 | __func__); |
554 | bits &= ~BITS_STOP_MASK; | 573 | bits &= ~BITS_STOP_MASK; |
555 | cp2101_set_config(port, CP2101_BITS, &bits, 2); | 574 | cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2); |
556 | break; | 575 | break; |
557 | } | 576 | } |
558 | 577 | ||
559 | cp2101_get_config(port, CP2101_MODEMCTL, modem_ctl, 16); | 578 | cp210x_get_config(port, CP210X_GET_FLOW, modem_ctl, 16); |
560 | if (modem_ctl[0] & 0x0008) { | 579 | if (modem_ctl[0] & 0x0008) { |
561 | dbg("%s - flow control = CRTSCTS", __func__); | 580 | dbg("%s - flow control = CRTSCTS", __func__); |
562 | cflag |= CRTSCTS; | 581 | cflag |= CRTSCTS; |
@@ -568,7 +587,7 @@ static void cp2101_get_termios_port(struct usb_serial_port *port, | |||
568 | *cflagp = cflag; | 587 | *cflagp = cflag; |
569 | } | 588 | } |
570 | 589 | ||
571 | static void cp2101_set_termios(struct tty_struct *tty, | 590 | static void cp210x_set_termios(struct tty_struct *tty, |
572 | struct usb_serial_port *port, struct ktermios *old_termios) | 591 | struct usb_serial_port *port, struct ktermios *old_termios) |
573 | { | 592 | { |
574 | unsigned int cflag, old_cflag; | 593 | unsigned int cflag, old_cflag; |
@@ -583,13 +602,13 @@ static void cp2101_set_termios(struct tty_struct *tty, | |||
583 | tty->termios->c_cflag &= ~CMSPAR; | 602 | tty->termios->c_cflag &= ~CMSPAR; |
584 | cflag = tty->termios->c_cflag; | 603 | cflag = tty->termios->c_cflag; |
585 | old_cflag = old_termios->c_cflag; | 604 | old_cflag = old_termios->c_cflag; |
586 | baud = cp2101_quantise_baudrate(tty_get_baud_rate(tty)); | 605 | baud = cp210x_quantise_baudrate(tty_get_baud_rate(tty)); |
587 | 606 | ||
588 | /* If the baud rate is to be updated*/ | 607 | /* If the baud rate is to be updated*/ |
589 | if (baud != tty_termios_baud_rate(old_termios) && baud != 0) { | 608 | if (baud != tty_termios_baud_rate(old_termios) && baud != 0) { |
590 | dbg("%s - Setting baud rate to %d baud", __func__, | 609 | dbg("%s - Setting baud rate to %d baud", __func__, |
591 | baud); | 610 | baud); |
592 | if (cp2101_set_config_single(port, CP2101_BAUDRATE, | 611 | if (cp210x_set_config_single(port, CP210X_SET_BAUDDIV, |
593 | ((BAUD_RATE_GEN_FREQ + baud/2) / baud))) { | 612 | ((BAUD_RATE_GEN_FREQ + baud/2) / baud))) { |
594 | dbg("Baud rate requested not supported by device\n"); | 613 | dbg("Baud rate requested not supported by device\n"); |
595 | baud = tty_termios_baud_rate(old_termios); | 614 | baud = tty_termios_baud_rate(old_termios); |
@@ -600,7 +619,7 @@ static void cp2101_set_termios(struct tty_struct *tty, | |||
600 | 619 | ||
601 | /* If the number of data bits is to be updated */ | 620 | /* If the number of data bits is to be updated */ |
602 | if ((cflag & CSIZE) != (old_cflag & CSIZE)) { | 621 | if ((cflag & CSIZE) != (old_cflag & CSIZE)) { |
603 | cp2101_get_config(port, CP2101_BITS, &bits, 2); | 622 | cp210x_get_config(port, CP210X_GET_LINE_CTL, &bits, 2); |
604 | bits &= ~BITS_DATA_MASK; | 623 | bits &= ~BITS_DATA_MASK; |
605 | switch (cflag & CSIZE) { | 624 | switch (cflag & CSIZE) { |
606 | case CS5: | 625 | case CS5: |
@@ -624,19 +643,19 @@ static void cp2101_set_termios(struct tty_struct *tty, | |||
624 | dbg("%s - data bits = 9", __func__); | 643 | dbg("%s - data bits = 9", __func__); |
625 | break;*/ | 644 | break;*/ |
626 | default: | 645 | default: |
627 | dbg("cp2101 driver does not " | 646 | dbg("cp210x driver does not " |
628 | "support the number of bits requested," | 647 | "support the number of bits requested," |
629 | " using 8 bit mode\n"); | 648 | " using 8 bit mode\n"); |
630 | bits |= BITS_DATA_8; | 649 | bits |= BITS_DATA_8; |
631 | break; | 650 | break; |
632 | } | 651 | } |
633 | if (cp2101_set_config(port, CP2101_BITS, &bits, 2)) | 652 | if (cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2)) |
634 | dbg("Number of data bits requested " | 653 | dbg("Number of data bits requested " |
635 | "not supported by device\n"); | 654 | "not supported by device\n"); |
636 | } | 655 | } |
637 | 656 | ||
638 | if ((cflag & (PARENB|PARODD)) != (old_cflag & (PARENB|PARODD))) { | 657 | if ((cflag & (PARENB|PARODD)) != (old_cflag & (PARENB|PARODD))) { |
639 | cp2101_get_config(port, CP2101_BITS, &bits, 2); | 658 | cp210x_get_config(port, CP210X_GET_LINE_CTL, &bits, 2); |
640 | bits &= ~BITS_PARITY_MASK; | 659 | bits &= ~BITS_PARITY_MASK; |
641 | if (cflag & PARENB) { | 660 | if (cflag & PARENB) { |
642 | if (cflag & PARODD) { | 661 | if (cflag & PARODD) { |
@@ -647,13 +666,13 @@ static void cp2101_set_termios(struct tty_struct *tty, | |||
647 | dbg("%s - parity = EVEN", __func__); | 666 | dbg("%s - parity = EVEN", __func__); |
648 | } | 667 | } |
649 | } | 668 | } |
650 | if (cp2101_set_config(port, CP2101_BITS, &bits, 2)) | 669 | if (cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2)) |
651 | dbg("Parity mode not supported " | 670 | dbg("Parity mode not supported " |
652 | "by device\n"); | 671 | "by device\n"); |
653 | } | 672 | } |
654 | 673 | ||
655 | if ((cflag & CSTOPB) != (old_cflag & CSTOPB)) { | 674 | if ((cflag & CSTOPB) != (old_cflag & CSTOPB)) { |
656 | cp2101_get_config(port, CP2101_BITS, &bits, 2); | 675 | cp210x_get_config(port, CP210X_GET_LINE_CTL, &bits, 2); |
657 | bits &= ~BITS_STOP_MASK; | 676 | bits &= ~BITS_STOP_MASK; |
658 | if (cflag & CSTOPB) { | 677 | if (cflag & CSTOPB) { |
659 | bits |= BITS_STOP_2; | 678 | bits |= BITS_STOP_2; |
@@ -662,13 +681,13 @@ static void cp2101_set_termios(struct tty_struct *tty, | |||
662 | bits |= BITS_STOP_1; | 681 | bits |= BITS_STOP_1; |
663 | dbg("%s - stop bits = 1", __func__); | 682 | dbg("%s - stop bits = 1", __func__); |
664 | } | 683 | } |
665 | if (cp2101_set_config(port, CP2101_BITS, &bits, 2)) | 684 | if (cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2)) |
666 | dbg("Number of stop bits requested " | 685 | dbg("Number of stop bits requested " |
667 | "not supported by device\n"); | 686 | "not supported by device\n"); |
668 | } | 687 | } |
669 | 688 | ||
670 | if ((cflag & CRTSCTS) != (old_cflag & CRTSCTS)) { | 689 | if ((cflag & CRTSCTS) != (old_cflag & CRTSCTS)) { |
671 | cp2101_get_config(port, CP2101_MODEMCTL, modem_ctl, 16); | 690 | cp210x_get_config(port, CP210X_GET_FLOW, modem_ctl, 16); |
672 | dbg("%s - read modem controls = 0x%.4x 0x%.4x 0x%.4x 0x%.4x", | 691 | dbg("%s - read modem controls = 0x%.4x 0x%.4x 0x%.4x 0x%.4x", |
673 | __func__, modem_ctl[0], modem_ctl[1], | 692 | __func__, modem_ctl[0], modem_ctl[1], |
674 | modem_ctl[2], modem_ctl[3]); | 693 | modem_ctl[2], modem_ctl[3]); |
@@ -688,19 +707,19 @@ static void cp2101_set_termios(struct tty_struct *tty, | |||
688 | dbg("%s - write modem controls = 0x%.4x 0x%.4x 0x%.4x 0x%.4x", | 707 | dbg("%s - write modem controls = 0x%.4x 0x%.4x 0x%.4x 0x%.4x", |
689 | __func__, modem_ctl[0], modem_ctl[1], | 708 | __func__, modem_ctl[0], modem_ctl[1], |
690 | modem_ctl[2], modem_ctl[3]); | 709 | modem_ctl[2], modem_ctl[3]); |
691 | cp2101_set_config(port, CP2101_MODEMCTL, modem_ctl, 16); | 710 | cp210x_set_config(port, CP210X_SET_FLOW, modem_ctl, 16); |
692 | } | 711 | } |
693 | 712 | ||
694 | } | 713 | } |
695 | 714 | ||
696 | static int cp2101_tiocmset (struct tty_struct *tty, struct file *file, | 715 | static int cp210x_tiocmset (struct tty_struct *tty, struct file *file, |
697 | unsigned int set, unsigned int clear) | 716 | unsigned int set, unsigned int clear) |
698 | { | 717 | { |
699 | struct usb_serial_port *port = tty->driver_data; | 718 | struct usb_serial_port *port = tty->driver_data; |
700 | return cp2101_tiocmset_port(port, file, set, clear); | 719 | return cp210x_tiocmset_port(port, file, set, clear); |
701 | } | 720 | } |
702 | 721 | ||
703 | static int cp2101_tiocmset_port(struct usb_serial_port *port, struct file *file, | 722 | static int cp210x_tiocmset_port(struct usb_serial_port *port, struct file *file, |
704 | unsigned int set, unsigned int clear) | 723 | unsigned int set, unsigned int clear) |
705 | { | 724 | { |
706 | unsigned int control = 0; | 725 | unsigned int control = 0; |
@@ -726,10 +745,10 @@ static int cp2101_tiocmset_port(struct usb_serial_port *port, struct file *file, | |||
726 | 745 | ||
727 | dbg("%s - control = 0x%.4x", __func__, control); | 746 | dbg("%s - control = 0x%.4x", __func__, control); |
728 | 747 | ||
729 | return cp2101_set_config(port, CP2101_CONTROL, &control, 2); | 748 | return cp210x_set_config(port, CP210X_SET_MHS, &control, 2); |
730 | } | 749 | } |
731 | 750 | ||
732 | static int cp2101_tiocmget (struct tty_struct *tty, struct file *file) | 751 | static int cp210x_tiocmget (struct tty_struct *tty, struct file *file) |
733 | { | 752 | { |
734 | struct usb_serial_port *port = tty->driver_data; | 753 | struct usb_serial_port *port = tty->driver_data; |
735 | unsigned int control; | 754 | unsigned int control; |
@@ -737,7 +756,7 @@ static int cp2101_tiocmget (struct tty_struct *tty, struct file *file) | |||
737 | 756 | ||
738 | dbg("%s - port %d", __func__, port->number); | 757 | dbg("%s - port %d", __func__, port->number); |
739 | 758 | ||
740 | cp2101_get_config(port, CP2101_CONTROL, &control, 1); | 759 | cp210x_get_config(port, CP210X_GET_MDMSTS, &control, 1); |
741 | 760 | ||
742 | result = ((control & CONTROL_DTR) ? TIOCM_DTR : 0) | 761 | result = ((control & CONTROL_DTR) ? TIOCM_DTR : 0) |
743 | |((control & CONTROL_RTS) ? TIOCM_RTS : 0) | 762 | |((control & CONTROL_RTS) ? TIOCM_RTS : 0) |
@@ -751,7 +770,7 @@ static int cp2101_tiocmget (struct tty_struct *tty, struct file *file) | |||
751 | return result; | 770 | return result; |
752 | } | 771 | } |
753 | 772 | ||
754 | static void cp2101_break_ctl (struct tty_struct *tty, int break_state) | 773 | static void cp210x_break_ctl (struct tty_struct *tty, int break_state) |
755 | { | 774 | { |
756 | struct usb_serial_port *port = tty->driver_data; | 775 | struct usb_serial_port *port = tty->driver_data; |
757 | unsigned int state; | 776 | unsigned int state; |
@@ -763,17 +782,17 @@ static void cp2101_break_ctl (struct tty_struct *tty, int break_state) | |||
763 | state = BREAK_ON; | 782 | state = BREAK_ON; |
764 | dbg("%s - turning break %s", __func__, | 783 | dbg("%s - turning break %s", __func__, |
765 | state == BREAK_OFF ? "off" : "on"); | 784 | state == BREAK_OFF ? "off" : "on"); |
766 | cp2101_set_config(port, CP2101_BREAK, &state, 2); | 785 | cp210x_set_config(port, CP210X_SET_BREAK, &state, 2); |
767 | } | 786 | } |
768 | 787 | ||
769 | static int cp2101_startup(struct usb_serial *serial) | 788 | static int cp210x_startup(struct usb_serial *serial) |
770 | { | 789 | { |
771 | /* CP2101 buffers behave strangely unless device is reset */ | 790 | /* cp210x buffers behave strangely unless device is reset */ |
772 | usb_reset_device(serial->dev); | 791 | usb_reset_device(serial->dev); |
773 | return 0; | 792 | return 0; |
774 | } | 793 | } |
775 | 794 | ||
776 | static void cp2101_shutdown(struct usb_serial *serial) | 795 | static void cp210x_shutdown(struct usb_serial *serial) |
777 | { | 796 | { |
778 | int i; | 797 | int i; |
779 | 798 | ||
@@ -781,21 +800,21 @@ static void cp2101_shutdown(struct usb_serial *serial) | |||
781 | 800 | ||
782 | /* Stop reads and writes on all ports */ | 801 | /* Stop reads and writes on all ports */ |
783 | for (i = 0; i < serial->num_ports; ++i) | 802 | for (i = 0; i < serial->num_ports; ++i) |
784 | cp2101_cleanup(serial->port[i]); | 803 | cp210x_cleanup(serial->port[i]); |
785 | } | 804 | } |
786 | 805 | ||
787 | static int __init cp2101_init(void) | 806 | static int __init cp210x_init(void) |
788 | { | 807 | { |
789 | int retval; | 808 | int retval; |
790 | 809 | ||
791 | retval = usb_serial_register(&cp2101_device); | 810 | retval = usb_serial_register(&cp210x_device); |
792 | if (retval) | 811 | if (retval) |
793 | return retval; /* Failed to register */ | 812 | return retval; /* Failed to register */ |
794 | 813 | ||
795 | retval = usb_register(&cp2101_driver); | 814 | retval = usb_register(&cp210x_driver); |
796 | if (retval) { | 815 | if (retval) { |
797 | /* Failed to register */ | 816 | /* Failed to register */ |
798 | usb_serial_deregister(&cp2101_device); | 817 | usb_serial_deregister(&cp210x_device); |
799 | return retval; | 818 | return retval; |
800 | } | 819 | } |
801 | 820 | ||
@@ -805,14 +824,14 @@ static int __init cp2101_init(void) | |||
805 | return 0; | 824 | return 0; |
806 | } | 825 | } |
807 | 826 | ||
808 | static void __exit cp2101_exit(void) | 827 | static void __exit cp210x_exit(void) |
809 | { | 828 | { |
810 | usb_deregister(&cp2101_driver); | 829 | usb_deregister(&cp210x_driver); |
811 | usb_serial_deregister(&cp2101_device); | 830 | usb_serial_deregister(&cp210x_device); |
812 | } | 831 | } |
813 | 832 | ||
814 | module_init(cp2101_init); | 833 | module_init(cp210x_init); |
815 | module_exit(cp2101_exit); | 834 | module_exit(cp210x_exit); |
816 | 835 | ||
817 | MODULE_DESCRIPTION(DRIVER_DESC); | 836 | MODULE_DESCRIPTION(DRIVER_DESC); |
818 | MODULE_VERSION(DRIVER_VERSION); | 837 | MODULE_VERSION(DRIVER_VERSION); |
diff --git a/drivers/usb/serial/cyberjack.c b/drivers/usb/serial/cyberjack.c index dd501bb63ed6..933ba913e66c 100644 --- a/drivers/usb/serial/cyberjack.c +++ b/drivers/usb/serial/cyberjack.c | |||
@@ -61,8 +61,7 @@ static int cyberjack_startup(struct usb_serial *serial); | |||
61 | static void cyberjack_shutdown(struct usb_serial *serial); | 61 | static void cyberjack_shutdown(struct usb_serial *serial); |
62 | static int cyberjack_open(struct tty_struct *tty, | 62 | static int cyberjack_open(struct tty_struct *tty, |
63 | struct usb_serial_port *port, struct file *filp); | 63 | struct usb_serial_port *port, struct file *filp); |
64 | static void cyberjack_close(struct tty_struct *tty, | 64 | static void cyberjack_close(struct usb_serial_port *port); |
65 | struct usb_serial_port *port, struct file *filp); | ||
66 | static int cyberjack_write(struct tty_struct *tty, | 65 | static int cyberjack_write(struct tty_struct *tty, |
67 | struct usb_serial_port *port, const unsigned char *buf, int count); | 66 | struct usb_serial_port *port, const unsigned char *buf, int count); |
68 | static int cyberjack_write_room(struct tty_struct *tty); | 67 | static int cyberjack_write_room(struct tty_struct *tty); |
@@ -185,8 +184,7 @@ static int cyberjack_open(struct tty_struct *tty, | |||
185 | return result; | 184 | return result; |
186 | } | 185 | } |
187 | 186 | ||
188 | static void cyberjack_close(struct tty_struct *tty, | 187 | static void cyberjack_close(struct usb_serial_port *port) |
189 | struct usb_serial_port *port, struct file *filp) | ||
190 | { | 188 | { |
191 | dbg("%s - port %d", __func__, port->number); | 189 | dbg("%s - port %d", __func__, port->number); |
192 | 190 | ||
diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c index e568710b263f..669f93848539 100644 --- a/drivers/usb/serial/cypress_m8.c +++ b/drivers/usb/serial/cypress_m8.c | |||
@@ -174,8 +174,8 @@ static int cypress_ca42v2_startup(struct usb_serial *serial); | |||
174 | static void cypress_shutdown(struct usb_serial *serial); | 174 | static void cypress_shutdown(struct usb_serial *serial); |
175 | static int cypress_open(struct tty_struct *tty, | 175 | static int cypress_open(struct tty_struct *tty, |
176 | struct usb_serial_port *port, struct file *filp); | 176 | struct usb_serial_port *port, struct file *filp); |
177 | static void cypress_close(struct tty_struct *tty, | 177 | static void cypress_close(struct usb_serial_port *port); |
178 | struct usb_serial_port *port, struct file *filp); | 178 | static void cypress_dtr_rts(struct usb_serial_port *port, int on); |
179 | static int cypress_write(struct tty_struct *tty, struct usb_serial_port *port, | 179 | static int cypress_write(struct tty_struct *tty, struct usb_serial_port *port, |
180 | const unsigned char *buf, int count); | 180 | const unsigned char *buf, int count); |
181 | static void cypress_send(struct usb_serial_port *port); | 181 | static void cypress_send(struct usb_serial_port *port); |
@@ -218,6 +218,7 @@ static struct usb_serial_driver cypress_earthmate_device = { | |||
218 | .shutdown = cypress_shutdown, | 218 | .shutdown = cypress_shutdown, |
219 | .open = cypress_open, | 219 | .open = cypress_open, |
220 | .close = cypress_close, | 220 | .close = cypress_close, |
221 | .dtr_rts = cypress_dtr_rts, | ||
221 | .write = cypress_write, | 222 | .write = cypress_write, |
222 | .write_room = cypress_write_room, | 223 | .write_room = cypress_write_room, |
223 | .ioctl = cypress_ioctl, | 224 | .ioctl = cypress_ioctl, |
@@ -244,6 +245,7 @@ static struct usb_serial_driver cypress_hidcom_device = { | |||
244 | .shutdown = cypress_shutdown, | 245 | .shutdown = cypress_shutdown, |
245 | .open = cypress_open, | 246 | .open = cypress_open, |
246 | .close = cypress_close, | 247 | .close = cypress_close, |
248 | .dtr_rts = cypress_dtr_rts, | ||
247 | .write = cypress_write, | 249 | .write = cypress_write, |
248 | .write_room = cypress_write_room, | 250 | .write_room = cypress_write_room, |
249 | .ioctl = cypress_ioctl, | 251 | .ioctl = cypress_ioctl, |
@@ -270,6 +272,7 @@ static struct usb_serial_driver cypress_ca42v2_device = { | |||
270 | .shutdown = cypress_shutdown, | 272 | .shutdown = cypress_shutdown, |
271 | .open = cypress_open, | 273 | .open = cypress_open, |
272 | .close = cypress_close, | 274 | .close = cypress_close, |
275 | .dtr_rts = cypress_dtr_rts, | ||
273 | .write = cypress_write, | 276 | .write = cypress_write, |
274 | .write_room = cypress_write_room, | 277 | .write_room = cypress_write_room, |
275 | .ioctl = cypress_ioctl, | 278 | .ioctl = cypress_ioctl, |
@@ -656,11 +659,7 @@ static int cypress_open(struct tty_struct *tty, | |||
656 | priv->rx_flags = 0; | 659 | priv->rx_flags = 0; |
657 | spin_unlock_irqrestore(&priv->lock, flags); | 660 | spin_unlock_irqrestore(&priv->lock, flags); |
658 | 661 | ||
659 | /* raise both lines and set termios */ | 662 | /* Set termios */ |
660 | spin_lock_irqsave(&priv->lock, flags); | ||
661 | priv->line_control = CONTROL_DTR | CONTROL_RTS; | ||
662 | priv->cmd_ctrl = 1; | ||
663 | spin_unlock_irqrestore(&priv->lock, flags); | ||
664 | result = cypress_write(tty, port, NULL, 0); | 663 | result = cypress_write(tty, port, NULL, 0); |
665 | 664 | ||
666 | if (result) { | 665 | if (result) { |
@@ -694,76 +693,42 @@ static int cypress_open(struct tty_struct *tty, | |||
694 | __func__, result); | 693 | __func__, result); |
695 | cypress_set_dead(port); | 694 | cypress_set_dead(port); |
696 | } | 695 | } |
697 | 696 | port->port.drain_delay = 256; | |
698 | return result; | 697 | return result; |
699 | } /* cypress_open */ | 698 | } /* cypress_open */ |
700 | 699 | ||
700 | static void cypress_dtr_rts(struct usb_serial_port *port, int on) | ||
701 | { | ||
702 | struct cypress_private *priv = usb_get_serial_port_data(port); | ||
703 | /* drop dtr and rts */ | ||
704 | priv = usb_get_serial_port_data(port); | ||
705 | spin_lock_irq(&priv->lock); | ||
706 | if (on == 0) | ||
707 | priv->line_control = 0; | ||
708 | else | ||
709 | priv->line_control = CONTROL_DTR | CONTROL_RTS; | ||
710 | priv->cmd_ctrl = 1; | ||
711 | spin_unlock_irq(&priv->lock); | ||
712 | cypress_write(NULL, port, NULL, 0); | ||
713 | } | ||
701 | 714 | ||
702 | static void cypress_close(struct tty_struct *tty, | 715 | static void cypress_close(struct usb_serial_port *port) |
703 | struct usb_serial_port *port, struct file *filp) | ||
704 | { | 716 | { |
705 | struct cypress_private *priv = usb_get_serial_port_data(port); | 717 | struct cypress_private *priv = usb_get_serial_port_data(port); |
706 | unsigned int c_cflag; | ||
707 | int bps; | ||
708 | long timeout; | ||
709 | wait_queue_t wait; | ||
710 | 718 | ||
711 | dbg("%s - port %d", __func__, port->number); | 719 | dbg("%s - port %d", __func__, port->number); |
712 | 720 | ||
713 | /* wait for data to drain from buffer */ | ||
714 | spin_lock_irq(&priv->lock); | ||
715 | timeout = CYPRESS_CLOSING_WAIT; | ||
716 | init_waitqueue_entry(&wait, current); | ||
717 | add_wait_queue(&tty->write_wait, &wait); | ||
718 | for (;;) { | ||
719 | set_current_state(TASK_INTERRUPTIBLE); | ||
720 | if (cypress_buf_data_avail(priv->buf) == 0 | ||
721 | || timeout == 0 || signal_pending(current) | ||
722 | /* without mutex, allowed due to harmless failure mode */ | ||
723 | || port->serial->disconnected) | ||
724 | break; | ||
725 | spin_unlock_irq(&priv->lock); | ||
726 | timeout = schedule_timeout(timeout); | ||
727 | spin_lock_irq(&priv->lock); | ||
728 | } | ||
729 | set_current_state(TASK_RUNNING); | ||
730 | remove_wait_queue(&tty->write_wait, &wait); | ||
731 | /* clear out any remaining data in the buffer */ | ||
732 | cypress_buf_clear(priv->buf); | ||
733 | spin_unlock_irq(&priv->lock); | ||
734 | |||
735 | /* writing is potentially harmful, lock must be taken */ | 721 | /* writing is potentially harmful, lock must be taken */ |
736 | mutex_lock(&port->serial->disc_mutex); | 722 | mutex_lock(&port->serial->disc_mutex); |
737 | if (port->serial->disconnected) { | 723 | if (port->serial->disconnected) { |
738 | mutex_unlock(&port->serial->disc_mutex); | 724 | mutex_unlock(&port->serial->disc_mutex); |
739 | return; | 725 | return; |
740 | } | 726 | } |
741 | /* wait for characters to drain from device */ | 727 | cypress_buf_clear(priv->buf); |
742 | if (tty) { | ||
743 | bps = tty_get_baud_rate(tty); | ||
744 | if (bps > 1200) | ||
745 | timeout = max((HZ * 2560) / bps, HZ / 10); | ||
746 | else | ||
747 | timeout = 2 * HZ; | ||
748 | schedule_timeout_interruptible(timeout); | ||
749 | } | ||
750 | |||
751 | dbg("%s - stopping urbs", __func__); | 728 | dbg("%s - stopping urbs", __func__); |
752 | usb_kill_urb(port->interrupt_in_urb); | 729 | usb_kill_urb(port->interrupt_in_urb); |
753 | usb_kill_urb(port->interrupt_out_urb); | 730 | usb_kill_urb(port->interrupt_out_urb); |
754 | 731 | ||
755 | if (tty) { | ||
756 | c_cflag = tty->termios->c_cflag; | ||
757 | if (c_cflag & HUPCL) { | ||
758 | /* drop dtr and rts */ | ||
759 | priv = usb_get_serial_port_data(port); | ||
760 | spin_lock_irq(&priv->lock); | ||
761 | priv->line_control = 0; | ||
762 | priv->cmd_ctrl = 1; | ||
763 | spin_unlock_irq(&priv->lock); | ||
764 | cypress_write(tty, port, NULL, 0); | ||
765 | } | ||
766 | } | ||
767 | 732 | ||
768 | if (stats) | 733 | if (stats) |
769 | dev_info(&port->dev, "Statistics: %d Bytes In | %d Bytes Out | %d Commands Issued\n", | 734 | dev_info(&port->dev, "Statistics: %d Bytes In | %d Bytes Out | %d Commands Issued\n", |
diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c index 38ba4ea8b6bf..30f5140eff03 100644 --- a/drivers/usb/serial/digi_acceleport.c +++ b/drivers/usb/serial/digi_acceleport.c | |||
@@ -422,7 +422,6 @@ struct digi_port { | |||
422 | int dp_throttled; | 422 | int dp_throttled; |
423 | int dp_throttle_restart; | 423 | int dp_throttle_restart; |
424 | wait_queue_head_t dp_flush_wait; | 424 | wait_queue_head_t dp_flush_wait; |
425 | int dp_in_close; /* close in progress */ | ||
426 | wait_queue_head_t dp_close_wait; /* wait queue for close */ | 425 | wait_queue_head_t dp_close_wait; /* wait queue for close */ |
427 | struct work_struct dp_wakeup_work; | 426 | struct work_struct dp_wakeup_work; |
428 | struct usb_serial_port *dp_port; | 427 | struct usb_serial_port *dp_port; |
@@ -456,8 +455,9 @@ static int digi_write_room(struct tty_struct *tty); | |||
456 | static int digi_chars_in_buffer(struct tty_struct *tty); | 455 | static int digi_chars_in_buffer(struct tty_struct *tty); |
457 | static int digi_open(struct tty_struct *tty, struct usb_serial_port *port, | 456 | static int digi_open(struct tty_struct *tty, struct usb_serial_port *port, |
458 | struct file *filp); | 457 | struct file *filp); |
459 | static void digi_close(struct tty_struct *tty, struct usb_serial_port *port, | 458 | static void digi_close(struct usb_serial_port *port); |
460 | struct file *filp); | 459 | static int digi_carrier_raised(struct usb_serial_port *port); |
460 | static void digi_dtr_rts(struct usb_serial_port *port, int on); | ||
461 | static int digi_startup_device(struct usb_serial *serial); | 461 | static int digi_startup_device(struct usb_serial *serial); |
462 | static int digi_startup(struct usb_serial *serial); | 462 | static int digi_startup(struct usb_serial *serial); |
463 | static void digi_shutdown(struct usb_serial *serial); | 463 | static void digi_shutdown(struct usb_serial *serial); |
@@ -510,6 +510,8 @@ static struct usb_serial_driver digi_acceleport_2_device = { | |||
510 | .num_ports = 3, | 510 | .num_ports = 3, |
511 | .open = digi_open, | 511 | .open = digi_open, |
512 | .close = digi_close, | 512 | .close = digi_close, |
513 | .dtr_rts = digi_dtr_rts, | ||
514 | .carrier_raised = digi_carrier_raised, | ||
513 | .write = digi_write, | 515 | .write = digi_write, |
514 | .write_room = digi_write_room, | 516 | .write_room = digi_write_room, |
515 | .write_bulk_callback = digi_write_bulk_callback, | 517 | .write_bulk_callback = digi_write_bulk_callback, |
@@ -1328,6 +1330,19 @@ static int digi_chars_in_buffer(struct tty_struct *tty) | |||
1328 | 1330 | ||
1329 | } | 1331 | } |
1330 | 1332 | ||
1333 | static void digi_dtr_rts(struct usb_serial_port *port, int on) | ||
1334 | { | ||
1335 | /* Adjust DTR and RTS */ | ||
1336 | digi_set_modem_signals(port, on * (TIOCM_DTR|TIOCM_RTS), 1); | ||
1337 | } | ||
1338 | |||
1339 | static int digi_carrier_raised(struct usb_serial_port *port) | ||
1340 | { | ||
1341 | struct digi_port *priv = usb_get_serial_port_data(port); | ||
1342 | if (priv->dp_modem_signals & TIOCM_CD) | ||
1343 | return 1; | ||
1344 | return 0; | ||
1345 | } | ||
1331 | 1346 | ||
1332 | static int digi_open(struct tty_struct *tty, struct usb_serial_port *port, | 1347 | static int digi_open(struct tty_struct *tty, struct usb_serial_port *port, |
1333 | struct file *filp) | 1348 | struct file *filp) |
@@ -1336,7 +1351,6 @@ static int digi_open(struct tty_struct *tty, struct usb_serial_port *port, | |||
1336 | unsigned char buf[32]; | 1351 | unsigned char buf[32]; |
1337 | struct digi_port *priv = usb_get_serial_port_data(port); | 1352 | struct digi_port *priv = usb_get_serial_port_data(port); |
1338 | struct ktermios not_termios; | 1353 | struct ktermios not_termios; |
1339 | unsigned long flags = 0; | ||
1340 | 1354 | ||
1341 | dbg("digi_open: TOP: port=%d, open_count=%d", | 1355 | dbg("digi_open: TOP: port=%d, open_count=%d", |
1342 | priv->dp_port_num, port->port.count); | 1356 | priv->dp_port_num, port->port.count); |
@@ -1345,26 +1359,6 @@ static int digi_open(struct tty_struct *tty, struct usb_serial_port *port, | |||
1345 | if (digi_startup_device(port->serial) != 0) | 1359 | if (digi_startup_device(port->serial) != 0) |
1346 | return -ENXIO; | 1360 | return -ENXIO; |
1347 | 1361 | ||
1348 | spin_lock_irqsave(&priv->dp_port_lock, flags); | ||
1349 | |||
1350 | /* don't wait on a close in progress for non-blocking opens */ | ||
1351 | if (priv->dp_in_close && (filp->f_flags&(O_NDELAY|O_NONBLOCK)) == 0) { | ||
1352 | spin_unlock_irqrestore(&priv->dp_port_lock, flags); | ||
1353 | return -EAGAIN; | ||
1354 | } | ||
1355 | |||
1356 | /* wait for a close in progress to finish */ | ||
1357 | while (priv->dp_in_close) { | ||
1358 | cond_wait_interruptible_timeout_irqrestore( | ||
1359 | &priv->dp_close_wait, DIGI_RETRY_TIMEOUT, | ||
1360 | &priv->dp_port_lock, flags); | ||
1361 | if (signal_pending(current)) | ||
1362 | return -EINTR; | ||
1363 | spin_lock_irqsave(&priv->dp_port_lock, flags); | ||
1364 | } | ||
1365 | |||
1366 | spin_unlock_irqrestore(&priv->dp_port_lock, flags); | ||
1367 | |||
1368 | /* read modem signals automatically whenever they change */ | 1362 | /* read modem signals automatically whenever they change */ |
1369 | buf[0] = DIGI_CMD_READ_INPUT_SIGNALS; | 1363 | buf[0] = DIGI_CMD_READ_INPUT_SIGNALS; |
1370 | buf[1] = priv->dp_port_num; | 1364 | buf[1] = priv->dp_port_num; |
@@ -1387,16 +1381,11 @@ static int digi_open(struct tty_struct *tty, struct usb_serial_port *port, | |||
1387 | not_termios.c_iflag = ~tty->termios->c_iflag; | 1381 | not_termios.c_iflag = ~tty->termios->c_iflag; |
1388 | digi_set_termios(tty, port, ¬_termios); | 1382 | digi_set_termios(tty, port, ¬_termios); |
1389 | } | 1383 | } |
1390 | |||
1391 | /* set DTR and RTS */ | ||
1392 | digi_set_modem_signals(port, TIOCM_DTR|TIOCM_RTS, 1); | ||
1393 | |||
1394 | return 0; | 1384 | return 0; |
1395 | } | 1385 | } |
1396 | 1386 | ||
1397 | 1387 | ||
1398 | static void digi_close(struct tty_struct *tty, struct usb_serial_port *port, | 1388 | static void digi_close(struct usb_serial_port *port) |
1399 | struct file *filp) | ||
1400 | { | 1389 | { |
1401 | DEFINE_WAIT(wait); | 1390 | DEFINE_WAIT(wait); |
1402 | int ret; | 1391 | int ret; |
@@ -1411,28 +1400,9 @@ static void digi_close(struct tty_struct *tty, struct usb_serial_port *port, | |||
1411 | if (port->serial->disconnected) | 1400 | if (port->serial->disconnected) |
1412 | goto exit; | 1401 | goto exit; |
1413 | 1402 | ||
1414 | /* do cleanup only after final close on this port */ | ||
1415 | spin_lock_irq(&priv->dp_port_lock); | ||
1416 | priv->dp_in_close = 1; | ||
1417 | spin_unlock_irq(&priv->dp_port_lock); | ||
1418 | |||
1419 | /* tell line discipline to process only XON/XOFF */ | ||
1420 | tty->closing = 1; | ||
1421 | |||
1422 | /* wait for output to drain */ | ||
1423 | if ((filp->f_flags&(O_NDELAY|O_NONBLOCK)) == 0) | ||
1424 | tty_wait_until_sent(tty, DIGI_CLOSE_TIMEOUT); | ||
1425 | |||
1426 | /* flush driver and line discipline buffers */ | ||
1427 | tty_driver_flush_buffer(tty); | ||
1428 | tty_ldisc_flush(tty); | ||
1429 | |||
1430 | if (port->serial->dev) { | 1403 | if (port->serial->dev) { |
1431 | /* wait for transmit idle */ | 1404 | /* FIXME: Transmit idle belongs in the wait_unti_sent path */ |
1432 | if ((filp->f_flags&(O_NDELAY|O_NONBLOCK)) == 0) | 1405 | digi_transmit_idle(port, DIGI_CLOSE_TIMEOUT); |
1433 | digi_transmit_idle(port, DIGI_CLOSE_TIMEOUT); | ||
1434 | /* drop DTR and RTS */ | ||
1435 | digi_set_modem_signals(port, 0, 0); | ||
1436 | 1406 | ||
1437 | /* disable input flow control */ | 1407 | /* disable input flow control */ |
1438 | buf[0] = DIGI_CMD_SET_INPUT_FLOW_CONTROL; | 1408 | buf[0] = DIGI_CMD_SET_INPUT_FLOW_CONTROL; |
@@ -1477,11 +1447,9 @@ static void digi_close(struct tty_struct *tty, struct usb_serial_port *port, | |||
1477 | /* shutdown any outstanding bulk writes */ | 1447 | /* shutdown any outstanding bulk writes */ |
1478 | usb_kill_urb(port->write_urb); | 1448 | usb_kill_urb(port->write_urb); |
1479 | } | 1449 | } |
1480 | tty->closing = 0; | ||
1481 | exit: | 1450 | exit: |
1482 | spin_lock_irq(&priv->dp_port_lock); | 1451 | spin_lock_irq(&priv->dp_port_lock); |
1483 | priv->dp_write_urb_in_use = 0; | 1452 | priv->dp_write_urb_in_use = 0; |
1484 | priv->dp_in_close = 0; | ||
1485 | wake_up_interruptible(&priv->dp_close_wait); | 1453 | wake_up_interruptible(&priv->dp_close_wait); |
1486 | spin_unlock_irq(&priv->dp_port_lock); | 1454 | spin_unlock_irq(&priv->dp_port_lock); |
1487 | mutex_unlock(&port->serial->disc_mutex); | 1455 | mutex_unlock(&port->serial->disc_mutex); |
@@ -1560,7 +1528,6 @@ static int digi_startup(struct usb_serial *serial) | |||
1560 | priv->dp_throttled = 0; | 1528 | priv->dp_throttled = 0; |
1561 | priv->dp_throttle_restart = 0; | 1529 | priv->dp_throttle_restart = 0; |
1562 | init_waitqueue_head(&priv->dp_flush_wait); | 1530 | init_waitqueue_head(&priv->dp_flush_wait); |
1563 | priv->dp_in_close = 0; | ||
1564 | init_waitqueue_head(&priv->dp_close_wait); | 1531 | init_waitqueue_head(&priv->dp_close_wait); |
1565 | INIT_WORK(&priv->dp_wakeup_work, digi_wakeup_write_lock); | 1532 | INIT_WORK(&priv->dp_wakeup_work, digi_wakeup_write_lock); |
1566 | priv->dp_port = serial->port[i]; | 1533 | priv->dp_port = serial->port[i]; |
diff --git a/drivers/usb/serial/empeg.c b/drivers/usb/serial/empeg.c index c709ec474a80..2b141ccb0cd9 100644 --- a/drivers/usb/serial/empeg.c +++ b/drivers/usb/serial/empeg.c | |||
@@ -81,8 +81,7 @@ static int debug; | |||
81 | /* function prototypes for an empeg-car player */ | 81 | /* function prototypes for an empeg-car player */ |
82 | static int empeg_open(struct tty_struct *tty, struct usb_serial_port *port, | 82 | static int empeg_open(struct tty_struct *tty, struct usb_serial_port *port, |
83 | struct file *filp); | 83 | struct file *filp); |
84 | static void empeg_close(struct tty_struct *tty, struct usb_serial_port *port, | 84 | static void empeg_close(struct usb_serial_port *port); |
85 | struct file *filp); | ||
86 | static int empeg_write(struct tty_struct *tty, struct usb_serial_port *port, | 85 | static int empeg_write(struct tty_struct *tty, struct usb_serial_port *port, |
87 | const unsigned char *buf, | 86 | const unsigned char *buf, |
88 | int count); | 87 | int count); |
@@ -181,8 +180,7 @@ static int empeg_open(struct tty_struct *tty, struct usb_serial_port *port, | |||
181 | } | 180 | } |
182 | 181 | ||
183 | 182 | ||
184 | static void empeg_close(struct tty_struct *tty, struct usb_serial_port *port, | 183 | static void empeg_close(struct usb_serial_port *port) |
185 | struct file *filp) | ||
186 | { | 184 | { |
187 | dbg("%s - port %d", __func__, port->number); | 185 | dbg("%s - port %d", __func__, port->number); |
188 | 186 | ||
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c index d9fcdaedf389..683304d60615 100644 --- a/drivers/usb/serial/ftdi_sio.c +++ b/drivers/usb/serial/ftdi_sio.c | |||
@@ -89,6 +89,7 @@ struct ftdi_private { | |||
89 | int force_rtscts; /* if non-zero, force RTS-CTS to always | 89 | int force_rtscts; /* if non-zero, force RTS-CTS to always |
90 | be enabled */ | 90 | be enabled */ |
91 | 91 | ||
92 | unsigned int latency; /* latency setting in use */ | ||
92 | spinlock_t tx_lock; /* spinlock for transmit state */ | 93 | spinlock_t tx_lock; /* spinlock for transmit state */ |
93 | unsigned long tx_bytes; | 94 | unsigned long tx_bytes; |
94 | unsigned long tx_outstanding_bytes; | 95 | unsigned long tx_outstanding_bytes; |
@@ -719,8 +720,8 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port); | |||
719 | static int ftdi_sio_port_remove(struct usb_serial_port *port); | 720 | static int ftdi_sio_port_remove(struct usb_serial_port *port); |
720 | static int ftdi_open(struct tty_struct *tty, | 721 | static int ftdi_open(struct tty_struct *tty, |
721 | struct usb_serial_port *port, struct file *filp); | 722 | struct usb_serial_port *port, struct file *filp); |
722 | static void ftdi_close(struct tty_struct *tty, | 723 | static void ftdi_close(struct usb_serial_port *port); |
723 | struct usb_serial_port *port, struct file *filp); | 724 | static void ftdi_dtr_rts(struct usb_serial_port *port, int on); |
724 | static int ftdi_write(struct tty_struct *tty, struct usb_serial_port *port, | 725 | static int ftdi_write(struct tty_struct *tty, struct usb_serial_port *port, |
725 | const unsigned char *buf, int count); | 726 | const unsigned char *buf, int count); |
726 | static int ftdi_write_room(struct tty_struct *tty); | 727 | static int ftdi_write_room(struct tty_struct *tty); |
@@ -758,6 +759,7 @@ static struct usb_serial_driver ftdi_sio_device = { | |||
758 | .port_remove = ftdi_sio_port_remove, | 759 | .port_remove = ftdi_sio_port_remove, |
759 | .open = ftdi_open, | 760 | .open = ftdi_open, |
760 | .close = ftdi_close, | 761 | .close = ftdi_close, |
762 | .dtr_rts = ftdi_dtr_rts, | ||
761 | .throttle = ftdi_throttle, | 763 | .throttle = ftdi_throttle, |
762 | .unthrottle = ftdi_unthrottle, | 764 | .unthrottle = ftdi_unthrottle, |
763 | .write = ftdi_write, | 765 | .write = ftdi_write, |
@@ -1037,7 +1039,54 @@ static int change_speed(struct tty_struct *tty, struct usb_serial_port *port) | |||
1037 | return rv; | 1039 | return rv; |
1038 | } | 1040 | } |
1039 | 1041 | ||
1042 | static int write_latency_timer(struct usb_serial_port *port) | ||
1043 | { | ||
1044 | struct ftdi_private *priv = usb_get_serial_port_data(port); | ||
1045 | struct usb_device *udev = port->serial->dev; | ||
1046 | char buf[1]; | ||
1047 | int rv = 0; | ||
1048 | int l = priv->latency; | ||
1049 | |||
1050 | if (priv->flags & ASYNC_LOW_LATENCY) | ||
1051 | l = 1; | ||
1052 | |||
1053 | dbg("%s: setting latency timer = %i", __func__, l); | ||
1054 | |||
1055 | rv = usb_control_msg(udev, | ||
1056 | usb_sndctrlpipe(udev, 0), | ||
1057 | FTDI_SIO_SET_LATENCY_TIMER_REQUEST, | ||
1058 | FTDI_SIO_SET_LATENCY_TIMER_REQUEST_TYPE, | ||
1059 | l, priv->interface, | ||
1060 | buf, 0, WDR_TIMEOUT); | ||
1061 | |||
1062 | if (rv < 0) | ||
1063 | dev_err(&port->dev, "Unable to write latency timer: %i\n", rv); | ||
1064 | return rv; | ||
1065 | } | ||
1066 | |||
1067 | static int read_latency_timer(struct usb_serial_port *port) | ||
1068 | { | ||
1069 | struct ftdi_private *priv = usb_get_serial_port_data(port); | ||
1070 | struct usb_device *udev = port->serial->dev; | ||
1071 | unsigned short latency = 0; | ||
1072 | int rv = 0; | ||
1073 | |||
1040 | 1074 | ||
1075 | dbg("%s", __func__); | ||
1076 | |||
1077 | rv = usb_control_msg(udev, | ||
1078 | usb_rcvctrlpipe(udev, 0), | ||
1079 | FTDI_SIO_GET_LATENCY_TIMER_REQUEST, | ||
1080 | FTDI_SIO_GET_LATENCY_TIMER_REQUEST_TYPE, | ||
1081 | 0, priv->interface, | ||
1082 | (char *) &latency, 1, WDR_TIMEOUT); | ||
1083 | |||
1084 | if (rv < 0) { | ||
1085 | dev_err(&port->dev, "Unable to read latency timer: %i\n", rv); | ||
1086 | return -EIO; | ||
1087 | } | ||
1088 | return latency; | ||
1089 | } | ||
1041 | 1090 | ||
1042 | static int get_serial_info(struct usb_serial_port *port, | 1091 | static int get_serial_info(struct usb_serial_port *port, |
1043 | struct serial_struct __user *retinfo) | 1092 | struct serial_struct __user *retinfo) |
@@ -1097,6 +1146,7 @@ static int set_serial_info(struct tty_struct *tty, | |||
1097 | priv->custom_divisor = new_serial.custom_divisor; | 1146 | priv->custom_divisor = new_serial.custom_divisor; |
1098 | 1147 | ||
1099 | tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0; | 1148 | tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0; |
1149 | write_latency_timer(port); | ||
1100 | 1150 | ||
1101 | check_and_exit: | 1151 | check_and_exit: |
1102 | if ((old_priv.flags & ASYNC_SPD_MASK) != | 1152 | if ((old_priv.flags & ASYNC_SPD_MASK) != |
@@ -1192,27 +1242,13 @@ static ssize_t show_latency_timer(struct device *dev, | |||
1192 | { | 1242 | { |
1193 | struct usb_serial_port *port = to_usb_serial_port(dev); | 1243 | struct usb_serial_port *port = to_usb_serial_port(dev); |
1194 | struct ftdi_private *priv = usb_get_serial_port_data(port); | 1244 | struct ftdi_private *priv = usb_get_serial_port_data(port); |
1195 | struct usb_device *udev = port->serial->dev; | 1245 | if (priv->flags & ASYNC_LOW_LATENCY) |
1196 | unsigned short latency = 0; | 1246 | return sprintf(buf, "1\n"); |
1197 | int rv = 0; | 1247 | else |
1198 | 1248 | return sprintf(buf, "%i\n", priv->latency); | |
1199 | |||
1200 | dbg("%s", __func__); | ||
1201 | |||
1202 | rv = usb_control_msg(udev, | ||
1203 | usb_rcvctrlpipe(udev, 0), | ||
1204 | FTDI_SIO_GET_LATENCY_TIMER_REQUEST, | ||
1205 | FTDI_SIO_GET_LATENCY_TIMER_REQUEST_TYPE, | ||
1206 | 0, priv->interface, | ||
1207 | (char *) &latency, 1, WDR_TIMEOUT); | ||
1208 | |||
1209 | if (rv < 0) { | ||
1210 | dev_err(dev, "Unable to read latency timer: %i\n", rv); | ||
1211 | return -EIO; | ||
1212 | } | ||
1213 | return sprintf(buf, "%i\n", latency); | ||
1214 | } | 1249 | } |
1215 | 1250 | ||
1251 | |||
1216 | /* Write a new value of the latency timer, in units of milliseconds. */ | 1252 | /* Write a new value of the latency timer, in units of milliseconds. */ |
1217 | static ssize_t store_latency_timer(struct device *dev, | 1253 | static ssize_t store_latency_timer(struct device *dev, |
1218 | struct device_attribute *attr, const char *valbuf, | 1254 | struct device_attribute *attr, const char *valbuf, |
@@ -1220,25 +1256,13 @@ static ssize_t store_latency_timer(struct device *dev, | |||
1220 | { | 1256 | { |
1221 | struct usb_serial_port *port = to_usb_serial_port(dev); | 1257 | struct usb_serial_port *port = to_usb_serial_port(dev); |
1222 | struct ftdi_private *priv = usb_get_serial_port_data(port); | 1258 | struct ftdi_private *priv = usb_get_serial_port_data(port); |
1223 | struct usb_device *udev = port->serial->dev; | ||
1224 | char buf[1]; | ||
1225 | int v = simple_strtoul(valbuf, NULL, 10); | 1259 | int v = simple_strtoul(valbuf, NULL, 10); |
1226 | int rv = 0; | 1260 | int rv = 0; |
1227 | 1261 | ||
1228 | dbg("%s: setting latency timer = %i", __func__, v); | 1262 | priv->latency = v; |
1229 | 1263 | rv = write_latency_timer(port); | |
1230 | rv = usb_control_msg(udev, | 1264 | if (rv < 0) |
1231 | usb_sndctrlpipe(udev, 0), | ||
1232 | FTDI_SIO_SET_LATENCY_TIMER_REQUEST, | ||
1233 | FTDI_SIO_SET_LATENCY_TIMER_REQUEST_TYPE, | ||
1234 | v, priv->interface, | ||
1235 | buf, 0, WDR_TIMEOUT); | ||
1236 | |||
1237 | if (rv < 0) { | ||
1238 | dev_err(dev, "Unable to write latency timer: %i\n", rv); | ||
1239 | return -EIO; | 1265 | return -EIO; |
1240 | } | ||
1241 | |||
1242 | return count; | 1266 | return count; |
1243 | } | 1267 | } |
1244 | 1268 | ||
@@ -1392,6 +1416,7 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port) | |||
1392 | usb_set_serial_port_data(port, priv); | 1416 | usb_set_serial_port_data(port, priv); |
1393 | 1417 | ||
1394 | ftdi_determine_type(port); | 1418 | ftdi_determine_type(port); |
1419 | read_latency_timer(port); | ||
1395 | create_sysfs_attrs(port); | 1420 | create_sysfs_attrs(port); |
1396 | return 0; | 1421 | return 0; |
1397 | } | 1422 | } |
@@ -1514,6 +1539,8 @@ static int ftdi_open(struct tty_struct *tty, | |||
1514 | if (tty) | 1539 | if (tty) |
1515 | tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0; | 1540 | tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0; |
1516 | 1541 | ||
1542 | write_latency_timer(port); | ||
1543 | |||
1517 | /* No error checking for this (will get errors later anyway) */ | 1544 | /* No error checking for this (will get errors later anyway) */ |
1518 | /* See ftdi_sio.h for description of what is reset */ | 1545 | /* See ftdi_sio.h for description of what is reset */ |
1519 | usb_control_msg(dev, usb_sndctrlpipe(dev, 0), | 1546 | usb_control_msg(dev, usb_sndctrlpipe(dev, 0), |
@@ -1529,11 +1556,6 @@ static int ftdi_open(struct tty_struct *tty, | |||
1529 | if (tty) | 1556 | if (tty) |
1530 | ftdi_set_termios(tty, port, tty->termios); | 1557 | ftdi_set_termios(tty, port, tty->termios); |
1531 | 1558 | ||
1532 | /* FIXME: Flow control might be enabled, so it should be checked - | ||
1533 | we have no control of defaults! */ | ||
1534 | /* Turn on RTS and DTR since we are not flow controlling by default */ | ||
1535 | set_mctrl(port, TIOCM_DTR | TIOCM_RTS); | ||
1536 | |||
1537 | /* Not throttled */ | 1559 | /* Not throttled */ |
1538 | spin_lock_irqsave(&priv->rx_lock, flags); | 1560 | spin_lock_irqsave(&priv->rx_lock, flags); |
1539 | priv->rx_flags &= ~(THROTTLED | ACTUALLY_THROTTLED); | 1561 | priv->rx_flags &= ~(THROTTLED | ACTUALLY_THROTTLED); |
@@ -1558,6 +1580,30 @@ static int ftdi_open(struct tty_struct *tty, | |||
1558 | } /* ftdi_open */ | 1580 | } /* ftdi_open */ |
1559 | 1581 | ||
1560 | 1582 | ||
1583 | static void ftdi_dtr_rts(struct usb_serial_port *port, int on) | ||
1584 | { | ||
1585 | struct ftdi_private *priv = usb_get_serial_port_data(port); | ||
1586 | char buf[1]; | ||
1587 | |||
1588 | mutex_lock(&port->serial->disc_mutex); | ||
1589 | if (!port->serial->disconnected) { | ||
1590 | /* Disable flow control */ | ||
1591 | if (!on && usb_control_msg(port->serial->dev, | ||
1592 | usb_sndctrlpipe(port->serial->dev, 0), | ||
1593 | FTDI_SIO_SET_FLOW_CTRL_REQUEST, | ||
1594 | FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE, | ||
1595 | 0, priv->interface, buf, 0, | ||
1596 | WDR_TIMEOUT) < 0) { | ||
1597 | dev_err(&port->dev, "error from flowcontrol urb\n"); | ||
1598 | } | ||
1599 | /* drop RTS and DTR */ | ||
1600 | if (on) | ||
1601 | set_mctrl(port, TIOCM_DTR | TIOCM_RTS); | ||
1602 | else | ||
1603 | clear_mctrl(port, TIOCM_DTR | TIOCM_RTS); | ||
1604 | } | ||
1605 | mutex_unlock(&port->serial->disc_mutex); | ||
1606 | } | ||
1561 | 1607 | ||
1562 | /* | 1608 | /* |
1563 | * usbserial:__serial_close only calls ftdi_close if the point is open | 1609 | * usbserial:__serial_close only calls ftdi_close if the point is open |
@@ -1567,31 +1613,12 @@ static int ftdi_open(struct tty_struct *tty, | |||
1567 | * | 1613 | * |
1568 | */ | 1614 | */ |
1569 | 1615 | ||
1570 | static void ftdi_close(struct tty_struct *tty, | 1616 | static void ftdi_close(struct usb_serial_port *port) |
1571 | struct usb_serial_port *port, struct file *filp) | ||
1572 | { /* ftdi_close */ | 1617 | { /* ftdi_close */ |
1573 | unsigned int c_cflag = tty->termios->c_cflag; | ||
1574 | struct ftdi_private *priv = usb_get_serial_port_data(port); | 1618 | struct ftdi_private *priv = usb_get_serial_port_data(port); |
1575 | char buf[1]; | ||
1576 | 1619 | ||
1577 | dbg("%s", __func__); | 1620 | dbg("%s", __func__); |
1578 | 1621 | ||
1579 | mutex_lock(&port->serial->disc_mutex); | ||
1580 | if (c_cflag & HUPCL && !port->serial->disconnected) { | ||
1581 | /* Disable flow control */ | ||
1582 | if (usb_control_msg(port->serial->dev, | ||
1583 | usb_sndctrlpipe(port->serial->dev, 0), | ||
1584 | FTDI_SIO_SET_FLOW_CTRL_REQUEST, | ||
1585 | FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE, | ||
1586 | 0, priv->interface, buf, 0, | ||
1587 | WDR_TIMEOUT) < 0) { | ||
1588 | dev_err(&port->dev, "error from flowcontrol urb\n"); | ||
1589 | } | ||
1590 | |||
1591 | /* drop RTS and DTR */ | ||
1592 | clear_mctrl(port, TIOCM_DTR | TIOCM_RTS); | ||
1593 | } /* Note change no line if hupcl is off */ | ||
1594 | mutex_unlock(&port->serial->disc_mutex); | ||
1595 | 1622 | ||
1596 | /* cancel any scheduled reading */ | 1623 | /* cancel any scheduled reading */ |
1597 | cancel_delayed_work_sync(&priv->rx_work); | 1624 | cancel_delayed_work_sync(&priv->rx_work); |
diff --git a/drivers/usb/serial/garmin_gps.c b/drivers/usb/serial/garmin_gps.c index 586d30ff450b..ee25a3fe3b09 100644 --- a/drivers/usb/serial/garmin_gps.c +++ b/drivers/usb/serial/garmin_gps.c | |||
@@ -993,8 +993,7 @@ static int garmin_open(struct tty_struct *tty, | |||
993 | } | 993 | } |
994 | 994 | ||
995 | 995 | ||
996 | static void garmin_close(struct tty_struct *tty, | 996 | static void garmin_close(struct usb_serial_port *port) |
997 | struct usb_serial_port *port, struct file *filp) | ||
998 | { | 997 | { |
999 | struct usb_serial *serial = port->serial; | 998 | struct usb_serial *serial = port->serial; |
1000 | struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); | 999 | struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); |
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c index 4cec9906ccf3..be82ea956720 100644 --- a/drivers/usb/serial/generic.c +++ b/drivers/usb/serial/generic.c | |||
@@ -184,8 +184,7 @@ int usb_serial_generic_resume(struct usb_serial *serial) | |||
184 | } | 184 | } |
185 | EXPORT_SYMBOL_GPL(usb_serial_generic_resume); | 185 | EXPORT_SYMBOL_GPL(usb_serial_generic_resume); |
186 | 186 | ||
187 | void usb_serial_generic_close(struct tty_struct *tty, | 187 | void usb_serial_generic_close(struct usb_serial_port *port) |
188 | struct usb_serial_port *port, struct file *filp) | ||
189 | { | 188 | { |
190 | dbg("%s - port %d", __func__, port->number); | 189 | dbg("%s - port %d", __func__, port->number); |
191 | generic_cleanup(port); | 190 | generic_cleanup(port); |
diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c index fb4a73d090f6..53ef5996e33d 100644 --- a/drivers/usb/serial/io_edgeport.c +++ b/drivers/usb/serial/io_edgeport.c | |||
@@ -207,8 +207,7 @@ static void edge_bulk_out_cmd_callback(struct urb *urb); | |||
207 | /* function prototypes for the usbserial callbacks */ | 207 | /* function prototypes for the usbserial callbacks */ |
208 | static int edge_open(struct tty_struct *tty, struct usb_serial_port *port, | 208 | static int edge_open(struct tty_struct *tty, struct usb_serial_port *port, |
209 | struct file *filp); | 209 | struct file *filp); |
210 | static void edge_close(struct tty_struct *tty, struct usb_serial_port *port, | 210 | static void edge_close(struct usb_serial_port *port); |
211 | struct file *filp); | ||
212 | static int edge_write(struct tty_struct *tty, struct usb_serial_port *port, | 211 | static int edge_write(struct tty_struct *tty, struct usb_serial_port *port, |
213 | const unsigned char *buf, int count); | 212 | const unsigned char *buf, int count); |
214 | static int edge_write_room(struct tty_struct *tty); | 213 | static int edge_write_room(struct tty_struct *tty); |
@@ -965,7 +964,7 @@ static int edge_open(struct tty_struct *tty, | |||
965 | 964 | ||
966 | if (!edge_port->txfifo.fifo) { | 965 | if (!edge_port->txfifo.fifo) { |
967 | dbg("%s - no memory", __func__); | 966 | dbg("%s - no memory", __func__); |
968 | edge_close(tty, port, filp); | 967 | edge_close(port); |
969 | return -ENOMEM; | 968 | return -ENOMEM; |
970 | } | 969 | } |
971 | 970 | ||
@@ -975,7 +974,7 @@ static int edge_open(struct tty_struct *tty, | |||
975 | 974 | ||
976 | if (!edge_port->write_urb) { | 975 | if (!edge_port->write_urb) { |
977 | dbg("%s - no memory", __func__); | 976 | dbg("%s - no memory", __func__); |
978 | edge_close(tty, port, filp); | 977 | edge_close(port); |
979 | return -ENOMEM; | 978 | return -ENOMEM; |
980 | } | 979 | } |
981 | 980 | ||
@@ -1099,8 +1098,7 @@ static void block_until_tx_empty(struct edgeport_port *edge_port) | |||
1099 | * edge_close | 1098 | * edge_close |
1100 | * 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 |
1101 | *****************************************************************************/ | 1100 | *****************************************************************************/ |
1102 | static void edge_close(struct tty_struct *tty, | 1101 | static void edge_close(struct usb_serial_port *port) |
1103 | struct usb_serial_port *port, struct file *filp) | ||
1104 | { | 1102 | { |
1105 | struct edgeport_serial *edge_serial; | 1103 | struct edgeport_serial *edge_serial; |
1106 | struct edgeport_port *edge_port; | 1104 | struct edgeport_port *edge_port; |
diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c index 513b25e044c1..eabf20eeb370 100644 --- a/drivers/usb/serial/io_ti.c +++ b/drivers/usb/serial/io_ti.c | |||
@@ -2009,8 +2009,7 @@ release_es_lock: | |||
2009 | return status; | 2009 | return status; |
2010 | } | 2010 | } |
2011 | 2011 | ||
2012 | static void edge_close(struct tty_struct *tty, | 2012 | static void edge_close(struct usb_serial_port *port) |
2013 | struct usb_serial_port *port, struct file *filp) | ||
2014 | { | 2013 | { |
2015 | struct edgeport_serial *edge_serial; | 2014 | struct edgeport_serial *edge_serial; |
2016 | struct edgeport_port *edge_port; | 2015 | struct edgeport_port *edge_port; |
diff --git a/drivers/usb/serial/ipaq.c b/drivers/usb/serial/ipaq.c index cd62825a9ac3..c610a99fa477 100644 --- a/drivers/usb/serial/ipaq.c +++ b/drivers/usb/serial/ipaq.c | |||
@@ -76,8 +76,7 @@ static int initial_wait; | |||
76 | /* Function prototypes for an ipaq */ | 76 | /* Function prototypes for an ipaq */ |
77 | static int ipaq_open(struct tty_struct *tty, | 77 | static int ipaq_open(struct tty_struct *tty, |
78 | struct usb_serial_port *port, struct file *filp); | 78 | struct usb_serial_port *port, struct file *filp); |
79 | static void ipaq_close(struct tty_struct *tty, | 79 | static void ipaq_close(struct usb_serial_port *port); |
80 | struct usb_serial_port *port, struct file *filp); | ||
81 | static int ipaq_calc_num_ports(struct usb_serial *serial); | 80 | static int ipaq_calc_num_ports(struct usb_serial *serial); |
82 | static int ipaq_startup(struct usb_serial *serial); | 81 | static int ipaq_startup(struct usb_serial *serial); |
83 | static void ipaq_shutdown(struct usb_serial *serial); | 82 | static void ipaq_shutdown(struct usb_serial *serial); |
@@ -714,8 +713,7 @@ error: | |||
714 | } | 713 | } |
715 | 714 | ||
716 | 715 | ||
717 | static void ipaq_close(struct tty_struct *tty, | 716 | static void ipaq_close(struct usb_serial_port *port) |
718 | struct usb_serial_port *port, struct file *filp) | ||
719 | { | 717 | { |
720 | struct ipaq_private *priv = usb_get_serial_port_data(port); | 718 | struct ipaq_private *priv = usb_get_serial_port_data(port); |
721 | 719 | ||
diff --git a/drivers/usb/serial/ipw.c b/drivers/usb/serial/ipw.c index da2a2b46644a..29ad038b9c8d 100644 --- a/drivers/usb/serial/ipw.c +++ b/drivers/usb/serial/ipw.c | |||
@@ -302,23 +302,17 @@ static int ipw_open(struct tty_struct *tty, | |||
302 | return 0; | 302 | return 0; |
303 | } | 303 | } |
304 | 304 | ||
305 | static void ipw_close(struct tty_struct *tty, | 305 | static void ipw_dtr_rts(struct usb_serial_port *port, int on) |
306 | struct usb_serial_port *port, struct file *filp) | ||
307 | { | 306 | { |
308 | struct usb_device *dev = port->serial->dev; | 307 | struct usb_device *dev = port->serial->dev; |
309 | int result; | 308 | int result; |
310 | 309 | ||
311 | if (tty_hung_up_p(filp)) { | ||
312 | dbg("%s: tty_hung_up_p ...", __func__); | ||
313 | return; | ||
314 | } | ||
315 | |||
316 | /*--1: drop the dtr */ | 310 | /*--1: drop the dtr */ |
317 | dbg("%s:dropping dtr", __func__); | 311 | dbg("%s:dropping dtr", __func__); |
318 | result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), | 312 | result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), |
319 | IPW_SIO_SET_PIN, | 313 | IPW_SIO_SET_PIN, |
320 | USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, | 314 | USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, |
321 | IPW_PIN_CLRDTR, | 315 | on ? IPW_PIN_SETDTR : IPW_PIN_CLRDTR, |
322 | 0, | 316 | 0, |
323 | NULL, | 317 | NULL, |
324 | 0, | 318 | 0, |
@@ -332,7 +326,7 @@ static void ipw_close(struct tty_struct *tty, | |||
332 | result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), | 326 | result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), |
333 | IPW_SIO_SET_PIN, USB_TYPE_VENDOR | | 327 | IPW_SIO_SET_PIN, USB_TYPE_VENDOR | |
334 | USB_RECIP_INTERFACE | USB_DIR_OUT, | 328 | USB_RECIP_INTERFACE | USB_DIR_OUT, |
335 | IPW_PIN_CLRRTS, | 329 | on ? IPW_PIN_SETRTS : IPW_PIN_CLRRTS, |
336 | 0, | 330 | 0, |
337 | NULL, | 331 | NULL, |
338 | 0, | 332 | 0, |
@@ -340,7 +334,12 @@ static void ipw_close(struct tty_struct *tty, | |||
340 | if (result < 0) | 334 | if (result < 0) |
341 | dev_err(&port->dev, | 335 | dev_err(&port->dev, |
342 | "dropping rts failed (error = %d)\n", result); | 336 | "dropping rts failed (error = %d)\n", result); |
337 | } | ||
343 | 338 | ||
339 | static void ipw_close(struct usb_serial_port *port) | ||
340 | { | ||
341 | struct usb_device *dev = port->serial->dev; | ||
342 | int result; | ||
344 | 343 | ||
345 | /*--3: purge */ | 344 | /*--3: purge */ |
346 | dbg("%s:sending purge", __func__); | 345 | dbg("%s:sending purge", __func__); |
@@ -461,6 +460,7 @@ static struct usb_serial_driver ipw_device = { | |||
461 | .num_ports = 1, | 460 | .num_ports = 1, |
462 | .open = ipw_open, | 461 | .open = ipw_open, |
463 | .close = ipw_close, | 462 | .close = ipw_close, |
463 | .dtr_rts = ipw_dtr_rts, | ||
464 | .port_probe = ipw_probe, | 464 | .port_probe = ipw_probe, |
465 | .port_remove = ipw_disconnect, | 465 | .port_remove = ipw_disconnect, |
466 | .write = ipw_write, | 466 | .write = ipw_write, |
diff --git a/drivers/usb/serial/ir-usb.c b/drivers/usb/serial/ir-usb.c index 4e2cda93da59..66009b6b763a 100644 --- a/drivers/usb/serial/ir-usb.c +++ b/drivers/usb/serial/ir-usb.c | |||
@@ -88,8 +88,7 @@ static int xbof = -1; | |||
88 | static int ir_startup (struct usb_serial *serial); | 88 | static int ir_startup (struct usb_serial *serial); |
89 | static int ir_open(struct tty_struct *tty, struct usb_serial_port *port, | 89 | static int ir_open(struct tty_struct *tty, struct usb_serial_port *port, |
90 | struct file *filep); | 90 | struct file *filep); |
91 | static void ir_close(struct tty_struct *tty, struct usb_serial_port *port, | 91 | static void ir_close(struct usb_serial_port *port); |
92 | struct file *filep); | ||
93 | static int ir_write(struct tty_struct *tty, struct usb_serial_port *port, | 92 | static int ir_write(struct tty_struct *tty, struct usb_serial_port *port, |
94 | const unsigned char *buf, int count); | 93 | const unsigned char *buf, int count); |
95 | static void ir_write_bulk_callback (struct urb *urb); | 94 | static void ir_write_bulk_callback (struct urb *urb); |
@@ -346,8 +345,7 @@ static int ir_open(struct tty_struct *tty, | |||
346 | return result; | 345 | return result; |
347 | } | 346 | } |
348 | 347 | ||
349 | static void ir_close(struct tty_struct *tty, | 348 | static void ir_close(struct usb_serial_port *port) |
350 | struct usb_serial_port *port, struct file * filp) | ||
351 | { | 349 | { |
352 | dbg("%s - port %d", __func__, port->number); | 350 | dbg("%s - port %d", __func__, port->number); |
353 | 351 | ||
diff --git a/drivers/usb/serial/iuu_phoenix.c b/drivers/usb/serial/iuu_phoenix.c index 4473d442b2aa..76a3cc327bb9 100644 --- a/drivers/usb/serial/iuu_phoenix.c +++ b/drivers/usb/serial/iuu_phoenix.c | |||
@@ -40,7 +40,7 @@ static int debug; | |||
40 | /* | 40 | /* |
41 | * Version Information | 41 | * Version Information |
42 | */ | 42 | */ |
43 | #define DRIVER_VERSION "v0.5" | 43 | #define DRIVER_VERSION "v0.10" |
44 | #define DRIVER_DESC "Infinity USB Unlimited Phoenix driver" | 44 | #define DRIVER_DESC "Infinity USB Unlimited Phoenix driver" |
45 | 45 | ||
46 | static struct usb_device_id id_table[] = { | 46 | static struct usb_device_id id_table[] = { |
@@ -70,7 +70,6 @@ static void read_rxcmd_callback(struct urb *urb); | |||
70 | struct iuu_private { | 70 | struct iuu_private { |
71 | spinlock_t lock; /* store irq state */ | 71 | spinlock_t lock; /* store irq state */ |
72 | wait_queue_head_t delta_msr_wait; | 72 | wait_queue_head_t delta_msr_wait; |
73 | u8 line_control; | ||
74 | u8 line_status; | 73 | u8 line_status; |
75 | u8 termios_initialized; | 74 | u8 termios_initialized; |
76 | int tiostatus; /* store IUART SIGNAL for tiocmget call */ | 75 | int tiostatus; /* store IUART SIGNAL for tiocmget call */ |
@@ -651,32 +650,33 @@ static int iuu_bulk_write(struct usb_serial_port *port) | |||
651 | unsigned long flags; | 650 | unsigned long flags; |
652 | int result; | 651 | int result; |
653 | int i; | 652 | int i; |
653 | int buf_len; | ||
654 | char *buf_ptr = port->write_urb->transfer_buffer; | 654 | char *buf_ptr = port->write_urb->transfer_buffer; |
655 | dbg("%s - enter", __func__); | 655 | dbg("%s - enter", __func__); |
656 | 656 | ||
657 | spin_lock_irqsave(&priv->lock, flags); | ||
657 | *buf_ptr++ = IUU_UART_ESC; | 658 | *buf_ptr++ = IUU_UART_ESC; |
658 | *buf_ptr++ = IUU_UART_TX; | 659 | *buf_ptr++ = IUU_UART_TX; |
659 | *buf_ptr++ = priv->writelen; | 660 | *buf_ptr++ = priv->writelen; |
660 | 661 | ||
661 | memcpy(buf_ptr, priv->writebuf, | 662 | memcpy(buf_ptr, priv->writebuf, priv->writelen); |
662 | priv->writelen); | 663 | buf_len = priv->writelen; |
664 | priv->writelen = 0; | ||
665 | spin_unlock_irqrestore(&priv->lock, flags); | ||
663 | if (debug == 1) { | 666 | if (debug == 1) { |
664 | for (i = 0; i < priv->writelen; i++) | 667 | for (i = 0; i < buf_len; i++) |
665 | sprintf(priv->dbgbuf + i*2 , | 668 | sprintf(priv->dbgbuf + i*2 , |
666 | "%02X", priv->writebuf[i]); | 669 | "%02X", priv->writebuf[i]); |
667 | priv->dbgbuf[priv->writelen+i*2] = 0; | 670 | priv->dbgbuf[buf_len+i*2] = 0; |
668 | dbg("%s - writing %i chars : %s", __func__, | 671 | dbg("%s - writing %i chars : %s", __func__, |
669 | priv->writelen, priv->dbgbuf); | 672 | buf_len, priv->dbgbuf); |
670 | } | 673 | } |
671 | usb_fill_bulk_urb(port->write_urb, port->serial->dev, | 674 | usb_fill_bulk_urb(port->write_urb, port->serial->dev, |
672 | usb_sndbulkpipe(port->serial->dev, | 675 | usb_sndbulkpipe(port->serial->dev, |
673 | port->bulk_out_endpointAddress), | 676 | port->bulk_out_endpointAddress), |
674 | port->write_urb->transfer_buffer, priv->writelen + 3, | 677 | port->write_urb->transfer_buffer, buf_len + 3, |
675 | iuu_rxcmd, port); | 678 | iuu_rxcmd, port); |
676 | result = usb_submit_urb(port->write_urb, GFP_ATOMIC); | 679 | result = usb_submit_urb(port->write_urb, GFP_ATOMIC); |
677 | spin_lock_irqsave(&priv->lock, flags); | ||
678 | priv->writelen = 0; | ||
679 | spin_unlock_irqrestore(&priv->lock, flags); | ||
680 | usb_serial_port_softint(port); | 680 | usb_serial_port_softint(port); |
681 | return result; | 681 | return result; |
682 | } | 682 | } |
@@ -770,14 +770,10 @@ static int iuu_uart_write(struct tty_struct *tty, struct usb_serial_port *port, | |||
770 | return -ENOMEM; | 770 | return -ENOMEM; |
771 | 771 | ||
772 | spin_lock_irqsave(&priv->lock, flags); | 772 | spin_lock_irqsave(&priv->lock, flags); |
773 | if (priv->writelen > 0) { | 773 | |
774 | /* buffer already filled but not commited */ | ||
775 | spin_unlock_irqrestore(&priv->lock, flags); | ||
776 | return 0; | ||
777 | } | ||
778 | /* fill the buffer */ | 774 | /* fill the buffer */ |
779 | memcpy(priv->writebuf, buf, count); | 775 | memcpy(priv->writebuf + priv->writelen, buf, count); |
780 | priv->writelen = count; | 776 | priv->writelen += count; |
781 | spin_unlock_irqrestore(&priv->lock, flags); | 777 | spin_unlock_irqrestore(&priv->lock, flags); |
782 | 778 | ||
783 | return count; | 779 | return count; |
@@ -819,7 +815,7 @@ static int iuu_uart_on(struct usb_serial_port *port) | |||
819 | buf[0] = IUU_UART_ENABLE; | 815 | buf[0] = IUU_UART_ENABLE; |
820 | buf[1] = (u8) ((IUU_BAUD_9600 >> 8) & 0x00FF); | 816 | buf[1] = (u8) ((IUU_BAUD_9600 >> 8) & 0x00FF); |
821 | buf[2] = (u8) (0x00FF & IUU_BAUD_9600); | 817 | buf[2] = (u8) (0x00FF & IUU_BAUD_9600); |
822 | buf[3] = (u8) (0x0F0 & IUU_TWO_STOP_BITS) | (0x07 & IUU_PARITY_EVEN); | 818 | buf[3] = (u8) (0x0F0 & IUU_ONE_STOP_BIT) | (0x07 & IUU_PARITY_EVEN); |
823 | 819 | ||
824 | status = bulk_immediate(port, buf, 4); | 820 | status = bulk_immediate(port, buf, 4); |
825 | if (status != IUU_OPERATION_OK) { | 821 | if (status != IUU_OPERATION_OK) { |
@@ -946,19 +942,59 @@ static int iuu_uart_baud(struct usb_serial_port *port, u32 baud, | |||
946 | return status; | 942 | return status; |
947 | } | 943 | } |
948 | 944 | ||
949 | static int set_control_lines(struct usb_device *dev, u8 value) | 945 | static void iuu_set_termios(struct tty_struct *tty, |
946 | struct usb_serial_port *port, struct ktermios *old_termios) | ||
950 | { | 947 | { |
951 | return 0; | 948 | const u32 supported_mask = CMSPAR|PARENB|PARODD; |
949 | |||
950 | unsigned int cflag = tty->termios->c_cflag; | ||
951 | int status; | ||
952 | u32 actual; | ||
953 | u32 parity; | ||
954 | int csize = CS7; | ||
955 | int baud = 9600; /* Fixed for the moment */ | ||
956 | u32 newval = cflag & supported_mask; | ||
957 | |||
958 | /* compute the parity parameter */ | ||
959 | parity = 0; | ||
960 | if (cflag & CMSPAR) { /* Using mark space */ | ||
961 | if (cflag & PARODD) | ||
962 | parity |= IUU_PARITY_SPACE; | ||
963 | else | ||
964 | parity |= IUU_PARITY_MARK; | ||
965 | } else if (!(cflag & PARENB)) { | ||
966 | parity |= IUU_PARITY_NONE; | ||
967 | csize = CS8; | ||
968 | } else if (cflag & PARODD) | ||
969 | parity |= IUU_PARITY_ODD; | ||
970 | else | ||
971 | parity |= IUU_PARITY_EVEN; | ||
972 | |||
973 | parity |= (cflag & CSTOPB ? IUU_TWO_STOP_BITS : IUU_ONE_STOP_BIT); | ||
974 | |||
975 | /* set it */ | ||
976 | status = iuu_uart_baud(port, | ||
977 | (clockmode == 2) ? 16457 : 9600 * boost / 100, | ||
978 | &actual, parity); | ||
979 | |||
980 | /* set the termios value to the real one, so the user now what has | ||
981 | * changed. We support few fields so its easies to copy the old hw | ||
982 | * settings back over and then adjust them | ||
983 | */ | ||
984 | if (old_termios) | ||
985 | tty_termios_copy_hw(tty->termios, old_termios); | ||
986 | if (status != 0) /* Set failed - return old bits */ | ||
987 | return; | ||
988 | /* Re-encode speed, parity and csize */ | ||
989 | tty_encode_baud_rate(tty, baud, baud); | ||
990 | tty->termios->c_cflag &= ~(supported_mask|CSIZE); | ||
991 | tty->termios->c_cflag |= newval | csize; | ||
952 | } | 992 | } |
953 | 993 | ||
954 | static void iuu_close(struct tty_struct *tty, | 994 | static void iuu_close(struct usb_serial_port *port) |
955 | struct usb_serial_port *port, struct file *filp) | ||
956 | { | 995 | { |
957 | /* iuu_led (port,255,0,0,0); */ | 996 | /* iuu_led (port,255,0,0,0); */ |
958 | struct usb_serial *serial; | 997 | struct usb_serial *serial; |
959 | struct iuu_private *priv = usb_get_serial_port_data(port); | ||
960 | unsigned long flags; | ||
961 | unsigned int c_cflag; | ||
962 | 998 | ||
963 | serial = port->serial; | 999 | serial = port->serial; |
964 | if (!serial) | 1000 | if (!serial) |
@@ -968,17 +1004,6 @@ static void iuu_close(struct tty_struct *tty, | |||
968 | 1004 | ||
969 | iuu_uart_off(port); | 1005 | iuu_uart_off(port); |
970 | if (serial->dev) { | 1006 | if (serial->dev) { |
971 | if (tty) { | ||
972 | c_cflag = tty->termios->c_cflag; | ||
973 | if (c_cflag & HUPCL) { | ||
974 | /* drop DTR and RTS */ | ||
975 | priv = usb_get_serial_port_data(port); | ||
976 | spin_lock_irqsave(&priv->lock, flags); | ||
977 | priv->line_control = 0; | ||
978 | spin_unlock_irqrestore(&priv->lock, flags); | ||
979 | set_control_lines(port->serial->dev, 0); | ||
980 | } | ||
981 | } | ||
982 | /* free writebuf */ | 1007 | /* free writebuf */ |
983 | /* shutdown our urbs */ | 1008 | /* shutdown our urbs */ |
984 | dbg("%s - shutting down urbs", __func__); | 1009 | dbg("%s - shutting down urbs", __func__); |
@@ -1154,7 +1179,7 @@ static int iuu_open(struct tty_struct *tty, | |||
1154 | if (result) { | 1179 | if (result) { |
1155 | dev_err(&port->dev, "%s - failed submitting read urb," | 1180 | dev_err(&port->dev, "%s - failed submitting read urb," |
1156 | " error %d\n", __func__, result); | 1181 | " error %d\n", __func__, result); |
1157 | iuu_close(tty, port, NULL); | 1182 | iuu_close(port); |
1158 | return -EPROTO; | 1183 | return -EPROTO; |
1159 | } else { | 1184 | } else { |
1160 | dbg("%s - rxcmd OK", __func__); | 1185 | dbg("%s - rxcmd OK", __func__); |
@@ -1175,6 +1200,7 @@ static struct usb_serial_driver iuu_device = { | |||
1175 | .read_bulk_callback = iuu_uart_read_callback, | 1200 | .read_bulk_callback = iuu_uart_read_callback, |
1176 | .tiocmget = iuu_tiocmget, | 1201 | .tiocmget = iuu_tiocmget, |
1177 | .tiocmset = iuu_tiocmset, | 1202 | .tiocmset = iuu_tiocmset, |
1203 | .set_termios = iuu_set_termios, | ||
1178 | .attach = iuu_startup, | 1204 | .attach = iuu_startup, |
1179 | .shutdown = iuu_shutdown, | 1205 | .shutdown = iuu_shutdown, |
1180 | }; | 1206 | }; |
diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c index 00daa8f7759a..f1195a98f316 100644 --- a/drivers/usb/serial/keyspan.c +++ b/drivers/usb/serial/keyspan.c | |||
@@ -1298,8 +1298,16 @@ static inline void stop_urb(struct urb *urb) | |||
1298 | usb_kill_urb(urb); | 1298 | usb_kill_urb(urb); |
1299 | } | 1299 | } |
1300 | 1300 | ||
1301 | static void keyspan_close(struct tty_struct *tty, | 1301 | static void keyspan_dtr_rts(struct usb_serial_port *port, int on) |
1302 | struct usb_serial_port *port, struct file *filp) | 1302 | { |
1303 | struct keyspan_port_private *p_priv = usb_get_serial_port_data(port); | ||
1304 | |||
1305 | p_priv->rts_state = on; | ||
1306 | p_priv->dtr_state = on; | ||
1307 | keyspan_send_setup(port, 0); | ||
1308 | } | ||
1309 | |||
1310 | static void keyspan_close(struct usb_serial_port *port) | ||
1303 | { | 1311 | { |
1304 | int i; | 1312 | int i; |
1305 | struct usb_serial *serial = port->serial; | 1313 | struct usb_serial *serial = port->serial; |
@@ -1336,7 +1344,6 @@ static void keyspan_close(struct tty_struct *tty, | |||
1336 | stop_urb(p_priv->out_urbs[i]); | 1344 | stop_urb(p_priv->out_urbs[i]); |
1337 | } | 1345 | } |
1338 | } | 1346 | } |
1339 | tty_port_tty_set(&port->port, NULL); | ||
1340 | } | 1347 | } |
1341 | 1348 | ||
1342 | /* download the firmware to a pre-renumeration device */ | 1349 | /* download the firmware to a pre-renumeration device */ |
diff --git a/drivers/usb/serial/keyspan.h b/drivers/usb/serial/keyspan.h index 38b4582e0734..0d4569b60768 100644 --- a/drivers/usb/serial/keyspan.h +++ b/drivers/usb/serial/keyspan.h | |||
@@ -38,9 +38,8 @@ | |||
38 | static int keyspan_open (struct tty_struct *tty, | 38 | static int keyspan_open (struct tty_struct *tty, |
39 | struct usb_serial_port *port, | 39 | struct usb_serial_port *port, |
40 | struct file *filp); | 40 | struct file *filp); |
41 | static void keyspan_close (struct tty_struct *tty, | 41 | static void keyspan_close (struct usb_serial_port *port); |
42 | struct usb_serial_port *port, | 42 | static void keyspan_dtr_rts (struct usb_serial_port *port, int on); |
43 | struct file *filp); | ||
44 | static int keyspan_startup (struct usb_serial *serial); | 43 | static int keyspan_startup (struct usb_serial *serial); |
45 | static void keyspan_shutdown (struct usb_serial *serial); | 44 | static void keyspan_shutdown (struct usb_serial *serial); |
46 | static int keyspan_write_room (struct tty_struct *tty); | 45 | static int keyspan_write_room (struct tty_struct *tty); |
@@ -562,6 +561,7 @@ static struct usb_serial_driver keyspan_1port_device = { | |||
562 | .num_ports = 1, | 561 | .num_ports = 1, |
563 | .open = keyspan_open, | 562 | .open = keyspan_open, |
564 | .close = keyspan_close, | 563 | .close = keyspan_close, |
564 | .dtr_rts = keyspan_dtr_rts, | ||
565 | .write = keyspan_write, | 565 | .write = keyspan_write, |
566 | .write_room = keyspan_write_room, | 566 | .write_room = keyspan_write_room, |
567 | .set_termios = keyspan_set_termios, | 567 | .set_termios = keyspan_set_termios, |
@@ -582,6 +582,7 @@ static struct usb_serial_driver keyspan_2port_device = { | |||
582 | .num_ports = 2, | 582 | .num_ports = 2, |
583 | .open = keyspan_open, | 583 | .open = keyspan_open, |
584 | .close = keyspan_close, | 584 | .close = keyspan_close, |
585 | .dtr_rts = keyspan_dtr_rts, | ||
585 | .write = keyspan_write, | 586 | .write = keyspan_write, |
586 | .write_room = keyspan_write_room, | 587 | .write_room = keyspan_write_room, |
587 | .set_termios = keyspan_set_termios, | 588 | .set_termios = keyspan_set_termios, |
@@ -602,6 +603,7 @@ static struct usb_serial_driver keyspan_4port_device = { | |||
602 | .num_ports = 4, | 603 | .num_ports = 4, |
603 | .open = keyspan_open, | 604 | .open = keyspan_open, |
604 | .close = keyspan_close, | 605 | .close = keyspan_close, |
606 | .dtr_rts = keyspan_dtr_rts, | ||
605 | .write = keyspan_write, | 607 | .write = keyspan_write, |
606 | .write_room = keyspan_write_room, | 608 | .write_room = keyspan_write_room, |
607 | .set_termios = keyspan_set_termios, | 609 | .set_termios = keyspan_set_termios, |
diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c index bf1ae247da66..ab769dbea1b3 100644 --- a/drivers/usb/serial/keyspan_pda.c +++ b/drivers/usb/serial/keyspan_pda.c | |||
@@ -651,6 +651,35 @@ static int keyspan_pda_chars_in_buffer(struct tty_struct *tty) | |||
651 | } | 651 | } |
652 | 652 | ||
653 | 653 | ||
654 | static void keyspan_pda_dtr_rts(struct usb_serial_port *port, int on) | ||
655 | { | ||
656 | struct usb_serial *serial = port->serial; | ||
657 | |||
658 | if (serial->dev) { | ||
659 | if (on) | ||
660 | keyspan_pda_set_modem_info(serial, (1<<7) | (1<< 2)); | ||
661 | else | ||
662 | keyspan_pda_set_modem_info(serial, 0); | ||
663 | } | ||
664 | } | ||
665 | |||
666 | static int keyspan_pda_carrier_raised(struct usb_serial_port *port) | ||
667 | { | ||
668 | struct usb_serial *serial = port->serial; | ||
669 | unsigned char modembits; | ||
670 | |||
671 | /* If we can read the modem status and the DCD is low then | ||
672 | carrier is not raised yet */ | ||
673 | if (keyspan_pda_get_modem_info(serial, &modembits) >= 0) { | ||
674 | if (!(modembits & (1>>6))) | ||
675 | return 0; | ||
676 | } | ||
677 | /* Carrier raised, or we failed (eg disconnected) so | ||
678 | progress accordingly */ | ||
679 | return 1; | ||
680 | } | ||
681 | |||
682 | |||
654 | static int keyspan_pda_open(struct tty_struct *tty, | 683 | static int keyspan_pda_open(struct tty_struct *tty, |
655 | struct usb_serial_port *port, struct file *filp) | 684 | struct usb_serial_port *port, struct file *filp) |
656 | { | 685 | { |
@@ -682,13 +711,6 @@ static int keyspan_pda_open(struct tty_struct *tty, | |||
682 | priv->tx_room = room; | 711 | priv->tx_room = room; |
683 | priv->tx_throttled = room ? 0 : 1; | 712 | priv->tx_throttled = room ? 0 : 1; |
684 | 713 | ||
685 | /* the normal serial device seems to always turn on DTR and RTS here, | ||
686 | so do the same */ | ||
687 | if (tty && (tty->termios->c_cflag & CBAUD)) | ||
688 | keyspan_pda_set_modem_info(serial, (1<<7) | (1<<2)); | ||
689 | else | ||
690 | keyspan_pda_set_modem_info(serial, 0); | ||
691 | |||
692 | /*Start reading from the device*/ | 714 | /*Start reading from the device*/ |
693 | port->interrupt_in_urb->dev = serial->dev; | 715 | port->interrupt_in_urb->dev = serial->dev; |
694 | rc = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); | 716 | rc = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); |
@@ -700,19 +722,11 @@ static int keyspan_pda_open(struct tty_struct *tty, | |||
700 | error: | 722 | error: |
701 | return rc; | 723 | return rc; |
702 | } | 724 | } |
703 | 725 | static void keyspan_pda_close(struct usb_serial_port *port) | |
704 | |||
705 | static void keyspan_pda_close(struct tty_struct *tty, | ||
706 | struct usb_serial_port *port, struct file *filp) | ||
707 | { | 726 | { |
708 | struct usb_serial *serial = port->serial; | 727 | struct usb_serial *serial = port->serial; |
709 | 728 | ||
710 | if (serial->dev) { | 729 | if (serial->dev) { |
711 | /* the normal serial device seems to always shut | ||
712 | off DTR and RTS now */ | ||
713 | if (tty->termios->c_cflag & HUPCL) | ||
714 | keyspan_pda_set_modem_info(serial, 0); | ||
715 | |||
716 | /* shutdown our bulk reads and writes */ | 730 | /* shutdown our bulk reads and writes */ |
717 | usb_kill_urb(port->write_urb); | 731 | usb_kill_urb(port->write_urb); |
718 | usb_kill_urb(port->interrupt_in_urb); | 732 | usb_kill_urb(port->interrupt_in_urb); |
@@ -839,6 +853,8 @@ static struct usb_serial_driver keyspan_pda_device = { | |||
839 | .usb_driver = &keyspan_pda_driver, | 853 | .usb_driver = &keyspan_pda_driver, |
840 | .id_table = id_table_std, | 854 | .id_table = id_table_std, |
841 | .num_ports = 1, | 855 | .num_ports = 1, |
856 | .dtr_rts = keyspan_pda_dtr_rts, | ||
857 | .carrier_raised = keyspan_pda_carrier_raised, | ||
842 | .open = keyspan_pda_open, | 858 | .open = keyspan_pda_open, |
843 | .close = keyspan_pda_close, | 859 | .close = keyspan_pda_close, |
844 | .write = keyspan_pda_write, | 860 | .write = keyspan_pda_write, |
diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c index fcd9082f3e7f..fa817c66b3e8 100644 --- a/drivers/usb/serial/kl5kusb105.c +++ b/drivers/usb/serial/kl5kusb105.c | |||
@@ -76,8 +76,7 @@ static int klsi_105_startup(struct usb_serial *serial); | |||
76 | static void klsi_105_shutdown(struct usb_serial *serial); | 76 | static void klsi_105_shutdown(struct usb_serial *serial); |
77 | static int klsi_105_open(struct tty_struct *tty, | 77 | static int klsi_105_open(struct tty_struct *tty, |
78 | struct usb_serial_port *port, struct file *filp); | 78 | struct usb_serial_port *port, struct file *filp); |
79 | static void klsi_105_close(struct tty_struct *tty, | 79 | static void klsi_105_close(struct usb_serial_port *port); |
80 | struct usb_serial_port *port, struct file *filp); | ||
81 | static int klsi_105_write(struct tty_struct *tty, | 80 | static int klsi_105_write(struct tty_struct *tty, |
82 | struct usb_serial_port *port, const unsigned char *buf, int count); | 81 | struct usb_serial_port *port, const unsigned char *buf, int count); |
83 | static void klsi_105_write_bulk_callback(struct urb *urb); | 82 | static void klsi_105_write_bulk_callback(struct urb *urb); |
@@ -447,8 +446,7 @@ exit: | |||
447 | } /* klsi_105_open */ | 446 | } /* klsi_105_open */ |
448 | 447 | ||
449 | 448 | ||
450 | static void klsi_105_close(struct tty_struct *tty, | 449 | static void klsi_105_close(struct usb_serial_port *port) |
451 | struct usb_serial_port *port, struct file *filp) | ||
452 | { | 450 | { |
453 | struct klsi_105_private *priv = usb_get_serial_port_data(port); | 451 | struct klsi_105_private *priv = usb_get_serial_port_data(port); |
454 | int rc; | 452 | int rc; |
diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c index c148544953b3..6b570498287f 100644 --- a/drivers/usb/serial/kobil_sct.c +++ b/drivers/usb/serial/kobil_sct.c | |||
@@ -72,8 +72,7 @@ static int kobil_startup(struct usb_serial *serial); | |||
72 | static void kobil_shutdown(struct usb_serial *serial); | 72 | static void kobil_shutdown(struct usb_serial *serial); |
73 | static int kobil_open(struct tty_struct *tty, | 73 | static int kobil_open(struct tty_struct *tty, |
74 | struct usb_serial_port *port, struct file *filp); | 74 | struct usb_serial_port *port, struct file *filp); |
75 | static void kobil_close(struct tty_struct *tty, struct usb_serial_port *port, | 75 | static void kobil_close(struct usb_serial_port *port); |
76 | struct file *filp); | ||
77 | static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port, | 76 | static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port, |
78 | const unsigned char *buf, int count); | 77 | const unsigned char *buf, int count); |
79 | static int kobil_write_room(struct tty_struct *tty); | 78 | static int kobil_write_room(struct tty_struct *tty); |
@@ -209,7 +208,7 @@ static void kobil_shutdown(struct usb_serial *serial) | |||
209 | 208 | ||
210 | for (i = 0; i < serial->num_ports; ++i) { | 209 | for (i = 0; i < serial->num_ports; ++i) { |
211 | while (serial->port[i]->port.count > 0) | 210 | while (serial->port[i]->port.count > 0) |
212 | kobil_close(NULL, serial->port[i], NULL); | 211 | kobil_close(serial->port[i]); |
213 | kfree(usb_get_serial_port_data(serial->port[i])); | 212 | kfree(usb_get_serial_port_data(serial->port[i])); |
214 | usb_set_serial_port_data(serial->port[i], NULL); | 213 | usb_set_serial_port_data(serial->port[i], NULL); |
215 | } | 214 | } |
@@ -346,11 +345,11 @@ static int kobil_open(struct tty_struct *tty, | |||
346 | } | 345 | } |
347 | 346 | ||
348 | 347 | ||
349 | static void kobil_close(struct tty_struct *tty, | 348 | static void kobil_close(struct usb_serial_port *port) |
350 | struct usb_serial_port *port, struct file *filp) | ||
351 | { | 349 | { |
352 | dbg("%s - port %d", __func__, port->number); | 350 | dbg("%s - port %d", __func__, port->number); |
353 | 351 | ||
352 | /* FIXME: Add rts/dtr methods */ | ||
354 | if (port->write_urb) { | 353 | if (port->write_urb) { |
355 | usb_kill_urb(port->write_urb); | 354 | usb_kill_urb(port->write_urb); |
356 | usb_free_urb(port->write_urb); | 355 | usb_free_urb(port->write_urb); |
diff --git a/drivers/usb/serial/mct_u232.c b/drivers/usb/serial/mct_u232.c index 82930a7d5093..873795548fc0 100644 --- a/drivers/usb/serial/mct_u232.c +++ b/drivers/usb/serial/mct_u232.c | |||
@@ -95,8 +95,8 @@ static int mct_u232_startup(struct usb_serial *serial); | |||
95 | static void mct_u232_shutdown(struct usb_serial *serial); | 95 | static void mct_u232_shutdown(struct usb_serial *serial); |
96 | static int mct_u232_open(struct tty_struct *tty, | 96 | static int mct_u232_open(struct tty_struct *tty, |
97 | struct usb_serial_port *port, struct file *filp); | 97 | struct usb_serial_port *port, struct file *filp); |
98 | static void mct_u232_close(struct tty_struct *tty, | 98 | static void mct_u232_close(struct usb_serial_port *port); |
99 | struct usb_serial_port *port, struct file *filp); | 99 | static void mct_u232_dtr_rts(struct usb_serial_port *port, int on); |
100 | static void mct_u232_read_int_callback(struct urb *urb); | 100 | static void mct_u232_read_int_callback(struct urb *urb); |
101 | static void mct_u232_set_termios(struct tty_struct *tty, | 101 | static void mct_u232_set_termios(struct tty_struct *tty, |
102 | struct usb_serial_port *port, struct ktermios *old); | 102 | struct usb_serial_port *port, struct ktermios *old); |
@@ -140,6 +140,7 @@ static struct usb_serial_driver mct_u232_device = { | |||
140 | .num_ports = 1, | 140 | .num_ports = 1, |
141 | .open = mct_u232_open, | 141 | .open = mct_u232_open, |
142 | .close = mct_u232_close, | 142 | .close = mct_u232_close, |
143 | .dtr_rts = mct_u232_dtr_rts, | ||
143 | .throttle = mct_u232_throttle, | 144 | .throttle = mct_u232_throttle, |
144 | .unthrottle = mct_u232_unthrottle, | 145 | .unthrottle = mct_u232_unthrottle, |
145 | .read_int_callback = mct_u232_read_int_callback, | 146 | .read_int_callback = mct_u232_read_int_callback, |
@@ -496,29 +497,29 @@ error: | |||
496 | return retval; | 497 | return retval; |
497 | } /* mct_u232_open */ | 498 | } /* mct_u232_open */ |
498 | 499 | ||
499 | 500 | static void mct_u232_dtr_rts(struct usb_serial_port *port, int on) | |
500 | static void mct_u232_close(struct tty_struct *tty, | ||
501 | struct usb_serial_port *port, struct file *filp) | ||
502 | { | 501 | { |
503 | unsigned int c_cflag; | ||
504 | unsigned int control_state; | 502 | unsigned int control_state; |
505 | struct mct_u232_private *priv = usb_get_serial_port_data(port); | 503 | struct mct_u232_private *priv = usb_get_serial_port_data(port); |
506 | dbg("%s port %d", __func__, port->number); | ||
507 | 504 | ||
508 | if (tty) { | 505 | mutex_lock(&port->serial->disc_mutex); |
509 | c_cflag = tty->termios->c_cflag; | 506 | if (!port->serial->disconnected) { |
510 | mutex_lock(&port->serial->disc_mutex); | 507 | /* drop DTR and RTS */ |
511 | if (c_cflag & HUPCL && !port->serial->disconnected) { | 508 | spin_lock_irq(&priv->lock); |
512 | /* drop DTR and RTS */ | 509 | if (on) |
513 | spin_lock_irq(&priv->lock); | 510 | priv->control_state |= TIOCM_DTR | TIOCM_RTS; |
511 | else | ||
514 | priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS); | 512 | priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS); |
515 | control_state = priv->control_state; | 513 | control_state = priv->control_state; |
516 | spin_unlock_irq(&priv->lock); | 514 | spin_unlock_irq(&priv->lock); |
517 | mct_u232_set_modem_ctrl(port->serial, control_state); | 515 | mct_u232_set_modem_ctrl(port->serial, control_state); |
518 | } | ||
519 | mutex_unlock(&port->serial->disc_mutex); | ||
520 | } | 516 | } |
517 | mutex_unlock(&port->serial->disc_mutex); | ||
518 | } | ||
521 | 519 | ||
520 | static void mct_u232_close(struct usb_serial_port *port) | ||
521 | { | ||
522 | dbg("%s port %d", __func__, port->number); | ||
522 | 523 | ||
523 | if (port->serial->dev) { | 524 | if (port->serial->dev) { |
524 | /* shutdown our urbs */ | 525 | /* shutdown our urbs */ |
diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c index 24e3b5d4b4d4..9e1a013ee7f6 100644 --- a/drivers/usb/serial/mos7720.c +++ b/drivers/usb/serial/mos7720.c | |||
@@ -533,8 +533,7 @@ static int mos7720_chars_in_buffer(struct tty_struct *tty) | |||
533 | return chars; | 533 | return chars; |
534 | } | 534 | } |
535 | 535 | ||
536 | static void mos7720_close(struct tty_struct *tty, | 536 | static void mos7720_close(struct usb_serial_port *port) |
537 | struct usb_serial_port *port, struct file *filp) | ||
538 | { | 537 | { |
539 | struct usb_serial *serial; | 538 | struct usb_serial *serial; |
540 | struct moschip_port *mos7720_port; | 539 | struct moschip_port *mos7720_port; |
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c index 84fb1dcd30dc..10b78a37214f 100644 --- a/drivers/usb/serial/mos7840.c +++ b/drivers/usb/serial/mos7840.c | |||
@@ -1135,54 +1135,12 @@ static int mos7840_chars_in_buffer(struct tty_struct *tty) | |||
1135 | 1135 | ||
1136 | } | 1136 | } |
1137 | 1137 | ||
1138 | /************************************************************************ | ||
1139 | * | ||
1140 | * mos7840_block_until_tx_empty | ||
1141 | * | ||
1142 | * This function will block the close until one of the following: | ||
1143 | * 1. TX count are 0 | ||
1144 | * 2. The mos7840 has stopped | ||
1145 | * 3. A timeout of 3 seconds without activity has expired | ||
1146 | * | ||
1147 | ************************************************************************/ | ||
1148 | static void mos7840_block_until_tx_empty(struct tty_struct *tty, | ||
1149 | struct moschip_port *mos7840_port) | ||
1150 | { | ||
1151 | int timeout = HZ / 10; | ||
1152 | int wait = 30; | ||
1153 | int count; | ||
1154 | |||
1155 | while (1) { | ||
1156 | |||
1157 | count = mos7840_chars_in_buffer(tty); | ||
1158 | |||
1159 | /* Check for Buffer status */ | ||
1160 | if (count <= 0) | ||
1161 | return; | ||
1162 | |||
1163 | /* Block the thread for a while */ | ||
1164 | interruptible_sleep_on_timeout(&mos7840_port->wait_chase, | ||
1165 | timeout); | ||
1166 | |||
1167 | /* No activity.. count down section */ | ||
1168 | wait--; | ||
1169 | if (wait == 0) { | ||
1170 | dbg("%s - TIMEOUT", __func__); | ||
1171 | return; | ||
1172 | } else { | ||
1173 | /* Reset timeout value back to seconds */ | ||
1174 | wait = 30; | ||
1175 | } | ||
1176 | } | ||
1177 | } | ||
1178 | |||
1179 | /***************************************************************************** | 1138 | /***************************************************************************** |
1180 | * mos7840_close | 1139 | * mos7840_close |
1181 | * this function is called by the tty driver when a port is closed | 1140 | * this function is called by the tty driver when a port is closed |
1182 | *****************************************************************************/ | 1141 | *****************************************************************************/ |
1183 | 1142 | ||
1184 | static void mos7840_close(struct tty_struct *tty, | 1143 | static void mos7840_close(struct usb_serial_port *port) |
1185 | struct usb_serial_port *port, struct file *filp) | ||
1186 | { | 1144 | { |
1187 | struct usb_serial *serial; | 1145 | struct usb_serial *serial; |
1188 | struct moschip_port *mos7840_port; | 1146 | struct moschip_port *mos7840_port; |
@@ -1223,10 +1181,6 @@ static void mos7840_close(struct tty_struct *tty, | |||
1223 | } | 1181 | } |
1224 | } | 1182 | } |
1225 | 1183 | ||
1226 | if (serial->dev) | ||
1227 | /* flush and block until tx is empty */ | ||
1228 | mos7840_block_until_tx_empty(tty, mos7840_port); | ||
1229 | |||
1230 | /* While closing port, shutdown all bulk read, write * | 1184 | /* While closing port, shutdown all bulk read, write * |
1231 | * and interrupt read if they exists */ | 1185 | * and interrupt read if they exists */ |
1232 | if (serial->dev) { | 1186 | if (serial->dev) { |
diff --git a/drivers/usb/serial/navman.c b/drivers/usb/serial/navman.c index bcdcbb822705..f5f3751a888c 100644 --- a/drivers/usb/serial/navman.c +++ b/drivers/usb/serial/navman.c | |||
@@ -98,8 +98,7 @@ static int navman_open(struct tty_struct *tty, | |||
98 | return result; | 98 | return result; |
99 | } | 99 | } |
100 | 100 | ||
101 | static void navman_close(struct tty_struct *tty, | 101 | static void navman_close(struct usb_serial_port *port) |
102 | struct usb_serial_port *port, struct file *filp) | ||
103 | { | 102 | { |
104 | dbg("%s - port %d", __func__, port->number); | 103 | dbg("%s - port %d", __func__, port->number); |
105 | 104 | ||
diff --git a/drivers/usb/serial/omninet.c b/drivers/usb/serial/omninet.c index df6539712726..1104617334f5 100644 --- a/drivers/usb/serial/omninet.c +++ b/drivers/usb/serial/omninet.c | |||
@@ -66,8 +66,7 @@ static int debug; | |||
66 | /* function prototypes */ | 66 | /* function prototypes */ |
67 | static int omninet_open(struct tty_struct *tty, struct usb_serial_port *port, | 67 | static int omninet_open(struct tty_struct *tty, struct usb_serial_port *port, |
68 | struct file *filp); | 68 | struct file *filp); |
69 | static void omninet_close(struct tty_struct *tty, struct usb_serial_port *port, | 69 | static void omninet_close(struct usb_serial_port *port); |
70 | struct file *filp); | ||
71 | static void omninet_read_bulk_callback(struct urb *urb); | 70 | static void omninet_read_bulk_callback(struct urb *urb); |
72 | static void omninet_write_bulk_callback(struct urb *urb); | 71 | static void omninet_write_bulk_callback(struct urb *urb); |
73 | static int omninet_write(struct tty_struct *tty, struct usb_serial_port *port, | 72 | static int omninet_write(struct tty_struct *tty, struct usb_serial_port *port, |
@@ -189,8 +188,7 @@ static int omninet_open(struct tty_struct *tty, | |||
189 | return result; | 188 | return result; |
190 | } | 189 | } |
191 | 190 | ||
192 | static void omninet_close(struct tty_struct *tty, | 191 | static void omninet_close(struct usb_serial_port *port) |
193 | struct usb_serial_port *port, struct file *filp) | ||
194 | { | 192 | { |
195 | dbg("%s - port %d", __func__, port->number); | 193 | dbg("%s - port %d", __func__, port->number); |
196 | usb_kill_urb(port->read_urb); | 194 | usb_kill_urb(port->read_urb); |
diff --git a/drivers/usb/serial/opticon.c b/drivers/usb/serial/opticon.c index b500ad10b758..c20480aa9755 100644 --- a/drivers/usb/serial/opticon.c +++ b/drivers/usb/serial/opticon.c | |||
@@ -173,8 +173,7 @@ static int opticon_open(struct tty_struct *tty, struct usb_serial_port *port, | |||
173 | return result; | 173 | return result; |
174 | } | 174 | } |
175 | 175 | ||
176 | static void opticon_close(struct tty_struct *tty, struct usb_serial_port *port, | 176 | static void opticon_close(struct usb_serial_port *port) |
177 | struct file *filp) | ||
178 | { | 177 | { |
179 | struct opticon_private *priv = usb_get_serial_data(port->serial); | 178 | struct opticon_private *priv = usb_get_serial_data(port->serial); |
180 | 179 | ||
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c index 7817b82889ca..a16d69fadba1 100644 --- a/drivers/usb/serial/option.c +++ b/drivers/usb/serial/option.c | |||
@@ -45,8 +45,9 @@ | |||
45 | /* Function prototypes */ | 45 | /* Function prototypes */ |
46 | static int option_open(struct tty_struct *tty, struct usb_serial_port *port, | 46 | static int option_open(struct tty_struct *tty, struct usb_serial_port *port, |
47 | struct file *filp); | 47 | struct file *filp); |
48 | static void option_close(struct tty_struct *tty, struct usb_serial_port *port, | 48 | static void option_close(struct usb_serial_port *port); |
49 | struct file *filp); | 49 | static void option_dtr_rts(struct usb_serial_port *port, int on); |
50 | |||
50 | static int option_startup(struct usb_serial *serial); | 51 | static int option_startup(struct usb_serial *serial); |
51 | static void option_shutdown(struct usb_serial *serial); | 52 | static void option_shutdown(struct usb_serial *serial); |
52 | static int option_write_room(struct tty_struct *tty); | 53 | static int option_write_room(struct tty_struct *tty); |
@@ -61,7 +62,7 @@ static void option_set_termios(struct tty_struct *tty, | |||
61 | static int option_tiocmget(struct tty_struct *tty, struct file *file); | 62 | static int option_tiocmget(struct tty_struct *tty, struct file *file); |
62 | static int option_tiocmset(struct tty_struct *tty, struct file *file, | 63 | static int option_tiocmset(struct tty_struct *tty, struct file *file, |
63 | unsigned int set, unsigned int clear); | 64 | unsigned int set, unsigned int clear); |
64 | static int option_send_setup(struct tty_struct *tty, struct usb_serial_port *port); | 65 | static int option_send_setup(struct usb_serial_port *port); |
65 | static int option_suspend(struct usb_serial *serial, pm_message_t message); | 66 | static int option_suspend(struct usb_serial *serial, pm_message_t message); |
66 | static int option_resume(struct usb_serial *serial); | 67 | static int option_resume(struct usb_serial *serial); |
67 | 68 | ||
@@ -551,6 +552,7 @@ static struct usb_serial_driver option_1port_device = { | |||
551 | .num_ports = 1, | 552 | .num_ports = 1, |
552 | .open = option_open, | 553 | .open = option_open, |
553 | .close = option_close, | 554 | .close = option_close, |
555 | .dtr_rts = option_dtr_rts, | ||
554 | .write = option_write, | 556 | .write = option_write, |
555 | .write_room = option_write_room, | 557 | .write_room = option_write_room, |
556 | .chars_in_buffer = option_chars_in_buffer, | 558 | .chars_in_buffer = option_chars_in_buffer, |
@@ -630,7 +632,7 @@ static void option_set_termios(struct tty_struct *tty, | |||
630 | dbg("%s", __func__); | 632 | dbg("%s", __func__); |
631 | /* Doesn't support option setting */ | 633 | /* Doesn't support option setting */ |
632 | tty_termios_copy_hw(tty->termios, old_termios); | 634 | tty_termios_copy_hw(tty->termios, old_termios); |
633 | option_send_setup(tty, port); | 635 | option_send_setup(port); |
634 | } | 636 | } |
635 | 637 | ||
636 | static int option_tiocmget(struct tty_struct *tty, struct file *file) | 638 | static int option_tiocmget(struct tty_struct *tty, struct file *file) |
@@ -669,7 +671,7 @@ static int option_tiocmset(struct tty_struct *tty, struct file *file, | |||
669 | portdata->rts_state = 0; | 671 | portdata->rts_state = 0; |
670 | if (clear & TIOCM_DTR) | 672 | if (clear & TIOCM_DTR) |
671 | portdata->dtr_state = 0; | 673 | portdata->dtr_state = 0; |
672 | return option_send_setup(tty, port); | 674 | return option_send_setup(port); |
673 | } | 675 | } |
674 | 676 | ||
675 | /* Write */ | 677 | /* Write */ |
@@ -897,10 +899,6 @@ static int option_open(struct tty_struct *tty, | |||
897 | 899 | ||
898 | dbg("%s", __func__); | 900 | dbg("%s", __func__); |
899 | 901 | ||
900 | /* Set some sane defaults */ | ||
901 | portdata->rts_state = 1; | ||
902 | portdata->dtr_state = 1; | ||
903 | |||
904 | /* Reset low level data toggle and start reading from endpoints */ | 902 | /* Reset low level data toggle and start reading from endpoints */ |
905 | for (i = 0; i < N_IN_URB; i++) { | 903 | for (i = 0; i < N_IN_URB; i++) { |
906 | urb = portdata->in_urbs[i]; | 904 | urb = portdata->in_urbs[i]; |
@@ -936,37 +934,43 @@ static int option_open(struct tty_struct *tty, | |||
936 | usb_pipeout(urb->pipe), 0); */ | 934 | usb_pipeout(urb->pipe), 0); */ |
937 | } | 935 | } |
938 | 936 | ||
939 | option_send_setup(tty, port); | 937 | option_send_setup(port); |
940 | 938 | ||
941 | return 0; | 939 | return 0; |
942 | } | 940 | } |
943 | 941 | ||
944 | static void option_close(struct tty_struct *tty, | 942 | static void option_dtr_rts(struct usb_serial_port *port, int on) |
945 | struct usb_serial_port *port, struct file *filp) | ||
946 | { | 943 | { |
947 | int i; | ||
948 | struct usb_serial *serial = port->serial; | 944 | struct usb_serial *serial = port->serial; |
949 | struct option_port_private *portdata; | 945 | struct option_port_private *portdata; |
950 | 946 | ||
951 | dbg("%s", __func__); | 947 | dbg("%s", __func__); |
952 | portdata = usb_get_serial_port_data(port); | 948 | portdata = usb_get_serial_port_data(port); |
949 | mutex_lock(&serial->disc_mutex); | ||
950 | portdata->rts_state = on; | ||
951 | portdata->dtr_state = on; | ||
952 | if (serial->dev) | ||
953 | option_send_setup(port); | ||
954 | mutex_unlock(&serial->disc_mutex); | ||
955 | } | ||
953 | 956 | ||
954 | portdata->rts_state = 0; | ||
955 | portdata->dtr_state = 0; | ||
956 | 957 | ||
957 | if (serial->dev) { | 958 | static void option_close(struct usb_serial_port *port) |
958 | mutex_lock(&serial->disc_mutex); | 959 | { |
959 | if (!serial->disconnected) | 960 | int i; |
960 | option_send_setup(tty, port); | 961 | struct usb_serial *serial = port->serial; |
961 | mutex_unlock(&serial->disc_mutex); | 962 | struct option_port_private *portdata; |
963 | |||
964 | dbg("%s", __func__); | ||
965 | portdata = usb_get_serial_port_data(port); | ||
962 | 966 | ||
967 | if (serial->dev) { | ||
963 | /* Stop reading/writing urbs */ | 968 | /* Stop reading/writing urbs */ |
964 | for (i = 0; i < N_IN_URB; i++) | 969 | for (i = 0; i < N_IN_URB; i++) |
965 | usb_kill_urb(portdata->in_urbs[i]); | 970 | usb_kill_urb(portdata->in_urbs[i]); |
966 | for (i = 0; i < N_OUT_URB; i++) | 971 | for (i = 0; i < N_OUT_URB; i++) |
967 | usb_kill_urb(portdata->out_urbs[i]); | 972 | usb_kill_urb(portdata->out_urbs[i]); |
968 | } | 973 | } |
969 | tty_port_tty_set(&port->port, NULL); | ||
970 | } | 974 | } |
971 | 975 | ||
972 | /* Helper functions used by option_setup_urbs */ | 976 | /* Helper functions used by option_setup_urbs */ |
@@ -1032,28 +1036,24 @@ static void option_setup_urbs(struct usb_serial *serial) | |||
1032 | * This is exactly the same as SET_CONTROL_LINE_STATE from the PSTN | 1036 | * This is exactly the same as SET_CONTROL_LINE_STATE from the PSTN |
1033 | * CDC. | 1037 | * CDC. |
1034 | */ | 1038 | */ |
1035 | static int option_send_setup(struct tty_struct *tty, | 1039 | static int option_send_setup(struct usb_serial_port *port) |
1036 | struct usb_serial_port *port) | ||
1037 | { | 1040 | { |
1038 | struct usb_serial *serial = port->serial; | 1041 | struct usb_serial *serial = port->serial; |
1039 | struct option_port_private *portdata; | 1042 | struct option_port_private *portdata; |
1040 | int ifNum = serial->interface->cur_altsetting->desc.bInterfaceNumber; | 1043 | int ifNum = serial->interface->cur_altsetting->desc.bInterfaceNumber; |
1044 | int val = 0; | ||
1041 | dbg("%s", __func__); | 1045 | dbg("%s", __func__); |
1042 | 1046 | ||
1043 | portdata = usb_get_serial_port_data(port); | 1047 | portdata = usb_get_serial_port_data(port); |
1044 | 1048 | ||
1045 | if (tty) { | 1049 | if (portdata->dtr_state) |
1046 | int val = 0; | 1050 | val |= 0x01; |
1047 | if (portdata->dtr_state) | 1051 | if (portdata->rts_state) |
1048 | val |= 0x01; | 1052 | val |= 0x02; |
1049 | if (portdata->rts_state) | ||
1050 | val |= 0x02; | ||
1051 | 1053 | ||
1052 | return usb_control_msg(serial->dev, | 1054 | return usb_control_msg(serial->dev, |
1053 | usb_rcvctrlpipe(serial->dev, 0), | 1055 | usb_rcvctrlpipe(serial->dev, 0), |
1054 | 0x22, 0x21, val, ifNum, NULL, 0, USB_CTRL_SET_TIMEOUT); | 1056 | 0x22, 0x21, val, ifNum, NULL, 0, USB_CTRL_SET_TIMEOUT); |
1055 | } | ||
1056 | return 0; | ||
1057 | } | 1057 | } |
1058 | 1058 | ||
1059 | static int option_startup(struct usb_serial *serial) | 1059 | static int option_startup(struct usb_serial *serial) |
diff --git a/drivers/usb/serial/oti6858.c b/drivers/usb/serial/oti6858.c index ba551f00f16f..7de54781fe61 100644 --- a/drivers/usb/serial/oti6858.c +++ b/drivers/usb/serial/oti6858.c | |||
@@ -143,8 +143,7 @@ struct oti6858_control_pkt { | |||
143 | /* function prototypes */ | 143 | /* function prototypes */ |
144 | static int oti6858_open(struct tty_struct *tty, | 144 | static int oti6858_open(struct tty_struct *tty, |
145 | struct usb_serial_port *port, struct file *filp); | 145 | struct usb_serial_port *port, struct file *filp); |
146 | static void oti6858_close(struct tty_struct *tty, | 146 | static void oti6858_close(struct usb_serial_port *port); |
147 | struct usb_serial_port *port, struct file *filp); | ||
148 | static void oti6858_set_termios(struct tty_struct *tty, | 147 | static void oti6858_set_termios(struct tty_struct *tty, |
149 | struct usb_serial_port *port, struct ktermios *old); | 148 | struct usb_serial_port *port, struct ktermios *old); |
150 | static int oti6858_ioctl(struct tty_struct *tty, struct file *file, | 149 | static int oti6858_ioctl(struct tty_struct *tty, struct file *file, |
@@ -622,67 +621,30 @@ static int oti6858_open(struct tty_struct *tty, | |||
622 | if (result != 0) { | 621 | if (result != 0) { |
623 | dev_err(&port->dev, "%s(): usb_submit_urb() failed" | 622 | dev_err(&port->dev, "%s(): usb_submit_urb() failed" |
624 | " with error %d\n", __func__, result); | 623 | " with error %d\n", __func__, result); |
625 | oti6858_close(tty, port, NULL); | 624 | oti6858_close(port); |
626 | return -EPROTO; | 625 | return -EPROTO; |
627 | } | 626 | } |
628 | 627 | ||
629 | /* setup termios */ | 628 | /* setup termios */ |
630 | if (tty) | 629 | if (tty) |
631 | oti6858_set_termios(tty, port, &tmp_termios); | 630 | oti6858_set_termios(tty, port, &tmp_termios); |
632 | 631 | port->port.drain_delay = 256; /* FIXME: check the FIFO length */ | |
633 | return 0; | 632 | return 0; |
634 | } | 633 | } |
635 | 634 | ||
636 | static void oti6858_close(struct tty_struct *tty, | 635 | static void oti6858_close(struct usb_serial_port *port) |
637 | struct usb_serial_port *port, struct file *filp) | ||
638 | { | 636 | { |
639 | struct oti6858_private *priv = usb_get_serial_port_data(port); | 637 | struct oti6858_private *priv = usb_get_serial_port_data(port); |
640 | unsigned long flags; | 638 | unsigned long flags; |
641 | long timeout; | ||
642 | wait_queue_t wait; | ||
643 | 639 | ||
644 | dbg("%s(port = %d)", __func__, port->number); | 640 | dbg("%s(port = %d)", __func__, port->number); |
645 | 641 | ||
646 | /* wait for data to drain from the buffer */ | ||
647 | spin_lock_irqsave(&priv->lock, flags); | 642 | spin_lock_irqsave(&priv->lock, flags); |
648 | timeout = 30 * HZ; /* PL2303_CLOSING_WAIT */ | ||
649 | init_waitqueue_entry(&wait, current); | ||
650 | add_wait_queue(&tty->write_wait, &wait); | ||
651 | dbg("%s(): entering wait loop", __func__); | ||
652 | for (;;) { | ||
653 | set_current_state(TASK_INTERRUPTIBLE); | ||
654 | if (oti6858_buf_data_avail(priv->buf) == 0 | ||
655 | || timeout == 0 || signal_pending(current) | ||
656 | || port->serial->disconnected) | ||
657 | break; | ||
658 | spin_unlock_irqrestore(&priv->lock, flags); | ||
659 | timeout = schedule_timeout(timeout); | ||
660 | spin_lock_irqsave(&priv->lock, flags); | ||
661 | } | ||
662 | set_current_state(TASK_RUNNING); | ||
663 | remove_wait_queue(&tty->write_wait, &wait); | ||
664 | dbg("%s(): after wait loop", __func__); | ||
665 | |||
666 | /* clear out any remaining data in the buffer */ | 643 | /* clear out any remaining data in the buffer */ |
667 | oti6858_buf_clear(priv->buf); | 644 | oti6858_buf_clear(priv->buf); |
668 | spin_unlock_irqrestore(&priv->lock, flags); | 645 | spin_unlock_irqrestore(&priv->lock, flags); |
669 | 646 | ||
670 | /* wait for characters to drain from the device */ | 647 | dbg("%s(): after buf_clear()", __func__); |
671 | /* (this is long enough for the entire 256 byte */ | ||
672 | /* pl2303 hardware buffer to drain with no flow */ | ||
673 | /* control for data rates of 1200 bps or more, */ | ||
674 | /* for lower rates we should really know how much */ | ||
675 | /* data is in the buffer to compute a delay */ | ||
676 | /* that is not unnecessarily long) */ | ||
677 | /* FIXME | ||
678 | bps = tty_get_baud_rate(tty); | ||
679 | if (bps > 1200) | ||
680 | timeout = max((HZ*2560)/bps,HZ/10); | ||
681 | else | ||
682 | */ | ||
683 | timeout = 2*HZ; | ||
684 | schedule_timeout_interruptible(timeout); | ||
685 | dbg("%s(): after schedule_timeout_interruptible()", __func__); | ||
686 | 648 | ||
687 | /* cancel scheduled setup */ | 649 | /* cancel scheduled setup */ |
688 | cancel_delayed_work(&priv->delayed_setup_work); | 650 | cancel_delayed_work(&priv->delayed_setup_work); |
@@ -694,15 +656,6 @@ static void oti6858_close(struct tty_struct *tty, | |||
694 | usb_kill_urb(port->write_urb); | 656 | usb_kill_urb(port->write_urb); |
695 | usb_kill_urb(port->read_urb); | 657 | usb_kill_urb(port->read_urb); |
696 | usb_kill_urb(port->interrupt_in_urb); | 658 | usb_kill_urb(port->interrupt_in_urb); |
697 | |||
698 | /* | ||
699 | if (tty && (tty->termios->c_cflag) & HUPCL) { | ||
700 | // drop DTR and RTS | ||
701 | spin_lock_irqsave(&priv->lock, flags); | ||
702 | priv->pending_setup.control &= ~CONTROL_MASK; | ||
703 | spin_unlock_irqrestore(&priv->lock, flags); | ||
704 | } | ||
705 | */ | ||
706 | } | 659 | } |
707 | 660 | ||
708 | static int oti6858_tiocmset(struct tty_struct *tty, struct file *file, | 661 | static int oti6858_tiocmset(struct tty_struct *tty, struct file *file, |
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c index 751a533a4347..e02dc3d643c7 100644 --- a/drivers/usb/serial/pl2303.c +++ b/drivers/usb/serial/pl2303.c | |||
@@ -652,69 +652,41 @@ static void pl2303_set_termios(struct tty_struct *tty, | |||
652 | kfree(buf); | 652 | kfree(buf); |
653 | } | 653 | } |
654 | 654 | ||
655 | static void pl2303_close(struct tty_struct *tty, | 655 | static void pl2303_dtr_rts(struct usb_serial_port *port, int on) |
656 | struct usb_serial_port *port, struct file *filp) | 656 | { |
657 | struct pl2303_private *priv = usb_get_serial_port_data(port); | ||
658 | unsigned long flags; | ||
659 | u8 control; | ||
660 | |||
661 | spin_lock_irqsave(&priv->lock, flags); | ||
662 | /* Change DTR and RTS */ | ||
663 | if (on) | ||
664 | priv->line_control |= (CONTROL_DTR | CONTROL_RTS); | ||
665 | else | ||
666 | priv->line_control &= ~(CONTROL_DTR | CONTROL_RTS); | ||
667 | control = priv->line_control; | ||
668 | spin_unlock_irqrestore(&priv->lock, flags); | ||
669 | set_control_lines(port->serial->dev, control); | ||
670 | } | ||
671 | |||
672 | static void pl2303_close(struct usb_serial_port *port) | ||
657 | { | 673 | { |
658 | struct pl2303_private *priv = usb_get_serial_port_data(port); | 674 | struct pl2303_private *priv = usb_get_serial_port_data(port); |
659 | unsigned long flags; | 675 | unsigned long flags; |
660 | unsigned int c_cflag; | ||
661 | int bps; | ||
662 | long timeout; | ||
663 | wait_queue_t wait; | ||
664 | 676 | ||
665 | dbg("%s - port %d", __func__, port->number); | 677 | dbg("%s - port %d", __func__, port->number); |
666 | 678 | ||
667 | /* wait for data to drain from the buffer */ | ||
668 | spin_lock_irqsave(&priv->lock, flags); | 679 | spin_lock_irqsave(&priv->lock, flags); |
669 | timeout = PL2303_CLOSING_WAIT; | ||
670 | init_waitqueue_entry(&wait, current); | ||
671 | add_wait_queue(&tty->write_wait, &wait); | ||
672 | for (;;) { | ||
673 | set_current_state(TASK_INTERRUPTIBLE); | ||
674 | if (pl2303_buf_data_avail(priv->buf) == 0 || | ||
675 | timeout == 0 || signal_pending(current) || | ||
676 | port->serial->disconnected) | ||
677 | break; | ||
678 | spin_unlock_irqrestore(&priv->lock, flags); | ||
679 | timeout = schedule_timeout(timeout); | ||
680 | spin_lock_irqsave(&priv->lock, flags); | ||
681 | } | ||
682 | set_current_state(TASK_RUNNING); | ||
683 | remove_wait_queue(&tty->write_wait, &wait); | ||
684 | /* clear out any remaining data in the buffer */ | 680 | /* clear out any remaining data in the buffer */ |
685 | pl2303_buf_clear(priv->buf); | 681 | pl2303_buf_clear(priv->buf); |
686 | spin_unlock_irqrestore(&priv->lock, flags); | 682 | spin_unlock_irqrestore(&priv->lock, flags); |
687 | 683 | ||
688 | /* wait for characters to drain from the device */ | ||
689 | /* (this is long enough for the entire 256 byte */ | ||
690 | /* pl2303 hardware buffer to drain with no flow */ | ||
691 | /* control for data rates of 1200 bps or more, */ | ||
692 | /* for lower rates we should really know how much */ | ||
693 | /* data is in the buffer to compute a delay */ | ||
694 | /* that is not unnecessarily long) */ | ||
695 | bps = tty_get_baud_rate(tty); | ||
696 | if (bps > 1200) | ||
697 | timeout = max((HZ*2560)/bps, HZ/10); | ||
698 | else | ||
699 | timeout = 2*HZ; | ||
700 | schedule_timeout_interruptible(timeout); | ||
701 | |||
702 | /* shutdown our urbs */ | 684 | /* shutdown our urbs */ |
703 | dbg("%s - shutting down urbs", __func__); | 685 | dbg("%s - shutting down urbs", __func__); |
704 | usb_kill_urb(port->write_urb); | 686 | usb_kill_urb(port->write_urb); |
705 | usb_kill_urb(port->read_urb); | 687 | usb_kill_urb(port->read_urb); |
706 | usb_kill_urb(port->interrupt_in_urb); | 688 | usb_kill_urb(port->interrupt_in_urb); |
707 | 689 | ||
708 | if (tty) { | ||
709 | c_cflag = tty->termios->c_cflag; | ||
710 | if (c_cflag & HUPCL) { | ||
711 | /* drop DTR and RTS */ | ||
712 | spin_lock_irqsave(&priv->lock, flags); | ||
713 | priv->line_control = 0; | ||
714 | spin_unlock_irqrestore(&priv->lock, flags); | ||
715 | set_control_lines(port->serial->dev, 0); | ||
716 | } | ||
717 | } | ||
718 | } | 690 | } |
719 | 691 | ||
720 | static int pl2303_open(struct tty_struct *tty, | 692 | static int pl2303_open(struct tty_struct *tty, |
@@ -748,7 +720,7 @@ static int pl2303_open(struct tty_struct *tty, | |||
748 | if (result) { | 720 | if (result) { |
749 | dev_err(&port->dev, "%s - failed submitting read urb," | 721 | dev_err(&port->dev, "%s - failed submitting read urb," |
750 | " error %d\n", __func__, result); | 722 | " error %d\n", __func__, result); |
751 | pl2303_close(tty, port, NULL); | 723 | pl2303_close(port); |
752 | return -EPROTO; | 724 | return -EPROTO; |
753 | } | 725 | } |
754 | 726 | ||
@@ -758,9 +730,10 @@ static int pl2303_open(struct tty_struct *tty, | |||
758 | if (result) { | 730 | if (result) { |
759 | dev_err(&port->dev, "%s - failed submitting interrupt urb," | 731 | dev_err(&port->dev, "%s - failed submitting interrupt urb," |
760 | " error %d\n", __func__, result); | 732 | " error %d\n", __func__, result); |
761 | pl2303_close(tty, port, NULL); | 733 | pl2303_close(port); |
762 | return -EPROTO; | 734 | return -EPROTO; |
763 | } | 735 | } |
736 | port->port.drain_delay = 256; | ||
764 | return 0; | 737 | return 0; |
765 | } | 738 | } |
766 | 739 | ||
@@ -821,6 +794,14 @@ static int pl2303_tiocmget(struct tty_struct *tty, struct file *file) | |||
821 | return result; | 794 | return result; |
822 | } | 795 | } |
823 | 796 | ||
797 | static int pl2303_carrier_raised(struct usb_serial_port *port) | ||
798 | { | ||
799 | struct pl2303_private *priv = usb_get_serial_port_data(port); | ||
800 | if (priv->line_status & UART_DCD) | ||
801 | return 1; | ||
802 | return 0; | ||
803 | } | ||
804 | |||
824 | static int wait_modem_info(struct usb_serial_port *port, unsigned int arg) | 805 | static int wait_modem_info(struct usb_serial_port *port, unsigned int arg) |
825 | { | 806 | { |
826 | struct pl2303_private *priv = usb_get_serial_port_data(port); | 807 | struct pl2303_private *priv = usb_get_serial_port_data(port); |
@@ -1125,6 +1106,8 @@ static struct usb_serial_driver pl2303_device = { | |||
1125 | .num_ports = 1, | 1106 | .num_ports = 1, |
1126 | .open = pl2303_open, | 1107 | .open = pl2303_open, |
1127 | .close = pl2303_close, | 1108 | .close = pl2303_close, |
1109 | .dtr_rts = pl2303_dtr_rts, | ||
1110 | .carrier_raised = pl2303_carrier_raised, | ||
1128 | .write = pl2303_write, | 1111 | .write = pl2303_write, |
1129 | .ioctl = pl2303_ioctl, | 1112 | .ioctl = pl2303_ioctl, |
1130 | .break_ctl = pl2303_break_ctl, | 1113 | .break_ctl = pl2303_break_ctl, |
diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c index 913225c61610..17ac34f4d668 100644 --- a/drivers/usb/serial/sierra.c +++ b/drivers/usb/serial/sierra.c | |||
@@ -26,12 +26,10 @@ | |||
26 | #include <linux/module.h> | 26 | #include <linux/module.h> |
27 | #include <linux/usb.h> | 27 | #include <linux/usb.h> |
28 | #include <linux/usb/serial.h> | 28 | #include <linux/usb/serial.h> |
29 | #include <linux/usb/ch9.h> | ||
30 | 29 | ||
31 | #define SWIMS_USB_REQUEST_SetPower 0x00 | 30 | #define SWIMS_USB_REQUEST_SetPower 0x00 |
32 | #define SWIMS_USB_REQUEST_SetNmea 0x07 | 31 | #define SWIMS_USB_REQUEST_SetNmea 0x07 |
33 | 32 | ||
34 | /* per port private data */ | ||
35 | #define N_IN_URB 4 | 33 | #define N_IN_URB 4 |
36 | #define N_OUT_URB 4 | 34 | #define N_OUT_URB 4 |
37 | #define IN_BUFLEN 4096 | 35 | #define IN_BUFLEN 4096 |
@@ -39,6 +37,12 @@ | |||
39 | static int debug; | 37 | static int debug; |
40 | static int nmea; | 38 | static int nmea; |
41 | 39 | ||
40 | /* Used in interface blacklisting */ | ||
41 | struct sierra_iface_info { | ||
42 | const u32 infolen; /* number of interface numbers on blacklist */ | ||
43 | const u8 *ifaceinfo; /* pointer to the array holding the numbers */ | ||
44 | }; | ||
45 | |||
42 | static int sierra_set_power_state(struct usb_device *udev, __u16 swiState) | 46 | static int sierra_set_power_state(struct usb_device *udev, __u16 swiState) |
43 | { | 47 | { |
44 | int result; | 48 | int result; |
@@ -85,6 +89,23 @@ static int sierra_calc_num_ports(struct usb_serial *serial) | |||
85 | return result; | 89 | return result; |
86 | } | 90 | } |
87 | 91 | ||
92 | static int is_blacklisted(const u8 ifnum, | ||
93 | const struct sierra_iface_info *blacklist) | ||
94 | { | ||
95 | const u8 *info; | ||
96 | int i; | ||
97 | |||
98 | if (blacklist) { | ||
99 | info = blacklist->ifaceinfo; | ||
100 | |||
101 | for (i = 0; i < blacklist->infolen; i++) { | ||
102 | if (info[i] == ifnum) | ||
103 | return 1; | ||
104 | } | ||
105 | } | ||
106 | return 0; | ||
107 | } | ||
108 | |||
88 | static int sierra_calc_interface(struct usb_serial *serial) | 109 | static int sierra_calc_interface(struct usb_serial *serial) |
89 | { | 110 | { |
90 | int interface; | 111 | int interface; |
@@ -153,9 +174,25 @@ static int sierra_probe(struct usb_serial *serial, | |||
153 | */ | 174 | */ |
154 | usb_set_serial_data(serial, (void *)num_ports); | 175 | usb_set_serial_data(serial, (void *)num_ports); |
155 | 176 | ||
177 | /* ifnum could have changed - by calling usb_set_interface */ | ||
178 | ifnum = sierra_calc_interface(serial); | ||
179 | |||
180 | if (is_blacklisted(ifnum, | ||
181 | (struct sierra_iface_info *)id->driver_info)) { | ||
182 | dev_dbg(&serial->dev->dev, | ||
183 | "Ignoring blacklisted interface #%d\n", ifnum); | ||
184 | return -ENODEV; | ||
185 | } | ||
186 | |||
156 | return result; | 187 | return result; |
157 | } | 188 | } |
158 | 189 | ||
190 | static const u8 direct_ip_non_serial_ifaces[] = { 7, 8, 9, 10, 11 }; | ||
191 | static const struct sierra_iface_info direct_ip_interface_blacklist = { | ||
192 | .infolen = ARRAY_SIZE(direct_ip_non_serial_ifaces), | ||
193 | .ifaceinfo = direct_ip_non_serial_ifaces, | ||
194 | }; | ||
195 | |||
159 | static struct usb_device_id id_table [] = { | 196 | static struct usb_device_id id_table [] = { |
160 | { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */ | 197 | { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */ |
161 | { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */ | 198 | { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */ |
@@ -188,9 +225,11 @@ static struct usb_device_id id_table [] = { | |||
188 | { USB_DEVICE(0x1199, 0x6833) }, /* Sierra Wireless MC8781 */ | 225 | { USB_DEVICE(0x1199, 0x6833) }, /* Sierra Wireless MC8781 */ |
189 | { USB_DEVICE(0x1199, 0x683A) }, /* Sierra Wireless MC8785 */ | 226 | { USB_DEVICE(0x1199, 0x683A) }, /* Sierra Wireless MC8785 */ |
190 | { USB_DEVICE(0x1199, 0x683B) }, /* Sierra Wireless MC8785 Composite */ | 227 | { USB_DEVICE(0x1199, 0x683B) }, /* Sierra Wireless MC8785 Composite */ |
191 | { USB_DEVICE(0x1199, 0x683C) }, /* Sierra Wireless MC8790 */ | 228 | /* Sierra Wireless MC8790, MC8791, MC8792 Composite */ |
192 | { USB_DEVICE(0x1199, 0x683D) }, /* Sierra Wireless MC8790 */ | 229 | { USB_DEVICE(0x1199, 0x683C) }, |
193 | { USB_DEVICE(0x1199, 0x683E) }, /* Sierra Wireless MC8790 */ | 230 | { USB_DEVICE(0x1199, 0x683D) }, /* Sierra Wireless MC8791 Composite */ |
231 | /* Sierra Wireless MC8790, MC8791, MC8792 */ | ||
232 | { USB_DEVICE(0x1199, 0x683E) }, | ||
194 | { USB_DEVICE(0x1199, 0x6850) }, /* Sierra Wireless AirCard 880 */ | 233 | { USB_DEVICE(0x1199, 0x6850) }, /* Sierra Wireless AirCard 880 */ |
195 | { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */ | 234 | { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */ |
196 | { USB_DEVICE(0x1199, 0x6852) }, /* Sierra Wireless AirCard 880 E */ | 235 | { USB_DEVICE(0x1199, 0x6852) }, /* Sierra Wireless AirCard 880 E */ |
@@ -211,6 +250,10 @@ static struct usb_device_id id_table [] = { | |||
211 | { USB_DEVICE(0x1199, 0x0112) }, /* Sierra Wireless AirCard 580 */ | 250 | { USB_DEVICE(0x1199, 0x0112) }, /* Sierra Wireless AirCard 580 */ |
212 | { USB_DEVICE(0x0F3D, 0x0112) }, /* Airprime/Sierra PC 5220 */ | 251 | { USB_DEVICE(0x0F3D, 0x0112) }, /* Airprime/Sierra PC 5220 */ |
213 | 252 | ||
253 | { USB_DEVICE(0x1199, 0x68A3), /* Sierra Wireless Direct IP modems */ | ||
254 | .driver_info = (kernel_ulong_t)&direct_ip_interface_blacklist | ||
255 | }, | ||
256 | |||
214 | { } | 257 | { } |
215 | }; | 258 | }; |
216 | MODULE_DEVICE_TABLE(usb, id_table); | 259 | MODULE_DEVICE_TABLE(usb, id_table); |
@@ -229,7 +272,6 @@ struct sierra_port_private { | |||
229 | 272 | ||
230 | /* Input endpoints and buffers for this port */ | 273 | /* Input endpoints and buffers for this port */ |
231 | struct urb *in_urbs[N_IN_URB]; | 274 | struct urb *in_urbs[N_IN_URB]; |
232 | char *in_buffer[N_IN_URB]; | ||
233 | 275 | ||
234 | /* Settings for the port */ | 276 | /* Settings for the port */ |
235 | int rts_state; /* Handshaking pins (outputs) */ | 277 | int rts_state; /* Handshaking pins (outputs) */ |
@@ -240,57 +282,50 @@ struct sierra_port_private { | |||
240 | int ri_state; | 282 | int ri_state; |
241 | }; | 283 | }; |
242 | 284 | ||
243 | static int sierra_send_setup(struct tty_struct *tty, | 285 | static int sierra_send_setup(struct usb_serial_port *port) |
244 | struct usb_serial_port *port) | ||
245 | { | 286 | { |
246 | struct usb_serial *serial = port->serial; | 287 | struct usb_serial *serial = port->serial; |
247 | struct sierra_port_private *portdata; | 288 | struct sierra_port_private *portdata; |
248 | __u16 interface = 0; | 289 | __u16 interface = 0; |
290 | int val = 0; | ||
249 | 291 | ||
250 | dev_dbg(&port->dev, "%s", __func__); | 292 | dev_dbg(&port->dev, "%s", __func__); |
251 | 293 | ||
252 | portdata = usb_get_serial_port_data(port); | 294 | portdata = usb_get_serial_port_data(port); |
253 | 295 | ||
254 | if (tty) { | 296 | if (portdata->dtr_state) |
255 | int val = 0; | 297 | val |= 0x01; |
256 | if (portdata->dtr_state) | 298 | if (portdata->rts_state) |
257 | val |= 0x01; | 299 | val |= 0x02; |
258 | if (portdata->rts_state) | ||
259 | val |= 0x02; | ||
260 | |||
261 | /* If composite device then properly report interface */ | ||
262 | if (serial->num_ports == 1) { | ||
263 | interface = sierra_calc_interface(serial); | ||
264 | |||
265 | /* Control message is sent only to interfaces with | ||
266 | * interrupt_in endpoints | ||
267 | */ | ||
268 | if (port->interrupt_in_urb) { | ||
269 | /* send control message */ | ||
270 | return usb_control_msg(serial->dev, | ||
271 | usb_rcvctrlpipe(serial->dev, 0), | ||
272 | 0x22, 0x21, val, interface, | ||
273 | NULL, 0, USB_CTRL_SET_TIMEOUT); | ||
274 | } | ||
275 | } | ||
276 | |||
277 | /* Otherwise the need to do non-composite mapping */ | ||
278 | else { | ||
279 | if (port->bulk_out_endpointAddress == 2) | ||
280 | interface = 0; | ||
281 | else if (port->bulk_out_endpointAddress == 4) | ||
282 | interface = 1; | ||
283 | else if (port->bulk_out_endpointAddress == 5) | ||
284 | interface = 2; | ||
285 | 300 | ||
301 | /* If composite device then properly report interface */ | ||
302 | if (serial->num_ports == 1) { | ||
303 | interface = sierra_calc_interface(serial); | ||
304 | /* Control message is sent only to interfaces with | ||
305 | * interrupt_in endpoints | ||
306 | */ | ||
307 | if (port->interrupt_in_urb) { | ||
308 | /* send control message */ | ||
286 | return usb_control_msg(serial->dev, | 309 | return usb_control_msg(serial->dev, |
287 | usb_rcvctrlpipe(serial->dev, 0), | 310 | usb_rcvctrlpipe(serial->dev, 0), |
288 | 0x22, 0x21, val, interface, | 311 | 0x22, 0x21, val, interface, |
289 | NULL, 0, USB_CTRL_SET_TIMEOUT); | 312 | NULL, 0, USB_CTRL_SET_TIMEOUT); |
290 | |||
291 | } | 313 | } |
292 | } | 314 | } |
293 | 315 | ||
316 | /* Otherwise the need to do non-composite mapping */ | ||
317 | else { | ||
318 | if (port->bulk_out_endpointAddress == 2) | ||
319 | interface = 0; | ||
320 | else if (port->bulk_out_endpointAddress == 4) | ||
321 | interface = 1; | ||
322 | else if (port->bulk_out_endpointAddress == 5) | ||
323 | interface = 2; | ||
324 | return usb_control_msg(serial->dev, | ||
325 | usb_rcvctrlpipe(serial->dev, 0), | ||
326 | 0x22, 0x21, val, interface, | ||
327 | NULL, 0, USB_CTRL_SET_TIMEOUT); | ||
328 | } | ||
294 | return 0; | 329 | return 0; |
295 | } | 330 | } |
296 | 331 | ||
@@ -299,7 +334,7 @@ static void sierra_set_termios(struct tty_struct *tty, | |||
299 | { | 334 | { |
300 | dev_dbg(&port->dev, "%s", __func__); | 335 | dev_dbg(&port->dev, "%s", __func__); |
301 | tty_termios_copy_hw(tty->termios, old_termios); | 336 | tty_termios_copy_hw(tty->termios, old_termios); |
302 | sierra_send_setup(tty, port); | 337 | sierra_send_setup(port); |
303 | } | 338 | } |
304 | 339 | ||
305 | static int sierra_tiocmget(struct tty_struct *tty, struct file *file) | 340 | static int sierra_tiocmget(struct tty_struct *tty, struct file *file) |
@@ -338,7 +373,18 @@ static int sierra_tiocmset(struct tty_struct *tty, struct file *file, | |||
338 | portdata->rts_state = 0; | 373 | portdata->rts_state = 0; |
339 | if (clear & TIOCM_DTR) | 374 | if (clear & TIOCM_DTR) |
340 | portdata->dtr_state = 0; | 375 | portdata->dtr_state = 0; |
341 | return sierra_send_setup(tty, port); | 376 | return sierra_send_setup(port); |
377 | } | ||
378 | |||
379 | static void sierra_release_urb(struct urb *urb) | ||
380 | { | ||
381 | struct usb_serial_port *port; | ||
382 | if (urb) { | ||
383 | port = urb->context; | ||
384 | dev_dbg(&port->dev, "%s: %p\n", __func__, urb); | ||
385 | kfree(urb->transfer_buffer); | ||
386 | usb_free_urb(urb); | ||
387 | } | ||
342 | } | 388 | } |
343 | 389 | ||
344 | static void sierra_outdat_callback(struct urb *urb) | 390 | static void sierra_outdat_callback(struct urb *urb) |
@@ -465,7 +511,7 @@ static void sierra_indat_callback(struct urb *urb) | |||
465 | " received", __func__); | 511 | " received", __func__); |
466 | 512 | ||
467 | /* Resubmit urb so we continue receiving */ | 513 | /* Resubmit urb so we continue receiving */ |
468 | if (port->port.count && status != -ESHUTDOWN) { | 514 | if (port->port.count && status != -ESHUTDOWN && status != -EPERM) { |
469 | err = usb_submit_urb(urb, GFP_ATOMIC); | 515 | err = usb_submit_urb(urb, GFP_ATOMIC); |
470 | if (err) | 516 | if (err) |
471 | dev_err(&port->dev, "resubmit read urb failed." | 517 | dev_err(&port->dev, "resubmit read urb failed." |
@@ -557,67 +603,99 @@ static int sierra_write_room(struct tty_struct *tty) | |||
557 | return 2048; | 603 | return 2048; |
558 | } | 604 | } |
559 | 605 | ||
560 | static int sierra_open(struct tty_struct *tty, | 606 | static void sierra_stop_rx_urbs(struct usb_serial_port *port) |
561 | struct usb_serial_port *port, struct file *filp) | ||
562 | { | 607 | { |
563 | struct sierra_port_private *portdata; | ||
564 | struct usb_serial *serial = port->serial; | ||
565 | int i; | 608 | int i; |
566 | struct urb *urb; | 609 | struct sierra_port_private *portdata = usb_get_serial_port_data(port); |
567 | int result; | ||
568 | 610 | ||
569 | portdata = usb_get_serial_port_data(port); | 611 | for (i = 0; i < ARRAY_SIZE(portdata->in_urbs); i++) |
612 | usb_kill_urb(portdata->in_urbs[i]); | ||
570 | 613 | ||
571 | dev_dbg(&port->dev, "%s", __func__); | 614 | usb_kill_urb(port->interrupt_in_urb); |
615 | } | ||
572 | 616 | ||
573 | /* Set some sane defaults */ | 617 | static int sierra_submit_rx_urbs(struct usb_serial_port *port, gfp_t mem_flags) |
574 | portdata->rts_state = 1; | 618 | { |
575 | portdata->dtr_state = 1; | 619 | int ok_cnt; |
620 | int err = -EINVAL; | ||
621 | int i; | ||
622 | struct urb *urb; | ||
623 | struct sierra_port_private *portdata = usb_get_serial_port_data(port); | ||
576 | 624 | ||
577 | /* Reset low level data toggle and start reading from endpoints */ | 625 | ok_cnt = 0; |
578 | for (i = 0; i < N_IN_URB; i++) { | 626 | for (i = 0; i < ARRAY_SIZE(portdata->in_urbs); i++) { |
579 | urb = portdata->in_urbs[i]; | 627 | urb = portdata->in_urbs[i]; |
580 | if (!urb) | 628 | if (!urb) |
581 | continue; | 629 | continue; |
582 | if (urb->dev != serial->dev) { | 630 | err = usb_submit_urb(urb, mem_flags); |
583 | dev_dbg(&port->dev, "%s: dev %p != %p", | 631 | if (err) { |
584 | __func__, urb->dev, serial->dev); | 632 | dev_err(&port->dev, "%s: submit urb failed: %d\n", |
585 | continue; | 633 | __func__, err); |
634 | } else { | ||
635 | ok_cnt++; | ||
586 | } | 636 | } |
637 | } | ||
587 | 638 | ||
588 | /* | 639 | if (ok_cnt && port->interrupt_in_urb) { |
589 | * make sure endpoint data toggle is synchronized with the | 640 | err = usb_submit_urb(port->interrupt_in_urb, mem_flags); |
590 | * device | 641 | if (err) { |
591 | */ | 642 | dev_err(&port->dev, "%s: submit intr urb failed: %d\n", |
592 | usb_clear_halt(urb->dev, urb->pipe); | 643 | __func__, err); |
593 | |||
594 | result = usb_submit_urb(urb, GFP_KERNEL); | ||
595 | if (result) { | ||
596 | dev_err(&port->dev, "submit urb %d failed (%d) %d\n", | ||
597 | i, result, urb->transfer_buffer_length); | ||
598 | } | 644 | } |
599 | } | 645 | } |
600 | 646 | ||
601 | sierra_send_setup(tty, port); | 647 | if (ok_cnt > 0) /* at least one rx urb submitted */ |
648 | return 0; | ||
649 | else | ||
650 | return err; | ||
651 | } | ||
652 | |||
653 | static struct urb *sierra_setup_urb(struct usb_serial *serial, int endpoint, | ||
654 | int dir, void *ctx, int len, | ||
655 | gfp_t mem_flags, | ||
656 | usb_complete_t callback) | ||
657 | { | ||
658 | struct urb *urb; | ||
659 | u8 *buf; | ||
660 | |||
661 | if (endpoint == -1) | ||
662 | return NULL; | ||
602 | 663 | ||
603 | /* start up the interrupt endpoint if we have one */ | 664 | urb = usb_alloc_urb(0, mem_flags); |
604 | if (port->interrupt_in_urb) { | 665 | if (urb == NULL) { |
605 | result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); | 666 | dev_dbg(&serial->dev->dev, "%s: alloc for endpoint %d failed\n", |
606 | if (result) | 667 | __func__, endpoint); |
607 | dev_err(&port->dev, "submit irq_in urb failed %d\n", | 668 | return NULL; |
608 | result); | ||
609 | } | 669 | } |
610 | return 0; | 670 | |
671 | buf = kmalloc(len, mem_flags); | ||
672 | if (buf) { | ||
673 | /* Fill URB using supplied data */ | ||
674 | usb_fill_bulk_urb(urb, serial->dev, | ||
675 | usb_sndbulkpipe(serial->dev, endpoint) | dir, | ||
676 | buf, len, callback, ctx); | ||
677 | |||
678 | /* debug */ | ||
679 | dev_dbg(&serial->dev->dev, "%s %c u : %p d:%p\n", __func__, | ||
680 | dir == USB_DIR_IN ? 'i' : 'o', urb, buf); | ||
681 | } else { | ||
682 | dev_dbg(&serial->dev->dev, "%s %c u:%p d:%p\n", __func__, | ||
683 | dir == USB_DIR_IN ? 'i' : 'o', urb, buf); | ||
684 | |||
685 | sierra_release_urb(urb); | ||
686 | urb = NULL; | ||
687 | } | ||
688 | |||
689 | return urb; | ||
611 | } | 690 | } |
612 | 691 | ||
613 | static void sierra_close(struct tty_struct *tty, | 692 | static void sierra_close(struct usb_serial_port *port) |
614 | struct usb_serial_port *port, struct file *filp) | ||
615 | { | 693 | { |
616 | int i; | 694 | int i; |
617 | struct usb_serial *serial = port->serial; | 695 | struct usb_serial *serial = port->serial; |
618 | struct sierra_port_private *portdata; | 696 | struct sierra_port_private *portdata; |
619 | 697 | ||
620 | dev_dbg(&port->dev, "%s", __func__); | 698 | dev_dbg(&port->dev, "%s\n", __func__); |
621 | portdata = usb_get_serial_port_data(port); | 699 | portdata = usb_get_serial_port_data(port); |
622 | 700 | ||
623 | portdata->rts_state = 0; | 701 | portdata->rts_state = 0; |
@@ -626,25 +704,83 @@ static void sierra_close(struct tty_struct *tty, | |||
626 | if (serial->dev) { | 704 | if (serial->dev) { |
627 | mutex_lock(&serial->disc_mutex); | 705 | mutex_lock(&serial->disc_mutex); |
628 | if (!serial->disconnected) | 706 | if (!serial->disconnected) |
629 | sierra_send_setup(tty, port); | 707 | sierra_send_setup(port); |
630 | mutex_unlock(&serial->disc_mutex); | 708 | mutex_unlock(&serial->disc_mutex); |
631 | 709 | ||
632 | /* Stop reading/writing urbs */ | 710 | /* Stop reading urbs */ |
633 | for (i = 0; i < N_IN_URB; i++) | 711 | sierra_stop_rx_urbs(port); |
634 | usb_kill_urb(portdata->in_urbs[i]); | 712 | /* .. and release them */ |
713 | for (i = 0; i < N_IN_URB; i++) { | ||
714 | sierra_release_urb(portdata->in_urbs[i]); | ||
715 | portdata->in_urbs[i] = NULL; | ||
716 | } | ||
635 | } | 717 | } |
718 | } | ||
636 | 719 | ||
637 | usb_kill_urb(port->interrupt_in_urb); | 720 | static int sierra_open(struct tty_struct *tty, |
638 | tty_port_tty_set(&port->port, NULL); | 721 | struct usb_serial_port *port, struct file *filp) |
722 | { | ||
723 | struct sierra_port_private *portdata; | ||
724 | struct usb_serial *serial = port->serial; | ||
725 | int i; | ||
726 | int err; | ||
727 | int endpoint; | ||
728 | struct urb *urb; | ||
729 | |||
730 | portdata = usb_get_serial_port_data(port); | ||
731 | |||
732 | dev_dbg(&port->dev, "%s", __func__); | ||
733 | |||
734 | /* Set some sane defaults */ | ||
735 | portdata->rts_state = 1; | ||
736 | portdata->dtr_state = 1; | ||
737 | |||
738 | |||
739 | endpoint = port->bulk_in_endpointAddress; | ||
740 | for (i = 0; i < ARRAY_SIZE(portdata->in_urbs); i++) { | ||
741 | urb = sierra_setup_urb(serial, endpoint, USB_DIR_IN, port, | ||
742 | IN_BUFLEN, GFP_KERNEL, | ||
743 | sierra_indat_callback); | ||
744 | portdata->in_urbs[i] = urb; | ||
745 | } | ||
746 | /* clear halt condition */ | ||
747 | usb_clear_halt(serial->dev, | ||
748 | usb_sndbulkpipe(serial->dev, endpoint) | USB_DIR_IN); | ||
749 | |||
750 | err = sierra_submit_rx_urbs(port, GFP_KERNEL); | ||
751 | if (err) { | ||
752 | /* get rid of everything as in close */ | ||
753 | sierra_close(port); | ||
754 | return err; | ||
755 | } | ||
756 | sierra_send_setup(port); | ||
757 | |||
758 | return 0; | ||
759 | } | ||
760 | |||
761 | |||
762 | static void sierra_dtr_rts(struct usb_serial_port *port, int on) | ||
763 | { | ||
764 | struct usb_serial *serial = port->serial; | ||
765 | struct sierra_port_private *portdata; | ||
766 | |||
767 | portdata = usb_get_serial_port_data(port); | ||
768 | portdata->rts_state = on; | ||
769 | portdata->dtr_state = on; | ||
770 | |||
771 | if (serial->dev) { | ||
772 | mutex_lock(&serial->disc_mutex); | ||
773 | if (!serial->disconnected) | ||
774 | sierra_send_setup(port); | ||
775 | mutex_unlock(&serial->disc_mutex); | ||
776 | } | ||
639 | } | 777 | } |
640 | 778 | ||
641 | static int sierra_startup(struct usb_serial *serial) | 779 | static int sierra_startup(struct usb_serial *serial) |
642 | { | 780 | { |
643 | struct usb_serial_port *port; | 781 | struct usb_serial_port *port; |
644 | struct sierra_port_private *portdata; | 782 | struct sierra_port_private *portdata; |
645 | struct urb *urb; | ||
646 | int i; | 783 | int i; |
647 | int j; | ||
648 | 784 | ||
649 | dev_dbg(&serial->dev->dev, "%s", __func__); | 785 | dev_dbg(&serial->dev->dev, "%s", __func__); |
650 | 786 | ||
@@ -666,34 +802,8 @@ static int sierra_startup(struct usb_serial *serial) | |||
666 | return -ENOMEM; | 802 | return -ENOMEM; |
667 | } | 803 | } |
668 | spin_lock_init(&portdata->lock); | 804 | spin_lock_init(&portdata->lock); |
669 | for (j = 0; j < N_IN_URB; j++) { | 805 | /* Set the port private data pointer */ |
670 | portdata->in_buffer[j] = kmalloc(IN_BUFLEN, GFP_KERNEL); | ||
671 | if (!portdata->in_buffer[j]) { | ||
672 | for (--j; j >= 0; j--) | ||
673 | kfree(portdata->in_buffer[j]); | ||
674 | kfree(portdata); | ||
675 | return -ENOMEM; | ||
676 | } | ||
677 | } | ||
678 | |||
679 | usb_set_serial_port_data(port, portdata); | 806 | usb_set_serial_port_data(port, portdata); |
680 | |||
681 | /* initialize the in urbs */ | ||
682 | for (j = 0; j < N_IN_URB; ++j) { | ||
683 | urb = usb_alloc_urb(0, GFP_KERNEL); | ||
684 | if (urb == NULL) { | ||
685 | dev_dbg(&port->dev, "%s: alloc for in " | ||
686 | "port failed.", __func__); | ||
687 | continue; | ||
688 | } | ||
689 | /* Fill URB using supplied data. */ | ||
690 | usb_fill_bulk_urb(urb, serial->dev, | ||
691 | usb_rcvbulkpipe(serial->dev, | ||
692 | port->bulk_in_endpointAddress), | ||
693 | portdata->in_buffer[j], IN_BUFLEN, | ||
694 | sierra_indat_callback, port); | ||
695 | portdata->in_urbs[j] = urb; | ||
696 | } | ||
697 | } | 807 | } |
698 | 808 | ||
699 | return 0; | 809 | return 0; |
@@ -701,7 +811,7 @@ static int sierra_startup(struct usb_serial *serial) | |||
701 | 811 | ||
702 | static void sierra_shutdown(struct usb_serial *serial) | 812 | static void sierra_shutdown(struct usb_serial *serial) |
703 | { | 813 | { |
704 | int i, j; | 814 | int i; |
705 | struct usb_serial_port *port; | 815 | struct usb_serial_port *port; |
706 | struct sierra_port_private *portdata; | 816 | struct sierra_port_private *portdata; |
707 | 817 | ||
@@ -714,12 +824,6 @@ static void sierra_shutdown(struct usb_serial *serial) | |||
714 | portdata = usb_get_serial_port_data(port); | 824 | portdata = usb_get_serial_port_data(port); |
715 | if (!portdata) | 825 | if (!portdata) |
716 | continue; | 826 | continue; |
717 | |||
718 | for (j = 0; j < N_IN_URB; j++) { | ||
719 | usb_kill_urb(portdata->in_urbs[j]); | ||
720 | usb_free_urb(portdata->in_urbs[j]); | ||
721 | kfree(portdata->in_buffer[j]); | ||
722 | } | ||
723 | kfree(portdata); | 827 | kfree(portdata); |
724 | usb_set_serial_port_data(port, NULL); | 828 | usb_set_serial_port_data(port, NULL); |
725 | } | 829 | } |
@@ -737,6 +841,7 @@ static struct usb_serial_driver sierra_device = { | |||
737 | .probe = sierra_probe, | 841 | .probe = sierra_probe, |
738 | .open = sierra_open, | 842 | .open = sierra_open, |
739 | .close = sierra_close, | 843 | .close = sierra_close, |
844 | .dtr_rts = sierra_dtr_rts, | ||
740 | .write = sierra_write, | 845 | .write = sierra_write, |
741 | .write_room = sierra_write_room, | 846 | .write_room = sierra_write_room, |
742 | .set_termios = sierra_set_termios, | 847 | .set_termios = sierra_set_termios, |
diff --git a/drivers/usb/serial/spcp8x5.c b/drivers/usb/serial/spcp8x5.c index 5e7528cc81a8..8f7ed8f13996 100644 --- a/drivers/usb/serial/spcp8x5.c +++ b/drivers/usb/serial/spcp8x5.c | |||
@@ -446,66 +446,47 @@ static void spcp8x5_set_workMode(struct usb_device *dev, u16 value, | |||
446 | "RTSCTS usb_control_msg(enable flowctrl) = %d\n", ret); | 446 | "RTSCTS usb_control_msg(enable flowctrl) = %d\n", ret); |
447 | } | 447 | } |
448 | 448 | ||
449 | static int spcp8x5_carrier_raised(struct usb_serial_port *port) | ||
450 | { | ||
451 | struct spcp8x5_private *priv = usb_get_serial_port_data(port); | ||
452 | if (priv->line_status & MSR_STATUS_LINE_DCD) | ||
453 | return 1; | ||
454 | return 0; | ||
455 | } | ||
456 | |||
457 | static void spcp8x5_dtr_rts(struct usb_serial_port *port, int on) | ||
458 | { | ||
459 | struct spcp8x5_private *priv = usb_get_serial_port_data(port); | ||
460 | unsigned long flags; | ||
461 | u8 control; | ||
462 | |||
463 | spin_lock_irqsave(&priv->lock, flags); | ||
464 | if (on) | ||
465 | priv->line_control = MCR_CONTROL_LINE_DTR | ||
466 | | MCR_CONTROL_LINE_RTS; | ||
467 | else | ||
468 | priv->line_control &= ~ (MCR_CONTROL_LINE_DTR | ||
469 | | MCR_CONTROL_LINE_RTS); | ||
470 | control = priv->line_control; | ||
471 | spin_unlock_irqrestore(&priv->lock, flags); | ||
472 | spcp8x5_set_ctrlLine(port->serial->dev, control , priv->type); | ||
473 | } | ||
474 | |||
449 | /* close the serial port. We should wait for data sending to device 1st and | 475 | /* close the serial port. We should wait for data sending to device 1st and |
450 | * then kill all urb. */ | 476 | * then kill all urb. */ |
451 | static void spcp8x5_close(struct tty_struct *tty, | 477 | static void spcp8x5_close(struct usb_serial_port *port) |
452 | struct usb_serial_port *port, struct file *filp) | ||
453 | { | 478 | { |
454 | struct spcp8x5_private *priv = usb_get_serial_port_data(port); | 479 | struct spcp8x5_private *priv = usb_get_serial_port_data(port); |
455 | unsigned long flags; | 480 | unsigned long flags; |
456 | unsigned int c_cflag; | ||
457 | int bps; | ||
458 | long timeout; | ||
459 | wait_queue_t wait; | ||
460 | int result; | 481 | int result; |
461 | 482 | ||
462 | dbg("%s - port %d", __func__, port->number); | 483 | dbg("%s - port %d", __func__, port->number); |
463 | 484 | ||
464 | /* wait for data to drain from the buffer */ | ||
465 | spin_lock_irqsave(&priv->lock, flags); | 485 | spin_lock_irqsave(&priv->lock, flags); |
466 | timeout = SPCP8x5_CLOSING_WAIT; | ||
467 | init_waitqueue_entry(&wait, current); | ||
468 | add_wait_queue(&tty->write_wait, &wait); | ||
469 | for (;;) { | ||
470 | set_current_state(TASK_INTERRUPTIBLE); | ||
471 | if (ringbuf_avail_data(priv->buf) == 0 || | ||
472 | timeout == 0 || signal_pending(current)) | ||
473 | break; | ||
474 | spin_unlock_irqrestore(&priv->lock, flags); | ||
475 | timeout = schedule_timeout(timeout); | ||
476 | spin_lock_irqsave(&priv->lock, flags); | ||
477 | } | ||
478 | set_current_state(TASK_RUNNING); | ||
479 | remove_wait_queue(&tty->write_wait, &wait); | ||
480 | |||
481 | /* clear out any remaining data in the buffer */ | 486 | /* clear out any remaining data in the buffer */ |
482 | clear_ringbuf(priv->buf); | 487 | clear_ringbuf(priv->buf); |
483 | spin_unlock_irqrestore(&priv->lock, flags); | 488 | spin_unlock_irqrestore(&priv->lock, flags); |
484 | 489 | ||
485 | /* wait for characters to drain from the device (this is long enough | ||
486 | * for the entire all byte spcp8x5 hardware buffer to drain with no | ||
487 | * flow control for data rates of 1200 bps or more, for lower rates we | ||
488 | * should really know how much data is in the buffer to compute a delay | ||
489 | * that is not unnecessarily long) */ | ||
490 | bps = tty_get_baud_rate(tty); | ||
491 | if (bps > 1200) | ||
492 | timeout = max((HZ*2560) / bps, HZ/10); | ||
493 | else | ||
494 | timeout = 2*HZ; | ||
495 | set_current_state(TASK_INTERRUPTIBLE); | ||
496 | schedule_timeout(timeout); | ||
497 | |||
498 | /* clear control lines */ | ||
499 | if (tty) { | ||
500 | c_cflag = tty->termios->c_cflag; | ||
501 | if (c_cflag & HUPCL) { | ||
502 | spin_lock_irqsave(&priv->lock, flags); | ||
503 | priv->line_control = 0; | ||
504 | spin_unlock_irqrestore(&priv->lock, flags); | ||
505 | spcp8x5_set_ctrlLine(port->serial->dev, 0 , priv->type); | ||
506 | } | ||
507 | } | ||
508 | |||
509 | /* kill urb */ | 490 | /* kill urb */ |
510 | if (port->write_urb != NULL) { | 491 | if (port->write_urb != NULL) { |
511 | result = usb_unlink_urb(port->write_urb); | 492 | result = usb_unlink_urb(port->write_urb); |
@@ -665,13 +646,6 @@ static int spcp8x5_open(struct tty_struct *tty, | |||
665 | if (ret) | 646 | if (ret) |
666 | return ret; | 647 | return ret; |
667 | 648 | ||
668 | spin_lock_irqsave(&priv->lock, flags); | ||
669 | if (tty && (tty->termios->c_cflag & CBAUD)) | ||
670 | priv->line_control = MCR_DTR | MCR_RTS; | ||
671 | else | ||
672 | priv->line_control = 0; | ||
673 | spin_unlock_irqrestore(&priv->lock, flags); | ||
674 | |||
675 | spcp8x5_set_ctrlLine(serial->dev, priv->line_control , priv->type); | 649 | spcp8x5_set_ctrlLine(serial->dev, priv->line_control , priv->type); |
676 | 650 | ||
677 | /* Setup termios */ | 651 | /* Setup termios */ |
@@ -691,9 +665,10 @@ static int spcp8x5_open(struct tty_struct *tty, | |||
691 | port->read_urb->dev = serial->dev; | 665 | port->read_urb->dev = serial->dev; |
692 | ret = usb_submit_urb(port->read_urb, GFP_KERNEL); | 666 | ret = usb_submit_urb(port->read_urb, GFP_KERNEL); |
693 | if (ret) { | 667 | if (ret) { |
694 | spcp8x5_close(tty, port, NULL); | 668 | spcp8x5_close(port); |
695 | return -EPROTO; | 669 | return -EPROTO; |
696 | } | 670 | } |
671 | port->port.drain_delay = 256; | ||
697 | return 0; | 672 | return 0; |
698 | } | 673 | } |
699 | 674 | ||
@@ -1033,6 +1008,8 @@ static struct usb_serial_driver spcp8x5_device = { | |||
1033 | .num_ports = 1, | 1008 | .num_ports = 1, |
1034 | .open = spcp8x5_open, | 1009 | .open = spcp8x5_open, |
1035 | .close = spcp8x5_close, | 1010 | .close = spcp8x5_close, |
1011 | .dtr_rts = spcp8x5_dtr_rts, | ||
1012 | .carrier_raised = spcp8x5_carrier_raised, | ||
1036 | .write = spcp8x5_write, | 1013 | .write = spcp8x5_write, |
1037 | .set_termios = spcp8x5_set_termios, | 1014 | .set_termios = spcp8x5_set_termios, |
1038 | .ioctl = spcp8x5_ioctl, | 1015 | .ioctl = spcp8x5_ioctl, |
diff --git a/drivers/usb/serial/symbolserial.c b/drivers/usb/serial/symbolserial.c index 69879e437940..8b07ebc6baeb 100644 --- a/drivers/usb/serial/symbolserial.c +++ b/drivers/usb/serial/symbolserial.c | |||
@@ -152,8 +152,7 @@ static int symbol_open(struct tty_struct *tty, struct usb_serial_port *port, | |||
152 | return result; | 152 | return result; |
153 | } | 153 | } |
154 | 154 | ||
155 | static void symbol_close(struct tty_struct *tty, struct usb_serial_port *port, | 155 | static void symbol_close(struct usb_serial_port *port) |
156 | struct file *filp) | ||
157 | { | 156 | { |
158 | struct symbol_private *priv = usb_get_serial_data(port->serial); | 157 | struct symbol_private *priv = usb_get_serial_data(port->serial); |
159 | 158 | ||
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c index 0a64bac306ee..42cb04c403be 100644 --- a/drivers/usb/serial/ti_usb_3410_5052.c +++ b/drivers/usb/serial/ti_usb_3410_5052.c | |||
@@ -100,8 +100,7 @@ static int ti_startup(struct usb_serial *serial); | |||
100 | static void ti_shutdown(struct usb_serial *serial); | 100 | static void ti_shutdown(struct usb_serial *serial); |
101 | static int ti_open(struct tty_struct *tty, struct usb_serial_port *port, | 101 | static int ti_open(struct tty_struct *tty, struct usb_serial_port *port, |
102 | struct file *file); | 102 | struct file *file); |
103 | static void ti_close(struct tty_struct *tty, struct usb_serial_port *port, | 103 | static void ti_close(struct usb_serial_port *port); |
104 | struct file *file); | ||
105 | static int ti_write(struct tty_struct *tty, struct usb_serial_port *port, | 104 | static int ti_write(struct tty_struct *tty, struct usb_serial_port *port, |
106 | const unsigned char *data, int count); | 105 | const unsigned char *data, int count); |
107 | static int ti_write_room(struct tty_struct *tty); | 106 | static int ti_write_room(struct tty_struct *tty); |
@@ -647,8 +646,7 @@ release_lock: | |||
647 | } | 646 | } |
648 | 647 | ||
649 | 648 | ||
650 | static void ti_close(struct tty_struct *tty, struct usb_serial_port *port, | 649 | static void ti_close(struct usb_serial_port *port) |
651 | struct file *file) | ||
652 | { | 650 | { |
653 | struct ti_device *tdev; | 651 | struct ti_device *tdev; |
654 | struct ti_port *tport; | 652 | struct ti_port *tport; |
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c index f331e2bde88a..1967a7edc10c 100644 --- a/drivers/usb/serial/usb-serial.c +++ b/drivers/usb/serial/usb-serial.c | |||
@@ -238,9 +238,11 @@ static int serial_open (struct tty_struct *tty, struct file *filp) | |||
238 | goto bailout_interface_put; | 238 | goto bailout_interface_put; |
239 | mutex_unlock(&serial->disc_mutex); | 239 | mutex_unlock(&serial->disc_mutex); |
240 | } | 240 | } |
241 | |||
242 | mutex_unlock(&port->mutex); | 241 | mutex_unlock(&port->mutex); |
243 | return 0; | 242 | /* Now do the correct tty layer semantics */ |
243 | retval = tty_port_block_til_ready(&port->port, tty, filp); | ||
244 | if (retval == 0) | ||
245 | return 0; | ||
244 | 246 | ||
245 | bailout_interface_put: | 247 | bailout_interface_put: |
246 | usb_autopm_put_interface(serial->interface); | 248 | usb_autopm_put_interface(serial->interface); |
@@ -259,64 +261,89 @@ bailout_serial_put: | |||
259 | return retval; | 261 | return retval; |
260 | } | 262 | } |
261 | 263 | ||
262 | static void serial_close(struct tty_struct *tty, struct file *filp) | 264 | /** |
265 | * serial_do_down - shut down hardware | ||
266 | * @port: port to shut down | ||
267 | * | ||
268 | * Shut down a USB port unless it is the console. We never shut down the | ||
269 | * console hardware as it will always be in use. | ||
270 | * | ||
271 | * Don't free any resources at this point | ||
272 | */ | ||
273 | static void serial_do_down(struct usb_serial_port *port) | ||
263 | { | 274 | { |
264 | struct usb_serial_port *port = tty->driver_data; | 275 | struct usb_serial_driver *drv = port->serial->type; |
265 | struct usb_serial *serial; | 276 | struct usb_serial *serial; |
266 | struct module *owner; | 277 | struct module *owner; |
267 | int count; | ||
268 | 278 | ||
269 | if (!port) | 279 | /* The console is magical, do not hang up the console hardware |
280 | or there will be tears */ | ||
281 | if (port->console) | ||
270 | return; | 282 | return; |
271 | 283 | ||
272 | dbg("%s - port %d", __func__, port->number); | ||
273 | |||
274 | mutex_lock(&port->mutex); | 284 | mutex_lock(&port->mutex); |
275 | serial = port->serial; | 285 | serial = port->serial; |
276 | owner = serial->type->driver.owner; | 286 | owner = serial->type->driver.owner; |
277 | 287 | ||
278 | if (port->port.count == 0) { | 288 | if (drv->close) |
279 | mutex_unlock(&port->mutex); | 289 | drv->close(port); |
280 | return; | ||
281 | } | ||
282 | |||
283 | if (port->port.count == 1) | ||
284 | /* only call the device specific close if this | ||
285 | * port is being closed by the last owner. Ensure we do | ||
286 | * this before we drop the port count. The call is protected | ||
287 | * by the port mutex | ||
288 | */ | ||
289 | serial->type->close(tty, port, filp); | ||
290 | |||
291 | if (port->port.count == (port->console ? 2 : 1)) { | ||
292 | struct tty_struct *tty = tty_port_tty_get(&port->port); | ||
293 | if (tty) { | ||
294 | /* We must do this before we drop the port count to | ||
295 | zero. */ | ||
296 | if (tty->driver_data) | ||
297 | tty->driver_data = NULL; | ||
298 | tty_port_tty_set(&port->port, NULL); | ||
299 | tty_kref_put(tty); | ||
300 | } | ||
301 | } | ||
302 | 290 | ||
303 | --port->port.count; | ||
304 | count = port->port.count; | ||
305 | mutex_unlock(&port->mutex); | 291 | mutex_unlock(&port->mutex); |
306 | put_device(&port->dev); | 292 | } |
293 | |||
294 | /** | ||
295 | * serial_do_free - free resources post close/hangup | ||
296 | * @port: port to free up | ||
297 | * | ||
298 | * Do the resource freeing and refcount dropping for the port. We must | ||
299 | * be careful about ordering and we must avoid freeing up the console. | ||
300 | */ | ||
307 | 301 | ||
302 | static void serial_do_free(struct usb_serial_port *port) | ||
303 | { | ||
304 | struct usb_serial *serial; | ||
305 | struct module *owner; | ||
306 | |||
307 | /* The console is magical, do not hang up the console hardware | ||
308 | or there will be tears */ | ||
309 | if (port->console) | ||
310 | return; | ||
311 | |||
312 | serial = port->serial; | ||
313 | owner = serial->type->driver.owner; | ||
314 | put_device(&port->dev); | ||
308 | /* Mustn't dereference port any more */ | 315 | /* Mustn't dereference port any more */ |
309 | if (count == 0) { | 316 | mutex_lock(&serial->disc_mutex); |
310 | mutex_lock(&serial->disc_mutex); | 317 | if (!serial->disconnected) |
311 | if (!serial->disconnected) | 318 | usb_autopm_put_interface(serial->interface); |
312 | usb_autopm_put_interface(serial->interface); | 319 | mutex_unlock(&serial->disc_mutex); |
313 | mutex_unlock(&serial->disc_mutex); | ||
314 | } | ||
315 | usb_serial_put(serial); | 320 | usb_serial_put(serial); |
316 | |||
317 | /* Mustn't dereference serial any more */ | 321 | /* Mustn't dereference serial any more */ |
318 | if (count == 0) | 322 | module_put(owner); |
319 | module_put(owner); | 323 | } |
324 | |||
325 | static void serial_close(struct tty_struct *tty, struct file *filp) | ||
326 | { | ||
327 | struct usb_serial_port *port = tty->driver_data; | ||
328 | |||
329 | dbg("%s - port %d", __func__, port->number); | ||
330 | |||
331 | |||
332 | if (tty_port_close_start(&port->port, tty, filp) == 0) | ||
333 | return; | ||
334 | |||
335 | serial_do_down(port); | ||
336 | tty_port_close_end(&port->port, tty); | ||
337 | tty_port_tty_set(&port->port, NULL); | ||
338 | serial_do_free(port); | ||
339 | } | ||
340 | |||
341 | static void serial_hangup(struct tty_struct *tty) | ||
342 | { | ||
343 | struct usb_serial_port *port = tty->driver_data; | ||
344 | serial_do_down(port); | ||
345 | tty_port_hangup(&port->port); | ||
346 | serial_do_free(port); | ||
320 | } | 347 | } |
321 | 348 | ||
322 | static int serial_write(struct tty_struct *tty, const unsigned char *buf, | 349 | static int serial_write(struct tty_struct *tty, const unsigned char *buf, |
@@ -648,6 +675,29 @@ static struct usb_serial_driver *search_serial_device( | |||
648 | return NULL; | 675 | return NULL; |
649 | } | 676 | } |
650 | 677 | ||
678 | static int serial_carrier_raised(struct tty_port *port) | ||
679 | { | ||
680 | struct usb_serial_port *p = container_of(port, struct usb_serial_port, port); | ||
681 | struct usb_serial_driver *drv = p->serial->type; | ||
682 | if (drv->carrier_raised) | ||
683 | return drv->carrier_raised(p); | ||
684 | /* No carrier control - don't block */ | ||
685 | return 1; | ||
686 | } | ||
687 | |||
688 | static void serial_dtr_rts(struct tty_port *port, int on) | ||
689 | { | ||
690 | struct usb_serial_port *p = container_of(port, struct usb_serial_port, port); | ||
691 | struct usb_serial_driver *drv = p->serial->type; | ||
692 | if (drv->dtr_rts) | ||
693 | drv->dtr_rts(p, on); | ||
694 | } | ||
695 | |||
696 | static const struct tty_port_operations serial_port_ops = { | ||
697 | .carrier_raised = serial_carrier_raised, | ||
698 | .dtr_rts = serial_dtr_rts, | ||
699 | }; | ||
700 | |||
651 | int usb_serial_probe(struct usb_interface *interface, | 701 | int usb_serial_probe(struct usb_interface *interface, |
652 | const struct usb_device_id *id) | 702 | const struct usb_device_id *id) |
653 | { | 703 | { |
@@ -841,6 +891,7 @@ int usb_serial_probe(struct usb_interface *interface, | |||
841 | if (!port) | 891 | if (!port) |
842 | goto probe_error; | 892 | goto probe_error; |
843 | tty_port_init(&port->port); | 893 | tty_port_init(&port->port); |
894 | port->port.ops = &serial_port_ops; | ||
844 | port->serial = serial; | 895 | port->serial = serial; |
845 | spin_lock_init(&port->lock); | 896 | spin_lock_init(&port->lock); |
846 | mutex_init(&port->mutex); | 897 | mutex_init(&port->mutex); |
@@ -1071,6 +1122,9 @@ void usb_serial_disconnect(struct usb_interface *interface) | |||
1071 | if (port) { | 1122 | if (port) { |
1072 | struct tty_struct *tty = tty_port_tty_get(&port->port); | 1123 | struct tty_struct *tty = tty_port_tty_get(&port->port); |
1073 | if (tty) { | 1124 | if (tty) { |
1125 | /* The hangup will occur asynchronously but | ||
1126 | the object refcounts will sort out all the | ||
1127 | cleanup */ | ||
1074 | tty_hangup(tty); | 1128 | tty_hangup(tty); |
1075 | tty_kref_put(tty); | 1129 | tty_kref_put(tty); |
1076 | } | 1130 | } |
@@ -1135,6 +1189,7 @@ static const struct tty_operations serial_ops = { | |||
1135 | .open = serial_open, | 1189 | .open = serial_open, |
1136 | .close = serial_close, | 1190 | .close = serial_close, |
1137 | .write = serial_write, | 1191 | .write = serial_write, |
1192 | .hangup = serial_hangup, | ||
1138 | .write_room = serial_write_room, | 1193 | .write_room = serial_write_room, |
1139 | .ioctl = serial_ioctl, | 1194 | .ioctl = serial_ioctl, |
1140 | .set_termios = serial_set_termios, | 1195 | .set_termios = serial_set_termios, |
@@ -1147,6 +1202,7 @@ static const struct tty_operations serial_ops = { | |||
1147 | .proc_fops = &serial_proc_fops, | 1202 | .proc_fops = &serial_proc_fops, |
1148 | }; | 1203 | }; |
1149 | 1204 | ||
1205 | |||
1150 | struct tty_driver *usb_serial_tty_driver; | 1206 | struct tty_driver *usb_serial_tty_driver; |
1151 | 1207 | ||
1152 | static int __init usb_serial_init(void) | 1208 | static int __init usb_serial_init(void) |
diff --git a/drivers/usb/serial/visor.c b/drivers/usb/serial/visor.c index 5ac414bda718..b15f1c0e1d4a 100644 --- a/drivers/usb/serial/visor.c +++ b/drivers/usb/serial/visor.c | |||
@@ -38,8 +38,7 @@ | |||
38 | /* function prototypes for a handspring visor */ | 38 | /* function prototypes for a handspring visor */ |
39 | static int visor_open(struct tty_struct *tty, struct usb_serial_port *port, | 39 | static int visor_open(struct tty_struct *tty, struct usb_serial_port *port, |
40 | struct file *filp); | 40 | struct file *filp); |
41 | static void visor_close(struct tty_struct *tty, struct usb_serial_port *port, | 41 | static void visor_close(struct usb_serial_port *port); |
42 | struct file *filp); | ||
43 | static int visor_write(struct tty_struct *tty, struct usb_serial_port *port, | 42 | static int visor_write(struct tty_struct *tty, struct usb_serial_port *port, |
44 | const unsigned char *buf, int count); | 43 | const unsigned char *buf, int count); |
45 | static int visor_write_room(struct tty_struct *tty); | 44 | static int visor_write_room(struct tty_struct *tty); |
@@ -324,8 +323,7 @@ exit: | |||
324 | } | 323 | } |
325 | 324 | ||
326 | 325 | ||
327 | static void visor_close(struct tty_struct *tty, | 326 | static void visor_close(struct usb_serial_port *port) |
328 | struct usb_serial_port *port, struct file *filp) | ||
329 | { | 327 | { |
330 | struct visor_private *priv = usb_get_serial_port_data(port); | 328 | struct visor_private *priv = usb_get_serial_port_data(port); |
331 | unsigned char *transfer_buffer; | 329 | unsigned char *transfer_buffer; |
diff --git a/drivers/usb/serial/whiteheat.c b/drivers/usb/serial/whiteheat.c index 5335d3211c07..7c7295d09f34 100644 --- a/drivers/usb/serial/whiteheat.c +++ b/drivers/usb/serial/whiteheat.c | |||
@@ -147,8 +147,7 @@ static int whiteheat_attach(struct usb_serial *serial); | |||
147 | static void whiteheat_shutdown(struct usb_serial *serial); | 147 | static void whiteheat_shutdown(struct usb_serial *serial); |
148 | static int whiteheat_open(struct tty_struct *tty, | 148 | static int whiteheat_open(struct tty_struct *tty, |
149 | struct usb_serial_port *port, struct file *filp); | 149 | struct usb_serial_port *port, struct file *filp); |
150 | static void whiteheat_close(struct tty_struct *tty, | 150 | static void whiteheat_close(struct usb_serial_port *port); |
151 | struct usb_serial_port *port, struct file *filp); | ||
152 | static int whiteheat_write(struct tty_struct *tty, | 151 | static int whiteheat_write(struct tty_struct *tty, |
153 | struct usb_serial_port *port, | 152 | struct usb_serial_port *port, |
154 | const unsigned char *buf, int count); | 153 | const unsigned char *buf, int count); |
@@ -712,8 +711,7 @@ exit: | |||
712 | } | 711 | } |
713 | 712 | ||
714 | 713 | ||
715 | static void whiteheat_close(struct tty_struct *tty, | 714 | static void whiteheat_close(struct usb_serial_port *port) |
716 | struct usb_serial_port *port, struct file *filp) | ||
717 | { | 715 | { |
718 | struct whiteheat_private *info = usb_get_serial_port_data(port); | 716 | struct whiteheat_private *info = usb_get_serial_port_data(port); |
719 | struct whiteheat_urb_wrap *wrap; | 717 | struct whiteheat_urb_wrap *wrap; |
@@ -723,31 +721,7 @@ static void whiteheat_close(struct tty_struct *tty, | |||
723 | 721 | ||
724 | dbg("%s - port %d", __func__, port->number); | 722 | dbg("%s - port %d", __func__, port->number); |
725 | 723 | ||
726 | mutex_lock(&port->serial->disc_mutex); | ||
727 | /* filp is NULL when called from usb_serial_disconnect */ | ||
728 | if ((filp && (tty_hung_up_p(filp))) || port->serial->disconnected) { | ||
729 | mutex_unlock(&port->serial->disc_mutex); | ||
730 | return; | ||
731 | } | ||
732 | mutex_unlock(&port->serial->disc_mutex); | ||
733 | |||
734 | tty->closing = 1; | ||
735 | |||
736 | /* | ||
737 | * Not currently in use; tty_wait_until_sent() calls | ||
738 | * serial_chars_in_buffer() which deadlocks on the second semaphore | ||
739 | * acquisition. This should be fixed at some point. Greg's been | ||
740 | * notified. | ||
741 | if ((filp->f_flags & (O_NDELAY | O_NONBLOCK)) == 0) { | ||
742 | tty_wait_until_sent(tty, CLOSING_DELAY); | ||
743 | } | ||
744 | */ | ||
745 | |||
746 | tty_driver_flush_buffer(tty); | ||
747 | tty_ldisc_flush(tty); | ||
748 | |||
749 | firm_report_tx_done(port); | 724 | firm_report_tx_done(port); |
750 | |||
751 | firm_close(port); | 725 | firm_close(port); |
752 | 726 | ||
753 | /* shutdown our bulk reads and writes */ | 727 | /* shutdown our bulk reads and writes */ |
@@ -775,10 +749,7 @@ static void whiteheat_close(struct tty_struct *tty, | |||
775 | } | 749 | } |
776 | spin_unlock_irq(&info->lock); | 750 | spin_unlock_irq(&info->lock); |
777 | mutex_unlock(&info->deathwarrant); | 751 | mutex_unlock(&info->deathwarrant); |
778 | |||
779 | stop_command_port(port->serial); | 752 | stop_command_port(port->serial); |
780 | |||
781 | tty->closing = 0; | ||
782 | } | 753 | } |
783 | 754 | ||
784 | 755 | ||
diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c index c68edb969441..9b1d285f9fe6 100644 --- a/fs/devpts/inode.c +++ b/fs/devpts/inode.c | |||
@@ -557,8 +557,10 @@ static int __init init_devpts_fs(void) | |||
557 | int err = register_filesystem(&devpts_fs_type); | 557 | int err = register_filesystem(&devpts_fs_type); |
558 | if (!err) { | 558 | if (!err) { |
559 | devpts_mnt = kern_mount(&devpts_fs_type); | 559 | devpts_mnt = kern_mount(&devpts_fs_type); |
560 | if (IS_ERR(devpts_mnt)) | 560 | if (IS_ERR(devpts_mnt)) { |
561 | err = PTR_ERR(devpts_mnt); | 561 | err = PTR_ERR(devpts_mnt); |
562 | unregister_filesystem(&devpts_fs_type); | ||
563 | } | ||
562 | } | 564 | } |
563 | return err; | 565 | return err; |
564 | } | 566 | } |
diff --git a/include/linux/cyclades.h b/include/linux/cyclades.h index 788850ba4e75..1fbdea4f08eb 100644 --- a/include/linux/cyclades.h +++ b/include/linux/cyclades.h | |||
@@ -142,19 +142,6 @@ struct CYZ_BOOT_CTRL { | |||
142 | 142 | ||
143 | 143 | ||
144 | #ifndef DP_WINDOW_SIZE | 144 | #ifndef DP_WINDOW_SIZE |
145 | /* #include "cyclomz.h" */ | ||
146 | /****************** ****************** *******************/ | ||
147 | /* | ||
148 | * The data types defined below are used in all ZFIRM interface | ||
149 | * data structures. They accomodate differences between HW | ||
150 | * architectures and compilers. | ||
151 | */ | ||
152 | |||
153 | typedef __u64 ucdouble; /* 64 bits, unsigned */ | ||
154 | typedef __u32 uclong; /* 32 bits, unsigned */ | ||
155 | typedef __u16 ucshort; /* 16 bits, unsigned */ | ||
156 | typedef __u8 ucchar; /* 8 bits, unsigned */ | ||
157 | |||
158 | /* | 145 | /* |
159 | * Memory Window Sizes | 146 | * Memory Window Sizes |
160 | */ | 147 | */ |
@@ -507,16 +494,20 @@ struct ZFW_CTRL { | |||
507 | 494 | ||
508 | /* Per card data structure */ | 495 | /* Per card data structure */ |
509 | struct cyclades_card { | 496 | struct cyclades_card { |
510 | void __iomem *base_addr; | 497 | void __iomem *base_addr; |
511 | void __iomem *ctl_addr; | 498 | union { |
512 | int irq; | 499 | void __iomem *p9050; |
513 | unsigned int num_chips; /* 0 if card absent, -1 if Z/PCI, else Y */ | 500 | struct RUNTIME_9060 __iomem *p9060; |
514 | unsigned int first_line; /* minor number of first channel on card */ | 501 | } ctl_addr; |
515 | unsigned int nports; /* Number of ports in the card */ | 502 | int irq; |
516 | int bus_index; /* address shift - 0 for ISA, 1 for PCI */ | 503 | unsigned int num_chips; /* 0 if card absent, -1 if Z/PCI, else Y */ |
517 | int intr_enabled; /* FW Interrupt flag - 0 disabled, 1 enabled */ | 504 | unsigned int first_line; /* minor number of first channel on card */ |
518 | spinlock_t card_lock; | 505 | unsigned int nports; /* Number of ports in the card */ |
519 | struct cyclades_port *ports; | 506 | int bus_index; /* address shift - 0 for ISA, 1 for PCI */ |
507 | int intr_enabled; /* FW Interrupt flag - 0 disabled, 1 enabled */ | ||
508 | u32 hw_ver; | ||
509 | spinlock_t card_lock; | ||
510 | struct cyclades_port *ports; | ||
520 | }; | 511 | }; |
521 | 512 | ||
522 | /*************************************** | 513 | /*************************************** |
diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h index 0f71812d67d3..d7d1c41a0b17 100644 --- a/include/linux/pci_ids.h +++ b/include/linux/pci_ids.h | |||
@@ -1996,10 +1996,12 @@ | |||
1996 | #define PCI_DEVICE_ID_OXSEMI_PCIe952_1_U 0xC118 | 1996 | #define PCI_DEVICE_ID_OXSEMI_PCIe952_1_U 0xC118 |
1997 | #define PCI_DEVICE_ID_OXSEMI_PCIe952_1_GU 0xC11C | 1997 | #define PCI_DEVICE_ID_OXSEMI_PCIe952_1_GU 0xC11C |
1998 | #define PCI_DEVICE_ID_OXSEMI_16PCI954 0x9501 | 1998 | #define PCI_DEVICE_ID_OXSEMI_16PCI954 0x9501 |
1999 | #define PCI_DEVICE_ID_OXSEMI_C950 0x950B | ||
1999 | #define PCI_DEVICE_ID_OXSEMI_16PCI95N 0x9511 | 2000 | #define PCI_DEVICE_ID_OXSEMI_16PCI95N 0x9511 |
2000 | #define PCI_DEVICE_ID_OXSEMI_16PCI954PP 0x9513 | 2001 | #define PCI_DEVICE_ID_OXSEMI_16PCI954PP 0x9513 |
2001 | #define PCI_DEVICE_ID_OXSEMI_16PCI952 0x9521 | 2002 | #define PCI_DEVICE_ID_OXSEMI_16PCI952 0x9521 |
2002 | #define PCI_DEVICE_ID_OXSEMI_16PCI952PP 0x9523 | 2003 | #define PCI_DEVICE_ID_OXSEMI_16PCI952PP 0x9523 |
2004 | #define PCI_SUBDEVICE_ID_OXSEMI_C950 0x0001 | ||
2003 | 2005 | ||
2004 | #define PCI_VENDOR_ID_CHELSIO 0x1425 | 2006 | #define PCI_VENDOR_ID_CHELSIO 0x1425 |
2005 | 2007 | ||
diff --git a/include/linux/rational.h b/include/linux/rational.h new file mode 100644 index 000000000000..4f532fcd9eea --- /dev/null +++ b/include/linux/rational.h | |||
@@ -0,0 +1,19 @@ | |||
1 | /* | ||
2 | * rational fractions | ||
3 | * | ||
4 | * Copyright (C) 2009 emlix GmbH, Oskar Schirmer <os@emlix.com> | ||
5 | * | ||
6 | * helper functions when coping with rational numbers, | ||
7 | * e.g. when calculating optimum numerator/denominator pairs for | ||
8 | * pll configuration taking into account restricted register size | ||
9 | */ | ||
10 | |||
11 | #ifndef _LINUX_RATIONAL_H | ||
12 | #define _LINUX_RATIONAL_H | ||
13 | |||
14 | void rational_best_approximation( | ||
15 | unsigned long given_numerator, unsigned long given_denominator, | ||
16 | unsigned long max_numerator, unsigned long max_denominator, | ||
17 | unsigned long *best_numerator, unsigned long *best_denominator); | ||
18 | |||
19 | #endif /* _LINUX_RATIONAL_H */ | ||
diff --git a/include/linux/serial.h b/include/linux/serial.h index 9136cc5608c3..e5bb75a63802 100644 --- a/include/linux/serial.h +++ b/include/linux/serial.h | |||
@@ -96,54 +96,76 @@ struct serial_uart_config { | |||
96 | 96 | ||
97 | /* | 97 | /* |
98 | * Definitions for async_struct (and serial_struct) flags field | 98 | * Definitions for async_struct (and serial_struct) flags field |
99 | * | ||
100 | * Define ASYNCB_* for convenient use with {test,set,clear}_bit. | ||
99 | */ | 101 | */ |
100 | #define ASYNC_HUP_NOTIFY 0x0001 /* Notify getty on hangups and closes | 102 | #define ASYNCB_HUP_NOTIFY 0 /* Notify getty on hangups and closes |
101 | on the callout port */ | 103 | * on the callout port */ |
102 | #define ASYNC_FOURPORT 0x0002 /* Set OU1, OUT2 per AST Fourport settings */ | 104 | #define ASYNCB_FOURPORT 1 /* Set OU1, OUT2 per AST Fourport settings */ |
103 | #define ASYNC_SAK 0x0004 /* Secure Attention Key (Orange book) */ | 105 | #define ASYNCB_SAK 2 /* Secure Attention Key (Orange book) */ |
104 | #define ASYNC_SPLIT_TERMIOS 0x0008 /* Separate termios for dialin/callout */ | 106 | #define ASYNCB_SPLIT_TERMIOS 3 /* Separate termios for dialin/callout */ |
105 | 107 | #define ASYNCB_SPD_HI 4 /* Use 56000 instead of 38400 bps */ | |
106 | #define ASYNC_SPD_MASK 0x1030 | 108 | #define ASYNCB_SPD_VHI 5 /* Use 115200 instead of 38400 bps */ |
107 | #define ASYNC_SPD_HI 0x0010 /* Use 56000 instead of 38400 bps */ | 109 | #define ASYNCB_SKIP_TEST 6 /* Skip UART test during autoconfiguration */ |
108 | 110 | #define ASYNCB_AUTO_IRQ 7 /* Do automatic IRQ during | |
109 | #define ASYNC_SPD_VHI 0x0020 /* Use 115200 instead of 38400 bps */ | 111 | * autoconfiguration */ |
110 | #define ASYNC_SPD_CUST 0x0030 /* Use user-specified divisor */ | 112 | #define ASYNCB_SESSION_LOCKOUT 8 /* Lock out cua opens based on session */ |
111 | 113 | #define ASYNCB_PGRP_LOCKOUT 9 /* Lock out cua opens based on pgrp */ | |
112 | #define ASYNC_SKIP_TEST 0x0040 /* Skip UART test during autoconfiguration */ | 114 | #define ASYNCB_CALLOUT_NOHUP 10 /* Don't do hangups for cua device */ |
113 | #define ASYNC_AUTO_IRQ 0x0080 /* Do automatic IRQ during autoconfiguration */ | 115 | #define ASYNCB_HARDPPS_CD 11 /* Call hardpps when CD goes high */ |
114 | #define ASYNC_SESSION_LOCKOUT 0x0100 /* Lock out cua opens based on session */ | 116 | #define ASYNCB_SPD_SHI 12 /* Use 230400 instead of 38400 bps */ |
115 | #define ASYNC_PGRP_LOCKOUT 0x0200 /* Lock out cua opens based on pgrp */ | 117 | #define ASYNCB_LOW_LATENCY 13 /* Request low latency behaviour */ |
116 | #define ASYNC_CALLOUT_NOHUP 0x0400 /* Don't do hangups for cua device */ | 118 | #define ASYNCB_BUGGY_UART 14 /* This is a buggy UART, skip some safety |
117 | 119 | * checks. Note: can be dangerous! */ | |
118 | #define ASYNC_HARDPPS_CD 0x0800 /* Call hardpps when CD goes high */ | 120 | #define ASYNCB_AUTOPROBE 15 /* Port was autoprobed by PCI or PNP code */ |
119 | 121 | #define ASYNCB_LAST_USER 15 | |
120 | #define ASYNC_SPD_SHI 0x1000 /* Use 230400 instead of 38400 bps */ | 122 | |
121 | #define ASYNC_SPD_WARP 0x1010 /* Use 460800 instead of 38400 bps */ | 123 | /* Internal flags used only by kernel */ |
122 | 124 | #define ASYNCB_INITIALIZED 31 /* Serial port was initialized */ | |
123 | #define ASYNC_LOW_LATENCY 0x2000 /* Request low latency behaviour */ | 125 | #define ASYNCB_NORMAL_ACTIVE 29 /* Normal device is active */ |
124 | 126 | #define ASYNCB_BOOT_AUTOCONF 28 /* Autoconfigure port on bootup */ | |
125 | #define ASYNC_BUGGY_UART 0x4000 /* This is a buggy UART, skip some safety | 127 | #define ASYNCB_CLOSING 27 /* Serial port is closing */ |
126 | * checks. Note: can be dangerous! */ | 128 | #define ASYNCB_CTS_FLOW 26 /* Do CTS flow control */ |
127 | 129 | #define ASYNCB_CHECK_CD 25 /* i.e., CLOCAL */ | |
128 | #define ASYNC_AUTOPROBE 0x8000 /* Port was autoprobed by PCI or PNP code */ | 130 | #define ASYNCB_SHARE_IRQ 24 /* for multifunction cards, no longer used */ |
129 | 131 | #define ASYNCB_CONS_FLOW 23 /* flow control for console */ | |
130 | #define ASYNC_FLAGS 0x7FFF /* Possible legal async flags */ | 132 | #define ASYNCB_BOOT_ONLYMCA 22 /* Probe only if MCA bus */ |
131 | #define ASYNC_USR_MASK 0x3430 /* Legal flags that non-privileged | 133 | #define ASYNCB_FIRST_KERNEL 22 |
132 | * users can set or reset */ | 134 | |
133 | 135 | #define ASYNC_HUP_NOTIFY (1U << ASYNCB_HUP_NOTIFY) | |
134 | /* Internal flags used only by kernel/chr_drv/serial.c */ | 136 | #define ASYNC_FOURPORT (1U << ASYNCB_FOURPORT) |
135 | #define ASYNC_INITIALIZED 0x80000000 /* Serial port was initialized */ | 137 | #define ASYNC_SAK (1U << ASYNCB_SAK) |
136 | #define ASYNC_NORMAL_ACTIVE 0x20000000 /* Normal device is active */ | 138 | #define ASYNC_SPLIT_TERMIOS (1U << ASYNCB_SPLIT_TERMIOS) |
137 | #define ASYNC_BOOT_AUTOCONF 0x10000000 /* Autoconfigure port on bootup */ | 139 | #define ASYNC_SPD_HI (1U << ASYNCB_SPD_HI) |
138 | #define ASYNC_CLOSING 0x08000000 /* Serial port is closing */ | 140 | #define ASYNC_SPD_VHI (1U << ASYNCB_SPD_VHI) |
139 | #define ASYNC_CTS_FLOW 0x04000000 /* Do CTS flow control */ | 141 | #define ASYNC_SKIP_TEST (1U << ASYNCB_SKIP_TEST) |
140 | #define ASYNC_CHECK_CD 0x02000000 /* i.e., CLOCAL */ | 142 | #define ASYNC_AUTO_IRQ (1U << ASYNCB_AUTO_IRQ) |
141 | #define ASYNC_SHARE_IRQ 0x01000000 /* for multifunction cards | 143 | #define ASYNC_SESSION_LOCKOUT (1U << ASYNCB_SESSION_LOCKOUT) |
142 | --- no longer used */ | 144 | #define ASYNC_PGRP_LOCKOUT (1U << ASYNCB_PGRP_LOCKOUT) |
143 | #define ASYNC_CONS_FLOW 0x00800000 /* flow control for console */ | 145 | #define ASYNC_CALLOUT_NOHUP (1U << ASYNCB_CALLOUT_NOHUP) |
144 | 146 | #define ASYNC_HARDPPS_CD (1U << ASYNCB_HARDPPS_CD) | |
145 | #define ASYNC_BOOT_ONLYMCA 0x00400000 /* Probe only if MCA bus */ | 147 | #define ASYNC_SPD_SHI (1U << ASYNCB_SPD_SHI) |
146 | #define ASYNC_INTERNAL_FLAGS 0xFFC00000 /* Internal flags */ | 148 | #define ASYNC_LOW_LATENCY (1U << ASYNCB_LOW_LATENCY) |
149 | #define ASYNC_BUGGY_UART (1U << ASYNCB_BUGGY_UART) | ||
150 | #define ASYNC_AUTOPROBE (1U << ASYNCB_AUTOPROBE) | ||
151 | |||
152 | #define ASYNC_FLAGS ((1U << ASYNCB_LAST_USER) - 1) | ||
153 | #define ASYNC_USR_MASK (ASYNC_SPD_HI|ASYNC_SPD_VHI| \ | ||
154 | ASYNC_CALLOUT_NOHUP|ASYNC_SPD_SHI|ASYNC_LOW_LATENCY) | ||
155 | #define ASYNC_SPD_CUST (ASYNC_SPD_HI|ASYNC_SPD_VHI) | ||
156 | #define ASYNC_SPD_WARP (ASYNC_SPD_HI|ASYNC_SPD_SHI) | ||
157 | #define ASYNC_SPD_MASK (ASYNC_SPD_HI|ASYNC_SPD_VHI|ASYNC_SPD_SHI) | ||
158 | |||
159 | #define ASYNC_INITIALIZED (1U << ASYNCB_INITIALIZED) | ||
160 | #define ASYNC_NORMAL_ACTIVE (1U << ASYNCB_NORMAL_ACTIVE) | ||
161 | #define ASYNC_BOOT_AUTOCONF (1U << ASYNCB_BOOT_AUTOCONF) | ||
162 | #define ASYNC_CLOSING (1U << ASYNCB_CLOSING) | ||
163 | #define ASYNC_CTS_FLOW (1U << ASYNCB_CTS_FLOW) | ||
164 | #define ASYNC_CHECK_CD (1U << ASYNCB_CHECK_CD) | ||
165 | #define ASYNC_SHARE_IRQ (1U << ASYNCB_SHARE_IRQ) | ||
166 | #define ASYNC_CONS_FLOW (1U << ASYNCB_CONS_FLOW) | ||
167 | #define ASYNC_BOOT_ONLYMCA (1U << ASYNCB_BOOT_ONLYMCA) | ||
168 | #define ASYNC_INTERNAL_FLAGS (~((1U << ASYNCB_FIRST_KERNEL) - 1)) | ||
147 | 169 | ||
148 | /* | 170 | /* |
149 | * Multiport serial configuration structure --- external structure | 171 | * Multiport serial configuration structure --- external structure |
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index 57a97e52e58d..6fd80c4243f1 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h | |||
@@ -41,7 +41,8 @@ | |||
41 | #define PORT_XSCALE 15 | 41 | #define PORT_XSCALE 15 |
42 | #define PORT_RM9000 16 /* PMC-Sierra RM9xxx internal UART */ | 42 | #define PORT_RM9000 16 /* PMC-Sierra RM9xxx internal UART */ |
43 | #define PORT_OCTEON 17 /* Cavium OCTEON internal UART */ | 43 | #define PORT_OCTEON 17 /* Cavium OCTEON internal UART */ |
44 | #define PORT_MAX_8250 17 /* max port ID */ | 44 | #define PORT_AR7 18 /* Texas Instruments AR7 internal UART */ |
45 | #define PORT_MAX_8250 18 /* max port ID */ | ||
45 | 46 | ||
46 | /* | 47 | /* |
47 | * ARM specific type numbers. These are not currently guaranteed | 48 | * ARM specific type numbers. These are not currently guaranteed |
@@ -167,6 +168,9 @@ | |||
167 | /* MAX3100 */ | 168 | /* MAX3100 */ |
168 | #define PORT_MAX3100 86 | 169 | #define PORT_MAX3100 86 |
169 | 170 | ||
171 | /* Timberdale UART */ | ||
172 | #define PORT_TIMBUART 87 | ||
173 | |||
170 | #ifdef __KERNEL__ | 174 | #ifdef __KERNEL__ |
171 | 175 | ||
172 | #include <linux/compiler.h> | 176 | #include <linux/compiler.h> |
diff --git a/include/linux/tty.h b/include/linux/tty.h index fc39db95499f..1488d8c81aac 100644 --- a/include/linux/tty.h +++ b/include/linux/tty.h | |||
@@ -185,7 +185,7 @@ struct tty_port; | |||
185 | struct tty_port_operations { | 185 | struct tty_port_operations { |
186 | /* Return 1 if the carrier is raised */ | 186 | /* Return 1 if the carrier is raised */ |
187 | int (*carrier_raised)(struct tty_port *port); | 187 | int (*carrier_raised)(struct tty_port *port); |
188 | void (*raise_dtr_rts)(struct tty_port *port); | 188 | void (*dtr_rts)(struct tty_port *port, int raise); |
189 | }; | 189 | }; |
190 | 190 | ||
191 | struct tty_port { | 191 | struct tty_port { |
@@ -201,6 +201,9 @@ struct tty_port { | |||
201 | unsigned char *xmit_buf; /* Optional buffer */ | 201 | unsigned char *xmit_buf; /* Optional buffer */ |
202 | int close_delay; /* Close port delay */ | 202 | int close_delay; /* Close port delay */ |
203 | int closing_wait; /* Delay for output */ | 203 | int closing_wait; /* Delay for output */ |
204 | int drain_delay; /* Set to zero if no pure time | ||
205 | based drain is needed else | ||
206 | set to size of fifo */ | ||
204 | }; | 207 | }; |
205 | 208 | ||
206 | /* | 209 | /* |
@@ -223,8 +226,11 @@ struct tty_struct { | |||
223 | struct tty_driver *driver; | 226 | struct tty_driver *driver; |
224 | const struct tty_operations *ops; | 227 | const struct tty_operations *ops; |
225 | int index; | 228 | int index; |
226 | /* The ldisc objects are protected by tty_ldisc_lock at the moment */ | 229 | |
227 | struct tty_ldisc ldisc; | 230 | /* Protects ldisc changes: Lock tty not pty */ |
231 | struct mutex ldisc_mutex; | ||
232 | struct tty_ldisc *ldisc; | ||
233 | |||
228 | struct mutex termios_mutex; | 234 | struct mutex termios_mutex; |
229 | spinlock_t ctrl_lock; | 235 | spinlock_t ctrl_lock; |
230 | /* Termios values are protected by the termios mutex */ | 236 | /* Termios values are protected by the termios mutex */ |
@@ -311,6 +317,7 @@ struct tty_struct { | |||
311 | #define TTY_CLOSING 7 /* ->close() in progress */ | 317 | #define TTY_CLOSING 7 /* ->close() in progress */ |
312 | #define TTY_LDISC 9 /* Line discipline attached */ | 318 | #define TTY_LDISC 9 /* Line discipline attached */ |
313 | #define TTY_LDISC_CHANGING 10 /* Line discipline changing */ | 319 | #define TTY_LDISC_CHANGING 10 /* Line discipline changing */ |
320 | #define TTY_LDISC_OPEN 11 /* Line discipline is open */ | ||
314 | #define TTY_HW_COOK_OUT 14 /* Hardware can do output cooking */ | 321 | #define TTY_HW_COOK_OUT 14 /* Hardware can do output cooking */ |
315 | #define TTY_HW_COOK_IN 15 /* Hardware can do input cooking */ | 322 | #define TTY_HW_COOK_IN 15 /* Hardware can do input cooking */ |
316 | #define TTY_PTY_LOCK 16 /* pty private */ | 323 | #define TTY_PTY_LOCK 16 /* pty private */ |
@@ -403,6 +410,7 @@ extern int tty_termios_hw_change(struct ktermios *a, struct ktermios *b); | |||
403 | extern struct tty_ldisc *tty_ldisc_ref(struct tty_struct *); | 410 | extern struct tty_ldisc *tty_ldisc_ref(struct tty_struct *); |
404 | extern void tty_ldisc_deref(struct tty_ldisc *); | 411 | extern void tty_ldisc_deref(struct tty_ldisc *); |
405 | extern struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *); | 412 | extern struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *); |
413 | extern void tty_ldisc_hangup(struct tty_struct *tty); | ||
406 | extern const struct file_operations tty_ldiscs_proc_fops; | 414 | extern const struct file_operations tty_ldiscs_proc_fops; |
407 | 415 | ||
408 | extern void tty_wakeup(struct tty_struct *tty); | 416 | extern void tty_wakeup(struct tty_struct *tty); |
@@ -425,6 +433,9 @@ extern struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx, | |||
425 | extern void tty_release_dev(struct file *filp); | 433 | extern void tty_release_dev(struct file *filp); |
426 | extern int tty_init_termios(struct tty_struct *tty); | 434 | extern int tty_init_termios(struct tty_struct *tty); |
427 | 435 | ||
436 | extern struct tty_struct *tty_pair_get_tty(struct tty_struct *tty); | ||
437 | extern struct tty_struct *tty_pair_get_pty(struct tty_struct *tty); | ||
438 | |||
428 | extern struct mutex tty_mutex; | 439 | extern struct mutex tty_mutex; |
429 | 440 | ||
430 | extern void tty_write_unlock(struct tty_struct *tty); | 441 | extern void tty_write_unlock(struct tty_struct *tty); |
@@ -438,6 +449,7 @@ extern struct tty_struct *tty_port_tty_get(struct tty_port *port); | |||
438 | extern void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty); | 449 | extern void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty); |
439 | extern int tty_port_carrier_raised(struct tty_port *port); | 450 | extern int tty_port_carrier_raised(struct tty_port *port); |
440 | extern void tty_port_raise_dtr_rts(struct tty_port *port); | 451 | extern void tty_port_raise_dtr_rts(struct tty_port *port); |
452 | extern void tty_port_lower_dtr_rts(struct tty_port *port); | ||
441 | extern void tty_port_hangup(struct tty_port *port); | 453 | extern void tty_port_hangup(struct tty_port *port); |
442 | extern int tty_port_block_til_ready(struct tty_port *port, | 454 | extern int tty_port_block_til_ready(struct tty_port *port, |
443 | struct tty_struct *tty, struct file *filp); | 455 | struct tty_struct *tty, struct file *filp); |
diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h index bcba84ea2d86..3566129384a4 100644 --- a/include/linux/tty_driver.h +++ b/include/linux/tty_driver.h | |||
@@ -127,7 +127,8 @@ | |||
127 | * the line discipline are close to full, and it should somehow | 127 | * the line discipline are close to full, and it should somehow |
128 | * signal that no more characters should be sent to the tty. | 128 | * signal that no more characters should be sent to the tty. |
129 | * | 129 | * |
130 | * Optional: Always invoke via tty_throttle(); | 130 | * Optional: Always invoke via tty_throttle(), called under the |
131 | * termios lock. | ||
131 | * | 132 | * |
132 | * void (*unthrottle)(struct tty_struct * tty); | 133 | * void (*unthrottle)(struct tty_struct * tty); |
133 | * | 134 | * |
@@ -135,7 +136,8 @@ | |||
135 | * that characters can now be sent to the tty without fear of | 136 | * that characters can now be sent to the tty without fear of |
136 | * overrunning the input buffers of the line disciplines. | 137 | * overrunning the input buffers of the line disciplines. |
137 | * | 138 | * |
138 | * Optional: Always invoke via tty_unthrottle(); | 139 | * Optional: Always invoke via tty_unthrottle(), called under the |
140 | * termios lock. | ||
139 | * | 141 | * |
140 | * void (*stop)(struct tty_struct *tty); | 142 | * void (*stop)(struct tty_struct *tty); |
141 | * | 143 | * |
diff --git a/include/linux/usb/serial.h b/include/linux/usb/serial.h index 625e9e4639c6..8cdfed738fe4 100644 --- a/include/linux/usb/serial.h +++ b/include/linux/usb/serial.h | |||
@@ -224,8 +224,7 @@ struct usb_serial_driver { | |||
224 | /* Called by console with tty = NULL and by tty */ | 224 | /* Called by console with tty = NULL and by tty */ |
225 | int (*open)(struct tty_struct *tty, | 225 | int (*open)(struct tty_struct *tty, |
226 | struct usb_serial_port *port, struct file *filp); | 226 | struct usb_serial_port *port, struct file *filp); |
227 | void (*close)(struct tty_struct *tty, | 227 | void (*close)(struct usb_serial_port *port); |
228 | struct usb_serial_port *port, struct file *filp); | ||
229 | int (*write)(struct tty_struct *tty, struct usb_serial_port *port, | 228 | int (*write)(struct tty_struct *tty, struct usb_serial_port *port, |
230 | const unsigned char *buf, int count); | 229 | const unsigned char *buf, int count); |
231 | /* Called only by the tty layer */ | 230 | /* Called only by the tty layer */ |
@@ -241,6 +240,10 @@ struct usb_serial_driver { | |||
241 | int (*tiocmget)(struct tty_struct *tty, struct file *file); | 240 | int (*tiocmget)(struct tty_struct *tty, struct file *file); |
242 | int (*tiocmset)(struct tty_struct *tty, struct file *file, | 241 | int (*tiocmset)(struct tty_struct *tty, struct file *file, |
243 | unsigned int set, unsigned int clear); | 242 | unsigned int set, unsigned int clear); |
243 | /* Called by the tty layer for port level work. There may or may not | ||
244 | be an attached tty at this point */ | ||
245 | void (*dtr_rts)(struct usb_serial_port *port, int on); | ||
246 | int (*carrier_raised)(struct usb_serial_port *port); | ||
244 | /* USB events */ | 247 | /* USB events */ |
245 | void (*read_int_callback)(struct urb *urb); | 248 | void (*read_int_callback)(struct urb *urb); |
246 | void (*write_int_callback)(struct urb *urb); | 249 | void (*write_int_callback)(struct urb *urb); |
@@ -283,8 +286,7 @@ extern int usb_serial_generic_open(struct tty_struct *tty, | |||
283 | struct usb_serial_port *port, struct file *filp); | 286 | struct usb_serial_port *port, struct file *filp); |
284 | extern int usb_serial_generic_write(struct tty_struct *tty, | 287 | extern int usb_serial_generic_write(struct tty_struct *tty, |
285 | struct usb_serial_port *port, const unsigned char *buf, int count); | 288 | struct usb_serial_port *port, const unsigned char *buf, int count); |
286 | extern void usb_serial_generic_close(struct tty_struct *tty, | 289 | extern void usb_serial_generic_close(struct usb_serial_port *port); |
287 | struct usb_serial_port *port, struct file *filp); | ||
288 | extern int usb_serial_generic_resume(struct usb_serial *serial); | 290 | extern int usb_serial_generic_resume(struct usb_serial *serial); |
289 | extern int usb_serial_generic_write_room(struct tty_struct *tty); | 291 | extern int usb_serial_generic_write_room(struct tty_struct *tty); |
290 | extern int usb_serial_generic_chars_in_buffer(struct tty_struct *tty); | 292 | extern int usb_serial_generic_chars_in_buffer(struct tty_struct *tty); |
diff --git a/lib/Kconfig b/lib/Kconfig index 8ade0a7a91e0..9960be04cbbe 100644 --- a/lib/Kconfig +++ b/lib/Kconfig | |||
@@ -10,6 +10,9 @@ menu "Library routines" | |||
10 | config BITREVERSE | 10 | config BITREVERSE |
11 | tristate | 11 | tristate |
12 | 12 | ||
13 | config RATIONAL | ||
14 | boolean | ||
15 | |||
13 | config GENERIC_FIND_FIRST_BIT | 16 | config GENERIC_FIND_FIRST_BIT |
14 | bool | 17 | bool |
15 | 18 | ||
diff --git a/lib/Makefile b/lib/Makefile index 33a40e40e3ee..1f6edefebffe 100644 --- a/lib/Makefile +++ b/lib/Makefile | |||
@@ -50,6 +50,7 @@ ifneq ($(CONFIG_HAVE_DEC_LOCK),y) | |||
50 | endif | 50 | endif |
51 | 51 | ||
52 | obj-$(CONFIG_BITREVERSE) += bitrev.o | 52 | obj-$(CONFIG_BITREVERSE) += bitrev.o |
53 | obj-$(CONFIG_RATIONAL) += rational.o | ||
53 | obj-$(CONFIG_CRC_CCITT) += crc-ccitt.o | 54 | obj-$(CONFIG_CRC_CCITT) += crc-ccitt.o |
54 | obj-$(CONFIG_CRC16) += crc16.o | 55 | obj-$(CONFIG_CRC16) += crc16.o |
55 | obj-$(CONFIG_CRC_T10DIF)+= crc-t10dif.o | 56 | obj-$(CONFIG_CRC_T10DIF)+= crc-t10dif.o |
diff --git a/lib/rational.c b/lib/rational.c new file mode 100644 index 000000000000..b3c099b5478e --- /dev/null +++ b/lib/rational.c | |||
@@ -0,0 +1,62 @@ | |||
1 | /* | ||
2 | * rational fractions | ||
3 | * | ||
4 | * Copyright (C) 2009 emlix GmbH, Oskar Schirmer <os@emlix.com> | ||
5 | * | ||
6 | * helper functions when coping with rational numbers | ||
7 | */ | ||
8 | |||
9 | #include <linux/rational.h> | ||
10 | |||
11 | /* | ||
12 | * calculate best rational approximation for a given fraction | ||
13 | * taking into account restricted register size, e.g. to find | ||
14 | * appropriate values for a pll with 5 bit denominator and | ||
15 | * 8 bit numerator register fields, trying to set up with a | ||
16 | * frequency ratio of 3.1415, one would say: | ||
17 | * | ||
18 | * rational_best_approximation(31415, 10000, | ||
19 | * (1 << 8) - 1, (1 << 5) - 1, &n, &d); | ||
20 | * | ||
21 | * you may look at given_numerator as a fixed point number, | ||
22 | * with the fractional part size described in given_denominator. | ||
23 | * | ||
24 | * for theoretical background, see: | ||
25 | * http://en.wikipedia.org/wiki/Continued_fraction | ||
26 | */ | ||
27 | |||
28 | void rational_best_approximation( | ||
29 | unsigned long given_numerator, unsigned long given_denominator, | ||
30 | unsigned long max_numerator, unsigned long max_denominator, | ||
31 | unsigned long *best_numerator, unsigned long *best_denominator) | ||
32 | { | ||
33 | unsigned long n, d, n0, d0, n1, d1; | ||
34 | n = given_numerator; | ||
35 | d = given_denominator; | ||
36 | n0 = d1 = 0; | ||
37 | n1 = d0 = 1; | ||
38 | for (;;) { | ||
39 | unsigned long t, a; | ||
40 | if ((n1 > max_numerator) || (d1 > max_denominator)) { | ||
41 | n1 = n0; | ||
42 | d1 = d0; | ||
43 | break; | ||
44 | } | ||
45 | if (d == 0) | ||
46 | break; | ||
47 | t = d; | ||
48 | a = n / d; | ||
49 | d = n % d; | ||
50 | n = t; | ||
51 | t = n0 + a * n1; | ||
52 | n0 = n1; | ||
53 | n1 = t; | ||
54 | t = d0 + a * d1; | ||
55 | d0 = d1; | ||
56 | d1 = t; | ||
57 | } | ||
58 | *best_numerator = n1; | ||
59 | *best_denominator = d1; | ||
60 | } | ||
61 | |||
62 | EXPORT_SYMBOL(rational_best_approximation); | ||