[PATCH 3/9] clk: realtek: Introduce a common probe()

Yu-Chun Lin posted 9 patches 1 month, 1 week ago
There is a newer version of this series
[PATCH 3/9] clk: realtek: Introduce a common probe()
Posted by Yu-Chun Lin 1 month, 1 week ago
Add rtk_clk_probe() to set up the shared regmap, register clock hardware,
add the clock provider, and optionally register a reset controller when
reset bank data is provided.

Signed-off-by: Cheng-Yu Lee <cylee12@realtek.com>
Signed-off-by: Yu-Chun Lin <eleanor.lin@realtek.com>
---
 drivers/clk/realtek/Makefile |  1 +
 drivers/clk/realtek/common.c | 72 ++++++++++++++++++++++++++++++++++++
 drivers/clk/realtek/common.h | 40 ++++++++++++++++++++
 3 files changed, 113 insertions(+)
 create mode 100644 drivers/clk/realtek/common.c
 create mode 100644 drivers/clk/realtek/common.h

diff --git a/drivers/clk/realtek/Makefile b/drivers/clk/realtek/Makefile
index 52267de2eef4..4041951b7c62 100644
--- a/drivers/clk/realtek/Makefile
+++ b/drivers/clk/realtek/Makefile
@@ -1,4 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0-only
 obj-$(CONFIG_RTK_CLK_COMMON) += clk-rtk.o
 
+clk-rtk-y += common.o
 clk-rtk-y += reset.o
diff --git a/drivers/clk/realtek/common.c b/drivers/clk/realtek/common.c
new file mode 100644
index 000000000000..df89d2a10291
--- /dev/null
+++ b/drivers/clk/realtek/common.c
@@ -0,0 +1,72 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2019 Realtek Semiconductor Corporation
+ * Author: Cheng-Yu Lee <cylee12@realtek.com>
+ */
+
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/mfd/syscon.h>
+#include <linux/platform_device.h>
+#include "common.h"
+
+int rtk_clk_probe(struct platform_device *pdev, const struct rtk_clk_desc *desc)
+{
+	int i, ret;
+	struct device *dev = &pdev->dev;
+	struct rtk_reset_initdata reset_initdata = { 0 };
+
+	struct regmap *regmap = device_node_to_regmap(pdev->dev.of_node);
+
+	if (IS_ERR(regmap)) {
+		ret = PTR_ERR(regmap);
+		dev_err(dev, "Failed to get regmap: %d\n", ret);
+		return ret;
+	}
+
+	for (i = 0; i < desc->num_clks; i++)
+		desc->clks[i]->regmap = regmap;
+
+	for (i = 0; i < desc->clk_data->num; i++) {
+		struct clk_hw *hw = desc->clk_data->hws[i];
+
+		if (!hw)
+			continue;
+
+		ret = devm_clk_hw_register(dev, hw);
+
+		if (ret) {
+			dev_warn(dev, "failed to register hw of clk%d: %d\n", i,
+				 ret);
+			desc->clk_data->hws[i] = NULL;
+		}
+	}
+
+	ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
+					  desc->clk_data);
+
+	if (ret) {
+		dev_err(dev, "Failed to add clock provider\n");
+		return ret;
+	}
+
+	if (!desc->num_reset_banks)
+		return 0;
+
+	if (!desc->reset_banks) {
+		dev_err(dev,
+			"Missing reset banks data though num_reset_banks is %lu\n",
+			desc->num_reset_banks);
+		return -EINVAL;
+	}
+
+	reset_initdata.regmap = regmap;
+	reset_initdata.num_banks = desc->num_reset_banks;
+	reset_initdata.banks = desc->reset_banks;
+
+	return rtk_reset_controller_add(dev, &reset_initdata);
+}
+EXPORT_SYMBOL_GPL(rtk_clk_probe);
+
+MODULE_DESCRIPTION("Realtek clock infrastructure");
+MODULE_LICENSE("GPL");
diff --git a/drivers/clk/realtek/common.h b/drivers/clk/realtek/common.h
new file mode 100644
index 000000000000..7b700f144e9e
--- /dev/null
+++ b/drivers/clk/realtek/common.h
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2016-2019 Realtek Semiconductor Corporation
+ * Author: Cheng-Yu Lee <cylee12@realtek.com>
+ */
+
+#ifndef __CLK_REALTEK_COMMON_H
+#define __CLK_REALTEK_COMMON_H
+
+#include <linux/clk-provider.h>
+#include <linux/device.h>
+#include <linux/hwspinlock.h>
+#include <linux/io.h>
+#include <linux/of.h>
+#include <linux/regmap.h>
+#include "reset.h"
+
+struct device;
+struct platform_device;
+
+struct clk_regmap {
+	struct clk_hw hw;
+	struct regmap *regmap;
+};
+
+#define to_clk_regmap(_hw) container_of(_hw, struct clk_regmap, hw)
+#define __clk_regmap_hw(_p) ((_p)->hw)
+
+struct rtk_clk_desc {
+	struct clk_hw_onecell_data *clk_data;
+	struct clk_regmap **clks;
+	size_t num_clks;
+	struct rtk_reset_bank *reset_banks;
+	size_t num_reset_banks;
+};
+
+int rtk_clk_probe(struct platform_device *pdev,
+		  const struct rtk_clk_desc *desc);
+
+#endif /* __CLK_REALTEK_COMMON_H */
-- 
2.34.1
Re: [PATCH 3/9] clk: realtek: Introduce a common probe()
Posted by kernel test robot 1 month, 1 week ago
Hi Yu-Chun,

kernel test robot noticed the following build warnings:

[auto build test WARNING on clk/clk-next]
[also build test WARNING on linus/master v6.19-rc3 next-20251219]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Yu-Chun-Lin/dt-bindings-clock-Add-Realtek-RTD1625-Clock-Reset-Controller/20251229-155549
base:   https://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git clk-next
patch link:    https://lore.kernel.org/r/20251229075313.27254-4-eleanor.lin%40realtek.com
patch subject: [PATCH 3/9] clk: realtek: Introduce a common probe()
config: arc-randconfig-002-20251231 (https://download.01.org/0day-ci/archive/20251231/202512310241.H75NfTMw-lkp@intel.com/config)
compiler: arc-linux-gcc (GCC) 8.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251231/202512310241.H75NfTMw-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202512310241.H75NfTMw-lkp@intel.com/

All warnings (new ones prefixed by >>):

   In file included from include/linux/device.h:15,
                    from drivers/clk/realtek/common.c:7:
   drivers/clk/realtek/common.c: In function 'rtk_clk_probe':
>> drivers/clk/realtek/common.c:58:4: warning: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type 'size_t' {aka 'const unsigned int'} [-Wformat=]
       "Missing reset banks data though num_reset_banks is %lu\n",
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/dev_printk.h:110:16: note: in definition of macro 'dev_printk_index_wrap'
      _p_func(dev, fmt, ##__VA_ARGS__);   \
                   ^~~
   include/linux/dev_printk.h:154:49: note: in expansion of macro 'dev_fmt'
     dev_printk_index_wrap(_dev_err, KERN_ERR, dev, dev_fmt(fmt), ##__VA_ARGS__)
                                                    ^~~~~~~
   drivers/clk/realtek/common.c:57:3: note: in expansion of macro 'dev_err'
      dev_err(dev,
      ^~~~~~~


vim +58 drivers/clk/realtek/common.c

    12	
    13	int rtk_clk_probe(struct platform_device *pdev, const struct rtk_clk_desc *desc)
    14	{
    15		int i, ret;
    16		struct device *dev = &pdev->dev;
    17		struct rtk_reset_initdata reset_initdata = { 0 };
    18	
    19		struct regmap *regmap = device_node_to_regmap(pdev->dev.of_node);
    20	
    21		if (IS_ERR(regmap)) {
    22			ret = PTR_ERR(regmap);
    23			dev_err(dev, "Failed to get regmap: %d\n", ret);
    24			return ret;
    25		}
    26	
    27		for (i = 0; i < desc->num_clks; i++)
    28			desc->clks[i]->regmap = regmap;
    29	
    30		for (i = 0; i < desc->clk_data->num; i++) {
    31			struct clk_hw *hw = desc->clk_data->hws[i];
    32	
    33			if (!hw)
    34				continue;
    35	
    36			ret = devm_clk_hw_register(dev, hw);
    37	
    38			if (ret) {
    39				dev_warn(dev, "failed to register hw of clk%d: %d\n", i,
    40					 ret);
    41				desc->clk_data->hws[i] = NULL;
    42			}
    43		}
    44	
    45		ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
    46						  desc->clk_data);
    47	
    48		if (ret) {
    49			dev_err(dev, "Failed to add clock provider\n");
    50			return ret;
    51		}
    52	
    53		if (!desc->num_reset_banks)
    54			return 0;
    55	
    56		if (!desc->reset_banks) {
    57			dev_err(dev,
  > 58				"Missing reset banks data though num_reset_banks is %lu\n",
    59				desc->num_reset_banks);
    60			return -EINVAL;
    61		}
    62	
    63		reset_initdata.regmap = regmap;
    64		reset_initdata.num_banks = desc->num_reset_banks;
    65		reset_initdata.banks = desc->reset_banks;
    66	
    67		return rtk_reset_controller_add(dev, &reset_initdata);
    68	}
    69	EXPORT_SYMBOL_GPL(rtk_clk_probe);
    70	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH 3/9] clk: realtek: Introduce a common probe()
Posted by kernel test robot 1 month, 1 week ago
Hi Yu-Chun,

kernel test robot noticed the following build warnings:

[auto build test WARNING on clk/clk-next]
[also build test WARNING on linus/master v6.19-rc3 next-20251219]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Yu-Chun-Lin/dt-bindings-clock-Add-Realtek-RTD1625-Clock-Reset-Controller/20251229-155549
base:   https://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git clk-next
patch link:    https://lore.kernel.org/r/20251229075313.27254-4-eleanor.lin%40realtek.com
patch subject: [PATCH 3/9] clk: realtek: Introduce a common probe()
config: i386-buildonly-randconfig-001-20251230 (https://download.01.org/0day-ci/archive/20251231/202512310112.MJuwgWEO-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251231/202512310112.MJuwgWEO-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202512310112.MJuwgWEO-lkp@intel.com/

All warnings (new ones prefixed by >>):

   In file included from include/linux/device.h:15,
                    from drivers/clk/realtek/common.c:7:
   drivers/clk/realtek/common.c: In function 'rtk_clk_probe':
>> drivers/clk/realtek/common.c:58:25: warning: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type 'size_t' {aka 'unsigned int'} [-Wformat=]
      58 |                         "Missing reset banks data though num_reset_banks is %lu\n",
         |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/dev_printk.h:110:30: note: in definition of macro 'dev_printk_index_wrap'
     110 |                 _p_func(dev, fmt, ##__VA_ARGS__);                       \
         |                              ^~~
   include/linux/dev_printk.h:154:56: note: in expansion of macro 'dev_fmt'
     154 |         dev_printk_index_wrap(_dev_err, KERN_ERR, dev, dev_fmt(fmt), ##__VA_ARGS__)
         |                                                        ^~~~~~~
   drivers/clk/realtek/common.c:57:17: note: in expansion of macro 'dev_err'
      57 |                 dev_err(dev,
         |                 ^~~~~~~
   drivers/clk/realtek/common.c:58:79: note: format string is defined here
      58 |                         "Missing reset banks data though num_reset_banks is %lu\n",
         |                                                                             ~~^
         |                                                                               |
         |                                                                               long unsigned int
         |                                                                             %u


vim +58 drivers/clk/realtek/common.c

    12	
    13	int rtk_clk_probe(struct platform_device *pdev, const struct rtk_clk_desc *desc)
    14	{
    15		int i, ret;
    16		struct device *dev = &pdev->dev;
    17		struct rtk_reset_initdata reset_initdata = { 0 };
    18	
    19		struct regmap *regmap = device_node_to_regmap(pdev->dev.of_node);
    20	
    21		if (IS_ERR(regmap)) {
    22			ret = PTR_ERR(regmap);
    23			dev_err(dev, "Failed to get regmap: %d\n", ret);
    24			return ret;
    25		}
    26	
    27		for (i = 0; i < desc->num_clks; i++)
    28			desc->clks[i]->regmap = regmap;
    29	
    30		for (i = 0; i < desc->clk_data->num; i++) {
    31			struct clk_hw *hw = desc->clk_data->hws[i];
    32	
    33			if (!hw)
    34				continue;
    35	
    36			ret = devm_clk_hw_register(dev, hw);
    37	
    38			if (ret) {
    39				dev_warn(dev, "failed to register hw of clk%d: %d\n", i,
    40					 ret);
    41				desc->clk_data->hws[i] = NULL;
    42			}
    43		}
    44	
    45		ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
    46						  desc->clk_data);
    47	
    48		if (ret) {
    49			dev_err(dev, "Failed to add clock provider\n");
    50			return ret;
    51		}
    52	
    53		if (!desc->num_reset_banks)
    54			return 0;
    55	
    56		if (!desc->reset_banks) {
    57			dev_err(dev,
  > 58				"Missing reset banks data though num_reset_banks is %lu\n",
    59				desc->num_reset_banks);
    60			return -EINVAL;
    61		}
    62	
    63		reset_initdata.regmap = regmap;
    64		reset_initdata.num_banks = desc->num_reset_banks;
    65		reset_initdata.banks = desc->reset_banks;
    66	
    67		return rtk_reset_controller_add(dev, &reset_initdata);
    68	}
    69	EXPORT_SYMBOL_GPL(rtk_clk_probe);
    70	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH 3/9] clk: realtek: Introduce a common probe()
Posted by Krzysztof Kozlowski 1 month, 1 week ago
On Mon, Dec 29, 2025 at 03:53:07PM +0800, Yu-Chun Lin wrote:
> Add rtk_clk_probe() to set up the shared regmap, register clock hardware,
> add the clock provider, and optionally register a reset controller when
> reset bank data is provided.
> 
> Signed-off-by: Cheng-Yu Lee <cylee12@realtek.com>
> Signed-off-by: Yu-Chun Lin <eleanor.lin@realtek.com>
> ---
>  drivers/clk/realtek/Makefile |  1 +
>  drivers/clk/realtek/common.c | 72 ++++++++++++++++++++++++++++++++++++
>  drivers/clk/realtek/common.h | 40 ++++++++++++++++++++
>  3 files changed, 113 insertions(+)
>  create mode 100644 drivers/clk/realtek/common.c
>  create mode 100644 drivers/clk/realtek/common.h
> 
> diff --git a/drivers/clk/realtek/Makefile b/drivers/clk/realtek/Makefile
> index 52267de2eef4..4041951b7c62 100644
> --- a/drivers/clk/realtek/Makefile
> +++ b/drivers/clk/realtek/Makefile
> @@ -1,4 +1,5 @@
>  # SPDX-License-Identifier: GPL-2.0-only
>  obj-$(CONFIG_RTK_CLK_COMMON) += clk-rtk.o
>  
> +clk-rtk-y += common.o
>  clk-rtk-y += reset.o
> diff --git a/drivers/clk/realtek/common.c b/drivers/clk/realtek/common.c
> new file mode 100644
> index 000000000000..df89d2a10291
> --- /dev/null
> +++ b/drivers/clk/realtek/common.c
> @@ -0,0 +1,72 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright (C) 2019 Realtek Semiconductor Corporation
> + * Author: Cheng-Yu Lee <cylee12@realtek.com>
> + */
> +
> +#include <linux/device.h>
> +#include <linux/module.h>
> +#include <linux/mfd/syscon.h>
> +#include <linux/platform_device.h>
> +#include "common.h"
> +
> +int rtk_clk_probe(struct platform_device *pdev, const struct rtk_clk_desc *desc)
> +{
> +	int i, ret;
> +	struct device *dev = &pdev->dev;
> +	struct rtk_reset_initdata reset_initdata = { 0 };
> +

There is never blank line between declarations.

> +	struct regmap *regmap = device_node_to_regmap(pdev->dev.of_node);

This is not supposed to be declaration with initialization.

> +

There is never blank line between get and if().

> +	if (IS_ERR(regmap)) {
> +		ret = PTR_ERR(regmap);
> +		dev_err(dev, "Failed to get regmap: %d\n", ret);
> +		return ret;

Syntax is just return dev_err_probe. Don't send us 2022 code, but
completely rework this to match upstream style.

> +	}
> +
> +	for (i = 0; i < desc->num_clks; i++)
> +		desc->clks[i]->regmap = regmap;
> +
> +	for (i = 0; i < desc->clk_data->num; i++) {
> +		struct clk_hw *hw = desc->clk_data->hws[i];
> +
> +		if (!hw)
> +			continue;
> +
> +		ret = devm_clk_hw_register(dev, hw);
> +
> +		if (ret) {
> +			dev_warn(dev, "failed to register hw of clk%d: %d\n", i,
> +				 ret);
> +			desc->clk_data->hws[i] = NULL;
> +		}
> +	}
> +
> +	ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
> +					  desc->clk_data);
> +
> +	if (ret) {
> +		dev_err(dev, "Failed to add clock provider\n");

Really... 2022 code...

Best regards,
Krzysztof