uPD60620.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Driver for the Renesas PHY uPD60620.
  4. *
  5. * Copyright (C) 2015 Softing Industrial Automation GmbH
  6. */
  7. #include <linux/kernel.h>
  8. #include <linux/module.h>
  9. #include <linux/phy.h>
  10. #define UPD60620_PHY_ID 0xb8242824
  11. /* Extended Registers and values */
  12. /* PHY Special Control/Status */
  13. #define PHY_PHYSCR 0x1F /* PHY.31 */
  14. #define PHY_PHYSCR_10MB 0x0004 /* PHY speed = 10mb */
  15. #define PHY_PHYSCR_100MB 0x0008 /* PHY speed = 100mb */
  16. #define PHY_PHYSCR_DUPLEX 0x0010 /* PHY Duplex */
  17. /* PHY Special Modes */
  18. #define PHY_SPM 0x12 /* PHY.18 */
  19. /* Init PHY */
  20. static int upd60620_config_init(struct phy_device *phydev)
  21. {
  22. /* Enable support for passive HUBs (could be a strap option) */
  23. /* PHYMODE: All speeds, HD in parallel detect */
  24. return phy_write(phydev, PHY_SPM, 0x0180 | phydev->mdio.addr);
  25. }
  26. /* Get PHY status from common registers */
  27. static int upd60620_read_status(struct phy_device *phydev)
  28. {
  29. int phy_state;
  30. /* Read negotiated state */
  31. phy_state = phy_read(phydev, MII_BMSR);
  32. if (phy_state < 0)
  33. return phy_state;
  34. phydev->link = 0;
  35. linkmode_zero(phydev->lp_advertising);
  36. phydev->pause = 0;
  37. phydev->asym_pause = 0;
  38. if (phy_state & (BMSR_ANEGCOMPLETE | BMSR_LSTATUS)) {
  39. phy_state = phy_read(phydev, PHY_PHYSCR);
  40. if (phy_state < 0)
  41. return phy_state;
  42. if (phy_state & (PHY_PHYSCR_10MB | PHY_PHYSCR_100MB)) {
  43. phydev->link = 1;
  44. phydev->speed = SPEED_10;
  45. phydev->duplex = DUPLEX_HALF;
  46. if (phy_state & PHY_PHYSCR_100MB)
  47. phydev->speed = SPEED_100;
  48. if (phy_state & PHY_PHYSCR_DUPLEX)
  49. phydev->duplex = DUPLEX_FULL;
  50. phy_state = phy_read(phydev, MII_LPA);
  51. if (phy_state < 0)
  52. return phy_state;
  53. mii_lpa_to_linkmode_lpa_t(phydev->lp_advertising,
  54. phy_state);
  55. if (phydev->duplex == DUPLEX_FULL) {
  56. if (phy_state & LPA_PAUSE_CAP)
  57. phydev->pause = 1;
  58. if (phy_state & LPA_PAUSE_ASYM)
  59. phydev->asym_pause = 1;
  60. }
  61. }
  62. }
  63. return 0;
  64. }
  65. MODULE_DESCRIPTION("Renesas uPD60620 PHY driver");
  66. MODULE_AUTHOR("Bernd Edlinger <bernd.edlinger@hotmail.de>");
  67. MODULE_LICENSE("GPL");
  68. static struct phy_driver upd60620_driver[1] = { {
  69. .phy_id = UPD60620_PHY_ID,
  70. .phy_id_mask = 0xfffffffe,
  71. .name = "Renesas uPD60620",
  72. /* PHY_BASIC_FEATURES */
  73. .flags = 0,
  74. .config_init = upd60620_config_init,
  75. .read_status = upd60620_read_status,
  76. } };
  77. module_phy_driver(upd60620_driver);
  78. static struct mdio_device_id __maybe_unused upd60620_tbl[] = {
  79. { UPD60620_PHY_ID, 0xfffffffe },
  80. { }
  81. };
  82. MODULE_DEVICE_TABLE(mdio, upd60620_tbl);