]> git.proxmox.com Git - mirror_edk2.git/blob - Omap35xxPkg/Library/SerialPortLib/SerialPortLib.c
2b94f0bfc2c5848893993cb45b32131e049f5976
[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 Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
7
8 SPDX-License-Identifier: BSD-2-Clause-Patent
9
10 **/
11
12 #include <Base.h>
13 #include <Library/DebugLib.h>
14 #include <Library/SerialPortLib.h>
15 #include <Library/PcdLib.h>
16 #include <Library/IoLib.h>
17 #include <Library/OmapLib.h>
18 #include <Omap3530/Omap3530.h>
19
20 /*
21
22 Programmed hardware of Serial port.
23
24 @return Always return EFI_UNSUPPORTED.
25
26 **/
27 RETURN_STATUS
28 EFIAPI
29 SerialPortInitialize (
30 VOID
31 )
32 {
33 // assume assembly code at reset vector has setup UART
34 return RETURN_SUCCESS;
35 }
36
37 /**
38 Write data to serial device.
39
40 @param Buffer Point of data buffer which need to be writed.
41 @param NumberOfBytes Number of output bytes which are cached in Buffer.
42
43 @retval 0 Write data failed.
44 @retval !0 Actual number of bytes writed to serial device.
45
46 **/
47 UINTN
48 EFIAPI
49 SerialPortWrite (
50 IN UINT8 *Buffer,
51 IN UINTN NumberOfBytes
52 )
53 {
54 UINT32 LSR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_LSR_REG;
55 UINT32 THR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_THR_REG;
56 UINTN Count;
57
58 for (Count = 0; Count < NumberOfBytes; Count++, Buffer++) {
59 while ((MmioRead8(LSR) & UART_LSR_TX_FIFO_E_MASK) == UART_LSR_TX_FIFO_E_NOT_EMPTY);
60 MmioWrite8(THR, *Buffer);
61 }
62
63 return NumberOfBytes;
64 }
65
66
67 /**
68 Read data from serial device and save the datas in buffer.
69
70 @param Buffer Point of data buffer which need to be writed.
71 @param NumberOfBytes Number of output bytes which are cached in Buffer.
72
73 @retval 0 Read data failed.
74 @retval !0 Aactual number of bytes read from serial device.
75
76 **/
77 UINTN
78 EFIAPI
79 SerialPortRead (
80 OUT UINT8 *Buffer,
81 IN UINTN NumberOfBytes
82 )
83 {
84 UINT32 LSR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_LSR_REG;
85 UINT32 RBR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_RBR_REG;
86 UINTN Count;
87
88 for (Count = 0; Count < NumberOfBytes; Count++, Buffer++) {
89 while ((MmioRead8(LSR) & UART_LSR_RX_FIFO_E_MASK) == UART_LSR_RX_FIFO_E_EMPTY);
90 *Buffer = MmioRead8(RBR);
91 }
92
93 return NumberOfBytes;
94 }
95
96
97 /**
98 Check to see if any data is avaiable to be read from the debug device.
99
100 @retval EFI_SUCCESS At least one byte of data is avaiable to be read
101 @retval EFI_NOT_READY No data is avaiable to be read
102 @retval EFI_DEVICE_ERROR The serial device is not functioning properly
103
104 **/
105 BOOLEAN
106 EFIAPI
107 SerialPortPoll (
108 VOID
109 )
110 {
111 UINT32 LSR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_LSR_REG;
112
113 if ((MmioRead8(LSR) & UART_LSR_RX_FIFO_E_MASK) == UART_LSR_RX_FIFO_E_NOT_EMPTY) {
114 return TRUE;
115 } else {
116 return FALSE;
117 }
118 }
119
120 /**
121 Sets the control bits on a serial device.
122
123 @param[in] Control Sets the bits of Control that are settable.
124
125 @retval RETURN_SUCCESS The new control bits were set on the serial device.
126 @retval RETURN_UNSUPPORTED The serial device does not support this operation.
127 @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.
128
129 **/
130 RETURN_STATUS
131 EFIAPI
132 SerialPortSetControl (
133 IN UINT32 Control
134 )
135 {
136 return RETURN_UNSUPPORTED;
137 }
138
139 /**
140 Retrieve the status of the control bits on a serial device.
141
142 @param[out] Control A pointer to return the current control signals from the serial device.
143
144 @retval RETURN_SUCCESS The control bits were read from the serial device.
145 @retval RETURN_UNSUPPORTED The serial device does not support this operation.
146 @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.
147
148 **/
149 RETURN_STATUS
150 EFIAPI
151 SerialPortGetControl (
152 OUT UINT32 *Control
153 )
154 {
155 *Control = 0;
156 if (!SerialPortPoll ()) {
157 *Control = EFI_SERIAL_INPUT_BUFFER_EMPTY;
158 }
159 return RETURN_SUCCESS;
160 }
161
162 /**
163 Sets the baud rate, receive FIFO depth, transmit/receice time out, parity,
164 data bits, and stop bits on a serial device.
165
166 @param BaudRate The requested baud rate. A BaudRate value of 0 will use the
167 device's default interface speed.
168 On output, the value actually set.
169 @param ReveiveFifoDepth The requested depth of the FIFO on the receive side of the
170 serial interface. A ReceiveFifoDepth value of 0 will use
171 the device's default FIFO depth.
172 On output, the value actually set.
173 @param Timeout The requested time out for a single character in microseconds.
174 This timeout applies to both the transmit and receive side of the
175 interface. A Timeout value of 0 will use the device's default time
176 out value.
177 On output, the value actually set.
178 @param Parity The type of parity to use on this serial device. A Parity value of
179 DefaultParity will use the device's default parity value.
180 On output, the value actually set.
181 @param DataBits The number of data bits to use on the serial device. A DataBits
182 vaule of 0 will use the device's default data bit setting.
183 On output, the value actually set.
184 @param StopBits The number of stop bits to use on this serial device. A StopBits
185 value of DefaultStopBits will use the device's default number of
186 stop bits.
187 On output, the value actually set.
188
189 @retval RETURN_SUCCESS The new attributes were set on the serial device.
190 @retval RETURN_UNSUPPORTED The serial device does not support this operation.
191 @retval RETURN_INVALID_PARAMETER One or more of the attributes has an unsupported value.
192 @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.
193
194 **/
195 RETURN_STATUS
196 EFIAPI
197 SerialPortSetAttributes (
198 IN OUT UINT64 *BaudRate,
199 IN OUT UINT32 *ReceiveFifoDepth,
200 IN OUT UINT32 *Timeout,
201 IN OUT EFI_PARITY_TYPE *Parity,
202 IN OUT UINT8 *DataBits,
203 IN OUT EFI_STOP_BITS_TYPE *StopBits
204 )
205 {
206 return RETURN_UNSUPPORTED;
207 }
208