Lines Matching +full:phy +full:- +full:pma
1 // SPDX-License-Identifier: GPL-2.0
3 * Rockchip PCIE3.0 phy driver
16 #include <linux/phy/pcie.h>
17 #include <linux/phy/phy.h>
58 struct phy *phy; member
69 static int rockchip_p3phy_set_mode(struct phy *phy, enum phy_mode mode, int submode) in rockchip_p3phy_set_mode() argument
71 struct rockchip_p3phy_priv *priv = phy_get_drvdata(phy); in rockchip_p3phy_set_mode()
76 priv->mode = PHY_MODE_PCIE_RC; in rockchip_p3phy_set_mode()
79 priv->mode = PHY_MODE_PCIE_EP; in rockchip_p3phy_set_mode()
82 dev_err(&phy->dev, "%s, invalid mode\n", __func__); in rockchip_p3phy_set_mode()
83 return -EINVAL; in rockchip_p3phy_set_mode()
91 struct phy *phy = priv->phy; in rockchip_p3phy_rk3568_init() local
96 /* Deassert PCIe PMA output clamp mode */ in rockchip_p3phy_rk3568_init()
97 regmap_write(priv->phy_grf, GRF_PCIE30PHY_CON9, GRF_PCIE30PHY_DA_OCM); in rockchip_p3phy_rk3568_init()
99 for (int i = 0; i < priv->num_lanes; i++) { in rockchip_p3phy_rk3568_init()
100 dev_info(&phy->dev, "lane number %d, val %d\n", i, priv->lanes[i]); in rockchip_p3phy_rk3568_init()
101 if (priv->lanes[i] > 1) in rockchip_p3phy_rk3568_init()
107 dev_info(&phy->dev, "bifurcation enabled\n"); in rockchip_p3phy_rk3568_init()
108 regmap_write(priv->phy_grf, GRF_PCIE30PHY_CON6, in rockchip_p3phy_rk3568_init()
110 regmap_write(priv->phy_grf, GRF_PCIE30PHY_CON1, in rockchip_p3phy_rk3568_init()
113 dev_dbg(&phy->dev, "bifurcation disabled\n"); in rockchip_p3phy_rk3568_init()
114 regmap_write(priv->phy_grf, GRF_PCIE30PHY_CON6, in rockchip_p3phy_rk3568_init()
118 reset_control_deassert(priv->p30phy); in rockchip_p3phy_rk3568_init()
120 ret = regmap_read_poll_timeout(priv->phy_grf, in rockchip_p3phy_rk3568_init()
125 dev_err(&priv->phy->dev, "%s: lock failed 0x%x, check input refclk and power supply\n", in rockchip_p3phy_rk3568_init()
140 /* Deassert PCIe PMA output clamp mode */ in rockchip_p3phy_rk3588_init()
141 regmap_write(priv->phy_grf, RK3588_PCIE3PHY_GRF_CMN_CON0, BIT(8) | BIT(24)); in rockchip_p3phy_rk3588_init()
144 for (int i = 0; i < priv->num_lanes; i++) { in rockchip_p3phy_rk3588_init()
145 if (priv->lanes[i] > 1) in rockchip_p3phy_rk3588_init()
147 if (priv->lanes[i] == 3) in rockchip_p3phy_rk3588_init()
149 if (priv->lanes[i] == 4) in rockchip_p3phy_rk3588_init()
154 regmap_write(priv->phy_grf, RK3588_PCIE3PHY_GRF_CMN_CON0, in rockchip_p3phy_rk3588_init()
158 if (!IS_ERR(priv->pipe_grf)) { in rockchip_p3phy_rk3588_init()
161 regmap_write(priv->pipe_grf, PHP_GRF_PCIESEL_CON, in rockchip_p3phy_rk3588_init()
165 reset_control_deassert(priv->p30phy); in rockchip_p3phy_rk3588_init()
167 ret = regmap_read_poll_timeout(priv->phy_grf, in rockchip_p3phy_rk3588_init()
171 ret |= regmap_read_poll_timeout(priv->phy_grf, in rockchip_p3phy_rk3588_init()
176 dev_err(&priv->phy->dev, "lock failed 0x%x, check input refclk and power supply\n", in rockchip_p3phy_rk3588_init()
185 static int rochchip_p3phy_init(struct phy *phy) in rochchip_p3phy_init() argument
187 struct rockchip_p3phy_priv *priv = phy_get_drvdata(phy); in rochchip_p3phy_init()
190 ret = clk_bulk_prepare_enable(priv->num_clks, priv->clks); in rochchip_p3phy_init()
192 dev_err(&priv->phy->dev, "failed to enable PCIe bulk clks %d\n", ret); in rochchip_p3phy_init()
196 reset_control_assert(priv->p30phy); in rochchip_p3phy_init()
199 if (priv->ops->phy_init) { in rochchip_p3phy_init()
200 ret = priv->ops->phy_init(priv); in rochchip_p3phy_init()
202 clk_bulk_disable_unprepare(priv->num_clks, priv->clks); in rochchip_p3phy_init()
208 static int rochchip_p3phy_exit(struct phy *phy) in rochchip_p3phy_exit() argument
210 struct rockchip_p3phy_priv *priv = phy_get_drvdata(phy); in rochchip_p3phy_exit()
212 clk_bulk_disable_unprepare(priv->num_clks, priv->clks); in rochchip_p3phy_exit()
213 reset_control_assert(priv->p30phy); in rochchip_p3phy_exit()
227 struct device *dev = &pdev->dev; in rockchip_p3phy_probe()
229 struct device_node *np = dev->of_node; in rockchip_p3phy_probe()
234 return -ENOMEM; in rockchip_p3phy_probe()
236 priv->mmio = devm_platform_get_and_ioremap_resource(pdev, 0, NULL); in rockchip_p3phy_probe()
237 if (IS_ERR(priv->mmio)) { in rockchip_p3phy_probe()
238 ret = PTR_ERR(priv->mmio); in rockchip_p3phy_probe()
242 priv->ops = of_device_get_match_data(&pdev->dev); in rockchip_p3phy_probe()
243 if (!priv->ops) { in rockchip_p3phy_probe()
245 return -EINVAL; in rockchip_p3phy_probe()
248 priv->phy_grf = syscon_regmap_lookup_by_phandle(np, "rockchip,phy-grf"); in rockchip_p3phy_probe()
249 if (IS_ERR(priv->phy_grf)) { in rockchip_p3phy_probe()
251 return PTR_ERR(priv->phy_grf); in rockchip_p3phy_probe()
254 if (of_device_is_compatible(np, "rockchip,rk3588-pcie3-phy")) { in rockchip_p3phy_probe()
255 priv->pipe_grf = in rockchip_p3phy_probe()
256 syscon_regmap_lookup_by_phandle(dev->of_node, in rockchip_p3phy_probe()
257 "rockchip,pipe-grf"); in rockchip_p3phy_probe()
258 if (IS_ERR(priv->pipe_grf)) in rockchip_p3phy_probe()
261 priv->pipe_grf = NULL; in rockchip_p3phy_probe()
264 priv->num_lanes = of_property_read_variable_u32_array(dev->of_node, "data-lanes", in rockchip_p3phy_probe()
265 priv->lanes, 2, in rockchip_p3phy_probe()
266 ARRAY_SIZE(priv->lanes)); in rockchip_p3phy_probe()
268 /* if no data-lanes assume aggregation */ in rockchip_p3phy_probe()
269 if (priv->num_lanes == -EINVAL) { in rockchip_p3phy_probe()
270 dev_dbg(dev, "no data-lanes property found\n"); in rockchip_p3phy_probe()
271 priv->num_lanes = 1; in rockchip_p3phy_probe()
272 priv->lanes[0] = 1; in rockchip_p3phy_probe()
273 } else if (priv->num_lanes < 0) { in rockchip_p3phy_probe()
274 dev_err(dev, "failed to read data-lanes property %d\n", priv->num_lanes); in rockchip_p3phy_probe()
275 return priv->num_lanes; in rockchip_p3phy_probe()
278 priv->phy = devm_phy_create(dev, NULL, &rochchip_p3phy_ops); in rockchip_p3phy_probe()
279 if (IS_ERR(priv->phy)) { in rockchip_p3phy_probe()
281 return PTR_ERR(priv->phy); in rockchip_p3phy_probe()
284 priv->p30phy = devm_reset_control_get_optional_exclusive(dev, "phy"); in rockchip_p3phy_probe()
285 if (IS_ERR(priv->p30phy)) { in rockchip_p3phy_probe()
286 return dev_err_probe(dev, PTR_ERR(priv->p30phy), in rockchip_p3phy_probe()
287 "failed to get phy reset control\n"); in rockchip_p3phy_probe()
289 if (!priv->p30phy) in rockchip_p3phy_probe()
290 dev_info(dev, "no phy reset control specified\n"); in rockchip_p3phy_probe()
292 priv->num_clks = devm_clk_bulk_get_all(dev, &priv->clks); in rockchip_p3phy_probe()
293 if (priv->num_clks < 1) in rockchip_p3phy_probe()
294 return -ENODEV; in rockchip_p3phy_probe()
297 phy_set_drvdata(priv->phy, priv); in rockchip_p3phy_probe()
303 { .compatible = "rockchip,rk3568-pcie3-phy", .data = &rk3568_ops },
304 { .compatible = "rockchip,rk3588-pcie3-phy", .data = &rk3588_ops },
312 .name = "rockchip-snps-pcie3-phy",
317 MODULE_DESCRIPTION("Rockchip Synopsys PCIe 3.0 PHY driver");