aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/hda/patch_cmedia.c
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2005-11-17 05:06:29 -0500
committerJaroslav Kysela <perex@suse.cz>2006-01-03 06:17:21 -0500
commitd2a6d7dc757da6b57d77bd8b460cf4faa9fd152d (patch)
treeb3edf27437b4be8ee23917b852d8e93376ac62da /sound/pci/hda/patch_cmedia.c
parent59de641ca37b88dd34d0e1d853800b488f642624 (diff)
[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: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/pci/hda/patch_cmedia.c')
-rw-r--r--sound/pci/hda/patch_cmedia.c62
1 files changed, 17 insertions, 45 deletions
diff --git a/sound/pci/hda/patch_cmedia.c b/sound/pci/hda/patch_cmedia.c
index 523c362ec44d..6e0fd92a2be3 100644
--- a/sound/pci/hda/patch_cmedia.c
+++ b/sound/pci/hda/patch_cmedia.c
@@ -44,7 +44,6 @@ enum {
44 44
45struct cmi_spec { 45struct cmi_spec {
46 int board_config; 46 int board_config;
47 unsigned int surr_switch: 1; /* switchable line,mic */
48 unsigned int no_line_in: 1; /* no line-in (5-jack) */ 47 unsigned int no_line_in: 1; /* no line-in (5-jack) */
49 unsigned int front_panel: 1; /* has front-panel 2-jack */ 48 unsigned int front_panel: 1; /* has front-panel 2-jack */
50 49
@@ -62,9 +61,8 @@ struct cmi_spec {
62 unsigned int cur_mux[2]; 61 unsigned int cur_mux[2];
63 62
64 /* channel mode */ 63 /* channel mode */
65 unsigned int num_ch_modes; 64 int num_channel_modes;
66 unsigned int cur_ch_mode; 65 const struct hda_channel_mode *channel_modes;
67 const struct cmi_channel_mode *channel_modes;
68 66
69 struct hda_pcm pcm_rec[2]; /* PCM information */ 67 struct hda_pcm pcm_rec[2]; /* PCM information */
70 68
@@ -158,12 +156,7 @@ static struct hda_verb cmi9880_ch8_init[] = {
158 {} 156 {}
159}; 157};
160 158
161struct cmi_channel_mode { 159static struct hda_channel_mode cmi9880_channel_modes[3] = {
162 unsigned int channels;
163 const struct hda_verb *sequence;
164};
165
166static struct cmi_channel_mode cmi9880_channel_modes[3] = {
167 { 2, cmi9880_ch2_init }, 160 { 2, cmi9880_ch2_init },
168 { 6, cmi9880_ch6_init }, 161 { 6, cmi9880_ch6_init },
169 { 8, cmi9880_ch8_init }, 162 { 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{ 166{
174 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 167 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
175 struct cmi_spec *spec = codec->spec; 168 struct cmi_spec *spec = codec->spec;
176 169 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_modes,
177 snd_assert(spec->channel_modes, return -EINVAL); 170 spec->num_channel_modes);
178 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
179 uinfo->count = 1;
180 uinfo->value.enumerated.items = spec->num_ch_modes;
181 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
182 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
183 sprintf(uinfo->value.enumerated.name, "%dch",
184 spec->channel_modes[uinfo->value.enumerated.item].channels);
185 return 0;
186} 171}
187 172
188static int cmi_ch_mode_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) 173static int cmi_ch_mode_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
189{ 174{
190 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 175 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
191 struct cmi_spec *spec = codec->spec; 176 struct cmi_spec *spec = codec->spec;
192 177 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_modes,
193 ucontrol->value.enumerated.item[0] = spec->cur_ch_mode; 178 spec->num_channel_modes, spec->multiout.max_channels);
194 return 0;
195} 179}
196 180
197static int cmi_ch_mode_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) 181static int cmi_ch_mode_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
198{ 182{
199 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 183 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
200 struct cmi_spec *spec = codec->spec; 184 struct cmi_spec *spec = codec->spec;
201 185 return snd_hda_ch_mode_put(codec, ucontrol, spec->channel_modes,
202 snd_assert(spec->channel_modes, return -EINVAL); 186 spec->num_channel_modes, &spec->multiout.max_channels);
203 if (ucontrol->value.enumerated.item[0] >= spec->num_ch_modes)
204 ucontrol->value.enumerated.item[0] = spec->num_ch_modes;
205 if (ucontrol->value.enumerated.item[0] == spec->cur_ch_mode &&
206 ! codec->in_resume)
207 return 0;
208
209 spec->cur_ch_mode = ucontrol->value.enumerated.item[0];
210 snd_hda_sequence_write(codec, spec->channel_modes[spec->cur_ch_mode].sequence);
211 spec->multiout.max_channels = spec->channel_modes[spec->cur_ch_mode].channels;
212 return 1;
213} 187}
214 188
215/* 189/*
@@ -361,7 +335,7 @@ static int cmi9880_build_controls(struct hda_codec *codec)
361 err = snd_hda_add_new_ctls(codec, cmi9880_basic_mixer); 335 err = snd_hda_add_new_ctls(codec, cmi9880_basic_mixer);
362 if (err < 0) 336 if (err < 0)
363 return err; 337 return err;
364 if (spec->surr_switch) { 338 if (spec->channel_modes) {
365 err = snd_hda_add_new_ctls(codec, cmi9880_ch_mode_mixer); 339 err = snd_hda_add_new_ctls(codec, cmi9880_ch_mode_mixer);
366 if (err < 0) 340 if (err < 0)
367 return err; 341 return err;
@@ -475,7 +449,7 @@ static int cmi9880_resume(struct hda_codec *codec)
475 449
476 cmi9880_init(codec); 450 cmi9880_init(codec);
477 snd_hda_resume_ctls(codec, cmi9880_basic_mixer); 451 snd_hda_resume_ctls(codec, cmi9880_basic_mixer);
478 if (spec->surr_switch) 452 if (spec->channel_modes)
479 snd_hda_resume_ctls(codec, cmi9880_ch_mode_mixer); 453 snd_hda_resume_ctls(codec, cmi9880_ch_mode_mixer);
480 if (spec->multiout.dig_out_nid) 454 if (spec->multiout.dig_out_nid)
481 snd_hda_resume_spdif_out(codec); 455 snd_hda_resume_spdif_out(codec);
@@ -685,14 +659,13 @@ static int patch_cmi9880(struct hda_codec *codec)
685 switch (spec->board_config) { 659 switch (spec->board_config) {
686 case CMI_MINIMAL: 660 case CMI_MINIMAL:
687 case CMI_MIN_FP: 661 case CMI_MIN_FP:
688 spec->surr_switch = 1; 662 spec->channel_modes = cmi9880_channel_modes;
689 if (spec->board_config == CMI_MINIMAL) 663 if (spec->board_config == CMI_MINIMAL)
690 spec->num_ch_modes = 2; 664 spec->num_channel_modes = 2;
691 else { 665 else {
692 spec->front_panel = 1; 666 spec->front_panel = 1;
693 spec->num_ch_modes = 3; 667 spec->num_channel_modes = 3;
694 } 668 }
695 spec->channel_modes = cmi9880_channel_modes;
696 spec->multiout.max_channels = cmi9880_channel_modes[0].channels; 669 spec->multiout.max_channels = cmi9880_channel_modes[0].channels;
697 spec->input_mux = &cmi9880_basic_mux; 670 spec->input_mux = &cmi9880_basic_mux;
698 break; 671 break;
@@ -727,19 +700,18 @@ static int patch_cmi9880(struct hda_codec *codec)
727 get_defcfg_connect(port_f) == AC_JACK_PORT_NONE) { 700 get_defcfg_connect(port_f) == AC_JACK_PORT_NONE) {
728 port_g = snd_hda_codec_read(codec, 0x1f, 0, AC_VERB_GET_CONFIG_DEFAULT, 0); 701 port_g = snd_hda_codec_read(codec, 0x1f, 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
729 port_h = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_CONFIG_DEFAULT, 0); 702 port_h = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
730 spec->surr_switch = 1; 703 spec->channel_modes = cmi9880_channel_modes;
731 /* no front panel */ 704 /* no front panel */
732 if (get_defcfg_connect(port_g) == AC_JACK_PORT_NONE || 705 if (get_defcfg_connect(port_g) == AC_JACK_PORT_NONE ||
733 get_defcfg_connect(port_h) == AC_JACK_PORT_NONE) { 706 get_defcfg_connect(port_h) == AC_JACK_PORT_NONE) {
734 /* no optional rear panel */ 707 /* no optional rear panel */
735 spec->board_config = CMI_MINIMAL; 708 spec->board_config = CMI_MINIMAL;
736 spec->front_panel = 0; 709 spec->front_panel = 0;
737 spec->num_ch_modes = 2; 710 spec->num_channel_modes = 2;
738 } else { 711 } else {
739 spec->board_config = CMI_MIN_FP; 712 spec->board_config = CMI_MIN_FP;
740 spec->num_ch_modes = 3; 713 spec->num_channel_modes = 3;
741 } 714 }
742 spec->channel_modes = cmi9880_channel_modes;
743 spec->input_mux = &cmi9880_basic_mux; 715 spec->input_mux = &cmi9880_basic_mux;
744 spec->multiout.max_channels = cmi9880_channel_modes[0].channels; 716 spec->multiout.max_channels = cmi9880_channel_modes[0].channels;
745 } else { 717 } else {