Skip to content

Commit 67b90cb

Browse files
Subhransu S. Prustytiwai
authored andcommitted
ALSA: hda - Create common chmap object
chmap object represents multichannel capability and contains chmap ops. Legacy driver is updated to use this. With next set of patches chmap object is moved to common to be reused by other drivers (ex: skylake ASoC hdmi 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 cdb1ee3 commit 67b90cb

2 files changed

Lines changed: 81 additions & 41 deletions

File tree

‎include/sound/hda_chmap.h‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* For multichannel support
3+
*/
4+
5+
#ifndef __SOUND_HDA_CHMAP_H
6+
#define __SOUND_HDA_CHMAP_H
7+
8+
#include <sound/hdaudio.h>
9+
10+
struct cea_channel_speaker_allocation {
11+
int ca_index;
12+
int speakers[8];
13+
14+
/* derived values, just for convenience */
15+
int channels;
16+
int spk_mask;
17+
};
18+
struct hdac_chmap;
19+
20+
struct hdac_chmap_ops {
21+
/*
22+
* Helpers for producing the channel map TLVs. These can be overridden
23+
* for devices that have non-standard mapping requirements.
24+
*/
25+
int (*chmap_cea_alloc_validate_get_type)(struct hdac_chmap *chmap,
26+
struct cea_channel_speaker_allocation *cap, int channels);
27+
void (*cea_alloc_to_tlv_chmap)
28+
(struct cea_channel_speaker_allocation *cap,
29+
unsigned int *chmap, int channels);
30+
31+
/* check that the user-given chmap is supported */
32+
int (*chmap_validate)(int ca, int channels, unsigned char *chmap);
33+
};
34+
35+
struct hdac_chmap {
36+
unsigned int channels_max; /* max over all cvts */
37+
struct hdac_chmap_ops ops;
38+
struct hdac_device *hdac;
39+
};
40+
41+
#endif /* __SOUND_HDA_CHMAP_H */

‎sound/pci/hda/patch_hdmi.c‎

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <sound/tlv.h>
4040
#include <sound/hdaudio.h>
4141
#include <sound/hda_i915.h>
42+
#include <sound/hda_chmap.h>
4243
#include "hda_codec.h"
4344
#include "hda_local.h"
4445
#include "hda_jack.h"
@@ -121,15 +122,6 @@ struct hdmi_ops {
121122
int (*setup_stream)(struct hda_codec *codec, hda_nid_t cvt_nid,
122123
hda_nid_t pin_nid, u32 stream_tag, int format);
123124

124-
/* Helpers for producing the channel map TLVs. These can be overridden
125-
* for devices that have non-standard mapping requirements. */
126-
int (*chmap_cea_alloc_validate_get_type)(struct cea_channel_speaker_allocation *cap,
127-
int channels);
128-
void (*cea_alloc_to_tlv_chmap)(struct cea_channel_speaker_allocation *cap,
129-
unsigned int *chmap, int channels);
130-
131-
/* check that the user-given chmap is supported */
132-
int (*chmap_validate)(int ca, int channels, unsigned char *chmap);
133125
};
134126

135127
struct hdmi_pcm {
@@ -155,7 +147,6 @@ struct hdmi_spec {
155147
* bit 1 means the second playback PCM, and so on.
156148
*/
157149
unsigned long pcm_in_use;
158-
unsigned int channels_max; /* max over all cvts */
159150

160151
struct hdmi_eld temp_eld;
161152
struct hdmi_ops ops;
@@ -171,6 +162,8 @@ struct hdmi_spec {
171162
/* i915/powerwell (Haswell+/Valleyview+) specific */
172163
struct i915_audio_component_audio_ops i915_audio_ops;
173164
bool i915_bound; /* was i915 bound in this driver? */
165+
166+
struct hdac_chmap chmap;
174167
};
175168

176169
#ifdef CONFIG_SND_HDA_I915
@@ -264,15 +257,6 @@ static int eld_speaker_allocation_bits[] = {
264257
[10] = FCH,
265258
};
266259

267-
struct cea_channel_speaker_allocation {
268-
int ca_index;
269-
int speakers[8];
270-
271-
/* derived values, just for convenience */
272-
int channels;
273-
int spk_mask;
274-
};
275-
276260
/*
277261
* ALSA sequence is:
278262
*
@@ -2141,8 +2125,8 @@ static int hdmi_add_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
21412125
per_cvt->channels_min = 2;
21422126
if (chans <= 16) {
21432127
per_cvt->channels_max = chans;
2144-
if (chans > spec->channels_max)
2145-
spec->channels_max = chans;
2128+
if (chans > spec->chmap.channels_max)
2129+
spec->chmap.channels_max = chans;
21462130
}
21472131

21482132
err = snd_hda_query_supported_pcm(codec, cvt_nid,
@@ -2368,15 +2352,17 @@ static int hdmi_chmap_ctl_info(struct snd_kcontrol *kcontrol,
23682352
struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
23692353
struct hda_codec *codec = info->private_data;
23702354
struct hdmi_spec *spec = codec->spec;
2355+
struct hdac_chmap *chmap = &spec->chmap;
2356+
23712357
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2372-
uinfo->count = spec->channels_max;
2358+
uinfo->count = chmap->channels_max;
23732359
uinfo->value.integer.min = 0;
23742360
uinfo->value.integer.max = SNDRV_CHMAP_LAST;
23752361
return 0;
23762362
}
23772363

2378-
static int hdmi_chmap_cea_alloc_validate_get_type(struct cea_channel_speaker_allocation *cap,
2379-
int channels)
2364+
static int hdmi_chmap_cea_alloc_validate_get_type(struct hdac_chmap *chmap,
2365+
struct cea_channel_speaker_allocation *cap, int channels)
23802366
{
23812367
/* If the speaker allocation matches the channel count, it is OK.*/
23822368
if (cap->channels != channels)
@@ -2409,6 +2395,7 @@ static int hdmi_chmap_ctl_tlv(struct snd_kcontrol *kcontrol, int op_flag,
24092395
struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
24102396
struct hda_codec *codec = info->private_data;
24112397
struct hdmi_spec *spec = codec->spec;
2398+
struct hdac_chmap *chmap = &spec->chmap;
24122399
unsigned int __user *dst;
24132400
int chs, count = 0;
24142401

@@ -2418,13 +2405,14 @@ static int hdmi_chmap_ctl_tlv(struct snd_kcontrol *kcontrol, int op_flag,
24182405
return -EFAULT;
24192406
size -= 8;
24202407
dst = tlv + 2;
2421-
for (chs = 2; chs <= spec->channels_max; chs++) {
2408+
for (chs = 2; chs <= chmap->channels_max; chs++) {
24222409
int i;
24232410
struct cea_channel_speaker_allocation *cap;
24242411
cap = channel_allocations;
24252412
for (i = 0; i < ARRAY_SIZE(channel_allocations); i++, cap++) {
24262413
int chs_bytes = chs * 4;
2427-
int type = spec->ops.chmap_cea_alloc_validate_get_type(cap, chs);
2414+
int type = chmap->ops.chmap_cea_alloc_validate_get_type(
2415+
chmap, cap, chs);
24282416
unsigned int tlv_chmap[8];
24292417

24302418
if (type < 0)
@@ -2441,7 +2429,7 @@ static int hdmi_chmap_ctl_tlv(struct snd_kcontrol *kcontrol, int op_flag,
24412429
return -ENOMEM;
24422430
size -= chs_bytes;
24432431
count += chs_bytes;
2444-
spec->ops.cea_alloc_to_tlv_chmap(cap, tlv_chmap, chs);
2432+
chmap->ops.cea_alloc_to_tlv_chmap(cap, tlv_chmap, chs);
24452433
if (copy_to_user(dst, tlv_chmap, chs_bytes))
24462434
return -EFAULT;
24472435
dst += chs;
@@ -2458,12 +2446,13 @@ static int hdmi_chmap_ctl_get(struct snd_kcontrol *kcontrol,
24582446
struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
24592447
struct hda_codec *codec = info->private_data;
24602448
struct hdmi_spec *spec = codec->spec;
2449+
struct hdac_chmap *chmap = &spec->chmap;
24612450
int pcm_idx = kcontrol->private_value;
24622451
struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx);
24632452
int i;
24642453

24652454
if (!per_pin) {
2466-
for (i = 0; i < spec->channels_max; i++)
2455+
for (i = 0; i < chmap->channels_max; i++)
24672456
ucontrol->value.integer.value[i] = 0;
24682457
return 0;
24692458
}
@@ -2479,6 +2468,7 @@ static int hdmi_chmap_ctl_put(struct snd_kcontrol *kcontrol,
24792468
struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
24802469
struct hda_codec *codec = info->private_data;
24812470
struct hdmi_spec *spec = codec->spec;
2471+
struct hdac_chmap *hchmap = &spec->chmap;
24822472
int pcm_idx = kcontrol->private_value;
24832473
struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx);
24842474
unsigned int ctl_idx;
@@ -2514,8 +2504,8 @@ static int hdmi_chmap_ctl_put(struct snd_kcontrol *kcontrol,
25142504
ca = hdmi_manual_channel_allocation(ARRAY_SIZE(chmap), chmap);
25152505
if (ca < 0)
25162506
return -EINVAL;
2517-
if (spec->ops.chmap_validate) {
2518-
err = spec->ops.chmap_validate(ca, ARRAY_SIZE(chmap), chmap);
2507+
if (hchmap->ops.chmap_validate) {
2508+
err = hchmap->ops.chmap_validate(ca, ARRAY_SIZE(chmap), chmap);
25192509
if (err)
25202510
return err;
25212511
}
@@ -2806,6 +2796,9 @@ static const struct hdmi_ops generic_standard_hdmi_ops = {
28062796
.pin_setup_infoframe = hdmi_pin_setup_infoframe,
28072797
.pin_hbr_setup = hdmi_pin_hbr_setup,
28082798
.setup_stream = hdmi_setup_stream,
2799+
};
2800+
2801+
static const struct hdac_chmap_ops chmap_ops = {
28092802
.chmap_cea_alloc_validate_get_type = hdmi_chmap_cea_alloc_validate_get_type,
28102803
.cea_alloc_to_tlv_chmap = hdmi_cea_alloc_to_tlv_chmap,
28112804
};
@@ -2912,6 +2905,8 @@ static int patch_generic_hdmi(struct hda_codec *codec)
29122905

29132906
spec->ops = generic_standard_hdmi_ops;
29142907
mutex_init(&spec->pcm_lock);
2908+
spec->chmap.ops = chmap_ops;
2909+
spec->chmap.hdac = &codec->core;
29152910
codec->spec = spec;
29162911
hdmi_array_init(spec, 4);
29172912

@@ -3503,13 +3498,14 @@ static int patch_nvhdmi_8ch_7x(struct hda_codec *codec)
35033498
* - 0x10de0015
35043499
* - 0x10de0040
35053500
*/
3506-
static int nvhdmi_chmap_cea_alloc_validate_get_type(struct cea_channel_speaker_allocation *cap,
3507-
int channels)
3501+
static int nvhdmi_chmap_cea_alloc_validate_get_type(struct hdac_chmap *chmap,
3502+
struct cea_channel_speaker_allocation *cap, int channels)
35083503
{
35093504
if (cap->ca_index == 0x00 && channels == 2)
35103505
return SNDRV_CTL_TLVT_CHMAP_FIXED;
35113506

3512-
return hdmi_chmap_cea_alloc_validate_get_type(cap, channels);
3507+
return chmap->ops.chmap_cea_alloc_validate_get_type(
3508+
chmap, cap, channels);
35133509
}
35143510

35153511
static int nvhdmi_chmap_validate(int ca, int chs, unsigned char *map)
@@ -3532,9 +3528,9 @@ static int patch_nvhdmi(struct hda_codec *codec)
35323528
spec = codec->spec;
35333529
spec->dyn_pin_out = true;
35343530

3535-
spec->ops.chmap_cea_alloc_validate_get_type =
3531+
spec->chmap.ops.chmap_cea_alloc_validate_get_type =
35363532
nvhdmi_chmap_cea_alloc_validate_get_type;
3537-
spec->ops.chmap_validate = nvhdmi_chmap_validate;
3533+
spec->chmap.ops.chmap_validate = nvhdmi_chmap_validate;
35383534

35393535
return 0;
35403536
}
@@ -3893,8 +3889,10 @@ static int atihdmi_pin_get_slot_channel(struct hda_codec *codec, hda_nid_t pin_n
38933889
return ((ati_channel_setup & 0xf0) >> 4) + !!was_odd;
38943890
}
38953891

3896-
static int atihdmi_paired_chmap_cea_alloc_validate_get_type(struct cea_channel_speaker_allocation *cap,
3897-
int channels)
3892+
static int atihdmi_paired_chmap_cea_alloc_validate_get_type(
3893+
struct hdac_chmap *chmap,
3894+
struct cea_channel_speaker_allocation *cap,
3895+
int channels)
38983896
{
38993897
int c;
39003898

@@ -4041,10 +4039,11 @@ static int patch_atihdmi(struct hda_codec *codec)
40414039

40424040
if (!has_amd_full_remap_support(codec)) {
40434041
/* override to ATI/AMD-specific versions with pairwise mapping */
4044-
spec->ops.chmap_cea_alloc_validate_get_type =
4042+
spec->chmap.ops.chmap_cea_alloc_validate_get_type =
40454043
atihdmi_paired_chmap_cea_alloc_validate_get_type;
4046-
spec->ops.cea_alloc_to_tlv_chmap = atihdmi_paired_cea_alloc_to_tlv_chmap;
4047-
spec->ops.chmap_validate = atihdmi_paired_chmap_validate;
4044+
spec->chmap.ops.cea_alloc_to_tlv_chmap =
4045+
atihdmi_paired_cea_alloc_to_tlv_chmap;
4046+
spec->chmap.ops.chmap_validate = atihdmi_paired_chmap_validate;
40484047
}
40494048

40504049
/* ATI/AMD converters do not advertise all of their capabilities */
@@ -4056,7 +4055,7 @@ static int patch_atihdmi(struct hda_codec *codec)
40564055
per_cvt->maxbps = max(per_cvt->maxbps, 24u);
40574056
}
40584057

4059-
spec->channels_max = max(spec->channels_max, 8u);
4058+
spec->chmap.channels_max = max(spec->chmap.channels_max, 8u);
40604059

40614060
return 0;
40624061
}

0 commit comments

Comments
 (0)