1 | /** @file
|
---|
2 |
|
---|
3 | Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
|
---|
4 |
|
---|
5 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
6 |
|
---|
7 | **/
|
---|
8 |
|
---|
9 | #ifndef __EMBEDDED_GPIO_H__
|
---|
10 | #define __EMBEDDED_GPIO_H__
|
---|
11 |
|
---|
12 | //
|
---|
13 | // Protocol interface structure
|
---|
14 | //
|
---|
15 | typedef struct _EMBEDDED_GPIO EMBEDDED_GPIO;
|
---|
16 |
|
---|
17 | //
|
---|
18 | // Data Types
|
---|
19 | //
|
---|
20 | typedef UINTN EMBEDDED_GPIO_PIN;
|
---|
21 |
|
---|
22 | #define GPIO(Port, Pin) ((EMBEDDED_GPIO_PIN)(((Port) << (16)) | (Pin)))
|
---|
23 | #define GPIO_PIN(x) ((EMBEDDED_GPIO_PIN)(x) & (0xFFFF))
|
---|
24 | #define GPIO_PORT(x) ((EMBEDDED_GPIO_PIN)(x) >> (16))
|
---|
25 |
|
---|
26 | typedef enum {
|
---|
27 | GPIO_MODE_INPUT = 0x00,
|
---|
28 | GPIO_MODE_OUTPUT_0 = 0x0E,
|
---|
29 | GPIO_MODE_OUTPUT_1 = 0x0F,
|
---|
30 | GPIO_MODE_SPECIAL_FUNCTION_2 = 0x02,
|
---|
31 | GPIO_MODE_SPECIAL_FUNCTION_3 = 0x03,
|
---|
32 | GPIO_MODE_SPECIAL_FUNCTION_4 = 0x04,
|
---|
33 | GPIO_MODE_SPECIAL_FUNCTION_5 = 0x05,
|
---|
34 | GPIO_MODE_SPECIAL_FUNCTION_6 = 0x06,
|
---|
35 | GPIO_MODE_SPECIAL_FUNCTION_7 = 0x07
|
---|
36 | } EMBEDDED_GPIO_MODE;
|
---|
37 |
|
---|
38 | typedef enum {
|
---|
39 | GPIO_PULL_NONE,
|
---|
40 | GPIO_PULL_UP,
|
---|
41 | GPIO_PULL_DOWN
|
---|
42 | } EMBEDDED_GPIO_PULL;
|
---|
43 |
|
---|
44 | //
|
---|
45 | // Function Prototypes
|
---|
46 | //
|
---|
47 | typedef
|
---|
48 | EFI_STATUS
|
---|
49 | (EFIAPI *EMBEDDED_GPIO_GET) (
|
---|
50 | IN EMBEDDED_GPIO *This,
|
---|
51 | IN EMBEDDED_GPIO_PIN Gpio,
|
---|
52 | OUT UINTN *Value
|
---|
53 | );
|
---|
54 | /*++
|
---|
55 |
|
---|
56 | Routine Description:
|
---|
57 |
|
---|
58 | Gets the state of a GPIO pin
|
---|
59 |
|
---|
60 | Arguments:
|
---|
61 |
|
---|
62 | This - pointer to protocol
|
---|
63 | Gpio - which pin to read
|
---|
64 | Value - state of the pin
|
---|
65 |
|
---|
66 | Returns:
|
---|
67 |
|
---|
68 | EFI_SUCCESS - GPIO state returned in Value
|
---|
69 |
|
---|
70 | --*/
|
---|
71 |
|
---|
72 |
|
---|
73 | typedef
|
---|
74 | EFI_STATUS
|
---|
75 | (EFIAPI *EMBEDDED_GPIO_SET) (
|
---|
76 | IN EMBEDDED_GPIO *This,
|
---|
77 | IN EMBEDDED_GPIO_PIN Gpio,
|
---|
78 | IN EMBEDDED_GPIO_MODE Mode
|
---|
79 | );
|
---|
80 | /*++
|
---|
81 |
|
---|
82 | Routine Description:
|
---|
83 |
|
---|
84 | Sets the state of a GPIO pin
|
---|
85 |
|
---|
86 | Arguments:
|
---|
87 |
|
---|
88 | This - pointer to protocol
|
---|
89 | Gpio - which pin to modify
|
---|
90 | Mode - mode to set
|
---|
91 |
|
---|
92 | Returns:
|
---|
93 |
|
---|
94 | EFI_SUCCESS - GPIO set as requested
|
---|
95 |
|
---|
96 | --*/
|
---|
97 |
|
---|
98 |
|
---|
99 | typedef
|
---|
100 | EFI_STATUS
|
---|
101 | (EFIAPI *EMBEDDED_GPIO_GET_MODE) (
|
---|
102 | IN EMBEDDED_GPIO *This,
|
---|
103 | IN EMBEDDED_GPIO_PIN Gpio,
|
---|
104 | OUT EMBEDDED_GPIO_MODE *Mode
|
---|
105 | );
|
---|
106 | /*++
|
---|
107 |
|
---|
108 | Routine Description:
|
---|
109 |
|
---|
110 | Gets the mode (function) of a GPIO pin
|
---|
111 |
|
---|
112 | Arguments:
|
---|
113 |
|
---|
114 | This - pointer to protocol
|
---|
115 | Gpio - which pin
|
---|
116 | Mode - pointer to output mode value
|
---|
117 |
|
---|
118 | Returns:
|
---|
119 |
|
---|
120 | EFI_SUCCESS - mode value retrieved
|
---|
121 |
|
---|
122 | --*/
|
---|
123 |
|
---|
124 |
|
---|
125 | typedef
|
---|
126 | EFI_STATUS
|
---|
127 | (EFIAPI *EMBEDDED_GPIO_SET_PULL) (
|
---|
128 | IN EMBEDDED_GPIO *This,
|
---|
129 | IN EMBEDDED_GPIO_PIN Gpio,
|
---|
130 | IN EMBEDDED_GPIO_PULL Direction
|
---|
131 | );
|
---|
132 | /*++
|
---|
133 |
|
---|
134 | Routine Description:
|
---|
135 |
|
---|
136 | Sets the pull-up / pull-down resistor of a GPIO pin
|
---|
137 |
|
---|
138 | Arguments:
|
---|
139 |
|
---|
140 | This - pointer to protocol
|
---|
141 | Gpio - which pin
|
---|
142 | Direction - pull-up, pull-down, or none
|
---|
143 |
|
---|
144 | Returns:
|
---|
145 |
|
---|
146 | EFI_SUCCESS - pin was set
|
---|
147 |
|
---|
148 | --*/
|
---|
149 |
|
---|
150 |
|
---|
151 |
|
---|
152 | struct _EMBEDDED_GPIO {
|
---|
153 | EMBEDDED_GPIO_GET Get;
|
---|
154 | EMBEDDED_GPIO_SET Set;
|
---|
155 | EMBEDDED_GPIO_GET_MODE GetMode;
|
---|
156 | EMBEDDED_GPIO_SET_PULL SetPull;
|
---|
157 | };
|
---|
158 |
|
---|
159 | extern EFI_GUID gEmbeddedGpioProtocolGuid;
|
---|
160 |
|
---|
161 | typedef struct _GPIO_CONTROLLER GPIO_CONTROLLER;
|
---|
162 | typedef struct _PLATFORM_GPIO_CONTROLLER PLATFORM_GPIO_CONTROLLER;
|
---|
163 |
|
---|
164 | struct _GPIO_CONTROLLER {
|
---|
165 | UINTN RegisterBase;
|
---|
166 | UINTN GpioIndex;
|
---|
167 | UINTN InternalGpioCount;
|
---|
168 | };
|
---|
169 |
|
---|
170 | struct _PLATFORM_GPIO_CONTROLLER {
|
---|
171 | UINTN GpioCount;
|
---|
172 | UINTN GpioControllerCount;
|
---|
173 | GPIO_CONTROLLER *GpioController;
|
---|
174 | };
|
---|
175 |
|
---|
176 | extern EFI_GUID gPlatformGpioProtocolGuid;
|
---|
177 |
|
---|
178 | #endif
|
---|