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