davicom.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. * drivers/net/phy/davicom.c
  3. *
  4. * Driver for Davicom 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. #define MII_DM9161_SCR 0x10
  38. #define MII_DM9161_SCR_INIT 0x0610
  39. /* DM9161 Interrupt Register */
  40. #define MII_DM9161_INTR 0x15
  41. #define MII_DM9161_INTR_PEND 0x8000
  42. #define MII_DM9161_INTR_DPLX_MASK 0x0800
  43. #define MII_DM9161_INTR_SPD_MASK 0x0400
  44. #define MII_DM9161_INTR_LINK_MASK 0x0200
  45. #define MII_DM9161_INTR_MASK 0x0100
  46. #define MII_DM9161_INTR_DPLX_CHANGE 0x0010
  47. #define MII_DM9161_INTR_SPD_CHANGE 0x0008
  48. #define MII_DM9161_INTR_LINK_CHANGE 0x0004
  49. #define MII_DM9161_INTR_INIT 0x0000
  50. #define MII_DM9161_INTR_STOP \
  51. (MII_DM9161_INTR_DPLX_MASK | MII_DM9161_INTR_SPD_MASK \
  52. | MII_DM9161_INTR_LINK_MASK | MII_DM9161_INTR_MASK)
  53. /* DM9161 10BT Configuration/Status */
  54. #define MII_DM9161_10BTCSR 0x12
  55. #define MII_DM9161_10BTCSR_INIT 0x7800
  56. MODULE_DESCRIPTION("Davicom PHY driver");
  57. MODULE_AUTHOR("Andy Fleming");
  58. MODULE_LICENSE("GPL");
  59. #define DM9161_DELAY 1
  60. static int dm9161_config_intr(struct phy_device *phydev)
  61. {
  62. int temp;
  63. temp = phy_read(phydev, MII_DM9161_INTR);
  64. if (temp < 0)
  65. return temp;
  66. if(PHY_INTERRUPT_ENABLED == phydev->interrupts )
  67. temp &= ~(MII_DM9161_INTR_STOP);
  68. else
  69. temp |= MII_DM9161_INTR_STOP;
  70. temp = phy_write(phydev, MII_DM9161_INTR, temp);
  71. return temp;
  72. }
  73. static int dm9161_config_aneg(struct phy_device *phydev)
  74. {
  75. int err;
  76. /* Isolate the PHY */
  77. err = phy_write(phydev, MII_BMCR, BMCR_ISOLATE);
  78. if (err < 0)
  79. return err;
  80. /* Configure the new settings */
  81. err = genphy_config_aneg(phydev);
  82. if (err < 0)
  83. return err;
  84. return 0;
  85. }
  86. static int dm9161_config_init(struct phy_device *phydev)
  87. {
  88. int err;
  89. /* Isolate the PHY */
  90. err = phy_write(phydev, MII_BMCR, BMCR_ISOLATE);
  91. if (err < 0)
  92. return err;
  93. /* Do not bypass the scrambler/descrambler */
  94. err = phy_write(phydev, MII_DM9161_SCR, MII_DM9161_SCR_INIT);
  95. if (err < 0)
  96. return err;
  97. /* Clear 10BTCSR to default */
  98. err = phy_write(phydev, MII_DM9161_10BTCSR, MII_DM9161_10BTCSR_INIT);
  99. if (err < 0)
  100. return err;
  101. /* Reconnect the PHY, and enable Autonegotiation */
  102. err = phy_write(phydev, MII_BMCR, BMCR_ANENABLE);
  103. if (err < 0)
  104. return err;
  105. return 0;
  106. }
  107. static int dm9161_ack_interrupt(struct phy_device *phydev)
  108. {
  109. int err = phy_read(phydev, MII_DM9161_INTR);
  110. return (err < 0) ? err : 0;
  111. }
  112. static struct phy_driver dm9161_driver = {
  113. .phy_id = 0x0181b880,
  114. .name = "Davicom DM9161E",
  115. .phy_id_mask = 0x0ffffff0,
  116. .features = PHY_BASIC_FEATURES,
  117. .config_init = dm9161_config_init,
  118. .config_aneg = dm9161_config_aneg,
  119. .read_status = genphy_read_status,
  120. .driver = { .owner = THIS_MODULE,},
  121. };
  122. static struct phy_driver dm9131_driver = {
  123. .phy_id = 0x00181b80,
  124. .name = "Davicom DM9131",
  125. .phy_id_mask = 0x0ffffff0,
  126. .features = PHY_BASIC_FEATURES,
  127. .flags = PHY_HAS_INTERRUPT,
  128. .config_aneg = genphy_config_aneg,
  129. .read_status = genphy_read_status,
  130. .ack_interrupt = dm9161_ack_interrupt,
  131. .config_intr = dm9161_config_intr,
  132. .driver = { .owner = THIS_MODULE,},
  133. };
  134. static int __init davicom_init(void)
  135. {
  136. int ret;
  137. ret = phy_driver_register(&dm9161_driver);
  138. if (ret)
  139. goto err1;
  140. ret = phy_driver_register(&dm9131_driver);
  141. if (ret)
  142. goto err2;
  143. return 0;
  144. err2:
  145. phy_driver_unregister(&dm9161_driver);
  146. err1:
  147. return ret;
  148. }
  149. static void __exit davicom_exit(void)
  150. {
  151. phy_driver_unregister(&dm9161_driver);
  152. phy_driver_unregister(&dm9131_driver);
  153. }
  154. module_init(davicom_init);
  155. module_exit(davicom_exit);