All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] change the clk-mux get_rate helper
@ 2020-05-02 15:58 Dario Binacchi
  2020-05-02 15:58 ` [PATCH 1/4] clk: ccf: mux: change include order Dario Binacchi
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Dario Binacchi @ 2020-05-02 15:58 UTC (permalink / raw)
  To: u-boot


Changes:
 - Apply coding style
 - Fix typo
 - Fix access to sandbox register
 - Change the gate_rate helper


Dario Binacchi (4):
  clk: ccf: mux: change include order
  clk: ccf: mux: fix typo
  clk: ccf: mux: fix access to the sandbox register
  clk: ccf: mux: change the get_rate helper

 drivers/clk/clk-mux.c | 44 +++++++++++++++++++++++++++++++++++++------
 test/dm/clk_ccf.c     | 24 +++++++++++++++++++++++
 2 files changed, 62 insertions(+), 6 deletions(-)

-- 
2.17.1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/4] clk: ccf: mux: change include order
  2020-05-02 15:58 [PATCH 0/4] change the clk-mux get_rate helper Dario Binacchi
@ 2020-05-02 15:58 ` Dario Binacchi
  2020-05-02 15:58 ` [PATCH 2/4] clk: ccf: mux: fix typo Dario Binacchi
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Dario Binacchi @ 2020-05-02 15:58 UTC (permalink / raw)
  To: u-boot

Apply u-boot coding style on include files order.

Signed-off-by: Dario Binacchi <dariobin@libero.it>
---

 drivers/clk/clk-mux.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/clk/clk-mux.c b/drivers/clk/clk-mux.c
index b9d2ae6778..9511a80fe3 100644
--- a/drivers/clk/clk-mux.c
+++ b/drivers/clk/clk-mux.c
@@ -22,15 +22,15 @@
  */
 
 #include <common.h>
-#include <asm/io.h>
-#include <malloc.h>
+#include <clk.h>
 #include <clk-uclass.h>
 #include <dm/device.h>
 #include <dm/devres.h>
+#include <malloc.h>
+#include <asm/io.h>
 #include <linux/clk-provider.h>
-#include <clk.h>
-#include "clk.h"
 #include <linux/err.h>
+#include "clk.h"
 
 #define UBOOT_DM_CLK_CCF_MUX "ccf_clk_mux"
 
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/4] clk: ccf: mux: fix typo
  2020-05-02 15:58 [PATCH 0/4] change the clk-mux get_rate helper Dario Binacchi
  2020-05-02 15:58 ` [PATCH 1/4] clk: ccf: mux: change include order Dario Binacchi
@ 2020-05-02 15:58 ` Dario Binacchi
  2020-05-02 15:58 ` [PATCH 3/4] clk: ccf: mux: fix access to the sandbox register Dario Binacchi
  2020-05-02 15:58 ` [PATCH 4/4] clk: ccf: mux: change the get_rate helper Dario Binacchi
  3 siblings, 0 replies; 6+ messages in thread
From: Dario Binacchi @ 2020-05-02 15:58 UTC (permalink / raw)
  To: u-boot

Close the opening bracket.

Signed-off-by: Dario Binacchi <dariobin@libero.it>
---

 drivers/clk/clk-mux.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/clk/clk-mux.c b/drivers/clk/clk-mux.c
index 9511a80fe3..6264b63900 100644
--- a/drivers/clk/clk-mux.c
+++ b/drivers/clk/clk-mux.c
@@ -193,7 +193,7 @@ struct clk *clk_hw_register_mux_table(struct device *dev, const char *name,
 	 * Read the current mux setup - so we assign correct parent.
 	 *
 	 * Changing parent would require changing internals of udevice struct
-	 * for the corresponding clock (to do that define .set_parent() method.
+	 * for the corresponding clock (to do that define .set_parent() method).
 	 */
 	ret = clk_register(clk, UBOOT_DM_CLK_CCF_MUX, name,
 			   parent_names[clk_mux_get_parent(clk)]);
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/4] clk: ccf: mux: fix access to the sandbox register
  2020-05-02 15:58 [PATCH 0/4] change the clk-mux get_rate helper Dario Binacchi
  2020-05-02 15:58 ` [PATCH 1/4] clk: ccf: mux: change include order Dario Binacchi
  2020-05-02 15:58 ` [PATCH 2/4] clk: ccf: mux: fix typo Dario Binacchi
@ 2020-05-02 15:58 ` Dario Binacchi
  2020-05-02 15:58 ` [PATCH 4/4] clk: ccf: mux: change the get_rate helper Dario Binacchi
  3 siblings, 0 replies; 6+ messages in thread
From: Dario Binacchi @ 2020-05-02 15:58 UTC (permalink / raw)
  To: u-boot

The tests developed for the mux clock are run on the sandbox. They don't
call the clk_mux_set_parent routine and therefore they do not detect
this error.

Signed-off-by: Dario Binacchi <dariobin@libero.it>
---

 drivers/clk/clk-mux.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/clk/clk-mux.c b/drivers/clk/clk-mux.c
index 6264b63900..8f85e84ae9 100644
--- a/drivers/clk/clk-mux.c
+++ b/drivers/clk/clk-mux.c
@@ -134,12 +134,20 @@ static int clk_mux_set_parent(struct clk *clk, struct clk *parent)
 	if (mux->flags & CLK_MUX_HIWORD_MASK) {
 		reg = mux->mask << (mux->shift + 16);
 	} else {
+#if CONFIG_IS_ENABLED(SANDBOX_CLK_CCF)
+		reg = mux->io_mux_val;
+#else
 		reg = readl(mux->reg);
+#endif
 		reg &= ~(mux->mask << mux->shift);
 	}
 	val = val << mux->shift;
 	reg |= val;
+#if CONFIG_IS_ENABLED(SANDBOX_CLK_CCF)
+	mux->io_mux_val = reg;
+#else
 	writel(reg, mux->reg);
+#endif
 
 	return 0;
 }
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/4] clk: ccf: mux: change the get_rate helper
  2020-05-02 15:58 [PATCH 0/4] change the clk-mux get_rate helper Dario Binacchi
                   ` (2 preceding siblings ...)
  2020-05-02 15:58 ` [PATCH 3/4] clk: ccf: mux: fix access to the sandbox register Dario Binacchi
@ 2020-05-02 15:58 ` Dario Binacchi
  2020-05-03  2:26   ` Simon Glass
  3 siblings, 1 reply; 6+ messages in thread
From: Dario Binacchi @ 2020-05-02 15:58 UTC (permalink / raw)
  To: u-boot

The previous version of the get_rate helper does not work if the mux
clock parent is changed after the probe. This error has not been
detected because this condition has not been tested. The error occurs
because the set_parent helper does not change the parent of the clock
device but only the clock selection register. Since changing the parent
of a probed device can be tricky, the new version of the get_rate helper
provides the rate of the selected clock and not that of the parent.

Signed-off-by: Dario Binacchi <dariobin@libero.it>

---

 drivers/clk/clk-mux.c | 26 +++++++++++++++++++++++++-
 test/dm/clk_ccf.c     | 24 ++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/clk-mux.c b/drivers/clk/clk-mux.c
index 8f85e84ae9..1f2dab647f 100644
--- a/drivers/clk/clk-mux.c
+++ b/drivers/clk/clk-mux.c
@@ -152,8 +152,32 @@ static int clk_mux_set_parent(struct clk *clk, struct clk *parent)
 	return 0;
 }
 
+static ulong clk_mux_get_rate(struct clk *clk)
+{
+	struct clk_mux *mux = to_clk_mux(clk_dev_binded(clk) ?
+			dev_get_clk_ptr(clk->dev) : clk);
+	struct udevice *parent;
+	struct clk *pclk;
+	int err, index;
+
+	index = clk_mux_get_parent(clk);
+	if (index >= mux->num_parents)
+		return -EFAULT;
+
+	err = uclass_get_device_by_name(UCLASS_CLK, mux->parent_names[index],
+					&parent);
+	if (err)
+		return err;
+
+	pclk = dev_get_clk_ptr(parent);
+	if (!pclk)
+		return -ENODEV;
+
+	return clk_get_rate(pclk);
+}
+
 const struct clk_ops clk_mux_ops = {
-	.get_rate = clk_generic_get_rate,
+	.get_rate = clk_mux_get_rate,
 	.set_parent = clk_mux_set_parent,
 };
 
diff --git a/test/dm/clk_ccf.c b/test/dm/clk_ccf.c
index ae3a4d8a76..bf99776ac1 100644
--- a/test/dm/clk_ccf.c
+++ b/test/dm/clk_ccf.c
@@ -46,6 +46,18 @@ static int dm_test_clk_ccf(struct unit_test_state *uts)
 	rate = clk_get_parent_rate(clk);
 	ut_asserteq(rate, 60000000);
 
+	rate = clk_get_rate(clk);
+	ut_asserteq(rate, 60000000);
+
+	ret = clk_get_by_id(SANDBOX_CLK_PLL3_80M, &pclk);
+	ut_assertok(ret);
+
+	ret = clk_set_parent(clk, pclk);
+	ut_assertok(ret);
+
+	rate = clk_get_rate(clk);
+	ut_asserteq(rate, 80000000);
+
 	ret = clk_get_by_id(SANDBOX_CLK_USDHC2_SEL, &clk);
 	ut_assertok(ret);
 	ut_asserteq_str("usdhc2_sel", clk->dev->name);
@@ -56,6 +68,18 @@ static int dm_test_clk_ccf(struct unit_test_state *uts)
 	pclk = clk_get_parent(clk);
 	ut_asserteq_str("pll3_80m", pclk->dev->name);
 
+	rate = clk_get_rate(clk);
+	ut_asserteq(rate, 80000000);
+
+	ret = clk_get_by_id(SANDBOX_CLK_PLL3_60M, &pclk);
+	ut_assertok(ret);
+
+	ret = clk_set_parent(clk, pclk);
+	ut_assertok(ret);
+
+	rate = clk_get_rate(clk);
+	ut_asserteq(rate, 60000000);
+
 	/* Test the composite of CCF */
 	ret = clk_get_by_id(SANDBOX_CLK_I2C, &clk);
 	ut_assertok(ret);
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/4] clk: ccf: mux: change the get_rate helper
  2020-05-02 15:58 ` [PATCH 4/4] clk: ccf: mux: change the get_rate helper Dario Binacchi
@ 2020-05-03  2:26   ` Simon Glass
  0 siblings, 0 replies; 6+ messages in thread
From: Simon Glass @ 2020-05-03  2:26 UTC (permalink / raw)
  To: u-boot

+Stephen Warren

On Sat, 2 May 2020 at 09:59, Dario Binacchi <dariobin@libero.it> wrote:
>
> The previous version of the get_rate helper does not work if the mux
> clock parent is changed after the probe. This error has not been
> detected because this condition has not been tested. The error occurs
> because the set_parent helper does not change the parent of the clock
> device but only the clock selection register. Since changing the parent
> of a probed device can be tricky, the new version of the get_rate helper
> provides the rate of the selected clock and not that of the parent.
>
> Signed-off-by: Dario Binacchi <dariobin@libero.it>
>
> ---
>
>  drivers/clk/clk-mux.c | 26 +++++++++++++++++++++++++-
>  test/dm/clk_ccf.c     | 24 ++++++++++++++++++++++++
>  2 files changed, 49 insertions(+), 1 deletion(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-05-03  2:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-02 15:58 [PATCH 0/4] change the clk-mux get_rate helper Dario Binacchi
2020-05-02 15:58 ` [PATCH 1/4] clk: ccf: mux: change include order Dario Binacchi
2020-05-02 15:58 ` [PATCH 2/4] clk: ccf: mux: fix typo Dario Binacchi
2020-05-02 15:58 ` [PATCH 3/4] clk: ccf: mux: fix access to the sandbox register Dario Binacchi
2020-05-02 15:58 ` [PATCH 4/4] clk: ccf: mux: change the get_rate helper Dario Binacchi
2020-05-03  2:26   ` Simon Glass

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.