Replace the bubble sort in sanitize_e820_map() with a call to the generic
[linux-2.6/next.git] / arch / blackfin / include / asm / bfin_serial.h
blobecacdf34768b593b0e43e91c2314927cde723e83
1 /*
2 * bfin_serial.h - Blackfin UART/Serial definitions
4 * Copyright 2006-2010 Analog Devices Inc.
6 * Licensed under the GPL-2 or later.
7 */
9 #ifndef __BFIN_ASM_SERIAL_H__
10 #define __BFIN_ASM_SERIAL_H__
12 #include <linux/serial_core.h>
13 #include <linux/spinlock.h>
14 #include <mach/anomaly.h>
15 #include <mach/bfin_serial.h>
17 #if defined(CONFIG_BFIN_UART0_CTSRTS) || \
18 defined(CONFIG_BFIN_UART1_CTSRTS) || \
19 defined(CONFIG_BFIN_UART2_CTSRTS) || \
20 defined(CONFIG_BFIN_UART3_CTSRTS)
21 # ifdef BFIN_UART_BF54X_STYLE
22 # define CONFIG_SERIAL_BFIN_HARD_CTSRTS
23 # else
24 # define CONFIG_SERIAL_BFIN_CTSRTS
25 # endif
26 #endif
28 struct circ_buf;
29 struct timer_list;
30 struct work_struct;
32 struct bfin_serial_port {
33 struct uart_port port;
34 unsigned int old_status;
35 int tx_irq;
36 int rx_irq;
37 int status_irq;
38 #ifndef BFIN_UART_BF54X_STYLE
39 unsigned int lsr;
40 #endif
41 #ifdef CONFIG_SERIAL_BFIN_DMA
42 int tx_done;
43 int tx_count;
44 struct circ_buf rx_dma_buf;
45 struct timer_list rx_dma_timer;
46 int rx_dma_nrows;
47 spinlock_t rx_lock;
48 unsigned int tx_dma_channel;
49 unsigned int rx_dma_channel;
50 struct work_struct tx_dma_workqueue;
51 #elif ANOMALY_05000363
52 unsigned int anomaly_threshold;
53 #endif
54 #ifdef CONFIG_SERIAL_BFIN_HARD_CTSRTS
55 int scts;
56 #endif
57 #if defined(CONFIG_SERIAL_BFIN_CTSRTS) || \
58 defined(CONFIG_SERIAL_BFIN_HARD_CTSRTS)
59 int cts_pin;
60 int rts_pin;
61 #endif
64 /* UART_LCR Masks */
65 #define WLS(x) (((x)-5) & 0x03) /* Word Length Select */
66 #define STB 0x04 /* Stop Bits */
67 #define PEN 0x08 /* Parity Enable */
68 #define EPS 0x10 /* Even Parity Select */
69 #define STP 0x20 /* Stick Parity */
70 #define SB 0x40 /* Set Break */
71 #define DLAB 0x80 /* Divisor Latch Access */
73 /* UART_LSR Masks */
74 #define DR 0x01 /* Data Ready */
75 #define OE 0x02 /* Overrun Error */
76 #define PE 0x04 /* Parity Error */
77 #define FE 0x08 /* Framing Error */
78 #define BI 0x10 /* Break Interrupt */
79 #define THRE 0x20 /* THR Empty */
80 #define TEMT 0x40 /* TSR and UART_THR Empty */
81 #define TFI 0x80 /* Transmission Finished Indicator */
83 /* UART_IER Masks */
84 #define ERBFI 0x01 /* Enable Receive Buffer Full Interrupt */
85 #define ETBEI 0x02 /* Enable Transmit Buffer Empty Interrupt */
86 #define ELSI 0x04 /* Enable RX Status Interrupt */
87 #define EDSSI 0x08 /* Enable Modem Status Interrupt */
88 #define EDTPTI 0x10 /* Enable DMA Transmit PIRQ Interrupt */
89 #define ETFI 0x20 /* Enable Transmission Finished Interrupt */
90 #define ERFCI 0x40 /* Enable Receive FIFO Count Interrupt */
92 /* UART_MCR Masks */
93 #define XOFF 0x01 /* Transmitter Off */
94 #define MRTS 0x02 /* Manual Request To Send */
95 #define RFIT 0x04 /* Receive FIFO IRQ Threshold */
96 #define RFRT 0x08 /* Receive FIFO RTS Threshold */
97 #define LOOP_ENA 0x10 /* Loopback Mode Enable */
98 #define FCPOL 0x20 /* Flow Control Pin Polarity */
99 #define ARTS 0x40 /* Automatic Request To Send */
100 #define ACTS 0x80 /* Automatic Clear To Send */
102 /* UART_MSR Masks */
103 #define SCTS 0x01 /* Sticky CTS */
104 #define CTS 0x10 /* Clear To Send */
105 #define RFCS 0x20 /* Receive FIFO Count Status */
107 /* UART_GCTL Masks */
108 #define UCEN 0x01 /* Enable UARTx Clocks */
109 #define IREN 0x02 /* Enable IrDA Mode */
110 #define TPOLC 0x04 /* IrDA TX Polarity Change */
111 #define RPOLC 0x08 /* IrDA RX Polarity Change */
112 #define FPE 0x10 /* Force Parity Error On Transmit */
113 #define FFE 0x20 /* Force Framing Error On Transmit */
115 #ifdef BFIN_UART_BF54X_STYLE
116 # define OFFSET_DLL 0x00 /* Divisor Latch (Low-Byte) */
117 # define OFFSET_DLH 0x04 /* Divisor Latch (High-Byte) */
118 # define OFFSET_GCTL 0x08 /* Global Control Register */
119 # define OFFSET_LCR 0x0C /* Line Control Register */
120 # define OFFSET_MCR 0x10 /* Modem Control Register */
121 # define OFFSET_LSR 0x14 /* Line Status Register */
122 # define OFFSET_MSR 0x18 /* Modem Status Register */
123 # define OFFSET_SCR 0x1C /* SCR Scratch Register */
124 # define OFFSET_IER_SET 0x20 /* Set Interrupt Enable Register */
125 # define OFFSET_IER_CLEAR 0x24 /* Clear Interrupt Enable Register */
126 # define OFFSET_THR 0x28 /* Transmit Holding register */
127 # define OFFSET_RBR 0x2C /* Receive Buffer register */
128 #else /* BF533 style */
129 # define OFFSET_THR 0x00 /* Transmit Holding register */
130 # define OFFSET_RBR 0x00 /* Receive Buffer register */
131 # define OFFSET_DLL 0x00 /* Divisor Latch (Low-Byte) */
132 # define OFFSET_DLH 0x04 /* Divisor Latch (High-Byte) */
133 # define OFFSET_IER 0x04 /* Interrupt Enable Register */
134 # define OFFSET_IIR 0x08 /* Interrupt Identification Register */
135 # define OFFSET_LCR 0x0C /* Line Control Register */
136 # define OFFSET_MCR 0x10 /* Modem Control Register */
137 # define OFFSET_LSR 0x14 /* Line Status Register */
138 # define OFFSET_MSR 0x18 /* Modem Status Register */
139 # define OFFSET_SCR 0x1C /* SCR Scratch Register */
140 # define OFFSET_GCTL 0x24 /* Global Control Register */
141 /* code should not need IIR, so force build error if they use it */
142 # undef OFFSET_IIR
143 #endif
146 * All Blackfin system MMRs are padded to 32bits even if the register
147 * itself is only 16bits. So use a helper macro to streamline this.
149 #define __BFP(m) u16 m; u16 __pad_##m
150 struct bfin_uart_regs {
151 #ifdef BFIN_UART_BF54X_STYLE
152 __BFP(dll);
153 __BFP(dlh);
154 __BFP(gctl);
155 __BFP(lcr);
156 __BFP(mcr);
157 __BFP(lsr);
158 __BFP(msr);
159 __BFP(scr);
160 __BFP(ier_set);
161 __BFP(ier_clear);
162 __BFP(thr);
163 __BFP(rbr);
164 #else
165 union {
166 u16 dll;
167 u16 thr;
168 const u16 rbr;
170 const u16 __pad0;
171 union {
172 u16 dlh;
173 u16 ier;
175 const u16 __pad1;
176 const __BFP(iir);
177 __BFP(lcr);
178 __BFP(mcr);
179 __BFP(lsr);
180 __BFP(msr);
181 __BFP(scr);
182 const u32 __pad2;
183 __BFP(gctl);
184 #endif
186 #undef __BFP
188 #ifndef port_membase
189 # define port_membase(p) 0
190 #endif
192 #define UART_GET_CHAR(p) bfin_read16(port_membase(p) + OFFSET_RBR)
193 #define UART_GET_DLL(p) bfin_read16(port_membase(p) + OFFSET_DLL)
194 #define UART_GET_DLH(p) bfin_read16(port_membase(p) + OFFSET_DLH)
195 #define UART_GET_GCTL(p) bfin_read16(port_membase(p) + OFFSET_GCTL)
196 #define UART_GET_LCR(p) bfin_read16(port_membase(p) + OFFSET_LCR)
197 #define UART_GET_MCR(p) bfin_read16(port_membase(p) + OFFSET_MCR)
198 #define UART_GET_MSR(p) bfin_read16(port_membase(p) + OFFSET_MSR)
200 #define UART_PUT_CHAR(p, v) bfin_write16(port_membase(p) + OFFSET_THR, v)
201 #define UART_PUT_DLL(p, v) bfin_write16(port_membase(p) + OFFSET_DLL, v)
202 #define UART_PUT_DLH(p, v) bfin_write16(port_membase(p) + OFFSET_DLH, v)
203 #define UART_PUT_GCTL(p, v) bfin_write16(port_membase(p) + OFFSET_GCTL, v)
204 #define UART_PUT_LCR(p, v) bfin_write16(port_membase(p) + OFFSET_LCR, v)
205 #define UART_PUT_MCR(p, v) bfin_write16(port_membase(p) + OFFSET_MCR, v)
207 #ifdef BFIN_UART_BF54X_STYLE
209 #define UART_CLEAR_IER(p, v) bfin_write16(port_membase(p) + OFFSET_IER_CLEAR, v)
210 #define UART_GET_IER(p) bfin_read16(port_membase(p) + OFFSET_IER_SET)
211 #define UART_SET_IER(p, v) bfin_write16(port_membase(p) + OFFSET_IER_SET, v)
213 #define UART_CLEAR_DLAB(p) /* MMRs not muxed on BF54x */
214 #define UART_SET_DLAB(p) /* MMRs not muxed on BF54x */
216 #define UART_CLEAR_LSR(p) bfin_write16(port_membase(p) + OFFSET_LSR, -1)
217 #define UART_GET_LSR(p) bfin_read16(port_membase(p) + OFFSET_LSR)
218 #define UART_PUT_LSR(p, v) bfin_write16(port_membase(p) + OFFSET_LSR, v)
220 /* This handles hard CTS/RTS */
221 #define BFIN_UART_CTSRTS_HARD
222 #define UART_CLEAR_SCTS(p) bfin_write16((port_membase(p) + OFFSET_MSR), SCTS)
223 #define UART_GET_CTS(x) (UART_GET_MSR(x) & CTS)
224 #define UART_DISABLE_RTS(x) UART_PUT_MCR(x, UART_GET_MCR(x) & ~(ARTS | MRTS))
225 #define UART_ENABLE_RTS(x) UART_PUT_MCR(x, UART_GET_MCR(x) | MRTS | ARTS)
226 #define UART_ENABLE_INTS(x, v) UART_SET_IER(x, v)
227 #define UART_DISABLE_INTS(x) UART_CLEAR_IER(x, 0xF)
229 #else /* BF533 style */
231 #define UART_CLEAR_IER(p, v) UART_PUT_IER(p, UART_GET_IER(p) & ~(v))
232 #define UART_GET_IER(p) bfin_read16(port_membase(p) + OFFSET_IER)
233 #define UART_PUT_IER(p, v) bfin_write16(port_membase(p) + OFFSET_IER, v)
234 #define UART_SET_IER(p, v) UART_PUT_IER(p, UART_GET_IER(p) | (v))
236 #define UART_CLEAR_DLAB(p) do { UART_PUT_LCR(p, UART_GET_LCR(p) & ~DLAB); SSYNC(); } while (0)
237 #define UART_SET_DLAB(p) do { UART_PUT_LCR(p, UART_GET_LCR(p) | DLAB); SSYNC(); } while (0)
239 #ifndef put_lsr_cache
240 # define put_lsr_cache(p, v)
241 #endif
242 #ifndef get_lsr_cache
243 # define get_lsr_cache(p) 0
244 #endif
246 /* The hardware clears the LSR bits upon read, so we need to cache
247 * some of the more fun bits in software so they don't get lost
248 * when checking the LSR in other code paths (TX).
250 static inline void UART_CLEAR_LSR(void *p)
252 put_lsr_cache(p, 0);
253 bfin_write16(port_membase(p) + OFFSET_LSR, -1);
255 static inline unsigned int UART_GET_LSR(void *p)
257 unsigned int lsr = bfin_read16(port_membase(p) + OFFSET_LSR);
258 put_lsr_cache(p, get_lsr_cache(p) | (lsr & (BI|FE|PE|OE)));
259 return lsr | get_lsr_cache(p);
261 static inline void UART_PUT_LSR(void *p, uint16_t val)
263 put_lsr_cache(p, get_lsr_cache(p) & ~val);
266 /* This handles soft CTS/RTS */
267 #define UART_GET_CTS(x) gpio_get_value((x)->cts_pin)
268 #define UART_DISABLE_RTS(x) gpio_set_value((x)->rts_pin, 1)
269 #define UART_ENABLE_RTS(x) gpio_set_value((x)->rts_pin, 0)
270 #define UART_ENABLE_INTS(x, v) UART_PUT_IER(x, v)
271 #define UART_DISABLE_INTS(x) UART_PUT_IER(x, 0)
273 #endif
275 #ifndef BFIN_UART_TX_FIFO_SIZE
276 # define BFIN_UART_TX_FIFO_SIZE 2
277 #endif
279 #endif /* __BFIN_ASM_SERIAL_H__ */