at91sam9261_devices.c 3.6 KB

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