xref: /openbmc/linux/drivers/clk/sunxi/clk-mod0.c (revision 03ab8e6297acd1bc0eedaa050e2a1635c576fd11)
1c942fddfSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2992a56e4SMaxime Ripard /*
3992a56e4SMaxime Ripard  * Copyright 2013 Emilio López
4992a56e4SMaxime Ripard  *
5992a56e4SMaxime Ripard  * Emilio López <emilio@elopez.com.ar>
6992a56e4SMaxime Ripard  */
7992a56e4SMaxime Ripard 
89dfefe8cSStephen Boyd #include <linux/clk.h>
9992a56e4SMaxime Ripard #include <linux/clk-provider.h>
1062e59c4eSStephen Boyd #include <linux/io.h>
1137e1041fSMaxime Ripard #include <linux/of_address.h>
126ea3953dSHans de Goede #include <linux/platform_device.h>
139dfefe8cSStephen Boyd #include <linux/slab.h>
14992a56e4SMaxime Ripard 
15992a56e4SMaxime Ripard #include "clk-factors.h"
16992a56e4SMaxime Ripard 
17eec9d9b7SLee Jones /*
1835b1fc2cSJulia Lawall  * sun4i_a10_get_mod0_factors() - calculates m, n factors for MOD0-style clocks
19992a56e4SMaxime Ripard  * MOD0 rate is calculated as follows
20992a56e4SMaxime Ripard  * rate = (parent_rate >> p) / (m + 1);
21992a56e4SMaxime Ripard  */
22992a56e4SMaxime Ripard 
sun4i_a10_get_mod0_factors(struct factors_request * req)23cfa63688SChen-Yu Tsai static void sun4i_a10_get_mod0_factors(struct factors_request *req)
24992a56e4SMaxime Ripard {
25992a56e4SMaxime Ripard 	u8 div, calcm, calcp;
26992a56e4SMaxime Ripard 
27992a56e4SMaxime Ripard 	/* These clocks can only divide, so we will never be able to achieve
28992a56e4SMaxime Ripard 	 * frequencies higher than the parent frequency */
29cfa63688SChen-Yu Tsai 	if (req->rate > req->parent_rate)
30cfa63688SChen-Yu Tsai 		req->rate = req->parent_rate;
31992a56e4SMaxime Ripard 
32cfa63688SChen-Yu Tsai 	div = DIV_ROUND_UP(req->parent_rate, req->rate);
33992a56e4SMaxime Ripard 
34992a56e4SMaxime Ripard 	if (div < 16)
35992a56e4SMaxime Ripard 		calcp = 0;
36992a56e4SMaxime Ripard 	else if (div / 2 < 16)
37992a56e4SMaxime Ripard 		calcp = 1;
38992a56e4SMaxime Ripard 	else if (div / 4 < 16)
39992a56e4SMaxime Ripard 		calcp = 2;
40992a56e4SMaxime Ripard 	else
41992a56e4SMaxime Ripard 		calcp = 3;
42992a56e4SMaxime Ripard 
43992a56e4SMaxime Ripard 	calcm = DIV_ROUND_UP(div, 1 << calcp);
44992a56e4SMaxime Ripard 
45cfa63688SChen-Yu Tsai 	req->rate = (req->parent_rate >> calcp) / calcm;
46cfa63688SChen-Yu Tsai 	req->m = calcm - 1;
47cfa63688SChen-Yu Tsai 	req->p = calcp;
48992a56e4SMaxime Ripard }
49992a56e4SMaxime Ripard 
50992a56e4SMaxime Ripard /* user manual says "n" but it's really "p" */
51b3e919e0SChen-Yu Tsai static const struct clk_factors_config sun4i_a10_mod0_config = {
52992a56e4SMaxime Ripard 	.mshift = 0,
53992a56e4SMaxime Ripard 	.mwidth = 4,
54992a56e4SMaxime Ripard 	.pshift = 16,
55992a56e4SMaxime Ripard 	.pwidth = 2,
56992a56e4SMaxime Ripard };
57992a56e4SMaxime Ripard 
586ea3953dSHans de Goede static const struct factors_data sun4i_a10_mod0_data = {
59992a56e4SMaxime Ripard 	.enable = 31,
60992a56e4SMaxime Ripard 	.mux = 24,
61e94f8cb3SChen-Yu Tsai 	.muxmask = BIT(1) | BIT(0),
62992a56e4SMaxime Ripard 	.table = &sun4i_a10_mod0_config,
63992a56e4SMaxime Ripard 	.getter = sun4i_a10_get_mod0_factors,
64992a56e4SMaxime Ripard };
65992a56e4SMaxime Ripard 
66992a56e4SMaxime Ripard static DEFINE_SPINLOCK(sun4i_a10_mod0_lock);
67992a56e4SMaxime Ripard 
sun4i_a10_mod0_setup(struct device_node * node)68992a56e4SMaxime Ripard static void __init sun4i_a10_mod0_setup(struct device_node *node)
69992a56e4SMaxime Ripard {
707c74c220SHans de Goede 	void __iomem *reg;
717c74c220SHans de Goede 
727c74c220SHans de Goede 	reg = of_iomap(node, 0);
737c74c220SHans de Goede 	if (!reg) {
746ea3953dSHans de Goede 		/*
756ea3953dSHans de Goede 		 * This happens with mod0 clk nodes instantiated through
766ea3953dSHans de Goede 		 * mfd, as those do not have their resources assigned at
776ea3953dSHans de Goede 		 * CLK_OF_DECLARE time yet, so do not print an error.
786ea3953dSHans de Goede 		 */
797c74c220SHans de Goede 		return;
807c74c220SHans de Goede 	}
817c74c220SHans de Goede 
827c74c220SHans de Goede 	sunxi_factors_register(node, &sun4i_a10_mod0_data,
837c74c220SHans de Goede 			       &sun4i_a10_mod0_lock, reg);
84992a56e4SMaxime Ripard }
85cb1291c3SRicardo Ribalda Delgado CLK_OF_DECLARE_DRIVER(sun4i_a10_mod0, "allwinner,sun4i-a10-mod0-clk",
86cb1291c3SRicardo Ribalda Delgado 		      sun4i_a10_mod0_setup);
87eaa18f5dSMaxime Ripard 
sun4i_a10_mod0_clk_probe(struct platform_device * pdev)886ea3953dSHans de Goede static int sun4i_a10_mod0_clk_probe(struct platform_device *pdev)
896ea3953dSHans de Goede {
906ea3953dSHans de Goede 	struct device_node *np = pdev->dev.of_node;
916ea3953dSHans de Goede 	void __iomem *reg;
926ea3953dSHans de Goede 
936ea3953dSHans de Goede 	if (!np)
946ea3953dSHans de Goede 		return -ENODEV;
956ea3953dSHans de Goede 
96*e42f3759SCai Huoqing 	reg = devm_platform_ioremap_resource(pdev, 0);
976ea3953dSHans de Goede 	if (IS_ERR(reg))
986ea3953dSHans de Goede 		return PTR_ERR(reg);
996ea3953dSHans de Goede 
1006ea3953dSHans de Goede 	sunxi_factors_register(np, &sun4i_a10_mod0_data,
1016ea3953dSHans de Goede 			       &sun4i_a10_mod0_lock, reg);
1026ea3953dSHans de Goede 	return 0;
1036ea3953dSHans de Goede }
1046ea3953dSHans de Goede 
1056ea3953dSHans de Goede static const struct of_device_id sun4i_a10_mod0_clk_dt_ids[] = {
1066ea3953dSHans de Goede 	{ .compatible = "allwinner,sun4i-a10-mod0-clk" },
1076ea3953dSHans de Goede 	{ /* sentinel */ }
1086ea3953dSHans de Goede };
1096ea3953dSHans de Goede 
1106ea3953dSHans de Goede static struct platform_driver sun4i_a10_mod0_clk_driver = {
1116ea3953dSHans de Goede 	.driver = {
1126ea3953dSHans de Goede 		.name = "sun4i-a10-mod0-clk",
1136ea3953dSHans de Goede 		.of_match_table = sun4i_a10_mod0_clk_dt_ids,
1146ea3953dSHans de Goede 	},
1156ea3953dSHans de Goede 	.probe = sun4i_a10_mod0_clk_probe,
1166ea3953dSHans de Goede };
11777459a0fSPaul Gortmaker builtin_platform_driver(sun4i_a10_mod0_clk_driver);
1186ea3953dSHans de Goede 
11961af4d8dSChen-Yu Tsai static const struct factors_data sun9i_a80_mod0_data __initconst = {
12061af4d8dSChen-Yu Tsai 	.enable = 31,
12161af4d8dSChen-Yu Tsai 	.mux = 24,
12261af4d8dSChen-Yu Tsai 	.muxmask = BIT(3) | BIT(2) | BIT(1) | BIT(0),
12361af4d8dSChen-Yu Tsai 	.table = &sun4i_a10_mod0_config,
12461af4d8dSChen-Yu Tsai 	.getter = sun4i_a10_get_mod0_factors,
12561af4d8dSChen-Yu Tsai };
12661af4d8dSChen-Yu Tsai 
sun9i_a80_mod0_setup(struct device_node * node)12761af4d8dSChen-Yu Tsai static void __init sun9i_a80_mod0_setup(struct device_node *node)
12861af4d8dSChen-Yu Tsai {
12961af4d8dSChen-Yu Tsai 	void __iomem *reg;
13061af4d8dSChen-Yu Tsai 
13161af4d8dSChen-Yu Tsai 	reg = of_io_request_and_map(node, 0, of_node_full_name(node));
13261af4d8dSChen-Yu Tsai 	if (IS_ERR(reg)) {
133e665f029SRob Herring 		pr_err("Could not get registers for mod0-clk: %pOFn\n",
134e665f029SRob Herring 		       node);
13561af4d8dSChen-Yu Tsai 		return;
13661af4d8dSChen-Yu Tsai 	}
13761af4d8dSChen-Yu Tsai 
13861af4d8dSChen-Yu Tsai 	sunxi_factors_register(node, &sun9i_a80_mod0_data,
13961af4d8dSChen-Yu Tsai 			       &sun4i_a10_mod0_lock, reg);
14061af4d8dSChen-Yu Tsai }
14161af4d8dSChen-Yu Tsai CLK_OF_DECLARE(sun9i_a80_mod0, "allwinner,sun9i-a80-mod0-clk", sun9i_a80_mod0_setup);
14261af4d8dSChen-Yu Tsai 
143eaa18f5dSMaxime Ripard static DEFINE_SPINLOCK(sun5i_a13_mbus_lock);
144eaa18f5dSMaxime Ripard 
sun5i_a13_mbus_setup(struct device_node * node)145eaa18f5dSMaxime Ripard static void __init sun5i_a13_mbus_setup(struct device_node *node)
146eaa18f5dSMaxime Ripard {
1477c74c220SHans de Goede 	void __iomem *reg;
1487c74c220SHans de Goede 
1497c74c220SHans de Goede 	reg = of_iomap(node, 0);
1507c74c220SHans de Goede 	if (!reg) {
1517c74c220SHans de Goede 		pr_err("Could not get registers for a13-mbus-clk\n");
1527c74c220SHans de Goede 		return;
1537c74c220SHans de Goede 	}
1547c74c220SHans de Goede 
155eaa18f5dSMaxime Ripard 	/* The MBUS clocks needs to be always enabled */
1569919d44fSStephen Boyd 	sunxi_factors_register_critical(node, &sun4i_a10_mod0_data,
1579919d44fSStephen Boyd 					&sun5i_a13_mbus_lock, reg);
158eaa18f5dSMaxime Ripard }
159eaa18f5dSMaxime Ripard CLK_OF_DECLARE(sun5i_a13_mbus, "allwinner,sun5i-a13-mbus-clk", sun5i_a13_mbus_setup);
16037e1041fSMaxime Ripard 
16137e1041fSMaxime Ripard struct mmc_phase {
16237e1041fSMaxime Ripard 	struct clk_hw		hw;
1636b0b8ccfSMaxime Ripard 	u8			offset;
16437e1041fSMaxime Ripard 	void __iomem		*reg;
16537e1041fSMaxime Ripard 	spinlock_t		*lock;
16637e1041fSMaxime Ripard };
16737e1041fSMaxime Ripard 
16837e1041fSMaxime Ripard #define to_mmc_phase(_hw) container_of(_hw, struct mmc_phase, hw)
16937e1041fSMaxime Ripard 
mmc_get_phase(struct clk_hw * hw)17037e1041fSMaxime Ripard static int mmc_get_phase(struct clk_hw *hw)
17137e1041fSMaxime Ripard {
17237e1041fSMaxime Ripard 	struct clk *mmc, *mmc_parent, *clk = hw->clk;
17337e1041fSMaxime Ripard 	struct mmc_phase *phase = to_mmc_phase(hw);
17437e1041fSMaxime Ripard 	unsigned int mmc_rate, mmc_parent_rate;
17537e1041fSMaxime Ripard 	u16 step, mmc_div;
17637e1041fSMaxime Ripard 	u32 value;
17737e1041fSMaxime Ripard 	u8 delay;
17837e1041fSMaxime Ripard 
17937e1041fSMaxime Ripard 	value = readl(phase->reg);
1806b0b8ccfSMaxime Ripard 	delay = (value >> phase->offset) & 0x3;
18137e1041fSMaxime Ripard 
18237e1041fSMaxime Ripard 	if (!delay)
18337e1041fSMaxime Ripard 		return 180;
18437e1041fSMaxime Ripard 
18537e1041fSMaxime Ripard 	/* Get the main MMC clock */
18637e1041fSMaxime Ripard 	mmc = clk_get_parent(clk);
18737e1041fSMaxime Ripard 	if (!mmc)
18837e1041fSMaxime Ripard 		return -EINVAL;
18937e1041fSMaxime Ripard 
19037e1041fSMaxime Ripard 	/* And its rate */
19137e1041fSMaxime Ripard 	mmc_rate = clk_get_rate(mmc);
19237e1041fSMaxime Ripard 	if (!mmc_rate)
19337e1041fSMaxime Ripard 		return -EINVAL;
19437e1041fSMaxime Ripard 
19537e1041fSMaxime Ripard 	/* Now, get the MMC parent (most likely some PLL) */
19637e1041fSMaxime Ripard 	mmc_parent = clk_get_parent(mmc);
19737e1041fSMaxime Ripard 	if (!mmc_parent)
19837e1041fSMaxime Ripard 		return -EINVAL;
19937e1041fSMaxime Ripard 
20037e1041fSMaxime Ripard 	/* And its rate */
20137e1041fSMaxime Ripard 	mmc_parent_rate = clk_get_rate(mmc_parent);
20237e1041fSMaxime Ripard 	if (!mmc_parent_rate)
20337e1041fSMaxime Ripard 		return -EINVAL;
20437e1041fSMaxime Ripard 
20537e1041fSMaxime Ripard 	/* Get MMC clock divider */
20637e1041fSMaxime Ripard 	mmc_div = mmc_parent_rate / mmc_rate;
20737e1041fSMaxime Ripard 
20837e1041fSMaxime Ripard 	step = DIV_ROUND_CLOSEST(360, mmc_div);
20937e1041fSMaxime Ripard 	return delay * step;
21037e1041fSMaxime Ripard }
21137e1041fSMaxime Ripard 
mmc_set_phase(struct clk_hw * hw,int degrees)21237e1041fSMaxime Ripard static int mmc_set_phase(struct clk_hw *hw, int degrees)
21337e1041fSMaxime Ripard {
21437e1041fSMaxime Ripard 	struct clk *mmc, *mmc_parent, *clk = hw->clk;
21537e1041fSMaxime Ripard 	struct mmc_phase *phase = to_mmc_phase(hw);
21637e1041fSMaxime Ripard 	unsigned int mmc_rate, mmc_parent_rate;
21737e1041fSMaxime Ripard 	unsigned long flags;
21837e1041fSMaxime Ripard 	u32 value;
21937e1041fSMaxime Ripard 	u8 delay;
22037e1041fSMaxime Ripard 
22137e1041fSMaxime Ripard 	/* Get the main MMC clock */
22237e1041fSMaxime Ripard 	mmc = clk_get_parent(clk);
22337e1041fSMaxime Ripard 	if (!mmc)
22437e1041fSMaxime Ripard 		return -EINVAL;
22537e1041fSMaxime Ripard 
22637e1041fSMaxime Ripard 	/* And its rate */
22737e1041fSMaxime Ripard 	mmc_rate = clk_get_rate(mmc);
22837e1041fSMaxime Ripard 	if (!mmc_rate)
22937e1041fSMaxime Ripard 		return -EINVAL;
23037e1041fSMaxime Ripard 
23137e1041fSMaxime Ripard 	/* Now, get the MMC parent (most likely some PLL) */
23237e1041fSMaxime Ripard 	mmc_parent = clk_get_parent(mmc);
23337e1041fSMaxime Ripard 	if (!mmc_parent)
23437e1041fSMaxime Ripard 		return -EINVAL;
23537e1041fSMaxime Ripard 
23637e1041fSMaxime Ripard 	/* And its rate */
23737e1041fSMaxime Ripard 	mmc_parent_rate = clk_get_rate(mmc_parent);
23837e1041fSMaxime Ripard 	if (!mmc_parent_rate)
23937e1041fSMaxime Ripard 		return -EINVAL;
24037e1041fSMaxime Ripard 
24137e1041fSMaxime Ripard 	if (degrees != 180) {
24237e1041fSMaxime Ripard 		u16 step, mmc_div;
24337e1041fSMaxime Ripard 
24437e1041fSMaxime Ripard 		/* Get MMC clock divider */
24537e1041fSMaxime Ripard 		mmc_div = mmc_parent_rate / mmc_rate;
24637e1041fSMaxime Ripard 
24737e1041fSMaxime Ripard 		/*
24837e1041fSMaxime Ripard 		 * We can only outphase the clocks by multiple of the
24937e1041fSMaxime Ripard 		 * PLL's period.
25037e1041fSMaxime Ripard 		 *
25137e1041fSMaxime Ripard 		 * Since the MMC clock in only a divider, and the
25237e1041fSMaxime Ripard 		 * formula to get the outphasing in degrees is deg =
25337e1041fSMaxime Ripard 		 * 360 * delta / period
25437e1041fSMaxime Ripard 		 *
25537e1041fSMaxime Ripard 		 * If we simplify this formula, we can see that the
25637e1041fSMaxime Ripard 		 * only thing that we're concerned about is the number
25737e1041fSMaxime Ripard 		 * of period we want to outphase our clock from, and
25837e1041fSMaxime Ripard 		 * the divider set by the MMC clock.
25937e1041fSMaxime Ripard 		 */
26037e1041fSMaxime Ripard 		step = DIV_ROUND_CLOSEST(360, mmc_div);
26137e1041fSMaxime Ripard 		delay = DIV_ROUND_CLOSEST(degrees, step);
26237e1041fSMaxime Ripard 	} else {
26337e1041fSMaxime Ripard 		delay = 0;
26437e1041fSMaxime Ripard 	}
26537e1041fSMaxime Ripard 
26637e1041fSMaxime Ripard 	spin_lock_irqsave(phase->lock, flags);
26737e1041fSMaxime Ripard 	value = readl(phase->reg);
2686b0b8ccfSMaxime Ripard 	value &= ~GENMASK(phase->offset + 3, phase->offset);
2696b0b8ccfSMaxime Ripard 	value |= delay << phase->offset;
27037e1041fSMaxime Ripard 	writel(value, phase->reg);
27137e1041fSMaxime Ripard 	spin_unlock_irqrestore(phase->lock, flags);
27237e1041fSMaxime Ripard 
27337e1041fSMaxime Ripard 	return 0;
27437e1041fSMaxime Ripard }
27537e1041fSMaxime Ripard 
27637e1041fSMaxime Ripard static const struct clk_ops mmc_clk_ops = {
27737e1041fSMaxime Ripard 	.get_phase	= mmc_get_phase,
27837e1041fSMaxime Ripard 	.set_phase	= mmc_set_phase,
27937e1041fSMaxime Ripard };
28037e1041fSMaxime Ripard 
281eb378df7SChen-Yu Tsai /*
282eb378df7SChen-Yu Tsai  * sunxi_mmc_setup - Common setup function for mmc module clocks
283eb378df7SChen-Yu Tsai  *
284eb378df7SChen-Yu Tsai  * The only difference between module clocks on different platforms is the
285eb378df7SChen-Yu Tsai  * width of the mux register bits and the valid values, which are passed in
286eb378df7SChen-Yu Tsai  * through struct factors_data. The phase clocks parts are identical.
287eb378df7SChen-Yu Tsai  */
sunxi_mmc_setup(struct device_node * node,const struct factors_data * data,spinlock_t * lock)288eb378df7SChen-Yu Tsai static void __init sunxi_mmc_setup(struct device_node *node,
289eb378df7SChen-Yu Tsai 				   const struct factors_data *data,
290eb378df7SChen-Yu Tsai 				   spinlock_t *lock)
29137e1041fSMaxime Ripard {
2926b0b8ccfSMaxime Ripard 	struct clk_onecell_data *clk_data;
2936b0b8ccfSMaxime Ripard 	const char *parent;
2946b0b8ccfSMaxime Ripard 	void __iomem *reg;
2956b0b8ccfSMaxime Ripard 	int i;
2966b0b8ccfSMaxime Ripard 
2976b0b8ccfSMaxime Ripard 	reg = of_io_request_and_map(node, 0, of_node_full_name(node));
2986b0b8ccfSMaxime Ripard 	if (IS_ERR(reg)) {
299e665f029SRob Herring 		pr_err("Couldn't map the %pOFn clock registers\n", node);
3006b0b8ccfSMaxime Ripard 		return;
3016b0b8ccfSMaxime Ripard 	}
3026b0b8ccfSMaxime Ripard 
3036b0b8ccfSMaxime Ripard 	clk_data = kmalloc(sizeof(*clk_data), GFP_KERNEL);
3046b0b8ccfSMaxime Ripard 	if (!clk_data)
3056b0b8ccfSMaxime Ripard 		return;
3066b0b8ccfSMaxime Ripard 
3076b0b8ccfSMaxime Ripard 	clk_data->clks = kcalloc(3, sizeof(*clk_data->clks), GFP_KERNEL);
3086b0b8ccfSMaxime Ripard 	if (!clk_data->clks)
3096b0b8ccfSMaxime Ripard 		goto err_free_data;
3106b0b8ccfSMaxime Ripard 
3116b0b8ccfSMaxime Ripard 	clk_data->clk_num = 3;
312eb378df7SChen-Yu Tsai 	clk_data->clks[0] = sunxi_factors_register(node, data, lock, reg);
3136b0b8ccfSMaxime Ripard 	if (!clk_data->clks[0])
3146b0b8ccfSMaxime Ripard 		goto err_free_clks;
3156b0b8ccfSMaxime Ripard 
3166b0b8ccfSMaxime Ripard 	parent = __clk_get_name(clk_data->clks[0]);
3176b0b8ccfSMaxime Ripard 
3186b0b8ccfSMaxime Ripard 	for (i = 1; i < 3; i++) {
31937e1041fSMaxime Ripard 		struct clk_init_data init = {
32037e1041fSMaxime Ripard 			.num_parents	= 1,
3216b0b8ccfSMaxime Ripard 			.parent_names	= &parent,
32237e1041fSMaxime Ripard 			.ops		= &mmc_clk_ops,
32337e1041fSMaxime Ripard 		};
32437e1041fSMaxime Ripard 		struct mmc_phase *phase;
32537e1041fSMaxime Ripard 
32637e1041fSMaxime Ripard 		phase = kmalloc(sizeof(*phase), GFP_KERNEL);
32737e1041fSMaxime Ripard 		if (!phase)
3286b0b8ccfSMaxime Ripard 			continue;
32937e1041fSMaxime Ripard 
33037e1041fSMaxime Ripard 		phase->hw.init = &init;
3316b0b8ccfSMaxime Ripard 		phase->reg = reg;
332eb378df7SChen-Yu Tsai 		phase->lock = lock;
33337e1041fSMaxime Ripard 
3346b0b8ccfSMaxime Ripard 		if (i == 1)
3356b0b8ccfSMaxime Ripard 			phase->offset = 8;
3366b0b8ccfSMaxime Ripard 		else
3376b0b8ccfSMaxime Ripard 			phase->offset = 20;
33837e1041fSMaxime Ripard 
3396b0b8ccfSMaxime Ripard 		if (of_property_read_string_index(node, "clock-output-names",
3406b0b8ccfSMaxime Ripard 						  i, &init.name))
34137e1041fSMaxime Ripard 			init.name = node->name;
34237e1041fSMaxime Ripard 
3436b0b8ccfSMaxime Ripard 		clk_data->clks[i] = clk_register(NULL, &phase->hw);
3446b0b8ccfSMaxime Ripard 		if (IS_ERR(clk_data->clks[i])) {
3456b0b8ccfSMaxime Ripard 			kfree(phase);
3466b0b8ccfSMaxime Ripard 			continue;
3476b0b8ccfSMaxime Ripard 		}
3486b0b8ccfSMaxime Ripard 	}
34937e1041fSMaxime Ripard 
3506b0b8ccfSMaxime Ripard 	of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
35137e1041fSMaxime Ripard 
35237e1041fSMaxime Ripard 	return;
35337e1041fSMaxime Ripard 
3546b0b8ccfSMaxime Ripard err_free_clks:
3556b0b8ccfSMaxime Ripard 	kfree(clk_data->clks);
3566b0b8ccfSMaxime Ripard err_free_data:
3576b0b8ccfSMaxime Ripard 	kfree(clk_data);
35837e1041fSMaxime Ripard }
359eb378df7SChen-Yu Tsai 
360eb378df7SChen-Yu Tsai static DEFINE_SPINLOCK(sun4i_a10_mmc_lock);
361eb378df7SChen-Yu Tsai 
sun4i_a10_mmc_setup(struct device_node * node)362eb378df7SChen-Yu Tsai static void __init sun4i_a10_mmc_setup(struct device_node *node)
363eb378df7SChen-Yu Tsai {
364eb378df7SChen-Yu Tsai 	sunxi_mmc_setup(node, &sun4i_a10_mod0_data, &sun4i_a10_mmc_lock);
365eb378df7SChen-Yu Tsai }
3666b0b8ccfSMaxime Ripard CLK_OF_DECLARE(sun4i_a10_mmc, "allwinner,sun4i-a10-mmc-clk", sun4i_a10_mmc_setup);
36761af4d8dSChen-Yu Tsai 
36861af4d8dSChen-Yu Tsai static DEFINE_SPINLOCK(sun9i_a80_mmc_lock);
36961af4d8dSChen-Yu Tsai 
sun9i_a80_mmc_setup(struct device_node * node)37061af4d8dSChen-Yu Tsai static void __init sun9i_a80_mmc_setup(struct device_node *node)
37161af4d8dSChen-Yu Tsai {
37261af4d8dSChen-Yu Tsai 	sunxi_mmc_setup(node, &sun9i_a80_mod0_data, &sun9i_a80_mmc_lock);
37361af4d8dSChen-Yu Tsai }
37461af4d8dSChen-Yu Tsai CLK_OF_DECLARE(sun9i_a80_mmc, "allwinner,sun9i-a80-mmc-clk", sun9i_a80_mmc_setup);
375