]>
Commit | Line | Data |
---|---|---|
a3f98646 | 1 | /** @file\r |
2 | Serial I/O Port library functions with no library constructor/destructor\r | |
3 | \r | |
4 | \r | |
3d70643b | 5 | Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r |
a3f98646 | 6 | \r |
3d70643b | 7 | This program and the accompanying materials\r |
a3f98646 | 8 | are licensed and made available under the terms and conditions of the BSD License\r |
9 | which accompanies this distribution. The full text of the license may be found at\r | |
10 | http://opensource.org/licenses/bsd-license.php\r | |
11 | \r | |
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
13 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
14 | \r | |
15 | **/\r | |
16 | \r | |
17 | #include <Base.h>\r | |
18 | #include <Library/DebugLib.h>\r | |
19 | #include <Library/SerialPortLib.h>\r | |
7d49ced0 | 20 | #include <Library/SerialPortExtLib.h>\r |
a3f98646 | 21 | #include <Library/PcdLib.h>\r |
22 | #include <Library/IoLib.h>\r | |
23 | #include <Library/OmapLib.h>\r | |
24 | #include <Omap3530/Omap3530.h>\r | |
25 | \r | |
26 | /*\r | |
27 | \r | |
28 | Programmed hardware of Serial port.\r | |
29 | \r | |
30 | @return Always return EFI_UNSUPPORTED.\r | |
31 | \r | |
32 | **/\r | |
33 | RETURN_STATUS\r | |
34 | EFIAPI\r | |
35 | SerialPortInitialize (\r | |
36 | VOID\r | |
37 | )\r | |
38 | {\r | |
39 | // assume assembly code at reset vector has setup UART\r | |
40 | return RETURN_SUCCESS;\r | |
41 | }\r | |
42 | \r | |
43 | /**\r | |
44 | Write data to serial device.\r | |
45 | \r | |
46 | @param Buffer Point of data buffer which need to be writed.\r | |
47 | @param NumberOfBytes Number of output bytes which are cached in Buffer.\r | |
48 | \r | |
49 | @retval 0 Write data failed.\r | |
50 | @retval !0 Actual number of bytes writed to serial device.\r | |
51 | \r | |
52 | **/\r | |
53 | UINTN\r | |
54 | EFIAPI\r | |
55 | SerialPortWrite (\r | |
56 | IN UINT8 *Buffer,\r | |
57 | IN UINTN NumberOfBytes\r | |
58 | )\r | |
59 | {\r | |
43263288 | 60 | UINT32 LSR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_LSR_REG;\r |
61 | UINT32 THR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_THR_REG;\r | |
a3f98646 | 62 | UINTN Count;\r |
63 | \r | |
64 | for (Count = 0; Count < NumberOfBytes; Count++, Buffer++) {\r | |
65 | while ((MmioRead8(LSR) & UART_LSR_TX_FIFO_E_MASK) == UART_LSR_TX_FIFO_E_NOT_EMPTY);\r | |
66 | MmioWrite8(THR, *Buffer);\r | |
67 | }\r | |
68 | \r | |
69 | return NumberOfBytes;\r | |
70 | }\r | |
71 | \r | |
72 | \r | |
73 | /**\r | |
74 | Read data from serial device and save the datas in buffer.\r | |
75 | \r | |
76 | @param Buffer Point of data buffer which need to be writed.\r | |
77 | @param NumberOfBytes Number of output bytes which are cached in Buffer.\r | |
78 | \r | |
79 | @retval 0 Read data failed.\r | |
80 | @retval !0 Aactual number of bytes read from serial device.\r | |
81 | \r | |
82 | **/\r | |
83 | UINTN\r | |
84 | EFIAPI\r | |
85 | SerialPortRead (\r | |
86 | OUT UINT8 *Buffer,\r | |
87 | IN UINTN NumberOfBytes\r | |
88 | )\r | |
89 | {\r | |
43263288 | 90 | UINT32 LSR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_LSR_REG;\r |
91 | UINT32 RBR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_RBR_REG;\r | |
a3f98646 | 92 | UINTN Count;\r |
93 | \r | |
94 | for (Count = 0; Count < NumberOfBytes; Count++, Buffer++) {\r | |
95 | while ((MmioRead8(LSR) & UART_LSR_RX_FIFO_E_MASK) == UART_LSR_RX_FIFO_E_EMPTY);\r | |
96 | *Buffer = MmioRead8(RBR);\r | |
97 | }\r | |
98 | \r | |
99 | return NumberOfBytes;\r | |
100 | }\r | |
101 | \r | |
102 | \r | |
103 | /**\r | |
104 | Check to see if any data is avaiable to be read from the debug device.\r | |
105 | \r | |
106 | @retval EFI_SUCCESS At least one byte of data is avaiable to be read\r | |
107 | @retval EFI_NOT_READY No data is avaiable to be read\r | |
108 | @retval EFI_DEVICE_ERROR The serial device is not functioning properly\r | |
109 | \r | |
110 | **/\r | |
111 | BOOLEAN\r | |
112 | EFIAPI\r | |
113 | SerialPortPoll (\r | |
114 | VOID\r | |
115 | )\r | |
116 | {\r | |
43263288 | 117 | UINT32 LSR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_LSR_REG;\r |
a3f98646 | 118 | \r |
119 | if ((MmioRead8(LSR) & UART_LSR_RX_FIFO_E_MASK) == UART_LSR_RX_FIFO_E_NOT_EMPTY) {\r | |
120 | return TRUE;\r | |
121 | } else {\r | |
122 | return FALSE;\r | |
123 | }\r | |
124 | }\r | |
125 | \r | |
7d49ced0 | 126 | /**\r |
127 | Set the serial device control bits.\r | |
128 | \r | |
129 | @return Always return EFI_UNSUPPORTED.\r | |
130 | \r | |
131 | **/\r | |
132 | RETURN_STATUS\r | |
133 | EFIAPI\r | |
134 | SerialPortSetControl (\r | |
135 | IN UINT32 Control\r | |
136 | )\r | |
137 | {\r | |
138 | return RETURN_SUCCESS;\r | |
139 | }\r | |
140 | \r | |
141 | /**\r | |
142 | Get the serial device control bits.\r | |
143 | \r | |
144 | @param Control Control signals read from the serial device.\r | |
145 | \r | |
146 | @retval EFI_SUCCESS The control bits were read from the serial device.\r | |
147 | @retval EFI_DEVICE_ERROR The serial device is not functioning correctly.\r | |
148 | \r | |
149 | **/\r | |
150 | RETURN_STATUS\r | |
151 | EFIAPI\r | |
152 | SerialPortGetControl (\r | |
153 | OUT UINT32 *Control\r | |
154 | )\r | |
155 | {\r | |
156 | return RETURN_SUCCESS;\r | |
157 | }\r | |
158 | \r | |
159 | \r | |
160 | /**\r | |
161 | Set the serial device attributes.\r | |
162 | \r | |
163 | @return Always return EFI_UNSUPPORTED.\r | |
164 | \r | |
165 | **/\r | |
166 | RETURN_STATUS\r | |
167 | EFIAPI\r | |
168 | SerialPortSetAttributes (\r | |
169 | IN UINT64 BaudRate,\r | |
170 | IN UINT32 ReceiveFifoDepth,\r | |
171 | IN UINT32 Timeout,\r | |
172 | IN EFI_PARITY_TYPE Parity,\r | |
173 | IN UINT8 DataBits,\r | |
174 | IN EFI_STOP_BITS_TYPE StopBits\r | |
175 | )\r | |
176 | {\r | |
177 | return RETURN_SUCCESS;\r | |
178 | }\r | |
179 | \r |