2 * Copyright (C) 2014 Chen-Yu Tsai
5 * Allwinner A23 APB0 clock driver
7 * License Terms: GNU General Public License v2
9 * Based on clk-sun6i-apb0.c
10 * Allwinner A31 APB0 clock driver
12 * Copyright (C) 2014 Free Electrons
17 #include <linux/clk-provider.h>
18 #include <linux/init.h>
20 #include <linux/of_address.h>
21 #include <linux/platform_device.h>
23 static struct clk *sun8i_a23_apb0_register(struct device_node *node,
26 const char *clk_name = node->name;
27 const char *clk_parent;
31 clk_parent = of_clk_get_parent_name(node, 0);
33 return ERR_PTR(-EINVAL);
35 of_property_read_string(node, "clock-output-names", &clk_name);
37 /* The A23 APB0 clock is a standard 2 bit wide divider clock */
38 clk = clk_register_divider(NULL, clk_name, clk_parent, 0, reg,
43 ret = of_clk_add_provider(node, of_clk_src_simple_get, clk);
50 clk_unregister_divider(clk);
55 static void sun8i_a23_apb0_setup(struct device_node *node)
61 reg = of_io_request_and_map(node, 0, of_node_full_name(node));
64 * This happens with clk nodes instantiated through mfd,
65 * as those do not have their resources assigned in the
66 * device tree. Do not print an error in this case.
68 if (PTR_ERR(reg) != -EINVAL)
69 pr_err("Could not get registers for a23-apb0-clk\n");
74 clk = sun8i_a23_apb0_register(node, reg);
82 of_address_to_resource(node, 0, &res);
83 release_mem_region(res.start, resource_size(&res));
85 CLK_OF_DECLARE_DRIVER(sun8i_a23_apb0, "allwinner,sun8i-a23-apb0-clk",
86 sun8i_a23_apb0_setup);
88 static int sun8i_a23_apb0_clk_probe(struct platform_device *pdev)
90 struct device_node *np = pdev->dev.of_node;
95 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
96 reg = devm_ioremap_resource(&pdev->dev, r);
100 clk = sun8i_a23_apb0_register(np, reg);
107 static const struct of_device_id sun8i_a23_apb0_clk_dt_ids[] = {
108 { .compatible = "allwinner,sun8i-a23-apb0-clk" },
112 static struct platform_driver sun8i_a23_apb0_clk_driver = {
114 .name = "sun8i-a23-apb0-clk",
115 .of_match_table = sun8i_a23_apb0_clk_dt_ids,
117 .probe = sun8i_a23_apb0_clk_probe,
119 builtin_platform_driver(sun8i_a23_apb0_clk_driver);