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