chry_phy.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. };
  20. struct chry_phy_status {
  21. bool link;
  22. bool duplex;
  23. uint16_t speed;
  24. };
  25. struct chry_phy_device;
  26. struct chry_phy_driver {
  27. char *phy_name;
  28. char *phy_desc;
  29. uint32_t phy_id;
  30. uint32_t phy_id_mask;
  31. void (*phy_init)(struct chry_phy_device *phydev, struct chry_phy_config *config);
  32. void (*phy_get_status)(struct chry_phy_device *phydev, struct chry_phy_status *status);
  33. };
  34. struct chry_phy_support {
  35. uint32_t support_100base_t4 : 1;
  36. uint32_t support_1000base_tx_full : 1;
  37. uint32_t support_1000base_tx_half : 1;
  38. uint32_t support_100base_tx_full : 1;
  39. uint32_t support_100base_tx_half : 1;
  40. uint32_t support_10base_tx_full : 1;
  41. uint32_t support_10base_tx_half : 1;
  42. uint32_t support_asym_pause : 1;
  43. uint32_t support_pause : 1;
  44. uint32_t support_autoeng : 1;
  45. uint32_t reserved : 22;
  46. };
  47. struct chry_phy_device {
  48. uint16_t phy_addr;
  49. uint32_t phy_id;
  50. struct chry_phy_support support;
  51. const struct chry_phy_driver *driver;
  52. void (*mdio_write)(struct chry_phy_device *phydev, uint16_t phy_addr, uint16_t regnum, uint16_t val);
  53. uint16_t (*mdio_read)(struct chry_phy_device *phydev, uint16_t phy_addr, uint16_t regnum);
  54. void *user_data;
  55. };
  56. #ifdef __cplusplus
  57. extern "C" {
  58. #endif
  59. int chry_phy_init(struct chry_phy_device *phydev, struct chry_phy_config *config);
  60. void chry_phy_get_status(struct chry_phy_device *phydev, struct chry_phy_status *status);
  61. #ifdef __cplusplus
  62. }
  63. #endif
  64. #endif