Setting up repository
[linux-libre-firmware.git] / ath9k_htc / sboot / magpie_1_1 / inc / uart_api.h
1 /*
2  * Copyright (c) 2013 Qualcomm Atheros, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted (subject to the limitations in the
7  * disclaimer below) provided that the following conditions are met:
8  *
9  *  * Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  *  * Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the
15  *    distribution.
16  *
17  *  * Neither the name of Qualcomm Atheros nor the names of its
18  *    contributors may be used to endorse or promote products derived
19  *    from this software without specific prior written permission.
20  *
21  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
22  * GRANTED BY THIS LICENSE.  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
23  * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
24  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
33  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 /*************************************************************************/
36 /*  Copyright (c) 2006 Atheros Communications, Inc., All Rights Reserved */
37 /*                                                                       */
38 /*  Module Name : uart.h                                                 */
39 /*                                                                       */
40 /*  Abstract                                                             */
41 /*      This file contains definition of uart registers, marco and api.  */
42 /*                                                                       */
43 /*  NOTES                                                                */
44 /*      None                                                             */
45 /*                                                                       */
46 /*************************************************************************/
47
48 #ifndef _UART_API_H_
49 #define _UART_API_H_
50
51 #include "reg_defs.h"
52
53 /************************* Register Process marco ************************/
54 #define UART_REG_WRITE(addr, val)       HAL_WORD_REG_WRITE(UART_BASE_ADDRESS|(uint32_t)(addr), (val))
55 #define UART_REG_READ(addr)             HAL_WORD_REG_READ(UART_BASE_ADDRESS|(uint32_t)(addr))
56
57 /************************** Register deinition ***************************/
58 #define RBR_ADDRESS                              0x00051000
59 #define RBR_OFFSET                               0x00000000
60 #define RBR_RBR_MSB                              7
61 #define RBR_RBR_LSB                              0
62 #define RBR_RBR_MASK                             0x000000ff
63 #define RBR_RBR_GET(x)                           (((x) & RBR_RBR_MASK) >> RBR_RBR_LSB)
64 #define RBR_RBR_SET(x)                           (((x) << RBR_RBR_LSB) & RBR_RBR_MASK)
65
66 #define THR_ADDRESS                              0x00051000
67 #define THR_OFFSET                               0x00000000
68 #define THR_THR_MSB                              7
69 #define THR_THR_LSB                              0
70 #define THR_THR_MASK                             0x000000ff
71 #define THR_THR_GET(x)                           (((x) & THR_THR_MASK) >> THR_THR_LSB)
72 #define THR_THR_SET(x)                           (((x) << THR_THR_LSB) & THR_THR_MASK)
73
74 #define DLL_ADDRESS                              0x00051000
75 #define DLL_OFFSET                               0x00000000
76 #define DLL_DLL_MSB                              7
77 #define DLL_DLL_LSB                              0
78 #define DLL_DLL_MASK                             0x000000ff
79 #define DLL_DLL_GET(x)                           (((x) & DLL_DLL_MASK) >> DLL_DLL_LSB)
80 #define DLL_DLL_SET(x)                           (((x) << DLL_DLL_LSB) & DLL_DLL_MASK)
81
82 #define DLH_ADDRESS                              0x00051004
83 #define DLH_OFFSET                               0x00000004
84 #define DLH_DLH_MSB                              7
85 #define DLH_DLH_LSB                              0
86 #define DLH_DLH_MASK                             0x000000ff
87 #define DLH_DLH_GET(x)                           (((x) & DLH_DLH_MASK) >> DLH_DLH_LSB)
88 #define DLH_DLH_SET(x)                           (((x) << DLH_DLH_LSB) & DLH_DLH_MASK)
89
90 #define IER_ADDRESS                              0x00051004
91 #define IER_OFFSET                               0x00000004
92 #define IER_EDDSI_MSB                            3
93 #define IER_EDDSI_LSB                            3
94 #define IER_EDDSI_MASK                           0x00000008
95 #define IER_EDDSI_GET(x)                         (((x) & IER_EDDSI_MASK) >> IER_EDDSI_LSB)
96 #define IER_EDDSI_SET(x)                         (((x) << IER_EDDSI_LSB) & IER_EDDSI_MASK)
97 #define IER_ELSI_MSB                             2
98 #define IER_ELSI_LSB                             2
99 #define IER_ELSI_MASK                            0x00000004
100 #define IER_ELSI_GET(x)                          (((x) & IER_ELSI_MASK) >> IER_ELSI_LSB)
101 #define IER_ELSI_SET(x)                          (((x) << IER_ELSI_LSB) & IER_ELSI_MASK)
102 #define IER_ETBEI_MSB                            1
103 #define IER_ETBEI_LSB                            1
104 #define IER_ETBEI_MASK                           0x00000002
105 #define IER_ETBEI_GET(x)                         (((x) & IER_ETBEI_MASK) >> IER_ETBEI_LSB)
106 #define IER_ETBEI_SET(x)                         (((x) << IER_ETBEI_LSB) & IER_ETBEI_MASK)
107 #define IER_ERBFI_MSB                            0
108 #define IER_ERBFI_LSB                            0
109 #define IER_ERBFI_MASK                           0x00000001
110 #define IER_ERBFI_GET(x)                         (((x) & IER_ERBFI_MASK) >> IER_ERBFI_LSB)
111 #define IER_ERBFI_SET(x)                         (((x) << IER_ERBFI_LSB) & IER_ERBFI_MASK)
112
113 #define IIR_ADDRESS                              0x00051008
114 #define IIR_OFFSET                               0x00000008
115 #define IIR_FIFO_STATUS_MSB                      7
116 #define IIR_FIFO_STATUS_LSB                      6
117 #define IIR_FIFO_STATUS_MASK                     0x000000c0
118 #define IIR_FIFO_STATUS_GET(x)                   (((x) & IIR_FIFO_STATUS_MASK) >> IIR_FIFO_STATUS_LSB)
119 #define IIR_FIFO_STATUS_SET(x)                   (((x) << IIR_FIFO_STATUS_LSB) & IIR_FIFO_STATUS_MASK)
120 #define IIR_IID_MSB                              3
121 #define IIR_IID_LSB                              0
122 #define IIR_IID_MASK                             0x0000000f
123 #define IIR_IID_GET(x)                           (((x) & IIR_IID_MASK) >> IIR_IID_LSB)
124 #define IIR_IID_SET(x)                           (((x) << IIR_IID_LSB) & IIR_IID_MASK)
125
126 #define FCR_ADDRESS                              0x00051008
127 #define FCR_OFFSET                               0x00000008
128 #define FCR_RCVR_TRIG_MSB                        7
129 #define FCR_RCVR_TRIG_LSB                        6
130 #define FCR_RCVR_TRIG_MASK                       0x000000c0
131 #define FCR_RCVR_TRIG_GET(x)                     (((x) & FCR_RCVR_TRIG_MASK) >> FCR_RCVR_TRIG_LSB)
132 #define FCR_RCVR_TRIG_SET(x)                     (((x) << FCR_RCVR_TRIG_LSB) & FCR_RCVR_TRIG_MASK)
133 #define FCR_DMA_MODE_MSB                         3
134 #define FCR_DMA_MODE_LSB                         3
135 #define FCR_DMA_MODE_MASK                        0x00000008
136 #define FCR_DMA_MODE_GET(x)                      (((x) & FCR_DMA_MODE_MASK) >> FCR_DMA_MODE_LSB)
137 #define FCR_DMA_MODE_SET(x)                      (((x) << FCR_DMA_MODE_LSB) & FCR_DMA_MODE_MASK)
138 #define FCR_XMIT_FIFO_RST_MSB                    2
139 #define FCR_XMIT_FIFO_RST_LSB                    2
140 #define FCR_XMIT_FIFO_RST_MASK                   0x00000004
141 #define FCR_XMIT_FIFO_RST_GET(x)                 (((x) & FCR_XMIT_FIFO_RST_MASK) >> FCR_XMIT_FIFO_RST_LSB)
142 #define FCR_XMIT_FIFO_RST_SET(x)                 (((x) << FCR_XMIT_FIFO_RST_LSB) & FCR_XMIT_FIFO_RST_MASK)
143 #define FCR_RCVR_FIFO_RST_MSB                    1
144 #define FCR_RCVR_FIFO_RST_LSB                    1
145 #define FCR_RCVR_FIFO_RST_MASK                   0x00000002
146 #define FCR_RCVR_FIFO_RST_GET(x)                 (((x) & FCR_RCVR_FIFO_RST_MASK) >> FCR_RCVR_FIFO_RST_LSB)
147 #define FCR_RCVR_FIFO_RST_SET(x)                 (((x) << FCR_RCVR_FIFO_RST_LSB) & FCR_RCVR_FIFO_RST_MASK)
148 #define FCR_FIFO_EN_MSB                          0
149 #define FCR_FIFO_EN_LSB                          0
150 #define FCR_FIFO_EN_MASK                         0x00000001
151 #define FCR_FIFO_EN_GET(x)                       (((x) & FCR_FIFO_EN_MASK) >> FCR_FIFO_EN_LSB)
152 #define FCR_FIFO_EN_SET(x)                       (((x) << FCR_FIFO_EN_LSB) & FCR_FIFO_EN_MASK)
153
154 #define LCR_ADDRESS                              0x0005100c
155 #define LCR_OFFSET                               0x0000000c
156 #define LCR_DLAB_MSB                             7
157 #define LCR_DLAB_LSB                             7
158 #define LCR_DLAB_MASK                            0x00000080
159 #define LCR_DLAB_GET(x)                          (((x) & LCR_DLAB_MASK) >> LCR_DLAB_LSB)
160 #define LCR_DLAB_SET(x)                          (((x) << LCR_DLAB_LSB) & LCR_DLAB_MASK)
161 #define LCR_BREAK_MSB                            6
162 #define LCR_BREAK_LSB                            6
163 #define LCR_BREAK_MASK                           0x00000040
164 #define LCR_BREAK_GET(x)                         (((x) & LCR_BREAK_MASK) >> LCR_BREAK_LSB)
165 #define LCR_BREAK_SET(x)                         (((x) << LCR_BREAK_LSB) & LCR_BREAK_MASK)
166 #define LCR_EPS_MSB                              4
167 #define LCR_EPS_LSB                              4
168 #define LCR_EPS_MASK                             0x00000010
169 #define LCR_EPS_GET(x)                           (((x) & LCR_EPS_MASK) >> LCR_EPS_LSB)
170 #define LCR_EPS_SET(x)                           (((x) << LCR_EPS_LSB) & LCR_EPS_MASK)
171 #define LCR_PEN_MSB                              3
172 #define LCR_PEN_LSB                              3
173 #define LCR_PEN_MASK                             0x00000008
174 #define LCR_PEN_GET(x)                           (((x) & LCR_PEN_MASK) >> LCR_PEN_LSB)
175 #define LCR_PEN_SET(x)                           (((x) << LCR_PEN_LSB) & LCR_PEN_MASK)
176 #define LCR_STOP_MSB                             2
177 #define LCR_STOP_LSB                             2
178 #define LCR_STOP_MASK                            0x00000004
179 #define LCR_STOP_GET(x)                          (((x) & LCR_STOP_MASK) >> LCR_STOP_LSB)
180 #define LCR_STOP_SET(x)                          (((x) << LCR_STOP_LSB) & LCR_STOP_MASK)
181 #define LCR_CLS_MSB                              1
182 #define LCR_CLS_LSB                              0
183 #define LCR_CLS_MASK                             0x00000003
184 #define LCR_CLS_GET(x)                           (((x) & LCR_CLS_MASK) >> LCR_CLS_LSB)
185 #define LCR_CLS_SET(x)                           (((x) << LCR_CLS_LSB) & LCR_CLS_MASK)
186
187 #define MCR_ADDRESS                              0x00051010
188 #define MCR_OFFSET                               0x00000010
189 #define MCR_LOOPBACK_MSB                         5
190 #define MCR_LOOPBACK_LSB                         5
191 #define MCR_LOOPBACK_MASK                        0x00000020
192 #define MCR_LOOPBACK_GET(x)                      (((x) & MCR_LOOPBACK_MASK) >> MCR_LOOPBACK_LSB)
193 #define MCR_LOOPBACK_SET(x)                      (((x) << MCR_LOOPBACK_LSB) & MCR_LOOPBACK_MASK)
194 #define MCR_OUT2_MSB                             3
195 #define MCR_OUT2_LSB                             3
196 #define MCR_OUT2_MASK                            0x00000008
197 #define MCR_OUT2_GET(x)                          (((x) & MCR_OUT2_MASK) >> MCR_OUT2_LSB)
198 #define MCR_OUT2_SET(x)                          (((x) << MCR_OUT2_LSB) & MCR_OUT2_MASK)
199 #define MCR_OUT1_MSB                             2
200 #define MCR_OUT1_LSB                             2
201 #define MCR_OUT1_MASK                            0x00000004
202 #define MCR_OUT1_GET(x)                          (((x) & MCR_OUT1_MASK) >> MCR_OUT1_LSB)
203 #define MCR_OUT1_SET(x)                          (((x) << MCR_OUT1_LSB) & MCR_OUT1_MASK)
204 #define MCR_RTS_MSB                              1
205 #define MCR_RTS_LSB                              1
206 #define MCR_RTS_MASK                             0x00000002
207 #define MCR_RTS_GET(x)                           (((x) & MCR_RTS_MASK) >> MCR_RTS_LSB)
208 #define MCR_RTS_SET(x)                           (((x) << MCR_RTS_LSB) & MCR_RTS_MASK)
209 #define MCR_DTR_MSB                              0
210 #define MCR_DTR_LSB                              0
211 #define MCR_DTR_MASK                             0x00000001
212 #define MCR_DTR_GET(x)                           (((x) & MCR_DTR_MASK) >> MCR_DTR_LSB)
213 #define MCR_DTR_SET(x)                           (((x) << MCR_DTR_LSB) & MCR_DTR_MASK)
214
215 #define LSR_ADDRESS                              0x00051014
216 #define LSR_OFFSET                               0x00000014
217 #define LSR_FERR_MSB                             7
218 #define LSR_FERR_LSB                             7
219 #define LSR_FERR_MASK                            0x00000080
220 #define LSR_FERR_GET(x)                          (((x) & LSR_FERR_MASK) >> LSR_FERR_LSB)
221 #define LSR_FERR_SET(x)                          (((x) << LSR_FERR_LSB) & LSR_FERR_MASK)
222 #define LSR_TEMT_MSB                             6
223 #define LSR_TEMT_LSB                             6
224 #define LSR_TEMT_MASK                            0x00000040
225 #define LSR_TEMT_GET(x)                          (((x) & LSR_TEMT_MASK) >> LSR_TEMT_LSB)
226 #define LSR_TEMT_SET(x)                          (((x) << LSR_TEMT_LSB) & LSR_TEMT_MASK)
227 #define LSR_THRE_MSB                             5
228 #define LSR_THRE_LSB                             5
229 #define LSR_THRE_MASK                            0x00000020
230 #define LSR_THRE_GET(x)                          (((x) & LSR_THRE_MASK) >> LSR_THRE_LSB)
231 #define LSR_THRE_SET(x)                          (((x) << LSR_THRE_LSB) & LSR_THRE_MASK)
232 #define LSR_BI_MSB                               4
233 #define LSR_BI_LSB                               4
234 #define LSR_BI_MASK                              0x00000010
235 #define LSR_BI_GET(x)                            (((x) & LSR_BI_MASK) >> LSR_BI_LSB)
236 #define LSR_BI_SET(x)                            (((x) << LSR_BI_LSB) & LSR_BI_MASK)
237 #define LSR_FE_MSB                               3
238 #define LSR_FE_LSB                               3
239 #define LSR_FE_MASK                              0x00000008
240 #define LSR_FE_GET(x)                            (((x) & LSR_FE_MASK) >> LSR_FE_LSB)
241 #define LSR_FE_SET(x)                            (((x) << LSR_FE_LSB) & LSR_FE_MASK)
242 #define LSR_PE_MSB                               2
243 #define LSR_PE_LSB                               2
244 #define LSR_PE_MASK                              0x00000004
245 #define LSR_PE_GET(x)                            (((x) & LSR_PE_MASK) >> LSR_PE_LSB)
246 #define LSR_PE_SET(x)                            (((x) << LSR_PE_LSB) & LSR_PE_MASK)
247 #define LSR_OE_MSB                               1
248 #define LSR_OE_LSB                               1
249 #define LSR_OE_MASK                              0x00000002
250 #define LSR_OE_GET(x)                            (((x) & LSR_OE_MASK) >> LSR_OE_LSB)
251 #define LSR_OE_SET(x)                            (((x) << LSR_OE_LSB) & LSR_OE_MASK)
252 #define LSR_DR_MSB                               0
253 #define LSR_DR_LSB                               0
254 #define LSR_DR_MASK                              0x00000001
255 #define LSR_DR_GET(x)                            (((x) & LSR_DR_MASK) >> LSR_DR_LSB)
256 #define LSR_DR_SET(x)                            (((x) << LSR_DR_LSB) & LSR_DR_MASK)
257
258 #define MSR_ADDRESS                              0x00051018
259 #define MSR_OFFSET                               0x00000018
260 #define MSR_DCD_MSB                              7
261 #define MSR_DCD_LSB                              7
262 #define MSR_DCD_MASK                             0x00000080
263 #define MSR_DCD_GET(x)                           (((x) & MSR_DCD_MASK) >> MSR_DCD_LSB)
264 #define MSR_DCD_SET(x)                           (((x) << MSR_DCD_LSB) & MSR_DCD_MASK)
265 #define MSR_RI_MSB                               6
266 #define MSR_RI_LSB                               6
267 #define MSR_RI_MASK                              0x00000040
268 #define MSR_RI_GET(x)                            (((x) & MSR_RI_MASK) >> MSR_RI_LSB)
269 #define MSR_RI_SET(x)                            (((x) << MSR_RI_LSB) & MSR_RI_MASK)
270 #define MSR_DSR_MSB                              5
271 #define MSR_DSR_LSB                              5
272 #define MSR_DSR_MASK                             0x00000020
273 #define MSR_DSR_GET(x)                           (((x) & MSR_DSR_MASK) >> MSR_DSR_LSB)
274 #define MSR_DSR_SET(x)                           (((x) << MSR_DSR_LSB) & MSR_DSR_MASK)
275 #define MSR_CTS_MSB                              4
276 #define MSR_CTS_LSB                              4
277 #define MSR_CTS_MASK                             0x00000010
278 #define MSR_CTS_GET(x)                           (((x) & MSR_CTS_MASK) >> MSR_CTS_LSB)
279 #define MSR_CTS_SET(x)                           (((x) << MSR_CTS_LSB) & MSR_CTS_MASK)
280 #define MSR_DDCD_MSB                             3
281 #define MSR_DDCD_LSB                             3
282 #define MSR_DDCD_MASK                            0x00000008
283 #define MSR_DDCD_GET(x)                          (((x) & MSR_DDCD_MASK) >> MSR_DDCD_LSB)
284 #define MSR_DDCD_SET(x)                          (((x) << MSR_DDCD_LSB) & MSR_DDCD_MASK)
285 #define MSR_TERI_MSB                             2
286 #define MSR_TERI_LSB                             2
287 #define MSR_TERI_MASK                            0x00000004
288 #define MSR_TERI_GET(x)                          (((x) & MSR_TERI_MASK) >> MSR_TERI_LSB)
289 #define MSR_TERI_SET(x)                          (((x) << MSR_TERI_LSB) & MSR_TERI_MASK)
290 #define MSR_DDSR_MSB                             1
291 #define MSR_DDSR_LSB                             1
292 #define MSR_DDSR_MASK                            0x00000002
293 #define MSR_DDSR_GET(x)                          (((x) & MSR_DDSR_MASK) >> MSR_DDSR_LSB)
294 #define MSR_DDSR_SET(x)                          (((x) << MSR_DDSR_LSB) & MSR_DDSR_MASK)
295 #define MSR_DCTS_MSB                             0
296 #define MSR_DCTS_LSB                             0
297 #define MSR_DCTS_MASK                            0x00000001
298 #define MSR_DCTS_GET(x)                          (((x) & MSR_DCTS_MASK) >> MSR_DCTS_LSB)
299 #define MSR_DCTS_SET(x)                          (((x) << MSR_DCTS_LSB) & MSR_DCTS_MASK)
300
301
302 /************************** config definition ***************************/
303 #define UART_FIFO_SIZE  512 //Must be 2^N
304
305 #define USE_POST_BUFFER 0   // ENABLE a tx buffer for post processing,
306 /*********************** data struction definition ************************/
307 // data struction definition
308 struct uart_fifo {
309 #if USE_POST_BUFFER
310         uint8_t buf[UART_FIFO_SIZE];
311 #endif
312         uint16_t start_index;
313         uint16_t end_index;
314         uint32_t overrun_err;
315 };
316
317
318 struct uart_blk {
319         uint16_t debug_mode;
320         uint16_t baud;
321        struct uart_api *_uart;
322         struct uart_fifo _tx;
323 };
324
325
326 /******** hardware API table structure (API descriptions below) *************/
327 struct uart_api {
328     uint32_t (*_uart_init)(void);
329     void (*_uart_char_put)(uint8_t ch);
330     uint16_t (*_uart_char_get)(uint8_t* ch);
331     void (*_uart_str_out)(uint8_t* str);
332     void (*_uart_task)(void);
333     uint32_t (*_uart_status)(void);\r
334     void (*_uart_config)(uint16_t flag);
335     void (*_uart_hwinit)(uint32_t freq, uint32_t baud);
336         //void (*_uart_config)(uint8_t cmd, void *pData);
337 };
338
339 /************************* EXPORT function ***************************/
340
341
342 #endif  // end of _UART_API_H_
343