Lines Matching +full:enable +full:- +full:ssc
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>
243 [CDNS_TORRENT_REFCLK_DRIVER] = "refclk-driver",
244 [CDNS_TORRENT_DERIVED_REFCLK] = "refclk-der",
245 [CDNS_TORRENT_RECEIVED_REFCLK] = "refclk-rec",
334 #define CDNS_TORRENT_KEY(refclk0, refclk1, link0, link1, ssc) \ argument
339 (((ssc) << SSC_SHIFT) & SSC_MASK))
468 enum cdns_torrent_ssc_mode ssc) in cdns_torrent_get_tbl_vals() argument
471 u32 key = CDNS_TORRENT_KEY(refclk0, refclk1, link0, link1, ssc); in cdns_torrent_get_tbl_vals()
473 for (i = 0; i < tbl->num_entries; i++) { in cdns_torrent_get_tbl_vals()
474 if (tbl->entries[i].key == key) in cdns_torrent_get_tbl_vals()
475 return tbl->entries[i].vals; in cdns_torrent_get_tbl_vals()
484 u32 offset = reg << ctx->reg_offset_shift; in cdns_regmap_write()
486 writew(val, ctx->base + offset); in cdns_regmap_write()
494 u32 offset = reg << ctx->reg_offset_shift; in cdns_regmap_read()
496 *val = readw(ctx->base + offset); in cdns_regmap_read()
506 writel(val, ctx->base + offset); in cdns_regmap_dptx_write()
517 *val = readl(ctx->base + offset); in cdns_regmap_dptx_read()
632 * Structure used to store values of PHY registers for voltage-related
633 * coefficients, for particular voltage swing and pre-emphasis level. Values
646 * Array consists of values of voltage-related registers for sd0801 PHY. A value
650 /* voltage swing 0, pre-emphasis 0->3 */
661 /* voltage swing 1, pre-emphasis 0->3 */
672 /* voltage swing 2, pre-emphasis 0->3 */
683 /* voltage swing 3, pre-emphasis 0->3 */
717 * Set registers responsible for enabling and configuring SSC, with second and
724 struct regmap *regmap = cdns_phy->regmap_common_cdb; in cdns_torrent_dp_enable_ssc_19_2mhz()
738 u32 rate, bool ssc) in cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz() argument
740 struct regmap *regmap = cdns_phy->regmap_common_cdb; in cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz()
757 if (ssc) in cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz()
774 if (ssc) in cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz()
790 if (ssc) in cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz()
805 if (ssc) in cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz()
810 if (ssc) { in cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz()
818 /* Set reset register values to disable SSC */ in cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz()
838 * Set registers responsible for enabling and configuring SSC, with second
844 struct regmap *regmap = cdns_phy->regmap_common_cdb; in cdns_torrent_dp_enable_ssc_25mhz()
858 u32 rate, bool ssc) in cdns_torrent_dp_pma_cmn_vco_cfg_25mhz() argument
860 struct regmap *regmap = cdns_phy->regmap_common_cdb; in cdns_torrent_dp_pma_cmn_vco_cfg_25mhz()
875 if (ssc) in cdns_torrent_dp_pma_cmn_vco_cfg_25mhz()
890 if (ssc) in cdns_torrent_dp_pma_cmn_vco_cfg_25mhz()
904 if (ssc) in cdns_torrent_dp_pma_cmn_vco_cfg_25mhz()
917 if (ssc) in cdns_torrent_dp_pma_cmn_vco_cfg_25mhz()
925 if (ssc) { in cdns_torrent_dp_pma_cmn_vco_cfg_25mhz()
939 /* Set reset register values to disable SSC */ in cdns_torrent_dp_pma_cmn_vco_cfg_25mhz()
962 u32 rate, bool ssc) in cdns_torrent_dp_pma_cmn_vco_cfg_100mhz() argument
964 struct regmap *regmap = cdns_phy->regmap_common_cdb; in cdns_torrent_dp_pma_cmn_vco_cfg_100mhz()
971 if (cdns_phy->dp_pll & DP_PLL0) in cdns_torrent_dp_pma_cmn_vco_cfg_100mhz()
974 if (cdns_phy->dp_pll & DP_PLL1) { in cdns_torrent_dp_pma_cmn_vco_cfg_100mhz()
984 if (cdns_phy->dp_pll & DP_PLL0) { in cdns_torrent_dp_pma_cmn_vco_cfg_100mhz()
995 if (cdns_phy->dp_pll & DP_PLL1) { in cdns_torrent_dp_pma_cmn_vco_cfg_100mhz()
1010 if (cdns_phy->dp_pll & DP_PLL0) { in cdns_torrent_dp_pma_cmn_vco_cfg_100mhz()
1021 if (cdns_phy->dp_pll & DP_PLL1) { in cdns_torrent_dp_pma_cmn_vco_cfg_100mhz()
1035 if (cdns_phy->dp_pll & DP_PLL0) { in cdns_torrent_dp_pma_cmn_vco_cfg_100mhz()
1045 if (cdns_phy->dp_pll & DP_PLL1) { in cdns_torrent_dp_pma_cmn_vco_cfg_100mhz()
1066 cdns_phy->dp_pll = DP_PLL1; in cdns_torrent_dp_get_pll()
1070 cdns_phy->dp_pll = DP_PLL0; in cdns_torrent_dp_get_pll()
1073 cdns_phy->dp_pll = DP_PLL0 | DP_PLL1; in cdns_torrent_dp_get_pll()
1076 dev_err(cdns_phy->dev, "Unsupported PHY configuration\n"); in cdns_torrent_dp_get_pll()
1077 return -EINVAL; in cdns_torrent_dp_get_pll()
1084 * Enable or disable PLL for selected lanes.
1089 bool enable) in cdns_torrent_dp_set_pll_en() argument
1091 struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg; in cdns_torrent_dp_set_pll_en()
1096 * Used to determine, which bits to check for or enable in in cdns_torrent_dp_set_pll_en()
1100 /* Used to enable or disable lanes. */ in cdns_torrent_dp_set_pll_en()
1106 if (enable) { in cdns_torrent_dp_set_pll_en()
1107 pll_bits = ((1 << dp->lanes) - 1); in cdns_torrent_dp_set_pll_en()
1111 pll_bits = ((1 << inst->num_lanes) - 1); in cdns_torrent_dp_set_pll_en()
1139 struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg; in cdns_torrent_dp_set_power_state()
1181 struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg; in cdns_torrent_dp_run()
1190 if (ret == -ETIMEDOUT) { in cdns_torrent_dp_run()
1191 dev_err(cdns_phy->dev, in cdns_torrent_dp_run()
1192 "timeout waiting for link PLL clock enable ack\n"); in cdns_torrent_dp_run()
1213 struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg; in cdns_torrent_dp_wait_pma_cmn_ready()
1217 if (ret == -ETIMEDOUT) { in cdns_torrent_dp_wait_pma_cmn_ready()
1218 dev_err(cdns_phy->dev, in cdns_torrent_dp_wait_pma_cmn_ready()
1220 return -ETIMEDOUT; in cdns_torrent_dp_wait_pma_cmn_ready()
1260 if (cdns_phy->dp_pll & DP_PLL0) in cdns_torrent_dp_pma_cmn_rate()
1261 cdns_torrent_phy_write(cdns_phy->regmap_common_cdb, in cdns_torrent_dp_pma_cmn_rate()
1264 if (cdns_phy->dp_pll & DP_PLL1) in cdns_torrent_dp_pma_cmn_rate()
1265 cdns_torrent_phy_write(cdns_phy->regmap_common_cdb, in cdns_torrent_dp_pma_cmn_rate()
1268 /* PMA lane configuration to deal with multi-link operation */ in cdns_torrent_dp_pma_cmn_rate()
1270 cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[inst->mlane + i], in cdns_torrent_dp_pma_cmn_rate()
1287 * re-programming the new data rate. in cdns_torrent_dp_configure_rate()
1289 ret = regmap_field_read(cdns_phy->phy_pma_pll_raw_ctrl, &field_val); in cdns_torrent_dp_configure_rate()
1292 field_val &= ~(cdns_phy->dp_pll); in cdns_torrent_dp_configure_rate()
1293 regmap_field_write(cdns_phy->phy_pma_pll_raw_ctrl, field_val); in cdns_torrent_dp_configure_rate()
1296 * Wait for PLL ready de-assertion. in cdns_torrent_dp_configure_rate()
1297 * For PLL0 - PHY_PMA_CMN_CTRL2[2] == 1 in cdns_torrent_dp_configure_rate()
1298 * For PLL1 - PHY_PMA_CMN_CTRL2[3] == 1 in cdns_torrent_dp_configure_rate()
1300 if (cdns_phy->dp_pll & DP_PLL0) { in cdns_torrent_dp_configure_rate()
1301 ret = regmap_field_read_poll_timeout(cdns_phy->phy_pma_cmn_ctrl_2, in cdns_torrent_dp_configure_rate()
1309 if ((cdns_phy->dp_pll & DP_PLL1) && cdns_phy->nsubnodes != 1) { in cdns_torrent_dp_configure_rate()
1310 ret = regmap_field_read_poll_timeout(cdns_phy->phy_pma_cmn_ctrl_2, in cdns_torrent_dp_configure_rate()
1319 /* DP Rate Change - VCO Output settings. */ in cdns_torrent_dp_configure_rate()
1320 if (cdns_phy->ref_clk_rate == CLK_19_2_MHZ) in cdns_torrent_dp_configure_rate()
1322 cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(cdns_phy, dp->link_rate, dp->ssc); in cdns_torrent_dp_configure_rate()
1323 else if (cdns_phy->ref_clk_rate == CLK_25_MHZ) in cdns_torrent_dp_configure_rate()
1325 cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(cdns_phy, dp->link_rate, dp->ssc); in cdns_torrent_dp_configure_rate()
1326 else if (cdns_phy->ref_clk_rate == CLK_100_MHZ) in cdns_torrent_dp_configure_rate()
1328 cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(cdns_phy, dp->link_rate, dp->ssc); in cdns_torrent_dp_configure_rate()
1330 cdns_torrent_dp_pma_cmn_rate(cdns_phy, inst, dp->link_rate, dp->lanes); in cdns_torrent_dp_configure_rate()
1332 /* Enable the associated PLL (cmn_pll0_en or cmn_pll1_en) */ in cdns_torrent_dp_configure_rate()
1333 ret = regmap_field_read(cdns_phy->phy_pma_pll_raw_ctrl, &field_val); in cdns_torrent_dp_configure_rate()
1336 field_val |= cdns_phy->dp_pll; in cdns_torrent_dp_configure_rate()
1337 regmap_field_write(cdns_phy->phy_pma_pll_raw_ctrl, field_val); in cdns_torrent_dp_configure_rate()
1341 * For PLL0 - PHY_PMA_CMN_CTRL2[0] == 1 in cdns_torrent_dp_configure_rate()
1342 * For PLL1 - PHY_PMA_CMN_CTRL2[1] == 1 in cdns_torrent_dp_configure_rate()
1344 if (cdns_phy->dp_pll & DP_PLL0) { in cdns_torrent_dp_configure_rate()
1345 ret = regmap_field_read_poll_timeout(cdns_phy->phy_pma_cmn_ctrl_2, in cdns_torrent_dp_configure_rate()
1353 if ((cdns_phy->dp_pll & DP_PLL1) && cdns_phy->nsubnodes != 1) in cdns_torrent_dp_configure_rate()
1354 ret = regmap_field_read_poll_timeout(cdns_phy->phy_pma_cmn_ctrl_2, in cdns_torrent_dp_configure_rate()
1371 if (dp->set_rate) { in cdns_torrent_dp_verify_config()
1372 switch (dp->link_rate) { in cdns_torrent_dp_verify_config()
1384 return -EINVAL; in cdns_torrent_dp_verify_config()
1389 switch (dp->lanes) { in cdns_torrent_dp_verify_config()
1396 return -EINVAL; in cdns_torrent_dp_verify_config()
1400 if (dp->lanes > inst->num_lanes) in cdns_torrent_dp_verify_config()
1401 return -EINVAL; in cdns_torrent_dp_verify_config()
1404 * If changing voltages is required, check swing and pre-emphasis in cdns_torrent_dp_verify_config()
1405 * levels, per-lane. in cdns_torrent_dp_verify_config()
1407 if (dp->set_voltages) { in cdns_torrent_dp_verify_config()
1409 for (i = 0; i < dp->lanes; i++) { in cdns_torrent_dp_verify_config()
1410 if (dp->voltage[i] > 3 || dp->pre[i] > 3) in cdns_torrent_dp_verify_config()
1411 return -EINVAL; in cdns_torrent_dp_verify_config()
1413 /* Sum of voltage swing and pre-emphasis levels cannot in cdns_torrent_dp_verify_config()
1416 if (dp->voltage[i] + dp->pre[i] > 3) in cdns_torrent_dp_verify_config()
1417 return -EINVAL; in cdns_torrent_dp_verify_config()
1424 /* Set power state A0 and PLL clock enable to 0 on enabled lanes. */
1429 struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg; in cdns_torrent_dp_set_a0_pll()
1438 << PHY_POWER_STATE_LN(inst->mlane + i)); in cdns_torrent_dp_set_a0_pll()
1440 pll_clk_en &= ~(0x01U << (inst->mlane + i)); in cdns_torrent_dp_set_a0_pll()
1454 struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg; in cdns_torrent_dp_set_lanes()
1455 u8 lane_mask = (1 << dp->lanes) - 1; in cdns_torrent_dp_set_lanes()
1457 u32 clane = inst->mlane; in cdns_torrent_dp_set_lanes()
1463 pma_tx_elec_idle_mask = ((1 << inst->num_lanes) - 1) << clane; in cdns_torrent_dp_set_lanes()
1481 * and powered down when re-enabling the link in cdns_torrent_dp_set_lanes()
1483 for (i = 0; i < inst->num_lanes; i++) in cdns_torrent_dp_set_lanes()
1486 for (i = 1; i < inst->num_lanes; i++) in cdns_torrent_dp_set_lanes()
1491 cdns_torrent_dp_set_a0_pll(cdns_phy, inst, dp->lanes); in cdns_torrent_dp_set_lanes()
1494 for (i = 0; i < inst->num_lanes; i++) in cdns_torrent_dp_set_lanes()
1497 for (i = 0; i < inst->num_lanes; i++) in cdns_torrent_dp_set_lanes()
1514 ret = cdns_torrent_dp_run(cdns_phy, inst, dp->lanes); in cdns_torrent_dp_set_lanes()
1526 ret = cdns_torrent_dp_set_power_state(cdns_phy, inst, dp->lanes, in cdns_torrent_dp_set_rate()
1543 ret = cdns_torrent_dp_set_power_state(cdns_phy, inst, dp->lanes, in cdns_torrent_dp_set_rate()
1547 ret = cdns_torrent_dp_set_power_state(cdns_phy, inst, dp->lanes, in cdns_torrent_dp_set_rate()
1556 /* Configure voltage swing and pre-emphasis for all enabled lanes. */
1564 for (lane = 0; lane < dp->lanes; lane++) { in cdns_torrent_dp_set_voltages()
1565 val = cdns_torrent_phy_read(cdns_phy->regmap_tx_lane_cdb[inst->mlane + lane], in cdns_torrent_dp_set_voltages()
1572 cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[inst->mlane + lane], in cdns_torrent_dp_set_voltages()
1575 cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[inst->mlane + lane], in cdns_torrent_dp_set_voltages()
1577 val = vltg_coeff[dp->voltage[lane]][dp->pre[lane]].diag_tx_drv; in cdns_torrent_dp_set_voltages()
1578 cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[inst->mlane + lane], in cdns_torrent_dp_set_voltages()
1580 val = vltg_coeff[dp->voltage[lane]][dp->pre[lane]].mgnfs_mult; in cdns_torrent_dp_set_voltages()
1581 cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[inst->mlane + lane], in cdns_torrent_dp_set_voltages()
1584 val = vltg_coeff[dp->voltage[lane]][dp->pre[lane]].cpost_mult; in cdns_torrent_dp_set_voltages()
1585 cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[inst->mlane + lane], in cdns_torrent_dp_set_voltages()
1589 val = cdns_torrent_phy_read(cdns_phy->regmap_tx_lane_cdb[inst->mlane + lane], in cdns_torrent_dp_set_voltages()
1596 cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[inst->mlane + lane], in cdns_torrent_dp_set_voltages()
1605 struct cdns_torrent_phy *cdns_phy = dev_get_drvdata(phy->dev.parent); in cdns_torrent_dp_configure()
1608 if (cdns_phy->already_configured) in cdns_torrent_dp_configure()
1611 ret = cdns_torrent_dp_verify_config(inst, &opts->dp); in cdns_torrent_dp_configure()
1613 dev_err(&phy->dev, "invalid params for phy configure\n"); in cdns_torrent_dp_configure()
1617 if (opts->dp.set_lanes) { in cdns_torrent_dp_configure()
1618 ret = cdns_torrent_dp_set_lanes(cdns_phy, inst, &opts->dp); in cdns_torrent_dp_configure()
1620 dev_err(&phy->dev, "cdns_torrent_dp_set_lanes failed\n"); in cdns_torrent_dp_configure()
1625 if (opts->dp.set_rate) { in cdns_torrent_dp_configure()
1626 ret = cdns_torrent_dp_set_rate(cdns_phy, inst, &opts->dp); in cdns_torrent_dp_configure()
1628 dev_err(&phy->dev, "cdns_torrent_dp_set_rate failed\n"); in cdns_torrent_dp_configure()
1633 if (opts->dp.set_voltages) in cdns_torrent_dp_configure()
1634 cdns_torrent_dp_set_voltages(cdns_phy, inst, &opts->dp); in cdns_torrent_dp_configure()
1642 struct cdns_torrent_phy *cdns_phy = dev_get_drvdata(phy->dev.parent); in cdns_torrent_phy_on()
1646 if (cdns_phy->already_configured) { in cdns_torrent_phy_on()
1652 if (cdns_phy->nsubnodes == 1) { in cdns_torrent_phy_on()
1654 reset_control_deassert(inst->lnk_rst); in cdns_torrent_phy_on()
1657 ret = reset_control_deassert(cdns_phy->phy_rst); in cdns_torrent_phy_on()
1666 ret = regmap_field_read_poll_timeout(cdns_phy->phy_pma_cmn_ctrl_1, in cdns_torrent_phy_on()
1670 dev_err(cdns_phy->dev, "Timeout waiting for CMN ready\n"); in cdns_torrent_phy_on()
1674 if (inst->phy_type == TYPE_PCIE || inst->phy_type == TYPE_USB) { in cdns_torrent_phy_on()
1675 ret = regmap_field_read_poll_timeout(cdns_phy->phy_pcs_iso_link_ctrl_1[inst->mlane], in cdns_torrent_phy_on()
1678 if (ret == -ETIMEDOUT) { in cdns_torrent_phy_on()
1679 dev_err(cdns_phy->dev, "Timeout waiting for PHY status ready\n"); in cdns_torrent_phy_on()
1690 struct cdns_torrent_phy *cdns_phy = dev_get_drvdata(phy->dev.parent); in cdns_torrent_phy_off()
1693 if (cdns_phy->nsubnodes != 1) in cdns_torrent_phy_off()
1696 ret = reset_control_assert(cdns_phy->phy_rst); in cdns_torrent_phy_off()
1700 return reset_control_assert(inst->lnk_rst); in cdns_torrent_phy_off()
1706 struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg; in cdns_torrent_dp_common_init()
1710 cdns_torrent_dp_write(regmap, PHY_AUX_CTRL, 0x0003); /* enable AUX */ in cdns_torrent_dp_common_init()
1714 * Set lines pll clk enable to 0 in cdns_torrent_dp_common_init()
1716 cdns_torrent_dp_set_a0_pll(cdns_phy, inst, inst->num_lanes); in cdns_torrent_dp_common_init()
1722 lane_bits = (1 << inst->num_lanes) - 1; in cdns_torrent_dp_common_init()
1736 * Initialize PHY with max supported link rate, without SSC. in cdns_torrent_dp_common_init()
1738 if (cdns_phy->ref_clk_rate == CLK_19_2_MHZ) in cdns_torrent_dp_common_init()
1740 cdns_phy->max_bit_rate, in cdns_torrent_dp_common_init()
1742 else if (cdns_phy->ref_clk_rate == CLK_25_MHZ) in cdns_torrent_dp_common_init()
1744 cdns_phy->max_bit_rate, in cdns_torrent_dp_common_init()
1746 else if (cdns_phy->ref_clk_rate == CLK_100_MHZ) in cdns_torrent_dp_common_init()
1748 cdns_phy->max_bit_rate, in cdns_torrent_dp_common_init()
1751 cdns_torrent_dp_pma_cmn_rate(cdns_phy, inst, cdns_phy->max_bit_rate, in cdns_torrent_dp_common_init()
1752 inst->num_lanes); in cdns_torrent_dp_common_init()
1755 regmap_field_write(cdns_phy->phy_reset_ctrl, 0x1); in cdns_torrent_dp_common_init()
1772 ret = cdns_torrent_dp_run(cdns_phy, inst, inst->num_lanes); in cdns_torrent_dp_start()
1780 struct cdns_torrent_phy *cdns_phy = dev_get_drvdata(phy->dev.parent); in cdns_torrent_dp_init()
1783 switch (cdns_phy->ref_clk_rate) { in cdns_torrent_dp_init()
1790 dev_err(cdns_phy->dev, "Unsupported Ref Clock Rate\n"); in cdns_torrent_dp_init()
1791 return -EINVAL; in cdns_torrent_dp_init()
1807 if (cdns_phy->ref_clk_rate != CLK_100_MHZ) { in cdns_torrent_dp_multilink_init()
1808 dev_err(cdns_phy->dev, "Unsupported Ref Clock Rate\n"); in cdns_torrent_dp_multilink_init()
1809 return -EINVAL; in cdns_torrent_dp_multilink_init()
1821 regmap_field_write(derived_refclk->cmn_cdiag_refclk_ovrd_4, 1); in cdns_torrent_derived_refclk_enable()
1822 regmap_field_write(derived_refclk->phy_pipe_cmn_ctrl1_0, 1); in cdns_torrent_derived_refclk_enable()
1831 regmap_field_write(derived_refclk->phy_pipe_cmn_ctrl1_0, 0); in cdns_torrent_derived_refclk_disable()
1832 regmap_field_write(derived_refclk->cmn_cdiag_refclk_ovrd_4, 0); in cdns_torrent_derived_refclk_disable()
1840 regmap_field_read(derived_refclk->cmn_cdiag_refclk_ovrd_4, &val); in cdns_torrent_derived_refclk_is_enabled()
1846 .enable = cdns_torrent_derived_refclk_enable,
1854 struct device *dev = cdns_phy->dev; in cdns_torrent_derived_refclk_register()
1864 return -ENOMEM; in cdns_torrent_derived_refclk_register()
1875 init = &derived_refclk->clk_data; in cdns_torrent_derived_refclk_register()
1879 init->parent_names = &parent_name; in cdns_torrent_derived_refclk_register()
1880 init->num_parents = 1; in cdns_torrent_derived_refclk_register()
1882 init->ops = &cdns_torrent_derived_refclk_ops; in cdns_torrent_derived_refclk_register()
1883 init->flags = 0; in cdns_torrent_derived_refclk_register()
1884 init->name = clk_name; in cdns_torrent_derived_refclk_register()
1886 derived_refclk->phy_pipe_cmn_ctrl1_0 = cdns_phy->phy_pipe_cmn_ctrl1_0; in cdns_torrent_derived_refclk_register()
1887 derived_refclk->cmn_cdiag_refclk_ovrd_4 = cdns_phy->cmn_cdiag_refclk_ovrd_4; in cdns_torrent_derived_refclk_register()
1889 derived_refclk->hw.init = init; in cdns_torrent_derived_refclk_register()
1891 hw = &derived_refclk->hw; in cdns_torrent_derived_refclk_register()
1896 cdns_phy->clk_hw_data->hws[CDNS_TORRENT_DERIVED_REFCLK] = hw; in cdns_torrent_derived_refclk_register()
1905 regmap_field_write(received_refclk->phy_pipe_cmn_ctrl1_0, 1); in cdns_torrent_received_refclk_enable()
1914 regmap_field_write(received_refclk->phy_pipe_cmn_ctrl1_0, 0); in cdns_torrent_received_refclk_disable()
1922 regmap_field_read(received_refclk->phy_pipe_cmn_ctrl1_0, &val); in cdns_torrent_received_refclk_is_enabled()
1923 regmap_field_read(received_refclk->cmn_cdiag_refclk_ovrd_4, &cmn_val); in cdns_torrent_received_refclk_is_enabled()
1929 .enable = cdns_torrent_received_refclk_enable,
1937 struct device *dev = cdns_phy->dev; in cdns_torrent_received_refclk_register()
1947 return -ENOMEM; in cdns_torrent_received_refclk_register()
1958 init = &received_refclk->clk_data; in cdns_torrent_received_refclk_register()
1962 init->parent_names = &parent_name; in cdns_torrent_received_refclk_register()
1963 init->num_parents = 1; in cdns_torrent_received_refclk_register()
1965 init->ops = &cdns_torrent_received_refclk_ops; in cdns_torrent_received_refclk_register()
1966 init->flags = 0; in cdns_torrent_received_refclk_register()
1967 init->name = clk_name; in cdns_torrent_received_refclk_register()
1969 received_refclk->phy_pipe_cmn_ctrl1_0 = cdns_phy->phy_pipe_cmn_ctrl1_0; in cdns_torrent_received_refclk_register()
1970 received_refclk->cmn_cdiag_refclk_ovrd_4 = cdns_phy->cmn_cdiag_refclk_ovrd_4; in cdns_torrent_received_refclk_register()
1972 received_refclk->hw.init = init; in cdns_torrent_received_refclk_register()
1974 hw = &received_refclk->hw; in cdns_torrent_received_refclk_register()
1979 cdns_phy->clk_hw_data->hws[CDNS_TORRENT_RECEIVED_REFCLK] = hw; in cdns_torrent_received_refclk_register()
1988 regmap_field_write(refclk_driver->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_6], 0); in cdns_torrent_refclk_driver_enable()
1989 regmap_field_write(refclk_driver->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_5], 1); in cdns_torrent_refclk_driver_enable()
1990 regmap_field_write(refclk_driver->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_1], 0); in cdns_torrent_refclk_driver_enable()
1999 regmap_field_write(refclk_driver->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_1], 1); in cdns_torrent_refclk_driver_disable()
2007 regmap_field_read(refclk_driver->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_1], &val); in cdns_torrent_refclk_driver_is_enabled()
2017 regmap_field_read(refclk_driver->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_4], &val); in cdns_torrent_refclk_driver_get_parent()
2027 return regmap_field_write(refclk_driver->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_4], val); in cdns_torrent_refclk_driver_set_parent()
2031 .enable = cdns_torrent_refclk_driver_enable,
2042 struct device *dev = cdns_phy->dev; in cdns_torrent_refclk_driver_register()
2054 return -ENOMEM; in cdns_torrent_refclk_driver_register()
2059 return -ENOMEM; in cdns_torrent_refclk_driver_register()
2062 hw = cdns_phy->clk_hw_data->hws[refclk_driver_parent_index[i]]; in cdns_torrent_refclk_driver_register()
2065 return IS_ERR(hw) ? PTR_ERR(hw) : -ENOENT; in cdns_torrent_refclk_driver_register()
2073 init = &refclk_driver->clk_data; in cdns_torrent_refclk_driver_register()
2075 init->ops = &cdns_torrent_refclk_driver_ops; in cdns_torrent_refclk_driver_register()
2076 init->flags = CLK_SET_RATE_NO_REPARENT; in cdns_torrent_refclk_driver_register()
2077 init->parent_names = parent_names; in cdns_torrent_refclk_driver_register()
2078 init->num_parents = num_parents; in cdns_torrent_refclk_driver_register()
2079 init->name = clk_name; in cdns_torrent_refclk_driver_register()
2081 regmap = cdns_phy->regmap_common_cdb; in cdns_torrent_refclk_driver_register()
2089 refclk_driver->cmn_fields[i] = field; in cdns_torrent_refclk_driver_register()
2092 /* Enable Derived reference clock as default */ in cdns_torrent_refclk_driver_register()
2093 regmap_field_write(refclk_driver->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_4], 1); in cdns_torrent_refclk_driver_register()
2095 refclk_driver->hw.init = init; in cdns_torrent_refclk_driver_register()
2097 hw = &refclk_driver->hw; in cdns_torrent_refclk_driver_register()
2102 cdns_phy->clk_hw_data->hws[CDNS_TORRENT_REFCLK_DRIVER] = hw; in cdns_torrent_refclk_driver_register()
2116 return ERR_PTR(-ENOMEM); in cdns_regmap_init()
2118 ctx->dev = dev; in cdns_regmap_init()
2119 ctx->base = base + block_offset; in cdns_regmap_init()
2120 ctx->reg_offset_shift = reg_offset_shift; in cdns_regmap_init()
2127 struct device *dev = cdns_phy->dev; in cdns_torrent_dp_regfield_init()
2131 regmap = cdns_phy->regmap_dptx_phy_reg; in cdns_torrent_dp_regfield_init()
2137 cdns_phy->phy_reset_ctrl = field; in cdns_torrent_dp_regfield_init()
2144 struct device *dev = cdns_phy->dev; in cdns_torrent_regfield_init()
2149 regmap = cdns_phy->regmap_phy_pcs_common_cdb; in cdns_torrent_regfield_init()
2155 cdns_phy->phy_pll_cfg = field; in cdns_torrent_regfield_init()
2157 regmap = cdns_phy->regmap_phy_pcs_common_cdb; in cdns_torrent_regfield_init()
2163 cdns_phy->phy_pipe_cmn_ctrl1_0 = field; in cdns_torrent_regfield_init()
2165 regmap = cdns_phy->regmap_common_cdb; in cdns_torrent_regfield_init()
2171 cdns_phy->cmn_cdiag_refclk_ovrd_4 = field; in cdns_torrent_regfield_init()
2173 regmap = cdns_phy->regmap_phy_pma_common_cdb; in cdns_torrent_regfield_init()
2179 cdns_phy->phy_pma_cmn_ctrl_1 = field; in cdns_torrent_regfield_init()
2181 regmap = cdns_phy->regmap_phy_pma_common_cdb; in cdns_torrent_regfield_init()
2187 cdns_phy->phy_pma_cmn_ctrl_2 = field; in cdns_torrent_regfield_init()
2189 regmap = cdns_phy->regmap_phy_pma_common_cdb; in cdns_torrent_regfield_init()
2195 cdns_phy->phy_pma_pll_raw_ctrl = field; in cdns_torrent_regfield_init()
2198 regmap = cdns_phy->regmap_phy_pcs_lane_cdb[i]; in cdns_torrent_regfield_init()
2204 cdns_phy->phy_pcs_iso_link_ctrl_1[i] = field; in cdns_torrent_regfield_init()
2212 void __iomem *base = cdns_phy->base; in cdns_torrent_dp_regmap_init()
2213 struct device *dev = cdns_phy->dev; in cdns_torrent_dp_regmap_init()
2218 reg_offset_shift = cdns_phy->init_data->reg_offset_shift; in cdns_torrent_dp_regmap_init()
2228 cdns_phy->regmap_dptx_phy_reg = regmap; in cdns_torrent_dp_regmap_init()
2235 void __iomem *sd_base = cdns_phy->sd_base; in cdns_torrent_regmap_init()
2237 struct device *dev = cdns_phy->dev; in cdns_torrent_regmap_init()
2242 block_offset_shift = cdns_phy->init_data->block_offset_shift; in cdns_torrent_regmap_init()
2243 reg_offset_shift = cdns_phy->init_data->reg_offset_shift; in cdns_torrent_regmap_init()
2255 cdns_phy->regmap_tx_lane_cdb[i] = regmap; in cdns_torrent_regmap_init()
2266 cdns_phy->regmap_rx_lane_cdb[i] = regmap; in cdns_torrent_regmap_init()
2277 cdns_phy->regmap_phy_pcs_lane_cdb[i] = regmap; in cdns_torrent_regmap_init()
2288 cdns_phy->regmap_common_cdb = regmap; in cdns_torrent_regmap_init()
2298 cdns_phy->regmap_phy_pcs_common_cdb = regmap; in cdns_torrent_regmap_init()
2308 cdns_phy->regmap_phy_pma_common_cdb = regmap; in cdns_torrent_regmap_init()
2315 struct cdns_torrent_phy *cdns_phy = dev_get_drvdata(phy->dev.parent); in cdns_torrent_phy_init()
2317 const struct cdns_torrent_data *init_data = cdns_phy->init_data; in cdns_torrent_phy_init()
2319 enum cdns_torrent_ref_clk ref_clk = cdns_phy->ref_clk_rate; in cdns_torrent_phy_init()
2321 enum cdns_torrent_phy_type phy_type = inst->phy_type; in cdns_torrent_phy_init()
2323 enum cdns_torrent_ssc_mode ssc = inst->ssc_mode; in cdns_torrent_phy_init() local
2330 if (cdns_phy->already_configured) in cdns_torrent_phy_init()
2333 if (cdns_phy->nsubnodes > 1) { in cdns_torrent_phy_init()
2344 ssc = NO_SSC; in cdns_torrent_phy_init()
2347 link_cmn_vals = cdns_torrent_get_tbl_vals(&init_data->link_cmn_vals_tbl, in cdns_torrent_phy_init()
2352 reg_pairs = link_cmn_vals->reg_pairs; in cdns_torrent_phy_init()
2353 num_regs = link_cmn_vals->num_regs; in cdns_torrent_phy_init()
2354 regmap = cdns_phy->regmap_common_cdb; in cdns_torrent_phy_init()
2360 regmap_field_write(cdns_phy->phy_pll_cfg, reg_pairs[0].val); in cdns_torrent_phy_init()
2367 xcvr_diag_vals = cdns_torrent_get_tbl_vals(&init_data->xcvr_diag_vals_tbl, in cdns_torrent_phy_init()
2372 reg_pairs = xcvr_diag_vals->reg_pairs; in cdns_torrent_phy_init()
2373 num_regs = xcvr_diag_vals->num_regs; in cdns_torrent_phy_init()
2374 for (i = 0; i < inst->num_lanes; i++) { in cdns_torrent_phy_init()
2375 regmap = cdns_phy->regmap_tx_lane_cdb[i + inst->mlane]; in cdns_torrent_phy_init()
2383 pcs_cmn_vals = cdns_torrent_get_tbl_vals(&init_data->pcs_cmn_vals_tbl, in cdns_torrent_phy_init()
2388 reg_pairs = pcs_cmn_vals->reg_pairs; in cdns_torrent_phy_init()
2389 num_regs = pcs_cmn_vals->num_regs; in cdns_torrent_phy_init()
2390 regmap = cdns_phy->regmap_phy_pcs_common_cdb; in cdns_torrent_phy_init()
2397 phy_pma_cmn_vals = cdns_torrent_get_tbl_vals(&init_data->phy_pma_cmn_vals_tbl, in cdns_torrent_phy_init()
2402 reg_pairs = phy_pma_cmn_vals->reg_pairs; in cdns_torrent_phy_init()
2403 num_regs = phy_pma_cmn_vals->num_regs; in cdns_torrent_phy_init()
2404 regmap = cdns_phy->regmap_phy_pma_common_cdb; in cdns_torrent_phy_init()
2411 cmn_vals = cdns_torrent_get_tbl_vals(&init_data->cmn_vals_tbl, in cdns_torrent_phy_init()
2414 ssc); in cdns_torrent_phy_init()
2416 reg_pairs = cmn_vals->reg_pairs; in cdns_torrent_phy_init()
2417 num_regs = cmn_vals->num_regs; in cdns_torrent_phy_init()
2418 regmap = cdns_phy->regmap_common_cdb; in cdns_torrent_phy_init()
2425 tx_ln_vals = cdns_torrent_get_tbl_vals(&init_data->tx_ln_vals_tbl, in cdns_torrent_phy_init()
2428 ssc); in cdns_torrent_phy_init()
2430 reg_pairs = tx_ln_vals->reg_pairs; in cdns_torrent_phy_init()
2431 num_regs = tx_ln_vals->num_regs; in cdns_torrent_phy_init()
2432 for (i = 0; i < inst->num_lanes; i++) { in cdns_torrent_phy_init()
2433 regmap = cdns_phy->regmap_tx_lane_cdb[i + inst->mlane]; in cdns_torrent_phy_init()
2441 rx_ln_vals = cdns_torrent_get_tbl_vals(&init_data->rx_ln_vals_tbl, in cdns_torrent_phy_init()
2444 ssc); in cdns_torrent_phy_init()
2446 reg_pairs = rx_ln_vals->reg_pairs; in cdns_torrent_phy_init()
2447 num_regs = rx_ln_vals->num_regs; in cdns_torrent_phy_init()
2448 for (i = 0; i < inst->num_lanes; i++) { in cdns_torrent_phy_init()
2449 regmap = cdns_phy->regmap_rx_lane_cdb[i + inst->mlane]; in cdns_torrent_phy_init()
2474 const struct cdns_torrent_data *init_data = cdns_phy->init_data; in cdns_torrent_phy_configure_multilink()
2476 enum cdns_torrent_ref_clk ref_clk1 = cdns_phy->ref_clk1_rate; in cdns_torrent_phy_configure_multilink()
2477 enum cdns_torrent_ref_clk ref_clk = cdns_phy->ref_clk_rate; in cdns_torrent_phy_configure_multilink()
2483 struct device *dev = cdns_phy->dev; in cdns_torrent_phy_configure_multilink()
2484 enum cdns_torrent_ssc_mode ssc; in cdns_torrent_phy_configure_multilink() local
2489 num_protocols = hweight32(cdns_phy->protocol_bitmask); in cdns_torrent_phy_configure_multilink()
2493 return -EINVAL; in cdns_torrent_phy_configure_multilink()
2502 if (cdns_phy->nsubnodes == 2) { in cdns_torrent_phy_configure_multilink()
2503 phy_t1 = cdns_phy->phys[0].phy_type; in cdns_torrent_phy_configure_multilink()
2504 phy_t2 = cdns_phy->phys[1].phy_type; in cdns_torrent_phy_configure_multilink()
2509 * a) Single-Link (1 Sub-node) - handled via PHY APIs in cdns_torrent_phy_configure_multilink()
2511 * b) Double-Link (2 Sub-nodes) - handled above in cdns_torrent_phy_configure_multilink()
2515 return -EINVAL; in cdns_torrent_phy_configure_multilink()
2518 phy_t1 = fns(cdns_phy->protocol_bitmask, 0); in cdns_torrent_phy_configure_multilink()
2519 phy_t2 = fns(cdns_phy->protocol_bitmask, 1); in cdns_torrent_phy_configure_multilink()
2523 * non-PCIe protocol. The existing limitation associated with in cdns_torrent_phy_configure_multilink()
2537 * PCIe Multilink configuration with a non-PCIe protocol. in cdns_torrent_phy_configure_multilink()
2539 for (node = 0; node < cdns_phy->nsubnodes; node++) { in cdns_torrent_phy_configure_multilink()
2540 if (cdns_phy->phys[node].phy_type == TYPE_PCIE) in cdns_torrent_phy_configure_multilink()
2547 return -EINVAL; in cdns_torrent_phy_configure_multilink()
2550 for (node = 0; node < cdns_phy->nsubnodes; node++) { in cdns_torrent_phy_configure_multilink()
2551 if (cdns_phy->phys[node].phy_type == TYPE_PCIE) { in cdns_torrent_phy_configure_multilink()
2552 cdns_phy->phys[node].phy_type = TYPE_PCIE_ML; in cdns_torrent_phy_configure_multilink()
2555 phy_t2 = cdns_phy->phys[node].phy_type; in cdns_torrent_phy_configure_multilink()
2566 * iterations over the sub-nodes (links). in cdns_torrent_phy_configure_multilink()
2569 * is performed by iterating over all sub-nodes matching the first in cdns_torrent_phy_configure_multilink()
2571 * all sub-nodes matching the second protocol and configuring them in cdns_torrent_phy_configure_multilink()
2586 * Get the array values as [phy_t2][phy_t1][ssc]. in cdns_torrent_phy_configure_multilink()
2592 for (node = 0; node < cdns_phy->nsubnodes; node++) { in cdns_torrent_phy_configure_multilink()
2593 if (cdns_phy->phys[node].phy_type != phy_t1) in cdns_torrent_phy_configure_multilink()
2596 mlane = cdns_phy->phys[node].mlane; in cdns_torrent_phy_configure_multilink()
2597 ssc = cdns_phy->phys[node].ssc_mode; in cdns_torrent_phy_configure_multilink()
2598 num_lanes = cdns_phy->phys[node].num_lanes; in cdns_torrent_phy_configure_multilink()
2604 * values should be same for [phy_t1][phy_t2][ssc] and in cdns_torrent_phy_configure_multilink()
2605 * [phy_t2][phy_t1][ssc]. in cdns_torrent_phy_configure_multilink()
2610 link_cmn_vals = cdns_torrent_get_tbl_vals(&init_data->link_cmn_vals_tbl, in cdns_torrent_phy_configure_multilink()
2614 reg_pairs = link_cmn_vals->reg_pairs; in cdns_torrent_phy_configure_multilink()
2615 num_regs = link_cmn_vals->num_regs; in cdns_torrent_phy_configure_multilink()
2616 regmap = cdns_phy->regmap_common_cdb; in cdns_torrent_phy_configure_multilink()
2622 regmap_field_write(cdns_phy->phy_pll_cfg, in cdns_torrent_phy_configure_multilink()
2630 xcvr_diag_vals = cdns_torrent_get_tbl_vals(&init_data->xcvr_diag_vals_tbl, in cdns_torrent_phy_configure_multilink()
2634 reg_pairs = xcvr_diag_vals->reg_pairs; in cdns_torrent_phy_configure_multilink()
2635 num_regs = xcvr_diag_vals->num_regs; in cdns_torrent_phy_configure_multilink()
2637 regmap = cdns_phy->regmap_tx_lane_cdb[i + mlane]; in cdns_torrent_phy_configure_multilink()
2645 pcs_cmn_vals = cdns_torrent_get_tbl_vals(&init_data->pcs_cmn_vals_tbl, in cdns_torrent_phy_configure_multilink()
2649 reg_pairs = pcs_cmn_vals->reg_pairs; in cdns_torrent_phy_configure_multilink()
2650 num_regs = pcs_cmn_vals->num_regs; in cdns_torrent_phy_configure_multilink()
2651 regmap = cdns_phy->regmap_phy_pcs_common_cdb; in cdns_torrent_phy_configure_multilink()
2659 cdns_torrent_get_tbl_vals(&init_data->phy_pma_cmn_vals_tbl, in cdns_torrent_phy_configure_multilink()
2663 reg_pairs = phy_pma_cmn_vals->reg_pairs; in cdns_torrent_phy_configure_multilink()
2664 num_regs = phy_pma_cmn_vals->num_regs; in cdns_torrent_phy_configure_multilink()
2665 regmap = cdns_phy->regmap_phy_pma_common_cdb; in cdns_torrent_phy_configure_multilink()
2672 cmn_vals = cdns_torrent_get_tbl_vals(&init_data->cmn_vals_tbl, in cdns_torrent_phy_configure_multilink()
2674 phy_t1, phy_t2, ssc); in cdns_torrent_phy_configure_multilink()
2676 reg_pairs = cmn_vals->reg_pairs; in cdns_torrent_phy_configure_multilink()
2677 num_regs = cmn_vals->num_regs; in cdns_torrent_phy_configure_multilink()
2678 regmap = cdns_phy->regmap_common_cdb; in cdns_torrent_phy_configure_multilink()
2685 tx_ln_vals = cdns_torrent_get_tbl_vals(&init_data->tx_ln_vals_tbl, in cdns_torrent_phy_configure_multilink()
2687 phy_t1, phy_t2, ssc); in cdns_torrent_phy_configure_multilink()
2689 reg_pairs = tx_ln_vals->reg_pairs; in cdns_torrent_phy_configure_multilink()
2690 num_regs = tx_ln_vals->num_regs; in cdns_torrent_phy_configure_multilink()
2692 regmap = cdns_phy->regmap_tx_lane_cdb[i + mlane]; in cdns_torrent_phy_configure_multilink()
2700 rx_ln_vals = cdns_torrent_get_tbl_vals(&init_data->rx_ln_vals_tbl, in cdns_torrent_phy_configure_multilink()
2702 phy_t1, phy_t2, ssc); in cdns_torrent_phy_configure_multilink()
2704 reg_pairs = rx_ln_vals->reg_pairs; in cdns_torrent_phy_configure_multilink()
2705 num_regs = rx_ln_vals->num_regs; in cdns_torrent_phy_configure_multilink()
2707 regmap = cdns_phy->regmap_rx_lane_cdb[i + mlane]; in cdns_torrent_phy_configure_multilink()
2720 reset_control_deassert(cdns_phy->phys[node].lnk_rst); in cdns_torrent_phy_configure_multilink()
2724 /* Restore TYPE_PCIE_ML to TYPE_PCIE to be compatible with suspend-resume */ in cdns_torrent_phy_configure_multilink()
2725 for (node = 0; node < cdns_phy->nsubnodes; node++) in cdns_torrent_phy_configure_multilink()
2726 if (cdns_phy->phys[node].phy_type == TYPE_PCIE_ML) in cdns_torrent_phy_configure_multilink()
2727 cdns_phy->phys[node].phy_type = TYPE_PCIE; in cdns_torrent_phy_configure_multilink()
2730 ret = reset_control_deassert(cdns_phy->phy_rst); in cdns_torrent_phy_configure_multilink()
2739 struct device *dev = cdns_phy->dev; in cdns_torrent_clk_cleanup()
2741 of_clk_del_provider(dev->of_node); in cdns_torrent_clk_cleanup()
2746 struct device *dev = cdns_phy->dev; in cdns_torrent_clk_register()
2747 struct device_node *node = dev->of_node; in cdns_torrent_clk_register()
2753 return -ENOMEM; in cdns_torrent_clk_register()
2755 data->num = CDNS_TORRENT_OUTPUT_CLOCKS; in cdns_torrent_clk_register()
2756 cdns_phy->clk_hw_data = data; in cdns_torrent_clk_register()
2778 dev_err(dev, "Failed to add clock provider: %s\n", node->name); in cdns_torrent_clk_register()
2787 struct device *dev = cdns_phy->dev; in cdns_torrent_of_get_reset()
2789 cdns_phy->phy_rst = devm_reset_control_get_exclusive_by_index(dev, 0); in cdns_torrent_of_get_reset()
2790 if (IS_ERR(cdns_phy->phy_rst)) { in cdns_torrent_of_get_reset()
2792 dev->of_node->full_name); in cdns_torrent_of_get_reset()
2793 return PTR_ERR(cdns_phy->phy_rst); in cdns_torrent_of_get_reset()
2796 cdns_phy->apb_rst = devm_reset_control_get_optional_exclusive(dev, "torrent_apb"); in cdns_torrent_of_get_reset()
2797 if (IS_ERR(cdns_phy->apb_rst)) { in cdns_torrent_of_get_reset()
2799 dev->of_node->full_name); in cdns_torrent_of_get_reset()
2800 return PTR_ERR(cdns_phy->apb_rst); in cdns_torrent_of_get_reset()
2809 cdns_phy->clk = devm_clk_get(cdns_phy->dev, "refclk"); in cdns_torrent_of_get_clk()
2810 if (IS_ERR(cdns_phy->clk)) in cdns_torrent_of_get_clk()
2811 return dev_err_probe(cdns_phy->dev, PTR_ERR(cdns_phy->clk), in cdns_torrent_of_get_clk()
2815 cdns_phy->clk1 = devm_clk_get_optional(cdns_phy->dev, "pll1_refclk"); in cdns_torrent_of_get_clk()
2816 if (IS_ERR(cdns_phy->clk1)) in cdns_torrent_of_get_clk()
2817 return dev_err_probe(cdns_phy->dev, PTR_ERR(cdns_phy->clk1), in cdns_torrent_of_get_clk()
2829 ret = clk_prepare_enable(cdns_phy->clk); in cdns_torrent_clk()
2831 dev_err(cdns_phy->dev, "Failed to prepare ref clock: %d\n", ret); in cdns_torrent_clk()
2835 ref_clk_rate = clk_get_rate(cdns_phy->clk); in cdns_torrent_clk()
2837 dev_err(cdns_phy->dev, "Failed to get ref clock rate\n"); in cdns_torrent_clk()
2838 ret = -EINVAL; in cdns_torrent_clk()
2844 cdns_phy->ref_clk_rate = CLK_19_2_MHZ; in cdns_torrent_clk()
2847 cdns_phy->ref_clk_rate = CLK_25_MHZ; in cdns_torrent_clk()
2850 cdns_phy->ref_clk_rate = CLK_100_MHZ; in cdns_torrent_clk()
2853 cdns_phy->ref_clk_rate = CLK_156_25_MHZ; in cdns_torrent_clk()
2856 dev_err(cdns_phy->dev, "Invalid ref clock rate\n"); in cdns_torrent_clk()
2857 ret = -EINVAL; in cdns_torrent_clk()
2861 if (cdns_phy->clk1) { in cdns_torrent_clk()
2862 ret = clk_prepare_enable(cdns_phy->clk1); in cdns_torrent_clk()
2864 dev_err(cdns_phy->dev, "Failed to prepare PLL1 ref clock: %d\n", ret); in cdns_torrent_clk()
2868 ref_clk1_rate = clk_get_rate(cdns_phy->clk1); in cdns_torrent_clk()
2870 dev_err(cdns_phy->dev, "Failed to get PLL1 ref clock rate\n"); in cdns_torrent_clk()
2871 ret = -EINVAL; in cdns_torrent_clk()
2877 cdns_phy->ref_clk1_rate = CLK_19_2_MHZ; in cdns_torrent_clk()
2880 cdns_phy->ref_clk1_rate = CLK_25_MHZ; in cdns_torrent_clk()
2883 cdns_phy->ref_clk1_rate = CLK_100_MHZ; in cdns_torrent_clk()
2886 cdns_phy->ref_clk1_rate = CLK_156_25_MHZ; in cdns_torrent_clk()
2889 dev_err(cdns_phy->dev, "Invalid PLL1 ref clock rate\n"); in cdns_torrent_clk()
2890 ret = -EINVAL; in cdns_torrent_clk()
2894 cdns_phy->ref_clk1_rate = cdns_phy->ref_clk_rate; in cdns_torrent_clk()
2900 clk_disable_unprepare(cdns_phy->clk1); in cdns_torrent_clk()
2902 clk_disable_unprepare(cdns_phy->clk); in cdns_torrent_clk()
2909 struct device *dev = &pdev->dev; in cdns_torrent_phy_probe()
2921 return -EINVAL; in cdns_torrent_phy_probe()
2925 return -ENOMEM; in cdns_torrent_phy_probe()
2928 cdns_phy->dev = dev; in cdns_torrent_phy_probe()
2929 cdns_phy->init_data = data; in cdns_torrent_phy_probe()
2930 cdns_phy->protocol_bitmask = 0; in cdns_torrent_phy_probe()
2932 cdns_phy->sd_base = devm_platform_ioremap_resource(pdev, 0); in cdns_torrent_phy_probe()
2933 if (IS_ERR(cdns_phy->sd_base)) in cdns_torrent_phy_probe()
2934 return PTR_ERR(cdns_phy->sd_base); in cdns_torrent_phy_probe()
2936 subnodes = of_get_available_child_count(dev->of_node); in cdns_torrent_phy_probe()
2939 return -EINVAL; in cdns_torrent_phy_probe()
2962 regmap_field_read(cdns_phy->phy_pma_cmn_ctrl_1, &cdns_phy->already_configured); in cdns_torrent_phy_probe()
2964 if (!cdns_phy->already_configured) { in cdns_torrent_phy_probe()
2969 /* Enable APB */ in cdns_torrent_phy_probe()
2970 reset_control_deassert(cdns_phy->apb_rst); in cdns_torrent_phy_probe()
2973 for_each_available_child_of_node(dev->of_node, child) { in cdns_torrent_phy_probe()
2980 cdns_phy->phys[node].lnk_rst = in cdns_torrent_phy_probe()
2982 if (IS_ERR(cdns_phy->phys[node].lnk_rst)) { in cdns_torrent_phy_probe()
2984 child->full_name); in cdns_torrent_phy_probe()
2985 ret = PTR_ERR(cdns_phy->phys[node].lnk_rst); in cdns_torrent_phy_probe()
2990 &cdns_phy->phys[node].mlane)) { in cdns_torrent_phy_probe()
2991 dev_err(dev, "%s: No \"reg\"-property.\n", in cdns_torrent_phy_probe()
2992 child->full_name); in cdns_torrent_phy_probe()
2993 ret = -EINVAL; in cdns_torrent_phy_probe()
2997 if (of_property_read_u32(child, "cdns,phy-type", &phy_type)) { in cdns_torrent_phy_probe()
2998 dev_err(dev, "%s: No \"cdns,phy-type\"-property.\n", in cdns_torrent_phy_probe()
2999 child->full_name); in cdns_torrent_phy_probe()
3000 ret = -EINVAL; in cdns_torrent_phy_probe()
3006 cdns_phy->phys[node].phy_type = TYPE_PCIE; in cdns_torrent_phy_probe()
3009 cdns_phy->phys[node].phy_type = TYPE_DP; in cdns_torrent_phy_probe()
3012 cdns_phy->phys[node].phy_type = TYPE_SGMII; in cdns_torrent_phy_probe()
3015 cdns_phy->phys[node].phy_type = TYPE_QSGMII; in cdns_torrent_phy_probe()
3018 cdns_phy->phys[node].phy_type = TYPE_USB; in cdns_torrent_phy_probe()
3021 cdns_phy->phys[node].phy_type = TYPE_USXGMII; in cdns_torrent_phy_probe()
3025 ret = -EINVAL; in cdns_torrent_phy_probe()
3029 if (of_property_read_u32(child, "cdns,num-lanes", in cdns_torrent_phy_probe()
3030 &cdns_phy->phys[node].num_lanes)) { in cdns_torrent_phy_probe()
3031 dev_err(dev, "%s: No \"cdns,num-lanes\"-property.\n", in cdns_torrent_phy_probe()
3032 child->full_name); in cdns_torrent_phy_probe()
3033 ret = -EINVAL; in cdns_torrent_phy_probe()
3037 total_num_lanes += cdns_phy->phys[node].num_lanes; in cdns_torrent_phy_probe()
3039 /* Get SSC mode */ in cdns_torrent_phy_probe()
3040 cdns_phy->phys[node].ssc_mode = NO_SSC; in cdns_torrent_phy_probe()
3041 of_property_read_u32(child, "cdns,ssc-mode", in cdns_torrent_phy_probe()
3042 &cdns_phy->phys[node].ssc_mode); in cdns_torrent_phy_probe()
3050 if (cdns_phy->phys[node].phy_type == TYPE_DP) { in cdns_torrent_phy_probe()
3051 switch (cdns_phy->phys[node].num_lanes) { in cdns_torrent_phy_probe()
3059 cdns_phy->phys[node].num_lanes); in cdns_torrent_phy_probe()
3060 ret = -EINVAL; in cdns_torrent_phy_probe()
3064 cdns_phy->max_bit_rate = DEFAULT_MAX_BIT_RATE; in cdns_torrent_phy_probe()
3065 of_property_read_u32(child, "cdns,max-bit-rate", in cdns_torrent_phy_probe()
3066 &cdns_phy->max_bit_rate); in cdns_torrent_phy_probe()
3068 switch (cdns_phy->max_bit_rate) { in cdns_torrent_phy_probe()
3081 cdns_phy->max_bit_rate); in cdns_torrent_phy_probe()
3082 ret = -EINVAL; in cdns_torrent_phy_probe()
3087 cdns_phy->base = devm_platform_ioremap_resource(pdev, 1); in cdns_torrent_phy_probe()
3088 if (IS_ERR(cdns_phy->base)) { in cdns_torrent_phy_probe()
3089 ret = PTR_ERR(cdns_phy->base); in cdns_torrent_phy_probe()
3106 cdns_phy->max_bit_rate / 1000, in cdns_torrent_phy_probe()
3107 cdns_phy->max_bit_rate % 1000); in cdns_torrent_phy_probe()
3109 gphy->attrs.bus_width = cdns_phy->phys[node].num_lanes; in cdns_torrent_phy_probe()
3110 gphy->attrs.max_link_rate = cdns_phy->max_bit_rate; in cdns_torrent_phy_probe()
3111 gphy->attrs.mode = PHY_MODE_DP; in cdns_torrent_phy_probe()
3114 cdns_phy->phys[node].phy = gphy; in cdns_torrent_phy_probe()
3115 cdns_phy->protocol_bitmask |= BIT(cdns_phy->phys[node].phy_type); in cdns_torrent_phy_probe()
3116 phy_set_drvdata(gphy, &cdns_phy->phys[node]); in cdns_torrent_phy_probe()
3120 cdns_phy->nsubnodes = node; in cdns_torrent_phy_probe()
3124 ret = -EINVAL; in cdns_torrent_phy_probe()
3128 if (cdns_phy->nsubnodes > 1 && !cdns_phy->already_configured) { in cdns_torrent_phy_probe()
3140 if (cdns_phy->nsubnodes > 1) in cdns_torrent_phy_probe()
3145 for (i = 0; i < cdns_phy->nsubnodes; i++) in cdns_torrent_phy_probe()
3147 cdns_torrent_get_phy_type(cdns_phy->phys[i].phy_type), in cdns_torrent_phy_probe()
3148 cdns_phy->phys[i].num_lanes); in cdns_torrent_phy_probe()
3156 reset_control_put(cdns_phy->phys[i].lnk_rst); in cdns_torrent_phy_probe()
3158 reset_control_assert(cdns_phy->apb_rst); in cdns_torrent_phy_probe()
3159 clk_disable_unprepare(cdns_phy->clk1); in cdns_torrent_phy_probe()
3160 clk_disable_unprepare(cdns_phy->clk); in cdns_torrent_phy_probe()
3171 reset_control_assert(cdns_phy->phy_rst); in cdns_torrent_phy_remove()
3172 reset_control_assert(cdns_phy->apb_rst); in cdns_torrent_phy_remove()
3173 for (i = 0; i < cdns_phy->nsubnodes; i++) { in cdns_torrent_phy_remove()
3174 reset_control_assert(cdns_phy->phys[i].lnk_rst); in cdns_torrent_phy_remove()
3175 reset_control_put(cdns_phy->phys[i].lnk_rst); in cdns_torrent_phy_remove()
3178 clk_disable_unprepare(cdns_phy->clk1); in cdns_torrent_phy_remove()
3179 clk_disable_unprepare(cdns_phy->clk); in cdns_torrent_phy_remove()
3183 /* Multilink PCIe and USB Same SSC link configuration */
3236 /* Multi link PCIe, 100 MHz Ref clk, no SSC */
3264 /* Multi link PCIe, 100 MHz Ref clk, internal SSC */
3334 reset_control_assert(cdns_phy->phy_rst); in cdns_torrent_phy_suspend_noirq()
3335 reset_control_assert(cdns_phy->apb_rst); in cdns_torrent_phy_suspend_noirq()
3336 for (i = 0; i < cdns_phy->nsubnodes; i++) in cdns_torrent_phy_suspend_noirq()
3337 reset_control_assert(cdns_phy->phys[i].lnk_rst); in cdns_torrent_phy_suspend_noirq()
3339 if (cdns_phy->already_configured) in cdns_torrent_phy_suspend_noirq()
3340 cdns_phy->already_configured = 0; in cdns_torrent_phy_suspend_noirq()
3342 clk_disable_unprepare(cdns_phy->clk1); in cdns_torrent_phy_suspend_noirq()
3343 clk_disable_unprepare(cdns_phy->clk); in cdns_torrent_phy_suspend_noirq()
3352 int node = cdns_phy->nsubnodes; in cdns_torrent_phy_resume_noirq()
3359 /* Enable APB */ in cdns_torrent_phy_resume_noirq()
3360 reset_control_deassert(cdns_phy->apb_rst); in cdns_torrent_phy_resume_noirq()
3362 if (cdns_phy->nsubnodes > 1) { in cdns_torrent_phy_resume_noirq()
3372 reset_control_assert(cdns_phy->phys[i].lnk_rst); in cdns_torrent_phy_resume_noirq()
3373 reset_control_assert(cdns_phy->apb_rst); in cdns_torrent_phy_resume_noirq()
3375 clk_disable_unprepare(cdns_phy->clk1); in cdns_torrent_phy_resume_noirq()
3376 clk_disable_unprepare(cdns_phy->clk); in cdns_torrent_phy_resume_noirq()
3451 /* Multilink USXGMII, using PLL0, 156.25 MHz Ref clk, no SSC */
3469 /* Multilink SGMII/QSGMII, using PLL1, 100 MHz Ref clk, no SSC */
3484 /* TI J7200, Multilink USXGMII, using PLL0, 156.25 MHz Ref clk, no SSC */
3516 /* TI J7200, Multilink SGMII/QSGMII, using PLL1, 100 MHz Ref clk, no SSC */
3569 * Multilink USXGMII, using PLL1, 156.25 MHz Ref clk, no SSC
3627 /* TI USXGMII configuration: Enable cmn_refclk_rcv_out_en */
3659 /* Single link USXGMII, 156.25 MHz Ref clk, no SSC */
3777 /* DP Multilink, 100 MHz Ref clk, no SSC */
3835 /* Single DP, 19.2 MHz Ref clk, no SSC */
3906 /* Single DP, 25 MHz Ref clk, no SSC */
3977 /* Single DP, 100 MHz Ref clk, no SSC */
4049 /* PCIe and USB Unique SSC link configuration */
4084 /* USB 100 MHz Ref clk, internal SSC */
4177 /* USB 100 MHz Ref clk, no SSC */
4250 /* Single link USB, 100 MHz Ref clk, internal SSC */
4297 /* PCIe and SGMII/QSGMII Unique SSC link configuration */
4332 /* SGMII 100 MHz Ref clk, no SSC */
4452 /* SGMII 100 MHz Ref clk, internal SSC */
4509 /* QSGMII 100 MHz Ref clk, no SSC */
4632 /* QSGMII 100 MHz Ref clk, internal SSC */
4711 /* For PCIe (with some other protocol), 100 MHz Ref clk, internal SSC */
4766 /* Single link PCIe, 100 MHz Ref clk, internal SSC */
4821 /* PCIe, 100 MHz Ref clk, no SSC & external SSC */
5696 .compatible = "cdns,torrent-phy",
5700 .compatible = "ti,j721e-serdes-10g",
5704 .compatible = "ti,j7200-serdes-10g",
5715 .name = "cdns-torrent-phy",