EDK2 doxygen online documents - Firmware Encoding Index 1
EDK2 doxygen online documents - Firmware Encoding Index

ArmPlatformPkg/Drivers/PL011Uart/PL011Uart.c

Go to the documentation of this file.
00001 
00017 #include <Include/Uefi.h>
00018 
00019 #include <Library/IoLib.h>
00020 
00021 #include <Drivers/PL011Uart.h>
00022 
00023 /*
00024 
00025   Programmed hardware of Serial port.
00026 
00027   @return    Always return EFI_UNSUPPORTED.
00028 
00029 **/
00030 RETURN_STATUS
00031 EFIAPI
00032 PL011UartInitialize (
00033   IN  UINTN       UartBase,
00034   IN  UINTN       BaudRate,
00035   IN  UINTN       LineControl
00036   )
00037 {
00038         if (BaudRate == 115200) {
00039                 // Initialize baud rate generator
00040                 MmioWrite32 (UartBase + UARTIBRD, UART_115200_IDIV);
00041                 MmioWrite32 (UartBase + UARTFBRD, UART_115200_FDIV);
00042         } else if (BaudRate == 38400) {
00043                 // Initialize baud rate generator
00044                 MmioWrite32 (UartBase + UARTIBRD, UART_38400_IDIV);
00045                 MmioWrite32 (UartBase + UARTFBRD, UART_38400_FDIV);
00046         } else if (BaudRate == 19200) {
00047                 // Initialize baud rate generator
00048                 MmioWrite32 (UartBase + UARTIBRD, UART_19200_IDIV);
00049                 MmioWrite32 (UartBase + UARTFBRD, UART_19200_FDIV);
00050         } else {
00051                 return EFI_INVALID_PARAMETER;
00052         }
00053 
00054   // No parity, 1 stop, no fifo, 8 data bits
00055   MmioWrite32 (UartBase + UARTLCR_H, LineControl);
00056 
00057   // Clear any pending errors
00058   MmioWrite32 (UartBase + UARTECR, 0);
00059 
00060   // Enable tx, rx, and uart overall
00061   MmioWrite32 (UartBase + UARTCR, PL011_UARTCR_RXE | PL011_UARTCR_TXE | PL011_UARTCR_UARTEN);
00062 
00063   return EFI_SUCCESS;
00064 }
00065 
00076 UINTN
00077 EFIAPI
00078 PL011UartWrite (
00079   IN  UINTN    UartBase,
00080   IN UINT8     *Buffer,
00081   IN UINTN     NumberOfBytes
00082   )
00083 {
00084         UINTN  Count;
00085 
00086         for (Count = 0; Count < NumberOfBytes; Count++, Buffer++) {
00087                 while ((MmioRead32 (UartBase + UARTFR) & UART_TX_EMPTY_FLAG_MASK) == 0);
00088                 MmioWrite8 (UartBase + UARTDR, *Buffer);
00089         }
00090 
00091         return NumberOfBytes;
00092 }
00093 
00104 UINTN
00105 EFIAPI
00106 PL011UartRead (
00107   IN  UINTN     UartBase,
00108   OUT UINT8     *Buffer,
00109   IN  UINTN     NumberOfBytes
00110   )
00111 {
00112   UINTN   Count;
00113 
00114         for (Count = 0; Count < NumberOfBytes; Count++, Buffer++) {
00115                 while ((MmioRead32 (UartBase + UARTFR) & UART_RX_EMPTY_FLAG_MASK) != 0);
00116                 *Buffer = MmioRead8 (UartBase + UARTDR);
00117         }
00118 
00119         return NumberOfBytes;
00120 }
00121 
00130 BOOLEAN
00131 EFIAPI
00132 PL011UartPoll (
00133   IN  UINTN     UartBase
00134   )
00135 {
00136   return ((MmioRead32 (UartBase + UARTFR) & UART_RX_EMPTY_FLAG_MASK) == 0);
00137 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Defines