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>
77083df59SJerome Brunet #include <linux/delay.h>
8a9770eacSAndrew Lunn #include <linux/clk.h>
9a9770eacSAndrew Lunn #include <linux/clk-provider.h>
10a9770eacSAndrew Lunn #include <linux/device.h>
11a9770eacSAndrew Lunn #include <linux/io.h>
12a9770eacSAndrew Lunn #include <linux/iopoll.h>
13a9770eacSAndrew Lunn #include <linux/mdio-mux.h>
14a9770eacSAndrew Lunn #include <linux/module.h>
15a9770eacSAndrew Lunn #include <linux/phy.h>
16a9770eacSAndrew Lunn #include <linux/platform_device.h>
17a9770eacSAndrew Lunn
18a9770eacSAndrew Lunn #define ETH_PLL_STS 0x40
19a9770eacSAndrew Lunn #define ETH_PLL_CTL0 0x44
20a9770eacSAndrew Lunn #define PLL_CTL0_LOCK_DIG BIT(30)
21a9770eacSAndrew Lunn #define PLL_CTL0_RST BIT(29)
22a9770eacSAndrew Lunn #define PLL_CTL0_EN BIT(28)
23a9770eacSAndrew Lunn #define PLL_CTL0_SEL BIT(23)
24a9770eacSAndrew Lunn #define PLL_CTL0_N GENMASK(14, 10)
25a9770eacSAndrew Lunn #define PLL_CTL0_M GENMASK(8, 0)
26a9770eacSAndrew Lunn #define PLL_LOCK_TIMEOUT 1000000
27a9770eacSAndrew Lunn #define PLL_MUX_NUM_PARENT 2
28a9770eacSAndrew Lunn #define ETH_PLL_CTL1 0x48
29a9770eacSAndrew Lunn #define ETH_PLL_CTL2 0x4c
30a9770eacSAndrew Lunn #define ETH_PLL_CTL3 0x50
31a9770eacSAndrew Lunn #define ETH_PLL_CTL4 0x54
32a9770eacSAndrew Lunn #define ETH_PLL_CTL5 0x58
33a9770eacSAndrew Lunn #define ETH_PLL_CTL6 0x5c
34a9770eacSAndrew Lunn #define ETH_PLL_CTL7 0x60
35a9770eacSAndrew Lunn
36a9770eacSAndrew Lunn #define ETH_PHY_CNTL0 0x80
37a9770eacSAndrew Lunn #define EPHY_G12A_ID 0x33010180
38a9770eacSAndrew Lunn #define ETH_PHY_CNTL1 0x84
39a9770eacSAndrew Lunn #define PHY_CNTL1_ST_MODE GENMASK(2, 0)
40a9770eacSAndrew Lunn #define PHY_CNTL1_ST_PHYADD GENMASK(7, 3)
41a9770eacSAndrew Lunn #define EPHY_DFLT_ADD 8
42a9770eacSAndrew Lunn #define PHY_CNTL1_MII_MODE GENMASK(15, 14)
43a9770eacSAndrew Lunn #define EPHY_MODE_RMII 0x1
44a9770eacSAndrew Lunn #define PHY_CNTL1_CLK_EN BIT(16)
45a9770eacSAndrew Lunn #define PHY_CNTL1_CLKFREQ BIT(17)
46a9770eacSAndrew Lunn #define PHY_CNTL1_PHY_ENB BIT(18)
47a9770eacSAndrew Lunn #define ETH_PHY_CNTL2 0x88
48a9770eacSAndrew Lunn #define PHY_CNTL2_USE_INTERNAL BIT(5)
49a9770eacSAndrew Lunn #define PHY_CNTL2_SMI_SRC_MAC BIT(6)
50a9770eacSAndrew Lunn #define PHY_CNTL2_RX_CLK_EPHY BIT(9)
51a9770eacSAndrew Lunn
52a9770eacSAndrew Lunn #define MESON_G12A_MDIO_EXTERNAL_ID 0
53a9770eacSAndrew Lunn #define MESON_G12A_MDIO_INTERNAL_ID 1
54a9770eacSAndrew Lunn
55a9770eacSAndrew Lunn struct g12a_mdio_mux {
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
g12a_ephy_pll_recalc_rate(struct clk_hw * hw,unsigned long parent_rate)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
g12a_ephy_pll_enable(struct clk_hw * hw)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
g12a_ephy_pll_disable(struct clk_hw * hw)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
g12a_ephy_pll_is_enabled(struct clk_hw * hw)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
g12a_ephy_pll_init(struct clk_hw * hw)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
g12a_enable_internal_mdio(struct g12a_mdio_mux * priv)150a9770eacSAndrew Lunn static int g12a_enable_internal_mdio(struct g12a_mdio_mux *priv)
151a9770eacSAndrew Lunn {
1527083df59SJerome Brunet u32 value;
153a9770eacSAndrew Lunn int ret;
154a9770eacSAndrew Lunn
155a9770eacSAndrew Lunn /* Enable the phy clock */
156453d9fdcSHeiner Kallweit if (!__clk_is_enabled(priv->pll)) {
157a9770eacSAndrew Lunn ret = clk_prepare_enable(priv->pll);
158a9770eacSAndrew Lunn if (ret)
159a9770eacSAndrew Lunn return ret;
160a9770eacSAndrew Lunn }
161a9770eacSAndrew Lunn
162a9770eacSAndrew Lunn /* Initialize ephy control */
163a9770eacSAndrew Lunn writel(EPHY_G12A_ID, priv->regs + ETH_PHY_CNTL0);
1647083df59SJerome Brunet
1657083df59SJerome Brunet /* Make sure we get a 0 -> 1 transition on the enable bit */
1667083df59SJerome Brunet value = FIELD_PREP(PHY_CNTL1_ST_MODE, 3) |
167a9770eacSAndrew Lunn FIELD_PREP(PHY_CNTL1_ST_PHYADD, EPHY_DFLT_ADD) |
168a9770eacSAndrew Lunn FIELD_PREP(PHY_CNTL1_MII_MODE, EPHY_MODE_RMII) |
169a9770eacSAndrew Lunn PHY_CNTL1_CLK_EN |
1707083df59SJerome Brunet PHY_CNTL1_CLKFREQ;
1717083df59SJerome Brunet writel(value, 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
1777083df59SJerome Brunet value |= PHY_CNTL1_PHY_ENB;
1787083df59SJerome Brunet writel(value, priv->regs + ETH_PHY_CNTL1);
1797083df59SJerome Brunet
1807083df59SJerome Brunet /* The phy needs a bit of time to power up */
1817083df59SJerome Brunet mdelay(10);
1827083df59SJerome Brunet
183a9770eacSAndrew Lunn return 0;
184a9770eacSAndrew Lunn }
185a9770eacSAndrew Lunn
g12a_enable_external_mdio(struct g12a_mdio_mux * priv)186a9770eacSAndrew Lunn static int g12a_enable_external_mdio(struct g12a_mdio_mux *priv)
187a9770eacSAndrew Lunn {
188a9770eacSAndrew Lunn /* Reset the mdio bus mux */
189a9770eacSAndrew Lunn writel_relaxed(0x0, priv->regs + ETH_PHY_CNTL2);
190a9770eacSAndrew Lunn
191a9770eacSAndrew Lunn /* Disable the phy clock if enabled */
192453d9fdcSHeiner Kallweit if (__clk_is_enabled(priv->pll))
193a9770eacSAndrew Lunn clk_disable_unprepare(priv->pll);
194a9770eacSAndrew Lunn
195a9770eacSAndrew Lunn return 0;
196a9770eacSAndrew Lunn }
197a9770eacSAndrew Lunn
g12a_mdio_switch_fn(int current_child,int desired_child,void * data)198a9770eacSAndrew Lunn static int g12a_mdio_switch_fn(int current_child, int desired_child,
199a9770eacSAndrew Lunn void *data)
200a9770eacSAndrew Lunn {
201a9770eacSAndrew Lunn struct g12a_mdio_mux *priv = dev_get_drvdata(data);
202a9770eacSAndrew Lunn
203a9770eacSAndrew Lunn if (current_child == desired_child)
204a9770eacSAndrew Lunn return 0;
205a9770eacSAndrew Lunn
206a9770eacSAndrew Lunn switch (desired_child) {
207a9770eacSAndrew Lunn case MESON_G12A_MDIO_EXTERNAL_ID:
208a9770eacSAndrew Lunn return g12a_enable_external_mdio(priv);
209a9770eacSAndrew Lunn case MESON_G12A_MDIO_INTERNAL_ID:
210a9770eacSAndrew Lunn return g12a_enable_internal_mdio(priv);
211a9770eacSAndrew Lunn default:
212a9770eacSAndrew Lunn return -EINVAL;
213a9770eacSAndrew Lunn }
214a9770eacSAndrew Lunn }
215a9770eacSAndrew Lunn
216a9770eacSAndrew Lunn static const struct of_device_id g12a_mdio_mux_match[] = {
217a9770eacSAndrew Lunn { .compatible = "amlogic,g12a-mdio-mux", },
218a9770eacSAndrew Lunn {},
219a9770eacSAndrew Lunn };
220a9770eacSAndrew Lunn MODULE_DEVICE_TABLE(of, g12a_mdio_mux_match);
221a9770eacSAndrew Lunn
g12a_ephy_glue_clk_register(struct device * dev)222a9770eacSAndrew Lunn static int g12a_ephy_glue_clk_register(struct device *dev)
223a9770eacSAndrew Lunn {
224a9770eacSAndrew Lunn struct g12a_mdio_mux *priv = dev_get_drvdata(dev);
225a9770eacSAndrew Lunn const char *parent_names[PLL_MUX_NUM_PARENT];
226a9770eacSAndrew Lunn struct clk_init_data init;
227a9770eacSAndrew Lunn struct g12a_ephy_pll *pll;
228a9770eacSAndrew Lunn struct clk_mux *mux;
229a9770eacSAndrew Lunn struct clk *clk;
230a9770eacSAndrew Lunn char *name;
231a9770eacSAndrew Lunn int i;
232a9770eacSAndrew Lunn
233a9770eacSAndrew Lunn /* get the mux parents */
234a9770eacSAndrew Lunn for (i = 0; i < PLL_MUX_NUM_PARENT; i++) {
235a9770eacSAndrew Lunn char in_name[8];
236a9770eacSAndrew Lunn
237a9770eacSAndrew Lunn snprintf(in_name, sizeof(in_name), "clkin%d", i);
238a9770eacSAndrew Lunn clk = devm_clk_get(dev, in_name);
239de0665c8SYang Yingliang if (IS_ERR(clk))
240de0665c8SYang Yingliang return dev_err_probe(dev, PTR_ERR(clk),
241de0665c8SYang Yingliang "Missing clock %s\n", in_name);
242a9770eacSAndrew Lunn
243a9770eacSAndrew Lunn parent_names[i] = __clk_get_name(clk);
244a9770eacSAndrew Lunn }
245a9770eacSAndrew Lunn
246a9770eacSAndrew Lunn /* create the input mux */
247a9770eacSAndrew Lunn mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL);
248a9770eacSAndrew Lunn if (!mux)
249a9770eacSAndrew Lunn return -ENOMEM;
250a9770eacSAndrew Lunn
251a9770eacSAndrew Lunn name = kasprintf(GFP_KERNEL, "%s#mux", dev_name(dev));
252a9770eacSAndrew Lunn if (!name)
253a9770eacSAndrew Lunn return -ENOMEM;
254a9770eacSAndrew Lunn
255a9770eacSAndrew Lunn init.name = name;
256a9770eacSAndrew Lunn init.ops = &clk_mux_ro_ops;
257a9770eacSAndrew Lunn init.flags = 0;
258a9770eacSAndrew Lunn init.parent_names = parent_names;
259a9770eacSAndrew Lunn init.num_parents = PLL_MUX_NUM_PARENT;
260a9770eacSAndrew Lunn
261a9770eacSAndrew Lunn mux->reg = priv->regs + ETH_PLL_CTL0;
262a9770eacSAndrew Lunn mux->shift = __ffs(PLL_CTL0_SEL);
263a9770eacSAndrew Lunn mux->mask = PLL_CTL0_SEL >> mux->shift;
264a9770eacSAndrew Lunn mux->hw.init = &init;
265a9770eacSAndrew Lunn
266a9770eacSAndrew Lunn clk = devm_clk_register(dev, &mux->hw);
267a9770eacSAndrew Lunn kfree(name);
268a9770eacSAndrew Lunn if (IS_ERR(clk)) {
269a9770eacSAndrew Lunn dev_err(dev, "failed to register input mux\n");
270a9770eacSAndrew Lunn return PTR_ERR(clk);
271a9770eacSAndrew Lunn }
272a9770eacSAndrew Lunn
273a9770eacSAndrew Lunn /* create the pll */
274a9770eacSAndrew Lunn pll = devm_kzalloc(dev, sizeof(*pll), GFP_KERNEL);
275a9770eacSAndrew Lunn if (!pll)
276a9770eacSAndrew Lunn return -ENOMEM;
277a9770eacSAndrew Lunn
278a9770eacSAndrew Lunn name = kasprintf(GFP_KERNEL, "%s#pll", dev_name(dev));
279a9770eacSAndrew Lunn if (!name)
280a9770eacSAndrew Lunn return -ENOMEM;
281a9770eacSAndrew Lunn
282a9770eacSAndrew Lunn init.name = name;
283a9770eacSAndrew Lunn init.ops = &g12a_ephy_pll_ops;
284a9770eacSAndrew Lunn init.flags = 0;
285a9770eacSAndrew Lunn parent_names[0] = __clk_get_name(clk);
286a9770eacSAndrew Lunn init.parent_names = parent_names;
287a9770eacSAndrew Lunn init.num_parents = 1;
288a9770eacSAndrew Lunn
289a9770eacSAndrew Lunn pll->base = priv->regs;
290a9770eacSAndrew Lunn pll->hw.init = &init;
291a9770eacSAndrew Lunn
292a9770eacSAndrew Lunn clk = devm_clk_register(dev, &pll->hw);
293a9770eacSAndrew Lunn kfree(name);
294a9770eacSAndrew Lunn if (IS_ERR(clk)) {
295a9770eacSAndrew Lunn dev_err(dev, "failed to register input mux\n");
296a9770eacSAndrew Lunn return PTR_ERR(clk);
297a9770eacSAndrew Lunn }
298a9770eacSAndrew Lunn
299a9770eacSAndrew Lunn priv->pll = clk;
300a9770eacSAndrew Lunn
301a9770eacSAndrew Lunn return 0;
302a9770eacSAndrew Lunn }
303a9770eacSAndrew Lunn
g12a_mdio_mux_probe(struct platform_device * pdev)304a9770eacSAndrew Lunn static int g12a_mdio_mux_probe(struct platform_device *pdev)
305a9770eacSAndrew Lunn {
306a9770eacSAndrew Lunn struct device *dev = &pdev->dev;
307a9770eacSAndrew Lunn struct g12a_mdio_mux *priv;
30832e54254SHeiner Kallweit struct clk *pclk;
309a9770eacSAndrew Lunn int ret;
310a9770eacSAndrew Lunn
311a9770eacSAndrew Lunn priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
312a9770eacSAndrew Lunn if (!priv)
313a9770eacSAndrew Lunn return -ENOMEM;
314a9770eacSAndrew Lunn
315a9770eacSAndrew Lunn platform_set_drvdata(pdev, priv);
316a9770eacSAndrew Lunn
317a9770eacSAndrew Lunn priv->regs = devm_platform_ioremap_resource(pdev, 0);
318a9770eacSAndrew Lunn if (IS_ERR(priv->regs))
319a9770eacSAndrew Lunn return PTR_ERR(priv->regs);
320a9770eacSAndrew Lunn
32132e54254SHeiner Kallweit pclk = devm_clk_get_enabled(dev, "pclk");
32232e54254SHeiner Kallweit if (IS_ERR(pclk))
32332e54254SHeiner Kallweit return dev_err_probe(dev, PTR_ERR(pclk),
324de0665c8SYang Yingliang "failed to get peripheral clock\n");
325a9770eacSAndrew Lunn
326a9770eacSAndrew Lunn /* Register PLL in CCF */
327a9770eacSAndrew Lunn ret = g12a_ephy_glue_clk_register(dev);
328a9770eacSAndrew Lunn if (ret)
32932e54254SHeiner Kallweit return ret;
330a9770eacSAndrew Lunn
331a9770eacSAndrew Lunn ret = mdio_mux_init(dev, dev->of_node, g12a_mdio_switch_fn,
332a9770eacSAndrew Lunn &priv->mux_handle, dev, NULL);
33332e54254SHeiner Kallweit if (ret)
334de0665c8SYang Yingliang dev_err_probe(dev, ret, "mdio multiplexer init failed\n");
335a9770eacSAndrew Lunn
336a9770eacSAndrew Lunn return ret;
337a9770eacSAndrew Lunn }
338a9770eacSAndrew Lunn
g12a_mdio_mux_remove(struct platform_device * pdev)339*458eb39dSUwe Kleine-König static void g12a_mdio_mux_remove(struct platform_device *pdev)
340a9770eacSAndrew Lunn {
341a9770eacSAndrew Lunn struct g12a_mdio_mux *priv = platform_get_drvdata(pdev);
342a9770eacSAndrew Lunn
343a9770eacSAndrew Lunn mdio_mux_uninit(priv->mux_handle);
344a9770eacSAndrew Lunn
345453d9fdcSHeiner Kallweit if (__clk_is_enabled(priv->pll))
346a9770eacSAndrew Lunn clk_disable_unprepare(priv->pll);
347a9770eacSAndrew Lunn }
348a9770eacSAndrew Lunn
349a9770eacSAndrew Lunn static struct platform_driver g12a_mdio_mux_driver = {
350a9770eacSAndrew Lunn .probe = g12a_mdio_mux_probe,
351*458eb39dSUwe Kleine-König .remove_new = g12a_mdio_mux_remove,
352a9770eacSAndrew Lunn .driver = {
353a9770eacSAndrew Lunn .name = "g12a-mdio_mux",
354a9770eacSAndrew Lunn .of_match_table = g12a_mdio_mux_match,
355a9770eacSAndrew Lunn },
356a9770eacSAndrew Lunn };
357a9770eacSAndrew Lunn module_platform_driver(g12a_mdio_mux_driver);
358a9770eacSAndrew Lunn
359a9770eacSAndrew Lunn MODULE_DESCRIPTION("Amlogic G12a MDIO multiplexer driver");
360a9770eacSAndrew Lunn MODULE_AUTHOR("Jerome Brunet <jbrunet@baylibre.com>");
361a9770eacSAndrew Lunn MODULE_LICENSE("GPL v2");
362