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>
22 #include "phy-qcom-qmp-common.h"
24 #include "phy-qcom-qmp.h"
36 /* set of registers with offsets different per-PHY */
139 /* struct qmp_phy_cfg - per-PHY initialization config */
144 /* Init sequence for PHY blocks - serdes, tx, rx, pcs */
169 * struct qmp_phy - per-lane phy descriptor
173 * @serdes: iomapped memory space for phy's serdes (i.e. PLL)
185 void __iomem *serdes; member
189 struct clk *pipe_clk;
196 * struct qcom_qmp - structure holding QMP phy block attributes
204 * @phys: array of per-lane phy descriptors
257 "vdda-phy", "vdda-pll",
282 struct qcom_qmp *qmp = qphy->qmp; in qmp_pcie_msm8996_serdes_init()
283 const struct qmp_phy_cfg *cfg = qphy->cfg; in qmp_pcie_msm8996_serdes_init()
284 void __iomem *serdes = qphy->serdes; in qmp_pcie_msm8996_serdes_init() local
285 const struct qmp_phy_init_tbl *serdes_tbl = cfg->serdes_tbl; in qmp_pcie_msm8996_serdes_init()
286 int serdes_tbl_num = cfg->serdes_tbl_num; in qmp_pcie_msm8996_serdes_init()
291 qmp_configure(qmp->dev, serdes, serdes_tbl, serdes_tbl_num); in qmp_pcie_msm8996_serdes_init()
293 qphy_clrbits(serdes, cfg->regs[QPHY_COM_SW_RESET], SW_RESET); in qmp_pcie_msm8996_serdes_init()
294 qphy_setbits(serdes, cfg->regs[QPHY_COM_START_CONTROL], in qmp_pcie_msm8996_serdes_init()
297 status = serdes + cfg->regs[QPHY_COM_PCS_READY_STATUS]; in qmp_pcie_msm8996_serdes_init()
301 dev_err(qmp->dev, in qmp_pcie_msm8996_serdes_init()
302 "phy common block init timed-out\n"); in qmp_pcie_msm8996_serdes_init()
311 struct qcom_qmp *qmp = qphy->qmp; in qmp_pcie_msm8996_com_init()
312 const struct qmp_phy_cfg *cfg = qphy->cfg; in qmp_pcie_msm8996_com_init()
313 void __iomem *serdes = qphy->serdes; in qmp_pcie_msm8996_com_init() local
316 mutex_lock(&qmp->phy_mutex); in qmp_pcie_msm8996_com_init()
317 if (qmp->init_count++) { in qmp_pcie_msm8996_com_init()
318 mutex_unlock(&qmp->phy_mutex); in qmp_pcie_msm8996_com_init()
322 ret = regulator_bulk_enable(cfg->num_vregs, qmp->vregs); in qmp_pcie_msm8996_com_init()
324 dev_err(qmp->dev, "failed to enable regulators, err=%d\n", ret); in qmp_pcie_msm8996_com_init()
328 ret = reset_control_bulk_assert(cfg->num_resets, qmp->resets); in qmp_pcie_msm8996_com_init()
330 dev_err(qmp->dev, "reset assert failed\n"); in qmp_pcie_msm8996_com_init()
334 ret = reset_control_bulk_deassert(cfg->num_resets, qmp->resets); in qmp_pcie_msm8996_com_init()
336 dev_err(qmp->dev, "reset deassert failed\n"); in qmp_pcie_msm8996_com_init()
340 ret = clk_bulk_prepare_enable(cfg->num_clks, qmp->clks); in qmp_pcie_msm8996_com_init()
344 qphy_setbits(serdes, cfg->regs[QPHY_COM_POWER_DOWN_CONTROL], in qmp_pcie_msm8996_com_init()
347 mutex_unlock(&qmp->phy_mutex); in qmp_pcie_msm8996_com_init()
352 reset_control_bulk_assert(cfg->num_resets, qmp->resets); in qmp_pcie_msm8996_com_init()
354 regulator_bulk_disable(cfg->num_vregs, qmp->vregs); in qmp_pcie_msm8996_com_init()
356 qmp->init_count--; in qmp_pcie_msm8996_com_init()
357 mutex_unlock(&qmp->phy_mutex); in qmp_pcie_msm8996_com_init()
364 struct qcom_qmp *qmp = qphy->qmp; in qmp_pcie_msm8996_com_exit()
365 const struct qmp_phy_cfg *cfg = qphy->cfg; in qmp_pcie_msm8996_com_exit()
366 void __iomem *serdes = qphy->serdes; in qmp_pcie_msm8996_com_exit() local
368 mutex_lock(&qmp->phy_mutex); in qmp_pcie_msm8996_com_exit()
369 if (--qmp->init_count) { in qmp_pcie_msm8996_com_exit()
370 mutex_unlock(&qmp->phy_mutex); in qmp_pcie_msm8996_com_exit()
374 qphy_setbits(serdes, cfg->regs[QPHY_COM_START_CONTROL], in qmp_pcie_msm8996_com_exit()
376 qphy_clrbits(serdes, cfg->regs[QPHY_COM_SW_RESET], in qmp_pcie_msm8996_com_exit()
378 qphy_setbits(serdes, cfg->regs[QPHY_COM_POWER_DOWN_CONTROL], in qmp_pcie_msm8996_com_exit()
381 reset_control_bulk_assert(cfg->num_resets, qmp->resets); in qmp_pcie_msm8996_com_exit()
383 clk_bulk_disable_unprepare(cfg->num_clks, qmp->clks); in qmp_pcie_msm8996_com_exit()
385 regulator_bulk_disable(cfg->num_vregs, qmp->vregs); in qmp_pcie_msm8996_com_exit()
387 mutex_unlock(&qmp->phy_mutex); in qmp_pcie_msm8996_com_exit()
395 struct qcom_qmp *qmp = qphy->qmp; in qmp_pcie_msm8996_init()
397 dev_vdbg(qmp->dev, "Initializing QMP phy\n"); in qmp_pcie_msm8996_init()
409 struct qcom_qmp *qmp = qphy->qmp; in qmp_pcie_msm8996_power_on()
410 const struct qmp_phy_cfg *cfg = qphy->cfg; in qmp_pcie_msm8996_power_on()
411 void __iomem *tx = qphy->tx; in qmp_pcie_msm8996_power_on()
412 void __iomem *rx = qphy->rx; in qmp_pcie_msm8996_power_on()
413 void __iomem *pcs = qphy->pcs; in qmp_pcie_msm8996_power_on()
420 ret = reset_control_deassert(qphy->lane_rst); in qmp_pcie_msm8996_power_on()
422 dev_err(qmp->dev, "lane%d reset deassert failed\n", in qmp_pcie_msm8996_power_on()
423 qphy->index); in qmp_pcie_msm8996_power_on()
427 ret = clk_prepare_enable(qphy->pipe_clk); in qmp_pcie_msm8996_power_on()
429 dev_err(qmp->dev, "pipe_clk enable failed err=%d\n", ret); in qmp_pcie_msm8996_power_on()
434 qmp_configure_lane(qmp->dev, tx, cfg->tx_tbl, cfg->tx_tbl_num, 1); in qmp_pcie_msm8996_power_on()
435 qmp_configure_lane(qmp->dev, rx, cfg->rx_tbl, cfg->rx_tbl_num, 1); in qmp_pcie_msm8996_power_on()
436 qmp_configure(qmp->dev, pcs, cfg->pcs_tbl, cfg->pcs_tbl_num); in qmp_pcie_msm8996_power_on()
440 * This is active low enable signal to power-down PHY. in qmp_pcie_msm8996_power_on()
448 qphy_clrbits(pcs, cfg->regs[QPHY_SW_RESET], SW_RESET); in qmp_pcie_msm8996_power_on()
450 /* start SerDes and Phy-Coding-Sublayer */ in qmp_pcie_msm8996_power_on()
451 qphy_setbits(pcs, cfg->regs[QPHY_START_CTRL], in qmp_pcie_msm8996_power_on()
454 status = pcs + cfg->regs[QPHY_PCS_STATUS]; in qmp_pcie_msm8996_power_on()
458 dev_err(qmp->dev, "phy initialization timed-out\n"); in qmp_pcie_msm8996_power_on()
465 clk_disable_unprepare(qphy->pipe_clk); in qmp_pcie_msm8996_power_on()
467 reset_control_assert(qphy->lane_rst); in qmp_pcie_msm8996_power_on()
475 const struct qmp_phy_cfg *cfg = qphy->cfg; in qmp_pcie_msm8996_power_off()
477 clk_disable_unprepare(qphy->pipe_clk); in qmp_pcie_msm8996_power_off()
480 qphy_setbits(qphy->pcs, cfg->regs[QPHY_SW_RESET], SW_RESET); in qmp_pcie_msm8996_power_off()
482 /* stop SerDes and Phy-Coding-Sublayer */ in qmp_pcie_msm8996_power_off()
483 qphy_clrbits(qphy->pcs, cfg->regs[QPHY_START_CTRL], in qmp_pcie_msm8996_power_off()
487 qphy_clrbits(qphy->pcs, QPHY_V2_PCS_POWER_DOWN_CONTROL, in qmp_pcie_msm8996_power_off()
497 reset_control_assert(qphy->lane_rst); in qmp_pcie_msm8996_exit()
532 int num = cfg->num_vregs; in qmp_pcie_msm8996_vreg_init()
535 qmp->vregs = devm_kcalloc(dev, num, sizeof(*qmp->vregs), GFP_KERNEL); in qmp_pcie_msm8996_vreg_init()
536 if (!qmp->vregs) in qmp_pcie_msm8996_vreg_init()
537 return -ENOMEM; in qmp_pcie_msm8996_vreg_init()
540 qmp->vregs[i].supply = cfg->vreg_list[i]; in qmp_pcie_msm8996_vreg_init()
542 return devm_regulator_bulk_get(dev, num, qmp->vregs); in qmp_pcie_msm8996_vreg_init()
551 qmp->resets = devm_kcalloc(dev, cfg->num_resets, in qmp_pcie_msm8996_reset_init()
552 sizeof(*qmp->resets), GFP_KERNEL); in qmp_pcie_msm8996_reset_init()
553 if (!qmp->resets) in qmp_pcie_msm8996_reset_init()
554 return -ENOMEM; in qmp_pcie_msm8996_reset_init()
556 for (i = 0; i < cfg->num_resets; i++) in qmp_pcie_msm8996_reset_init()
557 qmp->resets[i].id = cfg->reset_list[i]; in qmp_pcie_msm8996_reset_init()
559 ret = devm_reset_control_bulk_get_exclusive(dev, cfg->num_resets, qmp->resets); in qmp_pcie_msm8996_reset_init()
569 int num = cfg->num_clks; in qmp_pcie_msm8996_clk_init()
572 qmp->clks = devm_kcalloc(dev, num, sizeof(*qmp->clks), GFP_KERNEL); in qmp_pcie_msm8996_clk_init()
573 if (!qmp->clks) in qmp_pcie_msm8996_clk_init()
574 return -ENOMEM; in qmp_pcie_msm8996_clk_init()
577 qmp->clks[i].id = cfg->clk_list[i]; in qmp_pcie_msm8996_clk_init()
579 return devm_clk_bulk_get(dev, num, qmp->clks); in qmp_pcie_msm8996_clk_init()
597 * +---------------+
598 * | PHY block |<<---------------------------------------+
600 * | +-------+ | +-----+ |
601 * I/P---^-->| PLL |---^--->pipe_clksrc--->| GCC |--->pipe_clk---+
602 * clk | +-------+ | +-----+
603 * +---------------+
611 ret = of_property_read_string(np, "clock-output-names", &init.name); in phy_pipe_clk_register()
613 dev_err(qmp->dev, "%pOFn: No clock-output-names\n", np); in phy_pipe_clk_register()
617 fixed = devm_kzalloc(qmp->dev, sizeof(*fixed), GFP_KERNEL); in phy_pipe_clk_register()
619 return -ENOMEM; in phy_pipe_clk_register()
624 fixed->fixed_rate = 125000000; in phy_pipe_clk_register()
625 fixed->hw.init = &init; in phy_pipe_clk_register()
627 ret = devm_clk_hw_register(qmp->dev, &fixed->hw); in phy_pipe_clk_register()
631 ret = of_clk_add_hw_provider(np, of_clk_hw_simple_get, &fixed->hw); in phy_pipe_clk_register()
639 return devm_add_action_or_reset(qmp->dev, phy_clk_release_provider, np); in phy_pipe_clk_register()
654 void __iomem *serdes, const struct qmp_phy_cfg *cfg) in qmp_pcie_msm8996_create() argument
663 return -ENOMEM; in qmp_pcie_msm8996_create()
665 qphy->cfg = cfg; in qmp_pcie_msm8996_create()
666 qphy->serdes = serdes; in qmp_pcie_msm8996_create()
669 * Resources are indexed as: tx -> 0; rx -> 1; pcs -> 2. in qmp_pcie_msm8996_create()
671 qphy->tx = devm_of_iomap(dev, np, 0, NULL); in qmp_pcie_msm8996_create()
672 if (IS_ERR(qphy->tx)) in qmp_pcie_msm8996_create()
673 return PTR_ERR(qphy->tx); in qmp_pcie_msm8996_create()
675 qphy->rx = devm_of_iomap(dev, np, 1, NULL); in qmp_pcie_msm8996_create()
676 if (IS_ERR(qphy->rx)) in qmp_pcie_msm8996_create()
677 return PTR_ERR(qphy->rx); in qmp_pcie_msm8996_create()
679 qphy->pcs = devm_of_iomap(dev, np, 2, NULL); in qmp_pcie_msm8996_create()
680 if (IS_ERR(qphy->pcs)) in qmp_pcie_msm8996_create()
681 return PTR_ERR(qphy->pcs); in qmp_pcie_msm8996_create()
683 qphy->pipe_clk = devm_get_clk_from_child(dev, np, NULL); in qmp_pcie_msm8996_create()
684 if (IS_ERR(qphy->pipe_clk)) { in qmp_pcie_msm8996_create()
685 return dev_err_probe(dev, PTR_ERR(qphy->pipe_clk), in qmp_pcie_msm8996_create()
689 qphy->lane_rst = of_reset_control_get_exclusive_by_index(np, 0); in qmp_pcie_msm8996_create()
690 if (IS_ERR(qphy->lane_rst)) { in qmp_pcie_msm8996_create()
692 return PTR_ERR(qphy->lane_rst); in qmp_pcie_msm8996_create()
695 qphy->lane_rst); in qmp_pcie_msm8996_create()
706 qphy->phy = generic_phy; in qmp_pcie_msm8996_create()
707 qphy->index = id; in qmp_pcie_msm8996_create()
708 qphy->qmp = qmp; in qmp_pcie_msm8996_create()
709 qmp->phys[id] = qphy; in qmp_pcie_msm8996_create()
717 .compatible = "qcom,msm8996-qmp-pcie-phy",
727 struct device *dev = &pdev->dev; in qmp_pcie_msm8996_probe()
729 void __iomem *serdes; in qmp_pcie_msm8996_probe() local
736 return -ENOMEM; in qmp_pcie_msm8996_probe()
738 qmp->dev = dev; in qmp_pcie_msm8996_probe()
743 return -EINVAL; in qmp_pcie_msm8996_probe()
745 serdes = devm_platform_ioremap_resource(pdev, 0); in qmp_pcie_msm8996_probe()
746 if (IS_ERR(serdes)) in qmp_pcie_msm8996_probe()
747 return PTR_ERR(serdes); in qmp_pcie_msm8996_probe()
749 expected_phys = cfg->num_phys; in qmp_pcie_msm8996_probe()
751 mutex_init(&qmp->phy_mutex); in qmp_pcie_msm8996_probe()
765 num = of_get_available_child_count(dev->of_node); in qmp_pcie_msm8996_probe()
768 return -EINVAL; in qmp_pcie_msm8996_probe()
770 qmp->phys = devm_kcalloc(dev, num, sizeof(*qmp->phys), GFP_KERNEL); in qmp_pcie_msm8996_probe()
771 if (!qmp->phys) in qmp_pcie_msm8996_probe()
772 return -ENOMEM; in qmp_pcie_msm8996_probe()
775 for_each_available_child_of_node_scoped(dev->of_node, child) { in qmp_pcie_msm8996_probe()
776 /* Create per-lane phy */ in qmp_pcie_msm8996_probe()
777 ret = qmp_pcie_msm8996_create(dev, child, id, serdes, cfg); in qmp_pcie_msm8996_probe()
790 dev_err(qmp->dev, in qmp_pcie_msm8996_probe()
806 .name = "qcom-qmp-msm8996-pcie-phy",