aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/hda/patch_hdmi.c
diff options
context:
space:
mode:
authorSubhransu S. Prusty <subhransu.s.prusty@intel.com>2016-03-04 09:29:50 -0500
committerTakashi Iwai <tiwai@suse.de>2016-03-07 09:41:32 -0500
commit828cb4edd8074d35f814e03bee3e2ad8b7d8f64b (patch)
tree2a6186ab061ca0e2f08fdbbf91fcb9528d4135e2 /sound/pci/hda/patch_hdmi.c
parent739ffee97ed550a2899a925ed3f260fa1e8fa955 (diff)
ALSA: hda - chmap helper args modified to use generic hdac objs.
Chmap helper arguments are modified to use either hdac_device object or hdac_chmap object instead of codec specific object. With this moving these APIs to core will be easier. Helper added to access a specific channel_allocation object instead of directly accessing. Signed-off-by: Subhransu S. Prusty <subhransu.s.prusty@intel.com> Signed-off-by: Vinod Koul <vinod.koul@intel.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/pci/hda/patch_hdmi.c')
-rw-r--r--sound/pci/hda/patch_hdmi.c108
1 files changed, 67 insertions, 41 deletions
diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
index ac6c702f89db..3718b41f4b60 100644
--- a/sound/pci/hda/patch_hdmi.c
+++ b/sound/pci/hda/patch_hdmi.c
@@ -696,8 +696,8 @@ static int get_channel_allocation_order(int ca)
696 * 696 *
697 * TODO: it could select the wrong CA from multiple candidates. 697 * TODO: it could select the wrong CA from multiple candidates.
698*/ 698*/
699static int hdmi_channel_allocation(struct hda_codec *codec, 699static int hdmi_channel_allocation_spk_alloc_blk(struct hdac_device *codec,
700 struct hdmi_eld *eld, int channels) 700 int spk_alloc, int channels)
701{ 701{
702 int i; 702 int i;
703 int ca = 0; 703 int ca = 0;
@@ -717,7 +717,7 @@ static int hdmi_channel_allocation(struct hda_codec *codec,
717 * expand ELD's notions to match the ones used by Audio InfoFrame. 717 * expand ELD's notions to match the ones used by Audio InfoFrame.
718 */ 718 */
719 for (i = 0; i < ARRAY_SIZE(eld_speaker_allocation_bits); i++) { 719 for (i = 0; i < ARRAY_SIZE(eld_speaker_allocation_bits); i++) {
720 if (eld->info.spk_alloc & (1 << i)) 720 if (spk_alloc & (1 << i))
721 spk_mask |= eld_speaker_allocation_bits[i]; 721 spk_mask |= eld_speaker_allocation_bits[i];
722 } 722 }
723 723
@@ -742,36 +742,34 @@ static int hdmi_channel_allocation(struct hda_codec *codec,
742 } 742 }
743 } 743 }
744 744
745 snd_print_channel_allocation(eld->info.spk_alloc, buf, sizeof(buf)); 745 snd_print_channel_allocation(spk_alloc, buf, sizeof(buf));
746 codec_dbg(codec, "HDMI: select CA 0x%x for %d-channel allocation: %s\n", 746 dev_dbg(&codec->dev, "HDMI: select CA 0x%x for %d-channel allocation: %s\n",
747 ca, channels, buf); 747 ca, channels, buf);
748 748
749 return ca; 749 return ca;
750} 750}
751 751
752static void hdmi_debug_channel_mapping(struct hda_codec *codec, 752static void hdmi_debug_channel_mapping(struct hdac_chmap *chmap,
753 hda_nid_t pin_nid) 753 hda_nid_t pin_nid)
754{ 754{
755#ifdef CONFIG_SND_DEBUG_VERBOSE 755#ifdef CONFIG_SND_DEBUG_VERBOSE
756 struct hdmi_spec *spec = codec->spec;
757 int i; 756 int i;
758 int channel; 757 int channel;
759 758
760 for (i = 0; i < 8; i++) { 759 for (i = 0; i < 8; i++) {
761 channel = spec->chmap.ops.pin_get_slot_channel( 760 channel = chmap->ops.pin_get_slot_channel(
762 &codec->core, pin_nid, i); 761 chmap->hdac, pin_nid, i);
763 codec_dbg(codec, "HDMI: ASP channel %d => slot %d\n", 762 dev_dbg(&chmap->hdac->dev, "HDMI: ASP channel %d => slot %d\n",
764 channel, i); 763 channel, i);
765 } 764 }
766#endif 765#endif
767} 766}
768 767
769static void hdmi_std_setup_channel_mapping(struct hda_codec *codec, 768static void hdmi_std_setup_channel_mapping(struct hdac_chmap *chmap,
770 hda_nid_t pin_nid, 769 hda_nid_t pin_nid,
771 bool non_pcm, 770 bool non_pcm,
772 int ca) 771 int ca)
773{ 772{
774 struct hdmi_spec *spec = codec->spec;
775 struct hdac_cea_channel_speaker_allocation *ch_alloc; 773 struct hdac_cea_channel_speaker_allocation *ch_alloc;
776 int i; 774 int i;
777 int err; 775 int err;
@@ -807,10 +805,10 @@ static void hdmi_std_setup_channel_mapping(struct hda_codec *codec,
807 int slotsetup = non_pcm ? non_pcm_mapping[i] : hdmi_channel_mapping[ca][i]; 805 int slotsetup = non_pcm ? non_pcm_mapping[i] : hdmi_channel_mapping[ca][i];
808 int hdmi_slot = slotsetup & 0x0f; 806 int hdmi_slot = slotsetup & 0x0f;
809 int channel = (slotsetup & 0xf0) >> 4; 807 int channel = (slotsetup & 0xf0) >> 4;
810 err = spec->chmap.ops.pin_set_slot_channel( 808 err = chmap->ops.pin_set_slot_channel(chmap->hdac,
811 &codec->core, pin_nid, hdmi_slot, channel); 809 pin_nid, hdmi_slot, channel);
812 if (err) { 810 if (err) {
813 codec_dbg(codec, "HDMI: channel mapping failed\n"); 811 dev_dbg(&chmap->hdac->dev, "HDMI: channel mapping failed\n");
814 break; 812 break;
815 } 813 }
816 } 814 }
@@ -912,12 +910,11 @@ static int hdmi_manual_channel_allocation(int chs, unsigned char *map)
912} 910}
913 911
914/* set up the channel slots for the given ALSA API channel map */ 912/* set up the channel slots for the given ALSA API channel map */
915static int hdmi_manual_setup_channel_mapping(struct hda_codec *codec, 913static int hdmi_manual_setup_channel_mapping(struct hdac_chmap *chmap,
916 hda_nid_t pin_nid, 914 hda_nid_t pin_nid,
917 int chs, unsigned char *map, 915 int chs, unsigned char *map,
918 int ca) 916 int ca)
919{ 917{
920 struct hdmi_spec *spec = codec->spec;
921 int ordered_ca = get_channel_allocation_order(ca); 918 int ordered_ca = get_channel_allocation_order(ca);
922 int alsa_pos, hdmi_slot; 919 int alsa_pos, hdmi_slot;
923 int assignments[8] = {[0 ... 7] = 0xf}; 920 int assignments[8] = {[0 ... 7] = 0xf};
@@ -935,7 +932,7 @@ static int hdmi_manual_setup_channel_mapping(struct hda_codec *codec,
935 for (hdmi_slot = 0; hdmi_slot < 8; hdmi_slot++) { 932 for (hdmi_slot = 0; hdmi_slot < 8; hdmi_slot++) {
936 int err; 933 int err;
937 934
938 err = spec->chmap.ops.pin_set_slot_channel(&codec->core, 935 err = chmap->ops.pin_set_slot_channel(chmap->hdac,
939 pin_nid, hdmi_slot, assignments[hdmi_slot]); 936 pin_nid, hdmi_slot, assignments[hdmi_slot]);
940 if (err) 937 if (err)
941 return -EINVAL; 938 return -EINVAL;
@@ -956,20 +953,20 @@ static void hdmi_setup_fake_chmap(unsigned char *map, int ca)
956 } 953 }
957} 954}
958 955
959static void hdmi_setup_channel_mapping(struct hda_codec *codec, 956static void hdmi_setup_channel_mapping(struct hdac_chmap *chmap,
960 hda_nid_t pin_nid, bool non_pcm, int ca, 957 hda_nid_t pin_nid, bool non_pcm, int ca,
961 int channels, unsigned char *map, 958 int channels, unsigned char *map,
962 bool chmap_set) 959 bool chmap_set)
963{ 960{
964 if (!non_pcm && chmap_set) { 961 if (!non_pcm && chmap_set) {
965 hdmi_manual_setup_channel_mapping(codec, pin_nid, 962 hdmi_manual_setup_channel_mapping(chmap, pin_nid,
966 channels, map, ca); 963 channels, map, ca);
967 } else { 964 } else {
968 hdmi_std_setup_channel_mapping(codec, pin_nid, non_pcm, ca); 965 hdmi_std_setup_channel_mapping(chmap, pin_nid, non_pcm, ca);
969 hdmi_setup_fake_chmap(map, ca); 966 hdmi_setup_fake_chmap(map, ca);
970 } 967 }
971 968
972 hdmi_debug_channel_mapping(codec, pin_nid); 969 hdmi_debug_channel_mapping(chmap, pin_nid);
973} 970}
974 971
975/* 972/*
@@ -1142,6 +1139,35 @@ static void hdmi_pin_setup_infoframe(struct hda_codec *codec,
1142 } 1139 }
1143} 1140}
1144 1141
1142static int hdmi_get_active_channels(int ca)
1143{
1144 int ordered_ca = get_channel_allocation_order(ca);
1145
1146 return channel_allocations[ordered_ca].channels;
1147}
1148
1149static struct hdac_cea_channel_speaker_allocation *hdmi_get_ch_alloc_from_ca(int ca)
1150{
1151 return &channel_allocations[get_channel_allocation_order(ca)];
1152}
1153
1154static int hdmi_channel_allocation(struct hdac_device *hdac, int spk_alloc,
1155 int channels, bool chmap_set, bool non_pcm, unsigned char *map)
1156{
1157 int ca;
1158
1159 if (!non_pcm && chmap_set)
1160 ca = hdmi_manual_channel_allocation(channels, map);
1161 else
1162 ca = hdmi_channel_allocation_spk_alloc_blk(hdac,
1163 spk_alloc, channels);
1164
1165 if (ca < 0)
1166 ca = 0;
1167
1168 return ca;
1169}
1170
1145static void hdmi_setup_audio_infoframe(struct hda_codec *codec, 1171static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
1146 struct hdmi_spec_per_pin *per_pin, 1172 struct hdmi_spec_per_pin *per_pin,
1147 bool non_pcm) 1173 bool non_pcm)
@@ -1152,7 +1178,7 @@ static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
1152 int channels = per_pin->channels; 1178 int channels = per_pin->channels;
1153 int active_channels; 1179 int active_channels;
1154 struct hdmi_eld *eld; 1180 struct hdmi_eld *eld;
1155 int ca, ordered_ca; 1181 int ca;
1156 1182
1157 if (!channels) 1183 if (!channels)
1158 return; 1184 return;
@@ -1164,15 +1190,11 @@ static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
1164 1190
1165 eld = &per_pin->sink_eld; 1191 eld = &per_pin->sink_eld;
1166 1192
1167 if (!non_pcm && per_pin->chmap_set) 1193 ca = hdmi_channel_allocation(&codec->core,
1168 ca = hdmi_manual_channel_allocation(channels, per_pin->chmap); 1194 eld->info.spk_alloc, channels,
1169 else 1195 per_pin->chmap_set, non_pcm, per_pin->chmap);
1170 ca = hdmi_channel_allocation(codec, eld, channels);
1171 if (ca < 0)
1172 ca = 0;
1173 1196
1174 ordered_ca = get_channel_allocation_order(ca); 1197 active_channels = hdmi_get_active_channels(ca);
1175 active_channels = channel_allocations[ordered_ca].channels;
1176 1198
1177 chmap->ops.set_channel_count(&codec->core, per_pin->cvt_nid, 1199 chmap->ops.set_channel_count(&codec->core, per_pin->cvt_nid,
1178 active_channels); 1200 active_channels);
@@ -1181,9 +1203,9 @@ static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
1181 * always configure channel mapping, it may have been changed by the 1203 * always configure channel mapping, it may have been changed by the
1182 * user in the meantime 1204 * user in the meantime
1183 */ 1205 */
1184 hdmi_setup_channel_mapping(codec, pin_nid, non_pcm, ca, 1206 hdmi_setup_channel_mapping(&spec->chmap,
1185 channels, per_pin->chmap, 1207 pin_nid, non_pcm, ca, channels,
1186 per_pin->chmap_set); 1208 per_pin->chmap, per_pin->chmap_set);
1187 1209
1188 spec->ops.pin_setup_infoframe(codec, pin_nid, ca, active_channels, 1210 spec->ops.pin_setup_infoframe(codec, pin_nid, ca, active_channels,
1189 eld->info.conn_type); 1211 eld->info.conn_type);
@@ -2336,7 +2358,7 @@ static int hdmi_chmap_cea_alloc_validate_get_type(struct hdac_chmap *chmap,
2336 return SNDRV_CTL_TLVT_CHMAP_VAR; 2358 return SNDRV_CTL_TLVT_CHMAP_VAR;
2337} 2359}
2338 2360
2339static void hdmi_cea_alloc_to_tlv_chmap( 2361static void hdmi_cea_alloc_to_tlv_chmap(struct hdac_chmap *hchmap,
2340 struct hdac_cea_channel_speaker_allocation *cap, 2362 struct hdac_cea_channel_speaker_allocation *cap,
2341 unsigned int *chmap, int channels) 2363 unsigned int *chmap, int channels)
2342{ 2364{
@@ -2430,7 +2452,8 @@ static int hdmi_chmap_ctl_tlv(struct snd_kcontrol *kcontrol, int op_flag,
2430 return -ENOMEM; 2452 return -ENOMEM;
2431 size -= chs_bytes; 2453 size -= chs_bytes;
2432 count += chs_bytes; 2454 count += chs_bytes;
2433 chmap->ops.cea_alloc_to_tlv_chmap(cap, tlv_chmap, chs); 2455 chmap->ops.cea_alloc_to_tlv_chmap(chmap, cap,
2456 tlv_chmap, chs);
2434 if (copy_to_user(dst, tlv_chmap, chs_bytes)) 2457 if (copy_to_user(dst, tlv_chmap, chs_bytes))
2435 return -EFAULT; 2458 return -EFAULT;
2436 dst += chs; 2459 dst += chs;
@@ -2501,7 +2524,8 @@ static int hdmi_chmap_ctl_put(struct snd_kcontrol *kcontrol,
2501 if (ca < 0) 2524 if (ca < 0)
2502 return -EINVAL; 2525 return -EINVAL;
2503 if (hchmap->ops.chmap_validate) { 2526 if (hchmap->ops.chmap_validate) {
2504 err = hchmap->ops.chmap_validate(ca, ARRAY_SIZE(chmap), chmap); 2527 err = hchmap->ops.chmap_validate(hchmap, ca,
2528 ARRAY_SIZE(chmap), chmap);
2505 if (err) 2529 if (err)
2506 return err; 2530 return err;
2507 } 2531 }
@@ -3499,7 +3523,8 @@ static int nvhdmi_chmap_cea_alloc_validate_get_type(struct hdac_chmap *chmap,
3499 chmap, cap, channels); 3523 chmap, cap, channels);
3500} 3524}
3501 3525
3502static int nvhdmi_chmap_validate(int ca, int chs, unsigned char *map) 3526static int nvhdmi_chmap_validate(struct hdac_chmap *chmap,
3527 int ca, int chs, unsigned char *map)
3503{ 3528{
3504 if (ca == 0x00 && (map[0] != SNDRV_CHMAP_FL || map[1] != SNDRV_CHMAP_FR)) 3529 if (ca == 0x00 && (map[0] != SNDRV_CHMAP_FL || map[1] != SNDRV_CHMAP_FR))
3505 return -EINVAL; 3530 return -EINVAL;
@@ -3769,14 +3794,15 @@ static int atihdmi_paired_swap_fc_lfe(int pos)
3769 return pos; 3794 return pos;
3770} 3795}
3771 3796
3772static int atihdmi_paired_chmap_validate(int ca, int chs, unsigned char *map) 3797static int atihdmi_paired_chmap_validate(struct hdac_chmap *chmap,
3798 int ca, int chs, unsigned char *map)
3773{ 3799{
3774 struct hdac_cea_channel_speaker_allocation *cap; 3800 struct hdac_cea_channel_speaker_allocation *cap;
3775 int i, j; 3801 int i, j;
3776 3802
3777 /* check that only channel pairs need to be remapped on old pre-rev3 ATI/AMD */ 3803 /* check that only channel pairs need to be remapped on old pre-rev3 ATI/AMD */
3778 3804
3779 cap = &channel_allocations[get_channel_allocation_order(ca)]; 3805 cap = hdmi_get_ch_alloc_from_ca(ca);
3780 for (i = 0; i < chs; ++i) { 3806 for (i = 0; i < chs; ++i) {
3781 int mask = to_spk_mask(map[i]); 3807 int mask = to_spk_mask(map[i]);
3782 bool ok = false; 3808 bool ok = false;
@@ -3912,7 +3938,7 @@ static int atihdmi_paired_chmap_cea_alloc_validate_get_type(
3912 return SNDRV_CTL_TLVT_CHMAP_PAIRED; 3938 return SNDRV_CTL_TLVT_CHMAP_PAIRED;
3913} 3939}
3914 3940
3915static void atihdmi_paired_cea_alloc_to_tlv_chmap( 3941static void atihdmi_paired_cea_alloc_to_tlv_chmap(struct hdac_chmap *hchmap,
3916 struct hdac_cea_channel_speaker_allocation *cap, 3942 struct hdac_cea_channel_speaker_allocation *cap,
3917 unsigned int *chmap, int channels) 3943 unsigned int *chmap, int channels)
3918{ 3944{