blob: bfedbe44596aa31fb2266f7e052a63401f06d181 [file] [log] [blame]
Simon Glass9c35f0e2011-10-07 13:53:50 +00001/*
2 * Copyright (c) 2011 The Chromium OS Authors.
Joe Hershberger334b2322011-11-11 15:55:35 -06003 * Copyright (c) 2011, NVIDIA Corp. All rights reserved.
Simon Glass9c35f0e2011-10-07 13:53:50 +00004 * 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
Joe Hershberger334b2322011-11-11 15:55:35 -060023#ifndef _ASM_GENERIC_GPIO_H_
24#define _ASM_GENERIC_GPIO_H_
25
Simon Glass9c35f0e2011-10-07 13:53:50 +000026/*
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 */
Joe Hershberger334b2322011-11-11 15:55:35 -060043
44/**
Nikita Kiryanovd9a67172012-11-26 23:06:32 +000045 * Request a gpio. This should be called before any of the other functions
46 * are used on this gpio.
Joe Hershberger334b2322011-11-11 15:55:35 -060047 *
Nikita Kiryanovd9a67172012-11-26 23:06:32 +000048 * @param gp GPIO number
49 * @param label User label for this GPIO
Joe Hershberger334b2322011-11-11 15:55:35 -060050 * @return 0 if ok, -1 on error
51 */
52int gpio_request(unsigned gpio, const char *label);
Simon Glass9c35f0e2011-10-07 13:53:50 +000053
54/**
Joe Hershberger334b2322011-11-11 15:55:35 -060055 * Stop using the GPIO. This function should not alter pin configuration.
56 *
57 * @param gpio GPIO number
58 * @return 0 if ok, -1 on error
59 */
60int gpio_free(unsigned gpio);
61
62/**
Simon Glass9c35f0e2011-10-07 13:53:50 +000063 * Make a GPIO an input.
64 *
Joe Hershberger334b2322011-11-11 15:55:35 -060065 * @param gpio GPIO number
Simon Glass9c35f0e2011-10-07 13:53:50 +000066 * @return 0 if ok, -1 on error
67 */
Joe Hershberger334b2322011-11-11 15:55:35 -060068int gpio_direction_input(unsigned gpio);
Simon Glass9c35f0e2011-10-07 13:53:50 +000069
70/**
71 * Make a GPIO an output, and set its value.
72 *
Joe Hershberger334b2322011-11-11 15:55:35 -060073 * @param gpio GPIO number
Simon Glass9c35f0e2011-10-07 13:53:50 +000074 * @param value GPIO value (0 for low or 1 for high)
75 * @return 0 if ok, -1 on error
76 */
Joe Hershberger334b2322011-11-11 15:55:35 -060077int gpio_direction_output(unsigned gpio, int value);
Simon Glass9c35f0e2011-10-07 13:53:50 +000078
79/**
80 * Get a GPIO's value. This will work whether the GPIO is an input
81 * or an output.
82 *
Joe Hershberger334b2322011-11-11 15:55:35 -060083 * @param gpio GPIO number
Simon Glass9c35f0e2011-10-07 13:53:50 +000084 * @return 0 if low, 1 if high, -1 on error
85 */
Joe Hershberger334b2322011-11-11 15:55:35 -060086int gpio_get_value(unsigned gpio);
Simon Glass9c35f0e2011-10-07 13:53:50 +000087
88/**
Joe Hershberger334b2322011-11-11 15:55:35 -060089 * Set an output GPIO's value. The GPIO must already be an output or
Simon Glass9c35f0e2011-10-07 13:53:50 +000090 * this function may have no effect.
91 *
Joe Hershberger334b2322011-11-11 15:55:35 -060092 * @param gpio GPIO number
Simon Glass9c35f0e2011-10-07 13:53:50 +000093 * @param value GPIO value (0 for low or 1 for high)
94 * @return 0 if ok, -1 on error
95 */
Joe Hershberger334b2322011-11-11 15:55:35 -060096int gpio_set_value(unsigned gpio, int value);
Joe Hershberger334b2322011-11-11 15:55:35 -060097#endif /* _ASM_GENERIC_GPIO_H_ */