drv_emac.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2022-05-16 shelton first version
  9. * 2024-09-02 shelton add support phy lan8720 and yt8512
  10. */
  11. #ifndef __DRV_EMAC_H__
  12. #define __DRV_EMAC_H__
  13. #include <rtthread.h>
  14. #include <rthw.h>
  15. #include <rtdevice.h>
  16. #include "drv_common.h"
  17. #define CRYSTAL_ON_PHY 0 /* phy does not with crystal */
  18. /* the phy basic control register */
  19. #define PHY_BASIC_CONTROL_REG 0x00U
  20. #define PHY_RESET_MASK (1<<15)
  21. #define PHY_AUTO_NEGOTIATION_MASK (1<<12)
  22. /* the phy basic status register */
  23. #define PHY_BASIC_STATUS_REG 0x01U
  24. #define PHY_LINKED_STATUS_MASK (1<<2)
  25. #define PHY_AUTONEGO_COMPLETE_MASK (1<<5)
  26. /* the phy id one register */
  27. #define PHY_ID1_REG 0x02U
  28. /* the phy id two register */
  29. #define PHY_ID2_REG 0x03U
  30. /* the phy auto-negotiate advertise register */
  31. #define PHY_AUTONEG_ADVERTISE_REG 0x04U
  32. #if defined (PHY_USING_DM9162)
  33. #define PHY_CONTROL_REG (0x00) /*!< basic mode control register */
  34. #define PHY_STATUS_REG (0x01) /*!< basic mode status register */
  35. #define PHY_SPECIFIED_CS_REG (0x11) /*!< specified configuration and status register */
  36. /* phy control register */
  37. #define PHY_AUTO_NEGOTIATION_BIT (0x1000) /*!< enable auto negotiation */
  38. #define PHY_LOOPBACK_BIT (0x4000) /*!< enable loopback */
  39. #define PHY_RESET_BIT (0x8000) /*!< reset phy */
  40. /* phy status register */
  41. #define PHY_LINKED_STATUS_BIT (0x0004) /*!< link status */
  42. #define PHY_NEGO_COMPLETE_BIT (0x0020) /*!< auto negotiation complete */
  43. /* phy specified control/status register */
  44. #define PHY_FULL_DUPLEX_100MBPS_BIT (0x8000) /*!< full duplex 100 mbps */
  45. #define PHY_HALF_DUPLEX_100MBPS_BIT (0x4000) /*!< half duplex 100 mbps */
  46. #define PHY_FULL_DUPLEX_10MBPS_BIT (0x2000) /*!< full duplex 10 mbps */
  47. #define PHY_HALF_DUPLEX_10MBPS_BIT (0x1000) /*!< half duplex 10 mbps */
  48. #define PHY_DUPLEX_MODE (PHY_FULL_DUPLEX_100MBPS_BIT | PHY_FULL_DUPLEX_10MBPS_BIT) /*!< full duplex mode */
  49. #define PHY_SPEED_MODE (PHY_FULL_DUPLEX_10MBPS_BIT | PHY_HALF_DUPLEX_10MBPS_BIT) /*!< 10 mbps */
  50. /* the phy interrupt source flag register. */
  51. #define PHY_INTERRUPT_FLAG_REG 0x15U
  52. /* the phy interrupt mask register. */
  53. #define PHY_INTERRUPT_MASK_REG 0x15U
  54. #define PHY_INT_MASK 0
  55. #elif defined (PHY_USING_DP83848)
  56. #define PHY_CONTROL_REG (0x00) /*!< basic mode control register */
  57. #define PHY_STATUS_REG (0x01) /*!< basic mode status register */
  58. #define PHY_SPECIFIED_CS_REG (0x10) /*!< phy status register */
  59. /* phy control register */
  60. #define PHY_AUTO_NEGOTIATION_BIT (0x1000) /*!< enable auto negotiation */
  61. #define PHY_LOOPBACK_BIT (0x4000) /*!< enable loopback */
  62. #define PHY_RESET_BIT (0x8000) /*!< reset phy */
  63. /* phy status register */
  64. #define PHY_LINKED_STATUS_BIT (0x0004) /*!< link status */
  65. #define PHY_NEGO_COMPLETE_BIT (0x0020) /*!< auto negotiation complete */
  66. #define PHY_DUPLEX_MODE (0x0004) /*!< full duplex mode */
  67. #define PHY_SPEED_MODE (0x0002) /*!< 10 mbps */
  68. /* the phy interrupt source flag register. */
  69. #define PHY_INTERRUPT_FLAG_REG 0x12U
  70. #define PHY_LINK_CHANGE_FLAG (1<<13)
  71. /* the phy interrupt control register. */
  72. #define PHY_INTERRUPT_CTRL_REG 0x11U
  73. #define PHY_INTERRUPT_EN ((1<<0)|(1<<1))
  74. /* the phy interrupt mask register. */
  75. #define PHY_INTERRUPT_MASK_REG 0x12U
  76. #define PHY_INT_MASK (1<<5)
  77. #elif defined (PHY_USING_LAN8720)
  78. #define PHY_CONTROL_REG (0x00) /*!< basic mode control register */
  79. #define PHY_STATUS_REG (0x01) /*!< basic mode status register */
  80. #define PHY_SPECIFIED_CS_REG (0x1F) /*!< specified configuration and status register */
  81. /* phy control register */
  82. #define PHY_AUTO_NEGOTIATION_BIT (0x1000) /*!< enable auto negotiation */
  83. #define PHY_LOOPBACK_BIT (0x4000) /*!< enable loopback */
  84. #define PHY_RESET_BIT (0x8000) /*!< reset phy */
  85. /* phy status register */
  86. #define PHY_LINKED_STATUS_BIT (0x0004) /*!< link status */
  87. #define PHY_NEGO_COMPLETE_BIT (0x0020) /*!< auto negotiation complete */
  88. /* phy specified control/status register */
  89. #define PHY_FULL_DUPLEX_100MBPS_BIT (0x0018) /*!< full duplex 100 mbps */
  90. #define PHY_HALF_DUPLEX_100MBPS_BIT (0x0008) /*!< half duplex 100 mbps */
  91. #define PHY_FULL_DUPLEX_10MBPS_BIT (0x0014) /*!< full duplex 10 mbps */
  92. #define PHY_HALF_DUPLEX_10MBPS_BIT (0x0004) /*!< half duplex 10 mbps */
  93. #define PHY_DUPLEX_MODE (0x0100) /*!< full duplex mode */
  94. #define PHY_SPEED_MODE (0x2000) /*!< 100 mbps */
  95. /* the phy interrupt source flag register. */
  96. #define PHY_INTERRUPT_FLAG_REG 0x1DU
  97. /* the phy interrupt mask register. */
  98. #define PHY_INTERRUPT_MASK_REG 0x1EU
  99. #define PHY_INT_MASK (1<<4)
  100. #elif defined (PHY_USING_YT8512)
  101. #define PHY_CONTROL_REG (0x00) /*!< basic mode control register */
  102. #define PHY_STATUS_REG (0x01) /*!< basic mode status register */
  103. #define PHY_SPECIFIED_CS_REG (0x11) /*!< phy status register */
  104. /* phy control register */
  105. #define PHY_AUTO_NEGOTIATION_BIT (0x1000) /*!< enable auto negotiation */
  106. #define PHY_LOOPBACK_BIT (0x4000) /*!< enable loopback */
  107. #define PHY_RESET_BIT (0x8000) /*!< reset phy */
  108. /* phy status register */
  109. #define PHY_LINKED_STATUS_BIT (0x0004) /*!< link status */
  110. #define PHY_NEGO_COMPLETE_BIT (0x0020) /*!< auto negotiation complete */
  111. #define PHY_DUPLEX_MODE (0x2000) /*!< full duplex mode */
  112. #define PHY_SPEED_MODE (0x4000) /*!< 100 mbps */
  113. /* the phy interrupt source flag register. */
  114. #define PHY_INTERRUPT_FLAG_REG 0x13U
  115. #define PHY_LINK_CHANGE_FLAG (3<<10)
  116. /* the phy interrupt mask register. */
  117. #define PHY_INTERRUPT_MASK_REG 0x12U
  118. #define PHY_INT_MASK (3<<10)
  119. #endif
  120. #endif /* __DRV_EMAC_H__ */