mvgpio.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * (C) Copyright 2011
  3. * eInfochips Ltd. <www.einfochips.com>
  4. * Written-by: Ajay Bhargav <ajay.bhargav@einfochips.com>
  5. *
  6. * (C) Copyright 2010
  7. * Marvell Semiconductor <www.marvell.com>
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25. * MA 02110-1301 USA
  26. */
  27. #include <common.h>
  28. #include <asm/io.h>
  29. #include <asm/errno.h>
  30. #include "mvgpio.h"
  31. #include <asm/gpio.h>
  32. #ifndef MV_MAX_GPIO
  33. #define MV_MAX_GPIO 128
  34. #endif
  35. int gpio_request(unsigned gpio, const char *label)
  36. {
  37. if (gpio >= MV_MAX_GPIO) {
  38. printf("%s: Invalid GPIO requested %d\n", __func__, gpio);
  39. return -1;
  40. }
  41. return 0;
  42. }
  43. int gpio_free(unsigned gpio)
  44. {
  45. return 0;
  46. }
  47. int gpio_direction_input(unsigned gpio)
  48. {
  49. struct gpio_reg *gpio_reg_bank;
  50. if (gpio >= MV_MAX_GPIO) {
  51. printf("%s: Invalid GPIO %d\n", __func__, gpio);
  52. return -1;
  53. }
  54. gpio_reg_bank = get_gpio_base(GPIO_TO_REG(gpio));
  55. writel(GPIO_TO_BIT(gpio), &gpio_reg_bank->gcdr);
  56. return 0;
  57. }
  58. int gpio_direction_output(unsigned gpio, int value)
  59. {
  60. struct gpio_reg *gpio_reg_bank;
  61. if (gpio >= MV_MAX_GPIO) {
  62. printf("%s: Invalid GPIO %d\n", __func__, gpio);
  63. return -1;
  64. }
  65. gpio_reg_bank = get_gpio_base(GPIO_TO_REG(gpio));
  66. writel(GPIO_TO_BIT(gpio), &gpio_reg_bank->gsdr);
  67. gpio_set_value(gpio, value);
  68. return 0;
  69. }
  70. int gpio_get_value(unsigned gpio)
  71. {
  72. struct gpio_reg *gpio_reg_bank;
  73. u32 gpio_val;
  74. if (gpio >= MV_MAX_GPIO) {
  75. printf("%s: Invalid GPIO %d\n", __func__, gpio);
  76. return -1;
  77. }
  78. gpio_reg_bank = get_gpio_base(GPIO_TO_REG(gpio));
  79. gpio_val = readl(&gpio_reg_bank->gplr);
  80. return GPIO_VAL(gpio, gpio_val);
  81. }
  82. int gpio_set_value(unsigned gpio, int value)
  83. {
  84. struct gpio_reg *gpio_reg_bank;
  85. if (gpio >= MV_MAX_GPIO) {
  86. printf("%s: Invalid GPIO %d\n", __func__, gpio);
  87. return -1;
  88. }
  89. gpio_reg_bank = get_gpio_base(GPIO_TO_REG(gpio));
  90. if (value)
  91. writel(GPIO_TO_BIT(gpio), &gpio_reg_bank->gpsr);
  92. else
  93. writel(GPIO_TO_BIT(gpio), &gpio_reg_bank->gpcr);
  94. return 0;
  95. }