Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clk: meson: introduce meson-clkc-utils

Let's introduce a new module called meson-clkc-utils that
will contain shared utility functions for all Amlogic clock
controller drivers.

The first utility function is a replacement of of_clk_hw_onecell_get
in order to get rid of the NR_CLKS define in all Amlogic clock
drivers.

The goal is to move all duplicate probe and init code in this module.

[jbrunet: Fixed MODULE_LICENCE checkpatch warning]
Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
Link: https://lore.kernel.org/r/20230607-topic-amlogic-upstream-clkid-public-migration-v2-1-38172d17c27a@linaro.org
Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>

authored by

Neil Armstrong and committed by
Jerome Brunet
230b6f3a 06c2afb8

+48
+3
drivers/clk/meson/Kconfig
··· 30 30 tristate 31 31 select COMMON_CLK_MESON_REGMAP 32 32 33 + config COMMON_CLK_MESON_CLKC_UTILS 34 + tristate 35 + 33 36 config COMMON_CLK_MESON_AO_CLKC 34 37 tristate 35 38 select COMMON_CLK_MESON_REGMAP
+1
drivers/clk/meson/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0-only 2 2 # Amlogic clock drivers 3 3 4 + obj-$(CONFIG_COMMON_CLK_MESON_CLKC_UTILS) += meson-clkc-utils.o 4 5 obj-$(CONFIG_COMMON_CLK_MESON_AO_CLKC) += meson-aoclk.o 5 6 obj-$(CONFIG_COMMON_CLK_MESON_CPU_DYNDIV) += clk-cpu-dyndiv.o 6 7 obj-$(CONFIG_COMMON_CLK_MESON_DUALDIV) += clk-dualdiv.o
+25
drivers/clk/meson/meson-clkc-utils.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* 3 + * Copyright (c) 2023 Neil Armstrong <neil.armstrong@linaro.org> 4 + */ 5 + 6 + #include <linux/of_device.h> 7 + #include <linux/clk-provider.h> 8 + #include <linux/module.h> 9 + #include "meson-clkc-utils.h" 10 + 11 + struct clk_hw *meson_clk_hw_get(struct of_phandle_args *clkspec, void *clk_hw_data) 12 + { 13 + const struct meson_clk_hw_data *data = clk_hw_data; 14 + unsigned int idx = clkspec->args[0]; 15 + 16 + if (idx >= data->num) { 17 + pr_err("%s: invalid index %u\n", __func__, idx); 18 + return ERR_PTR(-EINVAL); 19 + } 20 + 21 + return data->hws[idx]; 22 + } 23 + EXPORT_SYMBOL_GPL(meson_clk_hw_get); 24 + 25 + MODULE_LICENSE("GPL");
+19
drivers/clk/meson/meson-clkc-utils.h
··· 1 + /* SPDX-License-Identifier: (GPL-2.0+ OR MIT) */ 2 + /* 3 + * Copyright (c) 2023 Neil Armstrong <neil.armstrong@linaro.org> 4 + */ 5 + 6 + #ifndef __MESON_CLKC_UTILS_H__ 7 + #define __MESON_CLKC_UTILS_H__ 8 + 9 + #include <linux/of_device.h> 10 + #include <linux/clk-provider.h> 11 + 12 + struct meson_clk_hw_data { 13 + struct clk_hw **hws; 14 + unsigned int num; 15 + }; 16 + 17 + struct clk_hw *meson_clk_hw_get(struct of_phandle_args *clkspec, void *clk_hw_data); 18 + 19 + #endif