Commit 5b77d162 authored by Wolfram Sang's avatar Wolfram Sang Committed by Wolfram Sang

i2c: slave: rework the slave API

After more discussion, brave users, and additional datasheet evaluation,
some API updates for the new I2C slave framework became imminent. The
slave events now get some easier to understand naming. Also, the event
handling has been simplified to only need a single call to the slave
callback when an action by the backend is required.
Reported-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: default avatarWolfram Sang <wsa+renesas@sang-engineering.com>
Acked-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
Acked-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: default avatarWolfram Sang <wsa@the-dreams.de>
parent 4a7a0822
...@@ -382,11 +382,11 @@ static bool rcar_i2c_slave_irq(struct rcar_i2c_priv *priv) ...@@ -382,11 +382,11 @@ static bool rcar_i2c_slave_irq(struct rcar_i2c_priv *priv)
if (ssr_filtered & SAR) { if (ssr_filtered & SAR) {
/* read or write request */ /* read or write request */
if (ssr_raw & STM) { if (ssr_raw & STM) {
i2c_slave_event(priv->slave, I2C_SLAVE_REQ_READ_START, &value); i2c_slave_event(priv->slave, I2C_SLAVE_READ_REQUESTED, &value);
rcar_i2c_write(priv, ICRXTX, value); rcar_i2c_write(priv, ICRXTX, value);
rcar_i2c_write(priv, ICSIER, SDE | SSR | SAR); rcar_i2c_write(priv, ICSIER, SDE | SSR | SAR);
} else { } else {
i2c_slave_event(priv->slave, I2C_SLAVE_REQ_WRITE_START, &value); i2c_slave_event(priv->slave, I2C_SLAVE_WRITE_REQUESTED, &value);
rcar_i2c_read(priv, ICRXTX); /* dummy read */ rcar_i2c_read(priv, ICRXTX); /* dummy read */
rcar_i2c_write(priv, ICSIER, SDR | SSR | SAR); rcar_i2c_write(priv, ICSIER, SDR | SSR | SAR);
} }
...@@ -406,17 +406,15 @@ static bool rcar_i2c_slave_irq(struct rcar_i2c_priv *priv) ...@@ -406,17 +406,15 @@ static bool rcar_i2c_slave_irq(struct rcar_i2c_priv *priv)
int ret; int ret;
value = rcar_i2c_read(priv, ICRXTX); value = rcar_i2c_read(priv, ICRXTX);
ret = i2c_slave_event(priv->slave, I2C_SLAVE_REQ_WRITE_END, &value); ret = i2c_slave_event(priv->slave, I2C_SLAVE_WRITE_RECEIVED, &value);
/* Send NACK in case of error */ /* Send NACK in case of error */
rcar_i2c_write(priv, ICSCR, SIE | SDBS | (ret < 0 ? FNA : 0)); rcar_i2c_write(priv, ICSCR, SIE | SDBS | (ret < 0 ? FNA : 0));
i2c_slave_event(priv->slave, I2C_SLAVE_REQ_WRITE_START, &value);
rcar_i2c_write(priv, ICSSR, ~SDR & 0xff); rcar_i2c_write(priv, ICSSR, ~SDR & 0xff);
} }
/* master wants to read from us */ /* master wants to read from us */
if (ssr_filtered & SDE) { if (ssr_filtered & SDE) {
i2c_slave_event(priv->slave, I2C_SLAVE_REQ_READ_END, &value); i2c_slave_event(priv->slave, I2C_SLAVE_READ_PROCESSED, &value);
i2c_slave_event(priv->slave, I2C_SLAVE_REQ_READ_START, &value);
rcar_i2c_write(priv, ICRXTX, value); rcar_i2c_write(priv, ICRXTX, value);
rcar_i2c_write(priv, ICSSR, ~SDE & 0xff); rcar_i2c_write(priv, ICSSR, ~SDE & 0xff);
} }
......
...@@ -36,7 +36,7 @@ static int i2c_slave_eeprom_slave_cb(struct i2c_client *client, ...@@ -36,7 +36,7 @@ static int i2c_slave_eeprom_slave_cb(struct i2c_client *client,
struct eeprom_data *eeprom = i2c_get_clientdata(client); struct eeprom_data *eeprom = i2c_get_clientdata(client);
switch (event) { switch (event) {
case I2C_SLAVE_REQ_WRITE_END: case I2C_SLAVE_WRITE_RECEIVED:
if (eeprom->first_write) { if (eeprom->first_write) {
eeprom->buffer_idx = *val; eeprom->buffer_idx = *val;
eeprom->first_write = false; eeprom->first_write = false;
...@@ -47,17 +47,17 @@ static int i2c_slave_eeprom_slave_cb(struct i2c_client *client, ...@@ -47,17 +47,17 @@ static int i2c_slave_eeprom_slave_cb(struct i2c_client *client,
} }
break; break;
case I2C_SLAVE_REQ_READ_START: case I2C_SLAVE_READ_PROCESSED:
eeprom->buffer_idx++;
/* fallthrough */
case I2C_SLAVE_READ_REQUESTED:
spin_lock(&eeprom->buffer_lock); spin_lock(&eeprom->buffer_lock);
*val = eeprom->buffer[eeprom->buffer_idx]; *val = eeprom->buffer[eeprom->buffer_idx];
spin_unlock(&eeprom->buffer_lock); spin_unlock(&eeprom->buffer_lock);
break; break;
case I2C_SLAVE_REQ_READ_END:
eeprom->buffer_idx++;
break;
case I2C_SLAVE_STOP: case I2C_SLAVE_STOP:
case I2C_SLAVE_WRITE_REQUESTED:
eeprom->first_write = true; eeprom->first_write = true;
break; break;
......
...@@ -253,10 +253,10 @@ static inline void i2c_set_clientdata(struct i2c_client *dev, void *data) ...@@ -253,10 +253,10 @@ static inline void i2c_set_clientdata(struct i2c_client *dev, void *data)
#if IS_ENABLED(CONFIG_I2C_SLAVE) #if IS_ENABLED(CONFIG_I2C_SLAVE)
enum i2c_slave_event { enum i2c_slave_event {
I2C_SLAVE_REQ_READ_START, I2C_SLAVE_READ_REQUESTED,
I2C_SLAVE_REQ_READ_END, I2C_SLAVE_WRITE_REQUESTED,
I2C_SLAVE_REQ_WRITE_START, I2C_SLAVE_READ_PROCESSED,
I2C_SLAVE_REQ_WRITE_END, I2C_SLAVE_WRITE_RECEIVED,
I2C_SLAVE_STOP, I2C_SLAVE_STOP,
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment