amba: Drop legacy PM support and some other PM improvements
Subsystems (5)
cover amba: Drop legacy PM support and some other PM improvements
This patch set start by converting a few AMBA drivers to use the modern PM ops. Once the final driver is converted we are able to remove the legacy PM support in the AMBA bus in patch 4.
Patch 5 is a cleanup patch related to clocks. Patch 6 improves the runtime PM support around clock handling.
Ulf Hansson (6):
ALSA: AACI: Convert to modern PM ops
serial: pl010: Convert to modern PM ops
serial: pl011: Convert to modern PM ops
amba: Drop legacy PM support and use the pm_generic functions
amba: Convert to clk_prepare_enable and clk_disable_unprepare
amba: Add clk_prepare|unprepare in runtime PM callbacks
drivers/amba/bus.c | 214 +++------------------------------------ drivers/tty/serial/amba-pl010.c | 15 +-- drivers/tty/serial/amba-pl011.c | 17 ++-- sound/arm/aaci.c | 23 ++--- 4 files changed, 43 insertions(+), 226 deletions(-)
Signature · 1 line
1.7.9.5
PATCH 1/6 ALSA: AACI: Convert to modern PM ops
Even if the CONFIG_PM explicity is undefined, let's convert to the modern PM ops.
--- sound/arm/aaci.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-)
sound/arm/aaci.c +11 -12
@@ -753,7 +753,7 @@ static struct snd_pcm_ops aaci_capture_ops = {* Power Management. */ #ifdef CONFIG_PM -static int aaci_do_suspend (struct snd_card *card,unsigned int state) +static int aaci_do_suspend (struct snd_card *card) {struct aaci *aaci = card->private_data;snd_power_change_state (card, SNDRV_CTL_POWER_D3cold);
@@ -761,28 +761,28 @@ static int aaci_do_suspend(struct snd_card *card, unsigned int state)return 0 ; } -static int aaci_do_resume (struct snd_card *card,unsigned int state) +static int aaci_do_resume (struct snd_card *card) {snd_power_change_state (card,SNDRV_CTL_POWER_D0 );return 0 ; } -static int aaci_suspend (struct amba_device *dev,pm_message_t state) +static int aaci_suspend (struct device *dev) { -struct snd_card *card =amba_get_drvdata (dev); +struct snd_card *card =dev_get_drvdata (dev);return card ?aaci_do_suspend (card) :0 ; } -static int aaci_resume (struct amba_device *dev) +static int aaci_resume (struct device *dev) { -struct snd_card *card =amba_get_drvdata (dev); +struct snd_card *card =dev_get_drvdata (dev);return card ?aaci_do_resume (card) :0 ; } + +static SIMPLE_DEV_PM_OPS(aaci_dev_pm_ops, aaci_suspend, aaci_resume); +#define AACI_DEV_PM_OPS (&aaci_dev_pm_ops)#else -#define aaci_do_suspend NULL -#define aaci_do_resume NULL -#define aaci_suspend NULL -#define aaci_resume NULL +#define AACI_DEV_PM_OPS NULL#endif
@@ -1100,11 +1100,10 @@ MODULE_DEVICE_TABLE(amba, aaci_ids);static struct amba_driver aaci_driver = { .drv = { .name =DRIVER_NAME , + .pm =AACI_DEV_PM_OPS , }, .probe = aaci_probe, .remove = aaci_remove, - .suspend = aaci_suspend, - .resume = aaci_resume, .id_table = aaci_ids, };
Signature · 1 line
1.7.9.5
Takashi Iwai
AppliedPATCH 1/6 ALSA: AACI: Convert to modern PM ops
At Tue, 3 Dec 2013 11:04:26 +0100,
Quoted 7 lines · Ulf Hansson
Even if the
CONFIG_PMexplicity is undefined, let's convert to the modern PM ops.Cc Takashi Iwai <[email protected]>Cc Jaroslav Kysela <[email protected]>Signed-off-by Ulf Hansson <[email protected]>
Thanks, applied.
Takashi
Quoted 71 lines
--- sound/arm/aaci.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-)sound/arm/aaci.c +11
-12@@ -753,7 +753,7 @@ static struct snd_pcm_ops aaci_capture_ops = {* Power Management. */ #ifdef CONFIG_PM -static int aaci_do_suspend (struct snd_card *card,unsigned int state) +static int aaci_do_suspend (struct snd_card *card) {struct aaci *aaci = card->private_data;snd_power_change_state (card, SNDRV_CTL_POWER_D3cold);@@ -761,28 +761,28 @@ static int aaci_do_suspend(struct snd_card *card, unsigned int state)return 0 ; } -static int aaci_do_resume (struct snd_card *card,unsigned int state) +static int aaci_do_resume (struct snd_card *card) {snd_power_change_state (card,SNDRV_CTL_POWER_D0 );return 0 ; } -static int aaci_suspend (struct amba_device *dev,pm_message_t state) +static int aaci_suspend (struct device *dev) { -struct snd_card *card =amba_get_drvdata (dev); +struct snd_card *card =dev_get_drvdata (dev);return card ?aaci_do_suspend (card) :0 ; } -static int aaci_resume (struct amba_device *dev) +static int aaci_resume (struct device *dev) { -struct snd_card *card =amba_get_drvdata (dev); +struct snd_card *card =dev_get_drvdata (dev);return card ?aaci_do_resume (card) :0 ; } + +static SIMPLE_DEV_PM_OPS(aaci_dev_pm_ops, aaci_suspend, aaci_resume); +#define AACI_DEV_PM_OPS (&aaci_dev_pm_ops)#else -#define aaci_do_suspend NULL -#define aaci_do_resume NULL -#define aaci_suspend NULL -#define aaci_resume NULL +#define AACI_DEV_PM_OPS NULL#endif @@ -1100,11 +1100,10 @@ MODULE_DEVICE_TABLE(amba, aaci_ids);static struct amba_driver aaci_driver = { .drv = { .name =DRIVER_NAME , + .pm =AACI_DEV_PM_OPS , }, .probe = aaci_probe, .remove = aaci_remove, - .suspend = aaci_suspend, - .resume = aaci_resume, .id_table = aaci_ids, };Signature · 1 line
1.7.9.5
PATCH 2/6 serial: pl010: Convert to modern PM ops
In reply to Ulf HanssonConvert to modern PM ops and use the SIMPLE_DEV_PM_OPS macro to set up the PM callbacks.
--- drivers/tty/serial/amba-pl010.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/tty/serial/amba-pl010.c +9 -6
@@ -756,9 +756,10 @@ static int pl010_remove(struct amba_device *dev)return 0 ; } -static int pl010_suspend (struct amba_device *dev,pm_message_t state) +#ifdef CONFIG_PM_SLEEP +static int pl010_suspend (struct device *dev) { -struct uart_amba_port *uap =amba_get_drvdata (dev); +struct uart_amba_port *uap =dev_get_drvdata (dev);if (uap)uart_suspend_port (&amba_reg, &uap->port);
@@ -766,15 +767,18 @@ static int pl010_suspend(struct amba_device *dev, pm_message_t state)return 0 ; } -static int pl010_resume (struct amba_device *dev) +static int pl010_resume (struct device *dev) { -struct uart_amba_port *uap =amba_get_drvdata (dev); +struct uart_amba_port *uap =dev_get_drvdata (dev);if (uap)uart_resume_port (&amba_reg, &uap->port);return 0 ; } +#endif + +static SIMPLE_DEV_PM_OPS(pl010_dev_pm_ops, pl010_suspend, pl010_resume);static struct amba_id pl010_ids[] = { {
@@ -789,12 +793,11 @@ MODULE_DEVICE_TABLE(amba, pl010_ids);static struct amba_driver pl010_driver = { .drv = { .name ="uart-pl010" , + .pm = &pl010_dev_pm_ops, }, .id_table = pl010_ids, .probe = pl010_probe, .remove = pl010_remove, - .suspend = pl010_suspend, - .resume = pl010_resume, };static int __init pl010_init (void )
Signature · 1 line
1.7.9.5
PATCH 3/6 serial: pl011: Convert to modern PM ops
In reply to Ulf HanssonConvert to modern PM ops and use the SIMPLE_DEV_PM_OPS macro to set up the PM callbacks.
--- drivers/tty/serial/amba-pl011.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/tty/serial/amba-pl011.c +8 -9
@@ -2169,10 +2169,10 @@ static int pl011_remove(struct amba_device *dev)return 0 ; } -#ifdef CONFIG_PM -static int pl011_suspend (struct amba_device *dev,pm_message_t state) +#ifdef CONFIG_PM_SLEEP +static int pl011_suspend (struct device *dev) { -struct uart_amba_port *uap =amba_get_drvdata (dev); +struct uart_amba_port *uap =dev_get_drvdata (dev);if (!uap)return -EINVAL ;
@@ -2180,9 +2180,9 @@ static int pl011_suspend(struct amba_device *dev, pm_message_t state)return uart_suspend_port (&amba_reg, &uap->port); } -static int pl011_resume (struct amba_device *dev) +static int pl011_resume (struct device *dev) { -struct uart_amba_port *uap =amba_get_drvdata (dev); +struct uart_amba_port *uap =dev_get_drvdata (dev);if (!uap)return -EINVAL ;
@@ -2191,6 +2191,8 @@ static int pl011_resume(struct amba_device *dev) }#endif +static SIMPLE_DEV_PM_OPS(pl011_dev_pm_ops, pl011_suspend, pl011_resume); +static struct amba_id pl011_ids[] = { { .id =0x00041011 ,
@@ -2210,14 +2212,11 @@ MODULE_DEVICE_TABLE(amba, pl011_ids);static struct amba_driver pl011_driver = { .drv = { .name ="uart-pl011" , + .pm = &pl011_dev_pm_ops, }, .id_table = pl011_ids, .probe = pl011_probe, .remove = pl011_remove, -#ifdef CONFIG_PM - .suspend = pl011_suspend, - .resume = pl011_resume, -#endif };static int __init pl011_init (void )
Signature · 1 line
1.7.9.5
PATCH 4/6 amba: Drop legacy PM support and use the pm_generic functions
In reply to Ulf HanssonAll AMBA drivers have converted to use the modern PM ops thus we can safely drop the legacy PM support from the bus.
While using the modern PM ops it also makes sense to convert to use the pm_generic callback functions.
--- drivers/amba/bus.c | 180 ++-------------------------------------------------- 1 file changed, 7 insertions(+), 173 deletions(-)
drivers/amba/bus.c +7 -173
@@ -83,162 +83,6 @@ static struct device_attribute amba_dev_attrs[] = { __ATTR_NULL, }; -#ifdef CONFIG_PM_SLEEP - -static int amba_legacy_suspend (struct device *dev,pm_message_t mesg) -{ -struct amba_driver *adrv =to_amba_driver (dev->driver); -struct amba_device *adev =to_amba_device (dev); -int ret =0 ; - -if (dev->driver && adrv->suspend) - ret = adrv->suspend (adev, mesg); - -return ret; -} - -static int amba_legacy_resume (struct device *dev) -{ -struct amba_driver *adrv =to_amba_driver (dev->driver); -struct amba_device *adev =to_amba_device (dev); -int ret =0 ; - -if (dev->driver && adrv->resume) - ret = adrv->resume (adev); - -return ret; -} - -#endif /* CONFIG_PM_SLEEP */ - -#ifdef CONFIG_SUSPEND - -static int amba_pm_suspend (struct device *dev) -{ -struct device_driver *drv = dev->driver; -int ret =0 ; - -if (!drv) -return 0 ; - -if (drv->pm) { -if (drv->pm->suspend) - ret = drv->pm->suspend (dev); - }else { - ret =amba_legacy_suspend (dev,PMSG_SUSPEND ); - } - -return ret; -} - -static int amba_pm_resume (struct device *dev) -{ -struct device_driver *drv = dev->driver; -int ret =0 ; - -if (!drv) -return 0 ; - -if (drv->pm) { -if (drv->pm->resume) - ret = drv->pm->resume (dev); - }else { - ret =amba_legacy_resume (dev); - } - -return ret; -} - -#else /* !CONFIG_SUSPEND */ - -#define amba_pm_suspend NULL -#define amba_pm_resume NULL - -#endif /* !CONFIG_SUSPEND */ - -#ifdef CONFIG_HIBERNATE_CALLBACKS - -static int amba_pm_freeze (struct device *dev) -{ -struct device_driver *drv = dev->driver; -int ret =0 ; - -if (!drv) -return 0 ; - -if (drv->pm) { -if (drv->pm->freeze) - ret = drv->pm->freeze (dev); - }else { - ret =amba_legacy_suspend (dev,PMSG_FREEZE ); - } - -return ret; -} - -static int amba_pm_thaw (struct device *dev) -{ -struct device_driver *drv = dev->driver; -int ret =0 ; - -if (!drv) -return 0 ; - -if (drv->pm) { -if (drv->pm->thaw) - ret = drv->pm->thaw (dev); - }else { - ret =amba_legacy_resume (dev); - } - -return ret; -} - -static int amba_pm_poweroff (struct device *dev) -{ -struct device_driver *drv = dev->driver; -int ret =0 ; - -if (!drv) -return 0 ; - -if (drv->pm) { -if (drv->pm->poweroff) - ret = drv->pm->poweroff (dev); - }else { - ret =amba_legacy_suspend (dev,PMSG_HIBERNATE ); - } - -return ret; -} - -static int amba_pm_restore (struct device *dev) -{ -struct device_driver *drv = dev->driver; -int ret =0 ; - -if (!drv) -return 0 ; - -if (drv->pm) { -if (drv->pm->restore) - ret = drv->pm->restore (dev); - }else { - ret =amba_legacy_resume (dev); - } - -return ret; -} - -#else /* !CONFIG_HIBERNATE_CALLBACKS */ - -#define amba_pm_freeze NULL -#define amba_pm_thaw NULL -#define amba_pm_poweroff NULL -#define amba_pm_restore NULL - -#endif /* !CONFIG_HIBERNATE_CALLBACKS */ -#ifdef CONFIG_PM_RUNTIME /* * Hooks to provide runtime PM of the pclk (bus clock). It is safe to
@@ -272,15 +116,13 @@ static int amba_pm_runtime_resume(struct device *dev) }#endif -#ifdef CONFIG_PM -static const struct dev_pm_ops amba_pm = { - .suspend = amba_pm_suspend, - .resume = amba_pm_resume, - .freeze = amba_pm_freeze, - .thaw = amba_pm_thaw, - .poweroff = amba_pm_poweroff, - .restore = amba_pm_restore, + .suspend = pm_generic_suspend, + .resume = pm_generic_resume, + .freeze = pm_generic_freeze, + .thaw = pm_generic_thaw, + .poweroff = pm_generic_poweroff, + .restore = pm_generic_restore, SET_RUNTIME_PM_OPS( amba_pm_runtime_suspend, amba_pm_runtime_resume,
@@ -288,14 +130,6 @@ static const struct dev_pm_ops amba_pm = { ) }; -#define AMBA_PM (&amba_pm) - -#else /* !CONFIG_PM */ - -#define AMBA_PM NULL - -#endif /* !CONFIG_PM */ -/* * Primecells are part of the Advanced Microcontroller Bus Architecture, * so we call the bus "amba".
@@ -305,7 +139,7 @@ struct bus_type amba_bustype = { .dev_attrs = amba_dev_attrs, .match = amba_match, .uevent = amba_uevent, - .pm = AMBA_PM, + .pm = &amba_pm, };static int __init amba_init (void )
Signature · 1 line
1.7.9.5
PATCH 5/6 amba: Convert to clk_prepare_enable and clk_disable_unprepare
In reply to Ulf HanssonTo simplify code and error handling let's use clk_prepare_enable and clk_disable_unprepare. No functional change.
--- drivers/amba/bus.c | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-)
drivers/amba/bus.c +6 -24
@@ -151,36 +151,18 @@ postcore_initcall(amba_init);static int amba_get_enable_pclk (struct amba_device *pcdev) { -struct clk *pclk =clk_get (&pcdev->dev,"apb_pclk" ); -int ret; - - pcdev->pclk = pclk; - -if (IS_ERR (pclk)) -return PTR_ERR (pclk); + pcdev->pclk =clk_get (&pcdev->dev,"apb_pclk" ); - ret =clk_prepare (pclk); -if (ret) { -clk_put (pclk); -return ret; - } +if (IS_ERR (pcdev->pclk)) +return PTR_ERR (pcdev->pclk); - ret =clk_enable (pclk); -if (ret) { -clk_unprepare (pclk); -clk_put (pclk); - } - -return ret; +return clk_prepare_enable (pcdev->pclk); }static void amba_put_disable_pclk (struct amba_device *pcdev) { -struct clk *pclk = pcdev->pclk; - -clk_disable (pclk); -clk_unprepare (pclk); -clk_put (pclk); +clk_disable_unprepare (pcdev->pclk); +clk_put (pcdev->pclk); }/*
Signature · 1 line
1.7.9.5
PATCH 5/6 amba: Convert to clk_prepare_enable and clk_disable_unprepare
Quoted 2 lines · Ulf Hansson
To simplify code and error handling let's use
clk_prepare_enableandclk_disable_unprepare. No functional change.
Not true.
Quoted 28 lines
Signed-off-by Ulf Hansson <[email protected]>--- drivers/amba/bus.c | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-)drivers/amba/bus.c +2
-12@@ -151,36 +151,18 @@ postcore_initcall(amba_init);static int amba_get_enable_pclk (struct amba_device *pcdev) { -struct clk *pclk =clk_get (&pcdev->dev,"apb_pclk" ); -int ret; - - pcdev->pclk = pclk; - -if (IS_ERR (pclk)) -return PTR_ERR (pclk); + pcdev->pclk =clk_get (&pcdev->dev,"apb_pclk" ); - ret =clk_prepare (pclk); -if (ret) { -clk_put (pclk); -return ret; - } +if (IS_ERR (pcdev->pclk))
drivers/amba/bus.c postcore_initcall(amba_init); · line 159
Quoted 10 lines
drivers/amba/bus.c +2
-7+return PTR_ERR (pcdev->pclk); - ret =clk_enable (pclk); -if (ret) { -clk_unprepare (pclk); -clk_put (pclk); - } - -return ret; +return clk_prepare_enable (pcdev->pclk);
There is clearly a change here in the error handling.
PATCH 5/6 amba: Convert to clk_prepare_enable and clk_disable_unprepare
Quoted 36 lines · Russell King - ARM Linux
Quoted 2 lines · Ulf Hansson
To simplify code and error handling let's use
clk_prepare_enableandclk_disable_unprepare. No functional change.Not true.
Quoted 30 lines
Signed-off-by Ulf Hansson <[email protected]>--- drivers/amba/bus.c | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-)drivers/amba/bus.c +3
-12@@ -151,36 +151,18 @@ postcore_initcall(amba_init);static int amba_get_enable_pclk (struct amba_device *pcdev) { -struct clk *pclk =clk_get (&pcdev->dev,"apb_pclk" ); -int ret; - - pcdev->pclk = pclk; - -if (IS_ERR (pclk)) -return PTR_ERR (pclk); + pcdev->pclk =clk_get (&pcdev->dev,"apb_pclk" ); - ret =clk_prepare (pclk); -if (ret) { -clk_put (pclk); -return ret; - } +if (IS_ERR (pcdev->pclk)) +return PTR_ERR (pcdev->pclk);
Quoted 10 lines
drivers/amba/bus.c postcore_initcall(amba_init); · line 159
Quoted 8 lines
drivers/amba/bus.c +1
-7- ret =clk_enable (pclk); -if (ret) { -clk_unprepare (pclk); -clk_put (pclk); - } - -return ret; +return clk_prepare_enable (pcdev->pclk);There is clearly a change here in the error handling.
Thanks for quick review and sorry for this obvious mistake. V2 on it's way.
Kind regards
Ulf Hansson
PATCH 6/6 amba: Add clk_prepare|unprepare in runtime PM callbacks
In reply to Ulf HanssonTo fully gate the clock and thus potentially also save more power in runtime suspend state, extend clock handling with clk_prepare|unprepare in the runtime PM callbacks.
--- drivers/amba/bus.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/amba/bus.c +2 -2
@@ -95,7 +95,7 @@ static int amba_pm_runtime_suspend(struct device *dev)int ret =pm_generic_runtime_suspend (dev);if (ret ==0 && dev->driver) -clk_disable (pcdev->pclk); +clk_disable_unprepare (pcdev->pclk);return ret; }
@@ -106,7 +106,7 @@ static int amba_pm_runtime_resume(struct device *dev)int ret;if (dev->driver) { - ret =clk_enable (pcdev->pclk); + ret =clk_prepare_enable (pcdev->pclk);/* Failure is probably fatal to the system, but... */ if (ret)return ret;
Signature · 1 line
1.7.9.5