Lines Matching +full:src +full:- +full:ref +full:- +full:clk +full:- +full:mhz
1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2004-2005 Andrey Volkov <avolkov@varma-el.com>,
7 * Copyright (C) 2008-2009 Wolfgang Grandegger <wg@grandegger.com>
23 #include <linux/clk.h>
40 { .compatible = "fsl,mpc5200-cdm", },
68 freq = mpc5xxx_get_bus_frequency(&ofdev->dev); in mpc52xx_can_get_clock()
78 dev_err(&ofdev->dev, "can't get clock node!\n"); in mpc52xx_can_get_clock()
84 dev_err(&ofdev->dev, "can't map clock node!\n"); in mpc52xx_can_get_clock()
88 if (in_8(&cdm->ipb_clk_sel) & 0x1) in mpc52xx_can_get_clock()
90 val = in_be32(&cdm->rstcfg); in mpc52xx_can_get_clock()
120 struct clk *clk_in, *clk_can; in mpc512x_can_get_clock()
123 struct clk *clk_ipg; in mpc512x_can_get_clock()
128 np = ofdev->dev.of_node; in mpc512x_can_get_clock()
130 of_property_read_u32(np, "fsl,mscan-clock-divider", &clockdiv); in mpc512x_can_get_clock()
131 dev_dbg(&ofdev->dev, "device tree specs: clk src[%s] div[%d]\n", in mpc512x_can_get_clock()
134 /* when clock-source is 'ip', the CANCTL1[CLKSRC] bit needs to in mpc512x_can_get_clock()
138 * for clock-source values of 'ref' or 'sys' the CANCTL1[CLKSRC] in mpc512x_can_get_clock()
139 * bit needs to get cleared, an optional clock-divider may have in mpc512x_can_get_clock()
143 * in the absence of a clock-source spec, first an optimal clock in mpc512x_can_get_clock()
145 * 'ref' clock is used in mpc512x_can_get_clock()
154 else if (!strcmp(clock_source, "ref")) in mpc512x_can_get_clock()
158 dev_dbg(&ofdev->dev, "got a clk source spec[%d]\n", clk_from); in mpc512x_can_get_clock()
162 * next MHz and see if we can get a multiple of 16MHz in mpc512x_can_get_clock()
164 dev_dbg(&ofdev->dev, "no clk source spec, trying SYS\n"); in mpc512x_can_get_clock()
165 clk_in = devm_clk_get(&ofdev->dev, "sys"); in mpc512x_can_get_clock()
175 dev_dbg(&ofdev->dev, in mpc512x_can_get_clock()
176 "clk fit, sys[%lu] div[%d] freq[%lu]\n", in mpc512x_can_get_clock()
181 /* no spec so far, use the 'ref' clock */ in mpc512x_can_get_clock()
182 dev_dbg(&ofdev->dev, "no clk source spec, trying REF\n"); in mpc512x_can_get_clock()
183 clk_in = devm_clk_get(&ofdev->dev, "ref"); in mpc512x_can_get_clock()
188 dev_dbg(&ofdev->dev, in mpc512x_can_get_clock()
189 "clk fit, ref[%lu] (no div) freq[%lu]\n", in mpc512x_can_get_clock()
200 clk_can = devm_clk_get(&ofdev->dev, "ips"); in mpc512x_can_get_clock()
203 priv = netdev_priv(dev_get_drvdata(&ofdev->dev)); in mpc512x_can_get_clock()
204 priv->clk_can = clk_can; in mpc512x_can_get_clock()
207 dev_dbg(&ofdev->dev, "clk from IPS, clksrc[%d] freq[%lu]\n", in mpc512x_can_get_clock()
212 clk_can = devm_clk_get(&ofdev->dev, "mclk"); in mpc512x_can_get_clock()
215 priv = netdev_priv(dev_get_drvdata(&ofdev->dev)); in mpc512x_can_get_clock()
216 priv->clk_can = clk_can; in mpc512x_can_get_clock()
218 clk_in = devm_clk_get(&ofdev->dev, "sys"); in mpc512x_can_get_clock()
220 clk_in = devm_clk_get(&ofdev->dev, "ref"); in mpc512x_can_get_clock()
229 dev_dbg(&ofdev->dev, "clk from MCLK, clksrc[%d] freq[%lu]\n", in mpc512x_can_get_clock()
239 clk_ipg = devm_clk_get(&ofdev->dev, "ipg"); in mpc512x_can_get_clock()
244 priv = netdev_priv(dev_get_drvdata(&ofdev->dev)); in mpc512x_can_get_clock()
245 priv->clk_ipg = clk_ipg; in mpc512x_can_get_clock()
251 dev_err(&ofdev->dev, "invalid clock source specification\n"); in mpc512x_can_get_clock()
256 dev_err(&ofdev->dev, "cannot acquire or setup bitrate clock source\n"); in mpc512x_can_get_clock()
261 dev_err(&ofdev->dev, "cannot acquire or setup register clock\n"); in mpc512x_can_get_clock()
270 priv = netdev_priv(dev_get_drvdata(&ofdev->dev)); in mpc512x_can_put_clock()
271 if (priv->clk_ipg) in mpc512x_can_put_clock()
272 clk_disable_unprepare(priv->clk_ipg); in mpc512x_can_put_clock()
287 struct device_node *np = ofdev->dev.of_node; in mpc5xxx_can_probe()
293 int err = -ENOMEM; in mpc5xxx_can_probe()
295 data = device_get_match_data(&ofdev->dev); in mpc5xxx_can_probe()
297 return -EINVAL; in mpc5xxx_can_probe()
301 return dev_err_probe(&ofdev->dev, err, "couldn't ioremap\n"); in mpc5xxx_can_probe()
305 dev_err(&ofdev->dev, "no irq found\n"); in mpc5xxx_can_probe()
306 err = -ENODEV; in mpc5xxx_can_probe()
314 SET_NETDEV_DEV(dev, &ofdev->dev); in mpc5xxx_can_probe()
317 priv->reg_base = base; in mpc5xxx_can_probe()
318 dev->irq = irq; in mpc5xxx_can_probe()
320 clock_name = of_get_property(np, "fsl,mscan-clock-source", NULL); in mpc5xxx_can_probe()
322 priv->type = data->type; in mpc5xxx_can_probe()
323 priv->can.clock.freq = data->get_clock(ofdev, clock_name, in mpc5xxx_can_probe()
325 if (!priv->can.clock.freq) { in mpc5xxx_can_probe()
326 dev_err(&ofdev->dev, "couldn't get MSCAN clock properties\n"); in mpc5xxx_can_probe()
332 dev_err(&ofdev->dev, "registering %s failed (err=%d)\n", in mpc5xxx_can_probe()
337 dev_info(&ofdev->dev, "MSCAN at 0x%p, irq %d, clock %d Hz\n", in mpc5xxx_can_probe()
338 priv->reg_base, dev->irq, priv->can.clock.freq); in mpc5xxx_can_probe()
343 if (data->put_clock) in mpc5xxx_can_probe()
344 data->put_clock(ofdev); in mpc5xxx_can_probe()
360 data = device_get_match_data(&ofdev->dev); in mpc5xxx_can_remove()
363 if (data && data->put_clock) in mpc5xxx_can_remove()
364 data->put_clock(ofdev); in mpc5xxx_can_remove()
365 iounmap(priv->reg_base); in mpc5xxx_can_remove()
366 irq_dispose_mapping(dev->irq); in mpc5xxx_can_remove()
376 struct mscan_regs *regs = (struct mscan_regs *)priv->reg_base; in mpc5xxx_can_suspend()
387 struct mscan_regs *regs = (struct mscan_regs *)priv->reg_base; in mpc5xxx_can_resume()
389 regs->canctl0 |= MSCAN_INITRQ; in mpc5xxx_can_resume()
390 while (!(regs->canctl1 & MSCAN_INITAK)) in mpc5xxx_can_resume()
393 regs->canctl1 = saved_regs.canctl1; in mpc5xxx_can_resume()
394 regs->canbtr0 = saved_regs.canbtr0; in mpc5xxx_can_resume()
395 regs->canbtr1 = saved_regs.canbtr1; in mpc5xxx_can_resume()
396 regs->canidac = saved_regs.canidac; in mpc5xxx_can_resume()
399 _memcpy_toio(®s->canidar1_0, (void *)&saved_regs.canidar1_0, in mpc5xxx_can_resume()
400 sizeof(*regs) - offsetof(struct mscan_regs, canidar1_0)); in mpc5xxx_can_resume()
402 regs->canctl0 &= ~MSCAN_INITRQ; in mpc5xxx_can_resume()
403 regs->cantbsel = saved_regs.cantbsel; in mpc5xxx_can_resume()
404 regs->canrier = saved_regs.canrier; in mpc5xxx_can_resume()
405 regs->cantier = saved_regs.cantier; in mpc5xxx_can_resume()
406 regs->canctl0 = saved_regs.canctl0; in mpc5xxx_can_resume()
425 { .compatible = "fsl,mpc5200-mscan", .data = &mpc5200_can_data, },
427 { .compatible = "fsl,mpc5121-mscan", .data = &mpc5121_can_data, },