Skip to content

Commit 583ca9c

Browse files
superna9999vinodkoul
authored andcommitted
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 <[email protected]> Reviewed-by: Dmitry Baryshkov <[email protected]> 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 <[email protected]>
1 parent 677b451 commit 583ca9c

File tree

1 file changed

+75
-3
lines changed

1 file changed

+75
-3
lines changed

drivers/phy/qualcomm/phy-qcom-qmp-pcie.c

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include <linux/reset.h>
2323
#include <linux/slab.h>
2424

25+
#include <dt-bindings/phy/phy-qcom-qmp.h>
26+
2527
#include "phy-qcom-qmp-common.h"
2628

2729
#include "phy-qcom-qmp.h"
@@ -2389,6 +2391,9 @@ struct qmp_phy_cfg {
23892391

23902392
/* QMP PHY pipe clock interface rate */
23912393
unsigned long pipe_clock_rate;
2394+
2395+
/* QMP PHY AUX clock interface rate */
2396+
unsigned long aux_clock_rate;
23922397
};
23932398

23942399
struct qmp_pcie {
@@ -2420,6 +2425,7 @@ struct qmp_pcie {
24202425
int mode;
24212426

24222427
struct clk_fixed_rate pipe_clk_fixed;
2428+
struct clk_fixed_rate aux_clk_fixed;
24232429
};
24242430

24252431
static inline void qphy_setbits(void __iomem *base, u32 offset, u32 val)
@@ -3686,6 +3692,62 @@ static int phy_pipe_clk_register(struct qmp_pcie *qmp, struct device_node *np)
36863692
return devm_clk_hw_register(qmp->dev, &fixed->hw);
36873693
}
36883694

3695+
/*
3696+
* Register a fixed rate PHY aux clock.
3697+
*
3698+
* The <s>_phy_aux_clksrc generated by PHY goes to the GCC that gate
3699+
* controls it. The <s>_phy_aux_clk coming out of the GCC is requested
3700+
* by the PHY driver for its operations.
3701+
* We register the <s>_phy_aux_clksrc here. The gcc driver takes care
3702+
* of assigning this <s>_phy_aux_clksrc as parent to <s>_phy_aux_clk.
3703+
* Below picture shows this relationship.
3704+
*
3705+
* +---------------+
3706+
* | PHY block |<<---------------------------------------------+
3707+
* | | |
3708+
* | +-------+ | +-----+ |
3709+
* I/P---^-->| PLL |---^--->phy_aux_clksrc--->| GCC |--->phy_aux_clk---+
3710+
* clk | +-------+ | +-----+
3711+
* +---------------+
3712+
*/
3713+
static int phy_aux_clk_register(struct qmp_pcie *qmp, struct device_node *np)
3714+
{
3715+
struct clk_fixed_rate *fixed = &qmp->aux_clk_fixed;
3716+
struct clk_init_data init = { };
3717+
int ret;
3718+
3719+
ret = of_property_read_string_index(np, "clock-output-names", 1, &init.name);
3720+
if (ret) {
3721+
dev_err(qmp->dev, "%pOFn: No clock-output-names index 1\n", np);
3722+
return ret;
3723+
}
3724+
3725+
init.ops = &clk_fixed_rate_ops;
3726+
3727+
fixed->fixed_rate = qmp->cfg->aux_clock_rate;
3728+
fixed->hw.init = &init;
3729+
3730+
return devm_clk_hw_register(qmp->dev, &fixed->hw);
3731+
}
3732+
3733+
static struct clk_hw *qmp_pcie_clk_hw_get(struct of_phandle_args *clkspec, void *data)
3734+
{
3735+
struct qmp_pcie *qmp = data;
3736+
3737+
/* Support legacy bindings */
3738+
if (!clkspec->args_count)
3739+
return &qmp->pipe_clk_fixed.hw;
3740+
3741+
switch (clkspec->args[0]) {
3742+
case QMP_PCIE_PIPE_CLK:
3743+
return &qmp->pipe_clk_fixed.hw;
3744+
case QMP_PCIE_PHY_AUX_CLK:
3745+
return &qmp->aux_clk_fixed.hw;
3746+
}
3747+
3748+
return ERR_PTR(-EINVAL);
3749+
}
3750+
36893751
static int qmp_pcie_register_clocks(struct qmp_pcie *qmp, struct device_node *np)
36903752
{
36913753
int ret;
@@ -3694,9 +3756,19 @@ static int qmp_pcie_register_clocks(struct qmp_pcie *qmp, struct device_node *np
36943756
if (ret)
36953757
return ret;
36963758

3697-
ret = of_clk_add_hw_provider(np, of_clk_hw_simple_get, &qmp->pipe_clk_fixed.hw);
3698-
if (ret)
3699-
return ret;
3759+
if (qmp->cfg->aux_clock_rate) {
3760+
ret = phy_aux_clk_register(qmp, np);
3761+
if (ret)
3762+
return ret;
3763+
3764+
ret = of_clk_add_hw_provider(np, qmp_pcie_clk_hw_get, qmp);
3765+
if (ret)
3766+
return ret;
3767+
} else {
3768+
ret = of_clk_add_hw_provider(np, of_clk_hw_simple_get, &qmp->pipe_clk_fixed.hw);
3769+
if (ret)
3770+
return ret;
3771+
}
37003772

37013773
/*
37023774
* Roll a devm action because the clock provider is the child node, but

0 commit comments

Comments
 (0)