phy-bcm-ns2-pcie.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. // Copyright (C) 2016 Broadcom
  3. #include <linux/device.h>
  4. #include <linux/module.h>
  5. #include <linux/of_mdio.h>
  6. #include <linux/mdio.h>
  7. #include <linux/phy.h>
  8. #include <linux/phy/phy.h>
  9. #define BLK_ADDR_REG_OFFSET 0x1f
  10. #define PLL_AFE1_100MHZ_BLK 0x2100
  11. #define PLL_CLK_AMP_OFFSET 0x03
  12. #define PLL_CLK_AMP_2P05V 0x2b18
  13. static int ns2_pci_phy_init(struct phy *p)
  14. {
  15. struct mdio_device *mdiodev = phy_get_drvdata(p);
  16. int rc;
  17. /* select the AFE 100MHz block page */
  18. rc = mdiodev_write(mdiodev, BLK_ADDR_REG_OFFSET, PLL_AFE1_100MHZ_BLK);
  19. if (rc)
  20. goto err;
  21. /* set the 100 MHz reference clock amplitude to 2.05 v */
  22. rc = mdiodev_write(mdiodev, PLL_CLK_AMP_OFFSET, PLL_CLK_AMP_2P05V);
  23. if (rc)
  24. goto err;
  25. return 0;
  26. err:
  27. dev_err(&mdiodev->dev, "Error %d writing to phy\n", rc);
  28. return rc;
  29. }
  30. static const struct phy_ops ns2_pci_phy_ops = {
  31. .init = ns2_pci_phy_init,
  32. .owner = THIS_MODULE,
  33. };
  34. static int ns2_pci_phy_probe(struct mdio_device *mdiodev)
  35. {
  36. struct device *dev = &mdiodev->dev;
  37. struct phy_provider *provider;
  38. struct phy *phy;
  39. phy = devm_phy_create(dev, dev->of_node, &ns2_pci_phy_ops);
  40. if (IS_ERR(phy)) {
  41. dev_err(dev, "failed to create Phy\n");
  42. return PTR_ERR(phy);
  43. }
  44. phy_set_drvdata(phy, mdiodev);
  45. provider = devm_of_phy_provider_register(&phy->dev,
  46. of_phy_simple_xlate);
  47. if (IS_ERR(provider)) {
  48. dev_err(dev, "failed to register Phy provider\n");
  49. return PTR_ERR(provider);
  50. }
  51. dev_info(dev, "%s PHY registered\n", dev_name(dev));
  52. return 0;
  53. }
  54. static const struct of_device_id ns2_pci_phy_of_match[] = {
  55. { .compatible = "brcm,ns2-pcie-phy", },
  56. { /* sentinel */ },
  57. };
  58. MODULE_DEVICE_TABLE(of, ns2_pci_phy_of_match);
  59. static struct mdio_driver ns2_pci_phy_driver = {
  60. .mdiodrv = {
  61. .driver = {
  62. .name = "phy-bcm-ns2-pci",
  63. .of_match_table = ns2_pci_phy_of_match,
  64. },
  65. },
  66. .probe = ns2_pci_phy_probe,
  67. };
  68. mdio_module_driver(ns2_pci_phy_driver);
  69. MODULE_AUTHOR("Broadcom");
  70. MODULE_DESCRIPTION("Broadcom Northstar2 PCI Phy driver");
  71. MODULE_LICENSE("GPL v2");
  72. MODULE_ALIAS("platform:phy-bcm-ns2-pci");