View | Details | Raw Unified | Return to bug 258994
Collapse All | Expand All

(-)b/sys/dev/iicbus/twsi/twsi.c (-54 / +80 lines)
Lines 550-556 twsi_intr(void *arg) Link Here
550
	case TWSI_STATUS_RPTD_START:
550
	case TWSI_STATUS_RPTD_START:
551
		/* Transmit the address */
551
		/* Transmit the address */
552
		debugf(sc->dev, "Send the address (%x)", sc->msgs[sc->msg_idx].slave);
552
		debugf(sc->dev, "Send the address (%x)", sc->msgs[sc->msg_idx].slave);
553
554
		if (sc->msgs[sc->msg_idx].flags & IIC_M_RD)
553
		if (sc->msgs[sc->msg_idx].flags & IIC_M_RD)
555
			TWSI_WRITE(sc, sc->reg_data,
554
			TWSI_WRITE(sc, sc->reg_data,
556
			    sc->msgs[sc->msg_idx].slave | LSB);
555
			    sc->msgs[sc->msg_idx].slave | LSB);
Lines 576-582 twsi_intr(void *arg) Link Here
576
		debugf(sc->dev, "Ack received after transmitting the address (read)\n");
575
		debugf(sc->dev, "Ack received after transmitting the address (read)\n");
577
		sc->recv_bytes = 0;
576
		sc->recv_bytes = 0;
578
577
579
		TWSI_WRITE(sc, sc->reg_control, sc->control_val);
578
                /* If we are expecting one byte, disable ACK now or else we will miss
579
		 * TWSI_STATUS_DATA_RD_NOACK event. Per I2C standard the last data received
580
		 * will not be acknowledged. */
581
                if (sc->msgs[sc->msg_idx].len - sc->recv_bytes == 1){
582
                        debugf(sc->dev, "Expecting one byte to receive, disabling ACK bit...\n");
583
                        sc->control_val &= ~TWSI_CONTROL_ACK;
584
                        TWSI_WRITE(sc, sc->reg_control, sc->control_val);
585
		/* Else, set ACK bit to acknowledge incoming data.
586
		 * TWSI_STATUS_DATA_RD_ACK will handle succeeding received envents. */
587
                } else {
588
			sc->control_val |= TWSI_CONTROL_ACK;
589
			TWSI_WRITE(sc, sc->reg_control, sc->control_val);
590
		}
580
		break;
591
		break;
581
592
582
	case TWSI_STATUS_ADDR_W_NACK:
593
	case TWSI_STATUS_ADDR_W_NACK:
Lines 590-664 twsi_intr(void *arg) Link Here
590
601
591
	case TWSI_STATUS_DATA_WR_ACK:
602
	case TWSI_STATUS_DATA_WR_ACK:
592
		debugf(sc->dev, "Ack received after transmitting data\n");
603
		debugf(sc->dev, "Ack received after transmitting data\n");
593
		if (sc->sent_bytes == sc->msgs[sc->msg_idx].len) {
604
		/* Check if all data have been sent already.*/
605
              	if (sc->sent_bytes == sc->msgs[sc->msg_idx].len) {
594
			debugf(sc->dev, "Done sending all the bytes for msg %d\n", sc->msg_idx);
606
			debugf(sc->dev, "Done sending all the bytes for msg %d\n", sc->msg_idx);
595
			/* Send stop, no interrupts on stop */
607
596
			if (!(sc->msgs[sc->msg_idx].flags & IIC_M_NOSTOP)) {
608
			/* Move to next message and decide the next operation to perform. */
597
				debugf(sc->dev, "Done TX data, send stop\n");
598
				TWSI_WRITE(sc, sc->reg_control,
599
				    sc->control_val | TWSI_CONTROL_STOP);
600
			} else {
601
				debugf(sc->dev, "Done TX data with NO_STOP\n");
602
				TWSI_WRITE(sc, sc->reg_control, sc->control_val | TWSI_CONTROL_START);
603
			}
604
			sc->msg_idx++;
609
			sc->msg_idx++;
605
			if (sc->msg_idx == sc->nmsgs) {
610
                        sc->sent_bytes=0;		/* Reset sent counter */
606
				debugf(sc->dev, "transfer_done=1\n");
611
607
				transfer_done = 1;
612
                        if (sc->msg_idx == sc->nmsgs) {
608
				sc->error = 0;
613
				/* If we are done with all the messages, end the transfer. */
614
				debugf(sc->dev, "Done all massages, sending STOP\n");
615
                                TWSI_WRITE(sc, sc->reg_control, sc->control_val | TWSI_CONTROL_STOP);
616
                                transfer_done = 1;
617
                                sc->transfer = 0;
618
                                sc->error = 0;
619
			/* Else, process the next messages */
620
			} else if (sc->msgs[sc->msg_idx].flags == IIC_M_RD) {
621
				/* If flag is IIC_M_RD, perform repeat START */
622
				debugf(sc->dev, "Done with massages[%d], sending repeat START\n", sc->msg_idx-1 );
623
                                TWSI_WRITE(sc, sc->reg_control, sc->control_val | TWSI_CONTROL_START);
624
                                TWSI_WRITE(sc, sc->reg_control, sc->control_val);
609
			} else {
625
			} else {
610
				debugf(sc->dev, "Send repeated start\n");
626
				/* Otherwise, treat it as a continuation of write operation. 
611
				TWSI_WRITE(sc, sc->reg_control, sc->control_val | TWSI_CONTROL_START);
627
				 * Immediately send the first data of the next message. 		
612
			}
628
				 * 
613
		} else {
629
				 * from i2c.c notes:
614
			debugf(sc->dev, "Sending byte %d (of %d) = %x\n",
630
				 * If the transfer direction is write and we did a write of the offset
615
			    sc->sent_bytes,
631
				 * above, then we need to elide the start; this transfer is just more
616
			    sc->msgs[sc->msg_idx].len,
632
				 * writing that follows the one started above. */  
617
			    sc->msgs[sc->msg_idx].buf[sc->sent_bytes]);
633
618
			TWSI_WRITE(sc, sc->reg_data,
634
				debugf(sc->dev, "Sending  data=%x of msg[%d]\n", 
619
			    sc->msgs[sc->msg_idx].buf[sc->sent_bytes]);
635
					sc->msgs[sc->msg_idx].buf[sc->sent_bytes], sc->msg_idx);
620
			TWSI_WRITE(sc, sc->reg_control,
636
                		TWSI_WRITE(sc, sc->reg_data, sc->msgs[sc->msg_idx].buf[sc->sent_bytes]);
621
			    sc->control_val);
637
                		TWSI_WRITE(sc, sc->reg_control, sc->control_val);
622
			sc->sent_bytes++;
638
                		sc->sent_bytes++;
639
			}	
640
641
                /* Send remaining data */
642
                } else { 
643
			debugf(sc->dev, "Sending  data=%x of msg[%d]\n", sc->msgs[sc->msg_idx].buf[sc->sent_bytes], sc->msg_idx);
644
                	TWSI_WRITE(sc, sc->reg_data, sc->msgs[sc->msg_idx].buf[sc->sent_bytes]);
645
                	TWSI_WRITE(sc, sc->reg_control, sc->control_val);
646
                	sc->sent_bytes++;
623
		}
647
		}
624
		break;
648
                break;
649
625
650
626
	case TWSI_STATUS_DATA_RD_ACK:
651
	case TWSI_STATUS_DATA_RD_ACK:
627
		debugf(sc->dev, "Ack received after receiving data\n");
652
		debugf(sc->dev, "Ack received after receiving data\n");
628
		sc->msgs[sc->msg_idx].buf[sc->recv_bytes++] = TWSI_READ(sc, sc->reg_data);
653
		sc->msgs[sc->msg_idx].buf[sc->recv_bytes++] = TWSI_READ(sc, sc->reg_data);
629
		debugf(sc->dev, "msg_len=%d recv_bytes=%d\n", sc->msgs[sc->msg_idx].len, sc->recv_bytes);
654
		debugf(sc->dev, "msg_len=%d recv_bytes=%d\n", sc->msgs[sc->msg_idx].len, sc->recv_bytes);
630
655
631
		/* If we only have one byte left, disable ACK */
656
		/* If we only have one byte left to receive , disable ACK bit now               *
632
		if (sc->msgs[sc->msg_idx].len - sc->recv_bytes == 1)
657
		 * so that TWSI_STATUS_DATA_RD_NOACK for will be triggered for next event.      */
658
		if (sc->msgs[sc->msg_idx].len - sc->recv_bytes == 1){
659
			debugf(sc->dev, "Last byte, disabling ACK bit...\n");
633
			sc->control_val &= ~TWSI_CONTROL_ACK;
660
			sc->control_val &= ~TWSI_CONTROL_ACK;
634
		if (sc->msgs[sc->msg_idx].len == sc->recv_bytes) {
661
          		TWSI_WRITE(sc, sc->reg_control, sc->control_val);
635
			debugf(sc->dev, "Done with msg %d\n", sc->msg_idx);
662
		} else {
636
			sc->msg_idx++;
663
			/* Ensure we ACK the next data we received */
637
			if (sc->msg_idx == sc->nmsgs - 1) {
664
			sc->control_val |=TWSI_CONTROL_ACK;
638
				debugf(sc->dev, "No more msgs\n");
665
			TWSI_WRITE(sc, sc->reg_control, sc->control_val);
639
				transfer_done = 1;
640
				sc->error = 0;
641
			}
642
		}
666
		}
643
		TWSI_WRITE(sc, sc->reg_control, sc->control_val);
644
		break;
667
		break;
645
668
646
	case TWSI_STATUS_DATA_RD_NOACK:
669
	case TWSI_STATUS_DATA_RD_NOACK:
647
		if (sc->msgs[sc->msg_idx].len - sc->recv_bytes == 1) {
670
		/* Put the data on the receive buffer. */
648
			sc->msgs[sc->msg_idx].buf[sc->recv_bytes++] = TWSI_READ(sc, sc->reg_data);
671
		sc->msgs[sc->msg_idx].buf[sc->recv_bytes++] = TWSI_READ(sc, sc->reg_data);
649
			debugf(sc->dev, "Done RX data, send stop (2)\n");
672
		debugf(sc->dev, "Done receiving all the byte(s) for msg %d\n", sc->msg_idx);
650
			if (!(sc->msgs[sc->msg_idx].flags & IIC_M_NOSTOP))
673
651
				TWSI_WRITE(sc, sc->reg_control,
674
                sc->msg_idx++;		/* Ready for next message */
652
				    sc->control_val | TWSI_CONTROL_STOP);
675
                sc->recv_bytes=0;	/* Reset receive counter */
676
		if (sc->msg_idx == sc->nmsgs) {
677
                	debugf(sc->dev, "Done all massages, sending STOP\n");
678
                	TWSI_WRITE(sc, sc->reg_control, sc->control_val | TWSI_CONTROL_STOP);
679
                	transfer_done = 1;
680
                 	sc->transfer = 0;
681
               		sc->error = 0;
653
		} else {
682
		} else {
654
			debugf(sc->dev, "No ack when receiving data, sending stop anyway\n");
683
	    		/* If we have more messages, start over. */
655
			if (!(sc->msgs[sc->msg_idx].flags & IIC_M_NOSTOP))
684
			debugf(sc->dev, "Done with massages[%d], sending repeat START\n", sc->msg_idx-1 );
656
				TWSI_WRITE(sc, sc->reg_control,
685
			TWSI_WRITE(sc, sc->reg_control, sc->control_val | TWSI_CONTROL_START);
657
				    sc->control_val | TWSI_CONTROL_STOP);
686
			TWSI_WRITE(sc, sc->reg_control, sc->control_val);
658
		}
687
		}
659
		sc->transfer = 0;
660
		transfer_done = 1;
661
		sc->error = 0;
662
		break;
688
		break;
663
689
664
	default:
690
	default:

Return to bug 258994