All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ALSA: pcsp: Only autoload if the pcspkr input driver is disabled
@ 2026-11-20 12:03 Paul Menzel
  2026-11-20 17:07 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Paul Menzel @ 2026-11-20 12:03 UTC (permalink / raw)
  To: Jaroslav Kysela, Takashi Iwai; +Cc: Paul Menzel, linux-sound, linux-kernel

The input driver pcspkr and snd-pcsp both register a platform driver
named "pcspkr" for the platform device of the same name, and both
declare the module alias platform:pcspkr. With both built as modules,
as distribution configurations do, udev loads both for the device, and
the second one fails to register its driver on every boot. On a Dell
XPS 13 9310 with Linux 7.4-rc1 and the Debian configuration:

    [    0.793761] input: PC Speaker as /devices/platform/pcspkr/input/input7
    [    0.813617] Error: Driver 'pcspkr' is already registered, aborting...

Which driver ends up handling the beeps depends on the module load
order. The help text of SND_PCSP already says that the driver is not
needed for beeps, and that it may become the default sound card. Debian
therefore removes the alias since 2014 [1], and Ubuntu blacklists
snd_pcsp. With pcspkr built in, snd-pcsp cannot register its driver at
all, so the alias is useless there, too.

Only declare the alias if INPUT_PCSPKR is disabled. Then snd-pcsp is
loaded automatically and takes over the beeps as before. Otherwise only
pcspkr is loaded automatically, and users wanting PCM sound from the PC
speaker keep pcspkr from loading and load snd-pcsp explicitly, which is
already needed today for a deterministic result. Document it in the
Kconfig help text.

Tested on the Dell XPS 13 9310 with Linux 7.4-rc1 and the Debian
configuration (INPUT_PCSPKR=m, SND_PCSP=m), with snd-pcsp not
blacklisted: without this change, the error above is logged; with it,
only pcspkr is loaded and provides the PC Speaker input device, and after
`rmmod pcspkr`, `modprobe snd-pcsp` binds snd-pcsp and creates its sound
card. In QEMU with x86_64_defconfig, kvm_guest.config and SND_PCSP=m,
with systemd-udevd loading the modules, the same holds for
INPUT_PCSPKR=m, and with INPUT_PCSPKR=n, snd-pcsp is still loaded
automatically, binds the device, and creates its sound card and PC
Speaker input device.

[1]: https://bugs.debian.org/697709

Signed-off-by: Paul Menzel <pmenzel@molgen.mpg.de>
---

Notes:
    Tool use: Claude Code (claude-opus-5-5) analysed the conflict, wrote the patch
    and the commit message, and ran the build, modinfo, QEMU and hardware
    tests; the author reviewed it.
    
    QEMU 11.1.2 test: the guest boots the host’s root file system read-only
    over 9p, with the test kernel’s modules bind-mounted over
    /usr/lib/modules from the second (writable) share. The init script
    starts systemd-udevd, runs `udevadm trigger` and `udevadm settle`, and
    records the loaded modules, the driver bound to the pcspkr platform
    device, the PC Speaker input devices and /proc/asound/cards; with
    pcspkr loaded, again after `rmmod pcspkr; modprobe snd-pcsp`. No audio
    backend is configured, so this checks loading and binding, not sound.
    
        qemu-system-x86_64 -enable-kvm -cpu host -smp 2 -m 1G \
            -machine q35 -display none -no-reboot -nic none \
            -serial file:$OUT/console \
            -kernel $OUT/kernel/boot/vmlinuz-7.4.0-rc2-pcsp-fix-n \
            -append "console=ttyS0,115200 root=root rootfstype=9p rootflags=trans=virtio,version=9p2000.L,cache=none ro init=$GUEST_INIT" \
            -fsdev local,id=root,path=/,security_model=none,readonly=on,multidevs=remap \
            -device virtio-9p-pci,fsdev=root,mount_tag=root \
            -fsdev local,id=out,path=$OUT,security_model=none,multidevs=remap \
            -device virtio-9p-pci,fsdev=out,mount_tag=out

 sound/drivers/Kconfig     | 5 ++++-
 sound/drivers/pcsp/pcsp.c | 7 +++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/sound/drivers/Kconfig b/sound/drivers/Kconfig
index 6debd8e95cb7a..4d875d0f5a17b 100644
--- a/sound/drivers/Kconfig
+++ b/sound/drivers/Kconfig
@@ -55,7 +55,10 @@ config SND_PCSP
 	  If you don't have a sound card in your computer, you can include a
 	  driver for the PC speaker which allows it to act like a primitive
 	  sound card.
-	  This driver also replaces the pcspkr driver for beeps.
+	  This driver also replaces the pcspkr driver for beeps. If the
+	  pcspkr driver (INPUT_PCSPKR) is enabled too, only pcspkr is loaded
+	  automatically. To use this driver instead, prevent pcspkr from
+	  loading, and load this driver explicitly.
 
 	  You can compile this as a module which will be called snd-pcsp.
 
diff --git a/sound/drivers/pcsp/pcsp.c b/sound/drivers/pcsp/pcsp.c
index ff6bb375c9001..d7d28ec2250b6 100644
--- a/sound/drivers/pcsp/pcsp.c
+++ b/sound/drivers/pcsp/pcsp.c
@@ -22,7 +22,14 @@
 MODULE_AUTHOR("Stas Sergeev <stsp@users.sourceforge.net>");
 MODULE_DESCRIPTION("PC-Speaker driver");
 MODULE_LICENSE("GPL");
+/*
+ * The input driver pcspkr binds to the same platform device and has the same
+ * driver name, so only one of the two can be loaded. If pcspkr is available,
+ * let it handle the beeps, and leave loading this driver to the user.
+ */
+#if !IS_ENABLED(CONFIG_INPUT_PCSPKR)
 MODULE_ALIAS("platform:pcspkr");
+#endif
 
 static int index = SNDRV_DEFAULT_IDX1;	/* Index 0-MAX */
 static char *id = SNDRV_DEFAULT_STR1;	/* ID for this card */
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ALSA: pcsp: Only autoload if the pcspkr input driver is disabled
  2026-11-20 12:03 [PATCH] ALSA: pcsp: Only autoload if the pcspkr input driver is disabled Paul Menzel
@ 2026-11-20 17:07 ` Takashi Iwai
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2026-11-20 17:07 UTC (permalink / raw)
  To: Paul Menzel; +Cc: Jaroslav Kysela, Takashi Iwai, linux-sound, linux-kernel

On Fri, 20 Nov 2026 13:03:04 +0100,
Paul Menzel wrote:
> 
> The input driver pcspkr and snd-pcsp both register a platform driver
> named "pcspkr" for the platform device of the same name, and both
> declare the module alias platform:pcspkr. With both built as modules,
> as distribution configurations do, udev loads both for the device, and
> the second one fails to register its driver on every boot. On a Dell
> XPS 13 9310 with Linux 7.4-rc1 and the Debian configuration:
> 
>     [    0.793761] input: PC Speaker as /devices/platform/pcspkr/input/input7
>     [    0.813617] Error: Driver 'pcspkr' is already registered, aborting...
> 
> Which driver ends up handling the beeps depends on the module load
> order. The help text of SND_PCSP already says that the driver is not
> needed for beeps, and that it may become the default sound card. Debian
> therefore removes the alias since 2014 [1], and Ubuntu blacklists
> snd_pcsp. With pcspkr built in, snd-pcsp cannot register its driver at
> all, so the alias is useless there, too.
> 
> Only declare the alias if INPUT_PCSPKR is disabled. Then snd-pcsp is
> loaded automatically and takes over the beeps as before. Otherwise only
> pcspkr is loaded automatically, and users wanting PCM sound from the PC
> speaker keep pcspkr from loading and load snd-pcsp explicitly, which is
> already needed today for a deterministic result. Document it in the
> Kconfig help text.
> 
> Tested on the Dell XPS 13 9310 with Linux 7.4-rc1 and the Debian
> configuration (INPUT_PCSPKR=m, SND_PCSP=m), with snd-pcsp not
> blacklisted: without this change, the error above is logged; with it,
> only pcspkr is loaded and provides the PC Speaker input device, and after
> `rmmod pcspkr`, `modprobe snd-pcsp` binds snd-pcsp and creates its sound
> card. In QEMU with x86_64_defconfig, kvm_guest.config and SND_PCSP=m,
> with systemd-udevd loading the modules, the same holds for
> INPUT_PCSPKR=m, and with INPUT_PCSPKR=n, snd-pcsp is still loaded
> automatically, binds the device, and creates its sound card and PC
> Speaker input device.
> 
> [1]: https://bugs.debian.org/697709
> 
> Signed-off-by: Paul Menzel <pmenzel@molgen.mpg.de>

Applied to for-next branch now.


thanks,

Takashi

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-20 17:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 12:03 [PATCH] ALSA: pcsp: Only autoload if the pcspkr input driver is disabled Paul Menzel
2026-11-20 17:07 ` Takashi Iwai

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.