micrel.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Driver for Micrel/Kendin PHYs
  3. *
  4. * Copyright (c) 2008-2009 Gabor Juhos <[email protected]>
  5. * Copyright (C) 2008 Imre Kaloz <[email protected]>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published
  9. * by the Free Software Foundation.
  10. *
  11. */
  12. #include <linux/module.h>
  13. #include <linux/delay.h>
  14. #include <linux/skbuff.h>
  15. #include <linux/phy.h>
  16. #define KSZ_REG_INT_CTRL 0x1b
  17. #define KSZ_INT_LU_EN (1 << 8) /* enable Link Up interrupt */
  18. #define KSZ_INT_RF_EN (1 << 9) /* enable Remote Fault interrupt */
  19. #define KSZ_INT_LD_EN (1 << 10) /* enable Link Down interrupt */
  20. #define KSZ_INT_INIT (KSZ_INT_LU_EN | KSZ_INT_LD_EN)
  21. static int ksz8041_ack_interrupt(struct phy_device *phydev)
  22. {
  23. int err;
  24. err = phy_read(phydev, KSZ_REG_INT_CTRL);
  25. return (err < 0) ? err : 0;
  26. }
  27. static int ksz8041_config_intr(struct phy_device *phydev)
  28. {
  29. int err;
  30. if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
  31. err = phy_write(phydev, KSZ_REG_INT_CTRL,
  32. KSZ_INT_INIT);
  33. else
  34. err = phy_write(phydev, KSZ_REG_INT_CTRL, 0);
  35. return err;
  36. }
  37. static struct phy_driver ksz8041_phy_driver = {
  38. .phy_id = 0x00221512,
  39. .name = "Micrel KSZ8041",
  40. .phy_id_mask = 0x001fffff,
  41. .features = PHY_BASIC_FEATURES,
  42. .flags = PHY_HAS_INTERRUPT,
  43. .config_aneg = genphy_config_aneg,
  44. .read_status = genphy_read_status,
  45. .ack_interrupt = ksz8041_ack_interrupt,
  46. .config_intr = ksz8041_config_intr,
  47. .driver = {
  48. .owner = THIS_MODULE,
  49. },
  50. };
  51. static int __init micrel_phy_init(void)
  52. {
  53. return phy_driver_register(&ksz8041_phy_driver);
  54. }
  55. static void __exit micrel_phy_exit(void)
  56. {
  57. phy_driver_unregister(&ksz8041_phy_driver);
  58. }
  59. #ifdef MODULE
  60. module_init(micrel_phy_init);
  61. module_exit(micrel_phy_exit);
  62. #else
  63. subsys_initcall(micrel_phy_init);
  64. #endif
  65. MODULE_DESCRIPTION("Micrel/Kendin PHY driver");
  66. MODULE_AUTHOR("Gabor Juhos <[email protected]>");
  67. MODULE_AUTHOR("Imre Kaloz <[email protected]>");
  68. MODULE_LICENSE("GPL v2");