amd.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Driver for AMD am79c PHYs
  3. *
  4. * Author: Heiko Schocher <hs@denx.de>
  5. *
  6. * Copyright (c) 2011 DENX Software Engineering GmbH
  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/kernel.h>
  15. #include <linux/errno.h>
  16. #include <linux/init.h>
  17. #include <linux/module.h>
  18. #include <linux/mii.h>
  19. #include <linux/phy.h>
  20. #define PHY_ID_AM79C874 0x0022561b
  21. #define MII_AM79C_IR 17 /* Interrupt Status/Control Register */
  22. #define MII_AM79C_IR_EN_LINK 0x0400 /* IR enable Linkstate */
  23. #define MII_AM79C_IR_EN_ANEG 0x0100 /* IR enable Aneg Complete */
  24. #define MII_AM79C_IR_IMASK_INIT (MII_AM79C_IR_EN_LINK | MII_AM79C_IR_EN_ANEG)
  25. MODULE_DESCRIPTION("AMD PHY driver");
  26. MODULE_AUTHOR("Heiko Schocher <hs@denx.de>");
  27. MODULE_LICENSE("GPL");
  28. static int am79c_ack_interrupt(struct phy_device *phydev)
  29. {
  30. int err;
  31. err = phy_read(phydev, MII_BMSR);
  32. if (err < 0)
  33. return err;
  34. err = phy_read(phydev, MII_AM79C_IR);
  35. if (err < 0)
  36. return err;
  37. return 0;
  38. }
  39. static int am79c_config_init(struct phy_device *phydev)
  40. {
  41. return 0;
  42. }
  43. static int am79c_config_intr(struct phy_device *phydev)
  44. {
  45. int err;
  46. if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
  47. err = phy_write(phydev, MII_AM79C_IR, MII_AM79C_IR_IMASK_INIT);
  48. else
  49. err = phy_write(phydev, MII_AM79C_IR, 0);
  50. return err;
  51. }
  52. static struct phy_driver am79c_driver = {
  53. .phy_id = PHY_ID_AM79C874,
  54. .name = "AM79C874",
  55. .phy_id_mask = 0xfffffff0,
  56. .features = PHY_BASIC_FEATURES,
  57. .flags = PHY_HAS_INTERRUPT,
  58. .config_init = am79c_config_init,
  59. .config_aneg = genphy_config_aneg,
  60. .read_status = genphy_read_status,
  61. .ack_interrupt = am79c_ack_interrupt,
  62. .config_intr = am79c_config_intr,
  63. .driver = { .owner = THIS_MODULE,},
  64. };
  65. static int __init am79c_init(void)
  66. {
  67. int ret;
  68. ret = phy_driver_register(&am79c_driver);
  69. if (ret)
  70. return ret;
  71. return 0;
  72. }
  73. static void __exit am79c_exit(void)
  74. {
  75. phy_driver_unregister(&am79c_driver);
  76. }
  77. module_init(am79c_init);
  78. module_exit(am79c_exit);
  79. static struct mdio_device_id __maybe_unused amd_tbl[] = {
  80. { PHY_ID_AM79C874, 0xfffffff0 },
  81. { }
  82. };
  83. MODULE_DEVICE_TABLE(mdio, amd_tbl);