IIO: Where dev_pm_ops rework and namespaces meet.
Subsystems (5)
v2 cover IIO: Where dev_pm_ops rework and namespaces meet.
v2:
Just the first 3 patches so they can go via the PM tree. Remainder of series will go via IIO in due course.
Hi All,
As these two activities have been ongoing across IIO at the same time it was inevitable that there would be drivers were they both interact. In particularly when we have EXPORT* of struct dev_pm_ops.
This series covers those cases by introducing (in patch 2) EXPORT_NS[_GPL]_SIMPLE_DEV_PM_OPS() and EXPORT_NS[_GPL]_RUNTIME_DEV_PM_OPS()
that add a namespace as the final parameter.
Thanks,
Jonathan
Jonathan Cameron (3):
iio: chemical: scd30: Export dev_pm_ops instead of suspend() and
resume()
PM: core: Add NS varients of EXPORT[_GPL]_SIMPLE_DEV_PM_OPS and
runtime pm equiv
iio: chemical: scd30: Move symbol exports into IIO_SCD30 namespace
drivers/iio/chemical/scd30.h | 5 +---- drivers/iio/chemical/scd30_core.c | 10 +++++----- drivers/iio/chemical/scd30_i2c.c | 3 ++- drivers/iio/chemical/scd30_serial.c | 3 ++- include/linux/pm.h | 14 +++++++++----- include/linux/pm_runtime.h | 10 ++++++++-- 6 files changed, 27 insertions(+), 18 deletions(-)
Signature · 1 line
2.32.0
PATCH v2 1/3 iio: chemical: scd30: Export dev_pm_ops instead of suspend() and resume()
Whilst here move to the new infrastructure using pm_sleep_ptr() and EXPORT_DEV_PM_OPS() so as to let the compiler remove the unused code if CONFIG_SLEEP is not defined.
--- drivers/iio/chemical/scd30.h | 5 +---- drivers/iio/chemical/scd30_core.c | 8 ++++---- drivers/iio/chemical/scd30_i2c.c | 2 +- drivers/iio/chemical/scd30_serial.c | 2 +- 4 files changed, 7 insertions(+), 10 deletions(-)
drivers/iio/chemical/scd30.h +1 -4
@@ -68,10 +68,7 @@ struct scd30_state {scd30_command_t command; }; -int scd30_suspend (struct device *dev); -int scd30_resume (struct device *dev); - -static __maybe_unused SIMPLE_DEV_PM_OPS(scd30_pm_ops, scd30_suspend, scd30_resume); +extern const struct dev_pm_ops scd30_pm_ops;int scd30_probe (struct device *dev,int irq,const char *name,void *priv,scd30_command_t command);
drivers/iio/chemical/scd30_core.c +4 -4
@@ -517,7 +517,7 @@ static const struct iio_chan_spec scd30_channels[] = { IIO_CHAN_SOFT_TIMESTAMP(3), }; -int __maybe_unused scd30_suspend (struct device *dev) +static int scd30_suspend (struct device *dev) {struct iio_dev *indio_dev =dev_get_drvdata (dev);struct scd30_state *state =iio_priv (indio_dev);
@@ -529,9 +529,8 @@ int __maybe_unused scd30_suspend(struct device *dev)return regulator_disable (state->vdd); } -EXPORT_SYMBOL (scd30_suspend); -int __maybe_unused scd30_resume (struct device *dev) +static int scd30_resume (struct device *dev) {struct iio_dev *indio_dev =dev_get_drvdata (dev);struct scd30_state *state =iio_priv (indio_dev);
@@ -543,7 +542,8 @@ int __maybe_unused scd30_resume(struct device *dev)return scd30_command_write (state,CMD_START_MEAS , state->pressure_comp); } -EXPORT_SYMBOL (scd30_resume); + +EXPORT_SIMPLE_DEV_PM_OPS (scd30_pm_ops, scd30_suspend, scd30_resume);static void scd30_stop_meas (void *data) {
drivers/iio/chemical/scd30_i2c.c +1 -1
@@ -128,7 +128,7 @@ static struct i2c_driver scd30_i2c_driver = { .driver = { .name = KBUILD_MODNAME, .of_match_table = scd30_i2c_of_match, - .pm = &scd30_pm_ops, + .pm = pm_sleep_ptr(&scd30_pm_ops), }, .probe_new = scd30_i2c_probe, };
drivers/iio/chemical/scd30_serial.c +1 -1
@@ -252,7 +252,7 @@ static struct serdev_device_driver scd30_serdev_driver = { .driver = { .name = KBUILD_MODNAME, .of_match_table = scd30_serdev_of_match, - .pm = &scd30_pm_ops, + .pm = pm_sleep_ptr(&scd30_pm_ops), }, .probe = scd30_serdev_probe, };
Signature · 1 line
2.32.0
Re: [PATCH v2 1/3] iio: chemical: scd30: Export dev_pm_ops instead of suspend() and resume()
Quoted 82 lines · Jonathan Cameron
Whilst here move to the new infrastructure using
pm_sleep_ptr()andEXPORT_DEV_PM_OPS()so as to let the compiler remove the unused code ifCONFIG_SLEEPis not defined.Signed-off-by Jonathan Cameron <[email protected]>Cc Tomasz Duszynski <[email protected]>--- drivers/iio/chemical/scd30.h | 5 +---- drivers/iio/chemical/scd30_core.c | 8 ++++---- drivers/iio/chemical/scd30_i2c.c | 2 +- drivers/iio/chemical/scd30_serial.c | 2 +- 4 files changed, 7 insertions(+), 10 deletions(-)drivers/iio/chemical/scd30.h +1
-4@@ -68,10 +68,7 @@ struct scd30_state {scd30_command_t command; }; -int scd30_suspend (struct device *dev); -int scd30_resume (struct device *dev); - -static __maybe_unused SIMPLE_DEV_PM_OPS(scd30_pm_ops, scd30_suspend, scd30_resume); +extern const struct dev_pm_ops scd30_pm_ops;int scd30_probe (struct device *dev,int irq,const char *name,void *priv,scd30_command_t command);drivers/iio/chemical/scd30_core.c +4
-4@@ -517,7 +517,7 @@ static const struct iio_chan_spec scd30_channels[] = { IIO_CHAN_SOFT_TIMESTAMP(3), }; -int __maybe_unused scd30_suspend (struct device *dev) +static int scd30_suspend (struct device *dev) {struct iio_dev *indio_dev =dev_get_drvdata (dev);struct scd30_state *state =iio_priv (indio_dev);@@ -529,9 +529,8 @@ int __maybe_unused scd30_suspend(struct device *dev)return regulator_disable (state->vdd); } -EXPORT_SYMBOL (scd30_suspend); -int __maybe_unused scd30_resume (struct device *dev) +static int scd30_resume (struct device *dev) {struct iio_dev *indio_dev =dev_get_drvdata (dev);struct scd30_state *state =iio_priv (indio_dev);@@ -543,7 +542,8 @@ int __maybe_unused scd30_resume(struct device *dev)return scd30_command_write (state,CMD_START_MEAS , state->pressure_comp); } -EXPORT_SYMBOL (scd30_resume); + +EXPORT_SIMPLE_DEV_PM_OPS (scd30_pm_ops, scd30_suspend, scd30_resume);static void scd30_stop_meas (void *data) {drivers/iio/chemical/scd30_i2c.c +1
-1@@ -128,7 +128,7 @@ static struct i2c_driver scd30_i2c_driver = { .driver = { .name = KBUILD_MODNAME, .of_match_table = scd30_i2c_of_match, - .pm = &scd30_pm_ops, + .pm = pm_sleep_ptr(&scd30_pm_ops), }, .probe_new = scd30_i2c_probe, };drivers/iio/chemical/scd30_serial.c +0
-0
drivers/iio/chemical/scd30_serial.c static struct serdev_device_driver scd30_serdev_driver = {
Quoted 9 lines
drivers/iio/chemical/scd30_serial.c +1
-2@@ -252,7 +252,7 @@ static struct serdev_device_driver scd30_serdev_driver = { .driver = { .name = KBUILD_MODNAME, .of_match_table = scd30_serdev_of_match, - .pm = &scd30_pm_ops, + .pm = pm_sleep_ptr(&scd30_pm_ops), }, .probe = scd30_serdev_probe, }; --
Applied as 5.19 material along with the [2-3/3].
Please let me know if you need a non-mutable branch to pull from in order to base other work on these commits.
Thanks!
Re: [PATCH v2 1/3] iio: chemical: scd30: Export dev_pm_ops instead of suspend() and resume()
Quoted 96 lines · On Tue, 5 Apr 2022 20:19:11 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 83 lines · Jonathan Cameron
Whilst here move to the new infrastructure using
pm_sleep_ptr()andEXPORT_DEV_PM_OPS()so as to let the compiler remove the unused code ifCONFIG_SLEEPis not defined.Signed-off-by Jonathan Cameron <[email protected]>Cc Tomasz Duszynski <[email protected]>--- drivers/iio/chemical/scd30.h | 5 +---- drivers/iio/chemical/scd30_core.c | 8 ++++---- drivers/iio/chemical/scd30_i2c.c | 2 +- drivers/iio/chemical/scd30_serial.c | 2 +- 4 files changed, 7 insertions(+), 10 deletions(-)drivers/iio/chemical/scd30.h +1
-4@@ -68,10 +68,7 @@ struct scd30_state {scd30_command_t command; }; -int scd30_suspend (struct device *dev); -int scd30_resume (struct device *dev); - -static __maybe_unused SIMPLE_DEV_PM_OPS(scd30_pm_ops, scd30_suspend, scd30_resume); +extern const struct dev_pm_ops scd30_pm_ops;int scd30_probe (struct device *dev,int irq,const char *name,void *priv,scd30_command_t command);drivers/iio/chemical/scd30_core.c +4
-4@@ -517,7 +517,7 @@ static const struct iio_chan_spec scd30_channels[] = { IIO_CHAN_SOFT_TIMESTAMP(3), }; -int __maybe_unused scd30_suspend (struct device *dev) +static int scd30_suspend (struct device *dev) {struct iio_dev *indio_dev =dev_get_drvdata (dev);struct scd30_state *state =iio_priv (indio_dev);@@ -529,9 +529,8 @@ int __maybe_unused scd30_suspend(struct device *dev)return regulator_disable (state->vdd); } -EXPORT_SYMBOL (scd30_suspend); -int __maybe_unused scd30_resume (struct device *dev) +static int scd30_resume (struct device *dev) {struct iio_dev *indio_dev =dev_get_drvdata (dev);struct scd30_state *state =iio_priv (indio_dev);@@ -543,7 +542,8 @@ int __maybe_unused scd30_resume(struct device *dev)return scd30_command_write (state,CMD_START_MEAS , state->pressure_comp); } -EXPORT_SYMBOL (scd30_resume); + +EXPORT_SIMPLE_DEV_PM_OPS (scd30_pm_ops, scd30_suspend, scd30_resume);static void scd30_stop_meas (void *data) {drivers/iio/chemical/scd30_i2c.c +1
-1@@ -128,7 +128,7 @@ static struct i2c_driver scd30_i2c_driver = { .driver = { .name = KBUILD_MODNAME, .of_match_table = scd30_i2c_of_match, - .pm = &scd30_pm_ops, + .pm = pm_sleep_ptr(&scd30_pm_ops), }, .probe_new = scd30_i2c_probe, };drivers/iio/chemical/scd30_serial.c +0
-0drivers/iio/chemical/scd30_serial.c static struct serdev_device_driver scd30_serdev_driver = { · line 258
Quoted 8 lines
drivers/iio/chemical/scd30_serial.c +1
-1@@ -252,7 +252,7 @@ static struct serdev_device_driver scd30_serdev_driver = { .driver = { .name = KBUILD_MODNAME, .of_match_table = scd30_serdev_of_match, - .pm = &scd30_pm_ops, + .pm = pm_sleep_ptr(&scd30_pm_ops), }, .probe = scd30_serdev_probe, };Applied as 5.19 material along with the [2-3/3].
Quoted 2 lines
Please let me know if you need a non-mutable branch to pull from in order to base other work on these commits.
Yes please. A non-mutable branch would be great.
Thanks,
Jonathan
Quoted 2 lines
Thanks!
PATCH v2 2/3 PM: core: Add NS varients of EXPORT[_GPL]_SIMPLE_DEV_PM_OPS and runtime pm equiv
In reply to Jonathan CameronAs more drivers start to use namespaces, we need to have varients of these useful macros that allow the export to be in a particular namespace.
--- include/linux/pm.h | 14 +++++++++----- include/linux/pm_runtime.h | 10 ++++++++-- 2 files changed, 17 insertions(+), 7 deletions(-)
include/linux/pm.h +9 -5
@@ -368,13 +368,13 @@ const struct dev_pm_ops name = { \#ifdef CONFIG_PM #define _EXPORT_DEV_PM_OPS (name, suspend_fn, resume_fn, runtime_suspend_fn, \ - runtime_resume_fn, idle_fn, sec) \ + runtime_resume_fn, idle_fn, sec, ns) \ _DEFINE_DEV_PM_OPS(name, suspend_fn, resume_fn, runtime_suspend_fn, \ runtime_resume_fn, idle_fn); \ - _EXPORT_SYMBOL(name, sec) + __EXPORT_SYMBOL(name, sec, ns)#else #define _EXPORT_DEV_PM_OPS (name, suspend_fn, resume_fn, runtime_suspend_fn, \ - runtime_resume_fn, idle_fn, sec) \ + runtime_resume_fn, idle_fn, sec, ns) \ static __maybe_unused _DEFINE_DEV_PM_OPS(__static_##name, suspend_fn, \ resume_fn, runtime_suspend_fn, \ runtime_resume_fn, idle_fn)
@@ -391,9 +391,13 @@ static __maybe_unused _DEFINE_DEV_PM_OPS(__static_##name, suspend_fn, \ _DEFINE_DEV_PM_OPS(name, suspend_fn, resume_fn, NULL, NULL, NULL)#define EXPORT_SIMPLE_DEV_PM_OPS (name, suspend_fn, resume_fn) \ - _EXPORT_DEV_PM_OPS(name, suspend_fn, resume_fn, NULL, NULL, NULL, "") + _EXPORT_DEV_PM_OPS(name, suspend_fn, resume_fn, NULL, NULL, NULL, "", "")#define EXPORT_GPL_SIMPLE_DEV_PM_OPS (name, suspend_fn, resume_fn) \ - _EXPORT_DEV_PM_OPS(name, suspend_fn, resume_fn, NULL, NULL, NULL, "_gpl") + _EXPORT_DEV_PM_OPS(name, suspend_fn, resume_fn, NULL, NULL, NULL, "_gpl", "") +#define EXPORT_NS_SIMPLE_DEV_PM_OPS (name, suspend_fn, resume_fn, ns) \ + _EXPORT_DEV_PM_OPS(name, suspend_fn, resume_fn, NULL, NULL, NULL, "", #ns) +#define EXPORT_NS_GPL_SIMPLE_DEV_PM_OPS (name, suspend_fn, resume_fn, ns) \ + _EXPORT_DEV_PM_OPS(name, suspend_fn, resume_fn, NULL, NULL, NULL, "_gpl", #ns)/* Deprecated. Use DEFINE_SIMPLE_DEV_PM_OPS() instead. */ #define SIMPLE_DEV_PM_OPS (name, suspend_fn, resume_fn) \
include/linux/pm_runtime.h +8 -2
@@ -41,10 +41,16 @@#define EXPORT_RUNTIME_DEV_PM_OPS (name, suspend_fn, resume_fn, idle_fn) \ _EXPORT_DEV_PM_OPS(name, pm_runtime_force_suspend, pm_runtime_force_resume, \ - suspend_fn, resume_fn, idle_fn, "") + suspend_fn, resume_fn, idle_fn, "", "")#define EXPORT_GPL_RUNTIME_DEV_PM_OPS (name, suspend_fn, resume_fn, idle_fn) \ _EXPORT_DEV_PM_OPS(name, pm_runtime_force_suspend, pm_runtime_force_resume, \ - suspend_fn, resume_fn, idle_fn, "_gpl") + suspend_fn, resume_fn, idle_fn, "_gpl", "") +#define EXPORT_NS_RUNTIME_DEV_PM_OPS (name, suspend_fn, resume_fn, idle_fn, ns) \ + _EXPORT_DEV_PM_OPS(name, pm_runtime_force_suspend, pm_runtime_force_resume, \ + suspend_fn, resume_fn, idle_fn, "", #ns) +#define EXPORT_NS_GPL_RUNTIME_DEV_PM_OPS (name, suspend_fn, resume_fn, idle_fn, ns) \ + _EXPORT_DEV_PM_OPS(name, pm_runtime_force_suspend, pm_runtime_force_resume, \ + suspend_fn, resume_fn, idle_fn, "_gpl", #ns)#ifdef CONFIG_PM extern struct workqueue_struct *pm_wq;
Signature · 1 line
2.32.0
PATCH v2 3/3 iio: chemical: scd30: Move symbol exports into IIO_SCD30 namespace
In reply to Jonathan CameronAvoid unnecessary pollution of the global symbol namespace by moving library functions in to a specific namespace and import that into the drivers that make use of the functions.
For more info: https://lwn.net/Articles/760045/
--- drivers/iio/chemical/scd30_core.c | 4 ++-- drivers/iio/chemical/scd30_i2c.c | 1 + drivers/iio/chemical/scd30_serial.c | 1 + 3 files changed, 4 insertions(+), 2 deletions(-)
drivers/iio/chemical/scd30_core.c +2 -2
@@ -543,7 +543,7 @@ static int scd30_resume(struct device *dev)return scd30_command_write (state,CMD_START_MEAS , state->pressure_comp); } -EXPORT_SIMPLE_DEV_PM_OPS (scd30_pm_ops, scd30_suspend, scd30_resume); +EXPORT_NS_SIMPLE_DEV_PM_OPS (scd30_pm_ops, scd30_suspend, scd30_resume,IIO_SCD30 );static void scd30_stop_meas (void *data) {
@@ -759,7 +759,7 @@ int scd30_probe(struct device *dev, int irq, const char *name, void *priv,return devm_iio_device_register (dev, indio_dev); } -EXPORT_SYMBOL (scd30_probe); +EXPORT_SYMBOL_NS (scd30_probe,IIO_SCD30 );MODULE_AUTHOR ("Tomasz Duszynski <[email protected]>" );MODULE_DESCRIPTION ("Sensirion SCD30 carbon dioxide sensor core driver" );
drivers/iio/chemical/scd30_i2c.c +1 -0
@@ -137,3 +137,4 @@ module_i2c_driver(scd30_i2c_driver);MODULE_AUTHOR ("Tomasz Duszynski <[email protected]>" );MODULE_DESCRIPTION ("Sensirion SCD30 carbon dioxide sensor i2c driver" );MODULE_LICENSE ("GPL v2" ); +MODULE_IMPORT_NS (IIO_SCD30 );
drivers/iio/chemical/scd30_serial.c +1 -0
@@ -261,3 +261,4 @@ module_serdev_device_driver(scd30_serdev_driver);MODULE_AUTHOR ("Tomasz Duszynski <[email protected]>" );MODULE_DESCRIPTION ("Sensirion SCD30 carbon dioxide sensor serial driver" );MODULE_LICENSE ("GPL v2" ); +MODULE_IMPORT_NS (IIO_SCD30 );
Signature · 1 line
2.32.0