portmux-pio.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright (C) 2006, 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. if (flags & PORTMUX_PULL_UP)
  30. pio_writel(port, PUER, pin_mask);
  31. else
  32. pio_writel(port, PUDR, pin_mask);
  33. switch (func) {
  34. case PORTMUX_FUNC_A:
  35. pio_writel(port, ASR, pin_mask);
  36. break;
  37. case PORTMUX_FUNC_B:
  38. pio_writel(port, BSR, pin_mask);
  39. break;
  40. }
  41. pio_writel(port, PDR, pin_mask);
  42. }
  43. void portmux_select_gpio(void *port, unsigned long pin_mask,
  44. unsigned long flags)
  45. {
  46. if (flags & PORTMUX_PULL_UP)
  47. pio_writel(port, PUER, pin_mask);
  48. else
  49. pio_writel(port, PUDR, pin_mask);
  50. if (flags & PORTMUX_OPEN_DRAIN)
  51. pio_writel(port, MDER, pin_mask);
  52. else
  53. pio_writel(port, MDDR, pin_mask);
  54. if (flags & PORTMUX_DIR_OUTPUT) {
  55. if (flags & PORTMUX_INIT_HIGH)
  56. pio_writel(port, SODR, pin_mask);
  57. else
  58. pio_writel(port, CODR, pin_mask);
  59. pio_writel(port, OER, pin_mask);
  60. } else {
  61. pio_writel(port, ODR, pin_mask);
  62. }
  63. pio_writel(port, PER, pin_mask);
  64. }
  65. void pio_set_output_value(unsigned int pin, int value)
  66. {
  67. void *port = pio_pin_to_port(pin);
  68. if (!port)
  69. panic("Invalid GPIO pin %u\n", pin);
  70. __pio_set_output_value(port, pin & 0x1f, value);
  71. }
  72. int pio_get_input_value(unsigned int pin)
  73. {
  74. void *port = pio_pin_to_port(pin);
  75. if (!port)
  76. panic("Invalid GPIO pin %u\n", pin);
  77. return __pio_get_input_value(port, pin & 0x1f);
  78. }