1
0

mdio.h 4.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (c) 2006-2024 RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2024-10-08 zhujiale the first version
  9. */
  10. #ifndef __PHY_MDIO_H__
  11. #define __PHY_MDIO_H__
  12. #include <rtthread.h>
  13. #include <rtdevice.h>
  14. #define RT_MDIO_DEVAD_NONE (-1)
  15. #define RT_MDIO_MMD_PMAPMD 1 /* Physical Medium Attachment/
  16. * Physical Medium Dependent */
  17. #define RT_MDIO_MMD_WIS 2 /* WAN Interface Sublayer */
  18. #define RT_MDIO_MMD_PCS 3 /* Physical Coding Sublayer */
  19. #define RT_MDIO_MMD_PHYXS 4 /* PHY Extender Sublayer */
  20. #define RT_MDIO_MMD_DTEXS 5 /* DTE Extender Sublayer */
  21. #define RT_MDIO_MMD_TC 6 /* Transmission Convergence */
  22. #define RT_MDIO_MMD_AN 7 /* Auto-Negotiation */
  23. #define RT_MDIO_MMD_C22EXT 29 /* Clause 22 extension */
  24. #define RT_MDIO_MMD_VEND1 30 /* Vendor specific 1 */
  25. #define RT_MDIO_MMD_VEND2 31 /* Vendor specific 2 */
  26. #define RT_MII_BMCR 0x00 /* Basic mode control register */
  27. #define RT_MII_BMSR 0x01 /* Basic mode status register */
  28. #define RT_MII_PHYSID1 0x02 /* PHYS ID 1 */
  29. #define RT_MII_PHYSID2 0x03 /* PHYS ID 2 */
  30. #define RT_MII_ADVERTISE 0x04 /* Advertisement control reg */
  31. #define RT_MII_LPA 0x05 /* Link partner ability reg */
  32. #define RT_MII_EXPANSION 0x06 /* Expansion register */
  33. #define RT_MII_CTRL1000 0x09 /* 1000BASE-T control */
  34. #define RT_MII_STAT1000 0x0a /* 1000BASE-T status */
  35. #define RT_MII_MMD_CTRL 0x0d /* MMD Access Control Register */
  36. #define RT_MII_MMD_DATA 0x0e /* MMD Access Data Register */
  37. #define RT_MII_ESTATUS 0x0f /* Extended Status */
  38. #define RT_MII_DCOUNTER 0x12 /* Disconnect counter */
  39. #define RT_MII_FCSCOUNTER 0x13 /* False carrier counter */
  40. #define RT_MII_NWAYTEST 0x14 /* N-way auto-neg test reg */
  41. #define RT_MII_RERRCOUNTER 0x15 /* Receive error counter */
  42. #define RT_MII_SREVISION 0x16 /* Silicon revision */
  43. #define RT_MII_RESV1 0x17 /* Reserved... */
  44. #define RT_MII_LBRERROR 0x18 /* Lpback, rx, bypass error */
  45. #define RT_MII_PHYADDR 0x19 /* PHY address */
  46. #define RT_MII_RESV2 0x1a /* Reserved... */
  47. #define RT_MII_TPISTATUS 0x1b /* TPI status for 10mbps */
  48. #define RT_MII_NCONFIG 0x1c /* Network interface config */
  49. /* Basic mode control register. */
  50. #define RT_BMCR_RESV 0x003f /* Unused... */
  51. #define RT_BMCR_SPEED1000 0x0040 /* MSB of Speed (1000) */
  52. #define RT_BMCR_CTST 0x0080 /* Collision test */
  53. #define RT_BMCR_FULLDPLX 0x0100 /* Full duplex */
  54. #define RT_BMCR_ANRESTART 0x0200 /* Auto negotiation restart */
  55. #define RT_BMCR_ISOLATE 0x0400 /* Isolate data paths from MII */
  56. #define RT_BMCR_PDOWN 0x0800 /* Enable low power state */
  57. #define RT_BMCR_ANENABLE 0x1000 /* Enable auto negotiation */
  58. #define RT_BMCR_SPEED100 0x2000 /* Select 100Mbps */
  59. #define RT_BMCR_LOOPBACK 0x4000 /* TXD loopback bits */
  60. #define RT_BMCR_RESET 0x8000 /* Reset to default state */
  61. #define RT_BMCR_SPEED10 0x0000 /* Select 10Mbps */
  62. #define RT_MII_MMD_CTRL_DEVAD_MASK 0x1f /* Mask MMD DEVAD*/
  63. #define RT_MII_MMD_CTRL_ADDR 0x0000 /* Address */
  64. #define RT_MII_MMD_CTRL_NOINCR 0x4000 /* no post increment */
  65. #define RT_MII_MMD_CTRL_INCR_RDWT 0x8000 /* post increment on reads & writes */
  66. #define RT_MII_MMD_CTRL_INCR_ON_WT 0xC000 /* post increment on writes only */
  67. #define RT_PHY_MAX 32
  68. struct mii_bus
  69. {
  70. struct rt_list_node node;
  71. char name[RT_NAME_MAX];
  72. void* priv;
  73. int (*read)(struct mii_bus* bus, int addr, int devad, int reg);
  74. int (*write)(struct mii_bus* bus, int addr, int devad, int reg, rt_uint16_t val);
  75. /** @read_c45: Perform a C45 read transfer on the bus */
  76. int (*read_c45)(struct mii_bus* bus, int addr, int devad, int reg);
  77. /** @write_c45: Perform a C45 write transfer on the bus */
  78. int (*write_c45)(struct mii_bus* bus, int addr, int devad, int reg, rt_uint16_t val);
  79. int (*reset)(struct mii_bus* bus);
  80. struct rt_phy_device* phymap[RT_PHY_MAX];
  81. rt_uint32_t phy_mask;
  82. int reset_delay_us;
  83. int reset_post_delay_us;
  84. };
  85. rt_err_t rt_mdio_register(struct mii_bus* bus);
  86. rt_err_t rt_mdio_unregister(struct mii_bus* bus);
  87. struct mii_bus* rt_mdio_get_bus_by_name(const char* busname);
  88. struct mii_bus* rt_mdio_alloc(void);
  89. #endif