45 #include <linux/module.h>
47 #include <linux/kernel.h>
48 #include <linux/sched.h>
49 #include <linux/types.h>
50 #include <linux/fcntl.h>
52 #include <linux/ptrace.h>
53 #include <linux/string.h>
54 #include <linux/errno.h>
55 #include <linux/netdevice.h>
56 #include <linux/if_arp.h>
57 #include <linux/if_ether.h>
66 #define DRV_NAME "sja1000"
107 if (priv->
reg_base && sja1000_is_absent(priv)) {
115 static void set_reset_mode(
struct net_device *dev)
124 for (i = 0; i < 100; i++) {
136 netdev_err(dev,
"setting SJA1000 into reset mode failed!\n");
139 static void set_normal_mode(
struct net_device *dev)
145 for (i = 0; i < 100; i++) {
147 if ((status & MOD_RM) == 0) {
169 netdev_err(dev,
"setting SJA1000 into normal mode failed!\n");
172 static void sja1000_start(
struct net_device *dev)
186 set_normal_mode(dev);
199 if (netif_queue_stopped(dev))
200 netif_wake_queue(dev);
210 static int sja1000_set_bittiming(
struct net_device *dev)
216 btr0 = ((bt->
brp - 1) & 0x3f) | (((bt->
sjw - 1) & 0x3) << 6);
222 netdev_info(dev,
"setting BTR0=0x%02x BTR1=0x%02x\n", btr0, btr1);
230 static int sja1000_get_berr_counter(
const struct net_device *dev,
249 static void chipset_init(
struct net_device *dev)
287 if (can_dropped_invalid_skb(dev, skb))
290 netif_stop_queue(dev);
313 for (i = 0; i < dlc; i++)
314 priv->
write_reg(priv, dreg++, cf->data[i]);
321 sja1000_write_cmdreg(priv,
CMD_TR);
326 static void sja1000_rx(
struct net_device *dev)
363 for (i = 0; i < cf->
can_dlc; i++)
364 cf->data[i] = priv->
read_reg(priv, dreg++);
370 sja1000_write_cmdreg(priv,
CMD_RRB);
398 sja1000_write_cmdreg(priv,
CMD_CDO);
405 if (status &
SR_BS) {
409 }
else if (status &
SR_ES) {
416 priv->
can.can_stats.bus_error++;
452 netdev_dbg(dev,
"arbitration lost interrupt\n");
454 priv->
can.can_stats.arbitration_lost++;
457 cf->data[0] = alc & 0x1f;
466 priv->
can.can_stats.error_warning++;
467 cf->data[1] = (txerr > rxerr) ?
471 priv->
can.can_stats.error_passive++;
472 cf->data[1] = (txerr > rxerr) ?
509 if (status == 0xFF && sja1000_is_absent(priv))
513 netdev_warn(dev,
"wakeup interrupt\n");
528 netif_wake_queue(dev);
536 if (status == 0xFF && sja1000_is_absent(priv))
540 if (isrc & (IRQ_DOI | IRQ_EI | IRQ_BEI | IRQ_EPI | IRQ_ALI)) {
542 if (sja1000_err(dev, isrc, status))
551 netdev_dbg(dev,
"%d messages handled in ISR", n);
557 static int sja1000_open(
struct net_device *dev)
573 dev->
name, (
void *)dev);
584 netif_start_queue(dev);
589 static int sja1000_close(
struct net_device *dev)
593 netif_stop_queue(dev);
616 priv = netdev_priv(dev);
619 priv->
can.bittiming_const = &sja1000_bittiming_const;
620 priv->
can.do_set_bittiming = sja1000_set_bittiming;
621 priv->
can.do_set_mode = sja1000_set_mode;
622 priv->
can.do_get_berr_counter = sja1000_get_berr_counter;
643 .ndo_open = sja1000_open,
644 .ndo_stop = sja1000_close,
645 .ndo_start_xmit = sja1000_start_xmit,
650 if (!sja1000_probe_chip(dev))
670 static __init int sja1000_init(
void)
679 static __exit void sja1000_exit(
void)