Skip to content

Commit 5ecc5dc

Browse files
adiknothtiwai
authored andcommitted
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>
1 parent 38ebb70 commit 5ecc5dc

File tree

1 file changed

+24
-76
lines changed

1 file changed

+24
-76
lines changed

sound/pci/rme9652/hdspm.c

Lines changed: 24 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -6043,23 +6043,30 @@ hdspm_hw_constraints_aes32_sample_rates = {
60436043
.mask = 0
60446044
};
60456045

6046-
static int snd_hdspm_playback_open(struct snd_pcm_substream *substream)
6046+
static int snd_hdspm_open(struct snd_pcm_substream *substream)
60476047
{
60486048
struct hdspm *hdspm = snd_pcm_substream_chip(substream);
60496049
struct snd_pcm_runtime *runtime = substream->runtime;
6050+
bool playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
60506051

60516052
spin_lock_irq(&hdspm->lock);
6052-
60536053
snd_pcm_set_sync(substream);
6054+
runtime->hw = (playback) ? snd_hdspm_playback_subinfo :
6055+
snd_hdspm_capture_subinfo;
60546056

6057+
if (playback) {
6058+
if (hdspm->capture_substream == NULL)
6059+
hdspm_stop_audio(hdspm);
60556060

6056-
runtime->hw = snd_hdspm_playback_subinfo;
6057-
6058-
if (hdspm->capture_substream == NULL)
6059-
hdspm_stop_audio(hdspm);
6061+
hdspm->playback_pid = current->pid;
6062+
hdspm->playback_substream = substream;
6063+
} else {
6064+
if (hdspm->playback_substream == NULL)
6065+
hdspm_stop_audio(hdspm);
60606066

6061-
hdspm->playback_pid = current->pid;
6062-
hdspm->playback_substream = substream;
6067+
hdspm->capture_pid = current->pid;
6068+
hdspm->capture_substream = substream;
6069+
}
60636070

60646071
spin_unlock_irq(&hdspm->lock);
60656072

@@ -6094,16 +6101,20 @@ static int snd_hdspm_playback_open(struct snd_pcm_substream *substream)
60946101
&hdspm_hw_constraints_aes32_sample_rates);
60956102
} else {
60966103
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,
60986107
SNDRV_PCM_HW_PARAM_CHANNELS, -1);
60996108
}
61006109

61016110
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,
61036113
SNDRV_PCM_HW_PARAM_CHANNELS, -1);
61046114

61056115
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,
61076118
SNDRV_PCM_HW_PARAM_RATE, -1);
61086119

61096120
return 0;
@@ -6123,69 +6134,6 @@ static int snd_hdspm_playback_release(struct snd_pcm_substream *substream)
61236134
return 0;
61246135
}
61256136

6126-
6127-
static 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-
61896137
static int snd_hdspm_capture_release(struct snd_pcm_substream *substream)
61906138
{
61916139
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,
64146362
}
64156363

64166364
static struct snd_pcm_ops snd_hdspm_playback_ops = {
6417-
.open = snd_hdspm_playback_open,
6365+
.open = snd_hdspm_open,
64186366
.close = snd_hdspm_playback_release,
64196367
.ioctl = snd_hdspm_ioctl,
64206368
.hw_params = snd_hdspm_hw_params,
@@ -6426,7 +6374,7 @@ static struct snd_pcm_ops snd_hdspm_playback_ops = {
64266374
};
64276375

64286376
static struct snd_pcm_ops snd_hdspm_capture_ops = {
6429-
.open = snd_hdspm_capture_open,
6377+
.open = snd_hdspm_open,
64306378
.close = snd_hdspm_capture_release,
64316379
.ioctl = snd_hdspm_ioctl,
64326380
.hw_params = snd_hdspm_hw_params,

0 commit comments

Comments
 (0)