MPC52xxx I2C: make algo use of I2C_RSTA
PATCH 1/1 MPC52xxx I2C: make algo use of I2C_RSTA
This patch makes use of I2C RESTART sequence when sending severals i2c_msg instead of the STOP and START sequence.
Some I2C component reset there internal values when a STOP is sent. (like the Ricoh rs5c372b I2C RTC)
Patch is against DENX linuxppc CVS
Regards,
Bertrand
drivers/i2c/i2c-algo-mpc5xxx.c +22 -9
@@ -62,6 +62,14 @@return ; } +static void i2c_restart (struct i2c_algo_mpc5xxx_data *algo_data) +{ +struct mpc5xxx_i2c *regs = algo_data->regs; + +mpc5xxx_out (®s->mcr, MPC5xxx_I2C_RSTA, MPC5xxx_I2C_RSTA); + +return ; +}static void i2c_stop (struct i2c_algo_mpc5xxx_data *algo_data) {
@@ -311,13 +319,14 @@int status;int i; +if (wait_for_bb (algo_data)) +return -EREMOTEIO ; + +i2c_start (algo_data); +for (i =0 ; i < num; i++) { pmsg = &msgs[i]; -if (wait_for_bb (algo_data)) -return -EREMOTEIO ; - -i2c_start (algo_data);mpc5xxx_do_address (algo_data, pmsg, adap->retries);if (wait_for_pin (algo_data, &status)) {
@@ -332,17 +341,21 @@if (pmsg->flags &I2C_M_RD ) { ret =mpc5xxx_readbytes (adap, pmsg->buf, pmsg->len); -if (ret != pmsg->len) +if (ret != pmsg->len) { +i2c_stop (algo_data);return (ret <0 ) ? ret : -EREMOTEIO ; + } }else { ret =mpc5xxx_sendbytes (adap, pmsg->buf, pmsg->len); -if (ret != pmsg->len) +if (ret != pmsg->len) { +i2c_stop (algo_data);return (ret <0 ) ? ret : -EREMOTEIO ; + } } - -i2c_stop (algo_data); +if (i+1 < num)i2c_restart (algo_data); } - + +i2c_stop (algo_data);return num; }