davicom.c 4.2 KB

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