clk: add CONFIG_CLK_AUTO_ID
Add a new config CONFIG_CLK_AUTO_ID to support a unique clk id
for all the clock providers, managed by clk uclass, when the clock
reference arg[0] is the same.
When the CONFIG is activated, the clock id is limited to the lower
CLK_ID_SZ = 24 bits in default clock xlate function
and the sequence number + 1 of the clk provider device is
added for the 8 higher bits.
We use sequence number + 1 to avoid the "dummy" clock id = 0,
used for invalid clock when CCF is activated.
When this config is activated, the new function clk_get_id()
should be used to get back the internal reference to clock
for the each clock provider.
Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
Signed-off-by: Patrice Chotard <patrice.chotard@foss.st.com>
Cc: Lukasz Majewski <lukma@denx.de>
Cc: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
diff --git a/include/clk.h b/include/clk.h
index a6ef4e0..f94135f 100644
--- a/include/clk.h
+++ b/include/clk.h
@@ -13,6 +13,15 @@
#include <linux/errno.h>
#include <linux/types.h>
+#ifdef CONFIG_CLK_AUTO_ID
+#define CLK_ID_SZ 24
+#define CLK_ID_MSK GENMASK(23, 0)
+#define CLK_ID(dev, id) (((dev_seq(dev) + 1) << CLK_ID_SZ) | ((id) & CLK_ID_MSK))
+#else
+#define CLK_ID_MSK (~0UL)
+#define CLK_ID(dev, id) id
+#endif
+
/**
* DOC: Overview
*
@@ -570,6 +579,16 @@
*/
bool clk_dev_binded(struct clk *clk);
+/**
+ * clk_get_id - get clk id
+ *
+ * @clk: A clock struct
+ *
+ * Return: the clock identifier as it is defined by the clock provider in
+ * device tree or in platdata
+ */
+ulong clk_get_id(const struct clk *clk);
+
#else /* CONFIG_IS_ENABLED(CLK) */
static inline int clk_request(struct udevice *dev, struct clk *clk)
@@ -641,6 +660,11 @@
{
return false;
}
+
+static inline ulong clk_get_id(const struct clk *clk)
+{
+ return 0;
+}
#endif /* CONFIG_IS_ENABLED(CLK) */
/**