Lines Matching +full:serdes +full:- +full:clk

1 // SPDX-License-Identifier: GPL-2.0
6 #include <linux/clk.h>
7 #include <linux/clk-provider.h>
26 #include "phy-qcom-qmp-common.h"
28 #include "phy-qcom-qmp.h"
29 #include "phy-qcom-qmp-pcs-misc-v3.h"
33 /* set of registers with offsets different per-PHY */
288 u16 serdes; member
298 /* struct qmp_phy_cfg - per-PHY initialization config */
302 /* Init sequence for PHY blocks - serdes, tx, rx, pcs */
325 void __iomem *serdes; member
336 struct clk *pipe_clk;
396 "vdda-phy", "vdda-pll",
400 .serdes = 0x0,
460 const struct qmp_phy_cfg *cfg = qmp->cfg; in qmp_usbc_init()
461 void __iomem *pcs = qmp->pcs; in qmp_usbc_init()
465 ret = regulator_bulk_enable(cfg->num_vregs, qmp->vregs); in qmp_usbc_init()
467 dev_err(qmp->dev, "failed to enable regulators, err=%d\n", ret); in qmp_usbc_init()
471 ret = reset_control_bulk_assert(qmp->num_resets, qmp->resets); in qmp_usbc_init()
473 dev_err(qmp->dev, "reset assert failed\n"); in qmp_usbc_init()
477 ret = reset_control_bulk_deassert(qmp->num_resets, qmp->resets); in qmp_usbc_init()
479 dev_err(qmp->dev, "reset deassert failed\n"); in qmp_usbc_init()
483 ret = clk_bulk_prepare_enable(qmp->num_clks, qmp->clks); in qmp_usbc_init()
487 qphy_setbits(pcs, cfg->regs[QPHY_PCS_POWER_DOWN_CONTROL], SW_PWRDN); in qmp_usbc_init()
493 if (qmp->orientation == TYPEC_ORIENTATION_REVERSE) in qmp_usbc_init()
495 writel(val, qmp->pcs_misc); in qmp_usbc_init()
500 reset_control_bulk_assert(qmp->num_resets, qmp->resets); in qmp_usbc_init()
502 regulator_bulk_disable(cfg->num_vregs, qmp->vregs); in qmp_usbc_init()
510 const struct qmp_phy_cfg *cfg = qmp->cfg; in qmp_usbc_exit()
512 reset_control_bulk_assert(qmp->num_resets, qmp->resets); in qmp_usbc_exit()
514 clk_bulk_disable_unprepare(qmp->num_clks, qmp->clks); in qmp_usbc_exit()
516 regulator_bulk_disable(cfg->num_vregs, qmp->vregs); in qmp_usbc_exit()
524 const struct qmp_phy_cfg *cfg = qmp->cfg; in qmp_usbc_power_on()
529 qmp_configure(qmp->dev, qmp->serdes, cfg->serdes_tbl, in qmp_usbc_power_on()
530 cfg->serdes_tbl_num); in qmp_usbc_power_on()
532 ret = clk_prepare_enable(qmp->pipe_clk); in qmp_usbc_power_on()
534 dev_err(qmp->dev, "pipe_clk enable failed err=%d\n", ret); in qmp_usbc_power_on()
539 qmp_configure_lane(qmp->dev, qmp->tx, cfg->tx_tbl, cfg->tx_tbl_num, 1); in qmp_usbc_power_on()
540 qmp_configure_lane(qmp->dev, qmp->rx, cfg->rx_tbl, cfg->rx_tbl_num, 1); in qmp_usbc_power_on()
542 qmp_configure_lane(qmp->dev, qmp->tx2, cfg->tx_tbl, cfg->tx_tbl_num, 2); in qmp_usbc_power_on()
543 qmp_configure_lane(qmp->dev, qmp->rx2, cfg->rx_tbl, cfg->rx_tbl_num, 2); in qmp_usbc_power_on()
545 qmp_configure(qmp->dev, qmp->pcs, cfg->pcs_tbl, cfg->pcs_tbl_num); in qmp_usbc_power_on()
548 qphy_clrbits(qmp->pcs, cfg->regs[QPHY_SW_RESET], SW_RESET); in qmp_usbc_power_on()
550 /* start SerDes and Phy-Coding-Sublayer */ in qmp_usbc_power_on()
551 qphy_setbits(qmp->pcs, cfg->regs[QPHY_START_CTRL], SERDES_START | PCS_START); in qmp_usbc_power_on()
553 status = qmp->pcs + cfg->regs[QPHY_PCS_STATUS]; in qmp_usbc_power_on()
557 dev_err(qmp->dev, "phy initialization timed-out\n"); in qmp_usbc_power_on()
564 clk_disable_unprepare(qmp->pipe_clk); in qmp_usbc_power_on()
572 const struct qmp_phy_cfg *cfg = qmp->cfg; in qmp_usbc_power_off()
574 clk_disable_unprepare(qmp->pipe_clk); in qmp_usbc_power_off()
577 qphy_setbits(qmp->pcs, cfg->regs[QPHY_SW_RESET], SW_RESET); in qmp_usbc_power_off()
579 /* stop SerDes and Phy-Coding-Sublayer */ in qmp_usbc_power_off()
580 qphy_clrbits(qmp->pcs, cfg->regs[QPHY_START_CTRL], in qmp_usbc_power_off()
584 qphy_clrbits(qmp->pcs, cfg->regs[QPHY_PCS_POWER_DOWN_CONTROL], in qmp_usbc_power_off()
595 mutex_lock(&qmp->phy_mutex); in qmp_usbc_enable()
607 qmp->usb_init_count++; in qmp_usbc_enable()
609 mutex_unlock(&qmp->phy_mutex); in qmp_usbc_enable()
619 qmp->usb_init_count--; in qmp_usbc_disable()
630 qmp->mode = mode; in qmp_usbc_set_mode()
644 const struct qmp_phy_cfg *cfg = qmp->cfg; in qmp_usbc_enable_autonomous_mode()
645 void __iomem *pcs = qmp->pcs; in qmp_usbc_enable_autonomous_mode()
648 if (qmp->mode == PHY_MODE_USB_HOST_SS || in qmp_usbc_enable_autonomous_mode()
649 qmp->mode == PHY_MODE_USB_DEVICE_SS) in qmp_usbc_enable_autonomous_mode()
655 qphy_setbits(pcs, cfg->regs[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR], IRQ_CLEAR); in qmp_usbc_enable_autonomous_mode()
657 qphy_clrbits(pcs, cfg->regs[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR], IRQ_CLEAR); in qmp_usbc_enable_autonomous_mode()
659 qphy_clrbits(pcs, cfg->regs[QPHY_PCS_AUTONOMOUS_MODE_CTRL], in qmp_usbc_enable_autonomous_mode()
663 qphy_setbits(pcs, cfg->regs[QPHY_PCS_AUTONOMOUS_MODE_CTRL], intr_mask); in qmp_usbc_enable_autonomous_mode()
666 if (qmp->tcsr_map && qmp->vls_clamp_reg) in qmp_usbc_enable_autonomous_mode()
667 regmap_write(qmp->tcsr_map, qmp->vls_clamp_reg, 1); in qmp_usbc_enable_autonomous_mode()
672 const struct qmp_phy_cfg *cfg = qmp->cfg; in qmp_usbc_disable_autonomous_mode()
673 void __iomem *pcs = qmp->pcs; in qmp_usbc_disable_autonomous_mode()
676 if (qmp->tcsr_map && qmp->vls_clamp_reg) in qmp_usbc_disable_autonomous_mode()
677 regmap_write(qmp->tcsr_map, qmp->vls_clamp_reg, 0); in qmp_usbc_disable_autonomous_mode()
679 qphy_clrbits(pcs, cfg->regs[QPHY_PCS_AUTONOMOUS_MODE_CTRL], in qmp_usbc_disable_autonomous_mode()
682 qphy_setbits(pcs, cfg->regs[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR], IRQ_CLEAR); in qmp_usbc_disable_autonomous_mode()
684 qphy_clrbits(pcs, cfg->regs[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR], IRQ_CLEAR); in qmp_usbc_disable_autonomous_mode()
691 dev_vdbg(dev, "Suspending QMP phy, mode:%d\n", qmp->mode); in qmp_usbc_runtime_suspend()
693 if (!qmp->phy->init_count) { in qmp_usbc_runtime_suspend()
700 clk_disable_unprepare(qmp->pipe_clk); in qmp_usbc_runtime_suspend()
701 clk_bulk_disable_unprepare(qmp->num_clks, qmp->clks); in qmp_usbc_runtime_suspend()
711 dev_vdbg(dev, "Resuming QMP phy, mode:%d\n", qmp->mode); in qmp_usbc_runtime_resume()
713 if (!qmp->phy->init_count) { in qmp_usbc_runtime_resume()
718 ret = clk_bulk_prepare_enable(qmp->num_clks, qmp->clks); in qmp_usbc_runtime_resume()
722 ret = clk_prepare_enable(qmp->pipe_clk); in qmp_usbc_runtime_resume()
725 clk_bulk_disable_unprepare(qmp->num_clks, qmp->clks); in qmp_usbc_runtime_resume()
741 const struct qmp_phy_cfg *cfg = qmp->cfg; in qmp_usbc_vreg_init()
742 struct device *dev = qmp->dev; in qmp_usbc_vreg_init()
743 int num = cfg->num_vregs; in qmp_usbc_vreg_init()
746 qmp->vregs = devm_kcalloc(dev, num, sizeof(*qmp->vregs), GFP_KERNEL); in qmp_usbc_vreg_init()
747 if (!qmp->vregs) in qmp_usbc_vreg_init()
748 return -ENOMEM; in qmp_usbc_vreg_init()
751 qmp->vregs[i].supply = cfg->vreg_list[i]; in qmp_usbc_vreg_init()
753 return devm_regulator_bulk_get(dev, num, qmp->vregs); in qmp_usbc_vreg_init()
760 struct device *dev = qmp->dev; in qmp_usbc_reset_init()
764 qmp->resets = devm_kcalloc(dev, num_resets, in qmp_usbc_reset_init()
765 sizeof(*qmp->resets), GFP_KERNEL); in qmp_usbc_reset_init()
766 if (!qmp->resets) in qmp_usbc_reset_init()
767 return -ENOMEM; in qmp_usbc_reset_init()
770 qmp->resets[i].id = reset_list[i]; in qmp_usbc_reset_init()
772 qmp->num_resets = num_resets; in qmp_usbc_reset_init()
774 ret = devm_reset_control_bulk_get_exclusive(dev, num_resets, qmp->resets); in qmp_usbc_reset_init()
783 struct device *dev = qmp->dev; in qmp_usbc_clk_init()
787 qmp->clks = devm_kcalloc(dev, num, sizeof(*qmp->clks), GFP_KERNEL); in qmp_usbc_clk_init()
788 if (!qmp->clks) in qmp_usbc_clk_init()
789 return -ENOMEM; in qmp_usbc_clk_init()
792 qmp->clks[i].id = qmp_usbc_phy_clk_l[i]; in qmp_usbc_clk_init()
794 qmp->num_clks = num; in qmp_usbc_clk_init()
796 return devm_clk_bulk_get_optional(dev, num, qmp->clks); in qmp_usbc_clk_init()
814 * +---------------+
815 * | PHY block |<<---------------------------------------+
817 * | +-------+ | +-----+ |
818 * I/P---^-->| PLL |---^--->pipe_clksrc--->| GCC |--->pipe_clk---+
819 * clk | +-------+ | +-----+
820 * +---------------+
824 struct clk_fixed_rate *fixed = &qmp->pipe_clk_fixed; in phy_pipe_clk_register()
828 ret = of_property_read_string(np, "clock-output-names", &init.name); in phy_pipe_clk_register()
830 dev_err(qmp->dev, "%pOFn: No clock-output-names\n", np); in phy_pipe_clk_register()
837 fixed->fixed_rate = 125000000; in phy_pipe_clk_register()
838 fixed->hw.init = &init; in phy_pipe_clk_register()
840 ret = devm_clk_hw_register(qmp->dev, &fixed->hw); in phy_pipe_clk_register()
844 ret = of_clk_add_hw_provider(np, of_clk_hw_simple_get, &fixed->hw); in phy_pipe_clk_register()
852 return devm_add_action_or_reset(qmp->dev, phy_clk_release_provider, np); in phy_pipe_clk_register()
861 if (orientation == qmp->orientation || orientation == TYPEC_ORIENTATION_NONE) in qmp_usbc_typec_switch_set()
864 mutex_lock(&qmp->phy_mutex); in qmp_usbc_typec_switch_set()
865 qmp->orientation = orientation; in qmp_usbc_typec_switch_set()
867 if (qmp->usb_init_count) { in qmp_usbc_typec_switch_set()
868 qmp_usbc_power_off(qmp->phy); in qmp_usbc_typec_switch_set()
869 qmp_usbc_exit(qmp->phy); in qmp_usbc_typec_switch_set()
871 qmp_usbc_init(qmp->phy); in qmp_usbc_typec_switch_set()
872 qmp_usbc_power_on(qmp->phy); in qmp_usbc_typec_switch_set()
875 mutex_unlock(&qmp->phy_mutex); in qmp_usbc_typec_switch_set()
884 typec_switch_unregister(qmp->sw); in qmp_usbc_typec_unregister()
890 struct device *dev = qmp->dev; in qmp_usbc_typec_switch_register()
893 sw_desc.fwnode = dev->fwnode; in qmp_usbc_typec_switch_register()
895 qmp->sw = typec_switch_register(dev, &sw_desc); in qmp_usbc_typec_switch_register()
896 if (IS_ERR(qmp->sw)) { in qmp_usbc_typec_switch_register()
897 dev_err(dev, "Unable to register typec switch: %pe\n", qmp->sw); in qmp_usbc_typec_switch_register()
898 return PTR_ERR(qmp->sw); in qmp_usbc_typec_switch_register()
912 struct platform_device *pdev = to_platform_device(qmp->dev); in qmp_usbc_parse_dt_legacy()
913 struct device *dev = qmp->dev; in qmp_usbc_parse_dt_legacy()
916 qmp->serdes = devm_platform_ioremap_resource(pdev, 0); in qmp_usbc_parse_dt_legacy()
917 if (IS_ERR(qmp->serdes)) in qmp_usbc_parse_dt_legacy()
918 return PTR_ERR(qmp->serdes); in qmp_usbc_parse_dt_legacy()
922 * Resources are indexed as: tx -> 0; rx -> 1; pcs -> 2. in qmp_usbc_parse_dt_legacy()
923 * For dual lane PHYs: tx2 -> 3, rx2 -> 4, pcs_misc (optional) -> 5 in qmp_usbc_parse_dt_legacy()
924 * For single lane PHYs: pcs_misc (optional) -> 3. in qmp_usbc_parse_dt_legacy()
926 qmp->tx = devm_of_iomap(dev, np, 0, NULL); in qmp_usbc_parse_dt_legacy()
927 if (IS_ERR(qmp->tx)) in qmp_usbc_parse_dt_legacy()
928 return PTR_ERR(qmp->tx); in qmp_usbc_parse_dt_legacy()
930 qmp->rx = devm_of_iomap(dev, np, 1, NULL); in qmp_usbc_parse_dt_legacy()
931 if (IS_ERR(qmp->rx)) in qmp_usbc_parse_dt_legacy()
932 return PTR_ERR(qmp->rx); in qmp_usbc_parse_dt_legacy()
934 qmp->pcs = devm_of_iomap(dev, np, 2, NULL); in qmp_usbc_parse_dt_legacy()
935 if (IS_ERR(qmp->pcs)) in qmp_usbc_parse_dt_legacy()
936 return PTR_ERR(qmp->pcs); in qmp_usbc_parse_dt_legacy()
938 qmp->tx2 = devm_of_iomap(dev, np, 3, NULL); in qmp_usbc_parse_dt_legacy()
939 if (IS_ERR(qmp->tx2)) in qmp_usbc_parse_dt_legacy()
940 return PTR_ERR(qmp->tx2); in qmp_usbc_parse_dt_legacy()
942 qmp->rx2 = devm_of_iomap(dev, np, 4, NULL); in qmp_usbc_parse_dt_legacy()
943 if (IS_ERR(qmp->rx2)) in qmp_usbc_parse_dt_legacy()
944 return PTR_ERR(qmp->rx2); in qmp_usbc_parse_dt_legacy()
946 qmp->pcs_misc = devm_of_iomap(dev, np, 5, NULL); in qmp_usbc_parse_dt_legacy()
947 if (IS_ERR(qmp->pcs_misc)) { in qmp_usbc_parse_dt_legacy()
948 dev_vdbg(dev, "PHY pcs_misc-reg not used\n"); in qmp_usbc_parse_dt_legacy()
949 qmp->pcs_misc = NULL; in qmp_usbc_parse_dt_legacy()
952 qmp->pipe_clk = devm_get_clk_from_child(dev, np, NULL); in qmp_usbc_parse_dt_legacy()
953 if (IS_ERR(qmp->pipe_clk)) { in qmp_usbc_parse_dt_legacy()
954 return dev_err_probe(dev, PTR_ERR(qmp->pipe_clk), in qmp_usbc_parse_dt_legacy()
958 ret = devm_clk_bulk_get_all(qmp->dev, &qmp->clks); in qmp_usbc_parse_dt_legacy()
962 qmp->num_clks = ret; in qmp_usbc_parse_dt_legacy()
974 struct platform_device *pdev = to_platform_device(qmp->dev); in qmp_usbc_parse_dt()
975 const struct qmp_phy_cfg *cfg = qmp->cfg; in qmp_usbc_parse_dt()
976 const struct qmp_usbc_offsets *offs = cfg->offsets; in qmp_usbc_parse_dt()
977 struct device *dev = qmp->dev; in qmp_usbc_parse_dt()
982 return -EINVAL; in qmp_usbc_parse_dt()
988 qmp->serdes = base + offs->serdes; in qmp_usbc_parse_dt()
989 qmp->pcs = base + offs->pcs; in qmp_usbc_parse_dt()
990 if (offs->pcs_misc) in qmp_usbc_parse_dt()
991 qmp->pcs_misc = base + offs->pcs_misc; in qmp_usbc_parse_dt()
992 qmp->tx = base + offs->tx; in qmp_usbc_parse_dt()
993 qmp->rx = base + offs->rx; in qmp_usbc_parse_dt()
995 qmp->tx2 = base + offs->tx2; in qmp_usbc_parse_dt()
996 qmp->rx2 = base + offs->rx2; in qmp_usbc_parse_dt()
1002 qmp->pipe_clk = devm_clk_get(dev, "pipe"); in qmp_usbc_parse_dt()
1003 if (IS_ERR(qmp->pipe_clk)) { in qmp_usbc_parse_dt()
1004 return dev_err_probe(dev, PTR_ERR(qmp->pipe_clk), in qmp_usbc_parse_dt()
1019 struct device *dev = qmp->dev; in qmp_usbc_parse_vls_clamp()
1023 ret = of_parse_phandle_with_fixed_args(dev->of_node, "qcom,tcsr-reg", 1, 0, in qmp_usbc_parse_vls_clamp()
1025 if (ret == -ENOENT) in qmp_usbc_parse_vls_clamp()
1028 return dev_err_probe(dev, ret, "Failed to parse qcom,tcsr-reg\n"); in qmp_usbc_parse_vls_clamp()
1030 qmp->tcsr_map = syscon_node_to_regmap(tcsr_args.np); in qmp_usbc_parse_vls_clamp()
1032 if (IS_ERR(qmp->tcsr_map)) in qmp_usbc_parse_vls_clamp()
1033 return PTR_ERR(qmp->tcsr_map); in qmp_usbc_parse_vls_clamp()
1035 qmp->vls_clamp_reg = tcsr_args.args[0]; in qmp_usbc_parse_vls_clamp()
1042 struct device *dev = &pdev->dev; in qmp_usbc_probe()
1050 return -ENOMEM; in qmp_usbc_probe()
1052 qmp->dev = dev; in qmp_usbc_probe()
1055 qmp->orientation = TYPEC_ORIENTATION_NORMAL; in qmp_usbc_probe()
1057 qmp->cfg = of_device_get_match_data(dev); in qmp_usbc_probe()
1058 if (!qmp->cfg) in qmp_usbc_probe()
1059 return -EINVAL; in qmp_usbc_probe()
1061 mutex_init(&qmp->phy_mutex); in qmp_usbc_probe()
1076 np = of_get_child_by_name(dev->of_node, "phy"); in qmp_usbc_probe()
1080 np = of_node_get(dev->of_node); in qmp_usbc_probe()
1100 qmp->phy = devm_phy_create(dev, np, &qmp_usbc_phy_ops); in qmp_usbc_probe()
1101 if (IS_ERR(qmp->phy)) { in qmp_usbc_probe()
1102 ret = PTR_ERR(qmp->phy); in qmp_usbc_probe()
1107 phy_set_drvdata(qmp->phy, qmp); in qmp_usbc_probe()
1122 .compatible = "qcom,msm8998-qmp-usb3-phy",
1125 .compatible = "qcom,qcm2290-qmp-usb3-phy",
1128 .compatible = "qcom,sdm660-qmp-usb3-phy",
1131 .compatible = "qcom,sm6115-qmp-usb3-phy",
1141 .name = "qcom-qmp-usbc-phy",
1150 MODULE_DESCRIPTION("Qualcomm QMP USB-C PHY driver");