1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2014 Free Electrons
5 * Author: Boris BREZILLON <boris.brezillon@free-electrons.com>
7 * Allwinner A31 AR100 clock driver
10 #include <linux/bitops.h>
11 #include <linux/clk-provider.h>
12 #include <linux/init.h>
14 #include <linux/platform_device.h>
15 #include <linux/spinlock.h>
17 #include "clk-factors.h"
20 * sun6i_get_ar100_factors - Calculates factors p, m for AR100
22 * AR100 rate is calculated as follows
23 * rate = (parent_rate >> p) / (m + 1);
25 static void sun6i_get_ar100_factors(struct factors_request *req)
30 /* clock only divides */
31 if (req->rate > req->parent_rate)
32 req->rate = req->parent_rate;
34 div = DIV_ROUND_UP(req->parent_rate, req->rate);
38 else if (div >> 1 < 32)
40 else if (div >> 2 < 32)
50 req->rate = (req->parent_rate >> shift) / div;
55 static const struct clk_factors_config sun6i_ar100_config = {
62 static const struct factors_data sun6i_ar100_data = {
64 .muxmask = GENMASK(1, 0),
65 .table = &sun6i_ar100_config,
66 .getter = sun6i_get_ar100_factors,
69 static DEFINE_SPINLOCK(sun6i_ar100_lock);
71 static int sun6i_a31_ar100_clk_probe(struct platform_device *pdev)
73 struct device_node *np = pdev->dev.of_node;
78 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
79 reg = devm_ioremap_resource(&pdev->dev, r);
83 clk = sunxi_factors_register(np, &sun6i_ar100_data, &sun6i_ar100_lock,
88 platform_set_drvdata(pdev, clk);
93 static const struct of_device_id sun6i_a31_ar100_clk_dt_ids[] = {
94 { .compatible = "allwinner,sun6i-a31-ar100-clk" },
98 static struct platform_driver sun6i_a31_ar100_clk_driver = {
100 .name = "sun6i-a31-ar100-clk",
101 .of_match_table = sun6i_a31_ar100_clk_dt_ids,
102 .suppress_bind_attrs = true,
104 .probe = sun6i_a31_ar100_clk_probe,
106 builtin_platform_driver(sun6i_a31_ar100_clk_driver);