1da607e19SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 23713d93aSTakashi Sakamoto /* 33713d93aSTakashi Sakamoto * oxfw_pcm.c - a part of driver for OXFW970/971 based devices 43713d93aSTakashi Sakamoto * 53713d93aSTakashi Sakamoto * Copyright (c) Clemens Ladisch <clemens@ladisch.de> 63713d93aSTakashi Sakamoto */ 73713d93aSTakashi Sakamoto 83713d93aSTakashi Sakamoto #include "oxfw.h" 93713d93aSTakashi Sakamoto 105cd1d3f4STakashi Sakamoto static int hw_rule_rate(struct snd_pcm_hw_params *params, 113713d93aSTakashi Sakamoto struct snd_pcm_hw_rule *rule) 123713d93aSTakashi Sakamoto { 135cd1d3f4STakashi Sakamoto u8 **formats = rule->private; 145cd1d3f4STakashi Sakamoto struct snd_interval *r = 153713d93aSTakashi Sakamoto hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); 165cd1d3f4STakashi Sakamoto const struct snd_interval *c = 175cd1d3f4STakashi Sakamoto hw_param_interval_c(params, SNDRV_PCM_HW_PARAM_CHANNELS); 185cd1d3f4STakashi Sakamoto struct snd_interval t = { 195cd1d3f4STakashi Sakamoto .min = UINT_MAX, .max = 0, .integer = 1 203713d93aSTakashi Sakamoto }; 215cd1d3f4STakashi Sakamoto struct snd_oxfw_stream_formation formation; 225580ba7bSDan Carpenter int i, err; 233713d93aSTakashi Sakamoto 245cd1d3f4STakashi Sakamoto for (i = 0; i < SND_OXFW_STREAM_FORMAT_ENTRIES; i++) { 255cd1d3f4STakashi Sakamoto if (formats[i] == NULL) 265cd1d3f4STakashi Sakamoto continue; 273713d93aSTakashi Sakamoto 285cd1d3f4STakashi Sakamoto err = snd_oxfw_stream_parse_format(formats[i], &formation); 293713d93aSTakashi Sakamoto if (err < 0) 305cd1d3f4STakashi Sakamoto continue; 315cd1d3f4STakashi Sakamoto if (!snd_interval_test(c, formation.pcm)) 325cd1d3f4STakashi Sakamoto continue; 333713d93aSTakashi Sakamoto 345cd1d3f4STakashi Sakamoto t.min = min(t.min, formation.rate); 355cd1d3f4STakashi Sakamoto t.max = max(t.max, formation.rate); 365cd1d3f4STakashi Sakamoto 375cd1d3f4STakashi Sakamoto } 385cd1d3f4STakashi Sakamoto return snd_interval_refine(r, &t); 393713d93aSTakashi Sakamoto } 403713d93aSTakashi Sakamoto 415cd1d3f4STakashi Sakamoto static int hw_rule_channels(struct snd_pcm_hw_params *params, 425cd1d3f4STakashi Sakamoto struct snd_pcm_hw_rule *rule) 433713d93aSTakashi Sakamoto { 445cd1d3f4STakashi Sakamoto u8 **formats = rule->private; 455cd1d3f4STakashi Sakamoto struct snd_interval *c = 465cd1d3f4STakashi Sakamoto hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); 475cd1d3f4STakashi Sakamoto const struct snd_interval *r = 485cd1d3f4STakashi Sakamoto hw_param_interval_c(params, SNDRV_PCM_HW_PARAM_RATE); 495cd1d3f4STakashi Sakamoto struct snd_oxfw_stream_formation formation; 505580ba7bSDan Carpenter int i, j, err; 515cd1d3f4STakashi Sakamoto unsigned int count, list[SND_OXFW_STREAM_FORMAT_ENTRIES] = {0}; 523713d93aSTakashi Sakamoto 535cd1d3f4STakashi Sakamoto count = 0; 545cd1d3f4STakashi Sakamoto for (i = 0; i < SND_OXFW_STREAM_FORMAT_ENTRIES; i++) { 555cd1d3f4STakashi Sakamoto if (formats[i] == NULL) 565cd1d3f4STakashi Sakamoto break; 575cd1d3f4STakashi Sakamoto 585cd1d3f4STakashi Sakamoto err = snd_oxfw_stream_parse_format(formats[i], &formation); 595cd1d3f4STakashi Sakamoto if (err < 0) 605cd1d3f4STakashi Sakamoto continue; 615cd1d3f4STakashi Sakamoto if (!snd_interval_test(r, formation.rate)) 625cd1d3f4STakashi Sakamoto continue; 635cd1d3f4STakashi Sakamoto if (list[count] == formation.pcm) 645cd1d3f4STakashi Sakamoto continue; 655cd1d3f4STakashi Sakamoto 665cd1d3f4STakashi Sakamoto for (j = 0; j < ARRAY_SIZE(list); j++) { 675cd1d3f4STakashi Sakamoto if (list[j] == formation.pcm) 685cd1d3f4STakashi Sakamoto break; 695cd1d3f4STakashi Sakamoto } 705cd1d3f4STakashi Sakamoto if (j == ARRAY_SIZE(list)) { 715cd1d3f4STakashi Sakamoto list[count] = formation.pcm; 725cd1d3f4STakashi Sakamoto if (++count == ARRAY_SIZE(list)) 735cd1d3f4STakashi Sakamoto break; 745cd1d3f4STakashi Sakamoto } 755cd1d3f4STakashi Sakamoto } 765cd1d3f4STakashi Sakamoto 775cd1d3f4STakashi Sakamoto return snd_interval_list(c, count, list, 0); 785cd1d3f4STakashi Sakamoto } 795cd1d3f4STakashi Sakamoto 805cd1d3f4STakashi Sakamoto static void limit_channels_and_rates(struct snd_pcm_hardware *hw, u8 **formats) 815cd1d3f4STakashi Sakamoto { 825cd1d3f4STakashi Sakamoto struct snd_oxfw_stream_formation formation; 835580ba7bSDan Carpenter int i, err; 845cd1d3f4STakashi Sakamoto 855cd1d3f4STakashi Sakamoto hw->channels_min = UINT_MAX; 865cd1d3f4STakashi Sakamoto hw->channels_max = 0; 875cd1d3f4STakashi Sakamoto 885cd1d3f4STakashi Sakamoto hw->rate_min = UINT_MAX; 895cd1d3f4STakashi Sakamoto hw->rate_max = 0; 905cd1d3f4STakashi Sakamoto hw->rates = 0; 915cd1d3f4STakashi Sakamoto 925cd1d3f4STakashi Sakamoto for (i = 0; i < SND_OXFW_STREAM_FORMAT_ENTRIES; i++) { 935cd1d3f4STakashi Sakamoto if (formats[i] == NULL) 945cd1d3f4STakashi Sakamoto break; 955cd1d3f4STakashi Sakamoto 965cd1d3f4STakashi Sakamoto err = snd_oxfw_stream_parse_format(formats[i], &formation); 975cd1d3f4STakashi Sakamoto if (err < 0) 985cd1d3f4STakashi Sakamoto continue; 995cd1d3f4STakashi Sakamoto 1005cd1d3f4STakashi Sakamoto hw->channels_min = min(hw->channels_min, formation.pcm); 1015cd1d3f4STakashi Sakamoto hw->channels_max = max(hw->channels_max, formation.pcm); 1025cd1d3f4STakashi Sakamoto 1035cd1d3f4STakashi Sakamoto hw->rate_min = min(hw->rate_min, formation.rate); 1045cd1d3f4STakashi Sakamoto hw->rate_max = max(hw->rate_max, formation.rate); 1055cd1d3f4STakashi Sakamoto hw->rates |= snd_pcm_rate_to_rate_bit(formation.rate); 1065cd1d3f4STakashi Sakamoto } 1075cd1d3f4STakashi Sakamoto } 1085cd1d3f4STakashi Sakamoto 109216e256fSTakashi Sakamoto static int init_hw_params(struct snd_oxfw *oxfw, 110216e256fSTakashi Sakamoto struct snd_pcm_substream *substream) 1113713d93aSTakashi Sakamoto { 1123713d93aSTakashi Sakamoto struct snd_pcm_runtime *runtime = substream->runtime; 1135cd1d3f4STakashi Sakamoto u8 **formats; 114216e256fSTakashi Sakamoto struct amdtp_stream *stream; 1153713d93aSTakashi Sakamoto int err; 1163713d93aSTakashi Sakamoto 117216e256fSTakashi Sakamoto if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { 11849c7b3fcSTakashi Sakamoto runtime->hw.formats = AM824_IN_PCM_FORMAT_BITS; 119216e256fSTakashi Sakamoto stream = &oxfw->tx_stream; 120216e256fSTakashi Sakamoto formats = oxfw->tx_stream_formats; 121216e256fSTakashi Sakamoto } else { 12249c7b3fcSTakashi Sakamoto runtime->hw.formats = AM824_OUT_PCM_FORMAT_BITS; 123216e256fSTakashi Sakamoto stream = &oxfw->rx_stream; 124216e256fSTakashi Sakamoto formats = oxfw->rx_stream_formats; 125216e256fSTakashi Sakamoto } 126216e256fSTakashi Sakamoto 1275cd1d3f4STakashi Sakamoto limit_channels_and_rates(&runtime->hw, formats); 1285cd1d3f4STakashi Sakamoto 1295cd1d3f4STakashi Sakamoto err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 1305cd1d3f4STakashi Sakamoto hw_rule_channels, formats, 1315cd1d3f4STakashi Sakamoto SNDRV_PCM_HW_PARAM_RATE, -1); 1323713d93aSTakashi Sakamoto if (err < 0) 1333713d93aSTakashi Sakamoto goto end; 1345cd1d3f4STakashi Sakamoto 1355cd1d3f4STakashi Sakamoto err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 1365cd1d3f4STakashi Sakamoto hw_rule_rate, formats, 1375cd1d3f4STakashi Sakamoto SNDRV_PCM_HW_PARAM_CHANNELS, -1); 1383713d93aSTakashi Sakamoto if (err < 0) 1393713d93aSTakashi Sakamoto goto end; 1403713d93aSTakashi Sakamoto 141bc8500daSTakashi Sakamoto err = amdtp_am824_add_pcm_hw_constraints(stream, runtime); 142216e256fSTakashi Sakamoto end: 143216e256fSTakashi Sakamoto return err; 144216e256fSTakashi Sakamoto } 145216e256fSTakashi Sakamoto 146216e256fSTakashi Sakamoto static int limit_to_current_params(struct snd_pcm_substream *substream) 147216e256fSTakashi Sakamoto { 148216e256fSTakashi Sakamoto struct snd_oxfw *oxfw = substream->private_data; 149216e256fSTakashi Sakamoto struct snd_oxfw_stream_formation formation; 150216e256fSTakashi Sakamoto enum avc_general_plug_dir dir; 151216e256fSTakashi Sakamoto int err; 152216e256fSTakashi Sakamoto 153216e256fSTakashi Sakamoto if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) 154216e256fSTakashi Sakamoto dir = AVC_GENERAL_PLUG_DIR_OUT; 155216e256fSTakashi Sakamoto else 156216e256fSTakashi Sakamoto dir = AVC_GENERAL_PLUG_DIR_IN; 157216e256fSTakashi Sakamoto 158216e256fSTakashi Sakamoto err = snd_oxfw_stream_get_current_formation(oxfw, dir, &formation); 1595cd1d3f4STakashi Sakamoto if (err < 0) 1605cd1d3f4STakashi Sakamoto goto end; 1615cd1d3f4STakashi Sakamoto 162216e256fSTakashi Sakamoto substream->runtime->hw.channels_min = formation.pcm; 163216e256fSTakashi Sakamoto substream->runtime->hw.channels_max = formation.pcm; 164216e256fSTakashi Sakamoto substream->runtime->hw.rate_min = formation.rate; 165216e256fSTakashi Sakamoto substream->runtime->hw.rate_max = formation.rate; 166216e256fSTakashi Sakamoto end: 167216e256fSTakashi Sakamoto return err; 168216e256fSTakashi Sakamoto } 169216e256fSTakashi Sakamoto 170216e256fSTakashi Sakamoto static int pcm_open(struct snd_pcm_substream *substream) 171216e256fSTakashi Sakamoto { 172216e256fSTakashi Sakamoto struct snd_oxfw *oxfw = substream->private_data; 173216e256fSTakashi Sakamoto int err; 174216e256fSTakashi Sakamoto 1758985f4acSTakashi Sakamoto err = snd_oxfw_stream_lock_try(oxfw); 176216e256fSTakashi Sakamoto if (err < 0) 177216e256fSTakashi Sakamoto goto end; 178216e256fSTakashi Sakamoto 1798985f4acSTakashi Sakamoto err = init_hw_params(oxfw, substream); 1808985f4acSTakashi Sakamoto if (err < 0) 1818985f4acSTakashi Sakamoto goto err_locked; 1828985f4acSTakashi Sakamoto 183216e256fSTakashi Sakamoto /* 184216e256fSTakashi Sakamoto * When any PCM streams are already running, the available sampling 185216e256fSTakashi Sakamoto * rate is limited at current value. 186216e256fSTakashi Sakamoto */ 187216e256fSTakashi Sakamoto if (amdtp_stream_pcm_running(&oxfw->tx_stream) || 188216e256fSTakashi Sakamoto amdtp_stream_pcm_running(&oxfw->rx_stream)) { 189216e256fSTakashi Sakamoto err = limit_to_current_params(substream); 190216e256fSTakashi Sakamoto if (err < 0) 191216e256fSTakashi Sakamoto goto end; 192216e256fSTakashi Sakamoto } 193216e256fSTakashi Sakamoto 1945cd1d3f4STakashi Sakamoto snd_pcm_set_sync(substream); 1953713d93aSTakashi Sakamoto end: 1963713d93aSTakashi Sakamoto return err; 1978985f4acSTakashi Sakamoto err_locked: 1988985f4acSTakashi Sakamoto snd_oxfw_stream_lock_release(oxfw); 1998985f4acSTakashi Sakamoto return err; 2003713d93aSTakashi Sakamoto } 2013713d93aSTakashi Sakamoto 2023713d93aSTakashi Sakamoto static int pcm_close(struct snd_pcm_substream *substream) 2033713d93aSTakashi Sakamoto { 2048985f4acSTakashi Sakamoto struct snd_oxfw *oxfw = substream->private_data; 2058985f4acSTakashi Sakamoto 2068985f4acSTakashi Sakamoto snd_oxfw_stream_lock_release(oxfw); 2073713d93aSTakashi Sakamoto return 0; 2083713d93aSTakashi Sakamoto } 2093713d93aSTakashi Sakamoto 210216e256fSTakashi Sakamoto static int pcm_capture_hw_params(struct snd_pcm_substream *substream, 2113713d93aSTakashi Sakamoto struct snd_pcm_hw_params *hw_params) 2123713d93aSTakashi Sakamoto { 2133713d93aSTakashi Sakamoto struct snd_oxfw *oxfw = substream->private_data; 21422c103cdSTakashi Sakamoto int err; 2153713d93aSTakashi 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; 220216e256fSTakashi Sakamoto 221216e256fSTakashi Sakamoto if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) { 2224f380d00STakashi Sakamoto unsigned int rate = params_rate(hw_params); 2234f380d00STakashi Sakamoto unsigned int channels = params_channels(hw_params); 2244f380d00STakashi Sakamoto 225216e256fSTakashi Sakamoto mutex_lock(&oxfw->mutex); 2264f380d00STakashi Sakamoto err = snd_oxfw_stream_reserve_duplex(oxfw, &oxfw->tx_stream, 2274f380d00STakashi Sakamoto rate, channels); 2284f380d00STakashi Sakamoto if (err >= 0) 2294a0a0472STakashi Sakamoto ++oxfw->substreams_count; 230216e256fSTakashi Sakamoto mutex_unlock(&oxfw->mutex); 231216e256fSTakashi Sakamoto } 232216e256fSTakashi Sakamoto 2334f380d00STakashi Sakamoto return err; 234216e256fSTakashi Sakamoto } 235216e256fSTakashi Sakamoto static int pcm_playback_hw_params(struct snd_pcm_substream *substream, 236216e256fSTakashi Sakamoto struct snd_pcm_hw_params *hw_params) 237216e256fSTakashi Sakamoto { 238216e256fSTakashi Sakamoto struct snd_oxfw *oxfw = substream->private_data; 23922c103cdSTakashi Sakamoto int err; 24022c103cdSTakashi Sakamoto 24122c103cdSTakashi Sakamoto err = snd_pcm_lib_alloc_vmalloc_buffer(substream, 24222c103cdSTakashi Sakamoto params_buffer_bytes(hw_params)); 24322c103cdSTakashi Sakamoto if (err < 0) 24422c103cdSTakashi Sakamoto return err; 245216e256fSTakashi Sakamoto 246216e256fSTakashi Sakamoto if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) { 2474f380d00STakashi Sakamoto unsigned int rate = params_rate(hw_params); 2484f380d00STakashi Sakamoto unsigned int channels = params_channels(hw_params); 2494f380d00STakashi Sakamoto 250216e256fSTakashi Sakamoto mutex_lock(&oxfw->mutex); 251*2fd23293STakashi Sakamoto err = snd_oxfw_stream_reserve_duplex(oxfw, &oxfw->rx_stream, 2524f380d00STakashi Sakamoto rate, channels); 2534f380d00STakashi Sakamoto if (err >= 0) 2544a0a0472STakashi Sakamoto ++oxfw->substreams_count; 255216e256fSTakashi Sakamoto mutex_unlock(&oxfw->mutex); 256216e256fSTakashi Sakamoto } 257216e256fSTakashi Sakamoto 25822c103cdSTakashi Sakamoto return 0; 2593713d93aSTakashi Sakamoto } 2603713d93aSTakashi Sakamoto 261216e256fSTakashi Sakamoto static int pcm_capture_hw_free(struct snd_pcm_substream *substream) 2623713d93aSTakashi Sakamoto { 2633713d93aSTakashi Sakamoto struct snd_oxfw *oxfw = substream->private_data; 2643713d93aSTakashi Sakamoto 2653713d93aSTakashi Sakamoto mutex_lock(&oxfw->mutex); 266216e256fSTakashi Sakamoto 267216e256fSTakashi Sakamoto if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN) 2684a0a0472STakashi Sakamoto --oxfw->substreams_count; 269216e256fSTakashi Sakamoto 270779f0dbaSTakashi Sakamoto snd_oxfw_stream_stop_duplex(oxfw); 271216e256fSTakashi Sakamoto 272216e256fSTakashi Sakamoto mutex_unlock(&oxfw->mutex); 273216e256fSTakashi Sakamoto 274216e256fSTakashi Sakamoto return snd_pcm_lib_free_vmalloc_buffer(substream); 275216e256fSTakashi Sakamoto } 276216e256fSTakashi Sakamoto static int pcm_playback_hw_free(struct snd_pcm_substream *substream) 277216e256fSTakashi Sakamoto { 278216e256fSTakashi Sakamoto struct snd_oxfw *oxfw = substream->private_data; 279216e256fSTakashi Sakamoto 280216e256fSTakashi Sakamoto mutex_lock(&oxfw->mutex); 281216e256fSTakashi Sakamoto 282216e256fSTakashi Sakamoto if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN) 2834a0a0472STakashi Sakamoto --oxfw->substreams_count; 284216e256fSTakashi Sakamoto 285779f0dbaSTakashi Sakamoto snd_oxfw_stream_stop_duplex(oxfw); 286216e256fSTakashi Sakamoto 2873713d93aSTakashi Sakamoto mutex_unlock(&oxfw->mutex); 2883713d93aSTakashi Sakamoto 2893713d93aSTakashi Sakamoto return snd_pcm_lib_free_vmalloc_buffer(substream); 2903713d93aSTakashi Sakamoto } 2913713d93aSTakashi Sakamoto 292216e256fSTakashi Sakamoto static int pcm_capture_prepare(struct snd_pcm_substream *substream) 293216e256fSTakashi Sakamoto { 294216e256fSTakashi Sakamoto struct snd_oxfw *oxfw = substream->private_data; 295216e256fSTakashi Sakamoto int err; 296216e256fSTakashi Sakamoto 297216e256fSTakashi Sakamoto mutex_lock(&oxfw->mutex); 2984f380d00STakashi Sakamoto err = snd_oxfw_stream_start_duplex(oxfw); 299216e256fSTakashi Sakamoto mutex_unlock(&oxfw->mutex); 300216e256fSTakashi Sakamoto if (err < 0) 301216e256fSTakashi Sakamoto goto end; 302216e256fSTakashi Sakamoto 303216e256fSTakashi Sakamoto amdtp_stream_pcm_prepare(&oxfw->tx_stream); 304216e256fSTakashi Sakamoto end: 305216e256fSTakashi Sakamoto return err; 306216e256fSTakashi Sakamoto } 307216e256fSTakashi Sakamoto static int pcm_playback_prepare(struct snd_pcm_substream *substream) 3083713d93aSTakashi Sakamoto { 3093713d93aSTakashi Sakamoto struct snd_oxfw *oxfw = substream->private_data; 3103713d93aSTakashi Sakamoto int err; 3113713d93aSTakashi Sakamoto 3123713d93aSTakashi Sakamoto mutex_lock(&oxfw->mutex); 3134f380d00STakashi Sakamoto err = snd_oxfw_stream_start_duplex(oxfw); 314f3699e2cSTakashi Sakamoto mutex_unlock(&oxfw->mutex); 3153713d93aSTakashi Sakamoto if (err < 0) 3163713d93aSTakashi Sakamoto goto end; 3173713d93aSTakashi Sakamoto 3183713d93aSTakashi Sakamoto amdtp_stream_pcm_prepare(&oxfw->rx_stream); 3193713d93aSTakashi Sakamoto end: 3203713d93aSTakashi Sakamoto return err; 3213713d93aSTakashi Sakamoto } 3223713d93aSTakashi Sakamoto 323216e256fSTakashi Sakamoto static int pcm_capture_trigger(struct snd_pcm_substream *substream, int cmd) 324216e256fSTakashi Sakamoto { 325216e256fSTakashi Sakamoto struct snd_oxfw *oxfw = substream->private_data; 326216e256fSTakashi Sakamoto struct snd_pcm_substream *pcm; 327216e256fSTakashi Sakamoto 328216e256fSTakashi Sakamoto switch (cmd) { 329216e256fSTakashi Sakamoto case SNDRV_PCM_TRIGGER_START: 330216e256fSTakashi Sakamoto pcm = substream; 331216e256fSTakashi Sakamoto break; 332216e256fSTakashi Sakamoto case SNDRV_PCM_TRIGGER_STOP: 333216e256fSTakashi Sakamoto pcm = NULL; 334216e256fSTakashi Sakamoto break; 335216e256fSTakashi Sakamoto default: 336216e256fSTakashi Sakamoto return -EINVAL; 337216e256fSTakashi Sakamoto } 338216e256fSTakashi Sakamoto amdtp_stream_pcm_trigger(&oxfw->tx_stream, pcm); 339216e256fSTakashi Sakamoto return 0; 340216e256fSTakashi Sakamoto } 341216e256fSTakashi Sakamoto static int pcm_playback_trigger(struct snd_pcm_substream *substream, int cmd) 3423713d93aSTakashi Sakamoto { 3433713d93aSTakashi Sakamoto struct snd_oxfw *oxfw = substream->private_data; 3443713d93aSTakashi Sakamoto struct snd_pcm_substream *pcm; 3453713d93aSTakashi Sakamoto 3463713d93aSTakashi Sakamoto switch (cmd) { 3473713d93aSTakashi Sakamoto case SNDRV_PCM_TRIGGER_START: 3483713d93aSTakashi Sakamoto pcm = substream; 3493713d93aSTakashi Sakamoto break; 3503713d93aSTakashi Sakamoto case SNDRV_PCM_TRIGGER_STOP: 3513713d93aSTakashi Sakamoto pcm = NULL; 3523713d93aSTakashi Sakamoto break; 3533713d93aSTakashi Sakamoto default: 3543713d93aSTakashi Sakamoto return -EINVAL; 3553713d93aSTakashi Sakamoto } 3563713d93aSTakashi Sakamoto amdtp_stream_pcm_trigger(&oxfw->rx_stream, pcm); 3573713d93aSTakashi Sakamoto return 0; 3583713d93aSTakashi Sakamoto } 3593713d93aSTakashi Sakamoto 360216e256fSTakashi Sakamoto static snd_pcm_uframes_t pcm_capture_pointer(struct snd_pcm_substream *sbstm) 3613713d93aSTakashi Sakamoto { 362216e256fSTakashi Sakamoto struct snd_oxfw *oxfw = sbstm->private_data; 363216e256fSTakashi Sakamoto 364216e256fSTakashi Sakamoto return amdtp_stream_pcm_pointer(&oxfw->tx_stream); 365216e256fSTakashi Sakamoto } 366216e256fSTakashi Sakamoto static snd_pcm_uframes_t pcm_playback_pointer(struct snd_pcm_substream *sbstm) 367216e256fSTakashi Sakamoto { 368216e256fSTakashi Sakamoto struct snd_oxfw *oxfw = sbstm->private_data; 3693713d93aSTakashi Sakamoto 3703713d93aSTakashi Sakamoto return amdtp_stream_pcm_pointer(&oxfw->rx_stream); 3713713d93aSTakashi Sakamoto } 3723713d93aSTakashi Sakamoto 373875becf8STakashi Sakamoto static int pcm_capture_ack(struct snd_pcm_substream *substream) 374875becf8STakashi Sakamoto { 375875becf8STakashi Sakamoto struct snd_oxfw *oxfw = substream->private_data; 376875becf8STakashi Sakamoto 377875becf8STakashi Sakamoto return amdtp_stream_pcm_ack(&oxfw->tx_stream); 378875becf8STakashi Sakamoto } 379875becf8STakashi Sakamoto 380875becf8STakashi Sakamoto static int pcm_playback_ack(struct snd_pcm_substream *substream) 381875becf8STakashi Sakamoto { 382875becf8STakashi Sakamoto struct snd_oxfw *oxfw = substream->private_data; 383875becf8STakashi Sakamoto 384875becf8STakashi Sakamoto return amdtp_stream_pcm_ack(&oxfw->rx_stream); 385875becf8STakashi Sakamoto } 386875becf8STakashi Sakamoto 3873713d93aSTakashi Sakamoto int snd_oxfw_create_pcm(struct snd_oxfw *oxfw) 3883713d93aSTakashi Sakamoto { 3895116ffc3SJulia Lawall static const struct snd_pcm_ops capture_ops = { 3903713d93aSTakashi Sakamoto .open = pcm_open, 3913713d93aSTakashi Sakamoto .close = pcm_close, 3923713d93aSTakashi Sakamoto .ioctl = snd_pcm_lib_ioctl, 393216e256fSTakashi Sakamoto .hw_params = pcm_capture_hw_params, 394216e256fSTakashi Sakamoto .hw_free = pcm_capture_hw_free, 395216e256fSTakashi Sakamoto .prepare = pcm_capture_prepare, 396216e256fSTakashi Sakamoto .trigger = pcm_capture_trigger, 397216e256fSTakashi Sakamoto .pointer = pcm_capture_pointer, 398875becf8STakashi Sakamoto .ack = pcm_capture_ack, 399216e256fSTakashi Sakamoto .page = snd_pcm_lib_get_vmalloc_page, 400216e256fSTakashi Sakamoto }; 4015116ffc3SJulia Lawall static const struct snd_pcm_ops playback_ops = { 402216e256fSTakashi Sakamoto .open = pcm_open, 403216e256fSTakashi Sakamoto .close = pcm_close, 404216e256fSTakashi Sakamoto .ioctl = snd_pcm_lib_ioctl, 405216e256fSTakashi Sakamoto .hw_params = pcm_playback_hw_params, 406216e256fSTakashi Sakamoto .hw_free = pcm_playback_hw_free, 407216e256fSTakashi Sakamoto .prepare = pcm_playback_prepare, 408216e256fSTakashi Sakamoto .trigger = pcm_playback_trigger, 409216e256fSTakashi Sakamoto .pointer = pcm_playback_pointer, 410875becf8STakashi Sakamoto .ack = pcm_playback_ack, 4113713d93aSTakashi Sakamoto .page = snd_pcm_lib_get_vmalloc_page, 4123713d93aSTakashi Sakamoto }; 4133713d93aSTakashi Sakamoto struct snd_pcm *pcm; 414216e256fSTakashi Sakamoto unsigned int cap = 0; 4153713d93aSTakashi Sakamoto int err; 4163713d93aSTakashi Sakamoto 417216e256fSTakashi Sakamoto if (oxfw->has_output) 418216e256fSTakashi Sakamoto cap = 1; 419216e256fSTakashi Sakamoto 420216e256fSTakashi Sakamoto err = snd_pcm_new(oxfw->card, oxfw->card->driver, 0, 1, cap, &pcm); 4213713d93aSTakashi Sakamoto if (err < 0) 4223713d93aSTakashi Sakamoto return err; 423216e256fSTakashi Sakamoto 4243713d93aSTakashi Sakamoto pcm->private_data = oxfw; 4253713d93aSTakashi Sakamoto strcpy(pcm->name, oxfw->card->shortname); 426216e256fSTakashi Sakamoto snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &playback_ops); 427216e256fSTakashi Sakamoto if (cap > 0) 428216e256fSTakashi Sakamoto snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &capture_ops); 429216e256fSTakashi Sakamoto 4303713d93aSTakashi Sakamoto return 0; 4313713d93aSTakashi Sakamoto } 432