Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'for-next' into for-linus

+1452 -1050
+8 -18
Documentation/sound/alsa/HD-Audio.txt
··· 655 655 and next kernels are found in for-linus and for-next branches, 656 656 respectively. 657 657 658 - If you are using the latest Linus tree, it'd be better to pull the 659 - above GIT tree onto it. If you are using the older kernels, an easy 660 - way to try the latest ALSA code is to build from the snapshot 661 - tarball. There are daily tarballs and the latest snapshot tarball. 662 - All can be built just like normal alsa-driver release packages, that 663 - is, installed via the usual spells: configure, make and make 664 - install(-modules). See INSTALL in the package. The snapshot tarballs 665 - are found at: 666 - 667 - - ftp://ftp.suse.com/pub/people/tiwai/snapshot/ 668 - 669 658 670 659 Sending a Bug Report 671 660 ~~~~~~~~~~~~~~~~~~~~ ··· 688 699 alsa-info 689 700 ~~~~~~~~~ 690 701 The script `alsa-info.sh` is a very useful tool to gather the audio 691 - device information. You can fetch the latest version from: 702 + device information. It's included in alsa-utils package. The latest 703 + version can be found on git repository: 704 + 705 + - git://git.alsa-project.org/alsa-utils.git 706 + 707 + The script can be fetched directly from the following URL, too: 692 708 693 709 - http://www.alsa-project.org/alsa-info.sh 694 710 ··· 830 836 (mixer) elements, set/get the control element value, simulate the PCM 831 837 operation, the jack plugging simulation, etc. 832 838 833 - The package is found in: 834 - 835 - - ftp://ftp.suse.com/pub/people/tiwai/misc/ 836 - 837 - A git repository is available: 839 + The program is found in the git repository below: 838 840 839 841 - git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/hda-emu.git 840 842 841 - See README file in the tarball for more details about hda-emu 843 + See README file in the repository for more details about hda-emu 842 844 program. 843 845 844 846
+2 -2
Documentation/sound/alsa/compress_offload.txt
··· 149 149 ================ 150 150 When playing thru an album, the decoders have the ability to skip the encoder 151 151 delay and padding and directly move from one track content to another. The end 152 - user can perceive this as gapless playback as we dont have silence while 152 + user can perceive this as gapless playback as we don't have silence while 153 153 switching from one track to another 154 154 155 155 Also, there might be low-intensity noises due to encoding. Perfect gapless is ··· 184 184 - Fill data of the first track 185 185 - Trigger start 186 186 - User-space finished sending all, 187 - - Indicaite next track data by sending set_next_track 187 + - Indicate next track data by sending set_next_track 188 188 - Set metadata of the next track 189 189 - then call partial_drain to flush most of buffer in DSP 190 190 - Fill data of the next track
+1 -1
Documentation/sound/alsa/soc/dapm.txt
··· 132 132 SND_SOC_DAPM_MIXER("Output Mixer", WM8731_PWR, 4, 1, wm8731_output_mixer_controls, 133 133 ARRAY_SIZE(wm8731_output_mixer_controls)), 134 134 135 - If you dont want the mixer elements prefixed with the name of the mixer widget, 135 + If you don't want the mixer elements prefixed with the name of the mixer widget, 136 136 you can use SND_SOC_DAPM_MIXER_NAMED_CTL instead. the parameters are the same 137 137 as for SND_SOC_DAPM_MIXER. 138 138
+1 -1
Documentation/sound/alsa/soc/overview.txt
··· 63 63 and any audio DSP drivers for that platform. 64 64 65 65 * Machine class driver: The machine driver class acts as the glue that 66 - decribes and binds the other component drivers together to form an ALSA 66 + describes and binds the other component drivers together to form an ALSA 67 67 "sound card device". It handles any machine specific controls and 68 68 machine level audio events (e.g. turning on an amp at start of playback). 69 69
+1 -1
Documentation/sound/alsa/timestamping.txt
··· 129 129 interpolation of the results 130 130 131 131 In some hardware-specific configuration, the system timestamp is 132 - latched by a low-level audio subsytem, and the information provided 132 + latched by a low-level audio subsystem, and the information provided 133 133 back to the driver. Due to potential delays in the communication with 134 134 the hardware, there is a risk of misalignment with the avail and delay 135 135 information. To make sure applications are not confused, a
+2
include/sound/hda_chmap.h
··· 36 36 int (*chmap_validate)(struct hdac_chmap *hchmap, int ca, 37 37 int channels, unsigned char *chmap); 38 38 39 + int (*get_spk_alloc)(struct hdac_device *hdac, int pcm_idx); 40 + 39 41 void (*get_chmap)(struct hdac_device *hdac, int pcm_idx, 40 42 unsigned char *chmap); 41 43 void (*set_chmap)(struct hdac_device *hdac, int pcm_idx,
+5 -5
include/sound/hda_i915.h
··· 10 10 int snd_hdac_set_codec_wakeup(struct hdac_bus *bus, bool enable); 11 11 int snd_hdac_display_power(struct hdac_bus *bus, bool enable); 12 12 void snd_hdac_i915_set_bclk(struct hdac_bus *bus); 13 - int snd_hdac_sync_audio_rate(struct hdac_bus *bus, hda_nid_t nid, int rate); 14 - int snd_hdac_acomp_get_eld(struct hdac_bus *bus, hda_nid_t nid, 13 + int snd_hdac_sync_audio_rate(struct hdac_device *codec, hda_nid_t nid, int rate); 14 + int snd_hdac_acomp_get_eld(struct hdac_device *codec, hda_nid_t nid, 15 15 bool *audio_enabled, char *buffer, int max_bytes); 16 16 int snd_hdac_i915_init(struct hdac_bus *bus); 17 17 int snd_hdac_i915_exit(struct hdac_bus *bus); ··· 28 28 static inline void snd_hdac_i915_set_bclk(struct hdac_bus *bus) 29 29 { 30 30 } 31 - static inline int snd_hdac_sync_audio_rate(struct hdac_bus *bus, hda_nid_t nid, 32 - int rate) 31 + static inline int snd_hdac_sync_audio_rate(struct hdac_device *codec, 32 + hda_nid_t nid, int rate) 33 33 { 34 34 return 0; 35 35 } 36 - static inline int snd_hdac_acomp_get_eld(struct hdac_bus *bus, hda_nid_t nid, 36 + static inline int snd_hdac_acomp_get_eld(struct hdac_device *codec, hda_nid_t nid, 37 37 bool *audio_enabled, char *buffer, 38 38 int max_bytes) 39 39 {
+1 -1
include/uapi/sound/asound.h
··· 672 672 673 673 /* global timers (device member) */ 674 674 #define SNDRV_TIMER_GLOBAL_SYSTEM 0 675 - #define SNDRV_TIMER_GLOBAL_RTC 1 675 + #define SNDRV_TIMER_GLOBAL_RTC 1 /* unused */ 676 676 #define SNDRV_TIMER_GLOBAL_HPET 2 677 677 #define SNDRV_TIMER_GLOBAL_HRTIMER 3 678 678
-29
sound/core/Kconfig
··· 141 141 Say Y here to use the HR-timer backend as the default sequencer 142 142 timer. 143 143 144 - config SND_RTCTIMER 145 - tristate "RTC Timer support" 146 - depends on RTC 147 - select SND_TIMER 148 - help 149 - Say Y here to enable RTC timer support for ALSA. ALSA uses 150 - the RTC timer as a precise timing source and maps the RTC 151 - timer to ALSA's timer interface. The ALSA sequencer code also 152 - can use this timing source. 153 - 154 - To compile this driver as a module, choose M here: the module 155 - will be called snd-rtctimer. 156 - 157 - Note that this option is exclusive with the new RTC drivers 158 - (CONFIG_RTC_CLASS) since this requires the old API. 159 - 160 - config SND_SEQ_RTCTIMER_DEFAULT 161 - bool "Use RTC as default sequencer timer" 162 - depends on SND_RTCTIMER && SND_SEQUENCER 163 - depends on !SND_SEQ_HRTIMER_DEFAULT 164 - default y 165 - help 166 - Say Y here to use the RTC timer as the default sequencer 167 - timer. This is strongly recommended because it ensures 168 - precise MIDI timing even when the system timer runs at less 169 - than 1000 Hz. 170 - 171 - If in doubt, say Y. 172 - 173 144 config SND_DYNAMIC_MINORS 174 145 bool "Dynamic device file minor numbers" 175 146 help
-1
sound/core/Makefile
··· 37 37 obj-$(CONFIG_SND_HWDEP) += snd-hwdep.o 38 38 obj-$(CONFIG_SND_TIMER) += snd-timer.o 39 39 obj-$(CONFIG_SND_HRTIMER) += snd-hrtimer.o 40 - obj-$(CONFIG_SND_RTCTIMER) += snd-rtctimer.o 41 40 obj-$(CONFIG_SND_PCM) += snd-pcm.o 42 41 obj-$(CONFIG_SND_DMAENGINE_PCM) += snd-pcm-dmaengine.o 43 42 obj-$(CONFIG_SND_RAWMIDI) += snd-rawmidi.o
+12 -13
sound/core/compress_offload.c
··· 288 288 stream = &data->stream; 289 289 mutex_lock(&stream->device->lock); 290 290 /* write is allowed when stream is running or has been steup */ 291 - if (stream->runtime->state != SNDRV_PCM_STATE_SETUP && 292 - stream->runtime->state != SNDRV_PCM_STATE_PREPARED && 293 - stream->runtime->state != SNDRV_PCM_STATE_RUNNING) { 291 + switch (stream->runtime->state) { 292 + case SNDRV_PCM_STATE_SETUP: 293 + case SNDRV_PCM_STATE_PREPARED: 294 + case SNDRV_PCM_STATE_RUNNING: 295 + break; 296 + default: 294 297 mutex_unlock(&stream->device->lock); 295 298 return -EBADFD; 296 299 } ··· 394 391 int retval = 0; 395 392 396 393 if (snd_BUG_ON(!data)) 397 - return -EFAULT; 394 + return POLLERR; 395 + 398 396 stream = &data->stream; 399 - if (snd_BUG_ON(!stream)) 400 - return -EFAULT; 401 397 402 398 mutex_lock(&stream->device->lock); 403 399 if (stream->runtime->state == SNDRV_PCM_STATE_OPEN) { 404 - retval = -EBADFD; 400 + retval = snd_compr_get_poll(stream) | POLLERR; 405 401 goto out; 406 402 } 407 403 poll_wait(f, &stream->runtime->sleep, wait); ··· 423 421 retval = snd_compr_get_poll(stream); 424 422 break; 425 423 default: 426 - if (stream->direction == SND_COMPRESS_PLAYBACK) 427 - retval = POLLOUT | POLLWRNORM | POLLERR; 428 - else 429 - retval = POLLIN | POLLRDNORM | POLLERR; 424 + retval = snd_compr_get_poll(stream) | POLLERR; 430 425 break; 431 426 } 432 427 out: ··· 801 802 802 803 if (snd_BUG_ON(!data)) 803 804 return -EFAULT; 805 + 804 806 stream = &data->stream; 805 - if (snd_BUG_ON(!stream)) 806 - return -EFAULT; 807 + 807 808 mutex_lock(&stream->device->lock); 808 809 switch (_IOC_NR(cmd)) { 809 810 case _IOC_NR(SNDRV_COMPRESS_IOCTL_VERSION):
+37 -15
sound/core/hrtimer.c
··· 38 38 struct snd_hrtimer { 39 39 struct snd_timer *timer; 40 40 struct hrtimer hrt; 41 - atomic_t running; 41 + bool in_callback; 42 42 }; 43 43 44 44 static enum hrtimer_restart snd_hrtimer_callback(struct hrtimer *hrt) 45 45 { 46 46 struct snd_hrtimer *stime = container_of(hrt, struct snd_hrtimer, hrt); 47 47 struct snd_timer *t = stime->timer; 48 - unsigned long oruns; 48 + ktime_t delta; 49 + unsigned long ticks; 50 + enum hrtimer_restart ret = HRTIMER_NORESTART; 49 51 50 - if (!atomic_read(&stime->running)) 51 - return HRTIMER_NORESTART; 52 + spin_lock(&t->lock); 53 + if (!t->running) 54 + goto out; /* fast path */ 55 + stime->in_callback = true; 56 + ticks = t->sticks; 57 + spin_unlock(&t->lock); 52 58 53 - oruns = hrtimer_forward_now(hrt, ns_to_ktime(t->sticks * resolution)); 54 - snd_timer_interrupt(stime->timer, t->sticks * oruns); 59 + /* calculate the drift */ 60 + delta = ktime_sub(hrt->base->get_time(), hrtimer_get_expires(hrt)); 61 + if (delta.tv64 > 0) 62 + ticks += ktime_divns(delta, ticks * resolution); 55 63 56 - if (!atomic_read(&stime->running)) 57 - return HRTIMER_NORESTART; 58 - return HRTIMER_RESTART; 64 + snd_timer_interrupt(stime->timer, ticks); 65 + 66 + spin_lock(&t->lock); 67 + if (t->running) { 68 + hrtimer_add_expires_ns(hrt, t->sticks * resolution); 69 + ret = HRTIMER_RESTART; 70 + } 71 + 72 + stime->in_callback = false; 73 + out: 74 + spin_unlock(&t->lock); 75 + return ret; 59 76 } 60 77 61 78 static int snd_hrtimer_open(struct snd_timer *t) 62 79 { 63 80 struct snd_hrtimer *stime; 64 81 65 - stime = kmalloc(sizeof(*stime), GFP_KERNEL); 82 + stime = kzalloc(sizeof(*stime), GFP_KERNEL); 66 83 if (!stime) 67 84 return -ENOMEM; 68 85 hrtimer_init(&stime->hrt, CLOCK_MONOTONIC, HRTIMER_MODE_REL); 69 86 stime->timer = t; 70 87 stime->hrt.function = snd_hrtimer_callback; 71 - atomic_set(&stime->running, 0); 72 88 t->private_data = stime; 73 89 return 0; 74 90 } ··· 94 78 struct snd_hrtimer *stime = t->private_data; 95 79 96 80 if (stime) { 81 + spin_lock_irq(&t->lock); 82 + t->running = 0; /* just to be sure */ 83 + stime->in_callback = 1; /* skip start/stop */ 84 + spin_unlock_irq(&t->lock); 85 + 97 86 hrtimer_cancel(&stime->hrt); 98 87 kfree(stime); 99 88 t->private_data = NULL; ··· 110 89 { 111 90 struct snd_hrtimer *stime = t->private_data; 112 91 113 - atomic_set(&stime->running, 0); 114 - hrtimer_try_to_cancel(&stime->hrt); 92 + if (stime->in_callback) 93 + return 0; 115 94 hrtimer_start(&stime->hrt, ns_to_ktime(t->sticks * resolution), 116 95 HRTIMER_MODE_REL); 117 - atomic_set(&stime->running, 1); 118 96 return 0; 119 97 } 120 98 121 99 static int snd_hrtimer_stop(struct snd_timer *t) 122 100 { 123 101 struct snd_hrtimer *stime = t->private_data; 124 - atomic_set(&stime->running, 0); 102 + 103 + if (stime->in_callback) 104 + return 0; 125 105 hrtimer_try_to_cancel(&stime->hrt); 126 106 return 0; 127 107 }
+3 -1
sound/core/pcm_lib.c
··· 1886 1886 snd_timer_interrupt(substream->timer, 1); 1887 1887 #endif 1888 1888 _end: 1889 - snd_pcm_stream_unlock_irqrestore(substream, flags); 1890 1889 kill_fasync(&runtime->fasync, SIGIO, POLL_IN); 1890 + snd_pcm_stream_unlock_irqrestore(substream, flags); 1891 1891 } 1892 1892 1893 1893 EXPORT_SYMBOL(snd_pcm_period_elapsed); ··· 2595 2595 }; 2596 2596 int err; 2597 2597 2598 + if (WARN_ON(pcm->streams[stream].chmap_kctl)) 2599 + return -EBUSY; 2598 2600 info = kzalloc(sizeof(*info), GFP_KERNEL); 2599 2601 if (!info) 2600 2602 return -ENOMEM;
+2 -2
sound/core/pcm_native.c
··· 3161 3161 3162 3162 substream = pcm_file->substream; 3163 3163 if (PCM_RUNTIME_CHECK(substream)) 3164 - return -ENXIO; 3164 + return POLLOUT | POLLWRNORM | POLLERR; 3165 3165 runtime = substream->runtime; 3166 3166 3167 3167 poll_wait(file, &runtime->sleep, wait); ··· 3200 3200 3201 3201 substream = pcm_file->substream; 3202 3202 if (PCM_RUNTIME_CHECK(substream)) 3203 - return -ENXIO; 3203 + return POLLIN | POLLRDNORM | POLLERR; 3204 3204 runtime = substream->runtime; 3205 3205 3206 3206 poll_wait(file, &runtime->sleep, wait);
-187
sound/core/rtctimer.c
··· 1 - /* 2 - * RTC based high-frequency timer 3 - * 4 - * Copyright (C) 2000 Takashi Iwai 5 - * based on rtctimer.c by Steve Ratcliffe 6 - * 7 - * This program is free software; you can redistribute it and/or modify 8 - * it under the terms of the GNU General Public License as published by 9 - * the Free Software Foundation; either version 2 of the License, or 10 - * (at your option) any later version. 11 - * 12 - * This program is distributed in the hope that it will be useful, 13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 - * GNU General Public License for more details. 16 - * 17 - * You should have received a copy of the GNU General Public License 18 - * along with this program; if not, write to the Free Software 19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 - * 21 - */ 22 - 23 - #include <linux/init.h> 24 - #include <linux/interrupt.h> 25 - #include <linux/module.h> 26 - #include <linux/log2.h> 27 - #include <sound/core.h> 28 - #include <sound/timer.h> 29 - 30 - #if IS_ENABLED(CONFIG_RTC) 31 - 32 - #include <linux/mc146818rtc.h> 33 - 34 - #define RTC_FREQ 1024 /* default frequency */ 35 - #define NANO_SEC 1000000000L /* 10^9 in sec */ 36 - 37 - /* 38 - * prototypes 39 - */ 40 - static int rtctimer_open(struct snd_timer *t); 41 - static int rtctimer_close(struct snd_timer *t); 42 - static int rtctimer_start(struct snd_timer *t); 43 - static int rtctimer_stop(struct snd_timer *t); 44 - 45 - 46 - /* 47 - * The hardware dependent description for this timer. 48 - */ 49 - static struct snd_timer_hardware rtc_hw = { 50 - .flags = SNDRV_TIMER_HW_AUTO | 51 - SNDRV_TIMER_HW_FIRST | 52 - SNDRV_TIMER_HW_TASKLET, 53 - .ticks = 100000000L, /* FIXME: XXX */ 54 - .open = rtctimer_open, 55 - .close = rtctimer_close, 56 - .start = rtctimer_start, 57 - .stop = rtctimer_stop, 58 - }; 59 - 60 - static int rtctimer_freq = RTC_FREQ; /* frequency */ 61 - static struct snd_timer *rtctimer; 62 - static struct tasklet_struct rtc_tasklet; 63 - static rtc_task_t rtc_task; 64 - 65 - 66 - static int 67 - rtctimer_open(struct snd_timer *t) 68 - { 69 - int err; 70 - 71 - err = rtc_register(&rtc_task); 72 - if (err < 0) 73 - return err; 74 - t->private_data = &rtc_task; 75 - return 0; 76 - } 77 - 78 - static int 79 - rtctimer_close(struct snd_timer *t) 80 - { 81 - rtc_task_t *rtc = t->private_data; 82 - if (rtc) { 83 - rtc_unregister(rtc); 84 - tasklet_kill(&rtc_tasklet); 85 - t->private_data = NULL; 86 - } 87 - return 0; 88 - } 89 - 90 - static int 91 - rtctimer_start(struct snd_timer *timer) 92 - { 93 - rtc_task_t *rtc = timer->private_data; 94 - if (snd_BUG_ON(!rtc)) 95 - return -EINVAL; 96 - rtc_control(rtc, RTC_IRQP_SET, rtctimer_freq); 97 - rtc_control(rtc, RTC_PIE_ON, 0); 98 - return 0; 99 - } 100 - 101 - static int 102 - rtctimer_stop(struct snd_timer *timer) 103 - { 104 - rtc_task_t *rtc = timer->private_data; 105 - if (snd_BUG_ON(!rtc)) 106 - return -EINVAL; 107 - rtc_control(rtc, RTC_PIE_OFF, 0); 108 - return 0; 109 - } 110 - 111 - static void rtctimer_tasklet(unsigned long data) 112 - { 113 - snd_timer_interrupt((struct snd_timer *)data, 1); 114 - } 115 - 116 - /* 117 - * interrupt 118 - */ 119 - static void rtctimer_interrupt(void *private_data) 120 - { 121 - tasklet_schedule(private_data); 122 - } 123 - 124 - 125 - /* 126 - * ENTRY functions 127 - */ 128 - static int __init rtctimer_init(void) 129 - { 130 - int err; 131 - struct snd_timer *timer; 132 - 133 - if (rtctimer_freq < 2 || rtctimer_freq > 8192 || 134 - !is_power_of_2(rtctimer_freq)) { 135 - pr_err("ALSA: rtctimer: invalid frequency %d\n", rtctimer_freq); 136 - return -EINVAL; 137 - } 138 - 139 - /* Create a new timer and set up the fields */ 140 - err = snd_timer_global_new("rtc", SNDRV_TIMER_GLOBAL_RTC, &timer); 141 - if (err < 0) 142 - return err; 143 - 144 - timer->module = THIS_MODULE; 145 - strcpy(timer->name, "RTC timer"); 146 - timer->hw = rtc_hw; 147 - timer->hw.resolution = NANO_SEC / rtctimer_freq; 148 - 149 - tasklet_init(&rtc_tasklet, rtctimer_tasklet, (unsigned long)timer); 150 - 151 - /* set up RTC callback */ 152 - rtc_task.func = rtctimer_interrupt; 153 - rtc_task.private_data = &rtc_tasklet; 154 - 155 - err = snd_timer_global_register(timer); 156 - if (err < 0) { 157 - snd_timer_global_free(timer); 158 - return err; 159 - } 160 - rtctimer = timer; /* remember this */ 161 - 162 - return 0; 163 - } 164 - 165 - static void __exit rtctimer_exit(void) 166 - { 167 - if (rtctimer) { 168 - snd_timer_global_free(rtctimer); 169 - rtctimer = NULL; 170 - } 171 - } 172 - 173 - 174 - /* 175 - * exported stuff 176 - */ 177 - module_init(rtctimer_init) 178 - module_exit(rtctimer_exit) 179 - 180 - module_param(rtctimer_freq, int, 0444); 181 - MODULE_PARM_DESC(rtctimer_freq, "timer frequency in Hz"); 182 - 183 - MODULE_LICENSE("GPL"); 184 - 185 - MODULE_ALIAS("snd-timer-" __stringify(SNDRV_TIMER_GLOBAL_RTC)); 186 - 187 - #endif /* IS_ENABLED(CONFIG_RTC) */
-2
sound/core/seq/seq.c
··· 47 47 int seq_default_timer_device = 48 48 #ifdef CONFIG_SND_SEQ_HRTIMER_DEFAULT 49 49 SNDRV_TIMER_GLOBAL_HRTIMER 50 - #elif defined(CONFIG_SND_SEQ_RTCTIMER_DEFAULT) 51 - SNDRV_TIMER_GLOBAL_RTC 52 50 #else 53 51 SNDRV_TIMER_GLOBAL_SYSTEM 54 52 #endif
+3 -2
sound/core/timer.c
··· 37 37 38 38 #if IS_ENABLED(CONFIG_SND_HRTIMER) 39 39 #define DEFAULT_TIMER_LIMIT 4 40 - #elif IS_ENABLED(CONFIG_SND_RTCTIMER) 41 - #define DEFAULT_TIMER_LIMIT 2 42 40 #else 43 41 #define DEFAULT_TIMER_LIMIT 1 44 42 #endif ··· 1223 1225 tu->tstamp = *tstamp; 1224 1226 if ((tu->filter & (1 << event)) == 0 || !tu->tread) 1225 1227 return; 1228 + memset(&r1, 0, sizeof(r1)); 1226 1229 r1.event = event; 1227 1230 r1.tstamp = *tstamp; 1228 1231 r1.val = resolution; ··· 1266 1267 } 1267 1268 if ((tu->filter & (1 << SNDRV_TIMER_EVENT_RESOLUTION)) && 1268 1269 tu->last_resolution != resolution) { 1270 + memset(&r1, 0, sizeof(r1)); 1269 1271 r1.event = SNDRV_TIMER_EVENT_RESOLUTION; 1270 1272 r1.tstamp = tstamp; 1271 1273 r1.val = resolution; ··· 1739 1739 if (tu->timeri->flags & SNDRV_TIMER_IFLG_EARLY_EVENT) { 1740 1740 if (tu->tread) { 1741 1741 struct snd_timer_tread tread; 1742 + memset(&tread, 0, sizeof(tread)); 1742 1743 tread.event = SNDRV_TIMER_EVENT_EARLY; 1743 1744 tread.tstamp.tv_sec = 0; 1744 1745 tread.tstamp.tv_nsec = 0;
+1
sound/firewire/Kconfig
··· 134 134 Say Y here to include support for TASCAM. 135 135 * FW-1884 136 136 * FW-1082 137 + * FW-1804 137 138 138 139 To compile this driver as a module, choose M here: the module 139 140 will be called snd-firewire-tascam.
+3
sound/firewire/Makefile
··· 1 + # To find a header included by define_trace.h. 2 + CFLAGS_amdtp-stream.o := -I$(src) 3 + 1 4 snd-firewire-lib-objs := lib.o iso-resources.o packets-buffer.o \ 2 5 fcp.o cmp.o amdtp-stream.o amdtp-am824.o 3 6 snd-isight-objs := isight.o
+110
sound/firewire/amdtp-stream-trace.h
··· 1 + /* 2 + * amdtp-stream-trace.h - tracepoint definitions to dump a part of packet data 3 + * 4 + * Copyright (c) 2016 Takashi Sakamoto 5 + * Licensed under the terms of the GNU General Public License, version 2. 6 + */ 7 + 8 + #undef TRACE_SYSTEM 9 + #define TRACE_SYSTEM snd_firewire_lib 10 + 11 + #if !defined(_AMDTP_STREAM_TRACE_H) || defined(TRACE_HEADER_MULTI_READ) 12 + #define _AMDTP_STREAM_TRACE_H 13 + 14 + #include <linux/tracepoint.h> 15 + 16 + TRACE_EVENT(in_packet, 17 + TP_PROTO(const struct amdtp_stream *s, u32 cycles, u32 cip_header[2], unsigned int payload_quadlets, unsigned int index), 18 + TP_ARGS(s, cycles, cip_header, payload_quadlets, index), 19 + TP_STRUCT__entry( 20 + __field(unsigned int, second) 21 + __field(unsigned int, cycle) 22 + __field(int, channel) 23 + __field(int, src) 24 + __field(int, dest) 25 + __field(u32, cip_header0) 26 + __field(u32, cip_header1) 27 + __field(unsigned int, payload_quadlets) 28 + __field(unsigned int, packet_index) 29 + __field(bool, irq) 30 + __field(unsigned int, index) 31 + ), 32 + TP_fast_assign( 33 + __entry->second = cycles / CYCLES_PER_SECOND; 34 + __entry->cycle = cycles % CYCLES_PER_SECOND; 35 + __entry->channel = s->context->channel; 36 + __entry->src = fw_parent_device(s->unit)->node_id; 37 + __entry->dest = fw_parent_device(s->unit)->card->node_id; 38 + __entry->cip_header0 = cip_header[0]; 39 + __entry->cip_header1 = cip_header[1]; 40 + __entry->payload_quadlets = payload_quadlets; 41 + __entry->packet_index = s->packet_index; 42 + __entry->irq = in_interrupt(); 43 + __entry->index = index; 44 + ), 45 + TP_printk( 46 + "%02u %04u %04x %04x %02d %08x %08x %03u %02u %01u %02u", 47 + __entry->second, 48 + __entry->cycle, 49 + __entry->src, 50 + __entry->dest, 51 + __entry->channel, 52 + __entry->cip_header0, 53 + __entry->cip_header1, 54 + __entry->payload_quadlets, 55 + __entry->packet_index, 56 + __entry->irq, 57 + __entry->index) 58 + ); 59 + 60 + TRACE_EVENT(out_packet, 61 + TP_PROTO(const struct amdtp_stream *s, u32 cycles, __be32 *cip_header, unsigned int payload_length, unsigned int index), 62 + TP_ARGS(s, cycles, cip_header, payload_length, index), 63 + TP_STRUCT__entry( 64 + __field(unsigned int, second) 65 + __field(unsigned int, cycle) 66 + __field(int, channel) 67 + __field(int, src) 68 + __field(int, dest) 69 + __field(u32, cip_header0) 70 + __field(u32, cip_header1) 71 + __field(unsigned int, payload_quadlets) 72 + __field(unsigned int, packet_index) 73 + __field(bool, irq) 74 + __field(unsigned int, index) 75 + ), 76 + TP_fast_assign( 77 + __entry->second = cycles / CYCLES_PER_SECOND; 78 + __entry->cycle = cycles % CYCLES_PER_SECOND; 79 + __entry->channel = s->context->channel; 80 + __entry->src = fw_parent_device(s->unit)->card->node_id; 81 + __entry->dest = fw_parent_device(s->unit)->node_id; 82 + __entry->cip_header0 = be32_to_cpu(cip_header[0]); 83 + __entry->cip_header1 = be32_to_cpu(cip_header[1]); 84 + __entry->payload_quadlets = payload_length / 4; 85 + __entry->packet_index = s->packet_index; 86 + __entry->irq = in_interrupt(); 87 + __entry->index = index; 88 + ), 89 + TP_printk( 90 + "%02u %04u %04x %04x %02d %08x %08x %03u %02u %01u %02u", 91 + __entry->second, 92 + __entry->cycle, 93 + __entry->src, 94 + __entry->dest, 95 + __entry->channel, 96 + __entry->cip_header0, 97 + __entry->cip_header1, 98 + __entry->payload_quadlets, 99 + __entry->packet_index, 100 + __entry->irq, 101 + __entry->index) 102 + ); 103 + 104 + #endif 105 + 106 + #undef TRACE_INCLUDE_PATH 107 + #define TRACE_INCLUDE_PATH . 108 + #undef TRACE_INCLUDE_FILE 109 + #define TRACE_INCLUDE_FILE amdtp-stream-trace 110 + #include <trace/define_trace.h>
+116 -94
sound/firewire/amdtp-stream.c
··· 19 19 #define CYCLES_PER_SECOND 8000 20 20 #define TICKS_PER_SECOND (TICKS_PER_CYCLE * CYCLES_PER_SECOND) 21 21 22 + /* Always support Linux tracing subsystem. */ 23 + #define CREATE_TRACE_POINTS 24 + #include "amdtp-stream-trace.h" 25 + 22 26 #define TRANSFER_DELAY_TICKS 0x2e00 /* 479.17 microseconds */ 23 27 24 28 /* isochronous header parameters */ ··· 91 87 92 88 init_waitqueue_head(&s->callback_wait); 93 89 s->callbacked = false; 94 - s->sync_slave = NULL; 95 90 96 91 s->fmt = fmt; 97 92 s->process_data_blocks = process_data_blocks; ··· 105 102 */ 106 103 void amdtp_stream_destroy(struct amdtp_stream *s) 107 104 { 105 + /* Not initialized. */ 106 + if (s->protocol == NULL) 107 + return; 108 + 108 109 WARN_ON(amdtp_stream_running(s)); 109 110 kfree(s->protocol); 110 111 mutex_destroy(&s->mutex); ··· 251 244 tasklet_kill(&s->period_tasklet); 252 245 s->pcm_buffer_pointer = 0; 253 246 s->pcm_period_pointer = 0; 254 - s->pointer_flush = true; 255 247 } 256 248 EXPORT_SYMBOL(amdtp_stream_pcm_prepare); 257 249 ··· 355 349 s->pcm_period_pointer += frames; 356 350 if (s->pcm_period_pointer >= pcm->runtime->period_size) { 357 351 s->pcm_period_pointer -= pcm->runtime->period_size; 358 - s->pointer_flush = false; 359 352 tasklet_hi_schedule(&s->period_tasklet); 360 353 } 361 354 } ··· 368 363 snd_pcm_period_elapsed(pcm); 369 364 } 370 365 371 - static int queue_packet(struct amdtp_stream *s, 372 - unsigned int header_length, 373 - unsigned int payload_length, bool skip) 366 + static int queue_packet(struct amdtp_stream *s, unsigned int header_length, 367 + unsigned int payload_length) 374 368 { 375 369 struct fw_iso_packet p = {0}; 376 370 int err = 0; ··· 380 376 p.interrupt = IS_ALIGNED(s->packet_index + 1, INTERRUPT_INTERVAL); 381 377 p.tag = TAG_CIP; 382 378 p.header_length = header_length; 383 - p.payload_length = (!skip) ? payload_length : 0; 384 - p.skip = skip; 379 + if (payload_length > 0) 380 + p.payload_length = payload_length; 381 + else 382 + p.skip = true; 385 383 err = fw_iso_context_queue(s->context, &p, &s->buffer.iso_buffer, 386 384 s->buffer.packets[s->packet_index].offset); 387 385 if (err < 0) { ··· 398 392 } 399 393 400 394 static inline int queue_out_packet(struct amdtp_stream *s, 401 - unsigned int payload_length, bool skip) 395 + unsigned int payload_length) 402 396 { 403 - return queue_packet(s, OUT_PACKET_HEADER_SIZE, 404 - payload_length, skip); 397 + return queue_packet(s, OUT_PACKET_HEADER_SIZE, payload_length); 405 398 } 406 399 407 400 static inline int queue_in_packet(struct amdtp_stream *s) 408 401 { 409 402 return queue_packet(s, IN_PACKET_HEADER_SIZE, 410 - amdtp_stream_get_max_payload(s), false); 403 + amdtp_stream_get_max_payload(s)); 411 404 } 412 405 413 - static int handle_out_packet(struct amdtp_stream *s, unsigned int data_blocks, 414 - unsigned int syt) 406 + static int handle_out_packet(struct amdtp_stream *s, unsigned int cycle, 407 + unsigned int index) 415 408 { 416 409 __be32 *buffer; 410 + unsigned int syt; 411 + unsigned int data_blocks; 417 412 unsigned int payload_length; 418 413 unsigned int pcm_frames; 419 414 struct snd_pcm_substream *pcm; 420 415 421 416 buffer = s->buffer.packets[s->packet_index].buffer; 417 + syt = calculate_syt(s, cycle); 418 + data_blocks = calculate_data_blocks(s, syt); 422 419 pcm_frames = s->process_data_blocks(s, buffer + 2, data_blocks, &syt); 423 420 424 421 buffer[0] = cpu_to_be32(ACCESS_ONCE(s->source_node_id_field) | ··· 433 424 (syt & CIP_SYT_MASK)); 434 425 435 426 s->data_block_counter = (s->data_block_counter + data_blocks) & 0xff; 436 - 437 427 payload_length = 8 + data_blocks * 4 * s->data_block_quadlets; 438 - if (queue_out_packet(s, payload_length, false) < 0) 428 + 429 + trace_out_packet(s, cycle, buffer, payload_length, index); 430 + 431 + if (queue_out_packet(s, payload_length) < 0) 439 432 return -EIO; 440 433 441 434 pcm = ACCESS_ONCE(s->pcm); ··· 449 438 } 450 439 451 440 static int handle_in_packet(struct amdtp_stream *s, 452 - unsigned int payload_quadlets, __be32 *buffer, 453 - unsigned int *data_blocks, unsigned int syt) 441 + unsigned int payload_quadlets, unsigned int cycle, 442 + unsigned int index) 454 443 { 444 + __be32 *buffer; 455 445 u32 cip_header[2]; 456 - unsigned int fmt, fdf; 446 + unsigned int fmt, fdf, syt; 457 447 unsigned int data_block_quadlets, data_block_counter, dbc_interval; 448 + unsigned int data_blocks; 458 449 struct snd_pcm_substream *pcm; 459 450 unsigned int pcm_frames; 460 451 bool lost; 461 452 453 + buffer = s->buffer.packets[s->packet_index].buffer; 462 454 cip_header[0] = be32_to_cpu(buffer[0]); 463 455 cip_header[1] = be32_to_cpu(buffer[1]); 456 + 457 + trace_in_packet(s, cycle, cip_header, payload_quadlets, index); 464 458 465 459 /* 466 460 * This module supports 'Two-quadlet CIP header with SYT field'. ··· 476 460 dev_info_ratelimited(&s->unit->device, 477 461 "Invalid CIP header for AMDTP: %08X:%08X\n", 478 462 cip_header[0], cip_header[1]); 479 - *data_blocks = 0; 463 + data_blocks = 0; 480 464 pcm_frames = 0; 481 465 goto end; 482 466 } ··· 487 471 dev_info_ratelimited(&s->unit->device, 488 472 "Detect unexpected protocol: %08x %08x\n", 489 473 cip_header[0], cip_header[1]); 490 - *data_blocks = 0; 474 + data_blocks = 0; 491 475 pcm_frames = 0; 492 476 goto end; 493 477 } ··· 496 480 fdf = (cip_header[1] & CIP_FDF_MASK) >> CIP_FDF_SHIFT; 497 481 if (payload_quadlets < 3 || 498 482 (fmt == CIP_FMT_AM && fdf == AMDTP_FDF_NO_DATA)) { 499 - *data_blocks = 0; 483 + data_blocks = 0; 500 484 } else { 501 485 data_block_quadlets = 502 486 (cip_header[0] & CIP_DBS_MASK) >> CIP_DBS_SHIFT; ··· 510 494 if (s->flags & CIP_WRONG_DBS) 511 495 data_block_quadlets = s->data_block_quadlets; 512 496 513 - *data_blocks = (payload_quadlets - 2) / data_block_quadlets; 497 + data_blocks = (payload_quadlets - 2) / data_block_quadlets; 514 498 } 515 499 516 500 /* Check data block counter continuity */ 517 501 data_block_counter = cip_header[0] & CIP_DBC_MASK; 518 - if (*data_blocks == 0 && (s->flags & CIP_EMPTY_HAS_WRONG_DBC) && 502 + if (data_blocks == 0 && (s->flags & CIP_EMPTY_HAS_WRONG_DBC) && 519 503 s->data_block_counter != UINT_MAX) 520 504 data_block_counter = s->data_block_counter; 521 505 ··· 526 510 } else if (!(s->flags & CIP_DBC_IS_END_EVENT)) { 527 511 lost = data_block_counter != s->data_block_counter; 528 512 } else { 529 - if ((*data_blocks > 0) && (s->tx_dbc_interval > 0)) 513 + if (data_blocks > 0 && s->tx_dbc_interval > 0) 530 514 dbc_interval = s->tx_dbc_interval; 531 515 else 532 - dbc_interval = *data_blocks; 516 + dbc_interval = data_blocks; 533 517 534 518 lost = data_block_counter != 535 519 ((s->data_block_counter + dbc_interval) & 0xff); ··· 542 526 return -EIO; 543 527 } 544 528 545 - pcm_frames = s->process_data_blocks(s, buffer + 2, *data_blocks, &syt); 529 + syt = be32_to_cpu(buffer[1]) & CIP_SYT_MASK; 530 + pcm_frames = s->process_data_blocks(s, buffer + 2, data_blocks, &syt); 546 531 547 532 if (s->flags & CIP_DBC_IS_END_EVENT) 548 533 s->data_block_counter = data_block_counter; 549 534 else 550 535 s->data_block_counter = 551 - (data_block_counter + *data_blocks) & 0xff; 536 + (data_block_counter + data_blocks) & 0xff; 552 537 end: 553 538 if (queue_in_packet(s) < 0) 554 539 return -EIO; ··· 561 544 return 0; 562 545 } 563 546 564 - static void out_stream_callback(struct fw_iso_context *context, u32 cycle, 547 + /* 548 + * In CYCLE_TIMER register of IEEE 1394, 7 bits are used to represent second. On 549 + * the other hand, in DMA descriptors of 1394 OHCI, 3 bits are used to represent 550 + * it. Thus, via Linux firewire subsystem, we can get the 3 bits for second. 551 + */ 552 + static inline u32 compute_cycle_count(u32 tstamp) 553 + { 554 + return (((tstamp >> 13) & 0x07) * 8000) + (tstamp & 0x1fff); 555 + } 556 + 557 + static inline u32 increment_cycle_count(u32 cycle, unsigned int addend) 558 + { 559 + cycle += addend; 560 + if (cycle >= 8 * CYCLES_PER_SECOND) 561 + cycle -= 8 * CYCLES_PER_SECOND; 562 + return cycle; 563 + } 564 + 565 + static inline u32 decrement_cycle_count(u32 cycle, unsigned int subtrahend) 566 + { 567 + if (cycle < subtrahend) 568 + cycle += 8 * CYCLES_PER_SECOND; 569 + return cycle - subtrahend; 570 + } 571 + 572 + static void out_stream_callback(struct fw_iso_context *context, u32 tstamp, 565 573 size_t header_length, void *header, 566 574 void *private_data) 567 575 { 568 576 struct amdtp_stream *s = private_data; 569 - unsigned int i, syt, packets = header_length / 4; 570 - unsigned int data_blocks; 577 + unsigned int i, packets = header_length / 4; 578 + u32 cycle; 571 579 572 580 if (s->packet_index < 0) 573 581 return; 574 582 575 - /* 576 - * Compute the cycle of the last queued packet. 577 - * (We need only the four lowest bits for the SYT, so we can ignore 578 - * that bits 0-11 must wrap around at 3072.) 579 - */ 580 - cycle += QUEUE_LENGTH - packets; 583 + cycle = compute_cycle_count(tstamp); 584 + 585 + /* Align to actual cycle count for the last packet. */ 586 + cycle = increment_cycle_count(cycle, QUEUE_LENGTH - packets); 581 587 582 588 for (i = 0; i < packets; ++i) { 583 - syt = calculate_syt(s, ++cycle); 584 - data_blocks = calculate_data_blocks(s, syt); 585 - 586 - if (handle_out_packet(s, data_blocks, syt) < 0) { 589 + cycle = increment_cycle_count(cycle, 1); 590 + if (handle_out_packet(s, cycle, i) < 0) { 587 591 s->packet_index = -1; 588 592 amdtp_stream_pcm_abort(s); 589 593 return; ··· 614 576 fw_iso_context_queue_flush(s->context); 615 577 } 616 578 617 - static void in_stream_callback(struct fw_iso_context *context, u32 cycle, 579 + static void in_stream_callback(struct fw_iso_context *context, u32 tstamp, 618 580 size_t header_length, void *header, 619 581 void *private_data) 620 582 { 621 583 struct amdtp_stream *s = private_data; 622 - unsigned int p, syt, packets; 584 + unsigned int i, packets; 623 585 unsigned int payload_quadlets, max_payload_quadlets; 624 - unsigned int data_blocks; 625 - __be32 *buffer, *headers = header; 586 + __be32 *headers = header; 587 + u32 cycle; 626 588 627 589 if (s->packet_index < 0) 628 590 return; ··· 630 592 /* The number of packets in buffer */ 631 593 packets = header_length / IN_PACKET_HEADER_SIZE; 632 594 595 + cycle = compute_cycle_count(tstamp); 596 + 597 + /* Align to actual cycle count for the last packet. */ 598 + cycle = decrement_cycle_count(cycle, packets); 599 + 633 600 /* For buffer-over-run prevention. */ 634 601 max_payload_quadlets = amdtp_stream_get_max_payload(s) / 4; 635 602 636 - for (p = 0; p < packets; p++) { 637 - buffer = s->buffer.packets[s->packet_index].buffer; 603 + for (i = 0; i < packets; i++) { 604 + cycle = increment_cycle_count(cycle, 1); 638 605 639 606 /* The number of quadlets in this packet */ 640 607 payload_quadlets = 641 - (be32_to_cpu(headers[p]) >> ISO_DATA_LENGTH_SHIFT) / 4; 608 + (be32_to_cpu(headers[i]) >> ISO_DATA_LENGTH_SHIFT) / 4; 642 609 if (payload_quadlets > max_payload_quadlets) { 643 610 dev_err(&s->unit->device, 644 611 "Detect jumbo payload: %02x %02x\n", 645 612 payload_quadlets, max_payload_quadlets); 646 - s->packet_index = -1; 647 613 break; 648 614 } 649 615 650 - syt = be32_to_cpu(buffer[1]) & CIP_SYT_MASK; 651 - if (handle_in_packet(s, payload_quadlets, buffer, 652 - &data_blocks, syt) < 0) { 653 - s->packet_index = -1; 616 + if (handle_in_packet(s, payload_quadlets, cycle, i) < 0) 654 617 break; 655 - } 656 - 657 - /* Process sync slave stream */ 658 - if (s->sync_slave && s->sync_slave->callbacked) { 659 - if (handle_out_packet(s->sync_slave, 660 - data_blocks, syt) < 0) { 661 - s->packet_index = -1; 662 - break; 663 - } 664 - } 665 618 } 666 619 667 - /* Queueing error or detecting discontinuity */ 668 - if (s->packet_index < 0) { 620 + /* Queueing error or detecting invalid payload. */ 621 + if (i < packets) { 622 + s->packet_index = -1; 669 623 amdtp_stream_pcm_abort(s); 670 - 671 - /* Abort sync slave. */ 672 - if (s->sync_slave) { 673 - s->sync_slave->packet_index = -1; 674 - amdtp_stream_pcm_abort(s->sync_slave); 675 - } 676 624 return; 677 625 } 678 - 679 - /* when sync to device, flush the packets for slave stream */ 680 - if (s->sync_slave && s->sync_slave->callbacked) 681 - fw_iso_context_queue_flush(s->sync_slave->context); 682 626 683 627 fw_iso_context_queue_flush(s->context); 684 628 } 685 629 686 - /* processing is done by master callback */ 687 - static void slave_stream_callback(struct fw_iso_context *context, u32 cycle, 688 - size_t header_length, void *header, 689 - void *private_data) 690 - { 691 - return; 692 - } 693 - 694 630 /* this is executed one time */ 695 631 static void amdtp_stream_first_callback(struct fw_iso_context *context, 696 - u32 cycle, size_t header_length, 632 + u32 tstamp, size_t header_length, 697 633 void *header, void *private_data) 698 634 { 699 635 struct amdtp_stream *s = private_data; ··· 681 669 682 670 if (s->direction == AMDTP_IN_STREAM) 683 671 context->callback.sc = in_stream_callback; 684 - else if (s->flags & CIP_SYNC_TO_DEVICE) 685 - context->callback.sc = slave_stream_callback; 686 672 else 687 673 context->callback.sc = out_stream_callback; 688 674 689 - context->callback.sc(context, cycle, header_length, header, s); 675 + context->callback.sc(context, tstamp, header_length, header, s); 690 676 } 691 677 692 678 /** ··· 723 713 goto err_unlock; 724 714 } 725 715 726 - if (s->direction == AMDTP_IN_STREAM && 727 - s->flags & CIP_SKIP_INIT_DBC_CHECK) 716 + if (s->direction == AMDTP_IN_STREAM) 728 717 s->data_block_counter = UINT_MAX; 729 718 else 730 719 s->data_block_counter = 0; ··· 764 755 if (s->direction == AMDTP_IN_STREAM) 765 756 err = queue_in_packet(s); 766 757 else 767 - err = queue_out_packet(s, 0, true); 758 + err = queue_out_packet(s, 0); 768 759 if (err < 0) 769 760 goto err_context; 770 761 } while (s->packet_index > 0); ··· 803 794 */ 804 795 unsigned long amdtp_stream_pcm_pointer(struct amdtp_stream *s) 805 796 { 806 - /* this optimization is allowed to be racy */ 807 - if (s->pointer_flush && amdtp_stream_running(s)) 797 + /* 798 + * This function is called in software IRQ context of period_tasklet or 799 + * process context. 800 + * 801 + * When the software IRQ context was scheduled by software IRQ context 802 + * of IR/IT contexts, queued packets were already handled. Therefore, 803 + * no need to flush the queue in buffer anymore. 804 + * 805 + * When the process context reach here, some packets will be already 806 + * queued in the buffer. These packets should be handled immediately 807 + * to keep better granularity of PCM pointer. 808 + * 809 + * Later, the process context will sometimes schedules software IRQ 810 + * context of the period_tasklet. Then, no need to flush the queue by 811 + * the same reason as described for IR/IT contexts. 812 + */ 813 + if (!in_interrupt() && amdtp_stream_running(s)) 808 814 fw_iso_context_flush_completions(s->context); 809 - else 810 - s->pointer_flush = true; 811 815 812 816 return ACCESS_ONCE(s->pcm_buffer_pointer); 813 817 }
+6 -31
sound/firewire/amdtp-stream.h
··· 17 17 * @CIP_BLOCKING: In blocking mode, each packet contains either zero or 18 18 * SYT_INTERVAL samples, with these two types alternating so that 19 19 * the overall sample rate comes out right. 20 - * @CIP_SYNC_TO_DEVICE: In sync to device mode, time stamp in out packets is 21 - * generated by in packets. Defaultly this driver generates timestamp. 22 20 * @CIP_EMPTY_WITH_TAG0: Only for in-stream. Empty in-packets have TAG0. 23 21 * @CIP_DBC_IS_END_EVENT: Only for in-stream. The value of dbc in an in-packet 24 22 * corresponds to the end of event in the packet. Out of IEC 61883. ··· 24 26 * The value of data_block_quadlets is used instead of reported value. 25 27 * @CIP_SKIP_DBC_ZERO_CHECK: Only for in-stream. Packets with zero in dbc is 26 28 * skipped for detecting discontinuity. 27 - * @CIP_SKIP_INIT_DBC_CHECK: Only for in-stream. The value of dbc in first 28 - * packet is not continuous from an initial value. 29 29 * @CIP_EMPTY_HAS_WRONG_DBC: Only for in-stream. The value of dbc in empty 30 30 * packet is wrong but the others are correct. 31 31 * @CIP_JUMBO_PAYLOAD: Only for in-stream. The number of data blocks in an ··· 33 37 enum cip_flags { 34 38 CIP_NONBLOCKING = 0x00, 35 39 CIP_BLOCKING = 0x01, 36 - CIP_SYNC_TO_DEVICE = 0x02, 37 - CIP_EMPTY_WITH_TAG0 = 0x04, 38 - CIP_DBC_IS_END_EVENT = 0x08, 39 - CIP_WRONG_DBS = 0x10, 40 - CIP_SKIP_DBC_ZERO_CHECK = 0x20, 41 - CIP_SKIP_INIT_DBC_CHECK = 0x40, 42 - CIP_EMPTY_HAS_WRONG_DBC = 0x80, 43 - CIP_JUMBO_PAYLOAD = 0x100, 40 + CIP_EMPTY_WITH_TAG0 = 0x02, 41 + CIP_DBC_IS_END_EVENT = 0x04, 42 + CIP_WRONG_DBS = 0x08, 43 + CIP_SKIP_DBC_ZERO_CHECK = 0x10, 44 + CIP_EMPTY_HAS_WRONG_DBC = 0x20, 45 + CIP_JUMBO_PAYLOAD = 0x40, 44 46 }; 45 47 46 48 /** ··· 126 132 struct tasklet_struct period_tasklet; 127 133 unsigned int pcm_buffer_pointer; 128 134 unsigned int pcm_period_pointer; 129 - bool pointer_flush; 130 135 131 136 /* To wait for first packet. */ 132 137 bool callbacked; 133 138 wait_queue_head_t callback_wait; 134 - struct amdtp_stream *sync_slave; 135 139 136 140 /* For backends to process data blocks. */ 137 141 void *protocol; ··· 213 221 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc) 214 222 { 215 223 return sfc & 1; 216 - } 217 - 218 - static inline void amdtp_stream_set_sync(enum cip_flags sync_mode, 219 - struct amdtp_stream *master, 220 - struct amdtp_stream *slave) 221 - { 222 - if (sync_mode == CIP_SYNC_TO_DEVICE) { 223 - master->flags |= CIP_SYNC_TO_DEVICE; 224 - slave->flags |= CIP_SYNC_TO_DEVICE; 225 - master->sync_slave = slave; 226 - } else { 227 - master->flags &= ~CIP_SYNC_TO_DEVICE; 228 - slave->flags &= ~CIP_SYNC_TO_DEVICE; 229 - master->sync_slave = NULL; 230 - } 231 - 232 - slave->sync_slave = NULL; 233 224 } 234 225 235 226 /**
+129 -90
sound/firewire/bebob/bebob.c
··· 67 67 #define MODEL_MAUDIO_PROJECTMIX 0x00010091 68 68 69 69 static int 70 - name_device(struct snd_bebob *bebob, unsigned int vendor_id) 70 + name_device(struct snd_bebob *bebob) 71 71 { 72 72 struct fw_device *fw_dev = fw_parent_device(bebob->unit); 73 73 char vendor[24] = {0}; ··· 126 126 return err; 127 127 } 128 128 129 + static void bebob_free(struct snd_bebob *bebob) 130 + { 131 + snd_bebob_stream_destroy_duplex(bebob); 132 + fw_unit_put(bebob->unit); 133 + 134 + kfree(bebob->maudio_special_quirk); 135 + 136 + mutex_destroy(&bebob->mutex); 137 + kfree(bebob); 138 + } 139 + 129 140 /* 130 141 * This module releases the FireWire unit data after all ALSA character devices 131 142 * are released by applications. This is for releasing stream data or finishing ··· 148 137 { 149 138 struct snd_bebob *bebob = card->private_data; 150 139 151 - snd_bebob_stream_destroy_duplex(bebob); 152 - fw_unit_put(bebob->unit); 140 + mutex_lock(&devices_mutex); 141 + clear_bit(bebob->card_index, devices_used); 142 + mutex_unlock(&devices_mutex); 153 143 154 - kfree(bebob->maudio_special_quirk); 155 - 156 - if (bebob->card_index >= 0) { 157 - mutex_lock(&devices_mutex); 158 - clear_bit(bebob->card_index, devices_used); 159 - mutex_unlock(&devices_mutex); 160 - } 161 - 162 - mutex_destroy(&bebob->mutex); 144 + bebob_free(card->private_data); 163 145 } 164 146 165 147 static const struct snd_bebob_spec * ··· 180 176 return strncmp(name, "FW Audiophile Bootloader", 15) != 0; 181 177 } 182 178 183 - static int 184 - bebob_probe(struct fw_unit *unit, 185 - const struct ieee1394_device_id *entry) 179 + static void 180 + do_registration(struct work_struct *work) 186 181 { 187 - struct snd_card *card; 188 - struct snd_bebob *bebob; 189 - const struct snd_bebob_spec *spec; 182 + struct snd_bebob *bebob = 183 + container_of(work, struct snd_bebob, dwork.work); 190 184 unsigned int card_index; 191 185 int err; 186 + 187 + if (bebob->registered) 188 + return; 192 189 193 190 mutex_lock(&devices_mutex); 194 191 ··· 198 193 break; 199 194 } 200 195 if (card_index >= SNDRV_CARDS) { 201 - err = -ENOENT; 202 - goto end; 196 + mutex_unlock(&devices_mutex); 197 + return; 203 198 } 204 199 205 - if ((entry->vendor_id == VEN_FOCUSRITE) && 206 - (entry->model_id == MODEL_FOCUSRITE_SAFFIRE_BOTH)) 207 - spec = get_saffire_spec(unit); 208 - else if ((entry->vendor_id == VEN_MAUDIO1) && 209 - (entry->model_id == MODEL_MAUDIO_AUDIOPHILE_BOTH) && 210 - !check_audiophile_booted(unit)) 211 - spec = NULL; 212 - else 213 - spec = (const struct snd_bebob_spec *)entry->driver_data; 214 - 215 - if (spec == NULL) { 216 - if ((entry->vendor_id == VEN_MAUDIO1) || 217 - (entry->vendor_id == VEN_MAUDIO2)) 218 - err = snd_bebob_maudio_load_firmware(unit); 219 - else 220 - err = -ENOSYS; 221 - goto end; 200 + err = snd_card_new(&bebob->unit->device, index[card_index], 201 + id[card_index], THIS_MODULE, 0, &bebob->card); 202 + if (err < 0) { 203 + mutex_unlock(&devices_mutex); 204 + return; 222 205 } 223 206 224 - err = snd_card_new(&unit->device, index[card_index], id[card_index], 225 - THIS_MODULE, sizeof(struct snd_bebob), &card); 226 - if (err < 0) 227 - goto end; 228 - bebob = card->private_data; 229 - bebob->card_index = card_index; 230 - set_bit(card_index, devices_used); 231 - card->private_free = bebob_card_free; 232 - 233 - bebob->card = card; 234 - bebob->unit = fw_unit_get(unit); 235 - bebob->spec = spec; 236 - mutex_init(&bebob->mutex); 237 - spin_lock_init(&bebob->lock); 238 - init_waitqueue_head(&bebob->hwdep_wait); 239 - 240 - err = name_device(bebob, entry->vendor_id); 207 + err = name_device(bebob); 241 208 if (err < 0) 242 209 goto error; 243 210 244 - if ((entry->vendor_id == VEN_MAUDIO1) && 245 - (entry->model_id == MODEL_MAUDIO_FW1814)) 246 - err = snd_bebob_maudio_special_discover(bebob, true); 247 - else if ((entry->vendor_id == VEN_MAUDIO1) && 248 - (entry->model_id == MODEL_MAUDIO_PROJECTMIX)) 249 - err = snd_bebob_maudio_special_discover(bebob, false); 250 - else 211 + if (bebob->spec == &maudio_special_spec) { 212 + if (bebob->entry->model_id == MODEL_MAUDIO_FW1814) 213 + err = snd_bebob_maudio_special_discover(bebob, true); 214 + else 215 + err = snd_bebob_maudio_special_discover(bebob, false); 216 + } else { 251 217 err = snd_bebob_stream_discover(bebob); 218 + } 219 + if (err < 0) 220 + goto error; 221 + 222 + err = snd_bebob_stream_init_duplex(bebob); 252 223 if (err < 0) 253 224 goto error; 254 225 255 226 snd_bebob_proc_init(bebob); 256 227 257 - if ((bebob->midi_input_ports > 0) || 258 - (bebob->midi_output_ports > 0)) { 228 + if (bebob->midi_input_ports > 0 || bebob->midi_output_ports > 0) { 259 229 err = snd_bebob_create_midi_devices(bebob); 260 230 if (err < 0) 261 231 goto error; ··· 244 264 if (err < 0) 245 265 goto error; 246 266 247 - err = snd_bebob_stream_init_duplex(bebob); 267 + err = snd_card_register(bebob->card); 248 268 if (err < 0) 249 269 goto error; 250 270 251 - if (!bebob->maudio_special_quirk) { 252 - err = snd_card_register(card); 253 - if (err < 0) { 254 - snd_bebob_stream_destroy_duplex(bebob); 255 - goto error; 256 - } 271 + set_bit(card_index, devices_used); 272 + mutex_unlock(&devices_mutex); 273 + 274 + /* 275 + * After registered, bebob instance can be released corresponding to 276 + * releasing the sound card instance. 277 + */ 278 + bebob->card->private_free = bebob_card_free; 279 + bebob->card->private_data = bebob; 280 + bebob->registered = true; 281 + 282 + return; 283 + error: 284 + mutex_unlock(&devices_mutex); 285 + snd_bebob_stream_destroy_duplex(bebob); 286 + snd_card_free(bebob->card); 287 + dev_info(&bebob->unit->device, 288 + "Sound card registration failed: %d\n", err); 289 + } 290 + 291 + static int 292 + bebob_probe(struct fw_unit *unit, const struct ieee1394_device_id *entry) 293 + { 294 + struct snd_bebob *bebob; 295 + const struct snd_bebob_spec *spec; 296 + 297 + if (entry->vendor_id == VEN_FOCUSRITE && 298 + entry->model_id == MODEL_FOCUSRITE_SAFFIRE_BOTH) 299 + spec = get_saffire_spec(unit); 300 + else if (entry->vendor_id == VEN_MAUDIO1 && 301 + entry->model_id == MODEL_MAUDIO_AUDIOPHILE_BOTH && 302 + !check_audiophile_booted(unit)) 303 + spec = NULL; 304 + else 305 + spec = (const struct snd_bebob_spec *)entry->driver_data; 306 + 307 + if (spec == NULL) { 308 + if (entry->vendor_id == VEN_MAUDIO1 || 309 + entry->vendor_id == VEN_MAUDIO2) 310 + return snd_bebob_maudio_load_firmware(unit); 311 + else 312 + return -ENODEV; 313 + } 314 + 315 + /* Allocate this independent of sound card instance. */ 316 + bebob = kzalloc(sizeof(struct snd_bebob), GFP_KERNEL); 317 + if (bebob == NULL) 318 + return -ENOMEM; 319 + 320 + bebob->unit = fw_unit_get(unit); 321 + bebob->entry = entry; 322 + bebob->spec = spec; 323 + dev_set_drvdata(&unit->device, bebob); 324 + 325 + mutex_init(&bebob->mutex); 326 + spin_lock_init(&bebob->lock); 327 + init_waitqueue_head(&bebob->hwdep_wait); 328 + 329 + /* Allocate and register this sound card later. */ 330 + INIT_DEFERRABLE_WORK(&bebob->dwork, do_registration); 331 + 332 + if (entry->vendor_id != VEN_MAUDIO1 || 333 + (entry->model_id != MODEL_MAUDIO_FW1814 && 334 + entry->model_id != MODEL_MAUDIO_PROJECTMIX)) { 335 + snd_fw_schedule_registration(unit, &bebob->dwork); 257 336 } else { 258 337 /* 259 338 * This is a workaround. This bus reset seems to have an effect ··· 324 285 * signals from dbus and starts I/Os. To avoid I/Os till the 325 286 * future bus reset, registration is done in next update(). 326 287 */ 327 - bebob->deferred_registration = true; 328 288 fw_schedule_bus_reset(fw_parent_device(bebob->unit)->card, 329 289 false, true); 330 290 } 331 291 332 - dev_set_drvdata(&unit->device, bebob); 333 - end: 334 - mutex_unlock(&devices_mutex); 335 - return err; 336 - error: 337 - mutex_unlock(&devices_mutex); 338 - snd_card_free(card); 339 - return err; 292 + return 0; 340 293 } 341 294 342 295 /* ··· 355 324 if (bebob == NULL) 356 325 return; 357 326 358 - fcp_bus_reset(bebob->unit); 359 - 360 - if (bebob->deferred_registration) { 361 - if (snd_card_register(bebob->card) < 0) { 362 - snd_bebob_stream_destroy_duplex(bebob); 363 - snd_card_free(bebob->card); 364 - } 365 - bebob->deferred_registration = false; 366 - } 327 + /* Postpone a workqueue for deferred registration. */ 328 + if (!bebob->registered) 329 + snd_fw_schedule_registration(unit, &bebob->dwork); 330 + else 331 + fcp_bus_reset(bebob->unit); 367 332 } 368 333 369 334 static void bebob_remove(struct fw_unit *unit) ··· 369 342 if (bebob == NULL) 370 343 return; 371 344 372 - /* No need to wait for releasing card object in this context. */ 373 - snd_card_free_when_closed(bebob->card); 345 + /* 346 + * Confirm to stop the work for registration before the sound card is 347 + * going to be released. The work is not scheduled again because bus 348 + * reset handler is not called anymore. 349 + */ 350 + cancel_delayed_work_sync(&bebob->dwork); 351 + 352 + if (bebob->registered) { 353 + /* No need to wait for releasing card object in this context. */ 354 + snd_card_free_when_closed(bebob->card); 355 + } else { 356 + /* Don't forget this case. */ 357 + bebob_free(bebob); 358 + } 374 359 } 375 360 376 361 static const struct snd_bebob_rate_spec normal_rate_spec = {
+4 -2
sound/firewire/bebob/bebob.h
··· 83 83 struct mutex mutex; 84 84 spinlock_t lock; 85 85 86 + bool registered; 87 + struct delayed_work dwork; 88 + 89 + const struct ieee1394_device_id *entry; 86 90 const struct snd_bebob_spec *spec; 87 91 88 92 unsigned int midi_input_ports; ··· 94 90 95 91 bool connected; 96 92 97 - struct amdtp_stream *master; 98 93 struct amdtp_stream tx_stream; 99 94 struct amdtp_stream rx_stream; 100 95 struct cmp_connection out_conn; ··· 114 111 115 112 /* for M-Audio special devices */ 116 113 void *maudio_special_quirk; 117 - bool deferred_registration; 118 114 119 115 /* For BeBoB version quirk. */ 120 116 unsigned int version;
+26 -75
sound/firewire/bebob/bebob_stream.c
··· 484 484 } 485 485 486 486 static int 487 - get_sync_mode(struct snd_bebob *bebob, enum cip_flags *sync_mode) 488 - { 489 - enum snd_bebob_clock_type src; 490 - int err; 491 - 492 - err = snd_bebob_stream_get_clock_src(bebob, &src); 493 - if (err < 0) 494 - return err; 495 - 496 - switch (src) { 497 - case SND_BEBOB_CLOCK_TYPE_INTERNAL: 498 - case SND_BEBOB_CLOCK_TYPE_EXTERNAL: 499 - *sync_mode = CIP_SYNC_TO_DEVICE; 500 - break; 501 - default: 502 - case SND_BEBOB_CLOCK_TYPE_SYT: 503 - *sync_mode = 0; 504 - break; 505 - } 506 - 507 - return 0; 508 - } 509 - 510 - static int 511 487 start_stream(struct snd_bebob *bebob, struct amdtp_stream *stream, 512 488 unsigned int rate) 513 489 { ··· 526 550 goto end; 527 551 } 528 552 529 - bebob->tx_stream.flags |= CIP_SKIP_INIT_DBC_CHECK; 530 - 531 553 /* 532 554 * BeBoB v3 transfers packets with these qurks: 533 555 * - In the beginning of streaming, the value of dbc is incremented ··· 558 584 int snd_bebob_stream_start_duplex(struct snd_bebob *bebob, unsigned int rate) 559 585 { 560 586 const struct snd_bebob_rate_spec *rate_spec = bebob->spec->rate; 561 - struct amdtp_stream *master, *slave; 562 - enum cip_flags sync_mode; 563 587 unsigned int curr_rate; 564 588 int err = 0; 565 589 ··· 565 593 if (bebob->substreams_counter == 0) 566 594 goto end; 567 595 568 - err = get_sync_mode(bebob, &sync_mode); 569 - if (err < 0) 570 - goto end; 571 - if (sync_mode == CIP_SYNC_TO_DEVICE) { 572 - master = &bebob->tx_stream; 573 - slave = &bebob->rx_stream; 574 - } else { 575 - master = &bebob->rx_stream; 576 - slave = &bebob->tx_stream; 577 - } 578 - 579 596 /* 580 597 * Considering JACK/FFADO streaming: 581 598 * TODO: This can be removed hwdep functionality becomes popular. 582 599 */ 583 - err = check_connection_used_by_others(bebob, master); 600 + err = check_connection_used_by_others(bebob, &bebob->rx_stream); 584 601 if (err < 0) 585 602 goto end; 586 603 ··· 579 618 * At bus reset, connections should not be broken here. So streams need 580 619 * to be re-started. This is a reason to use SKIP_INIT_DBC_CHECK flag. 581 620 */ 582 - if (amdtp_streaming_error(master)) 583 - amdtp_stream_stop(master); 584 - if (amdtp_streaming_error(slave)) 585 - amdtp_stream_stop(slave); 586 - if (!amdtp_stream_running(master) && !amdtp_stream_running(slave)) 621 + if (amdtp_streaming_error(&bebob->rx_stream)) 622 + amdtp_stream_stop(&bebob->rx_stream); 623 + if (amdtp_streaming_error(&bebob->tx_stream)) 624 + amdtp_stream_stop(&bebob->tx_stream); 625 + if (!amdtp_stream_running(&bebob->rx_stream) && 626 + !amdtp_stream_running(&bebob->tx_stream)) 587 627 break_both_connections(bebob); 588 628 589 629 /* stop streams if rate is different */ ··· 597 635 if (rate == 0) 598 636 rate = curr_rate; 599 637 if (rate != curr_rate) { 600 - amdtp_stream_stop(master); 601 - amdtp_stream_stop(slave); 638 + amdtp_stream_stop(&bebob->rx_stream); 639 + amdtp_stream_stop(&bebob->tx_stream); 602 640 break_both_connections(bebob); 603 641 } 604 642 605 643 /* master should be always running */ 606 - if (!amdtp_stream_running(master)) { 607 - amdtp_stream_set_sync(sync_mode, master, slave); 608 - bebob->master = master; 609 - 644 + if (!amdtp_stream_running(&bebob->rx_stream)) { 610 645 /* 611 646 * NOTE: 612 647 * If establishing connections at first, Yamaha GO46 ··· 625 666 if (err < 0) 626 667 goto end; 627 668 628 - err = start_stream(bebob, master, rate); 669 + err = start_stream(bebob, &bebob->rx_stream, rate); 629 670 if (err < 0) { 630 671 dev_err(&bebob->unit->device, 631 672 "fail to run AMDTP master stream:%d\n", err); ··· 644 685 dev_err(&bebob->unit->device, 645 686 "fail to ensure sampling rate: %d\n", 646 687 err); 647 - amdtp_stream_stop(master); 688 + amdtp_stream_stop(&bebob->rx_stream); 648 689 break_both_connections(bebob); 649 690 goto end; 650 691 } 651 692 } 652 693 653 694 /* wait first callback */ 654 - if (!amdtp_stream_wait_callback(master, CALLBACK_TIMEOUT)) { 655 - amdtp_stream_stop(master); 695 + if (!amdtp_stream_wait_callback(&bebob->rx_stream, 696 + CALLBACK_TIMEOUT)) { 697 + amdtp_stream_stop(&bebob->rx_stream); 656 698 break_both_connections(bebob); 657 699 err = -ETIMEDOUT; 658 700 goto end; ··· 661 701 } 662 702 663 703 /* start slave if needed */ 664 - if (!amdtp_stream_running(slave)) { 665 - err = start_stream(bebob, slave, rate); 704 + if (!amdtp_stream_running(&bebob->tx_stream)) { 705 + err = start_stream(bebob, &bebob->tx_stream, rate); 666 706 if (err < 0) { 667 707 dev_err(&bebob->unit->device, 668 708 "fail to run AMDTP slave stream:%d\n", err); 669 - amdtp_stream_stop(master); 709 + amdtp_stream_stop(&bebob->rx_stream); 670 710 break_both_connections(bebob); 671 711 goto end; 672 712 } 673 713 674 714 /* wait first callback */ 675 - if (!amdtp_stream_wait_callback(slave, CALLBACK_TIMEOUT)) { 676 - amdtp_stream_stop(slave); 677 - amdtp_stream_stop(master); 715 + if (!amdtp_stream_wait_callback(&bebob->tx_stream, 716 + CALLBACK_TIMEOUT)) { 717 + amdtp_stream_stop(&bebob->tx_stream); 718 + amdtp_stream_stop(&bebob->rx_stream); 678 719 break_both_connections(bebob); 679 720 err = -ETIMEDOUT; 680 721 } ··· 686 725 687 726 void snd_bebob_stream_stop_duplex(struct snd_bebob *bebob) 688 727 { 689 - struct amdtp_stream *master, *slave; 690 - 691 - if (bebob->master == &bebob->rx_stream) { 692 - slave = &bebob->tx_stream; 693 - master = &bebob->rx_stream; 694 - } else { 695 - slave = &bebob->rx_stream; 696 - master = &bebob->tx_stream; 697 - } 698 - 699 728 if (bebob->substreams_counter == 0) { 700 - amdtp_stream_pcm_abort(master); 701 - amdtp_stream_stop(master); 729 + amdtp_stream_pcm_abort(&bebob->rx_stream); 730 + amdtp_stream_stop(&bebob->rx_stream); 702 731 703 - amdtp_stream_pcm_abort(slave); 704 - amdtp_stream_stop(slave); 732 + amdtp_stream_pcm_abort(&bebob->tx_stream); 733 + amdtp_stream_stop(&bebob->tx_stream); 705 734 706 735 break_both_connections(bebob); 707 736 }
+15 -26
sound/firewire/dice/dice.c
··· 20 20 #define WEISS_CATEGORY_ID 0x00 21 21 #define LOUD_CATEGORY_ID 0x10 22 22 23 - #define PROBE_DELAY_MS (2 * MSEC_PER_SEC) 24 - 25 23 /* 26 24 * Some models support several isochronous channels, while these streams are not 27 25 * always available. In this case, add the model name to this list. ··· 199 201 200 202 dice_card_strings(dice); 201 203 204 + err = snd_dice_stream_init_duplex(dice); 205 + if (err < 0) 206 + goto error; 207 + 202 208 snd_dice_create_proc(dice); 203 209 204 210 err = snd_dice_create_pcm(dice); ··· 231 229 232 230 return; 233 231 error: 232 + snd_dice_stream_destroy_duplex(dice); 234 233 snd_dice_transaction_destroy(dice); 234 + snd_dice_stream_destroy_duplex(dice); 235 235 snd_card_free(dice->card); 236 236 dev_info(&dice->unit->device, 237 237 "Sound card registration failed: %d\n", err); 238 - } 239 - 240 - static void schedule_registration(struct snd_dice *dice) 241 - { 242 - struct fw_card *fw_card = fw_parent_device(dice->unit)->card; 243 - u64 now, delay; 244 - 245 - now = get_jiffies_64(); 246 - delay = fw_card->reset_jiffies + msecs_to_jiffies(PROBE_DELAY_MS); 247 - 248 - if (time_after64(delay, now)) 249 - delay -= now; 250 - else 251 - delay = 0; 252 - 253 - mod_delayed_work(system_wq, &dice->dwork, delay); 254 238 } 255 239 256 240 static int dice_probe(struct fw_unit *unit, const struct ieee1394_device_id *id) ··· 261 273 init_completion(&dice->clock_accepted); 262 274 init_waitqueue_head(&dice->hwdep_wait); 263 275 264 - err = snd_dice_stream_init_duplex(dice); 265 - if (err < 0) { 266 - dice_free(dice); 267 - return err; 268 - } 269 - 270 276 /* Allocate and register this sound card later. */ 271 277 INIT_DEFERRABLE_WORK(&dice->dwork, do_registration); 272 - schedule_registration(dice); 278 + snd_fw_schedule_registration(unit, &dice->dwork); 273 279 274 280 return 0; 275 281 } ··· 294 312 295 313 /* Postpone a workqueue for deferred registration. */ 296 314 if (!dice->registered) 297 - schedule_registration(dice); 315 + snd_fw_schedule_registration(unit, &dice->dwork); 298 316 299 317 /* The handler address register becomes initialized. */ 300 318 snd_dice_transaction_reinit(dice); ··· 316 334 { 317 335 .match_flags = IEEE1394_MATCH_VERSION, 318 336 .version = DICE_INTERFACE, 337 + }, 338 + /* M-Audio Profire 610/2626 has a different value in version field. */ 339 + { 340 + .match_flags = IEEE1394_MATCH_VENDOR_ID | 341 + IEEE1394_MATCH_SPECIFIER_ID, 342 + .vendor_id = 0x000d6c, 343 + .specifier_id = 0x000d6c, 319 344 }, 320 345 { } 321 346 };
+1 -1
sound/firewire/digi00x/amdtp-dot.c
··· 421 421 422 422 /* Use different mode between incoming/outgoing. */ 423 423 if (dir == AMDTP_IN_STREAM) { 424 - flags = CIP_NONBLOCKING | CIP_SKIP_INIT_DBC_CHECK; 424 + flags = CIP_NONBLOCKING; 425 425 process_data_blocks = process_tx_data_blocks; 426 426 } else { 427 427 flags = CIP_BLOCKING;
+6 -1
sound/firewire/digi00x/digi00x-transaction.c
··· 126 126 return err; 127 127 error: 128 128 fw_core_remove_address_handler(&dg00x->async_handler); 129 - dg00x->async_handler.address_callback = NULL; 129 + dg00x->async_handler.callback_data = NULL; 130 130 return err; 131 131 } 132 132 133 133 void snd_dg00x_transaction_unregister(struct snd_dg00x *dg00x) 134 134 { 135 + if (dg00x->async_handler.callback_data == NULL) 136 + return; 137 + 135 138 snd_fw_async_midi_port_destroy(&dg00x->out_control); 136 139 fw_core_remove_address_handler(&dg00x->async_handler); 140 + 141 + dg00x->async_handler.callback_data = NULL; 137 142 }
+76 -31
sound/firewire/digi00x/digi00x.c
··· 40 40 return 0; 41 41 } 42 42 43 - static void dg00x_card_free(struct snd_card *card) 43 + static void dg00x_free(struct snd_dg00x *dg00x) 44 44 { 45 - struct snd_dg00x *dg00x = card->private_data; 46 - 47 45 snd_dg00x_stream_destroy_duplex(dg00x); 48 46 snd_dg00x_transaction_unregister(dg00x); 49 47 ··· 50 52 mutex_destroy(&dg00x->mutex); 51 53 } 52 54 53 - static int snd_dg00x_probe(struct fw_unit *unit, 54 - const struct ieee1394_device_id *entry) 55 + static void dg00x_card_free(struct snd_card *card) 55 56 { 56 - struct snd_card *card; 57 - struct snd_dg00x *dg00x; 57 + dg00x_free(card->private_data); 58 + } 59 + 60 + static void do_registration(struct work_struct *work) 61 + { 62 + struct snd_dg00x *dg00x = 63 + container_of(work, struct snd_dg00x, dwork.work); 58 64 int err; 59 65 60 - /* create card */ 61 - err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE, 62 - sizeof(struct snd_dg00x), &card); 66 + if (dg00x->registered) 67 + return; 68 + 69 + err = snd_card_new(&dg00x->unit->device, -1, NULL, THIS_MODULE, 0, 70 + &dg00x->card); 63 71 if (err < 0) 64 - return err; 65 - card->private_free = dg00x_card_free; 66 - 67 - /* initialize myself */ 68 - dg00x = card->private_data; 69 - dg00x->card = card; 70 - dg00x->unit = fw_unit_get(unit); 71 - 72 - mutex_init(&dg00x->mutex); 73 - spin_lock_init(&dg00x->lock); 74 - init_waitqueue_head(&dg00x->hwdep_wait); 72 + return; 75 73 76 74 err = name_card(dg00x); 77 75 if (err < 0) ··· 95 101 if (err < 0) 96 102 goto error; 97 103 98 - err = snd_card_register(card); 104 + err = snd_card_register(dg00x->card); 99 105 if (err < 0) 100 106 goto error; 101 107 108 + dg00x->card->private_free = dg00x_card_free; 109 + dg00x->card->private_data = dg00x; 110 + dg00x->registered = true; 111 + 112 + return; 113 + error: 114 + snd_dg00x_transaction_unregister(dg00x); 115 + snd_dg00x_stream_destroy_duplex(dg00x); 116 + snd_card_free(dg00x->card); 117 + dev_info(&dg00x->unit->device, 118 + "Sound card registration failed: %d\n", err); 119 + } 120 + 121 + static int snd_dg00x_probe(struct fw_unit *unit, 122 + const struct ieee1394_device_id *entry) 123 + { 124 + struct snd_dg00x *dg00x; 125 + 126 + /* Allocate this independent of sound card instance. */ 127 + dg00x = kzalloc(sizeof(struct snd_dg00x), GFP_KERNEL); 128 + if (dg00x == NULL) 129 + return -ENOMEM; 130 + 131 + dg00x->unit = fw_unit_get(unit); 102 132 dev_set_drvdata(&unit->device, dg00x); 103 133 104 - return err; 105 - error: 106 - snd_card_free(card); 107 - return err; 134 + mutex_init(&dg00x->mutex); 135 + spin_lock_init(&dg00x->lock); 136 + init_waitqueue_head(&dg00x->hwdep_wait); 137 + 138 + /* Allocate and register this sound card later. */ 139 + INIT_DEFERRABLE_WORK(&dg00x->dwork, do_registration); 140 + snd_fw_schedule_registration(unit, &dg00x->dwork); 141 + 142 + return 0; 108 143 } 109 144 110 145 static void snd_dg00x_update(struct fw_unit *unit) 111 146 { 112 147 struct snd_dg00x *dg00x = dev_get_drvdata(&unit->device); 113 148 149 + /* Postpone a workqueue for deferred registration. */ 150 + if (!dg00x->registered) 151 + snd_fw_schedule_registration(unit, &dg00x->dwork); 152 + 114 153 snd_dg00x_transaction_reregister(dg00x); 115 154 116 - mutex_lock(&dg00x->mutex); 117 - snd_dg00x_stream_update_duplex(dg00x); 118 - mutex_unlock(&dg00x->mutex); 155 + /* 156 + * After registration, userspace can start packet streaming, then this 157 + * code block works fine. 158 + */ 159 + if (dg00x->registered) { 160 + mutex_lock(&dg00x->mutex); 161 + snd_dg00x_stream_update_duplex(dg00x); 162 + mutex_unlock(&dg00x->mutex); 163 + } 119 164 } 120 165 121 166 static void snd_dg00x_remove(struct fw_unit *unit) 122 167 { 123 168 struct snd_dg00x *dg00x = dev_get_drvdata(&unit->device); 124 169 125 - /* No need to wait for releasing card object in this context. */ 126 - snd_card_free_when_closed(dg00x->card); 170 + /* 171 + * Confirm to stop the work for registration before the sound card is 172 + * going to be released. The work is not scheduled again because bus 173 + * reset handler is not called anymore. 174 + */ 175 + cancel_delayed_work_sync(&dg00x->dwork); 176 + 177 + if (dg00x->registered) { 178 + /* No need to wait for releasing card object in this context. */ 179 + snd_card_free_when_closed(dg00x->card); 180 + } else { 181 + /* Don't forget this case. */ 182 + dg00x_free(dg00x); 183 + } 127 184 } 128 185 129 186 static const struct ieee1394_device_id snd_dg00x_id_table[] = {
+3
sound/firewire/digi00x/digi00x.h
··· 37 37 struct mutex mutex; 38 38 spinlock_t lock; 39 39 40 + bool registered; 41 + struct delayed_work dwork; 42 + 40 43 struct amdtp_stream tx_stream; 41 44 struct fw_iso_resources tx_resources; 42 45
+111 -57
sound/firewire/fireworks/fireworks.c
··· 168 168 sizeof(struct snd_efw_phys_grp) * hwinfo->phys_in_grp_count); 169 169 memcpy(&efw->phys_out_grps, hwinfo->phys_out_grps, 170 170 sizeof(struct snd_efw_phys_grp) * hwinfo->phys_out_grp_count); 171 + 172 + /* AudioFire8 (since 2009) and AudioFirePre8 */ 173 + if (hwinfo->type == MODEL_ECHO_AUDIOFIRE_9) 174 + efw->is_af9 = true; 175 + /* These models uses the same firmware. */ 176 + if (hwinfo->type == MODEL_ECHO_AUDIOFIRE_2 || 177 + hwinfo->type == MODEL_ECHO_AUDIOFIRE_4 || 178 + hwinfo->type == MODEL_ECHO_AUDIOFIRE_9 || 179 + hwinfo->type == MODEL_GIBSON_RIP || 180 + hwinfo->type == MODEL_GIBSON_GOLDTOP) 181 + efw->is_fireworks3 = true; 171 182 end: 172 183 kfree(hwinfo); 173 184 return err; 185 + } 186 + 187 + static void efw_free(struct snd_efw *efw) 188 + { 189 + snd_efw_stream_destroy_duplex(efw); 190 + snd_efw_transaction_remove_instance(efw); 191 + fw_unit_put(efw->unit); 192 + 193 + kfree(efw->resp_buf); 194 + 195 + mutex_destroy(&efw->mutex); 196 + kfree(efw); 174 197 } 175 198 176 199 /* ··· 207 184 { 208 185 struct snd_efw *efw = card->private_data; 209 186 210 - snd_efw_stream_destroy_duplex(efw); 211 - snd_efw_transaction_remove_instance(efw); 212 - fw_unit_put(efw->unit); 213 - 214 - kfree(efw->resp_buf); 215 - 216 187 if (efw->card_index >= 0) { 217 188 mutex_lock(&devices_mutex); 218 189 clear_bit(efw->card_index, devices_used); 219 190 mutex_unlock(&devices_mutex); 220 191 } 221 192 222 - mutex_destroy(&efw->mutex); 193 + efw_free(card->private_data); 223 194 } 224 195 225 - static int 226 - efw_probe(struct fw_unit *unit, 227 - const struct ieee1394_device_id *entry) 196 + static void 197 + do_registration(struct work_struct *work) 228 198 { 229 - struct snd_card *card; 230 - struct snd_efw *efw; 231 - int card_index, err; 199 + struct snd_efw *efw = container_of(work, struct snd_efw, dwork.work); 200 + unsigned int card_index; 201 + int err; 202 + 203 + if (efw->registered) 204 + return; 232 205 233 206 mutex_lock(&devices_mutex); 234 207 ··· 234 215 break; 235 216 } 236 217 if (card_index >= SNDRV_CARDS) { 237 - err = -ENOENT; 238 - goto end; 218 + mutex_unlock(&devices_mutex); 219 + return; 239 220 } 240 221 241 - err = snd_card_new(&unit->device, index[card_index], id[card_index], 242 - THIS_MODULE, sizeof(struct snd_efw), &card); 243 - if (err < 0) 244 - goto end; 245 - efw = card->private_data; 246 - efw->card_index = card_index; 247 - set_bit(card_index, devices_used); 248 - card->private_free = efw_card_free; 249 - 250 - efw->card = card; 251 - efw->unit = fw_unit_get(unit); 252 - mutex_init(&efw->mutex); 253 - spin_lock_init(&efw->lock); 254 - init_waitqueue_head(&efw->hwdep_wait); 222 + err = snd_card_new(&efw->unit->device, index[card_index], 223 + id[card_index], THIS_MODULE, 0, &efw->card); 224 + if (err < 0) { 225 + mutex_unlock(&devices_mutex); 226 + return; 227 + } 255 228 256 229 /* prepare response buffer */ 257 230 snd_efw_resp_buf_size = clamp(snd_efw_resp_buf_size, ··· 259 248 err = get_hardware_info(efw); 260 249 if (err < 0) 261 250 goto error; 262 - /* AudioFire8 (since 2009) and AudioFirePre8 */ 263 - if (entry->model_id == MODEL_ECHO_AUDIOFIRE_9) 264 - efw->is_af9 = true; 265 - /* These models uses the same firmware. */ 266 - if (entry->model_id == MODEL_ECHO_AUDIOFIRE_2 || 267 - entry->model_id == MODEL_ECHO_AUDIOFIRE_4 || 268 - entry->model_id == MODEL_ECHO_AUDIOFIRE_9 || 269 - entry->model_id == MODEL_GIBSON_RIP || 270 - entry->model_id == MODEL_GIBSON_GOLDTOP) 271 - efw->is_fireworks3 = true; 251 + 252 + err = snd_efw_stream_init_duplex(efw); 253 + if (err < 0) 254 + goto error; 272 255 273 256 snd_efw_proc_init(efw); 274 257 ··· 280 275 if (err < 0) 281 276 goto error; 282 277 283 - err = snd_efw_stream_init_duplex(efw); 278 + err = snd_card_register(efw->card); 284 279 if (err < 0) 285 280 goto error; 286 281 287 - err = snd_card_register(card); 288 - if (err < 0) { 289 - snd_efw_stream_destroy_duplex(efw); 290 - goto error; 291 - } 282 + set_bit(card_index, devices_used); 283 + mutex_unlock(&devices_mutex); 292 284 293 - dev_set_drvdata(&unit->device, efw); 294 - end: 295 - mutex_unlock(&devices_mutex); 296 - return err; 285 + /* 286 + * After registered, efw instance can be released corresponding to 287 + * releasing the sound card instance. 288 + */ 289 + efw->card->private_free = efw_card_free; 290 + efw->card->private_data = efw; 291 + efw->registered = true; 292 + 293 + return; 297 294 error: 298 - snd_efw_transaction_remove_instance(efw); 299 295 mutex_unlock(&devices_mutex); 300 - snd_card_free(card); 301 - return err; 296 + snd_efw_transaction_remove_instance(efw); 297 + snd_efw_stream_destroy_duplex(efw); 298 + snd_card_free(efw->card); 299 + dev_info(&efw->unit->device, 300 + "Sound card registration failed: %d\n", err); 301 + } 302 + 303 + static int 304 + efw_probe(struct fw_unit *unit, const struct ieee1394_device_id *entry) 305 + { 306 + struct snd_efw *efw; 307 + 308 + efw = kzalloc(sizeof(struct snd_efw), GFP_KERNEL); 309 + if (efw == NULL) 310 + return -ENOMEM; 311 + 312 + efw->unit = fw_unit_get(unit); 313 + dev_set_drvdata(&unit->device, efw); 314 + 315 + mutex_init(&efw->mutex); 316 + spin_lock_init(&efw->lock); 317 + init_waitqueue_head(&efw->hwdep_wait); 318 + 319 + /* Allocate and register this sound card later. */ 320 + INIT_DEFERRABLE_WORK(&efw->dwork, do_registration); 321 + snd_fw_schedule_registration(unit, &efw->dwork); 322 + 323 + return 0; 302 324 } 303 325 304 326 static void efw_update(struct fw_unit *unit) 305 327 { 306 328 struct snd_efw *efw = dev_get_drvdata(&unit->device); 307 329 330 + /* Postpone a workqueue for deferred registration. */ 331 + if (!efw->registered) 332 + snd_fw_schedule_registration(unit, &efw->dwork); 333 + 308 334 snd_efw_transaction_bus_reset(efw->unit); 309 335 310 - mutex_lock(&efw->mutex); 311 - snd_efw_stream_update_duplex(efw); 312 - mutex_unlock(&efw->mutex); 336 + /* 337 + * After registration, userspace can start packet streaming, then this 338 + * code block works fine. 339 + */ 340 + if (efw->registered) { 341 + mutex_lock(&efw->mutex); 342 + snd_efw_stream_update_duplex(efw); 343 + mutex_unlock(&efw->mutex); 344 + } 313 345 } 314 346 315 347 static void efw_remove(struct fw_unit *unit) 316 348 { 317 349 struct snd_efw *efw = dev_get_drvdata(&unit->device); 318 350 319 - /* No need to wait for releasing card object in this context. */ 320 - snd_card_free_when_closed(efw->card); 351 + /* 352 + * Confirm to stop the work for registration before the sound card is 353 + * going to be released. The work is not scheduled again because bus 354 + * reset handler is not called anymore. 355 + */ 356 + cancel_delayed_work_sync(&efw->dwork); 357 + 358 + if (efw->registered) { 359 + /* No need to wait for releasing card object in this context. */ 360 + snd_card_free_when_closed(efw->card); 361 + } else { 362 + /* Don't forget this case. */ 363 + efw_free(efw); 364 + } 321 365 } 322 366 323 367 static const struct ieee1394_device_id efw_id_table[] = {
+3 -1
sound/firewire/fireworks/fireworks.h
··· 65 65 struct mutex mutex; 66 66 spinlock_t lock; 67 67 68 + bool registered; 69 + struct delayed_work dwork; 70 + 68 71 /* for transaction */ 69 72 u32 seqnum; 70 73 bool resp_addr_changable; ··· 84 81 unsigned int pcm_capture_channels[SND_EFW_MULTIPLIER_MODES]; 85 82 unsigned int pcm_playback_channels[SND_EFW_MULTIPLIER_MODES]; 86 83 87 - struct amdtp_stream *master; 88 84 struct amdtp_stream tx_stream; 89 85 struct amdtp_stream rx_stream; 90 86 struct cmp_connection out_conn;
+17 -67
sound/firewire/fireworks/fireworks_stream.c
··· 121 121 } 122 122 123 123 static int 124 - get_sync_mode(struct snd_efw *efw, enum cip_flags *sync_mode) 125 - { 126 - enum snd_efw_clock_source clock_source; 127 - int err; 128 - 129 - err = snd_efw_command_get_clock_source(efw, &clock_source); 130 - if (err < 0) 131 - return err; 132 - 133 - if (clock_source == SND_EFW_CLOCK_SOURCE_SYTMATCH) 134 - return -ENOSYS; 135 - 136 - *sync_mode = CIP_SYNC_TO_DEVICE; 137 - return 0; 138 - } 139 - 140 - static int 141 124 check_connection_used_by_others(struct snd_efw *efw, struct amdtp_stream *s) 142 125 { 143 126 struct cmp_connection *conn; ··· 191 208 192 209 int snd_efw_stream_start_duplex(struct snd_efw *efw, unsigned int rate) 193 210 { 194 - struct amdtp_stream *master, *slave; 195 - unsigned int slave_substreams; 196 - enum cip_flags sync_mode; 197 211 unsigned int curr_rate; 198 212 int err = 0; 199 213 ··· 198 218 if (efw->playback_substreams == 0 && efw->capture_substreams == 0) 199 219 goto end; 200 220 201 - err = get_sync_mode(efw, &sync_mode); 202 - if (err < 0) 203 - goto end; 204 - if (sync_mode == CIP_SYNC_TO_DEVICE) { 205 - master = &efw->tx_stream; 206 - slave = &efw->rx_stream; 207 - slave_substreams = efw->playback_substreams; 208 - } else { 209 - master = &efw->rx_stream; 210 - slave = &efw->tx_stream; 211 - slave_substreams = efw->capture_substreams; 212 - } 213 - 214 221 /* 215 222 * Considering JACK/FFADO streaming: 216 223 * TODO: This can be removed hwdep functionality becomes popular. 217 224 */ 218 - err = check_connection_used_by_others(efw, master); 225 + err = check_connection_used_by_others(efw, &efw->rx_stream); 219 226 if (err < 0) 220 227 goto end; 221 228 222 229 /* packet queueing error */ 223 - if (amdtp_streaming_error(slave)) 224 - stop_stream(efw, slave); 225 - if (amdtp_streaming_error(master)) 226 - stop_stream(efw, master); 230 + if (amdtp_streaming_error(&efw->tx_stream)) 231 + stop_stream(efw, &efw->tx_stream); 232 + if (amdtp_streaming_error(&efw->rx_stream)) 233 + stop_stream(efw, &efw->rx_stream); 227 234 228 235 /* stop streams if rate is different */ 229 236 err = snd_efw_command_get_sampling_rate(efw, &curr_rate); ··· 219 252 if (rate == 0) 220 253 rate = curr_rate; 221 254 if (rate != curr_rate) { 222 - stop_stream(efw, slave); 223 - stop_stream(efw, master); 255 + stop_stream(efw, &efw->tx_stream); 256 + stop_stream(efw, &efw->rx_stream); 224 257 } 225 258 226 259 /* master should be always running */ 227 - if (!amdtp_stream_running(master)) { 228 - amdtp_stream_set_sync(sync_mode, master, slave); 229 - efw->master = master; 230 - 260 + if (!amdtp_stream_running(&efw->rx_stream)) { 231 261 err = snd_efw_command_set_sampling_rate(efw, rate); 232 262 if (err < 0) 233 263 goto end; 234 264 235 - err = start_stream(efw, master, rate); 265 + err = start_stream(efw, &efw->rx_stream, rate); 236 266 if (err < 0) { 237 267 dev_err(&efw->unit->device, 238 268 "fail to start AMDTP master stream:%d\n", err); ··· 238 274 } 239 275 240 276 /* start slave if needed */ 241 - if (slave_substreams > 0 && !amdtp_stream_running(slave)) { 242 - err = start_stream(efw, slave, rate); 277 + if (efw->capture_substreams > 0 && 278 + !amdtp_stream_running(&efw->tx_stream)) { 279 + err = start_stream(efw, &efw->tx_stream, rate); 243 280 if (err < 0) { 244 281 dev_err(&efw->unit->device, 245 282 "fail to start AMDTP slave stream:%d\n", err); 246 - stop_stream(efw, master); 283 + stop_stream(efw, &efw->rx_stream); 247 284 } 248 285 } 249 286 end: ··· 253 288 254 289 void snd_efw_stream_stop_duplex(struct snd_efw *efw) 255 290 { 256 - struct amdtp_stream *master, *slave; 257 - unsigned int master_substreams, slave_substreams; 291 + if (efw->capture_substreams == 0) { 292 + stop_stream(efw, &efw->tx_stream); 258 293 259 - if (efw->master == &efw->rx_stream) { 260 - slave = &efw->tx_stream; 261 - master = &efw->rx_stream; 262 - slave_substreams = efw->capture_substreams; 263 - master_substreams = efw->playback_substreams; 264 - } else { 265 - slave = &efw->rx_stream; 266 - master = &efw->tx_stream; 267 - slave_substreams = efw->playback_substreams; 268 - master_substreams = efw->capture_substreams; 269 - } 270 - 271 - if (slave_substreams == 0) { 272 - stop_stream(efw, slave); 273 - 274 - if (master_substreams == 0) 275 - stop_stream(efw, master); 294 + if (efw->playback_substreams == 0) 295 + stop_stream(efw, &efw->rx_stream); 276 296 } 277 297 } 278 298
+32
sound/firewire/lib.c
··· 67 67 } 68 68 EXPORT_SYMBOL(snd_fw_transaction); 69 69 70 + #define PROBE_DELAY_MS (2 * MSEC_PER_SEC) 71 + 72 + /** 73 + * snd_fw_schedule_registration - schedule work for sound card registration 74 + * @unit: an instance for unit on IEEE 1394 bus 75 + * @dwork: delayed work with callback function 76 + * 77 + * This function is not designed for general purposes. When new unit is 78 + * connected to IEEE 1394 bus, the bus is under bus-reset state because of 79 + * topological change. In this state, units tend to fail both of asynchronous 80 + * and isochronous communication. To avoid this problem, this function is used 81 + * to postpone sound card registration after the state. The callers must 82 + * set up instance of delayed work in advance. 83 + */ 84 + void snd_fw_schedule_registration(struct fw_unit *unit, 85 + struct delayed_work *dwork) 86 + { 87 + u64 now, delay; 88 + 89 + now = get_jiffies_64(); 90 + delay = fw_parent_device(unit)->card->reset_jiffies 91 + + msecs_to_jiffies(PROBE_DELAY_MS); 92 + 93 + if (time_after64(delay, now)) 94 + delay -= now; 95 + else 96 + delay = 0; 97 + 98 + mod_delayed_work(system_wq, dwork, delay); 99 + } 100 + EXPORT_SYMBOL(snd_fw_schedule_registration); 101 + 70 102 static void async_midi_port_callback(struct fw_card *card, int rcode, 71 103 void *data, size_t length, 72 104 void *callback_data)
+3
sound/firewire/lib.h
··· 22 22 return rcode == RCODE_TYPE_ERROR || rcode == RCODE_ADDRESS_ERROR; 23 23 } 24 24 25 + void snd_fw_schedule_registration(struct fw_unit *unit, 26 + struct delayed_work *dwork); 27 + 25 28 struct snd_fw_async_midi_port; 26 29 typedef int (*snd_fw_async_midi_port_fill)( 27 30 struct snd_rawmidi_substream *substream,
+1 -2
sound/firewire/oxfw/oxfw-stream.c
··· 242 242 * blocks than IEC 61883-6 defines. 243 243 */ 244 244 if (stream == &oxfw->tx_stream) { 245 - oxfw->tx_stream.flags |= CIP_SKIP_INIT_DBC_CHECK | 246 - CIP_JUMBO_PAYLOAD; 245 + oxfw->tx_stream.flags |= CIP_JUMBO_PAYLOAD; 247 246 if (oxfw->wrong_dbs) 248 247 oxfw->tx_stream.flags |= CIP_WRONG_DBS; 249 248 }
+100 -55
sound/firewire/oxfw/oxfw.c
··· 118 118 return err; 119 119 } 120 120 121 - /* 122 - * This module releases the FireWire unit data after all ALSA character devices 123 - * are released by applications. This is for releasing stream data or finishing 124 - * transactions safely. Thus at returning from .remove(), this module still keep 125 - * references for the unit. 126 - */ 127 - static void oxfw_card_free(struct snd_card *card) 121 + static void oxfw_free(struct snd_oxfw *oxfw) 128 122 { 129 - struct snd_oxfw *oxfw = card->private_data; 130 123 unsigned int i; 131 124 132 125 snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->rx_stream); ··· 135 142 136 143 kfree(oxfw->spec); 137 144 mutex_destroy(&oxfw->mutex); 145 + } 146 + 147 + /* 148 + * This module releases the FireWire unit data after all ALSA character devices 149 + * are released by applications. This is for releasing stream data or finishing 150 + * transactions safely. Thus at returning from .remove(), this module still keep 151 + * references for the unit. 152 + */ 153 + static void oxfw_card_free(struct snd_card *card) 154 + { 155 + oxfw_free(card->private_data); 138 156 } 139 157 140 158 static int detect_quirks(struct snd_oxfw *oxfw) ··· 209 205 return 0; 210 206 } 211 207 212 - static int oxfw_probe(struct fw_unit *unit, 213 - const struct ieee1394_device_id *entry) 208 + static void do_registration(struct work_struct *work) 214 209 { 215 - struct snd_card *card; 216 - struct snd_oxfw *oxfw; 210 + struct snd_oxfw *oxfw = container_of(work, struct snd_oxfw, dwork.work); 217 211 int err; 218 212 219 - if (entry->vendor_id == VENDOR_LOUD && !detect_loud_models(unit)) 220 - return -ENODEV; 213 + if (oxfw->registered) 214 + return; 221 215 222 - err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE, 223 - sizeof(*oxfw), &card); 216 + err = snd_card_new(&oxfw->unit->device, -1, NULL, THIS_MODULE, 0, 217 + &oxfw->card); 224 218 if (err < 0) 225 - return err; 226 - 227 - card->private_free = oxfw_card_free; 228 - oxfw = card->private_data; 229 - oxfw->card = card; 230 - mutex_init(&oxfw->mutex); 231 - oxfw->unit = fw_unit_get(unit); 232 - oxfw->entry = entry; 233 - spin_lock_init(&oxfw->lock); 234 - init_waitqueue_head(&oxfw->hwdep_wait); 235 - 236 - err = snd_oxfw_stream_discover(oxfw); 237 - if (err < 0) 238 - goto error; 219 + return; 239 220 240 221 err = name_card(oxfw); 241 222 if (err < 0) ··· 229 240 err = detect_quirks(oxfw); 230 241 if (err < 0) 231 242 goto error; 243 + 244 + err = snd_oxfw_stream_discover(oxfw); 245 + if (err < 0) 246 + goto error; 247 + 248 + err = snd_oxfw_stream_init_simplex(oxfw, &oxfw->rx_stream); 249 + if (err < 0) 250 + goto error; 251 + if (oxfw->has_output) { 252 + err = snd_oxfw_stream_init_simplex(oxfw, &oxfw->tx_stream); 253 + if (err < 0) 254 + goto error; 255 + } 232 256 233 257 err = snd_oxfw_create_pcm(oxfw); 234 258 if (err < 0) ··· 257 255 if (err < 0) 258 256 goto error; 259 257 260 - err = snd_oxfw_stream_init_simplex(oxfw, &oxfw->rx_stream); 258 + err = snd_card_register(oxfw->card); 261 259 if (err < 0) 262 260 goto error; 263 - if (oxfw->has_output) { 264 - err = snd_oxfw_stream_init_simplex(oxfw, &oxfw->tx_stream); 265 - if (err < 0) 266 - goto error; 267 - } 268 261 269 - err = snd_card_register(card); 270 - if (err < 0) { 271 - snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->rx_stream); 272 - if (oxfw->has_output) 273 - snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->tx_stream); 274 - goto error; 275 - } 262 + /* 263 + * After registered, oxfw instance can be released corresponding to 264 + * releasing the sound card instance. 265 + */ 266 + oxfw->card->private_free = oxfw_card_free; 267 + oxfw->card->private_data = oxfw; 268 + oxfw->registered = true; 269 + 270 + return; 271 + error: 272 + snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->rx_stream); 273 + if (oxfw->has_output) 274 + snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->tx_stream); 275 + snd_card_free(oxfw->card); 276 + dev_info(&oxfw->unit->device, 277 + "Sound card registration failed: %d\n", err); 278 + } 279 + 280 + static int oxfw_probe(struct fw_unit *unit, 281 + const struct ieee1394_device_id *entry) 282 + { 283 + struct snd_oxfw *oxfw; 284 + 285 + if (entry->vendor_id == VENDOR_LOUD && !detect_loud_models(unit)) 286 + return -ENODEV; 287 + 288 + /* Allocate this independent of sound card instance. */ 289 + oxfw = kzalloc(sizeof(struct snd_oxfw), GFP_KERNEL); 290 + if (oxfw == NULL) 291 + return -ENOMEM; 292 + 293 + oxfw->entry = entry; 294 + oxfw->unit = fw_unit_get(unit); 276 295 dev_set_drvdata(&unit->device, oxfw); 277 296 297 + mutex_init(&oxfw->mutex); 298 + spin_lock_init(&oxfw->lock); 299 + init_waitqueue_head(&oxfw->hwdep_wait); 300 + 301 + /* Allocate and register this sound card later. */ 302 + INIT_DEFERRABLE_WORK(&oxfw->dwork, do_registration); 303 + snd_fw_schedule_registration(unit, &oxfw->dwork); 304 + 278 305 return 0; 279 - error: 280 - snd_card_free(card); 281 - return err; 282 306 } 283 307 284 308 static void oxfw_bus_reset(struct fw_unit *unit) 285 309 { 286 310 struct snd_oxfw *oxfw = dev_get_drvdata(&unit->device); 287 311 312 + if (!oxfw->registered) 313 + snd_fw_schedule_registration(unit, &oxfw->dwork); 314 + 288 315 fcp_bus_reset(oxfw->unit); 289 316 290 - mutex_lock(&oxfw->mutex); 317 + if (oxfw->registered) { 318 + mutex_lock(&oxfw->mutex); 291 319 292 - snd_oxfw_stream_update_simplex(oxfw, &oxfw->rx_stream); 293 - if (oxfw->has_output) 294 - snd_oxfw_stream_update_simplex(oxfw, &oxfw->tx_stream); 320 + snd_oxfw_stream_update_simplex(oxfw, &oxfw->rx_stream); 321 + if (oxfw->has_output) 322 + snd_oxfw_stream_update_simplex(oxfw, &oxfw->tx_stream); 295 323 296 - mutex_unlock(&oxfw->mutex); 324 + mutex_unlock(&oxfw->mutex); 297 325 298 - if (oxfw->entry->vendor_id == OUI_STANTON) 299 - snd_oxfw_scs1x_update(oxfw); 326 + if (oxfw->entry->vendor_id == OUI_STANTON) 327 + snd_oxfw_scs1x_update(oxfw); 328 + } 300 329 } 301 330 302 331 static void oxfw_remove(struct fw_unit *unit) 303 332 { 304 333 struct snd_oxfw *oxfw = dev_get_drvdata(&unit->device); 305 334 306 - /* No need to wait for releasing card object in this context. */ 307 - snd_card_free_when_closed(oxfw->card); 335 + /* 336 + * Confirm to stop the work for registration before the sound card is 337 + * going to be released. The work is not scheduled again because bus 338 + * reset handler is not called anymore. 339 + */ 340 + cancel_delayed_work_sync(&oxfw->dwork); 341 + 342 + if (oxfw->registered) { 343 + /* No need to wait for releasing card object in this context. */ 344 + snd_card_free_when_closed(oxfw->card); 345 + } else { 346 + /* Don't forget this case. */ 347 + oxfw_free(oxfw); 348 + } 308 349 } 309 350 310 351 static const struct compat_info griffin_firewave = {
+3 -1
sound/firewire/oxfw/oxfw.h
··· 36 36 struct snd_oxfw { 37 37 struct snd_card *card; 38 38 struct fw_unit *unit; 39 - const struct device_info *device_info; 40 39 struct mutex mutex; 41 40 spinlock_t lock; 41 + 42 + bool registered; 43 + struct delayed_work dwork; 42 44 43 45 bool wrong_dbs; 44 46 bool has_output;
+19 -21
sound/firewire/tascam/tascam-stream.c
··· 381 381 if (err < 0) 382 382 return err; 383 383 if (curr_rate != rate || 384 - amdtp_streaming_error(&tscm->tx_stream) || 385 - amdtp_streaming_error(&tscm->rx_stream)) { 384 + amdtp_streaming_error(&tscm->rx_stream) || 385 + amdtp_streaming_error(&tscm->tx_stream)) { 386 386 finish_session(tscm); 387 387 388 - amdtp_stream_stop(&tscm->tx_stream); 389 388 amdtp_stream_stop(&tscm->rx_stream); 389 + amdtp_stream_stop(&tscm->tx_stream); 390 390 391 391 release_resources(tscm); 392 392 } 393 393 394 - if (!amdtp_stream_running(&tscm->tx_stream)) { 395 - amdtp_stream_set_sync(CIP_SYNC_TO_DEVICE, 396 - &tscm->tx_stream, &tscm->rx_stream); 394 + if (!amdtp_stream_running(&tscm->rx_stream)) { 397 395 err = keep_resources(tscm, rate); 398 396 if (err < 0) 399 397 goto error; ··· 404 406 if (err < 0) 405 407 goto error; 406 408 407 - err = amdtp_stream_start(&tscm->tx_stream, 408 - tscm->tx_resources.channel, 409 - fw_parent_device(tscm->unit)->max_speed); 410 - if (err < 0) 411 - goto error; 412 - 413 - if (!amdtp_stream_wait_callback(&tscm->tx_stream, 414 - CALLBACK_TIMEOUT)) { 415 - err = -ETIMEDOUT; 416 - goto error; 417 - } 418 - } 419 - 420 - if (!amdtp_stream_running(&tscm->rx_stream)) { 421 409 err = amdtp_stream_start(&tscm->rx_stream, 422 410 tscm->rx_resources.channel, 423 411 fw_parent_device(tscm->unit)->max_speed); ··· 417 433 } 418 434 } 419 435 436 + if (!amdtp_stream_running(&tscm->tx_stream)) { 437 + err = amdtp_stream_start(&tscm->tx_stream, 438 + tscm->tx_resources.channel, 439 + fw_parent_device(tscm->unit)->max_speed); 440 + if (err < 0) 441 + goto error; 442 + 443 + if (!amdtp_stream_wait_callback(&tscm->tx_stream, 444 + CALLBACK_TIMEOUT)) { 445 + err = -ETIMEDOUT; 446 + goto error; 447 + } 448 + } 449 + 420 450 return 0; 421 451 error: 422 - amdtp_stream_stop(&tscm->tx_stream); 423 452 amdtp_stream_stop(&tscm->rx_stream); 453 + amdtp_stream_stop(&tscm->tx_stream); 424 454 425 455 finish_session(tscm); 426 456 release_resources(tscm);
+82 -36
sound/firewire/tascam/tascam.c
··· 85 85 return 0; 86 86 } 87 87 88 - static void tscm_card_free(struct snd_card *card) 88 + static void tscm_free(struct snd_tscm *tscm) 89 89 { 90 - struct snd_tscm *tscm = card->private_data; 91 - 92 90 snd_tscm_transaction_unregister(tscm); 93 91 snd_tscm_stream_destroy_duplex(tscm); 94 92 ··· 95 97 mutex_destroy(&tscm->mutex); 96 98 } 97 99 98 - static int snd_tscm_probe(struct fw_unit *unit, 99 - const struct ieee1394_device_id *entry) 100 + static void tscm_card_free(struct snd_card *card) 100 101 { 101 - struct snd_card *card; 102 - struct snd_tscm *tscm; 102 + tscm_free(card->private_data); 103 + } 104 + 105 + static void do_registration(struct work_struct *work) 106 + { 107 + struct snd_tscm *tscm = container_of(work, struct snd_tscm, dwork.work); 103 108 int err; 104 109 105 - /* create card */ 106 - err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE, 107 - sizeof(struct snd_tscm), &card); 110 + err = snd_card_new(&tscm->unit->device, -1, NULL, THIS_MODULE, 0, 111 + &tscm->card); 108 112 if (err < 0) 109 - return err; 110 - card->private_free = tscm_card_free; 111 - 112 - /* initialize myself */ 113 - tscm = card->private_data; 114 - tscm->card = card; 115 - tscm->unit = fw_unit_get(unit); 116 - 117 - mutex_init(&tscm->mutex); 118 - spin_lock_init(&tscm->lock); 119 - init_waitqueue_head(&tscm->hwdep_wait); 113 + return; 120 114 121 115 err = identify_model(tscm); 122 116 if (err < 0) 123 117 goto error; 124 118 125 - snd_tscm_proc_init(tscm); 119 + err = snd_tscm_transaction_register(tscm); 120 + if (err < 0) 121 + goto error; 126 122 127 123 err = snd_tscm_stream_init_duplex(tscm); 128 124 if (err < 0) 129 125 goto error; 130 126 131 - err = snd_tscm_create_pcm_devices(tscm); 132 - if (err < 0) 133 - goto error; 127 + snd_tscm_proc_init(tscm); 134 128 135 - err = snd_tscm_transaction_register(tscm); 129 + err = snd_tscm_create_pcm_devices(tscm); 136 130 if (err < 0) 137 131 goto error; 138 132 ··· 136 146 if (err < 0) 137 147 goto error; 138 148 139 - err = snd_card_register(card); 149 + err = snd_card_register(tscm->card); 140 150 if (err < 0) 141 151 goto error; 142 152 153 + /* 154 + * After registered, tscm instance can be released corresponding to 155 + * releasing the sound card instance. 156 + */ 157 + tscm->card->private_free = tscm_card_free; 158 + tscm->card->private_data = tscm; 159 + tscm->registered = true; 160 + 161 + return; 162 + error: 163 + snd_tscm_transaction_unregister(tscm); 164 + snd_tscm_stream_destroy_duplex(tscm); 165 + snd_card_free(tscm->card); 166 + dev_info(&tscm->unit->device, 167 + "Sound card registration failed: %d\n", err); 168 + } 169 + 170 + static int snd_tscm_probe(struct fw_unit *unit, 171 + const struct ieee1394_device_id *entry) 172 + { 173 + struct snd_tscm *tscm; 174 + 175 + /* Allocate this independent of sound card instance. */ 176 + tscm = kzalloc(sizeof(struct snd_tscm), GFP_KERNEL); 177 + if (tscm == NULL) 178 + return -ENOMEM; 179 + 180 + /* initialize myself */ 181 + tscm->unit = fw_unit_get(unit); 143 182 dev_set_drvdata(&unit->device, tscm); 144 183 145 - return err; 146 - error: 147 - snd_card_free(card); 148 - return err; 184 + mutex_init(&tscm->mutex); 185 + spin_lock_init(&tscm->lock); 186 + init_waitqueue_head(&tscm->hwdep_wait); 187 + 188 + /* Allocate and register this sound card later. */ 189 + INIT_DEFERRABLE_WORK(&tscm->dwork, do_registration); 190 + snd_fw_schedule_registration(unit, &tscm->dwork); 191 + 192 + return 0; 149 193 } 150 194 151 195 static void snd_tscm_update(struct fw_unit *unit) 152 196 { 153 197 struct snd_tscm *tscm = dev_get_drvdata(&unit->device); 154 198 199 + /* Postpone a workqueue for deferred registration. */ 200 + if (!tscm->registered) 201 + snd_fw_schedule_registration(unit, &tscm->dwork); 202 + 155 203 snd_tscm_transaction_reregister(tscm); 156 204 157 - mutex_lock(&tscm->mutex); 158 - snd_tscm_stream_update_duplex(tscm); 159 - mutex_unlock(&tscm->mutex); 205 + /* 206 + * After registration, userspace can start packet streaming, then this 207 + * code block works fine. 208 + */ 209 + if (tscm->registered) { 210 + mutex_lock(&tscm->mutex); 211 + snd_tscm_stream_update_duplex(tscm); 212 + mutex_unlock(&tscm->mutex); 213 + } 160 214 } 161 215 162 216 static void snd_tscm_remove(struct fw_unit *unit) 163 217 { 164 218 struct snd_tscm *tscm = dev_get_drvdata(&unit->device); 165 219 166 - /* No need to wait for releasing card object in this context. */ 167 - snd_card_free_when_closed(tscm->card); 220 + /* 221 + * Confirm to stop the work for registration before the sound card is 222 + * going to be released. The work is not scheduled again because bus 223 + * reset handler is not called anymore. 224 + */ 225 + cancel_delayed_work_sync(&tscm->dwork); 226 + 227 + if (tscm->registered) { 228 + /* No need to wait for releasing card object in this context. */ 229 + snd_card_free_when_closed(tscm->card); 230 + } else { 231 + /* Don't forget this case. */ 232 + tscm_free(tscm); 233 + } 168 234 } 169 235 170 236 static const struct ieee1394_device_id snd_tscm_id_table[] = {
+2
sound/firewire/tascam/tascam.h
··· 51 51 struct mutex mutex; 52 52 spinlock_t lock; 53 53 54 + bool registered; 55 + struct delayed_work dwork; 54 56 const struct snd_tscm_spec *spec; 55 57 56 58 struct fw_iso_resources tx_resources;
+1
sound/hda/ext/hdac_ext_bus.c
··· 144 144 if (!edev) 145 145 return -ENOMEM; 146 146 hdev = &edev->hdac; 147 + edev->ebus = ebus; 147 148 148 149 snprintf(name, sizeof(name), "ehdaudio%dD%d", ebus->idx, addr); 149 150
+17
sound/hda/hdac_controller.c
··· 80 80 } 81 81 EXPORT_SYMBOL_GPL(snd_hdac_bus_init_cmd_io); 82 82 83 + /* wait for cmd dmas till they are stopped */ 84 + static void hdac_wait_for_cmd_dmas(struct hdac_bus *bus) 85 + { 86 + unsigned long timeout; 87 + 88 + timeout = jiffies + msecs_to_jiffies(100); 89 + while ((snd_hdac_chip_readb(bus, RIRBCTL) & AZX_RBCTL_DMA_EN) 90 + && time_before(jiffies, timeout)) 91 + udelay(10); 92 + 93 + timeout = jiffies + msecs_to_jiffies(100); 94 + while ((snd_hdac_chip_readb(bus, CORBCTL) & AZX_CORBCTL_RUN) 95 + && time_before(jiffies, timeout)) 96 + udelay(10); 97 + } 98 + 83 99 /** 84 100 * snd_hdac_bus_stop_cmd_io - clean up CORB/RIRB buffers 85 101 * @bus: HD-audio core bus ··· 106 90 /* disable ringbuffer DMAs */ 107 91 snd_hdac_chip_writeb(bus, RIRBCTL, 0); 108 92 snd_hdac_chip_writeb(bus, CORBCTL, 0); 93 + hdac_wait_for_cmd_dmas(bus); 109 94 /* disable unsolicited responses */ 110 95 snd_hdac_chip_updatel(bus, GCTL, AZX_GCTL_UNSOL, 0); 111 96 spin_unlock_irq(&bus->reg_lock);
+36 -11
sound/hda/hdac_i915.c
··· 158 158 } 159 159 EXPORT_SYMBOL_GPL(snd_hdac_i915_set_bclk); 160 160 161 - /* There is a fixed mapping between audio pin node and display port 162 - * on current Intel platforms: 161 + /* There is a fixed mapping between audio pin node and display port. 162 + * on SNB, IVY, HSW, BSW, SKL, BXT, KBL: 163 163 * Pin Widget 5 - PORT B (port = 1 in i915 driver) 164 164 * Pin Widget 6 - PORT C (port = 2 in i915 driver) 165 165 * Pin Widget 7 - PORT D (port = 3 in i915 driver) 166 + * 167 + * on VLV, ILK: 168 + * Pin Widget 4 - PORT B (port = 1 in i915 driver) 169 + * Pin Widget 5 - PORT C (port = 2 in i915 driver) 170 + * Pin Widget 6 - PORT D (port = 3 in i915 driver) 166 171 */ 167 - static int pin2port(hda_nid_t pin_nid) 172 + static int pin2port(struct hdac_device *codec, hda_nid_t pin_nid) 168 173 { 169 - if (WARN_ON(pin_nid < 5 || pin_nid > 7)) 174 + int base_nid; 175 + 176 + switch (codec->vendor_id) { 177 + case 0x80860054: /* ILK */ 178 + case 0x80862804: /* ILK */ 179 + case 0x80862882: /* VLV */ 180 + base_nid = 3; 181 + break; 182 + default: 183 + base_nid = 4; 184 + break; 185 + } 186 + 187 + if (WARN_ON(pin_nid <= base_nid || pin_nid > base_nid + 3)) 170 188 return -1; 171 - return pin_nid - 4; 189 + return pin_nid - base_nid; 172 190 } 173 191 174 192 /** 175 193 * snd_hdac_sync_audio_rate - Set N/CTS based on the sample rate 176 - * @bus: HDA core bus 194 + * @codec: HDA codec 177 195 * @nid: the pin widget NID 178 196 * @rate: the sample rate to set 179 197 * ··· 201 183 * This function sets N/CTS value based on the given sample rate. 202 184 * Returns zero for success, or a negative error code. 203 185 */ 204 - int snd_hdac_sync_audio_rate(struct hdac_bus *bus, hda_nid_t nid, int rate) 186 + int snd_hdac_sync_audio_rate(struct hdac_device *codec, hda_nid_t nid, int rate) 205 187 { 188 + struct hdac_bus *bus = codec->bus; 206 189 struct i915_audio_component *acomp = bus->audio_component; 207 190 int port; 208 191 209 192 if (!acomp || !acomp->ops || !acomp->ops->sync_audio_rate) 210 193 return -ENODEV; 211 - port = pin2port(nid); 194 + port = pin2port(codec, nid); 212 195 if (port < 0) 213 196 return -EINVAL; 214 197 return acomp->ops->sync_audio_rate(acomp->dev, port, rate); ··· 218 199 219 200 /** 220 201 * snd_hdac_acomp_get_eld - Get the audio state and ELD via component 221 - * @bus: HDA core bus 202 + * @codec: HDA codec 222 203 * @nid: the pin widget NID 223 204 * @audio_enabled: the pointer to store the current audio state 224 205 * @buffer: the buffer pointer to store ELD bytes ··· 236 217 * thus it may be over @max_bytes. If it's over @max_bytes, it implies 237 218 * that only a part of ELD bytes have been fetched. 238 219 */ 239 - int snd_hdac_acomp_get_eld(struct hdac_bus *bus, hda_nid_t nid, 220 + int snd_hdac_acomp_get_eld(struct hdac_device *codec, hda_nid_t nid, 240 221 bool *audio_enabled, char *buffer, int max_bytes) 241 222 { 223 + struct hdac_bus *bus = codec->bus; 242 224 struct i915_audio_component *acomp = bus->audio_component; 243 225 int port; 244 226 245 227 if (!acomp || !acomp->ops || !acomp->ops->get_eld) 246 228 return -ENODEV; 247 229 248 - port = pin2port(nid); 230 + port = pin2port(codec, nid); 249 231 if (port < 0) 250 232 return -EINVAL; 251 233 return acomp->ops->get_eld(acomp->dev, port, audio_enabled, ··· 358 338 struct i915_audio_component *acomp; 359 339 int ret; 360 340 341 + if (WARN_ON(hdac_acomp)) 342 + return -EBUSY; 343 + 361 344 if (!i915_gfx_present()) 362 345 return -ENODEV; 363 346 ··· 394 371 out_err: 395 372 kfree(acomp); 396 373 bus->audio_component = NULL; 374 + hdac_acomp = NULL; 397 375 dev_info(dev, "failed to add i915 component master (%d)\n", ret); 398 376 399 377 return ret; ··· 428 404 429 405 kfree(acomp); 430 406 bus->audio_component = NULL; 407 + hdac_acomp = NULL; 431 408 432 409 return 0; 433 410 }
+40 -4
sound/hda/hdmi_chmap.c
··· 625 625 WARN_ON(count != channels); 626 626 } 627 627 628 + static int spk_mask_from_spk_alloc(int spk_alloc) 629 + { 630 + int i; 631 + int spk_mask = eld_speaker_allocation_bits[0]; 632 + 633 + for (i = 0; i < ARRAY_SIZE(eld_speaker_allocation_bits); i++) { 634 + if (spk_alloc & (1 << i)) 635 + spk_mask |= eld_speaker_allocation_bits[i]; 636 + } 637 + 638 + return spk_mask; 639 + } 640 + 628 641 static int hdmi_chmap_ctl_tlv(struct snd_kcontrol *kcontrol, int op_flag, 629 642 unsigned int size, unsigned int __user *tlv) 630 643 { 631 644 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol); 632 645 struct hdac_chmap *chmap = info->private_data; 646 + int pcm_idx = kcontrol->private_value; 633 647 unsigned int __user *dst; 634 648 int chs, count = 0; 649 + unsigned long max_chs; 650 + int type; 651 + int spk_alloc, spk_mask; 635 652 636 653 if (size < 8) 637 654 return -ENOMEM; ··· 656 639 return -EFAULT; 657 640 size -= 8; 658 641 dst = tlv + 2; 659 - for (chs = 2; chs <= chmap->channels_max; chs++) { 642 + 643 + spk_alloc = chmap->ops.get_spk_alloc(chmap->hdac, pcm_idx); 644 + spk_mask = spk_mask_from_spk_alloc(spk_alloc); 645 + 646 + max_chs = hweight_long(spk_mask); 647 + 648 + for (chs = 2; chs <= max_chs; chs++) { 660 649 int i; 661 650 struct hdac_cea_channel_speaker_allocation *cap; 662 651 663 652 cap = channel_allocations; 664 653 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++, cap++) { 665 654 int chs_bytes = chs * 4; 666 - int type = chmap->ops.chmap_cea_alloc_validate_get_type( 667 - chmap, cap, chs); 668 655 unsigned int tlv_chmap[8]; 669 656 670 - if (type < 0) 657 + if (cap->channels != chs) 671 658 continue; 659 + 660 + if (!(cap->spk_mask == (spk_mask & cap->spk_mask))) 661 + continue; 662 + 663 + type = chmap->ops.chmap_cea_alloc_validate_get_type( 664 + chmap, cap, chs); 665 + if (type < 0) 666 + return -ENODEV; 672 667 if (size < 8) 673 668 return -ENOMEM; 669 + 674 670 if (put_user(type, dst) || 675 671 put_user(chs_bytes, dst + 1)) 676 672 return -EFAULT; 673 + 677 674 dst += 2; 678 675 size -= 8; 679 676 count += 8; 677 + 680 678 if (size < chs_bytes) 681 679 return -ENOMEM; 680 + 682 681 size -= chs_bytes; 683 682 count += chs_bytes; 684 683 chmap->ops.cea_alloc_to_tlv_chmap(chmap, cap, 685 684 tlv_chmap, chs); 685 + 686 686 if (copy_to_user(dst, tlv_chmap, chs_bytes)) 687 687 return -EFAULT; 688 688 dst += chs; 689 689 } 690 690 } 691 + 691 692 if (put_user(count, tlv + 1)) 692 693 return -EFAULT; 694 + 693 695 return 0; 694 696 } 695 697
+9
sound/isa/wavefront/wavefront_synth.c
··· 785 785 DPRINT (WF_DEBUG_LOAD_PATCH, "downloading patch %d\n", 786 786 header->number); 787 787 788 + if (header->number >= ARRAY_SIZE(dev->patch_status)) 789 + return -EINVAL; 790 + 788 791 dev->patch_status[header->number] |= WF_SLOT_FILLED; 789 792 790 793 bptr = buf; ··· 811 808 812 809 DPRINT (WF_DEBUG_LOAD_PATCH, "downloading program %d\n", 813 810 header->number); 811 + 812 + if (header->number >= ARRAY_SIZE(dev->prog_status)) 813 + return -EINVAL; 814 814 815 815 dev->prog_status[header->number] = WF_SLOT_USED; 816 816 ··· 903 897 snd_printk ("unspecified sample => %d\n", x); 904 898 header->number = x; 905 899 } 900 + 901 + if (header->number >= WF_MAX_SAMPLE) 902 + return -EINVAL; 906 903 907 904 if (header->size) { 908 905
+5 -9
sound/pci/au88x0/au88x0_core.c
··· 2151 2151 stream->resources, en, 2152 2152 VORTEX_RESOURCE_SRC)) < 0) { 2153 2153 memset(stream->resources, 0, 2154 - sizeof(unsigned char) * 2155 - VORTEX_RESOURCE_LAST); 2154 + sizeof(stream->resources)); 2156 2155 return -EBUSY; 2157 2156 } 2158 2157 if (stream->type != VORTEX_PCM_A3D) { ··· 2161 2162 VORTEX_RESOURCE_MIXIN)) < 0) { 2162 2163 memset(stream->resources, 2163 2164 0, 2164 - sizeof(unsigned char) * VORTEX_RESOURCE_LAST); 2165 + sizeof(stream->resources)); 2165 2166 return -EBUSY; 2166 2167 } 2167 2168 } ··· 2174 2175 stream->resources, en, 2175 2176 VORTEX_RESOURCE_A3D)) < 0) { 2176 2177 memset(stream->resources, 0, 2177 - sizeof(unsigned char) * 2178 - VORTEX_RESOURCE_LAST); 2178 + sizeof(stream->resources)); 2179 2179 dev_err(vortex->card->dev, 2180 2180 "out of A3D sources. Sorry\n"); 2181 2181 return -EBUSY; ··· 2288 2290 VORTEX_RESOURCE_MIXOUT)) 2289 2291 < 0) { 2290 2292 memset(stream->resources, 0, 2291 - sizeof(unsigned char) * 2292 - VORTEX_RESOURCE_LAST); 2293 + sizeof(stream->resources)); 2293 2294 return -EBUSY; 2294 2295 } 2295 2296 if ((src[i] = ··· 2296 2299 stream->resources, en, 2297 2300 VORTEX_RESOURCE_SRC)) < 0) { 2298 2301 memset(stream->resources, 0, 2299 - sizeof(unsigned char) * 2300 - VORTEX_RESOURCE_LAST); 2302 + sizeof(stream->resources)); 2301 2303 return -EBUSY; 2302 2304 } 2303 2305 }
+4 -1
sound/pci/au88x0/au88x0_pcm.c
··· 432 432 #endif 433 433 //printk(KERN_INFO "vortex: pointer = 0x%x\n", current_ptr); 434 434 spin_unlock(&chip->lock); 435 - return (bytes_to_frames(substream->runtime, current_ptr)); 435 + current_ptr = bytes_to_frames(substream->runtime, current_ptr); 436 + if (current_ptr >= substream->runtime->buffer_size) 437 + current_ptr = 0; 438 + return current_ptr; 436 439 } 437 440 438 441 /* operators */
+3 -3
sound/pci/ctxfi/cttimer.c
··· 49 49 spinlock_t lock; /* global timer lock (for xfitimer) */ 50 50 spinlock_t list_lock; /* lock for instance list */ 51 51 struct ct_atc *atc; 52 - struct ct_timer_ops *ops; 52 + const struct ct_timer_ops *ops; 53 53 struct list_head instance_head; 54 54 struct list_head running_head; 55 55 unsigned int wc; /* current wallclock */ ··· 128 128 129 129 #define ct_systimer_free ct_systimer_prepare 130 130 131 - static struct ct_timer_ops ct_systimer_ops = { 131 + static const struct ct_timer_ops ct_systimer_ops = { 132 132 .init = ct_systimer_init, 133 133 .free_instance = ct_systimer_free, 134 134 .prepare = ct_systimer_prepare, ··· 322 322 ct_xfitimer_irq_stop(atimer); 323 323 } 324 324 325 - static struct ct_timer_ops ct_xfitimer_ops = { 325 + static const struct ct_timer_ops ct_xfitimer_ops = { 326 326 .prepare = ct_xfitimer_prepare, 327 327 .start = ct_xfitimer_start, 328 328 .stop = ct_xfitimer_stop,
+1 -1
sound/pci/ens1370.c
··· 1548 1548 int val = 0; 1549 1549 1550 1550 spin_lock_irq(&ensoniq->reg_lock); 1551 - if ((ensoniq->ctrl & ES_1371_GPIO_OUTM) >= 4) 1551 + if (ensoniq->ctrl & ES_1371_GPIO_OUT(4)) 1552 1552 val = 1; 1553 1553 ucontrol->value.integer.value[0] = val; 1554 1554 spin_unlock_irq(&ensoniq->reg_lock);
+7 -3
sound/pci/hda/Kconfig
··· 50 50 bool "Allow dynamic codec reconfiguration" 51 51 help 52 52 Say Y here to enable the HD-audio codec re-configuration feature. 53 - This adds the sysfs interfaces to allow user to clear the whole 54 - codec configuration, change the codec setup, add extra verbs, 55 - and re-configure the codec dynamically. 53 + It allows user to clear the whole codec configuration, change the 54 + codec setup, add extra verbs, and re-configure the codec dynamically. 55 + 56 + Note that this item alone doesn't provide the sysfs interface, but 57 + enables the feature just for the patch loader below. 58 + If you need the traditional sysfs entries for the manual interaction, 59 + turn on CONFIG_SND_HDA_HWDEP as well. 56 60 57 61 config SND_HDA_INPUT_BEEP 58 62 bool "Support digital beep via input layer"
+2
sound/pci/hda/hda_generic.c
··· 5434 5434 spec->cur_adc_stream_tag = stream_tag; 5435 5435 spec->cur_adc_format = format; 5436 5436 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); 5437 + call_pcm_capture_hook(hinfo, codec, substream, HDA_GEN_PCM_ACT_PREPARE); 5437 5438 return 0; 5438 5439 } 5439 5440 ··· 5445 5444 struct hda_gen_spec *spec = codec->spec; 5446 5445 snd_hda_codec_cleanup_stream(codec, spec->cur_adc); 5447 5446 spec->cur_adc = 0; 5447 + call_pcm_capture_hook(hinfo, codec, substream, HDA_GEN_PCM_ACT_CLEANUP); 5448 5448 return 0; 5449 5449 } 5450 5450
+274 -126
sound/pci/hda/patch_hdmi.c
··· 114 114 int (*setup_stream)(struct hda_codec *codec, hda_nid_t cvt_nid, 115 115 hda_nid_t pin_nid, u32 stream_tag, int format); 116 116 117 + void (*pin_cvt_fixup)(struct hda_codec *codec, 118 + struct hdmi_spec_per_pin *per_pin, 119 + hda_nid_t cvt_nid); 117 120 }; 118 121 119 122 struct hdmi_pcm { ··· 687 684 if (!channels) 688 685 return; 689 686 690 - if (is_haswell_plus(codec)) 687 + /* some HW (e.g. HSW+) needs reprogramming the amp at each time */ 688 + if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP) 691 689 snd_hda_codec_write(codec, pin_nid, 0, 692 690 AC_VERB_SET_AMP_GAIN_MUTE, 693 691 AMP_OUT_UNMUTE); ··· 868 864 struct hdmi_spec *spec = codec->spec; 869 865 int err; 870 866 871 - if (is_haswell_plus(codec)) 872 - haswell_verify_D0(codec, cvt_nid, pin_nid); 873 - 874 867 err = spec->ops.pin_hbr_setup(codec, pin_nid, is_hbr_format(format)); 875 868 876 869 if (err) { ··· 885 884 * of the pin. 886 885 */ 887 886 static int hdmi_choose_cvt(struct hda_codec *codec, 888 - int pin_idx, int *cvt_id, int *mux_id) 887 + int pin_idx, int *cvt_id) 889 888 { 890 889 struct hdmi_spec *spec = codec->spec; 891 890 struct hdmi_spec_per_pin *per_pin; ··· 926 925 927 926 if (cvt_id) 928 927 *cvt_id = cvt_idx; 929 - if (mux_id) 930 - *mux_id = mux_idx; 931 928 932 929 return 0; 933 930 } ··· 1018 1019 int mux_idx; 1019 1020 struct hdmi_spec *spec = codec->spec; 1020 1021 1021 - if (!is_haswell_plus(codec) && !is_valleyview_plus(codec)) 1022 - return; 1023 - 1024 1022 /* On Intel platform, the mapping of converter nid to 1025 1023 * mux index of the pins are always the same. 1026 1024 * The pin nid may be 0, this means all pins will not ··· 1026 1030 mux_idx = intel_cvt_id_to_mux_idx(spec, cvt_nid); 1027 1031 if (mux_idx >= 0) 1028 1032 intel_not_share_assigned_cvt(codec, pin_nid, mux_idx); 1033 + } 1034 + 1035 + /* skeleton caller of pin_cvt_fixup ops */ 1036 + static void pin_cvt_fixup(struct hda_codec *codec, 1037 + struct hdmi_spec_per_pin *per_pin, 1038 + hda_nid_t cvt_nid) 1039 + { 1040 + struct hdmi_spec *spec = codec->spec; 1041 + 1042 + if (spec->ops.pin_cvt_fixup) 1043 + spec->ops.pin_cvt_fixup(codec, per_pin, cvt_nid); 1029 1044 } 1030 1045 1031 1046 /* called in hdmi_pcm_open when no pin is assigned to the PCM ··· 1056 1049 if (pcm_idx < 0) 1057 1050 return -EINVAL; 1058 1051 1059 - err = hdmi_choose_cvt(codec, -1, &cvt_idx, NULL); 1052 + err = hdmi_choose_cvt(codec, -1, &cvt_idx); 1060 1053 if (err) 1061 1054 return err; 1062 1055 ··· 1064 1057 per_cvt->assigned = 1; 1065 1058 hinfo->nid = per_cvt->cvt_nid; 1066 1059 1067 - intel_not_share_assigned_cvt_nid(codec, 0, per_cvt->cvt_nid); 1060 + pin_cvt_fixup(codec, NULL, per_cvt->cvt_nid); 1068 1061 1069 1062 set_bit(pcm_idx, &spec->pcm_in_use); 1070 1063 /* todo: setup spdif ctls assign */ ··· 1096 1089 { 1097 1090 struct hdmi_spec *spec = codec->spec; 1098 1091 struct snd_pcm_runtime *runtime = substream->runtime; 1099 - int pin_idx, cvt_idx, pcm_idx, mux_idx = 0; 1092 + int pin_idx, cvt_idx, pcm_idx; 1100 1093 struct hdmi_spec_per_pin *per_pin; 1101 1094 struct hdmi_eld *eld; 1102 1095 struct hdmi_spec_per_cvt *per_cvt = NULL; ··· 1125 1118 } 1126 1119 } 1127 1120 1128 - err = hdmi_choose_cvt(codec, pin_idx, &cvt_idx, &mux_idx); 1121 + err = hdmi_choose_cvt(codec, pin_idx, &cvt_idx); 1129 1122 if (err < 0) { 1130 1123 mutex_unlock(&spec->pcm_lock); 1131 1124 return err; ··· 1142 1135 1143 1136 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0, 1144 1137 AC_VERB_SET_CONNECT_SEL, 1145 - mux_idx); 1138 + per_pin->mux_idx); 1146 1139 1147 1140 /* configure unused pins to choose other converters */ 1148 - if (is_haswell_plus(codec) || is_valleyview_plus(codec)) 1149 - intel_not_share_assigned_cvt(codec, per_pin->pin_nid, mux_idx); 1141 + pin_cvt_fixup(codec, per_pin, 0); 1150 1142 1151 1143 snd_hda_spdif_ctls_assign(codec, pcm_idx, per_cvt->cvt_nid); 1152 1144 ··· 1378 1372 * and this can make HW reset converter selection on a pin. 1379 1373 */ 1380 1374 if (eld->eld_valid && !old_eld_valid && per_pin->setup) { 1381 - if (is_haswell_plus(codec) || is_valleyview_plus(codec)) { 1382 - intel_verify_pin_cvt_connect(codec, per_pin); 1383 - intel_not_share_assigned_cvt(codec, per_pin->pin_nid, 1384 - per_pin->mux_idx); 1385 - } 1386 - 1375 + pin_cvt_fixup(codec, per_pin, 0); 1387 1376 hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm); 1388 1377 } 1389 1378 ··· 1485 1484 1486 1485 mutex_lock(&per_pin->lock); 1487 1486 eld->monitor_present = false; 1488 - size = snd_hdac_acomp_get_eld(&codec->bus->core, per_pin->pin_nid, 1487 + size = snd_hdac_acomp_get_eld(&codec->core, per_pin->pin_nid, 1489 1488 &eld->monitor_present, eld->eld_buffer, 1490 1489 ELD_MAX_SIZE); 1491 1490 if (size > 0) { ··· 1712 1711 * skip pin setup and return 0 to make audio playback 1713 1712 * be ongoing 1714 1713 */ 1715 - intel_not_share_assigned_cvt_nid(codec, 0, cvt_nid); 1714 + pin_cvt_fixup(codec, NULL, cvt_nid); 1716 1715 snd_hda_codec_setup_stream(codec, cvt_nid, 1717 1716 stream_tag, 0, format); 1718 1717 mutex_unlock(&spec->pcm_lock); ··· 1725 1724 } 1726 1725 per_pin = get_pin(spec, pin_idx); 1727 1726 pin_nid = per_pin->pin_nid; 1728 - if (is_haswell_plus(codec) || is_valleyview_plus(codec)) { 1729 - /* Verify pin:cvt selections to avoid silent audio after S3. 1730 - * After S3, the audio driver restores pin:cvt selections 1731 - * but this can happen before gfx is ready and such selection 1732 - * is overlooked by HW. Thus multiple pins can share a same 1733 - * default convertor and mute control will affect each other, 1734 - * which can cause a resumed audio playback become silent 1735 - * after S3. 1736 - */ 1737 - intel_verify_pin_cvt_connect(codec, per_pin); 1738 - intel_not_share_assigned_cvt(codec, pin_nid, per_pin->mux_idx); 1739 - } 1727 + 1728 + /* Verify pin:cvt selections to avoid silent audio after S3. 1729 + * After S3, the audio driver restores pin:cvt selections 1730 + * but this can happen before gfx is ready and such selection 1731 + * is overlooked by HW. Thus multiple pins can share a same 1732 + * default convertor and mute control will affect each other, 1733 + * which can cause a resumed audio playback become silent 1734 + * after S3. 1735 + */ 1736 + pin_cvt_fixup(codec, per_pin, 0); 1740 1737 1741 1738 /* Call sync_audio_rate to set the N/CTS/M manually if necessary */ 1742 1739 /* Todo: add DP1.2 MST audio support later */ 1743 1740 if (codec_has_acomp(codec)) 1744 - snd_hdac_sync_audio_rate(&codec->bus->core, pin_nid, runtime->rate); 1741 + snd_hdac_sync_audio_rate(&codec->core, pin_nid, runtime->rate); 1745 1742 1746 1743 non_pcm = check_non_pcm_per_cvt(codec, cvt_nid); 1747 1744 mutex_lock(&per_pin->lock); ··· 1835 1836 .prepare = generic_hdmi_playback_pcm_prepare, 1836 1837 .cleanup = generic_hdmi_playback_pcm_cleanup, 1837 1838 }; 1839 + 1840 + static int hdmi_get_spk_alloc(struct hdac_device *hdac, int pcm_idx) 1841 + { 1842 + struct hda_codec *codec = container_of(hdac, struct hda_codec, core); 1843 + struct hdmi_spec *spec = codec->spec; 1844 + struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx); 1845 + 1846 + if (!per_pin) 1847 + return 0; 1848 + 1849 + return per_pin->sink_eld.info.spk_alloc; 1850 + } 1838 1851 1839 1852 static void hdmi_get_chmap(struct hdac_device *hdac, int pcm_idx, 1840 1853 unsigned char *chmap) ··· 2086 2075 snd_array_free(&spec->cvts); 2087 2076 } 2088 2077 2078 + static void generic_spec_free(struct hda_codec *codec) 2079 + { 2080 + struct hdmi_spec *spec = codec->spec; 2081 + 2082 + if (spec) { 2083 + if (spec->i915_bound) 2084 + snd_hdac_i915_exit(&codec->bus->core); 2085 + hdmi_array_free(spec); 2086 + kfree(spec); 2087 + codec->spec = NULL; 2088 + } 2089 + codec->dp_mst = false; 2090 + } 2091 + 2089 2092 static void generic_hdmi_free(struct hda_codec *codec) 2090 2093 { 2091 2094 struct hdmi_spec *spec = codec->spec; ··· 2124 2099 spec->pcm_rec[pcm_idx].jack = NULL; 2125 2100 } 2126 2101 2127 - if (spec->i915_bound) 2128 - snd_hdac_i915_exit(&codec->bus->core); 2129 - hdmi_array_free(spec); 2130 - kfree(spec); 2102 + generic_spec_free(codec); 2131 2103 } 2132 2104 2133 2105 #ifdef CONFIG_PM ··· 2161 2139 .pin_hbr_setup = hdmi_pin_hbr_setup, 2162 2140 .setup_stream = hdmi_setup_stream, 2163 2141 }; 2142 + 2143 + /* allocate codec->spec and assign/initialize generic parser ops */ 2144 + static int alloc_generic_hdmi(struct hda_codec *codec) 2145 + { 2146 + struct hdmi_spec *spec; 2147 + 2148 + spec = kzalloc(sizeof(*spec), GFP_KERNEL); 2149 + if (!spec) 2150 + return -ENOMEM; 2151 + 2152 + spec->ops = generic_standard_hdmi_ops; 2153 + mutex_init(&spec->pcm_lock); 2154 + snd_hdac_register_chmap_ops(&codec->core, &spec->chmap); 2155 + 2156 + spec->chmap.ops.get_chmap = hdmi_get_chmap; 2157 + spec->chmap.ops.set_chmap = hdmi_set_chmap; 2158 + spec->chmap.ops.is_pcm_attached = is_hdmi_pcm_attached; 2159 + spec->chmap.ops.get_spk_alloc = hdmi_get_spk_alloc, 2160 + 2161 + codec->spec = spec; 2162 + hdmi_array_init(spec, 4); 2163 + 2164 + codec->patch_ops = generic_hdmi_patch_ops; 2165 + 2166 + return 0; 2167 + } 2168 + 2169 + /* generic HDMI parser */ 2170 + static int patch_generic_hdmi(struct hda_codec *codec) 2171 + { 2172 + int err; 2173 + 2174 + err = alloc_generic_hdmi(codec); 2175 + if (err < 0) 2176 + return err; 2177 + 2178 + err = hdmi_parse_codec(codec); 2179 + if (err < 0) { 2180 + generic_spec_free(codec); 2181 + return err; 2182 + } 2183 + 2184 + generic_hdmi_init_per_pins(codec); 2185 + return 0; 2186 + } 2187 + 2188 + /* 2189 + * Intel codec parsers and helpers 2190 + */ 2164 2191 2165 2192 static void intel_haswell_fixup_connect_list(struct hda_codec *codec, 2166 2193 hda_nid_t nid) ··· 2288 2217 static void intel_pin_eld_notify(void *audio_ptr, int port) 2289 2218 { 2290 2219 struct hda_codec *codec = audio_ptr; 2291 - int pin_nid = port + 0x04; 2220 + int pin_nid; 2292 2221 2293 2222 /* we assume only from port-B to port-D */ 2294 2223 if (port < 1 || port > 3) 2295 2224 return; 2225 + 2226 + switch (codec->core.vendor_id) { 2227 + case 0x80860054: /* ILK */ 2228 + case 0x80862804: /* ILK */ 2229 + case 0x80862882: /* VLV */ 2230 + pin_nid = port + 0x03; 2231 + break; 2232 + default: 2233 + pin_nid = port + 0x04; 2234 + break; 2235 + } 2296 2236 2297 2237 /* skip notification during system suspend (but not in runtime PM); 2298 2238 * the state will be updated at resume ··· 2318 2236 check_presence_and_report(codec, pin_nid); 2319 2237 } 2320 2238 2321 - static int patch_generic_hdmi(struct hda_codec *codec) 2239 + /* register i915 component pin_eld_notify callback */ 2240 + static void register_i915_notifier(struct hda_codec *codec) 2241 + { 2242 + struct hdmi_spec *spec = codec->spec; 2243 + 2244 + spec->use_acomp_notifier = true; 2245 + spec->i915_audio_ops.audio_ptr = codec; 2246 + /* intel_audio_codec_enable() or intel_audio_codec_disable() 2247 + * will call pin_eld_notify with using audio_ptr pointer 2248 + * We need make sure audio_ptr is really setup 2249 + */ 2250 + wmb(); 2251 + spec->i915_audio_ops.pin_eld_notify = intel_pin_eld_notify; 2252 + snd_hdac_i915_register_notifier(&spec->i915_audio_ops); 2253 + } 2254 + 2255 + /* setup_stream ops override for HSW+ */ 2256 + static int i915_hsw_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid, 2257 + hda_nid_t pin_nid, u32 stream_tag, int format) 2258 + { 2259 + haswell_verify_D0(codec, cvt_nid, pin_nid); 2260 + return hdmi_setup_stream(codec, cvt_nid, pin_nid, stream_tag, format); 2261 + } 2262 + 2263 + /* pin_cvt_fixup ops override for HSW+ and VLV+ */ 2264 + static void i915_pin_cvt_fixup(struct hda_codec *codec, 2265 + struct hdmi_spec_per_pin *per_pin, 2266 + hda_nid_t cvt_nid) 2267 + { 2268 + if (per_pin) { 2269 + intel_verify_pin_cvt_connect(codec, per_pin); 2270 + intel_not_share_assigned_cvt(codec, per_pin->pin_nid, 2271 + per_pin->mux_idx); 2272 + } else { 2273 + intel_not_share_assigned_cvt_nid(codec, 0, cvt_nid); 2274 + } 2275 + } 2276 + 2277 + /* Intel Haswell and onwards; audio component with eld notifier */ 2278 + static int patch_i915_hsw_hdmi(struct hda_codec *codec) 2322 2279 { 2323 2280 struct hdmi_spec *spec; 2281 + int err; 2324 2282 2325 - spec = kzalloc(sizeof(*spec), GFP_KERNEL); 2326 - if (spec == NULL) 2327 - return -ENOMEM; 2328 - 2329 - spec->ops = generic_standard_hdmi_ops; 2330 - mutex_init(&spec->pcm_lock); 2331 - snd_hdac_register_chmap_ops(&codec->core, &spec->chmap); 2332 - 2333 - spec->chmap.ops.get_chmap = hdmi_get_chmap; 2334 - spec->chmap.ops.set_chmap = hdmi_set_chmap; 2335 - spec->chmap.ops.is_pcm_attached = is_hdmi_pcm_attached; 2336 - 2337 - codec->spec = spec; 2338 - hdmi_array_init(spec, 4); 2339 - 2340 - #ifdef CONFIG_SND_HDA_I915 2341 - /* Try to bind with i915 for Intel HSW+ codecs (if not done yet) */ 2342 - if ((codec->core.vendor_id >> 16) == 0x8086 && 2343 - is_haswell_plus(codec)) { 2344 - #if 0 2345 - /* on-demand binding leads to an unbalanced refcount when 2346 - * both i915 and hda drivers are probed concurrently; 2347 - * disabled temporarily for now 2348 - */ 2349 - if (!codec->bus->core.audio_component) 2350 - if (!snd_hdac_i915_init(&codec->bus->core)) 2351 - spec->i915_bound = true; 2352 - #endif 2353 - /* use i915 audio component notifier for hotplug */ 2354 - if (codec->bus->core.audio_component) 2355 - spec->use_acomp_notifier = true; 2283 + /* HSW+ requires i915 binding */ 2284 + if (!codec->bus->core.audio_component) { 2285 + codec_info(codec, "No i915 binding for Intel HDMI/DP codec\n"); 2286 + return -ENODEV; 2356 2287 } 2357 - #endif 2358 2288 2359 - if (is_haswell_plus(codec)) { 2360 - intel_haswell_enable_all_pins(codec, true); 2361 - intel_haswell_fixup_enable_dp12(codec); 2289 + err = alloc_generic_hdmi(codec); 2290 + if (err < 0) 2291 + return err; 2292 + spec = codec->spec; 2293 + 2294 + intel_haswell_enable_all_pins(codec, true); 2295 + intel_haswell_fixup_enable_dp12(codec); 2296 + 2297 + /* For Haswell/Broadwell, the controller is also in the power well and 2298 + * can cover the codec power request, and so need not set this flag. 2299 + */ 2300 + if (!is_haswell(codec) && !is_broadwell(codec)) 2301 + codec->core.link_power_control = 1; 2302 + 2303 + codec->patch_ops.set_power_state = haswell_set_power_state; 2304 + codec->dp_mst = true; 2305 + codec->depop_delay = 0; 2306 + codec->auto_runtime_pm = 1; 2307 + 2308 + spec->ops.setup_stream = i915_hsw_setup_stream; 2309 + spec->ops.pin_cvt_fixup = i915_pin_cvt_fixup; 2310 + 2311 + err = hdmi_parse_codec(codec); 2312 + if (err < 0) { 2313 + generic_spec_free(codec); 2314 + return err; 2362 2315 } 2316 + 2317 + generic_hdmi_init_per_pins(codec); 2318 + register_i915_notifier(codec); 2319 + return 0; 2320 + } 2321 + 2322 + /* Intel Baytrail and Braswell; with eld notifier */ 2323 + static int patch_i915_byt_hdmi(struct hda_codec *codec) 2324 + { 2325 + struct hdmi_spec *spec; 2326 + int err; 2327 + 2328 + /* requires i915 binding */ 2329 + if (!codec->bus->core.audio_component) { 2330 + codec_info(codec, "No i915 binding for Intel HDMI/DP codec\n"); 2331 + return -ENODEV; 2332 + } 2333 + 2334 + err = alloc_generic_hdmi(codec); 2335 + if (err < 0) 2336 + return err; 2337 + spec = codec->spec; 2363 2338 2364 2339 /* For Valleyview/Cherryview, only the display codec is in the display 2365 2340 * power well and can use link_power ops to request/release the power. 2366 - * For Haswell/Broadwell, the controller is also in the power well and 2367 - * can cover the codec power request, and so need not set this flag. 2368 - * For previous platforms, there is no such power well feature. 2369 2341 */ 2370 - if (is_valleyview_plus(codec) || is_skylake(codec) || 2371 - is_broxton(codec)) 2372 - codec->core.link_power_control = 1; 2342 + codec->core.link_power_control = 1; 2373 2343 2374 - if (hdmi_parse_codec(codec) < 0) { 2375 - if (spec->i915_bound) 2376 - snd_hdac_i915_exit(&codec->bus->core); 2377 - codec->spec = NULL; 2378 - kfree(spec); 2379 - return -EINVAL; 2380 - } 2381 - codec->patch_ops = generic_hdmi_patch_ops; 2382 - if (is_haswell_plus(codec)) { 2383 - codec->patch_ops.set_power_state = haswell_set_power_state; 2384 - codec->dp_mst = true; 2385 - } 2344 + codec->depop_delay = 0; 2345 + codec->auto_runtime_pm = 1; 2386 2346 2387 - /* Enable runtime pm for HDMI audio codec of HSW/BDW/SKL/BYT/BSW */ 2388 - if (is_haswell_plus(codec) || is_valleyview_plus(codec)) 2389 - codec->auto_runtime_pm = 1; 2347 + spec->ops.pin_cvt_fixup = i915_pin_cvt_fixup; 2348 + 2349 + err = hdmi_parse_codec(codec); 2350 + if (err < 0) { 2351 + generic_spec_free(codec); 2352 + return err; 2353 + } 2390 2354 2391 2355 generic_hdmi_init_per_pins(codec); 2392 - 2393 - 2394 - if (codec_has_acomp(codec)) { 2395 - codec->depop_delay = 0; 2396 - spec->i915_audio_ops.audio_ptr = codec; 2397 - /* intel_audio_codec_enable() or intel_audio_codec_disable() 2398 - * will call pin_eld_notify with using audio_ptr pointer 2399 - * We need make sure audio_ptr is really setup 2400 - */ 2401 - wmb(); 2402 - spec->i915_audio_ops.pin_eld_notify = intel_pin_eld_notify; 2403 - snd_hdac_i915_register_notifier(&spec->i915_audio_ops); 2404 - } 2405 - 2406 - WARN_ON(spec->dyn_pcm_assign && !codec_has_acomp(codec)); 2356 + register_i915_notifier(codec); 2407 2357 return 0; 2358 + } 2359 + 2360 + /* Intel IronLake, SandyBridge and IvyBridge; with eld notifier */ 2361 + static int patch_i915_cpt_hdmi(struct hda_codec *codec) 2362 + { 2363 + struct hdmi_spec *spec; 2364 + int err; 2365 + 2366 + /* no i915 component should have been bound before this */ 2367 + if (WARN_ON(codec->bus->core.audio_component)) 2368 + return -EBUSY; 2369 + 2370 + err = alloc_generic_hdmi(codec); 2371 + if (err < 0) 2372 + return err; 2373 + spec = codec->spec; 2374 + 2375 + /* Try to bind with i915 now */ 2376 + err = snd_hdac_i915_init(&codec->bus->core); 2377 + if (err < 0) 2378 + goto error; 2379 + spec->i915_bound = true; 2380 + 2381 + err = hdmi_parse_codec(codec); 2382 + if (err < 0) 2383 + goto error; 2384 + 2385 + generic_hdmi_init_per_pins(codec); 2386 + register_i915_notifier(codec); 2387 + return 0; 2388 + 2389 + error: 2390 + generic_spec_free(codec); 2391 + return err; 2408 2392 } 2409 2393 2410 2394 /* ··· 3640 3492 HDA_CODEC_ENTRY(0x11069f81, "VX900 HDMI/DP", patch_via_hdmi), 3641 3493 HDA_CODEC_ENTRY(0x11069f84, "VX11 HDMI/DP", patch_generic_hdmi), 3642 3494 HDA_CODEC_ENTRY(0x11069f85, "VX11 HDMI/DP", patch_generic_hdmi), 3643 - HDA_CODEC_ENTRY(0x80860054, "IbexPeak HDMI", patch_generic_hdmi), 3495 + HDA_CODEC_ENTRY(0x80860054, "IbexPeak HDMI", patch_i915_cpt_hdmi), 3644 3496 HDA_CODEC_ENTRY(0x80862801, "Bearlake HDMI", patch_generic_hdmi), 3645 3497 HDA_CODEC_ENTRY(0x80862802, "Cantiga HDMI", patch_generic_hdmi), 3646 3498 HDA_CODEC_ENTRY(0x80862803, "Eaglelake HDMI", patch_generic_hdmi), 3647 - HDA_CODEC_ENTRY(0x80862804, "IbexPeak HDMI", patch_generic_hdmi), 3648 - HDA_CODEC_ENTRY(0x80862805, "CougarPoint HDMI", patch_generic_hdmi), 3649 - HDA_CODEC_ENTRY(0x80862806, "PantherPoint HDMI", patch_generic_hdmi), 3650 - HDA_CODEC_ENTRY(0x80862807, "Haswell HDMI", patch_generic_hdmi), 3651 - HDA_CODEC_ENTRY(0x80862808, "Broadwell HDMI", patch_generic_hdmi), 3652 - HDA_CODEC_ENTRY(0x80862809, "Skylake HDMI", patch_generic_hdmi), 3653 - HDA_CODEC_ENTRY(0x8086280a, "Broxton HDMI", patch_generic_hdmi), 3654 - HDA_CODEC_ENTRY(0x8086280b, "Kabylake HDMI", patch_generic_hdmi), 3499 + HDA_CODEC_ENTRY(0x80862804, "IbexPeak HDMI", patch_i915_cpt_hdmi), 3500 + HDA_CODEC_ENTRY(0x80862805, "CougarPoint HDMI", patch_i915_cpt_hdmi), 3501 + HDA_CODEC_ENTRY(0x80862806, "PantherPoint HDMI", patch_i915_cpt_hdmi), 3502 + HDA_CODEC_ENTRY(0x80862807, "Haswell HDMI", patch_i915_hsw_hdmi), 3503 + HDA_CODEC_ENTRY(0x80862808, "Broadwell HDMI", patch_i915_hsw_hdmi), 3504 + HDA_CODEC_ENTRY(0x80862809, "Skylake HDMI", patch_i915_hsw_hdmi), 3505 + HDA_CODEC_ENTRY(0x8086280a, "Broxton HDMI", patch_i915_hsw_hdmi), 3506 + HDA_CODEC_ENTRY(0x8086280b, "Kabylake HDMI", patch_i915_hsw_hdmi), 3655 3507 HDA_CODEC_ENTRY(0x80862880, "CedarTrail HDMI", patch_generic_hdmi), 3656 - HDA_CODEC_ENTRY(0x80862882, "Valleyview2 HDMI", patch_generic_hdmi), 3657 - HDA_CODEC_ENTRY(0x80862883, "Braswell HDMI", patch_generic_hdmi), 3508 + HDA_CODEC_ENTRY(0x80862882, "Valleyview2 HDMI", patch_i915_byt_hdmi), 3509 + HDA_CODEC_ENTRY(0x80862883, "Braswell HDMI", patch_i915_byt_hdmi), 3658 3510 HDA_CODEC_ENTRY(0x808629fb, "Crestline HDMI", patch_generic_hdmi), 3659 3511 /* special ID for generic HDMI */ 3660 3512 HDA_CODEC_ENTRY(HDA_CODEC_ID_GENERIC_HDMI, "Generic HDMI", patch_generic_hdmi),
+15
sound/pci/hda/patch_realtek.c
··· 342 342 case 0x10ec0293: 343 343 alc_update_coef_idx(codec, 0xa, 1<<13, 0); 344 344 break; 345 + case 0x10ec0234: 346 + case 0x10ec0274: 347 + case 0x10ec0294: 348 + alc_update_coef_idx(codec, 0x10, 1<<15, 0); 349 + break; 345 350 case 0x10ec0662: 346 351 if ((coef & 0x00f0) == 0x0030) 347 352 alc_update_coef_idx(codec, 0x4, 1<<10, 0); /* EAPD Ctrl */ ··· 2652 2647 ALC269_TYPE_ALC255, 2653 2648 ALC269_TYPE_ALC256, 2654 2649 ALC269_TYPE_ALC225, 2650 + ALC269_TYPE_ALC294, 2655 2651 }; 2656 2652 2657 2653 /* ··· 2683 2677 case ALC269_TYPE_ALC255: 2684 2678 case ALC269_TYPE_ALC256: 2685 2679 case ALC269_TYPE_ALC225: 2680 + case ALC269_TYPE_ALC294: 2686 2681 ssids = alc269_ssids; 2687 2682 break; 2688 2683 default: ··· 6035 6028 case 0x10ec0225: 6036 6029 spec->codec_variant = ALC269_TYPE_ALC225; 6037 6030 break; 6031 + case 0x10ec0234: 6032 + case 0x10ec0274: 6033 + case 0x10ec0294: 6034 + spec->codec_variant = ALC269_TYPE_ALC294; 6035 + break; 6038 6036 } 6039 6037 6040 6038 if (snd_hda_codec_read(codec, 0x51, 0, AC_VERB_PARAMETERS, 0) == 0x10ec5505) { ··· 6954 6942 HDA_CODEC_ENTRY(0x10ec0225, "ALC225", patch_alc269), 6955 6943 HDA_CODEC_ENTRY(0x10ec0231, "ALC231", patch_alc269), 6956 6944 HDA_CODEC_ENTRY(0x10ec0233, "ALC233", patch_alc269), 6945 + HDA_CODEC_ENTRY(0x10ec0234, "ALC234", patch_alc269), 6957 6946 HDA_CODEC_ENTRY(0x10ec0235, "ALC233", patch_alc269), 6958 6947 HDA_CODEC_ENTRY(0x10ec0255, "ALC255", patch_alc269), 6959 6948 HDA_CODEC_ENTRY(0x10ec0256, "ALC256", patch_alc269), ··· 6965 6952 HDA_CODEC_ENTRY(0x10ec0269, "ALC269", patch_alc269), 6966 6953 HDA_CODEC_ENTRY(0x10ec0270, "ALC270", patch_alc269), 6967 6954 HDA_CODEC_ENTRY(0x10ec0272, "ALC272", patch_alc662), 6955 + HDA_CODEC_ENTRY(0x10ec0274, "ALC274", patch_alc269), 6968 6956 HDA_CODEC_ENTRY(0x10ec0275, "ALC275", patch_alc269), 6969 6957 HDA_CODEC_ENTRY(0x10ec0276, "ALC276", patch_alc269), 6970 6958 HDA_CODEC_ENTRY(0x10ec0280, "ALC280", patch_alc269), ··· 6978 6964 HDA_CODEC_ENTRY(0x10ec0290, "ALC290", patch_alc269), 6979 6965 HDA_CODEC_ENTRY(0x10ec0292, "ALC292", patch_alc269), 6980 6966 HDA_CODEC_ENTRY(0x10ec0293, "ALC293", patch_alc269), 6967 + HDA_CODEC_ENTRY(0x10ec0294, "ALC294", patch_alc269), 6981 6968 HDA_CODEC_ENTRY(0x10ec0298, "ALC298", patch_alc269), 6982 6969 HDA_CODEC_REV_ENTRY(0x10ec0861, 0x100340, "ALC660", patch_alc861), 6983 6970 HDA_CODEC_ENTRY(0x10ec0660, "ALC660-VD", patch_alc861vd),
+3 -17
sound/pci/intel8x0.c
··· 42 42 #include <asm/pgtable.h> 43 43 #include <asm/cacheflush.h> 44 44 45 - #ifdef CONFIG_KVM_GUEST 46 - #include <linux/kvm_para.h> 47 - #else 48 - #define kvm_para_available() (0) 49 - #endif 50 - 51 45 MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); 52 46 MODULE_DESCRIPTION("Intel 82801AA,82901AB,i810,i820,i830,i840,i845,MX440; SiS 7012; Ali 5455"); 53 47 MODULE_LICENSE("GPL"); ··· 2966 2972 goto fini; 2967 2973 } 2968 2974 2969 - /* detect KVM and Parallels virtual environments */ 2970 - result = kvm_para_available(); 2971 - #ifdef X86_FEATURE_HYPERVISOR 2972 - result = result || boot_cpu_has(X86_FEATURE_HYPERVISOR); 2973 - #endif 2974 - if (!result) 2975 - goto fini; 2976 - 2977 2975 /* check for known (emulated) devices */ 2976 + result = 0; 2978 2977 if (pci->subsystem_vendor == PCI_SUBVENDOR_ID_REDHAT_QUMRANET && 2979 2978 pci->subsystem_device == PCI_SUBDEVICE_ID_QEMU) { 2980 2979 /* KVM emulated sound, PCI SSID: 1af4:1100 */ 2981 2980 msg = "enable KVM"; 2981 + result = 1; 2982 2982 } else if (pci->subsystem_vendor == 0x1ab8) { 2983 2983 /* Parallels VM emulated sound, PCI SSID: 1ab8:xxxx */ 2984 2984 msg = "enable Parallels VM"; 2985 - } else { 2986 - msg = "disable (unknown or VT-d) VM"; 2987 - result = 0; 2985 + result = 1; 2988 2986 } 2989 2987 2990 2988 fini:
+1 -1
sound/pci/lx6464es/lx_core.c
··· 644 644 if (err < 0) 645 645 return err; 646 646 647 - if (current_state == state) 647 + if (!err && current_state == state) 648 648 return 0; 649 649 650 650 mdelay(1);
+4
sound/usb/card.c
··· 350 350 case USB_SPEED_HIGH: 351 351 case USB_SPEED_WIRELESS: 352 352 case USB_SPEED_SUPER: 353 + case USB_SPEED_SUPER_PLUS: 353 354 break; 354 355 default: 355 356 dev_err(&dev->dev, "unknown device speed %d\n", snd_usb_get_speed(dev)); ··· 450 449 break; 451 450 case USB_SPEED_SUPER: 452 451 strlcat(card->longname, ", super speed", sizeof(card->longname)); 452 + break; 453 + case USB_SPEED_SUPER_PLUS: 454 + strlcat(card->longname, ", super speed plus", sizeof(card->longname)); 453 455 break; 454 456 default: 455 457 break;
+4
sound/usb/clock.c
··· 309 309 * support reading */ 310 310 if (snd_usb_get_sample_rate_quirk(chip)) 311 311 return 0; 312 + /* the firmware is likely buggy, don't repeat to fail too many times */ 313 + if (chip->sample_rate_read_error > 2) 314 + return 0; 312 315 313 316 if ((err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC_GET_CUR, 314 317 USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_IN, ··· 319 316 data, sizeof(data))) < 0) { 320 317 dev_err(&dev->dev, "%d:%d: cannot get freq at ep %#x\n", 321 318 iface, fmt->altsetting, ep); 319 + chip->sample_rate_read_error++; 322 320 return 0; /* some devices don't support reading */ 323 321 } 324 322
+1
sound/usb/helper.c
··· 120 120 case USB_SPEED_HIGH: 121 121 case USB_SPEED_WIRELESS: 122 122 case USB_SPEED_SUPER: 123 + case USB_SPEED_SUPER_PLUS: 123 124 if (get_endpoint(alts, 0)->bInterval >= 1 && 124 125 get_endpoint(alts, 0)->bInterval <= 4) 125 126 return get_endpoint(alts, 0)->bInterval - 1;
+1
sound/usb/midi.c
··· 911 911 switch (snd_usb_get_speed(ep->umidi->dev)) { 912 912 case USB_SPEED_HIGH: 913 913 case USB_SPEED_SUPER: 914 + case USB_SPEED_SUPER_PLUS: 914 915 count = 1; 915 916 break; 916 917 default:
+76 -2
sound/usb/mixer.c
··· 45 45 #include <linux/bitops.h> 46 46 #include <linux/init.h> 47 47 #include <linux/list.h> 48 + #include <linux/log2.h> 48 49 #include <linux/slab.h> 49 50 #include <linux/string.h> 50 51 #include <linux/usb.h> ··· 1379 1378 snd_usb_mixer_add_control(&cval->head, kctl); 1380 1379 } 1381 1380 1381 + static int parse_clock_source_unit(struct mixer_build *state, int unitid, 1382 + void *_ftr) 1383 + { 1384 + struct uac_clock_source_descriptor *hdr = _ftr; 1385 + struct usb_mixer_elem_info *cval; 1386 + struct snd_kcontrol *kctl; 1387 + char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; 1388 + int ret; 1389 + 1390 + if (state->mixer->protocol != UAC_VERSION_2) 1391 + return -EINVAL; 1392 + 1393 + if (hdr->bLength != sizeof(*hdr)) { 1394 + usb_audio_dbg(state->chip, 1395 + "Bogus clock source descriptor length of %d, ignoring.\n", 1396 + hdr->bLength); 1397 + return 0; 1398 + } 1399 + 1400 + /* 1401 + * The only property of this unit we are interested in is the 1402 + * clock source validity. If that isn't readable, just bail out. 1403 + */ 1404 + if (!uac2_control_is_readable(hdr->bmControls, 1405 + ilog2(UAC2_CS_CONTROL_CLOCK_VALID))) 1406 + return 0; 1407 + 1408 + cval = kzalloc(sizeof(*cval), GFP_KERNEL); 1409 + if (!cval) 1410 + return -ENOMEM; 1411 + 1412 + snd_usb_mixer_elem_init_std(&cval->head, state->mixer, hdr->bClockID); 1413 + 1414 + cval->min = 0; 1415 + cval->max = 1; 1416 + cval->channels = 1; 1417 + cval->val_type = USB_MIXER_BOOLEAN; 1418 + cval->control = UAC2_CS_CONTROL_CLOCK_VALID; 1419 + 1420 + if (uac2_control_is_writeable(hdr->bmControls, 1421 + ilog2(UAC2_CS_CONTROL_CLOCK_VALID))) 1422 + kctl = snd_ctl_new1(&usb_feature_unit_ctl, cval); 1423 + else { 1424 + cval->master_readonly = 1; 1425 + kctl = snd_ctl_new1(&usb_feature_unit_ctl_ro, cval); 1426 + } 1427 + 1428 + if (!kctl) { 1429 + kfree(cval); 1430 + return -ENOMEM; 1431 + } 1432 + 1433 + kctl->private_free = snd_usb_mixer_elem_free; 1434 + ret = snd_usb_copy_string_desc(state, hdr->iClockSource, 1435 + name, sizeof(name)); 1436 + if (ret > 0) 1437 + snprintf(kctl->id.name, sizeof(kctl->id.name), 1438 + "%s Validity", name); 1439 + else 1440 + snprintf(kctl->id.name, sizeof(kctl->id.name), 1441 + "Clock Source %d Validity", hdr->bClockID); 1442 + 1443 + return snd_usb_mixer_add_control(&cval->head, kctl); 1444 + } 1445 + 1382 1446 /* 1383 1447 * parse a feature unit 1384 1448 * ··· 2192 2126 2193 2127 switch (p1[2]) { 2194 2128 case UAC_INPUT_TERMINAL: 2195 - case UAC2_CLOCK_SOURCE: 2196 2129 return 0; /* NOP */ 2197 2130 case UAC_MIXER_UNIT: 2198 2131 return parse_audio_mixer_unit(state, unitid, p1); 2132 + case UAC2_CLOCK_SOURCE: 2133 + return parse_clock_source_unit(state, unitid, p1); 2199 2134 case UAC_SELECTOR_UNIT: 2200 2135 case UAC2_CLOCK_SELECTOR: 2201 2136 return parse_audio_selector_unit(state, unitid, p1); ··· 2374 2307 __u8 unitid = (index >> 8) & 0xff; 2375 2308 __u8 control = (value >> 8) & 0xff; 2376 2309 __u8 channel = value & 0xff; 2310 + unsigned int count = 0; 2377 2311 2378 2312 if (channel >= MAX_CHANNELS) { 2379 2313 usb_audio_dbg(mixer->chip, ··· 2383 2315 return; 2384 2316 } 2385 2317 2318 + for (list = mixer->id_elems[unitid]; list; list = list->next_id_elem) 2319 + count++; 2320 + 2321 + if (count == 0) 2322 + return; 2323 + 2386 2324 for (list = mixer->id_elems[unitid]; list; list = list->next_id_elem) { 2387 2325 struct usb_mixer_elem_info *info; 2388 2326 ··· 2396 2322 continue; 2397 2323 2398 2324 info = (struct usb_mixer_elem_info *)list; 2399 - if (info->control != control) 2325 + if (count > 1 && info->control != control) 2400 2326 continue; 2401 2327 2402 2328 switch (attribute) {
+1
sound/usb/usbaudio.h
··· 47 47 48 48 int num_interfaces; 49 49 int num_suspended_intf; 50 + int sample_rate_read_error; 50 51 51 52 struct list_head pcm_list; /* list of pcm streams */ 52 53 struct list_head ep_list; /* list of audio-related endpoints */