pinctrl: Really force states during suspend/resume
Subsystems (2)
PATCH v3 1/1 pinctrl: Really force states during suspend/resume
In case a platform only defaults a "default" set of pins, but not a "sleep" set of pins, and this particular platform suspends and resumes in a way that the pin states are not preserved by the hardware, when we resume, we would call pinctrl_single_resume() -> pinctrl_force_default() -> pinctrl_select_state() and the first thing we do is check that the pins state is the same as before, and do nothing.
In order to fix this, decouple the actual state change from pinctrl_select_state() and move it pinctrl_commit_state(), while keeping the p->state == state check in pinctrl_select_state() not to change the caller assumptions. pinctrl_force_sleep() and pinctrl_force_default() are updated to bypass the state check by calling pinctrl_commit_state().
---
Changes in v3:
- move the state check to pinctrl_select_state
Changes in v2:
- rename __pinctrl_select_state to pinctrl_commit_state
drivers/pinctrl/core.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)
drivers/pinctrl/core.c +17 -7
@@ -992,19 +992,16 @@ struct pinctrl_state *pinctrl_lookup_state(struct pinctrl *p,EXPORT_SYMBOL_GPL (pinctrl_lookup_state);/** -* pinctrl_select_state() - select/activate/program a pinctrl state to HW +* pinctrl_commit_state() - select/activate/program a pinctrl state to HW * @p: the pinctrl handle for the device that requests configuration * @state: the state handle to select/activate/program */ -int pinctrl_select_state (struct pinctrl *p,struct pinctrl_state *state) +static int pinctrl_commit_state (struct pinctrl *p,struct pinctrl_state *state) {struct pinctrl_setting *setting, *setting2;struct pinctrl_state *old_state = p->state;int ret; -if (p->state == state) -return 0 ; -if (p->state) {/* * For each pinmux setting in the old state, forget SW's record
@@ -1068,6 +1065,19 @@ int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *state)return ret; } + +/** +* pinctrl_select_state() - select/activate/program a pinctrl state to HW +* @p: the pinctrl handle for the device that requests configuration +* @state: the state handle to select/activate/program +*/ +int pinctrl_select_state (struct pinctrl *p,struct pinctrl_state *state) +{ +if (p->state == state) +return 0 ; + +return pinctrl_commit_state (p, state); +}EXPORT_SYMBOL_GPL (pinctrl_select_state);static void devm_pinctrl_release (struct device *dev,void *res)
@@ -1236,7 +1246,7 @@ void pinctrl_unregister_map(struct pinctrl_map const *map)int pinctrl_force_sleep (struct pinctrl_dev *pctldev) {if (!IS_ERR (pctldev->p) && !IS_ERR (pctldev->hog_sleep)) -return pinctrl_select_state (pctldev->p, pctldev->hog_sleep); +return pinctrl_commit_state (pctldev->p, pctldev->hog_sleep);return 0 ; }EXPORT_SYMBOL_GPL (pinctrl_force_sleep);
@@ -1248,7 +1258,7 @@ EXPORT_SYMBOL_GPL(pinctrl_force_sleep);int pinctrl_force_default (struct pinctrl_dev *pctldev) {if (!IS_ERR (pctldev->p) && !IS_ERR (pctldev->hog_default)) -return pinctrl_select_state (pctldev->p, pctldev->hog_default); +return pinctrl_commit_state (pctldev->p, pctldev->hog_default);return 0 ; }EXPORT_SYMBOL_GPL (pinctrl_force_default);
Signature · 1 line
2.9.3
Quoted 7 lines · Florian Fainelli
In case a platform only defaults a "default" set of pins, but not a "sleep" set of pins, and this particular platform suspends and resumes in a way that the pin states are not preserved by the hardware, when we resume, we would call
pinctrl_single_resume()->pinctrl_force_default()->pinctrl_select_state()and the first thing we do is check that the pins state is the same as before, and do nothing.
Quoted 8 lines
In order to fix this, decouple the actual state change from
pinctrl_select_state()and move itpinctrl_commit_state(), while keeping thep->state== state check inpinctrl_select_state()not to change the caller assumptions.pinctrl_force_sleep()andpinctrl_force_default()are updated to bypass the state check by callingpinctrl_commit_state().Fixes 6e5e959dde0d ("pinctrl: API changes to support multiple states per device")Signed-off-by Florian Fainelli <[email protected]>
This change is indeed beautiful and clean.
FWIW:
Quoted 79 lines
---
Changes in v3:- move the state check to
pinctrl_select_stateChanges in v2:
- rename
__pinctrl_select_statetopinctrl_commit_statedrivers/pinctrl/core.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)drivers/pinctrl/core.c +17
-8@@ -992,19 +992,16 @@ struct pinctrl_state *pinctrl_lookup_state(struct pinctrl *p,EXPORT_SYMBOL_GPL (pinctrl_lookup_state);/** -* pinctrl_select_state() - select/activate/program a pinctrl state to HW +* pinctrl_commit_state() - select/activate/program a pinctrl state to HW * @p: the pinctrl handle for the device that requests configuration * @state: the state handle to select/activate/program */ -int pinctrl_select_state (struct pinctrl *p,struct pinctrl_state *state) +static int pinctrl_commit_state (struct pinctrl *p,struct pinctrl_state *state) {struct pinctrl_setting *setting, *setting2;struct pinctrl_state *old_state = p->state;int ret; -if (p->state == state) -return 0 ; -if (p->state) {/* * For each pinmux setting in the old state, forget SW's record @@ -1068,6 +1065,19 @@ int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *state)return ret; } + +/** +* pinctrl_select_state() - select/activate/program a pinctrl state to HW +* @p: the pinctrl handle for the device that requests configuration +* @state: the state handle to select/activate/program +*/ +int pinctrl_select_state (struct pinctrl *p,struct pinctrl_state *state) +{ +if (p->state == state) +return 0 ; + +return pinctrl_commit_state (p, state); +}EXPORT_SYMBOL_GPL (pinctrl_select_state);static void devm_pinctrl_release (struct device *dev,void *res)@@ -1236,7 +1246,7 @@ void pinctrl_unregister_map(struct pinctrl_map const *map)int pinctrl_force_sleep (struct pinctrl_dev *pctldev) {if (!IS_ERR (pctldev->p) && !IS_ERR (pctldev->hog_sleep)) -return pinctrl_select_state (pctldev->p, pctldev->hog_sleep); +return pinctrl_commit_state (pctldev->p, pctldev->hog_sleep);return 0 ; }EXPORT_SYMBOL_GPL (pinctrl_force_sleep);@@ -1248,7 +1258,7 @@ EXPORT_SYMBOL_GPL(pinctrl_force_sleep);int pinctrl_force_default (struct pinctrl_dev *pctldev) {if (!IS_ERR (pctldev->p) && !IS_ERR (pctldev->hog_default)) -return pinctrl_select_state (pctldev->p, pctldev->hog_default); +return pinctrl_commit_state (pctldev->p, pctldev->hog_default);return 0 ; }EXPORT_SYMBOL_GPL (pinctrl_force_default); --2.9.3
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 14 lines · Andy Shevchenko
Quoted 13 lines · Florian Fainelli
In case a platform only defaults a "default" set of pins, but not a "sleep" set of pins, and this particular platform suspends and resumes in a way that the pin states are not preserved by the hardware, when we resume, we would call
pinctrl_single_resume()->pinctrl_force_default()->pinctrl_select_state()and the first thing we do is check that the pins state is the same as before, and do nothing.In order to fix this, decouple the actual state change from
pinctrl_select_state()and move itpinctrl_commit_state(), while keeping thep->state== state check inpinctrl_select_state()not to change the caller assumptions.pinctrl_force_sleep()andpinctrl_force_default()are updated to bypass the state check by callingpinctrl_commit_state().
Quoted 7 lines
Quoted 2 lines
Fixes 6e5e959dde0d ("pinctrl: API changes to support multiple states per device")Signed-off-by Florian Fainelli <[email protected]>This change is indeed beautiful and clean.
FWIW:
Reviewed-by Andy Shevchenko <[email protected]>
Thanks Andy!
So actually, I have been thinking about this some more, and while this definitively fixes my original problem with pinctrl-single, I just had to make another driver (sdhci-brcmstb.c) pinctrl aware. And then again, same thing, it has got just one "default" state, so when we call pinctrl_select_state() during driver resume, nothing happens.
So, with that in mind, it seems to me like we may actually just want to remove the p->state == state statement entirely, even though that's an optimization....
... or, what we could do is, expose a version of pinctrl_force_default that takes a struct pinctrl reference instead of a struct pinctrl_dev reference and named differently of course.
Thoughts?
Quoted 84 lines
Quoted 81 lines
---
Changes in v3:- move the state check to
pinctrl_select_stateChanges in v2:
- rename
__pinctrl_select_statetopinctrl_commit_statedrivers/pinctrl/core.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)drivers/pinctrl/core.c +17
-8@@ -992,19 +992,16 @@ struct pinctrl_state *pinctrl_lookup_state(struct pinctrl *p,EXPORT_SYMBOL_GPL (pinctrl_lookup_state);/** -* pinctrl_select_state() - select/activate/program a pinctrl state to HW +* pinctrl_commit_state() - select/activate/program a pinctrl state to HW * @p: the pinctrl handle for the device that requests configuration * @state: the state handle to select/activate/program */ -int pinctrl_select_state (struct pinctrl *p,struct pinctrl_state *state) +static int pinctrl_commit_state (struct pinctrl *p,struct pinctrl_state *state) {struct pinctrl_setting *setting, *setting2;struct pinctrl_state *old_state = p->state;int ret; -if (p->state == state) -return 0 ; -if (p->state) {/* * For each pinmux setting in the old state, forget SW's record @@ -1068,6 +1065,19 @@ int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *state)return ret; } + +/** +* pinctrl_select_state() - select/activate/program a pinctrl state to HW +* @p: the pinctrl handle for the device that requests configuration +* @state: the state handle to select/activate/program +*/ +int pinctrl_select_state (struct pinctrl *p,struct pinctrl_state *state) +{ +if (p->state == state) +return 0 ; + +return pinctrl_commit_state (p, state); +}EXPORT_SYMBOL_GPL (pinctrl_select_state);static void devm_pinctrl_release (struct device *dev,void *res)@@ -1236,7 +1246,7 @@ void pinctrl_unregister_map(struct pinctrl_map const *map)int pinctrl_force_sleep (struct pinctrl_dev *pctldev) {if (!IS_ERR (pctldev->p) && !IS_ERR (pctldev->hog_sleep)) -return pinctrl_select_state (pctldev->p, pctldev->hog_sleep); +return pinctrl_commit_state (pctldev->p, pctldev->hog_sleep);return 0 ; }EXPORT_SYMBOL_GPL (pinctrl_force_sleep);@@ -1248,7 +1258,7 @@ EXPORT_SYMBOL_GPL(pinctrl_force_sleep);int pinctrl_force_default (struct pinctrl_dev *pctldev) {if (!IS_ERR (pctldev->p) && !IS_ERR (pctldev->hog_default)) -return pinctrl_select_state (pctldev->p, pctldev->hog_default); +return pinctrl_commit_state (pctldev->p, pctldev->hog_default);return 0 ; }EXPORT_SYMBOL_GPL (pinctrl_force_default); --2.9.3
Signature · 1 line
Florian
Quoted 10 lines · Florian Fainelli
So actually, I have been thinking about this some more, and while this definitively fixes my original problem with pinctrl-single, I just had to make another driver (
sdhci-brcmstb.c) pinctrl aware. And then again, same thing, it has got just one "default" state, so when we callpinctrl_select_state()during driver resume, nothing happens.So, with that in mind, it seems to me like we may actually just want to remove the
p->state== state statement entirely, even though that's an optimization....
Quoted 5 lines
... or, what we could do is, expose a version of
pinctrl_force_defaultthat takes a struct pinctrl reference instead of a structpinctrl_devreference and named differently of course.Thoughts?
The root problem that the patch is trying to solve is that the hardware loose state when going to sleep, without the pin control core being informed about this, correct?
And that is why the state is then "forced" with this patch, when setting default state: the core think we are already in "default" state, and thus the hack force it to be written down to the hardware again.
But it is IMO just papering over the real bug: that the core does not know that the state is lost.
What I think is the proper solution is to add a callback to switch the state in the core.
The most obvious would be to use the API as many already do:
define "sleep" states in the core, and switch to these before going to sleep. If CONFIG_PM is available simply by calling pinctrl_pm_select_sleep_state() in the driver suspend() callback.
I think this is the most intuitive and clean solution.
Alternatively we would add a function to set the pinctrl handle to an "unknown" state, so that when we resume, the pinctrl core at least knows that we are not in "default" state anymore, so that "default" is applied.
So then we would add:
/**
* pinctrl_set_unknown_state() - tell the pinctrl core that we lost the state */
void pinctrl_set_unknown_state(struct device *dev) {
struct dev_pin_info *pins = dev->pins;
if (!pins)
return 0;
pins->p->state = NULL;
}
I imagine this would give the right results on the suspend path.
Yours,
Linus Walleij
Quoted 16 lines · Linus Walleij
Quoted 14 lines · Florian Fainelli
So actually, I have been thinking about this some more, and while this definitively fixes my original problem with pinctrl-single, I just had to make another driver (
sdhci-brcmstb.c) pinctrl aware. And then again, same thing, it has got just one "default" state, so when we callpinctrl_select_state()during driver resume, nothing happens.So, with that in mind, it seems to me like we may actually just want to remove the
p->state== state statement entirely, even though that's an optimization....... or, what we could do is, expose a version of
pinctrl_force_defaultthat takes a struct pinctrl reference instead of a structpinctrl_devreference and named differently of course.
Quoted 5 lines
Quoted 1 line
Thoughts?
The root problem that the patch is trying to solve is that the hardware loose state when going to sleep, without the pin control core being informed about this, correct?
That is exactly what is happening.
Quoted 5 lines
And that is why the state is then "forced" with this patch, when setting default state: the core think we are already in "default" state, and thus the hack force it to be written down to the hardware again.
Correct.
Quoted 3 lines
But it is IMO just papering over the real bug: that the core does not know that the state is lost.
Yes, agree with that statement.
Quoted 8 lines
What I think is the proper solution is to add a callback to switch the state in the core.
The most obvious would be to use the API as many already do:
define "sleep" states in the core, and switch to these before going to sleep. IfCONFIG_PMis available simply by callingpinctrl_pm_select_sleep_state()in the driversuspend()callback.
Well, the difficulty for our platforms is that S2 does not make the HW lose pin states, only S3 does and drivers should be agnostic of S2 vs. S3.
There is not really a "sleep" and "default" state defined for these platforms just the "default" state. I initially even considered adding a fake "sleep" state just to satisfy the state transition condition, but that does not accurately represent the HW.
Quoted 7 lines
I think this is the most intuitive and clean solution.
Alternatively we would add a function to set the pinctrl handle to an "unknown" state, so that when we resume, the pinctrl core at least knows that we are not in "default" state anymore, so that "default" is applied.
And such a function would be called during driver suspend? Would not we still end-up with the drivers having to know about the fact that there is a) only one pin state defined, and b) these pins potentially lose their states in some deep sleep mode?
Quoted 15 lines
So then we would add:
/**
*pinctrl_set_unknown_state()- tell the pinctrl core that we lost the state */void pinctrl_set_unknown_state(struct device *dev) { struct dev_pin_info *pins = dev->pins; if (!pins) return 0; pins->p->state = NULL; }
Quoted 1 line
I imagine this would give the right results on the suspend path.
Humm, why not, but I am not clear how I would call that nor under which conditions from both the pinctrl-single driver and another one that we use (sdhci-brcmstb.c for instance, but it could be any pinctrl consumer really)?
Thanks!
Quoted 4 lines
Yours,
Linus Walleij
Signature · 1 line
Florian
Quoted 7 lines · Florian Fainelli
Quoted 4 lines · Linus Walleij
The most obvious would be to use the API as many already do:
define "sleep" states in the core, and switch to these before going to sleep. IfCONFIG_PMis available simply by callingpinctrl_pm_select_sleep_state()in the driversuspend()callback.
Quoted 7 lines
Well, the difficulty for our platforms is that S2 does not make the HW lose pin states, only S3 does and drivers should be agnostic of S2 vs. S3.
There is not really a "sleep" and "default" state defined for these platforms just the "default" state. I initially even considered adding a fake "sleep" state just to satisfy the state transition condition, but that does not accurately represent the HW.
Do you mean that on the way up, on the resume path, you know whether the setting was lost or not?
Or you don't know it anywhere?
It is not less elegant to uncessesarily switch to a sleep state than to unnecessarily program the default state when you only went into S2 in that case.
I guess then it is better to assume we will loose the state, or push for more granular handling of S2/3 etc states in the PM core (I guess these states comes from ACPI or similar).
Quoted 9 lines
Quoted 4 lines
Alternatively we would add a function to set the pinctrl handle to an "unknown" state, so that when we resume, the pinctrl core at least knows that we are not in "default" state anymore, so that "default" is applied.
And such a function would be called during driver suspend? Would not we still end-up with the drivers having to know about the fact that there is a) only one pin state defined, and b) these pins potentially lose their states in some deep sleep mode?
Again, the proposal to switch to default state twice just because we do not know how deep sleep we went into isn't any more elegant. Then it is better to just assume we lost the state at all times.
Alternatively develop the PM core. Is it really impossible for PM hooks to know which state it went into/came from?
Yours,
Linus Walleij
(sorry for the lag)
Quoted 11 lines · Linus Walleij
Quoted 10 lines · Florian Fainelli
Quoted 4 lines · Linus Walleij
The most obvious would be to use the API as many already do:
define "sleep" states in the core, and switch to these before going to sleep. IfCONFIG_PMis available simply by callingpinctrl_pm_select_sleep_state()in the driversuspend()callback.Well, the difficulty for our platforms is that S2 does not make the HW lose pin states, only S3 does and drivers should be agnostic of S2 vs. S3.
Quoted 6 lines
Quoted 4 lines
There is not really a "sleep" and "default" state defined for these platforms just the "default" state. I initially even considered adding a fake "sleep" state just to satisfy the state transition condition, but that does not accurately represent the HW.
Do you mean that on the way up, on the resume path, you know> whether the setting was lost or not?
In S3 we loose the hardware contents, and in S2 we do not. A platform device driver has no way (currently) in its suspend/resume callback to know which state was entered/exited.
Quoted 6 lines
Or you don't know it anywhere?
It is not less elegant to uncessesarily switch to a sleep state than to unnecessarily program the default state when you only went into S2 in that case.
Agreed, but defining a sleep state that does not exist just to force a transition to the default state upon resumption is not really elegant.
Quoted 4 lines
I guess then it is better to assume we will loose the state, or push for more granular handling of S2/3 etc states in the PM core (I guess these states comes from ACPI or similar).
I expected to see pm_message_t reflect which state we were entering into (PM_SUSPEND_STANDBY vs. PM_SUSPEND_MEM), but that is not the case.
Quoted 11 lines
Quoted 10 lines
Quoted 5 lines
Alternatively we would add a function to set the pinctrl handle to an "unknown" state, so that when we resume, the pinctrl core at least knows that we are not in "default" state anymore, so that "default" is applied.
And such a function would be called during driver suspend? Would not we still end-up with the drivers having to know about the fact that there is a) only one pin state defined, and b) these pins potentially lose their states in some deep sleep mode?
Quoted 7 lines
Again, the proposal to switch to default state twice just because we do not know how deep sleep we went into isn't any more elegant. Then it is better to just assume we lost the state at all times.
Alternatively develop the PM core. Is it really impossible for PM hooks to know which state it went into/came from?
I don't think I liked Rafael's suggestion of putting that kind of detail into the platform_suspend_ops routine as he seems to suggest here:
https://www.spinics.net/lists/arm-kernel/msg587311.html
and here is my response:
https://www.spinics.net/lists/arm-kernel/msg589844.html
Signature · 1 line
Florian
Sorry for slowness...
Quoted 8 lines · Florian Fainelli
Quoted 3 lines · Linus Walleij
I guess then it is better to assume we will loose the state, or push for more granular handling of S2/3 etc states in the PM core (I guess these states comes from ACPI or similar).
I expected to see
pm_message_treflect which state we were entering into (PM_SUSPEND_STANDBYvs.PM_SUSPEND_MEM), but that is not the case.
Can we fix it?
Quoted 7 lines
Quoted 2 lines
Alternatively develop the PM core. Is it really impossible for PM hooks to know which state it went into/came from?
I don't think I liked Rafael's suggestion of putting that kind of detail into the
platform_suspend_opsroutine as he seems to suggest here:
He is suggesting:
Quoted 3 lines
The cleanest way would be to run that code from one of the platform suspend hooks that receive information on what sleep state is to be entered.
But what I suggest is more the inverse: that it receive information on what state it is coming from, rather than which state it is going to.
But I guess it would be logical that suspend() get to know what state it is going to and resume() get to know which state it is coming from.
So Rafael seem to be aligned with that idea.
Quoted 3 lines
and here is my response:
So if it is not desireable to have every driver know which exact state it came from like S3 this or S2 that and on this laptop we have S2' which is slightly different and such mess (that you predict IIUC) what we really need to know is pretty simple:
did the hardware loose its state or not?
That is the information we want the PM core to provide to the resume() callback, somehow. A simple bool is fine.
Any platform specifics or simplifications pertaining to certain states and whether S5 or S7 looses the context should not be the concern of a driver, what it wants to know is simply whether its device has been powered off and lost its hardware context.
Yours,
Linus Walleij
Quoted 5 lines · Linus Walleij
Sorry for slowness...
Quoted 1 line · Florian Fainelli
On 03/16/2017 07:08 AM, Linus Walleij wrote:
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
I guess then it is better to assume we will loose the state, or push for more granular handling of S2/3 etc states in the PM core (I guess these states comes from ACPI or similar).
I expected to see
pm_message_treflect which state we were entering into (PM_SUSPEND_STANDBYvs.PM_SUSPEND_MEM), but that is not the case.Can we fix it?
Yes, I proposed this and got no feedback so far:
https://www.spinics.net/lists/arm-kernel/msg590135.html
Quoted 11 lines
Quoted 8 lines
Quoted 3 lines
Alternatively develop the PM core. Is it really impossible for PM hooks to know which state it went into/came from?
I don't think I liked Rafael's suggestion of putting that kind of detail into the
platform_suspend_opsroutine as he seems to suggest here:He is suggesting:
Quoted 7 lines
Quoted 3 lines
The cleanest way would be to run that code from one of the platform suspend hooks that receive information on what sleep state is to be entered.
But what I suggest is more the inverse: that it receive information on what state it is coming from, rather than which state it is going to.
The same information is available and it won't change from one suspend cycle to resume, since in between these calls you are supposed to be... suspended.
Quoted 7 lines
But I guess it would be logical that
suspend()get to know what state it is going to andresume()get to know which state it is coming from.> So Rafael seem to be aligned with that idea.Quoted 2 lines
and here is my response:
Quoted 7 lines
So if it is not desireable to have every driver know which exact state it came from like S3 this or S2 that and on this laptop we have S2' which is slightly different and such mess (that you predict IIUC) what we really need to know is pretty simple:
did the hardware loose its state or not?
That information is inherently platform specific though, so on platforms where pinctrl-single is used, you won't necessarily know whether the state should be restored (conversely saved) so maybe that means we should have the possibility for a platform to define a wrapper around pinctrl-single whose purpose is to implement platform specific suspend/r/resume functions and just that really? Is there such a driver already that uses pinctrl-single more as a "library" than anything else?
Quoted 13 lines
That is the information we want the PM core to provide to the
resume()callback, somehow. A simple bool is fine.Any platform specifics or simplifications pertaining to certain states and whether S5 or S7 looses the context should not be the concern of a driver, what it wants to know is simply whether its device has been powered off and lost its hardware context.
Yours,
Linus Walleij
Signature · 1 line
Florian
Quoted 8 lines · Florian Fainelli
Quoted 5 lines · Linus Walleij
So if it is not desireable to have every driver know which exact state it came from like S3 this or S2 that and on this laptop we have S2' which is slightly different and such mess (that you predict IIUC) what we really need to know is pretty simple:
did the hardware loose its state or not?
Quoted 7 lines
That information is inherently platform specific though, so on platforms where pinctrl-single is used, you won't necessarily know whether the state should be restored (conversely saved) so maybe that means we should have the possibility for a platform to define a wrapper around pinctrl-single whose purpose is to implement platform specific suspend/r/resume functions and just that really? Is there such a driver already that uses pinctrl-single more as a "library" than anything else?
pinctrl-single maye not be the easiest in cases like this, but Tony et al have bolted in a few OMAP specifics to pinctrl-single in the past so I don't see why this would be a problem.
commit 02e483f66deb6bd8df6af450726574614eb53be3 "pinctrl: single: Prepare for supporting SoC specific features" etc.
Yours,
Linus Walleij
Hi all,
Quoted 93 lines · Florian Fainelli
In case a platform only defaults a "default" set of pins, but not a "sleep" set of pins, and this particular platform suspends and resumes in a way that the pin states are not preserved by the hardware, when we resume, we would call
pinctrl_single_resume()->pinctrl_force_default()->pinctrl_select_state()and the first thing we do is check that the pins state is the same as before, and do nothing.In order to fix this, decouple the actual state change from
pinctrl_select_state()and move itpinctrl_commit_state(), while keeping thep->state== state check inpinctrl_select_state()not to change the caller assumptions.pinctrl_force_sleep()andpinctrl_force_default()are updated to bypass the state check by callingpinctrl_commit_state().Fixes 6e5e959dde0d ("pinctrl: API changes to support multiple statesper device")
Signed-off-by Florian Fainelli <[email protected]>---
Changes in v3:- move the state check to
pinctrl_select_stateChanges in v2:
- rename
__pinctrl_select_statetopinctrl_commit_statedrivers/pinctrl/core.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)drivers/pinctrl/core.c +0
-1@@ -992,19 +992,16 @@ struct pinctrl_state *pinctrl_lookup_state(struct pinctrl *p, EXPORT_SYMBOL_GPL(pinctrl_lookup_state);/** -* pinctrl_select_state() - select/activate/program a pinctrl state to HW
+ *pinctrl_commit_state()- select/activate/program a pinctrl state to HW
* @p: the pinctrl handle for the device that requests configuration
* @state: the state handle to select/activate/program
*/
-intpinctrl_select_state(struct pinctrl *p, struct pinctrl_state *state)
+static intpinctrl_commit_state(struct pinctrl *p, struct pinctrl_state *state)
{drivers/pinctrl/core.c +3
-3struct pinctrl_setting *setting, *setting2;struct pinctrl_state *old_state = p->state;int ret; -if (p->state == state) -return 0 ; -if (p->state) {/* * For each pinmux setting in the old state, forget SW's record @@ -1068,6 +1065,19 @@ int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *state)return ret; } + +/** +* pinctrl_select_state() - select/activate/program a pinctrl state to HW
+ * @p: the pinctrl handle for the device that requests configuration
+ * @state: the state handle to select/activate/program
+ */
+intpinctrl_select_state(struct pinctrl *p, struct pinctrl_state *state)drivers/pinctrl/core.c +7
-1+{ +if (p->state == state) +return 0 ; + +return pinctrl_commit_state (p, state); +}EXPORT_SYMBOL_GPL (pinctrl_select_state);static void devm_pinctrl_release (struct device *dev,void *res)@@ -1236,7 +1246,7 @@ void pinctrl_unregister_map(struct pinctrl_map const *map) int pinctrl_force_sleep(struct pinctrl_dev *pctldev) {if (!IS_ERR (pctldev->p) && !IS_ERR (pctldev->hog_sleep)) -return pinctrl_select_state (pctldev->p, pctldev->hog_sleep); +return pinctrl_commit_state (pctldev->p, pctldev->hog_sleep);return 0 ; }
EXPORT_SYMBOL_GPL(pinctrl_force_sleep);
drivers/pinctrl/core.c EXPORT_SYMBOL_GPL(pinctrl_force_sleep); · line 1264
Quoted 8 lines
drivers/pinctrl/core.c +1
-1@@ -1248,7 +1258,7 @@ EXPORT_SYMBOL_GPL(pinctrl_force_sleep);int pinctrl_force_default (struct pinctrl_dev *pctldev) {if (!IS_ERR (pctldev->p) && !IS_ERR (pctldev->hog_default)) -return pinctrl_select_state (pctldev->p, pctldev->hog_default); +return pinctrl_commit_state (pctldev->p, pctldev->hog_default);return 0 ; }EXPORT_SYMBOL_GPL (pinctrl_force_default);
I don't often go back over a year worth of LKML, but since this patch recently landed in mainline as 981ed1bfbc6c, I though I'd use it as an anchor to report the following:
It turns out that this patch completely breaks resume on my rk3399-based Chromebook. Most things are timing out, the box is unusable. And since this is my everyday tool, I'm mildly grumpy. Please don't break my toys! ;-) Reverting this patch on top of 4.16-rc2 makes me productive again...
More seriously, I have no idea what's wrong here. It could be a SoC-related issue, hence Heiko on Cc. I'm happy to test any idea you could have.
Thanks,
M.
Signature · 1 line
Who you jivin' with that Cosmik Debris?
Quoted 102 lines · Marc Zyngier
Hi all,
Quoted 99 lines · Florian Fainelli
In case a platform only defaults a "default" set of pins, but not a "sleep" set of pins, and this particular platform suspends and resumes
in a way that the pin states are not preserved by the hardware, when we
resume, we would callpinctrl_single_resume()->pinctrl_force_default()
->pinctrl_select_state()and the first thing we do is check that the pins state is the same as before, and do nothing.In order to fix this, decouple the actual state change from
pinctrl_select_state()and move itpinctrl_commit_state(), while keeping
thep->state== state check inpinctrl_select_state()not to change the
caller assumptions.pinctrl_force_sleep()andpinctrl_force_default()are updated to bypass the state check by callingpinctrl_commit_state().Fixes 6e5e959dde0d ("pinctrl: API changes to support multiple statesper device")
Signed-off-by Florian Fainelli <[email protected]>---
Changes in v3:- move the state check to
pinctrl_select_stateChanges in v2:
- rename
__pinctrl_select_statetopinctrl_commit_statedrivers/pinctrl/core.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)drivers/pinctrl/core.c +0
-1@@ -992,19 +992,16 @@ struct pinctrl_state *pinctrl_lookup_state(struct pinctrl *p, EXPORT_SYMBOL_GPL(pinctrl_lookup_state);/** -* pinctrl_select_state() - select/activate/program a pinctrl state to HW
+ *pinctrl_commit_state()- select/activate/program a pinctrl state to HW
* @p: the pinctrl handle for the device that requests configuration
* @state: the state handle to select/activate/program
*/
-intpinctrl_select_state(struct pinctrl *p, struct pinctrl_state *state)
+static intpinctrl_commit_state(struct pinctrl *p, struct pinctrl_state *state)
{drivers/pinctrl/core.c +3
-3struct pinctrl_setting *setting, *setting2;struct pinctrl_state *old_state = p->state;int ret; -if (p->state == state) -return 0 ; -if (p->state) {/* * For each pinmux setting in the old state, forget SW's record @@ -1068,6 +1065,19 @@ int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *state)return ret; } + +/** +* pinctrl_select_state() - select/activate/program a pinctrl state to HW
+ * @p: the pinctrl handle for the device that requests configuration
+ * @state: the state handle to select/activate/program
+ */
+intpinctrl_select_state(struct pinctrl *p, struct pinctrl_state *state)drivers/pinctrl/core.c +7
-1+{ +if (p->state == state) +return 0 ; + +return pinctrl_commit_state (p, state); +}EXPORT_SYMBOL_GPL (pinctrl_select_state);static void devm_pinctrl_release (struct device *dev,void *res)@@ -1236,7 +1246,7 @@ void pinctrl_unregister_map(struct pinctrl_map const *map) int pinctrl_force_sleep(struct pinctrl_dev *pctldev) {if (!IS_ERR (pctldev->p) && !IS_ERR (pctldev->hog_sleep)) -return pinctrl_select_state (pctldev->p, pctldev->hog_sleep); +return pinctrl_commit_state (pctldev->p, pctldev->hog_sleep);return 0 ; }
EXPORT_SYMBOL_GPL(pinctrl_force_sleep);drivers/pinctrl/core.c +0
-0@@ -1248,7 +1258,7 @@ EXPORT_SYMBOL_GPL(pinctrl_force_sleep);
Quoted 8 lines
drivers/pinctrl/core.c EXPORT_SYMBOL_GPL(pinctrl_force_sleep); · line 1264
Quoted 8 lines
drivers/pinctrl/core.c +1
-1int pinctrl_force_default (struct pinctrl_dev *pctldev) {if (!IS_ERR (pctldev->p) && !IS_ERR (pctldev->hog_default)) -return pinctrl_select_state (pctldev->p, pctldev->hog_default); +return pinctrl_commit_state (pctldev->p, pctldev->hog_default);return 0 ; }EXPORT_SYMBOL_GPL (pinctrl_force_default);
Hey Marc,
Quoted 9 lines
I don't often go back over a year worth of LKML, but since this patch recently landed in mainline as
981ed1bfbc6c, I though I'd use it as an anchor to report the following:It turns out that this patch completely breaks resume on my rk3399-based Chromebook. Most things are timing out, the box is unusable. And since this is my everyday tool, I'm mildly grumpy. Please
Quoted 6 lines
don't break my toys! ;-) Reverting this patch on top of 4.16-rc2 makes me productive again...
More seriously, I have no idea what's wrong here. It could be a SoC-related issue, hence Heiko on Cc. I'm happy to test any idea you could have.
Can you indicate which DTS file is used for your Chromebook model? Sorry about the breakage.
Signature · 1 line
Florian
Am Montag, 19. Februar 2018, 19:03:27 CET schrieb Florian Fainelli:
Quoted 123 lines · Marc Zyngier
Quoted 102 lines
Hi all,
Quoted 99 lines · Florian Fainelli
In case a platform only defaults a "default" set of pins, but not a "sleep" set of pins, and this particular platform suspends and resumes
in a way that the pin states are not preserved by the hardware, when we
resume, we would callpinctrl_single_resume()->pinctrl_force_default()
->pinctrl_select_state()and the first thing we do is check that the pins state is the same as before, and do nothing.In order to fix this, decouple the actual state change from
pinctrl_select_state()and move itpinctrl_commit_state(), while keeping
thep->state== state check inpinctrl_select_state()not to change the
caller assumptions.pinctrl_force_sleep()andpinctrl_force_default()are updated to bypass the state check by callingpinctrl_commit_state().Fixes 6e5e959dde0d ("pinctrl: API changes to support multiple statesper device")
Signed-off-by Florian Fainelli <[email protected]>---
Changes in v3:- move the state check to
pinctrl_select_stateChanges in v2:
- rename
__pinctrl_select_statetopinctrl_commit_statedrivers/pinctrl/core.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)drivers/pinctrl/core.c +0
-1@@ -992,19 +992,16 @@ struct pinctrl_state *pinctrl_lookup_state(struct pinctrl *p, EXPORT_SYMBOL_GPL(pinctrl_lookup_state);/** -* pinctrl_select_state() - select/activate/program a pinctrl state to HW
+ *pinctrl_commit_state()- select/activate/program a pinctrl state to HW
* @p: the pinctrl handle for the device that requests configuration
* @state: the state handle to select/activate/program
*/
-intpinctrl_select_state(struct pinctrl *p, struct pinctrl_state *state)
+static intpinctrl_commit_state(struct pinctrl *p, struct pinctrl_state *state)
{drivers/pinctrl/core.c +3
-3struct pinctrl_setting *setting, *setting2;struct pinctrl_state *old_state = p->state;int ret; -if (p->state == state) -return 0 ; -if (p->state) {/* * For each pinmux setting in the old state, forget SW's record @@ -1068,6 +1065,19 @@ int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *state)return ret; } + +/** +* pinctrl_select_state() - select/activate/program a pinctrl state to HW
+ * @p: the pinctrl handle for the device that requests configuration
+ * @state: the state handle to select/activate/program
+ */
+intpinctrl_select_state(struct pinctrl *p, struct pinctrl_state *state)drivers/pinctrl/core.c +7
-1+{ +if (p->state == state) +return 0 ; + +return pinctrl_commit_state (p, state); +}EXPORT_SYMBOL_GPL (pinctrl_select_state);static void devm_pinctrl_release (struct device *dev,void *res)@@ -1236,7 +1246,7 @@ void pinctrl_unregister_map(struct pinctrl_map const *map) int pinctrl_force_sleep(struct pinctrl_dev *pctldev) {if (!IS_ERR (pctldev->p) && !IS_ERR (pctldev->hog_sleep)) -return pinctrl_select_state (pctldev->p, pctldev->hog_sleep); +return pinctrl_commit_state (pctldev->p, pctldev->hog_sleep);return 0 ; }
EXPORT_SYMBOL_GPL(pinctrl_force_sleep);drivers/pinctrl/core.c +0
-0@@ -1248,7 +1258,7 @@ EXPORT_SYMBOL_GPL(pinctrl_force_sleep);Quoted 8 lines
drivers/pinctrl/core.c EXPORT_SYMBOL_GPL(pinctrl_force_sleep); · line 1264
Quoted 8 lines
drivers/pinctrl/core.c +1
-1int pinctrl_force_default (struct pinctrl_dev *pctldev) {if (!IS_ERR (pctldev->p) && !IS_ERR (pctldev->hog_default)) -return pinctrl_select_state (pctldev->p, pctldev->hog_default); +return pinctrl_commit_state (pctldev->p, pctldev->hog_default);return 0 ; }EXPORT_SYMBOL_GPL (pinctrl_force_default);Hey Marc,
Quoted 9 lines
I don't often go back over a year worth of LKML, but since this patch recently landed in mainline as
981ed1bfbc6c, I though I'd use it as an anchor to report the following:It turns out that this patch completely breaks resume on my rk3399-based Chromebook. Most things are timing out, the box is unusable. And since this is my everyday tool, I'm mildly grumpy. Please
Quoted 8 lines
Quoted 6 lines
don't break my toys! ;-) Reverting this patch on top of 4.16-rc2 makes me productive again...
More seriously, I have no idea what's wrong here. It could be a SoC-related issue, hence Heiko on Cc. I'm happy to test any idea you could have.
Can you indicate which DTS file is used for your Chromebook model? Sorry about the breakage.
that should be
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/boot/dts/rockchip/rk3399-gru-kevin.dts
I'm vacationing right now, so don't think I'll find time to dive into Rockchip pinctrl this week. But I'd guess it could be somehow related to the ATF touching pins during suspend/resume?
Quoted 40 lines · Heiko Stuebner
Am Montag, 19. Februar 2018, 19:03:27 CET schrieb Florian Fainelli:
Quoted 38 lines · Marc Zyngier
Quoted 37 lines
Hi all,
Quoted 34 lines · Florian Fainelli
In case a platform only defaults a "default" set of pins, but not a "sleep" set of pins, and this particular platform suspends and resumes
in a way that the pin states are not preserved by the hardware, when we
resume, we would callpinctrl_single_resume()->pinctrl_force_default()
->pinctrl_select_state()and the first thing we do is check that the pins state is the same as before, and do nothing.In order to fix this, decouple the actual state change from
pinctrl_select_state()and move itpinctrl_commit_state(), while keeping
thep->state== state check inpinctrl_select_state()not to change the
caller assumptions.pinctrl_force_sleep()andpinctrl_force_default()are updated to bypass the state check by callingpinctrl_commit_state().Fixes 6e5e959dde0d ("pinctrl: API changes to support multiple statesper device")
Signed-off-by Florian Fainelli <[email protected]>---
Changes in v3:- move the state check to
pinctrl_select_stateChanges in v2:
- rename
__pinctrl_select_statetopinctrl_commit_statedrivers/pinctrl/core.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)
Hey Heiko,
Quoted 18 lines
Quoted 18 lines
Hey Marc,
Quoted 15 lines
I don't often go back over a year worth of LKML, but since this patch recently landed in mainline as
981ed1bfbc6c, I though I'd use it as an anchor to report the following:It turns out that this patch completely breaks resume on my rk3399-based Chromebook. Most things are timing out, the box is unusable. And since this is my everyday tool, I'm mildly grumpy. Please
don't break my toys! ;-) Reverting this patch on top of 4.16-rc2 makes me productive again...
More seriously, I have no idea what's wrong here. It could be a SoC-related issue, hence Heiko on Cc. I'm happy to test any idea you could have.
Quoted 8 lines
Quoted 1 line
Can you indicate which DTS file is used for your Chromebook model? Sorry about the breakage.
that should be
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/boot/dts/rockchip/rk3399-gru-kevin.dtsI'm vacationing right now, so don't think I'll find time to dive into Rockchip pinctrl this week. But I'd guess it could be somehow related to the ATF touching pins during suspend/resume?
That'd be really unfortunate. I would have assumed that ATF would leave things as they were instead of re-configuring them to whatever default.
The most annoying thing is that if that's indeed the case, we need to find a solution that will cope with the current state of the firmware. I guess that'd mean eagerly saving/restoring the pin state across suspend/resume, irrespective of what firmware could do?
Enjoy your holiday!
M.
Signature · 1 line
Jazz is not dead, it just smell funny.
Quoted 11 lines · Marc Zyngier
Quoted 10 lines
Am Montag, 19. Februar 2018, 19:03:27 CET schrieb Florian Fainelli:
Quoted 1 line
Can you indicate which DTS file is used for your Chromebook model? Sorry about the breakage.
that should be
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/boot/dts/rockchip/rk3399-gru-kevin.dtsI'm vacationing right now, so don't think I'll find time to dive into Rockchip pinctrl this week. But I'd guess it could be somehow related to the ATF touching pins during suspend/resume?
Quoted 8 lines
That'd be really unfortunate. I would have assumed that ATF would leave things as they were instead of re-configuring them to whatever default.
The most annoying thing is that if that's indeed the case, we need to find a solution that will cope with the current state of the firmware. I guess that'd mean eagerly saving/restoring the pin state across suspend/resume, irrespective of what firmware could do?
What is ATF? Asus Touch Firmware?
Does it in effect mean that when the Rockchip pinctrl driver says pinctrl_force_sleep() and pinctrl_force_default() it expects those to be a noop?
Then the real patch to apply is something deleting the pinctrl_force* calls from the pinctrl-rockchip driver, is it not?
Yours,
Linus Walleij
Hi Linus,
Quoted 16 lines · Linus Walleij
Quoted 15 lines · Marc Zyngier
Quoted 10 lines
Am Montag, 19. Februar 2018, 19:03:27 CET schrieb Florian Fainelli:
Quoted 1 line
Can you indicate which DTS file is used for your Chromebook model? Sorry about the breakage.
that should be
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/boot/dts/rockchip/rk3399-gru-kevin.dtsI'm vacationing right now, so don't think I'll find time to dive into Rockchip pinctrl this week. But I'd guess it could be somehow related to the ATF touching pins during suspend/resume?
That'd be really unfortunate. I would have assumed that ATF would leave things as they were instead of re-configuring them to whatever default.
Quoted 6 lines
Quoted 4 lines
The most annoying thing is that if that's indeed the case, we need to find a solution that will cope with the current state of the firmware. I guess that'd mean eagerly saving/restoring the pin state across suspend/resume, irrespective of what firmware could do?
What is ATF? Asus Touch Firmware?
More like "ARM Trusted Firmware", aka the firmware that runs on the secure side of most 64bit ARM systems.
Quoted 7 lines
Does it in effect mean that when the Rockchip pinctrl driver says
pinctrl_force_sleep()andpinctrl_force_default()it expects those to be a noop?Then the real patch to apply is something deleting the pinctrl_force* calls from the pinctrl-rockchip driver, is it not?
Quite possibly. Unravelling this bit of code, I came to a similar conclusion. The question is then: what is this call supposed to be used for? I'm pretty sure it is not completely gratuitous, but it makes no sense on my platform.
I'll give it a go later today.
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Quoted 24 lines · Florian Fainelli
Quoted 22 lines · Marc Zyngier
Hi all,
Quoted 19 lines · Florian Fainelli
In case a platform only defaults a "default" set of pins, but not a "sleep" set of pins, and this particular platform suspends and resumes
in a way that the pin states are not preserved by the hardware, when we
resume, we would callpinctrl_single_resume()->pinctrl_force_default()
->pinctrl_select_state()and the first thing we do is check that the pins state is the same as before, and do nothing.In order to fix this, decouple the actual state change from
pinctrl_select_state()and move itpinctrl_commit_state(), while keeping
thep->state== state check inpinctrl_select_state()not to change the
caller assumptions.pinctrl_force_sleep()andpinctrl_force_default()are updated to bypass the state check by callingpinctrl_commit_state().
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Fixes 6e5e959dde0d ("pinctrl: API changes to support multiple statesper device")
Signed-off-by Florian Fainelli <[email protected]>
[back to using my ARM address]
Hey Florian,
Quoted 13 lines
Hey Marc,
Quoted 11 lines
I don't often go back over a year worth of LKML, but since this patch recently landed in mainline as
981ed1bfbc6c, I though I'd use it as an anchor to report the following:It turns out that this patch completely breaks resume on my rk3399-based Chromebook. Most things are timing out, the box is unusable. And since this is my everyday tool, I'm mildly grumpy. Please don't break my toys! ;-) Reverting this patch on top of 4.16-rc2 makes me productive again...
Quoted 5 lines
Quoted 3 lines
More seriously, I have no idea what's wrong here. It could be a SoC-related issue, hence Heiko on Cc. I'm happy to test any idea you could have.
Can you indicate which DTS file is used for your Chromebook model?
Sure. That's arch/arm64/boot/dts/rockchip/rk3399-gru-kevin.dts, with a couple of fixes on top (some clocks and big-little idiosyncrasies).
Quoted 1 line
Sorry about the breakage.
No worries.
M.
Signature · 1 line
Jazz is not dead, it just smell funny.