All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/5] drivers/sh/clk: add support for CLK_SET_TO_ENABLE flag
@ 2018-03-26 21:25 Thomas Petazzoni
  2018-03-27  7:08 ` Geert Uytterhoeven
  0 siblings, 1 reply; 2+ messages in thread
From: Thomas Petazzoni @ 2018-03-26 21:25 UTC (permalink / raw)
  To: linux-sh

The current sh_clk_mstp_{enable,disable} functions assume that
enable_bit must be cleared to enable the clock, and set to disable the
clock.

However, this clock type is used for the PHY of the SH7786 PCIe
controller, which has the opposite polarity: set to enable, clear to
disable. In order to properly support this clock, we introduce a
CLK_SET_TO_ENABLE flag.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
---
 drivers/sh/clk/cpg.c   | 10 ++++++++--
 include/linux/sh_clk.h |  2 ++
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/sh/clk/cpg.c b/drivers/sh/clk/cpg.c
index 7442bc130055..ecb1ab9a8f1d 100644
--- a/drivers/sh/clk/cpg.c
+++ b/drivers/sh/clk/cpg.c
@@ -53,7 +53,10 @@ static unsigned int r32(const void __iomem *addr)
 
 static int sh_clk_mstp_enable(struct clk *clk)
 {
-	sh_clk_write(sh_clk_read(clk) & ~(1 << clk->enable_bit), clk);
+	if (clk->flags & CLK_SET_TO_ENABLE)
+		sh_clk_write(sh_clk_read(clk) | (1 << clk->enable_bit), clk);
+	else
+		sh_clk_write(sh_clk_read(clk) & ~(1 << clk->enable_bit), clk);
 	if (clk->status_reg) {
 		unsigned int (*read)(const void __iomem *addr);
 		int i;
@@ -82,7 +85,10 @@ static int sh_clk_mstp_enable(struct clk *clk)
 
 static void sh_clk_mstp_disable(struct clk *clk)
 {
-	sh_clk_write(sh_clk_read(clk) | (1 << clk->enable_bit), clk);
+	if (clk->flags & CLK_SET_TO_ENABLE)
+		sh_clk_write(sh_clk_read(clk) & ~(1 << clk->enable_bit), clk);
+	else
+		sh_clk_write(sh_clk_read(clk) | (1 << clk->enable_bit), clk);
 }
 
 static struct sh_clk_ops sh_clk_mstp_clk_ops = {
diff --git a/include/linux/sh_clk.h b/include/linux/sh_clk.h
index 7bed5be886c6..0413570a7141 100644
--- a/include/linux/sh_clk.h
+++ b/include/linux/sh_clk.h
@@ -73,6 +73,8 @@ struct clk {
 
 #define CLK_MASK_DIV_ON_DISABLE	BIT(4)
 
+#define CLK_SET_TO_ENABLE	BIT(5)
+
 #define CLK_ENABLE_REG_MASK	(CLK_ENABLE_REG_32BIT | \
 				 CLK_ENABLE_REG_16BIT | \
 				 CLK_ENABLE_REG_8BIT)
-- 
2.14.3


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

* Re: [PATCH 1/5] drivers/sh/clk: add support for CLK_SET_TO_ENABLE flag
  2018-03-26 21:25 [PATCH 1/5] drivers/sh/clk: add support for CLK_SET_TO_ENABLE flag Thomas Petazzoni
@ 2018-03-27  7:08 ` Geert Uytterhoeven
  0 siblings, 0 replies; 2+ messages in thread
From: Geert Uytterhoeven @ 2018-03-27  7:08 UTC (permalink / raw)
  To: linux-sh

Hi Thomas,

Thanks for your patch!

On Mon, Mar 26, 2018 at 11:25 PM, Thomas Petazzoni
<thomas.petazzoni@bootlin.com> wrote:
> The current sh_clk_mstp_{enable,disable} functions assume that
> enable_bit must be cleared to enable the clock, and set to disable the
> clock.

Correct, mstp stands for "Module SToP".

> However, this clock type is used for the PHY of the SH7786 PCIe
> controller, which has the opposite polarity: set to enable, clear to
> disable. In order to properly support this clock, we introduce a
> CLK_SET_TO_ENABLE flag.

I think the correct solution is to not model the PHY clock as an MSTP clock,
so you don't need to pollute the MSTP clock driver with foreign clock support.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

end of thread, other threads:[~2018-03-27  7:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-26 21:25 [PATCH 1/5] drivers/sh/clk: add support for CLK_SET_TO_ENABLE flag Thomas Petazzoni
2018-03-27  7:08 ` Geert Uytterhoeven

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.