1*da607e19SThomas 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 132fbbebd2cSTakashi Sakamoto static int 133fbbebd2cSTakashi Sakamoto pcm_open(struct snd_pcm_substream *substream) 134fbbebd2cSTakashi Sakamoto { 135fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = substream->private_data; 1366b9866c8SJulia Lawall const struct snd_bebob_rate_spec *spec = bebob->spec->rate; 137fbbebd2cSTakashi Sakamoto unsigned int sampling_rate; 1383e254b16STakashi Sakamoto enum snd_bebob_clock_type src; 139fbbebd2cSTakashi Sakamoto int err; 140fbbebd2cSTakashi Sakamoto 141618eabeaSTakashi Sakamoto err = snd_bebob_stream_lock_try(bebob); 142fbbebd2cSTakashi Sakamoto if (err < 0) 143fbbebd2cSTakashi Sakamoto goto end; 144fbbebd2cSTakashi Sakamoto 145618eabeaSTakashi Sakamoto err = pcm_init_hw_params(bebob, substream); 146618eabeaSTakashi Sakamoto if (err < 0) 147618eabeaSTakashi Sakamoto goto err_locked; 148618eabeaSTakashi Sakamoto 1493e254b16STakashi Sakamoto err = snd_bebob_stream_get_clock_src(bebob, &src); 150fbbebd2cSTakashi Sakamoto if (err < 0) 151618eabeaSTakashi Sakamoto goto err_locked; 152fbbebd2cSTakashi Sakamoto 153fbbebd2cSTakashi Sakamoto /* 154fbbebd2cSTakashi Sakamoto * When source of clock is internal or any PCM stream are running, 155fbbebd2cSTakashi Sakamoto * the available sampling rate is limited at current sampling rate. 156fbbebd2cSTakashi Sakamoto */ 1573e254b16STakashi Sakamoto if (src == SND_BEBOB_CLOCK_TYPE_EXTERNAL || 158fbbebd2cSTakashi Sakamoto amdtp_stream_pcm_running(&bebob->tx_stream) || 159fbbebd2cSTakashi Sakamoto amdtp_stream_pcm_running(&bebob->rx_stream)) { 1601fc9522aSTakashi Sakamoto err = spec->get(bebob, &sampling_rate); 161fbbebd2cSTakashi Sakamoto if (err < 0) { 162fbbebd2cSTakashi Sakamoto dev_err(&bebob->unit->device, 163fbbebd2cSTakashi Sakamoto "fail to get sampling rate: %d\n", err); 164618eabeaSTakashi Sakamoto goto err_locked; 165fbbebd2cSTakashi Sakamoto } 166fbbebd2cSTakashi Sakamoto 167fbbebd2cSTakashi Sakamoto substream->runtime->hw.rate_min = sampling_rate; 168fbbebd2cSTakashi Sakamoto substream->runtime->hw.rate_max = sampling_rate; 169fbbebd2cSTakashi Sakamoto } 170fbbebd2cSTakashi Sakamoto 171fbbebd2cSTakashi Sakamoto snd_pcm_set_sync(substream); 172fbbebd2cSTakashi Sakamoto end: 173fbbebd2cSTakashi Sakamoto return err; 174618eabeaSTakashi Sakamoto err_locked: 175618eabeaSTakashi Sakamoto snd_bebob_stream_lock_release(bebob); 176618eabeaSTakashi Sakamoto return err; 177fbbebd2cSTakashi Sakamoto } 178fbbebd2cSTakashi Sakamoto 179fbbebd2cSTakashi Sakamoto static int 180fbbebd2cSTakashi Sakamoto pcm_close(struct snd_pcm_substream *substream) 181fbbebd2cSTakashi Sakamoto { 182618eabeaSTakashi Sakamoto struct snd_bebob *bebob = substream->private_data; 183618eabeaSTakashi Sakamoto snd_bebob_stream_lock_release(bebob); 184fbbebd2cSTakashi Sakamoto return 0; 185fbbebd2cSTakashi Sakamoto } 186fbbebd2cSTakashi Sakamoto 187fbbebd2cSTakashi Sakamoto static int 188fbbebd2cSTakashi Sakamoto pcm_capture_hw_params(struct snd_pcm_substream *substream, 189fbbebd2cSTakashi Sakamoto struct snd_pcm_hw_params *hw_params) 190fbbebd2cSTakashi Sakamoto { 191fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = substream->private_data; 19222c103cdSTakashi Sakamoto int err; 19322c103cdSTakashi Sakamoto 19422c103cdSTakashi Sakamoto err = snd_pcm_lib_alloc_vmalloc_buffer(substream, 19522c103cdSTakashi Sakamoto params_buffer_bytes(hw_params)); 19622c103cdSTakashi Sakamoto if (err < 0) 19722c103cdSTakashi Sakamoto return err; 198fbbebd2cSTakashi Sakamoto 1992a71e701STakashi Sakamoto if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) { 2002a71e701STakashi Sakamoto mutex_lock(&bebob->mutex); 2014fd6c6c7STakashi Sakamoto bebob->substreams_counter++; 2022a71e701STakashi Sakamoto mutex_unlock(&bebob->mutex); 2032a71e701STakashi Sakamoto } 20485130cb4STakashi Sakamoto 20522c103cdSTakashi Sakamoto return 0; 206fbbebd2cSTakashi Sakamoto } 207fbbebd2cSTakashi Sakamoto static int 208fbbebd2cSTakashi Sakamoto pcm_playback_hw_params(struct snd_pcm_substream *substream, 209fbbebd2cSTakashi Sakamoto struct snd_pcm_hw_params *hw_params) 210fbbebd2cSTakashi Sakamoto { 211fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = substream->private_data; 21222c103cdSTakashi Sakamoto int err; 21322c103cdSTakashi Sakamoto 21422c103cdSTakashi Sakamoto err = snd_pcm_lib_alloc_vmalloc_buffer(substream, 21522c103cdSTakashi Sakamoto params_buffer_bytes(hw_params)); 21622c103cdSTakashi Sakamoto if (err < 0) 21722c103cdSTakashi Sakamoto return err; 218fbbebd2cSTakashi Sakamoto 2192a71e701STakashi Sakamoto if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) { 2202a71e701STakashi Sakamoto mutex_lock(&bebob->mutex); 2214fd6c6c7STakashi Sakamoto bebob->substreams_counter++; 2222a71e701STakashi Sakamoto mutex_unlock(&bebob->mutex); 2232a71e701STakashi Sakamoto } 22485130cb4STakashi Sakamoto 22522c103cdSTakashi Sakamoto return 0; 226fbbebd2cSTakashi Sakamoto } 227fbbebd2cSTakashi Sakamoto 228fbbebd2cSTakashi Sakamoto static int 229fbbebd2cSTakashi Sakamoto pcm_capture_hw_free(struct snd_pcm_substream *substream) 230fbbebd2cSTakashi Sakamoto { 231fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = substream->private_data; 232fbbebd2cSTakashi Sakamoto 2332a71e701STakashi Sakamoto if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN) { 2342a71e701STakashi Sakamoto mutex_lock(&bebob->mutex); 2354fd6c6c7STakashi Sakamoto bebob->substreams_counter--; 2362a71e701STakashi Sakamoto mutex_unlock(&bebob->mutex); 2372a71e701STakashi Sakamoto } 238fbbebd2cSTakashi Sakamoto 239fbbebd2cSTakashi Sakamoto snd_bebob_stream_stop_duplex(bebob); 240fbbebd2cSTakashi Sakamoto 241fbbebd2cSTakashi Sakamoto return snd_pcm_lib_free_vmalloc_buffer(substream); 242fbbebd2cSTakashi Sakamoto } 243fbbebd2cSTakashi Sakamoto static int 244fbbebd2cSTakashi Sakamoto pcm_playback_hw_free(struct snd_pcm_substream *substream) 245fbbebd2cSTakashi Sakamoto { 246fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = substream->private_data; 247fbbebd2cSTakashi Sakamoto 2482a71e701STakashi Sakamoto if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN) { 2492a71e701STakashi Sakamoto mutex_lock(&bebob->mutex); 2504fd6c6c7STakashi Sakamoto bebob->substreams_counter--; 2512a71e701STakashi Sakamoto mutex_unlock(&bebob->mutex); 2522a71e701STakashi Sakamoto } 253fbbebd2cSTakashi Sakamoto 254fbbebd2cSTakashi Sakamoto snd_bebob_stream_stop_duplex(bebob); 255fbbebd2cSTakashi Sakamoto 256fbbebd2cSTakashi Sakamoto return snd_pcm_lib_free_vmalloc_buffer(substream); 257fbbebd2cSTakashi Sakamoto } 258fbbebd2cSTakashi Sakamoto 259fbbebd2cSTakashi Sakamoto static int 260fbbebd2cSTakashi Sakamoto pcm_capture_prepare(struct snd_pcm_substream *substream) 261fbbebd2cSTakashi Sakamoto { 262fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = substream->private_data; 263fbbebd2cSTakashi Sakamoto struct snd_pcm_runtime *runtime = substream->runtime; 264fbbebd2cSTakashi Sakamoto int err; 265fbbebd2cSTakashi Sakamoto 266fbbebd2cSTakashi Sakamoto err = snd_bebob_stream_start_duplex(bebob, runtime->rate); 267fbbebd2cSTakashi Sakamoto if (err >= 0) 268fbbebd2cSTakashi Sakamoto amdtp_stream_pcm_prepare(&bebob->tx_stream); 269fbbebd2cSTakashi Sakamoto 270fbbebd2cSTakashi Sakamoto return err; 271fbbebd2cSTakashi Sakamoto } 272fbbebd2cSTakashi Sakamoto static int 273fbbebd2cSTakashi Sakamoto pcm_playback_prepare(struct snd_pcm_substream *substream) 274fbbebd2cSTakashi Sakamoto { 275fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = substream->private_data; 276fbbebd2cSTakashi Sakamoto struct snd_pcm_runtime *runtime = substream->runtime; 277fbbebd2cSTakashi Sakamoto int err; 278fbbebd2cSTakashi Sakamoto 279fbbebd2cSTakashi Sakamoto err = snd_bebob_stream_start_duplex(bebob, runtime->rate); 280fbbebd2cSTakashi Sakamoto if (err >= 0) 281fbbebd2cSTakashi Sakamoto amdtp_stream_pcm_prepare(&bebob->rx_stream); 282fbbebd2cSTakashi Sakamoto 283fbbebd2cSTakashi Sakamoto return err; 284fbbebd2cSTakashi Sakamoto } 285fbbebd2cSTakashi Sakamoto 286fbbebd2cSTakashi Sakamoto static int 287fbbebd2cSTakashi Sakamoto pcm_capture_trigger(struct snd_pcm_substream *substream, int cmd) 288fbbebd2cSTakashi Sakamoto { 289fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = substream->private_data; 290fbbebd2cSTakashi Sakamoto 291fbbebd2cSTakashi Sakamoto switch (cmd) { 292fbbebd2cSTakashi Sakamoto case SNDRV_PCM_TRIGGER_START: 293fbbebd2cSTakashi Sakamoto amdtp_stream_pcm_trigger(&bebob->tx_stream, substream); 294fbbebd2cSTakashi Sakamoto break; 295fbbebd2cSTakashi Sakamoto case SNDRV_PCM_TRIGGER_STOP: 296fbbebd2cSTakashi Sakamoto amdtp_stream_pcm_trigger(&bebob->tx_stream, NULL); 297fbbebd2cSTakashi Sakamoto break; 298fbbebd2cSTakashi Sakamoto default: 299fbbebd2cSTakashi Sakamoto return -EINVAL; 300fbbebd2cSTakashi Sakamoto } 301fbbebd2cSTakashi Sakamoto 302fbbebd2cSTakashi Sakamoto return 0; 303fbbebd2cSTakashi Sakamoto } 304fbbebd2cSTakashi Sakamoto static int 305fbbebd2cSTakashi Sakamoto pcm_playback_trigger(struct snd_pcm_substream *substream, int cmd) 306fbbebd2cSTakashi Sakamoto { 307fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = substream->private_data; 308fbbebd2cSTakashi Sakamoto 309fbbebd2cSTakashi Sakamoto switch (cmd) { 310fbbebd2cSTakashi Sakamoto case SNDRV_PCM_TRIGGER_START: 311fbbebd2cSTakashi Sakamoto amdtp_stream_pcm_trigger(&bebob->rx_stream, substream); 312fbbebd2cSTakashi Sakamoto break; 313fbbebd2cSTakashi Sakamoto case SNDRV_PCM_TRIGGER_STOP: 314fbbebd2cSTakashi Sakamoto amdtp_stream_pcm_trigger(&bebob->rx_stream, NULL); 315fbbebd2cSTakashi Sakamoto break; 316fbbebd2cSTakashi Sakamoto default: 317fbbebd2cSTakashi Sakamoto return -EINVAL; 318fbbebd2cSTakashi Sakamoto } 319fbbebd2cSTakashi Sakamoto 320fbbebd2cSTakashi Sakamoto return 0; 321fbbebd2cSTakashi Sakamoto } 322fbbebd2cSTakashi Sakamoto 323fbbebd2cSTakashi Sakamoto static snd_pcm_uframes_t 324fbbebd2cSTakashi Sakamoto pcm_capture_pointer(struct snd_pcm_substream *sbstrm) 325fbbebd2cSTakashi Sakamoto { 326fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = sbstrm->private_data; 327fbbebd2cSTakashi Sakamoto return amdtp_stream_pcm_pointer(&bebob->tx_stream); 328fbbebd2cSTakashi Sakamoto } 329fbbebd2cSTakashi Sakamoto static snd_pcm_uframes_t 330fbbebd2cSTakashi Sakamoto pcm_playback_pointer(struct snd_pcm_substream *sbstrm) 331fbbebd2cSTakashi Sakamoto { 332fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = sbstrm->private_data; 333fbbebd2cSTakashi Sakamoto return amdtp_stream_pcm_pointer(&bebob->rx_stream); 334fbbebd2cSTakashi Sakamoto } 335fbbebd2cSTakashi Sakamoto 336875becf8STakashi Sakamoto static int pcm_capture_ack(struct snd_pcm_substream *substream) 337875becf8STakashi Sakamoto { 338875becf8STakashi Sakamoto struct snd_bebob *bebob = substream->private_data; 339875becf8STakashi Sakamoto 340875becf8STakashi Sakamoto return amdtp_stream_pcm_ack(&bebob->tx_stream); 341875becf8STakashi Sakamoto } 342875becf8STakashi Sakamoto 343875becf8STakashi Sakamoto static int pcm_playback_ack(struct snd_pcm_substream *substream) 344875becf8STakashi Sakamoto { 345875becf8STakashi Sakamoto struct snd_bebob *bebob = substream->private_data; 346875becf8STakashi Sakamoto 347875becf8STakashi Sakamoto return amdtp_stream_pcm_ack(&bebob->rx_stream); 348875becf8STakashi Sakamoto } 349875becf8STakashi Sakamoto 3504780f774STakashi Sakamoto int snd_bebob_create_pcm_devices(struct snd_bebob *bebob) 3514780f774STakashi Sakamoto { 3524780f774STakashi Sakamoto static const struct snd_pcm_ops capture_ops = { 353fbbebd2cSTakashi Sakamoto .open = pcm_open, 354fbbebd2cSTakashi Sakamoto .close = pcm_close, 355fbbebd2cSTakashi Sakamoto .ioctl = snd_pcm_lib_ioctl, 356fbbebd2cSTakashi Sakamoto .hw_params = pcm_capture_hw_params, 357fbbebd2cSTakashi Sakamoto .hw_free = pcm_capture_hw_free, 358fbbebd2cSTakashi Sakamoto .prepare = pcm_capture_prepare, 359fbbebd2cSTakashi Sakamoto .trigger = pcm_capture_trigger, 360fbbebd2cSTakashi Sakamoto .pointer = pcm_capture_pointer, 361875becf8STakashi Sakamoto .ack = pcm_capture_ack, 362fbbebd2cSTakashi Sakamoto .page = snd_pcm_lib_get_vmalloc_page, 363fbbebd2cSTakashi Sakamoto }; 3644780f774STakashi Sakamoto static const struct snd_pcm_ops playback_ops = { 365fbbebd2cSTakashi Sakamoto .open = pcm_open, 366fbbebd2cSTakashi Sakamoto .close = pcm_close, 367fbbebd2cSTakashi Sakamoto .ioctl = snd_pcm_lib_ioctl, 368fbbebd2cSTakashi Sakamoto .hw_params = pcm_playback_hw_params, 369fbbebd2cSTakashi Sakamoto .hw_free = pcm_playback_hw_free, 370fbbebd2cSTakashi Sakamoto .prepare = pcm_playback_prepare, 371fbbebd2cSTakashi Sakamoto .trigger = pcm_playback_trigger, 372fbbebd2cSTakashi Sakamoto .pointer = pcm_playback_pointer, 373875becf8STakashi Sakamoto .ack = pcm_playback_ack, 374fbbebd2cSTakashi Sakamoto .page = snd_pcm_lib_get_vmalloc_page, 375fbbebd2cSTakashi Sakamoto }; 376fbbebd2cSTakashi Sakamoto struct snd_pcm *pcm; 377fbbebd2cSTakashi Sakamoto int err; 378fbbebd2cSTakashi Sakamoto 379fbbebd2cSTakashi Sakamoto err = snd_pcm_new(bebob->card, bebob->card->driver, 0, 1, 1, &pcm); 380fbbebd2cSTakashi Sakamoto if (err < 0) 381fbbebd2cSTakashi Sakamoto goto end; 382fbbebd2cSTakashi Sakamoto 383fbbebd2cSTakashi Sakamoto pcm->private_data = bebob; 384fbbebd2cSTakashi Sakamoto snprintf(pcm->name, sizeof(pcm->name), 385fbbebd2cSTakashi Sakamoto "%s PCM", bebob->card->shortname); 3864780f774STakashi Sakamoto snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &playback_ops); 3874780f774STakashi Sakamoto snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &capture_ops); 388fbbebd2cSTakashi Sakamoto end: 389fbbebd2cSTakashi Sakamoto return err; 390fbbebd2cSTakashi Sakamoto } 391