[U-Boot] [PATCH v9 03/10] clk: add clk_release_all()
patrice.chotard at st.com
patrice.chotard at st.com
Wed Jun 21 12:42:39 UTC 2017
From: Patrice Chotard <patrice.chotard at st.com>
Add clk_release_all() method which Disable/Free an
array of clocks that has been previously requested by
clk_request/get_by_*()
Signed-off-by: Patrice Chotard <patrice.chotard at st.com>
---
v9: _ to avoid confusion, rename clk_disable_all() in clk_release_all()
as this function not only disable all clocks but also free all of them
_ add a check in clk_release_all() to verify if a clock has been previously
requested before asserting and freeing it.
v8: _ replace clk->dev by clk[i].dev in clk_request() param
v7: _ none
v6: _ none
v5: _ none
v4: _ none
v3: _ add commit message
v2: _ create this independant path for printf() replacement
drivers/clk/clk-uclass.c | 26 ++++++++++++++++++++++++++
include/clk.h | 14 ++++++++++++++
2 files changed, 40 insertions(+)
diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index 83b6328..ffbe872 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -65,6 +65,8 @@ int clk_get_by_index(struct udevice *dev, int index, struct clk *clk)
debug("%s(dev=%p, index=%d, clk=%p)\n", __func__, dev, index, clk);
assert(clk);
+ clk->dev = NULL;
+
ret = dev_read_phandle_with_args(dev, "clocks", "#clock-cells", 0,
index, &args);
if (ret) {
@@ -102,6 +104,7 @@ int clk_get_by_name(struct udevice *dev, const char *name, struct clk *clk)
int index;
debug("%s(dev=%p, name=%s, clk=%p)\n", __func__, dev, name, clk);
+ clk->dev = NULL;
index = dev_read_stringlist_search(dev, "clock-names", name);
if (index < 0) {
@@ -187,6 +190,29 @@ int clk_disable(struct clk *clk)
return ops->disable(clk);
}
+int clk_release_all(struct clk *clk, int count)
+{
+ int i, ret;
+
+ for (i = 0; i < count; i++) {
+ debug("%s(clk[%d]=%p)\n", __func__, i, &clk[i]);
+
+ /* check if clock has been previously requested */
+ if (!clk[i].dev)
+ continue;
+
+ ret = clk_disable(&clk[i]);
+ if (ret && ret != -ENOSYS)
+ return ret;
+
+ ret = clk_free(&clk[i]);
+ if (ret && ret != -ENOSYS)
+ return ret;
+ }
+
+ return 0;
+}
+
UCLASS_DRIVER(clk) = {
.id = UCLASS_CLK,
.name = "clk",
diff --git a/include/clk.h b/include/clk.h
index 5a5c2ff..a905a41 100644
--- a/include/clk.h
+++ b/include/clk.h
@@ -174,6 +174,20 @@ int clk_enable(struct clk *clk);
*/
int clk_disable(struct clk *clk);
+/**
+ * clk_release_all() - Disable (turn off)/Free an array of previously
+ * requested clocks.
+ *
+ * For each clock contained in the clock array, this function will check if
+ * clock has been previously requested and then will disable and free it.
+ *
+ * @clk: A clock struct array that was previously successfully
+ * requested by clk_request/get_by_*().
+ * @count Number of clock contained in the array
+ * @return zero on success, or -ve error code.
+ */
+int clk_release_all(struct clk *clk, int count);
+
int soc_clk_dump(void);
#endif
--
1.9.1
More information about the U-Boot
mailing list