Skip to contentSkip to conversation

Tegra: fix clock init

PATCH Superseded Svyatoslav Ryhel 3 participants 8 messages Dec 12, 2024 – Dec 13, 2024

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Tegra: fix clock init

This should fix https://lore.kernel.org/all/20241201164810.GT3600562@bill-the-cat/T/#m2b62b471fd37e4c9725c98547e2a919cf11db5e5

---
Changes from v1
- added partially support PLL clocks commit
---

Svyatoslav Ryhel (2):
driver: clk: tegra: partially support PLL clocks
driver: clk: tegra: init basic clocks on probe

 drivers/clk/tegra/tegra-car-clk.c | 52 +++++++++++++++++++++++++------
 1 file changed, 42 insertions(+), 10 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 1/2 driver: clk: tegra: partially support PLL clocks

Return PLL id into struct clk if PLL is parsed from device tree instead of throwing an error. Allow requesting PLL clock rate via get_rate op.

---
 drivers/clk/tegra/tegra-car-clk.c | 49 ++++++++++++++++++++++++-------
 1 file changed, 39 insertions(+), 10 deletions(-)
drivers/clk/tegra/tegra-car-clk.c +39 -10
index 1d61f8dc378..dd4d7791120 100644
@@ -10,6 +10,9 @@
 #include <asm/arch/clock.h>
 #include <asm/arch-tegra/clk_rst.h>
 
+#define TEGRA_CAR_CLK_PLL	BIT(0)
+#define TEGRA_CAR_CLK_PERIPH	BIT(1)
+
 static int tegra_car_clk_request(struct clk *clk)
 {
 	debug("%s(clk=%p) (dev=%p, id=%lu)\n", __func__, clk, clk->dev,
@@ -20,30 +23,50 @@ static int tegra_car_clk_request(struct clk *clk)
 	 * varies per SoC) are the peripheral clocks, which use a numbering
 	 * scheme that matches HW registers 1:1. There are other clock IDs
 	 * beyond this that are assigned arbitrarily by the Tegra CAR DT
-	 * binding. Due to the implementation of this driver, it currently
-	 * only supports the peripheral IDs.
+	 * binding.
 	 */
-	if (clk->id >= PERIPH_ID_COUNT)
-		return -EINVAL;
+	if (!(clk->id >= PERIPH_ID_COUNT)) {
+		clk->data |= TEGRA_CAR_CLK_PERIPH;
+		return 0;
+	}
 
-	return 0;
+	/* If check for periph failed, then check for PLL clock id */
+	int id = clk_id_to_pll_id(clk->id);
+
+	if (clock_id_is_pll(id)) {
+		clk->id = id;
+		clk->data |= TEGRA_CAR_CLK_PLL;
+		return 0;
+	}
+
+	return -EINVAL;
 }
 
 static ulong tegra_car_clk_get_rate(struct clk *clk)
 {
-	enum clock_id parent;
+	if (clk->data & TEGRA_CAR_CLK_PLL)
+		return clock_get_rate(clk->id);
 
-	debug("%s(clk=%p) (dev=%p, id=%lu)\n", __func__, clk, clk->dev,
-	      clk->id);
+	if (clk->data & TEGRA_CAR_CLK_PERIPH) {
+		enum clock_id parent;
 
-	parent = clock_get_periph_parent(clk->id);
-	return clock_get_periph_rate(clk->id, parent);
+		debug("%s(clk=%p) (dev=%p, id=%lu)\n", __func__,
+		      clk, clk->dev, clk->id);
+
+		parent = clock_get_periph_parent(clk->id);
+		return clock_get_periph_rate(clk->id, parent);
+	}
+
+	return -1U;
 }
 
 static ulong tegra_car_clk_set_rate(struct clk *clk, ulong rate)
 {
 	enum clock_id parent;
 
+	if (clk->data & TEGRA_CAR_CLK_PLL)
+		return 0;
+
 	debug("%s(clk=%p, rate=%lu) (dev=%p, id=%lu)\n", __func__, clk, rate,
 	      clk->dev, clk->id);
 
@@ -53,6 +76,9 @@ static ulong tegra_car_clk_set_rate(struct clk *clk, ulong rate)
 
 static int tegra_car_clk_enable(struct clk *clk)
 {
+	if (clk->data & TEGRA_CAR_CLK_PLL)
+		return 0;
+
 	debug("%s(clk=%p) (dev=%p, id=%lu)\n", __func__, clk, clk->dev,
 	      clk->id);
 
@@ -63,6 +89,9 @@ static int tegra_car_clk_enable(struct clk *clk)
 
 static int tegra_car_clk_disable(struct clk *clk)
 {
+	if (clk->data & TEGRA_CAR_CLK_PLL)
+		return 0;
+
 	debug("%s(clk=%p) (dev=%p, id=%lu)\n", __func__, clk, clk->dev,
 	      clk->id);
 
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH v2 1/2] driver: clk: tegra: partially support PLL clocks

Quoted 24 lines · Svyatoslav Ryhel

Return PLL id into struct clk if PLL is parsed from device tree instead of throwing an error. Allow requesting PLL clock rate via get_rate op.

---
 drivers/clk/tegra/tegra-car-clk.c | 49 ++++++++++++++++++++++++-------
 1 file changed, 39 insertions(+), 10 deletions(-)
drivers/clk/tegra/tegra-car-clk.c +3 -0
index 1d61f8dc378..dd4d7791120 100644
@@ -10,6 +10,9 @@
 #include <asm/arch/clock.h>
 #include <asm/arch-tegra/clk_rst.h>
 
+#define TEGRA_CAR_CLK_PLL	BIT(0)
+#define TEGRA_CAR_CLK_PERIPH	BIT(1)
+
 static int tegra_car_clk_request(struct clk *clk)
 {
 	debug("%s(clk=%p) (dev=%p, id=%lu)\n", __func__, clk, clk->dev,

drivers/clk/tegra/tegra-car-clk.c static int tegra_car_clk_request(struct clk *clk) · line 28

Quoted 10 lines
drivers/clk/tegra/tegra-car-clk.c +2 -4
@@ -20,30 +23,50 @@ static int tegra_car_clk_request(struct clk *clk)
 	 * varies per SoC) are the peripheral clocks, which use a numbering
 	 * scheme that matches HW registers 1:1. There are other clock IDs
 	 * beyond this that are assigned arbitrarily by the Tegra CAR DT
-	 * binding. Due to the implementation of this driver, it currently
-	 * only supports the peripheral IDs.
+	 * binding.
 	 */
-	if (clk->id >= PERIPH_ID_COUNT)
-		return -EINVAL;
+	if (!(clk->id >= PERIPH_ID_COUNT)) {

Maybe just do clk->id < PERIPH_ID_COUNT and get rid of the negation? Seems a bit more straightforward.

Quoted 22 lines
drivers/clk/tegra/tegra-car-clk.c +15 -2
+		clk->data |= TEGRA_CAR_CLK_PERIPH;
+		return 0;
+	}
 
-	return 0;
+	/* If check for periph failed, then check for PLL clock id */
+	int id = clk_id_to_pll_id(clk->id);
+
+	if (clock_id_is_pll(id)) {
+		clk->id = id;
+		clk->data |= TEGRA_CAR_CLK_PLL;
+		return 0;
+	}
+
+	return -EINVAL;
 }
 
 static ulong tegra_car_clk_get_rate(struct clk *clk)
 {
-	enum clock_id parent;
+	if (clk->data & TEGRA_CAR_CLK_PLL)
+		return clock_get_rate(clk->id);

drivers/clk/tegra/tegra-car-clk.c static int tegra_car_clk_request(struct clk *clk) · line 54

Quoted 10 lines
drivers/clk/tegra/tegra-car-clk.c +4 -4
 
-	debug("%s(clk=%p) (dev=%p, id=%lu)\n", __func__, clk, clk->dev,
-	      clk->id);
+	if (clk->data & TEGRA_CAR_CLK_PERIPH) {
+		enum clock_id parent;
 
-	parent = clock_get_periph_parent(clk->id);
-	return clock_get_periph_rate(clk->id, parent);
+		debug("%s(clk=%p) (dev=%p, id=%lu)\n", __func__,
+		      clk, clk->dev, clk->id);

Is there any specific reason why you moved the debug() call into the branch? It looks like it was supposed to be a simple function tracing message, so it would probably be useful to have for PLL clocks as well.

Quoted 7 lines
drivers/clk/tegra/tegra-car-clk.c +6 -0
+
+		parent = clock_get_periph_parent(clk->id);
+		return clock_get_periph_rate(clk->id, parent);
+	}
+
+	return -1U;
 }

drivers/clk/tegra/tegra-car-clk.c static int tegra_car_clk_request(struct clk *clk) · line 71

Quoted 10 lines
drivers/clk/tegra/tegra-car-clk.c +3 -0
 
 static ulong tegra_car_clk_set_rate(struct clk *clk, ulong rate)
 {
 	enum clock_id parent;
 
+	if (clk->data & TEGRA_CAR_CLK_PLL)
+		return 0;
+
 	debug("%s(clk=%p, rate=%lu) (dev=%p, id=%lu)\n", __func__, clk, rate,
 	      clk->dev, clk->id);

Same here.

drivers/clk/tegra/tegra-car-clk.c static ulong tegra_car_clk_set_rate(struct clk *clk, ulong rate) · line 83

Quoted 10 lines
drivers/clk/tegra/tegra-car-clk.c +3 -0
@@ -53,6 +76,9 @@ static ulong tegra_car_clk_set_rate(struct clk *clk, ulong rate)
 
 static int tegra_car_clk_enable(struct clk *clk)
 {
+	if (clk->data & TEGRA_CAR_CLK_PLL)
+		return 0;
+
 	debug("%s(clk=%p) (dev=%p, id=%lu)\n", __func__, clk, clk->dev,
 	      clk->id);

And here.

drivers/clk/tegra/tegra-car-clk.c static int tegra_car_clk_enable(struct clk *clk) · line 97

Quoted 11 lines
drivers/clk/tegra/tegra-car-clk.c +3 -0
@@ -63,6 +89,9 @@ static int tegra_car_clk_enable(struct clk *clk)
 
 static int tegra_car_clk_disable(struct clk *clk)
 {
+	if (clk->data & TEGRA_CAR_CLK_PLL)
+		return 0;
+
 	debug("%s(clk=%p) (dev=%p, id=%lu)\n", __func__, clk, clk->dev,
 	      clk->id);
 

And here, too.

Thierry

#3 lore raw

Re: [PATCH v2 1/2] driver: clk: tegra: partially support PLL clocks

пт, 13 груд. 2024 р. о 16:33 Thierry Reding <[email protected]> пише:

Quoted 31 lines · Svyatoslav Ryhel
Quoted 29 lines

Return PLL id into struct clk if PLL is parsed from device tree instead of throwing an error. Allow requesting PLL clock rate via get_rate op.

---
 drivers/clk/tegra/tegra-car-clk.c | 49 ++++++++++++++++++++++++-------
 1 file changed, 39 insertions(+), 10 deletions(-)
drivers/clk/tegra/tegra-car-clk.c +3 -2
index 1d61f8dc378..dd4d7791120 100644
@@ -10,6 +10,9 @@
 #include <asm/arch/clock.h>
 #include <asm/arch-tegra/clk_rst.h>
 
+#define TEGRA_CAR_CLK_PLL    BIT(0)
+#define TEGRA_CAR_CLK_PERIPH BIT(1)
+
 static int tegra_car_clk_request(struct clk *clk)
 {
      debug("%s(clk=%p) (dev=%p, id=%lu)\n", __func__, clk, clk->dev,
@@ -20,30 +23,50 @@ static int tegra_car_clk_request(struct clk *clk)
       * varies per SoC) are the peripheral clocks, which use a numbering
       * scheme that matches HW registers 1:1. There are other clock IDs
       * beyond this that are assigned arbitrarily by the Tegra CAR DT
-      * binding. Due to the implementation of this driver, it currently
-      * only supports the peripheral IDs.
Quoted 9 lines

drivers/clk/tegra/tegra-car-clk.c static int tegra_car_clk_request(struct clk *clk) · line 28

Quoted 5 lines
drivers/clk/tegra/tegra-car-clk.c +2 -2
+      * binding.
       */
-     if (clk->id >= PERIPH_ID_COUNT)
-             return -EINVAL;
+     if (!(clk->id >= PERIPH_ID_COUNT)) {

Maybe just do clk->id < PERIPH_ID_COUNT and get rid of the negation? Seems a bit more straightforward.

Agreed.

Quoted 28 lines
Quoted 28 lines
drivers/clk/tegra/tegra-car-clk.c +17 -4
+             clk->data |= TEGRA_CAR_CLK_PERIPH;
+             return 0;
+     }
 
-     return 0;
+     /* If check for periph failed, then check for PLL clock id */
+     int id = clk_id_to_pll_id(clk->id);
+
+     if (clock_id_is_pll(id)) {
+             clk->id = id;
+             clk->data |= TEGRA_CAR_CLK_PLL;
+             return 0;
+     }
+
+     return -EINVAL;
 }
 
 static ulong tegra_car_clk_get_rate(struct clk *clk)
 {
-     enum clock_id parent;
+     if (clk->data & TEGRA_CAR_CLK_PLL)
+             return clock_get_rate(clk->id);
 
-     debug("%s(clk=%p) (dev=%p, id=%lu)\n", __func__, clk, clk->dev,
-           clk->id);
+     if (clk->data & TEGRA_CAR_CLK_PERIPH) {
+             enum clock_id parent;
 
Quoted 9 lines

drivers/clk/tegra/tegra-car-clk.c static int tegra_car_clk_request(struct clk *clk) · line 54

Quoted 4 lines
drivers/clk/tegra/tegra-car-clk.c +2 -2
-     parent = clock_get_periph_parent(clk->id);
-     return clock_get_periph_rate(clk->id, parent);
+             debug("%s(clk=%p) (dev=%p, id=%lu)\n", __func__,
+                   clk, clk->dev, clk->id);

Is there any specific reason why you moved the debug() call into the branch? It looks like it was supposed to be a simple function tracing message, so it would probably be useful to have for PLL clocks as well.

I will check if this debug can be applied to plls as well as it is. If yes, I will move it higher. Thanks

Quoted 48 lines
Quoted 7 lines
drivers/clk/tegra/tegra-car-clk.c +6 -0
+
+             parent = clock_get_periph_parent(clk->id);
+             return clock_get_periph_rate(clk->id, parent);
+     }
+
+     return -1U;
 }

drivers/clk/tegra/tegra-car-clk.c static int tegra_car_clk_request(struct clk *clk) · line 71

Quoted 10 lines
drivers/clk/tegra/tegra-car-clk.c +3 -0
 
 static ulong tegra_car_clk_set_rate(struct clk *clk, ulong rate)
 {
      enum clock_id parent;
 
+     if (clk->data & TEGRA_CAR_CLK_PLL)
+             return 0;
+
      debug("%s(clk=%p, rate=%lu) (dev=%p, id=%lu)\n", __func__, clk, rate,
            clk->dev, clk->id);

Same here.

drivers/clk/tegra/tegra-car-clk.c static ulong tegra_car_clk_set_rate(struct clk *clk, ulong rate) · line 83

Quoted 10 lines
drivers/clk/tegra/tegra-car-clk.c +3 -0
@@ -53,6 +76,9 @@ static ulong tegra_car_clk_set_rate(struct clk *clk, ulong rate)
 
 static int tegra_car_clk_enable(struct clk *clk)
 {
+     if (clk->data & TEGRA_CAR_CLK_PLL)
+             return 0;
+
      debug("%s(clk=%p) (dev=%p, id=%lu)\n", __func__, clk, clk->dev,
            clk->id);

And here.

drivers/clk/tegra/tegra-car-clk.c static int tegra_car_clk_enable(struct clk *clk) · line 97

Quoted 11 lines
drivers/clk/tegra/tegra-car-clk.c +3 -0
@@ -63,6 +89,9 @@ static int tegra_car_clk_enable(struct clk *clk)
 
 static int tegra_car_clk_disable(struct clk *clk)
 {
+     if (clk->data & TEGRA_CAR_CLK_PLL)
+             return 0;
+
      debug("%s(clk=%p) (dev=%p, id=%lu)\n", __func__, clk, clk->dev,
            clk->id);
 

And here, too.

Thierry

#4 lore raw

PATCH v2 2/2 driver: clk: tegra: init basic clocks on probe

In reply to Svyatoslav Ryhel

In case DM drivers probe earlier than board clock setup is done init of basic clocks should be done in CAR driver probe as well. Add it to avoid possible clock related problems.

---
 drivers/clk/tegra/tegra-car-clk.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/clk/tegra/tegra-car-clk.c +3 -0
index dd4d7791120..a07c16c487a 100644
@@ -112,6 +112,9 @@ static int tegra_car_clk_probe(struct udevice *dev)
 {
 	debug("%s(dev=%p)\n", __func__, dev);
 
+	clock_init();
+	clock_verify();
+
 	return 0;
 }
 
Signature · 1 line
2.43.0
Acked-by on v2 2/2
#5 lore raw

Re: [PATCH v2 2/2] driver: clk: tegra: init basic clocks on probe

Quoted 8 lines · Svyatoslav Ryhel

In case DM drivers probe earlier than board clock setup is done init of basic clocks should be done in CAR driver probe as well. Add it to avoid possible clock related problems.

---
 drivers/clk/tegra/tegra-car-clk.c | 3 +++
 1 file changed, 3 insertions(+)
#6 lore raw
In reply to Svyatoslav Ryhel
Quoted 7 lines · Svyatoslav Ryhel

This should fix https://lore.kernel.org/all/20241201164810.GT3600562@bill-the-cat/T/#m2b62b471fd37e4c9725c98547e2a919cf11db5e5

---
Changes from v1
- added partially support PLL clocks commit
---

Quoted 6 lines

Svyatoslav Ryhel (2):
driver: clk: tegra: partially support PLL clocks
driver: clk: tegra: init basic clocks on probe

 drivers/clk/tegra/tegra-car-clk.c | 52 +++++++++++++++++++++++++------
 1 file changed, 42 insertions(+), 10 deletions(-)

Thanks. Do you want to send me a PR for these, or should I apply them directly in a bit after time for further review / testing?

Signature · 1 line
Tom
#7 lore raw

чт, 12 груд. 2024 р. о 17:55 Tom Rini <[email protected]> пише:

Quoted 14 lines · Svyatoslav Ryhel
Quoted 12 lines

This should fix https://lore.kernel.org/all/20241201164810.GT3600562@bill-the-cat/T/#m2b62b471fd37e4c9725c98547e2a919cf11db5e5

---
Changes from v1
- added partially support PLL clocks commit
---

Svyatoslav Ryhel (2):
driver: clk: tegra: partially support PLL clocks
driver: clk: tegra: init basic clocks on probe

Quoted 6 lines
Quoted 2 lines
 drivers/clk/tegra/tegra-car-clk.c | 52 +++++++++++++++++++++++++------
 1 file changed, 42 insertions(+), 10 deletions(-)

Thanks. Do you want to send me a PR for these, or should I apply them directly in a bit after time for further review / testing?

I have rushed previous patch since Simon responded that he is picking revert to some tree, which seems not to be official U-Boot repo.

I have send quite a bit of Tegra related patches today, and, if you are fine with that, I may pick them all after some a week or so to Tegra custodian repo and then ask for a PR. There is no urgency right now to apply clock patch tbh.

Quoted 2 lines

--
Tom