visorbus: switch from ioremap_cache to memremap
[linux/fpc-iii.git] / drivers / clk / sunxi / clk-sun8i-mbus.c
blob14cd026064bf377ed7cbc05bbd84aa608e639fec
1 /*
2 * Copyright 2014 Chen-Yu Tsai
4 * Chen-Yu Tsai <wens@csie.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
17 #include <linux/clk-provider.h>
18 #include <linux/clkdev.h>
19 #include <linux/of_address.h>
21 #include "clk-factors.h"
23 /**
24 * sun8i_a23_get_mbus_factors() - calculates m factor for MBUS clocks
25 * MBUS rate is calculated as follows
26 * rate = parent_rate / (m + 1);
29 static void sun8i_a23_get_mbus_factors(u32 *freq, u32 parent_rate,
30 u8 *n, u8 *k, u8 *m, u8 *p)
32 u8 div;
35 * These clocks can only divide, so we will never be able to
36 * achieve frequencies higher than the parent frequency
38 if (*freq > parent_rate)
39 *freq = parent_rate;
41 div = DIV_ROUND_UP(parent_rate, *freq);
43 if (div > 8)
44 div = 8;
46 *freq = parent_rate / div;
48 /* we were called to round the frequency, we can now return */
49 if (m == NULL)
50 return;
52 *m = div - 1;
55 static struct clk_factors_config sun8i_a23_mbus_config = {
56 .mshift = 0,
57 .mwidth = 3,
60 static const struct factors_data sun8i_a23_mbus_data __initconst = {
61 .enable = 31,
62 .mux = 24,
63 .muxmask = BIT(1) | BIT(0),
64 .table = &sun8i_a23_mbus_config,
65 .getter = sun8i_a23_get_mbus_factors,
68 static DEFINE_SPINLOCK(sun8i_a23_mbus_lock);
70 static void __init sun8i_a23_mbus_setup(struct device_node *node)
72 struct clk *mbus;
73 void __iomem *reg;
75 reg = of_iomap(node, 0);
76 if (!reg) {
77 pr_err("Could not get registers for a23-mbus-clk\n");
78 return;
81 mbus = sunxi_factors_register(node, &sun8i_a23_mbus_data,
82 &sun8i_a23_mbus_lock, reg);
84 /* The MBUS clocks needs to be always enabled */
85 __clk_get(mbus);
86 clk_prepare_enable(mbus);
88 CLK_OF_DECLARE(sun8i_a23_mbus, "allwinner,sun8i-a23-mbus-clk", sun8i_a23_mbus_setup);