Lines Matching +full:phy +full:- +full:qcom +full:- +full:qmp

1 // SPDX-License-Identifier: GPL-2.0
7 #include <linux/clk-provider.h>
16 #include <linux/phy/phy.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
171 * @phy: generic phy
172 * @cfg: phy specific configuration
173 * @serdes: iomapped memory space for phy's serdes (i.e. PLL)
179 * @qmp: QMP phy to which this lane belongs
183 struct phy *phy; member
191 struct qcom_qmp *qmp; member
196 * struct qcom_qmp - structure holding QMP phy block attributes
200 * @clks: array of clocks required by phy
201 * @resets: array of resets required by phy
204 * @phys: array of per-lane phy descriptors
205 * @phy_mutex: mutex lock for PHY common block initialization
206 * @init_count: phy common block initialization count
245 /* list of clocks required by phy */
252 "phy", "common", "cfg",
257 "vdda-phy", "vdda-pll",
282 struct qcom_qmp *qmp = qphy->qmp; in qmp_pcie_msm8996_serdes_init() local
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()
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() local
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()
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() local
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()
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()
392 static int qmp_pcie_msm8996_init(struct phy *phy) in qmp_pcie_msm8996_init() argument
394 struct qmp_phy *qphy = phy_get_drvdata(phy); in qmp_pcie_msm8996_init()
395 struct qcom_qmp *qmp = qphy->qmp; in qmp_pcie_msm8996_init() local
397 dev_vdbg(qmp->dev, "Initializing QMP phy\n"); in qmp_pcie_msm8996_init()
406 static int qmp_pcie_msm8996_power_on(struct phy *phy) in qmp_pcie_msm8996_power_on() argument
408 struct qmp_phy *qphy = phy_get_drvdata(phy); in qmp_pcie_msm8996_power_on()
409 struct qcom_qmp *qmp = qphy->qmp; in qmp_pcie_msm8996_power_on() local
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()
439 * Pull out PHY from POWER DOWN state. in qmp_pcie_msm8996_power_on()
440 * This is active low enable signal to power-down PHY. in qmp_pcie_msm8996_power_on()
447 /* Pull PHY out of reset state */ 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()
472 static int qmp_pcie_msm8996_power_off(struct phy *phy) in qmp_pcie_msm8996_power_off() argument
474 struct qmp_phy *qphy = phy_get_drvdata(phy); in qmp_pcie_msm8996_power_off()
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()
479 /* PHY reset */ 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()
486 /* Put PHY into POWER DOWN state: active low */ in qmp_pcie_msm8996_power_off()
487 qphy_clrbits(qphy->pcs, QPHY_V2_PCS_POWER_DOWN_CONTROL, in qmp_pcie_msm8996_power_off()
493 static int qmp_pcie_msm8996_exit(struct phy *phy) in qmp_pcie_msm8996_exit() argument
495 struct qmp_phy *qphy = phy_get_drvdata(phy); in qmp_pcie_msm8996_exit()
497 reset_control_assert(qphy->lane_rst); in qmp_pcie_msm8996_exit()
504 static int qmp_pcie_msm8996_enable(struct phy *phy) in qmp_pcie_msm8996_enable() argument
508 ret = qmp_pcie_msm8996_init(phy); in qmp_pcie_msm8996_enable()
512 ret = qmp_pcie_msm8996_power_on(phy); in qmp_pcie_msm8996_enable()
514 qmp_pcie_msm8996_exit(phy); in qmp_pcie_msm8996_enable()
519 static int qmp_pcie_msm8996_disable(struct phy *phy) in qmp_pcie_msm8996_disable() argument
523 ret = qmp_pcie_msm8996_power_off(phy); in qmp_pcie_msm8996_disable()
526 return qmp_pcie_msm8996_exit(phy); in qmp_pcie_msm8996_disable()
531 struct qcom_qmp *qmp = dev_get_drvdata(dev); in qmp_pcie_msm8996_vreg_init() local
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()
547 struct qcom_qmp *qmp = dev_get_drvdata(dev); in qmp_pcie_msm8996_reset_init() local
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()
568 struct qcom_qmp *qmp = dev_get_drvdata(dev); in qmp_pcie_msm8996_clk_init() local
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()
590 * The <s>_pipe_clksrc generated by PHY goes to the GCC that gate
592 * by the PHY driver for its operations.
597 * +---------------+
598 * | PHY block |<<---------------------------------------+
600 * | +-------+ | +-----+ |
601 * I/P---^-->| PLL |---^--->pipe_clksrc--->| GCC |--->pipe_clk---+
602 * clk | +-------+ | +-----+
603 * +---------------+
605 static int phy_pipe_clk_register(struct qcom_qmp *qmp, struct device_node *np) in phy_pipe_clk_register() argument
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()
623 /* controllers using QMP phys use 125MHz pipe clock interface */ 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()
656 struct qcom_qmp *qmp = dev_get_drvdata(dev); in qmp_pcie_msm8996_create() local
657 struct phy *generic_phy; in qmp_pcie_msm8996_create()
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()
668 * Get memory resources for each PHY: 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",
726 struct qcom_qmp *qmp; in qmp_pcie_msm8996_probe() local
727 struct device *dev = &pdev->dev; in qmp_pcie_msm8996_probe()
734 qmp = devm_kzalloc(dev, sizeof(*qmp), GFP_KERNEL); in qmp_pcie_msm8996_probe()
735 if (!qmp) in qmp_pcie_msm8996_probe()
736 return -ENOMEM; in qmp_pcie_msm8996_probe()
738 qmp->dev = dev; in qmp_pcie_msm8996_probe()
739 dev_set_drvdata(dev, qmp); in qmp_pcie_msm8996_probe()
743 return -EINVAL; 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()
779 dev_err(dev, "failed to create lane%d phy, %d\n", in qmp_pcie_msm8996_probe()
785 * Register the pipe clock provided by phy. in qmp_pcie_msm8996_probe()
788 ret = phy_pipe_clk_register(qmp, child); in qmp_pcie_msm8996_probe()
790 dev_err(qmp->dev, in qmp_pcie_msm8996_probe()
806 .name = "qcom-qmp-msm8996-pcie-phy",
814 MODULE_DESCRIPTION("Qualcomm QMP MSM8996 PCIe PHY driver");