davicom.c 4.2 KB

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