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