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