state = pca_status(adap); if ( state != 0xF8 ) { dev_dbg(&i2c_adap->dev, "bus is not idle. status is %#04x\n", state ); /* FIXME: what to do. Force stop ? */ return -EREMOTEIO; 
while ((state = pca_status(adap)) != 0xf8 && timeout--) { msleep(10); } if (state != 0xf8) { dev_dbg(&i2c_adap->dev, "bus is not idle. status is %#04x\n", state); return -EIO; 
static int pca_xfer(struct i2c_adapter *i2c_adap,                    struct i2c_msg *msgs,                    int num){        struct i2c_algo_pca_data *adap = i2c_adap->algo_data;        struct i2c_msg *msg = NULL;        int curmsg;	int numbytes = 0;	int state;	int ret;	state = pca_status(adap);	if ( state != 0xF8 ) {		dev_dbg(&i2c_adap->dev, "bus is not idle. status is %#04x\n", state );		/* FIXME: what to do. Force stop ? */		return -EREMOTEIO;	}	DEB1("{{{ XFER %d messages\n", num);	if (i2c_debug>=2) {		for (curmsg = 0; curmsg < num; curmsg++) {			int addr, i;			msg = &msgs[curmsg];						addr = (0x7f & msg->addr) ;					if (msg->flags & I2C_M_RD )				printk(KERN_INFO "    [%02d] RD %d bytes from %#02x [%#02x, ...]\n", 				       curmsg, msg->len, addr, (addr<<1) | 1);			else {				printk(KERN_INFO "    [%02d] WR %d bytes to %#02x [%#02x%s", 				       curmsg, msg->len, addr, addr<<1,				       msg->len == 0 ? "" : ", ");				for(i=0; i < msg->len; i++)					printk("%#04x%s", msg->buf[i], i == msg->len - 1 ? "" : ", ");				printk("]\n");			}		}	}	curmsg = 0;	ret = -EREMOTEIO;	while (curmsg < num) {		state = pca_status(adap);		DEB3("STATE is 0x%02x\n", state);		msg = &msgs[curmsg];		switch (state) {		case 0xf8: /* On reset or stop the bus is idle */			pca_start(adap);			break;		case 0x08: /* A START condition has been transmitted */		case 0x10: /* A repeated start condition has been transmitted */			pca_address(adap, msg);			break;					case 0x18: /* SLA+W has been transmitted; ACK has been received */		case 0x28: /* Data byte in I2CDAT has been transmitted; ACK has been received */			if (numbytes < msg->len) {				pca_tx_byte(adap, msg->buf[numbytes]);				numbytes++;				break;			}			curmsg++; numbytes = 0;			if (curmsg == num)				pca_stop(adap);			else				pca_repeated_start(adap);			break;		case 0x20: /* SLA+W has been transmitted; NOT ACK has been received */			DEB2("NOT ACK received after SLA+W\n");			pca_stop(adap);			goto out;		case 0x40: /* SLA+R has been transmitted; ACK has been received */			pca_rx_ack(adap, msg->len > 1);			break;		case 0x50: /* Data bytes has been received; ACK has been returned */			if (numbytes < msg->len) {				pca_rx_byte(adap, &msg->buf[numbytes], 1);				numbytes++;				pca_rx_ack(adap, numbytes < msg->len - 1);				break;			}			curmsg++; numbytes = 0;			if (curmsg == num)				pca_stop(adap);			else				pca_repeated_start(adap);			break;		case 0x48: /* SLA+R has been transmitted; NOT ACK has been received */			DEB2("NOT ACK received after SLA+R\n");			pca_stop(adap);			goto out;		case 0x30: /* Data byte in I2CDAT has been transmitted; NOT ACK has been received */			DEB2("NOT ACK received after data byte\n");			goto out;		case 0x38: /* Arbitration lost during SLA+W, SLA+R or data bytes */			DEB2("Arbitration lost\n");			goto out;					case 0x58: /* Data byte has been received; NOT ACK has been returned */			if ( numbytes == msg->len - 1 ) {				pca_rx_byte(adap, &msg->buf[numbytes], 0);				curmsg++; numbytes = 0;				if (curmsg == num)					pca_stop(adap);				else					pca_repeated_start(adap);			} else {				DEB2("NOT ACK sent after data byte received. "				     "Not final byte. numbytes %d. len %d\n",				     numbytes, msg->len);				pca_stop(adap);				goto out;			}			break;		case 0x70: /* Bus error - SDA stuck low */			DEB2("BUS ERROR - SDA Stuck low\n");			pca_reset(adap);			goto out;		case 0x90: /* Bus error - SCL stuck low */			DEB2("BUS ERROR - SCL Stuck low\n");			pca_reset(adap);			goto out;		case 0x00: /* Bus error during master or slave mode due to illegal START or STOP condition */			DEB2("BUS ERROR - Illegal START or STOP\n");			pca_reset(adap);			goto out;		default:			printk(KERN_ERR DRIVER ": unhandled SIO state 0x%02x\n", state);			break;		}			}	ret = curmsg; out:	DEB1(KERN_CRIT "}}} transfered %d/%d messages. "	     "status is %#04x. control is %#04x\n", 	     curmsg, num, pca_status(adap),	     pca_get_con(adap));	return ret;}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/48edcb65ddcd93b6421831ad133599aacea9724a/i2c-algo-pca.c/clean/drivers/i2c/algos/i2c-algo-pca.c