aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/can/sja1000/sja1000.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/can/sja1000/sja1000.c')
-rw-r--r--drivers/net/can/sja1000/sja1000.c108
1 files changed, 54 insertions, 54 deletions
diff --git a/drivers/net/can/sja1000/sja1000.c b/drivers/net/can/sja1000/sja1000.c
index b689964f182c..571f133a8fec 100644
--- a/drivers/net/can/sja1000/sja1000.c
+++ b/drivers/net/can/sja1000/sja1000.c
@@ -89,7 +89,7 @@ static int sja1000_probe_chip(struct net_device *dev)
89{ 89{
90 struct sja1000_priv *priv = netdev_priv(dev); 90 struct sja1000_priv *priv = netdev_priv(dev);
91 91
92 if (dev->base_addr && (priv->read_reg(dev, 0) == 0xFF)) { 92 if (priv->reg_base && (priv->read_reg(priv, 0) == 0xFF)) {
93 printk(KERN_INFO "%s: probing @0x%lX failed\n", 93 printk(KERN_INFO "%s: probing @0x%lX failed\n",
94 DRV_NAME, dev->base_addr); 94 DRV_NAME, dev->base_addr);
95 return 0; 95 return 0;
@@ -100,11 +100,11 @@ static int sja1000_probe_chip(struct net_device *dev)
100static void set_reset_mode(struct net_device *dev) 100static void set_reset_mode(struct net_device *dev)
101{ 101{
102 struct sja1000_priv *priv = netdev_priv(dev); 102 struct sja1000_priv *priv = netdev_priv(dev);
103 unsigned char status = priv->read_reg(dev, REG_MOD); 103 unsigned char status = priv->read_reg(priv, REG_MOD);
104 int i; 104 int i;
105 105
106 /* disable interrupts */ 106 /* disable interrupts */
107 priv->write_reg(dev, REG_IER, IRQ_OFF); 107 priv->write_reg(priv, REG_IER, IRQ_OFF);
108 108
109 for (i = 0; i < 100; i++) { 109 for (i = 0; i < 100; i++) {
110 /* check reset bit */ 110 /* check reset bit */
@@ -113,9 +113,9 @@ static void set_reset_mode(struct net_device *dev)
113 return; 113 return;
114 } 114 }
115 115
116 priv->write_reg(dev, REG_MOD, MOD_RM); /* reset chip */ 116 priv->write_reg(priv, REG_MOD, MOD_RM); /* reset chip */
117 udelay(10); 117 udelay(10);
118 status = priv->read_reg(dev, REG_MOD); 118 status = priv->read_reg(priv, REG_MOD);
119 } 119 }
120 120
121 dev_err(dev->dev.parent, "setting SJA1000 into reset mode failed!\n"); 121 dev_err(dev->dev.parent, "setting SJA1000 into reset mode failed!\n");
@@ -124,7 +124,7 @@ static void set_reset_mode(struct net_device *dev)
124static void set_normal_mode(struct net_device *dev) 124static void set_normal_mode(struct net_device *dev)
125{ 125{
126 struct sja1000_priv *priv = netdev_priv(dev); 126 struct sja1000_priv *priv = netdev_priv(dev);
127 unsigned char status = priv->read_reg(dev, REG_MOD); 127 unsigned char status = priv->read_reg(priv, REG_MOD);
128 int i; 128 int i;
129 129
130 for (i = 0; i < 100; i++) { 130 for (i = 0; i < 100; i++) {
@@ -132,14 +132,14 @@ static void set_normal_mode(struct net_device *dev)
132 if ((status & MOD_RM) == 0) { 132 if ((status & MOD_RM) == 0) {
133 priv->can.state = CAN_STATE_ERROR_ACTIVE; 133 priv->can.state = CAN_STATE_ERROR_ACTIVE;
134 /* enable all interrupts */ 134 /* enable all interrupts */
135 priv->write_reg(dev, REG_IER, IRQ_ALL); 135 priv->write_reg(priv, REG_IER, IRQ_ALL);
136 return; 136 return;
137 } 137 }
138 138
139 /* set chip to normal mode */ 139 /* set chip to normal mode */
140 priv->write_reg(dev, REG_MOD, 0x00); 140 priv->write_reg(priv, REG_MOD, 0x00);
141 udelay(10); 141 udelay(10);
142 status = priv->read_reg(dev, REG_MOD); 142 status = priv->read_reg(priv, REG_MOD);
143 } 143 }
144 144
145 dev_err(dev->dev.parent, "setting SJA1000 into normal mode failed!\n"); 145 dev_err(dev->dev.parent, "setting SJA1000 into normal mode failed!\n");
@@ -154,9 +154,9 @@ static void sja1000_start(struct net_device *dev)
154 set_reset_mode(dev); 154 set_reset_mode(dev);
155 155
156 /* Clear error counters and error code capture */ 156 /* Clear error counters and error code capture */
157 priv->write_reg(dev, REG_TXERR, 0x0); 157 priv->write_reg(priv, REG_TXERR, 0x0);
158 priv->write_reg(dev, REG_RXERR, 0x0); 158 priv->write_reg(priv, REG_RXERR, 0x0);
159 priv->read_reg(dev, REG_ECC); 159 priv->read_reg(priv, REG_ECC);
160 160
161 /* leave reset mode */ 161 /* leave reset mode */
162 set_normal_mode(dev); 162 set_normal_mode(dev);
@@ -198,8 +198,8 @@ static int sja1000_set_bittiming(struct net_device *dev)
198 dev_info(dev->dev.parent, 198 dev_info(dev->dev.parent,
199 "setting BTR0=0x%02x BTR1=0x%02x\n", btr0, btr1); 199 "setting BTR0=0x%02x BTR1=0x%02x\n", btr0, btr1);
200 200
201 priv->write_reg(dev, REG_BTR0, btr0); 201 priv->write_reg(priv, REG_BTR0, btr0);
202 priv->write_reg(dev, REG_BTR1, btr1); 202 priv->write_reg(priv, REG_BTR1, btr1);
203 203
204 return 0; 204 return 0;
205} 205}
@@ -217,20 +217,20 @@ static void chipset_init(struct net_device *dev)
217 struct sja1000_priv *priv = netdev_priv(dev); 217 struct sja1000_priv *priv = netdev_priv(dev);
218 218
219 /* set clock divider and output control register */ 219 /* set clock divider and output control register */
220 priv->write_reg(dev, REG_CDR, priv->cdr | CDR_PELICAN); 220 priv->write_reg(priv, REG_CDR, priv->cdr | CDR_PELICAN);
221 221
222 /* set acceptance filter (accept all) */ 222 /* set acceptance filter (accept all) */
223 priv->write_reg(dev, REG_ACCC0, 0x00); 223 priv->write_reg(priv, REG_ACCC0, 0x00);
224 priv->write_reg(dev, REG_ACCC1, 0x00); 224 priv->write_reg(priv, REG_ACCC1, 0x00);
225 priv->write_reg(dev, REG_ACCC2, 0x00); 225 priv->write_reg(priv, REG_ACCC2, 0x00);
226 priv->write_reg(dev, REG_ACCC3, 0x00); 226 priv->write_reg(priv, REG_ACCC3, 0x00);
227 227
228 priv->write_reg(dev, REG_ACCM0, 0xFF); 228 priv->write_reg(priv, REG_ACCM0, 0xFF);
229 priv->write_reg(dev, REG_ACCM1, 0xFF); 229 priv->write_reg(priv, REG_ACCM1, 0xFF);
230 priv->write_reg(dev, REG_ACCM2, 0xFF); 230 priv->write_reg(priv, REG_ACCM2, 0xFF);
231 priv->write_reg(dev, REG_ACCM3, 0xFF); 231 priv->write_reg(priv, REG_ACCM3, 0xFF);
232 232
233 priv->write_reg(dev, REG_OCR, priv->ocr | OCR_MODE_NORMAL); 233 priv->write_reg(priv, REG_OCR, priv->ocr | OCR_MODE_NORMAL);
234} 234}
235 235
236/* 236/*
@@ -261,27 +261,27 @@ static int sja1000_start_xmit(struct sk_buff *skb, struct net_device *dev)
261 if (id & CAN_EFF_FLAG) { 261 if (id & CAN_EFF_FLAG) {
262 fi |= FI_FF; 262 fi |= FI_FF;
263 dreg = EFF_BUF; 263 dreg = EFF_BUF;
264 priv->write_reg(dev, REG_FI, fi); 264 priv->write_reg(priv, REG_FI, fi);
265 priv->write_reg(dev, REG_ID1, (id & 0x1fe00000) >> (5 + 16)); 265 priv->write_reg(priv, REG_ID1, (id & 0x1fe00000) >> (5 + 16));
266 priv->write_reg(dev, REG_ID2, (id & 0x001fe000) >> (5 + 8)); 266 priv->write_reg(priv, REG_ID2, (id & 0x001fe000) >> (5 + 8));
267 priv->write_reg(dev, REG_ID3, (id & 0x00001fe0) >> 5); 267 priv->write_reg(priv, REG_ID3, (id & 0x00001fe0) >> 5);
268 priv->write_reg(dev, REG_ID4, (id & 0x0000001f) << 3); 268 priv->write_reg(priv, REG_ID4, (id & 0x0000001f) << 3);
269 } else { 269 } else {
270 dreg = SFF_BUF; 270 dreg = SFF_BUF;
271 priv->write_reg(dev, REG_FI, fi); 271 priv->write_reg(priv, REG_FI, fi);
272 priv->write_reg(dev, REG_ID1, (id & 0x000007f8) >> 3); 272 priv->write_reg(priv, REG_ID1, (id & 0x000007f8) >> 3);
273 priv->write_reg(dev, REG_ID2, (id & 0x00000007) << 5); 273 priv->write_reg(priv, REG_ID2, (id & 0x00000007) << 5);
274 } 274 }
275 275
276 for (i = 0; i < dlc; i++) 276 for (i = 0; i < dlc; i++)
277 priv->write_reg(dev, dreg++, cf->data[i]); 277 priv->write_reg(priv, dreg++, cf->data[i]);
278 278
279 stats->tx_bytes += dlc; 279 stats->tx_bytes += dlc;
280 dev->trans_start = jiffies; 280 dev->trans_start = jiffies;
281 281
282 can_put_echo_skb(skb, dev, 0); 282 can_put_echo_skb(skb, dev, 0);
283 283
284 priv->write_reg(dev, REG_CMR, CMD_TR); 284 priv->write_reg(priv, REG_CMR, CMD_TR);
285 285
286 return 0; 286 return 0;
287} 287}
@@ -304,22 +304,22 @@ static void sja1000_rx(struct net_device *dev)
304 skb->dev = dev; 304 skb->dev = dev;
305 skb->protocol = htons(ETH_P_CAN); 305 skb->protocol = htons(ETH_P_CAN);
306 306
307 fi = priv->read_reg(dev, REG_FI); 307 fi = priv->read_reg(priv, REG_FI);
308 dlc = fi & 0x0F; 308 dlc = fi & 0x0F;
309 309
310 if (fi & FI_FF) { 310 if (fi & FI_FF) {
311 /* extended frame format (EFF) */ 311 /* extended frame format (EFF) */
312 dreg = EFF_BUF; 312 dreg = EFF_BUF;
313 id = (priv->read_reg(dev, REG_ID1) << (5 + 16)) 313 id = (priv->read_reg(priv, REG_ID1) << (5 + 16))
314 | (priv->read_reg(dev, REG_ID2) << (5 + 8)) 314 | (priv->read_reg(priv, REG_ID2) << (5 + 8))
315 | (priv->read_reg(dev, REG_ID3) << 5) 315 | (priv->read_reg(priv, REG_ID3) << 5)
316 | (priv->read_reg(dev, REG_ID4) >> 3); 316 | (priv->read_reg(priv, REG_ID4) >> 3);
317 id |= CAN_EFF_FLAG; 317 id |= CAN_EFF_FLAG;
318 } else { 318 } else {
319 /* standard frame format (SFF) */ 319 /* standard frame format (SFF) */
320 dreg = SFF_BUF; 320 dreg = SFF_BUF;
321 id = (priv->read_reg(dev, REG_ID1) << 3) 321 id = (priv->read_reg(priv, REG_ID1) << 3)
322 | (priv->read_reg(dev, REG_ID2) >> 5); 322 | (priv->read_reg(priv, REG_ID2) >> 5);
323 } 323 }
324 324
325 if (fi & FI_RTR) 325 if (fi & FI_RTR)
@@ -330,13 +330,13 @@ static void sja1000_rx(struct net_device *dev)
330 cf->can_id = id; 330 cf->can_id = id;
331 cf->can_dlc = dlc; 331 cf->can_dlc = dlc;
332 for (i = 0; i < dlc; i++) 332 for (i = 0; i < dlc; i++)
333 cf->data[i] = priv->read_reg(dev, dreg++); 333 cf->data[i] = priv->read_reg(priv, dreg++);
334 334
335 while (i < 8) 335 while (i < 8)
336 cf->data[i++] = 0; 336 cf->data[i++] = 0;
337 337
338 /* release receive buffer */ 338 /* release receive buffer */
339 priv->write_reg(dev, REG_CMR, CMD_RRB); 339 priv->write_reg(priv, REG_CMR, CMD_RRB);
340 340
341 netif_rx(skb); 341 netif_rx(skb);
342 342
@@ -371,7 +371,7 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status)
371 cf->data[1] = CAN_ERR_CRTL_RX_OVERFLOW; 371 cf->data[1] = CAN_ERR_CRTL_RX_OVERFLOW;
372 stats->rx_over_errors++; 372 stats->rx_over_errors++;
373 stats->rx_errors++; 373 stats->rx_errors++;
374 priv->write_reg(dev, REG_CMR, CMD_CDO); /* clear bit */ 374 priv->write_reg(priv, REG_CMR, CMD_CDO); /* clear bit */
375 } 375 }
376 376
377 if (isrc & IRQ_EI) { 377 if (isrc & IRQ_EI) {
@@ -392,7 +392,7 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status)
392 priv->can.can_stats.bus_error++; 392 priv->can.can_stats.bus_error++;
393 stats->rx_errors++; 393 stats->rx_errors++;
394 394
395 ecc = priv->read_reg(dev, REG_ECC); 395 ecc = priv->read_reg(priv, REG_ECC);
396 396
397 cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR; 397 cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR;
398 398
@@ -426,7 +426,7 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status)
426 if (isrc & IRQ_ALI) { 426 if (isrc & IRQ_ALI) {
427 /* arbitration lost interrupt */ 427 /* arbitration lost interrupt */
428 dev_dbg(dev->dev.parent, "arbitration lost interrupt\n"); 428 dev_dbg(dev->dev.parent, "arbitration lost interrupt\n");
429 alc = priv->read_reg(dev, REG_ALC); 429 alc = priv->read_reg(priv, REG_ALC);
430 priv->can.can_stats.arbitration_lost++; 430 priv->can.can_stats.arbitration_lost++;
431 stats->rx_errors++; 431 stats->rx_errors++;
432 cf->can_id |= CAN_ERR_LOSTARB; 432 cf->can_id |= CAN_ERR_LOSTARB;
@@ -435,8 +435,8 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status)
435 435
436 if (state != priv->can.state && (state == CAN_STATE_ERROR_WARNING || 436 if (state != priv->can.state && (state == CAN_STATE_ERROR_WARNING ||
437 state == CAN_STATE_ERROR_PASSIVE)) { 437 state == CAN_STATE_ERROR_PASSIVE)) {
438 uint8_t rxerr = priv->read_reg(dev, REG_RXERR); 438 uint8_t rxerr = priv->read_reg(priv, REG_RXERR);
439 uint8_t txerr = priv->read_reg(dev, REG_TXERR); 439 uint8_t txerr = priv->read_reg(priv, REG_TXERR);
440 cf->can_id |= CAN_ERR_CRTL; 440 cf->can_id |= CAN_ERR_CRTL;
441 if (state == CAN_STATE_ERROR_WARNING) { 441 if (state == CAN_STATE_ERROR_WARNING) {
442 priv->can.can_stats.error_warning++; 442 priv->can.can_stats.error_warning++;
@@ -471,15 +471,15 @@ irqreturn_t sja1000_interrupt(int irq, void *dev_id)
471 int n = 0; 471 int n = 0;
472 472
473 /* Shared interrupts and IRQ off? */ 473 /* Shared interrupts and IRQ off? */
474 if (priv->read_reg(dev, REG_IER) == IRQ_OFF) 474 if (priv->read_reg(priv, REG_IER) == IRQ_OFF)
475 return IRQ_NONE; 475 return IRQ_NONE;
476 476
477 if (priv->pre_irq) 477 if (priv->pre_irq)
478 priv->pre_irq(dev); 478 priv->pre_irq(priv);
479 479
480 while ((isrc = priv->read_reg(dev, REG_IR)) && (n < SJA1000_MAX_IRQ)) { 480 while ((isrc = priv->read_reg(priv, REG_IR)) && (n < SJA1000_MAX_IRQ)) {
481 n++; 481 n++;
482 status = priv->read_reg(dev, REG_SR); 482 status = priv->read_reg(priv, REG_SR);
483 483
484 if (isrc & IRQ_WUI) 484 if (isrc & IRQ_WUI)
485 dev_warn(dev->dev.parent, "wakeup interrupt\n"); 485 dev_warn(dev->dev.parent, "wakeup interrupt\n");
@@ -494,7 +494,7 @@ irqreturn_t sja1000_interrupt(int irq, void *dev_id)
494 /* receive interrupt */ 494 /* receive interrupt */
495 while (status & SR_RBS) { 495 while (status & SR_RBS) {
496 sja1000_rx(dev); 496 sja1000_rx(dev);
497 status = priv->read_reg(dev, REG_SR); 497 status = priv->read_reg(priv, REG_SR);
498 } 498 }
499 } 499 }
500 if (isrc & (IRQ_DOI | IRQ_EI | IRQ_BEI | IRQ_EPI | IRQ_ALI)) { 500 if (isrc & (IRQ_DOI | IRQ_EI | IRQ_BEI | IRQ_EPI | IRQ_ALI)) {
@@ -505,7 +505,7 @@ irqreturn_t sja1000_interrupt(int irq, void *dev_id)
505 } 505 }
506 506
507 if (priv->post_irq) 507 if (priv->post_irq)
508 priv->post_irq(dev); 508 priv->post_irq(priv);
509 509
510 if (n >= SJA1000_MAX_IRQ) 510 if (n >= SJA1000_MAX_IRQ)
511 dev_dbg(dev->dev.parent, "%d messages handled in ISR", n); 511 dev_dbg(dev->dev.parent, "%d messages handled in ISR", n);