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