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