Skip to contentSkip to conversation

mmc: atmel-sdhci: do not check clk_set_rate return value

PATCH New Eugen Hristev 2 participants 3 messages Aug 27, 2020 – Sep 7, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 4/6 mmc: atmel-sdhci: do not check clk_set_rate return value

clk_set_rate will return rate in case of success and zero in case of error, however it can also return -ev, but it's an ulong function. To avoid any issues, disregard the return value of this call. In case this call actually fails, nothing much we can do anyway, but we can at least try with the previous values (or DT assigned-clocks)

---
 drivers/mmc/atmel_sdhci.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/mmc/atmel_sdhci.c +1 -3
index f03c0457e1..54b660c34a 100644
@@ -79,9 +79,7 @@ static int atmel_sdhci_probe(struct udevice *dev)
 	if (ret)
 		return ret;
 
-	ret = clk_set_rate(&clk, ATMEL_SDHC_GCK_RATE);
-	if (ret)
-		return ret;
+	clk_set_rate(&clk, ATMEL_SDHC_GCK_RATE);
 
 	max_clk = clk_get_rate(&clk);
 	if (!max_clk)
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 4/6 mmc: atmel-sdhci: do not check clk_set_rate return value

Quoted 19 lines

Subject: [PATCH v2 4/6] mmc: atmel-sdhci: do not check clk_set_rate return value

clk_set_rate will return rate in case of success and zero in case of error, however it can also return -ev, but it's an ulong function.
To avoid any issues, disregard the return value of this call.
In case this call actually fails, nothing much we can do anyway, but we can at least try with the previous values (or DT assigned-clocks)

---
 drivers/mmc/atmel_sdhci.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/mmc/atmel_sdhci.c index renamed from drivers/mmc/atmel_sdhci.c +0 -0

f03c0457e1..54b660c34a 100644

drivers/mmc/atmel_sdhci.c static int atmel_sdhci_probe(struct udevice *dev) · line 85

Quoted 10 lines
drivers/mmc/atmel_sdhci.c +1 -3
@@ -79,9 +79,7 @@ static int atmel_sdhci_probe(struct udevice *dev)
 	if (ret)
 		return ret;
 
-	ret = clk_set_rate(&clk, ATMEL_SDHC_GCK_RATE);
-	if (ret)
-		return ret;
+	clk_set_rate(&clk, ATMEL_SDHC_GCK_RATE);
 
 	max_clk = clk_get_rate(&clk);
 	if (!max_clk)

Since clk_set_rate will return the new rate or 0, is there a need to use clk_get_rate following there?

Regards,
Peng.

Quoted 2 lines

--
2.25.1

#2 lore raw

PATCH v2 4/6 mmc: atmel-sdhci: do not check clk_set_rate return value

Quoted 27 lines · Peng Fan
Quoted 27 lines

Subject: [PATCH v2 4/6] mmc: atmel-sdhci: do not check clk_set_rate return value

clk_set_rate will return rate in case of success and zero in case of error, however it can also return -ev, but it's an ulong function.
To avoid any issues, disregard the return value of this call.
In case this call actually fails, nothing much we can do anyway, but we can at least try with the previous values (or DT assigned-clocks)

---
  drivers/mmc/atmel_sdhci.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
drivers/mmc/atmel_sdhci.c index renamed from drivers/mmc/atmel_sdhci.c +0 -0

f03c0457e1..54b660c34a 100644

drivers/mmc/atmel_sdhci.c +1 -3
@@ -79,9 +79,7 @@ static int atmel_sdhci_probe(struct udevice *dev)
       if (ret)
               return ret;
 
-     ret = clk_set_rate(&clk, ATMEL_SDHC_GCK_RATE);
-     if (ret)
-             return ret;
+     clk_set_rate(&clk, ATMEL_SDHC_GCK_RATE);
 
Quoted 8 lines

drivers/mmc/atmel_sdhci.c static int atmel_sdhci_probe(struct udevice *dev) · line 85

Quoted 2 lines
drivers/mmc/atmel_sdhci.c +0 -0
       max_clk = clk_get_rate(&clk);
       if (!max_clk)

Since clk_set_rate will return the new rate or 0, is there a need to use clk_get_rate following there?

Regards,
Peng.

Hi Peng,

Yes. The clk_set_rate will return failure(0) if the clock was not changed, due to maybe an incorrect rate was set. However, this does not mean that we need to bail out.
The clock can be preconfigured from DT property assigned-clocks. When calling clk_get_rate, we get the currently assigned rate.

Here is an example:

sama7g5 SoC supports clock at maximum 200 Mhz. Thus we assign 200 Mhz from assigned-clocks property.

The driver will call set_rate with 240 Mhz (predefined in driver). It will fail, return code 0.
However, the clock works at 200 Mhz and already configured. When requesting the rate, we get the 200 Mhz from the clock subsystem. We can move forward, and have host->max_clk = max_clk, as done below in the driver.

Does this look good to you ?

Thanks,
Eugen

Quoted 5 lines
Quoted 4 lines

--
2.25.1