}
+ /*
+ * 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
*/
snd_ctl_elem_value_t *ucontrol, hda_nid_t nid,
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
*/
unsigned int cur_mux[3];
/* channel model */
- const struct alc_channel_mode *channel_mode;
+ const struct hda_channel_mode *channel_mode;
int num_channel_mode;
/* PCM information */
struct cmi_spec {
int board_config;
- unsigned int surr_switch: 1; /* switchable line,mic */
unsigned int no_line_in: 1; /* no line-in (5-jack) */
unsigned int front_panel: 1; /* has front-panel 2-jack */
unsigned int cur_mux[2];
/* channel mode */
- unsigned int num_ch_modes;
- unsigned int cur_ch_mode;
- const struct cmi_channel_mode *channel_modes;
+ int num_channel_modes;
+ const struct hda_channel_mode *channel_modes;
struct hda_pcm pcm_rec[2]; /* PCM information */
{}
};
-struct cmi_channel_mode {
- unsigned int channels;
- const struct hda_verb *sequence;
-};
-
-static struct cmi_channel_mode cmi9880_channel_modes[3] = {
+static struct hda_channel_mode cmi9880_channel_modes[3] = {
{ 2, cmi9880_ch2_init },
{ 6, cmi9880_ch6_init },
{ 8, cmi9880_ch8_init },
{
struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
struct cmi_spec *spec = codec->spec;
-
- snd_assert(spec->channel_modes, return -EINVAL);
- 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;
+ return snd_hda_ch_mode_info(codec, uinfo, spec->channel_modes,
+ spec->num_channel_modes);
}
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 cmi_spec *spec = codec->spec;
-
- ucontrol->value.enumerated.item[0] = spec->cur_ch_mode;
- return 0;
+ return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_modes,
+ spec->num_channel_modes, spec->multiout.max_channels);
}
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 cmi_spec *spec = codec->spec;
-
- snd_assert(spec->channel_modes, return -EINVAL);
- 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;
+ return snd_hda_ch_mode_put(codec, ucontrol, spec->channel_modes,
+ spec->num_channel_modes, &spec->multiout.max_channels);
}
/*
err = snd_hda_add_new_ctls(codec, cmi9880_basic_mixer);
if (err < 0)
return err;
- if (spec->surr_switch) {
+ if (spec->channel_modes) {
err = snd_hda_add_new_ctls(codec, cmi9880_ch_mode_mixer);
if (err < 0)
return err;
cmi9880_init(codec);
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);
if (spec->multiout.dig_out_nid)
snd_hda_resume_spdif_out(codec);
switch (spec->board_config) {
case CMI_MINIMAL:
case CMI_MIN_FP:
- spec->surr_switch = 1;
+ spec->channel_modes = cmi9880_channel_modes;
if (spec->board_config == CMI_MINIMAL)
- spec->num_ch_modes = 2;
+ spec->num_channel_modes = 2;
else {
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->input_mux = &cmi9880_basic_mux;
break;
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_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 */
if (get_defcfg_connect(port_g) == AC_JACK_PORT_NONE ||
get_defcfg_connect(port_h) == AC_JACK_PORT_NONE) {
/* no optional rear panel */
spec->board_config = CMI_MINIMAL;
spec->front_panel = 0;
- spec->num_ch_modes = 2;
+ spec->num_channel_modes = 2;
} else {
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->multiout.max_channels = cmi9880_channel_modes[0].channels;
} else {
unsigned int cur_mux[3];
/* channel model */
- const struct alc_channel_mode *channel_mode;
+ const struct hda_channel_mode *channel_mode;
int num_channel_mode;
/* PCM information */
/*
* 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)
{
struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
struct alc_spec *spec = codec->spec;
- int items = kcontrol->private_value ? (int)kcontrol->private_value : 2;
-
- 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;
+ return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
+ spec->num_channel_mode);
}
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 alc_spec *spec = codec->spec;
- int items = kcontrol->private_value ? (int)kcontrol->private_value : 2;
- int i;
-
- 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;
+ return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
+ spec->num_channel_mode, spec->multiout.max_channels);
}
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 alc_spec *spec = codec->spec;
- int mode;
-
- 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;
+ return snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
+ spec->num_channel_mode, &spec->multiout.max_channels);
}
{ } /* end */
};
-static struct alc_channel_mode alc880_threestack_modes[2] = {
+static struct hda_channel_mode alc880_threestack_modes[2] = {
{ 2, alc880_threestack_ch2_init },
{ 6, alc880_threestack_ch6_init },
};
{ } /* end */
};
-static struct alc_channel_mode alc880_fivestack_modes[2] = {
+static struct hda_channel_mode alc880_fivestack_modes[2] = {
{ 6, alc880_fivestack_ch6_init },
{ 8, alc880_fivestack_ch8_init },
};
};
/* fixed 8-channels */
-static struct alc_channel_mode alc880_sixstack_modes[1] = {
+static struct hda_channel_mode alc880_sixstack_modes[1] = {
{ 8, NULL },
};
};
/* fixed 6 channels */
-static struct alc_channel_mode alc880_w810_modes[1] = {
+static struct hda_channel_mode alc880_w810_modes[1] = {
{ 6, NULL }
};
#define ALC880_Z71V_HP_DAC 0x03
/* 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 }
};
},
};
-static struct alc_channel_mode alc880_test_modes[4] = {
+static struct hda_channel_mode alc880_test_modes[4] = {
{ 2, NULL },
{ 4, NULL },
{ 6, NULL },
unsigned int num_adc_nids;
hda_nid_t *adc_nids;
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;
};
* element which allows changing the channel mode, so the verb list is
* never used.
*/
-static struct alc_channel_mode alc260_modes[1] = {
+static struct hda_channel_mode alc260_modes[1] = {
{ 2, NULL },
};
* driver yet).
*/
-static struct alc_channel_mode alc882_ch_modes[1] = {
+static struct hda_channel_mode alc882_ch_modes[1] = {
{ 8, NULL }
};