Lines Matching defs:cdns_phy

293 static int cdns_torrent_dp_run(struct cdns_torrent_phy *cdns_phy,
296 int cdns_torrent_dp_wait_pma_cmn_ready(struct cdns_torrent_phy *cdns_phy);
297 static void cdns_torrent_dp_pma_cfg(struct cdns_torrent_phy *cdns_phy,
300 void cdns_torrent_dp_pma_cmn_cfg_19_2mhz(struct cdns_torrent_phy *cdns_phy);
302 void cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(struct cdns_torrent_phy *cdns_phy,
305 void cdns_torrent_dp_pma_cmn_cfg_25mhz(struct cdns_torrent_phy *cdns_phy);
307 void cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(struct cdns_torrent_phy *cdns_phy,
309 static void cdns_torrent_dp_pma_lane_cfg(struct cdns_torrent_phy *cdns_phy,
311 static void cdns_torrent_dp_pma_cmn_rate(struct cdns_torrent_phy *cdns_phy,
315 static int cdns_torrent_dp_set_power_state(struct cdns_torrent_phy *cdns_phy,
563 static int cdns_torrent_dp_set_pll_en(struct cdns_torrent_phy *cdns_phy,
569 struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg;
618 static int cdns_torrent_dp_configure_rate(struct cdns_torrent_phy *cdns_phy,
625 regmap_field_write(cdns_phy->phy_pma_pll_raw_ctrl, 0x0);
631 ret = regmap_field_read_poll_timeout(cdns_phy->phy_pma_cmn_ctrl_2,
640 if (cdns_phy->ref_clk_rate == REF_CLK_19_2MHz) {
642 cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(cdns_phy, dp->link_rate,
644 cdns_torrent_dp_pma_cmn_cfg_19_2mhz(cdns_phy);
645 } else if (cdns_phy->ref_clk_rate == REF_CLK_25MHz) {
647 cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(cdns_phy, dp->link_rate,
649 cdns_torrent_dp_pma_cmn_cfg_25mhz(cdns_phy);
651 cdns_torrent_dp_pma_cmn_rate(cdns_phy, dp->link_rate, dp->lanes);
654 regmap_field_write(cdns_phy->phy_pma_pll_raw_ctrl, 0x3);
660 ret = regmap_field_read_poll_timeout(cdns_phy->phy_pma_cmn_ctrl_2,
730 static void cdns_torrent_dp_set_a0_pll(struct cdns_torrent_phy *cdns_phy,
733 struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg;
766 static int cdns_torrent_dp_set_lanes(struct cdns_torrent_phy *cdns_phy,
771 struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg;
793 cdns_torrent_dp_set_a0_pll(cdns_phy, dp->lanes);
800 ret = cdns_torrent_dp_wait_pma_cmn_ready(cdns_phy);
809 ret = cdns_torrent_dp_run(cdns_phy, dp->lanes);
815 static int cdns_torrent_dp_set_rate(struct cdns_torrent_phy *cdns_phy,
820 ret = cdns_torrent_dp_set_power_state(cdns_phy, dp->lanes,
824 ret = cdns_torrent_dp_set_pll_en(cdns_phy, dp, false);
829 ret = cdns_torrent_dp_configure_rate(cdns_phy, dp);
834 ret = cdns_torrent_dp_set_pll_en(cdns_phy, dp, true);
837 ret = cdns_torrent_dp_set_power_state(cdns_phy, dp->lanes,
841 ret = cdns_torrent_dp_set_power_state(cdns_phy, dp->lanes,
851 static void cdns_torrent_dp_set_voltages(struct cdns_torrent_phy *cdns_phy,
858 val = cdns_torrent_phy_read(cdns_phy->regmap_tx_lane_cdb[lane],
865 cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[lane],
868 cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[lane],
871 cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[lane],
874 cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[lane],
878 cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[lane],
882 val = cdns_torrent_phy_read(cdns_phy->regmap_tx_lane_cdb[lane],
889 cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[lane],
898 struct cdns_torrent_phy *cdns_phy = dev_get_drvdata(phy->dev.parent);
908 ret = cdns_torrent_dp_set_lanes(cdns_phy, &opts->dp);
916 ret = cdns_torrent_dp_set_rate(cdns_phy, &opts->dp);
924 cdns_torrent_dp_set_voltages(cdns_phy, &opts->dp);
934 struct cdns_torrent_phy *cdns_phy = dev_get_drvdata(phy->dev.parent);
935 struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg;
937 switch (cdns_phy->ref_clk_rate) {
943 dev_err(cdns_phy->dev, "Unsupported Ref Clock Rate\n");
950 cdns_torrent_dp_pma_cfg(cdns_phy, inst);
956 cdns_torrent_dp_set_a0_pll(cdns_phy, inst->num_lanes);
971 if (cdns_phy->ref_clk_rate == REF_CLK_19_2MHz)
972 cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(cdns_phy,
973 cdns_phy->max_bit_rate,
975 else if (cdns_phy->ref_clk_rate == REF_CLK_25MHz)
976 cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(cdns_phy,
977 cdns_phy->max_bit_rate,
979 cdns_torrent_dp_pma_cmn_rate(cdns_phy, cdns_phy->max_bit_rate,
983 regmap_field_write(cdns_phy->phy_reset_ctrl, 0x1);
987 ret = cdns_torrent_dp_wait_pma_cmn_ready(cdns_phy);
991 ret = cdns_torrent_dp_run(cdns_phy, inst->num_lanes);
997 int cdns_torrent_dp_wait_pma_cmn_ready(struct cdns_torrent_phy *cdns_phy)
1001 struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg;
1006 dev_err(cdns_phy->dev,
1014 static void cdns_torrent_dp_pma_cfg(struct cdns_torrent_phy *cdns_phy,
1019 if (cdns_phy->ref_clk_rate == REF_CLK_19_2MHz)
1021 cdns_torrent_dp_pma_cmn_cfg_19_2mhz(cdns_phy);
1022 else if (cdns_phy->ref_clk_rate == REF_CLK_25MHz)
1024 cdns_torrent_dp_pma_cmn_cfg_25mhz(cdns_phy);
1028 cdns_torrent_dp_pma_lane_cfg(cdns_phy, i);
1032 void cdns_torrent_dp_pma_cmn_cfg_19_2mhz(struct cdns_torrent_phy *cdns_phy)
1034 struct regmap *regmap = cdns_phy->regmap_common_cdb;
1080 void cdns_torrent_dp_enable_ssc_19_2mhz(struct cdns_torrent_phy *cdns_phy,
1083 struct regmap *regmap = cdns_phy->regmap_common_cdb;
1096 void cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(struct cdns_torrent_phy *cdns_phy,
1099 struct regmap *regmap = cdns_phy->regmap_common_cdb;
1127 cdns_torrent_dp_enable_ssc_19_2mhz(cdns_phy, 0x033A,
1155 cdns_torrent_dp_enable_ssc_19_2mhz(cdns_phy, 0x05DD,
1182 cdns_torrent_dp_enable_ssc_19_2mhz(cdns_phy, 0x0536,
1208 cdns_torrent_dp_enable_ssc_19_2mhz(cdns_phy, 0x04D7,
1257 void cdns_torrent_dp_pma_cmn_cfg_25mhz(struct cdns_torrent_phy *cdns_phy)
1259 struct regmap *regmap = cdns_phy->regmap_common_cdb;
1304 static void cdns_torrent_dp_enable_ssc_25mhz(struct cdns_torrent_phy *cdns_phy,
1307 struct regmap *regmap = cdns_phy->regmap_common_cdb;
1320 void cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(struct cdns_torrent_phy *cdns_phy,
1323 struct regmap *regmap = cdns_phy->regmap_common_cdb;
1339 cdns_torrent_dp_enable_ssc_25mhz(cdns_phy, 0x0423);
1354 cdns_torrent_dp_enable_ssc_25mhz(cdns_phy, 0x03B9);
1368 cdns_torrent_dp_enable_ssc_25mhz(cdns_phy, 0x034F);
1381 cdns_torrent_dp_enable_ssc_25mhz(cdns_phy, 0x031A);
1423 static void cdns_torrent_dp_pma_cmn_rate(struct cdns_torrent_phy *cdns_phy,
1431 regmap_field_write(cdns_phy->phy_pll_cfg, 0x0);
1459 cdns_torrent_phy_write(cdns_phy->regmap_common_cdb,
1461 cdns_torrent_phy_write(cdns_phy->regmap_common_cdb,
1466 cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[i],
1470 static void cdns_torrent_dp_pma_lane_cfg(struct cdns_torrent_phy *cdns_phy,
1474 if (cdns_phy->ref_clk_rate == REF_CLK_19_2MHz)
1475 cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[lane],
1477 else if (cdns_phy->ref_clk_rate == REF_CLK_25MHz)
1478 cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[lane],
1482 cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[lane],
1484 cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[lane],
1486 cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[lane],
1488 cdns_torrent_phy_write(cdns_phy->regmap_rx_lane_cdb[lane],
1490 cdns_torrent_phy_write(cdns_phy->regmap_rx_lane_cdb[lane],
1492 cdns_torrent_phy_write(cdns_phy->regmap_rx_lane_cdb[lane],
1495 cdns_torrent_phy_write(cdns_phy->regmap_rx_lane_cdb[lane],
1498 cdns_torrent_phy_write(cdns_phy->regmap_rx_lane_cdb[lane],
1500 cdns_torrent_phy_write(cdns_phy->regmap_rx_lane_cdb[lane],
1502 cdns_torrent_phy_write(cdns_phy->regmap_rx_lane_cdb[lane],
1505 cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[lane],
1507 cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[lane],
1509 cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[lane],
1513 static int cdns_torrent_dp_set_power_state(struct cdns_torrent_phy *cdns_phy,
1523 struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg;
1575 static int cdns_torrent_dp_run(struct cdns_torrent_phy *cdns_phy, u32 num_lanes)
1579 struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg;
1589 dev_err(cdns_phy->dev,
1596 ret = cdns_torrent_dp_set_power_state(cdns_phy, num_lanes,
1601 ret = cdns_torrent_dp_set_power_state(cdns_phy, num_lanes,
1610 struct cdns_torrent_phy *cdns_phy = dev_get_drvdata(phy->dev.parent);
1614 if (cdns_phy->nsubnodes == 1) {
1619 ret = reset_control_deassert(cdns_phy->phy_rst);
1628 ret = regmap_field_read_poll_timeout(cdns_phy->phy_pma_cmn_ctrl_1,
1632 dev_err(cdns_phy->dev, "Timeout waiting for CMN ready\n");
1644 struct cdns_torrent_phy *cdns_phy = dev_get_drvdata(phy->dev.parent);
1647 if (cdns_phy->nsubnodes != 1)
1650 ret = reset_control_assert(cdns_phy->phy_rst);
1675 static int cdns_torrent_dp_regfield_init(struct cdns_torrent_phy *cdns_phy)
1677 struct device *dev = cdns_phy->dev;
1681 regmap = cdns_phy->regmap_dptx_phy_reg;
1687 cdns_phy->phy_reset_ctrl = field;
1692 static int cdns_torrent_regfield_init(struct cdns_torrent_phy *cdns_phy)
1694 struct device *dev = cdns_phy->dev;
1698 regmap = cdns_phy->regmap_phy_pcs_common_cdb;
1704 cdns_phy->phy_pll_cfg = field;
1706 regmap = cdns_phy->regmap_phy_pma_common_cdb;
1712 cdns_phy->phy_pma_cmn_ctrl_1 = field;
1714 regmap = cdns_phy->regmap_phy_pma_common_cdb;
1720 cdns_phy->phy_pma_cmn_ctrl_2 = field;
1722 regmap = cdns_phy->regmap_phy_pma_common_cdb;
1728 cdns_phy->phy_pma_pll_raw_ctrl = field;
1733 static int cdns_torrent_dp_regmap_init(struct cdns_torrent_phy *cdns_phy)
1735 void __iomem *base = cdns_phy->base;
1736 struct device *dev = cdns_phy->dev;
1741 reg_offset_shift = cdns_phy->init_data->reg_offset_shift;
1751 cdns_phy->regmap_dptx_phy_reg = regmap;
1756 static int cdns_torrent_regmap_init(struct cdns_torrent_phy *cdns_phy)
1758 void __iomem *sd_base = cdns_phy->sd_base;
1760 struct device *dev = cdns_phy->dev;
1765 block_offset_shift = cdns_phy->init_data->block_offset_shift;
1766 reg_offset_shift = cdns_phy->init_data->reg_offset_shift;
1778 cdns_phy->regmap_tx_lane_cdb[i] = regmap;
1789 cdns_phy->regmap_rx_lane_cdb[i] = regmap;
1800 cdns_phy->regmap_common_cdb = regmap;
1810 cdns_phy->regmap_phy_pcs_common_cdb = regmap;
1820 cdns_phy->regmap_phy_pma_common_cdb = regmap;
1827 struct cdns_torrent_phy *cdns_phy = dev_get_drvdata(phy->dev.parent);
1828 const struct cdns_torrent_data *init_data = cdns_phy->init_data;
1840 if (cdns_phy->nsubnodes > 1)
1858 regmap = cdns_phy->regmap_common_cdb;
1864 regmap_field_write(cdns_phy->phy_pll_cfg, reg_pairs[0].val);
1876 regmap = cdns_phy->regmap_tx_lane_cdb[i + inst->mlane];
1888 regmap = cdns_phy->regmap_phy_pcs_common_cdb;
1899 regmap = cdns_phy->regmap_common_cdb;
1911 regmap = cdns_phy->regmap_tx_lane_cdb[i + inst->mlane];
1924 regmap = cdns_phy->regmap_rx_lane_cdb[i + inst->mlane];
1935 int cdns_torrent_phy_configure_multilink(struct cdns_torrent_phy *cdns_phy)
1937 const struct cdns_torrent_data *init_data = cdns_phy->init_data;
1949 if (cdns_phy->nsubnodes != 2)
1952 phy_t1 = cdns_phy->phys[0].phy_type;
1953 phy_t2 = cdns_phy->phys[1].phy_type;
1959 for (node = 0; node < cdns_phy->nsubnodes; node++) {
1971 mlane = cdns_phy->phys[node].mlane;
1972 ssc = cdns_phy->phys[node].ssc_mode;
1973 num_lanes = cdns_phy->phys[node].num_lanes;
1989 regmap = cdns_phy->regmap_common_cdb;
1995 regmap_field_write(cdns_phy->phy_pll_cfg,
2008 regmap = cdns_phy->regmap_tx_lane_cdb[i + mlane];
2020 regmap = cdns_phy->regmap_phy_pcs_common_cdb;
2031 regmap = cdns_phy->regmap_common_cdb;
2043 regmap = cdns_phy->regmap_tx_lane_cdb[i + mlane];
2056 regmap = cdns_phy->regmap_rx_lane_cdb[i + mlane];
2063 reset_control_deassert(cdns_phy->phys[node].lnk_rst);
2067 ret = reset_control_deassert(cdns_phy->phy_rst);
2076 struct cdns_torrent_phy *cdns_phy;
2091 cdns_phy = devm_kzalloc(dev, sizeof(*cdns_phy), GFP_KERNEL);
2092 if (!cdns_phy)
2095 dev_set_drvdata(dev, cdns_phy);
2096 cdns_phy->dev = dev;
2097 cdns_phy->init_data = data;
2099 cdns_phy->phy_rst = devm_reset_control_get_exclusive_by_index(dev, 0);
2100 if (IS_ERR(cdns_phy->phy_rst)) {
2103 return PTR_ERR(cdns_phy->phy_rst);
2106 cdns_phy->apb_rst = devm_reset_control_get_optional(dev, "torrent_apb");
2107 if (IS_ERR(cdns_phy->apb_rst)) {
2110 return PTR_ERR(cdns_phy->apb_rst);
2113 cdns_phy->clk = devm_clk_get(dev, "refclk");
2114 if (IS_ERR(cdns_phy->clk)) {
2116 return PTR_ERR(cdns_phy->clk);
2119 cdns_phy->sd_base = devm_platform_ioremap_resource(pdev, 0);
2120 if (IS_ERR(cdns_phy->sd_base))
2121 return PTR_ERR(cdns_phy->sd_base);
2129 ret = cdns_torrent_regmap_init(cdns_phy);
2133 ret = cdns_torrent_regfield_init(cdns_phy);
2137 ret = clk_prepare_enable(cdns_phy->clk);
2139 dev_err(cdns_phy->dev, "Failed to prepare ref clock\n");
2143 cdns_phy->ref_clk_rate = clk_get_rate(cdns_phy->clk);
2144 if (!(cdns_phy->ref_clk_rate)) {
2145 dev_err(cdns_phy->dev, "Failed to get ref clock rate\n");
2146 clk_disable_unprepare(cdns_phy->clk);
2151 reset_control_deassert(cdns_phy->apb_rst);
2160 cdns_phy->phys[node].lnk_rst =
2162 if (IS_ERR(cdns_phy->phys[node].lnk_rst)) {
2165 ret = PTR_ERR(cdns_phy->phys[node].lnk_rst);
2170 &cdns_phy->phys[node].mlane)) {
2186 cdns_phy->phys[node].phy_type = TYPE_PCIE;
2189 cdns_phy->phys[node].phy_type = TYPE_DP;
2192 cdns_phy->phys[node].phy_type = TYPE_SGMII;
2195 cdns_phy->phys[node].phy_type = TYPE_QSGMII;
2198 cdns_phy->phys[node].phy_type = TYPE_USB;
2207 &cdns_phy->phys[node].num_lanes)) {
2214 total_num_lanes += cdns_phy->phys[node].num_lanes;
2217 cdns_phy->phys[node].ssc_mode = NO_SSC;
2219 &cdns_phy->phys[node].ssc_mode);
2227 if (cdns_phy->phys[node].phy_type == TYPE_DP) {
2228 switch (cdns_phy->phys[node].num_lanes) {
2236 cdns_phy->phys[node].num_lanes);
2241 cdns_phy->max_bit_rate = DEFAULT_MAX_BIT_RATE;
2243 &cdns_phy->max_bit_rate);
2245 switch (cdns_phy->max_bit_rate) {
2258 cdns_phy->max_bit_rate);
2264 cdns_phy->base = devm_platform_ioremap_resource(pdev, 1);
2265 if (IS_ERR(cdns_phy->base)) {
2266 ret = PTR_ERR(cdns_phy->base);
2271 ret = cdns_torrent_dp_regmap_init(cdns_phy);
2275 ret = cdns_torrent_dp_regfield_init(cdns_phy);
2283 cdns_phy->phys[node].num_lanes,
2284 cdns_phy->max_bit_rate / 1000,
2285 cdns_phy->max_bit_rate % 1000);
2287 gphy->attrs.bus_width = cdns_phy->phys[node].num_lanes;
2288 gphy->attrs.max_link_rate = cdns_phy->max_bit_rate;
2292 cdns_phy->phys[node].phy = gphy;
2293 phy_set_drvdata(gphy, &cdns_phy->phys[node]);
2297 cdns_phy->nsubnodes = node;
2305 if (cdns_phy->nsubnodes > 1) {
2306 ret = cdns_torrent_phy_configure_multilink(cdns_phy);
2323 reset_control_put(cdns_phy->phys[i].lnk_rst);
2325 reset_control_assert(cdns_phy->apb_rst);
2326 clk_disable_unprepare(cdns_phy->clk);
2332 struct cdns_torrent_phy *cdns_phy = platform_get_drvdata(pdev);
2335 reset_control_assert(cdns_phy->phy_rst);
2336 reset_control_assert(cdns_phy->apb_rst);
2337 for (i = 0; i < cdns_phy->nsubnodes; i++) {
2338 reset_control_assert(cdns_phy->phys[i].lnk_rst);
2339 reset_control_put(cdns_phy->phys[i].lnk_rst);
2342 clk_disable_unprepare(cdns_phy->clk);