blob: 6ad0bbf56c777b71c336e1281962ac09980995b7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*****************************************************************************/
2
3/*
4 * istallion.c -- stallion intelligent multiport serial driver.
5 *
6 * Copyright (C) 1996-1999 Stallion Technologies
7 * Copyright (C) 1994-1996 Greg Ungerer.
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 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
18
19/*****************************************************************************/
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
22#include <linux/slab.h>
23#include <linux/interrupt.h>
24#include <linux/tty.h>
25#include <linux/tty_flip.h>
26#include <linux/serial.h>
27#include <linux/cdk.h>
28#include <linux/comstats.h>
29#include <linux/istallion.h>
30#include <linux/ioport.h>
31#include <linux/delay.h>
32#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/device.h>
34#include <linux/wait.h>
Alan Cox4ac43602006-06-28 04:26:52 -070035#include <linux/eisa.h>
Jiri Slabya3f8d9d2006-12-08 02:39:18 -080036#include <linux/ctype.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38#include <asm/io.h>
39#include <asm/uaccess.h>
40
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43/*****************************************************************************/
44
45/*
46 * Define different board types. Not all of the following board types
47 * are supported by this driver. But I will use the standard "assigned"
48 * board numbers. Currently supported boards are abbreviated as:
49 * ECP = EasyConnection 8/64, ONB = ONboard, BBY = Brumby and
50 * STAL = Stallion.
51 */
52#define BRD_UNKNOWN 0
53#define BRD_STALLION 1
54#define BRD_BRUMBY4 2
55#define BRD_ONBOARD2 3
56#define BRD_ONBOARD 4
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#define BRD_ONBOARDE 7
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#define BRD_ECP 23
59#define BRD_ECPE 24
60#define BRD_ECPMC 25
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#define BRD_ECPPCI 29
62
63#define BRD_BRUMBY BRD_BRUMBY4
64
65/*
66 * Define a configuration structure to hold the board configuration.
67 * Need to set this up in the code (for now) with the boards that are
68 * to be configured into the system. This is what needs to be modified
69 * when adding/removing/modifying boards. Each line entry in the
70 * stli_brdconf[] array is a board. Each line contains io/irq/memory
71 * ranges for that board (as well as what type of board it is).
72 * Some examples:
73 * { BRD_ECP, 0x2a0, 0, 0xcc000, 0, 0 },
74 * This line will configure an EasyConnection 8/64 at io address 2a0,
75 * and shared memory address of cc000. Multiple EasyConnection 8/64
76 * boards can share the same shared memory address space. No interrupt
77 * is required for this board type.
78 * Another example:
79 * { BRD_ECPE, 0x5000, 0, 0x80000000, 0, 0 },
80 * This line will configure an EasyConnection 8/64 EISA in slot 5 and
81 * shared memory address of 0x80000000 (2 GByte). Multiple
82 * EasyConnection 8/64 EISA boards can share the same shared memory
83 * address space. No interrupt is required for this board type.
84 * Another example:
85 * { BRD_ONBOARD, 0x240, 0, 0xd0000, 0, 0 },
86 * This line will configure an ONboard (ISA type) at io address 240,
87 * and shared memory address of d0000. Multiple ONboards can share
88 * the same shared memory address space. No interrupt required.
89 * Another example:
90 * { BRD_BRUMBY4, 0x360, 0, 0xc8000, 0, 0 },
91 * This line will configure a Brumby board (any number of ports!) at
92 * io address 360 and shared memory address of c8000. All Brumby boards
93 * configured into a system must have their own separate io and memory
94 * addresses. No interrupt is required.
95 * Another example:
96 * { BRD_STALLION, 0x330, 0, 0xd0000, 0, 0 },
97 * This line will configure an original Stallion board at io address 330
98 * and shared memory address d0000 (this would only be valid for a "V4.0"
99 * or Rev.O Stallion board). All Stallion boards configured into the
100 * system must have their own separate io and memory addresses. No
101 * interrupt is required.
102 */
103
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800104struct stlconf {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 int brdtype;
106 int ioaddr1;
107 int ioaddr2;
108 unsigned long memaddr;
109 int irq;
110 int irqtype;
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800111};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Jiri Slaby1328d732006-12-08 02:39:19 -0800113static unsigned int stli_nrbrds;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Alan Cox4ac43602006-06-28 04:26:52 -0700115/* stli_lock must NOT be taken holding brd_lock */
116static spinlock_t stli_lock; /* TTY logic lock */
117static spinlock_t brd_lock; /* Board logic lock */
118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119/*
120 * There is some experimental EISA board detection code in this driver.
121 * By default it is disabled, but for those that want to try it out,
122 * then set the define below to be 1.
123 */
124#define STLI_EISAPROBE 0
125
126/*****************************************************************************/
127
128/*
129 * Define some important driver characteristics. Device major numbers
130 * allocated as per Linux Device Registry.
131 */
132#ifndef STL_SIOMEMMAJOR
133#define STL_SIOMEMMAJOR 28
134#endif
135#ifndef STL_SERIALMAJOR
136#define STL_SERIALMAJOR 24
137#endif
138#ifndef STL_CALLOUTMAJOR
139#define STL_CALLOUTMAJOR 25
140#endif
141
142/*****************************************************************************/
143
144/*
145 * Define our local driver identity first. Set up stuff to deal with
146 * all the local structures required by a serial tty driver.
147 */
148static char *stli_drvtitle = "Stallion Intelligent Multiport Serial Driver";
149static char *stli_drvname = "istallion";
150static char *stli_drvversion = "5.6.0";
151static char *stli_serialname = "ttyE";
152
153static struct tty_driver *stli_serial;
154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
156#define STLI_TXBUFSIZE 4096
157
158/*
159 * Use a fast local buffer for cooked characters. Typically a whole
160 * bunch of cooked characters come in for a port, 1 at a time. So we
161 * save those up into a local buffer, then write out the whole lot
162 * with a large memcpy. Just use 1 buffer for all ports, since its
163 * use it is only need for short periods of time by each port.
164 */
165static char *stli_txcookbuf;
166static int stli_txcooksize;
167static int stli_txcookrealsize;
168static struct tty_struct *stli_txcooktty;
169
170/*
171 * Define a local default termios struct. All ports will be created
172 * with this termios initially. Basically all it defines is a raw port
173 * at 9600 baud, 8 data bits, no parity, 1 stop bit.
174 */
Alan Cox606d0992006-12-08 02:38:45 -0800175static struct ktermios stli_deftermios = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
177 .c_cc = INIT_C_CC,
Alan Cox606d0992006-12-08 02:38:45 -0800178 .c_ispeed = 9600,
179 .c_ospeed = 9600,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180};
181
182/*
183 * Define global stats structures. Not used often, and can be
184 * re-used for each stats call.
185 */
186static comstats_t stli_comstats;
187static combrd_t stli_brdstats;
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800188static struct asystats stli_cdkstats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
190/*****************************************************************************/
191
Jiri Slabyb103b5c2006-12-08 02:39:21 -0800192static DEFINE_MUTEX(stli_brdslock);
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800193static struct stlibrd *stli_brds[STL_MAXBRDS];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
195static int stli_shared;
196
197/*
198 * Per board state flags. Used with the state field of the board struct.
199 * Not really much here... All we need to do is keep track of whether
200 * the board has been detected, and whether it is actually running a slave
201 * or not.
202 */
203#define BST_FOUND 0x1
204#define BST_STARTED 0x2
Jiri Slaby39014172006-12-08 02:39:22 -0800205#define BST_PROBED 0x4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
207/*
208 * Define the set of port state flags. These are marked for internal
209 * state purposes only, usually to do with the state of communications
210 * with the slave. Most of them need to be updated atomically, so always
211 * use the bit setting operations (unless protected by cli/sti).
212 */
213#define ST_INITIALIZING 1
214#define ST_OPENING 2
215#define ST_CLOSING 3
216#define ST_CMDING 4
217#define ST_TXBUSY 5
218#define ST_RXING 6
219#define ST_DOFLUSHRX 7
220#define ST_DOFLUSHTX 8
221#define ST_DOSIGS 9
222#define ST_RXSTOP 10
223#define ST_GETSIGS 11
224
225/*
226 * Define an array of board names as printable strings. Handy for
227 * referencing boards when printing trace and stuff.
228 */
229static char *stli_brdnames[] = {
230 "Unknown",
231 "Stallion",
232 "Brumby",
233 "ONboard-MC",
234 "ONboard",
235 "Brumby",
236 "Brumby",
237 "ONboard-EI",
Jiri Slabya3f8d9d2006-12-08 02:39:18 -0800238 NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 "ONboard",
240 "ONboard-MC",
241 "ONboard-MC",
Jiri Slabya3f8d9d2006-12-08 02:39:18 -0800242 NULL,
243 NULL,
244 NULL,
245 NULL,
246 NULL,
247 NULL,
248 NULL,
249 NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 "EasyIO",
251 "EC8/32-AT",
252 "EC8/32-MC",
253 "EC8/64-AT",
254 "EC8/64-EI",
255 "EC8/64-MC",
256 "EC8/32-PCI",
257 "EC8/64-PCI",
258 "EasyIO-PCI",
259 "EC/RA-PCI",
260};
261
262/*****************************************************************************/
263
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264/*
265 * Define some string labels for arguments passed from the module
266 * load line. These allow for easy board definitions, and easy
267 * modification of the io, memory and irq resoucres.
268 */
269
270static char *board0[8];
271static char *board1[8];
272static char *board2[8];
273static char *board3[8];
274
275static char **stli_brdsp[] = {
276 (char **) &board0,
277 (char **) &board1,
278 (char **) &board2,
279 (char **) &board3
280};
281
282/*
283 * Define a set of common board names, and types. This is used to
284 * parse any module arguments.
285 */
286
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800287static struct stlibrdtype {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 char *name;
289 int type;
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800290} stli_brdstr[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 { "stallion", BRD_STALLION },
292 { "1", BRD_STALLION },
293 { "brumby", BRD_BRUMBY },
294 { "brumby4", BRD_BRUMBY },
295 { "brumby/4", BRD_BRUMBY },
296 { "brumby-4", BRD_BRUMBY },
297 { "brumby8", BRD_BRUMBY },
298 { "brumby/8", BRD_BRUMBY },
299 { "brumby-8", BRD_BRUMBY },
300 { "brumby16", BRD_BRUMBY },
301 { "brumby/16", BRD_BRUMBY },
302 { "brumby-16", BRD_BRUMBY },
303 { "2", BRD_BRUMBY },
304 { "onboard2", BRD_ONBOARD2 },
305 { "onboard-2", BRD_ONBOARD2 },
306 { "onboard/2", BRD_ONBOARD2 },
307 { "onboard-mc", BRD_ONBOARD2 },
308 { "onboard/mc", BRD_ONBOARD2 },
309 { "onboard-mca", BRD_ONBOARD2 },
310 { "onboard/mca", BRD_ONBOARD2 },
311 { "3", BRD_ONBOARD2 },
312 { "onboard", BRD_ONBOARD },
313 { "onboardat", BRD_ONBOARD },
314 { "4", BRD_ONBOARD },
315 { "onboarde", BRD_ONBOARDE },
316 { "onboard-e", BRD_ONBOARDE },
317 { "onboard/e", BRD_ONBOARDE },
318 { "onboard-ei", BRD_ONBOARDE },
319 { "onboard/ei", BRD_ONBOARDE },
320 { "7", BRD_ONBOARDE },
321 { "ecp", BRD_ECP },
322 { "ecpat", BRD_ECP },
323 { "ec8/64", BRD_ECP },
324 { "ec8/64-at", BRD_ECP },
325 { "ec8/64-isa", BRD_ECP },
326 { "23", BRD_ECP },
327 { "ecpe", BRD_ECPE },
328 { "ecpei", BRD_ECPE },
329 { "ec8/64-e", BRD_ECPE },
330 { "ec8/64-ei", BRD_ECPE },
331 { "24", BRD_ECPE },
332 { "ecpmc", BRD_ECPMC },
333 { "ec8/64-mc", BRD_ECPMC },
334 { "ec8/64-mca", BRD_ECPMC },
335 { "25", BRD_ECPMC },
336 { "ecppci", BRD_ECPPCI },
337 { "ec/ra", BRD_ECPPCI },
338 { "ec/ra-pc", BRD_ECPPCI },
339 { "ec/ra-pci", BRD_ECPPCI },
340 { "29", BRD_ECPPCI },
341};
342
343/*
344 * Define the module agruments.
345 */
346MODULE_AUTHOR("Greg Ungerer");
347MODULE_DESCRIPTION("Stallion Intelligent Multiport Serial Driver");
348MODULE_LICENSE("GPL");
349
350
Rusty Russell8d3b33f2006-03-25 03:07:05 -0800351module_param_array(board0, charp, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,memaddr]");
Rusty Russell8d3b33f2006-03-25 03:07:05 -0800353module_param_array(board1, charp, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,memaddr]");
Rusty Russell8d3b33f2006-03-25 03:07:05 -0800355module_param_array(board2, charp, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,memaddr]");
Rusty Russell8d3b33f2006-03-25 03:07:05 -0800357module_param_array(board3, charp, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,memaddr]");
359
Jiri Slabya00f33f2006-12-08 02:39:20 -0800360#if STLI_EISAPROBE != 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361/*
362 * Set up a default memory address table for EISA board probing.
363 * The default addresses are all bellow 1Mbyte, which has to be the
364 * case anyway. They should be safe, since we only read values from
365 * them, and interrupts are disabled while we do it. If the higher
366 * memory support is compiled in then we also try probing around
367 * the 1Gb, 2Gb and 3Gb areas as well...
368 */
369static unsigned long stli_eisamemprobeaddrs[] = {
370 0xc0000, 0xd0000, 0xe0000, 0xf0000,
371 0x80000000, 0x80010000, 0x80020000, 0x80030000,
372 0x40000000, 0x40010000, 0x40020000, 0x40030000,
373 0xc0000000, 0xc0010000, 0xc0020000, 0xc0030000,
374 0xff000000, 0xff010000, 0xff020000, 0xff030000,
375};
376
Tobias Klauserfe971072006-01-09 20:54:02 -0800377static int stli_eisamempsize = ARRAY_SIZE(stli_eisamemprobeaddrs);
Jiri Slabya00f33f2006-12-08 02:39:20 -0800378#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379
380/*
381 * Define the Stallion PCI vendor and device IDs.
382 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383#ifndef PCI_DEVICE_ID_ECRA
384#define PCI_DEVICE_ID_ECRA 0x0004
385#endif
386
387static struct pci_device_id istallion_pci_tbl[] = {
Alan Cox4ac43602006-06-28 04:26:52 -0700388 { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECRA), },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 { 0 }
390};
391MODULE_DEVICE_TABLE(pci, istallion_pci_tbl);
392
Jiri Slaby845bead2006-12-08 02:39:17 -0800393static struct pci_driver stli_pcidriver;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
395/*****************************************************************************/
396
397/*
398 * Hardware configuration info for ECP boards. These defines apply
399 * to the directly accessible io ports of the ECP. There is a set of
400 * defines for each ECP board type, ISA, EISA, MCA and PCI.
401 */
402#define ECP_IOSIZE 4
403
404#define ECP_MEMSIZE (128 * 1024)
405#define ECP_PCIMEMSIZE (256 * 1024)
406
407#define ECP_ATPAGESIZE (4 * 1024)
408#define ECP_MCPAGESIZE (4 * 1024)
409#define ECP_EIPAGESIZE (64 * 1024)
410#define ECP_PCIPAGESIZE (64 * 1024)
411
412#define STL_EISAID 0x8c4e
413
414/*
415 * Important defines for the ISA class of ECP board.
416 */
417#define ECP_ATIREG 0
418#define ECP_ATCONFR 1
419#define ECP_ATMEMAR 2
420#define ECP_ATMEMPR 3
421#define ECP_ATSTOP 0x1
422#define ECP_ATINTENAB 0x10
423#define ECP_ATENABLE 0x20
424#define ECP_ATDISABLE 0x00
425#define ECP_ATADDRMASK 0x3f000
426#define ECP_ATADDRSHFT 12
427
428/*
429 * Important defines for the EISA class of ECP board.
430 */
431#define ECP_EIIREG 0
432#define ECP_EIMEMARL 1
433#define ECP_EICONFR 2
434#define ECP_EIMEMARH 3
435#define ECP_EIENABLE 0x1
436#define ECP_EIDISABLE 0x0
437#define ECP_EISTOP 0x4
438#define ECP_EIEDGE 0x00
439#define ECP_EILEVEL 0x80
440#define ECP_EIADDRMASKL 0x00ff0000
441#define ECP_EIADDRSHFTL 16
442#define ECP_EIADDRMASKH 0xff000000
443#define ECP_EIADDRSHFTH 24
444#define ECP_EIBRDENAB 0xc84
445
446#define ECP_EISAID 0x4
447
448/*
449 * Important defines for the Micro-channel class of ECP board.
450 * (It has a lot in common with the ISA boards.)
451 */
452#define ECP_MCIREG 0
453#define ECP_MCCONFR 1
454#define ECP_MCSTOP 0x20
455#define ECP_MCENABLE 0x80
456#define ECP_MCDISABLE 0x00
457
458/*
459 * Important defines for the PCI class of ECP board.
460 * (It has a lot in common with the other ECP boards.)
461 */
462#define ECP_PCIIREG 0
463#define ECP_PCICONFR 1
464#define ECP_PCISTOP 0x01
465
466/*
467 * Hardware configuration info for ONboard and Brumby boards. These
468 * defines apply to the directly accessible io ports of these boards.
469 */
470#define ONB_IOSIZE 16
471#define ONB_MEMSIZE (64 * 1024)
472#define ONB_ATPAGESIZE (64 * 1024)
473#define ONB_MCPAGESIZE (64 * 1024)
474#define ONB_EIMEMSIZE (128 * 1024)
475#define ONB_EIPAGESIZE (64 * 1024)
476
477/*
478 * Important defines for the ISA class of ONboard board.
479 */
480#define ONB_ATIREG 0
481#define ONB_ATMEMAR 1
482#define ONB_ATCONFR 2
483#define ONB_ATSTOP 0x4
484#define ONB_ATENABLE 0x01
485#define ONB_ATDISABLE 0x00
486#define ONB_ATADDRMASK 0xff0000
487#define ONB_ATADDRSHFT 16
488
489#define ONB_MEMENABLO 0
490#define ONB_MEMENABHI 0x02
491
492/*
493 * Important defines for the EISA class of ONboard board.
494 */
495#define ONB_EIIREG 0
496#define ONB_EIMEMARL 1
497#define ONB_EICONFR 2
498#define ONB_EIMEMARH 3
499#define ONB_EIENABLE 0x1
500#define ONB_EIDISABLE 0x0
501#define ONB_EISTOP 0x4
502#define ONB_EIEDGE 0x00
503#define ONB_EILEVEL 0x80
504#define ONB_EIADDRMASKL 0x00ff0000
505#define ONB_EIADDRSHFTL 16
506#define ONB_EIADDRMASKH 0xff000000
507#define ONB_EIADDRSHFTH 24
508#define ONB_EIBRDENAB 0xc84
509
510#define ONB_EISAID 0x1
511
512/*
513 * Important defines for the Brumby boards. They are pretty simple,
514 * there is not much that is programmably configurable.
515 */
516#define BBY_IOSIZE 16
517#define BBY_MEMSIZE (64 * 1024)
518#define BBY_PAGESIZE (16 * 1024)
519
520#define BBY_ATIREG 0
521#define BBY_ATCONFR 1
522#define BBY_ATSTOP 0x4
523
524/*
525 * Important defines for the Stallion boards. They are pretty simple,
526 * there is not much that is programmably configurable.
527 */
528#define STAL_IOSIZE 16
529#define STAL_MEMSIZE (64 * 1024)
530#define STAL_PAGESIZE (64 * 1024)
531
532/*
533 * Define the set of status register values for EasyConnection panels.
534 * The signature will return with the status value for each panel. From
535 * this we can determine what is attached to the board - before we have
536 * actually down loaded any code to it.
537 */
538#define ECH_PNLSTATUS 2
539#define ECH_PNL16PORT 0x20
540#define ECH_PNLIDMASK 0x07
541#define ECH_PNLXPID 0x40
542#define ECH_PNLINTRPEND 0x80
543
544/*
545 * Define some macros to do things to the board. Even those these boards
546 * are somewhat related there is often significantly different ways of
547 * doing some operation on it (like enable, paging, reset, etc). So each
548 * board class has a set of functions which do the commonly required
549 * operations. The macros below basically just call these functions,
550 * generally checking for a NULL function - which means that the board
551 * needs nothing done to it to achieve this operation!
552 */
553#define EBRDINIT(brdp) \
554 if (brdp->init != NULL) \
555 (* brdp->init)(brdp)
556
557#define EBRDENABLE(brdp) \
558 if (brdp->enable != NULL) \
559 (* brdp->enable)(brdp);
560
561#define EBRDDISABLE(brdp) \
562 if (brdp->disable != NULL) \
563 (* brdp->disable)(brdp);
564
565#define EBRDINTR(brdp) \
566 if (brdp->intr != NULL) \
567 (* brdp->intr)(brdp);
568
569#define EBRDRESET(brdp) \
570 if (brdp->reset != NULL) \
571 (* brdp->reset)(brdp);
572
573#define EBRDGETMEMPTR(brdp,offset) \
574 (* brdp->getmemptr)(brdp, offset, __LINE__)
575
576/*
577 * Define the maximal baud rate, and the default baud base for ports.
578 */
579#define STL_MAXBAUD 460800
580#define STL_BAUDBASE 115200
581#define STL_CLOSEDELAY (5 * HZ / 10)
582
583/*****************************************************************************/
584
585/*
586 * Define macros to extract a brd or port number from a minor number.
587 */
588#define MINOR2BRD(min) (((min) & 0xc0) >> 6)
589#define MINOR2PORT(min) ((min) & 0x3f)
590
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591/*****************************************************************************/
592
593/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 * Prototype all functions in this driver!
595 */
596
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800597static int stli_parsebrd(struct stlconf *confp, char **argp);
Adrian Bunk672b2712006-06-30 01:55:30 -0700598static int stli_init(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599static int stli_open(struct tty_struct *tty, struct file *filp);
600static void stli_close(struct tty_struct *tty, struct file *filp);
601static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count);
602static void stli_putchar(struct tty_struct *tty, unsigned char ch);
603static void stli_flushchars(struct tty_struct *tty);
604static int stli_writeroom(struct tty_struct *tty);
605static int stli_charsinbuffer(struct tty_struct *tty);
606static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
Alan Cox606d0992006-12-08 02:38:45 -0800607static void stli_settermios(struct tty_struct *tty, struct ktermios *old);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608static void stli_throttle(struct tty_struct *tty);
609static void stli_unthrottle(struct tty_struct *tty);
610static void stli_stop(struct tty_struct *tty);
611static void stli_start(struct tty_struct *tty);
612static void stli_flushbuffer(struct tty_struct *tty);
613static void stli_breakctl(struct tty_struct *tty, int state);
614static void stli_waituntilsent(struct tty_struct *tty, int timeout);
615static void stli_sendxchar(struct tty_struct *tty, char ch);
616static void stli_hangup(struct tty_struct *tty);
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800617static int stli_portinfo(struct stlibrd *brdp, struct stliport *portp, int portnr, char *pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800619static int stli_brdinit(struct stlibrd *brdp);
620static int stli_startbrd(struct stlibrd *brdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp);
622static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp);
623static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800624static void stli_brdpoll(struct stlibrd *brdp, cdkhdr_t __iomem *hdrp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625static void stli_poll(unsigned long arg);
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800626static int stli_hostcmd(struct stlibrd *brdp, struct stliport *portp);
627static int stli_initopen(struct stlibrd *brdp, struct stliport *portp);
628static int stli_rawopen(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait);
629static int stli_rawclose(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait);
630static int stli_waitcarrier(struct stlibrd *brdp, struct stliport *portp, struct file *filp);
Al Viro3e577a82006-12-06 18:41:45 +0000631static void stli_dohangup(struct work_struct *);
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800632static int stli_setport(struct stliport *portp);
633static int stli_cmdwait(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback);
634static void stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback);
635static void __stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback);
636static void stli_dodelaycmd(struct stliport *portp, cdkctrl_t __iomem *cp);
637static void stli_mkasyport(struct stliport *portp, asyport_t *pp, struct ktermios *tiosp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts);
639static long stli_mktiocm(unsigned long sigvalue);
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800640static void stli_read(struct stlibrd *brdp, struct stliport *portp);
641static int stli_getserial(struct stliport *portp, struct serial_struct __user *sp);
642static int stli_setserial(struct stliport *portp, struct serial_struct __user *sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643static int stli_getbrdstats(combrd_t __user *bp);
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800644static int stli_getportstats(struct stliport *portp, comstats_t __user *cp);
645static int stli_portcmdstats(struct stliport *portp);
646static int stli_clrportstats(struct stliport *portp, comstats_t __user *cp);
647static int stli_getportstruct(struct stliport __user *arg);
648static int stli_getbrdstruct(struct stlibrd __user *arg);
649static struct stlibrd *stli_allocbrd(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800651static void stli_ecpinit(struct stlibrd *brdp);
652static void stli_ecpenable(struct stlibrd *brdp);
653static void stli_ecpdisable(struct stlibrd *brdp);
654static void __iomem *stli_ecpgetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
655static void stli_ecpreset(struct stlibrd *brdp);
656static void stli_ecpintr(struct stlibrd *brdp);
657static void stli_ecpeiinit(struct stlibrd *brdp);
658static void stli_ecpeienable(struct stlibrd *brdp);
659static void stli_ecpeidisable(struct stlibrd *brdp);
660static void __iomem *stli_ecpeigetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
661static void stli_ecpeireset(struct stlibrd *brdp);
662static void stli_ecpmcenable(struct stlibrd *brdp);
663static void stli_ecpmcdisable(struct stlibrd *brdp);
664static void __iomem *stli_ecpmcgetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
665static void stli_ecpmcreset(struct stlibrd *brdp);
666static void stli_ecppciinit(struct stlibrd *brdp);
667static void __iomem *stli_ecppcigetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
668static void stli_ecppcireset(struct stlibrd *brdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800670static void stli_onbinit(struct stlibrd *brdp);
671static void stli_onbenable(struct stlibrd *brdp);
672static void stli_onbdisable(struct stlibrd *brdp);
673static void __iomem *stli_onbgetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
674static void stli_onbreset(struct stlibrd *brdp);
675static void stli_onbeinit(struct stlibrd *brdp);
676static void stli_onbeenable(struct stlibrd *brdp);
677static void stli_onbedisable(struct stlibrd *brdp);
678static void __iomem *stli_onbegetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
679static void stli_onbereset(struct stlibrd *brdp);
680static void stli_bbyinit(struct stlibrd *brdp);
681static void __iomem *stli_bbygetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
682static void stli_bbyreset(struct stlibrd *brdp);
683static void stli_stalinit(struct stlibrd *brdp);
684static void __iomem *stli_stalgetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
685static void stli_stalreset(struct stlibrd *brdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686
Jiri Slaby1328d732006-12-08 02:39:19 -0800687static struct stliport *stli_getport(unsigned int brdnr, unsigned int panelnr, unsigned int portnr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800689static int stli_initecp(struct stlibrd *brdp);
690static int stli_initonb(struct stlibrd *brdp);
Jiri Slabya00f33f2006-12-08 02:39:20 -0800691#if STLI_EISAPROBE != 0
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800692static int stli_eisamemprobe(struct stlibrd *brdp);
Jiri Slabya00f33f2006-12-08 02:39:20 -0800693#endif
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800694static int stli_initports(struct stlibrd *brdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696/*****************************************************************************/
697
698/*
699 * Define the driver info for a user level shared memory device. This
700 * device will work sort of like the /dev/kmem device - except that it
701 * will give access to the shared memory on the Stallion intelligent
702 * board. This is also a very useful debugging tool.
703 */
Arjan van de Ven62322d22006-07-03 00:24:21 -0700704static const struct file_operations stli_fsiomem = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 .owner = THIS_MODULE,
706 .read = stli_memread,
707 .write = stli_memwrite,
708 .ioctl = stli_memioctl,
709};
710
711/*****************************************************************************/
712
713/*
714 * Define a timer_list entry for our poll routine. The slave board
715 * is polled every so often to see if anything needs doing. This is
716 * much cheaper on host cpu than using interrupts. It turns out to
717 * not increase character latency by much either...
718 */
Ingo Molnar8d06afa2005-09-09 13:10:40 -0700719static DEFINE_TIMER(stli_timerlist, stli_poll, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720
721static int stli_timeron;
722
723/*
724 * Define the calculation for the timeout routine.
725 */
726#define STLI_TIMEOUT (jiffies + 1)
727
728/*****************************************************************************/
729
gregkh@suse.deca8eca62005-03-23 09:53:09 -0800730static struct class *istallion_class;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800732static void stli_cleanup_ports(struct stlibrd *brdp)
Jiri Slaby845bead2006-12-08 02:39:17 -0800733{
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800734 struct stliport *portp;
Jiri Slaby845bead2006-12-08 02:39:17 -0800735 unsigned int j;
736
737 for (j = 0; j < STL_MAXPORTS; j++) {
738 portp = brdp->ports[j];
739 if (portp != NULL) {
740 if (portp->tty != NULL)
741 tty_hangup(portp->tty);
742 kfree(portp);
743 }
744 }
745}
746
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747/*
748 * Loadable module initialization stuff.
749 */
750
751static int __init istallion_module_init(void)
752{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 stli_init();
Alan Cox4ac43602006-06-28 04:26:52 -0700754 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755}
756
757/*****************************************************************************/
758
759static void __exit istallion_module_exit(void)
760{
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800761 struct stlibrd *brdp;
Jiri Slaby1328d732006-12-08 02:39:19 -0800762 unsigned int j;
Jiri Slaby845bead2006-12-08 02:39:17 -0800763 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 printk(KERN_INFO "Unloading %s: version %s\n", stli_drvtitle,
766 stli_drvversion);
767
Jiri Slaby845bead2006-12-08 02:39:17 -0800768 pci_unregister_driver(&stli_pcidriver);
Alan Cox4ac43602006-06-28 04:26:52 -0700769 /*
770 * Free up all allocated resources used by the ports. This includes
771 * memory and interrupts.
772 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 if (stli_timeron) {
774 stli_timeron = 0;
Alan Cox4ac43602006-06-28 04:26:52 -0700775 del_timer_sync(&stli_timerlist);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 }
777
778 i = tty_unregister_driver(stli_serial);
779 if (i) {
780 printk("STALLION: failed to un-register tty driver, "
781 "errno=%d\n", -i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 return;
783 }
784 put_tty_driver(stli_serial);
Jiri Slaby1328d732006-12-08 02:39:19 -0800785 for (j = 0; j < 4; j++)
786 class_device_destroy(istallion_class, MKDEV(STL_SIOMEMMAJOR, j));
gregkh@suse.deca8eca62005-03-23 09:53:09 -0800787 class_destroy(istallion_class);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
789 printk("STALLION: failed to un-register serial memory device, "
790 "errno=%d\n", -i);
Jesper Juhl735d5662005-11-07 01:01:29 -0800791
Jesper Juhl735d5662005-11-07 01:01:29 -0800792 kfree(stli_txcookbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
Jiri Slaby1328d732006-12-08 02:39:19 -0800794 for (j = 0; (j < stli_nrbrds); j++) {
Jiri Slaby39014172006-12-08 02:39:22 -0800795 if ((brdp = stli_brds[j]) == NULL || (brdp->state & BST_PROBED))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 continue;
Jiri Slaby845bead2006-12-08 02:39:17 -0800797
798 stli_cleanup_ports(brdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799
800 iounmap(brdp->membase);
801 if (brdp->iosize > 0)
802 release_region(brdp->iobase, brdp->iosize);
803 kfree(brdp);
Jiri Slaby1328d732006-12-08 02:39:19 -0800804 stli_brds[j] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806}
807
808module_init(istallion_module_init);
809module_exit(istallion_module_exit);
810
811/*****************************************************************************/
812
813/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 * Parse the supplied argument string, into the board conf struct.
815 */
816
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800817static int stli_parsebrd(struct stlconf *confp, char **argp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818{
Jiri Slaby1328d732006-12-08 02:39:19 -0800819 unsigned int i;
Alan Cox4ac43602006-06-28 04:26:52 -0700820 char *sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
Alan Cox4ac43602006-06-28 04:26:52 -0700822 if (argp[0] == NULL || *argp[0] == 0)
823 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824
825 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
Jiri Slabya3f8d9d2006-12-08 02:39:18 -0800826 *sp = tolower(*sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827
Tobias Klauserfe971072006-01-09 20:54:02 -0800828 for (i = 0; i < ARRAY_SIZE(stli_brdstr); i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 if (strcmp(stli_brdstr[i].name, argp[0]) == 0)
830 break;
831 }
Tobias Klauserfe971072006-01-09 20:54:02 -0800832 if (i == ARRAY_SIZE(stli_brdstr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 printk("STALLION: unknown board name, %s?\n", argp[0]);
Tobias Klauserfe971072006-01-09 20:54:02 -0800834 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 }
836
837 confp->brdtype = stli_brdstr[i].type;
Alan Cox4ac43602006-06-28 04:26:52 -0700838 if (argp[1] != NULL && *argp[1] != 0)
Jiri Slabya3f8d9d2006-12-08 02:39:18 -0800839 confp->ioaddr1 = simple_strtoul(argp[1], NULL, 0);
Alan Cox4ac43602006-06-28 04:26:52 -0700840 if (argp[2] != NULL && *argp[2] != 0)
Jiri Slabya3f8d9d2006-12-08 02:39:18 -0800841 confp->memaddr = simple_strtoul(argp[2], NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 return(1);
843}
844
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845/*****************************************************************************/
846
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847static int stli_open(struct tty_struct *tty, struct file *filp)
848{
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800849 struct stlibrd *brdp;
850 struct stliport *portp;
Jiri Slaby1328d732006-12-08 02:39:19 -0800851 unsigned int minordev, brdnr, portnr;
852 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
854 minordev = tty->index;
855 brdnr = MINOR2BRD(minordev);
856 if (brdnr >= stli_nrbrds)
Alan Cox4ac43602006-06-28 04:26:52 -0700857 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 brdp = stli_brds[brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -0700859 if (brdp == NULL)
860 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 if ((brdp->state & BST_STARTED) == 0)
Alan Cox4ac43602006-06-28 04:26:52 -0700862 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 portnr = MINOR2PORT(minordev);
Jiri Slaby1328d732006-12-08 02:39:19 -0800864 if (portnr > brdp->nrports)
Alan Cox4ac43602006-06-28 04:26:52 -0700865 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866
867 portp = brdp->ports[portnr];
Alan Cox4ac43602006-06-28 04:26:52 -0700868 if (portp == NULL)
869 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 if (portp->devnr < 1)
Alan Cox4ac43602006-06-28 04:26:52 -0700871 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872
873
874/*
875 * Check if this port is in the middle of closing. If so then wait
876 * until it is closed then return error status based on flag settings.
877 * The sleep here does not need interrupt protection since the wakeup
878 * for it is done with the same context.
879 */
880 if (portp->flags & ASYNC_CLOSING) {
881 interruptible_sleep_on(&portp->close_wait);
882 if (portp->flags & ASYNC_HUP_NOTIFY)
Alan Cox4ac43602006-06-28 04:26:52 -0700883 return -EAGAIN;
884 return -ERESTARTSYS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 }
886
887/*
888 * On the first open of the device setup the port hardware, and
889 * initialize the per port data structure. Since initializing the port
890 * requires several commands to the board we will need to wait for any
891 * other open that is already initializing the port.
892 */
893 portp->tty = tty;
894 tty->driver_data = portp;
895 portp->refcount++;
896
897 wait_event_interruptible(portp->raw_wait,
898 !test_bit(ST_INITIALIZING, &portp->state));
899 if (signal_pending(current))
Alan Cox4ac43602006-06-28 04:26:52 -0700900 return -ERESTARTSYS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901
902 if ((portp->flags & ASYNC_INITIALIZED) == 0) {
903 set_bit(ST_INITIALIZING, &portp->state);
904 if ((rc = stli_initopen(brdp, portp)) >= 0) {
905 portp->flags |= ASYNC_INITIALIZED;
906 clear_bit(TTY_IO_ERROR, &tty->flags);
907 }
908 clear_bit(ST_INITIALIZING, &portp->state);
909 wake_up_interruptible(&portp->raw_wait);
910 if (rc < 0)
Alan Cox4ac43602006-06-28 04:26:52 -0700911 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 }
913
914/*
915 * Check if this port is in the middle of closing. If so then wait
916 * until it is closed then return error status, based on flag settings.
917 * The sleep here does not need interrupt protection since the wakeup
918 * for it is done with the same context.
919 */
920 if (portp->flags & ASYNC_CLOSING) {
921 interruptible_sleep_on(&portp->close_wait);
922 if (portp->flags & ASYNC_HUP_NOTIFY)
Alan Cox4ac43602006-06-28 04:26:52 -0700923 return -EAGAIN;
924 return -ERESTARTSYS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 }
926
927/*
928 * Based on type of open being done check if it can overlap with any
929 * previous opens still in effect. If we are a normal serial device
930 * then also we might have to wait for carrier.
931 */
932 if (!(filp->f_flags & O_NONBLOCK)) {
933 if ((rc = stli_waitcarrier(brdp, portp, filp)) != 0)
Alan Cox4ac43602006-06-28 04:26:52 -0700934 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 }
936 portp->flags |= ASYNC_NORMAL_ACTIVE;
Alan Cox4ac43602006-06-28 04:26:52 -0700937 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938}
939
940/*****************************************************************************/
941
942static void stli_close(struct tty_struct *tty, struct file *filp)
943{
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800944 struct stlibrd *brdp;
945 struct stliport *portp;
Alan Cox4ac43602006-06-28 04:26:52 -0700946 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947
948 portp = tty->driver_data;
Alan Cox4ac43602006-06-28 04:26:52 -0700949 if (portp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 return;
951
Alan Cox4ac43602006-06-28 04:26:52 -0700952 spin_lock_irqsave(&stli_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 if (tty_hung_up_p(filp)) {
Alan Cox4ac43602006-06-28 04:26:52 -0700954 spin_unlock_irqrestore(&stli_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 return;
956 }
957 if ((tty->count == 1) && (portp->refcount != 1))
958 portp->refcount = 1;
959 if (portp->refcount-- > 1) {
Alan Cox4ac43602006-06-28 04:26:52 -0700960 spin_unlock_irqrestore(&stli_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 return;
962 }
963
964 portp->flags |= ASYNC_CLOSING;
965
966/*
967 * May want to wait for data to drain before closing. The BUSY flag
968 * keeps track of whether we are still transmitting or not. It is
969 * updated by messages from the slave - indicating when all chars
970 * really have drained.
971 */
972 if (tty == stli_txcooktty)
973 stli_flushchars(tty);
974 tty->closing = 1;
Alan Cox4ac43602006-06-28 04:26:52 -0700975 spin_unlock_irqrestore(&stli_lock, flags);
976
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
978 tty_wait_until_sent(tty, portp->closing_wait);
979
980 portp->flags &= ~ASYNC_INITIALIZED;
981 brdp = stli_brds[portp->brdnr];
982 stli_rawclose(brdp, portp, 0, 0);
983 if (tty->termios->c_cflag & HUPCL) {
984 stli_mkasysigs(&portp->asig, 0, 0);
985 if (test_bit(ST_CMDING, &portp->state))
986 set_bit(ST_DOSIGS, &portp->state);
987 else
988 stli_sendcmd(brdp, portp, A_SETSIGNALS, &portp->asig,
989 sizeof(asysigs_t), 0);
990 }
991 clear_bit(ST_TXBUSY, &portp->state);
992 clear_bit(ST_RXSTOP, &portp->state);
993 set_bit(TTY_IO_ERROR, &tty->flags);
994 if (tty->ldisc.flush_buffer)
995 (tty->ldisc.flush_buffer)(tty);
996 set_bit(ST_DOFLUSHRX, &portp->state);
997 stli_flushbuffer(tty);
998
999 tty->closing = 0;
Alan Cox4ac43602006-06-28 04:26:52 -07001000 portp->tty = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001
1002 if (portp->openwaitcnt) {
1003 if (portp->close_delay)
1004 msleep_interruptible(jiffies_to_msecs(portp->close_delay));
1005 wake_up_interruptible(&portp->open_wait);
1006 }
1007
1008 portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1009 wake_up_interruptible(&portp->close_wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010}
1011
1012/*****************************************************************************/
1013
1014/*
1015 * Carry out first open operations on a port. This involves a number of
1016 * commands to be sent to the slave. We need to open the port, set the
1017 * notification events, set the initial port settings, get and set the
1018 * initial signal values. We sleep and wait in between each one. But
1019 * this still all happens pretty quickly.
1020 */
1021
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001022static int stli_initopen(struct stlibrd *brdp, struct stliport *portp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023{
Alan Cox4ac43602006-06-28 04:26:52 -07001024 struct tty_struct *tty;
1025 asynotify_t nt;
1026 asyport_t aport;
1027 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028
1029 if ((rc = stli_rawopen(brdp, portp, 0, 1)) < 0)
Alan Cox4ac43602006-06-28 04:26:52 -07001030 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031
1032 memset(&nt, 0, sizeof(asynotify_t));
1033 nt.data = (DT_TXLOW | DT_TXEMPTY | DT_RXBUSY | DT_RXBREAK);
1034 nt.signal = SG_DCD;
1035 if ((rc = stli_cmdwait(brdp, portp, A_SETNOTIFY, &nt,
1036 sizeof(asynotify_t), 0)) < 0)
Alan Cox4ac43602006-06-28 04:26:52 -07001037 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038
1039 tty = portp->tty;
Alan Cox4ac43602006-06-28 04:26:52 -07001040 if (tty == NULL)
1041 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 stli_mkasyport(portp, &aport, tty->termios);
1043 if ((rc = stli_cmdwait(brdp, portp, A_SETPORT, &aport,
1044 sizeof(asyport_t), 0)) < 0)
Alan Cox4ac43602006-06-28 04:26:52 -07001045 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046
1047 set_bit(ST_GETSIGS, &portp->state);
1048 if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS, &portp->asig,
1049 sizeof(asysigs_t), 1)) < 0)
Alan Cox4ac43602006-06-28 04:26:52 -07001050 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 if (test_and_clear_bit(ST_GETSIGS, &portp->state))
1052 portp->sigs = stli_mktiocm(portp->asig.sigvalue);
1053 stli_mkasysigs(&portp->asig, 1, 1);
1054 if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1055 sizeof(asysigs_t), 0)) < 0)
Alan Cox4ac43602006-06-28 04:26:52 -07001056 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057
Alan Cox4ac43602006-06-28 04:26:52 -07001058 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059}
1060
1061/*****************************************************************************/
1062
1063/*
1064 * Send an open message to the slave. This will sleep waiting for the
1065 * acknowledgement, so must have user context. We need to co-ordinate
1066 * with close events here, since we don't want open and close events
1067 * to overlap.
1068 */
1069
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001070static int stli_rawopen(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071{
Alan Cox4ac43602006-06-28 04:26:52 -07001072 cdkhdr_t __iomem *hdrp;
1073 cdkctrl_t __iomem *cp;
1074 unsigned char __iomem *bits;
1075 unsigned long flags;
1076 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077
1078/*
1079 * Send a message to the slave to open this port.
1080 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081
1082/*
1083 * Slave is already closing this port. This can happen if a hangup
1084 * occurs on this port. So we must wait until it is complete. The
1085 * order of opens and closes may not be preserved across shared
1086 * memory, so we must wait until it is complete.
1087 */
1088 wait_event_interruptible(portp->raw_wait,
1089 !test_bit(ST_CLOSING, &portp->state));
1090 if (signal_pending(current)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 return -ERESTARTSYS;
1092 }
1093
1094/*
1095 * Everything is ready now, so write the open message into shared
1096 * memory. Once the message is in set the service bits to say that
1097 * this port wants service.
1098 */
Alan Cox4ac43602006-06-28 04:26:52 -07001099 spin_lock_irqsave(&brd_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 EBRDENABLE(brdp);
Alan Cox4ac43602006-06-28 04:26:52 -07001101 cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
1102 writel(arg, &cp->openarg);
1103 writeb(1, &cp->open);
1104 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1105 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 portp->portidx;
Alan Cox4ac43602006-06-28 04:26:52 -07001107 writeb(readb(bits) | portp->portbit, bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 EBRDDISABLE(brdp);
1109
1110 if (wait == 0) {
Alan Cox4ac43602006-06-28 04:26:52 -07001111 spin_unlock_irqrestore(&brd_lock, flags);
1112 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 }
1114
1115/*
1116 * Slave is in action, so now we must wait for the open acknowledgment
1117 * to come back.
1118 */
1119 rc = 0;
1120 set_bit(ST_OPENING, &portp->state);
Alan Cox4ac43602006-06-28 04:26:52 -07001121 spin_unlock_irqrestore(&brd_lock, flags);
1122
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 wait_event_interruptible(portp->raw_wait,
1124 !test_bit(ST_OPENING, &portp->state));
1125 if (signal_pending(current))
1126 rc = -ERESTARTSYS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127
1128 if ((rc == 0) && (portp->rc != 0))
1129 rc = -EIO;
Alan Cox4ac43602006-06-28 04:26:52 -07001130 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131}
1132
1133/*****************************************************************************/
1134
1135/*
1136 * Send a close message to the slave. Normally this will sleep waiting
1137 * for the acknowledgement, but if wait parameter is 0 it will not. If
1138 * wait is true then must have user context (to sleep).
1139 */
1140
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001141static int stli_rawclose(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142{
Alan Cox4ac43602006-06-28 04:26:52 -07001143 cdkhdr_t __iomem *hdrp;
1144 cdkctrl_t __iomem *cp;
1145 unsigned char __iomem *bits;
1146 unsigned long flags;
1147 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148
1149/*
1150 * Slave is already closing this port. This can happen if a hangup
1151 * occurs on this port.
1152 */
1153 if (wait) {
1154 wait_event_interruptible(portp->raw_wait,
1155 !test_bit(ST_CLOSING, &portp->state));
1156 if (signal_pending(current)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 return -ERESTARTSYS;
1158 }
1159 }
1160
1161/*
1162 * Write the close command into shared memory.
1163 */
Alan Cox4ac43602006-06-28 04:26:52 -07001164 spin_lock_irqsave(&brd_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 EBRDENABLE(brdp);
Alan Cox4ac43602006-06-28 04:26:52 -07001166 cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
1167 writel(arg, &cp->closearg);
1168 writeb(1, &cp->close);
1169 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1170 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 portp->portidx;
Alan Cox4ac43602006-06-28 04:26:52 -07001172 writeb(readb(bits) |portp->portbit, bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 EBRDDISABLE(brdp);
1174
1175 set_bit(ST_CLOSING, &portp->state);
Alan Cox4ac43602006-06-28 04:26:52 -07001176 spin_unlock_irqrestore(&brd_lock, flags);
1177
1178 if (wait == 0)
1179 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180
1181/*
1182 * Slave is in action, so now we must wait for the open acknowledgment
1183 * to come back.
1184 */
1185 rc = 0;
1186 wait_event_interruptible(portp->raw_wait,
1187 !test_bit(ST_CLOSING, &portp->state));
1188 if (signal_pending(current))
1189 rc = -ERESTARTSYS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190
1191 if ((rc == 0) && (portp->rc != 0))
1192 rc = -EIO;
Alan Cox4ac43602006-06-28 04:26:52 -07001193 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194}
1195
1196/*****************************************************************************/
1197
1198/*
1199 * Send a command to the slave and wait for the response. This must
1200 * have user context (it sleeps). This routine is generic in that it
1201 * can send any type of command. Its purpose is to wait for that command
1202 * to complete (as opposed to initiating the command then returning).
1203 */
1204
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001205static int stli_cmdwait(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 wait_event_interruptible(portp->raw_wait,
1208 !test_bit(ST_CMDING, &portp->state));
Alan Cox4ac43602006-06-28 04:26:52 -07001209 if (signal_pending(current))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 return -ERESTARTSYS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211
1212 stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
1213
1214 wait_event_interruptible(portp->raw_wait,
1215 !test_bit(ST_CMDING, &portp->state));
Alan Cox4ac43602006-06-28 04:26:52 -07001216 if (signal_pending(current))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 return -ERESTARTSYS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218
1219 if (portp->rc != 0)
Alan Cox4ac43602006-06-28 04:26:52 -07001220 return -EIO;
1221 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222}
1223
1224/*****************************************************************************/
1225
1226/*
1227 * Send the termios settings for this port to the slave. This sleeps
1228 * waiting for the command to complete - so must have user context.
1229 */
1230
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001231static int stli_setport(struct stliport *portp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001233 struct stlibrd *brdp;
Alan Cox4ac43602006-06-28 04:26:52 -07001234 asyport_t aport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235
Alan Cox4ac43602006-06-28 04:26:52 -07001236 if (portp == NULL)
1237 return -ENODEV;
1238 if (portp->tty == NULL)
1239 return -ENODEV;
Jiri Slaby1328d732006-12-08 02:39:19 -08001240 if (portp->brdnr >= stli_nrbrds)
Alan Cox4ac43602006-06-28 04:26:52 -07001241 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 brdp = stli_brds[portp->brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07001243 if (brdp == NULL)
1244 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245
1246 stli_mkasyport(portp, &aport, portp->tty->termios);
1247 return(stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0));
1248}
1249
1250/*****************************************************************************/
1251
1252/*
1253 * Possibly need to wait for carrier (DCD signal) to come high. Say
1254 * maybe because if we are clocal then we don't need to wait...
1255 */
1256
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001257static int stli_waitcarrier(struct stlibrd *brdp, struct stliport *portp, struct file *filp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258{
Alan Cox4ac43602006-06-28 04:26:52 -07001259 unsigned long flags;
1260 int rc, doclocal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261
1262 rc = 0;
1263 doclocal = 0;
1264
1265 if (portp->tty->termios->c_cflag & CLOCAL)
1266 doclocal++;
1267
Alan Cox4ac43602006-06-28 04:26:52 -07001268 spin_lock_irqsave(&stli_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 portp->openwaitcnt++;
1270 if (! tty_hung_up_p(filp))
1271 portp->refcount--;
Alan Cox4ac43602006-06-28 04:26:52 -07001272 spin_unlock_irqrestore(&stli_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273
1274 for (;;) {
1275 stli_mkasysigs(&portp->asig, 1, 1);
1276 if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS,
1277 &portp->asig, sizeof(asysigs_t), 0)) < 0)
1278 break;
1279 if (tty_hung_up_p(filp) ||
1280 ((portp->flags & ASYNC_INITIALIZED) == 0)) {
1281 if (portp->flags & ASYNC_HUP_NOTIFY)
1282 rc = -EBUSY;
1283 else
1284 rc = -ERESTARTSYS;
1285 break;
1286 }
1287 if (((portp->flags & ASYNC_CLOSING) == 0) &&
1288 (doclocal || (portp->sigs & TIOCM_CD))) {
1289 break;
1290 }
1291 if (signal_pending(current)) {
1292 rc = -ERESTARTSYS;
1293 break;
1294 }
1295 interruptible_sleep_on(&portp->open_wait);
1296 }
1297
Alan Cox4ac43602006-06-28 04:26:52 -07001298 spin_lock_irqsave(&stli_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 if (! tty_hung_up_p(filp))
1300 portp->refcount++;
1301 portp->openwaitcnt--;
Alan Cox4ac43602006-06-28 04:26:52 -07001302 spin_unlock_irqrestore(&stli_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303
Alan Cox4ac43602006-06-28 04:26:52 -07001304 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305}
1306
1307/*****************************************************************************/
1308
1309/*
1310 * Write routine. Take the data and put it in the shared memory ring
1311 * queue. If port is not already sending chars then need to mark the
1312 * service bits for this port.
1313 */
1314
1315static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count)
1316{
Alan Cox4ac43602006-06-28 04:26:52 -07001317 cdkasy_t __iomem *ap;
1318 cdkhdr_t __iomem *hdrp;
1319 unsigned char __iomem *bits;
1320 unsigned char __iomem *shbuf;
1321 unsigned char *chbuf;
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001322 struct stliport *portp;
1323 struct stlibrd *brdp;
Alan Cox4ac43602006-06-28 04:26:52 -07001324 unsigned int len, stlen, head, tail, size;
1325 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 if (tty == stli_txcooktty)
1328 stli_flushchars(tty);
1329 portp = tty->driver_data;
Alan Cox4ac43602006-06-28 04:26:52 -07001330 if (portp == NULL)
1331 return 0;
Jiri Slaby1328d732006-12-08 02:39:19 -08001332 if (portp->brdnr >= stli_nrbrds)
Alan Cox4ac43602006-06-28 04:26:52 -07001333 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 brdp = stli_brds[portp->brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07001335 if (brdp == NULL)
1336 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 chbuf = (unsigned char *) buf;
1338
1339/*
1340 * All data is now local, shove as much as possible into shared memory.
1341 */
Alan Cox4ac43602006-06-28 04:26:52 -07001342 spin_lock_irqsave(&brd_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 EBRDENABLE(brdp);
Alan Cox4ac43602006-06-28 04:26:52 -07001344 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
1345 head = (unsigned int) readw(&ap->txq.head);
1346 tail = (unsigned int) readw(&ap->txq.tail);
1347 if (tail != ((unsigned int) readw(&ap->txq.tail)))
1348 tail = (unsigned int) readw(&ap->txq.tail);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 size = portp->txsize;
1350 if (head >= tail) {
1351 len = size - (head - tail) - 1;
1352 stlen = size - head;
1353 } else {
1354 len = tail - head - 1;
1355 stlen = len;
1356 }
1357
Jiri Slabya3f8d9d2006-12-08 02:39:18 -08001358 len = min(len, (unsigned int)count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 count = 0;
Alan Cox4ac43602006-06-28 04:26:52 -07001360 shbuf = (char __iomem *) EBRDGETMEMPTR(brdp, portp->txoffset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361
1362 while (len > 0) {
Jiri Slabya3f8d9d2006-12-08 02:39:18 -08001363 stlen = min(len, stlen);
Alan Cox4ac43602006-06-28 04:26:52 -07001364 memcpy_toio(shbuf + head, chbuf, stlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 chbuf += stlen;
1366 len -= stlen;
1367 count += stlen;
1368 head += stlen;
1369 if (head >= size) {
1370 head = 0;
1371 stlen = tail;
1372 }
1373 }
1374
Alan Cox4ac43602006-06-28 04:26:52 -07001375 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
1376 writew(head, &ap->txq.head);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 if (test_bit(ST_TXBUSY, &portp->state)) {
Alan Cox4ac43602006-06-28 04:26:52 -07001378 if (readl(&ap->changed.data) & DT_TXEMPTY)
1379 writel(readl(&ap->changed.data) & ~DT_TXEMPTY, &ap->changed.data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 }
Alan Cox4ac43602006-06-28 04:26:52 -07001381 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1382 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 portp->portidx;
Alan Cox4ac43602006-06-28 04:26:52 -07001384 writeb(readb(bits) | portp->portbit, bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 set_bit(ST_TXBUSY, &portp->state);
1386 EBRDDISABLE(brdp);
Alan Cox4ac43602006-06-28 04:26:52 -07001387 spin_unlock_irqrestore(&brd_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388
1389 return(count);
1390}
1391
1392/*****************************************************************************/
1393
1394/*
1395 * Output a single character. We put it into a temporary local buffer
1396 * (for speed) then write out that buffer when the flushchars routine
1397 * is called. There is a safety catch here so that if some other port
1398 * writes chars before the current buffer has been, then we write them
1399 * first them do the new ports.
1400 */
1401
1402static void stli_putchar(struct tty_struct *tty, unsigned char ch)
1403{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 if (tty != stli_txcooktty) {
Alan Cox4ac43602006-06-28 04:26:52 -07001405 if (stli_txcooktty != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 stli_flushchars(stli_txcooktty);
1407 stli_txcooktty = tty;
1408 }
1409
1410 stli_txcookbuf[stli_txcooksize++] = ch;
1411}
1412
1413/*****************************************************************************/
1414
1415/*
1416 * Transfer characters from the local TX cooking buffer to the board.
1417 * We sort of ignore the tty that gets passed in here. We rely on the
1418 * info stored with the TX cook buffer to tell us which port to flush
1419 * the data on. In any case we clean out the TX cook buffer, for re-use
1420 * by someone else.
1421 */
1422
1423static void stli_flushchars(struct tty_struct *tty)
1424{
Alan Cox4ac43602006-06-28 04:26:52 -07001425 cdkhdr_t __iomem *hdrp;
1426 unsigned char __iomem *bits;
1427 cdkasy_t __iomem *ap;
1428 struct tty_struct *cooktty;
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001429 struct stliport *portp;
1430 struct stlibrd *brdp;
Alan Cox4ac43602006-06-28 04:26:52 -07001431 unsigned int len, stlen, head, tail, size, count, cooksize;
1432 unsigned char *buf;
1433 unsigned char __iomem *shbuf;
1434 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435
1436 cooksize = stli_txcooksize;
1437 cooktty = stli_txcooktty;
1438 stli_txcooksize = 0;
1439 stli_txcookrealsize = 0;
Alan Cox4ac43602006-06-28 04:26:52 -07001440 stli_txcooktty = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441
Alan Cox4ac43602006-06-28 04:26:52 -07001442 if (tty == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 return;
Alan Cox4ac43602006-06-28 04:26:52 -07001444 if (cooktty == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 return;
1446 if (tty != cooktty)
1447 tty = cooktty;
1448 if (cooksize == 0)
1449 return;
1450
1451 portp = tty->driver_data;
Alan Cox4ac43602006-06-28 04:26:52 -07001452 if (portp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 return;
Jiri Slaby1328d732006-12-08 02:39:19 -08001454 if (portp->brdnr >= stli_nrbrds)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 return;
1456 brdp = stli_brds[portp->brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07001457 if (brdp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 return;
1459
Alan Cox4ac43602006-06-28 04:26:52 -07001460 spin_lock_irqsave(&brd_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 EBRDENABLE(brdp);
1462
Alan Cox4ac43602006-06-28 04:26:52 -07001463 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
1464 head = (unsigned int) readw(&ap->txq.head);
1465 tail = (unsigned int) readw(&ap->txq.tail);
1466 if (tail != ((unsigned int) readw(&ap->txq.tail)))
1467 tail = (unsigned int) readw(&ap->txq.tail);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 size = portp->txsize;
1469 if (head >= tail) {
1470 len = size - (head - tail) - 1;
1471 stlen = size - head;
1472 } else {
1473 len = tail - head - 1;
1474 stlen = len;
1475 }
1476
Jiri Slabya3f8d9d2006-12-08 02:39:18 -08001477 len = min(len, cooksize);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 count = 0;
Al Viro29756fa2006-10-10 22:47:27 +01001479 shbuf = EBRDGETMEMPTR(brdp, portp->txoffset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 buf = stli_txcookbuf;
1481
1482 while (len > 0) {
Jiri Slabya3f8d9d2006-12-08 02:39:18 -08001483 stlen = min(len, stlen);
Alan Cox4ac43602006-06-28 04:26:52 -07001484 memcpy_toio(shbuf + head, buf, stlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 buf += stlen;
1486 len -= stlen;
1487 count += stlen;
1488 head += stlen;
1489 if (head >= size) {
1490 head = 0;
1491 stlen = tail;
1492 }
1493 }
1494
Alan Cox4ac43602006-06-28 04:26:52 -07001495 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
1496 writew(head, &ap->txq.head);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497
1498 if (test_bit(ST_TXBUSY, &portp->state)) {
Alan Cox4ac43602006-06-28 04:26:52 -07001499 if (readl(&ap->changed.data) & DT_TXEMPTY)
1500 writel(readl(&ap->changed.data) & ~DT_TXEMPTY, &ap->changed.data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 }
Alan Cox4ac43602006-06-28 04:26:52 -07001502 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1503 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 portp->portidx;
Alan Cox4ac43602006-06-28 04:26:52 -07001505 writeb(readb(bits) | portp->portbit, bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 set_bit(ST_TXBUSY, &portp->state);
1507
1508 EBRDDISABLE(brdp);
Alan Cox4ac43602006-06-28 04:26:52 -07001509 spin_unlock_irqrestore(&brd_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510}
1511
1512/*****************************************************************************/
1513
1514static int stli_writeroom(struct tty_struct *tty)
1515{
Alan Cox4ac43602006-06-28 04:26:52 -07001516 cdkasyrq_t __iomem *rp;
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001517 struct stliport *portp;
1518 struct stlibrd *brdp;
Alan Cox4ac43602006-06-28 04:26:52 -07001519 unsigned int head, tail, len;
1520 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 if (tty == stli_txcooktty) {
1523 if (stli_txcookrealsize != 0) {
1524 len = stli_txcookrealsize - stli_txcooksize;
Alan Cox4ac43602006-06-28 04:26:52 -07001525 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 }
1527 }
1528
1529 portp = tty->driver_data;
Alan Cox4ac43602006-06-28 04:26:52 -07001530 if (portp == NULL)
1531 return 0;
Jiri Slaby1328d732006-12-08 02:39:19 -08001532 if (portp->brdnr >= stli_nrbrds)
Alan Cox4ac43602006-06-28 04:26:52 -07001533 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 brdp = stli_brds[portp->brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07001535 if (brdp == NULL)
1536 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537
Alan Cox4ac43602006-06-28 04:26:52 -07001538 spin_lock_irqsave(&brd_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 EBRDENABLE(brdp);
Alan Cox4ac43602006-06-28 04:26:52 -07001540 rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
1541 head = (unsigned int) readw(&rp->head);
1542 tail = (unsigned int) readw(&rp->tail);
1543 if (tail != ((unsigned int) readw(&rp->tail)))
1544 tail = (unsigned int) readw(&rp->tail);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 len = (head >= tail) ? (portp->txsize - (head - tail)) : (tail - head);
1546 len--;
1547 EBRDDISABLE(brdp);
Alan Cox4ac43602006-06-28 04:26:52 -07001548 spin_unlock_irqrestore(&brd_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549
1550 if (tty == stli_txcooktty) {
1551 stli_txcookrealsize = len;
1552 len -= stli_txcooksize;
1553 }
Alan Cox4ac43602006-06-28 04:26:52 -07001554 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555}
1556
1557/*****************************************************************************/
1558
1559/*
1560 * Return the number of characters in the transmit buffer. Normally we
1561 * will return the number of chars in the shared memory ring queue.
1562 * We need to kludge around the case where the shared memory buffer is
1563 * empty but not all characters have drained yet, for this case just
1564 * return that there is 1 character in the buffer!
1565 */
1566
1567static int stli_charsinbuffer(struct tty_struct *tty)
1568{
Alan Cox4ac43602006-06-28 04:26:52 -07001569 cdkasyrq_t __iomem *rp;
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001570 struct stliport *portp;
1571 struct stlibrd *brdp;
Alan Cox4ac43602006-06-28 04:26:52 -07001572 unsigned int head, tail, len;
1573 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 if (tty == stli_txcooktty)
1576 stli_flushchars(tty);
1577 portp = tty->driver_data;
Alan Cox4ac43602006-06-28 04:26:52 -07001578 if (portp == NULL)
1579 return 0;
Jiri Slaby1328d732006-12-08 02:39:19 -08001580 if (portp->brdnr >= stli_nrbrds)
Alan Cox4ac43602006-06-28 04:26:52 -07001581 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 brdp = stli_brds[portp->brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07001583 if (brdp == NULL)
1584 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585
Alan Cox4ac43602006-06-28 04:26:52 -07001586 spin_lock_irqsave(&brd_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 EBRDENABLE(brdp);
Alan Cox4ac43602006-06-28 04:26:52 -07001588 rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
1589 head = (unsigned int) readw(&rp->head);
1590 tail = (unsigned int) readw(&rp->tail);
1591 if (tail != ((unsigned int) readw(&rp->tail)))
1592 tail = (unsigned int) readw(&rp->tail);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 len = (head >= tail) ? (head - tail) : (portp->txsize - (tail - head));
1594 if ((len == 0) && test_bit(ST_TXBUSY, &portp->state))
1595 len = 1;
1596 EBRDDISABLE(brdp);
Alan Cox4ac43602006-06-28 04:26:52 -07001597 spin_unlock_irqrestore(&brd_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598
Alan Cox4ac43602006-06-28 04:26:52 -07001599 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600}
1601
1602/*****************************************************************************/
1603
1604/*
1605 * Generate the serial struct info.
1606 */
1607
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001608static int stli_getserial(struct stliport *portp, struct serial_struct __user *sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609{
Alan Cox4ac43602006-06-28 04:26:52 -07001610 struct serial_struct sio;
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001611 struct stlibrd *brdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612
1613 memset(&sio, 0, sizeof(struct serial_struct));
1614 sio.type = PORT_UNKNOWN;
1615 sio.line = portp->portnr;
1616 sio.irq = 0;
1617 sio.flags = portp->flags;
1618 sio.baud_base = portp->baud_base;
1619 sio.close_delay = portp->close_delay;
1620 sio.closing_wait = portp->closing_wait;
1621 sio.custom_divisor = portp->custom_divisor;
1622 sio.xmit_fifo_size = 0;
1623 sio.hub6 = 0;
1624
1625 brdp = stli_brds[portp->brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07001626 if (brdp != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 sio.port = brdp->iobase;
1628
1629 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ?
1630 -EFAULT : 0;
1631}
1632
1633/*****************************************************************************/
1634
1635/*
1636 * Set port according to the serial struct info.
1637 * At this point we do not do any auto-configure stuff, so we will
1638 * just quietly ignore any requests to change irq, etc.
1639 */
1640
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001641static int stli_setserial(struct stliport *portp, struct serial_struct __user *sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642{
Alan Cox4ac43602006-06-28 04:26:52 -07001643 struct serial_struct sio;
1644 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645
1646 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1647 return -EFAULT;
1648 if (!capable(CAP_SYS_ADMIN)) {
1649 if ((sio.baud_base != portp->baud_base) ||
1650 (sio.close_delay != portp->close_delay) ||
1651 ((sio.flags & ~ASYNC_USR_MASK) !=
1652 (portp->flags & ~ASYNC_USR_MASK)))
Alan Cox4ac43602006-06-28 04:26:52 -07001653 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 }
1655
1656 portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
1657 (sio.flags & ASYNC_USR_MASK);
1658 portp->baud_base = sio.baud_base;
1659 portp->close_delay = sio.close_delay;
1660 portp->closing_wait = sio.closing_wait;
1661 portp->custom_divisor = sio.custom_divisor;
1662
1663 if ((rc = stli_setport(portp)) < 0)
Alan Cox4ac43602006-06-28 04:26:52 -07001664 return rc;
1665 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666}
1667
1668/*****************************************************************************/
1669
1670static int stli_tiocmget(struct tty_struct *tty, struct file *file)
1671{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001672 struct stliport *portp = tty->driver_data;
1673 struct stlibrd *brdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674 int rc;
1675
Alan Cox4ac43602006-06-28 04:26:52 -07001676 if (portp == NULL)
1677 return -ENODEV;
Jiri Slaby1328d732006-12-08 02:39:19 -08001678 if (portp->brdnr >= stli_nrbrds)
Alan Cox4ac43602006-06-28 04:26:52 -07001679 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680 brdp = stli_brds[portp->brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07001681 if (brdp == NULL)
1682 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 if (tty->flags & (1 << TTY_IO_ERROR))
Alan Cox4ac43602006-06-28 04:26:52 -07001684 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685
1686 if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS,
1687 &portp->asig, sizeof(asysigs_t), 1)) < 0)
Alan Cox4ac43602006-06-28 04:26:52 -07001688 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689
1690 return stli_mktiocm(portp->asig.sigvalue);
1691}
1692
1693static int stli_tiocmset(struct tty_struct *tty, struct file *file,
1694 unsigned int set, unsigned int clear)
1695{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001696 struct stliport *portp = tty->driver_data;
1697 struct stlibrd *brdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 int rts = -1, dtr = -1;
1699
Alan Cox4ac43602006-06-28 04:26:52 -07001700 if (portp == NULL)
1701 return -ENODEV;
Jiri Slaby1328d732006-12-08 02:39:19 -08001702 if (portp->brdnr >= stli_nrbrds)
Alan Cox4ac43602006-06-28 04:26:52 -07001703 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704 brdp = stli_brds[portp->brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07001705 if (brdp == NULL)
1706 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 if (tty->flags & (1 << TTY_IO_ERROR))
Alan Cox4ac43602006-06-28 04:26:52 -07001708 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709
1710 if (set & TIOCM_RTS)
1711 rts = 1;
1712 if (set & TIOCM_DTR)
1713 dtr = 1;
1714 if (clear & TIOCM_RTS)
1715 rts = 0;
1716 if (clear & TIOCM_DTR)
1717 dtr = 0;
1718
1719 stli_mkasysigs(&portp->asig, dtr, rts);
1720
1721 return stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1722 sizeof(asysigs_t), 0);
1723}
1724
1725static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1726{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001727 struct stliport *portp;
1728 struct stlibrd *brdp;
Alan Cox4ac43602006-06-28 04:26:52 -07001729 unsigned int ival;
1730 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 void __user *argp = (void __user *)arg;
1732
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 portp = tty->driver_data;
Alan Cox4ac43602006-06-28 04:26:52 -07001734 if (portp == NULL)
1735 return -ENODEV;
Jiri Slaby1328d732006-12-08 02:39:19 -08001736 if (portp->brdnr >= stli_nrbrds)
Alan Cox4ac43602006-06-28 04:26:52 -07001737 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 brdp = stli_brds[portp->brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07001739 if (brdp == NULL)
1740 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741
1742 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1743 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
1744 if (tty->flags & (1 << TTY_IO_ERROR))
Alan Cox4ac43602006-06-28 04:26:52 -07001745 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 }
1747
1748 rc = 0;
1749
1750 switch (cmd) {
1751 case TIOCGSOFTCAR:
1752 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
1753 (unsigned __user *) arg);
1754 break;
1755 case TIOCSSOFTCAR:
1756 if ((rc = get_user(ival, (unsigned __user *) arg)) == 0)
1757 tty->termios->c_cflag =
1758 (tty->termios->c_cflag & ~CLOCAL) |
1759 (ival ? CLOCAL : 0);
1760 break;
1761 case TIOCGSERIAL:
1762 rc = stli_getserial(portp, argp);
1763 break;
1764 case TIOCSSERIAL:
1765 rc = stli_setserial(portp, argp);
1766 break;
1767 case STL_GETPFLAG:
1768 rc = put_user(portp->pflag, (unsigned __user *)argp);
1769 break;
1770 case STL_SETPFLAG:
1771 if ((rc = get_user(portp->pflag, (unsigned __user *)argp)) == 0)
1772 stli_setport(portp);
1773 break;
1774 case COM_GETPORTSTATS:
1775 rc = stli_getportstats(portp, argp);
1776 break;
1777 case COM_CLRPORTSTATS:
1778 rc = stli_clrportstats(portp, argp);
1779 break;
1780 case TIOCSERCONFIG:
1781 case TIOCSERGWILD:
1782 case TIOCSERSWILD:
1783 case TIOCSERGETLSR:
1784 case TIOCSERGSTRUCT:
1785 case TIOCSERGETMULTI:
1786 case TIOCSERSETMULTI:
1787 default:
1788 rc = -ENOIOCTLCMD;
1789 break;
1790 }
1791
Alan Cox4ac43602006-06-28 04:26:52 -07001792 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793}
1794
1795/*****************************************************************************/
1796
1797/*
1798 * This routine assumes that we have user context and can sleep.
1799 * Looks like it is true for the current ttys implementation..!!
1800 */
1801
Alan Cox606d0992006-12-08 02:38:45 -08001802static void stli_settermios(struct tty_struct *tty, struct ktermios *old)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001804 struct stliport *portp;
1805 struct stlibrd *brdp;
Alan Cox606d0992006-12-08 02:38:45 -08001806 struct ktermios *tiosp;
Alan Cox4ac43602006-06-28 04:26:52 -07001807 asyport_t aport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808
Alan Cox4ac43602006-06-28 04:26:52 -07001809 if (tty == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 return;
1811 portp = tty->driver_data;
Alan Cox4ac43602006-06-28 04:26:52 -07001812 if (portp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 return;
Jiri Slaby1328d732006-12-08 02:39:19 -08001814 if (portp->brdnr >= stli_nrbrds)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815 return;
1816 brdp = stli_brds[portp->brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07001817 if (brdp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818 return;
1819
1820 tiosp = tty->termios;
1821 if ((tiosp->c_cflag == old->c_cflag) &&
1822 (tiosp->c_iflag == old->c_iflag))
1823 return;
1824
1825 stli_mkasyport(portp, &aport, tiosp);
1826 stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0);
1827 stli_mkasysigs(&portp->asig, ((tiosp->c_cflag & CBAUD) ? 1 : 0), -1);
1828 stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1829 sizeof(asysigs_t), 0);
1830 if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0))
1831 tty->hw_stopped = 0;
1832 if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
1833 wake_up_interruptible(&portp->open_wait);
1834}
1835
1836/*****************************************************************************/
1837
1838/*
1839 * Attempt to flow control who ever is sending us data. We won't really
1840 * do any flow control action here. We can't directly, and even if we
1841 * wanted to we would have to send a command to the slave. The slave
1842 * knows how to flow control, and will do so when its buffers reach its
1843 * internal high water marks. So what we will do is set a local state
1844 * bit that will stop us sending any RX data up from the poll routine
1845 * (which is the place where RX data from the slave is handled).
1846 */
1847
1848static void stli_throttle(struct tty_struct *tty)
1849{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001850 struct stliport *portp = tty->driver_data;
Alan Cox4ac43602006-06-28 04:26:52 -07001851 if (portp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 set_bit(ST_RXSTOP, &portp->state);
1854}
1855
1856/*****************************************************************************/
1857
1858/*
1859 * Unflow control the device sending us data... That means that all
1860 * we have to do is clear the RXSTOP state bit. The next poll call
1861 * will then be able to pass the RX data back up.
1862 */
1863
1864static void stli_unthrottle(struct tty_struct *tty)
1865{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001866 struct stliport *portp = tty->driver_data;
Alan Cox4ac43602006-06-28 04:26:52 -07001867 if (portp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 clear_bit(ST_RXSTOP, &portp->state);
1870}
1871
1872/*****************************************************************************/
1873
1874/*
Alan Cox4ac43602006-06-28 04:26:52 -07001875 * Stop the transmitter.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876 */
1877
1878static void stli_stop(struct tty_struct *tty)
1879{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880}
1881
1882/*****************************************************************************/
1883
1884/*
Alan Cox4ac43602006-06-28 04:26:52 -07001885 * Start the transmitter again.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 */
1887
1888static void stli_start(struct tty_struct *tty)
1889{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890}
1891
1892/*****************************************************************************/
1893
1894/*
1895 * Scheduler called hang up routine. This is called from the scheduler,
1896 * not direct from the driver "poll" routine. We can't call it there
1897 * since the real local hangup code will enable/disable the board and
1898 * other things that we can't do while handling the poll. Much easier
1899 * to deal with it some time later (don't really care when, hangups
1900 * aren't that time critical).
1901 */
1902
Al Viro3e577a82006-12-06 18:41:45 +00001903static void stli_dohangup(struct work_struct *ugly_api)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001905 struct stliport *portp = container_of(ugly_api, struct stliport, tqhangup);
Alan Cox4ac43602006-06-28 04:26:52 -07001906 if (portp->tty != NULL) {
1907 tty_hangup(portp->tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 }
1909}
1910
1911/*****************************************************************************/
1912
1913/*
1914 * Hangup this port. This is pretty much like closing the port, only
1915 * a little more brutal. No waiting for data to drain. Shutdown the
1916 * port and maybe drop signals. This is rather tricky really. We want
1917 * to close the port as well.
1918 */
1919
1920static void stli_hangup(struct tty_struct *tty)
1921{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001922 struct stliport *portp;
1923 struct stlibrd *brdp;
Alan Cox4ac43602006-06-28 04:26:52 -07001924 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 portp = tty->driver_data;
Alan Cox4ac43602006-06-28 04:26:52 -07001927 if (portp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 return;
Jiri Slaby1328d732006-12-08 02:39:19 -08001929 if (portp->brdnr >= stli_nrbrds)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 return;
1931 brdp = stli_brds[portp->brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07001932 if (brdp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 return;
1934
1935 portp->flags &= ~ASYNC_INITIALIZED;
1936
Alan Cox4ac43602006-06-28 04:26:52 -07001937 if (!test_bit(ST_CLOSING, &portp->state))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938 stli_rawclose(brdp, portp, 0, 0);
Alan Cox4ac43602006-06-28 04:26:52 -07001939
1940 spin_lock_irqsave(&stli_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941 if (tty->termios->c_cflag & HUPCL) {
1942 stli_mkasysigs(&portp->asig, 0, 0);
1943 if (test_bit(ST_CMDING, &portp->state)) {
1944 set_bit(ST_DOSIGS, &portp->state);
1945 set_bit(ST_DOFLUSHTX, &portp->state);
1946 set_bit(ST_DOFLUSHRX, &portp->state);
1947 } else {
1948 stli_sendcmd(brdp, portp, A_SETSIGNALSF,
1949 &portp->asig, sizeof(asysigs_t), 0);
1950 }
1951 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952
1953 clear_bit(ST_TXBUSY, &portp->state);
1954 clear_bit(ST_RXSTOP, &portp->state);
1955 set_bit(TTY_IO_ERROR, &tty->flags);
Alan Cox4ac43602006-06-28 04:26:52 -07001956 portp->tty = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957 portp->flags &= ~ASYNC_NORMAL_ACTIVE;
1958 portp->refcount = 0;
Alan Cox4ac43602006-06-28 04:26:52 -07001959 spin_unlock_irqrestore(&stli_lock, flags);
1960
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961 wake_up_interruptible(&portp->open_wait);
1962}
1963
1964/*****************************************************************************/
1965
1966/*
1967 * Flush characters from the lower buffer. We may not have user context
1968 * so we cannot sleep waiting for it to complete. Also we need to check
1969 * if there is chars for this port in the TX cook buffer, and flush them
1970 * as well.
1971 */
1972
1973static void stli_flushbuffer(struct tty_struct *tty)
1974{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001975 struct stliport *portp;
1976 struct stlibrd *brdp;
Alan Cox4ac43602006-06-28 04:26:52 -07001977 unsigned long ftype, flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979 portp = tty->driver_data;
Alan Cox4ac43602006-06-28 04:26:52 -07001980 if (portp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981 return;
Jiri Slaby1328d732006-12-08 02:39:19 -08001982 if (portp->brdnr >= stli_nrbrds)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 return;
1984 brdp = stli_brds[portp->brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07001985 if (brdp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986 return;
1987
Alan Cox4ac43602006-06-28 04:26:52 -07001988 spin_lock_irqsave(&brd_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989 if (tty == stli_txcooktty) {
Alan Cox4ac43602006-06-28 04:26:52 -07001990 stli_txcooktty = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 stli_txcooksize = 0;
1992 stli_txcookrealsize = 0;
1993 }
1994 if (test_bit(ST_CMDING, &portp->state)) {
1995 set_bit(ST_DOFLUSHTX, &portp->state);
1996 } else {
1997 ftype = FLUSHTX;
1998 if (test_bit(ST_DOFLUSHRX, &portp->state)) {
1999 ftype |= FLUSHRX;
2000 clear_bit(ST_DOFLUSHRX, &portp->state);
2001 }
Alan Cox4ac43602006-06-28 04:26:52 -07002002 __stli_sendcmd(brdp, portp, A_FLUSH, &ftype, sizeof(u32), 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003 }
Alan Cox4ac43602006-06-28 04:26:52 -07002004 spin_unlock_irqrestore(&brd_lock, flags);
2005 tty_wakeup(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006}
2007
2008/*****************************************************************************/
2009
2010static void stli_breakctl(struct tty_struct *tty, int state)
2011{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002012 struct stlibrd *brdp;
2013 struct stliport *portp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014 long arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016 portp = tty->driver_data;
Alan Cox4ac43602006-06-28 04:26:52 -07002017 if (portp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 return;
Jiri Slaby1328d732006-12-08 02:39:19 -08002019 if (portp->brdnr >= stli_nrbrds)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 return;
2021 brdp = stli_brds[portp->brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07002022 if (brdp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023 return;
2024
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 arg = (state == -1) ? BREAKON : BREAKOFF;
2026 stli_cmdwait(brdp, portp, A_BREAK, &arg, sizeof(long), 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027}
2028
2029/*****************************************************************************/
2030
2031static void stli_waituntilsent(struct tty_struct *tty, int timeout)
2032{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002033 struct stliport *portp;
Alan Cox4ac43602006-06-28 04:26:52 -07002034 unsigned long tend;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035
Alan Cox4ac43602006-06-28 04:26:52 -07002036 if (tty == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037 return;
2038 portp = tty->driver_data;
Alan Cox4ac43602006-06-28 04:26:52 -07002039 if (portp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 return;
2041
2042 if (timeout == 0)
2043 timeout = HZ;
2044 tend = jiffies + timeout;
2045
2046 while (test_bit(ST_TXBUSY, &portp->state)) {
2047 if (signal_pending(current))
2048 break;
2049 msleep_interruptible(20);
2050 if (time_after_eq(jiffies, tend))
2051 break;
2052 }
2053}
2054
2055/*****************************************************************************/
2056
2057static void stli_sendxchar(struct tty_struct *tty, char ch)
2058{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002059 struct stlibrd *brdp;
2060 struct stliport *portp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 asyctrl_t actrl;
2062
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 portp = tty->driver_data;
Alan Cox4ac43602006-06-28 04:26:52 -07002064 if (portp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 return;
Jiri Slaby1328d732006-12-08 02:39:19 -08002066 if (portp->brdnr >= stli_nrbrds)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 return;
2068 brdp = stli_brds[portp->brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07002069 if (brdp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 return;
2071
2072 memset(&actrl, 0, sizeof(asyctrl_t));
2073 if (ch == STOP_CHAR(tty)) {
2074 actrl.rxctrl = CT_STOPFLOW;
2075 } else if (ch == START_CHAR(tty)) {
2076 actrl.rxctrl = CT_STARTFLOW;
2077 } else {
2078 actrl.txctrl = CT_SENDCHR;
2079 actrl.tximdch = ch;
2080 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
2082}
2083
2084/*****************************************************************************/
2085
2086#define MAXLINE 80
2087
2088/*
2089 * Format info for a specified port. The line is deliberately limited
2090 * to 80 characters. (If it is too long it will be truncated, if too
2091 * short then padded with spaces).
2092 */
2093
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002094static int stli_portinfo(struct stlibrd *brdp, struct stliport *portp, int portnr, char *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095{
Alan Cox4ac43602006-06-28 04:26:52 -07002096 char *sp, *uart;
2097 int rc, cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098
2099 rc = stli_portcmdstats(portp);
2100
2101 uart = "UNKNOWN";
2102 if (brdp->state & BST_STARTED) {
2103 switch (stli_comstats.hwid) {
Alan Cox4ac43602006-06-28 04:26:52 -07002104 case 0: uart = "2681"; break;
2105 case 1: uart = "SC26198"; break;
2106 default:uart = "CD1400"; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 }
2108 }
2109
2110 sp = pos;
2111 sp += sprintf(sp, "%d: uart:%s ", portnr, uart);
2112
2113 if ((brdp->state & BST_STARTED) && (rc >= 0)) {
2114 sp += sprintf(sp, "tx:%d rx:%d", (int) stli_comstats.txtotal,
2115 (int) stli_comstats.rxtotal);
2116
2117 if (stli_comstats.rxframing)
2118 sp += sprintf(sp, " fe:%d",
2119 (int) stli_comstats.rxframing);
2120 if (stli_comstats.rxparity)
2121 sp += sprintf(sp, " pe:%d",
2122 (int) stli_comstats.rxparity);
2123 if (stli_comstats.rxbreaks)
2124 sp += sprintf(sp, " brk:%d",
2125 (int) stli_comstats.rxbreaks);
2126 if (stli_comstats.rxoverrun)
2127 sp += sprintf(sp, " oe:%d",
2128 (int) stli_comstats.rxoverrun);
2129
2130 cnt = sprintf(sp, "%s%s%s%s%s ",
2131 (stli_comstats.signals & TIOCM_RTS) ? "|RTS" : "",
2132 (stli_comstats.signals & TIOCM_CTS) ? "|CTS" : "",
2133 (stli_comstats.signals & TIOCM_DTR) ? "|DTR" : "",
2134 (stli_comstats.signals & TIOCM_CD) ? "|DCD" : "",
2135 (stli_comstats.signals & TIOCM_DSR) ? "|DSR" : "");
2136 *sp = ' ';
2137 sp += cnt;
2138 }
2139
2140 for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
2141 *sp++ = ' ';
2142 if (cnt >= MAXLINE)
2143 pos[(MAXLINE - 2)] = '+';
2144 pos[(MAXLINE - 1)] = '\n';
2145
2146 return(MAXLINE);
2147}
2148
2149/*****************************************************************************/
2150
2151/*
2152 * Port info, read from the /proc file system.
2153 */
2154
2155static int stli_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
2156{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002157 struct stlibrd *brdp;
2158 struct stliport *portp;
Jiri Slaby1328d732006-12-08 02:39:19 -08002159 unsigned int brdnr, portnr, totalport;
Alan Cox4ac43602006-06-28 04:26:52 -07002160 int curoff, maxoff;
2161 char *pos;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162
2163 pos = page;
2164 totalport = 0;
2165 curoff = 0;
2166
2167 if (off == 0) {
2168 pos += sprintf(pos, "%s: version %s", stli_drvtitle,
2169 stli_drvversion);
2170 while (pos < (page + MAXLINE - 1))
2171 *pos++ = ' ';
2172 *pos++ = '\n';
2173 }
2174 curoff = MAXLINE;
2175
2176/*
2177 * We scan through for each board, panel and port. The offset is
2178 * calculated on the fly, and irrelevant ports are skipped.
2179 */
2180 for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
2181 brdp = stli_brds[brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07002182 if (brdp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 continue;
2184 if (brdp->state == 0)
2185 continue;
2186
2187 maxoff = curoff + (brdp->nrports * MAXLINE);
2188 if (off >= maxoff) {
2189 curoff = maxoff;
2190 continue;
2191 }
2192
2193 totalport = brdnr * STL_MAXPORTS;
2194 for (portnr = 0; (portnr < brdp->nrports); portnr++,
2195 totalport++) {
2196 portp = brdp->ports[portnr];
Alan Cox4ac43602006-06-28 04:26:52 -07002197 if (portp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198 continue;
2199 if (off >= (curoff += MAXLINE))
2200 continue;
2201 if ((pos - page + MAXLINE) > count)
2202 goto stli_readdone;
2203 pos += stli_portinfo(brdp, portp, totalport, pos);
2204 }
2205 }
2206
2207 *eof = 1;
2208
2209stli_readdone:
2210 *start = page;
2211 return(pos - page);
2212}
2213
2214/*****************************************************************************/
2215
2216/*
2217 * Generic send command routine. This will send a message to the slave,
2218 * of the specified type with the specified argument. Must be very
2219 * careful of data that will be copied out from shared memory -
2220 * containing command results. The command completion is all done from
2221 * a poll routine that does not have user context. Therefore you cannot
2222 * copy back directly into user space, or to the kernel stack of a
2223 * process. This routine does not sleep, so can be called from anywhere.
Alan Cox4ac43602006-06-28 04:26:52 -07002224 *
2225 * The caller must hold the brd_lock (see also stli_sendcmd the usual
2226 * entry point)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227 */
2228
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002229static void __stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230{
Alan Cox4ac43602006-06-28 04:26:52 -07002231 cdkhdr_t __iomem *hdrp;
2232 cdkctrl_t __iomem *cp;
2233 unsigned char __iomem *bits;
2234 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235
Alan Cox4ac43602006-06-28 04:26:52 -07002236 spin_lock_irqsave(&brd_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237
2238 if (test_bit(ST_CMDING, &portp->state)) {
2239 printk(KERN_ERR "STALLION: command already busy, cmd=%x!\n",
2240 (int) cmd);
Alan Cox4ac43602006-06-28 04:26:52 -07002241 spin_unlock_irqrestore(&brd_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 return;
2243 }
2244
2245 EBRDENABLE(brdp);
Alan Cox4ac43602006-06-28 04:26:52 -07002246 cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 if (size > 0) {
Alan Cox4ac43602006-06-28 04:26:52 -07002248 memcpy_toio((void __iomem *) &(cp->args[0]), arg, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 if (copyback) {
2250 portp->argp = arg;
2251 portp->argsize = size;
2252 }
2253 }
Alan Cox4ac43602006-06-28 04:26:52 -07002254 writel(0, &cp->status);
2255 writel(cmd, &cp->cmd);
2256 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2257 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 portp->portidx;
Alan Cox4ac43602006-06-28 04:26:52 -07002259 writeb(readb(bits) | portp->portbit, bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 set_bit(ST_CMDING, &portp->state);
2261 EBRDDISABLE(brdp);
Alan Cox4ac43602006-06-28 04:26:52 -07002262 spin_unlock_irqrestore(&brd_lock, flags);
2263}
2264
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002265static void stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback)
Alan Cox4ac43602006-06-28 04:26:52 -07002266{
2267 unsigned long flags;
2268
2269 spin_lock_irqsave(&brd_lock, flags);
2270 __stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
2271 spin_unlock_irqrestore(&brd_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272}
2273
2274/*****************************************************************************/
2275
2276/*
2277 * Read data from shared memory. This assumes that the shared memory
2278 * is enabled and that interrupts are off. Basically we just empty out
2279 * the shared memory buffer into the tty buffer. Must be careful to
2280 * handle the case where we fill up the tty buffer, but still have
2281 * more chars to unload.
2282 */
2283
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002284static void stli_read(struct stlibrd *brdp, struct stliport *portp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285{
Alan Cox4ac43602006-06-28 04:26:52 -07002286 cdkasyrq_t __iomem *rp;
2287 char __iomem *shbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 struct tty_struct *tty;
Alan Cox4ac43602006-06-28 04:26:52 -07002289 unsigned int head, tail, size;
2290 unsigned int len, stlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291
2292 if (test_bit(ST_RXSTOP, &portp->state))
2293 return;
2294 tty = portp->tty;
Alan Cox4ac43602006-06-28 04:26:52 -07002295 if (tty == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296 return;
2297
Alan Cox4ac43602006-06-28 04:26:52 -07002298 rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
2299 head = (unsigned int) readw(&rp->head);
2300 if (head != ((unsigned int) readw(&rp->head)))
2301 head = (unsigned int) readw(&rp->head);
2302 tail = (unsigned int) readw(&rp->tail);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 size = portp->rxsize;
2304 if (head >= tail) {
2305 len = head - tail;
2306 stlen = len;
2307 } else {
2308 len = size - (tail - head);
2309 stlen = size - tail;
2310 }
2311
Alan Cox33f0f882006-01-09 20:54:13 -08002312 len = tty_buffer_request_room(tty, len);
Alan Cox4ac43602006-06-28 04:26:52 -07002313
2314 shbuf = (char __iomem *) EBRDGETMEMPTR(brdp, portp->rxoffset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315
2316 while (len > 0) {
Alan Cox4ac43602006-06-28 04:26:52 -07002317 unsigned char *cptr;
2318
Jiri Slabya3f8d9d2006-12-08 02:39:18 -08002319 stlen = min(len, stlen);
Alan Cox4ac43602006-06-28 04:26:52 -07002320 tty_prepare_flip_string(tty, &cptr, stlen);
2321 memcpy_fromio(cptr, shbuf + tail, stlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 len -= stlen;
2323 tail += stlen;
2324 if (tail >= size) {
2325 tail = 0;
2326 stlen = head;
2327 }
2328 }
Alan Cox4ac43602006-06-28 04:26:52 -07002329 rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
2330 writew(tail, &rp->tail);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331
2332 if (head != tail)
2333 set_bit(ST_RXING, &portp->state);
2334
2335 tty_schedule_flip(tty);
2336}
2337
2338/*****************************************************************************/
2339
2340/*
2341 * Set up and carry out any delayed commands. There is only a small set
2342 * of slave commands that can be done "off-level". So it is not too
2343 * difficult to deal with them here.
2344 */
2345
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002346static void stli_dodelaycmd(struct stliport *portp, cdkctrl_t __iomem *cp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347{
Alan Cox4ac43602006-06-28 04:26:52 -07002348 int cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349
2350 if (test_bit(ST_DOSIGS, &portp->state)) {
2351 if (test_bit(ST_DOFLUSHTX, &portp->state) &&
2352 test_bit(ST_DOFLUSHRX, &portp->state))
2353 cmd = A_SETSIGNALSF;
2354 else if (test_bit(ST_DOFLUSHTX, &portp->state))
2355 cmd = A_SETSIGNALSFTX;
2356 else if (test_bit(ST_DOFLUSHRX, &portp->state))
2357 cmd = A_SETSIGNALSFRX;
2358 else
2359 cmd = A_SETSIGNALS;
2360 clear_bit(ST_DOFLUSHTX, &portp->state);
2361 clear_bit(ST_DOFLUSHRX, &portp->state);
2362 clear_bit(ST_DOSIGS, &portp->state);
Alan Cox4ac43602006-06-28 04:26:52 -07002363 memcpy_toio((void __iomem *) &(cp->args[0]), (void *) &portp->asig,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364 sizeof(asysigs_t));
Alan Cox4ac43602006-06-28 04:26:52 -07002365 writel(0, &cp->status);
2366 writel(cmd, &cp->cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 set_bit(ST_CMDING, &portp->state);
2368 } else if (test_bit(ST_DOFLUSHTX, &portp->state) ||
2369 test_bit(ST_DOFLUSHRX, &portp->state)) {
2370 cmd = ((test_bit(ST_DOFLUSHTX, &portp->state)) ? FLUSHTX : 0);
2371 cmd |= ((test_bit(ST_DOFLUSHRX, &portp->state)) ? FLUSHRX : 0);
2372 clear_bit(ST_DOFLUSHTX, &portp->state);
2373 clear_bit(ST_DOFLUSHRX, &portp->state);
Alan Cox4ac43602006-06-28 04:26:52 -07002374 memcpy_toio((void __iomem *) &(cp->args[0]), (void *) &cmd, sizeof(int));
2375 writel(0, &cp->status);
2376 writel(A_FLUSH, &cp->cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377 set_bit(ST_CMDING, &portp->state);
2378 }
2379}
2380
2381/*****************************************************************************/
2382
2383/*
2384 * Host command service checking. This handles commands or messages
2385 * coming from the slave to the host. Must have board shared memory
2386 * enabled and interrupts off when called. Notice that by servicing the
2387 * read data last we don't need to change the shared memory pointer
2388 * during processing (which is a slow IO operation).
2389 * Return value indicates if this port is still awaiting actions from
2390 * the slave (like open, command, or even TX data being sent). If 0
2391 * then port is still busy, otherwise no longer busy.
2392 */
2393
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002394static int stli_hostcmd(struct stlibrd *brdp, struct stliport *portp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395{
Alan Cox4ac43602006-06-28 04:26:52 -07002396 cdkasy_t __iomem *ap;
2397 cdkctrl_t __iomem *cp;
2398 struct tty_struct *tty;
2399 asynotify_t nt;
2400 unsigned long oldsigs;
2401 int rc, donerx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402
Alan Cox4ac43602006-06-28 04:26:52 -07002403 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404 cp = &ap->ctrl;
2405
2406/*
2407 * Check if we are waiting for an open completion message.
2408 */
2409 if (test_bit(ST_OPENING, &portp->state)) {
Alan Cox4ac43602006-06-28 04:26:52 -07002410 rc = readl(&cp->openarg);
2411 if (readb(&cp->open) == 0 && rc != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 if (rc > 0)
2413 rc--;
Alan Cox4ac43602006-06-28 04:26:52 -07002414 writel(0, &cp->openarg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 portp->rc = rc;
2416 clear_bit(ST_OPENING, &portp->state);
2417 wake_up_interruptible(&portp->raw_wait);
2418 }
2419 }
2420
2421/*
2422 * Check if we are waiting for a close completion message.
2423 */
2424 if (test_bit(ST_CLOSING, &portp->state)) {
Alan Cox4ac43602006-06-28 04:26:52 -07002425 rc = (int) readl(&cp->closearg);
2426 if (readb(&cp->close) == 0 && rc != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427 if (rc > 0)
2428 rc--;
Alan Cox4ac43602006-06-28 04:26:52 -07002429 writel(0, &cp->closearg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 portp->rc = rc;
2431 clear_bit(ST_CLOSING, &portp->state);
2432 wake_up_interruptible(&portp->raw_wait);
2433 }
2434 }
2435
2436/*
2437 * Check if we are waiting for a command completion message. We may
2438 * need to copy out the command results associated with this command.
2439 */
2440 if (test_bit(ST_CMDING, &portp->state)) {
Alan Cox4ac43602006-06-28 04:26:52 -07002441 rc = readl(&cp->status);
2442 if (readl(&cp->cmd) == 0 && rc != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 if (rc > 0)
2444 rc--;
Alan Cox4ac43602006-06-28 04:26:52 -07002445 if (portp->argp != NULL) {
2446 memcpy_fromio(portp->argp, (void __iomem *) &(cp->args[0]),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 portp->argsize);
Alan Cox4ac43602006-06-28 04:26:52 -07002448 portp->argp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 }
Alan Cox4ac43602006-06-28 04:26:52 -07002450 writel(0, &cp->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451 portp->rc = rc;
2452 clear_bit(ST_CMDING, &portp->state);
2453 stli_dodelaycmd(portp, cp);
2454 wake_up_interruptible(&portp->raw_wait);
2455 }
2456 }
2457
2458/*
2459 * Check for any notification messages ready. This includes lots of
2460 * different types of events - RX chars ready, RX break received,
2461 * TX data low or empty in the slave, modem signals changed state.
2462 */
2463 donerx = 0;
2464
2465 if (ap->notify) {
2466 nt = ap->changed;
2467 ap->notify = 0;
2468 tty = portp->tty;
2469
2470 if (nt.signal & SG_DCD) {
2471 oldsigs = portp->sigs;
2472 portp->sigs = stli_mktiocm(nt.sigvalue);
2473 clear_bit(ST_GETSIGS, &portp->state);
2474 if ((portp->sigs & TIOCM_CD) &&
2475 ((oldsigs & TIOCM_CD) == 0))
2476 wake_up_interruptible(&portp->open_wait);
2477 if ((oldsigs & TIOCM_CD) &&
2478 ((portp->sigs & TIOCM_CD) == 0)) {
2479 if (portp->flags & ASYNC_CHECK_CD) {
2480 if (tty)
2481 schedule_work(&portp->tqhangup);
2482 }
2483 }
2484 }
2485
2486 if (nt.data & DT_TXEMPTY)
2487 clear_bit(ST_TXBUSY, &portp->state);
2488 if (nt.data & (DT_TXEMPTY | DT_TXLOW)) {
Alan Cox4ac43602006-06-28 04:26:52 -07002489 if (tty != NULL) {
2490 tty_wakeup(tty);
2491 EBRDENABLE(brdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 wake_up_interruptible(&tty->write_wait);
2493 }
2494 }
2495
2496 if ((nt.data & DT_RXBREAK) && (portp->rxmarkmsk & BRKINT)) {
Alan Cox4ac43602006-06-28 04:26:52 -07002497 if (tty != NULL) {
Alan Cox33f0f882006-01-09 20:54:13 -08002498 tty_insert_flip_char(tty, 0, TTY_BREAK);
2499 if (portp->flags & ASYNC_SAK) {
2500 do_SAK(tty);
2501 EBRDENABLE(brdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502 }
Alan Cox33f0f882006-01-09 20:54:13 -08002503 tty_schedule_flip(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 }
2505 }
2506
2507 if (nt.data & DT_RXBUSY) {
2508 donerx++;
2509 stli_read(brdp, portp);
2510 }
2511 }
2512
2513/*
2514 * It might seem odd that we are checking for more RX chars here.
2515 * But, we need to handle the case where the tty buffer was previously
2516 * filled, but we had more characters to pass up. The slave will not
2517 * send any more RX notify messages until the RX buffer has been emptied.
2518 * But it will leave the service bits on (since the buffer is not empty).
2519 * So from here we can try to process more RX chars.
2520 */
2521 if ((!donerx) && test_bit(ST_RXING, &portp->state)) {
2522 clear_bit(ST_RXING, &portp->state);
2523 stli_read(brdp, portp);
2524 }
2525
2526 return((test_bit(ST_OPENING, &portp->state) ||
2527 test_bit(ST_CLOSING, &portp->state) ||
2528 test_bit(ST_CMDING, &portp->state) ||
2529 test_bit(ST_TXBUSY, &portp->state) ||
2530 test_bit(ST_RXING, &portp->state)) ? 0 : 1);
2531}
2532
2533/*****************************************************************************/
2534
2535/*
2536 * Service all ports on a particular board. Assumes that the boards
2537 * shared memory is enabled, and that the page pointer is pointed
2538 * at the cdk header structure.
2539 */
2540
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002541static void stli_brdpoll(struct stlibrd *brdp, cdkhdr_t __iomem *hdrp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002543 struct stliport *portp;
Alan Cox4ac43602006-06-28 04:26:52 -07002544 unsigned char hostbits[(STL_MAXCHANS / 8) + 1];
2545 unsigned char slavebits[(STL_MAXCHANS / 8) + 1];
2546 unsigned char __iomem *slavep;
2547 int bitpos, bitat, bitsize;
2548 int channr, nrdevs, slavebitchange;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549
2550 bitsize = brdp->bitsize;
2551 nrdevs = brdp->nrdevs;
2552
2553/*
2554 * Check if slave wants any service. Basically we try to do as
2555 * little work as possible here. There are 2 levels of service
2556 * bits. So if there is nothing to do we bail early. We check
2557 * 8 service bits at a time in the inner loop, so we can bypass
2558 * the lot if none of them want service.
2559 */
Alan Cox4ac43602006-06-28 04:26:52 -07002560 memcpy_fromio(&hostbits[0], (((unsigned char __iomem *) hdrp) + brdp->hostoffset),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561 bitsize);
2562
2563 memset(&slavebits[0], 0, bitsize);
2564 slavebitchange = 0;
2565
2566 for (bitpos = 0; (bitpos < bitsize); bitpos++) {
2567 if (hostbits[bitpos] == 0)
2568 continue;
2569 channr = bitpos * 8;
2570 for (bitat = 0x1; (channr < nrdevs); channr++, bitat <<= 1) {
2571 if (hostbits[bitpos] & bitat) {
2572 portp = brdp->ports[(channr - 1)];
2573 if (stli_hostcmd(brdp, portp)) {
2574 slavebitchange++;
2575 slavebits[bitpos] |= bitat;
2576 }
2577 }
2578 }
2579 }
2580
2581/*
2582 * If any of the ports are no longer busy then update them in the
2583 * slave request bits. We need to do this after, since a host port
2584 * service may initiate more slave requests.
2585 */
2586 if (slavebitchange) {
Alan Cox4ac43602006-06-28 04:26:52 -07002587 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2588 slavep = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589 for (bitpos = 0; (bitpos < bitsize); bitpos++) {
Alan Cox4ac43602006-06-28 04:26:52 -07002590 if (readb(slavebits + bitpos))
2591 writeb(readb(slavep + bitpos) & ~slavebits[bitpos], slavebits + bitpos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 }
2593 }
2594}
2595
2596/*****************************************************************************/
2597
2598/*
2599 * Driver poll routine. This routine polls the boards in use and passes
2600 * messages back up to host when necessary. This is actually very
2601 * CPU efficient, since we will always have the kernel poll clock, it
2602 * adds only a few cycles when idle (since board service can be
2603 * determined very easily), but when loaded generates no interrupts
2604 * (with their expensive associated context change).
2605 */
2606
2607static void stli_poll(unsigned long arg)
2608{
Alan Cox4ac43602006-06-28 04:26:52 -07002609 cdkhdr_t __iomem *hdrp;
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002610 struct stlibrd *brdp;
Jiri Slaby1328d732006-12-08 02:39:19 -08002611 unsigned int brdnr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612
2613 stli_timerlist.expires = STLI_TIMEOUT;
2614 add_timer(&stli_timerlist);
2615
2616/*
2617 * Check each board and do any servicing required.
2618 */
2619 for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
2620 brdp = stli_brds[brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07002621 if (brdp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622 continue;
2623 if ((brdp->state & BST_STARTED) == 0)
2624 continue;
2625
Alan Cox4ac43602006-06-28 04:26:52 -07002626 spin_lock(&brd_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 EBRDENABLE(brdp);
Alan Cox4ac43602006-06-28 04:26:52 -07002628 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2629 if (readb(&hdrp->hostreq))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630 stli_brdpoll(brdp, hdrp);
2631 EBRDDISABLE(brdp);
Alan Cox4ac43602006-06-28 04:26:52 -07002632 spin_unlock(&brd_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633 }
2634}
2635
2636/*****************************************************************************/
2637
2638/*
2639 * Translate the termios settings into the port setting structure of
2640 * the slave.
2641 */
2642
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002643static void stli_mkasyport(struct stliport *portp, asyport_t *pp, struct ktermios *tiosp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 memset(pp, 0, sizeof(asyport_t));
2646
2647/*
2648 * Start of by setting the baud, char size, parity and stop bit info.
2649 */
Alan Cox1db27c12006-09-29 02:01:38 -07002650 pp->baudout = tty_get_baud_rate(portp->tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 if ((tiosp->c_cflag & CBAUD) == B38400) {
2652 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
2653 pp->baudout = 57600;
2654 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
2655 pp->baudout = 115200;
2656 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
2657 pp->baudout = 230400;
2658 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
2659 pp->baudout = 460800;
2660 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
2661 pp->baudout = (portp->baud_base / portp->custom_divisor);
2662 }
2663 if (pp->baudout > STL_MAXBAUD)
2664 pp->baudout = STL_MAXBAUD;
2665 pp->baudin = pp->baudout;
2666
2667 switch (tiosp->c_cflag & CSIZE) {
2668 case CS5:
2669 pp->csize = 5;
2670 break;
2671 case CS6:
2672 pp->csize = 6;
2673 break;
2674 case CS7:
2675 pp->csize = 7;
2676 break;
2677 default:
2678 pp->csize = 8;
2679 break;
2680 }
2681
2682 if (tiosp->c_cflag & CSTOPB)
2683 pp->stopbs = PT_STOP2;
2684 else
2685 pp->stopbs = PT_STOP1;
2686
2687 if (tiosp->c_cflag & PARENB) {
2688 if (tiosp->c_cflag & PARODD)
2689 pp->parity = PT_ODDPARITY;
2690 else
2691 pp->parity = PT_EVENPARITY;
2692 } else {
2693 pp->parity = PT_NOPARITY;
2694 }
2695
2696/*
2697 * Set up any flow control options enabled.
2698 */
2699 if (tiosp->c_iflag & IXON) {
2700 pp->flow |= F_IXON;
2701 if (tiosp->c_iflag & IXANY)
2702 pp->flow |= F_IXANY;
2703 }
2704 if (tiosp->c_cflag & CRTSCTS)
2705 pp->flow |= (F_RTSFLOW | F_CTSFLOW);
2706
2707 pp->startin = tiosp->c_cc[VSTART];
2708 pp->stopin = tiosp->c_cc[VSTOP];
2709 pp->startout = tiosp->c_cc[VSTART];
2710 pp->stopout = tiosp->c_cc[VSTOP];
2711
2712/*
2713 * Set up the RX char marking mask with those RX error types we must
2714 * catch. We can get the slave to help us out a little here, it will
2715 * ignore parity errors and breaks for us, and mark parity errors in
2716 * the data stream.
2717 */
2718 if (tiosp->c_iflag & IGNPAR)
2719 pp->iflag |= FI_IGNRXERRS;
2720 if (tiosp->c_iflag & IGNBRK)
2721 pp->iflag |= FI_IGNBREAK;
2722
2723 portp->rxmarkmsk = 0;
2724 if (tiosp->c_iflag & (INPCK | PARMRK))
2725 pp->iflag |= FI_1MARKRXERRS;
2726 if (tiosp->c_iflag & BRKINT)
2727 portp->rxmarkmsk |= BRKINT;
2728
2729/*
2730 * Set up clocal processing as required.
2731 */
2732 if (tiosp->c_cflag & CLOCAL)
2733 portp->flags &= ~ASYNC_CHECK_CD;
2734 else
2735 portp->flags |= ASYNC_CHECK_CD;
2736
2737/*
2738 * Transfer any persistent flags into the asyport structure.
2739 */
2740 pp->pflag = (portp->pflag & 0xffff);
2741 pp->vmin = (portp->pflag & P_RXIMIN) ? 1 : 0;
2742 pp->vtime = (portp->pflag & P_RXITIME) ? 1 : 0;
2743 pp->cc[1] = (portp->pflag & P_RXTHOLD) ? 1 : 0;
2744}
2745
2746/*****************************************************************************/
2747
2748/*
2749 * Construct a slave signals structure for setting the DTR and RTS
2750 * signals as specified.
2751 */
2752
2753static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts)
2754{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755 memset(sp, 0, sizeof(asysigs_t));
2756 if (dtr >= 0) {
2757 sp->signal |= SG_DTR;
2758 sp->sigvalue |= ((dtr > 0) ? SG_DTR : 0);
2759 }
2760 if (rts >= 0) {
2761 sp->signal |= SG_RTS;
2762 sp->sigvalue |= ((rts > 0) ? SG_RTS : 0);
2763 }
2764}
2765
2766/*****************************************************************************/
2767
2768/*
2769 * Convert the signals returned from the slave into a local TIOCM type
2770 * signals value. We keep them locally in TIOCM format.
2771 */
2772
2773static long stli_mktiocm(unsigned long sigvalue)
2774{
Alan Cox4ac43602006-06-28 04:26:52 -07002775 long tiocm = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776 tiocm |= ((sigvalue & SG_DCD) ? TIOCM_CD : 0);
2777 tiocm |= ((sigvalue & SG_CTS) ? TIOCM_CTS : 0);
2778 tiocm |= ((sigvalue & SG_RI) ? TIOCM_RI : 0);
2779 tiocm |= ((sigvalue & SG_DSR) ? TIOCM_DSR : 0);
2780 tiocm |= ((sigvalue & SG_DTR) ? TIOCM_DTR : 0);
2781 tiocm |= ((sigvalue & SG_RTS) ? TIOCM_RTS : 0);
2782 return(tiocm);
2783}
2784
2785/*****************************************************************************/
2786
2787/*
2788 * All panels and ports actually attached have been worked out. All
2789 * we need to do here is set up the appropriate per port data structures.
2790 */
2791
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002792static int stli_initports(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002794 struct stliport *portp;
Jiri Slaby1328d732006-12-08 02:39:19 -08002795 unsigned int i, panelnr, panelport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797 for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) {
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002798 portp = kzalloc(sizeof(struct stliport), GFP_KERNEL);
Tobias Klauserb0b4ed72006-03-31 02:30:56 -08002799 if (!portp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800 printk("STALLION: failed to allocate port structure\n");
2801 continue;
2802 }
2803
Linus Torvalds1da177e2005-04-16 15:20:36 -07002804 portp->magic = STLI_PORTMAGIC;
2805 portp->portnr = i;
2806 portp->brdnr = brdp->brdnr;
2807 portp->panelnr = panelnr;
2808 portp->baud_base = STL_BAUDBASE;
2809 portp->close_delay = STL_CLOSEDELAY;
2810 portp->closing_wait = 30 * HZ;
Al Viro3e577a82006-12-06 18:41:45 +00002811 INIT_WORK(&portp->tqhangup, stli_dohangup);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812 init_waitqueue_head(&portp->open_wait);
2813 init_waitqueue_head(&portp->close_wait);
2814 init_waitqueue_head(&portp->raw_wait);
2815 panelport++;
2816 if (panelport >= brdp->panels[panelnr]) {
2817 panelport = 0;
2818 panelnr++;
2819 }
2820 brdp->ports[i] = portp;
2821 }
2822
Alan Cox4ac43602006-06-28 04:26:52 -07002823 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824}
2825
2826/*****************************************************************************/
2827
2828/*
2829 * All the following routines are board specific hardware operations.
2830 */
2831
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002832static void stli_ecpinit(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833{
2834 unsigned long memconf;
2835
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836 outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
2837 udelay(10);
2838 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
2839 udelay(100);
2840
2841 memconf = (brdp->memaddr & ECP_ATADDRMASK) >> ECP_ATADDRSHFT;
2842 outb(memconf, (brdp->iobase + ECP_ATMEMAR));
2843}
2844
2845/*****************************************************************************/
2846
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002847static void stli_ecpenable(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849 outb(ECP_ATENABLE, (brdp->iobase + ECP_ATCONFR));
2850}
2851
2852/*****************************************************************************/
2853
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002854static void stli_ecpdisable(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
2857}
2858
2859/*****************************************************************************/
2860
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002861static void __iomem *stli_ecpgetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862{
Al Viro29756fa2006-10-10 22:47:27 +01002863 void __iomem *ptr;
Alan Cox4ac43602006-06-28 04:26:52 -07002864 unsigned char val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865
2866 if (offset > brdp->memsize) {
2867 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
2868 "range at line=%d(%d), brd=%d\n",
2869 (int) offset, line, __LINE__, brdp->brdnr);
2870 ptr = NULL;
2871 val = 0;
2872 } else {
2873 ptr = brdp->membase + (offset % ECP_ATPAGESIZE);
2874 val = (unsigned char) (offset / ECP_ATPAGESIZE);
2875 }
2876 outb(val, (brdp->iobase + ECP_ATMEMPR));
2877 return(ptr);
2878}
2879
2880/*****************************************************************************/
2881
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002882static void stli_ecpreset(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884 outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
2885 udelay(10);
2886 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
2887 udelay(500);
2888}
2889
2890/*****************************************************************************/
2891
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002892static void stli_ecpintr(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894 outb(0x1, brdp->iobase);
2895}
2896
2897/*****************************************************************************/
2898
2899/*
2900 * The following set of functions act on ECP EISA boards.
2901 */
2902
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002903static void stli_ecpeiinit(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904{
2905 unsigned long memconf;
2906
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907 outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
2908 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
2909 udelay(10);
2910 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
2911 udelay(500);
2912
2913 memconf = (brdp->memaddr & ECP_EIADDRMASKL) >> ECP_EIADDRSHFTL;
2914 outb(memconf, (brdp->iobase + ECP_EIMEMARL));
2915 memconf = (brdp->memaddr & ECP_EIADDRMASKH) >> ECP_EIADDRSHFTH;
2916 outb(memconf, (brdp->iobase + ECP_EIMEMARH));
2917}
2918
2919/*****************************************************************************/
2920
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002921static void stli_ecpeienable(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922{
2923 outb(ECP_EIENABLE, (brdp->iobase + ECP_EICONFR));
2924}
2925
2926/*****************************************************************************/
2927
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002928static void stli_ecpeidisable(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929{
2930 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
2931}
2932
2933/*****************************************************************************/
2934
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002935static void __iomem *stli_ecpeigetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936{
Al Viro29756fa2006-10-10 22:47:27 +01002937 void __iomem *ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938 unsigned char val;
2939
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940 if (offset > brdp->memsize) {
2941 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
2942 "range at line=%d(%d), brd=%d\n",
2943 (int) offset, line, __LINE__, brdp->brdnr);
2944 ptr = NULL;
2945 val = 0;
2946 } else {
2947 ptr = brdp->membase + (offset % ECP_EIPAGESIZE);
2948 if (offset < ECP_EIPAGESIZE)
2949 val = ECP_EIENABLE;
2950 else
2951 val = ECP_EIENABLE | 0x40;
2952 }
2953 outb(val, (brdp->iobase + ECP_EICONFR));
2954 return(ptr);
2955}
2956
2957/*****************************************************************************/
2958
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002959static void stli_ecpeireset(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960{
2961 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
2962 udelay(10);
2963 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
2964 udelay(500);
2965}
2966
2967/*****************************************************************************/
2968
2969/*
2970 * The following set of functions act on ECP MCA boards.
2971 */
2972
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002973static void stli_ecpmcenable(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974{
2975 outb(ECP_MCENABLE, (brdp->iobase + ECP_MCCONFR));
2976}
2977
2978/*****************************************************************************/
2979
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002980static void stli_ecpmcdisable(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981{
2982 outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
2983}
2984
2985/*****************************************************************************/
2986
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002987static void __iomem *stli_ecpmcgetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988{
Al Viro29756fa2006-10-10 22:47:27 +01002989 void __iomem *ptr;
Alan Cox4ac43602006-06-28 04:26:52 -07002990 unsigned char val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991
2992 if (offset > brdp->memsize) {
2993 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
2994 "range at line=%d(%d), brd=%d\n",
2995 (int) offset, line, __LINE__, brdp->brdnr);
2996 ptr = NULL;
2997 val = 0;
2998 } else {
2999 ptr = brdp->membase + (offset % ECP_MCPAGESIZE);
3000 val = ((unsigned char) (offset / ECP_MCPAGESIZE)) | ECP_MCENABLE;
3001 }
3002 outb(val, (brdp->iobase + ECP_MCCONFR));
3003 return(ptr);
3004}
3005
3006/*****************************************************************************/
3007
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003008static void stli_ecpmcreset(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009{
3010 outb(ECP_MCSTOP, (brdp->iobase + ECP_MCCONFR));
3011 udelay(10);
3012 outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
3013 udelay(500);
3014}
3015
3016/*****************************************************************************/
3017
3018/*
3019 * The following set of functions act on ECP PCI boards.
3020 */
3021
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003022static void stli_ecppciinit(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024 outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
3025 udelay(10);
3026 outb(0, (brdp->iobase + ECP_PCICONFR));
3027 udelay(500);
3028}
3029
3030/*****************************************************************************/
3031
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003032static void __iomem *stli_ecppcigetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033{
Al Viro29756fa2006-10-10 22:47:27 +01003034 void __iomem *ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035 unsigned char val;
3036
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037 if (offset > brdp->memsize) {
3038 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3039 "range at line=%d(%d), board=%d\n",
3040 (int) offset, line, __LINE__, brdp->brdnr);
3041 ptr = NULL;
3042 val = 0;
3043 } else {
3044 ptr = brdp->membase + (offset % ECP_PCIPAGESIZE);
3045 val = (offset / ECP_PCIPAGESIZE) << 1;
3046 }
3047 outb(val, (brdp->iobase + ECP_PCICONFR));
3048 return(ptr);
3049}
3050
3051/*****************************************************************************/
3052
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003053static void stli_ecppcireset(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054{
3055 outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
3056 udelay(10);
3057 outb(0, (brdp->iobase + ECP_PCICONFR));
3058 udelay(500);
3059}
3060
3061/*****************************************************************************/
3062
3063/*
3064 * The following routines act on ONboards.
3065 */
3066
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003067static void stli_onbinit(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068{
3069 unsigned long memconf;
3070
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071 outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
3072 udelay(10);
3073 outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
3074 mdelay(1000);
3075
3076 memconf = (brdp->memaddr & ONB_ATADDRMASK) >> ONB_ATADDRSHFT;
3077 outb(memconf, (brdp->iobase + ONB_ATMEMAR));
3078 outb(0x1, brdp->iobase);
3079 mdelay(1);
3080}
3081
3082/*****************************************************************************/
3083
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003084static void stli_onbenable(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003085{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003086 outb((brdp->enabval | ONB_ATENABLE), (brdp->iobase + ONB_ATCONFR));
3087}
3088
3089/*****************************************************************************/
3090
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003091static void stli_onbdisable(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093 outb((brdp->enabval | ONB_ATDISABLE), (brdp->iobase + ONB_ATCONFR));
3094}
3095
3096/*****************************************************************************/
3097
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003098static void __iomem *stli_onbgetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099{
Al Viro29756fa2006-10-10 22:47:27 +01003100 void __iomem *ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101
Linus Torvalds1da177e2005-04-16 15:20:36 -07003102 if (offset > brdp->memsize) {
3103 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3104 "range at line=%d(%d), brd=%d\n",
3105 (int) offset, line, __LINE__, brdp->brdnr);
3106 ptr = NULL;
3107 } else {
3108 ptr = brdp->membase + (offset % ONB_ATPAGESIZE);
3109 }
3110 return(ptr);
3111}
3112
3113/*****************************************************************************/
3114
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003115static void stli_onbreset(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117 outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
3118 udelay(10);
3119 outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
3120 mdelay(1000);
3121}
3122
3123/*****************************************************************************/
3124
3125/*
3126 * The following routines act on ONboard EISA.
3127 */
3128
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003129static void stli_onbeinit(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130{
3131 unsigned long memconf;
3132
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133 outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
3134 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3135 udelay(10);
3136 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3137 mdelay(1000);
3138
3139 memconf = (brdp->memaddr & ONB_EIADDRMASKL) >> ONB_EIADDRSHFTL;
3140 outb(memconf, (brdp->iobase + ONB_EIMEMARL));
3141 memconf = (brdp->memaddr & ONB_EIADDRMASKH) >> ONB_EIADDRSHFTH;
3142 outb(memconf, (brdp->iobase + ONB_EIMEMARH));
3143 outb(0x1, brdp->iobase);
3144 mdelay(1);
3145}
3146
3147/*****************************************************************************/
3148
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003149static void stli_onbeenable(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151 outb(ONB_EIENABLE, (brdp->iobase + ONB_EICONFR));
3152}
3153
3154/*****************************************************************************/
3155
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003156static void stli_onbedisable(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3159}
3160
3161/*****************************************************************************/
3162
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003163static void __iomem *stli_onbegetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003164{
Al Viro29756fa2006-10-10 22:47:27 +01003165 void __iomem *ptr;
Alan Cox4ac43602006-06-28 04:26:52 -07003166 unsigned char val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167
3168 if (offset > brdp->memsize) {
3169 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3170 "range at line=%d(%d), brd=%d\n",
3171 (int) offset, line, __LINE__, brdp->brdnr);
3172 ptr = NULL;
3173 val = 0;
3174 } else {
3175 ptr = brdp->membase + (offset % ONB_EIPAGESIZE);
3176 if (offset < ONB_EIPAGESIZE)
3177 val = ONB_EIENABLE;
3178 else
3179 val = ONB_EIENABLE | 0x40;
3180 }
3181 outb(val, (brdp->iobase + ONB_EICONFR));
3182 return(ptr);
3183}
3184
3185/*****************************************************************************/
3186
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003187static void stli_onbereset(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003188{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3190 udelay(10);
3191 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3192 mdelay(1000);
3193}
3194
3195/*****************************************************************************/
3196
3197/*
3198 * The following routines act on Brumby boards.
3199 */
3200
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003201static void stli_bbyinit(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
3204 udelay(10);
3205 outb(0, (brdp->iobase + BBY_ATCONFR));
3206 mdelay(1000);
3207 outb(0x1, brdp->iobase);
3208 mdelay(1);
3209}
3210
3211/*****************************************************************************/
3212
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003213static void __iomem *stli_bbygetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214{
Al Viro29756fa2006-10-10 22:47:27 +01003215 void __iomem *ptr;
Alan Cox4ac43602006-06-28 04:26:52 -07003216 unsigned char val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217
Alan Cox4ac43602006-06-28 04:26:52 -07003218 BUG_ON(offset > brdp->memsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219
Alan Cox4ac43602006-06-28 04:26:52 -07003220 ptr = brdp->membase + (offset % BBY_PAGESIZE);
3221 val = (unsigned char) (offset / BBY_PAGESIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222 outb(val, (brdp->iobase + BBY_ATCONFR));
3223 return(ptr);
3224}
3225
3226/*****************************************************************************/
3227
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003228static void stli_bbyreset(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
3231 udelay(10);
3232 outb(0, (brdp->iobase + BBY_ATCONFR));
3233 mdelay(1000);
3234}
3235
3236/*****************************************************************************/
3237
3238/*
3239 * The following routines act on original old Stallion boards.
3240 */
3241
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003242static void stli_stalinit(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244 outb(0x1, brdp->iobase);
3245 mdelay(1000);
3246}
3247
3248/*****************************************************************************/
3249
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003250static void __iomem *stli_stalgetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251{
Alan Cox4ac43602006-06-28 04:26:52 -07003252 BUG_ON(offset > brdp->memsize);
3253 return brdp->membase + (offset % STAL_PAGESIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254}
3255
3256/*****************************************************************************/
3257
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003258static void stli_stalreset(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259{
Alan Cox4ac43602006-06-28 04:26:52 -07003260 u32 __iomem *vecp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261
Alan Cox4ac43602006-06-28 04:26:52 -07003262 vecp = (u32 __iomem *) (brdp->membase + 0x30);
3263 writel(0xffff0000, vecp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264 outb(0, brdp->iobase);
3265 mdelay(1000);
3266}
3267
3268/*****************************************************************************/
3269
3270/*
3271 * Try to find an ECP board and initialize it. This handles only ECP
3272 * board types.
3273 */
3274
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003275static int stli_initecp(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276{
Alan Cox4ac43602006-06-28 04:26:52 -07003277 cdkecpsig_t sig;
3278 cdkecpsig_t __iomem *sigsp;
3279 unsigned int status, nxtid;
3280 char *name;
3281 int panelnr, nrports;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003282
3283 if (!request_region(brdp->iobase, brdp->iosize, "istallion"))
3284 return -EIO;
3285
3286 if ((brdp->iobase == 0) || (brdp->memaddr == 0))
3287 {
3288 release_region(brdp->iobase, brdp->iosize);
Alan Cox4ac43602006-06-28 04:26:52 -07003289 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290 }
3291
3292 brdp->iosize = ECP_IOSIZE;
3293
3294/*
3295 * Based on the specific board type setup the common vars to access
3296 * and enable shared memory. Set all board specific information now
3297 * as well.
3298 */
3299 switch (brdp->brdtype) {
3300 case BRD_ECP:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003301 brdp->memsize = ECP_MEMSIZE;
3302 brdp->pagesize = ECP_ATPAGESIZE;
3303 brdp->init = stli_ecpinit;
3304 brdp->enable = stli_ecpenable;
3305 brdp->reenable = stli_ecpenable;
3306 brdp->disable = stli_ecpdisable;
3307 brdp->getmemptr = stli_ecpgetmemptr;
3308 brdp->intr = stli_ecpintr;
3309 brdp->reset = stli_ecpreset;
3310 name = "serial(EC8/64)";
3311 break;
3312
3313 case BRD_ECPE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314 brdp->memsize = ECP_MEMSIZE;
3315 brdp->pagesize = ECP_EIPAGESIZE;
3316 brdp->init = stli_ecpeiinit;
3317 brdp->enable = stli_ecpeienable;
3318 brdp->reenable = stli_ecpeienable;
3319 brdp->disable = stli_ecpeidisable;
3320 brdp->getmemptr = stli_ecpeigetmemptr;
3321 brdp->intr = stli_ecpintr;
3322 brdp->reset = stli_ecpeireset;
3323 name = "serial(EC8/64-EI)";
3324 break;
3325
3326 case BRD_ECPMC:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003327 brdp->memsize = ECP_MEMSIZE;
3328 brdp->pagesize = ECP_MCPAGESIZE;
3329 brdp->init = NULL;
3330 brdp->enable = stli_ecpmcenable;
3331 brdp->reenable = stli_ecpmcenable;
3332 brdp->disable = stli_ecpmcdisable;
3333 brdp->getmemptr = stli_ecpmcgetmemptr;
3334 brdp->intr = stli_ecpintr;
3335 brdp->reset = stli_ecpmcreset;
3336 name = "serial(EC8/64-MCA)";
3337 break;
3338
3339 case BRD_ECPPCI:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003340 brdp->memsize = ECP_PCIMEMSIZE;
3341 brdp->pagesize = ECP_PCIPAGESIZE;
3342 brdp->init = stli_ecppciinit;
3343 brdp->enable = NULL;
3344 brdp->reenable = NULL;
3345 brdp->disable = NULL;
3346 brdp->getmemptr = stli_ecppcigetmemptr;
3347 brdp->intr = stli_ecpintr;
3348 brdp->reset = stli_ecppcireset;
3349 name = "serial(EC/RA-PCI)";
3350 break;
3351
3352 default:
3353 release_region(brdp->iobase, brdp->iosize);
Alan Cox4ac43602006-06-28 04:26:52 -07003354 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355 }
3356
3357/*
3358 * The per-board operations structure is all set up, so now let's go
3359 * and get the board operational. Firstly initialize board configuration
3360 * registers. Set the memory mapping info so we can get at the boards
3361 * shared memory.
3362 */
3363 EBRDINIT(brdp);
3364
3365 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
Alan Cox4ac43602006-06-28 04:26:52 -07003366 if (brdp->membase == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003367 {
3368 release_region(brdp->iobase, brdp->iosize);
Alan Cox4ac43602006-06-28 04:26:52 -07003369 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370 }
3371
3372/*
3373 * Now that all specific code is set up, enable the shared memory and
3374 * look for the a signature area that will tell us exactly what board
3375 * this is, and what it is connected to it.
3376 */
3377 EBRDENABLE(brdp);
Alan Cox4ac43602006-06-28 04:26:52 -07003378 sigsp = (cdkecpsig_t __iomem *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
Al Viro634965f2006-09-23 01:20:31 +01003379 memcpy_fromio(&sig, sigsp, sizeof(cdkecpsig_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003380 EBRDDISABLE(brdp);
3381
Alan Cox4ac43602006-06-28 04:26:52 -07003382 if (sig.magic != cpu_to_le32(ECP_MAGIC))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003383 {
3384 release_region(brdp->iobase, brdp->iosize);
Amol Ladaa8a8d62006-12-06 20:35:22 -08003385 iounmap(brdp->membase);
3386 brdp->membase = NULL;
Alan Cox4ac43602006-06-28 04:26:52 -07003387 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003388 }
3389
3390/*
3391 * Scan through the signature looking at the panels connected to the
3392 * board. Calculate the total number of ports as we go.
3393 */
3394 for (panelnr = 0, nxtid = 0; (panelnr < STL_MAXPANELS); panelnr++) {
3395 status = sig.panelid[nxtid];
3396 if ((status & ECH_PNLIDMASK) != nxtid)
3397 break;
3398
3399 brdp->panelids[panelnr] = status;
3400 nrports = (status & ECH_PNL16PORT) ? 16 : 8;
3401 if ((nrports == 16) && ((status & ECH_PNLXPID) == 0))
3402 nxtid++;
3403 brdp->panels[panelnr] = nrports;
3404 brdp->nrports += nrports;
3405 nxtid++;
3406 brdp->nrpanels++;
3407 }
3408
3409
3410 brdp->state |= BST_FOUND;
Alan Cox4ac43602006-06-28 04:26:52 -07003411 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003412}
3413
3414/*****************************************************************************/
3415
3416/*
3417 * Try to find an ONboard, Brumby or Stallion board and initialize it.
3418 * This handles only these board types.
3419 */
3420
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003421static int stli_initonb(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003422{
Alan Cox4ac43602006-06-28 04:26:52 -07003423 cdkonbsig_t sig;
3424 cdkonbsig_t __iomem *sigsp;
3425 char *name;
3426 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003427
3428/*
3429 * Do a basic sanity check on the IO and memory addresses.
3430 */
Alan Cox4ac43602006-06-28 04:26:52 -07003431 if (brdp->iobase == 0 || brdp->memaddr == 0)
3432 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003433
3434 brdp->iosize = ONB_IOSIZE;
3435
3436 if (!request_region(brdp->iobase, brdp->iosize, "istallion"))
3437 return -EIO;
3438
3439/*
3440 * Based on the specific board type setup the common vars to access
3441 * and enable shared memory. Set all board specific information now
3442 * as well.
3443 */
3444 switch (brdp->brdtype) {
3445 case BRD_ONBOARD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446 case BRD_ONBOARD2:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003447 brdp->memsize = ONB_MEMSIZE;
3448 brdp->pagesize = ONB_ATPAGESIZE;
3449 brdp->init = stli_onbinit;
3450 brdp->enable = stli_onbenable;
3451 brdp->reenable = stli_onbenable;
3452 brdp->disable = stli_onbdisable;
3453 brdp->getmemptr = stli_onbgetmemptr;
3454 brdp->intr = stli_ecpintr;
3455 brdp->reset = stli_onbreset;
3456 if (brdp->memaddr > 0x100000)
3457 brdp->enabval = ONB_MEMENABHI;
3458 else
3459 brdp->enabval = ONB_MEMENABLO;
3460 name = "serial(ONBoard)";
3461 break;
3462
3463 case BRD_ONBOARDE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003464 brdp->memsize = ONB_EIMEMSIZE;
3465 brdp->pagesize = ONB_EIPAGESIZE;
3466 brdp->init = stli_onbeinit;
3467 brdp->enable = stli_onbeenable;
3468 brdp->reenable = stli_onbeenable;
3469 brdp->disable = stli_onbedisable;
3470 brdp->getmemptr = stli_onbegetmemptr;
3471 brdp->intr = stli_ecpintr;
3472 brdp->reset = stli_onbereset;
3473 name = "serial(ONBoard/E)";
3474 break;
3475
3476 case BRD_BRUMBY4:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477 brdp->memsize = BBY_MEMSIZE;
3478 brdp->pagesize = BBY_PAGESIZE;
3479 brdp->init = stli_bbyinit;
3480 brdp->enable = NULL;
3481 brdp->reenable = NULL;
3482 brdp->disable = NULL;
3483 brdp->getmemptr = stli_bbygetmemptr;
3484 brdp->intr = stli_ecpintr;
3485 brdp->reset = stli_bbyreset;
3486 name = "serial(Brumby)";
3487 break;
3488
3489 case BRD_STALLION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003490 brdp->memsize = STAL_MEMSIZE;
3491 brdp->pagesize = STAL_PAGESIZE;
3492 brdp->init = stli_stalinit;
3493 brdp->enable = NULL;
3494 brdp->reenable = NULL;
3495 brdp->disable = NULL;
3496 brdp->getmemptr = stli_stalgetmemptr;
3497 brdp->intr = stli_ecpintr;
3498 brdp->reset = stli_stalreset;
3499 name = "serial(Stallion)";
3500 break;
3501
3502 default:
3503 release_region(brdp->iobase, brdp->iosize);
Alan Cox4ac43602006-06-28 04:26:52 -07003504 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003505 }
3506
3507/*
3508 * The per-board operations structure is all set up, so now let's go
3509 * and get the board operational. Firstly initialize board configuration
3510 * registers. Set the memory mapping info so we can get at the boards
3511 * shared memory.
3512 */
3513 EBRDINIT(brdp);
3514
3515 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
Alan Cox4ac43602006-06-28 04:26:52 -07003516 if (brdp->membase == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003517 {
3518 release_region(brdp->iobase, brdp->iosize);
Alan Cox4ac43602006-06-28 04:26:52 -07003519 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003520 }
3521
3522/*
3523 * Now that all specific code is set up, enable the shared memory and
3524 * look for the a signature area that will tell us exactly what board
3525 * this is, and how many ports.
3526 */
3527 EBRDENABLE(brdp);
Alan Cox4ac43602006-06-28 04:26:52 -07003528 sigsp = (cdkonbsig_t __iomem *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
3529 memcpy_fromio(&sig, sigsp, sizeof(cdkonbsig_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003530 EBRDDISABLE(brdp);
3531
Alan Cox4ac43602006-06-28 04:26:52 -07003532 if (sig.magic0 != cpu_to_le16(ONB_MAGIC0) ||
3533 sig.magic1 != cpu_to_le16(ONB_MAGIC1) ||
3534 sig.magic2 != cpu_to_le16(ONB_MAGIC2) ||
3535 sig.magic3 != cpu_to_le16(ONB_MAGIC3))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003536 {
3537 release_region(brdp->iobase, brdp->iosize);
Amol Ladaa8a8d62006-12-06 20:35:22 -08003538 iounmap(brdp->membase);
3539 brdp->membase = NULL;
Alan Cox4ac43602006-06-28 04:26:52 -07003540 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003541 }
3542
3543/*
3544 * Scan through the signature alive mask and calculate how many ports
3545 * there are on this board.
3546 */
3547 brdp->nrpanels = 1;
3548 if (sig.amask1) {
3549 brdp->nrports = 32;
3550 } else {
3551 for (i = 0; (i < 16); i++) {
3552 if (((sig.amask0 << i) & 0x8000) == 0)
3553 break;
3554 }
3555 brdp->nrports = i;
3556 }
3557 brdp->panels[0] = brdp->nrports;
3558
3559
3560 brdp->state |= BST_FOUND;
Alan Cox4ac43602006-06-28 04:26:52 -07003561 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003562}
3563
3564/*****************************************************************************/
3565
3566/*
3567 * Start up a running board. This routine is only called after the
3568 * code has been down loaded to the board and is operational. It will
3569 * read in the memory map, and get the show on the road...
3570 */
3571
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003572static int stli_startbrd(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003573{
Alan Cox4ac43602006-06-28 04:26:52 -07003574 cdkhdr_t __iomem *hdrp;
3575 cdkmem_t __iomem *memp;
3576 cdkasy_t __iomem *ap;
3577 unsigned long flags;
Jiri Slaby1328d732006-12-08 02:39:19 -08003578 unsigned int portnr, nrdevs, i;
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003579 struct stliport *portp;
Jiri Slaby1328d732006-12-08 02:39:19 -08003580 int rc = 0;
Alan Cox4ac43602006-06-28 04:26:52 -07003581 u32 memoff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003582
Alan Cox4ac43602006-06-28 04:26:52 -07003583 spin_lock_irqsave(&brd_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003584 EBRDENABLE(brdp);
Alan Cox4ac43602006-06-28 04:26:52 -07003585 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003586 nrdevs = hdrp->nrdevs;
3587
3588#if 0
3589 printk("%s(%d): CDK version %d.%d.%d --> "
3590 "nrdevs=%d memp=%x hostp=%x slavep=%x\n",
Alan Cox4ac43602006-06-28 04:26:52 -07003591 __FILE__, __LINE__, readb(&hdrp->ver_release), readb(&hdrp->ver_modification),
3592 readb(&hdrp->ver_fix), nrdevs, (int) readl(&hdrp->memp), readl(&hdrp->hostp),
3593 readl(&hdrp->slavep));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003594#endif
3595
3596 if (nrdevs < (brdp->nrports + 1)) {
3597 printk(KERN_ERR "STALLION: slave failed to allocate memory for "
3598 "all devices, devices=%d\n", nrdevs);
3599 brdp->nrports = nrdevs - 1;
3600 }
3601 brdp->nrdevs = nrdevs;
3602 brdp->hostoffset = hdrp->hostp - CDK_CDKADDR;
3603 brdp->slaveoffset = hdrp->slavep - CDK_CDKADDR;
3604 brdp->bitsize = (nrdevs + 7) / 8;
Alan Cox4ac43602006-06-28 04:26:52 -07003605 memoff = readl(&hdrp->memp);
3606 if (memoff > brdp->memsize) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003607 printk(KERN_ERR "STALLION: corrupted shared memory region?\n");
3608 rc = -EIO;
3609 goto stli_donestartup;
3610 }
Alan Cox4ac43602006-06-28 04:26:52 -07003611 memp = (cdkmem_t __iomem *) EBRDGETMEMPTR(brdp, memoff);
3612 if (readw(&memp->dtype) != TYP_ASYNCTRL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003613 printk(KERN_ERR "STALLION: no slave control device found\n");
3614 goto stli_donestartup;
3615 }
3616 memp++;
3617
3618/*
3619 * Cycle through memory allocation of each port. We are guaranteed to
3620 * have all ports inside the first page of slave window, so no need to
3621 * change pages while reading memory map.
3622 */
3623 for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++, memp++) {
Alan Cox4ac43602006-06-28 04:26:52 -07003624 if (readw(&memp->dtype) != TYP_ASYNC)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003625 break;
3626 portp = brdp->ports[portnr];
Alan Cox4ac43602006-06-28 04:26:52 -07003627 if (portp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003628 break;
3629 portp->devnr = i;
Alan Cox4ac43602006-06-28 04:26:52 -07003630 portp->addr = readl(&memp->offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003631 portp->reqbit = (unsigned char) (0x1 << (i * 8 / nrdevs));
3632 portp->portidx = (unsigned char) (i / 8);
3633 portp->portbit = (unsigned char) (0x1 << (i % 8));
3634 }
3635
Alan Cox4ac43602006-06-28 04:26:52 -07003636 writeb(0xff, &hdrp->slavereq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003637
3638/*
3639 * For each port setup a local copy of the RX and TX buffer offsets
3640 * and sizes. We do this separate from the above, because we need to
3641 * move the shared memory page...
3642 */
3643 for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++) {
3644 portp = brdp->ports[portnr];
Alan Cox4ac43602006-06-28 04:26:52 -07003645 if (portp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003646 break;
3647 if (portp->addr == 0)
3648 break;
Alan Cox4ac43602006-06-28 04:26:52 -07003649 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
3650 if (ap != NULL) {
3651 portp->rxsize = readw(&ap->rxq.size);
3652 portp->txsize = readw(&ap->txq.size);
3653 portp->rxoffset = readl(&ap->rxq.offset);
3654 portp->txoffset = readl(&ap->txq.offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003655 }
3656 }
3657
3658stli_donestartup:
3659 EBRDDISABLE(brdp);
Alan Cox4ac43602006-06-28 04:26:52 -07003660 spin_unlock_irqrestore(&brd_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003661
3662 if (rc == 0)
3663 brdp->state |= BST_STARTED;
3664
3665 if (! stli_timeron) {
3666 stli_timeron++;
3667 stli_timerlist.expires = STLI_TIMEOUT;
3668 add_timer(&stli_timerlist);
3669 }
3670
Alan Cox4ac43602006-06-28 04:26:52 -07003671 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003672}
3673
3674/*****************************************************************************/
3675
3676/*
3677 * Probe and initialize the specified board.
3678 */
3679
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003680static int __devinit stli_brdinit(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003681{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003682 switch (brdp->brdtype) {
3683 case BRD_ECP:
3684 case BRD_ECPE:
3685 case BRD_ECPMC:
3686 case BRD_ECPPCI:
3687 stli_initecp(brdp);
3688 break;
3689 case BRD_ONBOARD:
3690 case BRD_ONBOARDE:
3691 case BRD_ONBOARD2:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003692 case BRD_BRUMBY4:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003693 case BRD_STALLION:
3694 stli_initonb(brdp);
3695 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003696 default:
3697 printk(KERN_ERR "STALLION: board=%d is unknown board "
3698 "type=%d\n", brdp->brdnr, brdp->brdtype);
Alan Cox4ac43602006-06-28 04:26:52 -07003699 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003700 }
3701
3702 if ((brdp->state & BST_FOUND) == 0) {
3703 printk(KERN_ERR "STALLION: %s board not found, board=%d "
3704 "io=%x mem=%x\n",
3705 stli_brdnames[brdp->brdtype], brdp->brdnr,
3706 brdp->iobase, (int) brdp->memaddr);
Alan Cox4ac43602006-06-28 04:26:52 -07003707 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003708 }
3709
3710 stli_initports(brdp);
3711 printk(KERN_INFO "STALLION: %s found, board=%d io=%x mem=%x "
3712 "nrpanels=%d nrports=%d\n", stli_brdnames[brdp->brdtype],
3713 brdp->brdnr, brdp->iobase, (int) brdp->memaddr,
3714 brdp->nrpanels, brdp->nrports);
Alan Cox4ac43602006-06-28 04:26:52 -07003715 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003716}
3717
Jiri Slabya00f33f2006-12-08 02:39:20 -08003718#if STLI_EISAPROBE != 0
Linus Torvalds1da177e2005-04-16 15:20:36 -07003719/*****************************************************************************/
3720
3721/*
3722 * Probe around trying to find where the EISA boards shared memory
3723 * might be. This is a bit if hack, but it is the best we can do.
3724 */
3725
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003726static int stli_eisamemprobe(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003727{
Alan Cox4ac43602006-06-28 04:26:52 -07003728 cdkecpsig_t ecpsig, __iomem *ecpsigp;
3729 cdkonbsig_t onbsig, __iomem *onbsigp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003730 int i, foundit;
3731
Linus Torvalds1da177e2005-04-16 15:20:36 -07003732/*
3733 * First up we reset the board, to get it into a known state. There
3734 * is only 2 board types here we need to worry about. Don;t use the
3735 * standard board init routine here, it programs up the shared
3736 * memory address, and we don't know it yet...
3737 */
3738 if (brdp->brdtype == BRD_ECPE) {
3739 outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
3740 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
3741 udelay(10);
3742 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
3743 udelay(500);
3744 stli_ecpeienable(brdp);
3745 } else if (brdp->brdtype == BRD_ONBOARDE) {
3746 outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
3747 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3748 udelay(10);
3749 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3750 mdelay(100);
3751 outb(0x1, brdp->iobase);
3752 mdelay(1);
3753 stli_onbeenable(brdp);
3754 } else {
Alan Cox4ac43602006-06-28 04:26:52 -07003755 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003756 }
3757
3758 foundit = 0;
3759 brdp->memsize = ECP_MEMSIZE;
3760
3761/*
3762 * Board shared memory is enabled, so now we have a poke around and
3763 * see if we can find it.
3764 */
3765 for (i = 0; (i < stli_eisamempsize); i++) {
3766 brdp->memaddr = stli_eisamemprobeaddrs[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003767 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
Alan Cox4ac43602006-06-28 04:26:52 -07003768 if (brdp->membase == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003769 continue;
3770
3771 if (brdp->brdtype == BRD_ECPE) {
Al Viro29756fa2006-10-10 22:47:27 +01003772 ecpsigp = stli_ecpeigetmemptr(brdp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003773 CDK_SIGADDR, __LINE__);
Alan Cox4ac43602006-06-28 04:26:52 -07003774 memcpy_fromio(&ecpsig, ecpsigp, sizeof(cdkecpsig_t));
3775 if (ecpsig.magic == cpu_to_le32(ECP_MAGIC))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003776 foundit = 1;
3777 } else {
Alan Cox4ac43602006-06-28 04:26:52 -07003778 onbsigp = (cdkonbsig_t __iomem *) stli_onbegetmemptr(brdp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779 CDK_SIGADDR, __LINE__);
Alan Cox4ac43602006-06-28 04:26:52 -07003780 memcpy_fromio(&onbsig, onbsigp, sizeof(cdkonbsig_t));
3781 if ((onbsig.magic0 == cpu_to_le16(ONB_MAGIC0)) &&
3782 (onbsig.magic1 == cpu_to_le16(ONB_MAGIC1)) &&
3783 (onbsig.magic2 == cpu_to_le16(ONB_MAGIC2)) &&
3784 (onbsig.magic3 == cpu_to_le16(ONB_MAGIC3)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785 foundit = 1;
3786 }
3787
3788 iounmap(brdp->membase);
3789 if (foundit)
3790 break;
3791 }
3792
3793/*
3794 * Regardless of whether we found the shared memory or not we must
3795 * disable the region. After that return success or failure.
3796 */
3797 if (brdp->brdtype == BRD_ECPE)
3798 stli_ecpeidisable(brdp);
3799 else
3800 stli_onbedisable(brdp);
3801
3802 if (! foundit) {
3803 brdp->memaddr = 0;
3804 brdp->membase = NULL;
3805 printk(KERN_ERR "STALLION: failed to probe shared memory "
3806 "region for %s in EISA slot=%d\n",
3807 stli_brdnames[brdp->brdtype], (brdp->iobase >> 12));
Alan Cox4ac43602006-06-28 04:26:52 -07003808 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003809 }
Alan Cox4ac43602006-06-28 04:26:52 -07003810 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003811}
Jiri Slabya00f33f2006-12-08 02:39:20 -08003812#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003813
3814static int stli_getbrdnr(void)
3815{
Jiri Slaby1328d732006-12-08 02:39:19 -08003816 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003817
3818 for (i = 0; i < STL_MAXBRDS; i++) {
3819 if (!stli_brds[i]) {
3820 if (i >= stli_nrbrds)
3821 stli_nrbrds = i + 1;
3822 return i;
3823 }
3824 }
3825 return -1;
3826}
3827
Jiri Slabya00f33f2006-12-08 02:39:20 -08003828#if STLI_EISAPROBE != 0
Linus Torvalds1da177e2005-04-16 15:20:36 -07003829/*****************************************************************************/
3830
3831/*
3832 * Probe around and try to find any EISA boards in system. The biggest
3833 * problem here is finding out what memory address is associated with
3834 * an EISA board after it is found. The registers of the ECPE and
3835 * ONboardE are not readable - so we can't read them from there. We
3836 * don't have access to the EISA CMOS (or EISA BIOS) so we don't
3837 * actually have any way to find out the real value. The best we can
3838 * do is go probing around in the usual places hoping we can find it.
3839 */
3840
3841static int stli_findeisabrds(void)
3842{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003843 struct stlibrd *brdp;
Jiri Slaby1328d732006-12-08 02:39:19 -08003844 unsigned int iobase, eid, i;
3845 int brdnr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003846
3847/*
Alan Cox4ac43602006-06-28 04:26:52 -07003848 * Firstly check if this is an EISA system. If this is not an EISA system then
Linus Torvalds1da177e2005-04-16 15:20:36 -07003849 * don't bother going any further!
3850 */
Alan Cox4ac43602006-06-28 04:26:52 -07003851 if (EISA_bus)
3852 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003853
3854/*
3855 * Looks like an EISA system, so go searching for EISA boards.
3856 */
3857 for (iobase = 0x1000; (iobase <= 0xc000); iobase += 0x1000) {
3858 outb(0xff, (iobase + 0xc80));
3859 eid = inb(iobase + 0xc80);
3860 eid |= inb(iobase + 0xc81) << 8;
3861 if (eid != STL_EISAID)
3862 continue;
3863
3864/*
3865 * We have found a board. Need to check if this board was
3866 * statically configured already (just in case!).
3867 */
3868 for (i = 0; (i < STL_MAXBRDS); i++) {
3869 brdp = stli_brds[i];
Alan Cox4ac43602006-06-28 04:26:52 -07003870 if (brdp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003871 continue;
3872 if (brdp->iobase == iobase)
3873 break;
3874 }
3875 if (i < STL_MAXBRDS)
3876 continue;
3877
3878/*
3879 * We have found a Stallion board and it is not configured already.
3880 * Allocate a board structure and initialize it.
3881 */
Alan Cox4ac43602006-06-28 04:26:52 -07003882 if ((brdp = stli_allocbrd()) == NULL)
3883 return -ENOMEM;
Jiri Slaby1328d732006-12-08 02:39:19 -08003884 brdnr = stli_getbrdnr();
3885 if (brdnr < 0)
Alan Cox4ac43602006-06-28 04:26:52 -07003886 return -ENOMEM;
Jiri Slaby1328d732006-12-08 02:39:19 -08003887 brdp->brdnr = (unsigned int)brdnr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003888 eid = inb(iobase + 0xc82);
3889 if (eid == ECP_EISAID)
3890 brdp->brdtype = BRD_ECPE;
3891 else if (eid == ONB_EISAID)
3892 brdp->brdtype = BRD_ONBOARDE;
3893 else
3894 brdp->brdtype = BRD_UNKNOWN;
3895 brdp->iobase = iobase;
3896 outb(0x1, (iobase + 0xc84));
3897 if (stli_eisamemprobe(brdp))
3898 outb(0, (iobase + 0xc84));
Jiri Slabyb103b5c2006-12-08 02:39:21 -08003899 stli_brds[brdp->brdnr] = brdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003900 stli_brdinit(brdp);
3901 }
3902
Alan Cox4ac43602006-06-28 04:26:52 -07003903 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904}
Jiri Slabya00f33f2006-12-08 02:39:20 -08003905#else
3906static inline int stli_findeisabrds(void) { return 0; }
3907#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908
3909/*****************************************************************************/
3910
3911/*
3912 * Find the next available board number that is free.
3913 */
3914
3915/*****************************************************************************/
3916
Linus Torvalds1da177e2005-04-16 15:20:36 -07003917/*
3918 * We have a Stallion board. Allocate a board structure and
3919 * initialize it. Read its IO and MEMORY resources from PCI
3920 * configuration space.
3921 */
3922
Jiri Slaby845bead2006-12-08 02:39:17 -08003923static int __devinit stli_pciprobe(struct pci_dev *pdev,
3924 const struct pci_device_id *ent)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003925{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003926 struct stlibrd *brdp;
Jiri Slaby1328d732006-12-08 02:39:19 -08003927 int brdnr, retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003928
Jiri Slaby845bead2006-12-08 02:39:17 -08003929 retval = pci_enable_device(pdev);
3930 if (retval)
3931 goto err;
3932 brdp = stli_allocbrd();
3933 if (brdp == NULL) {
3934 retval = -ENOMEM;
3935 goto err;
3936 }
Jiri Slabyb103b5c2006-12-08 02:39:21 -08003937 mutex_lock(&stli_brdslock);
Jiri Slaby1328d732006-12-08 02:39:19 -08003938 brdnr = stli_getbrdnr();
Jiri Slabyb103b5c2006-12-08 02:39:21 -08003939 if (brdnr < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003940 printk(KERN_INFO "STALLION: too many boards found, "
3941 "maximum supported %d\n", STL_MAXBRDS);
Jiri Slabyb103b5c2006-12-08 02:39:21 -08003942 mutex_unlock(&stli_brdslock);
Jiri Slaby845bead2006-12-08 02:39:17 -08003943 retval = -EIO;
3944 goto err_fr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003945 }
Jiri Slaby1328d732006-12-08 02:39:19 -08003946 brdp->brdnr = (unsigned int)brdnr;
Jiri Slabyb103b5c2006-12-08 02:39:21 -08003947 stli_brds[brdp->brdnr] = brdp;
3948 mutex_unlock(&stli_brdslock);
Jiri Slaby845bead2006-12-08 02:39:17 -08003949 brdp->brdtype = BRD_ECPPCI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003950/*
3951 * We have all resources from the board, so lets setup the actual
3952 * board structure now.
3953 */
Jiri Slaby845bead2006-12-08 02:39:17 -08003954 brdp->iobase = pci_resource_start(pdev, 3);
3955 brdp->memaddr = pci_resource_start(pdev, 2);
3956 retval = stli_brdinit(brdp);
3957 if (retval)
Jiri Slabyb103b5c2006-12-08 02:39:21 -08003958 goto err_null;
Jiri Slaby845bead2006-12-08 02:39:17 -08003959
Jiri Slaby39014172006-12-08 02:39:22 -08003960 brdp->state |= BST_PROBED;
Jiri Slaby845bead2006-12-08 02:39:17 -08003961 pci_set_drvdata(pdev, brdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003962
Alan Cox4ac43602006-06-28 04:26:52 -07003963 return 0;
Jiri Slabyb103b5c2006-12-08 02:39:21 -08003964err_null:
3965 stli_brds[brdp->brdnr] = NULL;
Jiri Slaby845bead2006-12-08 02:39:17 -08003966err_fr:
3967 kfree(brdp);
3968err:
3969 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003970}
3971
Jiri Slaby845bead2006-12-08 02:39:17 -08003972static void stli_pciremove(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003973{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003974 struct stlibrd *brdp = pci_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003975
Jiri Slaby845bead2006-12-08 02:39:17 -08003976 stli_cleanup_ports(brdp);
3977
3978 iounmap(brdp->membase);
3979 if (brdp->iosize > 0)
3980 release_region(brdp->iobase, brdp->iosize);
3981
3982 stli_brds[brdp->brdnr] = NULL;
3983 kfree(brdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003984}
3985
Jiri Slaby845bead2006-12-08 02:39:17 -08003986static struct pci_driver stli_pcidriver = {
3987 .name = "istallion",
3988 .id_table = istallion_pci_tbl,
3989 .probe = stli_pciprobe,
3990 .remove = __devexit_p(stli_pciremove)
3991};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003992/*****************************************************************************/
3993
3994/*
3995 * Allocate a new board structure. Fill out the basic info in it.
3996 */
3997
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003998static struct stlibrd *stli_allocbrd(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003999{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004000 struct stlibrd *brdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004001
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004002 brdp = kzalloc(sizeof(struct stlibrd), GFP_KERNEL);
Tobias Klauserb0b4ed72006-03-31 02:30:56 -08004003 if (!brdp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004004 printk(KERN_ERR "STALLION: failed to allocate memory "
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004005 "(size=%Zd)\n", sizeof(struct stlibrd));
Tobias Klauserb0b4ed72006-03-31 02:30:56 -08004006 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004007 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004008 brdp->magic = STLI_BOARDMAGIC;
Alan Cox4ac43602006-06-28 04:26:52 -07004009 return brdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004010}
4011
4012/*****************************************************************************/
4013
4014/*
4015 * Scan through all the boards in the configuration and see what we
4016 * can find.
4017 */
4018
4019static int stli_initbrds(void)
4020{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004021 struct stlibrd *brdp, *nxtbrdp;
4022 struct stlconf conf;
Jiri Slaby1328d732006-12-08 02:39:19 -08004023 unsigned int i, j;
4024 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004025
Jiri Slabya3f8d9d2006-12-08 02:39:18 -08004026 for (stli_nrbrds = 0; stli_nrbrds < ARRAY_SIZE(stli_brdsp);
4027 stli_nrbrds++) {
4028 memset(&conf, 0, sizeof(conf));
4029 if (stli_parsebrd(&conf, stli_brdsp[stli_nrbrds]) == 0)
4030 continue;
Alan Cox4ac43602006-06-28 04:26:52 -07004031 if ((brdp = stli_allocbrd()) == NULL)
Jiri Slabya3f8d9d2006-12-08 02:39:18 -08004032 continue;
4033 brdp->brdnr = stli_nrbrds;
4034 brdp->brdtype = conf.brdtype;
4035 brdp->iobase = conf.ioaddr1;
4036 brdp->memaddr = conf.memaddr;
Jiri Slabyb103b5c2006-12-08 02:39:21 -08004037 stli_brds[brdp->brdnr] = brdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004038 stli_brdinit(brdp);
4039 }
4040
Jiri Slabya00f33f2006-12-08 02:39:20 -08004041 stli_findeisabrds();
Jiri Slaby845bead2006-12-08 02:39:17 -08004042
4043 retval = pci_register_driver(&stli_pcidriver);
4044 /* TODO: check retval and do something */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004045
4046/*
4047 * All found boards are initialized. Now for a little optimization, if
4048 * no boards are sharing the "shared memory" regions then we can just
4049 * leave them all enabled. This is in fact the usual case.
4050 */
4051 stli_shared = 0;
4052 if (stli_nrbrds > 1) {
4053 for (i = 0; (i < stli_nrbrds); i++) {
4054 brdp = stli_brds[i];
Alan Cox4ac43602006-06-28 04:26:52 -07004055 if (brdp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004056 continue;
4057 for (j = i + 1; (j < stli_nrbrds); j++) {
4058 nxtbrdp = stli_brds[j];
Alan Cox4ac43602006-06-28 04:26:52 -07004059 if (nxtbrdp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004060 continue;
4061 if ((brdp->membase >= nxtbrdp->membase) &&
4062 (brdp->membase <= (nxtbrdp->membase +
4063 nxtbrdp->memsize - 1))) {
4064 stli_shared++;
4065 break;
4066 }
4067 }
4068 }
4069 }
4070
4071 if (stli_shared == 0) {
4072 for (i = 0; (i < stli_nrbrds); i++) {
4073 brdp = stli_brds[i];
Alan Cox4ac43602006-06-28 04:26:52 -07004074 if (brdp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004075 continue;
4076 if (brdp->state & BST_FOUND) {
4077 EBRDENABLE(brdp);
4078 brdp->enable = NULL;
4079 brdp->disable = NULL;
4080 }
4081 }
4082 }
4083
Alan Cox4ac43602006-06-28 04:26:52 -07004084 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004085}
4086
4087/*****************************************************************************/
4088
4089/*
4090 * Code to handle an "staliomem" read operation. This device is the
4091 * contents of the board shared memory. It is used for down loading
4092 * the slave image (and debugging :-)
4093 */
4094
4095static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp)
4096{
Alan Cox4ac43602006-06-28 04:26:52 -07004097 unsigned long flags;
Al Viro29756fa2006-10-10 22:47:27 +01004098 void __iomem *memptr;
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004099 struct stlibrd *brdp;
Jiri Slaby1328d732006-12-08 02:39:19 -08004100 unsigned int brdnr;
4101 int size, n;
Alan Cox4ac43602006-06-28 04:26:52 -07004102 void *p;
4103 loff_t off = *offp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004104
Josef Sipeka7113a92006-12-08 02:36:55 -08004105 brdnr = iminor(fp->f_path.dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004106 if (brdnr >= stli_nrbrds)
Alan Cox4ac43602006-06-28 04:26:52 -07004107 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004108 brdp = stli_brds[brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07004109 if (brdp == NULL)
4110 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004111 if (brdp->state == 0)
Alan Cox4ac43602006-06-28 04:26:52 -07004112 return -ENODEV;
4113 if (off >= brdp->memsize || off + count < off)
4114 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004115
Jiri Slabya3f8d9d2006-12-08 02:39:18 -08004116 size = min(count, (size_t)(brdp->memsize - off));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004117
Alan Cox4ac43602006-06-28 04:26:52 -07004118 /*
4119 * Copy the data a page at a time
4120 */
4121
4122 p = (void *)__get_free_page(GFP_KERNEL);
4123 if(p == NULL)
4124 return -ENOMEM;
4125
Linus Torvalds1da177e2005-04-16 15:20:36 -07004126 while (size > 0) {
Alan Cox4ac43602006-06-28 04:26:52 -07004127 spin_lock_irqsave(&brd_lock, flags);
4128 EBRDENABLE(brdp);
Al Viro29756fa2006-10-10 22:47:27 +01004129 memptr = EBRDGETMEMPTR(brdp, off);
Jiri Slabya3f8d9d2006-12-08 02:39:18 -08004130 n = min(size, (int)(brdp->pagesize - (((unsigned long) off) % brdp->pagesize)));
4131 n = min(n, (int)PAGE_SIZE);
Alan Cox4ac43602006-06-28 04:26:52 -07004132 memcpy_fromio(p, memptr, n);
4133 EBRDDISABLE(brdp);
4134 spin_unlock_irqrestore(&brd_lock, flags);
4135 if (copy_to_user(buf, p, n)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004136 count = -EFAULT;
4137 goto out;
4138 }
Alan Cox4ac43602006-06-28 04:26:52 -07004139 off += n;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004140 buf += n;
4141 size -= n;
4142 }
4143out:
Alan Cox4ac43602006-06-28 04:26:52 -07004144 *offp = off;
4145 free_page((unsigned long)p);
4146 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004147}
4148
4149/*****************************************************************************/
4150
4151/*
4152 * Code to handle an "staliomem" write operation. This device is the
4153 * contents of the board shared memory. It is used for down loading
4154 * the slave image (and debugging :-)
Alan Cox4ac43602006-06-28 04:26:52 -07004155 *
4156 * FIXME: copy under lock
Linus Torvalds1da177e2005-04-16 15:20:36 -07004157 */
4158
4159static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp)
4160{
Alan Cox4ac43602006-06-28 04:26:52 -07004161 unsigned long flags;
Al Viro29756fa2006-10-10 22:47:27 +01004162 void __iomem *memptr;
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004163 struct stlibrd *brdp;
Alan Cox4ac43602006-06-28 04:26:52 -07004164 char __user *chbuf;
Jiri Slaby1328d732006-12-08 02:39:19 -08004165 unsigned int brdnr;
4166 int size, n;
Alan Cox4ac43602006-06-28 04:26:52 -07004167 void *p;
4168 loff_t off = *offp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004169
Josef Sipeka7113a92006-12-08 02:36:55 -08004170 brdnr = iminor(fp->f_path.dentry->d_inode);
Alan Cox4ac43602006-06-28 04:26:52 -07004171
Linus Torvalds1da177e2005-04-16 15:20:36 -07004172 if (brdnr >= stli_nrbrds)
Alan Cox4ac43602006-06-28 04:26:52 -07004173 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004174 brdp = stli_brds[brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07004175 if (brdp == NULL)
4176 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004177 if (brdp->state == 0)
Alan Cox4ac43602006-06-28 04:26:52 -07004178 return -ENODEV;
4179 if (off >= brdp->memsize || off + count < off)
4180 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004181
4182 chbuf = (char __user *) buf;
Jiri Slabya3f8d9d2006-12-08 02:39:18 -08004183 size = min(count, (size_t)(brdp->memsize - off));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004184
Alan Cox4ac43602006-06-28 04:26:52 -07004185 /*
4186 * Copy the data a page at a time
4187 */
4188
4189 p = (void *)__get_free_page(GFP_KERNEL);
4190 if(p == NULL)
4191 return -ENOMEM;
4192
Linus Torvalds1da177e2005-04-16 15:20:36 -07004193 while (size > 0) {
Jiri Slabya3f8d9d2006-12-08 02:39:18 -08004194 n = min(size, (int)(brdp->pagesize - (((unsigned long) off) % brdp->pagesize)));
4195 n = min(n, (int)PAGE_SIZE);
Alan Cox4ac43602006-06-28 04:26:52 -07004196 if (copy_from_user(p, chbuf, n)) {
4197 if (count == 0)
4198 count = -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004199 goto out;
4200 }
Alan Cox4ac43602006-06-28 04:26:52 -07004201 spin_lock_irqsave(&brd_lock, flags);
4202 EBRDENABLE(brdp);
Al Viro29756fa2006-10-10 22:47:27 +01004203 memptr = EBRDGETMEMPTR(brdp, off);
Alan Cox4ac43602006-06-28 04:26:52 -07004204 memcpy_toio(memptr, p, n);
4205 EBRDDISABLE(brdp);
4206 spin_unlock_irqrestore(&brd_lock, flags);
4207 off += n;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004208 chbuf += n;
4209 size -= n;
4210 }
4211out:
Alan Cox4ac43602006-06-28 04:26:52 -07004212 free_page((unsigned long) p);
4213 *offp = off;
4214 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004215}
4216
4217/*****************************************************************************/
4218
4219/*
4220 * Return the board stats structure to user app.
4221 */
4222
4223static int stli_getbrdstats(combrd_t __user *bp)
4224{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004225 struct stlibrd *brdp;
Jiri Slaby1328d732006-12-08 02:39:19 -08004226 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004227
4228 if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t)))
4229 return -EFAULT;
4230 if (stli_brdstats.brd >= STL_MAXBRDS)
Alan Cox4ac43602006-06-28 04:26:52 -07004231 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004232 brdp = stli_brds[stli_brdstats.brd];
Alan Cox4ac43602006-06-28 04:26:52 -07004233 if (brdp == NULL)
4234 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004235
4236 memset(&stli_brdstats, 0, sizeof(combrd_t));
4237 stli_brdstats.brd = brdp->brdnr;
4238 stli_brdstats.type = brdp->brdtype;
4239 stli_brdstats.hwid = 0;
4240 stli_brdstats.state = brdp->state;
4241 stli_brdstats.ioaddr = brdp->iobase;
4242 stli_brdstats.memaddr = brdp->memaddr;
4243 stli_brdstats.nrpanels = brdp->nrpanels;
4244 stli_brdstats.nrports = brdp->nrports;
4245 for (i = 0; (i < brdp->nrpanels); i++) {
4246 stli_brdstats.panels[i].panel = i;
4247 stli_brdstats.panels[i].hwid = brdp->panelids[i];
4248 stli_brdstats.panels[i].nrports = brdp->panels[i];
4249 }
4250
4251 if (copy_to_user(bp, &stli_brdstats, sizeof(combrd_t)))
4252 return -EFAULT;
Alan Cox4ac43602006-06-28 04:26:52 -07004253 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004254}
4255
4256/*****************************************************************************/
4257
4258/*
4259 * Resolve the referenced port number into a port struct pointer.
4260 */
4261
Jiri Slaby1328d732006-12-08 02:39:19 -08004262static struct stliport *stli_getport(unsigned int brdnr, unsigned int panelnr,
4263 unsigned int portnr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004264{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004265 struct stlibrd *brdp;
Jiri Slaby1328d732006-12-08 02:39:19 -08004266 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004267
Jiri Slaby1328d732006-12-08 02:39:19 -08004268 if (brdnr >= STL_MAXBRDS)
Alan Cox4ac43602006-06-28 04:26:52 -07004269 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004270 brdp = stli_brds[brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07004271 if (brdp == NULL)
4272 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004273 for (i = 0; (i < panelnr); i++)
4274 portnr += brdp->panels[i];
Jiri Slaby1328d732006-12-08 02:39:19 -08004275 if (portnr >= brdp->nrports)
Alan Cox4ac43602006-06-28 04:26:52 -07004276 return NULL;
4277 return brdp->ports[portnr];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004278}
4279
4280/*****************************************************************************/
4281
4282/*
4283 * Return the port stats structure to user app. A NULL port struct
4284 * pointer passed in means that we need to find out from the app
4285 * what port to get stats for (used through board control device).
4286 */
4287
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004288static int stli_portcmdstats(struct stliport *portp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004289{
4290 unsigned long flags;
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004291 struct stlibrd *brdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004292 int rc;
4293
4294 memset(&stli_comstats, 0, sizeof(comstats_t));
4295
Alan Cox4ac43602006-06-28 04:26:52 -07004296 if (portp == NULL)
4297 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004298 brdp = stli_brds[portp->brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07004299 if (brdp == NULL)
4300 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004301
4302 if (brdp->state & BST_STARTED) {
4303 if ((rc = stli_cmdwait(brdp, portp, A_GETSTATS,
4304 &stli_cdkstats, sizeof(asystats_t), 1)) < 0)
Alan Cox4ac43602006-06-28 04:26:52 -07004305 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004306 } else {
4307 memset(&stli_cdkstats, 0, sizeof(asystats_t));
4308 }
4309
4310 stli_comstats.brd = portp->brdnr;
4311 stli_comstats.panel = portp->panelnr;
4312 stli_comstats.port = portp->portnr;
4313 stli_comstats.state = portp->state;
4314 stli_comstats.flags = portp->flags;
4315
Alan Cox4ac43602006-06-28 04:26:52 -07004316 spin_lock_irqsave(&brd_lock, flags);
4317 if (portp->tty != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004318 if (portp->tty->driver_data == portp) {
4319 stli_comstats.ttystate = portp->tty->flags;
Alan Cox4ac43602006-06-28 04:26:52 -07004320 stli_comstats.rxbuffered = -1;
4321 if (portp->tty->termios != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004322 stli_comstats.cflags = portp->tty->termios->c_cflag;
4323 stli_comstats.iflags = portp->tty->termios->c_iflag;
4324 stli_comstats.oflags = portp->tty->termios->c_oflag;
4325 stli_comstats.lflags = portp->tty->termios->c_lflag;
4326 }
4327 }
4328 }
Alan Cox4ac43602006-06-28 04:26:52 -07004329 spin_unlock_irqrestore(&brd_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004330
4331 stli_comstats.txtotal = stli_cdkstats.txchars;
4332 stli_comstats.rxtotal = stli_cdkstats.rxchars + stli_cdkstats.ringover;
4333 stli_comstats.txbuffered = stli_cdkstats.txringq;
4334 stli_comstats.rxbuffered += stli_cdkstats.rxringq;
4335 stli_comstats.rxoverrun = stli_cdkstats.overruns;
4336 stli_comstats.rxparity = stli_cdkstats.parity;
4337 stli_comstats.rxframing = stli_cdkstats.framing;
4338 stli_comstats.rxlost = stli_cdkstats.ringover;
4339 stli_comstats.rxbreaks = stli_cdkstats.rxbreaks;
4340 stli_comstats.txbreaks = stli_cdkstats.txbreaks;
4341 stli_comstats.txxon = stli_cdkstats.txstart;
4342 stli_comstats.txxoff = stli_cdkstats.txstop;
4343 stli_comstats.rxxon = stli_cdkstats.rxstart;
4344 stli_comstats.rxxoff = stli_cdkstats.rxstop;
4345 stli_comstats.rxrtsoff = stli_cdkstats.rtscnt / 2;
4346 stli_comstats.rxrtson = stli_cdkstats.rtscnt - stli_comstats.rxrtsoff;
4347 stli_comstats.modem = stli_cdkstats.dcdcnt;
4348 stli_comstats.hwid = stli_cdkstats.hwid;
4349 stli_comstats.signals = stli_mktiocm(stli_cdkstats.signals);
4350
Alan Cox4ac43602006-06-28 04:26:52 -07004351 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004352}
4353
4354/*****************************************************************************/
4355
4356/*
4357 * Return the port stats structure to user app. A NULL port struct
4358 * pointer passed in means that we need to find out from the app
4359 * what port to get stats for (used through board control device).
4360 */
4361
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004362static int stli_getportstats(struct stliport *portp, comstats_t __user *cp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004363{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004364 struct stlibrd *brdp;
Alan Cox4ac43602006-06-28 04:26:52 -07004365 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004366
4367 if (!portp) {
4368 if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
4369 return -EFAULT;
4370 portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
4371 stli_comstats.port);
4372 if (!portp)
4373 return -ENODEV;
4374 }
4375
4376 brdp = stli_brds[portp->brdnr];
4377 if (!brdp)
4378 return -ENODEV;
4379
4380 if ((rc = stli_portcmdstats(portp)) < 0)
4381 return rc;
4382
4383 return copy_to_user(cp, &stli_comstats, sizeof(comstats_t)) ?
4384 -EFAULT : 0;
4385}
4386
4387/*****************************************************************************/
4388
4389/*
4390 * Clear the port stats structure. We also return it zeroed out...
4391 */
4392
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004393static int stli_clrportstats(struct stliport *portp, comstats_t __user *cp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004394{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004395 struct stlibrd *brdp;
Alan Cox4ac43602006-06-28 04:26:52 -07004396 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004397
4398 if (!portp) {
4399 if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
4400 return -EFAULT;
4401 portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
4402 stli_comstats.port);
4403 if (!portp)
4404 return -ENODEV;
4405 }
4406
4407 brdp = stli_brds[portp->brdnr];
4408 if (!brdp)
4409 return -ENODEV;
4410
4411 if (brdp->state & BST_STARTED) {
4412 if ((rc = stli_cmdwait(brdp, portp, A_CLEARSTATS, NULL, 0, 0)) < 0)
4413 return rc;
4414 }
4415
4416 memset(&stli_comstats, 0, sizeof(comstats_t));
4417 stli_comstats.brd = portp->brdnr;
4418 stli_comstats.panel = portp->panelnr;
4419 stli_comstats.port = portp->portnr;
4420
4421 if (copy_to_user(cp, &stli_comstats, sizeof(comstats_t)))
4422 return -EFAULT;
4423 return 0;
4424}
4425
4426/*****************************************************************************/
4427
4428/*
4429 * Return the entire driver ports structure to a user app.
4430 */
4431
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004432static int stli_getportstruct(struct stliport __user *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004433{
Jiri Slaby1328d732006-12-08 02:39:19 -08004434 struct stliport stli_dummyport;
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004435 struct stliport *portp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004436
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004437 if (copy_from_user(&stli_dummyport, arg, sizeof(struct stliport)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004438 return -EFAULT;
4439 portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr,
4440 stli_dummyport.portnr);
4441 if (!portp)
4442 return -ENODEV;
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004443 if (copy_to_user(arg, portp, sizeof(struct stliport)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004444 return -EFAULT;
4445 return 0;
4446}
4447
4448/*****************************************************************************/
4449
4450/*
4451 * Return the entire driver board structure to a user app.
4452 */
4453
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004454static int stli_getbrdstruct(struct stlibrd __user *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004455{
Jiri Slaby1328d732006-12-08 02:39:19 -08004456 struct stlibrd stli_dummybrd;
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004457 struct stlibrd *brdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004458
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004459 if (copy_from_user(&stli_dummybrd, arg, sizeof(struct stlibrd)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004460 return -EFAULT;
Jiri Slaby1328d732006-12-08 02:39:19 -08004461 if (stli_dummybrd.brdnr >= STL_MAXBRDS)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004462 return -ENODEV;
4463 brdp = stli_brds[stli_dummybrd.brdnr];
4464 if (!brdp)
4465 return -ENODEV;
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004466 if (copy_to_user(arg, brdp, sizeof(struct stlibrd)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004467 return -EFAULT;
4468 return 0;
4469}
4470
4471/*****************************************************************************/
4472
4473/*
4474 * The "staliomem" device is also required to do some special operations on
4475 * the board. We need to be able to send an interrupt to the board,
4476 * reset it, and start/stop it.
4477 */
4478
4479static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
4480{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004481 struct stlibrd *brdp;
Alan Cox4ac43602006-06-28 04:26:52 -07004482 int brdnr, rc, done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004483 void __user *argp = (void __user *)arg;
4484
Linus Torvalds1da177e2005-04-16 15:20:36 -07004485/*
4486 * First up handle the board independent ioctls.
4487 */
4488 done = 0;
4489 rc = 0;
4490
4491 switch (cmd) {
4492 case COM_GETPORTSTATS:
4493 rc = stli_getportstats(NULL, argp);
4494 done++;
4495 break;
4496 case COM_CLRPORTSTATS:
4497 rc = stli_clrportstats(NULL, argp);
4498 done++;
4499 break;
4500 case COM_GETBRDSTATS:
4501 rc = stli_getbrdstats(argp);
4502 done++;
4503 break;
4504 case COM_READPORT:
4505 rc = stli_getportstruct(argp);
4506 done++;
4507 break;
4508 case COM_READBOARD:
4509 rc = stli_getbrdstruct(argp);
4510 done++;
4511 break;
4512 }
4513
4514 if (done)
Alan Cox4ac43602006-06-28 04:26:52 -07004515 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004516
4517/*
4518 * Now handle the board specific ioctls. These all depend on the
4519 * minor number of the device they were called from.
4520 */
4521 brdnr = iminor(ip);
4522 if (brdnr >= STL_MAXBRDS)
Alan Cox4ac43602006-06-28 04:26:52 -07004523 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004524 brdp = stli_brds[brdnr];
4525 if (!brdp)
Alan Cox4ac43602006-06-28 04:26:52 -07004526 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004527 if (brdp->state == 0)
Alan Cox4ac43602006-06-28 04:26:52 -07004528 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004529
4530 switch (cmd) {
4531 case STL_BINTR:
4532 EBRDINTR(brdp);
4533 break;
4534 case STL_BSTART:
4535 rc = stli_startbrd(brdp);
4536 break;
4537 case STL_BSTOP:
4538 brdp->state &= ~BST_STARTED;
4539 break;
4540 case STL_BRESET:
4541 brdp->state &= ~BST_STARTED;
4542 EBRDRESET(brdp);
4543 if (stli_shared == 0) {
4544 if (brdp->reenable != NULL)
4545 (* brdp->reenable)(brdp);
4546 }
4547 break;
4548 default:
4549 rc = -ENOIOCTLCMD;
4550 break;
4551 }
Alan Cox4ac43602006-06-28 04:26:52 -07004552 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004553}
4554
Jeff Dikeb68e31d2006-10-02 02:17:18 -07004555static const struct tty_operations stli_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004556 .open = stli_open,
4557 .close = stli_close,
4558 .write = stli_write,
4559 .put_char = stli_putchar,
4560 .flush_chars = stli_flushchars,
4561 .write_room = stli_writeroom,
4562 .chars_in_buffer = stli_charsinbuffer,
4563 .ioctl = stli_ioctl,
4564 .set_termios = stli_settermios,
4565 .throttle = stli_throttle,
4566 .unthrottle = stli_unthrottle,
4567 .stop = stli_stop,
4568 .start = stli_start,
4569 .hangup = stli_hangup,
4570 .flush_buffer = stli_flushbuffer,
4571 .break_ctl = stli_breakctl,
4572 .wait_until_sent = stli_waituntilsent,
4573 .send_xchar = stli_sendxchar,
4574 .read_proc = stli_readproc,
4575 .tiocmget = stli_tiocmget,
4576 .tiocmset = stli_tiocmset,
4577};
4578
4579/*****************************************************************************/
4580
Adrian Bunk672b2712006-06-30 01:55:30 -07004581static int __init stli_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004582{
4583 int i;
4584 printk(KERN_INFO "%s: version %s\n", stli_drvtitle, stli_drvversion);
4585
Alan Cox4ac43602006-06-28 04:26:52 -07004586 spin_lock_init(&stli_lock);
4587 spin_lock_init(&brd_lock);
4588
Linus Torvalds1da177e2005-04-16 15:20:36 -07004589 stli_initbrds();
4590
4591 stli_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
4592 if (!stli_serial)
4593 return -ENOMEM;
4594
4595/*
4596 * Allocate a temporary write buffer.
4597 */
Tobias Klauserb0b4ed72006-03-31 02:30:56 -08004598 stli_txcookbuf = kmalloc(STLI_TXBUFSIZE, GFP_KERNEL);
4599 if (!stli_txcookbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004600 printk(KERN_ERR "STALLION: failed to allocate memory "
4601 "(size=%d)\n", STLI_TXBUFSIZE);
4602
4603/*
4604 * Set up a character driver for the shared memory region. We need this
4605 * to down load the slave code image. Also it is a useful debugging tool.
4606 */
4607 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stli_fsiomem))
4608 printk(KERN_ERR "STALLION: failed to register serial memory "
4609 "device\n");
4610
gregkh@suse.deca8eca62005-03-23 09:53:09 -08004611 istallion_class = class_create(THIS_MODULE, "staliomem");
Greg Kroah-Hartman7c69ef72005-06-20 21:15:16 -07004612 for (i = 0; i < 4; i++)
Greg Kroah-Hartman53f46542005-10-27 22:25:43 -07004613 class_device_create(istallion_class, NULL,
4614 MKDEV(STL_SIOMEMMAJOR, i),
Linus Torvalds1da177e2005-04-16 15:20:36 -07004615 NULL, "staliomem%d", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004616
4617/*
4618 * Set up the tty driver structure and register us as a driver.
4619 */
4620 stli_serial->owner = THIS_MODULE;
4621 stli_serial->driver_name = stli_drvname;
4622 stli_serial->name = stli_serialname;
4623 stli_serial->major = STL_SERIALMAJOR;
4624 stli_serial->minor_start = 0;
4625 stli_serial->type = TTY_DRIVER_TYPE_SERIAL;
4626 stli_serial->subtype = SERIAL_TYPE_NORMAL;
4627 stli_serial->init_termios = stli_deftermios;
4628 stli_serial->flags = TTY_DRIVER_REAL_RAW;
4629 tty_set_operations(stli_serial, &stli_ops);
4630
4631 if (tty_register_driver(stli_serial)) {
4632 put_tty_driver(stli_serial);
4633 printk(KERN_ERR "STALLION: failed to register serial driver\n");
4634 return -EBUSY;
4635 }
Alan Cox4ac43602006-06-28 04:26:52 -07004636 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004637}
4638
4639/*****************************************************************************/