1da607e19SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2fbbebd2cSTakashi Sakamoto /*
3fbbebd2cSTakashi Sakamoto * bebob_pcm.c - a part of driver for BeBoB based devices
4fbbebd2cSTakashi Sakamoto *
5fbbebd2cSTakashi Sakamoto * Copyright (c) 2013-2014 Takashi Sakamoto
6fbbebd2cSTakashi Sakamoto */
7fbbebd2cSTakashi Sakamoto
8fbbebd2cSTakashi Sakamoto #include "./bebob.h"
9fbbebd2cSTakashi Sakamoto
10fbbebd2cSTakashi Sakamoto static int
hw_rule_rate(struct snd_pcm_hw_params * params,struct snd_pcm_hw_rule * rule)11fbbebd2cSTakashi Sakamoto hw_rule_rate(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule)
12fbbebd2cSTakashi Sakamoto {
13fbbebd2cSTakashi Sakamoto struct snd_bebob_stream_formation *formations = rule->private;
14fbbebd2cSTakashi Sakamoto struct snd_interval *r =
15fbbebd2cSTakashi Sakamoto hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
16fbbebd2cSTakashi Sakamoto const struct snd_interval *c =
17fbbebd2cSTakashi Sakamoto hw_param_interval_c(params, SNDRV_PCM_HW_PARAM_CHANNELS);
18fbbebd2cSTakashi Sakamoto struct snd_interval t = {
19fbbebd2cSTakashi Sakamoto .min = UINT_MAX, .max = 0, .integer = 1
20fbbebd2cSTakashi Sakamoto };
21fbbebd2cSTakashi Sakamoto unsigned int i;
22fbbebd2cSTakashi Sakamoto
23fbbebd2cSTakashi Sakamoto for (i = 0; i < SND_BEBOB_STRM_FMT_ENTRIES; i++) {
24fbbebd2cSTakashi Sakamoto /* entry is invalid */
25fbbebd2cSTakashi Sakamoto if (formations[i].pcm == 0)
26fbbebd2cSTakashi Sakamoto continue;
27fbbebd2cSTakashi Sakamoto
28fbbebd2cSTakashi Sakamoto if (!snd_interval_test(c, formations[i].pcm))
29fbbebd2cSTakashi Sakamoto continue;
30fbbebd2cSTakashi Sakamoto
31fbbebd2cSTakashi Sakamoto t.min = min(t.min, snd_bebob_rate_table[i]);
32fbbebd2cSTakashi Sakamoto t.max = max(t.max, snd_bebob_rate_table[i]);
33fbbebd2cSTakashi Sakamoto
34fbbebd2cSTakashi Sakamoto }
35fbbebd2cSTakashi Sakamoto return snd_interval_refine(r, &t);
36fbbebd2cSTakashi Sakamoto }
37fbbebd2cSTakashi Sakamoto
38fbbebd2cSTakashi Sakamoto static int
hw_rule_channels(struct snd_pcm_hw_params * params,struct snd_pcm_hw_rule * rule)39fbbebd2cSTakashi Sakamoto hw_rule_channels(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule)
40fbbebd2cSTakashi Sakamoto {
41fbbebd2cSTakashi Sakamoto struct snd_bebob_stream_formation *formations = rule->private;
42fbbebd2cSTakashi Sakamoto struct snd_interval *c =
43fbbebd2cSTakashi Sakamoto hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
44fbbebd2cSTakashi Sakamoto const struct snd_interval *r =
45fbbebd2cSTakashi Sakamoto hw_param_interval_c(params, SNDRV_PCM_HW_PARAM_RATE);
46fbbebd2cSTakashi Sakamoto struct snd_interval t = {
47fbbebd2cSTakashi Sakamoto .min = UINT_MAX, .max = 0, .integer = 1
48fbbebd2cSTakashi Sakamoto };
49fbbebd2cSTakashi Sakamoto
50fbbebd2cSTakashi Sakamoto unsigned int i;
51fbbebd2cSTakashi Sakamoto
52fbbebd2cSTakashi Sakamoto for (i = 0; i < SND_BEBOB_STRM_FMT_ENTRIES; i++) {
53fbbebd2cSTakashi Sakamoto /* entry is invalid */
54fbbebd2cSTakashi Sakamoto if (formations[i].pcm == 0)
55fbbebd2cSTakashi Sakamoto continue;
56fbbebd2cSTakashi Sakamoto
57fbbebd2cSTakashi Sakamoto if (!snd_interval_test(r, snd_bebob_rate_table[i]))
58fbbebd2cSTakashi Sakamoto continue;
59fbbebd2cSTakashi Sakamoto
60fbbebd2cSTakashi Sakamoto t.min = min(t.min, formations[i].pcm);
61fbbebd2cSTakashi Sakamoto t.max = max(t.max, formations[i].pcm);
62fbbebd2cSTakashi Sakamoto }
63fbbebd2cSTakashi Sakamoto
64fbbebd2cSTakashi Sakamoto return snd_interval_refine(c, &t);
65fbbebd2cSTakashi Sakamoto }
66fbbebd2cSTakashi Sakamoto
67fbbebd2cSTakashi Sakamoto static void
limit_channels_and_rates(struct snd_pcm_hardware * hw,struct snd_bebob_stream_formation * formations)68fbbebd2cSTakashi Sakamoto limit_channels_and_rates(struct snd_pcm_hardware *hw,
69fbbebd2cSTakashi Sakamoto struct snd_bebob_stream_formation *formations)
70fbbebd2cSTakashi Sakamoto {
71fbbebd2cSTakashi Sakamoto unsigned int i;
72fbbebd2cSTakashi Sakamoto
73fbbebd2cSTakashi Sakamoto hw->channels_min = UINT_MAX;
74fbbebd2cSTakashi Sakamoto hw->channels_max = 0;
75fbbebd2cSTakashi Sakamoto
76fbbebd2cSTakashi Sakamoto hw->rate_min = UINT_MAX;
77fbbebd2cSTakashi Sakamoto hw->rate_max = 0;
78fbbebd2cSTakashi Sakamoto hw->rates = 0;
79fbbebd2cSTakashi Sakamoto
80fbbebd2cSTakashi Sakamoto for (i = 0; i < SND_BEBOB_STRM_FMT_ENTRIES; i++) {
81fbbebd2cSTakashi Sakamoto /* entry has no PCM channels */
82fbbebd2cSTakashi Sakamoto if (formations[i].pcm == 0)
83fbbebd2cSTakashi Sakamoto continue;
84fbbebd2cSTakashi Sakamoto
85fbbebd2cSTakashi Sakamoto hw->channels_min = min(hw->channels_min, formations[i].pcm);
86fbbebd2cSTakashi Sakamoto hw->channels_max = max(hw->channels_max, formations[i].pcm);
87fbbebd2cSTakashi Sakamoto
88fbbebd2cSTakashi Sakamoto hw->rate_min = min(hw->rate_min, snd_bebob_rate_table[i]);
89fbbebd2cSTakashi Sakamoto hw->rate_max = max(hw->rate_max, snd_bebob_rate_table[i]);
90fbbebd2cSTakashi Sakamoto hw->rates |= snd_pcm_rate_to_rate_bit(snd_bebob_rate_table[i]);
91fbbebd2cSTakashi Sakamoto }
92fbbebd2cSTakashi Sakamoto }
93fbbebd2cSTakashi Sakamoto
94fbbebd2cSTakashi Sakamoto static int
pcm_init_hw_params(struct snd_bebob * bebob,struct snd_pcm_substream * substream)95fbbebd2cSTakashi Sakamoto pcm_init_hw_params(struct snd_bebob *bebob,
96fbbebd2cSTakashi Sakamoto struct snd_pcm_substream *substream)
97fbbebd2cSTakashi Sakamoto {
98fbbebd2cSTakashi Sakamoto struct snd_pcm_runtime *runtime = substream->runtime;
99fbbebd2cSTakashi Sakamoto struct amdtp_stream *s;
100fbbebd2cSTakashi Sakamoto struct snd_bebob_stream_formation *formations;
101fbbebd2cSTakashi Sakamoto int err;
102fbbebd2cSTakashi Sakamoto
103fbbebd2cSTakashi Sakamoto if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
10449c7b3fcSTakashi Sakamoto runtime->hw.formats = AM824_IN_PCM_FORMAT_BITS;
105fbbebd2cSTakashi Sakamoto s = &bebob->tx_stream;
106fbbebd2cSTakashi Sakamoto formations = bebob->tx_stream_formations;
107fbbebd2cSTakashi Sakamoto } else {
10849c7b3fcSTakashi Sakamoto runtime->hw.formats = AM824_OUT_PCM_FORMAT_BITS;
109fbbebd2cSTakashi Sakamoto s = &bebob->rx_stream;
110fbbebd2cSTakashi Sakamoto formations = bebob->rx_stream_formations;
111fbbebd2cSTakashi Sakamoto }
112fbbebd2cSTakashi Sakamoto
113fbbebd2cSTakashi Sakamoto limit_channels_and_rates(&runtime->hw, formations);
114fbbebd2cSTakashi Sakamoto
115fbbebd2cSTakashi Sakamoto err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
116fbbebd2cSTakashi Sakamoto hw_rule_channels, formations,
117fbbebd2cSTakashi Sakamoto SNDRV_PCM_HW_PARAM_RATE, -1);
118fbbebd2cSTakashi Sakamoto if (err < 0)
119fbbebd2cSTakashi Sakamoto goto end;
120fbbebd2cSTakashi Sakamoto
121fbbebd2cSTakashi Sakamoto err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
122fbbebd2cSTakashi Sakamoto hw_rule_rate, formations,
123fbbebd2cSTakashi Sakamoto SNDRV_PCM_HW_PARAM_CHANNELS, -1);
124fbbebd2cSTakashi Sakamoto if (err < 0)
125fbbebd2cSTakashi Sakamoto goto end;
126fbbebd2cSTakashi Sakamoto
127bc8500daSTakashi Sakamoto err = amdtp_am824_add_pcm_hw_constraints(s, runtime);
128fbbebd2cSTakashi Sakamoto end:
129fbbebd2cSTakashi Sakamoto return err;
130fbbebd2cSTakashi Sakamoto }
131fbbebd2cSTakashi Sakamoto
pcm_open(struct snd_pcm_substream * substream)132a80b29a4STakashi Sakamoto static int pcm_open(struct snd_pcm_substream *substream)
133fbbebd2cSTakashi Sakamoto {
134fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = substream->private_data;
1356b9866c8SJulia Lawall const struct snd_bebob_rate_spec *spec = bebob->spec->rate;
136a80b29a4STakashi Sakamoto struct amdtp_domain *d = &bebob->domain;
1373e254b16STakashi Sakamoto enum snd_bebob_clock_type src;
138fbbebd2cSTakashi Sakamoto int err;
139fbbebd2cSTakashi Sakamoto
140618eabeaSTakashi Sakamoto err = snd_bebob_stream_lock_try(bebob);
141fbbebd2cSTakashi Sakamoto if (err < 0)
142a80b29a4STakashi Sakamoto return err;
143fbbebd2cSTakashi Sakamoto
144618eabeaSTakashi Sakamoto err = pcm_init_hw_params(bebob, substream);
145618eabeaSTakashi Sakamoto if (err < 0)
146618eabeaSTakashi Sakamoto goto err_locked;
147618eabeaSTakashi Sakamoto
1483e254b16STakashi Sakamoto err = snd_bebob_stream_get_clock_src(bebob, &src);
149fbbebd2cSTakashi Sakamoto if (err < 0)
150618eabeaSTakashi Sakamoto goto err_locked;
151fbbebd2cSTakashi Sakamoto
152a80b29a4STakashi Sakamoto mutex_lock(&bebob->mutex);
153a80b29a4STakashi Sakamoto
154a80b29a4STakashi Sakamoto // When source of clock is not internal or any stream is reserved for
155a80b29a4STakashi Sakamoto // transmission of PCM frames, the available sampling rate is limited
156a80b29a4STakashi Sakamoto // at current one.
1573e254b16STakashi Sakamoto if (src == SND_BEBOB_CLOCK_TYPE_EXTERNAL ||
158a80b29a4STakashi Sakamoto (bebob->substreams_counter > 0 && d->events_per_period > 0)) {
159a80b29a4STakashi Sakamoto unsigned int frames_per_period = d->events_per_period;
1601fde7a44STakashi Sakamoto unsigned int frames_per_buffer = d->events_per_buffer;
161a80b29a4STakashi Sakamoto unsigned int sampling_rate;
162a80b29a4STakashi Sakamoto
1631fc9522aSTakashi Sakamoto err = spec->get(bebob, &sampling_rate);
164fbbebd2cSTakashi Sakamoto if (err < 0) {
165a80b29a4STakashi Sakamoto mutex_unlock(&bebob->mutex);
166fbbebd2cSTakashi Sakamoto dev_err(&bebob->unit->device,
167fbbebd2cSTakashi Sakamoto "fail to get sampling rate: %d\n", err);
168618eabeaSTakashi Sakamoto goto err_locked;
169fbbebd2cSTakashi Sakamoto }
170fbbebd2cSTakashi Sakamoto
171fbbebd2cSTakashi Sakamoto substream->runtime->hw.rate_min = sampling_rate;
172fbbebd2cSTakashi Sakamoto substream->runtime->hw.rate_max = sampling_rate;
173a80b29a4STakashi Sakamoto
174a80b29a4STakashi Sakamoto if (frames_per_period > 0) {
175a80b29a4STakashi Sakamoto err = snd_pcm_hw_constraint_minmax(substream->runtime,
176a80b29a4STakashi Sakamoto SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
177a80b29a4STakashi Sakamoto frames_per_period, frames_per_period);
178a80b29a4STakashi Sakamoto if (err < 0) {
179a80b29a4STakashi Sakamoto mutex_unlock(&bebob->mutex);
180a80b29a4STakashi Sakamoto goto err_locked;
181a80b29a4STakashi Sakamoto }
1821fde7a44STakashi Sakamoto
1831fde7a44STakashi Sakamoto err = snd_pcm_hw_constraint_minmax(substream->runtime,
1841fde7a44STakashi Sakamoto SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
1851fde7a44STakashi Sakamoto frames_per_buffer, frames_per_buffer);
1861fde7a44STakashi Sakamoto if (err < 0) {
1871fde7a44STakashi Sakamoto mutex_unlock(&bebob->mutex);
1881fde7a44STakashi Sakamoto goto err_locked;
1891fde7a44STakashi Sakamoto }
190a80b29a4STakashi Sakamoto }
191fbbebd2cSTakashi Sakamoto }
192fbbebd2cSTakashi Sakamoto
193a80b29a4STakashi Sakamoto mutex_unlock(&bebob->mutex);
194a80b29a4STakashi Sakamoto
195fbbebd2cSTakashi Sakamoto snd_pcm_set_sync(substream);
196a80b29a4STakashi Sakamoto
197a80b29a4STakashi Sakamoto return 0;
198618eabeaSTakashi Sakamoto err_locked:
199618eabeaSTakashi Sakamoto snd_bebob_stream_lock_release(bebob);
200618eabeaSTakashi Sakamoto return err;
201fbbebd2cSTakashi Sakamoto }
202fbbebd2cSTakashi Sakamoto
203fbbebd2cSTakashi Sakamoto static int
pcm_close(struct snd_pcm_substream * substream)204fbbebd2cSTakashi Sakamoto pcm_close(struct snd_pcm_substream *substream)
205fbbebd2cSTakashi Sakamoto {
206618eabeaSTakashi Sakamoto struct snd_bebob *bebob = substream->private_data;
207618eabeaSTakashi Sakamoto snd_bebob_stream_lock_release(bebob);
208fbbebd2cSTakashi Sakamoto return 0;
209fbbebd2cSTakashi Sakamoto }
210fbbebd2cSTakashi Sakamoto
pcm_hw_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * hw_params)211f69fc179STakashi Sakamoto static int pcm_hw_params(struct snd_pcm_substream *substream,
212fbbebd2cSTakashi Sakamoto struct snd_pcm_hw_params *hw_params)
213fbbebd2cSTakashi Sakamoto {
214fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = substream->private_data;
2157641d549STakashi Iwai int err = 0;
216fbbebd2cSTakashi Sakamoto
21723cb0767STakashi Iwai if (substream->runtime->state == SNDRV_PCM_STATE_OPEN) {
218ac2888b9STakashi Sakamoto unsigned int rate = params_rate(hw_params);
2198737209fSTakashi Sakamoto unsigned int frames_per_period = params_period_size(hw_params);
2201fde7a44STakashi Sakamoto unsigned int frames_per_buffer = params_buffer_size(hw_params);
221ac2888b9STakashi Sakamoto
2222a71e701STakashi Sakamoto mutex_lock(&bebob->mutex);
2238737209fSTakashi Sakamoto err = snd_bebob_stream_reserve_duplex(bebob, rate,
2241fde7a44STakashi Sakamoto frames_per_period, frames_per_buffer);
225ac2888b9STakashi Sakamoto if (err >= 0)
226ac2888b9STakashi Sakamoto ++bebob->substreams_counter;
2272a71e701STakashi Sakamoto mutex_unlock(&bebob->mutex);
2282a71e701STakashi Sakamoto }
22985130cb4STakashi Sakamoto
230ac2888b9STakashi Sakamoto return err;
231fbbebd2cSTakashi Sakamoto }
232fbbebd2cSTakashi Sakamoto
pcm_hw_free(struct snd_pcm_substream * substream)233f69fc179STakashi Sakamoto static int pcm_hw_free(struct snd_pcm_substream *substream)
234fbbebd2cSTakashi Sakamoto {
235fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = substream->private_data;
236fbbebd2cSTakashi Sakamoto
2372a71e701STakashi Sakamoto mutex_lock(&bebob->mutex);
2385e818ac2STakashi Sakamoto
23923cb0767STakashi Iwai if (substream->runtime->state != SNDRV_PCM_STATE_OPEN)
2404fd6c6c7STakashi Sakamoto bebob->substreams_counter--;
241fbbebd2cSTakashi Sakamoto
242fbbebd2cSTakashi Sakamoto snd_bebob_stream_stop_duplex(bebob);
243fbbebd2cSTakashi Sakamoto
2445e818ac2STakashi Sakamoto mutex_unlock(&bebob->mutex);
2455e818ac2STakashi Sakamoto
2467641d549STakashi Iwai return 0;
247fbbebd2cSTakashi Sakamoto }
248fbbebd2cSTakashi Sakamoto
249fbbebd2cSTakashi Sakamoto static int
pcm_capture_prepare(struct snd_pcm_substream * substream)250fbbebd2cSTakashi Sakamoto pcm_capture_prepare(struct snd_pcm_substream *substream)
251fbbebd2cSTakashi Sakamoto {
252fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = substream->private_data;
253fbbebd2cSTakashi Sakamoto int err;
254fbbebd2cSTakashi Sakamoto
255ac2888b9STakashi Sakamoto err = snd_bebob_stream_start_duplex(bebob);
256fbbebd2cSTakashi Sakamoto if (err >= 0)
257fbbebd2cSTakashi Sakamoto amdtp_stream_pcm_prepare(&bebob->tx_stream);
258fbbebd2cSTakashi Sakamoto
259fbbebd2cSTakashi Sakamoto return err;
260fbbebd2cSTakashi Sakamoto }
261fbbebd2cSTakashi Sakamoto static int
pcm_playback_prepare(struct snd_pcm_substream * substream)262fbbebd2cSTakashi Sakamoto pcm_playback_prepare(struct snd_pcm_substream *substream)
263fbbebd2cSTakashi Sakamoto {
264fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = substream->private_data;
265fbbebd2cSTakashi Sakamoto int err;
266fbbebd2cSTakashi Sakamoto
267ac2888b9STakashi Sakamoto err = snd_bebob_stream_start_duplex(bebob);
268fbbebd2cSTakashi Sakamoto if (err >= 0)
269fbbebd2cSTakashi Sakamoto amdtp_stream_pcm_prepare(&bebob->rx_stream);
270fbbebd2cSTakashi Sakamoto
271fbbebd2cSTakashi Sakamoto return err;
272fbbebd2cSTakashi Sakamoto }
273fbbebd2cSTakashi Sakamoto
274fbbebd2cSTakashi Sakamoto static int
pcm_capture_trigger(struct snd_pcm_substream * substream,int cmd)275fbbebd2cSTakashi Sakamoto pcm_capture_trigger(struct snd_pcm_substream *substream, int cmd)
276fbbebd2cSTakashi Sakamoto {
277fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = substream->private_data;
278fbbebd2cSTakashi Sakamoto
279fbbebd2cSTakashi Sakamoto switch (cmd) {
280fbbebd2cSTakashi Sakamoto case SNDRV_PCM_TRIGGER_START:
281fbbebd2cSTakashi Sakamoto amdtp_stream_pcm_trigger(&bebob->tx_stream, substream);
282fbbebd2cSTakashi Sakamoto break;
283fbbebd2cSTakashi Sakamoto case SNDRV_PCM_TRIGGER_STOP:
284fbbebd2cSTakashi Sakamoto amdtp_stream_pcm_trigger(&bebob->tx_stream, NULL);
285fbbebd2cSTakashi Sakamoto break;
286fbbebd2cSTakashi Sakamoto default:
287fbbebd2cSTakashi Sakamoto return -EINVAL;
288fbbebd2cSTakashi Sakamoto }
289fbbebd2cSTakashi Sakamoto
290fbbebd2cSTakashi Sakamoto return 0;
291fbbebd2cSTakashi Sakamoto }
292fbbebd2cSTakashi Sakamoto static int
pcm_playback_trigger(struct snd_pcm_substream * substream,int cmd)293fbbebd2cSTakashi Sakamoto pcm_playback_trigger(struct snd_pcm_substream *substream, int cmd)
294fbbebd2cSTakashi Sakamoto {
295fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = substream->private_data;
296fbbebd2cSTakashi Sakamoto
297fbbebd2cSTakashi Sakamoto switch (cmd) {
298fbbebd2cSTakashi Sakamoto case SNDRV_PCM_TRIGGER_START:
299fbbebd2cSTakashi Sakamoto amdtp_stream_pcm_trigger(&bebob->rx_stream, substream);
300fbbebd2cSTakashi Sakamoto break;
301fbbebd2cSTakashi Sakamoto case SNDRV_PCM_TRIGGER_STOP:
302fbbebd2cSTakashi Sakamoto amdtp_stream_pcm_trigger(&bebob->rx_stream, NULL);
303fbbebd2cSTakashi Sakamoto break;
304fbbebd2cSTakashi Sakamoto default:
305fbbebd2cSTakashi Sakamoto return -EINVAL;
306fbbebd2cSTakashi Sakamoto }
307fbbebd2cSTakashi Sakamoto
308fbbebd2cSTakashi Sakamoto return 0;
309fbbebd2cSTakashi Sakamoto }
310fbbebd2cSTakashi Sakamoto
pcm_capture_pointer(struct snd_pcm_substream * sbstrm)311f890f9a0STakashi Sakamoto static snd_pcm_uframes_t pcm_capture_pointer(struct snd_pcm_substream *sbstrm)
312fbbebd2cSTakashi Sakamoto {
313fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = sbstrm->private_data;
314f890f9a0STakashi Sakamoto
315f890f9a0STakashi Sakamoto return amdtp_domain_stream_pcm_pointer(&bebob->domain,
316f890f9a0STakashi Sakamoto &bebob->tx_stream);
317fbbebd2cSTakashi Sakamoto }
pcm_playback_pointer(struct snd_pcm_substream * sbstrm)318f890f9a0STakashi Sakamoto static snd_pcm_uframes_t pcm_playback_pointer(struct snd_pcm_substream *sbstrm)
319fbbebd2cSTakashi Sakamoto {
320fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = sbstrm->private_data;
321f890f9a0STakashi Sakamoto
322f890f9a0STakashi Sakamoto return amdtp_domain_stream_pcm_pointer(&bebob->domain,
323f890f9a0STakashi Sakamoto &bebob->rx_stream);
324fbbebd2cSTakashi Sakamoto }
325fbbebd2cSTakashi Sakamoto
pcm_capture_ack(struct snd_pcm_substream * substream)326875becf8STakashi Sakamoto static int pcm_capture_ack(struct snd_pcm_substream *substream)
327875becf8STakashi Sakamoto {
328875becf8STakashi Sakamoto struct snd_bebob *bebob = substream->private_data;
329875becf8STakashi Sakamoto
330e6dcc92fSTakashi Sakamoto return amdtp_domain_stream_pcm_ack(&bebob->domain, &bebob->tx_stream);
331875becf8STakashi Sakamoto }
332875becf8STakashi Sakamoto
pcm_playback_ack(struct snd_pcm_substream * substream)333875becf8STakashi Sakamoto static int pcm_playback_ack(struct snd_pcm_substream *substream)
334875becf8STakashi Sakamoto {
335875becf8STakashi Sakamoto struct snd_bebob *bebob = substream->private_data;
336875becf8STakashi Sakamoto
337e6dcc92fSTakashi Sakamoto return amdtp_domain_stream_pcm_ack(&bebob->domain, &bebob->rx_stream);
338875becf8STakashi Sakamoto }
339875becf8STakashi Sakamoto
snd_bebob_create_pcm_devices(struct snd_bebob * bebob)3404780f774STakashi Sakamoto int snd_bebob_create_pcm_devices(struct snd_bebob *bebob)
3414780f774STakashi Sakamoto {
3424780f774STakashi Sakamoto static const struct snd_pcm_ops capture_ops = {
343fbbebd2cSTakashi Sakamoto .open = pcm_open,
344fbbebd2cSTakashi Sakamoto .close = pcm_close,
345f69fc179STakashi Sakamoto .hw_params = pcm_hw_params,
346f69fc179STakashi Sakamoto .hw_free = pcm_hw_free,
347fbbebd2cSTakashi Sakamoto .prepare = pcm_capture_prepare,
348fbbebd2cSTakashi Sakamoto .trigger = pcm_capture_trigger,
349fbbebd2cSTakashi Sakamoto .pointer = pcm_capture_pointer,
350875becf8STakashi Sakamoto .ack = pcm_capture_ack,
351fbbebd2cSTakashi Sakamoto };
3524780f774STakashi Sakamoto static const struct snd_pcm_ops playback_ops = {
353fbbebd2cSTakashi Sakamoto .open = pcm_open,
354fbbebd2cSTakashi Sakamoto .close = pcm_close,
355f69fc179STakashi Sakamoto .hw_params = pcm_hw_params,
356f69fc179STakashi Sakamoto .hw_free = pcm_hw_free,
357fbbebd2cSTakashi Sakamoto .prepare = pcm_playback_prepare,
358fbbebd2cSTakashi Sakamoto .trigger = pcm_playback_trigger,
359fbbebd2cSTakashi Sakamoto .pointer = pcm_playback_pointer,
360875becf8STakashi Sakamoto .ack = pcm_playback_ack,
361fbbebd2cSTakashi Sakamoto };
362fbbebd2cSTakashi Sakamoto struct snd_pcm *pcm;
363fbbebd2cSTakashi Sakamoto int err;
364fbbebd2cSTakashi Sakamoto
365fbbebd2cSTakashi Sakamoto err = snd_pcm_new(bebob->card, bebob->card->driver, 0, 1, 1, &pcm);
366fbbebd2cSTakashi Sakamoto if (err < 0)
367fbbebd2cSTakashi Sakamoto goto end;
368fbbebd2cSTakashi Sakamoto
369fbbebd2cSTakashi Sakamoto pcm->private_data = bebob;
370*5c49cc0eSTakashi Sakamoto pcm->nonatomic = true;
371fbbebd2cSTakashi Sakamoto snprintf(pcm->name, sizeof(pcm->name),
372fbbebd2cSTakashi Sakamoto "%s PCM", bebob->card->shortname);
3734780f774STakashi Sakamoto snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &playback_ops);
3744780f774STakashi Sakamoto snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &capture_ops);
3757641d549STakashi Iwai snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_VMALLOC, NULL, 0, 0);
376fbbebd2cSTakashi Sakamoto end:
377fbbebd2cSTakashi Sakamoto return err;
378fbbebd2cSTakashi Sakamoto }
379