Skip to contentSkip to conversation

ALSA: hda - add runtime PM support

PATCH In review [email protected] 2 participants 4 messages Aug 23, 2012 Sound

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 ALSA: hda - add runtime PM support

From: Mengdong Lin <[email protected]>

Runtime PM can bring more power saving:
- When the controller is suspended, its parent device will also have a chance to suspend.
- PCI subsystem can choose the lowest power state the controller can signal wake up from. This state can be D3cold on platforms with ACPI PM support.
And runtime PM can provide a gerneral sysfs interface for a system policy manager.

Runtime PM support is based on current HDA power saving implementation. The user can enable runtime PM on platfroms that provide acceptable latency on transition from D3 to D0.

Details:
- When both power saving and runtime PM are enabled:
-- If a codec supports 'stop-clock' in D3, it will request suspending the
controller after it enters D3 and request resuming the controller before back to D0. Thus the controller will be suspended only when all codecs are suspended and support stop-clock in D3.
-- User IO operations and HW wakeup signal can resume the controller back to

     D0.

- If runtime PM is disabled, power saving just works as before.
- If power saving is disabled, the controller won't be suspended because the power usage counter can never be 0.

More about 'stop-clock' feature:
If a codec can support targeted pass-through operations in D3 state when there is no BCLK present on the link, it will set CLKSTOP flag in the supported power states and report PS-ClkStopOk when entering D3 state. Please refer to HDA spec section 7.3.3.10 Power state and 7.3.4.12 Supported Power State.

---
 sound/pci/hda/hda_codec.c |   19 ++++++++++--
 sound/pci/hda/hda_codec.h |    5 ++-
 sound/pci/hda/hda_intel.c |   75 +++++++++++++++++++++++++++++++++++----------
 3 files changed, 80 insertions(+), 19 deletions(-)
sound/pci/hda/hda_codec.c +17 -2
index f2f5347..d6b3a6d 100644
@@ -1209,6 +1209,9 @@ static void snd_hda_codec_free(struct hda_codec *codec)
 	kfree(codec);
 }
 
+static bool snd_hda_codec_get_supported_ps(struct hda_codec *codec,
+				hda_nid_t fg, unsigned int power_state);
+
 static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
 				unsigned int power_state);
 
@@ -1317,6 +1320,12 @@ int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus,
 					   AC_VERB_GET_SUBSYSTEM_ID, 0);
 	}
 
+	codec->d3_stop_clk = snd_hda_codec_get_supported_ps(codec,
+					codec->afg ? codec->afg : codec->mfg,
+					AC_PWRST_CLKSTOP);
+	if (!codec->d3_stop_clk)
+		bus->power_keep_link_on = 1;
+
 	/* power-up all before initialization */
 	hda_set_power_state(codec,
 			    codec->afg ? codec->afg : codec->mfg,
@@ -3514,6 +3523,8 @@ static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
 	int count;
 	unsigned int state;
 
+	codec->d3_stop_clk_ok = 0;
+
 	if (codec->patch_ops.set_power_state) {
 		codec->patch_ops.set_power_state(codec, fg, power_state);
 		return;
@@ -3536,6 +3547,10 @@ static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
 		if (!(state & AC_PWRST_ERROR))
 			break;
 	}
+
+	if ((power_state == AC_PWRST_D3)
+		&& codec->d3_stop_clk && (state & AC_PWRST_CLK_STOP_OK))
+		codec->d3_stop_clk_ok = 1;
 }
 
 #ifdef CONFIG_SND_HDA_HWDEP
@@ -4385,7 +4400,7 @@ static void hda_power_work(struct work_struct *work)
 
 	hda_call_codec_suspend(codec);
 	if (bus->ops.pm_notify)
-		bus->ops.pm_notify(bus);
+		bus->ops.pm_notify(bus, codec);
 }
 
 static void hda_keep_power_on(struct hda_codec *codec)
@@ -4440,7 +4455,7 @@ static void __snd_hda_power_up(struct hda_codec *codec, bool wait_power_down)
 	spin_unlock(&codec->power_lock);
 
 	if (bus->ops.pm_notify)
-		bus->ops.pm_notify(bus);
+		bus->ops.pm_notify(bus, codec);
 	hda_call_codec_resume(codec);
 
 	spin_lock(&codec->power_lock);
sound/pci/hda/hda_codec.h +4 -1
index fe6206b..b384c721 100644
@@ -612,7 +612,7 @@ struct hda_bus_ops {
 	void (*bus_reset)(struct hda_bus *bus);
 #ifdef CONFIG_SND_HDA_POWER_SAVE
 	/* notify power-up/down from codec to controller */
-	void (*pm_notify)(struct hda_bus *bus);
+	void (*pm_notify)(struct hda_bus *bus, struct hda_codec *codec);
 #endif
 };
 
@@ -870,6 +870,9 @@ struct hda_codec {
 	unsigned long power_off_acct;
 	unsigned long power_jiffies;
 	spinlock_t power_lock;
+
+	unsigned int d3_stop_clk:1;	/* support D3 operation without BCLK */
+	unsigned int d3_stop_clk_ok:1; /* BCLK can stop */
 #endif
 
 	/* codec-specific additional proc output */
sound/pci/hda/hda_intel.c +59 -16

132 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#1 lore raw

At Thu, 23 Aug 2012 17:32:30 +0800,

Quoted 27 lines · [email protected] wrote:

From: Mengdong Lin <[email protected]>

Runtime PM can bring more power saving:
- When the controller is suspended, its parent device will also have a chance to suspend.
- PCI subsystem can choose the lowest power state the controller can signal wake up from. This state can be D3cold on platforms with ACPI PM support.
And runtime PM can provide a gerneral sysfs interface for a system policy manager.

Runtime PM support is based on current HDA power saving implementation. The user can enable runtime PM on platfroms that provide acceptable latency on transition from D3 to D0.

Details:
- When both power saving and runtime PM are enabled:
-- If a codec supports 'stop-clock' in D3, it will request suspending the
controller after it enters D3 and request resuming the controller before back to D0. Thus the controller will be suspended only when all codecs are suspended and support stop-clock in D3.
-- User IO operations and HW wakeup signal can resume the controller back to

     D0.

- If runtime PM is disabled, power saving just works as before.
- If power saving is disabled, the controller won't be suspended because the power usage counter can never be 0.

Quoted 7 lines

More about 'stop-clock' feature:
If a codec can support targeted pass-through operations in D3 state when there is no BCLK present on the link, it will set CLKSTOP flag in the supported power states and report PS-ClkStopOk when entering D3 state. Please refer to HDA spec section 7.3.3.10 Power state and 7.3.4.12 Supported Power State.

Thanks, the patch looks almost good, but it gives a build error when CONFIG_PM_RUNTIME=n.

sound/pci/hda/hda_intel.c: In function ‘azx_interrupt’:
sound/pci/hda/hda_intel.c:1292:26: error: ‘struct dev_pm_info’ has no member named ‘runtime_status’ sound/pci/hda/hda_intel.c: At top level:
sound/pci/hda/hda_intel.c:2522:12: warning: ‘azx_runtime_suspend’ defined but not used [-Wunused-function] sound/pci/hda/hda_intel.c:2535:12: warning: ‘azx_runtime_resume’ defined but not used [-Wunused-function]

Takashi
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#2 lore raw

At Thu, 23 Aug 2012 12:00:53 +0200,

Quoted 38 lines · Takashi Iwai

At Thu, 23 Aug 2012 17:32:30 +0800,

Quoted 27 lines · [email protected] wrote:

From: Mengdong Lin <[email protected]>

Runtime PM can bring more power saving:
- When the controller is suspended, its parent device will also have a chance to suspend.
- PCI subsystem can choose the lowest power state the controller can signal wake up from. This state can be D3cold on platforms with ACPI PM support.
And runtime PM can provide a gerneral sysfs interface for a system policy manager.

Runtime PM support is based on current HDA power saving implementation. The user can enable runtime PM on platfroms that provide acceptable latency on transition from D3 to D0.

Details:
- When both power saving and runtime PM are enabled:
-- If a codec supports 'stop-clock' in D3, it will request suspending the
controller after it enters D3 and request resuming the controller before back to D0. Thus the controller will be suspended only when all codecs are suspended and support stop-clock in D3.
-- User IO operations and HW wakeup signal can resume the controller back to

     D0.

- If runtime PM is disabled, power saving just works as before.
- If power saving is disabled, the controller won't be suspended because the power usage counter can never be 0.

Quoted 7 lines

More about 'stop-clock' feature:
If a codec can support targeted pass-through operations in D3 state when there is no BCLK present on the link, it will set CLKSTOP flag in the supported power states and report PS-ClkStopOk when entering D3 state. Please refer to HDA spec section 7.3.3.10 Power state and 7.3.4.12 Supported Power State.

Quoted 8 lines

Thanks, the patch looks almost good, but it gives a build error when CONFIG_PM_RUNTIME=n.

sound/pci/hda/hda_intel.c: In function ‘azx_interrupt’:
sound/pci/hda/hda_intel.c:1292:26: error: ‘struct dev_pm_info’ has no member named ‘runtime_status’ sound/pci/hda/hda_intel.c: At top level:
sound/pci/hda/hda_intel.c:2522:12: warning: ‘azx_runtime_suspend’ defined but not used [-Wunused-function] sound/pci/hda/hda_intel.c:2535:12: warning: ‘azx_runtime_resume’ defined but not used [-Wunused-function]

Never mind, I fixed this by myself and applied the patch.

thanks,

Takashi
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#3 lore raw
Quoted 8 lines

-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]

Quoted 5 lines

Thanks, the patch looks almost good, but it gives a build error when CONFIG_PM_RUNTIME=n.

sound/pci/hda/hda_intel.c: In function ‘azx_interrupt’:
sound/pci/hda/hda_intel.c:1292:26: error: ‘struct dev_pm_info’ has no

Quoted 8 lines

member named ‘runtime_status’

Quoted 5 lines

sound/pci/hda/hda_intel.c: At top level:
sound/pci/hda/hda_intel.c:2522:12: warning: ‘azx_runtime_suspend’ defined but not used [-Wunused-function] sound/pci/hda/hda_intel.c:2535:12: warning: ‘azx_runtime_resume’ defined but not used [-Wunused-function]

Never mind, I fixed this by myself and applied the patch.

Thank you so much! I will be more careful next time.

Mengdong
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel