1fbbebd2cSTakashi Sakamoto /* 2fbbebd2cSTakashi Sakamoto * bebob_pcm.c - a part of driver for BeBoB based devices 3fbbebd2cSTakashi Sakamoto * 4fbbebd2cSTakashi Sakamoto * Copyright (c) 2013-2014 Takashi Sakamoto 5fbbebd2cSTakashi Sakamoto * 6fbbebd2cSTakashi Sakamoto * Licensed under the terms of the GNU General Public License, version 2. 7fbbebd2cSTakashi Sakamoto */ 8fbbebd2cSTakashi Sakamoto 9fbbebd2cSTakashi Sakamoto #include "./bebob.h" 10fbbebd2cSTakashi Sakamoto 11fbbebd2cSTakashi Sakamoto static int 12fbbebd2cSTakashi Sakamoto hw_rule_rate(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) 13fbbebd2cSTakashi Sakamoto { 14fbbebd2cSTakashi Sakamoto struct snd_bebob_stream_formation *formations = rule->private; 15fbbebd2cSTakashi Sakamoto struct snd_interval *r = 16fbbebd2cSTakashi Sakamoto hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); 17fbbebd2cSTakashi Sakamoto const struct snd_interval *c = 18fbbebd2cSTakashi Sakamoto hw_param_interval_c(params, SNDRV_PCM_HW_PARAM_CHANNELS); 19fbbebd2cSTakashi Sakamoto struct snd_interval t = { 20fbbebd2cSTakashi Sakamoto .min = UINT_MAX, .max = 0, .integer = 1 21fbbebd2cSTakashi Sakamoto }; 22fbbebd2cSTakashi Sakamoto unsigned int i; 23fbbebd2cSTakashi Sakamoto 24fbbebd2cSTakashi Sakamoto for (i = 0; i < SND_BEBOB_STRM_FMT_ENTRIES; i++) { 25fbbebd2cSTakashi Sakamoto /* entry is invalid */ 26fbbebd2cSTakashi Sakamoto if (formations[i].pcm == 0) 27fbbebd2cSTakashi Sakamoto continue; 28fbbebd2cSTakashi Sakamoto 29fbbebd2cSTakashi Sakamoto if (!snd_interval_test(c, formations[i].pcm)) 30fbbebd2cSTakashi Sakamoto continue; 31fbbebd2cSTakashi Sakamoto 32fbbebd2cSTakashi Sakamoto t.min = min(t.min, snd_bebob_rate_table[i]); 33fbbebd2cSTakashi Sakamoto t.max = max(t.max, snd_bebob_rate_table[i]); 34fbbebd2cSTakashi Sakamoto 35fbbebd2cSTakashi Sakamoto } 36fbbebd2cSTakashi Sakamoto return snd_interval_refine(r, &t); 37fbbebd2cSTakashi Sakamoto } 38fbbebd2cSTakashi Sakamoto 39fbbebd2cSTakashi Sakamoto static int 40fbbebd2cSTakashi Sakamoto hw_rule_channels(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) 41fbbebd2cSTakashi Sakamoto { 42fbbebd2cSTakashi Sakamoto struct snd_bebob_stream_formation *formations = rule->private; 43fbbebd2cSTakashi Sakamoto struct snd_interval *c = 44fbbebd2cSTakashi Sakamoto hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); 45fbbebd2cSTakashi Sakamoto const struct snd_interval *r = 46fbbebd2cSTakashi Sakamoto hw_param_interval_c(params, SNDRV_PCM_HW_PARAM_RATE); 47fbbebd2cSTakashi Sakamoto struct snd_interval t = { 48fbbebd2cSTakashi Sakamoto .min = UINT_MAX, .max = 0, .integer = 1 49fbbebd2cSTakashi Sakamoto }; 50fbbebd2cSTakashi Sakamoto 51fbbebd2cSTakashi Sakamoto unsigned int i; 52fbbebd2cSTakashi Sakamoto 53fbbebd2cSTakashi Sakamoto for (i = 0; i < SND_BEBOB_STRM_FMT_ENTRIES; i++) { 54fbbebd2cSTakashi Sakamoto /* entry is invalid */ 55fbbebd2cSTakashi Sakamoto if (formations[i].pcm == 0) 56fbbebd2cSTakashi Sakamoto continue; 57fbbebd2cSTakashi Sakamoto 58fbbebd2cSTakashi Sakamoto if (!snd_interval_test(r, snd_bebob_rate_table[i])) 59fbbebd2cSTakashi Sakamoto continue; 60fbbebd2cSTakashi Sakamoto 61fbbebd2cSTakashi Sakamoto t.min = min(t.min, formations[i].pcm); 62fbbebd2cSTakashi Sakamoto t.max = max(t.max, formations[i].pcm); 63fbbebd2cSTakashi Sakamoto } 64fbbebd2cSTakashi Sakamoto 65fbbebd2cSTakashi Sakamoto return snd_interval_refine(c, &t); 66fbbebd2cSTakashi Sakamoto } 67fbbebd2cSTakashi Sakamoto 68fbbebd2cSTakashi Sakamoto static void 69fbbebd2cSTakashi Sakamoto limit_channels_and_rates(struct snd_pcm_hardware *hw, 70fbbebd2cSTakashi Sakamoto struct snd_bebob_stream_formation *formations) 71fbbebd2cSTakashi Sakamoto { 72fbbebd2cSTakashi Sakamoto unsigned int i; 73fbbebd2cSTakashi Sakamoto 74fbbebd2cSTakashi Sakamoto hw->channels_min = UINT_MAX; 75fbbebd2cSTakashi Sakamoto hw->channels_max = 0; 76fbbebd2cSTakashi Sakamoto 77fbbebd2cSTakashi Sakamoto hw->rate_min = UINT_MAX; 78fbbebd2cSTakashi Sakamoto hw->rate_max = 0; 79fbbebd2cSTakashi Sakamoto hw->rates = 0; 80fbbebd2cSTakashi Sakamoto 81fbbebd2cSTakashi Sakamoto for (i = 0; i < SND_BEBOB_STRM_FMT_ENTRIES; i++) { 82fbbebd2cSTakashi Sakamoto /* entry has no PCM channels */ 83fbbebd2cSTakashi Sakamoto if (formations[i].pcm == 0) 84fbbebd2cSTakashi Sakamoto continue; 85fbbebd2cSTakashi Sakamoto 86fbbebd2cSTakashi Sakamoto hw->channels_min = min(hw->channels_min, formations[i].pcm); 87fbbebd2cSTakashi Sakamoto hw->channels_max = max(hw->channels_max, formations[i].pcm); 88fbbebd2cSTakashi Sakamoto 89fbbebd2cSTakashi Sakamoto hw->rate_min = min(hw->rate_min, snd_bebob_rate_table[i]); 90fbbebd2cSTakashi Sakamoto hw->rate_max = max(hw->rate_max, snd_bebob_rate_table[i]); 91fbbebd2cSTakashi Sakamoto hw->rates |= snd_pcm_rate_to_rate_bit(snd_bebob_rate_table[i]); 92fbbebd2cSTakashi Sakamoto } 93fbbebd2cSTakashi Sakamoto } 94fbbebd2cSTakashi Sakamoto 95fbbebd2cSTakashi Sakamoto static void 96fbbebd2cSTakashi Sakamoto limit_period_and_buffer(struct snd_pcm_hardware *hw) 97fbbebd2cSTakashi Sakamoto { 98fbbebd2cSTakashi Sakamoto hw->periods_min = 2; /* SNDRV_PCM_INFO_BATCH */ 99fbbebd2cSTakashi Sakamoto hw->periods_max = UINT_MAX; 100fbbebd2cSTakashi Sakamoto 101fbbebd2cSTakashi Sakamoto hw->period_bytes_min = 4 * hw->channels_max; /* bytes for a frame */ 102fbbebd2cSTakashi Sakamoto 103fbbebd2cSTakashi Sakamoto /* Just to prevent from allocating much pages. */ 104fbbebd2cSTakashi Sakamoto hw->period_bytes_max = hw->period_bytes_min * 2048; 105fbbebd2cSTakashi Sakamoto hw->buffer_bytes_max = hw->period_bytes_max * hw->periods_min; 106fbbebd2cSTakashi Sakamoto } 107fbbebd2cSTakashi Sakamoto 108fbbebd2cSTakashi Sakamoto static int 109fbbebd2cSTakashi Sakamoto pcm_init_hw_params(struct snd_bebob *bebob, 110fbbebd2cSTakashi Sakamoto struct snd_pcm_substream *substream) 111fbbebd2cSTakashi Sakamoto { 112fbbebd2cSTakashi Sakamoto struct snd_pcm_runtime *runtime = substream->runtime; 113fbbebd2cSTakashi Sakamoto struct amdtp_stream *s; 114fbbebd2cSTakashi Sakamoto struct snd_bebob_stream_formation *formations; 115fbbebd2cSTakashi Sakamoto int err; 116fbbebd2cSTakashi Sakamoto 117fbbebd2cSTakashi Sakamoto runtime->hw.info = SNDRV_PCM_INFO_BATCH | 118fbbebd2cSTakashi Sakamoto SNDRV_PCM_INFO_BLOCK_TRANSFER | 119fbbebd2cSTakashi Sakamoto SNDRV_PCM_INFO_INTERLEAVED | 120fbbebd2cSTakashi Sakamoto SNDRV_PCM_INFO_JOINT_DUPLEX | 121fbbebd2cSTakashi Sakamoto SNDRV_PCM_INFO_MMAP | 122fbbebd2cSTakashi Sakamoto SNDRV_PCM_INFO_MMAP_VALID; 123fbbebd2cSTakashi Sakamoto 124fbbebd2cSTakashi Sakamoto if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { 12549c7b3fcSTakashi Sakamoto runtime->hw.formats = AM824_IN_PCM_FORMAT_BITS; 126fbbebd2cSTakashi Sakamoto s = &bebob->tx_stream; 127fbbebd2cSTakashi Sakamoto formations = bebob->tx_stream_formations; 128fbbebd2cSTakashi Sakamoto } else { 12949c7b3fcSTakashi Sakamoto runtime->hw.formats = AM824_OUT_PCM_FORMAT_BITS; 130fbbebd2cSTakashi Sakamoto s = &bebob->rx_stream; 131fbbebd2cSTakashi Sakamoto formations = bebob->rx_stream_formations; 132fbbebd2cSTakashi Sakamoto } 133fbbebd2cSTakashi Sakamoto 134fbbebd2cSTakashi Sakamoto limit_channels_and_rates(&runtime->hw, formations); 135fbbebd2cSTakashi Sakamoto limit_period_and_buffer(&runtime->hw); 136fbbebd2cSTakashi Sakamoto 137fbbebd2cSTakashi Sakamoto err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 138fbbebd2cSTakashi Sakamoto hw_rule_channels, formations, 139fbbebd2cSTakashi Sakamoto SNDRV_PCM_HW_PARAM_RATE, -1); 140fbbebd2cSTakashi Sakamoto if (err < 0) 141fbbebd2cSTakashi Sakamoto goto end; 142fbbebd2cSTakashi Sakamoto 143fbbebd2cSTakashi Sakamoto err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 144fbbebd2cSTakashi Sakamoto hw_rule_rate, formations, 145fbbebd2cSTakashi Sakamoto SNDRV_PCM_HW_PARAM_CHANNELS, -1); 146fbbebd2cSTakashi Sakamoto if (err < 0) 147fbbebd2cSTakashi Sakamoto goto end; 148fbbebd2cSTakashi Sakamoto 149bc8500daSTakashi Sakamoto err = amdtp_am824_add_pcm_hw_constraints(s, runtime); 150fbbebd2cSTakashi Sakamoto end: 151fbbebd2cSTakashi Sakamoto return err; 152fbbebd2cSTakashi Sakamoto } 153fbbebd2cSTakashi Sakamoto 154fbbebd2cSTakashi Sakamoto static int 155fbbebd2cSTakashi Sakamoto pcm_open(struct snd_pcm_substream *substream) 156fbbebd2cSTakashi Sakamoto { 157fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = substream->private_data; 1586b9866c8SJulia Lawall const struct snd_bebob_rate_spec *spec = bebob->spec->rate; 159fbbebd2cSTakashi Sakamoto unsigned int sampling_rate; 1603e254b16STakashi Sakamoto enum snd_bebob_clock_type src; 161fbbebd2cSTakashi Sakamoto int err; 162fbbebd2cSTakashi Sakamoto 163618eabeaSTakashi Sakamoto err = snd_bebob_stream_lock_try(bebob); 164fbbebd2cSTakashi Sakamoto if (err < 0) 165fbbebd2cSTakashi Sakamoto goto end; 166fbbebd2cSTakashi Sakamoto 167618eabeaSTakashi Sakamoto err = pcm_init_hw_params(bebob, substream); 168618eabeaSTakashi Sakamoto if (err < 0) 169618eabeaSTakashi Sakamoto goto err_locked; 170618eabeaSTakashi Sakamoto 1713e254b16STakashi Sakamoto err = snd_bebob_stream_get_clock_src(bebob, &src); 172fbbebd2cSTakashi Sakamoto if (err < 0) 173618eabeaSTakashi Sakamoto goto err_locked; 174fbbebd2cSTakashi Sakamoto 175fbbebd2cSTakashi Sakamoto /* 176fbbebd2cSTakashi Sakamoto * When source of clock is internal or any PCM stream are running, 177fbbebd2cSTakashi Sakamoto * the available sampling rate is limited at current sampling rate. 178fbbebd2cSTakashi Sakamoto */ 1793e254b16STakashi Sakamoto if (src == SND_BEBOB_CLOCK_TYPE_EXTERNAL || 180fbbebd2cSTakashi Sakamoto amdtp_stream_pcm_running(&bebob->tx_stream) || 181fbbebd2cSTakashi Sakamoto amdtp_stream_pcm_running(&bebob->rx_stream)) { 1821fc9522aSTakashi Sakamoto err = spec->get(bebob, &sampling_rate); 183fbbebd2cSTakashi Sakamoto if (err < 0) { 184fbbebd2cSTakashi Sakamoto dev_err(&bebob->unit->device, 185fbbebd2cSTakashi Sakamoto "fail to get sampling rate: %d\n", err); 186618eabeaSTakashi Sakamoto goto err_locked; 187fbbebd2cSTakashi Sakamoto } 188fbbebd2cSTakashi Sakamoto 189fbbebd2cSTakashi Sakamoto substream->runtime->hw.rate_min = sampling_rate; 190fbbebd2cSTakashi Sakamoto substream->runtime->hw.rate_max = sampling_rate; 191fbbebd2cSTakashi Sakamoto } 192fbbebd2cSTakashi Sakamoto 193fbbebd2cSTakashi Sakamoto snd_pcm_set_sync(substream); 194fbbebd2cSTakashi Sakamoto end: 195fbbebd2cSTakashi Sakamoto return err; 196618eabeaSTakashi Sakamoto err_locked: 197618eabeaSTakashi Sakamoto snd_bebob_stream_lock_release(bebob); 198618eabeaSTakashi Sakamoto return err; 199fbbebd2cSTakashi Sakamoto } 200fbbebd2cSTakashi Sakamoto 201fbbebd2cSTakashi Sakamoto static int 202fbbebd2cSTakashi Sakamoto pcm_close(struct snd_pcm_substream *substream) 203fbbebd2cSTakashi Sakamoto { 204618eabeaSTakashi Sakamoto struct snd_bebob *bebob = substream->private_data; 205618eabeaSTakashi Sakamoto snd_bebob_stream_lock_release(bebob); 206fbbebd2cSTakashi Sakamoto return 0; 207fbbebd2cSTakashi Sakamoto } 208fbbebd2cSTakashi Sakamoto 209fbbebd2cSTakashi Sakamoto static int 210fbbebd2cSTakashi Sakamoto pcm_capture_hw_params(struct snd_pcm_substream *substream, 211fbbebd2cSTakashi Sakamoto struct snd_pcm_hw_params *hw_params) 212fbbebd2cSTakashi Sakamoto { 213fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = substream->private_data; 21422c103cdSTakashi Sakamoto int err; 21522c103cdSTakashi Sakamoto 21622c103cdSTakashi Sakamoto err = snd_pcm_lib_alloc_vmalloc_buffer(substream, 21722c103cdSTakashi Sakamoto params_buffer_bytes(hw_params)); 21822c103cdSTakashi Sakamoto if (err < 0) 21922c103cdSTakashi Sakamoto return err; 220fbbebd2cSTakashi Sakamoto 221*2a71e701STakashi Sakamoto if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) { 222*2a71e701STakashi Sakamoto mutex_lock(&bebob->mutex); 2238d1c2694STakashi Sakamoto atomic_inc(&bebob->substreams_counter); 224*2a71e701STakashi Sakamoto mutex_unlock(&bebob->mutex); 225*2a71e701STakashi Sakamoto } 22685130cb4STakashi Sakamoto 22785130cb4STakashi Sakamoto amdtp_am824_set_pcm_format(&bebob->tx_stream, params_format(hw_params)); 22822c103cdSTakashi Sakamoto 22922c103cdSTakashi Sakamoto return 0; 230fbbebd2cSTakashi Sakamoto } 231fbbebd2cSTakashi Sakamoto static int 232fbbebd2cSTakashi Sakamoto pcm_playback_hw_params(struct snd_pcm_substream *substream, 233fbbebd2cSTakashi Sakamoto struct snd_pcm_hw_params *hw_params) 234fbbebd2cSTakashi Sakamoto { 235fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = substream->private_data; 23622c103cdSTakashi Sakamoto int err; 23722c103cdSTakashi Sakamoto 23822c103cdSTakashi Sakamoto err = snd_pcm_lib_alloc_vmalloc_buffer(substream, 23922c103cdSTakashi Sakamoto params_buffer_bytes(hw_params)); 24022c103cdSTakashi Sakamoto if (err < 0) 24122c103cdSTakashi Sakamoto return err; 242fbbebd2cSTakashi Sakamoto 243*2a71e701STakashi Sakamoto if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) { 244*2a71e701STakashi Sakamoto mutex_lock(&bebob->mutex); 2458d1c2694STakashi Sakamoto atomic_inc(&bebob->substreams_counter); 246*2a71e701STakashi Sakamoto mutex_unlock(&bebob->mutex); 247*2a71e701STakashi Sakamoto } 24885130cb4STakashi Sakamoto 24985130cb4STakashi Sakamoto amdtp_am824_set_pcm_format(&bebob->rx_stream, params_format(hw_params)); 25022c103cdSTakashi Sakamoto 25122c103cdSTakashi Sakamoto return 0; 252fbbebd2cSTakashi Sakamoto } 253fbbebd2cSTakashi Sakamoto 254fbbebd2cSTakashi Sakamoto static int 255fbbebd2cSTakashi Sakamoto pcm_capture_hw_free(struct snd_pcm_substream *substream) 256fbbebd2cSTakashi Sakamoto { 257fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = substream->private_data; 258fbbebd2cSTakashi Sakamoto 259*2a71e701STakashi Sakamoto if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN) { 260*2a71e701STakashi Sakamoto mutex_lock(&bebob->mutex); 2618d1c2694STakashi Sakamoto atomic_dec(&bebob->substreams_counter); 262*2a71e701STakashi Sakamoto mutex_unlock(&bebob->mutex); 263*2a71e701STakashi Sakamoto } 264fbbebd2cSTakashi Sakamoto 265fbbebd2cSTakashi Sakamoto snd_bebob_stream_stop_duplex(bebob); 266fbbebd2cSTakashi Sakamoto 267fbbebd2cSTakashi Sakamoto return snd_pcm_lib_free_vmalloc_buffer(substream); 268fbbebd2cSTakashi Sakamoto } 269fbbebd2cSTakashi Sakamoto static int 270fbbebd2cSTakashi Sakamoto pcm_playback_hw_free(struct snd_pcm_substream *substream) 271fbbebd2cSTakashi Sakamoto { 272fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = substream->private_data; 273fbbebd2cSTakashi Sakamoto 274*2a71e701STakashi Sakamoto if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN) { 275*2a71e701STakashi Sakamoto mutex_lock(&bebob->mutex); 2768d1c2694STakashi Sakamoto atomic_dec(&bebob->substreams_counter); 277*2a71e701STakashi Sakamoto mutex_unlock(&bebob->mutex); 278*2a71e701STakashi Sakamoto } 279fbbebd2cSTakashi Sakamoto 280fbbebd2cSTakashi Sakamoto snd_bebob_stream_stop_duplex(bebob); 281fbbebd2cSTakashi Sakamoto 282fbbebd2cSTakashi Sakamoto return snd_pcm_lib_free_vmalloc_buffer(substream); 283fbbebd2cSTakashi Sakamoto } 284fbbebd2cSTakashi Sakamoto 285fbbebd2cSTakashi Sakamoto static int 286fbbebd2cSTakashi Sakamoto pcm_capture_prepare(struct snd_pcm_substream *substream) 287fbbebd2cSTakashi Sakamoto { 288fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = substream->private_data; 289fbbebd2cSTakashi Sakamoto struct snd_pcm_runtime *runtime = substream->runtime; 290fbbebd2cSTakashi Sakamoto int err; 291fbbebd2cSTakashi Sakamoto 292fbbebd2cSTakashi Sakamoto err = snd_bebob_stream_start_duplex(bebob, runtime->rate); 293fbbebd2cSTakashi Sakamoto if (err >= 0) 294fbbebd2cSTakashi Sakamoto amdtp_stream_pcm_prepare(&bebob->tx_stream); 295fbbebd2cSTakashi Sakamoto 296fbbebd2cSTakashi Sakamoto return err; 297fbbebd2cSTakashi Sakamoto } 298fbbebd2cSTakashi Sakamoto static int 299fbbebd2cSTakashi Sakamoto pcm_playback_prepare(struct snd_pcm_substream *substream) 300fbbebd2cSTakashi Sakamoto { 301fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = substream->private_data; 302fbbebd2cSTakashi Sakamoto struct snd_pcm_runtime *runtime = substream->runtime; 303fbbebd2cSTakashi Sakamoto int err; 304fbbebd2cSTakashi Sakamoto 305fbbebd2cSTakashi Sakamoto err = snd_bebob_stream_start_duplex(bebob, runtime->rate); 306fbbebd2cSTakashi Sakamoto if (err >= 0) 307fbbebd2cSTakashi Sakamoto amdtp_stream_pcm_prepare(&bebob->rx_stream); 308fbbebd2cSTakashi Sakamoto 309fbbebd2cSTakashi Sakamoto return err; 310fbbebd2cSTakashi Sakamoto } 311fbbebd2cSTakashi Sakamoto 312fbbebd2cSTakashi Sakamoto static int 313fbbebd2cSTakashi Sakamoto pcm_capture_trigger(struct snd_pcm_substream *substream, int cmd) 314fbbebd2cSTakashi Sakamoto { 315fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = substream->private_data; 316fbbebd2cSTakashi Sakamoto 317fbbebd2cSTakashi Sakamoto switch (cmd) { 318fbbebd2cSTakashi Sakamoto case SNDRV_PCM_TRIGGER_START: 319fbbebd2cSTakashi Sakamoto amdtp_stream_pcm_trigger(&bebob->tx_stream, substream); 320fbbebd2cSTakashi Sakamoto break; 321fbbebd2cSTakashi Sakamoto case SNDRV_PCM_TRIGGER_STOP: 322fbbebd2cSTakashi Sakamoto amdtp_stream_pcm_trigger(&bebob->tx_stream, NULL); 323fbbebd2cSTakashi Sakamoto break; 324fbbebd2cSTakashi Sakamoto default: 325fbbebd2cSTakashi Sakamoto return -EINVAL; 326fbbebd2cSTakashi Sakamoto } 327fbbebd2cSTakashi Sakamoto 328fbbebd2cSTakashi Sakamoto return 0; 329fbbebd2cSTakashi Sakamoto } 330fbbebd2cSTakashi Sakamoto static int 331fbbebd2cSTakashi Sakamoto pcm_playback_trigger(struct snd_pcm_substream *substream, int cmd) 332fbbebd2cSTakashi Sakamoto { 333fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = substream->private_data; 334fbbebd2cSTakashi Sakamoto 335fbbebd2cSTakashi Sakamoto switch (cmd) { 336fbbebd2cSTakashi Sakamoto case SNDRV_PCM_TRIGGER_START: 337fbbebd2cSTakashi Sakamoto amdtp_stream_pcm_trigger(&bebob->rx_stream, substream); 338fbbebd2cSTakashi Sakamoto break; 339fbbebd2cSTakashi Sakamoto case SNDRV_PCM_TRIGGER_STOP: 340fbbebd2cSTakashi Sakamoto amdtp_stream_pcm_trigger(&bebob->rx_stream, NULL); 341fbbebd2cSTakashi Sakamoto break; 342fbbebd2cSTakashi Sakamoto default: 343fbbebd2cSTakashi Sakamoto return -EINVAL; 344fbbebd2cSTakashi Sakamoto } 345fbbebd2cSTakashi Sakamoto 346fbbebd2cSTakashi Sakamoto return 0; 347fbbebd2cSTakashi Sakamoto } 348fbbebd2cSTakashi Sakamoto 349fbbebd2cSTakashi Sakamoto static snd_pcm_uframes_t 350fbbebd2cSTakashi Sakamoto pcm_capture_pointer(struct snd_pcm_substream *sbstrm) 351fbbebd2cSTakashi Sakamoto { 352fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = sbstrm->private_data; 353fbbebd2cSTakashi Sakamoto return amdtp_stream_pcm_pointer(&bebob->tx_stream); 354fbbebd2cSTakashi Sakamoto } 355fbbebd2cSTakashi Sakamoto static snd_pcm_uframes_t 356fbbebd2cSTakashi Sakamoto pcm_playback_pointer(struct snd_pcm_substream *sbstrm) 357fbbebd2cSTakashi Sakamoto { 358fbbebd2cSTakashi Sakamoto struct snd_bebob *bebob = sbstrm->private_data; 359fbbebd2cSTakashi Sakamoto return amdtp_stream_pcm_pointer(&bebob->rx_stream); 360fbbebd2cSTakashi Sakamoto } 361fbbebd2cSTakashi Sakamoto 362fbbebd2cSTakashi Sakamoto static const struct snd_pcm_ops pcm_capture_ops = { 363fbbebd2cSTakashi Sakamoto .open = pcm_open, 364fbbebd2cSTakashi Sakamoto .close = pcm_close, 365fbbebd2cSTakashi Sakamoto .ioctl = snd_pcm_lib_ioctl, 366fbbebd2cSTakashi Sakamoto .hw_params = pcm_capture_hw_params, 367fbbebd2cSTakashi Sakamoto .hw_free = pcm_capture_hw_free, 368fbbebd2cSTakashi Sakamoto .prepare = pcm_capture_prepare, 369fbbebd2cSTakashi Sakamoto .trigger = pcm_capture_trigger, 370fbbebd2cSTakashi Sakamoto .pointer = pcm_capture_pointer, 371fbbebd2cSTakashi Sakamoto .page = snd_pcm_lib_get_vmalloc_page, 372fbbebd2cSTakashi Sakamoto }; 373fbbebd2cSTakashi Sakamoto static const struct snd_pcm_ops pcm_playback_ops = { 374fbbebd2cSTakashi Sakamoto .open = pcm_open, 375fbbebd2cSTakashi Sakamoto .close = pcm_close, 376fbbebd2cSTakashi Sakamoto .ioctl = snd_pcm_lib_ioctl, 377fbbebd2cSTakashi Sakamoto .hw_params = pcm_playback_hw_params, 378fbbebd2cSTakashi Sakamoto .hw_free = pcm_playback_hw_free, 379fbbebd2cSTakashi Sakamoto .prepare = pcm_playback_prepare, 380fbbebd2cSTakashi Sakamoto .trigger = pcm_playback_trigger, 381fbbebd2cSTakashi Sakamoto .pointer = pcm_playback_pointer, 382fbbebd2cSTakashi Sakamoto .page = snd_pcm_lib_get_vmalloc_page, 383fbbebd2cSTakashi Sakamoto .mmap = snd_pcm_lib_mmap_vmalloc, 384fbbebd2cSTakashi Sakamoto }; 385fbbebd2cSTakashi Sakamoto 386fbbebd2cSTakashi Sakamoto int snd_bebob_create_pcm_devices(struct snd_bebob *bebob) 387fbbebd2cSTakashi Sakamoto { 388fbbebd2cSTakashi Sakamoto struct snd_pcm *pcm; 389fbbebd2cSTakashi Sakamoto int err; 390fbbebd2cSTakashi Sakamoto 391fbbebd2cSTakashi Sakamoto err = snd_pcm_new(bebob->card, bebob->card->driver, 0, 1, 1, &pcm); 392fbbebd2cSTakashi Sakamoto if (err < 0) 393fbbebd2cSTakashi Sakamoto goto end; 394fbbebd2cSTakashi Sakamoto 395fbbebd2cSTakashi Sakamoto pcm->private_data = bebob; 396fbbebd2cSTakashi Sakamoto snprintf(pcm->name, sizeof(pcm->name), 397fbbebd2cSTakashi Sakamoto "%s PCM", bebob->card->shortname); 398fbbebd2cSTakashi Sakamoto snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &pcm_playback_ops); 399fbbebd2cSTakashi Sakamoto snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &pcm_capture_ops); 400fbbebd2cSTakashi Sakamoto end: 401fbbebd2cSTakashi Sakamoto return err; 402fbbebd2cSTakashi Sakamoto } 403