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