xref: /linux/drivers/clk/sunxi/clk-sun8i-apb0.c (revision 3932b9ca55b0be314a36d3e84faff3e823c081f5)
1 /*
2  * Copyright (C) 2014 Chen-Yu Tsai
3  * Author: Chen-Yu Tsai <wens@csie.org>
4  *
5  * Allwinner A23 APB0 clock driver
6  *
7  * License Terms: GNU General Public License v2
8  *
9  * Based on clk-sun6i-apb0.c
10  * Allwinner A31 APB0 clock driver
11  *
12  * Copyright (C) 2014 Free Electrons
13  * Author: Boris BREZILLON <boris.brezillon@free-electrons.com>
14  *
15  */
16 
17 #include <linux/clk-provider.h>
18 #include <linux/module.h>
19 #include <linux/of.h>
20 #include <linux/platform_device.h>
21 
22 static int sun8i_a23_apb0_clk_probe(struct platform_device *pdev)
23 {
24 	struct device_node *np = pdev->dev.of_node;
25 	const char *clk_name = np->name;
26 	const char *clk_parent;
27 	struct resource *r;
28 	void __iomem *reg;
29 	struct clk *clk;
30 
31 	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
32 	reg = devm_ioremap_resource(&pdev->dev, r);
33 	if (IS_ERR(reg))
34 		return PTR_ERR(reg);
35 
36 	clk_parent = of_clk_get_parent_name(np, 0);
37 	if (!clk_parent)
38 		return -EINVAL;
39 
40 	of_property_read_string(np, "clock-output-names", &clk_name);
41 
42 	/* The A23 APB0 clock is a standard 2 bit wide divider clock */
43 	clk = clk_register_divider(&pdev->dev, clk_name, clk_parent, 0, reg,
44 				   0, 2, CLK_DIVIDER_POWER_OF_TWO, NULL);
45 	if (IS_ERR(clk))
46 		return PTR_ERR(clk);
47 
48 	return of_clk_add_provider(np, of_clk_src_simple_get, clk);
49 }
50 
51 static const struct of_device_id sun8i_a23_apb0_clk_dt_ids[] = {
52 	{ .compatible = "allwinner,sun8i-a23-apb0-clk" },
53 	{ /* sentinel */ }
54 };
55 
56 static struct platform_driver sun8i_a23_apb0_clk_driver = {
57 	.driver = {
58 		.name = "sun8i-a23-apb0-clk",
59 		.owner = THIS_MODULE,
60 		.of_match_table = sun8i_a23_apb0_clk_dt_ids,
61 	},
62 	.probe = sun8i_a23_apb0_clk_probe,
63 };
64 module_platform_driver(sun8i_a23_apb0_clk_driver);
65 
66 MODULE_AUTHOR("Chen-Yu Tsai <wens@csie.org>");
67 MODULE_DESCRIPTION("Allwinner A23 APB0 clock Driver");
68 MODULE_LICENSE("GPL v2");
69