phydev.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*!
  2. * Copyright (C) Fraunhofer-Institut for Photonic Microsystems (IPMS)
  3. * Maria-Reiche-Str. 2
  4. * 01109 Dresden
  5. *
  6. * Unauthorized copying of this file, via any medium is strictly prohibited
  7. * Proprietary and confidential
  8. *
  9. * \file phydev.h
  10. * \author phil.seipt@ipms.fraunhofer.de
  11. * \date 08.06.2021
  12. * \brief PHY devices
  13. *
  14. */
  15. #ifndef PHYDEV_H_
  16. #define PHYDEV_H_
  17. #include <stdint.h>
  18. //#include <kernel/net/phy.h>
  19. #include <kernel/net/netdev.h>
  20. /* FreeRTOS includes. */
  21. #include "FreeRTOS.h"
  22. #include "semphr.h"
  23. #define PHY_MAX_ADDR 32
  24. #define PHY_UPDATE_DELAY_MS 2000
  25. /**
  26. * \brief phydev register access
  27. */
  28. enum phydev_reg_access {
  29. PHYDEV_ACCESS_SET, //!< set register
  30. PHYDEV_ACCESS_GET, //!< get register
  31. };
  32. /**
  33. * \brief PHY device driver
  34. */
  35. struct phydev_s {
  36. uint32_t id; //!< device driver id
  37. void *prv; //!< pointer to private data
  38. struct netdev_s *netdev; //!< pointer to netdevice
  39. struct mdiobus_s *mdio; //!< pointer to MDIO bus driver
  40. uint32_t phyad; //!< PHY address at MDIO bus
  41. int speed; //!< last known speed
  42. int aneg_on; //!< autonegotiation enabled
  43. uint32_t fullduplex; //!< last known fullduplex status
  44. void (*open)(struct phydev_s *phy, void *config); //!< function pointer, bring up the PHY device
  45. void (*update_link)(struct phydev_s *phy); //!< function pointer, update link status (speed, duplex)
  46. void (*aneg_enable)(struct phydev_s *phy, int enable); //!< function pointer, enable/disable auto negotiation
  47. void (*force_speed)(struct phydev_s *phy, int speed); //!< function pointer, force PHY to speed
  48. void (*reg_dump)(struct phydev_s *phy); //!< function pointer, print PHY registers
  49. void (*restart)(struct phydev_s *phy); //!< function pointer, restart PHY
  50. void (*reg_modify)(struct phydev_s *phy, enum phydev_reg_access access, uint32_t reg, uint32_t *value); //!< function pointer, PHY register modify
  51. };
  52. void phydev_init(void);
  53. struct phydev_s *phydev_register(struct netdev_s *netdev, struct mdiobus_s *mdio);
  54. void phydev_start(struct phydev_s *phy, uint32_t phyad);
  55. void phydev_update_link(struct phydev_s *phy);
  56. void phydev_aneg_enable(struct phydev_s *phy, int enable);
  57. void phydev_force_speed(struct phydev_s *phy, int speed);
  58. void phydev_reset(struct phydev_s *phy);
  59. void phydev_reg_dump(struct phydev_s *phy);
  60. int phydev_rreg(struct phydev_s *phy, uint32_t reg);
  61. void phydev_wreg(struct phydev_s *phy, uint32_t reg, uint32_t value);
  62. void phydev_restart(struct phydev_s *phy);
  63. int32_t phydev_modify(struct phydev_s *phy, uint32_t regad, uint16_t clrmask, uint16_t setmask);
  64. #endif /* PHYDEV_H_ */