phy.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. * 2020-10-14 wangqiang the first version
  9. */
  10. #ifndef __PHY_H__
  11. #define __PHY_H__
  12. #include <rtthread.h>
  13. #ifdef __cplusplus
  14. extern "C"
  15. {
  16. #endif
  17. /* Defines the PHY link speed. This is align with the speed for MAC. */
  18. enum phy_speed
  19. {
  20. PHY_SPEED_10M = 0U, /* PHY 10M speed. */
  21. PHY_SPEED_100M /* PHY 100M speed. */
  22. };
  23. /* Defines the PHY link duplex. */
  24. enum phy_duplex
  25. {
  26. PHY_HALF_DUPLEX = 0U, /* PHY half duplex. */
  27. PHY_FULL_DUPLEX /* PHY full duplex. */
  28. };
  29. /*! @brief Defines the PHY loopback mode. */
  30. enum phy_loop
  31. {
  32. PHY_LOCAL_LOOP = 0U, /* PHY local loopback. */
  33. PHY_REMOTE_LOOP /* PHY remote loopback. */
  34. };
  35. struct rt_phy_msg
  36. {
  37. rt_uint32_t reg;
  38. rt_uint32_t value;
  39. };
  40. typedef struct rt_phy_msg rt_phy_msg_t;
  41. struct rt_phy_device
  42. {
  43. struct rt_device parent;
  44. struct rt_mdio_bus *bus;
  45. rt_uint32_t addr;
  46. struct rt_phy_ops *ops;
  47. };
  48. typedef struct rt_phy_device rt_phy_t;
  49. enum {
  50. PHY_STATUS_OK = 0,
  51. PHY_STATUS_FAIL,
  52. PHY_STATUS_TIMEOUT,
  53. };
  54. typedef rt_int32_t rt_phy_status;
  55. struct rt_phy_ops
  56. {
  57. rt_phy_status (*init)(void *object, rt_uint32_t phy_addr, rt_uint32_t src_clock_hz);
  58. rt_phy_status (*read)(rt_uint32_t reg, rt_uint32_t *data);
  59. rt_phy_status (*write)(rt_uint32_t reg, rt_uint32_t data);
  60. rt_phy_status (*loopback)(rt_uint32_t mode, rt_uint32_t speed, rt_bool_t enable);
  61. rt_phy_status (*get_link_status)(rt_bool_t *status);
  62. rt_phy_status (*get_link_speed_duplex)(rt_uint32_t *speed, rt_uint32_t *duplex);
  63. };
  64. rt_err_t rt_hw_phy_register(struct rt_phy_device *phy, const char *name);
  65. #ifdef __cplusplus
  66. }
  67. #endif
  68. #endif /* __PHY_H__*/