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