xref: /openbmc/u-boot/include/asm-generic/gpio.h (revision 2482e3c8)
1 /*
2  * Copyright (c) 2011 The Chromium OS Authors.
3  * See file CREDITS for list of people who contributed to this
4  * project.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
19  * MA 02111-1307 USA
20  */
21 
22 /*
23  * Generic GPIO API for U-Boot
24  *
25  * GPIOs are numbered from 0 to GPIO_COUNT-1 which value is defined
26  * by the SOC/architecture.
27  *
28  * Each GPIO can be an input or output. If an input then its value can
29  * be read as 0 or 1. If an output then its value can be set to 0 or 1.
30  * If you try to write an input then the value is undefined. If you try
31  * to read an output, barring something very unusual,  you will get
32  * back the value of the output that you previously set.
33  *
34  * In some cases the operation may fail, for example if the GPIO number
35  * is out of range, or the GPIO is not available because its pin is
36  * being used by another function. In that case, functions may return
37  * an error value of -1.
38  */
39 
40 /**
41  * Make a GPIO an input.
42  *
43  * @param gp	GPIO number
44  * @return 0 if ok, -1 on error
45  */
46 int gpio_direction_input(int gp);
47 
48 /**
49  * Make a GPIO an output, and set its value.
50  *
51  * @param gp	GPIO number
52  * @param value	GPIO value (0 for low or 1 for high)
53  * @return 0 if ok, -1 on error
54  */
55 int gpio_direction_output(int gp, int value);
56 
57 /**
58  * Get a GPIO's value. This will work whether the GPIO is an input
59  * or an output.
60  *
61  * @param gp	GPIO number
62  * @return 0 if low, 1 if high, -1 on error
63  */
64 int gpio_get_value(int gp);
65 
66 /**
67  * Set an output GPIO's value. The GPIO must already be an output of
68  * this function may have no effect.
69  *
70  * @param gp	GPIO number
71  * @param value	GPIO value (0 for low or 1 for high)
72  * @return 0 if ok, -1 on error
73  */
74 int gpio_set_value(int gp, int value);
75