提交 d2a6d7dc 编写于 作者: T Takashi Iwai 提交者: Jaroslav Kysela

[ALSA] hda-codec - Add channel-mode helper

Modules: HDA Codec driver,HDA generic driver

Add common channel-mode helper functions for all codec patches.
Signed-off-by: NTakashi Iwai <tiwai@suse.de>
上级 59de641c
...@@ -1662,6 +1662,54 @@ int snd_hda_add_new_ctls(struct hda_codec *codec, snd_kcontrol_new_t *knew) ...@@ -1662,6 +1662,54 @@ int snd_hda_add_new_ctls(struct hda_codec *codec, snd_kcontrol_new_t *knew)
} }
/*
* Channel mode helper
*/
int snd_hda_ch_mode_info(struct hda_codec *codec, snd_ctl_elem_info_t *uinfo,
const struct hda_channel_mode *chmode, int num_chmodes)
{
uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
uinfo->count = 1;
uinfo->value.enumerated.items = num_chmodes;
if (uinfo->value.enumerated.item >= num_chmodes)
uinfo->value.enumerated.item = num_chmodes - 1;
sprintf(uinfo->value.enumerated.name, "%dch",
chmode[uinfo->value.enumerated.item].channels);
return 0;
}
int snd_hda_ch_mode_get(struct hda_codec *codec, snd_ctl_elem_value_t *ucontrol,
const struct hda_channel_mode *chmode, int num_chmodes,
int max_channels)
{
int i;
for (i = 0; i < num_chmodes; i++) {
if (max_channels == chmode[i].channels) {
ucontrol->value.enumerated.item[0] = i;
break;
}
}
return 0;
}
int snd_hda_ch_mode_put(struct hda_codec *codec, snd_ctl_elem_value_t *ucontrol,
const struct hda_channel_mode *chmode, int num_chmodes,
int *max_channelsp)
{
unsigned int mode;
mode = ucontrol->value.enumerated.item[0];
snd_assert(mode < num_chmodes, return -EINVAL);
if (*max_channelsp && ! codec->in_resume)
return 0;
/* change the current channel setting */
*max_channelsp = chmode[mode].channels;
if (chmode[mode].sequence)
snd_hda_sequence_write(codec, chmode[mode].sequence);
return 1;
}
/* /*
* input MUX helper * input MUX helper
*/ */
......
...@@ -102,6 +102,23 @@ int snd_hda_input_mux_put(struct hda_codec *codec, const struct hda_input_mux *i ...@@ -102,6 +102,23 @@ int snd_hda_input_mux_put(struct hda_codec *codec, const struct hda_input_mux *i
snd_ctl_elem_value_t *ucontrol, hda_nid_t nid, snd_ctl_elem_value_t *ucontrol, hda_nid_t nid,
unsigned int *cur_val); unsigned int *cur_val);
/*
* Channel mode helper
*/
struct hda_channel_mode {
int channels;
const struct hda_verb *sequence;
};
int snd_hda_ch_mode_info(struct hda_codec *codec, snd_ctl_elem_info_t *uinfo,
const struct hda_channel_mode *chmode, int num_chmodes);
int snd_hda_ch_mode_get(struct hda_codec *codec, snd_ctl_elem_value_t *ucontrol,
const struct hda_channel_mode *chmode, int num_chmodes,
int max_channels);
int snd_hda_ch_mode_put(struct hda_codec *codec, snd_ctl_elem_value_t *ucontrol,
const struct hda_channel_mode *chmode, int num_chmodes,
int *max_channelsp);
/* /*
* Multi-channel / digital-out PCM helper * Multi-channel / digital-out PCM helper
*/ */
......
...@@ -52,7 +52,7 @@ struct ad198x_spec { ...@@ -52,7 +52,7 @@ struct ad198x_spec {
unsigned int cur_mux[3]; unsigned int cur_mux[3];
/* channel model */ /* channel model */
const struct alc_channel_mode *channel_mode; const struct hda_channel_mode *channel_mode;
int num_channel_mode; int num_channel_mode;
/* PCM information */ /* PCM information */
......
...@@ -44,7 +44,6 @@ enum { ...@@ -44,7 +44,6 @@ enum {
struct cmi_spec { struct cmi_spec {
int board_config; int board_config;
unsigned int surr_switch: 1; /* switchable line,mic */
unsigned int no_line_in: 1; /* no line-in (5-jack) */ unsigned int no_line_in: 1; /* no line-in (5-jack) */
unsigned int front_panel: 1; /* has front-panel 2-jack */ unsigned int front_panel: 1; /* has front-panel 2-jack */
...@@ -62,9 +61,8 @@ struct cmi_spec { ...@@ -62,9 +61,8 @@ struct cmi_spec {
unsigned int cur_mux[2]; unsigned int cur_mux[2];
/* channel mode */ /* channel mode */
unsigned int num_ch_modes; int num_channel_modes;
unsigned int cur_ch_mode; const struct hda_channel_mode *channel_modes;
const struct cmi_channel_mode *channel_modes;
struct hda_pcm pcm_rec[2]; /* PCM information */ struct hda_pcm pcm_rec[2]; /* PCM information */
...@@ -158,12 +156,7 @@ static struct hda_verb cmi9880_ch8_init[] = { ...@@ -158,12 +156,7 @@ static struct hda_verb cmi9880_ch8_init[] = {
{} {}
}; };
struct cmi_channel_mode { static struct hda_channel_mode cmi9880_channel_modes[3] = {
unsigned int channels;
const struct hda_verb *sequence;
};
static struct cmi_channel_mode cmi9880_channel_modes[3] = {
{ 2, cmi9880_ch2_init }, { 2, cmi9880_ch2_init },
{ 6, cmi9880_ch6_init }, { 6, cmi9880_ch6_init },
{ 8, cmi9880_ch8_init }, { 8, cmi9880_ch8_init },
...@@ -173,43 +166,24 @@ static int cmi_ch_mode_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo ...@@ -173,43 +166,24 @@ static int cmi_ch_mode_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo
{ {
struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
struct cmi_spec *spec = codec->spec; struct cmi_spec *spec = codec->spec;
return snd_hda_ch_mode_info(codec, uinfo, spec->channel_modes,
snd_assert(spec->channel_modes, return -EINVAL); spec->num_channel_modes);
uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
uinfo->count = 1;
uinfo->value.enumerated.items = spec->num_ch_modes;
if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
sprintf(uinfo->value.enumerated.name, "%dch",
spec->channel_modes[uinfo->value.enumerated.item].channels);
return 0;
} }
static int cmi_ch_mode_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) static int cmi_ch_mode_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
{ {
struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
struct cmi_spec *spec = codec->spec; struct cmi_spec *spec = codec->spec;
return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_modes,
ucontrol->value.enumerated.item[0] = spec->cur_ch_mode; spec->num_channel_modes, spec->multiout.max_channels);
return 0;
} }
static int cmi_ch_mode_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) static int cmi_ch_mode_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
{ {
struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
struct cmi_spec *spec = codec->spec; struct cmi_spec *spec = codec->spec;
return snd_hda_ch_mode_put(codec, ucontrol, spec->channel_modes,
snd_assert(spec->channel_modes, return -EINVAL); spec->num_channel_modes, &spec->multiout.max_channels);
if (ucontrol->value.enumerated.item[0] >= spec->num_ch_modes)
ucontrol->value.enumerated.item[0] = spec->num_ch_modes;
if (ucontrol->value.enumerated.item[0] == spec->cur_ch_mode &&
! codec->in_resume)
return 0;
spec->cur_ch_mode = ucontrol->value.enumerated.item[0];
snd_hda_sequence_write(codec, spec->channel_modes[spec->cur_ch_mode].sequence);
spec->multiout.max_channels = spec->channel_modes[spec->cur_ch_mode].channels;
return 1;
} }
/* /*
...@@ -361,7 +335,7 @@ static int cmi9880_build_controls(struct hda_codec *codec) ...@@ -361,7 +335,7 @@ static int cmi9880_build_controls(struct hda_codec *codec)
err = snd_hda_add_new_ctls(codec, cmi9880_basic_mixer); err = snd_hda_add_new_ctls(codec, cmi9880_basic_mixer);
if (err < 0) if (err < 0)
return err; return err;
if (spec->surr_switch) { if (spec->channel_modes) {
err = snd_hda_add_new_ctls(codec, cmi9880_ch_mode_mixer); err = snd_hda_add_new_ctls(codec, cmi9880_ch_mode_mixer);
if (err < 0) if (err < 0)
return err; return err;
...@@ -475,7 +449,7 @@ static int cmi9880_resume(struct hda_codec *codec) ...@@ -475,7 +449,7 @@ static int cmi9880_resume(struct hda_codec *codec)
cmi9880_init(codec); cmi9880_init(codec);
snd_hda_resume_ctls(codec, cmi9880_basic_mixer); snd_hda_resume_ctls(codec, cmi9880_basic_mixer);
if (spec->surr_switch) if (spec->channel_modes)
snd_hda_resume_ctls(codec, cmi9880_ch_mode_mixer); snd_hda_resume_ctls(codec, cmi9880_ch_mode_mixer);
if (spec->multiout.dig_out_nid) if (spec->multiout.dig_out_nid)
snd_hda_resume_spdif_out(codec); snd_hda_resume_spdif_out(codec);
...@@ -685,14 +659,13 @@ static int patch_cmi9880(struct hda_codec *codec) ...@@ -685,14 +659,13 @@ static int patch_cmi9880(struct hda_codec *codec)
switch (spec->board_config) { switch (spec->board_config) {
case CMI_MINIMAL: case CMI_MINIMAL:
case CMI_MIN_FP: case CMI_MIN_FP:
spec->surr_switch = 1; spec->channel_modes = cmi9880_channel_modes;
if (spec->board_config == CMI_MINIMAL) if (spec->board_config == CMI_MINIMAL)
spec->num_ch_modes = 2; spec->num_channel_modes = 2;
else { else {
spec->front_panel = 1; spec->front_panel = 1;
spec->num_ch_modes = 3; spec->num_channel_modes = 3;
} }
spec->channel_modes = cmi9880_channel_modes;
spec->multiout.max_channels = cmi9880_channel_modes[0].channels; spec->multiout.max_channels = cmi9880_channel_modes[0].channels;
spec->input_mux = &cmi9880_basic_mux; spec->input_mux = &cmi9880_basic_mux;
break; break;
...@@ -727,19 +700,18 @@ static int patch_cmi9880(struct hda_codec *codec) ...@@ -727,19 +700,18 @@ static int patch_cmi9880(struct hda_codec *codec)
get_defcfg_connect(port_f) == AC_JACK_PORT_NONE) { get_defcfg_connect(port_f) == AC_JACK_PORT_NONE) {
port_g = snd_hda_codec_read(codec, 0x1f, 0, AC_VERB_GET_CONFIG_DEFAULT, 0); port_g = snd_hda_codec_read(codec, 0x1f, 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
port_h = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_CONFIG_DEFAULT, 0); port_h = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
spec->surr_switch = 1; spec->channel_modes = cmi9880_channel_modes;
/* no front panel */ /* no front panel */
if (get_defcfg_connect(port_g) == AC_JACK_PORT_NONE || if (get_defcfg_connect(port_g) == AC_JACK_PORT_NONE ||
get_defcfg_connect(port_h) == AC_JACK_PORT_NONE) { get_defcfg_connect(port_h) == AC_JACK_PORT_NONE) {
/* no optional rear panel */ /* no optional rear panel */
spec->board_config = CMI_MINIMAL; spec->board_config = CMI_MINIMAL;
spec->front_panel = 0; spec->front_panel = 0;
spec->num_ch_modes = 2; spec->num_channel_modes = 2;
} else { } else {
spec->board_config = CMI_MIN_FP; spec->board_config = CMI_MIN_FP;
spec->num_ch_modes = 3; spec->num_channel_modes = 3;
} }
spec->channel_modes = cmi9880_channel_modes;
spec->input_mux = &cmi9880_basic_mux; spec->input_mux = &cmi9880_basic_mux;
spec->multiout.max_channels = cmi9880_channel_modes[0].channels; spec->multiout.max_channels = cmi9880_channel_modes[0].channels;
} else { } else {
......
...@@ -109,7 +109,7 @@ struct alc_spec { ...@@ -109,7 +109,7 @@ struct alc_spec {
unsigned int cur_mux[3]; unsigned int cur_mux[3];
/* channel model */ /* channel model */
const struct alc_channel_mode *channel_mode; const struct hda_channel_mode *channel_mode;
int num_channel_mode; int num_channel_mode;
/* PCM information */ /* PCM information */
...@@ -157,63 +157,28 @@ static int alc_mux_enum_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucon ...@@ -157,63 +157,28 @@ static int alc_mux_enum_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucon
/* /*
* channel mode setting * channel mode setting
*/ */
struct alc_channel_mode {
int channels;
const struct hda_verb *sequence;
};
static int alc880_ch_mode_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo) static int alc880_ch_mode_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
{ {
struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
struct alc_spec *spec = codec->spec; struct alc_spec *spec = codec->spec;
int items = kcontrol->private_value ? (int)kcontrol->private_value : 2; return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
spec->num_channel_mode);
snd_assert(spec->channel_mode, return -ENXIO);
uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
uinfo->count = 1;
uinfo->value.enumerated.items = items;
if (uinfo->value.enumerated.item >= items)
uinfo->value.enumerated.item = items - 1;
sprintf(uinfo->value.enumerated.name, "%dch",
spec->channel_mode[uinfo->value.enumerated.item].channels);
return 0;
} }
static int alc880_ch_mode_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) static int alc880_ch_mode_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
{ {
struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
struct alc_spec *spec = codec->spec; struct alc_spec *spec = codec->spec;
int items = kcontrol->private_value ? (int)kcontrol->private_value : 2; return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
int i; spec->num_channel_mode, spec->multiout.max_channels);
snd_assert(spec->channel_mode, return -ENXIO);
for (i = 0; i < items; i++) {
if (spec->multiout.max_channels == spec->channel_mode[i].channels) {
ucontrol->value.enumerated.item[0] = i;
break;
}
}
return 0;
} }
static int alc880_ch_mode_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) static int alc880_ch_mode_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
{ {
struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
struct alc_spec *spec = codec->spec; struct alc_spec *spec = codec->spec;
int mode; return snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
spec->num_channel_mode, &spec->multiout.max_channels);
snd_assert(spec->channel_mode, return -ENXIO);
mode = ucontrol->value.enumerated.item[0] ? 1 : 0;
if (spec->multiout.max_channels == spec->channel_mode[mode].channels &&
! codec->in_resume)
return 0;
/* change the current channel setting */
spec->multiout.max_channels = spec->channel_mode[mode].channels;
if (spec->channel_mode[mode].sequence)
snd_hda_sequence_write(codec, spec->channel_mode[mode].sequence);
return 1;
} }
...@@ -328,7 +293,7 @@ static struct hda_verb alc880_threestack_ch6_init[] = { ...@@ -328,7 +293,7 @@ static struct hda_verb alc880_threestack_ch6_init[] = {
{ } /* end */ { } /* end */
}; };
static struct alc_channel_mode alc880_threestack_modes[2] = { static struct hda_channel_mode alc880_threestack_modes[2] = {
{ 2, alc880_threestack_ch2_init }, { 2, alc880_threestack_ch2_init },
{ 6, alc880_threestack_ch6_init }, { 6, alc880_threestack_ch6_init },
}; };
...@@ -443,7 +408,7 @@ static struct hda_verb alc880_fivestack_ch8_init[] = { ...@@ -443,7 +408,7 @@ static struct hda_verb alc880_fivestack_ch8_init[] = {
{ } /* end */ { } /* end */
}; };
static struct alc_channel_mode alc880_fivestack_modes[2] = { static struct hda_channel_mode alc880_fivestack_modes[2] = {
{ 6, alc880_fivestack_ch6_init }, { 6, alc880_fivestack_ch6_init },
{ 8, alc880_fivestack_ch8_init }, { 8, alc880_fivestack_ch8_init },
}; };
...@@ -473,7 +438,7 @@ static struct hda_input_mux alc880_6stack_capture_source = { ...@@ -473,7 +438,7 @@ static struct hda_input_mux alc880_6stack_capture_source = {
}; };
/* fixed 8-channels */ /* fixed 8-channels */
static struct alc_channel_mode alc880_sixstack_modes[1] = { static struct hda_channel_mode alc880_sixstack_modes[1] = {
{ 8, NULL }, { 8, NULL },
}; };
...@@ -540,7 +505,7 @@ static hda_nid_t alc880_w810_dac_nids[3] = { ...@@ -540,7 +505,7 @@ static hda_nid_t alc880_w810_dac_nids[3] = {
}; };
/* fixed 6 channels */ /* fixed 6 channels */
static struct alc_channel_mode alc880_w810_modes[1] = { static struct hda_channel_mode alc880_w810_modes[1] = {
{ 6, NULL } { 6, NULL }
}; };
...@@ -572,7 +537,7 @@ static hda_nid_t alc880_z71v_dac_nids[1] = { ...@@ -572,7 +537,7 @@ static hda_nid_t alc880_z71v_dac_nids[1] = {
#define ALC880_Z71V_HP_DAC 0x03 #define ALC880_Z71V_HP_DAC 0x03
/* fixed 2 channels */ /* fixed 2 channels */
static struct alc_channel_mode alc880_2_jack_modes[1] = { static struct hda_channel_mode alc880_2_jack_modes[1] = {
{ 2, NULL } { 2, NULL }
}; };
...@@ -1227,7 +1192,7 @@ static struct hda_input_mux alc880_test_capture_source = { ...@@ -1227,7 +1192,7 @@ static struct hda_input_mux alc880_test_capture_source = {
}, },
}; };
static struct alc_channel_mode alc880_test_modes[4] = { static struct hda_channel_mode alc880_test_modes[4] = {
{ 2, NULL }, { 2, NULL },
{ 4, NULL }, { 4, NULL },
{ 6, NULL }, { 6, NULL },
...@@ -1585,7 +1550,7 @@ struct alc_config_preset { ...@@ -1585,7 +1550,7 @@ struct alc_config_preset {
unsigned int num_adc_nids; unsigned int num_adc_nids;
hda_nid_t *adc_nids; hda_nid_t *adc_nids;
unsigned int num_channel_mode; unsigned int num_channel_mode;
const struct alc_channel_mode *channel_mode; const struct hda_channel_mode *channel_mode;
const struct hda_input_mux *input_mux; const struct hda_input_mux *input_mux;
}; };
...@@ -2202,7 +2167,7 @@ static struct hda_input_mux alc260_fujitsu_capture_source = { ...@@ -2202,7 +2167,7 @@ static struct hda_input_mux alc260_fujitsu_capture_source = {
* element which allows changing the channel mode, so the verb list is * element which allows changing the channel mode, so the verb list is
* never used. * never used.
*/ */
static struct alc_channel_mode alc260_modes[1] = { static struct hda_channel_mode alc260_modes[1] = {
{ 2, NULL }, { 2, NULL },
}; };
...@@ -2506,7 +2471,7 @@ static int patch_alc260(struct hda_codec *codec) ...@@ -2506,7 +2471,7 @@ static int patch_alc260(struct hda_codec *codec)
* driver yet). * driver yet).
*/ */
static struct alc_channel_mode alc882_ch_modes[1] = { static struct hda_channel_mode alc882_ch_modes[1] = {
{ 8, NULL } { 8, NULL }
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册