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