]>
Commit | Line | Data |
---|---|---|
9d2cb8e8 SG |
1 | /* |
2 | * Copyright (c) 2011 The Chromium OS Authors. | |
5f533aeb | 3 | * Copyright (c) 2011, NVIDIA Corp. All rights reserved. |
1a459660 | 4 | * SPDX-License-Identifier: GPL-2.0+ |
9d2cb8e8 SG |
5 | */ |
6 | ||
5f533aeb JH |
7 | #ifndef _ASM_GENERIC_GPIO_H_ |
8 | #define _ASM_GENERIC_GPIO_H_ | |
9 | ||
9d2cb8e8 SG |
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 | ||
5f533aeb | 28 | /** |
94740e47 NK |
29 | * Request a gpio. This should be called before any of the other functions |
30 | * are used on this gpio. | |
5f533aeb | 31 | * |
94740e47 NK |
32 | * @param gp GPIO number |
33 | * @param label User label for this GPIO | |
5f533aeb JH |
34 | * @return 0 if ok, -1 on error |
35 | */ | |
36 | int gpio_request(unsigned gpio, const char *label); | |
37 | ||
38 | /** | |
39 | * 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 | */ | |
44 | int gpio_free(unsigned gpio); | |
45 | ||
9d2cb8e8 SG |
46 | /** |
47 | * Make a GPIO an input. | |
48 | * | |
5f533aeb | 49 | * @param gpio GPIO number |
9d2cb8e8 SG |
50 | * @return 0 if ok, -1 on error |
51 | */ | |
5f533aeb | 52 | int gpio_direction_input(unsigned gpio); |
9d2cb8e8 SG |
53 | |
54 | /** | |
55 | * Make a GPIO an output, and set its value. | |
56 | * | |
5f533aeb | 57 | * @param gpio GPIO number |
9d2cb8e8 SG |
58 | * @param value GPIO value (0 for low or 1 for high) |
59 | * @return 0 if ok, -1 on error | |
60 | */ | |
5f533aeb | 61 | int gpio_direction_output(unsigned gpio, int value); |
9d2cb8e8 SG |
62 | |
63 | /** | |
64 | * Get a GPIO's value. This will work whether the GPIO is an input | |
65 | * or an output. | |
66 | * | |
5f533aeb | 67 | * @param gpio GPIO number |
9d2cb8e8 SG |
68 | * @return 0 if low, 1 if high, -1 on error |
69 | */ | |
5f533aeb | 70 | int gpio_get_value(unsigned gpio); |
9d2cb8e8 SG |
71 | |
72 | /** | |
5f533aeb | 73 | * Set an output GPIO's value. The GPIO must already be an output or |
9d2cb8e8 SG |
74 | * this function may have no effect. |
75 | * | |
5f533aeb | 76 | * @param gpio GPIO number |
9d2cb8e8 SG |
77 | * @param value GPIO value (0 for low or 1 for high) |
78 | * @return 0 if ok, -1 on error | |
79 | */ | |
5f533aeb | 80 | int gpio_set_value(unsigned gpio, int value); |
5f533aeb | 81 | #endif /* _ASM_GENERIC_GPIO_H_ */ |