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