Beispiel #1
0
int i2c_write(int device, unsigned char *buf, int count)
{
    int cnt = count;
    int timeout = 5;

    device &= 0xFF;

    i2c_open();

    __i2c_send_nack();    /* Master does not send ACK, slave sends it */

W_try_again:
    if (timeout < 0)
        goto W_timeout;

    cnt = count;

    __i2c_send_start();
    if (i2c_put_data( (device << 1) | I2C_WRITE ) < 0)
        goto device_err;

#if 0 //CONFIG_JZ_TPANEL_ATA2508
    if (address == 0xff)
    {
        while (cnt)
        {
            if (i2c_put_data_nack(*buf) < 0)
                break;
            cnt--;
            buf++;
        }
    }
    else
#endif
    {
        while (cnt)
        {
            if (i2c_put_data(*buf) < 0)
                break;
            cnt--;
            buf++;
        }
    }

    __i2c_send_stop();
    i2c_close();
    return count - cnt;

device_err:
    timeout--;
    __i2c_send_stop();
    goto W_try_again;

W_timeout:
    logf("Write I2C device 0x%2x failed.", device);
    __i2c_send_stop();
    i2c_close();
    return -1;
}
Beispiel #2
0
int i2c_read(unsigned char device, unsigned char *buf,
	       unsigned char address, int count)
{
	int cnt = count;
	int timeout = 5;

L_try_again:

	if (timeout < 0)
		goto L_timeout;

	__i2c_send_nack();	/* Master does not send ACK, slave sends it */
	__i2c_send_start();
	if (i2c_put_data( (device << 1) | I2C_WRITE ) < 0)
		goto device_werr;
#ifndef CONFIG_TOUCHSCREEN_AK4183
	if (i2c_put_data(address) < 0)
		goto address_err;
#endif

	__i2c_send_start();
	if (i2c_put_data( (device << 1) | I2C_READ ) < 0)
		goto device_rerr;
	__i2c_send_ack();	/* Master sends ACK for continue reading */
	while (cnt) {
		if (cnt == 1) {
			if (i2c_get_data(buf, 0) < 0)
				break;
		} else {
			if (i2c_get_data(buf, 1) < 0)
				break;
		}
		cnt--;
		buf++;
	}
#ifdef CONFIG_TOUCHSCREEN_AK4183
	__i2c_send_nack();
#endif
	__i2c_send_stop();
	return count - cnt;
 device_rerr:
 device_werr:
 address_err:
	timeout --;
	__i2c_send_stop();
	goto L_try_again;

L_timeout:
	__i2c_send_stop();
	printk("Read I2C device 0x%2x failed.\n", device);
	return -ENODEV;
}
Beispiel #3
0
int i2c_lseek(unsigned char device, unsigned char offset)
{
	__i2c_send_nack();	/* Master does not send ACK, slave sends it */
	__i2c_send_start();
	if (i2c_put_data( (device << 1) | I2C_WRITE ) < 0)
		goto device_err;
	if (i2c_put_data(offset) < 0)
		goto address_err;
	return 0;
 device_err:
	printk(KERN_DEBUG "No I2C device (0x%02x) installed.\n", device);
	__i2c_send_stop();
	return -ENODEV;
 address_err:
	printk(KERN_DEBUG "No I2C device (0x%02x) response.\n", device);
	__i2c_send_stop();
	return -EREMOTEIO;
}
Beispiel #4
0
int i2c_read(int device, unsigned char *buf, int count)
{
    int cnt = count;
    int timeout = 5;

    device &= 0xFF;

    i2c_open();

L_try_again:
    if (timeout < 0)
        goto L_timeout;

    __i2c_send_nack();    /* Master does not send ACK, slave sends it */

    __i2c_send_start();
    if (i2c_put_data( (device << 1) | I2C_READ ) < 0)
        goto device_err;

    __i2c_send_ack();    /* Master sends ACK for continue reading */

    while (cnt)
    {
        if (cnt == 1)
        {
            if (i2c_get_data(buf, 0) < 0)
                break;
        }
        else
        {
            if (i2c_get_data(buf, 1) < 0)
                break;
        }
        cnt--;
        buf++;
    }

    __i2c_send_stop();
    i2c_close();
    return count - cnt;

device_err:
    timeout--;
    __i2c_send_stop();
    goto L_try_again;

L_timeout:
    __i2c_send_stop();
    logf("Read I2C device 0x%2x failed.", device);
    i2c_close();
    return -1;
}
Beispiel #5
0
int i2c_write(unsigned char device, unsigned char *buf,
		unsigned char address, int count)
{
	int cnt = count;
	int cnt_in_pg;
	int timeout = 5;
	unsigned char *tmpbuf;
	unsigned char tmpaddr;

	__i2c_send_nack();	/* Master does not send ACK, slave sends it */

 W_try_again:
	if (timeout < 0)
		goto W_timeout;

	cnt = count;
	tmpbuf = (unsigned char *)buf;
	tmpaddr = address;

 start_write_page:
	cnt_in_pg = 0;
	__i2c_send_start();
	if (i2c_put_data( (device << 1) | I2C_WRITE ) < 0)
		goto device_err;
#ifdef CONFIG_JZ_TPANEL_ATA2508
	if (address == 0xff) {
		if (i2c_put_data_nack(tmpaddr) < 0)
			goto address_err;
		while (cnt) {
			if (++cnt_in_pg > 8) {
				__i2c_send_stop();
				mdelay(1);
				tmpaddr += 8;
				goto start_write_page;
			}
			if (i2c_put_data_nack(*tmpbuf) < 0)
				break;
			cnt--;
			tmpbuf++;
		}
	}
	else {

		if (i2c_put_data(tmpaddr) < 0)
			goto address_err;
		while (cnt) {
			if (++cnt_in_pg > 8) {
				__i2c_send_stop();
				mdelay(1);
				tmpaddr += 8;
				goto start_write_page;
			}
			if (i2c_put_data(*tmpbuf) < 0)
				break;
			cnt--;
			tmpbuf++;
		}
	}
#else
#ifndef CONFIG_TOUCHSCREEN_AK4183
	if (i2c_put_data(tmpaddr) < 0)
		goto address_err;
#endif
	while (cnt) {
		if (++cnt_in_pg > 8) {
			__i2c_send_stop();
			mdelay(1);
			tmpaddr += 8;
			goto start_write_page;
		}
		if (i2c_put_data(*tmpbuf) < 0)
			break;
		cnt--;
		tmpbuf++;
	}
#endif
	__i2c_send_stop();
	return count - cnt;
 device_err:
 address_err:
	timeout--;
	__i2c_send_stop();
	goto W_try_again;

 W_timeout:
	printk(KERN_DEBUG "Write I2C device 0x%2x failed.\n", device);
	__i2c_send_stop();
	return -ENODEV;
}