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 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 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 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 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 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 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 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; 21522c103cdSTakashi Sakamoto int err; 21622c103cdSTakashi Sakamoto 21722c103cdSTakashi Sakamoto err = snd_pcm_lib_alloc_vmalloc_buffer(substream, 21822c103cdSTakashi Sakamoto params_buffer_bytes(hw_params)); 21922c103cdSTakashi Sakamoto if (err < 0) 22022c103cdSTakashi Sakamoto return err; 221fbbebd2cSTakashi Sakamoto 2222a71e701STakashi Sakamoto if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) { 223ac2888b9STakashi Sakamoto unsigned int rate = params_rate(hw_params); 2248737209fSTakashi Sakamoto unsigned int frames_per_period = params_period_size(hw_params); 2251fde7a44STakashi Sakamoto unsigned int frames_per_buffer = params_buffer_size(hw_params); 226ac2888b9STakashi Sakamoto 2272a71e701STakashi Sakamoto mutex_lock(&bebob->mutex); 2288737209fSTakashi Sakamoto err = snd_bebob_stream_reserve_duplex(bebob, rate, 2291fde7a44STakashi Sakamoto frames_per_period, frames_per_buffer); 230ac2888b9STakashi Sakamoto if (err >= 0) 231ac2888b9STakashi Sakamoto ++bebob->substreams_counter; 2322a71e701STakashi Sakamoto mutex_unlock(&bebob->mutex); 2332a71e701STakashi Sakamoto } 23485130cb4STakashi Sakamoto 235ac2888b9STakashi Sakamoto return err; 236fbbebd2cSTakashi Sakamoto } 237fbbebd2cSTakashi Sakamoto 238f69fc179STakashi Sakamoto static int pcm_hw_free(struct snd_pcm_substream *substream) 239fbbebd2cSTakashi Sakamoto { 240fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = substream->private_data; 241fbbebd2cSTakashi Sakamoto 2422a71e701STakashi Sakamoto mutex_lock(&bebob->mutex); 2435e818ac2STakashi Sakamoto 2445e818ac2STakashi Sakamoto if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN) 2454fd6c6c7STakashi Sakamoto bebob->substreams_counter--; 246fbbebd2cSTakashi Sakamoto 247fbbebd2cSTakashi Sakamoto snd_bebob_stream_stop_duplex(bebob); 248fbbebd2cSTakashi Sakamoto 2495e818ac2STakashi Sakamoto mutex_unlock(&bebob->mutex); 2505e818ac2STakashi Sakamoto 251fbbebd2cSTakashi Sakamoto return snd_pcm_lib_free_vmalloc_buffer(substream); 252fbbebd2cSTakashi Sakamoto } 253fbbebd2cSTakashi Sakamoto 254fbbebd2cSTakashi Sakamoto static int 255fbbebd2cSTakashi Sakamoto pcm_capture_prepare(struct snd_pcm_substream *substream) 256fbbebd2cSTakashi Sakamoto { 257fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = substream->private_data; 258fbbebd2cSTakashi Sakamoto int err; 259fbbebd2cSTakashi Sakamoto 260ac2888b9STakashi Sakamoto err = snd_bebob_stream_start_duplex(bebob); 261fbbebd2cSTakashi Sakamoto if (err >= 0) 262fbbebd2cSTakashi Sakamoto amdtp_stream_pcm_prepare(&bebob->tx_stream); 263fbbebd2cSTakashi Sakamoto 264fbbebd2cSTakashi Sakamoto return err; 265fbbebd2cSTakashi Sakamoto } 266fbbebd2cSTakashi Sakamoto static int 267fbbebd2cSTakashi Sakamoto pcm_playback_prepare(struct snd_pcm_substream *substream) 268fbbebd2cSTakashi Sakamoto { 269fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = substream->private_data; 270fbbebd2cSTakashi Sakamoto int err; 271fbbebd2cSTakashi Sakamoto 272ac2888b9STakashi Sakamoto err = snd_bebob_stream_start_duplex(bebob); 273fbbebd2cSTakashi Sakamoto if (err >= 0) 274fbbebd2cSTakashi Sakamoto amdtp_stream_pcm_prepare(&bebob->rx_stream); 275fbbebd2cSTakashi Sakamoto 276fbbebd2cSTakashi Sakamoto return err; 277fbbebd2cSTakashi Sakamoto } 278fbbebd2cSTakashi Sakamoto 279fbbebd2cSTakashi Sakamoto static int 280fbbebd2cSTakashi Sakamoto pcm_capture_trigger(struct snd_pcm_substream *substream, int cmd) 281fbbebd2cSTakashi Sakamoto { 282fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = substream->private_data; 283fbbebd2cSTakashi Sakamoto 284fbbebd2cSTakashi Sakamoto switch (cmd) { 285fbbebd2cSTakashi Sakamoto case SNDRV_PCM_TRIGGER_START: 286fbbebd2cSTakashi Sakamoto amdtp_stream_pcm_trigger(&bebob->tx_stream, substream); 287fbbebd2cSTakashi Sakamoto break; 288fbbebd2cSTakashi Sakamoto case SNDRV_PCM_TRIGGER_STOP: 289fbbebd2cSTakashi Sakamoto amdtp_stream_pcm_trigger(&bebob->tx_stream, NULL); 290fbbebd2cSTakashi Sakamoto break; 291fbbebd2cSTakashi Sakamoto default: 292fbbebd2cSTakashi Sakamoto return -EINVAL; 293fbbebd2cSTakashi Sakamoto } 294fbbebd2cSTakashi Sakamoto 295fbbebd2cSTakashi Sakamoto return 0; 296fbbebd2cSTakashi Sakamoto } 297fbbebd2cSTakashi Sakamoto static int 298fbbebd2cSTakashi Sakamoto pcm_playback_trigger(struct snd_pcm_substream *substream, int cmd) 299fbbebd2cSTakashi Sakamoto { 300fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = substream->private_data; 301fbbebd2cSTakashi Sakamoto 302fbbebd2cSTakashi Sakamoto switch (cmd) { 303fbbebd2cSTakashi Sakamoto case SNDRV_PCM_TRIGGER_START: 304fbbebd2cSTakashi Sakamoto amdtp_stream_pcm_trigger(&bebob->rx_stream, substream); 305fbbebd2cSTakashi Sakamoto break; 306fbbebd2cSTakashi Sakamoto case SNDRV_PCM_TRIGGER_STOP: 307fbbebd2cSTakashi Sakamoto amdtp_stream_pcm_trigger(&bebob->rx_stream, NULL); 308fbbebd2cSTakashi Sakamoto break; 309fbbebd2cSTakashi Sakamoto default: 310fbbebd2cSTakashi Sakamoto return -EINVAL; 311fbbebd2cSTakashi Sakamoto } 312fbbebd2cSTakashi Sakamoto 313fbbebd2cSTakashi Sakamoto return 0; 314fbbebd2cSTakashi Sakamoto } 315fbbebd2cSTakashi Sakamoto 316f890f9a0STakashi Sakamoto static snd_pcm_uframes_t pcm_capture_pointer(struct snd_pcm_substream *sbstrm) 317fbbebd2cSTakashi Sakamoto { 318fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = sbstrm->private_data; 319f890f9a0STakashi Sakamoto 320f890f9a0STakashi Sakamoto return amdtp_domain_stream_pcm_pointer(&bebob->domain, 321f890f9a0STakashi Sakamoto &bebob->tx_stream); 322fbbebd2cSTakashi Sakamoto } 323f890f9a0STakashi Sakamoto static snd_pcm_uframes_t pcm_playback_pointer(struct snd_pcm_substream *sbstrm) 324fbbebd2cSTakashi Sakamoto { 325fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = sbstrm->private_data; 326f890f9a0STakashi Sakamoto 327f890f9a0STakashi Sakamoto return amdtp_domain_stream_pcm_pointer(&bebob->domain, 328f890f9a0STakashi Sakamoto &bebob->rx_stream); 329fbbebd2cSTakashi Sakamoto } 330fbbebd2cSTakashi Sakamoto 331875becf8STakashi Sakamoto static int pcm_capture_ack(struct snd_pcm_substream *substream) 332875becf8STakashi Sakamoto { 333875becf8STakashi Sakamoto struct snd_bebob *bebob = substream->private_data; 334875becf8STakashi Sakamoto 335*e6dcc92fSTakashi Sakamoto return amdtp_domain_stream_pcm_ack(&bebob->domain, &bebob->tx_stream); 336875becf8STakashi Sakamoto } 337875becf8STakashi Sakamoto 338875becf8STakashi Sakamoto static int pcm_playback_ack(struct snd_pcm_substream *substream) 339875becf8STakashi Sakamoto { 340875becf8STakashi Sakamoto struct snd_bebob *bebob = substream->private_data; 341875becf8STakashi Sakamoto 342*e6dcc92fSTakashi Sakamoto return amdtp_domain_stream_pcm_ack(&bebob->domain, &bebob->rx_stream); 343875becf8STakashi Sakamoto } 344875becf8STakashi Sakamoto 3454780f774STakashi Sakamoto int snd_bebob_create_pcm_devices(struct snd_bebob *bebob) 3464780f774STakashi Sakamoto { 3474780f774STakashi Sakamoto static const struct snd_pcm_ops capture_ops = { 348fbbebd2cSTakashi Sakamoto .open = pcm_open, 349fbbebd2cSTakashi Sakamoto .close = pcm_close, 350fbbebd2cSTakashi Sakamoto .ioctl = snd_pcm_lib_ioctl, 351f69fc179STakashi Sakamoto .hw_params = pcm_hw_params, 352f69fc179STakashi Sakamoto .hw_free = pcm_hw_free, 353fbbebd2cSTakashi Sakamoto .prepare = pcm_capture_prepare, 354fbbebd2cSTakashi Sakamoto .trigger = pcm_capture_trigger, 355fbbebd2cSTakashi Sakamoto .pointer = pcm_capture_pointer, 356875becf8STakashi Sakamoto .ack = pcm_capture_ack, 357fbbebd2cSTakashi Sakamoto .page = snd_pcm_lib_get_vmalloc_page, 358fbbebd2cSTakashi Sakamoto }; 3594780f774STakashi Sakamoto static const struct snd_pcm_ops playback_ops = { 360fbbebd2cSTakashi Sakamoto .open = pcm_open, 361fbbebd2cSTakashi Sakamoto .close = pcm_close, 362fbbebd2cSTakashi Sakamoto .ioctl = snd_pcm_lib_ioctl, 363f69fc179STakashi Sakamoto .hw_params = pcm_hw_params, 364f69fc179STakashi Sakamoto .hw_free = pcm_hw_free, 365fbbebd2cSTakashi Sakamoto .prepare = pcm_playback_prepare, 366fbbebd2cSTakashi Sakamoto .trigger = pcm_playback_trigger, 367fbbebd2cSTakashi Sakamoto .pointer = pcm_playback_pointer, 368875becf8STakashi Sakamoto .ack = pcm_playback_ack, 369fbbebd2cSTakashi Sakamoto .page = snd_pcm_lib_get_vmalloc_page, 370fbbebd2cSTakashi Sakamoto }; 371fbbebd2cSTakashi Sakamoto struct snd_pcm *pcm; 372fbbebd2cSTakashi Sakamoto int err; 373fbbebd2cSTakashi Sakamoto 374fbbebd2cSTakashi Sakamoto err = snd_pcm_new(bebob->card, bebob->card->driver, 0, 1, 1, &pcm); 375fbbebd2cSTakashi Sakamoto if (err < 0) 376fbbebd2cSTakashi Sakamoto goto end; 377fbbebd2cSTakashi Sakamoto 378fbbebd2cSTakashi Sakamoto pcm->private_data = bebob; 379fbbebd2cSTakashi Sakamoto snprintf(pcm->name, sizeof(pcm->name), 380fbbebd2cSTakashi Sakamoto "%s PCM", bebob->card->shortname); 3814780f774STakashi Sakamoto snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &playback_ops); 3824780f774STakashi Sakamoto snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &capture_ops); 383fbbebd2cSTakashi Sakamoto end: 384fbbebd2cSTakashi Sakamoto return err; 385fbbebd2cSTakashi Sakamoto } 386