19d2cb8e8SSimon Glass /* 29d2cb8e8SSimon Glass * Copyright (c) 2011 The Chromium OS Authors. 35f533aebSJoe Hershberger * Copyright (c) 2011, NVIDIA Corp. All rights reserved. 49d2cb8e8SSimon Glass * See file CREDITS for list of people who contributed to this 59d2cb8e8SSimon Glass * project. 69d2cb8e8SSimon Glass * 79d2cb8e8SSimon Glass * This program is free software; you can redistribute it and/or 89d2cb8e8SSimon Glass * modify it under the terms of the GNU General Public License as 99d2cb8e8SSimon Glass * published by the Free Software Foundation; either version 2 of 109d2cb8e8SSimon Glass * the License, or (at your option) any later version. 119d2cb8e8SSimon Glass * 129d2cb8e8SSimon Glass * This program is distributed in the hope that it will be useful, 139d2cb8e8SSimon Glass * but WITHOUT ANY WARRANTY; without even the implied warranty of 149d2cb8e8SSimon Glass * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 159d2cb8e8SSimon Glass * GNU General Public License for more details. 169d2cb8e8SSimon Glass * 179d2cb8e8SSimon Glass * You should have received a copy of the GNU General Public License 189d2cb8e8SSimon Glass * along with this program; if not, write to the Free Software 199d2cb8e8SSimon Glass * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 209d2cb8e8SSimon Glass * MA 02111-1307 USA 219d2cb8e8SSimon Glass */ 229d2cb8e8SSimon Glass 235f533aebSJoe Hershberger #ifndef _ASM_GENERIC_GPIO_H_ 245f533aebSJoe Hershberger #define _ASM_GENERIC_GPIO_H_ 255f533aebSJoe Hershberger 269d2cb8e8SSimon Glass /* 279d2cb8e8SSimon Glass * Generic GPIO API for U-Boot 289d2cb8e8SSimon Glass * 299d2cb8e8SSimon Glass * GPIOs are numbered from 0 to GPIO_COUNT-1 which value is defined 309d2cb8e8SSimon Glass * by the SOC/architecture. 319d2cb8e8SSimon Glass * 329d2cb8e8SSimon Glass * Each GPIO can be an input or output. If an input then its value can 339d2cb8e8SSimon Glass * be read as 0 or 1. If an output then its value can be set to 0 or 1. 349d2cb8e8SSimon Glass * If you try to write an input then the value is undefined. If you try 359d2cb8e8SSimon Glass * to read an output, barring something very unusual, you will get 369d2cb8e8SSimon Glass * back the value of the output that you previously set. 379d2cb8e8SSimon Glass * 389d2cb8e8SSimon Glass * In some cases the operation may fail, for example if the GPIO number 399d2cb8e8SSimon Glass * is out of range, or the GPIO is not available because its pin is 409d2cb8e8SSimon Glass * being used by another function. In that case, functions may return 419d2cb8e8SSimon Glass * an error value of -1. 429d2cb8e8SSimon Glass */ 439d2cb8e8SSimon Glass 449d2cb8e8SSimon Glass /** 45*94740e47SNikita Kiryanov * Request a gpio. This should be called before any of the other functions 46*94740e47SNikita Kiryanov * are used on this gpio. 479d2cb8e8SSimon Glass * 48*94740e47SNikita Kiryanov * @param gp GPIO number 49*94740e47SNikita Kiryanov * @param label User label for this GPIO 509d2cb8e8SSimon Glass * @return 0 if ok, -1 on error 519d2cb8e8SSimon Glass */ 525f533aebSJoe Hershberger int gpio_request(unsigned gpio, const char *label); 535f533aebSJoe Hershberger 545f533aebSJoe Hershberger /** 555f533aebSJoe Hershberger * Stop using the GPIO. This function should not alter pin configuration. 565f533aebSJoe Hershberger * 575f533aebSJoe Hershberger * @param gpio GPIO number 585f533aebSJoe Hershberger * @return 0 if ok, -1 on error 595f533aebSJoe Hershberger */ 605f533aebSJoe Hershberger int gpio_free(unsigned gpio); 615f533aebSJoe Hershberger 625f533aebSJoe Hershberger /** 635f533aebSJoe Hershberger * Make a GPIO an input. 645f533aebSJoe Hershberger * 655f533aebSJoe Hershberger * @param gpio GPIO number 665f533aebSJoe Hershberger * @return 0 if ok, -1 on error 675f533aebSJoe Hershberger */ 685f533aebSJoe Hershberger int gpio_direction_input(unsigned gpio); 699d2cb8e8SSimon Glass 709d2cb8e8SSimon Glass /** 719d2cb8e8SSimon Glass * Make a GPIO an output, and set its value. 729d2cb8e8SSimon Glass * 735f533aebSJoe Hershberger * @param gpio GPIO number 749d2cb8e8SSimon Glass * @param value GPIO value (0 for low or 1 for high) 759d2cb8e8SSimon Glass * @return 0 if ok, -1 on error 769d2cb8e8SSimon Glass */ 775f533aebSJoe Hershberger int gpio_direction_output(unsigned gpio, int value); 789d2cb8e8SSimon Glass 799d2cb8e8SSimon Glass /** 809d2cb8e8SSimon Glass * Get a GPIO's value. This will work whether the GPIO is an input 819d2cb8e8SSimon Glass * or an output. 829d2cb8e8SSimon Glass * 835f533aebSJoe Hershberger * @param gpio GPIO number 849d2cb8e8SSimon Glass * @return 0 if low, 1 if high, -1 on error 859d2cb8e8SSimon Glass */ 865f533aebSJoe Hershberger int gpio_get_value(unsigned gpio); 879d2cb8e8SSimon Glass 889d2cb8e8SSimon Glass /** 895f533aebSJoe Hershberger * Set an output GPIO's value. The GPIO must already be an output or 909d2cb8e8SSimon Glass * this function may have no effect. 919d2cb8e8SSimon Glass * 925f533aebSJoe Hershberger * @param gpio GPIO number 939d2cb8e8SSimon Glass * @param value GPIO value (0 for low or 1 for high) 949d2cb8e8SSimon Glass * @return 0 if ok, -1 on error 959d2cb8e8SSimon Glass */ 965f533aebSJoe Hershberger int gpio_set_value(unsigned gpio, int value); 975f533aebSJoe Hershberger #endif /* _ASM_GENERIC_GPIO_H_ */ 98