ste10Xp.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * drivers/net/phy/ste10Xp.c
  3. *
  4. * Driver for STMicroelectronics STe10Xp PHYs
  5. *
  6. * Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
  7. *
  8. * Copyright (c) 2008 STMicroelectronics Limited
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the
  12. * Free Software Foundation; either version 2 of the License, or (at your
  13. * option) any later version.
  14. *
  15. */
  16. #include <linux/module.h>
  17. #include <linux/init.h>
  18. #include <linux/sched.h>
  19. #include <linux/kernel.h>
  20. #include <linux/moduleparam.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/netdevice.h>
  23. #include <linux/ethtool.h>
  24. #include <linux/mii.h>
  25. #include <linux/phy.h>
  26. #define MII_XCIIS 0x11 /* Configuration Info IRQ & Status Reg */
  27. #define MII_XIE 0x12 /* Interrupt Enable Register */
  28. #define MII_XIE_DEFAULT_MASK 0x0070 /* ANE complete, Remote Fault, Link Down */
  29. #define STE101P_PHY_ID 0x00061c50
  30. #define STE100P_PHY_ID 0x1c040011
  31. static int ste10Xp_config_init(struct phy_device *phydev)
  32. {
  33. int value, err;
  34. /* Software Reset PHY */
  35. value = phy_read(phydev, MII_BMCR);
  36. if (value < 0)
  37. return value;
  38. value |= BMCR_RESET;
  39. err = phy_write(phydev, MII_BMCR, value);
  40. if (err < 0)
  41. return err;
  42. do {
  43. value = phy_read(phydev, MII_BMCR);
  44. } while (value & BMCR_RESET);
  45. return 0;
  46. }
  47. static int ste10Xp_config_intr(struct phy_device *phydev)
  48. {
  49. int err, value;
  50. if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
  51. /* Enable all STe101P interrupts (PR12) */
  52. err = phy_write(phydev, MII_XIE, MII_XIE_DEFAULT_MASK);
  53. /* clear any pending interrupts */
  54. if (err == 0) {
  55. value = phy_read(phydev, MII_XCIIS);
  56. if (value < 0)
  57. err = value;
  58. }
  59. } else
  60. err = phy_write(phydev, MII_XIE, 0);
  61. return err;
  62. }
  63. static int ste10Xp_ack_interrupt(struct phy_device *phydev)
  64. {
  65. int err = phy_read(phydev, MII_XCIIS);
  66. if (err < 0)
  67. return err;
  68. return 0;
  69. }
  70. static struct phy_driver ste10xp_pdriver[] = {
  71. {
  72. .phy_id = STE101P_PHY_ID,
  73. .phy_id_mask = 0xfffffff0,
  74. .name = "STe101p",
  75. .features = PHY_BASIC_FEATURES | SUPPORTED_Pause,
  76. .flags = PHY_HAS_INTERRUPT,
  77. .config_init = ste10Xp_config_init,
  78. .config_aneg = genphy_config_aneg,
  79. .read_status = genphy_read_status,
  80. .ack_interrupt = ste10Xp_ack_interrupt,
  81. .config_intr = ste10Xp_config_intr,
  82. .suspend = genphy_suspend,
  83. .resume = genphy_resume,
  84. .driver = {.owner = THIS_MODULE,}
  85. }, {
  86. .phy_id = STE100P_PHY_ID,
  87. .phy_id_mask = 0xffffffff,
  88. .name = "STe100p",
  89. .features = PHY_BASIC_FEATURES | SUPPORTED_Pause,
  90. .flags = PHY_HAS_INTERRUPT,
  91. .config_init = ste10Xp_config_init,
  92. .config_aneg = genphy_config_aneg,
  93. .read_status = genphy_read_status,
  94. .ack_interrupt = ste10Xp_ack_interrupt,
  95. .config_intr = ste10Xp_config_intr,
  96. .suspend = genphy_suspend,
  97. .resume = genphy_resume,
  98. .driver = {.owner = THIS_MODULE,}
  99. } };
  100. module_phy_driver(ste10xp_pdriver);
  101. static struct mdio_device_id __maybe_unused ste10Xp_tbl[] = {
  102. { STE101P_PHY_ID, 0xfffffff0 },
  103. { STE100P_PHY_ID, 0xffffffff },
  104. { }
  105. };
  106. MODULE_DEVICE_TABLE(mdio, ste10Xp_tbl);
  107. MODULE_DESCRIPTION("STMicroelectronics STe10Xp PHY driver");
  108. MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
  109. MODULE_LICENSE("GPL");