11 #include <linux/module.h>
13 #include <linux/kernel.h>
14 #include <linux/bitops.h>
16 #include <linux/errno.h>
17 #include <linux/netdevice.h>
27 #define DRV_NAME "bfin_can"
28 #define BFIN_CAN_TIMEOUT 100
29 #define TX_ECHO_SKB_MAX 1
85 netdev_info(dev,
"setting CLOCK=0x%04x TIMING=0x%04x\n", clk, timing);
90 static void bfin_can_set_reset_mode(
struct net_device *dev)
109 if (--timeout == 0) {
110 netdev_err(dev,
"fail to enter configuration mode\n");
128 for (i = 0; i < 2; i++) {
137 for (i = 0; i < 2; i++) {
152 static void bfin_can_set_normal_mode(
struct net_device *dev)
165 if (--timeout == 0) {
166 netdev_err(dev,
"fail to leave configuration mode\n");
196 static void bfin_can_start(
struct net_device *dev)
202 bfin_can_set_reset_mode(dev);
205 bfin_can_set_normal_mode(dev);
213 if (netif_queue_stopped(dev))
214 netif_wake_queue(dev);
224 static int bfin_can_get_berr_counter(
const struct net_device *dev,
232 bec->
txerr = cec >> 8;
249 if (can_dropped_invalid_skb(dev, skb))
252 netif_stop_queue(dev);
257 val = ((
id & 0x1FFF0000) >> 16) |
IDE;
265 for (i = 0; i < 8; i += 2) {
266 val = ((7 -
i) < dlc ? (
data[7 - i]) : 0) +
267 ((6 - i) < dlc ? (
data[6 -
i] << 8) : 0);
312 cf->
can_id |= CAN_RTR_FLAG;
318 for (i = 0; i < 8; i += 2) {
320 cf->data[7 -
i] = (7 -
i) < cf->
can_dlc ? val : 0;
321 cf->data[6 - i] = (6 - i) < cf->
can_dlc ? (val >> 8) : 0;
366 netdev_dbg(dev,
"Error Warning Transmit/Receive Interrupt\n");
378 priv->
can.can_stats.error_warning++;
379 cf->data[1] = (txerr > rxerr) ?
383 priv->
can.can_stats.error_passive++;
384 cf->data[1] = (txerr > rxerr) ?
391 priv->
can.can_stats.bus_error++;
397 else if (status &
FER)
399 else if (status &
SER)
429 netif_wake_queue(dev);
434 bfin_can_rx(dev, isrc);
440 bfin_can_err(dev, isrc, status);
448 static int bfin_can_open(
struct net_device *dev)
454 bfin_can_set_reset_mode(dev);
471 "bfin-can-err", dev);
477 netif_start_queue(dev);
491 static int bfin_can_close(
struct net_device *dev)
495 netif_stop_queue(dev);
496 bfin_can_set_reset_mode(dev);
516 priv = netdev_priv(dev);
519 priv->
can.bittiming_const = &bfin_can_bittiming_const;
520 priv->
can.do_set_bittiming = bfin_can_set_bittiming;
521 priv->
can.do_set_mode = bfin_can_set_mode;
522 priv->
can.do_get_berr_counter = bfin_can_get_berr_counter;
529 .ndo_open = bfin_can_open,
530 .ndo_stop = bfin_can_close,
531 .ndo_start_xmit = bfin_can_start_xmit,
539 struct resource *res_mem, *rx_irq, *tx_irq, *err_irq;
540 unsigned short *
pdata;
542 pdata = pdev->
dev.platform_data;
544 dev_err(&pdev->
dev,
"No platform data provided!\n");
553 if (!res_mem || !rx_irq || !tx_irq || !err_irq) {
559 dev_name(&pdev->
dev))) {
567 goto exit_mem_release;
572 goto exit_peri_pin_free;
575 priv = netdev_priv(dev);
589 bfin_can_set_reset_mode(dev);
593 dev_err(&pdev->
dev,
"registering failed (err=%d)\n", err);
594 goto exit_candev_free;
598 "%s device registered"
599 "(®_base=%p, rx_irq=%d, tx_irq=%d, err_irq=%d, sclk=%d)\n",
620 bfin_can_set_reset_mode(dev);
643 if (netif_running(dev)) {
649 if (--timeout == 0) {
650 netdev_err(dev,
"fail to enter sleep mode\n");
665 if (netif_running(dev)) {
674 #define bfin_can_suspend NULL
675 #define bfin_can_resume NULL
679 .probe = bfin_can_probe,