diff options
author | Marc Kleine-Budde <mkl@pengutronix.de> | 2010-10-20 21:01:18 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2010-10-24 17:47:50 -0400 |
commit | 33a6f298c28a65fa643bc70222ebffe75077f197 (patch) | |
tree | 8035cabbb6a6252ae6d33224390a8eb52be07fed /drivers/net/can | |
parent | a9d992ecb36f8ed00130eaf41a406fda03433d23 (diff) |
can: at91_can: implement and use at91_get_berr_counter
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/can')
-rw-r--r-- | drivers/net/can/at91_can.c | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/drivers/net/can/at91_can.c b/drivers/net/can/at91_can.c index 61878135a9df..4fa0aa0e3f9c 100644 --- a/drivers/net/can/at91_can.c +++ b/drivers/net/can/at91_can.c | |||
@@ -275,6 +275,18 @@ static int at91_set_bittiming(struct net_device *dev) | |||
275 | return 0; | 275 | return 0; |
276 | } | 276 | } |
277 | 277 | ||
278 | static int at91_get_berr_counter(const struct net_device *dev, | ||
279 | struct can_berr_counter *bec) | ||
280 | { | ||
281 | const struct at91_priv *priv = netdev_priv(dev); | ||
282 | u32 reg_ecr = at91_read(priv, AT91_ECR); | ||
283 | |||
284 | bec->rxerr = reg_ecr & 0xff; | ||
285 | bec->txerr = reg_ecr >> 16; | ||
286 | |||
287 | return 0; | ||
288 | } | ||
289 | |||
278 | static void at91_chip_start(struct net_device *dev) | 290 | static void at91_chip_start(struct net_device *dev) |
279 | { | 291 | { |
280 | struct at91_priv *priv = netdev_priv(dev); | 292 | struct at91_priv *priv = netdev_priv(dev); |
@@ -764,12 +776,10 @@ static void at91_irq_err_state(struct net_device *dev, | |||
764 | struct can_frame *cf, enum can_state new_state) | 776 | struct can_frame *cf, enum can_state new_state) |
765 | { | 777 | { |
766 | struct at91_priv *priv = netdev_priv(dev); | 778 | struct at91_priv *priv = netdev_priv(dev); |
767 | u32 reg_idr = 0, reg_ier = 0, reg_ecr; | 779 | u32 reg_idr = 0, reg_ier = 0; |
768 | u8 tec, rec; | 780 | struct can_berr_counter bec; |
769 | 781 | ||
770 | reg_ecr = at91_read(priv, AT91_ECR); | 782 | at91_get_berr_counter(dev, &bec); |
771 | rec = reg_ecr & 0xff; | ||
772 | tec = reg_ecr >> 16; | ||
773 | 783 | ||
774 | switch (priv->can.state) { | 784 | switch (priv->can.state) { |
775 | case CAN_STATE_ERROR_ACTIVE: | 785 | case CAN_STATE_ERROR_ACTIVE: |
@@ -784,7 +794,7 @@ static void at91_irq_err_state(struct net_device *dev, | |||
784 | priv->can.can_stats.error_warning++; | 794 | priv->can.can_stats.error_warning++; |
785 | 795 | ||
786 | cf->can_id |= CAN_ERR_CRTL; | 796 | cf->can_id |= CAN_ERR_CRTL; |
787 | cf->data[1] = (tec > rec) ? | 797 | cf->data[1] = (bec.txerr > bec.rxerr) ? |
788 | CAN_ERR_CRTL_TX_WARNING : | 798 | CAN_ERR_CRTL_TX_WARNING : |
789 | CAN_ERR_CRTL_RX_WARNING; | 799 | CAN_ERR_CRTL_RX_WARNING; |
790 | } | 800 | } |
@@ -800,7 +810,7 @@ static void at91_irq_err_state(struct net_device *dev, | |||
800 | priv->can.can_stats.error_passive++; | 810 | priv->can.can_stats.error_passive++; |
801 | 811 | ||
802 | cf->can_id |= CAN_ERR_CRTL; | 812 | cf->can_id |= CAN_ERR_CRTL; |
803 | cf->data[1] = (tec > rec) ? | 813 | cf->data[1] = (bec.txerr > bec.rxerr) ? |
804 | CAN_ERR_CRTL_TX_PASSIVE : | 814 | CAN_ERR_CRTL_TX_PASSIVE : |
805 | CAN_ERR_CRTL_RX_PASSIVE; | 815 | CAN_ERR_CRTL_RX_PASSIVE; |
806 | } | 816 | } |
@@ -1078,6 +1088,7 @@ static int __devinit at91_can_probe(struct platform_device *pdev) | |||
1078 | priv->can.bittiming_const = &at91_bittiming_const; | 1088 | priv->can.bittiming_const = &at91_bittiming_const; |
1079 | priv->can.do_set_bittiming = at91_set_bittiming; | 1089 | priv->can.do_set_bittiming = at91_set_bittiming; |
1080 | priv->can.do_set_mode = at91_set_mode; | 1090 | priv->can.do_set_mode = at91_set_mode; |
1091 | priv->can.do_get_berr_counter = at91_get_berr_counter; | ||
1081 | priv->can.ctrlmode_supported = CAN_CTRLMODE_3_SAMPLES; | 1092 | priv->can.ctrlmode_supported = CAN_CTRLMODE_3_SAMPLES; |
1082 | priv->reg_base = addr; | 1093 | priv->reg_base = addr; |
1083 | priv->dev = dev; | 1094 | priv->dev = dev; |