amd.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. module_phy_driver(am79c_driver);
  66. static struct mdio_device_id __maybe_unused amd_tbl[] = {
  67. { PHY_ID_AM79C874, 0xfffffff0 },
  68. { }
  69. };
  70. MODULE_DEVICE_TABLE(mdio, amd_tbl);