EmbeddedPkg: introduce GPIO PPI
[mirror_edk2.git] / EmbeddedPkg / Include / Ppi / EmbeddedGpio.h
1 /** @file
2
3 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
4 Copyright (c) 2017, Linaro, Ltd. All rights reserved.<BR>
5
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #ifndef __EMBEDDED_GPIO_PPI_H__
17 #define __EMBEDDED_GPIO_PPI_H__
18
19 //
20 // Protocol interface structure
21 //
22 typedef struct _EMBEDDED_GPIO_PPI EMBEDDED_GPIO_PPI;
23
24 //
25 // Data Types
26 //
27 typedef UINTN EMBEDDED_GPIO_PIN;
28
29 #define GPIO(Port, Pin) ((EMBEDDED_GPIO_PIN)(((Port) << (16)) | (Pin)))
30 #define GPIO_PIN(x) ((EMBEDDED_GPIO_PIN)(x) & (0xFFFF))
31 #define GPIO_PORT(x) ((EMBEDDED_GPIO_PIN)(x) >> (16))
32
33 typedef enum {
34 GPIO_MODE_INPUT = 0x00,
35 GPIO_MODE_OUTPUT_0 = 0x0E,
36 GPIO_MODE_OUTPUT_1 = 0x0F,
37 GPIO_MODE_SPECIAL_FUNCTION_2 = 0x02,
38 GPIO_MODE_SPECIAL_FUNCTION_3 = 0x03,
39 GPIO_MODE_SPECIAL_FUNCTION_4 = 0x04,
40 GPIO_MODE_SPECIAL_FUNCTION_5 = 0x05,
41 GPIO_MODE_SPECIAL_FUNCTION_6 = 0x06,
42 GPIO_MODE_SPECIAL_FUNCTION_7 = 0x07
43 } EMBEDDED_GPIO_MODE;
44
45 typedef enum {
46 GPIO_PULL_NONE,
47 GPIO_PULL_UP,
48 GPIO_PULL_DOWN
49 } EMBEDDED_GPIO_PULL;
50
51 //
52 // Function Prototypes
53 //
54
55 /**
56
57 Gets the state of a GPIO pin
58
59 @param This Pointer to protocol
60 @param Gpio Which pin to read
61 @param Value State of the pin
62
63 @retval EFI_SUCCESS GPIO state returned in Value
64 @retval EFI_INVALID_PARAMETER Value is NULL
65 @retval EFI_NOT_FOUND Pin does not exit
66
67 **/
68 typedef
69 EFI_STATUS
70 (EFIAPI *EMBEDDED_GPIO_GET) (
71 IN EMBEDDED_GPIO_PPI *This,
72 IN EMBEDDED_GPIO_PIN Gpio,
73 OUT UINTN *Value
74 );
75
76 /**
77
78 Sets the state of a GPIO pin
79
80 @param This Pointer to protocol
81 @param Gpio Which pin to modify
82 @param Mode Mode to set
83
84 @retval EFI_SUCCESS GPIO set as requested
85 @retval EFI_INVALID_PARAMETER Invalid mode
86 @retval EFI_NOT_FOUND Pin does not exit
87
88 **/
89 typedef
90 EFI_STATUS
91 (EFIAPI *EMBEDDED_GPIO_SET) (
92 IN EMBEDDED_GPIO_PPI *This,
93 IN EMBEDDED_GPIO_PIN Gpio,
94 IN EMBEDDED_GPIO_MODE Mode
95 );
96
97
98 /**
99
100 Gets the mode (function) of a GPIO pin
101
102 @param This Pointer to protocol
103 @param Gpio Which pin
104 @param Mode Pointer to output mode value
105
106 @retval EFI_SUCCESS Mode value retrieved
107 @retval EFI_INVALID_PARAMETER Mode is NULL
108 @retval EFI_NOT_FOUND Pin does not exit
109
110 **/
111 typedef
112 EFI_STATUS
113 (EFIAPI *EMBEDDED_GPIO_GET_MODE) (
114 IN EMBEDDED_GPIO_PPI *This,
115 IN EMBEDDED_GPIO_PIN Gpio,
116 OUT EMBEDDED_GPIO_MODE *Mode
117 );
118
119
120 /**
121
122 Sets the pull-up / pull-down resistor of a GPIO pin
123
124 @param This Pointer to PPI
125 @param Gpio Port/pin index
126 @param Pull The pullup/pulldown mode to set
127
128 @retval EFI_SUCCESS Mode was set
129 @retval EFI_NOT_FOUND Pin does not exist
130 @retval EFI_UNSUPPORTED Action not supported
131
132 **/
133 typedef
134 EFI_STATUS
135 (EFIAPI *EMBEDDED_GPIO_SET_PULL) (
136 IN EMBEDDED_GPIO_PPI *This,
137 IN EMBEDDED_GPIO_PIN Gpio,
138 IN EMBEDDED_GPIO_PULL Direction
139 );
140
141
142 struct _EMBEDDED_GPIO_PPI {
143 EMBEDDED_GPIO_GET Get;
144 EMBEDDED_GPIO_SET Set;
145 EMBEDDED_GPIO_GET_MODE GetMode;
146 EMBEDDED_GPIO_SET_PULL SetPull;
147 };
148
149 extern EFI_GUID gEmbeddedGpioPpiGuid;
150
151 #endif