Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1 | /* |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 2 | * Line6 Linux USB driver - 0.9.1beta |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 3 | * |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 4 | * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation, version 2. |
| 9 | * |
| 10 | */ |
| 11 | |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 12 | #include <linux/slab.h> |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 13 | #include <linux/export.h> |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 14 | #include <sound/core.h> |
| 15 | #include <sound/control.h> |
| 16 | #include <sound/pcm.h> |
| 17 | #include <sound/pcm_params.h> |
| 18 | |
| 19 | #include "audio.h" |
| 20 | #include "capture.h" |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 21 | #include "driver.h" |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 22 | #include "playback.h" |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 23 | |
Takashi Iwai | 075587b | 2015-01-19 14:28:25 +0100 | [diff] [blame] | 24 | /* impulse response volume controls */ |
| 25 | static int snd_line6_impulse_volume_info(struct snd_kcontrol *kcontrol, |
| 26 | struct snd_ctl_elem_info *uinfo) |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 27 | { |
Takashi Iwai | 075587b | 2015-01-19 14:28:25 +0100 | [diff] [blame] | 28 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 29 | uinfo->count = 1; |
| 30 | uinfo->value.integer.min = 0; |
| 31 | uinfo->value.integer.max = 255; |
| 32 | return 0; |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 33 | } |
| 34 | |
Takashi Iwai | 075587b | 2015-01-19 14:28:25 +0100 | [diff] [blame] | 35 | static int snd_line6_impulse_volume_get(struct snd_kcontrol *kcontrol, |
| 36 | struct snd_ctl_elem_value *ucontrol) |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 37 | { |
Takashi Iwai | 075587b | 2015-01-19 14:28:25 +0100 | [diff] [blame] | 38 | struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol); |
| 39 | |
| 40 | ucontrol->value.integer.value[0] = line6pcm->impulse_volume; |
| 41 | return 0; |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 42 | } |
| 43 | |
Takashi Iwai | 075587b | 2015-01-19 14:28:25 +0100 | [diff] [blame] | 44 | static int snd_line6_impulse_volume_put(struct snd_kcontrol *kcontrol, |
| 45 | struct snd_ctl_elem_value *ucontrol) |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 46 | { |
Takashi Iwai | 075587b | 2015-01-19 14:28:25 +0100 | [diff] [blame] | 47 | struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol); |
| 48 | int value = ucontrol->value.integer.value[0]; |
Johannes Thumshirn | cdf5e55 | 2012-08-06 14:08:50 +0200 | [diff] [blame] | 49 | |
Takashi Iwai | 075587b | 2015-01-19 14:28:25 +0100 | [diff] [blame] | 50 | if (line6pcm->impulse_volume == value) |
| 51 | return 0; |
Johannes Thumshirn | cdf5e55 | 2012-08-06 14:08:50 +0200 | [diff] [blame] | 52 | |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 53 | line6pcm->impulse_volume = value; |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 54 | if (value > 0) |
Markus Grabner | 0ca5488 | 2012-01-20 00:09:09 +0100 | [diff] [blame] | 55 | line6_pcm_acquire(line6pcm, LINE6_BITS_PCM_IMPULSE); |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 56 | else |
Markus Grabner | 0ca5488 | 2012-01-20 00:09:09 +0100 | [diff] [blame] | 57 | line6_pcm_release(line6pcm, LINE6_BITS_PCM_IMPULSE); |
Takashi Iwai | 075587b | 2015-01-19 14:28:25 +0100 | [diff] [blame] | 58 | return 1; |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 59 | } |
| 60 | |
Takashi Iwai | 075587b | 2015-01-19 14:28:25 +0100 | [diff] [blame] | 61 | /* impulse response period controls */ |
| 62 | static int snd_line6_impulse_period_info(struct snd_kcontrol *kcontrol, |
| 63 | struct snd_ctl_elem_info *uinfo) |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 64 | { |
Takashi Iwai | 075587b | 2015-01-19 14:28:25 +0100 | [diff] [blame] | 65 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 66 | uinfo->count = 1; |
| 67 | uinfo->value.integer.min = 0; |
| 68 | uinfo->value.integer.max = 2000; |
| 69 | return 0; |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 70 | } |
| 71 | |
Takashi Iwai | 075587b | 2015-01-19 14:28:25 +0100 | [diff] [blame] | 72 | static int snd_line6_impulse_period_get(struct snd_kcontrol *kcontrol, |
| 73 | struct snd_ctl_elem_value *ucontrol) |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 74 | { |
Takashi Iwai | 075587b | 2015-01-19 14:28:25 +0100 | [diff] [blame] | 75 | struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol); |
Laurent Navet | a376290 | 2012-11-30 11:57:32 +0100 | [diff] [blame] | 76 | |
Takashi Iwai | 075587b | 2015-01-19 14:28:25 +0100 | [diff] [blame] | 77 | ucontrol->value.integer.value[0] = line6pcm->impulse_period; |
| 78 | return 0; |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 79 | } |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 80 | |
Takashi Iwai | 075587b | 2015-01-19 14:28:25 +0100 | [diff] [blame] | 81 | static int snd_line6_impulse_period_put(struct snd_kcontrol *kcontrol, |
| 82 | struct snd_ctl_elem_value *ucontrol) |
| 83 | { |
| 84 | struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol); |
| 85 | int value = ucontrol->value.integer.value[0]; |
| 86 | |
| 87 | if (line6pcm->impulse_period == value) |
| 88 | return 0; |
| 89 | |
| 90 | line6pcm->impulse_period = value; |
| 91 | return 1; |
| 92 | } |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 93 | |
Markus Grabner | 6b02a17e | 2011-12-10 02:12:32 +0100 | [diff] [blame] | 94 | static bool test_flags(unsigned long flags0, unsigned long flags1, |
| 95 | unsigned long mask) |
| 96 | { |
| 97 | return ((flags0 & mask) == 0) && ((flags1 & mask) != 0); |
| 98 | } |
| 99 | |
Markus Grabner | 0ca5488 | 2012-01-20 00:09:09 +0100 | [diff] [blame] | 100 | int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int channels) |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 101 | { |
Arnd Bergmann | 9f61360 | 2013-06-21 21:55:35 +0200 | [diff] [blame] | 102 | unsigned long flags_old, flags_new, flags_final; |
| 103 | int err; |
| 104 | |
| 105 | do { |
| 106 | flags_old = ACCESS_ONCE(line6pcm->flags); |
| 107 | flags_new = flags_old | channels; |
| 108 | } while (cmpxchg(&line6pcm->flags, flags_old, flags_new) != flags_old); |
| 109 | |
| 110 | flags_final = flags_old; |
Johannes Thumshirn | 82a74d4 | 2012-05-05 16:31:52 +0200 | [diff] [blame] | 111 | |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 112 | line6pcm->prev_fbuf = NULL; |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 113 | |
Markus Grabner | 0ca5488 | 2012-01-20 00:09:09 +0100 | [diff] [blame] | 114 | if (test_flags(flags_old, flags_new, LINE6_BITS_CAPTURE_BUFFER)) { |
Stefan Hajnoczi | 928f25e | 2012-11-11 13:24:41 +0100 | [diff] [blame] | 115 | /* Invoked multiple times in a row so allocate once only */ |
Markus Grabner | 0ca5488 | 2012-01-20 00:09:09 +0100 | [diff] [blame] | 116 | if (!line6pcm->buffer_in) { |
| 117 | line6pcm->buffer_in = |
| 118 | kmalloc(LINE6_ISO_BUFFERS * LINE6_ISO_PACKETS * |
| 119 | line6pcm->max_packet_size, GFP_KERNEL); |
Markus Grabner | 0ca5488 | 2012-01-20 00:09:09 +0100 | [diff] [blame] | 120 | if (!line6pcm->buffer_in) { |
Markus Grabner | 0ca5488 | 2012-01-20 00:09:09 +0100 | [diff] [blame] | 121 | err = -ENOMEM; |
| 122 | goto pcm_acquire_error; |
| 123 | } |
| 124 | |
| 125 | flags_final |= channels & LINE6_BITS_CAPTURE_BUFFER; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | if (test_flags(flags_old, flags_new, LINE6_BITS_CAPTURE_STREAM)) { |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 130 | /* |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 131 | Waiting for completion of active URBs in the stop handler is |
| 132 | a bug, we therefore report an error if capturing is restarted |
| 133 | too soon. |
| 134 | */ |
Markus Grabner | 0ca5488 | 2012-01-20 00:09:09 +0100 | [diff] [blame] | 135 | if (line6pcm->active_urb_in | line6pcm->unlink_urb_in) { |
| 136 | dev_err(line6pcm->line6->ifcdev, "Device not yet ready\n"); |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 137 | return -EBUSY; |
Markus Grabner | 6b02a17e | 2011-12-10 02:12:32 +0100 | [diff] [blame] | 138 | } |
| 139 | |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 140 | line6pcm->count_in = 0; |
| 141 | line6pcm->prev_fsize = 0; |
| 142 | err = line6_submit_audio_in_all_urbs(line6pcm); |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 143 | |
Markus Grabner | 6b02a17e | 2011-12-10 02:12:32 +0100 | [diff] [blame] | 144 | if (err < 0) |
Markus Grabner | 0ca5488 | 2012-01-20 00:09:09 +0100 | [diff] [blame] | 145 | goto pcm_acquire_error; |
| 146 | |
| 147 | flags_final |= channels & LINE6_BITS_CAPTURE_STREAM; |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 148 | } |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 149 | |
Markus Grabner | 0ca5488 | 2012-01-20 00:09:09 +0100 | [diff] [blame] | 150 | if (test_flags(flags_old, flags_new, LINE6_BITS_PLAYBACK_BUFFER)) { |
Stefan Hajnoczi | 928f25e | 2012-11-11 13:24:41 +0100 | [diff] [blame] | 151 | /* Invoked multiple times in a row so allocate once only */ |
Markus Grabner | 0ca5488 | 2012-01-20 00:09:09 +0100 | [diff] [blame] | 152 | if (!line6pcm->buffer_out) { |
| 153 | line6pcm->buffer_out = |
| 154 | kmalloc(LINE6_ISO_BUFFERS * LINE6_ISO_PACKETS * |
| 155 | line6pcm->max_packet_size, GFP_KERNEL); |
Markus Grabner | 0ca5488 | 2012-01-20 00:09:09 +0100 | [diff] [blame] | 156 | if (!line6pcm->buffer_out) { |
Markus Grabner | 0ca5488 | 2012-01-20 00:09:09 +0100 | [diff] [blame] | 157 | err = -ENOMEM; |
| 158 | goto pcm_acquire_error; |
| 159 | } |
| 160 | |
| 161 | flags_final |= channels & LINE6_BITS_PLAYBACK_BUFFER; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | if (test_flags(flags_old, flags_new, LINE6_BITS_PLAYBACK_STREAM)) { |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 166 | /* |
Markus Grabner | 0ca5488 | 2012-01-20 00:09:09 +0100 | [diff] [blame] | 167 | See comment above regarding PCM restart. |
| 168 | */ |
| 169 | if (line6pcm->active_urb_out | line6pcm->unlink_urb_out) { |
| 170 | dev_err(line6pcm->line6->ifcdev, "Device not yet ready\n"); |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 171 | return -EBUSY; |
Markus Grabner | 6b02a17e | 2011-12-10 02:12:32 +0100 | [diff] [blame] | 172 | } |
| 173 | |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 174 | line6pcm->count_out = 0; |
| 175 | err = line6_submit_audio_out_all_urbs(line6pcm); |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 176 | |
Markus Grabner | 6b02a17e | 2011-12-10 02:12:32 +0100 | [diff] [blame] | 177 | if (err < 0) |
Markus Grabner | 0ca5488 | 2012-01-20 00:09:09 +0100 | [diff] [blame] | 178 | goto pcm_acquire_error; |
| 179 | |
| 180 | flags_final |= channels & LINE6_BITS_PLAYBACK_STREAM; |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 181 | } |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 182 | |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 183 | return 0; |
Markus Grabner | 6b02a17e | 2011-12-10 02:12:32 +0100 | [diff] [blame] | 184 | |
Markus Grabner | 0ca5488 | 2012-01-20 00:09:09 +0100 | [diff] [blame] | 185 | pcm_acquire_error: |
| 186 | /* |
| 187 | If not all requested resources/streams could be obtained, release |
| 188 | those which were successfully obtained (if any). |
| 189 | */ |
| 190 | line6_pcm_release(line6pcm, flags_final & channels); |
Markus Grabner | 6b02a17e | 2011-12-10 02:12:32 +0100 | [diff] [blame] | 191 | return err; |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 192 | } |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 193 | EXPORT_SYMBOL_GPL(line6_pcm_acquire); |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 194 | |
Markus Grabner | 0ca5488 | 2012-01-20 00:09:09 +0100 | [diff] [blame] | 195 | int line6_pcm_release(struct snd_line6_pcm *line6pcm, int channels) |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 196 | { |
Arnd Bergmann | 9f61360 | 2013-06-21 21:55:35 +0200 | [diff] [blame] | 197 | unsigned long flags_old, flags_new; |
| 198 | |
| 199 | do { |
| 200 | flags_old = ACCESS_ONCE(line6pcm->flags); |
| 201 | flags_new = flags_old & ~channels; |
| 202 | } while (cmpxchg(&line6pcm->flags, flags_old, flags_new) != flags_old); |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 203 | |
Markus Grabner | 0ca5488 | 2012-01-20 00:09:09 +0100 | [diff] [blame] | 204 | if (test_flags(flags_new, flags_old, LINE6_BITS_CAPTURE_STREAM)) |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 205 | line6_unlink_audio_in_urbs(line6pcm); |
Markus Grabner | 6b02a17e | 2011-12-10 02:12:32 +0100 | [diff] [blame] | 206 | |
Markus Grabner | 0ca5488 | 2012-01-20 00:09:09 +0100 | [diff] [blame] | 207 | if (test_flags(flags_new, flags_old, LINE6_BITS_CAPTURE_BUFFER)) { |
| 208 | line6_wait_clear_audio_in_urbs(line6pcm); |
| 209 | line6_free_capture_buffer(line6pcm); |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 210 | } |
| 211 | |
Markus Grabner | 0ca5488 | 2012-01-20 00:09:09 +0100 | [diff] [blame] | 212 | if (test_flags(flags_new, flags_old, LINE6_BITS_PLAYBACK_STREAM)) |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 213 | line6_unlink_audio_out_urbs(line6pcm); |
Markus Grabner | 6b02a17e | 2011-12-10 02:12:32 +0100 | [diff] [blame] | 214 | |
Markus Grabner | 0ca5488 | 2012-01-20 00:09:09 +0100 | [diff] [blame] | 215 | if (test_flags(flags_new, flags_old, LINE6_BITS_PLAYBACK_BUFFER)) { |
| 216 | line6_wait_clear_audio_out_urbs(line6pcm); |
| 217 | line6_free_playback_buffer(line6pcm); |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 218 | } |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 219 | |
| 220 | return 0; |
| 221 | } |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 222 | EXPORT_SYMBOL_GPL(line6_pcm_release); |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 223 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 224 | /* trigger callback */ |
| 225 | int snd_line6_trigger(struct snd_pcm_substream *substream, int cmd) |
| 226 | { |
| 227 | struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 228 | struct snd_pcm_substream *s; |
| 229 | int err; |
| 230 | unsigned long flags; |
| 231 | |
| 232 | spin_lock_irqsave(&line6pcm->lock_trigger, flags); |
Markus Grabner | 0ca5488 | 2012-01-20 00:09:09 +0100 | [diff] [blame] | 233 | clear_bit(LINE6_INDEX_PREPARED, &line6pcm->flags); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 234 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 235 | snd_pcm_group_for_each_entry(s, substream) { |
Takashi Iwai | 7d70c81 | 2015-01-19 15:11:17 +0100 | [diff] [blame^] | 236 | if (s->pcm->card != substream->pcm->card) |
| 237 | continue; |
Greg Kroah-Hartman | 68dc3dd | 2009-02-27 22:43:30 -0800 | [diff] [blame] | 238 | switch (s->stream) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 239 | case SNDRV_PCM_STREAM_PLAYBACK: |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 240 | err = snd_line6_playback_trigger(line6pcm, cmd); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 241 | |
Greg Kroah-Hartman | 68dc3dd | 2009-02-27 22:43:30 -0800 | [diff] [blame] | 242 | if (err < 0) { |
| 243 | spin_unlock_irqrestore(&line6pcm->lock_trigger, |
| 244 | flags); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 245 | return err; |
| 246 | } |
| 247 | |
| 248 | break; |
| 249 | |
| 250 | case SNDRV_PCM_STREAM_CAPTURE: |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 251 | err = snd_line6_capture_trigger(line6pcm, cmd); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 252 | |
Greg Kroah-Hartman | 68dc3dd | 2009-02-27 22:43:30 -0800 | [diff] [blame] | 253 | if (err < 0) { |
| 254 | spin_unlock_irqrestore(&line6pcm->lock_trigger, |
| 255 | flags); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 256 | return err; |
| 257 | } |
| 258 | |
| 259 | break; |
| 260 | |
| 261 | default: |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 262 | dev_err(line6pcm->line6->ifcdev, |
| 263 | "Unknown stream direction %d\n", s->stream); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 264 | } |
| 265 | } |
| 266 | |
| 267 | spin_unlock_irqrestore(&line6pcm->lock_trigger, flags); |
| 268 | return 0; |
| 269 | } |
| 270 | |
| 271 | /* control info callback */ |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 272 | static int snd_line6_control_playback_info(struct snd_kcontrol *kcontrol, |
| 273 | struct snd_ctl_elem_info *uinfo) |
Greg Kroah-Hartman | 68dc3dd | 2009-02-27 22:43:30 -0800 | [diff] [blame] | 274 | { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 275 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 276 | uinfo->count = 2; |
| 277 | uinfo->value.integer.min = 0; |
| 278 | uinfo->value.integer.max = 256; |
| 279 | return 0; |
| 280 | } |
| 281 | |
| 282 | /* control get callback */ |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 283 | static int snd_line6_control_playback_get(struct snd_kcontrol *kcontrol, |
| 284 | struct snd_ctl_elem_value *ucontrol) |
Greg Kroah-Hartman | 68dc3dd | 2009-02-27 22:43:30 -0800 | [diff] [blame] | 285 | { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 286 | int i; |
| 287 | struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol); |
| 288 | |
Greg Kroah-Hartman | 68dc3dd | 2009-02-27 22:43:30 -0800 | [diff] [blame] | 289 | for (i = 2; i--;) |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 290 | ucontrol->value.integer.value[i] = line6pcm->volume_playback[i]; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 291 | |
| 292 | return 0; |
| 293 | } |
| 294 | |
| 295 | /* control put callback */ |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 296 | static int snd_line6_control_playback_put(struct snd_kcontrol *kcontrol, |
| 297 | struct snd_ctl_elem_value *ucontrol) |
Greg Kroah-Hartman | 68dc3dd | 2009-02-27 22:43:30 -0800 | [diff] [blame] | 298 | { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 299 | int i, changed = 0; |
| 300 | struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol); |
| 301 | |
Greg Kroah-Hartman | 68dc3dd | 2009-02-27 22:43:30 -0800 | [diff] [blame] | 302 | for (i = 2; i--;) |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 303 | if (line6pcm->volume_playback[i] != |
| 304 | ucontrol->value.integer.value[i]) { |
| 305 | line6pcm->volume_playback[i] = |
| 306 | ucontrol->value.integer.value[i]; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 307 | changed = 1; |
| 308 | } |
| 309 | |
| 310 | return changed; |
| 311 | } |
| 312 | |
| 313 | /* control definition */ |
Takashi Iwai | 075587b | 2015-01-19 14:28:25 +0100 | [diff] [blame] | 314 | static struct snd_kcontrol_new line6_controls[] = { |
| 315 | { |
| 316 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 317 | .name = "PCM Playback Volume", |
| 318 | .info = snd_line6_control_playback_info, |
| 319 | .get = snd_line6_control_playback_get, |
| 320 | .put = snd_line6_control_playback_put |
| 321 | }, |
| 322 | { |
| 323 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 324 | .name = "Impulse Response Volume", |
| 325 | .info = snd_line6_impulse_volume_info, |
| 326 | .get = snd_line6_impulse_volume_get, |
| 327 | .put = snd_line6_impulse_volume_put |
| 328 | }, |
| 329 | { |
| 330 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 331 | .name = "Impulse Response Period", |
| 332 | .info = snd_line6_impulse_period_info, |
| 333 | .get = snd_line6_impulse_period_get, |
| 334 | .put = snd_line6_impulse_period_put |
| 335 | }, |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 336 | }; |
| 337 | |
| 338 | /* |
| 339 | Cleanup the PCM device. |
| 340 | */ |
| 341 | static void line6_cleanup_pcm(struct snd_pcm *pcm) |
| 342 | { |
| 343 | int i; |
| 344 | struct snd_line6_pcm *line6pcm = snd_pcm_chip(pcm); |
| 345 | |
Greg Kroah-Hartman | 68dc3dd | 2009-02-27 22:43:30 -0800 | [diff] [blame] | 346 | for (i = LINE6_ISO_BUFFERS; i--;) { |
| 347 | if (line6pcm->urb_audio_out[i]) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 348 | usb_kill_urb(line6pcm->urb_audio_out[i]); |
| 349 | usb_free_urb(line6pcm->urb_audio_out[i]); |
| 350 | } |
Greg Kroah-Hartman | 68dc3dd | 2009-02-27 22:43:30 -0800 | [diff] [blame] | 351 | if (line6pcm->urb_audio_in[i]) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 352 | usb_kill_urb(line6pcm->urb_audio_in[i]); |
| 353 | usb_free_urb(line6pcm->urb_audio_in[i]); |
| 354 | } |
| 355 | } |
Takashi Iwai | b45a7c5 | 2015-01-19 14:41:57 +0100 | [diff] [blame] | 356 | kfree(line6pcm); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | /* create a PCM device */ |
Takashi Iwai | b45a7c5 | 2015-01-19 14:41:57 +0100 | [diff] [blame] | 360 | static int snd_line6_new_pcm(struct usb_line6 *line6, struct snd_pcm **pcm_ret) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 361 | { |
| 362 | struct snd_pcm *pcm; |
| 363 | int err; |
| 364 | |
Takashi Iwai | b45a7c5 | 2015-01-19 14:41:57 +0100 | [diff] [blame] | 365 | err = snd_pcm_new(line6->card, (char *)line6->properties->name, |
| 366 | 0, 1, 1, pcm_ret); |
Greg Kroah-Hartman | 68dc3dd | 2009-02-27 22:43:30 -0800 | [diff] [blame] | 367 | if (err < 0) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 368 | return err; |
Takashi Iwai | b45a7c5 | 2015-01-19 14:41:57 +0100 | [diff] [blame] | 369 | pcm = *pcm_ret; |
| 370 | strcpy(pcm->name, line6->properties->name); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 371 | |
| 372 | /* set operators */ |
Shawn Bohrer | afb9091 | 2009-11-15 22:17:57 -0600 | [diff] [blame] | 373 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, |
| 374 | &snd_line6_playback_ops); |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 375 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_line6_capture_ops); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 376 | |
| 377 | /* pre-allocation of buffers */ |
Greg Kroah-Hartman | 68dc3dd | 2009-02-27 22:43:30 -0800 | [diff] [blame] | 378 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS, |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 379 | snd_dma_continuous_data |
| 380 | (GFP_KERNEL), 64 * 1024, |
| 381 | 128 * 1024); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 382 | return 0; |
| 383 | } |
| 384 | |
| 385 | /* |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 386 | Stop substream if still running. |
| 387 | */ |
| 388 | static void pcm_disconnect_substream(struct snd_pcm_substream *substream) |
| 389 | { |
Takashi Iwai | 86f0b5b | 2013-07-11 18:02:38 +0200 | [diff] [blame] | 390 | if (substream->runtime && snd_pcm_running(substream)) { |
| 391 | snd_pcm_stream_lock_irq(substream); |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 392 | snd_pcm_stop(substream, SNDRV_PCM_STATE_DISCONNECTED); |
Takashi Iwai | 86f0b5b | 2013-07-11 18:02:38 +0200 | [diff] [blame] | 393 | snd_pcm_stream_unlock_irq(substream); |
| 394 | } |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | /* |
| 398 | Stop PCM stream. |
| 399 | */ |
| 400 | void line6_pcm_disconnect(struct snd_line6_pcm *line6pcm) |
| 401 | { |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 402 | pcm_disconnect_substream(get_substream |
| 403 | (line6pcm, SNDRV_PCM_STREAM_CAPTURE)); |
| 404 | pcm_disconnect_substream(get_substream |
| 405 | (line6pcm, SNDRV_PCM_STREAM_PLAYBACK)); |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 406 | line6_unlink_wait_clear_audio_out_urbs(line6pcm); |
| 407 | line6_unlink_wait_clear_audio_in_urbs(line6pcm); |
| 408 | } |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 409 | EXPORT_SYMBOL_GPL(line6_pcm_disconnect); |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 410 | |
| 411 | /* |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 412 | Create and register the PCM device and mixer entries. |
| 413 | Create URBs for playback and capture. |
| 414 | */ |
Greg Kroah-Hartman | 68dc3dd | 2009-02-27 22:43:30 -0800 | [diff] [blame] | 415 | int line6_init_pcm(struct usb_line6 *line6, |
| 416 | struct line6_pcm_properties *properties) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 417 | { |
Takashi Iwai | 075587b | 2015-01-19 14:28:25 +0100 | [diff] [blame] | 418 | int i, err; |
Chris Rorvick | 16d603d | 2015-01-12 12:42:55 -0800 | [diff] [blame] | 419 | unsigned ep_read = line6->properties->ep_audio_r; |
| 420 | unsigned ep_write = line6->properties->ep_audio_w; |
Takashi Iwai | b45a7c5 | 2015-01-19 14:41:57 +0100 | [diff] [blame] | 421 | struct snd_pcm *pcm; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 422 | struct snd_line6_pcm *line6pcm; |
| 423 | |
Chris Rorvick | 4cb1a4a | 2015-01-12 12:42:45 -0800 | [diff] [blame] | 424 | if (!(line6->properties->capabilities & LINE6_CAP_PCM)) |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 425 | return 0; /* skip PCM initialization and report success */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 426 | |
Takashi Iwai | b45a7c5 | 2015-01-19 14:41:57 +0100 | [diff] [blame] | 427 | err = snd_line6_new_pcm(line6, &pcm); |
| 428 | if (err < 0) |
| 429 | return err; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 430 | |
Takashi Iwai | b45a7c5 | 2015-01-19 14:41:57 +0100 | [diff] [blame] | 431 | line6pcm = kzalloc(sizeof(*line6pcm), GFP_KERNEL); |
| 432 | if (!line6pcm) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 433 | return -ENOMEM; |
| 434 | |
Takashi Iwai | b45a7c5 | 2015-01-19 14:41:57 +0100 | [diff] [blame] | 435 | line6pcm->pcm = pcm; |
| 436 | line6pcm->properties = properties; |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 437 | line6pcm->volume_playback[0] = line6pcm->volume_playback[1] = 255; |
| 438 | line6pcm->volume_monitor = 255; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 439 | line6pcm->line6 = line6; |
Stefan Hajnoczi | 3b08db3 | 2011-11-23 08:20:44 +0000 | [diff] [blame] | 440 | |
| 441 | /* Read and write buffers are sized identically, so choose minimum */ |
| 442 | line6pcm->max_packet_size = min( |
| 443 | usb_maxpacket(line6->usbdev, |
| 444 | usb_rcvisocpipe(line6->usbdev, ep_read), 0), |
| 445 | usb_maxpacket(line6->usbdev, |
| 446 | usb_sndisocpipe(line6->usbdev, ep_write), 1)); |
| 447 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 448 | spin_lock_init(&line6pcm->lock_audio_out); |
| 449 | spin_lock_init(&line6pcm->lock_audio_in); |
| 450 | spin_lock_init(&line6pcm->lock_trigger); |
Takashi Iwai | 075587b | 2015-01-19 14:28:25 +0100 | [diff] [blame] | 451 | line6pcm->impulse_period = LINE6_IMPULSE_DEFAULT_PERIOD; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 452 | |
Takashi Iwai | b45a7c5 | 2015-01-19 14:41:57 +0100 | [diff] [blame] | 453 | line6->line6pcm = line6pcm; |
| 454 | |
| 455 | pcm->private_data = line6pcm; |
| 456 | pcm->private_free = line6_cleanup_pcm; |
| 457 | |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 458 | err = line6_create_audio_out_urbs(line6pcm); |
Greg Kroah-Hartman | 68dc3dd | 2009-02-27 22:43:30 -0800 | [diff] [blame] | 459 | if (err < 0) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 460 | return err; |
| 461 | |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 462 | err = line6_create_audio_in_urbs(line6pcm); |
Greg Kroah-Hartman | 68dc3dd | 2009-02-27 22:43:30 -0800 | [diff] [blame] | 463 | if (err < 0) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 464 | return err; |
| 465 | |
| 466 | /* mixer: */ |
Takashi Iwai | 075587b | 2015-01-19 14:28:25 +0100 | [diff] [blame] | 467 | for (i = 0; i < ARRAY_SIZE(line6_controls); i++) { |
| 468 | err = snd_ctl_add(line6->card, |
| 469 | snd_ctl_new1(&line6_controls[i], line6pcm)); |
| 470 | if (err < 0) |
| 471 | return err; |
| 472 | } |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 473 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 474 | return 0; |
| 475 | } |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 476 | EXPORT_SYMBOL_GPL(line6_init_pcm); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 477 | |
| 478 | /* prepare pcm callback */ |
| 479 | int snd_line6_prepare(struct snd_pcm_substream *substream) |
| 480 | { |
| 481 | struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream); |
| 482 | |
Stefan Hajnoczi | 665f3f5 | 2011-12-10 02:12:31 +0100 | [diff] [blame] | 483 | switch (substream->stream) { |
| 484 | case SNDRV_PCM_STREAM_PLAYBACK: |
Markus Grabner | 0ca5488 | 2012-01-20 00:09:09 +0100 | [diff] [blame] | 485 | if ((line6pcm->flags & LINE6_BITS_PLAYBACK_STREAM) == 0) |
Markus Grabner | 6b02a17e | 2011-12-10 02:12:32 +0100 | [diff] [blame] | 486 | line6_unlink_wait_clear_audio_out_urbs(line6pcm); |
| 487 | |
Stefan Hajnoczi | 665f3f5 | 2011-12-10 02:12:31 +0100 | [diff] [blame] | 488 | break; |
| 489 | |
| 490 | case SNDRV_PCM_STREAM_CAPTURE: |
Markus Grabner | 0ca5488 | 2012-01-20 00:09:09 +0100 | [diff] [blame] | 491 | if ((line6pcm->flags & LINE6_BITS_CAPTURE_STREAM) == 0) |
Markus Grabner | 6b02a17e | 2011-12-10 02:12:32 +0100 | [diff] [blame] | 492 | line6_unlink_wait_clear_audio_in_urbs(line6pcm); |
| 493 | |
Stefan Hajnoczi | 665f3f5 | 2011-12-10 02:12:31 +0100 | [diff] [blame] | 494 | break; |
| 495 | |
| 496 | default: |
| 497 | MISSING_CASE; |
| 498 | } |
| 499 | |
Markus Grabner | 0ca5488 | 2012-01-20 00:09:09 +0100 | [diff] [blame] | 500 | if (!test_and_set_bit(LINE6_INDEX_PREPARED, &line6pcm->flags)) { |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 501 | line6pcm->count_out = 0; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 502 | line6pcm->pos_out = 0; |
| 503 | line6pcm->pos_out_done = 0; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 504 | line6pcm->bytes_out = 0; |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 505 | line6pcm->count_in = 0; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 506 | line6pcm->pos_in_done = 0; |
| 507 | line6pcm->bytes_in = 0; |
| 508 | } |
| 509 | |
| 510 | return 0; |
| 511 | } |