1 /******************************************************************************
2  *
3  *  Copyright (C) 2001-2012 Broadcom Corporation
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 #ifndef UPIO_H
19 #define UPIO_H
20 
21 /* Enumeration of UPIO features                                         */
22 /* Not all features enumerated here are supported by the hardware.      */
23 /* Use UPIO_Feature() to determine support of a particular feature.     */
24 enum
25 {
26     /* LEDs */
27     UPIO_FEAT_LED1,
28     UPIO_FEAT_LED2,
29     UPIO_FEAT_LED3,
30     UPIO_FEAT_LED4,
31     UPIO_FEAT_LED5,
32     UPIO_FEAT_LED6,
33     UPIO_FEAT_LED7,
34     UPIO_FEAT_LED8,
35 
36     /* Switches */
37     UPIO_FEAT_SWITCH1,
38     UPIO_FEAT_SWITCH2,
39     UPIO_FEAT_SWITCH3,
40     UPIO_FEAT_SWITCH4,
41     UPIO_FEAT_SWITCH5,
42     UPIO_FEAT_SWITCH6,
43     UPIO_FEAT_SWITCH7,
44     UPIO_FEAT_SWITCH8,
45     UPIO_FEAT_SWITCH9,
46     UPIO_FEAT_SWITCH10,
47     UPIO_FEAT_SWITCH11,
48     UPIO_FEAT_SWITCH12,
49     UPIO_FEAT_SWITCH13,
50     UPIO_FEAT_SWITCH14,
51     UPIO_FEAT_SWITCH15,
52     UPIO_FEAT_SWITCH16,
53 
54     /* Jumpers */
55     UPIO_FEAT_JUMPER1,
56     UPIO_FEAT_JUMPER2,
57     UPIO_FEAT_JUMPER3,
58     UPIO_FEAT_JUMPER4,
59     UPIO_FEAT_JUMPER5,
60     UPIO_FEAT_JUMPER6,
61     UPIO_FEAT_JUMPER7,
62     UPIO_FEAT_JUMPER8,
63 
64     /* Push buttons */
65     UPIO_FEAT_BUTTON1,
66     UPIO_FEAT_BUTTON2,
67     UPIO_FEAT_BUTTON3,
68     UPIO_FEAT_BUTTON4,
69     UPIO_FEAT_BUTTON5,
70     UPIO_FEAT_BUTTON6,
71     UPIO_FEAT_BUTTON7,
72     UPIO_FEAT_BUTTON8,
73 
74     /* General purpose */
75     UPIO_FEAT_GENERAL1,
76     UPIO_FEAT_GENERAL2,
77     UPIO_FEAT_GENERAL3,
78     UPIO_FEAT_GENERAL4,
79     UPIO_FEAT_GENERAL5,
80     UPIO_FEAT_GENERAL6,
81     UPIO_FEAT_GENERAL7,
82     UPIO_FEAT_GENERAL8,
83     UPIO_FEAT_GENERAL9,
84     UPIO_FEAT_GENERAL10,
85     UPIO_FEAT_GENERAL11,
86     UPIO_FEAT_GENERAL12,
87     UPIO_FEAT_GENERAL13,
88     UPIO_FEAT_GENERAL14,
89     UPIO_FEAT_GENERAL15,
90     UPIO_FEAT_GENERAL16,
91     UPIO_FEAT_GENERAL17,
92     UPIO_FEAT_GENERAL18,
93     UPIO_FEAT_GENERAL19,
94     UPIO_FEAT_GENERAL20,
95     UPIO_FEAT_GENERAL21,
96     UPIO_FEAT_GENERAL22,
97     UPIO_FEAT_GENERAL23,
98     UPIO_FEAT_GENERAL24,
99     UPIO_FEAT_GENERAL25,
100     UPIO_FEAT_GENERAL26,
101     UPIO_FEAT_GENERAL27,
102     UPIO_FEAT_GENERAL28,
103     UPIO_FEAT_GENERAL29,
104     UPIO_FEAT_GENERAL30,
105     UPIO_FEAT_GENERAL31,
106     UPIO_FEAT_GENERAL32,
107 
108     UPIO_FEAT_IN_HIGH,          /* Support for input with interrupt on high signal level. */
109     UPIO_FEAT_IN_LOW,           /* Support for input with interrupt on low signal level. */
110     UPIO_FEAT_IN_RISE,          /* Support for input with interrupt on rising edge. */
111     UPIO_FEAT_IN_FALL           /* Support for input with interrupt on falling. */
112 
113 };
114 typedef UINT8 tUPIO_FEATURE;
115 
116 
117 /* Enumeration of UPIO configurations */
118 enum
119 {
120     UPIO_OUT,
121     UPIO_IN,
122     UPIO_IN_EDGE,
123     UPIO_IN_LEVEL,
124     UPIO_NONE
125 };
126 typedef UINT8 tUPIO_CONFIG;
127 
128 
129 /* Enumeration of UPIO types */
130 enum
131 {
132     UPIO_LED,                   /* LED */
133     UPIO_SWITCH,                /* Switch */
134     UPIO_JUMPER,                /* Jumper */
135     UPIO_BUTTON,                /* Push-button switch */
136     UPIO_GENERAL,               /* General purpose I/O */
137 
138     UPIO_NUMBER_OF_TYPES
139 };
140 typedef UINT8 tUPIO_TYPE;
141 
142 
143 /* Enumeration of UPIO states */
144 enum
145 {
146     UPIO_OFF,
147     UPIO_ON,
148     UPIO_TOGGLE
149 };
150 typedef UINT8 tUPIO_STATE;
151 
152 
153 enum
154 {
155     UPIO_SW_BANK2,
156     UPIO_SW_BANK3
157 };
158 typedef UINT8 tUPIO_SW_BANK;
159 
160 /* Jumper masks */
161 #define UPIO_JUMPER1    0x00000001
162 #define UPIO_JUMPER2    0x00000002
163 #define UPIO_JUMPER3    0x00000004
164 #define UPIO_JUMPER4    0x00000008
165 #define UPIO_JUMPER5    0x00000010
166 #define UPIO_JUMPER6    0x00000020
167 #define UPIO_JUMPER7    0x00000040
168 #define UPIO_JUMPER8    0x00000080
169 
170 /* General purpose i/o masks */
171 #define UPIO_GENERAL1   0x00000001
172 #define UPIO_GENERAL2   0x00000002
173 #define UPIO_GENERAL3   0x00000004
174 #define UPIO_GENERAL4   0x00000008
175 #define UPIO_GENERAL5   0x00000010
176 #define UPIO_GENERAL6   0x00000020
177 #define UPIO_GENERAL7   0x00000040
178 #define UPIO_GENERAL8   0x00000080
179 #define UPIO_GENERAL9   0x00000100
180 #define UPIO_GENERAL10  0x00000200
181 #define UPIO_GENERAL11  0x00000400
182 #define UPIO_GENERAL12  0x00000800
183 #define UPIO_GENERAL13  0x00001000
184 #define UPIO_GENERAL14  0x00002000
185 #define UPIO_GENERAL15  0x00004000
186 #define UPIO_GENERAL16  0x00008000
187 #define UPIO_GENERAL17  0x00010000
188 #define UPIO_GENERAL18  0x00020000
189 #define UPIO_GENERAL19  0x00040000
190 #define UPIO_GENERAL20  0x00080000
191 #define UPIO_GENERAL21  0x00100000
192 #define UPIO_GENERAL22  0x00200000
193 #define UPIO_GENERAL23  0x00400000
194 #define UPIO_GENERAL24  0x00800000
195 #define UPIO_GENERAL25  0x01000000
196 #define UPIO_GENERAL26  0x02000000
197 #define UPIO_GENERAL27  0x04000000
198 #define UPIO_GENERAL28  0x08000000
199 #define UPIO_GENERAL29  0x10000000
200 #define UPIO_GENERAL30  0x20000000
201 #define UPIO_GENERAL31  0x40000000
202 #define UPIO_GENERAL32  0x80000000
203 
204 typedef UINT32 tUPIO;
205 
206 /* LED masks */
207 #define UPIO_LED1       0x00000001
208 #define UPIO_LED2       0x00000002
209 #define UPIO_LED3       0x00000004
210 #define UPIO_LED4       0x00000008
211 #define UPIO_LED5       0x00000010
212 #define UPIO_LED6       0x00000020
213 #define UPIO_LED7       0x00000040
214 #define UPIO_LED8       0x00000080
215 
216 #define UPIO_LED_ALL    (UPIO_LED1 | UPIO_LED2 | UPIO_LED3 | UPIO_LED4 | \
217                         UPIO_LED5 | UPIO_LED6 | UPIO_LED7 | UPIO_LED8)
218 
219 
220 /* Switch masks */
221 #define UPIO_SWITCH1    0x00000001
222 #define UPIO_SWITCH2    0x00000002
223 #define UPIO_SWITCH3    0x00000004
224 #define UPIO_SWITCH4    0x00000008
225 #define UPIO_SWITCH5    0x00000010
226 #define UPIO_SWITCH6    0x00000020
227 #define UPIO_SWITCH7    0x00000040
228 #define UPIO_SWITCH8    0x00000080
229 #define UPIO_SWITCH9    0x00000100
230 #define UPIO_SWITCH10   0x00000200
231 #define UPIO_SWITCH11   0x00000400
232 #define UPIO_SWITCH12   0x00000800
233 #define UPIO_SWITCH13   0x00001000
234 #define UPIO_SWITCH14   0x00002000
235 #define UPIO_SWITCH15   0x00004000
236 #define UPIO_SWITCH16   0x00008000
237 
238 /* Push button masks */
239 #define UPIO_BUTTON1    0x00000001
240 #define UPIO_BUTTON2    0x00000002
241 #define UPIO_BUTTON3    0x00000004
242 #define UPIO_BUTTON4    0x00000008
243 #define UPIO_BUTTON5    0x00000010
244 #define UPIO_BUTTON6    0x00000020
245 #define UPIO_BUTTON7    0x00000040
246 #define UPIO_BUTTON8    0x00000080
247 
248 typedef void (tUPIO_CBACK)(tUPIO_TYPE type, tUPIO pio, tUPIO_STATE state);
249 
250 #ifdef __cplusplus
251 extern "C" {
252 #endif
253 
254 /* API functions for UPIO driver */
255 
256 /*****************************************************************************
257 **
258 ** Function         UPIO_Init
259 **
260 ** Description
261 **      Initialize the GPIO service.
262 **      This function is typically called once upon system startup.
263 **
264 ** Returns          nothing
265 **
266 *****************************************************************************/
267 UDRV_API void UPIO_Init(void *p_cfg);
268 
269 
270 /*****************************************************************************
271 **
272 ** Function         UPIO_Set
273 **
274 ** Description
275 **      This function sets one or more GPIO devices to the given state.
276 **      Multiple GPIOs of the same type can be masked together to set more
277 **      than one GPIO. This function can only be used on types UPIO_LED and
278 **      UPIO_GENERAL.
279 **
280 ** Input Parameters:
281 **      type    The type of device.
282 **      pio     Indicates the particular GPIOs.
283 **      state   The desired state.
284 **
285 ** Output Parameter:
286 **      None.
287 **
288 ** Returns:
289 **      None.
290 **
291 *****************************************************************************/
292 UDRV_API void UPIO_Set(tUPIO_TYPE type, tUPIO pio, tUPIO_STATE state);
293 
294 
295 /*****************************************************************************
296 **
297 ** Function         UPIO_Read
298 **
299 ** Description
300 **      Read the state of a GPIO. This function can be used for any type of
301 **      device. Parameter pio can only indicate a single GPIO; multiple GPIOs
302 **      cannot be masked together.
303 **
304 ** Input Parameters:
305 **      Type:	The type of device.
306 **      pio:    Indicates the particular GUPIO.
307 **
308 ** Output Parameter:
309 **      None.
310 **
311 ** Returns:
312 **      State of GPIO (UPIO_ON or UPIO_OFF).
313 **
314 *****************************************************************************/
315 UDRV_API tUPIO_STATE UPIO_Read(tUPIO_TYPE type, tUPIO pio);
316 
317 
318 /*****************************************************************************
319 **
320 ** Function         UPIO_Config
321 **
322 ** Description      - Configure GPIOs of type UPIO_GENERAL as inputs or outputs
323 **                  - Configure GPIOs to be polled or interrupt driven
324 **
325 **                  Currently only support polled GPIOs.
326 **
327 ** Input Parameters:
328 **      type    The type of device.
329 **      pio     Indicates the particular GPIOs.
330 **      config
331 **      cback
332 **
333 ** Output Parameter:
334 **      None.
335 **
336 ** Returns:
337 **      None.
338 **
339 *****************************************************************************/
340 UDRV_API void UPIO_Config(tUPIO_TYPE type, tUPIO pio, tUPIO_CONFIG config, tUPIO_CBACK *cback);
341 
342 
343 /*****************************************************************************
344 **
345 ** Function         UPIO_Feature
346 **
347 ** Description
348 **      Checks whether a feature of the pio API is supported
349 **
350 ** Input Parameter:
351 **      feature     The feature to check
352 **
353 ** Output Parameter:
354 **      None.
355 **
356 ** Returns:
357 **      TRUE if feature is supported, FALSE if it is not.
358 **
359 *****************************************************************************/
360 UDRV_API BOOLEAN UPIO_Feature(tUPIO_FEATURE feature);
361 
362 #ifdef __cplusplus
363 }
364 #endif
365 
366 #endif  /* ifdef UPIO_H */
367