Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 // Copyright (C) 2016 Broadcom
0003 
0004 #include <linux/device.h>
0005 #include <linux/module.h>
0006 #include <linux/of_mdio.h>
0007 #include <linux/mdio.h>
0008 #include <linux/phy.h>
0009 #include <linux/phy/phy.h>
0010 
0011 #define BLK_ADDR_REG_OFFSET 0x1f
0012 #define PLL_AFE1_100MHZ_BLK 0x2100
0013 #define PLL_CLK_AMP_OFFSET  0x03
0014 #define PLL_CLK_AMP_2P05V   0x2b18
0015 
0016 static int ns2_pci_phy_init(struct phy *p)
0017 {
0018     struct mdio_device *mdiodev = phy_get_drvdata(p);
0019     int rc;
0020 
0021     /* select the AFE 100MHz block page */
0022     rc = mdiodev_write(mdiodev, BLK_ADDR_REG_OFFSET, PLL_AFE1_100MHZ_BLK);
0023     if (rc)
0024         goto err;
0025 
0026     /* set the 100 MHz reference clock amplitude to 2.05 v */
0027     rc = mdiodev_write(mdiodev, PLL_CLK_AMP_OFFSET, PLL_CLK_AMP_2P05V);
0028     if (rc)
0029         goto err;
0030 
0031     return 0;
0032 
0033 err:
0034     dev_err(&mdiodev->dev, "Error %d writing to phy\n", rc);
0035     return rc;
0036 }
0037 
0038 static const struct phy_ops ns2_pci_phy_ops = {
0039     .init = ns2_pci_phy_init,
0040     .owner = THIS_MODULE,
0041 };
0042 
0043 static int ns2_pci_phy_probe(struct mdio_device *mdiodev)
0044 {
0045     struct device *dev = &mdiodev->dev;
0046     struct phy_provider *provider;
0047     struct phy *phy;
0048 
0049     phy = devm_phy_create(dev, dev->of_node, &ns2_pci_phy_ops);
0050     if (IS_ERR(phy)) {
0051         dev_err(dev, "failed to create Phy\n");
0052         return PTR_ERR(phy);
0053     }
0054 
0055     phy_set_drvdata(phy, mdiodev);
0056 
0057     provider = devm_of_phy_provider_register(&phy->dev,
0058                          of_phy_simple_xlate);
0059     if (IS_ERR(provider)) {
0060         dev_err(dev, "failed to register Phy provider\n");
0061         return PTR_ERR(provider);
0062     }
0063 
0064     dev_info(dev, "%s PHY registered\n", dev_name(dev));
0065 
0066     return 0;
0067 }
0068 
0069 static const struct of_device_id ns2_pci_phy_of_match[] = {
0070     { .compatible = "brcm,ns2-pcie-phy", },
0071     { /* sentinel */ },
0072 };
0073 MODULE_DEVICE_TABLE(of, ns2_pci_phy_of_match);
0074 
0075 static struct mdio_driver ns2_pci_phy_driver = {
0076     .mdiodrv = {
0077         .driver = {
0078             .name = "phy-bcm-ns2-pci",
0079             .of_match_table = ns2_pci_phy_of_match,
0080         },
0081     },
0082     .probe = ns2_pci_phy_probe,
0083 };
0084 mdio_module_driver(ns2_pci_phy_driver);
0085 
0086 MODULE_AUTHOR("Broadcom");
0087 MODULE_DESCRIPTION("Broadcom Northstar2 PCI Phy driver");
0088 MODULE_LICENSE("GPL v2");
0089 MODULE_ALIAS("platform:phy-bcm-ns2-pci");