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