Skip to content

Commit 739ffee

Browse files
Subhransu S. Prustytiwai
authored andcommitted
ALSA: hda - Add hdmi chmap verb programming ops to chmap object
Add slot and channel count programming to hdmi_chmap object and move the chmap_ops to core. Use register_chmap_ops API to register for default ops. Override specific chmap ops in the driver. 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>
1 parent f302240 commit 739ffee

4 files changed

Lines changed: 88 additions & 60 deletions

File tree

‎include/sound/hda_chmap.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ struct hdac_chmap_ops {
3636
void (*set_chmap)(struct hdac_device *hdac, int pcm_idx,
3737
unsigned char *chmap, int prepared);
3838
bool (*is_pcm_attached)(struct hdac_device *hdac, int pcm_idx);
39+
40+
/* get and set channel assigned to each HDMI ASP (audio sample packet) slot */
41+
int (*pin_get_slot_channel)(struct hdac_device *codec,
42+
hda_nid_t pin_nid, int asp_slot);
43+
int (*pin_set_slot_channel)(struct hdac_device *codec,
44+
hda_nid_t pin_nid, int asp_slot, int channel);
45+
void (*set_channel_count)(struct hdac_device *codec,
46+
hda_nid_t cvt_nid, int chs);
3947
};
4048

4149
struct hdac_chmap {
@@ -44,4 +52,6 @@ struct hdac_chmap {
4452
struct hdac_device *hdac;
4553
};
4654

55+
void snd_hdac_register_chmap_ops(struct hdac_device *hdac,
56+
struct hdac_chmap *chmap);
4757
#endif /* __SOUND_HDA_CHMAP_H */

‎sound/hda/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
snd-hda-core-objs := hda_bus_type.o hdac_bus.o hdac_device.o hdac_sysfs.o \
2-
hdac_regmap.o hdac_controller.o hdac_stream.o array.o
2+
hdac_regmap.o hdac_controller.o hdac_stream.o array.o hdmi_chmap.o
33

44
snd-hda-core-objs += trace.o
55
CFLAGS_trace.o := -I$(src)

‎sound/hda/hdmi_chmap.c‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* HDMI Channel map support helpers
3+
*/
4+
5+
#include <sound/hda_chmap.h>
6+
7+
static int hdmi_pin_set_slot_channel(struct hdac_device *codec,
8+
hda_nid_t pin_nid, int asp_slot, int channel)
9+
{
10+
return snd_hdac_codec_write(codec, pin_nid, 0,
11+
AC_VERB_SET_HDMI_CHAN_SLOT,
12+
(channel << 4) | asp_slot);
13+
}
14+
15+
static int hdmi_pin_get_slot_channel(struct hdac_device *codec,
16+
hda_nid_t pin_nid, int asp_slot)
17+
{
18+
return (snd_hdac_codec_read(codec, pin_nid, 0,
19+
AC_VERB_GET_HDMI_CHAN_SLOT,
20+
asp_slot) & 0xf0) >> 4;
21+
}
22+
23+
static int hdmi_get_channel_count(struct hdac_device *codec, hda_nid_t cvt_nid)
24+
{
25+
return 1 + snd_hdac_codec_read(codec, cvt_nid, 0,
26+
AC_VERB_GET_CVT_CHAN_COUNT, 0);
27+
}
28+
29+
static void hdmi_set_channel_count(struct hdac_device *codec,
30+
hda_nid_t cvt_nid, int chs)
31+
{
32+
if (chs != hdmi_get_channel_count(codec, cvt_nid))
33+
snd_hdac_codec_write(codec, cvt_nid, 0,
34+
AC_VERB_SET_CVT_CHAN_COUNT, chs - 1);
35+
}
36+
37+
static const struct hdac_chmap_ops chmap_ops = {
38+
.pin_get_slot_channel = hdmi_pin_get_slot_channel,
39+
.pin_set_slot_channel = hdmi_pin_set_slot_channel,
40+
.set_channel_count = hdmi_set_channel_count,
41+
};
42+
43+
void snd_hdac_register_chmap_ops(struct hdac_device *hdac,
44+
struct hdac_chmap *chmap)
45+
{
46+
chmap->ops = chmap_ops;
47+
chmap->hdac = hdac;
48+
}
49+
EXPORT_SYMBOL_GPL(snd_hdac_register_chmap_ops);

‎sound/pci/hda/patch_hdmi.c‎

Lines changed: 28 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,6 @@ struct hdmi_ops {
105105
int (*pin_get_eld)(struct hda_codec *codec, hda_nid_t pin_nid,
106106
unsigned char *buf, int *eld_size);
107107

108-
/* get and set channel assigned to each HDMI ASP (audio sample packet) slot */
109-
int (*pin_get_slot_channel)(struct hda_codec *codec, hda_nid_t pin_nid,
110-
int asp_slot);
111-
int (*pin_set_slot_channel)(struct hda_codec *codec, hda_nid_t pin_nid,
112-
int asp_slot, int channel);
113-
114108
void (*pin_setup_infoframe)(struct hda_codec *codec, hda_nid_t pin_nid,
115109
int ca, int active_channels, int conn_type);
116110

@@ -596,20 +590,6 @@ static void hdmi_init_pin(struct hda_codec *codec, hda_nid_t pin_nid)
596590
AC_VERB_SET_PIN_WIDGET_CONTROL, pin_out);
597591
}
598592

599-
static int hdmi_get_channel_count(struct hda_codec *codec, hda_nid_t cvt_nid)
600-
{
601-
return 1 + snd_hda_codec_read(codec, cvt_nid, 0,
602-
AC_VERB_GET_CVT_CHAN_COUNT, 0);
603-
}
604-
605-
static void hdmi_set_channel_count(struct hda_codec *codec,
606-
hda_nid_t cvt_nid, int chs)
607-
{
608-
if (chs != hdmi_get_channel_count(codec, cvt_nid))
609-
snd_hda_codec_write(codec, cvt_nid, 0,
610-
AC_VERB_SET_CVT_CHAN_COUNT, chs - 1);
611-
}
612-
613593
/*
614594
* ELD proc files
615595
*/
@@ -778,7 +758,8 @@ static void hdmi_debug_channel_mapping(struct hda_codec *codec,
778758
int channel;
779759

780760
for (i = 0; i < 8; i++) {
781-
channel = spec->ops.pin_get_slot_channel(codec, pin_nid, i);
761+
channel = spec->chmap.ops.pin_get_slot_channel(
762+
&codec->core, pin_nid, i);
782763
codec_dbg(codec, "HDMI: ASP channel %d => slot %d\n",
783764
channel, i);
784765
}
@@ -826,7 +807,8 @@ static void hdmi_std_setup_channel_mapping(struct hda_codec *codec,
826807
int slotsetup = non_pcm ? non_pcm_mapping[i] : hdmi_channel_mapping[ca][i];
827808
int hdmi_slot = slotsetup & 0x0f;
828809
int channel = (slotsetup & 0xf0) >> 4;
829-
err = spec->ops.pin_set_slot_channel(codec, pin_nid, hdmi_slot, channel);
810+
err = spec->chmap.ops.pin_set_slot_channel(
811+
&codec->core, pin_nid, hdmi_slot, channel);
830812
if (err) {
831813
codec_dbg(codec, "HDMI: channel mapping failed\n");
832814
break;
@@ -953,8 +935,8 @@ static int hdmi_manual_setup_channel_mapping(struct hda_codec *codec,
953935
for (hdmi_slot = 0; hdmi_slot < 8; hdmi_slot++) {
954936
int err;
955937

956-
err = spec->ops.pin_set_slot_channel(codec, pin_nid, hdmi_slot,
957-
assignments[hdmi_slot]);
938+
err = spec->chmap.ops.pin_set_slot_channel(&codec->core,
939+
pin_nid, hdmi_slot, assignments[hdmi_slot]);
958940
if (err)
959941
return -EINVAL;
960942
}
@@ -990,22 +972,6 @@ static void hdmi_setup_channel_mapping(struct hda_codec *codec,
990972
hdmi_debug_channel_mapping(codec, pin_nid);
991973
}
992974

993-
static int hdmi_pin_set_slot_channel(struct hda_codec *codec, hda_nid_t pin_nid,
994-
int asp_slot, int channel)
995-
{
996-
return snd_hda_codec_write(codec, pin_nid, 0,
997-
AC_VERB_SET_HDMI_CHAN_SLOT,
998-
(channel << 4) | asp_slot);
999-
}
1000-
1001-
static int hdmi_pin_get_slot_channel(struct hda_codec *codec, hda_nid_t pin_nid,
1002-
int asp_slot)
1003-
{
1004-
return (snd_hda_codec_read(codec, pin_nid, 0,
1005-
AC_VERB_GET_HDMI_CHAN_SLOT,
1006-
asp_slot) & 0xf0) >> 4;
1007-
}
1008-
1009975
/*
1010976
* Audio InfoFrame routines
1011977
*/
@@ -1181,6 +1147,7 @@ static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
11811147
bool non_pcm)
11821148
{
11831149
struct hdmi_spec *spec = codec->spec;
1150+
struct hdac_chmap *chmap = &spec->chmap;
11841151
hda_nid_t pin_nid = per_pin->pin_nid;
11851152
int channels = per_pin->channels;
11861153
int active_channels;
@@ -1207,7 +1174,8 @@ static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
12071174
ordered_ca = get_channel_allocation_order(ca);
12081175
active_channels = channel_allocations[ordered_ca].channels;
12091176

1210-
hdmi_set_channel_count(codec, per_pin->cvt_nid, active_channels);
1177+
chmap->ops.set_channel_count(&codec->core, per_pin->cvt_nid,
1178+
active_channels);
12111179

12121180
/*
12131181
* always configure channel mapping, it may have been changed by the
@@ -2815,21 +2783,11 @@ static const struct hda_codec_ops generic_hdmi_patch_ops = {
28152783

28162784
static const struct hdmi_ops generic_standard_hdmi_ops = {
28172785
.pin_get_eld = snd_hdmi_get_eld,
2818-
.pin_get_slot_channel = hdmi_pin_get_slot_channel,
2819-
.pin_set_slot_channel = hdmi_pin_set_slot_channel,
28202786
.pin_setup_infoframe = hdmi_pin_setup_infoframe,
28212787
.pin_hbr_setup = hdmi_pin_hbr_setup,
28222788
.setup_stream = hdmi_setup_stream,
28232789
};
28242790

2825-
static const struct hdac_chmap_ops chmap_ops = {
2826-
.chmap_cea_alloc_validate_get_type = hdmi_chmap_cea_alloc_validate_get_type,
2827-
.cea_alloc_to_tlv_chmap = hdmi_cea_alloc_to_tlv_chmap,
2828-
.get_chmap = hdmi_get_chmap,
2829-
.set_chmap = hdmi_set_chmap,
2830-
.is_pcm_attached = is_hdmi_pcm_attached,
2831-
};
2832-
28332791
static void intel_haswell_fixup_connect_list(struct hda_codec *codec,
28342792
hda_nid_t nid)
28352793
{
@@ -2931,8 +2889,15 @@ static int patch_generic_hdmi(struct hda_codec *codec)
29312889

29322890
spec->ops = generic_standard_hdmi_ops;
29332891
mutex_init(&spec->pcm_lock);
2934-
spec->chmap.ops = chmap_ops;
2935-
spec->chmap.hdac = &codec->core;
2892+
snd_hdac_register_chmap_ops(&codec->core, &spec->chmap);
2893+
2894+
spec->chmap.ops.chmap_cea_alloc_validate_get_type =
2895+
hdmi_chmap_cea_alloc_validate_get_type;
2896+
spec->chmap.ops.cea_alloc_to_tlv_chmap = hdmi_cea_alloc_to_tlv_chmap;
2897+
spec->chmap.ops.get_chmap = hdmi_get_chmap;
2898+
spec->chmap.ops.set_chmap = hdmi_set_chmap;
2899+
spec->chmap.ops.is_pcm_attached = is_hdmi_pcm_attached;
2900+
29362901
codec->spec = spec;
29372902
hdmi_array_init(spec, 4);
29382903

@@ -3851,9 +3816,10 @@ static int atihdmi_paired_chmap_validate(int ca, int chs, unsigned char *map)
38513816
return 0;
38523817
}
38533818

3854-
static int atihdmi_pin_set_slot_channel(struct hda_codec *codec, hda_nid_t pin_nid,
3855-
int hdmi_slot, int stream_channel)
3819+
static int atihdmi_pin_set_slot_channel(struct hdac_device *hdac,
3820+
hda_nid_t pin_nid, int hdmi_slot, int stream_channel)
38563821
{
3822+
struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
38573823
int verb;
38583824
int ati_channel_setup = 0;
38593825

@@ -3886,9 +3852,10 @@ static int atihdmi_pin_set_slot_channel(struct hda_codec *codec, hda_nid_t pin_n
38863852
return snd_hda_codec_write(codec, pin_nid, 0, verb, ati_channel_setup);
38873853
}
38883854

3889-
static int atihdmi_pin_get_slot_channel(struct hda_codec *codec, hda_nid_t pin_nid,
3890-
int asp_slot)
3855+
static int atihdmi_pin_get_slot_channel(struct hdac_device *hdac,
3856+
hda_nid_t pin_nid, int asp_slot)
38913857
{
3858+
struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
38923859
bool was_odd = false;
38933860
int ati_asp_slot = asp_slot;
38943861
int verb;
@@ -4058,8 +4025,6 @@ static int patch_atihdmi(struct hda_codec *codec)
40584025
spec = codec->spec;
40594026

40604027
spec->ops.pin_get_eld = atihdmi_pin_get_eld;
4061-
spec->ops.pin_get_slot_channel = atihdmi_pin_get_slot_channel;
4062-
spec->ops.pin_set_slot_channel = atihdmi_pin_set_slot_channel;
40634028
spec->ops.pin_setup_infoframe = atihdmi_pin_setup_infoframe;
40644029
spec->ops.pin_hbr_setup = atihdmi_pin_hbr_setup;
40654030
spec->ops.setup_stream = atihdmi_setup_stream;
@@ -4071,6 +4036,10 @@ static int patch_atihdmi(struct hda_codec *codec)
40714036
spec->chmap.ops.cea_alloc_to_tlv_chmap =
40724037
atihdmi_paired_cea_alloc_to_tlv_chmap;
40734038
spec->chmap.ops.chmap_validate = atihdmi_paired_chmap_validate;
4039+
spec->chmap.ops.pin_get_slot_channel =
4040+
atihdmi_pin_get_slot_channel;
4041+
spec->chmap.ops.pin_set_slot_channel =
4042+
atihdmi_pin_set_slot_channel;
40744043
}
40754044

40764045
/* ATI/AMD converters do not advertise all of their capabilities */

0 commit comments

Comments
 (0)