Skip to contentSkip to conversation

gpio controlled clock

RFC PATCH New Jyri Sarha 2 participants 7 messages Nov 1, 2013 – Nov 8, 2013

Subsystems (2)
lore
Share & tools
lore

Jyri Sarha

author
#0 lore raw

RFC PATCH 1/1 gpio controlled clock

The patch implements a basic clock that can be enabled and disabled trough a gpio output. There is such a clock at least on Beaglebone-Black and I need such a clock to implement HDMI audio support for the board. I just thought this simple driver could be useful for wider audience.

Best regards,
Jyri

Jyri Sarha (1):
clk: add gpio controlled clock

 .../devicetree/bindings/clock/gpio-clock.txt       |   21 +++
 drivers/clk/Makefile                               |    1 +
 drivers/clk/clk-gpio.c                             |  154 ++++++++++++++++++++
 include/linux/clk-provider.h                       |   25 ++++
 4 files changed, 201 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/gpio-clock.txt
 create mode 100644 drivers/clk/clk-gpio.c
Signature · 1 line
1.7.9.5
author
#1 lore raw

RFC PATCH 1/1 clk: add gpio controlled clock

The added clk-gpio is a basic clock that can be enabled and disabled trough a gpio output. The DT binding document for the clock is also added.

---
 .../devicetree/bindings/clock/gpio-clock.txt       |   21 +++
 drivers/clk/Makefile                               |    1 +
 drivers/clk/clk-gpio.c                             |  154 ++++++++++++++++++++
 include/linux/clk-provider.h                       |   25 ++++
 4 files changed, 201 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/gpio-clock.txt
 create mode 100644 drivers/clk/clk-gpio.c
Documentation/devicetree/bindings/clock/gpio-clock.txt new file +21 -0
new file mode 100644
index 0000000..54fea39
@@ -0,0 +1,21 @@
+Binding for simple gpio controlled clock.
+
+This binding uses the common clock binding[1].
+
+[1] Documentation/devicetree/bindings/clock/clock-bindings.txt
+
+Required properties:
+- compatible : shall be "gpio-clock".
+- #clock-cells : from common clock binding; shall be set to 0.
+- enable-gpios : GPIO reference for enabling and disabling the clock.
+
+Optional properties:
+- clocks: Maximum of one parent clock is supported.
+
+Example:
+	clock {
+		compatible = "gpio-clock";
+		clocks = <&parentclk>;
+		#clock-cells = <0>;
+		enable-gpios = <&gpio 1 GPIO_ACTIVE_HIGH>;
+	};
drivers/clk/Makefile +1 -0
index 7d74d06..81b65a3 100644
@@ -8,6 +8,7 @@ obj-$(CONFIG_COMMON_CLK)	+= clk-fixed-rate.o
 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-gpio.o
 
 # SoCs specific
 obj-$(CONFIG_ARCH_BCM2835)	+= clk-bcm2835.o
drivers/clk/clk-gpio.c new file +154 -0

154 lines not on this page · raw message

include/linux/clk-provider.h +25 -0
index 3493c76..f861568 100644
@@ -439,6 +439,31 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
 		struct clk_hw *gate_hw, const struct clk_ops *gate_ops,
 		unsigned long flags);
 
+/***
+ * struct clk_gpio - gpio controlled clock
+ *
+ * @hw:		handle between common and hardware-specific interfaces
+ * @gpio:	gpio
+ * @active_low:	gpio polarity
+ *
+ * Clock with a gpio control for enabling and disabling the parent clock.
+ * Implements .enable, .disable and .is_enabled
+ */
+
+struct clk_gpio {
+	struct clk_hw	hw;
+	unsigned int	gpio;
+	bool		active_low;
+};
+
+extern const struct clk_ops clk_gpio_ops;
+
+struct clk *clk_register_gpio(struct device *dev, const char *name,
+		const char *parent_name, unsigned long flags,
+		unsigned int gpio, bool active_low);
+
+void of_gpio_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
Signature · 1 line
1.7.9.5
#2 lore raw

RFC PATCH 1/1 clk: add gpio controlled clock

Hi,

Quoted 19 lines · Jyri Sarha

The added clk-gpio is a basic clock that can be enabled and disabled trough a gpio output. The DT binding document for the clock is also added.

---
 .../devicetree/bindings/clock/gpio-clock.txt       |   21 +++
 drivers/clk/Makefile                               |    1 +
 drivers/clk/clk-gpio.c                             |  154 ++++++++++++++++++++
 include/linux/clk-provider.h                       |   25 ++++
 4 files changed, 201 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/gpio-clock.txt
 create mode 100644 drivers/clk/clk-gpio.c
Documentation/devicetree/bindings/clock/gpio-clock.txt new file +0 -0
new file mode 100644
index 0000000..54fea39

[...]

Quoted 20 lines
Documentation/devicetree/bindings/clock/gpio-clock.txt new file +19 -0
+/**
+ * clk_register_gpio - register a gpip clock with the clock framework
+ * @dev: device that is registering this clock
+ * @name: name of this clock
+ * @parent_name: name of this clock's parent
+ * @flags: framework-specific flags for this clock
+ * @gpio: gpio to control this clock
+ * @active_low: gpio polarity
+ */
+struct clk *clk_register_gpio(struct device *dev, const char *name,
+		const char *parent_name, unsigned long flags,
+		unsigned int gpio, bool active_low)
+{
+	struct clk_gpio *clk_gpio;
+	struct clk *clk;
+	struct clk_init_data init = { NULL };
+	unsigned long gpio_flags;
+	int err;
+

Documentation/devicetree/bindings/clock/gpio-clock.txt

Quoted 10 lines
Documentation/devicetree/bindings/clock/gpio-clock.txt new file +10 -0
+	if (active_low)
+		gpio_flags = GPIOF_OUT_INIT_LOW;
+	else
+		gpio_flags = GPIOF_OUT_INIT_HIGH;
+
+	err = gpio_request_one(gpio, gpio_flags, name);
+	if (err) {
+		pr_err("%s: Error requesting clock control gpio %u\n",
+		       __func__, gpio);
+		return ERR_PTR(-EINVAL);

You already have an error code from the gpio_request_one() call. Why return a different one?

Documentation/devicetree/bindings/clock/gpio-clock.txt

Quoted 3 lines
Documentation/devicetree/bindings/clock/gpio-clock.txt new file +2 -0
+
+	clk_gpio = kzalloc(sizeof(struct clk_gpio), GFP_KERNEL);

devm_kzalloc()?

Lothar Wa?mann

Signature · 9 lines
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstra?e 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Gesch?ftsf?hrer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | info at karo-electronics.de
___________________________________________________________
#3 lore raw

RFC PATCH 1/1 clk: add gpio controlled clock

Quoted 1 line

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

-----Original Message-----

Quoted 7 lines

From: Lothar Wa?mann [mailto:LW at KARO-electronics.de]
Sent: Monday, November 04, 2013 9:42 AM

Hi,

Quoted 1 line · Jyri Sarha

The added clk-gpio is a basic clock that can be enabled and disabled

...

Quoted 8 lines

drivers/clk/clk-gpio.c line 92

Quoted 6 lines
drivers/clk/clk-gpio.c new file +5 -0
+    err = gpio_request_one(gpio, gpio_flags, name);
+    if (err) {
+            pr_err("%s: Error requesting clock control gpio %u\n",
+                   __func__, gpio);
+            return ERR_PTR(-EINVAL);

You already have an error code from the gpio_request_one() call. Why return a different one?

I was just thinking the gpio number is more useful for debugging that the error code. Could print the both of cource.

Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+    clk_gpio = kzalloc(sizeof(struct clk_gpio), GFP_KERNEL);

devm_kzalloc()?

Good point. I'll change that.

Thanks,
Jyri

#4 lore raw

RFC PATCH 1/1 clk: add gpio controlled clock

Hi,

Quoted 18 lines · Jyri
Quoted 1 line

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

-----Original Message-----

Quoted 7 lines

From: Lothar Wa?mann [mailto:LW at KARO-electronics.de]
Sent: Monday, November 04, 2013 9:42 AM

Hi,

Quoted 1 line · Jyri Sarha

The added clk-gpio is a basic clock that can be enabled and disabled

...

Quoted 6 lines
Quoted 6 lines
drivers/clk/clk-gpio.c new file +5 -0
+    err = gpio_request_one(gpio, gpio_flags, name);
+    if (err) {
+            pr_err("%s: Error requesting clock control gpio %u\n",
+                   __func__, gpio);
+            return ERR_PTR(-EINVAL);
Quoted 5 lines
Quoted 2 lines

You already have an error code from the gpio_request_one() call. Why return a different one?

I was just thinking the gpio number is more useful for debugging that the error code. Could print the both of cource.

I wasn't talking about the error message, but the return value of the function!

Lothar Wa?mann

Signature · 9 lines
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstra?e 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Gesch?ftsf?hrer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | info at karo-electronics.de
___________________________________________________________
author
#5 lore raw

RFC PATCH v2 1/1 clk: add gpio controlled clock

In reply to Lothar Waßmann

The added clk-gpio is a basic clock that can be enabled and disabled trough a gpio output. The DT binding document for the clock is also added.

---
 .../devicetree/bindings/clock/gpio-clock.txt       |   21 +++
 drivers/clk/Makefile                               |    1 +
 drivers/clk/clk-gpio.c                             |  155 ++++++++++++++++++++
 include/linux/clk-provider.h                       |   25 ++++
 4 files changed, 202 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/gpio-clock.txt
 create mode 100644 drivers/clk/clk-gpio.c
Documentation/devicetree/bindings/clock/gpio-clock.txt new file +21 -0
new file mode 100644
index 0000000..54fea39
@@ -0,0 +1,21 @@
+Binding for simple gpio controlled clock.
+
+This binding uses the common clock binding[1].
+
+[1] Documentation/devicetree/bindings/clock/clock-bindings.txt
+
+Required properties:
+- compatible : shall be "gpio-clock".
+- #clock-cells : from common clock binding; shall be set to 0.
+- enable-gpios : GPIO reference for enabling and disabling the clock.
+
+Optional properties:
+- clocks: Maximum of one parent clock is supported.
+
+Example:
+	clock {
+		compatible = "gpio-clock";
+		clocks = <&parentclk>;
+		#clock-cells = <0>;
+		enable-gpios = <&gpio 1 GPIO_ACTIVE_HIGH>;
+	};
drivers/clk/Makefile +1 -0
index 7d74d06..81b65a3 100644
@@ -8,6 +8,7 @@ obj-$(CONFIG_COMMON_CLK)	+= clk-fixed-rate.o
 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-gpio.o
 
 # SoCs specific
 obj-$(CONFIG_ARCH_BCM2835)	+= clk-bcm2835.o
drivers/clk/clk-gpio.c new file +155 -0

155 lines not on this page · raw message

include/linux/clk-provider.h +25 -0
index 3493c76..f861568 100644
@@ -439,6 +439,31 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
 		struct clk_hw *gate_hw, const struct clk_ops *gate_ops,
 		unsigned long flags);
 
+/***
+ * struct clk_gpio - gpio controlled clock
+ *
+ * @hw:		handle between common and hardware-specific interfaces
+ * @gpio:	gpio
+ * @active_low:	gpio polarity
+ *
+ * Clock with a gpio control for enabling and disabling the parent clock.
+ * Implements .enable, .disable and .is_enabled
+ */
+
+struct clk_gpio {
+	struct clk_hw	hw;
+	unsigned int	gpio;
+	bool		active_low;
+};
+
+extern const struct clk_ops clk_gpio_ops;
+
+struct clk *clk_register_gpio(struct device *dev, const char *name,
+		const char *parent_name, unsigned long flags,
+		unsigned int gpio, bool active_low);
+
+void of_gpio_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
Signature · 1 line
1.7.9.5
author
#6 lore raw

RFC PATCH v3 1/1 clk: add gpio controlled clock

In reply to Jyri Sarha

The added clk-gpio is a basic clock that can be enabled and disabled trough a gpio output. The DT binding document for the clock is also added. For EPROBE_DEFER handling the registering of the clock has to be delayed until of_clk_get() call time.

CC t-kristo at ti.com
---
 .../devicetree/bindings/clock/gpio-clock.txt       |   21 ++
 drivers/clk/Makefile                               |    1 +
 drivers/clk/clk-gpio.c                             |  211 ++++++++++++++++++++
 include/linux/clk-provider.h                       |   25 +++
 4 files changed, 258 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/gpio-clock.txt
 create mode 100644 drivers/clk/clk-gpio.c
Documentation/devicetree/bindings/clock/gpio-clock.txt new file +21 -0
new file mode 100644
index 0000000..54fea39
@@ -0,0 +1,21 @@
+Binding for simple gpio controlled clock.
+
+This binding uses the common clock binding[1].
+
+[1] Documentation/devicetree/bindings/clock/clock-bindings.txt
+
+Required properties:
+- compatible : shall be "gpio-clock".
+- #clock-cells : from common clock binding; shall be set to 0.
+- enable-gpios : GPIO reference for enabling and disabling the clock.
+
+Optional properties:
+- clocks: Maximum of one parent clock is supported.
+
+Example:
+	clock {
+		compatible = "gpio-clock";
+		clocks = <&parentclk>;
+		#clock-cells = <0>;
+		enable-gpios = <&gpio 1 GPIO_ACTIVE_HIGH>;
+	};
drivers/clk/Makefile +1 -0
index 7d74d06..81b65a3 100644
@@ -8,6 +8,7 @@ obj-$(CONFIG_COMMON_CLK)	+= clk-fixed-rate.o
 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-gpio.o
 
 # SoCs specific
 obj-$(CONFIG_ARCH_BCM2835)	+= clk-bcm2835.o
drivers/clk/clk-gpio.c new file +211 -0

211 lines not on this page · raw message

include/linux/clk-provider.h +25 -0
index 3493c76..f861568 100644
@@ -439,6 +439,31 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
 		struct clk_hw *gate_hw, const struct clk_ops *gate_ops,
 		unsigned long flags);
 
+/***
+ * struct clk_gpio - gpio controlled clock
+ *
+ * @hw:		handle between common and hardware-specific interfaces
+ * @gpio:	gpio
+ * @active_low:	gpio polarity
+ *
+ * Clock with a gpio control for enabling and disabling the parent clock.
+ * Implements .enable, .disable and .is_enabled
+ */
+
+struct clk_gpio {
+	struct clk_hw	hw;
+	unsigned int	gpio;
+	bool		active_low;
+};
+
+extern const struct clk_ops clk_gpio_ops;
+
+struct clk *clk_register_gpio(struct device *dev, const char *name,
+		const char *parent_name, unsigned long flags,
+		unsigned int gpio, bool active_low);
+
+void of_gpio_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
Signature · 1 line
1.7.9.5