Commit Graph

2244 Commits

Author SHA1 Message Date
Takashi Iwai c4e51e424e ALSA: line6: Zero-initialize message buffers
For shutting up spurious KMSAN uninit-value warnings, just replace
kmalloc() calls with kzalloc() for the buffers used for
communications.  There should be no real issue with the original code,
but it's still better to cover.

Reported-by: syzbot+7fb05ccf7b3d2f9617b3@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/r/00000000000084b18706150bcca5@google.com
Message-ID: <20240402063628.26609-1-tiwai@suse.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-04-02 15:01:27 +02:00
Takashi Iwai c53898eb60 Revert "ALSA: usb-audio: Name feature ctl using output if input is PCM"
This reverts commit 1601cd53c7.

This fix is applied globally to all devices, and it may change the
existing control names.  When the devices are managed with the fixed
configuration like UCM, such control name mismatch may lead to
significant regressions.

For avoiding that kind of regression, we would need to apply such
changes conditionally, but it'd take time to settle down.
While the original fix is a good thing in general, in order to address
the regression, let's revert the change for now.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=218605
Reported-and-tested-by: Niklāvs Koļesņikovs <pinkflames.linux@gmail.com>
Message-ID: <20240316083744.28126-1-tiwai@suse.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-03-17 09:32:49 +01:00
Johan Carlsson a39d51ff1f ALSA: usb-audio: Stop parsing channels bits when all channels are found.
If a usb audio device sets more bits than the amount of channels
it could write outside of the map array.

Signed-off-by: Johan Carlsson <johan.carlsson@teenage.engineering>
Fixes: 04324ccc75 ("ALSA: usb-audio: add channel map support")
Message-ID: <20240313081509.9801-1-johan.carlsson@teenage.engineering>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-03-13 14:29:22 +01:00
Geoffrey D. Bennett 6719cd5e45 ALSA: scarlett2: Fix Scarlett 4th Gen input gain range again
The 4th Gen input preamp gain range is 0dB to +69dB, although the
control values range from 0 to 70. Replace SCARLETT2_MAX_GAIN with
SCARLETT2_MAX_GAIN_VALUE and SCARLETT2_MAX_GAIN_DB, and update the TLV
again.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Fixes: a45cf0a083 ("ALSA: scarlett2: Fix Scarlett 4th Gen input gain range")
Message-ID: <Ze7OMA8ntG7KteGa@m.b4.vu>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-03-11 13:37:39 +01:00
Geoffrey D. Bennett a45cf0a083 ALSA: scarlett2: Fix Scarlett 4th Gen input gain range
The input gain range TLV was declared as -70dB to 0dB, but the preamp
gain range is actually 0dB to +70dB. Rename SCARLETT2_GAIN_BIAS to
SCARLETT2_MAX_GAIN and update the TLV to fix.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Fixes: 0a995e38dc ("ALSA: scarlett2: Add support for software-controllable input gain")
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Message-ID: <9168317b5ac5335943d3f14dbcd1cc2d9b2299d0.1710047969.git.g@b4.vu>
2024-03-11 09:15:34 +01:00
Geoffrey D. Bennett be157c4683 ALSA: scarlett2: Fix Scarlett 4th Gen autogain status values
The meanings of the raw_auto_gain_status values were originally
guessed through experimentation, but the official names have now been
discovered. Update the autogain status control strings accordingly.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Fixes: 0a995e38dc ("ALSA: scarlett2: Add support for software-controllable input gain")
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Message-ID: <8bd12a5e7dc714801dd9887c4bc5cb35c384e27c.1710047969.git.g@b4.vu>
2024-03-11 09:15:34 +01:00
Geoffrey D. Bennett 6ef1f08b53 ALSA: scarlett2: Fix Scarlett 4th Gen 4i4 low-voltage detection
The value currently being read to determine the low-voltage state is
actually the front panel state. Fix the code to use the correct offset
for the low-voltage state.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Fixes: d7cfa2fdfc ("ALSA: scarlett2: Add power status control")
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Message-ID: <d97b7d87f43b0e54f37e1552394be2f3ae182704.1710047969.git.g@b4.vu>
2024-03-11 09:15:34 +01:00
Kenny Levinsen 1601cd53c7 ALSA: usb-audio: Name feature ctl using output if input is PCM
When building feature controls from a unit without a name, we try to
derive a name first from the feature unit's input, then fall back to the
output terminal.

If a feature unit connects directly to a "USB Streaming" input terminal
rather than a mixer or other virtual type, the control receives the
somewhat meaningless name "PCM", even if the output had a descriptive
type such as "Headset" or "Speaker".

Here is an example of such AudioControl descriptor from a USB headset
which ends up named "PCM Playback" and is therefore not recognized as
headphones by userspace:

      AudioControl Interface Descriptor:
        bLength                12
        bDescriptorType        36
        bDescriptorSubtype      2 (INPUT_TERMINAL)
        bTerminalID             4
        wTerminalType      0x0101 USB Streaming
        bAssocTerminal          5
        bNrChannels             2
        wChannelConfig     0x0003
          Left Front (L)
          Right Front (R)
        iChannelNames           0
        iTerminal               0
      AudioControl Interface Descriptor:
        bLength                 9
        bDescriptorType        36
        bDescriptorSubtype      3 (OUTPUT_TERMINAL)
        bTerminalID             5
        wTerminalType      0x0402 Headset
        bAssocTerminal          4
        bSourceID               6
        iTerminal               0
      AudioControl Interface Descriptor:
        bLength                13
        bDescriptorType        36
        bDescriptorSubtype      6 (FEATURE_UNIT)
        bUnitID                 6
        bSourceID               4
        bControlSize            2
        bmaControls(0)     0x0002
          Volume Control
        bmaControls(1)     0x0000
        bmaControls(2)     0x0000
        iFeature                0

Other headsets and DACs I tried that used their output terminal for
naming only did so due to their input being an unnamed sidetone mixer.

Instead of always starting with the input terminal, check the type of it
first. If it seems uninteresting, invert the order and use the output
terminal first for naming.

This makes userspace recognize headsets with simple controls as
headphones, and leads to more consistent naming of playback devices
based on their outputs irrespective of sidetone mixers.

Signed-off-by: Kenny Levinsen <kl@kl.wtf>
Link: https://lore.kernel.org/r/20240301231107.42679-1-kl@kl.wtf
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-03-04 09:13:44 +01:00
Takashi Iwai 41c25e193b ALSA: usb-audio: More relaxed check of MIDI jack names
The USB audio driver tries to retrieve MIDI jack name strings that can
be used for rawmidi substream names and sequencer port names, but its
checking is too strict: often the firmware provides the jack info for
unexpected directions, and then we miss the info although it's
present.

In this patch, the code to extract the jack info is changed to allow
both in and out directions in a single loop.  That is, the former two
functions to obtain the descriptor pointers for jack in and out are
changed to a single function that returns iJack of the corresponding
jack ID, no matter which direction is used.  It's a code
simplification at the same time as well as the fix.

Fixes: eb596e0fd1 ("ALSA: usb-audio: generate midi streaming substream names from jack names")
Link: https://lore.kernel.org/r/20240215153144.26047-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-02-15 16:56:05 +01:00
Alexander Tsoy eaa1b01fe7 ALSA: usb-audio: Ignore clock selector errors for single connection
For devices with multiple clock sources connected to a selector, we need
to check what a clock selector control request has returned. This is
needed to ensure that a requested clock source is indeed selected and for
autoclock feature to work.

For devices with single clock source connected, if we get an error there
is nothing else we can do about it. We can't skip clock selector setup as
it is required by some devices. So lets just ignore error in this case.

This should fix various buggy Mackie devices:

[  649.109785] usb 1-1.3: parse_audio_format_rates_v2v3(): unable to find clock source (clock -32)
[  649.111946] usb 1-1.3: parse_audio_format_rates_v2v3(): unable to find clock source (clock -32)
[  649.113822] usb 1-1.3: parse_audio_format_rates_v2v3(): unable to find clock source (clock -32)

There is also interesting info from the Windows documentation [1] (this
is probably why manufacturers dont't even test this feature):

"The USB Audio 2.0 driver doesn't support clock selection. The driver
uses the Clock Source Entity, which is selected by default and never
issues a Clock Selector Control SET CUR request."

Link: https://learn.microsoft.com/en-us/windows-hardware/drivers/audio/usb-2-0-audio-drivers [1]
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217314
Link: https://bugzilla.kernel.org/show_bug.cgi?id=218175
Link: https://bugzilla.kernel.org/show_bug.cgi?id=218342
Signed-off-by: Alexander Tsoy <alexander@tsoy.me>
Link: https://lore.kernel.org/r/20240201115308.17838-1-alexander@tsoy.me
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-02-01 15:29:40 +01:00
Alexander Tsoy 346f59d1e8 ALSA: usb-audio: Check presence of valid altsetting control
Many devices with a single alternate setting do not have a Valid
Alternate Setting Control and validation performed by
validate_sample_rate_table_v2v3() doesn't work on them and is not
really needed. So check the presense of control before sending
altsetting validation requests.

MOTU Microbook IIc is suffering the most without this check. It
takes up to 40 seconds to bootup due to how slow it switches
sampling rates:

[ 2659.164824] usb 3-2: New USB device found, idVendor=07fd, idProduct=0004, bcdDevice= 0.60
[ 2659.164827] usb 3-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 2659.164829] usb 3-2: Product: MicroBook IIc
[ 2659.164830] usb 3-2: Manufacturer: MOTU
[ 2659.166204] usb 3-2: Found last interface = 3
[ 2679.322298] usb 3-2: No valid sample rate available for 1:1, assuming a firmware bug
[ 2679.322306] usb 3-2: 1:1: add audio endpoint 0x3
[ 2679.322321] usb 3-2: Creating new data endpoint #3
[ 2679.322552] usb 3-2: 1:1 Set sample rate 96000, clock 1
[ 2684.362250] usb 3-2: 2:1: cannot get freq (v2/v3): err -110
[ 2694.444700] usb 3-2: No valid sample rate available for 2:1, assuming a firmware bug
[ 2694.444707] usb 3-2: 2:1: add audio endpoint 0x84
[ 2694.444721] usb 3-2: Creating new data endpoint #84
[ 2699.482103] usb 3-2: 2:1 Set sample rate 96000, clock 1

Signed-off-by: Alexander Tsoy <alexander@tsoy.me>
Link: https://lore.kernel.org/r/20240129121254.3454481-1-alexander@tsoy.me
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-01-29 16:46:01 +01:00
Alexander Tsoy c0787fcff8 Revert "ALSA: usb-audio: Skip setting clock selector for single connections"
This reverts commit 67794f882a.

We need to explicitly set up the clock selector to workaround a problem
with the Behringer mixers. This was originally done in d2e8f64125
("ALSA: usb-audio: Explicitly set up the clock selector")

The problem with MOTU M Series mentioned in commit message was fixed in
a different way by checking control capabilities of clock selectors.

Signed-off-by: Alexander Tsoy <alexander@tsoy.me>
Link: https://lore.kernel.org/r/20240128132338.819273-1-alexander@tsoy.me
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-01-29 09:07:57 +01:00
Alexander Tsoy eeca59a6e8 ALSA: usb-audio: Support read-only clock selector control
Clock selector control might be read-only. Add corresponding checks
to prevent sending control requests that would fail.

Signed-off-by: Alexander Tsoy <alexander@tsoy.me>
Link: https://lore.kernel.org/r/20240125205457.28258-1-alexander@tsoy.me
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-01-26 16:07:32 +01:00
Takashi Iwai 668abe6dc7 ALSA: usb-audio: Sort quirk table entries
The quirk table entries should be put in the USB ID order, but some
entries have been put in random places.  Re-sort them.

Fixes: bf990c1023 ("ALSA: usb-audio: add quirk to fix Hamedal C20 disconnect issue")
Fixes: fd28941cff ("ALSA: usb-audio: Add new quirk FIXED_RATE for JBL Quantum810 Wireless")
Fixes: dfd5fe19db ("ALSA: usb-audio: Add FIXED_RATE quirk for JBL Quantum610 Wireless")
Fixes: 4a63e68a29 ("ALSA: usb-audio: Fix microphone sound on Nexigo webcam.")
Fixes: 7822baa844 ("ALSA: usb-audio: add quirk for RODE NT-USB+")
Fixes: 4fb7c24f69 ("ALSA: usb-audio: Add quirk for Fiero SC-01")
Fixes: 2307a0e1ca ("ALSA: usb-audio: Add quirk for Fiero SC-01 (fw v1.0.0)")
Link: https://lore.kernel.org/r/20240124155307.16996-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-01-24 16:57:11 +01:00
Sean Young 7822baa844 ALSA: usb-audio: add quirk for RODE NT-USB+
The RODE NT-USB+ is marketed as a professional usb microphone, however the
usb audio interface is a mess:

[    1.130977] usb 1-5: new full-speed USB device number 2 using xhci_hcd
[    1.503906] usb 1-5: config 1 has an invalid interface number: 5 but max is 4
[    1.503912] usb 1-5: config 1 has no interface number 4
[    1.519689] usb 1-5: New USB device found, idVendor=19f7, idProduct=0035, bcdDevice= 1.09
[    1.519695] usb 1-5: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[    1.519697] usb 1-5: Product: RØDE NT-USB+
[    1.519699] usb 1-5: Manufacturer: RØDE
[    1.519700] usb 1-5: SerialNumber: 1D773A1A
[    8.327495] usb 1-5: 1:1: cannot get freq at ep 0x82
[    8.344500] usb 1-5: 1:2: cannot get freq at ep 0x82
[    8.365499] usb 1-5: 2:1: cannot get freq at ep 0x2

Add QUIRK_FLAG_GET_SAMPLE_RATE to work around the broken sample rate get.
I have asked Rode support to fix it, but they show no interest.

Signed-off-by: Sean Young <sean@mess.org>
Cc: <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20240124151524.23314-1-sean@mess.org
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-01-24 16:28:59 +01:00
Alexander Tsoy d915a6850e ALSA: usb-audio: Add delay quirk for MOTU M Series 2nd revision
Audio control requests that sets sampling frequency sometimes fail on
this card. Adding delay between control messages eliminates that problem.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=217601
Cc: <stable@vger.kernel.org>
Signed-off-by: Alexander Tsoy <alexander@tsoy.me>
Link: https://lore.kernel.org/r/20240124130239.358298-1-alexander@tsoy.me
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-01-24 14:41:54 +01:00
Jacob Siverskog 7c4298534c ALSA: usb-audio: fix typo
fix typo in midi fallback log.

Signed-off-by: Jacob Siverskog <jacob@teenage.engineering>
Fixes: ff49d1df79 ("ALSA: usb-audio: USB MIDI 2.0 UMP support")
Link: https://lore.kernel.org/r/20240124101827.35433-1-jacob@teenage.engineering
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-01-24 14:40:47 +01:00
Alexander Tsoy 67794f882a ALSA: usb-audio: Skip setting clock selector for single connections
Since commit 086b957cc1 ("ALSA: usb-audio: Skip the clock selector
inquiry for single connections") we are already skipping clock selector
inquiry if only one clock source is connected, but we are still sending
a set request. Lets skip that too.

This should fix errors when setting a sample rate on devices that don't
have any controls present within the clock selector. An example of such
device is the new revision of MOTU M Series (07fd:000b):

      AudioControl Interface Descriptor:
        bLength                 8
        bDescriptorType        36
        bDescriptorSubtype     11 (CLOCK_SELECTOR)
        bClockID                1
        bNrInPins               1
        baCSourceID(0)          2
        bmControls           0x00
        iClockSelector          0

Perhaps we also should check if clock selectors are readable and writeable
like we already do for clock sources, but this is out of scope of this
patch.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=217601
Signed-off-by: Alexander Tsoy <alexander@tsoy.me>
Link: https://lore.kernel.org/r/20240123134635.54026-1-alexander@tsoy.me
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-01-23 15:10:25 +01:00
Julian Sikorski a969210066 ALSA: usb-audio: Add a quirk for Yamaha YIT-W12TX transmitter
The device fails to initialize otherwise, giving the following error:
[ 3676.671641] usb 2-1.1: 1:1: cannot get freq at ep 0x1

Signed-off-by: Julian Sikorski <belegdol+github@gmail.com>
Cc: <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20240123084935.2745-1-belegdol+github@gmail.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-01-23 10:08:10 +01:00
Takashi Iwai 3787ffdd13 ALSA: scarlett2: Fix yet more -Wformat-truncation warnings
The recent code change introduced a few false-positive compile
warnings with -Wformat-trucation again.  Suppress them by replacing
snprintf() with scnprintf().

Fixes: 0a995e38dc ("ALSA: scarlett2: Add support for software-controllable input gain")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202401062344.AzZCYlpa-lkp@intel.com/
Link: https://lore.kernel.org/r/20240112171000.31855-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-01-15 12:41:14 +01:00
Geoffrey D. Bennett 4a2c8cc164 ALSA: scarlett2: Add PCM Input Switch for Solo Gen 4
When the Direct button on the Solo Gen 4 is held for 3 seconds, the
PCM 1 and 2 inputs are toggled between DSP Outputs 1 and 2, and Mixer
Outputs E and F. This patch adds the corresponding ALSA control.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/8c67c6131c459588ac4edab11e1fbc40a8297328.1703612638.git.g@b4.vu
2023-12-29 15:52:14 +01:00
Geoffrey D. Bennett 4e809a2996 ALSA: scarlett2: Add support for Solo, 2i2, and 4i4 Gen 4
Add new Focusrite Scarlett Gen 4 USB IDs, notification arrays, config
sets, and device info data.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/b33526d3b7a56bb2c86aa4eb2137a415bd23f1ce.1703612638.git.g@b4.vu
2023-12-29 15:52:14 +01:00
Geoffrey D. Bennett 2ecca0df90 ALSA: scarlett2: Add R/O headphone volume control
The Scarlett 4i4 Gen 4 adds a R/O headphone volume control in addition
to a R/O master volume control (which is already supported).

Mark the new scarlett2_notify_volume() function with __always_unused
until it gets used when the Gen 4 notification callback function arrays
are added.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/bd4a76da157f8cc3fbfa02eba96d02bdb86817c5.1703612638.git.g@b4.vu
2023-12-29 15:52:14 +01:00
Geoffrey D. Bennett f6a817e679 ALSA: scarlett2: Add minimum firmware version check
Early firmware for the Scarlett Gen 4 devices has sufficient
differences that it is better to enforce a minimum firmware version
than to try and work around those differences. Add a minimum firmware
version field to the device info struct, and display a message if the
firmware version is too old. Only create the Firmware Version and MSD
(optional) controls in this case.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/5455a7e54bda81556066abd7f761b10e9c5f8a16.1703612638.git.g@b4.vu
2023-12-29 15:52:14 +01:00
Geoffrey D. Bennett 66946398a4 ALSA: scarlett2: Rename DSP mux channels
The DSP mux channels are of type SCARLETT2_PORT_TYPE_MIX so the
ALSA controls would refer to them "Mix X" and "Mixer Input X". This
patch fixes them to be called "DSP X" and "DSP Input X".

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/2d91d0a74d5c7f6179e950bed2c80a4498d16649.1703612638.git.g@b4.vu
2023-12-29 15:52:14 +01:00
Geoffrey D. Bennett 166e1dfb75 ALSA: scarlett2: Add support for DSP mux channels
The DSP mux channels in the Scarlett 4th Gen appear as
SCARLETT2_PORT_TYPE_MIX ports but do not have corresponding mixer
controls. Add a dsp_count option to the device info struct to exclude
those DSP channels from the num_mix_in/num_mix_out counts.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/b78bdb1a7624d55783f5bf0e1ffbfa47a9e9a800.1703612638.git.g@b4.vu
2023-12-29 15:52:13 +01:00
Geoffrey D. Bennett c6c9f0cf9d ALSA: scarlett2: Add support for custom Gen 4 Direct Monitor mixes
The mixes used by Direct Monitor feature on the Scarlett 4th Gen Solo
and 2i2 interfaces are configurable. This patch adds ALSA controls for
the gains which are copied to the mixer when Direct Monitor is
enabled.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/96282a805b45f04560e5923d170745363906b7f3.1703612638.git.g@b4.vu
2023-12-29 15:52:13 +01:00
Geoffrey D. Bennett e8e14270d8 ALSA: scarlett2: Handle Gen 4 Direct Monitor mix updates
When the Direct Monitor feature on the Scarlett 4th Gen Solo and 2i2
interfaces is used, the Mix A and B gains are updated by the
interface. This patch calls snd_ctl_notify() for the ALSA mix controls
when a Direct Monitor notification is received.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/713d032e343e0547212368919bef17d6fa1c9d29.1703612638.git.g@b4.vu
2023-12-29 15:52:13 +01:00
Geoffrey D. Bennett ac19be067a ALSA: scarlett2: Store mix_ctls for Gen 4 Direct Monitor
The Scarlett 4th Gen small interfaces have a software-controllable
mixer like the large 2nd and 3rd Gen interfaces do. Pressing the
"Direct" button on the interface updates the mixer controls, which
this driver hasn't needed to deal with previously.

This commit stores the ALSA mixer controls, and adds a mix_updated
flag so that the controls can be updated when a notification is
received.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/3ba27c60230511b80b0fa75727551ea70f17d829.1703612638.git.g@b4.vu
2023-12-29 15:52:13 +01:00
Geoffrey D. Bennett d7cfa2fdfc ALSA: scarlett2: Add power status control
Add a control to retrieve the power status from the interface
(bus-powered, external-powered, or insufficient power).

Mark the new scarlett2_notify_power_status() function with
__always_unused until it gets used when the Gen 4 notification
callback function arrays are added.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/d9806bc41adc45b1c19749562fec7765ba24351d.1703612638.git.g@b4.vu
2023-12-29 15:52:13 +01:00
Geoffrey D. Bennett 882a2a36c4 ALSA: scarlett2: Disable autogain during phantom power state change
When phantom power is enabled or disabled, the autogain control cannot
be enabled until the interface has signalled that the change is
complete and the input is unmuted. Update those controls to be
read-only during this time.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/f49f7bf9358e1f20713d95d407d8d6a436859877.1703612638.git.g@b4.vu
2023-12-29 15:52:13 +01:00
Geoffrey D. Bennett 0d2e791db4 ALSA: scarlett2: Disable input controls while autogain is running
While the autogain function is running, the other input controls
(select, link, gain, safe, level, air, and phantom) can't be modified.
Update those controls to be read-only during this time.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/ad13bacae77860de8c2d7c89f6ec2a1ee104e65f.1703612638.git.g@b4.vu
2023-12-29 15:52:13 +01:00
Geoffrey D. Bennett a1ed1d6caf ALSA: scarlett2: Minor refactor MSD mode check
Create local variable for storing private data pointer in
snd_scarlett2_controls_create(). It's currently only used for checking
msd_switch, but it will be used again.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/ab50939dca0fdc5fa3493fc8eee3a2fdefffa62d.1703612638.git.g@b4.vu
2023-12-29 15:52:13 +01:00
Geoffrey D. Bennett 0a995e38dc ALSA: scarlett2: Add support for software-controllable input gain
Some devices in the Scarlett Gen 4 series have support for
software-controllable input gain. Along with this comes a channel
select option, an auto-gain feature, "safe" mode, and linking two
channels into a stereo pair.

Mark the new scarlett2_notify_input_*() functions with __always_unused
until they get used when the Gen 4 notification callback function
arrays are added.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/fc39e80bb39863dd1579d342097203942b4f3034.1703612638.git.g@b4.vu
2023-12-29 15:52:13 +01:00
Geoffrey D. Bennett 038216f2bc ALSA: scarlett2: Add support for Air Presence + Drive option
Extend the existing "air" option support from Scarlett Gen 3, which
had two states (off/on), to accommodate Scarlett Gen 4's new state:
Presence + Drive.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/a9ccda7222842a72e4ce7aa258614ff45248bb16.1703612638.git.g@b4.vu
2023-12-29 15:52:13 +01:00
Geoffrey D. Bennett 1b53c11623 ALSA: scarlett2: Allow for controls with a "mute mode"
Gen 2/3 interfaces would only use 0/1 values for input level and
phantom power switch controls. Gen 4 interfaces use the second bit to
indicate that the state should be changed (or is changing), and the
input is to be muted (or is muted) while that happens.

Add a "mute" flag to config items to enable this behaviour for the
level/phantom controls.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/f603cd16079c97fad910087e0302828a289d1c15.1703612638.git.g@b4.vu
2023-12-29 15:52:13 +01:00
Geoffrey D. Bennett 4fa07ff7b6 ALSA: scarlett2: Add support for Gen 4 style parameters
Writing Scarlett Gen 4 parameters differs from Gen 2 and Gen 3:
- the values are written into a shared write location
- the values are only byte-sized
- the read locations now extend beyond 0xFF
- a separate NVRAM save step is no longer required

This patch implements that alternate write style, triggered by setting
the config item size field to zero.

The write address is specified through a new config set field
gen4_write_addr.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/1624e6d8a0c629c3bdfe53825b16e8b589724fc4.1703612638.git.g@b4.vu
2023-12-29 15:52:12 +01:00
Geoffrey D. Bennett dd57b1213a ALSA: scarlett2: Add support for air/phantom control on input 2
The Focusrite Scarlett Gen 4 Solo has Air and Phantom Power controls
on analogue input #2 (the Gen 3 Solo had these controls on analogue
input #1). Add air_input_first and phantom_first device info options
to cater for this.

These options are similar to the level_input_first option that was
added for the Gen 3 Solo, but these new options do not require
adjusting the index of the control.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/19511f18895b8c094985a4a5691fbc1dc028c108.1703612638.git.g@b4.vu
2023-12-29 15:52:12 +01:00
Geoffrey D. Bennett 4dedf7ca92 ALSA: scarlett2: Remove repeated elem->head.mixer references
Use a local variable *mixer rather than repeating elem->header.mixer
in scarlett2_direct_monitor_ctl_get() and scarlett2_meter_ctl_get().

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/b21bacf4056366e10e01077e224d2b4970fdfe31.1703612638.git.g@b4.vu
2023-12-29 15:52:12 +01:00
Geoffrey D. Bennett d3cf557b26 ALSA: scarlett2: Split direct_monitor out from monitor_other
The notification value for monitor_other on the large interfaces is
the same as the notification value for direct_monitor on the 3rd Gen
small interfaces. Add a separate scarlett3a_notifications array and
split out the direct_monitor handling.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Link: https://lore.kernel.org/r/9b56a483e3e9c1447684f18239a88652c1f01445.1703444932.git.g@b4.vu
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2023-12-29 15:41:23 +01:00
Geoffrey D. Bennett d9b63123fb ALSA: scarlett2: Split input_other into level/pad/air/phantom
Gen 2/3 devices have a single notification value for "input other"
changes. Gen 4 has separate notification values for level, pad, air,
and phantom power changes. Therefore, split the input_other_updated
field and the scarlett2_update_input_other() function into the four
components so that they can be handled separately later.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Link: https://lore.kernel.org/r/a1a1d190659d56689792aa20ceeb53a6175171ad.1703444932.git.g@b4.vu
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2023-12-29 15:41:23 +01:00
Geoffrey D. Bennett ad5174608e ALSA: scarlett2: Rename db_scale_scarlett2_gain to volume
db_scale_scarlett2_gain is the TLV for the output volume controls.
Gen 4 has software-controllable input gain controls, so rename this to
db_scale_scarlett2_volume so we can use that name for the inputs.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Link: https://lore.kernel.org/r/d544ec7cc5d5a849da104a5a78b17f61f50657c1.1703444932.git.g@b4.vu
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2023-12-29 15:41:23 +01:00
Geoffrey D. Bennett a1faecfcfe ALSA: scarlett2: Add #define for SCARLETT2_MIX_MAX
Add a #define for SCARLETT2_MIX_MAX (max of mixer inputs * outputs) as
that will be used again soon.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Link: https://lore.kernel.org/r/83cec5ccd75f0db2bd061a76d31a7023d26300c1.1703444932.git.g@b4.vu
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2023-12-29 15:41:23 +01:00
Geoffrey D. Bennett 56275126ac ALSA: scarlett2: Add scarlett2_mixer_value_to_db()
Refactor scarlett2_usb_get_mix(), moving the scarlett2_mixer_values[]
lookup into scarlett2_mixer_value_to_db().

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Link: https://lore.kernel.org/r/7adf869852aba2819fddb850b0ea8df5f7d73931.1703444932.git.g@b4.vu
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2023-12-29 15:41:23 +01:00
Geoffrey D. Bennett 90d8fef837 ALSA: scarlett2: Allow for interfaces without per-channel volume
Currently-supported interfaces with a mixer have per-channel volume
controls, but this changes in Gen 4. Add a check so that the Playback
Volume and associated controls don't get created unless the
SCARLETT2_CONFIG_LINE_OUT_VOLUME config item is present.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Link: https://lore.kernel.org/r/30f68cb311e27f2cc1351cb846218f7248a90263.1703444932.git.g@b4.vu
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2023-12-29 15:41:23 +01:00
Geoffrey D. Bennett c6b3e71e2c ALSA: scarlett2: Remove line_out_hw_vol device info entry
By splitting config set gen2 into gen2a/b (for 6i6/18i8 vs 18i20), and
gen3b into gen3b/c (for 4i4/8i6 vs 18i8/18i20), we can use
scarlett2_has_config_item() instead of the per-device line_out_hw_vol.

As Gen 4 has a master volume control but no SW/HW switches, check for
both SCARLETT2_CONFIG_MASTER_VOLUME and SCARLETT2_CONFIG_SW_HW_SWITCH
as needed, even though for Gen 2 and Gen 3 the former implies the
latter.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Link: https://lore.kernel.org/r/307c4f8d6d2e034f3e386b51d72a39d77c8a9fce.1703444932.git.g@b4.vu
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2023-12-29 15:41:23 +01:00
Geoffrey D. Bennett e79aea579a ALSA: scarlett2: Split dim_mute_update from vol_updated
Scarlett Gen 2 and Gen 3 devices combine volume and dim/mute
notifications. The Scarlett 4i4 Gen 4 has volume change notification
but no dim/mute control so split dim_mute_update out from vol_update.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Link: https://lore.kernel.org/r/bf63f48bcc68ae739bd9948c8ee2f87ee7af22a2.1703444932.git.g@b4.vu
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2023-12-29 15:41:23 +01:00
Geoffrey D. Bennett 80c7933e74 ALSA: scarlett2: Remove struct scarlett2_usb_volume_status
The struct scarlett2_usb_volume_status matched the config space layout
of a few volume controls that could be read together and were in fixed
locations between Gen 2 and Gen 3 devices.

Gen 4 devices have removed, moved, and new related controls, so this
needs to be cleaned up. By adding SCARLETT2_CONFIG_MASTER_VOLUME (the
only config item that didn't already have its own entry, because it is
read-only), we can remove:
- struct scarlett2_usb_volume_state,
- #define SCARLETT2_USB_VOLUME_STATUS_OFFSET, and
- scarlett2_usb_get_volume_status()
and replace with calls to scarlett2_usb_get_config().

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Link: https://lore.kernel.org/r/2ee88994857246bf89fab8e62ac279f3bcf96192.1703444932.git.g@b4.vu
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2023-12-29 15:41:23 +01:00
Geoffrey D. Bennett 42caae0e20 ALSA: scarlett2: Refactor common port_count lookups
Rather than looking up the analogue and mixer I/O counts repeatedly in
info->port_count[SCARLETT2_PORT_TYPE_*][SCARLETT2_PORT_*], save those
numbers in private variables.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Link: https://lore.kernel.org/r/db0a5b56bdff476e2e31ad8e5ee15008314412b7.1703444932.git.g@b4.vu
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2023-12-29 15:41:23 +01:00
Geoffrey D. Bennett e5fab78cd8 ALSA: scarlett2: Change num_mux_* from int to u8
num_mux_srcs and num_mux_dsts will fit into a u8, so change the type.
More similar counts are coming soon.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Link: https://lore.kernel.org/r/886fbd9ce7f06b13c6dbf36f64e6b2d107d16a83.1703444932.git.g@b4.vu
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2023-12-29 15:41:23 +01:00