diff mbox

pinctrl: samsung: add pinctrl_force_sleep() for "sleep" pinctrl state

Message ID 006801d332d5$b0ca09d0$125e1d70$@samsung.com (mailing list archive)
State Changes Requested
Headers show

Commit Message

??? Sept. 21, 2017, 12:32 p.m. UTC
This patch adds pinctrl_for_sleep() in samsung_pinctrl_suspend()
to support configuration of "sleep" pinctrl state.

For example, we can configure "sleep" pinctrl state of "gpf1-6"
as "INPUT, PULL DOWN" by configuring power down mode register.

&pinctrl_5 {
	pinctrl-names = "default","sleep";
	pinctrl-0 = <&initial5>;
	pinctrl-1 = <&sleep5>;

	initial5: initial-state {
		samsung,pins = gpf1-6;
		samsung,pin-function = <EXYNOS_PIN_FUNC_INPUT>;
	};
	sleep5: sleep-state {
		samsung,pins = gpf1-6;
		samsung,pin-con-pdn = <EXYNOS_PIN_PDN_INPUT>;
		samsung,pin-pud-pdn = <EXYNOS_PIN_PULL_DOWN>;
	};
};

Signed-off-by: Youngmin Nam <youngmin.nam@samsung.com>
---
 drivers/pinctrl/samsung/pinctrl-samsung.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

Comments

Tomasz Figa Sept. 21, 2017, 4:14 p.m. UTC | #1
Hi Youngmin,

2017-09-21 21:32 GMT+09:00 남영민 <youngmin.nam@samsung.com>:
> This patch adds pinctrl_for_sleep() in samsung_pinctrl_suspend()
> to support configuration of "sleep" pinctrl state.
>
> For example, we can configure "sleep" pinctrl state of "gpf1-6"
> as "INPUT, PULL DOWN" by configuring power down mode register.
>
> &pinctrl_5 {
>         pinctrl-names = "default","sleep";
>         pinctrl-0 = <&initial5>;
>         pinctrl-1 = <&sleep5>;
>
>         initial5: initial-state {
>                 samsung,pins = gpf1-6;
>                 samsung,pin-function = <EXYNOS_PIN_FUNC_INPUT>;
>         };
>         sleep5: sleep-state {
>                 samsung,pins = gpf1-6;
>                 samsung,pin-con-pdn = <EXYNOS_PIN_PDN_INPUT>;
>                 samsung,pin-pud-pdn = <EXYNOS_PIN_PULL_DOWN>;

This isn't a very good example, because pin-con-pdn and pin-pud-pdn
are used to program dedicated sleep state registers in the pin
controller and they can be programmed at any time. Typically one would
include them in "default" state.

As for pins which don't have dedicated sleep state registers, i.e. the
alive banks, which retain their value, the DT node of device
associated with the pins would have "sleep" pinctrl state and its
driver would activate it on suspend.

The only remaining use case would be pins in alive banks not
associated with any device, but I can't imagine any practical case
that would need to change the value on suspend in such case.

Do you have an example of a real use case for this patch?

>         };
> };
>
> Signed-off-by: Youngmin Nam <youngmin.nam@samsung.com>
> ---
>  drivers/pinctrl/samsung/pinctrl-samsung.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/drivers/pinctrl/samsung/pinctrl-samsung.c b/drivers/pinctrl/samsung/pinctrl-samsung.c
> index e04f7fe0a65d..b4d12f8db475 100644
> --- a/drivers/pinctrl/samsung/pinctrl-samsung.c
> +++ b/drivers/pinctrl/samsung/pinctrl-samsung.c
> @@ -1099,6 +1099,11 @@ static int __maybe_unused samsung_pinctrl_suspend(struct device *dev)
>  {
>         struct samsung_pinctrl_drv_data *drvdata = dev_get_drvdata(dev);
>         int i;
> +       int ret;
> +
> +       ret = pinctrl_force_sleep(drvdata->pctl_dev);
> +       if (ret)
> +               dev_err(dev, "could not set sleep pinstate %d\n", ret);
>
>         for (i = 0; i < drvdata->nr_banks; i++) {
>                 struct samsung_pin_bank *bank = &drvdata->pin_banks[i];
> @@ -1187,6 +1192,11 @@ static int __maybe_unused samsung_pinctrl_resume(struct device *dev)
>         if (drvdata->retention_ctrl && drvdata->retention_ctrl->disable)
>                 drvdata->retention_ctrl->disable(drvdata);
>
> +       /* For changing state without writing register. */
> +       if (!IS_ERR(drvdata->pctl_dev->p) &&
> +           !IS_ERR(drvdata->pctl_dev->hog_default))
> +               drvdata->pctl_dev->p->state = drvdata->pctl_dev->hog_default;

How is this supposed to work? The pins were reconfigured at suspend,
where are they restored back to the values before suspend?

Best regards,
Tomasz
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Linus Walleij Sept. 22, 2017, 1:09 p.m. UTC | #2
On Thu, Sep 21, 2017 at 2:32 PM, 남영민 <youngmin.nam@samsung.com> wrote:

I'm copying the whole patch so that everyone added to To: can see it.

> This patch adds pinctrl_for_sleep() in samsung_pinctrl_suspend()
> to support configuration of "sleep" pinctrl state.
>
> For example, we can configure "sleep" pinctrl state of "gpf1-6"
> as "INPUT, PULL DOWN" by configuring power down mode register.
>
> &pinctrl_5 {
>         pinctrl-names = "default","sleep";
>         pinctrl-0 = <&initial5>;
>         pinctrl-1 = <&sleep5>;
>
>         initial5: initial-state {
>                 samsung,pins = gpf1-6;
>                 samsung,pin-function = <EXYNOS_PIN_FUNC_INPUT>;
>         };
>         sleep5: sleep-state {
>                 samsung,pins = gpf1-6;
>                 samsung,pin-con-pdn = <EXYNOS_PIN_PDN_INPUT>;
>                 samsung,pin-pud-pdn = <EXYNOS_PIN_PULL_DOWN>;
>         };
> };
>
> Signed-off-by: Youngmin Nam <youngmin.nam@samsung.com>
> ---
>  drivers/pinctrl/samsung/pinctrl-samsung.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/drivers/pinctrl/samsung/pinctrl-samsung.c b/drivers/pinctrl/samsung/pinctrl-samsung.c
> index e04f7fe0a65d..b4d12f8db475 100644
> --- a/drivers/pinctrl/samsung/pinctrl-samsung.c
> +++ b/drivers/pinctrl/samsung/pinctrl-samsung.c
> @@ -1099,6 +1099,11 @@ static int __maybe_unused samsung_pinctrl_suspend(struct device *dev)
>  {
>         struct samsung_pinctrl_drv_data *drvdata = dev_get_drvdata(dev);
>         int i;
> +       int ret;
> +
> +       ret = pinctrl_force_sleep(drvdata->pctl_dev);
> +       if (ret)
> +               dev_err(dev, "could not set sleep pinstate %d\n", ret);
>
>         for (i = 0; i < drvdata->nr_banks; i++) {
>                 struct samsung_pin_bank *bank = &drvdata->pin_banks[i];
> @@ -1187,6 +1192,11 @@ static int __maybe_unused samsung_pinctrl_resume(struct device *dev)
>         if (drvdata->retention_ctrl && drvdata->retention_ctrl->disable)
>                 drvdata->retention_ctrl->disable(drvdata);
>
> +       /* For changing state without writing register. */
> +       if (!IS_ERR(drvdata->pctl_dev->p) &&
> +           !IS_ERR(drvdata->pctl_dev->hog_default))
> +               drvdata->pctl_dev->p->state = drvdata->pctl_dev->hog_default;
> +
>         return 0;
>  }

Oddly this business of forcing the hardware into different "sleep" states
is coming up from the left and right at the moment.

Please check a bit at:
commit 6606bc9dee63 ("pinctrl: Add sleep related state to indicate
sleep related configs")
and how the Spreadtrum driver handles this.

That is for the case where the hardware autonomously defines
a sleep state that need to be programmed from somewhere.

This seems to be what this hardware needs to use?

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Linus Walleij Sept. 22, 2017, 1:14 p.m. UTC | #3
On Thu, Sep 21, 2017 at 6:14 PM, Tomasz Figa <tomasz.figa@gmail.com> wrote:

> This isn't a very good example, because pin-con-pdn and pin-pud-pdn
> are used to program dedicated sleep state registers in the pin
> controller and they can be programmed at any time. Typically one would
> include them in "default" state.

Yeah. Baolin added a special flag "sleep-hardware-state" to
indicate these special states, so the pin control driver can set them
up at first state instantiation.

> As for pins which don't have dedicated sleep state registers, i.e. the
> alive banks, which retain their value, the DT node of device
> associated with the pins would have "sleep" pinctrl state and its
> driver would activate it on suspend.

Correct.

> The only remaining use case would be pins in alive banks not
> associated with any device, but I can't imagine any practical case
> that would need to change the value on suspend in such case.

I think those could be made to work with hogs.

What also came up recently was pin controllers that
per se loose their state when the system suspends, so
the whole pin controller is kind of power-cycled and comes
up in some default state.

Florian is looking into a generic solution to that problem.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/pinctrl/samsung/pinctrl-samsung.c b/drivers/pinctrl/samsung/pinctrl-samsung.c
index e04f7fe0a65d..b4d12f8db475 100644
--- a/drivers/pinctrl/samsung/pinctrl-samsung.c
+++ b/drivers/pinctrl/samsung/pinctrl-samsung.c
@@ -1099,6 +1099,11 @@  static int __maybe_unused samsung_pinctrl_suspend(struct device *dev)
 {
 	struct samsung_pinctrl_drv_data *drvdata = dev_get_drvdata(dev);
 	int i;
+	int ret;
+
+	ret = pinctrl_force_sleep(drvdata->pctl_dev);
+	if (ret)
+		dev_err(dev, "could not set sleep pinstate %d\n", ret);
 
 	for (i = 0; i < drvdata->nr_banks; i++) {
 		struct samsung_pin_bank *bank = &drvdata->pin_banks[i];
@@ -1187,6 +1192,11 @@  static int __maybe_unused samsung_pinctrl_resume(struct device *dev)
 	if (drvdata->retention_ctrl && drvdata->retention_ctrl->disable)
 		drvdata->retention_ctrl->disable(drvdata);
 
+	/* For changing state without writing register. */
+	if (!IS_ERR(drvdata->pctl_dev->p) &&
+	    !IS_ERR(drvdata->pctl_dev->hog_default))
+		drvdata->pctl_dev->p->state = drvdata->pctl_dev->hog_default;
+
 	return 0;
 }