xref: /OK3568_Linux_fs/kernel/sound/firewire/motu/motu-pcm.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * motu-pcm.c - a part of driver for MOTU FireWire series
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (c) 2015-2017 Takashi Sakamoto <o-takashi@sakamocchi.jp>
6*4882a593Smuzhiyun  */
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun #include <sound/pcm_params.h>
9*4882a593Smuzhiyun #include "motu.h"
10*4882a593Smuzhiyun 
motu_rate_constraint(struct snd_pcm_hw_params * params,struct snd_pcm_hw_rule * rule)11*4882a593Smuzhiyun static int motu_rate_constraint(struct snd_pcm_hw_params *params,
12*4882a593Smuzhiyun 				struct snd_pcm_hw_rule *rule)
13*4882a593Smuzhiyun {
14*4882a593Smuzhiyun 	struct snd_motu_packet_format *formats = rule->private;
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun 	const struct snd_interval *c =
17*4882a593Smuzhiyun 		hw_param_interval_c(params, SNDRV_PCM_HW_PARAM_CHANNELS);
18*4882a593Smuzhiyun 	struct snd_interval *r =
19*4882a593Smuzhiyun 		hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
20*4882a593Smuzhiyun 	struct snd_interval rates = {
21*4882a593Smuzhiyun 		.min = UINT_MAX, .max = 0, .integer = 1
22*4882a593Smuzhiyun 	};
23*4882a593Smuzhiyun 	unsigned int i, pcm_channels, rate, mode;
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun 	for (i = 0; i < ARRAY_SIZE(snd_motu_clock_rates); ++i) {
26*4882a593Smuzhiyun 		rate = snd_motu_clock_rates[i];
27*4882a593Smuzhiyun 		mode = i / 2;
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun 		pcm_channels = formats->pcm_chunks[mode];
30*4882a593Smuzhiyun 		if (!snd_interval_test(c, pcm_channels))
31*4882a593Smuzhiyun 			continue;
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun 		rates.min = min(rates.min, rate);
34*4882a593Smuzhiyun 		rates.max = max(rates.max, rate);
35*4882a593Smuzhiyun 	}
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun 	return snd_interval_refine(r, &rates);
38*4882a593Smuzhiyun }
39*4882a593Smuzhiyun 
motu_channels_constraint(struct snd_pcm_hw_params * params,struct snd_pcm_hw_rule * rule)40*4882a593Smuzhiyun static int motu_channels_constraint(struct snd_pcm_hw_params *params,
41*4882a593Smuzhiyun 				    struct snd_pcm_hw_rule *rule)
42*4882a593Smuzhiyun {
43*4882a593Smuzhiyun 	struct snd_motu_packet_format *formats = rule->private;
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun 	const struct snd_interval *r =
46*4882a593Smuzhiyun 		hw_param_interval_c(params, SNDRV_PCM_HW_PARAM_RATE);
47*4882a593Smuzhiyun 	struct snd_interval *c =
48*4882a593Smuzhiyun 		hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
49*4882a593Smuzhiyun 	struct snd_interval channels = {
50*4882a593Smuzhiyun 		.min = UINT_MAX, .max = 0, .integer = 1
51*4882a593Smuzhiyun 	};
52*4882a593Smuzhiyun 	unsigned int i, pcm_channels, rate, mode;
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun 	for (i = 0; i < ARRAY_SIZE(snd_motu_clock_rates); ++i) {
55*4882a593Smuzhiyun 		rate = snd_motu_clock_rates[i];
56*4882a593Smuzhiyun 		mode = i / 2;
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun 		if (!snd_interval_test(r, rate))
59*4882a593Smuzhiyun 			continue;
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun 		pcm_channels = formats->pcm_chunks[mode];
62*4882a593Smuzhiyun 		channels.min = min(channels.min, pcm_channels);
63*4882a593Smuzhiyun 		channels.max = max(channels.max, pcm_channels);
64*4882a593Smuzhiyun 	}
65*4882a593Smuzhiyun 
66*4882a593Smuzhiyun 	return snd_interval_refine(c, &channels);
67*4882a593Smuzhiyun }
68*4882a593Smuzhiyun 
limit_channels_and_rates(struct snd_motu * motu,struct snd_pcm_runtime * runtime,struct snd_motu_packet_format * formats)69*4882a593Smuzhiyun static void limit_channels_and_rates(struct snd_motu *motu,
70*4882a593Smuzhiyun 				     struct snd_pcm_runtime *runtime,
71*4882a593Smuzhiyun 				     struct snd_motu_packet_format *formats)
72*4882a593Smuzhiyun {
73*4882a593Smuzhiyun 	struct snd_pcm_hardware *hw = &runtime->hw;
74*4882a593Smuzhiyun 	unsigned int i, pcm_channels, rate, mode;
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun 	hw->channels_min = UINT_MAX;
77*4882a593Smuzhiyun 	hw->channels_max = 0;
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun 	for (i = 0; i < ARRAY_SIZE(snd_motu_clock_rates); ++i) {
80*4882a593Smuzhiyun 		rate = snd_motu_clock_rates[i];
81*4882a593Smuzhiyun 		mode = i / 2;
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun 		pcm_channels = formats->pcm_chunks[mode];
84*4882a593Smuzhiyun 		if (pcm_channels == 0)
85*4882a593Smuzhiyun 			continue;
86*4882a593Smuzhiyun 
87*4882a593Smuzhiyun 		hw->rates |= snd_pcm_rate_to_rate_bit(rate);
88*4882a593Smuzhiyun 		hw->channels_min = min(hw->channels_min, pcm_channels);
89*4882a593Smuzhiyun 		hw->channels_max = max(hw->channels_max, pcm_channels);
90*4882a593Smuzhiyun 	}
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun 	snd_pcm_limit_hw_rates(runtime);
93*4882a593Smuzhiyun }
94*4882a593Smuzhiyun 
init_hw_info(struct snd_motu * motu,struct snd_pcm_substream * substream)95*4882a593Smuzhiyun static int init_hw_info(struct snd_motu *motu,
96*4882a593Smuzhiyun 			struct snd_pcm_substream *substream)
97*4882a593Smuzhiyun {
98*4882a593Smuzhiyun 	struct snd_pcm_runtime *runtime = substream->runtime;
99*4882a593Smuzhiyun 	struct snd_pcm_hardware *hw = &runtime->hw;
100*4882a593Smuzhiyun 	struct amdtp_stream *stream;
101*4882a593Smuzhiyun 	struct snd_motu_packet_format *formats;
102*4882a593Smuzhiyun 	int err;
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun 	if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
105*4882a593Smuzhiyun 		hw->formats = SNDRV_PCM_FMTBIT_S32;
106*4882a593Smuzhiyun 		stream = &motu->tx_stream;
107*4882a593Smuzhiyun 		formats = &motu->tx_packet_formats;
108*4882a593Smuzhiyun 	} else {
109*4882a593Smuzhiyun 		hw->formats = SNDRV_PCM_FMTBIT_S32;
110*4882a593Smuzhiyun 		stream = &motu->rx_stream;
111*4882a593Smuzhiyun 		formats = &motu->rx_packet_formats;
112*4882a593Smuzhiyun 	}
113*4882a593Smuzhiyun 
114*4882a593Smuzhiyun 	limit_channels_and_rates(motu, runtime, formats);
115*4882a593Smuzhiyun 
116*4882a593Smuzhiyun 	err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
117*4882a593Smuzhiyun 				  motu_rate_constraint, formats,
118*4882a593Smuzhiyun 				  SNDRV_PCM_HW_PARAM_CHANNELS, -1);
119*4882a593Smuzhiyun 	if (err < 0)
120*4882a593Smuzhiyun 		return err;
121*4882a593Smuzhiyun 	err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
122*4882a593Smuzhiyun 				  motu_channels_constraint, formats,
123*4882a593Smuzhiyun 				  SNDRV_PCM_HW_PARAM_RATE, -1);
124*4882a593Smuzhiyun 	if (err < 0)
125*4882a593Smuzhiyun 		return err;
126*4882a593Smuzhiyun 
127*4882a593Smuzhiyun 	return amdtp_motu_add_pcm_hw_constraints(stream, runtime);
128*4882a593Smuzhiyun }
129*4882a593Smuzhiyun 
pcm_open(struct snd_pcm_substream * substream)130*4882a593Smuzhiyun static int pcm_open(struct snd_pcm_substream *substream)
131*4882a593Smuzhiyun {
132*4882a593Smuzhiyun 	struct snd_motu *motu = substream->private_data;
133*4882a593Smuzhiyun 	struct amdtp_domain *d = &motu->domain;
134*4882a593Smuzhiyun 	enum snd_motu_clock_source src;
135*4882a593Smuzhiyun 	int err;
136*4882a593Smuzhiyun 
137*4882a593Smuzhiyun 	err = snd_motu_stream_lock_try(motu);
138*4882a593Smuzhiyun 	if (err < 0)
139*4882a593Smuzhiyun 		return err;
140*4882a593Smuzhiyun 
141*4882a593Smuzhiyun 	mutex_lock(&motu->mutex);
142*4882a593Smuzhiyun 
143*4882a593Smuzhiyun 	err = snd_motu_stream_cache_packet_formats(motu);
144*4882a593Smuzhiyun 	if (err < 0)
145*4882a593Smuzhiyun 		goto err_locked;
146*4882a593Smuzhiyun 
147*4882a593Smuzhiyun 	err = init_hw_info(motu, substream);
148*4882a593Smuzhiyun 	if (err < 0)
149*4882a593Smuzhiyun 		goto err_locked;
150*4882a593Smuzhiyun 
151*4882a593Smuzhiyun 	err = snd_motu_protocol_get_clock_source(motu, &src);
152*4882a593Smuzhiyun 	if (err < 0)
153*4882a593Smuzhiyun 		goto err_locked;
154*4882a593Smuzhiyun 
155*4882a593Smuzhiyun 	// When source of clock is not internal or any stream is reserved for
156*4882a593Smuzhiyun 	// transmission of PCM frames, the available sampling rate is limited
157*4882a593Smuzhiyun 	// at current one.
158*4882a593Smuzhiyun 	if ((src != SND_MOTU_CLOCK_SOURCE_INTERNAL &&
159*4882a593Smuzhiyun 	     src != SND_MOTU_CLOCK_SOURCE_SPH) ||
160*4882a593Smuzhiyun 	    (motu->substreams_counter > 0 && d->events_per_period > 0)) {
161*4882a593Smuzhiyun 		unsigned int frames_per_period = d->events_per_period;
162*4882a593Smuzhiyun 		unsigned int frames_per_buffer = d->events_per_buffer;
163*4882a593Smuzhiyun 		unsigned int rate;
164*4882a593Smuzhiyun 
165*4882a593Smuzhiyun 		err = snd_motu_protocol_get_clock_rate(motu, &rate);
166*4882a593Smuzhiyun 		if (err < 0)
167*4882a593Smuzhiyun 			goto err_locked;
168*4882a593Smuzhiyun 
169*4882a593Smuzhiyun 		substream->runtime->hw.rate_min = rate;
170*4882a593Smuzhiyun 		substream->runtime->hw.rate_max = rate;
171*4882a593Smuzhiyun 
172*4882a593Smuzhiyun 		if (frames_per_period > 0) {
173*4882a593Smuzhiyun 			err = snd_pcm_hw_constraint_minmax(substream->runtime,
174*4882a593Smuzhiyun 					SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
175*4882a593Smuzhiyun 					frames_per_period, frames_per_period);
176*4882a593Smuzhiyun 			if (err < 0)
177*4882a593Smuzhiyun 				goto err_locked;
178*4882a593Smuzhiyun 
179*4882a593Smuzhiyun 			err = snd_pcm_hw_constraint_minmax(substream->runtime,
180*4882a593Smuzhiyun 					SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
181*4882a593Smuzhiyun 					frames_per_buffer, frames_per_buffer);
182*4882a593Smuzhiyun 			if (err < 0)
183*4882a593Smuzhiyun 				goto err_locked;
184*4882a593Smuzhiyun 		}
185*4882a593Smuzhiyun 	}
186*4882a593Smuzhiyun 
187*4882a593Smuzhiyun 	snd_pcm_set_sync(substream);
188*4882a593Smuzhiyun 
189*4882a593Smuzhiyun 	mutex_unlock(&motu->mutex);
190*4882a593Smuzhiyun 
191*4882a593Smuzhiyun 	return 0;
192*4882a593Smuzhiyun err_locked:
193*4882a593Smuzhiyun 	mutex_unlock(&motu->mutex);
194*4882a593Smuzhiyun 	snd_motu_stream_lock_release(motu);
195*4882a593Smuzhiyun 	return err;
196*4882a593Smuzhiyun }
197*4882a593Smuzhiyun 
pcm_close(struct snd_pcm_substream * substream)198*4882a593Smuzhiyun static int pcm_close(struct snd_pcm_substream *substream)
199*4882a593Smuzhiyun {
200*4882a593Smuzhiyun 	struct snd_motu *motu = substream->private_data;
201*4882a593Smuzhiyun 
202*4882a593Smuzhiyun 	snd_motu_stream_lock_release(motu);
203*4882a593Smuzhiyun 
204*4882a593Smuzhiyun 	return 0;
205*4882a593Smuzhiyun }
206*4882a593Smuzhiyun 
pcm_hw_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * hw_params)207*4882a593Smuzhiyun static int pcm_hw_params(struct snd_pcm_substream *substream,
208*4882a593Smuzhiyun 			 struct snd_pcm_hw_params *hw_params)
209*4882a593Smuzhiyun {
210*4882a593Smuzhiyun 	struct snd_motu *motu = substream->private_data;
211*4882a593Smuzhiyun 	int err = 0;
212*4882a593Smuzhiyun 
213*4882a593Smuzhiyun 	if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) {
214*4882a593Smuzhiyun 		unsigned int rate = params_rate(hw_params);
215*4882a593Smuzhiyun 		unsigned int frames_per_period = params_period_size(hw_params);
216*4882a593Smuzhiyun 		unsigned int frames_per_buffer = params_buffer_size(hw_params);
217*4882a593Smuzhiyun 
218*4882a593Smuzhiyun 		mutex_lock(&motu->mutex);
219*4882a593Smuzhiyun 		err = snd_motu_stream_reserve_duplex(motu, rate,
220*4882a593Smuzhiyun 					frames_per_period, frames_per_buffer);
221*4882a593Smuzhiyun 		if (err >= 0)
222*4882a593Smuzhiyun 			++motu->substreams_counter;
223*4882a593Smuzhiyun 		mutex_unlock(&motu->mutex);
224*4882a593Smuzhiyun 	}
225*4882a593Smuzhiyun 
226*4882a593Smuzhiyun 	return err;
227*4882a593Smuzhiyun }
228*4882a593Smuzhiyun 
pcm_hw_free(struct snd_pcm_substream * substream)229*4882a593Smuzhiyun static int pcm_hw_free(struct snd_pcm_substream *substream)
230*4882a593Smuzhiyun {
231*4882a593Smuzhiyun 	struct snd_motu *motu = substream->private_data;
232*4882a593Smuzhiyun 
233*4882a593Smuzhiyun 	mutex_lock(&motu->mutex);
234*4882a593Smuzhiyun 
235*4882a593Smuzhiyun 	if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN)
236*4882a593Smuzhiyun 		--motu->substreams_counter;
237*4882a593Smuzhiyun 
238*4882a593Smuzhiyun 	snd_motu_stream_stop_duplex(motu);
239*4882a593Smuzhiyun 
240*4882a593Smuzhiyun 	mutex_unlock(&motu->mutex);
241*4882a593Smuzhiyun 
242*4882a593Smuzhiyun 	return 0;
243*4882a593Smuzhiyun }
244*4882a593Smuzhiyun 
capture_prepare(struct snd_pcm_substream * substream)245*4882a593Smuzhiyun static int capture_prepare(struct snd_pcm_substream *substream)
246*4882a593Smuzhiyun {
247*4882a593Smuzhiyun 	struct snd_motu *motu = substream->private_data;
248*4882a593Smuzhiyun 	int err;
249*4882a593Smuzhiyun 
250*4882a593Smuzhiyun 	mutex_lock(&motu->mutex);
251*4882a593Smuzhiyun 	err = snd_motu_stream_start_duplex(motu);
252*4882a593Smuzhiyun 	mutex_unlock(&motu->mutex);
253*4882a593Smuzhiyun 	if (err >= 0)
254*4882a593Smuzhiyun 		amdtp_stream_pcm_prepare(&motu->tx_stream);
255*4882a593Smuzhiyun 
256*4882a593Smuzhiyun 	return 0;
257*4882a593Smuzhiyun }
playback_prepare(struct snd_pcm_substream * substream)258*4882a593Smuzhiyun static int playback_prepare(struct snd_pcm_substream *substream)
259*4882a593Smuzhiyun {
260*4882a593Smuzhiyun 	struct snd_motu *motu = substream->private_data;
261*4882a593Smuzhiyun 	int err;
262*4882a593Smuzhiyun 
263*4882a593Smuzhiyun 	mutex_lock(&motu->mutex);
264*4882a593Smuzhiyun 	err = snd_motu_stream_start_duplex(motu);
265*4882a593Smuzhiyun 	mutex_unlock(&motu->mutex);
266*4882a593Smuzhiyun 	if (err >= 0)
267*4882a593Smuzhiyun 		amdtp_stream_pcm_prepare(&motu->rx_stream);
268*4882a593Smuzhiyun 
269*4882a593Smuzhiyun 	return err;
270*4882a593Smuzhiyun }
271*4882a593Smuzhiyun 
capture_trigger(struct snd_pcm_substream * substream,int cmd)272*4882a593Smuzhiyun static int capture_trigger(struct snd_pcm_substream *substream, int cmd)
273*4882a593Smuzhiyun {
274*4882a593Smuzhiyun 	struct snd_motu *motu = substream->private_data;
275*4882a593Smuzhiyun 
276*4882a593Smuzhiyun 	switch (cmd) {
277*4882a593Smuzhiyun 	case SNDRV_PCM_TRIGGER_START:
278*4882a593Smuzhiyun 		amdtp_stream_pcm_trigger(&motu->tx_stream, substream);
279*4882a593Smuzhiyun 		break;
280*4882a593Smuzhiyun 	case SNDRV_PCM_TRIGGER_STOP:
281*4882a593Smuzhiyun 		amdtp_stream_pcm_trigger(&motu->tx_stream, NULL);
282*4882a593Smuzhiyun 		break;
283*4882a593Smuzhiyun 	default:
284*4882a593Smuzhiyun 		return -EINVAL;
285*4882a593Smuzhiyun 	}
286*4882a593Smuzhiyun 
287*4882a593Smuzhiyun 	return 0;
288*4882a593Smuzhiyun }
playback_trigger(struct snd_pcm_substream * substream,int cmd)289*4882a593Smuzhiyun static int playback_trigger(struct snd_pcm_substream *substream, int cmd)
290*4882a593Smuzhiyun {
291*4882a593Smuzhiyun 	struct snd_motu *motu = substream->private_data;
292*4882a593Smuzhiyun 
293*4882a593Smuzhiyun 	switch (cmd) {
294*4882a593Smuzhiyun 	case SNDRV_PCM_TRIGGER_START:
295*4882a593Smuzhiyun 		amdtp_stream_pcm_trigger(&motu->rx_stream, substream);
296*4882a593Smuzhiyun 		break;
297*4882a593Smuzhiyun 	case SNDRV_PCM_TRIGGER_STOP:
298*4882a593Smuzhiyun 		amdtp_stream_pcm_trigger(&motu->rx_stream, NULL);
299*4882a593Smuzhiyun 		break;
300*4882a593Smuzhiyun 	default:
301*4882a593Smuzhiyun 		return -EINVAL;
302*4882a593Smuzhiyun 	}
303*4882a593Smuzhiyun 
304*4882a593Smuzhiyun 	return 0;
305*4882a593Smuzhiyun }
306*4882a593Smuzhiyun 
capture_pointer(struct snd_pcm_substream * substream)307*4882a593Smuzhiyun static snd_pcm_uframes_t capture_pointer(struct snd_pcm_substream *substream)
308*4882a593Smuzhiyun {
309*4882a593Smuzhiyun 	struct snd_motu *motu = substream->private_data;
310*4882a593Smuzhiyun 
311*4882a593Smuzhiyun 	return amdtp_domain_stream_pcm_pointer(&motu->domain, &motu->tx_stream);
312*4882a593Smuzhiyun }
playback_pointer(struct snd_pcm_substream * substream)313*4882a593Smuzhiyun static snd_pcm_uframes_t playback_pointer(struct snd_pcm_substream *substream)
314*4882a593Smuzhiyun {
315*4882a593Smuzhiyun 	struct snd_motu *motu = substream->private_data;
316*4882a593Smuzhiyun 
317*4882a593Smuzhiyun 	return amdtp_domain_stream_pcm_pointer(&motu->domain, &motu->rx_stream);
318*4882a593Smuzhiyun }
319*4882a593Smuzhiyun 
capture_ack(struct snd_pcm_substream * substream)320*4882a593Smuzhiyun static int capture_ack(struct snd_pcm_substream *substream)
321*4882a593Smuzhiyun {
322*4882a593Smuzhiyun 	struct snd_motu *motu = substream->private_data;
323*4882a593Smuzhiyun 
324*4882a593Smuzhiyun 	return amdtp_domain_stream_pcm_ack(&motu->domain, &motu->tx_stream);
325*4882a593Smuzhiyun }
326*4882a593Smuzhiyun 
playback_ack(struct snd_pcm_substream * substream)327*4882a593Smuzhiyun static int playback_ack(struct snd_pcm_substream *substream)
328*4882a593Smuzhiyun {
329*4882a593Smuzhiyun 	struct snd_motu *motu = substream->private_data;
330*4882a593Smuzhiyun 
331*4882a593Smuzhiyun 	return amdtp_domain_stream_pcm_ack(&motu->domain, &motu->rx_stream);
332*4882a593Smuzhiyun }
333*4882a593Smuzhiyun 
snd_motu_create_pcm_devices(struct snd_motu * motu)334*4882a593Smuzhiyun int snd_motu_create_pcm_devices(struct snd_motu *motu)
335*4882a593Smuzhiyun {
336*4882a593Smuzhiyun 	static const struct snd_pcm_ops capture_ops = {
337*4882a593Smuzhiyun 		.open      = pcm_open,
338*4882a593Smuzhiyun 		.close     = pcm_close,
339*4882a593Smuzhiyun 		.hw_params = pcm_hw_params,
340*4882a593Smuzhiyun 		.hw_free   = pcm_hw_free,
341*4882a593Smuzhiyun 		.prepare   = capture_prepare,
342*4882a593Smuzhiyun 		.trigger   = capture_trigger,
343*4882a593Smuzhiyun 		.pointer   = capture_pointer,
344*4882a593Smuzhiyun 		.ack       = capture_ack,
345*4882a593Smuzhiyun 	};
346*4882a593Smuzhiyun 	static const struct snd_pcm_ops playback_ops = {
347*4882a593Smuzhiyun 		.open      = pcm_open,
348*4882a593Smuzhiyun 		.close     = pcm_close,
349*4882a593Smuzhiyun 		.hw_params = pcm_hw_params,
350*4882a593Smuzhiyun 		.hw_free   = pcm_hw_free,
351*4882a593Smuzhiyun 		.prepare   = playback_prepare,
352*4882a593Smuzhiyun 		.trigger   = playback_trigger,
353*4882a593Smuzhiyun 		.pointer   = playback_pointer,
354*4882a593Smuzhiyun 		.ack       = playback_ack,
355*4882a593Smuzhiyun 	};
356*4882a593Smuzhiyun 	struct snd_pcm *pcm;
357*4882a593Smuzhiyun 	int err;
358*4882a593Smuzhiyun 
359*4882a593Smuzhiyun 	err = snd_pcm_new(motu->card, motu->card->driver, 0, 1, 1, &pcm);
360*4882a593Smuzhiyun 	if (err < 0)
361*4882a593Smuzhiyun 		return err;
362*4882a593Smuzhiyun 	pcm->private_data = motu;
363*4882a593Smuzhiyun 	strcpy(pcm->name, motu->card->shortname);
364*4882a593Smuzhiyun 
365*4882a593Smuzhiyun 	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &capture_ops);
366*4882a593Smuzhiyun 	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &playback_ops);
367*4882a593Smuzhiyun 	snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_VMALLOC, NULL, 0, 0);
368*4882a593Smuzhiyun 
369*4882a593Smuzhiyun 	return 0;
370*4882a593Smuzhiyun }
371