marvell.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * drivers/net/phy/marvell.c
  3. *
  4. * Driver for Marvell 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_M1011_IEVENT 0x13
  38. #define MII_M1011_IEVENT_CLEAR 0x0000
  39. #define MII_M1011_IMASK 0x12
  40. #define MII_M1011_IMASK_INIT 0x6400
  41. #define MII_M1011_IMASK_CLEAR 0x0000
  42. MODULE_DESCRIPTION("Marvell PHY driver");
  43. MODULE_AUTHOR("Andy Fleming");
  44. MODULE_LICENSE("GPL");
  45. static int marvell_ack_interrupt(struct phy_device *phydev)
  46. {
  47. int err;
  48. /* Clear the interrupts by reading the reg */
  49. err = phy_read(phydev, MII_M1011_IEVENT);
  50. if (err < 0)
  51. return err;
  52. return 0;
  53. }
  54. static int marvell_config_intr(struct phy_device *phydev)
  55. {
  56. int err;
  57. if(phydev->interrupts == PHY_INTERRUPT_ENABLED)
  58. err = phy_write(phydev, MII_M1011_IMASK, MII_M1011_IMASK_INIT);
  59. else
  60. err = phy_write(phydev, MII_M1011_IMASK, MII_M1011_IMASK_CLEAR);
  61. return err;
  62. }
  63. static int marvell_config_aneg(struct phy_device *phydev)
  64. {
  65. int err;
  66. /* The Marvell PHY has an errata which requires
  67. * that certain registers get written in order
  68. * to restart autonegotiation */
  69. err = phy_write(phydev, MII_BMCR, BMCR_RESET);
  70. if (err < 0)
  71. return err;
  72. err = phy_write(phydev, 0x1d, 0x1f);
  73. if (err < 0)
  74. return err;
  75. err = phy_write(phydev, 0x1e, 0x200c);
  76. if (err < 0)
  77. return err;
  78. err = phy_write(phydev, 0x1d, 0x5);
  79. if (err < 0)
  80. return err;
  81. err = phy_write(phydev, 0x1e, 0);
  82. if (err < 0)
  83. return err;
  84. err = phy_write(phydev, 0x1e, 0x100);
  85. if (err < 0)
  86. return err;
  87. err = genphy_config_aneg(phydev);
  88. return err;
  89. }
  90. static struct phy_driver m88e1101_driver = {
  91. .phy_id = 0x01410c00,
  92. .phy_id_mask = 0xffffff00,
  93. .name = "Marvell 88E1101",
  94. .features = PHY_GBIT_FEATURES,
  95. .flags = PHY_HAS_INTERRUPT,
  96. .config_aneg = &marvell_config_aneg,
  97. .read_status = &genphy_read_status,
  98. .ack_interrupt = &marvell_ack_interrupt,
  99. .config_intr = &marvell_config_intr,
  100. .driver = { .owner = THIS_MODULE,},
  101. };
  102. static int __init marvell_init(void)
  103. {
  104. return phy_driver_register(&m88e1101_driver);
  105. }
  106. static void __exit marvell_exit(void)
  107. {
  108. phy_driver_unregister(&m88e1101_driver);
  109. }
  110. module_init(marvell_init);
  111. module_exit(marvell_exit);