aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci
diff options
context:
space:
mode:
authorAdrian Knoth <aknoth@google.com>2015-02-16 18:05:04 -0500
committerTakashi Iwai <tiwai@suse.de>2015-02-17 01:40:24 -0500
commit5ecc5dc720307d3fb0167e2b14f50e97dd9a2233 (patch)
tree4ed0af794f7d03d520f12a958ac6b830484bc647 /sound/pci
parent38ebb7034970efe5c7419267e499295e5893b565 (diff)
ALSA: hdspm - DRY cleanup in .open callbacks
This commit removes code duplication between snd_hdspm_{capture,playback}_open. No semantic changes intended, this is purely cosmetic. Signed-off-by: Adrian Knoth <aknoth@google.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/pci')
-rw-r--r--sound/pci/rme9652/hdspm.c100
1 files changed, 24 insertions, 76 deletions
diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c
index ca67f896d117..51e984170b3d 100644
--- a/sound/pci/rme9652/hdspm.c
+++ b/sound/pci/rme9652/hdspm.c
@@ -6043,23 +6043,30 @@ hdspm_hw_constraints_aes32_sample_rates = {
6043 .mask = 0 6043 .mask = 0
6044}; 6044};
6045 6045
6046static int snd_hdspm_playback_open(struct snd_pcm_substream *substream) 6046static int snd_hdspm_open(struct snd_pcm_substream *substream)
6047{ 6047{
6048 struct hdspm *hdspm = snd_pcm_substream_chip(substream); 6048 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
6049 struct snd_pcm_runtime *runtime = substream->runtime; 6049 struct snd_pcm_runtime *runtime = substream->runtime;
6050 bool playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
6050 6051
6051 spin_lock_irq(&hdspm->lock); 6052 spin_lock_irq(&hdspm->lock);
6052
6053 snd_pcm_set_sync(substream); 6053 snd_pcm_set_sync(substream);
6054 runtime->hw = (playback) ? snd_hdspm_playback_subinfo :
6055 snd_hdspm_capture_subinfo;
6054 6056
6057 if (playback) {
6058 if (hdspm->capture_substream == NULL)
6059 hdspm_stop_audio(hdspm);
6055 6060
6056 runtime->hw = snd_hdspm_playback_subinfo; 6061 hdspm->playback_pid = current->pid;
6057 6062 hdspm->playback_substream = substream;
6058 if (hdspm->capture_substream == NULL) 6063 } else {
6059 hdspm_stop_audio(hdspm); 6064 if (hdspm->playback_substream == NULL)
6065 hdspm_stop_audio(hdspm);
6060 6066
6061 hdspm->playback_pid = current->pid; 6067 hdspm->capture_pid = current->pid;
6062 hdspm->playback_substream = substream; 6068 hdspm->capture_substream = substream;
6069 }
6063 6070
6064 spin_unlock_irq(&hdspm->lock); 6071 spin_unlock_irq(&hdspm->lock);
6065 6072
@@ -6094,16 +6101,20 @@ static int snd_hdspm_playback_open(struct snd_pcm_substream *substream)
6094 &hdspm_hw_constraints_aes32_sample_rates); 6101 &hdspm_hw_constraints_aes32_sample_rates);
6095 } else { 6102 } else {
6096 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 6103 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
6097 snd_hdspm_hw_rule_rate_out_channels, hdspm, 6104 (playback ?
6105 snd_hdspm_hw_rule_rate_out_channels :
6106 snd_hdspm_hw_rule_rate_in_channels), hdspm,
6098 SNDRV_PCM_HW_PARAM_CHANNELS, -1); 6107 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
6099 } 6108 }
6100 6109
6101 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 6110 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
6102 snd_hdspm_hw_rule_out_channels, hdspm, 6111 (playback ? snd_hdspm_hw_rule_out_channels :
6112 snd_hdspm_hw_rule_in_channels), hdspm,
6103 SNDRV_PCM_HW_PARAM_CHANNELS, -1); 6113 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
6104 6114
6105 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 6115 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
6106 snd_hdspm_hw_rule_out_channels_rate, hdspm, 6116 (playback ? snd_hdspm_hw_rule_out_channels_rate :
6117 snd_hdspm_hw_rule_in_channels_rate), hdspm,
6107 SNDRV_PCM_HW_PARAM_RATE, -1); 6118 SNDRV_PCM_HW_PARAM_RATE, -1);
6108 6119
6109 return 0; 6120 return 0;
@@ -6123,69 +6134,6 @@ static int snd_hdspm_playback_release(struct snd_pcm_substream *substream)
6123 return 0; 6134 return 0;
6124} 6135}
6125 6136
6126
6127static int snd_hdspm_capture_open(struct snd_pcm_substream *substream)
6128{
6129 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
6130 struct snd_pcm_runtime *runtime = substream->runtime;
6131
6132 spin_lock_irq(&hdspm->lock);
6133 snd_pcm_set_sync(substream);
6134 runtime->hw = snd_hdspm_capture_subinfo;
6135
6136 if (hdspm->playback_substream == NULL)
6137 hdspm_stop_audio(hdspm);
6138
6139 hdspm->capture_pid = current->pid;
6140 hdspm->capture_substream = substream;
6141
6142 spin_unlock_irq(&hdspm->lock);
6143
6144 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
6145 snd_pcm_hw_constraint_pow2(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
6146
6147 switch (hdspm->io_type) {
6148 case AIO:
6149 case RayDAT:
6150 snd_pcm_hw_constraint_minmax(runtime,
6151 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
6152 32, 4096);
6153 snd_pcm_hw_constraint_minmax(runtime,
6154 SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
6155 16384, 16384);
6156 break;
6157
6158 default:
6159 snd_pcm_hw_constraint_minmax(runtime,
6160 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
6161 64, 8192);
6162 snd_pcm_hw_constraint_minmax(runtime,
6163 SNDRV_PCM_HW_PARAM_PERIODS,
6164 2, 2);
6165 break;
6166 }
6167
6168 if (AES32 == hdspm->io_type) {
6169 runtime->hw.rates |= SNDRV_PCM_RATE_KNOT;
6170 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
6171 &hdspm_hw_constraints_aes32_sample_rates);
6172 } else {
6173 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
6174 snd_hdspm_hw_rule_rate_in_channels, hdspm,
6175 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
6176 }
6177
6178 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
6179 snd_hdspm_hw_rule_in_channels, hdspm,
6180 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
6181
6182 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
6183 snd_hdspm_hw_rule_in_channels_rate, hdspm,
6184 SNDRV_PCM_HW_PARAM_RATE, -1);
6185
6186 return 0;
6187}
6188
6189static int snd_hdspm_capture_release(struct snd_pcm_substream *substream) 6137static int snd_hdspm_capture_release(struct snd_pcm_substream *substream)
6190{ 6138{
6191 struct hdspm *hdspm = snd_pcm_substream_chip(substream); 6139 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
@@ -6414,7 +6362,7 @@ static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
6414} 6362}
6415 6363
6416static struct snd_pcm_ops snd_hdspm_playback_ops = { 6364static struct snd_pcm_ops snd_hdspm_playback_ops = {
6417 .open = snd_hdspm_playback_open, 6365 .open = snd_hdspm_open,
6418 .close = snd_hdspm_playback_release, 6366 .close = snd_hdspm_playback_release,
6419 .ioctl = snd_hdspm_ioctl, 6367 .ioctl = snd_hdspm_ioctl,
6420 .hw_params = snd_hdspm_hw_params, 6368 .hw_params = snd_hdspm_hw_params,
@@ -6426,7 +6374,7 @@ static struct snd_pcm_ops snd_hdspm_playback_ops = {
6426}; 6374};
6427 6375
6428static struct snd_pcm_ops snd_hdspm_capture_ops = { 6376static struct snd_pcm_ops snd_hdspm_capture_ops = {
6429 .open = snd_hdspm_capture_open, 6377 .open = snd_hdspm_open,
6430 .close = snd_hdspm_capture_release, 6378 .close = snd_hdspm_capture_release,
6431 .ioctl = snd_hdspm_ioctl, 6379 .ioctl = snd_hdspm_ioctl,
6432 .hw_params = snd_hdspm_hw_params, 6380 .hw_params = snd_hdspm_hw_params,