Skip to content

Commit 70dc52f

Browse files
committed
Merge tag 'sound-3.9' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound
Pull sound fixes from Takashi Iwai: "Mostly HD-audio and USB-audio regression fixes: - Oops fix at unloading of snd-hda-codec-conexant module - A few trivial regression fixes for Cirrus and Conexant HD-audio codecs - Relax the USB-audio descriptor parse errors as non-fatal - Fix locking of HD-audio CA0132 DSP loader - Fix the generic HD-audio parser for VIA codecs" * tag 'sound-3.9' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound: ALSA: hda - Fix DAC assignment for independent HP ALSA: hda - Fix abuse of snd_hda_lock_devices() for DSP loader ALSA: hda - Fix typo in checking IEC958 emphasis bit ALSA: snd-usb: mixer: ignore -EINVAL in snd_usb_mixer_controls() ALSA: snd-usb: mixer: propagate errors up the call chain ALSA: usb: Parse UAC2 extension unit like for UAC1 ALSA: hda - Fix yet missing GPIO/EAPD setup in cirrus driver ALSA: hda/cirrus - Fix the digital beep registration ALSA: hda - Fix missing beep detach in patch_conexant.c ALSA: documentation: Fix typo in Documentation/sound
2 parents 1e0695c + 55a63d4 commit 70dc52f

8 files changed

Lines changed: 184 additions & 41 deletions

File tree

‎Documentation/sound/alsa/ALSA-Configuration.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
912912
models depending on the codec chip. The list of available models
913913
is found in HD-Audio-Models.txt
914914

915-
The model name "genric" is treated as a special case. When this
915+
The model name "generic" is treated as a special case. When this
916916
model is given, the driver uses the generic codec parser without
917917
"codec-patch". It's sometimes good for testing and debugging.
918918

‎Documentation/sound/alsa/seq_oss.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ <H4>
285285
<H4>
286286
7.2.4 Close Callback</H4>
287287
The <TT>close</TT> callback is called when this device is closed by the
288-
applicaion. If any private data was allocated in open callback, it must
288+
application. If any private data was allocated in open callback, it must
289289
be released in the close callback. The deletion of ALSA port should be
290290
done here, too. This callback must not be NULL.
291291
<H4>

‎sound/pci/hda/hda_codec.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3144,7 +3144,7 @@ static unsigned int convert_to_spdif_status(unsigned short val)
31443144
if (val & AC_DIG1_PROFESSIONAL)
31453145
sbits |= IEC958_AES0_PROFESSIONAL;
31463146
if (sbits & IEC958_AES0_PROFESSIONAL) {
3147-
if (sbits & AC_DIG1_EMPHASIS)
3147+
if (val & AC_DIG1_EMPHASIS)
31483148
sbits |= IEC958_AES0_PRO_EMPHASIS_5015;
31493149
} else {
31503150
if (val & AC_DIG1_EMPHASIS)

‎sound/pci/hda/hda_generic.c‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,8 @@ enum {
995995
BAD_NO_EXTRA_SURR_DAC = 0x101,
996996
/* Primary DAC shared with main surrounds */
997997
BAD_SHARED_SURROUND = 0x100,
998+
/* No independent HP possible */
999+
BAD_NO_INDEP_HP = 0x40,
9981000
/* Primary DAC shared with main CLFE */
9991001
BAD_SHARED_CLFE = 0x10,
10001002
/* Primary DAC shared with extra surrounds */
@@ -1392,6 +1394,43 @@ static int check_aamix_out_path(struct hda_codec *codec, int path_idx)
13921394
return snd_hda_get_path_idx(codec, path);
13931395
}
13941396

1397+
/* check whether the independent HP is available with the current config */
1398+
static bool indep_hp_possible(struct hda_codec *codec)
1399+
{
1400+
struct hda_gen_spec *spec = codec->spec;
1401+
struct auto_pin_cfg *cfg = &spec->autocfg;
1402+
struct nid_path *path;
1403+
int i, idx;
1404+
1405+
if (cfg->line_out_type == AUTO_PIN_HP_OUT)
1406+
idx = spec->out_paths[0];
1407+
else
1408+
idx = spec->hp_paths[0];
1409+
path = snd_hda_get_path_from_idx(codec, idx);
1410+
if (!path)
1411+
return false;
1412+
1413+
/* assume no path conflicts unless aamix is involved */
1414+
if (!spec->mixer_nid || !is_nid_contained(path, spec->mixer_nid))
1415+
return true;
1416+
1417+
/* check whether output paths contain aamix */
1418+
for (i = 0; i < cfg->line_outs; i++) {
1419+
if (spec->out_paths[i] == idx)
1420+
break;
1421+
path = snd_hda_get_path_from_idx(codec, spec->out_paths[i]);
1422+
if (path && is_nid_contained(path, spec->mixer_nid))
1423+
return false;
1424+
}
1425+
for (i = 0; i < cfg->speaker_outs; i++) {
1426+
path = snd_hda_get_path_from_idx(codec, spec->speaker_paths[i]);
1427+
if (path && is_nid_contained(path, spec->mixer_nid))
1428+
return false;
1429+
}
1430+
1431+
return true;
1432+
}
1433+
13951434
/* fill the empty entries in the dac array for speaker/hp with the
13961435
* shared dac pointed by the paths
13971436
*/
@@ -1545,6 +1584,9 @@ static int fill_and_eval_dacs(struct hda_codec *codec,
15451584
badness += BAD_MULTI_IO;
15461585
}
15471586

1587+
if (spec->indep_hp && !indep_hp_possible(codec))
1588+
badness += BAD_NO_INDEP_HP;
1589+
15481590
/* re-fill the shared DAC for speaker / headphone */
15491591
if (cfg->line_out_type != AUTO_PIN_HP_OUT)
15501592
refill_shared_dacs(codec, cfg->hp_outs,
@@ -1758,6 +1800,10 @@ static int parse_output_paths(struct hda_codec *codec)
17581800
cfg->speaker_pins, val);
17591801
}
17601802

1803+
/* clear indep_hp flag if not available */
1804+
if (spec->indep_hp && !indep_hp_possible(codec))
1805+
spec->indep_hp = 0;
1806+
17611807
kfree(best_cfg);
17621808
return 0;
17631809
}

‎sound/pci/hda/hda_intel.c‎

Lines changed: 109 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,8 @@ struct azx_dev {
415415
unsigned int opened :1;
416416
unsigned int running :1;
417417
unsigned int irq_pending :1;
418+
unsigned int prepared:1;
419+
unsigned int locked:1;
418420
/*
419421
* For VIA:
420422
* A flag to ensure DMA position is 0
@@ -426,8 +428,25 @@ struct azx_dev {
426428

427429
struct timecounter azx_tc;
428430
struct cyclecounter azx_cc;
431+
432+
#ifdef CONFIG_SND_HDA_DSP_LOADER
433+
struct mutex dsp_mutex;
434+
#endif
429435
};
430436

437+
/* DSP lock helpers */
438+
#ifdef CONFIG_SND_HDA_DSP_LOADER
439+
#define dsp_lock_init(dev) mutex_init(&(dev)->dsp_mutex)
440+
#define dsp_lock(dev) mutex_lock(&(dev)->dsp_mutex)
441+
#define dsp_unlock(dev) mutex_unlock(&(dev)->dsp_mutex)
442+
#define dsp_is_locked(dev) ((dev)->locked)
443+
#else
444+
#define dsp_lock_init(dev) do {} while (0)
445+
#define dsp_lock(dev) do {} while (0)
446+
#define dsp_unlock(dev) do {} while (0)
447+
#define dsp_is_locked(dev) 0
448+
#endif
449+
431450
/* CORB/RIRB */
432451
struct azx_rb {
433452
u32 *buf; /* CORB/RIRB buffer
@@ -527,6 +546,10 @@ struct azx {
527546

528547
/* card list (for power_save trigger) */
529548
struct list_head list;
549+
550+
#ifdef CONFIG_SND_HDA_DSP_LOADER
551+
struct azx_dev saved_azx_dev;
552+
#endif
530553
};
531554

532555
#define CREATE_TRACE_POINTS
@@ -1793,15 +1816,25 @@ azx_assign_device(struct azx *chip, struct snd_pcm_substream *substream)
17931816
dev = chip->capture_index_offset;
17941817
nums = chip->capture_streams;
17951818
}
1796-
for (i = 0; i < nums; i++, dev++)
1797-
if (!chip->azx_dev[dev].opened) {
1798-
res = &chip->azx_dev[dev];
1799-
if (res->assigned_key == key)
1800-
break;
1819+
for (i = 0; i < nums; i++, dev++) {
1820+
struct azx_dev *azx_dev = &chip->azx_dev[dev];
1821+
dsp_lock(azx_dev);
1822+
if (!azx_dev->opened && !dsp_is_locked(azx_dev)) {
1823+
res = azx_dev;
1824+
if (res->assigned_key == key) {
1825+
res->opened = 1;
1826+
res->assigned_key = key;
1827+
dsp_unlock(azx_dev);
1828+
return azx_dev;
1829+
}
18011830
}
1831+
dsp_unlock(azx_dev);
1832+
}
18021833
if (res) {
1834+
dsp_lock(res);
18031835
res->opened = 1;
18041836
res->assigned_key = key;
1837+
dsp_unlock(res);
18051838
}
18061839
return res;
18071840
}
@@ -2009,15 +2042,23 @@ static int azx_pcm_hw_params(struct snd_pcm_substream *substream,
20092042
struct azx_dev *azx_dev = get_azx_dev(substream);
20102043
int ret;
20112044

2045+
dsp_lock(azx_dev);
2046+
if (dsp_is_locked(azx_dev)) {
2047+
ret = -EBUSY;
2048+
goto unlock;
2049+
}
2050+
20122051
mark_runtime_wc(chip, azx_dev, substream, false);
20132052
azx_dev->bufsize = 0;
20142053
azx_dev->period_bytes = 0;
20152054
azx_dev->format_val = 0;
20162055
ret = snd_pcm_lib_malloc_pages(substream,
20172056
params_buffer_bytes(hw_params));
20182057
if (ret < 0)
2019-
return ret;
2058+
goto unlock;
20202059
mark_runtime_wc(chip, azx_dev, substream, true);
2060+
unlock:
2061+
dsp_unlock(azx_dev);
20212062
return ret;
20222063
}
20232064

@@ -2029,16 +2070,21 @@ static int azx_pcm_hw_free(struct snd_pcm_substream *substream)
20292070
struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
20302071

20312072
/* reset BDL address */
2032-
azx_sd_writel(azx_dev, SD_BDLPL, 0);
2033-
azx_sd_writel(azx_dev, SD_BDLPU, 0);
2034-
azx_sd_writel(azx_dev, SD_CTL, 0);
2035-
azx_dev->bufsize = 0;
2036-
azx_dev->period_bytes = 0;
2037-
azx_dev->format_val = 0;
2073+
dsp_lock(azx_dev);
2074+
if (!dsp_is_locked(azx_dev)) {
2075+
azx_sd_writel(azx_dev, SD_BDLPL, 0);
2076+
azx_sd_writel(azx_dev, SD_BDLPU, 0);
2077+
azx_sd_writel(azx_dev, SD_CTL, 0);
2078+
azx_dev->bufsize = 0;
2079+
azx_dev->period_bytes = 0;
2080+
azx_dev->format_val = 0;
2081+
}
20382082

20392083
snd_hda_codec_cleanup(apcm->codec, hinfo, substream);
20402084

20412085
mark_runtime_wc(chip, azx_dev, substream, false);
2086+
azx_dev->prepared = 0;
2087+
dsp_unlock(azx_dev);
20422088
return snd_pcm_lib_free_pages(substream);
20432089
}
20442090

@@ -2055,6 +2101,12 @@ static int azx_pcm_prepare(struct snd_pcm_substream *substream)
20552101
snd_hda_spdif_out_of_nid(apcm->codec, hinfo->nid);
20562102
unsigned short ctls = spdif ? spdif->ctls : 0;
20572103

2104+
dsp_lock(azx_dev);
2105+
if (dsp_is_locked(azx_dev)) {
2106+
err = -EBUSY;
2107+
goto unlock;
2108+
}
2109+
20582110
azx_stream_reset(chip, azx_dev);
20592111
format_val = snd_hda_calc_stream_format(runtime->rate,
20602112
runtime->channels,
@@ -2065,7 +2117,8 @@ static int azx_pcm_prepare(struct snd_pcm_substream *substream)
20652117
snd_printk(KERN_ERR SFX
20662118
"%s: invalid format_val, rate=%d, ch=%d, format=%d\n",
20672119
pci_name(chip->pci), runtime->rate, runtime->channels, runtime->format);
2068-
return -EINVAL;
2120+
err = -EINVAL;
2121+
goto unlock;
20692122
}
20702123

20712124
bufsize = snd_pcm_lib_buffer_bytes(substream);
@@ -2084,7 +2137,7 @@ static int azx_pcm_prepare(struct snd_pcm_substream *substream)
20842137
azx_dev->no_period_wakeup = runtime->no_period_wakeup;
20852138
err = azx_setup_periods(chip, substream, azx_dev);
20862139
if (err < 0)
2087-
return err;
2140+
goto unlock;
20882141
}
20892142

20902143
/* wallclk has 24Mhz clock source */
@@ -2101,8 +2154,14 @@ static int azx_pcm_prepare(struct snd_pcm_substream *substream)
21012154
if ((chip->driver_caps & AZX_DCAPS_CTX_WORKAROUND) &&
21022155
stream_tag > chip->capture_streams)
21032156
stream_tag -= chip->capture_streams;
2104-
return snd_hda_codec_prepare(apcm->codec, hinfo, stream_tag,
2157+
err = snd_hda_codec_prepare(apcm->codec, hinfo, stream_tag,
21052158
azx_dev->format_val, substream);
2159+
2160+
unlock:
2161+
if (!err)
2162+
azx_dev->prepared = 1;
2163+
dsp_unlock(azx_dev);
2164+
return err;
21062165
}
21072166

21082167
static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
@@ -2117,6 +2176,9 @@ static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
21172176
azx_dev = get_azx_dev(substream);
21182177
trace_azx_pcm_trigger(chip, azx_dev, cmd);
21192178

2179+
if (dsp_is_locked(azx_dev) || !azx_dev->prepared)
2180+
return -EPIPE;
2181+
21202182
switch (cmd) {
21212183
case SNDRV_PCM_TRIGGER_START:
21222184
rstart = 1;
@@ -2621,17 +2683,27 @@ static int azx_load_dsp_prepare(struct hda_bus *bus, unsigned int format,
26212683
struct azx_dev *azx_dev;
26222684
int err;
26232685

2624-
if (snd_hda_lock_devices(bus))
2625-
return -EBUSY;
2686+
azx_dev = azx_get_dsp_loader_dev(chip);
2687+
2688+
dsp_lock(azx_dev);
2689+
spin_lock_irq(&chip->reg_lock);
2690+
if (azx_dev->running || azx_dev->locked) {
2691+
spin_unlock_irq(&chip->reg_lock);
2692+
err = -EBUSY;
2693+
goto unlock;
2694+
}
2695+
azx_dev->prepared = 0;
2696+
chip->saved_azx_dev = *azx_dev;
2697+
azx_dev->locked = 1;
2698+
spin_unlock_irq(&chip->reg_lock);
26262699

26272700
err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV_SG,
26282701
snd_dma_pci_data(chip->pci),
26292702
byte_size, bufp);
26302703
if (err < 0)
2631-
goto unlock;
2704+
goto err_alloc;
26322705

26332706
mark_pages_wc(chip, bufp, true);
2634-
azx_dev = azx_get_dsp_loader_dev(chip);
26352707
azx_dev->bufsize = byte_size;
26362708
azx_dev->period_bytes = byte_size;
26372709
azx_dev->format_val = format;
@@ -2649,13 +2721,20 @@ static int azx_load_dsp_prepare(struct hda_bus *bus, unsigned int format,
26492721
goto error;
26502722

26512723
azx_setup_controller(chip, azx_dev);
2724+
dsp_unlock(azx_dev);
26522725
return azx_dev->stream_tag;
26532726

26542727
error:
26552728
mark_pages_wc(chip, bufp, false);
26562729
snd_dma_free_pages(bufp);
2657-
unlock:
2658-
snd_hda_unlock_devices(bus);
2730+
err_alloc:
2731+
spin_lock_irq(&chip->reg_lock);
2732+
if (azx_dev->opened)
2733+
*azx_dev = chip->saved_azx_dev;
2734+
azx_dev->locked = 0;
2735+
spin_unlock_irq(&chip->reg_lock);
2736+
unlock:
2737+
dsp_unlock(azx_dev);
26592738
return err;
26602739
}
26612740

@@ -2677,9 +2756,10 @@ static void azx_load_dsp_cleanup(struct hda_bus *bus,
26772756
struct azx *chip = bus->private_data;
26782757
struct azx_dev *azx_dev = azx_get_dsp_loader_dev(chip);
26792758

2680-
if (!dmab->area)
2759+
if (!dmab->area || !azx_dev->locked)
26812760
return;
26822761

2762+
dsp_lock(azx_dev);
26832763
/* reset BDL address */
26842764
azx_sd_writel(azx_dev, SD_BDLPL, 0);
26852765
azx_sd_writel(azx_dev, SD_BDLPU, 0);
@@ -2692,7 +2772,12 @@ static void azx_load_dsp_cleanup(struct hda_bus *bus,
26922772
snd_dma_free_pages(dmab);
26932773
dmab->area = NULL;
26942774

2695-
snd_hda_unlock_devices(bus);
2775+
spin_lock_irq(&chip->reg_lock);
2776+
if (azx_dev->opened)
2777+
*azx_dev = chip->saved_azx_dev;
2778+
azx_dev->locked = 0;
2779+
spin_unlock_irq(&chip->reg_lock);
2780+
dsp_unlock(azx_dev);
26962781
}
26972782
#endif /* CONFIG_SND_HDA_DSP_LOADER */
26982783

@@ -3481,6 +3566,7 @@ static int azx_first_init(struct azx *chip)
34813566
}
34823567

34833568
for (i = 0; i < chip->num_streams; i++) {
3569+
dsp_lock_init(&chip->azx_dev[i]);
34843570
/* allocate memory for the BDL for each stream */
34853571
err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
34863572
snd_dma_pci_data(chip->pci),

‎sound/pci/hda/patch_cirrus.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,10 @@ static void cs_automute(struct hda_codec *codec)
168168
snd_hda_gen_update_outputs(codec);
169169

170170
if (spec->gpio_eapd_hp) {
171-
unsigned int gpio = spec->gen.hp_jack_present ?
171+
spec->gpio_data = spec->gen.hp_jack_present ?
172172
spec->gpio_eapd_hp : spec->gpio_eapd_speaker;
173173
snd_hda_codec_write(codec, 0x01, 0,
174-
AC_VERB_SET_GPIO_DATA, gpio);
174+
AC_VERB_SET_GPIO_DATA, spec->gpio_data);
175175
}
176176
}
177177

0 commit comments

Comments
 (0)