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