at91sam9261_devices.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2007-2008
  4. * Stelian Pop <stelian@popies.net>
  5. * Lead Tech Design <www.leadtechdesign.com>
  6. */
  7. #include <common.h>
  8. #include <asm/io.h>
  9. #include <asm/arch/at91_common.h>
  10. #include <asm/arch/clk.h>
  11. #include <asm/arch/gpio.h>
  12. /*
  13. * if CONFIG_AT91_GPIO_PULLUP ist set, keep pullups on on all
  14. * peripheral pins. Good to have if hardware is soldered optionally
  15. * or in case of SPI no slave is selected. Avoid lines to float
  16. * needlessly. Use a short local PUP define.
  17. *
  18. * Due to errata "TXD floats when CTS is inactive" pullups are always
  19. * on for TXD pins.
  20. */
  21. #ifdef CONFIG_AT91_GPIO_PULLUP
  22. # define PUP CONFIG_AT91_GPIO_PULLUP
  23. #else
  24. # define PUP 0
  25. #endif
  26. void at91_serial0_hw_init(void)
  27. {
  28. at91_set_a_periph(AT91_PIO_PORTC, 8, 1); /* TXD0 */
  29. at91_set_a_periph(AT91_PIO_PORTC, 9, 0); /* RXD0 */
  30. at91_periph_clk_enable(ATMEL_ID_USART0);
  31. }
  32. void at91_serial1_hw_init(void)
  33. {
  34. at91_set_a_periph(AT91_PIO_PORTC, 12, 1); /* TXD1 */
  35. at91_set_a_periph(AT91_PIO_PORTC, 13, 0); /* RXD1 */
  36. at91_periph_clk_enable(ATMEL_ID_USART1);
  37. }
  38. void at91_serial2_hw_init(void)
  39. {
  40. at91_set_a_periph(AT91_PIO_PORTC, 14, 1); /* TXD2 */
  41. at91_set_a_periph(AT91_PIO_PORTC, 15, 0); /* RXD2 */
  42. at91_periph_clk_enable(ATMEL_ID_USART2);
  43. }
  44. void at91_seriald_hw_init(void)
  45. {
  46. at91_set_a_periph(AT91_PIO_PORTA, 9, 0); /* DRXD */
  47. at91_set_a_periph(AT91_PIO_PORTA, 10, 1); /* DTXD */
  48. at91_periph_clk_enable(ATMEL_ID_SYS);
  49. }
  50. #ifdef CONFIG_ATMEL_SPI
  51. void at91_spi0_hw_init(unsigned long cs_mask)
  52. {
  53. at91_set_a_periph(AT91_PIO_PORTA, 0, PUP); /* SPI0_MISO */
  54. at91_set_a_periph(AT91_PIO_PORTA, 1, PUP); /* SPI0_MOSI */
  55. at91_set_a_periph(AT91_PIO_PORTA, 2, PUP); /* SPI0_SPCK */
  56. at91_periph_clk_enable(ATMEL_ID_SPI0);
  57. if (cs_mask & (1 << 0)) {
  58. at91_set_a_periph(AT91_PIO_PORTA, 3, 1);
  59. }
  60. if (cs_mask & (1 << 1)) {
  61. at91_set_a_periph(AT91_PIO_PORTA, 4, 1);
  62. }
  63. if (cs_mask & (1 << 2)) {
  64. at91_set_a_periph(AT91_PIO_PORTA, 5, 1);
  65. }
  66. if (cs_mask & (1 << 3)) {
  67. at91_set_a_periph(AT91_PIO_PORTA, 6, 1);
  68. }
  69. if (cs_mask & (1 << 4)) {
  70. at91_set_pio_output(AT91_PIO_PORTA, 3, 1);
  71. }
  72. if (cs_mask & (1 << 5)) {
  73. at91_set_pio_output(AT91_PIO_PORTA, 4, 1);
  74. }
  75. if (cs_mask & (1 << 6)) {
  76. at91_set_pio_output(AT91_PIO_PORTA, 5, 1);
  77. }
  78. if (cs_mask & (1 << 7)) {
  79. at91_set_pio_output(AT91_PIO_PORTA, 6, 1);
  80. }
  81. }
  82. void at91_spi1_hw_init(unsigned long cs_mask)
  83. {
  84. at91_set_a_periph(AT91_PIO_PORTB, 30, PUP); /* SPI1_MISO */
  85. at91_set_a_periph(AT91_PIO_PORTB, 31, PUP); /* SPI1_MOSI */
  86. at91_set_a_periph(AT91_PIO_PORTB, 29, PUP); /* SPI1_SPCK */
  87. at91_periph_clk_enable(ATMEL_ID_SPI1);
  88. if (cs_mask & (1 << 0)) {
  89. at91_set_a_periph(AT91_PIO_PORTB, 28, 1);
  90. }
  91. if (cs_mask & (1 << 1)) {
  92. at91_set_b_periph(AT91_PIO_PORTA, 24, 1);
  93. }
  94. if (cs_mask & (1 << 2)) {
  95. at91_set_b_periph(AT91_PIO_PORTA, 25, 1);
  96. }
  97. if (cs_mask & (1 << 3)) {
  98. at91_set_a_periph(AT91_PIO_PORTA, 26, 1);
  99. }
  100. if (cs_mask & (1 << 4)) {
  101. at91_set_pio_output(AT91_PIO_PORTB, 28, 1);
  102. }
  103. if (cs_mask & (1 << 5)) {
  104. at91_set_pio_output(AT91_PIO_PORTA, 24, 1);
  105. }
  106. if (cs_mask & (1 << 6)) {
  107. at91_set_pio_output(AT91_PIO_PORTA, 25, 1);
  108. }
  109. if (cs_mask & (1 << 7)) {
  110. at91_set_pio_output(AT91_PIO_PORTA, 26, 1);
  111. }
  112. }
  113. #endif