* [RESEND PATCH] clk: rockchip: Prevent calculating mmc phase if clock rate is zero
@ 2018-03-05 3:25 Shawn Lin
2018-03-05 21:08 ` Heiko Stübner
0 siblings, 1 reply; 2+ messages in thread
From: Shawn Lin @ 2018-03-05 3:25 UTC (permalink / raw)
To: Heiko Stuebner, Michael Turquette, Stephen Boyd
Cc: linux-clk, linux-rockchip, Shawn Lin
The MMC sample and drv clock for rockchip platforms are derived from
the bus clock output to the MMC/SDIO card. So it should never happens
that the clk rate is zero given it should inherits the clock rate from
its parent. If something goes wrong and makes the clock rate to be zero,
the calculation would be wrong but may still make the mmc tuning process
work luckily. However it makes people harder to debug when the following
data transfer is unstable.
Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
---
Resend this since the former log output missed '\n'
drivers/clk/rockchip/clk-mmc-phase.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/drivers/clk/rockchip/clk-mmc-phase.c b/drivers/clk/rockchip/clk-mmc-phase.c
index 077fcdc..c0c14e4 100644
--- a/drivers/clk/rockchip/clk-mmc-phase.c
+++ b/drivers/clk/rockchip/clk-mmc-phase.c
@@ -58,6 +58,12 @@ static int rockchip_mmc_get_phase(struct clk_hw *hw)
u16 degrees;
u32 delay_num = 0;
+ /* See the comment for rockchip_mmc_set_phase below */
+ if (!rate) {
+ pr_err("%s: invalid clk rate\n", __func__);
+ return -EINVAL;
+ }
+
raw_value = readl(mmc_clock->reg) >> (mmc_clock->shift);
degrees = (raw_value & ROCKCHIP_MMC_DEGREE_MASK) * 90;
@@ -84,6 +90,25 @@ static int rockchip_mmc_set_phase(struct clk_hw *hw, int degrees)
u32 raw_value;
u32 delay;
+ /*
+ * The below calculation is based on the output clock from
+ * MMC host to the card, which expects the phase clock inherits
+ * the clock rate from its parent, namely the output clock
+ * provider of MMC host. However, things may go wrong if
+ * (1) It is orphan.
+ * (2) It is assigned to the wrong parent.
+ *
+ * This check help debug the case (1), which seems to be the
+ * most likely problem we often made and explicitly makes people
+ * harder to debug the unstable mmc tuning stuff. So hope people
+ * to have a close look at this comment to help check out what was
+ * happening.
+ */
+ if (!rate) {
+ pr_err("%s: invalid clk rate\n", __func__);
+ return -EINVAL;
+ }
+
nineties = degrees / 90;
remainder = (degrees % 90);
--
1.9.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [RESEND PATCH] clk: rockchip: Prevent calculating mmc phase if clock rate is zero
2018-03-05 3:25 [RESEND PATCH] clk: rockchip: Prevent calculating mmc phase if clock rate is zero Shawn Lin
@ 2018-03-05 21:08 ` Heiko Stübner
0 siblings, 0 replies; 2+ messages in thread
From: Heiko Stübner @ 2018-03-05 21:08 UTC (permalink / raw)
To: Shawn Lin; +Cc: Michael Turquette, Stephen Boyd, linux-clk, linux-rockchip
Am Montag, 5. M=E4rz 2018, 04:25:58 CET schrieb Shawn Lin:
> The MMC sample and drv clock for rockchip platforms are derived from
> the bus clock output to the MMC/SDIO card. So it should never happens
> that the clk rate is zero given it should inherits the clock rate from
> its parent. If something goes wrong and makes the clock rate to be zero,
> the calculation would be wrong but may still make the mmc tuning process
> work luckily. However it makes people harder to debug when the following
> data transfer is unstable.
>=20
> Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
applied for 4.17
Thanks
Heiko
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-03-05 21:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-05 3:25 [RESEND PATCH] clk: rockchip: Prevent calculating mmc phase if clock rate is zero Shawn Lin
2018-03-05 21:08 ` Heiko Stübner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox