uPD60620.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. phy_resolve_aneg_pause(phydev);
  56. }
  57. }
  58. return 0;
  59. }
  60. MODULE_DESCRIPTION("Renesas uPD60620 PHY driver");
  61. MODULE_AUTHOR("Bernd Edlinger <[email protected]>");
  62. MODULE_LICENSE("GPL");
  63. static struct phy_driver upd60620_driver[1] = { {
  64. .phy_id = UPD60620_PHY_ID,
  65. .phy_id_mask = 0xfffffffe,
  66. .name = "Renesas uPD60620",
  67. /* PHY_BASIC_FEATURES */
  68. .flags = 0,
  69. .config_init = upd60620_config_init,
  70. .read_status = upd60620_read_status,
  71. } };
  72. module_phy_driver(upd60620_driver);
  73. static struct mdio_device_id __maybe_unused upd60620_tbl[] = {
  74. { UPD60620_PHY_ID, 0xfffffffe },
  75. { }
  76. };
  77. MODULE_DEVICE_TABLE(mdio, upd60620_tbl);