phy.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-10-14 wangqiang the first version
  9. * 2022-08-17 xjy198903 add 1000M definition
  10. */
  11. #ifndef __PHY_H__
  12. #define __PHY_H__
  13. #include <rtthread.h>
  14. #ifdef __cplusplus
  15. extern "C"
  16. {
  17. #endif
  18. /* Defines the PHY link speed. This is align with the speed for MAC. */
  19. #define PHY_SPEED_10M 0U /* PHY 10M speed. */
  20. #define PHY_SPEED_100M 1U /* PHY 100M speed. */
  21. #define PHY_SPEED_1000M 2U /* PHY 1000M speed. */
  22. /* Defines the PHY link duplex. */
  23. #define PHY_HALF_DUPLEX 0U /* PHY half duplex. */
  24. #define PHY_FULL_DUPLEX 1U /* PHY full duplex. */
  25. /*! @brief Defines the PHY loopback mode. */
  26. #define PHY_LOCAL_LOOP 0U /* PHY local loopback. */
  27. #define PHY_REMOTE_LOOP 1U /* PHY remote loopback. */
  28. #define PHY_STATUS_OK 0U
  29. #define PHY_STATUS_FAIL 1U
  30. #define PHY_STATUS_TIMEOUT 2U
  31. typedef struct rt_phy_msg
  32. {
  33. rt_uint32_t reg;
  34. rt_uint32_t value;
  35. }rt_phy_msg_t;
  36. typedef struct rt_phy_device
  37. {
  38. struct rt_device parent;
  39. struct rt_mdio_bus *bus;
  40. rt_uint32_t addr;
  41. struct rt_phy_ops *ops;
  42. }rt_phy_t;
  43. typedef rt_int32_t rt_phy_status;
  44. struct rt_phy_ops
  45. {
  46. rt_phy_status (*init)(void *object, rt_uint32_t phy_addr, rt_uint32_t src_clock_hz);
  47. rt_phy_status (*read)(rt_uint32_t reg, rt_uint32_t *data);
  48. rt_phy_status (*write)(rt_uint32_t reg, rt_uint32_t data);
  49. rt_phy_status (*loopback)(rt_uint32_t mode, rt_uint32_t speed, rt_bool_t enable);
  50. rt_phy_status (*get_link_status)(rt_bool_t *status);
  51. rt_phy_status (*get_link_speed_duplex)(rt_uint32_t *speed, rt_uint32_t *duplex);
  52. };
  53. rt_err_t rt_hw_phy_register(struct rt_phy_device *phy, const char *name);
  54. #ifdef __cplusplus
  55. }
  56. #endif
  57. #endif /* __PHY_H__*/