at91sam9g45_ek.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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/at91sam9260_ek.c
  36. * \brief AT91SAM9260-EK initialization.
  37. *
  38. * \verbatim
  39. * $Id$
  40. * \endverbatim
  41. */
  42. #include <toolchain.h>
  43. #define PHY_STRAP_AD0 _BV(PA14_ERX0_A)
  44. #define PHY_STRAP_AD1 _BV(PA15_ERX1_A)
  45. #define PHY_STRAP_AD2 _BV(PA25_ERX2_B)
  46. #define PHY_STRAP_AD3 _BV(PA26_ERX3_B)
  47. #define PHY_STRAP_AD4 _BV(PA28_ECRS_B)
  48. #define PHY_STRAP_TESTMODE _BV(PA17_ERXDV_A)
  49. #define PHY_STRAP_RMIISEL _BV(PA29_ECOL_B)
  50. #define PHY_STRAP ( \
  51. PHY_STRAP_AD0 | PHY_STRAP_AD1 | PHY_STRAP_AD2 | PHY_STRAP_AD3 | PHY_STRAP_AD4 | \
  52. PHY_STRAP_TESTMODE | PHY_STRAP_RMIISEL )
  53. /*!
  54. * \brief Delay loop.
  55. *
  56. * \param Number of loops to execute.
  57. */
  58. static void Sam9g45ekDelay(int n)
  59. {
  60. int l;
  61. for (l = 0; l < n; l++) {
  62. _NOP();
  63. }
  64. }
  65. /*!
  66. * \brief Enable peripheral clocks.
  67. */
  68. static void Sam9G45ekClockInit(void)
  69. {
  70. outr(PMC_PCER, _BV(PIOA_ID));
  71. outr(PMC_PCER, _BV(PIOB_ID));
  72. outr(PMC_PCER, _BV(PIOC_ID));
  73. outr(PMC_PCER, _BV(EMAC_ID));
  74. }
  75. /*!
  76. * \brief Toggle external hardware reset line.
  77. */
  78. static void Sam9260ekReset(void)
  79. {
  80. /* Set reset pulse length to 250us, disable user reset. */
  81. outr(RSTC_MR, RSTC_KEY | (2 << RSTC_ERSTL_LSB));
  82. /* Invoke external reset. */
  83. outr(RSTC_CR, RSTC_KEY | RSTC_EXTRST);
  84. Sam9g45ekDelay(250);
  85. /* Wait until reset pin is released. */
  86. while ((inr(RSTC_SR) & RSTC_NRSTL) == 0);
  87. Sam9g45ekDelay(25000);
  88. }
  89. /*!
  90. * \brief Initialize the PHY hardware.
  91. *
  92. * On startup all GPIO pull-ups on the SAM9 are enabled by default
  93. * and may fight against internal pull-downs of the DM9161A. Here
  94. * we switch off all pull-ups connected to PHY strap pins and
  95. * issue an external reset.
  96. */
  97. static void Sam9G45ekPhyInit(void)
  98. {
  99. /* The PHY needs 25ms for powering up. */
  100. Sam9g45ekDelay(250000);
  101. /* Disable pull-ups. */
  102. #if 0
  103. outr(PIOA_PUDR, PHY_STRAP);
  104. outr(PIOA_ODR, PHY_STRAP);
  105. outr(PIOA_PER, PHY_STRAP);
  106. #endif
  107. /* Toggle reset line. */
  108. Sam9260ekReset();
  109. /* Re-enable the pull-ups. */
  110. // outr(PIOA_PUER, PHY_STRAP);
  111. }
  112. /*!
  113. * \brief Early AT91SAM9260-EK hardware initialization.
  114. *
  115. * This routine is called during system initalization.
  116. */
  117. void NutBoardInit(void)
  118. {
  119. Sam9G45ekClockInit();
  120. return;
  121. Sam9G45ekPhyInit();
  122. }