Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
422 giacomo 1
/*
2
 *  linux/drivers/char/serial_core.h
3
 *
4
 *  Copyright (C) 2000 Deep Blue Solutions Ltd.
5
 *
6
 * This program is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 2 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 *
20
 *  $Id: serial_core.h,v 1.1 2004-01-28 15:26:38 giacomo Exp $
21
 */
22
 
23
/*
24
 * The type definitions.  These are from Ted Ts'o's serial.h
25
 */
26
#define PORT_UNKNOWN    0
27
#define PORT_8250       1
28
#define PORT_16450      2
29
#define PORT_16550      3
30
#define PORT_16550A     4
31
#define PORT_CIRRUS     5
32
#define PORT_16650      6
33
#define PORT_16650V2    7
34
#define PORT_16750      8
35
#define PORT_STARTECH   9
36
#define PORT_16C950     10
37
#define PORT_16654      11
38
#define PORT_16850      12
39
#define PORT_RSA        13
40
#define PORT_NS16550A   14
41
#define PORT_MAX_8250   14      /* max port ID */
42
 
43
/*
44
 * ARM specific type numbers.  These are not currently guaranteed
45
 * to be implemented, and will change in the future.  These are
46
 * separate so any additions to the old serial.c that occur before
47
 * we are merged can be easily merged here.
48
 */
49
#define PORT_AMBA       32
50
#define PORT_CLPS711X   33
51
#define PORT_SA1100     34
52
#define PORT_UART00     35
53
#define PORT_21285      37
54
 
55
/* Sparc type numbers.  */
56
#define PORT_SUNZILOG   38
57
#define PORT_SUNSAB     39
58
 
59
/* NEC v850.  */
60
#define PORT_V850E_UART 40
61
 
62
/* NEC PC-9800 */
63
#define PORT_8251_PC98  41
64
#define PORT_19K_PC98   42
65
#define PORT_FIFO_PC98  43
66
#define PORT_VFAST_PC98 44
67
#define PORT_PC9861     45
68
#define PORT_PC9801_101 46
69
 
70
/* DZ */
71
#define PORT_DZ         47
72
 
73
/* Parisc type numbers. */
74
#define PORT_MUX        48
75
 
76
/* Macintosh Zilog type numbers */
77
#define PORT_MAC_ZILOG  50      /* m68k : not yet implemented */
78
#define PORT_PMAC_ZILOG 51
79
 
80
#ifdef __KERNEL__
81
 
82
#include <linux/config.h>
83
#include <linux/interrupt.h>
84
#include <linux/circ_buf.h>
85
#include <linux/spinlock.h>
86
 
87
struct uart_port;
88
struct uart_info;
89
struct serial_struct;
90
 
91
/*
92
 * This structure describes all the operations that can be
93
 * done on the physical hardware.
94
 */
95
struct uart_ops {
96
        unsigned int    (*tx_empty)(struct uart_port *);
97
        void            (*set_mctrl)(struct uart_port *, unsigned int mctrl);
98
        unsigned int    (*get_mctrl)(struct uart_port *);
99
        void            (*stop_tx)(struct uart_port *, unsigned int tty_stop);
100
        void            (*start_tx)(struct uart_port *, unsigned int tty_start);
101
        void            (*send_xchar)(struct uart_port *, char ch);
102
        void            (*stop_rx)(struct uart_port *);
103
        void            (*enable_ms)(struct uart_port *);
104
        void            (*break_ctl)(struct uart_port *, int ctl);
105
        int             (*startup)(struct uart_port *);
106
        void            (*shutdown)(struct uart_port *);
107
        void            (*set_termios)(struct uart_port *, struct termios *new,
108
                                       struct termios *old);
109
        void            (*pm)(struct uart_port *, unsigned int state,
110
                              unsigned int oldstate);
111
        int             (*set_wake)(struct uart_port *, unsigned int state);
112
 
113
        /*
114
         * Return a string describing the type of the port
115
         */
116
        const char *(*type)(struct uart_port *);
117
 
118
        /*
119
         * Release IO and memory resources used by the port.
120
         * This includes iounmap if necessary.
121
         */
122
        void            (*release_port)(struct uart_port *);
123
 
124
        /*
125
         * Request IO and memory resources used by the port.
126
         * This includes iomapping the port if necessary.
127
         */
128
        int             (*request_port)(struct uart_port *);
129
        void            (*config_port)(struct uart_port *, int);
130
        int             (*verify_port)(struct uart_port *, struct serial_struct *);
131
        int             (*ioctl)(struct uart_port *, unsigned int, unsigned long);
132
};
133
 
134
#define UART_CONFIG_TYPE        (1 << 0)
135
#define UART_CONFIG_IRQ         (1 << 1)
136
 
137
struct uart_icount {
138
        __u32   cts;
139
        __u32   dsr;
140
        __u32   rng;
141
        __u32   dcd;
142
        __u32   rx;
143
        __u32   tx;
144
        __u32   frame;
145
        __u32   overrun;
146
        __u32   parity;
147
        __u32   brk;
148
        __u32   buf_overrun;
149
};
150
 
151
struct uart_port {
152
        spinlock_t              lock;                   /* port lock */
153
        unsigned int            iobase;                 /* in/out[bwl] */
154
        char                    *membase;               /* read/write[bwl] */
155
        unsigned int            irq;                    /* irq number */
156
        unsigned int            uartclk;                /* base uart clock */
157
        unsigned char           fifosize;               /* tx fifo size */
158
        unsigned char           x_char;                 /* xon/xoff char */
159
        unsigned char           regshift;               /* reg offset shift */
160
        unsigned char           iotype;                 /* io access style */
161
 
162
#define UPIO_PORT               (0)
163
#define UPIO_HUB6               (1)
164
#define UPIO_MEM                (2)
165
 
166
        unsigned int            read_status_mask;       /* driver specific */
167
        unsigned int            ignore_status_mask;     /* driver specific */
168
        struct uart_info        *info;                  /* pointer to parent info */
169
        struct uart_icount      icount;                 /* statistics */
170
 
171
        struct console          *cons;                  /* struct console, if any */
172
#ifdef CONFIG_SERIAL_CORE_CONSOLE
173
        unsigned long           sysrq;                  /* sysrq timeout */
174
#endif
175
 
176
        unsigned int            flags;
177
 
178
#define UPF_HUP_NOTIFY          (1 << 0)
179
#define UPF_FOURPORT            (1 << 1)
180
#define UPF_SAK                 (1 << 2)
181
#define UPF_SPD_MASK            (0x1030)
182
#define UPF_SPD_HI              (0x0010)
183
#define UPF_SPD_VHI             (0x0020)
184
#define UPF_SPD_CUST            (0x0030)
185
#define UPF_SPD_SHI             (0x1000)
186
#define UPF_SPD_WARP            (0x1010)
187
#define UPF_SKIP_TEST           (1 << 6)
188
#define UPF_AUTO_IRQ            (1 << 7)
189
#define UPF_HARDPPS_CD          (1 << 11)
190
#define UPF_LOW_LATENCY         (1 << 13)
191
#define UPF_BUGGY_UART          (1 << 14)
192
#define UPF_AUTOPROBE           (1 << 15)
193
#define UPF_MAGIC_MULTIPLIER    (1 << 16)
194
#define UPF_BOOT_ONLYMCA        (1 << 22)
195
#define UPF_CONS_FLOW           (1 << 23)
196
#define UPF_SHARE_IRQ           (1 << 24)
197
#define UPF_BOOT_AUTOCONF       (1 << 28)
198
#define UPF_RESOURCES           (1 << 30)
199
#define UPF_IOREMAP             (1 << 31)
200
 
201
#define UPF_CHANGE_MASK         (0x17fff)
202
#define UPF_USR_MASK            (UPF_SPD_MASK|UPF_LOW_LATENCY)
203
 
204
        unsigned int            mctrl;                  /* current modem ctrl settings */
205
        unsigned int            timeout;                /* character-based timeout */
206
        unsigned int            type;                   /* port type */
207
        struct uart_ops         *ops;
208
        unsigned int            custom_divisor;
209
        unsigned int            line;                   /* port index */
210
        unsigned long           mapbase;                /* for ioremap */
211
        unsigned char           hub6;                   /* this should be in the 8250 driver */
212
        unsigned char           unused[3];
213
};
214
 
215
/*
216
 * This is the state information which is persistent across opens.
217
 * The low level driver must not to touch any elements contained
218
 * within.
219
 */
220
struct uart_state {
221
        unsigned int            close_delay;
222
        unsigned int            closing_wait;
223
 
224
#define USF_CLOSING_WAIT_INF    (0)
225
#define USF_CLOSING_WAIT_NONE   (65535)
226
 
227
        int                     count;
228
        int                     pm_state;
229
        struct uart_info        *info;
230
        struct uart_port        *port;
231
 
232
        struct semaphore        sem;
233
};
234
 
235
#define UART_XMIT_SIZE 1024
236
/*
237
 * This is the state information which is only valid when the port
238
 * is open; it may be freed by the core driver once the device has
239
 * been closed.  Either the low level driver or the core can modify
240
 * stuff here.
241
 */
242
struct uart_info {
243
        struct tty_struct       *tty;
244
        struct circ_buf         xmit;
245
        unsigned int            flags;
246
 
247
/*
248
 * These are the flags that specific to info->flags, and reflect our
249
 * internal state.  They can not be accessed via port->flags.  Low
250
 * level drivers must not change these, but may query them instead.
251
 */
252
#define UIF_CHECK_CD            (1 << 25)
253
#define UIF_CTS_FLOW            (1 << 26)
254
#define UIF_NORMAL_ACTIVE       (1 << 29)
255
#define UIF_INITIALIZED         (1 << 31)
256
 
257
        unsigned char           *tmpbuf;
258
        struct semaphore        tmpbuf_sem;
259
 
260
        int                     blocked_open;
261
 
262
        struct tasklet_struct   tlet;
263
 
264
        wait_queue_head_t       open_wait;
265
        wait_queue_head_t       delta_msr_wait;
266
};
267
 
268
/* number of characters left in xmit buffer before we ask for more */
269
#define WAKEUP_CHARS            256
270
 
271
struct module;
272
struct tty_driver;
273
 
274
struct uart_driver {
275
        struct module           *owner;
276
        const char              *driver_name;
277
        const char              *dev_name;
278
        const char              *devfs_name;
279
        int                      major;
280
        int                      minor;
281
        int                      nr;
282
        struct console          *cons;
283
 
284
        /*
285
         * these are private; the low level driver should not
286
         * touch these; they should be initialised to NULL
287
         */
288
        struct uart_state       *state;
289
        struct tty_driver       *tty_driver;
290
};
291
 
292
void uart_write_wakeup(struct uart_port *port);
293
 
294
/*
295
 * Baud rate helpers.
296
 */
297
void uart_update_timeout(struct uart_port *port, unsigned int cflag,
298
                         unsigned int baud);
299
unsigned int uart_get_baud_rate(struct uart_port *port, struct termios *termios,
300
                                struct termios *old, unsigned int min,
301
                                unsigned int max);
302
unsigned int uart_get_divisor(struct uart_port *port, unsigned int baud);
303
 
304
/*
305
 * Console helpers.
306
 */
307
struct uart_port *uart_get_console(struct uart_port *ports, int nr,
308
                                   struct console *c);
309
void uart_parse_options(char *options, int *baud, int *parity, int *bits,
310
                        int *flow);
311
int uart_set_options(struct uart_port *port, struct console *co, int baud,
312
                     int parity, int bits, int flow);
313
struct tty_driver *uart_console_device(struct console *co, int *index);
314
 
315
/*
316
 * Port/driver registration/removal
317
 */
318
int uart_register_driver(struct uart_driver *uart);
319
void uart_unregister_driver(struct uart_driver *uart);
320
void uart_unregister_port(struct uart_driver *reg, int line);
321
int uart_register_port(struct uart_driver *reg, struct uart_port *port);
322
int uart_add_one_port(struct uart_driver *reg, struct uart_port *port);
323
int uart_remove_one_port(struct uart_driver *reg, struct uart_port *port);
324
 
325
/*
326
 * Power Management
327
 */
328
int uart_suspend_port(struct uart_driver *reg, struct uart_port *port);
329
int uart_resume_port(struct uart_driver *reg, struct uart_port *port);
330
 
331
#define uart_circ_empty(circ)           ((circ)->head == (circ)->tail)
332
#define uart_circ_clear(circ)           ((circ)->head = (circ)->tail = 0)
333
 
334
#define uart_circ_chars_pending(circ)   \
335
        (CIRC_CNT((circ)->head, (circ)->tail, UART_XMIT_SIZE))
336
 
337
#define uart_circ_chars_free(circ)      \
338
        (CIRC_SPACE((circ)->head, (circ)->tail, UART_XMIT_SIZE))
339
 
340
#define uart_tx_stopped(port)           \
341
        ((port)->info->tty->stopped || (port)->info->tty->hw_stopped)
342
 
343
/*
344
 * The following are helper functions for the low level drivers.
345
 */
346
#ifdef SUPPORT_SYSRQ
347
static inline int
348
uart_handle_sysrq_char(struct uart_port *port, unsigned int ch,
349
                       struct pt_regs *regs)
350
{
351
        if (port->sysrq) {
352
                if (ch && time_before(jiffies, port->sysrq)) {
353
                        handle_sysrq(ch, regs, NULL);
354
                        port->sysrq = 0;
355
                        return 1;
356
                }
357
                port->sysrq = 0;
358
        }
359
        return 0;
360
}
361
#else
362
#define uart_handle_sysrq_char(port,ch,regs)    (0)
363
#endif
364
 
365
/*
366
 * We do the SysRQ and SAK checking like this...
367
 */
368
static inline int uart_handle_break(struct uart_port *port)
369
{
370
        struct uart_info *info = port->info;
371
#ifdef SUPPORT_SYSRQ
372
        if (port->cons && port->cons->index == port->line) {
373
                if (!port->sysrq) {
374
                        port->sysrq = jiffies + HZ*5;
375
                        return 1;
376
                }
377
                port->sysrq = 0;
378
        }
379
#endif
380
        if (info->flags & UPF_SAK)
381
                do_SAK(info->tty);
382
        return 0;
383
}
384
 
385
/**
386
 *      uart_handle_dcd_change - handle a change of carrier detect state
387
 *      @port: uart_port structure for the open port
388
 *      @status: new carrier detect status, nonzero if active
389
 */
390
static inline void
391
uart_handle_dcd_change(struct uart_port *port, unsigned int status)
392
{
393
        struct uart_info *info = port->info;
394
 
395
        port->icount.dcd++;
396
 
397
#ifdef CONFIG_HARD_PPS
398
        if ((port->flags & UPF_HARDPPS_CD) && status)
399
                hardpps();
400
#endif
401
 
402
        if (info->flags & UIF_CHECK_CD) {
403
                if (status)
404
                        wake_up_interruptible(&info->open_wait);
405
                else if (info->tty)
406
                        tty_hangup(info->tty);
407
        }
408
}
409
 
410
/**
411
 *      uart_handle_cts_change - handle a change of clear-to-send state
412
 *      @port: uart_port structure for the open port
413
 *      @status: new clear to send status, nonzero if active
414
 */
415
static inline void
416
uart_handle_cts_change(struct uart_port *port, unsigned int status)
417
{
418
        struct uart_info *info = port->info;
419
        struct tty_struct *tty = info->tty;
420
 
421
        port->icount.cts++;
422
 
423
        if (info->flags & UIF_CTS_FLOW) {
424
                if (tty->hw_stopped) {
425
                        if (status) {
426
                                tty->hw_stopped = 0;
427
                                port->ops->start_tx(port, 0);
428
                                uart_write_wakeup(port);
429
                        }
430
                } else {
431
                        if (!status) {
432
                                tty->hw_stopped = 1;
433
                                port->ops->stop_tx(port, 0);
434
                        }
435
                }
436
        }
437
}
438
 
439
/*
440
 *      UART_ENABLE_MS - determine if port should enable modem status irqs
441
 */
442
#define UART_ENABLE_MS(port,cflag)      ((port)->flags & UPF_HARDPPS_CD || \
443
                                         (cflag) & CRTSCTS || \
444
                                         !((cflag) & CLOCAL))
445
 
446
#endif