linux-clk.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] clk: clk-gpio: add support for sleeping GPIOs in gpio-gate-clk
@ 2019-02-11 13:58 Thomas Petazzoni
  2019-02-13 17:14 ` Stephen Boyd
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Petazzoni @ 2019-02-11 13:58 UTC (permalink / raw)
  To: Michael Turquette, Stephen Boyd; +Cc: linux-clk, linux-kernel, Thomas Petazzoni

The current implementation of gpio-gate-clk enables/disables the clock
using the GPIO in the ->enable() and ->disable() clock callbacks. This
requires the GPIO to be configurable in atomic contexts. While it is
the case for most memory-mapped GPIO controllers, it is not the case
for GPIO expanders on I2C or SPI.

This commit extends the gpio-gate-clk to check whether the GPIO calls
require sleeping or not. If sleeping is not required, the current
implementation based on ->enable()/->disable() is kept. However, if
sleeping is needed, we instead implement the logic in the ->prepare()
and ->unprepare() hooks. Thanks to this, a gate clock connected to a
GPIO on a GPIO expander can be controlled with the existing driver.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
---
 drivers/clk/clk-gpio.c | 39 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 37 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/clk-gpio.c b/drivers/clk/clk-gpio.c
index 6a43ce420492..f5d481713c7d 100644
--- a/drivers/clk/clk-gpio.c
+++ b/drivers/clk/clk-gpio.c
@@ -61,6 +61,35 @@ const struct clk_ops clk_gpio_gate_ops = {
 };
 EXPORT_SYMBOL_GPL(clk_gpio_gate_ops);
 
+static int clk_sleeping_gpio_gate_prepare(struct clk_hw *hw)
+{
+	struct clk_gpio *clk = to_clk_gpio(hw);
+
+	gpiod_set_value_cansleep(clk->gpiod, 1);
+
+	return 0;
+}
+
+static void clk_sleeping_gpio_gate_unprepare(struct clk_hw *hw)
+{
+	struct clk_gpio *clk = to_clk_gpio(hw);
+
+	gpiod_set_value_cansleep(clk->gpiod, 0);
+}
+
+static int clk_sleeping_gpio_gate_is_prepared(struct clk_hw *hw)
+{
+	struct clk_gpio *clk = to_clk_gpio(hw);
+
+	return gpiod_get_value_cansleep(clk->gpiod);
+}
+
+const struct clk_ops clk_sleeping_gpio_gate_ops = {
+	.prepare = clk_sleeping_gpio_gate_prepare,
+	.unprepare = clk_sleeping_gpio_gate_unprepare,
+	.is_prepared = clk_sleeping_gpio_gate_is_prepared,
+};
+
 /**
  * DOC: basic clock multiplexer which can be controlled with a gpio output
  * Traits of this clock:
@@ -147,10 +176,16 @@ struct clk_hw *clk_hw_register_gpio_gate(struct device *dev, const char *name,
 		const char *parent_name, struct gpio_desc *gpiod,
 		unsigned long flags)
 {
+	const struct clk_ops *ops;
+
+	if (gpiod_cansleep(gpiod))
+		ops = &clk_sleeping_gpio_gate_ops;
+	else
+		ops = &clk_gpio_gate_ops;
+
 	return clk_register_gpio(dev, name,
 			(parent_name ? &parent_name : NULL),
-			(parent_name ? 1 : 0), gpiod, flags,
-			&clk_gpio_gate_ops);
+			(parent_name ? 1 : 0), gpiod, flags, ops);
 }
 EXPORT_SYMBOL_GPL(clk_hw_register_gpio_gate);
 
-- 
2.20.1


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

* Re: [PATCH] clk: clk-gpio: add support for sleeping GPIOs in gpio-gate-clk
  2019-02-11 13:58 [PATCH] clk: clk-gpio: add support for sleeping GPIOs in gpio-gate-clk Thomas Petazzoni
@ 2019-02-13 17:14 ` Stephen Boyd
  2019-02-21 22:05   ` Stephen Boyd
  0 siblings, 1 reply; 4+ messages in thread
From: Stephen Boyd @ 2019-02-13 17:14 UTC (permalink / raw)
  To: Michael Turquette, Thomas Petazzoni
  Cc: linux-clk, linux-kernel, Thomas Petazzoni

Quoting Thomas Petazzoni (2019-02-11 05:58:18)
> The current implementation of gpio-gate-clk enables/disables the clock
> using the GPIO in the ->enable() and ->disable() clock callbacks. This
> requires the GPIO to be configurable in atomic contexts. While it is
> the case for most memory-mapped GPIO controllers, it is not the case
> for GPIO expanders on I2C or SPI.
> 
> This commit extends the gpio-gate-clk to check whether the GPIO calls
> require sleeping or not. If sleeping is not required, the current
> implementation based on ->enable()/->disable() is kept. However, if
> sleeping is needed, we instead implement the logic in the ->prepare()
> and ->unprepare() hooks. Thanks to this, a gate clock connected to a
> GPIO on a GPIO expander can be controlled with the existing driver.
> 
> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>

Sounds like a good idea!

> diff --git a/drivers/clk/clk-gpio.c b/drivers/clk/clk-gpio.c
> index 6a43ce420492..f5d481713c7d 100644
> --- a/drivers/clk/clk-gpio.c
> +++ b/drivers/clk/clk-gpio.c
> @@ -61,6 +61,35 @@ const struct clk_ops clk_gpio_gate_ops = {
>  };
>  EXPORT_SYMBOL_GPL(clk_gpio_gate_ops);
>  
> +static int clk_sleeping_gpio_gate_prepare(struct clk_hw *hw)
> +{
> +       struct clk_gpio *clk = to_clk_gpio(hw);
> +
> +       gpiod_set_value_cansleep(clk->gpiod, 1);
> +
> +       return 0;
> +}
> +
> +static void clk_sleeping_gpio_gate_unprepare(struct clk_hw *hw)
> +{
> +       struct clk_gpio *clk = to_clk_gpio(hw);
> +
> +       gpiod_set_value_cansleep(clk->gpiod, 0);
> +}
> +
> +static int clk_sleeping_gpio_gate_is_prepared(struct clk_hw *hw)
> +{
> +       struct clk_gpio *clk = to_clk_gpio(hw);
> +
> +       return gpiod_get_value_cansleep(clk->gpiod);
> +}
> +
> +const struct clk_ops clk_sleeping_gpio_gate_ops = {

static?

> +       .prepare = clk_sleeping_gpio_gate_prepare,
> +       .unprepare = clk_sleeping_gpio_gate_unprepare,
> +       .is_prepared = clk_sleeping_gpio_gate_is_prepared,
> +};
> +
>  /**
>   * DOC: basic clock multiplexer which can be controlled with a gpio output
>   * Traits of this clock:

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

* Re: [PATCH] clk: clk-gpio: add support for sleeping GPIOs in gpio-gate-clk
  2019-02-13 17:14 ` Stephen Boyd
@ 2019-02-21 22:05   ` Stephen Boyd
  2019-02-22  8:37     ` Thomas Petazzoni
  0 siblings, 1 reply; 4+ messages in thread
From: Stephen Boyd @ 2019-02-21 22:05 UTC (permalink / raw)
  To: Michael Turquette, Thomas Petazzoni
  Cc: linux-clk, linux-kernel, Thomas Petazzoni

Quoting Stephen Boyd (2019-02-13 09:14:22)
> 
> static?
> 

Ok I marked it static and applied to clk-next.


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

* Re: [PATCH] clk: clk-gpio: add support for sleeping GPIOs in gpio-gate-clk
  2019-02-21 22:05   ` Stephen Boyd
@ 2019-02-22  8:37     ` Thomas Petazzoni
  0 siblings, 0 replies; 4+ messages in thread
From: Thomas Petazzoni @ 2019-02-22  8:37 UTC (permalink / raw)
  To: Stephen Boyd; +Cc: Michael Turquette, linux-clk, linux-kernel

Hello,

On Thu, 21 Feb 2019 14:05:09 -0800
Stephen Boyd <sboyd@kernel.org> wrote:

> Quoting Stephen Boyd (2019-02-13 09:14:22)
> > 
> > static?
> 
> Ok I marked it static and applied to clk-next.

Thanks, and sorry for not getting back with a v2 in a timely fashion. I
had several patch series in-flight for this project, and for several of
them, additional iterations were needed, so I kind of lost track of
this one. Sorry about that.

Thanks again,

Thomas
-- 
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

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

end of thread, other threads:[~2019-02-22  8:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-11 13:58 [PATCH] clk: clk-gpio: add support for sleeping GPIOs in gpio-gate-clk Thomas Petazzoni
2019-02-13 17:14 ` Stephen Boyd
2019-02-21 22:05   ` Stephen Boyd
2019-02-22  8:37     ` Thomas Petazzoni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).