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# ifdef BFIN_UART_BF54X_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 status_irq;
36#ifndef BFIN_UART_BF54X_STYLE
37 unsigned int lsr;
38#endif
39#ifdef CONFIG_SERIAL_BFIN_DMA
40 int tx_done;
41 int tx_count;
42 struct circ_buf rx_dma_buf;
43 struct timer_list rx_dma_timer;
44 int rx_dma_nrows;
45 spinlock_t rx_lock;
46 unsigned int tx_dma_channel;
47 unsigned int rx_dma_channel;
48 struct work_struct tx_dma_workqueue;
49#elif ANOMALY_05000363
50 unsigned int anomaly_threshold;
51#endif
52#ifdef CONFIG_SERIAL_BFIN_HARD_CTSRTS
53 int scts;
54#endif
55#if defined(CONFIG_SERIAL_BFIN_CTSRTS) || \
56 defined(CONFIG_SERIAL_BFIN_HARD_CTSRTS)
57 int cts_pin;
58 int rts_pin;
59#endif
60};
61
62
63#define WLS(x) (((x)-5) & 0x03)
64#define STB 0x04
65#define PEN 0x08
66#define EPS 0x10
67#define STP 0x20
68#define SB 0x40
69#define DLAB 0x80
70
71
72#define DR 0x01
73#define OE 0x02
74#define PE 0x04
75#define FE 0x08
76#define BI 0x10
77#define THRE 0x20
78#define TEMT 0x40
79#define TFI 0x80
80
81
82#define ERBFI 0x01
83#define ETBEI 0x02
84#define ELSI 0x04
85#define EDSSI 0x08
86#define EDTPTI 0x10
87#define ETFI 0x20
88#define ERFCI 0x40
89
90
91#define XOFF 0x01
92#define MRTS 0x02
93#define RFIT 0x04
94#define RFRT 0x08
95#define LOOP_ENA 0x10
96#define FCPOL 0x20
97#define ARTS 0x40
98#define ACTS 0x80
99
100
101#define SCTS 0x01
102#define CTS 0x10
103#define RFCS 0x20
104
105
106#define UCEN 0x01
107#define IREN 0x02
108#define TPOLC 0x04
109#define RPOLC 0x08
110#define FPE 0x10
111#define FFE 0x20
112
113#ifdef BFIN_UART_BF54X_STYLE
114# define OFFSET_DLL 0x00
115# define OFFSET_DLH 0x04
116# define OFFSET_GCTL 0x08
117# define OFFSET_LCR 0x0C
118# define OFFSET_MCR 0x10
119# define OFFSET_LSR 0x14
120# define OFFSET_MSR 0x18
121# define OFFSET_SCR 0x1C
122# define OFFSET_IER_SET 0x20
123# define OFFSET_IER_CLEAR 0x24
124# define OFFSET_THR 0x28
125# define OFFSET_RBR 0x2C
126#else
127# define OFFSET_THR 0x00
128# define OFFSET_RBR 0x00
129# define OFFSET_DLL 0x00
130# define OFFSET_DLH 0x04
131# define OFFSET_IER 0x04
132# define OFFSET_IIR 0x08
133# define OFFSET_LCR 0x0C
134# define OFFSET_MCR 0x10
135# define OFFSET_LSR 0x14
136# define OFFSET_MSR 0x18
137# define OFFSET_SCR 0x1C
138# define OFFSET_GCTL 0x24
139
140# undef OFFSET_IIR
141#endif
142
143
144
145
146
147#define __BFP(m) u16 m; u16 __pad_##m
148struct bfin_uart_regs {
149#ifdef BFIN_UART_BF54X_STYLE
150 __BFP(dll);
151 __BFP(dlh);
152 __BFP(gctl);
153 __BFP(lcr);
154 __BFP(mcr);
155 __BFP(lsr);
156 __BFP(msr);
157 __BFP(scr);
158 __BFP(ier_set);
159 __BFP(ier_clear);
160 __BFP(thr);
161 __BFP(rbr);
162#else
163 union {
164 u16 dll;
165 u16 thr;
166 const u16 rbr;
167 };
168 const u16 __pad0;
169 union {
170 u16 dlh;
171 u16 ier;
172 };
173 const u16 __pad1;
174 const __BFP(iir);
175 __BFP(lcr);
176 __BFP(mcr);
177 __BFP(lsr);
178 __BFP(msr);
179 __BFP(scr);
180 const u32 __pad2;
181 __BFP(gctl);
182#endif
183};
184#undef __BFP
185
186#ifndef port_membase
187# define port_membase(p) (((struct bfin_serial_port *)(p))->port.membase)
188#endif
189
190#define UART_GET_CHAR(p) bfin_read16(port_membase(p) + OFFSET_RBR)
191#define UART_GET_DLL(p) bfin_read16(port_membase(p) + OFFSET_DLL)
192#define UART_GET_DLH(p) bfin_read16(port_membase(p) + OFFSET_DLH)
193#define UART_GET_GCTL(p) bfin_read16(port_membase(p) + OFFSET_GCTL)
194#define UART_GET_LCR(p) bfin_read16(port_membase(p) + OFFSET_LCR)
195#define UART_GET_MCR(p) bfin_read16(port_membase(p) + OFFSET_MCR)
196#define UART_GET_MSR(p) bfin_read16(port_membase(p) + OFFSET_MSR)
197
198#define UART_PUT_CHAR(p, v) bfin_write16(port_membase(p) + OFFSET_THR, v)
199#define UART_PUT_DLL(p, v) bfin_write16(port_membase(p) + OFFSET_DLL, v)
200#define UART_PUT_DLH(p, v) bfin_write16(port_membase(p) + OFFSET_DLH, v)
201#define UART_PUT_GCTL(p, v) bfin_write16(port_membase(p) + OFFSET_GCTL, v)
202#define UART_PUT_LCR(p, v) bfin_write16(port_membase(p) + OFFSET_LCR, v)
203#define UART_PUT_MCR(p, v) bfin_write16(port_membase(p) + OFFSET_MCR, v)
204
205#ifdef BFIN_UART_BF54X_STYLE
206
207#define UART_CLEAR_IER(p, v) bfin_write16(port_membase(p) + OFFSET_IER_CLEAR, v)
208#define UART_GET_IER(p) bfin_read16(port_membase(p) + OFFSET_IER_SET)
209#define UART_SET_IER(p, v) bfin_write16(port_membase(p) + OFFSET_IER_SET, v)
210
211#define UART_CLEAR_DLAB(p)
212#define UART_SET_DLAB(p)
213
214#define UART_CLEAR_LSR(p) bfin_write16(port_membase(p) + OFFSET_LSR, -1)
215#define UART_GET_LSR(p) bfin_read16(port_membase(p) + OFFSET_LSR)
216#define UART_PUT_LSR(p, v) bfin_write16(port_membase(p) + OFFSET_LSR, v)
217
218
219#define BFIN_UART_CTSRTS_HARD
220#define UART_CLEAR_SCTS(p) bfin_write16((port_membase(p) + OFFSET_MSR), SCTS)
221#define UART_GET_CTS(x) (UART_GET_MSR(x) & CTS)
222#define UART_DISABLE_RTS(x) UART_PUT_MCR(x, UART_GET_MCR(x) & ~(ARTS | MRTS))
223#define UART_ENABLE_RTS(x) UART_PUT_MCR(x, UART_GET_MCR(x) | MRTS | ARTS)
224#define UART_ENABLE_INTS(x, v) UART_SET_IER(x, v)
225#define UART_DISABLE_INTS(x) UART_CLEAR_IER(x, 0xF)
226
227#else
228
229#define UART_CLEAR_IER(p, v) UART_PUT_IER(p, UART_GET_IER(p) & ~(v))
230#define UART_GET_IER(p) bfin_read16(port_membase(p) + OFFSET_IER)
231#define UART_PUT_IER(p, v) bfin_write16(port_membase(p) + OFFSET_IER, v)
232#define UART_SET_IER(p, v) UART_PUT_IER(p, UART_GET_IER(p) | (v))
233
234#define UART_CLEAR_DLAB(p) do { UART_PUT_LCR(p, UART_GET_LCR(p) & ~DLAB); SSYNC(); } while (0)
235#define UART_SET_DLAB(p) do { UART_PUT_LCR(p, UART_GET_LCR(p) | DLAB); SSYNC(); } while (0)
236
237#ifndef put_lsr_cache
238# define put_lsr_cache(p, v) (((struct bfin_serial_port *)(p))->lsr = (v))
239#endif
240#ifndef get_lsr_cache
241# define get_lsr_cache(p) (((struct bfin_serial_port *)(p))->lsr)
242#endif
243
244
245
246
247
248static inline void UART_CLEAR_LSR(void *p)
249{
250 put_lsr_cache(p, 0);
251 bfin_write16(port_membase(p) + OFFSET_LSR, -1);
252}
253static inline unsigned int UART_GET_LSR(void *p)
254{
255 unsigned int lsr = bfin_read16(port_membase(p) + OFFSET_LSR);
256 put_lsr_cache(p, get_lsr_cache(p) | (lsr & (BI|FE|PE|OE)));
257 return lsr | get_lsr_cache(p);
258}
259static inline void UART_PUT_LSR(void *p, uint16_t val)
260{
261 put_lsr_cache(p, get_lsr_cache(p) & ~val);
262}
263
264
265#define UART_GET_CTS(x) gpio_get_value((x)->cts_pin)
266#define UART_DISABLE_RTS(x) gpio_set_value((x)->rts_pin, 1)
267#define UART_ENABLE_RTS(x) gpio_set_value((x)->rts_pin, 0)
268#define UART_ENABLE_INTS(x, v) UART_PUT_IER(x, v)
269#define UART_DISABLE_INTS(x) UART_PUT_IER(x, 0)
270
271#endif
272
273#ifndef BFIN_UART_TX_FIFO_SIZE
274# define BFIN_UART_TX_FIFO_SIZE 2
275#endif
276
277#endif
278