chry_phy.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright (c) 2024, sakumisu
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef CHRY_PHY_H
  7. #define CHRY_PHY_H
  8. #include <stdbool.h>
  9. #include <string.h>
  10. #include <stdint.h>
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13. #include "chry_mii.h"
  14. struct chry_phy_config {
  15. bool loopback;
  16. bool auto_negotiation;
  17. bool duplex;
  18. uint16_t speed;
  19. uint16_t phy_port;
  20. };
  21. struct chry_phy_status {
  22. bool link;
  23. bool duplex;
  24. uint16_t speed;
  25. };
  26. struct chry_phy_device;
  27. struct chry_phy_driver {
  28. char *phy_name;
  29. char *phy_desc;
  30. uint32_t phy_id;
  31. uint32_t phy_id_mask;
  32. void (*phy_init)(struct chry_phy_device *phydev, struct chry_phy_config *config);
  33. void (*phy_get_status)(struct chry_phy_device *phydev, struct chry_phy_status *status);
  34. };
  35. struct chry_phy_support {
  36. uint32_t support_100base_t4 : 1;
  37. uint32_t support_1000base_tx_full : 1;
  38. uint32_t support_1000base_tx_half : 1;
  39. uint32_t support_100base_tx_full : 1;
  40. uint32_t support_100base_tx_half : 1;
  41. uint32_t support_10base_tx_full : 1;
  42. uint32_t support_10base_tx_half : 1;
  43. uint32_t support_asym_pause : 1;
  44. uint32_t support_pause : 1;
  45. uint32_t support_autoeng : 1;
  46. uint32_t reserved : 22;
  47. };
  48. struct chry_phy_device {
  49. uint16_t phy_port;
  50. uint16_t phy_addr;
  51. uint32_t phy_id;
  52. struct chry_phy_support support;
  53. const struct chry_phy_driver *driver;
  54. void (*mdio_write)(struct chry_phy_device *phydev, uint16_t phy_addr, uint16_t regnum, uint16_t val);
  55. uint16_t (*mdio_read)(struct chry_phy_device *phydev, uint16_t phy_addr, uint16_t regnum);
  56. void *user_data;
  57. };
  58. #ifdef __cplusplus
  59. extern "C" {
  60. #endif
  61. int chry_phy_init(struct chry_phy_device *phydev, struct chry_phy_config *config);
  62. void chry_phy_get_status(struct chry_phy_device *phydev, struct chry_phy_status *status);
  63. #ifdef __cplusplus
  64. }
  65. #endif
  66. #endif