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