0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <linux/clk-provider.h>
0016 #include <linux/init.h>
0017 #include <linux/io.h>
0018 #include <linux/of.h>
0019 #include <linux/of_address.h>
0020 #include <linux/platform_device.h>
0021
0022 static struct clk *sun8i_a23_apb0_register(struct device_node *node,
0023 void __iomem *reg)
0024 {
0025 const char *clk_name = node->name;
0026 const char *clk_parent;
0027 struct clk *clk;
0028 int ret;
0029
0030 clk_parent = of_clk_get_parent_name(node, 0);
0031 if (!clk_parent)
0032 return ERR_PTR(-EINVAL);
0033
0034 of_property_read_string(node, "clock-output-names", &clk_name);
0035
0036
0037 clk = clk_register_divider(NULL, clk_name, clk_parent, 0, reg,
0038 0, 2, 0, NULL);
0039 if (IS_ERR(clk))
0040 return clk;
0041
0042 ret = of_clk_add_provider(node, of_clk_src_simple_get, clk);
0043 if (ret)
0044 goto err_unregister;
0045
0046 return clk;
0047
0048 err_unregister:
0049 clk_unregister_divider(clk);
0050
0051 return ERR_PTR(ret);
0052 }
0053
0054 static void sun8i_a23_apb0_setup(struct device_node *node)
0055 {
0056 void __iomem *reg;
0057 struct resource res;
0058 struct clk *clk;
0059
0060 reg = of_io_request_and_map(node, 0, of_node_full_name(node));
0061 if (IS_ERR(reg)) {
0062
0063
0064
0065
0066
0067 if (PTR_ERR(reg) != -EINVAL)
0068 pr_err("Could not get registers for a23-apb0-clk\n");
0069
0070 return;
0071 }
0072
0073 clk = sun8i_a23_apb0_register(node, reg);
0074 if (IS_ERR(clk))
0075 goto err_unmap;
0076
0077 return;
0078
0079 err_unmap:
0080 iounmap(reg);
0081 of_address_to_resource(node, 0, &res);
0082 release_mem_region(res.start, resource_size(&res));
0083 }
0084 CLK_OF_DECLARE_DRIVER(sun8i_a23_apb0, "allwinner,sun8i-a23-apb0-clk",
0085 sun8i_a23_apb0_setup);
0086
0087 static int sun8i_a23_apb0_clk_probe(struct platform_device *pdev)
0088 {
0089 struct device_node *np = pdev->dev.of_node;
0090 void __iomem *reg;
0091 struct clk *clk;
0092
0093 reg = devm_platform_ioremap_resource(pdev, 0);
0094 if (IS_ERR(reg))
0095 return PTR_ERR(reg);
0096
0097 clk = sun8i_a23_apb0_register(np, reg);
0098 return PTR_ERR_OR_ZERO(clk);
0099 }
0100
0101 static const struct of_device_id sun8i_a23_apb0_clk_dt_ids[] = {
0102 { .compatible = "allwinner,sun8i-a23-apb0-clk" },
0103 { }
0104 };
0105
0106 static struct platform_driver sun8i_a23_apb0_clk_driver = {
0107 .driver = {
0108 .name = "sun8i-a23-apb0-clk",
0109 .of_match_table = sun8i_a23_apb0_clk_dt_ids,
0110 },
0111 .probe = sun8i_a23_apb0_clk_probe,
0112 };
0113 builtin_platform_driver(sun8i_a23_apb0_clk_driver);