Commit c6e4c666 authored by Takashi Iwai's avatar Takashi Iwai

ALSA: hda - Assign unsol tags dynamically in patch_sigmatel.c

Since we need to handle many unsolicited events assigned to different
widgets, allocate the event dynamically using the existing events
array, and use the tag appropriately instead of combination of fixed
number and widget nid.  (Note that widget nid can be over 4 bits!)

Also, replaced the call of unsol_event handler with a dedicated
function to be more readable.
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 0e19e7d2
...@@ -36,10 +36,12 @@ ...@@ -36,10 +36,12 @@
#include "hda_patch.h" #include "hda_patch.h"
#include "hda_beep.h" #include "hda_beep.h"
#define STAC_VREF_EVENT 0x00 enum {
#define STAC_INSERT_EVENT 0x10 STAC_VREF_EVENT = 1,
#define STAC_PWR_EVENT 0x20 STAC_INSERT_EVENT,
#define STAC_HP_EVENT 0x30 STAC_PWR_EVENT,
STAC_HP_EVENT,
};
enum { enum {
STAC_REF, STAC_REF,
...@@ -134,6 +136,8 @@ enum { ...@@ -134,6 +136,8 @@ enum {
struct sigmatel_event { struct sigmatel_event {
hda_nid_t nid; hda_nid_t nid;
unsigned char type;
unsigned char tag;
int data; int data;
}; };
...@@ -2549,6 +2553,9 @@ static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol, ...@@ -2549,6 +2553,9 @@ static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
return 0; return 0;
} }
static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid,
unsigned char type);
static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol, static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol) struct snd_ctl_elem_value *ucontrol)
{ {
...@@ -2561,7 +2568,7 @@ static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol, ...@@ -2561,7 +2568,7 @@ static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
/* check to be sure that the ports are upto date with /* check to be sure that the ports are upto date with
* switch changes * switch changes
*/ */
codec->patch_ops.unsol_event(codec, (STAC_HP_EVENT | nid) << 26); stac_issue_unsol_event(codec, nid, STAC_HP_EVENT);
return 1; return 1;
} }
...@@ -2601,8 +2608,7 @@ static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_ ...@@ -2601,8 +2608,7 @@ static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_
* appropriately according to the pin direction * appropriately according to the pin direction
*/ */
if (spec->hp_detect) if (spec->hp_detect)
codec->patch_ops.unsol_event(codec, stac_issue_unsol_event(codec, nid, STAC_HP_EVENT);
(STAC_HP_EVENT | nid) << 26);
return 1; return 1;
} }
...@@ -3768,8 +3774,8 @@ static int stac92xx_add_jack(struct hda_codec *codec, ...@@ -3768,8 +3774,8 @@ static int stac92xx_add_jack(struct hda_codec *codec,
#endif #endif
} }
static int stac92xx_add_event(struct sigmatel_spec *spec, hda_nid_t nid, static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
int data) unsigned char type, int data)
{ {
struct sigmatel_event *event; struct sigmatel_event *event;
...@@ -3778,32 +3784,59 @@ static int stac92xx_add_event(struct sigmatel_spec *spec, hda_nid_t nid, ...@@ -3778,32 +3784,59 @@ static int stac92xx_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
if (!event) if (!event)
return -ENOMEM; return -ENOMEM;
event->nid = nid; event->nid = nid;
event->type = type;
event->tag = spec->events.used;
event->data = data; event->data = data;
return 0; return event->tag;
} }
static int stac92xx_event_data(struct hda_codec *codec, hda_nid_t nid) static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
hda_nid_t nid, unsigned char type)
{ {
struct sigmatel_spec *spec = codec->spec; struct sigmatel_spec *spec = codec->spec;
struct sigmatel_event *events = spec->events.list; struct sigmatel_event *event = spec->events.list;
if (events) { int i;
int i;
for (i = 0; i < spec->events.used; i++) for (i = 0; i < spec->events.used; i++, event++) {
if (events[i].nid == nid) if (event->nid == nid && event->type == type)
return events[i].data; return event;
} }
return 0; return NULL;
} }
static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid, static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
unsigned int event) unsigned char tag)
{ {
if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) { struct sigmatel_spec *spec = codec->spec;
snd_hda_codec_write_cache(codec, nid, 0, struct sigmatel_event *event = spec->events.list;
AC_VERB_SET_UNSOLICITED_ENABLE, int i;
(AC_USRSP_EN | event | nid));
for (i = 0; i < spec->events.used; i++, event++) {
if (event->tag == tag)
return event;
} }
return NULL;
}
static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
unsigned int type)
{
struct sigmatel_event *event;
int tag;
if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
return;
event = stac_get_event(codec, nid, type);
if (event)
tag = event->tag;
else
tag = stac_add_event(codec->spec, nid, type, 0);
if (tag < 0)
return;
snd_hda_codec_write_cache(codec, nid, 0,
AC_VERB_SET_UNSOLICITED_ENABLE,
AC_USRSP_EN | tag);
} }
static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid) static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
...@@ -3862,7 +3895,7 @@ static int stac92xx_init(struct hda_codec *codec) ...@@ -3862,7 +3895,7 @@ static int stac92xx_init(struct hda_codec *codec)
/* Enable unsolicited responses on the HP widget */ /* Enable unsolicited responses on the HP widget */
for (i = 0; i < cfg->hp_outs; i++) { for (i = 0; i < cfg->hp_outs; i++) {
hda_nid_t nid = cfg->hp_pins[i]; hda_nid_t nid = cfg->hp_pins[i];
enable_pin_detect(codec, nid, STAC_HP_EVENT | nid); enable_pin_detect(codec, nid, STAC_HP_EVENT);
} }
/* force to enable the first line-out; the others are set up /* force to enable the first line-out; the others are set up
* in unsol_event * in unsol_event
...@@ -3870,8 +3903,8 @@ static int stac92xx_init(struct hda_codec *codec) ...@@ -3870,8 +3903,8 @@ static int stac92xx_init(struct hda_codec *codec)
stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0], stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
AC_PINCTL_OUT_EN); AC_PINCTL_OUT_EN);
/* fake event to set up pins */ /* fake event to set up pins */
codec->patch_ops.unsol_event(codec, stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0],
(STAC_HP_EVENT | spec->autocfg.hp_pins[0]) << 26); STAC_HP_EVENT);
} else { } else {
stac92xx_auto_init_multi_out(codec); stac92xx_auto_init_multi_out(codec);
stac92xx_auto_init_hp_out(codec); stac92xx_auto_init_hp_out(codec);
...@@ -3892,7 +3925,7 @@ static int stac92xx_init(struct hda_codec *codec) ...@@ -3892,7 +3925,7 @@ static int stac92xx_init(struct hda_codec *codec)
} }
pinctl |= AC_PINCTL_IN_EN; pinctl |= AC_PINCTL_IN_EN;
stac92xx_auto_set_pinctl(codec, nid, pinctl); stac92xx_auto_set_pinctl(codec, nid, pinctl);
enable_pin_detect(codec, nid, STAC_INSERT_EVENT | nid); enable_pin_detect(codec, nid, STAC_INSERT_EVENT);
} }
} }
for (i = 0; i < spec->num_dmics; i++) for (i = 0; i < spec->num_dmics; i++)
...@@ -3907,7 +3940,6 @@ static int stac92xx_init(struct hda_codec *codec) ...@@ -3907,7 +3940,6 @@ static int stac92xx_init(struct hda_codec *codec)
for (i = 0; i < spec->num_pwrs; i++) { for (i = 0; i < spec->num_pwrs; i++) {
hda_nid_t nid = spec->pwr_nids[i]; hda_nid_t nid = spec->pwr_nids[i];
int pinctl, def_conf; int pinctl, def_conf;
int event = STAC_PWR_EVENT;
if (is_nid_hp_pin(cfg, nid) && spec->hp_detect) if (is_nid_hp_pin(cfg, nid) && spec->hp_detect)
continue; /* already has an unsol event */ continue; /* already has an unsol event */
...@@ -3930,8 +3962,8 @@ static int stac92xx_init(struct hda_codec *codec) ...@@ -3930,8 +3962,8 @@ static int stac92xx_init(struct hda_codec *codec)
stac_toggle_power_map(codec, nid, 1); stac_toggle_power_map(codec, nid, 1);
continue; continue;
} }
enable_pin_detect(codec, spec->pwr_nids[i], event | i); enable_pin_detect(codec, nid, STAC_PWR_EVENT);
codec->patch_ops.unsol_event(codec, (event | i) << 26); stac_issue_unsol_event(codec, nid, STAC_PWR_EVENT);
} }
if (spec->dac_list) if (spec->dac_list)
stac92xx_power_down(codec); stac92xx_power_down(codec);
...@@ -4059,7 +4091,7 @@ static int no_hp_sensing(struct sigmatel_spec *spec, int i) ...@@ -4059,7 +4091,7 @@ static int no_hp_sensing(struct sigmatel_spec *spec, int i)
return 0; return 0;
} }
static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res) static void stac92xx_hp_detect(struct hda_codec *codec)
{ {
struct sigmatel_spec *spec = codec->spec; struct sigmatel_spec *spec = codec->spec;
struct auto_pin_cfg *cfg = &spec->autocfg; struct auto_pin_cfg *cfg = &spec->autocfg;
...@@ -4182,33 +4214,43 @@ static void stac92xx_report_jack(struct hda_codec *codec, hda_nid_t nid) ...@@ -4182,33 +4214,43 @@ static void stac92xx_report_jack(struct hda_codec *codec, hda_nid_t nid)
} }
} }
static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid,
unsigned char type)
{
struct sigmatel_event *event = stac_get_event(codec, nid, type);
if (!event)
return;
codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
}
static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res) static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
{ {
struct sigmatel_spec *spec = codec->spec; struct sigmatel_spec *spec = codec->spec;
int event = (res >> 26) & 0x70; struct sigmatel_event *event;
int nid = res >> 26 & 0x0f; int tag, data;
switch (event) { tag = (res >> 26) & 0x7f;
event = stac_get_event_from_tag(codec, tag);
if (!event)
return;
switch (event->type) {
case STAC_HP_EVENT: case STAC_HP_EVENT:
stac92xx_hp_detect(codec, res); stac92xx_hp_detect(codec);
/* fallthru */ /* fallthru */
case STAC_INSERT_EVENT: case STAC_INSERT_EVENT:
case STAC_PWR_EVENT: case STAC_PWR_EVENT:
if (nid) { if (spec->num_pwrs > 0)
if (spec->num_pwrs > 0) stac92xx_pin_sense(codec, event->nid);
stac92xx_pin_sense(codec, nid); stac92xx_report_jack(codec, event->nid);
stac92xx_report_jack(codec, nid);
}
break; break;
case STAC_VREF_EVENT: { case STAC_VREF_EVENT:
int data = snd_hda_codec_read(codec, codec->afg, 0, data = snd_hda_codec_read(codec, codec->afg, 0,
AC_VERB_GET_GPIO_DATA, 0); AC_VERB_GET_GPIO_DATA, 0);
int idx = stac92xx_event_data(codec, nid);
/* toggle VREF state based on GPIOx status */ /* toggle VREF state based on GPIOx status */
snd_hda_codec_write(codec, codec->afg, 0, 0x7e0, snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
!!(data & (1 << idx))); !!(data & (1 << event->data)));
break; break;
}
} }
} }
...@@ -4223,8 +4265,8 @@ static int stac92xx_resume(struct hda_codec *codec) ...@@ -4223,8 +4265,8 @@ static int stac92xx_resume(struct hda_codec *codec)
snd_hda_codec_resume_cache(codec); snd_hda_codec_resume_cache(codec);
/* fake event to set up pins again to override cached values */ /* fake event to set up pins again to override cached values */
if (spec->hp_detect) if (spec->hp_detect)
codec->patch_ops.unsol_event(codec, stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0],
(STAC_HP_EVENT | spec->autocfg.hp_pins[0]) << 26); STAC_HP_EVENT);
return 0; return 0;
} }
...@@ -4732,14 +4774,15 @@ static int patch_stac92hd71bxx(struct hda_codec *codec) ...@@ -4732,14 +4774,15 @@ static int patch_stac92hd71bxx(struct hda_codec *codec)
switch (spec->board_config) { switch (spec->board_config) {
case STAC_HP_M4: case STAC_HP_M4:
/* Enable VREF power saving on GPIO1 detect */ /* Enable VREF power saving on GPIO1 detect */
err = stac_add_event(spec, codec->afg,
STAC_VREF_EVENT, 0x02);
if (err < 0)
return err;
snd_hda_codec_write_cache(codec, codec->afg, 0, snd_hda_codec_write_cache(codec, codec->afg, 0,
AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02); AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
snd_hda_codec_write_cache(codec, codec->afg, 0, snd_hda_codec_write_cache(codec, codec->afg, 0,
AC_VERB_SET_UNSOLICITED_ENABLE, AC_VERB_SET_UNSOLICITED_ENABLE,
(AC_USRSP_EN | STAC_VREF_EVENT | codec->afg)); AC_USRSP_EN | err);
err = stac92xx_add_event(spec, codec->afg, 0x02);
if (err < 0)
return err;
spec->gpio_mask |= 0x02; spec->gpio_mask |= 0x02;
break; break;
} }
...@@ -5131,14 +5174,14 @@ static int patch_stac9205(struct hda_codec *codec) ...@@ -5131,14 +5174,14 @@ static int patch_stac9205(struct hda_codec *codec)
stac_change_pin_config(codec, 0x20, 0x1c410030); stac_change_pin_config(codec, 0x20, 0x1c410030);
/* Enable unsol response for GPIO4/Dock HP connection */ /* Enable unsol response for GPIO4/Dock HP connection */
err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
if (err < 0)
return err;
snd_hda_codec_write_cache(codec, codec->afg, 0, snd_hda_codec_write_cache(codec, codec->afg, 0,
AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10); AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
snd_hda_codec_write_cache(codec, codec->afg, 0, snd_hda_codec_write_cache(codec, codec->afg, 0,
AC_VERB_SET_UNSOLICITED_ENABLE, AC_VERB_SET_UNSOLICITED_ENABLE,
(AC_USRSP_EN | STAC_VREF_EVENT | codec->afg)); AC_USRSP_EN | err);
err = stac92xx_add_event(spec, codec->afg, 0x01);
if (err < 0)
return err;
spec->gpio_dir = 0x0b; spec->gpio_dir = 0x0b;
spec->eapd_mask = 0x01; spec->eapd_mask = 0x01;
......
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