phy-bcm-ns2-pcie.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (C) 2016 Broadcom
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation version 2.
  7. *
  8. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  9. * kind, whether express or implied; without even the implied warranty
  10. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include <linux/device.h>
  14. #include <linux/module.h>
  15. #include <linux/of_mdio.h>
  16. #include <linux/mdio.h>
  17. #include <linux/phy.h>
  18. #include <linux/phy/phy.h>
  19. #define BLK_ADDR_REG_OFFSET 0x1f
  20. #define PLL_AFE1_100MHZ_BLK 0x2100
  21. #define PLL_CLK_AMP_OFFSET 0x03
  22. #define PLL_CLK_AMP_2P05V 0x2b18
  23. static int ns2_pci_phy_init(struct phy *p)
  24. {
  25. struct mdio_device *mdiodev = phy_get_drvdata(p);
  26. int rc;
  27. /* select the AFE 100MHz block page */
  28. rc = mdiobus_write(mdiodev->bus, mdiodev->addr,
  29. BLK_ADDR_REG_OFFSET, PLL_AFE1_100MHZ_BLK);
  30. if (rc)
  31. goto err;
  32. /* set the 100 MHz reference clock amplitude to 2.05 v */
  33. rc = mdiobus_write(mdiodev->bus, mdiodev->addr,
  34. PLL_CLK_AMP_OFFSET, PLL_CLK_AMP_2P05V);
  35. if (rc)
  36. goto err;
  37. return 0;
  38. err:
  39. dev_err(&mdiodev->dev, "Error %d writing to phy\n", rc);
  40. return rc;
  41. }
  42. static const struct phy_ops ns2_pci_phy_ops = {
  43. .init = ns2_pci_phy_init,
  44. .owner = THIS_MODULE,
  45. };
  46. static int ns2_pci_phy_probe(struct mdio_device *mdiodev)
  47. {
  48. struct device *dev = &mdiodev->dev;
  49. struct phy_provider *provider;
  50. struct phy *phy;
  51. phy = devm_phy_create(dev, dev->of_node, &ns2_pci_phy_ops);
  52. if (IS_ERR(phy)) {
  53. dev_err(dev, "failed to create Phy\n");
  54. return PTR_ERR(phy);
  55. }
  56. phy_set_drvdata(phy, mdiodev);
  57. provider = devm_of_phy_provider_register(&phy->dev,
  58. of_phy_simple_xlate);
  59. if (IS_ERR(provider)) {
  60. dev_err(dev, "failed to register Phy provider\n");
  61. return PTR_ERR(provider);
  62. }
  63. dev_info(dev, "%s PHY registered\n", dev_name(dev));
  64. return 0;
  65. }
  66. static const struct of_device_id ns2_pci_phy_of_match[] = {
  67. { .compatible = "brcm,ns2-pcie-phy", },
  68. { /* sentinel */ },
  69. };
  70. MODULE_DEVICE_TABLE(of, ns2_pci_phy_of_match);
  71. static struct mdio_driver ns2_pci_phy_driver = {
  72. .mdiodrv = {
  73. .driver = {
  74. .name = "phy-bcm-ns2-pci",
  75. .of_match_table = ns2_pci_phy_of_match,
  76. },
  77. },
  78. .probe = ns2_pci_phy_probe,
  79. };
  80. mdio_module_driver(ns2_pci_phy_driver);
  81. MODULE_AUTHOR("Broadcom");
  82. MODULE_DESCRIPTION("Broadcom Northstar2 PCI Phy driver");
  83. MODULE_LICENSE("GPL v2");
  84. MODULE_ALIAS("platform:phy-bcm-ns2-pci");