Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Samsung Exynos SoC series PCIe PHY driver
0004  *
0005  * Phy provider for PCIe controller on Exynos SoC series
0006  *
0007  * Copyright (C) 2017-2020 Samsung Electronics Co., Ltd.
0008  * Jaehoon Chung <jh80.chung@samsung.com>
0009  */
0010 
0011 #include <linux/io.h>
0012 #include <linux/mfd/syscon.h>
0013 #include <linux/of_platform.h>
0014 #include <linux/platform_device.h>
0015 #include <linux/phy/phy.h>
0016 #include <linux/regmap.h>
0017 
0018 #define PCIE_PHY_OFFSET(x)      ((x) * 0x4)
0019 
0020 /* Sysreg FSYS register offsets and bits for Exynos5433 */
0021 #define PCIE_EXYNOS5433_PHY_MAC_RESET       0x0208
0022 #define PCIE_MAC_RESET_MASK         0xFF
0023 #define PCIE_MAC_RESET              BIT(4)
0024 #define PCIE_EXYNOS5433_PHY_L1SUB_CM_CON    0x1010
0025 #define PCIE_REFCLK_GATING_EN           BIT(0)
0026 #define PCIE_EXYNOS5433_PHY_COMMON_RESET    0x1020
0027 #define PCIE_PHY_RESET              BIT(0)
0028 #define PCIE_EXYNOS5433_PHY_GLOBAL_RESET    0x1040
0029 #define PCIE_GLOBAL_RESET           BIT(0)
0030 #define PCIE_REFCLK             BIT(1)
0031 #define PCIE_REFCLK_MASK            0x16
0032 #define PCIE_APP_REQ_EXIT_L1_MODE       BIT(5)
0033 
0034 /* PMU PCIE PHY isolation control */
0035 #define EXYNOS5433_PMU_PCIE_PHY_OFFSET      0x730
0036 
0037 /* For Exynos pcie phy */
0038 struct exynos_pcie_phy {
0039     void __iomem *base;
0040     struct regmap *pmureg;
0041     struct regmap *fsysreg;
0042 };
0043 
0044 static void exynos_pcie_phy_writel(void __iomem *base, u32 val, u32 offset)
0045 {
0046     writel(val, base + offset);
0047 }
0048 
0049 /* Exynos5433 specific functions */
0050 static int exynos5433_pcie_phy_init(struct phy *phy)
0051 {
0052     struct exynos_pcie_phy *ep = phy_get_drvdata(phy);
0053 
0054     regmap_update_bits(ep->pmureg, EXYNOS5433_PMU_PCIE_PHY_OFFSET,
0055                BIT(0), 1);
0056     regmap_update_bits(ep->fsysreg, PCIE_EXYNOS5433_PHY_GLOBAL_RESET,
0057                PCIE_APP_REQ_EXIT_L1_MODE, 0);
0058     regmap_update_bits(ep->fsysreg, PCIE_EXYNOS5433_PHY_L1SUB_CM_CON,
0059                PCIE_REFCLK_GATING_EN, 0);
0060 
0061     regmap_update_bits(ep->fsysreg, PCIE_EXYNOS5433_PHY_COMMON_RESET,
0062                PCIE_PHY_RESET, 1);
0063     regmap_update_bits(ep->fsysreg, PCIE_EXYNOS5433_PHY_MAC_RESET,
0064                PCIE_MAC_RESET, 0);
0065 
0066     /* PHY refclk 24MHz */
0067     regmap_update_bits(ep->fsysreg, PCIE_EXYNOS5433_PHY_GLOBAL_RESET,
0068                PCIE_REFCLK_MASK, PCIE_REFCLK);
0069     regmap_update_bits(ep->fsysreg, PCIE_EXYNOS5433_PHY_GLOBAL_RESET,
0070                PCIE_GLOBAL_RESET, 0);
0071 
0072 
0073     exynos_pcie_phy_writel(ep->base, 0x11, PCIE_PHY_OFFSET(0x3));
0074 
0075     /* band gap reference on */
0076     exynos_pcie_phy_writel(ep->base, 0, PCIE_PHY_OFFSET(0x20));
0077     exynos_pcie_phy_writel(ep->base, 0, PCIE_PHY_OFFSET(0x4b));
0078 
0079     /* jitter tuning */
0080     exynos_pcie_phy_writel(ep->base, 0x34, PCIE_PHY_OFFSET(0x4));
0081     exynos_pcie_phy_writel(ep->base, 0x02, PCIE_PHY_OFFSET(0x7));
0082     exynos_pcie_phy_writel(ep->base, 0x41, PCIE_PHY_OFFSET(0x21));
0083     exynos_pcie_phy_writel(ep->base, 0x7F, PCIE_PHY_OFFSET(0x14));
0084     exynos_pcie_phy_writel(ep->base, 0xC0, PCIE_PHY_OFFSET(0x15));
0085     exynos_pcie_phy_writel(ep->base, 0x61, PCIE_PHY_OFFSET(0x36));
0086 
0087     /* D0 uninit.. */
0088     exynos_pcie_phy_writel(ep->base, 0x44, PCIE_PHY_OFFSET(0x3D));
0089 
0090     /* 24MHz */
0091     exynos_pcie_phy_writel(ep->base, 0x94, PCIE_PHY_OFFSET(0x8));
0092     exynos_pcie_phy_writel(ep->base, 0xA7, PCIE_PHY_OFFSET(0x9));
0093     exynos_pcie_phy_writel(ep->base, 0x93, PCIE_PHY_OFFSET(0xA));
0094     exynos_pcie_phy_writel(ep->base, 0x6B, PCIE_PHY_OFFSET(0xC));
0095     exynos_pcie_phy_writel(ep->base, 0xA5, PCIE_PHY_OFFSET(0xF));
0096     exynos_pcie_phy_writel(ep->base, 0x34, PCIE_PHY_OFFSET(0x16));
0097     exynos_pcie_phy_writel(ep->base, 0xA3, PCIE_PHY_OFFSET(0x17));
0098     exynos_pcie_phy_writel(ep->base, 0xA7, PCIE_PHY_OFFSET(0x1A));
0099     exynos_pcie_phy_writel(ep->base, 0x71, PCIE_PHY_OFFSET(0x23));
0100     exynos_pcie_phy_writel(ep->base, 0x4C, PCIE_PHY_OFFSET(0x24));
0101 
0102     exynos_pcie_phy_writel(ep->base, 0x0E, PCIE_PHY_OFFSET(0x26));
0103     exynos_pcie_phy_writel(ep->base, 0x14, PCIE_PHY_OFFSET(0x7));
0104     exynos_pcie_phy_writel(ep->base, 0x48, PCIE_PHY_OFFSET(0x43));
0105     exynos_pcie_phy_writel(ep->base, 0x44, PCIE_PHY_OFFSET(0x44));
0106     exynos_pcie_phy_writel(ep->base, 0x03, PCIE_PHY_OFFSET(0x45));
0107     exynos_pcie_phy_writel(ep->base, 0xA7, PCIE_PHY_OFFSET(0x48));
0108     exynos_pcie_phy_writel(ep->base, 0x13, PCIE_PHY_OFFSET(0x54));
0109     exynos_pcie_phy_writel(ep->base, 0x04, PCIE_PHY_OFFSET(0x31));
0110     exynos_pcie_phy_writel(ep->base, 0, PCIE_PHY_OFFSET(0x32));
0111 
0112     regmap_update_bits(ep->fsysreg, PCIE_EXYNOS5433_PHY_COMMON_RESET,
0113                PCIE_PHY_RESET, 0);
0114     regmap_update_bits(ep->fsysreg, PCIE_EXYNOS5433_PHY_MAC_RESET,
0115                PCIE_MAC_RESET_MASK, PCIE_MAC_RESET);
0116     return 0;
0117 }
0118 
0119 static int exynos5433_pcie_phy_exit(struct phy *phy)
0120 {
0121     struct exynos_pcie_phy *ep = phy_get_drvdata(phy);
0122 
0123     regmap_update_bits(ep->fsysreg, PCIE_EXYNOS5433_PHY_L1SUB_CM_CON,
0124                PCIE_REFCLK_GATING_EN, PCIE_REFCLK_GATING_EN);
0125     regmap_update_bits(ep->pmureg, EXYNOS5433_PMU_PCIE_PHY_OFFSET,
0126                BIT(0), 0);
0127     return 0;
0128 }
0129 
0130 static const struct phy_ops exynos5433_phy_ops = {
0131     .init       = exynos5433_pcie_phy_init,
0132     .exit       = exynos5433_pcie_phy_exit,
0133     .owner      = THIS_MODULE,
0134 };
0135 
0136 static const struct of_device_id exynos_pcie_phy_match[] = {
0137     {
0138         .compatible = "samsung,exynos5433-pcie-phy",
0139     },
0140     {},
0141 };
0142 
0143 static int exynos_pcie_phy_probe(struct platform_device *pdev)
0144 {
0145     struct device *dev = &pdev->dev;
0146     struct exynos_pcie_phy *exynos_phy;
0147     struct phy *generic_phy;
0148     struct phy_provider *phy_provider;
0149 
0150     exynos_phy = devm_kzalloc(dev, sizeof(*exynos_phy), GFP_KERNEL);
0151     if (!exynos_phy)
0152         return -ENOMEM;
0153 
0154     exynos_phy->base = devm_platform_ioremap_resource(pdev, 0);
0155     if (IS_ERR(exynos_phy->base))
0156         return PTR_ERR(exynos_phy->base);
0157 
0158     exynos_phy->pmureg = syscon_regmap_lookup_by_phandle(dev->of_node,
0159                             "samsung,pmu-syscon");
0160     if (IS_ERR(exynos_phy->pmureg)) {
0161         dev_err(&pdev->dev, "PMU regmap lookup failed.\n");
0162         return PTR_ERR(exynos_phy->pmureg);
0163     }
0164 
0165     exynos_phy->fsysreg = syscon_regmap_lookup_by_phandle(dev->of_node,
0166                              "samsung,fsys-sysreg");
0167     if (IS_ERR(exynos_phy->fsysreg)) {
0168         dev_err(&pdev->dev, "FSYS sysreg regmap lookup failed.\n");
0169         return PTR_ERR(exynos_phy->fsysreg);
0170     }
0171 
0172     generic_phy = devm_phy_create(dev, dev->of_node, &exynos5433_phy_ops);
0173     if (IS_ERR(generic_phy)) {
0174         dev_err(dev, "failed to create PHY\n");
0175         return PTR_ERR(generic_phy);
0176     }
0177 
0178     phy_set_drvdata(generic_phy, exynos_phy);
0179     phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
0180 
0181     return PTR_ERR_OR_ZERO(phy_provider);
0182 }
0183 
0184 static struct platform_driver exynos_pcie_phy_driver = {
0185     .probe  = exynos_pcie_phy_probe,
0186     .driver = {
0187         .of_match_table = exynos_pcie_phy_match,
0188         .name       = "exynos_pcie_phy",
0189         .suppress_bind_attrs = true,
0190     }
0191 };
0192 builtin_platform_driver(exynos_pcie_phy_driver);