uPD60620.c 2.8 KB

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