]>
git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/Drivers/PL011Uart/PL011Uart.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>
19 #include <Library/IoLib.h>
21 #include <Drivers/PL011Uart.h>
25 Programmed hardware of Serial port.
27 @return Always return EFI_UNSUPPORTED.
38 if (BaudRate
== 115200) {
39 // Initialize baud rate generator
40 MmioWrite32 (UartBase
+ UARTIBRD
, UART_115200_IDIV
);
41 MmioWrite32 (UartBase
+ UARTFBRD
, UART_115200_FDIV
);
42 } else if (BaudRate
== 38400) {
43 // Initialize baud rate generator
44 MmioWrite32 (UartBase
+ UARTIBRD
, UART_38400_IDIV
);
45 MmioWrite32 (UartBase
+ UARTFBRD
, UART_38400_FDIV
);
46 } else if (BaudRate
== 19200) {
47 // Initialize baud rate generator
48 MmioWrite32 (UartBase
+ UARTIBRD
, UART_19200_IDIV
);
49 MmioWrite32 (UartBase
+ UARTFBRD
, UART_19200_FDIV
);
51 return EFI_INVALID_PARAMETER
;
54 // No parity, 1 stop, no fifo, 8 data bits
55 MmioWrite32 (UartBase
+ UARTLCR_H
, LineControl
);
57 // Clear any pending errors
58 MmioWrite32 (UartBase
+ UARTECR
, 0);
60 // Enable tx, rx, and uart overall
61 MmioWrite32 (UartBase
+ UARTCR
, PL011_UARTCR_RXE
| PL011_UARTCR_TXE
| PL011_UARTCR_UARTEN
);
67 Write data to serial device.
69 @param Buffer Point of data buffer which need to be written.
70 @param NumberOfBytes Number of output bytes which are cached in Buffer.
72 @retval 0 Write data failed.
73 @retval !0 Actual number of bytes written to serial device.
81 IN UINTN NumberOfBytes
86 for (Count
= 0; Count
< NumberOfBytes
; Count
++, Buffer
++) {
87 while ((MmioRead32 (UartBase
+ UARTFR
) & UART_TX_EMPTY_FLAG_MASK
) == 0);
88 MmioWrite8 (UartBase
+ UARTDR
, *Buffer
);
95 Read data from serial device and save the data in buffer.
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 Read data failed.
101 @retval !0 Actual number of bytes read from serial device.
109 IN UINTN NumberOfBytes
114 for (Count
= 0; Count
< NumberOfBytes
; Count
++, Buffer
++) {
115 while ((MmioRead32 (UartBase
+ UARTFR
) & UART_RX_EMPTY_FLAG_MASK
) != 0);
116 *Buffer
= MmioRead8 (UartBase
+ UARTDR
);
119 return NumberOfBytes
;
123 Check to see if any data is available to be read from the debug device.
125 @retval EFI_SUCCESS At least one byte of data is available to be read
126 @retval EFI_NOT_READY No data is available to be read
127 @retval EFI_DEVICE_ERROR The serial device is not functioning properly
136 return ((MmioRead32 (UartBase
+ UARTFR
) & UART_RX_EMPTY_FLAG_MASK
) == 0);