OSDN Git Service

tty: serial: 8250: allow to use custom DMA implementation
[uclinux-h8/linux.git] / drivers / tty / serial / 8250 / 8250.h
1 /*
2  *  Driver for 8250/16550-type serial ports
3  *
4  *  Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
5  *
6  *  Copyright (C) 2001 Russell King.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  */
13
14 #include <linux/serial_8250.h>
15 #include <linux/serial_reg.h>
16 #include <linux/dmaengine.h>
17
18 struct uart_8250_dma {
19         int (*tx_dma)(struct uart_8250_port *p);
20         int (*rx_dma)(struct uart_8250_port *p, unsigned int iir);
21
22         /* Filter function */
23         dma_filter_fn           fn;
24
25         /* Parameter to the filter function */
26         void                    *rx_param;
27         void                    *tx_param;
28
29         struct dma_slave_config rxconf;
30         struct dma_slave_config txconf;
31
32         struct dma_chan         *rxchan;
33         struct dma_chan         *txchan;
34
35         dma_addr_t              rx_addr;
36         dma_addr_t              tx_addr;
37
38         dma_cookie_t            rx_cookie;
39         dma_cookie_t            tx_cookie;
40
41         void                    *rx_buf;
42
43         size_t                  rx_size;
44         size_t                  tx_size;
45
46         unsigned char           tx_running:1;
47         unsigned char           tx_err: 1;
48         unsigned char           rx_running:1;
49 };
50
51 struct old_serial_port {
52         unsigned int uart;
53         unsigned int baud_base;
54         unsigned int port;
55         unsigned int irq;
56         unsigned int flags;
57         unsigned char hub6;
58         unsigned char io_type;
59         unsigned char *iomem_base;
60         unsigned short iomem_reg_shift;
61         unsigned long irqflags;
62 };
63
64 struct serial8250_config {
65         const char      *name;
66         unsigned short  fifo_size;
67         unsigned short  tx_loadsz;
68         unsigned char   fcr;
69         unsigned char   rxtrig_bytes[UART_FCR_R_TRIG_MAX_STATE];
70         unsigned int    flags;
71 };
72
73 #define UART_CAP_FIFO   (1 << 8)        /* UART has FIFO */
74 #define UART_CAP_EFR    (1 << 9)        /* UART has EFR */
75 #define UART_CAP_SLEEP  (1 << 10)       /* UART has IER sleep */
76 #define UART_CAP_AFE    (1 << 11)       /* MCR-based hw flow control */
77 #define UART_CAP_UUE    (1 << 12)       /* UART needs IER bit 6 set (Xscale) */
78 #define UART_CAP_RTOIE  (1 << 13)       /* UART needs IER bit 4 set (Xscale, Tegra) */
79 #define UART_CAP_HFIFO  (1 << 14)       /* UART has a "hidden" FIFO */
80 #define UART_CAP_RPM    (1 << 15)       /* Runtime PM is active while idle */
81
82 #define UART_BUG_QUOT   (1 << 0)        /* UART has buggy quot LSB */
83 #define UART_BUG_TXEN   (1 << 1)        /* UART has buggy TX IIR status */
84 #define UART_BUG_NOMSR  (1 << 2)        /* UART has buggy MSR status bits (Au1x00) */
85 #define UART_BUG_THRE   (1 << 3)        /* UART has buggy THRE reassertion */
86 #define UART_BUG_PARITY (1 << 4)        /* UART mishandles parity if FIFO enabled */
87
88 #define PROBE_RSA       (1 << 0)
89 #define PROBE_ANY       (~0)
90
91 #define HIGH_BITS_OFFSET ((sizeof(long)-sizeof(int))*8)
92
93 #ifdef CONFIG_SERIAL_8250_SHARE_IRQ
94 #define SERIAL8250_SHARE_IRQS 1
95 #else
96 #define SERIAL8250_SHARE_IRQS 0
97 #endif
98
99 static inline int serial_in(struct uart_8250_port *up, int offset)
100 {
101         return up->port.serial_in(&up->port, offset);
102 }
103
104 static inline void serial_out(struct uart_8250_port *up, int offset, int value)
105 {
106         up->port.serial_out(&up->port, offset, value);
107 }
108
109 void serial8250_clear_and_reinit_fifos(struct uart_8250_port *p);
110
111 static inline int serial_dl_read(struct uart_8250_port *up)
112 {
113         return up->dl_read(up);
114 }
115
116 static inline void serial_dl_write(struct uart_8250_port *up, int value)
117 {
118         up->dl_write(up, value);
119 }
120
121 struct uart_8250_port *serial8250_get_port(int line);
122
123 #if defined(__alpha__) && !defined(CONFIG_PCI)
124 /*
125  * Digital did something really horribly wrong with the OUT1 and OUT2
126  * lines on at least some ALPHA's.  The failure mode is that if either
127  * is cleared, the machine locks up with endless interrupts.
128  */
129 #define ALPHA_KLUDGE_MCR  (UART_MCR_OUT2 | UART_MCR_OUT1)
130 #else
131 #define ALPHA_KLUDGE_MCR 0
132 #endif
133
134 #ifdef CONFIG_SERIAL_8250_PNP
135 int serial8250_pnp_init(void);
136 void serial8250_pnp_exit(void);
137 #else
138 static inline int serial8250_pnp_init(void) { return 0; }
139 static inline void serial8250_pnp_exit(void) { }
140 #endif
141
142 #ifdef CONFIG_ARCH_OMAP1
143 static inline int is_omap1_8250(struct uart_8250_port *pt)
144 {
145         int res;
146
147         switch (pt->port.mapbase) {
148         case OMAP1_UART1_BASE:
149         case OMAP1_UART2_BASE:
150         case OMAP1_UART3_BASE:
151                 res = 1;
152                 break;
153         default:
154                 res = 0;
155                 break;
156         }
157
158         return res;
159 }
160
161 static inline int is_omap1510_8250(struct uart_8250_port *pt)
162 {
163         if (!cpu_is_omap1510())
164                 return 0;
165
166         return is_omap1_8250(pt);
167 }
168 #else
169 static inline int is_omap1_8250(struct uart_8250_port *pt)
170 {
171         return 0;
172 }
173 static inline int is_omap1510_8250(struct uart_8250_port *pt)
174 {
175         return 0;
176 }
177 #endif
178
179 #ifdef CONFIG_SERIAL_8250_DMA
180 extern int serial8250_tx_dma(struct uart_8250_port *);
181 extern int serial8250_rx_dma(struct uart_8250_port *, unsigned int iir);
182 extern int serial8250_request_dma(struct uart_8250_port *);
183 extern void serial8250_release_dma(struct uart_8250_port *);
184 #else
185 static inline int serial8250_tx_dma(struct uart_8250_port *p)
186 {
187         return -1;
188 }
189 static inline int serial8250_rx_dma(struct uart_8250_port *p, unsigned int iir)
190 {
191         return -1;
192 }
193 static inline int serial8250_request_dma(struct uart_8250_port *p)
194 {
195         return -1;
196 }
197 static inline void serial8250_release_dma(struct uart_8250_port *p) { }
198 #endif