1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
|
/*
* Drivers for CSR SiRFprimaII onboard UARTs.
*
* Copyright (c) 2011 Cambridge Silicon Radio Limited, a CSR plc group company.
*
* Licensed under GPLv2 or later.
*/
#include <linux/bitops.h>
#include <linux/log2.h>
#include <linux/hrtimer.h>
struct sirfsoc_uart_param {
const char *uart_name;
const char *port_name;
};
struct sirfsoc_register {
/* hardware uart specific */
u32 sirfsoc_line_ctrl;
u32 sirfsoc_divisor;
/* uart - usp common */
u32 sirfsoc_tx_rx_en;
u32 sirfsoc_int_en_reg;
u32 sirfsoc_int_st_reg;
u32 sirfsoc_int_en_clr_reg;
u32 sirfsoc_tx_dma_io_ctrl;
u32 sirfsoc_tx_dma_io_len;
u32 sirfsoc_tx_fifo_ctrl;
u32 sirfsoc_tx_fifo_level_chk;
u32 sirfsoc_tx_fifo_op;
u32 sirfsoc_tx_fifo_status;
u32 sirfsoc_tx_fifo_data;
u32 sirfsoc_rx_dma_io_ctrl;
u32 sirfsoc_rx_dma_io_len;
u32 sirfsoc_rx_fifo_ctrl;
u32 sirfsoc_rx_fifo_level_chk;
u32 sirfsoc_rx_fifo_op;
u32 sirfsoc_rx_fifo_status;
u32 sirfsoc_rx_fifo_data;
u32 sirfsoc_afc_ctrl;
u32 sirfsoc_swh_dma_io;
/* hardware usp specific */
u32 sirfsoc_mode1;
u32 sirfsoc_mode2;
u32 sirfsoc_tx_frame_ctrl;
u32 sirfsoc_rx_frame_ctrl;
u32 sirfsoc_async_param_reg;
};
typedef u32 (*fifo_full_mask)(struct uart_port *port);
typedef u32 (*fifo_empty_mask)(struct uart_port *port);
struct sirfsoc_fifo_status {
fifo_full_mask ff_full;
fifo_empty_mask ff_empty;
};
struct sirfsoc_int_en {
u32 sirfsoc_rx_done_en;
u32 sirfsoc_tx_done_en;
u32 sirfsoc_rx_oflow_en;
u32 sirfsoc_tx_allout_en;
u32 sirfsoc_rx_io_dma_en;
u32 sirfsoc_tx_io_dma_en;
u32 sirfsoc_rxfifo_full_en;
u32 sirfsoc_txfifo_empty_en;
u32 sirfsoc_rxfifo_thd_en;
u32 sirfsoc_txfifo_thd_en;
u32 sirfsoc_frm_err_en;
u32 sirfsoc_rxd_brk_en;
u32 sirfsoc_rx_timeout_en;
u32 sirfsoc_parity_err_en;
u32 sirfsoc_cts_en;
u32 sirfsoc_rts_en;
};
struct sirfsoc_int_status {
u32 sirfsoc_rx_done;
u32 sirfsoc_tx_done;
u32 sirfsoc_rx_oflow;
u32 sirfsoc_tx_allout;
u32 sirfsoc_rx_io_dma;
u32 sirfsoc_tx_io_dma;
u32 sirfsoc_rxfifo_full;
u32 sirfsoc_txfifo_empty;
u32 sirfsoc_rxfifo_thd;
u32 sirfsoc_txfifo_thd;
u32 sirfsoc_frm_err;
u32 sirfsoc_rxd_brk;
u32 sirfsoc_rx_timeout;
u32 sirfsoc_parity_err;
u32 sirfsoc_cts;
u32 sirfsoc_rts;
};
enum sirfsoc_uart_type {
SIRF_REAL_UART,
SIRF_USP_UART,
};
struct sirfsoc_uart_register {
struct sirfsoc_register uart_reg;
struct sirfsoc_int_en uart_int_en;
struct sirfsoc_int_status uart_int_st;
struct sirfsoc_fifo_status fifo_status;
struct sirfsoc_uart_param uart_param;
enum sirfsoc_uart_type uart_type;
};
u32 uart_usp_ff_full_mask(struct uart_port *port)
{
u32 full_bit;
full_bit = ilog2(port->fifosize);
return (1 << full_bit);
}
u32 uart_usp_ff_empty_mask(struct uart_port *port)
{
u32 empty_bit;
empty_bit = ilog2(port->fifosize) + 1;
return (1 << empty_bit);
}
struct sirfsoc_uart_register sirfsoc_usp = {
.uart_reg = {
.sirfsoc_mode1 = 0x0000,
.sirfsoc_mode2 = 0x0004,
.sirfsoc_tx_frame_ctrl = 0x0008,
.sirfsoc_rx_frame_ctrl = 0x000c,
.sirfsoc_tx_rx_en = 0x0010,
.sirfsoc_int_en_reg = 0x0014,
.sirfsoc_int_st_reg = 0x0018,
.sirfsoc_async_param_reg = 0x0024,
.sirfsoc_tx_dma_io_ctrl = 0x0100,
.sirfsoc_tx_dma_io_len = 0x0104,
.sirfsoc_tx_fifo_ctrl = 0x0108,
.sirfsoc_tx_fifo_level_chk = 0x010c,
.sirfsoc_tx_fifo_op = 0x0110,
.sirfsoc_tx_fifo_status = 0x0114,
.sirfsoc_tx_fifo_data = 0x0118,
.sirfsoc_rx_dma_io_ctrl = 0x0120,
.sirfsoc_rx_dma_io_len = 0x0124,
.sirfsoc_rx_fifo_ctrl = 0x0128,
.sirfsoc_rx_fifo_level_chk = 0x012c,
.sirfsoc_rx_fifo_op = 0x0130,
.sirfsoc_rx_fifo_status = 0x0134,
.sirfsoc_rx_fifo_data = 0x0138,
.sirfsoc_int_en_clr_reg = 0x140,
},
.uart_int_en = {
.sirfsoc_rx_done_en = BIT(0),
.sirfsoc_tx_done_en = BIT(1),
.sirfsoc_rx_oflow_en = BIT(2),
.sirfsoc_tx_allout_en = BIT(3),
.sirfsoc_rx_io_dma_en = BIT(4),
.sirfsoc_tx_io_dma_en = BIT(5),
.sirfsoc_rxfifo_full_en = BIT(6),
.sirfsoc_txfifo_empty_en = BIT(7),
.sirfsoc_rxfifo_thd_en = BIT(8),
.sirfsoc_txfifo_thd_en = BIT(9),
.sirfsoc_frm_err_en = BIT(10),
.sirfsoc_rx_timeout_en = BIT(11),
.sirfsoc_rxd_brk_en = BIT(15),
},
.uart_int_st = {
.sirfsoc_rx_done = BIT(0),
.sirfsoc_tx_done = BIT(1),
.sirfsoc_rx_oflow = BIT(2),
.sirfsoc_tx_allout = BIT(3),
.sirfsoc_rx_io_dma = BIT(4),
.sirfsoc_tx_io_dma = BIT(5),
.sirfsoc_rxfifo_full = BIT(6),
.sirfsoc_txfifo_empty = BIT(7),
.sirfsoc_rxfifo_thd = BIT(8),
.sirfsoc_txfifo_thd = BIT(9),
.sirfsoc_frm_err = BIT(10),
.sirfsoc_rx_timeout = BIT(11),
.sirfsoc_rxd_brk = BIT(15),
},
.fifo_status = {
.ff_full = uart_usp_ff_full_mask,
.ff_empty = uart_usp_ff_empty_mask,
},
.uart_param = {
.uart_name = "ttySiRF",
.port_name = "sirfsoc-uart",
},
};
struct sirfsoc_uart_register sirfsoc_uart = {
.uart_reg = {
.sirfsoc_line_ctrl = 0x0040,
.sirfsoc_tx_rx_en = 0x004c,
.sirfsoc_divisor = 0x0050,
.sirfsoc_int_en_reg = 0x0054,
.sirfsoc_int_st_reg = 0x0058,
.sirfsoc_int_en_clr_reg = 0x0060,
.sirfsoc_tx_dma_io_ctrl = 0x0100,
.sirfsoc_tx_dma_io_len = 0x0104,
.sirfsoc_tx_fifo_ctrl = 0x0108,
.sirfsoc_tx_fifo_level_chk = 0x010c,
.sirfsoc_tx_fifo_op = 0x0110,
.sirfsoc_tx_fifo_status = 0x0114,
.sirfsoc_tx_fifo_data = 0x0118,
.sirfsoc_rx_dma_io_ctrl = 0x0120,
.sirfsoc_rx_dma_io_len = 0x0124,
.sirfsoc_rx_fifo_ctrl = 0x0128,
.sirfsoc_rx_fifo_level_chk = 0x012c,
.sirfsoc_rx_fifo_op = 0x0130,
.sirfsoc_rx_fifo_status = 0x0134,
.sirfsoc_rx_fifo_data = 0x0138,
.sirfsoc_afc_ctrl = 0x0140,
.sirfsoc_swh_dma_io = 0x0148,
},
.uart_int_en = {
.sirfsoc_rx_done_en = BIT(0),
.sirfsoc_tx_done_en = BIT(1),
.sirfsoc_rx_oflow_en = BIT(2),
.sirfsoc_tx_allout_en = BIT(3),
.sirfsoc_rx_io_dma_en = BIT(4),
.sirfsoc_tx_io_dma_en = BIT(5),
.sirfsoc_rxfifo_full_en = BIT(6),
.sirfsoc_txfifo_empty_en = BIT(7),
.sirfsoc_rxfifo_thd_en = BIT(8),
.sirfsoc_txfifo_thd_en = BIT(9),
.sirfsoc_frm_err_en = BIT(10),
.sirfsoc_rxd_brk_en = BIT(11),
.sirfsoc_rx_timeout_en = BIT(12),
.sirfsoc_parity_err_en = BIT(13),
.sirfsoc_cts_en = BIT(14),
.sirfsoc_rts_en = BIT(15),
},
.uart_int_st = {
.sirfsoc_rx_done = BIT(0),
.sirfsoc_tx_done = BIT(1),
.sirfsoc_rx_oflow = BIT(2),
.sirfsoc_tx_allout = BIT(3),
.sirfsoc_rx_io_dma = BIT(4),
.sirfsoc_tx_io_dma = BIT(5),
.sirfsoc_rxfifo_full = BIT(6),
.sirfsoc_txfifo_empty = BIT(7
|