]> git.proxmox.com Git - mirror_edk2.git/blame - Omap35xxPkg/Library/SerialPortLib/SerialPortLib.c
Moving OMAP 3530 code out of BeagleBoard package into its own package
[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
5 Copyright (c) 2008-2009, Apple Inc. All rights reserved.\r
6 \r
7 All rights reserved. This program and the accompanying materials\r
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
20#include <Library/PcdLib.h>\r
21#include <Library/IoLib.h>\r
22#include <Library/OmapLib.h>\r
23#include <Omap3530/Omap3530.h>\r
24\r
25/*\r
26\r
27 Programmed hardware of Serial port.\r
28\r
29 @return Always return EFI_UNSUPPORTED.\r
30\r
31**/\r
32RETURN_STATUS\r
33EFIAPI\r
34SerialPortInitialize (\r
35 VOID\r
36 )\r
37{\r
38 // assume assembly code at reset vector has setup UART\r
39 return RETURN_SUCCESS;\r
40}\r
41\r
42/**\r
43 Write data to serial device.\r
44\r
45 @param Buffer Point of data buffer which need to be writed.\r
46 @param NumberOfBytes Number of output bytes which are cached in Buffer.\r
47\r
48 @retval 0 Write data failed.\r
49 @retval !0 Actual number of bytes writed to serial device.\r
50\r
51**/\r
52UINTN\r
53EFIAPI\r
54SerialPortWrite (\r
55 IN UINT8 *Buffer,\r
56 IN UINTN NumberOfBytes\r
57)\r
58{\r
59 UINT32 LSR = UartBase(PcdGet32(PcdBeagleConsoleUart)) + UART_LSR_REG;\r
60 UINT32 THR = UartBase(PcdGet32(PcdBeagleConsoleUart)) + UART_THR_REG;\r
61 UINTN Count;\r
62 \r
63 for (Count = 0; Count < NumberOfBytes; Count++, Buffer++) {\r
64 while ((MmioRead8(LSR) & UART_LSR_TX_FIFO_E_MASK) == UART_LSR_TX_FIFO_E_NOT_EMPTY);\r
65 MmioWrite8(THR, *Buffer);\r
66 }\r
67\r
68 return NumberOfBytes;\r
69}\r
70\r
71\r
72/**\r
73 Read data from serial device and save the datas in buffer.\r
74\r
75 @param Buffer Point of data buffer which need to be writed.\r
76 @param NumberOfBytes Number of output bytes which are cached in Buffer.\r
77\r
78 @retval 0 Read data failed.\r
79 @retval !0 Aactual number of bytes read from serial device.\r
80\r
81**/\r
82UINTN\r
83EFIAPI\r
84SerialPortRead (\r
85 OUT UINT8 *Buffer,\r
86 IN UINTN NumberOfBytes\r
87)\r
88{\r
89 UINT32 LSR = UartBase(PcdGet32(PcdBeagleConsoleUart)) + UART_LSR_REG;\r
90 UINT32 RBR = UartBase(PcdGet32(PcdBeagleConsoleUart)) + UART_RBR_REG;\r
91 UINTN Count;\r
92 \r
93 for (Count = 0; Count < NumberOfBytes; Count++, Buffer++) {\r
94 while ((MmioRead8(LSR) & UART_LSR_RX_FIFO_E_MASK) == UART_LSR_RX_FIFO_E_EMPTY);\r
95 *Buffer = MmioRead8(RBR);\r
96 }\r
97\r
98 return NumberOfBytes;\r
99}\r
100\r
101\r
102/**\r
103 Check to see if any data is avaiable to be read from the debug device.\r
104\r
105 @retval EFI_SUCCESS At least one byte of data is avaiable to be read\r
106 @retval EFI_NOT_READY No data is avaiable to be read\r
107 @retval EFI_DEVICE_ERROR The serial device is not functioning properly\r
108\r
109**/\r
110BOOLEAN\r
111EFIAPI\r
112SerialPortPoll (\r
113 VOID\r
114 )\r
115{\r
116 UINT32 LSR = UartBase(PcdGet32(PcdBeagleConsoleUart)) + UART_LSR_REG;\r
117\r
118 if ((MmioRead8(LSR) & UART_LSR_RX_FIFO_E_MASK) == UART_LSR_RX_FIFO_E_NOT_EMPTY) {\r
119 return TRUE;\r
120 } else {\r
121 return FALSE;\r
122 }\r
123}\r
124\r