]>
Commit | Line | Data |
---|---|---|
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 |
3402aac7 | 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 | |
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 | |
32 | RETURN_STATUS\r | |
33 | EFIAPI\r | |
34 | SerialPortInitialize (\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 | |
52 | UINTN\r | |
53 | EFIAPI\r | |
54 | SerialPortWrite (\r | |
55 | IN UINT8 *Buffer,\r | |
56 | IN UINTN NumberOfBytes\r | |
57 | )\r | |
58 | {\r | |
43263288 | 59 | UINT32 LSR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_LSR_REG;\r |
60 | UINT32 THR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_THR_REG;\r | |
a3f98646 | 61 | UINTN Count;\r |
3402aac7 | 62 | \r |
a3f98646 | 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 | |
82 | UINTN\r | |
83 | EFIAPI\r | |
84 | SerialPortRead (\r | |
85 | OUT UINT8 *Buffer,\r | |
86 | IN UINTN NumberOfBytes\r | |
87 | )\r | |
88 | {\r | |
43263288 | 89 | UINT32 LSR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_LSR_REG;\r |
90 | UINT32 RBR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_RBR_REG;\r | |
a3f98646 | 91 | UINTN Count;\r |
3402aac7 | 92 | \r |
a3f98646 | 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 | |
110 | BOOLEAN\r | |
111 | EFIAPI\r | |
112 | SerialPortPoll (\r | |
113 | VOID\r | |
114 | )\r | |
115 | {\r | |
43263288 | 116 | UINT32 LSR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_LSR_REG;\r |
a3f98646 | 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 |