vitesse.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Driver for Vitesse PHYs
  3. *
  4. * Author: Kriston Carson
  5. *
  6. * Copyright (c) 2005 Freescale Semiconductor, Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. */
  14. #include <linux/config.h>
  15. #include <linux/kernel.h>
  16. #include <linux/module.h>
  17. #include <linux/mii.h>
  18. #include <linux/ethtool.h>
  19. #include <linux/phy.h>
  20. /* Vitesse Extended Control Register 1 */
  21. #define MII_VSC8244_EXT_CON1 0x17
  22. #define MII_VSC8244_EXTCON1_INIT 0x0000
  23. /* Vitesse Interrupt Mask Register */
  24. #define MII_VSC8244_IMASK 0x19
  25. #define MII_VSC8244_IMASK_IEN 0x8000
  26. #define MII_VSC8244_IMASK_SPEED 0x4000
  27. #define MII_VSC8244_IMASK_LINK 0x2000
  28. #define MII_VSC8244_IMASK_DUPLEX 0x1000
  29. #define MII_VSC8244_IMASK_MASK 0xf000
  30. /* Vitesse Interrupt Status Register */
  31. #define MII_VSC8244_ISTAT 0x1a
  32. #define MII_VSC8244_ISTAT_STATUS 0x8000
  33. #define MII_VSC8244_ISTAT_SPEED 0x4000
  34. #define MII_VSC8244_ISTAT_LINK 0x2000
  35. #define MII_VSC8244_ISTAT_DUPLEX 0x1000
  36. /* Vitesse Auxiliary Control/Status Register */
  37. #define MII_VSC8244_AUX_CONSTAT 0x1c
  38. #define MII_VSC8244_AUXCONSTAT_INIT 0x0004
  39. #define MII_VSC8244_AUXCONSTAT_DUPLEX 0x0020
  40. #define MII_VSC8244_AUXCONSTAT_SPEED 0x0018
  41. #define MII_VSC8244_AUXCONSTAT_GBIT 0x0010
  42. #define MII_VSC8244_AUXCONSTAT_100 0x0008
  43. MODULE_DESCRIPTION("Vitesse PHY driver");
  44. MODULE_AUTHOR("Kriston Carson");
  45. MODULE_LICENSE("GPL");
  46. static int vsc824x_config_init(struct phy_device *phydev)
  47. {
  48. int err;
  49. err = phy_write(phydev, MII_VSC8244_AUX_CONSTAT,
  50. MII_VSC8244_AUXCONSTAT_INIT);
  51. if (err < 0)
  52. return err;
  53. err = phy_write(phydev, MII_VSC8244_EXT_CON1,
  54. MII_VSC8244_EXTCON1_INIT);
  55. return err;
  56. }
  57. static int vsc824x_ack_interrupt(struct phy_device *phydev)
  58. {
  59. int err = phy_read(phydev, MII_VSC8244_ISTAT);
  60. return (err < 0) ? err : 0;
  61. }
  62. static int vsc824x_config_intr(struct phy_device *phydev)
  63. {
  64. int err;
  65. if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
  66. err = phy_write(phydev, MII_VSC8244_IMASK,
  67. MII_VSC8244_IMASK_MASK);
  68. else
  69. err = phy_write(phydev, MII_VSC8244_IMASK, 0);
  70. return err;
  71. }
  72. /* Vitesse 824x */
  73. static struct phy_driver vsc8244_driver = {
  74. .phy_id = 0x000fc6c2,
  75. .name = "Vitesse VSC8244",
  76. .phy_id_mask = 0x000fffc0,
  77. .features = PHY_GBIT_FEATURES,
  78. .flags = PHY_HAS_INTERRUPT,
  79. .config_init = &vsc824x_config_init,
  80. .config_aneg = &genphy_config_aneg,
  81. .read_status = &genphy_read_status,
  82. .ack_interrupt = &vsc824x_ack_interrupt,
  83. .config_intr = &vsc824x_config_intr,
  84. .driver = { .owner = THIS_MODULE,},
  85. };
  86. static int __init vsc8244_init(void)
  87. {
  88. return phy_driver_register(&vsc8244_driver);
  89. }
  90. static void __exit vsc8244_exit(void)
  91. {
  92. phy_driver_unregister(&vsc8244_driver);
  93. }
  94. module_init(vsc8244_init);
  95. module_exit(vsc8244_exit);