blob: 0a8d1e56c99362e0da9b1df06c2452d30341d006 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Cox9492e132008-04-30 00:54:15 -07007 * 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 Torvalds1da177e2005-04-16 15:20:36 -070010 * 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 Cox9492e132008-04-30 00:54:15 -070036#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#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 Cox33f0f882006-01-09 20:54:13 -080049#include <linux/tty_flip.h>
Alexey Dobriyan405f5572009-07-11 22:08:37 +040050#include <linux/smp_lock.h>
Jeff Garzikd9afa432008-02-06 01:36:11 -080051#include <linux/spinlock.h>
Scott James Remnant5c9f5802009-04-06 17:33:26 +010052#include <linux/device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Alan Cox9492e132008-04-30 00:54:15 -070054#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56#include "riscom8.h"
57#include "riscom8_reg.h"
58
59/* Am I paranoid or not ? ;-) */
60#define RISCOM_PARANOIA_CHECK
61
Alan Cox9492e132008-04-30 00:54:15 -070062/*
63 * Crazy InteliCom/8 boards sometimes have swapped CTS & DSR signals.
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 * You can slightly speed up things by #undefing the following option,
Alan Cox9492e132008-04-30 00:54:15 -070065 * if you are REALLY sure that your board is correct one.
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 */
67
68#define RISCOM_BRAIN_DAMAGED_CTS
69
Alan Cox9492e132008-04-30 00:54:15 -070070/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 * The following defines are mostly for testing purposes. But if you need
72 * some nice reporting in your syslog, you can define them also.
73 */
74#undef RC_REPORT_FIFO
75#undef RC_REPORT_OVERRUN
76
77
78#define RISCOM_LEGAL_FLAGS \
79 (ASYNC_HUP_NOTIFY | ASYNC_SAK | ASYNC_SPLIT_TERMIOS | \
80 ASYNC_SPD_HI | ASYNC_SPEED_VHI | ASYNC_SESSION_LOCKOUT | \
81 ASYNC_PGRP_LOCKOUT | ASYNC_CALLOUT_NOHUP)
82
Linus Torvalds1da177e2005-04-16 15:20:36 -070083static struct tty_driver *riscom_driver;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
Jeff Garzikd9afa432008-02-06 01:36:11 -080085static DEFINE_SPINLOCK(riscom_lock);
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087static struct riscom_board rc_board[RC_NBOARD] = {
88 {
89 .base = RC_IOBASE1,
90 },
91 {
92 .base = RC_IOBASE2,
93 },
94 {
95 .base = RC_IOBASE3,
96 },
97 {
98 .base = RC_IOBASE4,
99 },
100};
101
102static struct riscom_port rc_port[RC_NBOARD * RC_NPORT];
103
104/* RISCom/8 I/O ports addresses (without address translation) */
105static unsigned short rc_ioport[] = {
Tobias Klauserfe971072006-01-09 20:54:02 -0800106#if 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0c,
Tobias Klauserfe971072006-01-09 20:54:02 -0800108#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0c, 0x10,
110 0x11, 0x12, 0x18, 0x28, 0x31, 0x32, 0x39, 0x3a, 0x40, 0x41, 0x61, 0x62,
111 0x63, 0x64, 0x6b, 0x70, 0x71, 0x78, 0x7a, 0x7b, 0x7f, 0x100, 0x101
Tobias Klauserfe971072006-01-09 20:54:02 -0800112#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113};
Tobias Klauserfe971072006-01-09 20:54:02 -0800114#define RC_NIOPORT ARRAY_SIZE(rc_ioport)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
116
Alan Cox9492e132008-04-30 00:54:15 -0700117static int rc_paranoia_check(struct riscom_port const *port,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 char *name, const char *routine)
119{
120#ifdef RISCOM_PARANOIA_CHECK
121 static const char badmagic[] = KERN_INFO
122 "rc: Warning: bad riscom port magic number for device %s in %s\n";
123 static const char badinfo[] = KERN_INFO
124 "rc: Warning: null riscom port for device %s in %s\n";
125
126 if (!port) {
127 printk(badinfo, name, routine);
128 return 1;
129 }
130 if (port->magic != RISCOM8_MAGIC) {
131 printk(badmagic, name, routine);
132 return 1;
133 }
134#endif
135 return 0;
136}
137
138/*
Alan Cox9492e132008-04-30 00:54:15 -0700139 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 * Service functions for RISCom/8 driver.
Alan Cox9492e132008-04-30 00:54:15 -0700141 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 */
143
144/* Get board number from pointer */
Alan Cox9492e132008-04-30 00:54:15 -0700145static inline int board_No(struct riscom_board const *bp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146{
147 return bp - rc_board;
148}
149
150/* Get port number from pointer */
Alan Cox9492e132008-04-30 00:54:15 -0700151static inline int port_No(struct riscom_port const *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152{
Alan Cox9492e132008-04-30 00:54:15 -0700153 return RC_PORT(port - rc_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154}
155
156/* Get pointer to board from pointer to port */
Alan Cox9492e132008-04-30 00:54:15 -0700157static inline struct riscom_board *port_Board(struct riscom_port const *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158{
159 return &rc_board[RC_BOARD(port - rc_port)];
160}
161
162/* Input Byte from CL CD180 register */
Alan Cox9492e132008-04-30 00:54:15 -0700163static inline unsigned char rc_in(struct riscom_board const *bp,
164 unsigned short reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165{
166 return inb(bp->base + RC_TO_ISA(reg));
167}
168
169/* Output Byte to CL CD180 register */
Alan Cox9492e132008-04-30 00:54:15 -0700170static inline void rc_out(struct riscom_board const *bp, unsigned short reg,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 unsigned char val)
172{
173 outb(val, bp->base + RC_TO_ISA(reg));
174}
175
176/* Wait for Channel Command Register ready */
Alan Cox9492e132008-04-30 00:54:15 -0700177static void rc_wait_CCR(struct riscom_board const *bp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178{
179 unsigned long delay;
180
181 /* FIXME: need something more descriptive then 100000 :) */
Alan Cox9492e132008-04-30 00:54:15 -0700182 for (delay = 100000; delay; delay--)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 if (!rc_in(bp, CD180_CCR))
184 return;
Alan Cox9492e132008-04-30 00:54:15 -0700185
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 printk(KERN_INFO "rc%d: Timeout waiting for CCR.\n", board_No(bp));
187}
188
189/*
190 * RISCom/8 probe functions.
191 */
192
Alan Cox9492e132008-04-30 00:54:15 -0700193static int rc_request_io_range(struct riscom_board * const bp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194{
195 int i;
Alan Cox9492e132008-04-30 00:54:15 -0700196
197 for (i = 0; i < RC_NIOPORT; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 if (!request_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1,
199 "RISCom/8")) {
200 goto out_release;
201 }
202 return 0;
203out_release:
204 printk(KERN_INFO "rc%d: Skipping probe at 0x%03x. IO address in use.\n",
205 board_No(bp), bp->base);
Alan Cox9492e132008-04-30 00:54:15 -0700206 while (--i >= 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 release_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1);
208 return 1;
209}
210
Alan Cox9492e132008-04-30 00:54:15 -0700211static void rc_release_io_range(struct riscom_board * const bp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212{
213 int i;
Alan Cox9492e132008-04-30 00:54:15 -0700214
215 for (i = 0; i < RC_NIOPORT; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 release_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1);
217}
Alan Cox9492e132008-04-30 00:54:15 -0700218
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219/* Reset and setup CD180 chip */
Alan Cox9492e132008-04-30 00:54:15 -0700220static void __init rc_init_CD180(struct riscom_board const *bp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221{
222 unsigned long flags;
Alan Cox9492e132008-04-30 00:54:15 -0700223
Jeff Garzikd9afa432008-02-06 01:36:11 -0800224 spin_lock_irqsave(&riscom_lock, flags);
225
Alan Cox9492e132008-04-30 00:54:15 -0700226 rc_out(bp, RC_CTOUT, 0); /* Clear timeout */
227 rc_wait_CCR(bp); /* Wait for CCR ready */
228 rc_out(bp, CD180_CCR, CCR_HARDRESET); /* Reset CD180 chip */
Jeff Garzikd9afa432008-02-06 01:36:11 -0800229 spin_unlock_irqrestore(&riscom_lock, flags);
Alan Cox9492e132008-04-30 00:54:15 -0700230 msleep(50); /* Delay 0.05 sec */
Jeff Garzikd9afa432008-02-06 01:36:11 -0800231 spin_lock_irqsave(&riscom_lock, flags);
Alan Cox9492e132008-04-30 00:54:15 -0700232 rc_out(bp, CD180_GIVR, RC_ID); /* Set ID for this chip */
233 rc_out(bp, CD180_GICR, 0); /* Clear all bits */
234 rc_out(bp, CD180_PILR1, RC_ACK_MINT); /* Prio for modem intr */
235 rc_out(bp, CD180_PILR2, RC_ACK_TINT); /* Prio for tx intr */
236 rc_out(bp, CD180_PILR3, RC_ACK_RINT); /* Prio for rx intr */
237
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 /* Setting up prescaler. We need 4 ticks per 1 ms */
239 rc_out(bp, CD180_PPRH, (RC_OSCFREQ/(1000000/RISCOM_TPS)) >> 8);
240 rc_out(bp, CD180_PPRL, (RC_OSCFREQ/(1000000/RISCOM_TPS)) & 0xff);
Alan Cox9492e132008-04-30 00:54:15 -0700241
Jeff Garzikd9afa432008-02-06 01:36:11 -0800242 spin_unlock_irqrestore(&riscom_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243}
244
245/* Main probing routine, also sets irq. */
246static int __init rc_probe(struct riscom_board *bp)
247{
248 unsigned char val1, val2;
249 int irqs = 0;
250 int retries;
Alan Cox9492e132008-04-30 00:54:15 -0700251
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 bp->irq = 0;
253
254 if (rc_request_io_range(bp))
255 return 1;
Alan Cox9492e132008-04-30 00:54:15 -0700256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 /* Are the I/O ports here ? */
258 rc_out(bp, CD180_PPRL, 0x5a);
259 outb(0xff, 0x80);
260 val1 = rc_in(bp, CD180_PPRL);
261 rc_out(bp, CD180_PPRL, 0xa5);
262 outb(0x00, 0x80);
263 val2 = rc_in(bp, CD180_PPRL);
Alan Cox9492e132008-04-30 00:54:15 -0700264
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 if ((val1 != 0x5a) || (val2 != 0xa5)) {
266 printk(KERN_ERR "rc%d: RISCom/8 Board at 0x%03x not found.\n",
267 board_No(bp), bp->base);
268 goto out_release;
269 }
Alan Cox9492e132008-04-30 00:54:15 -0700270
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 /* It's time to find IRQ for this board */
Alan Cox9492e132008-04-30 00:54:15 -0700272 for (retries = 0; retries < 5 && irqs <= 0; retries++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 irqs = probe_irq_on();
Alan Cox9492e132008-04-30 00:54:15 -0700274 rc_init_CD180(bp); /* Reset CD180 chip */
275 rc_out(bp, CD180_CAR, 2); /* Select port 2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 rc_wait_CCR(bp);
Alan Cox9492e132008-04-30 00:54:15 -0700277 rc_out(bp, CD180_CCR, CCR_TXEN); /* Enable transmitter */
278 rc_out(bp, CD180_IER, IER_TXRDY);/* Enable tx empty intr */
Jiri Slabyc4ebd922007-07-17 04:05:20 -0700279 msleep(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 irqs = probe_irq_off(irqs);
Alan Cox9492e132008-04-30 00:54:15 -0700281 val1 = rc_in(bp, RC_BSR); /* Get Board Status reg */
282 val2 = rc_in(bp, RC_ACK_TINT); /* ACK interrupt */
283 rc_init_CD180(bp); /* Reset CD180 again */
284
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 if ((val1 & RC_BSR_TINT) || (val2 != (RC_ID | GIVR_IT_TX))) {
286 printk(KERN_ERR "rc%d: RISCom/8 Board at 0x%03x not "
287 "found.\n", board_No(bp), bp->base);
288 goto out_release;
289 }
290 }
Alan Cox9492e132008-04-30 00:54:15 -0700291
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 if (irqs <= 0) {
293 printk(KERN_ERR "rc%d: Can't find IRQ for RISCom/8 board "
294 "at 0x%03x.\n", board_No(bp), bp->base);
295 goto out_release;
296 }
297 bp->irq = irqs;
298 bp->flags |= RC_BOARD_PRESENT;
Alan Cox9492e132008-04-30 00:54:15 -0700299
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 printk(KERN_INFO "rc%d: RISCom/8 Rev. %c board detected at "
301 "0x%03x, IRQ %d.\n",
302 board_No(bp),
303 (rc_in(bp, CD180_GFRCR) & 0x0f) + 'A', /* Board revision */
304 bp->base, bp->irq);
Alan Cox9492e132008-04-30 00:54:15 -0700305
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 return 0;
307out_release:
308 rc_release_io_range(bp);
309 return 1;
310}
311
Alan Cox9492e132008-04-30 00:54:15 -0700312/*
313 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 * Interrupt processing routines.
Alan Cox9492e132008-04-30 00:54:15 -0700315 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 */
317
Alan Cox9492e132008-04-30 00:54:15 -0700318static struct riscom_port *rc_get_port(struct riscom_board const *bp,
319 unsigned char const *what)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320{
321 unsigned char channel;
Alan Cox9492e132008-04-30 00:54:15 -0700322 struct riscom_port *port;
323
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 channel = rc_in(bp, CD180_GICR) >> GICR_CHAN_OFF;
325 if (channel < CD180_NCH) {
326 port = &rc_port[board_No(bp) * RC_NPORT + channel];
Alan Cox85f8f812008-07-16 21:55:29 +0100327 if (port->port.flags & ASYNC_INITIALIZED)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 return port;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 }
Alan Cox9492e132008-04-30 00:54:15 -0700330 printk(KERN_ERR "rc%d: %s interrupt from invalid port %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 board_No(bp), what, channel);
332 return NULL;
333}
334
Alan Cox9492e132008-04-30 00:54:15 -0700335static void rc_receive_exc(struct riscom_board const *bp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336{
337 struct riscom_port *port;
338 struct tty_struct *tty;
339 unsigned char status;
Alan Cox33f0f882006-01-09 20:54:13 -0800340 unsigned char ch, flag;
Alan Cox9492e132008-04-30 00:54:15 -0700341
342 port = rc_get_port(bp, "Receive");
343 if (port == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 return;
345
Alan Cox6ff1ab22009-09-19 13:13:22 -0700346 tty = tty_port_tty_get(&port->port);
Alan Cox9492e132008-04-30 00:54:15 -0700347
348#ifdef RC_REPORT_OVERRUN
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 status = rc_in(bp, CD180_RCSR);
Alan Cox33f0f882006-01-09 20:54:13 -0800350 if (status & RCSR_OE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 port->overrun++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 status &= port->mark_mask;
Alan Cox9492e132008-04-30 00:54:15 -0700353#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 status = rc_in(bp, CD180_RCSR) & port->mark_mask;
Alan Cox9492e132008-04-30 00:54:15 -0700355#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 ch = rc_in(bp, CD180_RDR);
Alan Cox9492e132008-04-30 00:54:15 -0700357 if (!status)
Alan Cox6ff1ab22009-09-19 13:13:22 -0700358 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 if (status & RCSR_TOUT) {
360 printk(KERN_WARNING "rc%d: port %d: Receiver timeout. "
Alan Cox9492e132008-04-30 00:54:15 -0700361 "Hardware problems ?\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 board_No(bp), port_No(port));
Alan Cox6ff1ab22009-09-19 13:13:22 -0700363 goto out;
Alan Cox9492e132008-04-30 00:54:15 -0700364
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 } else if (status & RCSR_BREAK) {
366 printk(KERN_INFO "rc%d: port %d: Handling break...\n",
367 board_No(bp), port_No(port));
Alan Cox33f0f882006-01-09 20:54:13 -0800368 flag = TTY_BREAK;
Alan Cox6ff1ab22009-09-19 13:13:22 -0700369 if (tty && (port->port.flags & ASYNC_SAK))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 do_SAK(tty);
Alan Cox9492e132008-04-30 00:54:15 -0700371
372 } else if (status & RCSR_PE)
Alan Cox33f0f882006-01-09 20:54:13 -0800373 flag = TTY_PARITY;
Alan Cox9492e132008-04-30 00:54:15 -0700374
375 else if (status & RCSR_FE)
Alan Cox33f0f882006-01-09 20:54:13 -0800376 flag = TTY_FRAME;
Alan Cox9492e132008-04-30 00:54:15 -0700377
378 else if (status & RCSR_OE)
Alan Cox33f0f882006-01-09 20:54:13 -0800379 flag = TTY_OVERRUN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 else
Alan Cox33f0f882006-01-09 20:54:13 -0800381 flag = TTY_NORMAL;
Alan Cox9492e132008-04-30 00:54:15 -0700382
Alan Cox6ff1ab22009-09-19 13:13:22 -0700383 if (tty) {
384 tty_insert_flip_char(tty, ch, flag);
385 tty_flip_buffer_push(tty);
386 }
387out:
388 tty_kref_put(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389}
390
Alan Cox9492e132008-04-30 00:54:15 -0700391static void rc_receive(struct riscom_board const *bp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392{
393 struct riscom_port *port;
394 struct tty_struct *tty;
395 unsigned char count;
Alan Cox9492e132008-04-30 00:54:15 -0700396
397 port = rc_get_port(bp, "Receive");
398 if (port == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 return;
Alan Cox9492e132008-04-30 00:54:15 -0700400
Alan Cox6ff1ab22009-09-19 13:13:22 -0700401 tty = tty_port_tty_get(&port->port);
Alan Cox9492e132008-04-30 00:54:15 -0700402
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 count = rc_in(bp, CD180_RDCR);
Alan Cox9492e132008-04-30 00:54:15 -0700404
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405#ifdef RC_REPORT_FIFO
406 port->hits[count > 8 ? 9 : count]++;
Alan Cox9492e132008-04-30 00:54:15 -0700407#endif
408
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 while (count--) {
Alan Cox6ff1ab22009-09-19 13:13:22 -0700410 u8 ch = rc_in(bp, CD180_RDR);
411 if (tty)
412 tty_insert_flip_char(tty, ch, TTY_NORMAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 }
Alan Cox6ff1ab22009-09-19 13:13:22 -0700414 if (tty) {
415 tty_flip_buffer_push(tty);
416 tty_kref_put(tty);
417 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418}
419
Alan Cox9492e132008-04-30 00:54:15 -0700420static void rc_transmit(struct riscom_board const *bp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421{
422 struct riscom_port *port;
423 struct tty_struct *tty;
424 unsigned char count;
Alan Cox9492e132008-04-30 00:54:15 -0700425
426 port = rc_get_port(bp, "Transmit");
427 if (port == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 return;
Alan Cox9492e132008-04-30 00:54:15 -0700429
Alan Cox6ff1ab22009-09-19 13:13:22 -0700430 tty = tty_port_tty_get(&port->port);
Alan Cox9492e132008-04-30 00:54:15 -0700431
432 if (port->IER & IER_TXEMPTY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 /* FIFO drained */
434 rc_out(bp, CD180_CAR, port_No(port));
435 port->IER &= ~IER_TXEMPTY;
436 rc_out(bp, CD180_IER, port->IER);
Alan Cox6ff1ab22009-09-19 13:13:22 -0700437 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 }
Alan Cox9492e132008-04-30 00:54:15 -0700439
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 if ((port->xmit_cnt <= 0 && !port->break_length)
Alan Cox6ff1ab22009-09-19 13:13:22 -0700441 || (tty && (tty->stopped || tty->hw_stopped))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 rc_out(bp, CD180_CAR, port_No(port));
443 port->IER &= ~IER_TXRDY;
444 rc_out(bp, CD180_IER, port->IER);
Alan Cox6ff1ab22009-09-19 13:13:22 -0700445 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 }
Alan Cox9492e132008-04-30 00:54:15 -0700447
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 if (port->break_length) {
449 if (port->break_length > 0) {
450 if (port->COR2 & COR2_ETC) {
451 rc_out(bp, CD180_TDR, CD180_C_ESC);
452 rc_out(bp, CD180_TDR, CD180_C_SBRK);
453 port->COR2 &= ~COR2_ETC;
454 }
455 count = min_t(int, port->break_length, 0xff);
456 rc_out(bp, CD180_TDR, CD180_C_ESC);
457 rc_out(bp, CD180_TDR, CD180_C_DELAY);
458 rc_out(bp, CD180_TDR, count);
Alan Cox9492e132008-04-30 00:54:15 -0700459 port->break_length -= count;
460 if (port->break_length == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 port->break_length--;
462 } else {
463 rc_out(bp, CD180_TDR, CD180_C_ESC);
464 rc_out(bp, CD180_TDR, CD180_C_EBRK);
465 rc_out(bp, CD180_COR2, port->COR2);
466 rc_wait_CCR(bp);
467 rc_out(bp, CD180_CCR, CCR_CORCHG2);
468 port->break_length = 0;
469 }
Jiri Slaby7e63d0c2009-09-06 23:10:09 +0200470 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 }
Alan Cox9492e132008-04-30 00:54:15 -0700472
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 count = CD180_NFIFO;
474 do {
Alan Cox85f8f812008-07-16 21:55:29 +0100475 rc_out(bp, CD180_TDR, port->port.xmit_buf[port->xmit_tail++]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 port->xmit_tail = port->xmit_tail & (SERIAL_XMIT_SIZE-1);
477 if (--port->xmit_cnt <= 0)
478 break;
479 } while (--count > 0);
Alan Cox9492e132008-04-30 00:54:15 -0700480
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 if (port->xmit_cnt <= 0) {
482 rc_out(bp, CD180_CAR, port_No(port));
483 port->IER &= ~IER_TXRDY;
484 rc_out(bp, CD180_IER, port->IER);
485 }
Alan Cox6ff1ab22009-09-19 13:13:22 -0700486 if (tty && port->xmit_cnt <= port->wakeup_chars)
Jiri Slabyb98e70d2008-02-07 00:16:41 -0800487 tty_wakeup(tty);
Alan Cox6ff1ab22009-09-19 13:13:22 -0700488out:
489 tty_kref_put(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490}
491
Alan Cox9492e132008-04-30 00:54:15 -0700492static void rc_check_modem(struct riscom_board const *bp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493{
494 struct riscom_port *port;
495 struct tty_struct *tty;
496 unsigned char mcr;
Alan Cox9492e132008-04-30 00:54:15 -0700497
498 port = rc_get_port(bp, "Modem");
499 if (port == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 return;
Alan Cox9492e132008-04-30 00:54:15 -0700501
Alan Cox6ff1ab22009-09-19 13:13:22 -0700502 tty = tty_port_tty_get(&port->port);
Alan Cox9492e132008-04-30 00:54:15 -0700503
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 mcr = rc_in(bp, CD180_MCR);
Alan Cox9492e132008-04-30 00:54:15 -0700505 if (mcr & MCR_CDCHG) {
506 if (rc_in(bp, CD180_MSVR) & MSVR_CD)
Alan Cox85f8f812008-07-16 21:55:29 +0100507 wake_up_interruptible(&port->port.open_wait);
Alan Cox6ff1ab22009-09-19 13:13:22 -0700508 else if (tty)
Jiri Slabyb98e70d2008-02-07 00:16:41 -0800509 tty_hangup(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 }
Alan Cox9492e132008-04-30 00:54:15 -0700511
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512#ifdef RISCOM_BRAIN_DAMAGED_CTS
513 if (mcr & MCR_CTSCHG) {
514 if (rc_in(bp, CD180_MSVR) & MSVR_CTS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 port->IER |= IER_TXRDY;
Alan Cox6ff1ab22009-09-19 13:13:22 -0700516 if (tty) {
517 tty->hw_stopped = 0;
518 if (port->xmit_cnt <= port->wakeup_chars)
519 tty_wakeup(tty);
520 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 } else {
Alan Cox6ff1ab22009-09-19 13:13:22 -0700522 if (tty)
523 tty->hw_stopped = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 port->IER &= ~IER_TXRDY;
525 }
526 rc_out(bp, CD180_IER, port->IER);
527 }
528 if (mcr & MCR_DSRCHG) {
529 if (rc_in(bp, CD180_MSVR) & MSVR_DSR) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 port->IER |= IER_TXRDY;
Alan Cox6ff1ab22009-09-19 13:13:22 -0700531 if (tty) {
532 tty->hw_stopped = 0;
533 if (port->xmit_cnt <= port->wakeup_chars)
534 tty_wakeup(tty);
535 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 } else {
Alan Cox6ff1ab22009-09-19 13:13:22 -0700537 if (tty)
538 tty->hw_stopped = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 port->IER &= ~IER_TXRDY;
540 }
541 rc_out(bp, CD180_IER, port->IER);
542 }
543#endif /* RISCOM_BRAIN_DAMAGED_CTS */
Alan Cox9492e132008-04-30 00:54:15 -0700544
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 /* Clear change bits */
546 rc_out(bp, CD180_MCR, 0);
Alan Cox6ff1ab22009-09-19 13:13:22 -0700547 tty_kref_put(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548}
549
550/* The main interrupt processing routine */
Alan Cox9492e132008-04-30 00:54:15 -0700551static irqreturn_t rc_interrupt(int dummy, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552{
553 unsigned char status;
554 unsigned char ack;
Jeff Garzikf07ef392007-10-23 19:12:11 -0400555 struct riscom_board *bp = dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 unsigned long loop = 0;
557 int handled = 0;
558
Jeff Garzikc7bec5a2006-10-06 15:00:58 -0400559 if (!(bp->flags & RC_BOARD_ACTIVE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 return IRQ_NONE;
Jeff Garzikc7bec5a2006-10-06 15:00:58 -0400561
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 while ((++loop < 16) && ((status = ~(rc_in(bp, RC_BSR))) &
563 (RC_BSR_TOUT | RC_BSR_TINT |
564 RC_BSR_MINT | RC_BSR_RINT))) {
565 handled = 1;
Alan Cox9492e132008-04-30 00:54:15 -0700566 if (status & RC_BSR_TOUT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 printk(KERN_WARNING "rc%d: Got timeout. Hardware "
568 "error?\n", board_No(bp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 else if (status & RC_BSR_RINT) {
570 ack = rc_in(bp, RC_ACK_RINT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 if (ack == (RC_ID | GIVR_IT_RCV))
572 rc_receive(bp);
573 else if (ack == (RC_ID | GIVR_IT_REXC))
574 rc_receive_exc(bp);
575 else
576 printk(KERN_WARNING "rc%d: Bad receive ack "
577 "0x%02x.\n",
578 board_No(bp), ack);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 } else if (status & RC_BSR_TINT) {
580 ack = rc_in(bp, RC_ACK_TINT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 if (ack == (RC_ID | GIVR_IT_TX))
582 rc_transmit(bp);
583 else
584 printk(KERN_WARNING "rc%d: Bad transmit ack "
585 "0x%02x.\n",
586 board_No(bp), ack);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 } else /* if (status & RC_BSR_MINT) */ {
588 ack = rc_in(bp, RC_ACK_MINT);
Alan Cox9492e132008-04-30 00:54:15 -0700589 if (ack == (RC_ID | GIVR_IT_MODEM))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 rc_check_modem(bp);
591 else
592 printk(KERN_WARNING "rc%d: Bad modem ack "
593 "0x%02x.\n",
594 board_No(bp), ack);
Alan Cox9492e132008-04-30 00:54:15 -0700595 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 rc_out(bp, CD180_EOIR, 0); /* Mark end of interrupt */
597 rc_out(bp, RC_CTOUT, 0); /* Clear timeout flag */
598 }
599 return IRQ_RETVAL(handled);
600}
601
602/*
603 * Routines for open & close processing.
604 */
605
606/* Called with disabled interrupts */
Alan Cox9492e132008-04-30 00:54:15 -0700607static int rc_setup_board(struct riscom_board *bp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608{
609 int error;
610
Alan Cox9492e132008-04-30 00:54:15 -0700611 if (bp->flags & RC_BOARD_ACTIVE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 return 0;
Alan Cox9492e132008-04-30 00:54:15 -0700613
Thomas Gleixner0f2ed4c2006-07-01 19:29:33 -0700614 error = request_irq(bp->irq, rc_interrupt, IRQF_DISABLED,
Jeff Garzikf07ef392007-10-23 19:12:11 -0400615 "RISCom/8", bp);
Alan Cox9492e132008-04-30 00:54:15 -0700616 if (error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 return error;
Alan Cox9492e132008-04-30 00:54:15 -0700618
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 rc_out(bp, RC_CTOUT, 0); /* Just in case */
620 bp->DTR = ~0;
621 rc_out(bp, RC_DTR, bp->DTR); /* Drop DTR on all ports */
Alan Cox9492e132008-04-30 00:54:15 -0700622
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 bp->flags |= RC_BOARD_ACTIVE;
Alan Cox9492e132008-04-30 00:54:15 -0700624
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 return 0;
626}
627
628/* Called with disabled interrupts */
Jeff Garzikf07ef392007-10-23 19:12:11 -0400629static void rc_shutdown_board(struct riscom_board *bp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630{
631 if (!(bp->flags & RC_BOARD_ACTIVE))
632 return;
Alan Cox9492e132008-04-30 00:54:15 -0700633
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 bp->flags &= ~RC_BOARD_ACTIVE;
Alan Cox9492e132008-04-30 00:54:15 -0700635
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 free_irq(bp->irq, NULL);
Alan Cox9492e132008-04-30 00:54:15 -0700637
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 bp->DTR = ~0;
639 rc_out(bp, RC_DTR, bp->DTR); /* Drop DTR on all ports */
Alan Cox9492e132008-04-30 00:54:15 -0700640
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641}
642
643/*
Alan Cox9492e132008-04-30 00:54:15 -0700644 * Setting up port characteristics.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 * Must be called with disabled interrupts
646 */
Alan Cox6ff1ab22009-09-19 13:13:22 -0700647static void rc_change_speed(struct tty_struct *tty, struct riscom_board *bp,
648 struct riscom_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 unsigned long baud;
651 long tmp;
652 unsigned char cor1 = 0, cor3 = 0;
653 unsigned char mcor1 = 0, mcor2 = 0;
Alan Cox9492e132008-04-30 00:54:15 -0700654
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 port->IER = 0;
656 port->COR2 = 0;
657 port->MSVR = MSVR_RTS;
Alan Cox9492e132008-04-30 00:54:15 -0700658
Alan Coxc7bce302006-09-30 23:27:24 -0700659 baud = tty_get_baud_rate(tty);
Alan Cox9492e132008-04-30 00:54:15 -0700660
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 /* Select port on the board */
662 rc_out(bp, CD180_CAR, port_No(port));
Alan Cox9492e132008-04-30 00:54:15 -0700663
Alan Coxc7bce302006-09-30 23:27:24 -0700664 if (!baud) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 /* Drop DTR & exit */
666 bp->DTR |= (1u << port_No(port));
667 rc_out(bp, RC_DTR, bp->DTR);
668 return;
669 } else {
670 /* Set DTR on */
671 bp->DTR &= ~(1u << port_No(port));
672 rc_out(bp, RC_DTR, bp->DTR);
673 }
Alan Cox9492e132008-04-30 00:54:15 -0700674
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 /*
Alan Cox9492e132008-04-30 00:54:15 -0700676 * Now we must calculate some speed depended things
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 */
Alan Cox9492e132008-04-30 00:54:15 -0700678
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 /* Set baud rate for port */
Alan Coxc7bce302006-09-30 23:27:24 -0700680 tmp = (((RC_OSCFREQ + baud/2) / baud +
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 CD180_TPC/2) / CD180_TPC);
682
Alan Cox9492e132008-04-30 00:54:15 -0700683 rc_out(bp, CD180_RBPRH, (tmp >> 8) & 0xff);
684 rc_out(bp, CD180_TBPRH, (tmp >> 8) & 0xff);
685 rc_out(bp, CD180_RBPRL, tmp & 0xff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 rc_out(bp, CD180_TBPRL, tmp & 0xff);
Alan Cox9492e132008-04-30 00:54:15 -0700687
Alan Coxc7bce302006-09-30 23:27:24 -0700688 baud = (baud + 5) / 10; /* Estimated CPS */
Alan Cox9492e132008-04-30 00:54:15 -0700689
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 /* Two timer ticks seems enough to wakeup something like SLIP driver */
Alan Cox9492e132008-04-30 00:54:15 -0700691 tmp = ((baud + HZ/2) / HZ) * 2 - CD180_NFIFO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 port->wakeup_chars = (tmp < 0) ? 0 : ((tmp >= SERIAL_XMIT_SIZE) ?
693 SERIAL_XMIT_SIZE - 1 : tmp);
Alan Cox9492e132008-04-30 00:54:15 -0700694
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 /* Receiver timeout will be transmission time for 1.5 chars */
696 tmp = (RISCOM_TPS + RISCOM_TPS/2 + baud/2) / baud;
697 tmp = (tmp > 0xff) ? 0xff : tmp;
698 rc_out(bp, CD180_RTPR, tmp);
Alan Cox9492e132008-04-30 00:54:15 -0700699
700 switch (C_CSIZE(tty)) {
701 case CS5:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 cor1 |= COR1_5BITS;
703 break;
Alan Cox9492e132008-04-30 00:54:15 -0700704 case CS6:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 cor1 |= COR1_6BITS;
706 break;
Alan Cox9492e132008-04-30 00:54:15 -0700707 case CS7:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 cor1 |= COR1_7BITS;
709 break;
Alan Cox9492e132008-04-30 00:54:15 -0700710 case CS8:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 cor1 |= COR1_8BITS;
712 break;
713 }
Alan Cox9492e132008-04-30 00:54:15 -0700714 if (C_CSTOPB(tty))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 cor1 |= COR1_2SB;
Alan Cox9492e132008-04-30 00:54:15 -0700716
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 cor1 |= COR1_IGNORE;
Alan Cox9492e132008-04-30 00:54:15 -0700718 if (C_PARENB(tty)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 cor1 |= COR1_NORMPAR;
Alan Cox9492e132008-04-30 00:54:15 -0700720 if (C_PARODD(tty))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 cor1 |= COR1_ODDP;
Alan Cox9492e132008-04-30 00:54:15 -0700722 if (I_INPCK(tty))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 cor1 &= ~COR1_IGNORE;
724 }
725 /* Set marking of some errors */
726 port->mark_mask = RCSR_OE | RCSR_TOUT;
Alan Cox9492e132008-04-30 00:54:15 -0700727 if (I_INPCK(tty))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 port->mark_mask |= RCSR_FE | RCSR_PE;
Alan Cox9492e132008-04-30 00:54:15 -0700729 if (I_BRKINT(tty) || I_PARMRK(tty))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 port->mark_mask |= RCSR_BREAK;
Alan Cox9492e132008-04-30 00:54:15 -0700731 if (I_IGNPAR(tty))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 port->mark_mask &= ~(RCSR_FE | RCSR_PE);
Alan Cox9492e132008-04-30 00:54:15 -0700733 if (I_IGNBRK(tty)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 port->mark_mask &= ~RCSR_BREAK;
Alan Cox9492e132008-04-30 00:54:15 -0700735 if (I_IGNPAR(tty))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 /* Real raw mode. Ignore all */
737 port->mark_mask &= ~RCSR_OE;
738 }
739 /* Enable Hardware Flow Control */
740 if (C_CRTSCTS(tty)) {
741#ifdef RISCOM_BRAIN_DAMAGED_CTS
742 port->IER |= IER_DSR | IER_CTS;
743 mcor1 |= MCOR1_DSRZD | MCOR1_CTSZD;
744 mcor2 |= MCOR2_DSROD | MCOR2_CTSOD;
Alan Cox9492e132008-04-30 00:54:15 -0700745 tty->hw_stopped = !(rc_in(bp, CD180_MSVR) &
746 (MSVR_CTS|MSVR_DSR));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747#else
748 port->COR2 |= COR2_CTSAE;
749#endif
750 }
751 /* Enable Software Flow Control. FIXME: I'm not sure about this */
752 /* Some people reported that it works, but I still doubt */
753 if (I_IXON(tty)) {
754 port->COR2 |= COR2_TXIBE;
755 cor3 |= (COR3_FCT | COR3_SCDE);
756 if (I_IXANY(tty))
757 port->COR2 |= COR2_IXM;
758 rc_out(bp, CD180_SCHR1, START_CHAR(tty));
759 rc_out(bp, CD180_SCHR2, STOP_CHAR(tty));
760 rc_out(bp, CD180_SCHR3, START_CHAR(tty));
761 rc_out(bp, CD180_SCHR4, STOP_CHAR(tty));
762 }
763 if (!C_CLOCAL(tty)) {
764 /* Enable CD check */
765 port->IER |= IER_CD;
766 mcor1 |= MCOR1_CDZD;
767 mcor2 |= MCOR2_CDOD;
768 }
Alan Cox9492e132008-04-30 00:54:15 -0700769
770 if (C_CREAD(tty))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 /* Enable receiver */
772 port->IER |= IER_RXD;
Alan Cox9492e132008-04-30 00:54:15 -0700773
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 /* Set input FIFO size (1-8 bytes) */
Alan Cox9492e132008-04-30 00:54:15 -0700775 cor3 |= RISCOM_RXFIFO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 /* Setting up CD180 channel registers */
777 rc_out(bp, CD180_COR1, cor1);
778 rc_out(bp, CD180_COR2, port->COR2);
779 rc_out(bp, CD180_COR3, cor3);
780 /* Make CD180 know about registers change */
781 rc_wait_CCR(bp);
782 rc_out(bp, CD180_CCR, CCR_CORCHG1 | CCR_CORCHG2 | CCR_CORCHG3);
783 /* Setting up modem option registers */
784 rc_out(bp, CD180_MCOR1, mcor1);
785 rc_out(bp, CD180_MCOR2, mcor2);
786 /* Enable CD180 transmitter & receiver */
787 rc_wait_CCR(bp);
788 rc_out(bp, CD180_CCR, CCR_TXEN | CCR_RXEN);
789 /* Enable interrupts */
790 rc_out(bp, CD180_IER, port->IER);
791 /* And finally set RTS on */
792 rc_out(bp, CD180_MSVR, port->MSVR);
793}
794
795/* Must be called with interrupts enabled */
Alan Cox8f1e6722009-11-30 13:16:47 +0000796static int rc_activate_port(struct tty_port *port, struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797{
Alan Cox8f1e6722009-11-30 13:16:47 +0000798 struct riscom_port *rp = container_of(port, struct riscom_port, port);
799 struct riscom_board *bp = port_Board(rp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 unsigned long flags;
Alan Cox9492e132008-04-30 00:54:15 -0700801
Alan Cox8f1e6722009-11-30 13:16:47 +0000802 if (tty_port_alloc_xmit_buf(port) < 0)
Alan Cox85f8f812008-07-16 21:55:29 +0100803 return -ENOMEM;
804
Jeff Garzikd9afa432008-02-06 01:36:11 -0800805 spin_lock_irqsave(&riscom_lock, flags);
806
Alan Cox6ff1ab22009-09-19 13:13:22 -0700807 clear_bit(TTY_IO_ERROR, &tty->flags);
Alan Cox8f1e6722009-11-30 13:16:47 +0000808 bp->count++;
809 rp->xmit_cnt = rp->xmit_head = rp->xmit_tail = 0;
810 rc_change_speed(tty, bp, rp);
Jeff Garzikd9afa432008-02-06 01:36:11 -0800811 spin_unlock_irqrestore(&riscom_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 return 0;
813}
814
815/* Must be called with interrupts disabled */
Alan Coxd99101f2008-07-16 21:55:37 +0100816static void rc_shutdown_port(struct tty_struct *tty,
817 struct riscom_board *bp, struct riscom_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819#ifdef RC_REPORT_OVERRUN
820 printk(KERN_INFO "rc%d: port %d: Total %ld overruns were detected.\n",
821 board_No(bp), port_No(port), port->overrun);
Alan Cox9492e132008-04-30 00:54:15 -0700822#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823#ifdef RC_REPORT_FIFO
824 {
825 int i;
Alan Cox9492e132008-04-30 00:54:15 -0700826
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 printk(KERN_INFO "rc%d: port %d: FIFO hits [ ",
828 board_No(bp), port_No(port));
Alan Cox9492e132008-04-30 00:54:15 -0700829 for (i = 0; i < 10; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 printk("%ld ", port->hits[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 printk("].\n");
832 }
Alan Cox9492e132008-04-30 00:54:15 -0700833#endif
Alan Cox85f8f812008-07-16 21:55:29 +0100834 tty_port_free_xmit_buf(&port->port);
Alan Cox9492e132008-04-30 00:54:15 -0700835
836 /* Select port */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 rc_out(bp, CD180_CAR, port_No(port));
838 /* Reset port */
839 rc_wait_CCR(bp);
840 rc_out(bp, CD180_CCR, CCR_SOFTRESET);
841 /* Disable all interrupts from this port */
842 port->IER = 0;
843 rc_out(bp, CD180_IER, port->IER);
Alan Cox9492e132008-04-30 00:54:15 -0700844
Alan Coxd99101f2008-07-16 21:55:37 +0100845 set_bit(TTY_IO_ERROR, &tty->flags);
Alan Cox9492e132008-04-30 00:54:15 -0700846
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 if (--bp->count < 0) {
848 printk(KERN_INFO "rc%d: rc_shutdown_port: "
849 "bad board count: %d\n",
850 board_No(bp), bp->count);
851 bp->count = 0;
852 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 /*
854 * If this is the last opened port on the board
855 * shutdown whole board
856 */
Alan Cox9492e132008-04-30 00:54:15 -0700857 if (!bp->count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 rc_shutdown_board(bp);
859}
860
Alan Cox31f35932009-01-02 13:45:05 +0000861static int carrier_raised(struct tty_port *port)
862{
863 struct riscom_port *p = container_of(port, struct riscom_port, port);
864 struct riscom_board *bp = port_Board(p);
865 unsigned long flags;
866 int CD;
867
868 spin_lock_irqsave(&riscom_lock, flags);
869 rc_out(bp, CD180_CAR, port_No(p));
870 CD = rc_in(bp, CD180_MSVR) & MSVR_CD;
871 rc_out(bp, CD180_MSVR, MSVR_RTS);
872 bp->DTR &= ~(1u << port_No(p));
873 rc_out(bp, RC_DTR, bp->DTR);
874 spin_unlock_irqrestore(&riscom_lock, flags);
875 return CD;
876}
877
Alan Cox8f1e6722009-11-30 13:16:47 +0000878static void dtr_rts(struct tty_port *port, int onoff)
879{
880 struct riscom_port *p = container_of(port, struct riscom_port, port);
881 struct riscom_board *bp = port_Board(p);
882 unsigned long flags;
883
884 spin_lock_irqsave(&riscom_lock, flags);
885 bp->DTR &= ~(1u << port_No(p));
886 if (onoff == 0)
887 bp->DTR |= (1u << port_No(p));
888 rc_out(bp, RC_DTR, bp->DTR);
889 spin_unlock_irqrestore(&riscom_lock, flags);
890}
891
Alan Cox9492e132008-04-30 00:54:15 -0700892static int rc_open(struct tty_struct *tty, struct file *filp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893{
894 int board;
895 int error;
Alan Cox9492e132008-04-30 00:54:15 -0700896 struct riscom_port *port;
897 struct riscom_board *bp;
898
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 board = RC_BOARD(tty->index);
900 if (board >= RC_NBOARD || !(rc_board[board].flags & RC_BOARD_PRESENT))
901 return -ENODEV;
Alan Cox9492e132008-04-30 00:54:15 -0700902
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 bp = &rc_board[board];
904 port = rc_port + board * RC_NPORT + RC_PORT(tty->index);
905 if (rc_paranoia_check(port, tty->name, "rc_open"))
906 return -ENODEV;
Alan Cox9492e132008-04-30 00:54:15 -0700907
908 error = rc_setup_board(bp);
909 if (error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 return error;
Alan Cox9492e132008-04-30 00:54:15 -0700911
Alan Cox8f1e6722009-11-30 13:16:47 +0000912 return tty_port_open(&port->port, tty, filp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913}
914
Alan Cox978e5952008-04-30 00:53:59 -0700915static void rc_flush_buffer(struct tty_struct *tty)
916{
Alan Coxc9f19e92009-01-02 13:47:26 +0000917 struct riscom_port *port = tty->driver_data;
Alan Cox978e5952008-04-30 00:53:59 -0700918 unsigned long flags;
919
920 if (rc_paranoia_check(port, tty->name, "rc_flush_buffer"))
921 return;
922
923 spin_lock_irqsave(&riscom_lock, flags);
Alan Cox978e5952008-04-30 00:53:59 -0700924 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
Alan Cox978e5952008-04-30 00:53:59 -0700925 spin_unlock_irqrestore(&riscom_lock, flags);
926
927 tty_wakeup(tty);
928}
929
Jiri Slaby90387f52009-08-22 09:04:42 +0200930static void rc_close_port(struct tty_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 unsigned long flags;
Alan Coxc1469422009-09-19 13:13:21 -0700933 struct riscom_port *rp = container_of(port, struct riscom_port, port);
934 struct riscom_board *bp = port_Board(rp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 unsigned long timeout;
Alan Coxa6614992009-01-02 13:46:50 +0000936
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 /*
938 * At this point we stop accepting input. To do this, we
939 * disable the receive line status interrupts, and tell the
940 * interrupt driver to stop checking the data ready bit in the
941 * line status register.
942 */
Alan Coxc2ba38c2009-01-02 13:45:50 +0000943
944 spin_lock_irqsave(&riscom_lock, flags);
Alan Coxc1469422009-09-19 13:13:21 -0700945 rp->IER &= ~IER_RXD;
Alan Cox8f1e6722009-11-30 13:16:47 +0000946
947 rp->IER &= ~IER_TXRDY;
948 rp->IER |= IER_TXEMPTY;
949 rc_out(bp, CD180_CAR, port_No(rp));
950 rc_out(bp, CD180_IER, rp->IER);
951 /*
952 * Before we drop DTR, make sure the UART transmitter
953 * has completely drained; this is especially
954 * important if there is a transmit FIFO!
955 */
956 timeout = jiffies + HZ;
957 while (rp->IER & IER_TXEMPTY) {
958 spin_unlock_irqrestore(&riscom_lock, flags);
959 msleep_interruptible(jiffies_to_msecs(rp->timeout));
960 spin_lock_irqsave(&riscom_lock, flags);
961 if (time_after(jiffies, timeout))
962 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 }
Jiri Slaby90387f52009-08-22 09:04:42 +0200964 rc_shutdown_port(port->tty, bp, rp);
Alan Coxc2ba38c2009-01-02 13:45:50 +0000965 spin_unlock_irqrestore(&riscom_lock, flags);
Alan Coxc1469422009-09-19 13:13:21 -0700966}
967
968static void rc_close(struct tty_struct *tty, struct file *filp)
969{
970 struct riscom_port *port = tty->driver_data;
971
972 if (!port || rc_paranoia_check(port, tty->name, "close"))
973 return;
Alan Cox6ff1ab22009-09-19 13:13:22 -0700974 tty_port_close(&port->port, tty, filp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975}
976
Alan Cox9492e132008-04-30 00:54:15 -0700977static int rc_write(struct tty_struct *tty,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 const unsigned char *buf, int count)
979{
Alan Coxc9f19e92009-01-02 13:47:26 +0000980 struct riscom_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 struct riscom_board *bp;
982 int c, total = 0;
983 unsigned long flags;
Alan Cox9492e132008-04-30 00:54:15 -0700984
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 if (rc_paranoia_check(port, tty->name, "rc_write"))
986 return 0;
Alan Cox9492e132008-04-30 00:54:15 -0700987
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 bp = port_Board(port);
989
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 while (1) {
Jeff Garzikd9afa432008-02-06 01:36:11 -0800991 spin_lock_irqsave(&riscom_lock, flags);
992
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 c = min_t(int, count, min(SERIAL_XMIT_SIZE - port->xmit_cnt - 1,
994 SERIAL_XMIT_SIZE - port->xmit_head));
Jeff Garzikd9afa432008-02-06 01:36:11 -0800995 if (c <= 0)
996 break; /* lock continues to be held */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997
Alan Cox85f8f812008-07-16 21:55:29 +0100998 memcpy(port->port.xmit_buf + port->xmit_head, buf, c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 port->xmit_head = (port->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
1000 port->xmit_cnt += c;
Jeff Garzikd9afa432008-02-06 01:36:11 -08001001
1002 spin_unlock_irqrestore(&riscom_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003
1004 buf += c;
1005 count -= c;
1006 total += c;
1007 }
1008
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 if (port->xmit_cnt && !tty->stopped && !tty->hw_stopped &&
1010 !(port->IER & IER_TXRDY)) {
1011 port->IER |= IER_TXRDY;
1012 rc_out(bp, CD180_CAR, port_No(port));
1013 rc_out(bp, CD180_IER, port->IER);
1014 }
Jeff Garzikd9afa432008-02-06 01:36:11 -08001015
1016 spin_unlock_irqrestore(&riscom_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017
1018 return total;
1019}
1020
Alan Cox9492e132008-04-30 00:54:15 -07001021static int rc_put_char(struct tty_struct *tty, unsigned char ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022{
Alan Coxc9f19e92009-01-02 13:47:26 +00001023 struct riscom_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 unsigned long flags;
Alan Coxbbbbb962008-04-30 00:54:05 -07001025 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026
1027 if (rc_paranoia_check(port, tty->name, "rc_put_char"))
Alan Coxbbbbb962008-04-30 00:54:05 -07001028 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029
Jeff Garzikd9afa432008-02-06 01:36:11 -08001030 spin_lock_irqsave(&riscom_lock, flags);
Alan Cox9492e132008-04-30 00:54:15 -07001031
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1)
1033 goto out;
1034
Alan Cox85f8f812008-07-16 21:55:29 +01001035 port->port.xmit_buf[port->xmit_head++] = ch;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 port->xmit_head &= SERIAL_XMIT_SIZE - 1;
1037 port->xmit_cnt++;
Alan Coxbbbbb962008-04-30 00:54:05 -07001038 ret = 1;
Jeff Garzikd9afa432008-02-06 01:36:11 -08001039
1040out:
1041 spin_unlock_irqrestore(&riscom_lock, flags);
Alan Coxbbbbb962008-04-30 00:54:05 -07001042 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043}
1044
Alan Cox9492e132008-04-30 00:54:15 -07001045static void rc_flush_chars(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046{
Alan Coxc9f19e92009-01-02 13:47:26 +00001047 struct riscom_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 unsigned long flags;
Alan Cox9492e132008-04-30 00:54:15 -07001049
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 if (rc_paranoia_check(port, tty->name, "rc_flush_chars"))
1051 return;
Alan Cox9492e132008-04-30 00:54:15 -07001052
Alan Coxd99101f2008-07-16 21:55:37 +01001053 if (port->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 return;
1055
Jeff Garzikd9afa432008-02-06 01:36:11 -08001056 spin_lock_irqsave(&riscom_lock, flags);
1057
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 port->IER |= IER_TXRDY;
1059 rc_out(port_Board(port), CD180_CAR, port_No(port));
1060 rc_out(port_Board(port), CD180_IER, port->IER);
Jeff Garzikd9afa432008-02-06 01:36:11 -08001061
1062 spin_unlock_irqrestore(&riscom_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063}
1064
Alan Cox9492e132008-04-30 00:54:15 -07001065static int rc_write_room(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066{
Alan Coxc9f19e92009-01-02 13:47:26 +00001067 struct riscom_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 int ret;
Alan Cox9492e132008-04-30 00:54:15 -07001069
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 if (rc_paranoia_check(port, tty->name, "rc_write_room"))
1071 return 0;
1072
1073 ret = SERIAL_XMIT_SIZE - port->xmit_cnt - 1;
1074 if (ret < 0)
1075 ret = 0;
1076 return ret;
1077}
1078
1079static int rc_chars_in_buffer(struct tty_struct *tty)
1080{
Alan Coxc9f19e92009-01-02 13:47:26 +00001081 struct riscom_port *port = tty->driver_data;
Alan Cox9492e132008-04-30 00:54:15 -07001082
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 if (rc_paranoia_check(port, tty->name, "rc_chars_in_buffer"))
1084 return 0;
Alan Cox9492e132008-04-30 00:54:15 -07001085
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 return port->xmit_cnt;
1087}
1088
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089static int rc_tiocmget(struct tty_struct *tty, struct file *file)
1090{
Alan Coxc9f19e92009-01-02 13:47:26 +00001091 struct riscom_port *port = tty->driver_data;
Alan Cox9492e132008-04-30 00:54:15 -07001092 struct riscom_board *bp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 unsigned char status;
1094 unsigned int result;
1095 unsigned long flags;
1096
Harvey Harrisonbf9d8922008-04-30 00:55:10 -07001097 if (rc_paranoia_check(port, tty->name, __func__))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 return -ENODEV;
1099
1100 bp = port_Board(port);
Jeff Garzikd9afa432008-02-06 01:36:11 -08001101
1102 spin_lock_irqsave(&riscom_lock, flags);
1103
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 rc_out(bp, CD180_CAR, port_No(port));
1105 status = rc_in(bp, CD180_MSVR);
1106 result = rc_in(bp, RC_RI) & (1u << port_No(port)) ? 0 : TIOCM_RNG;
Jeff Garzikd9afa432008-02-06 01:36:11 -08001107
1108 spin_unlock_irqrestore(&riscom_lock, flags);
1109
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 result |= ((status & MSVR_RTS) ? TIOCM_RTS : 0)
1111 | ((status & MSVR_DTR) ? TIOCM_DTR : 0)
1112 | ((status & MSVR_CD) ? TIOCM_CAR : 0)
1113 | ((status & MSVR_DSR) ? TIOCM_DSR : 0)
1114 | ((status & MSVR_CTS) ? TIOCM_CTS : 0);
1115 return result;
1116}
1117
1118static int rc_tiocmset(struct tty_struct *tty, struct file *file,
1119 unsigned int set, unsigned int clear)
1120{
Alan Coxc9f19e92009-01-02 13:47:26 +00001121 struct riscom_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 unsigned long flags;
1123 struct riscom_board *bp;
1124
Harvey Harrisonbf9d8922008-04-30 00:55:10 -07001125 if (rc_paranoia_check(port, tty->name, __func__))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 return -ENODEV;
1127
1128 bp = port_Board(port);
1129
Jeff Garzikd9afa432008-02-06 01:36:11 -08001130 spin_lock_irqsave(&riscom_lock, flags);
1131
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 if (set & TIOCM_RTS)
1133 port->MSVR |= MSVR_RTS;
1134 if (set & TIOCM_DTR)
1135 bp->DTR &= ~(1u << port_No(port));
1136
1137 if (clear & TIOCM_RTS)
1138 port->MSVR &= ~MSVR_RTS;
1139 if (clear & TIOCM_DTR)
1140 bp->DTR |= (1u << port_No(port));
1141
1142 rc_out(bp, CD180_CAR, port_No(port));
1143 rc_out(bp, CD180_MSVR, port->MSVR);
1144 rc_out(bp, RC_DTR, bp->DTR);
Jeff Garzikd9afa432008-02-06 01:36:11 -08001145
1146 spin_unlock_irqrestore(&riscom_lock, flags);
1147
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 return 0;
1149}
1150
Alan Cox781cff52008-07-22 11:18:30 +01001151static int rc_send_break(struct tty_struct *tty, int length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152{
Alan Coxc9f19e92009-01-02 13:47:26 +00001153 struct riscom_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 struct riscom_board *bp = port_Board(port);
1155 unsigned long flags;
Alan Cox9492e132008-04-30 00:54:15 -07001156
Alan Cox781cff52008-07-22 11:18:30 +01001157 if (length == 0 || length == -1)
1158 return -EOPNOTSUPP;
1159
Jeff Garzikd9afa432008-02-06 01:36:11 -08001160 spin_lock_irqsave(&riscom_lock, flags);
1161
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 port->break_length = RISCOM_TPS / HZ * length;
1163 port->COR2 |= COR2_ETC;
1164 port->IER |= IER_TXRDY;
1165 rc_out(bp, CD180_CAR, port_No(port));
1166 rc_out(bp, CD180_COR2, port->COR2);
1167 rc_out(bp, CD180_IER, port->IER);
1168 rc_wait_CCR(bp);
1169 rc_out(bp, CD180_CCR, CCR_CORCHG2);
1170 rc_wait_CCR(bp);
Jeff Garzikd9afa432008-02-06 01:36:11 -08001171
1172 spin_unlock_irqrestore(&riscom_lock, flags);
Alan Cox781cff52008-07-22 11:18:30 +01001173 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174}
1175
Alan Cox6ff1ab22009-09-19 13:13:22 -07001176static int rc_set_serial_info(struct tty_struct *tty, struct riscom_port *port,
Alan Cox9492e132008-04-30 00:54:15 -07001177 struct serial_struct __user *newinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178{
1179 struct serial_struct tmp;
1180 struct riscom_board *bp = port_Board(port);
1181 int change_speed;
Alan Cox9492e132008-04-30 00:54:15 -07001182
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 if (copy_from_user(&tmp, newinfo, sizeof(tmp)))
1184 return -EFAULT;
Alan Cox9492e132008-04-30 00:54:15 -07001185
Alan Cox85f8f812008-07-16 21:55:29 +01001186 change_speed = ((port->port.flags & ASYNC_SPD_MASK) !=
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 (tmp.flags & ASYNC_SPD_MASK));
Alan Cox9492e132008-04-30 00:54:15 -07001188
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 if (!capable(CAP_SYS_ADMIN)) {
Alan Cox44b7d1b2008-07-16 21:57:18 +01001190 if ((tmp.close_delay != port->port.close_delay) ||
1191 (tmp.closing_wait != port->port.closing_wait) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 ((tmp.flags & ~ASYNC_USR_MASK) !=
Alan Cox85f8f812008-07-16 21:55:29 +01001193 (port->port.flags & ~ASYNC_USR_MASK)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 return -EPERM;
Alan Cox85f8f812008-07-16 21:55:29 +01001195 port->port.flags = ((port->port.flags & ~ASYNC_USR_MASK) |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 (tmp.flags & ASYNC_USR_MASK));
1197 } else {
Alan Cox85f8f812008-07-16 21:55:29 +01001198 port->port.flags = ((port->port.flags & ~ASYNC_FLAGS) |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 (tmp.flags & ASYNC_FLAGS));
Alan Cox44b7d1b2008-07-16 21:57:18 +01001200 port->port.close_delay = tmp.close_delay;
1201 port->port.closing_wait = tmp.closing_wait;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 }
1203 if (change_speed) {
Jeff Garzikd9afa432008-02-06 01:36:11 -08001204 unsigned long flags;
1205
1206 spin_lock_irqsave(&riscom_lock, flags);
Alan Cox6ff1ab22009-09-19 13:13:22 -07001207 rc_change_speed(tty, bp, port);
Jeff Garzikd9afa432008-02-06 01:36:11 -08001208 spin_unlock_irqrestore(&riscom_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 }
1210 return 0;
1211}
1212
Alan Cox9492e132008-04-30 00:54:15 -07001213static int rc_get_serial_info(struct riscom_port *port,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 struct serial_struct __user *retinfo)
1215{
1216 struct serial_struct tmp;
1217 struct riscom_board *bp = port_Board(port);
Alan Cox9492e132008-04-30 00:54:15 -07001218
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 memset(&tmp, 0, sizeof(tmp));
1220 tmp.type = PORT_CIRRUS;
1221 tmp.line = port - rc_port;
1222 tmp.port = bp->base;
1223 tmp.irq = bp->irq;
Alan Cox85f8f812008-07-16 21:55:29 +01001224 tmp.flags = port->port.flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 tmp.baud_base = (RC_OSCFREQ + CD180_TPC/2) / CD180_TPC;
Alan Cox44b7d1b2008-07-16 21:57:18 +01001226 tmp.close_delay = port->port.close_delay * HZ/100;
1227 tmp.closing_wait = port->port.closing_wait * HZ/100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 tmp.xmit_fifo_size = CD180_NFIFO;
1229 return copy_to_user(retinfo, &tmp, sizeof(tmp)) ? -EFAULT : 0;
1230}
1231
Alan Cox9492e132008-04-30 00:54:15 -07001232static int rc_ioctl(struct tty_struct *tty, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234{
Alan Coxc9f19e92009-01-02 13:47:26 +00001235 struct riscom_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 void __user *argp = (void __user *)arg;
Alan Cox781cff52008-07-22 11:18:30 +01001237 int retval;
Alan Cox9492e132008-04-30 00:54:15 -07001238
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 if (rc_paranoia_check(port, tty->name, "rc_ioctl"))
1240 return -ENODEV;
Alan Cox9492e132008-04-30 00:54:15 -07001241
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 switch (cmd) {
Alan Cox9492e132008-04-30 00:54:15 -07001243 case TIOCGSERIAL:
1244 lock_kernel();
Alan Coxeb174552008-04-30 00:53:21 -07001245 retval = rc_get_serial_info(port, argp);
1246 unlock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 break;
Alan Cox9492e132008-04-30 00:54:15 -07001248 case TIOCSSERIAL:
1249 lock_kernel();
Alan Cox6ff1ab22009-09-19 13:13:22 -07001250 retval = rc_set_serial_info(tty, port, argp);
Alan Coxeb174552008-04-30 00:53:21 -07001251 unlock_kernel();
1252 break;
Alan Cox9492e132008-04-30 00:54:15 -07001253 default:
Alan Coxeb174552008-04-30 00:53:21 -07001254 retval = -ENOIOCTLCMD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 }
Alan Coxeb174552008-04-30 00:53:21 -07001256 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257}
1258
Alan Cox9492e132008-04-30 00:54:15 -07001259static void rc_throttle(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260{
Alan Coxc9f19e92009-01-02 13:47:26 +00001261 struct riscom_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 struct riscom_board *bp;
1263 unsigned long flags;
Alan Cox9492e132008-04-30 00:54:15 -07001264
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 if (rc_paranoia_check(port, tty->name, "rc_throttle"))
1266 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 bp = port_Board(port);
Jeff Garzikd9afa432008-02-06 01:36:11 -08001268
1269 spin_lock_irqsave(&riscom_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 port->MSVR &= ~MSVR_RTS;
1271 rc_out(bp, CD180_CAR, port_No(port));
Jeff Garzikd9afa432008-02-06 01:36:11 -08001272 if (I_IXOFF(tty)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 rc_wait_CCR(bp);
1274 rc_out(bp, CD180_CCR, CCR_SSCH2);
1275 rc_wait_CCR(bp);
1276 }
1277 rc_out(bp, CD180_MSVR, port->MSVR);
Jeff Garzikd9afa432008-02-06 01:36:11 -08001278 spin_unlock_irqrestore(&riscom_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279}
1280
Alan Cox9492e132008-04-30 00:54:15 -07001281static void rc_unthrottle(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282{
Alan Coxc9f19e92009-01-02 13:47:26 +00001283 struct riscom_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 struct riscom_board *bp;
1285 unsigned long flags;
Alan Cox9492e132008-04-30 00:54:15 -07001286
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 if (rc_paranoia_check(port, tty->name, "rc_unthrottle"))
1288 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 bp = port_Board(port);
Jeff Garzikd9afa432008-02-06 01:36:11 -08001290
Alan Cox9492e132008-04-30 00:54:15 -07001291 spin_lock_irqsave(&riscom_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 port->MSVR |= MSVR_RTS;
1293 rc_out(bp, CD180_CAR, port_No(port));
1294 if (I_IXOFF(tty)) {
1295 rc_wait_CCR(bp);
1296 rc_out(bp, CD180_CCR, CCR_SSCH1);
1297 rc_wait_CCR(bp);
1298 }
1299 rc_out(bp, CD180_MSVR, port->MSVR);
Jeff Garzikd9afa432008-02-06 01:36:11 -08001300 spin_unlock_irqrestore(&riscom_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301}
1302
Alan Cox9492e132008-04-30 00:54:15 -07001303static void rc_stop(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304{
Alan Coxc9f19e92009-01-02 13:47:26 +00001305 struct riscom_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 struct riscom_board *bp;
1307 unsigned long flags;
Alan Cox9492e132008-04-30 00:54:15 -07001308
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 if (rc_paranoia_check(port, tty->name, "rc_stop"))
1310 return;
Jeff Garzikd9afa432008-02-06 01:36:11 -08001311
Alan Cox9492e132008-04-30 00:54:15 -07001312 bp = port_Board(port);
1313
1314 spin_lock_irqsave(&riscom_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 port->IER &= ~IER_TXRDY;
1316 rc_out(bp, CD180_CAR, port_No(port));
1317 rc_out(bp, CD180_IER, port->IER);
Jeff Garzikd9afa432008-02-06 01:36:11 -08001318 spin_unlock_irqrestore(&riscom_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319}
1320
Alan Cox9492e132008-04-30 00:54:15 -07001321static void rc_start(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322{
Alan Coxc9f19e92009-01-02 13:47:26 +00001323 struct riscom_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 struct riscom_board *bp;
1325 unsigned long flags;
Alan Cox9492e132008-04-30 00:54:15 -07001326
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 if (rc_paranoia_check(port, tty->name, "rc_start"))
1328 return;
Alan Cox9492e132008-04-30 00:54:15 -07001329
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 bp = port_Board(port);
Alan Cox9492e132008-04-30 00:54:15 -07001331
Jeff Garzikd9afa432008-02-06 01:36:11 -08001332 spin_lock_irqsave(&riscom_lock, flags);
1333
Alan Cox85f8f812008-07-16 21:55:29 +01001334 if (port->xmit_cnt && port->port.xmit_buf && !(port->IER & IER_TXRDY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 port->IER |= IER_TXRDY;
1336 rc_out(bp, CD180_CAR, port_No(port));
1337 rc_out(bp, CD180_IER, port->IER);
1338 }
Jeff Garzikd9afa432008-02-06 01:36:11 -08001339 spin_unlock_irqrestore(&riscom_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340}
1341
Alan Cox9492e132008-04-30 00:54:15 -07001342static void rc_hangup(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343{
Alan Coxc9f19e92009-01-02 13:47:26 +00001344 struct riscom_port *port = tty->driver_data;
Alan Cox9492e132008-04-30 00:54:15 -07001345
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 if (rc_paranoia_check(port, tty->name, "rc_hangup"))
1347 return;
Alan Cox9492e132008-04-30 00:54:15 -07001348
Alan Cox6ff1ab22009-09-19 13:13:22 -07001349 tty_port_hangup(&port->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350}
1351
Alan Cox9492e132008-04-30 00:54:15 -07001352static void rc_set_termios(struct tty_struct *tty,
1353 struct ktermios *old_termios)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354{
Alan Coxc9f19e92009-01-02 13:47:26 +00001355 struct riscom_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 unsigned long flags;
Alan Cox9492e132008-04-30 00:54:15 -07001357
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 if (rc_paranoia_check(port, tty->name, "rc_set_termios"))
1359 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360
Jeff Garzikd9afa432008-02-06 01:36:11 -08001361 spin_lock_irqsave(&riscom_lock, flags);
Alan Cox6ff1ab22009-09-19 13:13:22 -07001362 rc_change_speed(tty, port_Board(port), port);
Jeff Garzikd9afa432008-02-06 01:36:11 -08001363 spin_unlock_irqrestore(&riscom_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364
1365 if ((old_termios->c_cflag & CRTSCTS) &&
1366 !(tty->termios->c_cflag & CRTSCTS)) {
1367 tty->hw_stopped = 0;
1368 rc_start(tty);
1369 }
1370}
1371
Jeff Dikeb68e31d2006-10-02 02:17:18 -07001372static const struct tty_operations riscom_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 .open = rc_open,
1374 .close = rc_close,
1375 .write = rc_write,
1376 .put_char = rc_put_char,
1377 .flush_chars = rc_flush_chars,
1378 .write_room = rc_write_room,
1379 .chars_in_buffer = rc_chars_in_buffer,
1380 .flush_buffer = rc_flush_buffer,
1381 .ioctl = rc_ioctl,
1382 .throttle = rc_throttle,
1383 .unthrottle = rc_unthrottle,
1384 .set_termios = rc_set_termios,
1385 .stop = rc_stop,
1386 .start = rc_start,
1387 .hangup = rc_hangup,
1388 .tiocmget = rc_tiocmget,
1389 .tiocmset = rc_tiocmset,
Alan Cox781cff52008-07-22 11:18:30 +01001390 .break_ctl = rc_send_break,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391};
1392
Alan Cox31f35932009-01-02 13:45:05 +00001393static const struct tty_port_operations riscom_port_ops = {
1394 .carrier_raised = carrier_raised,
Alan Cox8f1e6722009-11-30 13:16:47 +00001395 .dtr_rts = dtr_rts,
Alan Cox6ff1ab22009-09-19 13:13:22 -07001396 .shutdown = rc_close_port,
Alan Cox8f1e6722009-11-30 13:16:47 +00001397 .activate = rc_activate_port,
Alan Cox31f35932009-01-02 13:45:05 +00001398};
1399
1400
Jiri Slaby1386a822008-02-07 00:16:36 -08001401static int __init rc_init_drivers(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402{
1403 int error;
1404 int i;
1405
1406 riscom_driver = alloc_tty_driver(RC_NBOARD * RC_NPORT);
Alan Cox9492e132008-04-30 00:54:15 -07001407 if (!riscom_driver)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 return -ENOMEM;
Alan Cox9492e132008-04-30 00:54:15 -07001409
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 riscom_driver->owner = THIS_MODULE;
1411 riscom_driver->name = "ttyL";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 riscom_driver->major = RISCOM8_NORMAL_MAJOR;
1413 riscom_driver->type = TTY_DRIVER_TYPE_SERIAL;
1414 riscom_driver->subtype = SERIAL_TYPE_NORMAL;
1415 riscom_driver->init_termios = tty_std_termios;
1416 riscom_driver->init_termios.c_cflag =
1417 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
Alan Cox606d0992006-12-08 02:38:45 -08001418 riscom_driver->init_termios.c_ispeed = 9600;
1419 riscom_driver->init_termios.c_ospeed = 9600;
Alan Cox781cff52008-07-22 11:18:30 +01001420 riscom_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_HARDWARE_BREAK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 tty_set_operations(riscom_driver, &riscom_ops);
Alan Cox9492e132008-04-30 00:54:15 -07001422 error = tty_register_driver(riscom_driver);
1423 if (error != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 put_tty_driver(riscom_driver);
1425 printk(KERN_ERR "rc: Couldn't register RISCom/8 driver, "
Alan Cox9492e132008-04-30 00:54:15 -07001426 "error = %d\n", error);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 return 1;
1428 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 memset(rc_port, 0, sizeof(rc_port));
1430 for (i = 0; i < RC_NPORT * RC_NBOARD; i++) {
Alan Cox85f8f812008-07-16 21:55:29 +01001431 tty_port_init(&rc_port[i].port);
Alan Cox31f35932009-01-02 13:45:05 +00001432 rc_port[i].port.ops = &riscom_port_ops;
Alan Cox44b7d1b2008-07-16 21:57:18 +01001433 rc_port[i].magic = RISCOM8_MAGIC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 return 0;
1436}
1437
1438static void rc_release_drivers(void)
1439{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 tty_unregister_driver(riscom_driver);
1441 put_tty_driver(riscom_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442}
1443
1444#ifndef MODULE
1445/*
1446 * Called at boot time.
Alan Cox9492e132008-04-30 00:54:15 -07001447 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 * You can specify IO base for up to RC_NBOARD cards,
1449 * using line "riscom8=0xiobase1,0xiobase2,.." at LILO prompt.
1450 * Note that there will be no probing at default
1451 * addresses in this case.
1452 *
Alan Cox9492e132008-04-30 00:54:15 -07001453 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454static int __init riscom8_setup(char *str)
1455{
1456 int ints[RC_NBOARD];
1457 int i;
1458
1459 str = get_options(str, ARRAY_SIZE(ints), ints);
1460
1461 for (i = 0; i < RC_NBOARD; i++) {
1462 if (i < ints[0])
1463 rc_board[i].base = ints[i+1];
Alan Cox9492e132008-04-30 00:54:15 -07001464 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 rc_board[i].base = 0;
1466 }
1467 return 1;
1468}
1469
1470__setup("riscom8=", riscom8_setup);
1471#endif
1472
1473static char banner[] __initdata =
1474 KERN_INFO "rc: SDL RISCom/8 card driver v1.1, (c) D.Gorodchanin "
1475 "1994-1996.\n";
1476static char no_boards_msg[] __initdata =
1477 KERN_INFO "rc: No RISCom/8 boards detected.\n";
1478
Alan Cox9492e132008-04-30 00:54:15 -07001479/*
1480 * This routine must be called by kernel at boot time
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 */
1482static int __init riscom8_init(void)
1483{
1484 int i;
1485 int found = 0;
1486
1487 printk(banner);
1488
Alan Cox9492e132008-04-30 00:54:15 -07001489 if (rc_init_drivers())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 return -EIO;
1491
Alan Cox9492e132008-04-30 00:54:15 -07001492 for (i = 0; i < RC_NBOARD; i++)
1493 if (rc_board[i].base && !rc_probe(&rc_board[i]))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 found++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 if (!found) {
1496 rc_release_drivers();
1497 printk(no_boards_msg);
1498 return -EIO;
1499 }
1500 return 0;
1501}
1502
1503#ifdef MODULE
1504static int iobase;
1505static int iobase1;
1506static int iobase2;
1507static int iobase3;
Rusty Russell8d3b33f2006-03-25 03:07:05 -08001508module_param(iobase, int, 0);
1509module_param(iobase1, int, 0);
1510module_param(iobase2, int, 0);
1511module_param(iobase3, int, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512
1513MODULE_LICENSE("GPL");
Scott James Remnant5c9f5802009-04-06 17:33:26 +01001514MODULE_ALIAS_CHARDEV_MAJOR(RISCOM8_NORMAL_MAJOR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515#endif /* MODULE */
1516
1517/*
1518 * You can setup up to 4 boards (current value of RC_NBOARD)
1519 * by specifying "iobase=0xXXX iobase1=0xXXX ..." as insmod parameter.
1520 *
1521 */
Alan Cox9492e132008-04-30 00:54:15 -07001522static int __init riscom8_init_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523{
1524#ifdef MODULE
1525 int i;
1526
1527 if (iobase || iobase1 || iobase2 || iobase3) {
Alan Cox9492e132008-04-30 00:54:15 -07001528 for (i = 0; i < RC_NBOARD; i++)
Jiri Slaby9efda792008-03-13 12:32:39 -07001529 rc_board[i].base = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 }
1531
1532 if (iobase)
1533 rc_board[0].base = iobase;
1534 if (iobase1)
1535 rc_board[1].base = iobase1;
1536 if (iobase2)
1537 rc_board[2].base = iobase2;
1538 if (iobase3)
1539 rc_board[3].base = iobase3;
1540#endif /* MODULE */
1541
1542 return riscom8_init();
1543}
Alan Cox9492e132008-04-30 00:54:15 -07001544
1545static void __exit riscom8_exit_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546{
1547 int i;
Alan Cox9492e132008-04-30 00:54:15 -07001548
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 rc_release_drivers();
Alan Cox9492e132008-04-30 00:54:15 -07001550 for (i = 0; i < RC_NBOARD; i++)
1551 if (rc_board[i].flags & RC_BOARD_PRESENT)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 rc_release_io_range(&rc_board[i]);
Alan Cox9492e132008-04-30 00:54:15 -07001553
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554}
1555
1556module_init(riscom8_init_module);
1557module_exit(riscom8_exit_module);