@@ -257,6 +257,14 @@ static void rcar_i2c_init(struct rcar_i2c_priv *priv)
257257 }
258258}
259259
260+ static void rcar_i2c_reset_slave (struct rcar_i2c_priv * priv )
261+ {
262+ rcar_i2c_write (priv , ICSIER , 0 );
263+ rcar_i2c_write (priv , ICSSR , 0 );
264+ rcar_i2c_write (priv , ICSCR , SDBS );
265+ rcar_i2c_write (priv , ICSAR , 0 ); /* Gen2: must be 0 if not using slave */
266+ }
267+
260268static int rcar_i2c_bus_barrier (struct rcar_i2c_priv * priv )
261269{
262270 int ret ;
@@ -875,6 +883,10 @@ static int rcar_i2c_do_reset(struct rcar_i2c_priv *priv)
875883{
876884 int ret ;
877885
886+ /* Don't reset if a slave instance is currently running */
887+ if (priv -> slave )
888+ return - EISCONN ;
889+
878890 ret = reset_control_reset (priv -> rstc );
879891 if (ret )
880892 return ret ;
@@ -903,10 +915,10 @@ static int rcar_i2c_master_xfer(struct i2c_adapter *adap,
903915
904916 /* Gen3+ needs a reset. That also allows RXDMA once */
905917 if (priv -> devtype >= I2C_RCAR_GEN3 ) {
906- priv -> flags &= ~ID_P_NO_RXDMA ;
907918 ret = rcar_i2c_do_reset (priv );
908919 if (ret )
909920 goto out ;
921+ priv -> flags &= ~ID_P_NO_RXDMA ;
910922 }
911923
912924 rcar_i2c_init (priv );
@@ -1033,11 +1045,8 @@ static int rcar_unreg_slave(struct i2c_client *slave)
10331045
10341046 /* ensure no irq is running before clearing ptr */
10351047 disable_irq (priv -> irq );
1036- rcar_i2c_write (priv , ICSIER , 0 );
1037- rcar_i2c_write (priv , ICSSR , 0 );
1048+ rcar_i2c_reset_slave (priv );
10381049 enable_irq (priv -> irq );
1039- rcar_i2c_write (priv , ICSCR , SDBS );
1040- rcar_i2c_write (priv , ICSAR , 0 ); /* Gen2: must be 0 if not using slave */
10411050
10421051 priv -> slave = NULL ;
10431052
@@ -1152,7 +1161,9 @@ static int rcar_i2c_probe(struct platform_device *pdev)
11521161 goto out_pm_disable ;
11531162 }
11541163
1155- rcar_i2c_write (priv , ICSAR , 0 ); /* Gen2: must be 0 if not using slave */
1164+ /* Bring hardware to known state */
1165+ rcar_i2c_init (priv );
1166+ rcar_i2c_reset_slave (priv );
11561167
11571168 if (priv -> devtype < I2C_RCAR_GEN3 ) {
11581169 irqflags |= IRQF_NO_THREAD ;
@@ -1168,6 +1179,7 @@ static int rcar_i2c_probe(struct platform_device *pdev)
11681179 if (of_property_read_bool (dev -> of_node , "smbus" ))
11691180 priv -> flags |= ID_P_HOST_NOTIFY ;
11701181
1182+ /* R-Car Gen3+ needs a reset before every transfer */
11711183 if (priv -> devtype >= I2C_RCAR_GEN3 ) {
11721184 priv -> rstc = devm_reset_control_get_exclusive (& pdev -> dev , NULL );
11731185 if (IS_ERR (priv -> rstc )) {
@@ -1178,6 +1190,9 @@ static int rcar_i2c_probe(struct platform_device *pdev)
11781190 ret = reset_control_status (priv -> rstc );
11791191 if (ret < 0 )
11801192 goto out_pm_put ;
1193+
1194+ /* hard reset disturbs HostNotify local target, so disable it */
1195+ priv -> flags &= ~ID_P_HOST_NOTIFY ;
11811196 }
11821197
11831198 ret = platform_get_irq (pdev , 0 );
0 commit comments