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; }
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; }