]> git.proxmox.com Git - mirror_edk2.git/blob - Omap35xxPkg/Library/SerialPortLib/SerialPortLib.c
9a70593dbf8babc45ee418c7c4d77a17c62abe51
[mirror_edk2.git] / Omap35xxPkg / Library / SerialPortLib / SerialPortLib.c
1 /** @file
2 Serial I/O Port library functions with no library constructor/destructor
3
4
5 Copyright (c) 2008 - 2009, Apple Inc. 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 #include <Library/DebugLib.h>
19 #include <Library/SerialPortLib.h>
20 #include <Library/SerialPortExtLib.h>
21 #include <Library/PcdLib.h>
22 #include <Library/IoLib.h>
23 #include <Library/OmapLib.h>
24 #include <Omap3530/Omap3530.h>
25
26 /*
27
28 Programmed hardware of Serial port.
29
30 @return Always return EFI_UNSUPPORTED.
31
32 **/
33 RETURN_STATUS
34 EFIAPI
35 SerialPortInitialize (
36 VOID
37 )
38 {
39 // assume assembly code at reset vector has setup UART
40 return RETURN_SUCCESS;
41 }
42
43 /**
44 Write data to serial device.
45
46 @param Buffer Point of data buffer which need to be writed.
47 @param NumberOfBytes Number of output bytes which are cached in Buffer.
48
49 @retval 0 Write data failed.
50 @retval !0 Actual number of bytes writed to serial device.
51
52 **/
53 UINTN
54 EFIAPI
55 SerialPortWrite (
56 IN UINT8 *Buffer,
57 IN UINTN NumberOfBytes
58 )
59 {
60 UINT32 LSR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_LSR_REG;
61 UINT32 THR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_THR_REG;
62 UINTN Count;
63
64 for (Count = 0; Count < NumberOfBytes; Count++, Buffer++) {
65 while ((MmioRead8(LSR) & UART_LSR_TX_FIFO_E_MASK) == UART_LSR_TX_FIFO_E_NOT_EMPTY);
66 MmioWrite8(THR, *Buffer);
67 }
68
69 return NumberOfBytes;
70 }
71
72
73 /**
74 Read data from serial device and save the datas in buffer.
75
76 @param Buffer Point of data buffer which need to be writed.
77 @param NumberOfBytes Number of output bytes which are cached in Buffer.
78
79 @retval 0 Read data failed.
80 @retval !0 Aactual number of bytes read from serial device.
81
82 **/
83 UINTN
84 EFIAPI
85 SerialPortRead (
86 OUT UINT8 *Buffer,
87 IN UINTN NumberOfBytes
88 )
89 {
90 UINT32 LSR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_LSR_REG;
91 UINT32 RBR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_RBR_REG;
92 UINTN Count;
93
94 for (Count = 0; Count < NumberOfBytes; Count++, Buffer++) {
95 while ((MmioRead8(LSR) & UART_LSR_RX_FIFO_E_MASK) == UART_LSR_RX_FIFO_E_EMPTY);
96 *Buffer = MmioRead8(RBR);
97 }
98
99 return NumberOfBytes;
100 }
101
102
103 /**
104 Check to see if any data is avaiable to be read from the debug device.
105
106 @retval EFI_SUCCESS At least one byte of data is avaiable to be read
107 @retval EFI_NOT_READY No data is avaiable to be read
108 @retval EFI_DEVICE_ERROR The serial device is not functioning properly
109
110 **/
111 BOOLEAN
112 EFIAPI
113 SerialPortPoll (
114 VOID
115 )
116 {
117 UINT32 LSR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_LSR_REG;
118
119 if ((MmioRead8(LSR) & UART_LSR_RX_FIFO_E_MASK) == UART_LSR_RX_FIFO_E_NOT_EMPTY) {
120 return TRUE;
121 } else {
122 return FALSE;
123 }
124 }
125
126 /**
127 Set the serial device control bits.
128
129 @return Always return EFI_UNSUPPORTED.
130
131 **/
132 RETURN_STATUS
133 EFIAPI
134 SerialPortSetControl (
135 IN UINT32 Control
136 )
137 {
138 return RETURN_SUCCESS;
139 }
140
141 /**
142 Get the serial device control bits.
143
144 @param Control Control signals read from the serial device.
145
146 @retval EFI_SUCCESS The control bits were read from the serial device.
147 @retval EFI_DEVICE_ERROR The serial device is not functioning correctly.
148
149 **/
150 RETURN_STATUS
151 EFIAPI
152 SerialPortGetControl (
153 OUT UINT32 *Control
154 )
155 {
156 return RETURN_SUCCESS;
157 }
158
159
160 /**
161 Set the serial device attributes.
162
163 @return Always return EFI_UNSUPPORTED.
164
165 **/
166 RETURN_STATUS
167 EFIAPI
168 SerialPortSetAttributes (
169 IN UINT64 BaudRate,
170 IN UINT32 ReceiveFifoDepth,
171 IN UINT32 Timeout,
172 IN EFI_PARITY_TYPE Parity,
173 IN UINT8 DataBits,
174 IN EFI_STOP_BITS_TYPE StopBits
175 )
176 {
177 return RETURN_SUCCESS;
178 }
179