portmux-gpio.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright (C) 2008 Atmel Corporation
  3. *
  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. #include <common.h>
  23. #include <asm/io.h>
  24. #include <asm/arch/memory-map.h>
  25. #include <asm/arch/gpio.h>
  26. void portmux_select_peripheral(void *port, unsigned long pin_mask,
  27. enum portmux_function func, unsigned long flags)
  28. {
  29. /* Both pull-up and pull-down set means buskeeper */
  30. if (flags & PORTMUX_PULL_DOWN)
  31. gpio_writel(port, PDERS, pin_mask);
  32. else
  33. gpio_writel(port, PDERC, pin_mask);
  34. if (flags & PORTMUX_PULL_UP)
  35. gpio_writel(port, PUERS, pin_mask);
  36. else
  37. gpio_writel(port, PUERC, pin_mask);
  38. /* Select drive strength */
  39. if (flags & PORTMUX_DRIVE_LOW)
  40. gpio_writel(port, ODCR0S, pin_mask);
  41. else
  42. gpio_writel(port, ODCR0C, pin_mask);
  43. if (flags & PORTMUX_DRIVE_HIGH)
  44. gpio_writel(port, ODCR1S, pin_mask);
  45. else
  46. gpio_writel(port, ODCR1C, pin_mask);
  47. /* Select function */
  48. if (func & PORTMUX_FUNC_B)
  49. gpio_writel(port, PMR0S, pin_mask);
  50. else
  51. gpio_writel(port, PMR0C, pin_mask);
  52. if (func & PORTMUX_FUNC_C)
  53. gpio_writel(port, PMR1S, pin_mask);
  54. else
  55. gpio_writel(port, PMR1C, pin_mask);
  56. /* Disable GPIO (i.e. enable peripheral) */
  57. gpio_writel(port, GPERC, pin_mask);
  58. }
  59. void portmux_select_gpio(void *port, unsigned long pin_mask,
  60. unsigned long flags)
  61. {
  62. /* Both pull-up and pull-down set means buskeeper */
  63. if (flags & PORTMUX_PULL_DOWN)
  64. gpio_writel(port, PDERS, pin_mask);
  65. else
  66. gpio_writel(port, PDERC, pin_mask);
  67. if (flags & PORTMUX_PULL_UP)
  68. gpio_writel(port, PUERS, pin_mask);
  69. else
  70. gpio_writel(port, PUERC, pin_mask);
  71. /* Enable open-drain mode if requested */
  72. if (flags & PORTMUX_OPEN_DRAIN)
  73. gpio_writel(port, ODMERS, pin_mask);
  74. else
  75. gpio_writel(port, ODMERC, pin_mask);
  76. /* Select drive strength */
  77. if (flags & PORTMUX_DRIVE_LOW)
  78. gpio_writel(port, ODCR0S, pin_mask);
  79. else
  80. gpio_writel(port, ODCR0C, pin_mask);
  81. if (flags & PORTMUX_DRIVE_HIGH)
  82. gpio_writel(port, ODCR1S, pin_mask);
  83. else
  84. gpio_writel(port, ODCR1C, pin_mask);
  85. /* Select direction and initial pin state */
  86. if (flags & PORTMUX_DIR_OUTPUT) {
  87. if (flags & PORTMUX_INIT_HIGH)
  88. gpio_writel(port, OVRS, pin_mask);
  89. else
  90. gpio_writel(port, OVRC, pin_mask);
  91. gpio_writel(port, ODERS, pin_mask);
  92. } else {
  93. gpio_writel(port, ODERC, pin_mask);
  94. }
  95. /* Enable GPIO */
  96. gpio_writel(port, GPERS, pin_mask);
  97. }