2 * Copyright (C) 2016 Broadcom
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.
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.
14 #include <linux/device.h>
15 #include <linux/module.h>
16 #include <linux/of_mdio.h>
17 #include <linux/mdio.h>
18 #include <linux/phy.h>
19 #include <linux/phy/phy.h>
22 struct mdio_device *mdiodev;
26 #define BLK_ADDR_REG_OFFSET 0x1f
27 #define PLL_AFE1_100MHZ_BLK 0x2100
28 #define PLL_CLK_AMP_OFFSET 0x03
29 #define PLL_CLK_AMP_2P05V 0x2b18
31 static int ns2_pci_phy_init(struct phy *p)
33 struct ns2_pci_phy *phy = phy_get_drvdata(p);
36 /* select the AFE 100MHz block page */
37 rc = mdiobus_write(phy->mdiodev->bus, phy->mdiodev->addr,
38 BLK_ADDR_REG_OFFSET, PLL_AFE1_100MHZ_BLK);
42 /* set the 100 MHz reference clock amplitude to 2.05 v */
43 rc = mdiobus_write(phy->mdiodev->bus, phy->mdiodev->addr,
44 PLL_CLK_AMP_OFFSET, PLL_CLK_AMP_2P05V);
51 dev_err(&phy->mdiodev->dev, "Error %d writing to phy\n", rc);
55 static struct phy_ops ns2_pci_phy_ops = {
56 .init = ns2_pci_phy_init,
59 static int ns2_pci_phy_probe(struct mdio_device *mdiodev)
61 struct device *dev = &mdiodev->dev;
62 struct phy_provider *provider;
63 struct ns2_pci_phy *p;
66 phy = devm_phy_create(dev, dev->of_node, &ns2_pci_phy_ops);
68 dev_err(dev, "failed to create Phy\n");
72 p = devm_kmalloc(dev, sizeof(struct ns2_pci_phy),
78 dev_set_drvdata(dev, p);
81 phy_set_drvdata(phy, p);
83 provider = devm_of_phy_provider_register(&phy->dev,
85 if (IS_ERR(provider)) {
86 dev_err(dev, "failed to register Phy provider\n");
87 return PTR_ERR(provider);
90 dev_info(dev, "%s PHY registered\n", dev_name(dev));
95 static const struct of_device_id ns2_pci_phy_of_match[] = {
96 { .compatible = "brcm,ns2-pcie-phy", },
99 MODULE_DEVICE_TABLE(of, ns2_pci_phy_of_match);
101 static struct mdio_driver ns2_pci_phy_driver = {
104 .name = "phy-bcm-ns2-pci",
105 .of_match_table = ns2_pci_phy_of_match,
108 .probe = ns2_pci_phy_probe,
110 mdio_module_driver(ns2_pci_phy_driver);
112 MODULE_AUTHOR("Broadcom");
113 MODULE_DESCRIPTION("Broadcom Northstar2 PCI Phy driver");
114 MODULE_LICENSE("GPL v2");
115 MODULE_ALIAS("platform:phy-bcm-ns2-pci");