All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peng Fan <peng.fan@nxp.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 03/16] clk: mux: add set parent support
Date: Tue, 23 Jul 2019 03:15:16 +0000	[thread overview]
Message-ID: <20190723033031.12404-3-peng.fan@nxp.com> (raw)
In-Reply-To: <20190723033031.12404-1-peng.fan@nxp.com>

Add set parent support for clk mux

Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 drivers/clk/clk-mux.c        | 70 ++++++++++++++++++++++++++++++++++++++++++--
 include/linux/clk-provider.h |  2 ++
 2 files changed, 70 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/clk-mux.c b/drivers/clk/clk-mux.c
index 81d1e7ebee..5acc0b8cbd 100644
--- a/drivers/clk/clk-mux.c
+++ b/drivers/clk/clk-mux.c
@@ -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,
diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
index 43a25e9c6a..7e44045c16 100644
--- a/include/linux/clk-provider.h
+++ b/include/linux/clk-provider.h
@@ -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;
-- 
2.16.4

  parent reply	other threads:[~2019-07-23  3:15 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-23  3:15 [U-Boot] [PATCH 01/16] clk: introduce clk_dev_binded Peng Fan
2019-07-23  3:15 ` [U-Boot] [PATCH 02/16] clk: use clk_dev_binded Peng Fan
2019-07-23  3:15 ` Peng Fan [this message]
2019-07-23  3:15 ` [U-Boot] [PATCH 04/16] clk: export mux/divider ops Peng Fan
2019-07-23  3:15 ` [U-Boot] [PATCH 05/16] clk: add clk-gate support Peng Fan
2019-07-23  3:15 ` [U-Boot] [PATCH 06/16] clk: divider set rate supporrt Peng Fan
2019-07-23  3:15 ` [U-Boot] [PATCH 07/16] clk: fixed_rate: export clk_fixed_rate Peng Fan
2019-07-23  3:15 ` [U-Boot] [PATCH 08/16] clk: imx: import clk heplers Peng Fan
2019-07-23  3:15 ` [U-Boot] [PATCH 09/16] clk: imx: gate2 add set rate Peng Fan
2019-07-23  3:15 ` [U-Boot] [PATCH 10/16] dm: clk: ignore default settings when node not valid Peng Fan
2019-07-23  3:15 ` [U-Boot] [PATCH 11/16] clk: add composite clk support Peng Fan
2019-07-23  3:15 ` [U-Boot] [PATCH 12/16] clk-provider: include clk-uclass.h Peng Fan
2019-07-23  3:15 ` [U-Boot] [PATCH 13/16] clk: gate: support sandbox Peng Fan
2019-07-23  3:15 ` [U-Boot] [PATCH 14/16] clk: sandbox: add composite clk Peng Fan
2019-07-23  3:15 ` [U-Boot] [PATCH 15/16] test: dm: clk_ccf: test " Peng Fan
2019-07-23  3:15 ` [U-Boot] [PATCH 16/16] configs: sandbox: Enable " Peng Fan
2019-07-29  8:31 ` [U-Boot] [PATCH 01/16] clk: introduce clk_dev_binded Peng Fan
2019-07-29  8:57   ` Lukasz Majewski
2019-07-29  8:59     ` Peng Fan
2019-07-30  6:58     ` Lukasz Majewski
2019-07-30  7:01       ` Peng Fan
2019-07-30  7:54         ` Peng Fan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190723033031.12404-3-peng.fan@nxp.com \
    --to=peng.fan@nxp.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.