diff options
author | Takashi Iwai <tiwai@suse.de> | 2015-03-16 18:34:34 -0400 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2015-03-17 15:57:20 -0400 |
commit | fb83b6351052bf78686df2559f7ea6b10e596850 (patch) | |
tree | eee9711b4e895efc5c51587fe2cb87340a45c929 /sound/pci | |
parent | 2a557a861ae44e1941452bc2d700f1be58c1325b (diff) |
ALSA: hda - Simplify PCM setup overrides
This patch does two things:
- code refactoring with a local helper function,
- allow codec drivers to provide the specific PCM stream info pointers
only for overriding the non-NULL entries, instead of copying the
whole.
This simplifies the codec driver side (currently the only user is
alc269's 44kHz fixed rate).
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/pci')
-rw-r--r-- | sound/pci/hda/hda_generic.c | 110 | ||||
-rw-r--r-- | sound/pci/hda/patch_realtek.c | 41 |
2 files changed, 60 insertions, 91 deletions
diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c index ebdbc023583d..27ce54701f0f 100644 --- a/sound/pci/hda/hda_generic.c +++ b/sound/pci/hda/hda_generic.c | |||
@@ -5137,6 +5137,33 @@ static void fill_pcm_stream_name(char *str, size_t len, const char *sfx, | |||
5137 | strlcat(str, sfx, len); | 5137 | strlcat(str, sfx, len); |
5138 | } | 5138 | } |
5139 | 5139 | ||
5140 | /* copy PCM stream info from @default_str, and override non-NULL entries | ||
5141 | * from @spec_str and @nid | ||
5142 | */ | ||
5143 | static void setup_pcm_stream(struct hda_pcm_stream *str, | ||
5144 | const struct hda_pcm_stream *default_str, | ||
5145 | const struct hda_pcm_stream *spec_str, | ||
5146 | hda_nid_t nid) | ||
5147 | { | ||
5148 | *str = *default_str; | ||
5149 | if (nid) | ||
5150 | str->nid = nid; | ||
5151 | if (spec_str) { | ||
5152 | if (spec_str->substreams) | ||
5153 | str->substreams = spec_str->substreams; | ||
5154 | if (spec_str->channels_min) | ||
5155 | str->channels_min = spec_str->channels_min; | ||
5156 | if (spec_str->channels_max) | ||
5157 | str->channels_max = spec_str->channels_max; | ||
5158 | if (spec_str->rates) | ||
5159 | str->rates = spec_str->rates; | ||
5160 | if (spec_str->formats) | ||
5161 | str->formats = spec_str->formats; | ||
5162 | if (spec_str->maxbps) | ||
5163 | str->maxbps = spec_str->maxbps; | ||
5164 | } | ||
5165 | } | ||
5166 | |||
5140 | /** | 5167 | /** |
5141 | * snd_hda_gen_build_pcms - build PCM streams based on the parsed results | 5168 | * snd_hda_gen_build_pcms - build PCM streams based on the parsed results |
5142 | * @codec: the HDA codec | 5169 | * @codec: the HDA codec |
@@ -5147,7 +5174,6 @@ int snd_hda_gen_build_pcms(struct hda_codec *codec) | |||
5147 | { | 5174 | { |
5148 | struct hda_gen_spec *spec = codec->spec; | 5175 | struct hda_gen_spec *spec = codec->spec; |
5149 | struct hda_pcm *info; | 5176 | struct hda_pcm *info; |
5150 | const struct hda_pcm_stream *p; | ||
5151 | bool have_multi_adcs; | 5177 | bool have_multi_adcs; |
5152 | 5178 | ||
5153 | if (spec->no_analog) | 5179 | if (spec->no_analog) |
@@ -5162,11 +5188,10 @@ int snd_hda_gen_build_pcms(struct hda_codec *codec) | |||
5162 | spec->pcm_rec[0] = info; | 5188 | spec->pcm_rec[0] = info; |
5163 | 5189 | ||
5164 | if (spec->multiout.num_dacs > 0) { | 5190 | if (spec->multiout.num_dacs > 0) { |
5165 | p = spec->stream_analog_playback; | 5191 | setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK], |
5166 | if (!p) | 5192 | &pcm_analog_playback, |
5167 | p = &pcm_analog_playback; | 5193 | spec->stream_analog_playback, |
5168 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; | 5194 | spec->multiout.dac_nids[0]); |
5169 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0]; | ||
5170 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = | 5195 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = |
5171 | spec->multiout.max_channels; | 5196 | spec->multiout.max_channels; |
5172 | if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT && | 5197 | if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT && |
@@ -5175,15 +5200,11 @@ int snd_hda_gen_build_pcms(struct hda_codec *codec) | |||
5175 | snd_pcm_2_1_chmaps; | 5200 | snd_pcm_2_1_chmaps; |
5176 | } | 5201 | } |
5177 | if (spec->num_adc_nids) { | 5202 | if (spec->num_adc_nids) { |
5178 | p = spec->stream_analog_capture; | 5203 | setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE], |
5179 | if (!p) { | 5204 | (spec->dyn_adc_switch ? |
5180 | if (spec->dyn_adc_switch) | 5205 | &dyn_adc_pcm_analog_capture : &pcm_analog_capture), |
5181 | p = &dyn_adc_pcm_analog_capture; | 5206 | spec->stream_analog_capture, |
5182 | else | 5207 | spec->adc_nids[0]); |
5183 | p = &pcm_analog_capture; | ||
5184 | } | ||
5185 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; | ||
5186 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; | ||
5187 | } | 5208 | } |
5188 | 5209 | ||
5189 | skip_analog: | 5210 | skip_analog: |
@@ -5202,20 +5223,16 @@ int snd_hda_gen_build_pcms(struct hda_codec *codec) | |||
5202 | info->pcm_type = spec->dig_out_type; | 5223 | info->pcm_type = spec->dig_out_type; |
5203 | else | 5224 | else |
5204 | info->pcm_type = HDA_PCM_TYPE_SPDIF; | 5225 | info->pcm_type = HDA_PCM_TYPE_SPDIF; |
5205 | if (spec->multiout.dig_out_nid) { | 5226 | if (spec->multiout.dig_out_nid) |
5206 | p = spec->stream_digital_playback; | 5227 | setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK], |
5207 | if (!p) | 5228 | &pcm_digital_playback, |
5208 | p = &pcm_digital_playback; | 5229 | spec->stream_digital_playback, |
5209 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; | 5230 | spec->multiout.dig_out_nid); |
5210 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; | 5231 | if (spec->dig_in_nid) |
5211 | } | 5232 | setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE], |
5212 | if (spec->dig_in_nid) { | 5233 | &pcm_digital_capture, |
5213 | p = spec->stream_digital_capture; | 5234 | spec->stream_digital_capture, |
5214 | if (!p) | 5235 | spec->dig_in_nid); |
5215 | p = &pcm_digital_capture; | ||
5216 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; | ||
5217 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid; | ||
5218 | } | ||
5219 | } | 5236 | } |
5220 | 5237 | ||
5221 | if (spec->no_analog) | 5238 | if (spec->no_analog) |
@@ -5236,31 +5253,24 @@ int snd_hda_gen_build_pcms(struct hda_codec *codec) | |||
5236 | if (!info) | 5253 | if (!info) |
5237 | return -ENOMEM; | 5254 | return -ENOMEM; |
5238 | spec->pcm_rec[2] = info; | 5255 | spec->pcm_rec[2] = info; |
5239 | if (spec->alt_dac_nid) { | 5256 | if (spec->alt_dac_nid) |
5240 | p = spec->stream_analog_alt_playback; | 5257 | setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK], |
5241 | if (!p) | 5258 | &pcm_analog_alt_playback, |
5242 | p = &pcm_analog_alt_playback; | 5259 | spec->stream_analog_alt_playback, |
5243 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; | 5260 | spec->alt_dac_nid); |
5244 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = | 5261 | else |
5245 | spec->alt_dac_nid; | 5262 | setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK], |
5246 | } else { | 5263 | &pcm_null_stream, NULL, 0); |
5247 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = | ||
5248 | pcm_null_stream; | ||
5249 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0; | ||
5250 | } | ||
5251 | if (have_multi_adcs) { | 5264 | if (have_multi_adcs) { |
5252 | p = spec->stream_analog_alt_capture; | 5265 | setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE], |
5253 | if (!p) | 5266 | &pcm_analog_alt_capture, |
5254 | p = &pcm_analog_alt_capture; | 5267 | spec->stream_analog_alt_capture, |
5255 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; | 5268 | spec->adc_nids[1]); |
5256 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = | ||
5257 | spec->adc_nids[1]; | ||
5258 | info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = | 5269 | info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = |
5259 | spec->num_adc_nids - 1; | 5270 | spec->num_adc_nids - 1; |
5260 | } else { | 5271 | } else { |
5261 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = | 5272 | setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE], |
5262 | pcm_null_stream; | 5273 | &pcm_null_stream, NULL, 0); |
5263 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0; | ||
5264 | } | 5274 | } |
5265 | } | 5275 | } |
5266 | 5276 | ||
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c index 2a61bda8115d..124eacf67fc4 100644 --- a/sound/pci/hda/patch_realtek.c +++ b/sound/pci/hda/patch_realtek.c | |||
@@ -2602,53 +2602,12 @@ static int patch_alc268(struct hda_codec *codec) | |||
2602 | * ALC269 | 2602 | * ALC269 |
2603 | */ | 2603 | */ |
2604 | 2604 | ||
2605 | static int playback_pcm_open(struct hda_pcm_stream *hinfo, | ||
2606 | struct hda_codec *codec, | ||
2607 | struct snd_pcm_substream *substream) | ||
2608 | { | ||
2609 | struct hda_gen_spec *spec = codec->spec; | ||
2610 | return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, | ||
2611 | hinfo); | ||
2612 | } | ||
2613 | |||
2614 | static int playback_pcm_prepare(struct hda_pcm_stream *hinfo, | ||
2615 | struct hda_codec *codec, | ||
2616 | unsigned int stream_tag, | ||
2617 | unsigned int format, | ||
2618 | struct snd_pcm_substream *substream) | ||
2619 | { | ||
2620 | struct hda_gen_spec *spec = codec->spec; | ||
2621 | return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, | ||
2622 | stream_tag, format, substream); | ||
2623 | } | ||
2624 | |||
2625 | static int playback_pcm_cleanup(struct hda_pcm_stream *hinfo, | ||
2626 | struct hda_codec *codec, | ||
2627 | struct snd_pcm_substream *substream) | ||
2628 | { | ||
2629 | struct hda_gen_spec *spec = codec->spec; | ||
2630 | return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); | ||
2631 | } | ||
2632 | |||
2633 | static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = { | 2605 | static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = { |
2634 | .substreams = 1, | ||
2635 | .channels_min = 2, | ||
2636 | .channels_max = 8, | ||
2637 | .rates = SNDRV_PCM_RATE_44100, /* fixed rate */ | 2606 | .rates = SNDRV_PCM_RATE_44100, /* fixed rate */ |
2638 | /* NID is set in alc_build_pcms */ | ||
2639 | .ops = { | ||
2640 | .open = playback_pcm_open, | ||
2641 | .prepare = playback_pcm_prepare, | ||
2642 | .cleanup = playback_pcm_cleanup | ||
2643 | }, | ||
2644 | }; | 2607 | }; |
2645 | 2608 | ||
2646 | static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = { | 2609 | static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = { |
2647 | .substreams = 1, | ||
2648 | .channels_min = 2, | ||
2649 | .channels_max = 2, | ||
2650 | .rates = SNDRV_PCM_RATE_44100, /* fixed rate */ | 2610 | .rates = SNDRV_PCM_RATE_44100, /* fixed rate */ |
2651 | /* NID is set in alc_build_pcms */ | ||
2652 | }; | 2611 | }; |
2653 | 2612 | ||
2654 | /* different alc269-variants */ | 2613 | /* different alc269-variants */ |