.. | .. |
---|
23 | 23 | struct rockchip_combphy_priv; |
---|
24 | 24 | |
---|
25 | 25 | struct combphy_reg { |
---|
26 | | - u16 offset; |
---|
| 26 | + u32 offset; |
---|
27 | 27 | u16 bitend; |
---|
28 | 28 | u16 bitstart; |
---|
29 | 29 | u16 disable; |
---|
.. | .. |
---|
38 | 38 | struct combphy_reg pipe_rxterm_set; |
---|
39 | 39 | struct combphy_reg pipe_txelec_set; |
---|
40 | 40 | struct combphy_reg pipe_txcomp_set; |
---|
| 41 | + struct combphy_reg pipe_clk_24m; |
---|
41 | 42 | struct combphy_reg pipe_clk_25m; |
---|
42 | 43 | struct combphy_reg pipe_clk_100m; |
---|
43 | 44 | struct combphy_reg pipe_phymode_sel; |
---|
.. | .. |
---|
152 | 153 | |
---|
153 | 154 | static int rockchip_combphy_usb3_init(struct rockchip_combphy_priv *priv) |
---|
154 | 155 | { |
---|
| 156 | + const struct rockchip_combphy_cfg *phy_cfg = priv->cfg; |
---|
155 | 157 | int ret = 0; |
---|
| 158 | + |
---|
| 159 | + if (device_property_present(priv->dev, "rockchip,dis-u3otg0-port")) { |
---|
| 160 | + ret = param_write(priv->pipe_grf, &phy_cfg->grfcfg->u3otg0_port_en, |
---|
| 161 | + false); |
---|
| 162 | + return ret; |
---|
| 163 | + } else if (device_property_present(priv->dev, "rockchip,dis-u3otg1-port")) { |
---|
| 164 | + ret = param_write(priv->pipe_grf, &phy_cfg->grfcfg->u3otg1_port_en, |
---|
| 165 | + false); |
---|
| 166 | + return ret; |
---|
| 167 | + } |
---|
156 | 168 | |
---|
157 | 169 | if (priv->cfg->combphy_cfg) { |
---|
158 | 170 | ret = priv->cfg->combphy_cfg(priv); |
---|
.. | .. |
---|
409 | 421 | return PTR_ERR_OR_ZERO(phy_provider); |
---|
410 | 422 | } |
---|
411 | 423 | |
---|
| 424 | +static int rk3528_combphy_cfg(struct rockchip_combphy_priv *priv) |
---|
| 425 | +{ |
---|
| 426 | + const struct rockchip_combphy_grfcfg *cfg = priv->cfg->grfcfg; |
---|
| 427 | + struct clk *refclk = NULL; |
---|
| 428 | + unsigned long rate; |
---|
| 429 | + int i; |
---|
| 430 | + u32 val; |
---|
| 431 | + |
---|
| 432 | + /* Configure PHY reference clock frequency */ |
---|
| 433 | + for (i = 0; i < priv->num_clks; i++) { |
---|
| 434 | + if (!strncmp(priv->clks[i].id, "refclk", 6)) { |
---|
| 435 | + refclk = priv->clks[i].clk; |
---|
| 436 | + break; |
---|
| 437 | + } |
---|
| 438 | + } |
---|
| 439 | + |
---|
| 440 | + if (!refclk) { |
---|
| 441 | + dev_err(priv->dev, "No refclk found\n"); |
---|
| 442 | + return -EINVAL; |
---|
| 443 | + } |
---|
| 444 | + |
---|
| 445 | + switch (priv->mode) { |
---|
| 446 | + case PHY_TYPE_PCIE: |
---|
| 447 | + /* Set SSC downward spread spectrum */ |
---|
| 448 | + val = readl(priv->mmio + 0x18); |
---|
| 449 | + val &= ~GENMASK(5, 4); |
---|
| 450 | + val |= 0x01 << 4; |
---|
| 451 | + writel(val, priv->mmio + 0x18); |
---|
| 452 | + |
---|
| 453 | + param_write(priv->phy_grf, &cfg->con0_for_pcie, true); |
---|
| 454 | + param_write(priv->phy_grf, &cfg->con1_for_pcie, true); |
---|
| 455 | + param_write(priv->phy_grf, &cfg->con2_for_pcie, true); |
---|
| 456 | + param_write(priv->phy_grf, &cfg->con3_for_pcie, true); |
---|
| 457 | + break; |
---|
| 458 | + case PHY_TYPE_USB3: |
---|
| 459 | + /* Set SSC downward spread spectrum */ |
---|
| 460 | + val = readl(priv->mmio + 0x18); |
---|
| 461 | + val &= ~GENMASK(5, 4); |
---|
| 462 | + val |= 0x01 << 4; |
---|
| 463 | + writel(val, priv->mmio + 0x18); |
---|
| 464 | + |
---|
| 465 | + /* Enable adaptive CTLE for USB3.0 Rx */ |
---|
| 466 | + val = readl(priv->mmio + 0x200); |
---|
| 467 | + val &= ~GENMASK(17, 17); |
---|
| 468 | + val |= 0x01 << 17; |
---|
| 469 | + writel(val, priv->mmio + 0x200); |
---|
| 470 | + |
---|
| 471 | + /* Set Rx squelch input filler bandwidth */ |
---|
| 472 | + val = readl(priv->mmio + 0x20c); |
---|
| 473 | + val &= ~GENMASK(2, 0); |
---|
| 474 | + val |= 0x06; |
---|
| 475 | + writel(val, priv->mmio + 0x20c); |
---|
| 476 | + |
---|
| 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 | + default: |
---|
| 482 | + dev_err(priv->dev, "incompatible PHY type\n"); |
---|
| 483 | + return -EINVAL; |
---|
| 484 | + } |
---|
| 485 | + |
---|
| 486 | + rate = clk_get_rate(refclk); |
---|
| 487 | + |
---|
| 488 | + switch (rate) { |
---|
| 489 | + case 24000000: |
---|
| 490 | + param_write(priv->phy_grf, &cfg->pipe_clk_24m, true); |
---|
| 491 | + if (priv->mode == PHY_TYPE_USB3) { |
---|
| 492 | + /* Set ssc_cnt[10:0]=00101111101 & 31.5KHz */ |
---|
| 493 | + val = readl(priv->mmio + 0x100); |
---|
| 494 | + val &= ~GENMASK(10, 0); |
---|
| 495 | + val |= 0x17d; |
---|
| 496 | + writel(val, priv->mmio + 0x100); |
---|
| 497 | + } else if (priv->mode == PHY_TYPE_PCIE) { |
---|
| 498 | + /* Set ssc_cnt[10:0]=00101111101 & 31.5KHz */ |
---|
| 499 | + val = readl(priv->mmio + 0x100); |
---|
| 500 | + val &= ~GENMASK(10, 0); |
---|
| 501 | + val |= 0x17d; |
---|
| 502 | + writel(val, priv->mmio + 0x100); |
---|
| 503 | + |
---|
| 504 | + /* tx_trim[14]=1, Enable the counting clock of the rterm detect */ |
---|
| 505 | + val = readl(priv->mmio + 0x218); |
---|
| 506 | + val |= (1 << 14); |
---|
| 507 | + writel(val, priv->mmio + 0x218); |
---|
| 508 | + |
---|
| 509 | + /* PLL KVCO tuning fine */ |
---|
| 510 | + val = readl(priv->mmio + 0x18); |
---|
| 511 | + val &= ~(0x7 << 10); |
---|
| 512 | + val |= 0x2 << 10; |
---|
| 513 | + writel(val, priv->mmio + 0x18); |
---|
| 514 | + |
---|
| 515 | + /* su_trim[6:4]=111, [10:7]=1001, [2:0]=000 */ |
---|
| 516 | + val = readl(priv->mmio + 0x108); |
---|
| 517 | + val &= ~(0x7f7); |
---|
| 518 | + val |= 0x4f0; |
---|
| 519 | + writel(val, priv->mmio + 0x108); |
---|
| 520 | + } |
---|
| 521 | + break; |
---|
| 522 | + case 100000000: |
---|
| 523 | + param_write(priv->phy_grf, &cfg->pipe_clk_100m, true); |
---|
| 524 | + if (priv->mode == PHY_TYPE_PCIE) { |
---|
| 525 | + /* Set ssc_cnt[10:0]=11000110011 & 31.5KHz */ |
---|
| 526 | + val = readl(priv->mmio + 0x100); |
---|
| 527 | + val &= ~GENMASK(10, 0); |
---|
| 528 | + val |= 0x633; |
---|
| 529 | + writel(val, priv->mmio + 0x100); |
---|
| 530 | + |
---|
| 531 | + /* PLL KVCO tuning fine */ |
---|
| 532 | + val = readl(priv->mmio + 0x18); |
---|
| 533 | + val &= ~(0x7 << 10); |
---|
| 534 | + val |= 0x2 << 10; |
---|
| 535 | + writel(val, priv->mmio + 0x18); |
---|
| 536 | + |
---|
| 537 | + /* su_trim[6:4]=111, [10:7]=1001, [2:0]=000, swing 650mv */ |
---|
| 538 | + val = 0x570804f0; |
---|
| 539 | + writel(val, priv->mmio + 0x108); |
---|
| 540 | + } |
---|
| 541 | + break; |
---|
| 542 | + default: |
---|
| 543 | + dev_err(priv->dev, "Unsupported rate: %lu\n", rate); |
---|
| 544 | + return -EINVAL; |
---|
| 545 | + } |
---|
| 546 | + |
---|
| 547 | + if (priv->mode == PHY_TYPE_PCIE) { |
---|
| 548 | + if (device_property_read_bool(priv->dev, "rockchip,enable-ssc")) { |
---|
| 549 | + val = readl(priv->mmio + 0x100); |
---|
| 550 | + val |= BIT(20); |
---|
| 551 | + writel(val, priv->mmio + 0x100); |
---|
| 552 | + } |
---|
| 553 | + } |
---|
| 554 | + |
---|
| 555 | + return 0; |
---|
| 556 | +} |
---|
| 557 | + |
---|
| 558 | +static const struct rockchip_combphy_grfcfg rk3528_combphy_grfcfgs = { |
---|
| 559 | + /* pipe-phy-grf */ |
---|
| 560 | + .pcie_mode_set = { 0x48000, 5, 0, 0x00, 0x11 }, |
---|
| 561 | + .usb_mode_set = { 0x48000, 5, 0, 0x00, 0x04 }, |
---|
| 562 | + .pipe_rxterm_set = { 0x48000, 12, 12, 0x00, 0x01 }, |
---|
| 563 | + .pipe_txelec_set = { 0x48004, 1, 1, 0x00, 0x01 }, |
---|
| 564 | + .pipe_txcomp_set = { 0x48004, 4, 4, 0x00, 0x01 }, |
---|
| 565 | + .pipe_clk_24m = { 0x48004, 14, 13, 0x00, 0x00 }, |
---|
| 566 | + .pipe_clk_100m = { 0x48004, 14, 13, 0x00, 0x02 }, |
---|
| 567 | + .pipe_rxterm_sel = { 0x48008, 8, 8, 0x00, 0x01 }, |
---|
| 568 | + .pipe_txelec_sel = { 0x48008, 12, 12, 0x00, 0x01 }, |
---|
| 569 | + .pipe_txcomp_sel = { 0x48008, 15, 15, 0x00, 0x01 }, |
---|
| 570 | + .pipe_clk_ext = { 0x4800c, 9, 8, 0x02, 0x01 }, |
---|
| 571 | + .pipe_phy_status = { 0x48034, 6, 6, 0x01, 0x00 }, |
---|
| 572 | + .con0_for_pcie = { 0x48000, 15, 0, 0x00, 0x110 }, |
---|
| 573 | + .con1_for_pcie = { 0x48004, 15, 0, 0x00, 0x00 }, |
---|
| 574 | + .con2_for_pcie = { 0x48008, 15, 0, 0x00, 0x101 }, |
---|
| 575 | + .con3_for_pcie = { 0x4800c, 15, 0, 0x00, 0x0200 }, |
---|
| 576 | + /* pipe-grf */ |
---|
| 577 | + .u3otg0_port_en = { 0x40044, 15, 0, 0x0181, 0x1100 }, |
---|
| 578 | +}; |
---|
| 579 | + |
---|
| 580 | +static const struct clk_bulk_data rk3528_clks[] = { |
---|
| 581 | + { .id = "refclk" }, |
---|
| 582 | + { .id = "apbclk" }, |
---|
| 583 | + { .id = "pipe_clk" }, |
---|
| 584 | +}; |
---|
| 585 | + |
---|
| 586 | +static const struct rockchip_combphy_cfg rk3528_combphy_cfgs = { |
---|
| 587 | + .num_clks = ARRAY_SIZE(rk3528_clks), |
---|
| 588 | + .clks = rk3528_clks, |
---|
| 589 | + .grfcfg = &rk3528_combphy_grfcfgs, |
---|
| 590 | + .combphy_cfg = rk3528_combphy_cfg, |
---|
| 591 | +}; |
---|
| 592 | + |
---|
412 | 593 | static int rk3568_combphy_cfg(struct rockchip_combphy_priv *priv) |
---|
413 | 594 | { |
---|
414 | 595 | const struct rockchip_combphy_grfcfg *cfg = priv->cfg->grfcfg; |
---|
.. | .. |
---|
476 | 657 | |
---|
477 | 658 | /* Set PLL KVCO to min and set PLL charge pump current to max */ |
---|
478 | 659 | writel(0xf0, priv->mmio + (0xa << 2)); |
---|
| 660 | + |
---|
| 661 | + /* Set Rx squelch input filler bandwidth */ |
---|
| 662 | + writel(0x0e, priv->mmio + (0x14 << 2)); |
---|
479 | 663 | |
---|
480 | 664 | param_write(priv->phy_grf, &cfg->pipe_sel_usb, true); |
---|
481 | 665 | param_write(priv->phy_grf, &cfg->pipe_txcomp_sel, false); |
---|
.. | .. |
---|
635 | 819 | |
---|
636 | 820 | static const struct of_device_id rockchip_combphy_of_match[] = { |
---|
637 | 821 | { |
---|
| 822 | + .compatible = "rockchip,rk3528-naneng-combphy", |
---|
| 823 | + .data = &rk3528_combphy_cfgs, |
---|
| 824 | + }, |
---|
| 825 | + { |
---|
638 | 826 | .compatible = "rockchip,rk3568-naneng-combphy", |
---|
639 | 827 | .data = &rk3568_combphy_cfgs, |
---|
640 | 828 | }, |
---|