]>
git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/Library/PL011SerialPortLib/PL011SerialPortLib.c
2 Serial I/O Port library functions with no library constructor/destructor
5 Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
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
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.
17 #include <Include/Uefi.h>
18 #include <Library/SerialPortLib.h>
19 #include <Library/IoLib.h>
20 #include <Drivers/PL011Uart.h>
21 #include <ArmPlatform.h>
25 Programmed hardware of Serial port.
27 @return Always return EFI_UNSUPPORTED.
32 SerialPortInitialize (
36 if (PL011_CONSOLE_UART_SPEED
== 115200) {
37 // Initialize baud rate generator
38 MmioWrite32 (PL011_CONSOLE_UART_BASE
+ UARTIBRD
, UART_115200_IDIV
);
39 MmioWrite32 (PL011_CONSOLE_UART_BASE
+ UARTFBRD
, UART_115200_FDIV
);
40 } else if (PL011_CONSOLE_UART_SPEED
== 38400) {
41 // Initialize baud rate generator
42 MmioWrite32 (PL011_CONSOLE_UART_BASE
+ UARTIBRD
, UART_38400_IDIV
);
43 MmioWrite32 (PL011_CONSOLE_UART_BASE
+ UARTFBRD
, UART_38400_FDIV
);
44 } else if (PL011_CONSOLE_UART_SPEED
== 19200) {
45 // Initialize baud rate generator
46 MmioWrite32 (PL011_CONSOLE_UART_BASE
+ UARTIBRD
, UART_19200_IDIV
);
47 MmioWrite32 (PL011_CONSOLE_UART_BASE
+ UARTFBRD
, UART_19200_FDIV
);
49 return EFI_INVALID_PARAMETER
;
52 // No parity, 1 stop, no fifo, 8 data bits
53 MmioWrite32 (PL011_CONSOLE_UART_BASE
+ UARTLCR_H
, 0x60);
55 // Clear any pending errors
56 MmioWrite32 (PL011_CONSOLE_UART_BASE
+ UARTECR
, 0);
58 // enable tx, rx, and uart overall
59 MmioWrite32 (PL011_CONSOLE_UART_BASE
+ UARTCR
, 0x301);
65 Write data to serial device.
67 @param Buffer Point of data buffer which need to be writed.
68 @param NumberOfBytes Number of output bytes which are cached in Buffer.
70 @retval 0 Write data failed.
71 @retval !0 Actual number of bytes writed to serial device.
78 IN UINTN NumberOfBytes
83 for (Count
= 0; Count
< NumberOfBytes
; Count
++, Buffer
++) {
84 while ((MmioRead32 (PL011_CONSOLE_UART_BASE
+ UARTFR
) & UART_TX_EMPTY_FLAG_MASK
) == 0);
85 MmioWrite8 (PL011_CONSOLE_UART_BASE
+ UARTDR
, *Buffer
);
92 Read data from serial device and save the datas in buffer.
94 @param Buffer Point of data buffer which need to be writed.
95 @param NumberOfBytes Number of output bytes which are cached in Buffer.
97 @retval 0 Read data failed.
98 @retval !0 Aactual number of bytes read from serial device.
105 IN UINTN NumberOfBytes
110 for (Count
= 0; Count
< NumberOfBytes
; Count
++, Buffer
++) {
111 while ((MmioRead32 (PL011_CONSOLE_UART_BASE
+ UARTFR
) & UART_RX_EMPTY_FLAG_MASK
) != 0);
112 *Buffer
= MmioRead8 (PL011_CONSOLE_UART_BASE
+ UARTDR
);
115 return NumberOfBytes
;
119 Check to see if any data is avaiable to be read from the debug device.
121 @retval EFI_SUCCESS At least one byte of data is avaiable to be read
122 @retval EFI_NOT_READY No data is avaiable to be read
123 @retval EFI_DEVICE_ERROR The serial device is not functioning properly
132 return ((MmioRead32 (PL011_CONSOLE_UART_BASE
+ UARTFR
) & UART_RX_EMPTY_FLAG_MASK
) == 0);