imx_generic.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * arch/arm/mach-imx/generic.c
  3. *
  4. * author: Sascha Hauer
  5. * Created: april 20th, 2004
  6. * Copyright: Synertronixx GmbH
  7. *
  8. * Common code for i.MX machines
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. *
  24. */
  25. #include <common.h>
  26. #ifdef CONFIG_IMX
  27. #include <asm/arch/imx-regs.h>
  28. void imx_gpio_mode(int gpio_mode)
  29. {
  30. unsigned int pin = gpio_mode & GPIO_PIN_MASK;
  31. unsigned int port = (gpio_mode & GPIO_PORT_MASK) >> 5;
  32. unsigned int ocr = (gpio_mode & GPIO_OCR_MASK) >> 10;
  33. unsigned int tmp;
  34. /* Pullup enable */
  35. if(gpio_mode & GPIO_PUEN)
  36. PUEN(port) |= (1<<pin);
  37. else
  38. PUEN(port) &= ~(1<<pin);
  39. /* Data direction */
  40. if(gpio_mode & GPIO_OUT)
  41. DDIR(port) |= 1<<pin;
  42. else
  43. DDIR(port) &= ~(1<<pin);
  44. /* Primary / alternate function */
  45. if(gpio_mode & GPIO_AF)
  46. GPR(port) |= (1<<pin);
  47. else
  48. GPR(port) &= ~(1<<pin);
  49. /* use as gpio? */
  50. if( ocr == 3 )
  51. GIUS(port) |= (1<<pin);
  52. else
  53. GIUS(port) &= ~(1<<pin);
  54. /* Output / input configuration */
  55. /* FIXME: I'm not very sure about OCR and ICONF, someone
  56. * should have a look over it
  57. */
  58. if(pin<16) {
  59. tmp = OCR1(port);
  60. tmp &= ~( 3<<(pin*2));
  61. tmp |= (ocr << (pin*2));
  62. OCR1(port) = tmp;
  63. if( gpio_mode & GPIO_AOUT )
  64. ICONFA1(port) &= ~( 3<<(pin*2));
  65. if( gpio_mode & GPIO_BOUT )
  66. ICONFB1(port) &= ~( 3<<(pin*2));
  67. } else {
  68. tmp = OCR2(port);
  69. tmp &= ~( 3<<((pin-16)*2));
  70. tmp |= (ocr << ((pin-16)*2));
  71. OCR2(port) = tmp;
  72. if( gpio_mode & GPIO_AOUT )
  73. ICONFA2(port) &= ~( 3<<((pin-16)*2));
  74. if( gpio_mode & GPIO_BOUT )
  75. ICONFB2(port) &= ~( 3<<((pin-16)*2));
  76. }
  77. }
  78. #endif /* CONFIG_IMX */