1 |
199 |
simons |
/*****************************************************************************/
|
2 |
|
|
|
3 |
|
|
/*
|
4 |
|
|
* stallion.c -- stallion multiport serial driver.
|
5 |
|
|
*
|
6 |
|
|
* Copyright (C) 1996-1998 Stallion Technologies (support@stallion.oz.au).
|
7 |
|
|
* Copyright (C) 1994-1996 Greg Ungerer (gerg@stallion.oz.au).
|
8 |
|
|
*
|
9 |
|
|
* This code is loosely based on the Linux serial driver, written by
|
10 |
|
|
* Linus Torvalds, Theodore T'so and others.
|
11 |
|
|
*
|
12 |
|
|
* This program is free software; you can redistribute it and/or modify
|
13 |
|
|
* it under the terms of the GNU General Public License as published by
|
14 |
|
|
* the Free Software Foundation; either version 2 of the License, or
|
15 |
|
|
* (at your option) any later version.
|
16 |
|
|
*
|
17 |
|
|
* This program is distributed in the hope that it will be useful,
|
18 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
20 |
|
|
* GNU General Public License for more details.
|
21 |
|
|
*
|
22 |
|
|
* You should have received a copy of the GNU General Public License
|
23 |
|
|
* along with this program; if not, write to the Free Software
|
24 |
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
25 |
|
|
*/
|
26 |
|
|
|
27 |
|
|
/*****************************************************************************/
|
28 |
|
|
|
29 |
|
|
#include <linux/module.h>
|
30 |
|
|
#include <linux/errno.h>
|
31 |
|
|
#include <linux/sched.h>
|
32 |
|
|
#include <linux/wait.h>
|
33 |
|
|
#include <linux/interrupt.h>
|
34 |
|
|
#include <linux/termios.h>
|
35 |
|
|
#include <linux/fcntl.h>
|
36 |
|
|
#include <linux/tty_driver.h>
|
37 |
|
|
#include <linux/tty.h>
|
38 |
|
|
#include <linux/tty_flip.h>
|
39 |
|
|
#include <linux/serial.h>
|
40 |
|
|
#include <linux/cd1400.h>
|
41 |
|
|
#include <linux/sc26198.h>
|
42 |
|
|
#include <linux/comstats.h>
|
43 |
|
|
#include <linux/stallion.h>
|
44 |
|
|
#include <linux/string.h>
|
45 |
|
|
#include <linux/malloc.h>
|
46 |
|
|
#include <linux/ioport.h>
|
47 |
|
|
#include <linux/config.h>
|
48 |
|
|
#include <asm/system.h>
|
49 |
|
|
#include <asm/io.h>
|
50 |
|
|
#include <asm/segment.h>
|
51 |
|
|
|
52 |
|
|
#ifdef CONFIG_PCI
|
53 |
|
|
#include <linux/pci.h>
|
54 |
|
|
#include <linux/bios32.h>
|
55 |
|
|
#endif
|
56 |
|
|
|
57 |
|
|
/*****************************************************************************/
|
58 |
|
|
|
59 |
|
|
/*
|
60 |
|
|
* Define different board types. Use the standard Stallion "assigned"
|
61 |
|
|
* board numbers. Boards supported in this driver are abbreviated as
|
62 |
|
|
* EIO = EasyIO and ECH = EasyConnection 8/32.
|
63 |
|
|
*/
|
64 |
|
|
#define BRD_EASYIO 20
|
65 |
|
|
#define BRD_ECH 21
|
66 |
|
|
#define BRD_ECHMC 22
|
67 |
|
|
#define BRD_ECHPCI 26
|
68 |
|
|
#define BRD_ECH64PCI 27
|
69 |
|
|
#define BRD_EASYIOPCI 28
|
70 |
|
|
|
71 |
|
|
/*
|
72 |
|
|
* Define a configuration structure to hold the board configuration.
|
73 |
|
|
* Need to set this up in the code (for now) with the boards that are
|
74 |
|
|
* to be configured into the system. This is what needs to be modified
|
75 |
|
|
* when adding/removing/modifying boards. Each line entry in the
|
76 |
|
|
* stl_brdconf[] array is a board. Each line contains io/irq/memory
|
77 |
|
|
* ranges for that board (as well as what type of board it is).
|
78 |
|
|
* Some examples:
|
79 |
|
|
* { BRD_EASYIO, 0x2a0, 0, 0, 10, 0 }
|
80 |
|
|
* This line would configure an EasyIO board (4 or 8, no difference),
|
81 |
|
|
* at io address 2a0 and irq 10.
|
82 |
|
|
* Another example:
|
83 |
|
|
* { BRD_ECH, 0x2a8, 0x280, 0, 12, 0 },
|
84 |
|
|
* This line will configure an EasyConnection 8/32 board at primary io
|
85 |
|
|
* address 2a8, secondary io address 280 and irq 12.
|
86 |
|
|
* Enter as many lines into this array as you want (only the first 4
|
87 |
|
|
* will actually be used!). Any combination of EasyIO and EasyConnection
|
88 |
|
|
* boards can be specified. EasyConnection 8/32 boards can share their
|
89 |
|
|
* secondary io addresses between each other.
|
90 |
|
|
*
|
91 |
|
|
* NOTE: there is no need to put any entries in this table for PCI
|
92 |
|
|
* boards. They will be found automatically by the driver - provided
|
93 |
|
|
* PCI BIOS32 support is compiled into the kernel.
|
94 |
|
|
*/
|
95 |
|
|
|
96 |
|
|
typedef struct {
|
97 |
|
|
int brdtype;
|
98 |
|
|
int ioaddr1;
|
99 |
|
|
int ioaddr2;
|
100 |
|
|
unsigned long memaddr;
|
101 |
|
|
int irq;
|
102 |
|
|
int irqtype;
|
103 |
|
|
} stlconf_t;
|
104 |
|
|
|
105 |
|
|
static stlconf_t stl_brdconf[] = {
|
106 |
|
|
{ BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },
|
107 |
|
|
};
|
108 |
|
|
|
109 |
|
|
static int stl_nrbrds = sizeof(stl_brdconf) / sizeof(stlconf_t);
|
110 |
|
|
|
111 |
|
|
/*****************************************************************************/
|
112 |
|
|
|
113 |
|
|
/*
|
114 |
|
|
* Define some important driver characteristics. Device major numbers
|
115 |
|
|
* allocated as per Linux Device Registry.
|
116 |
|
|
*/
|
117 |
|
|
#ifndef STL_SIOMEMMAJOR
|
118 |
|
|
#define STL_SIOMEMMAJOR 28
|
119 |
|
|
#endif
|
120 |
|
|
#ifndef STL_SERIALMAJOR
|
121 |
|
|
#define STL_SERIALMAJOR 24
|
122 |
|
|
#endif
|
123 |
|
|
#ifndef STL_CALLOUTMAJOR
|
124 |
|
|
#define STL_CALLOUTMAJOR 25
|
125 |
|
|
#endif
|
126 |
|
|
|
127 |
|
|
#define STL_DRVTYPSERIAL 1
|
128 |
|
|
#define STL_DRVTYPCALLOUT 2
|
129 |
|
|
|
130 |
|
|
/*
|
131 |
|
|
* Set the TX buffer size. Bigger is better, but we don't want
|
132 |
|
|
* to chew too much memory with buffers!
|
133 |
|
|
*/
|
134 |
|
|
#define STL_TXBUFLOW 512
|
135 |
|
|
#define STL_TXBUFSIZE 4096
|
136 |
|
|
|
137 |
|
|
/*****************************************************************************/
|
138 |
|
|
|
139 |
|
|
/*
|
140 |
|
|
* Define our local driver identity first. Set up stuff to deal with
|
141 |
|
|
* all the local structures required by a serial tty driver.
|
142 |
|
|
*/
|
143 |
|
|
static char *stl_drvtitle = "Stallion Multiport Serial Driver";
|
144 |
|
|
static char *stl_drvversion = "5.4.4";
|
145 |
|
|
static char *stl_serialname = "ttyE";
|
146 |
|
|
static char *stl_calloutname = "cue";
|
147 |
|
|
|
148 |
|
|
static struct tty_driver stl_serial;
|
149 |
|
|
static struct tty_driver stl_callout;
|
150 |
|
|
static struct tty_struct *stl_ttys[STL_MAXDEVS];
|
151 |
|
|
static struct termios *stl_termios[STL_MAXDEVS];
|
152 |
|
|
static struct termios *stl_termioslocked[STL_MAXDEVS];
|
153 |
|
|
static int stl_refcount = 0;
|
154 |
|
|
|
155 |
|
|
/*
|
156 |
|
|
* We will need to allocate a temporary write buffer for chars that
|
157 |
|
|
* come direct from user space. The problem is that a copy from user
|
158 |
|
|
* space might cause a page fault (typically on a system that is
|
159 |
|
|
* swapping!). All ports will share one buffer - since if the system
|
160 |
|
|
* is already swapping a shared buffer won't make things any worse.
|
161 |
|
|
*/
|
162 |
|
|
static char *stl_tmpwritebuf;
|
163 |
|
|
static struct semaphore stl_tmpwritesem = MUTEX;
|
164 |
|
|
|
165 |
|
|
/*
|
166 |
|
|
* Define a local default termios struct. All ports will be created
|
167 |
|
|
* with this termios initially. Basically all it defines is a raw port
|
168 |
|
|
* at 9600, 8 data bits, 1 stop bit.
|
169 |
|
|
*/
|
170 |
|
|
static struct termios stl_deftermios = {
|
171 |
|
|
0,
|
172 |
|
|
0,
|
173 |
|
|
(B9600 | CS8 | CREAD | HUPCL | CLOCAL),
|
174 |
|
|
0,
|
175 |
|
|
0,
|
176 |
|
|
INIT_C_CC
|
177 |
|
|
};
|
178 |
|
|
|
179 |
|
|
/*
|
180 |
|
|
* Define global stats structures. Not used often, and can be
|
181 |
|
|
* re-used for each stats call.
|
182 |
|
|
*/
|
183 |
|
|
static comstats_t stl_comstats;
|
184 |
|
|
static combrd_t stl_brdstats;
|
185 |
|
|
static stlbrd_t stl_dummybrd;
|
186 |
|
|
static stlport_t stl_dummyport;
|
187 |
|
|
|
188 |
|
|
/*
|
189 |
|
|
* Define global place to put buffer overflow characters.
|
190 |
|
|
*/
|
191 |
|
|
static char stl_unwanted[SC26198_RXFIFOSIZE];
|
192 |
|
|
|
193 |
|
|
/*
|
194 |
|
|
* Keep track of what interrupts we have requested for us.
|
195 |
|
|
* We don't need to request an interrupt twice if it is being
|
196 |
|
|
* shared with another Stallion board.
|
197 |
|
|
*/
|
198 |
|
|
static int stl_gotintrs[STL_MAXBRDS];
|
199 |
|
|
static int stl_numintrs = 0;
|
200 |
|
|
|
201 |
|
|
/*****************************************************************************/
|
202 |
|
|
|
203 |
|
|
static stlbrd_t *stl_brds[STL_MAXBRDS];
|
204 |
|
|
|
205 |
|
|
/*
|
206 |
|
|
* Per board state flags. Used with the state field of the board struct.
|
207 |
|
|
* Not really much here!
|
208 |
|
|
*/
|
209 |
|
|
#define BRD_FOUND 0x1
|
210 |
|
|
|
211 |
|
|
/*
|
212 |
|
|
* Define the port structure istate flags. These set of flags are
|
213 |
|
|
* modified at interrupt time - so setting and reseting them needs
|
214 |
|
|
* to be atomic. Use the bit clear/setting routines for this.
|
215 |
|
|
*/
|
216 |
|
|
#define ASYI_TXBUSY 1
|
217 |
|
|
#define ASYI_TXLOW 2
|
218 |
|
|
#define ASYI_DCDCHANGE 3
|
219 |
|
|
#define ASYI_TXFLOWED 4
|
220 |
|
|
|
221 |
|
|
/*
|
222 |
|
|
* Define an array of board names as printable strings. Handy for
|
223 |
|
|
* referencing boards when printing trace and stuff.
|
224 |
|
|
*/
|
225 |
|
|
static char *stl_brdnames[] = {
|
226 |
|
|
(char *) NULL,
|
227 |
|
|
(char *) NULL,
|
228 |
|
|
(char *) NULL,
|
229 |
|
|
(char *) NULL,
|
230 |
|
|
(char *) NULL,
|
231 |
|
|
(char *) NULL,
|
232 |
|
|
(char *) NULL,
|
233 |
|
|
(char *) NULL,
|
234 |
|
|
(char *) NULL,
|
235 |
|
|
(char *) NULL,
|
236 |
|
|
(char *) NULL,
|
237 |
|
|
(char *) NULL,
|
238 |
|
|
(char *) NULL,
|
239 |
|
|
(char *) NULL,
|
240 |
|
|
(char *) NULL,
|
241 |
|
|
(char *) NULL,
|
242 |
|
|
(char *) NULL,
|
243 |
|
|
(char *) NULL,
|
244 |
|
|
(char *) NULL,
|
245 |
|
|
(char *) NULL,
|
246 |
|
|
"EasyIO",
|
247 |
|
|
"EC8/32-AT",
|
248 |
|
|
"EC8/32-MC",
|
249 |
|
|
(char *) NULL,
|
250 |
|
|
(char *) NULL,
|
251 |
|
|
(char *) NULL,
|
252 |
|
|
"EC8/32-PCI",
|
253 |
|
|
"EC8/64-PCI",
|
254 |
|
|
"EasyIO-PCI",
|
255 |
|
|
};
|
256 |
|
|
|
257 |
|
|
/*****************************************************************************/
|
258 |
|
|
|
259 |
|
|
/*
|
260 |
|
|
* Hardware ID bits for the EasyIO and ECH boards. These defines apply
|
261 |
|
|
* to the directly accessible io ports of these boards (not the uarts -
|
262 |
|
|
* they are in cd1400.h and sc26198.h).
|
263 |
|
|
*/
|
264 |
|
|
#define EIO_8PORTRS 0x04
|
265 |
|
|
#define EIO_4PORTRS 0x05
|
266 |
|
|
#define EIO_8PORTDI 0x00
|
267 |
|
|
#define EIO_8PORTM 0x06
|
268 |
|
|
#define EIO_MK3 0x03
|
269 |
|
|
#define EIO_IDBITMASK 0x07
|
270 |
|
|
|
271 |
|
|
#define EIO_BRDMASK 0xf0
|
272 |
|
|
#define ID_BRD4 0x10
|
273 |
|
|
#define ID_BRD8 0x20
|
274 |
|
|
#define ID_BRD16 0x30
|
275 |
|
|
|
276 |
|
|
#define EIO_INTRPEND 0x08
|
277 |
|
|
#define EIO_INTEDGE 0x00
|
278 |
|
|
#define EIO_INTLEVEL 0x08
|
279 |
|
|
#define EIO_0WS 0x10
|
280 |
|
|
|
281 |
|
|
#define ECH_ID 0xa0
|
282 |
|
|
#define ECH_IDBITMASK 0xe0
|
283 |
|
|
#define ECH_BRDENABLE 0x08
|
284 |
|
|
#define ECH_BRDDISABLE 0x00
|
285 |
|
|
#define ECH_INTENABLE 0x01
|
286 |
|
|
#define ECH_INTDISABLE 0x00
|
287 |
|
|
#define ECH_INTLEVEL 0x02
|
288 |
|
|
#define ECH_INTEDGE 0x00
|
289 |
|
|
#define ECH_INTRPEND 0x01
|
290 |
|
|
#define ECH_BRDRESET 0x01
|
291 |
|
|
|
292 |
|
|
#define ECHMC_INTENABLE 0x01
|
293 |
|
|
#define ECHMC_BRDRESET 0x02
|
294 |
|
|
|
295 |
|
|
#define ECH_PNLSTATUS 2
|
296 |
|
|
#define ECH_PNL16PORT 0x20
|
297 |
|
|
#define ECH_PNLIDMASK 0x07
|
298 |
|
|
#define ECH_PNLXPID 0x40
|
299 |
|
|
#define ECH_PNLINTRPEND 0x80
|
300 |
|
|
|
301 |
|
|
#define ECH_ADDR2MASK 0x1e0
|
302 |
|
|
|
303 |
|
|
/*
|
304 |
|
|
* Define the vector mapping bits for the programmable interrupt board
|
305 |
|
|
* hardware. These bits encode the interrupt for the board to use - it
|
306 |
|
|
* is software selectable (except the EIO-8M).
|
307 |
|
|
*/
|
308 |
|
|
static unsigned char stl_vecmap[] = {
|
309 |
|
|
0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
|
310 |
|
|
0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
|
311 |
|
|
};
|
312 |
|
|
|
313 |
|
|
/*
|
314 |
|
|
* Set up enable and disable macros for the ECH boards. They require
|
315 |
|
|
* the secondary io address space to be activated and deactivated.
|
316 |
|
|
* This way all ECH boards can share their secondary io region.
|
317 |
|
|
* If this is an ECH-PCI board then also need to set the page pointer
|
318 |
|
|
* to point to the correct page.
|
319 |
|
|
*/
|
320 |
|
|
#define BRDENABLE(brdnr,pagenr) \
|
321 |
|
|
if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
|
322 |
|
|
outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE), \
|
323 |
|
|
stl_brds[(brdnr)]->ioctrl); \
|
324 |
|
|
else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
|
325 |
|
|
outb((pagenr), stl_brds[(brdnr)]->ioctrl);
|
326 |
|
|
|
327 |
|
|
#define BRDDISABLE(brdnr) \
|
328 |
|
|
if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
|
329 |
|
|
outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE), \
|
330 |
|
|
stl_brds[(brdnr)]->ioctrl);
|
331 |
|
|
|
332 |
|
|
#define STL_CD1400MAXBAUD 230400
|
333 |
|
|
#define STL_SC26198MAXBAUD 460800
|
334 |
|
|
|
335 |
|
|
#define STL_BAUDBASE 115200
|
336 |
|
|
#define STL_CLOSEDELAY (5 * HZ / 10)
|
337 |
|
|
|
338 |
|
|
/*****************************************************************************/
|
339 |
|
|
|
340 |
|
|
#ifdef CONFIG_PCI
|
341 |
|
|
|
342 |
|
|
/*
|
343 |
|
|
* Define the Stallion PCI vendor and device IDs.
|
344 |
|
|
*/
|
345 |
|
|
#ifndef PCI_VENDOR_ID_STALLION
|
346 |
|
|
#define PCI_VENDOR_ID_STALLION 0x124d
|
347 |
|
|
#endif
|
348 |
|
|
#ifndef PCI_DEVICE_ID_ECHPCI832
|
349 |
|
|
#define PCI_DEVICE_ID_ECHPCI832 0x0000
|
350 |
|
|
#endif
|
351 |
|
|
#ifndef PCI_DEVICE_ID_ECHPCI864
|
352 |
|
|
#define PCI_DEVICE_ID_ECHPCI864 0x0002
|
353 |
|
|
#endif
|
354 |
|
|
#ifndef PCI_DEVICE_ID_EIOPCI
|
355 |
|
|
#define PCI_DEVICE_ID_EIOPCI 0x0003
|
356 |
|
|
#endif
|
357 |
|
|
|
358 |
|
|
/*
|
359 |
|
|
* Define structure to hold all Stallion PCI boards.
|
360 |
|
|
*/
|
361 |
|
|
typedef struct stlpcibrd {
|
362 |
|
|
unsigned short vendid;
|
363 |
|
|
unsigned short devid;
|
364 |
|
|
int brdtype;
|
365 |
|
|
} stlpcibrd_t;
|
366 |
|
|
|
367 |
|
|
static stlpcibrd_t stl_pcibrds[] = {
|
368 |
|
|
{ PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI864, BRD_ECH64PCI },
|
369 |
|
|
{ PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_EIOPCI, BRD_EASYIOPCI },
|
370 |
|
|
{ PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI832, BRD_ECHPCI },
|
371 |
|
|
{ PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410, BRD_ECHPCI },
|
372 |
|
|
};
|
373 |
|
|
|
374 |
|
|
static int stl_nrpcibrds = sizeof(stl_pcibrds) / sizeof(stlpcibrd_t);
|
375 |
|
|
|
376 |
|
|
#endif
|
377 |
|
|
|
378 |
|
|
/*****************************************************************************/
|
379 |
|
|
|
380 |
|
|
/*
|
381 |
|
|
* Define macros to extract a brd/port number from a minor number.
|
382 |
|
|
*/
|
383 |
|
|
#define MKDEV2BRD(min) (((min) & 0xc0) >> 6)
|
384 |
|
|
#define MKDEV2PORT(min) ((min) & 0x3f)
|
385 |
|
|
|
386 |
|
|
/*
|
387 |
|
|
* Define a baud rate table that converts termios baud rate selector
|
388 |
|
|
* into the actual baud rate value. All baud rate calculations are
|
389 |
|
|
* based on the actual baud rate required.
|
390 |
|
|
*/
|
391 |
|
|
static unsigned int stl_baudrates[] = {
|
392 |
|
|
0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
|
393 |
|
|
9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
|
394 |
|
|
};
|
395 |
|
|
|
396 |
|
|
/*
|
397 |
|
|
* Define some handy local macros...
|
398 |
|
|
*/
|
399 |
|
|
#ifndef MIN
|
400 |
|
|
#define MIN(a,b) (((a) <= (b)) ? (a) : (b))
|
401 |
|
|
#endif
|
402 |
|
|
|
403 |
|
|
/*****************************************************************************/
|
404 |
|
|
|
405 |
|
|
/*
|
406 |
|
|
* Declare all those functions in this driver!
|
407 |
|
|
*/
|
408 |
|
|
|
409 |
|
|
#ifdef MODULE
|
410 |
|
|
int init_module(void);
|
411 |
|
|
void cleanup_module(void);
|
412 |
|
|
#endif
|
413 |
|
|
|
414 |
|
|
int stl_init(void);
|
415 |
|
|
static int stl_open(struct tty_struct *tty, struct file *filp);
|
416 |
|
|
static void stl_close(struct tty_struct *tty, struct file *filp);
|
417 |
|
|
static int stl_write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count);
|
418 |
|
|
static void stl_putchar(struct tty_struct *tty, unsigned char ch);
|
419 |
|
|
static void stl_flushchars(struct tty_struct *tty);
|
420 |
|
|
static int stl_writeroom(struct tty_struct *tty);
|
421 |
|
|
static int stl_charsinbuffer(struct tty_struct *tty);
|
422 |
|
|
static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
|
423 |
|
|
static void stl_settermios(struct tty_struct *tty, struct termios *old);
|
424 |
|
|
static void stl_throttle(struct tty_struct *tty);
|
425 |
|
|
static void stl_unthrottle(struct tty_struct *tty);
|
426 |
|
|
static void stl_stop(struct tty_struct *tty);
|
427 |
|
|
static void stl_start(struct tty_struct *tty);
|
428 |
|
|
static void stl_flushbuffer(struct tty_struct *tty);
|
429 |
|
|
static void stl_waituntilsent(struct tty_struct *tty, int timeout);
|
430 |
|
|
static void stl_hangup(struct tty_struct *tty);
|
431 |
|
|
static int stl_memopen(struct inode *ip, struct file *fp);
|
432 |
|
|
static void stl_memclose(struct inode *ip, struct file *fp);
|
433 |
|
|
static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
|
434 |
|
|
|
435 |
|
|
static int stl_brdinit(stlbrd_t *brdp);
|
436 |
|
|
static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp);
|
437 |
|
|
static int stl_mapirq(int irq, char *name);
|
438 |
|
|
static void stl_getserial(stlport_t *portp, struct serial_struct *sp);
|
439 |
|
|
static int stl_setserial(stlport_t *portp, struct serial_struct *sp);
|
440 |
|
|
static int stl_getbrdstats(combrd_t *bp);
|
441 |
|
|
static int stl_getportstats(stlport_t *portp, comstats_t *cp);
|
442 |
|
|
static int stl_clrportstats(stlport_t *portp, comstats_t *cp);
|
443 |
|
|
static int stl_getportstruct(unsigned long arg);
|
444 |
|
|
static int stl_getbrdstruct(unsigned long arg);
|
445 |
|
|
static int stl_waitcarrier(stlport_t *portp, struct file *filp);
|
446 |
|
|
static void stl_delay(int len);
|
447 |
|
|
static void stl_intr(int irq, void *dev_id, struct pt_regs *regs);
|
448 |
|
|
static void stl_eiointr(stlbrd_t *brdp);
|
449 |
|
|
static void stl_echatintr(stlbrd_t *brdp);
|
450 |
|
|
static void stl_echmcaintr(stlbrd_t *brdp);
|
451 |
|
|
static void stl_echpciintr(stlbrd_t *brdp);
|
452 |
|
|
static void stl_echpci64intr(stlbrd_t *brdp);
|
453 |
|
|
static void stl_offintr(void *private);
|
454 |
|
|
static void *stl_memalloc(int len);
|
455 |
|
|
static stlport_t *stl_getport(int brdnr, int panelnr, int portnr);
|
456 |
|
|
|
457 |
|
|
static inline int stl_initbrds(void);
|
458 |
|
|
static inline int stl_initeio(stlbrd_t *brdp);
|
459 |
|
|
static inline int stl_initech(stlbrd_t *brdp);
|
460 |
|
|
|
461 |
|
|
#ifdef CONFIG_PCI
|
462 |
|
|
static inline int stl_findpcibrds(void);
|
463 |
|
|
static inline int stl_initpcibrd(int brdtype, unsigned char busnr, unsigned char devnr);
|
464 |
|
|
#endif
|
465 |
|
|
|
466 |
|
|
/*
|
467 |
|
|
* CD1400 uart specific handling functions.
|
468 |
|
|
*/
|
469 |
|
|
static void stl_cd1400setreg(stlport_t *portp, int regnr, int value);
|
470 |
|
|
static int stl_cd1400getreg(stlport_t *portp, int regnr);
|
471 |
|
|
static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value);
|
472 |
|
|
static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
|
473 |
|
|
static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
|
474 |
|
|
static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp);
|
475 |
|
|
static int stl_cd1400getsignals(stlport_t *portp);
|
476 |
|
|
static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts);
|
477 |
|
|
static void stl_cd1400ccrwait(stlport_t *portp);
|
478 |
|
|
static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx);
|
479 |
|
|
static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx);
|
480 |
|
|
static void stl_cd1400disableintrs(stlport_t *portp);
|
481 |
|
|
static void stl_cd1400sendbreak(stlport_t *portp, long len);
|
482 |
|
|
static void stl_cd1400flowctrl(stlport_t *portp, int state);
|
483 |
|
|
static void stl_cd1400sendflow(stlport_t *portp, int state);
|
484 |
|
|
static void stl_cd1400flush(stlport_t *portp);
|
485 |
|
|
static int stl_cd1400datastate(stlport_t *portp);
|
486 |
|
|
static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase);
|
487 |
|
|
static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase);
|
488 |
|
|
static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr);
|
489 |
|
|
static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr);
|
490 |
|
|
static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr);
|
491 |
|
|
|
492 |
|
|
/*
|
493 |
|
|
* SC26198 uart specific handling functions.
|
494 |
|
|
*/
|
495 |
|
|
static void stl_sc26198setreg(stlport_t *portp, int regnr, int value);
|
496 |
|
|
static int stl_sc26198getreg(stlport_t *portp, int regnr);
|
497 |
|
|
static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value);
|
498 |
|
|
static int stl_sc26198getglobreg(stlport_t *portp, int regnr);
|
499 |
|
|
static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
|
500 |
|
|
static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
|
501 |
|
|
static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp);
|
502 |
|
|
static int stl_sc26198getsignals(stlport_t *portp);
|
503 |
|
|
static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts);
|
504 |
|
|
static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx);
|
505 |
|
|
static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx);
|
506 |
|
|
static void stl_sc26198disableintrs(stlport_t *portp);
|
507 |
|
|
static void stl_sc26198sendbreak(stlport_t *portp, long len);
|
508 |
|
|
static void stl_sc26198flowctrl(stlport_t *portp, int state);
|
509 |
|
|
static void stl_sc26198sendflow(stlport_t *portp, int state);
|
510 |
|
|
static void stl_sc26198flush(stlport_t *portp);
|
511 |
|
|
static int stl_sc26198datastate(stlport_t *portp);
|
512 |
|
|
static void stl_sc26198wait(stlport_t *portp);
|
513 |
|
|
static void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty);
|
514 |
|
|
static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase);
|
515 |
|
|
static void stl_sc26198txisr(stlport_t *port);
|
516 |
|
|
static void stl_sc26198rxisr(stlport_t *port, unsigned int iack);
|
517 |
|
|
static void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch);
|
518 |
|
|
static void stl_sc26198rxbadchars(stlport_t *portp);
|
519 |
|
|
static void stl_sc26198otherisr(stlport_t *port, unsigned int iack);
|
520 |
|
|
|
521 |
|
|
/*****************************************************************************/
|
522 |
|
|
|
523 |
|
|
/*
|
524 |
|
|
* Generic UART support structure.
|
525 |
|
|
*/
|
526 |
|
|
typedef struct uart {
|
527 |
|
|
int (*panelinit)(stlbrd_t *brdp, stlpanel_t *panelp);
|
528 |
|
|
void (*portinit)(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
|
529 |
|
|
void (*setport)(stlport_t *portp, struct termios *tiosp);
|
530 |
|
|
int (*getsignals)(stlport_t *portp);
|
531 |
|
|
void (*setsignals)(stlport_t *portp, int dtr, int rts);
|
532 |
|
|
void (*enablerxtx)(stlport_t *portp, int rx, int tx);
|
533 |
|
|
void (*startrxtx)(stlport_t *portp, int rx, int tx);
|
534 |
|
|
void (*disableintrs)(stlport_t *portp);
|
535 |
|
|
void (*sendbreak)(stlport_t *portp, long len);
|
536 |
|
|
void (*flowctrl)(stlport_t *portp, int state);
|
537 |
|
|
void (*sendflow)(stlport_t *portp, int state);
|
538 |
|
|
void (*flush)(stlport_t *portp);
|
539 |
|
|
int (*datastate)(stlport_t *portp);
|
540 |
|
|
void (*intr)(stlpanel_t *panelp, unsigned int iobase);
|
541 |
|
|
} uart_t;
|
542 |
|
|
|
543 |
|
|
/*
|
544 |
|
|
* Define some macros to make calling these functions nice and clean.
|
545 |
|
|
*/
|
546 |
|
|
#define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
|
547 |
|
|
#define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
|
548 |
|
|
#define stl_setport (* ((uart_t *) portp->uartp)->setport)
|
549 |
|
|
#define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
|
550 |
|
|
#define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
|
551 |
|
|
#define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
|
552 |
|
|
#define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
|
553 |
|
|
#define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
|
554 |
|
|
#define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
|
555 |
|
|
#define stl_flowctrl (* ((uart_t *) portp->uartp)->flowctrl)
|
556 |
|
|
#define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
|
557 |
|
|
#define stl_flush (* ((uart_t *) portp->uartp)->flush)
|
558 |
|
|
#define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
|
559 |
|
|
|
560 |
|
|
/*****************************************************************************/
|
561 |
|
|
|
562 |
|
|
/*
|
563 |
|
|
* CD1400 UART specific data initialization.
|
564 |
|
|
*/
|
565 |
|
|
static uart_t stl_cd1400uart = {
|
566 |
|
|
stl_cd1400panelinit,
|
567 |
|
|
stl_cd1400portinit,
|
568 |
|
|
stl_cd1400setport,
|
569 |
|
|
stl_cd1400getsignals,
|
570 |
|
|
stl_cd1400setsignals,
|
571 |
|
|
stl_cd1400enablerxtx,
|
572 |
|
|
stl_cd1400startrxtx,
|
573 |
|
|
stl_cd1400disableintrs,
|
574 |
|
|
stl_cd1400sendbreak,
|
575 |
|
|
stl_cd1400flowctrl,
|
576 |
|
|
stl_cd1400sendflow,
|
577 |
|
|
stl_cd1400flush,
|
578 |
|
|
stl_cd1400datastate,
|
579 |
|
|
stl_cd1400eiointr
|
580 |
|
|
};
|
581 |
|
|
|
582 |
|
|
/*
|
583 |
|
|
* Define the offsets within the register bank of a cd1400 based panel.
|
584 |
|
|
* These io address offsets are common to the EasyIO board as well.
|
585 |
|
|
*/
|
586 |
|
|
#define EREG_ADDR 0
|
587 |
|
|
#define EREG_DATA 4
|
588 |
|
|
#define EREG_RXACK 5
|
589 |
|
|
#define EREG_TXACK 6
|
590 |
|
|
#define EREG_MDACK 7
|
591 |
|
|
|
592 |
|
|
#define EREG_BANKSIZE 8
|
593 |
|
|
|
594 |
|
|
#define CD1400_CLK 25000000
|
595 |
|
|
#define CD1400_CLK8M 20000000
|
596 |
|
|
|
597 |
|
|
/*
|
598 |
|
|
* Define the cd1400 baud rate clocks. These are used when calculating
|
599 |
|
|
* what clock and divisor to use for the required baud rate. Also
|
600 |
|
|
* define the maximum baud rate allowed, and the default base baud.
|
601 |
|
|
*/
|
602 |
|
|
static int stl_cd1400clkdivs[] = {
|
603 |
|
|
CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4
|
604 |
|
|
};
|
605 |
|
|
|
606 |
|
|
/*****************************************************************************/
|
607 |
|
|
|
608 |
|
|
/*
|
609 |
|
|
* SC26198 UART specific data initization.
|
610 |
|
|
*/
|
611 |
|
|
static uart_t stl_sc26198uart = {
|
612 |
|
|
stl_sc26198panelinit,
|
613 |
|
|
stl_sc26198portinit,
|
614 |
|
|
stl_sc26198setport,
|
615 |
|
|
stl_sc26198getsignals,
|
616 |
|
|
stl_sc26198setsignals,
|
617 |
|
|
stl_sc26198enablerxtx,
|
618 |
|
|
stl_sc26198startrxtx,
|
619 |
|
|
stl_sc26198disableintrs,
|
620 |
|
|
stl_sc26198sendbreak,
|
621 |
|
|
stl_sc26198flowctrl,
|
622 |
|
|
stl_sc26198sendflow,
|
623 |
|
|
stl_sc26198flush,
|
624 |
|
|
stl_sc26198datastate,
|
625 |
|
|
stl_sc26198intr
|
626 |
|
|
};
|
627 |
|
|
|
628 |
|
|
/*
|
629 |
|
|
* Define the offsets within the register bank of a sc26198 based panel.
|
630 |
|
|
*/
|
631 |
|
|
#define XP_DATA 0
|
632 |
|
|
#define XP_ADDR 1
|
633 |
|
|
#define XP_MODID 2
|
634 |
|
|
#define XP_STATUS 2
|
635 |
|
|
#define XP_IACK 3
|
636 |
|
|
|
637 |
|
|
#define XP_BANKSIZE 4
|
638 |
|
|
|
639 |
|
|
/*
|
640 |
|
|
* Define the sc26198 baud rate table. Offsets within the table
|
641 |
|
|
* represent the actual baud rate selector of sc26198 registers.
|
642 |
|
|
*/
|
643 |
|
|
static unsigned int sc26198_baudtable[] = {
|
644 |
|
|
50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
|
645 |
|
|
4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
|
646 |
|
|
230400, 460800, 921600
|
647 |
|
|
};
|
648 |
|
|
|
649 |
|
|
#define SC26198_NRBAUDS (sizeof(sc26198_baudtable) / sizeof(unsigned int))
|
650 |
|
|
|
651 |
|
|
/*****************************************************************************/
|
652 |
|
|
|
653 |
|
|
/*
|
654 |
|
|
* Define the driver info for a user level control device. Used mainly
|
655 |
|
|
* to get at port stats - only not using the port device itself.
|
656 |
|
|
*/
|
657 |
|
|
static struct file_operations stl_fsiomem = {
|
658 |
|
|
NULL,
|
659 |
|
|
NULL,
|
660 |
|
|
NULL,
|
661 |
|
|
NULL,
|
662 |
|
|
NULL,
|
663 |
|
|
stl_memioctl,
|
664 |
|
|
NULL,
|
665 |
|
|
stl_memopen,
|
666 |
|
|
stl_memclose,
|
667 |
|
|
NULL
|
668 |
|
|
};
|
669 |
|
|
|
670 |
|
|
/*****************************************************************************/
|
671 |
|
|
|
672 |
|
|
#ifdef MODULE
|
673 |
|
|
|
674 |
|
|
/*
|
675 |
|
|
* Loadable module initialization stuff.
|
676 |
|
|
*/
|
677 |
|
|
|
678 |
|
|
int init_module()
|
679 |
|
|
{
|
680 |
|
|
unsigned long flags;
|
681 |
|
|
|
682 |
|
|
#if DEBUG
|
683 |
|
|
printk("init_module()\n");
|
684 |
|
|
#endif
|
685 |
|
|
|
686 |
|
|
save_flags(flags);
|
687 |
|
|
cli();
|
688 |
|
|
stl_init();
|
689 |
|
|
restore_flags(flags);
|
690 |
|
|
|
691 |
|
|
return(0);
|
692 |
|
|
}
|
693 |
|
|
|
694 |
|
|
/*****************************************************************************/
|
695 |
|
|
|
696 |
|
|
void cleanup_module()
|
697 |
|
|
{
|
698 |
|
|
stlbrd_t *brdp;
|
699 |
|
|
stlpanel_t *panelp;
|
700 |
|
|
stlport_t *portp;
|
701 |
|
|
unsigned long flags;
|
702 |
|
|
int i, j, k;
|
703 |
|
|
|
704 |
|
|
#if DEBUG
|
705 |
|
|
printk("cleanup_module()\n");
|
706 |
|
|
#endif
|
707 |
|
|
|
708 |
|
|
printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
|
709 |
|
|
stl_drvversion);
|
710 |
|
|
|
711 |
|
|
save_flags(flags);
|
712 |
|
|
cli();
|
713 |
|
|
|
714 |
|
|
/*
|
715 |
|
|
* Free up all allocated resources used by the ports. This includes
|
716 |
|
|
* memory and interrupts. As part of this process we will also do
|
717 |
|
|
* a hangup on every open port - to try to flush out any processes
|
718 |
|
|
* hanging onto ports.
|
719 |
|
|
*/
|
720 |
|
|
i = tty_unregister_driver(&stl_serial);
|
721 |
|
|
j = tty_unregister_driver(&stl_callout);
|
722 |
|
|
if (i || j) {
|
723 |
|
|
printk("STALLION: failed to un-register tty driver, "
|
724 |
|
|
"errno=%d,%d\n", -i, -j);
|
725 |
|
|
restore_flags(flags);
|
726 |
|
|
return;
|
727 |
|
|
}
|
728 |
|
|
if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
|
729 |
|
|
printk("STALLION: failed to un-register serial memory device, "
|
730 |
|
|
"errno=%d\n", -i);
|
731 |
|
|
|
732 |
|
|
if (stl_tmpwritebuf != (char *) NULL)
|
733 |
|
|
kfree_s(stl_tmpwritebuf, STL_TXBUFSIZE);
|
734 |
|
|
|
735 |
|
|
for (i = 0; (i < stl_nrbrds); i++) {
|
736 |
|
|
brdp = stl_brds[i];
|
737 |
|
|
for (j = 0; (j < STL_MAXPANELS); j++) {
|
738 |
|
|
panelp = brdp->panels[j];
|
739 |
|
|
if (panelp == (stlpanel_t *) NULL)
|
740 |
|
|
continue;
|
741 |
|
|
for (k = 0; (k < STL_PORTSPERPANEL); k++) {
|
742 |
|
|
portp = panelp->ports[k];
|
743 |
|
|
if (portp == (stlport_t *) NULL)
|
744 |
|
|
continue;
|
745 |
|
|
if (portp->tty != (struct tty_struct *) NULL)
|
746 |
|
|
stl_hangup(portp->tty);
|
747 |
|
|
if (portp->tx.buf != (char *) NULL)
|
748 |
|
|
kfree_s(portp->tx.buf, STL_TXBUFSIZE);
|
749 |
|
|
kfree_s(portp, sizeof(stlport_t));
|
750 |
|
|
}
|
751 |
|
|
kfree_s(panelp, sizeof(stlpanel_t));
|
752 |
|
|
}
|
753 |
|
|
|
754 |
|
|
release_region(brdp->ioaddr1, brdp->iosize1);
|
755 |
|
|
if (brdp->iosize2 > 0)
|
756 |
|
|
release_region(brdp->ioaddr2, brdp->iosize2);
|
757 |
|
|
|
758 |
|
|
kfree_s(brdp, sizeof(stlbrd_t));
|
759 |
|
|
stl_brds[i] = (stlbrd_t *) NULL;
|
760 |
|
|
}
|
761 |
|
|
|
762 |
|
|
for (i = 0; (i < stl_numintrs); i++)
|
763 |
|
|
free_irq(stl_gotintrs[i], NULL);
|
764 |
|
|
|
765 |
|
|
restore_flags(flags);
|
766 |
|
|
}
|
767 |
|
|
|
768 |
|
|
#endif
|
769 |
|
|
|
770 |
|
|
/*****************************************************************************/
|
771 |
|
|
|
772 |
|
|
/*
|
773 |
|
|
* Local driver kernel memory allocation routine.
|
774 |
|
|
*/
|
775 |
|
|
|
776 |
|
|
static void *stl_memalloc(int len)
|
777 |
|
|
{
|
778 |
|
|
return((void *) kmalloc(len, GFP_KERNEL));
|
779 |
|
|
}
|
780 |
|
|
|
781 |
|
|
/*****************************************************************************/
|
782 |
|
|
|
783 |
|
|
static int stl_open(struct tty_struct *tty, struct file *filp)
|
784 |
|
|
{
|
785 |
|
|
stlport_t *portp;
|
786 |
|
|
stlbrd_t *brdp;
|
787 |
|
|
unsigned int minordev;
|
788 |
|
|
int brdnr, panelnr, portnr, rc;
|
789 |
|
|
|
790 |
|
|
#if DEBUG
|
791 |
|
|
printk("stl_open(tty=%x,filp=%x): device=%x\n", (int) tty,
|
792 |
|
|
(int) filp, tty->device);
|
793 |
|
|
#endif
|
794 |
|
|
|
795 |
|
|
minordev = MINOR(tty->device);
|
796 |
|
|
brdnr = MKDEV2BRD(minordev);
|
797 |
|
|
if (brdnr >= stl_nrbrds)
|
798 |
|
|
return(-ENODEV);
|
799 |
|
|
brdp = stl_brds[brdnr];
|
800 |
|
|
if (brdp == (stlbrd_t *) NULL)
|
801 |
|
|
return(-ENODEV);
|
802 |
|
|
minordev = MKDEV2PORT(minordev);
|
803 |
|
|
for (portnr = -1, panelnr = 0; (panelnr < STL_MAXPANELS); panelnr++) {
|
804 |
|
|
if (brdp->panels[panelnr] == (stlpanel_t *) NULL)
|
805 |
|
|
break;
|
806 |
|
|
if (minordev < brdp->panels[panelnr]->nrports) {
|
807 |
|
|
portnr = minordev;
|
808 |
|
|
break;
|
809 |
|
|
}
|
810 |
|
|
minordev -= brdp->panels[panelnr]->nrports;
|
811 |
|
|
}
|
812 |
|
|
if (portnr < 0)
|
813 |
|
|
return(-ENODEV);
|
814 |
|
|
|
815 |
|
|
portp = brdp->panels[panelnr]->ports[portnr];
|
816 |
|
|
if (portp == (stlport_t *) NULL)
|
817 |
|
|
return(-ENODEV);
|
818 |
|
|
|
819 |
|
|
MOD_INC_USE_COUNT;
|
820 |
|
|
|
821 |
|
|
/*
|
822 |
|
|
* On the first open of the device setup the port hardware, and
|
823 |
|
|
* initialize the per port data structure.
|
824 |
|
|
*/
|
825 |
|
|
portp->tty = tty;
|
826 |
|
|
tty->driver_data = portp;
|
827 |
|
|
portp->refcount++;
|
828 |
|
|
|
829 |
|
|
if ((portp->flags & ASYNC_INITIALIZED) == 0) {
|
830 |
|
|
if (portp->tx.buf == (char *) NULL) {
|
831 |
|
|
portp->tx.buf = (char *) stl_memalloc(STL_TXBUFSIZE);
|
832 |
|
|
if (portp->tx.buf == (char *) NULL)
|
833 |
|
|
return(-ENOMEM);
|
834 |
|
|
portp->tx.head = portp->tx.buf;
|
835 |
|
|
portp->tx.tail = portp->tx.buf;
|
836 |
|
|
}
|
837 |
|
|
stl_setport(portp, tty->termios);
|
838 |
|
|
portp->sigs = stl_getsignals(portp);
|
839 |
|
|
stl_setsignals(portp, 1, 1);
|
840 |
|
|
stl_enablerxtx(portp, 1, 1);
|
841 |
|
|
stl_startrxtx(portp, 1, 0);
|
842 |
|
|
clear_bit(TTY_IO_ERROR, &tty->flags);
|
843 |
|
|
portp->flags |= ASYNC_INITIALIZED;
|
844 |
|
|
}
|
845 |
|
|
|
846 |
|
|
/*
|
847 |
|
|
* Check if this port is in the middle of closing. If so then wait
|
848 |
|
|
* until it is closed then return error status, based on flag settings.
|
849 |
|
|
* The sleep here does not need interrupt protection since the wakeup
|
850 |
|
|
* for it is done with the same context.
|
851 |
|
|
*/
|
852 |
|
|
if (portp->flags & ASYNC_CLOSING) {
|
853 |
|
|
interruptible_sleep_on(&portp->close_wait);
|
854 |
|
|
if (portp->flags & ASYNC_HUP_NOTIFY)
|
855 |
|
|
return(-EAGAIN);
|
856 |
|
|
return(-ERESTARTSYS);
|
857 |
|
|
}
|
858 |
|
|
|
859 |
|
|
/*
|
860 |
|
|
* Based on type of open being done check if it can overlap with any
|
861 |
|
|
* previous opens still in effect. If we are a normal serial device
|
862 |
|
|
* then also we might have to wait for carrier.
|
863 |
|
|
*/
|
864 |
|
|
if (tty->driver.subtype == STL_DRVTYPCALLOUT) {
|
865 |
|
|
if (portp->flags & ASYNC_NORMAL_ACTIVE)
|
866 |
|
|
return(-EBUSY);
|
867 |
|
|
if (portp->flags & ASYNC_CALLOUT_ACTIVE) {
|
868 |
|
|
if ((portp->flags & ASYNC_SESSION_LOCKOUT) &&
|
869 |
|
|
(portp->session != current->session))
|
870 |
|
|
return(-EBUSY);
|
871 |
|
|
if ((portp->flags & ASYNC_PGRP_LOCKOUT) &&
|
872 |
|
|
(portp->pgrp != current->pgrp))
|
873 |
|
|
return(-EBUSY);
|
874 |
|
|
}
|
875 |
|
|
portp->flags |= ASYNC_CALLOUT_ACTIVE;
|
876 |
|
|
} else {
|
877 |
|
|
if (filp->f_flags & O_NONBLOCK) {
|
878 |
|
|
if (portp->flags & ASYNC_CALLOUT_ACTIVE)
|
879 |
|
|
return(-EBUSY);
|
880 |
|
|
} else {
|
881 |
|
|
if ((rc = stl_waitcarrier(portp, filp)) != 0)
|
882 |
|
|
return(rc);
|
883 |
|
|
}
|
884 |
|
|
portp->flags |= ASYNC_NORMAL_ACTIVE;
|
885 |
|
|
}
|
886 |
|
|
|
887 |
|
|
if ((portp->refcount == 1) && (portp->flags & ASYNC_SPLIT_TERMIOS)) {
|
888 |
|
|
if (tty->driver.subtype == STL_DRVTYPSERIAL)
|
889 |
|
|
*tty->termios = portp->normaltermios;
|
890 |
|
|
else
|
891 |
|
|
*tty->termios = portp->callouttermios;
|
892 |
|
|
stl_setport(portp, tty->termios);
|
893 |
|
|
}
|
894 |
|
|
|
895 |
|
|
portp->session = current->session;
|
896 |
|
|
portp->pgrp = current->pgrp;
|
897 |
|
|
return(0);
|
898 |
|
|
}
|
899 |
|
|
|
900 |
|
|
/*****************************************************************************/
|
901 |
|
|
|
902 |
|
|
/*
|
903 |
|
|
* Possibly need to wait for carrier (DCD signal) to come high. Say
|
904 |
|
|
* maybe because if we are clocal then we don't need to wait...
|
905 |
|
|
*/
|
906 |
|
|
|
907 |
|
|
static int stl_waitcarrier(stlport_t *portp, struct file *filp)
|
908 |
|
|
{
|
909 |
|
|
unsigned long flags;
|
910 |
|
|
int rc, doclocal;
|
911 |
|
|
|
912 |
|
|
#if DEBUG
|
913 |
|
|
printk("stl_waitcarrier(portp=%x,filp=%x)\n", (int) portp, (int) filp);
|
914 |
|
|
#endif
|
915 |
|
|
|
916 |
|
|
rc = 0;
|
917 |
|
|
doclocal = 0;
|
918 |
|
|
|
919 |
|
|
if (portp->flags & ASYNC_CALLOUT_ACTIVE) {
|
920 |
|
|
if (portp->normaltermios.c_cflag & CLOCAL)
|
921 |
|
|
doclocal++;
|
922 |
|
|
} else {
|
923 |
|
|
if (portp->tty->termios->c_cflag & CLOCAL)
|
924 |
|
|
doclocal++;
|
925 |
|
|
}
|
926 |
|
|
|
927 |
|
|
save_flags(flags);
|
928 |
|
|
cli();
|
929 |
|
|
portp->openwaitcnt++;
|
930 |
|
|
if (! tty_hung_up_p(filp))
|
931 |
|
|
portp->refcount--;
|
932 |
|
|
|
933 |
|
|
for (;;) {
|
934 |
|
|
if ((portp->flags & ASYNC_CALLOUT_ACTIVE) == 0)
|
935 |
|
|
stl_setsignals(portp, 1, 1);
|
936 |
|
|
if (tty_hung_up_p(filp) ||
|
937 |
|
|
((portp->flags & ASYNC_INITIALIZED) == 0)) {
|
938 |
|
|
if (portp->flags & ASYNC_HUP_NOTIFY)
|
939 |
|
|
rc = -EBUSY;
|
940 |
|
|
else
|
941 |
|
|
rc = -ERESTARTSYS;
|
942 |
|
|
break;
|
943 |
|
|
}
|
944 |
|
|
if (((portp->flags & ASYNC_CALLOUT_ACTIVE) == 0) &&
|
945 |
|
|
((portp->flags & ASYNC_CLOSING) == 0) &&
|
946 |
|
|
(doclocal || (portp->sigs & TIOCM_CD))) {
|
947 |
|
|
break;
|
948 |
|
|
}
|
949 |
|
|
if (current->signal & ~current->blocked) {
|
950 |
|
|
rc = -ERESTARTSYS;
|
951 |
|
|
break;
|
952 |
|
|
}
|
953 |
|
|
interruptible_sleep_on(&portp->open_wait);
|
954 |
|
|
}
|
955 |
|
|
|
956 |
|
|
if (! tty_hung_up_p(filp))
|
957 |
|
|
portp->refcount++;
|
958 |
|
|
portp->openwaitcnt--;
|
959 |
|
|
restore_flags(flags);
|
960 |
|
|
|
961 |
|
|
return(rc);
|
962 |
|
|
}
|
963 |
|
|
|
964 |
|
|
/*****************************************************************************/
|
965 |
|
|
|
966 |
|
|
static void stl_close(struct tty_struct *tty, struct file *filp)
|
967 |
|
|
{
|
968 |
|
|
stlport_t *portp;
|
969 |
|
|
unsigned long flags;
|
970 |
|
|
|
971 |
|
|
#if DEBUG
|
972 |
|
|
printk("stl_close(tty=%x,filp=%x)\n", (int) tty, (int) filp);
|
973 |
|
|
#endif
|
974 |
|
|
|
975 |
|
|
portp = tty->driver_data;
|
976 |
|
|
if (portp == (stlport_t *) NULL)
|
977 |
|
|
return;
|
978 |
|
|
|
979 |
|
|
save_flags(flags);
|
980 |
|
|
cli();
|
981 |
|
|
if (tty_hung_up_p(filp)) {
|
982 |
|
|
MOD_DEC_USE_COUNT;
|
983 |
|
|
restore_flags(flags);
|
984 |
|
|
return;
|
985 |
|
|
}
|
986 |
|
|
if ((tty->count == 1) && (portp->refcount != 1))
|
987 |
|
|
portp->refcount = 1;
|
988 |
|
|
if (portp->refcount-- > 1) {
|
989 |
|
|
MOD_DEC_USE_COUNT;
|
990 |
|
|
restore_flags(flags);
|
991 |
|
|
return;
|
992 |
|
|
}
|
993 |
|
|
|
994 |
|
|
portp->refcount = 0;
|
995 |
|
|
portp->flags |= ASYNC_CLOSING;
|
996 |
|
|
|
997 |
|
|
if (portp->flags & ASYNC_NORMAL_ACTIVE)
|
998 |
|
|
portp->normaltermios = *tty->termios;
|
999 |
|
|
if (portp->flags & ASYNC_CALLOUT_ACTIVE)
|
1000 |
|
|
portp->callouttermios = *tty->termios;
|
1001 |
|
|
|
1002 |
|
|
/*
|
1003 |
|
|
* May want to wait for any data to drain before closing. The BUSY
|
1004 |
|
|
* flag keeps track of whether we are still sending or not - it is
|
1005 |
|
|
* very accurate for the cd1400, not quite so for the sc26198.
|
1006 |
|
|
* (The sc26198 has no "end-of-data" interrupt only empty FIFO)
|
1007 |
|
|
*/
|
1008 |
|
|
tty->closing = 1;
|
1009 |
|
|
if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
|
1010 |
|
|
tty_wait_until_sent(tty, portp->closing_wait);
|
1011 |
|
|
stl_waituntilsent(tty, (HZ / 2));
|
1012 |
|
|
|
1013 |
|
|
portp->flags &= ~ASYNC_INITIALIZED;
|
1014 |
|
|
stl_disableintrs(portp);
|
1015 |
|
|
if (tty->termios->c_cflag & HUPCL)
|
1016 |
|
|
stl_setsignals(portp, 0, 0);
|
1017 |
|
|
stl_enablerxtx(portp, 0, 0);
|
1018 |
|
|
stl_flushbuffer(tty);
|
1019 |
|
|
portp->istate = 0;
|
1020 |
|
|
if (portp->tx.buf != (char *) NULL) {
|
1021 |
|
|
kfree_s(portp->tx.buf, STL_TXBUFSIZE);
|
1022 |
|
|
portp->tx.buf = (char *) NULL;
|
1023 |
|
|
portp->tx.head = (char *) NULL;
|
1024 |
|
|
portp->tx.tail = (char *) NULL;
|
1025 |
|
|
}
|
1026 |
|
|
set_bit(TTY_IO_ERROR, &tty->flags);
|
1027 |
|
|
if (tty->ldisc.flush_buffer)
|
1028 |
|
|
(tty->ldisc.flush_buffer)(tty);
|
1029 |
|
|
|
1030 |
|
|
tty->closing = 0;
|
1031 |
|
|
portp->tty = (struct tty_struct *) NULL;
|
1032 |
|
|
|
1033 |
|
|
if (portp->openwaitcnt) {
|
1034 |
|
|
if (portp->close_delay)
|
1035 |
|
|
stl_delay(portp->close_delay);
|
1036 |
|
|
wake_up_interruptible(&portp->open_wait);
|
1037 |
|
|
}
|
1038 |
|
|
|
1039 |
|
|
portp->flags &= ~(ASYNC_CALLOUT_ACTIVE | ASYNC_NORMAL_ACTIVE |
|
1040 |
|
|
ASYNC_CLOSING);
|
1041 |
|
|
wake_up_interruptible(&portp->close_wait);
|
1042 |
|
|
MOD_DEC_USE_COUNT;
|
1043 |
|
|
restore_flags(flags);
|
1044 |
|
|
}
|
1045 |
|
|
|
1046 |
|
|
/*****************************************************************************/
|
1047 |
|
|
|
1048 |
|
|
/*
|
1049 |
|
|
* Wait for a specified delay period, this is not a busy-loop. It will
|
1050 |
|
|
* give up the processor while waiting. Unfortunately this has some
|
1051 |
|
|
* rather intimate knowledge of the process management stuff.
|
1052 |
|
|
*/
|
1053 |
|
|
|
1054 |
|
|
static void stl_delay(int len)
|
1055 |
|
|
{
|
1056 |
|
|
#if DEBUG
|
1057 |
|
|
printk("stl_delay(len=%d)\n", len);
|
1058 |
|
|
#endif
|
1059 |
|
|
if (len > 0) {
|
1060 |
|
|
current->state = TASK_INTERRUPTIBLE;
|
1061 |
|
|
current->timeout = jiffies + len;
|
1062 |
|
|
schedule();
|
1063 |
|
|
}
|
1064 |
|
|
}
|
1065 |
|
|
|
1066 |
|
|
/*****************************************************************************/
|
1067 |
|
|
|
1068 |
|
|
/*
|
1069 |
|
|
* Write routine. Take data and stuff it in to the TX ring queue.
|
1070 |
|
|
* If transmit interrupts are not running then start them.
|
1071 |
|
|
*/
|
1072 |
|
|
|
1073 |
|
|
static int stl_write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count)
|
1074 |
|
|
{
|
1075 |
|
|
stlport_t *portp;
|
1076 |
|
|
unsigned int len, stlen;
|
1077 |
|
|
unsigned long flags;
|
1078 |
|
|
unsigned char *chbuf;
|
1079 |
|
|
char *head, *tail;
|
1080 |
|
|
|
1081 |
|
|
#if DEBUG
|
1082 |
|
|
printk("stl_write(tty=%x,from_user=%d,buf=%x,count=%d)\n",
|
1083 |
|
|
(int) tty, from_user, (int) buf, count);
|
1084 |
|
|
#endif
|
1085 |
|
|
|
1086 |
|
|
if ((tty == (struct tty_struct *) NULL) ||
|
1087 |
|
|
(stl_tmpwritebuf == (char *) NULL))
|
1088 |
|
|
return(0);
|
1089 |
|
|
portp = tty->driver_data;
|
1090 |
|
|
if (portp == (stlport_t *) NULL)
|
1091 |
|
|
return(0);
|
1092 |
|
|
if (portp->tx.buf == (char *) NULL)
|
1093 |
|
|
return(0);
|
1094 |
|
|
|
1095 |
|
|
/*
|
1096 |
|
|
* If copying direct from user space we must cater for page faults,
|
1097 |
|
|
* causing us to "sleep" here for a while. To handle this copy in all
|
1098 |
|
|
* the data we need now, into a local buffer. Then when we got it all
|
1099 |
|
|
* copy it into the TX buffer.
|
1100 |
|
|
*/
|
1101 |
|
|
chbuf = (unsigned char *) buf;
|
1102 |
|
|
if (from_user) {
|
1103 |
|
|
head = portp->tx.head;
|
1104 |
|
|
tail = portp->tx.tail;
|
1105 |
|
|
len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) :
|
1106 |
|
|
(tail - head - 1);
|
1107 |
|
|
count = MIN(len, count);
|
1108 |
|
|
|
1109 |
|
|
save_flags(flags);
|
1110 |
|
|
cli();
|
1111 |
|
|
down(&stl_tmpwritesem);
|
1112 |
|
|
memcpy_fromfs(stl_tmpwritebuf, chbuf, count);
|
1113 |
|
|
up(&stl_tmpwritesem);
|
1114 |
|
|
restore_flags(flags);
|
1115 |
|
|
chbuf = &stl_tmpwritebuf[0];
|
1116 |
|
|
}
|
1117 |
|
|
|
1118 |
|
|
head = portp->tx.head;
|
1119 |
|
|
tail = portp->tx.tail;
|
1120 |
|
|
if (head >= tail) {
|
1121 |
|
|
len = STL_TXBUFSIZE - (head - tail) - 1;
|
1122 |
|
|
stlen = STL_TXBUFSIZE - (head - portp->tx.buf);
|
1123 |
|
|
} else {
|
1124 |
|
|
len = tail - head - 1;
|
1125 |
|
|
stlen = len;
|
1126 |
|
|
}
|
1127 |
|
|
|
1128 |
|
|
len = MIN(len, count);
|
1129 |
|
|
count = 0;
|
1130 |
|
|
while (len > 0) {
|
1131 |
|
|
stlen = MIN(len, stlen);
|
1132 |
|
|
memcpy(head, chbuf, stlen);
|
1133 |
|
|
len -= stlen;
|
1134 |
|
|
chbuf += stlen;
|
1135 |
|
|
count += stlen;
|
1136 |
|
|
head += stlen;
|
1137 |
|
|
if (head >= (portp->tx.buf + STL_TXBUFSIZE)) {
|
1138 |
|
|
head = portp->tx.buf;
|
1139 |
|
|
stlen = tail - head;
|
1140 |
|
|
}
|
1141 |
|
|
}
|
1142 |
|
|
portp->tx.head = head;
|
1143 |
|
|
|
1144 |
|
|
clear_bit(ASYI_TXLOW, &portp->istate);
|
1145 |
|
|
stl_startrxtx(portp, -1, 1);
|
1146 |
|
|
|
1147 |
|
|
return(count);
|
1148 |
|
|
}
|
1149 |
|
|
|
1150 |
|
|
/*****************************************************************************/
|
1151 |
|
|
|
1152 |
|
|
static void stl_putchar(struct tty_struct *tty, unsigned char ch)
|
1153 |
|
|
{
|
1154 |
|
|
stlport_t *portp;
|
1155 |
|
|
unsigned int len;
|
1156 |
|
|
char *head, *tail;
|
1157 |
|
|
|
1158 |
|
|
#if DEBUG
|
1159 |
|
|
printk("stl_putchar(tty=%x,ch=%x)\n", (int) tty, (int) ch);
|
1160 |
|
|
#endif
|
1161 |
|
|
|
1162 |
|
|
if (tty == (struct tty_struct *) NULL)
|
1163 |
|
|
return;
|
1164 |
|
|
portp = tty->driver_data;
|
1165 |
|
|
if (portp == (stlport_t *) NULL)
|
1166 |
|
|
return;
|
1167 |
|
|
if (portp->tx.buf == (char *) NULL)
|
1168 |
|
|
return;
|
1169 |
|
|
|
1170 |
|
|
head = portp->tx.head;
|
1171 |
|
|
tail = portp->tx.tail;
|
1172 |
|
|
|
1173 |
|
|
len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail)) : (tail - head);
|
1174 |
|
|
len--;
|
1175 |
|
|
|
1176 |
|
|
if (len > 0) {
|
1177 |
|
|
*head++ = ch;
|
1178 |
|
|
if (head >= (portp->tx.buf + STL_TXBUFSIZE))
|
1179 |
|
|
head = portp->tx.buf;
|
1180 |
|
|
}
|
1181 |
|
|
portp->tx.head = head;
|
1182 |
|
|
}
|
1183 |
|
|
|
1184 |
|
|
/*****************************************************************************/
|
1185 |
|
|
|
1186 |
|
|
/*
|
1187 |
|
|
* If there are any characters in the buffer then make sure that TX
|
1188 |
|
|
* interrupts are on and get'em out. Normally used after the putchar
|
1189 |
|
|
* routine has been called.
|
1190 |
|
|
*/
|
1191 |
|
|
|
1192 |
|
|
static void stl_flushchars(struct tty_struct *tty)
|
1193 |
|
|
{
|
1194 |
|
|
stlport_t *portp;
|
1195 |
|
|
|
1196 |
|
|
#if DEBUG
|
1197 |
|
|
printk("stl_flushchars(tty=%x)\n", (int) tty);
|
1198 |
|
|
#endif
|
1199 |
|
|
|
1200 |
|
|
if (tty == (struct tty_struct *) NULL)
|
1201 |
|
|
return;
|
1202 |
|
|
portp = tty->driver_data;
|
1203 |
|
|
if (portp == (stlport_t *) NULL)
|
1204 |
|
|
return;
|
1205 |
|
|
if (portp->tx.buf == (char *) NULL)
|
1206 |
|
|
return;
|
1207 |
|
|
|
1208 |
|
|
#if 0
|
1209 |
|
|
if (tty->stopped || tty->hw_stopped ||
|
1210 |
|
|
(portp->tx.head == portp->tx.tail))
|
1211 |
|
|
return;
|
1212 |
|
|
#endif
|
1213 |
|
|
stl_startrxtx(portp, -1, 1);
|
1214 |
|
|
}
|
1215 |
|
|
|
1216 |
|
|
/*****************************************************************************/
|
1217 |
|
|
|
1218 |
|
|
static int stl_writeroom(struct tty_struct *tty)
|
1219 |
|
|
{
|
1220 |
|
|
stlport_t *portp;
|
1221 |
|
|
char *head, *tail;
|
1222 |
|
|
|
1223 |
|
|
#if DEBUG
|
1224 |
|
|
printk("stl_writeroom(tty=%x)\n", (int) tty);
|
1225 |
|
|
#endif
|
1226 |
|
|
|
1227 |
|
|
if (tty == (struct tty_struct *) NULL)
|
1228 |
|
|
return(0);
|
1229 |
|
|
portp = tty->driver_data;
|
1230 |
|
|
if (portp == (stlport_t *) NULL)
|
1231 |
|
|
return(0);
|
1232 |
|
|
if (portp->tx.buf == (char *) NULL)
|
1233 |
|
|
return(0);
|
1234 |
|
|
|
1235 |
|
|
head = portp->tx.head;
|
1236 |
|
|
tail = portp->tx.tail;
|
1237 |
|
|
return((head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1));
|
1238 |
|
|
}
|
1239 |
|
|
|
1240 |
|
|
/*****************************************************************************/
|
1241 |
|
|
|
1242 |
|
|
/*
|
1243 |
|
|
* Return number of chars in the TX buffer. Normally we would just
|
1244 |
|
|
* calculate the number of chars in the buffer and return that, but if
|
1245 |
|
|
* the buffer is empty and TX interrupts are still on then we return
|
1246 |
|
|
* that the buffer still has 1 char in it. This way whoever called us
|
1247 |
|
|
* will not think that ALL chars have drained - since the UART still
|
1248 |
|
|
* must have some chars in it (we are busy after all).
|
1249 |
|
|
*/
|
1250 |
|
|
|
1251 |
|
|
static int stl_charsinbuffer(struct tty_struct *tty)
|
1252 |
|
|
{
|
1253 |
|
|
stlport_t *portp;
|
1254 |
|
|
unsigned int size;
|
1255 |
|
|
char *head, *tail;
|
1256 |
|
|
|
1257 |
|
|
#if DEBUG
|
1258 |
|
|
printk("stl_charsinbuffer(tty=%x)\n", (int) tty);
|
1259 |
|
|
#endif
|
1260 |
|
|
|
1261 |
|
|
if (tty == (struct tty_struct *) NULL)
|
1262 |
|
|
return(0);
|
1263 |
|
|
portp = tty->driver_data;
|
1264 |
|
|
if (portp == (stlport_t *) NULL)
|
1265 |
|
|
return(0);
|
1266 |
|
|
if (portp->tx.buf == (char *) NULL)
|
1267 |
|
|
return(0);
|
1268 |
|
|
|
1269 |
|
|
head = portp->tx.head;
|
1270 |
|
|
tail = portp->tx.tail;
|
1271 |
|
|
size = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
|
1272 |
|
|
if ((size == 0) && test_bit(ASYI_TXBUSY, &portp->istate))
|
1273 |
|
|
size = 1;
|
1274 |
|
|
return(size);
|
1275 |
|
|
}
|
1276 |
|
|
|
1277 |
|
|
/*****************************************************************************/
|
1278 |
|
|
|
1279 |
|
|
/*
|
1280 |
|
|
* Generate the serial struct info.
|
1281 |
|
|
*/
|
1282 |
|
|
|
1283 |
|
|
static void stl_getserial(stlport_t *portp, struct serial_struct *sp)
|
1284 |
|
|
{
|
1285 |
|
|
struct serial_struct sio;
|
1286 |
|
|
stlbrd_t *brdp;
|
1287 |
|
|
|
1288 |
|
|
#if DEBUG
|
1289 |
|
|
printk("stl_getserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
|
1290 |
|
|
#endif
|
1291 |
|
|
|
1292 |
|
|
memset(&sio, 0, sizeof(struct serial_struct));
|
1293 |
|
|
sio.line = portp->portnr;
|
1294 |
|
|
sio.port = portp->ioaddr;
|
1295 |
|
|
sio.flags = portp->flags;
|
1296 |
|
|
sio.baud_base = portp->baud_base;
|
1297 |
|
|
sio.close_delay = portp->close_delay;
|
1298 |
|
|
sio.closing_wait = portp->closing_wait;
|
1299 |
|
|
sio.custom_divisor = portp->custom_divisor;
|
1300 |
|
|
sio.hub6 = 0;
|
1301 |
|
|
if (portp->uartp == &stl_cd1400uart) {
|
1302 |
|
|
sio.type = PORT_CIRRUS;
|
1303 |
|
|
sio.xmit_fifo_size = CD1400_TXFIFOSIZE;
|
1304 |
|
|
} else {
|
1305 |
|
|
sio.type = PORT_UNKNOWN;
|
1306 |
|
|
sio.xmit_fifo_size = SC26198_TXFIFOSIZE;
|
1307 |
|
|
}
|
1308 |
|
|
|
1309 |
|
|
brdp = stl_brds[portp->brdnr];
|
1310 |
|
|
if (brdp != (stlbrd_t *) NULL)
|
1311 |
|
|
sio.irq = brdp->irq;
|
1312 |
|
|
|
1313 |
|
|
memcpy_tofs(sp, &sio, sizeof(struct serial_struct));
|
1314 |
|
|
}
|
1315 |
|
|
|
1316 |
|
|
/*****************************************************************************/
|
1317 |
|
|
|
1318 |
|
|
/*
|
1319 |
|
|
* Set port according to the serial struct info.
|
1320 |
|
|
* At this point we do not do any auto-configure stuff, so we will
|
1321 |
|
|
* just quietly ignore any requests to change irq, etc.
|
1322 |
|
|
*/
|
1323 |
|
|
|
1324 |
|
|
static int stl_setserial(stlport_t *portp, struct serial_struct *sp)
|
1325 |
|
|
{
|
1326 |
|
|
struct serial_struct sio;
|
1327 |
|
|
|
1328 |
|
|
#if DEBUG
|
1329 |
|
|
printk("stl_setserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
|
1330 |
|
|
#endif
|
1331 |
|
|
|
1332 |
|
|
memcpy_fromfs(&sio, sp, sizeof(struct serial_struct));
|
1333 |
|
|
if (!suser()) {
|
1334 |
|
|
if ((sio.baud_base != portp->baud_base) ||
|
1335 |
|
|
(sio.close_delay != portp->close_delay) ||
|
1336 |
|
|
((sio.flags & ~ASYNC_USR_MASK) !=
|
1337 |
|
|
(portp->flags & ~ASYNC_USR_MASK)))
|
1338 |
|
|
return(-EPERM);
|
1339 |
|
|
}
|
1340 |
|
|
|
1341 |
|
|
portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
|
1342 |
|
|
(sio.flags & ASYNC_USR_MASK);
|
1343 |
|
|
portp->baud_base = sio.baud_base;
|
1344 |
|
|
portp->close_delay = sio.close_delay;
|
1345 |
|
|
portp->closing_wait = sio.closing_wait;
|
1346 |
|
|
portp->custom_divisor = sio.custom_divisor;
|
1347 |
|
|
stl_setport(portp, portp->tty->termios);
|
1348 |
|
|
return(0);
|
1349 |
|
|
}
|
1350 |
|
|
|
1351 |
|
|
/*****************************************************************************/
|
1352 |
|
|
|
1353 |
|
|
static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
|
1354 |
|
|
{
|
1355 |
|
|
stlport_t *portp;
|
1356 |
|
|
unsigned long val;
|
1357 |
|
|
int rc;
|
1358 |
|
|
|
1359 |
|
|
#if DEBUG
|
1360 |
|
|
printk("stl_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
|
1361 |
|
|
(int) tty, (int) file, cmd, (int) arg);
|
1362 |
|
|
#endif
|
1363 |
|
|
|
1364 |
|
|
if (tty == (struct tty_struct *) NULL)
|
1365 |
|
|
return(-ENODEV);
|
1366 |
|
|
portp = tty->driver_data;
|
1367 |
|
|
if (portp == (stlport_t *) NULL)
|
1368 |
|
|
return(-ENODEV);
|
1369 |
|
|
|
1370 |
|
|
if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
|
1371 |
|
|
(cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
|
1372 |
|
|
if (tty->flags & (1 << TTY_IO_ERROR))
|
1373 |
|
|
return(-EIO);
|
1374 |
|
|
}
|
1375 |
|
|
|
1376 |
|
|
rc = 0;
|
1377 |
|
|
|
1378 |
|
|
switch (cmd) {
|
1379 |
|
|
case TCSBRK:
|
1380 |
|
|
if ((rc = tty_check_change(tty)) == 0) {
|
1381 |
|
|
tty_wait_until_sent(tty, 0);
|
1382 |
|
|
if (! arg)
|
1383 |
|
|
stl_sendbreak(portp, 250);
|
1384 |
|
|
}
|
1385 |
|
|
break;
|
1386 |
|
|
case TCSBRKP:
|
1387 |
|
|
if ((rc = tty_check_change(tty)) == 0) {
|
1388 |
|
|
tty_wait_until_sent(tty, 0);
|
1389 |
|
|
stl_sendbreak(portp, (arg ? (arg * 100) : 250));
|
1390 |
|
|
}
|
1391 |
|
|
break;
|
1392 |
|
|
case TIOCGSOFTCAR:
|
1393 |
|
|
if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
|
1394 |
|
|
sizeof(long))) == 0)
|
1395 |
|
|
put_fs_long(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
|
1396 |
|
|
(unsigned long *) arg);
|
1397 |
|
|
break;
|
1398 |
|
|
case TIOCSSOFTCAR:
|
1399 |
|
|
if ((rc = verify_area(VERIFY_READ, (void *) arg,
|
1400 |
|
|
sizeof(long))) == 0) {
|
1401 |
|
|
arg = get_fs_long((unsigned long *) arg);
|
1402 |
|
|
tty->termios->c_cflag =
|
1403 |
|
|
(tty->termios->c_cflag & ~CLOCAL) |
|
1404 |
|
|
(arg ? CLOCAL : 0);
|
1405 |
|
|
}
|
1406 |
|
|
break;
|
1407 |
|
|
case TIOCMGET:
|
1408 |
|
|
if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
|
1409 |
|
|
sizeof(unsigned int))) == 0) {
|
1410 |
|
|
val = (unsigned long) stl_getsignals(portp);
|
1411 |
|
|
put_fs_long(val, (unsigned long *) arg);
|
1412 |
|
|
}
|
1413 |
|
|
break;
|
1414 |
|
|
case TIOCMBIS:
|
1415 |
|
|
if ((rc = verify_area(VERIFY_READ, (void *) arg,
|
1416 |
|
|
sizeof(long))) == 0) {
|
1417 |
|
|
arg = get_fs_long((unsigned long *) arg);
|
1418 |
|
|
stl_setsignals(portp, ((arg & TIOCM_DTR) ? 1 : -1),
|
1419 |
|
|
((arg & TIOCM_RTS) ? 1 : -1));
|
1420 |
|
|
}
|
1421 |
|
|
break;
|
1422 |
|
|
case TIOCMBIC:
|
1423 |
|
|
if ((rc = verify_area(VERIFY_READ, (void *) arg,
|
1424 |
|
|
sizeof(long))) == 0) {
|
1425 |
|
|
arg = get_fs_long((unsigned long *) arg);
|
1426 |
|
|
stl_setsignals(portp, ((arg & TIOCM_DTR) ? 0 : -1),
|
1427 |
|
|
((arg & TIOCM_RTS) ? 0 : -1));
|
1428 |
|
|
}
|
1429 |
|
|
break;
|
1430 |
|
|
case TIOCMSET:
|
1431 |
|
|
if ((rc = verify_area(VERIFY_READ, (void *) arg,
|
1432 |
|
|
sizeof(long))) == 0) {
|
1433 |
|
|
arg = get_fs_long((unsigned long *) arg);
|
1434 |
|
|
stl_setsignals(portp, ((arg & TIOCM_DTR) ? 1 : 0),
|
1435 |
|
|
((arg & TIOCM_RTS) ? 1 : 0));
|
1436 |
|
|
}
|
1437 |
|
|
break;
|
1438 |
|
|
case TIOCGSERIAL:
|
1439 |
|
|
if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
|
1440 |
|
|
sizeof(struct serial_struct))) == 0)
|
1441 |
|
|
stl_getserial(portp, (struct serial_struct *) arg);
|
1442 |
|
|
break;
|
1443 |
|
|
case TIOCSSERIAL:
|
1444 |
|
|
if ((rc = verify_area(VERIFY_READ, (void *) arg,
|
1445 |
|
|
sizeof(struct serial_struct))) == 0)
|
1446 |
|
|
rc = stl_setserial(portp, (struct serial_struct *) arg);
|
1447 |
|
|
break;
|
1448 |
|
|
case COM_GETPORTSTATS:
|
1449 |
|
|
if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
|
1450 |
|
|
sizeof(comstats_t))) == 0)
|
1451 |
|
|
rc = stl_getportstats(portp, (comstats_t *) arg);
|
1452 |
|
|
break;
|
1453 |
|
|
case COM_CLRPORTSTATS:
|
1454 |
|
|
if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
|
1455 |
|
|
sizeof(comstats_t))) == 0)
|
1456 |
|
|
rc = stl_clrportstats(portp, (comstats_t *) arg);
|
1457 |
|
|
break;
|
1458 |
|
|
case TIOCSERCONFIG:
|
1459 |
|
|
case TIOCSERGWILD:
|
1460 |
|
|
case TIOCSERSWILD:
|
1461 |
|
|
case TIOCSERGETLSR:
|
1462 |
|
|
case TIOCSERGSTRUCT:
|
1463 |
|
|
case TIOCSERGETMULTI:
|
1464 |
|
|
case TIOCSERSETMULTI:
|
1465 |
|
|
default:
|
1466 |
|
|
rc = -ENOIOCTLCMD;
|
1467 |
|
|
break;
|
1468 |
|
|
}
|
1469 |
|
|
|
1470 |
|
|
return(rc);
|
1471 |
|
|
}
|
1472 |
|
|
|
1473 |
|
|
/*****************************************************************************/
|
1474 |
|
|
|
1475 |
|
|
static void stl_settermios(struct tty_struct *tty, struct termios *old)
|
1476 |
|
|
{
|
1477 |
|
|
stlport_t *portp;
|
1478 |
|
|
struct termios *tiosp;
|
1479 |
|
|
|
1480 |
|
|
#if DEBUG
|
1481 |
|
|
printk("stl_settermios(tty=%x,old=%x)\n", (int) tty, (int) old);
|
1482 |
|
|
#endif
|
1483 |
|
|
|
1484 |
|
|
if (tty == (struct tty_struct *) NULL)
|
1485 |
|
|
return;
|
1486 |
|
|
portp = tty->driver_data;
|
1487 |
|
|
if (portp == (stlport_t *) NULL)
|
1488 |
|
|
return;
|
1489 |
|
|
|
1490 |
|
|
tiosp = tty->termios;
|
1491 |
|
|
if ((tiosp->c_cflag == old->c_cflag) &&
|
1492 |
|
|
(tiosp->c_iflag == old->c_iflag))
|
1493 |
|
|
return;
|
1494 |
|
|
|
1495 |
|
|
stl_setport(portp, tiosp);
|
1496 |
|
|
stl_setsignals(portp, ((tiosp->c_cflag & (CBAUD & ~CBAUDEX)) ? 1 : 0),
|
1497 |
|
|
-1);
|
1498 |
|
|
if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0)) {
|
1499 |
|
|
tty->hw_stopped = 0;
|
1500 |
|
|
stl_start(tty);
|
1501 |
|
|
}
|
1502 |
|
|
if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
|
1503 |
|
|
wake_up_interruptible(&portp->open_wait);
|
1504 |
|
|
}
|
1505 |
|
|
|
1506 |
|
|
/*****************************************************************************/
|
1507 |
|
|
|
1508 |
|
|
/*
|
1509 |
|
|
* Attempt to flow control who ever is sending us data. Based on termios
|
1510 |
|
|
* settings use software or/and hardware flow control.
|
1511 |
|
|
*/
|
1512 |
|
|
|
1513 |
|
|
static void stl_throttle(struct tty_struct *tty)
|
1514 |
|
|
{
|
1515 |
|
|
stlport_t *portp;
|
1516 |
|
|
|
1517 |
|
|
#if DEBUG
|
1518 |
|
|
printk("stl_throttle(tty=%x)\n", (int) tty);
|
1519 |
|
|
#endif
|
1520 |
|
|
|
1521 |
|
|
if (tty == (struct tty_struct *) NULL)
|
1522 |
|
|
return;
|
1523 |
|
|
portp = tty->driver_data;
|
1524 |
|
|
if (portp == (stlport_t *) NULL)
|
1525 |
|
|
return;
|
1526 |
|
|
stl_flowctrl(portp, 0);
|
1527 |
|
|
}
|
1528 |
|
|
|
1529 |
|
|
/*****************************************************************************/
|
1530 |
|
|
|
1531 |
|
|
/*
|
1532 |
|
|
* Unflow control the device sending us data...
|
1533 |
|
|
*/
|
1534 |
|
|
|
1535 |
|
|
static void stl_unthrottle(struct tty_struct *tty)
|
1536 |
|
|
{
|
1537 |
|
|
stlport_t *portp;
|
1538 |
|
|
|
1539 |
|
|
#if DEBUG
|
1540 |
|
|
printk("stl_unthrottle(tty=%x)\n", (int) tty);
|
1541 |
|
|
#endif
|
1542 |
|
|
|
1543 |
|
|
if (tty == (struct tty_struct *) NULL)
|
1544 |
|
|
return;
|
1545 |
|
|
portp = tty->driver_data;
|
1546 |
|
|
if (portp == (stlport_t *) NULL)
|
1547 |
|
|
return;
|
1548 |
|
|
stl_flowctrl(portp, 1);
|
1549 |
|
|
}
|
1550 |
|
|
|
1551 |
|
|
/*****************************************************************************/
|
1552 |
|
|
|
1553 |
|
|
/*
|
1554 |
|
|
* Stop the transmitter. Basically to do this we will just turn TX
|
1555 |
|
|
* interrupts off.
|
1556 |
|
|
*/
|
1557 |
|
|
|
1558 |
|
|
static void stl_stop(struct tty_struct *tty)
|
1559 |
|
|
{
|
1560 |
|
|
stlport_t *portp;
|
1561 |
|
|
|
1562 |
|
|
#if DEBUG
|
1563 |
|
|
printk("stl_stop(tty=%x)\n", (int) tty);
|
1564 |
|
|
#endif
|
1565 |
|
|
|
1566 |
|
|
if (tty == (struct tty_struct *) NULL)
|
1567 |
|
|
return;
|
1568 |
|
|
portp = tty->driver_data;
|
1569 |
|
|
if (portp == (stlport_t *) NULL)
|
1570 |
|
|
return;
|
1571 |
|
|
stl_startrxtx(portp, -1, 0);
|
1572 |
|
|
}
|
1573 |
|
|
|
1574 |
|
|
/*****************************************************************************/
|
1575 |
|
|
|
1576 |
|
|
/*
|
1577 |
|
|
* Start the transmitter again. Just turn TX interrupts back on.
|
1578 |
|
|
*/
|
1579 |
|
|
|
1580 |
|
|
static void stl_start(struct tty_struct *tty)
|
1581 |
|
|
{
|
1582 |
|
|
stlport_t *portp;
|
1583 |
|
|
|
1584 |
|
|
#if DEBUG
|
1585 |
|
|
printk("stl_start(tty=%x)\n", (int) tty);
|
1586 |
|
|
#endif
|
1587 |
|
|
|
1588 |
|
|
if (tty == (struct tty_struct *) NULL)
|
1589 |
|
|
return;
|
1590 |
|
|
portp = tty->driver_data;
|
1591 |
|
|
if (portp == (stlport_t *) NULL)
|
1592 |
|
|
return;
|
1593 |
|
|
stl_startrxtx(portp, -1, 1);
|
1594 |
|
|
}
|
1595 |
|
|
|
1596 |
|
|
/*****************************************************************************/
|
1597 |
|
|
|
1598 |
|
|
/*
|
1599 |
|
|
* Hangup this port. This is pretty much like closing the port, only
|
1600 |
|
|
* a little more brutal. No waiting for data to drain. Shutdown the
|
1601 |
|
|
* port and maybe drop signals.
|
1602 |
|
|
*/
|
1603 |
|
|
|
1604 |
|
|
static void stl_hangup(struct tty_struct *tty)
|
1605 |
|
|
{
|
1606 |
|
|
stlport_t *portp;
|
1607 |
|
|
|
1608 |
|
|
#if DEBUG
|
1609 |
|
|
printk("stl_hangup(tty=%x)\n", (int) tty);
|
1610 |
|
|
#endif
|
1611 |
|
|
|
1612 |
|
|
if (tty == (struct tty_struct *) NULL)
|
1613 |
|
|
return;
|
1614 |
|
|
portp = tty->driver_data;
|
1615 |
|
|
if (portp == (stlport_t *) NULL)
|
1616 |
|
|
return;
|
1617 |
|
|
|
1618 |
|
|
portp->flags &= ~ASYNC_INITIALIZED;
|
1619 |
|
|
stl_disableintrs(portp);
|
1620 |
|
|
if (tty->termios->c_cflag & HUPCL)
|
1621 |
|
|
stl_setsignals(portp, 0, 0);
|
1622 |
|
|
stl_enablerxtx(portp, 0, 0);
|
1623 |
|
|
stl_flushbuffer(tty);
|
1624 |
|
|
portp->istate = 0;
|
1625 |
|
|
set_bit(TTY_IO_ERROR, &tty->flags);
|
1626 |
|
|
if (portp->tx.buf != (char *) NULL) {
|
1627 |
|
|
kfree_s(portp->tx.buf, STL_TXBUFSIZE);
|
1628 |
|
|
portp->tx.buf = (char *) NULL;
|
1629 |
|
|
portp->tx.head = (char *) NULL;
|
1630 |
|
|
portp->tx.tail = (char *) NULL;
|
1631 |
|
|
}
|
1632 |
|
|
portp->tty = (struct tty_struct *) NULL;
|
1633 |
|
|
portp->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CALLOUT_ACTIVE);
|
1634 |
|
|
portp->refcount = 0;
|
1635 |
|
|
wake_up_interruptible(&portp->open_wait);
|
1636 |
|
|
}
|
1637 |
|
|
|
1638 |
|
|
/*****************************************************************************/
|
1639 |
|
|
|
1640 |
|
|
static void stl_flushbuffer(struct tty_struct *tty)
|
1641 |
|
|
{
|
1642 |
|
|
stlport_t *portp;
|
1643 |
|
|
|
1644 |
|
|
#if DEBUG
|
1645 |
|
|
printk("stl_flushbuffer(tty=%x)\n", (int) tty);
|
1646 |
|
|
#endif
|
1647 |
|
|
|
1648 |
|
|
if (tty == (struct tty_struct *) NULL)
|
1649 |
|
|
return;
|
1650 |
|
|
portp = tty->driver_data;
|
1651 |
|
|
if (portp == (stlport_t *) NULL)
|
1652 |
|
|
return;
|
1653 |
|
|
|
1654 |
|
|
stl_flush(portp);
|
1655 |
|
|
wake_up_interruptible(&tty->write_wait);
|
1656 |
|
|
if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
|
1657 |
|
|
tty->ldisc.write_wakeup)
|
1658 |
|
|
(tty->ldisc.write_wakeup)(tty);
|
1659 |
|
|
}
|
1660 |
|
|
|
1661 |
|
|
/*****************************************************************************/
|
1662 |
|
|
|
1663 |
|
|
static void stl_waituntilsent(struct tty_struct *tty, int timeout)
|
1664 |
|
|
{
|
1665 |
|
|
stlport_t *portp;
|
1666 |
|
|
unsigned long tend;
|
1667 |
|
|
|
1668 |
|
|
#if DEBUG
|
1669 |
|
|
printk("stl_waituntilsent(tty=%x,timeout=%d)\n", (int) tty, timeout);
|
1670 |
|
|
#endif
|
1671 |
|
|
|
1672 |
|
|
if (tty == (struct tty_struct *) NULL)
|
1673 |
|
|
return;
|
1674 |
|
|
portp = tty->driver_data;
|
1675 |
|
|
if (portp == (stlport_t *) NULL)
|
1676 |
|
|
return;
|
1677 |
|
|
|
1678 |
|
|
if (timeout == 0)
|
1679 |
|
|
timeout = HZ;
|
1680 |
|
|
tend = jiffies + timeout;
|
1681 |
|
|
|
1682 |
|
|
while (stl_datastate(portp)) {
|
1683 |
|
|
if (current->signal & ~current->blocked)
|
1684 |
|
|
break;
|
1685 |
|
|
stl_delay(2);
|
1686 |
|
|
if (jiffies >= tend)
|
1687 |
|
|
break;
|
1688 |
|
|
}
|
1689 |
|
|
}
|
1690 |
|
|
|
1691 |
|
|
/*****************************************************************************/
|
1692 |
|
|
|
1693 |
|
|
/*
|
1694 |
|
|
* All board interrupts are vectored through here first. This code then
|
1695 |
|
|
* calls off to the approrpriate board interrupt handlers.
|
1696 |
|
|
*/
|
1697 |
|
|
|
1698 |
|
|
static void stl_intr(int irq, void *dev_id, struct pt_regs *regs)
|
1699 |
|
|
{
|
1700 |
|
|
stlbrd_t *brdp;
|
1701 |
|
|
int i;
|
1702 |
|
|
|
1703 |
|
|
#if DEBUG
|
1704 |
|
|
printk("stl_intr(irq=%d,regs=%x)\n", irq, (int) regs);
|
1705 |
|
|
#endif
|
1706 |
|
|
|
1707 |
|
|
for (i = 0; (i < stl_nrbrds); i++) {
|
1708 |
|
|
if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL)
|
1709 |
|
|
continue;
|
1710 |
|
|
if (brdp->state == 0)
|
1711 |
|
|
continue;
|
1712 |
|
|
(* brdp->isr)(brdp);
|
1713 |
|
|
}
|
1714 |
|
|
}
|
1715 |
|
|
|
1716 |
|
|
/*****************************************************************************/
|
1717 |
|
|
|
1718 |
|
|
/*
|
1719 |
|
|
* Interrupt service routine for EasyIO board types.
|
1720 |
|
|
*/
|
1721 |
|
|
|
1722 |
|
|
static void stl_eiointr(stlbrd_t *brdp)
|
1723 |
|
|
{
|
1724 |
|
|
stlpanel_t *panelp;
|
1725 |
|
|
unsigned int iobase;
|
1726 |
|
|
|
1727 |
|
|
panelp = brdp->panels[0];
|
1728 |
|
|
iobase = panelp->iobase;
|
1729 |
|
|
while (inb(brdp->iostatus) & EIO_INTRPEND)
|
1730 |
|
|
(* panelp->isr)(panelp, iobase);
|
1731 |
|
|
}
|
1732 |
|
|
|
1733 |
|
|
/*****************************************************************************/
|
1734 |
|
|
|
1735 |
|
|
/*
|
1736 |
|
|
* Interrupt service routine for ECH-AT board types.
|
1737 |
|
|
*/
|
1738 |
|
|
|
1739 |
|
|
static void stl_echatintr(stlbrd_t *brdp)
|
1740 |
|
|
{
|
1741 |
|
|
stlpanel_t *panelp;
|
1742 |
|
|
unsigned int ioaddr;
|
1743 |
|
|
int bnknr;
|
1744 |
|
|
|
1745 |
|
|
outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
|
1746 |
|
|
|
1747 |
|
|
while (inb(brdp->iostatus) & ECH_INTRPEND) {
|
1748 |
|
|
for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
|
1749 |
|
|
ioaddr = brdp->bnkstataddr[bnknr];
|
1750 |
|
|
if (inb(ioaddr) & ECH_PNLINTRPEND) {
|
1751 |
|
|
panelp = brdp->bnk2panel[bnknr];
|
1752 |
|
|
(* panelp->isr)(panelp, (ioaddr & 0xfffc));
|
1753 |
|
|
}
|
1754 |
|
|
}
|
1755 |
|
|
}
|
1756 |
|
|
|
1757 |
|
|
outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
|
1758 |
|
|
}
|
1759 |
|
|
|
1760 |
|
|
/*****************************************************************************/
|
1761 |
|
|
|
1762 |
|
|
/*
|
1763 |
|
|
* Interrupt service routine for ECH-MCA board types.
|
1764 |
|
|
*/
|
1765 |
|
|
|
1766 |
|
|
static void stl_echmcaintr(stlbrd_t *brdp)
|
1767 |
|
|
{
|
1768 |
|
|
stlpanel_t *panelp;
|
1769 |
|
|
unsigned int ioaddr;
|
1770 |
|
|
int bnknr;
|
1771 |
|
|
|
1772 |
|
|
while (inb(brdp->iostatus) & ECH_INTRPEND) {
|
1773 |
|
|
for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
|
1774 |
|
|
ioaddr = brdp->bnkstataddr[bnknr];
|
1775 |
|
|
if (inb(ioaddr) & ECH_PNLINTRPEND) {
|
1776 |
|
|
panelp = brdp->bnk2panel[bnknr];
|
1777 |
|
|
(* panelp->isr)(panelp, (ioaddr & 0xfffc));
|
1778 |
|
|
}
|
1779 |
|
|
}
|
1780 |
|
|
}
|
1781 |
|
|
}
|
1782 |
|
|
|
1783 |
|
|
/*****************************************************************************/
|
1784 |
|
|
|
1785 |
|
|
/*
|
1786 |
|
|
* Interrupt service routine for ECH-PCI board types.
|
1787 |
|
|
*/
|
1788 |
|
|
|
1789 |
|
|
static void stl_echpciintr(stlbrd_t *brdp)
|
1790 |
|
|
{
|
1791 |
|
|
stlpanel_t *panelp;
|
1792 |
|
|
unsigned int ioaddr;
|
1793 |
|
|
int bnknr, recheck;
|
1794 |
|
|
|
1795 |
|
|
while (1) {
|
1796 |
|
|
recheck = 0;
|
1797 |
|
|
for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
|
1798 |
|
|
outb(brdp->bnkpageaddr[bnknr], brdp->ioctrl);
|
1799 |
|
|
ioaddr = brdp->bnkstataddr[bnknr];
|
1800 |
|
|
if (inb(ioaddr) & ECH_PNLINTRPEND) {
|
1801 |
|
|
panelp = brdp->bnk2panel[bnknr];
|
1802 |
|
|
(* panelp->isr)(panelp, (ioaddr & 0xfffc));
|
1803 |
|
|
recheck++;
|
1804 |
|
|
}
|
1805 |
|
|
}
|
1806 |
|
|
if (! recheck)
|
1807 |
|
|
break;
|
1808 |
|
|
}
|
1809 |
|
|
}
|
1810 |
|
|
|
1811 |
|
|
/*****************************************************************************/
|
1812 |
|
|
|
1813 |
|
|
/*
|
1814 |
|
|
* Interrupt service routine for ECH-8/64-PCI board types.
|
1815 |
|
|
*/
|
1816 |
|
|
|
1817 |
|
|
static void stl_echpci64intr(stlbrd_t *brdp)
|
1818 |
|
|
{
|
1819 |
|
|
stlpanel_t *panelp;
|
1820 |
|
|
unsigned int ioaddr;
|
1821 |
|
|
int bnknr;
|
1822 |
|
|
|
1823 |
|
|
while (inb(brdp->ioctrl) & 0x1) {
|
1824 |
|
|
for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
|
1825 |
|
|
ioaddr = brdp->bnkstataddr[bnknr];
|
1826 |
|
|
if (inb(ioaddr) & ECH_PNLINTRPEND) {
|
1827 |
|
|
panelp = brdp->bnk2panel[bnknr];
|
1828 |
|
|
(* panelp->isr)(panelp, (ioaddr & 0xfffc));
|
1829 |
|
|
}
|
1830 |
|
|
}
|
1831 |
|
|
}
|
1832 |
|
|
}
|
1833 |
|
|
|
1834 |
|
|
/*****************************************************************************/
|
1835 |
|
|
|
1836 |
|
|
/*
|
1837 |
|
|
* Service an off-level request for some channel.
|
1838 |
|
|
*/
|
1839 |
|
|
|
1840 |
|
|
static void stl_offintr(void *private)
|
1841 |
|
|
{
|
1842 |
|
|
stlport_t *portp;
|
1843 |
|
|
struct tty_struct *tty;
|
1844 |
|
|
unsigned int oldsigs;
|
1845 |
|
|
|
1846 |
|
|
portp = private;
|
1847 |
|
|
|
1848 |
|
|
#if DEBUG
|
1849 |
|
|
printk("stl_offintr(portp=%x)\n", (int) portp);
|
1850 |
|
|
#endif
|
1851 |
|
|
|
1852 |
|
|
if (portp == (stlport_t *) NULL)
|
1853 |
|
|
return;
|
1854 |
|
|
tty = portp->tty;
|
1855 |
|
|
if (tty == (struct tty_struct *) NULL)
|
1856 |
|
|
return;
|
1857 |
|
|
|
1858 |
|
|
if (test_bit(ASYI_TXLOW, &portp->istate)) {
|
1859 |
|
|
if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
|
1860 |
|
|
tty->ldisc.write_wakeup)
|
1861 |
|
|
(tty->ldisc.write_wakeup)(tty);
|
1862 |
|
|
wake_up_interruptible(&tty->write_wait);
|
1863 |
|
|
}
|
1864 |
|
|
if (test_bit(ASYI_DCDCHANGE, &portp->istate)) {
|
1865 |
|
|
clear_bit(ASYI_DCDCHANGE, &portp->istate);
|
1866 |
|
|
oldsigs = portp->sigs;
|
1867 |
|
|
portp->sigs = stl_getsignals(portp);
|
1868 |
|
|
if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0))
|
1869 |
|
|
wake_up_interruptible(&portp->open_wait);
|
1870 |
|
|
if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0)) {
|
1871 |
|
|
if (portp->flags & ASYNC_CHECK_CD) {
|
1872 |
|
|
if (! ((portp->flags & ASYNC_CALLOUT_ACTIVE) &&
|
1873 |
|
|
(portp->flags & ASYNC_CALLOUT_NOHUP))) {
|
1874 |
|
|
tty_hangup(tty);
|
1875 |
|
|
}
|
1876 |
|
|
}
|
1877 |
|
|
}
|
1878 |
|
|
}
|
1879 |
|
|
}
|
1880 |
|
|
|
1881 |
|
|
/*****************************************************************************/
|
1882 |
|
|
|
1883 |
|
|
/*
|
1884 |
|
|
* Map in interrupt vector to this driver. Check that we don't
|
1885 |
|
|
* already have this vector mapped, we might be sharing this
|
1886 |
|
|
* interrupt across multiple boards.
|
1887 |
|
|
*/
|
1888 |
|
|
|
1889 |
|
|
static int stl_mapirq(int irq, char *name)
|
1890 |
|
|
{
|
1891 |
|
|
int rc, i;
|
1892 |
|
|
|
1893 |
|
|
#if DEBUG
|
1894 |
|
|
printk("stl_mapirq(irq=%d,name=%s)\n", irq, name);
|
1895 |
|
|
#endif
|
1896 |
|
|
|
1897 |
|
|
rc = 0;
|
1898 |
|
|
for (i = 0; (i < stl_numintrs); i++) {
|
1899 |
|
|
if (stl_gotintrs[i] == irq)
|
1900 |
|
|
break;
|
1901 |
|
|
}
|
1902 |
|
|
if (i >= stl_numintrs) {
|
1903 |
|
|
if (request_irq(irq, stl_intr, SA_INTERRUPT, name, NULL) != 0) {
|
1904 |
|
|
printk("STALLION: failed to register interrupt "
|
1905 |
|
|
"routine for %s irq=%d\n", name, irq);
|
1906 |
|
|
rc = -ENODEV;
|
1907 |
|
|
} else {
|
1908 |
|
|
stl_gotintrs[stl_numintrs++] = irq;
|
1909 |
|
|
}
|
1910 |
|
|
}
|
1911 |
|
|
return(rc);
|
1912 |
|
|
}
|
1913 |
|
|
|
1914 |
|
|
/*****************************************************************************/
|
1915 |
|
|
|
1916 |
|
|
/*
|
1917 |
|
|
* Initialize all the ports on a panel.
|
1918 |
|
|
*/
|
1919 |
|
|
|
1920 |
|
|
static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
|
1921 |
|
|
{
|
1922 |
|
|
stlport_t *portp;
|
1923 |
|
|
int chipmask, i;
|
1924 |
|
|
|
1925 |
|
|
#if DEBUG
|
1926 |
|
|
printk("stl_initports(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
|
1927 |
|
|
#endif
|
1928 |
|
|
|
1929 |
|
|
chipmask = stl_panelinit(brdp, panelp);
|
1930 |
|
|
|
1931 |
|
|
/*
|
1932 |
|
|
* All UART's are initialized (if found!). Now go through and setup
|
1933 |
|
|
* each ports data structures.
|
1934 |
|
|
*/
|
1935 |
|
|
for (i = 0; (i < panelp->nrports); i++) {
|
1936 |
|
|
portp = (stlport_t *) stl_memalloc(sizeof(stlport_t));
|
1937 |
|
|
if (portp == (stlport_t *) NULL) {
|
1938 |
|
|
printk("STALLION: failed to allocate memory "
|
1939 |
|
|
"(size=%d)\n", sizeof(stlport_t));
|
1940 |
|
|
break;
|
1941 |
|
|
}
|
1942 |
|
|
memset(portp, 0, sizeof(stlport_t));
|
1943 |
|
|
|
1944 |
|
|
portp->magic = STL_PORTMAGIC;
|
1945 |
|
|
portp->portnr = i;
|
1946 |
|
|
portp->brdnr = panelp->brdnr;
|
1947 |
|
|
portp->panelnr = panelp->panelnr;
|
1948 |
|
|
portp->uartp = panelp->uartp;
|
1949 |
|
|
portp->clk = brdp->clk;
|
1950 |
|
|
portp->baud_base = STL_BAUDBASE;
|
1951 |
|
|
portp->close_delay = STL_CLOSEDELAY;
|
1952 |
|
|
portp->closing_wait = 30 * HZ;
|
1953 |
|
|
portp->normaltermios = stl_deftermios;
|
1954 |
|
|
portp->callouttermios = stl_deftermios;
|
1955 |
|
|
portp->tqueue.routine = stl_offintr;
|
1956 |
|
|
portp->tqueue.data = portp;
|
1957 |
|
|
portp->stats.brd = portp->brdnr;
|
1958 |
|
|
portp->stats.panel = portp->panelnr;
|
1959 |
|
|
portp->stats.port = portp->portnr;
|
1960 |
|
|
panelp->ports[i] = portp;
|
1961 |
|
|
stl_portinit(brdp, panelp, portp);
|
1962 |
|
|
}
|
1963 |
|
|
|
1964 |
|
|
return(0);
|
1965 |
|
|
}
|
1966 |
|
|
|
1967 |
|
|
/*****************************************************************************/
|
1968 |
|
|
|
1969 |
|
|
/*
|
1970 |
|
|
* Try to find and initialize an EasyIO board.
|
1971 |
|
|
*/
|
1972 |
|
|
|
1973 |
|
|
static inline int stl_initeio(stlbrd_t *brdp)
|
1974 |
|
|
{
|
1975 |
|
|
stlpanel_t *panelp;
|
1976 |
|
|
unsigned int status;
|
1977 |
|
|
char *name;
|
1978 |
|
|
int rc;
|
1979 |
|
|
|
1980 |
|
|
#if DEBUG
|
1981 |
|
|
printk("stl_initeio(brdp=%x)\n", (int) brdp);
|
1982 |
|
|
#endif
|
1983 |
|
|
|
1984 |
|
|
brdp->ioctrl = brdp->ioaddr1 + 1;
|
1985 |
|
|
brdp->iostatus = brdp->ioaddr1 + 2;
|
1986 |
|
|
|
1987 |
|
|
status = inb(brdp->iostatus);
|
1988 |
|
|
if ((status & EIO_IDBITMASK) == EIO_MK3)
|
1989 |
|
|
brdp->ioctrl++;
|
1990 |
|
|
|
1991 |
|
|
/*
|
1992 |
|
|
* Handle board specific stuff now. The real difference is PCI
|
1993 |
|
|
* or not PCI.
|
1994 |
|
|
*/
|
1995 |
|
|
if (brdp->brdtype == BRD_EASYIOPCI) {
|
1996 |
|
|
brdp->iosize1 = 0x80;
|
1997 |
|
|
brdp->iosize2 = 0x80;
|
1998 |
|
|
name = "serial(EIO-PCI)";
|
1999 |
|
|
outb(0x41, (brdp->ioaddr2 + 0x4c));
|
2000 |
|
|
} else {
|
2001 |
|
|
brdp->iosize1 = 8;
|
2002 |
|
|
name = "serial(EIO)";
|
2003 |
|
|
if ((brdp->irq < 0) || (brdp->irq > 15) ||
|
2004 |
|
|
(stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
|
2005 |
|
|
printk("STALLION: invalid irq=%d for brd=%d\n",
|
2006 |
|
|
brdp->irq, brdp->brdnr);
|
2007 |
|
|
return(-EINVAL);
|
2008 |
|
|
}
|
2009 |
|
|
outb((stl_vecmap[brdp->irq] | EIO_0WS |
|
2010 |
|
|
((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)),
|
2011 |
|
|
brdp->ioctrl);
|
2012 |
|
|
}
|
2013 |
|
|
|
2014 |
|
|
if (check_region(brdp->ioaddr1, brdp->iosize1)) {
|
2015 |
|
|
printk("STALLION: Warning, unit %d I/O address %x conflicts "
|
2016 |
|
|
"with another device\n", brdp->brdnr, brdp->ioaddr1);
|
2017 |
|
|
}
|
2018 |
|
|
if (brdp->iosize2 > 0) {
|
2019 |
|
|
if (check_region(brdp->ioaddr2, brdp->iosize2)) {
|
2020 |
|
|
printk("STALLION: Warning, unit %d I/O address %x "
|
2021 |
|
|
"conflicts with another device\n",
|
2022 |
|
|
brdp->brdnr, brdp->ioaddr2);
|
2023 |
|
|
}
|
2024 |
|
|
}
|
2025 |
|
|
|
2026 |
|
|
/*
|
2027 |
|
|
* Everything looks OK, so lets go ahead and probe for the hardware.
|
2028 |
|
|
*/
|
2029 |
|
|
brdp->clk = CD1400_CLK;
|
2030 |
|
|
brdp->isr = stl_eiointr;
|
2031 |
|
|
|
2032 |
|
|
switch (status & EIO_IDBITMASK) {
|
2033 |
|
|
case EIO_8PORTM:
|
2034 |
|
|
brdp->clk = CD1400_CLK8M;
|
2035 |
|
|
/* fall thru */
|
2036 |
|
|
case EIO_8PORTRS:
|
2037 |
|
|
case EIO_8PORTDI:
|
2038 |
|
|
brdp->nrports = 8;
|
2039 |
|
|
break;
|
2040 |
|
|
case EIO_4PORTRS:
|
2041 |
|
|
brdp->nrports = 4;
|
2042 |
|
|
break;
|
2043 |
|
|
case EIO_MK3:
|
2044 |
|
|
switch (status & EIO_BRDMASK) {
|
2045 |
|
|
case ID_BRD4:
|
2046 |
|
|
brdp->nrports = 4;
|
2047 |
|
|
break;
|
2048 |
|
|
case ID_BRD8:
|
2049 |
|
|
brdp->nrports = 8;
|
2050 |
|
|
break;
|
2051 |
|
|
case ID_BRD16:
|
2052 |
|
|
brdp->nrports = 16;
|
2053 |
|
|
break;
|
2054 |
|
|
default:
|
2055 |
|
|
return(-ENODEV);
|
2056 |
|
|
}
|
2057 |
|
|
break;
|
2058 |
|
|
default:
|
2059 |
|
|
return(-ENODEV);
|
2060 |
|
|
}
|
2061 |
|
|
|
2062 |
|
|
/*
|
2063 |
|
|
* We have verfied that the board is actually present, so now we
|
2064 |
|
|
* can complete the setup.
|
2065 |
|
|
*/
|
2066 |
|
|
request_region(brdp->ioaddr1, brdp->iosize1, name);
|
2067 |
|
|
if (brdp->iosize2 > 0)
|
2068 |
|
|
request_region(brdp->ioaddr2, brdp->iosize2, name);
|
2069 |
|
|
|
2070 |
|
|
panelp = (stlpanel_t *) stl_memalloc(sizeof(stlpanel_t));
|
2071 |
|
|
if (panelp == (stlpanel_t *) NULL) {
|
2072 |
|
|
printk("STALLION: failed to allocate memory (size=%d)\n",
|
2073 |
|
|
sizeof(stlpanel_t));
|
2074 |
|
|
return(-ENOMEM);
|
2075 |
|
|
}
|
2076 |
|
|
memset(panelp, 0, sizeof(stlpanel_t));
|
2077 |
|
|
|
2078 |
|
|
panelp->magic = STL_PANELMAGIC;
|
2079 |
|
|
panelp->brdnr = brdp->brdnr;
|
2080 |
|
|
panelp->panelnr = 0;
|
2081 |
|
|
panelp->nrports = brdp->nrports;
|
2082 |
|
|
panelp->iobase = brdp->ioaddr1;
|
2083 |
|
|
panelp->hwid = status;
|
2084 |
|
|
if ((status & EIO_IDBITMASK) == EIO_MK3) {
|
2085 |
|
|
panelp->uartp = (void *) &stl_sc26198uart;
|
2086 |
|
|
panelp->isr = stl_sc26198intr;
|
2087 |
|
|
} else {
|
2088 |
|
|
panelp->uartp = (void *) &stl_cd1400uart;
|
2089 |
|
|
panelp->isr = stl_cd1400eiointr;
|
2090 |
|
|
}
|
2091 |
|
|
|
2092 |
|
|
brdp->panels[0] = panelp;
|
2093 |
|
|
brdp->nrpanels = 1;
|
2094 |
|
|
brdp->state |= BRD_FOUND;
|
2095 |
|
|
brdp->hwid = status;
|
2096 |
|
|
rc = stl_mapirq(brdp->irq, name);
|
2097 |
|
|
return(rc);
|
2098 |
|
|
}
|
2099 |
|
|
|
2100 |
|
|
/*****************************************************************************/
|
2101 |
|
|
|
2102 |
|
|
/*
|
2103 |
|
|
* Try to find an ECH board and initialize it. This code is capable of
|
2104 |
|
|
* dealing with all types of ECH board.
|
2105 |
|
|
*/
|
2106 |
|
|
|
2107 |
|
|
static inline int stl_initech(stlbrd_t *brdp)
|
2108 |
|
|
{
|
2109 |
|
|
stlpanel_t *panelp;
|
2110 |
|
|
unsigned int status, nxtid, ioaddr, conflict;
|
2111 |
|
|
int panelnr, banknr, i;
|
2112 |
|
|
char *name;
|
2113 |
|
|
|
2114 |
|
|
#if DEBUG
|
2115 |
|
|
printk("stl_initech(brdp=%x)\n", (int) brdp);
|
2116 |
|
|
#endif
|
2117 |
|
|
|
2118 |
|
|
status = 0;
|
2119 |
|
|
conflict = 0;
|
2120 |
|
|
|
2121 |
|
|
/*
|
2122 |
|
|
* Set up the initial board register contents for boards. This varies a
|
2123 |
|
|
* bit between the different board types. So we need to handle each
|
2124 |
|
|
* separately. Also do a check that the supplied IRQ is good.
|
2125 |
|
|
*/
|
2126 |
|
|
switch (brdp->brdtype) {
|
2127 |
|
|
|
2128 |
|
|
case BRD_ECH:
|
2129 |
|
|
brdp->isr = stl_echatintr;
|
2130 |
|
|
brdp->ioctrl = brdp->ioaddr1 + 1;
|
2131 |
|
|
brdp->iostatus = brdp->ioaddr1 + 1;
|
2132 |
|
|
status = inb(brdp->iostatus);
|
2133 |
|
|
if ((status & ECH_IDBITMASK) != ECH_ID)
|
2134 |
|
|
return(-ENODEV);
|
2135 |
|
|
if ((brdp->irq < 0) || (brdp->irq > 15) ||
|
2136 |
|
|
(stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
|
2137 |
|
|
printk("STALLION: invalid irq=%d for brd=%d\n",
|
2138 |
|
|
brdp->irq, brdp->brdnr);
|
2139 |
|
|
return(-EINVAL);
|
2140 |
|
|
}
|
2141 |
|
|
status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
|
2142 |
|
|
status |= (stl_vecmap[brdp->irq] << 1);
|
2143 |
|
|
outb((status | ECH_BRDRESET), brdp->ioaddr1);
|
2144 |
|
|
brdp->ioctrlval = ECH_INTENABLE |
|
2145 |
|
|
((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
|
2146 |
|
|
for (i = 0; (i < 10); i++)
|
2147 |
|
|
outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
|
2148 |
|
|
brdp->iosize1 = 2;
|
2149 |
|
|
brdp->iosize2 = 32;
|
2150 |
|
|
name = "serial(EC8/32)";
|
2151 |
|
|
outb(status, brdp->ioaddr1);
|
2152 |
|
|
break;
|
2153 |
|
|
|
2154 |
|
|
case BRD_ECHMC:
|
2155 |
|
|
brdp->isr = stl_echmcaintr;
|
2156 |
|
|
brdp->ioctrl = brdp->ioaddr1 + 0x20;
|
2157 |
|
|
brdp->iostatus = brdp->ioctrl;
|
2158 |
|
|
status = inb(brdp->iostatus);
|
2159 |
|
|
if ((status & ECH_IDBITMASK) != ECH_ID)
|
2160 |
|
|
return(-ENODEV);
|
2161 |
|
|
if ((brdp->irq < 0) || (brdp->irq > 15) ||
|
2162 |
|
|
(stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
|
2163 |
|
|
printk("STALLION: invalid irq=%d for brd=%d\n",
|
2164 |
|
|
brdp->irq, brdp->brdnr);
|
2165 |
|
|
return(-EINVAL);
|
2166 |
|
|
}
|
2167 |
|
|
outb(ECHMC_BRDRESET, brdp->ioctrl);
|
2168 |
|
|
outb(ECHMC_INTENABLE, brdp->ioctrl);
|
2169 |
|
|
brdp->iosize1 = 64;
|
2170 |
|
|
name = "serial(EC8/32-MC)";
|
2171 |
|
|
break;
|
2172 |
|
|
|
2173 |
|
|
case BRD_ECHPCI:
|
2174 |
|
|
brdp->isr = stl_echpciintr;
|
2175 |
|
|
brdp->ioctrl = brdp->ioaddr1 + 2;
|
2176 |
|
|
brdp->iosize1 = 4;
|
2177 |
|
|
brdp->iosize2 = 8;
|
2178 |
|
|
name = "serial(EC8/32-PCI)";
|
2179 |
|
|
break;
|
2180 |
|
|
|
2181 |
|
|
case BRD_ECH64PCI:
|
2182 |
|
|
brdp->isr = stl_echpci64intr;
|
2183 |
|
|
brdp->ioctrl = brdp->ioaddr2 + 0x40;
|
2184 |
|
|
outb(0x43, (brdp->ioaddr1 + 0x4c));
|
2185 |
|
|
brdp->iosize1 = 0x80;
|
2186 |
|
|
brdp->iosize2 = 0x80;
|
2187 |
|
|
name = "serial(EC8/64-PCI)";
|
2188 |
|
|
break;
|
2189 |
|
|
|
2190 |
|
|
default:
|
2191 |
|
|
printk("STALLION: unknown board type=%d\n", brdp->brdtype);
|
2192 |
|
|
return(-EINVAL);
|
2193 |
|
|
break;
|
2194 |
|
|
}
|
2195 |
|
|
|
2196 |
|
|
/*
|
2197 |
|
|
* Check boards for possible IO address conflicts. We won't actually
|
2198 |
|
|
* do anything about it here, just issue a warning...
|
2199 |
|
|
*/
|
2200 |
|
|
conflict = check_region(brdp->ioaddr1, brdp->iosize1) ?
|
2201 |
|
|
brdp->ioaddr1 : 0;
|
2202 |
|
|
if ((conflict == 0) && (brdp->iosize2 > 0))
|
2203 |
|
|
conflict = check_region(brdp->ioaddr2, brdp->iosize2) ?
|
2204 |
|
|
brdp->ioaddr2 : 0;
|
2205 |
|
|
if (conflict) {
|
2206 |
|
|
printk("STALLION: Warning, unit %d I/O address %x conflicts "
|
2207 |
|
|
"with another device\n", brdp->brdnr, conflict);
|
2208 |
|
|
}
|
2209 |
|
|
|
2210 |
|
|
request_region(brdp->ioaddr1, brdp->iosize1, name);
|
2211 |
|
|
if (brdp->iosize2 > 0)
|
2212 |
|
|
request_region(brdp->ioaddr2, brdp->iosize2, name);
|
2213 |
|
|
|
2214 |
|
|
/*
|
2215 |
|
|
* Scan through the secondary io address space looking for panels.
|
2216 |
|
|
* As we find'em allocate and initialize panel structures for each.
|
2217 |
|
|
*/
|
2218 |
|
|
brdp->clk = CD1400_CLK;
|
2219 |
|
|
brdp->hwid = status;
|
2220 |
|
|
|
2221 |
|
|
ioaddr = brdp->ioaddr2;
|
2222 |
|
|
banknr = 0;
|
2223 |
|
|
panelnr = 0;
|
2224 |
|
|
nxtid = 0;
|
2225 |
|
|
|
2226 |
|
|
for (i = 0; (i < STL_MAXPANELS); i++) {
|
2227 |
|
|
if (brdp->brdtype == BRD_ECHPCI) {
|
2228 |
|
|
outb(nxtid, brdp->ioctrl);
|
2229 |
|
|
ioaddr = brdp->ioaddr2;
|
2230 |
|
|
}
|
2231 |
|
|
status = inb(ioaddr + ECH_PNLSTATUS);
|
2232 |
|
|
if ((status & ECH_PNLIDMASK) != nxtid)
|
2233 |
|
|
break;
|
2234 |
|
|
panelp = (stlpanel_t *) stl_memalloc(sizeof(stlpanel_t));
|
2235 |
|
|
if (panelp == (stlpanel_t *) NULL) {
|
2236 |
|
|
printk("STALLION: failed to allocate memory "
|
2237 |
|
|
"(size=%d)\n", sizeof(stlpanel_t));
|
2238 |
|
|
break;
|
2239 |
|
|
}
|
2240 |
|
|
memset(panelp, 0, sizeof(stlpanel_t));
|
2241 |
|
|
panelp->magic = STL_PANELMAGIC;
|
2242 |
|
|
panelp->brdnr = brdp->brdnr;
|
2243 |
|
|
panelp->panelnr = panelnr;
|
2244 |
|
|
panelp->iobase = ioaddr;
|
2245 |
|
|
panelp->pagenr = nxtid;
|
2246 |
|
|
panelp->hwid = status;
|
2247 |
|
|
brdp->bnk2panel[banknr] = panelp;
|
2248 |
|
|
brdp->bnkpageaddr[banknr] = nxtid;
|
2249 |
|
|
brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
|
2250 |
|
|
|
2251 |
|
|
if (status & ECH_PNLXPID) {
|
2252 |
|
|
panelp->uartp = (void *) &stl_sc26198uart;
|
2253 |
|
|
panelp->isr = stl_sc26198intr;
|
2254 |
|
|
if (status & ECH_PNL16PORT) {
|
2255 |
|
|
panelp->nrports = 16;
|
2256 |
|
|
brdp->bnk2panel[banknr] = panelp;
|
2257 |
|
|
brdp->bnkpageaddr[banknr] = nxtid;
|
2258 |
|
|
brdp->bnkstataddr[banknr++] = ioaddr + 4 +
|
2259 |
|
|
ECH_PNLSTATUS;
|
2260 |
|
|
} else {
|
2261 |
|
|
panelp->nrports = 8;
|
2262 |
|
|
}
|
2263 |
|
|
} else {
|
2264 |
|
|
panelp->uartp = (void *) &stl_cd1400uart;
|
2265 |
|
|
panelp->isr = stl_cd1400echintr;
|
2266 |
|
|
if (status & ECH_PNL16PORT) {
|
2267 |
|
|
panelp->nrports = 16;
|
2268 |
|
|
panelp->ackmask = 0x80;
|
2269 |
|
|
if (brdp->brdtype != BRD_ECHPCI)
|
2270 |
|
|
ioaddr += EREG_BANKSIZE;
|
2271 |
|
|
brdp->bnk2panel[banknr] = panelp;
|
2272 |
|
|
brdp->bnkpageaddr[banknr] = ++nxtid;
|
2273 |
|
|
brdp->bnkstataddr[banknr++] = ioaddr +
|
2274 |
|
|
ECH_PNLSTATUS;
|
2275 |
|
|
} else {
|
2276 |
|
|
panelp->nrports = 8;
|
2277 |
|
|
panelp->ackmask = 0xc0;
|
2278 |
|
|
}
|
2279 |
|
|
}
|
2280 |
|
|
|
2281 |
|
|
nxtid++;
|
2282 |
|
|
ioaddr += EREG_BANKSIZE;
|
2283 |
|
|
brdp->nrports += panelp->nrports;
|
2284 |
|
|
brdp->panels[panelnr++] = panelp;
|
2285 |
|
|
if ((brdp->brdtype != BRD_ECHPCI) &&
|
2286 |
|
|
(ioaddr >= (brdp->ioaddr2 + brdp->iosize2)))
|
2287 |
|
|
break;
|
2288 |
|
|
}
|
2289 |
|
|
|
2290 |
|
|
brdp->nrpanels = panelnr;
|
2291 |
|
|
brdp->nrbnks = banknr;
|
2292 |
|
|
if (brdp->brdtype == BRD_ECH)
|
2293 |
|
|
outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
|
2294 |
|
|
|
2295 |
|
|
brdp->state |= BRD_FOUND;
|
2296 |
|
|
i = stl_mapirq(brdp->irq, name);
|
2297 |
|
|
return(i);
|
2298 |
|
|
}
|
2299 |
|
|
|
2300 |
|
|
/*****************************************************************************/
|
2301 |
|
|
|
2302 |
|
|
/*
|
2303 |
|
|
* Initialize and configure the specified board.
|
2304 |
|
|
* Scan through all the boards in the configuration and see what we
|
2305 |
|
|
* can find. Handle EIO and the ECH boards a little differently here
|
2306 |
|
|
* since the initial search and setup is very different.
|
2307 |
|
|
*/
|
2308 |
|
|
|
2309 |
|
|
static int stl_brdinit(stlbrd_t *brdp)
|
2310 |
|
|
{
|
2311 |
|
|
int i;
|
2312 |
|
|
|
2313 |
|
|
#if DEBUG
|
2314 |
|
|
printk("stl_brdinit(brdp=%x)\n", (int) brdp);
|
2315 |
|
|
#endif
|
2316 |
|
|
|
2317 |
|
|
switch (brdp->brdtype) {
|
2318 |
|
|
case BRD_EASYIO:
|
2319 |
|
|
case BRD_EASYIOPCI:
|
2320 |
|
|
stl_initeio(brdp);
|
2321 |
|
|
break;
|
2322 |
|
|
case BRD_ECH:
|
2323 |
|
|
case BRD_ECHMC:
|
2324 |
|
|
case BRD_ECHPCI:
|
2325 |
|
|
case BRD_ECH64PCI:
|
2326 |
|
|
stl_initech(brdp);
|
2327 |
|
|
break;
|
2328 |
|
|
default:
|
2329 |
|
|
printk("STALLION: unit=%d is unknown board type=%d\n",
|
2330 |
|
|
brdp->brdnr, brdp->brdtype);
|
2331 |
|
|
return(ENODEV);
|
2332 |
|
|
}
|
2333 |
|
|
|
2334 |
|
|
stl_brds[brdp->brdnr] = brdp;
|
2335 |
|
|
if ((brdp->state & BRD_FOUND) == 0) {
|
2336 |
|
|
printk("STALLION: %s board not found, unit=%d io=%x irq=%d\n",
|
2337 |
|
|
stl_brdnames[brdp->brdtype], brdp->brdnr,
|
2338 |
|
|
brdp->ioaddr1, brdp->irq);
|
2339 |
|
|
return(ENODEV);
|
2340 |
|
|
}
|
2341 |
|
|
|
2342 |
|
|
for (i = 0; (i < STL_MAXPANELS); i++)
|
2343 |
|
|
if (brdp->panels[i] != (stlpanel_t *) NULL)
|
2344 |
|
|
stl_initports(brdp, brdp->panels[i]);
|
2345 |
|
|
|
2346 |
|
|
printk("STALLION: %s found, unit=%d io=%x irq=%d "
|
2347 |
|
|
"nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype],
|
2348 |
|
|
brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels,
|
2349 |
|
|
brdp->nrports);
|
2350 |
|
|
return(0);
|
2351 |
|
|
}
|
2352 |
|
|
|
2353 |
|
|
/*****************************************************************************/
|
2354 |
|
|
|
2355 |
|
|
#ifdef CONFIG_PCI
|
2356 |
|
|
|
2357 |
|
|
/*
|
2358 |
|
|
* We have a Stallion board. Allocate a board structure and
|
2359 |
|
|
* initialize it. Read its IO and IRQ resources from PCI
|
2360 |
|
|
* configuration space.
|
2361 |
|
|
*/
|
2362 |
|
|
|
2363 |
|
|
static inline int stl_initpcibrd(int brdtype, unsigned char busnr, unsigned char devnr)
|
2364 |
|
|
{
|
2365 |
|
|
unsigned int bar[4];
|
2366 |
|
|
stlbrd_t *brdp;
|
2367 |
|
|
int i, rc;
|
2368 |
|
|
unsigned char irq;
|
2369 |
|
|
|
2370 |
|
|
#if DEBUG
|
2371 |
|
|
printk("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n",
|
2372 |
|
|
brdtype, busnr, devnr);
|
2373 |
|
|
#endif
|
2374 |
|
|
|
2375 |
|
|
brdp = (stlbrd_t *) stl_memalloc(sizeof(stlbrd_t));
|
2376 |
|
|
if (brdp == (stlbrd_t *) NULL) {
|
2377 |
|
|
printk("STALLION: failed to allocate memory (size=%d)\n",
|
2378 |
|
|
sizeof(stlbrd_t));
|
2379 |
|
|
return(-ENOMEM);
|
2380 |
|
|
}
|
2381 |
|
|
|
2382 |
|
|
memset(brdp, 0, sizeof(stlbrd_t));
|
2383 |
|
|
brdp->magic = STL_BOARDMAGIC;
|
2384 |
|
|
brdp->brdnr = stl_nrbrds++;
|
2385 |
|
|
brdp->brdtype = brdtype;
|
2386 |
|
|
|
2387 |
|
|
/*
|
2388 |
|
|
* Read in all the BAR registers from this board. Different Stallion
|
2389 |
|
|
* boards use these in different ways, so we just read in the whole
|
2390 |
|
|
* lot and then figure out what is what later.
|
2391 |
|
|
*/
|
2392 |
|
|
for (i = 0; (i < 4); i++) {
|
2393 |
|
|
rc = pcibios_read_config_dword(busnr, devnr,
|
2394 |
|
|
(PCI_BASE_ADDRESS_0 + (i * 0x4)), &bar[i]);
|
2395 |
|
|
if (rc) {
|
2396 |
|
|
printk("STALLION: failed to read BAR register %d "
|
2397 |
|
|
"from PCI board, errno=%x\n", i, rc);
|
2398 |
|
|
return(0);
|
2399 |
|
|
}
|
2400 |
|
|
}
|
2401 |
|
|
|
2402 |
|
|
rc = pcibios_read_config_byte(busnr, devnr, PCI_INTERRUPT_LINE, &irq);
|
2403 |
|
|
if (rc) {
|
2404 |
|
|
printk("STALLION: failed to read INTERRUPT register "
|
2405 |
|
|
"from PCI board, errno=%x\n", rc);
|
2406 |
|
|
return(0);
|
2407 |
|
|
}
|
2408 |
|
|
|
2409 |
|
|
#if DEBUG
|
2410 |
|
|
printk("%s(%d): BAR[]=%x,%x,%x,%x IRQ=%x\n", __FILE__, __LINE__,
|
2411 |
|
|
bar[0], bar[1], bar[2], bar[3], irq);
|
2412 |
|
|
#endif
|
2413 |
|
|
|
2414 |
|
|
/*
|
2415 |
|
|
* We have all resources from the board, so lets setup the actual
|
2416 |
|
|
* board structure now.
|
2417 |
|
|
*/
|
2418 |
|
|
switch (brdtype) {
|
2419 |
|
|
case BRD_ECHPCI:
|
2420 |
|
|
brdp->ioaddr2 = (bar[0] & PCI_BASE_ADDRESS_IO_MASK);
|
2421 |
|
|
brdp->ioaddr1 = (bar[1] & PCI_BASE_ADDRESS_IO_MASK);
|
2422 |
|
|
break;
|
2423 |
|
|
case BRD_ECH64PCI:
|
2424 |
|
|
brdp->ioaddr2 = (bar[2] & PCI_BASE_ADDRESS_IO_MASK);
|
2425 |
|
|
brdp->ioaddr1 = (bar[1] & PCI_BASE_ADDRESS_IO_MASK);
|
2426 |
|
|
break;
|
2427 |
|
|
case BRD_EASYIOPCI:
|
2428 |
|
|
brdp->ioaddr1 = (bar[2] & PCI_BASE_ADDRESS_IO_MASK);
|
2429 |
|
|
brdp->ioaddr2 = (bar[1] & PCI_BASE_ADDRESS_IO_MASK);
|
2430 |
|
|
break;
|
2431 |
|
|
default:
|
2432 |
|
|
printk("STALLION: unknown PCI board type=%d\n", brdtype);
|
2433 |
|
|
break;
|
2434 |
|
|
}
|
2435 |
|
|
|
2436 |
|
|
brdp->irq = irq;
|
2437 |
|
|
stl_brdinit(brdp);
|
2438 |
|
|
|
2439 |
|
|
return(0);
|
2440 |
|
|
}
|
2441 |
|
|
|
2442 |
|
|
|
2443 |
|
|
/*****************************************************************************/
|
2444 |
|
|
|
2445 |
|
|
/*
|
2446 |
|
|
* Find all Stallion PCI boards that might be installed. Initialize each
|
2447 |
|
|
* one as it is found.
|
2448 |
|
|
*/
|
2449 |
|
|
|
2450 |
|
|
|
2451 |
|
|
static inline int stl_findpcibrds()
|
2452 |
|
|
{
|
2453 |
|
|
unsigned char busnr, devnr;
|
2454 |
|
|
unsigned short class;
|
2455 |
|
|
int i, rc, brdtypnr;
|
2456 |
|
|
|
2457 |
|
|
#if DEBUG
|
2458 |
|
|
printk("stl_findpcibrds()\n");
|
2459 |
|
|
#endif
|
2460 |
|
|
|
2461 |
|
|
if (! pcibios_present())
|
2462 |
|
|
return(0);
|
2463 |
|
|
|
2464 |
|
|
for (i = 0; (i < stl_nrpcibrds); i++) {
|
2465 |
|
|
for (brdtypnr = 0; ; brdtypnr++) {
|
2466 |
|
|
|
2467 |
|
|
rc = pcibios_find_device(stl_pcibrds[i].vendid,
|
2468 |
|
|
stl_pcibrds[i].devid, brdtypnr, &busnr, &devnr);
|
2469 |
|
|
if (rc)
|
2470 |
|
|
break;
|
2471 |
|
|
|
2472 |
|
|
/*
|
2473 |
|
|
* Check that we can handle more boards...
|
2474 |
|
|
*/
|
2475 |
|
|
if (stl_nrbrds >= STL_MAXBRDS) {
|
2476 |
|
|
printk("STALLION: too many boards found, "
|
2477 |
|
|
"maximum supported %d\n", STL_MAXBRDS);
|
2478 |
|
|
i = stl_nrpcibrds;
|
2479 |
|
|
break;
|
2480 |
|
|
}
|
2481 |
|
|
|
2482 |
|
|
/*
|
2483 |
|
|
* Found a device on the PCI bus that has our vendor and
|
2484 |
|
|
* device ID. Need to check now that it is really us.
|
2485 |
|
|
*/
|
2486 |
|
|
rc = pcibios_read_config_word(busnr, devnr,
|
2487 |
|
|
PCI_CLASS_DEVICE, &class);
|
2488 |
|
|
if (rc) {
|
2489 |
|
|
printk("STALLION: failed to read class type "
|
2490 |
|
|
"from PCI board, errno=%x\n", rc);
|
2491 |
|
|
continue;
|
2492 |
|
|
}
|
2493 |
|
|
if (class == PCI_CLASS_STORAGE_IDE)
|
2494 |
|
|
continue;
|
2495 |
|
|
|
2496 |
|
|
rc = stl_initpcibrd(stl_pcibrds[i].brdtype, busnr,
|
2497 |
|
|
devnr);
|
2498 |
|
|
if (rc)
|
2499 |
|
|
return(rc);
|
2500 |
|
|
}
|
2501 |
|
|
}
|
2502 |
|
|
|
2503 |
|
|
return(0);
|
2504 |
|
|
}
|
2505 |
|
|
|
2506 |
|
|
#endif
|
2507 |
|
|
|
2508 |
|
|
/*****************************************************************************/
|
2509 |
|
|
|
2510 |
|
|
/*
|
2511 |
|
|
* Scan through all the boards in the configuration and see what we
|
2512 |
|
|
* can find. Handle EIO and the ECH boards a little differently here
|
2513 |
|
|
* since the initial search and setup is too different.
|
2514 |
|
|
*/
|
2515 |
|
|
|
2516 |
|
|
static inline int stl_initbrds()
|
2517 |
|
|
{
|
2518 |
|
|
stlbrd_t *brdp;
|
2519 |
|
|
stlconf_t *confp;
|
2520 |
|
|
int i;
|
2521 |
|
|
|
2522 |
|
|
#if DEBUG
|
2523 |
|
|
printk("stl_initbrds()\n");
|
2524 |
|
|
#endif
|
2525 |
|
|
|
2526 |
|
|
if (stl_nrbrds > STL_MAXBRDS) {
|
2527 |
|
|
printk("STALLION: too many boards in configuration table, "
|
2528 |
|
|
"truncating to %d\n", STL_MAXBRDS);
|
2529 |
|
|
stl_nrbrds = STL_MAXBRDS;
|
2530 |
|
|
}
|
2531 |
|
|
|
2532 |
|
|
/*
|
2533 |
|
|
* Firstly scan the list of static boards configured. Allocate
|
2534 |
|
|
* resources and initialize the boards as found.
|
2535 |
|
|
*/
|
2536 |
|
|
for (i = 0; (i < stl_nrbrds); i++) {
|
2537 |
|
|
confp = &stl_brdconf[i];
|
2538 |
|
|
brdp = (stlbrd_t *) stl_memalloc(sizeof(stlbrd_t));
|
2539 |
|
|
if (brdp == (stlbrd_t *) NULL) {
|
2540 |
|
|
printk("STALLION: failed to allocate memory "
|
2541 |
|
|
"(size=%d)\n", sizeof(stlbrd_t));
|
2542 |
|
|
return(-ENOMEM);
|
2543 |
|
|
}
|
2544 |
|
|
memset(brdp, 0, sizeof(stlbrd_t));
|
2545 |
|
|
|
2546 |
|
|
brdp->magic = STL_BOARDMAGIC;
|
2547 |
|
|
brdp->brdnr = i;
|
2548 |
|
|
brdp->brdtype = confp->brdtype;
|
2549 |
|
|
brdp->ioaddr1 = confp->ioaddr1;
|
2550 |
|
|
brdp->ioaddr2 = confp->ioaddr2;
|
2551 |
|
|
brdp->irq = confp->irq;
|
2552 |
|
|
brdp->irqtype = confp->irqtype;
|
2553 |
|
|
stl_brdinit(brdp);
|
2554 |
|
|
}
|
2555 |
|
|
|
2556 |
|
|
#ifdef CONFIG_PCI
|
2557 |
|
|
/*
|
2558 |
|
|
* If the PCI BIOS support is compiled in then let's go looking for
|
2559 |
|
|
* ECH-PCI boards.
|
2560 |
|
|
*/
|
2561 |
|
|
stl_findpcibrds();
|
2562 |
|
|
#endif
|
2563 |
|
|
|
2564 |
|
|
return(0);
|
2565 |
|
|
}
|
2566 |
|
|
|
2567 |
|
|
/*****************************************************************************/
|
2568 |
|
|
|
2569 |
|
|
/*
|
2570 |
|
|
* Return the board stats structure to user app.
|
2571 |
|
|
*/
|
2572 |
|
|
|
2573 |
|
|
static int stl_getbrdstats(combrd_t *bp)
|
2574 |
|
|
{
|
2575 |
|
|
stlbrd_t *brdp;
|
2576 |
|
|
stlpanel_t *panelp;
|
2577 |
|
|
int i;
|
2578 |
|
|
|
2579 |
|
|
memcpy_fromfs(&stl_brdstats, bp, sizeof(combrd_t));
|
2580 |
|
|
if (stl_brdstats.brd >= STL_MAXBRDS)
|
2581 |
|
|
return(-ENODEV);
|
2582 |
|
|
brdp = stl_brds[stl_brdstats.brd];
|
2583 |
|
|
if (brdp == (stlbrd_t *) NULL)
|
2584 |
|
|
return(-ENODEV);
|
2585 |
|
|
|
2586 |
|
|
memset(&stl_brdstats, 0, sizeof(combrd_t));
|
2587 |
|
|
stl_brdstats.brd = brdp->brdnr;
|
2588 |
|
|
stl_brdstats.type = brdp->brdtype;
|
2589 |
|
|
stl_brdstats.hwid = brdp->hwid;
|
2590 |
|
|
stl_brdstats.state = brdp->state;
|
2591 |
|
|
stl_brdstats.ioaddr = brdp->ioaddr1;
|
2592 |
|
|
stl_brdstats.ioaddr2 = brdp->ioaddr2;
|
2593 |
|
|
stl_brdstats.irq = brdp->irq;
|
2594 |
|
|
stl_brdstats.nrpanels = brdp->nrpanels;
|
2595 |
|
|
stl_brdstats.nrports = brdp->nrports;
|
2596 |
|
|
for (i = 0; (i < brdp->nrpanels); i++) {
|
2597 |
|
|
panelp = brdp->panels[i];
|
2598 |
|
|
stl_brdstats.panels[i].panel = i;
|
2599 |
|
|
stl_brdstats.panels[i].hwid = panelp->hwid;
|
2600 |
|
|
stl_brdstats.panels[i].nrports = panelp->nrports;
|
2601 |
|
|
}
|
2602 |
|
|
|
2603 |
|
|
memcpy_tofs(bp, &stl_brdstats, sizeof(combrd_t));
|
2604 |
|
|
return(0);
|
2605 |
|
|
}
|
2606 |
|
|
|
2607 |
|
|
/*****************************************************************************/
|
2608 |
|
|
|
2609 |
|
|
/*
|
2610 |
|
|
* Resolve the referenced port number into a port struct pointer.
|
2611 |
|
|
*/
|
2612 |
|
|
|
2613 |
|
|
static stlport_t *stl_getport(int brdnr, int panelnr, int portnr)
|
2614 |
|
|
{
|
2615 |
|
|
stlbrd_t *brdp;
|
2616 |
|
|
stlpanel_t *panelp;
|
2617 |
|
|
|
2618 |
|
|
if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
|
2619 |
|
|
return((stlport_t *) NULL);
|
2620 |
|
|
brdp = stl_brds[brdnr];
|
2621 |
|
|
if (brdp == (stlbrd_t *) NULL)
|
2622 |
|
|
return((stlport_t *) NULL);
|
2623 |
|
|
if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
|
2624 |
|
|
return((stlport_t *) NULL);
|
2625 |
|
|
panelp = brdp->panels[panelnr];
|
2626 |
|
|
if (panelp == (stlpanel_t *) NULL)
|
2627 |
|
|
return((stlport_t *) NULL);
|
2628 |
|
|
if ((portnr < 0) || (portnr >= panelp->nrports))
|
2629 |
|
|
return((stlport_t *) NULL);
|
2630 |
|
|
return(panelp->ports[portnr]);
|
2631 |
|
|
}
|
2632 |
|
|
|
2633 |
|
|
/*****************************************************************************/
|
2634 |
|
|
|
2635 |
|
|
/*
|
2636 |
|
|
* Return the port stats structure to user app. A NULL port struct
|
2637 |
|
|
* pointer passed in means that we need to find out from the app
|
2638 |
|
|
* what port to get stats for (used through board control device).
|
2639 |
|
|
*/
|
2640 |
|
|
|
2641 |
|
|
static int stl_getportstats(stlport_t *portp, comstats_t *cp)
|
2642 |
|
|
{
|
2643 |
|
|
unsigned char *head, *tail;
|
2644 |
|
|
unsigned long flags;
|
2645 |
|
|
|
2646 |
|
|
if (portp == (stlport_t *) NULL) {
|
2647 |
|
|
memcpy_fromfs(&stl_comstats, cp, sizeof(comstats_t));
|
2648 |
|
|
portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
|
2649 |
|
|
stl_comstats.port);
|
2650 |
|
|
if (portp == (stlport_t *) NULL)
|
2651 |
|
|
return(-ENODEV);
|
2652 |
|
|
}
|
2653 |
|
|
|
2654 |
|
|
portp->stats.state = portp->istate;
|
2655 |
|
|
portp->stats.flags = portp->flags;
|
2656 |
|
|
portp->stats.hwid = portp->hwid;
|
2657 |
|
|
|
2658 |
|
|
portp->stats.ttystate = 0;
|
2659 |
|
|
portp->stats.cflags = 0;
|
2660 |
|
|
portp->stats.iflags = 0;
|
2661 |
|
|
portp->stats.oflags = 0;
|
2662 |
|
|
portp->stats.lflags = 0;
|
2663 |
|
|
portp->stats.rxbuffered = 0;
|
2664 |
|
|
|
2665 |
|
|
save_flags(flags);
|
2666 |
|
|
cli();
|
2667 |
|
|
if (portp->tty != (struct tty_struct *) NULL) {
|
2668 |
|
|
if (portp->tty->driver_data == portp) {
|
2669 |
|
|
portp->stats.ttystate = portp->tty->flags;
|
2670 |
|
|
portp->stats.rxbuffered = portp->tty->flip.count;
|
2671 |
|
|
if (portp->tty->termios != (struct termios *) NULL) {
|
2672 |
|
|
portp->stats.cflags = portp->tty->termios->c_cflag;
|
2673 |
|
|
portp->stats.iflags = portp->tty->termios->c_iflag;
|
2674 |
|
|
portp->stats.oflags = portp->tty->termios->c_oflag;
|
2675 |
|
|
portp->stats.lflags = portp->tty->termios->c_lflag;
|
2676 |
|
|
}
|
2677 |
|
|
}
|
2678 |
|
|
}
|
2679 |
|
|
restore_flags(flags);
|
2680 |
|
|
|
2681 |
|
|
head = portp->tx.head;
|
2682 |
|
|
tail = portp->tx.tail;
|
2683 |
|
|
portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
|
2684 |
|
|
(STL_TXBUFSIZE - (tail - head)));
|
2685 |
|
|
|
2686 |
|
|
portp->stats.signals = (unsigned long) stl_getsignals(portp);
|
2687 |
|
|
|
2688 |
|
|
memcpy_tofs(cp, &portp->stats, sizeof(comstats_t));
|
2689 |
|
|
return(0);
|
2690 |
|
|
}
|
2691 |
|
|
|
2692 |
|
|
/*****************************************************************************/
|
2693 |
|
|
|
2694 |
|
|
/*
|
2695 |
|
|
* Clear the port stats structure. We also return it zeroed out...
|
2696 |
|
|
*/
|
2697 |
|
|
|
2698 |
|
|
static int stl_clrportstats(stlport_t *portp, comstats_t *cp)
|
2699 |
|
|
{
|
2700 |
|
|
if (portp == (stlport_t *) NULL) {
|
2701 |
|
|
memcpy_fromfs(&stl_comstats, cp, sizeof(comstats_t));
|
2702 |
|
|
portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
|
2703 |
|
|
stl_comstats.port);
|
2704 |
|
|
if (portp == (stlport_t *) NULL)
|
2705 |
|
|
return(-ENODEV);
|
2706 |
|
|
}
|
2707 |
|
|
|
2708 |
|
|
memset(&portp->stats, 0, sizeof(comstats_t));
|
2709 |
|
|
portp->stats.brd = portp->brdnr;
|
2710 |
|
|
portp->stats.panel = portp->panelnr;
|
2711 |
|
|
portp->stats.port = portp->portnr;
|
2712 |
|
|
memcpy_tofs(cp, &portp->stats, sizeof(comstats_t));
|
2713 |
|
|
return(0);
|
2714 |
|
|
}
|
2715 |
|
|
|
2716 |
|
|
/*****************************************************************************/
|
2717 |
|
|
|
2718 |
|
|
/*
|
2719 |
|
|
* Return the entire driver ports structure to a user app.
|
2720 |
|
|
*/
|
2721 |
|
|
|
2722 |
|
|
static int stl_getportstruct(unsigned long arg)
|
2723 |
|
|
{
|
2724 |
|
|
stlport_t *portp;
|
2725 |
|
|
|
2726 |
|
|
memcpy_fromfs(&stl_dummyport, (void *) arg, sizeof(stlport_t));
|
2727 |
|
|
portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
|
2728 |
|
|
stl_dummyport.portnr);
|
2729 |
|
|
if (portp == (stlport_t *) NULL)
|
2730 |
|
|
return(-ENODEV);
|
2731 |
|
|
memcpy_tofs((void *) arg, portp, sizeof(stlport_t));
|
2732 |
|
|
return(0);
|
2733 |
|
|
}
|
2734 |
|
|
|
2735 |
|
|
/*****************************************************************************/
|
2736 |
|
|
|
2737 |
|
|
/*
|
2738 |
|
|
* Return the entire driver board structure to a user app.
|
2739 |
|
|
*/
|
2740 |
|
|
|
2741 |
|
|
static int stl_getbrdstruct(unsigned long arg)
|
2742 |
|
|
{
|
2743 |
|
|
stlbrd_t *brdp;
|
2744 |
|
|
|
2745 |
|
|
memcpy_fromfs(&stl_dummybrd, (void *) arg, sizeof(stlbrd_t));
|
2746 |
|
|
if ((stl_dummybrd.brdnr < 0) || (stl_dummybrd.brdnr >= STL_MAXBRDS))
|
2747 |
|
|
return(-ENODEV);
|
2748 |
|
|
brdp = stl_brds[stl_dummybrd.brdnr];
|
2749 |
|
|
if (brdp == (stlbrd_t *) NULL)
|
2750 |
|
|
return(-ENODEV);
|
2751 |
|
|
memcpy_tofs((void *) arg, brdp, sizeof(stlbrd_t));
|
2752 |
|
|
return(0);
|
2753 |
|
|
}
|
2754 |
|
|
|
2755 |
|
|
/*****************************************************************************/
|
2756 |
|
|
|
2757 |
|
|
/*
|
2758 |
|
|
* Memory device open code. Need to keep track of opens and close
|
2759 |
|
|
* for module handling.
|
2760 |
|
|
*/
|
2761 |
|
|
|
2762 |
|
|
static int stl_memopen(struct inode *ip, struct file *fp)
|
2763 |
|
|
{
|
2764 |
|
|
MOD_INC_USE_COUNT;
|
2765 |
|
|
return(0);
|
2766 |
|
|
}
|
2767 |
|
|
|
2768 |
|
|
/*****************************************************************************/
|
2769 |
|
|
|
2770 |
|
|
static void stl_memclose(struct inode *ip, struct file *fp)
|
2771 |
|
|
{
|
2772 |
|
|
MOD_DEC_USE_COUNT;
|
2773 |
|
|
}
|
2774 |
|
|
|
2775 |
|
|
/*****************************************************************************/
|
2776 |
|
|
|
2777 |
|
|
/*
|
2778 |
|
|
* The "staliomem" device is also required to do some special operations
|
2779 |
|
|
* on the board and/or ports. In this driver it is mostly used for stats
|
2780 |
|
|
* collection.
|
2781 |
|
|
*/
|
2782 |
|
|
|
2783 |
|
|
static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
|
2784 |
|
|
{
|
2785 |
|
|
int brdnr, rc;
|
2786 |
|
|
|
2787 |
|
|
#if DEBUG
|
2788 |
|
|
printk("stl_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n", (int) ip,
|
2789 |
|
|
(int) fp, cmd, (int) arg);
|
2790 |
|
|
#endif
|
2791 |
|
|
|
2792 |
|
|
brdnr = MINOR(ip->i_rdev);
|
2793 |
|
|
if (brdnr >= STL_MAXBRDS)
|
2794 |
|
|
return(-ENODEV);
|
2795 |
|
|
rc = 0;
|
2796 |
|
|
|
2797 |
|
|
switch (cmd) {
|
2798 |
|
|
case COM_GETPORTSTATS:
|
2799 |
|
|
if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
|
2800 |
|
|
sizeof(comstats_t))) == 0)
|
2801 |
|
|
rc = stl_getportstats((stlport_t *) NULL,
|
2802 |
|
|
(comstats_t *) arg);
|
2803 |
|
|
break;
|
2804 |
|
|
case COM_CLRPORTSTATS:
|
2805 |
|
|
if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
|
2806 |
|
|
sizeof(comstats_t))) == 0)
|
2807 |
|
|
rc = stl_clrportstats((stlport_t *) NULL,
|
2808 |
|
|
(comstats_t *) arg);
|
2809 |
|
|
break;
|
2810 |
|
|
case COM_GETBRDSTATS:
|
2811 |
|
|
if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
|
2812 |
|
|
sizeof(combrd_t))) == 0)
|
2813 |
|
|
rc = stl_getbrdstats((combrd_t *) arg);
|
2814 |
|
|
break;
|
2815 |
|
|
case COM_READPORT:
|
2816 |
|
|
if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
|
2817 |
|
|
sizeof(stlport_t))) == 0)
|
2818 |
|
|
rc = stl_getportstruct(arg);
|
2819 |
|
|
break;
|
2820 |
|
|
case COM_READBOARD:
|
2821 |
|
|
if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
|
2822 |
|
|
sizeof(stlbrd_t))) == 0)
|
2823 |
|
|
rc = stl_getbrdstruct(arg);
|
2824 |
|
|
break;
|
2825 |
|
|
default:
|
2826 |
|
|
rc = -ENOIOCTLCMD;
|
2827 |
|
|
break;
|
2828 |
|
|
}
|
2829 |
|
|
|
2830 |
|
|
return(rc);
|
2831 |
|
|
}
|
2832 |
|
|
|
2833 |
|
|
/*****************************************************************************/
|
2834 |
|
|
|
2835 |
|
|
int stl_init(void)
|
2836 |
|
|
{
|
2837 |
|
|
printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
|
2838 |
|
|
|
2839 |
|
|
stl_initbrds();
|
2840 |
|
|
|
2841 |
|
|
/*
|
2842 |
|
|
* Allocate a temporary write buffer.
|
2843 |
|
|
*/
|
2844 |
|
|
stl_tmpwritebuf = (char *) stl_memalloc(STL_TXBUFSIZE);
|
2845 |
|
|
if (stl_tmpwritebuf == (char *) NULL)
|
2846 |
|
|
printk("STALLION: failed to allocate memory (size=%d)\n",
|
2847 |
|
|
STL_TXBUFSIZE);
|
2848 |
|
|
|
2849 |
|
|
/*
|
2850 |
|
|
* Set up a character driver for per board stuff. This is mainly used
|
2851 |
|
|
* to do stats ioctls on the ports.
|
2852 |
|
|
*/
|
2853 |
|
|
if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
|
2854 |
|
|
printk("STALLION: failed to register serial board device\n");
|
2855 |
|
|
|
2856 |
|
|
/*
|
2857 |
|
|
* Set up the tty driver structure and register us as a driver.
|
2858 |
|
|
* Also setup the callout tty device.
|
2859 |
|
|
*/
|
2860 |
|
|
memset(&stl_serial, 0, sizeof(struct tty_driver));
|
2861 |
|
|
stl_serial.magic = TTY_DRIVER_MAGIC;
|
2862 |
|
|
stl_serial.name = stl_serialname;
|
2863 |
|
|
stl_serial.major = STL_SERIALMAJOR;
|
2864 |
|
|
stl_serial.minor_start = 0;
|
2865 |
|
|
stl_serial.num = STL_MAXBRDS * STL_MAXPORTS;
|
2866 |
|
|
stl_serial.type = TTY_DRIVER_TYPE_SERIAL;
|
2867 |
|
|
stl_serial.subtype = STL_DRVTYPSERIAL;
|
2868 |
|
|
stl_serial.init_termios = stl_deftermios;
|
2869 |
|
|
stl_serial.flags = TTY_DRIVER_REAL_RAW;
|
2870 |
|
|
stl_serial.refcount = &stl_refcount;
|
2871 |
|
|
stl_serial.table = stl_ttys;
|
2872 |
|
|
stl_serial.termios = stl_termios;
|
2873 |
|
|
stl_serial.termios_locked = stl_termioslocked;
|
2874 |
|
|
|
2875 |
|
|
stl_serial.open = stl_open;
|
2876 |
|
|
stl_serial.close = stl_close;
|
2877 |
|
|
stl_serial.write = stl_write;
|
2878 |
|
|
stl_serial.put_char = stl_putchar;
|
2879 |
|
|
stl_serial.flush_chars = stl_flushchars;
|
2880 |
|
|
stl_serial.write_room = stl_writeroom;
|
2881 |
|
|
stl_serial.chars_in_buffer = stl_charsinbuffer;
|
2882 |
|
|
stl_serial.ioctl = stl_ioctl;
|
2883 |
|
|
stl_serial.set_termios = stl_settermios;
|
2884 |
|
|
stl_serial.throttle = stl_throttle;
|
2885 |
|
|
stl_serial.unthrottle = stl_unthrottle;
|
2886 |
|
|
stl_serial.stop = stl_stop;
|
2887 |
|
|
stl_serial.start = stl_start;
|
2888 |
|
|
stl_serial.hangup = stl_hangup;
|
2889 |
|
|
stl_serial.flush_buffer = stl_flushbuffer;
|
2890 |
|
|
|
2891 |
|
|
stl_callout = stl_serial;
|
2892 |
|
|
stl_callout.name = stl_calloutname;
|
2893 |
|
|
stl_callout.major = STL_CALLOUTMAJOR;
|
2894 |
|
|
stl_callout.subtype = STL_DRVTYPCALLOUT;
|
2895 |
|
|
|
2896 |
|
|
if (tty_register_driver(&stl_serial))
|
2897 |
|
|
printk("STALLION: failed to register serial driver\n");
|
2898 |
|
|
if (tty_register_driver(&stl_callout))
|
2899 |
|
|
printk("STALLION: failed to register callout driver\n");
|
2900 |
|
|
|
2901 |
|
|
return(0);
|
2902 |
|
|
}
|
2903 |
|
|
|
2904 |
|
|
/*****************************************************************************/
|
2905 |
|
|
/* CD1400 HARDWARE FUNCTIONS */
|
2906 |
|
|
/*****************************************************************************/
|
2907 |
|
|
|
2908 |
|
|
/*
|
2909 |
|
|
* These functions get/set/update the registers of the cd1400 UARTs.
|
2910 |
|
|
* Access to the cd1400 registers is via an address/data io port pair.
|
2911 |
|
|
* (Maybe should make this inline...)
|
2912 |
|
|
*/
|
2913 |
|
|
|
2914 |
|
|
static int stl_cd1400getreg(stlport_t *portp, int regnr)
|
2915 |
|
|
{
|
2916 |
|
|
outb((regnr + portp->uartaddr), portp->ioaddr);
|
2917 |
|
|
return(inb(portp->ioaddr + EREG_DATA));
|
2918 |
|
|
}
|
2919 |
|
|
|
2920 |
|
|
static void stl_cd1400setreg(stlport_t *portp, int regnr, int value)
|
2921 |
|
|
{
|
2922 |
|
|
outb((regnr + portp->uartaddr), portp->ioaddr);
|
2923 |
|
|
outb(value, portp->ioaddr + EREG_DATA);
|
2924 |
|
|
}
|
2925 |
|
|
|
2926 |
|
|
static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value)
|
2927 |
|
|
{
|
2928 |
|
|
outb((regnr + portp->uartaddr), portp->ioaddr);
|
2929 |
|
|
if (inb(portp->ioaddr + EREG_DATA) != value) {
|
2930 |
|
|
outb(value, portp->ioaddr + EREG_DATA);
|
2931 |
|
|
return(1);
|
2932 |
|
|
}
|
2933 |
|
|
return(0);
|
2934 |
|
|
}
|
2935 |
|
|
|
2936 |
|
|
/*****************************************************************************/
|
2937 |
|
|
|
2938 |
|
|
/*
|
2939 |
|
|
* Inbitialize the UARTs in a panel. We don't care what sort of board
|
2940 |
|
|
* these ports are on - since the port io registers are almost
|
2941 |
|
|
* identical when dealing with ports.
|
2942 |
|
|
*/
|
2943 |
|
|
|
2944 |
|
|
static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
|
2945 |
|
|
{
|
2946 |
|
|
unsigned int gfrcr;
|
2947 |
|
|
int chipmask, i, j;
|
2948 |
|
|
int nrchips, uartaddr, ioaddr;
|
2949 |
|
|
|
2950 |
|
|
#if DEBUG
|
2951 |
|
|
printk("stl_panelinit(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
|
2952 |
|
|
#endif
|
2953 |
|
|
|
2954 |
|
|
BRDENABLE(panelp->brdnr, panelp->pagenr);
|
2955 |
|
|
|
2956 |
|
|
/*
|
2957 |
|
|
* Check that each chip is present and started up OK.
|
2958 |
|
|
*/
|
2959 |
|
|
chipmask = 0;
|
2960 |
|
|
nrchips = panelp->nrports / CD1400_PORTS;
|
2961 |
|
|
for (i = 0; (i < nrchips); i++) {
|
2962 |
|
|
if (brdp->brdtype == BRD_ECHPCI) {
|
2963 |
|
|
outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
|
2964 |
|
|
ioaddr = panelp->iobase;
|
2965 |
|
|
} else {
|
2966 |
|
|
ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
|
2967 |
|
|
}
|
2968 |
|
|
uartaddr = (i & 0x01) ? 0x080 : 0;
|
2969 |
|
|
outb((GFRCR + uartaddr), ioaddr);
|
2970 |
|
|
outb(0, (ioaddr + EREG_DATA));
|
2971 |
|
|
outb((CCR + uartaddr), ioaddr);
|
2972 |
|
|
outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
|
2973 |
|
|
outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
|
2974 |
|
|
outb((GFRCR + uartaddr), ioaddr);
|
2975 |
|
|
for (j = 0; (j < CCR_MAXWAIT); j++) {
|
2976 |
|
|
if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
|
2977 |
|
|
break;
|
2978 |
|
|
}
|
2979 |
|
|
if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
|
2980 |
|
|
printk("STALLION: cd1400 not responding, "
|
2981 |
|
|
"brd=%d panel=%d chip=%d\n",
|
2982 |
|
|
panelp->brdnr, panelp->panelnr, i);
|
2983 |
|
|
continue;
|
2984 |
|
|
}
|
2985 |
|
|
chipmask |= (0x1 << i);
|
2986 |
|
|
outb((PPR + uartaddr), ioaddr);
|
2987 |
|
|
outb(PPR_SCALAR, (ioaddr + EREG_DATA));
|
2988 |
|
|
}
|
2989 |
|
|
|
2990 |
|
|
BRDDISABLE(panelp->brdnr);
|
2991 |
|
|
return(chipmask);
|
2992 |
|
|
}
|
2993 |
|
|
|
2994 |
|
|
/*****************************************************************************/
|
2995 |
|
|
|
2996 |
|
|
/*
|
2997 |
|
|
* Initialize hardware specific port registers.
|
2998 |
|
|
*/
|
2999 |
|
|
|
3000 |
|
|
static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
|
3001 |
|
|
{
|
3002 |
|
|
#if DEBUG
|
3003 |
|
|
printk("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
|
3004 |
|
|
(int) brdp, (int) panelp, (int) portp);
|
3005 |
|
|
#endif
|
3006 |
|
|
|
3007 |
|
|
if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
|
3008 |
|
|
(portp == (stlport_t *) NULL))
|
3009 |
|
|
return;
|
3010 |
|
|
|
3011 |
|
|
portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
|
3012 |
|
|
(portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
|
3013 |
|
|
portp->uartaddr = (portp->portnr & 0x04) << 5;
|
3014 |
|
|
portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
|
3015 |
|
|
|
3016 |
|
|
BRDENABLE(portp->brdnr, portp->pagenr);
|
3017 |
|
|
stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
|
3018 |
|
|
stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
|
3019 |
|
|
portp->hwid = stl_cd1400getreg(portp, GFRCR);
|
3020 |
|
|
BRDDISABLE(portp->brdnr);
|
3021 |
|
|
}
|
3022 |
|
|
|
3023 |
|
|
/*****************************************************************************/
|
3024 |
|
|
|
3025 |
|
|
/*
|
3026 |
|
|
* Wait for the command register to be ready. We will poll this,
|
3027 |
|
|
* since it won't usually take too long to be ready.
|
3028 |
|
|
*/
|
3029 |
|
|
|
3030 |
|
|
static void stl_cd1400ccrwait(stlport_t *portp)
|
3031 |
|
|
{
|
3032 |
|
|
int i;
|
3033 |
|
|
|
3034 |
|
|
for (i = 0; (i < CCR_MAXWAIT); i++) {
|
3035 |
|
|
if (stl_cd1400getreg(portp, CCR) == 0) {
|
3036 |
|
|
return;
|
3037 |
|
|
}
|
3038 |
|
|
}
|
3039 |
|
|
|
3040 |
|
|
printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
|
3041 |
|
|
portp->portnr, portp->panelnr, portp->brdnr);
|
3042 |
|
|
}
|
3043 |
|
|
|
3044 |
|
|
/*****************************************************************************/
|
3045 |
|
|
|
3046 |
|
|
/*
|
3047 |
|
|
* Set up the cd1400 registers for a port based on the termios port
|
3048 |
|
|
* settings.
|
3049 |
|
|
*/
|
3050 |
|
|
|
3051 |
|
|
static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
|
3052 |
|
|
{
|
3053 |
|
|
stlbrd_t *brdp;
|
3054 |
|
|
unsigned long flags;
|
3055 |
|
|
unsigned int clkdiv, baudrate;
|
3056 |
|
|
unsigned char cor1, cor2, cor3;
|
3057 |
|
|
unsigned char cor4, cor5, ccr;
|
3058 |
|
|
unsigned char srer, sreron, sreroff;
|
3059 |
|
|
unsigned char mcor1, mcor2, rtpr;
|
3060 |
|
|
unsigned char clk, div;
|
3061 |
|
|
|
3062 |
|
|
cor1 = 0;
|
3063 |
|
|
cor2 = 0;
|
3064 |
|
|
cor3 = 0;
|
3065 |
|
|
cor4 = 0;
|
3066 |
|
|
cor5 = 0;
|
3067 |
|
|
ccr = 0;
|
3068 |
|
|
rtpr = 0;
|
3069 |
|
|
clk = 0;
|
3070 |
|
|
div = 0;
|
3071 |
|
|
mcor1 = 0;
|
3072 |
|
|
mcor2 = 0;
|
3073 |
|
|
sreron = 0;
|
3074 |
|
|
sreroff = 0;
|
3075 |
|
|
|
3076 |
|
|
brdp = stl_brds[portp->brdnr];
|
3077 |
|
|
if (brdp == (stlbrd_t *) NULL)
|
3078 |
|
|
return;
|
3079 |
|
|
|
3080 |
|
|
/*
|
3081 |
|
|
* Set up the RX char ignore mask with those RX error types we
|
3082 |
|
|
* can ignore. We can get the cd1400 to help us out a little here,
|
3083 |
|
|
* it will ignore parity errors and breaks for us.
|
3084 |
|
|
*/
|
3085 |
|
|
portp->rxignoremsk = 0;
|
3086 |
|
|
if (tiosp->c_iflag & IGNPAR) {
|
3087 |
|
|
portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
|
3088 |
|
|
cor1 |= COR1_PARIGNORE;
|
3089 |
|
|
}
|
3090 |
|
|
if (tiosp->c_iflag & IGNBRK) {
|
3091 |
|
|
portp->rxignoremsk |= ST_BREAK;
|
3092 |
|
|
cor4 |= COR4_IGNBRK;
|
3093 |
|
|
}
|
3094 |
|
|
|
3095 |
|
|
portp->rxmarkmsk = ST_OVERRUN;
|
3096 |
|
|
if (tiosp->c_iflag & (INPCK | PARMRK))
|
3097 |
|
|
portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
|
3098 |
|
|
if (tiosp->c_iflag & BRKINT)
|
3099 |
|
|
portp->rxmarkmsk |= ST_BREAK;
|
3100 |
|
|
|
3101 |
|
|
/*
|
3102 |
|
|
* Go through the char size, parity and stop bits and set all the
|
3103 |
|
|
* option register appropriately.
|
3104 |
|
|
*/
|
3105 |
|
|
switch (tiosp->c_cflag & CSIZE) {
|
3106 |
|
|
case CS5:
|
3107 |
|
|
cor1 |= COR1_CHL5;
|
3108 |
|
|
break;
|
3109 |
|
|
case CS6:
|
3110 |
|
|
cor1 |= COR1_CHL6;
|
3111 |
|
|
break;
|
3112 |
|
|
case CS7:
|
3113 |
|
|
cor1 |= COR1_CHL7;
|
3114 |
|
|
break;
|
3115 |
|
|
default:
|
3116 |
|
|
cor1 |= COR1_CHL8;
|
3117 |
|
|
break;
|
3118 |
|
|
}
|
3119 |
|
|
|
3120 |
|
|
if (tiosp->c_cflag & CSTOPB)
|
3121 |
|
|
cor1 |= COR1_STOP2;
|
3122 |
|
|
else
|
3123 |
|
|
cor1 |= COR1_STOP1;
|
3124 |
|
|
|
3125 |
|
|
if (tiosp->c_cflag & PARENB) {
|
3126 |
|
|
if (tiosp->c_cflag & PARODD)
|
3127 |
|
|
cor1 |= (COR1_PARENB | COR1_PARODD);
|
3128 |
|
|
else
|
3129 |
|
|
cor1 |= (COR1_PARENB | COR1_PAREVEN);
|
3130 |
|
|
} else {
|
3131 |
|
|
cor1 |= COR1_PARNONE;
|
3132 |
|
|
}
|
3133 |
|
|
|
3134 |
|
|
/*
|
3135 |
|
|
* Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
|
3136 |
|
|
* space for hardware flow control and the like. This should be set to
|
3137 |
|
|
* VMIN. Also here we will set the RX data timeout to 10ms - this should
|
3138 |
|
|
* really be based on VTIME.
|
3139 |
|
|
*/
|
3140 |
|
|
cor3 |= FIFO_RXTHRESHOLD;
|
3141 |
|
|
rtpr = 2;
|
3142 |
|
|
|
3143 |
|
|
/*
|
3144 |
|
|
* Calculate the baud rate timers. For now we will just assume that
|
3145 |
|
|
* the input and output baud are the same. Could have used a baud
|
3146 |
|
|
* table here, but this way we can generate virtually any baud rate
|
3147 |
|
|
* we like!
|
3148 |
|
|
*/
|
3149 |
|
|
baudrate = tiosp->c_cflag & CBAUD;
|
3150 |
|
|
if (baudrate & CBAUDEX) {
|
3151 |
|
|
baudrate &= ~CBAUDEX;
|
3152 |
|
|
if ((baudrate < 1) || (baudrate > 2))
|
3153 |
|
|
tiosp->c_cflag &= ~CBAUDEX;
|
3154 |
|
|
else
|
3155 |
|
|
baudrate += 15;
|
3156 |
|
|
}
|
3157 |
|
|
baudrate = stl_baudrates[baudrate];
|
3158 |
|
|
if ((tiosp->c_cflag & CBAUD) == B38400) {
|
3159 |
|
|
if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
|
3160 |
|
|
baudrate = 57600;
|
3161 |
|
|
else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
|
3162 |
|
|
baudrate = 115200;
|
3163 |
|
|
else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
|
3164 |
|
|
baudrate = (portp->baud_base / portp->custom_divisor);
|
3165 |
|
|
}
|
3166 |
|
|
if (baudrate > STL_CD1400MAXBAUD)
|
3167 |
|
|
baudrate = STL_CD1400MAXBAUD;
|
3168 |
|
|
|
3169 |
|
|
if (baudrate > 0) {
|
3170 |
|
|
for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
|
3171 |
|
|
clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) / baudrate);
|
3172 |
|
|
if (clkdiv < 0x100)
|
3173 |
|
|
break;
|
3174 |
|
|
}
|
3175 |
|
|
div = (unsigned char) clkdiv;
|
3176 |
|
|
}
|
3177 |
|
|
|
3178 |
|
|
/*
|
3179 |
|
|
* Check what form of modem signaling is required and set it up.
|
3180 |
|
|
*/
|
3181 |
|
|
if ((tiosp->c_cflag & CLOCAL) == 0) {
|
3182 |
|
|
mcor1 |= MCOR1_DCD;
|
3183 |
|
|
mcor2 |= MCOR2_DCD;
|
3184 |
|
|
sreron |= SRER_MODEM;
|
3185 |
|
|
portp->flags |= ASYNC_CHECK_CD;
|
3186 |
|
|
} else {
|
3187 |
|
|
portp->flags &= ~ASYNC_CHECK_CD;
|
3188 |
|
|
}
|
3189 |
|
|
|
3190 |
|
|
/*
|
3191 |
|
|
* Setup cd1400 enhanced modes if we can. In particular we want to
|
3192 |
|
|
* handle as much of the flow control as possible automatically. As
|
3193 |
|
|
* well as saving a few CPU cycles it will also greatly improve flow
|
3194 |
|
|
* control reliability.
|
3195 |
|
|
*/
|
3196 |
|
|
if (tiosp->c_iflag & IXON) {
|
3197 |
|
|
cor2 |= COR2_TXIBE;
|
3198 |
|
|
cor3 |= COR3_SCD12;
|
3199 |
|
|
if (tiosp->c_iflag & IXANY)
|
3200 |
|
|
cor2 |= COR2_IXM;
|
3201 |
|
|
}
|
3202 |
|
|
|
3203 |
|
|
if (tiosp->c_cflag & CRTSCTS) {
|
3204 |
|
|
cor2 |= COR2_CTSAE;
|
3205 |
|
|
mcor1 |= FIFO_RTSTHRESHOLD;
|
3206 |
|
|
}
|
3207 |
|
|
|
3208 |
|
|
/*
|
3209 |
|
|
* All cd1400 register values calculated so go through and set
|
3210 |
|
|
* them all up.
|
3211 |
|
|
*/
|
3212 |
|
|
|
3213 |
|
|
#if DEBUG
|
3214 |
|
|
printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
|
3215 |
|
|
portp->portnr, portp->panelnr, portp->brdnr);
|
3216 |
|
|
printk(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
|
3217 |
|
|
cor1, cor2, cor3, cor4, cor5);
|
3218 |
|
|
printk(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
|
3219 |
|
|
mcor1, mcor2, rtpr, sreron, sreroff);
|
3220 |
|
|
printk(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
|
3221 |
|
|
printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
|
3222 |
|
|
tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
|
3223 |
|
|
tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
|
3224 |
|
|
#endif
|
3225 |
|
|
|
3226 |
|
|
save_flags(flags);
|
3227 |
|
|
cli();
|
3228 |
|
|
BRDENABLE(portp->brdnr, portp->pagenr);
|
3229 |
|
|
stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
|
3230 |
|
|
srer = stl_cd1400getreg(portp, SRER);
|
3231 |
|
|
stl_cd1400setreg(portp, SRER, 0);
|
3232 |
|
|
if (stl_cd1400updatereg(portp, COR1, cor1))
|
3233 |
|
|
ccr = 1;
|
3234 |
|
|
if (stl_cd1400updatereg(portp, COR2, cor2))
|
3235 |
|
|
ccr = 1;
|
3236 |
|
|
if (stl_cd1400updatereg(portp, COR3, cor3))
|
3237 |
|
|
ccr = 1;
|
3238 |
|
|
if (ccr) {
|
3239 |
|
|
stl_cd1400ccrwait(portp);
|
3240 |
|
|
stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
|
3241 |
|
|
}
|
3242 |
|
|
stl_cd1400setreg(portp, COR4, cor4);
|
3243 |
|
|
stl_cd1400setreg(portp, COR5, cor5);
|
3244 |
|
|
stl_cd1400setreg(portp, MCOR1, mcor1);
|
3245 |
|
|
stl_cd1400setreg(portp, MCOR2, mcor2);
|
3246 |
|
|
if (baudrate > 0) {
|
3247 |
|
|
stl_cd1400setreg(portp, TCOR, clk);
|
3248 |
|
|
stl_cd1400setreg(portp, TBPR, div);
|
3249 |
|
|
stl_cd1400setreg(portp, RCOR, clk);
|
3250 |
|
|
stl_cd1400setreg(portp, RBPR, div);
|
3251 |
|
|
}
|
3252 |
|
|
stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
|
3253 |
|
|
stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
|
3254 |
|
|
stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
|
3255 |
|
|
stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
|
3256 |
|
|
stl_cd1400setreg(portp, RTPR, rtpr);
|
3257 |
|
|
mcor1 = stl_cd1400getreg(portp, MSVR1);
|
3258 |
|
|
if (mcor1 & MSVR1_DCD)
|
3259 |
|
|
portp->sigs |= TIOCM_CD;
|
3260 |
|
|
else
|
3261 |
|
|
portp->sigs &= ~TIOCM_CD;
|
3262 |
|
|
stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
|
3263 |
|
|
BRDDISABLE(portp->brdnr);
|
3264 |
|
|
restore_flags(flags);
|
3265 |
|
|
}
|
3266 |
|
|
|
3267 |
|
|
/*****************************************************************************/
|
3268 |
|
|
|
3269 |
|
|
/*
|
3270 |
|
|
* Set the state of the DTR and RTS signals.
|
3271 |
|
|
*/
|
3272 |
|
|
|
3273 |
|
|
static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts)
|
3274 |
|
|
{
|
3275 |
|
|
unsigned char msvr1, msvr2;
|
3276 |
|
|
unsigned long flags;
|
3277 |
|
|
|
3278 |
|
|
#if DEBUG
|
3279 |
|
|
printk("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n",
|
3280 |
|
|
(int) portp, dtr, rts);
|
3281 |
|
|
#endif
|
3282 |
|
|
|
3283 |
|
|
msvr1 = 0;
|
3284 |
|
|
msvr2 = 0;
|
3285 |
|
|
if (dtr > 0)
|
3286 |
|
|
msvr1 = MSVR1_DTR;
|
3287 |
|
|
if (rts > 0)
|
3288 |
|
|
msvr2 = MSVR2_RTS;
|
3289 |
|
|
|
3290 |
|
|
save_flags(flags);
|
3291 |
|
|
cli();
|
3292 |
|
|
BRDENABLE(portp->brdnr, portp->pagenr);
|
3293 |
|
|
stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
|
3294 |
|
|
if (rts >= 0)
|
3295 |
|
|
stl_cd1400setreg(portp, MSVR2, msvr2);
|
3296 |
|
|
if (dtr >= 0)
|
3297 |
|
|
stl_cd1400setreg(portp, MSVR1, msvr1);
|
3298 |
|
|
BRDDISABLE(portp->brdnr);
|
3299 |
|
|
restore_flags(flags);
|
3300 |
|
|
}
|
3301 |
|
|
|
3302 |
|
|
/*****************************************************************************/
|
3303 |
|
|
|
3304 |
|
|
/*
|
3305 |
|
|
* Return the state of the signals.
|
3306 |
|
|
*/
|
3307 |
|
|
|
3308 |
|
|
static int stl_cd1400getsignals(stlport_t *portp)
|
3309 |
|
|
{
|
3310 |
|
|
unsigned char msvr1, msvr2;
|
3311 |
|
|
unsigned long flags;
|
3312 |
|
|
int sigs;
|
3313 |
|
|
|
3314 |
|
|
#if DEBUG
|
3315 |
|
|
printk("stl_cd1400getsignals(portp=%x)\n", (int) portp);
|
3316 |
|
|
#endif
|
3317 |
|
|
|
3318 |
|
|
save_flags(flags);
|
3319 |
|
|
cli();
|
3320 |
|
|
BRDENABLE(portp->brdnr, portp->pagenr);
|
3321 |
|
|
stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
|
3322 |
|
|
msvr1 = stl_cd1400getreg(portp, MSVR1);
|
3323 |
|
|
msvr2 = stl_cd1400getreg(portp, MSVR2);
|
3324 |
|
|
BRDDISABLE(portp->brdnr);
|
3325 |
|
|
restore_flags(flags);
|
3326 |
|
|
|
3327 |
|
|
sigs = 0;
|
3328 |
|
|
sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
|
3329 |
|
|
sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
|
3330 |
|
|
sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
|
3331 |
|
|
sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
|
3332 |
|
|
#if 0
|
3333 |
|
|
sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
|
3334 |
|
|
sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
|
3335 |
|
|
#else
|
3336 |
|
|
sigs |= TIOCM_DSR;
|
3337 |
|
|
#endif
|
3338 |
|
|
return(sigs);
|
3339 |
|
|
}
|
3340 |
|
|
|
3341 |
|
|
/*****************************************************************************/
|
3342 |
|
|
|
3343 |
|
|
/*
|
3344 |
|
|
* Enable/Disable the Transmitter and/or Receiver.
|
3345 |
|
|
*/
|
3346 |
|
|
|
3347 |
|
|
static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx)
|
3348 |
|
|
{
|
3349 |
|
|
unsigned char ccr;
|
3350 |
|
|
unsigned long flags;
|
3351 |
|
|
|
3352 |
|
|
#if DEBUG
|
3353 |
|
|
printk("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n",
|
3354 |
|
|
(int) portp, rx, tx);
|
3355 |
|
|
#endif
|
3356 |
|
|
ccr = 0;
|
3357 |
|
|
|
3358 |
|
|
if (tx == 0)
|
3359 |
|
|
ccr |= CCR_TXDISABLE;
|
3360 |
|
|
else if (tx > 0)
|
3361 |
|
|
ccr |= CCR_TXENABLE;
|
3362 |
|
|
if (rx == 0)
|
3363 |
|
|
ccr |= CCR_RXDISABLE;
|
3364 |
|
|
else if (rx > 0)
|
3365 |
|
|
ccr |= CCR_RXENABLE;
|
3366 |
|
|
|
3367 |
|
|
save_flags(flags);
|
3368 |
|
|
cli();
|
3369 |
|
|
BRDENABLE(portp->brdnr, portp->pagenr);
|
3370 |
|
|
stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
|
3371 |
|
|
stl_cd1400ccrwait(portp);
|
3372 |
|
|
stl_cd1400setreg(portp, CCR, ccr);
|
3373 |
|
|
stl_cd1400ccrwait(portp);
|
3374 |
|
|
BRDDISABLE(portp->brdnr);
|
3375 |
|
|
restore_flags(flags);
|
3376 |
|
|
}
|
3377 |
|
|
|
3378 |
|
|
/*****************************************************************************/
|
3379 |
|
|
|
3380 |
|
|
/*
|
3381 |
|
|
* Start/stop the Transmitter and/or Receiver.
|
3382 |
|
|
*/
|
3383 |
|
|
|
3384 |
|
|
static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx)
|
3385 |
|
|
{
|
3386 |
|
|
unsigned char sreron, sreroff;
|
3387 |
|
|
unsigned long flags;
|
3388 |
|
|
|
3389 |
|
|
#if DEBUG
|
3390 |
|
|
printk("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
|
3391 |
|
|
(int) portp, rx, tx);
|
3392 |
|
|
#endif
|
3393 |
|
|
|
3394 |
|
|
sreron = 0;
|
3395 |
|
|
sreroff = 0;
|
3396 |
|
|
if (tx == 0)
|
3397 |
|
|
sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
|
3398 |
|
|
else if (tx == 1)
|
3399 |
|
|
sreron |= SRER_TXDATA;
|
3400 |
|
|
else if (tx >= 2)
|
3401 |
|
|
sreron |= SRER_TXEMPTY;
|
3402 |
|
|
if (rx == 0)
|
3403 |
|
|
sreroff |= SRER_RXDATA;
|
3404 |
|
|
else if (rx > 0)
|
3405 |
|
|
sreron |= SRER_RXDATA;
|
3406 |
|
|
|
3407 |
|
|
save_flags(flags);
|
3408 |
|
|
cli();
|
3409 |
|
|
BRDENABLE(portp->brdnr, portp->pagenr);
|
3410 |
|
|
stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
|
3411 |
|
|
stl_cd1400setreg(portp, SRER,
|
3412 |
|
|
((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
|
3413 |
|
|
BRDDISABLE(portp->brdnr);
|
3414 |
|
|
if (tx > 0)
|
3415 |
|
|
set_bit(ASYI_TXBUSY, &portp->istate);
|
3416 |
|
|
restore_flags(flags);
|
3417 |
|
|
}
|
3418 |
|
|
|
3419 |
|
|
/*****************************************************************************/
|
3420 |
|
|
|
3421 |
|
|
/*
|
3422 |
|
|
* Disable all interrupts from this port.
|
3423 |
|
|
*/
|
3424 |
|
|
|
3425 |
|
|
static void stl_cd1400disableintrs(stlport_t *portp)
|
3426 |
|
|
{
|
3427 |
|
|
unsigned long flags;
|
3428 |
|
|
|
3429 |
|
|
#if DEBUG
|
3430 |
|
|
printk("stl_cd1400disableintrs(portp=%x)\n", (int) portp);
|
3431 |
|
|
#endif
|
3432 |
|
|
save_flags(flags);
|
3433 |
|
|
cli();
|
3434 |
|
|
BRDENABLE(portp->brdnr, portp->pagenr);
|
3435 |
|
|
stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
|
3436 |
|
|
stl_cd1400setreg(portp, SRER, 0);
|
3437 |
|
|
BRDDISABLE(portp->brdnr);
|
3438 |
|
|
restore_flags(flags);
|
3439 |
|
|
}
|
3440 |
|
|
|
3441 |
|
|
/*****************************************************************************/
|
3442 |
|
|
|
3443 |
|
|
static void stl_cd1400sendbreak(stlport_t *portp, long len)
|
3444 |
|
|
{
|
3445 |
|
|
unsigned long flags;
|
3446 |
|
|
|
3447 |
|
|
#if DEBUG
|
3448 |
|
|
printk("stl_cd1400sendbreak(portp=%x,len=%d)\n",
|
3449 |
|
|
(int) portp, (int) len);
|
3450 |
|
|
#endif
|
3451 |
|
|
|
3452 |
|
|
save_flags(flags);
|
3453 |
|
|
cli();
|
3454 |
|
|
BRDENABLE(portp->brdnr, portp->pagenr);
|
3455 |
|
|
stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
|
3456 |
|
|
stl_cd1400setreg(portp, COR2,
|
3457 |
|
|
(stl_cd1400getreg(portp, COR2) | COR2_ETC));
|
3458 |
|
|
stl_cd1400setreg(portp, SRER,
|
3459 |
|
|
((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) | SRER_TXEMPTY));
|
3460 |
|
|
BRDDISABLE(portp->brdnr);
|
3461 |
|
|
len = len / 5;
|
3462 |
|
|
portp->brklen = (len > 255) ? 255 : len;
|
3463 |
|
|
portp->stats.txbreaks++;
|
3464 |
|
|
restore_flags(flags);
|
3465 |
|
|
}
|
3466 |
|
|
|
3467 |
|
|
/*****************************************************************************/
|
3468 |
|
|
|
3469 |
|
|
/*
|
3470 |
|
|
* Take flow control actions...
|
3471 |
|
|
*/
|
3472 |
|
|
|
3473 |
|
|
static void stl_cd1400flowctrl(stlport_t *portp, int state)
|
3474 |
|
|
{
|
3475 |
|
|
struct tty_struct *tty;
|
3476 |
|
|
unsigned long flags;
|
3477 |
|
|
|
3478 |
|
|
#if DEBUG
|
3479 |
|
|
printk("stl_cd1400flowctrl(portp=%x,state=%x)\n", (int) portp, state);
|
3480 |
|
|
#endif
|
3481 |
|
|
|
3482 |
|
|
if (portp == (stlport_t *) NULL)
|
3483 |
|
|
return;
|
3484 |
|
|
tty = portp->tty;
|
3485 |
|
|
if (tty == (struct tty_struct *) NULL)
|
3486 |
|
|
return;
|
3487 |
|
|
|
3488 |
|
|
save_flags(flags);
|
3489 |
|
|
cli();
|
3490 |
|
|
BRDENABLE(portp->brdnr, portp->pagenr);
|
3491 |
|
|
stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
|
3492 |
|
|
|
3493 |
|
|
if (state) {
|
3494 |
|
|
if (tty->termios->c_iflag & IXOFF) {
|
3495 |
|
|
stl_cd1400ccrwait(portp);
|
3496 |
|
|
stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
|
3497 |
|
|
portp->stats.rxxon++;
|
3498 |
|
|
stl_cd1400ccrwait(portp);
|
3499 |
|
|
}
|
3500 |
|
|
/*
|
3501 |
|
|
* Question: should we return RTS to what it was before? It may
|
3502 |
|
|
* have been set by an ioctl... Suppose not, since if you have
|
3503 |
|
|
* hardware flow control set then it is pretty silly to go and
|
3504 |
|
|
* set the RTS line by hand.
|
3505 |
|
|
*/
|
3506 |
|
|
if (tty->termios->c_cflag & CRTSCTS) {
|
3507 |
|
|
stl_cd1400setreg(portp, MCOR1,
|
3508 |
|
|
(stl_cd1400getreg(portp, MCOR1) |
|
3509 |
|
|
FIFO_RTSTHRESHOLD));
|
3510 |
|
|
stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
|
3511 |
|
|
portp->stats.rxrtson++;
|
3512 |
|
|
}
|
3513 |
|
|
} else {
|
3514 |
|
|
if (tty->termios->c_iflag & IXOFF) {
|
3515 |
|
|
stl_cd1400ccrwait(portp);
|
3516 |
|
|
stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
|
3517 |
|
|
portp->stats.rxxoff++;
|
3518 |
|
|
stl_cd1400ccrwait(portp);
|
3519 |
|
|
}
|
3520 |
|
|
if (tty->termios->c_cflag & CRTSCTS) {
|
3521 |
|
|
stl_cd1400setreg(portp, MCOR1,
|
3522 |
|
|
(stl_cd1400getreg(portp, MCOR1) & 0xf0));
|
3523 |
|
|
stl_cd1400setreg(portp, MSVR2, 0);
|
3524 |
|
|
portp->stats.rxrtsoff++;
|
3525 |
|
|
}
|
3526 |
|
|
}
|
3527 |
|
|
|
3528 |
|
|
BRDDISABLE(portp->brdnr);
|
3529 |
|
|
restore_flags(flags);
|
3530 |
|
|
}
|
3531 |
|
|
|
3532 |
|
|
/*****************************************************************************/
|
3533 |
|
|
|
3534 |
|
|
/*
|
3535 |
|
|
* Send a flow control character...
|
3536 |
|
|
*/
|
3537 |
|
|
|
3538 |
|
|
static void stl_cd1400sendflow(stlport_t *portp, int state)
|
3539 |
|
|
{
|
3540 |
|
|
struct tty_struct *tty;
|
3541 |
|
|
unsigned long flags;
|
3542 |
|
|
|
3543 |
|
|
#if DEBUG
|
3544 |
|
|
printk("stl_cd1400sendflow(portp=%x,state=%x)\n", (int) portp, state);
|
3545 |
|
|
#endif
|
3546 |
|
|
|
3547 |
|
|
if (portp == (stlport_t *) NULL)
|
3548 |
|
|
return;
|
3549 |
|
|
tty = portp->tty;
|
3550 |
|
|
if (tty == (struct tty_struct *) NULL)
|
3551 |
|
|
return;
|
3552 |
|
|
|
3553 |
|
|
save_flags(flags);
|
3554 |
|
|
cli();
|
3555 |
|
|
BRDENABLE(portp->brdnr, portp->pagenr);
|
3556 |
|
|
stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
|
3557 |
|
|
if (state) {
|
3558 |
|
|
stl_cd1400ccrwait(portp);
|
3559 |
|
|
stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
|
3560 |
|
|
portp->stats.rxxon++;
|
3561 |
|
|
stl_cd1400ccrwait(portp);
|
3562 |
|
|
} else {
|
3563 |
|
|
stl_cd1400ccrwait(portp);
|
3564 |
|
|
stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
|
3565 |
|
|
portp->stats.rxxoff++;
|
3566 |
|
|
stl_cd1400ccrwait(portp);
|
3567 |
|
|
}
|
3568 |
|
|
BRDDISABLE(portp->brdnr);
|
3569 |
|
|
restore_flags(flags);
|
3570 |
|
|
}
|
3571 |
|
|
|
3572 |
|
|
/*****************************************************************************/
|
3573 |
|
|
|
3574 |
|
|
static void stl_cd1400flush(stlport_t *portp)
|
3575 |
|
|
{
|
3576 |
|
|
unsigned long flags;
|
3577 |
|
|
|
3578 |
|
|
#if DEBUG
|
3579 |
|
|
printk("stl_cd1400flush(portp=%x)\n", (int) portp);
|
3580 |
|
|
#endif
|
3581 |
|
|
|
3582 |
|
|
if (portp == (stlport_t *) NULL)
|
3583 |
|
|
return;
|
3584 |
|
|
|
3585 |
|
|
save_flags(flags);
|
3586 |
|
|
cli();
|
3587 |
|
|
BRDENABLE(portp->brdnr, portp->pagenr);
|
3588 |
|
|
stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
|
3589 |
|
|
stl_cd1400ccrwait(portp);
|
3590 |
|
|
stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
|
3591 |
|
|
stl_cd1400ccrwait(portp);
|
3592 |
|
|
portp->tx.tail = portp->tx.head;
|
3593 |
|
|
BRDDISABLE(portp->brdnr);
|
3594 |
|
|
restore_flags(flags);
|
3595 |
|
|
}
|
3596 |
|
|
|
3597 |
|
|
/*****************************************************************************/
|
3598 |
|
|
|
3599 |
|
|
/*
|
3600 |
|
|
* Return the current state of data flow on this port. This is only
|
3601 |
|
|
* really interresting when determining if data has fully completed
|
3602 |
|
|
* transmission or not... This is easy for the cd1400, it accurately
|
3603 |
|
|
* maintains the busy port flag.
|
3604 |
|
|
*/
|
3605 |
|
|
|
3606 |
|
|
static int stl_cd1400datastate(stlport_t *portp)
|
3607 |
|
|
{
|
3608 |
|
|
#if DEBUG
|
3609 |
|
|
printk("stl_cd1400datastate(portp=%x)\n", (int) portp);
|
3610 |
|
|
#endif
|
3611 |
|
|
|
3612 |
|
|
if (portp == (stlport_t *) NULL)
|
3613 |
|
|
return(0);
|
3614 |
|
|
|
3615 |
|
|
return(test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0);
|
3616 |
|
|
}
|
3617 |
|
|
|
3618 |
|
|
/*****************************************************************************/
|
3619 |
|
|
|
3620 |
|
|
/*
|
3621 |
|
|
* Interrupt service routine for cd1400 EasyIO boards.
|
3622 |
|
|
*/
|
3623 |
|
|
|
3624 |
|
|
static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase)
|
3625 |
|
|
{
|
3626 |
|
|
unsigned char svrtype;
|
3627 |
|
|
|
3628 |
|
|
#if DEBUG
|
3629 |
|
|
printk("stl_cd1400eiointr(panelp=%x,iobase=%x)\n",
|
3630 |
|
|
(int) panelp, iobase);
|
3631 |
|
|
#endif
|
3632 |
|
|
|
3633 |
|
|
outb(SVRR, iobase);
|
3634 |
|
|
svrtype = inb(iobase + EREG_DATA);
|
3635 |
|
|
if (panelp->nrports > 4) {
|
3636 |
|
|
outb((SVRR + 0x80), iobase);
|
3637 |
|
|
svrtype |= inb(iobase + EREG_DATA);
|
3638 |
|
|
}
|
3639 |
|
|
|
3640 |
|
|
if (svrtype & SVRR_RX)
|
3641 |
|
|
stl_cd1400rxisr(panelp, iobase);
|
3642 |
|
|
else if (svrtype & SVRR_TX)
|
3643 |
|
|
stl_cd1400txisr(panelp, iobase);
|
3644 |
|
|
else if (svrtype & SVRR_MDM)
|
3645 |
|
|
stl_cd1400mdmisr(panelp, iobase);
|
3646 |
|
|
}
|
3647 |
|
|
|
3648 |
|
|
/*****************************************************************************/
|
3649 |
|
|
|
3650 |
|
|
/*
|
3651 |
|
|
* Interrupt service routine for cd1400 panels.
|
3652 |
|
|
*/
|
3653 |
|
|
|
3654 |
|
|
static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase)
|
3655 |
|
|
{
|
3656 |
|
|
unsigned char svrtype;
|
3657 |
|
|
|
3658 |
|
|
#if DEBUG
|
3659 |
|
|
printk("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp,
|
3660 |
|
|
iobase);
|
3661 |
|
|
#endif
|
3662 |
|
|
|
3663 |
|
|
outb(SVRR, iobase);
|
3664 |
|
|
svrtype = inb(iobase + EREG_DATA);
|
3665 |
|
|
outb((SVRR + 0x80), iobase);
|
3666 |
|
|
svrtype |= inb(iobase + EREG_DATA);
|
3667 |
|
|
if (svrtype & SVRR_RX)
|
3668 |
|
|
stl_cd1400rxisr(panelp, iobase);
|
3669 |
|
|
else if (svrtype & SVRR_TX)
|
3670 |
|
|
stl_cd1400txisr(panelp, iobase);
|
3671 |
|
|
else if (svrtype & SVRR_MDM)
|
3672 |
|
|
stl_cd1400mdmisr(panelp, iobase);
|
3673 |
|
|
}
|
3674 |
|
|
|
3675 |
|
|
/*****************************************************************************/
|
3676 |
|
|
|
3677 |
|
|
/*
|
3678 |
|
|
* Transmit interrupt handler. This has gotta be fast! Handling TX
|
3679 |
|
|
* chars is pretty simple, stuff as many as possible from the TX buffer
|
3680 |
|
|
* into the cd1400 FIFO. Must also handle TX breaks here, since they
|
3681 |
|
|
* are embedded as commands in the data stream. Oh no, had to use a goto!
|
3682 |
|
|
* This could be optimized more, will do when I get time...
|
3683 |
|
|
* In practice it is possible that interrupts are enabled but that the
|
3684 |
|
|
* port has been hung up. Need to handle not having any TX buffer here,
|
3685 |
|
|
* this is done by using the side effect that head and tail will also
|
3686 |
|
|
* be NULL if the buffer has been freed.
|
3687 |
|
|
*/
|
3688 |
|
|
|
3689 |
|
|
static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr)
|
3690 |
|
|
{
|
3691 |
|
|
stlport_t *portp;
|
3692 |
|
|
int len, stlen;
|
3693 |
|
|
char *head, *tail;
|
3694 |
|
|
unsigned char ioack, srer;
|
3695 |
|
|
|
3696 |
|
|
#if DEBUG
|
3697 |
|
|
printk("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
|
3698 |
|
|
#endif
|
3699 |
|
|
|
3700 |
|
|
ioack = inb(ioaddr + EREG_TXACK);
|
3701 |
|
|
if (((ioack & panelp->ackmask) != 0) ||
|
3702 |
|
|
((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
|
3703 |
|
|
printk("STALLION: bad TX interrupt ack value=%x\n", ioack);
|
3704 |
|
|
return;
|
3705 |
|
|
}
|
3706 |
|
|
portp = panelp->ports[(ioack >> 3)];
|
3707 |
|
|
|
3708 |
|
|
/*
|
3709 |
|
|
* Unfortunately we need to handle breaks in the data stream, since
|
3710 |
|
|
* this is the only way to generate them on the cd1400. Do it now if
|
3711 |
|
|
* a break is to be sent.
|
3712 |
|
|
*/
|
3713 |
|
|
if (portp->brklen != 0) {
|
3714 |
|
|
if (portp->brklen > 0) {
|
3715 |
|
|
outb((TDR + portp->uartaddr), ioaddr);
|
3716 |
|
|
outb(ETC_CMD, (ioaddr + EREG_DATA));
|
3717 |
|
|
outb(ETC_STARTBREAK, (ioaddr + EREG_DATA));
|
3718 |
|
|
outb(ETC_CMD, (ioaddr + EREG_DATA));
|
3719 |
|
|
outb(ETC_DELAY, (ioaddr + EREG_DATA));
|
3720 |
|
|
outb(portp->brklen, (ioaddr + EREG_DATA));
|
3721 |
|
|
outb(ETC_CMD, (ioaddr + EREG_DATA));
|
3722 |
|
|
outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
|
3723 |
|
|
portp->brklen = -1;
|
3724 |
|
|
goto stl_txalldone;
|
3725 |
|
|
} else {
|
3726 |
|
|
outb((COR2 + portp->uartaddr), ioaddr);
|
3727 |
|
|
outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC),
|
3728 |
|
|
(ioaddr + EREG_DATA));
|
3729 |
|
|
portp->brklen = 0;
|
3730 |
|
|
}
|
3731 |
|
|
}
|
3732 |
|
|
|
3733 |
|
|
head = portp->tx.head;
|
3734 |
|
|
tail = portp->tx.tail;
|
3735 |
|
|
len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
|
3736 |
|
|
if ((len == 0) || ((len < STL_TXBUFLOW) &&
|
3737 |
|
|
(test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
|
3738 |
|
|
set_bit(ASYI_TXLOW, &portp->istate);
|
3739 |
|
|
queue_task_irq_off(&portp->tqueue, &tq_scheduler);
|
3740 |
|
|
}
|
3741 |
|
|
|
3742 |
|
|
if (len == 0) {
|
3743 |
|
|
outb((SRER + portp->uartaddr), ioaddr);
|
3744 |
|
|
srer = inb(ioaddr + EREG_DATA);
|
3745 |
|
|
if (srer & SRER_TXDATA) {
|
3746 |
|
|
srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
|
3747 |
|
|
} else {
|
3748 |
|
|
srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
|
3749 |
|
|
clear_bit(ASYI_TXBUSY, &portp->istate);
|
3750 |
|
|
}
|
3751 |
|
|
outb(srer, (ioaddr + EREG_DATA));
|
3752 |
|
|
} else {
|
3753 |
|
|
len = MIN(len, CD1400_TXFIFOSIZE);
|
3754 |
|
|
portp->stats.txtotal += len;
|
3755 |
|
|
stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
|
3756 |
|
|
outb((TDR + portp->uartaddr), ioaddr);
|
3757 |
|
|
outsb((ioaddr + EREG_DATA), tail, stlen);
|
3758 |
|
|
len -= stlen;
|
3759 |
|
|
tail += stlen;
|
3760 |
|
|
if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
|
3761 |
|
|
tail = portp->tx.buf;
|
3762 |
|
|
if (len > 0) {
|
3763 |
|
|
outsb((ioaddr + EREG_DATA), tail, len);
|
3764 |
|
|
tail += len;
|
3765 |
|
|
}
|
3766 |
|
|
portp->tx.tail = tail;
|
3767 |
|
|
}
|
3768 |
|
|
|
3769 |
|
|
stl_txalldone:
|
3770 |
|
|
outb((EOSRR + portp->uartaddr), ioaddr);
|
3771 |
|
|
outb(0, (ioaddr + EREG_DATA));
|
3772 |
|
|
}
|
3773 |
|
|
|
3774 |
|
|
/*****************************************************************************/
|
3775 |
|
|
|
3776 |
|
|
/*
|
3777 |
|
|
* Receive character interrupt handler. Determine if we have good chars
|
3778 |
|
|
* or bad chars and then process appropriately. Good chars are easy
|
3779 |
|
|
* just shove the lot into the RX buffer and set all status byte to 0.
|
3780 |
|
|
* If a bad RX char then process as required. This routine needs to be
|
3781 |
|
|
* fast! In practice it is possible that we get an interrupt on a port
|
3782 |
|
|
* that is closed. This can happen on hangups - since they completely
|
3783 |
|
|
* shutdown a port not in user context. Need to handle this case.
|
3784 |
|
|
*/
|
3785 |
|
|
|
3786 |
|
|
static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
|
3787 |
|
|
{
|
3788 |
|
|
stlport_t *portp;
|
3789 |
|
|
struct tty_struct *tty;
|
3790 |
|
|
unsigned int ioack, len, buflen;
|
3791 |
|
|
unsigned char status;
|
3792 |
|
|
char ch;
|
3793 |
|
|
|
3794 |
|
|
#if DEBUG
|
3795 |
|
|
printk("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
|
3796 |
|
|
#endif
|
3797 |
|
|
|
3798 |
|
|
ioack = inb(ioaddr + EREG_RXACK);
|
3799 |
|
|
if ((ioack & panelp->ackmask) != 0) {
|
3800 |
|
|
printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
|
3801 |
|
|
return;
|
3802 |
|
|
}
|
3803 |
|
|
portp = panelp->ports[(ioack >> 3)];
|
3804 |
|
|
tty = portp->tty;
|
3805 |
|
|
|
3806 |
|
|
if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
|
3807 |
|
|
outb((RDCR + portp->uartaddr), ioaddr);
|
3808 |
|
|
len = inb(ioaddr + EREG_DATA);
|
3809 |
|
|
if ((tty == (struct tty_struct *) NULL) ||
|
3810 |
|
|
(tty->flip.char_buf_ptr == (char *) NULL) ||
|
3811 |
|
|
((buflen = TTY_FLIPBUF_SIZE - tty->flip.count) == 0)) {
|
3812 |
|
|
outb((RDSR + portp->uartaddr), ioaddr);
|
3813 |
|
|
insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
|
3814 |
|
|
portp->stats.rxlost += len;
|
3815 |
|
|
portp->stats.rxtotal += len;
|
3816 |
|
|
} else {
|
3817 |
|
|
len = MIN(len, buflen);
|
3818 |
|
|
if (len > 0) {
|
3819 |
|
|
outb((RDSR + portp->uartaddr), ioaddr);
|
3820 |
|
|
insb((ioaddr + EREG_DATA), tty->flip.char_buf_ptr, len);
|
3821 |
|
|
memset(tty->flip.flag_buf_ptr, 0, len);
|
3822 |
|
|
tty->flip.flag_buf_ptr += len;
|
3823 |
|
|
tty->flip.char_buf_ptr += len;
|
3824 |
|
|
tty->flip.count += len;
|
3825 |
|
|
tty_schedule_flip(tty);
|
3826 |
|
|
portp->stats.rxtotal += len;
|
3827 |
|
|
}
|
3828 |
|
|
}
|
3829 |
|
|
} else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
|
3830 |
|
|
outb((RDSR + portp->uartaddr), ioaddr);
|
3831 |
|
|
status = inb(ioaddr + EREG_DATA);
|
3832 |
|
|
ch = inb(ioaddr + EREG_DATA);
|
3833 |
|
|
if (status & ST_PARITY)
|
3834 |
|
|
portp->stats.rxparity++;
|
3835 |
|
|
if (status & ST_FRAMING)
|
3836 |
|
|
portp->stats.rxframing++;
|
3837 |
|
|
if (status & ST_OVERRUN)
|
3838 |
|
|
portp->stats.rxoverrun++;
|
3839 |
|
|
if (status & ST_BREAK)
|
3840 |
|
|
portp->stats.rxbreaks++;
|
3841 |
|
|
if (status & ST_SCHARMASK) {
|
3842 |
|
|
if ((status & ST_SCHARMASK) == ST_SCHAR1)
|
3843 |
|
|
portp->stats.txxon++;
|
3844 |
|
|
if ((status & ST_SCHARMASK) == ST_SCHAR2)
|
3845 |
|
|
portp->stats.txxoff++;
|
3846 |
|
|
goto stl_rxalldone;
|
3847 |
|
|
}
|
3848 |
|
|
if ((tty != (struct tty_struct *) NULL) &&
|
3849 |
|
|
((portp->rxignoremsk & status) == 0)) {
|
3850 |
|
|
if (portp->rxmarkmsk & status) {
|
3851 |
|
|
if (status & ST_BREAK) {
|
3852 |
|
|
status = TTY_BREAK;
|
3853 |
|
|
if (portp->flags & ASYNC_SAK) {
|
3854 |
|
|
do_SAK(tty);
|
3855 |
|
|
BRDENABLE(portp->brdnr, portp->pagenr);
|
3856 |
|
|
}
|
3857 |
|
|
} else if (status & ST_PARITY) {
|
3858 |
|
|
status = TTY_PARITY;
|
3859 |
|
|
} else if (status & ST_FRAMING) {
|
3860 |
|
|
status = TTY_FRAME;
|
3861 |
|
|
} else if(status & ST_OVERRUN) {
|
3862 |
|
|
status = TTY_OVERRUN;
|
3863 |
|
|
} else {
|
3864 |
|
|
status = 0;
|
3865 |
|
|
}
|
3866 |
|
|
} else {
|
3867 |
|
|
status = 0;
|
3868 |
|
|
}
|
3869 |
|
|
if (tty->flip.char_buf_ptr != (char *) NULL) {
|
3870 |
|
|
if (tty->flip.count < TTY_FLIPBUF_SIZE) {
|
3871 |
|
|
*tty->flip.flag_buf_ptr++ = status;
|
3872 |
|
|
*tty->flip.char_buf_ptr++ = ch;
|
3873 |
|
|
tty->flip.count++;
|
3874 |
|
|
}
|
3875 |
|
|
tty_schedule_flip(tty);
|
3876 |
|
|
}
|
3877 |
|
|
}
|
3878 |
|
|
} else {
|
3879 |
|
|
printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
|
3880 |
|
|
return;
|
3881 |
|
|
}
|
3882 |
|
|
|
3883 |
|
|
stl_rxalldone:
|
3884 |
|
|
outb((EOSRR + portp->uartaddr), ioaddr);
|
3885 |
|
|
outb(0, (ioaddr + EREG_DATA));
|
3886 |
|
|
}
|
3887 |
|
|
|
3888 |
|
|
/*****************************************************************************/
|
3889 |
|
|
|
3890 |
|
|
/*
|
3891 |
|
|
* Modem interrupt handler. The is called when the modem signal line
|
3892 |
|
|
* (DCD) has changed state. Leave most of the work to the off-level
|
3893 |
|
|
* processing routine.
|
3894 |
|
|
*/
|
3895 |
|
|
|
3896 |
|
|
static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr)
|
3897 |
|
|
{
|
3898 |
|
|
stlport_t *portp;
|
3899 |
|
|
unsigned int ioack;
|
3900 |
|
|
unsigned char misr;
|
3901 |
|
|
|
3902 |
|
|
#if DEBUG
|
3903 |
|
|
printk("stl_cd1400mdmisr(panelp=%x)\n", (int) panelp);
|
3904 |
|
|
#endif
|
3905 |
|
|
|
3906 |
|
|
ioack = inb(ioaddr + EREG_MDACK);
|
3907 |
|
|
if (((ioack & panelp->ackmask) != 0) ||
|
3908 |
|
|
((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
|
3909 |
|
|
printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
|
3910 |
|
|
return;
|
3911 |
|
|
}
|
3912 |
|
|
portp = panelp->ports[(ioack >> 3)];
|
3913 |
|
|
|
3914 |
|
|
outb((MISR + portp->uartaddr), ioaddr);
|
3915 |
|
|
misr = inb(ioaddr + EREG_DATA);
|
3916 |
|
|
if (misr & MISR_DCD) {
|
3917 |
|
|
set_bit(ASYI_DCDCHANGE, &portp->istate);
|
3918 |
|
|
queue_task_irq_off(&portp->tqueue, &tq_scheduler);
|
3919 |
|
|
portp->stats.modem++;
|
3920 |
|
|
}
|
3921 |
|
|
|
3922 |
|
|
outb((EOSRR + portp->uartaddr), ioaddr);
|
3923 |
|
|
outb(0, (ioaddr + EREG_DATA));
|
3924 |
|
|
}
|
3925 |
|
|
|
3926 |
|
|
/*****************************************************************************/
|
3927 |
|
|
/* SC26198 HARDWARE FUNCTIONS */
|
3928 |
|
|
/*****************************************************************************/
|
3929 |
|
|
|
3930 |
|
|
/*
|
3931 |
|
|
* These functions get/set/update the registers of the sc26198 UARTs.
|
3932 |
|
|
* Access to the sc26198 registers is via an address/data io port pair.
|
3933 |
|
|
* (Maybe should make this inline...)
|
3934 |
|
|
*/
|
3935 |
|
|
|
3936 |
|
|
static int stl_sc26198getreg(stlport_t *portp, int regnr)
|
3937 |
|
|
{
|
3938 |
|
|
outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
|
3939 |
|
|
return(inb(portp->ioaddr + XP_DATA));
|
3940 |
|
|
}
|
3941 |
|
|
|
3942 |
|
|
static void stl_sc26198setreg(stlport_t *portp, int regnr, int value)
|
3943 |
|
|
{
|
3944 |
|
|
outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
|
3945 |
|
|
outb(value, (portp->ioaddr + XP_DATA));
|
3946 |
|
|
}
|
3947 |
|
|
|
3948 |
|
|
static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value)
|
3949 |
|
|
{
|
3950 |
|
|
outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
|
3951 |
|
|
if (inb(portp->ioaddr + XP_DATA) != value) {
|
3952 |
|
|
outb(value, (portp->ioaddr + XP_DATA));
|
3953 |
|
|
return(1);
|
3954 |
|
|
}
|
3955 |
|
|
return(0);
|
3956 |
|
|
}
|
3957 |
|
|
|
3958 |
|
|
/*****************************************************************************/
|
3959 |
|
|
|
3960 |
|
|
/*
|
3961 |
|
|
* Functions to get and set the sc26198 global registers.
|
3962 |
|
|
*/
|
3963 |
|
|
|
3964 |
|
|
static int stl_sc26198getglobreg(stlport_t *portp, int regnr)
|
3965 |
|
|
{
|
3966 |
|
|
outb(regnr, (portp->ioaddr + XP_ADDR));
|
3967 |
|
|
return(inb(portp->ioaddr + XP_DATA));
|
3968 |
|
|
}
|
3969 |
|
|
|
3970 |
|
|
#if 0
|
3971 |
|
|
static void stl_sc26198setglobreg(stlport_t *portp, int regnr, int value)
|
3972 |
|
|
{
|
3973 |
|
|
outb(regnr, (portp->ioaddr + XP_ADDR));
|
3974 |
|
|
outb(value, (portp->ioaddr + XP_DATA));
|
3975 |
|
|
}
|
3976 |
|
|
#endif
|
3977 |
|
|
|
3978 |
|
|
/*****************************************************************************/
|
3979 |
|
|
|
3980 |
|
|
/*
|
3981 |
|
|
* Inbitialize the UARTs in a panel. We don't care what sort of board
|
3982 |
|
|
* these ports are on - since the port io registers are almost
|
3983 |
|
|
* identical when dealing with ports.
|
3984 |
|
|
*/
|
3985 |
|
|
|
3986 |
|
|
static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
|
3987 |
|
|
{
|
3988 |
|
|
int chipmask, i;
|
3989 |
|
|
int nrchips, ioaddr;
|
3990 |
|
|
|
3991 |
|
|
#if DEBUG
|
3992 |
|
|
printk("stl_sc26198panelinit(brdp=%x,panelp=%x)\n",
|
3993 |
|
|
(int) brdp, (int) panelp);
|
3994 |
|
|
#endif
|
3995 |
|
|
|
3996 |
|
|
BRDENABLE(panelp->brdnr, panelp->pagenr);
|
3997 |
|
|
|
3998 |
|
|
/*
|
3999 |
|
|
* Check that each chip is present and started up OK.
|
4000 |
|
|
*/
|
4001 |
|
|
chipmask = 0;
|
4002 |
|
|
nrchips = (panelp->nrports + 4) / SC26198_PORTS;
|
4003 |
|
|
if (brdp->brdtype == BRD_ECHPCI)
|
4004 |
|
|
outb(panelp->pagenr, brdp->ioctrl);
|
4005 |
|
|
|
4006 |
|
|
for (i = 0; (i < nrchips); i++) {
|
4007 |
|
|
ioaddr = panelp->iobase + (i * 4);
|
4008 |
|
|
outb(SCCR, (ioaddr + XP_ADDR));
|
4009 |
|
|
outb(CR_RESETALL, (ioaddr + XP_DATA));
|
4010 |
|
|
outb(TSTR, (ioaddr + XP_ADDR));
|
4011 |
|
|
if (inb(ioaddr + XP_DATA) != 0) {
|
4012 |
|
|
printk("STALLION: sc26198 not responding, "
|
4013 |
|
|
"brd=%d panel=%d chip=%d\n",
|
4014 |
|
|
panelp->brdnr, panelp->panelnr, i);
|
4015 |
|
|
continue;
|
4016 |
|
|
}
|
4017 |
|
|
chipmask |= (0x1 << i);
|
4018 |
|
|
outb(GCCR, (ioaddr + XP_ADDR));
|
4019 |
|
|
outb(GCCR_IVRTYPCHANACK, (ioaddr + XP_DATA));
|
4020 |
|
|
outb(WDTRCR, (ioaddr + XP_ADDR));
|
4021 |
|
|
outb(0xff, (ioaddr + XP_DATA));
|
4022 |
|
|
}
|
4023 |
|
|
|
4024 |
|
|
BRDDISABLE(panelp->brdnr);
|
4025 |
|
|
return(chipmask);
|
4026 |
|
|
}
|
4027 |
|
|
|
4028 |
|
|
/*****************************************************************************/
|
4029 |
|
|
|
4030 |
|
|
/*
|
4031 |
|
|
* Initialize hardware specific port registers.
|
4032 |
|
|
*/
|
4033 |
|
|
|
4034 |
|
|
static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
|
4035 |
|
|
{
|
4036 |
|
|
#if DEBUG
|
4037 |
|
|
printk("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n",
|
4038 |
|
|
(int) brdp, (int) panelp, (int) portp);
|
4039 |
|
|
#endif
|
4040 |
|
|
|
4041 |
|
|
if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
|
4042 |
|
|
(portp == (stlport_t *) NULL))
|
4043 |
|
|
return;
|
4044 |
|
|
|
4045 |
|
|
portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
|
4046 |
|
|
portp->uartaddr = (portp->portnr & 0x07) << 4;
|
4047 |
|
|
portp->pagenr = panelp->pagenr;
|
4048 |
|
|
portp->hwid = 0x1;
|
4049 |
|
|
|
4050 |
|
|
BRDENABLE(portp->brdnr, portp->pagenr);
|
4051 |
|
|
stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
|
4052 |
|
|
BRDDISABLE(portp->brdnr);
|
4053 |
|
|
}
|
4054 |
|
|
|
4055 |
|
|
/*****************************************************************************/
|
4056 |
|
|
|
4057 |
|
|
/*
|
4058 |
|
|
* Set up the sc26198 registers for a port based on the termios port
|
4059 |
|
|
* settings.
|
4060 |
|
|
*/
|
4061 |
|
|
|
4062 |
|
|
static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
|
4063 |
|
|
{
|
4064 |
|
|
stlbrd_t *brdp;
|
4065 |
|
|
unsigned long flags;
|
4066 |
|
|
unsigned int baudrate;
|
4067 |
|
|
unsigned char mr0, mr1, mr2, clk;
|
4068 |
|
|
unsigned char imron, imroff, iopr, ipr;
|
4069 |
|
|
|
4070 |
|
|
mr0 = 0;
|
4071 |
|
|
mr1 = 0;
|
4072 |
|
|
mr2 = 0;
|
4073 |
|
|
clk = 0;
|
4074 |
|
|
iopr = 0;
|
4075 |
|
|
imron = 0;
|
4076 |
|
|
imroff = 0;
|
4077 |
|
|
|
4078 |
|
|
brdp = stl_brds[portp->brdnr];
|
4079 |
|
|
if (brdp == (stlbrd_t *) NULL)
|
4080 |
|
|
return;
|
4081 |
|
|
|
4082 |
|
|
/*
|
4083 |
|
|
* Set up the RX char ignore mask with those RX error types we
|
4084 |
|
|
* can ignore.
|
4085 |
|
|
*/
|
4086 |
|
|
portp->rxignoremsk = 0;
|
4087 |
|
|
if (tiosp->c_iflag & IGNPAR)
|
4088 |
|
|
portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
|
4089 |
|
|
SR_RXOVERRUN);
|
4090 |
|
|
if (tiosp->c_iflag & IGNBRK)
|
4091 |
|
|
portp->rxignoremsk |= SR_RXBREAK;
|
4092 |
|
|
|
4093 |
|
|
portp->rxmarkmsk = SR_RXOVERRUN;
|
4094 |
|
|
if (tiosp->c_iflag & (INPCK | PARMRK))
|
4095 |
|
|
portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
|
4096 |
|
|
if (tiosp->c_iflag & BRKINT)
|
4097 |
|
|
portp->rxmarkmsk |= SR_RXBREAK;
|
4098 |
|
|
|
4099 |
|
|
/*
|
4100 |
|
|
* Go through the char size, parity and stop bits and set all the
|
4101 |
|
|
* option register appropriately.
|
4102 |
|
|
*/
|
4103 |
|
|
switch (tiosp->c_cflag & CSIZE) {
|
4104 |
|
|
case CS5:
|
4105 |
|
|
mr1 |= MR1_CS5;
|
4106 |
|
|
break;
|
4107 |
|
|
case CS6:
|
4108 |
|
|
mr1 |= MR1_CS6;
|
4109 |
|
|
break;
|
4110 |
|
|
case CS7:
|
4111 |
|
|
mr1 |= MR1_CS7;
|
4112 |
|
|
break;
|
4113 |
|
|
default:
|
4114 |
|
|
mr1 |= MR1_CS8;
|
4115 |
|
|
break;
|
4116 |
|
|
}
|
4117 |
|
|
|
4118 |
|
|
if (tiosp->c_cflag & CSTOPB)
|
4119 |
|
|
mr2 |= MR2_STOP2;
|
4120 |
|
|
else
|
4121 |
|
|
mr2 |= MR2_STOP1;
|
4122 |
|
|
|
4123 |
|
|
if (tiosp->c_cflag & PARENB) {
|
4124 |
|
|
if (tiosp->c_cflag & PARODD)
|
4125 |
|
|
mr1 |= (MR1_PARENB | MR1_PARODD);
|
4126 |
|
|
else
|
4127 |
|
|
mr1 |= (MR1_PARENB | MR1_PAREVEN);
|
4128 |
|
|
} else {
|
4129 |
|
|
mr1 |= MR1_PARNONE;
|
4130 |
|
|
}
|
4131 |
|
|
|
4132 |
|
|
mr1 |= MR1_ERRBLOCK;
|
4133 |
|
|
|
4134 |
|
|
/*
|
4135 |
|
|
* Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
|
4136 |
|
|
* space for hardware flow control and the like. This should be set to
|
4137 |
|
|
* VMIN.
|
4138 |
|
|
*/
|
4139 |
|
|
mr2 |= MR2_RXFIFOHALF;
|
4140 |
|
|
|
4141 |
|
|
/*
|
4142 |
|
|
* Calculate the baud rate timers. For now we will just assume that
|
4143 |
|
|
* the input and output baud are the same. The sc26198 has a fixed
|
4144 |
|
|
* baud rate table, so only discrete baud rates possible.
|
4145 |
|
|
*/
|
4146 |
|
|
baudrate = tiosp->c_cflag & CBAUD;
|
4147 |
|
|
if (baudrate & CBAUDEX) {
|
4148 |
|
|
baudrate &= ~CBAUDEX;
|
4149 |
|
|
if ((baudrate < 1) || (baudrate > 5))
|
4150 |
|
|
tiosp->c_cflag &= ~CBAUDEX;
|
4151 |
|
|
else
|
4152 |
|
|
baudrate += 15;
|
4153 |
|
|
}
|
4154 |
|
|
baudrate = stl_baudrates[baudrate];
|
4155 |
|
|
if ((tiosp->c_cflag & CBAUD) == B38400) {
|
4156 |
|
|
if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
|
4157 |
|
|
baudrate = 57600;
|
4158 |
|
|
else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
|
4159 |
|
|
baudrate = 115200;
|
4160 |
|
|
else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
|
4161 |
|
|
baudrate = (portp->baud_base / portp->custom_divisor);
|
4162 |
|
|
}
|
4163 |
|
|
if (baudrate > STL_SC26198MAXBAUD)
|
4164 |
|
|
baudrate = STL_SC26198MAXBAUD;
|
4165 |
|
|
|
4166 |
|
|
if (baudrate > 0) {
|
4167 |
|
|
for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
|
4168 |
|
|
if (baudrate <= sc26198_baudtable[clk])
|
4169 |
|
|
break;
|
4170 |
|
|
}
|
4171 |
|
|
}
|
4172 |
|
|
|
4173 |
|
|
/*
|
4174 |
|
|
* Check what form of modem signaling is required and set it up.
|
4175 |
|
|
*/
|
4176 |
|
|
if (tiosp->c_cflag & CLOCAL) {
|
4177 |
|
|
portp->flags &= ~ASYNC_CHECK_CD;
|
4178 |
|
|
} else {
|
4179 |
|
|
iopr |= IOPR_DCDCOS;
|
4180 |
|
|
imron |= IR_IOPORT;
|
4181 |
|
|
portp->flags |= ASYNC_CHECK_CD;
|
4182 |
|
|
}
|
4183 |
|
|
|
4184 |
|
|
/*
|
4185 |
|
|
* Setup sc26198 enhanced modes if we can. In particular we want to
|
4186 |
|
|
* handle as much of the flow control as possible automatically. As
|
4187 |
|
|
* well as saving a few CPU cycles it will also greatly improve flow
|
4188 |
|
|
* control reliability.
|
4189 |
|
|
*/
|
4190 |
|
|
if (tiosp->c_iflag & IXON) {
|
4191 |
|
|
mr0 |= MR0_SWFTX | MR0_SWFT;
|
4192 |
|
|
imron |= IR_XONXOFF;
|
4193 |
|
|
} else {
|
4194 |
|
|
imroff |= IR_XONXOFF;
|
4195 |
|
|
}
|
4196 |
|
|
if (tiosp->c_iflag & IXOFF)
|
4197 |
|
|
mr0 |= MR0_SWFRX;
|
4198 |
|
|
|
4199 |
|
|
if (tiosp->c_cflag & CRTSCTS) {
|
4200 |
|
|
mr2 |= MR2_AUTOCTS;
|
4201 |
|
|
mr1 |= MR1_AUTORTS;
|
4202 |
|
|
}
|
4203 |
|
|
|
4204 |
|
|
/*
|
4205 |
|
|
* All sc26198 register values calculated so go through and set
|
4206 |
|
|
* them all up.
|
4207 |
|
|
*/
|
4208 |
|
|
|
4209 |
|
|
#if DEBUG
|
4210 |
|
|
printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
|
4211 |
|
|
portp->portnr, portp->panelnr, portp->brdnr);
|
4212 |
|
|
printk(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
|
4213 |
|
|
printk(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
|
4214 |
|
|
printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
|
4215 |
|
|
tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
|
4216 |
|
|
tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
|
4217 |
|
|
#endif
|
4218 |
|
|
|
4219 |
|
|
save_flags(flags);
|
4220 |
|
|
cli();
|
4221 |
|
|
BRDENABLE(portp->brdnr, portp->pagenr);
|
4222 |
|
|
stl_sc26198setreg(portp, IMR, 0);
|
4223 |
|
|
stl_sc26198updatereg(portp, MR0, mr0);
|
4224 |
|
|
stl_sc26198updatereg(portp, MR1, mr1);
|
4225 |
|
|
stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
|
4226 |
|
|
stl_sc26198updatereg(portp, MR2, mr2);
|
4227 |
|
|
stl_sc26198updatereg(portp, IOPIOR,
|
4228 |
|
|
((stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr));
|
4229 |
|
|
|
4230 |
|
|
if (baudrate > 0) {
|
4231 |
|
|
stl_sc26198setreg(portp, TXCSR, clk);
|
4232 |
|
|
stl_sc26198setreg(portp, RXCSR, clk);
|
4233 |
|
|
}
|
4234 |
|
|
|
4235 |
|
|
stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
|
4236 |
|
|
stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
|
4237 |
|
|
|
4238 |
|
|
ipr = stl_sc26198getreg(portp, IPR);
|
4239 |
|
|
if (ipr & IPR_DCD)
|
4240 |
|
|
portp->sigs &= ~TIOCM_CD;
|
4241 |
|
|
else
|
4242 |
|
|
portp->sigs |= TIOCM_CD;
|
4243 |
|
|
|
4244 |
|
|
portp->imr = (portp->imr & ~imroff) | imron;
|
4245 |
|
|
stl_sc26198setreg(portp, IMR, portp->imr);
|
4246 |
|
|
BRDDISABLE(portp->brdnr);
|
4247 |
|
|
restore_flags(flags);
|
4248 |
|
|
}
|
4249 |
|
|
|
4250 |
|
|
/*****************************************************************************/
|
4251 |
|
|
|
4252 |
|
|
/*
|
4253 |
|
|
* Set the state of the DTR and RTS signals.
|
4254 |
|
|
*/
|
4255 |
|
|
|
4256 |
|
|
static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts)
|
4257 |
|
|
{
|
4258 |
|
|
unsigned char iopioron, iopioroff;
|
4259 |
|
|
unsigned long flags;
|
4260 |
|
|
|
4261 |
|
|
#if DEBUG
|
4262 |
|
|
printk("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)\n",
|
4263 |
|
|
(int) portp, dtr, rts);
|
4264 |
|
|
#endif
|
4265 |
|
|
|
4266 |
|
|
iopioron = 0;
|
4267 |
|
|
iopioroff = 0;
|
4268 |
|
|
if (dtr == 0)
|
4269 |
|
|
iopioroff |= IPR_DTR;
|
4270 |
|
|
else if (dtr > 0)
|
4271 |
|
|
iopioron |= IPR_DTR;
|
4272 |
|
|
if (rts == 0)
|
4273 |
|
|
iopioroff |= IPR_RTS;
|
4274 |
|
|
else if (rts > 0)
|
4275 |
|
|
iopioron |= IPR_RTS;
|
4276 |
|
|
|
4277 |
|
|
save_flags(flags);
|
4278 |
|
|
cli();
|
4279 |
|
|
BRDENABLE(portp->brdnr, portp->pagenr);
|
4280 |
|
|
stl_sc26198setreg(portp, IOPIOR,
|
4281 |
|
|
((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
|
4282 |
|
|
BRDDISABLE(portp->brdnr);
|
4283 |
|
|
restore_flags(flags);
|
4284 |
|
|
}
|
4285 |
|
|
|
4286 |
|
|
/*****************************************************************************/
|
4287 |
|
|
|
4288 |
|
|
/*
|
4289 |
|
|
* Return the state of the signals.
|
4290 |
|
|
*/
|
4291 |
|
|
|
4292 |
|
|
static int stl_sc26198getsignals(stlport_t *portp)
|
4293 |
|
|
{
|
4294 |
|
|
unsigned char ipr;
|
4295 |
|
|
unsigned long flags;
|
4296 |
|
|
int sigs;
|
4297 |
|
|
|
4298 |
|
|
#if DEBUG
|
4299 |
|
|
printk("stl_sc26198getsignals(portp=%x)\n", (int) portp);
|
4300 |
|
|
#endif
|
4301 |
|
|
|
4302 |
|
|
save_flags(flags);
|
4303 |
|
|
cli();
|
4304 |
|
|
BRDENABLE(portp->brdnr, portp->pagenr);
|
4305 |
|
|
ipr = stl_sc26198getreg(portp, IPR);
|
4306 |
|
|
BRDDISABLE(portp->brdnr);
|
4307 |
|
|
restore_flags(flags);
|
4308 |
|
|
|
4309 |
|
|
sigs = 0;
|
4310 |
|
|
sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
|
4311 |
|
|
sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
|
4312 |
|
|
sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
|
4313 |
|
|
sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
|
4314 |
|
|
sigs |= TIOCM_DSR;
|
4315 |
|
|
return(sigs);
|
4316 |
|
|
}
|
4317 |
|
|
|
4318 |
|
|
/*****************************************************************************/
|
4319 |
|
|
|
4320 |
|
|
/*
|
4321 |
|
|
* Enable/Disable the Transmitter and/or Receiver.
|
4322 |
|
|
*/
|
4323 |
|
|
|
4324 |
|
|
static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx)
|
4325 |
|
|
{
|
4326 |
|
|
unsigned char ccr;
|
4327 |
|
|
unsigned long flags;
|
4328 |
|
|
|
4329 |
|
|
#if DEBUG
|
4330 |
|
|
printk("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)\n",
|
4331 |
|
|
(int) portp, rx, tx);
|
4332 |
|
|
#endif
|
4333 |
|
|
|
4334 |
|
|
ccr = portp->crenable;
|
4335 |
|
|
if (tx == 0)
|
4336 |
|
|
ccr &= ~CR_TXENABLE;
|
4337 |
|
|
else if (tx > 0)
|
4338 |
|
|
ccr |= CR_TXENABLE;
|
4339 |
|
|
if (rx == 0)
|
4340 |
|
|
ccr &= ~CR_RXENABLE;
|
4341 |
|
|
else if (rx > 0)
|
4342 |
|
|
ccr |= CR_RXENABLE;
|
4343 |
|
|
|
4344 |
|
|
save_flags(flags);
|
4345 |
|
|
cli();
|
4346 |
|
|
BRDENABLE(portp->brdnr, portp->pagenr);
|
4347 |
|
|
stl_sc26198setreg(portp, SCCR, ccr);
|
4348 |
|
|
BRDDISABLE(portp->brdnr);
|
4349 |
|
|
portp->crenable = ccr;
|
4350 |
|
|
restore_flags(flags);
|
4351 |
|
|
}
|
4352 |
|
|
|
4353 |
|
|
/*****************************************************************************/
|
4354 |
|
|
|
4355 |
|
|
/*
|
4356 |
|
|
* Start/stop the Transmitter and/or Receiver.
|
4357 |
|
|
*/
|
4358 |
|
|
|
4359 |
|
|
static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx)
|
4360 |
|
|
{
|
4361 |
|
|
unsigned char imr;
|
4362 |
|
|
unsigned long flags;
|
4363 |
|
|
|
4364 |
|
|
#if DEBUG
|
4365 |
|
|
printk("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)\n",
|
4366 |
|
|
(int) portp, rx, tx);
|
4367 |
|
|
#endif
|
4368 |
|
|
|
4369 |
|
|
imr = portp->imr;
|
4370 |
|
|
if (tx == 0)
|
4371 |
|
|
imr &= ~IR_TXRDY;
|
4372 |
|
|
else if (tx == 1)
|
4373 |
|
|
imr |= IR_TXRDY;
|
4374 |
|
|
if (rx == 0)
|
4375 |
|
|
imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
|
4376 |
|
|
else if (rx > 0)
|
4377 |
|
|
imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
|
4378 |
|
|
|
4379 |
|
|
save_flags(flags);
|
4380 |
|
|
cli();
|
4381 |
|
|
BRDENABLE(portp->brdnr, portp->pagenr);
|
4382 |
|
|
stl_sc26198setreg(portp, IMR, imr);
|
4383 |
|
|
BRDDISABLE(portp->brdnr);
|
4384 |
|
|
portp->imr = imr;
|
4385 |
|
|
if (tx > 0)
|
4386 |
|
|
set_bit(ASYI_TXBUSY, &portp->istate);
|
4387 |
|
|
restore_flags(flags);
|
4388 |
|
|
}
|
4389 |
|
|
|
4390 |
|
|
/*****************************************************************************/
|
4391 |
|
|
|
4392 |
|
|
/*
|
4393 |
|
|
* Disable all interrupts from this port.
|
4394 |
|
|
*/
|
4395 |
|
|
|
4396 |
|
|
static void stl_sc26198disableintrs(stlport_t *portp)
|
4397 |
|
|
{
|
4398 |
|
|
unsigned long flags;
|
4399 |
|
|
|
4400 |
|
|
#if DEBUG
|
4401 |
|
|
printk("stl_sc26198disableintrs(portp=%x)\n", (int) portp);
|
4402 |
|
|
#endif
|
4403 |
|
|
|
4404 |
|
|
save_flags(flags);
|
4405 |
|
|
cli();
|
4406 |
|
|
BRDENABLE(portp->brdnr, portp->pagenr);
|
4407 |
|
|
portp->imr = 0;
|
4408 |
|
|
stl_sc26198setreg(portp, IMR, 0);
|
4409 |
|
|
BRDDISABLE(portp->brdnr);
|
4410 |
|
|
restore_flags(flags);
|
4411 |
|
|
}
|
4412 |
|
|
|
4413 |
|
|
/*****************************************************************************/
|
4414 |
|
|
|
4415 |
|
|
static void stl_sc26198sendbreak(stlport_t *portp, long len)
|
4416 |
|
|
{
|
4417 |
|
|
unsigned long flags;
|
4418 |
|
|
|
4419 |
|
|
#if DEBUG
|
4420 |
|
|
printk("stl_sc26198sendbreak(portp=%x,len=%d)\n", (int) portp,
|
4421 |
|
|
(int) len);
|
4422 |
|
|
#endif
|
4423 |
|
|
|
4424 |
|
|
current->state = TASK_INTERRUPTIBLE;
|
4425 |
|
|
current->timeout = jiffies + (len / (1000 / HZ));
|
4426 |
|
|
|
4427 |
|
|
save_flags(flags);
|
4428 |
|
|
cli();
|
4429 |
|
|
BRDENABLE(portp->brdnr, portp->pagenr);
|
4430 |
|
|
stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
|
4431 |
|
|
BRDDISABLE(portp->brdnr);
|
4432 |
|
|
portp->stats.txbreaks++;
|
4433 |
|
|
|
4434 |
|
|
schedule();
|
4435 |
|
|
|
4436 |
|
|
BRDENABLE(portp->brdnr, portp->pagenr);
|
4437 |
|
|
stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
|
4438 |
|
|
BRDDISABLE(portp->brdnr);
|
4439 |
|
|
restore_flags(flags);
|
4440 |
|
|
}
|
4441 |
|
|
|
4442 |
|
|
/*****************************************************************************/
|
4443 |
|
|
|
4444 |
|
|
/*
|
4445 |
|
|
* Take flow control actions...
|
4446 |
|
|
*/
|
4447 |
|
|
|
4448 |
|
|
static void stl_sc26198flowctrl(stlport_t *portp, int state)
|
4449 |
|
|
{
|
4450 |
|
|
struct tty_struct *tty;
|
4451 |
|
|
unsigned long flags;
|
4452 |
|
|
unsigned char mr0;
|
4453 |
|
|
|
4454 |
|
|
#if DEBUG
|
4455 |
|
|
printk("stl_sc26198flowctrl(portp=%x,state=%x)\n", (int) portp, state);
|
4456 |
|
|
#endif
|
4457 |
|
|
|
4458 |
|
|
if (portp == (stlport_t *) NULL)
|
4459 |
|
|
return;
|
4460 |
|
|
tty = portp->tty;
|
4461 |
|
|
if (tty == (struct tty_struct *) NULL)
|
4462 |
|
|
return;
|
4463 |
|
|
|
4464 |
|
|
save_flags(flags);
|
4465 |
|
|
cli();
|
4466 |
|
|
BRDENABLE(portp->brdnr, portp->pagenr);
|
4467 |
|
|
|
4468 |
|
|
if (state) {
|
4469 |
|
|
if (tty->termios->c_iflag & IXOFF) {
|
4470 |
|
|
mr0 = stl_sc26198getreg(portp, MR0);
|
4471 |
|
|
stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
|
4472 |
|
|
stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
|
4473 |
|
|
mr0 |= MR0_SWFRX;
|
4474 |
|
|
portp->stats.rxxon++;
|
4475 |
|
|
stl_sc26198wait(portp);
|
4476 |
|
|
stl_sc26198setreg(portp, MR0, mr0);
|
4477 |
|
|
}
|
4478 |
|
|
/*
|
4479 |
|
|
* Question: should we return RTS to what it was before? It may
|
4480 |
|
|
* have been set by an ioctl... Suppose not, since if you have
|
4481 |
|
|
* hardware flow control set then it is pretty silly to go and
|
4482 |
|
|
* set the RTS line by hand.
|
4483 |
|
|
*/
|
4484 |
|
|
if (tty->termios->c_cflag & CRTSCTS) {
|
4485 |
|
|
stl_sc26198setreg(portp, MR1,
|
4486 |
|
|
(stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
|
4487 |
|
|
stl_sc26198setreg(portp, IOPIOR,
|
4488 |
|
|
(stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
|
4489 |
|
|
portp->stats.rxrtson++;
|
4490 |
|
|
}
|
4491 |
|
|
} else {
|
4492 |
|
|
if (tty->termios->c_iflag & IXOFF) {
|
4493 |
|
|
mr0 = stl_sc26198getreg(portp, MR0);
|
4494 |
|
|
stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
|
4495 |
|
|
stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
|
4496 |
|
|
mr0 &= ~MR0_SWFRX;
|
4497 |
|
|
portp->stats.rxxoff++;
|
4498 |
|
|
stl_sc26198wait(portp);
|
4499 |
|
|
stl_sc26198setreg(portp, MR0, mr0);
|
4500 |
|
|
}
|
4501 |
|
|
if (tty->termios->c_cflag & CRTSCTS) {
|
4502 |
|
|
stl_sc26198setreg(portp, MR1,
|
4503 |
|
|
(stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
|
4504 |
|
|
stl_sc26198setreg(portp, IOPIOR,
|
4505 |
|
|
(stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
|
4506 |
|
|
portp->stats.rxrtsoff++;
|
4507 |
|
|
}
|
4508 |
|
|
}
|
4509 |
|
|
|
4510 |
|
|
BRDDISABLE(portp->brdnr);
|
4511 |
|
|
restore_flags(flags);
|
4512 |
|
|
}
|
4513 |
|
|
|
4514 |
|
|
/*****************************************************************************/
|
4515 |
|
|
|
4516 |
|
|
/*
|
4517 |
|
|
* Send a flow control character.
|
4518 |
|
|
*/
|
4519 |
|
|
|
4520 |
|
|
static void stl_sc26198sendflow(stlport_t *portp, int state)
|
4521 |
|
|
{
|
4522 |
|
|
struct tty_struct *tty;
|
4523 |
|
|
unsigned long flags;
|
4524 |
|
|
unsigned char mr0;
|
4525 |
|
|
|
4526 |
|
|
#if DEBUG
|
4527 |
|
|
printk("stl_sc26198sendflow(portp=%x,state=%x)\n", (int) portp, state);
|
4528 |
|
|
#endif
|
4529 |
|
|
|
4530 |
|
|
if (portp == (stlport_t *) NULL)
|
4531 |
|
|
return;
|
4532 |
|
|
tty = portp->tty;
|
4533 |
|
|
if (tty == (struct tty_struct *) NULL)
|
4534 |
|
|
return;
|
4535 |
|
|
|
4536 |
|
|
save_flags(flags);
|
4537 |
|
|
cli();
|
4538 |
|
|
BRDENABLE(portp->brdnr, portp->pagenr);
|
4539 |
|
|
if (state) {
|
4540 |
|
|
mr0 = stl_sc26198getreg(portp, MR0);
|
4541 |
|
|
stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
|
4542 |
|
|
stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
|
4543 |
|
|
mr0 |= MR0_SWFRX;
|
4544 |
|
|
portp->stats.rxxon++;
|
4545 |
|
|
stl_sc26198wait(portp);
|
4546 |
|
|
stl_sc26198setreg(portp, MR0, mr0);
|
4547 |
|
|
} else {
|
4548 |
|
|
mr0 = stl_sc26198getreg(portp, MR0);
|
4549 |
|
|
stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
|
4550 |
|
|
stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
|
4551 |
|
|
mr0 &= ~MR0_SWFRX;
|
4552 |
|
|
portp->stats.rxxoff++;
|
4553 |
|
|
stl_sc26198wait(portp);
|
4554 |
|
|
stl_sc26198setreg(portp, MR0, mr0);
|
4555 |
|
|
}
|
4556 |
|
|
BRDDISABLE(portp->brdnr);
|
4557 |
|
|
restore_flags(flags);
|
4558 |
|
|
}
|
4559 |
|
|
|
4560 |
|
|
/*****************************************************************************/
|
4561 |
|
|
|
4562 |
|
|
static void stl_sc26198flush(stlport_t *portp)
|
4563 |
|
|
{
|
4564 |
|
|
unsigned long flags;
|
4565 |
|
|
|
4566 |
|
|
#if DEBUG
|
4567 |
|
|
printk("stl_sc26198flush(portp=%x)\n", (int) portp);
|
4568 |
|
|
#endif
|
4569 |
|
|
|
4570 |
|
|
if (portp == (stlport_t *) NULL)
|
4571 |
|
|
return;
|
4572 |
|
|
|
4573 |
|
|
save_flags(flags);
|
4574 |
|
|
cli();
|
4575 |
|
|
BRDENABLE(portp->brdnr, portp->pagenr);
|
4576 |
|
|
stl_sc26198setreg(portp, SCCR, CR_TXRESET);
|
4577 |
|
|
stl_sc26198setreg(portp, SCCR, portp->crenable);
|
4578 |
|
|
BRDDISABLE(portp->brdnr);
|
4579 |
|
|
portp->tx.tail = portp->tx.head;
|
4580 |
|
|
restore_flags(flags);
|
4581 |
|
|
}
|
4582 |
|
|
|
4583 |
|
|
/*****************************************************************************/
|
4584 |
|
|
|
4585 |
|
|
/*
|
4586 |
|
|
* Return the current state of data flow on this port. This is only
|
4587 |
|
|
* really interresting when determining if data has fully completed
|
4588 |
|
|
* transmission or not... The sc26198 interrupt scheme cannot
|
4589 |
|
|
* determine when all data has actually drained, so we need to
|
4590 |
|
|
* check the port statusy register to be sure.
|
4591 |
|
|
*/
|
4592 |
|
|
|
4593 |
|
|
static int stl_sc26198datastate(stlport_t *portp)
|
4594 |
|
|
{
|
4595 |
|
|
unsigned long flags;
|
4596 |
|
|
unsigned char sr;
|
4597 |
|
|
|
4598 |
|
|
#if DEBUG
|
4599 |
|
|
printk("stl_sc26198datastate(portp=%x)\n", (int) portp);
|
4600 |
|
|
#endif
|
4601 |
|
|
|
4602 |
|
|
if (portp == (stlport_t *) NULL)
|
4603 |
|
|
return(0);
|
4604 |
|
|
if (test_bit(ASYI_TXBUSY, &portp->istate))
|
4605 |
|
|
return(1);
|
4606 |
|
|
|
4607 |
|
|
save_flags(flags);
|
4608 |
|
|
cli();
|
4609 |
|
|
BRDENABLE(portp->brdnr, portp->pagenr);
|
4610 |
|
|
sr = stl_sc26198getreg(portp, SR);
|
4611 |
|
|
BRDDISABLE(portp->brdnr);
|
4612 |
|
|
restore_flags(flags);
|
4613 |
|
|
|
4614 |
|
|
return((sr & SR_TXEMPTY) ? 0 : 1);
|
4615 |
|
|
}
|
4616 |
|
|
|
4617 |
|
|
/*****************************************************************************/
|
4618 |
|
|
|
4619 |
|
|
/*
|
4620 |
|
|
* Delay for a small amount of time, to give the sc26198 a chance
|
4621 |
|
|
* to process a command...
|
4622 |
|
|
*/
|
4623 |
|
|
|
4624 |
|
|
static void stl_sc26198wait(stlport_t *portp)
|
4625 |
|
|
{
|
4626 |
|
|
int i;
|
4627 |
|
|
|
4628 |
|
|
#if DEBUG
|
4629 |
|
|
printk("stl_sc26198wait(portp=%x)\n", (int) portp);
|
4630 |
|
|
#endif
|
4631 |
|
|
|
4632 |
|
|
if (portp == (stlport_t *) NULL)
|
4633 |
|
|
return;
|
4634 |
|
|
|
4635 |
|
|
for (i = 0; (i < 20); i++)
|
4636 |
|
|
stl_sc26198getglobreg(portp, TSTR);
|
4637 |
|
|
}
|
4638 |
|
|
|
4639 |
|
|
/*****************************************************************************/
|
4640 |
|
|
|
4641 |
|
|
/*
|
4642 |
|
|
* If we are TX flow controlled and in IXANY mode then we may
|
4643 |
|
|
* need to unflow control here. We gotta do this because of the
|
4644 |
|
|
* automatic flow control modes of the sc26198.
|
4645 |
|
|
*/
|
4646 |
|
|
|
4647 |
|
|
static inline void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty)
|
4648 |
|
|
{
|
4649 |
|
|
unsigned char mr0;
|
4650 |
|
|
|
4651 |
|
|
mr0 = stl_sc26198getreg(portp, MR0);
|
4652 |
|
|
stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
|
4653 |
|
|
stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
|
4654 |
|
|
stl_sc26198wait(portp);
|
4655 |
|
|
stl_sc26198setreg(portp, MR0, mr0);
|
4656 |
|
|
clear_bit(ASYI_TXFLOWED, &portp->istate);
|
4657 |
|
|
}
|
4658 |
|
|
|
4659 |
|
|
/*****************************************************************************/
|
4660 |
|
|
|
4661 |
|
|
/*
|
4662 |
|
|
* Interrupt service routine for sc26198 panels.
|
4663 |
|
|
*/
|
4664 |
|
|
|
4665 |
|
|
static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase)
|
4666 |
|
|
{
|
4667 |
|
|
stlport_t *portp;
|
4668 |
|
|
unsigned int iack;
|
4669 |
|
|
|
4670 |
|
|
/*
|
4671 |
|
|
* Work around bug in sc26198 chip... Cannot have A6 address
|
4672 |
|
|
* line of UART high, else iack will be returned as 0.
|
4673 |
|
|
*/
|
4674 |
|
|
outb(0, (iobase + 1));
|
4675 |
|
|
|
4676 |
|
|
iack = inb(iobase + XP_IACK);
|
4677 |
|
|
portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
|
4678 |
|
|
|
4679 |
|
|
if (iack & IVR_RXDATA)
|
4680 |
|
|
stl_sc26198rxisr(portp, iack);
|
4681 |
|
|
else if (iack & IVR_TXDATA)
|
4682 |
|
|
stl_sc26198txisr(portp);
|
4683 |
|
|
else
|
4684 |
|
|
stl_sc26198otherisr(portp, iack);
|
4685 |
|
|
}
|
4686 |
|
|
|
4687 |
|
|
/*****************************************************************************/
|
4688 |
|
|
|
4689 |
|
|
/*
|
4690 |
|
|
* Transmit interrupt handler. This has gotta be fast! Handling TX
|
4691 |
|
|
* chars is pretty simple, stuff as many as possible from the TX buffer
|
4692 |
|
|
* into the sc26198 FIFO.
|
4693 |
|
|
* In practice it is possible that interrupts are enabled but that the
|
4694 |
|
|
* port has been hung up. Need to handle not having any TX buffer here,
|
4695 |
|
|
* this is done by using the side effect that head and tail will also
|
4696 |
|
|
* be NULL if the buffer has been freed.
|
4697 |
|
|
*/
|
4698 |
|
|
|
4699 |
|
|
static void stl_sc26198txisr(stlport_t *portp)
|
4700 |
|
|
{
|
4701 |
|
|
unsigned int ioaddr;
|
4702 |
|
|
unsigned char mr0;
|
4703 |
|
|
int len, stlen;
|
4704 |
|
|
char *head, *tail;
|
4705 |
|
|
|
4706 |
|
|
#if DEBUG
|
4707 |
|
|
printk("stl_sc26198txisr(portp=%x)\n", (int) portp);
|
4708 |
|
|
#endif
|
4709 |
|
|
|
4710 |
|
|
ioaddr = portp->ioaddr;
|
4711 |
|
|
head = portp->tx.head;
|
4712 |
|
|
tail = portp->tx.tail;
|
4713 |
|
|
len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
|
4714 |
|
|
if ((len == 0) || ((len < STL_TXBUFLOW) &&
|
4715 |
|
|
(test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
|
4716 |
|
|
set_bit(ASYI_TXLOW, &portp->istate);
|
4717 |
|
|
queue_task_irq_off(&portp->tqueue, &tq_scheduler);
|
4718 |
|
|
}
|
4719 |
|
|
|
4720 |
|
|
if (len == 0) {
|
4721 |
|
|
outb((MR0 | portp->uartaddr), (ioaddr + XP_ADDR));
|
4722 |
|
|
mr0 = inb(ioaddr + XP_DATA);
|
4723 |
|
|
if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
|
4724 |
|
|
portp->imr &= ~IR_TXRDY;
|
4725 |
|
|
outb((IMR | portp->uartaddr), (ioaddr + XP_ADDR));
|
4726 |
|
|
outb(portp->imr, (ioaddr + XP_DATA));
|
4727 |
|
|
clear_bit(ASYI_TXBUSY, &portp->istate);
|
4728 |
|
|
} else {
|
4729 |
|
|
mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
|
4730 |
|
|
outb(mr0, (ioaddr + XP_DATA));
|
4731 |
|
|
}
|
4732 |
|
|
} else {
|
4733 |
|
|
len = MIN(len, SC26198_TXFIFOSIZE);
|
4734 |
|
|
portp->stats.txtotal += len;
|
4735 |
|
|
stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
|
4736 |
|
|
outb(GTXFIFO, (ioaddr + XP_ADDR));
|
4737 |
|
|
outsb((ioaddr + XP_DATA), tail, stlen);
|
4738 |
|
|
len -= stlen;
|
4739 |
|
|
tail += stlen;
|
4740 |
|
|
if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
|
4741 |
|
|
tail = portp->tx.buf;
|
4742 |
|
|
if (len > 0) {
|
4743 |
|
|
outsb((ioaddr + XP_DATA), tail, len);
|
4744 |
|
|
tail += len;
|
4745 |
|
|
}
|
4746 |
|
|
portp->tx.tail = tail;
|
4747 |
|
|
}
|
4748 |
|
|
}
|
4749 |
|
|
|
4750 |
|
|
/*****************************************************************************/
|
4751 |
|
|
|
4752 |
|
|
/*
|
4753 |
|
|
* Receive character interrupt handler. Determine if we have good chars
|
4754 |
|
|
* or bad chars and then process appropriately. Good chars are easy
|
4755 |
|
|
* just shove the lot into the RX buffer and set all status byte to 0.
|
4756 |
|
|
* If a bad RX char then process as required. This routine needs to be
|
4757 |
|
|
* fast! In practice it is possible that we get an interrupt on a port
|
4758 |
|
|
* that is closed. This can happen on hangups - since they completely
|
4759 |
|
|
* shutdown a port not in user context. Need to handle this case.
|
4760 |
|
|
*/
|
4761 |
|
|
|
4762 |
|
|
static void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
|
4763 |
|
|
{
|
4764 |
|
|
struct tty_struct *tty;
|
4765 |
|
|
unsigned int len, buflen, ioaddr;
|
4766 |
|
|
|
4767 |
|
|
#if DEBUG
|
4768 |
|
|
printk("stl_sc26198rxisr(portp=%x,iack=%x)\n", (int) portp, iack);
|
4769 |
|
|
#endif
|
4770 |
|
|
|
4771 |
|
|
tty = portp->tty;
|
4772 |
|
|
ioaddr = portp->ioaddr;
|
4773 |
|
|
outb(GIBCR, (ioaddr + XP_ADDR));
|
4774 |
|
|
len = inb(ioaddr + XP_DATA) + 1;
|
4775 |
|
|
|
4776 |
|
|
if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
|
4777 |
|
|
if ((tty == (struct tty_struct *) NULL) ||
|
4778 |
|
|
(tty->flip.char_buf_ptr == (char *) NULL) ||
|
4779 |
|
|
((buflen = TTY_FLIPBUF_SIZE - tty->flip.count) == 0)) {
|
4780 |
|
|
outb(GRXFIFO, (ioaddr + XP_ADDR));
|
4781 |
|
|
insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
|
4782 |
|
|
portp->stats.rxlost += len;
|
4783 |
|
|
portp->stats.rxtotal += len;
|
4784 |
|
|
} else {
|
4785 |
|
|
len = MIN(len, buflen);
|
4786 |
|
|
if (len > 0) {
|
4787 |
|
|
outb(GRXFIFO, (ioaddr + XP_ADDR));
|
4788 |
|
|
insb((ioaddr + XP_DATA), tty->flip.char_buf_ptr, len);
|
4789 |
|
|
memset(tty->flip.flag_buf_ptr, 0, len);
|
4790 |
|
|
tty->flip.flag_buf_ptr += len;
|
4791 |
|
|
tty->flip.char_buf_ptr += len;
|
4792 |
|
|
tty->flip.count += len;
|
4793 |
|
|
tty_schedule_flip(tty);
|
4794 |
|
|
portp->stats.rxtotal += len;
|
4795 |
|
|
}
|
4796 |
|
|
}
|
4797 |
|
|
} else {
|
4798 |
|
|
stl_sc26198rxbadchars(portp);
|
4799 |
|
|
}
|
4800 |
|
|
|
4801 |
|
|
/*
|
4802 |
|
|
* If we are TX flow controlled and in IXANY mode then we may need
|
4803 |
|
|
* to unflow control here. We gotta do this because of the automatic
|
4804 |
|
|
* flow control modes of the sc26198.
|
4805 |
|
|
*/
|
4806 |
|
|
if (test_bit(ASYI_TXFLOWED, &portp->istate)) {
|
4807 |
|
|
if ((tty != (struct tty_struct *) NULL) &&
|
4808 |
|
|
(tty->termios != (struct termios *) NULL) &&
|
4809 |
|
|
(tty->termios->c_iflag & IXANY)) {
|
4810 |
|
|
stl_sc26198txunflow(portp, tty);
|
4811 |
|
|
}
|
4812 |
|
|
}
|
4813 |
|
|
}
|
4814 |
|
|
|
4815 |
|
|
/*****************************************************************************/
|
4816 |
|
|
|
4817 |
|
|
/*
|
4818 |
|
|
* Process an RX bad character.
|
4819 |
|
|
*/
|
4820 |
|
|
|
4821 |
|
|
static void inline stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch)
|
4822 |
|
|
{
|
4823 |
|
|
struct tty_struct *tty;
|
4824 |
|
|
unsigned int ioaddr;
|
4825 |
|
|
|
4826 |
|
|
tty = portp->tty;
|
4827 |
|
|
ioaddr = portp->ioaddr;
|
4828 |
|
|
|
4829 |
|
|
if (status & SR_RXPARITY)
|
4830 |
|
|
portp->stats.rxparity++;
|
4831 |
|
|
if (status & SR_RXFRAMING)
|
4832 |
|
|
portp->stats.rxframing++;
|
4833 |
|
|
if (status & SR_RXOVERRUN)
|
4834 |
|
|
portp->stats.rxoverrun++;
|
4835 |
|
|
if (status & SR_RXBREAK)
|
4836 |
|
|
portp->stats.rxbreaks++;
|
4837 |
|
|
|
4838 |
|
|
if ((tty != (struct tty_struct *) NULL) &&
|
4839 |
|
|
((portp->rxignoremsk & status) == 0)) {
|
4840 |
|
|
if (portp->rxmarkmsk & status) {
|
4841 |
|
|
if (status & SR_RXBREAK) {
|
4842 |
|
|
status = TTY_BREAK;
|
4843 |
|
|
if (portp->flags & ASYNC_SAK) {
|
4844 |
|
|
do_SAK(tty);
|
4845 |
|
|
BRDENABLE(portp->brdnr, portp->pagenr);
|
4846 |
|
|
}
|
4847 |
|
|
} else if (status & SR_RXPARITY) {
|
4848 |
|
|
status = TTY_PARITY;
|
4849 |
|
|
} else if (status & SR_RXFRAMING) {
|
4850 |
|
|
status = TTY_FRAME;
|
4851 |
|
|
} else if(status & SR_RXOVERRUN) {
|
4852 |
|
|
status = TTY_OVERRUN;
|
4853 |
|
|
} else {
|
4854 |
|
|
status = 0;
|
4855 |
|
|
}
|
4856 |
|
|
} else {
|
4857 |
|
|
status = 0;
|
4858 |
|
|
}
|
4859 |
|
|
|
4860 |
|
|
if (tty->flip.char_buf_ptr != (char *) NULL) {
|
4861 |
|
|
if (tty->flip.count < TTY_FLIPBUF_SIZE) {
|
4862 |
|
|
*tty->flip.flag_buf_ptr++ = status;
|
4863 |
|
|
*tty->flip.char_buf_ptr++ = ch;
|
4864 |
|
|
tty->flip.count++;
|
4865 |
|
|
}
|
4866 |
|
|
tty_schedule_flip(tty);
|
4867 |
|
|
}
|
4868 |
|
|
|
4869 |
|
|
if (status == 0)
|
4870 |
|
|
portp->stats.rxtotal++;
|
4871 |
|
|
}
|
4872 |
|
|
}
|
4873 |
|
|
|
4874 |
|
|
/*****************************************************************************/
|
4875 |
|
|
|
4876 |
|
|
/*
|
4877 |
|
|
* Process all characters in the RX FIFO of the UART. Check all char
|
4878 |
|
|
* status bytes as well, and process as required. We need to check
|
4879 |
|
|
* all bytes in the FIFO, in case some more enter the FIFO while we
|
4880 |
|
|
* are here. To get the exact character error type we need to switch
|
4881 |
|
|
* into CHAR error mode (that is why we need to make sure we empty
|
4882 |
|
|
* the FIFO).
|
4883 |
|
|
*/
|
4884 |
|
|
|
4885 |
|
|
static void stl_sc26198rxbadchars(stlport_t *portp)
|
4886 |
|
|
{
|
4887 |
|
|
unsigned char status, mr1;
|
4888 |
|
|
char ch;
|
4889 |
|
|
|
4890 |
|
|
/*
|
4891 |
|
|
* To get the precise error type for each character we must switch
|
4892 |
|
|
* back into CHAR error mode.
|
4893 |
|
|
*/
|
4894 |
|
|
mr1 = stl_sc26198getreg(portp, MR1);
|
4895 |
|
|
stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
|
4896 |
|
|
|
4897 |
|
|
while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
|
4898 |
|
|
stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
|
4899 |
|
|
ch = stl_sc26198getreg(portp, RXFIFO);
|
4900 |
|
|
stl_sc26198rxbadch(portp, status, ch);
|
4901 |
|
|
}
|
4902 |
|
|
|
4903 |
|
|
/*
|
4904 |
|
|
* To get correct interrupt class we must switch back into BLOCK
|
4905 |
|
|
* error mode.
|
4906 |
|
|
*/
|
4907 |
|
|
stl_sc26198setreg(portp, MR1, mr1);
|
4908 |
|
|
}
|
4909 |
|
|
|
4910 |
|
|
/*****************************************************************************/
|
4911 |
|
|
|
4912 |
|
|
/*
|
4913 |
|
|
* Other interrupt handler. This includes modem signals, flow
|
4914 |
|
|
* control actions, etc. Most stuff is left to off-level interrupt
|
4915 |
|
|
* processing time.
|
4916 |
|
|
*/
|
4917 |
|
|
|
4918 |
|
|
static void stl_sc26198otherisr(stlport_t *portp, unsigned int iack)
|
4919 |
|
|
{
|
4920 |
|
|
unsigned char cir, ipr, xisr;
|
4921 |
|
|
|
4922 |
|
|
#if DEBUG
|
4923 |
|
|
printk("stl_sc26198otherisr(portp=%x,iack=%x)\n", (int) portp, iack);
|
4924 |
|
|
#endif
|
4925 |
|
|
|
4926 |
|
|
cir = stl_sc26198getglobreg(portp, CIR);
|
4927 |
|
|
|
4928 |
|
|
switch (cir & CIR_SUBTYPEMASK) {
|
4929 |
|
|
case CIR_SUBCOS:
|
4930 |
|
|
ipr = stl_sc26198getreg(portp, IPR);
|
4931 |
|
|
if (ipr & IPR_DCDCHANGE) {
|
4932 |
|
|
set_bit(ASYI_DCDCHANGE, &portp->istate);
|
4933 |
|
|
queue_task_irq_off(&portp->tqueue, &tq_scheduler);
|
4934 |
|
|
portp->stats.modem++;
|
4935 |
|
|
}
|
4936 |
|
|
break;
|
4937 |
|
|
case CIR_SUBXONXOFF:
|
4938 |
|
|
xisr = stl_sc26198getreg(portp, XISR);
|
4939 |
|
|
if (xisr & XISR_RXXONGOT) {
|
4940 |
|
|
set_bit(ASYI_TXFLOWED, &portp->istate);
|
4941 |
|
|
portp->stats.txxoff++;
|
4942 |
|
|
}
|
4943 |
|
|
if (xisr & XISR_RXXOFFGOT) {
|
4944 |
|
|
clear_bit(ASYI_TXFLOWED, &portp->istate);
|
4945 |
|
|
portp->stats.txxon++;
|
4946 |
|
|
}
|
4947 |
|
|
break;
|
4948 |
|
|
case CIR_SUBBREAK:
|
4949 |
|
|
stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
|
4950 |
|
|
stl_sc26198rxbadchars(portp);
|
4951 |
|
|
break;
|
4952 |
|
|
default:
|
4953 |
|
|
break;
|
4954 |
|
|
}
|
4955 |
|
|
}
|
4956 |
|
|
|
4957 |
|
|
/*****************************************************************************/
|