1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2014 Free Electrons
5 * Author: Boris BREZILLON <boris.brezillon@free-electrons.com>
7 * Allwinner A31 APB0 clock gates driver
10 #include <linux/clk-provider.h>
11 #include <linux/init.h>
13 #include <linux/platform_device.h>
15 #define SUN6I_APB0_GATES_MAX_SIZE 32
18 DECLARE_BITMAP(mask, SUN6I_APB0_GATES_MAX_SIZE);
21 static const struct gates_data sun6i_a31_apb0_gates __initconst = {
25 static const struct gates_data sun8i_a23_apb0_gates __initconst = {
29 static const struct of_device_id sun6i_a31_apb0_gates_clk_dt_ids[] = {
30 { .compatible = "allwinner,sun6i-a31-apb0-gates-clk", .data = &sun6i_a31_apb0_gates },
31 { .compatible = "allwinner,sun8i-a23-apb0-gates-clk", .data = &sun8i_a23_apb0_gates },
35 static int sun6i_a31_apb0_gates_clk_probe(struct platform_device *pdev)
37 struct device_node *np = pdev->dev.of_node;
38 struct clk_onecell_data *clk_data;
39 const struct gates_data *data;
40 const char *clk_parent;
50 data = of_device_get_match_data(&pdev->dev);
54 reg = devm_platform_ioremap_resource(pdev, 0);
58 clk_parent = of_clk_get_parent_name(np, 0);
62 clk_data = devm_kzalloc(&pdev->dev, sizeof(struct clk_onecell_data),
67 /* Worst-case size approximation and memory allocation */
68 ngates = find_last_bit(data->mask, SUN6I_APB0_GATES_MAX_SIZE);
69 clk_data->clks = devm_kcalloc(&pdev->dev, (ngates + 1),
70 sizeof(struct clk *), GFP_KERNEL);
74 for_each_set_bit(i, data->mask, SUN6I_APB0_GATES_MAX_SIZE) {
75 of_property_read_string_index(np, "clock-output-names",
78 clk_data->clks[i] = clk_register_gate(&pdev->dev, clk_name,
79 clk_parent, 0, reg, i,
81 WARN_ON(IS_ERR(clk_data->clks[i]));
86 clk_data->clk_num = ngates + 1;
88 return of_clk_add_provider(np, of_clk_src_onecell_get, clk_data);
91 static struct platform_driver sun6i_a31_apb0_gates_clk_driver = {
93 .name = "sun6i-a31-apb0-gates-clk",
94 .of_match_table = sun6i_a31_apb0_gates_clk_dt_ids,
96 .probe = sun6i_a31_apb0_gates_clk_probe,
98 builtin_platform_driver(sun6i_a31_apb0_gates_clk_driver);