[PATCH v3 06/11] clk: tegra: remove EMC to MC clock mux in Tegra114

Svyatoslav Ryhel posted 11 patches 4 months, 3 weeks ago
There is a newer version of this series
[PATCH v3 06/11] clk: tegra: remove EMC to MC clock mux in Tegra114
Posted by Svyatoslav Ryhel 4 months, 3 weeks ago
Configure EMC without mux for correct EMC driver support.

Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
---
 drivers/clk/tegra/clk-tegra114.c | 48 ++++++++++++++++++++++----------
 1 file changed, 33 insertions(+), 15 deletions(-)

diff --git a/drivers/clk/tegra/clk-tegra114.c b/drivers/clk/tegra/clk-tegra114.c
index 8bde72aa5e68..6b3a140772c2 100644
--- a/drivers/clk/tegra/clk-tegra114.c
+++ b/drivers/clk/tegra/clk-tegra114.c
@@ -622,10 +622,6 @@ static const char *mux_plld_out0_plld2_out0[] = {
 };
 #define mux_plld_out0_plld2_out0_idx NULL
 
-static const char *mux_pllmcp_clkm[] = {
-	"pll_m_out0", "pll_c_out0", "pll_p_out0", "clk_m", "pll_m_ud",
-};
-
 static const struct clk_div_table pll_re_div_table[] = {
 	{ .val = 0, .div = 1 },
 	{ .val = 1, .div = 2 },
@@ -672,7 +668,6 @@ static struct tegra_clk tegra114_clks[tegra_clk_max] __initdata = {
 	[tegra_clk_csi] = { .dt_id = TEGRA114_CLK_CSI, .present = true },
 	[tegra_clk_i2c2] = { .dt_id = TEGRA114_CLK_I2C2, .present = true },
 	[tegra_clk_uartc] = { .dt_id = TEGRA114_CLK_UARTC, .present = true },
-	[tegra_clk_emc] = { .dt_id = TEGRA114_CLK_EMC, .present = true },
 	[tegra_clk_usb2] = { .dt_id = TEGRA114_CLK_USB2, .present = true },
 	[tegra_clk_usb3] = { .dt_id = TEGRA114_CLK_USB3, .present = true },
 	[tegra_clk_vde_8] = { .dt_id = TEGRA114_CLK_VDE, .present = true },
@@ -1048,14 +1043,7 @@ static __init void tegra114_periph_clk_init(void __iomem *clk_base,
 					     0, 82, periph_clk_enb_refcnt);
 	clks[TEGRA114_CLK_DSIB] = clk;
 
-	/* emc mux */
-	clk = clk_register_mux(NULL, "emc_mux", mux_pllmcp_clkm,
-			       ARRAY_SIZE(mux_pllmcp_clkm),
-			       CLK_SET_RATE_NO_REPARENT,
-			       clk_base + CLK_SOURCE_EMC,
-			       29, 3, 0, &emc_lock);
-
-	clk = tegra_clk_register_mc("mc", "emc_mux", clk_base + CLK_SOURCE_EMC,
+	clk = tegra_clk_register_mc("mc", "emc", clk_base + CLK_SOURCE_EMC,
 				    &emc_lock);
 	clks[TEGRA114_CLK_MC] = clk;
 
@@ -1321,6 +1309,28 @@ static int tegra114_reset_deassert(unsigned long id)
 	return 0;
 }
 
+#ifdef CONFIG_TEGRA124_CLK_EMC
+static struct clk *tegra114_clk_src_onecell_get(struct of_phandle_args *clkspec,
+						void *data)
+{
+	struct clk_hw *hw;
+	struct clk *clk;
+
+	clk = of_clk_src_onecell_get(clkspec, data);
+	if (IS_ERR(clk))
+		return clk;
+
+	hw = __clk_get_hw(clk);
+
+	if (clkspec->args[0] == TEGRA114_CLK_EMC) {
+		if (!tegra124_clk_emc_driver_available(hw))
+			return ERR_PTR(-EPROBE_DEFER);
+	}
+
+	return clk;
+}
+#endif
+
 static void __init tegra114_clock_init(struct device_node *np)
 {
 	struct device_node *node;
@@ -1362,16 +1372,24 @@ static void __init tegra114_clock_init(struct device_node *np)
 	tegra_audio_clk_init(clk_base, pmc_base, tegra114_clks,
 			     tegra114_audio_plls,
 			     ARRAY_SIZE(tegra114_audio_plls), 24000000);
+
+	tegra_clk_apply_init_table = tegra114_clock_apply_init_table;
+
 	tegra_super_clk_gen4_init(clk_base, pmc_base, tegra114_clks,
 					&pll_x_params);
 
 	tegra_init_special_resets(1, tegra114_reset_assert,
 				  tegra114_reset_deassert);
 
+#ifdef CONFIG_TEGRA124_CLK_EMC
+	tegra_add_of_provider(np, tegra114_clk_src_onecell_get);
+	clks[TEGRA114_CLK_EMC] = tegra124_clk_register_emc(clk_base, np,
+							   &emc_lock);
+#else
 	tegra_add_of_provider(np, of_clk_src_onecell_get);
-	tegra_register_devclks(devclks, ARRAY_SIZE(devclks));
+#endif
 
-	tegra_clk_apply_init_table = tegra114_clock_apply_init_table;
+	tegra_register_devclks(devclks, ARRAY_SIZE(devclks));
 
 	tegra_cpu_car_ops = &tegra114_cpu_car_ops;
 }
-- 
2.48.1
Re: [PATCH v3 06/11] clk: tegra: remove EMC to MC clock mux in Tegra114
Posted by Stephen Boyd 4 months, 2 weeks ago
Quoting Svyatoslav Ryhel (2025-09-15 01:01:52)
> diff --git a/drivers/clk/tegra/clk-tegra114.c b/drivers/clk/tegra/clk-tegra114.c
> index 8bde72aa5e68..6b3a140772c2 100644
> --- a/drivers/clk/tegra/clk-tegra114.c
> +++ b/drivers/clk/tegra/clk-tegra114.c
> @@ -1321,6 +1309,28 @@ static int tegra114_reset_deassert(unsigned long id)
>         return 0;
>  }
>  
> +#ifdef CONFIG_TEGRA124_CLK_EMC
> +static struct clk *tegra114_clk_src_onecell_get(struct of_phandle_args *clkspec,
> +                                               void *data)
> +{
> +       struct clk_hw *hw;
> +       struct clk *clk;
> +
> +       clk = of_clk_src_onecell_get(clkspec, data);
> +       if (IS_ERR(clk))
> +               return clk;
> +
> +       hw = __clk_get_hw(clk);

Can you just use of_clk_hw_onecell_get() instead? Then we don't need to
use __clk_get_hw(). Or is this whole function used to return a clk
pointer to something that isn't the clk framework?

> +
> +       if (clkspec->args[0] == TEGRA114_CLK_EMC) {
> +               if (!tegra124_clk_emc_driver_available(hw))
> +                       return ERR_PTR(-EPROBE_DEFER);
> +       }
> +
> +       return clk;
Re: [PATCH v3 06/11] clk: tegra: remove EMC to MC clock mux in Tegra114
Posted by Svyatoslav Ryhel 2 months, 2 weeks ago
нд, 21 вер. 2025 р. о 20:54 Stephen Boyd <sboyd@kernel.org> пише:
>
> Quoting Svyatoslav Ryhel (2025-09-15 01:01:52)
> > diff --git a/drivers/clk/tegra/clk-tegra114.c b/drivers/clk/tegra/clk-tegra114.c
> > index 8bde72aa5e68..6b3a140772c2 100644
> > --- a/drivers/clk/tegra/clk-tegra114.c
> > +++ b/drivers/clk/tegra/clk-tegra114.c
> > @@ -1321,6 +1309,28 @@ static int tegra114_reset_deassert(unsigned long id)
> >         return 0;
> >  }
> >
> > +#ifdef CONFIG_TEGRA124_CLK_EMC
> > +static struct clk *tegra114_clk_src_onecell_get(struct of_phandle_args *clkspec,
> > +                                               void *data)
> > +{
> > +       struct clk_hw *hw;
> > +       struct clk *clk;
> > +
> > +       clk = of_clk_src_onecell_get(clkspec, data);
> > +       if (IS_ERR(clk))
> > +               return clk;
> > +
> > +       hw = __clk_get_hw(clk);
>
> Can you just use of_clk_hw_onecell_get() instead? Then we don't need to
> use __clk_get_hw(). Or is this whole function used to return a clk
> pointer to something that isn't the clk framework?
>

I have tried to switch __clk_get_hw to of_clk_hw_onecell_get but it
did not work, tegra124_clk_emc_driver_available fails and I get
EPROBE_DEFER cascade. I will keep __clk_get_hw like Tegra124 driver
does since of_clk_hw_onecell_get did not worked in this case.

> > +
> > +       if (clkspec->args[0] == TEGRA114_CLK_EMC) {
> > +               if (!tegra124_clk_emc_driver_available(hw))
> > +                       return ERR_PTR(-EPROBE_DEFER);
> > +       }
> > +
> > +       return clk;
Re: [PATCH v3 06/11] clk: tegra: remove EMC to MC clock mux in Tegra114
Posted by Svyatoslav Ryhel 2 months, 3 weeks ago
нд, 21 вер. 2025 р. о 20:54 Stephen Boyd <sboyd@kernel.org> пише:
>
> Quoting Svyatoslav Ryhel (2025-09-15 01:01:52)
> > diff --git a/drivers/clk/tegra/clk-tegra114.c b/drivers/clk/tegra/clk-tegra114.c
> > index 8bde72aa5e68..6b3a140772c2 100644
> > --- a/drivers/clk/tegra/clk-tegra114.c
> > +++ b/drivers/clk/tegra/clk-tegra114.c
> > @@ -1321,6 +1309,28 @@ static int tegra114_reset_deassert(unsigned long id)
> >         return 0;
> >  }
> >
> > +#ifdef CONFIG_TEGRA124_CLK_EMC
> > +static struct clk *tegra114_clk_src_onecell_get(struct of_phandle_args *clkspec,
> > +                                               void *data)
> > +{
> > +       struct clk_hw *hw;
> > +       struct clk *clk;
> > +
> > +       clk = of_clk_src_onecell_get(clkspec, data);
> > +       if (IS_ERR(clk))
> > +               return clk;
> > +
> > +       hw = __clk_get_hw(clk);
>
> Can you just use of_clk_hw_onecell_get() instead? Then we don't need to
> use __clk_get_hw(). Or is this whole function used to return a clk
> pointer to something that isn't the clk framework?
>

This logic was adopted from Tegra124 driver, but of_clk_hw_onecell_get
might be applicable. I will adjust to use it and if all works as
expected, I will apply it in v4. Thank you.

> > +
> > +       if (clkspec->args[0] == TEGRA114_CLK_EMC) {
> > +               if (!tegra124_clk_emc_driver_available(hw))
> > +                       return ERR_PTR(-EPROBE_DEFER);
> > +       }
> > +
> > +       return clk;
Re: [PATCH v3 06/11] clk: tegra: remove EMC to MC clock mux in Tegra114
Posted by Mikko Perttunen 2 months, 4 weeks ago
On Monday, September 15, 2025 5:01 PM Svyatoslav Ryhel wrote:
> Configure EMC without mux for correct EMC driver support.

Rather than just 'removing EMC to MC clock mux in Tegra114', I would say this patch removes current emc and emc_mux clocks and replaces them with the proper EMC clock implementation. I would edit the commit subject and commit message along those lines.

> 
> Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
> ---
>  drivers/clk/tegra/clk-tegra114.c | 48 ++++++++++++++++++++++----------
>  1 file changed, 33 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/clk/tegra/clk-tegra114.c b/drivers/clk/tegra/clk-tegra114.c
> index 8bde72aa5e68..6b3a140772c2 100644
> --- a/drivers/clk/tegra/clk-tegra114.c
> +++ b/drivers/clk/tegra/clk-tegra114.c
> @@ -622,10 +622,6 @@ static const char *mux_plld_out0_plld2_out0[] = {
>  };
>  #define mux_plld_out0_plld2_out0_idx NULL
>  
> -static const char *mux_pllmcp_clkm[] = {
> -	"pll_m_out0", "pll_c_out0", "pll_p_out0", "clk_m", "pll_m_ud",
> -};
> -
>  static const struct clk_div_table pll_re_div_table[] = {
>  	{ .val = 0, .div = 1 },
>  	{ .val = 1, .div = 2 },
> @@ -672,7 +668,6 @@ static struct tegra_clk tegra114_clks[tegra_clk_max] __initdata = {
>  	[tegra_clk_csi] = { .dt_id = TEGRA114_CLK_CSI, .present = true },
>  	[tegra_clk_i2c2] = { .dt_id = TEGRA114_CLK_I2C2, .present = true },
>  	[tegra_clk_uartc] = { .dt_id = TEGRA114_CLK_UARTC, .present = true },
> -	[tegra_clk_emc] = { .dt_id = TEGRA114_CLK_EMC, .present = true },
>  	[tegra_clk_usb2] = { .dt_id = TEGRA114_CLK_USB2, .present = true },
>  	[tegra_clk_usb3] = { .dt_id = TEGRA114_CLK_USB3, .present = true },
>  	[tegra_clk_vde_8] = { .dt_id = TEGRA114_CLK_VDE, .present = true },
> @@ -1048,14 +1043,7 @@ static __init void tegra114_periph_clk_init(void __iomem *clk_base,
>  					     0, 82, periph_clk_enb_refcnt);
>  	clks[TEGRA114_CLK_DSIB] = clk;
>  
> -	/* emc mux */
> -	clk = clk_register_mux(NULL, "emc_mux", mux_pllmcp_clkm,
> -			       ARRAY_SIZE(mux_pllmcp_clkm),
> -			       CLK_SET_RATE_NO_REPARENT,
> -			       clk_base + CLK_SOURCE_EMC,
> -			       29, 3, 0, &emc_lock);
> -
> -	clk = tegra_clk_register_mc("mc", "emc_mux", clk_base + CLK_SOURCE_EMC,
> +	clk = tegra_clk_register_mc("mc", "emc", clk_base + CLK_SOURCE_EMC,
>  				    &emc_lock);
>  	clks[TEGRA114_CLK_MC] = clk;
>  
> @@ -1321,6 +1309,28 @@ static int tegra114_reset_deassert(unsigned long id)
>  	return 0;
>  }
>  
> +#ifdef CONFIG_TEGRA124_CLK_EMC
> +static struct clk *tegra114_clk_src_onecell_get(struct of_phandle_args *clkspec,
> +						void *data)
> +{
> +	struct clk_hw *hw;
> +	struct clk *clk;
> +
> +	clk = of_clk_src_onecell_get(clkspec, data);
> +	if (IS_ERR(clk))
> +		return clk;
> +
> +	hw = __clk_get_hw(clk);
> +
> +	if (clkspec->args[0] == TEGRA114_CLK_EMC) {
> +		if (!tegra124_clk_emc_driver_available(hw))
> +			return ERR_PTR(-EPROBE_DEFER);
> +	}
> +
> +	return clk;
> +}
> +#endif
> +
>  static void __init tegra114_clock_init(struct device_node *np)
>  {
>  	struct device_node *node;
> @@ -1362,16 +1372,24 @@ static void __init tegra114_clock_init(struct device_node *np)
>  	tegra_audio_clk_init(clk_base, pmc_base, tegra114_clks,
>  			     tegra114_audio_plls,
>  			     ARRAY_SIZE(tegra114_audio_plls), 24000000);
> +
> +	tegra_clk_apply_init_table = tegra114_clock_apply_init_table;
> +

Is there any particular reason for moving this here? If not, omitting the change would simplify the patch a bit.

>  	tegra_super_clk_gen4_init(clk_base, pmc_base, tegra114_clks,
>  					&pll_x_params);
>  
>  	tegra_init_special_resets(1, tegra114_reset_assert,
>  				  tegra114_reset_deassert);
>  
> +#ifdef CONFIG_TEGRA124_CLK_EMC
> +	tegra_add_of_provider(np, tegra114_clk_src_onecell_get);
> +	clks[TEGRA114_CLK_EMC] = tegra124_clk_register_emc(clk_base, np,
> +							   &emc_lock);
> +#else
>  	tegra_add_of_provider(np, of_clk_src_onecell_get);
> -	tegra_register_devclks(devclks, ARRAY_SIZE(devclks));
> +#endif

tegra124_clk_register_emc and tegra124_clk_emc_driver_available have stub implementations when CONFIG_TEGRA124_CLK_EMC is not enabled, so it would be cleaner to just call them always.

>  
> -	tegra_clk_apply_init_table = tegra114_clock_apply_init_table;
> +	tegra_register_devclks(devclks, ARRAY_SIZE(devclks));
>  
>  	tegra_cpu_car_ops = &tegra114_cpu_car_ops;
>  }
> 
Re: [PATCH v3 06/11] clk: tegra: remove EMC to MC clock mux in Tegra114
Posted by Svyatoslav Ryhel 2 months, 3 weeks ago
чт, 13 лист. 2025 р. о 07:05 Mikko Perttunen <mperttunen@nvidia.com> пише:
>
> On Monday, September 15, 2025 5:01 PM Svyatoslav Ryhel wrote:
> > Configure EMC without mux for correct EMC driver support.
>
> Rather than just 'removing EMC to MC clock mux in Tegra114', I would say this patch removes current emc and emc_mux clocks and replaces them with the proper EMC clock implementation. I would edit the commit subject and commit message along those lines.
>

Noted

> >
> > Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
> > ---
> >  drivers/clk/tegra/clk-tegra114.c | 48 ++++++++++++++++++++++----------
> >  1 file changed, 33 insertions(+), 15 deletions(-)
> >
> > diff --git a/drivers/clk/tegra/clk-tegra114.c b/drivers/clk/tegra/clk-tegra114.c
> > index 8bde72aa5e68..6b3a140772c2 100644
> > --- a/drivers/clk/tegra/clk-tegra114.c
> > +++ b/drivers/clk/tegra/clk-tegra114.c
> > @@ -622,10 +622,6 @@ static const char *mux_plld_out0_plld2_out0[] = {
> >  };
> >  #define mux_plld_out0_plld2_out0_idx NULL
> >
> > -static const char *mux_pllmcp_clkm[] = {
> > -     "pll_m_out0", "pll_c_out0", "pll_p_out0", "clk_m", "pll_m_ud",
> > -};
> > -
> >  static const struct clk_div_table pll_re_div_table[] = {
> >       { .val = 0, .div = 1 },
> >       { .val = 1, .div = 2 },
> > @@ -672,7 +668,6 @@ static struct tegra_clk tegra114_clks[tegra_clk_max] __initdata = {
> >       [tegra_clk_csi] = { .dt_id = TEGRA114_CLK_CSI, .present = true },
> >       [tegra_clk_i2c2] = { .dt_id = TEGRA114_CLK_I2C2, .present = true },
> >       [tegra_clk_uartc] = { .dt_id = TEGRA114_CLK_UARTC, .present = true },
> > -     [tegra_clk_emc] = { .dt_id = TEGRA114_CLK_EMC, .present = true },
> >       [tegra_clk_usb2] = { .dt_id = TEGRA114_CLK_USB2, .present = true },
> >       [tegra_clk_usb3] = { .dt_id = TEGRA114_CLK_USB3, .present = true },
> >       [tegra_clk_vde_8] = { .dt_id = TEGRA114_CLK_VDE, .present = true },
> > @@ -1048,14 +1043,7 @@ static __init void tegra114_periph_clk_init(void __iomem *clk_base,
> >                                            0, 82, periph_clk_enb_refcnt);
> >       clks[TEGRA114_CLK_DSIB] = clk;
> >
> > -     /* emc mux */
> > -     clk = clk_register_mux(NULL, "emc_mux", mux_pllmcp_clkm,
> > -                            ARRAY_SIZE(mux_pllmcp_clkm),
> > -                            CLK_SET_RATE_NO_REPARENT,
> > -                            clk_base + CLK_SOURCE_EMC,
> > -                            29, 3, 0, &emc_lock);
> > -
> > -     clk = tegra_clk_register_mc("mc", "emc_mux", clk_base + CLK_SOURCE_EMC,
> > +     clk = tegra_clk_register_mc("mc", "emc", clk_base + CLK_SOURCE_EMC,
> >                                   &emc_lock);
> >       clks[TEGRA114_CLK_MC] = clk;
> >
> > @@ -1321,6 +1309,28 @@ static int tegra114_reset_deassert(unsigned long id)
> >       return 0;
> >  }
> >
> > +#ifdef CONFIG_TEGRA124_CLK_EMC
> > +static struct clk *tegra114_clk_src_onecell_get(struct of_phandle_args *clkspec,
> > +                                             void *data)
> > +{
> > +     struct clk_hw *hw;
> > +     struct clk *clk;
> > +
> > +     clk = of_clk_src_onecell_get(clkspec, data);
> > +     if (IS_ERR(clk))
> > +             return clk;
> > +
> > +     hw = __clk_get_hw(clk);
> > +
> > +     if (clkspec->args[0] == TEGRA114_CLK_EMC) {
> > +             if (!tegra124_clk_emc_driver_available(hw))
> > +                     return ERR_PTR(-EPROBE_DEFER);
> > +     }
> > +
> > +     return clk;
> > +}
> > +#endif
> > +
> >  static void __init tegra114_clock_init(struct device_node *np)
> >  {
> >       struct device_node *node;
> > @@ -1362,16 +1372,24 @@ static void __init tegra114_clock_init(struct device_node *np)
> >       tegra_audio_clk_init(clk_base, pmc_base, tegra114_clks,
> >                            tegra114_audio_plls,
> >                            ARRAY_SIZE(tegra114_audio_plls), 24000000);
> > +
> > +     tegra_clk_apply_init_table = tegra114_clock_apply_init_table;
> > +
>
> Is there any particular reason for moving this here? If not, omitting the change would simplify the patch a bit.
>

IIRC, I tried to align with Tegra124 EMC clk driver, I will try to
drop this change and check if all works as expected.

> >       tegra_super_clk_gen4_init(clk_base, pmc_base, tegra114_clks,
> >                                       &pll_x_params);
> >
> >       tegra_init_special_resets(1, tegra114_reset_assert,
> >                                 tegra114_reset_deassert);
> >
> > +#ifdef CONFIG_TEGRA124_CLK_EMC
> > +     tegra_add_of_provider(np, tegra114_clk_src_onecell_get);
> > +     clks[TEGRA114_CLK_EMC] = tegra124_clk_register_emc(clk_base, np,
> > +                                                        &emc_lock);
> > +#else
> >       tegra_add_of_provider(np, of_clk_src_onecell_get);
> > -     tegra_register_devclks(devclks, ARRAY_SIZE(devclks));
> > +#endif
>
> tegra124_clk_register_emc and tegra124_clk_emc_driver_available have stub implementations when CONFIG_TEGRA124_CLK_EMC is not enabled, so it would be cleaner to just call them always.
>

Yes, I will adjust this in v4. Thank you.

> >
> > -     tegra_clk_apply_init_table = tegra114_clock_apply_init_table;
> > +     tegra_register_devclks(devclks, ARRAY_SIZE(devclks));
> >
> >       tegra_cpu_car_ops = &tegra114_cpu_car_ops;
> >  }
> >
>
>
>
>