linux-clk.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 05/41] ARM: s3c24xx: make S3C24XX_MISCCR access indirect
       [not found] <20200806181932.2253-1-krzk@kernel.org>
@ 2020-08-06 18:20 ` Krzysztof Kozlowski
  2020-08-12  7:53   ` Stephen Boyd
  2020-08-06 18:20 ` [PATCH v2 06/41] ARM: s3c24xx: pass pointer to clk driver via platform data Krzysztof Kozlowski
  1 sibling, 1 reply; 4+ messages in thread
From: Krzysztof Kozlowski @ 2020-08-06 18:20 UTC (permalink / raw)
  To: linux-kernel
  Cc: Arnd Bergmann, Krzysztof Kozlowski, Russell King,
	Sylwester Nawrocki, Tomasz Figa, Chanwoo Choi, Michael Turquette,
	Stephen Boyd, Kukjin Kim, linux-arm-kernel, linux-samsung-soc,
	linux-clk

From: Arnd Bergmann <arnd@arndb.de>

The clk driver uses both a function call into an exported
platform file and a direct register access to a hardcoded
virtual address for accessing the MISCCR register, both
become are a problem for a multiplatform kernel because
of the header file dependency.

Make this an indirect function call through platform data
instead.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
---
 arch/arm/mach-s3c24xx/common.c         |  3 +++
 drivers/clk/samsung/clk-s3c2410-dclk.c | 10 ++++------
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/arch/arm/mach-s3c24xx/common.c b/arch/arm/mach-s3c24xx/common.c
index 0d55e88ee0a8..222238e8acbb 100644
--- a/arch/arm/mach-s3c24xx/common.c
+++ b/arch/arm/mach-s3c24xx/common.c
@@ -668,5 +668,8 @@ struct platform_device s3c2410_device_dclk = {
 	.id		= 0,
 	.num_resources	= ARRAY_SIZE(s3c2410_dclk_resource),
 	.resource	= s3c2410_dclk_resource,
+	.dev		= {
+		.platform_data = s3c2410_modify_misccr,
+	},
 };
 #endif
diff --git a/drivers/clk/samsung/clk-s3c2410-dclk.c b/drivers/clk/samsung/clk-s3c2410-dclk.c
index 7dad9098e897..3e0f23e8ec21 100644
--- a/drivers/clk/samsung/clk-s3c2410-dclk.c
+++ b/drivers/clk/samsung/clk-s3c2410-dclk.c
@@ -14,10 +14,6 @@
 #include <linux/module.h>
 #include "clk.h"
 
-/* legacy access to misccr, until dt conversion is finished */
-#include <mach/hardware.h>
-#include <mach/regs-gpio.h>
-
 #define MUX_DCLK0	0
 #define MUX_DCLK1	1
 #define DIV_DCLK0	2
@@ -52,6 +48,7 @@ struct s3c24xx_clkout {
 	struct clk_hw		hw;
 	u32			mask;
 	u8			shift;
+	unsigned int (*modify_misccr)(unsigned int clr, unsigned int chg);
 };
 
 #define to_s3c24xx_clkout(_hw) container_of(_hw, struct s3c24xx_clkout, hw)
@@ -62,7 +59,7 @@ static u8 s3c24xx_clkout_get_parent(struct clk_hw *hw)
 	int num_parents = clk_hw_get_num_parents(hw);
 	u32 val;
 
-	val = readl_relaxed(S3C24XX_MISCCR) >> clkout->shift;
+	val = clkout->modify_misccr(0, 0) >> clkout->shift;
 	val >>= clkout->shift;
 	val &= clkout->mask;
 
@@ -76,7 +73,7 @@ static int s3c24xx_clkout_set_parent(struct clk_hw *hw, u8 index)
 {
 	struct s3c24xx_clkout *clkout = to_s3c24xx_clkout(hw);
 
-	s3c2410_modify_misccr((clkout->mask << clkout->shift),
+	clkout->modify_misccr((clkout->mask << clkout->shift),
 			      (index << clkout->shift));
 
 	return 0;
@@ -110,6 +107,7 @@ static struct clk_hw *s3c24xx_register_clkout(struct device *dev,
 	clkout->shift = shift;
 	clkout->mask = mask;
 	clkout->hw.init = &init;
+	clkout->modify_misccr = dev->platform_data;
 
 	ret = clk_hw_register(dev, &clkout->hw);
 	if (ret)
-- 
2.17.1


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

* [PATCH v2 06/41] ARM: s3c24xx: pass pointer to clk driver via platform data
       [not found] <20200806181932.2253-1-krzk@kernel.org>
  2020-08-06 18:20 ` [PATCH v2 05/41] ARM: s3c24xx: make S3C24XX_MISCCR access indirect Krzysztof Kozlowski
@ 2020-08-06 18:20 ` Krzysztof Kozlowski
  2020-08-12  7:55   ` Stephen Boyd
  1 sibling, 1 reply; 4+ messages in thread
From: Krzysztof Kozlowski @ 2020-08-06 18:20 UTC (permalink / raw)
  To: linux-kernel
  Cc: Arnd Bergmann, Krzysztof Kozlowski, Russell King,
	Sylwester Nawrocki, Tomasz Figa, Chanwoo Choi, Michael Turquette,
	Stephen Boyd, Kukjin Kim, linux-arm-kernel, linux-samsung-soc,
	linux-clk

Passing pointers directly as platform data is fragile and undocumented.
Better to create a platform data structure which explicitly documents
what is passed to the driver.

Suggested-by: Tomasz Figa <tomasz.figa@gmail.com>
[krzk: Update maintainer's entry]
Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>

---

Changes since v1:
1. Update maintainer's entry.
---
 MAINTAINERS                               |  1 +
 arch/arm/mach-s3c24xx/common.c            |  7 ++++++-
 drivers/clk/samsung/clk-s3c2410-dclk.c    |  7 ++++++-
 include/linux/platform_data/clk-s3c2410.h | 19 +++++++++++++++++++
 4 files changed, 32 insertions(+), 2 deletions(-)
 create mode 100644 include/linux/platform_data/clk-s3c2410.h

diff --git a/MAINTAINERS b/MAINTAINERS
index 5675fc9bfa00..81046738cba9 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -15295,6 +15295,7 @@ F:	Documentation/devicetree/bindings/clock/samsung,s5p*
 F:	drivers/clk/samsung/
 F:	include/dt-bindings/clock/exynos*.h
 F:	include/linux/clk/samsung.h
+F:	include/linux/platform_data/clk-s3c2410.h
 
 SAMSUNG SPI DRIVERS
 M:	Kukjin Kim <kgene@kernel.org>
diff --git a/arch/arm/mach-s3c24xx/common.c b/arch/arm/mach-s3c24xx/common.c
index 222238e8acbb..c476a673d07f 100644
--- a/arch/arm/mach-s3c24xx/common.c
+++ b/arch/arm/mach-s3c24xx/common.c
@@ -17,6 +17,7 @@
 #include <linux/platform_device.h>
 #include <linux/delay.h>
 #include <linux/io.h>
+#include <linux/platform_data/clk-s3c2410.h>
 #include <linux/platform_data/dma-s3c24xx.h>
 #include <linux/dmaengine.h>
 #include <linux/clk/samsung.h>
@@ -663,13 +664,17 @@ static struct resource s3c2410_dclk_resource[] = {
 	[0] = DEFINE_RES_MEM(0x56000084, 0x4),
 };
 
+static struct s3c2410_clk_platform_data s3c_clk_platform_data = {
+	.modify_misccr = s3c2410_modify_misccr,
+};
+
 struct platform_device s3c2410_device_dclk = {
 	.name		= "s3c2410-dclk",
 	.id		= 0,
 	.num_resources	= ARRAY_SIZE(s3c2410_dclk_resource),
 	.resource	= s3c2410_dclk_resource,
 	.dev		= {
-		.platform_data = s3c2410_modify_misccr,
+		.platform_data = &s3c_clk_platform_data,
 	},
 };
 #endif
diff --git a/drivers/clk/samsung/clk-s3c2410-dclk.c b/drivers/clk/samsung/clk-s3c2410-dclk.c
index 3e0f23e8ec21..f5e0a6ba2d12 100644
--- a/drivers/clk/samsung/clk-s3c2410-dclk.c
+++ b/drivers/clk/samsung/clk-s3c2410-dclk.c
@@ -11,6 +11,7 @@
 #include <linux/clk-provider.h>
 #include <linux/io.h>
 #include <linux/platform_device.h>
+#include <linux/platform_data/clk-s3c2410.h>
 #include <linux/module.h>
 #include "clk.h"
 
@@ -89,10 +90,14 @@ static struct clk_hw *s3c24xx_register_clkout(struct device *dev,
 		const char *name, const char **parent_names, u8 num_parents,
 		u8 shift, u32 mask)
 {
+	struct s3c2410_clk_platform_data *pdata = dev_get_platdata(dev);
 	struct s3c24xx_clkout *clkout;
 	struct clk_init_data init;
 	int ret;
 
+	if (!pdata)
+		return ERR_PTR(-EINVAL);
+
 	/* allocate the clkout */
 	clkout = kzalloc(sizeof(*clkout), GFP_KERNEL);
 	if (!clkout)
@@ -107,7 +112,7 @@ static struct clk_hw *s3c24xx_register_clkout(struct device *dev,
 	clkout->shift = shift;
 	clkout->mask = mask;
 	clkout->hw.init = &init;
-	clkout->modify_misccr = dev->platform_data;
+	clkout->modify_misccr = pdata->modify_misccr;
 
 	ret = clk_hw_register(dev, &clkout->hw);
 	if (ret)
diff --git a/include/linux/platform_data/clk-s3c2410.h b/include/linux/platform_data/clk-s3c2410.h
new file mode 100644
index 000000000000..7eb1cfa5409b
--- /dev/null
+++ b/include/linux/platform_data/clk-s3c2410.h
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2020 Krzysztof Kozlowski <krzk@kernel.org>
+ */
+
+#ifndef __LINUX_PLATFORM_DATA_CLK_S3C2410_H_
+#define __LINUX_PLATFORM_DATA_CLK_S3C2410_H_
+
+/**
+ * struct s3c2410_clk_platform_data - platform data for S3C2410 clock driver
+ *
+ * @modify_misccr: Function to modify the MISCCR and return the new value
+ */
+struct s3c2410_clk_platform_data {
+	unsigned int (*modify_misccr)(unsigned int clr, unsigned int chg);
+};
+
+#endif /* __LINUX_PLATFORM_DATA_CLK_S3C2410_H_ */
+
-- 
2.17.1


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

* Re: [PATCH v2 05/41] ARM: s3c24xx: make S3C24XX_MISCCR access indirect
  2020-08-06 18:20 ` [PATCH v2 05/41] ARM: s3c24xx: make S3C24XX_MISCCR access indirect Krzysztof Kozlowski
@ 2020-08-12  7:53   ` Stephen Boyd
  0 siblings, 0 replies; 4+ messages in thread
From: Stephen Boyd @ 2020-08-12  7:53 UTC (permalink / raw)
  To: Krzysztof Kozlowski, linux-kernel
  Cc: Arnd Bergmann, Krzysztof Kozlowski, Russell King,
	Sylwester Nawrocki, Tomasz Figa, Chanwoo Choi, Michael Turquette,
	Kukjin Kim, linux-arm-kernel, linux-samsung-soc, linux-clk

Quoting Krzysztof Kozlowski (2020-08-06 11:20:22)
> From: Arnd Bergmann <arnd@arndb.de>
> 
> The clk driver uses both a function call into an exported
> platform file and a direct register access to a hardcoded
> virtual address for accessing the MISCCR register, both
> become are a problem for a multiplatform kernel because
> of the header file dependency.
> 
> Make this an indirect function call through platform data
> instead.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
> ---

Reviewed-by: Stephen Boyd <sboyd@kernel.org>

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

* Re: [PATCH v2 06/41] ARM: s3c24xx: pass pointer to clk driver via platform data
  2020-08-06 18:20 ` [PATCH v2 06/41] ARM: s3c24xx: pass pointer to clk driver via platform data Krzysztof Kozlowski
@ 2020-08-12  7:55   ` Stephen Boyd
  0 siblings, 0 replies; 4+ messages in thread
From: Stephen Boyd @ 2020-08-12  7:55 UTC (permalink / raw)
  To: Krzysztof Kozlowski, linux-kernel
  Cc: Arnd Bergmann, Krzysztof Kozlowski, Russell King,
	Sylwester Nawrocki, Tomasz Figa, Chanwoo Choi, Michael Turquette,
	Kukjin Kim, linux-arm-kernel, linux-samsung-soc, linux-clk

Quoting Krzysztof Kozlowski (2020-08-06 11:20:23)
> Passing pointers directly as platform data is fragile and undocumented.
> Better to create a platform data structure which explicitly documents
> what is passed to the driver.
> 
> Suggested-by: Tomasz Figa <tomasz.figa@gmail.com>
> [krzk: Update maintainer's entry]
> Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
> 
> ---

Ok.

Reviewed-by: Stephen Boyd <sboyd@kernel.org>

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

end of thread, other threads:[~2020-08-12  7:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20200806181932.2253-1-krzk@kernel.org>
2020-08-06 18:20 ` [PATCH v2 05/41] ARM: s3c24xx: make S3C24XX_MISCCR access indirect Krzysztof Kozlowski
2020-08-12  7:53   ` Stephen Boyd
2020-08-06 18:20 ` [PATCH v2 06/41] ARM: s3c24xx: pass pointer to clk driver via platform data Krzysztof Kozlowski
2020-08-12  7:55   ` Stephen Boyd

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).