Merge branch 'drm-armada-fixes' of git://ftp.arm.linux.org.uk/~rmk/linux-arm into...
[pandora-kernel.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  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  *
19  *      NOTE: THIS IS A SHARED HEADER. DO NOT CHANGE CODING STYLE!!!
20  *
21  *************************************************************************
22  *
23  * Driver includes
24  *
25  *************************************************************************/
26
27 #ifndef __DGNC_DRIVER_H
28 #define __DGNC_DRIVER_H
29
30 #include <linux/types.h>        /* To pick up the varions Linux types */
31 #include <linux/tty.h>    /* To pick up the various tty structs/defines */
32 #include <linux/interrupt.h>    /* For irqreturn_t type */
33
34 #include "dgnc_types.h"         /* Additional types needed by the Digi header files */
35 #include "digi.h"               /* Digi specific ioctl header */
36 #include "dgnc_kcompat.h"       /* Kernel 2.4/2.6 compat includes */
37 #include "dgnc_sysfs.h"         /* Support for SYSFS */
38
39 /*************************************************************************
40  *
41  * Driver defines
42  *
43  *************************************************************************/
44
45 /*
46  * Driver identification, error and debugging statments
47  *
48  * In theory, you can change all occurrences of "digi" in the next
49  * three lines, and the driver printk's will all automagically change.
50  *
51  * APR((fmt, args, ...));       Always prints message
52  */
53 #define PROCSTR         "dgnc"                  /* /proc entries         */
54 #define DEVSTR          "/dev/dg/dgnc"          /* /dev entries          */
55 #define DRVSTR          "dgnc"                  /* Driver name string
56                                                  * displayed by APR      */
57 #define APR(args)       do { printk(DRVSTR": "); printk args; \
58                            } while (0)
59 #define RAPR(args)      do { printk args; } while (0)
60
61 #define TRC_TO_CONSOLE 1
62
63 /*
64  * Debugging levels can be set using debug insmod variable
65  * They can also be compiled out completely.
66  */
67
68 #define DBG_INIT                (dgnc_debug & 0x01)
69 #define DBG_BASIC               (dgnc_debug & 0x02)
70 #define DBG_CORE                (dgnc_debug & 0x04)
71
72 #define DBG_OPEN                (dgnc_debug & 0x08)
73 #define DBG_CLOSE               (dgnc_debug & 0x10)
74 #define DBG_READ                (dgnc_debug & 0x20)
75 #define DBG_WRITE               (dgnc_debug & 0x40)
76
77 #define DBG_IOCTL               (dgnc_debug & 0x80)
78
79 #define DBG_PROC                (dgnc_debug & 0x100)
80 #define DBG_PARAM               (dgnc_debug & 0x200)
81 #define DBG_PSCAN               (dgnc_debug & 0x400)
82 #define DBG_EVENT               (dgnc_debug & 0x800)
83
84 #define DBG_DRAIN               (dgnc_debug & 0x1000)
85 #define DBG_MSIGS               (dgnc_debug & 0x2000)
86
87 #define DBG_MGMT                (dgnc_debug & 0x4000)
88 #define DBG_INTR                (dgnc_debug & 0x8000)
89
90 #define DBG_CARR                (dgnc_debug & 0x10000)
91
92 /* Number of boards we support at once. */
93 #define MAXBOARDS       20
94 #define MAXPORTS        8
95 #define MAXTTYNAMELEN   200
96
97 /* Our 3 magic numbers for our board, channel and unit structs */
98 #define DGNC_BOARD_MAGIC        0x5c6df104
99 #define DGNC_CHANNEL_MAGIC      0x6c6df104
100 #define DGNC_UNIT_MAGIC         0x7c6df104
101
102 /* Serial port types */
103 #define DGNC_SERIAL             0
104 #define DGNC_PRINT              1
105
106 #define SERIAL_TYPE_NORMAL      1
107
108 #define PORT_NUM(dev)   ((dev) & 0x7f)
109 #define IS_PRINT(dev)   (((dev) & 0xff) >= 0x80)
110
111 /* MAX number of stop characters we will send when our read queue is getting full */
112 #define MAX_STOPS_SENT 5
113
114 /* 4 extra for alignment play space */
115 #define WRITEBUFLEN             ((4096) + 4)
116 #define MYFLIPLEN               N_TTY_BUF_SIZE
117
118 #define dgnc_jiffies_from_ms(a) (((a) * HZ) / 1000)
119
120 /*
121  * Define a local default termios struct. All ports will be created
122  * with this termios initially.  This is the same structure that is defined
123  * as the default in tty_io.c with the same settings overriden as in serial.c
124  *
125  * In short, this should match the internal serial ports' defaults.
126  */
127 #define DEFAULT_IFLAGS  (ICRNL | IXON)
128 #define DEFAULT_OFLAGS  (OPOST | ONLCR)
129 #define DEFAULT_CFLAGS  (B9600 | CS8 | CREAD | HUPCL | CLOCAL)
130 #define DEFAULT_LFLAGS  (ISIG | ICANON | ECHO | ECHOE | ECHOK | \
131                         ECHOCTL | ECHOKE | IEXTEN)
132
133 #ifndef _POSIX_VDISABLE
134 #define   _POSIX_VDISABLE '\0'
135 #endif
136
137 #define SNIFF_MAX       65536           /* Sniff buffer size (2^n) */
138 #define SNIFF_MASK      (SNIFF_MAX - 1) /* Sniff wrap mask */
139
140 /*
141  * All the possible states the driver can be while being loaded.
142  */
143 enum {
144         DRIVER_INITIALIZED = 0,
145         DRIVER_READY
146 };
147
148 /*
149  * All the possible states the board can be while booting up.
150  */
151 enum {
152         BOARD_FAILED = 0,
153         BOARD_FOUND,
154         BOARD_READY
155 };
156
157
158 /*************************************************************************
159  *
160  * Structures and closely related defines.
161  *
162  *************************************************************************/
163
164 struct dgnc_board;
165 struct channel_t;
166
167 /************************************************************************
168  * Per board operations structure                                      *
169  ************************************************************************/
170 struct board_ops {
171         void (*tasklet)(unsigned long data);
172         irqreturn_t (*intr)(int irq, void *voidbrd);
173         void (*uart_init)(struct channel_t *ch);
174         void (*uart_off)(struct channel_t *ch);
175         int  (*drain)(struct tty_struct *tty, uint seconds);
176         void (*param)(struct tty_struct *tty);
177         void (*vpd)(struct dgnc_board *brd);
178         void (*assert_modem_signals)(struct channel_t *ch);
179         void (*flush_uart_write)(struct channel_t *ch);
180         void (*flush_uart_read)(struct channel_t *ch);
181         void (*disable_receiver)(struct channel_t *ch);
182         void (*enable_receiver)(struct channel_t *ch);
183         void (*send_break)(struct channel_t *ch, int);
184         void (*send_start_character)(struct channel_t *ch);
185         void (*send_stop_character)(struct channel_t *ch);
186         void (*copy_data_from_queue_to_uart)(struct channel_t *ch);
187         uint (*get_uart_bytes_left)(struct channel_t *ch);
188         void (*send_immediate_char)(struct channel_t *ch, unsigned char);
189 };
190
191 /************************************************************************
192  * Device flag definitions for bd_flags.
193  ************************************************************************/
194 #define BD_IS_PCI_EXPRESS     0x0001      /* Is a PCI Express board */
195
196
197 /*
198  *      Per-board information
199  */
200 struct dgnc_board {
201         int             magic;          /* Board Magic number.  */
202         int             boardnum;       /* Board number: 0-32 */
203
204         int             type;           /* Type of board */
205         char            *name;          /* Product Name */
206         struct pci_dev  *pdev;          /* Pointer to the pci_dev struct */
207         unsigned long   bd_flags;       /* Board flags */
208         u16             vendor;         /* PCI vendor ID */
209         u16             device;         /* PCI device ID */
210         u16             subvendor;      /* PCI subsystem vendor ID */
211         u16             subdevice;      /* PCI subsystem device ID */
212         unsigned char   rev;            /* PCI revision ID */
213         uint            pci_bus;        /* PCI bus value */
214         uint            pci_slot;       /* PCI slot value */
215         uint            maxports;       /* MAX ports this board can handle */
216         unsigned char   dvid;           /* Board specific device id */
217         unsigned char   vpd[128];       /* VPD of board, if found */
218         unsigned char   serial_num[20]; /* Serial number of board, if found in VPD */
219
220         spinlock_t      bd_lock;        /* Used to protect board */
221
222         spinlock_t      bd_intr_lock;   /* Used to protect the poller tasklet and
223                                          * the interrupt routine from each other.
224                                          */
225
226         uint            state;          /* State of card. */
227         wait_queue_head_t state_wait;   /* Place to sleep on for state change */
228
229         struct          tasklet_struct helper_tasklet; /* Poll helper tasklet */
230
231         uint            nasync;         /* Number of ports on card */
232
233         uint            irq;            /* Interrupt request number */
234         ulong           intr_count;     /* Count of interrupts */
235         ulong           intr_modem;     /* Count of interrupts */
236         ulong           intr_tx;        /* Count of interrupts */
237         ulong           intr_rx;        /* Count of interrupts */
238
239         ulong           membase;        /* Start of base memory of the card */
240         ulong           membase_end;    /* End of base memory of the card */
241
242         u8 __iomem              *re_map_membase;/* Remapped memory of the card */
243
244         ulong           iobase;         /* Start of io base of the card */
245         ulong           iobase_end;     /* End of io base of the card */
246
247         uint            bd_uart_offset; /* Space between each UART */
248
249         struct channel_t *channels[MAXPORTS]; /* array of pointers to our channels. */
250
251         struct tty_driver       SerialDriver;
252         char            SerialName[200];
253         struct tty_driver       PrintDriver;
254         char            PrintName[200];
255
256         uint            dgnc_Major_Serial_Registered;
257         uint            dgnc_Major_TransparentPrint_Registered;
258
259         uint            dgnc_Serial_Major;
260         uint            dgnc_TransparentPrint_Major;
261
262         uint            TtyRefCnt;
263
264         char            *flipbuf;       /* Our flip buffer, alloced if board is found */
265
266         u16             dpatype;        /* The board "type", as defined by DPA */
267         u16             dpastatus;      /* The board "status", as defined by DPA */
268
269         /*
270          *      Mgmt data.
271          */
272         char            *msgbuf_head;
273         char            *msgbuf;
274
275         uint            bd_dividend;    /* Board/UARTs specific dividend */
276
277         struct board_ops *bd_ops;
278
279         /* /proc/<board> entries */
280         struct proc_dir_entry *proc_entry_pointer;
281         struct dgnc_proc_entry *dgnc_board_table;
282
283 };
284
285
286 /************************************************************************
287  * Unit flag definitions for un_flags.
288  ************************************************************************/
289 #define UN_ISOPEN       0x0001          /* Device is open               */
290 #define UN_CLOSING      0x0002          /* Line is being closed         */
291 #define UN_IMM          0x0004          /* Service immediately          */
292 #define UN_BUSY         0x0008          /* Some work this channel       */
293 #define UN_BREAKI       0x0010          /* Input break received         */
294 #define UN_PWAIT        0x0020          /* Printer waiting for terminal */
295 #define UN_TIME         0x0040          /* Waiting on time              */
296 #define UN_EMPTY        0x0080          /* Waiting output queue empty   */
297 #define UN_LOW          0x0100          /* Waiting output low water mark*/
298 #define UN_EXCL_OPEN    0x0200          /* Open for exclusive use       */
299 #define UN_WOPEN        0x0400          /* Device waiting for open      */
300 #define UN_WIOCTL       0x0800          /* Device waiting for open      */
301 #define UN_HANGUP       0x8000          /* Carrier lost                 */
302
303 struct device;
304
305 /************************************************************************
306  * Structure for terminal or printer unit.
307  ************************************************************************/
308 struct un_t {
309         int     magic;          /* Unit Magic Number.                   */
310         struct  channel_t *un_ch;
311         ulong   un_time;
312         uint    un_type;
313         uint    un_open_count;  /* Counter of opens to port             */
314         struct tty_struct *un_tty;/* Pointer to unit tty structure      */
315         uint    un_flags;       /* Unit flags                           */
316         wait_queue_head_t un_flags_wait; /* Place to sleep to wait on unit */
317         uint    un_dev;         /* Minor device number                  */
318         struct device *un_sysfs;
319 };
320
321
322 /************************************************************************
323  * Device flag definitions for ch_flags.
324  ************************************************************************/
325 #define CH_PRON         0x0001          /* Printer on string            */
326 #define CH_STOP         0x0002          /* Output is stopped            */
327 #define CH_STOPI        0x0004          /* Input is stopped             */
328 #define CH_CD           0x0008          /* Carrier is present           */
329 #define CH_FCAR         0x0010          /* Carrier forced on            */
330 #define CH_HANGUP       0x0020          /* Hangup received              */
331
332 #define CH_RECEIVER_OFF 0x0040          /* Receiver is off              */
333 #define CH_OPENING      0x0080          /* Port in fragile open state   */
334 #define CH_CLOSING      0x0100          /* Port in fragile close state  */
335 #define CH_FIFO_ENABLED 0x0200          /* Port has FIFOs enabled       */
336 #define CH_TX_FIFO_EMPTY 0x0400         /* TX Fifo is completely empty  */
337 #define CH_TX_FIFO_LWM  0x0800          /* TX Fifo is below Low Water   */
338 #define CH_BREAK_SENDING 0x1000         /* Break is being sent          */
339 #define CH_LOOPBACK 0x2000              /* Channel is in lookback mode  */
340 #define CH_FLIPBUF_IN_USE 0x4000        /* Channel's flipbuf is in use  */
341 #define CH_BAUD0        0x08000         /* Used for checking B0 transitions */
342 #define CH_FORCED_STOP  0x20000         /* Output is forcibly stopped   */
343 #define CH_FORCED_STOPI 0x40000         /* Input is forcibly stopped    */
344
345 /*
346  * Definitions for ch_sniff_flags
347  */
348 #define SNIFF_OPEN      0x1
349 #define SNIFF_WAIT_DATA 0x2
350 #define SNIFF_WAIT_SPACE 0x4
351
352
353 /* Our Read/Error/Write queue sizes */
354 #define RQUEUEMASK      0x1FFF          /* 8 K - 1 */
355 #define EQUEUEMASK      0x1FFF          /* 8 K - 1 */
356 #define WQUEUEMASK      0x0FFF          /* 4 K - 1 */
357 #define RQUEUESIZE      (RQUEUEMASK + 1)
358 #define EQUEUESIZE      RQUEUESIZE
359 #define WQUEUESIZE      (WQUEUEMASK + 1)
360
361
362 /************************************************************************
363  * Channel information structure.
364  ************************************************************************/
365 struct channel_t {
366         int magic;                      /* Channel Magic Number         */
367         struct dgnc_board       *ch_bd;         /* Board structure pointer      */
368         struct digi_t   ch_digi;        /* Transparent Print structure  */
369         struct un_t     ch_tun;         /* Terminal unit info      */
370         struct un_t     ch_pun;         /* Printer unit info        */
371
372         spinlock_t      ch_lock;        /* provide for serialization */
373         wait_queue_head_t ch_flags_wait;
374
375         uint            ch_portnum;     /* Port number, 0 offset.       */
376         uint            ch_open_count;  /* open count                   */
377         uint            ch_flags;       /* Channel flags                */
378
379         ulong           ch_close_delay; /* How long we should drop RTS/DTR for */
380
381         ulong           ch_cpstime;     /* Time for CPS calculations    */
382
383         tcflag_t        ch_c_iflag;     /* channel iflags              */
384         tcflag_t        ch_c_cflag;     /* channel cflags              */
385         tcflag_t        ch_c_oflag;     /* channel oflags              */
386         tcflag_t        ch_c_lflag;     /* channel lflags              */
387         unsigned char   ch_stopc;       /* Stop character              */
388         unsigned char   ch_startc;      /* Start character            */
389
390         uint            ch_old_baud;    /* Cache of the current baud */
391         uint            ch_custom_speed;/* Custom baud, if set */
392
393         uint            ch_wopen;       /* Waiting for open process cnt */
394
395         unsigned char           ch_mostat;      /* FEP output modem status      */
396         unsigned char           ch_mistat;      /* FEP input modem status       */
397
398         struct neo_uart_struct __iomem *ch_neo_uart;    /* Pointer to the "mapped" UART struct */
399         struct cls_uart_struct __iomem *ch_cls_uart;    /* Pointer to the "mapped" UART struct */
400
401         unsigned char   ch_cached_lsr;  /* Cached value of the LSR register */
402
403         unsigned char   *ch_rqueue;     /* Our read queue buffer - malloc'ed */
404         ushort          ch_r_head;      /* Head location of the read queue */
405         ushort          ch_r_tail;      /* Tail location of the read queue */
406
407         unsigned char   *ch_equeue;     /* Our error queue buffer - malloc'ed */
408         ushort          ch_e_head;      /* Head location of the error queue */
409         ushort          ch_e_tail;      /* Tail location of the error queue */
410
411         unsigned char   *ch_wqueue;     /* Our write queue buffer - malloc'ed */
412         ushort          ch_w_head;      /* Head location of the write queue */
413         ushort          ch_w_tail;      /* Tail location of the write queue */
414
415         ulong           ch_rxcount;     /* total of data received so far */
416         ulong           ch_txcount;     /* total of data transmitted so far */
417
418         unsigned char           ch_r_tlevel;    /* Receive Trigger level */
419         unsigned char           ch_t_tlevel;    /* Transmit Trigger level */
420
421         unsigned char           ch_r_watermark; /* Receive Watermark */
422
423         ulong           ch_stop_sending_break;  /* Time we should STOP sending a break */
424
425         uint            ch_stops_sent;  /* How many times I have sent a stop character
426                                          * to try to stop the other guy sending.
427                                          */
428         ulong           ch_err_parity;  /* Count of parity errors on channel */
429         ulong           ch_err_frame;   /* Count of framing errors on channel */
430         ulong           ch_err_break;   /* Count of breaks on channel */
431         ulong           ch_err_overrun; /* Count of overruns on channel */
432
433         ulong           ch_xon_sends;   /* Count of xons transmitted */
434         ulong           ch_xoff_sends;  /* Count of xoffs transmitted */
435
436         ulong           ch_intr_modem;  /* Count of interrupts */
437         ulong           ch_intr_tx;     /* Count of interrupts */
438         ulong           ch_intr_rx;     /* Count of interrupts */
439
440
441         /* /proc/<board>/<channel> entries */
442         struct proc_dir_entry *proc_entry_pointer;
443         struct dgnc_proc_entry *dgnc_channel_table;
444
445         uint ch_sniff_in;
446         uint ch_sniff_out;
447         char *ch_sniff_buf;             /* Sniff buffer for proc */
448         ulong ch_sniff_flags;           /* Channel flags                */
449         wait_queue_head_t ch_sniff_wait;
450 };
451
452 /*
453  * Our Global Variables.
454  */
455 extern uint             dgnc_Major;             /* Our driver/mgmt major        */
456 extern int              dgnc_debug;             /* Debug variable               */
457 extern int              dgnc_rawreadok;         /* Set if user wants rawreads   */
458 extern int              dgnc_poll_tick;         /* Poll interval - 20 ms        */
459 extern int              dgnc_trcbuf_size;       /* Size of the ringbuffer       */
460 extern spinlock_t       dgnc_global_lock;       /* Driver global spinlock       */
461 extern uint             dgnc_NumBoards;         /* Total number of boards       */
462 extern struct dgnc_board        *dgnc_Board[MAXBOARDS]; /* Array of board structs       */
463 extern char             *dgnc_state_text[];     /* Array of state text          */
464
465 #endif