sam7eth.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Copyright 2011 by Thermotemp 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/enet_sam7x.c
  36. * \brief eNet-sam7X board initialization.
  37. *
  38. * \verbatim
  39. * $Id$
  40. * \endverbatim
  41. */
  42. #include <toolchain.h>
  43. #include <inttypes.h>
  44. #define PHY_STRAP_AD0 _BV(PB7_ERXER_A)
  45. #define PHY_STRAP_MODE0 _BV(PB5_ERX0_A) //RXD0
  46. #define PHY_STRAP_MODE1 _BV(PB6_ERX1_A) //RXD1
  47. #define PHY_STRAP_MODE2 _BV(PB15_ERXDV_ECRSDV_A) //CRS
  48. //#define PHY_STRAP_REGOFF (LED1)
  49. //#define PHY_STRAP_INTSEL (LED2)
  50. #define PHY_RESET _BV(4)
  51. #define PHY_STRAP (PHY_STRAP_AD0 | PHY_STRAP_MODE0 | PHY_STRAP_MODE1 | PHY_STRAP_MODE2)
  52. /*!
  53. * \brief Delay loop.
  54. *
  55. * \param Number of loops to execute.
  56. */
  57. static void Sam7EthDelay(int n)
  58. {
  59. int l;
  60. for (l = 0; l < n; l++) {
  61. _NOP();
  62. }
  63. }
  64. /*!
  65. * \brief Enable peripheral clocks.
  66. */
  67. static void Sam7EthClockInit(void)
  68. {
  69. outr(PMC_PCER, _BV(PIOA_ID));
  70. outr(PMC_PCER, _BV(PIOB_ID));
  71. outr(PMC_PCER, _BV(EMAC_ID));
  72. }
  73. /*!
  74. * \brief Toggle external hardware reset line.
  75. */
  76. static void Sam7EthReset(void)
  77. {
  78. /* Invoke external reset. */
  79. outr(PIOB_PER, PHY_RESET);
  80. outr(PIOB_OER, PHY_RESET);
  81. outr(PIOB_CODR, PHY_RESET);
  82. Sam7EthDelay(250);
  83. outr(PIOB_SODR, PHY_RESET);
  84. Sam7EthDelay(25000);
  85. }
  86. /*!
  87. * \brief Initialize the PHY hardware.
  88. *
  89. * On startup all GPIO pull-ups on the SAM7X are enabled by default
  90. * and may fight against internal pull-downs of the LAN8710. Here
  91. * we switch off all pull-ups connected to LAN8710 strap pins and
  92. * issue an external reset.
  93. */
  94. static void Sam7EthPhyInit(void)
  95. {
  96. #if 1
  97. /* Allow the PHY to power up (25ms) */
  98. Sam7EthDelay(250000);
  99. /* Disable pull-ups. */
  100. outr(PIOB_PUDR, PHY_STRAP);
  101. outr(PIOB_ODR, PHY_STRAP);
  102. outr(PIOB_PER, PHY_STRAP);
  103. #endif
  104. /* Toggle reset line. */
  105. Sam7EthReset();
  106. #if 1
  107. /* Re-enable the pull-ups. */
  108. outr(PIOB_PUER, PHY_STRAP);
  109. #endif
  110. }
  111. /*!
  112. * \brief Early eNet-sam7X hardware initialization.
  113. *
  114. * This routine is called during system initalization.
  115. */
  116. void NutBoardInit(void)
  117. {
  118. Sam7EthClockInit();
  119. Sam7EthPhyInit();
  120. }