blob: de869241baa040bef7bf18c084f0c40bd8eb6190 [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
205
206/*
207 * Define the set of port state flags. These are marked for internal
208 * state purposes only, usually to do with the state of communications
209 * with the slave. Most of them need to be updated atomically, so always
210 * use the bit setting operations (unless protected by cli/sti).
211 */
212#define ST_INITIALIZING 1
213#define ST_OPENING 2
214#define ST_CLOSING 3
215#define ST_CMDING 4
216#define ST_TXBUSY 5
217#define ST_RXING 6
218#define ST_DOFLUSHRX 7
219#define ST_DOFLUSHTX 8
220#define ST_DOSIGS 9
221#define ST_RXSTOP 10
222#define ST_GETSIGS 11
223
224/*
225 * Define an array of board names as printable strings. Handy for
226 * referencing boards when printing trace and stuff.
227 */
228static char *stli_brdnames[] = {
229 "Unknown",
230 "Stallion",
231 "Brumby",
232 "ONboard-MC",
233 "ONboard",
234 "Brumby",
235 "Brumby",
236 "ONboard-EI",
Jiri Slabya3f8d9d2006-12-08 02:39:18 -0800237 NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 "ONboard",
239 "ONboard-MC",
240 "ONboard-MC",
Jiri Slabya3f8d9d2006-12-08 02:39:18 -0800241 NULL,
242 NULL,
243 NULL,
244 NULL,
245 NULL,
246 NULL,
247 NULL,
248 NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 "EasyIO",
250 "EC8/32-AT",
251 "EC8/32-MC",
252 "EC8/64-AT",
253 "EC8/64-EI",
254 "EC8/64-MC",
255 "EC8/32-PCI",
256 "EC8/64-PCI",
257 "EasyIO-PCI",
258 "EC/RA-PCI",
259};
260
261/*****************************************************************************/
262
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263/*
264 * Define some string labels for arguments passed from the module
265 * load line. These allow for easy board definitions, and easy
266 * modification of the io, memory and irq resoucres.
267 */
268
269static char *board0[8];
270static char *board1[8];
271static char *board2[8];
272static char *board3[8];
273
274static char **stli_brdsp[] = {
275 (char **) &board0,
276 (char **) &board1,
277 (char **) &board2,
278 (char **) &board3
279};
280
281/*
282 * Define a set of common board names, and types. This is used to
283 * parse any module arguments.
284 */
285
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800286static struct stlibrdtype {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 char *name;
288 int type;
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800289} stli_brdstr[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 { "stallion", BRD_STALLION },
291 { "1", BRD_STALLION },
292 { "brumby", BRD_BRUMBY },
293 { "brumby4", BRD_BRUMBY },
294 { "brumby/4", BRD_BRUMBY },
295 { "brumby-4", BRD_BRUMBY },
296 { "brumby8", BRD_BRUMBY },
297 { "brumby/8", BRD_BRUMBY },
298 { "brumby-8", BRD_BRUMBY },
299 { "brumby16", BRD_BRUMBY },
300 { "brumby/16", BRD_BRUMBY },
301 { "brumby-16", BRD_BRUMBY },
302 { "2", BRD_BRUMBY },
303 { "onboard2", BRD_ONBOARD2 },
304 { "onboard-2", BRD_ONBOARD2 },
305 { "onboard/2", BRD_ONBOARD2 },
306 { "onboard-mc", BRD_ONBOARD2 },
307 { "onboard/mc", BRD_ONBOARD2 },
308 { "onboard-mca", BRD_ONBOARD2 },
309 { "onboard/mca", BRD_ONBOARD2 },
310 { "3", BRD_ONBOARD2 },
311 { "onboard", BRD_ONBOARD },
312 { "onboardat", BRD_ONBOARD },
313 { "4", BRD_ONBOARD },
314 { "onboarde", BRD_ONBOARDE },
315 { "onboard-e", BRD_ONBOARDE },
316 { "onboard/e", BRD_ONBOARDE },
317 { "onboard-ei", BRD_ONBOARDE },
318 { "onboard/ei", BRD_ONBOARDE },
319 { "7", BRD_ONBOARDE },
320 { "ecp", BRD_ECP },
321 { "ecpat", BRD_ECP },
322 { "ec8/64", BRD_ECP },
323 { "ec8/64-at", BRD_ECP },
324 { "ec8/64-isa", BRD_ECP },
325 { "23", BRD_ECP },
326 { "ecpe", BRD_ECPE },
327 { "ecpei", BRD_ECPE },
328 { "ec8/64-e", BRD_ECPE },
329 { "ec8/64-ei", BRD_ECPE },
330 { "24", BRD_ECPE },
331 { "ecpmc", BRD_ECPMC },
332 { "ec8/64-mc", BRD_ECPMC },
333 { "ec8/64-mca", BRD_ECPMC },
334 { "25", BRD_ECPMC },
335 { "ecppci", BRD_ECPPCI },
336 { "ec/ra", BRD_ECPPCI },
337 { "ec/ra-pc", BRD_ECPPCI },
338 { "ec/ra-pci", BRD_ECPPCI },
339 { "29", BRD_ECPPCI },
340};
341
342/*
343 * Define the module agruments.
344 */
345MODULE_AUTHOR("Greg Ungerer");
346MODULE_DESCRIPTION("Stallion Intelligent Multiport Serial Driver");
347MODULE_LICENSE("GPL");
348
349
Rusty Russell8d3b33f2006-03-25 03:07:05 -0800350module_param_array(board0, charp, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,memaddr]");
Rusty Russell8d3b33f2006-03-25 03:07:05 -0800352module_param_array(board1, charp, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,memaddr]");
Rusty Russell8d3b33f2006-03-25 03:07:05 -0800354module_param_array(board2, charp, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,memaddr]");
Rusty Russell8d3b33f2006-03-25 03:07:05 -0800356module_param_array(board3, charp, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,memaddr]");
358
Jiri Slabya00f33f2006-12-08 02:39:20 -0800359#if STLI_EISAPROBE != 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360/*
361 * Set up a default memory address table for EISA board probing.
362 * The default addresses are all bellow 1Mbyte, which has to be the
363 * case anyway. They should be safe, since we only read values from
364 * them, and interrupts are disabled while we do it. If the higher
365 * memory support is compiled in then we also try probing around
366 * the 1Gb, 2Gb and 3Gb areas as well...
367 */
368static unsigned long stli_eisamemprobeaddrs[] = {
369 0xc0000, 0xd0000, 0xe0000, 0xf0000,
370 0x80000000, 0x80010000, 0x80020000, 0x80030000,
371 0x40000000, 0x40010000, 0x40020000, 0x40030000,
372 0xc0000000, 0xc0010000, 0xc0020000, 0xc0030000,
373 0xff000000, 0xff010000, 0xff020000, 0xff030000,
374};
375
Tobias Klauserfe971072006-01-09 20:54:02 -0800376static int stli_eisamempsize = ARRAY_SIZE(stli_eisamemprobeaddrs);
Jiri Slabya00f33f2006-12-08 02:39:20 -0800377#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
379/*
380 * Define the Stallion PCI vendor and device IDs.
381 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382#ifndef PCI_DEVICE_ID_ECRA
383#define PCI_DEVICE_ID_ECRA 0x0004
384#endif
385
386static struct pci_device_id istallion_pci_tbl[] = {
Alan Cox4ac43602006-06-28 04:26:52 -0700387 { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECRA), },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 { 0 }
389};
390MODULE_DEVICE_TABLE(pci, istallion_pci_tbl);
391
Jiri Slaby845bead2006-12-08 02:39:17 -0800392static struct pci_driver stli_pcidriver;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
394/*****************************************************************************/
395
396/*
397 * Hardware configuration info for ECP boards. These defines apply
398 * to the directly accessible io ports of the ECP. There is a set of
399 * defines for each ECP board type, ISA, EISA, MCA and PCI.
400 */
401#define ECP_IOSIZE 4
402
403#define ECP_MEMSIZE (128 * 1024)
404#define ECP_PCIMEMSIZE (256 * 1024)
405
406#define ECP_ATPAGESIZE (4 * 1024)
407#define ECP_MCPAGESIZE (4 * 1024)
408#define ECP_EIPAGESIZE (64 * 1024)
409#define ECP_PCIPAGESIZE (64 * 1024)
410
411#define STL_EISAID 0x8c4e
412
413/*
414 * Important defines for the ISA class of ECP board.
415 */
416#define ECP_ATIREG 0
417#define ECP_ATCONFR 1
418#define ECP_ATMEMAR 2
419#define ECP_ATMEMPR 3
420#define ECP_ATSTOP 0x1
421#define ECP_ATINTENAB 0x10
422#define ECP_ATENABLE 0x20
423#define ECP_ATDISABLE 0x00
424#define ECP_ATADDRMASK 0x3f000
425#define ECP_ATADDRSHFT 12
426
427/*
428 * Important defines for the EISA class of ECP board.
429 */
430#define ECP_EIIREG 0
431#define ECP_EIMEMARL 1
432#define ECP_EICONFR 2
433#define ECP_EIMEMARH 3
434#define ECP_EIENABLE 0x1
435#define ECP_EIDISABLE 0x0
436#define ECP_EISTOP 0x4
437#define ECP_EIEDGE 0x00
438#define ECP_EILEVEL 0x80
439#define ECP_EIADDRMASKL 0x00ff0000
440#define ECP_EIADDRSHFTL 16
441#define ECP_EIADDRMASKH 0xff000000
442#define ECP_EIADDRSHFTH 24
443#define ECP_EIBRDENAB 0xc84
444
445#define ECP_EISAID 0x4
446
447/*
448 * Important defines for the Micro-channel class of ECP board.
449 * (It has a lot in common with the ISA boards.)
450 */
451#define ECP_MCIREG 0
452#define ECP_MCCONFR 1
453#define ECP_MCSTOP 0x20
454#define ECP_MCENABLE 0x80
455#define ECP_MCDISABLE 0x00
456
457/*
458 * Important defines for the PCI class of ECP board.
459 * (It has a lot in common with the other ECP boards.)
460 */
461#define ECP_PCIIREG 0
462#define ECP_PCICONFR 1
463#define ECP_PCISTOP 0x01
464
465/*
466 * Hardware configuration info for ONboard and Brumby boards. These
467 * defines apply to the directly accessible io ports of these boards.
468 */
469#define ONB_IOSIZE 16
470#define ONB_MEMSIZE (64 * 1024)
471#define ONB_ATPAGESIZE (64 * 1024)
472#define ONB_MCPAGESIZE (64 * 1024)
473#define ONB_EIMEMSIZE (128 * 1024)
474#define ONB_EIPAGESIZE (64 * 1024)
475
476/*
477 * Important defines for the ISA class of ONboard board.
478 */
479#define ONB_ATIREG 0
480#define ONB_ATMEMAR 1
481#define ONB_ATCONFR 2
482#define ONB_ATSTOP 0x4
483#define ONB_ATENABLE 0x01
484#define ONB_ATDISABLE 0x00
485#define ONB_ATADDRMASK 0xff0000
486#define ONB_ATADDRSHFT 16
487
488#define ONB_MEMENABLO 0
489#define ONB_MEMENABHI 0x02
490
491/*
492 * Important defines for the EISA class of ONboard board.
493 */
494#define ONB_EIIREG 0
495#define ONB_EIMEMARL 1
496#define ONB_EICONFR 2
497#define ONB_EIMEMARH 3
498#define ONB_EIENABLE 0x1
499#define ONB_EIDISABLE 0x0
500#define ONB_EISTOP 0x4
501#define ONB_EIEDGE 0x00
502#define ONB_EILEVEL 0x80
503#define ONB_EIADDRMASKL 0x00ff0000
504#define ONB_EIADDRSHFTL 16
505#define ONB_EIADDRMASKH 0xff000000
506#define ONB_EIADDRSHFTH 24
507#define ONB_EIBRDENAB 0xc84
508
509#define ONB_EISAID 0x1
510
511/*
512 * Important defines for the Brumby boards. They are pretty simple,
513 * there is not much that is programmably configurable.
514 */
515#define BBY_IOSIZE 16
516#define BBY_MEMSIZE (64 * 1024)
517#define BBY_PAGESIZE (16 * 1024)
518
519#define BBY_ATIREG 0
520#define BBY_ATCONFR 1
521#define BBY_ATSTOP 0x4
522
523/*
524 * Important defines for the Stallion boards. They are pretty simple,
525 * there is not much that is programmably configurable.
526 */
527#define STAL_IOSIZE 16
528#define STAL_MEMSIZE (64 * 1024)
529#define STAL_PAGESIZE (64 * 1024)
530
531/*
532 * Define the set of status register values for EasyConnection panels.
533 * The signature will return with the status value for each panel. From
534 * this we can determine what is attached to the board - before we have
535 * actually down loaded any code to it.
536 */
537#define ECH_PNLSTATUS 2
538#define ECH_PNL16PORT 0x20
539#define ECH_PNLIDMASK 0x07
540#define ECH_PNLXPID 0x40
541#define ECH_PNLINTRPEND 0x80
542
543/*
544 * Define some macros to do things to the board. Even those these boards
545 * are somewhat related there is often significantly different ways of
546 * doing some operation on it (like enable, paging, reset, etc). So each
547 * board class has a set of functions which do the commonly required
548 * operations. The macros below basically just call these functions,
549 * generally checking for a NULL function - which means that the board
550 * needs nothing done to it to achieve this operation!
551 */
552#define EBRDINIT(brdp) \
553 if (brdp->init != NULL) \
554 (* brdp->init)(brdp)
555
556#define EBRDENABLE(brdp) \
557 if (brdp->enable != NULL) \
558 (* brdp->enable)(brdp);
559
560#define EBRDDISABLE(brdp) \
561 if (brdp->disable != NULL) \
562 (* brdp->disable)(brdp);
563
564#define EBRDINTR(brdp) \
565 if (brdp->intr != NULL) \
566 (* brdp->intr)(brdp);
567
568#define EBRDRESET(brdp) \
569 if (brdp->reset != NULL) \
570 (* brdp->reset)(brdp);
571
572#define EBRDGETMEMPTR(brdp,offset) \
573 (* brdp->getmemptr)(brdp, offset, __LINE__)
574
575/*
576 * Define the maximal baud rate, and the default baud base for ports.
577 */
578#define STL_MAXBAUD 460800
579#define STL_BAUDBASE 115200
580#define STL_CLOSEDELAY (5 * HZ / 10)
581
582/*****************************************************************************/
583
584/*
585 * Define macros to extract a brd or port number from a minor number.
586 */
587#define MINOR2BRD(min) (((min) & 0xc0) >> 6)
588#define MINOR2PORT(min) ((min) & 0x3f)
589
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590/*****************************************************************************/
591
592/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 * Prototype all functions in this driver!
594 */
595
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800596static int stli_parsebrd(struct stlconf *confp, char **argp);
Adrian Bunk672b2712006-06-30 01:55:30 -0700597static int stli_init(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598static int stli_open(struct tty_struct *tty, struct file *filp);
599static void stli_close(struct tty_struct *tty, struct file *filp);
600static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count);
601static void stli_putchar(struct tty_struct *tty, unsigned char ch);
602static void stli_flushchars(struct tty_struct *tty);
603static int stli_writeroom(struct tty_struct *tty);
604static int stli_charsinbuffer(struct tty_struct *tty);
605static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
Alan Cox606d0992006-12-08 02:38:45 -0800606static void stli_settermios(struct tty_struct *tty, struct ktermios *old);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607static void stli_throttle(struct tty_struct *tty);
608static void stli_unthrottle(struct tty_struct *tty);
609static void stli_stop(struct tty_struct *tty);
610static void stli_start(struct tty_struct *tty);
611static void stli_flushbuffer(struct tty_struct *tty);
612static void stli_breakctl(struct tty_struct *tty, int state);
613static void stli_waituntilsent(struct tty_struct *tty, int timeout);
614static void stli_sendxchar(struct tty_struct *tty, char ch);
615static void stli_hangup(struct tty_struct *tty);
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800616static int stli_portinfo(struct stlibrd *brdp, struct stliport *portp, int portnr, char *pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800618static int stli_brdinit(struct stlibrd *brdp);
619static int stli_startbrd(struct stlibrd *brdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp);
621static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp);
622static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800623static void stli_brdpoll(struct stlibrd *brdp, cdkhdr_t __iomem *hdrp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624static void stli_poll(unsigned long arg);
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800625static int stli_hostcmd(struct stlibrd *brdp, struct stliport *portp);
626static int stli_initopen(struct stlibrd *brdp, struct stliport *portp);
627static int stli_rawopen(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait);
628static int stli_rawclose(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait);
629static int stli_waitcarrier(struct stlibrd *brdp, struct stliport *portp, struct file *filp);
Al Viro3e577a82006-12-06 18:41:45 +0000630static void stli_dohangup(struct work_struct *);
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800631static int stli_setport(struct stliport *portp);
632static int stli_cmdwait(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback);
633static void stli_sendcmd(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_dodelaycmd(struct stliport *portp, cdkctrl_t __iomem *cp);
636static void stli_mkasyport(struct stliport *portp, asyport_t *pp, struct ktermios *tiosp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts);
638static long stli_mktiocm(unsigned long sigvalue);
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800639static void stli_read(struct stlibrd *brdp, struct stliport *portp);
640static int stli_getserial(struct stliport *portp, struct serial_struct __user *sp);
641static int stli_setserial(struct stliport *portp, struct serial_struct __user *sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642static int stli_getbrdstats(combrd_t __user *bp);
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800643static int stli_getportstats(struct stliport *portp, comstats_t __user *cp);
644static int stli_portcmdstats(struct stliport *portp);
645static int stli_clrportstats(struct stliport *portp, comstats_t __user *cp);
646static int stli_getportstruct(struct stliport __user *arg);
647static int stli_getbrdstruct(struct stlibrd __user *arg);
648static struct stlibrd *stli_allocbrd(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800650static void stli_ecpinit(struct stlibrd *brdp);
651static void stli_ecpenable(struct stlibrd *brdp);
652static void stli_ecpdisable(struct stlibrd *brdp);
653static void __iomem *stli_ecpgetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
654static void stli_ecpreset(struct stlibrd *brdp);
655static void stli_ecpintr(struct stlibrd *brdp);
656static void stli_ecpeiinit(struct stlibrd *brdp);
657static void stli_ecpeienable(struct stlibrd *brdp);
658static void stli_ecpeidisable(struct stlibrd *brdp);
659static void __iomem *stli_ecpeigetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
660static void stli_ecpeireset(struct stlibrd *brdp);
661static void stli_ecpmcenable(struct stlibrd *brdp);
662static void stli_ecpmcdisable(struct stlibrd *brdp);
663static void __iomem *stli_ecpmcgetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
664static void stli_ecpmcreset(struct stlibrd *brdp);
665static void stli_ecppciinit(struct stlibrd *brdp);
666static void __iomem *stli_ecppcigetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
667static void stli_ecppcireset(struct stlibrd *brdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800669static void stli_onbinit(struct stlibrd *brdp);
670static void stli_onbenable(struct stlibrd *brdp);
671static void stli_onbdisable(struct stlibrd *brdp);
672static void __iomem *stli_onbgetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
673static void stli_onbreset(struct stlibrd *brdp);
674static void stli_onbeinit(struct stlibrd *brdp);
675static void stli_onbeenable(struct stlibrd *brdp);
676static void stli_onbedisable(struct stlibrd *brdp);
677static void __iomem *stli_onbegetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
678static void stli_onbereset(struct stlibrd *brdp);
679static void stli_bbyinit(struct stlibrd *brdp);
680static void __iomem *stli_bbygetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
681static void stli_bbyreset(struct stlibrd *brdp);
682static void stli_stalinit(struct stlibrd *brdp);
683static void __iomem *stli_stalgetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
684static void stli_stalreset(struct stlibrd *brdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685
Jiri Slaby1328d732006-12-08 02:39:19 -0800686static struct stliport *stli_getport(unsigned int brdnr, unsigned int panelnr, unsigned int portnr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800688static int stli_initecp(struct stlibrd *brdp);
689static int stli_initonb(struct stlibrd *brdp);
Jiri Slabya00f33f2006-12-08 02:39:20 -0800690#if STLI_EISAPROBE != 0
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800691static int stli_eisamemprobe(struct stlibrd *brdp);
Jiri Slabya00f33f2006-12-08 02:39:20 -0800692#endif
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800693static int stli_initports(struct stlibrd *brdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695/*****************************************************************************/
696
697/*
698 * Define the driver info for a user level shared memory device. This
699 * device will work sort of like the /dev/kmem device - except that it
700 * will give access to the shared memory on the Stallion intelligent
701 * board. This is also a very useful debugging tool.
702 */
Arjan van de Ven62322d22006-07-03 00:24:21 -0700703static const struct file_operations stli_fsiomem = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 .owner = THIS_MODULE,
705 .read = stli_memread,
706 .write = stli_memwrite,
707 .ioctl = stli_memioctl,
708};
709
710/*****************************************************************************/
711
712/*
713 * Define a timer_list entry for our poll routine. The slave board
714 * is polled every so often to see if anything needs doing. This is
715 * much cheaper on host cpu than using interrupts. It turns out to
716 * not increase character latency by much either...
717 */
Ingo Molnar8d06afa2005-09-09 13:10:40 -0700718static DEFINE_TIMER(stli_timerlist, stli_poll, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
720static int stli_timeron;
721
722/*
723 * Define the calculation for the timeout routine.
724 */
725#define STLI_TIMEOUT (jiffies + 1)
726
727/*****************************************************************************/
728
gregkh@suse.deca8eca62005-03-23 09:53:09 -0800729static struct class *istallion_class;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800731static void stli_cleanup_ports(struct stlibrd *brdp)
Jiri Slaby845bead2006-12-08 02:39:17 -0800732{
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800733 struct stliport *portp;
Jiri Slaby845bead2006-12-08 02:39:17 -0800734 unsigned int j;
735
736 for (j = 0; j < STL_MAXPORTS; j++) {
737 portp = brdp->ports[j];
738 if (portp != NULL) {
739 if (portp->tty != NULL)
740 tty_hangup(portp->tty);
741 kfree(portp);
742 }
743 }
744}
745
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746/*
747 * Loadable module initialization stuff.
748 */
749
750static int __init istallion_module_init(void)
751{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 stli_init();
Alan Cox4ac43602006-06-28 04:26:52 -0700753 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754}
755
756/*****************************************************************************/
757
758static void __exit istallion_module_exit(void)
759{
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800760 struct stlibrd *brdp;
Jiri Slaby1328d732006-12-08 02:39:19 -0800761 unsigned int j;
Jiri Slaby845bead2006-12-08 02:39:17 -0800762 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 printk(KERN_INFO "Unloading %s: version %s\n", stli_drvtitle,
765 stli_drvversion);
766
Jiri Slaby845bead2006-12-08 02:39:17 -0800767 pci_unregister_driver(&stli_pcidriver);
Alan Cox4ac43602006-06-28 04:26:52 -0700768 /*
769 * Free up all allocated resources used by the ports. This includes
770 * memory and interrupts.
771 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 if (stli_timeron) {
773 stli_timeron = 0;
Alan Cox4ac43602006-06-28 04:26:52 -0700774 del_timer_sync(&stli_timerlist);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 }
776
777 i = tty_unregister_driver(stli_serial);
778 if (i) {
779 printk("STALLION: failed to un-register tty driver, "
780 "errno=%d\n", -i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 return;
782 }
783 put_tty_driver(stli_serial);
Jiri Slaby1328d732006-12-08 02:39:19 -0800784 for (j = 0; j < 4; j++)
785 class_device_destroy(istallion_class, MKDEV(STL_SIOMEMMAJOR, j));
gregkh@suse.deca8eca62005-03-23 09:53:09 -0800786 class_destroy(istallion_class);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
788 printk("STALLION: failed to un-register serial memory device, "
789 "errno=%d\n", -i);
Jesper Juhl735d5662005-11-07 01:01:29 -0800790
Jesper Juhl735d5662005-11-07 01:01:29 -0800791 kfree(stli_txcookbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792
Jiri Slaby1328d732006-12-08 02:39:19 -0800793 for (j = 0; (j < stli_nrbrds); j++) {
794 if ((brdp = stli_brds[j]) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 continue;
Jiri Slaby845bead2006-12-08 02:39:17 -0800796
797 stli_cleanup_ports(brdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798
799 iounmap(brdp->membase);
800 if (brdp->iosize > 0)
801 release_region(brdp->iobase, brdp->iosize);
802 kfree(brdp);
Jiri Slaby1328d732006-12-08 02:39:19 -0800803 stli_brds[j] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805}
806
807module_init(istallion_module_init);
808module_exit(istallion_module_exit);
809
810/*****************************************************************************/
811
812/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 * Parse the supplied argument string, into the board conf struct.
814 */
815
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800816static int stli_parsebrd(struct stlconf *confp, char **argp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817{
Jiri Slaby1328d732006-12-08 02:39:19 -0800818 unsigned int i;
Alan Cox4ac43602006-06-28 04:26:52 -0700819 char *sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820
Alan Cox4ac43602006-06-28 04:26:52 -0700821 if (argp[0] == NULL || *argp[0] == 0)
822 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823
824 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
Jiri Slabya3f8d9d2006-12-08 02:39:18 -0800825 *sp = tolower(*sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826
Tobias Klauserfe971072006-01-09 20:54:02 -0800827 for (i = 0; i < ARRAY_SIZE(stli_brdstr); i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 if (strcmp(stli_brdstr[i].name, argp[0]) == 0)
829 break;
830 }
Tobias Klauserfe971072006-01-09 20:54:02 -0800831 if (i == ARRAY_SIZE(stli_brdstr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 printk("STALLION: unknown board name, %s?\n", argp[0]);
Tobias Klauserfe971072006-01-09 20:54:02 -0800833 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 }
835
836 confp->brdtype = stli_brdstr[i].type;
Alan Cox4ac43602006-06-28 04:26:52 -0700837 if (argp[1] != NULL && *argp[1] != 0)
Jiri Slabya3f8d9d2006-12-08 02:39:18 -0800838 confp->ioaddr1 = simple_strtoul(argp[1], NULL, 0);
Alan Cox4ac43602006-06-28 04:26:52 -0700839 if (argp[2] != NULL && *argp[2] != 0)
Jiri Slabya3f8d9d2006-12-08 02:39:18 -0800840 confp->memaddr = simple_strtoul(argp[2], NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 return(1);
842}
843
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844/*****************************************************************************/
845
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846static int stli_open(struct tty_struct *tty, struct file *filp)
847{
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800848 struct stlibrd *brdp;
849 struct stliport *portp;
Jiri Slaby1328d732006-12-08 02:39:19 -0800850 unsigned int minordev, brdnr, portnr;
851 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852
853 minordev = tty->index;
854 brdnr = MINOR2BRD(minordev);
855 if (brdnr >= stli_nrbrds)
Alan Cox4ac43602006-06-28 04:26:52 -0700856 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 brdp = stli_brds[brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -0700858 if (brdp == NULL)
859 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 if ((brdp->state & BST_STARTED) == 0)
Alan Cox4ac43602006-06-28 04:26:52 -0700861 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 portnr = MINOR2PORT(minordev);
Jiri Slaby1328d732006-12-08 02:39:19 -0800863 if (portnr > brdp->nrports)
Alan Cox4ac43602006-06-28 04:26:52 -0700864 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865
866 portp = brdp->ports[portnr];
Alan Cox4ac43602006-06-28 04:26:52 -0700867 if (portp == NULL)
868 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 if (portp->devnr < 1)
Alan Cox4ac43602006-06-28 04:26:52 -0700870 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871
872
873/*
874 * Check if this port is in the middle of closing. If so then wait
875 * until it is closed then return error status based on flag settings.
876 * The sleep here does not need interrupt protection since the wakeup
877 * for it is done with the same context.
878 */
879 if (portp->flags & ASYNC_CLOSING) {
880 interruptible_sleep_on(&portp->close_wait);
881 if (portp->flags & ASYNC_HUP_NOTIFY)
Alan Cox4ac43602006-06-28 04:26:52 -0700882 return -EAGAIN;
883 return -ERESTARTSYS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 }
885
886/*
887 * On the first open of the device setup the port hardware, and
888 * initialize the per port data structure. Since initializing the port
889 * requires several commands to the board we will need to wait for any
890 * other open that is already initializing the port.
891 */
892 portp->tty = tty;
893 tty->driver_data = portp;
894 portp->refcount++;
895
896 wait_event_interruptible(portp->raw_wait,
897 !test_bit(ST_INITIALIZING, &portp->state));
898 if (signal_pending(current))
Alan Cox4ac43602006-06-28 04:26:52 -0700899 return -ERESTARTSYS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900
901 if ((portp->flags & ASYNC_INITIALIZED) == 0) {
902 set_bit(ST_INITIALIZING, &portp->state);
903 if ((rc = stli_initopen(brdp, portp)) >= 0) {
904 portp->flags |= ASYNC_INITIALIZED;
905 clear_bit(TTY_IO_ERROR, &tty->flags);
906 }
907 clear_bit(ST_INITIALIZING, &portp->state);
908 wake_up_interruptible(&portp->raw_wait);
909 if (rc < 0)
Alan Cox4ac43602006-06-28 04:26:52 -0700910 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 }
912
913/*
914 * Check if this port is in the middle of closing. If so then wait
915 * until it is closed then return error status, based on flag settings.
916 * The sleep here does not need interrupt protection since the wakeup
917 * for it is done with the same context.
918 */
919 if (portp->flags & ASYNC_CLOSING) {
920 interruptible_sleep_on(&portp->close_wait);
921 if (portp->flags & ASYNC_HUP_NOTIFY)
Alan Cox4ac43602006-06-28 04:26:52 -0700922 return -EAGAIN;
923 return -ERESTARTSYS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 }
925
926/*
927 * Based on type of open being done check if it can overlap with any
928 * previous opens still in effect. If we are a normal serial device
929 * then also we might have to wait for carrier.
930 */
931 if (!(filp->f_flags & O_NONBLOCK)) {
932 if ((rc = stli_waitcarrier(brdp, portp, filp)) != 0)
Alan Cox4ac43602006-06-28 04:26:52 -0700933 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 }
935 portp->flags |= ASYNC_NORMAL_ACTIVE;
Alan Cox4ac43602006-06-28 04:26:52 -0700936 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937}
938
939/*****************************************************************************/
940
941static void stli_close(struct tty_struct *tty, struct file *filp)
942{
Jiri Slaby1f8ec432006-12-08 02:39:18 -0800943 struct stlibrd *brdp;
944 struct stliport *portp;
Alan Cox4ac43602006-06-28 04:26:52 -0700945 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946
947 portp = tty->driver_data;
Alan Cox4ac43602006-06-28 04:26:52 -0700948 if (portp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 return;
950
Alan Cox4ac43602006-06-28 04:26:52 -0700951 spin_lock_irqsave(&stli_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 if (tty_hung_up_p(filp)) {
Alan Cox4ac43602006-06-28 04:26:52 -0700953 spin_unlock_irqrestore(&stli_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 return;
955 }
956 if ((tty->count == 1) && (portp->refcount != 1))
957 portp->refcount = 1;
958 if (portp->refcount-- > 1) {
Alan Cox4ac43602006-06-28 04:26:52 -0700959 spin_unlock_irqrestore(&stli_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 return;
961 }
962
963 portp->flags |= ASYNC_CLOSING;
964
965/*
966 * May want to wait for data to drain before closing. The BUSY flag
967 * keeps track of whether we are still transmitting or not. It is
968 * updated by messages from the slave - indicating when all chars
969 * really have drained.
970 */
971 if (tty == stli_txcooktty)
972 stli_flushchars(tty);
973 tty->closing = 1;
Alan Cox4ac43602006-06-28 04:26:52 -0700974 spin_unlock_irqrestore(&stli_lock, flags);
975
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
977 tty_wait_until_sent(tty, portp->closing_wait);
978
979 portp->flags &= ~ASYNC_INITIALIZED;
980 brdp = stli_brds[portp->brdnr];
981 stli_rawclose(brdp, portp, 0, 0);
982 if (tty->termios->c_cflag & HUPCL) {
983 stli_mkasysigs(&portp->asig, 0, 0);
984 if (test_bit(ST_CMDING, &portp->state))
985 set_bit(ST_DOSIGS, &portp->state);
986 else
987 stli_sendcmd(brdp, portp, A_SETSIGNALS, &portp->asig,
988 sizeof(asysigs_t), 0);
989 }
990 clear_bit(ST_TXBUSY, &portp->state);
991 clear_bit(ST_RXSTOP, &portp->state);
992 set_bit(TTY_IO_ERROR, &tty->flags);
993 if (tty->ldisc.flush_buffer)
994 (tty->ldisc.flush_buffer)(tty);
995 set_bit(ST_DOFLUSHRX, &portp->state);
996 stli_flushbuffer(tty);
997
998 tty->closing = 0;
Alan Cox4ac43602006-06-28 04:26:52 -0700999 portp->tty = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000
1001 if (portp->openwaitcnt) {
1002 if (portp->close_delay)
1003 msleep_interruptible(jiffies_to_msecs(portp->close_delay));
1004 wake_up_interruptible(&portp->open_wait);
1005 }
1006
1007 portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1008 wake_up_interruptible(&portp->close_wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009}
1010
1011/*****************************************************************************/
1012
1013/*
1014 * Carry out first open operations on a port. This involves a number of
1015 * commands to be sent to the slave. We need to open the port, set the
1016 * notification events, set the initial port settings, get and set the
1017 * initial signal values. We sleep and wait in between each one. But
1018 * this still all happens pretty quickly.
1019 */
1020
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001021static int stli_initopen(struct stlibrd *brdp, struct stliport *portp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022{
Alan Cox4ac43602006-06-28 04:26:52 -07001023 struct tty_struct *tty;
1024 asynotify_t nt;
1025 asyport_t aport;
1026 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027
1028 if ((rc = stli_rawopen(brdp, portp, 0, 1)) < 0)
Alan Cox4ac43602006-06-28 04:26:52 -07001029 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030
1031 memset(&nt, 0, sizeof(asynotify_t));
1032 nt.data = (DT_TXLOW | DT_TXEMPTY | DT_RXBUSY | DT_RXBREAK);
1033 nt.signal = SG_DCD;
1034 if ((rc = stli_cmdwait(brdp, portp, A_SETNOTIFY, &nt,
1035 sizeof(asynotify_t), 0)) < 0)
Alan Cox4ac43602006-06-28 04:26:52 -07001036 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037
1038 tty = portp->tty;
Alan Cox4ac43602006-06-28 04:26:52 -07001039 if (tty == NULL)
1040 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 stli_mkasyport(portp, &aport, tty->termios);
1042 if ((rc = stli_cmdwait(brdp, portp, A_SETPORT, &aport,
1043 sizeof(asyport_t), 0)) < 0)
Alan Cox4ac43602006-06-28 04:26:52 -07001044 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045
1046 set_bit(ST_GETSIGS, &portp->state);
1047 if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS, &portp->asig,
1048 sizeof(asysigs_t), 1)) < 0)
Alan Cox4ac43602006-06-28 04:26:52 -07001049 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 if (test_and_clear_bit(ST_GETSIGS, &portp->state))
1051 portp->sigs = stli_mktiocm(portp->asig.sigvalue);
1052 stli_mkasysigs(&portp->asig, 1, 1);
1053 if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1054 sizeof(asysigs_t), 0)) < 0)
Alan Cox4ac43602006-06-28 04:26:52 -07001055 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056
Alan Cox4ac43602006-06-28 04:26:52 -07001057 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058}
1059
1060/*****************************************************************************/
1061
1062/*
1063 * Send an open message to the slave. This will sleep waiting for the
1064 * acknowledgement, so must have user context. We need to co-ordinate
1065 * with close events here, since we don't want open and close events
1066 * to overlap.
1067 */
1068
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001069static int stli_rawopen(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070{
Alan Cox4ac43602006-06-28 04:26:52 -07001071 cdkhdr_t __iomem *hdrp;
1072 cdkctrl_t __iomem *cp;
1073 unsigned char __iomem *bits;
1074 unsigned long flags;
1075 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076
1077/*
1078 * Send a message to the slave to open this port.
1079 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080
1081/*
1082 * Slave is already closing this port. This can happen if a hangup
1083 * occurs on this port. So we must wait until it is complete. The
1084 * order of opens and closes may not be preserved across shared
1085 * memory, so we must wait until it is complete.
1086 */
1087 wait_event_interruptible(portp->raw_wait,
1088 !test_bit(ST_CLOSING, &portp->state));
1089 if (signal_pending(current)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 return -ERESTARTSYS;
1091 }
1092
1093/*
1094 * Everything is ready now, so write the open message into shared
1095 * memory. Once the message is in set the service bits to say that
1096 * this port wants service.
1097 */
Alan Cox4ac43602006-06-28 04:26:52 -07001098 spin_lock_irqsave(&brd_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 EBRDENABLE(brdp);
Alan Cox4ac43602006-06-28 04:26:52 -07001100 cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
1101 writel(arg, &cp->openarg);
1102 writeb(1, &cp->open);
1103 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1104 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 portp->portidx;
Alan Cox4ac43602006-06-28 04:26:52 -07001106 writeb(readb(bits) | portp->portbit, bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 EBRDDISABLE(brdp);
1108
1109 if (wait == 0) {
Alan Cox4ac43602006-06-28 04:26:52 -07001110 spin_unlock_irqrestore(&brd_lock, flags);
1111 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 }
1113
1114/*
1115 * Slave is in action, so now we must wait for the open acknowledgment
1116 * to come back.
1117 */
1118 rc = 0;
1119 set_bit(ST_OPENING, &portp->state);
Alan Cox4ac43602006-06-28 04:26:52 -07001120 spin_unlock_irqrestore(&brd_lock, flags);
1121
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 wait_event_interruptible(portp->raw_wait,
1123 !test_bit(ST_OPENING, &portp->state));
1124 if (signal_pending(current))
1125 rc = -ERESTARTSYS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126
1127 if ((rc == 0) && (portp->rc != 0))
1128 rc = -EIO;
Alan Cox4ac43602006-06-28 04:26:52 -07001129 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130}
1131
1132/*****************************************************************************/
1133
1134/*
1135 * Send a close message to the slave. Normally this will sleep waiting
1136 * for the acknowledgement, but if wait parameter is 0 it will not. If
1137 * wait is true then must have user context (to sleep).
1138 */
1139
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001140static int stli_rawclose(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141{
Alan Cox4ac43602006-06-28 04:26:52 -07001142 cdkhdr_t __iomem *hdrp;
1143 cdkctrl_t __iomem *cp;
1144 unsigned char __iomem *bits;
1145 unsigned long flags;
1146 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147
1148/*
1149 * Slave is already closing this port. This can happen if a hangup
1150 * occurs on this port.
1151 */
1152 if (wait) {
1153 wait_event_interruptible(portp->raw_wait,
1154 !test_bit(ST_CLOSING, &portp->state));
1155 if (signal_pending(current)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 return -ERESTARTSYS;
1157 }
1158 }
1159
1160/*
1161 * Write the close command into shared memory.
1162 */
Alan Cox4ac43602006-06-28 04:26:52 -07001163 spin_lock_irqsave(&brd_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 EBRDENABLE(brdp);
Alan Cox4ac43602006-06-28 04:26:52 -07001165 cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
1166 writel(arg, &cp->closearg);
1167 writeb(1, &cp->close);
1168 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1169 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 portp->portidx;
Alan Cox4ac43602006-06-28 04:26:52 -07001171 writeb(readb(bits) |portp->portbit, bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 EBRDDISABLE(brdp);
1173
1174 set_bit(ST_CLOSING, &portp->state);
Alan Cox4ac43602006-06-28 04:26:52 -07001175 spin_unlock_irqrestore(&brd_lock, flags);
1176
1177 if (wait == 0)
1178 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179
1180/*
1181 * Slave is in action, so now we must wait for the open acknowledgment
1182 * to come back.
1183 */
1184 rc = 0;
1185 wait_event_interruptible(portp->raw_wait,
1186 !test_bit(ST_CLOSING, &portp->state));
1187 if (signal_pending(current))
1188 rc = -ERESTARTSYS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189
1190 if ((rc == 0) && (portp->rc != 0))
1191 rc = -EIO;
Alan Cox4ac43602006-06-28 04:26:52 -07001192 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193}
1194
1195/*****************************************************************************/
1196
1197/*
1198 * Send a command to the slave and wait for the response. This must
1199 * have user context (it sleeps). This routine is generic in that it
1200 * can send any type of command. Its purpose is to wait for that command
1201 * to complete (as opposed to initiating the command then returning).
1202 */
1203
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001204static 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 -07001205{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 wait_event_interruptible(portp->raw_wait,
1207 !test_bit(ST_CMDING, &portp->state));
Alan Cox4ac43602006-06-28 04:26:52 -07001208 if (signal_pending(current))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 return -ERESTARTSYS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210
1211 stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
1212
1213 wait_event_interruptible(portp->raw_wait,
1214 !test_bit(ST_CMDING, &portp->state));
Alan Cox4ac43602006-06-28 04:26:52 -07001215 if (signal_pending(current))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 return -ERESTARTSYS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217
1218 if (portp->rc != 0)
Alan Cox4ac43602006-06-28 04:26:52 -07001219 return -EIO;
1220 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221}
1222
1223/*****************************************************************************/
1224
1225/*
1226 * Send the termios settings for this port to the slave. This sleeps
1227 * waiting for the command to complete - so must have user context.
1228 */
1229
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001230static int stli_setport(struct stliport *portp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001232 struct stlibrd *brdp;
Alan Cox4ac43602006-06-28 04:26:52 -07001233 asyport_t aport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234
Alan Cox4ac43602006-06-28 04:26:52 -07001235 if (portp == NULL)
1236 return -ENODEV;
1237 if (portp->tty == NULL)
1238 return -ENODEV;
Jiri Slaby1328d732006-12-08 02:39:19 -08001239 if (portp->brdnr >= stli_nrbrds)
Alan Cox4ac43602006-06-28 04:26:52 -07001240 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 brdp = stli_brds[portp->brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07001242 if (brdp == NULL)
1243 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244
1245 stli_mkasyport(portp, &aport, portp->tty->termios);
1246 return(stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0));
1247}
1248
1249/*****************************************************************************/
1250
1251/*
1252 * Possibly need to wait for carrier (DCD signal) to come high. Say
1253 * maybe because if we are clocal then we don't need to wait...
1254 */
1255
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001256static int stli_waitcarrier(struct stlibrd *brdp, struct stliport *portp, struct file *filp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257{
Alan Cox4ac43602006-06-28 04:26:52 -07001258 unsigned long flags;
1259 int rc, doclocal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260
1261 rc = 0;
1262 doclocal = 0;
1263
1264 if (portp->tty->termios->c_cflag & CLOCAL)
1265 doclocal++;
1266
Alan Cox4ac43602006-06-28 04:26:52 -07001267 spin_lock_irqsave(&stli_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 portp->openwaitcnt++;
1269 if (! tty_hung_up_p(filp))
1270 portp->refcount--;
Alan Cox4ac43602006-06-28 04:26:52 -07001271 spin_unlock_irqrestore(&stli_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272
1273 for (;;) {
1274 stli_mkasysigs(&portp->asig, 1, 1);
1275 if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS,
1276 &portp->asig, sizeof(asysigs_t), 0)) < 0)
1277 break;
1278 if (tty_hung_up_p(filp) ||
1279 ((portp->flags & ASYNC_INITIALIZED) == 0)) {
1280 if (portp->flags & ASYNC_HUP_NOTIFY)
1281 rc = -EBUSY;
1282 else
1283 rc = -ERESTARTSYS;
1284 break;
1285 }
1286 if (((portp->flags & ASYNC_CLOSING) == 0) &&
1287 (doclocal || (portp->sigs & TIOCM_CD))) {
1288 break;
1289 }
1290 if (signal_pending(current)) {
1291 rc = -ERESTARTSYS;
1292 break;
1293 }
1294 interruptible_sleep_on(&portp->open_wait);
1295 }
1296
Alan Cox4ac43602006-06-28 04:26:52 -07001297 spin_lock_irqsave(&stli_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 if (! tty_hung_up_p(filp))
1299 portp->refcount++;
1300 portp->openwaitcnt--;
Alan Cox4ac43602006-06-28 04:26:52 -07001301 spin_unlock_irqrestore(&stli_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302
Alan Cox4ac43602006-06-28 04:26:52 -07001303 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304}
1305
1306/*****************************************************************************/
1307
1308/*
1309 * Write routine. Take the data and put it in the shared memory ring
1310 * queue. If port is not already sending chars then need to mark the
1311 * service bits for this port.
1312 */
1313
1314static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count)
1315{
Alan Cox4ac43602006-06-28 04:26:52 -07001316 cdkasy_t __iomem *ap;
1317 cdkhdr_t __iomem *hdrp;
1318 unsigned char __iomem *bits;
1319 unsigned char __iomem *shbuf;
1320 unsigned char *chbuf;
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001321 struct stliport *portp;
1322 struct stlibrd *brdp;
Alan Cox4ac43602006-06-28 04:26:52 -07001323 unsigned int len, stlen, head, tail, size;
1324 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 if (tty == stli_txcooktty)
1327 stli_flushchars(tty);
1328 portp = tty->driver_data;
Alan Cox4ac43602006-06-28 04:26:52 -07001329 if (portp == NULL)
1330 return 0;
Jiri Slaby1328d732006-12-08 02:39:19 -08001331 if (portp->brdnr >= stli_nrbrds)
Alan Cox4ac43602006-06-28 04:26:52 -07001332 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 brdp = stli_brds[portp->brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07001334 if (brdp == NULL)
1335 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 chbuf = (unsigned char *) buf;
1337
1338/*
1339 * All data is now local, shove as much as possible into shared memory.
1340 */
Alan Cox4ac43602006-06-28 04:26:52 -07001341 spin_lock_irqsave(&brd_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 EBRDENABLE(brdp);
Alan Cox4ac43602006-06-28 04:26:52 -07001343 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
1344 head = (unsigned int) readw(&ap->txq.head);
1345 tail = (unsigned int) readw(&ap->txq.tail);
1346 if (tail != ((unsigned int) readw(&ap->txq.tail)))
1347 tail = (unsigned int) readw(&ap->txq.tail);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 size = portp->txsize;
1349 if (head >= tail) {
1350 len = size - (head - tail) - 1;
1351 stlen = size - head;
1352 } else {
1353 len = tail - head - 1;
1354 stlen = len;
1355 }
1356
Jiri Slabya3f8d9d2006-12-08 02:39:18 -08001357 len = min(len, (unsigned int)count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 count = 0;
Alan Cox4ac43602006-06-28 04:26:52 -07001359 shbuf = (char __iomem *) EBRDGETMEMPTR(brdp, portp->txoffset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360
1361 while (len > 0) {
Jiri Slabya3f8d9d2006-12-08 02:39:18 -08001362 stlen = min(len, stlen);
Alan Cox4ac43602006-06-28 04:26:52 -07001363 memcpy_toio(shbuf + head, chbuf, stlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 chbuf += stlen;
1365 len -= stlen;
1366 count += stlen;
1367 head += stlen;
1368 if (head >= size) {
1369 head = 0;
1370 stlen = tail;
1371 }
1372 }
1373
Alan Cox4ac43602006-06-28 04:26:52 -07001374 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
1375 writew(head, &ap->txq.head);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 if (test_bit(ST_TXBUSY, &portp->state)) {
Alan Cox4ac43602006-06-28 04:26:52 -07001377 if (readl(&ap->changed.data) & DT_TXEMPTY)
1378 writel(readl(&ap->changed.data) & ~DT_TXEMPTY, &ap->changed.data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 }
Alan Cox4ac43602006-06-28 04:26:52 -07001380 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1381 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 portp->portidx;
Alan Cox4ac43602006-06-28 04:26:52 -07001383 writeb(readb(bits) | portp->portbit, bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384 set_bit(ST_TXBUSY, &portp->state);
1385 EBRDDISABLE(brdp);
Alan Cox4ac43602006-06-28 04:26:52 -07001386 spin_unlock_irqrestore(&brd_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387
1388 return(count);
1389}
1390
1391/*****************************************************************************/
1392
1393/*
1394 * Output a single character. We put it into a temporary local buffer
1395 * (for speed) then write out that buffer when the flushchars routine
1396 * is called. There is a safety catch here so that if some other port
1397 * writes chars before the current buffer has been, then we write them
1398 * first them do the new ports.
1399 */
1400
1401static void stli_putchar(struct tty_struct *tty, unsigned char ch)
1402{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 if (tty != stli_txcooktty) {
Alan Cox4ac43602006-06-28 04:26:52 -07001404 if (stli_txcooktty != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 stli_flushchars(stli_txcooktty);
1406 stli_txcooktty = tty;
1407 }
1408
1409 stli_txcookbuf[stli_txcooksize++] = ch;
1410}
1411
1412/*****************************************************************************/
1413
1414/*
1415 * Transfer characters from the local TX cooking buffer to the board.
1416 * We sort of ignore the tty that gets passed in here. We rely on the
1417 * info stored with the TX cook buffer to tell us which port to flush
1418 * the data on. In any case we clean out the TX cook buffer, for re-use
1419 * by someone else.
1420 */
1421
1422static void stli_flushchars(struct tty_struct *tty)
1423{
Alan Cox4ac43602006-06-28 04:26:52 -07001424 cdkhdr_t __iomem *hdrp;
1425 unsigned char __iomem *bits;
1426 cdkasy_t __iomem *ap;
1427 struct tty_struct *cooktty;
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001428 struct stliport *portp;
1429 struct stlibrd *brdp;
Alan Cox4ac43602006-06-28 04:26:52 -07001430 unsigned int len, stlen, head, tail, size, count, cooksize;
1431 unsigned char *buf;
1432 unsigned char __iomem *shbuf;
1433 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434
1435 cooksize = stli_txcooksize;
1436 cooktty = stli_txcooktty;
1437 stli_txcooksize = 0;
1438 stli_txcookrealsize = 0;
Alan Cox4ac43602006-06-28 04:26:52 -07001439 stli_txcooktty = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440
Alan Cox4ac43602006-06-28 04:26:52 -07001441 if (tty == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 return;
Alan Cox4ac43602006-06-28 04:26:52 -07001443 if (cooktty == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 return;
1445 if (tty != cooktty)
1446 tty = cooktty;
1447 if (cooksize == 0)
1448 return;
1449
1450 portp = tty->driver_data;
Alan Cox4ac43602006-06-28 04:26:52 -07001451 if (portp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 return;
Jiri Slaby1328d732006-12-08 02:39:19 -08001453 if (portp->brdnr >= stli_nrbrds)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 return;
1455 brdp = stli_brds[portp->brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07001456 if (brdp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 return;
1458
Alan Cox4ac43602006-06-28 04:26:52 -07001459 spin_lock_irqsave(&brd_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 EBRDENABLE(brdp);
1461
Alan Cox4ac43602006-06-28 04:26:52 -07001462 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
1463 head = (unsigned int) readw(&ap->txq.head);
1464 tail = (unsigned int) readw(&ap->txq.tail);
1465 if (tail != ((unsigned int) readw(&ap->txq.tail)))
1466 tail = (unsigned int) readw(&ap->txq.tail);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 size = portp->txsize;
1468 if (head >= tail) {
1469 len = size - (head - tail) - 1;
1470 stlen = size - head;
1471 } else {
1472 len = tail - head - 1;
1473 stlen = len;
1474 }
1475
Jiri Slabya3f8d9d2006-12-08 02:39:18 -08001476 len = min(len, cooksize);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 count = 0;
Al Viro29756fa2006-10-10 22:47:27 +01001478 shbuf = EBRDGETMEMPTR(brdp, portp->txoffset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 buf = stli_txcookbuf;
1480
1481 while (len > 0) {
Jiri Slabya3f8d9d2006-12-08 02:39:18 -08001482 stlen = min(len, stlen);
Alan Cox4ac43602006-06-28 04:26:52 -07001483 memcpy_toio(shbuf + head, buf, stlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 buf += stlen;
1485 len -= stlen;
1486 count += stlen;
1487 head += stlen;
1488 if (head >= size) {
1489 head = 0;
1490 stlen = tail;
1491 }
1492 }
1493
Alan Cox4ac43602006-06-28 04:26:52 -07001494 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
1495 writew(head, &ap->txq.head);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496
1497 if (test_bit(ST_TXBUSY, &portp->state)) {
Alan Cox4ac43602006-06-28 04:26:52 -07001498 if (readl(&ap->changed.data) & DT_TXEMPTY)
1499 writel(readl(&ap->changed.data) & ~DT_TXEMPTY, &ap->changed.data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 }
Alan Cox4ac43602006-06-28 04:26:52 -07001501 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1502 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 portp->portidx;
Alan Cox4ac43602006-06-28 04:26:52 -07001504 writeb(readb(bits) | portp->portbit, bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 set_bit(ST_TXBUSY, &portp->state);
1506
1507 EBRDDISABLE(brdp);
Alan Cox4ac43602006-06-28 04:26:52 -07001508 spin_unlock_irqrestore(&brd_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509}
1510
1511/*****************************************************************************/
1512
1513static int stli_writeroom(struct tty_struct *tty)
1514{
Alan Cox4ac43602006-06-28 04:26:52 -07001515 cdkasyrq_t __iomem *rp;
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001516 struct stliport *portp;
1517 struct stlibrd *brdp;
Alan Cox4ac43602006-06-28 04:26:52 -07001518 unsigned int head, tail, len;
1519 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 if (tty == stli_txcooktty) {
1522 if (stli_txcookrealsize != 0) {
1523 len = stli_txcookrealsize - stli_txcooksize;
Alan Cox4ac43602006-06-28 04:26:52 -07001524 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525 }
1526 }
1527
1528 portp = tty->driver_data;
Alan Cox4ac43602006-06-28 04:26:52 -07001529 if (portp == NULL)
1530 return 0;
Jiri Slaby1328d732006-12-08 02:39:19 -08001531 if (portp->brdnr >= stli_nrbrds)
Alan Cox4ac43602006-06-28 04:26:52 -07001532 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 brdp = stli_brds[portp->brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07001534 if (brdp == NULL)
1535 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536
Alan Cox4ac43602006-06-28 04:26:52 -07001537 spin_lock_irqsave(&brd_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 EBRDENABLE(brdp);
Alan Cox4ac43602006-06-28 04:26:52 -07001539 rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
1540 head = (unsigned int) readw(&rp->head);
1541 tail = (unsigned int) readw(&rp->tail);
1542 if (tail != ((unsigned int) readw(&rp->tail)))
1543 tail = (unsigned int) readw(&rp->tail);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 len = (head >= tail) ? (portp->txsize - (head - tail)) : (tail - head);
1545 len--;
1546 EBRDDISABLE(brdp);
Alan Cox4ac43602006-06-28 04:26:52 -07001547 spin_unlock_irqrestore(&brd_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548
1549 if (tty == stli_txcooktty) {
1550 stli_txcookrealsize = len;
1551 len -= stli_txcooksize;
1552 }
Alan Cox4ac43602006-06-28 04:26:52 -07001553 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554}
1555
1556/*****************************************************************************/
1557
1558/*
1559 * Return the number of characters in the transmit buffer. Normally we
1560 * will return the number of chars in the shared memory ring queue.
1561 * We need to kludge around the case where the shared memory buffer is
1562 * empty but not all characters have drained yet, for this case just
1563 * return that there is 1 character in the buffer!
1564 */
1565
1566static int stli_charsinbuffer(struct tty_struct *tty)
1567{
Alan Cox4ac43602006-06-28 04:26:52 -07001568 cdkasyrq_t __iomem *rp;
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001569 struct stliport *portp;
1570 struct stlibrd *brdp;
Alan Cox4ac43602006-06-28 04:26:52 -07001571 unsigned int head, tail, len;
1572 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 if (tty == stli_txcooktty)
1575 stli_flushchars(tty);
1576 portp = tty->driver_data;
Alan Cox4ac43602006-06-28 04:26:52 -07001577 if (portp == NULL)
1578 return 0;
Jiri Slaby1328d732006-12-08 02:39:19 -08001579 if (portp->brdnr >= stli_nrbrds)
Alan Cox4ac43602006-06-28 04:26:52 -07001580 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 brdp = stli_brds[portp->brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07001582 if (brdp == NULL)
1583 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584
Alan Cox4ac43602006-06-28 04:26:52 -07001585 spin_lock_irqsave(&brd_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586 EBRDENABLE(brdp);
Alan Cox4ac43602006-06-28 04:26:52 -07001587 rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
1588 head = (unsigned int) readw(&rp->head);
1589 tail = (unsigned int) readw(&rp->tail);
1590 if (tail != ((unsigned int) readw(&rp->tail)))
1591 tail = (unsigned int) readw(&rp->tail);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592 len = (head >= tail) ? (head - tail) : (portp->txsize - (tail - head));
1593 if ((len == 0) && test_bit(ST_TXBUSY, &portp->state))
1594 len = 1;
1595 EBRDDISABLE(brdp);
Alan Cox4ac43602006-06-28 04:26:52 -07001596 spin_unlock_irqrestore(&brd_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597
Alan Cox4ac43602006-06-28 04:26:52 -07001598 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599}
1600
1601/*****************************************************************************/
1602
1603/*
1604 * Generate the serial struct info.
1605 */
1606
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001607static int stli_getserial(struct stliport *portp, struct serial_struct __user *sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608{
Alan Cox4ac43602006-06-28 04:26:52 -07001609 struct serial_struct sio;
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001610 struct stlibrd *brdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611
1612 memset(&sio, 0, sizeof(struct serial_struct));
1613 sio.type = PORT_UNKNOWN;
1614 sio.line = portp->portnr;
1615 sio.irq = 0;
1616 sio.flags = portp->flags;
1617 sio.baud_base = portp->baud_base;
1618 sio.close_delay = portp->close_delay;
1619 sio.closing_wait = portp->closing_wait;
1620 sio.custom_divisor = portp->custom_divisor;
1621 sio.xmit_fifo_size = 0;
1622 sio.hub6 = 0;
1623
1624 brdp = stli_brds[portp->brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07001625 if (brdp != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 sio.port = brdp->iobase;
1627
1628 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ?
1629 -EFAULT : 0;
1630}
1631
1632/*****************************************************************************/
1633
1634/*
1635 * Set port according to the serial struct info.
1636 * At this point we do not do any auto-configure stuff, so we will
1637 * just quietly ignore any requests to change irq, etc.
1638 */
1639
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001640static int stli_setserial(struct stliport *portp, struct serial_struct __user *sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641{
Alan Cox4ac43602006-06-28 04:26:52 -07001642 struct serial_struct sio;
1643 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644
1645 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1646 return -EFAULT;
1647 if (!capable(CAP_SYS_ADMIN)) {
1648 if ((sio.baud_base != portp->baud_base) ||
1649 (sio.close_delay != portp->close_delay) ||
1650 ((sio.flags & ~ASYNC_USR_MASK) !=
1651 (portp->flags & ~ASYNC_USR_MASK)))
Alan Cox4ac43602006-06-28 04:26:52 -07001652 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 }
1654
1655 portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
1656 (sio.flags & ASYNC_USR_MASK);
1657 portp->baud_base = sio.baud_base;
1658 portp->close_delay = sio.close_delay;
1659 portp->closing_wait = sio.closing_wait;
1660 portp->custom_divisor = sio.custom_divisor;
1661
1662 if ((rc = stli_setport(portp)) < 0)
Alan Cox4ac43602006-06-28 04:26:52 -07001663 return rc;
1664 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665}
1666
1667/*****************************************************************************/
1668
1669static int stli_tiocmget(struct tty_struct *tty, struct file *file)
1670{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001671 struct stliport *portp = tty->driver_data;
1672 struct stlibrd *brdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673 int rc;
1674
Alan Cox4ac43602006-06-28 04:26:52 -07001675 if (portp == NULL)
1676 return -ENODEV;
Jiri Slaby1328d732006-12-08 02:39:19 -08001677 if (portp->brdnr >= stli_nrbrds)
Alan Cox4ac43602006-06-28 04:26:52 -07001678 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 brdp = stli_brds[portp->brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07001680 if (brdp == NULL)
1681 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 if (tty->flags & (1 << TTY_IO_ERROR))
Alan Cox4ac43602006-06-28 04:26:52 -07001683 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684
1685 if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS,
1686 &portp->asig, sizeof(asysigs_t), 1)) < 0)
Alan Cox4ac43602006-06-28 04:26:52 -07001687 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688
1689 return stli_mktiocm(portp->asig.sigvalue);
1690}
1691
1692static int stli_tiocmset(struct tty_struct *tty, struct file *file,
1693 unsigned int set, unsigned int clear)
1694{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001695 struct stliport *portp = tty->driver_data;
1696 struct stlibrd *brdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 int rts = -1, dtr = -1;
1698
Alan Cox4ac43602006-06-28 04:26:52 -07001699 if (portp == NULL)
1700 return -ENODEV;
Jiri Slaby1328d732006-12-08 02:39:19 -08001701 if (portp->brdnr >= stli_nrbrds)
Alan Cox4ac43602006-06-28 04:26:52 -07001702 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 brdp = stli_brds[portp->brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07001704 if (brdp == NULL)
1705 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706 if (tty->flags & (1 << TTY_IO_ERROR))
Alan Cox4ac43602006-06-28 04:26:52 -07001707 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708
1709 if (set & TIOCM_RTS)
1710 rts = 1;
1711 if (set & TIOCM_DTR)
1712 dtr = 1;
1713 if (clear & TIOCM_RTS)
1714 rts = 0;
1715 if (clear & TIOCM_DTR)
1716 dtr = 0;
1717
1718 stli_mkasysigs(&portp->asig, dtr, rts);
1719
1720 return stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1721 sizeof(asysigs_t), 0);
1722}
1723
1724static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1725{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001726 struct stliport *portp;
1727 struct stlibrd *brdp;
Alan Cox4ac43602006-06-28 04:26:52 -07001728 unsigned int ival;
1729 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730 void __user *argp = (void __user *)arg;
1731
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 portp = tty->driver_data;
Alan Cox4ac43602006-06-28 04:26:52 -07001733 if (portp == NULL)
1734 return -ENODEV;
Jiri Slaby1328d732006-12-08 02:39:19 -08001735 if (portp->brdnr >= stli_nrbrds)
Alan Cox4ac43602006-06-28 04:26:52 -07001736 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 brdp = stli_brds[portp->brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07001738 if (brdp == NULL)
1739 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740
1741 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1742 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
1743 if (tty->flags & (1 << TTY_IO_ERROR))
Alan Cox4ac43602006-06-28 04:26:52 -07001744 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 }
1746
1747 rc = 0;
1748
1749 switch (cmd) {
1750 case TIOCGSOFTCAR:
1751 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
1752 (unsigned __user *) arg);
1753 break;
1754 case TIOCSSOFTCAR:
1755 if ((rc = get_user(ival, (unsigned __user *) arg)) == 0)
1756 tty->termios->c_cflag =
1757 (tty->termios->c_cflag & ~CLOCAL) |
1758 (ival ? CLOCAL : 0);
1759 break;
1760 case TIOCGSERIAL:
1761 rc = stli_getserial(portp, argp);
1762 break;
1763 case TIOCSSERIAL:
1764 rc = stli_setserial(portp, argp);
1765 break;
1766 case STL_GETPFLAG:
1767 rc = put_user(portp->pflag, (unsigned __user *)argp);
1768 break;
1769 case STL_SETPFLAG:
1770 if ((rc = get_user(portp->pflag, (unsigned __user *)argp)) == 0)
1771 stli_setport(portp);
1772 break;
1773 case COM_GETPORTSTATS:
1774 rc = stli_getportstats(portp, argp);
1775 break;
1776 case COM_CLRPORTSTATS:
1777 rc = stli_clrportstats(portp, argp);
1778 break;
1779 case TIOCSERCONFIG:
1780 case TIOCSERGWILD:
1781 case TIOCSERSWILD:
1782 case TIOCSERGETLSR:
1783 case TIOCSERGSTRUCT:
1784 case TIOCSERGETMULTI:
1785 case TIOCSERSETMULTI:
1786 default:
1787 rc = -ENOIOCTLCMD;
1788 break;
1789 }
1790
Alan Cox4ac43602006-06-28 04:26:52 -07001791 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792}
1793
1794/*****************************************************************************/
1795
1796/*
1797 * This routine assumes that we have user context and can sleep.
1798 * Looks like it is true for the current ttys implementation..!!
1799 */
1800
Alan Cox606d0992006-12-08 02:38:45 -08001801static void stli_settermios(struct tty_struct *tty, struct ktermios *old)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001803 struct stliport *portp;
1804 struct stlibrd *brdp;
Alan Cox606d0992006-12-08 02:38:45 -08001805 struct ktermios *tiosp;
Alan Cox4ac43602006-06-28 04:26:52 -07001806 asyport_t aport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807
Alan Cox4ac43602006-06-28 04:26:52 -07001808 if (tty == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 return;
1810 portp = tty->driver_data;
Alan Cox4ac43602006-06-28 04:26:52 -07001811 if (portp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 return;
Jiri Slaby1328d732006-12-08 02:39:19 -08001813 if (portp->brdnr >= stli_nrbrds)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 return;
1815 brdp = stli_brds[portp->brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07001816 if (brdp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 return;
1818
1819 tiosp = tty->termios;
1820 if ((tiosp->c_cflag == old->c_cflag) &&
1821 (tiosp->c_iflag == old->c_iflag))
1822 return;
1823
1824 stli_mkasyport(portp, &aport, tiosp);
1825 stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0);
1826 stli_mkasysigs(&portp->asig, ((tiosp->c_cflag & CBAUD) ? 1 : 0), -1);
1827 stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1828 sizeof(asysigs_t), 0);
1829 if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0))
1830 tty->hw_stopped = 0;
1831 if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
1832 wake_up_interruptible(&portp->open_wait);
1833}
1834
1835/*****************************************************************************/
1836
1837/*
1838 * Attempt to flow control who ever is sending us data. We won't really
1839 * do any flow control action here. We can't directly, and even if we
1840 * wanted to we would have to send a command to the slave. The slave
1841 * knows how to flow control, and will do so when its buffers reach its
1842 * internal high water marks. So what we will do is set a local state
1843 * bit that will stop us sending any RX data up from the poll routine
1844 * (which is the place where RX data from the slave is handled).
1845 */
1846
1847static void stli_throttle(struct tty_struct *tty)
1848{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001849 struct stliport *portp = tty->driver_data;
Alan Cox4ac43602006-06-28 04:26:52 -07001850 if (portp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 set_bit(ST_RXSTOP, &portp->state);
1853}
1854
1855/*****************************************************************************/
1856
1857/*
1858 * Unflow control the device sending us data... That means that all
1859 * we have to do is clear the RXSTOP state bit. The next poll call
1860 * will then be able to pass the RX data back up.
1861 */
1862
1863static void stli_unthrottle(struct tty_struct *tty)
1864{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001865 struct stliport *portp = tty->driver_data;
Alan Cox4ac43602006-06-28 04:26:52 -07001866 if (portp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868 clear_bit(ST_RXSTOP, &portp->state);
1869}
1870
1871/*****************************************************************************/
1872
1873/*
Alan Cox4ac43602006-06-28 04:26:52 -07001874 * Stop the transmitter.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 */
1876
1877static void stli_stop(struct tty_struct *tty)
1878{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879}
1880
1881/*****************************************************************************/
1882
1883/*
Alan Cox4ac43602006-06-28 04:26:52 -07001884 * Start the transmitter again.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885 */
1886
1887static void stli_start(struct tty_struct *tty)
1888{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889}
1890
1891/*****************************************************************************/
1892
1893/*
1894 * Scheduler called hang up routine. This is called from the scheduler,
1895 * not direct from the driver "poll" routine. We can't call it there
1896 * since the real local hangup code will enable/disable the board and
1897 * other things that we can't do while handling the poll. Much easier
1898 * to deal with it some time later (don't really care when, hangups
1899 * aren't that time critical).
1900 */
1901
Al Viro3e577a82006-12-06 18:41:45 +00001902static void stli_dohangup(struct work_struct *ugly_api)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001904 struct stliport *portp = container_of(ugly_api, struct stliport, tqhangup);
Alan Cox4ac43602006-06-28 04:26:52 -07001905 if (portp->tty != NULL) {
1906 tty_hangup(portp->tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907 }
1908}
1909
1910/*****************************************************************************/
1911
1912/*
1913 * Hangup this port. This is pretty much like closing the port, only
1914 * a little more brutal. No waiting for data to drain. Shutdown the
1915 * port and maybe drop signals. This is rather tricky really. We want
1916 * to close the port as well.
1917 */
1918
1919static void stli_hangup(struct tty_struct *tty)
1920{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001921 struct stliport *portp;
1922 struct stlibrd *brdp;
Alan Cox4ac43602006-06-28 04:26:52 -07001923 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925 portp = tty->driver_data;
Alan Cox4ac43602006-06-28 04:26:52 -07001926 if (portp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 return;
Jiri Slaby1328d732006-12-08 02:39:19 -08001928 if (portp->brdnr >= stli_nrbrds)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929 return;
1930 brdp = stli_brds[portp->brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07001931 if (brdp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932 return;
1933
1934 portp->flags &= ~ASYNC_INITIALIZED;
1935
Alan Cox4ac43602006-06-28 04:26:52 -07001936 if (!test_bit(ST_CLOSING, &portp->state))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937 stli_rawclose(brdp, portp, 0, 0);
Alan Cox4ac43602006-06-28 04:26:52 -07001938
1939 spin_lock_irqsave(&stli_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940 if (tty->termios->c_cflag & HUPCL) {
1941 stli_mkasysigs(&portp->asig, 0, 0);
1942 if (test_bit(ST_CMDING, &portp->state)) {
1943 set_bit(ST_DOSIGS, &portp->state);
1944 set_bit(ST_DOFLUSHTX, &portp->state);
1945 set_bit(ST_DOFLUSHRX, &portp->state);
1946 } else {
1947 stli_sendcmd(brdp, portp, A_SETSIGNALSF,
1948 &portp->asig, sizeof(asysigs_t), 0);
1949 }
1950 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951
1952 clear_bit(ST_TXBUSY, &portp->state);
1953 clear_bit(ST_RXSTOP, &portp->state);
1954 set_bit(TTY_IO_ERROR, &tty->flags);
Alan Cox4ac43602006-06-28 04:26:52 -07001955 portp->tty = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956 portp->flags &= ~ASYNC_NORMAL_ACTIVE;
1957 portp->refcount = 0;
Alan Cox4ac43602006-06-28 04:26:52 -07001958 spin_unlock_irqrestore(&stli_lock, flags);
1959
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960 wake_up_interruptible(&portp->open_wait);
1961}
1962
1963/*****************************************************************************/
1964
1965/*
1966 * Flush characters from the lower buffer. We may not have user context
1967 * so we cannot sleep waiting for it to complete. Also we need to check
1968 * if there is chars for this port in the TX cook buffer, and flush them
1969 * as well.
1970 */
1971
1972static void stli_flushbuffer(struct tty_struct *tty)
1973{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08001974 struct stliport *portp;
1975 struct stlibrd *brdp;
Alan Cox4ac43602006-06-28 04:26:52 -07001976 unsigned long ftype, flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978 portp = tty->driver_data;
Alan Cox4ac43602006-06-28 04:26:52 -07001979 if (portp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980 return;
Jiri Slaby1328d732006-12-08 02:39:19 -08001981 if (portp->brdnr >= stli_nrbrds)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982 return;
1983 brdp = stli_brds[portp->brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07001984 if (brdp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985 return;
1986
Alan Cox4ac43602006-06-28 04:26:52 -07001987 spin_lock_irqsave(&brd_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988 if (tty == stli_txcooktty) {
Alan Cox4ac43602006-06-28 04:26:52 -07001989 stli_txcooktty = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990 stli_txcooksize = 0;
1991 stli_txcookrealsize = 0;
1992 }
1993 if (test_bit(ST_CMDING, &portp->state)) {
1994 set_bit(ST_DOFLUSHTX, &portp->state);
1995 } else {
1996 ftype = FLUSHTX;
1997 if (test_bit(ST_DOFLUSHRX, &portp->state)) {
1998 ftype |= FLUSHRX;
1999 clear_bit(ST_DOFLUSHRX, &portp->state);
2000 }
Alan Cox4ac43602006-06-28 04:26:52 -07002001 __stli_sendcmd(brdp, portp, A_FLUSH, &ftype, sizeof(u32), 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002 }
Alan Cox4ac43602006-06-28 04:26:52 -07002003 spin_unlock_irqrestore(&brd_lock, flags);
2004 tty_wakeup(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005}
2006
2007/*****************************************************************************/
2008
2009static void stli_breakctl(struct tty_struct *tty, int state)
2010{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002011 struct stlibrd *brdp;
2012 struct stliport *portp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013 long arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015 portp = tty->driver_data;
Alan Cox4ac43602006-06-28 04:26:52 -07002016 if (portp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 return;
Jiri Slaby1328d732006-12-08 02:39:19 -08002018 if (portp->brdnr >= stli_nrbrds)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019 return;
2020 brdp = stli_brds[portp->brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07002021 if (brdp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 return;
2023
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024 arg = (state == -1) ? BREAKON : BREAKOFF;
2025 stli_cmdwait(brdp, portp, A_BREAK, &arg, sizeof(long), 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026}
2027
2028/*****************************************************************************/
2029
2030static void stli_waituntilsent(struct tty_struct *tty, int timeout)
2031{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002032 struct stliport *portp;
Alan Cox4ac43602006-06-28 04:26:52 -07002033 unsigned long tend;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034
Alan Cox4ac43602006-06-28 04:26:52 -07002035 if (tty == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036 return;
2037 portp = tty->driver_data;
Alan Cox4ac43602006-06-28 04:26:52 -07002038 if (portp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039 return;
2040
2041 if (timeout == 0)
2042 timeout = HZ;
2043 tend = jiffies + timeout;
2044
2045 while (test_bit(ST_TXBUSY, &portp->state)) {
2046 if (signal_pending(current))
2047 break;
2048 msleep_interruptible(20);
2049 if (time_after_eq(jiffies, tend))
2050 break;
2051 }
2052}
2053
2054/*****************************************************************************/
2055
2056static void stli_sendxchar(struct tty_struct *tty, char ch)
2057{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002058 struct stlibrd *brdp;
2059 struct stliport *portp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060 asyctrl_t actrl;
2061
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062 portp = tty->driver_data;
Alan Cox4ac43602006-06-28 04:26:52 -07002063 if (portp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 return;
Jiri Slaby1328d732006-12-08 02:39:19 -08002065 if (portp->brdnr >= stli_nrbrds)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 return;
2067 brdp = stli_brds[portp->brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07002068 if (brdp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069 return;
2070
2071 memset(&actrl, 0, sizeof(asyctrl_t));
2072 if (ch == STOP_CHAR(tty)) {
2073 actrl.rxctrl = CT_STOPFLOW;
2074 } else if (ch == START_CHAR(tty)) {
2075 actrl.rxctrl = CT_STARTFLOW;
2076 } else {
2077 actrl.txctrl = CT_SENDCHR;
2078 actrl.tximdch = ch;
2079 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
2081}
2082
2083/*****************************************************************************/
2084
2085#define MAXLINE 80
2086
2087/*
2088 * Format info for a specified port. The line is deliberately limited
2089 * to 80 characters. (If it is too long it will be truncated, if too
2090 * short then padded with spaces).
2091 */
2092
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002093static int stli_portinfo(struct stlibrd *brdp, struct stliport *portp, int portnr, char *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094{
Alan Cox4ac43602006-06-28 04:26:52 -07002095 char *sp, *uart;
2096 int rc, cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097
2098 rc = stli_portcmdstats(portp);
2099
2100 uart = "UNKNOWN";
2101 if (brdp->state & BST_STARTED) {
2102 switch (stli_comstats.hwid) {
Alan Cox4ac43602006-06-28 04:26:52 -07002103 case 0: uart = "2681"; break;
2104 case 1: uart = "SC26198"; break;
2105 default:uart = "CD1400"; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 }
2107 }
2108
2109 sp = pos;
2110 sp += sprintf(sp, "%d: uart:%s ", portnr, uart);
2111
2112 if ((brdp->state & BST_STARTED) && (rc >= 0)) {
2113 sp += sprintf(sp, "tx:%d rx:%d", (int) stli_comstats.txtotal,
2114 (int) stli_comstats.rxtotal);
2115
2116 if (stli_comstats.rxframing)
2117 sp += sprintf(sp, " fe:%d",
2118 (int) stli_comstats.rxframing);
2119 if (stli_comstats.rxparity)
2120 sp += sprintf(sp, " pe:%d",
2121 (int) stli_comstats.rxparity);
2122 if (stli_comstats.rxbreaks)
2123 sp += sprintf(sp, " brk:%d",
2124 (int) stli_comstats.rxbreaks);
2125 if (stli_comstats.rxoverrun)
2126 sp += sprintf(sp, " oe:%d",
2127 (int) stli_comstats.rxoverrun);
2128
2129 cnt = sprintf(sp, "%s%s%s%s%s ",
2130 (stli_comstats.signals & TIOCM_RTS) ? "|RTS" : "",
2131 (stli_comstats.signals & TIOCM_CTS) ? "|CTS" : "",
2132 (stli_comstats.signals & TIOCM_DTR) ? "|DTR" : "",
2133 (stli_comstats.signals & TIOCM_CD) ? "|DCD" : "",
2134 (stli_comstats.signals & TIOCM_DSR) ? "|DSR" : "");
2135 *sp = ' ';
2136 sp += cnt;
2137 }
2138
2139 for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
2140 *sp++ = ' ';
2141 if (cnt >= MAXLINE)
2142 pos[(MAXLINE - 2)] = '+';
2143 pos[(MAXLINE - 1)] = '\n';
2144
2145 return(MAXLINE);
2146}
2147
2148/*****************************************************************************/
2149
2150/*
2151 * Port info, read from the /proc file system.
2152 */
2153
2154static int stli_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
2155{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002156 struct stlibrd *brdp;
2157 struct stliport *portp;
Jiri Slaby1328d732006-12-08 02:39:19 -08002158 unsigned int brdnr, portnr, totalport;
Alan Cox4ac43602006-06-28 04:26:52 -07002159 int curoff, maxoff;
2160 char *pos;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161
2162 pos = page;
2163 totalport = 0;
2164 curoff = 0;
2165
2166 if (off == 0) {
2167 pos += sprintf(pos, "%s: version %s", stli_drvtitle,
2168 stli_drvversion);
2169 while (pos < (page + MAXLINE - 1))
2170 *pos++ = ' ';
2171 *pos++ = '\n';
2172 }
2173 curoff = MAXLINE;
2174
2175/*
2176 * We scan through for each board, panel and port. The offset is
2177 * calculated on the fly, and irrelevant ports are skipped.
2178 */
2179 for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
2180 brdp = stli_brds[brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07002181 if (brdp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 continue;
2183 if (brdp->state == 0)
2184 continue;
2185
2186 maxoff = curoff + (brdp->nrports * MAXLINE);
2187 if (off >= maxoff) {
2188 curoff = maxoff;
2189 continue;
2190 }
2191
2192 totalport = brdnr * STL_MAXPORTS;
2193 for (portnr = 0; (portnr < brdp->nrports); portnr++,
2194 totalport++) {
2195 portp = brdp->ports[portnr];
Alan Cox4ac43602006-06-28 04:26:52 -07002196 if (portp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 continue;
2198 if (off >= (curoff += MAXLINE))
2199 continue;
2200 if ((pos - page + MAXLINE) > count)
2201 goto stli_readdone;
2202 pos += stli_portinfo(brdp, portp, totalport, pos);
2203 }
2204 }
2205
2206 *eof = 1;
2207
2208stli_readdone:
2209 *start = page;
2210 return(pos - page);
2211}
2212
2213/*****************************************************************************/
2214
2215/*
2216 * Generic send command routine. This will send a message to the slave,
2217 * of the specified type with the specified argument. Must be very
2218 * careful of data that will be copied out from shared memory -
2219 * containing command results. The command completion is all done from
2220 * a poll routine that does not have user context. Therefore you cannot
2221 * copy back directly into user space, or to the kernel stack of a
2222 * process. This routine does not sleep, so can be called from anywhere.
Alan Cox4ac43602006-06-28 04:26:52 -07002223 *
2224 * The caller must hold the brd_lock (see also stli_sendcmd the usual
2225 * entry point)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226 */
2227
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002228static 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 -07002229{
Alan Cox4ac43602006-06-28 04:26:52 -07002230 cdkhdr_t __iomem *hdrp;
2231 cdkctrl_t __iomem *cp;
2232 unsigned char __iomem *bits;
2233 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234
Alan Cox4ac43602006-06-28 04:26:52 -07002235 spin_lock_irqsave(&brd_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236
2237 if (test_bit(ST_CMDING, &portp->state)) {
2238 printk(KERN_ERR "STALLION: command already busy, cmd=%x!\n",
2239 (int) cmd);
Alan Cox4ac43602006-06-28 04:26:52 -07002240 spin_unlock_irqrestore(&brd_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241 return;
2242 }
2243
2244 EBRDENABLE(brdp);
Alan Cox4ac43602006-06-28 04:26:52 -07002245 cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 if (size > 0) {
Alan Cox4ac43602006-06-28 04:26:52 -07002247 memcpy_toio((void __iomem *) &(cp->args[0]), arg, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 if (copyback) {
2249 portp->argp = arg;
2250 portp->argsize = size;
2251 }
2252 }
Alan Cox4ac43602006-06-28 04:26:52 -07002253 writel(0, &cp->status);
2254 writel(cmd, &cp->cmd);
2255 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2256 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 portp->portidx;
Alan Cox4ac43602006-06-28 04:26:52 -07002258 writeb(readb(bits) | portp->portbit, bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 set_bit(ST_CMDING, &portp->state);
2260 EBRDDISABLE(brdp);
Alan Cox4ac43602006-06-28 04:26:52 -07002261 spin_unlock_irqrestore(&brd_lock, flags);
2262}
2263
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002264static 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 -07002265{
2266 unsigned long flags;
2267
2268 spin_lock_irqsave(&brd_lock, flags);
2269 __stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
2270 spin_unlock_irqrestore(&brd_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271}
2272
2273/*****************************************************************************/
2274
2275/*
2276 * Read data from shared memory. This assumes that the shared memory
2277 * is enabled and that interrupts are off. Basically we just empty out
2278 * the shared memory buffer into the tty buffer. Must be careful to
2279 * handle the case where we fill up the tty buffer, but still have
2280 * more chars to unload.
2281 */
2282
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002283static void stli_read(struct stlibrd *brdp, struct stliport *portp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284{
Alan Cox4ac43602006-06-28 04:26:52 -07002285 cdkasyrq_t __iomem *rp;
2286 char __iomem *shbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 struct tty_struct *tty;
Alan Cox4ac43602006-06-28 04:26:52 -07002288 unsigned int head, tail, size;
2289 unsigned int len, stlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290
2291 if (test_bit(ST_RXSTOP, &portp->state))
2292 return;
2293 tty = portp->tty;
Alan Cox4ac43602006-06-28 04:26:52 -07002294 if (tty == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 return;
2296
Alan Cox4ac43602006-06-28 04:26:52 -07002297 rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
2298 head = (unsigned int) readw(&rp->head);
2299 if (head != ((unsigned int) readw(&rp->head)))
2300 head = (unsigned int) readw(&rp->head);
2301 tail = (unsigned int) readw(&rp->tail);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 size = portp->rxsize;
2303 if (head >= tail) {
2304 len = head - tail;
2305 stlen = len;
2306 } else {
2307 len = size - (tail - head);
2308 stlen = size - tail;
2309 }
2310
Alan Cox33f0f882006-01-09 20:54:13 -08002311 len = tty_buffer_request_room(tty, len);
Alan Cox4ac43602006-06-28 04:26:52 -07002312
2313 shbuf = (char __iomem *) EBRDGETMEMPTR(brdp, portp->rxoffset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314
2315 while (len > 0) {
Alan Cox4ac43602006-06-28 04:26:52 -07002316 unsigned char *cptr;
2317
Jiri Slabya3f8d9d2006-12-08 02:39:18 -08002318 stlen = min(len, stlen);
Alan Cox4ac43602006-06-28 04:26:52 -07002319 tty_prepare_flip_string(tty, &cptr, stlen);
2320 memcpy_fromio(cptr, shbuf + tail, stlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 len -= stlen;
2322 tail += stlen;
2323 if (tail >= size) {
2324 tail = 0;
2325 stlen = head;
2326 }
2327 }
Alan Cox4ac43602006-06-28 04:26:52 -07002328 rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
2329 writew(tail, &rp->tail);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330
2331 if (head != tail)
2332 set_bit(ST_RXING, &portp->state);
2333
2334 tty_schedule_flip(tty);
2335}
2336
2337/*****************************************************************************/
2338
2339/*
2340 * Set up and carry out any delayed commands. There is only a small set
2341 * of slave commands that can be done "off-level". So it is not too
2342 * difficult to deal with them here.
2343 */
2344
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002345static void stli_dodelaycmd(struct stliport *portp, cdkctrl_t __iomem *cp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346{
Alan Cox4ac43602006-06-28 04:26:52 -07002347 int cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348
2349 if (test_bit(ST_DOSIGS, &portp->state)) {
2350 if (test_bit(ST_DOFLUSHTX, &portp->state) &&
2351 test_bit(ST_DOFLUSHRX, &portp->state))
2352 cmd = A_SETSIGNALSF;
2353 else if (test_bit(ST_DOFLUSHTX, &portp->state))
2354 cmd = A_SETSIGNALSFTX;
2355 else if (test_bit(ST_DOFLUSHRX, &portp->state))
2356 cmd = A_SETSIGNALSFRX;
2357 else
2358 cmd = A_SETSIGNALS;
2359 clear_bit(ST_DOFLUSHTX, &portp->state);
2360 clear_bit(ST_DOFLUSHRX, &portp->state);
2361 clear_bit(ST_DOSIGS, &portp->state);
Alan Cox4ac43602006-06-28 04:26:52 -07002362 memcpy_toio((void __iomem *) &(cp->args[0]), (void *) &portp->asig,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 sizeof(asysigs_t));
Alan Cox4ac43602006-06-28 04:26:52 -07002364 writel(0, &cp->status);
2365 writel(cmd, &cp->cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 set_bit(ST_CMDING, &portp->state);
2367 } else if (test_bit(ST_DOFLUSHTX, &portp->state) ||
2368 test_bit(ST_DOFLUSHRX, &portp->state)) {
2369 cmd = ((test_bit(ST_DOFLUSHTX, &portp->state)) ? FLUSHTX : 0);
2370 cmd |= ((test_bit(ST_DOFLUSHRX, &portp->state)) ? FLUSHRX : 0);
2371 clear_bit(ST_DOFLUSHTX, &portp->state);
2372 clear_bit(ST_DOFLUSHRX, &portp->state);
Alan Cox4ac43602006-06-28 04:26:52 -07002373 memcpy_toio((void __iomem *) &(cp->args[0]), (void *) &cmd, sizeof(int));
2374 writel(0, &cp->status);
2375 writel(A_FLUSH, &cp->cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 set_bit(ST_CMDING, &portp->state);
2377 }
2378}
2379
2380/*****************************************************************************/
2381
2382/*
2383 * Host command service checking. This handles commands or messages
2384 * coming from the slave to the host. Must have board shared memory
2385 * enabled and interrupts off when called. Notice that by servicing the
2386 * read data last we don't need to change the shared memory pointer
2387 * during processing (which is a slow IO operation).
2388 * Return value indicates if this port is still awaiting actions from
2389 * the slave (like open, command, or even TX data being sent). If 0
2390 * then port is still busy, otherwise no longer busy.
2391 */
2392
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002393static int stli_hostcmd(struct stlibrd *brdp, struct stliport *portp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394{
Alan Cox4ac43602006-06-28 04:26:52 -07002395 cdkasy_t __iomem *ap;
2396 cdkctrl_t __iomem *cp;
2397 struct tty_struct *tty;
2398 asynotify_t nt;
2399 unsigned long oldsigs;
2400 int rc, donerx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401
Alan Cox4ac43602006-06-28 04:26:52 -07002402 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 cp = &ap->ctrl;
2404
2405/*
2406 * Check if we are waiting for an open completion message.
2407 */
2408 if (test_bit(ST_OPENING, &portp->state)) {
Alan Cox4ac43602006-06-28 04:26:52 -07002409 rc = readl(&cp->openarg);
2410 if (readb(&cp->open) == 0 && rc != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 if (rc > 0)
2412 rc--;
Alan Cox4ac43602006-06-28 04:26:52 -07002413 writel(0, &cp->openarg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414 portp->rc = rc;
2415 clear_bit(ST_OPENING, &portp->state);
2416 wake_up_interruptible(&portp->raw_wait);
2417 }
2418 }
2419
2420/*
2421 * Check if we are waiting for a close completion message.
2422 */
2423 if (test_bit(ST_CLOSING, &portp->state)) {
Alan Cox4ac43602006-06-28 04:26:52 -07002424 rc = (int) readl(&cp->closearg);
2425 if (readb(&cp->close) == 0 && rc != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 if (rc > 0)
2427 rc--;
Alan Cox4ac43602006-06-28 04:26:52 -07002428 writel(0, &cp->closearg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 portp->rc = rc;
2430 clear_bit(ST_CLOSING, &portp->state);
2431 wake_up_interruptible(&portp->raw_wait);
2432 }
2433 }
2434
2435/*
2436 * Check if we are waiting for a command completion message. We may
2437 * need to copy out the command results associated with this command.
2438 */
2439 if (test_bit(ST_CMDING, &portp->state)) {
Alan Cox4ac43602006-06-28 04:26:52 -07002440 rc = readl(&cp->status);
2441 if (readl(&cp->cmd) == 0 && rc != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 if (rc > 0)
2443 rc--;
Alan Cox4ac43602006-06-28 04:26:52 -07002444 if (portp->argp != NULL) {
2445 memcpy_fromio(portp->argp, (void __iomem *) &(cp->args[0]),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 portp->argsize);
Alan Cox4ac43602006-06-28 04:26:52 -07002447 portp->argp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 }
Alan Cox4ac43602006-06-28 04:26:52 -07002449 writel(0, &cp->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450 portp->rc = rc;
2451 clear_bit(ST_CMDING, &portp->state);
2452 stli_dodelaycmd(portp, cp);
2453 wake_up_interruptible(&portp->raw_wait);
2454 }
2455 }
2456
2457/*
2458 * Check for any notification messages ready. This includes lots of
2459 * different types of events - RX chars ready, RX break received,
2460 * TX data low or empty in the slave, modem signals changed state.
2461 */
2462 donerx = 0;
2463
2464 if (ap->notify) {
2465 nt = ap->changed;
2466 ap->notify = 0;
2467 tty = portp->tty;
2468
2469 if (nt.signal & SG_DCD) {
2470 oldsigs = portp->sigs;
2471 portp->sigs = stli_mktiocm(nt.sigvalue);
2472 clear_bit(ST_GETSIGS, &portp->state);
2473 if ((portp->sigs & TIOCM_CD) &&
2474 ((oldsigs & TIOCM_CD) == 0))
2475 wake_up_interruptible(&portp->open_wait);
2476 if ((oldsigs & TIOCM_CD) &&
2477 ((portp->sigs & TIOCM_CD) == 0)) {
2478 if (portp->flags & ASYNC_CHECK_CD) {
2479 if (tty)
2480 schedule_work(&portp->tqhangup);
2481 }
2482 }
2483 }
2484
2485 if (nt.data & DT_TXEMPTY)
2486 clear_bit(ST_TXBUSY, &portp->state);
2487 if (nt.data & (DT_TXEMPTY | DT_TXLOW)) {
Alan Cox4ac43602006-06-28 04:26:52 -07002488 if (tty != NULL) {
2489 tty_wakeup(tty);
2490 EBRDENABLE(brdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 wake_up_interruptible(&tty->write_wait);
2492 }
2493 }
2494
2495 if ((nt.data & DT_RXBREAK) && (portp->rxmarkmsk & BRKINT)) {
Alan Cox4ac43602006-06-28 04:26:52 -07002496 if (tty != NULL) {
Alan Cox33f0f882006-01-09 20:54:13 -08002497 tty_insert_flip_char(tty, 0, TTY_BREAK);
2498 if (portp->flags & ASYNC_SAK) {
2499 do_SAK(tty);
2500 EBRDENABLE(brdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501 }
Alan Cox33f0f882006-01-09 20:54:13 -08002502 tty_schedule_flip(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 }
2504 }
2505
2506 if (nt.data & DT_RXBUSY) {
2507 donerx++;
2508 stli_read(brdp, portp);
2509 }
2510 }
2511
2512/*
2513 * It might seem odd that we are checking for more RX chars here.
2514 * But, we need to handle the case where the tty buffer was previously
2515 * filled, but we had more characters to pass up. The slave will not
2516 * send any more RX notify messages until the RX buffer has been emptied.
2517 * But it will leave the service bits on (since the buffer is not empty).
2518 * So from here we can try to process more RX chars.
2519 */
2520 if ((!donerx) && test_bit(ST_RXING, &portp->state)) {
2521 clear_bit(ST_RXING, &portp->state);
2522 stli_read(brdp, portp);
2523 }
2524
2525 return((test_bit(ST_OPENING, &portp->state) ||
2526 test_bit(ST_CLOSING, &portp->state) ||
2527 test_bit(ST_CMDING, &portp->state) ||
2528 test_bit(ST_TXBUSY, &portp->state) ||
2529 test_bit(ST_RXING, &portp->state)) ? 0 : 1);
2530}
2531
2532/*****************************************************************************/
2533
2534/*
2535 * Service all ports on a particular board. Assumes that the boards
2536 * shared memory is enabled, and that the page pointer is pointed
2537 * at the cdk header structure.
2538 */
2539
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002540static void stli_brdpoll(struct stlibrd *brdp, cdkhdr_t __iomem *hdrp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002542 struct stliport *portp;
Alan Cox4ac43602006-06-28 04:26:52 -07002543 unsigned char hostbits[(STL_MAXCHANS / 8) + 1];
2544 unsigned char slavebits[(STL_MAXCHANS / 8) + 1];
2545 unsigned char __iomem *slavep;
2546 int bitpos, bitat, bitsize;
2547 int channr, nrdevs, slavebitchange;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548
2549 bitsize = brdp->bitsize;
2550 nrdevs = brdp->nrdevs;
2551
2552/*
2553 * Check if slave wants any service. Basically we try to do as
2554 * little work as possible here. There are 2 levels of service
2555 * bits. So if there is nothing to do we bail early. We check
2556 * 8 service bits at a time in the inner loop, so we can bypass
2557 * the lot if none of them want service.
2558 */
Alan Cox4ac43602006-06-28 04:26:52 -07002559 memcpy_fromio(&hostbits[0], (((unsigned char __iomem *) hdrp) + brdp->hostoffset),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560 bitsize);
2561
2562 memset(&slavebits[0], 0, bitsize);
2563 slavebitchange = 0;
2564
2565 for (bitpos = 0; (bitpos < bitsize); bitpos++) {
2566 if (hostbits[bitpos] == 0)
2567 continue;
2568 channr = bitpos * 8;
2569 for (bitat = 0x1; (channr < nrdevs); channr++, bitat <<= 1) {
2570 if (hostbits[bitpos] & bitat) {
2571 portp = brdp->ports[(channr - 1)];
2572 if (stli_hostcmd(brdp, portp)) {
2573 slavebitchange++;
2574 slavebits[bitpos] |= bitat;
2575 }
2576 }
2577 }
2578 }
2579
2580/*
2581 * If any of the ports are no longer busy then update them in the
2582 * slave request bits. We need to do this after, since a host port
2583 * service may initiate more slave requests.
2584 */
2585 if (slavebitchange) {
Alan Cox4ac43602006-06-28 04:26:52 -07002586 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2587 slavep = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588 for (bitpos = 0; (bitpos < bitsize); bitpos++) {
Alan Cox4ac43602006-06-28 04:26:52 -07002589 if (readb(slavebits + bitpos))
2590 writeb(readb(slavep + bitpos) & ~slavebits[bitpos], slavebits + bitpos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 }
2592 }
2593}
2594
2595/*****************************************************************************/
2596
2597/*
2598 * Driver poll routine. This routine polls the boards in use and passes
2599 * messages back up to host when necessary. This is actually very
2600 * CPU efficient, since we will always have the kernel poll clock, it
2601 * adds only a few cycles when idle (since board service can be
2602 * determined very easily), but when loaded generates no interrupts
2603 * (with their expensive associated context change).
2604 */
2605
2606static void stli_poll(unsigned long arg)
2607{
Alan Cox4ac43602006-06-28 04:26:52 -07002608 cdkhdr_t __iomem *hdrp;
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002609 struct stlibrd *brdp;
Jiri Slaby1328d732006-12-08 02:39:19 -08002610 unsigned int brdnr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611
2612 stli_timerlist.expires = STLI_TIMEOUT;
2613 add_timer(&stli_timerlist);
2614
2615/*
2616 * Check each board and do any servicing required.
2617 */
2618 for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
2619 brdp = stli_brds[brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07002620 if (brdp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 continue;
2622 if ((brdp->state & BST_STARTED) == 0)
2623 continue;
2624
Alan Cox4ac43602006-06-28 04:26:52 -07002625 spin_lock(&brd_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626 EBRDENABLE(brdp);
Alan Cox4ac43602006-06-28 04:26:52 -07002627 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2628 if (readb(&hdrp->hostreq))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 stli_brdpoll(brdp, hdrp);
2630 EBRDDISABLE(brdp);
Alan Cox4ac43602006-06-28 04:26:52 -07002631 spin_unlock(&brd_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632 }
2633}
2634
2635/*****************************************************************************/
2636
2637/*
2638 * Translate the termios settings into the port setting structure of
2639 * the slave.
2640 */
2641
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002642static void stli_mkasyport(struct stliport *portp, asyport_t *pp, struct ktermios *tiosp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 memset(pp, 0, sizeof(asyport_t));
2645
2646/*
2647 * Start of by setting the baud, char size, parity and stop bit info.
2648 */
Alan Cox1db27c12006-09-29 02:01:38 -07002649 pp->baudout = tty_get_baud_rate(portp->tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 if ((tiosp->c_cflag & CBAUD) == B38400) {
2651 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
2652 pp->baudout = 57600;
2653 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
2654 pp->baudout = 115200;
2655 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
2656 pp->baudout = 230400;
2657 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
2658 pp->baudout = 460800;
2659 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
2660 pp->baudout = (portp->baud_base / portp->custom_divisor);
2661 }
2662 if (pp->baudout > STL_MAXBAUD)
2663 pp->baudout = STL_MAXBAUD;
2664 pp->baudin = pp->baudout;
2665
2666 switch (tiosp->c_cflag & CSIZE) {
2667 case CS5:
2668 pp->csize = 5;
2669 break;
2670 case CS6:
2671 pp->csize = 6;
2672 break;
2673 case CS7:
2674 pp->csize = 7;
2675 break;
2676 default:
2677 pp->csize = 8;
2678 break;
2679 }
2680
2681 if (tiosp->c_cflag & CSTOPB)
2682 pp->stopbs = PT_STOP2;
2683 else
2684 pp->stopbs = PT_STOP1;
2685
2686 if (tiosp->c_cflag & PARENB) {
2687 if (tiosp->c_cflag & PARODD)
2688 pp->parity = PT_ODDPARITY;
2689 else
2690 pp->parity = PT_EVENPARITY;
2691 } else {
2692 pp->parity = PT_NOPARITY;
2693 }
2694
2695/*
2696 * Set up any flow control options enabled.
2697 */
2698 if (tiosp->c_iflag & IXON) {
2699 pp->flow |= F_IXON;
2700 if (tiosp->c_iflag & IXANY)
2701 pp->flow |= F_IXANY;
2702 }
2703 if (tiosp->c_cflag & CRTSCTS)
2704 pp->flow |= (F_RTSFLOW | F_CTSFLOW);
2705
2706 pp->startin = tiosp->c_cc[VSTART];
2707 pp->stopin = tiosp->c_cc[VSTOP];
2708 pp->startout = tiosp->c_cc[VSTART];
2709 pp->stopout = tiosp->c_cc[VSTOP];
2710
2711/*
2712 * Set up the RX char marking mask with those RX error types we must
2713 * catch. We can get the slave to help us out a little here, it will
2714 * ignore parity errors and breaks for us, and mark parity errors in
2715 * the data stream.
2716 */
2717 if (tiosp->c_iflag & IGNPAR)
2718 pp->iflag |= FI_IGNRXERRS;
2719 if (tiosp->c_iflag & IGNBRK)
2720 pp->iflag |= FI_IGNBREAK;
2721
2722 portp->rxmarkmsk = 0;
2723 if (tiosp->c_iflag & (INPCK | PARMRK))
2724 pp->iflag |= FI_1MARKRXERRS;
2725 if (tiosp->c_iflag & BRKINT)
2726 portp->rxmarkmsk |= BRKINT;
2727
2728/*
2729 * Set up clocal processing as required.
2730 */
2731 if (tiosp->c_cflag & CLOCAL)
2732 portp->flags &= ~ASYNC_CHECK_CD;
2733 else
2734 portp->flags |= ASYNC_CHECK_CD;
2735
2736/*
2737 * Transfer any persistent flags into the asyport structure.
2738 */
2739 pp->pflag = (portp->pflag & 0xffff);
2740 pp->vmin = (portp->pflag & P_RXIMIN) ? 1 : 0;
2741 pp->vtime = (portp->pflag & P_RXITIME) ? 1 : 0;
2742 pp->cc[1] = (portp->pflag & P_RXTHOLD) ? 1 : 0;
2743}
2744
2745/*****************************************************************************/
2746
2747/*
2748 * Construct a slave signals structure for setting the DTR and RTS
2749 * signals as specified.
2750 */
2751
2752static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts)
2753{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 memset(sp, 0, sizeof(asysigs_t));
2755 if (dtr >= 0) {
2756 sp->signal |= SG_DTR;
2757 sp->sigvalue |= ((dtr > 0) ? SG_DTR : 0);
2758 }
2759 if (rts >= 0) {
2760 sp->signal |= SG_RTS;
2761 sp->sigvalue |= ((rts > 0) ? SG_RTS : 0);
2762 }
2763}
2764
2765/*****************************************************************************/
2766
2767/*
2768 * Convert the signals returned from the slave into a local TIOCM type
2769 * signals value. We keep them locally in TIOCM format.
2770 */
2771
2772static long stli_mktiocm(unsigned long sigvalue)
2773{
Alan Cox4ac43602006-06-28 04:26:52 -07002774 long tiocm = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775 tiocm |= ((sigvalue & SG_DCD) ? TIOCM_CD : 0);
2776 tiocm |= ((sigvalue & SG_CTS) ? TIOCM_CTS : 0);
2777 tiocm |= ((sigvalue & SG_RI) ? TIOCM_RI : 0);
2778 tiocm |= ((sigvalue & SG_DSR) ? TIOCM_DSR : 0);
2779 tiocm |= ((sigvalue & SG_DTR) ? TIOCM_DTR : 0);
2780 tiocm |= ((sigvalue & SG_RTS) ? TIOCM_RTS : 0);
2781 return(tiocm);
2782}
2783
2784/*****************************************************************************/
2785
2786/*
2787 * All panels and ports actually attached have been worked out. All
2788 * we need to do here is set up the appropriate per port data structures.
2789 */
2790
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002791static int stli_initports(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002793 struct stliport *portp;
Jiri Slaby1328d732006-12-08 02:39:19 -08002794 unsigned int i, panelnr, panelport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796 for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) {
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002797 portp = kzalloc(sizeof(struct stliport), GFP_KERNEL);
Tobias Klauserb0b4ed72006-03-31 02:30:56 -08002798 if (!portp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799 printk("STALLION: failed to allocate port structure\n");
2800 continue;
2801 }
2802
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803 portp->magic = STLI_PORTMAGIC;
2804 portp->portnr = i;
2805 portp->brdnr = brdp->brdnr;
2806 portp->panelnr = panelnr;
2807 portp->baud_base = STL_BAUDBASE;
2808 portp->close_delay = STL_CLOSEDELAY;
2809 portp->closing_wait = 30 * HZ;
Al Viro3e577a82006-12-06 18:41:45 +00002810 INIT_WORK(&portp->tqhangup, stli_dohangup);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002811 init_waitqueue_head(&portp->open_wait);
2812 init_waitqueue_head(&portp->close_wait);
2813 init_waitqueue_head(&portp->raw_wait);
2814 panelport++;
2815 if (panelport >= brdp->panels[panelnr]) {
2816 panelport = 0;
2817 panelnr++;
2818 }
2819 brdp->ports[i] = portp;
2820 }
2821
Alan Cox4ac43602006-06-28 04:26:52 -07002822 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002823}
2824
2825/*****************************************************************************/
2826
2827/*
2828 * All the following routines are board specific hardware operations.
2829 */
2830
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002831static void stli_ecpinit(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832{
2833 unsigned long memconf;
2834
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835 outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
2836 udelay(10);
2837 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
2838 udelay(100);
2839
2840 memconf = (brdp->memaddr & ECP_ATADDRMASK) >> ECP_ATADDRSHFT;
2841 outb(memconf, (brdp->iobase + ECP_ATMEMAR));
2842}
2843
2844/*****************************************************************************/
2845
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002846static void stli_ecpenable(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848 outb(ECP_ATENABLE, (brdp->iobase + ECP_ATCONFR));
2849}
2850
2851/*****************************************************************************/
2852
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002853static void stli_ecpdisable(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
2856}
2857
2858/*****************************************************************************/
2859
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002860static void __iomem *stli_ecpgetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861{
Al Viro29756fa2006-10-10 22:47:27 +01002862 void __iomem *ptr;
Alan Cox4ac43602006-06-28 04:26:52 -07002863 unsigned char val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864
2865 if (offset > brdp->memsize) {
2866 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
2867 "range at line=%d(%d), brd=%d\n",
2868 (int) offset, line, __LINE__, brdp->brdnr);
2869 ptr = NULL;
2870 val = 0;
2871 } else {
2872 ptr = brdp->membase + (offset % ECP_ATPAGESIZE);
2873 val = (unsigned char) (offset / ECP_ATPAGESIZE);
2874 }
2875 outb(val, (brdp->iobase + ECP_ATMEMPR));
2876 return(ptr);
2877}
2878
2879/*****************************************************************************/
2880
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002881static void stli_ecpreset(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883 outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
2884 udelay(10);
2885 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
2886 udelay(500);
2887}
2888
2889/*****************************************************************************/
2890
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002891static void stli_ecpintr(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893 outb(0x1, brdp->iobase);
2894}
2895
2896/*****************************************************************************/
2897
2898/*
2899 * The following set of functions act on ECP EISA boards.
2900 */
2901
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002902static void stli_ecpeiinit(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903{
2904 unsigned long memconf;
2905
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906 outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
2907 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
2908 udelay(10);
2909 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
2910 udelay(500);
2911
2912 memconf = (brdp->memaddr & ECP_EIADDRMASKL) >> ECP_EIADDRSHFTL;
2913 outb(memconf, (brdp->iobase + ECP_EIMEMARL));
2914 memconf = (brdp->memaddr & ECP_EIADDRMASKH) >> ECP_EIADDRSHFTH;
2915 outb(memconf, (brdp->iobase + ECP_EIMEMARH));
2916}
2917
2918/*****************************************************************************/
2919
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002920static void stli_ecpeienable(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921{
2922 outb(ECP_EIENABLE, (brdp->iobase + ECP_EICONFR));
2923}
2924
2925/*****************************************************************************/
2926
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002927static void stli_ecpeidisable(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928{
2929 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
2930}
2931
2932/*****************************************************************************/
2933
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002934static void __iomem *stli_ecpeigetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935{
Al Viro29756fa2006-10-10 22:47:27 +01002936 void __iomem *ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937 unsigned char val;
2938
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939 if (offset > brdp->memsize) {
2940 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
2941 "range at line=%d(%d), brd=%d\n",
2942 (int) offset, line, __LINE__, brdp->brdnr);
2943 ptr = NULL;
2944 val = 0;
2945 } else {
2946 ptr = brdp->membase + (offset % ECP_EIPAGESIZE);
2947 if (offset < ECP_EIPAGESIZE)
2948 val = ECP_EIENABLE;
2949 else
2950 val = ECP_EIENABLE | 0x40;
2951 }
2952 outb(val, (brdp->iobase + ECP_EICONFR));
2953 return(ptr);
2954}
2955
2956/*****************************************************************************/
2957
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002958static void stli_ecpeireset(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959{
2960 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
2961 udelay(10);
2962 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
2963 udelay(500);
2964}
2965
2966/*****************************************************************************/
2967
2968/*
2969 * The following set of functions act on ECP MCA boards.
2970 */
2971
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002972static void stli_ecpmcenable(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973{
2974 outb(ECP_MCENABLE, (brdp->iobase + ECP_MCCONFR));
2975}
2976
2977/*****************************************************************************/
2978
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002979static void stli_ecpmcdisable(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980{
2981 outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
2982}
2983
2984/*****************************************************************************/
2985
Jiri Slaby1f8ec432006-12-08 02:39:18 -08002986static void __iomem *stli_ecpmcgetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987{
Al Viro29756fa2006-10-10 22:47:27 +01002988 void __iomem *ptr;
Alan Cox4ac43602006-06-28 04:26:52 -07002989 unsigned char val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990
2991 if (offset > brdp->memsize) {
2992 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
2993 "range at line=%d(%d), brd=%d\n",
2994 (int) offset, line, __LINE__, brdp->brdnr);
2995 ptr = NULL;
2996 val = 0;
2997 } else {
2998 ptr = brdp->membase + (offset % ECP_MCPAGESIZE);
2999 val = ((unsigned char) (offset / ECP_MCPAGESIZE)) | ECP_MCENABLE;
3000 }
3001 outb(val, (brdp->iobase + ECP_MCCONFR));
3002 return(ptr);
3003}
3004
3005/*****************************************************************************/
3006
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003007static void stli_ecpmcreset(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008{
3009 outb(ECP_MCSTOP, (brdp->iobase + ECP_MCCONFR));
3010 udelay(10);
3011 outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
3012 udelay(500);
3013}
3014
3015/*****************************************************************************/
3016
3017/*
3018 * The following set of functions act on ECP PCI boards.
3019 */
3020
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003021static void stli_ecppciinit(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023 outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
3024 udelay(10);
3025 outb(0, (brdp->iobase + ECP_PCICONFR));
3026 udelay(500);
3027}
3028
3029/*****************************************************************************/
3030
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003031static void __iomem *stli_ecppcigetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032{
Al Viro29756fa2006-10-10 22:47:27 +01003033 void __iomem *ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034 unsigned char val;
3035
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036 if (offset > brdp->memsize) {
3037 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3038 "range at line=%d(%d), board=%d\n",
3039 (int) offset, line, __LINE__, brdp->brdnr);
3040 ptr = NULL;
3041 val = 0;
3042 } else {
3043 ptr = brdp->membase + (offset % ECP_PCIPAGESIZE);
3044 val = (offset / ECP_PCIPAGESIZE) << 1;
3045 }
3046 outb(val, (brdp->iobase + ECP_PCICONFR));
3047 return(ptr);
3048}
3049
3050/*****************************************************************************/
3051
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003052static void stli_ecppcireset(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053{
3054 outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
3055 udelay(10);
3056 outb(0, (brdp->iobase + ECP_PCICONFR));
3057 udelay(500);
3058}
3059
3060/*****************************************************************************/
3061
3062/*
3063 * The following routines act on ONboards.
3064 */
3065
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003066static void stli_onbinit(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067{
3068 unsigned long memconf;
3069
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070 outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
3071 udelay(10);
3072 outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
3073 mdelay(1000);
3074
3075 memconf = (brdp->memaddr & ONB_ATADDRMASK) >> ONB_ATADDRSHFT;
3076 outb(memconf, (brdp->iobase + ONB_ATMEMAR));
3077 outb(0x1, brdp->iobase);
3078 mdelay(1);
3079}
3080
3081/*****************************************************************************/
3082
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003083static void stli_onbenable(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003085 outb((brdp->enabval | ONB_ATENABLE), (brdp->iobase + ONB_ATCONFR));
3086}
3087
3088/*****************************************************************************/
3089
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003090static void stli_onbdisable(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003091{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092 outb((brdp->enabval | ONB_ATDISABLE), (brdp->iobase + ONB_ATCONFR));
3093}
3094
3095/*****************************************************************************/
3096
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003097static void __iomem *stli_onbgetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003098{
Al Viro29756fa2006-10-10 22:47:27 +01003099 void __iomem *ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101 if (offset > brdp->memsize) {
3102 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3103 "range at line=%d(%d), brd=%d\n",
3104 (int) offset, line, __LINE__, brdp->brdnr);
3105 ptr = NULL;
3106 } else {
3107 ptr = brdp->membase + (offset % ONB_ATPAGESIZE);
3108 }
3109 return(ptr);
3110}
3111
3112/*****************************************************************************/
3113
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003114static void stli_onbreset(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003115{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116 outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
3117 udelay(10);
3118 outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
3119 mdelay(1000);
3120}
3121
3122/*****************************************************************************/
3123
3124/*
3125 * The following routines act on ONboard EISA.
3126 */
3127
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003128static void stli_onbeinit(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129{
3130 unsigned long memconf;
3131
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132 outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
3133 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3134 udelay(10);
3135 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3136 mdelay(1000);
3137
3138 memconf = (brdp->memaddr & ONB_EIADDRMASKL) >> ONB_EIADDRSHFTL;
3139 outb(memconf, (brdp->iobase + ONB_EIMEMARL));
3140 memconf = (brdp->memaddr & ONB_EIADDRMASKH) >> ONB_EIADDRSHFTH;
3141 outb(memconf, (brdp->iobase + ONB_EIMEMARH));
3142 outb(0x1, brdp->iobase);
3143 mdelay(1);
3144}
3145
3146/*****************************************************************************/
3147
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003148static void stli_onbeenable(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150 outb(ONB_EIENABLE, (brdp->iobase + ONB_EICONFR));
3151}
3152
3153/*****************************************************************************/
3154
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003155static void stli_onbedisable(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3158}
3159
3160/*****************************************************************************/
3161
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003162static void __iomem *stli_onbegetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163{
Al Viro29756fa2006-10-10 22:47:27 +01003164 void __iomem *ptr;
Alan Cox4ac43602006-06-28 04:26:52 -07003165 unsigned char val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166
3167 if (offset > brdp->memsize) {
3168 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3169 "range at line=%d(%d), brd=%d\n",
3170 (int) offset, line, __LINE__, brdp->brdnr);
3171 ptr = NULL;
3172 val = 0;
3173 } else {
3174 ptr = brdp->membase + (offset % ONB_EIPAGESIZE);
3175 if (offset < ONB_EIPAGESIZE)
3176 val = ONB_EIENABLE;
3177 else
3178 val = ONB_EIENABLE | 0x40;
3179 }
3180 outb(val, (brdp->iobase + ONB_EICONFR));
3181 return(ptr);
3182}
3183
3184/*****************************************************************************/
3185
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003186static void stli_onbereset(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003188 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3189 udelay(10);
3190 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3191 mdelay(1000);
3192}
3193
3194/*****************************************************************************/
3195
3196/*
3197 * The following routines act on Brumby boards.
3198 */
3199
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003200static void stli_bbyinit(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
3203 udelay(10);
3204 outb(0, (brdp->iobase + BBY_ATCONFR));
3205 mdelay(1000);
3206 outb(0x1, brdp->iobase);
3207 mdelay(1);
3208}
3209
3210/*****************************************************************************/
3211
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003212static void __iomem *stli_bbygetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213{
Al Viro29756fa2006-10-10 22:47:27 +01003214 void __iomem *ptr;
Alan Cox4ac43602006-06-28 04:26:52 -07003215 unsigned char val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003216
Alan Cox4ac43602006-06-28 04:26:52 -07003217 BUG_ON(offset > brdp->memsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218
Alan Cox4ac43602006-06-28 04:26:52 -07003219 ptr = brdp->membase + (offset % BBY_PAGESIZE);
3220 val = (unsigned char) (offset / BBY_PAGESIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003221 outb(val, (brdp->iobase + BBY_ATCONFR));
3222 return(ptr);
3223}
3224
3225/*****************************************************************************/
3226
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003227static void stli_bbyreset(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003228{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
3230 udelay(10);
3231 outb(0, (brdp->iobase + BBY_ATCONFR));
3232 mdelay(1000);
3233}
3234
3235/*****************************************************************************/
3236
3237/*
3238 * The following routines act on original old Stallion boards.
3239 */
3240
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003241static void stli_stalinit(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243 outb(0x1, brdp->iobase);
3244 mdelay(1000);
3245}
3246
3247/*****************************************************************************/
3248
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003249static void __iomem *stli_stalgetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250{
Alan Cox4ac43602006-06-28 04:26:52 -07003251 BUG_ON(offset > brdp->memsize);
3252 return brdp->membase + (offset % STAL_PAGESIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253}
3254
3255/*****************************************************************************/
3256
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003257static void stli_stalreset(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258{
Alan Cox4ac43602006-06-28 04:26:52 -07003259 u32 __iomem *vecp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260
Alan Cox4ac43602006-06-28 04:26:52 -07003261 vecp = (u32 __iomem *) (brdp->membase + 0x30);
3262 writel(0xffff0000, vecp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263 outb(0, brdp->iobase);
3264 mdelay(1000);
3265}
3266
3267/*****************************************************************************/
3268
3269/*
3270 * Try to find an ECP board and initialize it. This handles only ECP
3271 * board types.
3272 */
3273
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003274static int stli_initecp(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003275{
Alan Cox4ac43602006-06-28 04:26:52 -07003276 cdkecpsig_t sig;
3277 cdkecpsig_t __iomem *sigsp;
3278 unsigned int status, nxtid;
3279 char *name;
3280 int panelnr, nrports;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003281
3282 if (!request_region(brdp->iobase, brdp->iosize, "istallion"))
3283 return -EIO;
3284
3285 if ((brdp->iobase == 0) || (brdp->memaddr == 0))
3286 {
3287 release_region(brdp->iobase, brdp->iosize);
Alan Cox4ac43602006-06-28 04:26:52 -07003288 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003289 }
3290
3291 brdp->iosize = ECP_IOSIZE;
3292
3293/*
3294 * Based on the specific board type setup the common vars to access
3295 * and enable shared memory. Set all board specific information now
3296 * as well.
3297 */
3298 switch (brdp->brdtype) {
3299 case BRD_ECP:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300 brdp->memsize = ECP_MEMSIZE;
3301 brdp->pagesize = ECP_ATPAGESIZE;
3302 brdp->init = stli_ecpinit;
3303 brdp->enable = stli_ecpenable;
3304 brdp->reenable = stli_ecpenable;
3305 brdp->disable = stli_ecpdisable;
3306 brdp->getmemptr = stli_ecpgetmemptr;
3307 brdp->intr = stli_ecpintr;
3308 brdp->reset = stli_ecpreset;
3309 name = "serial(EC8/64)";
3310 break;
3311
3312 case BRD_ECPE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003313 brdp->memsize = ECP_MEMSIZE;
3314 brdp->pagesize = ECP_EIPAGESIZE;
3315 brdp->init = stli_ecpeiinit;
3316 brdp->enable = stli_ecpeienable;
3317 brdp->reenable = stli_ecpeienable;
3318 brdp->disable = stli_ecpeidisable;
3319 brdp->getmemptr = stli_ecpeigetmemptr;
3320 brdp->intr = stli_ecpintr;
3321 brdp->reset = stli_ecpeireset;
3322 name = "serial(EC8/64-EI)";
3323 break;
3324
3325 case BRD_ECPMC:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326 brdp->memsize = ECP_MEMSIZE;
3327 brdp->pagesize = ECP_MCPAGESIZE;
3328 brdp->init = NULL;
3329 brdp->enable = stli_ecpmcenable;
3330 brdp->reenable = stli_ecpmcenable;
3331 brdp->disable = stli_ecpmcdisable;
3332 brdp->getmemptr = stli_ecpmcgetmemptr;
3333 brdp->intr = stli_ecpintr;
3334 brdp->reset = stli_ecpmcreset;
3335 name = "serial(EC8/64-MCA)";
3336 break;
3337
3338 case BRD_ECPPCI:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339 brdp->memsize = ECP_PCIMEMSIZE;
3340 brdp->pagesize = ECP_PCIPAGESIZE;
3341 brdp->init = stli_ecppciinit;
3342 brdp->enable = NULL;
3343 brdp->reenable = NULL;
3344 brdp->disable = NULL;
3345 brdp->getmemptr = stli_ecppcigetmemptr;
3346 brdp->intr = stli_ecpintr;
3347 brdp->reset = stli_ecppcireset;
3348 name = "serial(EC/RA-PCI)";
3349 break;
3350
3351 default:
3352 release_region(brdp->iobase, brdp->iosize);
Alan Cox4ac43602006-06-28 04:26:52 -07003353 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003354 }
3355
3356/*
3357 * The per-board operations structure is all set up, so now let's go
3358 * and get the board operational. Firstly initialize board configuration
3359 * registers. Set the memory mapping info so we can get at the boards
3360 * shared memory.
3361 */
3362 EBRDINIT(brdp);
3363
3364 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
Alan Cox4ac43602006-06-28 04:26:52 -07003365 if (brdp->membase == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003366 {
3367 release_region(brdp->iobase, brdp->iosize);
Alan Cox4ac43602006-06-28 04:26:52 -07003368 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003369 }
3370
3371/*
3372 * Now that all specific code is set up, enable the shared memory and
3373 * look for the a signature area that will tell us exactly what board
3374 * this is, and what it is connected to it.
3375 */
3376 EBRDENABLE(brdp);
Alan Cox4ac43602006-06-28 04:26:52 -07003377 sigsp = (cdkecpsig_t __iomem *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
Al Viro634965f2006-09-23 01:20:31 +01003378 memcpy_fromio(&sig, sigsp, sizeof(cdkecpsig_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003379 EBRDDISABLE(brdp);
3380
Alan Cox4ac43602006-06-28 04:26:52 -07003381 if (sig.magic != cpu_to_le32(ECP_MAGIC))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003382 {
3383 release_region(brdp->iobase, brdp->iosize);
Amol Ladaa8a8d62006-12-06 20:35:22 -08003384 iounmap(brdp->membase);
3385 brdp->membase = NULL;
Alan Cox4ac43602006-06-28 04:26:52 -07003386 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387 }
3388
3389/*
3390 * Scan through the signature looking at the panels connected to the
3391 * board. Calculate the total number of ports as we go.
3392 */
3393 for (panelnr = 0, nxtid = 0; (panelnr < STL_MAXPANELS); panelnr++) {
3394 status = sig.panelid[nxtid];
3395 if ((status & ECH_PNLIDMASK) != nxtid)
3396 break;
3397
3398 brdp->panelids[panelnr] = status;
3399 nrports = (status & ECH_PNL16PORT) ? 16 : 8;
3400 if ((nrports == 16) && ((status & ECH_PNLXPID) == 0))
3401 nxtid++;
3402 brdp->panels[panelnr] = nrports;
3403 brdp->nrports += nrports;
3404 nxtid++;
3405 brdp->nrpanels++;
3406 }
3407
3408
3409 brdp->state |= BST_FOUND;
Alan Cox4ac43602006-06-28 04:26:52 -07003410 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003411}
3412
3413/*****************************************************************************/
3414
3415/*
3416 * Try to find an ONboard, Brumby or Stallion board and initialize it.
3417 * This handles only these board types.
3418 */
3419
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003420static int stli_initonb(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003421{
Alan Cox4ac43602006-06-28 04:26:52 -07003422 cdkonbsig_t sig;
3423 cdkonbsig_t __iomem *sigsp;
3424 char *name;
3425 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003426
3427/*
3428 * Do a basic sanity check on the IO and memory addresses.
3429 */
Alan Cox4ac43602006-06-28 04:26:52 -07003430 if (brdp->iobase == 0 || brdp->memaddr == 0)
3431 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432
3433 brdp->iosize = ONB_IOSIZE;
3434
3435 if (!request_region(brdp->iobase, brdp->iosize, "istallion"))
3436 return -EIO;
3437
3438/*
3439 * Based on the specific board type setup the common vars to access
3440 * and enable shared memory. Set all board specific information now
3441 * as well.
3442 */
3443 switch (brdp->brdtype) {
3444 case BRD_ONBOARD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003445 case BRD_ONBOARD2:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446 brdp->memsize = ONB_MEMSIZE;
3447 brdp->pagesize = ONB_ATPAGESIZE;
3448 brdp->init = stli_onbinit;
3449 brdp->enable = stli_onbenable;
3450 brdp->reenable = stli_onbenable;
3451 brdp->disable = stli_onbdisable;
3452 brdp->getmemptr = stli_onbgetmemptr;
3453 brdp->intr = stli_ecpintr;
3454 brdp->reset = stli_onbreset;
3455 if (brdp->memaddr > 0x100000)
3456 brdp->enabval = ONB_MEMENABHI;
3457 else
3458 brdp->enabval = ONB_MEMENABLO;
3459 name = "serial(ONBoard)";
3460 break;
3461
3462 case BRD_ONBOARDE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003463 brdp->memsize = ONB_EIMEMSIZE;
3464 brdp->pagesize = ONB_EIPAGESIZE;
3465 brdp->init = stli_onbeinit;
3466 brdp->enable = stli_onbeenable;
3467 brdp->reenable = stli_onbeenable;
3468 brdp->disable = stli_onbedisable;
3469 brdp->getmemptr = stli_onbegetmemptr;
3470 brdp->intr = stli_ecpintr;
3471 brdp->reset = stli_onbereset;
3472 name = "serial(ONBoard/E)";
3473 break;
3474
3475 case BRD_BRUMBY4:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003476 brdp->memsize = BBY_MEMSIZE;
3477 brdp->pagesize = BBY_PAGESIZE;
3478 brdp->init = stli_bbyinit;
3479 brdp->enable = NULL;
3480 brdp->reenable = NULL;
3481 brdp->disable = NULL;
3482 brdp->getmemptr = stli_bbygetmemptr;
3483 brdp->intr = stli_ecpintr;
3484 brdp->reset = stli_bbyreset;
3485 name = "serial(Brumby)";
3486 break;
3487
3488 case BRD_STALLION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489 brdp->memsize = STAL_MEMSIZE;
3490 brdp->pagesize = STAL_PAGESIZE;
3491 brdp->init = stli_stalinit;
3492 brdp->enable = NULL;
3493 brdp->reenable = NULL;
3494 brdp->disable = NULL;
3495 brdp->getmemptr = stli_stalgetmemptr;
3496 brdp->intr = stli_ecpintr;
3497 brdp->reset = stli_stalreset;
3498 name = "serial(Stallion)";
3499 break;
3500
3501 default:
3502 release_region(brdp->iobase, brdp->iosize);
Alan Cox4ac43602006-06-28 04:26:52 -07003503 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003504 }
3505
3506/*
3507 * The per-board operations structure is all set up, so now let's go
3508 * and get the board operational. Firstly initialize board configuration
3509 * registers. Set the memory mapping info so we can get at the boards
3510 * shared memory.
3511 */
3512 EBRDINIT(brdp);
3513
3514 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
Alan Cox4ac43602006-06-28 04:26:52 -07003515 if (brdp->membase == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003516 {
3517 release_region(brdp->iobase, brdp->iosize);
Alan Cox4ac43602006-06-28 04:26:52 -07003518 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519 }
3520
3521/*
3522 * Now that all specific code is set up, enable the shared memory and
3523 * look for the a signature area that will tell us exactly what board
3524 * this is, and how many ports.
3525 */
3526 EBRDENABLE(brdp);
Alan Cox4ac43602006-06-28 04:26:52 -07003527 sigsp = (cdkonbsig_t __iomem *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
3528 memcpy_fromio(&sig, sigsp, sizeof(cdkonbsig_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003529 EBRDDISABLE(brdp);
3530
Alan Cox4ac43602006-06-28 04:26:52 -07003531 if (sig.magic0 != cpu_to_le16(ONB_MAGIC0) ||
3532 sig.magic1 != cpu_to_le16(ONB_MAGIC1) ||
3533 sig.magic2 != cpu_to_le16(ONB_MAGIC2) ||
3534 sig.magic3 != cpu_to_le16(ONB_MAGIC3))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003535 {
3536 release_region(brdp->iobase, brdp->iosize);
Amol Ladaa8a8d62006-12-06 20:35:22 -08003537 iounmap(brdp->membase);
3538 brdp->membase = NULL;
Alan Cox4ac43602006-06-28 04:26:52 -07003539 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540 }
3541
3542/*
3543 * Scan through the signature alive mask and calculate how many ports
3544 * there are on this board.
3545 */
3546 brdp->nrpanels = 1;
3547 if (sig.amask1) {
3548 brdp->nrports = 32;
3549 } else {
3550 for (i = 0; (i < 16); i++) {
3551 if (((sig.amask0 << i) & 0x8000) == 0)
3552 break;
3553 }
3554 brdp->nrports = i;
3555 }
3556 brdp->panels[0] = brdp->nrports;
3557
3558
3559 brdp->state |= BST_FOUND;
Alan Cox4ac43602006-06-28 04:26:52 -07003560 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003561}
3562
3563/*****************************************************************************/
3564
3565/*
3566 * Start up a running board. This routine is only called after the
3567 * code has been down loaded to the board and is operational. It will
3568 * read in the memory map, and get the show on the road...
3569 */
3570
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003571static int stli_startbrd(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003572{
Alan Cox4ac43602006-06-28 04:26:52 -07003573 cdkhdr_t __iomem *hdrp;
3574 cdkmem_t __iomem *memp;
3575 cdkasy_t __iomem *ap;
3576 unsigned long flags;
Jiri Slaby1328d732006-12-08 02:39:19 -08003577 unsigned int portnr, nrdevs, i;
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003578 struct stliport *portp;
Jiri Slaby1328d732006-12-08 02:39:19 -08003579 int rc = 0;
Alan Cox4ac43602006-06-28 04:26:52 -07003580 u32 memoff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003581
Alan Cox4ac43602006-06-28 04:26:52 -07003582 spin_lock_irqsave(&brd_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003583 EBRDENABLE(brdp);
Alan Cox4ac43602006-06-28 04:26:52 -07003584 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003585 nrdevs = hdrp->nrdevs;
3586
3587#if 0
3588 printk("%s(%d): CDK version %d.%d.%d --> "
3589 "nrdevs=%d memp=%x hostp=%x slavep=%x\n",
Alan Cox4ac43602006-06-28 04:26:52 -07003590 __FILE__, __LINE__, readb(&hdrp->ver_release), readb(&hdrp->ver_modification),
3591 readb(&hdrp->ver_fix), nrdevs, (int) readl(&hdrp->memp), readl(&hdrp->hostp),
3592 readl(&hdrp->slavep));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003593#endif
3594
3595 if (nrdevs < (brdp->nrports + 1)) {
3596 printk(KERN_ERR "STALLION: slave failed to allocate memory for "
3597 "all devices, devices=%d\n", nrdevs);
3598 brdp->nrports = nrdevs - 1;
3599 }
3600 brdp->nrdevs = nrdevs;
3601 brdp->hostoffset = hdrp->hostp - CDK_CDKADDR;
3602 brdp->slaveoffset = hdrp->slavep - CDK_CDKADDR;
3603 brdp->bitsize = (nrdevs + 7) / 8;
Alan Cox4ac43602006-06-28 04:26:52 -07003604 memoff = readl(&hdrp->memp);
3605 if (memoff > brdp->memsize) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003606 printk(KERN_ERR "STALLION: corrupted shared memory region?\n");
3607 rc = -EIO;
3608 goto stli_donestartup;
3609 }
Alan Cox4ac43602006-06-28 04:26:52 -07003610 memp = (cdkmem_t __iomem *) EBRDGETMEMPTR(brdp, memoff);
3611 if (readw(&memp->dtype) != TYP_ASYNCTRL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003612 printk(KERN_ERR "STALLION: no slave control device found\n");
3613 goto stli_donestartup;
3614 }
3615 memp++;
3616
3617/*
3618 * Cycle through memory allocation of each port. We are guaranteed to
3619 * have all ports inside the first page of slave window, so no need to
3620 * change pages while reading memory map.
3621 */
3622 for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++, memp++) {
Alan Cox4ac43602006-06-28 04:26:52 -07003623 if (readw(&memp->dtype) != TYP_ASYNC)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003624 break;
3625 portp = brdp->ports[portnr];
Alan Cox4ac43602006-06-28 04:26:52 -07003626 if (portp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003627 break;
3628 portp->devnr = i;
Alan Cox4ac43602006-06-28 04:26:52 -07003629 portp->addr = readl(&memp->offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003630 portp->reqbit = (unsigned char) (0x1 << (i * 8 / nrdevs));
3631 portp->portidx = (unsigned char) (i / 8);
3632 portp->portbit = (unsigned char) (0x1 << (i % 8));
3633 }
3634
Alan Cox4ac43602006-06-28 04:26:52 -07003635 writeb(0xff, &hdrp->slavereq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003636
3637/*
3638 * For each port setup a local copy of the RX and TX buffer offsets
3639 * and sizes. We do this separate from the above, because we need to
3640 * move the shared memory page...
3641 */
3642 for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++) {
3643 portp = brdp->ports[portnr];
Alan Cox4ac43602006-06-28 04:26:52 -07003644 if (portp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003645 break;
3646 if (portp->addr == 0)
3647 break;
Alan Cox4ac43602006-06-28 04:26:52 -07003648 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
3649 if (ap != NULL) {
3650 portp->rxsize = readw(&ap->rxq.size);
3651 portp->txsize = readw(&ap->txq.size);
3652 portp->rxoffset = readl(&ap->rxq.offset);
3653 portp->txoffset = readl(&ap->txq.offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003654 }
3655 }
3656
3657stli_donestartup:
3658 EBRDDISABLE(brdp);
Alan Cox4ac43602006-06-28 04:26:52 -07003659 spin_unlock_irqrestore(&brd_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003660
3661 if (rc == 0)
3662 brdp->state |= BST_STARTED;
3663
3664 if (! stli_timeron) {
3665 stli_timeron++;
3666 stli_timerlist.expires = STLI_TIMEOUT;
3667 add_timer(&stli_timerlist);
3668 }
3669
Alan Cox4ac43602006-06-28 04:26:52 -07003670 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003671}
3672
3673/*****************************************************************************/
3674
3675/*
3676 * Probe and initialize the specified board.
3677 */
3678
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003679static int __devinit stli_brdinit(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003680{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003681 switch (brdp->brdtype) {
3682 case BRD_ECP:
3683 case BRD_ECPE:
3684 case BRD_ECPMC:
3685 case BRD_ECPPCI:
3686 stli_initecp(brdp);
3687 break;
3688 case BRD_ONBOARD:
3689 case BRD_ONBOARDE:
3690 case BRD_ONBOARD2:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003691 case BRD_BRUMBY4:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003692 case BRD_STALLION:
3693 stli_initonb(brdp);
3694 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695 default:
3696 printk(KERN_ERR "STALLION: board=%d is unknown board "
3697 "type=%d\n", brdp->brdnr, brdp->brdtype);
Alan Cox4ac43602006-06-28 04:26:52 -07003698 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003699 }
3700
3701 if ((brdp->state & BST_FOUND) == 0) {
3702 printk(KERN_ERR "STALLION: %s board not found, board=%d "
3703 "io=%x mem=%x\n",
3704 stli_brdnames[brdp->brdtype], brdp->brdnr,
3705 brdp->iobase, (int) brdp->memaddr);
Alan Cox4ac43602006-06-28 04:26:52 -07003706 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003707 }
3708
3709 stli_initports(brdp);
3710 printk(KERN_INFO "STALLION: %s found, board=%d io=%x mem=%x "
3711 "nrpanels=%d nrports=%d\n", stli_brdnames[brdp->brdtype],
3712 brdp->brdnr, brdp->iobase, (int) brdp->memaddr,
3713 brdp->nrpanels, brdp->nrports);
Alan Cox4ac43602006-06-28 04:26:52 -07003714 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003715}
3716
Jiri Slabya00f33f2006-12-08 02:39:20 -08003717#if STLI_EISAPROBE != 0
Linus Torvalds1da177e2005-04-16 15:20:36 -07003718/*****************************************************************************/
3719
3720/*
3721 * Probe around trying to find where the EISA boards shared memory
3722 * might be. This is a bit if hack, but it is the best we can do.
3723 */
3724
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003725static int stli_eisamemprobe(struct stlibrd *brdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003726{
Alan Cox4ac43602006-06-28 04:26:52 -07003727 cdkecpsig_t ecpsig, __iomem *ecpsigp;
3728 cdkonbsig_t onbsig, __iomem *onbsigp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003729 int i, foundit;
3730
Linus Torvalds1da177e2005-04-16 15:20:36 -07003731/*
3732 * First up we reset the board, to get it into a known state. There
3733 * is only 2 board types here we need to worry about. Don;t use the
3734 * standard board init routine here, it programs up the shared
3735 * memory address, and we don't know it yet...
3736 */
3737 if (brdp->brdtype == BRD_ECPE) {
3738 outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
3739 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
3740 udelay(10);
3741 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
3742 udelay(500);
3743 stli_ecpeienable(brdp);
3744 } else if (brdp->brdtype == BRD_ONBOARDE) {
3745 outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
3746 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3747 udelay(10);
3748 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3749 mdelay(100);
3750 outb(0x1, brdp->iobase);
3751 mdelay(1);
3752 stli_onbeenable(brdp);
3753 } else {
Alan Cox4ac43602006-06-28 04:26:52 -07003754 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003755 }
3756
3757 foundit = 0;
3758 brdp->memsize = ECP_MEMSIZE;
3759
3760/*
3761 * Board shared memory is enabled, so now we have a poke around and
3762 * see if we can find it.
3763 */
3764 for (i = 0; (i < stli_eisamempsize); i++) {
3765 brdp->memaddr = stli_eisamemprobeaddrs[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003766 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
Alan Cox4ac43602006-06-28 04:26:52 -07003767 if (brdp->membase == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003768 continue;
3769
3770 if (brdp->brdtype == BRD_ECPE) {
Al Viro29756fa2006-10-10 22:47:27 +01003771 ecpsigp = stli_ecpeigetmemptr(brdp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003772 CDK_SIGADDR, __LINE__);
Alan Cox4ac43602006-06-28 04:26:52 -07003773 memcpy_fromio(&ecpsig, ecpsigp, sizeof(cdkecpsig_t));
3774 if (ecpsig.magic == cpu_to_le32(ECP_MAGIC))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003775 foundit = 1;
3776 } else {
Alan Cox4ac43602006-06-28 04:26:52 -07003777 onbsigp = (cdkonbsig_t __iomem *) stli_onbegetmemptr(brdp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003778 CDK_SIGADDR, __LINE__);
Alan Cox4ac43602006-06-28 04:26:52 -07003779 memcpy_fromio(&onbsig, onbsigp, sizeof(cdkonbsig_t));
3780 if ((onbsig.magic0 == cpu_to_le16(ONB_MAGIC0)) &&
3781 (onbsig.magic1 == cpu_to_le16(ONB_MAGIC1)) &&
3782 (onbsig.magic2 == cpu_to_le16(ONB_MAGIC2)) &&
3783 (onbsig.magic3 == cpu_to_le16(ONB_MAGIC3)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003784 foundit = 1;
3785 }
3786
3787 iounmap(brdp->membase);
3788 if (foundit)
3789 break;
3790 }
3791
3792/*
3793 * Regardless of whether we found the shared memory or not we must
3794 * disable the region. After that return success or failure.
3795 */
3796 if (brdp->brdtype == BRD_ECPE)
3797 stli_ecpeidisable(brdp);
3798 else
3799 stli_onbedisable(brdp);
3800
3801 if (! foundit) {
3802 brdp->memaddr = 0;
3803 brdp->membase = NULL;
3804 printk(KERN_ERR "STALLION: failed to probe shared memory "
3805 "region for %s in EISA slot=%d\n",
3806 stli_brdnames[brdp->brdtype], (brdp->iobase >> 12));
Alan Cox4ac43602006-06-28 04:26:52 -07003807 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003808 }
Alan Cox4ac43602006-06-28 04:26:52 -07003809 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810}
Jiri Slabya00f33f2006-12-08 02:39:20 -08003811#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003812
3813static int stli_getbrdnr(void)
3814{
Jiri Slaby1328d732006-12-08 02:39:19 -08003815 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816
3817 for (i = 0; i < STL_MAXBRDS; i++) {
3818 if (!stli_brds[i]) {
3819 if (i >= stli_nrbrds)
3820 stli_nrbrds = i + 1;
3821 return i;
3822 }
3823 }
3824 return -1;
3825}
3826
Jiri Slabya00f33f2006-12-08 02:39:20 -08003827#if STLI_EISAPROBE != 0
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828/*****************************************************************************/
3829
3830/*
3831 * Probe around and try to find any EISA boards in system. The biggest
3832 * problem here is finding out what memory address is associated with
3833 * an EISA board after it is found. The registers of the ECPE and
3834 * ONboardE are not readable - so we can't read them from there. We
3835 * don't have access to the EISA CMOS (or EISA BIOS) so we don't
3836 * actually have any way to find out the real value. The best we can
3837 * do is go probing around in the usual places hoping we can find it.
3838 */
3839
3840static int stli_findeisabrds(void)
3841{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003842 struct stlibrd *brdp;
Jiri Slaby1328d732006-12-08 02:39:19 -08003843 unsigned int iobase, eid, i;
3844 int brdnr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845
3846/*
Alan Cox4ac43602006-06-28 04:26:52 -07003847 * Firstly check if this is an EISA system. If this is not an EISA system then
Linus Torvalds1da177e2005-04-16 15:20:36 -07003848 * don't bother going any further!
3849 */
Alan Cox4ac43602006-06-28 04:26:52 -07003850 if (EISA_bus)
3851 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003852
3853/*
3854 * Looks like an EISA system, so go searching for EISA boards.
3855 */
3856 for (iobase = 0x1000; (iobase <= 0xc000); iobase += 0x1000) {
3857 outb(0xff, (iobase + 0xc80));
3858 eid = inb(iobase + 0xc80);
3859 eid |= inb(iobase + 0xc81) << 8;
3860 if (eid != STL_EISAID)
3861 continue;
3862
3863/*
3864 * We have found a board. Need to check if this board was
3865 * statically configured already (just in case!).
3866 */
3867 for (i = 0; (i < STL_MAXBRDS); i++) {
3868 brdp = stli_brds[i];
Alan Cox4ac43602006-06-28 04:26:52 -07003869 if (brdp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003870 continue;
3871 if (brdp->iobase == iobase)
3872 break;
3873 }
3874 if (i < STL_MAXBRDS)
3875 continue;
3876
3877/*
3878 * We have found a Stallion board and it is not configured already.
3879 * Allocate a board structure and initialize it.
3880 */
Alan Cox4ac43602006-06-28 04:26:52 -07003881 if ((brdp = stli_allocbrd()) == NULL)
3882 return -ENOMEM;
Jiri Slaby1328d732006-12-08 02:39:19 -08003883 brdnr = stli_getbrdnr();
3884 if (brdnr < 0)
Alan Cox4ac43602006-06-28 04:26:52 -07003885 return -ENOMEM;
Jiri Slaby1328d732006-12-08 02:39:19 -08003886 brdp->brdnr = (unsigned int)brdnr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003887 eid = inb(iobase + 0xc82);
3888 if (eid == ECP_EISAID)
3889 brdp->brdtype = BRD_ECPE;
3890 else if (eid == ONB_EISAID)
3891 brdp->brdtype = BRD_ONBOARDE;
3892 else
3893 brdp->brdtype = BRD_UNKNOWN;
3894 brdp->iobase = iobase;
3895 outb(0x1, (iobase + 0xc84));
3896 if (stli_eisamemprobe(brdp))
3897 outb(0, (iobase + 0xc84));
Jiri Slabyb103b5c2006-12-08 02:39:21 -08003898 stli_brds[brdp->brdnr] = brdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003899 stli_brdinit(brdp);
3900 }
3901
Alan Cox4ac43602006-06-28 04:26:52 -07003902 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003903}
Jiri Slabya00f33f2006-12-08 02:39:20 -08003904#else
3905static inline int stli_findeisabrds(void) { return 0; }
3906#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003907
3908/*****************************************************************************/
3909
3910/*
3911 * Find the next available board number that is free.
3912 */
3913
3914/*****************************************************************************/
3915
Linus Torvalds1da177e2005-04-16 15:20:36 -07003916/*
3917 * We have a Stallion board. Allocate a board structure and
3918 * initialize it. Read its IO and MEMORY resources from PCI
3919 * configuration space.
3920 */
3921
Jiri Slaby845bead2006-12-08 02:39:17 -08003922static int __devinit stli_pciprobe(struct pci_dev *pdev,
3923 const struct pci_device_id *ent)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003924{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003925 struct stlibrd *brdp;
Jiri Slaby1328d732006-12-08 02:39:19 -08003926 int brdnr, retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003927
Jiri Slaby845bead2006-12-08 02:39:17 -08003928 retval = pci_enable_device(pdev);
3929 if (retval)
3930 goto err;
3931 brdp = stli_allocbrd();
3932 if (brdp == NULL) {
3933 retval = -ENOMEM;
3934 goto err;
3935 }
Jiri Slabyb103b5c2006-12-08 02:39:21 -08003936 mutex_lock(&stli_brdslock);
Jiri Slaby1328d732006-12-08 02:39:19 -08003937 brdnr = stli_getbrdnr();
Jiri Slabyb103b5c2006-12-08 02:39:21 -08003938 if (brdnr < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003939 printk(KERN_INFO "STALLION: too many boards found, "
3940 "maximum supported %d\n", STL_MAXBRDS);
Jiri Slabyb103b5c2006-12-08 02:39:21 -08003941 mutex_unlock(&stli_brdslock);
Jiri Slaby845bead2006-12-08 02:39:17 -08003942 retval = -EIO;
3943 goto err_fr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003944 }
Jiri Slaby1328d732006-12-08 02:39:19 -08003945 brdp->brdnr = (unsigned int)brdnr;
Jiri Slabyb103b5c2006-12-08 02:39:21 -08003946 stli_brds[brdp->brdnr] = brdp;
3947 mutex_unlock(&stli_brdslock);
Jiri Slaby845bead2006-12-08 02:39:17 -08003948 brdp->brdtype = BRD_ECPPCI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003949/*
3950 * We have all resources from the board, so lets setup the actual
3951 * board structure now.
3952 */
Jiri Slaby845bead2006-12-08 02:39:17 -08003953 brdp->iobase = pci_resource_start(pdev, 3);
3954 brdp->memaddr = pci_resource_start(pdev, 2);
3955 retval = stli_brdinit(brdp);
3956 if (retval)
Jiri Slabyb103b5c2006-12-08 02:39:21 -08003957 goto err_null;
Jiri Slaby845bead2006-12-08 02:39:17 -08003958
3959 pci_set_drvdata(pdev, brdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003960
Alan Cox4ac43602006-06-28 04:26:52 -07003961 return 0;
Jiri Slabyb103b5c2006-12-08 02:39:21 -08003962err_null:
3963 stli_brds[brdp->brdnr] = NULL;
Jiri Slaby845bead2006-12-08 02:39:17 -08003964err_fr:
3965 kfree(brdp);
3966err:
3967 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003968}
3969
Jiri Slaby845bead2006-12-08 02:39:17 -08003970static void stli_pciremove(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003971{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003972 struct stlibrd *brdp = pci_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003973
Jiri Slaby845bead2006-12-08 02:39:17 -08003974 stli_cleanup_ports(brdp);
3975
3976 iounmap(brdp->membase);
3977 if (brdp->iosize > 0)
3978 release_region(brdp->iobase, brdp->iosize);
3979
3980 stli_brds[brdp->brdnr] = NULL;
3981 kfree(brdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003982}
3983
Jiri Slaby845bead2006-12-08 02:39:17 -08003984static struct pci_driver stli_pcidriver = {
3985 .name = "istallion",
3986 .id_table = istallion_pci_tbl,
3987 .probe = stli_pciprobe,
3988 .remove = __devexit_p(stli_pciremove)
3989};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003990/*****************************************************************************/
3991
3992/*
3993 * Allocate a new board structure. Fill out the basic info in it.
3994 */
3995
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003996static struct stlibrd *stli_allocbrd(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003997{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08003998 struct stlibrd *brdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003999
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004000 brdp = kzalloc(sizeof(struct stlibrd), GFP_KERNEL);
Tobias Klauserb0b4ed72006-03-31 02:30:56 -08004001 if (!brdp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004002 printk(KERN_ERR "STALLION: failed to allocate memory "
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004003 "(size=%Zd)\n", sizeof(struct stlibrd));
Tobias Klauserb0b4ed72006-03-31 02:30:56 -08004004 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004005 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004006 brdp->magic = STLI_BOARDMAGIC;
Alan Cox4ac43602006-06-28 04:26:52 -07004007 return brdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004008}
4009
4010/*****************************************************************************/
4011
4012/*
4013 * Scan through all the boards in the configuration and see what we
4014 * can find.
4015 */
4016
4017static int stli_initbrds(void)
4018{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004019 struct stlibrd *brdp, *nxtbrdp;
4020 struct stlconf conf;
Jiri Slaby1328d732006-12-08 02:39:19 -08004021 unsigned int i, j;
4022 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004023
Jiri Slabya3f8d9d2006-12-08 02:39:18 -08004024 for (stli_nrbrds = 0; stli_nrbrds < ARRAY_SIZE(stli_brdsp);
4025 stli_nrbrds++) {
4026 memset(&conf, 0, sizeof(conf));
4027 if (stli_parsebrd(&conf, stli_brdsp[stli_nrbrds]) == 0)
4028 continue;
Alan Cox4ac43602006-06-28 04:26:52 -07004029 if ((brdp = stli_allocbrd()) == NULL)
Jiri Slabya3f8d9d2006-12-08 02:39:18 -08004030 continue;
4031 brdp->brdnr = stli_nrbrds;
4032 brdp->brdtype = conf.brdtype;
4033 brdp->iobase = conf.ioaddr1;
4034 brdp->memaddr = conf.memaddr;
Jiri Slabyb103b5c2006-12-08 02:39:21 -08004035 stli_brds[brdp->brdnr] = brdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004036 stli_brdinit(brdp);
4037 }
4038
Jiri Slabya00f33f2006-12-08 02:39:20 -08004039 stli_findeisabrds();
Jiri Slaby845bead2006-12-08 02:39:17 -08004040
4041 retval = pci_register_driver(&stli_pcidriver);
4042 /* TODO: check retval and do something */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004043
4044/*
4045 * All found boards are initialized. Now for a little optimization, if
4046 * no boards are sharing the "shared memory" regions then we can just
4047 * leave them all enabled. This is in fact the usual case.
4048 */
4049 stli_shared = 0;
4050 if (stli_nrbrds > 1) {
4051 for (i = 0; (i < stli_nrbrds); i++) {
4052 brdp = stli_brds[i];
Alan Cox4ac43602006-06-28 04:26:52 -07004053 if (brdp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004054 continue;
4055 for (j = i + 1; (j < stli_nrbrds); j++) {
4056 nxtbrdp = stli_brds[j];
Alan Cox4ac43602006-06-28 04:26:52 -07004057 if (nxtbrdp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004058 continue;
4059 if ((brdp->membase >= nxtbrdp->membase) &&
4060 (brdp->membase <= (nxtbrdp->membase +
4061 nxtbrdp->memsize - 1))) {
4062 stli_shared++;
4063 break;
4064 }
4065 }
4066 }
4067 }
4068
4069 if (stli_shared == 0) {
4070 for (i = 0; (i < stli_nrbrds); i++) {
4071 brdp = stli_brds[i];
Alan Cox4ac43602006-06-28 04:26:52 -07004072 if (brdp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004073 continue;
4074 if (brdp->state & BST_FOUND) {
4075 EBRDENABLE(brdp);
4076 brdp->enable = NULL;
4077 brdp->disable = NULL;
4078 }
4079 }
4080 }
4081
Alan Cox4ac43602006-06-28 04:26:52 -07004082 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004083}
4084
4085/*****************************************************************************/
4086
4087/*
4088 * Code to handle an "staliomem" read operation. This device is the
4089 * contents of the board shared memory. It is used for down loading
4090 * the slave image (and debugging :-)
4091 */
4092
4093static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp)
4094{
Alan Cox4ac43602006-06-28 04:26:52 -07004095 unsigned long flags;
Al Viro29756fa2006-10-10 22:47:27 +01004096 void __iomem *memptr;
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004097 struct stlibrd *brdp;
Jiri Slaby1328d732006-12-08 02:39:19 -08004098 unsigned int brdnr;
4099 int size, n;
Alan Cox4ac43602006-06-28 04:26:52 -07004100 void *p;
4101 loff_t off = *offp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004102
Josef Sipeka7113a92006-12-08 02:36:55 -08004103 brdnr = iminor(fp->f_path.dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004104 if (brdnr >= stli_nrbrds)
Alan Cox4ac43602006-06-28 04:26:52 -07004105 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004106 brdp = stli_brds[brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07004107 if (brdp == NULL)
4108 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004109 if (brdp->state == 0)
Alan Cox4ac43602006-06-28 04:26:52 -07004110 return -ENODEV;
4111 if (off >= brdp->memsize || off + count < off)
4112 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004113
Jiri Slabya3f8d9d2006-12-08 02:39:18 -08004114 size = min(count, (size_t)(brdp->memsize - off));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004115
Alan Cox4ac43602006-06-28 04:26:52 -07004116 /*
4117 * Copy the data a page at a time
4118 */
4119
4120 p = (void *)__get_free_page(GFP_KERNEL);
4121 if(p == NULL)
4122 return -ENOMEM;
4123
Linus Torvalds1da177e2005-04-16 15:20:36 -07004124 while (size > 0) {
Alan Cox4ac43602006-06-28 04:26:52 -07004125 spin_lock_irqsave(&brd_lock, flags);
4126 EBRDENABLE(brdp);
Al Viro29756fa2006-10-10 22:47:27 +01004127 memptr = EBRDGETMEMPTR(brdp, off);
Jiri Slabya3f8d9d2006-12-08 02:39:18 -08004128 n = min(size, (int)(brdp->pagesize - (((unsigned long) off) % brdp->pagesize)));
4129 n = min(n, (int)PAGE_SIZE);
Alan Cox4ac43602006-06-28 04:26:52 -07004130 memcpy_fromio(p, memptr, n);
4131 EBRDDISABLE(brdp);
4132 spin_unlock_irqrestore(&brd_lock, flags);
4133 if (copy_to_user(buf, p, n)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004134 count = -EFAULT;
4135 goto out;
4136 }
Alan Cox4ac43602006-06-28 04:26:52 -07004137 off += n;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004138 buf += n;
4139 size -= n;
4140 }
4141out:
Alan Cox4ac43602006-06-28 04:26:52 -07004142 *offp = off;
4143 free_page((unsigned long)p);
4144 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004145}
4146
4147/*****************************************************************************/
4148
4149/*
4150 * Code to handle an "staliomem" write operation. This device is the
4151 * contents of the board shared memory. It is used for down loading
4152 * the slave image (and debugging :-)
Alan Cox4ac43602006-06-28 04:26:52 -07004153 *
4154 * FIXME: copy under lock
Linus Torvalds1da177e2005-04-16 15:20:36 -07004155 */
4156
4157static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp)
4158{
Alan Cox4ac43602006-06-28 04:26:52 -07004159 unsigned long flags;
Al Viro29756fa2006-10-10 22:47:27 +01004160 void __iomem *memptr;
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004161 struct stlibrd *brdp;
Alan Cox4ac43602006-06-28 04:26:52 -07004162 char __user *chbuf;
Jiri Slaby1328d732006-12-08 02:39:19 -08004163 unsigned int brdnr;
4164 int size, n;
Alan Cox4ac43602006-06-28 04:26:52 -07004165 void *p;
4166 loff_t off = *offp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004167
Josef Sipeka7113a92006-12-08 02:36:55 -08004168 brdnr = iminor(fp->f_path.dentry->d_inode);
Alan Cox4ac43602006-06-28 04:26:52 -07004169
Linus Torvalds1da177e2005-04-16 15:20:36 -07004170 if (brdnr >= stli_nrbrds)
Alan Cox4ac43602006-06-28 04:26:52 -07004171 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004172 brdp = stli_brds[brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07004173 if (brdp == NULL)
4174 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004175 if (brdp->state == 0)
Alan Cox4ac43602006-06-28 04:26:52 -07004176 return -ENODEV;
4177 if (off >= brdp->memsize || off + count < off)
4178 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004179
4180 chbuf = (char __user *) buf;
Jiri Slabya3f8d9d2006-12-08 02:39:18 -08004181 size = min(count, (size_t)(brdp->memsize - off));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004182
Alan Cox4ac43602006-06-28 04:26:52 -07004183 /*
4184 * Copy the data a page at a time
4185 */
4186
4187 p = (void *)__get_free_page(GFP_KERNEL);
4188 if(p == NULL)
4189 return -ENOMEM;
4190
Linus Torvalds1da177e2005-04-16 15:20:36 -07004191 while (size > 0) {
Jiri Slabya3f8d9d2006-12-08 02:39:18 -08004192 n = min(size, (int)(brdp->pagesize - (((unsigned long) off) % brdp->pagesize)));
4193 n = min(n, (int)PAGE_SIZE);
Alan Cox4ac43602006-06-28 04:26:52 -07004194 if (copy_from_user(p, chbuf, n)) {
4195 if (count == 0)
4196 count = -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004197 goto out;
4198 }
Alan Cox4ac43602006-06-28 04:26:52 -07004199 spin_lock_irqsave(&brd_lock, flags);
4200 EBRDENABLE(brdp);
Al Viro29756fa2006-10-10 22:47:27 +01004201 memptr = EBRDGETMEMPTR(brdp, off);
Alan Cox4ac43602006-06-28 04:26:52 -07004202 memcpy_toio(memptr, p, n);
4203 EBRDDISABLE(brdp);
4204 spin_unlock_irqrestore(&brd_lock, flags);
4205 off += n;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004206 chbuf += n;
4207 size -= n;
4208 }
4209out:
Alan Cox4ac43602006-06-28 04:26:52 -07004210 free_page((unsigned long) p);
4211 *offp = off;
4212 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004213}
4214
4215/*****************************************************************************/
4216
4217/*
4218 * Return the board stats structure to user app.
4219 */
4220
4221static int stli_getbrdstats(combrd_t __user *bp)
4222{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004223 struct stlibrd *brdp;
Jiri Slaby1328d732006-12-08 02:39:19 -08004224 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004225
4226 if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t)))
4227 return -EFAULT;
4228 if (stli_brdstats.brd >= STL_MAXBRDS)
Alan Cox4ac43602006-06-28 04:26:52 -07004229 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004230 brdp = stli_brds[stli_brdstats.brd];
Alan Cox4ac43602006-06-28 04:26:52 -07004231 if (brdp == NULL)
4232 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004233
4234 memset(&stli_brdstats, 0, sizeof(combrd_t));
4235 stli_brdstats.brd = brdp->brdnr;
4236 stli_brdstats.type = brdp->brdtype;
4237 stli_brdstats.hwid = 0;
4238 stli_brdstats.state = brdp->state;
4239 stli_brdstats.ioaddr = brdp->iobase;
4240 stli_brdstats.memaddr = brdp->memaddr;
4241 stli_brdstats.nrpanels = brdp->nrpanels;
4242 stli_brdstats.nrports = brdp->nrports;
4243 for (i = 0; (i < brdp->nrpanels); i++) {
4244 stli_brdstats.panels[i].panel = i;
4245 stli_brdstats.panels[i].hwid = brdp->panelids[i];
4246 stli_brdstats.panels[i].nrports = brdp->panels[i];
4247 }
4248
4249 if (copy_to_user(bp, &stli_brdstats, sizeof(combrd_t)))
4250 return -EFAULT;
Alan Cox4ac43602006-06-28 04:26:52 -07004251 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004252}
4253
4254/*****************************************************************************/
4255
4256/*
4257 * Resolve the referenced port number into a port struct pointer.
4258 */
4259
Jiri Slaby1328d732006-12-08 02:39:19 -08004260static struct stliport *stli_getport(unsigned int brdnr, unsigned int panelnr,
4261 unsigned int portnr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004262{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004263 struct stlibrd *brdp;
Jiri Slaby1328d732006-12-08 02:39:19 -08004264 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004265
Jiri Slaby1328d732006-12-08 02:39:19 -08004266 if (brdnr >= STL_MAXBRDS)
Alan Cox4ac43602006-06-28 04:26:52 -07004267 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004268 brdp = stli_brds[brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07004269 if (brdp == NULL)
4270 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004271 for (i = 0; (i < panelnr); i++)
4272 portnr += brdp->panels[i];
Jiri Slaby1328d732006-12-08 02:39:19 -08004273 if (portnr >= brdp->nrports)
Alan Cox4ac43602006-06-28 04:26:52 -07004274 return NULL;
4275 return brdp->ports[portnr];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004276}
4277
4278/*****************************************************************************/
4279
4280/*
4281 * Return the port stats structure to user app. A NULL port struct
4282 * pointer passed in means that we need to find out from the app
4283 * what port to get stats for (used through board control device).
4284 */
4285
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004286static int stli_portcmdstats(struct stliport *portp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004287{
4288 unsigned long flags;
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004289 struct stlibrd *brdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004290 int rc;
4291
4292 memset(&stli_comstats, 0, sizeof(comstats_t));
4293
Alan Cox4ac43602006-06-28 04:26:52 -07004294 if (portp == NULL)
4295 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004296 brdp = stli_brds[portp->brdnr];
Alan Cox4ac43602006-06-28 04:26:52 -07004297 if (brdp == NULL)
4298 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004299
4300 if (brdp->state & BST_STARTED) {
4301 if ((rc = stli_cmdwait(brdp, portp, A_GETSTATS,
4302 &stli_cdkstats, sizeof(asystats_t), 1)) < 0)
Alan Cox4ac43602006-06-28 04:26:52 -07004303 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004304 } else {
4305 memset(&stli_cdkstats, 0, sizeof(asystats_t));
4306 }
4307
4308 stli_comstats.brd = portp->brdnr;
4309 stli_comstats.panel = portp->panelnr;
4310 stli_comstats.port = portp->portnr;
4311 stli_comstats.state = portp->state;
4312 stli_comstats.flags = portp->flags;
4313
Alan Cox4ac43602006-06-28 04:26:52 -07004314 spin_lock_irqsave(&brd_lock, flags);
4315 if (portp->tty != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004316 if (portp->tty->driver_data == portp) {
4317 stli_comstats.ttystate = portp->tty->flags;
Alan Cox4ac43602006-06-28 04:26:52 -07004318 stli_comstats.rxbuffered = -1;
4319 if (portp->tty->termios != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004320 stli_comstats.cflags = portp->tty->termios->c_cflag;
4321 stli_comstats.iflags = portp->tty->termios->c_iflag;
4322 stli_comstats.oflags = portp->tty->termios->c_oflag;
4323 stli_comstats.lflags = portp->tty->termios->c_lflag;
4324 }
4325 }
4326 }
Alan Cox4ac43602006-06-28 04:26:52 -07004327 spin_unlock_irqrestore(&brd_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004328
4329 stli_comstats.txtotal = stli_cdkstats.txchars;
4330 stli_comstats.rxtotal = stli_cdkstats.rxchars + stli_cdkstats.ringover;
4331 stli_comstats.txbuffered = stli_cdkstats.txringq;
4332 stli_comstats.rxbuffered += stli_cdkstats.rxringq;
4333 stli_comstats.rxoverrun = stli_cdkstats.overruns;
4334 stli_comstats.rxparity = stli_cdkstats.parity;
4335 stli_comstats.rxframing = stli_cdkstats.framing;
4336 stli_comstats.rxlost = stli_cdkstats.ringover;
4337 stli_comstats.rxbreaks = stli_cdkstats.rxbreaks;
4338 stli_comstats.txbreaks = stli_cdkstats.txbreaks;
4339 stli_comstats.txxon = stli_cdkstats.txstart;
4340 stli_comstats.txxoff = stli_cdkstats.txstop;
4341 stli_comstats.rxxon = stli_cdkstats.rxstart;
4342 stli_comstats.rxxoff = stli_cdkstats.rxstop;
4343 stli_comstats.rxrtsoff = stli_cdkstats.rtscnt / 2;
4344 stli_comstats.rxrtson = stli_cdkstats.rtscnt - stli_comstats.rxrtsoff;
4345 stli_comstats.modem = stli_cdkstats.dcdcnt;
4346 stli_comstats.hwid = stli_cdkstats.hwid;
4347 stli_comstats.signals = stli_mktiocm(stli_cdkstats.signals);
4348
Alan Cox4ac43602006-06-28 04:26:52 -07004349 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004350}
4351
4352/*****************************************************************************/
4353
4354/*
4355 * Return the port stats structure to user app. A NULL port struct
4356 * pointer passed in means that we need to find out from the app
4357 * what port to get stats for (used through board control device).
4358 */
4359
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004360static int stli_getportstats(struct stliport *portp, comstats_t __user *cp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004361{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004362 struct stlibrd *brdp;
Alan Cox4ac43602006-06-28 04:26:52 -07004363 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004364
4365 if (!portp) {
4366 if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
4367 return -EFAULT;
4368 portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
4369 stli_comstats.port);
4370 if (!portp)
4371 return -ENODEV;
4372 }
4373
4374 brdp = stli_brds[portp->brdnr];
4375 if (!brdp)
4376 return -ENODEV;
4377
4378 if ((rc = stli_portcmdstats(portp)) < 0)
4379 return rc;
4380
4381 return copy_to_user(cp, &stli_comstats, sizeof(comstats_t)) ?
4382 -EFAULT : 0;
4383}
4384
4385/*****************************************************************************/
4386
4387/*
4388 * Clear the port stats structure. We also return it zeroed out...
4389 */
4390
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004391static int stli_clrportstats(struct stliport *portp, comstats_t __user *cp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004392{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004393 struct stlibrd *brdp;
Alan Cox4ac43602006-06-28 04:26:52 -07004394 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004395
4396 if (!portp) {
4397 if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
4398 return -EFAULT;
4399 portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
4400 stli_comstats.port);
4401 if (!portp)
4402 return -ENODEV;
4403 }
4404
4405 brdp = stli_brds[portp->brdnr];
4406 if (!brdp)
4407 return -ENODEV;
4408
4409 if (brdp->state & BST_STARTED) {
4410 if ((rc = stli_cmdwait(brdp, portp, A_CLEARSTATS, NULL, 0, 0)) < 0)
4411 return rc;
4412 }
4413
4414 memset(&stli_comstats, 0, sizeof(comstats_t));
4415 stli_comstats.brd = portp->brdnr;
4416 stli_comstats.panel = portp->panelnr;
4417 stli_comstats.port = portp->portnr;
4418
4419 if (copy_to_user(cp, &stli_comstats, sizeof(comstats_t)))
4420 return -EFAULT;
4421 return 0;
4422}
4423
4424/*****************************************************************************/
4425
4426/*
4427 * Return the entire driver ports structure to a user app.
4428 */
4429
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004430static int stli_getportstruct(struct stliport __user *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004431{
Jiri Slaby1328d732006-12-08 02:39:19 -08004432 struct stliport stli_dummyport;
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004433 struct stliport *portp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004434
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004435 if (copy_from_user(&stli_dummyport, arg, sizeof(struct stliport)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004436 return -EFAULT;
4437 portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr,
4438 stli_dummyport.portnr);
4439 if (!portp)
4440 return -ENODEV;
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004441 if (copy_to_user(arg, portp, sizeof(struct stliport)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004442 return -EFAULT;
4443 return 0;
4444}
4445
4446/*****************************************************************************/
4447
4448/*
4449 * Return the entire driver board structure to a user app.
4450 */
4451
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004452static int stli_getbrdstruct(struct stlibrd __user *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004453{
Jiri Slaby1328d732006-12-08 02:39:19 -08004454 struct stlibrd stli_dummybrd;
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004455 struct stlibrd *brdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004456
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004457 if (copy_from_user(&stli_dummybrd, arg, sizeof(struct stlibrd)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004458 return -EFAULT;
Jiri Slaby1328d732006-12-08 02:39:19 -08004459 if (stli_dummybrd.brdnr >= STL_MAXBRDS)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004460 return -ENODEV;
4461 brdp = stli_brds[stli_dummybrd.brdnr];
4462 if (!brdp)
4463 return -ENODEV;
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004464 if (copy_to_user(arg, brdp, sizeof(struct stlibrd)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004465 return -EFAULT;
4466 return 0;
4467}
4468
4469/*****************************************************************************/
4470
4471/*
4472 * The "staliomem" device is also required to do some special operations on
4473 * the board. We need to be able to send an interrupt to the board,
4474 * reset it, and start/stop it.
4475 */
4476
4477static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
4478{
Jiri Slaby1f8ec432006-12-08 02:39:18 -08004479 struct stlibrd *brdp;
Alan Cox4ac43602006-06-28 04:26:52 -07004480 int brdnr, rc, done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004481 void __user *argp = (void __user *)arg;
4482
Linus Torvalds1da177e2005-04-16 15:20:36 -07004483/*
4484 * First up handle the board independent ioctls.
4485 */
4486 done = 0;
4487 rc = 0;
4488
4489 switch (cmd) {
4490 case COM_GETPORTSTATS:
4491 rc = stli_getportstats(NULL, argp);
4492 done++;
4493 break;
4494 case COM_CLRPORTSTATS:
4495 rc = stli_clrportstats(NULL, argp);
4496 done++;
4497 break;
4498 case COM_GETBRDSTATS:
4499 rc = stli_getbrdstats(argp);
4500 done++;
4501 break;
4502 case COM_READPORT:
4503 rc = stli_getportstruct(argp);
4504 done++;
4505 break;
4506 case COM_READBOARD:
4507 rc = stli_getbrdstruct(argp);
4508 done++;
4509 break;
4510 }
4511
4512 if (done)
Alan Cox4ac43602006-06-28 04:26:52 -07004513 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004514
4515/*
4516 * Now handle the board specific ioctls. These all depend on the
4517 * minor number of the device they were called from.
4518 */
4519 brdnr = iminor(ip);
4520 if (brdnr >= STL_MAXBRDS)
Alan Cox4ac43602006-06-28 04:26:52 -07004521 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004522 brdp = stli_brds[brdnr];
4523 if (!brdp)
Alan Cox4ac43602006-06-28 04:26:52 -07004524 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004525 if (brdp->state == 0)
Alan Cox4ac43602006-06-28 04:26:52 -07004526 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004527
4528 switch (cmd) {
4529 case STL_BINTR:
4530 EBRDINTR(brdp);
4531 break;
4532 case STL_BSTART:
4533 rc = stli_startbrd(brdp);
4534 break;
4535 case STL_BSTOP:
4536 brdp->state &= ~BST_STARTED;
4537 break;
4538 case STL_BRESET:
4539 brdp->state &= ~BST_STARTED;
4540 EBRDRESET(brdp);
4541 if (stli_shared == 0) {
4542 if (brdp->reenable != NULL)
4543 (* brdp->reenable)(brdp);
4544 }
4545 break;
4546 default:
4547 rc = -ENOIOCTLCMD;
4548 break;
4549 }
Alan Cox4ac43602006-06-28 04:26:52 -07004550 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004551}
4552
Jeff Dikeb68e31d2006-10-02 02:17:18 -07004553static const struct tty_operations stli_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004554 .open = stli_open,
4555 .close = stli_close,
4556 .write = stli_write,
4557 .put_char = stli_putchar,
4558 .flush_chars = stli_flushchars,
4559 .write_room = stli_writeroom,
4560 .chars_in_buffer = stli_charsinbuffer,
4561 .ioctl = stli_ioctl,
4562 .set_termios = stli_settermios,
4563 .throttle = stli_throttle,
4564 .unthrottle = stli_unthrottle,
4565 .stop = stli_stop,
4566 .start = stli_start,
4567 .hangup = stli_hangup,
4568 .flush_buffer = stli_flushbuffer,
4569 .break_ctl = stli_breakctl,
4570 .wait_until_sent = stli_waituntilsent,
4571 .send_xchar = stli_sendxchar,
4572 .read_proc = stli_readproc,
4573 .tiocmget = stli_tiocmget,
4574 .tiocmset = stli_tiocmset,
4575};
4576
4577/*****************************************************************************/
4578
Adrian Bunk672b2712006-06-30 01:55:30 -07004579static int __init stli_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004580{
4581 int i;
4582 printk(KERN_INFO "%s: version %s\n", stli_drvtitle, stli_drvversion);
4583
Alan Cox4ac43602006-06-28 04:26:52 -07004584 spin_lock_init(&stli_lock);
4585 spin_lock_init(&brd_lock);
4586
Linus Torvalds1da177e2005-04-16 15:20:36 -07004587 stli_initbrds();
4588
4589 stli_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
4590 if (!stli_serial)
4591 return -ENOMEM;
4592
4593/*
4594 * Allocate a temporary write buffer.
4595 */
Tobias Klauserb0b4ed72006-03-31 02:30:56 -08004596 stli_txcookbuf = kmalloc(STLI_TXBUFSIZE, GFP_KERNEL);
4597 if (!stli_txcookbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004598 printk(KERN_ERR "STALLION: failed to allocate memory "
4599 "(size=%d)\n", STLI_TXBUFSIZE);
4600
4601/*
4602 * Set up a character driver for the shared memory region. We need this
4603 * to down load the slave code image. Also it is a useful debugging tool.
4604 */
4605 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stli_fsiomem))
4606 printk(KERN_ERR "STALLION: failed to register serial memory "
4607 "device\n");
4608
gregkh@suse.deca8eca62005-03-23 09:53:09 -08004609 istallion_class = class_create(THIS_MODULE, "staliomem");
Greg Kroah-Hartman7c69ef72005-06-20 21:15:16 -07004610 for (i = 0; i < 4; i++)
Greg Kroah-Hartman53f46542005-10-27 22:25:43 -07004611 class_device_create(istallion_class, NULL,
4612 MKDEV(STL_SIOMEMMAJOR, i),
Linus Torvalds1da177e2005-04-16 15:20:36 -07004613 NULL, "staliomem%d", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004614
4615/*
4616 * Set up the tty driver structure and register us as a driver.
4617 */
4618 stli_serial->owner = THIS_MODULE;
4619 stli_serial->driver_name = stli_drvname;
4620 stli_serial->name = stli_serialname;
4621 stli_serial->major = STL_SERIALMAJOR;
4622 stli_serial->minor_start = 0;
4623 stli_serial->type = TTY_DRIVER_TYPE_SERIAL;
4624 stli_serial->subtype = SERIAL_TYPE_NORMAL;
4625 stli_serial->init_termios = stli_deftermios;
4626 stli_serial->flags = TTY_DRIVER_REAL_RAW;
4627 tty_set_operations(stli_serial, &stli_ops);
4628
4629 if (tty_register_driver(stli_serial)) {
4630 put_tty_driver(stli_serial);
4631 printk(KERN_ERR "STALLION: failed to register serial driver\n");
4632 return -EBUSY;
4633 }
Alan Cox4ac43602006-06-28 04:26:52 -07004634 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004635}
4636
4637/*****************************************************************************/