]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - include/asm-generic/gpio.h
merged tx6dl-devel into denx master branch
[karo-tx-uboot.git] / include / asm-generic / gpio.h
1 /*
2  * Copyright (c) 2011 The Chromium OS Authors.
3  * Copyright (c) 2011, NVIDIA Corp. All rights reserved.
4  * SPDX-License-Identifier:     GPL-2.0+
5  */
6
7 #ifndef _ASM_GENERIC_GPIO_H_
8 #define _ASM_GENERIC_GPIO_H_
9
10 /*
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  */
27
28 enum gpio_flags {
29         GPIOF_INPUT,
30         GPIOF_OUTPUT_INIT_LOW,
31         GPIOF_OUTPUT_INIT_HIGH,
32 };
33
34 struct gpio {
35         unsigned int gpio;
36         enum gpio_flags flags;
37         const char *label;
38 };
39
40 /**
41  * Request a gpio. This should be called before any of the other functions
42  * are used on this gpio.
43  *
44  * @param gp    GPIO number
45  * @param label User label for this GPIO
46  * @return 0 if ok, -1 on error
47  */
48 int gpio_request(unsigned gpio, const char *label);
49
50 /**
51  * Stop using the GPIO.  This function should not alter pin configuration.
52  *
53  * @param gpio  GPIO number
54  * @return 0 if ok, -1 on error
55  */
56 int gpio_free(unsigned gpio);
57
58 /**
59  * Make a GPIO an input.
60  *
61  * @param gpio  GPIO number
62  * @return 0 if ok, -1 on error
63  */
64 int gpio_direction_input(unsigned gpio);
65
66 /**
67  * Make a GPIO an output, and set its value.
68  *
69  * @param gpio  GPIO number
70  * @param value GPIO value (0 for low or 1 for high)
71  * @return 0 if ok, -1 on error
72  */
73 int gpio_direction_output(unsigned gpio, int value);
74
75 /**
76  * Get a GPIO's value. This will work whether the GPIO is an input
77  * or an output.
78  *
79  * @param gpio  GPIO number
80  * @return 0 if low, 1 if high, -1 on error
81  */
82 int gpio_get_value(unsigned gpio);
83
84 /**
85  * Set an output GPIO's value. The GPIO must already be an output or
86  * this function may have no effect.
87  *
88  * @param gpio  GPIO number
89  * @param value GPIO value (0 for low or 1 for high)
90  * @return 0 if ok, -1 on error
91  */
92 int gpio_set_value(unsigned gpio, int value);
93
94 /**
95  * Request a GPIO and configure it
96  * @param gpios pointer to array of gpio defs
97  * @param count number of GPIOs to set up
98  */
99 int gpio_request_one(unsigned gpio, enum gpio_flags flags, const char *label);
100
101 /**
102  * Request a set of GPIOs and configure them
103  * @param gpios pointer to array of gpio defs
104  * @param count number of GPIOs to set up
105  */
106 int gpio_request_array(const struct gpio *gpios, int count);
107
108 /**
109  * Release a set of GPIOs
110  * @param gpios pointer to array of gpio defs
111  * @param count number of GPIOs to set up
112  */
113 int gpio_free_array(const struct gpio *gpios, int count);
114
115 #endif  /* _ASM_GENERIC_GPIO_H_ */