qsemi.c 3.6 KB

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