Commit 7146b2d9 authored by Andreas Larsson's avatar Andreas Larsson Committed by David S. Miller

can: sja1000: Add support for listen-only mode and one-shot mode

One-shot mode uses the TCS bit of the status register to discern
whether a transmission was successful or not. On a failed
transmission, the frame is not echoed back.
Signed-off-by: default avatarAndreas Larsson <andreas@gaisler.com>
Acked-by: default avatarWolfgang Grandegger <wg@grandegger.com>
Acked-by: default avatarOliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
parent f61bd058
...@@ -156,8 +156,13 @@ static void set_normal_mode(struct net_device *dev) ...@@ -156,8 +156,13 @@ static void set_normal_mode(struct net_device *dev)
} }
/* set chip to normal mode */ /* set chip to normal mode */
if (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY)
priv->write_reg(priv, REG_MOD, MOD_LOM);
else
priv->write_reg(priv, REG_MOD, 0x00); priv->write_reg(priv, REG_MOD, 0x00);
udelay(10); udelay(10);
status = priv->read_reg(priv, REG_MOD); status = priv->read_reg(priv, REG_MOD);
} }
...@@ -310,6 +315,9 @@ static netdev_tx_t sja1000_start_xmit(struct sk_buff *skb, ...@@ -310,6 +315,9 @@ static netdev_tx_t sja1000_start_xmit(struct sk_buff *skb,
can_put_echo_skb(skb, dev, 0); can_put_echo_skb(skb, dev, 0);
if (priv->can.ctrlmode & CAN_CTRLMODE_ONE_SHOT)
sja1000_write_cmdreg(priv, CMD_TR | CMD_AT);
else
sja1000_write_cmdreg(priv, CMD_TR); sja1000_write_cmdreg(priv, CMD_TR);
return NETDEV_TX_OK; return NETDEV_TX_OK;
...@@ -505,10 +513,18 @@ irqreturn_t sja1000_interrupt(int irq, void *dev_id) ...@@ -505,10 +513,18 @@ irqreturn_t sja1000_interrupt(int irq, void *dev_id)
netdev_warn(dev, "wakeup interrupt\n"); netdev_warn(dev, "wakeup interrupt\n");
if (isrc & IRQ_TI) { if (isrc & IRQ_TI) {
/* transmission complete interrupt */ /* transmission buffer released */
stats->tx_bytes += priv->read_reg(priv, REG_FI) & 0xf; if (priv->can.ctrlmode & CAN_CTRLMODE_ONE_SHOT &&
!(status & SR_TCS)) {
stats->tx_errors++;
can_free_echo_skb(dev, 0);
} else {
/* transmission complete */
stats->tx_bytes +=
priv->read_reg(priv, REG_FI) & 0xf;
stats->tx_packets++; stats->tx_packets++;
can_get_echo_skb(dev, 0); can_get_echo_skb(dev, 0);
}
netif_wake_queue(dev); netif_wake_queue(dev);
} }
if (isrc & IRQ_RI) { if (isrc & IRQ_RI) {
...@@ -605,7 +621,8 @@ struct net_device *alloc_sja1000dev(int sizeof_priv) ...@@ -605,7 +621,8 @@ struct net_device *alloc_sja1000dev(int sizeof_priv)
priv->can.do_set_mode = sja1000_set_mode; priv->can.do_set_mode = sja1000_set_mode;
priv->can.do_get_berr_counter = sja1000_get_berr_counter; priv->can.do_get_berr_counter = sja1000_get_berr_counter;
priv->can.ctrlmode_supported = CAN_CTRLMODE_3_SAMPLES | priv->can.ctrlmode_supported = CAN_CTRLMODE_3_SAMPLES |
CAN_CTRLMODE_BERR_REPORTING; CAN_CTRLMODE_BERR_REPORTING | CAN_CTRLMODE_LISTENONLY |
CAN_CTRLMODE_ONE_SHOT;
spin_lock_init(&priv->cmdreg_lock); spin_lock_init(&priv->cmdreg_lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment