1 |
1275 |
phoenix |
/*
|
2 |
|
|
*
|
3 |
|
|
* BRIEF MODULE DESCRIPTION
|
4 |
|
|
* Au1x00 serial port driver.
|
5 |
|
|
*
|
6 |
|
|
* Copyright 2001 MontaVista Software Inc.
|
7 |
|
|
* Author: MontaVista Software, Inc.
|
8 |
|
|
* ppopov@mvista.com or source@mvista.com
|
9 |
|
|
*
|
10 |
|
|
* Derived almost entirely from drivers/char/serial.c:
|
11 |
|
|
*
|
12 |
|
|
* Copyright (C) 1991, 1992 Linus Torvalds
|
13 |
|
|
* Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997,
|
14 |
|
|
* 1998, 1999 Theodore Ts'o
|
15 |
|
|
*
|
16 |
|
|
* This program is free software; you can redistribute it and/or modify it
|
17 |
|
|
* under the terms of the GNU General Public License as published by the
|
18 |
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
19 |
|
|
* option) any later version.
|
20 |
|
|
*
|
21 |
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
22 |
|
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
23 |
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
24 |
|
|
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
25 |
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
26 |
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
27 |
|
|
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
28 |
|
|
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
29 |
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
30 |
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31 |
|
|
*
|
32 |
|
|
* You should have received a copy of the GNU General Public License along
|
33 |
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
34 |
|
|
* 675 Mass Ave, Cambridge, MA 02139, USA.
|
35 |
|
|
*/
|
36 |
|
|
|
37 |
|
|
static char *serial_version = "1.01";
|
38 |
|
|
static char *serial_revdate = "2001-02-08";
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
#include <linux/config.h>
|
42 |
|
|
#include <linux/version.h>
|
43 |
|
|
|
44 |
|
|
#undef SERIAL_PARANOIA_CHECK
|
45 |
|
|
#define CONFIG_SERIAL_NOPAUSE_IO
|
46 |
|
|
#define SERIAL_DO_RESTART
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
/* Set of debugging defines */
|
50 |
|
|
|
51 |
|
|
#undef SERIAL_DEBUG_INTR
|
52 |
|
|
#undef SERIAL_DEBUG_OPEN
|
53 |
|
|
#undef SERIAL_DEBUG_FLOW
|
54 |
|
|
#undef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
|
55 |
|
|
#undef SERIAL_DEBUG_PCI
|
56 |
|
|
#undef SERIAL_DEBUG_AUTOCONF
|
57 |
|
|
|
58 |
|
|
#ifdef MODULE
|
59 |
|
|
#undef CONFIG_AU1X00_SERIAL_CONSOLE
|
60 |
|
|
#endif
|
61 |
|
|
|
62 |
|
|
#define CONFIG_SERIAL_RSA
|
63 |
|
|
|
64 |
|
|
#define RS_STROBE_TIME (10*HZ)
|
65 |
|
|
#define RS_ISR_PASS_LIMIT 256
|
66 |
|
|
|
67 |
|
|
/*
|
68 |
|
|
* End of serial driver configuration section.
|
69 |
|
|
*/
|
70 |
|
|
|
71 |
|
|
#include <linux/module.h>
|
72 |
|
|
|
73 |
|
|
#include <linux/types.h>
|
74 |
|
|
#ifdef LOCAL_HEADERS
|
75 |
|
|
#include "serial_local.h"
|
76 |
|
|
#else
|
77 |
|
|
#include <linux/serial.h>
|
78 |
|
|
#include <linux/serialP.h>
|
79 |
|
|
#include <asm/au1000.h>
|
80 |
|
|
#include <asm/serial.h>
|
81 |
|
|
#define LOCAL_VERSTRING ""
|
82 |
|
|
#endif
|
83 |
|
|
|
84 |
|
|
#include <linux/errno.h>
|
85 |
|
|
#include <linux/signal.h>
|
86 |
|
|
#include <linux/sched.h>
|
87 |
|
|
#include <linux/timer.h>
|
88 |
|
|
#include <linux/interrupt.h>
|
89 |
|
|
#include <linux/tty.h>
|
90 |
|
|
#include <linux/tty_flip.h>
|
91 |
|
|
#include <linux/major.h>
|
92 |
|
|
#include <linux/string.h>
|
93 |
|
|
#include <linux/fcntl.h>
|
94 |
|
|
#include <linux/ptrace.h>
|
95 |
|
|
#include <linux/ioport.h>
|
96 |
|
|
#include <linux/mm.h>
|
97 |
|
|
#include <linux/slab.h>
|
98 |
|
|
#include <linux/init.h>
|
99 |
|
|
#include <asm/uaccess.h>
|
100 |
|
|
#include <linux/delay.h>
|
101 |
|
|
#ifdef CONFIG_AU1X00_SERIAL_CONSOLE
|
102 |
|
|
#include <linux/console.h>
|
103 |
|
|
#endif
|
104 |
|
|
#ifdef CONFIG_MAGIC_SYSRQ
|
105 |
|
|
#include <linux/sysrq.h>
|
106 |
|
|
#endif
|
107 |
|
|
|
108 |
|
|
#include <asm/system.h>
|
109 |
|
|
#include <asm/io.h>
|
110 |
|
|
#include <asm/irq.h>
|
111 |
|
|
#include <asm/bitops.h>
|
112 |
|
|
|
113 |
|
|
#ifdef CONFIG_MAC_SERIAL
|
114 |
|
|
#define SERIAL_DEV_OFFSET 2
|
115 |
|
|
#else
|
116 |
|
|
#define SERIAL_DEV_OFFSET 0
|
117 |
|
|
#endif
|
118 |
|
|
|
119 |
|
|
#ifdef SERIAL_INLINE
|
120 |
|
|
#define _INLINE_ inline
|
121 |
|
|
#else
|
122 |
|
|
#define _INLINE_
|
123 |
|
|
#endif
|
124 |
|
|
|
125 |
|
|
static char *serial_name = "Serial driver";
|
126 |
|
|
|
127 |
|
|
static DECLARE_TASK_QUEUE(tq_serial);
|
128 |
|
|
|
129 |
|
|
static struct tty_driver serial_driver, callout_driver;
|
130 |
|
|
static int serial_refcount;
|
131 |
|
|
|
132 |
|
|
static struct timer_list serial_timer;
|
133 |
|
|
|
134 |
|
|
extern unsigned long get_au1x00_uart_baud_base(void);
|
135 |
|
|
|
136 |
|
|
/* serial subtype definitions */
|
137 |
|
|
#ifndef SERIAL_TYPE_NORMAL
|
138 |
|
|
#define SERIAL_TYPE_NORMAL 1
|
139 |
|
|
#define SERIAL_TYPE_CALLOUT 2
|
140 |
|
|
#endif
|
141 |
|
|
|
142 |
|
|
/* number of characters left in xmit buffer before we ask for more */
|
143 |
|
|
#define WAKEUP_CHARS 256
|
144 |
|
|
|
145 |
|
|
/*
|
146 |
|
|
* IRQ_timeout - How long the timeout should be for each IRQ
|
147 |
|
|
* should be after the IRQ has been active.
|
148 |
|
|
*/
|
149 |
|
|
|
150 |
|
|
static struct async_struct *IRQ_ports[NR_IRQS];
|
151 |
|
|
static int IRQ_timeout[NR_IRQS];
|
152 |
|
|
#ifdef CONFIG_AU1X00_SERIAL_CONSOLE
|
153 |
|
|
static struct console sercons;
|
154 |
|
|
static int lsr_break_flag;
|
155 |
|
|
#endif
|
156 |
|
|
#if defined(CONFIG_AU1X00_SERIAL_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
|
157 |
|
|
static unsigned long break_pressed; /* break, really ... */
|
158 |
|
|
#endif
|
159 |
|
|
|
160 |
|
|
static void autoconfig(struct serial_state * state);
|
161 |
|
|
static void change_speed(struct async_struct *info, struct termios *old);
|
162 |
|
|
static void rs_wait_until_sent(struct tty_struct *tty, int timeout);
|
163 |
|
|
|
164 |
|
|
/*
|
165 |
|
|
* Here we define the default xmit fifo size used for each type of
|
166 |
|
|
* UART
|
167 |
|
|
*/
|
168 |
|
|
static struct serial_uart_config uart_config[] = {
|
169 |
|
|
{ "unknown", 1, 0 },
|
170 |
|
|
{ "8250", 1, 0 },
|
171 |
|
|
{ "16450", 1, 0 },
|
172 |
|
|
{ "16550", 1, 0 },
|
173 |
|
|
{ 0, 0}
|
174 |
|
|
};
|
175 |
|
|
|
176 |
|
|
|
177 |
|
|
static struct serial_state rs_table[RS_TABLE_SIZE] = {
|
178 |
|
|
SERIAL_PORT_DFNS /* Defined in serial.h */
|
179 |
|
|
};
|
180 |
|
|
|
181 |
|
|
#define NR_PORTS (sizeof(rs_table)/sizeof(struct serial_state))
|
182 |
|
|
|
183 |
|
|
#ifndef PREPARE_FUNC
|
184 |
|
|
#define PREPARE_FUNC(dev) (dev->prepare)
|
185 |
|
|
#define ACTIVATE_FUNC(dev) (dev->activate)
|
186 |
|
|
#define DEACTIVATE_FUNC(dev) (dev->deactivate)
|
187 |
|
|
#endif
|
188 |
|
|
|
189 |
|
|
#define HIGH_BITS_OFFSET ((sizeof(long)-sizeof(int))*8)
|
190 |
|
|
|
191 |
|
|
static struct tty_struct *serial_table[NR_PORTS];
|
192 |
|
|
static struct termios *serial_termios[NR_PORTS];
|
193 |
|
|
static struct termios *serial_termios_locked[NR_PORTS];
|
194 |
|
|
|
195 |
|
|
|
196 |
|
|
#if defined(MODULE) && defined(SERIAL_DEBUG_MCOUNT)
|
197 |
|
|
#define DBG_CNT(s) printk("(%s): [%x] refc=%d, serc=%d, ttyc=%d -> %s\n", \
|
198 |
|
|
kdevname(tty->device), (info->flags), serial_refcount,info->count,tty->count,s)
|
199 |
|
|
#else
|
200 |
|
|
#define DBG_CNT(s)
|
201 |
|
|
#endif
|
202 |
|
|
|
203 |
|
|
/*
|
204 |
|
|
* tmp_buf is used as a temporary buffer by serial_write. We need to
|
205 |
|
|
* lock it in case the copy_from_user blocks while swapping in a page,
|
206 |
|
|
* and some other program tries to do a serial write at the same time.
|
207 |
|
|
* Since the lock will only come under contention when the system is
|
208 |
|
|
* swapping and available memory is low, it makes sense to share one
|
209 |
|
|
* buffer across all the serial ports, since it significantly saves
|
210 |
|
|
* memory if large numbers of serial ports are open.
|
211 |
|
|
*/
|
212 |
|
|
static unsigned char *tmp_buf;
|
213 |
|
|
#ifdef DECLARE_MUTEX
|
214 |
|
|
static DECLARE_MUTEX(tmp_buf_sem);
|
215 |
|
|
#else
|
216 |
|
|
static struct semaphore tmp_buf_sem = MUTEX;
|
217 |
|
|
#endif
|
218 |
|
|
|
219 |
|
|
static spinlock_t serial_lock = SPIN_LOCK_UNLOCKED;
|
220 |
|
|
|
221 |
|
|
static inline int serial_paranoia_check(struct async_struct *info,
|
222 |
|
|
kdev_t device, const char *routine)
|
223 |
|
|
{
|
224 |
|
|
#ifdef SERIAL_PARANOIA_CHECK
|
225 |
|
|
static const char *badmagic =
|
226 |
|
|
"Warning: bad magic number for serial struct (%s) in %s\n";
|
227 |
|
|
static const char *badinfo =
|
228 |
|
|
"Warning: null async_struct for (%s) in %s\n";
|
229 |
|
|
|
230 |
|
|
if (!info) {
|
231 |
|
|
printk(badinfo, kdevname(device), routine);
|
232 |
|
|
return 1;
|
233 |
|
|
}
|
234 |
|
|
if (info->magic != SERIAL_MAGIC) {
|
235 |
|
|
printk(badmagic, kdevname(device), routine);
|
236 |
|
|
return 1;
|
237 |
|
|
}
|
238 |
|
|
#endif
|
239 |
|
|
return 0;
|
240 |
|
|
}
|
241 |
|
|
|
242 |
|
|
static _INLINE_ unsigned int serial_in(struct async_struct *info, int offset)
|
243 |
|
|
{
|
244 |
|
|
return (au_readl(info->port+offset) & 0xffff);
|
245 |
|
|
}
|
246 |
|
|
|
247 |
|
|
static _INLINE_ void serial_out(struct async_struct *info, int offset, int value)
|
248 |
|
|
{
|
249 |
|
|
au_writel(value & 0xffff, info->port+offset);
|
250 |
|
|
}
|
251 |
|
|
|
252 |
|
|
|
253 |
|
|
/*
|
254 |
|
|
* We used to support using pause I/O for certain machines. We
|
255 |
|
|
* haven't supported this for a while, but just in case it's badly
|
256 |
|
|
* needed for certain old 386 machines, I've left these #define's
|
257 |
|
|
* in....
|
258 |
|
|
*/
|
259 |
|
|
#define serial_inp(info, offset) serial_in(info, offset)
|
260 |
|
|
#define serial_outp(info, offset, value) serial_out(info, offset, value)
|
261 |
|
|
|
262 |
|
|
|
263 |
|
|
/*
|
264 |
|
|
* ------------------------------------------------------------
|
265 |
|
|
* rs_stop() and rs_start()
|
266 |
|
|
*
|
267 |
|
|
* This routines are called before setting or resetting tty->stopped.
|
268 |
|
|
* They enable or disable transmitter interrupts, as necessary.
|
269 |
|
|
* ------------------------------------------------------------
|
270 |
|
|
*/
|
271 |
|
|
static void rs_stop(struct tty_struct *tty)
|
272 |
|
|
{
|
273 |
|
|
struct async_struct *info = (struct async_struct *)tty->driver_data;
|
274 |
|
|
unsigned long flags;
|
275 |
|
|
|
276 |
|
|
if (serial_paranoia_check(info, tty->device, "rs_stop"))
|
277 |
|
|
return;
|
278 |
|
|
|
279 |
|
|
spin_lock_irqsave(&serial_lock, flags);
|
280 |
|
|
if (info->IER & UART_IER_THRI) {
|
281 |
|
|
info->IER &= ~UART_IER_THRI;
|
282 |
|
|
serial_out(info, UART_IER, info->IER);
|
283 |
|
|
}
|
284 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
285 |
|
|
}
|
286 |
|
|
|
287 |
|
|
static void rs_start(struct tty_struct *tty)
|
288 |
|
|
{
|
289 |
|
|
struct async_struct *info = (struct async_struct *)tty->driver_data;
|
290 |
|
|
unsigned long flags;
|
291 |
|
|
|
292 |
|
|
if (serial_paranoia_check(info, tty->device, "rs_start"))
|
293 |
|
|
return;
|
294 |
|
|
|
295 |
|
|
spin_lock_irqsave(&serial_lock, flags);
|
296 |
|
|
if (info->xmit.head != info->xmit.tail
|
297 |
|
|
&& info->xmit.buf
|
298 |
|
|
&& !(info->IER & UART_IER_THRI)) {
|
299 |
|
|
info->IER |= UART_IER_THRI;
|
300 |
|
|
serial_out(info, UART_IER, info->IER);
|
301 |
|
|
}
|
302 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
303 |
|
|
}
|
304 |
|
|
|
305 |
|
|
/*
|
306 |
|
|
* ----------------------------------------------------------------------
|
307 |
|
|
*
|
308 |
|
|
* Here starts the interrupt handling routines. All of the following
|
309 |
|
|
* subroutines are declared as inline and are folded into
|
310 |
|
|
* rs_interrupt(). They were separated out for readability's sake.
|
311 |
|
|
*
|
312 |
|
|
* Note: rs_interrupt() is a "fast" interrupt, which means that it
|
313 |
|
|
* runs with interrupts turned off. People who may want to modify
|
314 |
|
|
* rs_interrupt() should try to keep the interrupt handler as fast as
|
315 |
|
|
* possible. After you are done making modifications, it is not a bad
|
316 |
|
|
* idea to do:
|
317 |
|
|
*
|
318 |
|
|
* gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
|
319 |
|
|
*
|
320 |
|
|
* and look at the resulting assemble code in serial.s.
|
321 |
|
|
*
|
322 |
|
|
* - Ted Ts'o (tytso@mit.edu), 7-Mar-93
|
323 |
|
|
* -----------------------------------------------------------------------
|
324 |
|
|
*/
|
325 |
|
|
|
326 |
|
|
/*
|
327 |
|
|
* This routine is used by the interrupt handler to schedule
|
328 |
|
|
* processing in the software interrupt portion of the driver.
|
329 |
|
|
*/
|
330 |
|
|
static _INLINE_ void rs_sched_event(struct async_struct *info,
|
331 |
|
|
int event)
|
332 |
|
|
{
|
333 |
|
|
info->event |= 1 << event;
|
334 |
|
|
queue_task(&info->tqueue, &tq_serial);
|
335 |
|
|
mark_bh(SERIAL_BH);
|
336 |
|
|
}
|
337 |
|
|
|
338 |
|
|
static _INLINE_ void receive_chars(struct async_struct *info,
|
339 |
|
|
int *status, struct pt_regs * regs)
|
340 |
|
|
{
|
341 |
|
|
struct tty_struct *tty = info->tty;
|
342 |
|
|
unsigned char ch;
|
343 |
|
|
int ignored = 0;
|
344 |
|
|
struct async_icount *icount;
|
345 |
|
|
|
346 |
|
|
icount = &info->state->icount;
|
347 |
|
|
do {
|
348 |
|
|
ch = serial_inp(info, UART_RX);
|
349 |
|
|
if (tty->flip.count >= TTY_FLIPBUF_SIZE)
|
350 |
|
|
goto ignore_char;
|
351 |
|
|
*tty->flip.char_buf_ptr = ch;
|
352 |
|
|
icount->rx++;
|
353 |
|
|
|
354 |
|
|
#ifdef SERIAL_DEBUG_INTR
|
355 |
|
|
printk("DR%02x:%02x...", ch, *status);
|
356 |
|
|
#endif
|
357 |
|
|
*tty->flip.flag_buf_ptr = 0;
|
358 |
|
|
if (*status & (UART_LSR_BI | UART_LSR_PE |
|
359 |
|
|
UART_LSR_FE | UART_LSR_OE)) {
|
360 |
|
|
/*
|
361 |
|
|
* For statistics only
|
362 |
|
|
*/
|
363 |
|
|
if (*status & UART_LSR_BI) {
|
364 |
|
|
*status &= ~(UART_LSR_FE | UART_LSR_PE);
|
365 |
|
|
icount->brk++;
|
366 |
|
|
/*
|
367 |
|
|
* We do the SysRQ and SAK checking
|
368 |
|
|
* here because otherwise the break
|
369 |
|
|
* may get masked by ignore_status_mask
|
370 |
|
|
* or read_status_mask.
|
371 |
|
|
*/
|
372 |
|
|
#if defined(CONFIG_AU1X00_SERIAL_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
|
373 |
|
|
if (info->line == sercons.index) {
|
374 |
|
|
if (!break_pressed) {
|
375 |
|
|
break_pressed = jiffies;
|
376 |
|
|
goto ignore_char;
|
377 |
|
|
}
|
378 |
|
|
break_pressed = 0;
|
379 |
|
|
}
|
380 |
|
|
#endif
|
381 |
|
|
if (info->flags & ASYNC_SAK)
|
382 |
|
|
do_SAK(tty);
|
383 |
|
|
} else if (*status & UART_LSR_PE)
|
384 |
|
|
icount->parity++;
|
385 |
|
|
else if (*status & UART_LSR_FE)
|
386 |
|
|
icount->frame++;
|
387 |
|
|
if (*status & UART_LSR_OE)
|
388 |
|
|
icount->overrun++;
|
389 |
|
|
|
390 |
|
|
/*
|
391 |
|
|
* Now check to see if character should be
|
392 |
|
|
* ignored, and mask off conditions which
|
393 |
|
|
* should be ignored.
|
394 |
|
|
*/
|
395 |
|
|
if (*status & info->ignore_status_mask) {
|
396 |
|
|
if (++ignored > 100)
|
397 |
|
|
break;
|
398 |
|
|
goto ignore_char;
|
399 |
|
|
}
|
400 |
|
|
*status &= info->read_status_mask;
|
401 |
|
|
|
402 |
|
|
#ifdef CONFIG_AU1X00_SERIAL_CONSOLE
|
403 |
|
|
if (info->line == sercons.index) {
|
404 |
|
|
/* Recover the break flag from console xmit */
|
405 |
|
|
*status |= lsr_break_flag;
|
406 |
|
|
lsr_break_flag = 0;
|
407 |
|
|
}
|
408 |
|
|
#endif
|
409 |
|
|
if (*status & (UART_LSR_BI)) {
|
410 |
|
|
#ifdef SERIAL_DEBUG_INTR
|
411 |
|
|
printk("handling break....");
|
412 |
|
|
#endif
|
413 |
|
|
*tty->flip.flag_buf_ptr = TTY_BREAK;
|
414 |
|
|
} else if (*status & UART_LSR_PE)
|
415 |
|
|
*tty->flip.flag_buf_ptr = TTY_PARITY;
|
416 |
|
|
else if (*status & UART_LSR_FE)
|
417 |
|
|
*tty->flip.flag_buf_ptr = TTY_FRAME;
|
418 |
|
|
if (*status & UART_LSR_OE) {
|
419 |
|
|
/*
|
420 |
|
|
* Overrun is special, since it's
|
421 |
|
|
* reported immediately, and doesn't
|
422 |
|
|
* affect the current character
|
423 |
|
|
*/
|
424 |
|
|
tty->flip.count++;
|
425 |
|
|
tty->flip.flag_buf_ptr++;
|
426 |
|
|
tty->flip.char_buf_ptr++;
|
427 |
|
|
*tty->flip.flag_buf_ptr = TTY_OVERRUN;
|
428 |
|
|
if (tty->flip.count >= TTY_FLIPBUF_SIZE)
|
429 |
|
|
goto ignore_char;
|
430 |
|
|
}
|
431 |
|
|
}
|
432 |
|
|
#if defined(CONFIG_AU1X00_SERIAL_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
|
433 |
|
|
if (break_pressed && info->line == sercons.index) {
|
434 |
|
|
if (ch != 0 &&
|
435 |
|
|
time_before(jiffies, break_pressed + HZ*5)) {
|
436 |
|
|
handle_sysrq(ch, regs, NULL, NULL);
|
437 |
|
|
break_pressed = 0;
|
438 |
|
|
goto ignore_char;
|
439 |
|
|
}
|
440 |
|
|
break_pressed = 0;
|
441 |
|
|
}
|
442 |
|
|
#endif
|
443 |
|
|
tty->flip.flag_buf_ptr++;
|
444 |
|
|
tty->flip.char_buf_ptr++;
|
445 |
|
|
tty->flip.count++;
|
446 |
|
|
ignore_char:
|
447 |
|
|
*status = serial_inp(info, UART_LSR);
|
448 |
|
|
} while (*status & UART_LSR_DR);
|
449 |
|
|
tty_flip_buffer_push(tty);
|
450 |
|
|
}
|
451 |
|
|
|
452 |
|
|
static _INLINE_ void transmit_chars(struct async_struct *info, int *intr_done)
|
453 |
|
|
{
|
454 |
|
|
int count;
|
455 |
|
|
|
456 |
|
|
if (info->x_char) {
|
457 |
|
|
serial_outp(info, UART_TX, info->x_char);
|
458 |
|
|
info->state->icount.tx++;
|
459 |
|
|
info->x_char = 0;
|
460 |
|
|
if (intr_done)
|
461 |
|
|
*intr_done = 0;
|
462 |
|
|
return;
|
463 |
|
|
}
|
464 |
|
|
if (info->xmit.head == info->xmit.tail
|
465 |
|
|
|| info->tty->stopped
|
466 |
|
|
|| info->tty->hw_stopped) {
|
467 |
|
|
info->IER &= ~UART_IER_THRI;
|
468 |
|
|
serial_out(info, UART_IER, info->IER);
|
469 |
|
|
return;
|
470 |
|
|
}
|
471 |
|
|
|
472 |
|
|
count = info->xmit_fifo_size;
|
473 |
|
|
do {
|
474 |
|
|
serial_out(info, UART_TX, info->xmit.buf[info->xmit.tail]);
|
475 |
|
|
info->xmit.tail = (info->xmit.tail + 1) & (SERIAL_XMIT_SIZE-1);
|
476 |
|
|
info->state->icount.tx++;
|
477 |
|
|
if (info->xmit.head == info->xmit.tail)
|
478 |
|
|
break;
|
479 |
|
|
} while (--count > 0);
|
480 |
|
|
|
481 |
|
|
if (CIRC_CNT(info->xmit.head,
|
482 |
|
|
info->xmit.tail,
|
483 |
|
|
SERIAL_XMIT_SIZE) < WAKEUP_CHARS)
|
484 |
|
|
rs_sched_event(info, RS_EVENT_WRITE_WAKEUP);
|
485 |
|
|
|
486 |
|
|
#ifdef SERIAL_DEBUG_INTR
|
487 |
|
|
printk("THRE...");
|
488 |
|
|
#endif
|
489 |
|
|
if (intr_done)
|
490 |
|
|
*intr_done = 0;
|
491 |
|
|
|
492 |
|
|
if (info->xmit.head == info->xmit.tail) {
|
493 |
|
|
info->IER &= ~UART_IER_THRI;
|
494 |
|
|
serial_out(info, UART_IER, info->IER);
|
495 |
|
|
}
|
496 |
|
|
}
|
497 |
|
|
|
498 |
|
|
static _INLINE_ void check_modem_status(struct async_struct *info)
|
499 |
|
|
{
|
500 |
|
|
int status;
|
501 |
|
|
struct async_icount *icount;
|
502 |
|
|
|
503 |
|
|
status = serial_in(info, UART_MSR);
|
504 |
|
|
|
505 |
|
|
if (status & UART_MSR_ANY_DELTA) {
|
506 |
|
|
icount = &info->state->icount;
|
507 |
|
|
/* update input line counters */
|
508 |
|
|
if (status & UART_MSR_TERI)
|
509 |
|
|
icount->rng++;
|
510 |
|
|
if (status & UART_MSR_DDSR)
|
511 |
|
|
icount->dsr++;
|
512 |
|
|
if (status & UART_MSR_DDCD) {
|
513 |
|
|
icount->dcd++;
|
514 |
|
|
#ifdef CONFIG_HARD_PPS
|
515 |
|
|
if ((info->flags & ASYNC_HARDPPS_CD) &&
|
516 |
|
|
(status & UART_MSR_DCD))
|
517 |
|
|
hardpps();
|
518 |
|
|
#endif
|
519 |
|
|
}
|
520 |
|
|
if (status & UART_MSR_DCTS)
|
521 |
|
|
icount->cts++;
|
522 |
|
|
wake_up_interruptible(&info->delta_msr_wait);
|
523 |
|
|
}
|
524 |
|
|
|
525 |
|
|
if ((info->flags & ASYNC_CHECK_CD) && (status & UART_MSR_DDCD)) {
|
526 |
|
|
#if (defined(SERIAL_DEBUG_OPEN) || defined(SERIAL_DEBUG_INTR))
|
527 |
|
|
printk("ttys%d CD now %s...", info->line,
|
528 |
|
|
(status & UART_MSR_DCD) ? "on" : "off");
|
529 |
|
|
#endif
|
530 |
|
|
if (status & UART_MSR_DCD)
|
531 |
|
|
wake_up_interruptible(&info->open_wait);
|
532 |
|
|
else if (!((info->flags & ASYNC_CALLOUT_ACTIVE) &&
|
533 |
|
|
(info->flags & ASYNC_CALLOUT_NOHUP))) {
|
534 |
|
|
#ifdef SERIAL_DEBUG_OPEN
|
535 |
|
|
printk("doing serial hangup...");
|
536 |
|
|
#endif
|
537 |
|
|
if (info->tty)
|
538 |
|
|
tty_hangup(info->tty);
|
539 |
|
|
}
|
540 |
|
|
}
|
541 |
|
|
if (info->flags & ASYNC_CTS_FLOW) {
|
542 |
|
|
if (info->tty->hw_stopped) {
|
543 |
|
|
if (status & UART_MSR_CTS) {
|
544 |
|
|
#if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
|
545 |
|
|
printk("CTS tx start...");
|
546 |
|
|
#endif
|
547 |
|
|
info->tty->hw_stopped = 0;
|
548 |
|
|
info->IER |= UART_IER_THRI;
|
549 |
|
|
serial_out(info, UART_IER, info->IER);
|
550 |
|
|
rs_sched_event(info, RS_EVENT_WRITE_WAKEUP);
|
551 |
|
|
return;
|
552 |
|
|
}
|
553 |
|
|
} else {
|
554 |
|
|
if (!(status & UART_MSR_CTS)) {
|
555 |
|
|
#if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
|
556 |
|
|
printk("CTS tx stop...");
|
557 |
|
|
#endif
|
558 |
|
|
info->tty->hw_stopped = 1;
|
559 |
|
|
info->IER &= ~UART_IER_THRI;
|
560 |
|
|
serial_out(info, UART_IER, info->IER);
|
561 |
|
|
}
|
562 |
|
|
}
|
563 |
|
|
}
|
564 |
|
|
}
|
565 |
|
|
|
566 |
|
|
|
567 |
|
|
|
568 |
|
|
/*
|
569 |
|
|
* This is the serial driver's interrupt routine for a single port
|
570 |
|
|
*/
|
571 |
|
|
static void rs_interrupt_single(int irq, void *dev_id, struct pt_regs * regs)
|
572 |
|
|
{
|
573 |
|
|
int status;
|
574 |
|
|
int pass_counter = 0;
|
575 |
|
|
struct async_struct * info;
|
576 |
|
|
|
577 |
|
|
#ifdef SERIAL_DEBUG_INTR
|
578 |
|
|
printk("rs_interrupt_single(%d)...", irq);
|
579 |
|
|
#endif
|
580 |
|
|
|
581 |
|
|
info = IRQ_ports[irq];
|
582 |
|
|
if (!info || !info->tty)
|
583 |
|
|
return;
|
584 |
|
|
|
585 |
|
|
do {
|
586 |
|
|
status = serial_inp(info, UART_LSR);
|
587 |
|
|
#ifdef SERIAL_DEBUG_INTR
|
588 |
|
|
printk("status = %x...", status);
|
589 |
|
|
#endif
|
590 |
|
|
if (status & UART_LSR_DR)
|
591 |
|
|
receive_chars(info, &status, regs);
|
592 |
|
|
check_modem_status(info);
|
593 |
|
|
if (status & UART_LSR_THRE)
|
594 |
|
|
transmit_chars(info, 0);
|
595 |
|
|
if (pass_counter++ > RS_ISR_PASS_LIMIT) {
|
596 |
|
|
#if 0
|
597 |
|
|
printk("rs_single loop break.\n");
|
598 |
|
|
#endif
|
599 |
|
|
break;
|
600 |
|
|
}
|
601 |
|
|
} while (!(serial_in(info, UART_IIR) & UART_IIR_NO_INT));
|
602 |
|
|
info->last_active = jiffies;
|
603 |
|
|
#ifdef SERIAL_DEBUG_INTR
|
604 |
|
|
printk("end.\n");
|
605 |
|
|
#endif
|
606 |
|
|
}
|
607 |
|
|
|
608 |
|
|
|
609 |
|
|
/*
|
610 |
|
|
* -------------------------------------------------------------------
|
611 |
|
|
* Here ends the serial interrupt routines.
|
612 |
|
|
* -------------------------------------------------------------------
|
613 |
|
|
*/
|
614 |
|
|
|
615 |
|
|
/*
|
616 |
|
|
* This routine is used to handle the "bottom half" processing for the
|
617 |
|
|
* serial driver, known also the "software interrupt" processing.
|
618 |
|
|
* This processing is done at the kernel interrupt level, after the
|
619 |
|
|
* rs_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
|
620 |
|
|
* is where time-consuming activities which can not be done in the
|
621 |
|
|
* interrupt driver proper are done; the interrupt driver schedules
|
622 |
|
|
* them using rs_sched_event(), and they get done here.
|
623 |
|
|
*/
|
624 |
|
|
static void do_serial_bh(void)
|
625 |
|
|
{
|
626 |
|
|
run_task_queue(&tq_serial);
|
627 |
|
|
}
|
628 |
|
|
|
629 |
|
|
static void do_softint(void *private_)
|
630 |
|
|
{
|
631 |
|
|
struct async_struct *info = (struct async_struct *) private_;
|
632 |
|
|
struct tty_struct *tty;
|
633 |
|
|
|
634 |
|
|
tty = info->tty;
|
635 |
|
|
if (!tty)
|
636 |
|
|
return;
|
637 |
|
|
|
638 |
|
|
if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &info->event)) {
|
639 |
|
|
if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
|
640 |
|
|
tty->ldisc.write_wakeup)
|
641 |
|
|
(tty->ldisc.write_wakeup)(tty);
|
642 |
|
|
wake_up_interruptible(&tty->write_wait);
|
643 |
|
|
#ifdef SERIAL_HAVE_POLL_WAIT
|
644 |
|
|
wake_up_interruptible(&tty->poll_wait);
|
645 |
|
|
#endif
|
646 |
|
|
}
|
647 |
|
|
}
|
648 |
|
|
|
649 |
|
|
/*
|
650 |
|
|
* This subroutine is called when the RS_TIMER goes off. It is used
|
651 |
|
|
* by the serial driver to handle ports that do not have an interrupt
|
652 |
|
|
* (irq=0). This doesn't work very well for 16450's, but gives barely
|
653 |
|
|
* passable results for a 16550A. (Although at the expense of much
|
654 |
|
|
* CPU overhead).
|
655 |
|
|
*/
|
656 |
|
|
static void rs_timer(unsigned long dummy)
|
657 |
|
|
{
|
658 |
|
|
static unsigned long last_strobe;
|
659 |
|
|
struct async_struct *info;
|
660 |
|
|
unsigned int i;
|
661 |
|
|
unsigned long flags;
|
662 |
|
|
|
663 |
|
|
if ((jiffies - last_strobe) >= RS_STROBE_TIME) {
|
664 |
|
|
for (i=0; i < NR_IRQS; i++) {
|
665 |
|
|
info = IRQ_ports[i];
|
666 |
|
|
if (!info)
|
667 |
|
|
continue;
|
668 |
|
|
spin_lock_irqsave(&serial_lock, flags);
|
669 |
|
|
rs_interrupt_single(i, NULL, NULL);
|
670 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
671 |
|
|
}
|
672 |
|
|
}
|
673 |
|
|
last_strobe = jiffies;
|
674 |
|
|
mod_timer(&serial_timer, jiffies + RS_STROBE_TIME);
|
675 |
|
|
|
676 |
|
|
#if 0
|
677 |
|
|
if (IRQ_ports[0]) {
|
678 |
|
|
spin_lock_irqsave(&serial_lock, flags);
|
679 |
|
|
rs_interrupt_single(0, NULL, NULL);
|
680 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
681 |
|
|
|
682 |
|
|
mod_timer(&serial_timer, jiffies + IRQ_timeout[0]);
|
683 |
|
|
}
|
684 |
|
|
#endif
|
685 |
|
|
}
|
686 |
|
|
|
687 |
|
|
/*
|
688 |
|
|
* ---------------------------------------------------------------
|
689 |
|
|
* Low level utility subroutines for the serial driver: routines to
|
690 |
|
|
* figure out the appropriate timeout for an interrupt chain, routines
|
691 |
|
|
* to initialize and startup a serial port, and routines to shutdown a
|
692 |
|
|
* serial port. Useful stuff like that.
|
693 |
|
|
* ---------------------------------------------------------------
|
694 |
|
|
*/
|
695 |
|
|
|
696 |
|
|
/*
|
697 |
|
|
* This routine figures out the correct timeout for a particular IRQ.
|
698 |
|
|
* It uses the smallest timeout of all of the serial ports in a
|
699 |
|
|
* particular interrupt chain. Now only used for IRQ 0....
|
700 |
|
|
*/
|
701 |
|
|
static void figure_IRQ_timeout(int irq)
|
702 |
|
|
{
|
703 |
|
|
struct async_struct *info;
|
704 |
|
|
int timeout = 60*HZ; /* 60 seconds === a long time :-) */
|
705 |
|
|
|
706 |
|
|
info = IRQ_ports[irq];
|
707 |
|
|
if (!info) {
|
708 |
|
|
IRQ_timeout[irq] = 60*HZ;
|
709 |
|
|
return;
|
710 |
|
|
}
|
711 |
|
|
while (info) {
|
712 |
|
|
if (info->timeout < timeout)
|
713 |
|
|
timeout = info->timeout;
|
714 |
|
|
info = info->next_port;
|
715 |
|
|
}
|
716 |
|
|
if (!irq)
|
717 |
|
|
timeout = timeout / 2;
|
718 |
|
|
IRQ_timeout[irq] = (timeout > 3) ? timeout-2 : 1;
|
719 |
|
|
}
|
720 |
|
|
|
721 |
|
|
|
722 |
|
|
static int startup(struct async_struct * info)
|
723 |
|
|
{
|
724 |
|
|
unsigned long flags;
|
725 |
|
|
int retval=0;
|
726 |
|
|
void (*handler)(int, void *, struct pt_regs *);
|
727 |
|
|
struct serial_state *state= info->state;
|
728 |
|
|
unsigned long page;
|
729 |
|
|
|
730 |
|
|
page = get_zeroed_page(GFP_KERNEL);
|
731 |
|
|
if (!page)
|
732 |
|
|
return -ENOMEM;
|
733 |
|
|
|
734 |
|
|
spin_lock_irqsave(&serial_lock, flags);
|
735 |
|
|
|
736 |
|
|
if (info->flags & ASYNC_INITIALIZED) {
|
737 |
|
|
free_page(page);
|
738 |
|
|
goto errout;
|
739 |
|
|
}
|
740 |
|
|
|
741 |
|
|
if (!CONFIGURED_SERIAL_PORT(state) || !state->type) {
|
742 |
|
|
if (info->tty)
|
743 |
|
|
set_bit(TTY_IO_ERROR, &info->tty->flags);
|
744 |
|
|
free_page(page);
|
745 |
|
|
goto errout;
|
746 |
|
|
}
|
747 |
|
|
if (info->xmit.buf)
|
748 |
|
|
free_page(page);
|
749 |
|
|
else
|
750 |
|
|
info->xmit.buf = (unsigned char *) page;
|
751 |
|
|
|
752 |
|
|
|
753 |
|
|
if (au_readl(UART_MOD_CNTRL + state->port) != 0x3) {
|
754 |
|
|
au_writel(3, UART_MOD_CNTRL + state->port);
|
755 |
|
|
au_sync_delay(10);
|
756 |
|
|
}
|
757 |
|
|
#ifdef SERIAL_DEBUG_OPEN
|
758 |
|
|
printk("starting up ttys%d (irq %d)...", info->line, state->irq);
|
759 |
|
|
#endif
|
760 |
|
|
|
761 |
|
|
|
762 |
|
|
/*
|
763 |
|
|
* Clear the FIFO buffers and disable them
|
764 |
|
|
* (they will be reenabled in change_speed())
|
765 |
|
|
*/
|
766 |
|
|
if (uart_config[state->type].flags & UART_CLEAR_FIFO) {
|
767 |
|
|
serial_outp(info, UART_FCR, UART_FCR_ENABLE_FIFO);
|
768 |
|
|
serial_outp(info, UART_FCR, (UART_FCR_ENABLE_FIFO |
|
769 |
|
|
UART_FCR_CLEAR_RCVR |
|
770 |
|
|
UART_FCR_CLEAR_XMIT));
|
771 |
|
|
serial_outp(info, UART_FCR, 0);
|
772 |
|
|
}
|
773 |
|
|
|
774 |
|
|
/*
|
775 |
|
|
* Clear the interrupt registers.
|
776 |
|
|
*/
|
777 |
|
|
(void) serial_inp(info, UART_LSR);
|
778 |
|
|
(void) serial_inp(info, UART_RX);
|
779 |
|
|
(void) serial_inp(info, UART_IIR);
|
780 |
|
|
(void) serial_inp(info, UART_MSR);
|
781 |
|
|
|
782 |
|
|
/*
|
783 |
|
|
* At this point there's no way the LSR could still be 0xFF;
|
784 |
|
|
* if it is, then bail out, because there's likely no UART
|
785 |
|
|
* here.
|
786 |
|
|
*/
|
787 |
|
|
if (!(info->flags & ASYNC_BUGGY_UART) &&
|
788 |
|
|
(serial_inp(info, UART_LSR) == 0xff)) {
|
789 |
|
|
printk("LSR safety check engaged!\n");
|
790 |
|
|
if (capable(CAP_SYS_ADMIN)) {
|
791 |
|
|
if (info->tty)
|
792 |
|
|
set_bit(TTY_IO_ERROR, &info->tty->flags);
|
793 |
|
|
} else
|
794 |
|
|
retval = -ENODEV;
|
795 |
|
|
goto errout;
|
796 |
|
|
}
|
797 |
|
|
|
798 |
|
|
/*
|
799 |
|
|
* Allocate the IRQ if necessary
|
800 |
|
|
*/
|
801 |
|
|
#if 0
|
802 |
|
|
/* au1000, uart0 irq is 0 */
|
803 |
|
|
if (state->irq && (!IRQ_ports[state->irq] || !IRQ_ports[state->irq]->next_port)) {
|
804 |
|
|
#endif
|
805 |
|
|
if ((!IRQ_ports[state->irq] || !IRQ_ports[state->irq]->next_port)) {
|
806 |
|
|
if (IRQ_ports[state->irq]) {
|
807 |
|
|
retval = -EBUSY;
|
808 |
|
|
goto errout;
|
809 |
|
|
} else
|
810 |
|
|
handler = rs_interrupt_single;
|
811 |
|
|
|
812 |
|
|
retval = request_irq(state->irq, handler, SA_SHIRQ,
|
813 |
|
|
"serial", &IRQ_ports[state->irq]);
|
814 |
|
|
if (retval) {
|
815 |
|
|
if (capable(CAP_SYS_ADMIN)) {
|
816 |
|
|
if (info->tty)
|
817 |
|
|
set_bit(TTY_IO_ERROR,
|
818 |
|
|
&info->tty->flags);
|
819 |
|
|
retval = 0;
|
820 |
|
|
}
|
821 |
|
|
goto errout;
|
822 |
|
|
}
|
823 |
|
|
}
|
824 |
|
|
|
825 |
|
|
/*
|
826 |
|
|
* Insert serial port into IRQ chain.
|
827 |
|
|
*/
|
828 |
|
|
info->prev_port = 0;
|
829 |
|
|
info->next_port = IRQ_ports[state->irq];
|
830 |
|
|
if (info->next_port)
|
831 |
|
|
info->next_port->prev_port = info;
|
832 |
|
|
IRQ_ports[state->irq] = info;
|
833 |
|
|
figure_IRQ_timeout(state->irq);
|
834 |
|
|
|
835 |
|
|
/*
|
836 |
|
|
* Now, initialize the UART
|
837 |
|
|
*/
|
838 |
|
|
serial_outp(info, UART_LCR, UART_LCR_WLEN8);
|
839 |
|
|
|
840 |
|
|
info->MCR = 0;
|
841 |
|
|
if (info->tty->termios->c_cflag & CBAUD)
|
842 |
|
|
info->MCR = UART_MCR_DTR | UART_MCR_RTS;
|
843 |
|
|
{
|
844 |
|
|
if (state->irq != 0)
|
845 |
|
|
info->MCR |= UART_MCR_OUT2;
|
846 |
|
|
}
|
847 |
|
|
info->MCR |= ALPHA_KLUDGE_MCR; /* Don't ask */
|
848 |
|
|
serial_outp(info, UART_MCR, info->MCR);
|
849 |
|
|
|
850 |
|
|
/*
|
851 |
|
|
* Finally, enable interrupts
|
852 |
|
|
*/
|
853 |
|
|
info->IER = UART_IER_MSI | UART_IER_RLSI | UART_IER_RDI;
|
854 |
|
|
serial_outp(info, UART_IER, info->IER); /* enable interrupts */
|
855 |
|
|
|
856 |
|
|
|
857 |
|
|
/*
|
858 |
|
|
* And clear the interrupt registers again for luck.
|
859 |
|
|
*/
|
860 |
|
|
(void)serial_inp(info, UART_LSR);
|
861 |
|
|
(void)serial_inp(info, UART_RX);
|
862 |
|
|
(void)serial_inp(info, UART_IIR);
|
863 |
|
|
(void)serial_inp(info, UART_MSR);
|
864 |
|
|
|
865 |
|
|
if (info->tty)
|
866 |
|
|
clear_bit(TTY_IO_ERROR, &info->tty->flags);
|
867 |
|
|
info->xmit.head = info->xmit.tail = 0;
|
868 |
|
|
|
869 |
|
|
/*
|
870 |
|
|
* Set up serial timers...
|
871 |
|
|
*/
|
872 |
|
|
mod_timer(&serial_timer, jiffies + 2*HZ/100);
|
873 |
|
|
|
874 |
|
|
/*
|
875 |
|
|
* Set up the tty->alt_speed kludge
|
876 |
|
|
*/
|
877 |
|
|
if (info->tty) {
|
878 |
|
|
if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
|
879 |
|
|
info->tty->alt_speed = 57600;
|
880 |
|
|
if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
|
881 |
|
|
info->tty->alt_speed = 115200;
|
882 |
|
|
if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
|
883 |
|
|
info->tty->alt_speed = 230400;
|
884 |
|
|
if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
|
885 |
|
|
info->tty->alt_speed = 460800;
|
886 |
|
|
}
|
887 |
|
|
|
888 |
|
|
/*
|
889 |
|
|
* and set the speed of the serial port
|
890 |
|
|
*/
|
891 |
|
|
change_speed(info, 0);
|
892 |
|
|
|
893 |
|
|
info->flags |= ASYNC_INITIALIZED;
|
894 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
895 |
|
|
return 0;
|
896 |
|
|
|
897 |
|
|
errout:
|
898 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
899 |
|
|
return retval;
|
900 |
|
|
}
|
901 |
|
|
|
902 |
|
|
/*
|
903 |
|
|
* This routine will shutdown a serial port; interrupts are disabled, and
|
904 |
|
|
* DTR is dropped if the hangup on close termio flag is on.
|
905 |
|
|
*/
|
906 |
|
|
static void shutdown(struct async_struct * info)
|
907 |
|
|
{
|
908 |
|
|
unsigned long flags;
|
909 |
|
|
struct serial_state *state;
|
910 |
|
|
int retval;
|
911 |
|
|
|
912 |
|
|
if (!(info->flags & ASYNC_INITIALIZED))
|
913 |
|
|
return;
|
914 |
|
|
|
915 |
|
|
state = info->state;
|
916 |
|
|
|
917 |
|
|
#ifdef SERIAL_DEBUG_OPEN
|
918 |
|
|
printk("Shutting down serial port %d (irq %d)....", info->line,
|
919 |
|
|
state->irq);
|
920 |
|
|
#endif
|
921 |
|
|
|
922 |
|
|
spin_lock_irqsave(&serial_lock, flags);
|
923 |
|
|
|
924 |
|
|
/*
|
925 |
|
|
* clear delta_msr_wait queue to avoid mem leaks: we may free the irq
|
926 |
|
|
* here so the queue might never be waken up
|
927 |
|
|
*/
|
928 |
|
|
wake_up_interruptible(&info->delta_msr_wait);
|
929 |
|
|
|
930 |
|
|
/*
|
931 |
|
|
* First unlink the serial port from the IRQ chain...
|
932 |
|
|
*/
|
933 |
|
|
if (info->next_port)
|
934 |
|
|
info->next_port->prev_port = info->prev_port;
|
935 |
|
|
if (info->prev_port)
|
936 |
|
|
info->prev_port->next_port = info->next_port;
|
937 |
|
|
else
|
938 |
|
|
IRQ_ports[state->irq] = info->next_port;
|
939 |
|
|
figure_IRQ_timeout(state->irq);
|
940 |
|
|
|
941 |
|
|
/*
|
942 |
|
|
* Free the IRQ, if necessary
|
943 |
|
|
*/
|
944 |
|
|
// if (state->irq && (!IRQ_ports[state->irq] ||
|
945 |
|
|
if ((!IRQ_ports[state->irq] ||
|
946 |
|
|
!IRQ_ports[state->irq]->next_port)) {
|
947 |
|
|
if (IRQ_ports[state->irq]) {
|
948 |
|
|
free_irq(state->irq, &IRQ_ports[state->irq]);
|
949 |
|
|
retval = request_irq(state->irq, rs_interrupt_single,
|
950 |
|
|
SA_SHIRQ, "serial",
|
951 |
|
|
&IRQ_ports[state->irq]);
|
952 |
|
|
|
953 |
|
|
if (retval)
|
954 |
|
|
printk("serial shutdown: request_irq: error %d"
|
955 |
|
|
" Couldn't reacquire IRQ.\n", retval);
|
956 |
|
|
} else
|
957 |
|
|
free_irq(state->irq, &IRQ_ports[state->irq]);
|
958 |
|
|
}
|
959 |
|
|
|
960 |
|
|
if (info->xmit.buf) {
|
961 |
|
|
unsigned long pg = (unsigned long) info->xmit.buf;
|
962 |
|
|
info->xmit.buf = 0;
|
963 |
|
|
free_page(pg);
|
964 |
|
|
}
|
965 |
|
|
|
966 |
|
|
info->IER = 0;
|
967 |
|
|
serial_outp(info, UART_IER, 0x00); /* disable all intrs */
|
968 |
|
|
info->MCR &= ~UART_MCR_OUT2;
|
969 |
|
|
info->MCR |= ALPHA_KLUDGE_MCR; /* Don't ask */
|
970 |
|
|
|
971 |
|
|
/* disable break condition */
|
972 |
|
|
serial_out(info, UART_LCR, serial_inp(info, UART_LCR) & ~UART_LCR_SBC);
|
973 |
|
|
|
974 |
|
|
if (!info->tty || (info->tty->termios->c_cflag & HUPCL))
|
975 |
|
|
info->MCR &= ~(UART_MCR_DTR|UART_MCR_RTS);
|
976 |
|
|
serial_outp(info, UART_MCR, info->MCR);
|
977 |
|
|
|
978 |
|
|
/* disable FIFO's */
|
979 |
|
|
serial_outp(info, UART_FCR, (UART_FCR_ENABLE_FIFO |
|
980 |
|
|
UART_FCR_CLEAR_RCVR |
|
981 |
|
|
UART_FCR_CLEAR_XMIT));
|
982 |
|
|
serial_outp(info, UART_FCR, 0);
|
983 |
|
|
|
984 |
|
|
(void)serial_in(info, UART_RX); /* read data port to reset things */
|
985 |
|
|
|
986 |
|
|
if (info->tty)
|
987 |
|
|
set_bit(TTY_IO_ERROR, &info->tty->flags);
|
988 |
|
|
|
989 |
|
|
info->flags &= ~ASYNC_INITIALIZED;
|
990 |
|
|
#ifndef CONFIG_KGDB
|
991 |
|
|
au_writel(0, UART_MOD_CNTRL + state->port);
|
992 |
|
|
au_sync_delay(10);
|
993 |
|
|
#endif
|
994 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
995 |
|
|
}
|
996 |
|
|
|
997 |
|
|
|
998 |
|
|
/*
|
999 |
|
|
* This routine is called to set the UART divisor registers to match
|
1000 |
|
|
* the specified baud rate for a serial port.
|
1001 |
|
|
*/
|
1002 |
|
|
static void change_speed(struct async_struct *info,
|
1003 |
|
|
struct termios *old_termios)
|
1004 |
|
|
{
|
1005 |
|
|
int quot = 0, baud_base, baud;
|
1006 |
|
|
unsigned cflag, cval, fcr = 0;
|
1007 |
|
|
int bits;
|
1008 |
|
|
unsigned long flags;
|
1009 |
|
|
|
1010 |
|
|
if (!info->tty || !info->tty->termios)
|
1011 |
|
|
return;
|
1012 |
|
|
cflag = info->tty->termios->c_cflag;
|
1013 |
|
|
if (!CONFIGURED_SERIAL_PORT(info))
|
1014 |
|
|
return;
|
1015 |
|
|
|
1016 |
|
|
/* byte size and parity */
|
1017 |
|
|
switch (cflag & CSIZE) {
|
1018 |
|
|
case CS5: cval = 0x00; bits = 7; break;
|
1019 |
|
|
case CS6: cval = 0x01; bits = 8; break;
|
1020 |
|
|
case CS7: cval = 0x02; bits = 9; break;
|
1021 |
|
|
case CS8: cval = 0x03; bits = 10; break;
|
1022 |
|
|
/* Never happens, but GCC is too dumb to figure it out */
|
1023 |
|
|
default: cval = 0x00; bits = 7; break;
|
1024 |
|
|
}
|
1025 |
|
|
if (cflag & CSTOPB) {
|
1026 |
|
|
cval |= 0x04;
|
1027 |
|
|
bits++;
|
1028 |
|
|
}
|
1029 |
|
|
if (cflag & PARENB) {
|
1030 |
|
|
cval |= UART_LCR_PARITY;
|
1031 |
|
|
bits++;
|
1032 |
|
|
}
|
1033 |
|
|
if (!(cflag & PARODD))
|
1034 |
|
|
cval |= UART_LCR_EPAR;
|
1035 |
|
|
#ifdef CMSPAR
|
1036 |
|
|
if (cflag & CMSPAR)
|
1037 |
|
|
cval |= UART_LCR_SPAR;
|
1038 |
|
|
#endif
|
1039 |
|
|
|
1040 |
|
|
/* Determine divisor based on baud rate */
|
1041 |
|
|
baud = tty_get_baud_rate(info->tty);
|
1042 |
|
|
if (!baud) {
|
1043 |
|
|
baud = 9600; /* B0 transition handled in rs_set_termios */
|
1044 |
|
|
}
|
1045 |
|
|
baud_base = get_au1x00_uart_baud_base();
|
1046 |
|
|
|
1047 |
|
|
//if (baud == 38400 &&
|
1048 |
|
|
if (((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)) {
|
1049 |
|
|
quot = info->state->custom_divisor;
|
1050 |
|
|
}
|
1051 |
|
|
else {
|
1052 |
|
|
if (baud == 134)
|
1053 |
|
|
/* Special case since 134 is really 134.5 */
|
1054 |
|
|
quot = (2*baud_base / 269);
|
1055 |
|
|
else if (baud)
|
1056 |
|
|
quot = baud_base / baud;
|
1057 |
|
|
}
|
1058 |
|
|
/* If the quotient is zero refuse the change */
|
1059 |
|
|
if (!quot && old_termios) {
|
1060 |
|
|
info->tty->termios->c_cflag &= ~CBAUD;
|
1061 |
|
|
info->tty->termios->c_cflag |= (old_termios->c_cflag & CBAUD);
|
1062 |
|
|
baud = tty_get_baud_rate(info->tty);
|
1063 |
|
|
if (!baud)
|
1064 |
|
|
baud = 9600;
|
1065 |
|
|
if (baud == 38400 &&
|
1066 |
|
|
((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST))
|
1067 |
|
|
quot = info->state->custom_divisor;
|
1068 |
|
|
else {
|
1069 |
|
|
if (baud == 134)
|
1070 |
|
|
/* Special case since 134 is really 134.5 */
|
1071 |
|
|
quot = (2*baud_base / 269);
|
1072 |
|
|
else if (baud)
|
1073 |
|
|
quot = baud_base / baud;
|
1074 |
|
|
}
|
1075 |
|
|
}
|
1076 |
|
|
/* As a last resort, if the quotient is zero, default to 9600 bps */
|
1077 |
|
|
if (!quot)
|
1078 |
|
|
quot = baud_base / 9600;
|
1079 |
|
|
|
1080 |
|
|
info->quot = quot;
|
1081 |
|
|
info->timeout = ((info->xmit_fifo_size*HZ*bits*quot) / baud_base);
|
1082 |
|
|
info->timeout += HZ/50; /* Add .02 seconds of slop */
|
1083 |
|
|
|
1084 |
|
|
/* Set up FIFO's */
|
1085 |
|
|
if (uart_config[info->state->type].flags & UART_USE_FIFO) {
|
1086 |
|
|
if ((info->state->baud_base / quot) < 2400)
|
1087 |
|
|
fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIGGER_1;
|
1088 |
|
|
else
|
1089 |
|
|
fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIGGER_8;
|
1090 |
|
|
}
|
1091 |
|
|
|
1092 |
|
|
/* CTS flow control flag and modem status interrupts */
|
1093 |
|
|
info->IER &= ~UART_IER_MSI;
|
1094 |
|
|
if (info->flags & ASYNC_HARDPPS_CD)
|
1095 |
|
|
info->IER |= UART_IER_MSI;
|
1096 |
|
|
if (cflag & CRTSCTS) {
|
1097 |
|
|
info->flags |= ASYNC_CTS_FLOW;
|
1098 |
|
|
info->IER |= UART_IER_MSI;
|
1099 |
|
|
} else
|
1100 |
|
|
info->flags &= ~ASYNC_CTS_FLOW;
|
1101 |
|
|
if (cflag & CLOCAL)
|
1102 |
|
|
info->flags &= ~ASYNC_CHECK_CD;
|
1103 |
|
|
else {
|
1104 |
|
|
info->flags |= ASYNC_CHECK_CD;
|
1105 |
|
|
info->IER |= UART_IER_MSI;
|
1106 |
|
|
}
|
1107 |
|
|
serial_out(info, UART_IER, info->IER);
|
1108 |
|
|
|
1109 |
|
|
/*
|
1110 |
|
|
* Set up parity check flag
|
1111 |
|
|
*/
|
1112 |
|
|
#define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
|
1113 |
|
|
|
1114 |
|
|
info->read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
|
1115 |
|
|
if (I_INPCK(info->tty))
|
1116 |
|
|
info->read_status_mask |= UART_LSR_FE | UART_LSR_PE;
|
1117 |
|
|
if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
|
1118 |
|
|
info->read_status_mask |= UART_LSR_BI;
|
1119 |
|
|
|
1120 |
|
|
/*
|
1121 |
|
|
* Characters to ignore
|
1122 |
|
|
*/
|
1123 |
|
|
info->ignore_status_mask = 0;
|
1124 |
|
|
if (I_IGNPAR(info->tty))
|
1125 |
|
|
info->ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
|
1126 |
|
|
if (I_IGNBRK(info->tty)) {
|
1127 |
|
|
info->ignore_status_mask |= UART_LSR_BI;
|
1128 |
|
|
/*
|
1129 |
|
|
* If we're ignore parity and break indicators, ignore
|
1130 |
|
|
* overruns too. (For real raw support).
|
1131 |
|
|
*/
|
1132 |
|
|
if (I_IGNPAR(info->tty))
|
1133 |
|
|
info->ignore_status_mask |= UART_LSR_OE;
|
1134 |
|
|
}
|
1135 |
|
|
/*
|
1136 |
|
|
* !!! ignore all characters if CREAD is not set
|
1137 |
|
|
*/
|
1138 |
|
|
if ((cflag & CREAD) == 0)
|
1139 |
|
|
info->ignore_status_mask |= UART_LSR_DR;
|
1140 |
|
|
spin_lock_irqsave(&serial_lock, flags);
|
1141 |
|
|
|
1142 |
|
|
serial_outp(info, UART_CLK, quot & 0xffff);
|
1143 |
|
|
serial_outp(info, UART_LCR, cval);
|
1144 |
|
|
info->LCR = cval; /* Save LCR */
|
1145 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
1146 |
|
|
}
|
1147 |
|
|
|
1148 |
|
|
static void rs_put_char(struct tty_struct *tty, unsigned char ch)
|
1149 |
|
|
{
|
1150 |
|
|
struct async_struct *info = (struct async_struct *)tty->driver_data;
|
1151 |
|
|
unsigned long flags;
|
1152 |
|
|
|
1153 |
|
|
if (serial_paranoia_check(info, tty->device, "rs_put_char"))
|
1154 |
|
|
return;
|
1155 |
|
|
|
1156 |
|
|
if (!tty || !info->xmit.buf)
|
1157 |
|
|
return;
|
1158 |
|
|
|
1159 |
|
|
spin_lock_irqsave(&serial_lock, flags);
|
1160 |
|
|
if (CIRC_SPACE(info->xmit.head,
|
1161 |
|
|
info->xmit.tail,
|
1162 |
|
|
SERIAL_XMIT_SIZE) == 0) {
|
1163 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
1164 |
|
|
return;
|
1165 |
|
|
}
|
1166 |
|
|
|
1167 |
|
|
info->xmit.buf[info->xmit.head] = ch;
|
1168 |
|
|
info->xmit.head = (info->xmit.head + 1) & (SERIAL_XMIT_SIZE-1);
|
1169 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
1170 |
|
|
}
|
1171 |
|
|
|
1172 |
|
|
static void rs_flush_chars(struct tty_struct *tty)
|
1173 |
|
|
{
|
1174 |
|
|
struct async_struct *info = (struct async_struct *)tty->driver_data;
|
1175 |
|
|
unsigned long flags;
|
1176 |
|
|
|
1177 |
|
|
if (serial_paranoia_check(info, tty->device, "rs_flush_chars"))
|
1178 |
|
|
return;
|
1179 |
|
|
|
1180 |
|
|
if (info->xmit.head == info->xmit.tail
|
1181 |
|
|
|| tty->stopped
|
1182 |
|
|
|| tty->hw_stopped
|
1183 |
|
|
|| !info->xmit.buf)
|
1184 |
|
|
return;
|
1185 |
|
|
|
1186 |
|
|
spin_lock_irqsave(&serial_lock, flags);
|
1187 |
|
|
info->IER |= UART_IER_THRI;
|
1188 |
|
|
serial_out(info, UART_IER, info->IER);
|
1189 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
1190 |
|
|
}
|
1191 |
|
|
|
1192 |
|
|
static int rs_write(struct tty_struct * tty, int from_user,
|
1193 |
|
|
const unsigned char *buf, int count)
|
1194 |
|
|
{
|
1195 |
|
|
int c, ret = 0;
|
1196 |
|
|
struct async_struct *info = (struct async_struct *)tty->driver_data;
|
1197 |
|
|
unsigned long flags;
|
1198 |
|
|
|
1199 |
|
|
if (serial_paranoia_check(info, tty->device, "rs_write"))
|
1200 |
|
|
return 0;
|
1201 |
|
|
|
1202 |
|
|
if (!tty || !info->xmit.buf || !tmp_buf)
|
1203 |
|
|
return 0;
|
1204 |
|
|
|
1205 |
|
|
spin_lock_irqsave(&serial_lock, flags);
|
1206 |
|
|
if (from_user) {
|
1207 |
|
|
down(&tmp_buf_sem);
|
1208 |
|
|
while (1) {
|
1209 |
|
|
int c1;
|
1210 |
|
|
c = CIRC_SPACE_TO_END(info->xmit.head,
|
1211 |
|
|
info->xmit.tail,
|
1212 |
|
|
SERIAL_XMIT_SIZE);
|
1213 |
|
|
if (count < c)
|
1214 |
|
|
c = count;
|
1215 |
|
|
if (c <= 0)
|
1216 |
|
|
break;
|
1217 |
|
|
|
1218 |
|
|
c -= copy_from_user(tmp_buf, buf, c);
|
1219 |
|
|
if (!c) {
|
1220 |
|
|
if (!ret)
|
1221 |
|
|
ret = -EFAULT;
|
1222 |
|
|
break;
|
1223 |
|
|
}
|
1224 |
|
|
cli();
|
1225 |
|
|
c1 = CIRC_SPACE_TO_END(info->xmit.head,
|
1226 |
|
|
info->xmit.tail,
|
1227 |
|
|
SERIAL_XMIT_SIZE);
|
1228 |
|
|
if (c1 < c)
|
1229 |
|
|
c = c1;
|
1230 |
|
|
memcpy(info->xmit.buf + info->xmit.head, tmp_buf, c);
|
1231 |
|
|
info->xmit.head = ((info->xmit.head + c) &
|
1232 |
|
|
(SERIAL_XMIT_SIZE-1));
|
1233 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
1234 |
|
|
buf += c;
|
1235 |
|
|
count -= c;
|
1236 |
|
|
ret += c;
|
1237 |
|
|
}
|
1238 |
|
|
up(&tmp_buf_sem);
|
1239 |
|
|
} else {
|
1240 |
|
|
cli();
|
1241 |
|
|
while (1) {
|
1242 |
|
|
c = CIRC_SPACE_TO_END(info->xmit.head,
|
1243 |
|
|
info->xmit.tail,
|
1244 |
|
|
SERIAL_XMIT_SIZE);
|
1245 |
|
|
if (count < c)
|
1246 |
|
|
c = count;
|
1247 |
|
|
if (c <= 0) {
|
1248 |
|
|
break;
|
1249 |
|
|
}
|
1250 |
|
|
memcpy(info->xmit.buf + info->xmit.head, buf, c);
|
1251 |
|
|
info->xmit.head = ((info->xmit.head + c) &
|
1252 |
|
|
(SERIAL_XMIT_SIZE-1));
|
1253 |
|
|
buf += c;
|
1254 |
|
|
count -= c;
|
1255 |
|
|
ret += c;
|
1256 |
|
|
}
|
1257 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
1258 |
|
|
}
|
1259 |
|
|
if (info->xmit.head != info->xmit.tail
|
1260 |
|
|
&& !tty->stopped
|
1261 |
|
|
&& !tty->hw_stopped
|
1262 |
|
|
&& !(info->IER & UART_IER_THRI)) {
|
1263 |
|
|
info->IER |= UART_IER_THRI;
|
1264 |
|
|
serial_out(info, UART_IER, info->IER);
|
1265 |
|
|
}
|
1266 |
|
|
return ret;
|
1267 |
|
|
}
|
1268 |
|
|
|
1269 |
|
|
static int rs_write_room(struct tty_struct *tty)
|
1270 |
|
|
{
|
1271 |
|
|
struct async_struct *info = (struct async_struct *)tty->driver_data;
|
1272 |
|
|
|
1273 |
|
|
if (serial_paranoia_check(info, tty->device, "rs_write_room"))
|
1274 |
|
|
return 0;
|
1275 |
|
|
return CIRC_SPACE(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
|
1276 |
|
|
}
|
1277 |
|
|
|
1278 |
|
|
static int rs_chars_in_buffer(struct tty_struct *tty)
|
1279 |
|
|
{
|
1280 |
|
|
struct async_struct *info = (struct async_struct *)tty->driver_data;
|
1281 |
|
|
|
1282 |
|
|
if (serial_paranoia_check(info, tty->device, "rs_chars_in_buffer"))
|
1283 |
|
|
return 0;
|
1284 |
|
|
return CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
|
1285 |
|
|
}
|
1286 |
|
|
|
1287 |
|
|
static void rs_flush_buffer(struct tty_struct *tty)
|
1288 |
|
|
{
|
1289 |
|
|
struct async_struct *info = (struct async_struct *)tty->driver_data;
|
1290 |
|
|
unsigned long flags;
|
1291 |
|
|
|
1292 |
|
|
if (serial_paranoia_check(info, tty->device, "rs_flush_buffer"))
|
1293 |
|
|
return;
|
1294 |
|
|
spin_lock_irqsave(&serial_lock, flags);
|
1295 |
|
|
info->xmit.head = info->xmit.tail = 0;
|
1296 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
1297 |
|
|
wake_up_interruptible(&tty->write_wait);
|
1298 |
|
|
#ifdef SERIAL_HAVE_POLL_WAIT
|
1299 |
|
|
wake_up_interruptible(&tty->poll_wait);
|
1300 |
|
|
#endif
|
1301 |
|
|
if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
|
1302 |
|
|
tty->ldisc.write_wakeup)
|
1303 |
|
|
(tty->ldisc.write_wakeup)(tty);
|
1304 |
|
|
}
|
1305 |
|
|
|
1306 |
|
|
/*
|
1307 |
|
|
* This function is used to send a high-priority XON/XOFF character to
|
1308 |
|
|
* the device
|
1309 |
|
|
*/
|
1310 |
|
|
static void rs_send_xchar(struct tty_struct *tty, char ch)
|
1311 |
|
|
{
|
1312 |
|
|
struct async_struct *info = (struct async_struct *)tty->driver_data;
|
1313 |
|
|
|
1314 |
|
|
if (serial_paranoia_check(info, tty->device, "rs_send_char"))
|
1315 |
|
|
return;
|
1316 |
|
|
|
1317 |
|
|
info->x_char = ch;
|
1318 |
|
|
if (ch) {
|
1319 |
|
|
/* Make sure transmit interrupts are on */
|
1320 |
|
|
info->IER |= UART_IER_THRI;
|
1321 |
|
|
serial_out(info, UART_IER, info->IER);
|
1322 |
|
|
}
|
1323 |
|
|
}
|
1324 |
|
|
|
1325 |
|
|
/*
|
1326 |
|
|
* ------------------------------------------------------------
|
1327 |
|
|
* rs_throttle()
|
1328 |
|
|
*
|
1329 |
|
|
* This routine is called by the upper-layer tty layer to signal that
|
1330 |
|
|
* incoming characters should be throttled.
|
1331 |
|
|
* ------------------------------------------------------------
|
1332 |
|
|
*/
|
1333 |
|
|
static void rs_throttle(struct tty_struct * tty)
|
1334 |
|
|
{
|
1335 |
|
|
struct async_struct *info = (struct async_struct *)tty->driver_data;
|
1336 |
|
|
unsigned long flags;
|
1337 |
|
|
#ifdef SERIAL_DEBUG_THROTTLE
|
1338 |
|
|
char buf[64];
|
1339 |
|
|
|
1340 |
|
|
printk("throttle %s: %d....\n", tty_name(tty, buf),
|
1341 |
|
|
tty->ldisc.chars_in_buffer(tty));
|
1342 |
|
|
#endif
|
1343 |
|
|
|
1344 |
|
|
if (serial_paranoia_check(info, tty->device, "rs_throttle"))
|
1345 |
|
|
return;
|
1346 |
|
|
|
1347 |
|
|
if (I_IXOFF(tty))
|
1348 |
|
|
rs_send_xchar(tty, STOP_CHAR(tty));
|
1349 |
|
|
|
1350 |
|
|
if (tty->termios->c_cflag & CRTSCTS)
|
1351 |
|
|
info->MCR &= ~UART_MCR_RTS;
|
1352 |
|
|
|
1353 |
|
|
spin_lock_irqsave(&serial_lock, flags);
|
1354 |
|
|
serial_out(info, UART_MCR, info->MCR);
|
1355 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
1356 |
|
|
}
|
1357 |
|
|
|
1358 |
|
|
static void rs_unthrottle(struct tty_struct * tty)
|
1359 |
|
|
{
|
1360 |
|
|
struct async_struct *info = (struct async_struct *)tty->driver_data;
|
1361 |
|
|
unsigned long flags;
|
1362 |
|
|
#ifdef SERIAL_DEBUG_THROTTLE
|
1363 |
|
|
char buf[64];
|
1364 |
|
|
|
1365 |
|
|
printk("unthrottle %s: %d....\n", tty_name(tty, buf),
|
1366 |
|
|
tty->ldisc.chars_in_buffer(tty));
|
1367 |
|
|
#endif
|
1368 |
|
|
|
1369 |
|
|
if (serial_paranoia_check(info, tty->device, "rs_unthrottle"))
|
1370 |
|
|
return;
|
1371 |
|
|
|
1372 |
|
|
if (I_IXOFF(tty)) {
|
1373 |
|
|
if (info->x_char)
|
1374 |
|
|
info->x_char = 0;
|
1375 |
|
|
else
|
1376 |
|
|
rs_send_xchar(tty, START_CHAR(tty));
|
1377 |
|
|
}
|
1378 |
|
|
if (tty->termios->c_cflag & CRTSCTS)
|
1379 |
|
|
info->MCR |= UART_MCR_RTS;
|
1380 |
|
|
spin_lock_irqsave(&serial_lock, flags);
|
1381 |
|
|
serial_out(info, UART_MCR, info->MCR);
|
1382 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
1383 |
|
|
}
|
1384 |
|
|
|
1385 |
|
|
/*
|
1386 |
|
|
* ------------------------------------------------------------
|
1387 |
|
|
* rs_ioctl() and friends
|
1388 |
|
|
* ------------------------------------------------------------
|
1389 |
|
|
*/
|
1390 |
|
|
|
1391 |
|
|
static int get_serial_info(struct async_struct * info,
|
1392 |
|
|
struct serial_struct * retinfo)
|
1393 |
|
|
{
|
1394 |
|
|
struct serial_struct tmp;
|
1395 |
|
|
struct serial_state *state = info->state;
|
1396 |
|
|
|
1397 |
|
|
if (!retinfo)
|
1398 |
|
|
return -EFAULT;
|
1399 |
|
|
memset(&tmp, 0, sizeof(tmp));
|
1400 |
|
|
tmp.type = state->type;
|
1401 |
|
|
tmp.line = state->line;
|
1402 |
|
|
tmp.port = state->port;
|
1403 |
|
|
if (HIGH_BITS_OFFSET)
|
1404 |
|
|
tmp.port_high = state->port >> HIGH_BITS_OFFSET;
|
1405 |
|
|
else
|
1406 |
|
|
tmp.port_high = 0;
|
1407 |
|
|
tmp.irq = state->irq;
|
1408 |
|
|
tmp.flags = state->flags;
|
1409 |
|
|
tmp.xmit_fifo_size = state->xmit_fifo_size;
|
1410 |
|
|
tmp.baud_base = state->baud_base;
|
1411 |
|
|
tmp.close_delay = state->close_delay;
|
1412 |
|
|
tmp.closing_wait = state->closing_wait;
|
1413 |
|
|
tmp.custom_divisor = state->custom_divisor;
|
1414 |
|
|
tmp.hub6 = state->hub6;
|
1415 |
|
|
tmp.io_type = state->io_type;
|
1416 |
|
|
if (copy_to_user(retinfo,&tmp,sizeof(*retinfo)))
|
1417 |
|
|
return -EFAULT;
|
1418 |
|
|
return 0;
|
1419 |
|
|
}
|
1420 |
|
|
|
1421 |
|
|
static int set_serial_info(struct async_struct * info,
|
1422 |
|
|
struct serial_struct * new_info)
|
1423 |
|
|
{
|
1424 |
|
|
struct serial_struct new_serial;
|
1425 |
|
|
struct serial_state old_state, *state;
|
1426 |
|
|
unsigned int i,change_irq,change_port;
|
1427 |
|
|
int retval = 0;
|
1428 |
|
|
unsigned long new_port;
|
1429 |
|
|
|
1430 |
|
|
if (copy_from_user(&new_serial,new_info,sizeof(new_serial)))
|
1431 |
|
|
return -EFAULT;
|
1432 |
|
|
state = info->state;
|
1433 |
|
|
old_state = *state;
|
1434 |
|
|
|
1435 |
|
|
new_port = new_serial.port;
|
1436 |
|
|
if (HIGH_BITS_OFFSET)
|
1437 |
|
|
new_port += (unsigned long) new_serial.port_high << HIGH_BITS_OFFSET;
|
1438 |
|
|
|
1439 |
|
|
change_irq = new_serial.irq != state->irq;
|
1440 |
|
|
change_port = (new_port != ((int) state->port)) ||
|
1441 |
|
|
(new_serial.hub6 != state->hub6);
|
1442 |
|
|
|
1443 |
|
|
if (!capable(CAP_SYS_ADMIN)) {
|
1444 |
|
|
if (change_irq || change_port ||
|
1445 |
|
|
(new_serial.baud_base != state->baud_base) ||
|
1446 |
|
|
(new_serial.type != state->type) ||
|
1447 |
|
|
(new_serial.close_delay != state->close_delay) ||
|
1448 |
|
|
(new_serial.xmit_fifo_size != state->xmit_fifo_size) ||
|
1449 |
|
|
((new_serial.flags & ~ASYNC_USR_MASK) !=
|
1450 |
|
|
(state->flags & ~ASYNC_USR_MASK)))
|
1451 |
|
|
return -EPERM;
|
1452 |
|
|
state->flags = ((state->flags & ~ASYNC_USR_MASK) |
|
1453 |
|
|
(new_serial.flags & ASYNC_USR_MASK));
|
1454 |
|
|
info->flags = ((info->flags & ~ASYNC_USR_MASK) |
|
1455 |
|
|
(new_serial.flags & ASYNC_USR_MASK));
|
1456 |
|
|
state->custom_divisor = new_serial.custom_divisor;
|
1457 |
|
|
goto check_and_exit;
|
1458 |
|
|
}
|
1459 |
|
|
|
1460 |
|
|
new_serial.irq = irq_cannonicalize(new_serial.irq);
|
1461 |
|
|
|
1462 |
|
|
if ((new_serial.irq >= NR_IRQS) || (new_serial.irq < 0) ||
|
1463 |
|
|
(new_serial.baud_base < 9600)|| (new_serial.type < PORT_UNKNOWN) ||
|
1464 |
|
|
(new_serial.type > PORT_MAX) || (new_serial.type == PORT_CIRRUS) ||
|
1465 |
|
|
(new_serial.type == PORT_STARTECH)) {
|
1466 |
|
|
return -EINVAL;
|
1467 |
|
|
}
|
1468 |
|
|
|
1469 |
|
|
if ((new_serial.type != state->type) ||
|
1470 |
|
|
(new_serial.xmit_fifo_size <= 0))
|
1471 |
|
|
new_serial.xmit_fifo_size =
|
1472 |
|
|
uart_config[new_serial.type].dfl_xmit_fifo_size;
|
1473 |
|
|
|
1474 |
|
|
/* Make sure address is not already in use */
|
1475 |
|
|
if (new_serial.type) {
|
1476 |
|
|
for (i = 0 ; i < NR_PORTS; i++)
|
1477 |
|
|
if ((state != &rs_table[i]) &&
|
1478 |
|
|
(rs_table[i].port == new_port) &&
|
1479 |
|
|
rs_table[i].type)
|
1480 |
|
|
return -EADDRINUSE;
|
1481 |
|
|
}
|
1482 |
|
|
|
1483 |
|
|
if ((change_port || change_irq) && (state->count > 1))
|
1484 |
|
|
return -EBUSY;
|
1485 |
|
|
|
1486 |
|
|
/*
|
1487 |
|
|
* OK, past this point, all the error checking has been done.
|
1488 |
|
|
* At this point, we start making changes.....
|
1489 |
|
|
*/
|
1490 |
|
|
|
1491 |
|
|
state->baud_base = new_serial.baud_base;
|
1492 |
|
|
state->flags = ((state->flags & ~ASYNC_FLAGS) |
|
1493 |
|
|
(new_serial.flags & ASYNC_FLAGS));
|
1494 |
|
|
info->flags = ((state->flags & ~ASYNC_INTERNAL_FLAGS) |
|
1495 |
|
|
(info->flags & ASYNC_INTERNAL_FLAGS));
|
1496 |
|
|
state->custom_divisor = new_serial.custom_divisor;
|
1497 |
|
|
state->close_delay = new_serial.close_delay * HZ/100;
|
1498 |
|
|
state->closing_wait = new_serial.closing_wait * HZ/100;
|
1499 |
|
|
info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
|
1500 |
|
|
info->xmit_fifo_size = state->xmit_fifo_size =
|
1501 |
|
|
new_serial.xmit_fifo_size;
|
1502 |
|
|
|
1503 |
|
|
if ((state->type != PORT_UNKNOWN) && state->port) {
|
1504 |
|
|
release_region(state->port,8);
|
1505 |
|
|
}
|
1506 |
|
|
state->type = new_serial.type;
|
1507 |
|
|
if (change_port || change_irq) {
|
1508 |
|
|
/*
|
1509 |
|
|
* We need to shutdown the serial port at the old
|
1510 |
|
|
* port/irq combination.
|
1511 |
|
|
*/
|
1512 |
|
|
shutdown(info);
|
1513 |
|
|
state->irq = new_serial.irq;
|
1514 |
|
|
info->port = state->port = new_port;
|
1515 |
|
|
info->hub6 = state->hub6 = new_serial.hub6;
|
1516 |
|
|
if (info->hub6)
|
1517 |
|
|
info->io_type = state->io_type = SERIAL_IO_HUB6;
|
1518 |
|
|
else if (info->io_type == SERIAL_IO_HUB6)
|
1519 |
|
|
info->io_type = state->io_type = SERIAL_IO_PORT;
|
1520 |
|
|
}
|
1521 |
|
|
if ((state->type != PORT_UNKNOWN) && state->port) {
|
1522 |
|
|
request_region(state->port,8,"serial(set)");
|
1523 |
|
|
}
|
1524 |
|
|
|
1525 |
|
|
|
1526 |
|
|
check_and_exit:
|
1527 |
|
|
if (!state->port || !state->type)
|
1528 |
|
|
return 0;
|
1529 |
|
|
if (info->flags & ASYNC_INITIALIZED) {
|
1530 |
|
|
if (((old_state.flags & ASYNC_SPD_MASK) !=
|
1531 |
|
|
(state->flags & ASYNC_SPD_MASK)) ||
|
1532 |
|
|
(old_state.custom_divisor != state->custom_divisor)) {
|
1533 |
|
|
if ((state->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
|
1534 |
|
|
info->tty->alt_speed = 57600;
|
1535 |
|
|
if ((state->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
|
1536 |
|
|
info->tty->alt_speed = 115200;
|
1537 |
|
|
if ((state->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
|
1538 |
|
|
info->tty->alt_speed = 230400;
|
1539 |
|
|
if ((state->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
|
1540 |
|
|
info->tty->alt_speed = 460800;
|
1541 |
|
|
change_speed(info, 0);
|
1542 |
|
|
}
|
1543 |
|
|
} else {
|
1544 |
|
|
retval = startup(info);
|
1545 |
|
|
}
|
1546 |
|
|
return retval;
|
1547 |
|
|
}
|
1548 |
|
|
|
1549 |
|
|
|
1550 |
|
|
/*
|
1551 |
|
|
* get_lsr_info - get line status register info
|
1552 |
|
|
*
|
1553 |
|
|
* Purpose: Let user call ioctl() to get info when the UART physically
|
1554 |
|
|
* is emptied. On bus types like RS485, the transmitter must
|
1555 |
|
|
* release the bus after transmitting. This must be done when
|
1556 |
|
|
* the transmit shift register is empty, not be done when the
|
1557 |
|
|
* transmit holding register is empty. This functionality
|
1558 |
|
|
* allows an RS485 driver to be written in user space.
|
1559 |
|
|
*/
|
1560 |
|
|
static int get_lsr_info(struct async_struct * info, unsigned int *value)
|
1561 |
|
|
{
|
1562 |
|
|
unsigned char status;
|
1563 |
|
|
unsigned int result;
|
1564 |
|
|
unsigned long flags;
|
1565 |
|
|
|
1566 |
|
|
spin_lock_irqsave(&serial_lock, flags);
|
1567 |
|
|
status = serial_in(info, UART_LSR);
|
1568 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
1569 |
|
|
result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0);
|
1570 |
|
|
|
1571 |
|
|
/*
|
1572 |
|
|
* If we're about to load something into the transmit
|
1573 |
|
|
* register, we'll pretend the transmitter isn't empty to
|
1574 |
|
|
* avoid a race condition (depending on when the transmit
|
1575 |
|
|
* interrupt happens).
|
1576 |
|
|
*/
|
1577 |
|
|
if (info->x_char ||
|
1578 |
|
|
((CIRC_CNT(info->xmit.head, info->xmit.tail,
|
1579 |
|
|
SERIAL_XMIT_SIZE) > 0) &&
|
1580 |
|
|
!info->tty->stopped && !info->tty->hw_stopped))
|
1581 |
|
|
result &= TIOCSER_TEMT;
|
1582 |
|
|
|
1583 |
|
|
if (copy_to_user(value, &result, sizeof(int)))
|
1584 |
|
|
return -EFAULT;
|
1585 |
|
|
return 0;
|
1586 |
|
|
}
|
1587 |
|
|
|
1588 |
|
|
|
1589 |
|
|
static int get_modem_info(struct async_struct * info, unsigned int *value)
|
1590 |
|
|
{
|
1591 |
|
|
unsigned char control, status;
|
1592 |
|
|
unsigned int result;
|
1593 |
|
|
unsigned long flags;
|
1594 |
|
|
|
1595 |
|
|
control = info->MCR;
|
1596 |
|
|
spin_lock_irqsave(&serial_lock, flags);
|
1597 |
|
|
status = serial_in(info, UART_MSR);
|
1598 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
1599 |
|
|
result = ((control & UART_MCR_RTS) ? TIOCM_RTS : 0)
|
1600 |
|
|
| ((control & UART_MCR_DTR) ? TIOCM_DTR : 0)
|
1601 |
|
|
#ifdef TIOCM_OUT1
|
1602 |
|
|
| ((control & UART_MCR_OUT1) ? TIOCM_OUT1 : 0)
|
1603 |
|
|
| ((control & UART_MCR_OUT2) ? TIOCM_OUT2 : 0)
|
1604 |
|
|
#endif
|
1605 |
|
|
| ((status & UART_MSR_DCD) ? TIOCM_CAR : 0)
|
1606 |
|
|
| ((status & UART_MSR_RI) ? TIOCM_RNG : 0)
|
1607 |
|
|
| ((status & UART_MSR_DSR) ? TIOCM_DSR : 0)
|
1608 |
|
|
| ((status & UART_MSR_CTS) ? TIOCM_CTS : 0);
|
1609 |
|
|
|
1610 |
|
|
if (copy_to_user(value, &result, sizeof(int)))
|
1611 |
|
|
return -EFAULT;
|
1612 |
|
|
return 0;
|
1613 |
|
|
}
|
1614 |
|
|
|
1615 |
|
|
static int set_modem_info(struct async_struct * info, unsigned int cmd,
|
1616 |
|
|
unsigned int *value)
|
1617 |
|
|
{
|
1618 |
|
|
unsigned int arg;
|
1619 |
|
|
unsigned long flags;
|
1620 |
|
|
|
1621 |
|
|
if (copy_from_user(&arg, value, sizeof(int)))
|
1622 |
|
|
return -EFAULT;
|
1623 |
|
|
|
1624 |
|
|
switch (cmd) {
|
1625 |
|
|
case TIOCMBIS:
|
1626 |
|
|
if (arg & TIOCM_RTS)
|
1627 |
|
|
info->MCR |= UART_MCR_RTS;
|
1628 |
|
|
if (arg & TIOCM_DTR)
|
1629 |
|
|
info->MCR |= UART_MCR_DTR;
|
1630 |
|
|
#ifdef TIOCM_OUT1
|
1631 |
|
|
if (arg & TIOCM_OUT1)
|
1632 |
|
|
info->MCR |= UART_MCR_OUT1;
|
1633 |
|
|
if (arg & TIOCM_OUT2)
|
1634 |
|
|
info->MCR |= UART_MCR_OUT2;
|
1635 |
|
|
#endif
|
1636 |
|
|
if (arg & TIOCM_LOOP)
|
1637 |
|
|
info->MCR |= UART_MCR_LOOP;
|
1638 |
|
|
break;
|
1639 |
|
|
case TIOCMBIC:
|
1640 |
|
|
if (arg & TIOCM_RTS)
|
1641 |
|
|
info->MCR &= ~UART_MCR_RTS;
|
1642 |
|
|
if (arg & TIOCM_DTR)
|
1643 |
|
|
info->MCR &= ~UART_MCR_DTR;
|
1644 |
|
|
#ifdef TIOCM_OUT1
|
1645 |
|
|
if (arg & TIOCM_OUT1)
|
1646 |
|
|
info->MCR &= ~UART_MCR_OUT1;
|
1647 |
|
|
if (arg & TIOCM_OUT2)
|
1648 |
|
|
info->MCR &= ~UART_MCR_OUT2;
|
1649 |
|
|
#endif
|
1650 |
|
|
if (arg & TIOCM_LOOP)
|
1651 |
|
|
info->MCR &= ~UART_MCR_LOOP;
|
1652 |
|
|
break;
|
1653 |
|
|
case TIOCMSET:
|
1654 |
|
|
info->MCR = ((info->MCR & ~(UART_MCR_RTS |
|
1655 |
|
|
#ifdef TIOCM_OUT1
|
1656 |
|
|
UART_MCR_OUT1 |
|
1657 |
|
|
UART_MCR_OUT2 |
|
1658 |
|
|
#endif
|
1659 |
|
|
UART_MCR_LOOP |
|
1660 |
|
|
UART_MCR_DTR))
|
1661 |
|
|
| ((arg & TIOCM_RTS) ? UART_MCR_RTS : 0)
|
1662 |
|
|
#ifdef TIOCM_OUT1
|
1663 |
|
|
| ((arg & TIOCM_OUT1) ? UART_MCR_OUT1 : 0)
|
1664 |
|
|
| ((arg & TIOCM_OUT2) ? UART_MCR_OUT2 : 0)
|
1665 |
|
|
#endif
|
1666 |
|
|
| ((arg & TIOCM_LOOP) ? UART_MCR_LOOP : 0)
|
1667 |
|
|
| ((arg & TIOCM_DTR) ? UART_MCR_DTR : 0));
|
1668 |
|
|
break;
|
1669 |
|
|
default:
|
1670 |
|
|
return -EINVAL;
|
1671 |
|
|
}
|
1672 |
|
|
spin_lock_irqsave(&serial_lock, flags);
|
1673 |
|
|
info->MCR |= ALPHA_KLUDGE_MCR; /* Don't ask */
|
1674 |
|
|
serial_out(info, UART_MCR, info->MCR);
|
1675 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
1676 |
|
|
return 0;
|
1677 |
|
|
}
|
1678 |
|
|
|
1679 |
|
|
static int do_autoconfig(struct async_struct * info)
|
1680 |
|
|
{
|
1681 |
|
|
int retval;
|
1682 |
|
|
|
1683 |
|
|
if (!capable(CAP_SYS_ADMIN))
|
1684 |
|
|
return -EPERM;
|
1685 |
|
|
|
1686 |
|
|
if (info->state->count > 1)
|
1687 |
|
|
return -EBUSY;
|
1688 |
|
|
|
1689 |
|
|
shutdown(info);
|
1690 |
|
|
|
1691 |
|
|
autoconfig(info->state);
|
1692 |
|
|
retval = startup(info);
|
1693 |
|
|
if (retval)
|
1694 |
|
|
return retval;
|
1695 |
|
|
return 0;
|
1696 |
|
|
}
|
1697 |
|
|
|
1698 |
|
|
/*
|
1699 |
|
|
* rs_break() --- routine which turns the break handling on or off
|
1700 |
|
|
*/
|
1701 |
|
|
static void rs_break(struct tty_struct *tty, int break_state)
|
1702 |
|
|
{
|
1703 |
|
|
struct async_struct * info = (struct async_struct *)tty->driver_data;
|
1704 |
|
|
unsigned long flags;
|
1705 |
|
|
|
1706 |
|
|
if (serial_paranoia_check(info, tty->device, "rs_break"))
|
1707 |
|
|
return;
|
1708 |
|
|
|
1709 |
|
|
if (!CONFIGURED_SERIAL_PORT(info))
|
1710 |
|
|
return;
|
1711 |
|
|
spin_lock_irqsave(&serial_lock, flags);
|
1712 |
|
|
if (break_state == -1)
|
1713 |
|
|
info->LCR |= UART_LCR_SBC;
|
1714 |
|
|
else
|
1715 |
|
|
info->LCR &= ~UART_LCR_SBC;
|
1716 |
|
|
serial_out(info, UART_LCR, info->LCR);
|
1717 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
1718 |
|
|
}
|
1719 |
|
|
|
1720 |
|
|
|
1721 |
|
|
static int rs_ioctl(struct tty_struct *tty, struct file * file,
|
1722 |
|
|
unsigned int cmd, unsigned long arg)
|
1723 |
|
|
{
|
1724 |
|
|
struct async_struct * info = (struct async_struct *)tty->driver_data;
|
1725 |
|
|
struct async_icount cprev, cnow; /* kernel counter temps */
|
1726 |
|
|
struct serial_icounter_struct icount;
|
1727 |
|
|
unsigned long flags;
|
1728 |
|
|
|
1729 |
|
|
if (serial_paranoia_check(info, tty->device, "rs_ioctl"))
|
1730 |
|
|
return -ENODEV;
|
1731 |
|
|
|
1732 |
|
|
if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
|
1733 |
|
|
(cmd != TIOCSERCONFIG) && (cmd != TIOCSERGSTRUCT) &&
|
1734 |
|
|
(cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) {
|
1735 |
|
|
if (tty->flags & (1 << TTY_IO_ERROR))
|
1736 |
|
|
return -EIO;
|
1737 |
|
|
}
|
1738 |
|
|
|
1739 |
|
|
switch (cmd) {
|
1740 |
|
|
case TIOCMGET:
|
1741 |
|
|
return get_modem_info(info, (unsigned int *) arg);
|
1742 |
|
|
case TIOCMBIS:
|
1743 |
|
|
case TIOCMBIC:
|
1744 |
|
|
case TIOCMSET:
|
1745 |
|
|
return set_modem_info(info, cmd, (unsigned int *) arg);
|
1746 |
|
|
case TIOCGSERIAL:
|
1747 |
|
|
return get_serial_info(info,
|
1748 |
|
|
(struct serial_struct *) arg);
|
1749 |
|
|
case TIOCSSERIAL:
|
1750 |
|
|
return set_serial_info(info,
|
1751 |
|
|
(struct serial_struct *) arg);
|
1752 |
|
|
case TIOCSERCONFIG:
|
1753 |
|
|
return do_autoconfig(info);
|
1754 |
|
|
|
1755 |
|
|
case TIOCSERGETLSR: /* Get line status register */
|
1756 |
|
|
return get_lsr_info(info, (unsigned int *) arg);
|
1757 |
|
|
|
1758 |
|
|
case TIOCSERGSTRUCT:
|
1759 |
|
|
if (copy_to_user((struct async_struct *) arg,
|
1760 |
|
|
info, sizeof(struct async_struct)))
|
1761 |
|
|
return -EFAULT;
|
1762 |
|
|
return 0;
|
1763 |
|
|
|
1764 |
|
|
|
1765 |
|
|
/*
|
1766 |
|
|
* Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
|
1767 |
|
|
* - mask passed in arg for lines of interest
|
1768 |
|
|
* (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
|
1769 |
|
|
* Caller should use TIOCGICOUNT to see which one it was
|
1770 |
|
|
*/
|
1771 |
|
|
case TIOCMIWAIT:
|
1772 |
|
|
spin_lock_irqsave(&serial_lock, flags);
|
1773 |
|
|
/* note the counters on entry */
|
1774 |
|
|
cprev = info->state->icount;
|
1775 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
1776 |
|
|
/* Force modem status interrupts on */
|
1777 |
|
|
info->IER |= UART_IER_MSI;
|
1778 |
|
|
serial_out(info, UART_IER, info->IER);
|
1779 |
|
|
while (1) {
|
1780 |
|
|
interruptible_sleep_on(&info->delta_msr_wait);
|
1781 |
|
|
/* see if a signal did it */
|
1782 |
|
|
if (signal_pending(current))
|
1783 |
|
|
return -ERESTARTSYS;
|
1784 |
|
|
spin_lock_irqsave(&serial_lock, flags);
|
1785 |
|
|
cnow = info->state->icount; /* atomic copy */
|
1786 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
1787 |
|
|
if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
|
1788 |
|
|
cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
|
1789 |
|
|
return -EIO; /* no change => error */
|
1790 |
|
|
if ( ((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
|
1791 |
|
|
((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
|
1792 |
|
|
((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
|
1793 |
|
|
((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {
|
1794 |
|
|
return 0;
|
1795 |
|
|
}
|
1796 |
|
|
cprev = cnow;
|
1797 |
|
|
}
|
1798 |
|
|
/* NOTREACHED */
|
1799 |
|
|
|
1800 |
|
|
/*
|
1801 |
|
|
* Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
|
1802 |
|
|
* Return: write counters to the user passed counter struct
|
1803 |
|
|
* NB: both 1->0 and 0->1 transitions are counted except for
|
1804 |
|
|
* RI where only 0->1 is counted.
|
1805 |
|
|
*/
|
1806 |
|
|
case TIOCGICOUNT:
|
1807 |
|
|
spin_lock_irqsave(&serial_lock, flags);
|
1808 |
|
|
cnow = info->state->icount;
|
1809 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
1810 |
|
|
icount.cts = cnow.cts;
|
1811 |
|
|
icount.dsr = cnow.dsr;
|
1812 |
|
|
icount.rng = cnow.rng;
|
1813 |
|
|
icount.dcd = cnow.dcd;
|
1814 |
|
|
icount.rx = cnow.rx;
|
1815 |
|
|
icount.tx = cnow.tx;
|
1816 |
|
|
icount.frame = cnow.frame;
|
1817 |
|
|
icount.overrun = cnow.overrun;
|
1818 |
|
|
icount.parity = cnow.parity;
|
1819 |
|
|
icount.brk = cnow.brk;
|
1820 |
|
|
icount.buf_overrun = cnow.buf_overrun;
|
1821 |
|
|
|
1822 |
|
|
if (copy_to_user((void *)arg, &icount, sizeof(icount)))
|
1823 |
|
|
return -EFAULT;
|
1824 |
|
|
return 0;
|
1825 |
|
|
case TIOCSERGWILD:
|
1826 |
|
|
case TIOCSERSWILD:
|
1827 |
|
|
/* "setserial -W" is called in Debian boot */
|
1828 |
|
|
printk ("TIOCSER?WILD ioctl obsolete, ignored.\n");
|
1829 |
|
|
return 0;
|
1830 |
|
|
|
1831 |
|
|
default:
|
1832 |
|
|
return -ENOIOCTLCMD;
|
1833 |
|
|
}
|
1834 |
|
|
return 0;
|
1835 |
|
|
}
|
1836 |
|
|
|
1837 |
|
|
static void rs_set_termios(struct tty_struct *tty, struct termios *old_termios)
|
1838 |
|
|
{
|
1839 |
|
|
struct async_struct *info = (struct async_struct *)tty->driver_data;
|
1840 |
|
|
unsigned long flags;
|
1841 |
|
|
unsigned int cflag = tty->termios->c_cflag;
|
1842 |
|
|
|
1843 |
|
|
if ( (cflag == old_termios->c_cflag)
|
1844 |
|
|
&& ( RELEVANT_IFLAG(tty->termios->c_iflag)
|
1845 |
|
|
== RELEVANT_IFLAG(old_termios->c_iflag)))
|
1846 |
|
|
return;
|
1847 |
|
|
|
1848 |
|
|
change_speed(info, old_termios);
|
1849 |
|
|
|
1850 |
|
|
/* Handle transition to B0 status */
|
1851 |
|
|
if ((old_termios->c_cflag & CBAUD) &&
|
1852 |
|
|
!(cflag & CBAUD)) {
|
1853 |
|
|
info->MCR &= ~(UART_MCR_DTR|UART_MCR_RTS);
|
1854 |
|
|
spin_lock_irqsave(&serial_lock, flags);
|
1855 |
|
|
serial_out(info, UART_MCR, info->MCR);
|
1856 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
1857 |
|
|
}
|
1858 |
|
|
|
1859 |
|
|
/* Handle transition away from B0 status */
|
1860 |
|
|
if (!(old_termios->c_cflag & CBAUD) &&
|
1861 |
|
|
(cflag & CBAUD)) {
|
1862 |
|
|
info->MCR |= UART_MCR_DTR;
|
1863 |
|
|
if (!(tty->termios->c_cflag & CRTSCTS) ||
|
1864 |
|
|
!test_bit(TTY_THROTTLED, &tty->flags)) {
|
1865 |
|
|
info->MCR |= UART_MCR_RTS;
|
1866 |
|
|
}
|
1867 |
|
|
spin_lock_irqsave(&serial_lock, flags);
|
1868 |
|
|
serial_out(info, UART_MCR, info->MCR);
|
1869 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
1870 |
|
|
}
|
1871 |
|
|
|
1872 |
|
|
/* Handle turning off CRTSCTS */
|
1873 |
|
|
if ((old_termios->c_cflag & CRTSCTS) &&
|
1874 |
|
|
!(tty->termios->c_cflag & CRTSCTS)) {
|
1875 |
|
|
tty->hw_stopped = 0;
|
1876 |
|
|
rs_start(tty);
|
1877 |
|
|
}
|
1878 |
|
|
}
|
1879 |
|
|
|
1880 |
|
|
/*
|
1881 |
|
|
* ------------------------------------------------------------
|
1882 |
|
|
* rs_close()
|
1883 |
|
|
*
|
1884 |
|
|
* This routine is called when the serial port gets closed. First, we
|
1885 |
|
|
* wait for the last remaining data to be sent. Then, we unlink its
|
1886 |
|
|
* async structure from the interrupt chain if necessary, and we free
|
1887 |
|
|
* that IRQ if nothing is left in the chain.
|
1888 |
|
|
* ------------------------------------------------------------
|
1889 |
|
|
*/
|
1890 |
|
|
static void rs_close(struct tty_struct *tty, struct file * filp)
|
1891 |
|
|
{
|
1892 |
|
|
struct async_struct * info = (struct async_struct *)tty->driver_data;
|
1893 |
|
|
struct serial_state *state;
|
1894 |
|
|
unsigned long flags;
|
1895 |
|
|
|
1896 |
|
|
if (!info || serial_paranoia_check(info, tty->device, "rs_close"))
|
1897 |
|
|
return;
|
1898 |
|
|
|
1899 |
|
|
state = info->state;
|
1900 |
|
|
|
1901 |
|
|
spin_lock_irqsave(&serial_lock, flags);
|
1902 |
|
|
|
1903 |
|
|
if (tty_hung_up_p(filp)) {
|
1904 |
|
|
DBG_CNT("before DEC-hung");
|
1905 |
|
|
MOD_DEC_USE_COUNT;
|
1906 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
1907 |
|
|
return;
|
1908 |
|
|
}
|
1909 |
|
|
|
1910 |
|
|
#ifdef SERIAL_DEBUG_OPEN
|
1911 |
|
|
printk("rs_close ttys%d, count = %d\n", info->line, state->count);
|
1912 |
|
|
#endif
|
1913 |
|
|
if ((tty->count == 1) && (state->count != 1)) {
|
1914 |
|
|
/*
|
1915 |
|
|
* Uh, oh. tty->count is 1, which means that the tty
|
1916 |
|
|
* structure will be freed. state->count should always
|
1917 |
|
|
* be one in these conditions. If it's greater than
|
1918 |
|
|
* one, we've got real problems, since it means the
|
1919 |
|
|
* serial port won't be shutdown.
|
1920 |
|
|
*/
|
1921 |
|
|
printk("rs_close: bad serial port count; tty->count is 1, "
|
1922 |
|
|
"state->count is %d\n", state->count);
|
1923 |
|
|
state->count = 1;
|
1924 |
|
|
}
|
1925 |
|
|
if (--state->count < 0) {
|
1926 |
|
|
printk("rs_close: bad serial port count for ttys%d: %d\n",
|
1927 |
|
|
info->line, state->count);
|
1928 |
|
|
state->count = 0;
|
1929 |
|
|
}
|
1930 |
|
|
if (state->count) {
|
1931 |
|
|
DBG_CNT("before DEC-2");
|
1932 |
|
|
MOD_DEC_USE_COUNT;
|
1933 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
1934 |
|
|
return;
|
1935 |
|
|
}
|
1936 |
|
|
info->flags |= ASYNC_CLOSING;
|
1937 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
1938 |
|
|
/*
|
1939 |
|
|
* Save the termios structure, since this port may have
|
1940 |
|
|
* separate termios for callout and dialin.
|
1941 |
|
|
*/
|
1942 |
|
|
if (info->flags & ASYNC_NORMAL_ACTIVE)
|
1943 |
|
|
info->state->normal_termios = *tty->termios;
|
1944 |
|
|
if (info->flags & ASYNC_CALLOUT_ACTIVE)
|
1945 |
|
|
info->state->callout_termios = *tty->termios;
|
1946 |
|
|
/*
|
1947 |
|
|
* Now we wait for the transmit buffer to clear; and we notify
|
1948 |
|
|
* the line discipline to only process XON/XOFF characters.
|
1949 |
|
|
*/
|
1950 |
|
|
tty->closing = 1;
|
1951 |
|
|
if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE)
|
1952 |
|
|
tty_wait_until_sent(tty, info->closing_wait);
|
1953 |
|
|
/*
|
1954 |
|
|
* At this point we stop accepting input. To do this, we
|
1955 |
|
|
* disable the receive line status interrupts, and tell the
|
1956 |
|
|
* interrupt driver to stop checking the data ready bit in the
|
1957 |
|
|
* line status register.
|
1958 |
|
|
*/
|
1959 |
|
|
info->IER &= ~UART_IER_RLSI;
|
1960 |
|
|
info->read_status_mask &= ~UART_LSR_DR;
|
1961 |
|
|
if (info->flags & ASYNC_INITIALIZED) {
|
1962 |
|
|
serial_out(info, UART_IER, info->IER);
|
1963 |
|
|
/*
|
1964 |
|
|
* Before we drop DTR, make sure the UART transmitter
|
1965 |
|
|
* has completely drained; this is especially
|
1966 |
|
|
* important if there is a transmit FIFO!
|
1967 |
|
|
*/
|
1968 |
|
|
rs_wait_until_sent(tty, info->timeout);
|
1969 |
|
|
}
|
1970 |
|
|
shutdown(info);
|
1971 |
|
|
if (tty->driver.flush_buffer)
|
1972 |
|
|
tty->driver.flush_buffer(tty);
|
1973 |
|
|
if (tty->ldisc.flush_buffer)
|
1974 |
|
|
tty->ldisc.flush_buffer(tty);
|
1975 |
|
|
tty->closing = 0;
|
1976 |
|
|
info->event = 0;
|
1977 |
|
|
info->tty = 0;
|
1978 |
|
|
if (info->blocked_open) {
|
1979 |
|
|
if (info->close_delay) {
|
1980 |
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
1981 |
|
|
schedule_timeout(info->close_delay);
|
1982 |
|
|
}
|
1983 |
|
|
wake_up_interruptible(&info->open_wait);
|
1984 |
|
|
}
|
1985 |
|
|
info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE|
|
1986 |
|
|
ASYNC_CLOSING);
|
1987 |
|
|
wake_up_interruptible(&info->close_wait);
|
1988 |
|
|
MOD_DEC_USE_COUNT;
|
1989 |
|
|
}
|
1990 |
|
|
|
1991 |
|
|
/*
|
1992 |
|
|
* rs_wait_until_sent() --- wait until the transmitter is empty
|
1993 |
|
|
*/
|
1994 |
|
|
static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
|
1995 |
|
|
{
|
1996 |
|
|
struct async_struct * info = (struct async_struct *)tty->driver_data;
|
1997 |
|
|
unsigned long orig_jiffies, char_time;
|
1998 |
|
|
int lsr;
|
1999 |
|
|
|
2000 |
|
|
if (serial_paranoia_check(info, tty->device, "rs_wait_until_sent"))
|
2001 |
|
|
return;
|
2002 |
|
|
|
2003 |
|
|
if (info->state->type == PORT_UNKNOWN)
|
2004 |
|
|
return;
|
2005 |
|
|
|
2006 |
|
|
if (info->xmit_fifo_size == 0)
|
2007 |
|
|
return; /* Just in case.... */
|
2008 |
|
|
|
2009 |
|
|
orig_jiffies = jiffies;
|
2010 |
|
|
/*
|
2011 |
|
|
* Set the check interval to be 1/5 of the estimated time to
|
2012 |
|
|
* send a single character, and make it at least 1. The check
|
2013 |
|
|
* interval should also be less than the timeout.
|
2014 |
|
|
*
|
2015 |
|
|
* Note: we have to use pretty tight timings here to satisfy
|
2016 |
|
|
* the NIST-PCTS.
|
2017 |
|
|
*/
|
2018 |
|
|
char_time = (info->timeout - HZ/50) / info->xmit_fifo_size;
|
2019 |
|
|
char_time = char_time / 5;
|
2020 |
|
|
if (char_time == 0)
|
2021 |
|
|
char_time = 1;
|
2022 |
|
|
if (timeout && timeout < char_time)
|
2023 |
|
|
char_time = timeout;
|
2024 |
|
|
/*
|
2025 |
|
|
* If the transmitter hasn't cleared in twice the approximate
|
2026 |
|
|
* amount of time to send the entire FIFO, it probably won't
|
2027 |
|
|
* ever clear. This assumes the UART isn't doing flow
|
2028 |
|
|
* control, which is currently the case. Hence, if it ever
|
2029 |
|
|
* takes longer than info->timeout, this is probably due to a
|
2030 |
|
|
* UART bug of some kind. So, we clamp the timeout parameter at
|
2031 |
|
|
* 2*info->timeout.
|
2032 |
|
|
*/
|
2033 |
|
|
if (!timeout || timeout > 2*info->timeout)
|
2034 |
|
|
timeout = 2*info->timeout;
|
2035 |
|
|
#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
|
2036 |
|
|
printk("In rs_wait_until_sent(%d) check=%lu...", timeout, char_time);
|
2037 |
|
|
printk("jiff=%lu...", jiffies);
|
2038 |
|
|
#endif
|
2039 |
|
|
while (!((lsr = serial_inp(info, UART_LSR)) & UART_LSR_TEMT)) {
|
2040 |
|
|
#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
|
2041 |
|
|
printk("lsr = %d (jiff=%lu)...", lsr, jiffies);
|
2042 |
|
|
#endif
|
2043 |
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
2044 |
|
|
schedule_timeout(char_time);
|
2045 |
|
|
if (signal_pending(current))
|
2046 |
|
|
break;
|
2047 |
|
|
if (timeout && time_after(jiffies, orig_jiffies + timeout))
|
2048 |
|
|
break;
|
2049 |
|
|
}
|
2050 |
|
|
set_current_state(TASK_RUNNING);
|
2051 |
|
|
#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
|
2052 |
|
|
printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
|
2053 |
|
|
#endif
|
2054 |
|
|
}
|
2055 |
|
|
|
2056 |
|
|
/*
|
2057 |
|
|
* rs_hangup() --- called by tty_hangup() when a hangup is signaled.
|
2058 |
|
|
*/
|
2059 |
|
|
static void rs_hangup(struct tty_struct *tty)
|
2060 |
|
|
{
|
2061 |
|
|
struct async_struct * info = (struct async_struct *)tty->driver_data;
|
2062 |
|
|
struct serial_state *state = info->state;
|
2063 |
|
|
|
2064 |
|
|
if (serial_paranoia_check(info, tty->device, "rs_hangup"))
|
2065 |
|
|
return;
|
2066 |
|
|
|
2067 |
|
|
state = info->state;
|
2068 |
|
|
|
2069 |
|
|
rs_flush_buffer(tty);
|
2070 |
|
|
if (info->flags & ASYNC_CLOSING)
|
2071 |
|
|
return;
|
2072 |
|
|
shutdown(info);
|
2073 |
|
|
info->event = 0;
|
2074 |
|
|
state->count = 0;
|
2075 |
|
|
info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE);
|
2076 |
|
|
info->tty = 0;
|
2077 |
|
|
wake_up_interruptible(&info->open_wait);
|
2078 |
|
|
}
|
2079 |
|
|
|
2080 |
|
|
/*
|
2081 |
|
|
* ------------------------------------------------------------
|
2082 |
|
|
* rs_open() and friends
|
2083 |
|
|
* ------------------------------------------------------------
|
2084 |
|
|
*/
|
2085 |
|
|
static int block_til_ready(struct tty_struct *tty, struct file * filp,
|
2086 |
|
|
struct async_struct *info)
|
2087 |
|
|
{
|
2088 |
|
|
DECLARE_WAITQUEUE(wait, current);
|
2089 |
|
|
struct serial_state *state = info->state;
|
2090 |
|
|
int retval;
|
2091 |
|
|
int do_clocal = 0, extra_count = 0;
|
2092 |
|
|
unsigned long flags;
|
2093 |
|
|
|
2094 |
|
|
/*
|
2095 |
|
|
* If the device is in the middle of being closed, then block
|
2096 |
|
|
* until it's done, and then try again.
|
2097 |
|
|
*/
|
2098 |
|
|
if (tty_hung_up_p(filp) ||
|
2099 |
|
|
(info->flags & ASYNC_CLOSING)) {
|
2100 |
|
|
if (info->flags & ASYNC_CLOSING)
|
2101 |
|
|
interruptible_sleep_on(&info->close_wait);
|
2102 |
|
|
#ifdef SERIAL_DO_RESTART
|
2103 |
|
|
return ((info->flags & ASYNC_HUP_NOTIFY) ?
|
2104 |
|
|
-EAGAIN : -ERESTARTSYS);
|
2105 |
|
|
#else
|
2106 |
|
|
return -EAGAIN;
|
2107 |
|
|
#endif
|
2108 |
|
|
}
|
2109 |
|
|
|
2110 |
|
|
/*
|
2111 |
|
|
* If this is a callout device, then just make sure the normal
|
2112 |
|
|
* device isn't being used.
|
2113 |
|
|
*/
|
2114 |
|
|
if (tty->driver.subtype == SERIAL_TYPE_CALLOUT) {
|
2115 |
|
|
if (info->flags & ASYNC_NORMAL_ACTIVE)
|
2116 |
|
|
return -EBUSY;
|
2117 |
|
|
if ((info->flags & ASYNC_CALLOUT_ACTIVE) &&
|
2118 |
|
|
(info->flags & ASYNC_SESSION_LOCKOUT) &&
|
2119 |
|
|
(info->session != current->session))
|
2120 |
|
|
return -EBUSY;
|
2121 |
|
|
if ((info->flags & ASYNC_CALLOUT_ACTIVE) &&
|
2122 |
|
|
(info->flags & ASYNC_PGRP_LOCKOUT) &&
|
2123 |
|
|
(info->pgrp != current->pgrp))
|
2124 |
|
|
return -EBUSY;
|
2125 |
|
|
info->flags |= ASYNC_CALLOUT_ACTIVE;
|
2126 |
|
|
return 0;
|
2127 |
|
|
}
|
2128 |
|
|
|
2129 |
|
|
/*
|
2130 |
|
|
* If non-blocking mode is set, or the port is not enabled,
|
2131 |
|
|
* then make the check up front and then exit.
|
2132 |
|
|
*/
|
2133 |
|
|
if ((filp->f_flags & O_NONBLOCK) ||
|
2134 |
|
|
(tty->flags & (1 << TTY_IO_ERROR))) {
|
2135 |
|
|
if (info->flags & ASYNC_CALLOUT_ACTIVE)
|
2136 |
|
|
return -EBUSY;
|
2137 |
|
|
info->flags |= ASYNC_NORMAL_ACTIVE;
|
2138 |
|
|
return 0;
|
2139 |
|
|
}
|
2140 |
|
|
|
2141 |
|
|
if (info->flags & ASYNC_CALLOUT_ACTIVE) {
|
2142 |
|
|
if (state->normal_termios.c_cflag & CLOCAL)
|
2143 |
|
|
do_clocal = 1;
|
2144 |
|
|
} else {
|
2145 |
|
|
if (tty->termios->c_cflag & CLOCAL)
|
2146 |
|
|
do_clocal = 1;
|
2147 |
|
|
}
|
2148 |
|
|
|
2149 |
|
|
/*
|
2150 |
|
|
* Block waiting for the carrier detect and the line to become
|
2151 |
|
|
* free (i.e., not in use by the callout). While we are in
|
2152 |
|
|
* this loop, state->count is dropped by one, so that
|
2153 |
|
|
* rs_close() knows when to free things. We restore it upon
|
2154 |
|
|
* exit, either normal or abnormal.
|
2155 |
|
|
*/
|
2156 |
|
|
retval = 0;
|
2157 |
|
|
add_wait_queue(&info->open_wait, &wait);
|
2158 |
|
|
#ifdef SERIAL_DEBUG_OPEN
|
2159 |
|
|
printk("block_til_ready before block: ttys%d, count = %d\n",
|
2160 |
|
|
state->line, state->count);
|
2161 |
|
|
#endif
|
2162 |
|
|
spin_lock_irqsave(&serial_lock, flags);
|
2163 |
|
|
if (!tty_hung_up_p(filp)) {
|
2164 |
|
|
extra_count = 1;
|
2165 |
|
|
state->count--;
|
2166 |
|
|
}
|
2167 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
2168 |
|
|
info->blocked_open++;
|
2169 |
|
|
while (1) {
|
2170 |
|
|
spin_lock_irqsave(&serial_lock, flags);
|
2171 |
|
|
if (!(info->flags & ASYNC_CALLOUT_ACTIVE) &&
|
2172 |
|
|
(tty->termios->c_cflag & CBAUD))
|
2173 |
|
|
serial_out(info, UART_MCR,
|
2174 |
|
|
serial_inp(info, UART_MCR) |
|
2175 |
|
|
(UART_MCR_DTR | UART_MCR_RTS));
|
2176 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
2177 |
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
2178 |
|
|
if (tty_hung_up_p(filp) ||
|
2179 |
|
|
!(info->flags & ASYNC_INITIALIZED)) {
|
2180 |
|
|
#ifdef SERIAL_DO_RESTART
|
2181 |
|
|
if (info->flags & ASYNC_HUP_NOTIFY)
|
2182 |
|
|
retval = -EAGAIN;
|
2183 |
|
|
else
|
2184 |
|
|
retval = -ERESTARTSYS;
|
2185 |
|
|
#else
|
2186 |
|
|
retval = -EAGAIN;
|
2187 |
|
|
#endif
|
2188 |
|
|
break;
|
2189 |
|
|
}
|
2190 |
|
|
if (!(info->flags & ASYNC_CALLOUT_ACTIVE) &&
|
2191 |
|
|
!(info->flags & ASYNC_CLOSING) &&
|
2192 |
|
|
(do_clocal || (serial_in(info, UART_MSR) &
|
2193 |
|
|
UART_MSR_DCD)))
|
2194 |
|
|
break;
|
2195 |
|
|
if (signal_pending(current)) {
|
2196 |
|
|
retval = -ERESTARTSYS;
|
2197 |
|
|
break;
|
2198 |
|
|
}
|
2199 |
|
|
#ifdef SERIAL_DEBUG_OPEN
|
2200 |
|
|
printk("block_til_ready blocking: ttys%d, count = %d\n",
|
2201 |
|
|
info->line, state->count);
|
2202 |
|
|
#endif
|
2203 |
|
|
schedule();
|
2204 |
|
|
}
|
2205 |
|
|
set_current_state(TASK_RUNNING);
|
2206 |
|
|
remove_wait_queue(&info->open_wait, &wait);
|
2207 |
|
|
if (extra_count)
|
2208 |
|
|
state->count++;
|
2209 |
|
|
info->blocked_open--;
|
2210 |
|
|
#ifdef SERIAL_DEBUG_OPEN
|
2211 |
|
|
printk("block_til_ready after blocking: ttys%d, count = %d\n",
|
2212 |
|
|
info->line, state->count);
|
2213 |
|
|
#endif
|
2214 |
|
|
if (retval)
|
2215 |
|
|
return retval;
|
2216 |
|
|
info->flags |= ASYNC_NORMAL_ACTIVE;
|
2217 |
|
|
return 0;
|
2218 |
|
|
}
|
2219 |
|
|
|
2220 |
|
|
static int get_async_struct(int line, struct async_struct **ret_info)
|
2221 |
|
|
{
|
2222 |
|
|
struct async_struct *info;
|
2223 |
|
|
struct serial_state *sstate;
|
2224 |
|
|
|
2225 |
|
|
sstate = rs_table + line;
|
2226 |
|
|
sstate->count++;
|
2227 |
|
|
if (sstate->info) {
|
2228 |
|
|
*ret_info = sstate->info;
|
2229 |
|
|
return 0;
|
2230 |
|
|
}
|
2231 |
|
|
info = kmalloc(sizeof(struct async_struct), GFP_KERNEL);
|
2232 |
|
|
if (!info) {
|
2233 |
|
|
sstate->count--;
|
2234 |
|
|
return -ENOMEM;
|
2235 |
|
|
}
|
2236 |
|
|
memset(info, 0, sizeof(struct async_struct));
|
2237 |
|
|
init_waitqueue_head(&info->open_wait);
|
2238 |
|
|
init_waitqueue_head(&info->close_wait);
|
2239 |
|
|
init_waitqueue_head(&info->delta_msr_wait);
|
2240 |
|
|
info->magic = SERIAL_MAGIC;
|
2241 |
|
|
info->port = sstate->port;
|
2242 |
|
|
info->flags = sstate->flags;
|
2243 |
|
|
info->io_type = sstate->io_type;
|
2244 |
|
|
info->iomem_base = sstate->iomem_base;
|
2245 |
|
|
info->iomem_reg_shift = sstate->iomem_reg_shift;
|
2246 |
|
|
info->xmit_fifo_size = sstate->xmit_fifo_size;
|
2247 |
|
|
info->line = line;
|
2248 |
|
|
info->tqueue.routine = do_softint;
|
2249 |
|
|
info->tqueue.data = info;
|
2250 |
|
|
info->state = sstate;
|
2251 |
|
|
if (sstate->info) {
|
2252 |
|
|
kfree(info);
|
2253 |
|
|
*ret_info = sstate->info;
|
2254 |
|
|
return 0;
|
2255 |
|
|
}
|
2256 |
|
|
*ret_info = sstate->info = info;
|
2257 |
|
|
return 0;
|
2258 |
|
|
}
|
2259 |
|
|
|
2260 |
|
|
/*
|
2261 |
|
|
* This routine is called whenever a serial port is opened. It
|
2262 |
|
|
* enables interrupts for a serial port, linking in its async structure into
|
2263 |
|
|
* the IRQ chain. It also performs the serial-specific
|
2264 |
|
|
* initialization for the tty structure.
|
2265 |
|
|
*/
|
2266 |
|
|
static int rs_open(struct tty_struct *tty, struct file * filp)
|
2267 |
|
|
{
|
2268 |
|
|
struct async_struct *info;
|
2269 |
|
|
int retval, line;
|
2270 |
|
|
unsigned long page;
|
2271 |
|
|
|
2272 |
|
|
MOD_INC_USE_COUNT;
|
2273 |
|
|
line = MINOR(tty->device) - tty->driver.minor_start;
|
2274 |
|
|
if ((line < 0) || (line >= NR_PORTS)) {
|
2275 |
|
|
MOD_DEC_USE_COUNT;
|
2276 |
|
|
return -ENODEV;
|
2277 |
|
|
}
|
2278 |
|
|
retval = get_async_struct(line, &info);
|
2279 |
|
|
if (retval) {
|
2280 |
|
|
MOD_DEC_USE_COUNT;
|
2281 |
|
|
return retval;
|
2282 |
|
|
}
|
2283 |
|
|
tty->driver_data = info;
|
2284 |
|
|
info->tty = tty;
|
2285 |
|
|
if (serial_paranoia_check(info, tty->device, "rs_open")) {
|
2286 |
|
|
MOD_DEC_USE_COUNT;
|
2287 |
|
|
return -ENODEV;
|
2288 |
|
|
}
|
2289 |
|
|
|
2290 |
|
|
#ifdef SERIAL_DEBUG_OPEN
|
2291 |
|
|
printk("rs_open %s%d, count = %d\n", tty->driver.name, info->line,
|
2292 |
|
|
info->state->count);
|
2293 |
|
|
#endif
|
2294 |
|
|
info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
|
2295 |
|
|
|
2296 |
|
|
if (!tmp_buf) {
|
2297 |
|
|
page = get_zeroed_page(GFP_KERNEL);
|
2298 |
|
|
if (!page) {
|
2299 |
|
|
MOD_DEC_USE_COUNT;
|
2300 |
|
|
return -ENOMEM;
|
2301 |
|
|
}
|
2302 |
|
|
if (tmp_buf)
|
2303 |
|
|
free_page(page);
|
2304 |
|
|
else
|
2305 |
|
|
tmp_buf = (unsigned char *) page;
|
2306 |
|
|
}
|
2307 |
|
|
|
2308 |
|
|
/*
|
2309 |
|
|
* If the port is the middle of closing, bail out now
|
2310 |
|
|
*/
|
2311 |
|
|
if (tty_hung_up_p(filp) ||
|
2312 |
|
|
(info->flags & ASYNC_CLOSING)) {
|
2313 |
|
|
if (info->flags & ASYNC_CLOSING)
|
2314 |
|
|
interruptible_sleep_on(&info->close_wait);
|
2315 |
|
|
MOD_DEC_USE_COUNT;
|
2316 |
|
|
#ifdef SERIAL_DO_RESTART
|
2317 |
|
|
return ((info->flags & ASYNC_HUP_NOTIFY) ?
|
2318 |
|
|
-EAGAIN : -ERESTARTSYS);
|
2319 |
|
|
#else
|
2320 |
|
|
return -EAGAIN;
|
2321 |
|
|
#endif
|
2322 |
|
|
}
|
2323 |
|
|
|
2324 |
|
|
/*
|
2325 |
|
|
* Start up serial port
|
2326 |
|
|
*/
|
2327 |
|
|
retval = startup(info);
|
2328 |
|
|
if (retval) {
|
2329 |
|
|
MOD_DEC_USE_COUNT;
|
2330 |
|
|
return retval;
|
2331 |
|
|
}
|
2332 |
|
|
|
2333 |
|
|
retval = block_til_ready(tty, filp, info);
|
2334 |
|
|
if (retval) {
|
2335 |
|
|
#ifdef SERIAL_DEBUG_OPEN
|
2336 |
|
|
printk("rs_open returning after block_til_ready with %d\n",
|
2337 |
|
|
retval);
|
2338 |
|
|
#endif
|
2339 |
|
|
MOD_DEC_USE_COUNT;
|
2340 |
|
|
return retval;
|
2341 |
|
|
}
|
2342 |
|
|
|
2343 |
|
|
if ((info->state->count == 1) &&
|
2344 |
|
|
(info->flags & ASYNC_SPLIT_TERMIOS)) {
|
2345 |
|
|
if (tty->driver.subtype == SERIAL_TYPE_NORMAL)
|
2346 |
|
|
*tty->termios = info->state->normal_termios;
|
2347 |
|
|
else
|
2348 |
|
|
*tty->termios = info->state->callout_termios;
|
2349 |
|
|
change_speed(info, 0);
|
2350 |
|
|
}
|
2351 |
|
|
#ifdef CONFIG_AU1X00_SERIAL_CONSOLE
|
2352 |
|
|
if (sercons.cflag && sercons.index == line) {
|
2353 |
|
|
tty->termios->c_cflag = sercons.cflag;
|
2354 |
|
|
sercons.cflag = 0;
|
2355 |
|
|
change_speed(info, 0);
|
2356 |
|
|
}
|
2357 |
|
|
#endif
|
2358 |
|
|
info->session = current->session;
|
2359 |
|
|
info->pgrp = current->pgrp;
|
2360 |
|
|
|
2361 |
|
|
#ifdef SERIAL_DEBUG_OPEN
|
2362 |
|
|
printk("rs_open ttys%d successful...", info->line);
|
2363 |
|
|
#endif
|
2364 |
|
|
return 0;
|
2365 |
|
|
}
|
2366 |
|
|
|
2367 |
|
|
/*
|
2368 |
|
|
* /proc fs routines....
|
2369 |
|
|
*/
|
2370 |
|
|
|
2371 |
|
|
static inline int line_info(char *buf, struct serial_state *state)
|
2372 |
|
|
{
|
2373 |
|
|
struct async_struct *info = state->info, scr_info;
|
2374 |
|
|
char stat_buf[30], control, status;
|
2375 |
|
|
int ret;
|
2376 |
|
|
unsigned long flags;
|
2377 |
|
|
|
2378 |
|
|
ret = sprintf(buf, "%d: uart:%s port:%lX irq:%d",
|
2379 |
|
|
state->line, uart_config[state->type].name,
|
2380 |
|
|
state->port, state->irq);
|
2381 |
|
|
|
2382 |
|
|
if (!state->port || (state->type == PORT_UNKNOWN)) {
|
2383 |
|
|
ret += sprintf(buf+ret, "\n");
|
2384 |
|
|
return ret;
|
2385 |
|
|
}
|
2386 |
|
|
|
2387 |
|
|
/*
|
2388 |
|
|
* Figure out the current RS-232 lines
|
2389 |
|
|
*/
|
2390 |
|
|
if (!info) {
|
2391 |
|
|
info = &scr_info; /* This is just for serial_{in,out} */
|
2392 |
|
|
|
2393 |
|
|
info->magic = SERIAL_MAGIC;
|
2394 |
|
|
info->port = state->port;
|
2395 |
|
|
info->flags = state->flags;
|
2396 |
|
|
info->quot = 0;
|
2397 |
|
|
info->tty = 0;
|
2398 |
|
|
}
|
2399 |
|
|
spin_lock_irqsave(&serial_lock, flags);
|
2400 |
|
|
status = serial_in(info, UART_MSR);
|
2401 |
|
|
control = info != &scr_info ? info->MCR : serial_in(info, UART_MCR);
|
2402 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
2403 |
|
|
|
2404 |
|
|
stat_buf[0] = 0;
|
2405 |
|
|
stat_buf[1] = 0;
|
2406 |
|
|
if (control & UART_MCR_RTS)
|
2407 |
|
|
strcat(stat_buf, "|RTS");
|
2408 |
|
|
if (status & UART_MSR_CTS)
|
2409 |
|
|
strcat(stat_buf, "|CTS");
|
2410 |
|
|
if (control & UART_MCR_DTR)
|
2411 |
|
|
strcat(stat_buf, "|DTR");
|
2412 |
|
|
if (status & UART_MSR_DSR)
|
2413 |
|
|
strcat(stat_buf, "|DSR");
|
2414 |
|
|
if (status & UART_MSR_DCD)
|
2415 |
|
|
strcat(stat_buf, "|CD");
|
2416 |
|
|
if (status & UART_MSR_RI)
|
2417 |
|
|
strcat(stat_buf, "|RI");
|
2418 |
|
|
|
2419 |
|
|
if (info->quot) {
|
2420 |
|
|
ret += sprintf(buf+ret, " baud:%d",
|
2421 |
|
|
state->baud_base / info->quot);
|
2422 |
|
|
}
|
2423 |
|
|
|
2424 |
|
|
ret += sprintf(buf+ret, " tx:%d rx:%d",
|
2425 |
|
|
state->icount.tx, state->icount.rx);
|
2426 |
|
|
|
2427 |
|
|
if (state->icount.frame)
|
2428 |
|
|
ret += sprintf(buf+ret, " fe:%d", state->icount.frame);
|
2429 |
|
|
|
2430 |
|
|
if (state->icount.parity)
|
2431 |
|
|
ret += sprintf(buf+ret, " pe:%d", state->icount.parity);
|
2432 |
|
|
|
2433 |
|
|
if (state->icount.brk)
|
2434 |
|
|
ret += sprintf(buf+ret, " brk:%d", state->icount.brk);
|
2435 |
|
|
|
2436 |
|
|
if (state->icount.overrun)
|
2437 |
|
|
ret += sprintf(buf+ret, " oe:%d", state->icount.overrun);
|
2438 |
|
|
|
2439 |
|
|
/*
|
2440 |
|
|
* Last thing is the RS-232 status lines
|
2441 |
|
|
*/
|
2442 |
|
|
ret += sprintf(buf+ret, " %s\n", stat_buf+1);
|
2443 |
|
|
return ret;
|
2444 |
|
|
}
|
2445 |
|
|
|
2446 |
|
|
int rs_read_proc(char *page, char **start, off_t off, int count,
|
2447 |
|
|
int *eof, void *data)
|
2448 |
|
|
{
|
2449 |
|
|
int i, len = 0, l;
|
2450 |
|
|
off_t begin = 0;
|
2451 |
|
|
|
2452 |
|
|
len += sprintf(page, "serinfo:1.0 driver:%s%s revision:%s\n",
|
2453 |
|
|
serial_version, LOCAL_VERSTRING, serial_revdate);
|
2454 |
|
|
for (i = 0; i < NR_PORTS && len < 4000; i++) {
|
2455 |
|
|
l = line_info(page + len, &rs_table[i]);
|
2456 |
|
|
len += l;
|
2457 |
|
|
if (len+begin > off+count)
|
2458 |
|
|
goto done;
|
2459 |
|
|
if (len+begin < off) {
|
2460 |
|
|
begin += len;
|
2461 |
|
|
len = 0;
|
2462 |
|
|
}
|
2463 |
|
|
}
|
2464 |
|
|
*eof = 1;
|
2465 |
|
|
done:
|
2466 |
|
|
if (off >= len+begin)
|
2467 |
|
|
return 0;
|
2468 |
|
|
*start = page + (off-begin);
|
2469 |
|
|
return ((count < begin+len-off) ? count : begin+len-off);
|
2470 |
|
|
}
|
2471 |
|
|
|
2472 |
|
|
/*
|
2473 |
|
|
* ---------------------------------------------------------------------
|
2474 |
|
|
* rs_init() and friends
|
2475 |
|
|
*
|
2476 |
|
|
* rs_init() is called at boot-time to initialize the serial driver.
|
2477 |
|
|
* ---------------------------------------------------------------------
|
2478 |
|
|
*/
|
2479 |
|
|
|
2480 |
|
|
/*
|
2481 |
|
|
* This routine prints out the appropriate serial driver version
|
2482 |
|
|
* number, and identifies which options were configured into this
|
2483 |
|
|
* driver.
|
2484 |
|
|
*/
|
2485 |
|
|
static char serial_options[] __initdata =
|
2486 |
|
|
" no serial options enabled\n";
|
2487 |
|
|
#undef SERIAL_OPT
|
2488 |
|
|
|
2489 |
|
|
static _INLINE_ void show_serial_version(void)
|
2490 |
|
|
{
|
2491 |
|
|
printk(KERN_INFO "%s version %s%s (%s) with%s", serial_name,
|
2492 |
|
|
serial_version, LOCAL_VERSTRING, serial_revdate,
|
2493 |
|
|
serial_options);
|
2494 |
|
|
}
|
2495 |
|
|
|
2496 |
|
|
|
2497 |
|
|
/*
|
2498 |
|
|
* This routine is called by rs_init() to initialize a specific serial
|
2499 |
|
|
* port. It determines what type of UART chip this serial port is
|
2500 |
|
|
* using: 8250, 16450, 16550, 16550A. The important question is
|
2501 |
|
|
* whether or not this UART is a 16550A or not, since this will
|
2502 |
|
|
* determine whether or not we can use its FIFO features or not.
|
2503 |
|
|
*/
|
2504 |
|
|
static void autoconfig(struct serial_state * state)
|
2505 |
|
|
{
|
2506 |
|
|
struct async_struct *info, scr_info;
|
2507 |
|
|
unsigned long flags;
|
2508 |
|
|
|
2509 |
|
|
|
2510 |
|
|
#ifdef SERIAL_DEBUG_AUTOCONF
|
2511 |
|
|
printk("Testing ttyS%d (0x%04lx, 0x%04x)...\n", state->line,
|
2512 |
|
|
state->port, (unsigned) state->iomem_base);
|
2513 |
|
|
#endif
|
2514 |
|
|
|
2515 |
|
|
if (!CONFIGURED_SERIAL_PORT(state))
|
2516 |
|
|
return;
|
2517 |
|
|
|
2518 |
|
|
if (au_readl(UART_MOD_CNTRL + state->port) != 0x3) {
|
2519 |
|
|
au_writel(3, UART_MOD_CNTRL + state->port);
|
2520 |
|
|
au_sync_delay(10);
|
2521 |
|
|
}
|
2522 |
|
|
|
2523 |
|
|
state->type = PORT_16550;
|
2524 |
|
|
info = &scr_info; /* This is just for serial_{in,out} */
|
2525 |
|
|
|
2526 |
|
|
info->magic = SERIAL_MAGIC;
|
2527 |
|
|
info->state = state;
|
2528 |
|
|
info->port = state->port;
|
2529 |
|
|
info->flags = state->flags;
|
2530 |
|
|
info->io_type = state->io_type;
|
2531 |
|
|
info->iomem_base = state->iomem_base;
|
2532 |
|
|
info->iomem_reg_shift = state->iomem_reg_shift;
|
2533 |
|
|
|
2534 |
|
|
|
2535 |
|
|
spin_lock_irqsave(&serial_lock, flags);
|
2536 |
|
|
state->xmit_fifo_size = uart_config[state->type].dfl_xmit_fifo_size;
|
2537 |
|
|
|
2538 |
|
|
if (info->port) {
|
2539 |
|
|
request_region(info->port,8,"serial(auto)");
|
2540 |
|
|
}
|
2541 |
|
|
|
2542 |
|
|
/*
|
2543 |
|
|
* Reset the UART.
|
2544 |
|
|
*/
|
2545 |
|
|
serial_outp(info, UART_FCR, (UART_FCR_ENABLE_FIFO |
|
2546 |
|
|
UART_FCR_CLEAR_RCVR |
|
2547 |
|
|
UART_FCR_CLEAR_XMIT));
|
2548 |
|
|
serial_outp(info, UART_FCR, 0);
|
2549 |
|
|
(void)serial_in(info, UART_RX);
|
2550 |
|
|
serial_outp(info, UART_IER, 0);
|
2551 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
2552 |
|
|
}
|
2553 |
|
|
|
2554 |
|
|
int register_serial(struct serial_struct *req);
|
2555 |
|
|
void unregister_serial(int line);
|
2556 |
|
|
|
2557 |
|
|
/*
|
2558 |
|
|
* The serial driver boot-time initialization code!
|
2559 |
|
|
*/
|
2560 |
|
|
static int __init rs_init(void)
|
2561 |
|
|
{
|
2562 |
|
|
int i;
|
2563 |
|
|
struct serial_state * state;
|
2564 |
|
|
|
2565 |
|
|
init_bh(SERIAL_BH, do_serial_bh);
|
2566 |
|
|
init_timer(&serial_timer);
|
2567 |
|
|
serial_timer.function = rs_timer;
|
2568 |
|
|
mod_timer(&serial_timer, jiffies + RS_STROBE_TIME);
|
2569 |
|
|
|
2570 |
|
|
for (i = 0; i < NR_IRQS; i++) {
|
2571 |
|
|
IRQ_ports[i] = 0;
|
2572 |
|
|
IRQ_timeout[i] = 0;
|
2573 |
|
|
}
|
2574 |
|
|
#ifdef CONFIG_AU1X00_SERIAL_CONSOLE
|
2575 |
|
|
/*
|
2576 |
|
|
* The interrupt of the serial console port
|
2577 |
|
|
* can't be shared.
|
2578 |
|
|
*/
|
2579 |
|
|
if (sercons.flags & CON_CONSDEV) {
|
2580 |
|
|
for(i = 0; i < NR_PORTS; i++)
|
2581 |
|
|
if (i != sercons.index &&
|
2582 |
|
|
rs_table[i].irq == rs_table[sercons.index].irq)
|
2583 |
|
|
rs_table[i].irq = 0;
|
2584 |
|
|
}
|
2585 |
|
|
#endif
|
2586 |
|
|
show_serial_version();
|
2587 |
|
|
|
2588 |
|
|
/* Initialize the tty_driver structure */
|
2589 |
|
|
|
2590 |
|
|
memset(&serial_driver, 0, sizeof(struct tty_driver));
|
2591 |
|
|
serial_driver.magic = TTY_DRIVER_MAGIC;
|
2592 |
|
|
serial_driver.driver_name = "serial";
|
2593 |
|
|
#if (LINUX_VERSION_CODE > 0x2032D && defined(CONFIG_DEVFS_FS))
|
2594 |
|
|
serial_driver.name = "tts/%d";
|
2595 |
|
|
#else
|
2596 |
|
|
serial_driver.name = "ttyS";
|
2597 |
|
|
#endif
|
2598 |
|
|
serial_driver.major = TTY_MAJOR;
|
2599 |
|
|
serial_driver.minor_start = 64 + SERIAL_DEV_OFFSET;
|
2600 |
|
|
serial_driver.num = NR_PORTS;
|
2601 |
|
|
serial_driver.type = TTY_DRIVER_TYPE_SERIAL;
|
2602 |
|
|
serial_driver.subtype = SERIAL_TYPE_NORMAL;
|
2603 |
|
|
serial_driver.init_termios = tty_std_termios;
|
2604 |
|
|
serial_driver.init_termios.c_cflag =
|
2605 |
|
|
B9600 | CS8 | CREAD | HUPCL | CLOCAL;
|
2606 |
|
|
serial_driver.flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_NO_DEVFS;
|
2607 |
|
|
serial_driver.refcount = &serial_refcount;
|
2608 |
|
|
serial_driver.table = serial_table;
|
2609 |
|
|
serial_driver.termios = serial_termios;
|
2610 |
|
|
serial_driver.termios_locked = serial_termios_locked;
|
2611 |
|
|
|
2612 |
|
|
serial_driver.open = rs_open;
|
2613 |
|
|
serial_driver.close = rs_close;
|
2614 |
|
|
serial_driver.write = rs_write;
|
2615 |
|
|
serial_driver.put_char = rs_put_char;
|
2616 |
|
|
serial_driver.flush_chars = rs_flush_chars;
|
2617 |
|
|
serial_driver.write_room = rs_write_room;
|
2618 |
|
|
serial_driver.chars_in_buffer = rs_chars_in_buffer;
|
2619 |
|
|
serial_driver.flush_buffer = rs_flush_buffer;
|
2620 |
|
|
serial_driver.ioctl = rs_ioctl;
|
2621 |
|
|
serial_driver.throttle = rs_throttle;
|
2622 |
|
|
serial_driver.unthrottle = rs_unthrottle;
|
2623 |
|
|
serial_driver.set_termios = rs_set_termios;
|
2624 |
|
|
serial_driver.stop = rs_stop;
|
2625 |
|
|
serial_driver.start = rs_start;
|
2626 |
|
|
serial_driver.hangup = rs_hangup;
|
2627 |
|
|
serial_driver.break_ctl = rs_break;
|
2628 |
|
|
serial_driver.send_xchar = rs_send_xchar;
|
2629 |
|
|
serial_driver.wait_until_sent = rs_wait_until_sent;
|
2630 |
|
|
serial_driver.read_proc = rs_read_proc;
|
2631 |
|
|
|
2632 |
|
|
/*
|
2633 |
|
|
* The callout device is just like normal device except for
|
2634 |
|
|
* major number and the subtype code.
|
2635 |
|
|
*/
|
2636 |
|
|
callout_driver = serial_driver;
|
2637 |
|
|
#if (LINUX_VERSION_CODE > 0x2032D && defined(CONFIG_DEVFS_FS))
|
2638 |
|
|
callout_driver.name = "cua/%d";
|
2639 |
|
|
#else
|
2640 |
|
|
callout_driver.name = "cua";
|
2641 |
|
|
#endif
|
2642 |
|
|
callout_driver.major = TTYAUX_MAJOR;
|
2643 |
|
|
callout_driver.subtype = SERIAL_TYPE_CALLOUT;
|
2644 |
|
|
callout_driver.read_proc = 0;
|
2645 |
|
|
callout_driver.proc_entry = 0;
|
2646 |
|
|
|
2647 |
|
|
if (tty_register_driver(&serial_driver))
|
2648 |
|
|
panic("Couldn't register serial driver");
|
2649 |
|
|
if (tty_register_driver(&callout_driver))
|
2650 |
|
|
panic("Couldn't register callout driver");
|
2651 |
|
|
|
2652 |
|
|
for (i = 0, state = rs_table; i < NR_PORTS; i++,state++) {
|
2653 |
|
|
state->baud_base = get_au1x00_uart_baud_base();
|
2654 |
|
|
state->magic = SSTATE_MAGIC;
|
2655 |
|
|
state->line = i;
|
2656 |
|
|
state->type = PORT_UNKNOWN;
|
2657 |
|
|
state->custom_divisor = 0;
|
2658 |
|
|
state->close_delay = 5*HZ/10;
|
2659 |
|
|
state->closing_wait = 30*HZ;
|
2660 |
|
|
state->callout_termios = callout_driver.init_termios;
|
2661 |
|
|
state->normal_termios = serial_driver.init_termios;
|
2662 |
|
|
state->icount.cts = state->icount.dsr =
|
2663 |
|
|
state->icount.rng = state->icount.dcd = 0;
|
2664 |
|
|
state->icount.rx = state->icount.tx = 0;
|
2665 |
|
|
state->icount.frame = state->icount.parity = 0;
|
2666 |
|
|
state->icount.overrun = state->icount.brk = 0;
|
2667 |
|
|
state->irq = irq_cannonicalize(state->irq);
|
2668 |
|
|
if (state->hub6)
|
2669 |
|
|
state->io_type = SERIAL_IO_HUB6;
|
2670 |
|
|
if (state->port && check_region(state->port,8)) {
|
2671 |
|
|
continue;
|
2672 |
|
|
}
|
2673 |
|
|
|
2674 |
|
|
if (state->flags & ASYNC_BOOT_AUTOCONF) {
|
2675 |
|
|
autoconfig(state);
|
2676 |
|
|
}
|
2677 |
|
|
}
|
2678 |
|
|
for (i = 0, state = rs_table; i < NR_PORTS; i++,state++) {
|
2679 |
|
|
if (state->type == PORT_UNKNOWN) {
|
2680 |
|
|
continue;
|
2681 |
|
|
}
|
2682 |
|
|
printk(KERN_INFO "ttyS%02d%s at 0x%04lx (irq = %d) is a %s\n",
|
2683 |
|
|
state->line + SERIAL_DEV_OFFSET,
|
2684 |
|
|
(state->flags & ASYNC_FOURPORT) ? " FourPort" : "",
|
2685 |
|
|
state->port, state->irq,
|
2686 |
|
|
uart_config[state->type].name);
|
2687 |
|
|
tty_register_devfs(&serial_driver, 0,
|
2688 |
|
|
serial_driver.minor_start + state->line);
|
2689 |
|
|
tty_register_devfs(&callout_driver, 0,
|
2690 |
|
|
callout_driver.minor_start + state->line);
|
2691 |
|
|
}
|
2692 |
|
|
return 0;
|
2693 |
|
|
}
|
2694 |
|
|
|
2695 |
|
|
/*
|
2696 |
|
|
* register_serial and unregister_serial allows for 16x50 serial ports to be
|
2697 |
|
|
* configured at run-time, to support PCMCIA modems.
|
2698 |
|
|
*/
|
2699 |
|
|
|
2700 |
|
|
/**
|
2701 |
|
|
* register_serial - configure a 16x50 serial port at runtime
|
2702 |
|
|
* @req: request structure
|
2703 |
|
|
*
|
2704 |
|
|
* Configure the serial port specified by the request. If the
|
2705 |
|
|
* port exists and is in use an error is returned. If the port
|
2706 |
|
|
* is not currently in the table it is added.
|
2707 |
|
|
*
|
2708 |
|
|
* The port is then probed and if neccessary the IRQ is autodetected
|
2709 |
|
|
* If this fails an error is returned.
|
2710 |
|
|
*
|
2711 |
|
|
* On success the port is ready to use and the line number is returned.
|
2712 |
|
|
*/
|
2713 |
|
|
|
2714 |
|
|
int register_serial(struct serial_struct *req)
|
2715 |
|
|
{
|
2716 |
|
|
int i;
|
2717 |
|
|
unsigned long flags;
|
2718 |
|
|
struct serial_state *state;
|
2719 |
|
|
struct async_struct *info;
|
2720 |
|
|
unsigned long port;
|
2721 |
|
|
|
2722 |
|
|
port = req->port;
|
2723 |
|
|
if (HIGH_BITS_OFFSET)
|
2724 |
|
|
port += (unsigned long) req->port_high << HIGH_BITS_OFFSET;
|
2725 |
|
|
|
2726 |
|
|
spin_lock_irqsave(&serial_lock, flags);
|
2727 |
|
|
for (i = 0; i < NR_PORTS; i++) {
|
2728 |
|
|
if ((rs_table[i].port == port) &&
|
2729 |
|
|
(rs_table[i].iomem_base == req->iomem_base))
|
2730 |
|
|
break;
|
2731 |
|
|
}
|
2732 |
|
|
if (i == NR_PORTS) {
|
2733 |
|
|
for (i = 0; i < NR_PORTS; i++)
|
2734 |
|
|
if ((rs_table[i].type == PORT_UNKNOWN) &&
|
2735 |
|
|
(rs_table[i].count == 0))
|
2736 |
|
|
break;
|
2737 |
|
|
}
|
2738 |
|
|
if (i == NR_PORTS) {
|
2739 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
2740 |
|
|
return -1;
|
2741 |
|
|
}
|
2742 |
|
|
state = &rs_table[i];
|
2743 |
|
|
if (rs_table[i].count) {
|
2744 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
2745 |
|
|
printk("Couldn't configure serial #%d (port=%ld,irq=%d): "
|
2746 |
|
|
"device already open\n", i, port, req->irq);
|
2747 |
|
|
return -1;
|
2748 |
|
|
}
|
2749 |
|
|
state->irq = req->irq;
|
2750 |
|
|
state->port = port;
|
2751 |
|
|
state->flags = req->flags;
|
2752 |
|
|
state->io_type = req->io_type;
|
2753 |
|
|
state->iomem_base = req->iomem_base;
|
2754 |
|
|
state->iomem_reg_shift = req->iomem_reg_shift;
|
2755 |
|
|
if (req->baud_base)
|
2756 |
|
|
state->baud_base = req->baud_base;
|
2757 |
|
|
if ((info = state->info) != NULL) {
|
2758 |
|
|
info->port = port;
|
2759 |
|
|
info->flags = req->flags;
|
2760 |
|
|
info->io_type = req->io_type;
|
2761 |
|
|
info->iomem_base = req->iomem_base;
|
2762 |
|
|
info->iomem_reg_shift = req->iomem_reg_shift;
|
2763 |
|
|
}
|
2764 |
|
|
autoconfig(state);
|
2765 |
|
|
if (state->type == PORT_UNKNOWN) {
|
2766 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
2767 |
|
|
printk("register_serial(): autoconfig failed\n");
|
2768 |
|
|
return -1;
|
2769 |
|
|
}
|
2770 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
2771 |
|
|
|
2772 |
|
|
printk(KERN_INFO "ttyS%02d at %s 0x%04lx (irq = %d) is a %s\n",
|
2773 |
|
|
state->line + SERIAL_DEV_OFFSET,
|
2774 |
|
|
state->iomem_base ? "iomem" : "port",
|
2775 |
|
|
state->iomem_base ? (unsigned long)state->iomem_base :
|
2776 |
|
|
state->port, state->irq, uart_config[state->type].name);
|
2777 |
|
|
tty_register_devfs(&serial_driver, 0,
|
2778 |
|
|
serial_driver.minor_start + state->line);
|
2779 |
|
|
tty_register_devfs(&callout_driver, 0,
|
2780 |
|
|
callout_driver.minor_start + state->line);
|
2781 |
|
|
return state->line + SERIAL_DEV_OFFSET;
|
2782 |
|
|
}
|
2783 |
|
|
|
2784 |
|
|
/**
|
2785 |
|
|
* unregister_serial - deconfigure a 16x50 serial port
|
2786 |
|
|
* @line: line to deconfigure
|
2787 |
|
|
*
|
2788 |
|
|
* The port specified is deconfigured and its resources are freed. Any
|
2789 |
|
|
* user of the port is disconnected as if carrier was dropped. Line is
|
2790 |
|
|
* the port number returned by register_serial().
|
2791 |
|
|
*/
|
2792 |
|
|
|
2793 |
|
|
void unregister_serial(int line)
|
2794 |
|
|
{
|
2795 |
|
|
unsigned long flags;
|
2796 |
|
|
struct serial_state *state = &rs_table[line];
|
2797 |
|
|
|
2798 |
|
|
spin_lock_irqsave(&serial_lock, flags);
|
2799 |
|
|
if (state->info && state->info->tty)
|
2800 |
|
|
tty_hangup(state->info->tty);
|
2801 |
|
|
state->type = PORT_UNKNOWN;
|
2802 |
|
|
printk(KERN_INFO "tty%02d unloaded\n", state->line);
|
2803 |
|
|
/* These will be hidden, because they are devices that will no longer
|
2804 |
|
|
* be available to the system. (ie, PCMCIA modems, once ejected)
|
2805 |
|
|
*/
|
2806 |
|
|
tty_unregister_devfs(&serial_driver,
|
2807 |
|
|
serial_driver.minor_start + state->line);
|
2808 |
|
|
tty_unregister_devfs(&callout_driver,
|
2809 |
|
|
callout_driver.minor_start + state->line);
|
2810 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
2811 |
|
|
}
|
2812 |
|
|
|
2813 |
|
|
static void __exit rs_fini(void)
|
2814 |
|
|
{
|
2815 |
|
|
unsigned long flags;
|
2816 |
|
|
int e1, e2;
|
2817 |
|
|
int i;
|
2818 |
|
|
struct async_struct *info;
|
2819 |
|
|
|
2820 |
|
|
/* printk("Unloading %s: version %s\n", serial_name, serial_version); */
|
2821 |
|
|
del_timer_sync(&serial_timer);
|
2822 |
|
|
spin_lock_irqsave(&serial_lock, flags);
|
2823 |
|
|
remove_bh(SERIAL_BH);
|
2824 |
|
|
if ((e1 = tty_unregister_driver(&serial_driver)))
|
2825 |
|
|
printk("serial: failed to unregister serial driver (%d)\n",
|
2826 |
|
|
e1);
|
2827 |
|
|
if ((e2 = tty_unregister_driver(&callout_driver)))
|
2828 |
|
|
printk("serial: failed to unregister callout driver (%d)\n",
|
2829 |
|
|
e2);
|
2830 |
|
|
spin_unlock_irqrestore(&serial_lock, flags);
|
2831 |
|
|
|
2832 |
|
|
for (i = 0; i < NR_PORTS; i++) {
|
2833 |
|
|
if ((info = rs_table[i].info)) {
|
2834 |
|
|
rs_table[i].info = NULL;
|
2835 |
|
|
kfree(info);
|
2836 |
|
|
}
|
2837 |
|
|
if ((rs_table[i].type != PORT_UNKNOWN) && rs_table[i].port) {
|
2838 |
|
|
release_region(rs_table[i].port, 8);
|
2839 |
|
|
}
|
2840 |
|
|
}
|
2841 |
|
|
if (tmp_buf) {
|
2842 |
|
|
unsigned long pg = (unsigned long) tmp_buf;
|
2843 |
|
|
tmp_buf = NULL;
|
2844 |
|
|
free_page(pg);
|
2845 |
|
|
}
|
2846 |
|
|
}
|
2847 |
|
|
|
2848 |
|
|
module_init(rs_init);
|
2849 |
|
|
module_exit(rs_fini);
|
2850 |
|
|
MODULE_DESCRIPTION("Au1x00 serial driver");
|
2851 |
|
|
|
2852 |
|
|
|
2853 |
|
|
/*
|
2854 |
|
|
* ------------------------------------------------------------
|
2855 |
|
|
* Serial console driver
|
2856 |
|
|
* ------------------------------------------------------------
|
2857 |
|
|
*/
|
2858 |
|
|
#ifdef CONFIG_AU1X00_SERIAL_CONSOLE
|
2859 |
|
|
|
2860 |
|
|
#define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
|
2861 |
|
|
|
2862 |
|
|
static struct async_struct async_sercons;
|
2863 |
|
|
|
2864 |
|
|
/*
|
2865 |
|
|
* Wait for transmitter & holding register to empty
|
2866 |
|
|
*/
|
2867 |
|
|
static inline void wait_for_xmitr(struct async_struct *info)
|
2868 |
|
|
{
|
2869 |
|
|
unsigned int status, tmout = 0xffffff;
|
2870 |
|
|
|
2871 |
|
|
do {
|
2872 |
|
|
status = serial_in(info, UART_LSR);
|
2873 |
|
|
|
2874 |
|
|
if (status & UART_LSR_BI)
|
2875 |
|
|
lsr_break_flag = UART_LSR_BI;
|
2876 |
|
|
|
2877 |
|
|
if (--tmout == 0)
|
2878 |
|
|
break;
|
2879 |
|
|
} while((status & BOTH_EMPTY) != BOTH_EMPTY);
|
2880 |
|
|
}
|
2881 |
|
|
|
2882 |
|
|
|
2883 |
|
|
/*
|
2884 |
|
|
* Print a string to the serial port trying not to disturb
|
2885 |
|
|
* any possible real use of the port...
|
2886 |
|
|
*
|
2887 |
|
|
* The console_lock must be held when we get here.
|
2888 |
|
|
*/
|
2889 |
|
|
static void serial_console_write(struct console *co, const char *s,
|
2890 |
|
|
unsigned count)
|
2891 |
|
|
{
|
2892 |
|
|
static struct async_struct *info = &async_sercons;
|
2893 |
|
|
int ier;
|
2894 |
|
|
unsigned i;
|
2895 |
|
|
|
2896 |
|
|
/*
|
2897 |
|
|
* First save the IER then disable the interrupts
|
2898 |
|
|
*/
|
2899 |
|
|
ier = serial_in(info, UART_IER);
|
2900 |
|
|
serial_out(info, UART_IER, 0x00);
|
2901 |
|
|
|
2902 |
|
|
/*
|
2903 |
|
|
* Now, do each character
|
2904 |
|
|
*/
|
2905 |
|
|
for (i = 0; i < count; i++, s++) {
|
2906 |
|
|
wait_for_xmitr(info);
|
2907 |
|
|
|
2908 |
|
|
/*
|
2909 |
|
|
* Send the character out.
|
2910 |
|
|
* If a LF, also do CR...
|
2911 |
|
|
*/
|
2912 |
|
|
serial_out(info, UART_TX, *s);
|
2913 |
|
|
if (*s == 10) {
|
2914 |
|
|
wait_for_xmitr(info);
|
2915 |
|
|
serial_out(info, UART_TX, 13);
|
2916 |
|
|
}
|
2917 |
|
|
}
|
2918 |
|
|
|
2919 |
|
|
/*
|
2920 |
|
|
* Finally, Wait for transmitter & holding register to empty
|
2921 |
|
|
* and restore the IER
|
2922 |
|
|
*/
|
2923 |
|
|
wait_for_xmitr(info);
|
2924 |
|
|
serial_out(info, UART_IER, ier);
|
2925 |
|
|
}
|
2926 |
|
|
|
2927 |
|
|
/*
|
2928 |
|
|
* Receive character from the serial port
|
2929 |
|
|
*/
|
2930 |
|
|
static int serial_console_wait_key(struct console *co)
|
2931 |
|
|
{
|
2932 |
|
|
static struct async_struct *info;
|
2933 |
|
|
int ier, c;
|
2934 |
|
|
|
2935 |
|
|
info = &async_sercons;
|
2936 |
|
|
|
2937 |
|
|
/*
|
2938 |
|
|
* First save the IER then disable the interrupts so
|
2939 |
|
|
* that the real driver for the port does not get the
|
2940 |
|
|
* character.
|
2941 |
|
|
*/
|
2942 |
|
|
ier = serial_in(info, UART_IER);
|
2943 |
|
|
serial_out(info, UART_IER, 0x00);
|
2944 |
|
|
|
2945 |
|
|
while ((serial_in(info, UART_LSR) & UART_LSR_DR) == 0);
|
2946 |
|
|
c = serial_in(info, UART_RX);
|
2947 |
|
|
|
2948 |
|
|
/*
|
2949 |
|
|
* Restore the interrupts
|
2950 |
|
|
*/
|
2951 |
|
|
serial_out(info, UART_IER, ier);
|
2952 |
|
|
|
2953 |
|
|
return c;
|
2954 |
|
|
}
|
2955 |
|
|
|
2956 |
|
|
static kdev_t serial_console_device(struct console *c)
|
2957 |
|
|
{
|
2958 |
|
|
return MKDEV(TTY_MAJOR, 64 + c->index);
|
2959 |
|
|
}
|
2960 |
|
|
|
2961 |
|
|
/*
|
2962 |
|
|
* Setup initial baud/bits/parity. We do two things here:
|
2963 |
|
|
* - construct a cflag setting for the first rs_open()
|
2964 |
|
|
* - initialize the serial port
|
2965 |
|
|
* Return non-zero if we didn't find a serial port.
|
2966 |
|
|
*/
|
2967 |
|
|
static int __init serial_console_setup(struct console *co, char *options)
|
2968 |
|
|
{
|
2969 |
|
|
static struct async_struct *info;
|
2970 |
|
|
struct serial_state *state;
|
2971 |
|
|
unsigned cval;
|
2972 |
|
|
int baud = 9600;
|
2973 |
|
|
int bits = 8;
|
2974 |
|
|
int parity = 'n';
|
2975 |
|
|
int cflag = CREAD | HUPCL | CLOCAL;
|
2976 |
|
|
int quot = 0;
|
2977 |
|
|
char *s;
|
2978 |
|
|
|
2979 |
|
|
if (options) {
|
2980 |
|
|
baud = simple_strtoul(options, NULL, 10);
|
2981 |
|
|
s = options;
|
2982 |
|
|
while(*s >= '0' && *s <= '9')
|
2983 |
|
|
s++;
|
2984 |
|
|
if (*s) parity = *s++;
|
2985 |
|
|
if (*s) bits = *s - '0';
|
2986 |
|
|
}
|
2987 |
|
|
|
2988 |
|
|
/*
|
2989 |
|
|
* Now construct a cflag setting.
|
2990 |
|
|
*/
|
2991 |
|
|
switch(baud) {
|
2992 |
|
|
case 1200:
|
2993 |
|
|
cflag |= B1200;
|
2994 |
|
|
break;
|
2995 |
|
|
case 2400:
|
2996 |
|
|
cflag |= B2400;
|
2997 |
|
|
break;
|
2998 |
|
|
case 4800:
|
2999 |
|
|
cflag |= B4800;
|
3000 |
|
|
break;
|
3001 |
|
|
case 19200:
|
3002 |
|
|
cflag |= B19200;
|
3003 |
|
|
break;
|
3004 |
|
|
case 38400:
|
3005 |
|
|
cflag |= B38400;
|
3006 |
|
|
break;
|
3007 |
|
|
case 57600:
|
3008 |
|
|
cflag |= B57600;
|
3009 |
|
|
break;
|
3010 |
|
|
case 115200:
|
3011 |
|
|
cflag |= B115200;
|
3012 |
|
|
break;
|
3013 |
|
|
case 9600:
|
3014 |
|
|
default:
|
3015 |
|
|
cflag |= B9600;
|
3016 |
|
|
break;
|
3017 |
|
|
}
|
3018 |
|
|
switch(bits) {
|
3019 |
|
|
case 7:
|
3020 |
|
|
cflag |= CS7;
|
3021 |
|
|
break;
|
3022 |
|
|
default:
|
3023 |
|
|
case 8:
|
3024 |
|
|
cflag |= CS8;
|
3025 |
|
|
break;
|
3026 |
|
|
}
|
3027 |
|
|
switch(parity) {
|
3028 |
|
|
case 'o': case 'O':
|
3029 |
|
|
cflag |= PARODD;
|
3030 |
|
|
break;
|
3031 |
|
|
case 'e': case 'E':
|
3032 |
|
|
cflag |= PARENB;
|
3033 |
|
|
break;
|
3034 |
|
|
}
|
3035 |
|
|
co->cflag = cflag;
|
3036 |
|
|
|
3037 |
|
|
/*
|
3038 |
|
|
* Divisor, bytesize and parity
|
3039 |
|
|
*/
|
3040 |
|
|
state = rs_table + co->index;
|
3041 |
|
|
info = &async_sercons;
|
3042 |
|
|
info->magic = SERIAL_MAGIC;
|
3043 |
|
|
info->state = state;
|
3044 |
|
|
info->port = state->port;
|
3045 |
|
|
info->flags = state->flags;
|
3046 |
|
|
info->io_type = state->io_type;
|
3047 |
|
|
info->iomem_base = state->iomem_base;
|
3048 |
|
|
info->iomem_reg_shift = state->iomem_reg_shift;
|
3049 |
|
|
state->baud_base = get_au1x00_uart_baud_base();
|
3050 |
|
|
quot = state->baud_base / baud;
|
3051 |
|
|
|
3052 |
|
|
cval = cflag & (CSIZE | CSTOPB);
|
3053 |
|
|
cval >>= 4;
|
3054 |
|
|
if (cflag & PARENB)
|
3055 |
|
|
cval |= UART_LCR_PARITY;
|
3056 |
|
|
if (!(cflag & PARODD))
|
3057 |
|
|
cval |= UART_LCR_EPAR;
|
3058 |
|
|
|
3059 |
|
|
/*
|
3060 |
|
|
* Disable UART interrupts, set DTR and RTS high
|
3061 |
|
|
* and set speed.
|
3062 |
|
|
*/
|
3063 |
|
|
serial_out(info, UART_CLK, quot & 0xffff);
|
3064 |
|
|
serial_out(info, UART_IER, 0);
|
3065 |
|
|
serial_out(info, UART_MCR, UART_MCR_DTR | UART_MCR_RTS);
|
3066 |
|
|
|
3067 |
|
|
/*
|
3068 |
|
|
* If we read 0xff from the LSR, there is no UART here.
|
3069 |
|
|
*/
|
3070 |
|
|
if (serial_in(info, UART_LSR) == 0xff)
|
3071 |
|
|
return -1;
|
3072 |
|
|
|
3073 |
|
|
return 0;
|
3074 |
|
|
}
|
3075 |
|
|
|
3076 |
|
|
static struct console sercons = {
|
3077 |
|
|
.name = "ttyS",
|
3078 |
|
|
.write = serial_console_write,
|
3079 |
|
|
.device = serial_console_device,
|
3080 |
|
|
.setup = serial_console_setup,
|
3081 |
|
|
.flags = CON_PRINTBUFFER,
|
3082 |
|
|
.index = -1,
|
3083 |
|
|
};
|
3084 |
|
|
|
3085 |
|
|
/*
|
3086 |
|
|
* Register console.
|
3087 |
|
|
*/
|
3088 |
|
|
void __init au1x00_serial_console_init(void)
|
3089 |
|
|
{
|
3090 |
|
|
register_console(&sercons);
|
3091 |
|
|
}
|
3092 |
|
|
#endif
|
3093 |
|
|
|
3094 |
|
|
/*
|
3095 |
|
|
Local variables:
|
3096 |
|
|
compile-command: "gcc -D__KERNEL__ -I../../include -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -fno-strict-aliasing -pipe -fno-strength-reduce -march=i586 -DMODULE -DMODVERSIONS -include ../../include/linux/modversions.h -DEXPORT_SYMTAB -c serial.c"
|
3097 |
|
|
End:
|
3098 |
|
|
*/
|