Merge branch 'drm-etnaviv-fixes' of git://git.pengutronix.de/lst/linux into drm-fixes
[linux-2.6-block.git] / drivers / staging / dgnc / dgnc_driver.h
CommitLineData
0b99d589
LL
1/*
2 * Copyright 2003 Digi International (www.digi.com)
3 * Scott H Kilau <Scott_Kilau at digi dot com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
12 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 *
0b99d589
LL
15 *************************************************************************
16 *
17 * Driver includes
18 *
19 *************************************************************************/
20
21#ifndef __DGNC_DRIVER_H
22#define __DGNC_DRIVER_H
23
f3c709b8
NC
24#include <linux/types.h>
25#include <linux/tty.h>
26#include <linux/interrupt.h>
0b99d589 27
4c1c56e6 28#include "digi.h" /* Digi specific ioctl header */
0b99d589
LL
29#include "dgnc_sysfs.h" /* Support for SYSFS */
30
31/*************************************************************************
32 *
33 * Driver defines
34 *
35 *************************************************************************/
36
2a71a3c7 37/* Driver identification and error statments */
0b99d589
LL
38#define PROCSTR "dgnc" /* /proc entries */
39#define DEVSTR "/dev/dg/dgnc" /* /dev entries */
1f26adc9 40#define DRVSTR "dgnc" /* Driver name string */
f11cc568 41#define DG_PART "40002369_F" /* RPM part number */
0b99d589
LL
42
43#define TRC_TO_CONSOLE 1
44
0b99d589
LL
45/* Number of boards we support at once. */
46#define MAXBOARDS 20
47#define MAXPORTS 8
48#define MAXTTYNAMELEN 200
49
50/* Our 3 magic numbers for our board, channel and unit structs */
51#define DGNC_BOARD_MAGIC 0x5c6df104
52#define DGNC_CHANNEL_MAGIC 0x6c6df104
53#define DGNC_UNIT_MAGIC 0x7c6df104
54
55/* Serial port types */
56#define DGNC_SERIAL 0
57#define DGNC_PRINT 1
58
59#define SERIAL_TYPE_NORMAL 1
60
61#define PORT_NUM(dev) ((dev) & 0x7f)
62#define IS_PRINT(dev) (((dev) & 0xff) >= 0x80)
63
51c826f0
CM
64/* MAX number of stop characters we will send
65 * when our read queue is getting full
66 */
0b99d589
LL
67#define MAX_STOPS_SENT 5
68
69/* 4 extra for alignment play space */
70#define WRITEBUFLEN ((4096) + 4)
0b99d589
LL
71
72#define dgnc_jiffies_from_ms(a) (((a) * HZ) / 1000)
73
74/*
75 * Define a local default termios struct. All ports will be created
76 * with this termios initially. This is the same structure that is defined
d8a76d66 77 * as the default in tty_io.c with the same settings overridden as in serial.c
0b99d589
LL
78 *
79 * In short, this should match the internal serial ports' defaults.
80 */
81#define DEFAULT_IFLAGS (ICRNL | IXON)
82#define DEFAULT_OFLAGS (OPOST | ONLCR)
83#define DEFAULT_CFLAGS (B9600 | CS8 | CREAD | HUPCL | CLOCAL)
84#define DEFAULT_LFLAGS (ISIG | ICANON | ECHO | ECHOE | ECHOK | \
85 ECHOCTL | ECHOKE | IEXTEN)
86
87#ifndef _POSIX_VDISABLE
88#define _POSIX_VDISABLE '\0'
89#endif
90
0b99d589
LL
91/*
92 * All the possible states the driver can be while being loaded.
93 */
94enum {
95 DRIVER_INITIALIZED = 0,
96 DRIVER_READY
97};
98
99/*
100 * All the possible states the board can be while booting up.
101 */
102enum {
103 BOARD_FAILED = 0,
104 BOARD_FOUND,
105 BOARD_READY
106};
107
0b99d589
LL
108/*************************************************************************
109 *
110 * Structures and closely related defines.
111 *
112 *************************************************************************/
113
03425f55 114struct dgnc_board;
0b99d589
LL
115struct channel_t;
116
117/************************************************************************
5a62025d 118 * Per board operations structure *
0b99d589
LL
119 ************************************************************************/
120struct board_ops {
f23e875f
GK
121 void (*tasklet)(unsigned long data);
122 irqreturn_t (*intr)(int irq, void *voidbrd);
123 void (*uart_init)(struct channel_t *ch);
124 void (*uart_off)(struct channel_t *ch);
125 int (*drain)(struct tty_struct *tty, uint seconds);
126 void (*param)(struct tty_struct *tty);
127 void (*vpd)(struct dgnc_board *brd);
128 void (*assert_modem_signals)(struct channel_t *ch);
129 void (*flush_uart_write)(struct channel_t *ch);
130 void (*flush_uart_read)(struct channel_t *ch);
131 void (*disable_receiver)(struct channel_t *ch);
132 void (*enable_receiver)(struct channel_t *ch);
133 void (*send_break)(struct channel_t *ch, int);
134 void (*send_start_character)(struct channel_t *ch);
135 void (*send_stop_character)(struct channel_t *ch);
136 void (*copy_data_from_queue_to_uart)(struct channel_t *ch);
137 uint (*get_uart_bytes_left)(struct channel_t *ch);
138 void (*send_immediate_char)(struct channel_t *ch, unsigned char);
0b99d589
LL
139};
140
4c1c56e6 141/************************************************************************
0b99d589
LL
142 * Device flag definitions for bd_flags.
143 ************************************************************************/
5a62025d 144#define BD_IS_PCI_EXPRESS 0x0001 /* Is a PCI Express board */
0b99d589 145
0b99d589
LL
146/*
147 * Per-board information
148 */
03425f55 149struct dgnc_board {
0b99d589
LL
150 int magic; /* Board Magic number. */
151 int boardnum; /* Board number: 0-32 */
152
153 int type; /* Type of board */
154 char *name; /* Product Name */
155 struct pci_dev *pdev; /* Pointer to the pci_dev struct */
156 unsigned long bd_flags; /* Board flags */
157 u16 vendor; /* PCI vendor ID */
158 u16 device; /* PCI device ID */
159 u16 subvendor; /* PCI subsystem vendor ID */
160 u16 subdevice; /* PCI subsystem device ID */
446393e9 161 unsigned char rev; /* PCI revision ID */
0b99d589
LL
162 uint pci_bus; /* PCI bus value */
163 uint pci_slot; /* PCI slot value */
164 uint maxports; /* MAX ports this board can handle */
446393e9
EA
165 unsigned char dvid; /* Board specific device id */
166 unsigned char vpd[128]; /* VPD of board, if found */
51c826f0
CM
167 unsigned char serial_num[20]; /* Serial number of board,
168 * if found in VPD
169 */
0b99d589
LL
170
171 spinlock_t bd_lock; /* Used to protect board */
172
51c826f0
CM
173 spinlock_t bd_intr_lock; /* Used to protect the poller tasklet
174 * and the interrupt routine from each
175 * other.
0b99d589
LL
176 */
177
178 uint state; /* State of card. */
179 wait_queue_head_t state_wait; /* Place to sleep on for state change */
180
181 struct tasklet_struct helper_tasklet; /* Poll helper tasklet */
182
183 uint nasync; /* Number of ports on card */
184
185 uint irq; /* Interrupt request number */
0b99d589
LL
186
187 ulong membase; /* Start of base memory of the card */
188 ulong membase_end; /* End of base memory of the card */
189
51c826f0 190 u8 __iomem *re_map_membase; /* Remapped memory of the card */
0b99d589
LL
191
192 ulong iobase; /* Start of io base of the card */
193 ulong iobase_end; /* End of io base of the card */
194
195 uint bd_uart_offset; /* Space between each UART */
196
51c826f0
CM
197 struct channel_t *channels[MAXPORTS]; /* array of pointers
198 * to our channels.
199 */
0b99d589 200
60b3109e 201 struct tty_driver *serial_driver;
a25ad520 202 char serial_name[200];
60b3109e 203 struct tty_driver *print_driver;
a25ad520 204 char print_name[200];
0b99d589 205
51c826f0
CM
206 u16 dpatype; /* The board "type",
207 * as defined by DPA
208 */
209 u16 dpastatus; /* The board "status",
210 * as defined by DPA
211 */
0b99d589 212
0b99d589
LL
213 uint bd_dividend; /* Board/UARTs specific dividend */
214
215 struct board_ops *bd_ops;
216
217 /* /proc/<board> entries */
218 struct proc_dir_entry *proc_entry_pointer;
219 struct dgnc_proc_entry *dgnc_board_table;
220
221};
222
4c1c56e6 223/************************************************************************
0b99d589
LL
224 * Unit flag definitions for un_flags.
225 ************************************************************************/
226#define UN_ISOPEN 0x0001 /* Device is open */
227#define UN_CLOSING 0x0002 /* Line is being closed */
228#define UN_IMM 0x0004 /* Service immediately */
229#define UN_BUSY 0x0008 /* Some work this channel */
230#define UN_BREAKI 0x0010 /* Input break received */
231#define UN_PWAIT 0x0020 /* Printer waiting for terminal */
232#define UN_TIME 0x0040 /* Waiting on time */
233#define UN_EMPTY 0x0080 /* Waiting output queue empty */
234#define UN_LOW 0x0100 /* Waiting output low water mark*/
235#define UN_EXCL_OPEN 0x0200 /* Open for exclusive use */
236#define UN_WOPEN 0x0400 /* Device waiting for open */
237#define UN_WIOCTL 0x0800 /* Device waiting for open */
238#define UN_HANGUP 0x8000 /* Carrier lost */
239
240struct device;
241
242/************************************************************************
4c1c56e6 243 * Structure for terminal or printer unit.
0b99d589
LL
244 ************************************************************************/
245struct un_t {
246 int magic; /* Unit Magic Number. */
247 struct channel_t *un_ch;
248 ulong un_time;
249 uint un_type;
250 uint un_open_count; /* Counter of opens to port */
251 struct tty_struct *un_tty;/* Pointer to unit tty structure */
252 uint un_flags; /* Unit flags */
253 wait_queue_head_t un_flags_wait; /* Place to sleep to wait on unit */
254 uint un_dev; /* Minor device number */
255 struct device *un_sysfs;
256};
257
4c1c56e6 258/************************************************************************
0b99d589
LL
259 * Device flag definitions for ch_flags.
260 ************************************************************************/
261#define CH_PRON 0x0001 /* Printer on string */
262#define CH_STOP 0x0002 /* Output is stopped */
263#define CH_STOPI 0x0004 /* Input is stopped */
264#define CH_CD 0x0008 /* Carrier is present */
265#define CH_FCAR 0x0010 /* Carrier forced on */
266#define CH_HANGUP 0x0020 /* Hangup received */
267
268#define CH_RECEIVER_OFF 0x0040 /* Receiver is off */
269#define CH_OPENING 0x0080 /* Port in fragile open state */
270#define CH_CLOSING 0x0100 /* Port in fragile close state */
271#define CH_FIFO_ENABLED 0x0200 /* Port has FIFOs enabled */
272#define CH_TX_FIFO_EMPTY 0x0400 /* TX Fifo is completely empty */
273#define CH_TX_FIFO_LWM 0x0800 /* TX Fifo is below Low Water */
274#define CH_BREAK_SENDING 0x1000 /* Break is being sent */
275#define CH_LOOPBACK 0x2000 /* Channel is in lookback mode */
0b99d589 276#define CH_BAUD0 0x08000 /* Used for checking B0 transitions */
4c1c56e6 277#define CH_FORCED_STOP 0x20000 /* Output is forcibly stopped */
0b99d589
LL
278#define CH_FORCED_STOPI 0x40000 /* Input is forcibly stopped */
279
0b99d589
LL
280/* Our Read/Error/Write queue sizes */
281#define RQUEUEMASK 0x1FFF /* 8 K - 1 */
282#define EQUEUEMASK 0x1FFF /* 8 K - 1 */
283#define WQUEUEMASK 0x0FFF /* 4 K - 1 */
284#define RQUEUESIZE (RQUEUEMASK + 1)
285#define EQUEUESIZE RQUEUESIZE
286#define WQUEUESIZE (WQUEUEMASK + 1)
287
4c1c56e6 288/************************************************************************
0b99d589
LL
289 * Channel information structure.
290 ************************************************************************/
291struct channel_t {
292 int magic; /* Channel Magic Number */
51c826f0 293 struct dgnc_board *ch_bd; /* Board structure pointer */
0b99d589 294 struct digi_t ch_digi; /* Transparent Print structure */
5a62025d
LL
295 struct un_t ch_tun; /* Terminal unit info */
296 struct un_t ch_pun; /* Printer unit info */
0b99d589
LL
297
298 spinlock_t ch_lock; /* provide for serialization */
299 wait_queue_head_t ch_flags_wait;
300
301 uint ch_portnum; /* Port number, 0 offset. */
302 uint ch_open_count; /* open count */
5a62025d 303 uint ch_flags; /* Channel flags */
0b99d589 304
51c826f0
CM
305 ulong ch_close_delay; /* How long we should
306 * drop RTS/DTR for
307 */
0b99d589
LL
308
309 ulong ch_cpstime; /* Time for CPS calculations */
310
5a62025d
LL
311 tcflag_t ch_c_iflag; /* channel iflags */
312 tcflag_t ch_c_cflag; /* channel cflags */
313 tcflag_t ch_c_oflag; /* channel oflags */
314 tcflag_t ch_c_lflag; /* channel lflags */
446393e9
EA
315 unsigned char ch_stopc; /* Stop character */
316 unsigned char ch_startc; /* Start character */
0b99d589
LL
317
318 uint ch_old_baud; /* Cache of the current baud */
319 uint ch_custom_speed;/* Custom baud, if set */
320
321 uint ch_wopen; /* Waiting for open process cnt */
322
51c826f0
CM
323 unsigned char ch_mostat; /* FEP output modem status */
324 unsigned char ch_mistat; /* FEP input modem status */
0b99d589 325
51c826f0
CM
326 struct neo_uart_struct __iomem *ch_neo_uart; /* Pointer to the
327 * "mapped" UART struct
328 */
329 struct cls_uart_struct __iomem *ch_cls_uart; /* Pointer to the
330 * "mapped" UART struct
331 */
0b99d589 332
446393e9 333 unsigned char ch_cached_lsr; /* Cached value of the LSR register */
0b99d589 334
446393e9 335 unsigned char *ch_rqueue; /* Our read queue buffer - malloc'ed */
0b99d589
LL
336 ushort ch_r_head; /* Head location of the read queue */
337 ushort ch_r_tail; /* Tail location of the read queue */
338
446393e9 339 unsigned char *ch_equeue; /* Our error queue buffer - malloc'ed */
0b99d589
LL
340 ushort ch_e_head; /* Head location of the error queue */
341 ushort ch_e_tail; /* Tail location of the error queue */
342
446393e9 343 unsigned char *ch_wqueue; /* Our write queue buffer - malloc'ed */
0b99d589
LL
344 ushort ch_w_head; /* Head location of the write queue */
345 ushort ch_w_tail; /* Tail location of the write queue */
346
347 ulong ch_rxcount; /* total of data received so far */
348 ulong ch_txcount; /* total of data transmitted so far */
349
446393e9
EA
350 unsigned char ch_r_tlevel; /* Receive Trigger level */
351 unsigned char ch_t_tlevel; /* Transmit Trigger level */
0b99d589 352
446393e9 353 unsigned char ch_r_watermark; /* Receive Watermark */
0b99d589 354
51c826f0
CM
355 ulong ch_stop_sending_break; /* Time we should STOP
356 * sending a break
357 */
0b99d589 358
51c826f0
CM
359 uint ch_stops_sent; /* How many times I have sent a stop
360 * character to try to stop the other
361 * guy sending.
0b99d589
LL
362 */
363 ulong ch_err_parity; /* Count of parity errors on channel */
364 ulong ch_err_frame; /* Count of framing errors on channel */
365 ulong ch_err_break; /* Count of breaks on channel */
366 ulong ch_err_overrun; /* Count of overruns on channel */
367
368 ulong ch_xon_sends; /* Count of xons transmitted */
369 ulong ch_xoff_sends; /* Count of xoffs transmitted */
370
0b99d589
LL
371 /* /proc/<board>/<channel> entries */
372 struct proc_dir_entry *proc_entry_pointer;
373 struct dgnc_proc_entry *dgnc_channel_table;
374
0b99d589
LL
375};
376
0b99d589
LL
377/*
378 * Our Global Variables.
379 */
80e3e241 380extern uint dgnc_major; /* Our driver/mgmt major */
9e39ab27
VH
381extern int dgnc_poll_tick; /* Poll interval - 20 ms */
382extern spinlock_t dgnc_global_lock; /* Driver global spinlock */
51abf45c 383extern spinlock_t dgnc_poll_lock; /* Poll scheduling lock */
f56edd42 384extern uint dgnc_num_boards; /* Total number of boards */
80e3e241 385extern struct dgnc_board *dgnc_board[MAXBOARDS]; /* Array of board
51c826f0
CM
386 * structs
387 */
0b99d589
LL
388
389#endif