xref: /linux/drivers/net/mdio/mdio-mux-meson-g12a.c (revision 32e54254bab86529f6adcfd7fec6fae29a6ed4ff)
1a9770eacSAndrew Lunn // SPDX-License-Identifier: GPL-2.0
2a9770eacSAndrew Lunn /* Copyright (c) 2019 Baylibre, SAS.
3a9770eacSAndrew Lunn  * Author: Jerome Brunet <jbrunet@baylibre.com>
4a9770eacSAndrew Lunn  */
5a9770eacSAndrew Lunn 
6a9770eacSAndrew Lunn #include <linux/bitfield.h>
7a9770eacSAndrew Lunn #include <linux/clk.h>
8a9770eacSAndrew Lunn #include <linux/clk-provider.h>
9a9770eacSAndrew Lunn #include <linux/device.h>
10a9770eacSAndrew Lunn #include <linux/io.h>
11a9770eacSAndrew Lunn #include <linux/iopoll.h>
12a9770eacSAndrew Lunn #include <linux/mdio-mux.h>
13a9770eacSAndrew Lunn #include <linux/module.h>
14a9770eacSAndrew Lunn #include <linux/phy.h>
15a9770eacSAndrew Lunn #include <linux/platform_device.h>
16a9770eacSAndrew Lunn 
17a9770eacSAndrew Lunn #define ETH_PLL_STS		0x40
18a9770eacSAndrew Lunn #define ETH_PLL_CTL0		0x44
19a9770eacSAndrew Lunn #define  PLL_CTL0_LOCK_DIG	BIT(30)
20a9770eacSAndrew Lunn #define  PLL_CTL0_RST		BIT(29)
21a9770eacSAndrew Lunn #define  PLL_CTL0_EN		BIT(28)
22a9770eacSAndrew Lunn #define  PLL_CTL0_SEL		BIT(23)
23a9770eacSAndrew Lunn #define  PLL_CTL0_N		GENMASK(14, 10)
24a9770eacSAndrew Lunn #define  PLL_CTL0_M		GENMASK(8, 0)
25a9770eacSAndrew Lunn #define  PLL_LOCK_TIMEOUT	1000000
26a9770eacSAndrew Lunn #define  PLL_MUX_NUM_PARENT	2
27a9770eacSAndrew Lunn #define ETH_PLL_CTL1		0x48
28a9770eacSAndrew Lunn #define ETH_PLL_CTL2		0x4c
29a9770eacSAndrew Lunn #define ETH_PLL_CTL3		0x50
30a9770eacSAndrew Lunn #define ETH_PLL_CTL4		0x54
31a9770eacSAndrew Lunn #define ETH_PLL_CTL5		0x58
32a9770eacSAndrew Lunn #define ETH_PLL_CTL6		0x5c
33a9770eacSAndrew Lunn #define ETH_PLL_CTL7		0x60
34a9770eacSAndrew Lunn 
35a9770eacSAndrew Lunn #define ETH_PHY_CNTL0		0x80
36a9770eacSAndrew Lunn #define   EPHY_G12A_ID		0x33010180
37a9770eacSAndrew Lunn #define ETH_PHY_CNTL1		0x84
38a9770eacSAndrew Lunn #define  PHY_CNTL1_ST_MODE	GENMASK(2, 0)
39a9770eacSAndrew Lunn #define  PHY_CNTL1_ST_PHYADD	GENMASK(7, 3)
40a9770eacSAndrew Lunn #define   EPHY_DFLT_ADD		8
41a9770eacSAndrew Lunn #define  PHY_CNTL1_MII_MODE	GENMASK(15, 14)
42a9770eacSAndrew Lunn #define   EPHY_MODE_RMII	0x1
43a9770eacSAndrew Lunn #define  PHY_CNTL1_CLK_EN	BIT(16)
44a9770eacSAndrew Lunn #define  PHY_CNTL1_CLKFREQ	BIT(17)
45a9770eacSAndrew Lunn #define  PHY_CNTL1_PHY_ENB	BIT(18)
46a9770eacSAndrew Lunn #define ETH_PHY_CNTL2		0x88
47a9770eacSAndrew Lunn #define  PHY_CNTL2_USE_INTERNAL	BIT(5)
48a9770eacSAndrew Lunn #define  PHY_CNTL2_SMI_SRC_MAC	BIT(6)
49a9770eacSAndrew Lunn #define  PHY_CNTL2_RX_CLK_EPHY	BIT(9)
50a9770eacSAndrew Lunn 
51a9770eacSAndrew Lunn #define MESON_G12A_MDIO_EXTERNAL_ID 0
52a9770eacSAndrew Lunn #define MESON_G12A_MDIO_INTERNAL_ID 1
53a9770eacSAndrew Lunn 
54a9770eacSAndrew Lunn struct g12a_mdio_mux {
55a9770eacSAndrew Lunn 	bool pll_is_enabled;
56a9770eacSAndrew Lunn 	void __iomem *regs;
57a9770eacSAndrew Lunn 	void *mux_handle;
58a9770eacSAndrew Lunn 	struct clk *pll;
59a9770eacSAndrew Lunn };
60a9770eacSAndrew Lunn 
61a9770eacSAndrew Lunn struct g12a_ephy_pll {
62a9770eacSAndrew Lunn 	void __iomem *base;
63a9770eacSAndrew Lunn 	struct clk_hw hw;
64a9770eacSAndrew Lunn };
65a9770eacSAndrew Lunn 
66a9770eacSAndrew Lunn #define g12a_ephy_pll_to_dev(_hw)			\
67a9770eacSAndrew Lunn 	container_of(_hw, struct g12a_ephy_pll, hw)
68a9770eacSAndrew Lunn 
69a9770eacSAndrew Lunn static unsigned long g12a_ephy_pll_recalc_rate(struct clk_hw *hw,
70a9770eacSAndrew Lunn 					       unsigned long parent_rate)
71a9770eacSAndrew Lunn {
72a9770eacSAndrew Lunn 	struct g12a_ephy_pll *pll = g12a_ephy_pll_to_dev(hw);
73a9770eacSAndrew Lunn 	u32 val, m, n;
74a9770eacSAndrew Lunn 
75a9770eacSAndrew Lunn 	val = readl(pll->base + ETH_PLL_CTL0);
76a9770eacSAndrew Lunn 	m = FIELD_GET(PLL_CTL0_M, val);
77a9770eacSAndrew Lunn 	n = FIELD_GET(PLL_CTL0_N, val);
78a9770eacSAndrew Lunn 
79a9770eacSAndrew Lunn 	return parent_rate * m / n;
80a9770eacSAndrew Lunn }
81a9770eacSAndrew Lunn 
82a9770eacSAndrew Lunn static int g12a_ephy_pll_enable(struct clk_hw *hw)
83a9770eacSAndrew Lunn {
84a9770eacSAndrew Lunn 	struct g12a_ephy_pll *pll = g12a_ephy_pll_to_dev(hw);
85a9770eacSAndrew Lunn 	u32 val = readl(pll->base + ETH_PLL_CTL0);
86a9770eacSAndrew Lunn 
87a9770eacSAndrew Lunn 	/* Apply both enable an reset */
88a9770eacSAndrew Lunn 	val |= PLL_CTL0_RST | PLL_CTL0_EN;
89a9770eacSAndrew Lunn 	writel(val, pll->base + ETH_PLL_CTL0);
90a9770eacSAndrew Lunn 
91a9770eacSAndrew Lunn 	/* Clear the reset to let PLL lock */
92a9770eacSAndrew Lunn 	val &= ~PLL_CTL0_RST;
93a9770eacSAndrew Lunn 	writel(val, pll->base + ETH_PLL_CTL0);
94a9770eacSAndrew Lunn 
95a9770eacSAndrew Lunn 	/* Poll on the digital lock instead of the usual analog lock
96a9770eacSAndrew Lunn 	 * This is done because bit 31 is unreliable on some SoC. Bit
97a9770eacSAndrew Lunn 	 * 31 may indicate that the PLL is not lock even though the clock
98a9770eacSAndrew Lunn 	 * is actually running
99a9770eacSAndrew Lunn 	 */
100a9770eacSAndrew Lunn 	return readl_poll_timeout(pll->base + ETH_PLL_CTL0, val,
101a9770eacSAndrew Lunn 				  val & PLL_CTL0_LOCK_DIG, 0, PLL_LOCK_TIMEOUT);
102a9770eacSAndrew Lunn }
103a9770eacSAndrew Lunn 
104a9770eacSAndrew Lunn static void g12a_ephy_pll_disable(struct clk_hw *hw)
105a9770eacSAndrew Lunn {
106a9770eacSAndrew Lunn 	struct g12a_ephy_pll *pll = g12a_ephy_pll_to_dev(hw);
107a9770eacSAndrew Lunn 	u32 val;
108a9770eacSAndrew Lunn 
109a9770eacSAndrew Lunn 	val = readl(pll->base + ETH_PLL_CTL0);
110a9770eacSAndrew Lunn 	val &= ~PLL_CTL0_EN;
111a9770eacSAndrew Lunn 	val |= PLL_CTL0_RST;
112a9770eacSAndrew Lunn 	writel(val, pll->base + ETH_PLL_CTL0);
113a9770eacSAndrew Lunn }
114a9770eacSAndrew Lunn 
115a9770eacSAndrew Lunn static int g12a_ephy_pll_is_enabled(struct clk_hw *hw)
116a9770eacSAndrew Lunn {
117a9770eacSAndrew Lunn 	struct g12a_ephy_pll *pll = g12a_ephy_pll_to_dev(hw);
118a9770eacSAndrew Lunn 	unsigned int val;
119a9770eacSAndrew Lunn 
120a9770eacSAndrew Lunn 	val = readl(pll->base + ETH_PLL_CTL0);
121a9770eacSAndrew Lunn 
122a9770eacSAndrew Lunn 	return (val & PLL_CTL0_LOCK_DIG) ? 1 : 0;
123a9770eacSAndrew Lunn }
124a9770eacSAndrew Lunn 
125a9770eacSAndrew Lunn static int g12a_ephy_pll_init(struct clk_hw *hw)
126a9770eacSAndrew Lunn {
127a9770eacSAndrew Lunn 	struct g12a_ephy_pll *pll = g12a_ephy_pll_to_dev(hw);
128a9770eacSAndrew Lunn 
129a9770eacSAndrew Lunn 	/* Apply PLL HW settings */
130a9770eacSAndrew Lunn 	writel(0x29c0040a, pll->base + ETH_PLL_CTL0);
131a9770eacSAndrew Lunn 	writel(0x927e0000, pll->base + ETH_PLL_CTL1);
132a9770eacSAndrew Lunn 	writel(0xac5f49e5, pll->base + ETH_PLL_CTL2);
133a9770eacSAndrew Lunn 	writel(0x00000000, pll->base + ETH_PLL_CTL3);
134a9770eacSAndrew Lunn 	writel(0x00000000, pll->base + ETH_PLL_CTL4);
135a9770eacSAndrew Lunn 	writel(0x20200000, pll->base + ETH_PLL_CTL5);
136a9770eacSAndrew Lunn 	writel(0x0000c002, pll->base + ETH_PLL_CTL6);
137a9770eacSAndrew Lunn 	writel(0x00000023, pll->base + ETH_PLL_CTL7);
138a9770eacSAndrew Lunn 
139a9770eacSAndrew Lunn 	return 0;
140a9770eacSAndrew Lunn }
141a9770eacSAndrew Lunn 
142a9770eacSAndrew Lunn static const struct clk_ops g12a_ephy_pll_ops = {
143a9770eacSAndrew Lunn 	.recalc_rate	= g12a_ephy_pll_recalc_rate,
144a9770eacSAndrew Lunn 	.is_enabled	= g12a_ephy_pll_is_enabled,
145a9770eacSAndrew Lunn 	.enable		= g12a_ephy_pll_enable,
146a9770eacSAndrew Lunn 	.disable	= g12a_ephy_pll_disable,
147a9770eacSAndrew Lunn 	.init		= g12a_ephy_pll_init,
148a9770eacSAndrew Lunn };
149a9770eacSAndrew Lunn 
150a9770eacSAndrew Lunn static int g12a_enable_internal_mdio(struct g12a_mdio_mux *priv)
151a9770eacSAndrew Lunn {
152a9770eacSAndrew Lunn 	int ret;
153a9770eacSAndrew Lunn 
154a9770eacSAndrew Lunn 	/* Enable the phy clock */
155a9770eacSAndrew Lunn 	if (!priv->pll_is_enabled) {
156a9770eacSAndrew Lunn 		ret = clk_prepare_enable(priv->pll);
157a9770eacSAndrew Lunn 		if (ret)
158a9770eacSAndrew Lunn 			return ret;
159a9770eacSAndrew Lunn 	}
160a9770eacSAndrew Lunn 
161a9770eacSAndrew Lunn 	priv->pll_is_enabled = true;
162a9770eacSAndrew Lunn 
163a9770eacSAndrew Lunn 	/* Initialize ephy control */
164a9770eacSAndrew Lunn 	writel(EPHY_G12A_ID, priv->regs + ETH_PHY_CNTL0);
165a9770eacSAndrew Lunn 	writel(FIELD_PREP(PHY_CNTL1_ST_MODE, 3) |
166a9770eacSAndrew Lunn 	       FIELD_PREP(PHY_CNTL1_ST_PHYADD, EPHY_DFLT_ADD) |
167a9770eacSAndrew Lunn 	       FIELD_PREP(PHY_CNTL1_MII_MODE, EPHY_MODE_RMII) |
168a9770eacSAndrew Lunn 	       PHY_CNTL1_CLK_EN |
169a9770eacSAndrew Lunn 	       PHY_CNTL1_CLKFREQ |
170a9770eacSAndrew Lunn 	       PHY_CNTL1_PHY_ENB,
171a9770eacSAndrew Lunn 	       priv->regs + ETH_PHY_CNTL1);
172a9770eacSAndrew Lunn 	writel(PHY_CNTL2_USE_INTERNAL |
173a9770eacSAndrew Lunn 	       PHY_CNTL2_SMI_SRC_MAC |
174a9770eacSAndrew Lunn 	       PHY_CNTL2_RX_CLK_EPHY,
175a9770eacSAndrew Lunn 	       priv->regs + ETH_PHY_CNTL2);
176a9770eacSAndrew Lunn 
177a9770eacSAndrew Lunn 	return 0;
178a9770eacSAndrew Lunn }
179a9770eacSAndrew Lunn 
180a9770eacSAndrew Lunn static int g12a_enable_external_mdio(struct g12a_mdio_mux *priv)
181a9770eacSAndrew Lunn {
182a9770eacSAndrew Lunn 	/* Reset the mdio bus mux */
183a9770eacSAndrew Lunn 	writel_relaxed(0x0, priv->regs + ETH_PHY_CNTL2);
184a9770eacSAndrew Lunn 
185a9770eacSAndrew Lunn 	/* Disable the phy clock if enabled */
186a9770eacSAndrew Lunn 	if (priv->pll_is_enabled) {
187a9770eacSAndrew Lunn 		clk_disable_unprepare(priv->pll);
188a9770eacSAndrew Lunn 		priv->pll_is_enabled = false;
189a9770eacSAndrew Lunn 	}
190a9770eacSAndrew Lunn 
191a9770eacSAndrew Lunn 	return 0;
192a9770eacSAndrew Lunn }
193a9770eacSAndrew Lunn 
194a9770eacSAndrew Lunn static int g12a_mdio_switch_fn(int current_child, int desired_child,
195a9770eacSAndrew Lunn 			       void *data)
196a9770eacSAndrew Lunn {
197a9770eacSAndrew Lunn 	struct g12a_mdio_mux *priv = dev_get_drvdata(data);
198a9770eacSAndrew Lunn 
199a9770eacSAndrew Lunn 	if (current_child == desired_child)
200a9770eacSAndrew Lunn 		return 0;
201a9770eacSAndrew Lunn 
202a9770eacSAndrew Lunn 	switch (desired_child) {
203a9770eacSAndrew Lunn 	case MESON_G12A_MDIO_EXTERNAL_ID:
204a9770eacSAndrew Lunn 		return g12a_enable_external_mdio(priv);
205a9770eacSAndrew Lunn 	case MESON_G12A_MDIO_INTERNAL_ID:
206a9770eacSAndrew Lunn 		return g12a_enable_internal_mdio(priv);
207a9770eacSAndrew Lunn 	default:
208a9770eacSAndrew Lunn 		return -EINVAL;
209a9770eacSAndrew Lunn 	}
210a9770eacSAndrew Lunn }
211a9770eacSAndrew Lunn 
212a9770eacSAndrew Lunn static const struct of_device_id g12a_mdio_mux_match[] = {
213a9770eacSAndrew Lunn 	{ .compatible = "amlogic,g12a-mdio-mux", },
214a9770eacSAndrew Lunn 	{},
215a9770eacSAndrew Lunn };
216a9770eacSAndrew Lunn MODULE_DEVICE_TABLE(of, g12a_mdio_mux_match);
217a9770eacSAndrew Lunn 
218a9770eacSAndrew Lunn static int g12a_ephy_glue_clk_register(struct device *dev)
219a9770eacSAndrew Lunn {
220a9770eacSAndrew Lunn 	struct g12a_mdio_mux *priv = dev_get_drvdata(dev);
221a9770eacSAndrew Lunn 	const char *parent_names[PLL_MUX_NUM_PARENT];
222a9770eacSAndrew Lunn 	struct clk_init_data init;
223a9770eacSAndrew Lunn 	struct g12a_ephy_pll *pll;
224a9770eacSAndrew Lunn 	struct clk_mux *mux;
225a9770eacSAndrew Lunn 	struct clk *clk;
226a9770eacSAndrew Lunn 	char *name;
227a9770eacSAndrew Lunn 	int i;
228a9770eacSAndrew Lunn 
229a9770eacSAndrew Lunn 	/* get the mux parents */
230a9770eacSAndrew Lunn 	for (i = 0; i < PLL_MUX_NUM_PARENT; i++) {
231a9770eacSAndrew Lunn 		char in_name[8];
232a9770eacSAndrew Lunn 
233a9770eacSAndrew Lunn 		snprintf(in_name, sizeof(in_name), "clkin%d", i);
234a9770eacSAndrew Lunn 		clk = devm_clk_get(dev, in_name);
235de0665c8SYang Yingliang 		if (IS_ERR(clk))
236de0665c8SYang Yingliang 			return dev_err_probe(dev, PTR_ERR(clk),
237de0665c8SYang Yingliang 					     "Missing clock %s\n", in_name);
238a9770eacSAndrew Lunn 
239a9770eacSAndrew Lunn 		parent_names[i] = __clk_get_name(clk);
240a9770eacSAndrew Lunn 	}
241a9770eacSAndrew Lunn 
242a9770eacSAndrew Lunn 	/* create the input mux */
243a9770eacSAndrew Lunn 	mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL);
244a9770eacSAndrew Lunn 	if (!mux)
245a9770eacSAndrew Lunn 		return -ENOMEM;
246a9770eacSAndrew Lunn 
247a9770eacSAndrew Lunn 	name = kasprintf(GFP_KERNEL, "%s#mux", dev_name(dev));
248a9770eacSAndrew Lunn 	if (!name)
249a9770eacSAndrew Lunn 		return -ENOMEM;
250a9770eacSAndrew Lunn 
251a9770eacSAndrew Lunn 	init.name = name;
252a9770eacSAndrew Lunn 	init.ops = &clk_mux_ro_ops;
253a9770eacSAndrew Lunn 	init.flags = 0;
254a9770eacSAndrew Lunn 	init.parent_names = parent_names;
255a9770eacSAndrew Lunn 	init.num_parents = PLL_MUX_NUM_PARENT;
256a9770eacSAndrew Lunn 
257a9770eacSAndrew Lunn 	mux->reg = priv->regs + ETH_PLL_CTL0;
258a9770eacSAndrew Lunn 	mux->shift = __ffs(PLL_CTL0_SEL);
259a9770eacSAndrew Lunn 	mux->mask = PLL_CTL0_SEL >> mux->shift;
260a9770eacSAndrew Lunn 	mux->hw.init = &init;
261a9770eacSAndrew Lunn 
262a9770eacSAndrew Lunn 	clk = devm_clk_register(dev, &mux->hw);
263a9770eacSAndrew Lunn 	kfree(name);
264a9770eacSAndrew Lunn 	if (IS_ERR(clk)) {
265a9770eacSAndrew Lunn 		dev_err(dev, "failed to register input mux\n");
266a9770eacSAndrew Lunn 		return PTR_ERR(clk);
267a9770eacSAndrew Lunn 	}
268a9770eacSAndrew Lunn 
269a9770eacSAndrew Lunn 	/* create the pll */
270a9770eacSAndrew Lunn 	pll = devm_kzalloc(dev, sizeof(*pll), GFP_KERNEL);
271a9770eacSAndrew Lunn 	if (!pll)
272a9770eacSAndrew Lunn 		return -ENOMEM;
273a9770eacSAndrew Lunn 
274a9770eacSAndrew Lunn 	name = kasprintf(GFP_KERNEL, "%s#pll", dev_name(dev));
275a9770eacSAndrew Lunn 	if (!name)
276a9770eacSAndrew Lunn 		return -ENOMEM;
277a9770eacSAndrew Lunn 
278a9770eacSAndrew Lunn 	init.name = name;
279a9770eacSAndrew Lunn 	init.ops = &g12a_ephy_pll_ops;
280a9770eacSAndrew Lunn 	init.flags = 0;
281a9770eacSAndrew Lunn 	parent_names[0] = __clk_get_name(clk);
282a9770eacSAndrew Lunn 	init.parent_names = parent_names;
283a9770eacSAndrew Lunn 	init.num_parents = 1;
284a9770eacSAndrew Lunn 
285a9770eacSAndrew Lunn 	pll->base = priv->regs;
286a9770eacSAndrew Lunn 	pll->hw.init = &init;
287a9770eacSAndrew Lunn 
288a9770eacSAndrew Lunn 	clk = devm_clk_register(dev, &pll->hw);
289a9770eacSAndrew Lunn 	kfree(name);
290a9770eacSAndrew Lunn 	if (IS_ERR(clk)) {
291a9770eacSAndrew Lunn 		dev_err(dev, "failed to register input mux\n");
292a9770eacSAndrew Lunn 		return PTR_ERR(clk);
293a9770eacSAndrew Lunn 	}
294a9770eacSAndrew Lunn 
295a9770eacSAndrew Lunn 	priv->pll = clk;
296a9770eacSAndrew Lunn 
297a9770eacSAndrew Lunn 	return 0;
298a9770eacSAndrew Lunn }
299a9770eacSAndrew Lunn 
300a9770eacSAndrew Lunn static int g12a_mdio_mux_probe(struct platform_device *pdev)
301a9770eacSAndrew Lunn {
302a9770eacSAndrew Lunn 	struct device *dev = &pdev->dev;
303a9770eacSAndrew Lunn 	struct g12a_mdio_mux *priv;
304*32e54254SHeiner Kallweit 	struct clk *pclk;
305a9770eacSAndrew Lunn 	int ret;
306a9770eacSAndrew Lunn 
307a9770eacSAndrew Lunn 	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
308a9770eacSAndrew Lunn 	if (!priv)
309a9770eacSAndrew Lunn 		return -ENOMEM;
310a9770eacSAndrew Lunn 
311a9770eacSAndrew Lunn 	platform_set_drvdata(pdev, priv);
312a9770eacSAndrew Lunn 
313a9770eacSAndrew Lunn 	priv->regs = devm_platform_ioremap_resource(pdev, 0);
314a9770eacSAndrew Lunn 	if (IS_ERR(priv->regs))
315a9770eacSAndrew Lunn 		return PTR_ERR(priv->regs);
316a9770eacSAndrew Lunn 
317*32e54254SHeiner Kallweit 	pclk = devm_clk_get_enabled(dev, "pclk");
318*32e54254SHeiner Kallweit 	if (IS_ERR(pclk))
319*32e54254SHeiner Kallweit 		return dev_err_probe(dev, PTR_ERR(pclk),
320de0665c8SYang Yingliang 				     "failed to get peripheral clock\n");
321a9770eacSAndrew Lunn 
322a9770eacSAndrew Lunn 	/* Register PLL in CCF */
323a9770eacSAndrew Lunn 	ret = g12a_ephy_glue_clk_register(dev);
324a9770eacSAndrew Lunn 	if (ret)
325*32e54254SHeiner Kallweit 		return ret;
326a9770eacSAndrew Lunn 
327a9770eacSAndrew Lunn 	ret = mdio_mux_init(dev, dev->of_node, g12a_mdio_switch_fn,
328a9770eacSAndrew Lunn 			    &priv->mux_handle, dev, NULL);
329*32e54254SHeiner Kallweit 	if (ret)
330de0665c8SYang Yingliang 		dev_err_probe(dev, ret, "mdio multiplexer init failed\n");
331a9770eacSAndrew Lunn 
332a9770eacSAndrew Lunn 	return ret;
333a9770eacSAndrew Lunn }
334a9770eacSAndrew Lunn 
335a9770eacSAndrew Lunn static int g12a_mdio_mux_remove(struct platform_device *pdev)
336a9770eacSAndrew Lunn {
337a9770eacSAndrew Lunn 	struct g12a_mdio_mux *priv = platform_get_drvdata(pdev);
338a9770eacSAndrew Lunn 
339a9770eacSAndrew Lunn 	mdio_mux_uninit(priv->mux_handle);
340a9770eacSAndrew Lunn 
341a9770eacSAndrew Lunn 	if (priv->pll_is_enabled)
342a9770eacSAndrew Lunn 		clk_disable_unprepare(priv->pll);
343a9770eacSAndrew Lunn 
344a9770eacSAndrew Lunn 	return 0;
345a9770eacSAndrew Lunn }
346a9770eacSAndrew Lunn 
347a9770eacSAndrew Lunn static struct platform_driver g12a_mdio_mux_driver = {
348a9770eacSAndrew Lunn 	.probe		= g12a_mdio_mux_probe,
349a9770eacSAndrew Lunn 	.remove		= g12a_mdio_mux_remove,
350a9770eacSAndrew Lunn 	.driver		= {
351a9770eacSAndrew Lunn 		.name	= "g12a-mdio_mux",
352a9770eacSAndrew Lunn 		.of_match_table = g12a_mdio_mux_match,
353a9770eacSAndrew Lunn 	},
354a9770eacSAndrew Lunn };
355a9770eacSAndrew Lunn module_platform_driver(g12a_mdio_mux_driver);
356a9770eacSAndrew Lunn 
357a9770eacSAndrew Lunn MODULE_DESCRIPTION("Amlogic G12a MDIO multiplexer driver");
358a9770eacSAndrew Lunn MODULE_AUTHOR("Jerome Brunet <jbrunet@baylibre.com>");
359a9770eacSAndrew Lunn MODULE_LICENSE("GPL v2");
360