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