[PATCH v2 3/4] clk: sophgo: Add SG2042 clock generator driver
Krzysztof Kozlowski
krzysztof.kozlowski at linaro.org
Sun Nov 26 23:12:00 PST 2023
On 27/11/2023 02:15, Chen Wang wrote:
> From: Chen Wang <unicorn_wang at outlook.com>
>
> Add a driver for the SOPHGO SG2042 clock generator.
>
> Signed-off-by: Chen Wang <unicorn_wang at outlook.com>
...
> +static void __init sg2042_clk_init(struct device_node *node)
> +{
> + struct sg2042_clk_data *clk_data = NULL;
> + int i, ret = 0;
> + int num_clks = 0;
> +
> + num_clks = ARRAY_SIZE(sg2042_pll_clks) +
> + ARRAY_SIZE(sg2042_div_clks) +
> + ARRAY_SIZE(sg2042_gate_clks) +
> + ARRAY_SIZE(sg2042_mux_clks);
> + if (num_clks == 0) {
> + ret = -EINVAL;
> + goto error_out;
> + }
> +
> + ret = sg2042_clk_init_clk_data(node, num_clks, &clk_data);
> + if (ret < 0)
> + goto error_out;
> +
> + ret = sg2042_clk_register_plls(clk_data, sg2042_pll_clks,
> + ARRAY_SIZE(sg2042_pll_clks));
> + if (ret)
> + goto cleanup;
> +
> + ret = sg2042_clk_register_divs(clk_data, sg2042_div_clks,
> + ARRAY_SIZE(sg2042_div_clks));
> + if (ret)
> + goto cleanup;
> +
> + ret = sg2042_clk_register_gates(clk_data, sg2042_gate_clks,
> + ARRAY_SIZE(sg2042_gate_clks));
> + if (ret)
> + goto cleanup;
> +
> + ret = sg2042_clk_register_muxs(clk_data, sg2042_mux_clks,
> + ARRAY_SIZE(sg2042_mux_clks));
> + if (ret)
> + goto cleanup;
> +
> + for (i = 0; i < num_clks; i++)
> + dbg_info("provider [%d]: %s\n", i, clk_hw_get_name(clk_data->onecell_data.hws[i]));
> + ret = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, &clk_data->onecell_data);
> + if (ret)
> + goto cleanup;
> +
> + return;
> +
> +cleanup:
> + for (i = 0; i < num_clks; i++) {
> + if (clk_data->onecell_data.hws[i] != NULL)
> + clk_hw_unregister(clk_data->onecell_data.hws[i]);
> + }
> + kfree(clk_data);
> +
> +error_out:
> + pr_err("%s failed error number %d\n", __func__, ret);
> +}
> +
> +CLK_OF_DECLARE(sg2042_clk, "sophgo,sg2042-clkgen", sg2042_clk_init);
No, this should be platform device. It's a child of another device, so
you cannot use other way of init ordering.
> diff --git a/drivers/clk/sophgo/clk-sophgo-sg2042.h b/drivers/clk/sophgo/clk-sophgo-sg2042.h
> new file mode 100644
> index 000000000000..ca1c8b9a937a
> --- /dev/null
...
> +#define to_sg2042_mux_nb(_nb) container_of(_nb, struct sg2042_mux_clock, clk_nb)
> +
> +#ifdef DEBUG
> + #define dbg_info(format, arg...) \
> + pr_info("--> %s: "format"", __func__, ## arg)
> +#else
> + #define dbg_info(format, arg...)
> +#endif
Drop custom debug prints.
> +
> +#endif /* __CLK_SOPHGO_SG2042_H */
Best regards,
Krzysztof
More information about the linux-riscv
mailing list