1
2
3
4
5
6
7
8
9#ifndef __BFIN_ASM_SERIAL_H__
10#define __BFIN_ASM_SERIAL_H__
11
12#include <linux/serial_core.h>
13#include <linux/spinlock.h>
14#include <mach/anomaly.h>
15#include <mach/bfin_serial.h>
16
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# if defined(BFIN_UART_BF54X_STYLE) || defined(BFIN_UART_BF60X_STYLE)
22# define CONFIG_SERIAL_BFIN_HARD_CTSRTS
23# else
24# define CONFIG_SERIAL_BFIN_CTSRTS
25# endif
26#endif
27
28struct circ_buf;
29struct timer_list;
30struct work_struct;
31
32struct 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#if defined(CONFIG_SERIAL_BFIN_CTSRTS) || \
55 defined(CONFIG_SERIAL_BFIN_HARD_CTSRTS)
56 int cts_pin;
57 int rts_pin;
58#endif
59};
60
61#ifdef BFIN_UART_BF60X_STYLE
62
63
64#define UCEN 0x1
65#define LOOP_ENA 0x2
66#define UMOD_MDB 0x10
67#define UMOD_IRDA 0x20
68#define UMOD_MASK 0x30
69#define WLS(x) (((x-5) & 0x03) << 8)
70#define WLS_MASK 0x300
71#define WLS_OFFSET 8
72#define STB 0x1000
73#define STBH 0x2000
74#define PEN 0x4000
75#define EPS 0x8000
76#define STP 0x10000
77#define FPE 0x20000
78#define FFE 0x40000
79#define SB 0x80000
80#define LCR_MASK (SB | STP | EPS | PEN | STB | WLS_MASK)
81#define FCPOL 0x400000
82#define RPOLC 0x800000
83#define TPOLC 0x1000000
84#define MRTS 0x2000000
85#define XOFF 0x4000000
86#define ARTS 0x8000000
87#define ACTS 0x10000000
88#define RFIT 0x20000000
89#define RFRT 0x40000000
90
91
92#define DR 0x01
93#define OE 0x02
94#define PE 0x04
95#define FE 0x08
96#define BI 0x10
97#define THRE 0x20
98#define TEMT 0x80
99#define TFI 0x100
100
101#define ASTKY 0x200
102#define ADDR 0x400
103#define RO 0x800
104#define SCTS 0x1000
105#define CTS 0x10000
106#define RFCS 0x20000
107
108
109#define EDBO 0x80000000
110
111#else
112
113
114#define WLS(x) (((x)-5) & 0x03)
115#define WLS_MASK 0x03
116#define WLS_OFFSET 0
117#define STB 0x04
118#define PEN 0x08
119#define EPS 0x10
120#define STP 0x20
121#define SB 0x40
122#define DLAB 0x80
123#define LCR_MASK (SB | STP | EPS | PEN | STB | WLS_MASK)
124
125
126#define DR 0x01
127#define OE 0x02
128#define PE 0x04
129#define FE 0x08
130#define BI 0x10
131#define THRE 0x20
132#define TEMT 0x40
133#define TFI 0x80
134
135
136#define XOFF 0x01
137#define MRTS 0x02
138#define RFIT 0x04
139#define RFRT 0x08
140#define LOOP_ENA 0x10
141#define FCPOL 0x20
142#define ARTS 0x40
143#define ACTS 0x80
144
145
146#define SCTS 0x01
147#define CTS 0x10
148#define RFCS 0x20
149
150
151#define UCEN 0x01
152#define UMOD_IRDA 0x02
153#define UMOD_MASK 0x02
154#define TPOLC 0x04
155#define RPOLC 0x08
156#define FPE 0x10
157#define FFE 0x20
158
159#endif
160
161
162#define ERBFI 0x01
163#define ETBEI 0x02
164#define ELSI 0x04
165#define EDSSI 0x08
166#define EDTPTI 0x10
167#define ETFI 0x20
168#define ERFCI 0x40
169
170#if defined(BFIN_UART_BF60X_STYLE)
171# define OFFSET_REDIV 0x00
172# define OFFSET_CTL 0x04
173# define OFFSET_STAT 0x08
174# define OFFSET_SCR 0x0C
175# define OFFSET_CLK 0x10
176# define OFFSET_IER 0x14
177# define OFFSET_IER_SET 0x18
178# define OFFSET_IER_CLEAR 0x1C
179# define OFFSET_RBR 0x20
180# define OFFSET_THR 0x24
181#elif defined(BFIN_UART_BF54X_STYLE)
182# define OFFSET_DLL 0x00
183# define OFFSET_DLH 0x04
184# define OFFSET_GCTL 0x08
185# define OFFSET_LCR 0x0C
186# define OFFSET_MCR 0x10
187# define OFFSET_LSR 0x14
188# define OFFSET_MSR 0x18
189# define OFFSET_SCR 0x1C
190# define OFFSET_IER_SET 0x20
191# define OFFSET_IER_CLEAR 0x24
192# define OFFSET_THR 0x28
193# define OFFSET_RBR 0x2C
194#else
195# define OFFSET_THR 0x00
196# define OFFSET_RBR 0x00
197# define OFFSET_DLL 0x00
198# define OFFSET_DLH 0x04
199# define OFFSET_IER 0x04
200# define OFFSET_IIR 0x08
201# define OFFSET_LCR 0x0C
202# define OFFSET_MCR 0x10
203# define OFFSET_LSR 0x14
204# define OFFSET_MSR 0x18
205# define OFFSET_SCR 0x1C
206# define OFFSET_GCTL 0x24
207
208# undef OFFSET_IIR
209#endif
210
211
212
213
214
215#define __BFP(m) u16 m; u16 __pad_##m
216struct bfin_uart_regs {
217#if defined(BFIN_UART_BF60X_STYLE)
218 u32 revid;
219 u32 ctl;
220 u32 stat;
221 u32 scr;
222 u32 clk;
223 u32 ier;
224 u32 ier_set;
225 u32 ier_clear;
226 u32 rbr;
227 u32 thr;
228 u32 taip;
229 u32 tsr;
230 u32 rsr;
231 u32 txdiv;
232 u32 rxdiv;
233#elif defined(BFIN_UART_BF54X_STYLE)
234 __BFP(dll);
235 __BFP(dlh);
236 __BFP(gctl);
237 __BFP(lcr);
238 __BFP(mcr);
239 __BFP(lsr);
240 __BFP(msr);
241 __BFP(scr);
242 __BFP(ier_set);
243 __BFP(ier_clear);
244 __BFP(thr);
245 __BFP(rbr);
246#else
247 union {
248 u16 dll;
249 u16 thr;
250 const u16 rbr;
251 };
252 const u16 __pad0;
253 union {
254 u16 dlh;
255 u16 ier;
256 };
257 const u16 __pad1;
258 const __BFP(iir);
259 __BFP(lcr);
260 __BFP(mcr);
261 __BFP(lsr);
262 __BFP(msr);
263 __BFP(scr);
264 const u32 __pad2;
265 __BFP(gctl);
266#endif
267};
268#undef __BFP
269
270#define port_membase(uart) (((struct bfin_serial_port *)(uart))->port.membase)
271
272
273
274
275
276
277#ifdef BFIN_UART_BF60X_STYLE
278
279#define UART_GET_CHAR(p) bfin_read32(port_membase(p) + OFFSET_RBR)
280#define UART_GET_CLK(p) bfin_read32(port_membase(p) + OFFSET_CLK)
281#define UART_GET_CTL(p) bfin_read32(port_membase(p) + OFFSET_CTL)
282#define UART_GET_GCTL(p) UART_GET_CTL(p)
283#define UART_GET_LCR(p) UART_GET_CTL(p)
284#define UART_GET_MCR(p) UART_GET_CTL(p)
285#if ANOMALY_16000030
286#define UART_GET_STAT(p) \
287({ \
288 u32 __ret; \
289 unsigned long flags; \
290 flags = hard_local_irq_save(); \
291 __ret = bfin_read32(port_membase(p) + OFFSET_STAT); \
292 hard_local_irq_restore(flags); \
293 __ret; \
294})
295#else
296#define UART_GET_STAT(p) bfin_read32(port_membase(p) + OFFSET_STAT)
297#endif
298#define UART_GET_MSR(p) UART_GET_STAT(p)
299
300#define UART_PUT_CHAR(p, v) bfin_write32(port_membase(p) + OFFSET_THR, v)
301#define UART_PUT_CLK(p, v) bfin_write32(port_membase(p) + OFFSET_CLK, v)
302#define UART_PUT_CTL(p, v) bfin_write32(port_membase(p) + OFFSET_CTL, v)
303#define UART_PUT_GCTL(p, v) UART_PUT_CTL(p, v)
304#define UART_PUT_LCR(p, v) UART_PUT_CTL(p, v)
305#define UART_PUT_MCR(p, v) UART_PUT_CTL(p, v)
306#define UART_PUT_STAT(p, v) bfin_write32(port_membase(p) + OFFSET_STAT, v)
307
308#define UART_CLEAR_IER(p, v) bfin_write32(port_membase(p) + OFFSET_IER_CLEAR, v)
309#define UART_GET_IER(p) bfin_read32(port_membase(p) + OFFSET_IER)
310#define UART_SET_IER(p, v) bfin_write32(port_membase(p) + OFFSET_IER_SET, v)
311
312#define UART_CLEAR_DLAB(p)
313#define UART_SET_DLAB(p)
314
315#define UART_CLEAR_LSR(p) UART_PUT_STAT(p, -1)
316#define UART_GET_LSR(p) UART_GET_STAT(p)
317#define UART_PUT_LSR(p, v) UART_PUT_STAT(p, v)
318
319
320#define BFIN_UART_CTSRTS_HARD
321#define UART_CLEAR_SCTS(p) UART_PUT_STAT(p, SCTS)
322#define UART_GET_CTS(x) (UART_GET_MSR(x) & CTS)
323#define UART_DISABLE_RTS(x) UART_PUT_MCR(x, UART_GET_MCR(x) & ~(ARTS | MRTS))
324#define UART_ENABLE_RTS(x) UART_PUT_MCR(x, UART_GET_MCR(x) | MRTS | ARTS)
325#define UART_ENABLE_INTS(x, v) UART_SET_IER(x, v)
326#define UART_DISABLE_INTS(x) UART_CLEAR_IER(x, 0xF)
327
328#else
329
330#define UART_GET_CHAR(p) bfin_read16(port_membase(p) + OFFSET_RBR)
331#define UART_GET_DLL(p) bfin_read16(port_membase(p) + OFFSET_DLL)
332#define UART_GET_DLH(p) bfin_read16(port_membase(p) + OFFSET_DLH)
333#define UART_GET_CLK(p) ((UART_GET_DLH(p) << 8) | UART_GET_DLL(p))
334#define UART_GET_GCTL(p) bfin_read16(port_membase(p) + OFFSET_GCTL)
335#define UART_GET_LCR(p) bfin_read16(port_membase(p) + OFFSET_LCR)
336#define UART_GET_MCR(p) bfin_read16(port_membase(p) + OFFSET_MCR)
337#define UART_GET_MSR(p) bfin_read16(port_membase(p) + OFFSET_MSR)
338
339#define UART_PUT_CHAR(p, v) bfin_write16(port_membase(p) + OFFSET_THR, v)
340#define UART_PUT_DLL(p, v) bfin_write16(port_membase(p) + OFFSET_DLL, v)
341#define UART_PUT_DLH(p, v) bfin_write16(port_membase(p) + OFFSET_DLH, v)
342#define UART_PUT_CLK(p, v) do \
343{\
344UART_PUT_DLL(p, v & 0xFF); \
345UART_PUT_DLH(p, (v >> 8) & 0xFF); } while (0);
346
347#define UART_PUT_GCTL(p, v) bfin_write16(port_membase(p) + OFFSET_GCTL, v)
348#define UART_PUT_LCR(p, v) bfin_write16(port_membase(p) + OFFSET_LCR, v)
349#define UART_PUT_MCR(p, v) bfin_write16(port_membase(p) + OFFSET_MCR, v)
350
351#ifdef BFIN_UART_BF54X_STYLE
352
353#define UART_CLEAR_IER(p, v) bfin_write16(port_membase(p) + OFFSET_IER_CLEAR, v)
354#define UART_GET_IER(p) bfin_read16(port_membase(p) + OFFSET_IER_SET)
355#define UART_SET_IER(p, v) bfin_write16(port_membase(p) + OFFSET_IER_SET, v)
356
357#define UART_CLEAR_DLAB(p)
358#define UART_SET_DLAB(p)
359
360#define UART_CLEAR_LSR(p) bfin_write16(port_membase(p) + OFFSET_LSR, -1)
361#define UART_GET_LSR(p) bfin_read16(port_membase(p) + OFFSET_LSR)
362#define UART_PUT_LSR(p, v) bfin_write16(port_membase(p) + OFFSET_LSR, v)
363
364
365#define BFIN_UART_CTSRTS_HARD
366#define UART_CLEAR_SCTS(p) bfin_write16((port_membase(p) + OFFSET_MSR), SCTS)
367#define UART_GET_CTS(x) (UART_GET_MSR(x) & CTS)
368#define UART_DISABLE_RTS(x) UART_PUT_MCR(x, UART_GET_MCR(x) & ~(ARTS | MRTS))
369#define UART_ENABLE_RTS(x) UART_PUT_MCR(x, UART_GET_MCR(x) | MRTS | ARTS)
370#define UART_ENABLE_INTS(x, v) UART_SET_IER(x, v)
371#define UART_DISABLE_INTS(x) UART_CLEAR_IER(x, 0xF)
372
373#else
374
375#define UART_CLEAR_IER(p, v) UART_PUT_IER(p, UART_GET_IER(p) & ~(v))
376#define UART_GET_IER(p) bfin_read16(port_membase(p) + OFFSET_IER)
377#define UART_PUT_IER(p, v) bfin_write16(port_membase(p) + OFFSET_IER, v)
378#define UART_SET_IER(p, v) UART_PUT_IER(p, UART_GET_IER(p) | (v))
379
380#define UART_CLEAR_DLAB(p) do { UART_PUT_LCR(p, UART_GET_LCR(p) & ~DLAB); SSYNC(); } while (0)
381#define UART_SET_DLAB(p) do { UART_PUT_LCR(p, UART_GET_LCR(p) | DLAB); SSYNC(); } while (0)
382
383#define get_lsr_cache(uart) (((struct bfin_serial_port *)(uart))->lsr)
384#define put_lsr_cache(uart, v) (((struct bfin_serial_port *)(uart))->lsr = (v))
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399static inline void UART_CLEAR_LSR(void *p)
400{
401 put_lsr_cache(p, 0);
402 bfin_write16(port_membase(p) + OFFSET_LSR, -1);
403}
404static inline unsigned int UART_GET_LSR(void *p)
405{
406 unsigned int lsr = bfin_read16(port_membase(p) + OFFSET_LSR);
407 put_lsr_cache(p, get_lsr_cache(p) | (lsr & (BI|FE|PE|OE)));
408 return lsr | get_lsr_cache(p);
409}
410static inline void UART_PUT_LSR(void *p, uint16_t val)
411{
412 put_lsr_cache(p, get_lsr_cache(p) & ~val);
413}
414
415
416#define UART_GET_CTS(x) gpio_get_value((x)->cts_pin)
417#define UART_DISABLE_RTS(x) gpio_set_value((x)->rts_pin, 1)
418#define UART_ENABLE_RTS(x) gpio_set_value((x)->rts_pin, 0)
419#define UART_ENABLE_INTS(x, v) UART_PUT_IER(x, v)
420#define UART_DISABLE_INTS(x) UART_PUT_IER(x, 0)
421
422#endif
423
424#endif
425
426#ifndef BFIN_UART_TX_FIFO_SIZE
427# define BFIN_UART_TX_FIFO_SIZE 2
428#endif
429
430#endif
431