2023-07-05 21:16:14

by Paul Cercueil

[permalink] [raw]
Subject: [PATCH 00/23] i2c: Use new PM macros

Hi Wolfram,

This patchset converts the I2C subsystem to use the PM macros that were
introduced in v5.17, which allow the dev_pm_ops and related callbacks to
be automatically dropped by the compiler when CONFIG_PM or
CONFIG_PM_SLEEP are disabled, without having to use #ifdef guards.

The point of this, is that all this code is now compiled independently
of any Kconfig option, which makes bugs and regressions easier to catch.

This continues the work that has been started in other subsystems (DRM,
IIO, watchdog).

As an added bonus, the diff is 71+/192-, that means less code you will
have to maintain ;)

The patches generally don't change the behaviour, with a few exceptions,
that are documented in the corresponding patches.

I would like to draw the attention to a few patches in particular:

- [01/23] the driver most likely does something that it shouldn't do
(use the same callbacks for runtime PM and system PM). The patch does
not change this behaviour but I have questions.

- [11/23] uses platform_driver.{suspend,resume} instead of the regular
.driver.pm. I have no idea why it does that and I believe it doesn't
really have to.

- [18/23] I feel like the qup_i2c_suspend / qup_i2c_resume don't really
need to exist, and the pm_runtime_force_suspend() /
pm_runtime_force_resume() helpers should be used instead, using the
DEFINE_RUNTIME_DEV_PM_OPS() macro.

Cheers,
-Paul

Paul Cercueil (23):
i2c: amd-mp2: Remove #ifdef guards for PM related functions
i2c: au1550: Remove #ifdef guards for PM related functions
i2c: iproc: Remove #ifdef guards for PM related functions
i2c: brcmstb: Remove #ifdef guards for PM related functions
i2c: davinci: Remove #ifdef guards for PM related functions
i2c: designware: Remove #ifdef guards for PM related functions
i2c: exynos5: Remove #ifdef guards for PM related functions
i2c: hix5hd2: Remove #ifdef guards for PM related functions
i2c: i801: Remove #ifdef guards for PM related functions
i2c: img-scb: Remove #ifdef guards for PM related functions
i2c: kempld: Remove #ifdef guards for PM related functions
i2c: lpc2k: Remove #ifdef guards for PM related functions
i2c: mt65xx: Remove #ifdef guards for PM related functions
i2c: nomadik: Remove #ifdef guards for PM related functions
i2c: ocores: Remove #ifdef guards for PM related functions
i2c: pnx: Remove #ifdef guards for PM related functions
i2c: pxa: Remove #ifdef guards for PM related functions
i2c: qup: Remove #ifdef guards for PM related functions
i2c: rcar: Remove #ifdef guards for PM related functions
i2c: s3c2410: Remove #ifdef guards for PM related functions
i2c: sh-mobile: Remove #ifdef guards for PM related functions
i2c: virtio: Remove #ifdef guards for PM related functions
i2c: mux: pca954x: Remove #ifdef guards for PM related functions

drivers/i2c/busses/i2c-amd-mp2-pci.c | 14 +++++--------
drivers/i2c/busses/i2c-amd-mp2-plat.c | 8 ++------
drivers/i2c/busses/i2c-amd-mp2.h | 2 --
drivers/i2c/busses/i2c-au1550.c | 15 +++-----------
drivers/i2c/busses/i2c-bcm-iproc.c | 10 +---------
drivers/i2c/busses/i2c-brcmstb.c | 8 +++-----
drivers/i2c/busses/i2c-davinci.c | 12 +++--------
drivers/i2c/busses/i2c-designware-platdrv.c | 22 ++++++---------------
drivers/i2c/busses/i2c-exynos5.c | 8 +++-----
drivers/i2c/busses/i2c-hix5hd2.c | 10 ++++------
drivers/i2c/busses/i2c-i801.c | 6 ++----
drivers/i2c/busses/i2c-img-scb.c | 13 ++++--------
drivers/i2c/busses/i2c-kempld.c | 9 ++-------
drivers/i2c/busses/i2c-lpc2k.c | 8 +-------
drivers/i2c/busses/i2c-mt65xx.c | 8 +++-----
drivers/i2c/busses/i2c-nomadik.c | 14 +++++--------
drivers/i2c/busses/i2c-ocores.c | 10 +++-------
drivers/i2c/busses/i2c-pnx.c | 12 ++++-------
drivers/i2c/busses/i2c-pxa.c | 8 +-------
drivers/i2c/busses/i2c-qup.c | 16 ++++-----------
drivers/i2c/busses/i2c-rcar.c | 10 ++--------
drivers/i2c/busses/i2c-s3c2410.c | 14 +++----------
drivers/i2c/busses/i2c-sh_mobile.c | 12 +++--------
drivers/i2c/busses/i2c-virtio.c | 8 ++------
drivers/i2c/muxes/i2c-mux-pca954x.c | 6 ++----
25 files changed, 71 insertions(+), 192 deletions(-)

--
2.40.1



2023-07-05 21:16:45

by Paul Cercueil

[permalink] [raw]
Subject: [PATCH 07/23] i2c: exynos5: Remove #ifdef guards for PM related functions

Use the new PM macros for the suspend and resume functions to be
automatically dropped by the compiler when CONFIG_PM or
CONFIG_PM_SLEEP are 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: Krzysztof Kozlowski <[email protected]>
Cc: Alim Akhtar <[email protected]>
Cc: [email protected]
Cc: [email protected]
---
drivers/i2c/busses/i2c-exynos5.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/i2c/busses/i2c-exynos5.c b/drivers/i2c/busses/i2c-exynos5.c
index f378cd479e55..5b201a326c13 100644
--- a/drivers/i2c/busses/i2c-exynos5.c
+++ b/drivers/i2c/busses/i2c-exynos5.c
@@ -892,7 +892,6 @@ static void exynos5_i2c_remove(struct platform_device *pdev)
clk_unprepare(i2c->pclk);
}

-#ifdef CONFIG_PM_SLEEP
static int exynos5_i2c_suspend_noirq(struct device *dev)
{
struct exynos5_i2c *i2c = dev_get_drvdata(dev);
@@ -934,11 +933,10 @@ static int exynos5_i2c_resume_noirq(struct device *dev)
clk_disable_unprepare(i2c->pclk);
return ret;
}
-#endif

static const struct dev_pm_ops exynos5_i2c_dev_pm_ops = {
- SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(exynos5_i2c_suspend_noirq,
- exynos5_i2c_resume_noirq)
+ NOIRQ_SYSTEM_SLEEP_PM_OPS(exynos5_i2c_suspend_noirq,
+ exynos5_i2c_resume_noirq)
};

static struct platform_driver exynos5_i2c_driver = {
@@ -946,7 +944,7 @@ static struct platform_driver exynos5_i2c_driver = {
.remove_new = exynos5_i2c_remove,
.driver = {
.name = "exynos5-hsi2c",
- .pm = &exynos5_i2c_dev_pm_ops,
+ .pm = pm_sleep_ptr(&exynos5_i2c_dev_pm_ops),
.of_match_table = exynos5_i2c_match,
},
};
--
2.40.1


2023-07-05 21:18:35

by Paul Cercueil

[permalink] [raw]
Subject: [PATCH 09/23] i2c: i801: Remove #ifdef guards for PM related functions

Use the new PM macros for the suspend and resume functions to be
automatically dropped by the compiler when CONFIG_PM or
CONFIG_PM_SLEEP are 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: Jean Delvare <[email protected]>
---
drivers/i2c/busses/i2c-i801.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 943b8e6d026d..73ae06432133 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -1808,7 +1808,6 @@ static void i801_shutdown(struct pci_dev *dev)
pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg);
}

-#ifdef CONFIG_PM_SLEEP
static int i801_suspend(struct device *dev)
{
struct i801_priv *priv = dev_get_drvdata(dev);
@@ -1827,9 +1826,8 @@ static int i801_resume(struct device *dev)

return 0;
}
-#endif

-static SIMPLE_DEV_PM_OPS(i801_pm_ops, i801_suspend, i801_resume);
+static DEFINE_SIMPLE_DEV_PM_OPS(i801_pm_ops, i801_suspend, i801_resume);

static struct pci_driver i801_driver = {
.name = DRV_NAME,
@@ -1838,7 +1836,7 @@ static struct pci_driver i801_driver = {
.remove = i801_remove,
.shutdown = i801_shutdown,
.driver = {
- .pm = &i801_pm_ops,
+ .pm = pm_sleep_ptr(&i801_pm_ops),
.probe_type = PROBE_PREFER_ASYNCHRONOUS,
},
};
--
2.40.1


2023-07-05 21:18:50

by Paul Cercueil

[permalink] [raw]
Subject: [PATCH 10/23] i2c: img-scb: Remove #ifdef guards for PM related functions

Use the new PM macros for the suspend and resume functions to be
automatically dropped by the compiler when CONFIG_PM or
CONFIG_PM_SLEEP are 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/i2c/busses/i2c-img-scb.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/drivers/i2c/busses/i2c-img-scb.c b/drivers/i2c/busses/i2c-img-scb.c
index 4b674cfbc6fb..a92e3082542e 100644
--- a/drivers/i2c/busses/i2c-img-scb.c
+++ b/drivers/i2c/busses/i2c-img-scb.c
@@ -1454,7 +1454,6 @@ static int img_i2c_runtime_resume(struct device *dev)
return 0;
}

-#ifdef CONFIG_PM_SLEEP
static int img_i2c_suspend(struct device *dev)
{
struct img_i2c *i2c = dev_get_drvdata(dev);
@@ -1482,14 +1481,10 @@ static int img_i2c_resume(struct device *dev)

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

-static const struct dev_pm_ops img_i2c_pm = {
- SET_RUNTIME_PM_OPS(img_i2c_runtime_suspend,
- img_i2c_runtime_resume,
- NULL)
- SET_SYSTEM_SLEEP_PM_OPS(img_i2c_suspend, img_i2c_resume)
-};
+static _DEFINE_DEV_PM_OPS(img_i2c_pm, img_i2c_suspend, img_i2c_resume,
+ img_i2c_runtime_suspend, img_i2c_runtime_resume,
+ NULL);

static const struct of_device_id img_scb_i2c_match[] = {
{ .compatible = "img,scb-i2c" },
@@ -1501,7 +1496,7 @@ static struct platform_driver img_scb_i2c_driver = {
.driver = {
.name = "img-i2c-scb",
.of_match_table = img_scb_i2c_match,
- .pm = &img_i2c_pm,
+ .pm = pm_ptr(&img_i2c_pm),
},
.probe = img_i2c_probe,
.remove_new = img_i2c_remove,
--
2.40.1


2023-07-05 21:19:17

by Paul Cercueil

[permalink] [raw]
Subject: [PATCH 14/23] i2c: nomadik: Remove #ifdef guards for PM related functions

Use the new PM macros for the suspend and resume functions to be
automatically dropped by the compiler when CONFIG_PM or
CONFIG_PM_SLEEP are 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: Linus Walleij <[email protected]>
Cc: [email protected]
---
drivers/i2c/busses/i2c-nomadik.c | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c
index 1e5fd23ef45c..4a4b5bc257ae 100644
--- a/drivers/i2c/busses/i2c-nomadik.c
+++ b/drivers/i2c/busses/i2c-nomadik.c
@@ -873,7 +873,6 @@ static irqreturn_t i2c_irq_handler(int irq, void *arg)
return IRQ_HANDLED;
}

-#ifdef CONFIG_PM_SLEEP
static int nmk_i2c_suspend_late(struct device *dev)
{
int ret;
@@ -890,9 +889,7 @@ static int nmk_i2c_resume_early(struct device *dev)
{
return pm_runtime_force_resume(dev);
}
-#endif

-#ifdef CONFIG_PM
static int nmk_i2c_runtime_suspend(struct device *dev)
{
struct amba_device *adev = to_amba_device(dev);
@@ -925,13 +922,12 @@ static int nmk_i2c_runtime_resume(struct device *dev)

return ret;
}
-#endif

static const struct dev_pm_ops nmk_i2c_pm = {
- SET_LATE_SYSTEM_SLEEP_PM_OPS(nmk_i2c_suspend_late, nmk_i2c_resume_early)
- SET_RUNTIME_PM_OPS(nmk_i2c_runtime_suspend,
- nmk_i2c_runtime_resume,
- NULL)
+ LATE_SYSTEM_SLEEP_PM_OPS(nmk_i2c_suspend_late, nmk_i2c_resume_early)
+ RUNTIME_PM_OPS(nmk_i2c_runtime_suspend,
+ nmk_i2c_runtime_resume,
+ NULL)
};

static unsigned int nmk_i2c_functionality(struct i2c_adapter *adap)
@@ -1080,7 +1076,7 @@ static struct amba_driver nmk_i2c_driver = {
.drv = {
.owner = THIS_MODULE,
.name = DRIVER_NAME,
- .pm = &nmk_i2c_pm,
+ .pm = pm_ptr(&nmk_i2c_pm),
},
.id_table = nmk_i2c_ids,
.probe = nmk_i2c_probe,
--
2.40.1


2023-07-05 21:20:41

by Paul Cercueil

[permalink] [raw]
Subject: [PATCH 02/23] i2c: au1550: Remove #ifdef guards for PM related functions

Use the new PM macros for the suspend and resume functions to be
automatically dropped by the compiler when CONFIG_PM or
CONFIG_PM_SLEEP are 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 the behaviour is slightly different than before; the original
code wrapped the suspend/resume with #ifdef CONFIG_PM guards, which
resulted in these functions being compiled in but never used when
CONFIG_PM_SLEEP was disabled.

Now, those functions are only compiled in when CONFIG_PM_SLEEP is
enabled.

Signed-off-by: Paul Cercueil <[email protected]>
---
drivers/i2c/busses/i2c-au1550.c | 15 +++------------
1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/drivers/i2c/busses/i2c-au1550.c b/drivers/i2c/busses/i2c-au1550.c
index e66c12ecf270..8e43f25c117e 100644
--- a/drivers/i2c/busses/i2c-au1550.c
+++ b/drivers/i2c/busses/i2c-au1550.c
@@ -342,7 +342,6 @@ static void i2c_au1550_remove(struct platform_device *pdev)
i2c_au1550_disable(priv);
}

-#ifdef CONFIG_PM
static int i2c_au1550_suspend(struct device *dev)
{
struct i2c_au1550_data *priv = dev_get_drvdata(dev);
@@ -361,21 +360,13 @@ static int i2c_au1550_resume(struct device *dev)
return 0;
}

-static const struct dev_pm_ops i2c_au1550_pmops = {
- .suspend = i2c_au1550_suspend,
- .resume = i2c_au1550_resume,
-};
-
-#define AU1XPSC_SMBUS_PMOPS (&i2c_au1550_pmops)
-
-#else
-#define AU1XPSC_SMBUS_PMOPS NULL
-#endif
+static DEFINE_SIMPLE_DEV_PM_OPS(i2c_au1550_pmops,
+ i2c_au1550_suspend, i2c_au1550_resume);

static struct platform_driver au1xpsc_smbus_driver = {
.driver = {
.name = "au1xpsc_smbus",
- .pm = AU1XPSC_SMBUS_PMOPS,
+ .pm = pm_sleep_ptr(&i2c_au1550_pmops),
},
.probe = i2c_au1550_probe,
.remove_new = i2c_au1550_remove,
--
2.40.1


2023-07-05 21:20:50

by Paul Cercueil

[permalink] [raw]
Subject: [PATCH 19/23] i2c: rcar: Remove #ifdef guards for PM related functions

Use the new PM macros for the suspend and resume functions to be
automatically dropped by the compiler when CONFIG_PM or
CONFIG_PM_SLEEP are 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: Wolfram Sang <[email protected]>
Cc: [email protected]
---
drivers/i2c/busses/i2c-rcar.c | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c
index 2d9c37410ebd..6b7f0f27d0c3 100644
--- a/drivers/i2c/busses/i2c-rcar.c
+++ b/drivers/i2c/busses/i2c-rcar.c
@@ -1169,7 +1169,6 @@ static void rcar_i2c_remove(struct platform_device *pdev)
pm_runtime_disable(dev);
}

-#ifdef CONFIG_PM_SLEEP
static int rcar_i2c_suspend(struct device *dev)
{
struct rcar_i2c_priv *priv = dev_get_drvdata(dev);
@@ -1187,19 +1186,14 @@ static int rcar_i2c_resume(struct device *dev)
}

static const struct dev_pm_ops rcar_i2c_pm_ops = {
- SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(rcar_i2c_suspend, rcar_i2c_resume)
+ NOIRQ_SYSTEM_SLEEP_PM_OPS(rcar_i2c_suspend, rcar_i2c_resume)
};

-#define DEV_PM_OPS (&rcar_i2c_pm_ops)
-#else
-#define DEV_PM_OPS NULL
-#endif /* CONFIG_PM_SLEEP */
-
static struct platform_driver rcar_i2c_driver = {
.driver = {
.name = "i2c-rcar",
.of_match_table = rcar_i2c_dt_ids,
- .pm = DEV_PM_OPS,
+ .pm = pm_sleep_ptr(&rcar_i2c_pm_ops),
},
.probe = rcar_i2c_probe,
.remove_new = rcar_i2c_remove,
--
2.40.1


2023-07-05 21:21:14

by Paul Cercueil

[permalink] [raw]
Subject: [PATCH 12/23] i2c: lpc2k: Remove #ifdef guards for PM related functions

Use the new PM macros for the suspend and resume functions to be
automatically dropped by the compiler when CONFIG_PM or
CONFIG_PM_SLEEP are 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 the behaviour is slightly different than before; the original
code wrapped the suspend/resume with #ifdef CONFIG_PM guards, which
resulted in these functions being compiled in but never used when
CONFIG_PM_SLEEP was disabled.

Now, those functions are only compiled in when CONFIG_PM_SLEEP is
enabled.

Also note that pm_sleep_ptr() has not been applied to each callback
in the dev_pm_ops structure because the pm_sleep_ptr() at the usage site
is sufficient.

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

---
Cc: Vladimir Zapolskiy <[email protected]>
Cc: [email protected]
---
drivers/i2c/busses/i2c-lpc2k.c | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/i2c/busses/i2c-lpc2k.c b/drivers/i2c/busses/i2c-lpc2k.c
index 5c6d96554753..c61157f1409b 100644
--- a/drivers/i2c/busses/i2c-lpc2k.c
+++ b/drivers/i2c/busses/i2c-lpc2k.c
@@ -431,7 +431,6 @@ static void i2c_lpc2k_remove(struct platform_device *dev)
i2c_del_adapter(&i2c->adap);
}

-#ifdef CONFIG_PM
static int i2c_lpc2k_suspend(struct device *dev)
{
struct lpc2k_i2c *i2c = dev_get_drvdata(dev);
@@ -456,11 +455,6 @@ static const struct dev_pm_ops i2c_lpc2k_dev_pm_ops = {
.resume_noirq = i2c_lpc2k_resume,
};

-#define I2C_LPC2K_DEV_PM_OPS (&i2c_lpc2k_dev_pm_ops)
-#else
-#define I2C_LPC2K_DEV_PM_OPS NULL
-#endif
-
static const struct of_device_id lpc2k_i2c_match[] = {
{ .compatible = "nxp,lpc1788-i2c" },
{},
@@ -472,7 +466,7 @@ static struct platform_driver i2c_lpc2k_driver = {
.remove_new = i2c_lpc2k_remove,
.driver = {
.name = "lpc2k-i2c",
- .pm = I2C_LPC2K_DEV_PM_OPS,
+ .pm = pm_sleep_ptr(&i2c_lpc2k_dev_pm_ops),
.of_match_table = lpc2k_i2c_match,
},
};
--
2.40.1


2023-07-05 21:31:05

by Paul Cercueil

[permalink] [raw]
Subject: [PATCH 23/23] i2c: mux: pca954x: Remove #ifdef guards for PM related functions

Use the new PM macros for the suspend and resume functions to be
automatically dropped by the compiler when CONFIG_PM or
CONFIG_PM_SLEEP are 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: Peter Rosin <[email protected]>
---
drivers/i2c/muxes/i2c-mux-pca954x.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/i2c/muxes/i2c-mux-pca954x.c b/drivers/i2c/muxes/i2c-mux-pca954x.c
index 0ccee2ae5720..6965bf4c2348 100644
--- a/drivers/i2c/muxes/i2c-mux-pca954x.c
+++ b/drivers/i2c/muxes/i2c-mux-pca954x.c
@@ -530,7 +530,6 @@ static void pca954x_remove(struct i2c_client *client)
pca954x_cleanup(muxc);
}

-#ifdef CONFIG_PM_SLEEP
static int pca954x_resume(struct device *dev)
{
struct i2c_client *client = to_i2c_client(dev);
@@ -544,14 +543,13 @@ static int pca954x_resume(struct device *dev)

return ret;
}
-#endif

-static SIMPLE_DEV_PM_OPS(pca954x_pm, NULL, pca954x_resume);
+static DEFINE_SIMPLE_DEV_PM_OPS(pca954x_pm, NULL, pca954x_resume);

static struct i2c_driver pca954x_driver = {
.driver = {
.name = "pca954x",
- .pm = &pca954x_pm,
+ .pm = pm_sleep_ptr(&pca954x_pm),
.of_match_table = pca954x_of_match,
},
.probe = pca954x_probe,
--
2.40.1


2023-07-06 02:30:16

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH 02/23] i2c: au1550: Remove #ifdef guards for PM related functions

On Wed, 5 Jul 2023 22:42:53 +0200
Paul Cercueil <[email protected]> wrote:

> Use the new PM macros for the suspend and resume functions to be
> automatically dropped by the compiler when CONFIG_PM or
> CONFIG_PM_SLEEP are 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 the behaviour is slightly different than before; the original
> code wrapped the suspend/resume with #ifdef CONFIG_PM guards, which
> resulted in these functions being compiled in but never used when
> CONFIG_PM_SLEEP was disabled.
>
> Now, those functions are only compiled in when CONFIG_PM_SLEEP is
> enabled.
>
> Signed-off-by: Paul Cercueil <[email protected]>

Reviewed-by: Jonathan Cameron <[email protected]>

> ---
> drivers/i2c/busses/i2c-au1550.c | 15 +++------------
> 1 file changed, 3 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-au1550.c b/drivers/i2c/busses/i2c-au1550.c
> index e66c12ecf270..8e43f25c117e 100644
> --- a/drivers/i2c/busses/i2c-au1550.c
> +++ b/drivers/i2c/busses/i2c-au1550.c
> @@ -342,7 +342,6 @@ static void i2c_au1550_remove(struct platform_device *pdev)
> i2c_au1550_disable(priv);
> }
>
> -#ifdef CONFIG_PM
> static int i2c_au1550_suspend(struct device *dev)
> {
> struct i2c_au1550_data *priv = dev_get_drvdata(dev);
> @@ -361,21 +360,13 @@ static int i2c_au1550_resume(struct device *dev)
> return 0;
> }
>
> -static const struct dev_pm_ops i2c_au1550_pmops = {
> - .suspend = i2c_au1550_suspend,
> - .resume = i2c_au1550_resume,
> -};
> -
> -#define AU1XPSC_SMBUS_PMOPS (&i2c_au1550_pmops)
> -
> -#else
> -#define AU1XPSC_SMBUS_PMOPS NULL
> -#endif
> +static DEFINE_SIMPLE_DEV_PM_OPS(i2c_au1550_pmops,
> + i2c_au1550_suspend, i2c_au1550_resume);
>
> static struct platform_driver au1xpsc_smbus_driver = {
> .driver = {
> .name = "au1xpsc_smbus",
> - .pm = AU1XPSC_SMBUS_PMOPS,
> + .pm = pm_sleep_ptr(&i2c_au1550_pmops),
> },
> .probe = i2c_au1550_probe,
> .remove_new = i2c_au1550_remove,


2023-07-06 02:50:17

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH 07/23] i2c: exynos5: Remove #ifdef guards for PM related functions

On Wed, 5 Jul 2023 22:42:58 +0200
Paul Cercueil <[email protected]> wrote:

> Use the new PM macros for the suspend and resume functions to be
> automatically dropped by the compiler when CONFIG_PM or
> CONFIG_PM_SLEEP are 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: Jonathan Cameron <[email protected]>


2023-07-06 02:51:13

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH 10/23] i2c: img-scb: Remove #ifdef guards for PM related functions

On Wed, 5 Jul 2023 22:43:01 +0200
Paul Cercueil <[email protected]> wrote:

> Use the new PM macros for the suspend and resume functions to be
> automatically dropped by the compiler when CONFIG_PM or
> CONFIG_PM_SLEEP are 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]>
I thought the _DEFINE macros weren't really intended for driver
usage and it's good to keep the ability to change those details
without updating lots of drivers. Perhaps just express it long hand here?

Jonathan


> ---
> drivers/i2c/busses/i2c-img-scb.c | 13 ++++---------
> 1 file changed, 4 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-img-scb.c b/drivers/i2c/busses/i2c-img-scb.c
> index 4b674cfbc6fb..a92e3082542e 100644
> --- a/drivers/i2c/busses/i2c-img-scb.c
> +++ b/drivers/i2c/busses/i2c-img-scb.c
> @@ -1454,7 +1454,6 @@ static int img_i2c_runtime_resume(struct device *dev)
> return 0;
> }
>
> -#ifdef CONFIG_PM_SLEEP
> static int img_i2c_suspend(struct device *dev)
> {
> struct img_i2c *i2c = dev_get_drvdata(dev);
> @@ -1482,14 +1481,10 @@ static int img_i2c_resume(struct device *dev)
>
> return 0;
> }
> -#endif /* CONFIG_PM_SLEEP */
>
> -static const struct dev_pm_ops img_i2c_pm = {
> - SET_RUNTIME_PM_OPS(img_i2c_runtime_suspend,
> - img_i2c_runtime_resume,
> - NULL)
> - SET_SYSTEM_SLEEP_PM_OPS(img_i2c_suspend, img_i2c_resume)
> -};
> +static _DEFINE_DEV_PM_OPS(img_i2c_pm, img_i2c_suspend, img_i2c_resume,
> + img_i2c_runtime_suspend, img_i2c_runtime_resume,
> + NULL);
>
> static const struct of_device_id img_scb_i2c_match[] = {
> { .compatible = "img,scb-i2c" },
> @@ -1501,7 +1496,7 @@ static struct platform_driver img_scb_i2c_driver = {
> .driver = {
> .name = "img-i2c-scb",
> .of_match_table = img_scb_i2c_match,
> - .pm = &img_i2c_pm,
> + .pm = pm_ptr(&img_i2c_pm),
> },
> .probe = img_i2c_probe,
> .remove_new = img_i2c_remove,


2023-07-06 02:54:38

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH 09/23] i2c: i801: Remove #ifdef guards for PM related functions

On Wed, 5 Jul 2023 22:43:00 +0200
Paul Cercueil <[email protected]> wrote:

> Use the new PM macros for the suspend and resume functions to be
> automatically dropped by the compiler when CONFIG_PM or
> CONFIG_PM_SLEEP are 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: Jonathan Cameron <[email protected]>


2023-07-06 03:03:04

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH 12/23] i2c: lpc2k: Remove #ifdef guards for PM related functions

On Wed, 5 Jul 2023 22:43:03 +0200
Paul Cercueil <[email protected]> wrote:

> Use the new PM macros for the suspend and resume functions to be
> automatically dropped by the compiler when CONFIG_PM or
> CONFIG_PM_SLEEP are 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 the behaviour is slightly different than before; the original
> code wrapped the suspend/resume with #ifdef CONFIG_PM guards, which
> resulted in these functions being compiled in but never used when
> CONFIG_PM_SLEEP was disabled.
>
> Now, those functions are only compiled in when CONFIG_PM_SLEEP is
> enabled.
>
> Also note that pm_sleep_ptr() has not been applied to each callback
> in the dev_pm_ops structure because the pm_sleep_ptr() at the usage site
> is sufficient.
>
> Signed-off-by: Paul Cercueil <[email protected]>
Reviewed-by: Jonathan Cameron <[email protected]>

2023-07-06 03:07:20

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH 14/23] i2c: nomadik: Remove #ifdef guards for PM related functions

On Wed, 5 Jul 2023 22:43:05 +0200
Paul Cercueil <[email protected]> wrote:

> Use the new PM macros for the suspend and resume functions to be
> automatically dropped by the compiler when CONFIG_PM or
> CONFIG_PM_SLEEP are 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]>
>
Might be worth rewrapping the runtime pm line. Otherwise LGTM

Reviewed-by: Jonathan Cameron <[email protected]>

> ---
> Cc: Linus Walleij <[email protected]>
> Cc: [email protected]
> ---
> drivers/i2c/busses/i2c-nomadik.c | 14 +++++---------
> 1 file changed, 5 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c
> index 1e5fd23ef45c..4a4b5bc257ae 100644
> --- a/drivers/i2c/busses/i2c-nomadik.c
> +++ b/drivers/i2c/busses/i2c-nomadik.c
> @@ -873,7 +873,6 @@ static irqreturn_t i2c_irq_handler(int irq, void *arg)
> return IRQ_HANDLED;
> }
>
> -#ifdef CONFIG_PM_SLEEP
> static int nmk_i2c_suspend_late(struct device *dev)
> {
> int ret;
> @@ -890,9 +889,7 @@ static int nmk_i2c_resume_early(struct device *dev)
> {
> return pm_runtime_force_resume(dev);
> }
> -#endif
>
> -#ifdef CONFIG_PM
> static int nmk_i2c_runtime_suspend(struct device *dev)
> {
> struct amba_device *adev = to_amba_device(dev);
> @@ -925,13 +922,12 @@ static int nmk_i2c_runtime_resume(struct device *dev)
>
> return ret;
> }
> -#endif
>
> static const struct dev_pm_ops nmk_i2c_pm = {
> - SET_LATE_SYSTEM_SLEEP_PM_OPS(nmk_i2c_suspend_late, nmk_i2c_resume_early)
> - SET_RUNTIME_PM_OPS(nmk_i2c_runtime_suspend,
> - nmk_i2c_runtime_resume,
> - NULL)
> + LATE_SYSTEM_SLEEP_PM_OPS(nmk_i2c_suspend_late, nmk_i2c_resume_early)
> + RUNTIME_PM_OPS(nmk_i2c_runtime_suspend,
> + nmk_i2c_runtime_resume,
> + NULL)

rewrap?

> };
>
> static unsigned int nmk_i2c_functionality(struct i2c_adapter *adap)
> @@ -1080,7 +1076,7 @@ static struct amba_driver nmk_i2c_driver = {
> .drv = {
> .owner = THIS_MODULE,
> .name = DRIVER_NAME,
> - .pm = &nmk_i2c_pm,
> + .pm = pm_ptr(&nmk_i2c_pm),
> },
> .id_table = nmk_i2c_ids,
> .probe = nmk_i2c_probe,


2023-07-06 03:09:25

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH 19/23] i2c: rcar: Remove #ifdef guards for PM related functions

On Wed, 5 Jul 2023 22:45:17 +0200
Paul Cercueil <[email protected]> wrote:

> Use the new PM macros for the suspend and resume functions to be
> automatically dropped by the compiler when CONFIG_PM or
> CONFIG_PM_SLEEP are 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: Jonathan Cameron <[email protected]>

2023-07-06 03:28:53

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH 23/23] i2c: mux: pca954x: Remove #ifdef guards for PM related functions

On Wed, 5 Jul 2023 22:45:21 +0200
Paul Cercueil <[email protected]> wrote:

> Use the new PM macros for the suspend and resume functions to be
> automatically dropped by the compiler when CONFIG_PM or
> CONFIG_PM_SLEEP are 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: Jonathan Cameron <[email protected]>

2023-07-06 06:36:59

by Peter Rosin

[permalink] [raw]
Subject: Re: [PATCH 23/23] i2c: mux: pca954x: Remove #ifdef guards for PM related functions

Hi!

2023-07-05 at 22:45, Paul Cercueil wrote:
> Use the new PM macros for the suspend and resume functions to be
> automatically dropped by the compiler when CONFIG_PM or
> CONFIG_PM_SLEEP are 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]>

Acked-by: Peter Rosin <[email protected]>

Cheers,
Peter

2023-07-06 17:29:50

by Linus Walleij

[permalink] [raw]
Subject: Re: [PATCH 14/23] i2c: nomadik: Remove #ifdef guards for PM related functions

On Wed, Jul 5, 2023 at 10:43 PM Paul Cercueil <[email protected]> wrote:

> Use the new PM macros for the suspend and resume functions to be
> automatically dropped by the compiler when CONFIG_PM or
> CONFIG_PM_SLEEP are 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]>

Looks correct!
Reviewed-by: Linus Walleij <[email protected]>

Yours,
Linus Walleij

2023-07-08 08:58:44

by Paul Cercueil

[permalink] [raw]
Subject: Re: [PATCH 10/23] i2c: img-scb: Remove #ifdef guards for PM related functions

Hi Jonathan,

Le jeudi 06 juillet 2023 à 10:31 +0800, Jonathan Cameron a écrit :
> On Wed,  5 Jul 2023 22:43:01 +0200
> Paul Cercueil <[email protected]> wrote:
>
> > Use the new PM macros for the suspend and resume functions to be
> > automatically dropped by the compiler when CONFIG_PM or
> > CONFIG_PM_SLEEP are 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]>
> I thought the _DEFINE macros weren't really intended for driver
> usage and it's good to keep the ability to change those details
> without updating lots of drivers.  Perhaps just express it long hand
> here?

Yeah you are right. The "long version" isn't much longer anyway.

Cheers,
-Paul

> Jonathan
>
>
> > ---
> >  drivers/i2c/busses/i2c-img-scb.c | 13 ++++---------
> >  1 file changed, 4 insertions(+), 9 deletions(-)
> >
> > diff --git a/drivers/i2c/busses/i2c-img-scb.c
> > b/drivers/i2c/busses/i2c-img-scb.c
> > index 4b674cfbc6fb..a92e3082542e 100644
> > --- a/drivers/i2c/busses/i2c-img-scb.c
> > +++ b/drivers/i2c/busses/i2c-img-scb.c
> > @@ -1454,7 +1454,6 @@ static int img_i2c_runtime_resume(struct
> > device *dev)
> >         return 0;
> >  }
> >  
> > -#ifdef CONFIG_PM_SLEEP
> >  static int img_i2c_suspend(struct device *dev)
> >  {
> >         struct img_i2c *i2c = dev_get_drvdata(dev);
> > @@ -1482,14 +1481,10 @@ static int img_i2c_resume(struct device
> > *dev)
> >  
> >         return 0;
> >  }
> > -#endif /* CONFIG_PM_SLEEP */
> >  
> > -static const struct dev_pm_ops img_i2c_pm = {
> > -       SET_RUNTIME_PM_OPS(img_i2c_runtime_suspend,
> > -                          img_i2c_runtime_resume,
> > -                          NULL)
> > -       SET_SYSTEM_SLEEP_PM_OPS(img_i2c_suspend, img_i2c_resume)
> > -};
> > +static _DEFINE_DEV_PM_OPS(img_i2c_pm, img_i2c_suspend,
> > img_i2c_resume,
> > +                         img_i2c_runtime_suspend,
> > img_i2c_runtime_resume,
> > +                         NULL);
> >  
> >  static const struct of_device_id img_scb_i2c_match[] = {
> >         { .compatible = "img,scb-i2c" },
> > @@ -1501,7 +1496,7 @@ static struct platform_driver
> > img_scb_i2c_driver = {
> >         .driver = {
> >                 .name           = "img-i2c-scb",
> >                 .of_match_table = img_scb_i2c_match,
> > -               .pm             = &img_i2c_pm,
> > +               .pm             = pm_ptr(&img_i2c_pm),
> >         },
> >         .probe = img_i2c_probe,
> >         .remove_new = img_i2c_remove,
>

2023-07-10 13:01:55

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH 19/23] i2c: rcar: Remove #ifdef guards for PM related functions

On Wed, Jul 5, 2023 at 10:49 PM Paul Cercueil <[email protected]> wrote:
> Use the new PM macros for the suspend and resume functions to be
> automatically dropped by the compiler when CONFIG_PM or
> CONFIG_PM_SLEEP are 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: Geert Uytterhoeven <[email protected]>

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds