@@ -100,8 +100,6 @@ struct hdmi_spec_per_pin {
100100#endif
101101};
102102
103- struct cea_channel_speaker_allocation;
104-
105103/* operations used by generic code that can be overridden by patches */
106104struct hdmi_ops {
107105 int (*pin_get_eld)(struct hda_codec *codec, hda_nid_t pin_nid,
@@ -2350,9 +2348,7 @@ static int hdmi_chmap_ctl_info(struct snd_kcontrol *kcontrol,
23502348 struct snd_ctl_elem_info *uinfo)
23512349{
23522350 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
2353- struct hda_codec *codec = info->private_data;
2354- struct hdmi_spec *spec = codec->spec;
2355- struct hdac_chmap *chmap = &spec->chmap;
2351+ struct hdac_chmap *chmap = info->private_data;
23562352
23572353 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
23582354 uinfo->count = chmap->channels_max;
@@ -2389,13 +2385,49 @@ static void hdmi_cea_alloc_to_tlv_chmap(struct cea_channel_speaker_allocation *c
23892385 WARN_ON(count != channels);
23902386}
23912387
2388+ static void hdmi_get_chmap(struct hdac_device *hdac, int pcm_idx,
2389+ unsigned char *chmap)
2390+ {
2391+ struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
2392+ struct hdmi_spec *spec = codec->spec;
2393+ struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx);
2394+
2395+ /* chmap is already set to 0 in caller */
2396+ if (!per_pin)
2397+ return;
2398+
2399+ memcpy(chmap, per_pin->chmap, ARRAY_SIZE(per_pin->chmap));
2400+ }
2401+
2402+ static void hdmi_set_chmap(struct hdac_device *hdac, int pcm_idx,
2403+ unsigned char *chmap, int prepared)
2404+ {
2405+ struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
2406+ struct hdmi_spec *spec = codec->spec;
2407+ struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx);
2408+
2409+ mutex_lock(&per_pin->lock);
2410+ per_pin->chmap_set = true;
2411+ memcpy(per_pin->chmap, chmap, ARRAY_SIZE(per_pin->chmap));
2412+ if (prepared)
2413+ hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm);
2414+ mutex_unlock(&per_pin->lock);
2415+ }
2416+
2417+ static bool is_hdmi_pcm_attached(struct hdac_device *hdac, int pcm_idx)
2418+ {
2419+ struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
2420+ struct hdmi_spec *spec = codec->spec;
2421+ struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx);
2422+
2423+ return per_pin ? true:false;
2424+ }
2425+
23922426static int hdmi_chmap_ctl_tlv(struct snd_kcontrol *kcontrol, int op_flag,
23932427 unsigned int size, unsigned int __user *tlv)
23942428{
23952429 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
2396- struct hda_codec *codec = info->private_data;
2397- struct hdmi_spec *spec = codec->spec;
2398- struct hdac_chmap *chmap = &spec->chmap;
2430+ struct hdac_chmap *chmap = info->private_data;
23992431 unsigned int __user *dst;
24002432 int chs, count = 0;
24012433
@@ -2444,42 +2476,35 @@ static int hdmi_chmap_ctl_get(struct snd_kcontrol *kcontrol,
24442476 struct snd_ctl_elem_value *ucontrol)
24452477{
24462478 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
2447- struct hda_codec *codec = info->private_data;
2448- struct hdmi_spec *spec = codec->spec;
2449- struct hdac_chmap *chmap = &spec->chmap;
2479+ struct hdac_chmap *chmap = info->private_data;
24502480 int pcm_idx = kcontrol->private_value;
2451- struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx) ;
2481+ unsigned char pcm_chmap[8] ;
24522482 int i;
24532483
2454- if (!per_pin) {
2455- for (i = 0; i < chmap->channels_max; i++)
2456- ucontrol->value.integer.value[i] = 0;
2457- return 0;
2458- }
2484+ memset(pcm_chmap, 0, sizeof(pcm_chmap));
2485+ chmap->ops.get_chmap( chmap->hdac, pcm_idx, pcm_chmap);
2486+
2487+ for (i = 0; i < sizeof(chmap); i++)
2488+ ucontrol->value.integer.value[i] = pcm_chmap[i];
24592489
2460- for (i = 0; i < ARRAY_SIZE(per_pin->chmap); i++)
2461- ucontrol->value.integer.value[i] = per_pin->chmap[i];
24622490 return 0;
24632491}
24642492
24652493static int hdmi_chmap_ctl_put(struct snd_kcontrol *kcontrol,
24662494 struct snd_ctl_elem_value *ucontrol)
24672495{
24682496 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
2469- struct hda_codec *codec = info->private_data;
2470- struct hdmi_spec *spec = codec->spec;
2471- struct hdac_chmap *hchmap = &spec->chmap;
2497+ struct hdac_chmap *hchmap = info->private_data;
24722498 int pcm_idx = kcontrol->private_value;
2473- struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx);
24742499 unsigned int ctl_idx;
24752500 struct snd_pcm_substream *substream;
2476- unsigned char chmap[8];
2501+ unsigned char chmap[8], per_pin_chmap[8] ;
24772502 int i, err, ca, prepared = 0;
24782503
24792504 /* No monitor is connected in dyn_pcm_assign.
24802505 * It's invalid to setup the chmap
24812506 */
2482- if (!per_pin )
2507+ if (!hchmap->ops.is_pcm_attached(hchmap->hdac, pcm_idx) )
24832508 return 0;
24842509
24852510 ctl_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
@@ -2499,7 +2524,9 @@ static int hdmi_chmap_ctl_put(struct snd_kcontrol *kcontrol,
24992524 memset(chmap, 0, sizeof(chmap));
25002525 for (i = 0; i < ARRAY_SIZE(chmap); i++)
25012526 chmap[i] = ucontrol->value.integer.value[i];
2502- if (!memcmp(chmap, per_pin->chmap, sizeof(chmap)))
2527+
2528+ hchmap->ops.get_chmap(hchmap->hdac, pcm_idx, per_pin_chmap);
2529+ if (!memcmp(chmap, per_pin_chmap, sizeof(chmap)))
25032530 return 0;
25042531 ca = hdmi_manual_channel_allocation(ARRAY_SIZE(chmap), chmap);
25052532 if (ca < 0)
@@ -2509,12 +2536,8 @@ static int hdmi_chmap_ctl_put(struct snd_kcontrol *kcontrol,
25092536 if (err)
25102537 return err;
25112538 }
2512- mutex_lock(&per_pin->lock);
2513- per_pin->chmap_set = true;
2514- memcpy(per_pin->chmap, chmap, sizeof(chmap));
2515- if (prepared)
2516- hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm);
2517- mutex_unlock(&per_pin->lock);
2539+
2540+ hchmap->ops.set_chmap(hchmap->hdac, pcm_idx, chmap, prepared);
25182541
25192542 return 0;
25202543}
@@ -2672,7 +2695,7 @@ static int generic_hdmi_build_controls(struct hda_codec *codec)
26722695 if (err < 0)
26732696 return err;
26742697 /* override handlers */
2675- chmap->private_data = codec ;
2698+ chmap->private_data = &spec->chmap ;
26762699 kctl = chmap->kctl;
26772700 for (i = 0; i < kctl->count; i++)
26782701 kctl->vd[i].access |= SNDRV_CTL_ELEM_ACCESS_WRITE;
@@ -2801,9 +2824,11 @@ static const struct hdmi_ops generic_standard_hdmi_ops = {
28012824static const struct hdac_chmap_ops chmap_ops = {
28022825 .chmap_cea_alloc_validate_get_type = hdmi_chmap_cea_alloc_validate_get_type,
28032826 .cea_alloc_to_tlv_chmap = hdmi_cea_alloc_to_tlv_chmap,
2827+ .get_chmap = hdmi_get_chmap,
2828+ .set_chmap = hdmi_set_chmap,
2829+ .is_pcm_attached = is_hdmi_pcm_attached,
28042830};
28052831
2806-
28072832static void intel_haswell_fixup_connect_list(struct hda_codec *codec,
28082833 hda_nid_t nid)
28092834{
0 commit comments