]>
Commit | Line | Data |
---|---|---|
a3f98646 | 1 | /** @file |
2 | ||
3d70643b | 3 | Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR> |
a3f98646 | 4 | |
3d70643b | 5 | This program and the accompanying materials |
a3f98646 | 6 | are licensed and made available under the terms and conditions of the BSD License |
7 | which accompanies this distribution. The full text of the license may be found at | |
8 | http://opensource.org/licenses/bsd-license.php | |
9 | ||
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. | |
12 | ||
13 | **/ | |
14 | ||
15 | #include <Uefi.h> | |
16 | ||
17 | #include <Library/IoLib.h> | |
18 | #include <Library/OmapLib.h> | |
19 | #include <Library/UefiBootServicesTableLib.h> | |
20 | ||
21 | #include <Protocol/EmbeddedGpio.h> | |
22 | ||
23 | #include <Omap3530/Omap3530.h> | |
24 | ||
25 | EFI_STATUS | |
26 | Get ( | |
27 | IN EMBEDDED_GPIO *This, | |
28 | IN EMBEDDED_GPIO_PIN Gpio, | |
29 | OUT UINTN *Value | |
30 | ) | |
31 | { | |
32 | UINTN Port; | |
33 | UINTN Pin; | |
34 | UINT32 DataInRegister; | |
35 | ||
36 | if (Value == NULL) | |
37 | { | |
38 | return EFI_UNSUPPORTED; | |
39 | } | |
40 | ||
41 | Port = GPIO_PORT(Gpio); | |
42 | Pin = GPIO_PIN(Gpio); | |
43 | ||
44 | DataInRegister = GpioBase(Port) + GPIO_DATAIN; | |
45 | ||
43263288 | 46 | if (MmioRead32 (DataInRegister) & GPIO_DATAIN_MASK(Pin)) { |
a3f98646 | 47 | *Value = 1; |
48 | } else { | |
49 | *Value = 0; | |
50 | } | |
51 | ||
52 | return EFI_SUCCESS; | |
53 | } | |
54 | ||
55 | EFI_STATUS | |
56 | Set ( | |
57 | IN EMBEDDED_GPIO *This, | |
58 | IN EMBEDDED_GPIO_PIN Gpio, | |
59 | IN EMBEDDED_GPIO_MODE Mode | |
60 | ) | |
61 | { | |
62 | UINTN Port; | |
63 | UINTN Pin; | |
64 | UINT32 OutputEnableRegister; | |
65 | UINT32 SetDataOutRegister; | |
66 | UINT32 ClearDataOutRegister; | |
67 | ||
68 | Port = GPIO_PORT(Gpio); | |
69 | Pin = GPIO_PIN(Gpio); | |
70 | ||
71 | OutputEnableRegister = GpioBase(Port) + GPIO_OE; | |
72 | SetDataOutRegister = GpioBase(Port) + GPIO_SETDATAOUT; | |
73 | ClearDataOutRegister = GpioBase(Port) + GPIO_CLEARDATAOUT; | |
74 | ||
75 | switch (Mode) | |
76 | { | |
77 | case GPIO_MODE_INPUT: | |
78 | MmioAndThenOr32(OutputEnableRegister, ~GPIO_OE_MASK(Pin), GPIO_OE_INPUT(Pin)); | |
79 | break; | |
80 | ||
81 | case GPIO_MODE_OUTPUT_0: | |
026e30c4 | 82 | MmioWrite32 (ClearDataOutRegister, GPIO_CLEARDATAOUT_BIT(Pin)); |
a3f98646 | 83 | MmioAndThenOr32(OutputEnableRegister, ~GPIO_OE_MASK(Pin), GPIO_OE_OUTPUT(Pin)); |
84 | break; | |
85 | ||
86 | case GPIO_MODE_OUTPUT_1: | |
026e30c4 | 87 | MmioWrite32 (SetDataOutRegister, GPIO_SETDATAOUT_BIT(Pin)); |
a3f98646 | 88 | MmioAndThenOr32(OutputEnableRegister, ~GPIO_OE_MASK(Pin), GPIO_OE_OUTPUT(Pin)); |
89 | break; | |
90 | ||
91 | default: | |
92 | return EFI_UNSUPPORTED; | |
93 | } | |
94 | ||
95 | return EFI_SUCCESS; | |
96 | } | |
97 | ||
98 | EFI_STATUS | |
99 | GetMode ( | |
100 | IN EMBEDDED_GPIO *This, | |
101 | IN EMBEDDED_GPIO_PIN Gpio, | |
102 | OUT EMBEDDED_GPIO_MODE *Mode | |
103 | ) | |
104 | { | |
105 | return EFI_UNSUPPORTED; | |
106 | } | |
107 | ||
108 | EFI_STATUS | |
109 | SetPull ( | |
110 | IN EMBEDDED_GPIO *This, | |
111 | IN EMBEDDED_GPIO_PIN Gpio, | |
112 | IN EMBEDDED_GPIO_PULL Direction | |
113 | ) | |
114 | { | |
115 | return EFI_UNSUPPORTED; | |
116 | } | |
117 | ||
118 | EMBEDDED_GPIO Gpio = { | |
119 | Get, | |
120 | Set, | |
121 | GetMode, | |
122 | SetPull | |
123 | }; | |
124 | ||
125 | EFI_STATUS | |
126 | GpioInitialize ( | |
127 | IN EFI_HANDLE ImageHandle, | |
128 | IN EFI_SYSTEM_TABLE *SystemTable | |
129 | ) | |
130 | { | |
131 | EFI_STATUS Status; | |
132 | ||
133 | Status = gBS->InstallMultipleProtocolInterfaces(&ImageHandle, &gEmbeddedGpioProtocolGuid, &Gpio, NULL); | |
134 | return Status; | |
135 | } |