Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * specialix.c -- specialix IO8+ multiport serial driver. |
| 3 | * |
| 4 | * Copyright (C) 1997 Roger Wolff (R.E.Wolff@BitWizard.nl) |
| 5 | * Copyright (C) 1994-1996 Dmitry Gorodchanin (pgmdsg@ibi.com) |
| 6 | * |
| 7 | * Specialix pays for the development and support of this driver. |
| 8 | * Please DO contact io8-linux@specialix.co.uk if you require |
| 9 | * support. But please read the documentation (specialix.txt) |
| 10 | * first. |
| 11 | * |
| 12 | * This driver was developped in the BitWizard linux device |
| 13 | * driver service. If you require a linux device driver for your |
| 14 | * product, please contact devices@BitWizard.nl for a quote. |
| 15 | * |
| 16 | * This code is firmly based on the riscom/8 serial driver, |
| 17 | * written by Dmitry Gorodchanin. The specialix IO8+ card |
| 18 | * programming information was obtained from the CL-CD1865 Data |
| 19 | * Book, and Specialix document number 6200059: IO8+ Hardware |
| 20 | * Functional Specification. |
| 21 | * |
| 22 | * This program is free software; you can redistribute it and/or |
| 23 | * modify it under the terms of the GNU General Public License as |
| 24 | * published by the Free Software Foundation; either version 2 of |
| 25 | * the License, or (at your option) any later version. |
| 26 | * |
| 27 | * This program is distributed in the hope that it will be |
| 28 | * useful, but WITHOUT ANY WARRANTY; without even the implied |
| 29 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 30 | * PURPOSE. See the GNU General Public License for more details. |
| 31 | * |
| 32 | * You should have received a copy of the GNU General Public |
| 33 | * License along with this program; if not, write to the Free |
| 34 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, |
| 35 | * USA. |
| 36 | * |
| 37 | * Revision history: |
| 38 | * |
| 39 | * Revision 1.0: April 1st 1997. |
| 40 | * Initial release for alpha testing. |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 41 | * Revision 1.1: April 14th 1997. |
| 42 | * Incorporated Richard Hudsons suggestions, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | * removed some debugging printk's. |
| 44 | * Revision 1.2: April 15th 1997. |
| 45 | * Ported to 2.1.x kernels. |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 46 | * Revision 1.3: April 17th 1997 |
| 47 | * Backported to 2.0. (Compatibility macros). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | * Revision 1.4: April 18th 1997 |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 49 | * Fixed DTR/RTS bug that caused the card to indicate |
| 50 | * "don't send data" to a modem after the password prompt. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | * Fixed bug for premature (fake) interrupts. |
| 52 | * Revision 1.5: April 19th 1997 |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 53 | * fixed a minor typo in the header file, cleanup a little. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | * performance warnings are now MAXed at once per minute. |
| 55 | * Revision 1.6: May 23 1997 |
| 56 | * Changed the specialix=... format to include interrupt. |
| 57 | * Revision 1.7: May 27 1997 |
| 58 | * Made many more debug printk's a compile time option. |
| 59 | * Revision 1.8: Jul 1 1997 |
| 60 | * port to linux-2.1.43 kernel. |
| 61 | * Revision 1.9: Oct 9 1998 |
| 62 | * Added stuff for the IO8+/PCI version. |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 63 | * Revision 1.10: Oct 22 1999 / Jan 21 2000. |
| 64 | * Added stuff for setserial. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | * Nicolas Mailhot (Nicolas.Mailhot@email.enst.fr) |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 66 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | */ |
| 68 | |
| 69 | #define VERSION "1.11" |
| 70 | |
| 71 | |
| 72 | /* |
| 73 | * There is a bunch of documentation about the card, jumpers, config |
| 74 | * settings, restrictions, cables, device names and numbers in |
Randy Dunlap | 31c00fc | 2008-11-13 21:33:24 +0000 | [diff] [blame] | 75 | * Documentation/serial/specialix.txt |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | */ |
| 77 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | #include <linux/module.h> |
| 79 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 80 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | #include <linux/kernel.h> |
| 82 | #include <linux/sched.h> |
| 83 | #include <linux/ioport.h> |
| 84 | #include <linux/interrupt.h> |
| 85 | #include <linux/errno.h> |
| 86 | #include <linux/tty.h> |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 87 | #include <linux/tty_flip.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | #include <linux/mm.h> |
| 89 | #include <linux/serial.h> |
Alexey Dobriyan | 405f557 | 2009-07-11 22:08:37 +0400 | [diff] [blame] | 90 | #include <linux/smp_lock.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | #include <linux/fcntl.h> |
| 92 | #include <linux/major.h> |
| 93 | #include <linux/delay.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | #include <linux/pci.h> |
| 95 | #include <linux/init.h> |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 96 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
| 98 | #include "specialix_io8.h" |
| 99 | #include "cd1865.h" |
| 100 | |
| 101 | |
| 102 | /* |
| 103 | This driver can spew a whole lot of debugging output at you. If you |
| 104 | need maximum performance, you should disable the DEBUG define. To |
| 105 | aid in debugging in the field, I'm leaving the compile-time debug |
| 106 | features enabled, and disable them "runtime". That allows me to |
| 107 | instruct people with problems to enable debugging without requiring |
| 108 | them to recompile... |
| 109 | */ |
| 110 | #define DEBUG |
| 111 | |
| 112 | static int sx_debug; |
| 113 | static int sx_rxfifo = SPECIALIX_RXFIFO; |
Alan Cox | d2fbd0f | 2008-07-22 11:17:16 +0100 | [diff] [blame] | 114 | static int sx_rtscts; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | |
| 116 | #ifdef DEBUG |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 117 | #define dprintk(f, str...) if (sx_debug & f) printk(str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | #else |
| 119 | #define dprintk(f, str...) /* nothing */ |
| 120 | #endif |
| 121 | |
| 122 | #define SX_DEBUG_FLOW 0x0001 |
| 123 | #define SX_DEBUG_DATA 0x0002 |
| 124 | #define SX_DEBUG_PROBE 0x0004 |
| 125 | #define SX_DEBUG_CHAN 0x0008 |
| 126 | #define SX_DEBUG_INIT 0x0010 |
| 127 | #define SX_DEBUG_RX 0x0020 |
| 128 | #define SX_DEBUG_TX 0x0040 |
| 129 | #define SX_DEBUG_IRQ 0x0080 |
| 130 | #define SX_DEBUG_OPEN 0x0100 |
| 131 | #define SX_DEBUG_TERMIOS 0x0200 |
| 132 | #define SX_DEBUG_SIGNALS 0x0400 |
| 133 | #define SX_DEBUG_FIFO 0x0800 |
| 134 | |
| 135 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 136 | #define func_enter() dprintk(SX_DEBUG_FLOW, "io8: enter %s\n", __func__) |
| 137 | #define func_exit() dprintk(SX_DEBUG_FLOW, "io8: exit %s\n", __func__) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
| 140 | /* Configurable options: */ |
| 141 | |
| 142 | /* Am I paranoid or not ? ;-) */ |
| 143 | #define SPECIALIX_PARANOIA_CHECK |
| 144 | |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 145 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | * The following defines are mostly for testing purposes. But if you need |
| 147 | * some nice reporting in your syslog, you can define them also. |
| 148 | */ |
| 149 | #undef SX_REPORT_FIFO |
| 150 | #undef SX_REPORT_OVERRUN |
| 151 | |
| 152 | |
| 153 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | |
| 155 | #define SPECIALIX_LEGAL_FLAGS \ |
| 156 | (ASYNC_HUP_NOTIFY | ASYNC_SAK | ASYNC_SPLIT_TERMIOS | \ |
| 157 | ASYNC_SPD_HI | ASYNC_SPEED_VHI | ASYNC_SESSION_LOCKOUT | \ |
| 158 | ASYNC_PGRP_LOCKOUT | ASYNC_CALLOUT_NOHUP) |
| 159 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | static struct tty_driver *specialix_driver; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | static struct specialix_board sx_board[SX_NBOARD] = { |
| 163 | { 0, SX_IOBASE1, 9, }, |
| 164 | { 0, SX_IOBASE2, 11, }, |
| 165 | { 0, SX_IOBASE3, 12, }, |
| 166 | { 0, SX_IOBASE4, 15, }, |
| 167 | }; |
| 168 | |
| 169 | static struct specialix_port sx_port[SX_NBOARD * SX_NPORT]; |
| 170 | |
| 171 | |
Alan Cox | d2fbd0f | 2008-07-22 11:17:16 +0100 | [diff] [blame] | 172 | static int sx_paranoia_check(struct specialix_port const *port, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | char *name, const char *routine) |
| 174 | { |
| 175 | #ifdef SPECIALIX_PARANOIA_CHECK |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 176 | static const char *badmagic = KERN_ERR |
| 177 | "sx: Warning: bad specialix port magic number for device %s in %s\n"; |
| 178 | static const char *badinfo = KERN_ERR |
| 179 | "sx: Warning: null specialix port for device %s in %s\n"; |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | if (!port) { |
| 182 | printk(badinfo, name, routine); |
| 183 | return 1; |
| 184 | } |
| 185 | if (port->magic != SPECIALIX_MAGIC) { |
| 186 | printk(badmagic, name, routine); |
| 187 | return 1; |
| 188 | } |
| 189 | #endif |
| 190 | return 0; |
| 191 | } |
| 192 | |
| 193 | |
| 194 | /* |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 195 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | * Service functions for specialix IO8+ driver. |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 197 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | */ |
| 199 | |
| 200 | /* Get board number from pointer */ |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 201 | static inline int board_No(struct specialix_board *bp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | { |
| 203 | return bp - sx_board; |
| 204 | } |
| 205 | |
| 206 | |
| 207 | /* Get port number from pointer */ |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 208 | static inline int port_No(struct specialix_port const *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | { |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 210 | return SX_PORT(port - sx_port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | |
| 214 | /* Get pointer to board from pointer to port */ |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 215 | static inline struct specialix_board *port_Board( |
| 216 | struct specialix_port const *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | { |
| 218 | return &sx_board[SX_BOARD(port - sx_port)]; |
| 219 | } |
| 220 | |
| 221 | |
| 222 | /* Input Byte from CL CD186x register */ |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 223 | static inline unsigned char sx_in(struct specialix_board *bp, |
| 224 | unsigned short reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | { |
| 226 | bp->reg = reg | 0x80; |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 227 | outb(reg | 0x80, bp->base + SX_ADDR_REG); |
| 228 | return inb(bp->base + SX_DATA_REG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | |
| 232 | /* Output Byte to CL CD186x register */ |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 233 | static inline void sx_out(struct specialix_board *bp, unsigned short reg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | unsigned char val) |
| 235 | { |
| 236 | bp->reg = reg | 0x80; |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 237 | outb(reg | 0x80, bp->base + SX_ADDR_REG); |
| 238 | outb(val, bp->base + SX_DATA_REG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | |
| 242 | /* Input Byte from CL CD186x register */ |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 243 | static inline unsigned char sx_in_off(struct specialix_board *bp, |
| 244 | unsigned short reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | { |
| 246 | bp->reg = reg; |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 247 | outb(reg, bp->base + SX_ADDR_REG); |
| 248 | return inb(bp->base + SX_DATA_REG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | |
| 252 | /* Output Byte to CL CD186x register */ |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 253 | static inline void sx_out_off(struct specialix_board *bp, |
| 254 | unsigned short reg, unsigned char val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | { |
| 256 | bp->reg = reg; |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 257 | outb(reg, bp->base + SX_ADDR_REG); |
| 258 | outb(val, bp->base + SX_DATA_REG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | |
| 262 | /* Wait for Channel Command Register ready */ |
Alan Cox | d2fbd0f | 2008-07-22 11:17:16 +0100 | [diff] [blame] | 263 | static void sx_wait_CCR(struct specialix_board *bp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | { |
| 265 | unsigned long delay, flags; |
| 266 | unsigned char ccr; |
| 267 | |
| 268 | for (delay = SX_CCR_TIMEOUT; delay; delay--) { |
| 269 | spin_lock_irqsave(&bp->lock, flags); |
| 270 | ccr = sx_in(bp, CD186x_CCR); |
| 271 | spin_unlock_irqrestore(&bp->lock, flags); |
| 272 | if (!ccr) |
| 273 | return; |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 274 | udelay(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | } |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 276 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | printk(KERN_ERR "sx%d: Timeout waiting for CCR.\n", board_No(bp)); |
| 278 | } |
| 279 | |
| 280 | |
| 281 | /* Wait for Channel Command Register ready */ |
Alan Cox | d2fbd0f | 2008-07-22 11:17:16 +0100 | [diff] [blame] | 282 | static void sx_wait_CCR_off(struct specialix_board *bp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | { |
| 284 | unsigned long delay; |
| 285 | unsigned char crr; |
| 286 | unsigned long flags; |
| 287 | |
| 288 | for (delay = SX_CCR_TIMEOUT; delay; delay--) { |
| 289 | spin_lock_irqsave(&bp->lock, flags); |
| 290 | crr = sx_in_off(bp, CD186x_CCR); |
| 291 | spin_unlock_irqrestore(&bp->lock, flags); |
| 292 | if (!crr) |
| 293 | return; |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 294 | udelay(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | } |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 296 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | printk(KERN_ERR "sx%d: Timeout waiting for CCR.\n", board_No(bp)); |
| 298 | } |
| 299 | |
| 300 | |
| 301 | /* |
| 302 | * specialix IO8+ IO range functions. |
| 303 | */ |
| 304 | |
Alan Cox | d2fbd0f | 2008-07-22 11:17:16 +0100 | [diff] [blame] | 305 | static int sx_request_io_range(struct specialix_board *bp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | { |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 307 | return request_region(bp->base, |
| 308 | bp->flags & SX_BOARD_IS_PCI ? SX_PCI_IO_SPACE : SX_IO_SPACE, |
| 309 | "specialix IO8+") == NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | |
Alan Cox | d2fbd0f | 2008-07-22 11:17:16 +0100 | [diff] [blame] | 313 | static void sx_release_io_range(struct specialix_board *bp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | { |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 315 | release_region(bp->base, bp->flags & SX_BOARD_IS_PCI ? |
| 316 | SX_PCI_IO_SPACE : SX_IO_SPACE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 319 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | /* Set the IRQ using the RTS lines that run to the PAL on the board.... */ |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 321 | static int sx_set_irq(struct specialix_board *bp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | { |
| 323 | int virq; |
| 324 | int i; |
| 325 | unsigned long flags; |
| 326 | |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 327 | if (bp->flags & SX_BOARD_IS_PCI) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | return 1; |
| 329 | switch (bp->irq) { |
| 330 | /* In the same order as in the docs... */ |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 331 | case 15: |
| 332 | virq = 0; |
| 333 | break; |
| 334 | case 12: |
| 335 | virq = 1; |
| 336 | break; |
| 337 | case 11: |
| 338 | virq = 2; |
| 339 | break; |
| 340 | case 9: |
| 341 | virq = 3; |
| 342 | break; |
| 343 | default:printk(KERN_ERR |
| 344 | "Speclialix: cannot set irq to %d.\n", bp->irq); |
| 345 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | } |
| 347 | spin_lock_irqsave(&bp->lock, flags); |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 348 | for (i = 0; i < 2; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | sx_out(bp, CD186x_CAR, i); |
| 350 | sx_out(bp, CD186x_MSVRTS, ((virq >> i) & 0x1)? MSVR_RTS:0); |
| 351 | } |
| 352 | spin_unlock_irqrestore(&bp->lock, flags); |
| 353 | return 1; |
| 354 | } |
| 355 | |
| 356 | |
| 357 | /* Reset and setup CD186x chip */ |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 358 | static int sx_init_CD186x(struct specialix_board *bp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | { |
| 360 | unsigned long flags; |
| 361 | int scaler; |
| 362 | int rv = 1; |
| 363 | |
| 364 | func_enter(); |
| 365 | sx_wait_CCR_off(bp); /* Wait for CCR ready */ |
| 366 | spin_lock_irqsave(&bp->lock, flags); |
| 367 | sx_out_off(bp, CD186x_CCR, CCR_HARDRESET); /* Reset CD186x chip */ |
| 368 | spin_unlock_irqrestore(&bp->lock, flags); |
Jiri Slaby | 3e98cee | 2007-07-17 04:05:19 -0700 | [diff] [blame] | 369 | msleep(50); /* Delay 0.05 sec */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | spin_lock_irqsave(&bp->lock, flags); |
| 371 | sx_out_off(bp, CD186x_GIVR, SX_ID); /* Set ID for this chip */ |
| 372 | sx_out_off(bp, CD186x_GICR, 0); /* Clear all bits */ |
| 373 | sx_out_off(bp, CD186x_PILR1, SX_ACK_MINT); /* Prio for modem intr */ |
| 374 | sx_out_off(bp, CD186x_PILR2, SX_ACK_TINT); /* Prio for transmitter intr */ |
| 375 | sx_out_off(bp, CD186x_PILR3, SX_ACK_RINT); /* Prio for receiver intr */ |
| 376 | /* Set RegAckEn */ |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 377 | sx_out_off(bp, CD186x_SRCR, sx_in(bp, CD186x_SRCR) | SRCR_REGACKEN); |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 378 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | /* Setting up prescaler. We need 4 ticks per 1 ms */ |
| 380 | scaler = SX_OSCFREQ/SPECIALIX_TPS; |
| 381 | |
| 382 | sx_out_off(bp, CD186x_PPRH, scaler >> 8); |
| 383 | sx_out_off(bp, CD186x_PPRL, scaler & 0xff); |
| 384 | spin_unlock_irqrestore(&bp->lock, flags); |
| 385 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 386 | if (!sx_set_irq(bp)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | /* Figure out how to pass this along... */ |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 388 | printk(KERN_ERR "Cannot set irq to %d.\n", bp->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | rv = 0; |
| 390 | } |
| 391 | |
| 392 | func_exit(); |
| 393 | return rv; |
| 394 | } |
| 395 | |
| 396 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 397 | static int read_cross_byte(struct specialix_board *bp, int reg, int bit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | { |
| 399 | int i; |
| 400 | int t; |
| 401 | unsigned long flags; |
| 402 | |
| 403 | spin_lock_irqsave(&bp->lock, flags); |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 404 | for (i = 0, t = 0; i < 8; i++) { |
| 405 | sx_out_off(bp, CD186x_CAR, i); |
| 406 | if (sx_in_off(bp, reg) & bit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | t |= 1 << i; |
| 408 | } |
| 409 | spin_unlock_irqrestore(&bp->lock, flags); |
| 410 | |
| 411 | return t; |
| 412 | } |
| 413 | |
| 414 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | /* Main probing routine, also sets irq. */ |
| 416 | static int sx_probe(struct specialix_board *bp) |
| 417 | { |
| 418 | unsigned char val1, val2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | int rev; |
| 420 | int chip; |
| 421 | |
| 422 | func_enter(); |
| 423 | |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 424 | if (sx_request_io_range(bp)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | func_exit(); |
| 426 | return 1; |
| 427 | } |
| 428 | |
| 429 | /* Are the I/O ports here ? */ |
| 430 | sx_out_off(bp, CD186x_PPRL, 0x5a); |
Alan Cox | d2fbd0f | 2008-07-22 11:17:16 +0100 | [diff] [blame] | 431 | udelay(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | val1 = sx_in_off(bp, CD186x_PPRL); |
| 433 | |
| 434 | sx_out_off(bp, CD186x_PPRL, 0xa5); |
Alan Cox | d2fbd0f | 2008-07-22 11:17:16 +0100 | [diff] [blame] | 435 | udelay(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | val2 = sx_in_off(bp, CD186x_PPRL); |
| 437 | |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 438 | |
Alan Cox | d2fbd0f | 2008-07-22 11:17:16 +0100 | [diff] [blame] | 439 | if (val1 != 0x5a || val2 != 0xa5) { |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 440 | printk(KERN_INFO |
| 441 | "sx%d: specialix IO8+ Board at 0x%03x not found.\n", |
| 442 | board_No(bp), bp->base); |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 443 | sx_release_io_range(bp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | func_exit(); |
| 445 | return 1; |
| 446 | } |
| 447 | |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 448 | /* Check the DSR lines that Specialix uses as board |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | identification */ |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 450 | val1 = read_cross_byte(bp, CD186x_MSVR, MSVR_DSR); |
| 451 | val2 = read_cross_byte(bp, CD186x_MSVR, MSVR_RTS); |
| 452 | dprintk(SX_DEBUG_INIT, |
| 453 | "sx%d: DSR lines are: %02x, rts lines are: %02x\n", |
| 454 | board_No(bp), val1, val2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | |
| 456 | /* They managed to switch the bit order between the docs and |
| 457 | the IO8+ card. The new PCI card now conforms to old docs. |
| 458 | They changed the PCI docs to reflect the situation on the |
| 459 | old card. */ |
| 460 | val2 = (bp->flags & SX_BOARD_IS_PCI)?0x4d : 0xb2; |
| 461 | if (val1 != val2) { |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 462 | printk(KERN_INFO |
| 463 | "sx%d: specialix IO8+ ID %02x at 0x%03x not found (%02x).\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | board_No(bp), val2, bp->base, val1); |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 465 | sx_release_io_range(bp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | func_exit(); |
| 467 | return 1; |
| 468 | } |
| 469 | |
| 470 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | /* Reset CD186x again */ |
| 472 | if (!sx_init_CD186x(bp)) { |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 473 | sx_release_io_range(bp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | func_exit(); |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 475 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | sx_request_io_range(bp); |
| 479 | bp->flags |= SX_BOARD_PRESENT; |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 480 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | /* Chip revcode pkgtype |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 482 | GFRCR SRCR bit 7 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | CD180 rev B 0x81 0 |
| 484 | CD180 rev C 0x82 0 |
| 485 | CD1864 rev A 0x82 1 |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 486 | CD1865 rev A 0x83 1 -- Do not use!!! Does not work. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | CD1865 rev B 0x84 1 |
| 488 | -- Thanks to Gwen Wang, Cirrus Logic. |
| 489 | */ |
| 490 | |
| 491 | switch (sx_in_off(bp, CD186x_GFRCR)) { |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 492 | case 0x82: |
| 493 | chip = 1864; |
| 494 | rev = 'A'; |
| 495 | break; |
| 496 | case 0x83: |
| 497 | chip = 1865; |
| 498 | rev = 'A'; |
| 499 | break; |
| 500 | case 0x84: |
| 501 | chip = 1865; |
| 502 | rev = 'B'; |
| 503 | break; |
| 504 | case 0x85: |
| 505 | chip = 1865; |
| 506 | rev = 'C'; |
| 507 | break; /* Does not exist at this time */ |
| 508 | default: |
| 509 | chip = -1; |
| 510 | rev = 'x'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | } |
| 512 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 513 | dprintk(SX_DEBUG_INIT, " GFCR = 0x%02x\n", sx_in_off(bp, CD186x_GFRCR)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 515 | printk(KERN_INFO |
| 516 | "sx%d: specialix IO8+ board detected at 0x%03x, IRQ %d, CD%d Rev. %c.\n", |
| 517 | board_No(bp), bp->base, bp->irq, chip, rev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | |
| 519 | func_exit(); |
| 520 | return 0; |
| 521 | } |
| 522 | |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 523 | /* |
| 524 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | * Interrupt processing routines. |
| 526 | * */ |
| 527 | |
Alan Cox | d2fbd0f | 2008-07-22 11:17:16 +0100 | [diff] [blame] | 528 | static struct specialix_port *sx_get_port(struct specialix_board *bp, |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 529 | unsigned char const *what) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | { |
| 531 | unsigned char channel; |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 532 | struct specialix_port *port = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | |
| 534 | channel = sx_in(bp, CD186x_GICR) >> GICR_CHAN_OFF; |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 535 | dprintk(SX_DEBUG_CHAN, "channel: %d\n", channel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | if (channel < CD186x_NCH) { |
| 537 | port = &sx_port[board_No(bp) * SX_NPORT + channel]; |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 538 | dprintk(SX_DEBUG_CHAN, "port: %d %p flags: 0x%lx\n", |
| 539 | board_No(bp) * SX_NPORT + channel, port, |
| 540 | port->port.flags & ASYNC_INITIALIZED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 542 | if (port->port.flags & ASYNC_INITIALIZED) { |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 543 | dprintk(SX_DEBUG_CHAN, "port: %d %p\n", channel, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | func_exit(); |
| 545 | return port; |
| 546 | } |
| 547 | } |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 548 | printk(KERN_INFO "sx%d: %s interrupt from invalid port %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | board_No(bp), what, channel); |
| 550 | return NULL; |
| 551 | } |
| 552 | |
| 553 | |
Alan Cox | d2fbd0f | 2008-07-22 11:17:16 +0100 | [diff] [blame] | 554 | static void sx_receive_exc(struct specialix_board *bp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | { |
| 556 | struct specialix_port *port; |
| 557 | struct tty_struct *tty; |
| 558 | unsigned char status; |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 559 | unsigned char ch, flag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | |
| 561 | func_enter(); |
| 562 | |
| 563 | port = sx_get_port(bp, "Receive"); |
| 564 | if (!port) { |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 565 | dprintk(SX_DEBUG_RX, "Hmm, couldn't find port.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | func_exit(); |
| 567 | return; |
| 568 | } |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 569 | tty = port->port.tty; |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 570 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | status = sx_in(bp, CD186x_RCSR); |
| 572 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 573 | dprintk(SX_DEBUG_RX, "status: 0x%x\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | if (status & RCSR_OE) { |
| 575 | port->overrun++; |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 576 | dprintk(SX_DEBUG_FIFO, |
| 577 | "sx%d: port %d: Overrun. Total %ld overruns.\n", |
| 578 | board_No(bp), port_No(port), port->overrun); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | } |
| 580 | status &= port->mark_mask; |
| 581 | |
| 582 | /* This flip buffer check needs to be below the reading of the |
| 583 | status register to reset the chip's IRQ.... */ |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 584 | if (tty_buffer_request_room(tty, 1) == 0) { |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 585 | dprintk(SX_DEBUG_FIFO, |
| 586 | "sx%d: port %d: Working around flip buffer overflow.\n", |
| 587 | board_No(bp), port_No(port)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | func_exit(); |
| 589 | return; |
| 590 | } |
| 591 | |
| 592 | ch = sx_in(bp, CD186x_RDR); |
| 593 | if (!status) { |
| 594 | func_exit(); |
| 595 | return; |
| 596 | } |
| 597 | if (status & RCSR_TOUT) { |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 598 | printk(KERN_INFO |
| 599 | "sx%d: port %d: Receiver timeout. Hardware problems ?\n", |
| 600 | board_No(bp), port_No(port)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | func_exit(); |
| 602 | return; |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 603 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | } else if (status & RCSR_BREAK) { |
| 605 | dprintk(SX_DEBUG_RX, "sx%d: port %d: Handling break...\n", |
| 606 | board_No(bp), port_No(port)); |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 607 | flag = TTY_BREAK; |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 608 | if (port->port.flags & ASYNC_SAK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | do_SAK(tty); |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 610 | |
| 611 | } else if (status & RCSR_PE) |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 612 | flag = TTY_PARITY; |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 613 | |
| 614 | else if (status & RCSR_FE) |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 615 | flag = TTY_FRAME; |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 616 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | else if (status & RCSR_OE) |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 618 | flag = TTY_OVERRUN; |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 619 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | else |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 621 | flag = TTY_NORMAL; |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 622 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 623 | if (tty_insert_flip_char(tty, ch, flag)) |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 624 | tty_flip_buffer_push(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | func_exit(); |
| 626 | } |
| 627 | |
| 628 | |
Alan Cox | d2fbd0f | 2008-07-22 11:17:16 +0100 | [diff] [blame] | 629 | static void sx_receive(struct specialix_board *bp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | { |
| 631 | struct specialix_port *port; |
| 632 | struct tty_struct *tty; |
| 633 | unsigned char count; |
| 634 | |
| 635 | func_enter(); |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 636 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 637 | port = sx_get_port(bp, "Receive"); |
| 638 | if (port == NULL) { |
| 639 | dprintk(SX_DEBUG_RX, "Hmm, couldn't find port.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | func_exit(); |
| 641 | return; |
| 642 | } |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 643 | tty = port->port.tty; |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 644 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | count = sx_in(bp, CD186x_RDCR); |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 646 | dprintk(SX_DEBUG_RX, "port: %p: count: %d\n", port, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | port->hits[count > 8 ? 9 : count]++; |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 648 | |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 649 | tty_buffer_request_room(tty, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 651 | while (count--) |
| 652 | tty_insert_flip_char(tty, sx_in(bp, CD186x_RDR), TTY_NORMAL); |
| 653 | tty_flip_buffer_push(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | func_exit(); |
| 655 | } |
| 656 | |
| 657 | |
Alan Cox | d2fbd0f | 2008-07-22 11:17:16 +0100 | [diff] [blame] | 658 | static void sx_transmit(struct specialix_board *bp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | { |
| 660 | struct specialix_port *port; |
| 661 | struct tty_struct *tty; |
| 662 | unsigned char count; |
| 663 | |
| 664 | func_enter(); |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 665 | port = sx_get_port(bp, "Transmit"); |
| 666 | if (port == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | func_exit(); |
| 668 | return; |
| 669 | } |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 670 | dprintk(SX_DEBUG_TX, "port: %p\n", port); |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 671 | tty = port->port.tty; |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 672 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | if (port->IER & IER_TXEMPTY) { |
| 674 | /* FIFO drained */ |
| 675 | sx_out(bp, CD186x_CAR, port_No(port)); |
| 676 | port->IER &= ~IER_TXEMPTY; |
| 677 | sx_out(bp, CD186x_IER, port->IER); |
| 678 | func_exit(); |
| 679 | return; |
| 680 | } |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 681 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | if ((port->xmit_cnt <= 0 && !port->break_length) |
| 683 | || tty->stopped || tty->hw_stopped) { |
| 684 | sx_out(bp, CD186x_CAR, port_No(port)); |
| 685 | port->IER &= ~IER_TXRDY; |
| 686 | sx_out(bp, CD186x_IER, port->IER); |
| 687 | func_exit(); |
| 688 | return; |
| 689 | } |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 690 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | if (port->break_length) { |
| 692 | if (port->break_length > 0) { |
| 693 | if (port->COR2 & COR2_ETC) { |
| 694 | sx_out(bp, CD186x_TDR, CD186x_C_ESC); |
| 695 | sx_out(bp, CD186x_TDR, CD186x_C_SBRK); |
| 696 | port->COR2 &= ~COR2_ETC; |
| 697 | } |
| 698 | count = min_t(int, port->break_length, 0xff); |
| 699 | sx_out(bp, CD186x_TDR, CD186x_C_ESC); |
| 700 | sx_out(bp, CD186x_TDR, CD186x_C_DELAY); |
| 701 | sx_out(bp, CD186x_TDR, count); |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 702 | port->break_length -= count; |
| 703 | if (port->break_length == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | port->break_length--; |
| 705 | } else { |
| 706 | sx_out(bp, CD186x_TDR, CD186x_C_ESC); |
| 707 | sx_out(bp, CD186x_TDR, CD186x_C_EBRK); |
| 708 | sx_out(bp, CD186x_COR2, port->COR2); |
| 709 | sx_wait_CCR(bp); |
| 710 | sx_out(bp, CD186x_CCR, CCR_CORCHG2); |
| 711 | port->break_length = 0; |
| 712 | } |
| 713 | |
| 714 | func_exit(); |
| 715 | return; |
| 716 | } |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 717 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | count = CD186x_NFIFO; |
| 719 | do { |
| 720 | sx_out(bp, CD186x_TDR, port->xmit_buf[port->xmit_tail++]); |
| 721 | port->xmit_tail = port->xmit_tail & (SERIAL_XMIT_SIZE-1); |
| 722 | if (--port->xmit_cnt <= 0) |
| 723 | break; |
| 724 | } while (--count > 0); |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 725 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | if (port->xmit_cnt <= 0) { |
| 727 | sx_out(bp, CD186x_CAR, port_No(port)); |
| 728 | port->IER &= ~IER_TXRDY; |
| 729 | sx_out(bp, CD186x_IER, port->IER); |
| 730 | } |
| 731 | if (port->xmit_cnt <= port->wakeup_chars) |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 732 | tty_wakeup(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | |
| 734 | func_exit(); |
| 735 | } |
| 736 | |
| 737 | |
Alan Cox | d2fbd0f | 2008-07-22 11:17:16 +0100 | [diff] [blame] | 738 | static void sx_check_modem(struct specialix_board *bp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | { |
| 740 | struct specialix_port *port; |
| 741 | struct tty_struct *tty; |
| 742 | unsigned char mcr; |
| 743 | int msvr_cd; |
| 744 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 745 | dprintk(SX_DEBUG_SIGNALS, "Modem intr. "); |
| 746 | port = sx_get_port(bp, "Modem"); |
| 747 | if (port == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | return; |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 749 | |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 750 | tty = port->port.tty; |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 751 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | mcr = sx_in(bp, CD186x_MCR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | |
| 754 | if ((mcr & MCR_CDCHG)) { |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 755 | dprintk(SX_DEBUG_SIGNALS, "CD just changed... "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | msvr_cd = sx_in(bp, CD186x_MSVR) & MSVR_CD; |
| 757 | if (msvr_cd) { |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 758 | dprintk(SX_DEBUG_SIGNALS, "Waking up guys in open.\n"); |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 759 | wake_up_interruptible(&port->port.open_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | } else { |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 761 | dprintk(SX_DEBUG_SIGNALS, "Sending HUP.\n"); |
Jiri Slaby | d0d4e1c | 2008-02-07 00:16:39 -0800 | [diff] [blame] | 762 | tty_hangup(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | } |
| 764 | } |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 765 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | #ifdef SPECIALIX_BRAIN_DAMAGED_CTS |
| 767 | if (mcr & MCR_CTSCHG) { |
| 768 | if (sx_in(bp, CD186x_MSVR) & MSVR_CTS) { |
| 769 | tty->hw_stopped = 0; |
| 770 | port->IER |= IER_TXRDY; |
| 771 | if (port->xmit_cnt <= port->wakeup_chars) |
Jiri Slaby | d0d4e1c | 2008-02-07 00:16:39 -0800 | [diff] [blame] | 772 | tty_wakeup(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | } else { |
| 774 | tty->hw_stopped = 1; |
| 775 | port->IER &= ~IER_TXRDY; |
| 776 | } |
| 777 | sx_out(bp, CD186x_IER, port->IER); |
| 778 | } |
| 779 | if (mcr & MCR_DSSXHG) { |
| 780 | if (sx_in(bp, CD186x_MSVR) & MSVR_DSR) { |
| 781 | tty->hw_stopped = 0; |
| 782 | port->IER |= IER_TXRDY; |
| 783 | if (port->xmit_cnt <= port->wakeup_chars) |
Jiri Slaby | d0d4e1c | 2008-02-07 00:16:39 -0800 | [diff] [blame] | 784 | tty_wakeup(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | } else { |
| 786 | tty->hw_stopped = 1; |
| 787 | port->IER &= ~IER_TXRDY; |
| 788 | } |
| 789 | sx_out(bp, CD186x_IER, port->IER); |
| 790 | } |
| 791 | #endif /* SPECIALIX_BRAIN_DAMAGED_CTS */ |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 792 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | /* Clear change bits */ |
| 794 | sx_out(bp, CD186x_MCR, 0); |
| 795 | } |
| 796 | |
| 797 | |
| 798 | /* The main interrupt processing routine */ |
Jeff Garzik | a6f97b2 | 2007-10-31 05:20:49 -0400 | [diff] [blame] | 799 | static irqreturn_t sx_interrupt(int dummy, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | { |
| 801 | unsigned char status; |
| 802 | unsigned char ack; |
Jeff Garzik | a6f97b2 | 2007-10-31 05:20:49 -0400 | [diff] [blame] | 803 | struct specialix_board *bp = dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | unsigned long loop = 0; |
| 805 | int saved_reg; |
| 806 | unsigned long flags; |
| 807 | |
| 808 | func_enter(); |
| 809 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | spin_lock_irqsave(&bp->lock, flags); |
| 811 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 812 | dprintk(SX_DEBUG_FLOW, "enter %s port %d room: %ld\n", __func__, |
| 813 | port_No(sx_get_port(bp, "INT")), |
| 814 | SERIAL_XMIT_SIZE - sx_get_port(bp, "ITN")->xmit_cnt - 1); |
Jeff Garzik | c7bec5a | 2006-10-06 15:00:58 -0400 | [diff] [blame] | 815 | if (!(bp->flags & SX_BOARD_ACTIVE)) { |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 816 | dprintk(SX_DEBUG_IRQ, "sx: False interrupt. irq %d.\n", |
| 817 | bp->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | spin_unlock_irqrestore(&bp->lock, flags); |
| 819 | func_exit(); |
| 820 | return IRQ_NONE; |
| 821 | } |
| 822 | |
| 823 | saved_reg = bp->reg; |
| 824 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 825 | while (++loop < 16) { |
| 826 | status = sx_in(bp, CD186x_SRSR) & |
| 827 | (SRSR_RREQint | SRSR_TREQint | SRSR_MREQint); |
| 828 | if (status == 0) |
| 829 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | if (status & SRSR_RREQint) { |
| 831 | ack = sx_in(bp, CD186x_RRAR); |
| 832 | |
| 833 | if (ack == (SX_ID | GIVR_IT_RCV)) |
| 834 | sx_receive(bp); |
| 835 | else if (ack == (SX_ID | GIVR_IT_REXC)) |
| 836 | sx_receive_exc(bp); |
| 837 | else |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 838 | printk(KERN_ERR |
| 839 | "sx%d: status: 0x%x Bad receive ack 0x%02x.\n", |
| 840 | board_No(bp), status, ack); |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 841 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | } else if (status & SRSR_TREQint) { |
| 843 | ack = sx_in(bp, CD186x_TRAR); |
| 844 | |
| 845 | if (ack == (SX_ID | GIVR_IT_TX)) |
| 846 | sx_transmit(bp); |
| 847 | else |
| 848 | printk(KERN_ERR "sx%d: status: 0x%x Bad transmit ack 0x%02x. port: %d\n", |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 849 | board_No(bp), status, ack, |
| 850 | port_No(sx_get_port(bp, "Int"))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | } else if (status & SRSR_MREQint) { |
| 852 | ack = sx_in(bp, CD186x_MRAR); |
| 853 | |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 854 | if (ack == (SX_ID | GIVR_IT_MODEM)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | sx_check_modem(bp); |
| 856 | else |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 857 | printk(KERN_ERR |
| 858 | "sx%d: status: 0x%x Bad modem ack 0x%02x.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | board_No(bp), status, ack); |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 860 | |
| 861 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | |
| 863 | sx_out(bp, CD186x_EOIR, 0); /* Mark end of interrupt */ |
| 864 | } |
| 865 | bp->reg = saved_reg; |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 866 | outb(bp->reg, bp->base + SX_ADDR_REG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | spin_unlock_irqrestore(&bp->lock, flags); |
| 868 | func_exit(); |
| 869 | return IRQ_HANDLED; |
| 870 | } |
| 871 | |
| 872 | |
| 873 | /* |
| 874 | * Routines for open & close processing. |
| 875 | */ |
| 876 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 877 | static void turn_ints_off(struct specialix_board *bp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | { |
| 879 | unsigned long flags; |
| 880 | |
| 881 | func_enter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | spin_lock_irqsave(&bp->lock, flags); |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 883 | (void) sx_in_off(bp, 0); /* Turn off interrupts. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | spin_unlock_irqrestore(&bp->lock, flags); |
| 885 | |
| 886 | func_exit(); |
| 887 | } |
| 888 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 889 | static void turn_ints_on(struct specialix_board *bp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | { |
| 891 | unsigned long flags; |
| 892 | |
| 893 | func_enter(); |
| 894 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | spin_lock_irqsave(&bp->lock, flags); |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 896 | (void) sx_in(bp, 0); /* Turn ON interrupts. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | spin_unlock_irqrestore(&bp->lock, flags); |
| 898 | |
| 899 | func_exit(); |
| 900 | } |
| 901 | |
| 902 | |
| 903 | /* Called with disabled interrupts */ |
Alan Cox | d2fbd0f | 2008-07-22 11:17:16 +0100 | [diff] [blame] | 904 | static int sx_setup_board(struct specialix_board *bp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | { |
| 906 | int error; |
| 907 | |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 908 | if (bp->flags & SX_BOARD_ACTIVE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | return 0; |
| 910 | |
| 911 | if (bp->flags & SX_BOARD_IS_PCI) |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 912 | error = request_irq(bp->irq, sx_interrupt, |
| 913 | IRQF_DISABLED | IRQF_SHARED, "specialix IO8+", bp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | else |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 915 | error = request_irq(bp->irq, sx_interrupt, |
| 916 | IRQF_DISABLED, "specialix IO8+", bp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 918 | if (error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | return error; |
| 920 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 921 | turn_ints_on(bp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | bp->flags |= SX_BOARD_ACTIVE; |
| 923 | |
| 924 | return 0; |
| 925 | } |
| 926 | |
| 927 | |
| 928 | /* Called with disabled interrupts */ |
Alan Cox | d2fbd0f | 2008-07-22 11:17:16 +0100 | [diff] [blame] | 929 | static void sx_shutdown_board(struct specialix_board *bp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | { |
| 931 | func_enter(); |
| 932 | |
| 933 | if (!(bp->flags & SX_BOARD_ACTIVE)) { |
| 934 | func_exit(); |
| 935 | return; |
| 936 | } |
| 937 | |
| 938 | bp->flags &= ~SX_BOARD_ACTIVE; |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 939 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 940 | dprintk(SX_DEBUG_IRQ, "Freeing IRQ%d for board %d.\n", |
| 941 | bp->irq, board_No(bp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | free_irq(bp->irq, bp); |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 943 | turn_ints_off(bp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | func_exit(); |
| 945 | } |
| 946 | |
Alan Cox | d2fbd0f | 2008-07-22 11:17:16 +0100 | [diff] [blame] | 947 | static unsigned int sx_crtscts(struct tty_struct *tty) |
| 948 | { |
| 949 | if (sx_rtscts) |
| 950 | return C_CRTSCTS(tty); |
| 951 | return 1; |
| 952 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | |
| 954 | /* |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 955 | * Setting up port characteristics. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | * Must be called with disabled interrupts |
| 957 | */ |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 958 | static void sx_change_speed(struct specialix_board *bp, |
| 959 | struct specialix_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | { |
| 961 | struct tty_struct *tty; |
| 962 | unsigned long baud; |
| 963 | long tmp; |
| 964 | unsigned char cor1 = 0, cor3 = 0; |
| 965 | unsigned char mcor1 = 0, mcor2 = 0; |
| 966 | static unsigned long again; |
| 967 | unsigned long flags; |
| 968 | |
| 969 | func_enter(); |
| 970 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 971 | tty = port->port.tty; |
| 972 | if (!tty || !tty->termios) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | func_exit(); |
| 974 | return; |
| 975 | } |
| 976 | |
| 977 | port->IER = 0; |
| 978 | port->COR2 = 0; |
| 979 | /* Select port on the board */ |
| 980 | spin_lock_irqsave(&bp->lock, flags); |
| 981 | sx_out(bp, CD186x_CAR, port_No(port)); |
| 982 | |
| 983 | /* The Specialix board doens't implement the RTS lines. |
| 984 | They are used to set the IRQ level. Don't touch them. */ |
Alan Cox | d2fbd0f | 2008-07-22 11:17:16 +0100 | [diff] [blame] | 985 | if (sx_crtscts(tty)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | port->MSVR = MSVR_DTR | (sx_in(bp, CD186x_MSVR) & MSVR_RTS); |
| 987 | else |
| 988 | port->MSVR = (sx_in(bp, CD186x_MSVR) & MSVR_RTS); |
| 989 | spin_unlock_irqrestore(&bp->lock, flags); |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 990 | dprintk(SX_DEBUG_TERMIOS, "sx: got MSVR=%02x.\n", port->MSVR); |
Alan Cox | 67cc016 | 2006-09-29 02:01:39 -0700 | [diff] [blame] | 991 | baud = tty_get_baud_rate(tty); |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 992 | |
Alan Cox | 67cc016 | 2006-09-29 02:01:39 -0700 | [diff] [blame] | 993 | if (baud == 38400) { |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 994 | if ((port->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI) |
Adrian Bunk | a4bb2cf | 2006-10-17 00:10:00 -0700 | [diff] [blame] | 995 | baud = 57600; |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 996 | if ((port->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI) |
Adrian Bunk | a4bb2cf | 2006-10-17 00:10:00 -0700 | [diff] [blame] | 997 | baud = 115200; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | } |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 999 | |
Alan Cox | 67cc016 | 2006-09-29 02:01:39 -0700 | [diff] [blame] | 1000 | if (!baud) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | /* Drop DTR & exit */ |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1002 | dprintk(SX_DEBUG_TERMIOS, "Dropping DTR... Hmm....\n"); |
Alan Cox | d2fbd0f | 2008-07-22 11:17:16 +0100 | [diff] [blame] | 1003 | if (!sx_crtscts(tty)) { |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1004 | port->MSVR &= ~MSVR_DTR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | spin_lock_irqsave(&bp->lock, flags); |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1006 | sx_out(bp, CD186x_MSVR, port->MSVR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | spin_unlock_irqrestore(&bp->lock, flags); |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1008 | } else |
| 1009 | dprintk(SX_DEBUG_TERMIOS, "Can't drop DTR: no DTR.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | return; |
| 1011 | } else { |
| 1012 | /* Set DTR on */ |
Alan Cox | d2fbd0f | 2008-07-22 11:17:16 +0100 | [diff] [blame] | 1013 | if (!sx_crtscts(tty)) |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1014 | port->MSVR |= MSVR_DTR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | } |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1016 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | /* |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1018 | * Now we must calculate some speed depended things |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | */ |
| 1020 | |
| 1021 | /* Set baud rate for port */ |
| 1022 | tmp = port->custom_divisor ; |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1023 | if (tmp) |
| 1024 | printk(KERN_INFO |
| 1025 | "sx%d: Using custom baud rate divisor %ld. \n" |
| 1026 | "This is an untested option, please be careful.\n", |
| 1027 | port_No(port), tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | else |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1029 | tmp = (((SX_OSCFREQ + baud/2) / baud + CD186x_TPC/2) / |
| 1030 | CD186x_TPC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1032 | if (tmp < 0x10 && time_before(again, jiffies)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | again = jiffies + HZ * 60; |
| 1034 | /* Page 48 of version 2.0 of the CL-CD1865 databook */ |
| 1035 | if (tmp >= 12) { |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1036 | printk(KERN_INFO "sx%d: Baud rate divisor is %ld. \n" |
| 1037 | "Performance degradation is possible.\n" |
| 1038 | "Read specialix.txt for more info.\n", |
| 1039 | port_No(port), tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | } else { |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1041 | printk(KERN_INFO "sx%d: Baud rate divisor is %ld. \n" |
| 1042 | "Warning: overstressing Cirrus chip. This might not work.\n" |
| 1043 | "Read specialix.txt for more info.\n", port_No(port), tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | } |
| 1045 | } |
| 1046 | spin_lock_irqsave(&bp->lock, flags); |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1047 | sx_out(bp, CD186x_RBPRH, (tmp >> 8) & 0xff); |
| 1048 | sx_out(bp, CD186x_TBPRH, (tmp >> 8) & 0xff); |
| 1049 | sx_out(bp, CD186x_RBPRL, tmp & 0xff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | sx_out(bp, CD186x_TBPRL, tmp & 0xff); |
| 1051 | spin_unlock_irqrestore(&bp->lock, flags); |
Adrian Bunk | a4bb2cf | 2006-10-17 00:10:00 -0700 | [diff] [blame] | 1052 | if (port->custom_divisor) |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1053 | baud = (SX_OSCFREQ + port->custom_divisor/2) / |
| 1054 | port->custom_divisor; |
Adrian Bunk | a4bb2cf | 2006-10-17 00:10:00 -0700 | [diff] [blame] | 1055 | baud = (baud + 5) / 10; /* Estimated CPS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | |
| 1057 | /* Two timer ticks seems enough to wakeup something like SLIP driver */ |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1058 | tmp = ((baud + HZ/2) / HZ) * 2 - CD186x_NFIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | port->wakeup_chars = (tmp < 0) ? 0 : ((tmp >= SERIAL_XMIT_SIZE) ? |
| 1060 | SERIAL_XMIT_SIZE - 1 : tmp); |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1061 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | /* Receiver timeout will be transmission time for 1.5 chars */ |
| 1063 | tmp = (SPECIALIX_TPS + SPECIALIX_TPS/2 + baud/2) / baud; |
| 1064 | tmp = (tmp > 0xff) ? 0xff : tmp; |
| 1065 | spin_lock_irqsave(&bp->lock, flags); |
| 1066 | sx_out(bp, CD186x_RTPR, tmp); |
| 1067 | spin_unlock_irqrestore(&bp->lock, flags); |
| 1068 | switch (C_CSIZE(tty)) { |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1069 | case CS5: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | cor1 |= COR1_5BITS; |
| 1071 | break; |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1072 | case CS6: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | cor1 |= COR1_6BITS; |
| 1074 | break; |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1075 | case CS7: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | cor1 |= COR1_7BITS; |
| 1077 | break; |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1078 | case CS8: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | cor1 |= COR1_8BITS; |
| 1080 | break; |
| 1081 | } |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1082 | |
| 1083 | if (C_CSTOPB(tty)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | cor1 |= COR1_2SB; |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1085 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | cor1 |= COR1_IGNORE; |
| 1087 | if (C_PARENB(tty)) { |
| 1088 | cor1 |= COR1_NORMPAR; |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1089 | if (C_PARODD(tty)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | cor1 |= COR1_ODDP; |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1091 | if (I_INPCK(tty)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | cor1 &= ~COR1_IGNORE; |
| 1093 | } |
| 1094 | /* Set marking of some errors */ |
| 1095 | port->mark_mask = RCSR_OE | RCSR_TOUT; |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1096 | if (I_INPCK(tty)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | port->mark_mask |= RCSR_FE | RCSR_PE; |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1098 | if (I_BRKINT(tty) || I_PARMRK(tty)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | port->mark_mask |= RCSR_BREAK; |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1100 | if (I_IGNPAR(tty)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | port->mark_mask &= ~(RCSR_FE | RCSR_PE); |
| 1102 | if (I_IGNBRK(tty)) { |
| 1103 | port->mark_mask &= ~RCSR_BREAK; |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1104 | if (I_IGNPAR(tty)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | /* Real raw mode. Ignore all */ |
| 1106 | port->mark_mask &= ~RCSR_OE; |
| 1107 | } |
| 1108 | /* Enable Hardware Flow Control */ |
| 1109 | if (C_CRTSCTS(tty)) { |
| 1110 | #ifdef SPECIALIX_BRAIN_DAMAGED_CTS |
| 1111 | port->IER |= IER_DSR | IER_CTS; |
| 1112 | mcor1 |= MCOR1_DSRZD | MCOR1_CTSZD; |
| 1113 | mcor2 |= MCOR2_DSROD | MCOR2_CTSOD; |
| 1114 | spin_lock_irqsave(&bp->lock, flags); |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1115 | tty->hw_stopped = !(sx_in(bp, CD186x_MSVR) & |
| 1116 | (MSVR_CTS|MSVR_DSR)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | spin_unlock_irqrestore(&bp->lock, flags); |
| 1118 | #else |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1119 | port->COR2 |= COR2_CTSAE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | #endif |
| 1121 | } |
| 1122 | /* Enable Software Flow Control. FIXME: I'm not sure about this */ |
| 1123 | /* Some people reported that it works, but I still doubt it */ |
| 1124 | if (I_IXON(tty)) { |
| 1125 | port->COR2 |= COR2_TXIBE; |
| 1126 | cor3 |= (COR3_FCT | COR3_SCDE); |
| 1127 | if (I_IXANY(tty)) |
| 1128 | port->COR2 |= COR2_IXM; |
| 1129 | spin_lock_irqsave(&bp->lock, flags); |
| 1130 | sx_out(bp, CD186x_SCHR1, START_CHAR(tty)); |
| 1131 | sx_out(bp, CD186x_SCHR2, STOP_CHAR(tty)); |
| 1132 | sx_out(bp, CD186x_SCHR3, START_CHAR(tty)); |
| 1133 | sx_out(bp, CD186x_SCHR4, STOP_CHAR(tty)); |
| 1134 | spin_unlock_irqrestore(&bp->lock, flags); |
| 1135 | } |
| 1136 | if (!C_CLOCAL(tty)) { |
| 1137 | /* Enable CD check */ |
| 1138 | port->IER |= IER_CD; |
| 1139 | mcor1 |= MCOR1_CDZD; |
| 1140 | mcor2 |= MCOR2_CDOD; |
| 1141 | } |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1142 | |
| 1143 | if (C_CREAD(tty)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1144 | /* Enable receiver */ |
| 1145 | port->IER |= IER_RXD; |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | /* Set input FIFO size (1-8 bytes) */ |
| 1148 | cor3 |= sx_rxfifo; |
| 1149 | /* Setting up CD186x channel registers */ |
| 1150 | spin_lock_irqsave(&bp->lock, flags); |
| 1151 | sx_out(bp, CD186x_COR1, cor1); |
| 1152 | sx_out(bp, CD186x_COR2, port->COR2); |
| 1153 | sx_out(bp, CD186x_COR3, cor3); |
| 1154 | spin_unlock_irqrestore(&bp->lock, flags); |
| 1155 | /* Make CD186x know about registers change */ |
| 1156 | sx_wait_CCR(bp); |
| 1157 | spin_lock_irqsave(&bp->lock, flags); |
| 1158 | sx_out(bp, CD186x_CCR, CCR_CORCHG1 | CCR_CORCHG2 | CCR_CORCHG3); |
| 1159 | /* Setting up modem option registers */ |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1160 | dprintk(SX_DEBUG_TERMIOS, "Mcor1 = %02x, mcor2 = %02x.\n", |
| 1161 | mcor1, mcor2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | sx_out(bp, CD186x_MCOR1, mcor1); |
| 1163 | sx_out(bp, CD186x_MCOR2, mcor2); |
| 1164 | spin_unlock_irqrestore(&bp->lock, flags); |
| 1165 | /* Enable CD186x transmitter & receiver */ |
| 1166 | sx_wait_CCR(bp); |
| 1167 | spin_lock_irqsave(&bp->lock, flags); |
| 1168 | sx_out(bp, CD186x_CCR, CCR_TXEN | CCR_RXEN); |
| 1169 | /* Enable interrupts */ |
| 1170 | sx_out(bp, CD186x_IER, port->IER); |
| 1171 | /* And finally set the modem lines... */ |
| 1172 | sx_out(bp, CD186x_MSVR, port->MSVR); |
| 1173 | spin_unlock_irqrestore(&bp->lock, flags); |
| 1174 | |
| 1175 | func_exit(); |
| 1176 | } |
| 1177 | |
| 1178 | |
| 1179 | /* Must be called with interrupts enabled */ |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1180 | static int sx_setup_port(struct specialix_board *bp, |
| 1181 | struct specialix_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | { |
| 1183 | unsigned long flags; |
| 1184 | |
| 1185 | func_enter(); |
| 1186 | |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1187 | if (port->port.flags & ASYNC_INITIALIZED) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | func_exit(); |
| 1189 | return 0; |
| 1190 | } |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1191 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1192 | if (!port->xmit_buf) { |
| 1193 | /* We may sleep in get_zeroed_page() */ |
| 1194 | unsigned long tmp; |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1195 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1196 | tmp = get_zeroed_page(GFP_KERNEL); |
| 1197 | if (tmp == 0L) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | func_exit(); |
| 1199 | return -ENOMEM; |
| 1200 | } |
| 1201 | |
| 1202 | if (port->xmit_buf) { |
| 1203 | free_page(tmp); |
| 1204 | func_exit(); |
| 1205 | return -ERESTARTSYS; |
| 1206 | } |
| 1207 | port->xmit_buf = (unsigned char *) tmp; |
| 1208 | } |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1209 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | spin_lock_irqsave(&port->lock, flags); |
| 1211 | |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1212 | if (port->port.tty) |
| 1213 | clear_bit(TTY_IO_ERROR, &port->port.tty->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | |
| 1215 | port->xmit_cnt = port->xmit_head = port->xmit_tail = 0; |
| 1216 | sx_change_speed(bp, port); |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1217 | port->port.flags |= ASYNC_INITIALIZED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | |
| 1219 | spin_unlock_irqrestore(&port->lock, flags); |
| 1220 | |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1221 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | func_exit(); |
| 1223 | return 0; |
| 1224 | } |
| 1225 | |
| 1226 | |
| 1227 | /* Must be called with interrupts disabled */ |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1228 | static void sx_shutdown_port(struct specialix_board *bp, |
| 1229 | struct specialix_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | { |
| 1231 | struct tty_struct *tty; |
| 1232 | int i; |
| 1233 | unsigned long flags; |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1234 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | func_enter(); |
| 1236 | |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1237 | if (!(port->port.flags & ASYNC_INITIALIZED)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | func_exit(); |
| 1239 | return; |
| 1240 | } |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1241 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | if (sx_debug & SX_DEBUG_FIFO) { |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1243 | dprintk(SX_DEBUG_FIFO, |
| 1244 | "sx%d: port %d: %ld overruns, FIFO hits [ ", |
| 1245 | board_No(bp), port_No(port), port->overrun); |
| 1246 | for (i = 0; i < 10; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | dprintk(SX_DEBUG_FIFO, "%ld ", port->hits[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | dprintk(SX_DEBUG_FIFO, "].\n"); |
| 1249 | } |
| 1250 | |
| 1251 | if (port->xmit_buf) { |
| 1252 | free_page((unsigned long) port->xmit_buf); |
| 1253 | port->xmit_buf = NULL; |
| 1254 | } |
| 1255 | |
| 1256 | /* Select port */ |
| 1257 | spin_lock_irqsave(&bp->lock, flags); |
| 1258 | sx_out(bp, CD186x_CAR, port_No(port)); |
| 1259 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1260 | tty = port->port.tty; |
| 1261 | if (tty == NULL || C_HUPCL(tty)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | /* Drop DTR */ |
| 1263 | sx_out(bp, CD186x_MSVDTR, 0); |
| 1264 | } |
| 1265 | spin_unlock_irqrestore(&bp->lock, flags); |
| 1266 | /* Reset port */ |
| 1267 | sx_wait_CCR(bp); |
| 1268 | spin_lock_irqsave(&bp->lock, flags); |
| 1269 | sx_out(bp, CD186x_CCR, CCR_SOFTRESET); |
| 1270 | /* Disable all interrupts from this port */ |
| 1271 | port->IER = 0; |
| 1272 | sx_out(bp, CD186x_IER, port->IER); |
| 1273 | spin_unlock_irqrestore(&bp->lock, flags); |
| 1274 | if (tty) |
| 1275 | set_bit(TTY_IO_ERROR, &tty->flags); |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1276 | port->port.flags &= ~ASYNC_INITIALIZED; |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1277 | |
| 1278 | if (!bp->count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | sx_shutdown_board(bp); |
| 1280 | func_exit(); |
| 1281 | } |
| 1282 | |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1283 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1284 | static int block_til_ready(struct tty_struct *tty, struct file *filp, |
| 1285 | struct specialix_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | { |
| 1287 | DECLARE_WAITQUEUE(wait, current); |
| 1288 | struct specialix_board *bp = port_Board(port); |
| 1289 | int retval; |
| 1290 | int do_clocal = 0; |
| 1291 | int CD; |
| 1292 | unsigned long flags; |
| 1293 | |
| 1294 | func_enter(); |
| 1295 | |
| 1296 | /* |
| 1297 | * If the device is in the middle of being closed, then block |
| 1298 | * until it's done, and then try again. |
| 1299 | */ |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1300 | if (tty_hung_up_p(filp) || port->port.flags & ASYNC_CLOSING) { |
| 1301 | interruptible_sleep_on(&port->port.close_wait); |
| 1302 | if (port->port.flags & ASYNC_HUP_NOTIFY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | func_exit(); |
| 1304 | return -EAGAIN; |
| 1305 | } else { |
| 1306 | func_exit(); |
| 1307 | return -ERESTARTSYS; |
| 1308 | } |
| 1309 | } |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1310 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | /* |
| 1312 | * If non-blocking mode is set, or the port is not enabled, |
| 1313 | * then make the check up front and then exit. |
| 1314 | */ |
| 1315 | if ((filp->f_flags & O_NONBLOCK) || |
| 1316 | (tty->flags & (1 << TTY_IO_ERROR))) { |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1317 | port->port.flags |= ASYNC_NORMAL_ACTIVE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | func_exit(); |
| 1319 | return 0; |
| 1320 | } |
| 1321 | |
| 1322 | if (C_CLOCAL(tty)) |
| 1323 | do_clocal = 1; |
| 1324 | |
| 1325 | /* |
| 1326 | * Block waiting for the carrier detect and the line to become |
| 1327 | * free (i.e., not in use by the callout). While we are in |
| 1328 | * this loop, info->count is dropped by one, so that |
| 1329 | * rs_close() knows when to free things. We restore it upon |
| 1330 | * exit, either normal or abnormal. |
| 1331 | */ |
| 1332 | retval = 0; |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1333 | add_wait_queue(&port->port.open_wait, &wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1334 | spin_lock_irqsave(&port->lock, flags); |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1335 | if (!tty_hung_up_p(filp)) |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1336 | port->port.count--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | spin_unlock_irqrestore(&port->lock, flags); |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1338 | port->port.blocked_open++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | while (1) { |
| 1340 | spin_lock_irqsave(&bp->lock, flags); |
| 1341 | sx_out(bp, CD186x_CAR, port_No(port)); |
| 1342 | CD = sx_in(bp, CD186x_MSVR) & MSVR_CD; |
Alan Cox | d2fbd0f | 2008-07-22 11:17:16 +0100 | [diff] [blame] | 1343 | if (sx_crtscts(tty)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | /* Activate RTS */ |
| 1345 | port->MSVR |= MSVR_DTR; /* WTF? */ |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1346 | sx_out(bp, CD186x_MSVR, port->MSVR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | } else { |
| 1348 | /* Activate DTR */ |
| 1349 | port->MSVR |= MSVR_DTR; |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1350 | sx_out(bp, CD186x_MSVR, port->MSVR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | } |
| 1352 | spin_unlock_irqrestore(&bp->lock, flags); |
| 1353 | set_current_state(TASK_INTERRUPTIBLE); |
| 1354 | if (tty_hung_up_p(filp) || |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1355 | !(port->port.flags & ASYNC_INITIALIZED)) { |
| 1356 | if (port->port.flags & ASYNC_HUP_NOTIFY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1357 | retval = -EAGAIN; |
| 1358 | else |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1359 | retval = -ERESTARTSYS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | break; |
| 1361 | } |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1362 | if (!(port->port.flags & ASYNC_CLOSING) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | (do_clocal || CD)) |
| 1364 | break; |
| 1365 | if (signal_pending(current)) { |
| 1366 | retval = -ERESTARTSYS; |
| 1367 | break; |
| 1368 | } |
| 1369 | schedule(); |
| 1370 | } |
| 1371 | |
| 1372 | set_current_state(TASK_RUNNING); |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1373 | remove_wait_queue(&port->port.open_wait, &wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | spin_lock_irqsave(&port->lock, flags); |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1375 | if (!tty_hung_up_p(filp)) |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1376 | port->port.count++; |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1377 | port->port.blocked_open--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | spin_unlock_irqrestore(&port->lock, flags); |
| 1379 | if (retval) { |
| 1380 | func_exit(); |
| 1381 | return retval; |
| 1382 | } |
| 1383 | |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1384 | port->port.flags |= ASYNC_NORMAL_ACTIVE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | func_exit(); |
| 1386 | return 0; |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1387 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1388 | |
| 1389 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1390 | static int sx_open(struct tty_struct *tty, struct file *filp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1391 | { |
| 1392 | int board; |
| 1393 | int error; |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1394 | struct specialix_port *port; |
| 1395 | struct specialix_board *bp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1396 | int i; |
| 1397 | unsigned long flags; |
| 1398 | |
| 1399 | func_enter(); |
| 1400 | |
| 1401 | board = SX_BOARD(tty->index); |
| 1402 | |
| 1403 | if (board >= SX_NBOARD || !(sx_board[board].flags & SX_BOARD_PRESENT)) { |
| 1404 | func_exit(); |
| 1405 | return -ENODEV; |
| 1406 | } |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1407 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1408 | bp = &sx_board[board]; |
| 1409 | port = sx_port + board * SX_NPORT + SX_PORT(tty->index); |
| 1410 | port->overrun = 0; |
| 1411 | for (i = 0; i < 10; i++) |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1412 | port->hits[i] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1413 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1414 | dprintk(SX_DEBUG_OPEN, |
| 1415 | "Board = %d, bp = %p, port = %p, portno = %d.\n", |
| 1416 | board, bp, port, SX_PORT(tty->index)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 | |
| 1418 | if (sx_paranoia_check(port, tty->name, "sx_open")) { |
| 1419 | func_enter(); |
| 1420 | return -ENODEV; |
| 1421 | } |
| 1422 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1423 | error = sx_setup_board(bp); |
| 1424 | if (error) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1425 | func_exit(); |
| 1426 | return error; |
| 1427 | } |
| 1428 | |
| 1429 | spin_lock_irqsave(&bp->lock, flags); |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1430 | port->port.count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | bp->count++; |
| 1432 | tty->driver_data = port; |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1433 | port->port.tty = tty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1434 | spin_unlock_irqrestore(&bp->lock, flags); |
| 1435 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1436 | error = sx_setup_port(bp, port); |
| 1437 | if (error) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | func_enter(); |
| 1439 | return error; |
| 1440 | } |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1441 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1442 | error = block_til_ready(tty, filp, port); |
| 1443 | if (error) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | func_enter(); |
| 1445 | return error; |
| 1446 | } |
| 1447 | |
| 1448 | func_exit(); |
| 1449 | return 0; |
| 1450 | } |
| 1451 | |
Alan Cox | 978e595 | 2008-04-30 00:53:59 -0700 | [diff] [blame] | 1452 | static void sx_flush_buffer(struct tty_struct *tty) |
| 1453 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1454 | struct specialix_port *port = tty->driver_data; |
Alan Cox | 978e595 | 2008-04-30 00:53:59 -0700 | [diff] [blame] | 1455 | unsigned long flags; |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1456 | struct specialix_board *bp; |
Alan Cox | 978e595 | 2008-04-30 00:53:59 -0700 | [diff] [blame] | 1457 | |
| 1458 | func_enter(); |
| 1459 | |
| 1460 | if (sx_paranoia_check(port, tty->name, "sx_flush_buffer")) { |
| 1461 | func_exit(); |
| 1462 | return; |
| 1463 | } |
| 1464 | |
| 1465 | bp = port_Board(port); |
| 1466 | spin_lock_irqsave(&port->lock, flags); |
| 1467 | port->xmit_cnt = port->xmit_head = port->xmit_tail = 0; |
| 1468 | spin_unlock_irqrestore(&port->lock, flags); |
| 1469 | tty_wakeup(tty); |
| 1470 | |
| 1471 | func_exit(); |
| 1472 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1473 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1474 | static void sx_close(struct tty_struct *tty, struct file *filp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1475 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1476 | struct specialix_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1477 | struct specialix_board *bp; |
| 1478 | unsigned long flags; |
| 1479 | unsigned long timeout; |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1480 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1481 | func_enter(); |
| 1482 | if (!port || sx_paranoia_check(port, tty->name, "close")) { |
| 1483 | func_exit(); |
| 1484 | return; |
| 1485 | } |
| 1486 | spin_lock_irqsave(&port->lock, flags); |
| 1487 | |
| 1488 | if (tty_hung_up_p(filp)) { |
| 1489 | spin_unlock_irqrestore(&port->lock, flags); |
| 1490 | func_exit(); |
| 1491 | return; |
| 1492 | } |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1493 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1494 | bp = port_Board(port); |
Alan Cox | d2fbd0f | 2008-07-22 11:17:16 +0100 | [diff] [blame] | 1495 | if (tty->count == 1 && port->port.count != 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | printk(KERN_ERR "sx%d: sx_close: bad port count;" |
| 1497 | " tty->count is 1, port count is %d\n", |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1498 | board_No(bp), port->port.count); |
| 1499 | port->port.count = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | } |
| 1501 | |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1502 | if (port->port.count > 1) { |
| 1503 | port->port.count--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | bp->count--; |
| 1505 | |
| 1506 | spin_unlock_irqrestore(&port->lock, flags); |
| 1507 | |
| 1508 | func_exit(); |
| 1509 | return; |
| 1510 | } |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1511 | port->port.flags |= ASYNC_CLOSING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1512 | /* |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1513 | * Now we wait for the transmit buffer to clear; and we notify |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1514 | * the line discipline to only process XON/XOFF characters. |
| 1515 | */ |
| 1516 | tty->closing = 1; |
| 1517 | spin_unlock_irqrestore(&port->lock, flags); |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1518 | dprintk(SX_DEBUG_OPEN, "Closing\n"); |
| 1519 | if (port->port.closing_wait != ASYNC_CLOSING_WAIT_NONE) |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1520 | tty_wait_until_sent(tty, port->port.closing_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1521 | /* |
| 1522 | * At this point we stop accepting input. To do this, we |
| 1523 | * disable the receive line status interrupts, and tell the |
| 1524 | * interrupt driver to stop checking the data ready bit in the |
| 1525 | * line status register. |
| 1526 | */ |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1527 | dprintk(SX_DEBUG_OPEN, "Closed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1528 | port->IER &= ~IER_RXD; |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1529 | if (port->port.flags & ASYNC_INITIALIZED) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1530 | port->IER &= ~IER_TXRDY; |
| 1531 | port->IER |= IER_TXEMPTY; |
| 1532 | spin_lock_irqsave(&bp->lock, flags); |
| 1533 | sx_out(bp, CD186x_CAR, port_No(port)); |
| 1534 | sx_out(bp, CD186x_IER, port->IER); |
| 1535 | spin_unlock_irqrestore(&bp->lock, flags); |
| 1536 | /* |
| 1537 | * Before we drop DTR, make sure the UART transmitter |
| 1538 | * has completely drained; this is especially |
| 1539 | * important if there is a transmit FIFO! |
| 1540 | */ |
| 1541 | timeout = jiffies+HZ; |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1542 | while (port->IER & IER_TXEMPTY) { |
| 1543 | set_current_state(TASK_INTERRUPTIBLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | msleep_interruptible(jiffies_to_msecs(port->timeout)); |
| 1545 | if (time_after(jiffies, timeout)) { |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1546 | printk(KERN_INFO "Timeout waiting for close\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1547 | break; |
| 1548 | } |
| 1549 | } |
| 1550 | |
| 1551 | } |
| 1552 | |
| 1553 | if (--bp->count < 0) { |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1554 | printk(KERN_ERR |
| 1555 | "sx%d: sx_shutdown_port: bad board count: %d port: %d\n", |
| 1556 | board_No(bp), bp->count, tty->index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | bp->count = 0; |
| 1558 | } |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1559 | if (--port->port.count < 0) { |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1560 | printk(KERN_ERR |
| 1561 | "sx%d: sx_close: bad port count for tty%d: %d\n", |
| 1562 | board_No(bp), port_No(port), port->port.count); |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1563 | port->port.count = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | } |
| 1565 | |
| 1566 | sx_shutdown_port(bp, port); |
Alan Cox | 978e595 | 2008-04-30 00:53:59 -0700 | [diff] [blame] | 1567 | sx_flush_buffer(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1568 | tty_ldisc_flush(tty); |
| 1569 | spin_lock_irqsave(&port->lock, flags); |
| 1570 | tty->closing = 0; |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1571 | port->port.tty = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1572 | spin_unlock_irqrestore(&port->lock, flags); |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1573 | if (port->port.blocked_open) { |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1574 | if (port->port.close_delay) |
| 1575 | msleep_interruptible( |
| 1576 | jiffies_to_msecs(port->port.close_delay)); |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1577 | wake_up_interruptible(&port->port.open_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1578 | } |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1579 | port->port.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); |
| 1580 | wake_up_interruptible(&port->port.close_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1581 | |
| 1582 | func_exit(); |
| 1583 | } |
| 1584 | |
| 1585 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1586 | static int sx_write(struct tty_struct *tty, |
| 1587 | const unsigned char *buf, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1589 | struct specialix_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1590 | struct specialix_board *bp; |
| 1591 | int c, total = 0; |
| 1592 | unsigned long flags; |
| 1593 | |
| 1594 | func_enter(); |
| 1595 | if (sx_paranoia_check(port, tty->name, "sx_write")) { |
| 1596 | func_exit(); |
| 1597 | return 0; |
| 1598 | } |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1599 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1600 | bp = port_Board(port); |
| 1601 | |
Jiri Slaby | 365e022 | 2006-09-30 23:28:11 -0700 | [diff] [blame] | 1602 | if (!port->xmit_buf) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1603 | func_exit(); |
| 1604 | return 0; |
| 1605 | } |
| 1606 | |
| 1607 | while (1) { |
| 1608 | spin_lock_irqsave(&port->lock, flags); |
| 1609 | c = min_t(int, count, min(SERIAL_XMIT_SIZE - port->xmit_cnt - 1, |
| 1610 | SERIAL_XMIT_SIZE - port->xmit_head)); |
| 1611 | if (c <= 0) { |
| 1612 | spin_unlock_irqrestore(&port->lock, flags); |
| 1613 | break; |
| 1614 | } |
| 1615 | memcpy(port->xmit_buf + port->xmit_head, buf, c); |
| 1616 | port->xmit_head = (port->xmit_head + c) & (SERIAL_XMIT_SIZE-1); |
| 1617 | port->xmit_cnt += c; |
| 1618 | spin_unlock_irqrestore(&port->lock, flags); |
| 1619 | |
| 1620 | buf += c; |
| 1621 | count -= c; |
| 1622 | total += c; |
| 1623 | } |
| 1624 | |
| 1625 | spin_lock_irqsave(&bp->lock, flags); |
| 1626 | if (port->xmit_cnt && !tty->stopped && !tty->hw_stopped && |
| 1627 | !(port->IER & IER_TXRDY)) { |
| 1628 | port->IER |= IER_TXRDY; |
| 1629 | sx_out(bp, CD186x_CAR, port_No(port)); |
| 1630 | sx_out(bp, CD186x_IER, port->IER); |
| 1631 | } |
| 1632 | spin_unlock_irqrestore(&bp->lock, flags); |
| 1633 | func_exit(); |
| 1634 | |
| 1635 | return total; |
| 1636 | } |
| 1637 | |
| 1638 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1639 | static int sx_put_char(struct tty_struct *tty, unsigned char ch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1640 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1641 | struct specialix_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1642 | unsigned long flags; |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1643 | struct specialix_board *bp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1644 | |
| 1645 | func_enter(); |
| 1646 | |
| 1647 | if (sx_paranoia_check(port, tty->name, "sx_put_char")) { |
| 1648 | func_exit(); |
Alan Cox | 6ae0457 | 2008-04-30 00:54:07 -0700 | [diff] [blame] | 1649 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1650 | } |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1651 | dprintk(SX_DEBUG_TX, "check tty: %p %p\n", tty, port->xmit_buf); |
Eric Sesterhenn | 326f28e9 | 2006-06-25 05:48:48 -0700 | [diff] [blame] | 1652 | if (!port->xmit_buf) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1653 | func_exit(); |
Alan Cox | 6ae0457 | 2008-04-30 00:54:07 -0700 | [diff] [blame] | 1654 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1655 | } |
| 1656 | bp = port_Board(port); |
| 1657 | spin_lock_irqsave(&port->lock, flags); |
| 1658 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1659 | dprintk(SX_DEBUG_TX, "xmit_cnt: %d xmit_buf: %p\n", |
| 1660 | port->xmit_cnt, port->xmit_buf); |
| 1661 | if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1 || !port->xmit_buf) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | spin_unlock_irqrestore(&port->lock, flags); |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1663 | dprintk(SX_DEBUG_TX, "Exit size\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1664 | func_exit(); |
Alan Cox | 6ae0457 | 2008-04-30 00:54:07 -0700 | [diff] [blame] | 1665 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1666 | } |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1667 | dprintk(SX_DEBUG_TX, "Handle xmit: %p %p\n", port, port->xmit_buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1668 | port->xmit_buf[port->xmit_head++] = ch; |
| 1669 | port->xmit_head &= SERIAL_XMIT_SIZE - 1; |
| 1670 | port->xmit_cnt++; |
| 1671 | spin_unlock_irqrestore(&port->lock, flags); |
| 1672 | |
| 1673 | func_exit(); |
Alan Cox | 6ae0457 | 2008-04-30 00:54:07 -0700 | [diff] [blame] | 1674 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | } |
| 1676 | |
| 1677 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1678 | static void sx_flush_chars(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1680 | struct specialix_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1681 | unsigned long flags; |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1682 | struct specialix_board *bp = port_Board(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | |
| 1684 | func_enter(); |
| 1685 | |
| 1686 | if (sx_paranoia_check(port, tty->name, "sx_flush_chars")) { |
| 1687 | func_exit(); |
| 1688 | return; |
| 1689 | } |
| 1690 | if (port->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped || |
| 1691 | !port->xmit_buf) { |
| 1692 | func_exit(); |
| 1693 | return; |
| 1694 | } |
| 1695 | spin_lock_irqsave(&bp->lock, flags); |
| 1696 | port->IER |= IER_TXRDY; |
| 1697 | sx_out(port_Board(port), CD186x_CAR, port_No(port)); |
| 1698 | sx_out(port_Board(port), CD186x_IER, port->IER); |
| 1699 | spin_unlock_irqrestore(&bp->lock, flags); |
| 1700 | |
| 1701 | func_exit(); |
| 1702 | } |
| 1703 | |
| 1704 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1705 | static int sx_write_room(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1707 | struct specialix_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1708 | int ret; |
| 1709 | |
| 1710 | func_enter(); |
| 1711 | |
| 1712 | if (sx_paranoia_check(port, tty->name, "sx_write_room")) { |
| 1713 | func_exit(); |
| 1714 | return 0; |
| 1715 | } |
| 1716 | |
| 1717 | ret = SERIAL_XMIT_SIZE - port->xmit_cnt - 1; |
| 1718 | if (ret < 0) |
| 1719 | ret = 0; |
| 1720 | |
| 1721 | func_exit(); |
| 1722 | return ret; |
| 1723 | } |
| 1724 | |
| 1725 | |
| 1726 | static int sx_chars_in_buffer(struct tty_struct *tty) |
| 1727 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1728 | struct specialix_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | |
| 1730 | func_enter(); |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1731 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | if (sx_paranoia_check(port, tty->name, "sx_chars_in_buffer")) { |
| 1733 | func_exit(); |
| 1734 | return 0; |
| 1735 | } |
| 1736 | func_exit(); |
| 1737 | return port->xmit_cnt; |
| 1738 | } |
| 1739 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1740 | static int sx_tiocmget(struct tty_struct *tty, struct file *file) |
| 1741 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1742 | struct specialix_port *port = tty->driver_data; |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1743 | struct specialix_board *bp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1744 | unsigned char status; |
| 1745 | unsigned int result; |
| 1746 | unsigned long flags; |
| 1747 | |
| 1748 | func_enter(); |
| 1749 | |
Harvey Harrison | bf9d892 | 2008-04-30 00:55:10 -0700 | [diff] [blame] | 1750 | if (sx_paranoia_check(port, tty->name, __func__)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1751 | func_exit(); |
| 1752 | return -ENODEV; |
| 1753 | } |
| 1754 | |
| 1755 | bp = port_Board(port); |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1756 | spin_lock_irqsave(&bp->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1757 | sx_out(bp, CD186x_CAR, port_No(port)); |
| 1758 | status = sx_in(bp, CD186x_MSVR); |
| 1759 | spin_unlock_irqrestore(&bp->lock, flags); |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1760 | dprintk(SX_DEBUG_INIT, "Got msvr[%d] = %02x, car = %d.\n", |
| 1761 | port_No(port), status, sx_in(bp, CD186x_CAR)); |
| 1762 | dprintk(SX_DEBUG_INIT, "sx_port = %p, port = %p\n", sx_port, port); |
Alan Cox | d2fbd0f | 2008-07-22 11:17:16 +0100 | [diff] [blame] | 1763 | if (sx_crtscts(port->port.tty)) { |
| 1764 | result = TIOCM_DTR | TIOCM_DSR |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1765 | | ((status & MSVR_DTR) ? TIOCM_RTS : 0) |
| 1766 | | ((status & MSVR_CD) ? TIOCM_CAR : 0) |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1767 | | ((status & MSVR_CTS) ? TIOCM_CTS : 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1768 | } else { |
Alan Cox | d2fbd0f | 2008-07-22 11:17:16 +0100 | [diff] [blame] | 1769 | result = TIOCM_RTS | TIOCM_DSR |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1770 | | ((status & MSVR_DTR) ? TIOCM_DTR : 0) |
| 1771 | | ((status & MSVR_CD) ? TIOCM_CAR : 0) |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1772 | | ((status & MSVR_CTS) ? TIOCM_CTS : 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | } |
| 1774 | |
| 1775 | func_exit(); |
| 1776 | |
| 1777 | return result; |
| 1778 | } |
| 1779 | |
| 1780 | |
| 1781 | static int sx_tiocmset(struct tty_struct *tty, struct file *file, |
| 1782 | unsigned int set, unsigned int clear) |
| 1783 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1784 | struct specialix_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1785 | unsigned long flags; |
| 1786 | struct specialix_board *bp; |
| 1787 | |
| 1788 | func_enter(); |
| 1789 | |
Harvey Harrison | bf9d892 | 2008-04-30 00:55:10 -0700 | [diff] [blame] | 1790 | if (sx_paranoia_check(port, tty->name, __func__)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1791 | func_exit(); |
| 1792 | return -ENODEV; |
| 1793 | } |
| 1794 | |
| 1795 | bp = port_Board(port); |
| 1796 | |
| 1797 | spin_lock_irqsave(&port->lock, flags); |
Alan Cox | d2fbd0f | 2008-07-22 11:17:16 +0100 | [diff] [blame] | 1798 | if (sx_crtscts(port->port.tty)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1799 | if (set & TIOCM_RTS) |
| 1800 | port->MSVR |= MSVR_DTR; |
| 1801 | } else { |
| 1802 | if (set & TIOCM_DTR) |
| 1803 | port->MSVR |= MSVR_DTR; |
| 1804 | } |
Alan Cox | d2fbd0f | 2008-07-22 11:17:16 +0100 | [diff] [blame] | 1805 | if (sx_crtscts(port->port.tty)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1806 | if (clear & TIOCM_RTS) |
| 1807 | port->MSVR &= ~MSVR_DTR; |
| 1808 | } else { |
| 1809 | if (clear & TIOCM_DTR) |
| 1810 | port->MSVR &= ~MSVR_DTR; |
| 1811 | } |
Julia Lawall | 2547025 | 2009-07-20 16:05:07 +0100 | [diff] [blame] | 1812 | spin_lock(&bp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1813 | sx_out(bp, CD186x_CAR, port_No(port)); |
| 1814 | sx_out(bp, CD186x_MSVR, port->MSVR); |
Julia Lawall | 2547025 | 2009-07-20 16:05:07 +0100 | [diff] [blame] | 1815 | spin_unlock(&bp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1816 | spin_unlock_irqrestore(&port->lock, flags); |
| 1817 | func_exit(); |
| 1818 | return 0; |
| 1819 | } |
| 1820 | |
| 1821 | |
Alan Cox | faa7612 | 2008-07-22 11:19:05 +0100 | [diff] [blame] | 1822 | static int sx_send_break(struct tty_struct *tty, int length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1824 | struct specialix_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1825 | struct specialix_board *bp = port_Board(port); |
| 1826 | unsigned long flags; |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1827 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | func_enter(); |
Alan Cox | faa7612 | 2008-07-22 11:19:05 +0100 | [diff] [blame] | 1829 | if (length == 0 || length == -1) |
| 1830 | return -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1831 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1832 | spin_lock_irqsave(&port->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1833 | port->break_length = SPECIALIX_TPS / HZ * length; |
| 1834 | port->COR2 |= COR2_ETC; |
| 1835 | port->IER |= IER_TXRDY; |
Julia Lawall | 2547025 | 2009-07-20 16:05:07 +0100 | [diff] [blame] | 1836 | spin_lock(&bp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | sx_out(bp, CD186x_CAR, port_No(port)); |
| 1838 | sx_out(bp, CD186x_COR2, port->COR2); |
| 1839 | sx_out(bp, CD186x_IER, port->IER); |
Julia Lawall | 2547025 | 2009-07-20 16:05:07 +0100 | [diff] [blame] | 1840 | spin_unlock(&bp->lock); |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1841 | spin_unlock_irqrestore(&port->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1842 | sx_wait_CCR(bp); |
| 1843 | spin_lock_irqsave(&bp->lock, flags); |
| 1844 | sx_out(bp, CD186x_CCR, CCR_CORCHG2); |
| 1845 | spin_unlock_irqrestore(&bp->lock, flags); |
| 1846 | sx_wait_CCR(bp); |
| 1847 | |
| 1848 | func_exit(); |
Alan Cox | faa7612 | 2008-07-22 11:19:05 +0100 | [diff] [blame] | 1849 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1850 | } |
| 1851 | |
| 1852 | |
Alan Cox | d2fbd0f | 2008-07-22 11:17:16 +0100 | [diff] [blame] | 1853 | static int sx_set_serial_info(struct specialix_port *port, |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1854 | struct serial_struct __user *newinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1855 | { |
| 1856 | struct serial_struct tmp; |
| 1857 | struct specialix_board *bp = port_Board(port); |
| 1858 | int change_speed; |
| 1859 | |
| 1860 | func_enter(); |
Alan Cox | b190e17 | 2008-04-30 00:53:22 -0700 | [diff] [blame] | 1861 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | if (copy_from_user(&tmp, newinfo, sizeof(tmp))) { |
| 1863 | func_enter(); |
| 1864 | return -EFAULT; |
| 1865 | } |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1866 | |
Alan Cox | b190e17 | 2008-04-30 00:53:22 -0700 | [diff] [blame] | 1867 | lock_kernel(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1869 | change_speed = ((port->port.flags & ASYNC_SPD_MASK) != |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1870 | (tmp.flags & ASYNC_SPD_MASK)); |
| 1871 | change_speed |= (tmp.custom_divisor != port->custom_divisor); |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1872 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1873 | if (!capable(CAP_SYS_ADMIN)) { |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1874 | if ((tmp.close_delay != port->port.close_delay) || |
| 1875 | (tmp.closing_wait != port->port.closing_wait) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | ((tmp.flags & ~ASYNC_USR_MASK) != |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1877 | (port->port.flags & ~ASYNC_USR_MASK))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | func_exit(); |
Alan Cox | b190e17 | 2008-04-30 00:53:22 -0700 | [diff] [blame] | 1879 | unlock_kernel(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1880 | return -EPERM; |
| 1881 | } |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1882 | port->port.flags = ((port->port.flags & ~ASYNC_USR_MASK) | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1883 | (tmp.flags & ASYNC_USR_MASK)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1884 | port->custom_divisor = tmp.custom_divisor; |
| 1885 | } else { |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1886 | port->port.flags = ((port->port.flags & ~ASYNC_FLAGS) | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1887 | (tmp.flags & ASYNC_FLAGS)); |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1888 | port->port.close_delay = tmp.close_delay; |
| 1889 | port->port.closing_wait = tmp.closing_wait; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1890 | port->custom_divisor = tmp.custom_divisor; |
| 1891 | } |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1892 | if (change_speed) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1893 | sx_change_speed(bp, port); |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1894 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1895 | func_exit(); |
Alan Cox | b190e17 | 2008-04-30 00:53:22 -0700 | [diff] [blame] | 1896 | unlock_kernel(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1897 | return 0; |
| 1898 | } |
| 1899 | |
| 1900 | |
Alan Cox | d2fbd0f | 2008-07-22 11:17:16 +0100 | [diff] [blame] | 1901 | static int sx_get_serial_info(struct specialix_port *port, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1902 | struct serial_struct __user *retinfo) |
| 1903 | { |
| 1904 | struct serial_struct tmp; |
| 1905 | struct specialix_board *bp = port_Board(port); |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1906 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1907 | func_enter(); |
| 1908 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | memset(&tmp, 0, sizeof(tmp)); |
Alan Cox | b190e17 | 2008-04-30 00:53:22 -0700 | [diff] [blame] | 1910 | lock_kernel(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | tmp.type = PORT_CIRRUS; |
| 1912 | tmp.line = port - sx_port; |
| 1913 | tmp.port = bp->base; |
| 1914 | tmp.irq = bp->irq; |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1915 | tmp.flags = port->port.flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1916 | tmp.baud_base = (SX_OSCFREQ + CD186x_TPC/2) / CD186x_TPC; |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1917 | tmp.close_delay = port->port.close_delay * HZ/100; |
| 1918 | tmp.closing_wait = port->port.closing_wait * HZ/100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | tmp.custom_divisor = port->custom_divisor; |
| 1920 | tmp.xmit_fifo_size = CD186x_NFIFO; |
Alan Cox | b190e17 | 2008-04-30 00:53:22 -0700 | [diff] [blame] | 1921 | unlock_kernel(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1922 | if (copy_to_user(retinfo, &tmp, sizeof(tmp))) { |
| 1923 | func_exit(); |
| 1924 | return -EFAULT; |
| 1925 | } |
| 1926 | |
| 1927 | func_exit(); |
| 1928 | return 0; |
| 1929 | } |
| 1930 | |
| 1931 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1932 | static int sx_ioctl(struct tty_struct *tty, struct file *filp, |
| 1933 | unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1934 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1935 | struct specialix_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | void __user *argp = (void __user *)arg; |
| 1937 | |
| 1938 | func_enter(); |
| 1939 | |
| 1940 | if (sx_paranoia_check(port, tty->name, "sx_ioctl")) { |
| 1941 | func_exit(); |
| 1942 | return -ENODEV; |
| 1943 | } |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1944 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1945 | switch (cmd) { |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1946 | case TIOCGSERIAL: |
Alan Cox | faa7612 | 2008-07-22 11:19:05 +0100 | [diff] [blame] | 1947 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 | return sx_get_serial_info(port, argp); |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1949 | case TIOCSSERIAL: |
Alan Cox | faa7612 | 2008-07-22 11:19:05 +0100 | [diff] [blame] | 1950 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1951 | return sx_set_serial_info(port, argp); |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1952 | default: |
Alan Cox | faa7612 | 2008-07-22 11:19:05 +0100 | [diff] [blame] | 1953 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1954 | return -ENOIOCTLCMD; |
| 1955 | } |
| 1956 | func_exit(); |
| 1957 | return 0; |
| 1958 | } |
| 1959 | |
| 1960 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1961 | static void sx_throttle(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1962 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1963 | struct specialix_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1964 | struct specialix_board *bp; |
| 1965 | unsigned long flags; |
| 1966 | |
| 1967 | func_enter(); |
| 1968 | |
| 1969 | if (sx_paranoia_check(port, tty->name, "sx_throttle")) { |
| 1970 | func_exit(); |
| 1971 | return; |
| 1972 | } |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1973 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1974 | bp = port_Board(port); |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1975 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1976 | /* Use DTR instead of RTS ! */ |
Alan Cox | d2fbd0f | 2008-07-22 11:17:16 +0100 | [diff] [blame] | 1977 | if (sx_crtscts(tty)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1978 | port->MSVR &= ~MSVR_DTR; |
| 1979 | else { |
| 1980 | /* Auch!!! I think the system shouldn't call this then. */ |
| 1981 | /* Or maybe we're supposed (allowed?) to do our side of hw |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 1982 | handshake anyway, even when hardware handshake is off. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | When you see this in your logs, please report.... */ |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 1984 | printk(KERN_ERR |
| 1985 | "sx%d: Need to throttle, but can't (hardware hs is off)\n", |
| 1986 | port_No(port)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1987 | } |
| 1988 | spin_lock_irqsave(&bp->lock, flags); |
| 1989 | sx_out(bp, CD186x_CAR, port_No(port)); |
| 1990 | spin_unlock_irqrestore(&bp->lock, flags); |
| 1991 | if (I_IXOFF(tty)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1992 | sx_wait_CCR(bp); |
| 1993 | spin_lock_irqsave(&bp->lock, flags); |
| 1994 | sx_out(bp, CD186x_CCR, CCR_SSCH2); |
| 1995 | spin_unlock_irqrestore(&bp->lock, flags); |
| 1996 | sx_wait_CCR(bp); |
| 1997 | } |
| 1998 | spin_lock_irqsave(&bp->lock, flags); |
| 1999 | sx_out(bp, CD186x_MSVR, port->MSVR); |
| 2000 | spin_unlock_irqrestore(&bp->lock, flags); |
| 2001 | |
| 2002 | func_exit(); |
| 2003 | } |
| 2004 | |
| 2005 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 2006 | static void sx_unthrottle(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2007 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 2008 | struct specialix_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2009 | struct specialix_board *bp; |
| 2010 | unsigned long flags; |
| 2011 | |
| 2012 | func_enter(); |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 2013 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2014 | if (sx_paranoia_check(port, tty->name, "sx_unthrottle")) { |
| 2015 | func_exit(); |
| 2016 | return; |
| 2017 | } |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 2018 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2019 | bp = port_Board(port); |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 2020 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2021 | spin_lock_irqsave(&port->lock, flags); |
| 2022 | /* XXXX Use DTR INSTEAD???? */ |
Alan Cox | d2fbd0f | 2008-07-22 11:17:16 +0100 | [diff] [blame] | 2023 | if (sx_crtscts(tty)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2024 | port->MSVR |= MSVR_DTR; |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 2025 | /* Else clause: see remark in "sx_throttle"... */ |
Julia Lawall | 2547025 | 2009-07-20 16:05:07 +0100 | [diff] [blame] | 2026 | spin_lock(&bp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2027 | sx_out(bp, CD186x_CAR, port_No(port)); |
Julia Lawall | 2547025 | 2009-07-20 16:05:07 +0100 | [diff] [blame] | 2028 | spin_unlock(&bp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2029 | if (I_IXOFF(tty)) { |
| 2030 | spin_unlock_irqrestore(&port->lock, flags); |
| 2031 | sx_wait_CCR(bp); |
| 2032 | spin_lock_irqsave(&bp->lock, flags); |
| 2033 | sx_out(bp, CD186x_CCR, CCR_SSCH1); |
| 2034 | spin_unlock_irqrestore(&bp->lock, flags); |
| 2035 | sx_wait_CCR(bp); |
| 2036 | spin_lock_irqsave(&port->lock, flags); |
| 2037 | } |
Julia Lawall | 2547025 | 2009-07-20 16:05:07 +0100 | [diff] [blame] | 2038 | spin_lock(&bp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2039 | sx_out(bp, CD186x_MSVR, port->MSVR); |
Julia Lawall | 2547025 | 2009-07-20 16:05:07 +0100 | [diff] [blame] | 2040 | spin_unlock(&bp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2041 | spin_unlock_irqrestore(&port->lock, flags); |
| 2042 | |
| 2043 | func_exit(); |
| 2044 | } |
| 2045 | |
| 2046 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 2047 | static void sx_stop(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2048 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 2049 | struct specialix_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2050 | struct specialix_board *bp; |
| 2051 | unsigned long flags; |
| 2052 | |
| 2053 | func_enter(); |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 2054 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2055 | if (sx_paranoia_check(port, tty->name, "sx_stop")) { |
| 2056 | func_exit(); |
| 2057 | return; |
| 2058 | } |
| 2059 | |
| 2060 | bp = port_Board(port); |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 2061 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2062 | spin_lock_irqsave(&port->lock, flags); |
| 2063 | port->IER &= ~IER_TXRDY; |
Julia Lawall | 2547025 | 2009-07-20 16:05:07 +0100 | [diff] [blame] | 2064 | spin_lock(&bp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2065 | sx_out(bp, CD186x_CAR, port_No(port)); |
| 2066 | sx_out(bp, CD186x_IER, port->IER); |
Julia Lawall | 2547025 | 2009-07-20 16:05:07 +0100 | [diff] [blame] | 2067 | spin_unlock(&bp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2068 | spin_unlock_irqrestore(&port->lock, flags); |
| 2069 | |
| 2070 | func_exit(); |
| 2071 | } |
| 2072 | |
| 2073 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 2074 | static void sx_start(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2075 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 2076 | struct specialix_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2077 | struct specialix_board *bp; |
| 2078 | unsigned long flags; |
| 2079 | |
| 2080 | func_enter(); |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 2081 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2082 | if (sx_paranoia_check(port, tty->name, "sx_start")) { |
| 2083 | func_exit(); |
| 2084 | return; |
| 2085 | } |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 2086 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2087 | bp = port_Board(port); |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 2088 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2089 | spin_lock_irqsave(&port->lock, flags); |
| 2090 | if (port->xmit_cnt && port->xmit_buf && !(port->IER & IER_TXRDY)) { |
| 2091 | port->IER |= IER_TXRDY; |
Julia Lawall | 2547025 | 2009-07-20 16:05:07 +0100 | [diff] [blame] | 2092 | spin_lock(&bp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2093 | sx_out(bp, CD186x_CAR, port_No(port)); |
| 2094 | sx_out(bp, CD186x_IER, port->IER); |
Julia Lawall | 2547025 | 2009-07-20 16:05:07 +0100 | [diff] [blame] | 2095 | spin_unlock(&bp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2096 | } |
| 2097 | spin_unlock_irqrestore(&port->lock, flags); |
| 2098 | |
| 2099 | func_exit(); |
| 2100 | } |
| 2101 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 2102 | static void sx_hangup(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2103 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 2104 | struct specialix_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2105 | struct specialix_board *bp; |
| 2106 | unsigned long flags; |
| 2107 | |
| 2108 | func_enter(); |
| 2109 | |
| 2110 | if (sx_paranoia_check(port, tty->name, "sx_hangup")) { |
| 2111 | func_exit(); |
| 2112 | return; |
| 2113 | } |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 2114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | bp = port_Board(port); |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 2116 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2117 | sx_shutdown_port(bp, port); |
| 2118 | spin_lock_irqsave(&port->lock, flags); |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 2119 | bp->count -= port->port.count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2120 | if (bp->count < 0) { |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 2121 | printk(KERN_ERR |
| 2122 | "sx%d: sx_hangup: bad board count: %d port: %d\n", |
| 2123 | board_No(bp), bp->count, tty->index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | bp->count = 0; |
| 2125 | } |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 2126 | port->port.count = 0; |
| 2127 | port->port.flags &= ~ASYNC_NORMAL_ACTIVE; |
| 2128 | port->port.tty = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2129 | spin_unlock_irqrestore(&port->lock, flags); |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 2130 | wake_up_interruptible(&port->port.open_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2131 | |
| 2132 | func_exit(); |
| 2133 | } |
| 2134 | |
| 2135 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 2136 | static void sx_set_termios(struct tty_struct *tty, |
| 2137 | struct ktermios *old_termios) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2138 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 2139 | struct specialix_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2140 | unsigned long flags; |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 2141 | struct specialix_board *bp; |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 2142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2143 | if (sx_paranoia_check(port, tty->name, "sx_set_termios")) |
| 2144 | return; |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 2145 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2146 | bp = port_Board(port); |
| 2147 | spin_lock_irqsave(&port->lock, flags); |
| 2148 | sx_change_speed(port_Board(port), port); |
| 2149 | spin_unlock_irqrestore(&port->lock, flags); |
| 2150 | |
| 2151 | if ((old_termios->c_cflag & CRTSCTS) && |
| 2152 | !(tty->termios->c_cflag & CRTSCTS)) { |
| 2153 | tty->hw_stopped = 0; |
| 2154 | sx_start(tty); |
| 2155 | } |
| 2156 | } |
| 2157 | |
Jeff Dike | b68e31d | 2006-10-02 02:17:18 -0700 | [diff] [blame] | 2158 | static const struct tty_operations sx_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2159 | .open = sx_open, |
| 2160 | .close = sx_close, |
| 2161 | .write = sx_write, |
| 2162 | .put_char = sx_put_char, |
| 2163 | .flush_chars = sx_flush_chars, |
| 2164 | .write_room = sx_write_room, |
| 2165 | .chars_in_buffer = sx_chars_in_buffer, |
| 2166 | .flush_buffer = sx_flush_buffer, |
| 2167 | .ioctl = sx_ioctl, |
| 2168 | .throttle = sx_throttle, |
| 2169 | .unthrottle = sx_unthrottle, |
| 2170 | .set_termios = sx_set_termios, |
| 2171 | .stop = sx_stop, |
| 2172 | .start = sx_start, |
| 2173 | .hangup = sx_hangup, |
| 2174 | .tiocmget = sx_tiocmget, |
| 2175 | .tiocmset = sx_tiocmset, |
Alan Cox | faa7612 | 2008-07-22 11:19:05 +0100 | [diff] [blame] | 2176 | .break_ctl = sx_send_break, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2177 | }; |
| 2178 | |
| 2179 | static int sx_init_drivers(void) |
| 2180 | { |
| 2181 | int error; |
| 2182 | int i; |
| 2183 | |
| 2184 | func_enter(); |
| 2185 | |
| 2186 | specialix_driver = alloc_tty_driver(SX_NBOARD * SX_NPORT); |
| 2187 | if (!specialix_driver) { |
| 2188 | printk(KERN_ERR "sx: Couldn't allocate tty_driver.\n"); |
| 2189 | func_exit(); |
| 2190 | return 1; |
| 2191 | } |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 2192 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2193 | specialix_driver->owner = THIS_MODULE; |
| 2194 | specialix_driver->name = "ttyW"; |
| 2195 | specialix_driver->major = SPECIALIX_NORMAL_MAJOR; |
| 2196 | specialix_driver->type = TTY_DRIVER_TYPE_SERIAL; |
| 2197 | specialix_driver->subtype = SERIAL_TYPE_NORMAL; |
| 2198 | specialix_driver->init_termios = tty_std_termios; |
| 2199 | specialix_driver->init_termios.c_cflag = |
| 2200 | B9600 | CS8 | CREAD | HUPCL | CLOCAL; |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 2201 | specialix_driver->init_termios.c_ispeed = 9600; |
| 2202 | specialix_driver->init_termios.c_ospeed = 9600; |
Alan Cox | faa7612 | 2008-07-22 11:19:05 +0100 | [diff] [blame] | 2203 | specialix_driver->flags = TTY_DRIVER_REAL_RAW | |
| 2204 | TTY_DRIVER_HARDWARE_BREAK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2205 | tty_set_operations(specialix_driver, &sx_ops); |
| 2206 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 2207 | error = tty_register_driver(specialix_driver); |
| 2208 | if (error) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2209 | put_tty_driver(specialix_driver); |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 2210 | printk(KERN_ERR |
| 2211 | "sx: Couldn't register specialix IO8+ driver, error = %d\n", |
| 2212 | error); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2213 | func_exit(); |
| 2214 | return 1; |
| 2215 | } |
| 2216 | memset(sx_port, 0, sizeof(sx_port)); |
| 2217 | for (i = 0; i < SX_NPORT * SX_NBOARD; i++) { |
| 2218 | sx_port[i].magic = SPECIALIX_MAGIC; |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 2219 | tty_port_init(&sx_port[i].port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2220 | spin_lock_init(&sx_port[i].lock); |
| 2221 | } |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 2222 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2223 | func_exit(); |
| 2224 | return 0; |
| 2225 | } |
| 2226 | |
| 2227 | static void sx_release_drivers(void) |
| 2228 | { |
| 2229 | func_enter(); |
| 2230 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2231 | tty_unregister_driver(specialix_driver); |
| 2232 | put_tty_driver(specialix_driver); |
| 2233 | func_exit(); |
| 2234 | } |
| 2235 | |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 2236 | /* |
| 2237 | * This routine must be called by kernel at boot time |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2238 | */ |
| 2239 | static int __init specialix_init(void) |
| 2240 | { |
| 2241 | int i; |
| 2242 | int found = 0; |
| 2243 | |
| 2244 | func_enter(); |
| 2245 | |
| 2246 | printk(KERN_INFO "sx: Specialix IO8+ driver v" VERSION ", (c) R.E.Wolff 1997/1998.\n"); |
| 2247 | printk(KERN_INFO "sx: derived from work (c) D.Gorodchanin 1994-1996.\n"); |
Alan Cox | d2fbd0f | 2008-07-22 11:17:16 +0100 | [diff] [blame] | 2248 | if (sx_rtscts) |
| 2249 | printk(KERN_INFO |
| 2250 | "sx: DTR/RTS pin is RTS when CRTSCTS is on.\n"); |
| 2251 | else |
| 2252 | printk(KERN_INFO "sx: DTR/RTS pin is always RTS.\n"); |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 2253 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2254 | for (i = 0; i < SX_NBOARD; i++) |
Ingo Molnar | 34af946 | 2006-06-27 02:53:55 -0700 | [diff] [blame] | 2255 | spin_lock_init(&sx_board[i].lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2256 | |
| 2257 | if (sx_init_drivers()) { |
| 2258 | func_exit(); |
| 2259 | return -EIO; |
| 2260 | } |
| 2261 | |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 2262 | for (i = 0; i < SX_NBOARD; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2263 | if (sx_board[i].base && !sx_probe(&sx_board[i])) |
| 2264 | found++; |
| 2265 | |
| 2266 | #ifdef CONFIG_PCI |
| 2267 | { |
| 2268 | struct pci_dev *pdev = NULL; |
| 2269 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 2270 | i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2271 | while (i < SX_NBOARD) { |
| 2272 | if (sx_board[i].flags & SX_BOARD_PRESENT) { |
| 2273 | i++; |
| 2274 | continue; |
| 2275 | } |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 2276 | pdev = pci_get_device(PCI_VENDOR_ID_SPECIALIX, |
| 2277 | PCI_DEVICE_ID_SPECIALIX_IO8, pdev); |
| 2278 | if (!pdev) |
| 2279 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2280 | |
| 2281 | if (pci_enable_device(pdev)) |
| 2282 | continue; |
| 2283 | |
| 2284 | sx_board[i].irq = pdev->irq; |
| 2285 | |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 2286 | sx_board[i].base = pci_resource_start(pdev, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2287 | |
| 2288 | sx_board[i].flags |= SX_BOARD_IS_PCI; |
| 2289 | if (!sx_probe(&sx_board[i])) |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 2290 | found++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2291 | } |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 2292 | /* May exit pci_get sequence early with lots of boards */ |
| 2293 | if (pdev != NULL) |
| 2294 | pci_dev_put(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2295 | } |
| 2296 | #endif |
| 2297 | |
| 2298 | if (!found) { |
| 2299 | sx_release_drivers(); |
| 2300 | printk(KERN_INFO "sx: No specialix IO8+ boards detected.\n"); |
| 2301 | func_exit(); |
| 2302 | return -EIO; |
| 2303 | } |
| 2304 | |
| 2305 | func_exit(); |
| 2306 | return 0; |
| 2307 | } |
| 2308 | |
| 2309 | static int iobase[SX_NBOARD] = {0,}; |
Alan Cox | d2fbd0f | 2008-07-22 11:17:16 +0100 | [diff] [blame] | 2310 | static int irq[SX_NBOARD] = {0,}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2311 | |
| 2312 | module_param_array(iobase, int, NULL, 0); |
| 2313 | module_param_array(irq, int, NULL, 0); |
| 2314 | module_param(sx_debug, int, 0); |
Alan Cox | d2fbd0f | 2008-07-22 11:17:16 +0100 | [diff] [blame] | 2315 | module_param(sx_rtscts, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2316 | module_param(sx_rxfifo, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2317 | |
| 2318 | /* |
| 2319 | * You can setup up to 4 boards. |
| 2320 | * by specifying "iobase=0xXXX,0xXXX ..." as insmod parameter. |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 2321 | * You should specify the IRQs too in that case "irq=....,...". |
| 2322 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2323 | * More than 4 boards in one computer is not possible, as the card can |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 2324 | * only use 4 different interrupts. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2325 | * |
| 2326 | */ |
| 2327 | static int __init specialix_init_module(void) |
| 2328 | { |
| 2329 | int i; |
| 2330 | |
| 2331 | func_enter(); |
| 2332 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2333 | if (iobase[0] || iobase[1] || iobase[2] || iobase[3]) { |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 2334 | for (i = 0; i < SX_NBOARD; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2335 | sx_board[i].base = iobase[i]; |
| 2336 | sx_board[i].irq = irq[i]; |
Alan Cox | a72492b | 2008-07-22 11:17:05 +0100 | [diff] [blame] | 2337 | sx_board[i].count = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2338 | } |
| 2339 | } |
| 2340 | |
| 2341 | func_exit(); |
| 2342 | |
| 2343 | return specialix_init(); |
| 2344 | } |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 2345 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2346 | static void __exit specialix_exit_module(void) |
| 2347 | { |
| 2348 | int i; |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 2349 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2350 | func_enter(); |
| 2351 | |
| 2352 | sx_release_drivers(); |
| 2353 | for (i = 0; i < SX_NBOARD; i++) |
Jeff Garzik | d61780c | 2005-10-30 15:01:51 -0800 | [diff] [blame] | 2354 | if (sx_board[i].flags & SX_BOARD_PRESENT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2355 | sx_release_io_range(&sx_board[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2356 | func_exit(); |
| 2357 | } |
| 2358 | |
Chuck Short | 7691030b | 2006-07-10 04:43:59 -0700 | [diff] [blame] | 2359 | static struct pci_device_id specialx_pci_tbl[] __devinitdata = { |
| 2360 | { PCI_DEVICE(PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_IO8) }, |
| 2361 | { } |
| 2362 | }; |
| 2363 | MODULE_DEVICE_TABLE(pci, specialx_pci_tbl); |
| 2364 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2365 | module_init(specialix_init_module); |
| 2366 | module_exit(specialix_exit_module); |
| 2367 | |
| 2368 | MODULE_LICENSE("GPL"); |
Scott James Remnant | 5350d3b | 2009-04-06 17:33:11 +0100 | [diff] [blame] | 2369 | MODULE_ALIAS_CHARDEV_MAJOR(SPECIALIX_NORMAL_MAJOR); |