Merge branch 'turbostat' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux
[linux-2.6-block.git] / drivers / i2c / i2c-slave-eeprom.c
index cf9b09db092f4e9969666565ba1562220d6b2a46..8223746546093c7a08f4bdfc8425459d88fe1a52 100644 (file)
@@ -36,7 +36,7 @@ static int i2c_slave_eeprom_slave_cb(struct i2c_client *client,
        struct eeprom_data *eeprom = i2c_get_clientdata(client);
 
        switch (event) {
-       case I2C_SLAVE_REQ_WRITE_END:
+       case I2C_SLAVE_WRITE_RECEIVED:
                if (eeprom->first_write) {
                        eeprom->buffer_idx = *val;
                        eeprom->first_write = false;
@@ -47,17 +47,23 @@ static int i2c_slave_eeprom_slave_cb(struct i2c_client *client,
                }
                break;
 
-       case I2C_SLAVE_REQ_READ_START:
+       case I2C_SLAVE_READ_PROCESSED:
+               /* The previous byte made it to the bus, get next one */
+               eeprom->buffer_idx++;
+               /* fallthrough */
+       case I2C_SLAVE_READ_REQUESTED:
                spin_lock(&eeprom->buffer_lock);
                *val = eeprom->buffer[eeprom->buffer_idx];
                spin_unlock(&eeprom->buffer_lock);
-               break;
-
-       case I2C_SLAVE_REQ_READ_END:
-               eeprom->buffer_idx++;
+               /*
+                * Do not increment buffer_idx here, because we don't know if
+                * this byte will be actually used. Read Linux I2C slave docs
+                * for details.
+                */
                break;
 
        case I2C_SLAVE_STOP:
+       case I2C_SLAVE_WRITE_REQUESTED:
                eeprom->first_write = true;
                break;