^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Line 6 Linux USB driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <sound/control.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <sound/pcm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <sound/pcm_params.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "capture.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "driver.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "playback.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) /* impulse response volume controls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) static int snd_line6_impulse_volume_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) uinfo->count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) uinfo->value.integer.min = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) uinfo->value.integer.max = 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static int snd_line6_impulse_volume_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) ucontrol->value.integer.value[0] = line6pcm->impulse_volume;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static int snd_line6_impulse_volume_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) int value = ucontrol->value.integer.value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) if (line6pcm->impulse_volume == value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) line6pcm->impulse_volume = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) if (value > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) err = line6_pcm_acquire(line6pcm, LINE6_STREAM_IMPULSE, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) line6pcm->impulse_volume = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) line6_pcm_release(line6pcm, LINE6_STREAM_IMPULSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) /* impulse response period controls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) static int snd_line6_impulse_period_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) uinfo->count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) uinfo->value.integer.min = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) uinfo->value.integer.max = 2000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) static int snd_line6_impulse_period_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) ucontrol->value.integer.value[0] = line6pcm->impulse_period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) static int snd_line6_impulse_period_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) int value = ucontrol->value.integer.value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) if (line6pcm->impulse_period == value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) line6pcm->impulse_period = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) Unlink all currently active URBs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) static void line6_unlink_audio_urbs(struct snd_line6_pcm *line6pcm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) struct line6_pcm_stream *pcms)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) for (i = 0; i < line6pcm->line6->iso_buffers; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) if (test_bit(i, &pcms->active_urbs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (!test_and_set_bit(i, &pcms->unlink_urbs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) usb_unlink_urb(pcms->urbs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) Wait until unlinking of all currently active URBs has been finished.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static void line6_wait_clear_audio_urbs(struct snd_line6_pcm *line6pcm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct line6_pcm_stream *pcms)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) int timeout = HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) int alive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) alive = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) for (i = 0; i < line6pcm->line6->iso_buffers; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if (test_bit(i, &pcms->active_urbs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) alive++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) if (!alive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) set_current_state(TASK_UNINTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) schedule_timeout(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) } while (--timeout > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) if (alive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) dev_err(line6pcm->line6->ifcdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) "timeout: still %d active urbs..\n", alive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) static inline struct line6_pcm_stream *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) get_stream(struct snd_line6_pcm *line6pcm, int direction)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) return (direction == SNDRV_PCM_STREAM_PLAYBACK) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) &line6pcm->out : &line6pcm->in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) /* allocate a buffer if not opened yet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * call this in line6pcm.state_mutex
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) static int line6_buffer_acquire(struct snd_line6_pcm *line6pcm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) struct line6_pcm_stream *pstr, int direction, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) const int pkt_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) (direction == SNDRV_PCM_STREAM_PLAYBACK) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) line6pcm->max_packet_size_out :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) line6pcm->max_packet_size_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) /* Invoked multiple times in a row so allocate once only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) if (!test_and_set_bit(type, &pstr->opened) && !pstr->buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) pstr->buffer =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) kmalloc(array3_size(line6pcm->line6->iso_buffers,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) LINE6_ISO_PACKETS, pkt_size),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) if (!pstr->buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) /* free a buffer if all streams are closed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * call this in line6pcm.state_mutex
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) static void line6_buffer_release(struct snd_line6_pcm *line6pcm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) struct line6_pcm_stream *pstr, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) clear_bit(type, &pstr->opened);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) if (!pstr->opened) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) line6_wait_clear_audio_urbs(line6pcm, pstr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) kfree(pstr->buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) pstr->buffer = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) /* start a PCM stream */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) static int line6_stream_start(struct snd_line6_pcm *line6pcm, int direction,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) struct line6_pcm_stream *pstr = get_stream(line6pcm, direction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) spin_lock_irqsave(&pstr->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if (!test_and_set_bit(type, &pstr->running) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) !(pstr->active_urbs || pstr->unlink_urbs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) pstr->count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) /* Submit all currently available URBs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) if (direction == SNDRV_PCM_STREAM_PLAYBACK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) ret = line6_submit_audio_out_all_urbs(line6pcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) ret = line6_submit_audio_in_all_urbs(line6pcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) clear_bit(type, &pstr->running);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) spin_unlock_irqrestore(&pstr->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) /* stop a PCM stream; this doesn't sync with the unlinked URBs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static void line6_stream_stop(struct snd_line6_pcm *line6pcm, int direction,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) struct line6_pcm_stream *pstr = get_stream(line6pcm, direction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) spin_lock_irqsave(&pstr->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) clear_bit(type, &pstr->running);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) if (!pstr->running) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) spin_unlock_irqrestore(&pstr->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) line6_unlink_audio_urbs(line6pcm, pstr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) spin_lock_irqsave(&pstr->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (direction == SNDRV_PCM_STREAM_CAPTURE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) line6pcm->prev_fbuf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) line6pcm->prev_fsize = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) spin_unlock_irqrestore(&pstr->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) /* common PCM trigger callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) int snd_line6_trigger(struct snd_pcm_substream *substream, int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) struct snd_pcm_substream *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) clear_bit(LINE6_FLAG_PREPARED, &line6pcm->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) snd_pcm_group_for_each_entry(s, substream) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) if (s->pcm->card != substream->pcm->card)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) case SNDRV_PCM_TRIGGER_START:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) case SNDRV_PCM_TRIGGER_RESUME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) if (s->stream == SNDRV_PCM_STREAM_CAPTURE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) (line6pcm->line6->properties->capabilities &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) LINE6_CAP_IN_NEEDS_OUT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) err = line6_stream_start(line6pcm, SNDRV_PCM_STREAM_PLAYBACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) LINE6_STREAM_CAPTURE_HELPER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) err = line6_stream_start(line6pcm, s->stream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) LINE6_STREAM_PCM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) case SNDRV_PCM_TRIGGER_STOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) case SNDRV_PCM_TRIGGER_SUSPEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if (s->stream == SNDRV_PCM_STREAM_CAPTURE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) (line6pcm->line6->properties->capabilities &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) LINE6_CAP_IN_NEEDS_OUT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) line6_stream_stop(line6pcm, SNDRV_PCM_STREAM_PLAYBACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) LINE6_STREAM_CAPTURE_HELPER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) line6_stream_stop(line6pcm, s->stream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) LINE6_STREAM_PCM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) if (s->stream != SNDRV_PCM_STREAM_PLAYBACK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) set_bit(LINE6_FLAG_PAUSE_PLAYBACK, &line6pcm->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) if (s->stream != SNDRV_PCM_STREAM_PLAYBACK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) clear_bit(LINE6_FLAG_PAUSE_PLAYBACK, &line6pcm->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) /* common PCM pointer callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) snd_pcm_uframes_t snd_line6_pointer(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) struct line6_pcm_stream *pstr = get_stream(line6pcm, substream->stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) return pstr->pos_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) /* Acquire and optionally start duplex streams:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) * type is either LINE6_STREAM_IMPULSE or LINE6_STREAM_MONITOR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int type, bool start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) struct line6_pcm_stream *pstr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) int ret = 0, dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) /* TODO: We should assert SNDRV_PCM_STREAM_PLAYBACK/CAPTURE == 0/1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) mutex_lock(&line6pcm->state_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) for (dir = 0; dir < 2; dir++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) pstr = get_stream(line6pcm, dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) ret = line6_buffer_acquire(line6pcm, pstr, dir, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) if (!pstr->running)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) line6_wait_clear_audio_urbs(line6pcm, pstr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) if (start) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) for (dir = 0; dir < 2; dir++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) ret = line6_stream_start(line6pcm, dir, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) mutex_unlock(&line6pcm->state_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) line6_pcm_release(line6pcm, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) EXPORT_SYMBOL_GPL(line6_pcm_acquire);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) /* Stop and release duplex streams */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) void line6_pcm_release(struct snd_line6_pcm *line6pcm, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) struct line6_pcm_stream *pstr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) int dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) mutex_lock(&line6pcm->state_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) for (dir = 0; dir < 2; dir++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) line6_stream_stop(line6pcm, dir, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) for (dir = 0; dir < 2; dir++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) pstr = get_stream(line6pcm, dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) line6_buffer_release(line6pcm, pstr, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) mutex_unlock(&line6pcm->state_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) EXPORT_SYMBOL_GPL(line6_pcm_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) /* common PCM hw_params callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) int snd_line6_hw_params(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) struct snd_pcm_hw_params *hw_params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) struct line6_pcm_stream *pstr = get_stream(line6pcm, substream->stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) mutex_lock(&line6pcm->state_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) ret = line6_buffer_acquire(line6pcm, pstr, substream->stream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) LINE6_STREAM_PCM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) pstr->period = params_period_bytes(hw_params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) mutex_unlock(&line6pcm->state_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) /* common PCM hw_free callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) int snd_line6_hw_free(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) struct line6_pcm_stream *pstr = get_stream(line6pcm, substream->stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) mutex_lock(&line6pcm->state_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) line6_buffer_release(line6pcm, pstr, LINE6_STREAM_PCM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) mutex_unlock(&line6pcm->state_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) /* control info callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) static int snd_line6_control_playback_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) uinfo->count = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) uinfo->value.integer.min = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) uinfo->value.integer.max = 256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) /* control get callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) static int snd_line6_control_playback_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) for (i = 0; i < 2; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) ucontrol->value.integer.value[i] = line6pcm->volume_playback[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) /* control put callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) static int snd_line6_control_playback_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) int i, changed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) for (i = 0; i < 2; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) if (line6pcm->volume_playback[i] !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) ucontrol->value.integer.value[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) line6pcm->volume_playback[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) ucontrol->value.integer.value[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) changed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) return changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) /* control definition */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) static const struct snd_kcontrol_new line6_controls[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) .name = "PCM Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) .info = snd_line6_control_playback_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) .get = snd_line6_control_playback_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) .put = snd_line6_control_playback_put
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) .name = "Impulse Response Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) .info = snd_line6_impulse_volume_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) .get = snd_line6_impulse_volume_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) .put = snd_line6_impulse_volume_put
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) .name = "Impulse Response Period",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) .info = snd_line6_impulse_period_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) .get = snd_line6_impulse_period_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) .put = snd_line6_impulse_period_put
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) Cleanup the PCM device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) static void cleanup_urbs(struct line6_pcm_stream *pcms, int iso_buffers)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) /* Most likely impossible in current code... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) if (pcms->urbs == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) for (i = 0; i < iso_buffers; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) if (pcms->urbs[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) usb_kill_urb(pcms->urbs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) usb_free_urb(pcms->urbs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) kfree(pcms->urbs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) pcms->urbs = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) static void line6_cleanup_pcm(struct snd_pcm *pcm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) struct snd_line6_pcm *line6pcm = snd_pcm_chip(pcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) cleanup_urbs(&line6pcm->out, line6pcm->line6->iso_buffers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) cleanup_urbs(&line6pcm->in, line6pcm->line6->iso_buffers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) kfree(line6pcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) /* create a PCM device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) static int snd_line6_new_pcm(struct usb_line6 *line6, struct snd_pcm **pcm_ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) struct snd_pcm *pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) err = snd_pcm_new(line6->card, (char *)line6->properties->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 0, 1, 1, pcm_ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) pcm = *pcm_ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) strcpy(pcm->name, line6->properties->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) /* set operators */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) &snd_line6_playback_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_line6_capture_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) /* pre-allocation of buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) NULL, 64 * 1024, 128 * 1024);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) Sync with PCM stream stops.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) void line6_pcm_disconnect(struct snd_line6_pcm *line6pcm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) line6_unlink_audio_urbs(line6pcm, &line6pcm->out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) line6_unlink_audio_urbs(line6pcm, &line6pcm->in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) line6_wait_clear_audio_urbs(line6pcm, &line6pcm->out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) line6_wait_clear_audio_urbs(line6pcm, &line6pcm->in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) Create and register the PCM device and mixer entries.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) Create URBs for playback and capture.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) int line6_init_pcm(struct usb_line6 *line6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) struct line6_pcm_properties *properties)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) int i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) unsigned ep_read = line6->properties->ep_audio_r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) unsigned ep_write = line6->properties->ep_audio_w;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) struct snd_pcm *pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) struct snd_line6_pcm *line6pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) if (!(line6->properties->capabilities & LINE6_CAP_PCM))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) return 0; /* skip PCM initialization and report success */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) err = snd_line6_new_pcm(line6, &pcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) line6pcm = kzalloc(sizeof(*line6pcm), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) if (!line6pcm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) mutex_init(&line6pcm->state_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) line6pcm->pcm = pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) line6pcm->properties = properties;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) line6pcm->volume_playback[0] = line6pcm->volume_playback[1] = 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) line6pcm->volume_monitor = 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) line6pcm->line6 = line6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) spin_lock_init(&line6pcm->out.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) spin_lock_init(&line6pcm->in.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) line6pcm->impulse_period = LINE6_IMPULSE_DEFAULT_PERIOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) line6->line6pcm = line6pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) pcm->private_data = line6pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) pcm->private_free = line6_cleanup_pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) line6pcm->max_packet_size_in =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) usb_maxpacket(line6->usbdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) usb_rcvisocpipe(line6->usbdev, ep_read), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) line6pcm->max_packet_size_out =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) usb_maxpacket(line6->usbdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) usb_sndisocpipe(line6->usbdev, ep_write), 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) if (!line6pcm->max_packet_size_in || !line6pcm->max_packet_size_out) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) dev_err(line6pcm->line6->ifcdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) "cannot get proper max packet size\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) err = line6_create_audio_out_urbs(line6pcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) err = line6_create_audio_in_urbs(line6pcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) /* mixer: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) for (i = 0; i < ARRAY_SIZE(line6_controls); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) err = snd_ctl_add(line6->card,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) snd_ctl_new1(&line6_controls[i], line6pcm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) EXPORT_SYMBOL_GPL(line6_init_pcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) /* prepare pcm callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) int snd_line6_prepare(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) struct line6_pcm_stream *pstr = get_stream(line6pcm, substream->stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) mutex_lock(&line6pcm->state_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) if (!pstr->running)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) line6_wait_clear_audio_urbs(line6pcm, pstr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) if (!test_and_set_bit(LINE6_FLAG_PREPARED, &line6pcm->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) line6pcm->out.count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) line6pcm->out.pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) line6pcm->out.pos_done = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) line6pcm->out.bytes = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) line6pcm->in.count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) line6pcm->in.pos_done = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) line6pcm->in.bytes = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) mutex_unlock(&line6pcm->state_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) }