Skip to contentSkip to conversation

clk: introduce clk_dev_binded

PATCH Superseded Peng Fan 2 participants 22 messages Jul 23, 2019 – Jul 30, 2019

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Peng Fan

author reviewer
#0 lore raw

PATCH 1/16 clk: introduce clk_dev_binded

When support Clock Common Framework, U-Boot use dev for clk tree information, there is no clk->parent. When support composite clk, it contains mux/gate/divider, but the mux/gate/divider is not binded with device. So we could not use dev_get_uclass_priv to get the correct clk_mux/gate/divider. So add clk_dev_binded to let choose the correct method.

---
 drivers/clk/clk.c | 8 ++++++++
 include/clk.h     | 9 +++++++++
 2 files changed, 17 insertions(+)
drivers/clk/clk.c +8 -0
index 7d748c9fc7..39b3087067 100644
@@ -55,3 +55,11 @@ const char *clk_hw_get_name(const struct clk *hw)
 {
 	return hw->dev->name;
 }
+
+bool clk_dev_binded(struct clk *clk)
+{
+	if (clk->dev && (clk->dev->flags & DM_FLAG_BOUND))
+		return true;
+
+	return false;
+}
include/clk.h +9 -0
index f8f56d9cf0..2ebc905e04 100644
@@ -356,4 +356,13 @@ static inline bool clk_valid(struct clk *clk)
  * @return zero on success, or -ENOENT on error
  */
 int clk_get_by_id(ulong id, struct clk **clkp);
+
+/**
+ * clk_dev_binded() - Check whether the clk has a device binded
+ *
+ * @clk		A pointer to the clk
+ *
+ * @return true on binded, or false on no
+ */
+bool clk_dev_binded(struct clk *clk);
 #endif
Signature · 1 line
2.16.4
author reviewer
#1 lore raw

PATCH 1/16 clk: introduce clk_dev_binded

Hi Lukasz,

Quoted 1 line

Subject: [PATCH 01/16] clk: introduce clk_dev_binded

Do you have time to review the patchset? Patches were delegated to you.

Thanks,
Peng.

Quoted 49 lines

When support Clock Common Framework, U-Boot use dev for clk tree information, there is no clk->parent. When support composite clk, it contains mux/gate/divider, but the mux/gate/divider is not binded with device. So we could not use dev_get_uclass_priv to get the correct clk_mux/gate/divider. So add clk_dev_binded to let choose the correct method.

---
 drivers/clk/clk.c | 8 ++++++++
 include/clk.h     | 9 +++++++++
 2 files changed, 17 insertions(+)
drivers/clk/clk.c index 7d748c9fc7..39b3087067 renamed from drivers/clk/clk.c +0 -0

100644

drivers/clk/clk.c +8 -0
@@ -55,3 +55,11 @@ const char *clk_hw_get_name(const struct clk *hw)
 {
 	return hw->dev->name;
 }
+
+bool clk_dev_binded(struct clk *clk)
+{
+	if (clk->dev && (clk->dev->flags & DM_FLAG_BOUND))
+		return true;
+
+	return false;
+}
include/clk.h index f8f56d9cf0..2ebc905e04 renamed from include/clk.h +0 -0

100644

include/clk.h +8 -1
@@ -356,4 +356,13 @@ static inline bool clk_valid(struct clk *clk)
  * @return zero on success, or -ENOENT on error
  */
 int clk_get_by_id(ulong id, struct clk **clkp);
+
+/**
+ * clk_dev_binded() - Check whether the clk has a device binded
+ *
+ * @clk		A pointer to the clk
+ *
+ * @return true on binded, or false on no  */ bool
+clk_dev_binded(struct clk *clk);
 #endif
--

2.16.4

#2 lore raw

PATCH 1/16 clk: introduce clk_dev_binded

Hi Peng,

Quoted 6 lines

Hi Lukasz,

Quoted 1 line

Subject: [PATCH 01/16] clk: introduce clk_dev_binded

Do you have time to review the patchset? Patches were delegated to you.

The i.MX related PR (with base CCF) has been pulled to mainline just yesteday, so I'm going to rewiew and test your code on top of it (with buildman) today.

I shall send PR for -clk tomorrow.

Thanks for your patches.

Quoted 45 lines

Thanks,
Peng.

Quoted 41 lines

When support Clock Common Framework, U-Boot use dev for clk tree information, there is no clk->parent. When support composite clk, it contains mux/gate/divider, but the mux/gate/divider is not binded with device. So we could not use dev_get_uclass_priv to get the correct clk_mux/gate/divider. So add clk_dev_binded to let choose the correct method.

---
 drivers/clk/clk.c | 8 ++++++++
 include/clk.h     | 9 +++++++++
 2 files changed, 17 insertions(+)
drivers/clk/clk.c index renamed from drivers/clk/clk.c +0 -0

7d748c9fc7..39b3087067 100644

drivers/clk/clk.c +8 -0
@@ -55,3 +55,11 @@ const char *clk_hw_get_name(const struct clk *hw)
 {
 	return hw->dev->name;
 }
+
+bool clk_dev_binded(struct clk *clk)
+{
+	if (clk->dev && (clk->dev->flags & DM_FLAG_BOUND))
+		return true;
+
+	return false;
+}
include/clk.h index renamed from include/clk.h +0 -0

f8f56d9cf0..2ebc905e04 100644

include/clk.h +3 -0
@@ -356,4 +356,13 @@ static inline bool clk_valid(struct clk *clk)
  * @return zero on success, or -ENOENT on error
  */
 int clk_get_by_id(ulong id, struct clk **clkp);
+
+/**
+ * clk_dev_binded() - Check whether the clk has a device binded
Quoted 9 lines
Quoted 8 lines
include/clk.h +5 -1
+ *
+ * @clk		A pointer to the clk
+ *
+ * @return true on binded, or false on no  */ bool
+clk_dev_binded(struct clk *clk);
 #endif
--

2.16.4

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma at denx.de -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190729/f80b4933/attachment.sig>

author reviewer
#3 lore raw

PATCH 1/16 clk: introduce clk_dev_binded

Quoted 7 lines

Subject: Re: [PATCH 01/16] clk: introduce clk_dev_binded

Hi Peng,

Quoted 2 lines

Hi Lukasz,

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Subject: [PATCH 01/16] clk: introduce clk_dev_binded

Do you have time to review the patchset? Patches were delegated to you.

The i.MX related PR (with base CCF) has been pulled to mainline just yesteday, so I'm going to rewiew and test your code on top of it (with buildman) today.

Thanks very much.

Thanks,
Peng.

Quoted 73 lines

I shall send PR for -clk tomorrow.

Thanks for your patches.

Quoted 18 lines

Thanks,
Peng.

Quoted 14 lines

When support Clock Common Framework, U-Boot use dev for clk tree information, there is no clk->parent. When support composite clk, it contains mux/gate/divider, but the mux/gate/divider is not binded with device. So we could not use dev_get_uclass_priv to get the correct clk_mux/gate/divider. So add clk_dev_binded to let choose the correct method.

---
 drivers/clk/clk.c | 8 ++++++++
 include/clk.h     | 9 +++++++++
 2 files changed, 17 insertions(+)
Quoted 5 lines

drivers/clk/clk.c const char *clk_hw_get_name(const struct clk

Quoted 5 lines
drivers/clk/clk.c index renamed from drivers/clk/clk.c +0 -0

7d748c9fc7..39b3087067 100644

drivers/clk/clk.c +0 -0
@@ -55,3 +55,11 @@ const char *clk_hw_get_name(const struct clk

*hw)

Quoted 21 lines
Quoted 21 lines
drivers/clk/clk.c +7 -0
 {
 	return hw->dev->name;
 }
+
+bool clk_dev_binded(struct clk *clk) {
+	if (clk->dev && (clk->dev->flags & DM_FLAG_BOUND))
+		return true;
+
+	return false;
+}
include/clk.h index renamed from include/clk.h +0 -0

f8f56d9cf0..2ebc905e04 100644

include/clk.h +3 -0
@@ -356,4 +356,13 @@ static inline bool clk_valid(struct clk *clk)
  * @return zero on success, or -ENOENT on error
  */
 int clk_get_by_id(ulong id, struct clk **clkp);
+
+/**
+ * clk_dev_binded() - Check whether the clk has a device binded
Quoted 9 lines
Quoted 8 lines
include/clk.h +5 -1
+ *
+ * @clk		A pointer to the clk
+ *
+ * @return true on binded, or false on no  */ bool
+clk_dev_binded(struct clk *clk);
 #endif
--

2.16.4

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email:
lukma at denx.de

#4 lore raw

PATCH 1/16 clk: introduce clk_dev_binded

In reply to Lukasz Majewski

Hi Peng,

Quoted 6 lines

Hi Peng,

Quoted 4 lines

Hi Lukasz,

Quoted 1 line

Subject: [PATCH 01/16] clk: introduce clk_dev_binded

Quoted 9 lines
Quoted 2 lines

Do you have time to review the patchset? Patches were delegated to you.

The i.MX related PR (with base CCF) has been pulled to mainline just yesteday, so I'm going to rewiew and test your code on top of it (with buildman) today.

I shall send PR for -clk tomorrow.

The patches from this series causes the sandbox travis-ci to break:
https://travis-ci.org/lmajewski/u-boot-dfu/builds/565204559

Please fix those errors.

You can also reproduce this issue with:

./tools/buildman/buildman.py --branch=HEAD sandbox --show_errors --force-build --count=16 --output-dir=../BUILD/

run on this series.

Quoted 62 lines

Thanks for your patches.

Quoted 45 lines

Thanks,
Peng.

Quoted 41 lines

When support Clock Common Framework, U-Boot use dev for clk tree information, there is no clk->parent. When support composite clk, it contains mux/gate/divider, but the mux/gate/divider is not binded with device. So we could not use dev_get_uclass_priv to get the correct clk_mux/gate/divider. So add clk_dev_binded to let choose the correct method.

---
 drivers/clk/clk.c | 8 ++++++++
 include/clk.h     | 9 +++++++++
 2 files changed, 17 insertions(+)
drivers/clk/clk.c index renamed from drivers/clk/clk.c +0 -0

7d748c9fc7..39b3087067 100644

drivers/clk/clk.c +8 -0
@@ -55,3 +55,11 @@ const char *clk_hw_get_name(const struct clk
 *hw) {
 	return hw->dev->name;
 }
+
+bool clk_dev_binded(struct clk *clk)
+{
+	if (clk->dev && (clk->dev->flags & DM_FLAG_BOUND))
+		return true;
+
+	return false;
+}
include/clk.h index renamed from include/clk.h +0 -0

f8f56d9cf0..2ebc905e04 100644

include/clk.h +3 -0
@@ -356,4 +356,13 @@ static inline bool clk_valid(struct clk *clk)
  * @return zero on success, or -ENOENT on error
  */
 int clk_get_by_id(ulong id, struct clk **clkp);
+
+/**
+ * clk_dev_binded() - Check whether the clk has a device binded
Quoted 9 lines
Quoted 8 lines
include/clk.h +5 -1
+ *
+ * @clk		A pointer to the clk
+ *
+ * @return true on binded, or false on no  */ bool
+clk_dev_binded(struct clk *clk);
 #endif
--

2.16.4

Best regards,

Quoted 8 lines

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email:
lukma at denx.de

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma at denx.de -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190730/121b39de/attachment.sig>

author reviewer
#5 lore raw

PATCH 1/16 clk: introduce clk_dev_binded

Hi Lukasz,

Quoted 17 lines

Subject: Re: [PATCH 01/16] clk: introduce clk_dev_binded

Hi Peng,

Quoted 13 lines

Hi Peng,

Quoted 6 lines

Hi Lukasz,

Quoted 1 line

Subject: [PATCH 01/16] clk: introduce clk_dev_binded

Do you have time to review the patchset? Patches were delegated to you.

The i.MX related PR (with base CCF) has been pulled to mainline just yesteday, so I'm going to rewiew and test your code on top of it (with buildman) today.

Quoted 5 lines
Quoted 2 lines

I shall send PR for -clk tomorrow.

The patches from this series causes the sandbox travis-ci to break:
https://travis-ci.org/lmajewski/u-boot-dfu/builds/565204559

I ran qcheck before posting patches.

Quoted 7 lines

Please fix those errors.

You can also reproduce this issue with:

./tools/buildman/buildman.py --branch=HEAD sandbox --show_errors --force-build --count=16 --output-dir=../BUILD/

I'll fix soon.

Thanks,
Peng.

Quoted 87 lines

run on this series.

Quoted 59 lines

Thanks for your patches.

Quoted 44 lines

Thanks,
Peng.

Quoted 40 lines

When support Clock Common Framework, U-Boot use dev for clk tree information, there is no clk->parent. When support composite clk, it contains mux/gate/divider, but the mux/gate/divider is not binded with device. So we could not use dev_get_uclass_priv to get the correct clk_mux/gate/divider. So add clk_dev_binded to let choose the correct method.

---
 drivers/clk/clk.c | 8 ++++++++
 include/clk.h     | 9 +++++++++
 2 files changed, 17 insertions(+)
drivers/clk/clk.c index renamed from drivers/clk/clk.c +0 -0

7d748c9fc7..39b3087067 100644

drivers/clk/clk.c +7 -0
@@ -55,3 +55,11 @@ const char *clk_hw_get_name(const struct clk
 *hw) {
 	return hw->dev->name;
 }
+
+bool clk_dev_binded(struct clk *clk) {
+	if (clk->dev && (clk->dev->flags & DM_FLAG_BOUND))
+		return true;
+
+	return false;
+}
include/clk.h index renamed from include/clk.h +0 -0

f8f56d9cf0..2ebc905e04 100644

include/clk.h +3 -0
@@ -356,4 +356,13 @@ static inline bool clk_valid(struct clk *clk)
  * @return zero on success, or -ENOENT on error
  */
 int clk_get_by_id(ulong id, struct clk **clkp);
+
+/**
+ * clk_dev_binded() - Check whether the clk has a device binded
Quoted 9 lines
Quoted 8 lines
include/clk.h +5 -1
+ *
+ * @clk		A pointer to the clk
+ *
+ * @return true on binded, or false on no  */ bool
+clk_dev_binded(struct clk *clk);
 #endif
--

2.16.4

Quoted 7 lines

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Wolfgang

Denk

Quoted 3 lines

HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email:
lukma at denx.de

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email:
lukma at denx.de

author reviewer
#6 lore raw

PATCH 1/16 clk: introduce clk_dev_binded

Hi Lukasz,

Quoted 22 lines

Subject: RE: [PATCH 01/16] clk: introduce clk_dev_binded

Hi Lukasz,

Quoted 18 lines

Subject: Re: [PATCH 01/16] clk: introduce clk_dev_binded

Hi Peng,

Quoted 14 lines

Hi Peng,

Quoted 6 lines

Hi Lukasz,

Quoted 1 line

Subject: [PATCH 01/16] clk: introduce clk_dev_binded

Do you have time to review the patchset? Patches were delegated to you.

The i.MX related PR (with base CCF) has been pulled to mainline just yesteday, so I'm going to rewiew and test your code on top of it (with
buildman) today.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

I shall send PR for -clk tomorrow.

The patches from this series causes the sandbox travis-ci to break:
https://travis-ci.org/lmajewski/u-boot-dfu/builds/565204559

I ran qcheck before posting patches.

Missed a build warning when ran qcheck.

It was divider_recalc_rate missed add to clk-provider.h. Just posted out v2.

Thanks,
Peng.

Quoted 103 lines
Quoted 8 lines

Please fix those errors.

You can also reproduce this issue with:

./tools/buildman/buildman.py --branch=HEAD sandbox --show_errors --force-build --count=16 --output-dir=../BUILD/

I'll fix soon.

Thanks,
Peng.

Quoted 78 lines

run on this series.

Quoted 59 lines

Thanks for your patches.

Quoted 44 lines

Thanks,
Peng.

Quoted 40 lines

When support Clock Common Framework, U-Boot use dev for clk tree information, there is no clk->parent. When support composite clk, it contains mux/gate/divider, but the mux/gate/divider is not binded with device. So we could not use dev_get_uclass_priv to get the correct clk_mux/gate/divider. So add clk_dev_binded to let choose the correct method.

---
 drivers/clk/clk.c | 8 ++++++++
 include/clk.h     | 9 +++++++++
 2 files changed, 17 insertions(+)
drivers/clk/clk.c index renamed from drivers/clk/clk.c +0 -0

7d748c9fc7..39b3087067 100644

drivers/clk/clk.c +7 -0
@@ -55,3 +55,11 @@ const char *clk_hw_get_name(const struct clk
 *hw) {
 	return hw->dev->name;
 }
+
+bool clk_dev_binded(struct clk *clk) {
+	if (clk->dev && (clk->dev->flags & DM_FLAG_BOUND))
+		return true;
+
+	return false;
+}
include/clk.h index renamed from include/clk.h +0 -0

f8f56d9cf0..2ebc905e04 100644

include/clk.h +3 -0
@@ -356,4 +356,13 @@ static inline bool clk_valid(struct clk *clk)
  * @return zero on success, or -ENOENT on error
  */
 int clk_get_by_id(ulong id, struct clk **clkp);
+
+/**
+ * clk_dev_binded() - Check whether the clk has a device binded
Quoted 9 lines
Quoted 8 lines
include/clk.h +5 -1
+ *
+ * @clk		A pointer to the clk
+ *
+ * @return true on binded, or false on no  */ bool
+clk_dev_binded(struct clk *clk);
 #endif
--

2.16.4

Quoted 7 lines

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Wolfgang

Denk

Quoted 4 lines

HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email:
lukma at denx.de

Quoted 7 lines

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Wolfgang

Denk

Quoted 3 lines

HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email:
lukma at denx.de

author reviewer
#7 lore raw

PATCH 2/16 clk: use clk_dev_binded

In reply to Peng Fan

Preparing to support composite clk.

---
 drivers/clk/clk-divider.c | 4 ++--
 drivers/clk/clk-mux.c     | 6 ++++--
 2 files changed, 6 insertions(+), 4 deletions(-)
drivers/clk/clk-divider.c +2 -2
index 6921c76a48..2ed9ed6ab8 100644
@@ -69,8 +69,8 @@ unsigned long divider_recalc_rate(struct clk *hw, unsigned long parent_rate,
 
 static ulong clk_divider_recalc_rate(struct clk *clk)
 {
-	struct clk_divider *divider =
-		to_clk_divider(dev_get_clk_ptr(clk->dev));
+	struct clk_divider *divider = to_clk_divider(clk_dev_binded(clk) ?
+			dev_get_clk_ptr(clk->dev) : clk);
 	unsigned long parent_rate = clk_get_parent_rate(clk);
 	unsigned int val;
 
drivers/clk/clk-mux.c +4 -2
index 3c075aa09e..81d1e7ebee 100644
@@ -35,7 +35,8 @@
 int clk_mux_val_to_index(struct clk *clk, u32 *table, unsigned int flags,
 			 unsigned int val)
 {
-	struct clk_mux *mux = to_clk_mux(clk);
+	struct clk_mux *mux = to_clk_mux(clk_dev_binded(clk) ?
+			dev_get_clk_ptr(clk->dev) : clk);
 	int num_parents = mux->num_parents;
 
 	if (table) {
@@ -61,7 +62,8 @@ int clk_mux_val_to_index(struct clk *clk, u32 *table, unsigned int flags,
 
 static u8 clk_mux_get_parent(struct clk *clk)
 {
-	struct clk_mux *mux = to_clk_mux(clk);
+	struct clk_mux *mux = to_clk_mux(clk_dev_binded(clk) ?
+			dev_get_clk_ptr(clk->dev) : clk);
 	u32 val;
 
 #if CONFIG_IS_ENABLED(SANDBOX_CLK_CCF)
Signature · 1 line
2.16.4
author reviewer
#8 lore raw

PATCH 3/16 clk: mux: add set parent support

In reply to Peng Fan

Add set parent support for clk mux

---
 drivers/clk/clk-mux.c        | 70 ++++++++++++++++++++++++++++++++++++++++++--
 include/linux/clk-provider.h |  2 ++
 2 files changed, 70 insertions(+), 2 deletions(-)
drivers/clk/clk-mux.c +68 -2
index 81d1e7ebee..5acc0b8cbd 100644
@@ -60,7 +60,24 @@ int clk_mux_val_to_index(struct clk *clk, u32 *table, unsigned int flags,
 	return val;
 }
 
-static u8 clk_mux_get_parent(struct clk *clk)
+unsigned int clk_mux_index_to_val(u32 *table, unsigned int flags, u8 index)
+{
+	unsigned int val = index;
+
+	if (table) {
+		val = table[index];
+	} else {
+		if (flags & CLK_MUX_INDEX_BIT)
+			val = 1 << index;
+
+		if (flags & CLK_MUX_INDEX_ONE)
+			val++;
+	}
+
+	return val;
+}
+
+u8 clk_mux_get_parent(struct clk *clk)
 {
 	struct clk_mux *mux = to_clk_mux(clk_dev_binded(clk) ?
 			dev_get_clk_ptr(clk->dev) : clk);
@@ -77,8 +94,57 @@ static u8 clk_mux_get_parent(struct clk *clk)
 	return clk_mux_val_to_index(clk, mux->table, mux->flags, val);
 }
 
+static int clk_fetch_parent_index(struct clk *clk,
+				  struct clk *parent)
+{
+	struct clk_mux *mux = to_clk_mux(clk_dev_binded(clk) ?
+			dev_get_clk_ptr(clk->dev) : clk);
+
+	int i;
+
+	if (!parent)
+		return -EINVAL;
+
+	for (i = 0; i < mux->num_parents; i++) {
+		if (!strcmp(parent->dev->name, mux->parent_names[i]))
+			return i;
+	}
+
+	return -EINVAL;
+}
+
+static int clk_mux_set_parent(struct clk *clk, struct clk *parent)
+{
+	struct clk_mux *mux = to_clk_mux(clk_dev_binded(clk) ?
+			dev_get_clk_ptr(clk->dev) : clk);
+	int index;
+	u32 val;
+	u32 reg;
+
+	index = clk_fetch_parent_index(clk, parent);
+	if (index < 0) {
+		printf("Could not fetch index\n");
+		return index;
+	}
+
+	val = clk_mux_index_to_val(mux->table, mux->flags, index);
+
+	if (mux->flags & CLK_MUX_HIWORD_MASK) {
+		reg = mux->mask << (mux->shift + 16);
+	} else {
+		reg = readl(mux->reg);
+		reg &= ~(mux->mask << mux->shift);
+	}
+	val = val << mux->shift;
+	reg |= val;
+	writel(reg, mux->reg);
+
+	return 0;
+}
+
 const struct clk_ops clk_mux_ops = {
-		.get_rate = clk_generic_get_rate,
+	.get_rate = clk_generic_get_rate,
+	.set_parent = clk_mux_set_parent,
 };
 
 struct clk *clk_hw_register_mux_table(struct device *dev, const char *name,
include/linux/clk-provider.h +2 -0
index 43a25e9c6a..7e44045c16 100644
@@ -66,6 +66,8 @@ struct clk_mux {
 };
 
 #define to_clk_mux(_clk) container_of(_clk, struct clk_mux, clk)
+extern const struct clk_ops clk_mux_ops;
+u8 clk_mux_get_parent(struct clk *clk);
 
 struct clk_div_table {
 	unsigned int	val;
Signature · 1 line
2.16.4
author reviewer
#9 lore raw

PATCH 4/16 clk: export mux/divider ops

In reply to Peng Fan

Export mux/divider ops for composite usage

---
 include/linux/clk-provider.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/clk-provider.h +1 -0
index 7e44045c16..6c6475ea91 100644
@@ -96,6 +96,7 @@ struct clk_divider {
 #define CLK_DIVIDER_ROUND_CLOSEST	BIT(4)
 #define CLK_DIVIDER_READ_ONLY		BIT(5)
 #define CLK_DIVIDER_MAX_AT_ZERO		BIT(6)
+extern const struct clk_ops clk_divider_ops;
 
 struct clk_fixed_factor {
 	struct clk	clk;
Signature · 1 line
2.16.4
author reviewer
#10 lore raw

PATCH 5/16 clk: add clk-gate support

In reply to Peng Fan

Import clk-gate support from Linux Kernel 5.1-rc5

---
 drivers/clk/Makefile         |   2 +-
 drivers/clk/clk-gate.c       | 148 +++++++++++++++++++++++++++++++++++++++++++
 include/linux/clk-provider.h |  18 ++++++
 3 files changed, 167 insertions(+), 1 deletion(-)
 create mode 100644 drivers/clk/clk-gate.c
drivers/clk/Makefile +1 -1
index 37dfd281e9..a17ba6deae 100644
@@ -7,7 +7,7 @@
 obj-$(CONFIG_$(SPL_TPL_)CLK) += clk-uclass.o
 obj-$(CONFIG_$(SPL_TPL_)CLK) += clk_fixed_rate.o
 obj-$(CONFIG_$(SPL_TPL_)CLK) += clk_fixed_factor.o
-obj-$(CONFIG_$(SPL_TPL_)CLK_CCF) += clk.o clk-divider.o clk-mux.o
+obj-$(CONFIG_$(SPL_TPL_)CLK_CCF) += clk.o clk-divider.o clk-mux.o clk-gate.o
 obj-$(CONFIG_$(SPL_TPL_)CLK_CCF) += clk-fixed-factor.o
 
 obj-y += imx/
drivers/clk/clk-gate.c new file +148 -0

148 lines not on this page · raw message

include/linux/clk-provider.h +18 -0
index 6c6475ea91..b9568502a1 100644
@@ -69,6 +69,24 @@ struct clk_mux {
 extern const struct clk_ops clk_mux_ops;
 u8 clk_mux_get_parent(struct clk *clk);
 
+struct clk_gate {
+	struct clk	clk;
+	void __iomem	*reg;
+	u8		bit_idx;
+	u8		flags;
+};
+
+#define to_clk_gate(_clk) container_of(_clk, struct clk_gate, clk)
+
+#define CLK_GATE_SET_TO_DISABLE		BIT(0)
+#define CLK_GATE_HIWORD_MASK		BIT(1)
+
+extern const struct clk_ops clk_gate_ops;
+struct clk *clk_register_gate(struct device *dev, const char *name,
+			      const char *parent_name, unsigned long flags,
+			      void __iomem *reg, u8 bit_idx,
+			      u8 clk_gate_flags, spinlock_t *lock);
+
 struct clk_div_table {
 	unsigned int	val;
 	unsigned int	div;
Signature · 1 line
2.16.4
author reviewer
#11 lore raw

PATCH 6/16 clk: divider set rate supporrt

In reply to Peng Fan
---
 drivers/clk/clk-divider.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 88 insertions(+)
drivers/clk/clk-divider.c +88 -0
index 2ed9ed6ab8..822e09b084 100644
@@ -18,6 +18,7 @@
 #include <dm/lists.h>
 #include <dm/device-internal.h>
 #include <linux/clk-provider.h>
+#include <linux/log2.h>
 #include <div64.h>
 #include <clk.h>
 #include "clk.h"
@@ -86,8 +87,95 @@ static ulong clk_divider_recalc_rate(struct clk *clk)
 				   divider->flags, divider->width);
 }
 
+static bool _is_valid_table_div(const struct clk_div_table *table,
+				unsigned int div)
+{
+	const struct clk_div_table *clkt;
+
+	for (clkt = table; clkt->div; clkt++)
+		if (clkt->div == div)
+			return true;
+	return false;
+}
+
+static bool _is_valid_div(const struct clk_div_table *table, unsigned int div,
+			  unsigned long flags)
+{
+	if (flags & CLK_DIVIDER_POWER_OF_TWO)
+		return is_power_of_2(div);
+	if (table)
+		return _is_valid_table_div(table, div);
+	return true;
+}
+
+static unsigned int _get_table_val(const struct clk_div_table *table,
+				   unsigned int div)
+{
+	const struct clk_div_table *clkt;
+
+	for (clkt = table; clkt->div; clkt++)
+		if (clkt->div == div)
+			return clkt->val;
+	return 0;
+}
+
+static unsigned int _get_val(const struct clk_div_table *table,
+			     unsigned int div, unsigned long flags, u8 width)
+{
+	if (flags & CLK_DIVIDER_ONE_BASED)
+		return div;
+	if (flags & CLK_DIVIDER_POWER_OF_TWO)
+		return __ffs(div);
+	if (flags & CLK_DIVIDER_MAX_AT_ZERO)
+		return (div == clk_div_mask(width) + 1) ? 0 : div;
+	if (table)
+		return  _get_table_val(table, div);
+	return div - 1;
+}
+int divider_get_val(unsigned long rate, unsigned long parent_rate,
+		    const struct clk_div_table *table, u8 width,
+		    unsigned long flags)
+{
+	unsigned int div, value;
+
+	div = DIV_ROUND_UP_ULL((u64)parent_rate, rate);
+
+	if (!_is_valid_div(table, div, flags))
+		return -EINVAL;
+
+	value = _get_val(table, div, flags, width);
+
+	return min_t(unsigned int, value, clk_div_mask(width));
+}
+
+static ulong clk_divider_set_rate(struct clk *clk, unsigned long rate)
+{
+	struct clk_divider *divider = to_clk_divider(clk_dev_binded(clk) ?
+			dev_get_clk_ptr(clk->dev) : clk);
+	unsigned long parent_rate = clk_get_parent_rate(clk);
+	int value;
+	u32 val;
+
+	value = divider_get_val(rate, parent_rate, divider->table,
+				divider->width, divider->flags);
+	if (value < 0)
+		return value;
+
+	if (divider->flags & CLK_DIVIDER_HIWORD_MASK) {
+		val = clk_div_mask(divider->width) << (divider->shift + 16);
+	} else {
+		val = readl(divider->reg);
+		val &= ~(clk_div_mask(divider->width) << divider->shift);
+	}
+	val |= (u32)value << divider->shift;
+	writel(val, divider->reg);
+
+	return clk_get_rate(clk);
+}
+
 const struct clk_ops clk_divider_ops = {
 	.get_rate = clk_divider_recalc_rate,
+	.set_rate = clk_divider_set_rate,
 };
 
 static struct clk *_register_divider(struct device *dev, const char *name,
Signature · 1 line
2.16.4
author reviewer
#12 lore raw

PATCH 7/16 clk: fixed_rate: export clk_fixed_rate

In reply to Peng Fan

Export the structure for others to use.

---
 drivers/clk/clk_fixed_rate.c | 8 +-------
 include/linux/clk-provider.h | 7 +++++++
 2 files changed, 8 insertions(+), 7 deletions(-)
drivers/clk/clk_fixed_rate.c +1 -7
index 1fdf8c4e54..08cce0d79b 100644
@@ -6,13 +6,7 @@
 #include <common.h>
 #include <clk-uclass.h>
 #include <dm.h>
-
-struct clk_fixed_rate {
-	struct clk clk;
-	unsigned long fixed_rate;
-};
-
-#define to_clk_fixed_rate(dev)	((struct clk_fixed_rate *)dev_get_platdata(dev))
+#include <linux/clk-provider.h>
 
 static ulong clk_fixed_rate_get_rate(struct clk *clk)
 {
include/linux/clk-provider.h +7 -0
index b9568502a1..8b790cb666 100644
@@ -125,6 +125,13 @@ struct clk_fixed_factor {
 #define to_clk_fixed_factor(_clk) container_of(_clk, struct clk_fixed_factor,\
 					       clk)
 
+struct clk_fixed_rate {
+	struct clk clk;
+	unsigned long fixed_rate;
+};
+
+#define to_clk_fixed_rate(dev)	((struct clk_fixed_rate *)dev_get_platdata(dev))
+
 int clk_register(struct clk *clk, const char *drv_name, const char *name,
 		 const char *parent_name);
 
Signature · 1 line
2.16.4
author reviewer
#13 lore raw

PATCH 8/16 clk: imx: import clk heplers

In reply to Peng Fan

Import some clk helpers from Linux Kernel for i.MX8MM usage

---
 drivers/clk/imx/clk.h | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 81 insertions(+)
drivers/clk/imx/clk.h +81 -0
index e6d51830e8..1d480d8722 100644
@@ -36,6 +36,23 @@ static inline struct clk *imx_clk_gate2(const char *name, const char *parent,
 			shift, 0x3, 0);
 }
 
+static inline struct clk *imx_clk_gate4(const char *name, const char *parent,
+		void __iomem *reg, u8 shift)
+{
+	return clk_register_gate2(NULL, name, parent,
+			CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
+			reg, shift, 0x3, 0);
+}
+
+static inline struct clk *imx_clk_gate4_flags(const char *name,
+		const char *parent, void __iomem *reg, u8 shift,
+		unsigned long flags)
+{
+	return clk_register_gate2(NULL, name, parent,
+			flags | CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
+			reg, shift, 0x3, 0);
+}
+
 static inline struct clk *imx_clk_fixed_factor(const char *name,
 		const char *parent, unsigned int mult, unsigned int div)
 {
@@ -50,6 +67,14 @@ static inline struct clk *imx_clk_divider(const char *name, const char *parent,
 			reg, shift, width, 0);
 }
 
+static inline struct clk *imx_clk_divider2(const char *name, const char *parent,
+		void __iomem *reg, u8 shift, u8 width)
+{
+	return clk_register_divider(NULL, name, parent,
+			CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
+			reg, shift, width, 0);
+}
+
 struct clk *imx_clk_pfd(const char *name, const char *parent_name,
 			void __iomem *reg, u8 idx);
 
@@ -57,6 +82,16 @@ struct clk *imx_clk_fixup_mux(const char *name, void __iomem *reg,
 			      u8 shift, u8 width, const char * const *parents,
 			      int num_parents, void (*fixup)(u32 *val));
 
+static inline struct clk *imx_clk_mux_flags(const char *name,
+			void __iomem *reg, u8 shift, u8 width,
+			const char * const *parents, int num_parents,
+			unsigned long flags)
+{
+	return clk_register_mux(NULL, name, parents, num_parents,
+				flags | CLK_SET_RATE_NO_REPARENT, reg, shift,
+				width, 0);
+}
+
 static inline struct clk *imx_clk_mux(const char *name, void __iomem *reg,
 			u8 shift, u8 width, const char * const *parents,
 			int num_parents)
@@ -66,4 +101,50 @@ static inline struct clk *imx_clk_mux(const char *name, void __iomem *reg,
 			width, 0);
 }
 
+static inline struct clk *imx_clk_mux2(const char *name, void __iomem *reg,
+			u8 shift, u8 width, const char * const *parents,
+			int num_parents)
+{
+	return clk_register_mux(NULL, name, parents, num_parents,
+			CLK_SET_RATE_NO_REPARENT | CLK_OPS_PARENT_ENABLE,
+			reg, shift, width, 0);
+}
+
+static inline struct clk *imx_clk_gate(const char *name, const char *parent,
+		void __iomem *reg, u8 shift)
+{
+	return clk_register_gate(NULL, name, parent, CLK_SET_RATE_PARENT, reg,
+			shift, 0, NULL);
+}
+
+static inline struct clk *imx_clk_gate_flags(const char *name, const char *parent,
+		void __iomem *reg, u8 shift, unsigned long flags)
+{
+	return clk_register_gate(NULL, name, parent, flags | CLK_SET_RATE_PARENT, reg,
+			shift, 0, NULL);
+}
+
+static inline struct clk *imx_clk_gate3(const char *name, const char *parent,
+		void __iomem *reg, u8 shift)
+{
+	return clk_register_gate(NULL, name, parent,
+			CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
+			reg, shift, 0, NULL);
+}
+
+struct clk *imx8m_clk_composite_flags(const char *name,
+		const char * const *parent_names,
+		int num_parents, void __iomem *reg, unsigned long flags);
+
+#define __imx8m_clk_composite(name, parent_names, reg, flags) \
+	imx8m_clk_composite_flags(name, parent_names, \
+		ARRAY_SIZE(parent_names), reg, \
+		flags | CLK_SET_RATE_NO_REPARENT | CLK_OPS_PARENT_ENABLE)
+
+#define imx8m_clk_composite(name, parent_names, reg) \
+	__imx8m_clk_composite(name, parent_names, reg, 0)
+
+#define imx8m_clk_composite_critical(name, parent_names, reg) \
+	__imx8m_clk_composite(name, parent_names, reg, CLK_IS_CRITICAL)
+
 #endif /* __MACH_IMX_CLK_H */
Signature · 1 line
2.16.4
author reviewer
#14 lore raw

PATCH 9/16 clk: imx: gate2 add set rate

In reply to Peng Fan

Add set rate for imx clk-gate2

---
 drivers/clk/imx/clk-gate2.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/clk/imx/clk-gate2.c +11 -0
index 571be32088..1b9db6e791 100644
@@ -60,7 +60,18 @@ static int clk_gate2_disable(struct clk *clk)
 	return 0;
 }
 
+static ulong clk_gate2_set_rate(struct clk *clk, ulong rate)
+{
+	struct clk *parent = clk_get_parent(clk);
+
+	if (parent)
+		return clk_set_rate(parent, rate);
+
+	return -ENODEV;
+}
+
 static const struct clk_ops clk_gate2_ops = {
+	.set_rate = clk_gate2_set_rate,
 	.enable = clk_gate2_enable,
 	.disable = clk_gate2_disable,
 	.get_rate = clk_generic_get_rate,
Signature · 1 line
2.16.4
author reviewer
#15 lore raw

PATCH 10/16 dm: clk: ignore default settings when node not valid

In reply to Peng Fan

When the device not binded with a node, we need ignore the parents and rate settings.

Cc Simon Glass <[email protected]>
Cc Jagan Teki <[email protected]>
Cc Philipp Tomsich <[email protected]>
Cc Neil Armstrong <[email protected]>
Cc Andreas Dannenberg <[email protected]>
---
 drivers/clk/clk-uclass.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/clk/clk-uclass.c +3 -0
index 5acf186b01..39c6a97caa 100644
@@ -283,6 +283,9 @@ int clk_set_defaults(struct udevice *dev)
 {
 	int ret;
 
+	if (!dev_of_valid(dev))
+		return 0;
+
 	/* If this not in SPL and pre-reloc state, don't take any action. */
 	if (!(IS_ENABLED(CONFIG_SPL_BUILD) || (gd->flags & GD_FLG_RELOC)))
 		return 0;
Signature · 1 line
2.16.4
author reviewer
#16 lore raw

PATCH 11/16 clk: add composite clk support

In reply to Peng Fan

Import clk composite clk support from Linux Kernel 5.1-rc5

---
 drivers/clk/Kconfig          |  14 ++++
 drivers/clk/Makefile         |   1 +
 drivers/clk/clk-composite.c  | 160 +++++++++++++++++++++++++++++++++++++++++++
 include/linux/clk-provider.h |  22 ++++++
 4 files changed, 197 insertions(+)
 create mode 100644 drivers/clk/clk-composite.c
drivers/clk/Kconfig +14 -0
index 9399bb79e9..0138473ac7 100644
@@ -53,6 +53,13 @@ config SPL_CLK_CCF
 	  Enable this option if you want to (re-)use the Linux kernel's Common
 	  Clock Framework [CCF] code in U-Boot's SPL.
 
+config SPL_CLK_COMPOSITE_CCF
+	bool "SPL Common Clock Framework [CCF] composite clk support "
+	depends on SPL_CLK_CCF
+	help
+	  Enable this option if you want to (re-)use the Linux kernel's Common
+	  Clock Framework [CCF] composite code in U-Boot's SPL.
+
 config CLK_CCF
 	bool "Common Clock Framework [CCF] support "
 	depends on CLK_IMX6Q || SANDBOX_CLK_CCF
@@ -60,6 +67,13 @@ config CLK_CCF
 	  Enable this option if you want to (re-)use the Linux kernel's Common
 	  Clock Framework [CCF] code in U-Boot's clock driver.
 
+config CLK_COMPOSITE_CCF
+	bool "Common Clock Framework [CCF] composite clk support "
+	depends on CLK_CCF
+	help
+	  Enable this option if you want to (re-)use the Linux kernel's Common
+	  Clock Framework [CCF] composite code in U-Boot's clock driver.
+
 config CLK_STM32F
 	bool "Enable clock driver support for STM32F family"
 	depends on CLK && (STM32F7 || STM32F4)
drivers/clk/Makefile +1 -0
index a17ba6deae..681372639d 100644
@@ -9,6 +9,7 @@ obj-$(CONFIG_$(SPL_TPL_)CLK) += clk_fixed_rate.o
 obj-$(CONFIG_$(SPL_TPL_)CLK) += clk_fixed_factor.o
 obj-$(CONFIG_$(SPL_TPL_)CLK_CCF) += clk.o clk-divider.o clk-mux.o clk-gate.o
 obj-$(CONFIG_$(SPL_TPL_)CLK_CCF) += clk-fixed-factor.o
+obj-$(CONFIG_$(SPL_TPL_)CLK_COMPOSITE_CCF) += clk-composite.o
 
 obj-y += imx/
 obj-y += tegra/
drivers/clk/clk-composite.c new file +160 -0

160 lines not on this page · raw message

include/linux/clk-provider.h +22 -0
index 8b790cb666..9c292f555d 100644
@@ -132,6 +132,28 @@ struct clk_fixed_rate {
 
 #define to_clk_fixed_rate(dev)	((struct clk_fixed_rate *)dev_get_platdata(dev))
 
+struct clk_composite {
+	struct clk	clk;
+	struct clk_ops	ops;
+
+	struct clk	*mux;
+	struct clk	*rate;
+	struct clk	*gate;
+
+	const struct clk_ops	*mux_ops;
+	const struct clk_ops	*rate_ops;
+	const struct clk_ops	*gate_ops;
+};
+
+#define to_clk_composite(_clk) container_of(_clk, struct clk_composite, clk)
+
+struct clk *clk_register_composite(struct device *dev, const char *name,
+		const char * const *parent_names, int num_parents,
+		struct clk *mux_clk, const struct clk_ops *mux_ops,
+		struct clk *rate_clk, const struct clk_ops *rate_ops,
+		struct clk *gate_clk, const struct clk_ops *gate_ops,
+		unsigned long flags);
+
 int clk_register(struct clk *clk, const char *drv_name, const char *name,
 		 const char *parent_name);
 
Signature · 1 line
2.16.4
author reviewer
#17 lore raw

PATCH 12/16 clk-provider: include clk-uclass.h

In reply to Peng Fan

Because clk-provider use clk_ops, so let's include clk-uclass.h

---
 include/linux/clk-provider.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/clk-provider.h +1 -0
index 9c292f555d..32a777d86c 100644
@@ -8,6 +8,7 @@
  */
 #ifndef __LINUX_CLK_PROVIDER_H
 #define __LINUX_CLK_PROVIDER_H
+#include <clk-uclass.h>
 
 static inline void clk_dm(ulong id, struct clk *clk)
 {
Signature · 1 line
2.16.4
author reviewer
#18 lore raw

PATCH 13/16 clk: gate: support sandbox

In reply to Peng Fan

Introduce io_gate_val for sandbox clk gate test usage

---
 drivers/clk/clk-gate.c       | 11 +++++++++++
 include/linux/clk-provider.h |  3 +++
 2 files changed, 14 insertions(+)
drivers/clk/clk-gate.c +11 -0
index a3a1fdd3b2..70b8794554 100644
@@ -55,7 +55,11 @@ static void clk_gate_endisable(struct clk *clk, int enable)
 		if (set)
 			reg |= BIT(gate->bit_idx);
 	} else {
+#if CONFIG_IS_ENABLED(SANDBOX_CLK_CCF)
+		reg = gate->io_gate_val;
+#else
 		reg = readl(gate->reg);
+#endif
 
 		if (set)
 			reg |= BIT(gate->bit_idx);
@@ -86,7 +90,11 @@ int clk_gate_is_enabled(struct clk *clk)
 			dev_get_clk_ptr(clk->dev) : clk);
 	u32 reg;
 
+#if CONFIG_IS_ENABLED(SANDBOX_CLK_CCF)
+	reg = gate->io_gate_val;
+#else
 	reg = readl(gate->reg);
+#endif
 
 	/* if a set bit disables this clk, flip it before masking */
 	if (gate->flags & CLK_GATE_SET_TO_DISABLE)
@@ -128,6 +136,9 @@ struct clk *clk_register_gate(struct device *dev, const char *name,
 	gate->reg = reg;
 	gate->bit_idx = bit_idx;
 	gate->flags = clk_gate_flags;
+#if CONFIG_IS_ENABLED(SANDBOX_CLK_CCF)
+	gate->io_gate_val = *(u32 *)reg;
+#endif
 
 	clk = &gate->clk;
 
include/linux/clk-provider.h +3 -0
index 32a777d86c..1e8183207d 100644
@@ -75,6 +75,9 @@ struct clk_gate {
 	void __iomem	*reg;
 	u8		bit_idx;
 	u8		flags;
+#if CONFIG_IS_ENABLED(SANDBOX_CLK_CCF)
+	u32		io_gate_val;
+#endif
 };
 
 #define to_clk_gate(_clk) container_of(_clk, struct clk_gate, clk)
Signature · 1 line
2.16.4
author reviewer
#19 lore raw

PATCH 14/16 clk: sandbox: add composite clk

In reply to Peng Fan

Add composite clk to sandbox driver

---
 drivers/clk/clk_sandbox_ccf.c | 80 +++++++++++++++++++++++++++++++++++++++++++
 include/sandbox-clk.h         |  1 +
 2 files changed, 81 insertions(+)
drivers/clk/clk_sandbox_ccf.c +80 -0
index edeb0f2cf3..e126f18d8e 100644
@@ -130,6 +130,80 @@ U_BOOT_DRIVER(sandbox_clk_gate2) = {
 	.ops	= &clk_gate2_ops,
 };
 
+static unsigned long sandbox_clk_composite_divider_recalc_rate(struct clk *clk)
+{
+	struct clk_divider *divider = (struct clk_divider *)to_clk_divider(clk);
+	struct clk_composite *composite = (struct clk_composite *)clk->data;
+	ulong parent_rate = clk_get_parent_rate(&composite->clk);
+	unsigned int val;
+
+	val = divider->io_divider_val;
+	val >>= divider->shift;
+	val &= clk_div_mask(divider->width);
+
+	return divider_recalc_rate(clk, parent_rate, val, divider->table,
+				   divider->flags, divider->width);
+}
+
+static const struct clk_ops sandbox_clk_composite_divider_ops = {
+	.get_rate = sandbox_clk_composite_divider_recalc_rate,
+};
+
+struct clk *sandbox_clk_composite(const char *name,
+				  const char * const *parent_names,
+				  int num_parents, void __iomem *reg,
+				  unsigned long flags)
+{
+	struct clk *clk = ERR_PTR(-ENOMEM);
+	struct clk_divider *div = NULL;
+	struct clk_gate *gate = NULL;
+	struct clk_mux *mux = NULL;
+
+	mux = kzalloc(sizeof(*mux), GFP_KERNEL);
+	if (!mux)
+		goto fail;
+
+	mux->reg = reg;
+	mux->shift = 24;
+	mux->mask = 0x7;
+	mux->num_parents = num_parents;
+	mux->flags = flags;
+	mux->parent_names = parent_names;
+
+	div = kzalloc(sizeof(*div), GFP_KERNEL);
+	if (!div)
+		goto fail;
+
+	div->reg = reg;
+	div->shift = 16;
+	div->width = 3;
+	div->flags = CLK_DIVIDER_ROUND_CLOSEST | flags;
+
+	gate = kzalloc(sizeof(*gate), GFP_KERNEL);
+	if (!gate)
+		goto fail;
+
+	gate->reg = reg;
+	gate->bit_idx = 28;
+	gate->flags = flags;
+
+	clk = clk_register_composite(NULL, name,
+				     parent_names, num_parents,
+				     &mux->clk, &clk_mux_ops, &div->clk,
+				     &sandbox_clk_composite_divider_ops,
+				     &gate->clk, &clk_gate_ops, flags);
+	if (IS_ERR(clk))
+		goto fail;
+
+	return clk;
+
+fail:
+	kfree(gate);
+	kfree(div);
+	kfree(mux);
+	return ERR_CAST(clk);
+}
+
 /* --- Sandbox Gate --- */
 /* The CCF core driver itself */
 static const struct udevice_id sandbox_clk_ccf_test_ids[] = {
@@ -138,6 +212,7 @@ static const struct udevice_id sandbox_clk_ccf_test_ids[] = {
 };
 
 static const char *const usdhc_sels[] = { "pll3_60m", "pll3_80m", };
+static const char *const i2c_sels[] = { "pll3_60m", "pll3_80m", };
 
 static int sandbox_clk_ccf_probe(struct udevice *dev)
 {
@@ -174,6 +249,11 @@ static int sandbox_clk_ccf_probe(struct udevice *dev)
 	       sandbox_clk_mux("usdhc2_sel", &reg, 17, 1, usdhc_sels,
 			       ARRAY_SIZE(usdhc_sels)));
 
+	reg = BIT(28) | BIT(24) | BIT(16);
+	clk_dm(SANDBOX_CLK_I2C,
+	       sandbox_clk_composite("i2c", i2c_sels, ARRAY_SIZE(i2c_sels),
+				     &reg, 0));
+
 	return 0;
 }
 
include/sandbox-clk.h +1 -0
index 37c9838f76..f449de1364 100644
@@ -19,6 +19,7 @@ enum {
 	SANDBOX_CLK_ECSPI1,
 	SANDBOX_CLK_USDHC1_SEL,
 	SANDBOX_CLK_USDHC2_SEL,
+	SANDBOX_CLK_I2C,
 };
 
 enum sandbox_pllv3_type {
Signature · 1 line
2.16.4
author reviewer
#20 lore raw

PATCH 15/16 test: dm: clk_ccf: test composite clk

In reply to Peng Fan

Test composite clk with dm ccf

---
 test/dm/clk_ccf.c | 8 ++++++++
 1 file changed, 8 insertions(+)
test/dm/clk_ccf.c +8 -0
index 8d397593a3..bbc4b500e8 100644
@@ -56,6 +56,14 @@ static int dm_test_clk_ccf(struct unit_test_state *uts)
 	pclk = clk_get_parent(clk);
 	ut_asserteq_str("pll3_80m", pclk->dev->name);
 
+	/* Test the composite of CCF */
+	ret = clk_get_by_id(SANDBOX_CLK_I2C, &clk);
+	ut_assertok(ret);
+	ut_asserteq_str("i2c", clk->dev->name);
+
+	rate = clk_get_rate(clk);
+	ut_asserteq(rate, 60000000);
+
 	return 1;
 }
 
Signature · 1 line
2.16.4
author reviewer
#21 lore raw

PATCH 16/16 configs: sandbox: Enable composite clk

In reply to Peng Fan

Enable composite clk for sandbox test

---
 configs/sandbox_defconfig          | 1 +
 configs/sandbox_flattree_defconfig | 1 +
 2 files changed, 2 insertions(+)
configs/sandbox_defconfig +1 -0
index f9c9b19b6d..402c6d4e19 100644
@@ -91,6 +91,7 @@ CONFIG_BOOTCOUNT_LIMIT=y
 CONFIG_DM_BOOTCOUNT=y
 CONFIG_DM_BOOTCOUNT_RTC=y
 CONFIG_CLK=y
+CONFIG_CLK_COMPOSITE_CCF=y
 CONFIG_SANDBOX_CLK_CCF=y
 CONFIG_CPU=y
 CONFIG_DM_DEMO=y
configs/sandbox_flattree_defconfig +1 -0
index 2429ae4621..610457e0aa 100644
@@ -66,6 +66,7 @@ CONFIG_DEBUG_DEVRES=y
 CONFIG_ADC=y
 CONFIG_ADC_SANDBOX=y
 CONFIG_CLK=y
+CONFIG_CLK_COMPOSITE_CCF=y
 CONFIG_SANDBOX_CLK_CCF=y
 CONFIG_CPU=y
 CONFIG_DM_DEMO=y
Signature · 1 line
2.16.4