1
2
3
4
5
6
7
8
9
10
11
12#include "ops.h"
13#include "io.h"
14#include "stdio.h"
15
16#define UART_DLL 0
17#define UART_DLM 1
18#define UART_FCR 2
19#define UART_FCR_CLEAR_RCVR 0x02
20#define UART_FCR_CLEAR_XMIT 0x04
21#define UART_LCR 3
22#define UART_MCR 4
23#define UART_MCR_RTS 0x02
24#define UART_MCR_DTR 0x01
25#define UART_LCR_DLAB 0x80
26#define UART_LCR_WLEN8 0x03
27
28static int virtex_ns16550_console_init(void *devp)
29{
30 unsigned char *reg_base;
31 u32 reg_shift, reg_offset, clk, spd;
32 u16 divisor;
33 int n;
34
35 if (dt_get_virtual_reg(devp, (void **)®_base, 1) < 1)
36 return -1;
37
38 n = getprop(devp, "reg-offset", ®_offset, sizeof(reg_offset));
39 if (n == sizeof(reg_offset))
40 reg_base += reg_offset;
41
42 n = getprop(devp, "reg-shift", ®_shift, sizeof(reg_shift));
43 if (n != sizeof(reg_shift))
44 reg_shift = 0;
45
46 n = getprop(devp, "current-speed", (void *)&spd, sizeof(spd));
47 if (n != sizeof(spd))
48 spd = 9600;
49
50
51 n = getprop(devp, "clock-frequency", (void *)&clk, sizeof(clk));
52 if (n != sizeof(clk))
53 return -1;
54
55 divisor = clk / (16 * spd);
56
57
58 out_8(reg_base + (UART_LCR << reg_shift), UART_LCR_DLAB);
59
60
61 out_8(reg_base + (UART_DLL << reg_shift), divisor & 0xFF);
62 out_8(reg_base + (UART_DLM << reg_shift), divisor >> 8);
63
64
65 out_8(reg_base + (UART_LCR << reg_shift), UART_LCR_WLEN8);
66
67
68 out_8(reg_base + (UART_MCR << reg_shift), UART_MCR_RTS | UART_MCR_DTR);
69
70
71 out_8(reg_base + (UART_FCR << reg_shift),
72 UART_FCR_CLEAR_XMIT | UART_FCR_CLEAR_RCVR);
73 return 0;
74}
75
76
77
78
79int platform_specific_init(void)
80{
81 void *devp;
82 char devtype[MAX_PROP_LEN];
83 char path[MAX_PATH_LEN];
84
85 devp = finddevice("/chosen");
86 if (devp == NULL)
87 return -1;
88
89 if (getprop(devp, "linux,stdout-path", path, MAX_PATH_LEN) > 0) {
90 devp = finddevice(path);
91 if (devp == NULL)
92 return -1;
93
94 if ((getprop(devp, "device_type", devtype, sizeof(devtype)) > 0)
95 && !strcmp(devtype, "serial")
96 && (dt_is_compatible(devp, "ns16550")))
97 virtex_ns16550_console_init(devp);
98 }
99 return 0;
100}
101