2 * Copyright (C) 2014 Free Electrons
4 * License Terms: GNU General Public License v2
5 * Author: Boris BREZILLON <boris.brezillon@free-electrons.com>
7 * Allwinner A31 APB0 clock gates driver
11 #include <linux/clk-provider.h>
12 #include <linux/module.h>
14 #include <linux/platform_device.h>
16 #define SUN6I_APB0_GATES_MAX_SIZE 32
18 static int sun6i_a31_apb0_gates_clk_probe(struct platform_device
*pdev
)
20 struct device_node
*np
= pdev
->dev
.of_node
;
21 struct clk_onecell_data
*clk_data
;
22 const char *clk_parent
;
30 r
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
31 reg
= devm_ioremap_resource(&pdev
->dev
, r
);
35 clk_parent
= of_clk_get_parent_name(np
, 0);
39 ngates
= of_property_count_strings(np
, "clock-output-names");
43 if (!ngates
|| ngates
> SUN6I_APB0_GATES_MAX_SIZE
)
46 clk_data
= devm_kzalloc(&pdev
->dev
, sizeof(struct clk_onecell_data
),
51 clk_data
->clks
= devm_kzalloc(&pdev
->dev
,
52 SUN6I_APB0_GATES_MAX_SIZE
*
58 for (i
= 0; i
< ngates
; i
++) {
59 of_property_read_string_index(np
, "clock-output-names",
63 of_property_read_u32_index(np
, "clock-indices", i
, &gate_id
);
65 WARN_ON(gate_id
>= SUN6I_APB0_GATES_MAX_SIZE
);
66 if (gate_id
>= SUN6I_APB0_GATES_MAX_SIZE
)
69 clk_data
->clks
[gate_id
] = clk_register_gate(&pdev
->dev
,
74 WARN_ON(IS_ERR(clk_data
->clks
[gate_id
]));
77 clk_data
->clk_num
= ngates
;
79 return of_clk_add_provider(np
, of_clk_src_onecell_get
, clk_data
);
82 const struct of_device_id sun6i_a31_apb0_gates_clk_dt_ids
[] = {
83 { .compatible
= "allwinner,sun6i-a31-apb0-gates-clk" },
87 static struct platform_driver sun6i_a31_apb0_gates_clk_driver
= {
89 .name
= "sun6i-a31-apb0-gates-clk",
91 .of_match_table
= sun6i_a31_apb0_gates_clk_dt_ids
,
93 .probe
= sun6i_a31_apb0_gates_clk_probe
,
95 module_platform_driver(sun6i_a31_apb0_gates_clk_driver
);
97 MODULE_AUTHOR("Boris BREZILLON <boris.brezillon@free-electrons.com>");
98 MODULE_DESCRIPTION("Allwinner A31 APB0 gate clocks driver");
99 MODULE_LICENSE("GPL v2");