2 Serial I/O Port library functions with base address discovered from FDT
4 Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
5 Copyright (c) 2012 - 2013, ARM Ltd. All rights reserved.<BR>
6 Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>
7 Copyright (c) 2014, Red Hat, Inc.<BR>
8 Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
10 This program and the accompanying materials
11 are licensed and made available under the terms and conditions of the BSD License
12 which accompanies this distribution. The full text of the license may be found at
13 http://opensource.org/licenses/bsd-license.php
15 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
16 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
22 #include <Library/PcdLib.h>
23 #include <Library/SerialPortLib.h>
24 #include <Pi/PiBootMode.h>
25 #include <Uefi/UefiBaseType.h>
26 #include <Uefi/UefiMultiPhase.h>
28 #include <Library/HobLib.h>
29 #include <Guid/EarlyPL011BaseAddress.h>
31 #include <Drivers/PL011Uart.h>
33 STATIC UINTN mSerialBaseAddress
;
37 SerialPortInitialize (
41 return RETURN_SUCCESS
;
46 Program hardware of Serial port
48 @return RETURN_NOT_FOUND if no PL011 base address could be found
49 Otherwise, result of PL011UartInitializePort () is returned
54 FdtPL011SerialPortLibInitialize (
59 CONST UINT64
*UartBase
;
61 UINT32 ReceiveFifoDepth
;
62 EFI_PARITY_TYPE Parity
;
64 EFI_STOP_BITS_TYPE StopBits
;
66 Hob
= GetFirstGuidHob (&gEarlyPL011BaseAddressGuid
);
67 if (Hob
== NULL
|| GET_GUID_HOB_DATA_SIZE (Hob
) != sizeof *UartBase
) {
68 return RETURN_NOT_FOUND
;
70 UartBase
= GET_GUID_HOB_DATA (Hob
);
72 mSerialBaseAddress
= (UINTN
)*UartBase
;
73 if (mSerialBaseAddress
== 0) {
74 return RETURN_NOT_FOUND
;
77 BaudRate
= (UINTN
)PcdGet64 (PcdUartDefaultBaudRate
);
78 ReceiveFifoDepth
= 0; // Use the default value for Fifo depth
79 Parity
= (EFI_PARITY_TYPE
)PcdGet8 (PcdUartDefaultParity
);
80 DataBits
= PcdGet8 (PcdUartDefaultDataBits
);
81 StopBits
= (EFI_STOP_BITS_TYPE
) PcdGet8 (PcdUartDefaultStopBits
);
83 return PL011UartInitializePort (
85 FixedPcdGet32 (PL011UartClkInHz
),
95 Write data to serial device.
97 @param Buffer Point of data buffer which need to be written.
98 @param NumberOfBytes Number of output bytes which are cached in Buffer.
100 @retval 0 Write data failed.
101 @retval !0 Actual number of bytes written to serial device.
108 IN UINTN NumberOfBytes
111 if (mSerialBaseAddress
!= 0) {
112 return PL011UartWrite (mSerialBaseAddress
, Buffer
, NumberOfBytes
);
118 Read data from serial device and save the data in buffer.
120 @param Buffer Point of data buffer which need to be written.
121 @param NumberOfBytes Number of output bytes which are cached in Buffer.
123 @retval 0 Read data failed.
124 @retval !0 Actual number of bytes read from serial device.
131 IN UINTN NumberOfBytes
134 if (mSerialBaseAddress
!= 0) {
135 return PL011UartRead (mSerialBaseAddress
, Buffer
, NumberOfBytes
);
141 Check to see if any data is available to be read from the debug device.
143 @retval TRUE At least one byte of data is available to be read
144 @retval FALSE No data is available to be read
153 if (mSerialBaseAddress
!= 0) {
154 return PL011UartPoll (mSerialBaseAddress
);
160 Sets the baud rate, receive FIFO depth, transmit/receice time out, parity,
161 data bits, and stop bits on a serial device.
163 @param BaudRate The requested baud rate. A BaudRate value of 0 will use the
164 device's default interface speed.
165 On output, the value actually set.
166 @param ReveiveFifoDepth The requested depth of the FIFO on the receive side of the
167 serial interface. A ReceiveFifoDepth value of 0 will use
168 the device's default FIFO depth.
169 On output, the value actually set.
170 @param Timeout The requested time out for a single character in microseconds.
171 This timeout applies to both the transmit and receive side of the
172 interface. A Timeout value of 0 will use the device's default time
174 On output, the value actually set.
175 @param Parity The type of parity to use on this serial device. A Parity value of
176 DefaultParity will use the device's default parity value.
177 On output, the value actually set.
178 @param DataBits The number of data bits to use on the serial device. A DataBits
179 vaule of 0 will use the device's default data bit setting.
180 On output, the value actually set.
181 @param StopBits The number of stop bits to use on this serial device. A StopBits
182 value of DefaultStopBits will use the device's default number of
184 On output, the value actually set.
186 @retval RETURN_SUCCESS The new attributes were set on the serial device.
187 @retval RETURN_UNSUPPORTED The serial device does not support this operation.
188 @retval RETURN_INVALID_PARAMETER One or more of the attributes has an unsupported value.
189 @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.
194 SerialPortSetAttributes (
195 IN OUT UINT64
*BaudRate
,
196 IN OUT UINT32
*ReceiveFifoDepth
,
197 IN OUT UINT32
*Timeout
,
198 IN OUT EFI_PARITY_TYPE
*Parity
,
199 IN OUT UINT8
*DataBits
,
200 IN OUT EFI_STOP_BITS_TYPE
*StopBits
203 return RETURN_UNSUPPORTED
;
207 Sets the control bits on a serial device.
209 @param Control Sets the bits of Control that are settable.
211 @retval RETURN_SUCCESS The new control bits were set on the serial device.
212 @retval RETURN_UNSUPPORTED The serial device does not support this operation.
213 @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.
218 SerialPortSetControl (
222 return RETURN_UNSUPPORTED
;
226 Retrieve the status of the control bits on a serial device.
228 @param Control A pointer to return the current control signals from the serial device.
230 @retval RETURN_SUCCESS The control bits were read from the serial device.
231 @retval RETURN_UNSUPPORTED The serial device does not support this operation.
232 @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.
237 SerialPortGetControl (
241 return RETURN_UNSUPPORTED
;