0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/bitops.h>
0011 #include <linux/clk-provider.h>
0012 #include <linux/init.h>
0013 #include <linux/of.h>
0014 #include <linux/platform_device.h>
0015 #include <linux/spinlock.h>
0016
0017 #include "clk-factors.h"
0018
0019
0020
0021
0022
0023
0024
0025 static void sun6i_get_ar100_factors(struct factors_request *req)
0026 {
0027 unsigned long div;
0028 int shift;
0029
0030
0031 if (req->rate > req->parent_rate)
0032 req->rate = req->parent_rate;
0033
0034 div = DIV_ROUND_UP(req->parent_rate, req->rate);
0035
0036 if (div < 32)
0037 shift = 0;
0038 else if (div >> 1 < 32)
0039 shift = 1;
0040 else if (div >> 2 < 32)
0041 shift = 2;
0042 else
0043 shift = 3;
0044
0045 div >>= shift;
0046
0047 if (div > 32)
0048 div = 32;
0049
0050 req->rate = (req->parent_rate >> shift) / div;
0051 req->m = div - 1;
0052 req->p = shift;
0053 }
0054
0055 static const struct clk_factors_config sun6i_ar100_config = {
0056 .mwidth = 5,
0057 .mshift = 8,
0058 .pwidth = 2,
0059 .pshift = 4,
0060 };
0061
0062 static const struct factors_data sun6i_ar100_data = {
0063 .mux = 16,
0064 .muxmask = GENMASK(1, 0),
0065 .table = &sun6i_ar100_config,
0066 .getter = sun6i_get_ar100_factors,
0067 };
0068
0069 static DEFINE_SPINLOCK(sun6i_ar100_lock);
0070
0071 static int sun6i_a31_ar100_clk_probe(struct platform_device *pdev)
0072 {
0073 struct device_node *np = pdev->dev.of_node;
0074 void __iomem *reg;
0075 struct clk *clk;
0076
0077 reg = devm_platform_ioremap_resource(pdev, 0);
0078 if (IS_ERR(reg))
0079 return PTR_ERR(reg);
0080
0081 clk = sunxi_factors_register(np, &sun6i_ar100_data, &sun6i_ar100_lock,
0082 reg);
0083 if (!clk)
0084 return -ENOMEM;
0085
0086 platform_set_drvdata(pdev, clk);
0087
0088 return 0;
0089 }
0090
0091 static const struct of_device_id sun6i_a31_ar100_clk_dt_ids[] = {
0092 { .compatible = "allwinner,sun6i-a31-ar100-clk" },
0093 { }
0094 };
0095
0096 static struct platform_driver sun6i_a31_ar100_clk_driver = {
0097 .driver = {
0098 .name = "sun6i-a31-ar100-clk",
0099 .of_match_table = sun6i_a31_ar100_clk_dt_ids,
0100 .suppress_bind_attrs = true,
0101 },
0102 .probe = sun6i_a31_ar100_clk_probe,
0103 };
0104 builtin_platform_driver(sun6i_a31_ar100_clk_driver);