All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lukasz Majewski <lukma@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3 08/11] dm: clk: Define clk_get_by_id() for clk operations
Date: Thu, 25 Apr 2019 12:29:50 +0200	[thread overview]
Message-ID: <20190425102953.5348-9-lukma@denx.de> (raw)
In-Reply-To: <20190425102953.5348-1-lukma@denx.de>

This commit adds the clk_get_by_id() function, which is responsible
for getting the udevice with matching clk->id. Such approach allows
re-usage of inherit DM list relationship for the same class (UCLASS_CLK).
As a result - we don't need any other external list - it is just enough
to look for UCLASS_CLK related udevices.

Signed-off-by: Lukasz Majewski <lukma@denx.de>

---

Changes in v3:
- Replace -ENODEV with -ENOENT
- Use **clkp instead of **c

 drivers/clk/clk-uclass.c | 22 ++++++++++++++++++++++
 include/clk.h            | 11 +++++++++++
 2 files changed, 33 insertions(+)

diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index da6624d4f2..85dae5321a 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -451,6 +451,28 @@ int clk_disable_bulk(struct clk_bulk *bulk)
 	return 0;
 }
 
+int clk_get_by_id(ulong id, struct clk **clkp)
+{
+	struct udevice *dev;
+	struct uclass *uc;
+	int ret;
+
+	ret = uclass_get(UCLASS_CLK, &uc);
+	if (ret)
+		return ret;
+
+	uclass_foreach_dev(dev, uc) {
+		struct clk *clk = (struct clk *)dev_get_driver_data(dev);
+
+		if (clk && clk->id == id) {
+			*clkp = clk;
+			return 0;
+		}
+	}
+
+	return -ENOENT;
+}
+
 UCLASS_DRIVER(clk) = {
 	.id		= UCLASS_CLK,
 	.name		= "clk",
diff --git a/include/clk.h b/include/clk.h
index 98c3e12fb4..a4ecca9fbc 100644
--- a/include/clk.h
+++ b/include/clk.h
@@ -326,4 +326,15 @@ static inline bool clk_valid(struct clk *clk)
 {
 	return !!clk->dev;
 }
+
+/**
+ * clk_get_by_id() - Get the clock by its ID
+ *
+ * @id:	The clock ID to search for
+ *
+ * @clkp:	A pointer to clock struct that has been found among added clocks
+ *              to UCLASS_CLK
+ * @return zero on success, or -ENOENT on error
+ */
+int clk_get_by_id(ulong id, struct clk **clkp);
 #endif
-- 
2.11.0

  parent reply	other threads:[~2019-04-25 10:29 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-25 10:29 [U-Boot] [PATCH v3 00/11] clk: Port Linux common clock framework [CCF] to U-boot (tag: 5.0-rc3) Lukasz Majewski
2019-04-25 10:29 ` [U-Boot] [PATCH v3 01/11] dm: Fix documentation entry as there is no UCLASS_CLOCK uclass Lukasz Majewski
2019-04-26  2:16   ` Peng Fan
2019-04-25 10:29 ` [U-Boot] [PATCH v3 02/11] cmd: Do not show frequency for clocks which .get_rate() return error Lukasz Majewski
2019-04-26  2:17   ` Peng Fan
2019-04-25 10:29 ` [U-Boot] [PATCH v3 03/11] clk: Remove clock ID check in .get_rate() of clk_fixed_* Lukasz Majewski
2019-04-26  2:17   ` Peng Fan
2019-04-25 10:29 ` [U-Boot] [PATCH v3 04/11] clk: Extend struct clk to provide information regarding clock rate Lukasz Majewski
2019-04-26  2:23   ` Peng Fan
2019-04-25 10:29 ` [U-Boot] [PATCH v3 05/11] clk: Provide struct clk for fixed rate clock (clk_fixed_rate.c) Lukasz Majewski
2019-04-26  2:29   ` Peng Fan
2019-04-25 10:29 ` [U-Boot] [PATCH v3 06/11] dm: clk: Define clk_get_parent() for clk operations Lukasz Majewski
2019-04-26  2:31   ` Peng Fan
2019-04-25 10:29 ` [U-Boot] [PATCH v3 07/11] dm: clk: Define clk_get_parent_rate() " Lukasz Majewski
2019-04-26  2:36   ` Peng Fan
2019-04-26  6:04     ` Lukasz Majewski
2019-04-25 10:29 ` Lukasz Majewski [this message]
2019-04-26  2:39   ` [U-Boot] [PATCH v3 08/11] dm: clk: Define clk_get_by_id() " Peng Fan
2019-04-25 10:29 ` [U-Boot] [PATCH v3 09/11] clk: test: Provide unit test for clk_get_by_id() method Lukasz Majewski
2019-04-25 10:29 ` [U-Boot] [PATCH v3 10/11] clk: test: Provide unit test for clk_get_parent_rate() method Lukasz Majewski
2019-04-25 10:29 ` [U-Boot] [PATCH v3 11/11] clk: Port Linux common clock framework [CCF] for imx6q to U-boot (tag: 5.0-rc3) Lukasz Majewski
2019-04-26  2:54   ` Peng Fan
2019-05-08  7:25 ` [U-Boot] [PATCH v3 00/11] clk: Port Linux common clock framework [CCF] " Lukasz Majewski
2019-05-18 16:08 ` Simon Glass
2019-05-18 21:28   ` Lukasz Majewski
2019-05-18 22:21     ` Simon Glass
2019-05-19 21:03       ` Lukasz Majewski
2019-05-20 16:09         ` Simon Glass
2019-05-21 14:48           ` Lukasz Majewski
2019-05-22  0:53             ` Simon Glass
2019-05-30  3:04               ` Peng Fan
2019-05-30  8:17                 ` Marek Vasut
2019-06-03  7:22                 ` Lukasz Majewski
2019-06-22 19:09                   ` Simon Glass

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=20190425102953.5348-9-lukma@denx.de \
    --to=lukma@denx.de \
    --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.