]>
Commit | Line | Data |
---|---|---|
f1f0ba19 LE |
1 | /** @file\r |
2 | Serial I/O Port library functions with base address discovered from FDT\r | |
3 | \r | |
4 | Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r | |
5 | Copyright (c) 2012 - 2013, ARM Ltd. All rights reserved.<BR>\r | |
6 | Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>\r | |
7 | Copyright (c) 2014, Red Hat, Inc.<BR>\r | |
ad7f6bc2 | 8 | Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r |
f1f0ba19 LE |
9 | \r |
10 | This program and the accompanying materials\r | |
11 | are licensed and made available under the terms and conditions of the BSD License\r | |
12 | which accompanies this distribution. The full text of the license may be found at\r | |
13 | http://opensource.org/licenses/bsd-license.php\r | |
14 | \r | |
15 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
16 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
17 | \r | |
18 | **/\r | |
19 | \r | |
20 | #include <Base.h>\r | |
21 | \r | |
22 | #include <Library/PcdLib.h>\r | |
23 | #include <Library/SerialPortLib.h>\r | |
24 | #include <Pi/PiBootMode.h>\r | |
25 | #include <Uefi/UefiBaseType.h>\r | |
26 | #include <Uefi/UefiMultiPhase.h>\r | |
27 | #include <Pi/PiHob.h>\r | |
28 | #include <Library/HobLib.h>\r | |
29 | #include <Guid/EarlyPL011BaseAddress.h>\r | |
30 | \r | |
31 | #include <Drivers/PL011Uart.h>\r | |
32 | \r | |
33 | STATIC UINTN mSerialBaseAddress;\r | |
34 | \r | |
35 | RETURN_STATUS\r | |
36 | EFIAPI\r | |
37 | SerialPortInitialize (\r | |
38 | VOID\r | |
39 | )\r | |
40 | {\r | |
41 | return RETURN_SUCCESS;\r | |
42 | }\r | |
43 | \r | |
44 | /**\r | |
45 | \r | |
46 | Program hardware of Serial port\r | |
47 | \r | |
48 | @return RETURN_NOT_FOUND if no PL011 base address could be found\r | |
49 | Otherwise, result of PL011UartInitializePort () is returned\r | |
50 | \r | |
51 | **/\r | |
52 | RETURN_STATUS\r | |
53 | EFIAPI\r | |
54 | FdtPL011SerialPortLibInitialize (\r | |
55 | VOID\r | |
56 | )\r | |
57 | {\r | |
58 | VOID *Hob;\r | |
59 | CONST UINT64 *UartBase;\r | |
60 | UINT64 BaudRate;\r | |
61 | UINT32 ReceiveFifoDepth;\r | |
62 | EFI_PARITY_TYPE Parity;\r | |
63 | UINT8 DataBits;\r | |
64 | EFI_STOP_BITS_TYPE StopBits;\r | |
65 | \r | |
66 | Hob = GetFirstGuidHob (&gEarlyPL011BaseAddressGuid);\r | |
67 | if (Hob == NULL || GET_GUID_HOB_DATA_SIZE (Hob) != sizeof *UartBase) {\r | |
68 | return RETURN_NOT_FOUND;\r | |
69 | }\r | |
70 | UartBase = GET_GUID_HOB_DATA (Hob);\r | |
71 | \r | |
72 | mSerialBaseAddress = (UINTN)*UartBase;\r | |
73 | if (mSerialBaseAddress == 0) {\r | |
74 | return RETURN_NOT_FOUND;\r | |
75 | }\r | |
76 | \r | |
77 | BaudRate = (UINTN)PcdGet64 (PcdUartDefaultBaudRate);\r | |
78 | ReceiveFifoDepth = 0; // Use the default value for Fifo depth\r | |
79 | Parity = (EFI_PARITY_TYPE)PcdGet8 (PcdUartDefaultParity);\r | |
80 | DataBits = PcdGet8 (PcdUartDefaultDataBits);\r | |
81 | StopBits = (EFI_STOP_BITS_TYPE) PcdGet8 (PcdUartDefaultStopBits);\r | |
82 | \r | |
83 | return PL011UartInitializePort (\r | |
090916d8 EL |
84 | mSerialBaseAddress,\r |
85 | FixedPcdGet32 (PL011UartClkInHz),\r | |
86 | &BaudRate,\r | |
87 | &ReceiveFifoDepth,\r | |
88 | &Parity,\r | |
89 | &DataBits,\r | |
90 | &StopBits\r | |
91 | );\r | |
f1f0ba19 LE |
92 | }\r |
93 | \r | |
94 | /**\r | |
95 | Write data to serial device.\r | |
96 | \r | |
97 | @param Buffer Point of data buffer which need to be written.\r | |
98 | @param NumberOfBytes Number of output bytes which are cached in Buffer.\r | |
99 | \r | |
100 | @retval 0 Write data failed.\r | |
101 | @retval !0 Actual number of bytes written to serial device.\r | |
102 | \r | |
103 | **/\r | |
104 | UINTN\r | |
105 | EFIAPI\r | |
106 | SerialPortWrite (\r | |
107 | IN UINT8 *Buffer,\r | |
108 | IN UINTN NumberOfBytes\r | |
109 | )\r | |
110 | {\r | |
111 | if (mSerialBaseAddress != 0) {\r | |
112 | return PL011UartWrite (mSerialBaseAddress, Buffer, NumberOfBytes);\r | |
113 | }\r | |
114 | return 0;\r | |
115 | }\r | |
116 | \r | |
117 | /**\r | |
118 | Read data from serial device and save the data in buffer.\r | |
119 | \r | |
120 | @param Buffer Point of data buffer which need to be written.\r | |
121 | @param NumberOfBytes Number of output bytes which are cached in Buffer.\r | |
122 | \r | |
123 | @retval 0 Read data failed.\r | |
124 | @retval !0 Actual number of bytes read from serial device.\r | |
125 | \r | |
126 | **/\r | |
127 | UINTN\r | |
128 | EFIAPI\r | |
129 | SerialPortRead (\r | |
130 | OUT UINT8 *Buffer,\r | |
131 | IN UINTN NumberOfBytes\r | |
132 | )\r | |
133 | {\r | |
134 | if (mSerialBaseAddress != 0) {\r | |
135 | return PL011UartRead (mSerialBaseAddress, Buffer, NumberOfBytes);\r | |
136 | }\r | |
137 | return 0;\r | |
138 | }\r | |
139 | \r | |
140 | /**\r | |
141 | Check to see if any data is available to be read from the debug device.\r | |
142 | \r | |
143 | @retval TRUE At least one byte of data is available to be read\r | |
144 | @retval FALSE No data is available to be read\r | |
145 | \r | |
146 | **/\r | |
147 | BOOLEAN\r | |
148 | EFIAPI\r | |
149 | SerialPortPoll (\r | |
150 | VOID\r | |
151 | )\r | |
152 | {\r | |
153 | if (mSerialBaseAddress != 0) {\r | |
154 | return PL011UartPoll (mSerialBaseAddress);\r | |
155 | }\r | |
156 | return FALSE;\r | |
157 | }\r | |
ad7f6bc2 SZ |
158 | \r |
159 | /**\r | |
160 | Sets the baud rate, receive FIFO depth, transmit/receice time out, parity,\r | |
161 | data bits, and stop bits on a serial device.\r | |
162 | \r | |
163 | @param BaudRate The requested baud rate. A BaudRate value of 0 will use the\r | |
164 | device's default interface speed.\r | |
165 | On output, the value actually set.\r | |
166 | @param ReveiveFifoDepth The requested depth of the FIFO on the receive side of the\r | |
167 | serial interface. A ReceiveFifoDepth value of 0 will use\r | |
168 | the device's default FIFO depth.\r | |
169 | On output, the value actually set.\r | |
170 | @param Timeout The requested time out for a single character in microseconds.\r | |
171 | This timeout applies to both the transmit and receive side of the\r | |
172 | interface. A Timeout value of 0 will use the device's default time\r | |
173 | out value.\r | |
174 | On output, the value actually set.\r | |
175 | @param Parity The type of parity to use on this serial device. A Parity value of\r | |
176 | DefaultParity will use the device's default parity value.\r | |
177 | On output, the value actually set.\r | |
178 | @param DataBits The number of data bits to use on the serial device. A DataBits\r | |
179 | vaule of 0 will use the device's default data bit setting.\r | |
180 | On output, the value actually set.\r | |
181 | @param StopBits The number of stop bits to use on this serial device. A StopBits\r | |
182 | value of DefaultStopBits will use the device's default number of\r | |
183 | stop bits.\r | |
184 | On output, the value actually set.\r | |
185 | \r | |
186 | @retval RETURN_SUCCESS The new attributes were set on the serial device.\r | |
187 | @retval RETURN_UNSUPPORTED The serial device does not support this operation.\r | |
188 | @retval RETURN_INVALID_PARAMETER One or more of the attributes has an unsupported value.\r | |
189 | @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.\r | |
190 | \r | |
191 | **/\r | |
192 | RETURN_STATUS\r | |
193 | EFIAPI\r | |
194 | SerialPortSetAttributes (\r | |
195 | IN OUT UINT64 *BaudRate,\r | |
196 | IN OUT UINT32 *ReceiveFifoDepth,\r | |
197 | IN OUT UINT32 *Timeout,\r | |
198 | IN OUT EFI_PARITY_TYPE *Parity,\r | |
199 | IN OUT UINT8 *DataBits,\r | |
200 | IN OUT EFI_STOP_BITS_TYPE *StopBits\r | |
201 | )\r | |
202 | {\r | |
5f0f5e90 LE |
203 | RETURN_STATUS Status;\r |
204 | \r | |
205 | if (mSerialBaseAddress == 0) {\r | |
206 | Status = RETURN_UNSUPPORTED;\r | |
207 | } else {\r | |
208 | Status = PL011UartInitializePort (\r | |
209 | mSerialBaseAddress,\r | |
210 | FixedPcdGet32 (PL011UartClkInHz),\r | |
211 | BaudRate,\r | |
212 | ReceiveFifoDepth,\r | |
213 | Parity,\r | |
214 | DataBits,\r | |
215 | StopBits\r | |
216 | );\r | |
217 | }\r | |
218 | \r | |
219 | return Status;\r | |
ad7f6bc2 SZ |
220 | }\r |
221 | \r | |
222 | /**\r | |
223 | Sets the control bits on a serial device.\r | |
224 | \r | |
225 | @param Control Sets the bits of Control that are settable.\r | |
226 | \r | |
227 | @retval RETURN_SUCCESS The new control bits were set on the serial device.\r | |
228 | @retval RETURN_UNSUPPORTED The serial device does not support this operation.\r | |
229 | @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.\r | |
230 | \r | |
231 | **/\r | |
232 | RETURN_STATUS\r | |
233 | EFIAPI\r | |
234 | SerialPortSetControl (\r | |
235 | IN UINT32 Control\r | |
236 | )\r | |
237 | {\r | |
5f0f5e90 LE |
238 | RETURN_STATUS Status;\r |
239 | \r | |
240 | if (mSerialBaseAddress == 0) {\r | |
241 | Status = RETURN_UNSUPPORTED;\r | |
242 | } else {\r | |
243 | Status = PL011UartSetControl (mSerialBaseAddress, Control);\r | |
244 | }\r | |
245 | \r | |
246 | return Status;\r | |
ad7f6bc2 SZ |
247 | }\r |
248 | \r | |
249 | /**\r | |
250 | Retrieve the status of the control bits on a serial device.\r | |
251 | \r | |
252 | @param Control A pointer to return the current control signals from the serial device.\r | |
253 | \r | |
254 | @retval RETURN_SUCCESS The control bits were read from the serial device.\r | |
255 | @retval RETURN_UNSUPPORTED The serial device does not support this operation.\r | |
256 | @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.\r | |
257 | \r | |
258 | **/\r | |
259 | RETURN_STATUS\r | |
260 | EFIAPI\r | |
261 | SerialPortGetControl (\r | |
262 | OUT UINT32 *Control\r | |
263 | )\r | |
264 | {\r | |
5f0f5e90 LE |
265 | RETURN_STATUS Status;\r |
266 | \r | |
267 | if (mSerialBaseAddress == 0) {\r | |
268 | Status = RETURN_UNSUPPORTED;\r | |
269 | } else {\r | |
270 | Status = PL011UartGetControl (mSerialBaseAddress, Control);\r | |
271 | }\r | |
272 | \r | |
273 | return Status;\r | |
ad7f6bc2 SZ |
274 | }\r |
275 | \r |