Lines Matching +full:hw +full:- +full:settle +full:- +full:time

2  * sja1000.c -  Philips SJA1000 network device driver
7 * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
90 * The command register needs some locking and time to settle in sja1000_write_cmdreg()
91 * the write_reg() operation - especially on SMP systems. in sja1000_write_cmdreg()
93 spin_lock_irqsave(&priv->cmdreg_lock, flags); in sja1000_write_cmdreg()
94 priv->write_reg(priv, SJA1000_CMR, val); in sja1000_write_cmdreg()
95 priv->read_reg(priv, SJA1000_SR); in sja1000_write_cmdreg()
96 spin_unlock_irqrestore(&priv->cmdreg_lock, flags); in sja1000_write_cmdreg()
101 return (priv->read_reg(priv, SJA1000_MOD) == 0xFF); in sja1000_is_absent()
108 if (priv->reg_base && sja1000_is_absent(priv)) { in sja1000_probe_chip()
112 return -1; in sja1000_probe_chip()
118 unsigned char status = priv->read_reg(priv, SJA1000_MOD); in set_reset_mode()
122 priv->write_reg(priv, SJA1000_IER, IRQ_OFF); in set_reset_mode()
127 priv->can.state = CAN_STATE_STOPPED; in set_reset_mode()
132 priv->write_reg(priv, SJA1000_MOD, MOD_RM); in set_reset_mode()
134 status = priv->read_reg(priv, SJA1000_MOD); in set_reset_mode()
143 unsigned char status = priv->read_reg(priv, SJA1000_MOD); in set_normal_mode()
150 priv->can.state = CAN_STATE_ERROR_ACTIVE; in set_normal_mode()
152 if (priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING) in set_normal_mode()
153 priv->write_reg(priv, SJA1000_IER, IRQ_ALL); in set_normal_mode()
155 priv->write_reg(priv, SJA1000_IER, in set_normal_mode()
161 if (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY) in set_normal_mode()
163 if (priv->can.ctrlmode & CAN_CTRLMODE_PRESUME_ACK) in set_normal_mode()
165 priv->write_reg(priv, SJA1000_MOD, mod_reg_val); in set_normal_mode()
169 status = priv->read_reg(priv, SJA1000_MOD); in set_normal_mode()
177 * - reset chip
178 * - set output mode
179 * - set baudrate
180 * - enable interrupts
181 * - start operating mode
188 priv->write_reg(priv, SJA1000_CDR, priv->cdr | CDR_PELICAN); in chipset_init()
191 priv->write_reg(priv, SJA1000_ACCC0, 0x00); in chipset_init()
192 priv->write_reg(priv, SJA1000_ACCC1, 0x00); in chipset_init()
193 priv->write_reg(priv, SJA1000_ACCC2, 0x00); in chipset_init()
194 priv->write_reg(priv, SJA1000_ACCC3, 0x00); in chipset_init()
196 priv->write_reg(priv, SJA1000_ACCM0, 0xFF); in chipset_init()
197 priv->write_reg(priv, SJA1000_ACCM1, 0xFF); in chipset_init()
198 priv->write_reg(priv, SJA1000_ACCM2, 0xFF); in chipset_init()
199 priv->write_reg(priv, SJA1000_ACCM3, 0xFF); in chipset_init()
201 priv->write_reg(priv, SJA1000_OCR, priv->ocr | OCR_MODE_NORMAL); in chipset_init()
209 if (priv->can.state != CAN_STATE_STOPPED) in sja1000_start()
213 if (!(priv->read_reg(priv, SJA1000_CDR) & CDR_PELICAN)) in sja1000_start()
217 priv->write_reg(priv, SJA1000_TXERR, 0x0); in sja1000_start()
218 priv->write_reg(priv, SJA1000_RXERR, 0x0); in sja1000_start()
219 priv->read_reg(priv, SJA1000_ECC); in sja1000_start()
222 priv->read_reg(priv, SJA1000_IR); in sja1000_start()
238 return -EOPNOTSUPP; in sja1000_set_mode()
247 struct can_bittiming *bt = &priv->can.bittiming; in sja1000_set_bittiming()
250 btr0 = ((bt->brp - 1) & 0x3f) | (((bt->sjw - 1) & 0x3) << 6); in sja1000_set_bittiming()
251 btr1 = ((bt->prop_seg + bt->phase_seg1 - 1) & 0xf) | in sja1000_set_bittiming()
252 (((bt->phase_seg2 - 1) & 0x7) << 4); in sja1000_set_bittiming()
253 if (priv->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES) in sja1000_set_bittiming()
258 priv->write_reg(priv, SJA1000_BTR0, btr0); in sja1000_set_bittiming()
259 priv->write_reg(priv, SJA1000_BTR1, btr1); in sja1000_set_bittiming()
269 bec->txerr = priv->read_reg(priv, SJA1000_TXERR); in sja1000_get_berr_counter()
270 bec->rxerr = priv->read_reg(priv, SJA1000_RXERR); in sja1000_get_berr_counter()
279 * [ can-id ] [flags] [len] [can data (up to 8 bytes]
285 struct can_frame *cf = (struct can_frame *)skb->data; in sja1000_start_xmit()
298 fi = dlc = cf->can_dlc; in sja1000_start_xmit()
299 id = cf->can_id; in sja1000_start_xmit()
307 priv->write_reg(priv, SJA1000_FI, fi); in sja1000_start_xmit()
308 priv->write_reg(priv, SJA1000_ID1, (id & 0x1fe00000) >> 21); in sja1000_start_xmit()
309 priv->write_reg(priv, SJA1000_ID2, (id & 0x001fe000) >> 13); in sja1000_start_xmit()
310 priv->write_reg(priv, SJA1000_ID3, (id & 0x00001fe0) >> 5); in sja1000_start_xmit()
311 priv->write_reg(priv, SJA1000_ID4, (id & 0x0000001f) << 3); in sja1000_start_xmit()
314 priv->write_reg(priv, SJA1000_FI, fi); in sja1000_start_xmit()
315 priv->write_reg(priv, SJA1000_ID1, (id & 0x000007f8) >> 3); in sja1000_start_xmit()
316 priv->write_reg(priv, SJA1000_ID2, (id & 0x00000007) << 5); in sja1000_start_xmit()
320 priv->write_reg(priv, dreg++, cf->data[i]); in sja1000_start_xmit()
324 if (priv->can.ctrlmode & CAN_CTRLMODE_ONE_SHOT) in sja1000_start_xmit()
327 if (priv->can.ctrlmode & CAN_CTRLMODE_LOOPBACK) in sja1000_start_xmit()
340 struct net_device_stats *stats = &dev->stats; in sja1000_rx()
353 fi = priv->read_reg(priv, SJA1000_FI); in sja1000_rx()
358 id = (priv->read_reg(priv, SJA1000_ID1) << 21) in sja1000_rx()
359 | (priv->read_reg(priv, SJA1000_ID2) << 13) in sja1000_rx()
360 | (priv->read_reg(priv, SJA1000_ID3) << 5) in sja1000_rx()
361 | (priv->read_reg(priv, SJA1000_ID4) >> 3); in sja1000_rx()
366 id = (priv->read_reg(priv, SJA1000_ID1) << 3) in sja1000_rx()
367 | (priv->read_reg(priv, SJA1000_ID2) >> 5); in sja1000_rx()
370 cf->can_dlc = get_can_dlc(fi & 0x0F); in sja1000_rx()
374 for (i = 0; i < cf->can_dlc; i++) in sja1000_rx()
375 cf->data[i] = priv->read_reg(priv, dreg++); in sja1000_rx()
378 cf->can_id = id; in sja1000_rx()
383 stats->rx_packets++; in sja1000_rx()
384 stats->rx_bytes += cf->can_dlc; in sja1000_rx()
393 struct net_device_stats *stats = &dev->stats; in sja1000_err()
396 enum can_state state = priv->can.state; in sja1000_err()
403 return -ENOMEM; in sja1000_err()
405 txerr = priv->read_reg(priv, SJA1000_TXERR); in sja1000_err()
406 rxerr = priv->read_reg(priv, SJA1000_RXERR); in sja1000_err()
408 cf->data[6] = txerr; in sja1000_err()
409 cf->data[7] = rxerr; in sja1000_err()
414 cf->can_id |= CAN_ERR_CRTL; in sja1000_err()
415 cf->data[1] = CAN_ERR_CRTL_RX_OVERFLOW; in sja1000_err()
416 stats->rx_over_errors++; in sja1000_err()
417 stats->rx_errors++; in sja1000_err()
434 priv->can.can_stats.bus_error++; in sja1000_err()
435 stats->rx_errors++; in sja1000_err()
437 ecc = priv->read_reg(priv, SJA1000_ECC); in sja1000_err()
439 cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR; in sja1000_err()
444 cf->data[2] |= CAN_ERR_PROT_BIT; in sja1000_err()
447 cf->data[2] |= CAN_ERR_PROT_FORM; in sja1000_err()
450 cf->data[2] |= CAN_ERR_PROT_STUFF; in sja1000_err()
457 cf->data[3] = ecc & ECC_SEG; in sja1000_err()
461 cf->data[2] |= CAN_ERR_PROT_TX; in sja1000_err()
475 alc = priv->read_reg(priv, SJA1000_ALC); in sja1000_err()
476 priv->can.can_stats.arbitration_lost++; in sja1000_err()
477 cf->can_id |= CAN_ERR_LOSTARB; in sja1000_err()
478 cf->data[0] = alc & 0x1f; in sja1000_err()
481 if (state != priv->can.state) { in sja1000_err()
491 stats->rx_packets++; in sja1000_err()
492 stats->rx_bytes += cf->can_dlc; in sja1000_err()
502 struct net_device_stats *stats = &dev->stats; in sja1000_interrupt()
506 if (priv->pre_irq) in sja1000_interrupt()
507 priv->pre_irq(priv); in sja1000_interrupt()
510 if (priv->read_reg(priv, SJA1000_IER) == IRQ_OFF) in sja1000_interrupt()
513 while ((isrc = priv->read_reg(priv, SJA1000_IR)) && in sja1000_interrupt()
516 status = priv->read_reg(priv, SJA1000_SR); in sja1000_interrupt()
517 /* check for absent controller due to hw unplug */ in sja1000_interrupt()
526 if (priv->can.ctrlmode & CAN_CTRLMODE_ONE_SHOT && in sja1000_interrupt()
528 stats->tx_errors++; in sja1000_interrupt()
532 stats->tx_bytes += in sja1000_interrupt()
533 priv->read_reg(priv, SJA1000_FI) & 0xf; in sja1000_interrupt()
534 stats->tx_packets++; in sja1000_interrupt()
544 status = priv->read_reg(priv, SJA1000_SR); in sja1000_interrupt()
558 if (priv->post_irq) in sja1000_interrupt()
559 priv->post_irq(priv); in sja1000_interrupt()
582 if (!(priv->flags & SJA1000_CUSTOM_IRQ_HANDLER)) { in sja1000_open()
583 err = request_irq(dev->irq, sja1000_interrupt, priv->irq_flags, in sja1000_open()
584 dev->name, (void *)dev); in sja1000_open()
587 return -EAGAIN; in sja1000_open()
608 if (!(priv->flags & SJA1000_CUSTOM_IRQ_HANDLER)) in sja1000_close()
609 free_irq(dev->irq, (void *)dev); in sja1000_close()
630 priv->dev = dev; in alloc_sja1000dev()
631 priv->can.bittiming_const = &sja1000_bittiming_const; in alloc_sja1000dev()
632 priv->can.do_set_bittiming = sja1000_set_bittiming; in alloc_sja1000dev()
633 priv->can.do_set_mode = sja1000_set_mode; in alloc_sja1000dev()
634 priv->can.do_get_berr_counter = sja1000_get_berr_counter; in alloc_sja1000dev()
635 priv->can.ctrlmode_supported = CAN_CTRLMODE_LOOPBACK | in alloc_sja1000dev()
642 spin_lock_init(&priv->cmdreg_lock); in alloc_sja1000dev()
645 priv->priv = (void *)priv + sizeof(struct sja1000_priv); in alloc_sja1000dev()
669 return -ENODEV; in register_sja1000dev()
671 dev->flags |= IFF_ECHO; /* we support local echo */ in register_sja1000dev()
672 dev->netdev_ops = &sja1000_netdev_ops; in register_sja1000dev()