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 AR100 clock driver
11 #include <linux/bitops.h>
12 #include <linux/clk-provider.h>
13 #include <linux/module.h>
15 #include <linux/platform_device.h>
16 #include <linux/spinlock.h>
18 #include "clk-factors.h"
21 * sun6i_get_ar100_factors - Calculates factors p, m for AR100
23 * AR100 rate is calculated as follows
24 * rate = (parent_rate >> p) / (m + 1);
26 static void sun6i_get_ar100_factors(struct factors_request
*req
)
31 /* clock only divides */
32 if (req
->rate
> req
->parent_rate
)
33 req
->rate
= req
->parent_rate
;
35 div
= DIV_ROUND_UP(req
->parent_rate
, req
->rate
);
39 else if (div
>> 1 < 32)
41 else if (div
>> 2 < 32)
51 req
->rate
= (req
->parent_rate
>> shift
) / div
;
56 static const struct clk_factors_config sun6i_ar100_config
= {
63 static const struct factors_data sun6i_ar100_data
= {
65 .muxmask
= GENMASK(1, 0),
66 .table
= &sun6i_ar100_config
,
67 .getter
= sun6i_get_ar100_factors
,
70 static DEFINE_SPINLOCK(sun6i_ar100_lock
);
72 static int sun6i_a31_ar100_clk_probe(struct platform_device
*pdev
)
74 struct device_node
*np
= pdev
->dev
.of_node
;
79 r
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
80 reg
= devm_ioremap_resource(&pdev
->dev
, r
);
84 clk
= sunxi_factors_register(np
, &sun6i_ar100_data
, &sun6i_ar100_lock
,
89 platform_set_drvdata(pdev
, clk
);
94 static int sun6i_a31_ar100_clk_remove(struct platform_device
*pdev
)
96 struct device_node
*np
= pdev
->dev
.of_node
;
97 struct clk
*clk
= platform_get_drvdata(pdev
);
99 sunxi_factors_unregister(np
, clk
);
104 static const struct of_device_id sun6i_a31_ar100_clk_dt_ids
[] = {
105 { .compatible
= "allwinner,sun6i-a31-ar100-clk" },
108 MODULE_DEVICE_TABLE(of
, sun6i_a31_ar100_clk_dt_ids
);
110 static struct platform_driver sun6i_a31_ar100_clk_driver
= {
112 .name
= "sun6i-a31-ar100-clk",
113 .of_match_table
= sun6i_a31_ar100_clk_dt_ids
,
115 .probe
= sun6i_a31_ar100_clk_probe
,
116 .remove
= sun6i_a31_ar100_clk_remove
,
118 module_platform_driver(sun6i_a31_ar100_clk_driver
);
120 MODULE_AUTHOR("Boris BREZILLON <boris.brezillon@free-electrons.com>");
121 MODULE_DESCRIPTION("Allwinner A31 AR100 clock Driver");
122 MODULE_LICENSE("GPL v2");