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