2018-07-16 15:33:48

by Geert Uytterhoeven

[permalink] [raw]
Subject: [PATCH v4 0/3] regulator: bd9571mwv: Add support for toggle power switches

Hi all,

The ROHM BD9571MWV PMIC on the Renesas Salvator-X(S) and ULCB
development boards supports DDR Backup Power, which means that the DDR
power rails can be kept powered while the main SoC is powered down.

This patch series extends the support for DDR backup mode (see commit
6eb0bfae6973eb6a ("regulator: bd9571mwv: Add support for backup mode"))
to systems with toggle instead of momentary power switches.

With a toggle power switch (or level signal), the following steps must
be followed exactly:
1. Configure PMIC for backup mode, which changes the role of the
power switch to a wake-up switch,
2. Switch accessory power switch off, to prepare for system suspend,
which is a manual step not controlled by software,
3. Suspend system,
4. Switch accessory power switch on, to resume.

Unlike on systems with a momentary toggle switch, an additional step 2
must be performed in between step 1 and step 3. Hence step 1 can no
longer be handled in the PMIC's suspend callback.

This patch series allows performing step 1 when the user writes
"on" to the PMIC's "backup_mode" virtual file in sysfs, e.g.

echo on > /sys/bus/i2c/drivers/bd9571mwv/*/bd9571mwv-regulator*/backup_mode

Conversely, writing "off" reverts the role of the accessory switch to a
power switch.
Note that unlike with momentary switches, backup mode is not enabled by
default, as enabling it prevents the board from being powered off using
the power switch, which may confuse the user.

Changes compared to v3:
- Fix build error and warning if !CONFIG_PM_SLEEP,
- Improve patch description and comment,
- Add Acked-by.

Changes compared to v2:
- Drop 'PM / wakeup: Add callback for wake-up change notification',
- New patch 'regulator: bd9571mwv: Use "backup_mode" sysfs file
instead of "wake_up"',
- Replace use of "wake_up" sysfs file and extra callback for wake-up
change notification by custom "backup_mode" sysfs file,
- New patch ;regulator: bd9571mwv: Document "backup_mode" sysfs file'.

Changes compared to v1:
- Improve patch descriptions,
- Drop "return;" at end of function.

This has been tested on Salvator-XS.

For testing, this series is also available in the
topic/bd9571-toggle-power-switch-v4 branch of my renesas-drivers git
repository at
git://git.kernel.org/pub/scm/linux/kernel/git/geert/renesas-drivers.git.

Thanks for applying!

Geert Uytterhoeven (3):
regulator: bd9571mwv: Use "backup_mode" sysfs file instead of
"wake_up"
regulator: bd9571mwv: Add support for toggle power switches
regulator: bd9571mwv: Document "backup_mode" sysfs file

.../testing/sysfs-driver-bd9571mwv-regulator | 27 +++++++
drivers/regulator/bd9571mwv-regulator.c | 72 +++++++++++++++++--
2 files changed, 94 insertions(+), 5 deletions(-)
create mode 100644 Documentation/ABI/testing/sysfs-driver-bd9571mwv-regulator

--
2.17.1



2018-07-16 15:32:04

by Geert Uytterhoeven

[permalink] [raw]
Subject: [PATCH v4 3/3] regulator: bd9571mwv: Document "backup_mode" sysfs file

Signed-off-by: Geert Uytterhoeven <[email protected]>
Acked-by: Pavel Machek <[email protected]>
---
v4:
- Add Acked-by,

v3:
- New.
---
.../testing/sysfs-driver-bd9571mwv-regulator | 27 +++++++++++++++++++
1 file changed, 27 insertions(+)
create mode 100644 Documentation/ABI/testing/sysfs-driver-bd9571mwv-regulator

diff --git a/Documentation/ABI/testing/sysfs-driver-bd9571mwv-regulator b/Documentation/ABI/testing/sysfs-driver-bd9571mwv-regulator
new file mode 100644
index 0000000000000000..4d63a7904b94a993
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-driver-bd9571mwv-regulator
@@ -0,0 +1,27 @@
+What: /sys/bus/i2c/devices/.../bd9571mwv-regulator.*.auto/backup_mode
+Date: Jul 2018
+KernelVersion: 4.19
+Contact: Geert Uytterhoeven <[email protected]>
+Description: Read/write the current state of DDR Backup Mode, which controls
+ if DDR power rails will be kept powered during system suspend.
+ ("on"/"1" = enabled, "off"/"0" = disabled).
+ Two types of power switches (or control signals) can be used:
+ A. With a momentary power switch (or pulse signal), DDR
+ Backup Mode is enabled by default when available, as the
+ PMIC will be configured only during system suspend.
+ B. With a toggle power switch (or level signal), the
+ following steps must be followed exactly:
+ 1. Configure PMIC for backup mode, to change the role of
+ the accessory power switch from a power switch to a
+ wake-up switch,
+ 2. Switch accessory power switch off, to prepare for
+ system suspend, which is a manual step not controlled
+ by software,
+ 3. Suspend system,
+ 4. Switch accessory power switch on, to resume the
+ system.
+ DDR Backup Mode must be explicitly enabled by the user,
+ to invoke step 1.
+ See also Documentation/devicetree/bindings/mfd/bd9571mwv.txt.
+Users: User space applications for embedded boards equipped with a
+ BD9571MWV PMIC.
--
2.17.1


2018-07-16 15:32:36

by Geert Uytterhoeven

[permalink] [raw]
Subject: [PATCH v4 1/3] regulator: bd9571mwv: Use "backup_mode" sysfs file instead of "wake_up"

Currently the BD9571MWV PMIC driver uses the standard "wake_up" sysfs
file to control enablement of DDR Backup Mode.

However, configuring DDR Backup Mode is not really equivalent to
configuring the PMIC as a wake-up source. To avoid confusion, use a
custom "backup_mode" attribute file in sysfs instead.

Signed-off-by: Geert Uytterhoeven <[email protected]>
---
v4:
- Fix build error and warning if !CONFIG_PM_SLEEP,

v3:
- New.
---
drivers/regulator/bd9571mwv-regulator.c | 52 ++++++++++++++++++++++---
1 file changed, 47 insertions(+), 5 deletions(-)

diff --git a/drivers/regulator/bd9571mwv-regulator.c b/drivers/regulator/bd9571mwv-regulator.c
index be574eb444ebda97..1da36a6590c84ba4 100644
--- a/drivers/regulator/bd9571mwv-regulator.c
+++ b/drivers/regulator/bd9571mwv-regulator.c
@@ -30,6 +30,7 @@ struct bd9571mwv_reg {
/* DDR Backup Power */
u8 bkup_mode_cnt_keepon; /* from "rohm,ddr-backup-power" */
u8 bkup_mode_cnt_saved;
+ bool bkup_mode_enabled;

/* Power switch type */
bool rstbmode_level;
@@ -171,13 +172,40 @@ static int bd9571mwv_bkup_mode_write(struct bd9571mwv *bd, unsigned int mode)
return 0;
}

+static ssize_t backup_mode_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct bd9571mwv_reg *bdreg = dev_get_drvdata(dev);
+
+ return sprintf(buf, "%s\n", bdreg->bkup_mode_enabled ? "on" : "off");
+}
+
+static ssize_t backup_mode_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct bd9571mwv_reg *bdreg = dev_get_drvdata(dev);
+ int ret;
+
+ if (!count)
+ return 0;
+
+ ret = kstrtobool(buf, &bdreg->bkup_mode_enabled);
+ if (ret)
+ return ret;
+
+ return count;
+}
+
+DEVICE_ATTR_RW(backup_mode);
+
static int bd9571mwv_suspend(struct device *dev)
{
struct bd9571mwv_reg *bdreg = dev_get_drvdata(dev);
unsigned int mode;
int ret;

- if (!device_may_wakeup(dev))
+ if (!bdreg->bkup_mode_enabled)
return 0;

/* Save DDR Backup Mode */
@@ -204,7 +232,7 @@ static int bd9571mwv_resume(struct device *dev)
{
struct bd9571mwv_reg *bdreg = dev_get_drvdata(dev);

- if (!device_may_wakeup(dev))
+ if (!bdreg->bkup_mode_enabled)
return 0;

/* Restore DDR Backup Mode */
@@ -215,9 +243,15 @@ static const struct dev_pm_ops bd9571mwv_pm = {
SET_SYSTEM_SLEEP_PM_OPS(bd9571mwv_suspend, bd9571mwv_resume)
};

+static int bd9571mwv_regulator_remove(struct platform_device *pdev)
+{
+ device_remove_file(&pdev->dev, &dev_attr_backup_mode);
+ return 0;
+}
#define DEV_PM_OPS &bd9571mwv_pm
#else
#define DEV_PM_OPS NULL
+#define bd9571mwv_regulator_remove NULL
#endif /* CONFIG_PM_SLEEP */

static int bd9571mwv_regulator_probe(struct platform_device *pdev)
@@ -270,14 +304,21 @@ static int bd9571mwv_regulator_probe(struct platform_device *pdev)
return -EINVAL;
}

+#ifdef CONFIG_PM_SLEEP
if (bdreg->bkup_mode_cnt_keepon) {
- device_set_wakeup_capable(&pdev->dev, true);
+ int ret;
+
/*
- * Wakeup is enabled by default in pulse mode, but needs
+ * Backup mode is enabled by default in pulse mode, but needs
* explicit user setup in level mode.
*/
- device_set_wakeup_enable(&pdev->dev, bdreg->rstbmode_pulse);
+ bdreg->bkup_mode_enabled = bdreg->rstbmode_pulse;
+
+ ret = device_create_file(&pdev->dev, &dev_attr_backup_mode);
+ if (ret)
+ return ret;
}
+#endif /* CONFIG_PM_SLEEP */

return 0;
}
@@ -294,6 +335,7 @@ static struct platform_driver bd9571mwv_regulator_driver = {
.pm = DEV_PM_OPS,
},
.probe = bd9571mwv_regulator_probe,
+ .remove = bd9571mwv_regulator_remove,
.id_table = bd9571mwv_regulator_id_table,
};
module_platform_driver(bd9571mwv_regulator_driver);
--
2.17.1


2018-07-16 15:32:38

by Geert Uytterhoeven

[permalink] [raw]
Subject: [PATCH v4 2/3] regulator: bd9571mwv: Add support for toggle power switches

Extend the existing support for backup mode to toggle power switches.
With a toggle power switch (or level signal), the following steps must
be followed exactly:
1. Configure PMIC for backup mode, to change the role of the
accessory power switch from a power switch to a wake-up switch,
2. Switch accessory power switch off, to prepare for system suspend,
which is a manual step not controlled by software,
3. Suspend system,
4. Switch accessory power switch on, to resume the system.

Hence the PMIC is configured for backup mode when "on" or "1" is written
to the PMIC's "backup_mode" virtual file in sysfs. Conversely, writing
"off" or "0" reverts the role of the accessory switch to a power
switch.

Unlike with momentary switches, backup mode is not enabled by default,
as enabling it prevents the board from being powered off using the power
switch, which may confuse the user.

Signed-off-by: Geert Uytterhoeven <[email protected]>
---
v4:
- Improve patch description and comment,

v3:
- Replace use of "wake_up" sysfs file and extra callback for wake-up
change notification by custom "backup_mode" sysfs file,

v2:
- Improve patch description,
- Drop "return;" at end of function.
---
drivers/regulator/bd9571mwv-regulator.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)

diff --git a/drivers/regulator/bd9571mwv-regulator.c b/drivers/regulator/bd9571mwv-regulator.c
index 1da36a6590c84ba4..c44613b9423baf07 100644
--- a/drivers/regulator/bd9571mwv-regulator.c
+++ b/drivers/regulator/bd9571mwv-regulator.c
@@ -185,6 +185,7 @@ static ssize_t backup_mode_store(struct device *dev,
const char *buf, size_t count)
{
struct bd9571mwv_reg *bdreg = dev_get_drvdata(dev);
+ unsigned int mode;
int ret;

if (!count)
@@ -194,6 +195,25 @@ static ssize_t backup_mode_store(struct device *dev,
if (ret)
return ret;

+ if (!bdreg->rstbmode_level)
+ return count;
+
+ /*
+ * Configure DDR Backup Mode, to change the role of the accessory power
+ * switch from a power switch to a wake-up switch, or vice versa
+ */
+ ret = bd9571mwv_bkup_mode_read(bdreg->bd, &mode);
+ if (ret)
+ return ret;
+
+ mode &= ~BD9571MWV_BKUP_MODE_CNT_KEEPON_MASK;
+ if (bdreg->bkup_mode_enabled)
+ mode |= bdreg->bkup_mode_cnt_keepon;
+
+ ret = bd9571mwv_bkup_mode_write(bdreg->bd, mode);
+ if (ret)
+ return ret;
+
return count;
}

--
2.17.1


2018-07-17 11:37:30

by Niklas Söderlund

[permalink] [raw]
Subject: Re: [PATCH v4 1/3] regulator: bd9571mwv: Use "backup_mode" sysfs file instead of "wake_up"

Hi Geert,

Thanks for your patch.

On 2018-07-16 17:30:50 +0200, Geert Uytterhoeven wrote:
> Currently the BD9571MWV PMIC driver uses the standard "wake_up" sysfs
> file to control enablement of DDR Backup Mode.
>
> However, configuring DDR Backup Mode is not really equivalent to
> configuring the PMIC as a wake-up source. To avoid confusion, use a
> custom "backup_mode" attribute file in sysfs instead.
>
> Signed-off-by: Geert Uytterhoeven <[email protected]>

Reviewed-by: Niklas S?derlund <[email protected]>

> ---
> v4:
> - Fix build error and warning if !CONFIG_PM_SLEEP,
>
> v3:
> - New.
> ---
> drivers/regulator/bd9571mwv-regulator.c | 52 ++++++++++++++++++++++---
> 1 file changed, 47 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/regulator/bd9571mwv-regulator.c b/drivers/regulator/bd9571mwv-regulator.c
> index be574eb444ebda97..1da36a6590c84ba4 100644
> --- a/drivers/regulator/bd9571mwv-regulator.c
> +++ b/drivers/regulator/bd9571mwv-regulator.c
> @@ -30,6 +30,7 @@ struct bd9571mwv_reg {
> /* DDR Backup Power */
> u8 bkup_mode_cnt_keepon; /* from "rohm,ddr-backup-power" */
> u8 bkup_mode_cnt_saved;
> + bool bkup_mode_enabled;
>
> /* Power switch type */
> bool rstbmode_level;
> @@ -171,13 +172,40 @@ static int bd9571mwv_bkup_mode_write(struct bd9571mwv *bd, unsigned int mode)
> return 0;
> }
>
> +static ssize_t backup_mode_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct bd9571mwv_reg *bdreg = dev_get_drvdata(dev);
> +
> + return sprintf(buf, "%s\n", bdreg->bkup_mode_enabled ? "on" : "off");
> +}
> +
> +static ssize_t backup_mode_store(struct device *dev,
> + struct device_attribute *attr,
> + const char *buf, size_t count)
> +{
> + struct bd9571mwv_reg *bdreg = dev_get_drvdata(dev);
> + int ret;
> +
> + if (!count)
> + return 0;
> +
> + ret = kstrtobool(buf, &bdreg->bkup_mode_enabled);
> + if (ret)
> + return ret;
> +
> + return count;
> +}
> +
> +DEVICE_ATTR_RW(backup_mode);
> +
> static int bd9571mwv_suspend(struct device *dev)
> {
> struct bd9571mwv_reg *bdreg = dev_get_drvdata(dev);
> unsigned int mode;
> int ret;
>
> - if (!device_may_wakeup(dev))
> + if (!bdreg->bkup_mode_enabled)
> return 0;
>
> /* Save DDR Backup Mode */
> @@ -204,7 +232,7 @@ static int bd9571mwv_resume(struct device *dev)
> {
> struct bd9571mwv_reg *bdreg = dev_get_drvdata(dev);
>
> - if (!device_may_wakeup(dev))
> + if (!bdreg->bkup_mode_enabled)
> return 0;
>
> /* Restore DDR Backup Mode */
> @@ -215,9 +243,15 @@ static const struct dev_pm_ops bd9571mwv_pm = {
> SET_SYSTEM_SLEEP_PM_OPS(bd9571mwv_suspend, bd9571mwv_resume)
> };
>
> +static int bd9571mwv_regulator_remove(struct platform_device *pdev)
> +{
> + device_remove_file(&pdev->dev, &dev_attr_backup_mode);
> + return 0;
> +}
> #define DEV_PM_OPS &bd9571mwv_pm
> #else
> #define DEV_PM_OPS NULL
> +#define bd9571mwv_regulator_remove NULL
> #endif /* CONFIG_PM_SLEEP */
>
> static int bd9571mwv_regulator_probe(struct platform_device *pdev)
> @@ -270,14 +304,21 @@ static int bd9571mwv_regulator_probe(struct platform_device *pdev)
> return -EINVAL;
> }
>
> +#ifdef CONFIG_PM_SLEEP
> if (bdreg->bkup_mode_cnt_keepon) {
> - device_set_wakeup_capable(&pdev->dev, true);
> + int ret;
> +
> /*
> - * Wakeup is enabled by default in pulse mode, but needs
> + * Backup mode is enabled by default in pulse mode, but needs
> * explicit user setup in level mode.
> */
> - device_set_wakeup_enable(&pdev->dev, bdreg->rstbmode_pulse);
> + bdreg->bkup_mode_enabled = bdreg->rstbmode_pulse;
> +
> + ret = device_create_file(&pdev->dev, &dev_attr_backup_mode);
> + if (ret)
> + return ret;
> }
> +#endif /* CONFIG_PM_SLEEP */
>
> return 0;
> }
> @@ -294,6 +335,7 @@ static struct platform_driver bd9571mwv_regulator_driver = {
> .pm = DEV_PM_OPS,
> },
> .probe = bd9571mwv_regulator_probe,
> + .remove = bd9571mwv_regulator_remove,
> .id_table = bd9571mwv_regulator_id_table,
> };
> module_platform_driver(bd9571mwv_regulator_driver);
> --
> 2.17.1
>

--
Regards,
Niklas S?derlund

2018-07-17 11:50:57

by Niklas Söderlund

[permalink] [raw]
Subject: Re: [PATCH v4 2/3] regulator: bd9571mwv: Add support for toggle power switches

Hi Geert,

Thanks for your work.

On 2018-07-16 17:30:51 +0200, Geert Uytterhoeven wrote:
> Extend the existing support for backup mode to toggle power switches.
> With a toggle power switch (or level signal), the following steps must
> be followed exactly:
> 1. Configure PMIC for backup mode, to change the role of the
> accessory power switch from a power switch to a wake-up switch,
> 2. Switch accessory power switch off, to prepare for system suspend,
> which is a manual step not controlled by software,
> 3. Suspend system,
> 4. Switch accessory power switch on, to resume the system.
>
> Hence the PMIC is configured for backup mode when "on" or "1" is written
> to the PMIC's "backup_mode" virtual file in sysfs. Conversely, writing
> "off" or "0" reverts the role of the accessory switch to a power
> switch.
>
> Unlike with momentary switches, backup mode is not enabled by default,
> as enabling it prevents the board from being powered off using the power
> switch, which may confuse the user.
>
> Signed-off-by: Geert Uytterhoeven <[email protected]>

Reviewed-by: Niklas S?derlund <[email protected]>

> ---
> v4:
> - Improve patch description and comment,
>
> v3:
> - Replace use of "wake_up" sysfs file and extra callback for wake-up
> change notification by custom "backup_mode" sysfs file,
>
> v2:
> - Improve patch description,
> - Drop "return;" at end of function.
> ---
> drivers/regulator/bd9571mwv-regulator.c | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
> diff --git a/drivers/regulator/bd9571mwv-regulator.c b/drivers/regulator/bd9571mwv-regulator.c
> index 1da36a6590c84ba4..c44613b9423baf07 100644
> --- a/drivers/regulator/bd9571mwv-regulator.c
> +++ b/drivers/regulator/bd9571mwv-regulator.c
> @@ -185,6 +185,7 @@ static ssize_t backup_mode_store(struct device *dev,
> const char *buf, size_t count)
> {
> struct bd9571mwv_reg *bdreg = dev_get_drvdata(dev);
> + unsigned int mode;
> int ret;
>
> if (!count)
> @@ -194,6 +195,25 @@ static ssize_t backup_mode_store(struct device *dev,
> if (ret)
> return ret;
>
> + if (!bdreg->rstbmode_level)
> + return count;
> +
> + /*
> + * Configure DDR Backup Mode, to change the role of the accessory power
> + * switch from a power switch to a wake-up switch, or vice versa
> + */
> + ret = bd9571mwv_bkup_mode_read(bdreg->bd, &mode);
> + if (ret)
> + return ret;
> +
> + mode &= ~BD9571MWV_BKUP_MODE_CNT_KEEPON_MASK;
> + if (bdreg->bkup_mode_enabled)
> + mode |= bdreg->bkup_mode_cnt_keepon;
> +
> + ret = bd9571mwv_bkup_mode_write(bdreg->bd, mode);
> + if (ret)
> + return ret;
> +
> return count;
> }
>
> --
> 2.17.1
>

--
Regards,
Niklas S?derlund

2018-07-17 11:54:00

by Niklas Söderlund

[permalink] [raw]
Subject: Re: [PATCH v4 3/3] regulator: bd9571mwv: Document "backup_mode" sysfs file

Hi Geert,

Thanks for your work.

On 2018-07-16 17:30:52 +0200, Geert Uytterhoeven wrote:
> Signed-off-by: Geert Uytterhoeven <[email protected]>
> Acked-by: Pavel Machek <[email protected]>

Reviewed-by: Niklas S?derlund <[email protected]>

> ---
> v4:
> - Add Acked-by,
>
> v3:
> - New.
> ---
> .../testing/sysfs-driver-bd9571mwv-regulator | 27 +++++++++++++++++++
> 1 file changed, 27 insertions(+)
> create mode 100644 Documentation/ABI/testing/sysfs-driver-bd9571mwv-regulator
>
> diff --git a/Documentation/ABI/testing/sysfs-driver-bd9571mwv-regulator b/Documentation/ABI/testing/sysfs-driver-bd9571mwv-regulator
> new file mode 100644
> index 0000000000000000..4d63a7904b94a993
> --- /dev/null
> +++ b/Documentation/ABI/testing/sysfs-driver-bd9571mwv-regulator
> @@ -0,0 +1,27 @@
> +What: /sys/bus/i2c/devices/.../bd9571mwv-regulator.*.auto/backup_mode
> +Date: Jul 2018
> +KernelVersion: 4.19
> +Contact: Geert Uytterhoeven <[email protected]>
> +Description: Read/write the current state of DDR Backup Mode, which controls
> + if DDR power rails will be kept powered during system suspend.
> + ("on"/"1" = enabled, "off"/"0" = disabled).
> + Two types of power switches (or control signals) can be used:
> + A. With a momentary power switch (or pulse signal), DDR
> + Backup Mode is enabled by default when available, as the
> + PMIC will be configured only during system suspend.
> + B. With a toggle power switch (or level signal), the
> + following steps must be followed exactly:
> + 1. Configure PMIC for backup mode, to change the role of
> + the accessory power switch from a power switch to a
> + wake-up switch,
> + 2. Switch accessory power switch off, to prepare for
> + system suspend, which is a manual step not controlled
> + by software,
> + 3. Suspend system,
> + 4. Switch accessory power switch on, to resume the
> + system.
> + DDR Backup Mode must be explicitly enabled by the user,
> + to invoke step 1.
> + See also Documentation/devicetree/bindings/mfd/bd9571mwv.txt.
> +Users: User space applications for embedded boards equipped with a
> + BD9571MWV PMIC.
> --
> 2.17.1
>

--
Regards,
Niklas S?derlund

2018-07-18 12:30:52

by Mark Brown

[permalink] [raw]
Subject: Applied "regulator: bd9571mwv: Use "backup_mode" sysfs file instead of "wake_up"" to the regulator tree

The patch

regulator: bd9571mwv: Use "backup_mode" sysfs file instead of "wake_up"

has been applied to the regulator tree at

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

From 02b3a073c12edc8cbc18e07e8880a32e78c1aee0 Mon Sep 17 00:00:00 2001
From: Geert Uytterhoeven <[email protected]>
Date: Mon, 16 Jul 2018 17:30:50 +0200
Subject: [PATCH] regulator: bd9571mwv: Use "backup_mode" sysfs file instead of
"wake_up"
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Currently the BD9571MWV PMIC driver uses the standard "wake_up" sysfs
file to control enablement of DDR Backup Mode.

However, configuring DDR Backup Mode is not really equivalent to
configuring the PMIC as a wake-up source. To avoid confusion, use a
custom "backup_mode" attribute file in sysfs instead.

Signed-off-by: Geert Uytterhoeven <[email protected]>
Reviewed-by: Niklas Söderlund <[email protected]>
Signed-off-by: Mark Brown <[email protected]>
---
drivers/regulator/bd9571mwv-regulator.c | 52 ++++++++++++++++++++++---
1 file changed, 47 insertions(+), 5 deletions(-)

diff --git a/drivers/regulator/bd9571mwv-regulator.c b/drivers/regulator/bd9571mwv-regulator.c
index be574eb444eb..1da36a6590c8 100644
--- a/drivers/regulator/bd9571mwv-regulator.c
+++ b/drivers/regulator/bd9571mwv-regulator.c
@@ -30,6 +30,7 @@ struct bd9571mwv_reg {
/* DDR Backup Power */
u8 bkup_mode_cnt_keepon; /* from "rohm,ddr-backup-power" */
u8 bkup_mode_cnt_saved;
+ bool bkup_mode_enabled;

/* Power switch type */
bool rstbmode_level;
@@ -171,13 +172,40 @@ static int bd9571mwv_bkup_mode_write(struct bd9571mwv *bd, unsigned int mode)
return 0;
}

+static ssize_t backup_mode_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct bd9571mwv_reg *bdreg = dev_get_drvdata(dev);
+
+ return sprintf(buf, "%s\n", bdreg->bkup_mode_enabled ? "on" : "off");
+}
+
+static ssize_t backup_mode_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct bd9571mwv_reg *bdreg = dev_get_drvdata(dev);
+ int ret;
+
+ if (!count)
+ return 0;
+
+ ret = kstrtobool(buf, &bdreg->bkup_mode_enabled);
+ if (ret)
+ return ret;
+
+ return count;
+}
+
+DEVICE_ATTR_RW(backup_mode);
+
static int bd9571mwv_suspend(struct device *dev)
{
struct bd9571mwv_reg *bdreg = dev_get_drvdata(dev);
unsigned int mode;
int ret;

- if (!device_may_wakeup(dev))
+ if (!bdreg->bkup_mode_enabled)
return 0;

/* Save DDR Backup Mode */
@@ -204,7 +232,7 @@ static int bd9571mwv_resume(struct device *dev)
{
struct bd9571mwv_reg *bdreg = dev_get_drvdata(dev);

- if (!device_may_wakeup(dev))
+ if (!bdreg->bkup_mode_enabled)
return 0;

/* Restore DDR Backup Mode */
@@ -215,9 +243,15 @@ static const struct dev_pm_ops bd9571mwv_pm = {
SET_SYSTEM_SLEEP_PM_OPS(bd9571mwv_suspend, bd9571mwv_resume)
};

+static int bd9571mwv_regulator_remove(struct platform_device *pdev)
+{
+ device_remove_file(&pdev->dev, &dev_attr_backup_mode);
+ return 0;
+}
#define DEV_PM_OPS &bd9571mwv_pm
#else
#define DEV_PM_OPS NULL
+#define bd9571mwv_regulator_remove NULL
#endif /* CONFIG_PM_SLEEP */

static int bd9571mwv_regulator_probe(struct platform_device *pdev)
@@ -270,14 +304,21 @@ static int bd9571mwv_regulator_probe(struct platform_device *pdev)
return -EINVAL;
}

+#ifdef CONFIG_PM_SLEEP
if (bdreg->bkup_mode_cnt_keepon) {
- device_set_wakeup_capable(&pdev->dev, true);
+ int ret;
+
/*
- * Wakeup is enabled by default in pulse mode, but needs
+ * Backup mode is enabled by default in pulse mode, but needs
* explicit user setup in level mode.
*/
- device_set_wakeup_enable(&pdev->dev, bdreg->rstbmode_pulse);
+ bdreg->bkup_mode_enabled = bdreg->rstbmode_pulse;
+
+ ret = device_create_file(&pdev->dev, &dev_attr_backup_mode);
+ if (ret)
+ return ret;
}
+#endif /* CONFIG_PM_SLEEP */

return 0;
}
@@ -294,6 +335,7 @@ static struct platform_driver bd9571mwv_regulator_driver = {
.pm = DEV_PM_OPS,
},
.probe = bd9571mwv_regulator_probe,
+ .remove = bd9571mwv_regulator_remove,
.id_table = bd9571mwv_regulator_id_table,
};
module_platform_driver(bd9571mwv_regulator_driver);
--
2.18.0


2018-07-18 12:31:30

by Mark Brown

[permalink] [raw]
Subject: Applied "regulator: bd9571mwv: Document "backup_mode" sysfs file" to the regulator tree

The patch

regulator: bd9571mwv: Document "backup_mode" sysfs file

has been applied to the regulator tree at

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

From cf18fd01466d59263c615165341684a055206dd5 Mon Sep 17 00:00:00 2001
From: Geert Uytterhoeven <[email protected]>
Date: Mon, 16 Jul 2018 17:30:52 +0200
Subject: [PATCH] regulator: bd9571mwv: Document "backup_mode" sysfs file
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Geert Uytterhoeven <[email protected]>
Acked-by: Pavel Machek <[email protected]>
Reviewed-by: Niklas Söderlund <[email protected]>
Signed-off-by: Mark Brown <[email protected]>
---
.../testing/sysfs-driver-bd9571mwv-regulator | 27 +++++++++++++++++++
1 file changed, 27 insertions(+)
create mode 100644 Documentation/ABI/testing/sysfs-driver-bd9571mwv-regulator

diff --git a/Documentation/ABI/testing/sysfs-driver-bd9571mwv-regulator b/Documentation/ABI/testing/sysfs-driver-bd9571mwv-regulator
new file mode 100644
index 000000000000..4d63a7904b94
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-driver-bd9571mwv-regulator
@@ -0,0 +1,27 @@
+What: /sys/bus/i2c/devices/.../bd9571mwv-regulator.*.auto/backup_mode
+Date: Jul 2018
+KernelVersion: 4.19
+Contact: Geert Uytterhoeven <[email protected]>
+Description: Read/write the current state of DDR Backup Mode, which controls
+ if DDR power rails will be kept powered during system suspend.
+ ("on"/"1" = enabled, "off"/"0" = disabled).
+ Two types of power switches (or control signals) can be used:
+ A. With a momentary power switch (or pulse signal), DDR
+ Backup Mode is enabled by default when available, as the
+ PMIC will be configured only during system suspend.
+ B. With a toggle power switch (or level signal), the
+ following steps must be followed exactly:
+ 1. Configure PMIC for backup mode, to change the role of
+ the accessory power switch from a power switch to a
+ wake-up switch,
+ 2. Switch accessory power switch off, to prepare for
+ system suspend, which is a manual step not controlled
+ by software,
+ 3. Suspend system,
+ 4. Switch accessory power switch on, to resume the
+ system.
+ DDR Backup Mode must be explicitly enabled by the user,
+ to invoke step 1.
+ See also Documentation/devicetree/bindings/mfd/bd9571mwv.txt.
+Users: User space applications for embedded boards equipped with a
+ BD9571MWV PMIC.
--
2.18.0


2018-07-18 12:32:02

by Mark Brown

[permalink] [raw]
Subject: Applied "regulator: bd9571mwv: Add support for toggle power switches" to the regulator tree

The patch

regulator: bd9571mwv: Add support for toggle power switches

has been applied to the regulator tree at

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

From e436875f6f97708613976da75a92974f18998af9 Mon Sep 17 00:00:00 2001
From: Geert Uytterhoeven <[email protected]>
Date: Mon, 16 Jul 2018 17:30:51 +0200
Subject: [PATCH] regulator: bd9571mwv: Add support for toggle power switches
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Extend the existing support for backup mode to toggle power switches.
With a toggle power switch (or level signal), the following steps must
be followed exactly:
1. Configure PMIC for backup mode, to change the role of the
accessory power switch from a power switch to a wake-up switch,
2. Switch accessory power switch off, to prepare for system suspend,
which is a manual step not controlled by software,
3. Suspend system,
4. Switch accessory power switch on, to resume the system.

Hence the PMIC is configured for backup mode when "on" or "1" is written
to the PMIC's "backup_mode" virtual file in sysfs. Conversely, writing
"off" or "0" reverts the role of the accessory switch to a power
switch.

Unlike with momentary switches, backup mode is not enabled by default,
as enabling it prevents the board from being powered off using the power
switch, which may confuse the user.

Signed-off-by: Geert Uytterhoeven <[email protected]>
Reviewed-by: Niklas Söderlund <[email protected]>
Signed-off-by: Mark Brown <[email protected]>
---
drivers/regulator/bd9571mwv-regulator.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)

diff --git a/drivers/regulator/bd9571mwv-regulator.c b/drivers/regulator/bd9571mwv-regulator.c
index 1da36a6590c8..c44613b9423b 100644
--- a/drivers/regulator/bd9571mwv-regulator.c
+++ b/drivers/regulator/bd9571mwv-regulator.c
@@ -185,6 +185,7 @@ static ssize_t backup_mode_store(struct device *dev,
const char *buf, size_t count)
{
struct bd9571mwv_reg *bdreg = dev_get_drvdata(dev);
+ unsigned int mode;
int ret;

if (!count)
@@ -194,6 +195,25 @@ static ssize_t backup_mode_store(struct device *dev,
if (ret)
return ret;

+ if (!bdreg->rstbmode_level)
+ return count;
+
+ /*
+ * Configure DDR Backup Mode, to change the role of the accessory power
+ * switch from a power switch to a wake-up switch, or vice versa
+ */
+ ret = bd9571mwv_bkup_mode_read(bdreg->bd, &mode);
+ if (ret)
+ return ret;
+
+ mode &= ~BD9571MWV_BKUP_MODE_CNT_KEEPON_MASK;
+ if (bdreg->bkup_mode_enabled)
+ mode |= bdreg->bkup_mode_cnt_keepon;
+
+ ret = bd9571mwv_bkup_mode_write(bdreg->bd, mode);
+ if (ret)
+ return ret;
+
return count;
}

--
2.18.0