]> git.proxmox.com Git - mirror_edk2.git/blame - Omap35xxPkg/Library/SerialPortLib/SerialPortLib.c
EmbeddedPkg: Introduced 'SerialPortExtLib.h'
[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
a3f98646 6 \r
3d70643b 7 This program and the accompanying materials\r
a3f98646 8 are licensed and made available under the terms and conditions of the BSD License\r
9 which accompanies this distribution. The full text of the license may be found at\r
10 http://opensource.org/licenses/bsd-license.php\r
11\r
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15**/\r
16\r
17#include <Base.h>\r
18#include <Library/DebugLib.h>\r
19#include <Library/SerialPortLib.h>\r
7d49ced0 20#include <Library/SerialPortExtLib.h>\r
a3f98646 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
63 \r
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
93 \r
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
7d49ced0 126/**\r
127 Set the serial device control bits.\r
128\r
129 @return Always return EFI_UNSUPPORTED.\r
130\r
131**/\r
132RETURN_STATUS\r
133EFIAPI\r
134SerialPortSetControl (\r
135 IN UINT32 Control\r
136 )\r
137{\r
138 return RETURN_SUCCESS;\r
139}\r
140\r
141/**\r
142 Get the serial device control bits.\r
143\r
144 @param Control Control signals read from the serial device.\r
145\r
146 @retval EFI_SUCCESS The control bits were read from the serial device.\r
147 @retval EFI_DEVICE_ERROR The serial device is not functioning correctly.\r
148\r
149**/\r
150RETURN_STATUS\r
151EFIAPI\r
152SerialPortGetControl (\r
153 OUT UINT32 *Control\r
154 )\r
155{\r
156 return RETURN_SUCCESS;\r
157}\r
158\r
159\r
160/**\r
161 Set the serial device attributes.\r
162\r
163 @return Always return EFI_UNSUPPORTED.\r
164\r
165**/\r
166RETURN_STATUS\r
167EFIAPI\r
168SerialPortSetAttributes (\r
169 IN UINT64 BaudRate,\r
170 IN UINT32 ReceiveFifoDepth,\r
171 IN UINT32 Timeout,\r
172 IN EFI_PARITY_TYPE Parity,\r
173 IN UINT8 DataBits,\r
174 IN EFI_STOP_BITS_TYPE StopBits\r
175 )\r
176{\r
177 return RETURN_SUCCESS;\r
178}\r
179\r