Commit cc72da7d authored by Takashi Iwai's avatar Takashi Iwai

ALSA: hda - Use standard runtime PM for codec power-save control

Like the previous transition of suspend/resume, now move the
power-save code to the standard runtime PM.  As usual for runtime PM,
it's a bit tricky, but this simplified codes a lot in the end.

For keeping the usage compatibility, power_save module option still
controls the whole power-saving behavior on all codecs.  The value is
translated to pm_runtime_*_autosuspend() and pm_runtime_allow() /
pm_runtime_forbid() calls.

snd_hda_power_up() and snd_hda_power_down() are translated to
pm_runtime_get_sync() and pm_runtime_put_autosuspend(), respectively.
Since we can do call pm_runtime_get_sync() more reliably, the sync
version is used always and snd_hda_power_up_d3wait() is dropped.
Another slight difference is that snd_hda_power_up()/down() don't call
runtime_pm code during the suspend/resume transition phase.  Calling
them there isn't safe unlike our own code, resulted in unexpected
behavior (endless wakeups).

The hda_power_count tracepoint was removed, as it doesn't match well
with the new code.

Last but not least, we need to set ignore_children flag in the parent
dev.power field so that the runtime PM of the controller chip won't
get confused.  The notification is still done in the bus pm_notify
callback.  We'll get rid of this hack in the later patch.
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 59ed1ead
This diff is collapsed.
...@@ -372,17 +372,12 @@ struct hda_codec { ...@@ -372,17 +372,12 @@ struct hda_codec {
unsigned int dp_mst:1; /* support DP1.2 Multi-stream transport */ unsigned int dp_mst:1; /* support DP1.2 Multi-stream transport */
unsigned int dump_coef:1; /* dump processing coefs in codec proc file */ unsigned int dump_coef:1; /* dump processing coefs in codec proc file */
#ifdef CONFIG_PM #ifdef CONFIG_PM
unsigned int power_on :1; /* current (global) power-state */
unsigned int d3_stop_clk:1; /* support D3 operation without BCLK */ unsigned int d3_stop_clk:1; /* support D3 operation without BCLK */
unsigned int pm_up_notified:1; /* PM notified to controller */ unsigned int pm_up_notified:1; /* PM notified to controller */
unsigned int in_pm:1; /* suspend/resume being performed */ atomic_t in_pm; /* suspend/resume being performed */
int power_transition; /* power-state in transition */
int power_count; /* current (global) power refcount */
struct delayed_work power_work; /* delayed task for powerdown */
unsigned long power_on_acct; unsigned long power_on_acct;
unsigned long power_off_acct; unsigned long power_off_acct;
unsigned long power_jiffies; unsigned long power_jiffies;
spinlock_t power_lock;
#endif #endif
/* filter the requested power state per nid */ /* filter the requested power state per nid */
...@@ -595,64 +590,16 @@ const char *snd_hda_get_jack_location(u32 cfg); ...@@ -595,64 +590,16 @@ const char *snd_hda_get_jack_location(u32 cfg);
* power saving * power saving
*/ */
#ifdef CONFIG_PM #ifdef CONFIG_PM
void snd_hda_power_save(struct hda_codec *codec, int delta, bool d3wait); void snd_hda_power_up(struct hda_codec *codec);
void snd_hda_power_down(struct hda_codec *codec);
void snd_hda_power_sync(struct hda_codec *codec);
void snd_hda_update_power_acct(struct hda_codec *codec); void snd_hda_update_power_acct(struct hda_codec *codec);
#else #else
static inline void snd_hda_power_save(struct hda_codec *codec, int delta, static inline void snd_hda_power_up(struct hda_codec *codec) {}
bool d3wait) {} static inline void snd_hda_power_down(struct hda_codec *codec) {}
static inline void snd_hda_power_sync(struct hda_codec *codec) {}
#endif #endif
/**
* snd_hda_power_up - Power-up the codec
* @codec: HD-audio codec
*
* Increment the power-up counter and power up the hardware really when
* not turned on yet.
*/
static inline void snd_hda_power_up(struct hda_codec *codec)
{
snd_hda_power_save(codec, 1, false);
}
/**
* snd_hda_power_up_d3wait - Power-up the codec after waiting for any pending
* D3 transition to complete. This differs from snd_hda_power_up() when
* power_transition == -1. snd_hda_power_up sees this case as a nop,
* snd_hda_power_up_d3wait waits for the D3 transition to complete then powers
* back up.
* @codec: HD-audio codec
*
* Cancel any power down operation hapenning on the work queue, then power up.
*/
static inline void snd_hda_power_up_d3wait(struct hda_codec *codec)
{
snd_hda_power_save(codec, 1, true);
}
/**
* snd_hda_power_down - Power-down the codec
* @codec: HD-audio codec
*
* Decrement the power-up counter and schedules the power-off work if
* the counter rearches to zero.
*/
static inline void snd_hda_power_down(struct hda_codec *codec)
{
snd_hda_power_save(codec, -1, false);
}
/**
* snd_hda_power_sync - Synchronize the power-save status
* @codec: HD-audio codec
*
* Synchronize the actual power state with the power account;
* called when power_save parameter is changed
*/
static inline void snd_hda_power_sync(struct hda_codec *codec)
{
snd_hda_power_save(codec, 0, false);
}
#ifdef CONFIG_SND_HDA_PATCH_LOADER #ifdef CONFIG_SND_HDA_PATCH_LOADER
/* /*
* patch firmware * patch firmware
......
...@@ -836,7 +836,7 @@ static int azx_pcm_open(struct snd_pcm_substream *substream) ...@@ -836,7 +836,7 @@ static int azx_pcm_open(struct snd_pcm_substream *substream)
buff_step); buff_step);
snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
buff_step); buff_step);
snd_hda_power_up_d3wait(apcm->codec); snd_hda_power_up(apcm->codec);
err = hinfo->ops.open(hinfo, apcm->codec, substream); err = hinfo->ops.open(hinfo, apcm->codec, substream);
if (err < 0) { if (err < 0) {
azx_release_device(azx_dev); azx_release_device(azx_dev);
......
...@@ -1087,6 +1087,7 @@ static int azx_free(struct azx *chip) ...@@ -1087,6 +1087,7 @@ static int azx_free(struct azx *chip)
azx_stop_chip(chip); azx_stop_chip(chip);
} }
pci->dev.power.ignore_children = 0; /* FIXME */
if (chip->irq >= 0) if (chip->irq >= 0)
free_irq(chip->irq, (void*)chip); free_irq(chip->irq, (void*)chip);
if (chip->msi) if (chip->msi)
...@@ -1796,6 +1797,7 @@ static int azx_probe(struct pci_dev *pci, ...@@ -1796,6 +1797,7 @@ static int azx_probe(struct pci_dev *pci,
return err; return err;
} }
pci->dev.power.ignore_children = 1; /* FIXME */
err = azx_create(card, pci, dev, pci_id->driver_data, err = azx_create(card, pci, dev, pci_id->driver_data,
&pci_hda_ops, &chip); &pci_hda_ops, &chip);
if (err < 0) if (err < 0)
......
...@@ -87,30 +87,6 @@ DEFINE_EVENT(hda_power, hda_power_up, ...@@ -87,30 +87,6 @@ DEFINE_EVENT(hda_power, hda_power_up,
TP_PROTO(struct hda_codec *codec), TP_PROTO(struct hda_codec *codec),
TP_ARGS(codec) TP_ARGS(codec)
); );
TRACE_EVENT(hda_power_count,
TP_PROTO(struct hda_codec *codec),
TP_ARGS(codec),
TP_STRUCT__entry(
__field( unsigned int, card )
__field( unsigned int, addr )
__field( int, power_count )
__field( int, power_on )
__field( int, power_transition )
),
TP_fast_assign(
__entry->card = (codec)->bus->card->number;
__entry->addr = (codec)->addr;
__entry->power_count = (codec)->power_count;
__entry->power_on = (codec)->power_on;
__entry->power_transition = (codec)->power_transition;
),
TP_printk("[%d:%d] power_count=%d, power_on=%d, power_transition=%d",
__entry->card, __entry->addr, __entry->power_count,
__entry->power_on, __entry->power_transition)
);
#endif /* CONFIG_PM */ #endif /* CONFIG_PM */
TRACE_EVENT(hda_unsol_event, TRACE_EVENT(hda_unsol_event,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment