Lines Matching +full:pll0 +full:- +full:refclk
1 // SPDX-License-Identifier: GPL-2.0-only
9 #include <dt-bindings/phy/phy.h>
10 #include <dt-bindings/phy/phy-cadence.h>
12 #include <linux/clk-provider.h>
241 [CDNS_TORRENT_REFCLK_DRIVER] = "refclk-driver",
242 [CDNS_TORRENT_DERIVED_REFCLK] = "refclk-der",
243 [CDNS_TORRENT_RECEIVED_REFCLK] = "refclk-rec",
424 u32 offset = reg << ctx->reg_offset_shift; in cdns_regmap_write()
426 writew(val, ctx->base + offset); in cdns_regmap_write()
434 u32 offset = reg << ctx->reg_offset_shift; in cdns_regmap_read()
436 *val = readw(ctx->base + offset); in cdns_regmap_read()
446 writel(val, ctx->base + offset); in cdns_regmap_dptx_write()
457 *val = readl(ctx->base + offset); in cdns_regmap_dptx_read()
572 * Structure used to store values of PHY registers for voltage-related
573 * coefficients, for particular voltage swing and pre-emphasis level. Values
586 * Array consists of values of voltage-related registers for sd0801 PHY. A value
590 /* voltage swing 0, pre-emphasis 0->3 */
601 /* voltage swing 1, pre-emphasis 0->3 */
612 /* voltage swing 2, pre-emphasis 0->3 */
623 /* voltage swing 3, pre-emphasis 0->3 */
661 struct regmap *regmap = cdns_phy->regmap_common_cdb; in cdns_torrent_dp_enable_ssc_19_2mhz()
677 struct regmap *regmap = cdns_phy->regmap_common_cdb; in cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz()
781 struct regmap *regmap = cdns_phy->regmap_common_cdb; in cdns_torrent_dp_enable_ssc_25mhz()
797 struct regmap *regmap = cdns_phy->regmap_common_cdb; in cdns_torrent_dp_pma_cmn_vco_cfg_25mhz()
901 struct regmap *regmap = cdns_phy->regmap_common_cdb; in cdns_torrent_dp_pma_cmn_vco_cfg_100mhz()
989 struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg; in cdns_torrent_dp_set_pll_en()
1002 switch (dp->lanes) { in cdns_torrent_dp_set_pll_en()
1007 /* lanes 0-1 */ in cdns_torrent_dp_set_pll_en()
1011 /* lanes 0-3, all */ in cdns_torrent_dp_set_pll_en()
1044 struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg; in cdns_torrent_dp_set_power_state()
1068 /* lanes 0-1 */ in cdns_torrent_dp_set_power_state()
1074 /* lanes 0-3, all */ in cdns_torrent_dp_set_power_state()
1100 struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg; in cdns_torrent_dp_run()
1109 if (ret == -ETIMEDOUT) { in cdns_torrent_dp_run()
1110 dev_err(cdns_phy->dev, in cdns_torrent_dp_run()
1132 struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg; in cdns_torrent_dp_wait_pma_cmn_ready()
1136 if (ret == -ETIMEDOUT) { in cdns_torrent_dp_wait_pma_cmn_ready()
1137 dev_err(cdns_phy->dev, in cdns_torrent_dp_wait_pma_cmn_ready()
1139 return -ETIMEDOUT; in cdns_torrent_dp_wait_pma_cmn_ready()
1178 cdns_torrent_phy_write(cdns_phy->regmap_common_cdb, in cdns_torrent_dp_pma_cmn_rate()
1180 cdns_torrent_phy_write(cdns_phy->regmap_common_cdb, in cdns_torrent_dp_pma_cmn_rate()
1183 /* PMA lane configuration to deal with multi-link operation */ in cdns_torrent_dp_pma_cmn_rate()
1185 cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[i], in cdns_torrent_dp_pma_cmn_rate()
1198 /* Disable the cmn_pll0_en before re-programming the new data rate. */ in cdns_torrent_dp_configure_rate()
1199 regmap_field_write(cdns_phy->phy_pma_pll_raw_ctrl, 0x0); in cdns_torrent_dp_configure_rate()
1202 * Wait for PLL ready de-assertion. in cdns_torrent_dp_configure_rate()
1203 * For PLL0 - PHY_PMA_CMN_CTRL2[2] == 1 in cdns_torrent_dp_configure_rate()
1205 ret = regmap_field_read_poll_timeout(cdns_phy->phy_pma_cmn_ctrl_2, in cdns_torrent_dp_configure_rate()
1213 /* DP Rate Change - VCO Output settings. */ in cdns_torrent_dp_configure_rate()
1214 if (cdns_phy->ref_clk_rate == CLK_19_2_MHZ) in cdns_torrent_dp_configure_rate()
1216 cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(cdns_phy, dp->link_rate, dp->ssc); in cdns_torrent_dp_configure_rate()
1217 else if (cdns_phy->ref_clk_rate == CLK_25_MHZ) in cdns_torrent_dp_configure_rate()
1219 cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(cdns_phy, dp->link_rate, dp->ssc); in cdns_torrent_dp_configure_rate()
1220 else if (cdns_phy->ref_clk_rate == CLK_100_MHZ) in cdns_torrent_dp_configure_rate()
1222 cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(cdns_phy, dp->link_rate, dp->ssc); in cdns_torrent_dp_configure_rate()
1224 cdns_torrent_dp_pma_cmn_rate(cdns_phy, dp->link_rate, dp->lanes); in cdns_torrent_dp_configure_rate()
1227 regmap_field_write(cdns_phy->phy_pma_pll_raw_ctrl, 0x3); in cdns_torrent_dp_configure_rate()
1231 * For PLL0 - PHY_PMA_CMN_CTRL2[0] == 1 in cdns_torrent_dp_configure_rate()
1233 ret = regmap_field_read_poll_timeout(cdns_phy->phy_pma_cmn_ctrl_2, in cdns_torrent_dp_configure_rate()
1249 if (dp->set_rate) { in cdns_torrent_dp_verify_config()
1250 switch (dp->link_rate) { in cdns_torrent_dp_verify_config()
1262 return -EINVAL; in cdns_torrent_dp_verify_config()
1267 switch (dp->lanes) { in cdns_torrent_dp_verify_config()
1274 return -EINVAL; in cdns_torrent_dp_verify_config()
1278 if (dp->lanes > inst->num_lanes) in cdns_torrent_dp_verify_config()
1279 return -EINVAL; in cdns_torrent_dp_verify_config()
1282 * If changing voltages is required, check swing and pre-emphasis in cdns_torrent_dp_verify_config()
1283 * levels, per-lane. in cdns_torrent_dp_verify_config()
1285 if (dp->set_voltages) { in cdns_torrent_dp_verify_config()
1287 for (i = 0; i < dp->lanes; i++) { in cdns_torrent_dp_verify_config()
1288 if (dp->voltage[i] > 3 || dp->pre[i] > 3) in cdns_torrent_dp_verify_config()
1289 return -EINVAL; in cdns_torrent_dp_verify_config()
1291 /* Sum of voltage swing and pre-emphasis levels cannot in cdns_torrent_dp_verify_config()
1294 if (dp->voltage[i] + dp->pre[i] > 3) in cdns_torrent_dp_verify_config()
1295 return -EINVAL; in cdns_torrent_dp_verify_config()
1306 struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg; in cdns_torrent_dp_set_a0_pll()
1344 struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg; in cdns_torrent_dp_set_lanes()
1345 u8 lane_mask = (1 << dp->lanes) - 1; in cdns_torrent_dp_set_lanes()
1361 * and powered down when re-enabling the link in cdns_torrent_dp_set_lanes()
1366 cdns_torrent_dp_set_a0_pll(cdns_phy, dp->lanes); in cdns_torrent_dp_set_lanes()
1382 ret = cdns_torrent_dp_run(cdns_phy, dp->lanes); in cdns_torrent_dp_set_lanes()
1393 ret = cdns_torrent_dp_set_power_state(cdns_phy, dp->lanes, in cdns_torrent_dp_set_rate()
1410 ret = cdns_torrent_dp_set_power_state(cdns_phy, dp->lanes, in cdns_torrent_dp_set_rate()
1414 ret = cdns_torrent_dp_set_power_state(cdns_phy, dp->lanes, in cdns_torrent_dp_set_rate()
1423 /* Configure voltage swing and pre-emphasis for all enabled lanes. */
1430 for (lane = 0; lane < dp->lanes; lane++) { in cdns_torrent_dp_set_voltages()
1431 val = cdns_torrent_phy_read(cdns_phy->regmap_tx_lane_cdb[lane], in cdns_torrent_dp_set_voltages()
1438 cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[lane], in cdns_torrent_dp_set_voltages()
1441 cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[lane], in cdns_torrent_dp_set_voltages()
1443 val = vltg_coeff[dp->voltage[lane]][dp->pre[lane]].diag_tx_drv; in cdns_torrent_dp_set_voltages()
1444 cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[lane], in cdns_torrent_dp_set_voltages()
1446 val = vltg_coeff[dp->voltage[lane]][dp->pre[lane]].mgnfs_mult; in cdns_torrent_dp_set_voltages()
1447 cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[lane], in cdns_torrent_dp_set_voltages()
1450 val = vltg_coeff[dp->voltage[lane]][dp->pre[lane]].cpost_mult; in cdns_torrent_dp_set_voltages()
1451 cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[lane], in cdns_torrent_dp_set_voltages()
1455 val = cdns_torrent_phy_read(cdns_phy->regmap_tx_lane_cdb[lane], in cdns_torrent_dp_set_voltages()
1462 cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[lane], in cdns_torrent_dp_set_voltages()
1471 struct cdns_torrent_phy *cdns_phy = dev_get_drvdata(phy->dev.parent); in cdns_torrent_dp_configure()
1474 ret = cdns_torrent_dp_verify_config(inst, &opts->dp); in cdns_torrent_dp_configure()
1476 dev_err(&phy->dev, "invalid params for phy configure\n"); in cdns_torrent_dp_configure()
1480 if (opts->dp.set_lanes) { in cdns_torrent_dp_configure()
1481 ret = cdns_torrent_dp_set_lanes(cdns_phy, &opts->dp); in cdns_torrent_dp_configure()
1483 dev_err(&phy->dev, "cdns_torrent_dp_set_lanes failed\n"); in cdns_torrent_dp_configure()
1488 if (opts->dp.set_rate) { in cdns_torrent_dp_configure()
1489 ret = cdns_torrent_dp_set_rate(cdns_phy, &opts->dp); in cdns_torrent_dp_configure()
1491 dev_err(&phy->dev, "cdns_torrent_dp_set_rate failed\n"); in cdns_torrent_dp_configure()
1496 if (opts->dp.set_voltages) in cdns_torrent_dp_configure()
1497 cdns_torrent_dp_set_voltages(cdns_phy, &opts->dp); in cdns_torrent_dp_configure()
1505 struct cdns_torrent_phy *cdns_phy = dev_get_drvdata(phy->dev.parent); in cdns_torrent_phy_on()
1509 if (cdns_phy->nsubnodes == 1) { in cdns_torrent_phy_on()
1511 reset_control_deassert(inst->lnk_rst); in cdns_torrent_phy_on()
1514 ret = reset_control_deassert(cdns_phy->phy_rst); in cdns_torrent_phy_on()
1523 ret = regmap_field_read_poll_timeout(cdns_phy->phy_pma_cmn_ctrl_1, in cdns_torrent_phy_on()
1527 dev_err(cdns_phy->dev, "Timeout waiting for CMN ready\n"); in cdns_torrent_phy_on()
1531 if (inst->phy_type == TYPE_PCIE || inst->phy_type == TYPE_USB) { in cdns_torrent_phy_on()
1532 ret = regmap_field_read_poll_timeout(cdns_phy->phy_pcs_iso_link_ctrl_1[inst->mlane], in cdns_torrent_phy_on()
1535 if (ret == -ETIMEDOUT) { in cdns_torrent_phy_on()
1536 dev_err(cdns_phy->dev, "Timeout waiting for PHY status ready\n"); in cdns_torrent_phy_on()
1547 struct cdns_torrent_phy *cdns_phy = dev_get_drvdata(phy->dev.parent); in cdns_torrent_phy_off()
1550 if (cdns_phy->nsubnodes != 1) in cdns_torrent_phy_off()
1553 ret = reset_control_assert(cdns_phy->phy_rst); in cdns_torrent_phy_off()
1557 return reset_control_assert(inst->lnk_rst); in cdns_torrent_phy_off()
1563 struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg; in cdns_torrent_dp_common_init()
1572 cdns_torrent_dp_set_a0_pll(cdns_phy, inst->num_lanes); in cdns_torrent_dp_common_init()
1578 lane_bits = (1 << inst->num_lanes) - 1; in cdns_torrent_dp_common_init()
1589 if (cdns_phy->ref_clk_rate == CLK_19_2_MHZ) in cdns_torrent_dp_common_init()
1591 cdns_phy->max_bit_rate, in cdns_torrent_dp_common_init()
1593 else if (cdns_phy->ref_clk_rate == CLK_25_MHZ) in cdns_torrent_dp_common_init()
1595 cdns_phy->max_bit_rate, in cdns_torrent_dp_common_init()
1597 else if (cdns_phy->ref_clk_rate == CLK_100_MHZ) in cdns_torrent_dp_common_init()
1599 cdns_phy->max_bit_rate, in cdns_torrent_dp_common_init()
1602 cdns_torrent_dp_pma_cmn_rate(cdns_phy, cdns_phy->max_bit_rate, in cdns_torrent_dp_common_init()
1603 inst->num_lanes); in cdns_torrent_dp_common_init()
1606 regmap_field_write(cdns_phy->phy_reset_ctrl, 0x1); in cdns_torrent_dp_common_init()
1621 ret = cdns_torrent_dp_run(cdns_phy, inst->num_lanes); in cdns_torrent_dp_start()
1629 struct cdns_torrent_phy *cdns_phy = dev_get_drvdata(phy->dev.parent); in cdns_torrent_dp_init()
1631 switch (cdns_phy->ref_clk_rate) { in cdns_torrent_dp_init()
1638 dev_err(cdns_phy->dev, "Unsupported Ref Clock Rate\n"); in cdns_torrent_dp_init()
1639 return -EINVAL; in cdns_torrent_dp_init()
1651 regmap_field_write(derived_refclk->cmn_cdiag_refclk_ovrd_4, 1); in cdns_torrent_derived_refclk_enable()
1652 regmap_field_write(derived_refclk->phy_pipe_cmn_ctrl1_0, 1); in cdns_torrent_derived_refclk_enable()
1661 regmap_field_write(derived_refclk->phy_pipe_cmn_ctrl1_0, 0); in cdns_torrent_derived_refclk_disable()
1662 regmap_field_write(derived_refclk->cmn_cdiag_refclk_ovrd_4, 0); in cdns_torrent_derived_refclk_disable()
1670 regmap_field_read(derived_refclk->cmn_cdiag_refclk_ovrd_4, &val); in cdns_torrent_derived_refclk_is_enabled()
1684 struct device *dev = cdns_phy->dev; in cdns_torrent_derived_refclk_register()
1694 return -ENOMEM; in cdns_torrent_derived_refclk_register()
1705 init = &derived_refclk->clk_data; in cdns_torrent_derived_refclk_register()
1709 init->parent_names = &parent_name; in cdns_torrent_derived_refclk_register()
1710 init->num_parents = 1; in cdns_torrent_derived_refclk_register()
1712 init->ops = &cdns_torrent_derived_refclk_ops; in cdns_torrent_derived_refclk_register()
1713 init->flags = 0; in cdns_torrent_derived_refclk_register()
1714 init->name = clk_name; in cdns_torrent_derived_refclk_register()
1716 derived_refclk->phy_pipe_cmn_ctrl1_0 = cdns_phy->phy_pipe_cmn_ctrl1_0; in cdns_torrent_derived_refclk_register()
1717 derived_refclk->cmn_cdiag_refclk_ovrd_4 = cdns_phy->cmn_cdiag_refclk_ovrd_4; in cdns_torrent_derived_refclk_register()
1719 derived_refclk->hw.init = init; in cdns_torrent_derived_refclk_register()
1721 hw = &derived_refclk->hw; in cdns_torrent_derived_refclk_register()
1726 cdns_phy->clk_hw_data->hws[CDNS_TORRENT_DERIVED_REFCLK] = hw; in cdns_torrent_derived_refclk_register()
1735 regmap_field_write(received_refclk->phy_pipe_cmn_ctrl1_0, 1); in cdns_torrent_received_refclk_enable()
1744 regmap_field_write(received_refclk->phy_pipe_cmn_ctrl1_0, 0); in cdns_torrent_received_refclk_disable()
1752 regmap_field_read(received_refclk->phy_pipe_cmn_ctrl1_0, &val); in cdns_torrent_received_refclk_is_enabled()
1753 regmap_field_read(received_refclk->cmn_cdiag_refclk_ovrd_4, &cmn_val); in cdns_torrent_received_refclk_is_enabled()
1767 struct device *dev = cdns_phy->dev; in cdns_torrent_received_refclk_register()
1777 return -ENOMEM; in cdns_torrent_received_refclk_register()
1788 init = &received_refclk->clk_data; in cdns_torrent_received_refclk_register()
1792 init->parent_names = &parent_name; in cdns_torrent_received_refclk_register()
1793 init->num_parents = 1; in cdns_torrent_received_refclk_register()
1795 init->ops = &cdns_torrent_received_refclk_ops; in cdns_torrent_received_refclk_register()
1796 init->flags = 0; in cdns_torrent_received_refclk_register()
1797 init->name = clk_name; in cdns_torrent_received_refclk_register()
1799 received_refclk->phy_pipe_cmn_ctrl1_0 = cdns_phy->phy_pipe_cmn_ctrl1_0; in cdns_torrent_received_refclk_register()
1800 received_refclk->cmn_cdiag_refclk_ovrd_4 = cdns_phy->cmn_cdiag_refclk_ovrd_4; in cdns_torrent_received_refclk_register()
1802 received_refclk->hw.init = init; in cdns_torrent_received_refclk_register()
1804 hw = &received_refclk->hw; in cdns_torrent_received_refclk_register()
1809 cdns_phy->clk_hw_data->hws[CDNS_TORRENT_RECEIVED_REFCLK] = hw; in cdns_torrent_received_refclk_register()
1818 regmap_field_write(refclk_driver->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_6], 0); in cdns_torrent_refclk_driver_enable()
1819 regmap_field_write(refclk_driver->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_5], 1); in cdns_torrent_refclk_driver_enable()
1820 regmap_field_write(refclk_driver->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_1], 0); in cdns_torrent_refclk_driver_enable()
1829 regmap_field_write(refclk_driver->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_1], 1); in cdns_torrent_refclk_driver_disable()
1837 regmap_field_read(refclk_driver->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_1], &val); in cdns_torrent_refclk_driver_is_enabled()
1847 regmap_field_read(refclk_driver->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_4], &val); in cdns_torrent_refclk_driver_get_parent()
1857 return regmap_field_write(refclk_driver->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_4], val); in cdns_torrent_refclk_driver_set_parent()
1871 struct device *dev = cdns_phy->dev; in cdns_torrent_refclk_driver_register()
1883 return -ENOMEM; in cdns_torrent_refclk_driver_register()
1888 return -ENOMEM; in cdns_torrent_refclk_driver_register()
1891 hw = cdns_phy->clk_hw_data->hws[refclk_driver_parent_index[i]]; in cdns_torrent_refclk_driver_register()
1893 dev_err(dev, "No parent clock for refclk driver clock\n"); in cdns_torrent_refclk_driver_register()
1894 return IS_ERR(hw) ? PTR_ERR(hw) : -ENOENT; in cdns_torrent_refclk_driver_register()
1902 init = &refclk_driver->clk_data; in cdns_torrent_refclk_driver_register()
1904 init->ops = &cdns_torrent_refclk_driver_ops; in cdns_torrent_refclk_driver_register()
1905 init->flags = CLK_SET_RATE_NO_REPARENT; in cdns_torrent_refclk_driver_register()
1906 init->parent_names = parent_names; in cdns_torrent_refclk_driver_register()
1907 init->num_parents = num_parents; in cdns_torrent_refclk_driver_register()
1908 init->name = clk_name; in cdns_torrent_refclk_driver_register()
1910 regmap = cdns_phy->regmap_common_cdb; in cdns_torrent_refclk_driver_register()
1915 dev_err(dev, "Refclk driver CMN reg field init failed\n"); in cdns_torrent_refclk_driver_register()
1918 refclk_driver->cmn_fields[i] = field; in cdns_torrent_refclk_driver_register()
1922 regmap_field_write(refclk_driver->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_4], 1); in cdns_torrent_refclk_driver_register()
1924 refclk_driver->hw.init = init; in cdns_torrent_refclk_driver_register()
1926 hw = &refclk_driver->hw; in cdns_torrent_refclk_driver_register()
1931 cdns_phy->clk_hw_data->hws[CDNS_TORRENT_REFCLK_DRIVER] = hw; in cdns_torrent_refclk_driver_register()
1945 return ERR_PTR(-ENOMEM); in cdns_regmap_init()
1947 ctx->dev = dev; in cdns_regmap_init()
1948 ctx->base = base + block_offset; in cdns_regmap_init()
1949 ctx->reg_offset_shift = reg_offset_shift; in cdns_regmap_init()
1956 struct device *dev = cdns_phy->dev; in cdns_torrent_dp_regfield_init()
1960 regmap = cdns_phy->regmap_dptx_phy_reg; in cdns_torrent_dp_regfield_init()
1966 cdns_phy->phy_reset_ctrl = field; in cdns_torrent_dp_regfield_init()
1973 struct device *dev = cdns_phy->dev; in cdns_torrent_regfield_init()
1978 regmap = cdns_phy->regmap_phy_pcs_common_cdb; in cdns_torrent_regfield_init()
1984 cdns_phy->phy_pll_cfg = field; in cdns_torrent_regfield_init()
1986 regmap = cdns_phy->regmap_phy_pcs_common_cdb; in cdns_torrent_regfield_init()
1992 cdns_phy->phy_pipe_cmn_ctrl1_0 = field; in cdns_torrent_regfield_init()
1994 regmap = cdns_phy->regmap_common_cdb; in cdns_torrent_regfield_init()
2000 cdns_phy->cmn_cdiag_refclk_ovrd_4 = field; in cdns_torrent_regfield_init()
2002 regmap = cdns_phy->regmap_phy_pma_common_cdb; in cdns_torrent_regfield_init()
2008 cdns_phy->phy_pma_cmn_ctrl_1 = field; in cdns_torrent_regfield_init()
2010 regmap = cdns_phy->regmap_phy_pma_common_cdb; in cdns_torrent_regfield_init()
2016 cdns_phy->phy_pma_cmn_ctrl_2 = field; in cdns_torrent_regfield_init()
2018 regmap = cdns_phy->regmap_phy_pma_common_cdb; in cdns_torrent_regfield_init()
2024 cdns_phy->phy_pma_pll_raw_ctrl = field; in cdns_torrent_regfield_init()
2027 regmap = cdns_phy->regmap_phy_pcs_lane_cdb[i]; in cdns_torrent_regfield_init()
2033 cdns_phy->phy_pcs_iso_link_ctrl_1[i] = field; in cdns_torrent_regfield_init()
2041 void __iomem *base = cdns_phy->base; in cdns_torrent_dp_regmap_init()
2042 struct device *dev = cdns_phy->dev; in cdns_torrent_dp_regmap_init()
2047 reg_offset_shift = cdns_phy->init_data->reg_offset_shift; in cdns_torrent_dp_regmap_init()
2057 cdns_phy->regmap_dptx_phy_reg = regmap; in cdns_torrent_dp_regmap_init()
2064 void __iomem *sd_base = cdns_phy->sd_base; in cdns_torrent_regmap_init()
2066 struct device *dev = cdns_phy->dev; in cdns_torrent_regmap_init()
2071 block_offset_shift = cdns_phy->init_data->block_offset_shift; in cdns_torrent_regmap_init()
2072 reg_offset_shift = cdns_phy->init_data->reg_offset_shift; in cdns_torrent_regmap_init()
2084 cdns_phy->regmap_tx_lane_cdb[i] = regmap; in cdns_torrent_regmap_init()
2095 cdns_phy->regmap_rx_lane_cdb[i] = regmap; in cdns_torrent_regmap_init()
2106 cdns_phy->regmap_phy_pcs_lane_cdb[i] = regmap; in cdns_torrent_regmap_init()
2117 cdns_phy->regmap_common_cdb = regmap; in cdns_torrent_regmap_init()
2127 cdns_phy->regmap_phy_pcs_common_cdb = regmap; in cdns_torrent_regmap_init()
2137 cdns_phy->regmap_phy_pma_common_cdb = regmap; in cdns_torrent_regmap_init()
2144 struct cdns_torrent_phy *cdns_phy = dev_get_drvdata(phy->dev.parent); in cdns_torrent_phy_init()
2145 const struct cdns_torrent_data *init_data = cdns_phy->init_data; in cdns_torrent_phy_init()
2147 enum cdns_torrent_ref_clk ref_clk = cdns_phy->ref_clk_rate; in cdns_torrent_phy_init()
2150 enum cdns_torrent_phy_type phy_type = inst->phy_type; in cdns_torrent_phy_init()
2151 enum cdns_torrent_ssc_mode ssc = inst->ssc_mode; in cdns_torrent_phy_init()
2158 if (cdns_phy->nsubnodes > 1) in cdns_torrent_phy_init()
2169 link_cmn_vals = init_data->link_cmn_vals[phy_type][TYPE_NONE][ssc]; in cdns_torrent_phy_init()
2171 reg_pairs = link_cmn_vals->reg_pairs; in cdns_torrent_phy_init()
2172 num_regs = link_cmn_vals->num_regs; in cdns_torrent_phy_init()
2173 regmap = cdns_phy->regmap_common_cdb; in cdns_torrent_phy_init()
2179 regmap_field_write(cdns_phy->phy_pll_cfg, reg_pairs[0].val); in cdns_torrent_phy_init()
2186 xcvr_diag_vals = init_data->xcvr_diag_vals[phy_type][TYPE_NONE][ssc]; in cdns_torrent_phy_init()
2188 reg_pairs = xcvr_diag_vals->reg_pairs; in cdns_torrent_phy_init()
2189 num_regs = xcvr_diag_vals->num_regs; in cdns_torrent_phy_init()
2190 for (i = 0; i < inst->num_lanes; i++) { in cdns_torrent_phy_init()
2191 regmap = cdns_phy->regmap_tx_lane_cdb[i + inst->mlane]; in cdns_torrent_phy_init()
2199 pcs_cmn_vals = init_data->pcs_cmn_vals[phy_type][TYPE_NONE][ssc]; in cdns_torrent_phy_init()
2201 reg_pairs = pcs_cmn_vals->reg_pairs; in cdns_torrent_phy_init()
2202 num_regs = pcs_cmn_vals->num_regs; in cdns_torrent_phy_init()
2203 regmap = cdns_phy->regmap_phy_pcs_common_cdb; in cdns_torrent_phy_init()
2210 cmn_vals = init_data->cmn_vals[ref_clk][phy_type][TYPE_NONE][ssc]; in cdns_torrent_phy_init()
2212 reg_pairs = cmn_vals->reg_pairs; in cdns_torrent_phy_init()
2213 num_regs = cmn_vals->num_regs; in cdns_torrent_phy_init()
2214 regmap = cdns_phy->regmap_common_cdb; in cdns_torrent_phy_init()
2221 tx_ln_vals = init_data->tx_ln_vals[ref_clk][phy_type][TYPE_NONE][ssc]; in cdns_torrent_phy_init()
2223 reg_pairs = tx_ln_vals->reg_pairs; in cdns_torrent_phy_init()
2224 num_regs = tx_ln_vals->num_regs; in cdns_torrent_phy_init()
2225 for (i = 0; i < inst->num_lanes; i++) { in cdns_torrent_phy_init()
2226 regmap = cdns_phy->regmap_tx_lane_cdb[i + inst->mlane]; in cdns_torrent_phy_init()
2234 rx_ln_vals = init_data->rx_ln_vals[ref_clk][phy_type][TYPE_NONE][ssc]; in cdns_torrent_phy_init()
2236 reg_pairs = rx_ln_vals->reg_pairs; in cdns_torrent_phy_init()
2237 num_regs = rx_ln_vals->num_regs; in cdns_torrent_phy_init()
2238 for (i = 0; i < inst->num_lanes; i++) { in cdns_torrent_phy_init()
2239 regmap = cdns_phy->regmap_rx_lane_cdb[i + inst->mlane]; in cdns_torrent_phy_init()
2276 const struct cdns_torrent_data *init_data = cdns_phy->init_data; in cdns_torrent_phy_configure_multilink()
2278 enum cdns_torrent_ref_clk ref_clk = cdns_phy->ref_clk_rate; in cdns_torrent_phy_configure_multilink()
2289 if (cdns_phy->nsubnodes != 2) in cdns_torrent_phy_configure_multilink()
2290 return -EINVAL; in cdns_torrent_phy_configure_multilink()
2292 phy_t1 = cdns_phy->phys[0].phy_type; in cdns_torrent_phy_configure_multilink()
2293 phy_t2 = cdns_phy->phys[1].phy_type; in cdns_torrent_phy_configure_multilink()
2299 for (node = 0; node < cdns_phy->nsubnodes; node++) { in cdns_torrent_phy_configure_multilink()
2309 mlane = cdns_phy->phys[node].mlane; in cdns_torrent_phy_configure_multilink()
2310 ssc = cdns_phy->phys[node].ssc_mode; in cdns_torrent_phy_configure_multilink()
2311 num_lanes = cdns_phy->phys[node].num_lanes; in cdns_torrent_phy_configure_multilink()
2323 link_cmn_vals = init_data->link_cmn_vals[phy_t1][phy_t2][ssc]; in cdns_torrent_phy_configure_multilink()
2325 reg_pairs = link_cmn_vals->reg_pairs; in cdns_torrent_phy_configure_multilink()
2326 num_regs = link_cmn_vals->num_regs; in cdns_torrent_phy_configure_multilink()
2327 regmap = cdns_phy->regmap_common_cdb; in cdns_torrent_phy_configure_multilink()
2333 regmap_field_write(cdns_phy->phy_pll_cfg, in cdns_torrent_phy_configure_multilink()
2341 xcvr_diag_vals = init_data->xcvr_diag_vals[phy_t1][phy_t2][ssc]; in cdns_torrent_phy_configure_multilink()
2343 reg_pairs = xcvr_diag_vals->reg_pairs; in cdns_torrent_phy_configure_multilink()
2344 num_regs = xcvr_diag_vals->num_regs; in cdns_torrent_phy_configure_multilink()
2346 regmap = cdns_phy->regmap_tx_lane_cdb[i + mlane]; in cdns_torrent_phy_configure_multilink()
2354 pcs_cmn_vals = init_data->pcs_cmn_vals[phy_t1][phy_t2][ssc]; in cdns_torrent_phy_configure_multilink()
2356 reg_pairs = pcs_cmn_vals->reg_pairs; in cdns_torrent_phy_configure_multilink()
2357 num_regs = pcs_cmn_vals->num_regs; in cdns_torrent_phy_configure_multilink()
2358 regmap = cdns_phy->regmap_phy_pcs_common_cdb; in cdns_torrent_phy_configure_multilink()
2365 cmn_vals = init_data->cmn_vals[ref_clk][phy_t1][phy_t2][ssc]; in cdns_torrent_phy_configure_multilink()
2367 reg_pairs = cmn_vals->reg_pairs; in cdns_torrent_phy_configure_multilink()
2368 num_regs = cmn_vals->num_regs; in cdns_torrent_phy_configure_multilink()
2369 regmap = cdns_phy->regmap_common_cdb; in cdns_torrent_phy_configure_multilink()
2376 tx_ln_vals = init_data->tx_ln_vals[ref_clk][phy_t1][phy_t2][ssc]; in cdns_torrent_phy_configure_multilink()
2378 reg_pairs = tx_ln_vals->reg_pairs; in cdns_torrent_phy_configure_multilink()
2379 num_regs = tx_ln_vals->num_regs; in cdns_torrent_phy_configure_multilink()
2381 regmap = cdns_phy->regmap_tx_lane_cdb[i + mlane]; in cdns_torrent_phy_configure_multilink()
2389 rx_ln_vals = init_data->rx_ln_vals[ref_clk][phy_t1][phy_t2][ssc]; in cdns_torrent_phy_configure_multilink()
2391 reg_pairs = rx_ln_vals->reg_pairs; in cdns_torrent_phy_configure_multilink()
2392 num_regs = rx_ln_vals->num_regs; in cdns_torrent_phy_configure_multilink()
2394 regmap = cdns_phy->regmap_rx_lane_cdb[i + mlane]; in cdns_torrent_phy_configure_multilink()
2401 reset_control_deassert(cdns_phy->phys[node].lnk_rst); in cdns_torrent_phy_configure_multilink()
2405 ret = reset_control_deassert(cdns_phy->phy_rst); in cdns_torrent_phy_configure_multilink()
2414 struct device *dev = cdns_phy->dev; in cdns_torrent_clk_cleanup()
2416 of_clk_del_provider(dev->of_node); in cdns_torrent_clk_cleanup()
2421 struct device *dev = cdns_phy->dev; in cdns_torrent_clk_register()
2422 struct device_node *node = dev->of_node; in cdns_torrent_clk_register()
2428 return -ENOMEM; in cdns_torrent_clk_register()
2430 data->num = CDNS_TORRENT_OUTPUT_CLOCKS; in cdns_torrent_clk_register()
2431 cdns_phy->clk_hw_data = data; in cdns_torrent_clk_register()
2435 dev_err(dev, "failed to register derived refclk\n"); in cdns_torrent_clk_register()
2441 dev_err(dev, "failed to register received refclk\n"); in cdns_torrent_clk_register()
2447 dev_err(dev, "failed to register refclk driver\n"); in cdns_torrent_clk_register()
2453 dev_err(dev, "Failed to add clock provider: %s\n", node->name); in cdns_torrent_clk_register()
2462 struct device *dev = cdns_phy->dev; in cdns_torrent_reset()
2464 cdns_phy->phy_rst = devm_reset_control_get_exclusive_by_index(dev, 0); in cdns_torrent_reset()
2465 if (IS_ERR(cdns_phy->phy_rst)) { in cdns_torrent_reset()
2467 dev->of_node->full_name); in cdns_torrent_reset()
2468 return PTR_ERR(cdns_phy->phy_rst); in cdns_torrent_reset()
2471 cdns_phy->apb_rst = devm_reset_control_get_optional_exclusive(dev, "torrent_apb"); in cdns_torrent_reset()
2472 if (IS_ERR(cdns_phy->apb_rst)) { in cdns_torrent_reset()
2474 dev->of_node->full_name); in cdns_torrent_reset()
2475 return PTR_ERR(cdns_phy->apb_rst); in cdns_torrent_reset()
2483 struct device *dev = cdns_phy->dev; in cdns_torrent_clk()
2487 cdns_phy->clk = devm_clk_get(dev, "refclk"); in cdns_torrent_clk()
2488 if (IS_ERR(cdns_phy->clk)) { in cdns_torrent_clk()
2490 return PTR_ERR(cdns_phy->clk); in cdns_torrent_clk()
2493 ret = clk_prepare_enable(cdns_phy->clk); in cdns_torrent_clk()
2495 dev_err(cdns_phy->dev, "Failed to prepare ref clock\n"); in cdns_torrent_clk()
2499 ref_clk_rate = clk_get_rate(cdns_phy->clk); in cdns_torrent_clk()
2501 dev_err(cdns_phy->dev, "Failed to get ref clock rate\n"); in cdns_torrent_clk()
2502 clk_disable_unprepare(cdns_phy->clk); in cdns_torrent_clk()
2503 return -EINVAL; in cdns_torrent_clk()
2508 cdns_phy->ref_clk_rate = CLK_19_2_MHZ; in cdns_torrent_clk()
2511 cdns_phy->ref_clk_rate = CLK_25_MHZ; in cdns_torrent_clk()
2514 cdns_phy->ref_clk_rate = CLK_100_MHZ; in cdns_torrent_clk()
2517 dev_err(cdns_phy->dev, "Invalid Ref Clock Rate\n"); in cdns_torrent_clk()
2518 clk_disable_unprepare(cdns_phy->clk); in cdns_torrent_clk()
2519 return -EINVAL; in cdns_torrent_clk()
2528 struct device *dev = &pdev->dev; in cdns_torrent_phy_probe()
2541 return -EINVAL; in cdns_torrent_phy_probe()
2545 return -ENOMEM; in cdns_torrent_phy_probe()
2548 cdns_phy->dev = dev; in cdns_torrent_phy_probe()
2549 cdns_phy->init_data = data; in cdns_torrent_phy_probe()
2551 cdns_phy->sd_base = devm_platform_ioremap_resource(pdev, 0); in cdns_torrent_phy_probe()
2552 if (IS_ERR(cdns_phy->sd_base)) in cdns_torrent_phy_probe()
2553 return PTR_ERR(cdns_phy->sd_base); in cdns_torrent_phy_probe()
2555 subnodes = of_get_available_child_count(dev->of_node); in cdns_torrent_phy_probe()
2558 return -EINVAL; in cdns_torrent_phy_probe()
2573 regmap_field_read(cdns_phy->phy_pma_cmn_ctrl_1, &already_configured); in cdns_torrent_phy_probe()
2585 reset_control_deassert(cdns_phy->apb_rst); in cdns_torrent_phy_probe()
2588 for_each_available_child_of_node(dev->of_node, child) { in cdns_torrent_phy_probe()
2595 cdns_phy->phys[node].lnk_rst = in cdns_torrent_phy_probe()
2597 if (IS_ERR(cdns_phy->phys[node].lnk_rst)) { in cdns_torrent_phy_probe()
2599 child->full_name); in cdns_torrent_phy_probe()
2600 ret = PTR_ERR(cdns_phy->phys[node].lnk_rst); in cdns_torrent_phy_probe()
2605 &cdns_phy->phys[node].mlane)) { in cdns_torrent_phy_probe()
2606 dev_err(dev, "%s: No \"reg\"-property.\n", in cdns_torrent_phy_probe()
2607 child->full_name); in cdns_torrent_phy_probe()
2608 ret = -EINVAL; in cdns_torrent_phy_probe()
2612 if (of_property_read_u32(child, "cdns,phy-type", &phy_type)) { in cdns_torrent_phy_probe()
2613 dev_err(dev, "%s: No \"cdns,phy-type\"-property.\n", in cdns_torrent_phy_probe()
2614 child->full_name); in cdns_torrent_phy_probe()
2615 ret = -EINVAL; in cdns_torrent_phy_probe()
2621 cdns_phy->phys[node].phy_type = TYPE_PCIE; in cdns_torrent_phy_probe()
2624 cdns_phy->phys[node].phy_type = TYPE_DP; in cdns_torrent_phy_probe()
2627 cdns_phy->phys[node].phy_type = TYPE_SGMII; in cdns_torrent_phy_probe()
2630 cdns_phy->phys[node].phy_type = TYPE_QSGMII; in cdns_torrent_phy_probe()
2633 cdns_phy->phys[node].phy_type = TYPE_USB; in cdns_torrent_phy_probe()
2637 ret = -EINVAL; in cdns_torrent_phy_probe()
2641 if (of_property_read_u32(child, "cdns,num-lanes", in cdns_torrent_phy_probe()
2642 &cdns_phy->phys[node].num_lanes)) { in cdns_torrent_phy_probe()
2643 dev_err(dev, "%s: No \"cdns,num-lanes\"-property.\n", in cdns_torrent_phy_probe()
2644 child->full_name); in cdns_torrent_phy_probe()
2645 ret = -EINVAL; in cdns_torrent_phy_probe()
2649 total_num_lanes += cdns_phy->phys[node].num_lanes; in cdns_torrent_phy_probe()
2652 cdns_phy->phys[node].ssc_mode = NO_SSC; in cdns_torrent_phy_probe()
2653 of_property_read_u32(child, "cdns,ssc-mode", in cdns_torrent_phy_probe()
2654 &cdns_phy->phys[node].ssc_mode); in cdns_torrent_phy_probe()
2665 if (cdns_phy->phys[node].phy_type == TYPE_DP) { in cdns_torrent_phy_probe()
2666 switch (cdns_phy->phys[node].num_lanes) { in cdns_torrent_phy_probe()
2674 cdns_phy->phys[node].num_lanes); in cdns_torrent_phy_probe()
2675 ret = -EINVAL; in cdns_torrent_phy_probe()
2679 cdns_phy->max_bit_rate = DEFAULT_MAX_BIT_RATE; in cdns_torrent_phy_probe()
2680 of_property_read_u32(child, "cdns,max-bit-rate", in cdns_torrent_phy_probe()
2681 &cdns_phy->max_bit_rate); in cdns_torrent_phy_probe()
2683 switch (cdns_phy->max_bit_rate) { in cdns_torrent_phy_probe()
2696 cdns_phy->max_bit_rate); in cdns_torrent_phy_probe()
2697 ret = -EINVAL; in cdns_torrent_phy_probe()
2702 cdns_phy->base = devm_platform_ioremap_resource(pdev, 1); in cdns_torrent_phy_probe()
2703 if (IS_ERR(cdns_phy->base)) { in cdns_torrent_phy_probe()
2704 ret = PTR_ERR(cdns_phy->base); in cdns_torrent_phy_probe()
2721 cdns_phy->max_bit_rate / 1000, in cdns_torrent_phy_probe()
2722 cdns_phy->max_bit_rate % 1000); in cdns_torrent_phy_probe()
2724 gphy->attrs.bus_width = cdns_phy->phys[node].num_lanes; in cdns_torrent_phy_probe()
2725 gphy->attrs.max_link_rate = cdns_phy->max_bit_rate; in cdns_torrent_phy_probe()
2726 gphy->attrs.mode = PHY_MODE_DP; in cdns_torrent_phy_probe()
2729 cdns_phy->phys[node].phy = gphy; in cdns_torrent_phy_probe()
2730 phy_set_drvdata(gphy, &cdns_phy->phys[node]); in cdns_torrent_phy_probe()
2734 cdns_phy->nsubnodes = node; in cdns_torrent_phy_probe()
2738 ret = -EINVAL; in cdns_torrent_phy_probe()
2742 if (cdns_phy->nsubnodes > 1 && !already_configured) { in cdns_torrent_phy_probe()
2754 if (cdns_phy->nsubnodes > 1) in cdns_torrent_phy_probe()
2755 dev_dbg(dev, "Multi-link: %s (%d lanes) & %s (%d lanes)", in cdns_torrent_phy_probe()
2756 cdns_torrent_get_phy_type(cdns_phy->phys[0].phy_type), in cdns_torrent_phy_probe()
2757 cdns_phy->phys[0].num_lanes, in cdns_torrent_phy_probe()
2758 cdns_torrent_get_phy_type(cdns_phy->phys[1].phy_type), in cdns_torrent_phy_probe()
2759 cdns_phy->phys[1].num_lanes); in cdns_torrent_phy_probe()
2762 cdns_torrent_get_phy_type(cdns_phy->phys[0].phy_type), in cdns_torrent_phy_probe()
2763 cdns_phy->phys[0].num_lanes); in cdns_torrent_phy_probe()
2771 reset_control_put(cdns_phy->phys[i].lnk_rst); in cdns_torrent_phy_probe()
2773 reset_control_assert(cdns_phy->apb_rst); in cdns_torrent_phy_probe()
2774 clk_disable_unprepare(cdns_phy->clk); in cdns_torrent_phy_probe()
2785 reset_control_assert(cdns_phy->phy_rst); in cdns_torrent_phy_remove()
2786 reset_control_assert(cdns_phy->apb_rst); in cdns_torrent_phy_remove()
2787 for (i = 0; i < cdns_phy->nsubnodes; i++) { in cdns_torrent_phy_remove()
2788 reset_control_assert(cdns_phy->phys[i].lnk_rst); in cdns_torrent_phy_remove()
2789 reset_control_put(cdns_phy->phys[i].lnk_rst); in cdns_torrent_phy_remove()
2792 clk_disable_unprepare(cdns_phy->clk); in cdns_torrent_phy_remove()
4698 .compatible = "cdns,torrent-phy",
4702 .compatible = "ti,j721e-serdes-10g",
4713 .name = "cdns-torrent-phy",