i2c: mux: pca954x: Make sure the mux remains configured the same as before resume
Subsystems (2)
PATCH 1/2 i2c: mux: pca954x: Make sure the mux remains configured the same as before resume
The current implementation of pca954x_init() rewrites content of data->last_chan which is then populated into the mux select register. Skip this part, so that the mux is populated with content of data->last_chan as it was set before suspend. This way, the mux state is retained across suspend/resume cycle.
---
Cc: Peter Rosin <[email protected]>
Cc: Wolfram Sang <[email protected]>
Cc: [email protected]
--- drivers/i2c/muxes/i2c-mux-pca954x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/i2c/muxes/i2c-mux-pca954x.c +2 -2
@@ -620,9 +620,9 @@ static int pca954x_resume(struct device *dev)struct pca954x *data =i2c_mux_priv (muxc);int ret; - ret =pca954x_init (client, data); + ret =i2c_smbus_write_byte (client, data->last_chan);if (ret <0 ) -dev_err (&client->dev,"failed to verify mux presence\n" ); +dev_err (&client->dev,"failed to restore mux state\n" );return ret; }
Signature · 1 line
2.40.1
PATCH 2/2 i2c: mux: pca954x: Resume the mux early
The mux resumes alongside its subdevices, which means the subdevices may resume while the mux is not yet fully configured and those subdevices may fail to access I2C registers through the mux. Use resume_early to resume the mux before any of the other i2c devices.
---
NOTE: This might be wrong approach
---
Cc: Peter Rosin <[email protected]>
Cc: Wolfram Sang <[email protected]>
Cc: [email protected]
--- drivers/i2c/muxes/i2c-mux-pca954x.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/i2c/muxes/i2c-mux-pca954x.c +4 -2
@@ -627,12 +627,14 @@ static int pca954x_resume(struct device *dev)return ret; } -static DEFINE_SIMPLE_DEV_PM_OPS(pca954x_pm, NULL, pca954x_resume); +static const struct dev_pm_ops pca954x_pm = { + .resume_early = pca954x_resume, +};static struct i2c_driver pca954x_driver = { .driver = { .name ="pca954x" , - .pm =pm_sleep_ptr (&pca954x_pm), + .pm = &pca954x_pm, .of_match_table = pca954x_of_match, }, .probe = pca954x_probe,
Signature · 1 line
2.40.1
Hi!
Quoted 4 lines · Marek Vasut
The current implementation of
pca954x_init()rewrites content ofdata->last_chanwhich is then populated into the mux select register. Skip this part, so that the mux is populated with content ofdata->last_chanas it was set before suspend. This way, the mux state is retained across suspend/resume cycle.
I fail to see in what situation this change makes a significant difference? For me, it's a nice conservative thing to initialize to the default state after something comparatively heavy such as a suspend/resume cycle. If there is a significant difference, then maybe it's not the usual access patterns after resume since there are probably other chips initializing as well, in which case this change might make things worse depending on what devices you do have and what idle-state you have configured.
Quoted 15 lines
Fixes e65e228eb096 ("i2c: mux: pca954x: support property idle-state")Signed-off-by Marek Vasut <[email protected]>---
Cc: Peter Rosin <[email protected]>
Cc: Wolfram Sang <[email protected]>
Cc: [email protected]--- drivers/i2c/muxes/i2c-mux-pca954x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/i2c/muxes/i2c-mux-pca954x.c +0
-0
drivers/i2c/muxes/i2c-mux-pca954x.c static int pca954x_resume(struct device *dev) · line 625
Quoted 8 lines
drivers/i2c/muxes/i2c-mux-pca954x.c +2
-2@@ -620,9 +620,9 @@ static int pca954x_resume(struct device *dev)struct pca954x *data =i2c_mux_priv (muxc);int ret; - ret =pca954x_init (client, data); + ret =i2c_smbus_write_byte (client, data->last_chan);if (ret <0 ) -dev_err (&client->dev,"failed to verify mux presence\n" ); +dev_err (&client->dev,"failed to restore mux state\n" );
data->last_chan is no longer cleared in case the write fails. Is that a problem?
Cheers,
Peter
Quoted 3 lines
drivers/i2c/muxes/i2c-mux-pca954x.c +0
-0return ret; }
Quoted 1 line · Peter Rosin
Hi!
Hi,
Quoted 6 lines
Quoted 4 lines · Marek Vasut
The current implementation of
pca954x_init()rewrites content ofdata->last_chanwhich is then populated into the mux select register. Skip this part, so that the mux is populated with content ofdata->last_chanas it was set before suspend. This way, the mux state is retained across suspend/resume cycle.
Quoted 8 lines
I fail to see in what situation this change makes a significant difference? For me, it's a nice conservative thing to initialize to the default state after something comparatively heavy such as a suspend/resume cycle. If there is a significant difference, then maybe it's not the usual access patterns after resume since there are probably other chips initializing as well, in which case this change might make things worse depending on what devices you do have and what idle-state you have configured.
Isn't it better to keep the hardware in the same state it was before it entered suspend ? For me, that's the behavior I would expect from suspend/resume .
Quoted 18 lines
Quoted 18 lines
Fixes e65e228eb096 ("i2c: mux: pca954x: support property idle-state")Signed-off-by Marek Vasut <[email protected]>---
Cc: Peter Rosin <[email protected]>
Cc: Wolfram Sang <[email protected]>
Cc: [email protected]--- drivers/i2c/muxes/i2c-mux-pca954x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/i2c/muxes/i2c-mux-pca954x.c +0
-0@@ -620,9 +620,9 @@ static int pca954x_resume(struct device *dev)struct pca954x *data =i2c_mux_priv (muxc);int ret;
Quoted 8 lines
drivers/i2c/muxes/i2c-mux-pca954x.c static int pca954x_resume(struct device *dev) · line 625
Quoted 5 lines
drivers/i2c/muxes/i2c-mux-pca954x.c +2
-2- ret =pca954x_init (client, data); + ret =i2c_smbus_write_byte (client, data->last_chan);if (ret <0 ) -dev_err (&client->dev,"failed to verify mux presence\n" ); +dev_err (&client->dev,"failed to restore mux state\n" );
data->last_chanis no longer cleared in case the write fails. Is that a problem?
If the write fails here, the hardware is in undefined state anyway .
Either the next attempt to flip the switch would help bring it back, or, the system is in undefined state.
Hi!
Quoted 20 lines · Marek Vasut
Quoted 1 line · Peter Rosin
Hi!
Hi,
Quoted 6 lines
Quoted 4 lines · Marek Vasut
The current implementation of
pca954x_init()rewrites content ofdata->last_chanwhich is then populated into the mux select register. Skip this part, so that the mux is populated with content ofdata->last_chanas it was set before suspend. This way, the mux state is retained across suspend/resume cycle.Quoted 8 lines
I fail to see in what situation this change makes a significant difference? For me, it's a nice conservative thing to initialize to the default state after something comparatively heavy such as a suspend/resume cycle. If there is a significant difference, then maybe it's not the usual access patterns after resume since there are probably other chips initializing as well, in which case this change might make things worse depending on what devices you do have and what idle-state you have configured.
Quoted 1 line
Isn't it better to keep the hardware in the same state it was before it entered suspend ? For me, that's the behavior I would expect from suspend/resume .
Ok, in either case the current behavior isn't a bug. Please drop the Fixes-tag.
Quoted 27 lines
Quoted 11 lines
Quoted 11 lines
Fixes e65e228eb096 ("i2c: mux: pca954x: support property idle-state")Signed-off-by Marek Vasut <[email protected]>---
Cc: Peter Rosin <[email protected]>
Cc: Wolfram Sang <[email protected]>
Cc: [email protected]
---
drivers/i2c/muxes/i2c-mux-pca954x.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)Quoted 15 lines
drivers/i2c/muxes/i2c-mux-pca954x.c static int pca954x_resume(struct device *dev) · line 625
Quoted 12 lines
drivers/i2c/muxes/i2c-mux-pca954x.c +2
-1@@ -620,9 +620,9 @@ static int pca954x_resume(struct device *dev) struct pca954x *data = i2c_mux_priv(muxc); int ret; - ret = pca954x_init(client, data); + ret = i2c_smbus_write_byte(client, data->last_chan); if (ret < 0) - dev_err(&client->dev, "failed to verify mux presence\n"); + dev_err(&client->dev, "failed to restore mux state\n");
data->last_chanis no longer cleared in case the write fails. Is that a problem?
Quoted 2 lines
If the write fails here, the hardware is in undefined state anyway .
Either the next attempt to flip the switch would help bring it back, or, the system is in undefined state.
Being in an undefined state with last_chan being zero is better than being in an undefined state with last_chan holding some other value, so that writing the register isn't skipped in the following call to pca954x_select_chan(). This is the whole point of clearing last_chan on error. Notice how pca954x_select_chan() also clears last_chan on error.
Cheers,
Peter
Quoted 58 lines · Peter Rosin
Hi!
Quoted 20 lines · Marek Vasut
Quoted 1 line · Peter Rosin
Hi!
Hi,
Quoted 6 lines
Quoted 4 lines · Marek Vasut
The current implementation of
pca954x_init()rewrites content ofdata->last_chanwhich is then populated into the mux select register. Skip this part, so that the mux is populated with content ofdata->last_chanas it was set before suspend. This way, the mux state is retained across suspend/resume cycle.Quoted 8 lines
I fail to see in what situation this change makes a significant difference? For me, it's a nice conservative thing to initialize to the default state after something comparatively heavy such as a suspend/resume cycle. If there is a significant difference, then maybe it's not the usual access patterns after resume since there are probably other chips initializing as well, in which case this change might make things worse depending on what devices you do have and what idle-state you have configured.
Quoted 1 line
Isn't it better to keep the hardware in the same state it was before it entered suspend ? For me, that's the behavior I would expect from suspend/resume .
Ok, in either case the current behavior isn't a bug. Please drop the Fixes-tag.
Quoted 27 lines
Quoted 11 lines
Quoted 11 lines
Fixes e65e228eb096 ("i2c: mux: pca954x: support property idle-state")Signed-off-by Marek Vasut <[email protected]>---
Cc: Peter Rosin <[email protected]>
Cc: Wolfram Sang <[email protected]>
Cc: [email protected]--- drivers/i2c/muxes/i2c-mux-pca954x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)Quoted 15 lines
drivers/i2c/muxes/i2c-mux-pca954x.c static int pca954x_resume(struct device *dev) · line 625
Quoted 12 lines
drivers/i2c/muxes/i2c-mux-pca954x.c +2
-1@@ -620,9 +620,9 @@ static int pca954x_resume(struct device *dev) struct pca954x *data = i2c_mux_priv(muxc); int ret; - ret = pca954x_init(client, data); + ret = i2c_smbus_write_byte(client, data->last_chan); if (ret < 0) - dev_err(&client->dev, "failed to verify mux presence\n"); + dev_err(&client->dev, "failed to restore mux state\n");
data->last_chanis no longer cleared in case the write fails. Is that a problem?Quoted 2 lines
If the write fails here, the hardware is in undefined state anyway .
Either the next attempt to flip the switch would help bring it back, or, the system is in undefined state.
Quoted 6 lines
Being in an undefined state with
last_chanbeing zero is better than being in an undefined state withlast_chanholding some other value, so that writing the register isn't skipped in the following call topca954x_select_chan(). This is the whole point of clearinglast_chanon error. Notice howpca954x_select_chan()also clearslast_chanon error.
OK, then just drop this patch.