Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

phy: qcom: qmp-pcie: register second optional PHY AUX clock

The PCIe Gen4x2 PHY found in the SM8[456]50 SoCs have a second clock,
add the code to register it for PHYs configs that sets a aux_clock_rate.

In order to get the right clock, add qmp_pcie_clk_hw_get() which uses
the newly introduced QMP_PCIE_PIPE_CLK & QMP_PCIE_PHY_AUX_CLK clock
IDs and also supports the legacy bindings by returning the PIPE clock
when #clock-cells=0.

Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Link: https://lore.kernel.org/r/20240322-topic-sm8x50-upstream-pcie-1-phy-aux-clk-v2-3-3ec0a966d52f@linaro.org
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by

Neil Armstrong and committed by
Vinod Koul
583ca9cc 677b4511

+75 -3
+75 -3
drivers/phy/qualcomm/phy-qcom-qmp-pcie.c
··· 22 22 #include <linux/reset.h> 23 23 #include <linux/slab.h> 24 24 25 + #include <dt-bindings/phy/phy-qcom-qmp.h> 26 + 25 27 #include "phy-qcom-qmp-common.h" 26 28 27 29 #include "phy-qcom-qmp.h" ··· 2391 2389 2392 2390 /* QMP PHY pipe clock interface rate */ 2393 2391 unsigned long pipe_clock_rate; 2392 + 2393 + /* QMP PHY AUX clock interface rate */ 2394 + unsigned long aux_clock_rate; 2394 2395 }; 2395 2396 2396 2397 struct qmp_pcie { ··· 2425 2420 int mode; 2426 2421 2427 2422 struct clk_fixed_rate pipe_clk_fixed; 2423 + struct clk_fixed_rate aux_clk_fixed; 2428 2424 }; 2429 2425 2430 2426 static inline void qphy_setbits(void __iomem *base, u32 offset, u32 val) ··· 3692 3686 return devm_clk_hw_register(qmp->dev, &fixed->hw); 3693 3687 } 3694 3688 3689 + /* 3690 + * Register a fixed rate PHY aux clock. 3691 + * 3692 + * The <s>_phy_aux_clksrc generated by PHY goes to the GCC that gate 3693 + * controls it. The <s>_phy_aux_clk coming out of the GCC is requested 3694 + * by the PHY driver for its operations. 3695 + * We register the <s>_phy_aux_clksrc here. The gcc driver takes care 3696 + * of assigning this <s>_phy_aux_clksrc as parent to <s>_phy_aux_clk. 3697 + * Below picture shows this relationship. 3698 + * 3699 + * +---------------+ 3700 + * | PHY block |<<---------------------------------------------+ 3701 + * | | | 3702 + * | +-------+ | +-----+ | 3703 + * I/P---^-->| PLL |---^--->phy_aux_clksrc--->| GCC |--->phy_aux_clk---+ 3704 + * clk | +-------+ | +-----+ 3705 + * +---------------+ 3706 + */ 3707 + static int phy_aux_clk_register(struct qmp_pcie *qmp, struct device_node *np) 3708 + { 3709 + struct clk_fixed_rate *fixed = &qmp->aux_clk_fixed; 3710 + struct clk_init_data init = { }; 3711 + int ret; 3712 + 3713 + ret = of_property_read_string_index(np, "clock-output-names", 1, &init.name); 3714 + if (ret) { 3715 + dev_err(qmp->dev, "%pOFn: No clock-output-names index 1\n", np); 3716 + return ret; 3717 + } 3718 + 3719 + init.ops = &clk_fixed_rate_ops; 3720 + 3721 + fixed->fixed_rate = qmp->cfg->aux_clock_rate; 3722 + fixed->hw.init = &init; 3723 + 3724 + return devm_clk_hw_register(qmp->dev, &fixed->hw); 3725 + } 3726 + 3727 + static struct clk_hw *qmp_pcie_clk_hw_get(struct of_phandle_args *clkspec, void *data) 3728 + { 3729 + struct qmp_pcie *qmp = data; 3730 + 3731 + /* Support legacy bindings */ 3732 + if (!clkspec->args_count) 3733 + return &qmp->pipe_clk_fixed.hw; 3734 + 3735 + switch (clkspec->args[0]) { 3736 + case QMP_PCIE_PIPE_CLK: 3737 + return &qmp->pipe_clk_fixed.hw; 3738 + case QMP_PCIE_PHY_AUX_CLK: 3739 + return &qmp->aux_clk_fixed.hw; 3740 + } 3741 + 3742 + return ERR_PTR(-EINVAL); 3743 + } 3744 + 3695 3745 static int qmp_pcie_register_clocks(struct qmp_pcie *qmp, struct device_node *np) 3696 3746 { 3697 3747 int ret; ··· 3756 3694 if (ret) 3757 3695 return ret; 3758 3696 3759 - ret = of_clk_add_hw_provider(np, of_clk_hw_simple_get, &qmp->pipe_clk_fixed.hw); 3760 - if (ret) 3761 - return ret; 3697 + if (qmp->cfg->aux_clock_rate) { 3698 + ret = phy_aux_clk_register(qmp, np); 3699 + if (ret) 3700 + return ret; 3701 + 3702 + ret = of_clk_add_hw_provider(np, qmp_pcie_clk_hw_get, qmp); 3703 + if (ret) 3704 + return ret; 3705 + } else { 3706 + ret = of_clk_add_hw_provider(np, of_clk_hw_simple_get, &qmp->pipe_clk_fixed.hw); 3707 + if (ret) 3708 + return ret; 3709 + } 3762 3710 3763 3711 /* 3764 3712 * Roll a devm action because the clock provider is the child node, but