at91sam7x_ek.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Copyright 2010 by egnite GmbH
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. */
  34. /*
  35. * \file arch/arm/board/at91sam7x_ek.c
  36. * \brief AT91SAM7X-EK board initialization.
  37. *
  38. * \verbatim
  39. * $Id$
  40. * \endverbatim
  41. */
  42. #include <toolchain.h>
  43. #define PHY_STRAP_AD0 _BV(PB5_ERX0_A)
  44. #define PHY_STRAP_AD1 _BV(PB6_ERX1_A)
  45. #define PHY_STRAP_AD2 _BV(PB13_ERX2_A)
  46. #define PHY_STRAP_AD3 _BV(PB14_ERX3_A)
  47. #define PHY_STRAP_AD4 _BV(PB4_ECRS_A)
  48. #define PHY_STRAP_ISOLATE _BV(PB0_ETXCK_EREFCK_A)
  49. #define PHY_STRAP_10BTSER _BV(PB17_ERXCK_A)
  50. #define PHY_STRAP_RPTR _BV(PB7_ERXER_A)
  51. #define PHY_STRAP_RMII _BV(PB16_ECOL_A)
  52. #define PHY_STRAP_TESTMODE _BV(PB15_ERXDV_ECRSDV_A)
  53. #define PHY_PWRDWN _BV(PB18_EF100_A)
  54. #define PHY_STRAP ( \
  55. PHY_STRAP_AD0 | PHY_STRAP_AD1 | PHY_STRAP_AD2 | PHY_STRAP_AD3 | \
  56. PHY_STRAP_AD4 | PHY_STRAP_RMII | PHY_STRAP_TESTMODE )
  57. /*!
  58. * \brief Delay loop.
  59. *
  60. * \param Number of loops to execute.
  61. */
  62. static void Sam7xekDelay(int n)
  63. {
  64. int l;
  65. for (l = 0; l < n; l++) {
  66. _NOP();
  67. }
  68. }
  69. /*!
  70. * \brief Enable peripheral clocks.
  71. */
  72. static void Sam7xekClockInit(void)
  73. {
  74. outr(PMC_PCER, _BV(PIOB_ID));
  75. outr(PMC_PCER, _BV(EMAC_ID));
  76. }
  77. /*!
  78. * \brief Toggle external hardware reset line.
  79. */
  80. static void Sam7xekReset(void)
  81. {
  82. unsigned int mr;
  83. /* Save initial configuration. */
  84. mr = inr(RSTC_MR) & ~RSTC_KEY_MSK;
  85. /* Set reset pulse length to 250us, disable user reset. */
  86. outr(RSTC_MR, RSTC_KEY | (2 << RSTC_ERSTL_LSB));
  87. /* Invoke external reset. */
  88. outr(RSTC_CR, RSTC_KEY | RSTC_EXTRST);
  89. /* If we have 10k/100n RC, we need to wait 25us (1200 cycles)
  90. ** for NRST becoming low. */
  91. Sam7xekDelay(250);
  92. /* Wait until reset pin is released. */
  93. while ((inr(RSTC_SR) & RSTC_NRSTL) == 0);
  94. /* Due to the RC filter, the pin is rising very slowly. */
  95. Sam7xekDelay(25000);
  96. /* Restore initial configuration. */
  97. outr(RSTC_MR, RSTC_KEY | mr);
  98. }
  99. /*!
  100. * \brief Initialize the PHY hardware.
  101. *
  102. * On startup all GPIO pull-ups on the SAM7X are enabled by default
  103. * and may fight against internal pull-downs of the LAN8710. Here
  104. * we switch off all pull-ups connected to LAN8710 strap pins and
  105. * issue an external reset.
  106. */
  107. static void Sam7xekPhyInit(void)
  108. {
  109. /* Power up the PHY. */
  110. outr(PIOB_PER, PHY_PWRDWN);
  111. outr(PIOB_OER, PHY_PWRDWN);
  112. outr(PIOB_CODR, PHY_PWRDWN);
  113. /* The PHY needs 25ms for powering up. */
  114. Sam7xekDelay(250000);
  115. /* Disable strap pin pull-ups. */
  116. outr(PIOB_PUDR, PHY_STRAP);
  117. /* Toggle reset line. */
  118. Sam7xekReset();
  119. /* Re-enable the pull-ups. */
  120. outr(PIOB_PUER, PHY_STRAP);
  121. }
  122. /*!
  123. * \brief Early AT91SAM7X-EK hardware initialization.
  124. *
  125. * This routine is called during system initalization.
  126. */
  127. void NutBoardInit(void)
  128. {
  129. Sam7xekClockInit();
  130. Sam7xekPhyInit();
  131. }