ste10Xp.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * drivers/net/phy/ste10Xp.c
  4. *
  5. * Driver for STMicroelectronics STe10Xp PHYs
  6. *
  7. * Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
  8. *
  9. * Copyright (c) 2008 STMicroelectronics Limited
  10. */
  11. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <linux/sched.h>
  14. #include <linux/kernel.h>
  15. #include <linux/moduleparam.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/netdevice.h>
  18. #include <linux/ethtool.h>
  19. #include <linux/mii.h>
  20. #include <linux/phy.h>
  21. #define MII_XCIIS 0x11 /* Configuration Info IRQ & Status Reg */
  22. #define MII_XIE 0x12 /* Interrupt Enable Register */
  23. #define MII_XIE_DEFAULT_MASK 0x0070 /* ANE complete, Remote Fault, Link Down */
  24. #define STE101P_PHY_ID 0x00061c50
  25. #define STE100P_PHY_ID 0x1c040011
  26. static int ste10Xp_config_init(struct phy_device *phydev)
  27. {
  28. int value, err;
  29. /* Software Reset PHY */
  30. value = phy_read(phydev, MII_BMCR);
  31. if (value < 0)
  32. return value;
  33. value |= BMCR_RESET;
  34. err = phy_write(phydev, MII_BMCR, value);
  35. if (err < 0)
  36. return err;
  37. do {
  38. value = phy_read(phydev, MII_BMCR);
  39. } while (value & BMCR_RESET);
  40. return 0;
  41. }
  42. static int ste10Xp_config_intr(struct phy_device *phydev)
  43. {
  44. int err, value;
  45. if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
  46. /* Enable all STe101P interrupts (PR12) */
  47. err = phy_write(phydev, MII_XIE, MII_XIE_DEFAULT_MASK);
  48. /* clear any pending interrupts */
  49. if (err == 0) {
  50. value = phy_read(phydev, MII_XCIIS);
  51. if (value < 0)
  52. err = value;
  53. }
  54. } else
  55. err = phy_write(phydev, MII_XIE, 0);
  56. return err;
  57. }
  58. static int ste10Xp_ack_interrupt(struct phy_device *phydev)
  59. {
  60. int err = phy_read(phydev, MII_XCIIS);
  61. if (err < 0)
  62. return err;
  63. return 0;
  64. }
  65. static struct phy_driver ste10xp_pdriver[] = {
  66. {
  67. .phy_id = STE101P_PHY_ID,
  68. .phy_id_mask = 0xfffffff0,
  69. .name = "STe101p",
  70. /* PHY_BASIC_FEATURES */
  71. .config_init = ste10Xp_config_init,
  72. .ack_interrupt = ste10Xp_ack_interrupt,
  73. .config_intr = ste10Xp_config_intr,
  74. .suspend = genphy_suspend,
  75. .resume = genphy_resume,
  76. }, {
  77. .phy_id = STE100P_PHY_ID,
  78. .phy_id_mask = 0xffffffff,
  79. .name = "STe100p",
  80. /* PHY_BASIC_FEATURES */
  81. .config_init = ste10Xp_config_init,
  82. .ack_interrupt = ste10Xp_ack_interrupt,
  83. .config_intr = ste10Xp_config_intr,
  84. .suspend = genphy_suspend,
  85. .resume = genphy_resume,
  86. } };
  87. module_phy_driver(ste10xp_pdriver);
  88. static struct mdio_device_id __maybe_unused ste10Xp_tbl[] = {
  89. { STE101P_PHY_ID, 0xfffffff0 },
  90. { STE100P_PHY_ID, 0xffffffff },
  91. { }
  92. };
  93. MODULE_DEVICE_TABLE(mdio, ste10Xp_tbl);
  94. MODULE_DESCRIPTION("STMicroelectronics STe10Xp PHY driver");
  95. MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
  96. MODULE_LICENSE("GPL");