23 #include <linux/kernel.h>
24 #include <linux/module.h>
27 #include <linux/netdevice.h>
37 #define DRV_NAME "mpc5xxx_can"
45 #ifdef CONFIG_PPC_MPC52xx
47 { .compatible =
"fsl,mpc5200-cdm", },
52 const char *clock_name,
71 if (clock_name &&
strcmp(clock_name,
"ip") == 0)
86 dev_err(&ofdev->
dev,
"can't get clock node!\n");
95 freq *= (val & (1 << 5)) ? 8 : 4;
96 freq /= (val & (1 << 6)) ? 12 : 16;
105 const char *clock_name,
112 #ifdef CONFIG_PPC_MPC512x
128 { .compatible =
"fsl,mpc5121-clock", },
133 const char *clock_name,
139 int plen, clockidx, clocksrc = -1;
140 u32 sys_freq,
val, clockdiv = 1, freq = 0;
145 dev_err(&ofdev->
dev,
"couldn't find clock node\n");
150 dev_err(&ofdev->
dev,
"couldn't map clock registers\n");
156 BUG_ON(!pval || plen <
sizeof(*pval));
157 clockidx = (*pval & 0x80) ? 1 : 0;
169 if (clock_name && !
strcmp(clock_name,
"ip")) {
170 *mscan_clksrc = MSCAN_CLKSRC_IPS;
176 "fsl,mscan-clock-divider", &plen);
177 if (pval && plen ==
sizeof(*pval))
182 if (!clock_name || !
strcmp(clock_name,
"sys")) {
184 if (IS_ERR(sys_clk)) {
185 dev_err(&ofdev->
dev,
"couldn't get sys_clk\n");
194 if ((sys_freq % 16000000) == 0) {
196 clockdiv = sys_freq / 16000000;
197 freq = sys_freq / clockdiv;
201 freq = sys_freq / clockdiv;
207 if (IS_ERR(ref_clk)) {
208 dev_err(&ofdev->
dev,
"couldn't get ref_clk\n");
217 out_be32(&clockctl->mccr[clockidx], 0x0);
220 val = (clocksrc << 14) | ((clockdiv - 1) << 17);
221 out_be32(&clockctl->mccr[clockidx], val);
223 out_be32(&clockctl->mccr[clockidx], val | 0x10000);
228 if (!(val & (1 << 25)))
231 dev_dbg(&ofdev->
dev,
"using '%s' with frequency divider %d\n",
232 *mscan_clksrc == MSCAN_CLKSRC_IPS ?
"ips_clk" :
233 clocksrc == 1 ?
"ref_clk" :
"sys_clk", clockdiv);
238 of_node_put(np_clock);
243 const char *clock_name,
259 const char *clock_name =
NULL;
260 int irq, mscan_clksrc = 0;
283 goto exit_dispose_irq;
285 priv = netdev_priv(dev);
293 priv->
can.clock.freq = data->
get_clock(ofdev, clock_name,
295 if (!priv->
can.clock.freq) {
296 dev_err(&ofdev->
dev,
"couldn't get MSCAN clock properties\n");
297 goto exit_free_mscan;
304 dev_err(&ofdev->
dev,
"registering %s failed (err=%d)\n",
306 goto exit_free_mscan;
311 dev_info(&ofdev->
dev,
"MSCAN at 0x%p, irq %d, clock %d Hz\n",
385 .get_clock = mpc52xx_can_get_clock,
390 .get_clock = mpc512x_can_get_clock,
394 { .compatible =
"fsl,mpc5200-mscan", .data = &mpc5200_can_data, },
396 { .compatible =
"fsl,mpc5121-mscan", .data = &mpc5121_can_data, },
402 .name =
"mpc5xxx_can",
404 .of_match_table = mpc5xxx_can_table,
406 .probe = mpc5xxx_can_probe,
409 .suspend = mpc5xxx_can_suspend,
410 .resume = mpc5xxx_can_resume,