All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v2 0/6] clk: some fixes, device tree support, new features
@ 2016-01-13  4:16 Masahiro Yamada
  2016-01-13  4:16 ` [U-Boot] [PATCH v2 1/6] clk: fix comments in include/clk.h Masahiro Yamada
                   ` (5 more replies)
  0 siblings, 6 replies; 13+ messages in thread
From: Masahiro Yamada @ 2016-01-13  4:16 UTC (permalink / raw)
  To: u-boot



Masahiro Yamada (6):
  clk: fix comments in include/clk.h
  clk: add needed include and declaration to include/clk.h
  clk: add static qualifier to local functions
  clk: change the type of return value to long
  clk: add API to enable clock
  clk: add device tree support for clock framework

 drivers/clk/clk-uclass.c  | 51 ++++++++++++++++++++++++---
 drivers/clk/clk_rk3036.c  |  6 ++--
 drivers/clk/clk_rk3288.c  |  6 ++--
 drivers/clk/clk_sandbox.c |  8 ++---
 include/clk.h             | 87 +++++++++++++++++++++++++++++++++++++----------
 5 files changed, 126 insertions(+), 32 deletions(-)

-- 
1.9.1

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [U-Boot] [PATCH v2 1/6] clk: fix comments in include/clk.h
  2016-01-13  4:16 [U-Boot] [PATCH v2 0/6] clk: some fixes, device tree support, new features Masahiro Yamada
@ 2016-01-13  4:16 ` Masahiro Yamada
  2016-01-16  1:27   ` Simon Glass
  2016-01-13  4:16 ` [U-Boot] [PATCH v2 2/6] clk: add needed include and declaration to include/clk.h Masahiro Yamada
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 13+ messages in thread
From: Masahiro Yamada @ 2016-01-13  4:16 UTC (permalink / raw)
  To: u-boot

The comment about get_periph_rate() is the same as that of
set_periph_rate().

I am fixing typos here and there while I am in this file.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Acked-by: Simon Glass <sjg@chromium.org>
---

Changes in v2: None

 include/clk.h | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/include/clk.h b/include/clk.h
index 254ad2b..f244301 100644
--- a/include/clk.h
+++ b/include/clk.h
@@ -29,19 +29,19 @@ struct clk_ops {
 	ulong (*set_rate)(struct udevice *dev, ulong rate);
 
 	/**
-	* clk_set_periph_rate() - Set clock rate for a peripheral
-	*
-	* @dev:	Device to adjust (UCLASS_CLK)
-	* @rate:	New clock rate in Hz
-	* @return new clock rate in Hz, or -ve error code
-	*/
+	 * get_periph_rate() - Get clock rate for a peripheral
+	 *
+	 * @dev:	Device to check (UCLASS_CLK)
+	 * @periph:	Peripheral ID to check
+	 * @return clock rate in Hz, or -ve error code
+	 */
 	ulong (*get_periph_rate)(struct udevice *dev, int periph);
 
 	/**
-	 * clk_set_periph_rate() - Set current clock rate for a peripheral
+	 * set_periph_rate() - Set current clock rate for a peripheral
 	 *
 	 * @dev:	Device to update (UCLASS_CLK)
-	 * @periph:	Peripheral ID to cupdate
+	 * @periph:	Peripheral ID to update
 	 * @return new clock rate in Hz, or -ve error code
 	 */
 	ulong (*set_periph_rate)(struct udevice *dev, int periph, ulong rate);
@@ -58,7 +58,7 @@ struct clk_ops {
 ulong clk_get_rate(struct udevice *dev);
 
 /**
- * set_rate() - Set current clock rate
+ * clk_set_rate() - Set current clock rate
  *
  * @dev:	Device to adjust
  * @rate:	New clock rate in Hz
@@ -78,7 +78,7 @@ ulong clk_get_periph_rate(struct udevice *dev, int periph);
  * clk_set_periph_rate() - Set current clock rate for a peripheral
  *
  * @dev:	Device to update (UCLASS_CLK)
- * @periph:	Peripheral ID to cupdate
+ * @periph:	Peripheral ID to update
  * @return new clock rate in Hz, or -ve error code
  */
 ulong clk_set_periph_rate(struct udevice *dev, int periph, ulong rate);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [U-Boot] [PATCH v2 2/6] clk: add needed include and declaration to include/clk.h
  2016-01-13  4:16 [U-Boot] [PATCH v2 0/6] clk: some fixes, device tree support, new features Masahiro Yamada
  2016-01-13  4:16 ` [U-Boot] [PATCH v2 1/6] clk: fix comments in include/clk.h Masahiro Yamada
@ 2016-01-13  4:16 ` Masahiro Yamada
  2016-01-16  1:27   ` Simon Glass
  2016-01-13  4:16 ` [U-Boot] [PATCH v2 3/6] clk: add static qualifier to local functions Masahiro Yamada
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 13+ messages in thread
From: Masahiro Yamada @ 2016-01-13  4:16 UTC (permalink / raw)
  To: u-boot

This header uses ulong, so it needs to include <linux/types.h>.
Likewise, "struct udevice" must be declared before it is used.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Acked-by: Simon Glass <sjg@chromium.org>
---

Changes in v2: None

 include/clk.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/include/clk.h b/include/clk.h
index f244301..371784a 100644
--- a/include/clk.h
+++ b/include/clk.h
@@ -8,6 +8,10 @@
 #ifndef _CLK_H_
 #define _CLK_H_
 
+#include <linux/types.h>
+
+struct udevice;
+
 int soc_clk_dump(void);
 
 struct clk_ops {
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [U-Boot] [PATCH v2 3/6] clk: add static qualifier to local functions
  2016-01-13  4:16 [U-Boot] [PATCH v2 0/6] clk: some fixes, device tree support, new features Masahiro Yamada
  2016-01-13  4:16 ` [U-Boot] [PATCH v2 1/6] clk: fix comments in include/clk.h Masahiro Yamada
  2016-01-13  4:16 ` [U-Boot] [PATCH v2 2/6] clk: add needed include and declaration to include/clk.h Masahiro Yamada
@ 2016-01-13  4:16 ` Masahiro Yamada
  2016-01-15  1:26   ` Simon Glass
  2016-01-13  4:16 ` [U-Boot] [PATCH v2 4/6] clk: change the type of return value to long Masahiro Yamada
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 13+ messages in thread
From: Masahiro Yamada @ 2016-01-13  4:16 UTC (permalink / raw)
  To: u-boot

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

Changes in v2: None

 drivers/clk/clk_rk3036.c  | 2 +-
 drivers/clk/clk_rk3288.c  | 2 +-
 drivers/clk/clk_sandbox.c | 5 +++--
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/clk/clk_rk3036.c b/drivers/clk/clk_rk3036.c
index 6c802b6..f650810 100644
--- a/drivers/clk/clk_rk3036.c
+++ b/drivers/clk/clk_rk3036.c
@@ -314,7 +314,7 @@ static ulong rk3036_clk_set_rate(struct udevice *dev, ulong rate)
 	return 0;
 }
 
-ulong rk3036_set_periph_rate(struct udevice *dev, int periph, ulong rate)
+static ulong rk3036_set_periph_rate(struct udevice *dev, int periph, ulong rate)
 {
 	struct rk3036_clk_priv *priv = dev_get_priv(dev);
 	ulong new_rate;
diff --git a/drivers/clk/clk_rk3288.c b/drivers/clk/clk_rk3288.c
index 54d4930..0172ad1 100644
--- a/drivers/clk/clk_rk3288.c
+++ b/drivers/clk/clk_rk3288.c
@@ -508,7 +508,7 @@ static ulong rockchip_spi_set_clk(struct rk3288_cru *cru, uint clk_general_rate,
 	return rockchip_spi_get_clk(cru, clk_general_rate, periph);
 }
 
-ulong rk3288_set_periph_rate(struct udevice *dev, int periph, ulong rate)
+static ulong rk3288_set_periph_rate(struct udevice *dev, int periph, ulong rate)
 {
 	struct rk3288_clk_priv *priv = dev_get_priv(dev);
 	ulong new_rate;
diff --git a/drivers/clk/clk_sandbox.c b/drivers/clk/clk_sandbox.c
index 058225a..367130f 100644
--- a/drivers/clk/clk_sandbox.c
+++ b/drivers/clk/clk_sandbox.c
@@ -32,7 +32,7 @@ static ulong sandbox_clk_set_rate(struct udevice *dev, ulong rate)
 	return 0;
 }
 
-ulong sandbox_get_periph_rate(struct udevice *dev, int periph)
+static ulong sandbox_get_periph_rate(struct udevice *dev, int periph)
 {
 	struct sandbox_clk_priv *priv = dev_get_priv(dev);
 
@@ -41,7 +41,8 @@ ulong sandbox_get_periph_rate(struct udevice *dev, int periph)
 	return priv->periph_rate[periph];
 }
 
-ulong sandbox_set_periph_rate(struct udevice *dev, int periph, ulong rate)
+static ulong sandbox_set_periph_rate(struct udevice *dev, int periph,
+				     ulong rate)
 {
 	struct sandbox_clk_priv *priv = dev_get_priv(dev);
 	ulong old_rate;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [U-Boot] [PATCH v2 4/6] clk: change the type of return value to long
  2016-01-13  4:16 [U-Boot] [PATCH v2 0/6] clk: some fixes, device tree support, new features Masahiro Yamada
                   ` (2 preceding siblings ...)
  2016-01-13  4:16 ` [U-Boot] [PATCH v2 3/6] clk: add static qualifier to local functions Masahiro Yamada
@ 2016-01-13  4:16 ` Masahiro Yamada
  2016-01-18  3:58   ` Simon Glass
  2016-01-13  4:16 ` [U-Boot] [PATCH v2 5/6] clk: add API to enable clock Masahiro Yamada
  2016-01-13  4:16 ` [U-Boot] [PATCH v2 6/6] clk: add device tree support for clock framework Masahiro Yamada
  5 siblings, 1 reply; 13+ messages in thread
From: Masahiro Yamada @ 2016-01-13  4:16 UTC (permalink / raw)
  To: u-boot

The comments in include/clk.h state "or -ve error code" for these
functions, and actually the functions return negative error code
here and there.  Returning unsigned value is not suitable.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

Changes in v2: None

 drivers/clk/clk-uclass.c  |  8 ++++----
 drivers/clk/clk_rk3036.c  |  6 +++---
 drivers/clk/clk_rk3288.c  |  6 +++---
 drivers/clk/clk_sandbox.c |  9 ++++-----
 include/clk.h             | 16 ++++++++--------
 5 files changed, 22 insertions(+), 23 deletions(-)

diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index 73dfd7d..a5bef59 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -12,7 +12,7 @@
 #include <dm/lists.h>
 #include <dm/root.h>
 
-ulong clk_get_rate(struct udevice *dev)
+long clk_get_rate(struct udevice *dev)
 {
 	struct clk_ops *ops = clk_get_ops(dev);
 
@@ -22,7 +22,7 @@ ulong clk_get_rate(struct udevice *dev)
 	return ops->get_rate(dev);
 }
 
-ulong clk_set_rate(struct udevice *dev, ulong rate)
+long clk_set_rate(struct udevice *dev, ulong rate)
 {
 	struct clk_ops *ops = clk_get_ops(dev);
 
@@ -32,7 +32,7 @@ ulong clk_set_rate(struct udevice *dev, ulong rate)
 	return ops->set_rate(dev, rate);
 }
 
-ulong clk_get_periph_rate(struct udevice *dev, int periph)
+long clk_get_periph_rate(struct udevice *dev, int periph)
 {
 	struct clk_ops *ops = clk_get_ops(dev);
 
@@ -42,7 +42,7 @@ ulong clk_get_periph_rate(struct udevice *dev, int periph)
 	return ops->get_periph_rate(dev, periph);
 }
 
-ulong clk_set_periph_rate(struct udevice *dev, int periph, ulong rate)
+long clk_set_periph_rate(struct udevice *dev, int periph, ulong rate)
 {
 	struct clk_ops *ops = clk_get_ops(dev);
 
diff --git a/drivers/clk/clk_rk3036.c b/drivers/clk/clk_rk3036.c
index f650810..8613123 100644
--- a/drivers/clk/clk_rk3036.c
+++ b/drivers/clk/clk_rk3036.c
@@ -298,7 +298,7 @@ static ulong rockchip_mmc_set_clk(struct rk3036_cru *cru, uint clk_general_rate,
 	return rockchip_mmc_get_clk(cru, clk_general_rate, periph);
 }
 
-static ulong rk3036_clk_get_rate(struct udevice *dev)
+static long rk3036_clk_get_rate(struct udevice *dev)
 {
 	struct rk3036_clk_plat *plat = dev_get_platdata(dev);
 	struct rk3036_clk_priv *priv = dev_get_priv(dev);
@@ -307,14 +307,14 @@ static ulong rk3036_clk_get_rate(struct udevice *dev)
 	return rkclk_pll_get_rate(priv->cru, plat->clk_id);
 }
 
-static ulong rk3036_clk_set_rate(struct udevice *dev, ulong rate)
+static long rk3036_clk_set_rate(struct udevice *dev, ulong rate)
 {
 	debug("%s\n", dev->name);
 
 	return 0;
 }
 
-static ulong rk3036_set_periph_rate(struct udevice *dev, int periph, ulong rate)
+static long rk3036_set_periph_rate(struct udevice *dev, int periph, ulong rate)
 {
 	struct rk3036_clk_priv *priv = dev_get_priv(dev);
 	ulong new_rate;
diff --git a/drivers/clk/clk_rk3288.c b/drivers/clk/clk_rk3288.c
index 0172ad1..8ed0bff 100644
--- a/drivers/clk/clk_rk3288.c
+++ b/drivers/clk/clk_rk3288.c
@@ -337,7 +337,7 @@ static uint32_t rkclk_pll_get_rate(struct rk3288_cru *cru,
 	}
 }
 
-static ulong rk3288_clk_get_rate(struct udevice *dev)
+static long rk3288_clk_get_rate(struct udevice *dev)
 {
 	struct rk3288_clk_plat *plat = dev_get_platdata(dev);
 	struct rk3288_clk_priv *priv = dev_get_priv(dev);
@@ -346,7 +346,7 @@ static ulong rk3288_clk_get_rate(struct udevice *dev)
 	return rkclk_pll_get_rate(priv->cru, plat->clk_id);
 }
 
-static ulong rk3288_clk_set_rate(struct udevice *dev, ulong rate)
+static long rk3288_clk_set_rate(struct udevice *dev, ulong rate)
 {
 	struct rk3288_clk_plat *plat = dev_get_platdata(dev);
 	struct rk3288_clk_priv *priv = dev_get_priv(dev);
@@ -508,7 +508,7 @@ static ulong rockchip_spi_set_clk(struct rk3288_cru *cru, uint clk_general_rate,
 	return rockchip_spi_get_clk(cru, clk_general_rate, periph);
 }
 
-static ulong rk3288_set_periph_rate(struct udevice *dev, int periph, ulong rate)
+static long rk3288_set_periph_rate(struct udevice *dev, int periph, ulong rate)
 {
 	struct rk3288_clk_priv *priv = dev_get_priv(dev);
 	ulong new_rate;
diff --git a/drivers/clk/clk_sandbox.c b/drivers/clk/clk_sandbox.c
index 367130f..0ff4605 100644
--- a/drivers/clk/clk_sandbox.c
+++ b/drivers/clk/clk_sandbox.c
@@ -15,14 +15,14 @@ struct sandbox_clk_priv {
 	ulong periph_rate[PERIPH_ID_COUNT];
 };
 
-static ulong sandbox_clk_get_rate(struct udevice *dev)
+static long sandbox_clk_get_rate(struct udevice *dev)
 {
 	struct sandbox_clk_priv *priv = dev_get_priv(dev);
 
 	return priv->rate;
 }
 
-static ulong sandbox_clk_set_rate(struct udevice *dev, ulong rate)
+static long sandbox_clk_set_rate(struct udevice *dev, ulong rate)
 {
 	struct sandbox_clk_priv *priv = dev_get_priv(dev);
 
@@ -32,7 +32,7 @@ static ulong sandbox_clk_set_rate(struct udevice *dev, ulong rate)
 	return 0;
 }
 
-static ulong sandbox_get_periph_rate(struct udevice *dev, int periph)
+static long sandbox_get_periph_rate(struct udevice *dev, int periph)
 {
 	struct sandbox_clk_priv *priv = dev_get_priv(dev);
 
@@ -41,8 +41,7 @@ static ulong sandbox_get_periph_rate(struct udevice *dev, int periph)
 	return priv->periph_rate[periph];
 }
 
-static ulong sandbox_set_periph_rate(struct udevice *dev, int periph,
-				     ulong rate)
+static long sandbox_set_periph_rate(struct udevice *dev, int periph, ulong rate)
 {
 	struct sandbox_clk_priv *priv = dev_get_priv(dev);
 	ulong old_rate;
diff --git a/include/clk.h b/include/clk.h
index 371784a..61bb468 100644
--- a/include/clk.h
+++ b/include/clk.h
@@ -21,7 +21,7 @@ struct clk_ops {
 	 * @dev:	Device to check (UCLASS_CLK)
 	 * @return clock rate in Hz, or -ve error code
 	 */
-	ulong (*get_rate)(struct udevice *dev);
+	long (*get_rate)(struct udevice *dev);
 
 	/**
 	 * set_rate() - Set current clock rate
@@ -30,7 +30,7 @@ struct clk_ops {
 	 * @rate:	New clock rate in Hz
 	 * @return new rate, or -ve error code
 	 */
-	ulong (*set_rate)(struct udevice *dev, ulong rate);
+	long (*set_rate)(struct udevice *dev, ulong rate);
 
 	/**
 	 * get_periph_rate() - Get clock rate for a peripheral
@@ -39,7 +39,7 @@ struct clk_ops {
 	 * @periph:	Peripheral ID to check
 	 * @return clock rate in Hz, or -ve error code
 	 */
-	ulong (*get_periph_rate)(struct udevice *dev, int periph);
+	long (*get_periph_rate)(struct udevice *dev, int periph);
 
 	/**
 	 * set_periph_rate() - Set current clock rate for a peripheral
@@ -48,7 +48,7 @@ struct clk_ops {
 	 * @periph:	Peripheral ID to update
 	 * @return new clock rate in Hz, or -ve error code
 	 */
-	ulong (*set_periph_rate)(struct udevice *dev, int periph, ulong rate);
+	long (*set_periph_rate)(struct udevice *dev, int periph, ulong rate);
 };
 
 #define clk_get_ops(dev)	((struct clk_ops *)(dev)->driver->ops)
@@ -59,7 +59,7 @@ struct clk_ops {
  * @dev:	Device to check (UCLASS_CLK)
  * @return clock rate in Hz, or -ve error code
  */
-ulong clk_get_rate(struct udevice *dev);
+long clk_get_rate(struct udevice *dev);
 
 /**
  * clk_set_rate() - Set current clock rate
@@ -68,7 +68,7 @@ ulong clk_get_rate(struct udevice *dev);
  * @rate:	New clock rate in Hz
  * @return new rate, or -ve error code
  */
-ulong clk_set_rate(struct udevice *dev, ulong rate);
+long clk_set_rate(struct udevice *dev, ulong rate);
 
 /**
  * clk_get_periph_rate() - Get current clock rate for a peripheral
@@ -76,7 +76,7 @@ ulong clk_set_rate(struct udevice *dev, ulong rate);
  * @dev:	Device to check (UCLASS_CLK)
  * @return clock rate in Hz, -ve error code
  */
-ulong clk_get_periph_rate(struct udevice *dev, int periph);
+long clk_get_periph_rate(struct udevice *dev, int periph);
 
 /**
  * clk_set_periph_rate() - Set current clock rate for a peripheral
@@ -85,6 +85,6 @@ ulong clk_get_periph_rate(struct udevice *dev, int periph);
  * @periph:	Peripheral ID to update
  * @return new clock rate in Hz, or -ve error code
  */
-ulong clk_set_periph_rate(struct udevice *dev, int periph, ulong rate);
+long clk_set_periph_rate(struct udevice *dev, int periph, ulong rate);
 
 #endif /* _CLK_H_ */
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [U-Boot] [PATCH v2 5/6] clk: add API to enable clock
  2016-01-13  4:16 [U-Boot] [PATCH v2 0/6] clk: some fixes, device tree support, new features Masahiro Yamada
                   ` (3 preceding siblings ...)
  2016-01-13  4:16 ` [U-Boot] [PATCH v2 4/6] clk: change the type of return value to long Masahiro Yamada
@ 2016-01-13  4:16 ` Masahiro Yamada
  2016-01-18  3:58   ` Simon Glass
  2016-01-13  4:16 ` [U-Boot] [PATCH v2 6/6] clk: add device tree support for clock framework Masahiro Yamada
  5 siblings, 1 reply; 13+ messages in thread
From: Masahiro Yamada @ 2016-01-13  4:16 UTC (permalink / raw)
  To: u-boot

The most basic thing for clock is to enable it, but it is missing
in this uclass.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Acked-by: Simon Glass <sjg@chromium.org>
---

Changes in v2:
  - Add clk_enable() function

 drivers/clk/clk-uclass.c | 10 ++++++++++
 include/clk.h            | 18 ++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index a5bef59..ac3909d 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -32,6 +32,16 @@ long clk_set_rate(struct udevice *dev, ulong rate)
 	return ops->set_rate(dev, rate);
 }
 
+int clk_enable(struct udevice *dev, int periph)
+{
+	struct clk_ops *ops = clk_get_ops(dev);
+
+	if (!ops->enable)
+		return -ENOSYS;
+
+	return ops->enable(dev, periph);
+}
+
 long clk_get_periph_rate(struct udevice *dev, int periph)
 {
 	struct clk_ops *ops = clk_get_ops(dev);
diff --git a/include/clk.h b/include/clk.h
index 61bb468..de15999 100644
--- a/include/clk.h
+++ b/include/clk.h
@@ -33,6 +33,15 @@ struct clk_ops {
 	long (*set_rate)(struct udevice *dev, ulong rate);
 
 	/**
+	 * enable() - Enable the clock for a peripheral
+	 *
+	 * @dev:	clock provider
+	 * @periph:	Peripheral ID to enable
+	 * @return zero on success, or -ve error code
+	 */
+	int (*enable)(struct udevice *dev, int periph);
+
+	/**
 	 * get_periph_rate() - Get clock rate for a peripheral
 	 *
 	 * @dev:	Device to check (UCLASS_CLK)
@@ -71,6 +80,15 @@ long clk_get_rate(struct udevice *dev);
 long clk_set_rate(struct udevice *dev, ulong rate);
 
 /**
+ * clk_enable() - Enable the clock for a peripheral
+ *
+ * @dev:	clock provider
+ * @periph:	Peripheral ID to enable
+ * @return zero on success, or -ve error code
+ */
+int clk_enable(struct udevice *dev, int periph);
+
+/**
  * clk_get_periph_rate() - Get current clock rate for a peripheral
  *
  * @dev:	Device to check (UCLASS_CLK)
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [U-Boot] [PATCH v2 6/6] clk: add device tree support for clock framework
  2016-01-13  4:16 [U-Boot] [PATCH v2 0/6] clk: some fixes, device tree support, new features Masahiro Yamada
                   ` (4 preceding siblings ...)
  2016-01-13  4:16 ` [U-Boot] [PATCH v2 5/6] clk: add API to enable clock Masahiro Yamada
@ 2016-01-13  4:16 ` Masahiro Yamada
  5 siblings, 0 replies; 13+ messages in thread
From: Masahiro Yamada @ 2016-01-13  4:16 UTC (permalink / raw)
  To: u-boot

Add device tree binding support for the clock uclass.  This allows
clock consumers to get the peripheral ID based on the "clocks"
property in the device tree.

Usage:
Assume the following device tree:

  clk: myclock {
          compatible = "myclocktype";
          #clock-cells = <1>;
  };

  uart {
          compatible = "myuart";
          clocks = <&clk 3>;
  };

  i2c {
          compatible = "myi2c";
          clocks = <&clk 5>;
  };

In this example, the UART, I2C driver can get the peripheral ID 3, 5,
respectively by calling fdt_clk_get().

By default, fdt_clk_get() returns the value of the first cell, or
zero if #clock-cells == <0>.  This should work for most of the cases,
but you can still override this behavior by implementing .fdt_xlate
callback in your driver.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

Changes in v2:
  - Change the arguments of fdt_clk_get() as Simon mentioned
  - rename .get_id() to .fdt_xlate(), which seems a more suitable name

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

diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index ac3909d..81ef526 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -62,6 +62,39 @@ long clk_set_periph_rate(struct udevice *dev, int periph, ulong rate)
 	return ops->set_periph_rate(dev, periph, rate);
 }
 
+#if CONFIG_IS_ENABLED(OF_CONTROL)
+int fdt_clk_get(struct udevice *dev, int index, struct udevice **clkdevp)
+{
+	DECLARE_GLOBAL_DATA_PTR;
+	struct fdtdec_phandle_args clkspec;
+	struct clk_ops *ops;
+	struct udevice *clkdev;
+	int rc;
+
+	rc = fdtdec_parse_phandle_with_args(gd->fdt_blob, dev->of_offset,
+					    "clocks", "#clock-cells", 0, index,
+					    &clkspec);
+	if (rc)
+		return rc;
+
+	rc = uclass_get_device_by_of_offset(UCLASS_CLK, clkspec.node, &clkdev);
+	if (rc)
+		return rc;
+
+	ops = clk_get_ops(clkdev);
+
+	if (ops->fdt_xlate)
+		rc = ops->fdt_xlate(clkdev, &clkspec);
+	else
+		rc = clkspec.args_count > 0 ? clkspec.args[0] : 0;
+
+	if (clkdevp)
+		*clkdevp = clkdev;
+
+	return rc;
+}
+#endif
+
 UCLASS_DRIVER(clk) = {
 	.id		= UCLASS_CLK,
 	.name		= "clk",
diff --git a/include/clk.h b/include/clk.h
index de15999..3f95395 100644
--- a/include/clk.h
+++ b/include/clk.h
@@ -10,6 +10,7 @@
 
 #include <linux/types.h>
 
+struct fdtdec_phandle_args;
 struct udevice;
 
 int soc_clk_dump(void);
@@ -58,6 +59,16 @@ struct clk_ops {
 	 * @return new clock rate in Hz, or -ve error code
 	 */
 	long (*set_periph_rate)(struct udevice *dev, int periph, ulong rate);
+
+	/**
+	 * fdt_xlate() - translate DT arguments into peripheral ID
+	 *
+	 * @dev:	clock provider
+	 * @clkspec:	arguments taken from the device tree
+	 * @return peripheral ID, or -ve error code
+	 */
+	int (*fdt_xlate)(struct udevice *dev,
+			 struct fdtdec_phandle_args *clkspec);
 };
 
 #define clk_get_ops(dev)	((struct clk_ops *)(dev)->driver->ops)
@@ -105,4 +116,22 @@ long clk_get_periph_rate(struct udevice *dev, int periph);
  */
 long clk_set_periph_rate(struct udevice *dev, int periph, ulong rate);
 
+#if CONFIG_IS_ENABLED(OF_CONTROL)
+/**
+ * fdt_clk_get() - Get peripheral ID from device tree
+ *
+ * @dev:	Peripheral device
+ * @index:	index of a phandle to parse out in "clocks" property
+ * @clkdevp:	if not NULL, filled with pointer of clock provider
+ * @return peripheral ID, or -ve error code
+ */
+int fdt_clk_get(struct udevice *dev, int index, struct udevice **clkdevp);
+#else
+static inline int fdt_clk_get(struct udevice *dev, int index,
+			      struct udevice **clkdevp);
+{
+	return -ENOSYS;
+}
+#endif
+
 #endif /* _CLK_H_ */
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [U-Boot] [PATCH v2 3/6] clk: add static qualifier to local functions
  2016-01-13  4:16 ` [U-Boot] [PATCH v2 3/6] clk: add static qualifier to local functions Masahiro Yamada
@ 2016-01-15  1:26   ` Simon Glass
  2016-01-16  1:27     ` Simon Glass
  0 siblings, 1 reply; 13+ messages in thread
From: Simon Glass @ 2016-01-15  1:26 UTC (permalink / raw)
  To: u-boot

On 12 January 2016 at 21:16, Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> ---
>
> Changes in v2: None
>
>  drivers/clk/clk_rk3036.c  | 2 +-
>  drivers/clk/clk_rk3288.c  | 2 +-
>  drivers/clk/clk_sandbox.c | 5 +++--
>  3 files changed, 5 insertions(+), 4 deletions(-)

Acked-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [U-Boot] [PATCH v2 1/6] clk: fix comments in include/clk.h
  2016-01-13  4:16 ` [U-Boot] [PATCH v2 1/6] clk: fix comments in include/clk.h Masahiro Yamada
@ 2016-01-16  1:27   ` Simon Glass
  0 siblings, 0 replies; 13+ messages in thread
From: Simon Glass @ 2016-01-16  1:27 UTC (permalink / raw)
  To: u-boot

On 12 January 2016 at 21:16, Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
> The comment about get_periph_rate() is the same as that of
> set_periph_rate().
>
> I am fixing typos here and there while I am in this file.
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> Acked-by: Simon Glass <sjg@chromium.org>
> ---
>
> Changes in v2: None
>
>  include/clk.h | 20 ++++++++++----------
>  1 file changed, 10 insertions(+), 10 deletions(-)

Applied to u-boot-dm, thanks!

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [U-Boot] [PATCH v2 2/6] clk: add needed include and declaration to include/clk.h
  2016-01-13  4:16 ` [U-Boot] [PATCH v2 2/6] clk: add needed include and declaration to include/clk.h Masahiro Yamada
@ 2016-01-16  1:27   ` Simon Glass
  0 siblings, 0 replies; 13+ messages in thread
From: Simon Glass @ 2016-01-16  1:27 UTC (permalink / raw)
  To: u-boot

On 12 January 2016 at 21:16, Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
> This header uses ulong, so it needs to include <linux/types.h>.
> Likewise, "struct udevice" must be declared before it is used.
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> Acked-by: Simon Glass <sjg@chromium.org>
> ---
>
> Changes in v2: None
>
>  include/clk.h | 4 ++++
>  1 file changed, 4 insertions(+)

Applied to u-boot-dm, thanks!

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [U-Boot] [PATCH v2 3/6] clk: add static qualifier to local functions
  2016-01-15  1:26   ` Simon Glass
@ 2016-01-16  1:27     ` Simon Glass
  0 siblings, 0 replies; 13+ messages in thread
From: Simon Glass @ 2016-01-16  1:27 UTC (permalink / raw)
  To: u-boot

On 14 January 2016 at 18:26, Simon Glass <sjg@chromium.org> wrote:
> On 12 January 2016 at 21:16, Masahiro Yamada
> <yamada.masahiro@socionext.com> wrote:
>> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
>> ---
>>
>> Changes in v2: None
>>
>>  drivers/clk/clk_rk3036.c  | 2 +-
>>  drivers/clk/clk_rk3288.c  | 2 +-
>>  drivers/clk/clk_sandbox.c | 5 +++--
>>  3 files changed, 5 insertions(+), 4 deletions(-)
>
> Acked-by: Simon Glass <sjg@chromium.org>

Applied to u-boot-dm, thanks!

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [U-Boot] [PATCH v2 5/6] clk: add API to enable clock
  2016-01-13  4:16 ` [U-Boot] [PATCH v2 5/6] clk: add API to enable clock Masahiro Yamada
@ 2016-01-18  3:58   ` Simon Glass
  0 siblings, 0 replies; 13+ messages in thread
From: Simon Glass @ 2016-01-18  3:58 UTC (permalink / raw)
  To: u-boot

On 12 January 2016 at 21:16, Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
> The most basic thing for clock is to enable it, but it is missing
> in this uclass.
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> Acked-by: Simon Glass <sjg@chromium.org>
> ---
>
> Changes in v2:
>   - Add clk_enable() function
>
>  drivers/clk/clk-uclass.c | 10 ++++++++++
>  include/clk.h            | 18 ++++++++++++++++++
>  2 files changed, 28 insertions(+)

Applied to u-boot-dm, thanks!

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [U-Boot] [PATCH v2 4/6] clk: change the type of return value to long
  2016-01-13  4:16 ` [U-Boot] [PATCH v2 4/6] clk: change the type of return value to long Masahiro Yamada
@ 2016-01-18  3:58   ` Simon Glass
  0 siblings, 0 replies; 13+ messages in thread
From: Simon Glass @ 2016-01-18  3:58 UTC (permalink / raw)
  To: u-boot

Hi Masahiro,

On 12 January 2016 at 21:16, Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
> The comments in include/clk.h state "or -ve error code" for these
> functions, and actually the functions return negative error code
> here and there.  Returning unsigned value is not suitable.
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> ---
>
> Changes in v2: None
>
>  drivers/clk/clk-uclass.c  |  8 ++++----
>  drivers/clk/clk_rk3036.c  |  6 +++---
>  drivers/clk/clk_rk3288.c  |  6 +++---
>  drivers/clk/clk_sandbox.c |  9 ++++-----
>  include/clk.h             | 16 ++++++++--------
>  5 files changed, 22 insertions(+), 23 deletions(-)
>

For the benefit of those who see this patch later, as discussed on the
v1 patch, this limits us to about 2GHz which seems a bit dangerous. We
are starting to see things around that level. We can use
IS_ERR_VALUE(). So I'm going to drop this patch.

Regards,
Simon

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2016-01-18  3:58 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-13  4:16 [U-Boot] [PATCH v2 0/6] clk: some fixes, device tree support, new features Masahiro Yamada
2016-01-13  4:16 ` [U-Boot] [PATCH v2 1/6] clk: fix comments in include/clk.h Masahiro Yamada
2016-01-16  1:27   ` Simon Glass
2016-01-13  4:16 ` [U-Boot] [PATCH v2 2/6] clk: add needed include and declaration to include/clk.h Masahiro Yamada
2016-01-16  1:27   ` Simon Glass
2016-01-13  4:16 ` [U-Boot] [PATCH v2 3/6] clk: add static qualifier to local functions Masahiro Yamada
2016-01-15  1:26   ` Simon Glass
2016-01-16  1:27     ` Simon Glass
2016-01-13  4:16 ` [U-Boot] [PATCH v2 4/6] clk: change the type of return value to long Masahiro Yamada
2016-01-18  3:58   ` Simon Glass
2016-01-13  4:16 ` [U-Boot] [PATCH v2 5/6] clk: add API to enable clock Masahiro Yamada
2016-01-18  3:58   ` Simon Glass
2016-01-13  4:16 ` [U-Boot] [PATCH v2 6/6] clk: add device tree support for clock framework Masahiro Yamada

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.