cicada.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * drivers/net/phy/cicada.c
  3. *
  4. * Driver for Cicada 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/sched.h>
  18. #include <linux/string.h>
  19. #include <linux/errno.h>
  20. #include <linux/unistd.h>
  21. #include <linux/slab.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/init.h>
  24. #include <linux/delay.h>
  25. #include <linux/netdevice.h>
  26. #include <linux/etherdevice.h>
  27. #include <linux/skbuff.h>
  28. #include <linux/spinlock.h>
  29. #include <linux/mm.h>
  30. #include <linux/module.h>
  31. #include <linux/mii.h>
  32. #include <linux/ethtool.h>
  33. #include <linux/phy.h>
  34. #include <asm/io.h>
  35. #include <asm/irq.h>
  36. #include <asm/uaccess.h>
  37. /* Cicada Extended Control Register 1 */
  38. #define MII_CIS8201_EXT_CON1 0x17
  39. #define MII_CIS8201_EXTCON1_INIT 0x0000
  40. /* Cicada Interrupt Mask Register */
  41. #define MII_CIS8201_IMASK 0x19
  42. #define MII_CIS8201_IMASK_IEN 0x8000
  43. #define MII_CIS8201_IMASK_SPEED 0x4000
  44. #define MII_CIS8201_IMASK_LINK 0x2000
  45. #define MII_CIS8201_IMASK_DUPLEX 0x1000
  46. #define MII_CIS8201_IMASK_MASK 0xf000
  47. /* Cicada Interrupt Status Register */
  48. #define MII_CIS8201_ISTAT 0x1a
  49. #define MII_CIS8201_ISTAT_STATUS 0x8000
  50. #define MII_CIS8201_ISTAT_SPEED 0x4000
  51. #define MII_CIS8201_ISTAT_LINK 0x2000
  52. #define MII_CIS8201_ISTAT_DUPLEX 0x1000
  53. /* Cicada Auxiliary Control/Status Register */
  54. #define MII_CIS8201_AUX_CONSTAT 0x1c
  55. #define MII_CIS8201_AUXCONSTAT_INIT 0x0004
  56. #define MII_CIS8201_AUXCONSTAT_DUPLEX 0x0020
  57. #define MII_CIS8201_AUXCONSTAT_SPEED 0x0018
  58. #define MII_CIS8201_AUXCONSTAT_GBIT 0x0010
  59. #define MII_CIS8201_AUXCONSTAT_100 0x0008
  60. MODULE_DESCRIPTION("Cicadia PHY driver");
  61. MODULE_AUTHOR("Andy Fleming");
  62. MODULE_LICENSE("GPL");
  63. static int cis820x_config_init(struct phy_device *phydev)
  64. {
  65. int err;
  66. err = phy_write(phydev, MII_CIS8201_AUX_CONSTAT,
  67. MII_CIS8201_AUXCONSTAT_INIT);
  68. if (err < 0)
  69. return err;
  70. err = phy_write(phydev, MII_CIS8201_EXT_CON1,
  71. MII_CIS8201_EXTCON1_INIT);
  72. return err;
  73. }
  74. static int cis820x_ack_interrupt(struct phy_device *phydev)
  75. {
  76. int err = phy_read(phydev, MII_CIS8201_ISTAT);
  77. return (err < 0) ? err : 0;
  78. }
  79. static int cis820x_config_intr(struct phy_device *phydev)
  80. {
  81. int err;
  82. if(phydev->interrupts == PHY_INTERRUPT_ENABLED)
  83. err = phy_write(phydev, MII_CIS8201_IMASK,
  84. MII_CIS8201_IMASK_MASK);
  85. else
  86. err = phy_write(phydev, MII_CIS8201_IMASK, 0);
  87. return err;
  88. }
  89. /* Cicada 8201, a.k.a Vitesse VSC8201 */
  90. static struct phy_driver cis8201_driver = {
  91. .phy_id = 0x000fc410,
  92. .name = "Cicada Cis8201",
  93. .phy_id_mask = 0x000ffff0,
  94. .features = PHY_GBIT_FEATURES,
  95. .flags = PHY_HAS_INTERRUPT,
  96. .config_init = &cis820x_config_init,
  97. .config_aneg = &genphy_config_aneg,
  98. .read_status = &genphy_read_status,
  99. .ack_interrupt = &cis820x_ack_interrupt,
  100. .config_intr = &cis820x_config_intr,
  101. .driver = { .owner = THIS_MODULE,},
  102. };
  103. /* Cicada 8204 */
  104. static struct phy_driver cis8204_driver = {
  105. .phy_id = 0x000fc440,
  106. .name = "Cicada Cis8204",
  107. .phy_id_mask = 0x000fffc0,
  108. .features = PHY_GBIT_FEATURES,
  109. .flags = PHY_HAS_INTERRUPT,
  110. .config_init = &cis820x_config_init,
  111. .config_aneg = &genphy_config_aneg,
  112. .read_status = &genphy_read_status,
  113. .ack_interrupt = &cis820x_ack_interrupt,
  114. .config_intr = &cis820x_config_intr,
  115. .driver = { .owner = THIS_MODULE,},
  116. };
  117. static int __init cicada_init(void)
  118. {
  119. int ret;
  120. ret = phy_driver_register(&cis8204_driver);
  121. if (ret)
  122. goto err1;
  123. ret = phy_driver_register(&cis8201_driver);
  124. if (ret)
  125. goto err2;
  126. return 0;
  127. err2:
  128. phy_driver_unregister(&cis8204_driver);
  129. err1:
  130. return ret;
  131. }
  132. static void __exit cicada_exit(void)
  133. {
  134. phy_driver_unregister(&cis8204_driver);
  135. phy_driver_unregister(&cis8201_driver);
  136. }
  137. module_init(cicada_init);
  138. module_exit(cicada_exit);