qsemi.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * drivers/net/phy/qsemi.c
  4. *
  5. * Driver for Quality Semiconductor PHYs
  6. *
  7. * Author: Andy Fleming
  8. *
  9. * Copyright (c) 2004 Freescale Semiconductor, Inc.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/string.h>
  13. #include <linux/errno.h>
  14. #include <linux/unistd.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/init.h>
  17. #include <linux/delay.h>
  18. #include <linux/netdevice.h>
  19. #include <linux/etherdevice.h>
  20. #include <linux/skbuff.h>
  21. #include <linux/spinlock.h>
  22. #include <linux/mm.h>
  23. #include <linux/module.h>
  24. #include <linux/mii.h>
  25. #include <linux/ethtool.h>
  26. #include <linux/phy.h>
  27. #include <asm/io.h>
  28. #include <asm/irq.h>
  29. #include <linux/uaccess.h>
  30. /* ------------------------------------------------------------------------- */
  31. /* The Quality Semiconductor QS6612 is used on the RPX CLLF */
  32. /* register definitions */
  33. #define MII_QS6612_MCR 17 /* Mode Control Register */
  34. #define MII_QS6612_FTR 27 /* Factory Test Register */
  35. #define MII_QS6612_MCO 28 /* Misc. Control Register */
  36. #define MII_QS6612_ISR 29 /* Interrupt Source Register */
  37. #define MII_QS6612_IMR 30 /* Interrupt Mask Register */
  38. #define MII_QS6612_IMR_INIT 0x003a
  39. #define MII_QS6612_PCR 31 /* 100BaseTx PHY Control Reg. */
  40. #define QS6612_PCR_AN_COMPLETE 0x1000
  41. #define QS6612_PCR_RLBEN 0x0200
  42. #define QS6612_PCR_DCREN 0x0100
  43. #define QS6612_PCR_4B5BEN 0x0040
  44. #define QS6612_PCR_TX_ISOLATE 0x0020
  45. #define QS6612_PCR_MLT3_DIS 0x0002
  46. #define QS6612_PCR_SCRM_DESCRM 0x0001
  47. MODULE_DESCRIPTION("Quality Semiconductor PHY driver");
  48. MODULE_AUTHOR("Andy Fleming");
  49. MODULE_LICENSE("GPL");
  50. /* Returns 0, unless there's a write error */
  51. static int qs6612_config_init(struct phy_device *phydev)
  52. {
  53. /* The PHY powers up isolated on the RPX,
  54. * so send a command to allow operation.
  55. * XXX - My docs indicate this should be 0x0940
  56. * ...or something. The current value sets three
  57. * reserved bits, bit 11, which specifies it should be
  58. * set to one, bit 10, which specifies it should be set
  59. * to 0, and bit 7, which doesn't specify. However, my
  60. * docs are preliminary, and I will leave it like this
  61. * until someone more knowledgable corrects me or it.
  62. * -- Andy Fleming
  63. */
  64. return phy_write(phydev, MII_QS6612_PCR, 0x0dc0);
  65. }
  66. static int qs6612_ack_interrupt(struct phy_device *phydev)
  67. {
  68. int err;
  69. err = phy_read(phydev, MII_QS6612_ISR);
  70. if (err < 0)
  71. return err;
  72. err = phy_read(phydev, MII_BMSR);
  73. if (err < 0)
  74. return err;
  75. err = phy_read(phydev, MII_EXPANSION);
  76. if (err < 0)
  77. return err;
  78. return 0;
  79. }
  80. static int qs6612_config_intr(struct phy_device *phydev)
  81. {
  82. int err;
  83. if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
  84. err = phy_write(phydev, MII_QS6612_IMR,
  85. MII_QS6612_IMR_INIT);
  86. else
  87. err = phy_write(phydev, MII_QS6612_IMR, 0);
  88. return err;
  89. }
  90. static struct phy_driver qs6612_driver[] = { {
  91. .phy_id = 0x00181440,
  92. .name = "QS6612",
  93. .phy_id_mask = 0xfffffff0,
  94. /* PHY_BASIC_FEATURES */
  95. .config_init = qs6612_config_init,
  96. .ack_interrupt = qs6612_ack_interrupt,
  97. .config_intr = qs6612_config_intr,
  98. } };
  99. module_phy_driver(qs6612_driver);
  100. static struct mdio_device_id __maybe_unused qs6612_tbl[] = {
  101. { 0x00181440, 0xfffffff0 },
  102. { }
  103. };
  104. MODULE_DEVICE_TABLE(mdio, qs6612_tbl);