icplus.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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/slab.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/init.h>
  19. #include <linux/delay.h>
  20. #include <linux/netdevice.h>
  21. #include <linux/etherdevice.h>
  22. #include <linux/skbuff.h>
  23. #include <linux/spinlock.h>
  24. #include <linux/mm.h>
  25. #include <linux/module.h>
  26. #include <linux/mii.h>
  27. #include <linux/ethtool.h>
  28. #include <linux/phy.h>
  29. #include <asm/io.h>
  30. #include <asm/irq.h>
  31. #include <asm/uaccess.h>
  32. MODULE_DESCRIPTION("ICPlus IP175C PHY driver");
  33. MODULE_AUTHOR("Michael Barkowski");
  34. MODULE_LICENSE("GPL");
  35. static int ip175c_config_init(struct phy_device *phydev)
  36. {
  37. int err, i;
  38. static int full_reset_performed = 0;
  39. if (full_reset_performed == 0) {
  40. /* master reset */
  41. err = phydev->bus->write(phydev->bus, 30, 0, 0x175c);
  42. if (err < 0)
  43. return err;
  44. /* ensure no bus delays overlap reset period */
  45. err = phydev->bus->read(phydev->bus, 30, 0);
  46. /* data sheet specifies reset period is 2 msec */
  47. mdelay(2);
  48. /* enable IP175C mode */
  49. err = phydev->bus->write(phydev->bus, 29, 31, 0x175c);
  50. if (err < 0)
  51. return err;
  52. /* Set MII0 speed and duplex (in PHY mode) */
  53. err = phydev->bus->write(phydev->bus, 29, 22, 0x420);
  54. if (err < 0)
  55. return err;
  56. /* reset switch ports */
  57. for (i = 0; i < 5; i++) {
  58. err = phydev->bus->write(phydev->bus, i,
  59. MII_BMCR, BMCR_RESET);
  60. if (err < 0)
  61. return err;
  62. }
  63. for (i = 0; i < 5; i++)
  64. err = phydev->bus->read(phydev->bus, i, MII_BMCR);
  65. mdelay(2);
  66. full_reset_performed = 1;
  67. }
  68. if (phydev->addr != 4) {
  69. phydev->state = PHY_RUNNING;
  70. phydev->speed = SPEED_100;
  71. phydev->duplex = DUPLEX_FULL;
  72. phydev->link = 1;
  73. netif_carrier_on(phydev->attached_dev);
  74. }
  75. return 0;
  76. }
  77. static int ip175c_read_status(struct phy_device *phydev)
  78. {
  79. if (phydev->addr == 4) /* WAN port */
  80. genphy_read_status(phydev);
  81. else
  82. /* Don't need to read status for switch ports */
  83. phydev->irq = PHY_IGNORE_INTERRUPT;
  84. return 0;
  85. }
  86. static int ip175c_config_aneg(struct phy_device *phydev)
  87. {
  88. if (phydev->addr == 4) /* WAN port */
  89. genphy_config_aneg(phydev);
  90. return 0;
  91. }
  92. static struct phy_driver ip175c_driver = {
  93. .phy_id = 0x02430d80,
  94. .name = "ICPlus IP175C",
  95. .phy_id_mask = 0x0ffffff0,
  96. .features = PHY_BASIC_FEATURES,
  97. .config_init = &ip175c_config_init,
  98. .config_aneg = &ip175c_config_aneg,
  99. .read_status = &ip175c_read_status,
  100. .driver = { .owner = THIS_MODULE,},
  101. };
  102. static int __init ip175c_init(void)
  103. {
  104. return phy_driver_register(&ip175c_driver);
  105. }
  106. static void __exit ip175c_exit(void)
  107. {
  108. phy_driver_unregister(&ip175c_driver);
  109. }
  110. module_init(ip175c_init);
  111. module_exit(ip175c_exit);