Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/char/serial167.c |
| 3 | * |
| 4 | * Driver for MVME166/7 board serial ports, which are via a CD2401. |
| 5 | * Based very much on cyclades.c. |
| 6 | * |
| 7 | * MVME166/7 work by Richard Hirst [richard@sleepie.demon.co.uk] |
| 8 | * |
| 9 | * ============================================================== |
| 10 | * |
| 11 | * static char rcsid[] = |
| 12 | * "$Revision: 1.36.1.4 $$Date: 1995/03/29 06:14:14 $"; |
| 13 | * |
| 14 | * linux/kernel/cyclades.c |
| 15 | * |
| 16 | * Maintained by Marcio Saito (cyclades@netcom.com) and |
| 17 | * Randolph Bentson (bentson@grieg.seaslug.org) |
| 18 | * |
| 19 | * Much of the design and some of the code came from serial.c |
| 20 | * which was copyright (C) 1991, 1992 Linus Torvalds. It was |
| 21 | * extensively rewritten by Theodore Ts'o, 8/16/92 -- 9/14/92, |
| 22 | * and then fixed as suggested by Michael K. Johnson 12/12/92. |
| 23 | * |
| 24 | * This version does not support shared irq's. |
| 25 | * |
| 26 | * $Log: cyclades.c,v $ |
| 27 | * Revision 1.36.1.4 1995/03/29 06:14:14 bentson |
| 28 | * disambiguate between Cyclom-16Y and Cyclom-32Ye; |
| 29 | * |
| 30 | * Changes: |
| 31 | * |
| 32 | * 200 lines of changes record removed - RGH 11-10-95, starting work on |
| 33 | * converting this to drive serial ports on mvme166 (cd2401). |
| 34 | * |
| 35 | * Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 2000/08/25 |
| 36 | * - get rid of verify_area |
| 37 | * - use get_user to access memory from userspace in set_threshold, |
| 38 | * set_default_threshold and set_timeout |
| 39 | * - don't use the panic function in serial167_init |
| 40 | * - do resource release on failure on serial167_init |
| 41 | * - include missing restore_flags in mvme167_serial_console_setup |
| 42 | * |
| 43 | * Kars de Jong <jongk@linux-m68k.org> - 2004/09/06 |
| 44 | * - replace bottom half handler with task queue handler |
| 45 | */ |
| 46 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include <linux/errno.h> |
| 48 | #include <linux/signal.h> |
| 49 | #include <linux/sched.h> |
| 50 | #include <linux/timer.h> |
| 51 | #include <linux/tty.h> |
| 52 | #include <linux/interrupt.h> |
| 53 | #include <linux/serial.h> |
| 54 | #include <linux/serialP.h> |
Alexey Dobriyan | 405f557 | 2009-07-11 22:08:37 +0400 | [diff] [blame] | 55 | #include <linux/smp_lock.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #include <linux/string.h> |
| 57 | #include <linux/fcntl.h> |
| 58 | #include <linux/ptrace.h> |
| 59 | #include <linux/serial167.h> |
| 60 | #include <linux/delay.h> |
| 61 | #include <linux/major.h> |
| 62 | #include <linux/mm.h> |
| 63 | #include <linux/console.h> |
| 64 | #include <linux/module.h> |
| 65 | #include <linux/bitops.h> |
Geert Uytterhoeven | 81e859a | 2006-10-09 22:27:42 +0200 | [diff] [blame] | 66 | #include <linux/tty_flip.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 67 | #include <linux/gfp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
| 69 | #include <asm/system.h> |
| 70 | #include <asm/io.h> |
| 71 | #include <asm/mvme16xhw.h> |
| 72 | #include <asm/bootinfo.h> |
| 73 | #include <asm/setup.h> |
| 74 | |
| 75 | #include <linux/types.h> |
| 76 | #include <linux/kernel.h> |
| 77 | |
| 78 | #include <asm/uaccess.h> |
| 79 | #include <linux/init.h> |
| 80 | |
| 81 | #define SERIAL_PARANOIA_CHECK |
| 82 | #undef SERIAL_DEBUG_OPEN |
| 83 | #undef SERIAL_DEBUG_THROTTLE |
| 84 | #undef SERIAL_DEBUG_OTHER |
| 85 | #undef SERIAL_DEBUG_IO |
| 86 | #undef SERIAL_DEBUG_COUNT |
| 87 | #undef SERIAL_DEBUG_DTR |
| 88 | #undef CYCLOM_16Y_HACK |
| 89 | #define CYCLOM_ENABLE_MONITORING |
| 90 | |
| 91 | #define WAKEUP_CHARS 256 |
| 92 | |
| 93 | #define STD_COM_FLAGS (0) |
| 94 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | static struct tty_driver *cy_serial_driver; |
| 96 | extern int serial_console; |
| 97 | static struct cyclades_port *serial_console_info = NULL; |
| 98 | static unsigned int serial_console_cflag = 0; |
| 99 | u_char initial_console_speed; |
| 100 | |
| 101 | /* Base address of cd2401 chip on mvme166/7 */ |
| 102 | |
| 103 | #define BASE_ADDR (0xfff45000) |
| 104 | #define pcc2chip ((volatile u_char *)0xfff42000) |
| 105 | #define PccSCCMICR 0x1d |
| 106 | #define PccSCCTICR 0x1e |
| 107 | #define PccSCCRICR 0x1f |
| 108 | #define PccTPIACKR 0x25 |
| 109 | #define PccRPIACKR 0x27 |
| 110 | #define PccIMLR 0x3f |
| 111 | |
| 112 | /* This is the per-port data structure */ |
| 113 | struct cyclades_port cy_port[] = { |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 114 | /* CARD# */ |
| 115 | {-1}, /* ttyS0 */ |
| 116 | {-1}, /* ttyS1 */ |
| 117 | {-1}, /* ttyS2 */ |
| 118 | {-1}, /* ttyS3 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | }; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 120 | |
Tobias Klauser | fe97107 | 2006-01-09 20:54:02 -0800 | [diff] [blame] | 121 | #define NR_PORTS ARRAY_SIZE(cy_port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
| 123 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | * This is used to look up the divisor speeds and the timeouts |
| 125 | * We're normally limited to 15 distinct baud rates. The extra |
| 126 | * are accessed via settings in info->flags. |
| 127 | * 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, |
| 128 | * 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, |
| 129 | * HI VHI |
| 130 | */ |
| 131 | static int baud_table[] = { |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 132 | 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, |
| 133 | 1800, 2400, 4800, 9600, 19200, 38400, 57600, 76800, 115200, 150000, |
| 134 | 0 |
| 135 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
| 137 | #if 0 |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 138 | static char baud_co[] = { /* 25 MHz clock option table */ |
| 139 | /* value => 00 01 02 03 04 */ |
| 140 | /* divide by 8 32 128 512 2048 */ |
| 141 | 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x02, |
| 142 | 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 143 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 145 | static char baud_bpr[] = { /* 25 MHz baud rate period table */ |
| 146 | 0x00, 0xf5, 0xa3, 0x6f, 0x5c, 0x51, 0xf5, 0xa3, 0x51, 0xa3, |
| 147 | 0x6d, 0x51, 0xa3, 0x51, 0xa3, 0x51, 0x36, 0x29, 0x1b, 0x15 |
| 148 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | #endif |
| 150 | |
| 151 | /* I think 166 brd clocks 2401 at 20MHz.... */ |
| 152 | |
| 153 | /* These values are written directly to tcor, and >> 5 for writing to rcor */ |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 154 | static u_char baud_co[] = { /* 20 MHz clock option table */ |
| 155 | 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x60, 0x60, 0x40, |
| 156 | 0x40, 0x40, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 157 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
| 159 | /* These values written directly to tbpr/rbpr */ |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 160 | static u_char baud_bpr[] = { /* 20 MHz baud rate period table */ |
| 161 | 0x00, 0xc0, 0x80, 0x58, 0x6c, 0x40, 0xc0, 0x81, 0x40, 0x81, |
| 162 | 0x57, 0x40, 0x81, 0x40, 0x81, 0x40, 0x2b, 0x20, 0x15, 0x10 |
| 163 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 165 | static u_char baud_cor4[] = { /* receive threshold */ |
| 166 | 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, |
| 167 | 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x07 |
| 168 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
| 170 | static void shutdown(struct cyclades_port *); |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 171 | static int startup(struct cyclades_port *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | static void cy_throttle(struct tty_struct *); |
| 173 | static void cy_unthrottle(struct tty_struct *); |
| 174 | static void config_setup(struct cyclades_port *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | #ifdef CYCLOM_SHOW_STATUS |
| 176 | static void show_status(int); |
| 177 | #endif |
| 178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | /* |
| 180 | * I have my own version of udelay(), as it is needed when initialising |
| 181 | * the chip, before the delay loop has been calibrated. Should probably |
| 182 | * reference one of the vmechip2 or pccchip2 counter for an accurate |
| 183 | * delay, but this wild guess will do for now. |
| 184 | */ |
| 185 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 186 | void my_udelay(long us) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | { |
| 188 | u_char x; |
| 189 | volatile u_char *p = &x; |
| 190 | int i; |
| 191 | |
| 192 | while (us--) |
| 193 | for (i = 100; i; i--) |
| 194 | x |= *p; |
| 195 | } |
| 196 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 197 | static inline int serial_paranoia_check(struct cyclades_port *info, char *name, |
| 198 | const char *routine) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | { |
| 200 | #ifdef SERIAL_PARANOIA_CHECK |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 201 | if (!info) { |
| 202 | printk("Warning: null cyclades_port for (%s) in %s\n", name, |
| 203 | routine); |
| 204 | return 1; |
| 205 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | |
Roel Kluin | f23fc15 | 2009-10-01 15:44:25 -0700 | [diff] [blame] | 207 | if (info < &cy_port[0] || info >= &cy_port[NR_PORTS]) { |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 208 | printk("Warning: cyclades_port out of range for (%s) in %s\n", |
| 209 | name, routine); |
| 210 | return 1; |
| 211 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 213 | if (info->magic != CYCLADES_MAGIC) { |
| 214 | printk("Warning: bad magic number for serial struct (%s) in " |
| 215 | "%s\n", name, routine); |
| 216 | return 1; |
| 217 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | #endif |
| 219 | return 0; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 220 | } /* serial_paranoia_check */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | |
| 222 | #if 0 |
| 223 | /* The following diagnostic routines allow the driver to spew |
| 224 | information on the screen, even (especially!) during interrupts. |
| 225 | */ |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 226 | void SP(char *data) |
| 227 | { |
| 228 | unsigned long flags; |
| 229 | local_irq_save(flags); |
Anirban Sinha | 353f6dd | 2009-09-14 11:13:37 -0700 | [diff] [blame] | 230 | printk(KERN_EMERG "%s", data); |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 231 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 234 | char scrn[2]; |
| 235 | void CP(char data) |
| 236 | { |
| 237 | unsigned long flags; |
| 238 | local_irq_save(flags); |
| 239 | scrn[0] = data; |
Anirban Sinha | 353f6dd | 2009-09-14 11:13:37 -0700 | [diff] [blame] | 240 | printk(KERN_EMERG "%c", scrn); |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 241 | local_irq_restore(flags); |
| 242 | } /* CP */ |
| 243 | |
| 244 | void CP1(int data) |
| 245 | { |
| 246 | (data < 10) ? CP(data + '0') : CP(data + 'A' - 10); |
| 247 | } /* CP1 */ |
| 248 | void CP2(int data) |
| 249 | { |
| 250 | CP1((data >> 4) & 0x0f); |
| 251 | CP1(data & 0x0f); |
| 252 | } /* CP2 */ |
| 253 | void CP4(int data) |
| 254 | { |
| 255 | CP2((data >> 8) & 0xff); |
| 256 | CP2(data & 0xff); |
| 257 | } /* CP4 */ |
| 258 | void CP8(long data) |
| 259 | { |
| 260 | CP4((data >> 16) & 0xffff); |
| 261 | CP4(data & 0xffff); |
| 262 | } /* CP8 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | #endif |
| 264 | |
| 265 | /* This routine waits up to 1000 micro-seconds for the previous |
| 266 | command to the Cirrus chip to complete and then issues the |
| 267 | new command. An error is returned if the previous command |
| 268 | didn't finish within the time limit. |
| 269 | */ |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 270 | u_short write_cy_cmd(volatile u_char * base_addr, u_char cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | { |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 272 | unsigned long flags; |
| 273 | volatile int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 275 | local_irq_save(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | /* Check to see that the previous command has completed */ |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 277 | for (i = 0; i < 100; i++) { |
| 278 | if (base_addr[CyCCR] == 0) { |
| 279 | break; |
| 280 | } |
| 281 | my_udelay(10L); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | } |
| 283 | /* if the CCR never cleared, the previous command |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 284 | didn't finish within the "reasonable time" */ |
| 285 | if (i == 10) { |
| 286 | local_irq_restore(flags); |
| 287 | return (-1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | /* Issue the new command */ |
| 291 | base_addr[CyCCR] = cmd; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 292 | local_irq_restore(flags); |
| 293 | return (0); |
| 294 | } /* write_cy_cmd */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | |
| 296 | /* cy_start and cy_stop provide software output flow control as a |
| 297 | function of XON/XOFF, software CTS, and other such stuff. */ |
| 298 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 299 | static void cy_stop(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 301 | struct cyclades_port *info = tty->driver_data; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 302 | volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR; |
| 303 | int channel; |
| 304 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | |
| 306 | #ifdef SERIAL_DEBUG_OTHER |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 307 | printk("cy_stop %s\n", tty->name); /* */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | #endif |
| 309 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 310 | if (serial_paranoia_check(info, tty->name, "cy_stop")) |
| 311 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 313 | channel = info->line; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 315 | local_irq_save(flags); |
| 316 | base_addr[CyCAR] = (u_char) (channel); /* index channel */ |
| 317 | base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy); |
| 318 | local_irq_restore(flags); |
| 319 | } /* cy_stop */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 321 | static void cy_start(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 323 | struct cyclades_port *info = tty->driver_data; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 324 | volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR; |
| 325 | int channel; |
| 326 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | |
| 328 | #ifdef SERIAL_DEBUG_OTHER |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 329 | printk("cy_start %s\n", tty->name); /* */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | #endif |
| 331 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 332 | if (serial_paranoia_check(info, tty->name, "cy_start")) |
| 333 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 335 | channel = info->line; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 337 | local_irq_save(flags); |
| 338 | base_addr[CyCAR] = (u_char) (channel); |
| 339 | base_addr[CyIER] |= CyTxMpty; |
| 340 | local_irq_restore(flags); |
| 341 | } /* cy_start */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | /* The real interrupt service routines are called |
| 344 | whenever the card wants its hand held--chars |
| 345 | received, out buffer empty, modem change, etc. |
| 346 | */ |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 347 | static irqreturn_t cd2401_rxerr_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | { |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 349 | struct tty_struct *tty; |
| 350 | struct cyclades_port *info; |
| 351 | volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR; |
| 352 | unsigned char err, rfoc; |
| 353 | int channel; |
| 354 | char data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 356 | /* determine the channel and change to that context */ |
| 357 | channel = (u_short) (base_addr[CyLICR] >> 2); |
| 358 | info = &cy_port[channel]; |
| 359 | info->last_active = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 361 | if ((err = base_addr[CyRISR]) & CyTIMEOUT) { |
| 362 | /* This is a receive timeout interrupt, ignore it */ |
| 363 | base_addr[CyREOIR] = CyNOTRANS; |
| 364 | return IRQ_HANDLED; |
| 365 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 367 | /* Read a byte of data if there is any - assume the error |
| 368 | * is associated with this character */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 370 | if ((rfoc = base_addr[CyRFOC]) != 0) |
| 371 | data = base_addr[CyRDR]; |
| 372 | else |
| 373 | data = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 375 | /* if there is nowhere to put the data, discard it */ |
| 376 | if (info->tty == 0) { |
| 377 | base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS; |
| 378 | return IRQ_HANDLED; |
| 379 | } else { /* there is an open port for this data */ |
| 380 | tty = info->tty; |
| 381 | if (err & info->ignore_status_mask) { |
| 382 | base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS; |
| 383 | return IRQ_HANDLED; |
| 384 | } |
| 385 | if (tty_buffer_request_room(tty, 1) != 0) { |
| 386 | if (err & info->read_status_mask) { |
| 387 | if (err & CyBREAK) { |
| 388 | tty_insert_flip_char(tty, data, |
| 389 | TTY_BREAK); |
| 390 | if (info->flags & ASYNC_SAK) { |
| 391 | do_SAK(tty); |
| 392 | } |
| 393 | } else if (err & CyFRAME) { |
| 394 | tty_insert_flip_char(tty, data, |
| 395 | TTY_FRAME); |
| 396 | } else if (err & CyPARITY) { |
| 397 | tty_insert_flip_char(tty, data, |
| 398 | TTY_PARITY); |
| 399 | } else if (err & CyOVERRUN) { |
| 400 | tty_insert_flip_char(tty, 0, |
| 401 | TTY_OVERRUN); |
| 402 | /* |
| 403 | If the flip buffer itself is |
Nick Andrew | c4f0124 | 2008-12-05 16:34:46 +0000 | [diff] [blame] | 404 | overflowing, we still lose |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 405 | the next incoming character. |
| 406 | */ |
| 407 | if (tty_buffer_request_room(tty, 1) != |
| 408 | 0) { |
| 409 | tty_insert_flip_char(tty, data, |
| 410 | TTY_FRAME); |
| 411 | } |
| 412 | /* These two conditions may imply */ |
| 413 | /* a normal read should be done. */ |
| 414 | /* else if(data & CyTIMEOUT) */ |
| 415 | /* else if(data & CySPECHAR) */ |
| 416 | } else { |
| 417 | tty_insert_flip_char(tty, 0, |
| 418 | TTY_NORMAL); |
| 419 | } |
| 420 | } else { |
| 421 | tty_insert_flip_char(tty, data, TTY_NORMAL); |
| 422 | } |
| 423 | } else { |
| 424 | /* there was a software buffer overrun |
| 425 | and nothing could be done about it!!! */ |
| 426 | } |
| 427 | } |
| 428 | tty_schedule_flip(tty); |
| 429 | /* end of service */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS; |
| 431 | return IRQ_HANDLED; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 432 | } /* cy_rxerr_interrupt */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 434 | static irqreturn_t cd2401_modem_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | { |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 436 | struct cyclades_port *info; |
| 437 | volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR; |
| 438 | int channel; |
| 439 | int mdm_change; |
| 440 | int mdm_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 442 | /* determine the channel and change to that context */ |
| 443 | channel = (u_short) (base_addr[CyLICR] >> 2); |
| 444 | info = &cy_port[channel]; |
| 445 | info->last_active = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 447 | mdm_change = base_addr[CyMISR]; |
| 448 | mdm_status = base_addr[CyMSVR1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 450 | if (info->tty == 0) { /* nowhere to put the data, ignore it */ |
| 451 | ; |
| 452 | } else { |
| 453 | if ((mdm_change & CyDCD) |
| 454 | && (info->flags & ASYNC_CHECK_CD)) { |
| 455 | if (mdm_status & CyDCD) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | /* CP('!'); */ |
Jiri Slaby | 3099bbc | 2008-02-07 00:16:40 -0800 | [diff] [blame] | 457 | wake_up_interruptible(&info->open_wait); |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 458 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | /* CP('@'); */ |
Jiri Slaby | 3099bbc | 2008-02-07 00:16:40 -0800 | [diff] [blame] | 460 | tty_hangup(info->tty); |
| 461 | wake_up_interruptible(&info->open_wait); |
| 462 | info->flags &= ~ASYNC_NORMAL_ACTIVE; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 463 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | } |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 465 | if ((mdm_change & CyCTS) |
| 466 | && (info->flags & ASYNC_CTS_FLOW)) { |
| 467 | if (info->tty->stopped) { |
| 468 | if (mdm_status & CyCTS) { |
| 469 | /* !!! cy_start isn't used because... */ |
| 470 | info->tty->stopped = 0; |
| 471 | base_addr[CyIER] |= CyTxMpty; |
Jiri Slaby | 3099bbc | 2008-02-07 00:16:40 -0800 | [diff] [blame] | 472 | tty_wakeup(info->tty); |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 473 | } |
| 474 | } else { |
| 475 | if (!(mdm_status & CyCTS)) { |
| 476 | /* !!! cy_stop isn't used because... */ |
| 477 | info->tty->stopped = 1; |
| 478 | base_addr[CyIER] &= |
| 479 | ~(CyTxMpty | CyTxRdy); |
| 480 | } |
| 481 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | } |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 483 | if (mdm_status & CyDSR) { |
| 484 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | } |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 486 | base_addr[CyMEOIR] = 0; |
| 487 | return IRQ_HANDLED; |
| 488 | } /* cy_modem_interrupt */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 490 | static irqreturn_t cd2401_tx_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | { |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 492 | struct cyclades_port *info; |
| 493 | volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR; |
| 494 | int channel; |
| 495 | int char_count, saved_cnt; |
| 496 | int outch; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 498 | /* determine the channel and change to that context */ |
| 499 | channel = (u_short) (base_addr[CyLICR] >> 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 501 | /* validate the port number (as configured and open) */ |
| 502 | if ((channel < 0) || (NR_PORTS <= channel)) { |
| 503 | base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy); |
| 504 | base_addr[CyTEOIR] = CyNOTRANS; |
| 505 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | } |
Roel Kluin | f23fc15 | 2009-10-01 15:44:25 -0700 | [diff] [blame] | 507 | info = &cy_port[channel]; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 508 | info->last_active = jiffies; |
| 509 | if (info->tty == 0) { |
| 510 | base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy); |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 511 | base_addr[CyTEOIR] = CyNOTRANS; |
| 512 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | } |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 514 | |
| 515 | /* load the on-chip space available for outbound data */ |
| 516 | saved_cnt = char_count = base_addr[CyTFTC]; |
| 517 | |
| 518 | if (info->x_char) { /* send special char */ |
| 519 | outch = info->x_char; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | base_addr[CyTDR] = outch; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | char_count--; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 522 | info->x_char = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 525 | if (info->x_break) { |
| 526 | /* The Cirrus chip requires the "Embedded Transmit |
| 527 | Commands" of start break, delay, and end break |
| 528 | sequences to be sent. The duration of the |
| 529 | break is given in TICs, which runs at HZ |
| 530 | (typically 100) and the PPR runs at 200 Hz, |
| 531 | so the delay is duration * 200/HZ, and thus a |
| 532 | break can run from 1/100 sec to about 5/4 sec. |
| 533 | Need to check these values - RGH 141095. |
| 534 | */ |
| 535 | base_addr[CyTDR] = 0; /* start break */ |
| 536 | base_addr[CyTDR] = 0x81; |
| 537 | base_addr[CyTDR] = 0; /* delay a bit */ |
| 538 | base_addr[CyTDR] = 0x82; |
| 539 | base_addr[CyTDR] = info->x_break * 200 / HZ; |
| 540 | base_addr[CyTDR] = 0; /* terminate break */ |
| 541 | base_addr[CyTDR] = 0x83; |
| 542 | char_count -= 7; |
| 543 | info->x_break = 0; |
| 544 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 546 | while (char_count > 0) { |
| 547 | if (!info->xmit_cnt) { |
| 548 | base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy); |
| 549 | break; |
| 550 | } |
| 551 | if (info->xmit_buf == 0) { |
| 552 | base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy); |
| 553 | break; |
| 554 | } |
| 555 | if (info->tty->stopped || info->tty->hw_stopped) { |
| 556 | base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy); |
| 557 | break; |
| 558 | } |
| 559 | /* Because the Embedded Transmit Commands have been |
| 560 | enabled, we must check to see if the escape |
| 561 | character, NULL, is being sent. If it is, we |
| 562 | must ensure that there is room for it to be |
| 563 | doubled in the output stream. Therefore we |
| 564 | no longer advance the pointer when the character |
| 565 | is fetched, but rather wait until after the check |
| 566 | for a NULL output character. (This is necessary |
| 567 | because there may not be room for the two chars |
| 568 | needed to send a NULL. |
| 569 | */ |
| 570 | outch = info->xmit_buf[info->xmit_tail]; |
| 571 | if (outch) { |
| 572 | info->xmit_cnt--; |
| 573 | info->xmit_tail = (info->xmit_tail + 1) |
| 574 | & (PAGE_SIZE - 1); |
| 575 | base_addr[CyTDR] = outch; |
| 576 | char_count--; |
| 577 | } else { |
| 578 | if (char_count > 1) { |
| 579 | info->xmit_cnt--; |
| 580 | info->xmit_tail = (info->xmit_tail + 1) |
| 581 | & (PAGE_SIZE - 1); |
| 582 | base_addr[CyTDR] = outch; |
| 583 | base_addr[CyTDR] = 0; |
| 584 | char_count--; |
| 585 | char_count--; |
| 586 | } else { |
| 587 | break; |
| 588 | } |
| 589 | } |
| 590 | } |
| 591 | |
Jiri Slaby | 3099bbc | 2008-02-07 00:16:40 -0800 | [diff] [blame] | 592 | if (info->xmit_cnt < WAKEUP_CHARS) |
| 593 | tty_wakeup(info->tty); |
| 594 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 595 | base_addr[CyTEOIR] = (char_count != saved_cnt) ? 0 : CyNOTRANS; |
| 596 | return IRQ_HANDLED; |
| 597 | } /* cy_tx_interrupt */ |
| 598 | |
| 599 | static irqreturn_t cd2401_rx_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | { |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 601 | struct tty_struct *tty; |
| 602 | struct cyclades_port *info; |
| 603 | volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR; |
| 604 | int channel; |
| 605 | char data; |
| 606 | int char_count; |
| 607 | int save_cnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 609 | /* determine the channel and change to that context */ |
| 610 | channel = (u_short) (base_addr[CyLICR] >> 2); |
| 611 | info = &cy_port[channel]; |
| 612 | info->last_active = jiffies; |
| 613 | save_cnt = char_count = base_addr[CyRFOC]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 615 | /* if there is nowhere to put the data, discard it */ |
| 616 | if (info->tty == 0) { |
| 617 | while (char_count--) { |
| 618 | data = base_addr[CyRDR]; |
| 619 | } |
| 620 | } else { /* there is an open port for this data */ |
| 621 | tty = info->tty; |
| 622 | /* load # characters available from the chip */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | |
| 624 | #ifdef CYCLOM_ENABLE_MONITORING |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 625 | ++info->mon.int_count; |
| 626 | info->mon.char_count += char_count; |
| 627 | if (char_count > info->mon.char_max) |
| 628 | info->mon.char_max = char_count; |
| 629 | info->mon.char_last = char_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | #endif |
Alan Cox | 4165fe4 | 2010-02-17 13:07:13 +0000 | [diff] [blame] | 631 | while (char_count--) { |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 632 | data = base_addr[CyRDR]; |
| 633 | tty_insert_flip_char(tty, data, TTY_NORMAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | #ifdef CYCLOM_16Y_HACK |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 635 | udelay(10L); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | #endif |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 637 | } |
| 638 | tty_schedule_flip(tty); |
| 639 | } |
| 640 | /* end of service */ |
| 641 | base_addr[CyREOIR] = save_cnt ? 0 : CyNOTRANS; |
| 642 | return IRQ_HANDLED; |
| 643 | } /* cy_rx_interrupt */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | /* This is called whenever a port becomes active; |
| 646 | interrupts are enabled and DTR & RTS are turned on. |
| 647 | */ |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 648 | static int startup(struct cyclades_port *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | { |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 650 | unsigned long flags; |
| 651 | volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR; |
| 652 | int channel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 654 | if (info->flags & ASYNC_INITIALIZED) { |
| 655 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | } |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 657 | |
| 658 | if (!info->type) { |
| 659 | if (info->tty) { |
| 660 | set_bit(TTY_IO_ERROR, &info->tty->flags); |
| 661 | } |
| 662 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | } |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 664 | if (!info->xmit_buf) { |
| 665 | info->xmit_buf = (unsigned char *)get_zeroed_page(GFP_KERNEL); |
| 666 | if (!info->xmit_buf) { |
| 667 | return -ENOMEM; |
| 668 | } |
| 669 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 671 | config_setup(info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 673 | channel = info->line; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | |
| 675 | #ifdef SERIAL_DEBUG_OPEN |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 676 | printk("startup channel %d\n", channel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | #endif |
| 678 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 679 | local_irq_save(flags); |
| 680 | base_addr[CyCAR] = (u_char) channel; |
| 681 | write_cy_cmd(base_addr, CyENB_RCVR | CyENB_XMTR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 683 | base_addr[CyCAR] = (u_char) channel; /* !!! Is this needed? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | base_addr[CyMSVR1] = CyRTS; |
| 685 | /* CP('S');CP('1'); */ |
| 686 | base_addr[CyMSVR2] = CyDTR; |
| 687 | |
| 688 | #ifdef SERIAL_DEBUG_DTR |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 689 | printk("cyc: %d: raising DTR\n", __LINE__); |
| 690 | printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], |
| 691 | base_addr[CyMSVR2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | #endif |
| 693 | |
| 694 | base_addr[CyIER] |= CyRxData; |
| 695 | info->flags |= ASYNC_INITIALIZED; |
| 696 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 697 | if (info->tty) { |
| 698 | clear_bit(TTY_IO_ERROR, &info->tty->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | } |
| 700 | info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; |
| 701 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 702 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | |
| 704 | #ifdef SERIAL_DEBUG_OPEN |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 705 | printk(" done\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | #endif |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 707 | return 0; |
| 708 | } /* startup */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 710 | void start_xmit(struct cyclades_port *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | { |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 712 | unsigned long flags; |
| 713 | volatile unsigned char *base_addr = (u_char *) BASE_ADDR; |
| 714 | int channel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 716 | channel = info->line; |
| 717 | local_irq_save(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | base_addr[CyCAR] = channel; |
| 719 | base_addr[CyIER] |= CyTxMpty; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 720 | local_irq_restore(flags); |
| 721 | } /* start_xmit */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | |
| 723 | /* |
| 724 | * This routine shuts down a serial port; interrupts are disabled, |
| 725 | * and DTR is dropped if the hangup on close termio flag is on. |
| 726 | */ |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 727 | static void shutdown(struct cyclades_port *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | { |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 729 | unsigned long flags; |
| 730 | volatile unsigned char *base_addr = (u_char *) BASE_ADDR; |
| 731 | int channel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 733 | if (!(info->flags & ASYNC_INITIALIZED)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | /* CP('$'); */ |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 735 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | } |
| 737 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 738 | channel = info->line; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 740 | #ifdef SERIAL_DEBUG_OPEN |
| 741 | printk("shutdown channel %d\n", channel); |
| 742 | #endif |
| 743 | |
| 744 | /* !!! REALLY MUST WAIT FOR LAST CHARACTER TO BE |
| 745 | SENT BEFORE DROPPING THE LINE !!! (Perhaps |
| 746 | set some flag that is read when XMTY happens.) |
| 747 | Other choices are to delay some fixed interval |
| 748 | or schedule some later processing. |
| 749 | */ |
| 750 | local_irq_save(flags); |
| 751 | if (info->xmit_buf) { |
| 752 | free_page((unsigned long)info->xmit_buf); |
| 753 | info->xmit_buf = NULL; |
| 754 | } |
| 755 | |
| 756 | base_addr[CyCAR] = (u_char) channel; |
| 757 | if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) { |
| 758 | base_addr[CyMSVR1] = 0; |
| 759 | /* CP('C');CP('1'); */ |
| 760 | base_addr[CyMSVR2] = 0; |
| 761 | #ifdef SERIAL_DEBUG_DTR |
| 762 | printk("cyc: %d: dropping DTR\n", __LINE__); |
| 763 | printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], |
| 764 | base_addr[CyMSVR2]); |
| 765 | #endif |
| 766 | } |
| 767 | write_cy_cmd(base_addr, CyDIS_RCVR); |
| 768 | /* it may be appropriate to clear _XMIT at |
| 769 | some later date (after testing)!!! */ |
| 770 | |
| 771 | if (info->tty) { |
| 772 | set_bit(TTY_IO_ERROR, &info->tty->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | } |
| 774 | info->flags &= ~ASYNC_INITIALIZED; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 775 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | |
| 777 | #ifdef SERIAL_DEBUG_OPEN |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 778 | printk(" done\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | #endif |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 780 | } /* shutdown */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | |
| 782 | /* |
| 783 | * This routine finds or computes the various line characteristics. |
| 784 | */ |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 785 | static void config_setup(struct cyclades_port *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | { |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 787 | unsigned long flags; |
| 788 | volatile unsigned char *base_addr = (u_char *) BASE_ADDR; |
| 789 | int channel; |
| 790 | unsigned cflag; |
| 791 | int i; |
| 792 | unsigned char ti, need_init_chan = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 794 | if (!info->tty || !info->tty->termios) { |
| 795 | return; |
| 796 | } |
| 797 | if (info->line == -1) { |
| 798 | return; |
| 799 | } |
| 800 | cflag = info->tty->termios->c_cflag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 802 | /* baud rate */ |
| 803 | i = cflag & CBAUD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | #ifdef CBAUDEX |
| 805 | /* Starting with kernel 1.1.65, there is direct support for |
| 806 | higher baud rates. The following code supports those |
| 807 | changes. The conditional aspect allows this driver to be |
| 808 | used for earlier as well as later kernel versions. (The |
| 809 | mapping is slightly different from serial.c because there |
| 810 | is still the possibility of supporting 75 kbit/sec with |
| 811 | the Cyclades board.) |
| 812 | */ |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 813 | if (i & CBAUDEX) { |
| 814 | if (i == B57600) |
| 815 | i = 16; |
| 816 | else if (i == B115200) |
| 817 | i = 18; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | #ifdef B78600 |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 819 | else if (i == B78600) |
| 820 | i = 17; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | #endif |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 822 | else |
| 823 | info->tty->termios->c_cflag &= ~CBAUDEX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | #endif |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 826 | if (i == 15) { |
| 827 | if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI) |
| 828 | i += 1; |
| 829 | if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI) |
| 830 | i += 3; |
| 831 | } |
| 832 | /* Don't ever change the speed of the console port. It will |
| 833 | * run at the speed specified in bootinfo, or at 19.2K */ |
| 834 | /* Actually, it should run at whatever speed 166Bug was using */ |
| 835 | /* Note info->timeout isn't used at present */ |
| 836 | if (info != serial_console_info) { |
| 837 | info->tbpr = baud_bpr[i]; /* Tx BPR */ |
| 838 | info->tco = baud_co[i]; /* Tx CO */ |
| 839 | info->rbpr = baud_bpr[i]; /* Rx BPR */ |
| 840 | info->rco = baud_co[i] >> 5; /* Rx CO */ |
| 841 | if (baud_table[i] == 134) { |
| 842 | info->timeout = |
| 843 | (info->xmit_fifo_size * HZ * 30 / 269) + 2; |
| 844 | /* get it right for 134.5 baud */ |
| 845 | } else if (baud_table[i]) { |
| 846 | info->timeout = |
| 847 | (info->xmit_fifo_size * HZ * 15 / baud_table[i]) + |
| 848 | 2; |
| 849 | /* this needs to be propagated into the card info */ |
| 850 | } else { |
| 851 | info->timeout = 0; |
| 852 | } |
| 853 | } |
| 854 | /* By tradition (is it a standard?) a baud rate of zero |
| 855 | implies the line should be/has been closed. A bit |
| 856 | later in this routine such a test is performed. */ |
| 857 | |
| 858 | /* byte size and parity */ |
| 859 | info->cor7 = 0; |
| 860 | info->cor6 = 0; |
| 861 | info->cor5 = 0; |
| 862 | info->cor4 = (info->default_threshold ? info->default_threshold : baud_cor4[i]); /* receive threshold */ |
| 863 | /* Following two lines added 101295, RGH. */ |
| 864 | /* It is obviously wrong to access CyCORx, and not info->corx here, |
| 865 | * try and remember to fix it later! */ |
| 866 | channel = info->line; |
| 867 | base_addr[CyCAR] = (u_char) channel; |
| 868 | if (C_CLOCAL(info->tty)) { |
| 869 | if (base_addr[CyIER] & CyMdmCh) |
| 870 | base_addr[CyIER] &= ~CyMdmCh; /* without modem intr */ |
| 871 | /* ignore 1->0 modem transitions */ |
| 872 | if (base_addr[CyCOR4] & (CyDSR | CyCTS | CyDCD)) |
| 873 | base_addr[CyCOR4] &= ~(CyDSR | CyCTS | CyDCD); |
| 874 | /* ignore 0->1 modem transitions */ |
| 875 | if (base_addr[CyCOR5] & (CyDSR | CyCTS | CyDCD)) |
| 876 | base_addr[CyCOR5] &= ~(CyDSR | CyCTS | CyDCD); |
| 877 | } else { |
| 878 | if ((base_addr[CyIER] & CyMdmCh) != CyMdmCh) |
| 879 | base_addr[CyIER] |= CyMdmCh; /* with modem intr */ |
| 880 | /* act on 1->0 modem transitions */ |
| 881 | if ((base_addr[CyCOR4] & (CyDSR | CyCTS | CyDCD)) != |
| 882 | (CyDSR | CyCTS | CyDCD)) |
| 883 | base_addr[CyCOR4] |= CyDSR | CyCTS | CyDCD; |
| 884 | /* act on 0->1 modem transitions */ |
| 885 | if ((base_addr[CyCOR5] & (CyDSR | CyCTS | CyDCD)) != |
| 886 | (CyDSR | CyCTS | CyDCD)) |
| 887 | base_addr[CyCOR5] |= CyDSR | CyCTS | CyDCD; |
| 888 | } |
| 889 | info->cor3 = (cflag & CSTOPB) ? Cy_2_STOP : Cy_1_STOP; |
| 890 | info->cor2 = CyETC; |
| 891 | switch (cflag & CSIZE) { |
| 892 | case CS5: |
| 893 | info->cor1 = Cy_5_BITS; |
| 894 | break; |
| 895 | case CS6: |
| 896 | info->cor1 = Cy_6_BITS; |
| 897 | break; |
| 898 | case CS7: |
| 899 | info->cor1 = Cy_7_BITS; |
| 900 | break; |
| 901 | case CS8: |
| 902 | info->cor1 = Cy_8_BITS; |
| 903 | break; |
| 904 | } |
| 905 | if (cflag & PARENB) { |
| 906 | if (cflag & PARODD) { |
| 907 | info->cor1 |= CyPARITY_O; |
| 908 | } else { |
| 909 | info->cor1 |= CyPARITY_E; |
| 910 | } |
| 911 | } else { |
| 912 | info->cor1 |= CyPARITY_NONE; |
| 913 | } |
| 914 | |
| 915 | /* CTS flow control flag */ |
| 916 | #if 0 |
| 917 | /* Don't complcate matters for now! RGH 141095 */ |
| 918 | if (cflag & CRTSCTS) { |
| 919 | info->flags |= ASYNC_CTS_FLOW; |
| 920 | info->cor2 |= CyCtsAE; |
| 921 | } else { |
| 922 | info->flags &= ~ASYNC_CTS_FLOW; |
| 923 | info->cor2 &= ~CyCtsAE; |
| 924 | } |
| 925 | #endif |
| 926 | if (cflag & CLOCAL) |
| 927 | info->flags &= ~ASYNC_CHECK_CD; |
| 928 | else |
| 929 | info->flags |= ASYNC_CHECK_CD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | |
| 931 | /*********************************************** |
| 932 | The hardware option, CyRtsAO, presents RTS when |
| 933 | the chip has characters to send. Since most modems |
| 934 | use RTS as reverse (inbound) flow control, this |
| 935 | option is not used. If inbound flow control is |
| 936 | necessary, DTR can be programmed to provide the |
| 937 | appropriate signals for use with a non-standard |
| 938 | cable. Contact Marcio Saito for details. |
| 939 | ***********************************************/ |
| 940 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 941 | channel = info->line; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 943 | local_irq_save(flags); |
| 944 | base_addr[CyCAR] = (u_char) channel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | |
| 946 | /* CyCMR set once only in mvme167_init_serial() */ |
| 947 | if (base_addr[CyLICR] != channel << 2) |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 948 | base_addr[CyLICR] = channel << 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | if (base_addr[CyLIVR] != 0x5c) |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 950 | base_addr[CyLIVR] = 0x5c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 952 | /* tx and rx baud rate */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | |
| 954 | if (base_addr[CyCOR1] != info->cor1) |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 955 | need_init_chan = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | if (base_addr[CyTCOR] != info->tco) |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 957 | base_addr[CyTCOR] = info->tco; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | if (base_addr[CyTBPR] != info->tbpr) |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 959 | base_addr[CyTBPR] = info->tbpr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | if (base_addr[CyRCOR] != info->rco) |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 961 | base_addr[CyRCOR] = info->rco; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | if (base_addr[CyRBPR] != info->rbpr) |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 963 | base_addr[CyRBPR] = info->rbpr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | |
| 965 | /* set line characteristics according configuration */ |
| 966 | |
| 967 | if (base_addr[CySCHR1] != START_CHAR(info->tty)) |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 968 | base_addr[CySCHR1] = START_CHAR(info->tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | if (base_addr[CySCHR2] != STOP_CHAR(info->tty)) |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 970 | base_addr[CySCHR2] = STOP_CHAR(info->tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | if (base_addr[CySCRL] != START_CHAR(info->tty)) |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 972 | base_addr[CySCRL] = START_CHAR(info->tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | if (base_addr[CySCRH] != START_CHAR(info->tty)) |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 974 | base_addr[CySCRH] = START_CHAR(info->tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | if (base_addr[CyCOR1] != info->cor1) |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 976 | base_addr[CyCOR1] = info->cor1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | if (base_addr[CyCOR2] != info->cor2) |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 978 | base_addr[CyCOR2] = info->cor2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | if (base_addr[CyCOR3] != info->cor3) |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 980 | base_addr[CyCOR3] = info->cor3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | if (base_addr[CyCOR4] != info->cor4) |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 982 | base_addr[CyCOR4] = info->cor4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | if (base_addr[CyCOR5] != info->cor5) |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 984 | base_addr[CyCOR5] = info->cor5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | if (base_addr[CyCOR6] != info->cor6) |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 986 | base_addr[CyCOR6] = info->cor6; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | if (base_addr[CyCOR7] != info->cor7) |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 988 | base_addr[CyCOR7] = info->cor7; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | |
| 990 | if (need_init_chan) |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 991 | write_cy_cmd(base_addr, CyINIT_CHAN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 993 | base_addr[CyCAR] = (u_char) channel; /* !!! Is this needed? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | |
| 995 | /* 2ms default rx timeout */ |
| 996 | ti = info->default_timeout ? info->default_timeout : 0x02; |
| 997 | if (base_addr[CyRTPRL] != ti) |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 998 | base_addr[CyRTPRL] = ti; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | if (base_addr[CyRTPRH] != 0) |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1000 | base_addr[CyRTPRH] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | |
| 1002 | /* Set up RTS here also ????? RGH 141095 */ |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1003 | if (i == 0) { /* baud rate is zero, turn off line */ |
| 1004 | if ((base_addr[CyMSVR2] & CyDTR) == CyDTR) |
| 1005 | base_addr[CyMSVR2] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | #ifdef SERIAL_DEBUG_DTR |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1007 | printk("cyc: %d: dropping DTR\n", __LINE__); |
| 1008 | printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], |
| 1009 | base_addr[CyMSVR2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | #endif |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1011 | } else { |
| 1012 | if ((base_addr[CyMSVR2] & CyDTR) != CyDTR) |
| 1013 | base_addr[CyMSVR2] = CyDTR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | #ifdef SERIAL_DEBUG_DTR |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1015 | printk("cyc: %d: raising DTR\n", __LINE__); |
| 1016 | printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], |
| 1017 | base_addr[CyMSVR2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | #endif |
| 1019 | } |
| 1020 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1021 | if (info->tty) { |
| 1022 | clear_bit(TTY_IO_ERROR, &info->tty->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | } |
| 1024 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1025 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1027 | } /* config_setup */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | |
Alan Cox | a5b08c6 | 2008-04-30 00:54:05 -0700 | [diff] [blame] | 1029 | static int cy_put_char(struct tty_struct *tty, unsigned char ch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1031 | struct cyclades_port *info = tty->driver_data; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1032 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | |
| 1034 | #ifdef SERIAL_DEBUG_IO |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1035 | printk("cy_put_char %s(0x%02x)\n", tty->name, ch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | #endif |
| 1037 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1038 | if (serial_paranoia_check(info, tty->name, "cy_put_char")) |
Alan Cox | a5b08c6 | 2008-04-30 00:54:05 -0700 | [diff] [blame] | 1039 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1041 | if (!info->xmit_buf) |
Geert Uytterhoeven | 63a59fa | 2008-05-05 21:15:48 +0200 | [diff] [blame] | 1042 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1044 | local_irq_save(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | if (info->xmit_cnt >= PAGE_SIZE - 1) { |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1046 | local_irq_restore(flags); |
Alan Cox | a5b08c6 | 2008-04-30 00:54:05 -0700 | [diff] [blame] | 1047 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | } |
| 1049 | |
| 1050 | info->xmit_buf[info->xmit_head++] = ch; |
| 1051 | info->xmit_head &= PAGE_SIZE - 1; |
| 1052 | info->xmit_cnt++; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1053 | local_irq_restore(flags); |
Alan Cox | a5b08c6 | 2008-04-30 00:54:05 -0700 | [diff] [blame] | 1054 | return 1; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1055 | } /* cy_put_char */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1057 | static void cy_flush_chars(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1059 | struct cyclades_port *info = tty->driver_data; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1060 | unsigned long flags; |
| 1061 | volatile unsigned char *base_addr = (u_char *) BASE_ADDR; |
| 1062 | int channel; |
| 1063 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | #ifdef SERIAL_DEBUG_IO |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1065 | printk("cy_flush_chars %s\n", tty->name); /* */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | #endif |
| 1067 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1068 | if (serial_paranoia_check(info, tty->name, "cy_flush_chars")) |
| 1069 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1071 | if (info->xmit_cnt <= 0 || tty->stopped |
| 1072 | || tty->hw_stopped || !info->xmit_buf) |
| 1073 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1075 | channel = info->line; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1077 | local_irq_save(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | base_addr[CyCAR] = channel; |
| 1079 | base_addr[CyIER] |= CyTxMpty; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1080 | local_irq_restore(flags); |
| 1081 | } /* cy_flush_chars */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | |
| 1083 | /* This routine gets called when tty_write has put something into |
| 1084 | the write_queue. If the port is not already transmitting stuff, |
| 1085 | start it off by enabling interrupts. The interrupt service |
| 1086 | routine will then ensure that the characters are sent. If the |
| 1087 | port is already active, there is no need to kick it. |
| 1088 | */ |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1089 | static int cy_write(struct tty_struct *tty, const unsigned char *buf, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1091 | struct cyclades_port *info = tty->driver_data; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1092 | unsigned long flags; |
| 1093 | int c, total = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | |
| 1095 | #ifdef SERIAL_DEBUG_IO |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1096 | printk("cy_write %s\n", tty->name); /* */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | #endif |
| 1098 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1099 | if (serial_paranoia_check(info, tty->name, "cy_write")) { |
| 1100 | return 0; |
| 1101 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1103 | if (!info->xmit_buf) { |
| 1104 | return 0; |
| 1105 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1107 | while (1) { |
| 1108 | local_irq_save(flags); |
| 1109 | c = min_t(int, count, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1, |
| 1110 | SERIAL_XMIT_SIZE - info->xmit_head)); |
| 1111 | if (c <= 0) { |
| 1112 | local_irq_restore(flags); |
| 1113 | break; |
| 1114 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1116 | memcpy(info->xmit_buf + info->xmit_head, buf, c); |
| 1117 | info->xmit_head = |
| 1118 | (info->xmit_head + c) & (SERIAL_XMIT_SIZE - 1); |
| 1119 | info->xmit_cnt += c; |
| 1120 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1122 | buf += c; |
| 1123 | count -= c; |
| 1124 | total += c; |
| 1125 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1127 | if (info->xmit_cnt && !tty->stopped && !tty->hw_stopped) { |
| 1128 | start_xmit(info); |
| 1129 | } |
| 1130 | return total; |
| 1131 | } /* cy_write */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1133 | static int cy_write_room(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1135 | struct cyclades_port *info = tty->driver_data; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1136 | int ret; |
| 1137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | #ifdef SERIAL_DEBUG_IO |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1139 | printk("cy_write_room %s\n", tty->name); /* */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | #endif |
| 1141 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1142 | if (serial_paranoia_check(info, tty->name, "cy_write_room")) |
| 1143 | return 0; |
| 1144 | ret = PAGE_SIZE - info->xmit_cnt - 1; |
| 1145 | if (ret < 0) |
| 1146 | ret = 0; |
| 1147 | return ret; |
| 1148 | } /* cy_write_room */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1150 | static int cy_chars_in_buffer(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1152 | struct cyclades_port *info = tty->driver_data; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1153 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | #ifdef SERIAL_DEBUG_IO |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1155 | printk("cy_chars_in_buffer %s %d\n", tty->name, info->xmit_cnt); /* */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | #endif |
| 1157 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1158 | if (serial_paranoia_check(info, tty->name, "cy_chars_in_buffer")) |
| 1159 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1161 | return info->xmit_cnt; |
| 1162 | } /* cy_chars_in_buffer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1163 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1164 | static void cy_flush_buffer(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1166 | struct cyclades_port *info = tty->driver_data; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1167 | unsigned long flags; |
| 1168 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | #ifdef SERIAL_DEBUG_IO |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1170 | printk("cy_flush_buffer %s\n", tty->name); /* */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | #endif |
| 1172 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1173 | if (serial_paranoia_check(info, tty->name, "cy_flush_buffer")) |
| 1174 | return; |
| 1175 | local_irq_save(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1177 | local_irq_restore(flags); |
| 1178 | tty_wakeup(tty); |
| 1179 | } /* cy_flush_buffer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | |
| 1181 | /* This routine is called by the upper-layer tty layer to signal |
| 1182 | that incoming characters should be throttled or that the |
| 1183 | throttle should be released. |
| 1184 | */ |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1185 | static void cy_throttle(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1187 | struct cyclades_port *info = tty->driver_data; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1188 | unsigned long flags; |
| 1189 | volatile unsigned char *base_addr = (u_char *) BASE_ADDR; |
| 1190 | int channel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | |
| 1192 | #ifdef SERIAL_DEBUG_THROTTLE |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1193 | char buf[64]; |
| 1194 | |
| 1195 | printk("throttle %s: %d....\n", tty_name(tty, buf), |
| 1196 | tty->ldisc.chars_in_buffer(tty)); |
| 1197 | printk("cy_throttle %s\n", tty->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | #endif |
| 1199 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1200 | if (serial_paranoia_check(info, tty->name, "cy_nthrottle")) { |
| 1201 | return; |
| 1202 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1204 | if (I_IXOFF(tty)) { |
| 1205 | info->x_char = STOP_CHAR(tty); |
| 1206 | /* Should use the "Send Special Character" feature!!! */ |
| 1207 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1209 | channel = info->line; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1211 | local_irq_save(flags); |
| 1212 | base_addr[CyCAR] = (u_char) channel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | base_addr[CyMSVR1] = 0; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1214 | local_irq_restore(flags); |
| 1215 | } /* cy_throttle */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1217 | static void cy_unthrottle(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1219 | struct cyclades_port *info = tty->driver_data; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1220 | unsigned long flags; |
| 1221 | volatile unsigned char *base_addr = (u_char *) BASE_ADDR; |
| 1222 | int channel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | |
| 1224 | #ifdef SERIAL_DEBUG_THROTTLE |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1225 | char buf[64]; |
| 1226 | |
| 1227 | printk("throttle %s: %d....\n", tty_name(tty, buf), |
| 1228 | tty->ldisc.chars_in_buffer(tty)); |
| 1229 | printk("cy_unthrottle %s\n", tty->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | #endif |
| 1231 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1232 | if (serial_paranoia_check(info, tty->name, "cy_nthrottle")) { |
| 1233 | return; |
| 1234 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1236 | if (I_IXOFF(tty)) { |
| 1237 | info->x_char = START_CHAR(tty); |
| 1238 | /* Should use the "Send Special Character" feature!!! */ |
| 1239 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1241 | channel = info->line; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1243 | local_irq_save(flags); |
| 1244 | base_addr[CyCAR] = (u_char) channel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | base_addr[CyMSVR1] = CyRTS; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1246 | local_irq_restore(flags); |
| 1247 | } /* cy_unthrottle */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | |
| 1249 | static int |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1250 | get_serial_info(struct cyclades_port *info, |
| 1251 | struct serial_struct __user * retinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | { |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1253 | struct serial_struct tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | |
| 1255 | /* CP('g'); */ |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1256 | if (!retinfo) |
| 1257 | return -EFAULT; |
| 1258 | memset(&tmp, 0, sizeof(tmp)); |
| 1259 | tmp.type = info->type; |
| 1260 | tmp.line = info->line; |
| 1261 | tmp.port = info->line; |
| 1262 | tmp.irq = 0; |
| 1263 | tmp.flags = info->flags; |
| 1264 | tmp.baud_base = 0; /*!!! */ |
| 1265 | tmp.close_delay = info->close_delay; |
| 1266 | tmp.custom_divisor = 0; /*!!! */ |
| 1267 | tmp.hub6 = 0; /*!!! */ |
| 1268 | return copy_to_user(retinfo, &tmp, sizeof(*retinfo)) ? -EFAULT : 0; |
| 1269 | } /* get_serial_info */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | |
| 1271 | static int |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1272 | set_serial_info(struct cyclades_port *info, |
| 1273 | struct serial_struct __user * new_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | { |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1275 | struct serial_struct new_serial; |
| 1276 | struct cyclades_port old_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | |
| 1278 | /* CP('s'); */ |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1279 | if (!new_info) |
| 1280 | return -EFAULT; |
| 1281 | if (copy_from_user(&new_serial, new_info, sizeof(new_serial))) |
| 1282 | return -EFAULT; |
| 1283 | old_info = *info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1285 | if (!capable(CAP_SYS_ADMIN)) { |
| 1286 | if ((new_serial.close_delay != info->close_delay) || |
| 1287 | ((new_serial.flags & ASYNC_FLAGS & ~ASYNC_USR_MASK) != |
| 1288 | (info->flags & ASYNC_FLAGS & ~ASYNC_USR_MASK))) |
| 1289 | return -EPERM; |
| 1290 | info->flags = ((info->flags & ~ASYNC_USR_MASK) | |
| 1291 | (new_serial.flags & ASYNC_USR_MASK)); |
| 1292 | goto check_and_exit; |
| 1293 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1294 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1295 | /* |
| 1296 | * OK, past this point, all the error checking has been done. |
| 1297 | * At this point, we start making changes..... |
| 1298 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1300 | info->flags = ((info->flags & ~ASYNC_FLAGS) | |
| 1301 | (new_serial.flags & ASYNC_FLAGS)); |
| 1302 | info->close_delay = new_serial.close_delay; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | |
| 1304 | check_and_exit: |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1305 | if (info->flags & ASYNC_INITIALIZED) { |
| 1306 | config_setup(info); |
| 1307 | return 0; |
| 1308 | } |
| 1309 | return startup(info); |
| 1310 | } /* set_serial_info */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1312 | static int cy_tiocmget(struct tty_struct *tty, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1314 | struct cyclades_port *info = tty->driver_data; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1315 | int channel; |
| 1316 | volatile unsigned char *base_addr = (u_char *) BASE_ADDR; |
| 1317 | unsigned long flags; |
| 1318 | unsigned char status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1320 | channel = info->line; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1322 | local_irq_save(flags); |
| 1323 | base_addr[CyCAR] = (u_char) channel; |
| 1324 | status = base_addr[CyMSVR1] | base_addr[CyMSVR2]; |
| 1325 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1327 | return ((status & CyRTS) ? TIOCM_RTS : 0) |
| 1328 | | ((status & CyDTR) ? TIOCM_DTR : 0) |
| 1329 | | ((status & CyDCD) ? TIOCM_CAR : 0) |
| 1330 | | ((status & CyDSR) ? TIOCM_DSR : 0) |
| 1331 | | ((status & CyCTS) ? TIOCM_CTS : 0); |
| 1332 | } /* cy_tiocmget */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | |
| 1334 | static int |
| 1335 | cy_tiocmset(struct tty_struct *tty, struct file *file, |
| 1336 | unsigned int set, unsigned int clear) |
| 1337 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1338 | struct cyclades_port *info = tty->driver_data; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1339 | int channel; |
| 1340 | volatile unsigned char *base_addr = (u_char *) BASE_ADDR; |
| 1341 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1343 | channel = info->line; |
| 1344 | |
| 1345 | if (set & TIOCM_RTS) { |
| 1346 | local_irq_save(flags); |
| 1347 | base_addr[CyCAR] = (u_char) channel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | base_addr[CyMSVR1] = CyRTS; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1349 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | } |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1351 | if (set & TIOCM_DTR) { |
| 1352 | local_irq_save(flags); |
| 1353 | base_addr[CyCAR] = (u_char) channel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | /* CP('S');CP('2'); */ |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1355 | base_addr[CyMSVR2] = CyDTR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | #ifdef SERIAL_DEBUG_DTR |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1357 | printk("cyc: %d: raising DTR\n", __LINE__); |
| 1358 | printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], |
| 1359 | base_addr[CyMSVR2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | #endif |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1361 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | } |
| 1363 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1364 | if (clear & TIOCM_RTS) { |
| 1365 | local_irq_save(flags); |
| 1366 | base_addr[CyCAR] = (u_char) channel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | base_addr[CyMSVR1] = 0; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1368 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | } |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1370 | if (clear & TIOCM_DTR) { |
| 1371 | local_irq_save(flags); |
| 1372 | base_addr[CyCAR] = (u_char) channel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | /* CP('C');CP('2'); */ |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1374 | base_addr[CyMSVR2] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1375 | #ifdef SERIAL_DEBUG_DTR |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1376 | printk("cyc: %d: dropping DTR\n", __LINE__); |
| 1377 | printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], |
| 1378 | base_addr[CyMSVR2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | #endif |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1380 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | } |
| 1382 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1383 | return 0; |
| 1384 | } /* set_modem_info */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1386 | static void send_break(struct cyclades_port *info, int duration) |
| 1387 | { /* Let the transmit ISR take care of this (since it |
| 1388 | requires stuffing characters into the output stream). |
| 1389 | */ |
| 1390 | info->x_break = duration; |
| 1391 | if (!info->xmit_cnt) { |
| 1392 | start_xmit(info); |
| 1393 | } |
| 1394 | } /* send_break */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | |
| 1396 | static int |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1397 | get_mon_info(struct cyclades_port *info, struct cyclades_monitor __user * mon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | { |
| 1399 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1400 | if (copy_to_user(mon, &info->mon, sizeof(struct cyclades_monitor))) |
| 1401 | return -EFAULT; |
| 1402 | info->mon.int_count = 0; |
| 1403 | info->mon.char_count = 0; |
| 1404 | info->mon.char_max = 0; |
| 1405 | info->mon.char_last = 0; |
| 1406 | return 0; |
| 1407 | } |
| 1408 | |
| 1409 | static int set_threshold(struct cyclades_port *info, unsigned long __user * arg) |
| 1410 | { |
| 1411 | volatile unsigned char *base_addr = (u_char *) BASE_ADDR; |
| 1412 | unsigned long value; |
| 1413 | int channel; |
| 1414 | |
| 1415 | if (get_user(value, arg)) |
| 1416 | return -EFAULT; |
| 1417 | |
| 1418 | channel = info->line; |
| 1419 | info->cor4 &= ~CyREC_FIFO; |
| 1420 | info->cor4 |= value & CyREC_FIFO; |
| 1421 | base_addr[CyCOR4] = info->cor4; |
| 1422 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1423 | } |
| 1424 | |
| 1425 | static int |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1426 | get_threshold(struct cyclades_port *info, unsigned long __user * value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1427 | { |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1428 | volatile unsigned char *base_addr = (u_char *) BASE_ADDR; |
| 1429 | int channel; |
| 1430 | unsigned long tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1432 | channel = info->line; |
| 1433 | |
| 1434 | tmp = base_addr[CyCOR4] & CyREC_FIFO; |
| 1435 | return put_user(tmp, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | } |
| 1437 | |
| 1438 | static int |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1439 | set_default_threshold(struct cyclades_port *info, unsigned long __user * arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | { |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1441 | unsigned long value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1443 | if (get_user(value, arg)) |
| 1444 | return -EFAULT; |
| 1445 | |
| 1446 | info->default_threshold = value & 0x0f; |
| 1447 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | } |
| 1449 | |
| 1450 | static int |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1451 | get_default_threshold(struct cyclades_port *info, unsigned long __user * value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | { |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1453 | return put_user(info->default_threshold, value); |
| 1454 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1455 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1456 | static int set_timeout(struct cyclades_port *info, unsigned long __user * arg) |
| 1457 | { |
| 1458 | volatile unsigned char *base_addr = (u_char *) BASE_ADDR; |
| 1459 | int channel; |
| 1460 | unsigned long value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1462 | if (get_user(value, arg)) |
| 1463 | return -EFAULT; |
| 1464 | |
| 1465 | channel = info->line; |
| 1466 | |
| 1467 | base_addr[CyRTPRL] = value & 0xff; |
| 1468 | base_addr[CyRTPRH] = (value >> 8) & 0xff; |
| 1469 | return 0; |
| 1470 | } |
| 1471 | |
| 1472 | static int get_timeout(struct cyclades_port *info, unsigned long __user * value) |
| 1473 | { |
| 1474 | volatile unsigned char *base_addr = (u_char *) BASE_ADDR; |
| 1475 | int channel; |
| 1476 | unsigned long tmp; |
| 1477 | |
| 1478 | channel = info->line; |
| 1479 | |
| 1480 | tmp = base_addr[CyRTPRL]; |
| 1481 | return put_user(tmp, value); |
| 1482 | } |
| 1483 | |
| 1484 | static int set_default_timeout(struct cyclades_port *info, unsigned long value) |
| 1485 | { |
| 1486 | info->default_timeout = value & 0xff; |
| 1487 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | } |
| 1489 | |
| 1490 | static int |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1491 | get_default_timeout(struct cyclades_port *info, unsigned long __user * value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | { |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1493 | return put_user(info->default_timeout, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1494 | } |
| 1495 | |
| 1496 | static int |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1497 | cy_ioctl(struct tty_struct *tty, struct file *file, |
| 1498 | unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1499 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1500 | struct cyclades_port *info = tty->driver_data; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1501 | int ret_val = 0; |
| 1502 | void __user *argp = (void __user *)arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 | |
| 1504 | #ifdef SERIAL_DEBUG_OTHER |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1505 | printk("cy_ioctl %s, cmd = %x arg = %lx\n", tty->name, cmd, arg); /* */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1506 | #endif |
| 1507 | |
Arnd Bergmann | ec79d60 | 2010-06-01 22:53:01 +0200 | [diff] [blame] | 1508 | tty_lock(); |
Alan Cox | 638157b | 2008-04-30 00:53:22 -0700 | [diff] [blame] | 1509 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1510 | switch (cmd) { |
| 1511 | case CYGETMON: |
| 1512 | ret_val = get_mon_info(info, argp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | break; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1514 | case CYGETTHRESH: |
| 1515 | ret_val = get_threshold(info, argp); |
| 1516 | break; |
| 1517 | case CYSETTHRESH: |
| 1518 | ret_val = set_threshold(info, argp); |
| 1519 | break; |
| 1520 | case CYGETDEFTHRESH: |
| 1521 | ret_val = get_default_threshold(info, argp); |
| 1522 | break; |
| 1523 | case CYSETDEFTHRESH: |
| 1524 | ret_val = set_default_threshold(info, argp); |
| 1525 | break; |
| 1526 | case CYGETTIMEOUT: |
| 1527 | ret_val = get_timeout(info, argp); |
| 1528 | break; |
| 1529 | case CYSETTIMEOUT: |
| 1530 | ret_val = set_timeout(info, argp); |
| 1531 | break; |
| 1532 | case CYGETDEFTIMEOUT: |
| 1533 | ret_val = get_default_timeout(info, argp); |
| 1534 | break; |
| 1535 | case CYSETDEFTIMEOUT: |
| 1536 | ret_val = set_default_timeout(info, (unsigned long)arg); |
| 1537 | break; |
| 1538 | case TCSBRK: /* SVID version: non-zero arg --> no break */ |
| 1539 | ret_val = tty_check_change(tty); |
| 1540 | if (ret_val) |
| 1541 | break; |
| 1542 | tty_wait_until_sent(tty, 0); |
| 1543 | if (!arg) |
| 1544 | send_break(info, HZ / 4); /* 1/4 second */ |
| 1545 | break; |
| 1546 | case TCSBRKP: /* support for POSIX tcsendbreak() */ |
| 1547 | ret_val = tty_check_change(tty); |
| 1548 | if (ret_val) |
| 1549 | break; |
| 1550 | tty_wait_until_sent(tty, 0); |
| 1551 | send_break(info, arg ? arg * (HZ / 10) : HZ / 4); |
| 1552 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1553 | |
| 1554 | /* The following commands are incompletely implemented!!! */ |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1555 | case TIOCGSERIAL: |
| 1556 | ret_val = get_serial_info(info, argp); |
| 1557 | break; |
| 1558 | case TIOCSSERIAL: |
| 1559 | ret_val = set_serial_info(info, argp); |
| 1560 | break; |
| 1561 | default: |
| 1562 | ret_val = -ENOIOCTLCMD; |
| 1563 | } |
Arnd Bergmann | ec79d60 | 2010-06-01 22:53:01 +0200 | [diff] [blame] | 1564 | tty_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1565 | |
| 1566 | #ifdef SERIAL_DEBUG_OTHER |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1567 | printk("cy_ioctl done\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1568 | #endif |
| 1569 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1570 | return ret_val; |
| 1571 | } /* cy_ioctl */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1572 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1573 | static void cy_set_termios(struct tty_struct *tty, struct ktermios *old_termios) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1574 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1575 | struct cyclades_port *info = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1576 | |
| 1577 | #ifdef SERIAL_DEBUG_OTHER |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1578 | printk("cy_set_termios %s\n", tty->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | #endif |
| 1580 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1581 | if (tty->termios->c_cflag == old_termios->c_cflag) |
| 1582 | return; |
| 1583 | config_setup(info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1584 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1585 | if ((old_termios->c_cflag & CRTSCTS) && |
| 1586 | !(tty->termios->c_cflag & CRTSCTS)) { |
| 1587 | tty->stopped = 0; |
| 1588 | cy_start(tty); |
| 1589 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1590 | #ifdef tytso_patch_94Nov25_1726 |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1591 | if (!(old_termios->c_cflag & CLOCAL) && |
| 1592 | (tty->termios->c_cflag & CLOCAL)) |
| 1593 | wake_up_interruptible(&info->open_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1594 | #endif |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1595 | } /* cy_set_termios */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1596 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1597 | static void cy_close(struct tty_struct *tty, struct file *filp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1599 | struct cyclades_port *info = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1600 | |
| 1601 | /* CP('C'); */ |
| 1602 | #ifdef SERIAL_DEBUG_OTHER |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1603 | printk("cy_close %s\n", tty->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1604 | #endif |
| 1605 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1606 | if (!info || serial_paranoia_check(info, tty->name, "cy_close")) { |
| 1607 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1608 | } |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1609 | #ifdef SERIAL_DEBUG_OPEN |
| 1610 | printk("cy_close %s, count = %d\n", tty->name, info->count); |
| 1611 | #endif |
| 1612 | |
| 1613 | if ((tty->count == 1) && (info->count != 1)) { |
| 1614 | /* |
| 1615 | * Uh, oh. tty->count is 1, which means that the tty |
| 1616 | * structure will be freed. Info->count should always |
| 1617 | * be one in these conditions. If it's greater than |
| 1618 | * one, we've got real problems, since it means the |
| 1619 | * serial port won't be shutdown. |
| 1620 | */ |
| 1621 | printk("cy_close: bad serial port count; tty->count is 1, " |
| 1622 | "info->count is %d\n", info->count); |
| 1623 | info->count = 1; |
| 1624 | } |
| 1625 | #ifdef SERIAL_DEBUG_COUNT |
| 1626 | printk("cyc: %d: decrementing count to %d\n", __LINE__, |
| 1627 | info->count - 1); |
| 1628 | #endif |
| 1629 | if (--info->count < 0) { |
| 1630 | printk("cy_close: bad serial port count for ttys%d: %d\n", |
| 1631 | info->line, info->count); |
| 1632 | #ifdef SERIAL_DEBUG_COUNT |
| 1633 | printk("cyc: %d: setting count to 0\n", __LINE__); |
| 1634 | #endif |
| 1635 | info->count = 0; |
| 1636 | } |
| 1637 | if (info->count) |
| 1638 | return; |
| 1639 | info->flags |= ASYNC_CLOSING; |
| 1640 | if (info->flags & ASYNC_INITIALIZED) |
| 1641 | tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */ |
| 1642 | shutdown(info); |
Alan Cox | 978e595 | 2008-04-30 00:53:59 -0700 | [diff] [blame] | 1643 | cy_flush_buffer(tty); |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1644 | tty_ldisc_flush(tty); |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1645 | info->tty = NULL; |
| 1646 | if (info->blocked_open) { |
| 1647 | if (info->close_delay) { |
| 1648 | msleep_interruptible(jiffies_to_msecs |
| 1649 | (info->close_delay)); |
| 1650 | } |
| 1651 | wake_up_interruptible(&info->open_wait); |
| 1652 | } |
| 1653 | info->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING); |
| 1654 | wake_up_interruptible(&info->close_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1655 | |
| 1656 | #ifdef SERIAL_DEBUG_OTHER |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1657 | printk("cy_close done\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | #endif |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1659 | } /* cy_close */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1660 | |
| 1661 | /* |
| 1662 | * cy_hangup() --- called by tty_hangup() when a hangup is signaled. |
| 1663 | */ |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1664 | void cy_hangup(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1665 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1666 | struct cyclades_port *info = tty->driver_data; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1667 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1668 | #ifdef SERIAL_DEBUG_OTHER |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1669 | printk("cy_hangup %s\n", tty->name); /* */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1670 | #endif |
| 1671 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1672 | if (serial_paranoia_check(info, tty->name, "cy_hangup")) |
| 1673 | return; |
| 1674 | |
| 1675 | shutdown(info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1676 | #if 0 |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1677 | info->event = 0; |
| 1678 | info->count = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | #ifdef SERIAL_DEBUG_COUNT |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1680 | printk("cyc: %d: setting count to 0\n", __LINE__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1681 | #endif |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1682 | info->tty = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | #endif |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1684 | info->flags &= ~ASYNC_NORMAL_ACTIVE; |
| 1685 | wake_up_interruptible(&info->open_wait); |
| 1686 | } /* cy_hangup */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1687 | |
| 1688 | /* |
| 1689 | * ------------------------------------------------------------ |
| 1690 | * cy_open() and friends |
| 1691 | * ------------------------------------------------------------ |
| 1692 | */ |
| 1693 | |
| 1694 | static int |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1695 | block_til_ready(struct tty_struct *tty, struct file *filp, |
| 1696 | struct cyclades_port *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1697 | { |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1698 | DECLARE_WAITQUEUE(wait, current); |
| 1699 | unsigned long flags; |
| 1700 | int channel; |
| 1701 | int retval; |
| 1702 | volatile u_char *base_addr = (u_char *) BASE_ADDR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1703 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1704 | /* |
| 1705 | * If the device is in the middle of being closed, then block |
| 1706 | * until it's done, and then try again. |
| 1707 | */ |
| 1708 | if (info->flags & ASYNC_CLOSING) { |
| 1709 | interruptible_sleep_on(&info->close_wait); |
| 1710 | if (info->flags & ASYNC_HUP_NOTIFY) { |
| 1711 | return -EAGAIN; |
| 1712 | } else { |
| 1713 | return -ERESTARTSYS; |
| 1714 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1716 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1717 | /* |
| 1718 | * If non-blocking mode is set, then make the check up front |
| 1719 | * and then exit. |
| 1720 | */ |
| 1721 | if (filp->f_flags & O_NONBLOCK) { |
| 1722 | info->flags |= ASYNC_NORMAL_ACTIVE; |
| 1723 | return 0; |
| 1724 | } |
| 1725 | |
| 1726 | /* |
| 1727 | * Block waiting for the carrier detect and the line to become |
| 1728 | * free (i.e., not in use by the callout). While we are in |
| 1729 | * this loop, info->count is dropped by one, so that |
| 1730 | * cy_close() knows when to free things. We restore it upon |
| 1731 | * exit, either normal or abnormal. |
| 1732 | */ |
| 1733 | retval = 0; |
| 1734 | add_wait_queue(&info->open_wait, &wait); |
| 1735 | #ifdef SERIAL_DEBUG_OPEN |
| 1736 | printk("block_til_ready before block: %s, count = %d\n", |
| 1737 | tty->name, info->count); |
| 1738 | /**/ |
| 1739 | #endif |
| 1740 | info->count--; |
| 1741 | #ifdef SERIAL_DEBUG_COUNT |
| 1742 | printk("cyc: %d: decrementing count to %d\n", __LINE__, info->count); |
| 1743 | #endif |
| 1744 | info->blocked_open++; |
| 1745 | |
| 1746 | channel = info->line; |
| 1747 | |
| 1748 | while (1) { |
| 1749 | local_irq_save(flags); |
| 1750 | base_addr[CyCAR] = (u_char) channel; |
| 1751 | base_addr[CyMSVR1] = CyRTS; |
| 1752 | /* CP('S');CP('4'); */ |
| 1753 | base_addr[CyMSVR2] = CyDTR; |
| 1754 | #ifdef SERIAL_DEBUG_DTR |
| 1755 | printk("cyc: %d: raising DTR\n", __LINE__); |
| 1756 | printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], |
| 1757 | base_addr[CyMSVR2]); |
| 1758 | #endif |
| 1759 | local_irq_restore(flags); |
| 1760 | set_current_state(TASK_INTERRUPTIBLE); |
| 1761 | if (tty_hung_up_p(filp) |
| 1762 | || !(info->flags & ASYNC_INITIALIZED)) { |
| 1763 | if (info->flags & ASYNC_HUP_NOTIFY) { |
| 1764 | retval = -EAGAIN; |
| 1765 | } else { |
| 1766 | retval = -ERESTARTSYS; |
| 1767 | } |
| 1768 | break; |
| 1769 | } |
| 1770 | local_irq_save(flags); |
| 1771 | base_addr[CyCAR] = (u_char) channel; |
| 1772 | /* CP('L');CP1(1 && C_CLOCAL(tty)); CP1(1 && (base_addr[CyMSVR1] & CyDCD) ); */ |
| 1773 | if (!(info->flags & ASYNC_CLOSING) |
| 1774 | && (C_CLOCAL(tty) |
| 1775 | || (base_addr[CyMSVR1] & CyDCD))) { |
| 1776 | local_irq_restore(flags); |
| 1777 | break; |
| 1778 | } |
| 1779 | local_irq_restore(flags); |
| 1780 | if (signal_pending(current)) { |
| 1781 | retval = -ERESTARTSYS; |
| 1782 | break; |
| 1783 | } |
| 1784 | #ifdef SERIAL_DEBUG_OPEN |
| 1785 | printk("block_til_ready blocking: %s, count = %d\n", |
| 1786 | tty->name, info->count); |
| 1787 | /**/ |
| 1788 | #endif |
Arnd Bergmann | e142a31 | 2010-06-01 22:53:10 +0200 | [diff] [blame] | 1789 | tty_unlock(); |
| 1790 | schedule(); |
| 1791 | tty_lock(); |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1792 | } |
Milind Arun Choudhary | cc0a8fb | 2007-05-08 00:30:52 -0700 | [diff] [blame] | 1793 | __set_current_state(TASK_RUNNING); |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1794 | remove_wait_queue(&info->open_wait, &wait); |
| 1795 | if (!tty_hung_up_p(filp)) { |
| 1796 | info->count++; |
| 1797 | #ifdef SERIAL_DEBUG_COUNT |
| 1798 | printk("cyc: %d: incrementing count to %d\n", __LINE__, |
| 1799 | info->count); |
| 1800 | #endif |
| 1801 | } |
| 1802 | info->blocked_open--; |
| 1803 | #ifdef SERIAL_DEBUG_OPEN |
| 1804 | printk("block_til_ready after blocking: %s, count = %d\n", |
| 1805 | tty->name, info->count); |
| 1806 | /**/ |
| 1807 | #endif |
| 1808 | if (retval) |
| 1809 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | info->flags |= ASYNC_NORMAL_ACTIVE; |
| 1811 | return 0; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1812 | } /* block_til_ready */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1813 | |
| 1814 | /* |
| 1815 | * This routine is called whenever a serial port is opened. It |
| 1816 | * performs the serial-specific initialization for the tty structure. |
| 1817 | */ |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1818 | int cy_open(struct tty_struct *tty, struct file *filp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1819 | { |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1820 | struct cyclades_port *info; |
| 1821 | int retval, line; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | |
| 1823 | /* CP('O'); */ |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1824 | line = tty->index; |
| 1825 | if ((line < 0) || (NR_PORTS <= line)) { |
| 1826 | return -ENODEV; |
| 1827 | } |
| 1828 | info = &cy_port[line]; |
| 1829 | if (info->line < 0) { |
| 1830 | return -ENODEV; |
| 1831 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | #ifdef SERIAL_DEBUG_OTHER |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1833 | printk("cy_open %s\n", tty->name); /* */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | #endif |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1835 | if (serial_paranoia_check(info, tty->name, "cy_open")) { |
| 1836 | return -ENODEV; |
| 1837 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1838 | #ifdef SERIAL_DEBUG_OPEN |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1839 | printk("cy_open %s, count = %d\n", tty->name, info->count); |
| 1840 | /**/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1841 | #endif |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1842 | info->count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | #ifdef SERIAL_DEBUG_COUNT |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1844 | printk("cyc: %d: incrementing count to %d\n", __LINE__, info->count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | #endif |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1846 | tty->driver_data = info; |
| 1847 | info->tty = tty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1849 | /* |
| 1850 | * Start up serial port |
| 1851 | */ |
| 1852 | retval = startup(info); |
| 1853 | if (retval) { |
| 1854 | return retval; |
| 1855 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1857 | retval = block_til_ready(tty, filp, info); |
| 1858 | if (retval) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | #ifdef SERIAL_DEBUG_OPEN |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1860 | printk("cy_open returning after block_til_ready with %d\n", |
| 1861 | retval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | #endif |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1863 | return retval; |
| 1864 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | #ifdef SERIAL_DEBUG_OPEN |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1866 | printk("cy_open done\n"); |
| 1867 | /**/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | #endif |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1869 | return 0; |
| 1870 | } /* cy_open */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1871 | |
| 1872 | /* |
| 1873 | * --------------------------------------------------------------------- |
| 1874 | * serial167_init() and friends |
| 1875 | * |
| 1876 | * serial167_init() is called at boot-time to initialize the serial driver. |
| 1877 | * --------------------------------------------------------------------- |
| 1878 | */ |
| 1879 | |
| 1880 | /* |
| 1881 | * This routine prints out the appropriate serial driver version |
| 1882 | * number, and identifies which options were configured into this |
| 1883 | * driver. |
| 1884 | */ |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1885 | static void show_version(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1886 | { |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1887 | printk("MVME166/167 cd2401 driver\n"); |
| 1888 | } /* show_version */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | |
| 1890 | /* initialize chips on card -- return number of valid |
| 1891 | chips (which is number of ports/4) */ |
| 1892 | |
| 1893 | /* |
| 1894 | * This initialises the hardware to a reasonable state. It should |
| 1895 | * probe the chip first so as to copy 166-Bug setup as a default for |
| 1896 | * port 0. It initialises CMR to CyASYNC; that is never done again, so |
| 1897 | * as to limit the number of CyINIT_CHAN commands in normal running. |
| 1898 | * |
| 1899 | * ... I wonder what I should do if this fails ... |
| 1900 | */ |
| 1901 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1902 | void mvme167_serial_console_setup(int cflag) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | { |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1904 | volatile unsigned char *base_addr = (u_char *) BASE_ADDR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1905 | int ch; |
| 1906 | u_char spd; |
| 1907 | u_char rcor, rbpr, badspeed = 0; |
| 1908 | unsigned long flags; |
| 1909 | |
| 1910 | local_irq_save(flags); |
| 1911 | |
| 1912 | /* |
| 1913 | * First probe channel zero of the chip, to see what speed has |
| 1914 | * been selected. |
| 1915 | */ |
| 1916 | |
| 1917 | base_addr[CyCAR] = 0; |
| 1918 | |
| 1919 | rcor = base_addr[CyRCOR] << 5; |
| 1920 | rbpr = base_addr[CyRBPR]; |
| 1921 | |
| 1922 | for (spd = 0; spd < sizeof(baud_bpr); spd++) |
| 1923 | if (rbpr == baud_bpr[spd] && rcor == baud_co[spd]) |
| 1924 | break; |
| 1925 | if (spd >= sizeof(baud_bpr)) { |
| 1926 | spd = 14; /* 19200 */ |
| 1927 | badspeed = 1; /* Failed to identify speed */ |
| 1928 | } |
| 1929 | initial_console_speed = spd; |
| 1930 | |
| 1931 | /* OK, we have chosen a speed, now reset and reinitialise */ |
| 1932 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1933 | my_udelay(20000L); /* Allow time for any active o/p to complete */ |
| 1934 | if (base_addr[CyCCR] != 0x00) { |
| 1935 | local_irq_restore(flags); |
| 1936 | /* printk(" chip is never idle (CCR != 0)\n"); */ |
| 1937 | return; |
| 1938 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1939 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1940 | base_addr[CyCCR] = CyCHIP_RESET; /* Reset the chip */ |
| 1941 | my_udelay(1000L); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1942 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1943 | if (base_addr[CyGFRCR] == 0x00) { |
| 1944 | local_irq_restore(flags); |
| 1945 | /* printk(" chip is not responding (GFRCR stayed 0)\n"); */ |
| 1946 | return; |
| 1947 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 | |
| 1949 | /* |
| 1950 | * System clock is 20Mhz, divided by 2048, so divide by 10 for a 1.0ms |
| 1951 | * tick |
| 1952 | */ |
| 1953 | |
| 1954 | base_addr[CyTPR] = 10; |
| 1955 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1956 | base_addr[CyPILR1] = 0x01; /* Interrupt level for modem change */ |
| 1957 | base_addr[CyPILR2] = 0x02; /* Interrupt level for tx ints */ |
| 1958 | base_addr[CyPILR3] = 0x03; /* Interrupt level for rx ints */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1959 | |
| 1960 | /* |
| 1961 | * Attempt to set up all channels to something reasonable, and |
| 1962 | * bang out a INIT_CHAN command. We should then be able to limit |
Uwe Kleine-König | 9ddc5b6 | 2010-01-20 17:02:24 +0100 | [diff] [blame] | 1963 | * the amount of fiddling we have to do in normal running. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1964 | */ |
| 1965 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1966 | for (ch = 3; ch >= 0; ch--) { |
| 1967 | base_addr[CyCAR] = (u_char) ch; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 | base_addr[CyIER] = 0; |
| 1969 | base_addr[CyCMR] = CyASYNC; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1970 | base_addr[CyLICR] = (u_char) ch << 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1971 | base_addr[CyLIVR] = 0x5c; |
| 1972 | base_addr[CyTCOR] = baud_co[spd]; |
| 1973 | base_addr[CyTBPR] = baud_bpr[spd]; |
| 1974 | base_addr[CyRCOR] = baud_co[spd] >> 5; |
| 1975 | base_addr[CyRBPR] = baud_bpr[spd]; |
| 1976 | base_addr[CySCHR1] = 'Q' & 0x1f; |
| 1977 | base_addr[CySCHR2] = 'X' & 0x1f; |
| 1978 | base_addr[CySCRL] = 0; |
| 1979 | base_addr[CySCRH] = 0; |
| 1980 | base_addr[CyCOR1] = Cy_8_BITS | CyPARITY_NONE; |
| 1981 | base_addr[CyCOR2] = 0; |
| 1982 | base_addr[CyCOR3] = Cy_1_STOP; |
| 1983 | base_addr[CyCOR4] = baud_cor4[spd]; |
| 1984 | base_addr[CyCOR5] = 0; |
| 1985 | base_addr[CyCOR6] = 0; |
| 1986 | base_addr[CyCOR7] = 0; |
| 1987 | base_addr[CyRTPRL] = 2; |
| 1988 | base_addr[CyRTPRH] = 0; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1989 | base_addr[CyMSVR1] = 0; |
| 1990 | base_addr[CyMSVR2] = 0; |
| 1991 | write_cy_cmd(base_addr, CyINIT_CHAN | CyDIS_RCVR | CyDIS_XMTR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1992 | } |
| 1993 | |
| 1994 | /* |
| 1995 | * Now do specials for channel zero.... |
| 1996 | */ |
| 1997 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 1998 | base_addr[CyMSVR1] = CyRTS; |
| 1999 | base_addr[CyMSVR2] = CyDTR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2000 | base_addr[CyIER] = CyRxData; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2001 | write_cy_cmd(base_addr, CyENB_RCVR | CyENB_XMTR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | |
| 2003 | local_irq_restore(flags); |
| 2004 | |
| 2005 | my_udelay(20000L); /* Let it all settle down */ |
| 2006 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2007 | printk("CD2401 initialised, chip is rev 0x%02x\n", base_addr[CyGFRCR]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2008 | if (badspeed) |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2009 | printk |
| 2010 | (" WARNING: Failed to identify line speed, rcor=%02x,rbpr=%02x\n", |
| 2011 | rcor >> 5, rbpr); |
| 2012 | } /* serial_console_init */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | |
Jeff Dike | b68e31d | 2006-10-02 02:17:18 -0700 | [diff] [blame] | 2014 | static const struct tty_operations cy_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2015 | .open = cy_open, |
| 2016 | .close = cy_close, |
| 2017 | .write = cy_write, |
| 2018 | .put_char = cy_put_char, |
| 2019 | .flush_chars = cy_flush_chars, |
| 2020 | .write_room = cy_write_room, |
| 2021 | .chars_in_buffer = cy_chars_in_buffer, |
| 2022 | .flush_buffer = cy_flush_buffer, |
| 2023 | .ioctl = cy_ioctl, |
| 2024 | .throttle = cy_throttle, |
| 2025 | .unthrottle = cy_unthrottle, |
| 2026 | .set_termios = cy_set_termios, |
| 2027 | .stop = cy_stop, |
| 2028 | .start = cy_start, |
| 2029 | .hangup = cy_hangup, |
| 2030 | .tiocmget = cy_tiocmget, |
| 2031 | .tiocmset = cy_tiocmset, |
| 2032 | }; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2033 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2034 | /* The serial driver boot-time initialization code! |
| 2035 | Hardware I/O ports are mapped to character special devices on a |
| 2036 | first found, first allocated manner. That is, this code searches |
| 2037 | for Cyclom cards in the system. As each is found, it is probed |
| 2038 | to discover how many chips (and thus how many ports) are present. |
| 2039 | These ports are mapped to the tty ports 64 and upward in monotonic |
| 2040 | fashion. If an 8-port card is replaced with a 16-port card, the |
| 2041 | port mapping on a following card will shift. |
| 2042 | |
| 2043 | This approach is different from what is used in the other serial |
| 2044 | device driver because the Cyclom is more properly a multiplexer, |
| 2045 | not just an aggregation of serial ports on one card. |
| 2046 | |
| 2047 | If there are more cards with more ports than have been statically |
| 2048 | allocated above, a warning is printed and the extra ports are ignored. |
| 2049 | */ |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2050 | static int __init serial167_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | { |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2052 | struct cyclades_port *info; |
| 2053 | int ret = 0; |
| 2054 | int good_ports = 0; |
| 2055 | int port_num = 0; |
| 2056 | int index; |
| 2057 | int DefSpeed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2058 | #ifdef notyet |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2059 | struct sigaction sa; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | #endif |
| 2061 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2062 | if (!(mvme16x_config & MVME16x_CONFIG_GOT_CD2401)) |
| 2063 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2064 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2065 | cy_serial_driver = alloc_tty_driver(NR_PORTS); |
| 2066 | if (!cy_serial_driver) |
| 2067 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2068 | |
| 2069 | #if 0 |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2070 | scrn[1] = '\0'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2071 | #endif |
| 2072 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2073 | show_version(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2075 | /* Has "console=0,9600n8" been used in bootinfo to change speed? */ |
| 2076 | if (serial_console_cflag) |
| 2077 | DefSpeed = serial_console_cflag & 0017; |
| 2078 | else { |
| 2079 | DefSpeed = initial_console_speed; |
| 2080 | serial_console_info = &cy_port[0]; |
| 2081 | serial_console_cflag = DefSpeed | CS8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2082 | #if 0 |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2083 | serial_console = 64; /*callout_driver.minor_start */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2084 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2085 | } |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2086 | |
| 2087 | /* Initialize the tty_driver structure */ |
| 2088 | |
| 2089 | cy_serial_driver->owner = THIS_MODULE; |
| 2090 | cy_serial_driver->name = "ttyS"; |
| 2091 | cy_serial_driver->major = TTY_MAJOR; |
| 2092 | cy_serial_driver->minor_start = 64; |
| 2093 | cy_serial_driver->type = TTY_DRIVER_TYPE_SERIAL; |
| 2094 | cy_serial_driver->subtype = SERIAL_TYPE_NORMAL; |
| 2095 | cy_serial_driver->init_termios = tty_std_termios; |
| 2096 | cy_serial_driver->init_termios.c_cflag = |
| 2097 | B9600 | CS8 | CREAD | HUPCL | CLOCAL; |
| 2098 | cy_serial_driver->flags = TTY_DRIVER_REAL_RAW; |
| 2099 | tty_set_operations(cy_serial_driver, &cy_ops); |
| 2100 | |
| 2101 | ret = tty_register_driver(cy_serial_driver); |
| 2102 | if (ret) { |
| 2103 | printk(KERN_ERR "Couldn't register MVME166/7 serial driver\n"); |
| 2104 | put_tty_driver(cy_serial_driver); |
| 2105 | return ret; |
| 2106 | } |
| 2107 | |
| 2108 | port_num = 0; |
| 2109 | info = cy_port; |
| 2110 | for (index = 0; index < 1; index++) { |
| 2111 | |
| 2112 | good_ports = 4; |
| 2113 | |
| 2114 | if (port_num < NR_PORTS) { |
| 2115 | while (good_ports-- && port_num < NR_PORTS) { |
| 2116 | /*** initialize port ***/ |
| 2117 | info->magic = CYCLADES_MAGIC; |
| 2118 | info->type = PORT_CIRRUS; |
| 2119 | info->card = index; |
| 2120 | info->line = port_num; |
| 2121 | info->flags = STD_COM_FLAGS; |
| 2122 | info->tty = NULL; |
| 2123 | info->xmit_fifo_size = 12; |
| 2124 | info->cor1 = CyPARITY_NONE | Cy_8_BITS; |
| 2125 | info->cor2 = CyETC; |
| 2126 | info->cor3 = Cy_1_STOP; |
| 2127 | info->cor4 = 0x08; /* _very_ small receive threshold */ |
| 2128 | info->cor5 = 0; |
| 2129 | info->cor6 = 0; |
| 2130 | info->cor7 = 0; |
| 2131 | info->tbpr = baud_bpr[DefSpeed]; /* Tx BPR */ |
| 2132 | info->tco = baud_co[DefSpeed]; /* Tx CO */ |
| 2133 | info->rbpr = baud_bpr[DefSpeed]; /* Rx BPR */ |
| 2134 | info->rco = baud_co[DefSpeed] >> 5; /* Rx CO */ |
| 2135 | info->close_delay = 0; |
| 2136 | info->x_char = 0; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2137 | info->count = 0; |
| 2138 | #ifdef SERIAL_DEBUG_COUNT |
| 2139 | printk("cyc: %d: setting count to 0\n", |
| 2140 | __LINE__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2141 | #endif |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2142 | info->blocked_open = 0; |
| 2143 | info->default_threshold = 0; |
| 2144 | info->default_timeout = 0; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2145 | init_waitqueue_head(&info->open_wait); |
| 2146 | init_waitqueue_head(&info->close_wait); |
| 2147 | /* info->session */ |
| 2148 | /* info->pgrp */ |
| 2149 | /*** !!!!!!!! this may expose new bugs !!!!!!!!! *********/ |
| 2150 | info->read_status_mask = |
| 2151 | CyTIMEOUT | CySPECHAR | CyBREAK | CyPARITY | |
| 2152 | CyFRAME | CyOVERRUN; |
| 2153 | /* info->timeout */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2154 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2155 | printk("ttyS%d ", info->line); |
| 2156 | port_num++; |
| 2157 | info++; |
| 2158 | if (!(port_num & 7)) { |
| 2159 | printk("\n "); |
| 2160 | } |
| 2161 | } |
| 2162 | } |
| 2163 | printk("\n"); |
| 2164 | } |
| 2165 | while (port_num < NR_PORTS) { |
| 2166 | info->line = -1; |
| 2167 | port_num++; |
| 2168 | info++; |
| 2169 | } |
Christoph Egger | 0dbb567 | 2010-05-17 17:25:54 +0200 | [diff] [blame] | 2170 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2171 | ret = request_irq(MVME167_IRQ_SER_ERR, cd2401_rxerr_interrupt, 0, |
| 2172 | "cd2401_errors", cd2401_rxerr_interrupt); |
| 2173 | if (ret) { |
| 2174 | printk(KERN_ERR "Could't get cd2401_errors IRQ"); |
| 2175 | goto cleanup_serial_driver; |
| 2176 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2177 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2178 | ret = request_irq(MVME167_IRQ_SER_MODEM, cd2401_modem_interrupt, 0, |
| 2179 | "cd2401_modem", cd2401_modem_interrupt); |
| 2180 | if (ret) { |
| 2181 | printk(KERN_ERR "Could't get cd2401_modem IRQ"); |
| 2182 | goto cleanup_irq_cd2401_errors; |
| 2183 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2184 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2185 | ret = request_irq(MVME167_IRQ_SER_TX, cd2401_tx_interrupt, 0, |
| 2186 | "cd2401_txints", cd2401_tx_interrupt); |
| 2187 | if (ret) { |
| 2188 | printk(KERN_ERR "Could't get cd2401_txints IRQ"); |
| 2189 | goto cleanup_irq_cd2401_modem; |
| 2190 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2191 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2192 | ret = request_irq(MVME167_IRQ_SER_RX, cd2401_rx_interrupt, 0, |
| 2193 | "cd2401_rxints", cd2401_rx_interrupt); |
| 2194 | if (ret) { |
| 2195 | printk(KERN_ERR "Could't get cd2401_rxints IRQ"); |
| 2196 | goto cleanup_irq_cd2401_txints; |
| 2197 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2198 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2199 | /* Now we have registered the interrupt handlers, allow the interrupts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2200 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2201 | pcc2chip[PccSCCMICR] = 0x15; /* Serial ints are level 5 */ |
| 2202 | pcc2chip[PccSCCTICR] = 0x15; |
| 2203 | pcc2chip[PccSCCRICR] = 0x15; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2204 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2205 | pcc2chip[PccIMLR] = 3; /* Allow PCC2 ints above 3!? */ |
| 2206 | |
| 2207 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2208 | cleanup_irq_cd2401_txints: |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2209 | free_irq(MVME167_IRQ_SER_TX, cd2401_tx_interrupt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2210 | cleanup_irq_cd2401_modem: |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2211 | free_irq(MVME167_IRQ_SER_MODEM, cd2401_modem_interrupt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2212 | cleanup_irq_cd2401_errors: |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2213 | free_irq(MVME167_IRQ_SER_ERR, cd2401_rxerr_interrupt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2214 | cleanup_serial_driver: |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2215 | if (tty_unregister_driver(cy_serial_driver)) |
| 2216 | printk(KERN_ERR |
| 2217 | "Couldn't unregister MVME166/7 serial driver\n"); |
| 2218 | put_tty_driver(cy_serial_driver); |
| 2219 | return ret; |
| 2220 | } /* serial167_init */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2221 | |
| 2222 | module_init(serial167_init); |
| 2223 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2224 | #ifdef CYCLOM_SHOW_STATUS |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2225 | static void show_status(int line_num) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2226 | { |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2227 | volatile unsigned char *base_addr = (u_char *) BASE_ADDR; |
| 2228 | int channel; |
| 2229 | struct cyclades_port *info; |
| 2230 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2231 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2232 | info = &cy_port[line_num]; |
| 2233 | channel = info->line; |
| 2234 | printk(" channel %d\n", channel); |
| 2235 | /**/ printk(" cy_port\n"); |
| 2236 | printk(" card line flags = %d %d %x\n", |
| 2237 | info->card, info->line, info->flags); |
| 2238 | printk |
| 2239 | (" *tty read_status_mask timeout xmit_fifo_size = %lx %x %x %x\n", |
| 2240 | (long)info->tty, info->read_status_mask, info->timeout, |
| 2241 | info->xmit_fifo_size); |
| 2242 | printk(" cor1,cor2,cor3,cor4,cor5,cor6,cor7 = %x %x %x %x %x %x %x\n", |
| 2243 | info->cor1, info->cor2, info->cor3, info->cor4, info->cor5, |
| 2244 | info->cor6, info->cor7); |
| 2245 | printk(" tbpr,tco,rbpr,rco = %d %d %d %d\n", info->tbpr, info->tco, |
| 2246 | info->rbpr, info->rco); |
| 2247 | printk(" close_delay event count = %d %d %d\n", info->close_delay, |
| 2248 | info->event, info->count); |
| 2249 | printk(" x_char blocked_open = %x %x\n", info->x_char, |
| 2250 | info->blocked_open); |
| 2251 | printk(" open_wait = %lx %lx %lx\n", (long)info->open_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2252 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2253 | local_irq_save(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2254 | |
| 2255 | /* Global Registers */ |
| 2256 | |
| 2257 | printk(" CyGFRCR %x\n", base_addr[CyGFRCR]); |
| 2258 | printk(" CyCAR %x\n", base_addr[CyCAR]); |
| 2259 | printk(" CyRISR %x\n", base_addr[CyRISR]); |
| 2260 | printk(" CyTISR %x\n", base_addr[CyTISR]); |
| 2261 | printk(" CyMISR %x\n", base_addr[CyMISR]); |
| 2262 | printk(" CyRIR %x\n", base_addr[CyRIR]); |
| 2263 | printk(" CyTIR %x\n", base_addr[CyTIR]); |
| 2264 | printk(" CyMIR %x\n", base_addr[CyMIR]); |
| 2265 | printk(" CyTPR %x\n", base_addr[CyTPR]); |
| 2266 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2267 | base_addr[CyCAR] = (u_char) channel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2268 | |
| 2269 | /* Virtual Registers */ |
| 2270 | |
| 2271 | #if 0 |
| 2272 | printk(" CyRIVR %x\n", base_addr[CyRIVR]); |
| 2273 | printk(" CyTIVR %x\n", base_addr[CyTIVR]); |
| 2274 | printk(" CyMIVR %x\n", base_addr[CyMIVR]); |
| 2275 | printk(" CyMISR %x\n", base_addr[CyMISR]); |
| 2276 | #endif |
| 2277 | |
| 2278 | /* Channel Registers */ |
| 2279 | |
| 2280 | printk(" CyCCR %x\n", base_addr[CyCCR]); |
| 2281 | printk(" CyIER %x\n", base_addr[CyIER]); |
| 2282 | printk(" CyCOR1 %x\n", base_addr[CyCOR1]); |
| 2283 | printk(" CyCOR2 %x\n", base_addr[CyCOR2]); |
| 2284 | printk(" CyCOR3 %x\n", base_addr[CyCOR3]); |
| 2285 | printk(" CyCOR4 %x\n", base_addr[CyCOR4]); |
| 2286 | printk(" CyCOR5 %x\n", base_addr[CyCOR5]); |
| 2287 | #if 0 |
| 2288 | printk(" CyCCSR %x\n", base_addr[CyCCSR]); |
| 2289 | printk(" CyRDCR %x\n", base_addr[CyRDCR]); |
| 2290 | #endif |
| 2291 | printk(" CySCHR1 %x\n", base_addr[CySCHR1]); |
| 2292 | printk(" CySCHR2 %x\n", base_addr[CySCHR2]); |
| 2293 | #if 0 |
| 2294 | printk(" CySCHR3 %x\n", base_addr[CySCHR3]); |
| 2295 | printk(" CySCHR4 %x\n", base_addr[CySCHR4]); |
| 2296 | printk(" CySCRL %x\n", base_addr[CySCRL]); |
| 2297 | printk(" CySCRH %x\n", base_addr[CySCRH]); |
| 2298 | printk(" CyLNC %x\n", base_addr[CyLNC]); |
| 2299 | printk(" CyMCOR1 %x\n", base_addr[CyMCOR1]); |
| 2300 | printk(" CyMCOR2 %x\n", base_addr[CyMCOR2]); |
| 2301 | #endif |
| 2302 | printk(" CyRTPRL %x\n", base_addr[CyRTPRL]); |
| 2303 | printk(" CyRTPRH %x\n", base_addr[CyRTPRH]); |
| 2304 | printk(" CyMSVR1 %x\n", base_addr[CyMSVR1]); |
| 2305 | printk(" CyMSVR2 %x\n", base_addr[CyMSVR2]); |
| 2306 | printk(" CyRBPR %x\n", base_addr[CyRBPR]); |
| 2307 | printk(" CyRCOR %x\n", base_addr[CyRCOR]); |
| 2308 | printk(" CyTBPR %x\n", base_addr[CyTBPR]); |
| 2309 | printk(" CyTCOR %x\n", base_addr[CyTCOR]); |
| 2310 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2311 | local_irq_restore(flags); |
| 2312 | } /* show_status */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2313 | #endif |
| 2314 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2315 | #if 0 |
| 2316 | /* Dummy routine in mvme16x/config.c for now */ |
| 2317 | |
| 2318 | /* Serial console setup. Called from linux/init/main.c */ |
| 2319 | |
| 2320 | void console_setup(char *str, int *ints) |
| 2321 | { |
| 2322 | char *s; |
| 2323 | int baud, bits, parity; |
| 2324 | int cflag = 0; |
| 2325 | |
| 2326 | /* Sanity check. */ |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2327 | if (ints[0] > 3 || ints[1] > 3) |
| 2328 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2329 | |
| 2330 | /* Get baud, bits and parity */ |
| 2331 | baud = 2400; |
| 2332 | bits = 8; |
| 2333 | parity = 'n'; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2334 | if (ints[2]) |
| 2335 | baud = ints[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2336 | if ((s = strchr(str, ','))) { |
| 2337 | do { |
| 2338 | s++; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2339 | } while (*s >= '0' && *s <= '9'); |
| 2340 | if (*s) |
| 2341 | parity = *s++; |
| 2342 | if (*s) |
| 2343 | bits = *s - '0'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2344 | } |
| 2345 | |
| 2346 | /* Now construct a cflag setting. */ |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2347 | switch (baud) { |
| 2348 | case 1200: |
| 2349 | cflag |= B1200; |
| 2350 | break; |
| 2351 | case 9600: |
| 2352 | cflag |= B9600; |
| 2353 | break; |
| 2354 | case 19200: |
| 2355 | cflag |= B19200; |
| 2356 | break; |
| 2357 | case 38400: |
| 2358 | cflag |= B38400; |
| 2359 | break; |
| 2360 | case 2400: |
| 2361 | default: |
| 2362 | cflag |= B2400; |
| 2363 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2364 | } |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2365 | switch (bits) { |
| 2366 | case 7: |
| 2367 | cflag |= CS7; |
| 2368 | break; |
| 2369 | default: |
| 2370 | case 8: |
| 2371 | cflag |= CS8; |
| 2372 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2373 | } |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2374 | switch (parity) { |
| 2375 | case 'o': |
| 2376 | case 'O': |
| 2377 | cflag |= PARODD; |
| 2378 | break; |
| 2379 | case 'e': |
| 2380 | case 'E': |
| 2381 | cflag |= PARENB; |
| 2382 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2383 | } |
| 2384 | |
| 2385 | serial_console_info = &cy_port[ints[1]]; |
| 2386 | serial_console_cflag = cflag; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2387 | serial_console = ints[1] + 64; /*callout_driver.minor_start */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2388 | } |
| 2389 | #endif |
| 2390 | |
| 2391 | /* |
| 2392 | * The following is probably out of date for 2.1.x serial console stuff. |
| 2393 | * |
| 2394 | * The console is registered early on from arch/m68k/kernel/setup.c, and |
| 2395 | * it therefore relies on the chip being setup correctly by 166-Bug. This |
| 2396 | * seems reasonable, as the serial port has been used to invoke the system |
| 2397 | * boot. It also means that this function must not rely on any data |
| 2398 | * initialisation performed by serial167_init() etc. |
| 2399 | * |
| 2400 | * Of course, once the console has been registered, we had better ensure |
| 2401 | * that serial167_init() doesn't leave the chip non-functional. |
| 2402 | * |
| 2403 | * The console must be locked when we get here. |
| 2404 | */ |
| 2405 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2406 | void serial167_console_write(struct console *co, const char *str, |
| 2407 | unsigned count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2408 | { |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2409 | volatile unsigned char *base_addr = (u_char *) BASE_ADDR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2410 | unsigned long flags; |
| 2411 | volatile u_char sink; |
| 2412 | u_char ier; |
| 2413 | int port; |
| 2414 | u_char do_lf = 0; |
| 2415 | int i = 0; |
| 2416 | |
| 2417 | local_irq_save(flags); |
| 2418 | |
| 2419 | /* Ensure transmitter is enabled! */ |
| 2420 | |
| 2421 | port = 0; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2422 | base_addr[CyCAR] = (u_char) port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2423 | while (base_addr[CyCCR]) |
| 2424 | ; |
| 2425 | base_addr[CyCCR] = CyENB_XMTR; |
| 2426 | |
| 2427 | ier = base_addr[CyIER]; |
| 2428 | base_addr[CyIER] = CyTxMpty; |
| 2429 | |
| 2430 | while (1) { |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2431 | if (pcc2chip[PccSCCTICR] & 0x20) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2432 | /* We have a Tx int. Acknowledge it */ |
| 2433 | sink = pcc2chip[PccTPIACKR]; |
| 2434 | if ((base_addr[CyLICR] >> 2) == port) { |
| 2435 | if (i == count) { |
| 2436 | /* Last char of string is now output */ |
| 2437 | base_addr[CyTEOIR] = CyNOTRANS; |
| 2438 | break; |
| 2439 | } |
| 2440 | if (do_lf) { |
| 2441 | base_addr[CyTDR] = '\n'; |
| 2442 | str++; |
| 2443 | i++; |
| 2444 | do_lf = 0; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2445 | } else if (*str == '\n') { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2446 | base_addr[CyTDR] = '\r'; |
| 2447 | do_lf = 1; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2448 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2449 | base_addr[CyTDR] = *str++; |
| 2450 | i++; |
| 2451 | } |
| 2452 | base_addr[CyTEOIR] = 0; |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2453 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2454 | base_addr[CyTEOIR] = CyNOTRANS; |
| 2455 | } |
| 2456 | } |
| 2457 | |
| 2458 | base_addr[CyIER] = ier; |
| 2459 | |
| 2460 | local_irq_restore(flags); |
| 2461 | } |
| 2462 | |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2463 | static struct tty_driver *serial167_console_device(struct console *c, |
| 2464 | int *index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2465 | { |
| 2466 | *index = c->index; |
| 2467 | return cy_serial_driver; |
| 2468 | } |
| 2469 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2470 | static struct console sercons = { |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2471 | .name = "ttyS", |
| 2472 | .write = serial167_console_write, |
| 2473 | .device = serial167_console_device, |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2474 | .flags = CON_PRINTBUFFER, |
| 2475 | .index = -1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2476 | }; |
| 2477 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2478 | static int __init serial167_console_init(void) |
| 2479 | { |
| 2480 | if (vme_brdtype == VME_TYPE_MVME166 || |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2481 | vme_brdtype == VME_TYPE_MVME167 || |
| 2482 | vme_brdtype == VME_TYPE_MVME177) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2483 | mvme167_serial_console_setup(0); |
| 2484 | register_console(&sercons); |
| 2485 | } |
| 2486 | return 0; |
| 2487 | } |
Jiri Slaby | 44bafdf | 2007-02-10 01:45:08 -0800 | [diff] [blame] | 2488 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2489 | console_initcall(serial167_console_init); |
| 2490 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2491 | MODULE_LICENSE("GPL"); |