Skip to contentSkip to conversation

clk: Add get/enable/disable/release for a bulk of clocks

PATCH New Neil Armstrong 3 participants 7 messages Apr 3, 2018 – Apr 11, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover clk: Add get/enable/disable/release for a bulk of clocks

This patch adds a "bulk" API to the clock API in order to get/enable/disable /release a group of clocks associated with a device.

This bulk API will avoid adding a copy of the same code to manage a group of clocks in drivers.

This serie and the "reset bulk" serie is necessary and suggested by Marek Vasut for the "Add USB Support for Amlogic Meson GXL SoCs" to avoid adding the same code to manage a bulk of clocks and resets in another driver.
I will push a RFC code to update the other drivers having a similar code pattern when these patches are merged.

The second patch adds the bulk clock API tests for the sandbox test suite.

Changes since v1 :
- Add sandbox tests

Neil Armstrong (2):
clk: Add get/enable/disable/release for a bulk of clocks
clk: add sandbox test for bulk API

 arch/sandbox/include/asm/clk.h | 32 +++++++++++++++++++
 drivers/clk/clk-uclass.c       | 59 ++++++++++++++++++++++++++++++++++
 drivers/clk/clk_sandbox_test.c | 29 +++++++++++++++++
 include/clk.h                  | 72 +++++++++++++++++++++++++++++++++++++++++-
 test/dm/clk.c                  | 38 ++++++++++++++++++++++
 5 files changed, 229 insertions(+), 1 deletion(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH v2 1/2 clk: Add get/enable/disable/release for a bulk of clocks

This patch adds a "bulk" API to the clock API in order to get/enable/disable /release a group of clocks associated with a device.

This bulk API will avoid adding a copy of the same code to manage a group of clocks in drivers.

---
 drivers/clk/clk-uclass.c | 59 +++++++++++++++++++++++++++++++++++++++
 include/clk.h            | 72 +++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 130 insertions(+), 1 deletion(-)
drivers/clk/clk-uclass.c +59 -0
index ad76379..6e99b3b 100644
@@ -104,6 +104,39 @@ int clk_get_by_index(struct udevice *dev, int index, struct clk *clk)
 	return clk_get_by_indexed_prop(dev, "clocks", index, clk);
 }
 
+int clk_get_bulk(struct udevice *dev, struct clk_bulk *bulk)
+{
+	int i, ret, err, count;
+	
+	bulk->count = 0;
+
+	count = dev_count_phandle_with_args(dev, "clocks", "#clock-cells");
+	if (!count)
+		return 0;
+
+	bulk->clks = devm_kcalloc(dev, count, sizeof(struct clk), GFP_KERNEL);
+	if (!bulk->clks)
+		return -ENOMEM;
+
+	for (i = 0; i < count; i++) {
+		ret = clk_get_by_index(dev, i, &bulk->clks[i]);
+		if (ret < 0)
+			goto bulk_get_err;
+
+		++bulk->count;
+	}
+
+	return 0;
+
+bulk_get_err:
+	err = clk_release_all(bulk->clks, bulk->count);
+	if (err)
+		debug("%s: could release all clocks for %p\n",
+		      __func__, dev);
+
+	return ret;
+}
+
 static int clk_set_default_parents(struct udevice *dev)
 {
 	struct clk clk, parent_clk;
@@ -336,6 +369,19 @@ int clk_enable(struct clk *clk)
 	return ops->enable(clk);
 }
 
+int clk_enable_bulk(struct clk_bulk *bulk)
+{
+	int i, ret;
+
+	for (i = 0; i < bulk->count; i++) {
+		ret = clk_enable(&bulk->clks[i]);
+		if (ret < 0 && ret != -ENOSYS)
+			return ret;
+	}
+
+	return 0;
+}
+
 int clk_disable(struct clk *clk)
 {
 	const struct clk_ops *ops = clk_dev_ops(clk->dev);
@@ -348,6 +394,19 @@ int clk_disable(struct clk *clk)
 	return ops->disable(clk);
 }
 
+int clk_disable_bulk(struct clk_bulk *bulk)
+{
+	int i, ret;
+
+	for (i = 0; i < bulk->count; i++) {
+		ret = clk_disable(&bulk->clks[i]);
+		if (ret < 0 && ret != -ENOSYS)
+			return ret;
+	}
+
+	return 0;
+}
+
 UCLASS_DRIVER(clk) = {
 	.id		= UCLASS_CLK,
 	.name		= "clk",
include/clk.h +71 -1

114 lines not on this page · raw message

Signature · 1 line
2.7.4
#2 lore raw

PATCH v2 1/2 clk: Add get/enable/disable/release for a bulk of clocks

Quoted 11 lines · Neil Armstrong

This patch adds a "bulk" API to the clock API in order to get/enable/disable /release a group of clocks associated with a device.

This bulk API will avoid adding a copy of the same code to manage a group of clocks in drivers.

---
 drivers/clk/clk-uclass.c | 59 +++++++++++++++++++++++++++++++++++++++
 include/clk.h            | 72 +++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 130 insertions(+), 1 deletion(-)
#3 lore raw

PATCH v2 1/2 clk: Add get/enable/disable/release for a bulk of clocks

In reply to Neil Armstrong
Quoted 8 lines · Neil Armstrong

This patch adds a "bulk" API to the clock API in order to get/enable/disable /release a group of clocks associated with a device.

This bulk API will avoid adding a copy of the same code to manage a group of clocks in drivers.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-amlogic/attachments/20180411/3ec095db/attachment.sig>
#4 lore raw

PATCH v2 2/2 clk: add sandbox test for bulk API

In reply to Neil Armstrong

This patch adds the bulk clock API tests for the sandbox test suite.

It's very similar to the main test but only uses the _bulk() API and checks if the clocks are correctly enabled/disabled.

---
 arch/sandbox/include/asm/clk.h | 32 ++++++++++++++++++++++++++++++++
 drivers/clk/clk_sandbox_test.c | 29 +++++++++++++++++++++++++++++
 test/dm/clk.c                  | 38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 99 insertions(+)
arch/sandbox/include/asm/clk.h +32 -0
index 9dc6c81..01b5ba4 100644
@@ -64,6 +64,14 @@ int sandbox_clk_query_enable(struct udevice *dev, int id);
  */
 int sandbox_clk_test_get(struct udevice *dev);
 /**
+ * sandbox_clk_test_get_bulk - Ask the sandbox clock test device to request its
+ * clocks with the bulk clk API.
+ *
+ * @dev:	The sandbox clock test (client) devivce.
+ * @return:	0 if OK, or a negative error code.
+ */
+int sandbox_clk_test_get_bulk(struct udevice *dev);
+/**
  * sandbox_clk_test_get_rate - Ask the sandbox clock test device to query a
  * clock's rate.
  *
@@ -91,6 +99,14 @@ ulong sandbox_clk_test_set_rate(struct udevice *dev, int id, ulong rate);
  */
 int sandbox_clk_test_enable(struct udevice *dev, int id);
 /**
+ * sandbox_clk_test_enable_bulk - Ask the sandbox clock test device to enable
+ * all clocks in it's clock bulk struct.
+ *
+ * @dev:	The sandbox clock test (client) devivce.
+ * @return:	0 if OK, or a negative error code.
+ */
+int sandbox_clk_test_enable_bulk(struct udevice *dev);
+/**
  * sandbox_clk_test_disable - Ask the sandbox clock test device to disable a
  * clock.
  *
@@ -100,6 +116,14 @@ int sandbox_clk_test_enable(struct udevice *dev, int id);
  */
 int sandbox_clk_test_disable(struct udevice *dev, int id);
 /**
+ * sandbox_clk_test_disable_bulk - Ask the sandbox clock test device to disable
+ * all clocks in it's clock bulk struct.
+ *
+ * @dev:	The sandbox clock test (client) devivce.
+ * @return:	0 if OK, or a negative error code.
+ */
+int sandbox_clk_test_disable_bulk(struct udevice *dev);
+/**
  * sandbox_clk_test_free - Ask the sandbox clock test device to free its
  * clocks.
  *
@@ -107,5 +131,13 @@ int sandbox_clk_test_disable(struct udevice *dev, int id);
  * @return:	0 if OK, or a negative error code.
  */
 int sandbox_clk_test_free(struct udevice *dev);
+/**
+ * sandbox_clk_test_release_bulk - Ask the sandbox clock test device to release
+ * all clocks in it's clock bulk struct.
+ *
+ * @dev:	The sandbox clock test (client) devivce.
+ * @return:	0 if OK, or a negative error code.
+ */
+int sandbox_clk_test_release_bulk(struct udevice *dev);
 
 #endif
drivers/clk/clk_sandbox_test.c +29 -0
index 999100d..d089881 100644
@@ -11,6 +11,7 @@
 
 struct sandbox_clk_test {
 	struct clk clks[SANDBOX_CLK_TEST_ID_COUNT];
+	struct clk_bulk bulk;
 };
 
 static const char * const sandbox_clk_test_names[] = {
@@ -34,6 +35,13 @@ int sandbox_clk_test_get(struct udevice *dev)
 	return 0;
 }
 
+int sandbox_clk_test_get_bulk(struct udevice *dev)
+{
+	struct sandbox_clk_test *sbct = dev_get_priv(dev);
+
+	return clk_get_bulk(dev, &sbct->bulk);
+}
+
 ulong sandbox_clk_test_get_rate(struct udevice *dev, int id)
 {
 	struct sandbox_clk_test *sbct = dev_get_priv(dev);
@@ -64,6 +72,13 @@ int sandbox_clk_test_enable(struct udevice *dev, int id)
 	return clk_enable(&sbct->clks[id]);
 }
 
+int sandbox_clk_test_enable_bulk(struct udevice *dev)
+{
+	struct sandbox_clk_test *sbct = dev_get_priv(dev);
+
+	return clk_enable_bulk(&sbct->bulk);
+}
+
 int sandbox_clk_test_disable(struct udevice *dev, int id)
 {
 	struct sandbox_clk_test *sbct = dev_get_priv(dev);
@@ -74,6 +89,13 @@ int sandbox_clk_test_disable(struct udevice *dev, int id)
 	return clk_disable(&sbct->clks[id]);
 }
 
+int sandbox_clk_test_disable_bulk(struct udevice *dev)
+{
+	struct sandbox_clk_test *sbct = dev_get_priv(dev);
+
+	return clk_disable_bulk(&sbct->bulk);
+}
+
 int sandbox_clk_test_free(struct udevice *dev)
 {
 	struct sandbox_clk_test *sbct = dev_get_priv(dev);
@@ -88,6 +110,13 @@ int sandbox_clk_test_free(struct udevice *dev)
 	return 0;
 }
 
+int sandbox_clk_test_release_bulk(struct udevice *dev)
+{
+	struct sandbox_clk_test *sbct = dev_get_priv(dev);
+
+	return clk_release_bulk(&sbct->bulk);
+}
+
 static const struct udevice_id sandbox_clk_test_ids[] = {
 	{ .compatible = "sandbox,clk-test" },
 	{ }
test/dm/clk.c +38 -0
index 712a1e6..95716f8 100644
@@ -101,3 +101,41 @@ static int dm_test_clk(struct unit_test_state *uts)
 	return 0;
 }
 DM_TEST(dm_test_clk, DM_TESTF_SCAN_FDT);
+
+static int dm_test_clk_bulk(struct unit_test_state *uts)
+{
+	struct udevice *dev_clk, *dev_test;
+	ulong rate;
+
+	ut_assertok(uclass_get_device_by_name(UCLASS_CLK, "clk-sbox",
+					      &dev_clk));
+	ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "clk-test",
+					      &dev_test));
+	ut_assertok(sandbox_clk_test_get_bulk(dev_test));
+
+	ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI));
+	ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C));
+
+	/* Fixed clock does not support enable, thus should not fail */
+	ut_assertok(sandbox_clk_test_enable_bulk(dev_test));
+	ut_asserteq(1, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI));
+	ut_asserteq(1, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C));
+
+	/* Fixed clock does not support disable, thus should not fail */
+	ut_assertok(sandbox_clk_test_disable_bulk(dev_test));
+	ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI));
+	ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C));
+
+	/* Fixed clock does not support enable, thus should not fail */
+	ut_assertok(sandbox_clk_test_enable_bulk(dev_test));
+	ut_asserteq(1, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI));
+	ut_asserteq(1, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C));
+
+	/* Fixed clock does not support disable, thus should not fail */
+	ut_assertok(sandbox_clk_test_release_bulk(dev_test));
+	ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI));
+	ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C));
+
+	return 0;
+}
+DM_TEST(dm_test_clk_bulk, DM_TESTF_SCAN_FDT);
Signature · 1 line
2.7.4
#5 lore raw

PATCH v2 2/2 clk: add sandbox test for bulk API

Quoted 11 lines · Neil Armstrong

This patch adds the bulk clock API tests for the sandbox test suite.

It's very similar to the main test but only uses the _bulk() API and checks if the clocks are correctly enabled/disabled.

---
 arch/sandbox/include/asm/clk.h | 32 ++++++++++++++++++++++++++++++++
 drivers/clk/clk_sandbox_test.c | 29 +++++++++++++++++++++++++++++
 test/dm/clk.c                  | 38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 99 insertions(+)
#6 lore raw

PATCH v2 2/2 clk: add sandbox test for bulk API

In reply to Neil Armstrong
Quoted 7 lines · Neil Armstrong

This patch adds the bulk clock API tests for the sandbox test suite.

It's very similar to the main test but only uses the _bulk() API and checks if the clocks are correctly enabled/disabled.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-amlogic/attachments/20180411/a280eb10/attachment.sig>