Several MediaTek SoCs expose multiple clock gate controller instances. Each instance currently requires its own U_BOOT_DRIVER, mtk_clk_tree, probe() function and struct udevice_id table, even though they all share the same implementation.
For example, MT8188 defines five nearly identical clock gate drivers, resulting in a significant amount of duplicated code. As additional clock gate controllers are introduced, such as those required for HDMI support, this duplication will continue to grow. MT8189 already avoids this by using a single generic U_BOOT_DRIVER shared across all clock gate controller compatibles, with the SoC-specific information provided through driver data. Generalize this approach by introducing struct mtk_gate_clk_data, allowing MediaTek clock gate drivers to share a common driver, probe() function and clock tree definition while keeping the SoC-specific data separate. This removes duplicated code and provides a reusable framework for existing and future MediaTek SoCs. Signed-off-by: Julien Stephan <[email protected]> --- drivers/clk/mediatek/clk-mtk.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/clk/mediatek/clk-mtk.h b/drivers/clk/mediatek/clk-mtk.h index e363a375093..545a493572c 100644 --- a/drivers/clk/mediatek/clk-mtk.h +++ b/drivers/clk/mediatek/clk-mtk.h @@ -230,6 +230,17 @@ struct mtk_gate { u32 flags; }; +struct mtk_gate_clk_data { + const struct mtk_gate *gates; + int num_gates; +}; + +#define MTK_GATE_CLK_DATA(name) \ +static const struct mtk_gate_clk_data name##_data = { \ + .gates = name, \ + .num_gates = ARRAY_SIZE(name) \ +} + #define GATE_FLAGS(_id, _parent, _regs, _shift, _flags) { \ .id = _id, \ .parent = _parent, \ -- 2.54.0

