eth_phy_port.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (c) 2021 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef ETH_PHY_PORT_H
  8. #define ETH_PHY_PORT_H
  9. #include "hpm_ioc_regs.h"
  10. #include <rtdevice.h>
  11. #ifndef PHY_AUTO_NEGO
  12. #define PHY_AUTO_NEGO (1U)
  13. #endif
  14. #ifndef PHY_MDIO_CSR_CLK_FREQ
  15. #define PHY_MDIO_CSR_CLK_FREQ (200000000U)
  16. #endif
  17. enum phy_link_status
  18. {
  19. PHY_LINK_DOWN = 0U,
  20. PHY_LINK_UP
  21. };
  22. typedef struct {
  23. rt_uint32_t phy_speed;
  24. rt_uint32_t phy_duplex;
  25. } phy_info_t;
  26. typedef struct {
  27. rt_uint32_t phy_link;
  28. rt_phy_t phy;
  29. phy_info_t phy_info;
  30. } phy_device_t;
  31. /** @note PHY: LAN8720A */
  32. #define PHY_NAME ("LAN8720A")
  33. #define PHY_ID1 (7U)
  34. /* The PHY basic control register */
  35. #define PHY_BASIC_CONTROL_REG (0x00U)
  36. #define PHY_RESET_MASK (1U << 15)
  37. #define PHY_AUTO_NEGOTIATION_MASK (1U << 12)
  38. /* The PHY basic status register */
  39. #define PHY_BASIC_STATUS_REG (0x01U)
  40. #define PHY_LINKED_STATUS_MASK (1U << 2)
  41. #define PHY_AUTONEGO_COMPLETE_MASK (1U << 5)
  42. /* The PHY ID one register */
  43. #define PHY_ID1_REG (0x02U)
  44. /* The PHY ID two register */
  45. #define PHY_ID2_REG (0x03U)
  46. /* The PHY auto-negotiate advertise register */
  47. #define PHY_AUTONEG_ADVERTISE_REG (0x04U)
  48. /* The PHY SPECIAL MODES REGISTER */
  49. #define PHY_SPECIAL_MODES_REG (0x12U)
  50. /* The PHY interrupt source flag register. */
  51. #define PHY_INTERRUPT_FLAG_REG (0x1dU)
  52. /* The PHY interrupt mask register. */
  53. #define PHY_INTERRUPT_MASK_REG (0x1eU)
  54. #define PHY_LINK_DOWN_MASK (1 << 4)
  55. #define PHY_AUTO_NEGO_COMPLETE_MASK (1 << 6)
  56. /* The PHY status register. */
  57. #define PHY_STATUS_REG (0x1fU)
  58. #define PHY_10M_MASK (1 << 2)
  59. #define PHY_100M_MASK (1 << 3)
  60. #define PHY_FULL_DUPLEX_MASK (1 << 4)
  61. #define PHY_STATUS_SPEED_10M(SR) ((SR) & PHY_10M_MASK)
  62. #define PHY_STATUS_SPEED_100M(SR) ((SR) & PHY_100M_MASK)
  63. #define PHY_STATUS_FULL_DUPLEX(SR) ((SR) & PHY_FULL_DUPLEX_MASK)
  64. /* PHY0 register list */
  65. #define PHY0_REG_LIST PHY_BASIC_CONTROL_REG,\
  66. PHY_BASIC_STATUS_REG,\
  67. PHY_ID1_REG,\
  68. PHY_ID2_REG,\
  69. PHY_SPECIAL_MODES_REG,\
  70. PHY_INTERRUPT_FLAG_REG,\
  71. PHY_INTERRUPT_MASK_REG,\
  72. PHY_STATUS_REG
  73. /* PHY0 register index */
  74. #define PHY0_BASIC_STATUS_REG_IDX (1U)
  75. #define PHY0_ID1_REG_IDX (2U)
  76. #define PHY0_STATUS_REG_IDX (7U)
  77. /* PHY1 register list */
  78. #define PHY1_REG_LIST PHY_BASIC_CONTROL_REG,\
  79. PHY_BASIC_STATUS_REG,\
  80. PHY_ID1_REG,\
  81. PHY_ID2_REG,\
  82. PHY_SPECIAL_MODES_REG,\
  83. PHY_INTERRUPT_FLAG_REG,\
  84. PHY_INTERRUPT_MASK_REG,\
  85. PHY_STATUS_REG
  86. /* PHY1 register index */
  87. #define PHY_BASIC_STATUS_REG_IDX (1U)
  88. #define PHY_ID1_REG_IDX (2U)
  89. #define PHY_STATUS_REG_IDX (7U)
  90. #endif