chry_phy_dp83825.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright (c) 2024, sakumisu
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include "chry_phy.h"
  7. #define DP83825_PHYSTS 0x10 /* PHY Status Register */
  8. #define DP83825_PHYCR 0x19
  9. #define DP83825_PHYSTS_LINK_STATUS (0x0001U)
  10. /*
  11. * SPEED_STATUS (RO)
  12. *
  13. * Speed10:
  14. * This bit indicates the status of the speed and is determined from Auto-Negotiation or Forced
  15. * Modes.
  16. * 1 = 10 Mb/s mode.
  17. * 0 = 100 Mb/s mode.
  18. * Note: This bit is only valid if Auto-Negotiation is enabled and complete and there is a valid
  19. * link or if Auto-Negotiation is disabled and there is a valid link.
  20. */
  21. #define DP83825_PHYSTS_SPEED_STATUS (0x0002U)
  22. #define DP83825_PHYSTS_DUPLEX_STATUS (0x0004U)
  23. void dp83825_phy_init(struct chry_phy_device *phydev, struct chry_phy_config *config)
  24. {
  25. // uint16_t data = 0;
  26. //
  27. // data |= config->auto_negotiation ? 0x1000U : 0;
  28. //
  29. // if (config->auto_negotiation == false) {
  30. // data |= 0x2000U; /* Set port speed */
  31. // data |= 0x100U; /* Set duplex mode */
  32. // }
  33. //
  34. //
  35. // phydev->mdio_write(phydev, phydev->phy_addr, MII_BMCR, data);
  36. // data = phydev->mdio_read(phydev, phydev->phy_addr, DP83825_PHYCR); //DP83825_PHYCR
  37. // data &= 0x3f;
  38. // phydev->mdio_write(phydev, phydev->phy_addr, DP83825_PHYCR, data); //disable auto MDIX
  39. }
  40. void dp83825_phy_get_status(struct chry_phy_device *phydev, struct chry_phy_status *status)
  41. {
  42. uint16_t regval;
  43. regval = phydev->mdio_read(phydev, phydev->phy_addr, DP83825_PHYSTS);
  44. status->link = regval & DP83825_PHYSTS_LINK_STATUS;
  45. if (status->link) {
  46. status->duplex = regval & DP83825_PHYSTS_DUPLEX_STATUS;
  47. status->speed = (regval & DP83825_PHYSTS_SPEED_STATUS) ? 10 : 100;
  48. }
  49. }
  50. const struct chry_phy_driver dp83825_driver = {
  51. .phy_id = 0x2000A000,
  52. .phy_id_mask = 0xFFFFFC00,
  53. .phy_name = "DP83825",
  54. .phy_desc = "TI DP83825 Ethernet PHY",
  55. .phy_init = dp83825_phy_init,
  56. .phy_get_status = dp83825_phy_get_status,
  57. };