Lines Matching +full:tx +full:- +full:pcs
1 // SPDX-License-Identifier: GPL-2.0
7 #include <linux/clk-provider.h>
23 #include "phy-qcom-qmp.h"
24 #include "phy-qcom-qmp-pcs-misc-v3.h"
25 #include "phy-qcom-qmp-pcs-usb-v4.h"
26 #include "phy-qcom-qmp-pcs-usb-v5.h"
89 /* set of registers with offsets different per-PHY */
91 /* PCS registers */
502 u16 pcs; member
504 u16 tx; member
508 /* struct qmp_phy_cfg - per-PHY initialization config */
514 /* Init sequence for PHY blocks - serdes, tx, rx, pcs */
539 /* Offset from PCS to PCS_USB region */
549 void __iomem *pcs; member
552 void __iomem *tx; member
620 "vdda-phy", "vdda-pll",
744 if (!(t->lane_mask & lane_mask)) in qmp_usb_legacy_configure_lane()
747 writel(t->val, base + t->offset); in qmp_usb_legacy_configure_lane()
760 const struct qmp_phy_cfg *cfg = qmp->cfg; in qmp_usb_legacy_serdes_init()
761 void __iomem *serdes = qmp->serdes; in qmp_usb_legacy_serdes_init()
762 const struct qmp_phy_init_tbl *serdes_tbl = cfg->serdes_tbl; in qmp_usb_legacy_serdes_init()
763 int serdes_tbl_num = cfg->serdes_tbl_num; in qmp_usb_legacy_serdes_init()
773 void __iomem *dp_com = qmp->dp_com; in qmp_usb_legacy_init_dp_com()
782 /* Default type-c orientation, i.e CC1 */ in qmp_usb_legacy_init_dp_com()
788 /* bring both QMP USB and QMP DP PHYs PCS block out of reset */ in qmp_usb_legacy_init_dp_com()
800 const struct qmp_phy_cfg *cfg = qmp->cfg; in qmp_usb_legacy_init()
801 void __iomem *pcs = qmp->pcs; in qmp_usb_legacy_init() local
804 ret = regulator_bulk_enable(cfg->num_vregs, qmp->vregs); in qmp_usb_legacy_init()
806 dev_err(qmp->dev, "failed to enable regulators, err=%d\n", ret); in qmp_usb_legacy_init()
810 ret = reset_control_bulk_assert(cfg->num_resets, qmp->resets); in qmp_usb_legacy_init()
812 dev_err(qmp->dev, "reset assert failed\n"); in qmp_usb_legacy_init()
816 ret = reset_control_bulk_deassert(cfg->num_resets, qmp->resets); in qmp_usb_legacy_init()
818 dev_err(qmp->dev, "reset deassert failed\n"); in qmp_usb_legacy_init()
822 ret = clk_bulk_prepare_enable(cfg->num_clks, qmp->clks); in qmp_usb_legacy_init()
828 qphy_setbits(pcs, cfg->regs[QPHY_PCS_POWER_DOWN_CONTROL], SW_PWRDN); in qmp_usb_legacy_init()
833 reset_control_bulk_assert(cfg->num_resets, qmp->resets); in qmp_usb_legacy_init()
835 regulator_bulk_disable(cfg->num_vregs, qmp->vregs); in qmp_usb_legacy_init()
843 const struct qmp_phy_cfg *cfg = qmp->cfg; in qmp_usb_legacy_exit()
845 reset_control_bulk_assert(cfg->num_resets, qmp->resets); in qmp_usb_legacy_exit()
847 clk_bulk_disable_unprepare(cfg->num_clks, qmp->clks); in qmp_usb_legacy_exit()
849 regulator_bulk_disable(cfg->num_vregs, qmp->vregs); in qmp_usb_legacy_exit()
857 const struct qmp_phy_cfg *cfg = qmp->cfg; in qmp_usb_legacy_power_on()
858 void __iomem *tx = qmp->tx; in qmp_usb_legacy_power_on() local
859 void __iomem *rx = qmp->rx; in qmp_usb_legacy_power_on()
860 void __iomem *pcs = qmp->pcs; in qmp_usb_legacy_power_on() local
867 ret = clk_prepare_enable(qmp->pipe_clk); in qmp_usb_legacy_power_on()
869 dev_err(qmp->dev, "pipe_clk enable failed err=%d\n", ret); in qmp_usb_legacy_power_on()
873 /* Tx, Rx, and PCS configurations */ in qmp_usb_legacy_power_on()
874 qmp_usb_legacy_configure_lane(tx, cfg->tx_tbl, cfg->tx_tbl_num, 1); in qmp_usb_legacy_power_on()
875 qmp_usb_legacy_configure_lane(rx, cfg->rx_tbl, cfg->rx_tbl_num, 1); in qmp_usb_legacy_power_on()
877 if (cfg->lanes >= 2) { in qmp_usb_legacy_power_on()
878 qmp_usb_legacy_configure_lane(qmp->tx2, cfg->tx_tbl, cfg->tx_tbl_num, 2); in qmp_usb_legacy_power_on()
879 qmp_usb_legacy_configure_lane(qmp->rx2, cfg->rx_tbl, cfg->rx_tbl_num, 2); in qmp_usb_legacy_power_on()
882 qmp_usb_legacy_configure(pcs, cfg->pcs_tbl, cfg->pcs_tbl_num); in qmp_usb_legacy_power_on()
887 qphy_clrbits(pcs, cfg->regs[QPHY_SW_RESET], SW_RESET); in qmp_usb_legacy_power_on()
889 /* start SerDes and Phy-Coding-Sublayer */ in qmp_usb_legacy_power_on()
890 qphy_setbits(pcs, cfg->regs[QPHY_START_CTRL], SERDES_START | PCS_START); in qmp_usb_legacy_power_on()
892 status = pcs + cfg->regs[QPHY_PCS_STATUS]; in qmp_usb_legacy_power_on()
896 dev_err(qmp->dev, "phy initialization timed-out\n"); in qmp_usb_legacy_power_on()
903 clk_disable_unprepare(qmp->pipe_clk); in qmp_usb_legacy_power_on()
911 const struct qmp_phy_cfg *cfg = qmp->cfg; in qmp_usb_legacy_power_off()
913 clk_disable_unprepare(qmp->pipe_clk); in qmp_usb_legacy_power_off()
916 qphy_setbits(qmp->pcs, cfg->regs[QPHY_SW_RESET], SW_RESET); in qmp_usb_legacy_power_off()
918 /* stop SerDes and Phy-Coding-Sublayer */ in qmp_usb_legacy_power_off()
919 qphy_clrbits(qmp->pcs, cfg->regs[QPHY_START_CTRL], in qmp_usb_legacy_power_off()
923 qphy_clrbits(qmp->pcs, cfg->regs[QPHY_PCS_POWER_DOWN_CONTROL], in qmp_usb_legacy_power_off()
958 qmp->mode = mode; in qmp_usb_legacy_set_mode()
972 const struct qmp_phy_cfg *cfg = qmp->cfg; in qmp_usb_legacy_enable_autonomous_mode()
973 void __iomem *pcs_usb = qmp->pcs_usb ?: qmp->pcs; in qmp_usb_legacy_enable_autonomous_mode()
974 void __iomem *pcs_misc = qmp->pcs_misc; in qmp_usb_legacy_enable_autonomous_mode()
977 if (qmp->mode == PHY_MODE_USB_HOST_SS || in qmp_usb_legacy_enable_autonomous_mode()
978 qmp->mode == PHY_MODE_USB_DEVICE_SS) in qmp_usb_legacy_enable_autonomous_mode()
984 qphy_setbits(pcs_usb, cfg->regs[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR], IRQ_CLEAR); in qmp_usb_legacy_enable_autonomous_mode()
986 qphy_clrbits(pcs_usb, cfg->regs[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR], IRQ_CLEAR); in qmp_usb_legacy_enable_autonomous_mode()
988 qphy_clrbits(pcs_usb, cfg->regs[QPHY_PCS_AUTONOMOUS_MODE_CTRL], in qmp_usb_legacy_enable_autonomous_mode()
992 qphy_setbits(pcs_usb, cfg->regs[QPHY_PCS_AUTONOMOUS_MODE_CTRL], intr_mask); in qmp_usb_legacy_enable_autonomous_mode()
1001 const struct qmp_phy_cfg *cfg = qmp->cfg; in qmp_usb_legacy_disable_autonomous_mode()
1002 void __iomem *pcs_usb = qmp->pcs_usb ?: qmp->pcs; in qmp_usb_legacy_disable_autonomous_mode()
1003 void __iomem *pcs_misc = qmp->pcs_misc; in qmp_usb_legacy_disable_autonomous_mode()
1009 qphy_clrbits(pcs_usb, cfg->regs[QPHY_PCS_AUTONOMOUS_MODE_CTRL], in qmp_usb_legacy_disable_autonomous_mode()
1012 qphy_setbits(pcs_usb, cfg->regs[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR], IRQ_CLEAR); in qmp_usb_legacy_disable_autonomous_mode()
1014 qphy_clrbits(pcs_usb, cfg->regs[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR], IRQ_CLEAR); in qmp_usb_legacy_disable_autonomous_mode()
1020 const struct qmp_phy_cfg *cfg = qmp->cfg; in qmp_usb_legacy_runtime_suspend()
1022 dev_vdbg(dev, "Suspending QMP phy, mode:%d\n", qmp->mode); in qmp_usb_legacy_runtime_suspend()
1024 if (!qmp->phy->init_count) { in qmp_usb_legacy_runtime_suspend()
1031 clk_disable_unprepare(qmp->pipe_clk); in qmp_usb_legacy_runtime_suspend()
1032 clk_bulk_disable_unprepare(cfg->num_clks, qmp->clks); in qmp_usb_legacy_runtime_suspend()
1040 const struct qmp_phy_cfg *cfg = qmp->cfg; in qmp_usb_legacy_runtime_resume()
1043 dev_vdbg(dev, "Resuming QMP phy, mode:%d\n", qmp->mode); in qmp_usb_legacy_runtime_resume()
1045 if (!qmp->phy->init_count) { in qmp_usb_legacy_runtime_resume()
1050 ret = clk_bulk_prepare_enable(cfg->num_clks, qmp->clks); in qmp_usb_legacy_runtime_resume()
1054 ret = clk_prepare_enable(qmp->pipe_clk); in qmp_usb_legacy_runtime_resume()
1057 clk_bulk_disable_unprepare(cfg->num_clks, qmp->clks); in qmp_usb_legacy_runtime_resume()
1073 const struct qmp_phy_cfg *cfg = qmp->cfg; in qmp_usb_legacy_vreg_init()
1074 struct device *dev = qmp->dev; in qmp_usb_legacy_vreg_init()
1075 int num = cfg->num_vregs; in qmp_usb_legacy_vreg_init()
1078 qmp->vregs = devm_kcalloc(dev, num, sizeof(*qmp->vregs), GFP_KERNEL); in qmp_usb_legacy_vreg_init()
1079 if (!qmp->vregs) in qmp_usb_legacy_vreg_init()
1080 return -ENOMEM; in qmp_usb_legacy_vreg_init()
1083 qmp->vregs[i].supply = cfg->vreg_list[i]; in qmp_usb_legacy_vreg_init()
1085 return devm_regulator_bulk_get(dev, num, qmp->vregs); in qmp_usb_legacy_vreg_init()
1090 const struct qmp_phy_cfg *cfg = qmp->cfg; in qmp_usb_legacy_reset_init()
1091 struct device *dev = qmp->dev; in qmp_usb_legacy_reset_init()
1095 qmp->resets = devm_kcalloc(dev, cfg->num_resets, in qmp_usb_legacy_reset_init()
1096 sizeof(*qmp->resets), GFP_KERNEL); in qmp_usb_legacy_reset_init()
1097 if (!qmp->resets) in qmp_usb_legacy_reset_init()
1098 return -ENOMEM; in qmp_usb_legacy_reset_init()
1100 for (i = 0; i < cfg->num_resets; i++) in qmp_usb_legacy_reset_init()
1101 qmp->resets[i].id = cfg->reset_list[i]; in qmp_usb_legacy_reset_init()
1103 ret = devm_reset_control_bulk_get_exclusive(dev, cfg->num_resets, qmp->resets); in qmp_usb_legacy_reset_init()
1112 const struct qmp_phy_cfg *cfg = qmp->cfg; in qmp_usb_legacy_clk_init()
1113 struct device *dev = qmp->dev; in qmp_usb_legacy_clk_init()
1114 int num = cfg->num_clks; in qmp_usb_legacy_clk_init()
1117 qmp->clks = devm_kcalloc(dev, num, sizeof(*qmp->clks), GFP_KERNEL); in qmp_usb_legacy_clk_init()
1118 if (!qmp->clks) in qmp_usb_legacy_clk_init()
1119 return -ENOMEM; in qmp_usb_legacy_clk_init()
1122 qmp->clks[i].id = cfg->clk_list[i]; in qmp_usb_legacy_clk_init()
1124 return devm_clk_bulk_get(dev, num, qmp->clks); in qmp_usb_legacy_clk_init()
1142 * +---------------+
1143 * | PHY block |<<---------------------------------------+
1145 * | +-------+ | +-----+ |
1146 * I/P---^-->| PLL |---^--->pipe_clksrc--->| GCC |--->pipe_clk---+
1147 * clk | +-------+ | +-----+
1148 * +---------------+
1152 struct clk_fixed_rate *fixed = &qmp->pipe_clk_fixed; in phy_pipe_clk_register()
1156 ret = of_property_read_string(np, "clock-output-names", &init.name); in phy_pipe_clk_register()
1158 dev_err(qmp->dev, "%pOFn: No clock-output-names\n", np); in phy_pipe_clk_register()
1165 fixed->fixed_rate = 125000000; in phy_pipe_clk_register()
1166 fixed->hw.init = &init; in phy_pipe_clk_register()
1168 ret = devm_clk_hw_register(qmp->dev, &fixed->hw); in phy_pipe_clk_register()
1172 ret = of_clk_add_hw_provider(np, of_clk_hw_simple_get, &fixed->hw); in phy_pipe_clk_register()
1180 return devm_add_action_or_reset(qmp->dev, phy_clk_release_provider, np); in phy_pipe_clk_register()
1190 return IOMEM_ERR_PTR(-EINVAL); in qmp_usb_legacy_iomap()
1200 struct platform_device *pdev = to_platform_device(qmp->dev); in qmp_usb_legacy_parse_dt_legacy()
1201 const struct qmp_phy_cfg *cfg = qmp->cfg; in qmp_usb_legacy_parse_dt_legacy()
1202 struct device *dev = qmp->dev; in qmp_usb_legacy_parse_dt_legacy()
1205 qmp->serdes = devm_platform_ioremap_resource(pdev, 0); in qmp_usb_legacy_parse_dt_legacy()
1206 if (IS_ERR(qmp->serdes)) in qmp_usb_legacy_parse_dt_legacy()
1207 return PTR_ERR(qmp->serdes); in qmp_usb_legacy_parse_dt_legacy()
1209 qmp->dp_com = devm_platform_ioremap_resource(pdev, 1); in qmp_usb_legacy_parse_dt_legacy()
1210 if (IS_ERR(qmp->dp_com)) in qmp_usb_legacy_parse_dt_legacy()
1211 return PTR_ERR(qmp->dp_com); in qmp_usb_legacy_parse_dt_legacy()
1215 * Resources are indexed as: tx -> 0; rx -> 1; pcs -> 2. in qmp_usb_legacy_parse_dt_legacy()
1216 * For dual lane PHYs: tx2 -> 3, rx2 -> 4, pcs_misc (optional) -> 5 in qmp_usb_legacy_parse_dt_legacy()
1217 * For single lane PHYs: pcs_misc (optional) -> 3. in qmp_usb_legacy_parse_dt_legacy()
1219 qmp->tx = devm_of_iomap(dev, np, 0, NULL); in qmp_usb_legacy_parse_dt_legacy()
1220 if (IS_ERR(qmp->tx)) in qmp_usb_legacy_parse_dt_legacy()
1221 return PTR_ERR(qmp->tx); in qmp_usb_legacy_parse_dt_legacy()
1223 qmp->rx = devm_of_iomap(dev, np, 1, NULL); in qmp_usb_legacy_parse_dt_legacy()
1224 if (IS_ERR(qmp->rx)) in qmp_usb_legacy_parse_dt_legacy()
1225 return PTR_ERR(qmp->rx); in qmp_usb_legacy_parse_dt_legacy()
1227 qmp->pcs = qmp_usb_legacy_iomap(dev, np, 2, exclusive); in qmp_usb_legacy_parse_dt_legacy()
1228 if (IS_ERR(qmp->pcs)) in qmp_usb_legacy_parse_dt_legacy()
1229 return PTR_ERR(qmp->pcs); in qmp_usb_legacy_parse_dt_legacy()
1231 if (cfg->pcs_usb_offset) in qmp_usb_legacy_parse_dt_legacy()
1232 qmp->pcs_usb = qmp->pcs + cfg->pcs_usb_offset; in qmp_usb_legacy_parse_dt_legacy()
1234 if (cfg->lanes >= 2) { in qmp_usb_legacy_parse_dt_legacy()
1235 qmp->tx2 = devm_of_iomap(dev, np, 3, NULL); in qmp_usb_legacy_parse_dt_legacy()
1236 if (IS_ERR(qmp->tx2)) in qmp_usb_legacy_parse_dt_legacy()
1237 return PTR_ERR(qmp->tx2); in qmp_usb_legacy_parse_dt_legacy()
1239 qmp->rx2 = devm_of_iomap(dev, np, 4, NULL); in qmp_usb_legacy_parse_dt_legacy()
1240 if (IS_ERR(qmp->rx2)) in qmp_usb_legacy_parse_dt_legacy()
1241 return PTR_ERR(qmp->rx2); in qmp_usb_legacy_parse_dt_legacy()
1243 qmp->pcs_misc = devm_of_iomap(dev, np, 5, NULL); in qmp_usb_legacy_parse_dt_legacy()
1245 qmp->pcs_misc = devm_of_iomap(dev, np, 3, NULL); in qmp_usb_legacy_parse_dt_legacy()
1248 if (IS_ERR(qmp->pcs_misc)) { in qmp_usb_legacy_parse_dt_legacy()
1249 dev_vdbg(dev, "PHY pcs_misc-reg not used\n"); in qmp_usb_legacy_parse_dt_legacy()
1250 qmp->pcs_misc = NULL; in qmp_usb_legacy_parse_dt_legacy()
1253 qmp->pipe_clk = devm_get_clk_from_child(dev, np, NULL); in qmp_usb_legacy_parse_dt_legacy()
1254 if (IS_ERR(qmp->pipe_clk)) { in qmp_usb_legacy_parse_dt_legacy()
1255 return dev_err_probe(dev, PTR_ERR(qmp->pipe_clk), in qmp_usb_legacy_parse_dt_legacy()
1264 struct platform_device *pdev = to_platform_device(qmp->dev); in qmp_usb_legacy_parse_dt()
1265 const struct qmp_phy_cfg *cfg = qmp->cfg; in qmp_usb_legacy_parse_dt()
1266 const struct qmp_usb_legacy_offsets *offs = cfg->offsets; in qmp_usb_legacy_parse_dt()
1267 struct device *dev = qmp->dev; in qmp_usb_legacy_parse_dt()
1271 return -EINVAL; in qmp_usb_legacy_parse_dt()
1277 qmp->serdes = base + offs->serdes; in qmp_usb_legacy_parse_dt()
1278 qmp->pcs = base + offs->pcs; in qmp_usb_legacy_parse_dt()
1279 qmp->pcs_usb = base + offs->pcs_usb; in qmp_usb_legacy_parse_dt()
1280 qmp->tx = base + offs->tx; in qmp_usb_legacy_parse_dt()
1281 qmp->rx = base + offs->rx; in qmp_usb_legacy_parse_dt()
1283 qmp->pipe_clk = devm_clk_get(dev, "pipe"); in qmp_usb_legacy_parse_dt()
1284 if (IS_ERR(qmp->pipe_clk)) { in qmp_usb_legacy_parse_dt()
1285 return dev_err_probe(dev, PTR_ERR(qmp->pipe_clk), in qmp_usb_legacy_parse_dt()
1294 struct device *dev = &pdev->dev; in qmp_usb_legacy_probe()
1302 return -ENOMEM; in qmp_usb_legacy_probe()
1304 qmp->dev = dev; in qmp_usb_legacy_probe()
1307 qmp->cfg = of_device_get_match_data(dev); in qmp_usb_legacy_probe()
1308 if (!qmp->cfg) in qmp_usb_legacy_probe()
1309 return -EINVAL; in qmp_usb_legacy_probe()
1324 np = of_get_next_available_child(dev->of_node, NULL); in qmp_usb_legacy_probe()
1328 np = of_node_get(dev->of_node); in qmp_usb_legacy_probe()
1348 qmp->phy = devm_phy_create(dev, np, &qmp_usb_legacy_phy_ops); in qmp_usb_legacy_probe()
1349 if (IS_ERR(qmp->phy)) { in qmp_usb_legacy_probe()
1350 ret = PTR_ERR(qmp->phy); in qmp_usb_legacy_probe()
1355 phy_set_drvdata(qmp->phy, qmp); in qmp_usb_legacy_probe()
1370 .compatible = "qcom,sc7180-qmp-usb3-phy",
1373 .compatible = "qcom,sc8180x-qmp-usb3-phy",
1376 .compatible = "qcom,sdm845-qmp-usb3-phy",
1379 .compatible = "qcom,sm8150-qmp-usb3-phy",
1382 .compatible = "qcom,sm8250-qmp-usb3-phy",
1385 .compatible = "qcom,sm8350-qmp-usb3-phy",
1388 .compatible = "qcom,sm8450-qmp-usb3-phy",
1398 .name = "qcom-qmp-usb-legacy-phy",