Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 255359
b: refs/heads/master
c: 6388b39
h: refs/heads/master
i:
  255357: be4c826
  255355: 1e44428
  255351: 7cbc909
  255343: 64c5b37
  255327: 2b75d66
  255295: 21a91ee
  255231: 76aa864
v: v3
  • Loading branch information
Marc Kleine-Budde committed Jun 6, 2011
1 parent 91ef22d commit e537bd5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 15 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 07a648e668aa7f7c94d41d8d2e4ad53b609e391d
refs/heads/master: 6388b39614208d63661607f45157e3326548eb62
69 changes: 55 additions & 14 deletions trunk/drivers/net/can/at91_can.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ enum at91_mb_mode {

enum at91_devtype {
AT91_DEVTYPE_SAM9263,
AT91_DEVTYPE_SAM9X5,
};

struct at91_devtype_data {
Expand Down Expand Up @@ -163,6 +164,12 @@ static const struct at91_devtype_data at91_devtype_data[] __devinitconst = {
.rx_last = 11,
.tx_shift = 2,
},
[AT91_DEVTYPE_SAM9X5] = {
.rx_first = 0,
.rx_split = 4,
.rx_last = 5,
.tx_shift = 1,
},
};

static struct can_bittiming_const at91_bittiming_const = {
Expand All @@ -184,6 +191,7 @@ static inline int at91_is_sam##_model(const struct at91_priv *priv) \
}

AT91_IS(9263);
AT91_IS(9X5);

static inline unsigned int get_mb_rx_first(const struct at91_priv *priv)
{
Expand Down Expand Up @@ -991,28 +999,58 @@ static void at91_irq_err_state(struct net_device *dev,
at91_write(priv, AT91_IER, reg_ier);
}

static int at91_get_state_by_bec(const struct net_device *dev,
enum can_state *state)
{
struct can_berr_counter bec;
int err;

err = at91_get_berr_counter(dev, &bec);
if (err)
return err;

if (bec.txerr < 96 && bec.rxerr < 96)
*state = CAN_STATE_ERROR_ACTIVE;
else if (bec.txerr < 128 && bec.rxerr < 128)
*state = CAN_STATE_ERROR_WARNING;
else if (bec.txerr < 256 && bec.rxerr < 256)
*state = CAN_STATE_ERROR_PASSIVE;
else
*state = CAN_STATE_BUS_OFF;

return 0;
}


static void at91_irq_err(struct net_device *dev)
{
struct at91_priv *priv = netdev_priv(dev);
struct sk_buff *skb;
struct can_frame *cf;
enum can_state new_state;
u32 reg_sr;
int err;

reg_sr = at91_read(priv, AT91_SR);

/* we need to look at the unmasked reg_sr */
if (unlikely(reg_sr & AT91_IRQ_BOFF))
new_state = CAN_STATE_BUS_OFF;
else if (unlikely(reg_sr & AT91_IRQ_ERRP))
new_state = CAN_STATE_ERROR_PASSIVE;
else if (unlikely(reg_sr & AT91_IRQ_WARN))
new_state = CAN_STATE_ERROR_WARNING;
else if (likely(reg_sr & AT91_IRQ_ERRA))
new_state = CAN_STATE_ERROR_ACTIVE;
else {
netdev_err(dev, "BUG! hardware in undefined state\n");
return;
if (at91_is_sam9263(priv)) {
reg_sr = at91_read(priv, AT91_SR);

/* we need to look at the unmasked reg_sr */
if (unlikely(reg_sr & AT91_IRQ_BOFF))
new_state = CAN_STATE_BUS_OFF;
else if (unlikely(reg_sr & AT91_IRQ_ERRP))
new_state = CAN_STATE_ERROR_PASSIVE;
else if (unlikely(reg_sr & AT91_IRQ_WARN))
new_state = CAN_STATE_ERROR_WARNING;
else if (likely(reg_sr & AT91_IRQ_ERRA))
new_state = CAN_STATE_ERROR_ACTIVE;
else {
netdev_err(dev, "BUG! hardware in undefined state\n");
return;
}
} else {
err = at91_get_state_by_bec(dev, &new_state);
if (err)
return;
}

/* state hasn't changed */
Expand Down Expand Up @@ -1329,6 +1367,9 @@ static const struct platform_device_id at91_can_id_table[] = {
{
.name = "at91_can",
.driver_data = AT91_DEVTYPE_SAM9263,
}, {
.name = "at91sam9x5_can",
.driver_data = AT91_DEVTYPE_SAM9X5,
}, {
/* sentinel */
}
Expand Down

0 comments on commit e537bd5

Please sign in to comment.