Simon Glass | 9c35f0e | 2011-10-07 13:53:50 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 The Chromium OS Authors. |
Joe Hershberger | 334b232 | 2011-11-11 15:55:35 -0600 | [diff] [blame] | 3 | * Copyright (c) 2011, NVIDIA Corp. All rights reserved. |
Simon Glass | 9c35f0e | 2011-10-07 13:53:50 +0000 | [diff] [blame] | 4 | * 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 Hershberger | 334b232 | 2011-11-11 15:55:35 -0600 | [diff] [blame] | 23 | #ifndef _ASM_GENERIC_GPIO_H_ |
| 24 | #define _ASM_GENERIC_GPIO_H_ |
| 25 | |
Simon Glass | 9c35f0e | 2011-10-07 13:53:50 +0000 | [diff] [blame] | 26 | /* |
| 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 Hershberger | 334b232 | 2011-11-11 15:55:35 -0600 | [diff] [blame] | 43 | |
| 44 | /** |
| 45 | * Request ownership of a GPIO. |
| 46 | * |
| 47 | * @param gpio GPIO number |
| 48 | * @param label Name given to the GPIO |
| 49 | * @return 0 if ok, -1 on error |
| 50 | */ |
| 51 | int gpio_request(unsigned gpio, const char *label); |
Simon Glass | 9c35f0e | 2011-10-07 13:53:50 +0000 | [diff] [blame] | 52 | |
| 53 | /** |
Joe Hershberger | 334b232 | 2011-11-11 15:55:35 -0600 | [diff] [blame] | 54 | * Stop using the GPIO. This function should not alter pin configuration. |
| 55 | * |
| 56 | * @param gpio GPIO number |
| 57 | * @return 0 if ok, -1 on error |
| 58 | */ |
| 59 | int gpio_free(unsigned gpio); |
| 60 | |
| 61 | /** |
Simon Glass | 9c35f0e | 2011-10-07 13:53:50 +0000 | [diff] [blame] | 62 | * Make a GPIO an input. |
| 63 | * |
Joe Hershberger | 334b232 | 2011-11-11 15:55:35 -0600 | [diff] [blame] | 64 | * @param gpio GPIO number |
Simon Glass | 9c35f0e | 2011-10-07 13:53:50 +0000 | [diff] [blame] | 65 | * @return 0 if ok, -1 on error |
| 66 | */ |
Joe Hershberger | 334b232 | 2011-11-11 15:55:35 -0600 | [diff] [blame] | 67 | int gpio_direction_input(unsigned gpio); |
Simon Glass | 9c35f0e | 2011-10-07 13:53:50 +0000 | [diff] [blame] | 68 | |
| 69 | /** |
| 70 | * Make a GPIO an output, and set its value. |
| 71 | * |
Joe Hershberger | 334b232 | 2011-11-11 15:55:35 -0600 | [diff] [blame] | 72 | * @param gpio GPIO number |
Simon Glass | 9c35f0e | 2011-10-07 13:53:50 +0000 | [diff] [blame] | 73 | * @param value GPIO value (0 for low or 1 for high) |
| 74 | * @return 0 if ok, -1 on error |
| 75 | */ |
Joe Hershberger | 334b232 | 2011-11-11 15:55:35 -0600 | [diff] [blame] | 76 | int gpio_direction_output(unsigned gpio, int value); |
Simon Glass | 9c35f0e | 2011-10-07 13:53:50 +0000 | [diff] [blame] | 77 | |
| 78 | /** |
| 79 | * Get a GPIO's value. This will work whether the GPIO is an input |
| 80 | * or an output. |
| 81 | * |
Joe Hershberger | 334b232 | 2011-11-11 15:55:35 -0600 | [diff] [blame] | 82 | * @param gpio GPIO number |
Simon Glass | 9c35f0e | 2011-10-07 13:53:50 +0000 | [diff] [blame] | 83 | * @return 0 if low, 1 if high, -1 on error |
| 84 | */ |
Joe Hershberger | 334b232 | 2011-11-11 15:55:35 -0600 | [diff] [blame] | 85 | int gpio_get_value(unsigned gpio); |
Simon Glass | 9c35f0e | 2011-10-07 13:53:50 +0000 | [diff] [blame] | 86 | |
| 87 | /** |
Joe Hershberger | 334b232 | 2011-11-11 15:55:35 -0600 | [diff] [blame] | 88 | * Set an output GPIO's value. The GPIO must already be an output or |
Simon Glass | 9c35f0e | 2011-10-07 13:53:50 +0000 | [diff] [blame] | 89 | * this function may have no effect. |
| 90 | * |
Joe Hershberger | 334b232 | 2011-11-11 15:55:35 -0600 | [diff] [blame] | 91 | * @param gpio GPIO number |
Simon Glass | 9c35f0e | 2011-10-07 13:53:50 +0000 | [diff] [blame] | 92 | * @param value GPIO value (0 for low or 1 for high) |
| 93 | * @return 0 if ok, -1 on error |
| 94 | */ |
Joe Hershberger | 334b232 | 2011-11-11 15:55:35 -0600 | [diff] [blame] | 95 | int gpio_set_value(unsigned gpio, int value); |
| 96 | |
Simon Glass | eadbf1a | 2012-06-13 06:19:37 +0000 | [diff] [blame] | 97 | /** |
| 98 | * Request a gpio. This should be called before any of the other functions |
| 99 | * are used on this gpio. |
| 100 | * |
| 101 | * @param gp GPIO number |
| 102 | * @param label User label for this GPIO |
| 103 | * @return 0 if ok, -1 on error |
| 104 | */ |
| 105 | int gpio_request(unsigned gpio, const char *label); |
Joe Hershberger | 334b232 | 2011-11-11 15:55:35 -0600 | [diff] [blame] | 106 | #endif /* _ASM_GENERIC_GPIO_H_ */ |