Shawn Lin | 6ec62b6 | 2021-01-15 18:01:21 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Rockchip PCIE3.0 phy driver |
| 4 | * |
| 5 | * Copyright (C) 2021 Rockchip Electronics Co., Ltd. |
| 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <clk.h> |
| 10 | #include <dm.h> |
| 11 | #include <generic-phy.h> |
| 12 | #include <regmap.h> |
| 13 | #include <reset-uclass.h> |
| 14 | #include <syscon.h> |
| 15 | #include <asm/io.h> |
| 16 | #include <dm/device_compat.h> |
| 17 | #include <dm/lists.h> |
| 18 | |
| 19 | #define GRF_PCIE30PHY_CON1 0x4 |
| 20 | #define GRF_PCIE30PHY_CON6 0x18 |
| 21 | #define GRF_PCIE30PHY_CON9 0x24 |
| 22 | |
| 23 | /** |
| 24 | * struct rockchip_p3phy_priv - RK DW PCIe PHY state |
| 25 | * |
| 26 | * @mmio: The base address of PHY internal registers |
| 27 | * @phy_grf: The regmap for controlling pipe signal |
| 28 | * @p30phy: The reset signal for PHY |
Jonas Karlman | 3b39592 | 2023-08-02 19:04:29 +0000 | [diff] [blame^] | 29 | * @clks: The clocks for PHY |
Shawn Lin | 6ec62b6 | 2021-01-15 18:01:21 +0800 | [diff] [blame] | 30 | */ |
| 31 | struct rockchip_p3phy_priv { |
| 32 | void __iomem *mmio; |
| 33 | struct regmap *phy_grf; |
| 34 | struct reset_ctl p30phy; |
Jonas Karlman | 3b39592 | 2023-08-02 19:04:29 +0000 | [diff] [blame^] | 35 | struct clk_bulk clks; |
Shawn Lin | 6ec62b6 | 2021-01-15 18:01:21 +0800 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | static int rochchip_p3phy_init(struct phy *phy) |
| 39 | { |
| 40 | struct rockchip_p3phy_priv *priv = dev_get_priv(phy->dev); |
| 41 | int ret; |
| 42 | |
Jonas Karlman | 3b39592 | 2023-08-02 19:04:29 +0000 | [diff] [blame^] | 43 | ret = clk_enable_bulk(&priv->clks); |
| 44 | if (ret) |
Shawn Lin | 6ec62b6 | 2021-01-15 18:01:21 +0800 | [diff] [blame] | 45 | return ret; |
| 46 | |
Shawn Lin | 6ec62b6 | 2021-01-15 18:01:21 +0800 | [diff] [blame] | 47 | reset_assert(&priv->p30phy); |
| 48 | udelay(1); |
| 49 | |
| 50 | /* Deassert PCIe PMA output clamp mode */ |
| 51 | regmap_write(priv->phy_grf, GRF_PCIE30PHY_CON9, |
| 52 | (0x1 << 15) | (0x1 << 31)); |
| 53 | |
| 54 | reset_deassert(&priv->p30phy); |
| 55 | udelay(1); |
| 56 | |
| 57 | return 0; |
Shawn Lin | 6ec62b6 | 2021-01-15 18:01:21 +0800 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | static int rochchip_p3phy_exit(struct phy *phy) |
| 61 | { |
| 62 | struct rockchip_p3phy_priv *priv = dev_get_priv(phy->dev); |
| 63 | |
Jonas Karlman | 3b39592 | 2023-08-02 19:04:29 +0000 | [diff] [blame^] | 64 | clk_disable_bulk(&priv->clks); |
Shawn Lin | 6ec62b6 | 2021-01-15 18:01:21 +0800 | [diff] [blame] | 65 | reset_assert(&priv->p30phy); |
| 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | static int rockchip_p3phy_probe(struct udevice *dev) |
| 71 | { |
| 72 | struct rockchip_p3phy_priv *priv = dev_get_priv(dev); |
Shawn Lin | 6ec62b6 | 2021-01-15 18:01:21 +0800 | [diff] [blame] | 73 | int ret; |
| 74 | |
Johan Jonker | a12a73b | 2023-03-13 01:32:04 +0100 | [diff] [blame] | 75 | priv->mmio = dev_read_addr_ptr(dev); |
| 76 | if (!priv->mmio) |
Shawn Lin | 6ec62b6 | 2021-01-15 18:01:21 +0800 | [diff] [blame] | 77 | return -EINVAL; |
| 78 | |
Jonas Karlman | 3b39592 | 2023-08-02 19:04:29 +0000 | [diff] [blame^] | 79 | priv->phy_grf = syscon_regmap_lookup_by_phandle(dev, "rockchip,phy-grf"); |
Shawn Lin | 6ec62b6 | 2021-01-15 18:01:21 +0800 | [diff] [blame] | 80 | if (IS_ERR(priv->phy_grf)) { |
| 81 | dev_err(dev, "failed to find rockchip,phy_grf regmap\n"); |
| 82 | return PTR_ERR(priv->phy_grf); |
| 83 | } |
| 84 | |
| 85 | ret = reset_get_by_name(dev, "phy", &priv->p30phy); |
| 86 | if (ret) { |
| 87 | dev_err(dev, "no phy reset control specified\n"); |
| 88 | return ret; |
| 89 | } |
| 90 | |
Jonas Karlman | 3b39592 | 2023-08-02 19:04:29 +0000 | [diff] [blame^] | 91 | ret = clk_get_bulk(dev, &priv->clks); |
Shawn Lin | 6ec62b6 | 2021-01-15 18:01:21 +0800 | [diff] [blame] | 92 | if (ret) { |
Jonas Karlman | 3b39592 | 2023-08-02 19:04:29 +0000 | [diff] [blame^] | 93 | dev_err(dev, "failed to get clocks\n"); |
| 94 | return ret; |
Shawn Lin | 6ec62b6 | 2021-01-15 18:01:21 +0800 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | static struct phy_ops rochchip_p3phy_ops = { |
| 101 | .init = rochchip_p3phy_init, |
| 102 | .exit = rochchip_p3phy_exit, |
| 103 | }; |
| 104 | |
| 105 | static const struct udevice_id rockchip_p3phy_of_match[] = { |
| 106 | { .compatible = "rockchip,rk3568-pcie3-phy" }, |
| 107 | { }, |
| 108 | }; |
| 109 | |
| 110 | U_BOOT_DRIVER(rockchip_pcie3phy) = { |
| 111 | .name = "rockchip_pcie3phy", |
| 112 | .id = UCLASS_PHY, |
| 113 | .of_match = rockchip_p3phy_of_match, |
| 114 | .ops = &rochchip_p3phy_ops, |
| 115 | .probe = rockchip_p3phy_probe, |
| 116 | .priv_auto = sizeof(struct rockchip_p3phy_priv), |
| 117 | }; |