Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Simulated Serial Driver (fake serial) |
| 3 | * |
| 4 | * This driver is mostly used for bringup purposes and will go away. |
| 5 | * It has a strong dependency on the system console. All outputs |
| 6 | * are rerouted to the same facility as the one used by printk which, in our |
| 7 | * case means sys_sim.c console (goes via the simulator). The code hereafter |
| 8 | * is completely leveraged from the serial.c driver. |
| 9 | * |
| 10 | * Copyright (C) 1999-2000, 2002-2003 Hewlett-Packard Co |
| 11 | * Stephane Eranian <eranian@hpl.hp.com> |
| 12 | * David Mosberger-Tang <davidm@hpl.hp.com> |
| 13 | * |
| 14 | * 02/04/00 D. Mosberger Merged in serial.c bug fixes in rs_close(). |
| 15 | * 02/25/00 D. Mosberger Synced up with 2.3.99pre-5 version of serial.c. |
| 16 | * 07/30/02 D. Mosberger Replace sti()/cli() with explicit spinlocks & local irq masking |
| 17 | */ |
| 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/init.h> |
| 20 | #include <linux/errno.h> |
| 21 | #include <linux/sched.h> |
| 22 | #include <linux/tty.h> |
| 23 | #include <linux/tty_flip.h> |
| 24 | #include <linux/major.h> |
| 25 | #include <linux/fcntl.h> |
| 26 | #include <linux/mm.h> |
Alexey Dobriyan | bf54215 | 2009-03-31 15:19:23 -0700 | [diff] [blame] | 27 | #include <linux/seq_file.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/slab.h> |
Randy Dunlap | a941564 | 2006-01-11 12:17:48 -0800 | [diff] [blame] | 29 | #include <linux/capability.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/console.h> |
| 31 | #include <linux/module.h> |
| 32 | #include <linux/serial.h> |
| 33 | #include <linux/serialP.h> |
David Mosberger-Tang | 819c67e | 2005-06-09 22:40:00 -0700 | [diff] [blame] | 34 | #include <linux/sysrq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
| 36 | #include <asm/irq.h> |
Jiri Slaby | 035cfe5 | 2012-03-08 21:01:17 +0100 | [diff] [blame] | 37 | #include <asm/hpsim.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <asm/hw_irq.h> |
| 39 | #include <asm/uaccess.h> |
| 40 | |
Jiri Slaby | 035cfe5 | 2012-03-08 21:01:17 +0100 | [diff] [blame] | 41 | #include "hpsim_ssc.h" |
| 42 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #undef SIMSERIAL_DEBUG /* define this to get some debug information */ |
| 44 | |
| 45 | #define KEYBOARD_INTR 3 /* must match with simulator! */ |
| 46 | |
| 47 | #define NR_PORTS 1 /* only one port for now */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Jiri Slaby | 979b6d8 | 2012-03-05 14:52:15 +0100 | [diff] [blame] | 49 | #define IRQ_T(state) ((state->flags & ASYNC_SHARE_IRQ) ? IRQF_SHARED : IRQF_DISABLED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | static char *serial_name = "SimSerial driver"; |
| 52 | static char *serial_version = "0.6"; |
| 53 | |
| 54 | /* |
| 55 | * This has been extracted from asm/serial.h. We need one eventually but |
| 56 | * I don't know exactly what we're going to put in it so just fake one |
| 57 | * for now. |
| 58 | */ |
| 59 | #define BASE_BAUD ( 1843200 / 16 ) |
| 60 | |
| 61 | #define STD_COM_FLAGS (ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST) |
| 62 | |
| 63 | /* |
| 64 | * Most of the values here are meaningless to this particular driver. |
| 65 | * However some values must be preserved for the code (leveraged from serial.c |
| 66 | * to work correctly). |
| 67 | * port must not be 0 |
| 68 | * type must not be UNKNOWN |
| 69 | * So I picked arbitrary (guess from where?) values instead |
| 70 | */ |
| 71 | static struct serial_state rs_table[NR_PORTS]={ |
| 72 | /* UART CLK PORT IRQ FLAGS */ |
Jiri Slaby | 9c8efec | 2012-03-05 14:52:12 +0100 | [diff] [blame] | 73 | { BASE_BAUD, 0x3F8, 0, STD_COM_FLAGS, PORT_16550 } /* ttyS0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | /* |
| 77 | * Just for the fun of it ! |
| 78 | */ |
| 79 | static struct serial_uart_config uart_config[] = { |
| 80 | { "unknown", 1, 0 }, |
| 81 | { "8250", 1, 0 }, |
| 82 | { "16450", 1, 0 }, |
| 83 | { "16550", 1, 0 }, |
| 84 | { "16550A", 16, UART_CLEAR_FIFO | UART_USE_FIFO }, |
| 85 | { "cirrus", 1, 0 }, |
| 86 | { "ST16650", 1, UART_CLEAR_FIFO | UART_STARTECH }, |
| 87 | { "ST16650V2", 32, UART_CLEAR_FIFO | UART_USE_FIFO | |
| 88 | UART_STARTECH }, |
| 89 | { "TI16750", 64, UART_CLEAR_FIFO | UART_USE_FIFO}, |
Al Viro | cfa7fd7 | 2006-10-10 22:46:17 +0100 | [diff] [blame] | 90 | { NULL, 0} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | struct tty_driver *hp_simserial_driver; |
| 94 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | static struct console *console; |
| 96 | |
| 97 | static unsigned char *tmp_buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
| 99 | extern struct console *console_drivers; /* from kernel/printk.c */ |
| 100 | |
| 101 | /* |
| 102 | * ------------------------------------------------------------ |
| 103 | * rs_stop() and rs_start() |
| 104 | * |
| 105 | * This routines are called before setting or resetting tty->stopped. |
| 106 | * They enable or disable transmitter interrupts, as necessary. |
| 107 | * ------------------------------------------------------------ |
| 108 | */ |
| 109 | static void rs_stop(struct tty_struct *tty) |
| 110 | { |
| 111 | #ifdef SIMSERIAL_DEBUG |
| 112 | printk("rs_stop: tty->stopped=%d tty->hw_stopped=%d tty->flow_stopped=%d\n", |
| 113 | tty->stopped, tty->hw_stopped, tty->flow_stopped); |
| 114 | #endif |
| 115 | |
| 116 | } |
| 117 | |
| 118 | static void rs_start(struct tty_struct *tty) |
| 119 | { |
viro@ZenIV.linux.org.uk | e72225d | 2005-09-07 23:23:50 +0100 | [diff] [blame] | 120 | #ifdef SIMSERIAL_DEBUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | printk("rs_start: tty->stopped=%d tty->hw_stopped=%d tty->flow_stopped=%d\n", |
| 122 | tty->stopped, tty->hw_stopped, tty->flow_stopped); |
| 123 | #endif |
| 124 | } |
| 125 | |
Al Viro | 5dcded1 | 2006-10-08 14:59:19 +0100 | [diff] [blame] | 126 | static void receive_chars(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | { |
| 128 | unsigned char ch; |
| 129 | static unsigned char seen_esc = 0; |
| 130 | |
| 131 | while ( (ch = ia64_ssc(0, 0, 0, 0, SSC_GETCHAR)) ) { |
| 132 | if ( ch == 27 && seen_esc == 0 ) { |
| 133 | seen_esc = 1; |
| 134 | continue; |
| 135 | } else { |
| 136 | if ( seen_esc==1 && ch == 'O' ) { |
| 137 | seen_esc = 2; |
| 138 | continue; |
| 139 | } else if ( seen_esc == 2 ) { |
David Mosberger-Tang | 819c67e | 2005-06-09 22:40:00 -0700 | [diff] [blame] | 140 | if ( ch == 'P' ) /* F1 */ |
| 141 | show_state(); |
| 142 | #ifdef CONFIG_MAGIC_SYSRQ |
| 143 | if ( ch == 'S' ) { /* F4 */ |
| 144 | do |
| 145 | ch = ia64_ssc(0, 0, 0, 0, |
| 146 | SSC_GETCHAR); |
| 147 | while (!ch); |
Dmitry Torokhov | f335397 | 2010-08-17 21:15:47 -0700 | [diff] [blame] | 148 | handle_sysrq(ch); |
David Mosberger-Tang | 819c67e | 2005-06-09 22:40:00 -0700 | [diff] [blame] | 149 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | seen_esc = 0; |
| 152 | continue; |
| 153 | } |
| 154 | } |
| 155 | seen_esc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
Andreas Schwab | d50f5c5 | 2006-01-13 23:46:38 +0100 | [diff] [blame] | 157 | if (tty_insert_flip_char(tty, ch, TTY_NORMAL) == 0) |
| 158 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | } |
| 160 | tty_flip_buffer_push(tty); |
| 161 | } |
| 162 | |
| 163 | /* |
| 164 | * This is the serial driver's interrupt routine for a single port |
| 165 | */ |
Al Viro | 5dcded1 | 2006-10-08 14:59:19 +0100 | [diff] [blame] | 166 | static irqreturn_t rs_interrupt_single(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | { |
Jiri Slaby | 964105b | 2012-03-05 14:52:17 +0100 | [diff] [blame^] | 168 | struct async_struct *info = dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
Jiri Slaby | 964105b | 2012-03-05 14:52:17 +0100 | [diff] [blame^] | 170 | if (!info->tty) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | printk(KERN_INFO "simrs_interrupt_single: info|tty=0 info=%p problem\n", info); |
| 172 | return IRQ_NONE; |
| 173 | } |
| 174 | /* |
| 175 | * pretty simple in our case, because we only get interrupts |
| 176 | * on inbound traffic |
| 177 | */ |
Al Viro | 5dcded1 | 2006-10-08 14:59:19 +0100 | [diff] [blame] | 178 | receive_chars(info->tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | return IRQ_HANDLED; |
| 180 | } |
| 181 | |
| 182 | /* |
| 183 | * ------------------------------------------------------------------- |
| 184 | * Here ends the serial interrupt routines. |
| 185 | * ------------------------------------------------------------------- |
| 186 | */ |
| 187 | |
Alan Cox | f34d7a5 | 2008-04-30 00:54:13 -0700 | [diff] [blame] | 188 | static int rs_put_char(struct tty_struct *tty, unsigned char ch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | { |
| 190 | struct async_struct *info = (struct async_struct *)tty->driver_data; |
| 191 | unsigned long flags; |
| 192 | |
Alan Cox | f34d7a5 | 2008-04-30 00:54:13 -0700 | [diff] [blame] | 193 | if (!tty || !info->xmit.buf) |
| 194 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | |
| 196 | local_irq_save(flags); |
| 197 | if (CIRC_SPACE(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE) == 0) { |
| 198 | local_irq_restore(flags); |
Alan Cox | f34d7a5 | 2008-04-30 00:54:13 -0700 | [diff] [blame] | 199 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | } |
| 201 | info->xmit.buf[info->xmit.head] = ch; |
| 202 | info->xmit.head = (info->xmit.head + 1) & (SERIAL_XMIT_SIZE-1); |
| 203 | local_irq_restore(flags); |
Alan Cox | f34d7a5 | 2008-04-30 00:54:13 -0700 | [diff] [blame] | 204 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Adrian Bunk | 41c28ff | 2006-03-23 03:00:56 -0800 | [diff] [blame] | 207 | static void transmit_chars(struct async_struct *info, int *intr_done) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | { |
| 209 | int count; |
| 210 | unsigned long flags; |
| 211 | |
| 212 | |
| 213 | local_irq_save(flags); |
| 214 | |
| 215 | if (info->x_char) { |
| 216 | char c = info->x_char; |
| 217 | |
| 218 | console->write(console, &c, 1); |
| 219 | |
| 220 | info->state->icount.tx++; |
| 221 | info->x_char = 0; |
| 222 | |
| 223 | goto out; |
| 224 | } |
| 225 | |
| 226 | if (info->xmit.head == info->xmit.tail || info->tty->stopped || info->tty->hw_stopped) { |
| 227 | #ifdef SIMSERIAL_DEBUG |
| 228 | printk("transmit_chars: head=%d, tail=%d, stopped=%d\n", |
| 229 | info->xmit.head, info->xmit.tail, info->tty->stopped); |
| 230 | #endif |
| 231 | goto out; |
| 232 | } |
| 233 | /* |
| 234 | * We removed the loop and try to do it in to chunks. We need |
| 235 | * 2 operations maximum because it's a ring buffer. |
| 236 | * |
| 237 | * First from current to tail if possible. |
| 238 | * Then from the beginning of the buffer until necessary |
| 239 | */ |
| 240 | |
| 241 | count = min(CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE), |
| 242 | SERIAL_XMIT_SIZE - info->xmit.tail); |
| 243 | console->write(console, info->xmit.buf+info->xmit.tail, count); |
| 244 | |
| 245 | info->xmit.tail = (info->xmit.tail+count) & (SERIAL_XMIT_SIZE-1); |
| 246 | |
| 247 | /* |
| 248 | * We have more at the beginning of the buffer |
| 249 | */ |
| 250 | count = CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE); |
| 251 | if (count) { |
| 252 | console->write(console, info->xmit.buf, count); |
| 253 | info->xmit.tail += count; |
| 254 | } |
| 255 | out: |
| 256 | local_irq_restore(flags); |
| 257 | } |
| 258 | |
| 259 | static void rs_flush_chars(struct tty_struct *tty) |
| 260 | { |
| 261 | struct async_struct *info = (struct async_struct *)tty->driver_data; |
| 262 | |
| 263 | if (info->xmit.head == info->xmit.tail || tty->stopped || tty->hw_stopped || |
| 264 | !info->xmit.buf) |
| 265 | return; |
| 266 | |
| 267 | transmit_chars(info, NULL); |
| 268 | } |
| 269 | |
| 270 | |
| 271 | static int rs_write(struct tty_struct * tty, |
| 272 | const unsigned char *buf, int count) |
| 273 | { |
| 274 | int c, ret = 0; |
| 275 | struct async_struct *info = (struct async_struct *)tty->driver_data; |
| 276 | unsigned long flags; |
| 277 | |
| 278 | if (!tty || !info->xmit.buf || !tmp_buf) return 0; |
| 279 | |
| 280 | local_irq_save(flags); |
| 281 | while (1) { |
| 282 | c = CIRC_SPACE_TO_END(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE); |
| 283 | if (count < c) |
| 284 | c = count; |
| 285 | if (c <= 0) { |
| 286 | break; |
| 287 | } |
| 288 | memcpy(info->xmit.buf + info->xmit.head, buf, c); |
| 289 | info->xmit.head = ((info->xmit.head + c) & |
| 290 | (SERIAL_XMIT_SIZE-1)); |
| 291 | buf += c; |
| 292 | count -= c; |
| 293 | ret += c; |
| 294 | } |
| 295 | local_irq_restore(flags); |
| 296 | /* |
| 297 | * Hey, we transmit directly from here in our case |
| 298 | */ |
| 299 | if (CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE) |
| 300 | && !tty->stopped && !tty->hw_stopped) { |
| 301 | transmit_chars(info, NULL); |
| 302 | } |
| 303 | return ret; |
| 304 | } |
| 305 | |
| 306 | static int rs_write_room(struct tty_struct *tty) |
| 307 | { |
| 308 | struct async_struct *info = (struct async_struct *)tty->driver_data; |
| 309 | |
| 310 | return CIRC_SPACE(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE); |
| 311 | } |
| 312 | |
| 313 | static int rs_chars_in_buffer(struct tty_struct *tty) |
| 314 | { |
| 315 | struct async_struct *info = (struct async_struct *)tty->driver_data; |
| 316 | |
| 317 | return CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE); |
| 318 | } |
| 319 | |
| 320 | static void rs_flush_buffer(struct tty_struct *tty) |
| 321 | { |
| 322 | struct async_struct *info = (struct async_struct *)tty->driver_data; |
| 323 | unsigned long flags; |
| 324 | |
| 325 | local_irq_save(flags); |
| 326 | info->xmit.head = info->xmit.tail = 0; |
| 327 | local_irq_restore(flags); |
| 328 | |
Alan Cox | 15648f1 | 2008-07-16 21:52:25 +0100 | [diff] [blame] | 329 | tty_wakeup(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | /* |
| 333 | * This function is used to send a high-priority XON/XOFF character to |
| 334 | * the device |
| 335 | */ |
| 336 | static void rs_send_xchar(struct tty_struct *tty, char ch) |
| 337 | { |
| 338 | struct async_struct *info = (struct async_struct *)tty->driver_data; |
| 339 | |
| 340 | info->x_char = ch; |
| 341 | if (ch) { |
| 342 | /* |
| 343 | * I guess we could call console->write() directly but |
| 344 | * let's do that for now. |
| 345 | */ |
| 346 | transmit_chars(info, NULL); |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | /* |
| 351 | * ------------------------------------------------------------ |
| 352 | * rs_throttle() |
| 353 | * |
| 354 | * This routine is called by the upper-layer tty layer to signal that |
| 355 | * incoming characters should be throttled. |
| 356 | * ------------------------------------------------------------ |
| 357 | */ |
| 358 | static void rs_throttle(struct tty_struct * tty) |
| 359 | { |
| 360 | if (I_IXOFF(tty)) rs_send_xchar(tty, STOP_CHAR(tty)); |
| 361 | |
| 362 | printk(KERN_INFO "simrs_throttle called\n"); |
| 363 | } |
| 364 | |
| 365 | static void rs_unthrottle(struct tty_struct * tty) |
| 366 | { |
| 367 | struct async_struct *info = (struct async_struct *)tty->driver_data; |
| 368 | |
| 369 | if (I_IXOFF(tty)) { |
| 370 | if (info->x_char) |
| 371 | info->x_char = 0; |
| 372 | else |
| 373 | rs_send_xchar(tty, START_CHAR(tty)); |
| 374 | } |
| 375 | printk(KERN_INFO "simrs_unthrottle called\n"); |
| 376 | } |
| 377 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | |
Luck, Tony | 10e82f6 | 2011-02-22 11:47:04 -0800 | [diff] [blame] | 379 | static int rs_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | { |
| 381 | if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) && |
| 382 | (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGSTRUCT) && |
Alan Cox | 0587102 | 2010-09-16 18:21:52 +0100 | [diff] [blame] | 383 | (cmd != TIOCMIWAIT)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | if (tty->flags & (1 << TTY_IO_ERROR)) |
| 385 | return -EIO; |
| 386 | } |
| 387 | |
| 388 | switch (cmd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | case TIOCGSERIAL: |
| 390 | printk(KERN_INFO "simrs_ioctl TIOCGSERIAL called\n"); |
| 391 | return 0; |
| 392 | case TIOCSSERIAL: |
| 393 | printk(KERN_INFO "simrs_ioctl TIOCSSERIAL called\n"); |
| 394 | return 0; |
| 395 | case TIOCSERCONFIG: |
| 396 | printk(KERN_INFO "rs_ioctl: TIOCSERCONFIG called\n"); |
| 397 | return -EINVAL; |
| 398 | |
| 399 | case TIOCSERGETLSR: /* Get line status register */ |
| 400 | printk(KERN_INFO "rs_ioctl: TIOCSERGETLSR called\n"); |
| 401 | return -EINVAL; |
| 402 | |
| 403 | case TIOCSERGSTRUCT: |
| 404 | printk(KERN_INFO "rs_ioctl: TIOCSERGSTRUCT called\n"); |
| 405 | #if 0 |
| 406 | if (copy_to_user((struct async_struct *) arg, |
| 407 | info, sizeof(struct async_struct))) |
| 408 | return -EFAULT; |
| 409 | #endif |
| 410 | return 0; |
| 411 | |
| 412 | /* |
| 413 | * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change |
| 414 | * - mask passed in arg for lines of interest |
| 415 | * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking) |
| 416 | * Caller should use TIOCGICOUNT to see which one it was |
| 417 | */ |
| 418 | case TIOCMIWAIT: |
| 419 | printk(KERN_INFO "rs_ioctl: TIOCMIWAIT: called\n"); |
| 420 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | case TIOCSERGWILD: |
| 422 | case TIOCSERSWILD: |
| 423 | /* "setserial -W" is called in Debian boot */ |
| 424 | printk (KERN_INFO "TIOCSER?WILD ioctl obsolete, ignored.\n"); |
| 425 | return 0; |
| 426 | |
| 427 | default: |
| 428 | return -ENOIOCTLCMD; |
| 429 | } |
| 430 | return 0; |
| 431 | } |
| 432 | |
| 433 | #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK)) |
| 434 | |
Tony Luck | f889a26 | 2006-12-12 10:47:36 -0800 | [diff] [blame] | 435 | static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | /* Handle turning off CRTSCTS */ |
| 438 | if ((old_termios->c_cflag & CRTSCTS) && |
| 439 | !(tty->termios->c_cflag & CRTSCTS)) { |
| 440 | tty->hw_stopped = 0; |
| 441 | rs_start(tty); |
| 442 | } |
| 443 | } |
| 444 | /* |
| 445 | * This routine will shutdown a serial port; interrupts are disabled, and |
| 446 | * DTR is dropped if the hangup on close termio flag is on. |
| 447 | */ |
| 448 | static void shutdown(struct async_struct * info) |
| 449 | { |
| 450 | unsigned long flags; |
Jiri Slaby | 979b6d8 | 2012-03-05 14:52:15 +0100 | [diff] [blame] | 451 | struct serial_state *state = info->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | |
Jiri Slaby | 979b6d8 | 2012-03-05 14:52:15 +0100 | [diff] [blame] | 453 | if (!(state->flags & ASYNC_INITIALIZED)) |
| 454 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | |
| 456 | #ifdef SIMSERIAL_DEBUG |
| 457 | printk("Shutting down serial port %d (irq %d)....", info->line, |
| 458 | state->irq); |
| 459 | #endif |
| 460 | |
| 461 | local_irq_save(flags); |
| 462 | { |
Jiri Slaby | 964105b | 2012-03-05 14:52:17 +0100 | [diff] [blame^] | 463 | if (state->irq) |
| 464 | free_irq(state->irq, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | |
| 466 | if (info->xmit.buf) { |
| 467 | free_page((unsigned long) info->xmit.buf); |
Al Viro | cfa7fd7 | 2006-10-10 22:46:17 +0100 | [diff] [blame] | 468 | info->xmit.buf = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | if (info->tty) set_bit(TTY_IO_ERROR, &info->tty->flags); |
| 472 | |
Jiri Slaby | 979b6d8 | 2012-03-05 14:52:15 +0100 | [diff] [blame] | 473 | state->flags &= ~ASYNC_INITIALIZED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | } |
| 475 | local_irq_restore(flags); |
| 476 | } |
| 477 | |
| 478 | /* |
| 479 | * ------------------------------------------------------------ |
| 480 | * rs_close() |
| 481 | * |
| 482 | * This routine is called when the serial port gets closed. First, we |
| 483 | * wait for the last remaining data to be sent. Then, we unlink its |
| 484 | * async structure from the interrupt chain if necessary, and we free |
| 485 | * that IRQ if nothing is left in the chain. |
| 486 | * ------------------------------------------------------------ |
| 487 | */ |
| 488 | static void rs_close(struct tty_struct *tty, struct file * filp) |
| 489 | { |
| 490 | struct async_struct * info = (struct async_struct *)tty->driver_data; |
| 491 | struct serial_state *state; |
| 492 | unsigned long flags; |
| 493 | |
| 494 | if (!info ) return; |
| 495 | |
| 496 | state = info->state; |
| 497 | |
| 498 | local_irq_save(flags); |
| 499 | if (tty_hung_up_p(filp)) { |
| 500 | #ifdef SIMSERIAL_DEBUG |
| 501 | printk("rs_close: hung_up\n"); |
| 502 | #endif |
| 503 | local_irq_restore(flags); |
| 504 | return; |
| 505 | } |
| 506 | #ifdef SIMSERIAL_DEBUG |
| 507 | printk("rs_close ttys%d, count = %d\n", info->line, state->count); |
| 508 | #endif |
| 509 | if ((tty->count == 1) && (state->count != 1)) { |
| 510 | /* |
| 511 | * Uh, oh. tty->count is 1, which means that the tty |
| 512 | * structure will be freed. state->count should always |
| 513 | * be one in these conditions. If it's greater than |
| 514 | * one, we've got real problems, since it means the |
| 515 | * serial port won't be shutdown. |
| 516 | */ |
| 517 | printk(KERN_ERR "rs_close: bad serial port count; tty->count is 1, " |
| 518 | "state->count is %d\n", state->count); |
| 519 | state->count = 1; |
| 520 | } |
| 521 | if (--state->count < 0) { |
| 522 | printk(KERN_ERR "rs_close: bad serial port count for ttys%d: %d\n", |
Jiri Slaby | d852256 | 2012-03-05 14:52:16 +0100 | [diff] [blame] | 523 | state->line, state->count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | state->count = 0; |
| 525 | } |
| 526 | if (state->count) { |
| 527 | local_irq_restore(flags); |
| 528 | return; |
| 529 | } |
Jiri Slaby | 979b6d8 | 2012-03-05 14:52:15 +0100 | [diff] [blame] | 530 | state->flags |= ASYNC_CLOSING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | local_irq_restore(flags); |
| 532 | |
| 533 | /* |
| 534 | * Now we wait for the transmit buffer to clear; and we notify |
| 535 | * the line discipline to only process XON/XOFF characters. |
| 536 | */ |
| 537 | shutdown(info); |
Alan Cox | 15648f1 | 2008-07-16 21:52:25 +0100 | [diff] [blame] | 538 | rs_flush_buffer(tty); |
| 539 | tty_ldisc_flush(tty); |
Al Viro | cfa7fd7 | 2006-10-10 22:46:17 +0100 | [diff] [blame] | 540 | info->tty = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | if (info->blocked_open) { |
Jiri Slaby | d852256 | 2012-03-05 14:52:16 +0100 | [diff] [blame] | 542 | if (state->close_delay) |
| 543 | schedule_timeout_interruptible(state->close_delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | wake_up_interruptible(&info->open_wait); |
| 545 | } |
Jiri Slaby | 979b6d8 | 2012-03-05 14:52:15 +0100 | [diff] [blame] | 546 | state->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | wake_up_interruptible(&info->close_wait); |
| 548 | } |
| 549 | |
| 550 | /* |
| 551 | * rs_wait_until_sent() --- wait until the transmitter is empty |
| 552 | */ |
| 553 | static void rs_wait_until_sent(struct tty_struct *tty, int timeout) |
| 554 | { |
| 555 | } |
| 556 | |
| 557 | |
| 558 | /* |
| 559 | * rs_hangup() --- called by tty_hangup() when a hangup is signaled. |
| 560 | */ |
| 561 | static void rs_hangup(struct tty_struct *tty) |
| 562 | { |
| 563 | struct async_struct * info = (struct async_struct *)tty->driver_data; |
| 564 | struct serial_state *state = info->state; |
| 565 | |
| 566 | #ifdef SIMSERIAL_DEBUG |
| 567 | printk("rs_hangup: called\n"); |
| 568 | #endif |
| 569 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | rs_flush_buffer(tty); |
Jiri Slaby | 979b6d8 | 2012-03-05 14:52:15 +0100 | [diff] [blame] | 571 | if (state->flags & ASYNC_CLOSING) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | return; |
| 573 | shutdown(info); |
| 574 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | state->count = 0; |
Jiri Slaby | 979b6d8 | 2012-03-05 14:52:15 +0100 | [diff] [blame] | 576 | state->flags &= ~ASYNC_NORMAL_ACTIVE; |
Al Viro | cfa7fd7 | 2006-10-10 22:46:17 +0100 | [diff] [blame] | 577 | info->tty = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | wake_up_interruptible(&info->open_wait); |
| 579 | } |
| 580 | |
| 581 | |
| 582 | static int get_async_struct(int line, struct async_struct **ret_info) |
| 583 | { |
| 584 | struct async_struct *info; |
| 585 | struct serial_state *sstate; |
| 586 | |
| 587 | sstate = rs_table + line; |
| 588 | sstate->count++; |
| 589 | if (sstate->info) { |
| 590 | *ret_info = sstate->info; |
| 591 | return 0; |
| 592 | } |
Yan Burman | 52fd910 | 2006-12-04 14:58:35 -0800 | [diff] [blame] | 593 | info = kzalloc(sizeof(struct async_struct), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | if (!info) { |
| 595 | sstate->count--; |
| 596 | return -ENOMEM; |
| 597 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | init_waitqueue_head(&info->open_wait); |
| 599 | init_waitqueue_head(&info->close_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | info->state = sstate; |
| 601 | if (sstate->info) { |
| 602 | kfree(info); |
| 603 | *ret_info = sstate->info; |
| 604 | return 0; |
| 605 | } |
| 606 | *ret_info = sstate->info = info; |
| 607 | return 0; |
| 608 | } |
| 609 | |
| 610 | static int |
| 611 | startup(struct async_struct *info) |
| 612 | { |
| 613 | unsigned long flags; |
| 614 | int retval=0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | struct serial_state *state= info->state; |
| 616 | unsigned long page; |
| 617 | |
| 618 | page = get_zeroed_page(GFP_KERNEL); |
| 619 | if (!page) |
| 620 | return -ENOMEM; |
| 621 | |
| 622 | local_irq_save(flags); |
| 623 | |
Jiri Slaby | 979b6d8 | 2012-03-05 14:52:15 +0100 | [diff] [blame] | 624 | if (state->flags & ASYNC_INITIALIZED) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | free_page(page); |
| 626 | goto errout; |
| 627 | } |
| 628 | |
| 629 | if (!state->port || !state->type) { |
| 630 | if (info->tty) set_bit(TTY_IO_ERROR, &info->tty->flags); |
| 631 | free_page(page); |
| 632 | goto errout; |
| 633 | } |
| 634 | if (info->xmit.buf) |
| 635 | free_page(page); |
| 636 | else |
| 637 | info->xmit.buf = (unsigned char *) page; |
| 638 | |
| 639 | #ifdef SIMSERIAL_DEBUG |
| 640 | printk("startup: ttys%d (irq %d)...", info->line, state->irq); |
| 641 | #endif |
| 642 | |
| 643 | /* |
| 644 | * Allocate the IRQ if necessary |
| 645 | */ |
Jiri Slaby | 964105b | 2012-03-05 14:52:17 +0100 | [diff] [blame^] | 646 | if (state->irq) { |
| 647 | retval = request_irq(state->irq, rs_interrupt_single, |
| 648 | IRQ_T(state), "simserial", info); |
Jiri Slaby | 9e12dd5 | 2012-03-08 21:01:19 +0100 | [diff] [blame] | 649 | if (retval) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | goto errout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | } |
| 652 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | if (info->tty) clear_bit(TTY_IO_ERROR, &info->tty->flags); |
| 654 | |
| 655 | info->xmit.head = info->xmit.tail = 0; |
| 656 | |
| 657 | #if 0 |
| 658 | /* |
| 659 | * Set up serial timers... |
| 660 | */ |
| 661 | timer_table[RS_TIMER].expires = jiffies + 2*HZ/100; |
| 662 | timer_active |= 1 << RS_TIMER; |
| 663 | #endif |
| 664 | |
| 665 | /* |
| 666 | * Set up the tty->alt_speed kludge |
| 667 | */ |
| 668 | if (info->tty) { |
Jiri Slaby | 979b6d8 | 2012-03-05 14:52:15 +0100 | [diff] [blame] | 669 | if ((state->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | info->tty->alt_speed = 57600; |
Jiri Slaby | 979b6d8 | 2012-03-05 14:52:15 +0100 | [diff] [blame] | 671 | if ((state->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | info->tty->alt_speed = 115200; |
Jiri Slaby | 979b6d8 | 2012-03-05 14:52:15 +0100 | [diff] [blame] | 673 | if ((state->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | info->tty->alt_speed = 230400; |
Jiri Slaby | 979b6d8 | 2012-03-05 14:52:15 +0100 | [diff] [blame] | 675 | if ((state->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | info->tty->alt_speed = 460800; |
| 677 | } |
| 678 | |
Jiri Slaby | 979b6d8 | 2012-03-05 14:52:15 +0100 | [diff] [blame] | 679 | state->flags |= ASYNC_INITIALIZED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | local_irq_restore(flags); |
| 681 | return 0; |
| 682 | |
| 683 | errout: |
| 684 | local_irq_restore(flags); |
| 685 | return retval; |
| 686 | } |
| 687 | |
| 688 | |
| 689 | /* |
| 690 | * This routine is called whenever a serial port is opened. It |
| 691 | * enables interrupts for a serial port, linking in its async structure into |
| 692 | * the IRQ chain. It also performs the serial-specific |
| 693 | * initialization for the tty structure. |
| 694 | */ |
| 695 | static int rs_open(struct tty_struct *tty, struct file * filp) |
| 696 | { |
| 697 | struct async_struct *info; |
Jiri Slaby | 410235f | 2012-03-05 14:52:01 +0100 | [diff] [blame] | 698 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | unsigned long page; |
| 700 | |
Jiri Slaby | 410235f | 2012-03-05 14:52:01 +0100 | [diff] [blame] | 701 | retval = get_async_struct(tty->index, &info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | if (retval) |
| 703 | return retval; |
| 704 | tty->driver_data = info; |
| 705 | info->tty = tty; |
| 706 | |
| 707 | #ifdef SIMSERIAL_DEBUG |
| 708 | printk("rs_open %s, count = %d\n", tty->name, info->state->count); |
| 709 | #endif |
Jiri Slaby | 979b6d8 | 2012-03-05 14:52:15 +0100 | [diff] [blame] | 710 | info->tty->low_latency = (info->state->flags & ASYNC_LOW_LATENCY) ? 1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | |
| 712 | if (!tmp_buf) { |
| 713 | page = get_zeroed_page(GFP_KERNEL); |
| 714 | if (!page) |
| 715 | return -ENOMEM; |
| 716 | if (tmp_buf) |
| 717 | free_page(page); |
| 718 | else |
| 719 | tmp_buf = (unsigned char *) page; |
| 720 | } |
| 721 | |
| 722 | /* |
| 723 | * If the port is the middle of closing, bail out now |
| 724 | */ |
| 725 | if (tty_hung_up_p(filp) || |
Jiri Slaby | 979b6d8 | 2012-03-05 14:52:15 +0100 | [diff] [blame] | 726 | (info->state->flags & ASYNC_CLOSING)) { |
| 727 | if (info->state->flags & ASYNC_CLOSING) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | interruptible_sleep_on(&info->close_wait); |
| 729 | #ifdef SERIAL_DO_RESTART |
Jiri Slaby | 979b6d8 | 2012-03-05 14:52:15 +0100 | [diff] [blame] | 730 | return ((info->state->flags & ASYNC_HUP_NOTIFY) ? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | -EAGAIN : -ERESTARTSYS); |
| 732 | #else |
| 733 | return -EAGAIN; |
| 734 | #endif |
| 735 | } |
| 736 | |
| 737 | /* |
| 738 | * Start up serial port |
| 739 | */ |
| 740 | retval = startup(info); |
| 741 | if (retval) { |
| 742 | return retval; |
| 743 | } |
| 744 | |
| 745 | /* |
| 746 | * figure out which console to use (should be one already) |
| 747 | */ |
| 748 | console = console_drivers; |
| 749 | while (console) { |
| 750 | if ((console->flags & CON_ENABLED) && console->write) break; |
| 751 | console = console->next; |
| 752 | } |
| 753 | |
| 754 | #ifdef SIMSERIAL_DEBUG |
| 755 | printk("rs_open ttys%d successful\n", info->line); |
| 756 | #endif |
| 757 | return 0; |
| 758 | } |
| 759 | |
| 760 | /* |
| 761 | * /proc fs routines.... |
| 762 | */ |
| 763 | |
Alexey Dobriyan | bf54215 | 2009-03-31 15:19:23 -0700 | [diff] [blame] | 764 | static inline void line_info(struct seq_file *m, struct serial_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | { |
Alexey Dobriyan | bf54215 | 2009-03-31 15:19:23 -0700 | [diff] [blame] | 766 | seq_printf(m, "%d: uart:%s port:%lX irq:%d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | state->line, uart_config[state->type].name, |
| 768 | state->port, state->irq); |
| 769 | } |
| 770 | |
Alexey Dobriyan | bf54215 | 2009-03-31 15:19:23 -0700 | [diff] [blame] | 771 | static int rs_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | { |
Alexey Dobriyan | bf54215 | 2009-03-31 15:19:23 -0700 | [diff] [blame] | 773 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | |
Alexey Dobriyan | bf54215 | 2009-03-31 15:19:23 -0700 | [diff] [blame] | 775 | seq_printf(m, "simserinfo:1.0 driver:%s\n", serial_version); |
| 776 | for (i = 0; i < NR_PORTS; i++) |
| 777 | line_info(m, &rs_table[i]); |
| 778 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | } |
| 780 | |
Alexey Dobriyan | bf54215 | 2009-03-31 15:19:23 -0700 | [diff] [blame] | 781 | static int rs_proc_open(struct inode *inode, struct file *file) |
| 782 | { |
| 783 | return single_open(file, rs_proc_show, NULL); |
| 784 | } |
| 785 | |
| 786 | static const struct file_operations rs_proc_fops = { |
| 787 | .owner = THIS_MODULE, |
| 788 | .open = rs_proc_open, |
| 789 | .read = seq_read, |
| 790 | .llseek = seq_lseek, |
| 791 | .release = single_release, |
| 792 | }; |
| 793 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | /* |
| 795 | * --------------------------------------------------------------------- |
| 796 | * rs_init() and friends |
| 797 | * |
| 798 | * rs_init() is called at boot-time to initialize the serial driver. |
| 799 | * --------------------------------------------------------------------- |
| 800 | */ |
| 801 | |
| 802 | /* |
| 803 | * This routine prints out the appropriate serial driver version |
| 804 | * number, and identifies which options were configured into this |
| 805 | * driver. |
| 806 | */ |
| 807 | static inline void show_serial_version(void) |
| 808 | { |
| 809 | printk(KERN_INFO "%s version %s with", serial_name, serial_version); |
| 810 | printk(KERN_INFO " no serial options enabled\n"); |
| 811 | } |
| 812 | |
Jeff Dike | b68e31d | 2006-10-02 02:17:18 -0700 | [diff] [blame] | 813 | static const struct tty_operations hp_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | .open = rs_open, |
| 815 | .close = rs_close, |
| 816 | .write = rs_write, |
| 817 | .put_char = rs_put_char, |
| 818 | .flush_chars = rs_flush_chars, |
| 819 | .write_room = rs_write_room, |
| 820 | .chars_in_buffer = rs_chars_in_buffer, |
| 821 | .flush_buffer = rs_flush_buffer, |
| 822 | .ioctl = rs_ioctl, |
| 823 | .throttle = rs_throttle, |
| 824 | .unthrottle = rs_unthrottle, |
| 825 | .send_xchar = rs_send_xchar, |
| 826 | .set_termios = rs_set_termios, |
| 827 | .stop = rs_stop, |
| 828 | .start = rs_start, |
| 829 | .hangup = rs_hangup, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | .wait_until_sent = rs_wait_until_sent, |
Alexey Dobriyan | bf54215 | 2009-03-31 15:19:23 -0700 | [diff] [blame] | 831 | .proc_fops = &rs_proc_fops, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | }; |
| 833 | |
| 834 | /* |
| 835 | * The serial driver boot-time initialization code! |
| 836 | */ |
| 837 | static int __init |
| 838 | simrs_init (void) |
| 839 | { |
Kenji Kaneshige | 3b5cc09 | 2005-07-10 21:49:00 -0700 | [diff] [blame] | 840 | int i, rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | struct serial_state *state; |
| 842 | |
| 843 | if (!ia64_platform_is("hpsim")) |
| 844 | return -ENODEV; |
| 845 | |
Jiri Slaby | 410235f | 2012-03-05 14:52:01 +0100 | [diff] [blame] | 846 | hp_simserial_driver = alloc_tty_driver(NR_PORTS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | if (!hp_simserial_driver) |
| 848 | return -ENOMEM; |
| 849 | |
| 850 | show_serial_version(); |
| 851 | |
| 852 | /* Initialize the tty_driver structure */ |
| 853 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | hp_simserial_driver->driver_name = "simserial"; |
| 855 | hp_simserial_driver->name = "ttyS"; |
| 856 | hp_simserial_driver->major = TTY_MAJOR; |
| 857 | hp_simserial_driver->minor_start = 64; |
| 858 | hp_simserial_driver->type = TTY_DRIVER_TYPE_SERIAL; |
| 859 | hp_simserial_driver->subtype = SERIAL_TYPE_NORMAL; |
| 860 | hp_simserial_driver->init_termios = tty_std_termios; |
| 861 | hp_simserial_driver->init_termios.c_cflag = |
| 862 | B9600 | CS8 | CREAD | HUPCL | CLOCAL; |
| 863 | hp_simserial_driver->flags = TTY_DRIVER_REAL_RAW; |
| 864 | tty_set_operations(hp_simserial_driver, &hp_ops); |
| 865 | |
| 866 | /* |
| 867 | * Let's have a little bit of fun ! |
| 868 | */ |
| 869 | for (i = 0, state = rs_table; i < NR_PORTS; i++,state++) { |
| 870 | |
| 871 | if (state->type == PORT_UNKNOWN) continue; |
| 872 | |
| 873 | if (!state->irq) { |
Jiri Slaby | 6efb6b7 | 2012-03-08 21:01:18 +0100 | [diff] [blame] | 874 | if ((rc = hpsim_get_irq(KEYBOARD_INTR)) < 0) |
Kenji Kaneshige | 3b5cc09 | 2005-07-10 21:49:00 -0700 | [diff] [blame] | 875 | panic("%s: out of interrupt vectors!\n", |
Harvey Harrison | d4ed808 | 2008-03-04 15:15:00 -0800 | [diff] [blame] | 876 | __func__); |
Kenji Kaneshige | 3b5cc09 | 2005-07-10 21:49:00 -0700 | [diff] [blame] | 877 | state->irq = rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | printk(KERN_INFO "ttyS%d at 0x%04lx (irq = %d) is a %s\n", |
| 881 | state->line, |
| 882 | state->port, state->irq, |
| 883 | uart_config[state->type].name); |
| 884 | } |
| 885 | |
| 886 | if (tty_register_driver(hp_simserial_driver)) |
| 887 | panic("Couldn't register simserial driver\n"); |
| 888 | |
| 889 | return 0; |
| 890 | } |
| 891 | |
| 892 | #ifndef MODULE |
| 893 | __initcall(simrs_init); |
| 894 | #endif |