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 SPDX-License-Identifier: BSD-2-Clause-Patent
14 #include <Library/IoLib.h>
15 #include <Library/PcdLib.h>
16 #include <Library/PL011UartClockLib.h>
17 #include <Library/PL011UartLib.h>
18 #include <Library/SerialPortLib.h>
20 /** Initialise the serial device hardware with default settings.
22 @retval RETURN_SUCCESS The serial device was initialised.
23 @retval RETURN_INVALID_PARAMETER One or more of the default settings
24 has an unsupported value.
28 SerialPortInitialize (
33 UINT32 ReceiveFifoDepth
;
34 EFI_PARITY_TYPE Parity
;
36 EFI_STOP_BITS_TYPE StopBits
;
38 BaudRate
= FixedPcdGet64 (PcdUartDefaultBaudRate
);
39 ReceiveFifoDepth
= 0; // Use default FIFO depth
40 Parity
= (EFI_PARITY_TYPE
)FixedPcdGet8 (PcdUartDefaultParity
);
41 DataBits
= FixedPcdGet8 (PcdUartDefaultDataBits
);
42 StopBits
= (EFI_STOP_BITS_TYPE
)FixedPcdGet8 (PcdUartDefaultStopBits
);
44 return PL011UartInitializePort (
45 (UINTN
)PcdGet64 (PcdSerialRegisterBase
),
46 PL011UartClockGetFreq (),
56 Write data to serial device.
58 @param Buffer Point of data buffer which need to be written.
59 @param NumberOfBytes Number of output bytes which are cached in Buffer.
61 @retval 0 Write data failed.
62 @retval !0 Actual number of bytes written to serial device.
69 IN UINTN NumberOfBytes
72 return PL011UartWrite ((UINTN
)PcdGet64 (PcdSerialRegisterBase
), Buffer
, NumberOfBytes
);
76 Read data from serial device and save the data in buffer.
78 @param Buffer Point of data buffer which need to be written.
79 @param NumberOfBytes Number of output bytes which are cached in Buffer.
81 @retval 0 Read data failed.
82 @retval !0 Actual number of bytes read from serial device.
89 IN UINTN NumberOfBytes
92 return PL011UartRead ((UINTN
)PcdGet64 (PcdSerialRegisterBase
), Buffer
, NumberOfBytes
);
96 Check to see if any data is available to be read from the debug device.
98 @retval TRUE At least one byte of data is available to be read
99 @retval FALSE No data is available to be read
108 return PL011UartPoll ((UINTN
)PcdGet64 (PcdSerialRegisterBase
));
112 Set new attributes to PL011.
114 @param BaudRate The baud rate of the serial device. If the
115 baud rate is not supported, the speed will
116 be reduced down to the nearest supported one
117 and the variable's value will be updated
119 @param ReceiveFifoDepth The number of characters the device will
120 buffer on input. If the specified value is
121 not supported, the variable's value will
122 be reduced down to the nearest supported one.
123 @param Timeout If applicable, the number of microseconds the
124 device will wait before timing out a Read or
126 @param Parity If applicable, this is the EFI_PARITY_TYPE
127 that is computed or checked as each character
128 is transmitted or received. If the device
129 does not support parity, the value is the
130 default parity value.
131 @param DataBits The number of data bits in each character
132 @param StopBits If applicable, the EFI_STOP_BITS_TYPE number
133 of stop bits per character. If the device
134 does not support stop bits, the value is the
135 default stop bit value.
137 @retval EFI_SUCCESS All attributes were set correctly.
138 @retval EFI_INVALID_PARAMETERS One or more attributes has an unsupported
144 SerialPortSetAttributes (
145 IN OUT UINT64
*BaudRate
,
146 IN OUT UINT32
*ReceiveFifoDepth
,
147 IN OUT UINT32
*Timeout
,
148 IN OUT EFI_PARITY_TYPE
*Parity
,
149 IN OUT UINT8
*DataBits
,
150 IN OUT EFI_STOP_BITS_TYPE
*StopBits
153 return PL011UartInitializePort (
154 (UINTN
)PcdGet64 (PcdSerialRegisterBase
),
155 PL011UartClockGetFreq (),
166 Assert or deassert the control signals on a serial port.
167 The following control signals are set according their bit settings :
169 . Data Terminal Ready
171 @param[in] Control The following bits are taken into account :
172 . EFI_SERIAL_REQUEST_TO_SEND : assert/deassert the
173 "Request To Send" control signal if this bit is
175 . EFI_SERIAL_DATA_TERMINAL_READY : assert/deassert
176 the "Data Terminal Ready" control signal if this
177 bit is equal to one/zero.
178 . EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE : enable/disable
179 the hardware loopback if this bit is equal to
181 . EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE : not supported.
182 . EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE : enable/
183 disable the hardware flow control based on CTS (Clear
184 To Send) and RTS (Ready To Send) control signals.
186 @retval RETURN_SUCCESS The new control bits were set on the device.
187 @retval RETURN_UNSUPPORTED The device does not support this operation.
192 SerialPortSetControl (
196 return PL011UartSetControl ((UINTN
)PcdGet64 (PcdSerialRegisterBase
), Control
);
201 Retrieve the status of the control bits on a serial device.
203 @param[out] Control Status of the control bits on a serial device :
205 . EFI_SERIAL_DATA_CLEAR_TO_SEND,
206 EFI_SERIAL_DATA_SET_READY,
207 EFI_SERIAL_RING_INDICATE,
208 EFI_SERIAL_CARRIER_DETECT,
209 EFI_SERIAL_REQUEST_TO_SEND,
210 EFI_SERIAL_DATA_TERMINAL_READY
211 are all related to the DTE (Data Terminal Equipment)
212 and DCE (Data Communication Equipment) modes of
213 operation of the serial device.
214 . EFI_SERIAL_INPUT_BUFFER_EMPTY : equal to one if the
215 receive buffer is empty, 0 otherwise.
216 . EFI_SERIAL_OUTPUT_BUFFER_EMPTY : equal to one if the
217 transmit buffer is empty, 0 otherwise.
218 . EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE : equal to one if
219 the hardware loopback is enabled (the output feeds
220 the receive buffer), 0 otherwise.
221 . EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE : equal to one
222 if a loopback is accomplished by software, else 0.
223 . EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE : equal to
224 one if the hardware flow control based on CTS (Clear
225 To Send) and RTS (Ready To Send) control signals is
226 enabled, 0 otherwise.
228 @retval RETURN_SUCCESS The control bits were read from the device.
233 SerialPortGetControl (
237 return PL011UartGetControl ((UINTN
)PcdGet64 (PcdSerialRegisterBase
), Control
);