icplus.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Driver for ICPlus PHYs
  3. *
  4. * Copyright (c) 2007 Freescale Semiconductor, Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. *
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/string.h>
  14. #include <linux/errno.h>
  15. #include <linux/unistd.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/init.h>
  18. #include <linux/delay.h>
  19. #include <linux/netdevice.h>
  20. #include <linux/etherdevice.h>
  21. #include <linux/skbuff.h>
  22. #include <linux/spinlock.h>
  23. #include <linux/mm.h>
  24. #include <linux/module.h>
  25. #include <linux/mii.h>
  26. #include <linux/ethtool.h>
  27. #include <linux/phy.h>
  28. #include <asm/io.h>
  29. #include <asm/irq.h>
  30. #include <asm/uaccess.h>
  31. MODULE_DESCRIPTION("ICPlus IP175C PHY driver");
  32. MODULE_AUTHOR("Michael Barkowski");
  33. MODULE_LICENSE("GPL");
  34. static int ip175c_config_init(struct phy_device *phydev)
  35. {
  36. int err, i;
  37. static int full_reset_performed = 0;
  38. if (full_reset_performed == 0) {
  39. /* master reset */
  40. err = phydev->bus->write(phydev->bus, 30, 0, 0x175c);
  41. if (err < 0)
  42. return err;
  43. /* ensure no bus delays overlap reset period */
  44. err = phydev->bus->read(phydev->bus, 30, 0);
  45. /* data sheet specifies reset period is 2 msec */
  46. mdelay(2);
  47. /* enable IP175C mode */
  48. err = phydev->bus->write(phydev->bus, 29, 31, 0x175c);
  49. if (err < 0)
  50. return err;
  51. /* Set MII0 speed and duplex (in PHY mode) */
  52. err = phydev->bus->write(phydev->bus, 29, 22, 0x420);
  53. if (err < 0)
  54. return err;
  55. /* reset switch ports */
  56. for (i = 0; i < 5; i++) {
  57. err = phydev->bus->write(phydev->bus, i,
  58. MII_BMCR, BMCR_RESET);
  59. if (err < 0)
  60. return err;
  61. }
  62. for (i = 0; i < 5; i++)
  63. err = phydev->bus->read(phydev->bus, i, MII_BMCR);
  64. mdelay(2);
  65. full_reset_performed = 1;
  66. }
  67. if (phydev->addr != 4) {
  68. phydev->state = PHY_RUNNING;
  69. phydev->speed = SPEED_100;
  70. phydev->duplex = DUPLEX_FULL;
  71. phydev->link = 1;
  72. netif_carrier_on(phydev->attached_dev);
  73. }
  74. return 0;
  75. }
  76. static int ip175c_read_status(struct phy_device *phydev)
  77. {
  78. if (phydev->addr == 4) /* WAN port */
  79. genphy_read_status(phydev);
  80. else
  81. /* Don't need to read status for switch ports */
  82. phydev->irq = PHY_IGNORE_INTERRUPT;
  83. return 0;
  84. }
  85. static int ip175c_config_aneg(struct phy_device *phydev)
  86. {
  87. if (phydev->addr == 4) /* WAN port */
  88. genphy_config_aneg(phydev);
  89. return 0;
  90. }
  91. static struct phy_driver ip175c_driver = {
  92. .phy_id = 0x02430d80,
  93. .name = "ICPlus IP175C",
  94. .phy_id_mask = 0x0ffffff0,
  95. .features = PHY_BASIC_FEATURES,
  96. .config_init = &ip175c_config_init,
  97. .config_aneg = &ip175c_config_aneg,
  98. .read_status = &ip175c_read_status,
  99. .driver = { .owner = THIS_MODULE,},
  100. };
  101. static int __init ip175c_init(void)
  102. {
  103. return phy_driver_register(&ip175c_driver);
  104. }
  105. static void __exit ip175c_exit(void)
  106. {
  107. phy_driver_unregister(&ip175c_driver);
  108. }
  109. module_init(ip175c_init);
  110. module_exit(ip175c_exit);