2 Serial I/O Port library functions with no library constructor/destructor
4 Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
5 Copyright (c) 2012 - 2016, ARM Ltd. All rights reserved.<BR>
6 Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
8 This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 #include <Library/IoLib.h>
21 #include <Library/PcdLib.h>
22 #include <Library/SerialPortLib.h>
24 #include <Drivers/PL011Uart.h>
26 /** Initialise the serial device hardware with default settings.
28 @retval RETURN_SUCCESS The serial device was initialised.
29 @retval RETURN_INVALID_PARAMETER One or more of the default settings
30 has an unsupported value.
34 SerialPortInitialize (
39 UINT32 ReceiveFifoDepth
;
40 EFI_PARITY_TYPE Parity
;
42 EFI_STOP_BITS_TYPE StopBits
;
44 BaudRate
= FixedPcdGet64 (PcdUartDefaultBaudRate
);
45 ReceiveFifoDepth
= 0; // Use default FIFO depth
46 Parity
= (EFI_PARITY_TYPE
)FixedPcdGet8 (PcdUartDefaultParity
);
47 DataBits
= FixedPcdGet8 (PcdUartDefaultDataBits
);
48 StopBits
= (EFI_STOP_BITS_TYPE
) FixedPcdGet8 (PcdUartDefaultStopBits
);
50 return PL011UartInitializePort (
51 (UINTN
)FixedPcdGet64 (PcdSerialRegisterBase
),
52 FixedPcdGet32 (PL011UartClkInHz
),
62 Write data to serial device.
64 @param Buffer Point of data buffer which need to be written.
65 @param NumberOfBytes Number of output bytes which are cached in Buffer.
67 @retval 0 Write data failed.
68 @retval !0 Actual number of bytes written to serial device.
75 IN UINTN NumberOfBytes
78 return PL011UartWrite ((UINTN
)FixedPcdGet64 (PcdSerialRegisterBase
), Buffer
, NumberOfBytes
);
82 Read data from serial device and save the data in buffer.
84 @param Buffer Point of data buffer which need to be written.
85 @param NumberOfBytes Number of output bytes which are cached in Buffer.
87 @retval 0 Read data failed.
88 @retval !0 Actual number of bytes read from serial device.
95 IN UINTN NumberOfBytes
98 return PL011UartRead ((UINTN
)FixedPcdGet64 (PcdSerialRegisterBase
), Buffer
, NumberOfBytes
);
102 Check to see if any data is available to be read from the debug device.
104 @retval TRUE At least one byte of data is available to be read
105 @retval FALSE No data is available to be read
114 return PL011UartPoll ((UINTN
)FixedPcdGet64 (PcdSerialRegisterBase
));
117 Set new attributes to PL011.
119 @param BaudRate The baud rate of the serial device. If the
120 baud rate is not supported, the speed will
121 be reduced down to the nearest supported one
122 and the variable's value will be updated
124 @param ReceiveFifoDepth The number of characters the device will
125 buffer on input. If the specified value is
126 not supported, the variable's value will
127 be reduced down to the nearest supported one.
128 @param Timeout If applicable, the number of microseconds the
129 device will wait before timing out a Read or
131 @param Parity If applicable, this is the EFI_PARITY_TYPE
132 that is computed or checked as each character
133 is transmitted or received. If the device
134 does not support parity, the value is the
135 default parity value.
136 @param DataBits The number of data bits in each character
137 @param StopBits If applicable, the EFI_STOP_BITS_TYPE number
138 of stop bits per character. If the device
139 does not support stop bits, the value is the
140 default stop bit value.
142 @retval EFI_SUCCESS All attributes were set correctly.
143 @retval EFI_INVALID_PARAMETERS One or more attributes has an unsupported
149 SerialPortSetAttributes (
150 IN OUT UINT64
*BaudRate
,
151 IN OUT UINT32
*ReceiveFifoDepth
,
152 IN OUT UINT32
*Timeout
,
153 IN OUT EFI_PARITY_TYPE
*Parity
,
154 IN OUT UINT8
*DataBits
,
155 IN OUT EFI_STOP_BITS_TYPE
*StopBits
158 return PL011UartInitializePort (
159 (UINTN
)FixedPcdGet64 (PcdSerialRegisterBase
),
160 FixedPcdGet32 (PL011UartClkInHz
),
171 Assert or deassert the control signals on a serial port.
172 The following control signals are set according their bit settings :
174 . Data Terminal Ready
176 @param[in] Control The following bits are taken into account :
177 . EFI_SERIAL_REQUEST_TO_SEND : assert/deassert the
178 "Request To Send" control signal if this bit is
180 . EFI_SERIAL_DATA_TERMINAL_READY : assert/deassert
181 the "Data Terminal Ready" control signal if this
182 bit is equal to one/zero.
183 . EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE : enable/disable
184 the hardware loopback if this bit is equal to
186 . EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE : not supported.
187 . EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE : enable/
188 disable the hardware flow control based on CTS (Clear
189 To Send) and RTS (Ready To Send) control signals.
191 @retval RETURN_SUCCESS The new control bits were set on the device.
192 @retval RETURN_UNSUPPORTED The device does not support this operation.
197 SerialPortSetControl (
201 return PL011UartSetControl ((UINTN
)FixedPcdGet64 (PcdSerialRegisterBase
), Control
);
206 Retrieve the status of the control bits on a serial device.
208 @param[out] Control Status of the control bits on a serial device :
210 . EFI_SERIAL_DATA_CLEAR_TO_SEND,
211 EFI_SERIAL_DATA_SET_READY,
212 EFI_SERIAL_RING_INDICATE,
213 EFI_SERIAL_CARRIER_DETECT,
214 EFI_SERIAL_REQUEST_TO_SEND,
215 EFI_SERIAL_DATA_TERMINAL_READY
216 are all related to the DTE (Data Terminal Equipment)
217 and DCE (Data Communication Equipment) modes of
218 operation of the serial device.
219 . EFI_SERIAL_INPUT_BUFFER_EMPTY : equal to one if the
220 receive buffer is empty, 0 otherwise.
221 . EFI_SERIAL_OUTPUT_BUFFER_EMPTY : equal to one if the
222 transmit buffer is empty, 0 otherwise.
223 . EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE : equal to one if
224 the hardware loopback is enabled (the output feeds
225 the receive buffer), 0 otherwise.
226 . EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE : equal to one
227 if a loopback is accomplished by software, else 0.
228 . EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE : equal to
229 one if the hardware flow control based on CTS (Clear
230 To Send) and RTS (Ready To Send) control signals is
231 enabled, 0 otherwise.
233 @retval RETURN_SUCCESS The control bits were read from the device.
238 SerialPortGetControl (
242 return PL011UartGetControl ((UINTN
)FixedPcdGet64 (PcdSerialRegisterBase
), Control
);