Lines Matching +full:tx +full:- +full:pcs
1 // SPDX-License-Identifier: GPL-2.0
7 #include <linux/clk-provider.h>
22 #include "phy-qcom-qmp.h"
66 /* set of registers with offsets different per-PHY */
73 /* PCS registers */
169 /* struct qmp_phy_cfg - per-PHY initialization config */
174 /* Init sequence for PHY blocks - serdes, tx, rx, pcs */
199 * struct qmp_phy - per-lane phy descriptor
204 * @tx: iomapped memory space for lane's tx
206 * @pcs: iomapped memory space for lane's pcs
216 void __iomem *tx; member
218 void __iomem *pcs; member
226 * struct qcom_qmp - structure holding QMP phy block attributes
234 * @phys: array of per-lane phy descriptors
287 "vdda-phy", "vdda-pll",
322 if (!(t->lane_mask & lane_mask)) in qmp_pcie_msm8996_configure_lane()
325 writel(t->val, base + t->offset); in qmp_pcie_msm8996_configure_lane()
338 struct qcom_qmp *qmp = qphy->qmp; in qmp_pcie_msm8996_serdes_init()
339 const struct qmp_phy_cfg *cfg = qphy->cfg; in qmp_pcie_msm8996_serdes_init()
340 void __iomem *serdes = qphy->serdes; in qmp_pcie_msm8996_serdes_init()
341 const struct qmp_phy_init_tbl *serdes_tbl = cfg->serdes_tbl; in qmp_pcie_msm8996_serdes_init()
342 int serdes_tbl_num = cfg->serdes_tbl_num; in qmp_pcie_msm8996_serdes_init()
349 qphy_clrbits(serdes, cfg->regs[QPHY_COM_SW_RESET], SW_RESET); in qmp_pcie_msm8996_serdes_init()
350 qphy_setbits(serdes, cfg->regs[QPHY_COM_START_CONTROL], in qmp_pcie_msm8996_serdes_init()
353 status = serdes + cfg->regs[QPHY_COM_PCS_READY_STATUS]; in qmp_pcie_msm8996_serdes_init()
357 dev_err(qmp->dev, in qmp_pcie_msm8996_serdes_init()
358 "phy common block init timed-out\n"); in qmp_pcie_msm8996_serdes_init()
367 struct qcom_qmp *qmp = qphy->qmp; in qmp_pcie_msm8996_com_init()
368 const struct qmp_phy_cfg *cfg = qphy->cfg; in qmp_pcie_msm8996_com_init()
369 void __iomem *serdes = qphy->serdes; in qmp_pcie_msm8996_com_init()
372 mutex_lock(&qmp->phy_mutex); in qmp_pcie_msm8996_com_init()
373 if (qmp->init_count++) { in qmp_pcie_msm8996_com_init()
374 mutex_unlock(&qmp->phy_mutex); in qmp_pcie_msm8996_com_init()
378 ret = regulator_bulk_enable(cfg->num_vregs, qmp->vregs); in qmp_pcie_msm8996_com_init()
380 dev_err(qmp->dev, "failed to enable regulators, err=%d\n", ret); in qmp_pcie_msm8996_com_init()
384 ret = reset_control_bulk_assert(cfg->num_resets, qmp->resets); in qmp_pcie_msm8996_com_init()
386 dev_err(qmp->dev, "reset assert failed\n"); in qmp_pcie_msm8996_com_init()
390 ret = reset_control_bulk_deassert(cfg->num_resets, qmp->resets); in qmp_pcie_msm8996_com_init()
392 dev_err(qmp->dev, "reset deassert failed\n"); in qmp_pcie_msm8996_com_init()
396 ret = clk_bulk_prepare_enable(cfg->num_clks, qmp->clks); in qmp_pcie_msm8996_com_init()
400 qphy_setbits(serdes, cfg->regs[QPHY_COM_POWER_DOWN_CONTROL], in qmp_pcie_msm8996_com_init()
403 mutex_unlock(&qmp->phy_mutex); in qmp_pcie_msm8996_com_init()
408 reset_control_bulk_assert(cfg->num_resets, qmp->resets); in qmp_pcie_msm8996_com_init()
410 regulator_bulk_disable(cfg->num_vregs, qmp->vregs); in qmp_pcie_msm8996_com_init()
412 qmp->init_count--; in qmp_pcie_msm8996_com_init()
413 mutex_unlock(&qmp->phy_mutex); in qmp_pcie_msm8996_com_init()
420 struct qcom_qmp *qmp = qphy->qmp; in qmp_pcie_msm8996_com_exit()
421 const struct qmp_phy_cfg *cfg = qphy->cfg; in qmp_pcie_msm8996_com_exit()
422 void __iomem *serdes = qphy->serdes; in qmp_pcie_msm8996_com_exit()
424 mutex_lock(&qmp->phy_mutex); in qmp_pcie_msm8996_com_exit()
425 if (--qmp->init_count) { in qmp_pcie_msm8996_com_exit()
426 mutex_unlock(&qmp->phy_mutex); in qmp_pcie_msm8996_com_exit()
430 qphy_setbits(serdes, cfg->regs[QPHY_COM_START_CONTROL], in qmp_pcie_msm8996_com_exit()
432 qphy_clrbits(serdes, cfg->regs[QPHY_COM_SW_RESET], in qmp_pcie_msm8996_com_exit()
434 qphy_setbits(serdes, cfg->regs[QPHY_COM_POWER_DOWN_CONTROL], in qmp_pcie_msm8996_com_exit()
437 reset_control_bulk_assert(cfg->num_resets, qmp->resets); in qmp_pcie_msm8996_com_exit()
439 clk_bulk_disable_unprepare(cfg->num_clks, qmp->clks); in qmp_pcie_msm8996_com_exit()
441 regulator_bulk_disable(cfg->num_vregs, qmp->vregs); in qmp_pcie_msm8996_com_exit()
443 mutex_unlock(&qmp->phy_mutex); in qmp_pcie_msm8996_com_exit()
451 struct qcom_qmp *qmp = qphy->qmp; in qmp_pcie_msm8996_init()
453 dev_vdbg(qmp->dev, "Initializing QMP phy\n"); in qmp_pcie_msm8996_init()
465 struct qcom_qmp *qmp = qphy->qmp; in qmp_pcie_msm8996_power_on()
466 const struct qmp_phy_cfg *cfg = qphy->cfg; in qmp_pcie_msm8996_power_on()
467 void __iomem *tx = qphy->tx; in qmp_pcie_msm8996_power_on() local
468 void __iomem *rx = qphy->rx; in qmp_pcie_msm8996_power_on()
469 void __iomem *pcs = qphy->pcs; in qmp_pcie_msm8996_power_on() local
476 ret = reset_control_deassert(qphy->lane_rst); in qmp_pcie_msm8996_power_on()
478 dev_err(qmp->dev, "lane%d reset deassert failed\n", in qmp_pcie_msm8996_power_on()
479 qphy->index); in qmp_pcie_msm8996_power_on()
483 ret = clk_prepare_enable(qphy->pipe_clk); in qmp_pcie_msm8996_power_on()
485 dev_err(qmp->dev, "pipe_clk enable failed err=%d\n", ret); in qmp_pcie_msm8996_power_on()
489 /* Tx, Rx, and PCS configurations */ in qmp_pcie_msm8996_power_on()
490 qmp_pcie_msm8996_configure_lane(tx, cfg->tx_tbl, cfg->tx_tbl_num, 1); in qmp_pcie_msm8996_power_on()
491 qmp_pcie_msm8996_configure_lane(rx, cfg->rx_tbl, cfg->rx_tbl_num, 1); in qmp_pcie_msm8996_power_on()
492 qmp_pcie_msm8996_configure(pcs, cfg->pcs_tbl, cfg->pcs_tbl_num); in qmp_pcie_msm8996_power_on()
496 * This is active low enable signal to power-down PHY. in qmp_pcie_msm8996_power_on()
498 qphy_setbits(pcs, QPHY_V2_PCS_POWER_DOWN_CONTROL, in qmp_pcie_msm8996_power_on()
504 qphy_clrbits(pcs, cfg->regs[QPHY_SW_RESET], SW_RESET); in qmp_pcie_msm8996_power_on()
506 /* start SerDes and Phy-Coding-Sublayer */ in qmp_pcie_msm8996_power_on()
507 qphy_setbits(pcs, cfg->regs[QPHY_START_CTRL], in qmp_pcie_msm8996_power_on()
510 status = pcs + cfg->regs[QPHY_PCS_STATUS]; in qmp_pcie_msm8996_power_on()
514 dev_err(qmp->dev, "phy initialization timed-out\n"); in qmp_pcie_msm8996_power_on()
521 clk_disable_unprepare(qphy->pipe_clk); in qmp_pcie_msm8996_power_on()
523 reset_control_assert(qphy->lane_rst); in qmp_pcie_msm8996_power_on()
531 const struct qmp_phy_cfg *cfg = qphy->cfg; in qmp_pcie_msm8996_power_off()
533 clk_disable_unprepare(qphy->pipe_clk); in qmp_pcie_msm8996_power_off()
536 qphy_setbits(qphy->pcs, cfg->regs[QPHY_SW_RESET], SW_RESET); in qmp_pcie_msm8996_power_off()
538 /* stop SerDes and Phy-Coding-Sublayer */ in qmp_pcie_msm8996_power_off()
539 qphy_clrbits(qphy->pcs, cfg->regs[QPHY_START_CTRL], in qmp_pcie_msm8996_power_off()
543 qphy_clrbits(qphy->pcs, QPHY_V2_PCS_POWER_DOWN_CONTROL, in qmp_pcie_msm8996_power_off()
553 reset_control_assert(qphy->lane_rst); in qmp_pcie_msm8996_exit()
588 int num = cfg->num_vregs; in qmp_pcie_msm8996_vreg_init()
591 qmp->vregs = devm_kcalloc(dev, num, sizeof(*qmp->vregs), GFP_KERNEL); in qmp_pcie_msm8996_vreg_init()
592 if (!qmp->vregs) in qmp_pcie_msm8996_vreg_init()
593 return -ENOMEM; in qmp_pcie_msm8996_vreg_init()
596 qmp->vregs[i].supply = cfg->vreg_list[i]; in qmp_pcie_msm8996_vreg_init()
598 return devm_regulator_bulk_get(dev, num, qmp->vregs); in qmp_pcie_msm8996_vreg_init()
607 qmp->resets = devm_kcalloc(dev, cfg->num_resets, in qmp_pcie_msm8996_reset_init()
608 sizeof(*qmp->resets), GFP_KERNEL); in qmp_pcie_msm8996_reset_init()
609 if (!qmp->resets) in qmp_pcie_msm8996_reset_init()
610 return -ENOMEM; in qmp_pcie_msm8996_reset_init()
612 for (i = 0; i < cfg->num_resets; i++) in qmp_pcie_msm8996_reset_init()
613 qmp->resets[i].id = cfg->reset_list[i]; in qmp_pcie_msm8996_reset_init()
615 ret = devm_reset_control_bulk_get_exclusive(dev, cfg->num_resets, qmp->resets); in qmp_pcie_msm8996_reset_init()
625 int num = cfg->num_clks; in qmp_pcie_msm8996_clk_init()
628 qmp->clks = devm_kcalloc(dev, num, sizeof(*qmp->clks), GFP_KERNEL); in qmp_pcie_msm8996_clk_init()
629 if (!qmp->clks) in qmp_pcie_msm8996_clk_init()
630 return -ENOMEM; in qmp_pcie_msm8996_clk_init()
633 qmp->clks[i].id = cfg->clk_list[i]; in qmp_pcie_msm8996_clk_init()
635 return devm_clk_bulk_get(dev, num, qmp->clks); in qmp_pcie_msm8996_clk_init()
653 * +---------------+
654 * | PHY block |<<---------------------------------------+
656 * | +-------+ | +-----+ |
657 * I/P---^-->| PLL |---^--->pipe_clksrc--->| GCC |--->pipe_clk---+
658 * clk | +-------+ | +-----+
659 * +---------------+
667 ret = of_property_read_string(np, "clock-output-names", &init.name); in phy_pipe_clk_register()
669 dev_err(qmp->dev, "%pOFn: No clock-output-names\n", np); in phy_pipe_clk_register()
673 fixed = devm_kzalloc(qmp->dev, sizeof(*fixed), GFP_KERNEL); in phy_pipe_clk_register()
675 return -ENOMEM; in phy_pipe_clk_register()
680 fixed->fixed_rate = 125000000; in phy_pipe_clk_register()
681 fixed->hw.init = &init; in phy_pipe_clk_register()
683 ret = devm_clk_hw_register(qmp->dev, &fixed->hw); in phy_pipe_clk_register()
687 ret = of_clk_add_hw_provider(np, of_clk_hw_simple_get, &fixed->hw); in phy_pipe_clk_register()
695 return devm_add_action_or_reset(qmp->dev, phy_clk_release_provider, np); in phy_pipe_clk_register()
719 return -ENOMEM; in qmp_pcie_msm8996_create()
721 qphy->cfg = cfg; in qmp_pcie_msm8996_create()
722 qphy->serdes = serdes; in qmp_pcie_msm8996_create()
725 * Resources are indexed as: tx -> 0; rx -> 1; pcs -> 2. in qmp_pcie_msm8996_create()
727 qphy->tx = devm_of_iomap(dev, np, 0, NULL); in qmp_pcie_msm8996_create()
728 if (IS_ERR(qphy->tx)) in qmp_pcie_msm8996_create()
729 return PTR_ERR(qphy->tx); in qmp_pcie_msm8996_create()
731 qphy->rx = devm_of_iomap(dev, np, 1, NULL); in qmp_pcie_msm8996_create()
732 if (IS_ERR(qphy->rx)) in qmp_pcie_msm8996_create()
733 return PTR_ERR(qphy->rx); in qmp_pcie_msm8996_create()
735 qphy->pcs = devm_of_iomap(dev, np, 2, NULL); in qmp_pcie_msm8996_create()
736 if (IS_ERR(qphy->pcs)) in qmp_pcie_msm8996_create()
737 return PTR_ERR(qphy->pcs); in qmp_pcie_msm8996_create()
739 qphy->pipe_clk = devm_get_clk_from_child(dev, np, NULL); in qmp_pcie_msm8996_create()
740 if (IS_ERR(qphy->pipe_clk)) { in qmp_pcie_msm8996_create()
741 return dev_err_probe(dev, PTR_ERR(qphy->pipe_clk), in qmp_pcie_msm8996_create()
745 qphy->lane_rst = of_reset_control_get_exclusive_by_index(np, 0); in qmp_pcie_msm8996_create()
746 if (IS_ERR(qphy->lane_rst)) { in qmp_pcie_msm8996_create()
748 return PTR_ERR(qphy->lane_rst); in qmp_pcie_msm8996_create()
751 qphy->lane_rst); in qmp_pcie_msm8996_create()
762 qphy->phy = generic_phy; in qmp_pcie_msm8996_create()
763 qphy->index = id; in qmp_pcie_msm8996_create()
764 qphy->qmp = qmp; in qmp_pcie_msm8996_create()
765 qmp->phys[id] = qphy; in qmp_pcie_msm8996_create()
773 .compatible = "qcom,msm8996-qmp-pcie-phy",
783 struct device *dev = &pdev->dev; in qmp_pcie_msm8996_probe()
793 return -ENOMEM; in qmp_pcie_msm8996_probe()
795 qmp->dev = dev; in qmp_pcie_msm8996_probe()
800 return -EINVAL; in qmp_pcie_msm8996_probe()
806 expected_phys = cfg->num_phys; in qmp_pcie_msm8996_probe()
808 mutex_init(&qmp->phy_mutex); in qmp_pcie_msm8996_probe()
822 num = of_get_available_child_count(dev->of_node); in qmp_pcie_msm8996_probe()
825 return -EINVAL; in qmp_pcie_msm8996_probe()
827 qmp->phys = devm_kcalloc(dev, num, sizeof(*qmp->phys), GFP_KERNEL); in qmp_pcie_msm8996_probe()
828 if (!qmp->phys) in qmp_pcie_msm8996_probe()
829 return -ENOMEM; in qmp_pcie_msm8996_probe()
832 for_each_available_child_of_node(dev->of_node, child) { in qmp_pcie_msm8996_probe()
833 /* Create per-lane phy */ in qmp_pcie_msm8996_probe()
847 dev_err(qmp->dev, in qmp_pcie_msm8996_probe()
867 .name = "qcom-qmp-msm8996-pcie-phy",