Jagan Teki | 0d2d0bf | 2023-02-17 17:28:41 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Rockchip USB3.0/PCIe Gen2/SATA/SGMII combphy driver |
| 4 | * |
| 5 | * Copyright (C) 2021 Rockchip Electronics Co., Ltd. |
| 6 | */ |
| 7 | |
Jagan Teki | 0d2d0bf | 2023-02-17 17:28:41 +0530 | [diff] [blame] | 8 | #include <clk.h> |
| 9 | #include <dm.h> |
| 10 | #include <dm/lists.h> |
| 11 | #include <dt-bindings/phy/phy.h> |
| 12 | #include <generic-phy.h> |
| 13 | #include <syscon.h> |
| 14 | #include <asm/io.h> |
| 15 | #include <asm/arch-rockchip/clock.h> |
| 16 | #include <regmap.h> |
| 17 | #include <reset-uclass.h> |
| 18 | #include <dm/device_compat.h> |
| 19 | |
| 20 | #define BIT_WRITEABLE_SHIFT 16 |
| 21 | |
| 22 | struct rockchip_combphy_priv; |
| 23 | |
| 24 | struct combphy_reg { |
| 25 | u16 offset; |
| 26 | u16 bitend; |
| 27 | u16 bitstart; |
| 28 | u16 disable; |
| 29 | u16 enable; |
| 30 | }; |
| 31 | |
| 32 | struct rockchip_combphy_grfcfg { |
| 33 | struct combphy_reg pcie_mode_set; |
| 34 | struct combphy_reg usb_mode_set; |
| 35 | struct combphy_reg sgmii_mode_set; |
| 36 | struct combphy_reg qsgmii_mode_set; |
| 37 | struct combphy_reg pipe_rxterm_set; |
| 38 | struct combphy_reg pipe_txelec_set; |
| 39 | struct combphy_reg pipe_txcomp_set; |
| 40 | struct combphy_reg pipe_clk_25m; |
| 41 | struct combphy_reg pipe_clk_100m; |
| 42 | struct combphy_reg pipe_phymode_sel; |
| 43 | struct combphy_reg pipe_rate_sel; |
| 44 | struct combphy_reg pipe_rxterm_sel; |
| 45 | struct combphy_reg pipe_txelec_sel; |
| 46 | struct combphy_reg pipe_txcomp_sel; |
| 47 | struct combphy_reg pipe_clk_ext; |
| 48 | struct combphy_reg pipe_sel_usb; |
| 49 | struct combphy_reg pipe_sel_qsgmii; |
| 50 | struct combphy_reg pipe_phy_status; |
| 51 | struct combphy_reg con0_for_pcie; |
| 52 | struct combphy_reg con1_for_pcie; |
| 53 | struct combphy_reg con2_for_pcie; |
| 54 | struct combphy_reg con3_for_pcie; |
| 55 | struct combphy_reg con0_for_sata; |
| 56 | struct combphy_reg con1_for_sata; |
| 57 | struct combphy_reg con2_for_sata; |
| 58 | struct combphy_reg con3_for_sata; |
| 59 | struct combphy_reg pipe_con0_for_sata; |
Jon Lin | bc980f6 | 2023-04-27 10:35:35 +0300 | [diff] [blame] | 60 | struct combphy_reg pipe_con1_for_sata; |
Jagan Teki | 0d2d0bf | 2023-02-17 17:28:41 +0530 | [diff] [blame] | 61 | struct combphy_reg pipe_sgmii_mac_sel; |
| 62 | struct combphy_reg pipe_xpcs_phy_ready; |
Jonas Karlman | ecc7245 | 2023-08-02 19:41:22 +0000 | [diff] [blame] | 63 | struct combphy_reg pipe_pcie1l0_sel; |
| 64 | struct combphy_reg pipe_pcie1l1_sel; |
Jagan Teki | 0d2d0bf | 2023-02-17 17:28:41 +0530 | [diff] [blame] | 65 | struct combphy_reg u3otg0_port_en; |
| 66 | struct combphy_reg u3otg1_port_en; |
| 67 | }; |
| 68 | |
| 69 | struct rockchip_combphy_cfg { |
| 70 | const struct rockchip_combphy_grfcfg *grfcfg; |
| 71 | int (*combphy_cfg)(struct rockchip_combphy_priv *priv); |
| 72 | }; |
| 73 | |
| 74 | struct rockchip_combphy_priv { |
| 75 | u32 mode; |
| 76 | void __iomem *mmio; |
| 77 | struct udevice *dev; |
| 78 | struct regmap *pipe_grf; |
| 79 | struct regmap *phy_grf; |
| 80 | struct phy *phy; |
Eugen Hristev | 03a4483 | 2023-04-27 10:35:34 +0300 | [diff] [blame] | 81 | struct reset_ctl_bulk phy_rsts; |
Jagan Teki | 0d2d0bf | 2023-02-17 17:28:41 +0530 | [diff] [blame] | 82 | struct clk ref_clk; |
| 83 | const struct rockchip_combphy_cfg *cfg; |
| 84 | }; |
| 85 | |
| 86 | static int param_write(struct regmap *base, |
| 87 | const struct combphy_reg *reg, bool en) |
| 88 | { |
| 89 | u32 val, mask, tmp; |
| 90 | |
| 91 | tmp = en ? reg->enable : reg->disable; |
| 92 | mask = GENMASK(reg->bitend, reg->bitstart); |
| 93 | val = (tmp << reg->bitstart) | (mask << BIT_WRITEABLE_SHIFT); |
| 94 | |
| 95 | return regmap_write(base, reg->offset, val); |
| 96 | } |
| 97 | |
| 98 | static int rockchip_combphy_pcie_init(struct rockchip_combphy_priv *priv) |
| 99 | { |
| 100 | int ret = 0; |
| 101 | |
| 102 | if (priv->cfg->combphy_cfg) { |
| 103 | ret = priv->cfg->combphy_cfg(priv); |
| 104 | if (ret) { |
| 105 | dev_err(priv->dev, "failed to init phy for pcie\n"); |
| 106 | return ret; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | return ret; |
| 111 | } |
| 112 | |
| 113 | static int rockchip_combphy_usb3_init(struct rockchip_combphy_priv *priv) |
| 114 | { |
| 115 | int ret = 0; |
| 116 | |
| 117 | if (priv->cfg->combphy_cfg) { |
| 118 | ret = priv->cfg->combphy_cfg(priv); |
| 119 | if (ret) { |
| 120 | dev_err(priv->dev, "failed to init phy for usb3\n"); |
| 121 | return ret; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | return ret; |
| 126 | } |
| 127 | |
| 128 | static int rockchip_combphy_sata_init(struct rockchip_combphy_priv *priv) |
| 129 | { |
| 130 | int ret = 0; |
| 131 | |
| 132 | if (priv->cfg->combphy_cfg) { |
| 133 | ret = priv->cfg->combphy_cfg(priv); |
| 134 | if (ret) { |
| 135 | dev_err(priv->dev, "failed to init phy for sata\n"); |
| 136 | return ret; |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | return ret; |
| 141 | } |
| 142 | |
| 143 | static int rockchip_combphy_sgmii_init(struct rockchip_combphy_priv *priv) |
| 144 | { |
| 145 | int ret = 0; |
| 146 | |
| 147 | if (priv->cfg->combphy_cfg) { |
| 148 | ret = priv->cfg->combphy_cfg(priv); |
| 149 | if (ret) { |
| 150 | dev_err(priv->dev, "failed to init phy for sgmii\n"); |
| 151 | return ret; |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | return ret; |
| 156 | } |
| 157 | |
| 158 | static int rockchip_combphy_set_mode(struct rockchip_combphy_priv *priv) |
| 159 | { |
| 160 | switch (priv->mode) { |
| 161 | case PHY_TYPE_PCIE: |
| 162 | rockchip_combphy_pcie_init(priv); |
| 163 | break; |
| 164 | case PHY_TYPE_USB3: |
| 165 | rockchip_combphy_usb3_init(priv); |
| 166 | break; |
| 167 | case PHY_TYPE_SATA: |
| 168 | rockchip_combphy_sata_init(priv); |
| 169 | break; |
| 170 | case PHY_TYPE_SGMII: |
| 171 | case PHY_TYPE_QSGMII: |
| 172 | return rockchip_combphy_sgmii_init(priv); |
| 173 | default: |
| 174 | dev_err(priv->dev, "incompatible PHY type\n"); |
| 175 | return -EINVAL; |
| 176 | } |
| 177 | |
| 178 | return 0; |
| 179 | } |
| 180 | |
| 181 | static int rockchip_combphy_init(struct phy *phy) |
| 182 | { |
| 183 | struct rockchip_combphy_priv *priv = dev_get_priv(phy->dev); |
| 184 | int ret; |
| 185 | |
| 186 | ret = clk_enable(&priv->ref_clk); |
| 187 | if (ret < 0 && ret != -ENOSYS) |
| 188 | return ret; |
| 189 | |
| 190 | ret = rockchip_combphy_set_mode(priv); |
| 191 | if (ret) |
| 192 | goto err_clk; |
| 193 | |
Eugen Hristev | 03a4483 | 2023-04-27 10:35:34 +0300 | [diff] [blame] | 194 | reset_deassert_bulk(&priv->phy_rsts); |
Jagan Teki | 0d2d0bf | 2023-02-17 17:28:41 +0530 | [diff] [blame] | 195 | |
| 196 | return 0; |
| 197 | |
| 198 | err_clk: |
| 199 | clk_disable(&priv->ref_clk); |
| 200 | |
| 201 | return ret; |
| 202 | } |
| 203 | |
| 204 | static int rockchip_combphy_exit(struct phy *phy) |
| 205 | { |
| 206 | struct rockchip_combphy_priv *priv = dev_get_priv(phy->dev); |
| 207 | |
| 208 | clk_disable(&priv->ref_clk); |
Eugen Hristev | 03a4483 | 2023-04-27 10:35:34 +0300 | [diff] [blame] | 209 | reset_assert_bulk(&priv->phy_rsts); |
Jagan Teki | 0d2d0bf | 2023-02-17 17:28:41 +0530 | [diff] [blame] | 210 | |
| 211 | return 0; |
| 212 | } |
| 213 | |
| 214 | static int rockchip_combphy_xlate(struct phy *phy, struct ofnode_phandle_args *args) |
| 215 | { |
| 216 | struct rockchip_combphy_priv *priv = dev_get_priv(phy->dev); |
| 217 | |
| 218 | if (args->args_count != 1) { |
| 219 | pr_err("invalid number of arguments\n"); |
| 220 | return -EINVAL; |
| 221 | } |
| 222 | |
| 223 | priv->mode = args->args[0]; |
| 224 | |
| 225 | return 0; |
| 226 | } |
| 227 | |
| 228 | static const struct phy_ops rochchip_combphy_ops = { |
| 229 | .init = rockchip_combphy_init, |
| 230 | .exit = rockchip_combphy_exit, |
| 231 | .of_xlate = rockchip_combphy_xlate, |
| 232 | }; |
| 233 | |
| 234 | static int rockchip_combphy_parse_dt(struct udevice *dev, |
| 235 | struct rockchip_combphy_priv *priv) |
| 236 | { |
| 237 | struct udevice *syscon; |
| 238 | int ret; |
| 239 | |
| 240 | ret = uclass_get_device_by_phandle(UCLASS_SYSCON, dev, "rockchip,pipe-grf", &syscon); |
| 241 | if (ret) { |
| 242 | dev_err(dev, "failed to find peri_ctrl pipe-grf regmap"); |
| 243 | return ret; |
| 244 | } |
| 245 | priv->pipe_grf = syscon_get_regmap(syscon); |
| 246 | |
| 247 | ret = uclass_get_device_by_phandle(UCLASS_SYSCON, dev, "rockchip,pipe-phy-grf", &syscon); |
| 248 | if (ret) { |
| 249 | dev_err(dev, "failed to find peri_ctrl pipe-phy-grf regmap\n"); |
| 250 | return ret; |
| 251 | } |
| 252 | priv->phy_grf = syscon_get_regmap(syscon); |
| 253 | |
| 254 | ret = clk_get_by_index(dev, 0, &priv->ref_clk); |
| 255 | if (ret) { |
| 256 | dev_err(dev, "failed to find ref clock\n"); |
| 257 | return PTR_ERR(&priv->ref_clk); |
| 258 | } |
| 259 | |
Eugen Hristev | 03a4483 | 2023-04-27 10:35:34 +0300 | [diff] [blame] | 260 | ret = reset_get_bulk(dev, &priv->phy_rsts); |
Jagan Teki | 0d2d0bf | 2023-02-17 17:28:41 +0530 | [diff] [blame] | 261 | if (ret) { |
| 262 | dev_err(dev, "no phy reset control specified\n"); |
| 263 | return ret; |
| 264 | } |
| 265 | |
| 266 | return 0; |
| 267 | } |
| 268 | |
| 269 | static int rockchip_combphy_probe(struct udevice *udev) |
| 270 | { |
| 271 | struct rockchip_combphy_priv *priv = dev_get_priv(udev); |
| 272 | const struct rockchip_combphy_cfg *phy_cfg; |
| 273 | |
| 274 | priv->mmio = (void __iomem *)dev_read_addr(udev); |
| 275 | if (IS_ERR(priv->mmio)) |
| 276 | return PTR_ERR(priv->mmio); |
| 277 | |
| 278 | phy_cfg = (const struct rockchip_combphy_cfg *)dev_get_driver_data(udev); |
| 279 | if (!phy_cfg) { |
| 280 | dev_err(udev, "No OF match data provided\n"); |
| 281 | return -EINVAL; |
| 282 | } |
| 283 | |
| 284 | priv->dev = udev; |
| 285 | priv->mode = PHY_TYPE_SATA; |
| 286 | priv->cfg = phy_cfg; |
| 287 | |
| 288 | return rockchip_combphy_parse_dt(udev, priv); |
| 289 | } |
| 290 | |
| 291 | static int rk3568_combphy_cfg(struct rockchip_combphy_priv *priv) |
| 292 | { |
| 293 | const struct rockchip_combphy_grfcfg *cfg = priv->cfg->grfcfg; |
| 294 | u32 val; |
| 295 | |
| 296 | switch (priv->mode) { |
| 297 | case PHY_TYPE_PCIE: |
| 298 | /* Set SSC downward spread spectrum */ |
| 299 | val = readl(priv->mmio + (0x1f << 2)); |
| 300 | val &= ~GENMASK(5, 4); |
| 301 | val |= 0x01 << 4; |
| 302 | writel(val, priv->mmio + 0x7c); |
| 303 | |
| 304 | param_write(priv->phy_grf, &cfg->con0_for_pcie, true); |
| 305 | param_write(priv->phy_grf, &cfg->con1_for_pcie, true); |
| 306 | param_write(priv->phy_grf, &cfg->con2_for_pcie, true); |
| 307 | param_write(priv->phy_grf, &cfg->con3_for_pcie, true); |
| 308 | break; |
| 309 | case PHY_TYPE_USB3: |
| 310 | /* Set SSC downward spread spectrum */ |
| 311 | val = readl(priv->mmio + (0x1f << 2)); |
| 312 | val &= ~GENMASK(5, 4); |
| 313 | val |= 0x01 << 4; |
| 314 | writel(val, priv->mmio + 0x7c); |
| 315 | |
| 316 | /* Enable adaptive CTLE for USB3.0 Rx */ |
| 317 | val = readl(priv->mmio + (0x0e << 2)); |
| 318 | val &= ~GENMASK(0, 0); |
| 319 | val |= 0x01; |
| 320 | writel(val, priv->mmio + (0x0e << 2)); |
| 321 | |
| 322 | /* Set PLL KVCO fine tuning signals */ |
| 323 | val = readl(priv->mmio + (0x20 << 2)); |
| 324 | val &= ~(0x7 << 2); |
| 325 | val |= 0x2 << 2; |
| 326 | writel(val, priv->mmio + (0x20 << 2)); |
| 327 | |
| 328 | /* Set PLL LPF R1 to su_trim[10:7]=1001 */ |
| 329 | writel(0x4, priv->mmio + (0xb << 2)); |
| 330 | |
| 331 | /* Set PLL input clock divider 1/2 */ |
| 332 | val = readl(priv->mmio + (0x5 << 2)); |
| 333 | val &= ~(0x3 << 6); |
| 334 | val |= 0x1 << 6; |
| 335 | writel(val, priv->mmio + (0x5 << 2)); |
| 336 | |
| 337 | /* Set PLL loop divider */ |
| 338 | writel(0x32, priv->mmio + (0x11 << 2)); |
| 339 | |
| 340 | /* Set PLL KVCO to min and set PLL charge pump current to max */ |
| 341 | writel(0xf0, priv->mmio + (0xa << 2)); |
| 342 | |
| 343 | param_write(priv->phy_grf, &cfg->pipe_sel_usb, true); |
| 344 | param_write(priv->phy_grf, &cfg->pipe_txcomp_sel, false); |
| 345 | param_write(priv->phy_grf, &cfg->pipe_txelec_sel, false); |
| 346 | param_write(priv->phy_grf, &cfg->usb_mode_set, true); |
| 347 | break; |
| 348 | case PHY_TYPE_SATA: |
| 349 | writel(0x41, priv->mmio + 0x38); |
| 350 | writel(0x8F, priv->mmio + 0x18); |
| 351 | param_write(priv->phy_grf, &cfg->con0_for_sata, true); |
| 352 | param_write(priv->phy_grf, &cfg->con1_for_sata, true); |
| 353 | param_write(priv->phy_grf, &cfg->con2_for_sata, true); |
| 354 | param_write(priv->phy_grf, &cfg->con3_for_sata, true); |
| 355 | param_write(priv->pipe_grf, &cfg->pipe_con0_for_sata, true); |
| 356 | break; |
| 357 | case PHY_TYPE_SGMII: |
| 358 | param_write(priv->pipe_grf, &cfg->pipe_xpcs_phy_ready, true); |
| 359 | param_write(priv->phy_grf, &cfg->pipe_phymode_sel, true); |
| 360 | param_write(priv->phy_grf, &cfg->pipe_sel_qsgmii, true); |
| 361 | param_write(priv->phy_grf, &cfg->sgmii_mode_set, true); |
| 362 | break; |
| 363 | case PHY_TYPE_QSGMII: |
| 364 | param_write(priv->pipe_grf, &cfg->pipe_xpcs_phy_ready, true); |
| 365 | param_write(priv->phy_grf, &cfg->pipe_phymode_sel, true); |
| 366 | param_write(priv->phy_grf, &cfg->pipe_rate_sel, true); |
| 367 | param_write(priv->phy_grf, &cfg->pipe_sel_qsgmii, true); |
| 368 | param_write(priv->phy_grf, &cfg->qsgmii_mode_set, true); |
| 369 | break; |
| 370 | default: |
| 371 | pr_err("%s, phy-type %d\n", __func__, priv->mode); |
| 372 | return -EINVAL; |
| 373 | } |
| 374 | |
| 375 | /* The default ref clock is 25Mhz */ |
| 376 | param_write(priv->phy_grf, &cfg->pipe_clk_25m, true); |
| 377 | |
| 378 | if (dev_read_bool(priv->dev, "rockchip,enable-ssc")) { |
| 379 | val = readl(priv->mmio + (0x7 << 2)); |
| 380 | val |= BIT(4); |
| 381 | writel(val, priv->mmio + (0x7 << 2)); |
| 382 | } |
| 383 | |
| 384 | return 0; |
| 385 | } |
| 386 | |
| 387 | static const struct rockchip_combphy_grfcfg rk3568_combphy_grfcfgs = { |
| 388 | /* pipe-phy-grf */ |
| 389 | .pcie_mode_set = { 0x0000, 5, 0, 0x00, 0x11 }, |
| 390 | .usb_mode_set = { 0x0000, 5, 0, 0x00, 0x04 }, |
| 391 | .sgmii_mode_set = { 0x0000, 5, 0, 0x00, 0x01 }, |
| 392 | .qsgmii_mode_set = { 0x0000, 5, 0, 0x00, 0x21 }, |
| 393 | .pipe_rxterm_set = { 0x0000, 12, 12, 0x00, 0x01 }, |
| 394 | .pipe_txelec_set = { 0x0004, 1, 1, 0x00, 0x01 }, |
| 395 | .pipe_txcomp_set = { 0x0004, 4, 4, 0x00, 0x01 }, |
| 396 | .pipe_clk_25m = { 0x0004, 14, 13, 0x00, 0x01 }, |
| 397 | .pipe_clk_100m = { 0x0004, 14, 13, 0x00, 0x02 }, |
| 398 | .pipe_phymode_sel = { 0x0008, 1, 1, 0x00, 0x01 }, |
| 399 | .pipe_rate_sel = { 0x0008, 2, 2, 0x00, 0x01 }, |
| 400 | .pipe_rxterm_sel = { 0x0008, 8, 8, 0x00, 0x01 }, |
| 401 | .pipe_txelec_sel = { 0x0008, 12, 12, 0x00, 0x01 }, |
| 402 | .pipe_txcomp_sel = { 0x0008, 15, 15, 0x00, 0x01 }, |
| 403 | .pipe_clk_ext = { 0x000c, 9, 8, 0x02, 0x01 }, |
| 404 | .pipe_sel_usb = { 0x000c, 14, 13, 0x00, 0x01 }, |
| 405 | .pipe_sel_qsgmii = { 0x000c, 15, 13, 0x00, 0x07 }, |
| 406 | .pipe_phy_status = { 0x0034, 6, 6, 0x01, 0x00 }, |
| 407 | .con0_for_pcie = { 0x0000, 15, 0, 0x00, 0x1000 }, |
| 408 | .con1_for_pcie = { 0x0004, 15, 0, 0x00, 0x0000 }, |
| 409 | .con2_for_pcie = { 0x0008, 15, 0, 0x00, 0x0101 }, |
| 410 | .con3_for_pcie = { 0x000c, 15, 0, 0x00, 0x0200 }, |
| 411 | .con0_for_sata = { 0x0000, 15, 0, 0x00, 0x0119 }, |
| 412 | .con1_for_sata = { 0x0004, 15, 0, 0x00, 0x0040 }, |
| 413 | .con2_for_sata = { 0x0008, 15, 0, 0x00, 0x80c3 }, |
| 414 | .con3_for_sata = { 0x000c, 15, 0, 0x00, 0x4407 }, |
| 415 | /* pipe-grf */ |
| 416 | .pipe_con0_for_sata = { 0x0000, 15, 0, 0x00, 0x2220 }, |
| 417 | .pipe_sgmii_mac_sel = { 0x0040, 1, 1, 0x00, 0x01 }, |
| 418 | .pipe_xpcs_phy_ready = { 0x0040, 2, 2, 0x00, 0x01 }, |
| 419 | .u3otg0_port_en = { 0x0104, 15, 0, 0x0181, 0x1100 }, |
| 420 | .u3otg1_port_en = { 0x0144, 15, 0, 0x0181, 0x1100 }, |
| 421 | }; |
| 422 | |
| 423 | static const struct rockchip_combphy_cfg rk3568_combphy_cfgs = { |
| 424 | .grfcfg = &rk3568_combphy_grfcfgs, |
| 425 | .combphy_cfg = rk3568_combphy_cfg, |
| 426 | }; |
| 427 | |
Jon Lin | bc980f6 | 2023-04-27 10:35:35 +0300 | [diff] [blame] | 428 | static int rk3588_combphy_cfg(struct rockchip_combphy_priv *priv) |
| 429 | { |
| 430 | const struct rockchip_combphy_grfcfg *cfg = priv->cfg->grfcfg; |
| 431 | u32 val; |
| 432 | |
| 433 | switch (priv->mode) { |
| 434 | case PHY_TYPE_PCIE: |
| 435 | param_write(priv->phy_grf, &cfg->con0_for_pcie, true); |
| 436 | param_write(priv->phy_grf, &cfg->con1_for_pcie, true); |
| 437 | param_write(priv->phy_grf, &cfg->con2_for_pcie, true); |
| 438 | param_write(priv->phy_grf, &cfg->con3_for_pcie, true); |
Jonas Karlman | ecc7245 | 2023-08-02 19:41:22 +0000 | [diff] [blame] | 439 | param_write(priv->pipe_grf, &cfg->pipe_pcie1l0_sel, true); |
| 440 | param_write(priv->pipe_grf, &cfg->pipe_pcie1l1_sel, true); |
Jon Lin | bc980f6 | 2023-04-27 10:35:35 +0300 | [diff] [blame] | 441 | break; |
| 442 | case PHY_TYPE_USB3: |
| 443 | param_write(priv->phy_grf, &cfg->pipe_txcomp_sel, false); |
| 444 | param_write(priv->phy_grf, &cfg->pipe_txelec_sel, false); |
| 445 | param_write(priv->phy_grf, &cfg->usb_mode_set, true); |
| 446 | break; |
| 447 | case PHY_TYPE_SATA: |
| 448 | param_write(priv->phy_grf, &cfg->con0_for_sata, true); |
| 449 | param_write(priv->phy_grf, &cfg->con1_for_sata, true); |
| 450 | param_write(priv->phy_grf, &cfg->con2_for_sata, true); |
| 451 | param_write(priv->phy_grf, &cfg->con3_for_sata, true); |
| 452 | param_write(priv->pipe_grf, &cfg->pipe_con0_for_sata, true); |
| 453 | param_write(priv->pipe_grf, &cfg->pipe_con1_for_sata, true); |
| 454 | break; |
| 455 | case PHY_TYPE_SGMII: |
| 456 | case PHY_TYPE_QSGMII: |
| 457 | default: |
| 458 | dev_err(priv->dev, "incompatible PHY type\n"); |
| 459 | return -EINVAL; |
| 460 | } |
| 461 | |
| 462 | /* 100MHz refclock signal is good */ |
| 463 | clk_set_rate(&priv->ref_clk, 100000000); |
| 464 | param_write(priv->phy_grf, &cfg->pipe_clk_100m, true); |
| 465 | if (priv->mode == PHY_TYPE_PCIE) { |
| 466 | /* PLL KVCO tuning fine */ |
| 467 | val = readl(priv->mmio + (0x20 << 2)); |
| 468 | val &= ~GENMASK(4, 2); |
| 469 | val |= 0x4 << 2; |
| 470 | writel(val, priv->mmio + (0x20 << 2)); |
| 471 | |
| 472 | /* Set up rx_trim: PLL LPF C1 85pf R1 1.25kohm */ |
| 473 | val = 0x4c; |
| 474 | writel(val, priv->mmio + (0x1b << 2)); |
| 475 | |
| 476 | /* Set up su_trim: T3 */ |
| 477 | val = 0xb0; |
| 478 | writel(val, priv->mmio + (0xa << 2)); |
| 479 | val = 0x47; |
| 480 | writel(val, priv->mmio + (0xb << 2)); |
| 481 | val = 0x57; |
| 482 | writel(val, priv->mmio + (0xd << 2)); |
| 483 | } |
| 484 | |
| 485 | return 0; |
| 486 | } |
| 487 | |
| 488 | static const struct rockchip_combphy_grfcfg rk3588_combphy_grfcfgs = { |
| 489 | /* pipe-phy-grf */ |
| 490 | .pcie_mode_set = { 0x0000, 5, 0, 0x00, 0x11 }, |
| 491 | .usb_mode_set = { 0x0000, 5, 0, 0x00, 0x04 }, |
| 492 | .pipe_rxterm_set = { 0x0000, 12, 12, 0x00, 0x01 }, |
| 493 | .pipe_txelec_set = { 0x0004, 1, 1, 0x00, 0x01 }, |
| 494 | .pipe_txcomp_set = { 0x0004, 4, 4, 0x00, 0x01 }, |
| 495 | .pipe_clk_25m = { 0x0004, 14, 13, 0x00, 0x01 }, |
| 496 | .pipe_clk_100m = { 0x0004, 14, 13, 0x00, 0x02 }, |
| 497 | .pipe_rxterm_sel = { 0x0008, 8, 8, 0x00, 0x01 }, |
| 498 | .pipe_txelec_sel = { 0x0008, 12, 12, 0x00, 0x01 }, |
| 499 | .pipe_txcomp_sel = { 0x0008, 15, 15, 0x00, 0x01 }, |
| 500 | .pipe_clk_ext = { 0x000c, 9, 8, 0x02, 0x01 }, |
| 501 | .pipe_phy_status = { 0x0034, 6, 6, 0x01, 0x00 }, |
| 502 | .con0_for_pcie = { 0x0000, 15, 0, 0x00, 0x1000 }, |
| 503 | .con1_for_pcie = { 0x0004, 15, 0, 0x00, 0x0000 }, |
| 504 | .con2_for_pcie = { 0x0008, 15, 0, 0x00, 0x0101 }, |
| 505 | .con3_for_pcie = { 0x000c, 15, 0, 0x00, 0x0200 }, |
| 506 | .con0_for_sata = { 0x0000, 15, 0, 0x00, 0x0129 }, |
| 507 | .con1_for_sata = { 0x0004, 15, 0, 0x00, 0x0040 }, |
| 508 | .con2_for_sata = { 0x0008, 15, 0, 0x00, 0x80c1 }, |
| 509 | .con3_for_sata = { 0x000c, 15, 0, 0x00, 0x0407 }, |
| 510 | /* pipe-grf */ |
| 511 | .pipe_con0_for_sata = { 0x0000, 11, 5, 0x00, 0x22 }, |
| 512 | .pipe_con1_for_sata = { 0x0000, 2, 0, 0x00, 0x2 }, |
Jonas Karlman | ecc7245 | 2023-08-02 19:41:22 +0000 | [diff] [blame] | 513 | .pipe_pcie1l0_sel = { 0x0100, 0, 0, 0x01, 0x0 }, |
| 514 | .pipe_pcie1l1_sel = { 0x0100, 1, 1, 0x01, 0x0 }, |
Jon Lin | bc980f6 | 2023-04-27 10:35:35 +0300 | [diff] [blame] | 515 | }; |
| 516 | |
| 517 | static const struct rockchip_combphy_cfg rk3588_combphy_cfgs = { |
| 518 | .grfcfg = &rk3588_combphy_grfcfgs, |
| 519 | .combphy_cfg = rk3588_combphy_cfg, |
| 520 | }; |
| 521 | |
Jagan Teki | 0d2d0bf | 2023-02-17 17:28:41 +0530 | [diff] [blame] | 522 | static const struct udevice_id rockchip_combphy_ids[] = { |
| 523 | { |
| 524 | .compatible = "rockchip,rk3568-naneng-combphy", |
| 525 | .data = (ulong)&rk3568_combphy_cfgs |
| 526 | }, |
Jon Lin | bc980f6 | 2023-04-27 10:35:35 +0300 | [diff] [blame] | 527 | { |
| 528 | .compatible = "rockchip,rk3588-naneng-combphy", |
| 529 | .data = (ulong)&rk3588_combphy_cfgs |
| 530 | }, |
Jagan Teki | 0d2d0bf | 2023-02-17 17:28:41 +0530 | [diff] [blame] | 531 | { } |
| 532 | }; |
| 533 | |
| 534 | U_BOOT_DRIVER(rockchip_naneng_combphy) = { |
| 535 | .name = "naneng-combphy", |
| 536 | .id = UCLASS_PHY, |
| 537 | .of_match = rockchip_combphy_ids, |
| 538 | .ops = &rochchip_combphy_ops, |
| 539 | .probe = rockchip_combphy_probe, |
| 540 | .priv_auto = sizeof(struct rockchip_combphy_priv), |
| 541 | }; |