mx31_gpio.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (C) 2009
  3. * Guennadi Liakhovetski, DENX Software Engineering, <lg@denx.de>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <asm/arch/mx31.h>
  25. #include <asm/arch/mx31-regs.h>
  26. /* GPIO port description */
  27. static unsigned long gpio_ports[] = {
  28. [0] = GPIO1_BASE,
  29. [1] = GPIO2_BASE,
  30. [2] = GPIO3_BASE,
  31. };
  32. int mx31_gpio_direction(unsigned int gpio, enum mx31_gpio_direction direction)
  33. {
  34. unsigned int port = gpio >> 5;
  35. u32 l;
  36. if (port >= ARRAY_SIZE(gpio_ports))
  37. return 1;
  38. gpio &= 0x1f;
  39. l = __REG(gpio_ports[port] + GPIO_GDIR);
  40. switch (direction) {
  41. case MX31_GPIO_DIRECTION_OUT:
  42. l |= 1 << gpio;
  43. break;
  44. case MX31_GPIO_DIRECTION_IN:
  45. l &= ~(1 << gpio);
  46. }
  47. __REG(gpio_ports[port] + GPIO_GDIR) = l;
  48. return 0;
  49. }
  50. void mx31_gpio_set(unsigned int gpio, unsigned int value)
  51. {
  52. unsigned int port = gpio >> 5;
  53. u32 l;
  54. if (port >= ARRAY_SIZE(gpio_ports))
  55. return;
  56. gpio &= 0x1f;
  57. l = __REG(gpio_ports[port] + GPIO_DR);
  58. if (value)
  59. l |= 1 << gpio;
  60. else
  61. l &= ~(1 << gpio);
  62. __REG(gpio_ports[port] + GPIO_DR) = l;
  63. }