Skip to contentSkip to conversation

clk: add gpio controlled clock multiplexer

PATCH Applied Sergej Sawazki 2 participants 8 messages Jun 28, 2015 – Jul 7, 2015

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

v4 cover clk: add gpio controlled clock multiplexer

This patch series adds a common clock driver for basic gpio controlled clock multiplexers. It does also contain some minor fixes for the gpio-gate-clock.

The first two patches are minor fixes for the gpio-gate-clock. Patch three refactors the file clk-gpio-gate.c and adds the new gpio-mux-clock driver. Finally, patch four renames the file clk-gpio-gate.c to clk-gpio.c.

Based on clk-next.

Changes since v3:
* Suggested by Stephen Boyd:
- Split the patch into a patch series, separate gpio-gate-clock fixes and file renaming.
- Include linux/gpio/consumer.h.
- Remove debug noise.
- Remove some comments.
- Fix: Do not call free if alloc fails.

Changes since v2:
* Suggested by Stephen Boyd:
- Delete unneeded includes.
- Fix some style issues.
- Put gpio-gate-clock and gpio-mux-clock into a new file (clk-gpio.c) and refactor the code to minimize code duplication.

Changes since v1:
* Suggested by Stephen Boyd and Jyri Sarha:
- Remove the optional enable/disable support. If enable/disable is required, the gpio-mux-clock can be used in combination with the gpio-gate-clock.

* Suggested by Stephen Boyd:
- Remove the (index > 1)-check from clk_gpio_mux_set_parent().
- Stay silent if gpio_request_one() fails with -EPROBE_DEFER.
- Make sure num_parents is 2 in clk_register_gpio_mux().
- Use devm_clk_register() if a device is provided.
- Remove the flags variable from of_clk_gpio_mux_delayed_register_get().
- Fix num_parents check in of_clk_gpio_mux_delayed_register_get().
- Use kcalloc() for parent_names array allocation.
- Use pr_debug() instead of pr_warn() for the EPROBE_DEFER message.
- Use kzalloc(sizeof(*data)... ) instead of kzalloc(sizeof(struct clk_gpio_mux_delayed_register_data)... ) in of_gpio_mux_clk_setup().

Many thanks for your time and effort,
Sergej

Sergej Sawazki (4):
clk: gpio-gate: Include export.h instead of module.h
clk: gpio-gate: Stay silent on EPROBE_DEFER
clk: add gpio controlled clock multiplexer
clk: Rename clk-gpio-gate.c to clk-gpio.c

 .../devicetree/bindings/clock/gpio-mux-clock.txt   |  19 ++
 drivers/clk/Makefile                               |   2 +-
 drivers/clk/clk-gpio-gate.c                        | 207 -------------
 drivers/clk/clk-gpio.c                             | 319 +++++++++++++++++++++
 include/linux/clk-provider.h                       |  17 ++
 5 files changed, 356 insertions(+), 208 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/clock/gpio-mux-clock.txt
 delete mode 100644 drivers/clk/clk-gpio-gate.c
 create mode 100644 drivers/clk/clk-gpio.c
Signature · 1 line
1.9.1
#2 lore raw

PATCH v4 2/4 clk: gpio-gate: Stay silent on EPROBE_DEFER

Do not output an error message if requesting gpio failes with EPROBE_DEFER.

---
 drivers/clk/clk-gpio-gate.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/clk/clk-gpio-gate.c +3 -2
index a377f88..ef942da 100644
@@ -90,8 +90,9 @@ struct clk *clk_register_gpio_gate(struct device *dev, const char *name,
 		err = gpio_request_one(gpio, gpio_flags, name);
 
 	if (err) {
-		pr_err("%s: %s: Error requesting clock control gpio %u\n",
-		       __func__, name, gpio);
+		if (err != -EPROBE_DEFER)
+			pr_err("%s: %s: Error requesting clock control gpio %u\n",
+					__func__, name, gpio);
 		return ERR_PTR(err);
 	}
 
Signature · 1 line
1.9.1
#3 lore raw

PATCH v4 3/4 clk: add gpio controlled clock multiplexer

In reply to Sergej Sawazki

Add a common clock driver for basic gpio controlled clock multiplexers. This driver can be used for devices like 5V41068A or 831721I from IDT or for discrete multiplexer circuits. The 'select' pin selects one of two parent clocks.

---
 .../devicetree/bindings/clock/gpio-mux-clock.txt   |  19 ++
 drivers/clk/clk-gpio-gate.c                        | 231 +++++++++++++++------
 include/linux/clk-provider.h                       |  17 ++
 3 files changed, 207 insertions(+), 60 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/clock/gpio-mux-clock.txt
Documentation/devicetree/bindings/clock/gpio-mux-clock.txt new file +19 -0
new file mode 100644
index 0000000..2be1e03
@@ -0,0 +1,19 @@
+Binding for simple gpio clock multiplexer.
+
+This binding uses the common clock binding[1].
+
+[1] Documentation/devicetree/bindings/clock/clock-bindings.txt
+
+Required properties:
+- compatible : shall be "gpio-mux-clock".
+- clocks: list of two references to parent clocks.
+- #clock-cells : from common clock binding; shall be set to 0.
+- select-gpios : GPIO reference for selecting the parent clock.
+
+Example:
+	clock {
+		compatible = "gpio-mux-clock";
+		clocks = <&parentclk1>, <&parentclk2>;
+		#clock-cells = <0>;
+		select-gpios = <&gpio 1 GPIO_ACTIVE_HIGH>;
+	};
drivers/clk/clk-gpio-gate.c +171 -60

318 lines not on this page · raw message

include/linux/clk-provider.h +17 -0
index 78842f4..823d7f7 100644
@@ -550,6 +550,23 @@ struct clk *clk_register_gpio_gate(struct device *dev, const char *name,
 void of_gpio_clk_gate_setup(struct device_node *node);
 
 /**
+ * struct clk_gpio_mux - gpio controlled clock multiplexer
+ *
+ * @hw:		see struct clk_gpio
+ * @gpiod:	gpio descriptor to select the parent of this clock multiplexer
+ *
+ * Clock with a gpio control for selecting the parent clock.
+ * Implements .get_parent, .set_parent and .determine_rate
+ */
+
+extern const struct clk_ops clk_gpio_mux_ops;
+struct clk *clk_register_gpio_mux(struct device *dev, const char *name,
+		const char **parent_names, u8 num_parents, unsigned gpio,
+		bool active_low, unsigned long flags);
+
+void of_gpio_mux_clk_setup(struct device_node *node);
+
+/**
  * clk_register - allocate a new clock, register it and return an opaque cookie
  * @dev: device that is registering this clock
  * @hw: link to hardware-specific clock data
Signature · 1 line
1.9.1
#5 lore raw

PATCH v4 4/4 clk: Rename clk-gpio-gate.c to clk-gpio.c

In reply to Sergej Sawazki

The file clk-gpio-gate.c does not only contain the gate clock, but also the mux clock. Rename the file to clk-gpio.c.

---
 drivers/clk/Makefile        |   2 +-
 drivers/clk/clk-gpio-gate.c | 319 --------------------------------------------
 drivers/clk/clk-gpio.c      | 319 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 320 insertions(+), 320 deletions(-)
 delete mode 100644 drivers/clk/clk-gpio-gate.c
 create mode 100644 drivers/clk/clk-gpio.c
drivers/clk/Makefile +1 -1
index fc789a0..c917504 100644
@@ -9,7 +9,7 @@ obj-$(CONFIG_COMMON_CLK)	+= clk-gate.o
 obj-$(CONFIG_COMMON_CLK)	+= clk-mux.o
 obj-$(CONFIG_COMMON_CLK)	+= clk-composite.o
 obj-$(CONFIG_COMMON_CLK)	+= clk-fractional-divider.o
-obj-$(CONFIG_COMMON_CLK)	+= clk-gpio-gate.o
+obj-$(CONFIG_COMMON_CLK)	+= clk-gpio.o
 ifeq ($(CONFIG_OF), y)
 obj-$(CONFIG_COMMON_CLK)	+= clk-conf.o
 endif
drivers/clk/clk-gpio-gate.c deleted +0 -319

319 lines not on this page · raw message

drivers/clk/clk-gpio.c new file +319 -0

319 lines not on this page · raw message

Signature · 1 line
1.9.1
#1 lore raw

PATCH v4 1/4 clk: gpio-gate: Include export.h instead of module.h

In reply to Sergej Sawazki

Include export.h for EXPORT_SYMBOL_GPL, no need to include module.h.

---
 drivers/clk/clk-gpio-gate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/clk-gpio-gate.c +1 -1
index f564e62..a377f88 100644
@@ -10,7 +10,7 @@
  */
 
 #include <linux/clk-provider.h>
-#include <linux/module.h>
+#include <linux/export.h>
 #include <linux/slab.h>
 #include <linux/gpio.h>
 #include <linux/gpio/consumer.h>
Signature · 1 line
1.9.1
Applied
#6 lore raw

Re: [PATCH v4 4/4] clk: Rename clk-gpio-gate.c to clk-gpio.c

In reply to Sergej Sawazki
Quoted 6 lines · Sergej Sawazki

The file clk-gpio-gate.c does not only contain the gate clock, but also the mux clock. Rename the file to clk-gpio.c.

---

Applied to clk-next (but won't appear in -next until after rc1 drops).

Next time feel free to generate this sort of thing with -M -C so that the diff is much smaller.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#7 lore raw
In reply to Sergej Sawazki
Quoted 8 lines · Sergej Sawazki

This patch series adds a common clock driver for basic gpio controlled clock multiplexers. It does also contain some minor fixes for the gpio-gate-clock.

The first two patches are minor fixes for the gpio-gate-clock. Patch three refactors the file clk-gpio-gate.c and adds the new gpio-mux-clock driver. Finally, patch four renames the file clk-gpio-gate.c to clk-gpio.c.

Based on clk-next.

I applied all of them to clk-next but you won't see it in -next until rc1 drops.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#4 lore raw
In reply to Sergej Sawazki
Quoted 9 lines · Sergej Sawazki

Add a common clock driver for basic gpio controlled clock multiplexers. This driver can be used for devices like 5V41068A or 831721I from IDT or for discrete multiplexer circuits. The 'select' pin selects one of two parent clocks.

---

And this doesn't do a good job of freeing stuff on failure paths. I squashed this in

---8<---

drivers/clk/clk-gpio.c +8 -5
index 29d8917e8eeb..c0d202c24a97 100644
@@ -126,6 +126,9 @@ static struct clk *clk_register_gpio(struct device *dev, const char *name,
 		if (err != -EPROBE_DEFER)
 			pr_err("%s: %s: Error requesting clock control gpio %u\n",
 					__func__, name, gpio);
+		if (!dev)
+			kfree(clk_gpio);
+
 		return ERR_PTR(err);
 	}
 
@@ -147,8 +150,8 @@ static struct clk *clk_register_gpio(struct device *dev, const char *name,
 		return clk;
 
 	if (!dev) {
-		kfree(clk_gpio);
 		gpiod_put(clk_gpio->gpiod);
+		kfree(clk_gpio);
 	}
 
 	return clk;
@@ -256,13 +259,13 @@ static struct clk *of_clk_gpio_delayed_register_get(
 
 	clk = data->clk_register_get(data->node->name, parent_names,
 			num_parents, gpio, of_flags & OF_GPIO_ACTIVE_LOW);
-	if (IS_ERR(clk)) {
-		mutex_unlock(&data->lock);
-		return clk;
-	}
+	if (IS_ERR(clk))
+		goto out;
 
 	data->clk = clk;
+out:
 	mutex_unlock(&data->lock);
+	kfree(parent_names);
 
 	return clk;
 }
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project