blob: f54103980c3348775e163d3e8163f59ddceedbb6 [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.
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Simon Glass9c35f0e2011-10-07 13:53:50 +00005 */
6
Joe Hershberger334b2322011-11-11 15:55:35 -06007#ifndef _ASM_GENERIC_GPIO_H_
8#define _ASM_GENERIC_GPIO_H_
9
Simon Glass9c35f0e2011-10-07 13:53:50 +000010/*
11 * Generic GPIO API for U-Boot
12 *
13 * GPIOs are numbered from 0 to GPIO_COUNT-1 which value is defined
14 * by the SOC/architecture.
15 *
16 * Each GPIO can be an input or output. If an input then its value can
17 * be read as 0 or 1. If an output then its value can be set to 0 or 1.
18 * If you try to write an input then the value is undefined. If you try
19 * to read an output, barring something very unusual, you will get
20 * back the value of the output that you previously set.
21 *
22 * In some cases the operation may fail, for example if the GPIO number
23 * is out of range, or the GPIO is not available because its pin is
24 * being used by another function. In that case, functions may return
25 * an error value of -1.
26 */
Joe Hershberger334b2322011-11-11 15:55:35 -060027
28/**
Nikita Kiryanovd9a67172012-11-26 23:06:32 +000029 * Request a gpio. This should be called before any of the other functions
30 * are used on this gpio.
Joe Hershberger334b2322011-11-11 15:55:35 -060031 *
Nikita Kiryanovd9a67172012-11-26 23:06:32 +000032 * @param gp GPIO number
33 * @param label User label for this GPIO
Joe Hershberger334b2322011-11-11 15:55:35 -060034 * @return 0 if ok, -1 on error
35 */
36int gpio_request(unsigned gpio, const char *label);
Simon Glass9c35f0e2011-10-07 13:53:50 +000037
38/**
Joe Hershberger334b2322011-11-11 15:55:35 -060039 * Stop using the GPIO. This function should not alter pin configuration.
40 *
41 * @param gpio GPIO number
42 * @return 0 if ok, -1 on error
43 */
44int gpio_free(unsigned gpio);
45
46/**
Simon Glass9c35f0e2011-10-07 13:53:50 +000047 * Make a GPIO an input.
48 *
Joe Hershberger334b2322011-11-11 15:55:35 -060049 * @param gpio GPIO number
Simon Glass9c35f0e2011-10-07 13:53:50 +000050 * @return 0 if ok, -1 on error
51 */
Joe Hershberger334b2322011-11-11 15:55:35 -060052int gpio_direction_input(unsigned gpio);
Simon Glass9c35f0e2011-10-07 13:53:50 +000053
54/**
55 * Make a GPIO an output, and set its value.
56 *
Joe Hershberger334b2322011-11-11 15:55:35 -060057 * @param gpio GPIO number
Simon Glass9c35f0e2011-10-07 13:53:50 +000058 * @param value GPIO value (0 for low or 1 for high)
59 * @return 0 if ok, -1 on error
60 */
Joe Hershberger334b2322011-11-11 15:55:35 -060061int gpio_direction_output(unsigned gpio, int value);
Simon Glass9c35f0e2011-10-07 13:53:50 +000062
63/**
64 * Get a GPIO's value. This will work whether the GPIO is an input
65 * or an output.
66 *
Joe Hershberger334b2322011-11-11 15:55:35 -060067 * @param gpio GPIO number
Simon Glass9c35f0e2011-10-07 13:53:50 +000068 * @return 0 if low, 1 if high, -1 on error
69 */
Joe Hershberger334b2322011-11-11 15:55:35 -060070int gpio_get_value(unsigned gpio);
Simon Glass9c35f0e2011-10-07 13:53:50 +000071
72/**
Joe Hershberger334b2322011-11-11 15:55:35 -060073 * Set an output GPIO's value. The GPIO must already be an output or
Simon Glass9c35f0e2011-10-07 13:53:50 +000074 * this function may have no effect.
75 *
Joe Hershberger334b2322011-11-11 15:55:35 -060076 * @param gpio GPIO number
Simon Glass9c35f0e2011-10-07 13:53:50 +000077 * @param value GPIO value (0 for low or 1 for high)
78 * @return 0 if ok, -1 on error
79 */
Joe Hershberger334b2322011-11-11 15:55:35 -060080int gpio_set_value(unsigned gpio, int value);
Joe Hershberger334b2322011-11-11 15:55:35 -060081#endif /* _ASM_GENERIC_GPIO_H_ */