oxfw-pcm.c (1d6a722c4a0146ac20fd0daa541a177279adcbb2) oxfw-pcm.c (c0ede398b52654edb8b2a90be69dec2fb966f483)
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * oxfw_pcm.c - a part of driver for OXFW970/971 based devices
4 *
5 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
6 */
7
8#include "oxfw.h"

--- 156 unchanged lines hidden (view full) ---

165 substream->runtime->hw.rate_max = formation.rate;
166end:
167 return err;
168}
169
170static int pcm_open(struct snd_pcm_substream *substream)
171{
172 struct snd_oxfw *oxfw = substream->private_data;
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * oxfw_pcm.c - a part of driver for OXFW970/971 based devices
4 *
5 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
6 */
7
8#include "oxfw.h"

--- 156 unchanged lines hidden (view full) ---

165 substream->runtime->hw.rate_max = formation.rate;
166end:
167 return err;
168}
169
170static int pcm_open(struct snd_pcm_substream *substream)
171{
172 struct snd_oxfw *oxfw = substream->private_data;
173 struct amdtp_domain *d = &oxfw->domain;
173 int err;
174
175 err = snd_oxfw_stream_lock_try(oxfw);
176 if (err < 0)
174 int err;
175
176 err = snd_oxfw_stream_lock_try(oxfw);
177 if (err < 0)
177 goto end;
178 return err;
178
179 err = init_hw_params(oxfw, substream);
180 if (err < 0)
181 goto err_locked;
182
179
180 err = init_hw_params(oxfw, substream);
181 if (err < 0)
182 goto err_locked;
183
183 /*
184 * When any PCM streams are already running, the available sampling
185 * rate is limited at current value.
186 */
187 if (amdtp_stream_pcm_running(&oxfw->tx_stream) ||
188 amdtp_stream_pcm_running(&oxfw->rx_stream)) {
184 mutex_lock(&oxfw->mutex);
185
186 // When source of clock is not internal or any stream is reserved for
187 // transmission of PCM frames, the available sampling rate is limited
188 // at current one.
189 if (oxfw->substreams_count > 0 && d->events_per_period > 0) {
190 unsigned int frames_per_period = d->events_per_period;
191
189 err = limit_to_current_params(substream);
192 err = limit_to_current_params(substream);
190 if (err < 0)
191 goto end;
193 if (err < 0) {
194 mutex_unlock(&oxfw->mutex);
195 goto err_locked;
196 }
197
198 if (frames_per_period > 0) {
199 err = snd_pcm_hw_constraint_minmax(substream->runtime,
200 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
201 frames_per_period, frames_per_period);
202 if (err < 0) {
203 mutex_unlock(&oxfw->mutex);
204 goto err_locked;
205 }
206 }
192 }
193
207 }
208
209 mutex_unlock(&oxfw->mutex);
210
194 snd_pcm_set_sync(substream);
211 snd_pcm_set_sync(substream);
195end:
196 return err;
212
213 return 0;
197err_locked:
198 snd_oxfw_stream_lock_release(oxfw);
199 return err;
200}
201
202static int pcm_close(struct snd_pcm_substream *substream)
203{
204 struct snd_oxfw *oxfw = substream->private_data;

--- 229 unchanged lines hidden ---
214err_locked:
215 snd_oxfw_stream_lock_release(oxfw);
216 return err;
217}
218
219static int pcm_close(struct snd_pcm_substream *substream)
220{
221 struct snd_oxfw *oxfw = substream->private_data;

--- 229 unchanged lines hidden ---