Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/char/riscom.c -- RISCom/8 multiport serial driver. |
| 3 | * |
| 4 | * Copyright (C) 1994-1996 Dmitry Gorodchanin (pgmdsg@ibi.com) |
| 5 | * |
| 6 | * This code is loosely based on the Linux serial driver, written by |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 7 | * Linus Torvalds, Theodore T'so and others. The RISCom/8 card |
| 8 | * programming info was obtained from various drivers for other OSes |
| 9 | * (FreeBSD, ISC, etc), but no source code from those drivers were |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * directly included in this driver. |
| 11 | * |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License as published by |
| 15 | * the Free Software Foundation; either version 2 of the License, or |
| 16 | * (at your option) any later version. |
| 17 | * |
| 18 | * This program is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | * GNU General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public License |
| 24 | * along with this program; if not, write to the Free Software |
| 25 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 26 | * |
| 27 | * Revision 1.1 |
| 28 | * |
| 29 | * ChangeLog: |
| 30 | * Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 27-Jun-2001 |
| 31 | * - get rid of check_region and several cleanups |
| 32 | */ |
| 33 | |
| 34 | #include <linux/module.h> |
| 35 | |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 36 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <linux/kernel.h> |
| 38 | #include <linux/sched.h> |
| 39 | #include <linux/ioport.h> |
| 40 | #include <linux/interrupt.h> |
| 41 | #include <linux/errno.h> |
| 42 | #include <linux/tty.h> |
| 43 | #include <linux/mm.h> |
| 44 | #include <linux/serial.h> |
| 45 | #include <linux/fcntl.h> |
| 46 | #include <linux/major.h> |
| 47 | #include <linux/init.h> |
| 48 | #include <linux/delay.h> |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 49 | #include <linux/tty_flip.h> |
Jeff Garzik | d9afa43 | 2008-02-06 01:36:11 -0800 | [diff] [blame] | 50 | #include <linux/spinlock.h> |
Scott James Remnant | 5c9f580 | 2009-04-06 17:33:26 +0100 | [diff] [blame] | 51 | #include <linux/device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 53 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | #include "riscom8.h" |
| 56 | #include "riscom8_reg.h" |
| 57 | |
| 58 | /* Am I paranoid or not ? ;-) */ |
| 59 | #define RISCOM_PARANOIA_CHECK |
| 60 | |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 61 | /* |
| 62 | * Crazy InteliCom/8 boards sometimes have swapped CTS & DSR signals. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | * You can slightly speed up things by #undefing the following option, |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 64 | * if you are REALLY sure that your board is correct one. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | */ |
| 66 | |
| 67 | #define RISCOM_BRAIN_DAMAGED_CTS |
| 68 | |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 69 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | * The following defines are mostly for testing purposes. But if you need |
| 71 | * some nice reporting in your syslog, you can define them also. |
| 72 | */ |
| 73 | #undef RC_REPORT_FIFO |
| 74 | #undef RC_REPORT_OVERRUN |
| 75 | |
| 76 | |
| 77 | #define RISCOM_LEGAL_FLAGS \ |
| 78 | (ASYNC_HUP_NOTIFY | ASYNC_SAK | ASYNC_SPLIT_TERMIOS | \ |
| 79 | ASYNC_SPD_HI | ASYNC_SPEED_VHI | ASYNC_SESSION_LOCKOUT | \ |
| 80 | ASYNC_PGRP_LOCKOUT | ASYNC_CALLOUT_NOHUP) |
| 81 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | static struct tty_driver *riscom_driver; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
Jeff Garzik | d9afa43 | 2008-02-06 01:36:11 -0800 | [diff] [blame] | 84 | static DEFINE_SPINLOCK(riscom_lock); |
| 85 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | static struct riscom_board rc_board[RC_NBOARD] = { |
| 87 | { |
| 88 | .base = RC_IOBASE1, |
| 89 | }, |
| 90 | { |
| 91 | .base = RC_IOBASE2, |
| 92 | }, |
| 93 | { |
| 94 | .base = RC_IOBASE3, |
| 95 | }, |
| 96 | { |
| 97 | .base = RC_IOBASE4, |
| 98 | }, |
| 99 | }; |
| 100 | |
| 101 | static struct riscom_port rc_port[RC_NBOARD * RC_NPORT]; |
| 102 | |
| 103 | /* RISCom/8 I/O ports addresses (without address translation) */ |
| 104 | static unsigned short rc_ioport[] = { |
Tobias Klauser | fe97107 | 2006-01-09 20:54:02 -0800 | [diff] [blame] | 105 | #if 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0c, |
Tobias Klauser | fe97107 | 2006-01-09 20:54:02 -0800 | [diff] [blame] | 107 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0c, 0x10, |
| 109 | 0x11, 0x12, 0x18, 0x28, 0x31, 0x32, 0x39, 0x3a, 0x40, 0x41, 0x61, 0x62, |
| 110 | 0x63, 0x64, 0x6b, 0x70, 0x71, 0x78, 0x7a, 0x7b, 0x7f, 0x100, 0x101 |
Tobias Klauser | fe97107 | 2006-01-09 20:54:02 -0800 | [diff] [blame] | 111 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | }; |
Tobias Klauser | fe97107 | 2006-01-09 20:54:02 -0800 | [diff] [blame] | 113 | #define RC_NIOPORT ARRAY_SIZE(rc_ioport) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
| 115 | |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 116 | static int rc_paranoia_check(struct riscom_port const *port, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | char *name, const char *routine) |
| 118 | { |
| 119 | #ifdef RISCOM_PARANOIA_CHECK |
| 120 | static const char badmagic[] = KERN_INFO |
| 121 | "rc: Warning: bad riscom port magic number for device %s in %s\n"; |
| 122 | static const char badinfo[] = KERN_INFO |
| 123 | "rc: Warning: null riscom port for device %s in %s\n"; |
| 124 | |
| 125 | if (!port) { |
| 126 | printk(badinfo, name, routine); |
| 127 | return 1; |
| 128 | } |
| 129 | if (port->magic != RISCOM8_MAGIC) { |
| 130 | printk(badmagic, name, routine); |
| 131 | return 1; |
| 132 | } |
| 133 | #endif |
| 134 | return 0; |
| 135 | } |
| 136 | |
| 137 | /* |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 138 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | * Service functions for RISCom/8 driver. |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 140 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | */ |
| 142 | |
| 143 | /* Get board number from pointer */ |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 144 | static inline int board_No(struct riscom_board const *bp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | { |
| 146 | return bp - rc_board; |
| 147 | } |
| 148 | |
| 149 | /* Get port number from pointer */ |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 150 | static inline int port_No(struct riscom_port const *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | { |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 152 | return RC_PORT(port - rc_port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | /* Get pointer to board from pointer to port */ |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 156 | static inline struct riscom_board *port_Board(struct riscom_port const *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | { |
| 158 | return &rc_board[RC_BOARD(port - rc_port)]; |
| 159 | } |
| 160 | |
| 161 | /* Input Byte from CL CD180 register */ |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 162 | static inline unsigned char rc_in(struct riscom_board const *bp, |
| 163 | unsigned short reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | { |
| 165 | return inb(bp->base + RC_TO_ISA(reg)); |
| 166 | } |
| 167 | |
| 168 | /* Output Byte to CL CD180 register */ |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 169 | static inline void rc_out(struct riscom_board const *bp, unsigned short reg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | unsigned char val) |
| 171 | { |
| 172 | outb(val, bp->base + RC_TO_ISA(reg)); |
| 173 | } |
| 174 | |
| 175 | /* Wait for Channel Command Register ready */ |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 176 | static void rc_wait_CCR(struct riscom_board const *bp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | { |
| 178 | unsigned long delay; |
| 179 | |
| 180 | /* FIXME: need something more descriptive then 100000 :) */ |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 181 | for (delay = 100000; delay; delay--) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | if (!rc_in(bp, CD180_CCR)) |
| 183 | return; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | printk(KERN_INFO "rc%d: Timeout waiting for CCR.\n", board_No(bp)); |
| 186 | } |
| 187 | |
| 188 | /* |
| 189 | * RISCom/8 probe functions. |
| 190 | */ |
| 191 | |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 192 | static int rc_request_io_range(struct riscom_board * const bp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | { |
| 194 | int i; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 195 | |
| 196 | for (i = 0; i < RC_NIOPORT; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | if (!request_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1, |
| 198 | "RISCom/8")) { |
| 199 | goto out_release; |
| 200 | } |
| 201 | return 0; |
| 202 | out_release: |
| 203 | printk(KERN_INFO "rc%d: Skipping probe at 0x%03x. IO address in use.\n", |
| 204 | board_No(bp), bp->base); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 205 | while (--i >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | release_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1); |
| 207 | return 1; |
| 208 | } |
| 209 | |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 210 | static void rc_release_io_range(struct riscom_board * const bp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | { |
| 212 | int i; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 213 | |
| 214 | for (i = 0; i < RC_NIOPORT; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | release_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1); |
| 216 | } |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 217 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | /* Reset and setup CD180 chip */ |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 219 | static void __init rc_init_CD180(struct riscom_board const *bp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | { |
| 221 | unsigned long flags; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 222 | |
Jeff Garzik | d9afa43 | 2008-02-06 01:36:11 -0800 | [diff] [blame] | 223 | spin_lock_irqsave(&riscom_lock, flags); |
| 224 | |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 225 | rc_out(bp, RC_CTOUT, 0); /* Clear timeout */ |
| 226 | rc_wait_CCR(bp); /* Wait for CCR ready */ |
| 227 | rc_out(bp, CD180_CCR, CCR_HARDRESET); /* Reset CD180 chip */ |
Jeff Garzik | d9afa43 | 2008-02-06 01:36:11 -0800 | [diff] [blame] | 228 | spin_unlock_irqrestore(&riscom_lock, flags); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 229 | msleep(50); /* Delay 0.05 sec */ |
Jeff Garzik | d9afa43 | 2008-02-06 01:36:11 -0800 | [diff] [blame] | 230 | spin_lock_irqsave(&riscom_lock, flags); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 231 | rc_out(bp, CD180_GIVR, RC_ID); /* Set ID for this chip */ |
| 232 | rc_out(bp, CD180_GICR, 0); /* Clear all bits */ |
| 233 | rc_out(bp, CD180_PILR1, RC_ACK_MINT); /* Prio for modem intr */ |
| 234 | rc_out(bp, CD180_PILR2, RC_ACK_TINT); /* Prio for tx intr */ |
| 235 | rc_out(bp, CD180_PILR3, RC_ACK_RINT); /* Prio for rx intr */ |
| 236 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | /* Setting up prescaler. We need 4 ticks per 1 ms */ |
| 238 | rc_out(bp, CD180_PPRH, (RC_OSCFREQ/(1000000/RISCOM_TPS)) >> 8); |
| 239 | rc_out(bp, CD180_PPRL, (RC_OSCFREQ/(1000000/RISCOM_TPS)) & 0xff); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 240 | |
Jeff Garzik | d9afa43 | 2008-02-06 01:36:11 -0800 | [diff] [blame] | 241 | spin_unlock_irqrestore(&riscom_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | /* Main probing routine, also sets irq. */ |
| 245 | static int __init rc_probe(struct riscom_board *bp) |
| 246 | { |
| 247 | unsigned char val1, val2; |
| 248 | int irqs = 0; |
| 249 | int retries; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 250 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | bp->irq = 0; |
| 252 | |
| 253 | if (rc_request_io_range(bp)) |
| 254 | return 1; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | /* Are the I/O ports here ? */ |
| 257 | rc_out(bp, CD180_PPRL, 0x5a); |
| 258 | outb(0xff, 0x80); |
| 259 | val1 = rc_in(bp, CD180_PPRL); |
| 260 | rc_out(bp, CD180_PPRL, 0xa5); |
| 261 | outb(0x00, 0x80); |
| 262 | val2 = rc_in(bp, CD180_PPRL); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 263 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | if ((val1 != 0x5a) || (val2 != 0xa5)) { |
| 265 | printk(KERN_ERR "rc%d: RISCom/8 Board at 0x%03x not found.\n", |
| 266 | board_No(bp), bp->base); |
| 267 | goto out_release; |
| 268 | } |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | /* It's time to find IRQ for this board */ |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 271 | for (retries = 0; retries < 5 && irqs <= 0; retries++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | irqs = probe_irq_on(); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 273 | rc_init_CD180(bp); /* Reset CD180 chip */ |
| 274 | rc_out(bp, CD180_CAR, 2); /* Select port 2 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | rc_wait_CCR(bp); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 276 | rc_out(bp, CD180_CCR, CCR_TXEN); /* Enable transmitter */ |
| 277 | rc_out(bp, CD180_IER, IER_TXRDY);/* Enable tx empty intr */ |
Jiri Slaby | c4ebd92 | 2007-07-17 04:05:20 -0700 | [diff] [blame] | 278 | msleep(50); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | irqs = probe_irq_off(irqs); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 280 | val1 = rc_in(bp, RC_BSR); /* Get Board Status reg */ |
| 281 | val2 = rc_in(bp, RC_ACK_TINT); /* ACK interrupt */ |
| 282 | rc_init_CD180(bp); /* Reset CD180 again */ |
| 283 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | if ((val1 & RC_BSR_TINT) || (val2 != (RC_ID | GIVR_IT_TX))) { |
| 285 | printk(KERN_ERR "rc%d: RISCom/8 Board at 0x%03x not " |
| 286 | "found.\n", board_No(bp), bp->base); |
| 287 | goto out_release; |
| 288 | } |
| 289 | } |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 290 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | if (irqs <= 0) { |
| 292 | printk(KERN_ERR "rc%d: Can't find IRQ for RISCom/8 board " |
| 293 | "at 0x%03x.\n", board_No(bp), bp->base); |
| 294 | goto out_release; |
| 295 | } |
| 296 | bp->irq = irqs; |
| 297 | bp->flags |= RC_BOARD_PRESENT; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | printk(KERN_INFO "rc%d: RISCom/8 Rev. %c board detected at " |
| 300 | "0x%03x, IRQ %d.\n", |
| 301 | board_No(bp), |
| 302 | (rc_in(bp, CD180_GFRCR) & 0x0f) + 'A', /* Board revision */ |
| 303 | bp->base, bp->irq); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 304 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | return 0; |
| 306 | out_release: |
| 307 | rc_release_io_range(bp); |
| 308 | return 1; |
| 309 | } |
| 310 | |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 311 | /* |
| 312 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | * Interrupt processing routines. |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 314 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | */ |
| 316 | |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 317 | static struct riscom_port *rc_get_port(struct riscom_board const *bp, |
| 318 | unsigned char const *what) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | { |
| 320 | unsigned char channel; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 321 | struct riscom_port *port; |
| 322 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | channel = rc_in(bp, CD180_GICR) >> GICR_CHAN_OFF; |
| 324 | if (channel < CD180_NCH) { |
| 325 | port = &rc_port[board_No(bp) * RC_NPORT + channel]; |
Alan Cox | 85f8f81 | 2008-07-16 21:55:29 +0100 | [diff] [blame] | 326 | if (port->port.flags & ASYNC_INITIALIZED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | return port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | } |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 329 | printk(KERN_ERR "rc%d: %s interrupt from invalid port %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | board_No(bp), what, channel); |
| 331 | return NULL; |
| 332 | } |
| 333 | |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 334 | static void rc_receive_exc(struct riscom_board const *bp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | { |
| 336 | struct riscom_port *port; |
| 337 | struct tty_struct *tty; |
| 338 | unsigned char status; |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 339 | unsigned char ch, flag; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 340 | |
| 341 | port = rc_get_port(bp, "Receive"); |
| 342 | if (port == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | return; |
| 344 | |
Alan Cox | 6ff1ab2 | 2009-09-19 13:13:22 -0700 | [diff] [blame] | 345 | tty = tty_port_tty_get(&port->port); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 346 | |
| 347 | #ifdef RC_REPORT_OVERRUN |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | status = rc_in(bp, CD180_RCSR); |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 349 | if (status & RCSR_OE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | port->overrun++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | status &= port->mark_mask; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 352 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | status = rc_in(bp, CD180_RCSR) & port->mark_mask; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 354 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | ch = rc_in(bp, CD180_RDR); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 356 | if (!status) |
Alan Cox | 6ff1ab2 | 2009-09-19 13:13:22 -0700 | [diff] [blame] | 357 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | if (status & RCSR_TOUT) { |
| 359 | printk(KERN_WARNING "rc%d: port %d: Receiver timeout. " |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 360 | "Hardware problems ?\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | board_No(bp), port_No(port)); |
Alan Cox | 6ff1ab2 | 2009-09-19 13:13:22 -0700 | [diff] [blame] | 362 | goto out; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 363 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | } else if (status & RCSR_BREAK) { |
| 365 | printk(KERN_INFO "rc%d: port %d: Handling break...\n", |
| 366 | board_No(bp), port_No(port)); |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 367 | flag = TTY_BREAK; |
Alan Cox | 6ff1ab2 | 2009-09-19 13:13:22 -0700 | [diff] [blame] | 368 | if (tty && (port->port.flags & ASYNC_SAK)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | do_SAK(tty); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 370 | |
| 371 | } else if (status & RCSR_PE) |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 372 | flag = TTY_PARITY; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 373 | |
| 374 | else if (status & RCSR_FE) |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 375 | flag = TTY_FRAME; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 376 | |
| 377 | else if (status & RCSR_OE) |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 378 | flag = TTY_OVERRUN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | else |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 380 | flag = TTY_NORMAL; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 381 | |
Alan Cox | 6ff1ab2 | 2009-09-19 13:13:22 -0700 | [diff] [blame] | 382 | if (tty) { |
| 383 | tty_insert_flip_char(tty, ch, flag); |
| 384 | tty_flip_buffer_push(tty); |
| 385 | } |
| 386 | out: |
| 387 | tty_kref_put(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | } |
| 389 | |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 390 | static void rc_receive(struct riscom_board const *bp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | { |
| 392 | struct riscom_port *port; |
| 393 | struct tty_struct *tty; |
| 394 | unsigned char count; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 395 | |
| 396 | port = rc_get_port(bp, "Receive"); |
| 397 | if (port == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | return; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 399 | |
Alan Cox | 6ff1ab2 | 2009-09-19 13:13:22 -0700 | [diff] [blame] | 400 | tty = tty_port_tty_get(&port->port); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 401 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | count = rc_in(bp, CD180_RDCR); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 403 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | #ifdef RC_REPORT_FIFO |
| 405 | port->hits[count > 8 ? 9 : count]++; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 406 | #endif |
| 407 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | while (count--) { |
Alan Cox | 6ff1ab2 | 2009-09-19 13:13:22 -0700 | [diff] [blame] | 409 | u8 ch = rc_in(bp, CD180_RDR); |
| 410 | if (tty) |
| 411 | tty_insert_flip_char(tty, ch, TTY_NORMAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | } |
Alan Cox | 6ff1ab2 | 2009-09-19 13:13:22 -0700 | [diff] [blame] | 413 | if (tty) { |
| 414 | tty_flip_buffer_push(tty); |
| 415 | tty_kref_put(tty); |
| 416 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | } |
| 418 | |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 419 | static void rc_transmit(struct riscom_board const *bp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | { |
| 421 | struct riscom_port *port; |
| 422 | struct tty_struct *tty; |
| 423 | unsigned char count; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 424 | |
| 425 | port = rc_get_port(bp, "Transmit"); |
| 426 | if (port == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | return; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 428 | |
Alan Cox | 6ff1ab2 | 2009-09-19 13:13:22 -0700 | [diff] [blame] | 429 | tty = tty_port_tty_get(&port->port); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 430 | |
| 431 | if (port->IER & IER_TXEMPTY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | /* FIFO drained */ |
| 433 | rc_out(bp, CD180_CAR, port_No(port)); |
| 434 | port->IER &= ~IER_TXEMPTY; |
| 435 | rc_out(bp, CD180_IER, port->IER); |
Alan Cox | 6ff1ab2 | 2009-09-19 13:13:22 -0700 | [diff] [blame] | 436 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | } |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 438 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | if ((port->xmit_cnt <= 0 && !port->break_length) |
Alan Cox | 6ff1ab2 | 2009-09-19 13:13:22 -0700 | [diff] [blame] | 440 | || (tty && (tty->stopped || tty->hw_stopped))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | rc_out(bp, CD180_CAR, port_No(port)); |
| 442 | port->IER &= ~IER_TXRDY; |
| 443 | rc_out(bp, CD180_IER, port->IER); |
Alan Cox | 6ff1ab2 | 2009-09-19 13:13:22 -0700 | [diff] [blame] | 444 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | } |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 446 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | if (port->break_length) { |
| 448 | if (port->break_length > 0) { |
| 449 | if (port->COR2 & COR2_ETC) { |
| 450 | rc_out(bp, CD180_TDR, CD180_C_ESC); |
| 451 | rc_out(bp, CD180_TDR, CD180_C_SBRK); |
| 452 | port->COR2 &= ~COR2_ETC; |
| 453 | } |
| 454 | count = min_t(int, port->break_length, 0xff); |
| 455 | rc_out(bp, CD180_TDR, CD180_C_ESC); |
| 456 | rc_out(bp, CD180_TDR, CD180_C_DELAY); |
| 457 | rc_out(bp, CD180_TDR, count); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 458 | port->break_length -= count; |
| 459 | if (port->break_length == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | port->break_length--; |
| 461 | } else { |
| 462 | rc_out(bp, CD180_TDR, CD180_C_ESC); |
| 463 | rc_out(bp, CD180_TDR, CD180_C_EBRK); |
| 464 | rc_out(bp, CD180_COR2, port->COR2); |
| 465 | rc_wait_CCR(bp); |
| 466 | rc_out(bp, CD180_CCR, CCR_CORCHG2); |
| 467 | port->break_length = 0; |
| 468 | } |
Jiri Slaby | 7e63d0c | 2009-09-06 23:10:09 +0200 | [diff] [blame] | 469 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | } |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 471 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | count = CD180_NFIFO; |
| 473 | do { |
Alan Cox | 85f8f81 | 2008-07-16 21:55:29 +0100 | [diff] [blame] | 474 | rc_out(bp, CD180_TDR, port->port.xmit_buf[port->xmit_tail++]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | port->xmit_tail = port->xmit_tail & (SERIAL_XMIT_SIZE-1); |
| 476 | if (--port->xmit_cnt <= 0) |
| 477 | break; |
| 478 | } while (--count > 0); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 479 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | if (port->xmit_cnt <= 0) { |
| 481 | rc_out(bp, CD180_CAR, port_No(port)); |
| 482 | port->IER &= ~IER_TXRDY; |
| 483 | rc_out(bp, CD180_IER, port->IER); |
| 484 | } |
Alan Cox | 6ff1ab2 | 2009-09-19 13:13:22 -0700 | [diff] [blame] | 485 | if (tty && port->xmit_cnt <= port->wakeup_chars) |
Jiri Slaby | b98e70d | 2008-02-07 00:16:41 -0800 | [diff] [blame] | 486 | tty_wakeup(tty); |
Alan Cox | 6ff1ab2 | 2009-09-19 13:13:22 -0700 | [diff] [blame] | 487 | out: |
| 488 | tty_kref_put(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | } |
| 490 | |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 491 | static void rc_check_modem(struct riscom_board const *bp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | { |
| 493 | struct riscom_port *port; |
| 494 | struct tty_struct *tty; |
| 495 | unsigned char mcr; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 496 | |
| 497 | port = rc_get_port(bp, "Modem"); |
| 498 | if (port == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | return; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 500 | |
Alan Cox | 6ff1ab2 | 2009-09-19 13:13:22 -0700 | [diff] [blame] | 501 | tty = tty_port_tty_get(&port->port); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 502 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | mcr = rc_in(bp, CD180_MCR); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 504 | if (mcr & MCR_CDCHG) { |
| 505 | if (rc_in(bp, CD180_MSVR) & MSVR_CD) |
Alan Cox | 85f8f81 | 2008-07-16 21:55:29 +0100 | [diff] [blame] | 506 | wake_up_interruptible(&port->port.open_wait); |
Alan Cox | 6ff1ab2 | 2009-09-19 13:13:22 -0700 | [diff] [blame] | 507 | else if (tty) |
Jiri Slaby | b98e70d | 2008-02-07 00:16:41 -0800 | [diff] [blame] | 508 | tty_hangup(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | } |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 510 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | #ifdef RISCOM_BRAIN_DAMAGED_CTS |
| 512 | if (mcr & MCR_CTSCHG) { |
| 513 | if (rc_in(bp, CD180_MSVR) & MSVR_CTS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | port->IER |= IER_TXRDY; |
Alan Cox | 6ff1ab2 | 2009-09-19 13:13:22 -0700 | [diff] [blame] | 515 | if (tty) { |
| 516 | tty->hw_stopped = 0; |
| 517 | if (port->xmit_cnt <= port->wakeup_chars) |
| 518 | tty_wakeup(tty); |
| 519 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | } else { |
Alan Cox | 6ff1ab2 | 2009-09-19 13:13:22 -0700 | [diff] [blame] | 521 | if (tty) |
| 522 | tty->hw_stopped = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | port->IER &= ~IER_TXRDY; |
| 524 | } |
| 525 | rc_out(bp, CD180_IER, port->IER); |
| 526 | } |
| 527 | if (mcr & MCR_DSRCHG) { |
| 528 | if (rc_in(bp, CD180_MSVR) & MSVR_DSR) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | port->IER |= IER_TXRDY; |
Alan Cox | 6ff1ab2 | 2009-09-19 13:13:22 -0700 | [diff] [blame] | 530 | if (tty) { |
| 531 | tty->hw_stopped = 0; |
| 532 | if (port->xmit_cnt <= port->wakeup_chars) |
| 533 | tty_wakeup(tty); |
| 534 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | } else { |
Alan Cox | 6ff1ab2 | 2009-09-19 13:13:22 -0700 | [diff] [blame] | 536 | if (tty) |
| 537 | tty->hw_stopped = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | port->IER &= ~IER_TXRDY; |
| 539 | } |
| 540 | rc_out(bp, CD180_IER, port->IER); |
| 541 | } |
| 542 | #endif /* RISCOM_BRAIN_DAMAGED_CTS */ |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 543 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | /* Clear change bits */ |
| 545 | rc_out(bp, CD180_MCR, 0); |
Alan Cox | 6ff1ab2 | 2009-09-19 13:13:22 -0700 | [diff] [blame] | 546 | tty_kref_put(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | /* The main interrupt processing routine */ |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 550 | static irqreturn_t rc_interrupt(int dummy, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | { |
| 552 | unsigned char status; |
| 553 | unsigned char ack; |
Jeff Garzik | f07ef39 | 2007-10-23 19:12:11 -0400 | [diff] [blame] | 554 | struct riscom_board *bp = dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | unsigned long loop = 0; |
| 556 | int handled = 0; |
| 557 | |
Jeff Garzik | c7bec5a | 2006-10-06 15:00:58 -0400 | [diff] [blame] | 558 | if (!(bp->flags & RC_BOARD_ACTIVE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | return IRQ_NONE; |
Jeff Garzik | c7bec5a | 2006-10-06 15:00:58 -0400 | [diff] [blame] | 560 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | while ((++loop < 16) && ((status = ~(rc_in(bp, RC_BSR))) & |
| 562 | (RC_BSR_TOUT | RC_BSR_TINT | |
| 563 | RC_BSR_MINT | RC_BSR_RINT))) { |
| 564 | handled = 1; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 565 | if (status & RC_BSR_TOUT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | printk(KERN_WARNING "rc%d: Got timeout. Hardware " |
| 567 | "error?\n", board_No(bp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | else if (status & RC_BSR_RINT) { |
| 569 | ack = rc_in(bp, RC_ACK_RINT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | if (ack == (RC_ID | GIVR_IT_RCV)) |
| 571 | rc_receive(bp); |
| 572 | else if (ack == (RC_ID | GIVR_IT_REXC)) |
| 573 | rc_receive_exc(bp); |
| 574 | else |
| 575 | printk(KERN_WARNING "rc%d: Bad receive ack " |
| 576 | "0x%02x.\n", |
| 577 | board_No(bp), ack); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | } else if (status & RC_BSR_TINT) { |
| 579 | ack = rc_in(bp, RC_ACK_TINT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | if (ack == (RC_ID | GIVR_IT_TX)) |
| 581 | rc_transmit(bp); |
| 582 | else |
| 583 | printk(KERN_WARNING "rc%d: Bad transmit ack " |
| 584 | "0x%02x.\n", |
| 585 | board_No(bp), ack); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | } else /* if (status & RC_BSR_MINT) */ { |
| 587 | ack = rc_in(bp, RC_ACK_MINT); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 588 | if (ack == (RC_ID | GIVR_IT_MODEM)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | rc_check_modem(bp); |
| 590 | else |
| 591 | printk(KERN_WARNING "rc%d: Bad modem ack " |
| 592 | "0x%02x.\n", |
| 593 | board_No(bp), ack); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 594 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | rc_out(bp, CD180_EOIR, 0); /* Mark end of interrupt */ |
| 596 | rc_out(bp, RC_CTOUT, 0); /* Clear timeout flag */ |
| 597 | } |
| 598 | return IRQ_RETVAL(handled); |
| 599 | } |
| 600 | |
| 601 | /* |
| 602 | * Routines for open & close processing. |
| 603 | */ |
| 604 | |
| 605 | /* Called with disabled interrupts */ |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 606 | static int rc_setup_board(struct riscom_board *bp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | { |
| 608 | int error; |
| 609 | |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 610 | if (bp->flags & RC_BOARD_ACTIVE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | return 0; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 612 | |
Thomas Gleixner | 0f2ed4c | 2006-07-01 19:29:33 -0700 | [diff] [blame] | 613 | error = request_irq(bp->irq, rc_interrupt, IRQF_DISABLED, |
Jeff Garzik | f07ef39 | 2007-10-23 19:12:11 -0400 | [diff] [blame] | 614 | "RISCom/8", bp); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 615 | if (error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | return error; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 617 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | rc_out(bp, RC_CTOUT, 0); /* Just in case */ |
| 619 | bp->DTR = ~0; |
| 620 | rc_out(bp, RC_DTR, bp->DTR); /* Drop DTR on all ports */ |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 621 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | bp->flags |= RC_BOARD_ACTIVE; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 623 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | return 0; |
| 625 | } |
| 626 | |
| 627 | /* Called with disabled interrupts */ |
Jeff Garzik | f07ef39 | 2007-10-23 19:12:11 -0400 | [diff] [blame] | 628 | static void rc_shutdown_board(struct riscom_board *bp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | { |
| 630 | if (!(bp->flags & RC_BOARD_ACTIVE)) |
| 631 | return; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 632 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | bp->flags &= ~RC_BOARD_ACTIVE; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 634 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | free_irq(bp->irq, NULL); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 636 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | bp->DTR = ~0; |
| 638 | rc_out(bp, RC_DTR, bp->DTR); /* Drop DTR on all ports */ |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 639 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | /* |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 643 | * Setting up port characteristics. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | * Must be called with disabled interrupts |
| 645 | */ |
Alan Cox | 6ff1ab2 | 2009-09-19 13:13:22 -0700 | [diff] [blame] | 646 | static void rc_change_speed(struct tty_struct *tty, struct riscom_board *bp, |
| 647 | struct riscom_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | unsigned long baud; |
| 650 | long tmp; |
| 651 | unsigned char cor1 = 0, cor3 = 0; |
| 652 | unsigned char mcor1 = 0, mcor2 = 0; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 653 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | port->IER = 0; |
| 655 | port->COR2 = 0; |
| 656 | port->MSVR = MSVR_RTS; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 657 | |
Alan Cox | c7bce30 | 2006-09-30 23:27:24 -0700 | [diff] [blame] | 658 | baud = tty_get_baud_rate(tty); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 659 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | /* Select port on the board */ |
| 661 | rc_out(bp, CD180_CAR, port_No(port)); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 662 | |
Alan Cox | c7bce30 | 2006-09-30 23:27:24 -0700 | [diff] [blame] | 663 | if (!baud) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | /* Drop DTR & exit */ |
| 665 | bp->DTR |= (1u << port_No(port)); |
| 666 | rc_out(bp, RC_DTR, bp->DTR); |
| 667 | return; |
| 668 | } else { |
| 669 | /* Set DTR on */ |
| 670 | bp->DTR &= ~(1u << port_No(port)); |
| 671 | rc_out(bp, RC_DTR, bp->DTR); |
| 672 | } |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 673 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | /* |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 675 | * Now we must calculate some speed depended things |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | */ |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 677 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | /* Set baud rate for port */ |
Alan Cox | c7bce30 | 2006-09-30 23:27:24 -0700 | [diff] [blame] | 679 | tmp = (((RC_OSCFREQ + baud/2) / baud + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | CD180_TPC/2) / CD180_TPC); |
| 681 | |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 682 | rc_out(bp, CD180_RBPRH, (tmp >> 8) & 0xff); |
| 683 | rc_out(bp, CD180_TBPRH, (tmp >> 8) & 0xff); |
| 684 | rc_out(bp, CD180_RBPRL, tmp & 0xff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | rc_out(bp, CD180_TBPRL, tmp & 0xff); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 686 | |
Alan Cox | c7bce30 | 2006-09-30 23:27:24 -0700 | [diff] [blame] | 687 | baud = (baud + 5) / 10; /* Estimated CPS */ |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 688 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | /* Two timer ticks seems enough to wakeup something like SLIP driver */ |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 690 | tmp = ((baud + HZ/2) / HZ) * 2 - CD180_NFIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | port->wakeup_chars = (tmp < 0) ? 0 : ((tmp >= SERIAL_XMIT_SIZE) ? |
| 692 | SERIAL_XMIT_SIZE - 1 : tmp); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 693 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | /* Receiver timeout will be transmission time for 1.5 chars */ |
| 695 | tmp = (RISCOM_TPS + RISCOM_TPS/2 + baud/2) / baud; |
| 696 | tmp = (tmp > 0xff) ? 0xff : tmp; |
| 697 | rc_out(bp, CD180_RTPR, tmp); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 698 | |
| 699 | switch (C_CSIZE(tty)) { |
| 700 | case CS5: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | cor1 |= COR1_5BITS; |
| 702 | break; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 703 | case CS6: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | cor1 |= COR1_6BITS; |
| 705 | break; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 706 | case CS7: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | cor1 |= COR1_7BITS; |
| 708 | break; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 709 | case CS8: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | cor1 |= COR1_8BITS; |
| 711 | break; |
| 712 | } |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 713 | if (C_CSTOPB(tty)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | cor1 |= COR1_2SB; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 715 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | cor1 |= COR1_IGNORE; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 717 | if (C_PARENB(tty)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | cor1 |= COR1_NORMPAR; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 719 | if (C_PARODD(tty)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | cor1 |= COR1_ODDP; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 721 | if (I_INPCK(tty)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | cor1 &= ~COR1_IGNORE; |
| 723 | } |
| 724 | /* Set marking of some errors */ |
| 725 | port->mark_mask = RCSR_OE | RCSR_TOUT; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 726 | if (I_INPCK(tty)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | port->mark_mask |= RCSR_FE | RCSR_PE; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 728 | if (I_BRKINT(tty) || I_PARMRK(tty)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | port->mark_mask |= RCSR_BREAK; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 730 | if (I_IGNPAR(tty)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | port->mark_mask &= ~(RCSR_FE | RCSR_PE); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 732 | if (I_IGNBRK(tty)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | port->mark_mask &= ~RCSR_BREAK; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 734 | if (I_IGNPAR(tty)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | /* Real raw mode. Ignore all */ |
| 736 | port->mark_mask &= ~RCSR_OE; |
| 737 | } |
| 738 | /* Enable Hardware Flow Control */ |
| 739 | if (C_CRTSCTS(tty)) { |
| 740 | #ifdef RISCOM_BRAIN_DAMAGED_CTS |
| 741 | port->IER |= IER_DSR | IER_CTS; |
| 742 | mcor1 |= MCOR1_DSRZD | MCOR1_CTSZD; |
| 743 | mcor2 |= MCOR2_DSROD | MCOR2_CTSOD; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 744 | tty->hw_stopped = !(rc_in(bp, CD180_MSVR) & |
| 745 | (MSVR_CTS|MSVR_DSR)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | #else |
| 747 | port->COR2 |= COR2_CTSAE; |
| 748 | #endif |
| 749 | } |
| 750 | /* Enable Software Flow Control. FIXME: I'm not sure about this */ |
| 751 | /* Some people reported that it works, but I still doubt */ |
| 752 | if (I_IXON(tty)) { |
| 753 | port->COR2 |= COR2_TXIBE; |
| 754 | cor3 |= (COR3_FCT | COR3_SCDE); |
| 755 | if (I_IXANY(tty)) |
| 756 | port->COR2 |= COR2_IXM; |
| 757 | rc_out(bp, CD180_SCHR1, START_CHAR(tty)); |
| 758 | rc_out(bp, CD180_SCHR2, STOP_CHAR(tty)); |
| 759 | rc_out(bp, CD180_SCHR3, START_CHAR(tty)); |
| 760 | rc_out(bp, CD180_SCHR4, STOP_CHAR(tty)); |
| 761 | } |
| 762 | if (!C_CLOCAL(tty)) { |
| 763 | /* Enable CD check */ |
| 764 | port->IER |= IER_CD; |
| 765 | mcor1 |= MCOR1_CDZD; |
| 766 | mcor2 |= MCOR2_CDOD; |
| 767 | } |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 768 | |
| 769 | if (C_CREAD(tty)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | /* Enable receiver */ |
| 771 | port->IER |= IER_RXD; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 772 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | /* Set input FIFO size (1-8 bytes) */ |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 774 | cor3 |= RISCOM_RXFIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | /* Setting up CD180 channel registers */ |
| 776 | rc_out(bp, CD180_COR1, cor1); |
| 777 | rc_out(bp, CD180_COR2, port->COR2); |
| 778 | rc_out(bp, CD180_COR3, cor3); |
| 779 | /* Make CD180 know about registers change */ |
| 780 | rc_wait_CCR(bp); |
| 781 | rc_out(bp, CD180_CCR, CCR_CORCHG1 | CCR_CORCHG2 | CCR_CORCHG3); |
| 782 | /* Setting up modem option registers */ |
| 783 | rc_out(bp, CD180_MCOR1, mcor1); |
| 784 | rc_out(bp, CD180_MCOR2, mcor2); |
| 785 | /* Enable CD180 transmitter & receiver */ |
| 786 | rc_wait_CCR(bp); |
| 787 | rc_out(bp, CD180_CCR, CCR_TXEN | CCR_RXEN); |
| 788 | /* Enable interrupts */ |
| 789 | rc_out(bp, CD180_IER, port->IER); |
| 790 | /* And finally set RTS on */ |
| 791 | rc_out(bp, CD180_MSVR, port->MSVR); |
| 792 | } |
| 793 | |
| 794 | /* Must be called with interrupts enabled */ |
Alan Cox | 8f1e672 | 2009-11-30 13:16:47 +0000 | [diff] [blame] | 795 | static int rc_activate_port(struct tty_port *port, struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | { |
Alan Cox | 8f1e672 | 2009-11-30 13:16:47 +0000 | [diff] [blame] | 797 | struct riscom_port *rp = container_of(port, struct riscom_port, port); |
| 798 | struct riscom_board *bp = port_Board(rp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | unsigned long flags; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 800 | |
Alan Cox | 8f1e672 | 2009-11-30 13:16:47 +0000 | [diff] [blame] | 801 | if (tty_port_alloc_xmit_buf(port) < 0) |
Alan Cox | 85f8f81 | 2008-07-16 21:55:29 +0100 | [diff] [blame] | 802 | return -ENOMEM; |
| 803 | |
Jeff Garzik | d9afa43 | 2008-02-06 01:36:11 -0800 | [diff] [blame] | 804 | spin_lock_irqsave(&riscom_lock, flags); |
| 805 | |
Alan Cox | 6ff1ab2 | 2009-09-19 13:13:22 -0700 | [diff] [blame] | 806 | clear_bit(TTY_IO_ERROR, &tty->flags); |
Alan Cox | 8f1e672 | 2009-11-30 13:16:47 +0000 | [diff] [blame] | 807 | bp->count++; |
| 808 | rp->xmit_cnt = rp->xmit_head = rp->xmit_tail = 0; |
| 809 | rc_change_speed(tty, bp, rp); |
Jeff Garzik | d9afa43 | 2008-02-06 01:36:11 -0800 | [diff] [blame] | 810 | spin_unlock_irqrestore(&riscom_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | return 0; |
| 812 | } |
| 813 | |
| 814 | /* Must be called with interrupts disabled */ |
Alan Cox | d99101f | 2008-07-16 21:55:37 +0100 | [diff] [blame] | 815 | static void rc_shutdown_port(struct tty_struct *tty, |
| 816 | struct riscom_board *bp, struct riscom_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | #ifdef RC_REPORT_OVERRUN |
| 819 | printk(KERN_INFO "rc%d: port %d: Total %ld overruns were detected.\n", |
| 820 | board_No(bp), port_No(port), port->overrun); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 821 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | #ifdef RC_REPORT_FIFO |
| 823 | { |
| 824 | int i; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 825 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | printk(KERN_INFO "rc%d: port %d: FIFO hits [ ", |
| 827 | board_No(bp), port_No(port)); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 828 | for (i = 0; i < 10; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | printk("%ld ", port->hits[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | printk("].\n"); |
| 831 | } |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 832 | #endif |
Alan Cox | 85f8f81 | 2008-07-16 21:55:29 +0100 | [diff] [blame] | 833 | tty_port_free_xmit_buf(&port->port); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 834 | |
| 835 | /* Select port */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | rc_out(bp, CD180_CAR, port_No(port)); |
| 837 | /* Reset port */ |
| 838 | rc_wait_CCR(bp); |
| 839 | rc_out(bp, CD180_CCR, CCR_SOFTRESET); |
| 840 | /* Disable all interrupts from this port */ |
| 841 | port->IER = 0; |
| 842 | rc_out(bp, CD180_IER, port->IER); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 843 | |
Alan Cox | d99101f | 2008-07-16 21:55:37 +0100 | [diff] [blame] | 844 | set_bit(TTY_IO_ERROR, &tty->flags); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 845 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | if (--bp->count < 0) { |
| 847 | printk(KERN_INFO "rc%d: rc_shutdown_port: " |
| 848 | "bad board count: %d\n", |
| 849 | board_No(bp), bp->count); |
| 850 | bp->count = 0; |
| 851 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | /* |
| 853 | * If this is the last opened port on the board |
| 854 | * shutdown whole board |
| 855 | */ |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 856 | if (!bp->count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | rc_shutdown_board(bp); |
| 858 | } |
| 859 | |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame] | 860 | static int carrier_raised(struct tty_port *port) |
| 861 | { |
| 862 | struct riscom_port *p = container_of(port, struct riscom_port, port); |
| 863 | struct riscom_board *bp = port_Board(p); |
| 864 | unsigned long flags; |
| 865 | int CD; |
| 866 | |
| 867 | spin_lock_irqsave(&riscom_lock, flags); |
| 868 | rc_out(bp, CD180_CAR, port_No(p)); |
| 869 | CD = rc_in(bp, CD180_MSVR) & MSVR_CD; |
| 870 | rc_out(bp, CD180_MSVR, MSVR_RTS); |
| 871 | bp->DTR &= ~(1u << port_No(p)); |
| 872 | rc_out(bp, RC_DTR, bp->DTR); |
| 873 | spin_unlock_irqrestore(&riscom_lock, flags); |
| 874 | return CD; |
| 875 | } |
| 876 | |
Alan Cox | 8f1e672 | 2009-11-30 13:16:47 +0000 | [diff] [blame] | 877 | static void dtr_rts(struct tty_port *port, int onoff) |
| 878 | { |
| 879 | struct riscom_port *p = container_of(port, struct riscom_port, port); |
| 880 | struct riscom_board *bp = port_Board(p); |
| 881 | unsigned long flags; |
| 882 | |
| 883 | spin_lock_irqsave(&riscom_lock, flags); |
| 884 | bp->DTR &= ~(1u << port_No(p)); |
| 885 | if (onoff == 0) |
| 886 | bp->DTR |= (1u << port_No(p)); |
| 887 | rc_out(bp, RC_DTR, bp->DTR); |
| 888 | spin_unlock_irqrestore(&riscom_lock, flags); |
| 889 | } |
| 890 | |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 891 | static int rc_open(struct tty_struct *tty, struct file *filp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | { |
| 893 | int board; |
| 894 | int error; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 895 | struct riscom_port *port; |
| 896 | struct riscom_board *bp; |
| 897 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | board = RC_BOARD(tty->index); |
| 899 | if (board >= RC_NBOARD || !(rc_board[board].flags & RC_BOARD_PRESENT)) |
| 900 | return -ENODEV; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 901 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | bp = &rc_board[board]; |
| 903 | port = rc_port + board * RC_NPORT + RC_PORT(tty->index); |
| 904 | if (rc_paranoia_check(port, tty->name, "rc_open")) |
| 905 | return -ENODEV; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 906 | |
| 907 | error = rc_setup_board(bp); |
| 908 | if (error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | return error; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 910 | |
Alan Cox | a2d1e35 | 2010-04-23 16:01:18 +0100 | [diff] [blame] | 911 | tty->driver_data = port; |
Alan Cox | 8f1e672 | 2009-11-30 13:16:47 +0000 | [diff] [blame] | 912 | return tty_port_open(&port->port, tty, filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | } |
| 914 | |
Alan Cox | 978e595 | 2008-04-30 00:53:59 -0700 | [diff] [blame] | 915 | static void rc_flush_buffer(struct tty_struct *tty) |
| 916 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 917 | struct riscom_port *port = tty->driver_data; |
Alan Cox | 978e595 | 2008-04-30 00:53:59 -0700 | [diff] [blame] | 918 | unsigned long flags; |
| 919 | |
| 920 | if (rc_paranoia_check(port, tty->name, "rc_flush_buffer")) |
| 921 | return; |
| 922 | |
| 923 | spin_lock_irqsave(&riscom_lock, flags); |
Alan Cox | 978e595 | 2008-04-30 00:53:59 -0700 | [diff] [blame] | 924 | port->xmit_cnt = port->xmit_head = port->xmit_tail = 0; |
Alan Cox | 978e595 | 2008-04-30 00:53:59 -0700 | [diff] [blame] | 925 | spin_unlock_irqrestore(&riscom_lock, flags); |
| 926 | |
| 927 | tty_wakeup(tty); |
| 928 | } |
| 929 | |
Jiri Slaby | 90387f5 | 2009-08-22 09:04:42 +0200 | [diff] [blame] | 930 | static void rc_close_port(struct tty_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | unsigned long flags; |
Alan Cox | c146942 | 2009-09-19 13:13:21 -0700 | [diff] [blame] | 933 | struct riscom_port *rp = container_of(port, struct riscom_port, port); |
| 934 | struct riscom_board *bp = port_Board(rp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | unsigned long timeout; |
Alan Cox | a661499 | 2009-01-02 13:46:50 +0000 | [diff] [blame] | 936 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | /* |
| 938 | * At this point we stop accepting input. To do this, we |
| 939 | * disable the receive line status interrupts, and tell the |
| 940 | * interrupt driver to stop checking the data ready bit in the |
| 941 | * line status register. |
| 942 | */ |
Alan Cox | c2ba38c | 2009-01-02 13:45:50 +0000 | [diff] [blame] | 943 | |
| 944 | spin_lock_irqsave(&riscom_lock, flags); |
Alan Cox | c146942 | 2009-09-19 13:13:21 -0700 | [diff] [blame] | 945 | rp->IER &= ~IER_RXD; |
Alan Cox | 8f1e672 | 2009-11-30 13:16:47 +0000 | [diff] [blame] | 946 | |
| 947 | rp->IER &= ~IER_TXRDY; |
| 948 | rp->IER |= IER_TXEMPTY; |
| 949 | rc_out(bp, CD180_CAR, port_No(rp)); |
| 950 | rc_out(bp, CD180_IER, rp->IER); |
| 951 | /* |
| 952 | * Before we drop DTR, make sure the UART transmitter |
| 953 | * has completely drained; this is especially |
| 954 | * important if there is a transmit FIFO! |
| 955 | */ |
| 956 | timeout = jiffies + HZ; |
| 957 | while (rp->IER & IER_TXEMPTY) { |
| 958 | spin_unlock_irqrestore(&riscom_lock, flags); |
| 959 | msleep_interruptible(jiffies_to_msecs(rp->timeout)); |
| 960 | spin_lock_irqsave(&riscom_lock, flags); |
| 961 | if (time_after(jiffies, timeout)) |
| 962 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | } |
Jiri Slaby | 90387f5 | 2009-08-22 09:04:42 +0200 | [diff] [blame] | 964 | rc_shutdown_port(port->tty, bp, rp); |
Alan Cox | c2ba38c | 2009-01-02 13:45:50 +0000 | [diff] [blame] | 965 | spin_unlock_irqrestore(&riscom_lock, flags); |
Alan Cox | c146942 | 2009-09-19 13:13:21 -0700 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | static void rc_close(struct tty_struct *tty, struct file *filp) |
| 969 | { |
| 970 | struct riscom_port *port = tty->driver_data; |
| 971 | |
| 972 | if (!port || rc_paranoia_check(port, tty->name, "close")) |
| 973 | return; |
Alan Cox | 6ff1ab2 | 2009-09-19 13:13:22 -0700 | [diff] [blame] | 974 | tty_port_close(&port->port, tty, filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | } |
| 976 | |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 977 | static int rc_write(struct tty_struct *tty, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | const unsigned char *buf, int count) |
| 979 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 980 | struct riscom_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | struct riscom_board *bp; |
| 982 | int c, total = 0; |
| 983 | unsigned long flags; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 984 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | if (rc_paranoia_check(port, tty->name, "rc_write")) |
| 986 | return 0; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 987 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | bp = port_Board(port); |
| 989 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | while (1) { |
Jeff Garzik | d9afa43 | 2008-02-06 01:36:11 -0800 | [diff] [blame] | 991 | spin_lock_irqsave(&riscom_lock, flags); |
| 992 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | c = min_t(int, count, min(SERIAL_XMIT_SIZE - port->xmit_cnt - 1, |
| 994 | SERIAL_XMIT_SIZE - port->xmit_head)); |
Jeff Garzik | d9afa43 | 2008-02-06 01:36:11 -0800 | [diff] [blame] | 995 | if (c <= 0) |
| 996 | break; /* lock continues to be held */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | |
Alan Cox | 85f8f81 | 2008-07-16 21:55:29 +0100 | [diff] [blame] | 998 | memcpy(port->port.xmit_buf + port->xmit_head, buf, c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | port->xmit_head = (port->xmit_head + c) & (SERIAL_XMIT_SIZE-1); |
| 1000 | port->xmit_cnt += c; |
Jeff Garzik | d9afa43 | 2008-02-06 01:36:11 -0800 | [diff] [blame] | 1001 | |
| 1002 | spin_unlock_irqrestore(&riscom_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | |
| 1004 | buf += c; |
| 1005 | count -= c; |
| 1006 | total += c; |
| 1007 | } |
| 1008 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | if (port->xmit_cnt && !tty->stopped && !tty->hw_stopped && |
| 1010 | !(port->IER & IER_TXRDY)) { |
| 1011 | port->IER |= IER_TXRDY; |
| 1012 | rc_out(bp, CD180_CAR, port_No(port)); |
| 1013 | rc_out(bp, CD180_IER, port->IER); |
| 1014 | } |
Jeff Garzik | d9afa43 | 2008-02-06 01:36:11 -0800 | [diff] [blame] | 1015 | |
| 1016 | spin_unlock_irqrestore(&riscom_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | |
| 1018 | return total; |
| 1019 | } |
| 1020 | |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1021 | static int rc_put_char(struct tty_struct *tty, unsigned char ch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1023 | struct riscom_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | unsigned long flags; |
Alan Cox | bbbbb96 | 2008-04-30 00:54:05 -0700 | [diff] [blame] | 1025 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | |
| 1027 | if (rc_paranoia_check(port, tty->name, "rc_put_char")) |
Alan Cox | bbbbb96 | 2008-04-30 00:54:05 -0700 | [diff] [blame] | 1028 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | |
Jeff Garzik | d9afa43 | 2008-02-06 01:36:11 -0800 | [diff] [blame] | 1030 | spin_lock_irqsave(&riscom_lock, flags); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1031 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1) |
| 1033 | goto out; |
| 1034 | |
Alan Cox | 85f8f81 | 2008-07-16 21:55:29 +0100 | [diff] [blame] | 1035 | port->port.xmit_buf[port->xmit_head++] = ch; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | port->xmit_head &= SERIAL_XMIT_SIZE - 1; |
| 1037 | port->xmit_cnt++; |
Alan Cox | bbbbb96 | 2008-04-30 00:54:05 -0700 | [diff] [blame] | 1038 | ret = 1; |
Jeff Garzik | d9afa43 | 2008-02-06 01:36:11 -0800 | [diff] [blame] | 1039 | |
| 1040 | out: |
| 1041 | spin_unlock_irqrestore(&riscom_lock, flags); |
Alan Cox | bbbbb96 | 2008-04-30 00:54:05 -0700 | [diff] [blame] | 1042 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | } |
| 1044 | |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1045 | static void rc_flush_chars(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1047 | struct riscom_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | unsigned long flags; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1049 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | if (rc_paranoia_check(port, tty->name, "rc_flush_chars")) |
| 1051 | return; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1052 | |
Alan Cox | d99101f | 2008-07-16 21:55:37 +0100 | [diff] [blame] | 1053 | if (port->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | return; |
| 1055 | |
Jeff Garzik | d9afa43 | 2008-02-06 01:36:11 -0800 | [diff] [blame] | 1056 | spin_lock_irqsave(&riscom_lock, flags); |
| 1057 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | port->IER |= IER_TXRDY; |
| 1059 | rc_out(port_Board(port), CD180_CAR, port_No(port)); |
| 1060 | rc_out(port_Board(port), CD180_IER, port->IER); |
Jeff Garzik | d9afa43 | 2008-02-06 01:36:11 -0800 | [diff] [blame] | 1061 | |
| 1062 | spin_unlock_irqrestore(&riscom_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | } |
| 1064 | |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1065 | static int rc_write_room(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1067 | struct riscom_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | int ret; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1069 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | if (rc_paranoia_check(port, tty->name, "rc_write_room")) |
| 1071 | return 0; |
| 1072 | |
| 1073 | ret = SERIAL_XMIT_SIZE - port->xmit_cnt - 1; |
| 1074 | if (ret < 0) |
| 1075 | ret = 0; |
| 1076 | return ret; |
| 1077 | } |
| 1078 | |
| 1079 | static int rc_chars_in_buffer(struct tty_struct *tty) |
| 1080 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1081 | struct riscom_port *port = tty->driver_data; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1082 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | if (rc_paranoia_check(port, tty->name, "rc_chars_in_buffer")) |
| 1084 | return 0; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1085 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | return port->xmit_cnt; |
| 1087 | } |
| 1088 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | static int rc_tiocmget(struct tty_struct *tty, struct file *file) |
| 1090 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1091 | struct riscom_port *port = tty->driver_data; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1092 | struct riscom_board *bp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | unsigned char status; |
| 1094 | unsigned int result; |
| 1095 | unsigned long flags; |
| 1096 | |
Harvey Harrison | bf9d892 | 2008-04-30 00:55:10 -0700 | [diff] [blame] | 1097 | if (rc_paranoia_check(port, tty->name, __func__)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | return -ENODEV; |
| 1099 | |
| 1100 | bp = port_Board(port); |
Jeff Garzik | d9afa43 | 2008-02-06 01:36:11 -0800 | [diff] [blame] | 1101 | |
| 1102 | spin_lock_irqsave(&riscom_lock, flags); |
| 1103 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | rc_out(bp, CD180_CAR, port_No(port)); |
| 1105 | status = rc_in(bp, CD180_MSVR); |
| 1106 | result = rc_in(bp, RC_RI) & (1u << port_No(port)) ? 0 : TIOCM_RNG; |
Jeff Garzik | d9afa43 | 2008-02-06 01:36:11 -0800 | [diff] [blame] | 1107 | |
| 1108 | spin_unlock_irqrestore(&riscom_lock, flags); |
| 1109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | result |= ((status & MSVR_RTS) ? TIOCM_RTS : 0) |
| 1111 | | ((status & MSVR_DTR) ? TIOCM_DTR : 0) |
| 1112 | | ((status & MSVR_CD) ? TIOCM_CAR : 0) |
| 1113 | | ((status & MSVR_DSR) ? TIOCM_DSR : 0) |
| 1114 | | ((status & MSVR_CTS) ? TIOCM_CTS : 0); |
| 1115 | return result; |
| 1116 | } |
| 1117 | |
| 1118 | static int rc_tiocmset(struct tty_struct *tty, struct file *file, |
| 1119 | unsigned int set, unsigned int clear) |
| 1120 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1121 | struct riscom_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | unsigned long flags; |
| 1123 | struct riscom_board *bp; |
| 1124 | |
Harvey Harrison | bf9d892 | 2008-04-30 00:55:10 -0700 | [diff] [blame] | 1125 | if (rc_paranoia_check(port, tty->name, __func__)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | return -ENODEV; |
| 1127 | |
| 1128 | bp = port_Board(port); |
| 1129 | |
Jeff Garzik | d9afa43 | 2008-02-06 01:36:11 -0800 | [diff] [blame] | 1130 | spin_lock_irqsave(&riscom_lock, flags); |
| 1131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | if (set & TIOCM_RTS) |
| 1133 | port->MSVR |= MSVR_RTS; |
| 1134 | if (set & TIOCM_DTR) |
| 1135 | bp->DTR &= ~(1u << port_No(port)); |
| 1136 | |
| 1137 | if (clear & TIOCM_RTS) |
| 1138 | port->MSVR &= ~MSVR_RTS; |
| 1139 | if (clear & TIOCM_DTR) |
| 1140 | bp->DTR |= (1u << port_No(port)); |
| 1141 | |
| 1142 | rc_out(bp, CD180_CAR, port_No(port)); |
| 1143 | rc_out(bp, CD180_MSVR, port->MSVR); |
| 1144 | rc_out(bp, RC_DTR, bp->DTR); |
Jeff Garzik | d9afa43 | 2008-02-06 01:36:11 -0800 | [diff] [blame] | 1145 | |
| 1146 | spin_unlock_irqrestore(&riscom_lock, flags); |
| 1147 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | return 0; |
| 1149 | } |
| 1150 | |
Alan Cox | 781cff5 | 2008-07-22 11:18:30 +0100 | [diff] [blame] | 1151 | static int rc_send_break(struct tty_struct *tty, int length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1153 | struct riscom_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | struct riscom_board *bp = port_Board(port); |
| 1155 | unsigned long flags; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1156 | |
Alan Cox | 781cff5 | 2008-07-22 11:18:30 +0100 | [diff] [blame] | 1157 | if (length == 0 || length == -1) |
| 1158 | return -EOPNOTSUPP; |
| 1159 | |
Jeff Garzik | d9afa43 | 2008-02-06 01:36:11 -0800 | [diff] [blame] | 1160 | spin_lock_irqsave(&riscom_lock, flags); |
| 1161 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | port->break_length = RISCOM_TPS / HZ * length; |
| 1163 | port->COR2 |= COR2_ETC; |
| 1164 | port->IER |= IER_TXRDY; |
| 1165 | rc_out(bp, CD180_CAR, port_No(port)); |
| 1166 | rc_out(bp, CD180_COR2, port->COR2); |
| 1167 | rc_out(bp, CD180_IER, port->IER); |
| 1168 | rc_wait_CCR(bp); |
| 1169 | rc_out(bp, CD180_CCR, CCR_CORCHG2); |
| 1170 | rc_wait_CCR(bp); |
Jeff Garzik | d9afa43 | 2008-02-06 01:36:11 -0800 | [diff] [blame] | 1171 | |
| 1172 | spin_unlock_irqrestore(&riscom_lock, flags); |
Alan Cox | 781cff5 | 2008-07-22 11:18:30 +0100 | [diff] [blame] | 1173 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | } |
| 1175 | |
Alan Cox | 6ff1ab2 | 2009-09-19 13:13:22 -0700 | [diff] [blame] | 1176 | static int rc_set_serial_info(struct tty_struct *tty, struct riscom_port *port, |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1177 | struct serial_struct __user *newinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | { |
| 1179 | struct serial_struct tmp; |
| 1180 | struct riscom_board *bp = port_Board(port); |
| 1181 | int change_speed; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1182 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | if (copy_from_user(&tmp, newinfo, sizeof(tmp))) |
| 1184 | return -EFAULT; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1185 | |
Alan Cox | bf936f9 | 2010-06-01 22:52:43 +0200 | [diff] [blame] | 1186 | mutex_lock(&port->port.mutex); |
Alan Cox | 85f8f81 | 2008-07-16 21:55:29 +0100 | [diff] [blame] | 1187 | change_speed = ((port->port.flags & ASYNC_SPD_MASK) != |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | (tmp.flags & ASYNC_SPD_MASK)); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1189 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | if (!capable(CAP_SYS_ADMIN)) { |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1191 | if ((tmp.close_delay != port->port.close_delay) || |
| 1192 | (tmp.closing_wait != port->port.closing_wait) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | ((tmp.flags & ~ASYNC_USR_MASK) != |
Alan Cox | bf936f9 | 2010-06-01 22:52:43 +0200 | [diff] [blame] | 1194 | (port->port.flags & ~ASYNC_USR_MASK))) { |
| 1195 | mutex_unlock(&port->port.mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | return -EPERM; |
Alan Cox | bf936f9 | 2010-06-01 22:52:43 +0200 | [diff] [blame] | 1197 | } |
Alan Cox | 85f8f81 | 2008-07-16 21:55:29 +0100 | [diff] [blame] | 1198 | port->port.flags = ((port->port.flags & ~ASYNC_USR_MASK) | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | (tmp.flags & ASYNC_USR_MASK)); |
| 1200 | } else { |
Alan Cox | 85f8f81 | 2008-07-16 21:55:29 +0100 | [diff] [blame] | 1201 | port->port.flags = ((port->port.flags & ~ASYNC_FLAGS) | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1202 | (tmp.flags & ASYNC_FLAGS)); |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1203 | port->port.close_delay = tmp.close_delay; |
| 1204 | port->port.closing_wait = tmp.closing_wait; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | } |
| 1206 | if (change_speed) { |
Jeff Garzik | d9afa43 | 2008-02-06 01:36:11 -0800 | [diff] [blame] | 1207 | unsigned long flags; |
| 1208 | |
| 1209 | spin_lock_irqsave(&riscom_lock, flags); |
Alan Cox | 6ff1ab2 | 2009-09-19 13:13:22 -0700 | [diff] [blame] | 1210 | rc_change_speed(tty, bp, port); |
Jeff Garzik | d9afa43 | 2008-02-06 01:36:11 -0800 | [diff] [blame] | 1211 | spin_unlock_irqrestore(&riscom_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | } |
Alan Cox | bf936f9 | 2010-06-01 22:52:43 +0200 | [diff] [blame] | 1213 | mutex_unlock(&port->port.mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | return 0; |
| 1215 | } |
| 1216 | |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1217 | static int rc_get_serial_info(struct riscom_port *port, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | struct serial_struct __user *retinfo) |
| 1219 | { |
| 1220 | struct serial_struct tmp; |
| 1221 | struct riscom_board *bp = port_Board(port); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1222 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | memset(&tmp, 0, sizeof(tmp)); |
| 1224 | tmp.type = PORT_CIRRUS; |
| 1225 | tmp.line = port - rc_port; |
Alan Cox | bf936f9 | 2010-06-01 22:52:43 +0200 | [diff] [blame] | 1226 | |
| 1227 | mutex_lock(&port->port.mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | tmp.port = bp->base; |
| 1229 | tmp.irq = bp->irq; |
Alan Cox | 85f8f81 | 2008-07-16 21:55:29 +0100 | [diff] [blame] | 1230 | tmp.flags = port->port.flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | tmp.baud_base = (RC_OSCFREQ + CD180_TPC/2) / CD180_TPC; |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1232 | tmp.close_delay = port->port.close_delay * HZ/100; |
| 1233 | tmp.closing_wait = port->port.closing_wait * HZ/100; |
Alan Cox | bf936f9 | 2010-06-01 22:52:43 +0200 | [diff] [blame] | 1234 | mutex_unlock(&port->port.mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | tmp.xmit_fifo_size = CD180_NFIFO; |
| 1236 | return copy_to_user(retinfo, &tmp, sizeof(tmp)) ? -EFAULT : 0; |
| 1237 | } |
| 1238 | |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1239 | static int rc_ioctl(struct tty_struct *tty, struct file *filp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1242 | struct riscom_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | void __user *argp = (void __user *)arg; |
Alan Cox | 781cff5 | 2008-07-22 11:18:30 +0100 | [diff] [blame] | 1244 | int retval; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1245 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | if (rc_paranoia_check(port, tty->name, "rc_ioctl")) |
| 1247 | return -ENODEV; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1248 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | switch (cmd) { |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1250 | case TIOCGSERIAL: |
Alan Cox | eb17455 | 2008-04-30 00:53:21 -0700 | [diff] [blame] | 1251 | retval = rc_get_serial_info(port, argp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | break; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1253 | case TIOCSSERIAL: |
Alan Cox | 6ff1ab2 | 2009-09-19 13:13:22 -0700 | [diff] [blame] | 1254 | retval = rc_set_serial_info(tty, port, argp); |
Alan Cox | eb17455 | 2008-04-30 00:53:21 -0700 | [diff] [blame] | 1255 | break; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1256 | default: |
Alan Cox | eb17455 | 2008-04-30 00:53:21 -0700 | [diff] [blame] | 1257 | retval = -ENOIOCTLCMD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | } |
Alan Cox | eb17455 | 2008-04-30 00:53:21 -0700 | [diff] [blame] | 1259 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | } |
| 1261 | |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1262 | static void rc_throttle(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1264 | struct riscom_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | struct riscom_board *bp; |
| 1266 | unsigned long flags; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1267 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | if (rc_paranoia_check(port, tty->name, "rc_throttle")) |
| 1269 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | bp = port_Board(port); |
Jeff Garzik | d9afa43 | 2008-02-06 01:36:11 -0800 | [diff] [blame] | 1271 | |
| 1272 | spin_lock_irqsave(&riscom_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 | port->MSVR &= ~MSVR_RTS; |
| 1274 | rc_out(bp, CD180_CAR, port_No(port)); |
Jeff Garzik | d9afa43 | 2008-02-06 01:36:11 -0800 | [diff] [blame] | 1275 | if (I_IXOFF(tty)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | rc_wait_CCR(bp); |
| 1277 | rc_out(bp, CD180_CCR, CCR_SSCH2); |
| 1278 | rc_wait_CCR(bp); |
| 1279 | } |
| 1280 | rc_out(bp, CD180_MSVR, port->MSVR); |
Jeff Garzik | d9afa43 | 2008-02-06 01:36:11 -0800 | [diff] [blame] | 1281 | spin_unlock_irqrestore(&riscom_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | } |
| 1283 | |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1284 | static void rc_unthrottle(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1286 | struct riscom_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1287 | struct riscom_board *bp; |
| 1288 | unsigned long flags; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1289 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1290 | if (rc_paranoia_check(port, tty->name, "rc_unthrottle")) |
| 1291 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | bp = port_Board(port); |
Jeff Garzik | d9afa43 | 2008-02-06 01:36:11 -0800 | [diff] [blame] | 1293 | |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1294 | spin_lock_irqsave(&riscom_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | port->MSVR |= MSVR_RTS; |
| 1296 | rc_out(bp, CD180_CAR, port_No(port)); |
| 1297 | if (I_IXOFF(tty)) { |
| 1298 | rc_wait_CCR(bp); |
| 1299 | rc_out(bp, CD180_CCR, CCR_SSCH1); |
| 1300 | rc_wait_CCR(bp); |
| 1301 | } |
| 1302 | rc_out(bp, CD180_MSVR, port->MSVR); |
Jeff Garzik | d9afa43 | 2008-02-06 01:36:11 -0800 | [diff] [blame] | 1303 | spin_unlock_irqrestore(&riscom_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1304 | } |
| 1305 | |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1306 | static void rc_stop(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1308 | struct riscom_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | struct riscom_board *bp; |
| 1310 | unsigned long flags; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1311 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | if (rc_paranoia_check(port, tty->name, "rc_stop")) |
| 1313 | return; |
Jeff Garzik | d9afa43 | 2008-02-06 01:36:11 -0800 | [diff] [blame] | 1314 | |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1315 | bp = port_Board(port); |
| 1316 | |
| 1317 | spin_lock_irqsave(&riscom_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | port->IER &= ~IER_TXRDY; |
| 1319 | rc_out(bp, CD180_CAR, port_No(port)); |
| 1320 | rc_out(bp, CD180_IER, port->IER); |
Jeff Garzik | d9afa43 | 2008-02-06 01:36:11 -0800 | [diff] [blame] | 1321 | spin_unlock_irqrestore(&riscom_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1322 | } |
| 1323 | |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1324 | static void rc_start(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1326 | struct riscom_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | struct riscom_board *bp; |
| 1328 | unsigned long flags; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1329 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | if (rc_paranoia_check(port, tty->name, "rc_start")) |
| 1331 | return; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1332 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | bp = port_Board(port); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1334 | |
Jeff Garzik | d9afa43 | 2008-02-06 01:36:11 -0800 | [diff] [blame] | 1335 | spin_lock_irqsave(&riscom_lock, flags); |
| 1336 | |
Alan Cox | 85f8f81 | 2008-07-16 21:55:29 +0100 | [diff] [blame] | 1337 | if (port->xmit_cnt && port->port.xmit_buf && !(port->IER & IER_TXRDY)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1338 | port->IER |= IER_TXRDY; |
| 1339 | rc_out(bp, CD180_CAR, port_No(port)); |
| 1340 | rc_out(bp, CD180_IER, port->IER); |
| 1341 | } |
Jeff Garzik | d9afa43 | 2008-02-06 01:36:11 -0800 | [diff] [blame] | 1342 | spin_unlock_irqrestore(&riscom_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1343 | } |
| 1344 | |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1345 | static void rc_hangup(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1347 | struct riscom_port *port = tty->driver_data; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1348 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | if (rc_paranoia_check(port, tty->name, "rc_hangup")) |
| 1350 | return; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1351 | |
Alan Cox | 6ff1ab2 | 2009-09-19 13:13:22 -0700 | [diff] [blame] | 1352 | tty_port_hangup(&port->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | } |
| 1354 | |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1355 | static void rc_set_termios(struct tty_struct *tty, |
| 1356 | struct ktermios *old_termios) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1357 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1358 | struct riscom_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | unsigned long flags; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1360 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | if (rc_paranoia_check(port, tty->name, "rc_set_termios")) |
| 1362 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | |
Jeff Garzik | d9afa43 | 2008-02-06 01:36:11 -0800 | [diff] [blame] | 1364 | spin_lock_irqsave(&riscom_lock, flags); |
Alan Cox | 6ff1ab2 | 2009-09-19 13:13:22 -0700 | [diff] [blame] | 1365 | rc_change_speed(tty, port_Board(port), port); |
Jeff Garzik | d9afa43 | 2008-02-06 01:36:11 -0800 | [diff] [blame] | 1366 | spin_unlock_irqrestore(&riscom_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | |
| 1368 | if ((old_termios->c_cflag & CRTSCTS) && |
| 1369 | !(tty->termios->c_cflag & CRTSCTS)) { |
| 1370 | tty->hw_stopped = 0; |
| 1371 | rc_start(tty); |
| 1372 | } |
| 1373 | } |
| 1374 | |
Jeff Dike | b68e31d | 2006-10-02 02:17:18 -0700 | [diff] [blame] | 1375 | static const struct tty_operations riscom_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1376 | .open = rc_open, |
| 1377 | .close = rc_close, |
| 1378 | .write = rc_write, |
| 1379 | .put_char = rc_put_char, |
| 1380 | .flush_chars = rc_flush_chars, |
| 1381 | .write_room = rc_write_room, |
| 1382 | .chars_in_buffer = rc_chars_in_buffer, |
| 1383 | .flush_buffer = rc_flush_buffer, |
| 1384 | .ioctl = rc_ioctl, |
| 1385 | .throttle = rc_throttle, |
| 1386 | .unthrottle = rc_unthrottle, |
| 1387 | .set_termios = rc_set_termios, |
| 1388 | .stop = rc_stop, |
| 1389 | .start = rc_start, |
| 1390 | .hangup = rc_hangup, |
| 1391 | .tiocmget = rc_tiocmget, |
| 1392 | .tiocmset = rc_tiocmset, |
Alan Cox | 781cff5 | 2008-07-22 11:18:30 +0100 | [diff] [blame] | 1393 | .break_ctl = rc_send_break, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1394 | }; |
| 1395 | |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame] | 1396 | static const struct tty_port_operations riscom_port_ops = { |
| 1397 | .carrier_raised = carrier_raised, |
Alan Cox | 8f1e672 | 2009-11-30 13:16:47 +0000 | [diff] [blame] | 1398 | .dtr_rts = dtr_rts, |
Alan Cox | 6ff1ab2 | 2009-09-19 13:13:22 -0700 | [diff] [blame] | 1399 | .shutdown = rc_close_port, |
Alan Cox | 8f1e672 | 2009-11-30 13:16:47 +0000 | [diff] [blame] | 1400 | .activate = rc_activate_port, |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame] | 1401 | }; |
| 1402 | |
| 1403 | |
Jiri Slaby | 1386a82 | 2008-02-07 00:16:36 -0800 | [diff] [blame] | 1404 | static int __init rc_init_drivers(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1405 | { |
| 1406 | int error; |
| 1407 | int i; |
| 1408 | |
| 1409 | riscom_driver = alloc_tty_driver(RC_NBOARD * RC_NPORT); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1410 | if (!riscom_driver) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1411 | return -ENOMEM; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1412 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1413 | riscom_driver->owner = THIS_MODULE; |
| 1414 | riscom_driver->name = "ttyL"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | riscom_driver->major = RISCOM8_NORMAL_MAJOR; |
| 1416 | riscom_driver->type = TTY_DRIVER_TYPE_SERIAL; |
| 1417 | riscom_driver->subtype = SERIAL_TYPE_NORMAL; |
| 1418 | riscom_driver->init_termios = tty_std_termios; |
| 1419 | riscom_driver->init_termios.c_cflag = |
| 1420 | B9600 | CS8 | CREAD | HUPCL | CLOCAL; |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 1421 | riscom_driver->init_termios.c_ispeed = 9600; |
| 1422 | riscom_driver->init_termios.c_ospeed = 9600; |
Alan Cox | 781cff5 | 2008-07-22 11:18:30 +0100 | [diff] [blame] | 1423 | riscom_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_HARDWARE_BREAK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1424 | tty_set_operations(riscom_driver, &riscom_ops); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1425 | error = tty_register_driver(riscom_driver); |
| 1426 | if (error != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1427 | put_tty_driver(riscom_driver); |
| 1428 | printk(KERN_ERR "rc: Couldn't register RISCom/8 driver, " |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1429 | "error = %d\n", error); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | return 1; |
| 1431 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1432 | memset(rc_port, 0, sizeof(rc_port)); |
| 1433 | for (i = 0; i < RC_NPORT * RC_NBOARD; i++) { |
Alan Cox | 85f8f81 | 2008-07-16 21:55:29 +0100 | [diff] [blame] | 1434 | tty_port_init(&rc_port[i].port); |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame] | 1435 | rc_port[i].port.ops = &riscom_port_ops; |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 1436 | rc_port[i].magic = RISCOM8_MAGIC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1437 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | return 0; |
| 1439 | } |
| 1440 | |
| 1441 | static void rc_release_drivers(void) |
| 1442 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1443 | tty_unregister_driver(riscom_driver); |
| 1444 | put_tty_driver(riscom_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 | } |
| 1446 | |
| 1447 | #ifndef MODULE |
| 1448 | /* |
| 1449 | * Called at boot time. |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1450 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | * You can specify IO base for up to RC_NBOARD cards, |
| 1452 | * using line "riscom8=0xiobase1,0xiobase2,.." at LILO prompt. |
| 1453 | * Note that there will be no probing at default |
| 1454 | * addresses in this case. |
| 1455 | * |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1456 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1457 | static int __init riscom8_setup(char *str) |
| 1458 | { |
| 1459 | int ints[RC_NBOARD]; |
| 1460 | int i; |
| 1461 | |
| 1462 | str = get_options(str, ARRAY_SIZE(ints), ints); |
| 1463 | |
| 1464 | for (i = 0; i < RC_NBOARD; i++) { |
| 1465 | if (i < ints[0]) |
| 1466 | rc_board[i].base = ints[i+1]; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1467 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | rc_board[i].base = 0; |
| 1469 | } |
| 1470 | return 1; |
| 1471 | } |
| 1472 | |
| 1473 | __setup("riscom8=", riscom8_setup); |
| 1474 | #endif |
| 1475 | |
| 1476 | static char banner[] __initdata = |
| 1477 | KERN_INFO "rc: SDL RISCom/8 card driver v1.1, (c) D.Gorodchanin " |
| 1478 | "1994-1996.\n"; |
| 1479 | static char no_boards_msg[] __initdata = |
| 1480 | KERN_INFO "rc: No RISCom/8 boards detected.\n"; |
| 1481 | |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1482 | /* |
| 1483 | * This routine must be called by kernel at boot time |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | */ |
| 1485 | static int __init riscom8_init(void) |
| 1486 | { |
| 1487 | int i; |
| 1488 | int found = 0; |
| 1489 | |
| 1490 | printk(banner); |
| 1491 | |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1492 | if (rc_init_drivers()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1493 | return -EIO; |
| 1494 | |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1495 | for (i = 0; i < RC_NBOARD; i++) |
| 1496 | if (rc_board[i].base && !rc_probe(&rc_board[i])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1497 | found++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1498 | if (!found) { |
| 1499 | rc_release_drivers(); |
| 1500 | printk(no_boards_msg); |
| 1501 | return -EIO; |
| 1502 | } |
| 1503 | return 0; |
| 1504 | } |
| 1505 | |
| 1506 | #ifdef MODULE |
| 1507 | static int iobase; |
| 1508 | static int iobase1; |
| 1509 | static int iobase2; |
| 1510 | static int iobase3; |
Rusty Russell | 8d3b33f | 2006-03-25 03:07:05 -0800 | [diff] [blame] | 1511 | module_param(iobase, int, 0); |
| 1512 | module_param(iobase1, int, 0); |
| 1513 | module_param(iobase2, int, 0); |
| 1514 | module_param(iobase3, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1515 | |
| 1516 | MODULE_LICENSE("GPL"); |
Scott James Remnant | 5c9f580 | 2009-04-06 17:33:26 +0100 | [diff] [blame] | 1517 | MODULE_ALIAS_CHARDEV_MAJOR(RISCOM8_NORMAL_MAJOR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1518 | #endif /* MODULE */ |
| 1519 | |
| 1520 | /* |
| 1521 | * You can setup up to 4 boards (current value of RC_NBOARD) |
| 1522 | * by specifying "iobase=0xXXX iobase1=0xXXX ..." as insmod parameter. |
| 1523 | * |
| 1524 | */ |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1525 | static int __init riscom8_init_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | { |
| 1527 | #ifdef MODULE |
| 1528 | int i; |
| 1529 | |
| 1530 | if (iobase || iobase1 || iobase2 || iobase3) { |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1531 | for (i = 0; i < RC_NBOARD; i++) |
Jiri Slaby | 9efda79 | 2008-03-13 12:32:39 -0700 | [diff] [blame] | 1532 | rc_board[i].base = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1533 | } |
| 1534 | |
| 1535 | if (iobase) |
| 1536 | rc_board[0].base = iobase; |
| 1537 | if (iobase1) |
| 1538 | rc_board[1].base = iobase1; |
| 1539 | if (iobase2) |
| 1540 | rc_board[2].base = iobase2; |
| 1541 | if (iobase3) |
| 1542 | rc_board[3].base = iobase3; |
| 1543 | #endif /* MODULE */ |
| 1544 | |
| 1545 | return riscom8_init(); |
| 1546 | } |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1547 | |
| 1548 | static void __exit riscom8_exit_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1549 | { |
| 1550 | int i; |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1551 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1552 | rc_release_drivers(); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1553 | for (i = 0; i < RC_NBOARD; i++) |
| 1554 | if (rc_board[i].flags & RC_BOARD_PRESENT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1555 | rc_release_io_range(&rc_board[i]); |
Alan Cox | 9492e13 | 2008-04-30 00:54:15 -0700 | [diff] [blame] | 1556 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | } |
| 1558 | |
| 1559 | module_init(riscom8_init_module); |
| 1560 | module_exit(riscom8_exit_module); |