xref: /rk3399_rockchip-uboot/include/asm-generic/gpio.h (revision 5f533aeb5117ebe4ef1d10b5cae326334965035d)
19d2cb8e8SSimon Glass /*
29d2cb8e8SSimon Glass  * Copyright (c) 2011 The Chromium OS Authors.
3*5f533aebSJoe Hershberger  * Copyright (c) 2011, NVIDIA Corp. All rights reserved.
49d2cb8e8SSimon Glass  * See file CREDITS for list of people who contributed to this
59d2cb8e8SSimon Glass  * project.
69d2cb8e8SSimon Glass  *
79d2cb8e8SSimon Glass  * This program is free software; you can redistribute it and/or
89d2cb8e8SSimon Glass  * modify it under the terms of the GNU General Public License as
99d2cb8e8SSimon Glass  * published by the Free Software Foundation; either version 2 of
109d2cb8e8SSimon Glass  * the License, or (at your option) any later version.
119d2cb8e8SSimon Glass  *
129d2cb8e8SSimon Glass  * This program is distributed in the hope that it will be useful,
139d2cb8e8SSimon Glass  * but WITHOUT ANY WARRANTY; without even the implied warranty of
149d2cb8e8SSimon Glass  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
159d2cb8e8SSimon Glass  * GNU General Public License for more details.
169d2cb8e8SSimon Glass  *
179d2cb8e8SSimon Glass  * You should have received a copy of the GNU General Public License
189d2cb8e8SSimon Glass  * along with this program; if not, write to the Free Software
199d2cb8e8SSimon Glass  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
209d2cb8e8SSimon Glass  * MA 02111-1307 USA
219d2cb8e8SSimon Glass  */
229d2cb8e8SSimon Glass 
23*5f533aebSJoe Hershberger #ifndef _ASM_GENERIC_GPIO_H_
24*5f533aebSJoe Hershberger #define _ASM_GENERIC_GPIO_H_
25*5f533aebSJoe Hershberger 
269d2cb8e8SSimon Glass /*
279d2cb8e8SSimon Glass  * Generic GPIO API for U-Boot
289d2cb8e8SSimon Glass  *
299d2cb8e8SSimon Glass  * GPIOs are numbered from 0 to GPIO_COUNT-1 which value is defined
309d2cb8e8SSimon Glass  * by the SOC/architecture.
319d2cb8e8SSimon Glass  *
329d2cb8e8SSimon Glass  * Each GPIO can be an input or output. If an input then its value can
339d2cb8e8SSimon Glass  * be read as 0 or 1. If an output then its value can be set to 0 or 1.
349d2cb8e8SSimon Glass  * If you try to write an input then the value is undefined. If you try
359d2cb8e8SSimon Glass  * to read an output, barring something very unusual,  you will get
369d2cb8e8SSimon Glass  * back the value of the output that you previously set.
379d2cb8e8SSimon Glass  *
389d2cb8e8SSimon Glass  * In some cases the operation may fail, for example if the GPIO number
399d2cb8e8SSimon Glass  * is out of range, or the GPIO is not available because its pin is
409d2cb8e8SSimon Glass  * being used by another function. In that case, functions may return
419d2cb8e8SSimon Glass  * an error value of -1.
429d2cb8e8SSimon Glass  */
439d2cb8e8SSimon Glass 
449d2cb8e8SSimon Glass /**
45*5f533aebSJoe Hershberger  * Request ownership of a GPIO.
469d2cb8e8SSimon Glass  *
47*5f533aebSJoe Hershberger  * @param gpio	GPIO number
48*5f533aebSJoe Hershberger  * @param label	Name given to the GPIO
499d2cb8e8SSimon Glass  * @return 0 if ok, -1 on error
509d2cb8e8SSimon Glass  */
51*5f533aebSJoe Hershberger int gpio_request(unsigned gpio, const char *label);
52*5f533aebSJoe Hershberger 
53*5f533aebSJoe Hershberger /**
54*5f533aebSJoe Hershberger  * Stop using the GPIO.  This function should not alter pin configuration.
55*5f533aebSJoe Hershberger  *
56*5f533aebSJoe Hershberger  * @param gpio	GPIO number
57*5f533aebSJoe Hershberger  * @return 0 if ok, -1 on error
58*5f533aebSJoe Hershberger  */
59*5f533aebSJoe Hershberger int gpio_free(unsigned gpio);
60*5f533aebSJoe Hershberger 
61*5f533aebSJoe Hershberger /**
62*5f533aebSJoe Hershberger  * Make a GPIO an input.
63*5f533aebSJoe Hershberger  *
64*5f533aebSJoe Hershberger  * @param gpio	GPIO number
65*5f533aebSJoe Hershberger  * @return 0 if ok, -1 on error
66*5f533aebSJoe Hershberger  */
67*5f533aebSJoe Hershberger int gpio_direction_input(unsigned gpio);
689d2cb8e8SSimon Glass 
699d2cb8e8SSimon Glass /**
709d2cb8e8SSimon Glass  * Make a GPIO an output, and set its value.
719d2cb8e8SSimon Glass  *
72*5f533aebSJoe Hershberger  * @param gpio	GPIO number
739d2cb8e8SSimon Glass  * @param value	GPIO value (0 for low or 1 for high)
749d2cb8e8SSimon Glass  * @return 0 if ok, -1 on error
759d2cb8e8SSimon Glass  */
76*5f533aebSJoe Hershberger int gpio_direction_output(unsigned gpio, int value);
779d2cb8e8SSimon Glass 
789d2cb8e8SSimon Glass /**
799d2cb8e8SSimon Glass  * Get a GPIO's value. This will work whether the GPIO is an input
809d2cb8e8SSimon Glass  * or an output.
819d2cb8e8SSimon Glass  *
82*5f533aebSJoe Hershberger  * @param gpio	GPIO number
839d2cb8e8SSimon Glass  * @return 0 if low, 1 if high, -1 on error
849d2cb8e8SSimon Glass  */
85*5f533aebSJoe Hershberger int gpio_get_value(unsigned gpio);
869d2cb8e8SSimon Glass 
879d2cb8e8SSimon Glass /**
88*5f533aebSJoe Hershberger  * Set an output GPIO's value. The GPIO must already be an output or
899d2cb8e8SSimon Glass  * this function may have no effect.
909d2cb8e8SSimon Glass  *
91*5f533aebSJoe Hershberger  * @param gpio	GPIO number
929d2cb8e8SSimon Glass  * @param value	GPIO value (0 for low or 1 for high)
939d2cb8e8SSimon Glass  * @return 0 if ok, -1 on error
949d2cb8e8SSimon Glass  */
95*5f533aebSJoe Hershberger int gpio_set_value(unsigned gpio, int value);
96*5f533aebSJoe Hershberger 
97*5f533aebSJoe Hershberger #endif	/* _ASM_GENERIC_GPIO_H_ */
98