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