diff mbox

ALSA: ac97: Switch to dev_pm_ops

Message ID 1438890129-32621-1-git-send-email-lars@metafoo.de (mailing list archive)
State Accepted
Commit ef3c79ff372b17a407b72e26d32af28919abdf39
Headers show

Commit Message

Lars-Peter Clausen Aug. 6, 2015, 7:42 p.m. UTC
Convert the ac97_bus from legacy suspend/resume callbacks to dev_pm_ops.

Since there isn't anything special to do at the bus level the bus driver
does not have to implement any callbacks. The device driver core will
automatically pick up and execute the device's PM ops.

As there is only a single AC'97 driver implementing suspend and resume,
update both the core and driver at the same time to avoid unnecessary code
churn.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
This patch touches code in both ALSA and the input subsystem. Ideally this
patch will be merged via the ALSA tree. Given that the wm97xx touchscreen
driver is not seeing too many changes these days the risk of conflicts
should be low.
---
 drivers/input/touchscreen/wm97xx-core.c | 13 +++++++------
 sound/ac97_bus.c                        | 26 --------------------------
 2 files changed, 7 insertions(+), 32 deletions(-)

Comments

Dmitry Torokhov Aug. 6, 2015, 10:55 p.m. UTC | #1
Hi,

On Thu, Aug 06, 2015 at 09:42:09PM +0200, Lars-Peter Clausen wrote:
> Convert the ac97_bus from legacy suspend/resume callbacks to dev_pm_ops.
> 
> Since there isn't anything special to do at the bus level the bus driver
> does not have to implement any callbacks. The device driver core will
> automatically pick up and execute the device's PM ops.
> 
> As there is only a single AC'97 driver implementing suspend and resume,
> update both the core and driver at the same time to avoid unnecessary code
> churn.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> ---
> This patch touches code in both ALSA and the input subsystem. Ideally this
> patch will be merged via the ALSA tree. Given that the wm97xx touchscreen
> driver is not seeing too many changes these days the risk of conflicts
> should be low.

That will be fine once the comments below are addressed.

> ---
>  drivers/input/touchscreen/wm97xx-core.c | 13 +++++++------
>  sound/ac97_bus.c                        | 26 --------------------------
>  2 files changed, 7 insertions(+), 32 deletions(-)
> 
> diff --git a/drivers/input/touchscreen/wm97xx-core.c b/drivers/input/touchscreen/wm97xx-core.c
> index b1ae779..1d11fd8 100644
> --- a/drivers/input/touchscreen/wm97xx-core.c
> +++ b/drivers/input/touchscreen/wm97xx-core.c
> @@ -732,8 +732,8 @@ static int wm97xx_remove(struct device *dev)
>  	return 0;
>  }
>  
> -#ifdef CONFIG_PM
> -static int wm97xx_suspend(struct device *dev, pm_message_t state)
> +#ifdef CONFIG_PM_SLEEP
> +static int wm97xx_suspend(struct device *dev)

While we are changing it please drop #ifdef CONFIG_PM_SLEEP and annotate
suspend and resume with __maybe_unused.

>  {
>  	struct wm97xx *wm = dev_get_drvdata(dev);
>  	u16 reg;
> @@ -799,9 +799,11 @@ static int wm97xx_resume(struct device *dev)
>  	return 0;
>  }
>  
> +static SIMPLE_DEV_PM_OPS(wm97xx_pm_ops, wm97xx_suspend, wm97xx_resume);

Pull this out of #ifdef block and kill entire #else/endif along with
WM97XX_PM_OPS define: SIMPLE_DEV_PM_OPS will result in an empty
structure if CONFIG_PM_SLEEP is not set.

> +#define WM97XX_PM_OPS (&wm97xx_pm_ops)
> +
>  #else
> -#define wm97xx_suspend		NULL
> -#define wm97xx_resume		NULL
> +#define WM97XX_PM_OPS NULL
>  #endif
>  
>  /*
> @@ -836,8 +838,7 @@ static struct device_driver wm97xx_driver = {
>  	.owner =	THIS_MODULE,
>  	.probe =	wm97xx_probe,
>  	.remove =	wm97xx_remove,
> -	.suspend =	wm97xx_suspend,
> -	.resume =	wm97xx_resume,
> +	.pm =		WM97XX_PM_OPS,

	.pm		&wm97xx_pm_ops,
>  };
>  
>  static int __init wm97xx_init(void)
> diff --git a/sound/ac97_bus.c b/sound/ac97_bus.c
> index 2b50cbe..57a6dfc 100644
> --- a/sound/ac97_bus.c
> +++ b/sound/ac97_bus.c
> @@ -27,35 +27,9 @@ static int ac97_bus_match(struct device *dev, struct device_driver *drv)
>  	return 1;
>  }
>  
> -#ifdef CONFIG_PM
> -static int ac97_bus_suspend(struct device *dev, pm_message_t state)
> -{
> -	int ret = 0;
> -
> -	if (dev->driver && dev->driver->suspend)
> -		ret = dev->driver->suspend(dev, state);
> -
> -	return ret;
> -}
> -
> -static int ac97_bus_resume(struct device *dev)
> -{
> -	int ret = 0;
> -
> -	if (dev->driver && dev->driver->resume)
> -		ret = dev->driver->resume(dev);
> -
> -	return ret;
> -}
> -#endif /* CONFIG_PM */
> -
>  struct bus_type ac97_bus_type = {
>  	.name		= "ac97",
>  	.match		= ac97_bus_match,
> -#ifdef CONFIG_PM
> -	.suspend	= ac97_bus_suspend,
> -	.resume		= ac97_bus_resume,
> -#endif /* CONFIG_PM */
>  };
>  
>  static int __init ac97_bus_init(void)
> -- 
> 2.1.4
> 

Thanks.
Lars-Peter Clausen Aug. 7, 2015, 8:13 a.m. UTC | #2
On 08/07/2015 12:55 AM, Dmitry Torokhov wrote:
[...]
>>  
>> -#ifdef CONFIG_PM
>> -static int wm97xx_suspend(struct device *dev, pm_message_t state)
>> +#ifdef CONFIG_PM_SLEEP
>> +static int wm97xx_suspend(struct device *dev)
> 
> While we are changing it please drop #ifdef CONFIG_PM_SLEEP and annotate
> suspend and resume with __maybe_unused.

We know that it is used when CONFIG_PM_SLEEP is defined and we know that it
is unused CONFIG_PM_SLEEP is not defined. Marking the function as
__maybe_unused will cause the compiler to not generate a warning when the
function is really unused. Making this explicit works much better.

> 
>>  {
>>  	struct wm97xx *wm = dev_get_drvdata(dev);
>>  	u16 reg;
>> @@ -799,9 +799,11 @@ static int wm97xx_resume(struct device *dev)
>>  	return 0;
>>  }
>>  
>> +static SIMPLE_DEV_PM_OPS(wm97xx_pm_ops, wm97xx_suspend, wm97xx_resume);
> 
> Pull this out of #ifdef block and kill entire #else/endif along with
> WM97XX_PM_OPS define: SIMPLE_DEV_PM_OPS will result in an empty
> structure if CONFIG_PM_SLEEP is not set.

It will create a struct dev_pm_ops full of NULLs. That's kind of
counterproductive to removing PM related data and functions from the kernel
if PM support is no enabled.

> 
>> +#define WM97XX_PM_OPS (&wm97xx_pm_ops)
>> +
>>  #else
>> -#define wm97xx_suspend		NULL
>> -#define wm97xx_resume		NULL
>> +#define WM97XX_PM_OPS NULL
>>  #endif
[...]
Mark Brown Aug. 7, 2015, 1:30 p.m. UTC | #3
On Fri, Aug 07, 2015 at 10:13:48AM +0200, Lars-Peter Clausen wrote:
> On 08/07/2015 12:55 AM, Dmitry Torokhov wrote:

> > Pull this out of #ifdef block and kill entire #else/endif along with
> > WM97XX_PM_OPS define: SIMPLE_DEV_PM_OPS will result in an empty
> > structure if CONFIG_PM_SLEEP is not set.

> It will create a struct dev_pm_ops full of NULLs. That's kind of
> counterproductive to removing PM related data and functions from the kernel
> if PM support is no enabled.

Indeed, a major goal of disabling PM support is to save space.
Dmitry Torokhov Aug. 7, 2015, 4:30 p.m. UTC | #4
On Fri, Aug 07, 2015 at 02:30:05PM +0100, Mark Brown wrote:
> On Fri, Aug 07, 2015 at 10:13:48AM +0200, Lars-Peter Clausen wrote:
> > On 08/07/2015 12:55 AM, Dmitry Torokhov wrote:
> 
> > > Pull this out of #ifdef block and kill entire #else/endif along with
> > > WM97XX_PM_OPS define: SIMPLE_DEV_PM_OPS will result in an empty
> > > structure if CONFIG_PM_SLEEP is not set.
> 
> > It will create a struct dev_pm_ops full of NULLs. That's kind of
> > counterproductive to removing PM related data and functions from the kernel
> > if PM support is no enabled.
> 
> Indeed, a major goal of disabling PM support is to save space.

Then maybe we should adjust dev_pm_ops definition to omit members that
are not used if given state is not supported? We have a lot of drivers
that are not doing silly pointer #define games.
Dmitry Torokhov Aug. 7, 2015, 4:32 p.m. UTC | #5
On Fri, Aug 07, 2015 at 10:13:48AM +0200, Lars-Peter Clausen wrote:
> On 08/07/2015 12:55 AM, Dmitry Torokhov wrote:
> [...]
> >>  
> >> -#ifdef CONFIG_PM
> >> -static int wm97xx_suspend(struct device *dev, pm_message_t state)
> >> +#ifdef CONFIG_PM_SLEEP
> >> +static int wm97xx_suspend(struct device *dev)
> > 
> > While we are changing it please drop #ifdef CONFIG_PM_SLEEP and annotate
> > suspend and resume with __maybe_unused.
> 
> We know that it is used when CONFIG_PM_SLEEP is defined and we know that it
> is unused CONFIG_PM_SLEEP is not defined. Marking the function as
> __maybe_unused will cause the compiler to not generate a warning when the
> function is really unused. Making this explicit works much better.

It will also drop the code form the final image and having the functions
in provides better compile coverage.

Thanks.
Mark Brown Aug. 7, 2015, 4:38 p.m. UTC | #6
On Fri, Aug 07, 2015 at 09:30:29AM -0700, Dmitry Torokhov wrote:
> On Fri, Aug 07, 2015 at 02:30:05PM +0100, Mark Brown wrote:

> > Indeed, a major goal of disabling PM support is to save space.

> Then maybe we should adjust dev_pm_ops definition to omit members that
> are not used if given state is not supported? We have a lot of drivers
> that are not doing silly pointer #define games.

Yeah, I've always been vaugely surprised that we don't do that.
Mark Brown Aug. 20, 2015, 4:33 p.m. UTC | #7
On Fri, Aug 07, 2015 at 09:32:13AM -0700, Dmitry Torokhov wrote:
> On Fri, Aug 07, 2015 at 10:13:48AM +0200, Lars-Peter Clausen wrote:

> > We know that it is used when CONFIG_PM_SLEEP is defined and we know that it
> > is unused CONFIG_PM_SLEEP is not defined. Marking the function as
> > __maybe_unused will cause the compiler to not generate a warning when the
> > function is really unused. Making this explicit works much better.

> It will also drop the code form the final image and having the functions
> in provides better compile coverage.

Just discussed this in person with Dmitry: I'll apply the patch just now
for v4.3 and we can incrementally improve the ifdef handling after.
Lars-Peter Clausen Aug. 20, 2015, 4:35 p.m. UTC | #8
On 08/20/2015 06:33 PM, Mark Brown wrote:
> On Fri, Aug 07, 2015 at 09:32:13AM -0700, Dmitry Torokhov wrote:
>> On Fri, Aug 07, 2015 at 10:13:48AM +0200, Lars-Peter Clausen wrote:
> 
>>> We know that it is used when CONFIG_PM_SLEEP is defined and we know that it
>>> is unused CONFIG_PM_SLEEP is not defined. Marking the function as
>>> __maybe_unused will cause the compiler to not generate a warning when the
>>> function is really unused. Making this explicit works much better.
> 
>> It will also drop the code form the final image and having the functions
>> in provides better compile coverage.
> 
> Just discussed this in person with Dmitry: I'll apply the patch just now
> for v4.3 and we can incrementally improve the ifdef handling after.

Great, thanks. I was about to send a patch with the ifdefs removed tomorrow.
Mark Brown Aug. 20, 2015, 5:18 p.m. UTC | #9
On Thu, Aug 20, 2015 at 06:35:24PM +0200, Lars-Peter Clausen wrote:
> On 08/20/2015 06:33 PM, Mark Brown wrote:

> > Just discussed this in person with Dmitry: I'll apply the patch just now
> > for v4.3 and we can incrementally improve the ifdef handling after.

> Great, thanks. I was about to send a patch with the ifdefs removed tomorrow.

Oh, that'd be even better if we could get that into v4.3 instead - this
was partly given that I'd just met Dmitry and the merge window will be
opening very soon.  If you could get that patch done that'd be even
better.
diff mbox

Patch

diff --git a/drivers/input/touchscreen/wm97xx-core.c b/drivers/input/touchscreen/wm97xx-core.c
index b1ae779..1d11fd8 100644
--- a/drivers/input/touchscreen/wm97xx-core.c
+++ b/drivers/input/touchscreen/wm97xx-core.c
@@ -732,8 +732,8 @@  static int wm97xx_remove(struct device *dev)
 	return 0;
 }
 
-#ifdef CONFIG_PM
-static int wm97xx_suspend(struct device *dev, pm_message_t state)
+#ifdef CONFIG_PM_SLEEP
+static int wm97xx_suspend(struct device *dev)
 {
 	struct wm97xx *wm = dev_get_drvdata(dev);
 	u16 reg;
@@ -799,9 +799,11 @@  static int wm97xx_resume(struct device *dev)
 	return 0;
 }
 
+static SIMPLE_DEV_PM_OPS(wm97xx_pm_ops, wm97xx_suspend, wm97xx_resume);
+#define WM97XX_PM_OPS (&wm97xx_pm_ops)
+
 #else
-#define wm97xx_suspend		NULL
-#define wm97xx_resume		NULL
+#define WM97XX_PM_OPS NULL
 #endif
 
 /*
@@ -836,8 +838,7 @@  static struct device_driver wm97xx_driver = {
 	.owner =	THIS_MODULE,
 	.probe =	wm97xx_probe,
 	.remove =	wm97xx_remove,
-	.suspend =	wm97xx_suspend,
-	.resume =	wm97xx_resume,
+	.pm =		WM97XX_PM_OPS,
 };
 
 static int __init wm97xx_init(void)
diff --git a/sound/ac97_bus.c b/sound/ac97_bus.c
index 2b50cbe..57a6dfc 100644
--- a/sound/ac97_bus.c
+++ b/sound/ac97_bus.c
@@ -27,35 +27,9 @@  static int ac97_bus_match(struct device *dev, struct device_driver *drv)
 	return 1;
 }
 
-#ifdef CONFIG_PM
-static int ac97_bus_suspend(struct device *dev, pm_message_t state)
-{
-	int ret = 0;
-
-	if (dev->driver && dev->driver->suspend)
-		ret = dev->driver->suspend(dev, state);
-
-	return ret;
-}
-
-static int ac97_bus_resume(struct device *dev)
-{
-	int ret = 0;
-
-	if (dev->driver && dev->driver->resume)
-		ret = dev->driver->resume(dev);
-
-	return ret;
-}
-#endif /* CONFIG_PM */
-
 struct bus_type ac97_bus_type = {
 	.name		= "ac97",
 	.match		= ac97_bus_match,
-#ifdef CONFIG_PM
-	.suspend	= ac97_bus_suspend,
-	.resume		= ac97_bus_resume,
-#endif /* CONFIG_PM */
 };
 
 static int __init ac97_bus_init(void)