]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/Library/PL011SerialPortLib/PL011SerialPortLib.c
ArmPlatformPkg/PL031RealTimeClockLib: Fixed the conditions in LibSetTime()
[mirror_edk2.git] / ArmPlatformPkg / Library / PL011SerialPortLib / PL011SerialPortLib.c
1 /** @file
2 Serial I/O Port library functions with no library constructor/destructor
3
4 Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
5 Copyright (c) 2012 - 2013, ARM Ltd. All rights reserved.<BR>
6
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15 **/
16
17 #include <Base.h>
18
19 #include <Library/IoLib.h>
20 #include <Library/PcdLib.h>
21 #include <Library/SerialPortLib.h>
22 #include <Library/SerialPortExtLib.h>
23
24 #include <Drivers/PL011Uart.h>
25
26
27 /**
28
29 Programmed hardware of Serial port.
30
31 @return Always return RETURN_UNSUPPORTED.
32
33 **/
34 RETURN_STATUS
35 EFIAPI
36 SerialPortInitialize (
37 VOID
38 )
39 {
40 UINT64 BaudRate;
41 UINT32 ReceiveFifoDepth;
42 EFI_PARITY_TYPE Parity;
43 UINT8 DataBits;
44 EFI_STOP_BITS_TYPE StopBits;
45
46 BaudRate = (UINTN)PcdGet64 (PcdUartDefaultBaudRate);
47 ReceiveFifoDepth = 0; // Use the default value for Fifo depth
48 Parity = (EFI_PARITY_TYPE)PcdGet8 (PcdUartDefaultParity);
49 DataBits = PcdGet8 (PcdUartDefaultDataBits);
50 StopBits = (EFI_STOP_BITS_TYPE) PcdGet8 (PcdUartDefaultStopBits);
51
52 return PL011UartInitializePort (
53 (UINTN)PcdGet64 (PcdSerialRegisterBase),
54 &BaudRate, &ReceiveFifoDepth, &Parity, &DataBits, &StopBits);
55 }
56
57 /**
58 Write data to serial device.
59
60 @param Buffer Point of data buffer which need to be written.
61 @param NumberOfBytes Number of output bytes which are cached in Buffer.
62
63 @retval 0 Write data failed.
64 @retval !0 Actual number of bytes written to serial device.
65
66 **/
67 UINTN
68 EFIAPI
69 SerialPortWrite (
70 IN UINT8 *Buffer,
71 IN UINTN NumberOfBytes
72 )
73 {
74 return PL011UartWrite ((UINTN)PcdGet64 (PcdSerialRegisterBase), Buffer, NumberOfBytes);
75 }
76
77 /**
78 Read data from serial device and save the data in buffer.
79
80 @param Buffer Point of data buffer which need to be written.
81 @param NumberOfBytes Number of output bytes which are cached in Buffer.
82
83 @retval 0 Read data failed.
84 @retval !0 Actual number of bytes read from serial device.
85
86 **/
87 UINTN
88 EFIAPI
89 SerialPortRead (
90 OUT UINT8 *Buffer,
91 IN UINTN NumberOfBytes
92 )
93 {
94 return PL011UartRead ((UINTN)PcdGet64 (PcdSerialRegisterBase), Buffer, NumberOfBytes);
95 }
96
97 /**
98 Check to see if any data is available to be read from the debug device.
99
100 @retval EFI_SUCCESS At least one byte of data is available to be read
101 @retval EFI_NOT_READY No data is available to be read
102 @retval EFI_DEVICE_ERROR The serial device is not functioning properly
103
104 **/
105 BOOLEAN
106 EFIAPI
107 SerialPortPoll (
108 VOID
109 )
110 {
111 return PL011UartPoll ((UINTN)PcdGet64 (PcdSerialRegisterBase));
112 }
113