2022-08-08 18:03:26

by Paul Cercueil

[permalink] [raw]
Subject: [PATCH v2 00/30] mfd: Remove #ifdef guards for PM functions

Hi Lee,

Here's my revised patchset updated from the feedback I got in V1.
This one is based on the current mfd-next-5.20.

I updated the PM macros in <linux/pm.h> and <linux/pm_runtime.h>, to
make them more versatile. They now allow to conditionally export
arbitrary dev_pm_ops structures. This is used in the "arizona" driver
for instance, which has "noirq" callbacks.

I Cc'd Jonathan, whom might be interested by the PM patch to convert the
IIO drivers to the new PM macros. Lee, if this patchset gets merged to
the MFD tree, could you then create an immutable branch for Jonathan?

Changes:
- [01/30] is new and adds the reworked PM macros.
- [12/30] now only modifies intel_soc_pmic_core.c since Andy updated
the other file.
- [21/30] uses the new EXPORT_GPL_DEV_PM_OPS() macro instead of the
trickery that was used before.
- [26/30] removes a CONFIG_PM wrapper around fields in private struct
- [27/30] removes a duplicated "const".
- [30/30] is new, and updates the intel-lpss driver.
- All patches: Reworded the last paragraph, hide the Cc's, remove
the Cc to Bartlomiej's email address.

Cheers,
-Paul

Paul Cercueil (30):
pm: Improve EXPORT_*_DEV_PM_OPS macros
mfd: 88pm80x: Remove #ifdef guards for PM related functions
mfd: aat2870: Remove #ifdef guards for PM related functions
mfd: adp5520: Remove #ifdef guards for PM related functions
mfd: max8925-i2c: Remove #ifdef guards for PM related functions
mfd: mt6397-irq: Remove #ifdef guards for PM related functions
mfd: pcf50633: Remove #ifdef guards for PM related functions
mfd: rc5t583-irq: Remove #ifdef guards for PM related functions
mfd: stpmic1: Remove #ifdef guards for PM related functions
mfd: ucb1x00: Remove #ifdef guards for PM related functions
mfd: 88pm860x: Remove #ifdef guards for PM related functions
mfd: intel_soc_pmic: Remove #ifdef guards for PM related functions
mfd: mcp-sa11x0: Remove #ifdef guards for PM related functions
mfd: sec: Remove #ifdef guards for PM related functions
mfd: sm501: Remove #ifdef guards for PM related functions
mfd: tc6387xb: Remove #ifdef guards for PM related functions
mfd: tps6586x: Remove #ifdef guards for PM related functions
mfd: wm8994: Remove #ifdef guards for PM related functions
mfd: max77620: Remove #ifdef guards for PM related functions
mfd: t7l66xb: Remove #ifdef guards for PM related functions
mfd: arizona: Remove #ifdef guards for PM related functions
mfd: max14577: Remove #ifdef guards for PM related functions
mfd: max77686: Remove #ifdef guards for PM related functions
mfd: motorola-cpcap: Remove #ifdef guards for PM related functions
mfd: sprd-sc27xx: Remove #ifdef guards for PM related functions
mfd: stmfx: Remove #ifdef guards for PM related functions
mfd: stmpe: Remove #ifdef guards for PM related functions
mfd: tc3589x: Remove #ifdef guards for PM related functions
mfd: tc6393xb: Remove #ifdef guards for PM related functions
mfd: intel-lpss: Remove #ifdef guards for PM related functions

drivers/mfd/88pm800.c | 2 +-
drivers/mfd/88pm805.c | 2 +-
drivers/mfd/88pm80x.c | 5 +----
drivers/mfd/88pm860x-core.c | 6 ++---
drivers/mfd/aat2870-core.c | 8 +++----
drivers/mfd/adp5520.c | 6 ++---
drivers/mfd/arizona-core.c | 19 ++++++----------
drivers/mfd/arizona-i2c.c | 2 +-
drivers/mfd/arizona-spi.c | 2 +-
drivers/mfd/intel-lpss-acpi.c | 4 +---
drivers/mfd/intel-lpss-pci.c | 4 +---
drivers/mfd/intel-lpss.c | 15 ++++++++-----
drivers/mfd/intel-lpss.h | 28 +----------------------
drivers/mfd/intel_soc_pmic_core.c | 8 +++----
drivers/mfd/max14577.c | 6 ++---
drivers/mfd/max77620.c | 9 +++-----
drivers/mfd/max77686.c | 6 ++---
drivers/mfd/max8925-i2c.c | 7 +++---
drivers/mfd/mcp-sa11x0.c | 6 +----
drivers/mfd/motorola-cpcap.c | 6 ++---
drivers/mfd/mt6397-irq.c | 6 +----
drivers/mfd/pcf50633-core.c | 22 +-----------------
drivers/mfd/pcf50633-irq.c | 13 ++++++-----
drivers/mfd/rc5t583-irq.c | 7 ++----
drivers/mfd/sec-core.c | 7 +++---
drivers/mfd/sm501.c | 10 ++-------
drivers/mfd/sprd-sc27xx-spi.c | 7 +++---
drivers/mfd/stmfx.c | 6 ++---
drivers/mfd/stmpe-i2c.c | 4 +---
drivers/mfd/stmpe-spi.c | 4 +---
drivers/mfd/stmpe.c | 8 ++-----
drivers/mfd/stpmic1.c | 6 ++---
drivers/mfd/t7l66xb.c | 9 ++------
drivers/mfd/tc3589x.c | 7 +++---
drivers/mfd/tc6387xb.c | 9 ++------
drivers/mfd/tc6393xb.c | 9 ++------
drivers/mfd/tps6586x.c | 6 +----
drivers/mfd/ucb1x00-core.c | 7 +++---
drivers/mfd/wm8994-core.c | 6 ++---
include/linux/mfd/pcf50633/core.h | 6 ++---
include/linux/mfd/stmfx.h | 2 --
include/linux/pm.h | 37 +++++++++++++++++++------------
include/linux/pm_runtime.h | 20 ++++++++++-------
43 files changed, 127 insertions(+), 242 deletions(-)

---
Cc: Jonathan Cameron <[email protected]>
Cc: Rafael J. Wysocki <[email protected]>
Cc: linux-pm <[email protected]>
--
2.35.1


2022-08-08 18:03:29

by Paul Cercueil

[permalink] [raw]
Subject: [PATCH v2 18/30] mfd: wm8994: Remove #ifdef guards for PM related functions

Use the new RUNTIME_PM_OPS() and pm_ptr() macros to handle the
.runtime_suspend/.runtime_resume callbacks.

These macros allow the suspend and resume functions to be automatically
dropped by the compiler when CONFIG_PM is disabled, without having
to use #ifdef guards.

This has the advantage of always compiling these functions in,
independently of any Kconfig option. Thanks to that, bugs and other
regressions are subsequently easier to catch.

Note that this driver should probably use the new
DEFINE_RUNTIME_DEV_PM_OPS() macro instead, which will provide
.suspend/.resume callbacks, pointing to pm_runtime_force_suspend() and
pm_runtime_force_resume() respectively; unless those callbacks really
aren't needed.

Signed-off-by: Paul Cercueil <[email protected]>
---
Cc: [email protected]

drivers/mfd/wm8994-core.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/mfd/wm8994-core.c b/drivers/mfd/wm8994-core.c
index 7b1d270722ba..a27a13b5ae1e 100644
--- a/drivers/mfd/wm8994-core.c
+++ b/drivers/mfd/wm8994-core.c
@@ -110,7 +110,6 @@ static const char *wm8958_main_supplies[] = {
"SPKVDD2",
};

-#ifdef CONFIG_PM
static int wm8994_suspend(struct device *dev)
{
struct wm8994 *wm8994 = dev_get_drvdata(dev);
@@ -213,7 +212,6 @@ static int wm8994_resume(struct device *dev)

return ret;
}
-#endif

#ifdef CONFIG_REGULATOR
static int wm8994_ldo_in_use(struct wm8994_pdata *pdata, int ldo)
@@ -676,13 +674,13 @@ static const struct i2c_device_id wm8994_i2c_id[] = {
MODULE_DEVICE_TABLE(i2c, wm8994_i2c_id);

static const struct dev_pm_ops wm8994_pm_ops = {
- SET_RUNTIME_PM_OPS(wm8994_suspend, wm8994_resume, NULL)
+ RUNTIME_PM_OPS(wm8994_suspend, wm8994_resume, NULL)
};

static struct i2c_driver wm8994_i2c_driver = {
.driver = {
.name = "wm8994",
- .pm = &wm8994_pm_ops,
+ .pm = pm_ptr(&wm8994_pm_ops),
.of_match_table = wm8994_of_match,
},
.probe = wm8994_i2c_probe,
--
2.35.1

2022-08-08 18:03:33

by Paul Cercueil

[permalink] [raw]
Subject: [PATCH v2 08/30] mfd: rc5t583-irq: Remove #ifdef guards for PM related functions

Use the new pm_sleep_ptr() macro to handle the .irq_set_wake() callback.

This macro allows the mt6397_irq_set_wake() function to be automatically
dropped by the compiler when CONFIG_SUSPEND is disabled, without having
to use #ifdef guards.

This has the advantage of always compiling these functions in,
independently of any Kconfig option. Thanks to that, bugs and other
regressions are subsequently easier to catch.

Signed-off-by: Paul Cercueil <[email protected]>
---
drivers/mfd/rc5t583-irq.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/mfd/rc5t583-irq.c b/drivers/mfd/rc5t583-irq.c
index b374a3d34688..621ea61fa7c6 100644
--- a/drivers/mfd/rc5t583-irq.c
+++ b/drivers/mfd/rc5t583-irq.c
@@ -228,15 +228,12 @@ static void rc5t583_irq_sync_unlock(struct irq_data *irq_data)

mutex_unlock(&rc5t583->irq_lock);
}
-#ifdef CONFIG_PM_SLEEP
+
static int rc5t583_irq_set_wake(struct irq_data *irq_data, unsigned int on)
{
struct rc5t583 *rc5t583 = irq_data_get_irq_chip_data(irq_data);
return irq_set_irq_wake(rc5t583->chip_irq, on);
}
-#else
-#define rc5t583_irq_set_wake NULL
-#endif

static irqreturn_t rc5t583_irq(int irq, void *data)
{
@@ -317,7 +314,7 @@ static struct irq_chip rc5t583_irq_chip = {
.irq_bus_lock = rc5t583_irq_lock,
.irq_bus_sync_unlock = rc5t583_irq_sync_unlock,
.irq_set_type = rc5t583_irq_set_type,
- .irq_set_wake = rc5t583_irq_set_wake,
+ .irq_set_wake = pm_sleep_ptr(rc5t583_irq_set_wake),
};

int rc5t583_irq_init(struct rc5t583 *rc5t583, int irq, int irq_base)
--
2.35.1

2022-08-08 18:04:41

by Paul Cercueil

[permalink] [raw]
Subject: [PATCH v2 27/30] mfd: stmpe: Remove #ifdef guards for PM related functions

Use the new EXPORT_GPL_SIMPLE_DEV_PM_OPS() and pm_sleep_ptr() macros
to handle the .suspend/.resume callbacks.

These macros allow the suspend and resume functions to be automatically
dropped by the compiler when CONFIG_SUSPEND is disabled, without having
to use #ifdef guards.

This has the advantage of always compiling these functions in,
independently of any Kconfig option. Thanks to that, bugs and other
regressions are subsequently easier to catch.

Signed-off-by: Paul Cercueil <[email protected]>
---

V2: remove duplicated "const".

Cc: Maxime Coquelin <[email protected]>
Cc: Alexandre Torgue <[email protected]>
Cc: [email protected]
Cc: [email protected]

drivers/mfd/stmpe-i2c.c | 4 +---
drivers/mfd/stmpe-spi.c | 4 +---
drivers/mfd/stmpe.c | 8 ++------
3 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/drivers/mfd/stmpe-i2c.c b/drivers/mfd/stmpe-i2c.c
index d3eedf3d607e..bf094cc9f9de 100644
--- a/drivers/mfd/stmpe-i2c.c
+++ b/drivers/mfd/stmpe-i2c.c
@@ -116,9 +116,7 @@ MODULE_DEVICE_TABLE(i2c, stmpe_i2c_id);
static struct i2c_driver stmpe_i2c_driver = {
.driver = {
.name = "stmpe-i2c",
-#ifdef CONFIG_PM
- .pm = &stmpe_dev_pm_ops,
-#endif
+ .pm = pm_sleep_ptr(&stmpe_dev_pm_ops),
.of_match_table = stmpe_of_match,
},
.probe = stmpe_i2c_probe,
diff --git a/drivers/mfd/stmpe-spi.c b/drivers/mfd/stmpe-spi.c
index ad8055a0e286..e9cbf33502b3 100644
--- a/drivers/mfd/stmpe-spi.c
+++ b/drivers/mfd/stmpe-spi.c
@@ -135,9 +135,7 @@ static struct spi_driver stmpe_spi_driver = {
.driver = {
.name = "stmpe-spi",
.of_match_table = of_match_ptr(stmpe_spi_of_match),
-#ifdef CONFIG_PM
- .pm = &stmpe_dev_pm_ops,
-#endif
+ .pm = pm_sleep_ptr(&stmpe_dev_pm_ops),
},
.probe = stmpe_spi_probe,
.remove = stmpe_spi_remove,
diff --git a/drivers/mfd/stmpe.c b/drivers/mfd/stmpe.c
index aeb9ea55f97d..89ffd5a7fab8 100644
--- a/drivers/mfd/stmpe.c
+++ b/drivers/mfd/stmpe.c
@@ -1508,7 +1508,6 @@ void stmpe_remove(struct stmpe *stmpe)
mfd_remove_devices(stmpe->dev);
}

-#ifdef CONFIG_PM
static int stmpe_suspend(struct device *dev)
{
struct stmpe *stmpe = dev_get_drvdata(dev);
@@ -1529,8 +1528,5 @@ static int stmpe_resume(struct device *dev)
return 0;
}

-const struct dev_pm_ops stmpe_dev_pm_ops = {
- .suspend = stmpe_suspend,
- .resume = stmpe_resume,
-};
-#endif
+EXPORT_GPL_SIMPLE_DEV_PM_OPS(stmpe_dev_pm_ops,
+ stmpe_suspend, stmpe_resume);
--
2.35.1

2022-08-08 18:16:51

by Paul Cercueil

[permalink] [raw]
Subject: [PATCH v2 02/30] mfd: 88pm80x: Remove #ifdef guards for PM related functions

Use the new EXPORT_GPL_SIMPLE_DEV_PM_OPS() and pm_sleep_ptr() macros
to handle the .suspend/.resume callbacks.

These macros allow the suspend and resume functions to be automatically
dropped by the compiler when CONFIG_SUSPEND is disabled, without having
to use #ifdef guards.

This has the advantage of always compiling these functions in,
independently of any Kconfig option. Thanks to that, bugs and other
regressions are subsequently easier to catch.

Signed-off-by: Paul Cercueil <[email protected]>
---
drivers/mfd/88pm800.c | 2 +-
drivers/mfd/88pm805.c | 2 +-
drivers/mfd/88pm80x.c | 5 +----
3 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/mfd/88pm800.c b/drivers/mfd/88pm800.c
index eaf9845633b4..409f0996ae1d 100644
--- a/drivers/mfd/88pm800.c
+++ b/drivers/mfd/88pm800.c
@@ -599,7 +599,7 @@ static int pm800_remove(struct i2c_client *client)
static struct i2c_driver pm800_driver = {
.driver = {
.name = "88PM800",
- .pm = &pm80x_pm_ops,
+ .pm = pm_sleep_ptr(&pm80x_pm_ops),
},
.probe = pm800_probe,
.remove = pm800_remove,
diff --git a/drivers/mfd/88pm805.c b/drivers/mfd/88pm805.c
index ada6c513302b..724ac4947e6f 100644
--- a/drivers/mfd/88pm805.c
+++ b/drivers/mfd/88pm805.c
@@ -254,7 +254,7 @@ static int pm805_remove(struct i2c_client *client)
static struct i2c_driver pm805_driver = {
.driver = {
.name = "88PM805",
- .pm = &pm80x_pm_ops,
+ .pm = pm_sleep_ptr(&pm80x_pm_ops),
},
.probe = pm805_probe,
.remove = pm805_remove,
diff --git a/drivers/mfd/88pm80x.c b/drivers/mfd/88pm80x.c
index be036e7e787b..ac4f08565f29 100644
--- a/drivers/mfd/88pm80x.c
+++ b/drivers/mfd/88pm80x.c
@@ -129,7 +129,6 @@ int pm80x_deinit(void)
}
EXPORT_SYMBOL_GPL(pm80x_deinit);

-#ifdef CONFIG_PM_SLEEP
static int pm80x_suspend(struct device *dev)
{
struct i2c_client *client = to_i2c_client(dev);
@@ -153,10 +152,8 @@ static int pm80x_resume(struct device *dev)

return 0;
}
-#endif

-SIMPLE_DEV_PM_OPS(pm80x_pm_ops, pm80x_suspend, pm80x_resume);
-EXPORT_SYMBOL_GPL(pm80x_pm_ops);
+EXPORT_GPL_SIMPLE_DEV_PM_OPS(pm80x_pm_ops, pm80x_suspend, pm80x_resume);

MODULE_DESCRIPTION("I2C Driver for Marvell 88PM80x");
MODULE_AUTHOR("Qiao Zhou <[email protected]>");
--
2.35.1

2022-08-08 18:17:02

by Paul Cercueil

[permalink] [raw]
Subject: [PATCH v2 06/30] mfd: mt6397-irq: Remove #ifdef guards for PM related functions

Use the new pm_sleep_ptr() macro to handle the .irq_set_wake() callback.

This macro allows the mt6397_irq_set_wake() function to be automatically
dropped by the compiler when CONFIG_SUSPEND is disabled, without having
to use #ifdef guards.

This has the advantage of always compiling these functions in,
independently of any Kconfig option. Thanks to that, bugs and other
regressions are subsequently easier to catch.

Signed-off-by: Paul Cercueil <[email protected]>
---
Cc: Matthias Brugger <[email protected]>
Cc: [email protected]
Cc: [email protected]

drivers/mfd/mt6397-irq.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/mfd/mt6397-irq.c b/drivers/mfd/mt6397-irq.c
index eff53fed8fe7..72f923e47752 100644
--- a/drivers/mfd/mt6397-irq.c
+++ b/drivers/mfd/mt6397-irq.c
@@ -54,7 +54,6 @@ static void mt6397_irq_enable(struct irq_data *data)
mt6397->irq_masks_cur[reg] |= BIT(shift);
}

-#ifdef CONFIG_PM_SLEEP
static int mt6397_irq_set_wake(struct irq_data *irq_data, unsigned int on)
{
struct mt6397_chip *mt6397 = irq_data_get_irq_chip_data(irq_data);
@@ -68,9 +67,6 @@ static int mt6397_irq_set_wake(struct irq_data *irq_data, unsigned int on)

return 0;
}
-#else
-#define mt6397_irq_set_wake NULL
-#endif

static struct irq_chip mt6397_irq_chip = {
.name = "mt6397-irq",
@@ -78,7 +74,7 @@ static struct irq_chip mt6397_irq_chip = {
.irq_bus_sync_unlock = mt6397_irq_sync_unlock,
.irq_enable = mt6397_irq_enable,
.irq_disable = mt6397_irq_disable,
- .irq_set_wake = mt6397_irq_set_wake,
+ .irq_set_wake = pm_sleep_ptr(mt6397_irq_set_wake),
};

static void mt6397_irq_handle_reg(struct mt6397_chip *mt6397, int reg,
--
2.35.1

2022-08-08 18:17:04

by Paul Cercueil

[permalink] [raw]
Subject: [PATCH v2 15/30] mfd: sm501: Remove #ifdef guards for PM related functions

Use the new pm_sleep_ptr() macro to handle the .suspend/.resume
callbacks.

This macro allow the suspend and resume functions to be automatically
dropped by the compiler when CONFIG_SUSPEND is disabled, without having
to use #ifdef guards.

This has the advantage of always compiling these functions in,
independently of any Kconfig option. Thanks to that, bugs and other
regressions are subsequently easier to catch.

Signed-off-by: Paul Cercueil <[email protected]>
---
drivers/mfd/sm501.c | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/mfd/sm501.c b/drivers/mfd/sm501.c
index bc0a2c38653e..81e15e646e77 100644
--- a/drivers/mfd/sm501.c
+++ b/drivers/mfd/sm501.c
@@ -1432,8 +1432,6 @@ static int sm501_plat_probe(struct platform_device *dev)

}

-#ifdef CONFIG_PM
-
/* power management support */

static void sm501_set_power(struct sm501_devdata *sm, int on)
@@ -1509,10 +1507,6 @@ static int sm501_plat_resume(struct platform_device *pdev)

return 0;
}
-#else
-#define sm501_plat_suspend NULL
-#define sm501_plat_resume NULL
-#endif

/* Initialisation data for PCI devices */

@@ -1714,8 +1708,8 @@ static struct platform_driver sm501_plat_driver = {
},
.probe = sm501_plat_probe,
.remove = sm501_plat_remove,
- .suspend = sm501_plat_suspend,
- .resume = sm501_plat_resume,
+ .suspend = pm_sleep_ptr(sm501_plat_suspend),
+ .resume = pm_sleep_ptr(sm501_plat_resume),
};

static int __init sm501_base_init(void)
--
2.35.1

2022-08-08 18:17:30

by Paul Cercueil

[permalink] [raw]
Subject: [PATCH v2 05/30] mfd: max8925-i2c: Remove #ifdef guards for PM related functions

Use the new DEFINE_SIMPLE_DEV_PM_OPS() and pm_sleep_ptr() macros
to handle the .suspend/.resume callbacks.

These macros allow the suspend and resume functions to be automatically
dropped by the compiler when CONFIG_SUSPEND is disabled, without having
to use #ifdef guards.

This has the advantage of always compiling these functions in,
independently of any Kconfig option. Thanks to that, bugs and other
regressions are subsequently easier to catch.

Signed-off-by: Paul Cercueil <[email protected]>
---
drivers/mfd/max8925-i2c.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
index 114e905bef25..649310b5bb3e 100644
--- a/drivers/mfd/max8925-i2c.c
+++ b/drivers/mfd/max8925-i2c.c
@@ -208,7 +208,6 @@ static int max8925_remove(struct i2c_client *client)
return 0;
}

-#ifdef CONFIG_PM_SLEEP
static int max8925_suspend(struct device *dev)
{
struct i2c_client *client = to_i2c_client(dev);
@@ -228,9 +227,9 @@ static int max8925_resume(struct device *dev)
disable_irq_wake(chip->core_irq);
return 0;
}
-#endif

-static SIMPLE_DEV_PM_OPS(max8925_pm_ops, max8925_suspend, max8925_resume);
+static DEFINE_SIMPLE_DEV_PM_OPS(max8925_pm_ops,
+ max8925_suspend, max8925_resume);

static const struct of_device_id max8925_dt_ids[] = {
{ .compatible = "maxim,max8925", },
@@ -240,7 +239,7 @@ static const struct of_device_id max8925_dt_ids[] = {
static struct i2c_driver max8925_driver = {
.driver = {
.name = "max8925",
- .pm = &max8925_pm_ops,
+ .pm = pm_sleep_ptr(&max8925_pm_ops),
.of_match_table = max8925_dt_ids,
},
.probe = max8925_probe,
--
2.35.1

2022-08-08 18:18:39

by Paul Cercueil

[permalink] [raw]
Subject: [PATCH v2 14/30] mfd: sec: Remove #ifdef guards for PM related functions

Use the new DEFINE_SIMPLE_DEV_PM_OPS() and pm_sleep_ptr() macros
to handle the .suspend/.resume callbacks.

These macros allow the suspend and resume functions to be automatically
dropped by the compiler when CONFIG_SUSPEND is disabled, without having
to use #ifdef guards.

This has the advantage of always compiling these functions in,
independently of any Kconfig option. Thanks to that, bugs and other
regressions are subsequently easier to catch.

Signed-off-by: Paul Cercueil <[email protected]>
Reviewed-by: Krzysztof Kozlowski <[email protected]>
---
Cc: Krzysztof Kozlowski <[email protected]>
Cc: [email protected]

drivers/mfd/sec-core.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/mfd/sec-core.c b/drivers/mfd/sec-core.c
index 1fb29c45f5cf..a467de2b2fea 100644
--- a/drivers/mfd/sec-core.c
+++ b/drivers/mfd/sec-core.c
@@ -455,7 +455,6 @@ static void sec_pmic_shutdown(struct i2c_client *i2c)
regmap_update_bits(sec_pmic->regmap_pmic, reg, mask, 0);
}

-#ifdef CONFIG_PM_SLEEP
static int sec_pmic_suspend(struct device *dev)
{
struct i2c_client *i2c = to_i2c_client(dev);
@@ -488,14 +487,14 @@ static int sec_pmic_resume(struct device *dev)

return 0;
}
-#endif /* CONFIG_PM_SLEEP */

-static SIMPLE_DEV_PM_OPS(sec_pmic_pm_ops, sec_pmic_suspend, sec_pmic_resume);
+static DEFINE_SIMPLE_DEV_PM_OPS(sec_pmic_pm_ops,
+ sec_pmic_suspend, sec_pmic_resume);

static struct i2c_driver sec_pmic_driver = {
.driver = {
.name = "sec_pmic",
- .pm = &sec_pmic_pm_ops,
+ .pm = pm_sleep_ptr(&sec_pmic_pm_ops),
.of_match_table = sec_dt_match,
},
.probe = sec_pmic_probe,
--
2.35.1

2022-08-08 18:19:31

by Paul Cercueil

[permalink] [raw]
Subject: [PATCH v2 07/30] mfd: pcf50633: Remove #ifdef guards for PM related functions

Use the new EXPORT_GPL_SIMPLE_DEV_PM_OPS() and pm_sleep_ptr() macros
to handle the .suspend/.resume callbacks.

These macros allow the suspend and resume functions to be automatically
dropped by the compiler when CONFIG_SUSPEND is disabled, without having
to use #ifdef guards.

This has the advantage of always compiling these functions in,
independently of any Kconfig option. Thanks to that, bugs and other
regressions are subsequently easier to catch.

Signed-off-by: Paul Cercueil <[email protected]>
---
drivers/mfd/pcf50633-core.c | 22 +---------------------
drivers/mfd/pcf50633-irq.c | 13 ++++++++-----
include/linux/mfd/pcf50633/core.h | 6 ++----
3 files changed, 11 insertions(+), 30 deletions(-)

diff --git a/drivers/mfd/pcf50633-core.c b/drivers/mfd/pcf50633-core.c
index e9c565cf0f54..06d750d9a476 100644
--- a/drivers/mfd/pcf50633-core.c
+++ b/drivers/mfd/pcf50633-core.c
@@ -158,26 +158,6 @@ pcf50633_client_dev_register(struct pcf50633 *pcf, const char *name,
}
}

-#ifdef CONFIG_PM_SLEEP
-static int pcf50633_suspend(struct device *dev)
-{
- struct i2c_client *client = to_i2c_client(dev);
- struct pcf50633 *pcf = i2c_get_clientdata(client);
-
- return pcf50633_irq_suspend(pcf);
-}
-
-static int pcf50633_resume(struct device *dev)
-{
- struct i2c_client *client = to_i2c_client(dev);
- struct pcf50633 *pcf = i2c_get_clientdata(client);
-
- return pcf50633_irq_resume(pcf);
-}
-#endif
-
-static SIMPLE_DEV_PM_OPS(pcf50633_pm, pcf50633_suspend, pcf50633_resume);
-
static const struct regmap_config pcf50633_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
@@ -302,7 +282,7 @@ MODULE_DEVICE_TABLE(i2c, pcf50633_id_table);
static struct i2c_driver pcf50633_driver = {
.driver = {
.name = "pcf50633",
- .pm = &pcf50633_pm,
+ .pm = pm_sleep_ptr(&pcf50633_pm),
},
.id_table = pcf50633_id_table,
.probe = pcf50633_probe,
diff --git a/drivers/mfd/pcf50633-irq.c b/drivers/mfd/pcf50633-irq.c
index 2096afb0ce9b..e85af7f1cb0b 100644
--- a/drivers/mfd/pcf50633-irq.c
+++ b/drivers/mfd/pcf50633-irq.c
@@ -7,6 +7,7 @@
* All rights reserved.
*/

+#include <linux/i2c.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/mutex.h>
@@ -218,10 +219,10 @@ static irqreturn_t pcf50633_irq(int irq, void *data)
return IRQ_HANDLED;
}

-#ifdef CONFIG_PM
-
-int pcf50633_irq_suspend(struct pcf50633 *pcf)
+static int pcf50633_suspend(struct device *dev)
{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct pcf50633 *pcf = i2c_get_clientdata(client);
int ret;
int i;
u8 res[5];
@@ -257,8 +258,10 @@ int pcf50633_irq_suspend(struct pcf50633 *pcf)
return ret;
}

-int pcf50633_irq_resume(struct pcf50633 *pcf)
+static int pcf50633_resume(struct device *dev)
{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct pcf50633 *pcf = i2c_get_clientdata(client);
int ret;

/* Write the saved mask registers */
@@ -273,7 +276,7 @@ int pcf50633_irq_resume(struct pcf50633 *pcf)
return ret;
}

-#endif
+EXPORT_GPL_SIMPLE_DEV_PM_OPS(pcf50633_pm, pcf50633_suspend, pcf50633_resume);

int pcf50633_irq_init(struct pcf50633 *pcf, int irq)
{
diff --git a/include/linux/mfd/pcf50633/core.h b/include/linux/mfd/pcf50633/core.h
index 3f752dc62a6c..539f27f8bd89 100644
--- a/include/linux/mfd/pcf50633/core.h
+++ b/include/linux/mfd/pcf50633/core.h
@@ -13,6 +13,7 @@
#include <linux/workqueue.h>
#include <linux/regulator/driver.h>
#include <linux/regulator/machine.h>
+#include <linux/pm.h>
#include <linux/power_supply.h>
#include <linux/mfd/pcf50633/backlight.h>

@@ -226,9 +227,6 @@ static inline struct pcf50633 *dev_to_pcf50633(struct device *dev)

int pcf50633_irq_init(struct pcf50633 *pcf, int irq);
void pcf50633_irq_free(struct pcf50633 *pcf);
-#ifdef CONFIG_PM
-int pcf50633_irq_suspend(struct pcf50633 *pcf);
-int pcf50633_irq_resume(struct pcf50633 *pcf);
-#endif
+extern const struct dev_pm_ops pcf50633_pm;

#endif
--
2.35.1

2022-08-13 14:46:55

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH v2 00/30] mfd: Remove #ifdef guards for PM functions

On Mon, 8 Aug 2022 19:40:37 +0200
Paul Cercueil <[email protected]> wrote:

> Hi Lee,
>
> Here's my revised patchset updated from the feedback I got in V1.
> This one is based on the current mfd-next-5.20.
>
> I updated the PM macros in <linux/pm.h> and <linux/pm_runtime.h>, to
> make them more versatile. They now allow to conditionally export
> arbitrary dev_pm_ops structures. This is used in the "arizona" driver
> for instance, which has "noirq" callbacks.
>
> I Cc'd Jonathan, whom might be interested by the PM patch to convert the
> IIO drivers to the new PM macros. Lee, if this patchset gets merged to
> the MFD tree, could you then create an immutable branch for Jonathan?

That would be much appreciated. Ideally the immutable branch would just
contain patch 1. If it doesn't work out that way I can always pick up
the half dozen cases that would use the new infrastructure next cycle.

Thanks!

Jonathan
>
> Changes:
> - [01/30] is new and adds the reworked PM macros.
> - [12/30] now only modifies intel_soc_pmic_core.c since Andy updated
> the other file.
> - [21/30] uses the new EXPORT_GPL_DEV_PM_OPS() macro instead of the
> trickery that was used before.
> - [26/30] removes a CONFIG_PM wrapper around fields in private struct
> - [27/30] removes a duplicated "const".
> - [30/30] is new, and updates the intel-lpss driver.
> - All patches: Reworded the last paragraph, hide the Cc's, remove
> the Cc to Bartlomiej's email address.
>
> Cheers,
> -Paul
>
> Paul Cercueil (30):
> pm: Improve EXPORT_*_DEV_PM_OPS macros
> mfd: 88pm80x: Remove #ifdef guards for PM related functions
> mfd: aat2870: Remove #ifdef guards for PM related functions
> mfd: adp5520: Remove #ifdef guards for PM related functions
> mfd: max8925-i2c: Remove #ifdef guards for PM related functions
> mfd: mt6397-irq: Remove #ifdef guards for PM related functions
> mfd: pcf50633: Remove #ifdef guards for PM related functions
> mfd: rc5t583-irq: Remove #ifdef guards for PM related functions
> mfd: stpmic1: Remove #ifdef guards for PM related functions
> mfd: ucb1x00: Remove #ifdef guards for PM related functions
> mfd: 88pm860x: Remove #ifdef guards for PM related functions
> mfd: intel_soc_pmic: Remove #ifdef guards for PM related functions
> mfd: mcp-sa11x0: Remove #ifdef guards for PM related functions
> mfd: sec: Remove #ifdef guards for PM related functions
> mfd: sm501: Remove #ifdef guards for PM related functions
> mfd: tc6387xb: Remove #ifdef guards for PM related functions
> mfd: tps6586x: Remove #ifdef guards for PM related functions
> mfd: wm8994: Remove #ifdef guards for PM related functions
> mfd: max77620: Remove #ifdef guards for PM related functions
> mfd: t7l66xb: Remove #ifdef guards for PM related functions
> mfd: arizona: Remove #ifdef guards for PM related functions
> mfd: max14577: Remove #ifdef guards for PM related functions
> mfd: max77686: Remove #ifdef guards for PM related functions
> mfd: motorola-cpcap: Remove #ifdef guards for PM related functions
> mfd: sprd-sc27xx: Remove #ifdef guards for PM related functions
> mfd: stmfx: Remove #ifdef guards for PM related functions
> mfd: stmpe: Remove #ifdef guards for PM related functions
> mfd: tc3589x: Remove #ifdef guards for PM related functions
> mfd: tc6393xb: Remove #ifdef guards for PM related functions
> mfd: intel-lpss: Remove #ifdef guards for PM related functions
>
> drivers/mfd/88pm800.c | 2 +-
> drivers/mfd/88pm805.c | 2 +-
> drivers/mfd/88pm80x.c | 5 +----
> drivers/mfd/88pm860x-core.c | 6 ++---
> drivers/mfd/aat2870-core.c | 8 +++----
> drivers/mfd/adp5520.c | 6 ++---
> drivers/mfd/arizona-core.c | 19 ++++++----------
> drivers/mfd/arizona-i2c.c | 2 +-
> drivers/mfd/arizona-spi.c | 2 +-
> drivers/mfd/intel-lpss-acpi.c | 4 +---
> drivers/mfd/intel-lpss-pci.c | 4 +---
> drivers/mfd/intel-lpss.c | 15 ++++++++-----
> drivers/mfd/intel-lpss.h | 28 +----------------------
> drivers/mfd/intel_soc_pmic_core.c | 8 +++----
> drivers/mfd/max14577.c | 6 ++---
> drivers/mfd/max77620.c | 9 +++-----
> drivers/mfd/max77686.c | 6 ++---
> drivers/mfd/max8925-i2c.c | 7 +++---
> drivers/mfd/mcp-sa11x0.c | 6 +----
> drivers/mfd/motorola-cpcap.c | 6 ++---
> drivers/mfd/mt6397-irq.c | 6 +----
> drivers/mfd/pcf50633-core.c | 22 +-----------------
> drivers/mfd/pcf50633-irq.c | 13 ++++++-----
> drivers/mfd/rc5t583-irq.c | 7 ++----
> drivers/mfd/sec-core.c | 7 +++---
> drivers/mfd/sm501.c | 10 ++-------
> drivers/mfd/sprd-sc27xx-spi.c | 7 +++---
> drivers/mfd/stmfx.c | 6 ++---
> drivers/mfd/stmpe-i2c.c | 4 +---
> drivers/mfd/stmpe-spi.c | 4 +---
> drivers/mfd/stmpe.c | 8 ++-----
> drivers/mfd/stpmic1.c | 6 ++---
> drivers/mfd/t7l66xb.c | 9 ++------
> drivers/mfd/tc3589x.c | 7 +++---
> drivers/mfd/tc6387xb.c | 9 ++------
> drivers/mfd/tc6393xb.c | 9 ++------
> drivers/mfd/tps6586x.c | 6 +----
> drivers/mfd/ucb1x00-core.c | 7 +++---
> drivers/mfd/wm8994-core.c | 6 ++---
> include/linux/mfd/pcf50633/core.h | 6 ++---
> include/linux/mfd/stmfx.h | 2 --
> include/linux/pm.h | 37 +++++++++++++++++++------------
> include/linux/pm_runtime.h | 20 ++++++++++-------
> 43 files changed, 127 insertions(+), 242 deletions(-)
>
> ---
> Cc: Jonathan Cameron <[email protected]>
> Cc: Rafael J. Wysocki <[email protected]>
> Cc: linux-pm <[email protected]>

2022-08-22 10:07:19

by Charles Keepax

[permalink] [raw]
Subject: Re: [PATCH v2 18/30] mfd: wm8994: Remove #ifdef guards for PM related functions

On Mon, Aug 08, 2022 at 07:40:55PM +0200, Paul Cercueil wrote:
> Use the new RUNTIME_PM_OPS() and pm_ptr() macros to handle the
> .runtime_suspend/.runtime_resume callbacks.
>
> These macros allow the suspend and resume functions to be automatically
> dropped by the compiler when CONFIG_PM is disabled, without having
> to use #ifdef guards.
>
> This has the advantage of always compiling these functions in,
> independently of any Kconfig option. Thanks to that, bugs and other
> regressions are subsequently easier to catch.
>
> Note that this driver should probably use the new
> DEFINE_RUNTIME_DEV_PM_OPS() macro instead, which will provide
> .suspend/.resume callbacks, pointing to pm_runtime_force_suspend() and
> pm_runtime_force_resume() respectively; unless those callbacks really
> aren't needed.
>
> Signed-off-by: Paul Cercueil <[email protected]>
> ---

Acked-by: Charles Keepax <[email protected]>

Thanks,
Charles