]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - include/asm-generic/gpio.h
Unified codebase for TX28, TX48, TX51, TX53
[karo-tx-uboot.git] / include / asm-generic / gpio.h
1 /*
2  * Copyright (c) 2011 The Chromium OS Authors.
3  * Copyright (c) 2011, NVIDIA Corp. All rights reserved.
4  * See file CREDITS for list of people who contributed to this
5  * project.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of
10  * the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20  * MA 02111-1307 USA
21  */
22
23 #ifndef _ASM_GENERIC_GPIO_H_
24 #define _ASM_GENERIC_GPIO_H_
25
26 /*
27  * Generic GPIO API for U-Boot
28  *
29  * GPIOs are numbered from 0 to GPIO_COUNT-1 which value is defined
30  * by the SOC/architecture.
31  *
32  * Each GPIO can be an input or output. If an input then its value can
33  * be read as 0 or 1. If an output then its value can be set to 0 or 1.
34  * If you try to write an input then the value is undefined. If you try
35  * to read an output, barring something very unusual,  you will get
36  * back the value of the output that you previously set.
37  *
38  * In some cases the operation may fail, for example if the GPIO number
39  * is out of range, or the GPIO is not available because its pin is
40  * being used by another function. In that case, functions may return
41  * an error value of -1.
42  */
43
44 enum gpio_flags {
45         GPIOF_INPUT,
46         GPIOF_OUTPUT_INIT_LOW,
47         GPIOF_OUTPUT_INIT_HIGH,
48 };
49
50 struct gpio {
51         unsigned int gpio;
52         enum gpio_flags flags;
53         const char *label;
54 };
55
56 /**
57  * Request ownership of a GPIO.
58  *
59  * @param gpio  GPIO number
60  * @param label Name given to the GPIO
61  * @return 0 if ok, -1 on error
62  */
63 int gpio_request(unsigned gpio, const char *label);
64
65 /**
66  * Stop using the GPIO.  This function should not alter pin configuration.
67  *
68  * @param gpio  GPIO number
69  * @return 0 if ok, -1 on error
70  */
71 int gpio_free(unsigned gpio);
72
73 /**
74  * Make a GPIO an input.
75  *
76  * @param gpio  GPIO number
77  * @return 0 if ok, -1 on error
78  */
79 int gpio_direction_input(unsigned gpio);
80
81 /**
82  * Make a GPIO an output, and set its value.
83  *
84  * @param gpio  GPIO number
85  * @param value GPIO value (0 for low or 1 for high)
86  * @return 0 if ok, -1 on error
87  */
88 int gpio_direction_output(unsigned gpio, int value);
89
90 /**
91  * Get a GPIO's value. This will work whether the GPIO is an input
92  * or an output.
93  *
94  * @param gpio  GPIO number
95  * @return 0 if low, 1 if high, -1 on error
96  */
97 int gpio_get_value(unsigned gpio);
98
99 /**
100  * Set an output GPIO's value. The GPIO must already be an output or
101  * this function may have no effect.
102  *
103  * @param gpio  GPIO number
104  * @param value GPIO value (0 for low or 1 for high)
105  * @return 0 if ok, -1 on error
106  */
107 int gpio_set_value(unsigned gpio, int value);
108
109 /**
110  * Request a GPIO and configure it
111  * @param gpios pointer to array of gpio defs
112  * @param count number of GPIOs to set up
113  */
114 int gpio_request_one(unsigned gpio, enum gpio_flags flags, const char *label);
115
116 /**
117  * Request a set of GPIOs and configure them
118  * @param gpios pointer to array of gpio defs
119  * @param count number of GPIOs to set up
120  */
121 int gpio_request_array(const struct gpio *gpios, int count);
122
123 /**
124  * Release a set of GPIOs
125  * @param gpios pointer to array of gpio defs
126  * @param count number of GPIOs to set up
127  */
128 int gpio_free_array(const struct gpio *gpios, int count);
129
130 #endif  /* _ASM_GENERIC_GPIO_H_ */