ARM: s3c24xx: pass pointer to clk driver via platform data
authorKrzysztof Kozlowski <krzk@kernel.org>
Thu, 6 Aug 2020 18:20:23 +0000 (20:20 +0200)
committerKrzysztof Kozlowski <krzk@kernel.org>
Wed, 19 Aug 2020 18:58:10 +0000 (20:58 +0200)
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>
Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Stephen Boyd <sboyd@kernel.org>
Link: https://lore.kernel.org/r/20200806182059.2431-6-krzk@kernel.org
MAINTAINERS
arch/arm/mach-s3c24xx/common.c
drivers/clk/samsung/clk-s3c2410-dclk.c
include/linux/platform_data/clk-s3c2410.h [new file with mode: 0644]

index d6abe0cc1a5dcfc34c3df658ac3eeb1619ada515..45906c58ff4ada7a1431d490e6fb1b37ad122bbf 100644 (file)
@@ -15305,6 +15305,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>
index 222238e8acbb24fc7c1c1fb3eddfdcf340b46833..c476a673d07ffc55af258d69a0a84a5bac213213 100644 (file)
@@ -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
index 3e0f23e8ec21df45cea0ba0714aa2d1d4c4d66e5..f5e0a6ba2d12b701d26dcb03d9440474f65ec33d 100644 (file)
@@ -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 (file)
index 0000000..7eb1cfa
--- /dev/null
@@ -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_ */
+