0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/clk-provider.h>
0011 #include <linux/init.h>
0012 #include <linux/of.h>
0013 #include <linux/platform_device.h>
0014
0015
0016
0017
0018
0019
0020
0021
0022 static const struct clk_div_table sun6i_a31_apb0_divs[] = {
0023 { .val = 0, .div = 2, },
0024 { .val = 1, .div = 2, },
0025 { .val = 2, .div = 4, },
0026 { .val = 3, .div = 8, },
0027 { },
0028 };
0029
0030 static int sun6i_a31_apb0_clk_probe(struct platform_device *pdev)
0031 {
0032 struct device_node *np = pdev->dev.of_node;
0033 const char *clk_name = np->name;
0034 const char *clk_parent;
0035 void __iomem *reg;
0036 struct clk *clk;
0037
0038 reg = devm_platform_ioremap_resource(pdev, 0);
0039 if (IS_ERR(reg))
0040 return PTR_ERR(reg);
0041
0042 clk_parent = of_clk_get_parent_name(np, 0);
0043 if (!clk_parent)
0044 return -EINVAL;
0045
0046 of_property_read_string(np, "clock-output-names", &clk_name);
0047
0048 clk = clk_register_divider_table(&pdev->dev, clk_name, clk_parent,
0049 0, reg, 0, 2, 0, sun6i_a31_apb0_divs,
0050 NULL);
0051 if (IS_ERR(clk))
0052 return PTR_ERR(clk);
0053
0054 return of_clk_add_provider(np, of_clk_src_simple_get, clk);
0055 }
0056
0057 static const struct of_device_id sun6i_a31_apb0_clk_dt_ids[] = {
0058 { .compatible = "allwinner,sun6i-a31-apb0-clk" },
0059 { }
0060 };
0061
0062 static struct platform_driver sun6i_a31_apb0_clk_driver = {
0063 .driver = {
0064 .name = "sun6i-a31-apb0-clk",
0065 .of_match_table = sun6i_a31_apb0_clk_dt_ids,
0066 },
0067 .probe = sun6i_a31_apb0_clk_probe,
0068 };
0069 builtin_platform_driver(sun6i_a31_apb0_clk_driver);