]>
git.proxmox.com Git - mirror_edk2.git/blob - ArmRealViewEbPkg/Library/SerialPortLib/SerialPortLib.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.
18 #include <Library/SerialPortLib.h>
19 #include <Library/PcdLib.h>
20 #include <Library/IoLib.h>
22 #include <ArmEb/ArmEb.h>
26 Programmed hardware of Serial port.
28 @return Always return EFI_UNSUPPORTED.
33 SerialPortInitialize (
37 UINT32 Base
= PcdGet32 (PcdConsoleUartBase
);
39 // initialize baud rate generator to 115200 based on EB clock REFCLK24MHZ
40 MmioWrite32 (Base
+ UARTIBRD
, UART_115200_IDIV
);
41 MmioWrite32 (Base
+ UARTFBRD
, UART_115200_FDIV
);
43 // no parity, 1 stop, no fifo, 8 data bits
44 MmioWrite32 (Base
+ UARTLCR_H
, 0x60);
46 // clear any pending errors
47 MmioWrite32 (Base
+ UARTECR
, 0);
49 // enable tx, rx, and uart overall
50 MmioWrite32 (Base
+ UARTCR
, 0x301);
52 return RETURN_SUCCESS
;
56 Write data to serial device.
58 @param Buffer Point of data buffer which need to be writed.
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 writed to serial device.
69 IN UINTN NumberOfBytes
72 UINT32 FR
= PcdGet32 (PcdConsoleUartBase
) + UARTFR
;
73 UINT32 DR
= PcdGet32 (PcdConsoleUartBase
) + UARTDR
;
76 for (Count
= 0; Count
< NumberOfBytes
; Count
++, Buffer
++) {
77 while ((MmioRead32 (FR
) & UART_TX_EMPTY_FLAG_MASK
) == 0);
78 MmioWrite8 (DR
, *Buffer
);
86 Read data from serial device and save the datas in buffer.
88 @param Buffer Point of data buffer which need to be writed.
89 @param NumberOfBytes Number of output bytes which are cached in Buffer.
91 @retval 0 Read data failed.
92 @retval !0 Aactual number of bytes read from serial device.
99 IN UINTN NumberOfBytes
102 UINT32 FR
= PcdGet32 (PcdConsoleUartBase
) + UARTFR
;
103 UINT32 DR
= PcdGet32 (PcdConsoleUartBase
) + UARTDR
;
106 for (Count
= 0; Count
< NumberOfBytes
; Count
++, Buffer
++) {
107 while ((MmioRead32 (FR
) & UART_RX_EMPTY_FLAG_MASK
) != 0);
108 *Buffer
= MmioRead8 (DR
);
111 return NumberOfBytes
;
116 Check to see if any data is avaiable to be read from the debug device.
118 @retval EFI_SUCCESS At least one byte of data is avaiable to be read
119 @retval EFI_NOT_READY No data is avaiable to be read
120 @retval EFI_DEVICE_ERROR The serial device is not functioning properly
129 UINT32 FR
= PcdGet32 (PcdConsoleUartBase
) + UARTFR
;
131 if ((MmioRead32 (FR
) & UART_RX_EMPTY_FLAG_MASK
) == 0) {