Commit 9419ab6b authored by Takashi Iwai's avatar Takashi Iwai

ALSA: hda - Add power state filtering

Add a hook to struct hda_codec for filtering the target power state of
each widget when powering up/down.  The current hackish EAPD check is
implemented as the default hook pointer, too.

This allows codec drivers to implement own power filter.  In the
upcoming changes, the generic parser will have the better power filter
based on the active paths.
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 25368c47
...@@ -1276,6 +1276,8 @@ static bool snd_hda_codec_get_supported_ps(struct hda_codec *codec, ...@@ -1276,6 +1276,8 @@ static bool snd_hda_codec_get_supported_ps(struct hda_codec *codec,
static unsigned int hda_set_power_state(struct hda_codec *codec, static unsigned int hda_set_power_state(struct hda_codec *codec,
unsigned int power_state); unsigned int power_state);
static unsigned int default_power_filter(struct hda_codec *codec, hda_nid_t nid,
unsigned int power_state);
/** /**
* snd_hda_codec_new - create a HDA codec * snd_hda_codec_new - create a HDA codec
...@@ -1396,6 +1398,7 @@ int snd_hda_codec_new(struct hda_bus *bus, ...@@ -1396,6 +1398,7 @@ int snd_hda_codec_new(struct hda_bus *bus,
#endif #endif
codec->epss = snd_hda_codec_get_supported_ps(codec, fg, codec->epss = snd_hda_codec_get_supported_ps(codec, fg,
AC_PWRST_EPSS); AC_PWRST_EPSS);
codec->power_filter = default_power_filter;
/* power-up all before initialization */ /* power-up all before initialization */
hda_set_power_state(codec, AC_PWRST_D0); hda_set_power_state(codec, AC_PWRST_D0);
...@@ -3649,29 +3652,23 @@ void snd_hda_codec_flush_cache(struct hda_codec *codec) ...@@ -3649,29 +3652,23 @@ void snd_hda_codec_flush_cache(struct hda_codec *codec)
EXPORT_SYMBOL_HDA(snd_hda_codec_flush_cache); EXPORT_SYMBOL_HDA(snd_hda_codec_flush_cache);
void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg, void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg,
unsigned int power_state, unsigned int power_state)
bool eapd_workaround)
{ {
hda_nid_t nid = codec->start_nid; hda_nid_t nid = codec->start_nid;
int i; int i;
for (i = 0; i < codec->num_nodes; i++, nid++) { for (i = 0; i < codec->num_nodes; i++, nid++) {
unsigned int wcaps = get_wcaps(codec, nid); unsigned int wcaps = get_wcaps(codec, nid);
unsigned int state = power_state;
if (!(wcaps & AC_WCAP_POWER)) if (!(wcaps & AC_WCAP_POWER))
continue; continue;
/* don't power down the widget if it controls eapd and if (codec->power_filter) {
* EAPD_BTLENABLE is set. state = codec->power_filter(codec, nid, power_state);
*/ if (state != power_state && power_state == AC_PWRST_D3)
if (eapd_workaround && power_state == AC_PWRST_D3 &&
get_wcaps_type(wcaps) == AC_WID_PIN &&
(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)) {
int eapd = snd_hda_codec_read(codec, nid, 0,
AC_VERB_GET_EAPD_BTLENABLE, 0);
if (eapd & 0x02)
continue; continue;
} }
snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE,
power_state); state);
} }
} }
EXPORT_SYMBOL_HDA(snd_hda_codec_set_power_to_all); EXPORT_SYMBOL_HDA(snd_hda_codec_set_power_to_all);
...@@ -3718,6 +3715,21 @@ static unsigned int hda_sync_power_state(struct hda_codec *codec, ...@@ -3718,6 +3715,21 @@ static unsigned int hda_sync_power_state(struct hda_codec *codec,
return state; return state;
} }
/* don't power down the widget if it controls eapd and EAPD_BTLENABLE is set */
static unsigned int default_power_filter(struct hda_codec *codec, hda_nid_t nid,
unsigned int power_state)
{
if (power_state == AC_PWRST_D3 &&
get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_PIN &&
(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)) {
int eapd = snd_hda_codec_read(codec, nid, 0,
AC_VERB_GET_EAPD_BTLENABLE, 0);
if (eapd & 0x02)
return AC_PWRST_D0;
}
return power_state;
}
/* /*
* set power state of the codec, and return the power state * set power state of the codec, and return the power state
*/ */
...@@ -3743,8 +3755,7 @@ static unsigned int hda_set_power_state(struct hda_codec *codec, ...@@ -3743,8 +3755,7 @@ static unsigned int hda_set_power_state(struct hda_codec *codec,
snd_hda_codec_read(codec, fg, 0, snd_hda_codec_read(codec, fg, 0,
AC_VERB_SET_POWER_STATE, AC_VERB_SET_POWER_STATE,
power_state); power_state);
snd_hda_codec_set_power_to_all(codec, fg, power_state, snd_hda_codec_set_power_to_all(codec, fg, power_state);
true);
} }
state = hda_sync_power_state(codec, fg, power_state); state = hda_sync_power_state(codec, fg, power_state);
if (!(state & AC_PWRST_ERROR)) if (!(state & AC_PWRST_ERROR))
......
...@@ -886,6 +886,10 @@ struct hda_codec { ...@@ -886,6 +886,10 @@ struct hda_codec {
spinlock_t power_lock; spinlock_t power_lock;
#endif #endif
/* filter the requested power state per nid */
unsigned int (*power_filter)(struct hda_codec *codec, hda_nid_t nid,
unsigned int power_state);
/* codec-specific additional proc output */ /* codec-specific additional proc output */
void (*proc_widget_hook)(struct snd_info_buffer *buffer, void (*proc_widget_hook)(struct snd_info_buffer *buffer,
struct hda_codec *codec, hda_nid_t nid); struct hda_codec *codec, hda_nid_t nid);
...@@ -1047,8 +1051,7 @@ extern const struct snd_pcm_chmap_elem snd_pcm_2_1_chmaps[]; ...@@ -1047,8 +1051,7 @@ extern const struct snd_pcm_chmap_elem snd_pcm_2_1_chmaps[];
void snd_hda_get_codec_name(struct hda_codec *codec, char *name, int namelen); void snd_hda_get_codec_name(struct hda_codec *codec, char *name, int namelen);
void snd_hda_bus_reboot_notify(struct hda_bus *bus); void snd_hda_bus_reboot_notify(struct hda_bus *bus);
void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg, void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg,
unsigned int power_state, unsigned int power_state);
bool eapd_workaround);
int snd_hda_lock_devices(struct hda_bus *bus); int snd_hda_lock_devices(struct hda_bus *bus);
void snd_hda_unlock_devices(struct hda_bus *bus); void snd_hda_unlock_devices(struct hda_bus *bus);
......
...@@ -435,7 +435,7 @@ static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg, ...@@ -435,7 +435,7 @@ static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg,
/* partial workaround for "azx_get_response timeout" */ /* partial workaround for "azx_get_response timeout" */
if (power_state == AC_PWRST_D0) if (power_state == AC_PWRST_D0)
msleep(10); msleep(10);
snd_hda_codec_set_power_to_all(codec, fg, power_state, true); snd_hda_codec_set_power_to_all(codec, fg, power_state);
} }
static int conexant_init(struct hda_codec *codec) static int conexant_init(struct hda_codec *codec)
......
...@@ -3724,7 +3724,7 @@ static void stac_set_power_state(struct hda_codec *codec, hda_nid_t fg, ...@@ -3724,7 +3724,7 @@ static void stac_set_power_state(struct hda_codec *codec, hda_nid_t fg,
} }
snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE, snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
afg_power_state); afg_power_state);
snd_hda_codec_set_power_to_all(codec, fg, power_state, true); snd_hda_codec_set_power_to_all(codec, fg, power_state);
} }
#else #else
#define stac_suspend NULL #define stac_suspend NULL
......
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