EmbeddedPkg: Replace BSD License with BSD+Patent License
[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 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #ifndef __EMBEDDED_GPIO_PPI_H__
11 #define __EMBEDDED_GPIO_PPI_H__
12
13 //
14 // Protocol interface structure
15 //
16 typedef struct _EMBEDDED_GPIO_PPI EMBEDDED_GPIO_PPI;
17
18 //
19 // Data Types
20 //
21 typedef UINTN EMBEDDED_GPIO_PIN;
22
23 #define GPIO(Port, Pin) ((EMBEDDED_GPIO_PIN)(((Port) << (16)) | (Pin)))
24 #define GPIO_PIN(x) ((EMBEDDED_GPIO_PIN)(x) & (0xFFFF))
25 #define GPIO_PORT(x) ((EMBEDDED_GPIO_PIN)(x) >> (16))
26
27 typedef enum {
28 GPIO_MODE_INPUT = 0x00,
29 GPIO_MODE_OUTPUT_0 = 0x0E,
30 GPIO_MODE_OUTPUT_1 = 0x0F,
31 GPIO_MODE_SPECIAL_FUNCTION_2 = 0x02,
32 GPIO_MODE_SPECIAL_FUNCTION_3 = 0x03,
33 GPIO_MODE_SPECIAL_FUNCTION_4 = 0x04,
34 GPIO_MODE_SPECIAL_FUNCTION_5 = 0x05,
35 GPIO_MODE_SPECIAL_FUNCTION_6 = 0x06,
36 GPIO_MODE_SPECIAL_FUNCTION_7 = 0x07
37 } EMBEDDED_GPIO_MODE;
38
39 typedef enum {
40 GPIO_PULL_NONE,
41 GPIO_PULL_UP,
42 GPIO_PULL_DOWN
43 } EMBEDDED_GPIO_PULL;
44
45 //
46 // Function Prototypes
47 //
48
49 /**
50
51 Gets the state of a GPIO pin
52
53 @param This Pointer to protocol
54 @param Gpio Which pin to read
55 @param Value State of the pin
56
57 @retval EFI_SUCCESS GPIO state returned in Value
58 @retval EFI_INVALID_PARAMETER Value is NULL
59 @retval EFI_NOT_FOUND Pin does not exit
60
61 **/
62 typedef
63 EFI_STATUS
64 (EFIAPI *EMBEDDED_GPIO_GET) (
65 IN EMBEDDED_GPIO_PPI *This,
66 IN EMBEDDED_GPIO_PIN Gpio,
67 OUT UINTN *Value
68 );
69
70 /**
71
72 Sets the state of a GPIO pin
73
74 @param This Pointer to protocol
75 @param Gpio Which pin to modify
76 @param Mode Mode to set
77
78 @retval EFI_SUCCESS GPIO set as requested
79 @retval EFI_INVALID_PARAMETER Invalid mode
80 @retval EFI_NOT_FOUND Pin does not exit
81
82 **/
83 typedef
84 EFI_STATUS
85 (EFIAPI *EMBEDDED_GPIO_SET) (
86 IN EMBEDDED_GPIO_PPI *This,
87 IN EMBEDDED_GPIO_PIN Gpio,
88 IN EMBEDDED_GPIO_MODE Mode
89 );
90
91
92 /**
93
94 Gets the mode (function) of a GPIO pin
95
96 @param This Pointer to protocol
97 @param Gpio Which pin
98 @param Mode Pointer to output mode value
99
100 @retval EFI_SUCCESS Mode value retrieved
101 @retval EFI_INVALID_PARAMETER Mode is NULL
102 @retval EFI_NOT_FOUND Pin does not exit
103
104 **/
105 typedef
106 EFI_STATUS
107 (EFIAPI *EMBEDDED_GPIO_GET_MODE) (
108 IN EMBEDDED_GPIO_PPI *This,
109 IN EMBEDDED_GPIO_PIN Gpio,
110 OUT EMBEDDED_GPIO_MODE *Mode
111 );
112
113
114 /**
115
116 Sets the pull-up / pull-down resistor of a GPIO pin
117
118 @param This Pointer to PPI
119 @param Gpio Port/pin index
120 @param Pull The pullup/pulldown mode to set
121
122 @retval EFI_SUCCESS Mode was set
123 @retval EFI_NOT_FOUND Pin does not exist
124 @retval EFI_UNSUPPORTED Action not supported
125
126 **/
127 typedef
128 EFI_STATUS
129 (EFIAPI *EMBEDDED_GPIO_SET_PULL) (
130 IN EMBEDDED_GPIO_PPI *This,
131 IN EMBEDDED_GPIO_PIN Gpio,
132 IN EMBEDDED_GPIO_PULL Direction
133 );
134
135
136 struct _EMBEDDED_GPIO_PPI {
137 EMBEDDED_GPIO_GET Get;
138 EMBEDDED_GPIO_SET Set;
139 EMBEDDED_GPIO_GET_MODE GetMode;
140 EMBEDDED_GPIO_SET_PULL SetPull;
141 };
142
143 extern EFI_GUID gEmbeddedGpioPpiGuid;
144
145 #endif