ALSA: usb-audio: Audient iD14 MkI vendor controls
cover ALSA: usb-audio: Audient iD14 MkI vendor controls
The Audient iD14 MkI (2708:0002) keeps its monitor section, output routing, mixer and input options on vendor extension units. It also uses feature units whose descriptors declare no controls. On Linux a user cannot change the routing. The device powers up with every output on DAW Thru, which bypasses the volume knob.
This series adds those controls in a new mixer_audient_id.c, one group per patch. A MkI-only name map hides the generic controls that each group replaces. The MkII keeps audient_id14_map.
Scope: only the iD14 MkI is supported, and only its USB ID reaches the new code. Other Audient iD models keep the generic driver. Their units may differ, and this series does not cover them. The file follows mixer_scarlett2.c, which began with one model and added others through per-model tables. Names with id14_ hold the MkI's unit IDs and tables. A later iD model can add its own tables to this file.
sound for-next also has mixer_evo.c for the Audient EVO 4 (2708:0006). EVO and iD are separate Audient product lines. The iD14 MkI uses other units and a larger control set: a monitor controller, output routing, a 14 x 4 mixer and write-only controls. So this series keeps the iD line in its own file.
At probe the driver writes only controls that it cannot read back: the write-only controls (patch 4) and FU 12 (patch 5). They get the launch values of Audient's iD application. If a probe write fails, the control shows the fallback value that those patches describe. The driver does not write the routing or the mix. User space (alsactl, an application) sets the rest of the iD application's launch state.
There is no resume code. Every write to a write-only control reaches the device, so alsactl restore also repairs a device that was reset. The state across a suspend depends on the power source:
- On USB bus power, a system suspend re-enumerates the device.
- With its mains adapter connected, the device keeps its state across a system suspend. This is also true when the host controller resets the device and the card stays. The sampled readable controls did not change.
- A runtime suspend left the readable controls unchanged on both power sources, with no reset logged. A runtime suspend is possible only after usbhid releases the HID interface.
Patch 5 replaces the generic "Monitor Mix Playback Volume" (FU 12) with one of the same name, count and range. FU 12 GET CUR returns stale data from other units. Its Main L channel ignores writes, but Main R applies them. audient_id14_map already notes this asymmetry. The new control holds Main at 0 dB. This is a deliberate change for existing users: a Main R attenuation set through the generic control no longer applies.
The protocol comes from Audient's iD application (version 4.4.5 for macOS). USB captures of the application confirmed it.
Test setup:
- iD14 MkI, firmware 1.1.1
- Bazzite 44, kernel 7.2.9-ogc3.1.fc44
- snd-usb-audio built out of tree from the v7.2.9 sound/usb sources with this series applied
Tests:
- listening tests: routing, dim, talkback, Cue
- a loopback cable: gain boost, polarity, FU 12 per channel
- alsactl store and restore across a replug
- an out-of-list routing value
- a runtime suspend
- three system suspends (S3) with control reads running at about 3000 per second: no read failed after a resume
- the optical power-on mode, read on macOS 27.0.1 with no Audient software running
The series is based on sound for-next a4ef328ce3b3. Each patch builds on its own there with make W=1 sound/usb/. The hardware tests used the complete series on 7.2.9 sources, where snd_usb_mixer_add_list() has no look_for_empty argument. The series passes true, which keeps that behaviour.
Will Porter (5):
ALSA: usb-audio: Give the Audient iD14 MkI its own mixer map
ALSA: usb-audio: Add Audient iD14 MkI monitor and routing controls
ALSA: usb-audio: Add Audient iD14 MkI mixer matrix
ALSA: usb-audio: Add Audient iD14 MkI write-only controls
ALSA: usb-audio: Replace the Audient iD14 MkI FU 12 control
sound/usb/Makefile | 1 + sound/usb/mixer_audient_id.c | 790 +++++++++++++++++++++++++++++++++++ sound/usb/mixer_audient_id.h | 7 + sound/usb/mixer_maps.c | 10 +- sound/usb/mixer_quirks.c | 4 + 5 files changed, 811 insertions(+), 1 deletion(-) create mode 100644 sound/usb/mixer_audient_id.c create mode 100644 sound/usb/mixer_audient_id.h
base-commit: a4ef328ce3b3ab1bf63c6350e890f13b9b25e3f1
Signature · 1 line
2.47.3
PATCH 1/5 ALSA: usb-audio: Give the Audient iD14 MkI its own mixer map
The iD14 MkI (2708:0002) and MkII (2708:0008) share audient_id14_map. Later commits add MkI vendor controls that replace some of the generic MkI controls. The MkII keeps the generic controls. Give the MkI its own copy of the map.
No functional change.
--- sound/usb/mixer_maps.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
sound/usb/mixer_maps.c +7 -1
@@ -526,6 +526,12 @@ static const struct usbmix_name_map audient_id14_map[] = { {} }; +/* Audient iD14 MkI: model-specific control map. */ +static const struct usbmix_name_map audient_id14_mk1_map[] = { + {12 ,"Monitor Mix Playback" },/* FU, partial coverage */ + {} +}; +/* * Audient iD24: feature unit 12 ("Speaker Playback Volume") sits in the * monitor-mixer branch and does not apply volume to all of its channels;
@@ -638,7 +644,7 @@ static const struct usbmix_ctl_map usbmix_ctl_maps[] = { {/* Audient iD14 MkI */ .id = USB_ID(0x2708, 0x0002), - .map = audient_id14_map, + .map = audient_id14_mk1_map, }, {/* Audient EVO4 MkI */
Signature · 1 line
2.47.3
PATCH 2/5 ALSA: usb-audio: Add Audient iD14 MkI monitor and routing controls
In reply to Will PorterThe iD14 MkI keeps three groups of controls where the generic driver cannot discover them:
- the monitor controller, on Audient extension unit 54
- the headphone level, on feature unit 10, whose descriptor declares no controls
- the output routing, on extension unit 51
So Linux users cannot change the routing. The MkI powers up with every output on DAW Thru: the USB stream goes straight to the output and bypasses the volume knob.
Add mixer_audient_id.c with these controls:
- Monitor Speaker Playback Volume and Switch (speaker level and cut)
- Monitor Dim Playback Switch, Monitor Dim Level Playback Volume
- Monitor Mono Playback Switch, Monitor Mono Mode Playback Enum
- Monitor Polarity Invert Playback Switch
- Monitor Headphone Playback Volume and Switch (FU 10, channels 3-4)
- Talkback Playback Switch
- Main Out L/R Source Playback Enum, Headphone L/R Source Playback Enum:
"Main Mix", "Cue Mix" or "DAW Thru (full scale)"
Every get reads the device, because the volume knob changes the speaker and headphone levels. The volumes are 0-128 in 1 dB steps: 0 is -128 dB (mute) and 128 is 0 dB. The driver converts them to the device's s16 in 1/256 dB.
The routing controls are mono enums, as in mixer_scarlett2.c. Thus one output on DAW Thru cannot hide behind its pair. The "... Playback Enum" names follow the same driver. A source outside the list reads as an extra item, "Other". A put rejects "Other", but alsactl store saves it. A restore of it then fails for that control only, or for the card with --pedantic. The restore cannot recreate the original source. So after a replug on bus power, that output stays on its power-on source, DAW Thru.
The file is named for the iD family and keeps model data in per-model tables, as mixer_scarlett2.c does. Only the iD14 MkI is supported. Other iD models keep the generic driver.
The driver writes nothing at probe. User space sets the launch state of Audient's iD application (all outputs on Main Mix).
Test setup:
- iD14 MkI, firmware 1.1.1
- Bazzite 44, kernel 7.2.9-ogc3.1.fc44
- snd-usb-audio built out of tree from the v7.2.9 sound/usb sources and the complete driver (this commit and the later ones)
Results:
- routing: listening tests (Main Mix and Cue Mix, left and right) and read-back
- dim, by ear: host switch and iD key
- talkback, by ear (a later commit adds the talkback source control)
- alsactl store and restore across a replug
- an out-of-list routing byte (0x13) reads as "Other"
--- sound/usb/Makefile | 1 + sound/usb/mixer_audient_id.c | 407 +++++++++++++++++++++++++++++++++++ sound/usb/mixer_audient_id.h | 7 + sound/usb/mixer_quirks.c | 4 + 4 files changed, 419 insertions(+) create mode 100644 sound/usb/mixer_audient_id.c create mode 100644 sound/usb/mixer_audient_id.h
sound/usb/Makefile +1 -0
@@ -11,6 +11,7 @@ snd-usb-audio-y := card.o \ helper.o \ implicit.o \ mixer.o \ + mixer_audient_id.o \ mixer_evo.o \ mixer_quirks.o \ mixer_scarlett.o \
sound/usb/mixer_audient_id.c new file +407 -0
407 lines not on this page · raw message
sound/usb/mixer_audient_id.h new file +7 -0
@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __USB_MIXER_AUDIENT_ID_H +#define __USB_MIXER_AUDIENT_ID_H + +int snd_audient_id14_mk1_controls_create (struct usb_mixer_interface *mixer); + +#endif /* __USB_MIXER_AUDIENT_ID_H */
sound/usb/mixer_quirks.c +4 -0
@@ -34,6 +34,7 @@#include "usbaudio.h" #include "mixer.h" #include "mixer_quirks.h" +#include "mixer_audient_id.h" #include "mixer_scarlett.h" #include "mixer_scarlett2.h" #include "mixer_us16x08.h"
@@ -4609,6 +4610,9 @@ int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)case USB_ID (0x03f0 ,0x0269 ):/* HP TB Dock G2 */ err =hp_dock_mixer_create (mixer);break ; +case USB_ID (0x2708 ,0x0002 ):/* Audient iD14 MkI */ + err =snd_audient_id14_mk1_controls_create (mixer); +break ; }return err;
Signature · 1 line
2.47.3
PATCH 3/5 ALSA: usb-audio: Add Audient iD14 MkI mixer matrix
In reply to Will PorterMixer unit 60 mixes 14 inputs (Mic 1-2, Digi 1-8, DAW 1-4) into four outputs (Main L/R, Cue L/R). GET RANGE reports -127 to 0 dB in 1 dB steps, so the generic driver creates four "Analogue 4 Volume" controls with values from 0 to 127. The crosspoints take -128 dB (mute) to +6 dB in 1/256 dB steps. The reported range cannot show the gains above 0 dB or the fine steps that Audient's iD application uses.
Add one control per crosspoint, "Mix <output> <input> Playback Volume". The value is the device's s16 in 1/256 dB, from -128 dB (mute) to +6 dB. The fine steps carry the pan law of Audient's iD application. GET CUR works, so get reads the device. Hide the generic controls in the MkI map. The driver writes nothing to the mixer at probe.
Test setup:
- iD14 MkI, firmware 1.1.1
- Bazzite 44, kernel 7.2.9-ogc3.1.fc44
- snd-usb-audio built out of tree from the v7.2.9 sound/usb sources and the complete driver (this commit and the later ones)
Results:
- crosspoints read back after writes
- DAW 1/2 reach Main L/R and Cue L/R through them (listening test)
--- sound/usb/mixer_audient_id.c | 124 +++++++++++++++++++++++++++++++++++ sound/usb/mixer_maps.c | 1 + 2 files changed, 125 insertions(+)
sound/usb/mixer_audient_id.c +124 -0
@@ -43,6 +43,7 @@#define ID14_FU_OUT 0x0a/* feature unit before the outputs */ #define ID14_ROUTE 0x33/* routing XU: CN = destination */ #define ID14_MON 0x36/* monitor controller XU */ +#define ID14_MIXER 0x3c/* mixer unit: 14 inputs x 4 outputs */ /* Control selectors */ #define ID14_ROUTE_SOURCE 0x06/* u8: source of the destination */
@@ -60,6 +61,7 @@* use 1 dB steps. The controls show the steps: 0 (-128 dB, mute) ... 128 (0 dB). */ #define ID_DB (db) ((db) * 256) +#define ID_DB_MIN ID_DB(-128)/* 0x8000: mute */ #define ID_VOL_MAX 128/* control value for 0 dB */ enum id_kind {
@@ -392,10 +394,125 @@ static int id_add_ctl(struct usb_mixer_interface *mixer, const struct id_ctl *c)return snd_usb_mixer_add_list (&e->list, kctl, false, true); } +/* +* iD14 MkI mixer crosspoints: CS 1, CN = input * 4 + output, s16 in +* 1/256 dB. The control value is the raw s16, -128 dB (mute) ... +6 dB; +* the iD application's pan law needs the fine steps. GET CUR works; no +* probe writes. +*/ +#define ID14_MIX_OUTPUTS 4 +#define ID14_MIX_MAX ID_DB(6) + +static const char *const id14_mix_inputs[] = { +"Mic 1" ,"Mic 2" , +"Digi 1" ,"Digi 2" ,"Digi 3" ,"Digi 4" ,"Digi 5" ,"Digi 6" ,"Digi 7" ,"Digi 8" , +"DAW 1" ,"DAW 2" ,"DAW 3" ,"DAW 4" , +}; + +static const char *const id14_mix_outputs[ID14_MIX_OUTPUTS ] = { +"Main L" ,"Main R" ,"Cue L" ,"Cue R" , +}; + +static const DECLARE_TLV_DB_MINMAX_MUTE(id14_mix_tlv, -12800, 600); + +static int id14_mix_info (struct snd_kcontrol *kctl,struct snd_ctl_elem_info *uinfo) +{ + uinfo->type =SNDRV_CTL_ELEM_TYPE_INTEGER ; + uinfo->count =1 ; + uinfo->value.integer.min =ID_DB_MIN ; + uinfo->value.integer.max =ID14_MIX_MAX ; +return 0 ; +} + +struct id14_mix { +struct usb_mixer_elem_list list;/* first: snd_usb_mixer_elem_free */ +u8 cn; +}; + +static int id14_mix_read (struct id14_mix *m,long *val) +{ +u8 buf[2 ]; +int err; + + err =id_xfer (m->list.mixer, false,ID14_MIXER ,UAC2_MU_MIXER , m->cn, buf,sizeof (buf)); +if (err <0 ) +return err; + *val =clamp_t (long, (s16 )get_unaligned_le16 (buf),ID_DB_MIN ,ID14_MIX_MAX ); +return 0 ; +} + +static int id14_mix_get (struct snd_kcontrol *kctl,struct snd_ctl_elem_value *v) +{ +struct id14_mix *m =snd_kcontrol_chip (kctl); +long val; +int err; + + err =id14_mix_read (m, &val); +if (err <0 ) +return err; + v->value.integer.value[0 ] = val; +return 0 ; +} + +static int id14_mix_put (struct snd_kcontrol *kctl,struct snd_ctl_elem_value *v) +{ +struct id14_mix *m =snd_kcontrol_chip (kctl); +long cur, val = v->value.integer.value[0 ]; +u8 buf[2 ]; +int err; + +if (val <ID_DB_MIN || val >ID14_MIX_MAX ) +return -EINVAL ; +CLASS (snd_usb_lock, pm)(m->list.mixer->chip); +if (pm.err <0 ) +return pm.err; + err =id14_mix_read (m, &cur); +if (err <0 || cur == val) +return err; +put_unaligned_le16 (val, buf); + err =id_xfer (m->list.mixer, true,ID14_MIXER ,UAC2_MU_MIXER , m->cn, buf,sizeof (buf)); +return err <0 ? err :1 ; +} + +static int id14_mix_add_ctl (struct usb_mixer_interface *mixer,unsigned int in, +unsigned int out) +{ +struct snd_kcontrol_new knew = { + .iface =SNDRV_CTL_ELEM_IFACE_MIXER , + .access =SNDRV_CTL_ELEM_ACCESS_READWRITE | +SNDRV_CTL_ELEM_ACCESS_VOLATILE | +SNDRV_CTL_ELEM_ACCESS_TLV_READ , + .info = id14_mix_info, + .get = id14_mix_get, + .put = id14_mix_put, + .tlv.p = id14_mix_tlv, + }; +struct snd_kcontrol *kctl; +struct id14_mix *m; + + m =kzalloc_obj (*m); +if (!m) +return -ENOMEM ; + m->list.mixer = mixer; + m->list.id =ID14_MIXER ; + m->cn = in *ID14_MIX_OUTPUTS + out; + + kctl =snd_ctl_new1 (&knew, m); +if (!kctl) { +kfree (m); +return -ENOMEM ; + } +snprintf (kctl->id.name,sizeof (kctl->id.name),"Mix %s %s Playback Volume" , + id14_mix_outputs[out], id14_mix_inputs[in]); + kctl->private_free = snd_usb_mixer_elem_free; +return snd_usb_mixer_add_list (&m->list, kctl, false, true); +} +/* called from mixer_quirks.c */ int snd_audient_id14_mk1_controls_create (struct usb_mixer_interface *mixer) {const struct id_ctl *c; +unsigned int in, out;int err;for (c = id14_mk1_ctls; c->name; c++) {
@@ -403,5 +520,12 @@ int snd_audient_id14_mk1_controls_create(struct usb_mixer_interface *mixer)if (err <0 )return err; } +for (in =0 ; in <ARRAY_SIZE (id14_mix_inputs); in++) { +for (out =0 ; out <ID14_MIX_OUTPUTS ; out++) { + err =id14_mix_add_ctl (mixer, in, out); +if (err <0 ) +return err; + } + }return 0 ; }
sound/usb/mixer_maps.c +1 -0
@@ -529,6 +529,7 @@ static const struct usbmix_name_map audient_id14_map[] = {/* Audient iD14 MkI: model-specific control map. */ static const struct usbmix_name_map audient_id14_mk1_map[] = { {12 ,"Monitor Mix Playback" },/* FU, partial coverage */ + {60 ,NULL },/* MU, see mixer_audient_id.c */ {} };
Signature · 1 line
2.47.3
PATCH 4/5 ALSA: usb-audio: Add Audient iD14 MkI write-only controls
In reply to Will PorterSome MkI controls cannot be read back:
- GET stalls for the input gain boost and polarity (feature unit 11), the iD key function and the digital input mode.
- GET of the talkback source answers 0, whatever value a SET wrote.
For FU 11 the generic driver creates "Input Gain Control" and "Phase Inverter Control" and logs "cannot get min/max values".
Add:
- Mic 1/2 Boost Capture Switch (+10 dB)
- Mic 1/2 and Digi 1/2 Polarity Invert Capture Switch
- iD Key Function Playback Enum (ScrollControl, Mono, Mono + Polarity, Dim, Talkback)
- Talkback Source Capture Enum (None, Mic 1-2, Digi 1-8)
- Digital In Mode Capture Enum (ADAT, S/PDIF)
and hide the generic FU 11 controls in the MkI map. The named polarity switches replace the ten values of "Phase Inverter Control". The controls follow Audient's iD application. It offers gain boost on the Mic inputs only, and polarity on the Mic and Digi inputs. The device refuses polarity on Digi 3-8 with EPIPE, in ADAT and in S/PDIF mode (no ADAT signal connected). So Digi 3-8 have no polarity control.
These controls show the last value the device accepted. Every put sends its value, also an unchanged one, so that a restore reaches a device that was reset. At probe the driver sets each control once, so that the value it shows is true:
- boost and polarity off, iD key ScrollControl, talkback source None:
the defaults of the iD application and the manual
- S/PDIF: the MkI's measured power-on mode
If that write fails, the control reads "Unknown" (or off) until a put succeeds. alsactl store saves that value.
The probe write replaces any value the device kept. The device keeps its values across a module reload or a rebind. On mains power it also keeps them across a replug. In each of these cases the controls return to the probe values (for example from ADAT to S/PDIF) until alsactl restore runs.
Test setup:
- iD14 MkI, firmware 1.1.1
- Bazzite 44, kernel 7.2.9-ogc3.1.fc44
- snd-usb-audio built out of tree from the v7.2.9 sound/usb sources and the complete driver (this commit and the later ones)
Results:
- a loopback cable measured the gain boost (+10.0 dB) and the Mic polarity
- listening tests: the iD key set to Dim, talkback from Mic 2
- alsactl restored the controls across a replug
- the optical power-on mode, read on macOS 27.0.1 with no Audient software running: S/PDIF
- the device accepts the Digi 1/2 polarity request. Its effect was not measured.
--- sound/usb/mixer_audient_id.c | 144 +++++++++++++++++++++++++++++++---- sound/usb/mixer_maps.c | 1 + 2 files changed, 129 insertions(+), 16 deletions(-)
sound/usb/mixer_audient_id.c +128 -16
@@ -19,8 +19,10 @@* The protocol comes from Audient's iD application (version 4.4.5 for * macOS). USB captures of the application confirmed it. * -* The controls read the device on every get: the front panel changes -* several of them. +* Most controls read the device on every get. Controls whose GET cannot +* report the current state show the last value the device accepted. +* Every put to these controls sends the value, even when unchanged, so +* that alsactl restore also reaches a device that was reset. * * Get and put need no lock of their own: the control core runs put with * card->controls_rwsem held for writing and get with it held for reading.
@@ -40,12 +42,17 @@#include "mixer_audient_id.h" /* Unit IDs */ +#define ID14_IT_DIGITAL 0x01/* input terminal: optical and coaxial inputs */ #define ID14_FU_OUT 0x0a/* feature unit before the outputs */ +#define ID14_FU_IN 0x0b/* feature unit on the inputs: CN 1-2 Mic, 3-10 Digi */ #define ID14_ROUTE 0x33/* routing XU: CN = destination */ #define ID14_MON 0x36/* monitor controller XU */ #define ID14_MIXER 0x3c/* mixer unit: 14 inputs x 4 outputs */ /* Control selectors */ +#define ID14_IT_OPTICAL_MODE 0x00/* u32: 0 ADAT, 1 S/PDIF */ +#define ID14_IN_BOOST 0x0b/* s16: 0x0a00 = +10 dB, 0 = off */ +#define ID14_IN_POLARITY 0x0d#define ID14_ROUTE_SOURCE 0x06/* u8: source of the destination */ #define ID14_MON_MONO 0x00#define ID14_MON_MONO_MODE 0x01
@@ -54,6 +61,8 @@#define ID14_MON_DIM 0x05#define ID14_MON_DIM_LEVEL 0x06/* s16, 1/256 dB */ #define ID14_MON_TALKBACK 0x07 +#define ID14_MON_TALKBACK_SRC 0x08/* GET always returns 0 */ +#define ID14_MON_ID_KEY 0x10/* u16: the selector the iD key toggles */ #define ID14_MON_VOLUME 0x12/* s16, 1/256 dB; the knob also sets it */ /*
@@ -68,6 +77,7 @@ enum id_kind {ID_BOOL ,/* u8: 1 = on */ ID_BOOL_INV ,/* u8: 1 = cut or mute, shown as a switch that is off */ ID_VOL ,/* s16 in 1/256 dB; control value 0 ... ID_VOL_MAX, 1 dB steps */ +ID_BOOST ,/* s16: on = +10 dB */ ID_ENUM, /* item list with device values (struct id_enum) */ };
@@ -78,6 +88,8 @@ struct id_enum {u8 len;/* bytes on the wire */ }; +#define ID_WO BIT(0)/* write-only: GET stalls or does not report writes */ +struct id_ctl {const char *name;enum id_kind kind;
@@ -85,12 +97,15 @@ struct id_ctl {u8 cs;u8 cn;/* first channel number */ u8 channels; +u8 flags; +int init;/* ID_WO: value written at probe */ const struct id_enum *e; };/* * The texts have one item more than the values. A put cannot select the last -* item, "Other": it shows a device value outside the list. +* item: a readable control shows it for a device value outside the list +* ("Other"), a write-only control while its value is not known ("Unknown"). */ #define ID_ENUM_TEXTS (name, texts_, len_, ...) \ static const u32 name##_values[] = { __VA_ARGS__ }; \
@@ -102,11 +117,35 @@ struct id_ctl { ID_ENUM_TEXTS(name, name##_texts, len_, __VA_ARGS__); \ static_assert(ARRAY_SIZE(name##_texts) == ARRAY_SIZE(name##_values) + 1) +/* +* iD key function: the value is the monitor-controller selector the key +* toggles. ScrollControl (0xffff) toggles nothing: the knob then scrolls +* through the HID interface. + */ +static const char *const id14_id_key_texts[] = { +"ScrollControl" ,"Mono" ,"Mono + Polarity" ,"Dim" ,"Talkback" ,"Unknown" , +}; + +ID_ENUM_DEF (id14_id_key,2 ,0xffff ,ID14_MON_MONO ,ID14_MON_POLARITY ,ID14_MON_DIM , +ID14_MON_TALKBACK ); +/* Mono mode: one-speaker sum (Left, Right) or phantom centre. */ static const char *const id14_mono_mode_texts[] = {"Left" ,"Centre" ,"Right" ,"Other" };ID_ENUM_DEF (id14_mono_mode,1 ,1 ,0 ,2 ); +/* Talkback source: the routing source of the input; none = 0xff. */ +static const char *const id14_talkback_texts[] = { +"None" ,"Mic 1" ,"Mic 2" ,"Digi 1" ,"Digi 2" ,"Digi 3" ,"Digi 4" ,"Digi 5" ,"Digi 6" , +"Digi 7" ,"Digi 8" ,"Unknown" , +}; + +ID_ENUM_DEF (id14_talkback,1 ,0xff ,4 ,5 ,6 ,7 ,8 ,9 ,10 ,11 ,12 ,13 ); + +static const char *const id14_optical_texts[] = {"ADAT" ,"S/PDIF" ,"Unknown" }; + +ID_ENUM_DEF (id14_optical,4 ,0 ,1 ); +/* * Routing sources for each destination. DAW Thru plays the USB stream * directly and bypasses the volume knob: full scale. Main Mix is 0x14/0x15
@@ -122,6 +161,16 @@ ID_ENUM_TEXTS(id14_route_hl, id14_route_texts, 1, 0x18, 0x10, 0x02);ID_ENUM_TEXTS (id14_route_hr, id14_route_texts,1 ,0x19 ,0x11 ,0x03 );static_assert (ARRAY_SIZE (id14_route_texts) ==ARRAY_SIZE (id14_route_ml_values) +1 ); +/* +* The iD application offers polarity on the Mic and Digi strips, not on +* DAW. The MkI accepts it on Digi 1-2 only: CN 5-10 stall in both optical modes +* (tested without an ADAT signal). +*/ +#define ID14_DIGI_POLARITY (n) \ + { .name = "Digi " #n " Polarity Invert Capture Switch", .kind = ID_BOOL, \ + .unit = ID14_FU_IN, .cs = ID14_IN_POLARITY, .cn = 2 + (n), .channels = 1, \ + .flags = ID_WO, .init = 0 } +static const struct id_ctl id14_mk1_ctls[] = { { .name ="Monitor Speaker Playback Volume" , .kind =ID_VOL , .unit =ID14_MON , .cs =ID14_MON_VOLUME , .channels =1 },
@@ -152,6 +201,26 @@ static const struct id_ctl id14_mk1_ctls[] = { .cs = ID14_ROUTE_SOURCE, .cn = 2, .channels = 1, .e = &id14_route_hl }, { .name = "Headphone R Source Playback Enum", .kind = ID_ENUM, .unit = ID14_ROUTE, .cs = ID14_ROUTE_SOURCE, .cn = 3, .channels = 1, .e = &id14_route_hr }, + /* Write-only: GET stalls. The probe writes the iD application defaults. */ + { .name = "Mic 1 Boost Capture Switch", .kind = ID_BOOST, .unit = ID14_FU_IN, + .cs = ID14_IN_BOOST, .cn = 1, .channels = 1, .flags = ID_WO, .init = 0 }, + { .name = "Mic 2 Boost Capture Switch", .kind = ID_BOOST, .unit = ID14_FU_IN, + .cs = ID14_IN_BOOST, .cn = 2, .channels = 1, .flags = ID_WO, .init = 0 }, + { .name = "Mic 1 Polarity Invert Capture Switch", .kind = ID_BOOL, .unit = ID14_FU_IN, + .cs = ID14_IN_POLARITY, .cn = 1, .channels = 1, .flags = ID_WO, .init = 0 }, + { .name = "Mic 2 Polarity Invert Capture Switch", .kind = ID_BOOL, .unit = ID14_FU_IN, + .cs = ID14_IN_POLARITY, .cn = 2, .channels = 1, .flags = ID_WO, .init = 0 }, +ID14_DIGI_POLARITY (1 ),ID14_DIGI_POLARITY (2 ), + { .name = "iD Key Function Playback Enum", .kind = ID_ENUM, .unit = ID14_MON, + .cs = ID14_MON_ID_KEY, .channels = 1, .flags = ID_WO, .init = 0, .e = &id14_id_key }, + /* Write-only: GET returns 0 whatever was written. */ + { .name = "Talkback Source Capture Enum", .kind = ID_ENUM, .unit = ID14_MON, + .cs = ID14_MON_TALKBACK_SRC, .channels = 1, .flags = ID_WO, .init = 0, + .e = &id14_talkback }, + /* Write-only: GET stalls. The probe writes the power-on mode, S/PDIF. */ + { .name = "Digital In Mode Capture Enum", .kind = ID_ENUM, .unit = ID14_IT_DIGITAL, + .cs = ID14_IT_OPTICAL_MODE, .channels = 1, .flags = ID_WO, .init = 1, + .e = &id14_optical }, { } };
@@ -159,6 +228,8 @@ static const struct id_ctl id14_mk1_ctls[] = {struct id_elem {struct usb_mixer_elem_list list;const struct id_ctl *ctl; +long val[2 ];/* ID_WO: the last value the device accepted */ +u8 valid;/* ID_WO: bit per channel, set when val[] is that value */ };/* 0 = -128 dB (mute), 1 dB per step: ID_VOL_MAX = 0 dB. */
@@ -192,6 +263,7 @@ static int id_len(const struct id_ctl *c)case ID_ENUM :return c->e->len;case ID_VOL : +case ID_BOOST :return 2 ;default :return 1 ;
@@ -203,11 +275,12 @@ static bool id_valid(const struct id_ctl *c, long val)switch (c->kind) {case ID_BOOL :case ID_BOOL_INV : +case ID_BOOST :return val ==0 || val ==1 ;case ID_VOL :return val >=0 && val <=ID_VOL_MAX ;case ID_ENUM : -return val >=0 && val < c->e->items;/* never "Other" */ +return val >=0 && val < c->e->items;/* never "Other" or "Unknown" */ }return false; }
@@ -234,6 +307,9 @@ static int id_read(struct usb_mixer_interface *mixer, const struct id_ctl *c,case ID_BOOL_INV : *val = !buf[0 ];break ; +case ID_BOOST : + *val = raw !=0 ; +break ;case ID_VOL :/* the knob moves in whole dB; round anything else to the nearest step */ *val = clamp_t(long, DIV_ROUND_CLOSEST(raw, ID_DB(1)) + ID_VOL_MAX,
@@ -262,6 +338,9 @@ static int id_write(struct usb_mixer_interface *mixer, const struct id_ctl *c,case ID_BOOL_INV : buf[0 ] = !val;break ; +case ID_BOOST : +put_unaligned_le16 (val ?ID_DB (10 ) :0 , buf); +break ;case ID_VOL :put_unaligned_le16 (ID_DB (val -ID_VOL_MAX ), buf);break ;
@@ -319,9 +398,14 @@ static int id_get(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *v)int err;for (i =0 ; i < c->channels; i++) { - err =id_read (e->list.mixer, c, i, &val); -if (err <0 ) -return err; +if (c->flags &ID_WO ) { +/* No last value (the probe write failed): "Unknown", or off. */ + val = e->valid &BIT (i) ? e->val[i] : c->kind ==ID_ENUM ? c->e->items :0 ; + }else { + err =id_read (e->list.mixer, c, i, &val); +if (err <0 ) +return err; + }id_set_value (c, v, i, val); }return 0 ;
@@ -346,15 +430,25 @@ static int id_put(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *v)for (i =0 ; i < c->channels; i++) { val =id_get_value (c, v, i); - err =id_read (mixer, c, i, &cur); -if (err <0 ) -return err; -if (cur == val) -continue ; - changed =1 ; +if (c->flags &ID_WO ) { +/* Always send: the device may have been reset since the last write. */ +if (!(e->valid &BIT (i)) || e->val[i] != val) + changed =1 ; + }else { + err =id_read (mixer, c, i, &cur); +if (err <0 ) +return err; +if (cur == val) +continue ; + changed =1 ; + } err =id_write (mixer, c, i, val);if (err <0 ) -return err; +return err;/* a write-only channel keeps its last accepted value */ +if (c->flags &ID_WO ) { + e->val[i] = val; + e->valid |=BIT (i); + } }return changed; }
@@ -364,15 +458,19 @@ static int id_add_ctl(struct usb_mixer_interface *mixer, const struct id_ctl *c)struct snd_kcontrol_new knew = { .iface =SNDRV_CTL_ELEM_IFACE_MIXER , .name = c->name, -/* The front panel changes values: user space must not cache them. */ - .access =SNDRV_CTL_ELEM_ACCESS_READWRITE |SNDRV_CTL_ELEM_ACCESS_VOLATILE , + .access =SNDRV_CTL_ELEM_ACCESS_READWRITE , .info = id_info, .get = id_get, .put = id_put, };struct snd_kcontrol *kctl;struct id_elem *e; +unsigned int i; +int err; +/* The front panel changes readable values: user space must not cache them. */ +if (!(c->flags &ID_WO )) + knew.access |=SNDRV_CTL_ELEM_ACCESS_VOLATILE ;if (c->kind ==ID_VOL ) { knew.access |=SNDRV_CTL_ELEM_ACCESS_TLV_READ ; knew.tlv.p = id_vol_tlv;
@@ -385,6 +483,20 @@ static int id_add_ctl(struct usb_mixer_interface *mixer, const struct id_ctl *c) e->list.id = c->unit; e->ctl = c; +/* A write-only control needs a known value. On failure it reads "Unknown" (or off). */ +if (c->flags &ID_WO ) { +for (i =0 ; i < c->channels; i++) { + err =id_write (mixer, c, i, c->init); +if (err <0 ) { +usb_audio_warn (mixer->chip,"iD14: cannot set '%s' (%d)\n" , + c->name, err); +continue ; + } + e->val[i] = c->init; + e->valid |=BIT (i); + } + } + kctl =snd_ctl_new1 (&knew, e);if (!kctl) {kfree (e);
sound/usb/mixer_maps.c +1 -0
@@ -528,6 +528,7 @@ static const struct usbmix_name_map audient_id14_map[] = {/* Audient iD14 MkI: model-specific control map. */ static const struct usbmix_name_map audient_id14_mk1_map[] = { + {11 ,NULL },/* FU, see mixer_audient_id.c */ {12 ,"Monitor Mix Playback" },/* FU, partial coverage */ {60 ,NULL },/* MU, see mixer_audient_id.c */ {}
Signature · 1 line
2.47.3
PATCH 5/5 ALSA: usb-audio: Replace the Audient iD14 MkI FU 12 control
In reply to Will PorterFeature unit 12 sets the level of the mixer outputs: channels 1-2 Main, 3-4 Cue. Two firmware faults make the generic control wrong on the MkI:
- GET CUR does not return the FU 12 value. It returns a reply buffer that the device shares with FU 10, MU 60 and XU 51. The buffer holds the data of the last GET or SET to any of them. So the generic sticky-GET check passes, because GET echoes the SET just sent. The check then writes the stale value that it read first to channel 1.
- Main L ignores its level, but Main R applies it. So any Main value other than 0 dB unbalances the main outputs. audient_id14_map already records this asymmetry. A loopback cable measured it: Main R at -20 dB, -40 dB and mute changes its output by -20.0, -40.9 and -56.6 dB. Main L at the same values changes nothing. Cue L and Cue R both work.
Replace the generic control with one of the same name, count and range. It is "Monitor Mix Playback Volume", with four values from 0 to 127 in 1 dB steps. 127 is 0 dB. Value 0 is mute (0x8000), the floor that Audient's iD application writes, and the TLV says so. The four values keep the Main L/R, Cue L/R layout of existing saved ALSA states, but Main is now held at 0 dB.
The control holds Main at 0 dB, as the iD application does. (The application has no Main fader and writes 0 dB at launch.) A put always sends 0 dB to channels 1-2 and returns that value to the caller. Get reports it too. For Cue the control shows the last value the device accepted. At probe the driver writes the iD application's launch values once per channel: Main 0 dB, Cue muted. A channel whose probe write fails reads as mute until a put succeeds.
The iD14 MkI profile in alsa-ucm-conf writes 127,127,127,127 to this control at boot and when its HiFi verb starts. The new control accepts that write: Main stays at 0 dB and Cue goes to 0 dB, the same result as with the generic control.
Differences from the generic control:
- Value 0 is now mute. It was -127 dB.
- The control holds Main at 0 dB. A Main R attenuation stored with the generic control (for example 107, -20 dB) now restores as 0 dB, which raises Main R by 20 dB. Main L never applied that attenuation, so Main R comes up to the level that Main L already had. FU 12 comes before the monitor controller (XU 54) and the headphone level (FU 10), so the volume knob still sets the listening level.
- Cue starts muted at every probe. An output routed to the Cue Mix keeps that routing across a module reload or a rebind. On mains power it also keeps it across a replug. That output is then silent until alsactl restore runs. On bus power the MkI returns to DAW Thru when it enumerates, so no output is on the Cue Mix at probe.
Test setup:
- iD14 MkI, firmware 1.1.1
- Bazzite 44, kernel 7.2.9-ogc3.1.fc44
- snd-usb-audio built out of tree from the v7.2.9 sound/usb sources and the complete driver (this commit and the later ones)
Results:
- the loopback measurements above
- the Cue master, by ear
- a put of 107,107,90,90 reads back 127,127,90,90
- alsactl restore of the Cue level across a replug
--- sound/usb/mixer_audient_id.c | 147 +++++++++++++++++++++++++++++++++++ sound/usb/mixer_maps.c | 2 +- 2 files changed, 148 insertions(+), 1 deletion(-)
sound/usb/mixer_audient_id.c +147 -0
@@ -45,6 +45,7 @@#define ID14_IT_DIGITAL 0x01/* input terminal: optical and coaxial inputs */ #define ID14_FU_OUT 0x0a/* feature unit before the outputs */ #define ID14_FU_IN 0x0b/* feature unit on the inputs: CN 1-2 Mic, 3-10 Digi */ +#define ID14_FU_MIX 0x0c/* feature unit after the mixer: CN 1-2 Main, 3-4 Cue */ #define ID14_ROUTE 0x33/* routing XU: CN = destination */ #define ID14_MON 0x36/* monitor controller XU */ #define ID14_MIXER 0x3c/* mixer unit: 14 inputs x 4 outputs */
@@ -506,6 +507,149 @@ static int id_add_ctl(struct usb_mixer_interface *mixer, const struct id_ctl *c)return snd_usb_mixer_add_list (&e->list, kctl, false, true); } +/* +* iD14 MkI FU 12, the mixer output level: CN 1-2 Main, 3-4 Cue. GET RANGE works +* (-127 ... 0 dB, 1 dB steps), but GET CUR returns a reply buffer the +* device shares with other units, not the FU 12 value. So the generic +* control (hidden by the name map) shows stale data, and its sticky-GET +* check passes and then writes that stale value to Main L. +* +* The firmware ignores Main L (CN 1) but applies Main R (CN 2), so any Main +* level other than 0 dB unbalances the main outputs (measured with a +* loopback; Cue L and Cue R both work). The iD application has no Main +* fader and writes 0 dB to Main at launch. This control holds Main at 0 dB: +* a put sends 0 dB to CN 1-2 whatever it asks for, and get reports it. +* +* It keeps the generic control's name and format: four values, 0 ... 127 +* in 1 dB steps, 127 = 0 dB. Value 0 is mute (0x8000), the floor the iD +* application writes. It shows the last value the device accepted, and +* every put sends all four channels. +*/ +#define ID14_FU12_CHANNELS 4 +#define ID14_FU12_MAIN_CHANNELS 2/* CN 1-2, held at 0 dB */ +#define ID14_FU12_MAX 127 +#define ID14_FU12_MUTE 0 + +static const DECLARE_TLV_DB_MINMAX_MUTE(id14_fu12_tlv, -12700, 0); + +struct id14_fu12 { +struct usb_mixer_elem_list list;/* first: snd_usb_mixer_elem_free */ +long val[ID14_FU12_CHANNELS ]; +u8 valid;/* bit per channel */ +}; + +static s16 id14_fu12_raw (long val) +{ +return val ==ID14_FU12_MUTE ?ID_DB_MIN :ID_DB (val -ID14_FU12_MAX ); +} + +static int id14_fu12_write (struct id14_fu12 *f,unsigned int ch,long val) +{ +u8 buf[2 ]; +int err; + +put_unaligned_le16 (id14_fu12_raw (val), buf); + err =id_xfer (f->list.mixer, true,ID14_FU_MIX ,UAC_FU_VOLUME , ch +1 , buf,sizeof (buf)); +if (err <0 ) +return err; + f->val[ch] = val; + f->valid |=BIT (ch); +return 0 ; +} + +static int id14_fu12_info (struct snd_kcontrol *kctl,struct snd_ctl_elem_info *uinfo) +{ + uinfo->type =SNDRV_CTL_ELEM_TYPE_INTEGER ; + uinfo->count =ID14_FU12_CHANNELS ; + uinfo->value.integer.min =0 ; + uinfo->value.integer.max =ID14_FU12_MAX ; +return 0 ; +} + +static int id14_fu12_get (struct snd_kcontrol *kctl,struct snd_ctl_elem_value *v) +{ +struct id14_fu12 *f =snd_kcontrol_chip (kctl); +unsigned int ch; + +/* A channel that was never written reads as mute. */ +for (ch =0 ; ch <ID14_FU12_CHANNELS ; ch++) + v->value.integer.value[ch] = f->valid &BIT (ch) ? f->val[ch] :ID14_FU12_MUTE ; +return 0 ; +} + +static int id14_fu12_put (struct snd_kcontrol *kctl,struct snd_ctl_elem_value *v) +{ +struct id14_fu12 *f =snd_kcontrol_chip (kctl); +unsigned int ch; +long val; +int err, changed =0 ; + +for (ch =0 ; ch <ID14_FU12_CHANNELS ; ch++) +if (v->value.integer.value[ch] <0 || v->value.integer.value[ch] >ID14_FU12_MAX ) +return -EINVAL ; + +CLASS (snd_usb_lock, pm)(f->list.mixer->chip); +if (pm.err <0 ) +return pm.err; + +/* Main is held at 0 dB: report that back to the caller. */ +for (ch =0 ; ch <ID14_FU12_MAIN_CHANNELS ; ch++) + v->value.integer.value[ch] =ID14_FU12_MAX ; + +for (ch =0 ; ch <ID14_FU12_CHANNELS ; ch++) { + val = v->value.integer.value[ch]; +if (!(f->valid &BIT (ch)) || f->val[ch] != val) + changed =1 ; + err =id14_fu12_write (f, ch, val); +if (err <0 ) +return err; + } +return changed; +} + +/* +* At probe, write the iD application's launch values: Main at 0 dB (the +* iD application has no Main fader) and Cue muted. +*/ +static int id14_fu12_create (struct usb_mixer_interface *mixer) +{ +struct snd_kcontrol_new knew = { + .iface =SNDRV_CTL_ELEM_IFACE_MIXER , + .name ="Monitor Mix Playback Volume" , + .access =SNDRV_CTL_ELEM_ACCESS_READWRITE |SNDRV_CTL_ELEM_ACCESS_TLV_READ , + .info = id14_fu12_info, + .get = id14_fu12_get, + .put = id14_fu12_put, + .tlv.p = id14_fu12_tlv, + }; +struct snd_kcontrol *kctl; +struct id14_fu12 *f; +unsigned int ch; +int err; + + f =kzalloc_obj (*f); +if (!f) +return -ENOMEM ; + f->list.mixer = mixer; + f->list.id =ID14_FU_MIX ; + +for (ch =0 ; ch <ID14_FU12_CHANNELS ; ch++) { + err =id14_fu12_write (f, ch, ch <ID14_FU12_MAIN_CHANNELS ? +ID14_FU12_MAX :ID14_FU12_MUTE ); +if (err <0 )/* the channel stays unknown and reads as mute */ +usb_audio_warn (mixer->chip,"iD14: cannot set FU 12 channel %u (%d)\n" , + ch +1 , err); + } + + kctl =snd_ctl_new1 (&knew, f); +if (!kctl) { +kfree (f); +return -ENOMEM ; + } + kctl->private_free = snd_usb_mixer_elem_free; +return snd_usb_mixer_add_list (&f->list, kctl, false, true); +} +/* * iD14 MkI mixer crosspoints: CS 1, CN = input * 4 + output, s16 in * 1/256 dB. The control value is the raw s16, -128 dB (mute) ... +6 dB;
@@ -632,6 +776,9 @@ int snd_audient_id14_mk1_controls_create(struct usb_mixer_interface *mixer)if (err <0 )return err; } + err =id14_fu12_create (mixer); +if (err <0 ) +return err;for (in =0 ; in <ARRAY_SIZE (id14_mix_inputs); in++) {for (out =0 ; out <ID14_MIX_OUTPUTS ; out++) { err =id14_mix_add_ctl (mixer, in, out);
sound/usb/mixer_maps.c +1 -1
@@ -529,7 +529,7 @@ static const struct usbmix_name_map audient_id14_map[] = {/* Audient iD14 MkI: model-specific control map. */ static const struct usbmix_name_map audient_id14_mk1_map[] = { {11 ,NULL },/* FU, see mixer_audient_id.c */ - {12 ,"Monitor Mix Playback" },/* FU, partial coverage */ + {12 ,NULL },/* FU, see mixer_audient_id.c */ {60 ,NULL },/* MU, see mixer_audient_id.c */ {} };
Signature · 1 line
2.47.3
Quoted 83 lines · Will Porter
The Audient iD14 MkI (2708:0002) keeps its monitor section, output routing, mixer and input options on vendor extension units. It also uses feature units whose descriptors declare no controls. On Linux a user cannot change the routing. The device powers up with every output on DAW Thru, which bypasses the volume knob.
This series adds those controls in a new
mixer_audient_id.c, one group per patch. A MkI-only name map hides the generic controls that each group replaces. The MkII keepsaudient_id14_map.Scope: only the iD14 MkI is supported, and only its USB ID reaches the new code. Other Audient iD models keep the generic driver. Their units may differ, and this series does not cover them. The file follows
mixer_scarlett2.c, which began with one model and added others through per-model tables. Names withid14_hold the MkI's unit IDs and tables. A later iD model can add its own tables to this file.sound for-next also has
mixer_evo.cfor the Audient EVO 4 (2708:0006). EVO and iD are separate Audient product lines. The iD14 MkI uses other units and a larger control set: a monitor controller, output routing, a 14 x 4 mixer and write-only controls. So this series keeps the iD line in its own file.At probe the driver writes only controls that it cannot read back: the write-only controls (patch 4) and FU 12 (patch 5). They get the launch values of Audient's iD application. If a probe write fails, the control shows the fallback value that those patches describe. The driver does not write the routing or the mix. User space (alsactl, an application) sets the rest of the iD application's launch state.
There is no resume code. Every write to a write-only control reaches the device, so alsactl restore also repairs a device that was reset. The state across a suspend depends on the power source:
- On USB bus power, a system suspend re-enumerates the device.
- With its mains adapter connected, the device keeps its state across a system suspend. This is also true when the host controller resets the device and the card stays. The sampled readable controls did not change.
- A runtime suspend left the readable controls unchanged on both power sources, with no reset logged. A runtime suspend is possible only after usbhid releases the HID interface.Patch 5 replaces the generic "Monitor Mix Playback Volume" (FU 12) with one of the same name, count and range. FU 12 GET CUR returns stale data from other units. Its Main L channel ignores writes, but Main R applies them.
audient_id14_mapalready notes this asymmetry. The new control holds Main at 0 dB. This is a deliberate change for existing users: a Main R attenuation set through the generic control no longer applies.The protocol comes from Audient's iD application (version 4.4.5 for macOS). USB captures of the application confirmed it.
Test setup:
- iD14 MkI, firmware 1.1.1
- Bazzite 44, kernel 7.2.9-ogc3.1.fc44
- snd-usb-audio built out of tree from the v7.2.9sound/usbsources with this series appliedTests:
- listening tests: routing, dim, talkback, Cue
- a loopback cable: gain boost, polarity, FU 12 per channel
- alsactl store and restore across a replug
- an out-of-list routing value
- a runtime suspend
- three system suspends (S3) with control reads running at about 3000 per second: no read failed after a resume
- the optical power-on mode, read on macOS 27.0.1 with no Audient software runningThe series is based on sound for-next
a4ef328ce3b3. Each patch builds on its own there with make W=1sound/usb/. The hardware tests used the complete series on 7.2.9 sources, wheresnd_usb_mixer_add_list()has nolook_for_emptyargument. The series passes true, which keeps that behaviour.Will Porter (5):
ALSA: usb-audio: Give the Audient iD14 MkI its own mixer map
ALSA: usb-audio: Add Audient iD14 MkI monitor and routing controls
ALSA: usb-audio: Add Audient iD14 MkI mixer matrix
ALSA: usb-audio: Add Audient iD14 MkI write-only controls
ALSA: usb-audio: Replace the Audient iD14 MkI FU 12 control
Quoted 8 lines
sound/usb/Makefile | 1 + sound/usb/mixer_audient_id.c | 790 +++++++++++++++++++++++++++++++++++ sound/usb/mixer_audient_id.h | 7 + sound/usb/mixer_maps.c | 10 +- sound/usb/mixer_quirks.c | 4 + 5 files changed, 811 insertions(+), 1 deletion(-) create mode 100644 sound/usb/mixer_audient_id.c create mode 100644 sound/usb/mixer_audient_id.h
FYI, I postpone this to 7.5, as 7.4 merge window was already opened and this PR has too big changes as a last-minute fix.
thanks,
Takashi
Hi Will,
Quoted 9 lines · Will Porter
[...]
sound for-next also has
mixer_evo.cfor the Audient EVO 4 (2708:0006). EVO and iD are separate Audient product lines. The iD14 MkI uses other units and a larger control set: a monitor controller, output routing, a 14 x 4 mixer and write-only controls. So this series keeps the iD line in its own file.[...]
I took a look at this question and it seems like we can share the majority of code in the EVO driver by complementing it with the following features:
- variable width read/write
- caching of write-only values
- enum data type
Most of these changes should be trivial as the EVO driver controls are also structured in tabular form and the driver was intended from the start to be extensible to the evo8 and possibly other hardware. See below diff for an example of how to support the first point (just to illustrate these changes are minor, others should be of similar extent, not properly tested so use with caution).
Adding those features should allow to simply add a new table (allocated at probe time for WO caching) with entries for most id14 controls. The only part which seems more problematic is probably FU12 which looks like it requires some custom logic and would still need actual code.
Happy to support a common driver activity and rename everything to audient if you think this makes sense in order to reduce code size but no problem if you think this is too complex to manage, up to you.
Christian
sound/usb/mixer_evo.c +44 -22
@@ -31,9 +31,13 @@ enum snd_evo_type {SND_EVO_TYPE_NCTYPES }; +#define SND_EVO_CTRL_FLAGS_SIGNED (1L<<0) +#define SND_EVO_CTRL_FLAGS_INVERT (1L<<1) + static const struct snd_evo_ctrl_type { snd_ctl_elem_type_t type; - bool invert; + unsigned long width; + unsigned long flags; union { int integer; } min;
@@ -45,6 +49,7 @@ static const struct snd_evo_ctrl_type { } snd_evo_ctypes[SND_EVO_TYPE_NCTYPES] = { [SND_EVO_TYPE_MONITOR] = { .type = SNDRV_CTL_ELEM_TYPE_INTEGER, + .width = 2, .min.integer = 0, .max.integer = 127, .wValue = 0x0000,
@@ -52,7 +57,7 @@ static const struct snd_evo_ctrl_type { }, [SND_EVO_TYPE_PHANTOM] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, - .invert = false, + .width = 4, .min.integer = 0, .max.integer = 1, .wValue = 0x0000,
@@ -60,7 +65,8 @@ static const struct snd_evo_ctrl_type { }, [SND_EVO_TYPE_MUTE] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, - .invert = true, + .width = 4, + .flags = SND_EVO_CTRL_FLAGS_INVERT, .min.integer = 0, .max.integer = 1, .wValue = 0x0200,
@@ -68,7 +74,8 @@ static const struct snd_evo_ctrl_type { }, [SND_EVO_TYPE_MUTE_OUT] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, - .invert = true, + .width = 4, + .flags = SND_EVO_CTRL_FLAGS_INVERT, .min.integer = 0, .max.integer = 1, .wValue = 0x0100,
@@ -76,6 +83,8 @@ static const struct snd_evo_ctrl_type { }, [SND_EVO_TYPE_MIXER] = { .type = SNDRV_CTL_ELEM_TYPE_INTEGER, + .width = 2, + .flags = SND_EVO_CTRL_FLAGS_SIGNED, .min.integer = -128 * 256, .max.integer = 6 * 256, .wValue = 0x0100,
@@ -280,24 +289,24 @@ static int snd_ctl_evo_boolean_get(struct snd_kcontrol *kctl,int i;for (i =0 ; i < hwchan; i++) { -u32 buf; +u32 buf =0 ;int ret; ret =snd_evo_get_cur (mixer, value + i, index, - &buf,sizeof (buf)); + &buf, ctype->width);if (ret <0 )return ret; ctl_val->value.integer.value[i] =le32_to_cpu (buf) ?1 :0 ; -if (ctype->invert) +if (ctype->flags &SND_EVO_CTRL_FLAGS_INVERT ) ctl_val->value.integer.value[i] ^=0x1 ; }for (; i < nchan; i++) - ctl_val->value.integer.value[i] = ctype->invert - ? ctype->max.integer - : ctype->min.integer; + ctl_val->value.integer.value[i] + = (ctype->flags &SND_EVO_CTRL_FLAGS_INVERT ) + ? ctype->max.integer : ctype->min.integer;return 0 ; }
@@ -317,15 +326,15 @@ static int snd_ctl_evo_boolean_set(struct snd_kcontrol *kctl,int i;for (i =0 ; i < hwchan; i++) { -u32 rbuf; +u32 rbuf =0 ;u32 buf =cpu_to_le32 (ctl_val->value.integer.value[i] ?1 :0 );int ret; -if (ctype->invert) +if (ctype->flags &SND_EVO_CTRL_FLAGS_INVERT ) buf ^=0x1 ; ret =snd_evo_get_cur (mixer, value + i, index, - &rbuf,sizeof (rbuf)); + &rbuf, ctype->width);if (ret <0 )return ret;
@@ -333,7 +342,7 @@ static int snd_ctl_evo_boolean_set(struct snd_kcontrol *kctl, changed =1 ; ret =snd_evo_set_cur (mixer, value + i, index, - &buf,sizeof (buf)); + &buf, ctype->width);if (ret <0 )return ret; }
@@ -342,6 +351,19 @@ static int snd_ctl_evo_boolean_set(struct snd_kcontrol *kctl,return changed; } +static inline long buf2cpu (const struct snd_evo_ctrl_type *const ctype,u32 in) +{ +const u32 u =le32_to_cpu (in); + +if (ctype->flags &SND_EVO_CTRL_FLAGS_SIGNED ) { +const int sh =32 - ctype->width *8 ; +const s32 s = u << sh; + +return s >> sh; + }else +return u; +} +static int snd_ctl_evo_integer_get (struct snd_kcontrol *kctl,struct snd_ctl_elem_value *ctl_val) {
@@ -357,16 +379,16 @@ static int snd_ctl_evo_integer_get(struct snd_kcontrol *kctl,int i;for (i =0 ; i < hwchan; i++) { -u16 buf; -s16 val; +u32 buf =0 ; +s32 val;int ret; ret =snd_evo_get_cur (mixer, value + i, index, - &buf,sizeof (buf)); + &buf, ctype->width);if (ret <0 )return ret; - val =le16_to_cpu (buf); + val =buf2cpu (ctype, buf); ctl_val->value.integer.value[i] = val; }
@@ -391,16 +413,16 @@ static int snd_ctl_evo_integer_set(struct snd_kcontrol *kctl,int i;for (i =0 ; i < hwchan; i++) { -s16 rbuf; -s16 buf =cpu_to_le16 (ctl_val->value.integer.value[i]); +s32 rbuf =0 ; +s32 buf =cpu_to_le32 (ctl_val->value.integer.value[i]);int ret; ret =snd_evo_get_cur (mixer, value + i, index, - &rbuf,sizeof (rbuf)); + &rbuf, ctype->width);if (ret <0 )return ret; -if (rbuf != buf) { +if (buf2cpu (ctype, rbuf) != ctl_val->value.integer.value[i]) { changed =1 ; ret = snd_evo_set_cur(mixer, value + i, index,
Hi Christian,
Quoted 5 lines · Christian Ruppert
I took a look at this question and it seems like we can share the majority of code in the EVO driver by complementing it with the following features:
- variable width read/write
- caching of write-only values
- enum data type
Thanks for looking into this so closely, and for the fixes. I like the idea of one driver, and I'd like to find out whether the iD line fits.
Your TLV in patch 4/4 is the same one I use for the iD14 matrix: same unit 0x3C, s16 in 1/256 dB, -128 to +6 dB. That made me wonder whether the iD14 matrix could use your MIXER type almost as it is. Its channel number is input * 4 + output, so Main L/R and Cue L/R of each input are adjacent, like your stereo pairs. Could we expose it as 28 controls with two values each, rather than my 56 single-value ones? An input's level and pan in a mix set its L and R values together, so a pair seems a natural fit. Does that look right to you?
Quoted 2 lines
The only part which seems more problematic is probably FU12 which looks like it requires some custom logic and would still need actual code.
Agreed. I'd keep FU 12 as its own code.
A few questions about the rest:
1. Read before write. As I understand it, the put handlers in mixer_evo.c read the value first to see if it changed. On the iD14, GET stalls for mic boost, input polarity, optical mode and the iD key function, so a put that reads first would fail there. Talkback source always reads 0, so a read would hide real changes. Could these write-only controls skip GET in both get and put, with get returning the cached value? And could every put still send the value, even when it matches the cache, so that "alsactl restore" reaches a device that was reset?
2. The cache. My driver writes a known value at probe (off or none, and for optical mode its measured power-on mode, S/PDIF) and updates the cache only after a full-length write. If the probe write fails, an enum reads "Unknown" and a switch reads off. Would that approach work for you?
3. Control entries. The iD14 table uses 16 unit/selector pairs and explicit control names, such as "Main Out L Source Playback Enum". It also needs volumes in 1 dB steps (0..128, stored as s16 1/256 dB), a boost switch that writes 0x0a00 for on, and enums that map items to device values, plus an "Other" item that only get reports, for values outside the list. Would it make sense to move the unit, selector and an optional full name into each control entry, and add the new value formats (1 dB volumes, boost, enum) as ctypes? Or would you structure it differently?
4. Checks. My helper returns -EIO on a short read or write, before it decodes a value or updates the cache. My matrix put also rejects values outside -128..+6 dB, and get clamps what it reads back. Could the shared code keep these checks?
I don't have a firm view yet on which way is better. If the iD14 fits the table without many special cases, one driver seems clearly worth it. If it needs a lot of per-device branches, two smaller files might be easier to read and review. What do you think, now that you have seen what the iD14 needs?
If we do combine them, the order I imagined is: your four fixes first, then the rename to Audient, then the generic changes, then the iD14 tables on top as v2 of my series.
In that case, would you prefer to do the rename and the generic part yourself? The rename would also touch MAINTAINERS; how would you like to handle review of the iD14 parts? I can write the iD14 parts and test them on my MkI. I don't have an EVO 4, so would you be able to test that side? And which base should I work against, sound for-next once your fixes are in? I'm also not sure how a combined change should reach Takashi: as one series, or as two with a stated dependency.
Thanks,
Will
Quoted 70 lines · Will Porter
Hi Christian,
Quoted 5 lines · Christian Ruppert
I took a look at this question and it seems like we can share the majority of code in the EVO driver by complementing it with the following features:
- variable width read/write
- caching of write-only values
- enum data typeThanks for looking into this so closely, and for the fixes. I like the idea of one driver, and I'd like to find out whether the iD line fits.
Your TLV in patch 4/4 is the same one I use for the iD14 matrix: same unit
0x3C, s16 in 1/256 dB, -128 to +6 dB. That made me wonder whether the iD14 matrix could use your MIXER type almost as it is. Its channel number is input * 4 + output, so Main L/R and Cue L/R of each input are adjacent, like your stereo pairs. Could we expose it as 28 controls with two values each, rather than my 56 single-value ones? An input's level and pan in a mix set its L and R values together, so a pair seems a natural fit. Does that look right to you?Quoted 2 lines
The only part which seems more problematic is probably FU12 which looks like it requires some custom logic and would still need actual code.
Agreed. I'd keep FU 12 as its own code.
A few questions about the rest:
1. Read before write. As I understand it, the put handlers in
mixer_evo.cread the value first to see if it changed. On the iD14, GET stalls for mic boost, input polarity, optical mode and the iD key function, so a put that reads first would fail there. Talkback source always reads 0, so a read would hide real changes. Could these write-only controls skip GET in both get and put, with get returning the cached value? And could every put still send the value, even when it matches the cache, so that "alsactl restore" reaches a device that was reset?2. The cache. My driver writes a known value at probe (off or none, and for optical mode its measured power-on mode, S/PDIF) and updates the cache only after a full-length write. If the probe write fails, an enum reads "Unknown" and a switch reads off. Would that approach work for you?
3. Control entries. The iD14 table uses 16 unit/selector pairs and explicit control names, such as "Main Out L Source Playback Enum". It also needs volumes in 1 dB steps (0..128, stored as s16 1/256 dB), a boost switch that writes
0x0a00for on, and enums that map items to device values, plus an "Other" item that only get reports, for values outside the list. Would it make sense to move the unit, selector and an optional full name into each control entry, and add the new value formats (1 dB volumes, boost, enum) as ctypes? Or would you structure it differently?4. Checks. My helper returns
-EIOon a short read or write, before it decodes a value or updates the cache. My matrix put also rejects values outside -128..+6 dB, and get clamps what it reads back. Could the shared code keep these checks?I don't have a firm view yet on which way is better. If the iD14 fits the table without many special cases, one driver seems clearly worth it. If it needs a lot of per-device branches, two smaller files might be easier to read and review. What do you think, now that you have seen what the iD14 needs?
If we do combine them, the order I imagined is: your four fixes first, then the rename to Audient, then the generic changes, then the iD14 tables on top as v2 of my series.
Quoted 8 lines
In that case, would you prefer to do the rename and the generic part yourself? The rename would also touch
MAINTAINERS; how would you like to handle review of the iD14 parts? I can write the iD14 parts and test them on my MkI. I don't have an EVO 4, so would you be able to test that side? And which base should I work against, sound for-next once your fixes are in? I'm also not sure how a combined change should reach Takashi: as one series, or as two with a stated dependency.
Well, it's all up to you guys :)
Just arrange between Christian and you, then resubmit, either v2 or additional patches. I'll be traveling from tomorrow and can't react for a few days, in anyway.
thanks,
Takashi
Hi Will,
Quoted 7 lines · Will Porter
Quoted 5 lines · Christian Ruppert
I took a look at this question and it seems like we can share the majority of code in the EVO driver by complementing it with the following features:
- variable width read/write
- caching of write-only values
- enum data type
Quoted 6 lines
Thanks for looking into this so closely, and for the fixes. I like the idea of one driver, and I'd like to find out whether the iD line fits.
Your TLV in patch 4/4 is the same one I use for the iD14 matrix: same unit
0x3C, s16 in 1/256 dB, -128 to +6 dB. That made me wonder whether the iD14 matrix could use your MIXER type almost as it is.
Agreed. If my understanding is correct, this type could be reused without any modifications. The others would have to be newly defined due to different unit IDs/control selectors. BTW: the mixer matrix seems to be identical also for the EVO8 so chances are it's the same for most audient devices and we could simply use a width and height parameter to generate it in a loop.
Quoted 6 lines
Its channel
number is input * 4 + output, so Main L/R and Cue L/R of each input are adjacent, like your stereo pairs. Could we expose it as 28 controls with two values each, rather than my 56 single-value ones? An input's level and pan in a mix set its L and R values together, so a pair seems a natural fit. Does that look right to you?
This is exactly what the stereo pairs do for the EVO. For example, mic 1 shows up as one stereo pair which can be either recorded on both channels (paned between L and R) or exclusively on the left one if it's connected to a stereo mic. Same for mic 2 (which can be used as the right channel of a stereo mic or an independently paned mic). The same principle applies for the L and R outputs of the monitor and USB main out where it seems a bit more quirky but is coherent with the Mics. That said, the existing table system would also allow for individual channels or grouping them in "mini-matrices of four" but neither seemed right when looking at them in alsamixer and so I stuck with one stereo mixer for each (mono) input channel, similar to most mixing consoles.
Quoted 7 lines
Quoted 2 lines
The only part which seems more problematic is probably FU12 which looks like it requires some custom logic and would still need actual code.
Agreed. I'd keep FU 12 as its own code.
A few questions about the rest:
Quoted 9 lines
1. Read before write. As I understand it, the put handlers in
mixer_evo.cread the value first to see if it changed. On the iD14, GET stalls for mic boost, input polarity, optical mode and the iD key function, so a put that reads first would fail there. Talkback source always reads 0, so a read would hide real changes. Could these write-only controls skip GET in both get and put, with get returning the cached value? And could every put still send the value, even when it matches the cache, so that "alsactl restore" reaches a device that was reset?
My view of the WO implementation would be to add three flags: cache, init and force_write:
- If cache is set, the values will be cached and the channel not marked as volatile. No need to read back actual values from USB before a write in this case. This could also be used in the EVO for the mixer matrix which doesn't have physical controls that can change values while the driver doesn't look. Didn't implement it to not complicate the driver with unnecessary caching but if we need caching anyway we should use it.
- If init is set, the driver will initialize the control at probe. The EVO mixer matrix' initial read returns a wrong value so initialization would be great. Also not implemented today because there's no need to complicate the driver for a control which must be fiddled with anyway before it is useful but if we have the feature we should use it.
- If force_write is set, the driver will always write the value, no matter if a cached (or previously read) value is identical. IMHO this is mainly required for broken or quirky controls but I'm a bit undecided if it would really hurt to simply make this behaviour the default for everything.
Quoted 5 lines
2. The cache. My driver writes a known value at probe (off or none, and for optical mode its measured power-on mode, S/PDIF) and updates the cache only after a full-length write. If the probe write fails, an enum reads "Unknown" and a switch reads off. Would that approach work for you?
This is very much in line with what I was thinking, see above.
Quoted 9 lines
3. Control entries. The iD14 table uses 16 unit/selector pairs and explicit control names, such as "Main Out L Source Playback Enum". It also needs volumes in 1 dB steps (0..128, stored as s16 1/256 dB), a boost switch that writes
0x0a00for on, and enums that map items to device values, plus an "Other" item that only get reports, for values outside the list. Would it make sense to move the unit, selector and an optional full name into each control entry, and add the new value formats (1 dB volumes, boost, enum) as ctypes? Or would you structure it differently?
This is several questions in one, let me try not to forget an answer ;)
- The intent of the control types was to associate unit/selector pairs with data types. I would add a new ctype for each unit/selector pair but am open to move unit/selector to the controls and only leave the data type definition in ctype (which will then become rather a dtype) if it significantly reduces repetition. I'm afraid it might just shift repetition to the controls table, though. Btw: I like the unit/selector macros, will introduce this also for the EVO.
- I don't have a preference between explicit control names and the basename/suffix system the EVO driver currently uses. If you prefer we can simply replace the basename with a full name and remove the flags field in the controls.
- The boost switch writing 0x0 for 0dB gain and 0x0a00 for 10dB gain looks suspiciously like a volume control between 0dB and 10dB * 256steps/dB. Does this control only accept these two values or can we simply implement it as a standard volume type controlling a mic pre-amp? If it's only 0xa00 or 0x0 I would suggest to slightly redefine the boolean type to use the max value for true and the min value for false which would also be an elegant way to remove the inversion flag.
- We definitely need a new snd_evo_type entry and get/set functions for enums, up to you to define those in the most suitable manner for the id14.
Quoted 4 lines
4. Checks. My helper returns
-EIOon a short read or write, before it decodes a value or updates the cache. My matrix put also rejects values outside -128..+6 dB, and get clamps what it reads back. Could the shared code keep these checks?
Sure, error management is always good to have. I never encountered any short reads/writes or out of range reads with the EVO so I didn't add any logic for this until now. Also, for the controls I checked, the EVO cleanly rejects out-of-range writes but if the id14 doesn't we should add those checks as well.
Quoted 5 lines
I don't have a firm view yet on which way is better. If the iD14 fits the table without many special cases, one driver seems clearly worth it. If it needs a lot of per-device branches, two smaller files might be easier to read and review. What do you think, now that you have seen what the iD14 needs?
I think we can put everything except for FU12 into the tables and the EVO driver would even benefit from the added features (see above).
Quoted 3 lines
If we do combine them, the order I imagined is: your four fixes first, then the rename to Audient, then the generic changes, then the iD14 tables on top as v2 of my series.
Agreed. Renaming the file first might turn out to be annoying because it's the one thing which might create rebase conflicts we'll have to deal with while we work on this but it's probably preferable to keep as much of the commit history as possible after the rename.
Quoted 2 lines
In that case, would you prefer to do the rename and the generic part yourself?
I suppose we can cut one testing loop if I do the part of the generic part that touches the EVO myself so I can do that, no problem.
Quoted 2 lines
The rename would also touch
MAINTAINERS; how would you like to handle review of the iD14 parts?
I would definitely prefer to list both of us as maintainers. Practically all code will be shared and I can't speak for the id14 in any way.
Quoted 4 lines
I can write the iD14 parts and
test them on my MkI. I don't have an EVO 4, so would you be able to test that side? And which base should I work against, sound for-next once your fixes are in?
It shouldn't make a huge difference because we're rather independent on this file. I'll probably prepare everything on 7.3 and then rebase it onto sound/master to test it there and submit (that's what I did until now, but for-next is also fine). I suggest I submit an RFC with the generic part that you can apply locally to work against (and potentially adjust) before you submit everything in a final series which, if everything goes well, I only need to retest and tag.
Quoted 3 lines
I'm also not sure how a combined change
should reach Takashi: as one series, or as two with a stated dependency.
Hi Christian,
Quoted 3 lines · Christian Ruppert
BTW: the mixer matrix seems to be identical also for the EVO8 so chances are it's the same for most audient devices and we could simply use a width and height parameter to generate it in a loop.
That sounds good to me. On the iD14 it would be 14 inputs by 4 outputs.
Quoted 2 lines
My view of the WO implementation would be to add three flags: cache, init and
force_write:
These look right to me. As per-control flags, you could set init on the EVO matrix, and for the iD14 entries, could we set it only on the write-only controls? The matrix, routing and readable monitor controls keep their values across a replug on mains power, so I'd leave those untouched at probe. Would each entry also carry its init value? On the iD14 most start at off or the first item, but optical mode starts at S/PDIF.
I'd keep force_write on the cached write-only controls, as a precaution against a reset that leaves the card registered. I haven't seen that on the iD14: the resets I've seen re-enumerate it and run probe again. For the readable controls, skipping an unchanged write seems fine to me.
Quoted 7 lines
- The intent of the control types was to associate unit/selector pairs with data types. I would add a new ctype for each unit/selector pair [...]
- I don't have a preference between explicit control names and the basename/suffix system the EVO driver currently uses. If you prefer we can simply replace the basename with a full name and remove the flags field in the controls.
Yes, full names would make the iD14 table easier to check. And one ctype per unit/selector pair is fine with me.
Quoted 5 lines
- The boost switch writing
0x0for 0dB gain and0x0a00for 10dB gain looks suspiciously like a volume control between 0dB and 10dB * 256steps/dB. Does this control only accept these two values or can we simply implement it as a standard volume type controlling a mic pre-amp?
Your guess was correct! The device answers no RANGE request for it, so I tried intermediate values with a loopback cable: 0x0100, 0x0280 and 0x0500 gave +1, +2.5 and +5 dB on both mic inputs, each tested successfully within 0.01 dB of nominal. I didn't test outside 0..+10 dB though.
Even so, I'd like to keep it as a switch in this series, because the iD14's documentation describes a fixed +10 dB boost. Your max-for-true, min-for-false boolean would fit that, with 0 and 0x0a00. A 0..10 dB volume could follow as its own patch if people want it later. Does that sound reasonable?
Quoted 3 lines
- We definitely need a new
snd_evo_typeentry and get/set functions for enums, up to you to define those in the most suitable manner for the id14.
OK, I'll write the enum type with the iD14 tables.
Quoted 3 lines
Sure, error management is always good to have. [...] Also, for the controls I checked, the EVO cleanly rejects out-of-range writes but if the id14 doesn't we should add those checks as well.
I haven't tested whether the iD14 rejects them. Could the generic put handlers reject values outside each control's writable ALSA range with -EINVAL, before converting them to device values? That would cover both devices.
Quoted 1 line
I would definitely prefer to list both of us as maintainers.
Okay, let's do that.
Quoted 4 lines
I suggest I submit an RFC with the generic part that you can apply locally to work against (and potentially adjust) before you submit everything in a final series which, if everything goes well, I only need to retest and tag.
That works for me. I'll carry your rename and generic patches in the final series, with your authorship and Signed-off-by kept and mine added, followed by the iD14 patches. Are your four fixes still going in separately first? And could you include the base commit in the RFC?
Thanks,
Will
Hi Will,
As discussed here an RFC to prepare iD14 support. It goes on top of the previous patch set (minor fixes and tlv addition) which I hope can still make it into 7.4.
The driver was restructured as agreed, with one (short) patch per item to make the changes as understandable as possible. Up to you to squash them into fewer ones before submitting everything in order to keep the final patch series short.
The patches were generated for sound/master commit 603a4df9e6ae60a26adb335f and tested with linux-7.3.1. In both cases, the "minor fixes and tlv addition" patch series was applied first. Note that I could not fully test everything using the EVO4 hardware, some of the newly possible configurations are only usable with the iD14.
See below for a few more comments about the technical details.
Christian
Quoted 7 lines · Will Porter
Quoted 3 lines · Christian Ruppert
BTW: the mixer matrix seems to be identical also for the EVO8 so chances are it's the same for most audient devices and we could simply use a width and height parameter to generate it in a loop.
That sounds good to me. On the iD14 it would be 14 inputs by 4 outputs.
OK, defined as a list of names, see patch 11.
Quoted 10 lines
Quoted 2 lines
My view of the WO implementation would be to add three flags: cache, init and
force_write:These look right to me. As per-control flags, you could set init on the EVO matrix, and for the iD14 entries, could we set it only on the write-only controls? The matrix, routing and readable monitor controls keep their values across a replug on mains power, so I'd leave those untouched at probe. Would each entry also carry its init value? On the iD14 most start at off or the first item, but optical mode starts at S/PDIF.
Actually, the matrix settings also seem to survive a reboot on the EVO (as long as the device remains powered) so finally I decided not to initialize at enumeration either to make the behaviour consistent with the iD14.
Init values are defined in the control type and apply to both the hardware (if the INIT_HW flag is set) and the cache (e.g. if the FORCE_SET flag is set without INIT_HW).
Quoted 4 lines
I'd keep
force_writeon the cached write-only controls, as a precaution against a reset that leaves the card registered. I haven't seen that on the iD14: the resets I've seen re-enumerate it and run probe again. For the readable controls, skipping an unchanged write seems fine to me.
OK, the flags should be rather orthogonal. I couldn't test all combinations with the EVO, though, so don't hesitate to fix potential issues you might discover.
Quoted 10 lines
Quoted 7 lines
- The intent of the control types was to associate unit/selector pairs with data types. I would add a new ctype for each unit/selector pair [...]
- I don't have a preference between explicit control names and the basename/suffix system the EVO driver currently uses. If you prefer we can simply replace the basename with a full name and remove the flags field in the controls.Yes, full names would make the iD14 table easier to check. And one ctype per unit/selector pair is fine with me.
ok, see patch 2 for the names and patch 3 to make the unit/selector pairs more explicit.
Quoted 12 lines
Quoted 5 lines
- The boost switch writing
0x0for 0dB gain and0x0a00for 10dB gain looks suspiciously like a volume control between 0dB and 10dB * 256steps/dB. Does this control only accept these two values or can we simply implement it as a standard volume type controlling a mic pre-amp?Your guess was correct! The device answers no RANGE request for it, so I tried intermediate values with a loopback cable:
0x0100,0x0280and0x0500gave +1, +2.5 and +5 dB on both mic inputs, each tested successfully within 0.01 dB of nominal. I didn't test outside 0..+10 dB though.
Quoted 5 lines
Even so, I'd like to keep it as a switch in this series, because the iD14's documentation describes a fixed +10 dB boost. Your max-for-true, min-for-false boolean would fit that, with 0 and
0x0a00. A 0..10 dB volume could follow as its own patch if people want it later. Does that sound reasonable?
OK, with the current implementation both should be possible with a simple table change.
Quoted 5 lines
[...]
I haven't tested whether the iD14 rejects them. Could the generic put handlers reject values outside each control's writable ALSA range with-EINVAL, before converting them to device values? That would cover both devices.
OK, see patch 7.
Quoted 1 line
[...]
Christian Ruppert (11):
ALSA: rename mixer_evo to mixer_audient
ALSA: mixer_audient: explicitly define full control names
ALSA: mixer_audient: clarify USB control message definition
ALSA: mixer_audient: Add length check to USB transfer
ALSA: mixer_audient: make USB control transfer size configurable
ALSA: mixer_audient: Allow arbitrary boolean control values
ALSA: mixer_audient: Add integer range checks
ALSA: mixer_audient: Add control initialization at probe
ALSA: mixer_audient: Add readback-free parameter set
ALSA: mixer_audient: add control value caching
ALSA: mixer_audient: Create matrix programmatically
MAINTAINERS | 7 +- sound/usb/Makefile | 2 +- sound/usb/mixer_audient.c | 633 ++++++++++++++++++++++++++++++++++++++ sound/usb/mixer_audient.h | 12 + sound/usb/mixer_evo.c | 526 ------------------------------- sound/usb/mixer_evo.h | 12 - sound/usb/mixer_quirks.c | 4 +- 7 files changed, 652 insertions(+), 544 deletions(-) create mode 100644 sound/usb/mixer_audient.c create mode 100644 sound/usb/mixer_audient.h delete mode 100644 sound/usb/mixer_evo.c delete mode 100644 sound/usb/mixer_evo.h
Signature · 1 line
2.56.0
RFC PATCH 3/11 ALSA: mixer_audient: clarify USB control message definition
Previously, base values for wIndex and wValue were directly given in the control type. Construct them from a unit ID and selector for clarity.
--- sound/usb/mixer_audient.c | 76 +++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 35 deletions(-)
sound/usb/mixer_audient.c +41 -35
@@ -45,15 +45,15 @@ static const struct snd_audient_ctrl_type {int integer; } max;const unsigned int *tlv; -u16 wValue; -u16 wIndex; +u8 unit; +u8 sel; } snd_audient_ctypes[SND_AUDIENT_TYPE_NCTYPES] = { [SND_AUDIENT_TYPE_MONITOR] = { .type = SNDRV_CTL_ELEM_TYPE_INTEGER, .min.integer = 0, .max.integer = 127, - .wValue = 0x0000, - .wIndex = 0x3800, + .unit = 0x38, + .sel = 0x00, /* no TLV here because we can't describe the cross-fader */ }, [SND_AUDIENT_TYPE_PHANTOM] = {
@@ -61,31 +61,31 @@ static const struct snd_audient_ctrl_type { .invert = false, .min.integer = 0, .max.integer = 1, - .wValue = 0x0000, - .wIndex = 0x3A00, + .unit = 0x3A, + .sel = 0x00, }, [SND_AUDIENT_TYPE_MUTE] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, .invert = true, .min.integer = 0, .max.integer = 1, - .wValue = 0x0200, - .wIndex = 0x3A00, + .unit = 0x3A, + .sel = 0x02, }, [SND_AUDIENT_TYPE_MUTE_OUT] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, .invert = true, .min.integer = 0, .max.integer = 1, - .wValue = 0x0100, - .wIndex = 0x3B00, + .unit = 0x3B, + .sel = 0x01, }, [SND_AUDIENT_TYPE_MIXER] = { .type = SNDRV_CTL_ELEM_TYPE_INTEGER, .min.integer = -128 * 256, .max.integer = 6 * 256, - .wValue = 0x0100, - .wIndex = 0x3C00, + .unit = 0x3C, + .sel = 0x01, .tlv = snd_audient_tlv_mixer, }, };
@@ -209,7 +209,7 @@ const struct snd_audient_ctrl_type *snd_audient_kctl_type(struct snd_kcontrolreturn &snd_audient_ctypes[kctl->private_value &0xFF ]; } -static __always_inline u16 snd_audient_kctl_valoffs(struct snd_kcontrol *kctl) +static __always_inline u16 snd_audient_kctl_cidxoffs(struct snd_kcontrol *kctl) {return (kctl->private_value >>8 ) &0xFF ; }
@@ -233,11 +233,16 @@ static inline u16 snd_audient_kctl_channels(struct snd_kcontrol *kctl)#define AUDIENT_REQTYPE_GET (USB_DIR_IN | USB_TYPE_CLASS \ | USB_RECIP_INTERFACE) +#define U8_U8 (HI ,LO ) ((((u16)(HI)) << 8) | ((LO) & 0xFF)) +static inline int snd_audient_get_cur (struct usb_mixer_interface *mixer, -u16 value,u16 index, -void *buf,size_t len) +const u8 unit,const u8 sel, +const u8 cidx, +void *const buf,const size_t len) {struct usb_device *const dev = mixer->chip->dev; +const u16 value =U8_U8 (sel, cidx); +const u16 index =U8_U8 (unit, mixer->hostif->desc.bInterfaceNumber); return snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_CUR, AUDIENT_REQTYPE_GET,
@@ -245,10 +250,13 @@ static inline int snd_audient_get_cur(struct usb_mixer_interface *mixer, }static inline int snd_audient_set_cur (struct usb_mixer_interface *mixer, -u16 value,u16 index, -void *buf,size_t len) +const u8 unit,const u8 sel, +const u8 cidx, +void *const buf,const size_t len) {struct usb_device *const dev = mixer->chip->dev; +const u16 value =U8_U8 (sel, cidx); +const u16 index =U8_U8 (unit, mixer->hostif->desc.bInterfaceNumber); return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC2_CS_CUR, AUDIENT_REQTYPE_SET,
@@ -266,8 +274,7 @@ static int snd_ctl_audient_boolean_get(struct snd_kcontrol *kctl,const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl);const struct snd_audient_ctrl_type *const ctype =snd_audient_kctl_type (kctl); -const u16 value = ctype->wValue +snd_audient_kctl_valoffs (kctl); -const u16 index = ctype->wIndex; +const u8 base =snd_audient_kctl_cidxoffs (kctl);int i;
@@ -279,8 +286,8 @@ static int snd_ctl_audient_boolean_get(struct snd_kcontrol *kctl,u32 buf;int ret; - ret =snd_audient_get_cur (mixer, value + i, index, - &buf,sizeof (buf)); + ret =snd_audient_get_cur (mixer, ctype->unit, ctype->sel, + base + i, &buf,sizeof (buf));if (ret <0 )return ret;
@@ -307,8 +314,7 @@ static int snd_ctl_audient_boolean_set(struct snd_kcontrol *kctl,const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl);const struct snd_audient_ctrl_type *const ctype =snd_audient_kctl_type (kctl); -const u16 value = ctype->wValue +snd_audient_kctl_valoffs (kctl); -const u16 index = ctype->wIndex; +const u8 base =snd_audient_kctl_cidxoffs (kctl);int changed =0 ;int i;
@@ -325,15 +331,16 @@ static int snd_ctl_audient_boolean_set(struct snd_kcontrol *kctl,if (ctype->invert) buf ^=cpu_to_le32 (0x1 ); - ret =snd_audient_get_cur (mixer, value + i, index, - &rbuf,sizeof (rbuf)); + ret =snd_audient_get_cur (mixer, ctype->unit, ctype->sel, + base + i, &rbuf,sizeof (rbuf));if (ret <0 )return ret;if (rbuf != buf) { changed =1 ; - ret =snd_audient_set_cur (mixer, value + i, index, + ret =snd_audient_set_cur (mixer, ctype->unit, + ctype->sel, base + i, &buf,sizeof (buf));if (ret <0 )return ret;
@@ -353,8 +360,7 @@ static int snd_ctl_audient_integer_get(struct snd_kcontrol *kctl,const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl);const struct snd_audient_ctrl_type *const ctype =snd_audient_kctl_type (kctl); -const u16 value = ctype->wValue +snd_audient_kctl_valoffs (kctl); -const u16 index = ctype->wIndex; +const u8 base =snd_audient_kctl_cidxoffs (kctl);int i;
@@ -367,8 +373,8 @@ static int snd_ctl_audient_integer_get(struct snd_kcontrol *kctl,s16 val;int ret; - ret =snd_audient_get_cur (mixer, value + i, index, - &buf,sizeof (buf)); + ret =snd_audient_get_cur (mixer, ctype->unit, ctype->sel, + base + i, &buf,sizeof (buf));if (ret <0 )return ret;
@@ -391,8 +397,7 @@ static int snd_ctl_audient_integer_set(struct snd_kcontrol *kctl,const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl);const struct snd_audient_ctrl_type *const ctype =snd_audient_kctl_type (kctl); -const u16 value = ctype->wValue +snd_audient_kctl_valoffs (kctl); -const u16 index = ctype->wIndex; +const u8 base =snd_audient_kctl_cidxoffs (kctl);int changed =0 ;int i;
@@ -406,15 +411,16 @@ static int snd_ctl_audient_integer_set(struct snd_kcontrol *kctl,s16 buf =cpu_to_le16 (ctl_val->value.integer.value[i]);int ret; - ret =snd_audient_get_cur (mixer, value + i, index, - &rbuf,sizeof (rbuf)); + ret =snd_audient_get_cur (mixer, ctype->unit, ctype->sel, + base + i, &rbuf,sizeof (rbuf));if (ret <0 )return ret;if (rbuf != buf) { changed =1 ; - ret =snd_audient_set_cur (mixer, value + i, index, + ret =snd_audient_set_cur (mixer, ctype->unit, + ctype->sel, base + i, &buf,sizeof (buf));if (ret <0 )return ret;
Signature · 1 line
2.56.0
RFC PATCH 1/11 ALSA: rename mixer_evo to mixer_audient
In reply to Christian RuppertRename mixer_evo files and functions to *_audient in preparation of a more generic driver for audient devices.
---
MAINTAINERS | 7 +-
sound/usb/Makefile | 2 +-
sound/usb/{mixer_evo.c => mixer_audient.c} | 247 +++++++++++----------
sound/usb/mixer_audient.h | 12 +
sound/usb/mixer_evo.h | 12 -
sound/usb/mixer_quirks.c | 4 +-
6 files changed, 147 insertions(+), 137 deletions(-)
rename sound/usb/{mixer_evo.c => mixer_audient.c} (54%)
create mode 100644 sound/usb/mixer_audient.h
delete mode 100644 sound/usb/mixer_evo.hMAINTAINERS +4 -3
@@ -4354,12 +4354,13 @@ F: drivers/net/ieee802154/at86rf230.h F: drivers/net/ieee802154/atusb.c F: drivers/net/ieee802154/atusb.h -AUDIENT EVO MIXER DRIVER +AUDIENT MIXER DRIVER M: Christian Ruppert <[email protected]> +M: Will Porter <[email protected]> L: [email protected] S: Maintained -F: sound/usb/mixer_evo.c -F: sound/usb/mixer_evo.h +F: sound/usb/mixer_audient.c +F: sound/usb/mixer_audient.h AUDIT SUBSYSTEM M: Paul Moore <[email protected]>
sound/usb/Makefile +1 -1
@@ -11,7 +11,7 @@ snd-usb-audio-y := card.o \ helper.o \ implicit.o \ mixer.o \ - mixer_evo.o \ + mixer_audient.o \ mixer_quirks.o \ mixer_scarlett.o \ mixer_scarlett2.o \
sound/usb/mixer_audient.c renamed from sound/usb/mixer_evo.c +128 -119
550 lines not on this page · raw message
sound/usb/mixer_audient.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __USB_MIXER_AUDIENT_H +#define __USB_MIXER_AUDIENT_H + +#include "mixer.h" + +#define USB_AUDIENT_VID (0x2708) +#define USB_EVO4_PID (0x0006) + +int snd_audient_controls_create (struct usb_mixer_interface *mixer); + +#endif /* __USB_MIXER_AUDIENT_H */
sound/usb/mixer_evo.h deleted +0 -12
@@ -1,12 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef __USB_MIXER_EVO_H -#define __USB_MIXER_EVO_H - -#include "mixer.h" - -#define USB_AUDIENT_VID (0x2708) -#define USB_EVO4_PID (0x0006) - -int snd_evo_controls_create (struct usb_mixer_interface *mixer); - -#endif /* __USB_MIXER_EVO_H */
sound/usb/mixer_quirks.c +2 -2
@@ -38,7 +38,7 @@#include "mixer_scarlett2.h" #include "mixer_us16x08.h" #include "mixer_s1810c.h" -#include "mixer_evo.h" +#include "mixer_audient.h" #include "helper.h" #include "fcp.h"
@@ -4541,7 +4541,7 @@ int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)break ;case USB_ID (USB_AUDIENT_VID ,USB_EVO4_PID ):/* Audient EVO 4 */ - err =snd_evo_controls_create (mixer); + err =snd_audient_controls_create (mixer);break ;case USB_ID (0x041e ,0x323b ):/* Creative Sound Blaster E1 */
Signature · 1 line
2.56.0
RFC PATCH 7/11 ALSA: mixer_audient: Add integer range checks
In reply to Christian RuppertAdd range checks to integer parameters to improve error management:
- Reject out-of-range write attempts with -EINVAL
- Prune out-of-range values returned by the device to the range limits
--- sound/usb/mixer_audient.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
sound/usb/mixer_audient.c +15 -2
@@ -42,10 +42,10 @@ static const struct snd_audient_ctrl_type {unsigned long flags;size_t len;union { -int integer; +long integer; } min;/* for booleans holds physical int value for false */ union { -int integer; +long integer; } max;/* for booleans holds physical int value for true */ const unsigned int *tlv;u8 unit;
@@ -424,6 +424,12 @@ static int snd_ctl_audient_integer_get(struct snd_kcontrol *kctl,if (ret <0 )return ret; +if (val < ctype->min.integer) + val = ctype->min.integer; + +if (val > ctype->max.integer) + val = ctype->max.integer; + ctl_val->value.integer.value[i] = val; }
@@ -447,6 +453,13 @@ static int snd_ctl_audient_integer_set(struct snd_kcontrol *kctl,int changed =0 ;int i; +for (i =0 ; i < hwchan; i++) { +long val = ctl_val->value.integer.value[i]; + +if ((val < ctype->min.integer) || (val > ctype->max.integer)) +return -EINVAL ; + } +CLASS (snd_usb_lock, pm)(mixer->chip);if (pm.err <0 )return pm.err;
Signature · 1 line
2.56.0
RFC PATCH 2/11 ALSA: mixer_audient: explicitly define full control names
In reply to Christian RuppertPreviously, control names were dynamically created depending if the control was an input or an output, a volume or a switch. Get rid of this logic by simply defining the full name in the control structure.
--- sound/usb/mixer_audient.c | 50 +++++++++++---------------------------- 1 file changed, 14 insertions(+), 36 deletions(-)
sound/usb/mixer_audient.c +14 -36
@@ -90,107 +90,92 @@ static const struct snd_audient_ctrl_type { }, }; -#define SND_AUDIENT_FLAGS_DIRECTION (1L<<0) -#define SND_AUDIENT_FLAGS_CAPTURE (1L<<0) -#define SND_AUDIENT_FLAGS_PLAYBACK (0L<<0)struct snd_audient_ctrl { -char *basename; +char *name;enum snd_audient_type type;unsigned int channels;unsigned int hwchannels;unsigned int val_offs; -unsigned long flags; };static const struct snd_audient_ctrl snd_audient_evo4_controls[] = { { - .basename ="Master" , + .name ="Master Playback Switch" , .type =SND_AUDIENT_TYPE_MUTE_OUT , .channels =1 , .hwchannels =1 , .val_offs =0 , - .flags =SND_AUDIENT_FLAGS_PLAYBACK , }, { - .basename ="Mic" , + .name ="Mic Playback Switch" , .type =SND_AUDIENT_TYPE_MUTE , .channels =4 , .hwchannels =2 , .val_offs =0 , - .flags =SND_AUDIENT_FLAGS_PLAYBACK , }, { - .basename ="Monitor" , + .name ="Monitor Playback Volume" , .type =SND_AUDIENT_TYPE_MONITOR , .channels =1 , .hwchannels =1 , .val_offs =0 , - .flags =SND_AUDIENT_FLAGS_PLAYBACK , }, { - .basename ="Mic 1" , + .name ="Mic 1 Capture Volume" , .type =SND_AUDIENT_TYPE_MIXER , .channels =2 , .hwchannels =2 , .val_offs =0 , - .flags =SND_AUDIENT_FLAGS_CAPTURE , }, { - .basename ="Mic 2" , + .name ="Mic 2 Capture Volume" , .type =SND_AUDIENT_TYPE_MIXER , .channels =2 , .hwchannels =2 , .val_offs =2 , - .flags =SND_AUDIENT_FLAGS_CAPTURE , }, { - .basename ="Master Left" , + .name ="Master Left Capture Volume" , .type =SND_AUDIENT_TYPE_MIXER , .channels =2 , .hwchannels =2 , .val_offs =4 , - .flags =SND_AUDIENT_FLAGS_CAPTURE , }, { - .basename ="Master Right" , + .name ="Master Right Capture Volume" , .type =SND_AUDIENT_TYPE_MIXER , .channels =2 , .hwchannels =2 , .val_offs =6 , - .flags =SND_AUDIENT_FLAGS_CAPTURE , }, { - .basename ="Loopback Left" , + .name ="Loopback Left Capture Volume" , .type =SND_AUDIENT_TYPE_MIXER , .channels =2 , .hwchannels =2 , .val_offs =8 , - .flags =SND_AUDIENT_FLAGS_CAPTURE , }, { - .basename ="Loopback Right" , + .name ="Loopback Right Capture Volume" , .type =SND_AUDIENT_TYPE_MIXER , .channels =2 , .hwchannels =2 , .val_offs =10 , - .flags =SND_AUDIENT_FLAGS_CAPTURE , }, { - .basename ="Mic 1 Phantom" , + .name ="Mic 1 Phantom Capture Switch" , .type =SND_AUDIENT_TYPE_PHANTOM , .channels =1 , .hwchannels =1 , .val_offs =0 , - .flags =SND_AUDIENT_FLAGS_CAPTURE , }, { - .basename ="Mic 2 Phantom" , + .name ="Mic 2 Phantom Capture Switch" , .type =SND_AUDIENT_TYPE_PHANTOM , .channels =1 , .hwchannels =1 , .val_offs =1 , - .flags =SND_AUDIENT_FLAGS_CAPTURE , }, {0 },/* sentinel */ };
@@ -458,13 +443,12 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer, {const struct snd_audient_ctrl_type *ctype = &snd_audient_ctypes[ctrl->type]; -char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN ];struct snd_kcontrol_new knew = {0 };struct snd_kcontrol *kctl;struct usb_mixer_elem_info *elem; knew.iface =SNDRV_CTL_ELEM_IFACE_MIXER ; - knew.name = name; + knew.name = ctrl->name; knew.info = snd_ctl_audient_info; knew.private_value =snd_audient_kctl_priv (ctrl->type, ctrl->val_offs, ctrl->hwchannels);
@@ -486,12 +470,6 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer,return -EINVAL ; } -snprintf (name,sizeof (name),"%s %s %s" , ctrl->basename, - ((ctrl->flags &SND_AUDIENT_FLAGS_DIRECTION ) - ==SND_AUDIENT_FLAGS_CAPTURE ) ?"Capture" :"Playback" , - (ctype->type ==SNDRV_CTL_ELEM_TYPE_BOOLEAN ) - ?"Switch" :"Volume" ); - elem =kzalloc_obj (*elem);if (!elem)return -ENOMEM ;
@@ -524,7 +502,7 @@ int snd_audient_controls_create(struct usb_mixer_interface *mixer)if (!info->controls)return -ENODEV ; -for (ctrl = info->controls; ctrl->basename; ctrl++) { +for (ctrl = info->controls; ctrl->name; ctrl++) {const int ret =snd_audient_add_ctrl (mixer, ctrl);if (ret <0 )
Signature · 1 line
2.56.0
RFC PATCH 4/11 ALSA: mixer_audient: Add length check to USB transfer
In reply to Christian RuppertCheck USB control transfers not only for errors but also for expected length and return -EIO in case of error.
--- sound/usb/mixer_audient.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
sound/usb/mixer_audient.c +16 -6
@@ -244,9 +244,14 @@ static inline int snd_audient_get_cur(struct usb_mixer_interface *mixer,const u16 value =U8_U8 (sel, cidx);const u16 index =U8_U8 (unit, mixer->hostif->desc.bInterfaceNumber); -return snd_usb_ctl_msg (dev,usb_rcvctrlpipe (dev,0 ), -UAC2_CS_CUR ,AUDIENT_REQTYPE_GET , - value, index, buf, len); +const int ret =snd_usb_ctl_msg (dev,usb_rcvctrlpipe (dev,0 ), +UAC2_CS_CUR ,AUDIENT_REQTYPE_GET , + value, index, buf, len); + +if ((ret >=0 ) && (ret != len)) +return -EIO ; + +return ret; } static inline int snd_audient_set_cur(struct usb_mixer_interface *mixer,
@@ -258,9 +263,14 @@ static inline int snd_audient_set_cur(struct usb_mixer_interface *mixer,const u16 value =U8_U8 (sel, cidx);const u16 index =U8_U8 (unit, mixer->hostif->desc.bInterfaceNumber); -return snd_usb_ctl_msg (dev,usb_sndctrlpipe (dev,0 ), -UAC2_CS_CUR ,AUDIENT_REQTYPE_SET , - value, index, buf, len); +const int ret =snd_usb_ctl_msg (dev,usb_sndctrlpipe (dev,0 ), +UAC2_CS_CUR ,AUDIENT_REQTYPE_SET , + value, index, buf, len); + +if ((ret >=0 ) && (ret != len)) +return -EIO ; + +return ret; }
Signature · 1 line
2.56.0
RFC PATCH 8/11 ALSA: mixer_audient: Add control initialization at probe
In reply to Christian RuppertAdd the possibility to initialize certain control types to known values at probe time. This is particularly useful for controls which initially read wrong values and for controls which cannot be read at all.
--- sound/usb/mixer_audient.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
sound/usb/mixer_audient.c +14 -0
@@ -36,6 +36,7 @@ enum snd_audient_type { static const DECLARE_TLV_DB_MINMAX_MUTE(snd_audient_tlv_mixer, -12800, 600);#define SND_AUDIENT_CTYPE_FLAGS_SIGNED (1L << 0) +#define SND_AUDIENT_CTYPE_FLAGS_INIT_HW (1L << 1) static const struct snd_audient_ctrl_type { snd_ctl_elem_type_t type;
@@ -47,6 +48,7 @@ static const struct snd_audient_ctrl_type {union {long integer; } max;/* for booleans holds physical int value for true */ +u32 init;const unsigned int *tlv;u8 unit;u8 sel;
@@ -532,6 +534,18 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer,return -EINVAL ; } +if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_INIT_HW ) { +int i; + +for (i =0 ; i < ctrl->hwchannels; i++) { +int ret =snd_audient_raw_set_one (mixer, ctype, + ctrl->val_offs + i, + ctype->init); +if (ret <0 ) +return ret; + } + } + elem =kzalloc_obj (*elem);if (!elem)return -ENOMEM ;
Signature · 1 line
2.56.0
RFC PATCH 11/11 ALSA: mixer_audient: Create matrix programmatically
In reply to Christian RuppertMost Audient devices seem to have a similar mixer matrix with many identical channels. The only difference between devices seems to be the matrix' dimension. Create it programmatically in a loop rather than from the controls table.
--- sound/usb/mixer_audient.c | 75 +++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 43 deletions(-)
sound/usb/mixer_audient.c +32 -43
@@ -103,7 +103,7 @@ static const struct snd_audient_ctrl_type {struct snd_audient_ctrl { -char *name; +const char *const name;enum snd_audient_type type;unsigned int channels;unsigned int hwchannels;
@@ -132,48 +132,6 @@ static const struct snd_audient_ctrl snd_audient_evo4_controls[] = { .hwchannels = 1, .val_offs = 0, }, - { - .name = "Mic 1 Capture Volume", - .type = SND_AUDIENT_TYPE_MIXER, - .channels = 2, - .hwchannels = 2, - .val_offs = 0, - }, - { - .name = "Mic 2 Capture Volume", - .type = SND_AUDIENT_TYPE_MIXER, - .channels = 2, - .hwchannels = 2, - .val_offs = 2, - }, - { - .name = "Master Left Capture Volume", - .type = SND_AUDIENT_TYPE_MIXER, - .channels = 2, - .hwchannels = 2, - .val_offs = 4, - }, - { - .name = "Master Right Capture Volume", - .type = SND_AUDIENT_TYPE_MIXER, - .channels = 2, - .hwchannels = 2, - .val_offs = 6, - }, - { - .name = "Loopback Left Capture Volume", - .type = SND_AUDIENT_TYPE_MIXER, - .channels = 2, - .hwchannels = 2, - .val_offs = 8, - }, - { - .name = "Loopback Right Capture Volume", - .type = SND_AUDIENT_TYPE_MIXER, - .channels = 2, - .hwchannels = 2, - .val_offs = 10, - }, { .name = "Mic 1 Phantom Capture Switch", .type = SND_AUDIENT_TYPE_PHANTOM,
@@ -191,13 +149,27 @@ static const struct snd_audient_ctrl snd_audient_evo4_controls[] = { { 0 }, /* sentinel */ }; +static const char *const snd_audient_evo4_matrix[] = { +"Mic 1 Capture Volume" , +"Mic 2 Capture Volume" , +"Master Left Capture Volume" , +"Master Right Capture Volume" , +"Loopback Left Capture Volume" , +"Loopback Right Capture Volume" , +NULL +}; +static const struct audient_devinfo {u32 usb_id;const struct snd_audient_ctrl *controls; +const char *const *const matrix_names; +const unsigned int matrix_channels; } audient_devinfo[] = { { .usb_id =USB_ID (USB_AUDIENT_VID ,USB_EVO4_PID ), .controls = snd_audient_evo4_controls, + .matrix_names = snd_audient_evo4_matrix, + .matrix_channels =2 , }, {0 }/* sentinel */ };
@@ -626,6 +598,8 @@ int snd_audient_controls_create(struct usb_mixer_interface *mixer)const struct audient_devinfo *info;const struct snd_audient_ctrl *ctrl; +int i; +for (info = audient_devinfo; info->controls; info++)if (info->usb_id == mixer->chip->usb_id)break ;
@@ -640,5 +614,20 @@ int snd_audient_controls_create(struct usb_mixer_interface *mixer)return ret; } +for (i =0 ; info->matrix_names[i]; i++) { +const struct snd_audient_ctrl c = { + .name = info->matrix_names[i], + .type =SND_AUDIENT_TYPE_MIXER , + .channels = info->matrix_channels, + .hwchannels = info->matrix_channels, + .val_offs = i * info->matrix_channels, + }; + +const int ret =snd_audient_add_ctrl (mixer, &c); + +if (ret <0 ) +return ret; + } +return 0 ; }
Signature · 1 line
2.56.0
RFC PATCH 6/11 ALSA: mixer_audient: Allow arbitrary boolean control values
In reply to Christian RuppertIn preparation of id14 support, allow arbitrary values for true and false of boolean switches. This also rids us of the tedious invert flag.
--- sound/usb/mixer_audient.c | 43 ++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 23 deletions(-)
sound/usb/mixer_audient.c +20 -23
@@ -41,13 +41,12 @@ static const struct snd_audient_ctrl_type {snd_ctl_elem_type_t type;unsigned long flags;size_t len; -bool invert;union {int integer; - } min; + } min;/* for booleans holds physical int value for false */ union {int integer; - } max; + } max;/* for booleans holds physical int value for true */ const unsigned int *tlv;u8 unit;u8 sel;
@@ -63,7 +62,6 @@ static const struct snd_audient_ctrl_type { }, [SND_AUDIENT_TYPE_PHANTOM] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, - .invert = false, .len = 4, .min.integer = 0, .max.integer = 1,
@@ -72,19 +70,17 @@ static const struct snd_audient_ctrl_type { }, [SND_AUDIENT_TYPE_MUTE] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, - .invert = true, .len = 4, - .min.integer = 0, - .max.integer = 1, + .min.integer = 1, + .max.integer = 0, .unit = 0x3A, .sel = 0x02, }, [SND_AUDIENT_TYPE_MUTE_OUT] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, - .invert = true, .len = 4, - .min.integer = 0, - .max.integer = 1, + .min.integer = 1, + .max.integer = 0, .unit = 0x3B, .sel = 0x01, },
@@ -358,16 +354,12 @@ static int snd_ctl_audient_boolean_get(struct snd_kcontrol *kctl,if (ret <0 )return ret; - ctl_val->value.integer.value[i] = buf ?1 :0 ; - -if (ctype->invert) - ctl_val->value.integer.value[i] ^=0x1 ; + ctl_val->value.integer.value[i] = (buf == ctype->min.integer) + ? false : true; }for (; i < nchan; i++) - ctl_val->value.integer.value[i] = ctype->invert - ? ctype->max.integer - : ctype->min.integer; + ctl_val->value.integer.value[i] =0 ;return 0 ; }
@@ -391,12 +383,10 @@ static int snd_ctl_audient_boolean_set(struct snd_kcontrol *kctl,return pm.err;for (i =0 ; i < hwchan; i++) { -u32 buf = ctl_val->value.integer.value[i] ?1 :0 ; +u32 buf = ctl_val->value.integer.value[i] ? ctype->max.integer + : ctype->min.integer;int ret; -if (ctype->invert) - buf ^=0x1 ; - ret =snd_audient_raw_set_one (mixer, ctype, base + i, buf);if (ret <0 )return ret;
@@ -484,8 +474,15 @@ static int snd_ctl_audient_info(struct snd_kcontrol *kctl, uinfo->type = ctype->type; uinfo->count =snd_audient_kctl_channels (kctl); - uinfo->value.integer.min = ctype->min.integer; - uinfo->value.integer.max = ctype->max.integer; + +if (ctype->type ==SNDRV_CTL_ELEM_TYPE_BOOLEAN ) { + uinfo->value.integer.min =0 ; + uinfo->value.integer.max =1 ; + }else { + uinfo->value.integer.min = ctype->min.integer; + uinfo->value.integer.max = ctype->max.integer; + } +return 0 ; }
Signature · 1 line
2.56.0
RFC PATCH 10/11 ALSA: mixer_audient: add control value caching
In reply to Christian RuppertIn preparation of id14 support, add control value caching.
--- sound/usb/mixer_audient.c | 112 +++++++++++++++++++++++++++----------- 1 file changed, 81 insertions(+), 31 deletions(-)
sound/usb/mixer_audient.c +81 -31
@@ -38,6 +38,7 @@ static const DECLARE_TLV_DB_MINMAX_MUTE(snd_audient_tlv_mixer, -12800, 600);#define SND_AUDIENT_CTYPE_FLAGS_SIGNED (1L << 0)#define SND_AUDIENT_CTYPE_FLAGS_INIT_HW (1L << 1)#define SND_AUDIENT_CTYPE_FLAGS_FORCE_SET (1L << 2) +#define SND_AUDIENT_CTYPE_FLAGS_CACHE (1L << 3) static const struct snd_audient_ctrl_type { snd_ctl_elem_type_t type;
@@ -49,7 +50,7 @@ static const struct snd_audient_ctrl_type {union {long integer; } max;/* for booleans holds physical int value for true */ -u32 init; +u32 init;/* hardware and cache are initialized to this value */ const unsigned int *tlv;u8 unit;u8 sel;
@@ -89,7 +90,8 @@ static const struct snd_audient_ctrl_type { }, [SND_AUDIENT_TYPE_MIXER] = { .type = SNDRV_CTL_ELEM_TYPE_INTEGER, - .flags = SND_AUDIENT_CTYPE_FLAGS_SIGNED, + .flags =SND_AUDIENT_CTYPE_FLAGS_SIGNED + | SND_AUDIENT_CTYPE_FLAGS_CACHE, .len = 2, .min.integer = -128 * 256, .max.integer = 6 * 256,
@@ -285,11 +287,18 @@ static inline int snd_audient_set_cur(struct usb_mixer_interface *mixer,static int snd_audient_raw_get_one (struct usb_mixer_interface *const mixer,const struct snd_audient_ctrl_type *const ctype, +const u32 *const cache,const u8 cidx,u32 *const value) {int ret;s32 buf =0 ; +if (cache) { + *value = cache[cidx]; + +return ctype->len; + } + ret =snd_audient_get_cur (mixer, ctype, cidx, &buf);if (ret <0 )return ret;
@@ -309,15 +318,16 @@ static int snd_audient_raw_get_one(struct usb_mixer_interface *const mixer,static int snd_audient_raw_set_one (struct usb_mixer_interface *const mixer,const struct snd_audient_ctrl_type *const ctype, -const u8 cidx,const u32 value) +u32 *const cache,const u8 cidx,const u32 value, +bool force) {int ret;u32 buf; -if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_FORCE_SET ) { +if ((ctype->flags &SND_AUDIENT_CTYPE_FLAGS_FORCE_SET ) || force) { buf = !value;/* just make it different */ }else { - ret =snd_audient_raw_get_one (mixer, ctype, cidx, &buf); + ret =snd_audient_raw_get_one (mixer, ctype, cache, cidx, &buf);if (ret <0 )return ret; }
@@ -328,6 +338,9 @@ static int snd_audient_raw_set_one(struct usb_mixer_interface *const mixer,if (ret <0 )return ret; +if (cache) + cache[cidx] = value; +return 1 ; }
@@ -338,8 +351,8 @@ static int snd_audient_raw_set_one(struct usb_mixer_interface *const mixer,static int snd_ctl_audient_boolean_get (struct snd_kcontrol *kctl,struct snd_ctl_elem_value *ctl_val) { -struct usb_mixer_elem_list *const list =snd_kcontrol_chip (kctl); -struct usb_mixer_interface *const mixer = list->mixer; +struct usb_mixer_elem_info *const elem =snd_kcontrol_chip (kctl); +struct usb_mixer_interface *const mixer = elem->head.mixer;const unsigned int nchan =snd_audient_kctl_channels (kctl);const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl);
@@ -357,7 +370,8 @@ static int snd_ctl_audient_boolean_get(struct snd_kcontrol *kctl,u32 buf;int ret; - ret =snd_audient_raw_get_one (mixer, ctype, base + i, &buf); + ret =snd_audient_raw_get_one (mixer, ctype, elem->private_data, + base + i, &buf);if (ret <0 )return ret;
@@ -374,8 +388,8 @@ static int snd_ctl_audient_boolean_get(struct snd_kcontrol *kctl,static int snd_ctl_audient_boolean_set (struct snd_kcontrol *kctl,struct snd_ctl_elem_value *ctl_val) { -struct usb_mixer_elem_list *list =snd_kcontrol_chip (kctl); -struct usb_mixer_interface *mixer = list->mixer; +struct usb_mixer_elem_info *const elem =snd_kcontrol_chip (kctl); +struct usb_mixer_interface *const mixer = elem->head.mixer;const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl);const struct snd_audient_ctrl_type *const ctype
@@ -394,7 +408,8 @@ static int snd_ctl_audient_boolean_set(struct snd_kcontrol *kctl, : ctype->min.integer;int ret; - ret =snd_audient_raw_set_one (mixer, ctype, base + i, buf); + ret =snd_audient_raw_set_one (mixer, ctype, elem->private_data, + base + i, buf, false);if (ret <0 )return ret;
@@ -408,8 +423,8 @@ static int snd_ctl_audient_boolean_set(struct snd_kcontrol *kctl,static int snd_ctl_audient_integer_get (struct snd_kcontrol *kctl,struct snd_ctl_elem_value *ctl_val) { -struct usb_mixer_elem_list *const list =snd_kcontrol_chip (kctl); -struct usb_mixer_interface *const mixer = list->mixer; +struct usb_mixer_elem_info *const elem =snd_kcontrol_chip (kctl); +struct usb_mixer_interface *const mixer = elem->head.mixer;const unsigned int nchan =snd_audient_kctl_channels (kctl);const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl);
@@ -427,7 +442,8 @@ static int snd_ctl_audient_integer_get(struct snd_kcontrol *kctl,s32 val;int ret; - ret =snd_audient_raw_get_one (mixer, ctype, base + i, &val); + ret =snd_audient_raw_get_one (mixer, ctype, elem->private_data, + base + i, &val);if (ret <0 )return ret;
@@ -449,8 +465,8 @@ static int snd_ctl_audient_integer_get(struct snd_kcontrol *kctl,static int snd_ctl_audient_integer_set (struct snd_kcontrol *kctl,struct snd_ctl_elem_value *ctl_val) { -struct usb_mixer_elem_list *list =snd_kcontrol_chip (kctl); -struct usb_mixer_interface *mixer = list->mixer; +struct usb_mixer_elem_info *const elem =snd_kcontrol_chip (kctl); +struct usb_mixer_interface *mixer = elem->head.mixer;const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl);const struct snd_audient_ctrl_type *const ctype
@@ -475,7 +491,8 @@ static int snd_ctl_audient_integer_set(struct snd_kcontrol *kctl,s32 val = ctl_val->value.integer.value[i];int ret; - ret =snd_audient_raw_set_one (mixer, ctype, base + i, val); + ret =snd_audient_raw_set_one (mixer, ctype, elem->private_data, + base + i, val, false);if (ret <0 )return ret;
@@ -516,6 +533,8 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer,struct snd_kcontrol *kctl;struct usb_mixer_elem_info *elem; +int ret; + knew.iface =SNDRV_CTL_ELEM_IFACE_MIXER ; knew.name = ctrl->name; knew.info = snd_ctl_audient_info;
@@ -523,7 +542,9 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer, ctrl->hwchannels); knew.tlv.p = ctype->tlv; knew.access =SNDRV_CTL_ELEM_ACCESS_READWRITE - |SNDRV_CTL_ELEM_ACCESS_VOLATILE + | ((ctype->flags &SND_AUDIENT_CTYPE_FLAGS_CACHE ) + ?0 + :SNDRV_CTL_ELEM_ACCESS_VOLATILE ) | (ctype->tlv ?SNDRV_CTL_ELEM_ACCESS_TLV_READ :0 );switch (ctype->type) {
@@ -539,34 +560,63 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer,return -EINVAL ; } + elem =kzalloc (sizeof (*elem) + + ((ctype->flags &SND_AUDIENT_CTYPE_FLAGS_CACHE ) + ? (sizeof (u32) * ctrl->hwchannels) + :0 ), +GFP_KERNEL ); +if (!elem) +return -ENOMEM ; + + elem->head.mixer = mixer; + elem->channels = ctrl->channels; + +if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_CACHE ) + elem->private_data = elem +1 ; +if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_INIT_HW ) {int i;for (i =0 ; i < ctrl->hwchannels; i++) { -int ret =snd_audient_raw_set_one (mixer, ctype, - ctrl->val_offs + i, - ctype->init); + ret =snd_audient_raw_set_one (mixer, ctype, + elem->private_data, + ctrl->val_offs + i, + ctype->init, true);if (ret <0 ) -return ret; + goto free_elem; } - } - - elem =kzalloc_obj (*elem); -if (!elem) -return -ENOMEM ; + }else if (elem->private_data) { +u32 *const cache = elem->private_data; +int i; - elem->head.mixer = mixer; - elem->channels = ctrl->channels; +if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_FORCE_SET ) +for (i =0 ; i < ctrl->hwchannels; i++) + cache[i] = ctype->init; +else +for (i =0 ; i < ctrl->hwchannels; i++) { + ret =snd_audient_raw_get_one ( + mixer, ctype,NULL , + ctrl->val_offs + i, + cache + i); +if (ret <0 ) + goto free_elem; + } + } kctl =snd_ctl_new1 (&knew, elem);if (!kctl) { -kfree (elem); -return -ENOMEM ; + ret = -ENOMEM ; + goto free_elem; } kctl->private_free = snd_usb_mixer_elem_free;return snd_usb_mixer_add_control (&elem->head, kctl); + +free_elem: +kfree (elem); + +return ret; }
Signature · 1 line
2.56.0
RFC PATCH 5/11 ALSA: mixer_audient: make USB control transfer size configurable
In reply to Christian RuppertPreviously, the USB transfer size was hardcoded in the datatype get/set functions. Make it configurable in the ctype structure in preparation of new control types for the id14.
--- sound/usb/mixer_audient.c | 130 ++++++++++++++++++++++++-------------- 1 file changed, 83 insertions(+), 47 deletions(-)
sound/usb/mixer_audient.c +83 -47
@@ -35,8 +35,12 @@ enum snd_audient_type {/* Mixer matrix: -128dB (mute) to +6dB */ static const DECLARE_TLV_DB_MINMAX_MUTE(snd_audient_tlv_mixer, -12800, 600); +#define SND_AUDIENT_CTYPE_FLAGS_SIGNED (1L << 0) + static const struct snd_audient_ctrl_type { snd_ctl_elem_type_t type; + unsigned long flags; + size_t len; bool invert; union { int integer;
@@ -50,6 +54,7 @@ static const struct snd_audient_ctrl_type { } snd_audient_ctypes[SND_AUDIENT_TYPE_NCTYPES] = { [SND_AUDIENT_TYPE_MONITOR] = { .type = SNDRV_CTL_ELEM_TYPE_INTEGER, + .len = 2, .min.integer = 0, .max.integer = 127, .unit = 0x38,
@@ -59,6 +64,7 @@ static const struct snd_audient_ctrl_type { [SND_AUDIENT_TYPE_PHANTOM] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, .invert = false, + .len = 4, .min.integer = 0, .max.integer = 1, .unit = 0x3A,
@@ -67,6 +73,7 @@ static const struct snd_audient_ctrl_type { [SND_AUDIENT_TYPE_MUTE] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, .invert = true, + .len = 4, .min.integer = 0, .max.integer = 1, .unit = 0x3A,
@@ -75,6 +82,7 @@ static const struct snd_audient_ctrl_type { [SND_AUDIENT_TYPE_MUTE_OUT] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, .invert = true, + .len = 4, .min.integer = 0, .max.integer = 1, .unit = 0x3B,
@@ -82,6 +90,8 @@ static const struct snd_audient_ctrl_type { }, [SND_AUDIENT_TYPE_MIXER] = { .type = SNDRV_CTL_ELEM_TYPE_INTEGER, + .flags = SND_AUDIENT_CTYPE_FLAGS_SIGNED, + .len = 2, .min.integer = -128 * 256, .max.integer = 6 * 256, .unit = 0x3C,
@@ -236,44 +246,92 @@ static inline u16 snd_audient_kctl_channels(struct snd_kcontrol *kctl)#define U8_U8 (HI ,LO ) ((((u16)(HI)) << 8) | ((LO) & 0xFF))static inline int snd_audient_get_cur (struct usb_mixer_interface *mixer, -const u8 unit,const u8 sel, -const u8 cidx, -void *const buf,const size_t len) +const struct snd_audient_ctrl_type *const ctype, +const u8 cidx,void *const buf) {struct usb_device *const dev = mixer->chip->dev; -const u16 value =U8_U8 (sel, cidx); -const u16 index =U8_U8 (unit, mixer->hostif->desc.bInterfaceNumber); +const u16 value =U8_U8 (ctype->sel, cidx); +const u16 index =U8_U8 (ctype->unit, + mixer->hostif->desc.bInterfaceNumber);const int ret =snd_usb_ctl_msg (dev,usb_rcvctrlpipe (dev,0 ),UAC2_CS_CUR ,AUDIENT_REQTYPE_GET , - value, index, buf, len); + value, index, buf, ctype->len); -if ((ret >=0 ) && (ret != len)) +if ((ret >=0 ) && (ret != ctype->len))return -EIO ;return ret; }static inline int snd_audient_set_cur (struct usb_mixer_interface *mixer, -const u8 unit,const u8 sel, -const u8 cidx, -void *const buf,const size_t len) +const struct snd_audient_ctrl_type *const ctype, +const u8 cidx,void *const buf) {struct usb_device *const dev = mixer->chip->dev; -const u16 value =U8_U8 (sel, cidx); -const u16 index =U8_U8 (unit, mixer->hostif->desc.bInterfaceNumber); +const u16 value =U8_U8 (ctype->sel, cidx); +const u16 index =U8_U8 (ctype->unit, + mixer->hostif->desc.bInterfaceNumber);const int ret =snd_usb_ctl_msg (dev,usb_sndctrlpipe (dev,0 ),UAC2_CS_CUR ,AUDIENT_REQTYPE_SET , - value, index, buf, len); + value, index, buf, ctype->len); -if ((ret >=0 ) && (ret != len)) +if ((ret >=0 ) && (ret != ctype->len))return -EIO ;return ret; } +static int snd_audient_raw_get_one (struct usb_mixer_interface *const mixer, +const struct snd_audient_ctrl_type *const ctype, +const u8 cidx,u32 *const value) +{ +int ret; +s32 buf =0 ; + + ret =snd_audient_get_cur (mixer, ctype, cidx, &buf); +if (ret <0 ) +return ret; + + buf =le32_to_cpu (buf); + +if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_SIGNED ) { +const unsigned int sh =32 -8 * ctype->len; + + buf = (buf << sh) >> sh; + } + + *value = buf; + +return ret; +} + +static int snd_audient_raw_set_one (struct usb_mixer_interface *const mixer, +const struct snd_audient_ctrl_type *const ctype, +const u8 cidx,const u32 value) +{ +int ret; +u32 buf; + + ret =snd_audient_raw_get_one (mixer, ctype, cidx, &buf); +if (ret <0 ) +return ret; + +if (buf != value) { + buf =cpu_to_le32 (value); + ret =snd_audient_set_cur (mixer, ctype, cidx, &buf); +if (ret <0 ) +return ret; + +return 1 ; + } + +return 0 ; +} + +static int snd_ctl_audient_boolean_get (struct snd_kcontrol *kctl,struct snd_ctl_elem_value *ctl_val) {
@@ -296,12 +354,11 @@ static int snd_ctl_audient_boolean_get(struct snd_kcontrol *kctl,u32 buf;int ret; - ret =snd_audient_get_cur (mixer, ctype->unit, ctype->sel, - base + i, &buf,sizeof (buf)); + ret =snd_audient_raw_get_one (mixer, ctype, base + i, &buf);if (ret <0 )return ret; - ctl_val->value.integer.value[i] =le32_to_cpu (buf) ?1 :0 ; + ctl_val->value.integer.value[i] = buf ?1 :0 ;if (ctype->invert) ctl_val->value.integer.value[i] ^=0x1 ;
@@ -334,27 +391,18 @@ static int snd_ctl_audient_boolean_set(struct snd_kcontrol *kctl,return pm.err;for (i =0 ; i < hwchan; i++) { -u32 rbuf; -u32 buf =cpu_to_le32 (ctl_val->value.integer.value[i] ?1 :0 ); +u32 buf = ctl_val->value.integer.value[i] ?1 :0 ;int ret;if (ctype->invert) - buf ^=cpu_to_le32 (0x1 ); + buf ^=0x1 ; - ret =snd_audient_get_cur (mixer, ctype->unit, ctype->sel, - base + i, &rbuf,sizeof (rbuf)); + ret =snd_audient_raw_set_one (mixer, ctype, base + i, buf);if (ret <0 )return ret; -if (rbuf != buf) { +if (ret) changed =1 ; - - ret =snd_audient_set_cur (mixer, ctype->unit, - ctype->sel, base + i, - &buf,sizeof (buf)); -if (ret <0 ) -return ret; - } }return changed;
@@ -379,16 +427,13 @@ static int snd_ctl_audient_integer_get(struct snd_kcontrol *kctl,return pm.err;for (i =0 ; i < hwchan; i++) { -u16 buf; -s16 val; +s32 val;int ret; - ret =snd_audient_get_cur (mixer, ctype->unit, ctype->sel, - base + i, &buf,sizeof (buf)); + ret =snd_audient_raw_get_one (mixer, ctype, base + i, &val);if (ret <0 )return ret; - val =le16_to_cpu (buf); ctl_val->value.integer.value[i] = val; }
@@ -417,24 +462,15 @@ static int snd_ctl_audient_integer_set(struct snd_kcontrol *kctl,return pm.err;for (i =0 ; i < hwchan; i++) { -s16 rbuf; -s16 buf =cpu_to_le16 (ctl_val->value.integer.value[i]); +s32 val = ctl_val->value.integer.value[i];int ret; - ret =snd_audient_get_cur (mixer, ctype->unit, ctype->sel, - base + i, &rbuf,sizeof (rbuf)); + ret =snd_audient_raw_set_one (mixer, ctype, base + i, val);if (ret <0 )return ret; -if (rbuf != buf) { +if (ret) changed =1 ; - - ret =snd_audient_set_cur (mixer, ctype->unit, - ctype->sel, base + i, - &buf,sizeof (buf)); -if (ret <0 ) -return ret; - } }return changed;
Signature · 1 line
2.56.0
RFC PATCH 9/11 ALSA: mixer_audient: Add readback-free parameter set
In reply to Christian RuppertAdd a flag to systematically force parameter writing without prior readback to certain control types. In preparation of the id14 driver.
--- sound/usb/mixer_audient.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
sound/usb/mixer_audient.c +8 -3
@@ -37,6 +37,7 @@ static const DECLARE_TLV_DB_MINMAX_MUTE(snd_audient_tlv_mixer, -12800, 600);#define SND_AUDIENT_CTYPE_FLAGS_SIGNED (1L << 0)#define SND_AUDIENT_CTYPE_FLAGS_INIT_HW (1L << 1) +#define SND_AUDIENT_CTYPE_FLAGS_FORCE_SET (1L << 2) static const struct snd_audient_ctrl_type { snd_ctl_elem_type_t type;
@@ -313,9 +314,13 @@ static int snd_audient_raw_set_one(struct usb_mixer_interface *const mixer,int ret;u32 buf; - ret =snd_audient_raw_get_one (mixer, ctype, cidx, &buf); -if (ret <0 ) -return ret; +if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_FORCE_SET ) { + buf = !value;/* just make it different */ + }else { + ret =snd_audient_raw_get_one (mixer, ctype, cidx, &buf); +if (ret <0 ) +return ret; + }if (buf != value) { buf =cpu_to_le32 (value);
Signature · 1 line
2.56.0
Hi Christian,
Thanks for the RFC, and for splitting it into small patches. It made the review easy, and the cover letter answers my three questions.
I compiled mixer_audient.c after each patch with W=1, out of tree against a 7.2 kernel's headers: no warnings. checkpatch --strict gives only CHECK-level style notes. I can't test on an EVO, so the points below come from reading the code.
1. Patch 10, cache index
The cache has hwchannels entries, and the probe fills it by element index (cache[i]). But get, put and the INIT_HW write index it by device channel:
*value = cache[cidx]; /* cidx = val_offs + i */
cache[cidx] = value;
So a nonzero val_offs can access past the allocation. On the EVO4, "Mic 2 Capture Volume" (val_offs 2) uses cache[2] and cache[3] of a 2-entry array, and "Loopback Right Capture Volume" uses cache[10] and cache[11]. Those rows would also show other memory, not the value read at probe. On the iD14 the last matrix element would use cache[54] and cache[55].
Would indexing relative to the element fix it? The diff at the end of this mail passes the cache entry of channel i instead of the array, so that raw_get_one() and raw_set_one() never see cidx for the cache.
2. Probe-time USB errors now fail the whole card
With patch 10 the EVO matrix is read at probe, and with INIT_HW a control is written at probe. If one of those transfers fails, snd_audient_controls_create() returns the error, snd_usb_create_mixer() fails, and the card does not register. As far as I can see, QUIRK_FLAG_IGNORE_CTL_ERROR does not suppress errors returned by snd_usb_mixer_apply_create_quirk(). Before this series the quirk sent no USB traffic at probe, so this is new.
Could we keep the card registering after a failed probe transfer, while keeping the cache entry invalid until a transfer succeeds?
To save a round, I wrote it out; the diff is at the end of this mail, on top of your series. Please change or drop anything that doesn't fit your plans.
It gives each cache entry a valid flag, set when a transfer confirms the value (a read, or a write that succeeded). A failed probe transfer logs a warning and keeps the control with an invalid entry. For a cached write-only control, get still succeeds after a failed probe write, so that failure alone does not stop alsactl store: boolean and integer controls return their minimum, and my enum type reports "Unknown". A readable control retries the GET and returns an error if that retry fails. Since a get can now fill the cache, the callbacks take mixer->lock. Control allocation and registration errors still fail the probe. It contains the point 1 fix as well, since both change the same cache code.
On the iD14 I tested it with a test-only control that the device refuses (polarity on Digi 3). The card registered, the log showed one warning for that control, and get returned off. A put returned -EPIPE; a subsequent get still returned off.
3. Smaller points
- Patch 05: would sign_extend32(buf, 8 * ctype->len - 1) work in place of the shift pair?
- Patch 05: the buffers mix u32/s32 with cpu_to_le32()/le32_to_cpu(). Would __le32 buffers keep sparse quiet?
- Patch 05: the transfer buffer is 4 bytes on the stack, but nothing checks the table's len. Could snd_audient_add_ctrl() return -EINVAL unless 1 <= len <= 4?
- Patch 09: with FORCE_SET, a put of the cached value still writes (good) but also reports a change, so each alsactl restore sends a change event for every such control. Could it write but return 0 when the cache already holds the value?
- Patch 11: a device with no matrix list would dereference NULL in the loop. Would a check on info->matrix_names be worth adding?
- Patch 01: FYI, the file header still says "Audient EVO driver for ALSA".
4. iD14 tables on top
I built the iD14 tables on your series, with the cache fix applied. On an iD14 MkI they passed control read and write checks, the range checks and a loopback test of the matrix crosspoints. The crosspoints also kept their values across a module reload and were read back into the cache.
On top of your patches I needed three generic additions:
- a step size for integer types (res): the iD14 level controls use s16 in 1/256 dB; I expose them in whole-dB steps, matching the volume knob. The control counts steps from min, as the generic USB mixer does with the RANGE resolution;
- an enumerated type with a value list, plus one extra last item that a get shows for a device value outside the list;
- a per-device create hook, for the FU 12 control that does not fit the tables (in the same patch as that control).
The matrix uses your loop as it is: with 2 channels per element and the names in the order Mic 1 Main, Mic 1 Cue, Mic 2 Main, ..., element n starts at CN 2 * n, which is input * 4 + output on the iD14. Does that fit what you had in mind?
5. Next steps
Would you prefer to incorporate these changes in an RFC v2, or shall I fold them into the relevant patches when I carry your series, with notes in the commit messages?
Thanks,
Will
-- >8 --
From: Will Porter <[email protected]>
Subject: [RFC PATCH] ALSA: mixer_audient: Fix cache indexing and probe error handling
The cache has hwchannels entries, but get, put and the INIT_HW write indexed it with the device channel (val_offs + i). Pass the entry of element channel i instead.
A failed probe transfer made snd_audient_controls_create() fail, so the card did not register. Give each cache entry a valid flag, set when a transfer confirms the value: a read, or a write that succeeded. A failed probe transfer logs a warning and leaves the entry invalid. A readable control then reads the device on its next get, and returns an error if that read fails; a write-only (FORCE_SET) control shows its minimum until a put succeeds. CACHE | FORCE_SET without INIT_HW keeps the earlier behaviour: the init value is assumed, without a transfer.
A get can now fill the cache, and the control core runs gets in parallel, so the callbacks take mixer->lock around the transfers and the cache.
Control allocation and registration errors still fail the probe.
---
Proposed changes to patches 08 and 10.
sound/usb/mixer_audient.c +87 -28
@@ -210,6 +210,26 @@ static inline u16 snd_audient_kctl_channels(struct snd_kcontrol *kctl)return info->channels; } +/* +* A cached value is valid once a transfer confirmed it: a read, or a write +* that succeeded. A probe transfer that fails leaves it invalid. CACHE | +* FORCE_SET without INIT_HW keeps the earlier behaviour: the init value is +* assumed, without a transfer. +*/ +struct snd_audient_cache_entry { +u32 value; +bool valid; +}; + +/* Cache entry of element channel i, or NULL for an uncached control. */ +static inline struct snd_audient_cache_entry * +snd_audient_cache_slot (struct usb_mixer_elem_info *elem,unsigned int i) +{ +struct snd_audient_cache_entry *const cache = elem->private_data; + +return cache ? cache + i :NULL ; +} +#define AUDIENT_REQTYPE_SET (USB_DIR_OUT | USB_TYPE_CLASS \ | USB_RECIP_INTERFACE)
@@ -259,18 +279,25 @@ static inline int snd_audient_set_cur(struct usb_mixer_interface *mixer,static int snd_audient_raw_get_one (struct usb_mixer_interface *const mixer,const struct snd_audient_ctrl_type *const ctype, -const u32 *const cache, +struct snd_audient_cache_entry *const slot,const u8 cidx,u32 *const value) {int ret;s32 buf =0 ; -if (cache) { - *value = cache[cidx]; +if (slot && slot->valid) { + *value = slot->value;return ctype->len; } +/* +* Cached FORCE_SET controls are treated as write-only: an invalid +* cache entry does not trigger a GET. +*/ +if (slot && (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_FORCE_SET )) +return -ENODATA ; + ret =snd_audient_get_cur (mixer, ctype, cidx, &buf);if (ret <0 )return ret;
@@ -285,12 +312,18 @@ static int snd_audient_raw_get_one(struct usb_mixer_interface *const mixer, *value = buf; +if (slot) { + slot->value = buf; + slot->valid = true; + } +return ret; }static int snd_audient_raw_set_one (struct usb_mixer_interface *const mixer,const struct snd_audient_ctrl_type *const ctype, -u32 *const cache,const u8 cidx,const u32 value, +struct snd_audient_cache_entry *const slot, +const u8 cidx,const u32 value,bool force) {int ret;
@@ -299,7 +332,7 @@ static int snd_audient_raw_set_one(struct usb_mixer_interface *const mixer,if ((ctype->flags &SND_AUDIENT_CTYPE_FLAGS_FORCE_SET ) || force) { buf = !value;/* just make it different */ }else { - ret =snd_audient_raw_get_one (mixer, ctype, cache, cidx, &buf); + ret =snd_audient_raw_get_one (mixer, ctype, slot, cidx, &buf);if (ret <0 )return ret; }
@@ -310,8 +343,10 @@ static int snd_audient_raw_set_one(struct usb_mixer_interface *const mixer,if (ret <0 )return ret; -if (cache) - cache[cidx] = value; +if (slot) { + slot->value = value; + slot->valid = true; + }return 1 ; }
@@ -337,14 +372,18 @@ static int snd_ctl_audient_boolean_get(struct snd_kcontrol *kctl,CLASS (snd_usb_lock, pm)(mixer->chip);if (pm.err <0 )return pm.err; +/* serializes the transfers and the cache, also between gets */ +guard (mutex)(&mixer->lock);for (i =0 ; i < hwchan; i++) {u32 buf;int ret; - ret =snd_audient_raw_get_one (mixer, ctype, elem->private_data, + ret =snd_audient_raw_get_one (mixer, ctype,snd_audient_cache_slot (elem, i), base + i, &buf); -if (ret <0 ) +if (ret == -ENODATA )/* unknown write-only value: off */ + buf = ctype->min.integer; +else if (ret <0 )return ret; ctl_val->value.integer.value[i] = (buf == ctype->min.integer)
@@ -374,13 +413,15 @@ static int snd_ctl_audient_boolean_set(struct snd_kcontrol *kctl,CLASS (snd_usb_lock, pm)(mixer->chip);if (pm.err <0 )return pm.err; +/* serializes the transfers and the cache, also between gets */ +guard (mutex)(&mixer->lock);for (i =0 ; i < hwchan; i++) {u32 buf = ctl_val->value.integer.value[i] ? ctype->max.integer : ctype->min.integer;int ret; - ret =snd_audient_raw_set_one (mixer, ctype, elem->private_data, + ret =snd_audient_raw_set_one (mixer, ctype,snd_audient_cache_slot (elem, i), base + i, buf, false);if (ret <0 )return ret;
@@ -409,14 +450,18 @@ static int snd_ctl_audient_integer_get(struct snd_kcontrol *kctl,CLASS (snd_usb_lock, pm)(mixer->chip);if (pm.err <0 )return pm.err; +/* serializes the transfers and the cache, also between gets */ +guard (mutex)(&mixer->lock);for (i =0 ; i < hwchan; i++) {s32 val;int ret; - ret =snd_audient_raw_get_one (mixer, ctype, elem->private_data, + ret =snd_audient_raw_get_one (mixer, ctype,snd_audient_cache_slot (elem, i), base + i, &val); -if (ret <0 ) +if (ret == -ENODATA )/* unknown write-only value: minimum */ + val = ctype->min.integer; +else if (ret <0 )return ret;if (val < ctype->min.integer)
@@ -458,12 +503,14 @@ static int snd_ctl_audient_integer_set(struct snd_kcontrol *kctl,CLASS (snd_usb_lock, pm)(mixer->chip);if (pm.err <0 )return pm.err; +/* serializes the transfers and the cache, also between gets */ +guard (mutex)(&mixer->lock);for (i =0 ; i < hwchan; i++) {s32 val = ctl_val->value.integer.value[i];int ret; - ret =snd_audient_raw_set_one (mixer, ctype, elem->private_data, + ret =snd_audient_raw_set_one (mixer, ctype,snd_audient_cache_slot (elem, i), base + i, val, false);if (ret <0 )return ret;
@@ -534,7 +581,8 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer, elem =kzalloc (sizeof (*elem) + ((ctype->flags &SND_AUDIENT_CTYPE_FLAGS_CACHE ) - ? (sizeof (u32) * ctrl->hwchannels) + ? (sizeof (struct snd_audient_cache_entry ) + * ctrl->hwchannels) :0 ),GFP_KERNEL );if (!elem)
@@ -546,33 +594,44 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer,if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_CACHE ) elem->private_data = elem +1 ; +/* +* A failed probe transfer must not fail the card: warn and keep the +* control. Its cache entry stays invalid, so a readable control reads +* the device again on its next get, and a write-only control shows an +* unknown value until a put succeeds. +*/ if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_INIT_HW ) {int i;for (i =0 ; i < ctrl->hwchannels; i++) { ret =snd_audient_raw_set_one (mixer, ctype, - elem->private_data, +snd_audient_cache_slot (elem, i), ctrl->val_offs + i, ctype->init, true);if (ret <0 ) - goto free_elem; +usb_audio_warn (mixer->chip, +"%s: cannot set channel %d (%d)\n" , + ctrl->name, i, ret); } }else if (elem->private_data) { -u32 *const cache = elem->private_data; +struct snd_audient_cache_entry *const cache = elem->private_data;int i; -if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_FORCE_SET ) -for (i =0 ; i < ctrl->hwchannels; i++) - cache[i] = ctype->init; -else -for (i =0 ; i < ctrl->hwchannels; i++) { - ret =snd_audient_raw_get_one ( - mixer, ctype,NULL , - ctrl->val_offs + i, - cache + i); -if (ret <0 ) - goto free_elem; +for (i =0 ; i < ctrl->hwchannels; i++) { +if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_FORCE_SET ) { + cache[i].value = ctype->init; + cache[i].valid = true; +continue ; } + + ret =snd_audient_raw_get_one (mixer, ctype, cache + i, + ctrl->val_offs + i, + &cache[i].value); +if (ret <0 ) +usb_audio_warn (mixer->chip, +"%s: cannot read channel %d (%d)\n" , + ctrl->name, i, ret); + } } kctl =snd_ctl_new1 (&knew, elem);
RFC PATCH v2 1/11 ALSA: rename mixer_evo to mixer_audient
In reply to Christian RuppertRename mixer_evo files and functions to *_audient in preparation of a more generic driver for audient devices.
---
MAINTAINERS | 7 +-
sound/usb/Makefile | 2 +-
sound/usb/{mixer_evo.c => mixer_audient.c} | 249 +++++++++++----------
sound/usb/mixer_audient.h | 12 +
sound/usb/mixer_evo.h | 12 -
sound/usb/mixer_quirks.c | 4 +-
6 files changed, 148 insertions(+), 138 deletions(-)
rename sound/usb/{mixer_evo.c => mixer_audient.c} (54%)
create mode 100644 sound/usb/mixer_audient.h
delete mode 100644 sound/usb/mixer_evo.hMAINTAINERS +4 -3
@@ -4354,12 +4354,13 @@ F: drivers/net/ieee802154/at86rf230.h F: drivers/net/ieee802154/atusb.c F: drivers/net/ieee802154/atusb.h -AUDIENT EVO MIXER DRIVER +AUDIENT MIXER DRIVER M: Christian Ruppert <[email protected]> +M: Will Porter <[email protected]> L: [email protected] S: Maintained -F: sound/usb/mixer_evo.c -F: sound/usb/mixer_evo.h +F: sound/usb/mixer_audient.c +F: sound/usb/mixer_audient.h AUDIT SUBSYSTEM M: Paul Moore <[email protected]>
sound/usb/Makefile +1 -1
@@ -11,7 +11,7 @@ snd-usb-audio-y := card.o \ helper.o \ implicit.o \ mixer.o \ - mixer_evo.o \ + mixer_audient.o \ mixer_quirks.o \ mixer_scarlett.o \ mixer_scarlett2.o \
sound/usb/mixer_audient.c renamed from sound/usb/mixer_evo.c +129 -120
553 lines not on this page · raw message
sound/usb/mixer_audient.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __USB_MIXER_AUDIENT_H +#define __USB_MIXER_AUDIENT_H + +#include "mixer.h" + +#define USB_AUDIENT_VID (0x2708) +#define USB_EVO4_PID (0x0006) + +int snd_audient_controls_create (struct usb_mixer_interface *mixer); + +#endif /* __USB_MIXER_AUDIENT_H */
sound/usb/mixer_evo.h deleted +0 -12
@@ -1,12 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef __USB_MIXER_EVO_H -#define __USB_MIXER_EVO_H - -#include "mixer.h" - -#define USB_AUDIENT_VID (0x2708) -#define USB_EVO4_PID (0x0006) - -int snd_evo_controls_create (struct usb_mixer_interface *mixer); - -#endif /* __USB_MIXER_EVO_H */
sound/usb/mixer_quirks.c +2 -2
@@ -38,7 +38,7 @@#include "mixer_scarlett2.h" #include "mixer_us16x08.h" #include "mixer_s1810c.h" -#include "mixer_evo.h" +#include "mixer_audient.h" #include "helper.h" #include "fcp.h"
@@ -4541,7 +4541,7 @@ int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)break ;case USB_ID (USB_AUDIENT_VID ,USB_EVO4_PID ):/* Audient EVO 4 */ - err =snd_evo_controls_create (mixer); + err =snd_audient_controls_create (mixer);break ;case USB_ID (0x041e ,0x323b ):/* Creative Sound Blaster E1 */
Signature · 1 line
2.56.0
RFC PATCH v2 2/11 ALSA: mixer_audient: explicitly define full control names
In reply to Christian RuppertPreviously, control names were dynamically created depending if the control was an input or an output, a volume or a switch. Get rid of this logic by simply defining the full name in the control structure.
--- sound/usb/mixer_audient.c | 50 +++++++++++---------------------------- 1 file changed, 14 insertions(+), 36 deletions(-)
sound/usb/mixer_audient.c +14 -36
@@ -90,107 +90,92 @@ static const struct snd_audient_ctrl_type { }, }; -#define SND_AUDIENT_FLAGS_DIRECTION (1L<<0) -#define SND_AUDIENT_FLAGS_CAPTURE (1L<<0) -#define SND_AUDIENT_FLAGS_PLAYBACK (0L<<0)struct snd_audient_ctrl { -char *basename; +char *name;enum snd_audient_type type;unsigned int channels;unsigned int hwchannels;unsigned int val_offs; -unsigned long flags; };static const struct snd_audient_ctrl snd_audient_evo4_controls[] = { { - .basename ="Master" , + .name ="Master Playback Switch" , .type =SND_AUDIENT_TYPE_MUTE_OUT , .channels =1 , .hwchannels =1 , .val_offs =0 , - .flags =SND_AUDIENT_FLAGS_PLAYBACK , }, { - .basename ="Mic" , + .name ="Mic Playback Switch" , .type =SND_AUDIENT_TYPE_MUTE , .channels =4 , .hwchannels =2 , .val_offs =0 , - .flags =SND_AUDIENT_FLAGS_PLAYBACK , }, { - .basename ="Monitor" , + .name ="Monitor Playback Volume" , .type =SND_AUDIENT_TYPE_MONITOR , .channels =1 , .hwchannels =1 , .val_offs =0 , - .flags =SND_AUDIENT_FLAGS_PLAYBACK , }, { - .basename ="Mic 1" , + .name ="Mic 1 Capture Volume" , .type =SND_AUDIENT_TYPE_MIXER , .channels =2 , .hwchannels =2 , .val_offs =0 , - .flags =SND_AUDIENT_FLAGS_CAPTURE , }, { - .basename ="Mic 2" , + .name ="Mic 2 Capture Volume" , .type =SND_AUDIENT_TYPE_MIXER , .channels =2 , .hwchannels =2 , .val_offs =2 , - .flags =SND_AUDIENT_FLAGS_CAPTURE , }, { - .basename ="Master Left" , + .name ="Master Left Capture Volume" , .type =SND_AUDIENT_TYPE_MIXER , .channels =2 , .hwchannels =2 , .val_offs =4 , - .flags =SND_AUDIENT_FLAGS_CAPTURE , }, { - .basename ="Master Right" , + .name ="Master Right Capture Volume" , .type =SND_AUDIENT_TYPE_MIXER , .channels =2 , .hwchannels =2 , .val_offs =6 , - .flags =SND_AUDIENT_FLAGS_CAPTURE , }, { - .basename ="Loopback Left" , + .name ="Loopback Left Capture Volume" , .type =SND_AUDIENT_TYPE_MIXER , .channels =2 , .hwchannels =2 , .val_offs =8 , - .flags =SND_AUDIENT_FLAGS_CAPTURE , }, { - .basename ="Loopback Right" , + .name ="Loopback Right Capture Volume" , .type =SND_AUDIENT_TYPE_MIXER , .channels =2 , .hwchannels =2 , .val_offs =10 , - .flags =SND_AUDIENT_FLAGS_CAPTURE , }, { - .basename ="Mic 1 Phantom" , + .name ="Mic 1 Phantom Capture Switch" , .type =SND_AUDIENT_TYPE_PHANTOM , .channels =1 , .hwchannels =1 , .val_offs =0 , - .flags =SND_AUDIENT_FLAGS_CAPTURE , }, { - .basename ="Mic 2 Phantom" , + .name ="Mic 2 Phantom Capture Switch" , .type =SND_AUDIENT_TYPE_PHANTOM , .channels =1 , .hwchannels =1 , .val_offs =1 , - .flags =SND_AUDIENT_FLAGS_CAPTURE , }, {0 },/* sentinel */ };
@@ -458,13 +443,12 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer, {const struct snd_audient_ctrl_type *ctype = &snd_audient_ctypes[ctrl->type]; -char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN ];struct snd_kcontrol_new knew = {0 };struct snd_kcontrol *kctl;struct usb_mixer_elem_info *elem; knew.iface =SNDRV_CTL_ELEM_IFACE_MIXER ; - knew.name = name; + knew.name = ctrl->name; knew.info = snd_ctl_audient_info; knew.private_value =snd_audient_kctl_priv (ctrl->type, ctrl->val_offs, ctrl->hwchannels);
@@ -486,12 +470,6 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer,return -EINVAL ; } -snprintf (name,sizeof (name),"%s %s %s" , ctrl->basename, - ((ctrl->flags &SND_AUDIENT_FLAGS_DIRECTION ) - ==SND_AUDIENT_FLAGS_CAPTURE ) ?"Capture" :"Playback" , - (ctype->type ==SNDRV_CTL_ELEM_TYPE_BOOLEAN ) - ?"Switch" :"Volume" ); - elem =kzalloc_obj (*elem);if (!elem)return -ENOMEM ;
@@ -524,7 +502,7 @@ int snd_audient_controls_create(struct usb_mixer_interface *mixer)if (!info->controls)return -ENODEV ; -for (ctrl = info->controls; ctrl->basename; ctrl++) { +for (ctrl = info->controls; ctrl->name; ctrl++) {const int ret =snd_audient_add_ctrl (mixer, ctrl);if (ret <0 )
Signature · 1 line
2.56.0
RFC PATCH v2 3/11 ALSA: mixer_audient: clarify USB control message definition
In reply to Christian RuppertPreviously, base values for wIndex and wValue were directly given in the control type. Construct them from a unit ID and selector for clarity.
--- sound/usb/mixer_audient.c | 76 +++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 35 deletions(-)
sound/usb/mixer_audient.c +41 -35
@@ -45,15 +45,15 @@ static const struct snd_audient_ctrl_type {int integer; } max;const unsigned int *tlv; -u16 wValue; -u16 wIndex; +u8 unit; +u8 sel; } snd_audient_ctypes[SND_AUDIENT_TYPE_NCTYPES] = { [SND_AUDIENT_TYPE_MONITOR] = { .type = SNDRV_CTL_ELEM_TYPE_INTEGER, .min.integer = 0, .max.integer = 127, - .wValue = 0x0000, - .wIndex = 0x3800, + .unit = 0x38, + .sel = 0x00, /* no TLV here because we can't describe the cross-fader */ }, [SND_AUDIENT_TYPE_PHANTOM] = {
@@ -61,31 +61,31 @@ static const struct snd_audient_ctrl_type { .invert = false, .min.integer = 0, .max.integer = 1, - .wValue = 0x0000, - .wIndex = 0x3A00, + .unit = 0x3A, + .sel = 0x00, }, [SND_AUDIENT_TYPE_MUTE] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, .invert = true, .min.integer = 0, .max.integer = 1, - .wValue = 0x0200, - .wIndex = 0x3A00, + .unit = 0x3A, + .sel = 0x02, }, [SND_AUDIENT_TYPE_MUTE_OUT] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, .invert = true, .min.integer = 0, .max.integer = 1, - .wValue = 0x0100, - .wIndex = 0x3B00, + .unit = 0x3B, + .sel = 0x01, }, [SND_AUDIENT_TYPE_MIXER] = { .type = SNDRV_CTL_ELEM_TYPE_INTEGER, .min.integer = -128 * 256, .max.integer = 6 * 256, - .wValue = 0x0100, - .wIndex = 0x3C00, + .unit = 0x3C, + .sel = 0x01, .tlv = snd_audient_tlv_mixer, }, };
@@ -209,7 +209,7 @@ const struct snd_audient_ctrl_type *snd_audient_kctl_type(struct snd_kcontrolreturn &snd_audient_ctypes[kctl->private_value &0xFF ]; } -static __always_inline u16 snd_audient_kctl_valoffs(struct snd_kcontrol *kctl) +static __always_inline u16 snd_audient_kctl_cidxoffs(struct snd_kcontrol *kctl) {return (kctl->private_value >>8 ) &0xFF ; }
@@ -233,11 +233,16 @@ static inline u16 snd_audient_kctl_channels(struct snd_kcontrol *kctl)#define AUDIENT_REQTYPE_GET (USB_DIR_IN | USB_TYPE_CLASS \ | USB_RECIP_INTERFACE) +#define U8_U8 (HI ,LO ) ((((u16)(HI)) << 8) | ((LO) & 0xFF)) +static inline int snd_audient_get_cur (struct usb_mixer_interface *mixer, -u16 value,u16 index, -void *buf,size_t len) +const u8 unit,const u8 sel, +const u8 cidx, +void *const buf,const size_t len) {struct usb_device *const dev = mixer->chip->dev; +const u16 value =U8_U8 (sel, cidx); +const u16 index =U8_U8 (unit, mixer->hostif->desc.bInterfaceNumber); return snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_CUR, AUDIENT_REQTYPE_GET,
@@ -245,10 +250,13 @@ static inline int snd_audient_get_cur(struct usb_mixer_interface *mixer, }static inline int snd_audient_set_cur (struct usb_mixer_interface *mixer, -u16 value,u16 index, -void *buf,size_t len) +const u8 unit,const u8 sel, +const u8 cidx, +void *const buf,const size_t len) {struct usb_device *const dev = mixer->chip->dev; +const u16 value =U8_U8 (sel, cidx); +const u16 index =U8_U8 (unit, mixer->hostif->desc.bInterfaceNumber); return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC2_CS_CUR, AUDIENT_REQTYPE_SET,
@@ -266,8 +274,7 @@ static int snd_ctl_audient_boolean_get(struct snd_kcontrol *kctl,const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl);const struct snd_audient_ctrl_type *const ctype =snd_audient_kctl_type (kctl); -const u16 value = ctype->wValue +snd_audient_kctl_valoffs (kctl); -const u16 index = ctype->wIndex; +const u8 base =snd_audient_kctl_cidxoffs (kctl);int i;
@@ -279,8 +286,8 @@ static int snd_ctl_audient_boolean_get(struct snd_kcontrol *kctl,u32 buf;int ret; - ret =snd_audient_get_cur (mixer, value + i, index, - &buf,sizeof (buf)); + ret =snd_audient_get_cur (mixer, ctype->unit, ctype->sel, + base + i, &buf,sizeof (buf));if (ret <0 )return ret;
@@ -307,8 +314,7 @@ static int snd_ctl_audient_boolean_set(struct snd_kcontrol *kctl,const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl);const struct snd_audient_ctrl_type *const ctype =snd_audient_kctl_type (kctl); -const u16 value = ctype->wValue +snd_audient_kctl_valoffs (kctl); -const u16 index = ctype->wIndex; +const u8 base =snd_audient_kctl_cidxoffs (kctl);int changed =0 ;int i;
@@ -325,15 +331,16 @@ static int snd_ctl_audient_boolean_set(struct snd_kcontrol *kctl,if (ctype->invert) buf ^=cpu_to_le32 (0x1 ); - ret =snd_audient_get_cur (mixer, value + i, index, - &rbuf,sizeof (rbuf)); + ret =snd_audient_get_cur (mixer, ctype->unit, ctype->sel, + base + i, &rbuf,sizeof (rbuf));if (ret <0 )return ret;if (rbuf != buf) { changed =1 ; - ret =snd_audient_set_cur (mixer, value + i, index, + ret =snd_audient_set_cur (mixer, ctype->unit, + ctype->sel, base + i, &buf,sizeof (buf));if (ret <0 )return ret;
@@ -353,8 +360,7 @@ static int snd_ctl_audient_integer_get(struct snd_kcontrol *kctl,const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl);const struct snd_audient_ctrl_type *const ctype =snd_audient_kctl_type (kctl); -const u16 value = ctype->wValue +snd_audient_kctl_valoffs (kctl); -const u16 index = ctype->wIndex; +const u8 base =snd_audient_kctl_cidxoffs (kctl);int i;
@@ -367,8 +373,8 @@ static int snd_ctl_audient_integer_get(struct snd_kcontrol *kctl,s16 val;int ret; - ret =snd_audient_get_cur (mixer, value + i, index, - &buf,sizeof (buf)); + ret =snd_audient_get_cur (mixer, ctype->unit, ctype->sel, + base + i, &buf,sizeof (buf));if (ret <0 )return ret;
@@ -391,8 +397,7 @@ static int snd_ctl_audient_integer_set(struct snd_kcontrol *kctl,const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl);const struct snd_audient_ctrl_type *const ctype =snd_audient_kctl_type (kctl); -const u16 value = ctype->wValue +snd_audient_kctl_valoffs (kctl); -const u16 index = ctype->wIndex; +const u8 base =snd_audient_kctl_cidxoffs (kctl);int changed =0 ;int i;
@@ -406,15 +411,16 @@ static int snd_ctl_audient_integer_set(struct snd_kcontrol *kctl,s16 buf =cpu_to_le16 (ctl_val->value.integer.value[i]);int ret; - ret =snd_audient_get_cur (mixer, value + i, index, - &rbuf,sizeof (rbuf)); + ret =snd_audient_get_cur (mixer, ctype->unit, ctype->sel, + base + i, &rbuf,sizeof (rbuf));if (ret <0 )return ret;if (rbuf != buf) { changed =1 ; - ret =snd_audient_set_cur (mixer, value + i, index, + ret =snd_audient_set_cur (mixer, ctype->unit, + ctype->sel, base + i, &buf,sizeof (buf));if (ret <0 )return ret;
Signature · 1 line
2.56.0
RFC PATCH v2 4/11 ALSA: mixer_audient: Add length check to USB transfer
In reply to Christian RuppertCheck USB control transfers not only for errors but also for expected length and return -EIO in case of error.
--- sound/usb/mixer_audient.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
sound/usb/mixer_audient.c +16 -6
@@ -244,9 +244,14 @@ static inline int snd_audient_get_cur(struct usb_mixer_interface *mixer,const u16 value =U8_U8 (sel, cidx);const u16 index =U8_U8 (unit, mixer->hostif->desc.bInterfaceNumber); -return snd_usb_ctl_msg (dev,usb_rcvctrlpipe (dev,0 ), -UAC2_CS_CUR ,AUDIENT_REQTYPE_GET , - value, index, buf, len); +const int ret =snd_usb_ctl_msg (dev,usb_rcvctrlpipe (dev,0 ), +UAC2_CS_CUR ,AUDIENT_REQTYPE_GET , + value, index, buf, len); + +if ((ret >=0 ) && (ret != len)) +return -EIO ; + +return ret; } static inline int snd_audient_set_cur(struct usb_mixer_interface *mixer,
@@ -258,9 +263,14 @@ static inline int snd_audient_set_cur(struct usb_mixer_interface *mixer,const u16 value =U8_U8 (sel, cidx);const u16 index =U8_U8 (unit, mixer->hostif->desc.bInterfaceNumber); -return snd_usb_ctl_msg (dev,usb_sndctrlpipe (dev,0 ), -UAC2_CS_CUR ,AUDIENT_REQTYPE_SET , - value, index, buf, len); +const int ret =snd_usb_ctl_msg (dev,usb_sndctrlpipe (dev,0 ), +UAC2_CS_CUR ,AUDIENT_REQTYPE_SET , + value, index, buf, len); + +if ((ret >=0 ) && (ret != len)) +return -EIO ; + +return ret; }
Signature · 1 line
2.56.0
RFC PATCH v2 5/11 ALSA: mixer_audient: make USB control transfer size configurable
In reply to Christian RuppertPreviously, the USB transfer size was hardcoded in the datatype get/set functions. Make it configurable in the ctype structure in preparation of new control types for the id14.
--- sound/usb/mixer_audient.c | 131 ++++++++++++++++++++++++-------------- 1 file changed, 84 insertions(+), 47 deletions(-)
sound/usb/mixer_audient.c +84 -47
@@ -12,6 +12,8 @@#include <linux/usb.h> #include <linux/usb/audio-v2.h> #include <linux/slab.h> +#include <linux/types.h> +#include <linux/bitops.h> #include <sound/core.h> #include <sound/control.h> #include <sound/tlv.h>
@@ -35,8 +37,12 @@ enum snd_audient_type {/* Mixer matrix: -128dB (mute) to +6dB */ static const DECLARE_TLV_DB_MINMAX_MUTE(snd_audient_tlv_mixer, -12800, 600); +#define SND_AUDIENT_CTYPE_FLAGS_SIGNED BIT(0) + static const struct snd_audient_ctrl_type { snd_ctl_elem_type_t type; + unsigned long flags; + size_t len; /* datatype size, can be 1, 2 or 4 bytes */ bool invert; union { int integer;
@@ -50,6 +56,7 @@ static const struct snd_audient_ctrl_type { } snd_audient_ctypes[SND_AUDIENT_TYPE_NCTYPES] = { [SND_AUDIENT_TYPE_MONITOR] = { .type = SNDRV_CTL_ELEM_TYPE_INTEGER, + .len = 2, .min.integer = 0, .max.integer = 127, .unit = 0x38,
@@ -59,6 +66,7 @@ static const struct snd_audient_ctrl_type { [SND_AUDIENT_TYPE_PHANTOM] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, .invert = false, + .len = 4, .min.integer = 0, .max.integer = 1, .unit = 0x3A,
@@ -67,6 +75,7 @@ static const struct snd_audient_ctrl_type { [SND_AUDIENT_TYPE_MUTE] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, .invert = true, + .len = 4, .min.integer = 0, .max.integer = 1, .unit = 0x3A,
@@ -75,6 +84,7 @@ static const struct snd_audient_ctrl_type { [SND_AUDIENT_TYPE_MUTE_OUT] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, .invert = true, + .len = 4, .min.integer = 0, .max.integer = 1, .unit = 0x3B,
@@ -82,6 +92,8 @@ static const struct snd_audient_ctrl_type { }, [SND_AUDIENT_TYPE_MIXER] = { .type = SNDRV_CTL_ELEM_TYPE_INTEGER, + .flags = SND_AUDIENT_CTYPE_FLAGS_SIGNED, + .len = 2, .min.integer = -128 * 256, .max.integer = 6 * 256, .unit = 0x3C,
@@ -236,44 +248,91 @@ static inline u16 snd_audient_kctl_channels(struct snd_kcontrol *kctl)#define U8_U8 (HI ,LO ) ((((u16)(HI)) << 8) | ((LO) & 0xFF))static inline int snd_audient_get_cur (struct usb_mixer_interface *mixer, -const u8 unit,const u8 sel, -const u8 cidx, -void *const buf,const size_t len) +const struct snd_audient_ctrl_type *const ctype, +const u8 cidx,void *const buf) {struct usb_device *const dev = mixer->chip->dev; -const u16 value =U8_U8 (sel, cidx); -const u16 index =U8_U8 (unit, mixer->hostif->desc.bInterfaceNumber); +const u16 value =U8_U8 (ctype->sel, cidx); +const u16 index =U8_U8 (ctype->unit, + mixer->hostif->desc.bInterfaceNumber);const int ret =snd_usb_ctl_msg (dev,usb_rcvctrlpipe (dev,0 ),UAC2_CS_CUR ,AUDIENT_REQTYPE_GET , - value, index, buf, len); + value, index, buf, ctype->len); -if ((ret >=0 ) && (ret != len)) +if ((ret >=0 ) && (ret != ctype->len))return -EIO ;return ret; }static inline int snd_audient_set_cur (struct usb_mixer_interface *mixer, -const u8 unit,const u8 sel, -const u8 cidx, -void *const buf,const size_t len) +const struct snd_audient_ctrl_type *const ctype, +const u8 cidx,void *const buf) {struct usb_device *const dev = mixer->chip->dev; -const u16 value =U8_U8 (sel, cidx); -const u16 index =U8_U8 (unit, mixer->hostif->desc.bInterfaceNumber); +const u16 value =U8_U8 (ctype->sel, cidx); +const u16 index =U8_U8 (ctype->unit, + mixer->hostif->desc.bInterfaceNumber);const int ret =snd_usb_ctl_msg (dev,usb_sndctrlpipe (dev,0 ),UAC2_CS_CUR ,AUDIENT_REQTYPE_SET , - value, index, buf, len); + value, index, buf, ctype->len); -if ((ret >=0 ) && (ret != len)) +if ((ret >=0 ) && (ret != ctype->len))return -EIO ;return ret; } +static int snd_audient_raw_get_one (struct usb_mixer_interface *const mixer, +const struct snd_audient_ctrl_type *const ctype, +const u8 cidx,u32 *const value) +{ +int ret; +__le32 buf =0 ; +s32 val; + + ret =snd_audient_get_cur (mixer, ctype, cidx, &buf); +if (ret <0 ) +return ret; + + val =le32_to_cpu (buf); + +if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_SIGNED ) + val =sign_extend32 (val,8 * ctype->len -1 ); + + *value = val; + +return ret; +} + +static int snd_audient_raw_set_one (struct usb_mixer_interface *const mixer, +const struct snd_audient_ctrl_type *const ctype, +const u8 cidx,const u32 value) +{ +int ret; +u32 val; + + ret =snd_audient_raw_get_one (mixer, ctype, cidx, &val); +if (ret <0 ) +return ret; + +if (val != value) { +__le32 buf =cpu_to_le32 (value); + + ret =snd_audient_set_cur (mixer, ctype, cidx, &buf); +if (ret <0 ) +return ret; + +return 1 ; + } + +return 0 ; +} + +static int snd_ctl_audient_boolean_get (struct snd_kcontrol *kctl,struct snd_ctl_elem_value *ctl_val) {
@@ -296,12 +355,11 @@ static int snd_ctl_audient_boolean_get(struct snd_kcontrol *kctl,u32 buf;int ret; - ret =snd_audient_get_cur (mixer, ctype->unit, ctype->sel, - base + i, &buf,sizeof (buf)); + ret =snd_audient_raw_get_one (mixer, ctype, base + i, &buf);if (ret <0 )return ret; - ctl_val->value.integer.value[i] =le32_to_cpu (buf) ?1 :0 ; + ctl_val->value.integer.value[i] = buf ?1 :0 ;if (ctype->invert) ctl_val->value.integer.value[i] ^=0x1 ;
@@ -334,27 +392,18 @@ static int snd_ctl_audient_boolean_set(struct snd_kcontrol *kctl,return pm.err;for (i =0 ; i < hwchan; i++) { -u32 rbuf; -u32 buf =cpu_to_le32 (ctl_val->value.integer.value[i] ?1 :0 ); +u32 buf = ctl_val->value.integer.value[i] ?1 :0 ;int ret;if (ctype->invert) - buf ^=cpu_to_le32 (0x1 ); + buf ^=0x1 ; - ret =snd_audient_get_cur (mixer, ctype->unit, ctype->sel, - base + i, &rbuf,sizeof (rbuf)); + ret =snd_audient_raw_set_one (mixer, ctype, base + i, buf);if (ret <0 )return ret; -if (rbuf != buf) { +if (ret) changed =1 ; - - ret =snd_audient_set_cur (mixer, ctype->unit, - ctype->sel, base + i, - &buf,sizeof (buf)); -if (ret <0 ) -return ret; - } }return changed;
@@ -379,16 +428,13 @@ static int snd_ctl_audient_integer_get(struct snd_kcontrol *kctl,return pm.err;for (i =0 ; i < hwchan; i++) { -u16 buf; -s16 val; +s32 val;int ret; - ret =snd_audient_get_cur (mixer, ctype->unit, ctype->sel, - base + i, &buf,sizeof (buf)); + ret =snd_audient_raw_get_one (mixer, ctype, base + i, &val);if (ret <0 )return ret; - val =le16_to_cpu (buf); ctl_val->value.integer.value[i] = val; }
@@ -417,24 +463,15 @@ static int snd_ctl_audient_integer_set(struct snd_kcontrol *kctl,return pm.err;for (i =0 ; i < hwchan; i++) { -s16 rbuf; -s16 buf =cpu_to_le16 (ctl_val->value.integer.value[i]); +s32 val = ctl_val->value.integer.value[i];int ret; - ret =snd_audient_get_cur (mixer, ctype->unit, ctype->sel, - base + i, &rbuf,sizeof (rbuf)); + ret =snd_audient_raw_set_one (mixer, ctype, base + i, val);if (ret <0 )return ret; -if (rbuf != buf) { +if (ret) changed =1 ; - - ret =snd_audient_set_cur (mixer, ctype->unit, - ctype->sel, base + i, - &buf,sizeof (buf)); -if (ret <0 ) -return ret; - } }return changed;
Signature · 1 line
2.56.0
RFC PATCH v2 6/11 ALSA: mixer_audient: Allow arbitrary boolean control values
In reply to Christian RuppertIn preparation of id14 support, allow arbitrary values for true and false of boolean switches. This also rids us of the tedious invert flag.
--- sound/usb/mixer_audient.c | 43 ++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 23 deletions(-)
sound/usb/mixer_audient.c +20 -23
@@ -43,13 +43,12 @@ static const struct snd_audient_ctrl_type {snd_ctl_elem_type_t type;unsigned long flags;size_t len;/* datatype size, can be 1, 2 or 4 bytes */ -bool invert;union {int integer; - } min; + } min;/* for booleans holds physical int value for false */ union {int integer; - } max; + } max;/* for booleans holds physical int value for true */ const unsigned int *tlv;u8 unit;u8 sel;
@@ -65,7 +64,6 @@ static const struct snd_audient_ctrl_type { }, [SND_AUDIENT_TYPE_PHANTOM] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, - .invert = false, .len = 4, .min.integer = 0, .max.integer = 1,
@@ -74,19 +72,17 @@ static const struct snd_audient_ctrl_type { }, [SND_AUDIENT_TYPE_MUTE] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, - .invert = true, .len = 4, - .min.integer = 0, - .max.integer = 1, + .min.integer = 1, + .max.integer = 0, .unit = 0x3A, .sel = 0x02, }, [SND_AUDIENT_TYPE_MUTE_OUT] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, - .invert = true, .len = 4, - .min.integer = 0, - .max.integer = 1, + .min.integer = 1, + .max.integer = 0, .unit = 0x3B, .sel = 0x01, },
@@ -359,16 +355,12 @@ static int snd_ctl_audient_boolean_get(struct snd_kcontrol *kctl,if (ret <0 )return ret; - ctl_val->value.integer.value[i] = buf ?1 :0 ; - -if (ctype->invert) - ctl_val->value.integer.value[i] ^=0x1 ; + ctl_val->value.integer.value[i] = (buf == ctype->min.integer) + ? false : true; }for (; i < nchan; i++) - ctl_val->value.integer.value[i] = ctype->invert - ? ctype->max.integer - : ctype->min.integer; + ctl_val->value.integer.value[i] =0 ;return 0 ; }
@@ -392,12 +384,10 @@ static int snd_ctl_audient_boolean_set(struct snd_kcontrol *kctl,return pm.err;for (i =0 ; i < hwchan; i++) { -u32 buf = ctl_val->value.integer.value[i] ?1 :0 ; +u32 buf = ctl_val->value.integer.value[i] ? ctype->max.integer + : ctype->min.integer;int ret; -if (ctype->invert) - buf ^=0x1 ; - ret =snd_audient_raw_set_one (mixer, ctype, base + i, buf);if (ret <0 )return ret;
@@ -485,8 +475,15 @@ static int snd_ctl_audient_info(struct snd_kcontrol *kctl, uinfo->type = ctype->type; uinfo->count =snd_audient_kctl_channels (kctl); - uinfo->value.integer.min = ctype->min.integer; - uinfo->value.integer.max = ctype->max.integer; + +if (ctype->type ==SNDRV_CTL_ELEM_TYPE_BOOLEAN ) { + uinfo->value.integer.min =0 ; + uinfo->value.integer.max =1 ; + }else { + uinfo->value.integer.min = ctype->min.integer; + uinfo->value.integer.max = ctype->max.integer; + } +return 0 ; }
Signature · 1 line
2.56.0
[RFC V2 PATCH 00/11] Re: ALSA: usb-audio: Audient iD14 MkI vendor
In reply to Will PorterHi Will,
Quoted 8 lines · Will Porter
[...]
1. Patch 10, cache index
The cache has hwchannels entries, and the probe fills it by element index (cache[i]). But get, put and the
INIT_HWwrite index it by device channel:
[...]
Good catch and thanks for the fix, applied in RFC V2.
Quoted 9 lines
2. Probe-time USB errors now fail the whole card
[...]
Could we keep the card registering after a failed probe transfer, while keeping the cache entry invalid until a transfer succeeds?To save a round, I wrote it out; the diff is at the end of this mail, on top of your series. Please change or drop anything that doesn't fit your plans.
[...]
Fine with me, I suppose the question if individual reads should be allowed to fail during driver initialization is more philosophical in this case. I don't see any harm. Patch applied in RFC V2
Quoted 6 lines
3. Smaller points
- Patch 05: would
sign_extend32(buf, 8 * ctype->len - 1)work in place of the shift pair?
- Patch 05: the buffers mix u32/s32 with cpu_to_le32()/le32_to_cpu(). Would__le32buffers keep sparse quiet?
OK, these make the code a bit cleaner, added to RFC V2.
Quoted 3 lines
- Patch 05: the transfer buffer is 4 bytes on the stack, but nothing checks the table's len. Could
snd_audient_add_ctrl()return-EINVALunless 1 <= len <= 4?
I don't think this is necessary as it should be rather obvious to everyone touching the driver that the u32 argument can't carry more than 4 bytes. Added a comment to the parameter definition.
Quoted 4 lines
- Patch 09: with
FORCE_SET, a put of the cached value still writes (good) but also reports a change, so each alsactl restore sends a change event for every such control. Could it write but return 0 when the cache already holds the value?
Makes sense. Added to RFC V2 (in patch 10 where the cache is added). Please double-check if the logic reflects what you had in mind.
Quoted 2 lines
- Patch 11: a device with no matrix list would dereference NULL in the loop. Would a check on
info->matrix_namesbe worth adding?
Makes sense although this could also be held off until somebody actually adds such a device. Added to RFC V2.
Quoted 2 lines
- Patch 01: FYI, the file header still says "Audient EVO driver for ALSA".
Fixed in RFC V2.
Quoted 19 lines
4. iD14 tables on top
I built the iD14 tables on your series, with the cache fix applied. On an iD14 MkI they passed control read and write checks, the range checks and a loopback test of the matrix crosspoints. The crosspoints also kept their values across a module reload and were read back into the cache.
On top of your patches I needed three generic additions:
- a step size for integer types (res): the iD14 level controls use s16 in 1/256 dB; I expose them in whole-dB steps, matching the volume knob. The control counts steps from min, as the generic USB mixer does with the RANGE resolution;
- an enumerated type with a value list, plus one extra last item that a get shows for a device value outside the list;
- a per-device create hook, for the FU 12 control that does not fit the tables (in the same patch as that control).
Quoted 4 lines
The matrix uses your loop as it is: with 2 channels per element and the names in the order Mic 1 Main, Mic 1 Cue, Mic 2 Main, ..., element n starts at CN 2 * n, which is input * 4 + output on the iD14. Does that fit what you had in mind?
Yep, sounds good.
Quoted 5 lines
5. Next steps
Would you prefer to incorporate these changes in an RFC v2, or shall I fold them into the relevant patches when I carry your series, with notes in the commit messages?
I created RFC V2 with your patch and the fixes you suggested. This will make things easier to review when we submit the everything, compared to fixes on top of a long series of patches.
Based on the same commit as before and retested on 7.3.1.
Christian
Christian Ruppert (11):
ALSA: rename mixer_evo to mixer_audient
ALSA: mixer_audient: explicitly define full control names
ALSA: mixer_audient: clarify USB control message definition
ALSA: mixer_audient: Add length check to USB transfer
ALSA: mixer_audient: make USB control transfer size configurable
ALSA: mixer_audient: Allow arbitrary boolean control values
ALSA: mixer_audient: Add integer range checks
ALSA: mixer_audient: Add control initialization at probe
ALSA: mixer_audient: Add readback-free parameter set
ALSA: mixer_audient: add control value caching
ALSA: mixer_audient: Create matrix programmatically
MAINTAINERS | 7 +- sound/usb/Makefile | 2 +- sound/usb/mixer_audient.c | 702 ++++++++++++++++++++++++++++++++++++++ sound/usb/mixer_audient.h | 12 + sound/usb/mixer_evo.c | 526 ---------------------------- sound/usb/mixer_evo.h | 12 - sound/usb/mixer_quirks.c | 4 +- 7 files changed, 721 insertions(+), 544 deletions(-) create mode 100644 sound/usb/mixer_audient.c create mode 100644 sound/usb/mixer_audient.h delete mode 100644 sound/usb/mixer_evo.c delete mode 100644 sound/usb/mixer_evo.h
Signature · 1 line
2.56.0
RFC PATCH v2 7/11 ALSA: mixer_audient: Add integer range checks
Add range checks to integer parameters to improve error management:
- Reject out-of-range write attempts with -EINVAL
- Prune out-of-range values returned by the device to the range limits
--- sound/usb/mixer_audient.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
sound/usb/mixer_audient.c +15 -2
@@ -44,10 +44,10 @@ static const struct snd_audient_ctrl_type {unsigned long flags;size_t len;/* datatype size, can be 1, 2 or 4 bytes */ union { -int integer; +long integer; } min;/* for booleans holds physical int value for false */ union { -int integer; +long integer; } max;/* for booleans holds physical int value for true */ const unsigned int *tlv;u8 unit;
@@ -425,6 +425,12 @@ static int snd_ctl_audient_integer_get(struct snd_kcontrol *kctl,if (ret <0 )return ret; +if (val < ctype->min.integer) + val = ctype->min.integer; + +if (val > ctype->max.integer) + val = ctype->max.integer; + ctl_val->value.integer.value[i] = val; }
@@ -448,6 +454,13 @@ static int snd_ctl_audient_integer_set(struct snd_kcontrol *kctl,int changed =0 ;int i; +for (i =0 ; i < hwchan; i++) { +long val = ctl_val->value.integer.value[i]; + +if ((val < ctype->min.integer) || (val > ctype->max.integer)) +return -EINVAL ; + } +CLASS (snd_usb_lock, pm)(mixer->chip);if (pm.err <0 )return pm.err;
Signature · 1 line
2.56.0
RFC PATCH v2 9/11 ALSA: mixer_audient: Add readback-free parameter set
In reply to Christian RuppertAdd a flag to systematically force parameter writing without prior readback to certain control types. In preparation of the id14 driver.
--- sound/usb/mixer_audient.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
sound/usb/mixer_audient.c +8 -3
@@ -39,6 +39,7 @@ static const DECLARE_TLV_DB_MINMAX_MUTE(snd_audient_tlv_mixer, -12800, 600);#define SND_AUDIENT_CTYPE_FLAGS_SIGNED BIT(0)#define SND_AUDIENT_CTYPE_FLAGS_INIT_HW BIT(1) +#define SND_AUDIENT_CTYPE_FLAGS_FORCE_SET BIT(2) static const struct snd_audient_ctrl_type { snd_ctl_elem_type_t type;
@@ -313,9 +314,13 @@ static int snd_audient_raw_set_one(struct usb_mixer_interface *const mixer,int ret;u32 val; - ret =snd_audient_raw_get_one (mixer, ctype, cidx, &val); -if (ret <0 ) -return ret; +if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_FORCE_SET ) { + val = !value;/* just make it different */ + }else { + ret =snd_audient_raw_get_one (mixer, ctype, cidx, &val); +if (ret <0 ) +return ret; + }if (val != value) {__le32 buf =cpu_to_le32 (value);
Signature · 1 line
2.56.0
RFC PATCH v2 8/11 ALSA: mixer_audient: Add control initialization at probe
In reply to Christian RuppertAdd the possibility to initialize certain control types to known values at probe time. This is particularly useful for controls which initially read wrong values and for controls which cannot be read at all.
--- sound/usb/mixer_audient.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
sound/usb/mixer_audient.c +16 -0
@@ -38,6 +38,7 @@ enum snd_audient_type { static const DECLARE_TLV_DB_MINMAX_MUTE(snd_audient_tlv_mixer, -12800, 600);#define SND_AUDIENT_CTYPE_FLAGS_SIGNED BIT(0) +#define SND_AUDIENT_CTYPE_FLAGS_INIT_HW BIT(1) static const struct snd_audient_ctrl_type { snd_ctl_elem_type_t type;
@@ -49,6 +50,7 @@ static const struct snd_audient_ctrl_type {union {long integer; } max;/* for booleans holds physical int value for true */ +u32 init;const unsigned int *tlv;u8 unit;u8 sel;
@@ -533,6 +535,20 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer,return -EINVAL ; } +if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_INIT_HW ) { +int i; + +for (i =0 ; i < ctrl->hwchannels; i++) { +int ret =snd_audient_raw_set_one (mixer, ctype, + ctrl->val_offs + i, + ctype->init); +if (ret <0 ) +usb_audio_warn (mixer->chip, +"%s: cannot set channel %d (%d)\n" , + ctrl->name, i, ret); + } + } + elem =kzalloc_obj (*elem);if (!elem)return -ENOMEM ;
Signature · 1 line
2.56.0
RFC PATCH v2 11/11 ALSA: mixer_audient: Create matrix programmatically
In reply to Christian RuppertMost Audient devices seem to have a similar mixer matrix with many identical channels. The only difference between devices seems to be the matrix' dimension. Create it programmatically in a loop rather than from the controls table.
--- sound/usb/mixer_audient.c | 77 +++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 43 deletions(-)
sound/usb/mixer_audient.c +34 -43
@@ -105,7 +105,7 @@ static const struct snd_audient_ctrl_type {struct snd_audient_ctrl { -char *name; +const char *const name;enum snd_audient_type type;unsigned int channels;unsigned int hwchannels;
@@ -134,48 +134,6 @@ static const struct snd_audient_ctrl snd_audient_evo4_controls[] = { .hwchannels = 1, .val_offs = 0, }, - { - .name = "Mic 1 Capture Volume", - .type = SND_AUDIENT_TYPE_MIXER, - .channels = 2, - .hwchannels = 2, - .val_offs = 0, - }, - { - .name = "Mic 2 Capture Volume", - .type = SND_AUDIENT_TYPE_MIXER, - .channels = 2, - .hwchannels = 2, - .val_offs = 2, - }, - { - .name = "Master Left Capture Volume", - .type = SND_AUDIENT_TYPE_MIXER, - .channels = 2, - .hwchannels = 2, - .val_offs = 4, - }, - { - .name = "Master Right Capture Volume", - .type = SND_AUDIENT_TYPE_MIXER, - .channels = 2, - .hwchannels = 2, - .val_offs = 6, - }, - { - .name = "Loopback Left Capture Volume", - .type = SND_AUDIENT_TYPE_MIXER, - .channels = 2, - .hwchannels = 2, - .val_offs = 8, - }, - { - .name = "Loopback Right Capture Volume", - .type = SND_AUDIENT_TYPE_MIXER, - .channels = 2, - .hwchannels = 2, - .val_offs = 10, - }, { .name = "Mic 1 Phantom Capture Switch", .type = SND_AUDIENT_TYPE_PHANTOM,
@@ -193,13 +151,27 @@ static const struct snd_audient_ctrl snd_audient_evo4_controls[] = { { 0 }, /* sentinel */ }; +static const char *const snd_audient_evo4_matrix[] = { +"Mic 1 Capture Volume" , +"Mic 2 Capture Volume" , +"Master Left Capture Volume" , +"Master Right Capture Volume" , +"Loopback Left Capture Volume" , +"Loopback Right Capture Volume" , +NULL +}; +static const struct audient_devinfo {u32 usb_id;const struct snd_audient_ctrl *controls; +const char *const *const matrix_names; +const unsigned int matrix_channels; } audient_devinfo[] = { { .usb_id =USB_ID (USB_AUDIENT_VID ,USB_EVO4_PID ), .controls = snd_audient_evo4_controls, + .matrix_names = snd_audient_evo4_matrix, + .matrix_channels =2 , }, {0 }/* sentinel */ };
@@ -693,6 +665,8 @@ int snd_audient_controls_create(struct usb_mixer_interface *mixer)const struct audient_devinfo *info;const struct snd_audient_ctrl *ctrl; +int i; +for (info = audient_devinfo; info->controls; info++)if (info->usb_id == mixer->chip->usb_id)break ;
@@ -707,5 +681,22 @@ int snd_audient_controls_create(struct usb_mixer_interface *mixer)return ret; } +if (info->matrix_names) { +for (i =0 ; info->matrix_names[i]; i++) { +const struct snd_audient_ctrl c = { + .name = info->matrix_names[i], + .type =SND_AUDIENT_TYPE_MIXER , + .channels = info->matrix_channels, + .hwchannels = info->matrix_channels, + .val_offs = i * info->matrix_channels, + }; + +const int ret =snd_audient_add_ctrl (mixer, &c); + +if (ret <0 ) +return ret; + } + } +return 0 ; }
Signature · 1 line
2.56.0
RFC PATCH v2 10/11 ALSA: mixer_audient: add control value caching
In reply to Christian RuppertIn preparation of id14 support, add control value caching.
--- sound/usb/mixer_audient.c | 186 ++++++++++++++++++++++++++++++-------- 1 file changed, 150 insertions(+), 36 deletions(-)
sound/usb/mixer_audient.c +150 -36
@@ -40,6 +40,7 @@ static const DECLARE_TLV_DB_MINMAX_MUTE(snd_audient_tlv_mixer, -12800, 600);#define SND_AUDIENT_CTYPE_FLAGS_SIGNED BIT(0)#define SND_AUDIENT_CTYPE_FLAGS_INIT_HW BIT(1)#define SND_AUDIENT_CTYPE_FLAGS_FORCE_SET BIT(2) +#define SND_AUDIENT_CTYPE_FLAGS_CACHE BIT(3) static const struct snd_audient_ctrl_type { snd_ctl_elem_type_t type;
@@ -51,7 +52,7 @@ static const struct snd_audient_ctrl_type {union {long integer; } max;/* for booleans holds physical int value for true */ -u32 init; +u32 init;/* hardware and cache are initialized to this value */ const unsigned int *tlv;u8 unit;u8 sel;
@@ -91,7 +92,8 @@ static const struct snd_audient_ctrl_type { }, [SND_AUDIENT_TYPE_MIXER] = { .type = SNDRV_CTL_ELEM_TYPE_INTEGER, - .flags = SND_AUDIENT_CTYPE_FLAGS_SIGNED, + .flags =SND_AUDIENT_CTYPE_FLAGS_SIGNED + | SND_AUDIENT_CTYPE_FLAGS_CACHE, .len = 2, .min.integer = -128 * 256, .max.integer = 6 * 256,
@@ -238,6 +240,26 @@ static inline u16 snd_audient_kctl_channels(struct snd_kcontrol *kctl)return info->channels; } +/* +* A cached value is valid once a transfer confirmed it: a read, or a write +* that succeeded. A probe transfer that fails leaves it invalid. CACHE | +* FORCE_SET without INIT_HW keeps the earlier behaviour: the init value is +* assumed, without a transfer. +*/ +struct snd_audient_cache_entry { +u32 value; +bool valid; +}; + +/* Cache entry of element channel i, or NULL for an uncached control. */ +static inline struct snd_audient_cache_entry * +snd_audient_cache_slot (struct usb_mixer_elem_info *elem,unsigned int i) +{ +struct snd_audient_cache_entry *const cache = elem->private_data; + +return cache ? cache + i :NULL ; +} +#define AUDIENT_REQTYPE_SET (USB_DIR_OUT | USB_TYPE_CLASS \ | USB_RECIP_INTERFACE)
@@ -287,12 +309,26 @@ static inline int snd_audient_set_cur(struct usb_mixer_interface *mixer,static int snd_audient_raw_get_one (struct usb_mixer_interface *const mixer,const struct snd_audient_ctrl_type *const ctype, +struct snd_audient_cache_entry *const slot,const u8 cidx,u32 *const value) {int ret;__le32 buf =0 ;s32 val; +if (slot && slot->valid) { + *value = slot->value; + +return ctype->len; + } + +/* +* Cached FORCE_SET controls are treated as write-only: an invalid +* cache entry does not trigger a GET. +*/ +if (slot && (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_FORCE_SET )) +return -ENODATA ; + ret =snd_audient_get_cur (mixer, ctype, cidx, &buf);if (ret <0 )return ret;
@@ -304,43 +340,58 @@ static int snd_audient_raw_get_one(struct usb_mixer_interface *const mixer, *value = val; +if (slot) { + slot->value = val; + slot->valid = true; + } +return ret; }static int snd_audient_raw_set_one (struct usb_mixer_interface *const mixer,const struct snd_audient_ctrl_type *const ctype, -const u8 cidx,const u32 value) +struct snd_audient_cache_entry *const slot, +const u8 cidx,const u32 value, +bool force) {int ret;u32 val; -if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_FORCE_SET ) { +if (force) { val = !value;/* just make it different */ }else { - ret =snd_audient_raw_get_one (mixer, ctype, cidx, &val); -if (ret <0 ) + ret =snd_audient_raw_get_one (mixer, ctype, slot, cidx, &val); +if (ret == -ENODATA )/* FORCED_SET and not cached yet */ + val = !value;/* just make it different */ +else if (ret <0 )return ret; } -if (val != value) { + force = force || (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_FORCE_SET ); + +if (force || (val != value)) {__le32 buf =cpu_to_le32 (value); ret =snd_audient_set_cur (mixer, ctype, cidx, &buf);if (ret <0 )return ret; -return 1 ; +if (slot) { + slot->value = value; + slot->valid = true; + } + } -return 0 ; +return val != value; }static int snd_ctl_audient_boolean_get (struct snd_kcontrol *kctl,struct snd_ctl_elem_value *ctl_val) { -struct usb_mixer_elem_list *const list =snd_kcontrol_chip (kctl); -struct usb_mixer_interface *const mixer = list->mixer; +struct usb_mixer_elem_info *const elem =snd_kcontrol_chip (kctl); +struct usb_mixer_interface *const mixer = elem->head.mixer;const unsigned int nchan =snd_audient_kctl_channels (kctl);const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl);
@@ -353,13 +404,19 @@ static int snd_ctl_audient_boolean_get(struct snd_kcontrol *kctl,CLASS (snd_usb_lock, pm)(mixer->chip);if (pm.err <0 )return pm.err; +/* serializes the transfers and the cache, also between gets */ +guard (mutex)(&mixer->lock);for (i =0 ; i < hwchan; i++) {u32 buf;int ret; - ret =snd_audient_raw_get_one (mixer, ctype, base + i, &buf); -if (ret <0 ) + ret =snd_audient_raw_get_one (mixer, ctype, +snd_audient_cache_slot (elem, i), + base + i, &buf); +if (ret == -ENODATA )/* unknown write-only value: off */ + buf = ctype->min.integer; +else if (ret <0 )return ret; ctl_val->value.integer.value[i] = (buf == ctype->min.integer)
@@ -375,8 +432,8 @@ static int snd_ctl_audient_boolean_get(struct snd_kcontrol *kctl,static int snd_ctl_audient_boolean_set (struct snd_kcontrol *kctl,struct snd_ctl_elem_value *ctl_val) { -struct usb_mixer_elem_list *list =snd_kcontrol_chip (kctl); -struct usb_mixer_interface *mixer = list->mixer; +struct usb_mixer_elem_info *const elem =snd_kcontrol_chip (kctl); +struct usb_mixer_interface *const mixer = elem->head.mixer;const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl);const struct snd_audient_ctrl_type *const ctype
@@ -389,13 +446,17 @@ static int snd_ctl_audient_boolean_set(struct snd_kcontrol *kctl,CLASS (snd_usb_lock, pm)(mixer->chip);if (pm.err <0 )return pm.err; +/* serializes the transfers and the cache, also between gets */ +guard (mutex)(&mixer->lock);for (i =0 ; i < hwchan; i++) {u32 buf = ctl_val->value.integer.value[i] ? ctype->max.integer : ctype->min.integer;int ret; - ret =snd_audient_raw_set_one (mixer, ctype, base + i, buf); + ret =snd_audient_raw_set_one (mixer, ctype, +snd_audient_cache_slot (elem, i), + base + i, buf, false);if (ret <0 )return ret;
@@ -409,8 +470,8 @@ static int snd_ctl_audient_boolean_set(struct snd_kcontrol *kctl,static int snd_ctl_audient_integer_get (struct snd_kcontrol *kctl,struct snd_ctl_elem_value *ctl_val) { -struct usb_mixer_elem_list *const list =snd_kcontrol_chip (kctl); -struct usb_mixer_interface *const mixer = list->mixer; +struct usb_mixer_elem_info *const elem =snd_kcontrol_chip (kctl); +struct usb_mixer_interface *const mixer = elem->head.mixer;const unsigned int nchan =snd_audient_kctl_channels (kctl);const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl);
@@ -423,13 +484,19 @@ static int snd_ctl_audient_integer_get(struct snd_kcontrol *kctl,CLASS (snd_usb_lock, pm)(mixer->chip);if (pm.err <0 )return pm.err; +/* serializes the transfers and the cache, also between gets */ +guard (mutex)(&mixer->lock);for (i =0 ; i < hwchan; i++) {s32 val;int ret; - ret =snd_audient_raw_get_one (mixer, ctype, base + i, &val); -if (ret <0 ) + ret =snd_audient_raw_get_one (mixer, ctype, +snd_audient_cache_slot (elem, i), + base + i, &val); +if (ret == -ENODATA )/* unknown write-only value: minimum */ + val = ctype->min.integer; +else if (ret <0 )return ret;if (val < ctype->min.integer)
@@ -450,8 +517,8 @@ static int snd_ctl_audient_integer_get(struct snd_kcontrol *kctl,static int snd_ctl_audient_integer_set (struct snd_kcontrol *kctl,struct snd_ctl_elem_value *ctl_val) { -struct usb_mixer_elem_list *list =snd_kcontrol_chip (kctl); -struct usb_mixer_interface *mixer = list->mixer; +struct usb_mixer_elem_info *const elem =snd_kcontrol_chip (kctl); +struct usb_mixer_interface *mixer = elem->head.mixer;const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl);const struct snd_audient_ctrl_type *const ctype
@@ -471,12 +538,16 @@ static int snd_ctl_audient_integer_set(struct snd_kcontrol *kctl,CLASS (snd_usb_lock, pm)(mixer->chip);if (pm.err <0 )return pm.err; +/* serializes the transfers and the cache, also between gets */ +guard (mutex)(&mixer->lock);for (i =0 ; i < hwchan; i++) {s32 val = ctl_val->value.integer.value[i];int ret; - ret =snd_audient_raw_set_one (mixer, ctype, base + i, val); + ret =snd_audient_raw_set_one (mixer, ctype, +snd_audient_cache_slot (elem, i), + base + i, val, false);if (ret <0 )return ret;
@@ -517,6 +588,8 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer,struct snd_kcontrol *kctl;struct usb_mixer_elem_info *elem; +int ret; + knew.iface =SNDRV_CTL_ELEM_IFACE_MIXER ; knew.name = ctrl->name; knew.info = snd_ctl_audient_info;
@@ -524,7 +597,9 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer, ctrl->hwchannels); knew.tlv.p = ctype->tlv; knew.access =SNDRV_CTL_ELEM_ACCESS_READWRITE - |SNDRV_CTL_ELEM_ACCESS_VOLATILE + | ((ctype->flags &SND_AUDIENT_CTYPE_FLAGS_CACHE ) + ?0 + :SNDRV_CTL_ELEM_ACCESS_VOLATILE ) | (ctype->tlv ?SNDRV_CTL_ELEM_ACCESS_TLV_READ :0 );switch (ctype->type) {
@@ -540,36 +615,75 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer,return -EINVAL ; } + elem =kzalloc (sizeof (*elem) + + ((ctype->flags &SND_AUDIENT_CTYPE_FLAGS_CACHE ) + ? (sizeof (struct snd_audient_cache_entry ) + * ctrl->hwchannels) + :0 ), +GFP_KERNEL ); +if (!elem) +return -ENOMEM ; + + elem->head.mixer = mixer; + elem->channels = ctrl->channels; + +if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_CACHE ) + elem->private_data = elem +1 ; + +/* +* A failed probe transfer must not fail the card: warn and keep the +* control. Its cache entry stays invalid, so a readable control reads +* the device again on its next get, and a write-only control shows an +* unknown value until a put succeeds. +*/ if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_INIT_HW ) {int i;for (i =0 ; i < ctrl->hwchannels; i++) { -int ret =snd_audient_raw_set_one (mixer, ctype, - ctrl->val_offs + i, - ctype->init); + ret =snd_audient_raw_set_one (mixer, ctype, +snd_audient_cache_slot (elem, i), + ctrl->val_offs + i, + ctype->init, true);if (ret <0 )usb_audio_warn (mixer->chip,"%s: cannot set channel %d (%d)\n" , ctrl->name, i, ret); } - } - - elem =kzalloc_obj (*elem); -if (!elem) -return -ENOMEM ; + }else if (elem->private_data) { +struct snd_audient_cache_entry *const cache = elem->private_data; +int i; - elem->head.mixer = mixer; - elem->channels = ctrl->channels; +for (i =0 ; i < ctrl->hwchannels; i++) { +if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_FORCE_SET ) { + cache[i].value = ctype->init; + cache[i].valid = true; +continue ; + } + + ret =snd_audient_raw_get_one (mixer, ctype, cache + i, + ctrl->val_offs + i, + &cache[i].value); +if (ret <0 ) +usb_audio_warn (mixer->chip, +"%s: cannot read channel %d (%d)\n" , + ctrl->name, i, ret); + } + } kctl =snd_ctl_new1 (&knew, elem);if (!kctl) { -kfree (elem); -return -ENOMEM ; + ret = -ENOMEM ; + goto free_elem; } kctl->private_free = snd_usb_mixer_elem_free;return snd_usb_mixer_add_control (&elem->head, kctl); + +free_elem: +kfree (elem); + +return ret; }
Signature · 1 line
2.56.0
Re: [RFC V2 PATCH 00/11] Re: ALSA: usb-audio: Audient iD14 MkI vendor
In reply to Christian RuppertHi Christian,
Thanks for RFC V2, and for folding everything in so quickly.
Quoted 2 lines · Christian Ruppert
Makes sense. Added to RFC V2 (in patch 10 where the cache is added). Please double-check if the logic reflects what you had in mind.
Yes, that is what I had in mind: a put of the cached value still writes it, but returns 0, so alsactl restore sends no change events. On an iD14 MkI, a put of the held value sent no change event on a write-only switch, a volume or a matrix control. A put of a new value on the write-only switch sent one.
One question on the same function. A FORCE_SET control without CACHE now reads the device before each write; in RFC v1 the put skipped that read. If the device refuses the read, the put fails before it writes. No table uses FORCE_SET without CACHE today, so nothing breaks now.
Should that combination work? If yes, the put could skip the read when the control has no cache slot, as the diff below does. If not, a comment or a check in snd_audient_add_ctrl() would say so, and you can drop the diff.
Quoted 3 lines
I don't think this is necessary as it should be rather obvious to everyone touching the driver that the u32 argument can't carry more than 4 bytes. Added a comment to the parameter definition.
Fine with me.
checkpatch --strict on the 11 patches gives no errors or warnings, only CHECK-level style notes, mostly unneeded parentheses (04, 05, 07, 10) and alignment (01, 05). I'll leave those to your discretion.
iD14 patches on RFC V2
I rebased my iD14 patch series on RFC V2. Three of my patches are now part of yours, so seven remain:
1. a step size for integer controls
2. enumerated controls
3. a separate mixer map for the iD14 MkI
4. iD14 MkI monitor and routing controls
5. iD14 MkI mixer matrix
6. iD14 MkI write-only controls
7. the iD14 MkI FU 12 control
All 18 patches build one by one with W=1 without warnings. On an iD14 MkI (7.2.11 stable), the controls passed the same read and write checks as on RFC v1.
Next steps
As agreed, I'll send the final series: your 11 patches, then the seven iD14 patches. Two questions first:
- Your four mixer_evo fixes ("ALSA: mixer_evo: minor fixes and tlv addition") are still open on Patchwork. Should they still go in separately, before this series? Then I'd base the final series on sound for-next once Takashi applies them. Or should I put them at the front of the final series?
- If the diff below looks right to you, shall I fold it into patch 10 when I send, or would you prefer to take it into your own tree first?
Thanks,
Will
-- >8 --
From: Will Porter <[email protected]>
Subject: [RFC PATCH] ALSA: mixer_audient: Skip the read for an uncached FORCE_SET put
A FORCE_SET put without a cache slot reads the device before the write, and fails without writing if that read fails. Skip the read in that case, as RFC v1 did. Puts on cached controls keep their change reporting.
Also fix a typo in a comment and drop a blank line.
---
Proposed change to patch 10.
sound/usb/mixer_audient.c +3 -3
@@ -329,11 +329,12 @@ static int snd_audient_raw_set_one(struct usb_mixer_interface *const mixer,int ret;u32 val; -if (force) { +if (force || + (!slot && (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_FORCE_SET ))) { val = !value;/* just make it different */ }else { ret =snd_audient_raw_get_one (mixer, ctype, slot, cidx, &val); -if (ret == -ENODATA )/* FORCED_SET and not cached yet */ +if (ret == -ENODATA )/* FORCE_SET and not cached yet */ val = !value;/* just make it different */ else if (ret <0 )return ret;
@@ -352,7 +353,6 @@ static int snd_audient_raw_set_one(struct usb_mixer_interface *const mixer, slot->value = value; slot->valid = true; } - }return val != value;
Re: [RFC V2 PATCH 00/11] Re: ALSA: usb-audio: Audient iD14 MkI vendor
Quoted 20 lines · Will Porter
Hi Christian,
Thanks for RFC V2, and for folding everything in so quickly.
Quoted 2 lines · Christian Ruppert
Makes sense. Added to RFC V2 (in patch 10 where the cache is added). Please double-check if the logic reflects what you had in mind.
Yes, that is what I had in mind: a put of the cached value still writes it, but returns 0, so alsactl restore sends no change events. On an iD14 MkI, a put of the held value sent no change event on a write-only switch, a volume or a matrix control. A put of a new value on the write-only switch sent one.
One question on the same function. A
FORCE_SETcontrol without CACHE now reads the device before each write; in RFC v1 the put skipped that read. If the device refuses the read, the put fails before it writes. No table usesFORCE_SETwithout CACHE today, so nothing breaks now.
Quoted 4 lines
Should that combination work? If yes, the put could skip the read when the control has no cache slot, as the diff below does. If not, a comment or a check in
snd_audient_add_ctrl()would say so, and you can drop the diff.
I guess that depends how we define force_set. In my mind it's literally force set, i.e. for write-only values we must explicitly specify both FORCE_SET and CACHE. The reasoning is that I don't see how write-only controls can work correctly without cache. But force-setting uncached read-write controls might be of value if the set operation as such triggers an event inside a device, even if the value is the same as the one just read back on some volatile control. I imagine this could become useful for certain enumeration types, for example to load a preset.
The question is now what the put function should return in such a case and until we encounter one it's rather hypothetical to say what's preferable:
- We could systematically return 1 because an event was triggered in the device. If you think this is the right thing to do, feel free to weave your diff into patch 10. I don't think it makes sense to reiterate RFC V3 for such a small change and I'll test the full patch set anwyay.
- We could return 1 if the value is changed and 0 if it isn't which is the current behaviour and designed to be consistent with FORCE_SET in case we do have a cache. I imagine (cached) write-only controls are more probable to trigger events on writing than volatile read-write controls so this seemed the reasonable choice.
Quoted 9 lines
Quoted 3 lines
I don't think this is necessary as it should be rather obvious to everyone touching the driver that the u32 argument can't carry more than 4 bytes. Added a comment to the parameter definition.
Fine with me.
checkpatch --strict on the 11 patches gives no errors or warnings, only CHECK-level style notes, mostly unneeded parentheses (04, 05, 07, 10) and alignment (01, 05). I'll leave those to your discretion.
Not sure if we need to reiterate because of those, Takashi please advise. I would like to keep the parentheses for readability if possible and the alignment issues can be fixed little by little when we touch the file over time. Or otherwise, you can also weave in fixes if you prefer.
Quoted 5 lines
iD14 patches on RFC V2
I rebased my iD14 patch series on RFC V2. Three of my patches are now part of yours, so seven remain:
Quoted 7 lines
1. a step size for integer controls
2. enumerated controls
3. a separate mixer map for the iD14 MkI
4. iD14 MkI monitor and routing controls
5. iD14 MkI mixer matrix
6. iD14 MkI write-only controls
7. the iD14 MkI FU 12 control
Is there a reason 4, 5 and 6 are separate? They should all be one big update in the device definition tables without any code changes, right?
Quoted 6 lines
All 18 patches build one by one with W=1 without warnings. On an iD14 MkI (7.2.11 stable), the controls passed the same read and write checks as on RFC v1.
Next steps
Quoted 8 lines
As agreed, I'll send the final series: your 11 patches, then the seven iD14 patches. Two questions first:
- Your four
mixer_evofixes ("ALSA:mixer_evo: minor fixes and tlv addition") are still open on Patchwork. Should they still go in separately, before this series? Then I'd base the final series on sound for-next once Takashi applies them. Or should I put them at the front of the final series?
In principle they are bugfixes and the intention was to keep them small enough so they can still squeeze into 7.4. If Takashi decides that it's already too late for this type of fixes I'm happy remove the ones which are fixed by our new patch set anyway and resubmit the remaining ones at the beginning of our serie.
Happy to review and test an RFC of the complete series until he's back and takes a decision. I expect your seven patches aren't massively impacted by the four pending fixes so starting to review them as soon as you're ready would allow for one or two iterations if required, without losing any time while waiting.
Quoted 3 lines
- If the diff below looks right to you, shall I fold it into patch 10 when I send, or would you prefer to take it into your own tree first?
See above. If you think it makes sense to apply it please just fold it in, I don't think we need a full iteration for this.
Quoted 46 lines
Thanks,
Will-- >8 --
From: Will Porter <[email protected]>
Subject: [RFC PATCH] ALSA:mixer_audient: Skip the read for an uncachedFORCE_SETputA
FORCE_SETput without a cache slot reads the device before the write, and fails without writing if that read fails. Skip the read in that case, as RFC v1 did. Puts on cached controls keep their change reporting.Also fix a typo in a comment and drop a blank line.
Assisted-by Claude:claude-opus-5-5Signed-off-by Will Porter <[email protected]>---
Proposed change to patch 10.sound/usb/mixer_audient.c +3
-3@@ -329,11 +329,12 @@ static int snd_audient_raw_set_one(struct usb_mixer_interface *const mixer,int ret;u32 val; -if (force) { +if (force || + (!slot && (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_FORCE_SET ))) { val = !value;/* just make it different */ }else { ret =snd_audient_raw_get_one (mixer, ctype, slot, cidx, &val); -if (ret == -ENODATA )/* FORCED_SET and not cached yet */ +if (ret == -ENODATA )/* FORCE_SET and not cached yet */ val = !value;/* just make it different */ else if (ret <0 )return ret;@@ -352,7 +353,6 @@ static int snd_audient_raw_set_one(struct usb_mixer_interface *const mixer, slot->value = value; slot->valid = true; } - }return val != value;
Signature · 4 lines
Christian Ruppert <[email protected]> This message is digitally signed with GnuPG. GPG/PGP Key fingerprint = 4492 2196 75F0 EAA0 981E B661 1476 F17A 975F 587B
cover ALSA: usb-audio: Audient driver and iD14 MkI support
Hi Christian,
Quoted 3 lines · Christian Ruppert
I guess that depends how we define
force_set. In my mind it's literally force set, i.e. for write-only values we must explicitly specify bothFORCE_SETand CACHE.
That definition makes sense to me. With it, the read before the write is fine: an uncached FORCE_SET control is one the device can read.
I also prefer the current return value. If a put always returned 1, the kernel would send a change event even when alsactl restores an unchanged value. So I dropped my diff. Patch 10 has only the comment typo fixed and the blank line removed.
Quoted 2 lines
Is there a reason 4, 5 and 6 are separate? They should all be one big update in the device definition tables without any code changes, right?
Right, they add only table entries, the device ID and the map lines. They are now one patch (15 of this series).
Quoted 2 lines
Happy to review and test an RFC of the complete series until he's back and takes a decision.
Thanks, here it is: your 11 RFC V2 patches, then the five iD14 patches. It sits on top of your four mixer_evo fixes. I can rebase it once Takashi decides how those go in.
Patches 12 to 16:
- 12 adds a step size to integer controls (the iD14 volumes move in 1 dB steps).
- 13 adds enumerated controls (routing, iD key function, talkback source, digital input mode).
- 14 gives the iD14 MkI its own mixer map; the MkII keeps the shared one.
- 15 adds the iD14 MkI controls: monitor section, routing, mixer matrix and the write-only controls.
- 16 replaces the generic FU 12 control, whose GET returns stale data.
Base: sound master 603a4df9e6ae with your four fixes (Patchwork series 1193966). Each patch builds on its own with W=1 without warnings. On an iD14 MkI (7.2.11 stable), the complete series passed the same read and write checks as RFC V2, change events included.
Thanks,
Will
Christian Ruppert (11):
ALSA: rename mixer_evo to mixer_audient
ALSA: mixer_audient: explicitly define full control names
ALSA: mixer_audient: clarify USB control message definition
ALSA: mixer_audient: Add length check to USB transfer
ALSA: mixer_audient: make USB control transfer size configurable
ALSA: mixer_audient: Allow arbitrary boolean control values
ALSA: mixer_audient: Add integer range checks
ALSA: mixer_audient: Add control initialization at probe
ALSA: mixer_audient: Add readback-free parameter set
ALSA: mixer_audient: add control value caching
ALSA: mixer_audient: Create matrix programmatically
Will Porter (5):
ALSA: mixer_audient: Add a step size to integer controls
ALSA: mixer_audient: Add enumerated controls
ALSA: usb-audio: Give the Audient iD14 MkI its own mixer map
ALSA: mixer_audient: Add Audient iD14 MkI controls
ALSA: mixer_audient: Replace the Audient iD14 MkI FU 12 control
MAINTAINERS | 7 +- sound/usb/Makefile | 2 +- sound/usb/mixer_audient.c | 1342 +++++++++++++++++++++++++++++++++++++ sound/usb/mixer_audient.h | 13 + sound/usb/mixer_evo.c | 526 --------------- sound/usb/mixer_evo.h | 12 - sound/usb/mixer_maps.c | 10 +- sound/usb/mixer_quirks.c | 7 +- 8 files changed, 1374 insertions(+), 545 deletions(-) create mode 100644 sound/usb/mixer_audient.c create mode 100644 sound/usb/mixer_audient.h delete mode 100644 sound/usb/mixer_evo.c delete mode 100644 sound/usb/mixer_evo.h
base-commit: 603a4df9e6ae60a26adb335fe8d8f6e8f19e5d8e
prerequisite-patch-id: 522b05214a3c615ec30e50574b2bcc9c6c55dc3c
prerequisite-patch-id: 4c58588cb3fd46832de61018d60452ad1f5de1f9
prerequisite-patch-id: e15c90c1732110d25b16d26b4f919715cae7f5be
prerequisite-patch-id: 02c9ab9c3fd4cc8617060c81eed06affae2da0d2
Signature · 1 line
2.47.3
RFC PATCH 1/16 ALSA: rename mixer_evo to mixer_audient
From: Christian Ruppert <[email protected]>
Rename mixer_evo files and functions to *_audient in preparation of a more generic driver for audient devices.
---
MAINTAINERS | 7 +-
sound/usb/Makefile | 2 +-
sound/usb/{mixer_evo.c => mixer_audient.c} | 249 +++++++++++----------
sound/usb/mixer_audient.h | 12 +
sound/usb/mixer_evo.h | 12 -
sound/usb/mixer_quirks.c | 4 +-
6 files changed, 148 insertions(+), 138 deletions(-)
rename sound/usb/{mixer_evo.c => mixer_audient.c} (54%)
create mode 100644 sound/usb/mixer_audient.h
delete mode 100644 sound/usb/mixer_evo.hMAINTAINERS +4 -3
@@ -4354,12 +4354,13 @@ F: drivers/net/ieee802154/at86rf230.h F: drivers/net/ieee802154/atusb.c F: drivers/net/ieee802154/atusb.h -AUDIENT EVO MIXER DRIVER +AUDIENT MIXER DRIVER M: Christian Ruppert <[email protected]> +M: Will Porter <[email protected]> L: [email protected] S: Maintained -F: sound/usb/mixer_evo.c -F: sound/usb/mixer_evo.h +F: sound/usb/mixer_audient.c +F: sound/usb/mixer_audient.h AUDIT SUBSYSTEM M: Paul Moore <[email protected]>
sound/usb/Makefile +1 -1
@@ -11,7 +11,7 @@ snd-usb-audio-y := card.o \ helper.o \ implicit.o \ mixer.o \ - mixer_evo.o \ + mixer_audient.o \ mixer_quirks.o \ mixer_scarlett.o \ mixer_scarlett2.o \
sound/usb/mixer_audient.c renamed from sound/usb/mixer_evo.c +129 -120
553 lines not on this page · raw message
sound/usb/mixer_audient.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __USB_MIXER_AUDIENT_H +#define __USB_MIXER_AUDIENT_H + +#include "mixer.h" + +#define USB_AUDIENT_VID (0x2708) +#define USB_EVO4_PID (0x0006) + +int snd_audient_controls_create (struct usb_mixer_interface *mixer); + +#endif /* __USB_MIXER_AUDIENT_H */
sound/usb/mixer_evo.h deleted +0 -12
@@ -1,12 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef __USB_MIXER_EVO_H -#define __USB_MIXER_EVO_H - -#include "mixer.h" - -#define USB_AUDIENT_VID (0x2708) -#define USB_EVO4_PID (0x0006) - -int snd_evo_controls_create (struct usb_mixer_interface *mixer); - -#endif /* __USB_MIXER_EVO_H */
sound/usb/mixer_quirks.c +2 -2
@@ -38,7 +38,7 @@#include "mixer_scarlett2.h" #include "mixer_us16x08.h" #include "mixer_s1810c.h" -#include "mixer_evo.h" +#include "mixer_audient.h" #include "helper.h" #include "fcp.h"
@@ -4541,7 +4541,7 @@ int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)break ;case USB_ID (USB_AUDIENT_VID ,USB_EVO4_PID ):/* Audient EVO 4 */ - err =snd_evo_controls_create (mixer); + err =snd_audient_controls_create (mixer);break ;case USB_ID (0x041e ,0x323b ):/* Creative Sound Blaster E1 */
Signature · 1 line
2.47.3
RFC PATCH 2/16 ALSA: mixer_audient: explicitly define full control names
In reply to Will PorterFrom: Christian Ruppert <[email protected]>
Previously, control names were dynamically created depending if the control was an input or an output, a volume or a switch. Get rid of this logic by simply defining the full name in the control structure.
--- sound/usb/mixer_audient.c | 50 +++++++++++---------------------------- 1 file changed, 14 insertions(+), 36 deletions(-)
sound/usb/mixer_audient.c +14 -36
@@ -90,107 +90,92 @@ static const struct snd_audient_ctrl_type { }, }; -#define SND_AUDIENT_FLAGS_DIRECTION (1L<<0) -#define SND_AUDIENT_FLAGS_CAPTURE (1L<<0) -#define SND_AUDIENT_FLAGS_PLAYBACK (0L<<0)struct snd_audient_ctrl { -char *basename; +char *name;enum snd_audient_type type;unsigned int channels;unsigned int hwchannels;unsigned int val_offs; -unsigned long flags; };static const struct snd_audient_ctrl snd_audient_evo4_controls[] = { { - .basename ="Master" , + .name ="Master Playback Switch" , .type =SND_AUDIENT_TYPE_MUTE_OUT , .channels =1 , .hwchannels =1 , .val_offs =0 , - .flags =SND_AUDIENT_FLAGS_PLAYBACK , }, { - .basename ="Mic" , + .name ="Mic Playback Switch" , .type =SND_AUDIENT_TYPE_MUTE , .channels =4 , .hwchannels =2 , .val_offs =0 , - .flags =SND_AUDIENT_FLAGS_PLAYBACK , }, { - .basename ="Monitor" , + .name ="Monitor Playback Volume" , .type =SND_AUDIENT_TYPE_MONITOR , .channels =1 , .hwchannels =1 , .val_offs =0 , - .flags =SND_AUDIENT_FLAGS_PLAYBACK , }, { - .basename ="Mic 1" , + .name ="Mic 1 Capture Volume" , .type =SND_AUDIENT_TYPE_MIXER , .channels =2 , .hwchannels =2 , .val_offs =0 , - .flags =SND_AUDIENT_FLAGS_CAPTURE , }, { - .basename ="Mic 2" , + .name ="Mic 2 Capture Volume" , .type =SND_AUDIENT_TYPE_MIXER , .channels =2 , .hwchannels =2 , .val_offs =2 , - .flags =SND_AUDIENT_FLAGS_CAPTURE , }, { - .basename ="Master Left" , + .name ="Master Left Capture Volume" , .type =SND_AUDIENT_TYPE_MIXER , .channels =2 , .hwchannels =2 , .val_offs =4 , - .flags =SND_AUDIENT_FLAGS_CAPTURE , }, { - .basename ="Master Right" , + .name ="Master Right Capture Volume" , .type =SND_AUDIENT_TYPE_MIXER , .channels =2 , .hwchannels =2 , .val_offs =6 , - .flags =SND_AUDIENT_FLAGS_CAPTURE , }, { - .basename ="Loopback Left" , + .name ="Loopback Left Capture Volume" , .type =SND_AUDIENT_TYPE_MIXER , .channels =2 , .hwchannels =2 , .val_offs =8 , - .flags =SND_AUDIENT_FLAGS_CAPTURE , }, { - .basename ="Loopback Right" , + .name ="Loopback Right Capture Volume" , .type =SND_AUDIENT_TYPE_MIXER , .channels =2 , .hwchannels =2 , .val_offs =10 , - .flags =SND_AUDIENT_FLAGS_CAPTURE , }, { - .basename ="Mic 1 Phantom" , + .name ="Mic 1 Phantom Capture Switch" , .type =SND_AUDIENT_TYPE_PHANTOM , .channels =1 , .hwchannels =1 , .val_offs =0 , - .flags =SND_AUDIENT_FLAGS_CAPTURE , }, { - .basename ="Mic 2 Phantom" , + .name ="Mic 2 Phantom Capture Switch" , .type =SND_AUDIENT_TYPE_PHANTOM , .channels =1 , .hwchannels =1 , .val_offs =1 , - .flags =SND_AUDIENT_FLAGS_CAPTURE , }, {0 },/* sentinel */ };
@@ -458,13 +443,12 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer, {const struct snd_audient_ctrl_type *ctype = &snd_audient_ctypes[ctrl->type]; -char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN ];struct snd_kcontrol_new knew = {0 };struct snd_kcontrol *kctl;struct usb_mixer_elem_info *elem; knew.iface =SNDRV_CTL_ELEM_IFACE_MIXER ; - knew.name = name; + knew.name = ctrl->name; knew.info = snd_ctl_audient_info; knew.private_value =snd_audient_kctl_priv (ctrl->type, ctrl->val_offs, ctrl->hwchannels);
@@ -486,12 +470,6 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer,return -EINVAL ; } -snprintf (name,sizeof (name),"%s %s %s" , ctrl->basename, - ((ctrl->flags &SND_AUDIENT_FLAGS_DIRECTION ) - ==SND_AUDIENT_FLAGS_CAPTURE ) ?"Capture" :"Playback" , - (ctype->type ==SNDRV_CTL_ELEM_TYPE_BOOLEAN ) - ?"Switch" :"Volume" ); - elem =kzalloc_obj (*elem);if (!elem)return -ENOMEM ;
@@ -524,7 +502,7 @@ int snd_audient_controls_create(struct usb_mixer_interface *mixer)if (!info->controls)return -ENODEV ; -for (ctrl = info->controls; ctrl->basename; ctrl++) { +for (ctrl = info->controls; ctrl->name; ctrl++) {const int ret =snd_audient_add_ctrl (mixer, ctrl);if (ret <0 )
Signature · 1 line
2.47.3
RFC PATCH 3/16 ALSA: mixer_audient: clarify USB control message definition
In reply to Will PorterFrom: Christian Ruppert <[email protected]>
Previously, base values for wIndex and wValue were directly given in the control type. Construct them from a unit ID and selector for clarity.
--- sound/usb/mixer_audient.c | 76 +++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 35 deletions(-)
sound/usb/mixer_audient.c +41 -35
@@ -45,15 +45,15 @@ static const struct snd_audient_ctrl_type {int integer; } max;const unsigned int *tlv; -u16 wValue; -u16 wIndex; +u8 unit; +u8 sel; } snd_audient_ctypes[SND_AUDIENT_TYPE_NCTYPES] = { [SND_AUDIENT_TYPE_MONITOR] = { .type = SNDRV_CTL_ELEM_TYPE_INTEGER, .min.integer = 0, .max.integer = 127, - .wValue = 0x0000, - .wIndex = 0x3800, + .unit = 0x38, + .sel = 0x00, /* no TLV here because we can't describe the cross-fader */ }, [SND_AUDIENT_TYPE_PHANTOM] = {
@@ -61,31 +61,31 @@ static const struct snd_audient_ctrl_type { .invert = false, .min.integer = 0, .max.integer = 1, - .wValue = 0x0000, - .wIndex = 0x3A00, + .unit = 0x3A, + .sel = 0x00, }, [SND_AUDIENT_TYPE_MUTE] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, .invert = true, .min.integer = 0, .max.integer = 1, - .wValue = 0x0200, - .wIndex = 0x3A00, + .unit = 0x3A, + .sel = 0x02, }, [SND_AUDIENT_TYPE_MUTE_OUT] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, .invert = true, .min.integer = 0, .max.integer = 1, - .wValue = 0x0100, - .wIndex = 0x3B00, + .unit = 0x3B, + .sel = 0x01, }, [SND_AUDIENT_TYPE_MIXER] = { .type = SNDRV_CTL_ELEM_TYPE_INTEGER, .min.integer = -128 * 256, .max.integer = 6 * 256, - .wValue = 0x0100, - .wIndex = 0x3C00, + .unit = 0x3C, + .sel = 0x01, .tlv = snd_audient_tlv_mixer, }, };
@@ -209,7 +209,7 @@ const struct snd_audient_ctrl_type *snd_audient_kctl_type(struct snd_kcontrolreturn &snd_audient_ctypes[kctl->private_value &0xFF ]; } -static __always_inline u16 snd_audient_kctl_valoffs(struct snd_kcontrol *kctl) +static __always_inline u16 snd_audient_kctl_cidxoffs(struct snd_kcontrol *kctl) {return (kctl->private_value >>8 ) &0xFF ; }
@@ -233,11 +233,16 @@ static inline u16 snd_audient_kctl_channels(struct snd_kcontrol *kctl)#define AUDIENT_REQTYPE_GET (USB_DIR_IN | USB_TYPE_CLASS \ | USB_RECIP_INTERFACE) +#define U8_U8 (HI ,LO ) ((((u16)(HI)) << 8) | ((LO) & 0xFF)) +static inline int snd_audient_get_cur (struct usb_mixer_interface *mixer, -u16 value,u16 index, -void *buf,size_t len) +const u8 unit,const u8 sel, +const u8 cidx, +void *const buf,const size_t len) {struct usb_device *const dev = mixer->chip->dev; +const u16 value =U8_U8 (sel, cidx); +const u16 index =U8_U8 (unit, mixer->hostif->desc.bInterfaceNumber); return snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_CUR, AUDIENT_REQTYPE_GET,
@@ -245,10 +250,13 @@ static inline int snd_audient_get_cur(struct usb_mixer_interface *mixer, }static inline int snd_audient_set_cur (struct usb_mixer_interface *mixer, -u16 value,u16 index, -void *buf,size_t len) +const u8 unit,const u8 sel, +const u8 cidx, +void *const buf,const size_t len) {struct usb_device *const dev = mixer->chip->dev; +const u16 value =U8_U8 (sel, cidx); +const u16 index =U8_U8 (unit, mixer->hostif->desc.bInterfaceNumber); return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC2_CS_CUR, AUDIENT_REQTYPE_SET,
@@ -266,8 +274,7 @@ static int snd_ctl_audient_boolean_get(struct snd_kcontrol *kctl,const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl);const struct snd_audient_ctrl_type *const ctype =snd_audient_kctl_type (kctl); -const u16 value = ctype->wValue +snd_audient_kctl_valoffs (kctl); -const u16 index = ctype->wIndex; +const u8 base =snd_audient_kctl_cidxoffs (kctl);int i;
@@ -279,8 +286,8 @@ static int snd_ctl_audient_boolean_get(struct snd_kcontrol *kctl,u32 buf;int ret; - ret =snd_audient_get_cur (mixer, value + i, index, - &buf,sizeof (buf)); + ret =snd_audient_get_cur (mixer, ctype->unit, ctype->sel, + base + i, &buf,sizeof (buf));if (ret <0 )return ret;
@@ -307,8 +314,7 @@ static int snd_ctl_audient_boolean_set(struct snd_kcontrol *kctl,const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl);const struct snd_audient_ctrl_type *const ctype =snd_audient_kctl_type (kctl); -const u16 value = ctype->wValue +snd_audient_kctl_valoffs (kctl); -const u16 index = ctype->wIndex; +const u8 base =snd_audient_kctl_cidxoffs (kctl);int changed =0 ;int i;
@@ -325,15 +331,16 @@ static int snd_ctl_audient_boolean_set(struct snd_kcontrol *kctl,if (ctype->invert) buf ^=cpu_to_le32 (0x1 ); - ret =snd_audient_get_cur (mixer, value + i, index, - &rbuf,sizeof (rbuf)); + ret =snd_audient_get_cur (mixer, ctype->unit, ctype->sel, + base + i, &rbuf,sizeof (rbuf));if (ret <0 )return ret;if (rbuf != buf) { changed =1 ; - ret =snd_audient_set_cur (mixer, value + i, index, + ret =snd_audient_set_cur (mixer, ctype->unit, + ctype->sel, base + i, &buf,sizeof (buf));if (ret <0 )return ret;
@@ -353,8 +360,7 @@ static int snd_ctl_audient_integer_get(struct snd_kcontrol *kctl,const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl);const struct snd_audient_ctrl_type *const ctype =snd_audient_kctl_type (kctl); -const u16 value = ctype->wValue +snd_audient_kctl_valoffs (kctl); -const u16 index = ctype->wIndex; +const u8 base =snd_audient_kctl_cidxoffs (kctl);int i;
@@ -367,8 +373,8 @@ static int snd_ctl_audient_integer_get(struct snd_kcontrol *kctl,s16 val;int ret; - ret =snd_audient_get_cur (mixer, value + i, index, - &buf,sizeof (buf)); + ret =snd_audient_get_cur (mixer, ctype->unit, ctype->sel, + base + i, &buf,sizeof (buf));if (ret <0 )return ret;
@@ -391,8 +397,7 @@ static int snd_ctl_audient_integer_set(struct snd_kcontrol *kctl,const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl);const struct snd_audient_ctrl_type *const ctype =snd_audient_kctl_type (kctl); -const u16 value = ctype->wValue +snd_audient_kctl_valoffs (kctl); -const u16 index = ctype->wIndex; +const u8 base =snd_audient_kctl_cidxoffs (kctl);int changed =0 ;int i;
@@ -406,15 +411,16 @@ static int snd_ctl_audient_integer_set(struct snd_kcontrol *kctl,s16 buf =cpu_to_le16 (ctl_val->value.integer.value[i]);int ret; - ret =snd_audient_get_cur (mixer, value + i, index, - &rbuf,sizeof (rbuf)); + ret =snd_audient_get_cur (mixer, ctype->unit, ctype->sel, + base + i, &rbuf,sizeof (rbuf));if (ret <0 )return ret;if (rbuf != buf) { changed =1 ; - ret =snd_audient_set_cur (mixer, value + i, index, + ret =snd_audient_set_cur (mixer, ctype->unit, + ctype->sel, base + i, &buf,sizeof (buf));if (ret <0 )return ret;
Signature · 1 line
2.47.3
RFC PATCH 4/16 ALSA: mixer_audient: Add length check to USB transfer
In reply to Will PorterFrom: Christian Ruppert <[email protected]>
Check USB control transfers not only for errors but also for expected length and return -EIO in case of error.
--- sound/usb/mixer_audient.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
sound/usb/mixer_audient.c +16 -6
@@ -244,9 +244,14 @@ static inline int snd_audient_get_cur(struct usb_mixer_interface *mixer,const u16 value =U8_U8 (sel, cidx);const u16 index =U8_U8 (unit, mixer->hostif->desc.bInterfaceNumber); -return snd_usb_ctl_msg (dev,usb_rcvctrlpipe (dev,0 ), -UAC2_CS_CUR ,AUDIENT_REQTYPE_GET , - value, index, buf, len); +const int ret =snd_usb_ctl_msg (dev,usb_rcvctrlpipe (dev,0 ), +UAC2_CS_CUR ,AUDIENT_REQTYPE_GET , + value, index, buf, len); + +if ((ret >=0 ) && (ret != len)) +return -EIO ; + +return ret; } static inline int snd_audient_set_cur(struct usb_mixer_interface *mixer,
@@ -258,9 +263,14 @@ static inline int snd_audient_set_cur(struct usb_mixer_interface *mixer,const u16 value =U8_U8 (sel, cidx);const u16 index =U8_U8 (unit, mixer->hostif->desc.bInterfaceNumber); -return snd_usb_ctl_msg (dev,usb_sndctrlpipe (dev,0 ), -UAC2_CS_CUR ,AUDIENT_REQTYPE_SET , - value, index, buf, len); +const int ret =snd_usb_ctl_msg (dev,usb_sndctrlpipe (dev,0 ), +UAC2_CS_CUR ,AUDIENT_REQTYPE_SET , + value, index, buf, len); + +if ((ret >=0 ) && (ret != len)) +return -EIO ; + +return ret; }
Signature · 1 line
2.47.3
RFC PATCH 5/16 ALSA: mixer_audient: make USB control transfer size configurable
In reply to Will PorterFrom: Christian Ruppert <[email protected]>
Previously, the USB transfer size was hardcoded in the datatype get/set functions. Make it configurable in the ctype structure in preparation of new control types for the id14.
--- sound/usb/mixer_audient.c | 131 ++++++++++++++++++++++++-------------- 1 file changed, 84 insertions(+), 47 deletions(-)
sound/usb/mixer_audient.c +84 -47
@@ -12,6 +12,8 @@#include <linux/usb.h> #include <linux/usb/audio-v2.h> #include <linux/slab.h> +#include <linux/types.h> +#include <linux/bitops.h> #include <sound/core.h> #include <sound/control.h> #include <sound/tlv.h>
@@ -35,8 +37,12 @@ enum snd_audient_type {/* Mixer matrix: -128dB (mute) to +6dB */ static const DECLARE_TLV_DB_MINMAX_MUTE(snd_audient_tlv_mixer, -12800, 600); +#define SND_AUDIENT_CTYPE_FLAGS_SIGNED BIT(0) + static const struct snd_audient_ctrl_type { snd_ctl_elem_type_t type; + unsigned long flags; + size_t len; /* datatype size, can be 1, 2 or 4 bytes */ bool invert; union { int integer;
@@ -50,6 +56,7 @@ static const struct snd_audient_ctrl_type { } snd_audient_ctypes[SND_AUDIENT_TYPE_NCTYPES] = { [SND_AUDIENT_TYPE_MONITOR] = { .type = SNDRV_CTL_ELEM_TYPE_INTEGER, + .len = 2, .min.integer = 0, .max.integer = 127, .unit = 0x38,
@@ -59,6 +66,7 @@ static const struct snd_audient_ctrl_type { [SND_AUDIENT_TYPE_PHANTOM] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, .invert = false, + .len = 4, .min.integer = 0, .max.integer = 1, .unit = 0x3A,
@@ -67,6 +75,7 @@ static const struct snd_audient_ctrl_type { [SND_AUDIENT_TYPE_MUTE] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, .invert = true, + .len = 4, .min.integer = 0, .max.integer = 1, .unit = 0x3A,
@@ -75,6 +84,7 @@ static const struct snd_audient_ctrl_type { [SND_AUDIENT_TYPE_MUTE_OUT] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, .invert = true, + .len = 4, .min.integer = 0, .max.integer = 1, .unit = 0x3B,
@@ -82,6 +92,8 @@ static const struct snd_audient_ctrl_type { }, [SND_AUDIENT_TYPE_MIXER] = { .type = SNDRV_CTL_ELEM_TYPE_INTEGER, + .flags = SND_AUDIENT_CTYPE_FLAGS_SIGNED, + .len = 2, .min.integer = -128 * 256, .max.integer = 6 * 256, .unit = 0x3C,
@@ -236,44 +248,91 @@ static inline u16 snd_audient_kctl_channels(struct snd_kcontrol *kctl)#define U8_U8 (HI ,LO ) ((((u16)(HI)) << 8) | ((LO) & 0xFF))static inline int snd_audient_get_cur (struct usb_mixer_interface *mixer, -const u8 unit,const u8 sel, -const u8 cidx, -void *const buf,const size_t len) +const struct snd_audient_ctrl_type *const ctype, +const u8 cidx,void *const buf) {struct usb_device *const dev = mixer->chip->dev; -const u16 value =U8_U8 (sel, cidx); -const u16 index =U8_U8 (unit, mixer->hostif->desc.bInterfaceNumber); +const u16 value =U8_U8 (ctype->sel, cidx); +const u16 index =U8_U8 (ctype->unit, + mixer->hostif->desc.bInterfaceNumber);const int ret =snd_usb_ctl_msg (dev,usb_rcvctrlpipe (dev,0 ),UAC2_CS_CUR ,AUDIENT_REQTYPE_GET , - value, index, buf, len); + value, index, buf, ctype->len); -if ((ret >=0 ) && (ret != len)) +if ((ret >=0 ) && (ret != ctype->len))return -EIO ;return ret; }static inline int snd_audient_set_cur (struct usb_mixer_interface *mixer, -const u8 unit,const u8 sel, -const u8 cidx, -void *const buf,const size_t len) +const struct snd_audient_ctrl_type *const ctype, +const u8 cidx,void *const buf) {struct usb_device *const dev = mixer->chip->dev; -const u16 value =U8_U8 (sel, cidx); -const u16 index =U8_U8 (unit, mixer->hostif->desc.bInterfaceNumber); +const u16 value =U8_U8 (ctype->sel, cidx); +const u16 index =U8_U8 (ctype->unit, + mixer->hostif->desc.bInterfaceNumber);const int ret =snd_usb_ctl_msg (dev,usb_sndctrlpipe (dev,0 ),UAC2_CS_CUR ,AUDIENT_REQTYPE_SET , - value, index, buf, len); + value, index, buf, ctype->len); -if ((ret >=0 ) && (ret != len)) +if ((ret >=0 ) && (ret != ctype->len))return -EIO ;return ret; } +static int snd_audient_raw_get_one (struct usb_mixer_interface *const mixer, +const struct snd_audient_ctrl_type *const ctype, +const u8 cidx,u32 *const value) +{ +int ret; +__le32 buf =0 ; +s32 val; + + ret =snd_audient_get_cur (mixer, ctype, cidx, &buf); +if (ret <0 ) +return ret; + + val =le32_to_cpu (buf); + +if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_SIGNED ) + val =sign_extend32 (val,8 * ctype->len -1 ); + + *value = val; + +return ret; +} + +static int snd_audient_raw_set_one (struct usb_mixer_interface *const mixer, +const struct snd_audient_ctrl_type *const ctype, +const u8 cidx,const u32 value) +{ +int ret; +u32 val; + + ret =snd_audient_raw_get_one (mixer, ctype, cidx, &val); +if (ret <0 ) +return ret; + +if (val != value) { +__le32 buf =cpu_to_le32 (value); + + ret =snd_audient_set_cur (mixer, ctype, cidx, &buf); +if (ret <0 ) +return ret; + +return 1 ; + } + +return 0 ; +} + +static int snd_ctl_audient_boolean_get (struct snd_kcontrol *kctl,struct snd_ctl_elem_value *ctl_val) {
@@ -296,12 +355,11 @@ static int snd_ctl_audient_boolean_get(struct snd_kcontrol *kctl,u32 buf;int ret; - ret =snd_audient_get_cur (mixer, ctype->unit, ctype->sel, - base + i, &buf,sizeof (buf)); + ret =snd_audient_raw_get_one (mixer, ctype, base + i, &buf);if (ret <0 )return ret; - ctl_val->value.integer.value[i] =le32_to_cpu (buf) ?1 :0 ; + ctl_val->value.integer.value[i] = buf ?1 :0 ;if (ctype->invert) ctl_val->value.integer.value[i] ^=0x1 ;
@@ -334,27 +392,18 @@ static int snd_ctl_audient_boolean_set(struct snd_kcontrol *kctl,return pm.err;for (i =0 ; i < hwchan; i++) { -u32 rbuf; -u32 buf =cpu_to_le32 (ctl_val->value.integer.value[i] ?1 :0 ); +u32 buf = ctl_val->value.integer.value[i] ?1 :0 ;int ret;if (ctype->invert) - buf ^=cpu_to_le32 (0x1 ); + buf ^=0x1 ; - ret =snd_audient_get_cur (mixer, ctype->unit, ctype->sel, - base + i, &rbuf,sizeof (rbuf)); + ret =snd_audient_raw_set_one (mixer, ctype, base + i, buf);if (ret <0 )return ret; -if (rbuf != buf) { +if (ret) changed =1 ; - - ret =snd_audient_set_cur (mixer, ctype->unit, - ctype->sel, base + i, - &buf,sizeof (buf)); -if (ret <0 ) -return ret; - } }return changed;
@@ -379,16 +428,13 @@ static int snd_ctl_audient_integer_get(struct snd_kcontrol *kctl,return pm.err;for (i =0 ; i < hwchan; i++) { -u16 buf; -s16 val; +s32 val;int ret; - ret =snd_audient_get_cur (mixer, ctype->unit, ctype->sel, - base + i, &buf,sizeof (buf)); + ret =snd_audient_raw_get_one (mixer, ctype, base + i, &val);if (ret <0 )return ret; - val =le16_to_cpu (buf); ctl_val->value.integer.value[i] = val; }
@@ -417,24 +463,15 @@ static int snd_ctl_audient_integer_set(struct snd_kcontrol *kctl,return pm.err;for (i =0 ; i < hwchan; i++) { -s16 rbuf; -s16 buf =cpu_to_le16 (ctl_val->value.integer.value[i]); +s32 val = ctl_val->value.integer.value[i];int ret; - ret =snd_audient_get_cur (mixer, ctype->unit, ctype->sel, - base + i, &rbuf,sizeof (rbuf)); + ret =snd_audient_raw_set_one (mixer, ctype, base + i, val);if (ret <0 )return ret; -if (rbuf != buf) { +if (ret) changed =1 ; - - ret =snd_audient_set_cur (mixer, ctype->unit, - ctype->sel, base + i, - &buf,sizeof (buf)); -if (ret <0 ) -return ret; - } }return changed;
Signature · 1 line
2.47.3
RFC PATCH 6/16 ALSA: mixer_audient: Allow arbitrary boolean control values
In reply to Will PorterFrom: Christian Ruppert <[email protected]>
In preparation of id14 support, allow arbitrary values for true and false of boolean switches. This also rids us of the tedious invert flag.
--- sound/usb/mixer_audient.c | 43 ++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 23 deletions(-)
sound/usb/mixer_audient.c +20 -23
@@ -43,13 +43,12 @@ static const struct snd_audient_ctrl_type {snd_ctl_elem_type_t type;unsigned long flags;size_t len;/* datatype size, can be 1, 2 or 4 bytes */ -bool invert;union {int integer; - } min; + } min;/* for booleans holds physical int value for false */ union {int integer; - } max; + } max;/* for booleans holds physical int value for true */ const unsigned int *tlv;u8 unit;u8 sel;
@@ -65,7 +64,6 @@ static const struct snd_audient_ctrl_type { }, [SND_AUDIENT_TYPE_PHANTOM] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, - .invert = false, .len = 4, .min.integer = 0, .max.integer = 1,
@@ -74,19 +72,17 @@ static const struct snd_audient_ctrl_type { }, [SND_AUDIENT_TYPE_MUTE] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, - .invert = true, .len = 4, - .min.integer = 0, - .max.integer = 1, + .min.integer = 1, + .max.integer = 0, .unit = 0x3A, .sel = 0x02, }, [SND_AUDIENT_TYPE_MUTE_OUT] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, - .invert = true, .len = 4, - .min.integer = 0, - .max.integer = 1, + .min.integer = 1, + .max.integer = 0, .unit = 0x3B, .sel = 0x01, },
@@ -359,16 +355,12 @@ static int snd_ctl_audient_boolean_get(struct snd_kcontrol *kctl,if (ret <0 )return ret; - ctl_val->value.integer.value[i] = buf ?1 :0 ; - -if (ctype->invert) - ctl_val->value.integer.value[i] ^=0x1 ; + ctl_val->value.integer.value[i] = (buf == ctype->min.integer) + ? false : true; }for (; i < nchan; i++) - ctl_val->value.integer.value[i] = ctype->invert - ? ctype->max.integer - : ctype->min.integer; + ctl_val->value.integer.value[i] =0 ;return 0 ; }
@@ -392,12 +384,10 @@ static int snd_ctl_audient_boolean_set(struct snd_kcontrol *kctl,return pm.err;for (i =0 ; i < hwchan; i++) { -u32 buf = ctl_val->value.integer.value[i] ?1 :0 ; +u32 buf = ctl_val->value.integer.value[i] ? ctype->max.integer + : ctype->min.integer;int ret; -if (ctype->invert) - buf ^=0x1 ; - ret =snd_audient_raw_set_one (mixer, ctype, base + i, buf);if (ret <0 )return ret;
@@ -485,8 +475,15 @@ static int snd_ctl_audient_info(struct snd_kcontrol *kctl, uinfo->type = ctype->type; uinfo->count =snd_audient_kctl_channels (kctl); - uinfo->value.integer.min = ctype->min.integer; - uinfo->value.integer.max = ctype->max.integer; + +if (ctype->type ==SNDRV_CTL_ELEM_TYPE_BOOLEAN ) { + uinfo->value.integer.min =0 ; + uinfo->value.integer.max =1 ; + }else { + uinfo->value.integer.min = ctype->min.integer; + uinfo->value.integer.max = ctype->max.integer; + } +return 0 ; }
Signature · 1 line
2.47.3
RFC PATCH 7/16 ALSA: mixer_audient: Add integer range checks
In reply to Will PorterFrom: Christian Ruppert <[email protected]>
Add range checks to integer parameters to improve error management:
- Reject out-of-range write attempts with -EINVAL
- Prune out-of-range values returned by the device to the range limits
--- sound/usb/mixer_audient.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
sound/usb/mixer_audient.c +15 -2
@@ -44,10 +44,10 @@ static const struct snd_audient_ctrl_type {unsigned long flags;size_t len;/* datatype size, can be 1, 2 or 4 bytes */ union { -int integer; +long integer; } min;/* for booleans holds physical int value for false */ union { -int integer; +long integer; } max;/* for booleans holds physical int value for true */ const unsigned int *tlv;u8 unit;
@@ -425,6 +425,12 @@ static int snd_ctl_audient_integer_get(struct snd_kcontrol *kctl,if (ret <0 )return ret; +if (val < ctype->min.integer) + val = ctype->min.integer; + +if (val > ctype->max.integer) + val = ctype->max.integer; + ctl_val->value.integer.value[i] = val; }
@@ -448,6 +454,13 @@ static int snd_ctl_audient_integer_set(struct snd_kcontrol *kctl,int changed =0 ;int i; +for (i =0 ; i < hwchan; i++) { +long val = ctl_val->value.integer.value[i]; + +if ((val < ctype->min.integer) || (val > ctype->max.integer)) +return -EINVAL ; + } +CLASS (snd_usb_lock, pm)(mixer->chip);if (pm.err <0 )return pm.err;
Signature · 1 line
2.47.3
RFC PATCH 8/16 ALSA: mixer_audient: Add control initialization at probe
In reply to Will PorterFrom: Christian Ruppert <[email protected]>
Add the possibility to initialize certain control types to known values at probe time. This is particularly useful for controls which initially read wrong values and for controls which cannot be read at all.
--- sound/usb/mixer_audient.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
sound/usb/mixer_audient.c +16 -0
@@ -38,6 +38,7 @@ enum snd_audient_type { static const DECLARE_TLV_DB_MINMAX_MUTE(snd_audient_tlv_mixer, -12800, 600);#define SND_AUDIENT_CTYPE_FLAGS_SIGNED BIT(0) +#define SND_AUDIENT_CTYPE_FLAGS_INIT_HW BIT(1) static const struct snd_audient_ctrl_type { snd_ctl_elem_type_t type;
@@ -49,6 +50,7 @@ static const struct snd_audient_ctrl_type {union {long integer; } max;/* for booleans holds physical int value for true */ +u32 init;const unsigned int *tlv;u8 unit;u8 sel;
@@ -533,6 +535,20 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer,return -EINVAL ; } +if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_INIT_HW ) { +int i; + +for (i =0 ; i < ctrl->hwchannels; i++) { +int ret =snd_audient_raw_set_one (mixer, ctype, + ctrl->val_offs + i, + ctype->init); +if (ret <0 ) +usb_audio_warn (mixer->chip, +"%s: cannot set channel %d (%d)\n" , + ctrl->name, i, ret); + } + } + elem =kzalloc_obj (*elem);if (!elem)return -ENOMEM ;
Signature · 1 line
2.47.3
RFC PATCH 9/16 ALSA: mixer_audient: Add readback-free parameter set
In reply to Will PorterFrom: Christian Ruppert <[email protected]>
Add a flag to systematically force parameter writing without prior readback to certain control types. In preparation of the id14 driver.
--- sound/usb/mixer_audient.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
sound/usb/mixer_audient.c +8 -3
@@ -39,6 +39,7 @@ static const DECLARE_TLV_DB_MINMAX_MUTE(snd_audient_tlv_mixer, -12800, 600);#define SND_AUDIENT_CTYPE_FLAGS_SIGNED BIT(0)#define SND_AUDIENT_CTYPE_FLAGS_INIT_HW BIT(1) +#define SND_AUDIENT_CTYPE_FLAGS_FORCE_SET BIT(2) static const struct snd_audient_ctrl_type { snd_ctl_elem_type_t type;
@@ -313,9 +314,13 @@ static int snd_audient_raw_set_one(struct usb_mixer_interface *const mixer,int ret;u32 val; - ret =snd_audient_raw_get_one (mixer, ctype, cidx, &val); -if (ret <0 ) -return ret; +if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_FORCE_SET ) { + val = !value;/* just make it different */ + }else { + ret =snd_audient_raw_get_one (mixer, ctype, cidx, &val); +if (ret <0 ) +return ret; + }if (val != value) {__le32 buf =cpu_to_le32 (value);
Signature · 1 line
2.47.3
RFC PATCH 10/16 ALSA: mixer_audient: add control value caching
In reply to Will PorterFrom: Christian Ruppert <[email protected]>
In preparation of id14 support, add control value caching.
--- sound/usb/mixer_audient.c | 185 ++++++++++++++++++++++++++++++-------- 1 file changed, 149 insertions(+), 36 deletions(-)
sound/usb/mixer_audient.c +149 -36
@@ -40,6 +40,7 @@ static const DECLARE_TLV_DB_MINMAX_MUTE(snd_audient_tlv_mixer, -12800, 600);#define SND_AUDIENT_CTYPE_FLAGS_SIGNED BIT(0)#define SND_AUDIENT_CTYPE_FLAGS_INIT_HW BIT(1)#define SND_AUDIENT_CTYPE_FLAGS_FORCE_SET BIT(2) +#define SND_AUDIENT_CTYPE_FLAGS_CACHE BIT(3) static const struct snd_audient_ctrl_type { snd_ctl_elem_type_t type;
@@ -51,7 +52,7 @@ static const struct snd_audient_ctrl_type {union {long integer; } max;/* for booleans holds physical int value for true */ -u32 init; +u32 init;/* hardware and cache are initialized to this value */ const unsigned int *tlv;u8 unit;u8 sel;
@@ -91,7 +92,8 @@ static const struct snd_audient_ctrl_type { }, [SND_AUDIENT_TYPE_MIXER] = { .type = SNDRV_CTL_ELEM_TYPE_INTEGER, - .flags = SND_AUDIENT_CTYPE_FLAGS_SIGNED, + .flags =SND_AUDIENT_CTYPE_FLAGS_SIGNED + | SND_AUDIENT_CTYPE_FLAGS_CACHE, .len = 2, .min.integer = -128 * 256, .max.integer = 6 * 256,
@@ -238,6 +240,26 @@ static inline u16 snd_audient_kctl_channels(struct snd_kcontrol *kctl)return info->channels; } +/* +* A cached value is valid once a transfer confirmed it: a read, or a write +* that succeeded. A probe transfer that fails leaves it invalid. CACHE | +* FORCE_SET without INIT_HW keeps the earlier behaviour: the init value is +* assumed, without a transfer. +*/ +struct snd_audient_cache_entry { +u32 value; +bool valid; +}; + +/* Cache entry of element channel i, or NULL for an uncached control. */ +static inline struct snd_audient_cache_entry * +snd_audient_cache_slot (struct usb_mixer_elem_info *elem,unsigned int i) +{ +struct snd_audient_cache_entry *const cache = elem->private_data; + +return cache ? cache + i :NULL ; +} +#define AUDIENT_REQTYPE_SET (USB_DIR_OUT | USB_TYPE_CLASS \ | USB_RECIP_INTERFACE)
@@ -287,12 +309,26 @@ static inline int snd_audient_set_cur(struct usb_mixer_interface *mixer,static int snd_audient_raw_get_one (struct usb_mixer_interface *const mixer,const struct snd_audient_ctrl_type *const ctype, +struct snd_audient_cache_entry *const slot,const u8 cidx,u32 *const value) {int ret;__le32 buf =0 ;s32 val; +if (slot && slot->valid) { + *value = slot->value; + +return ctype->len; + } + +/* +* Cached FORCE_SET controls are treated as write-only: an invalid +* cache entry does not trigger a GET. +*/ +if (slot && (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_FORCE_SET )) +return -ENODATA ; + ret =snd_audient_get_cur (mixer, ctype, cidx, &buf);if (ret <0 )return ret;
@@ -304,43 +340,57 @@ static int snd_audient_raw_get_one(struct usb_mixer_interface *const mixer, *value = val; +if (slot) { + slot->value = val; + slot->valid = true; + } +return ret; }static int snd_audient_raw_set_one (struct usb_mixer_interface *const mixer,const struct snd_audient_ctrl_type *const ctype, -const u8 cidx,const u32 value) +struct snd_audient_cache_entry *const slot, +const u8 cidx,const u32 value, +bool force) {int ret;u32 val; -if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_FORCE_SET ) { +if (force) { val = !value;/* just make it different */ }else { - ret =snd_audient_raw_get_one (mixer, ctype, cidx, &val); -if (ret <0 ) + ret =snd_audient_raw_get_one (mixer, ctype, slot, cidx, &val); +if (ret == -ENODATA )/* FORCE_SET and not cached yet */ + val = !value;/* just make it different */ +else if (ret <0 )return ret; } -if (val != value) { + force = force || (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_FORCE_SET ); + +if (force || (val != value)) {__le32 buf =cpu_to_le32 (value); ret =snd_audient_set_cur (mixer, ctype, cidx, &buf);if (ret <0 )return ret; -return 1 ; +if (slot) { + slot->value = value; + slot->valid = true; + } } -return 0 ; +return val != value; }static int snd_ctl_audient_boolean_get (struct snd_kcontrol *kctl,struct snd_ctl_elem_value *ctl_val) { -struct usb_mixer_elem_list *const list =snd_kcontrol_chip (kctl); -struct usb_mixer_interface *const mixer = list->mixer; +struct usb_mixer_elem_info *const elem =snd_kcontrol_chip (kctl); +struct usb_mixer_interface *const mixer = elem->head.mixer;const unsigned int nchan =snd_audient_kctl_channels (kctl);const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl);
@@ -353,13 +403,19 @@ static int snd_ctl_audient_boolean_get(struct snd_kcontrol *kctl,CLASS (snd_usb_lock, pm)(mixer->chip);if (pm.err <0 )return pm.err; +/* serializes the transfers and the cache, also between gets */ +guard (mutex)(&mixer->lock);for (i =0 ; i < hwchan; i++) {u32 buf;int ret; - ret =snd_audient_raw_get_one (mixer, ctype, base + i, &buf); -if (ret <0 ) + ret =snd_audient_raw_get_one (mixer, ctype, +snd_audient_cache_slot (elem, i), + base + i, &buf); +if (ret == -ENODATA )/* unknown write-only value: off */ + buf = ctype->min.integer; +else if (ret <0 )return ret; ctl_val->value.integer.value[i] = (buf == ctype->min.integer)
@@ -375,8 +431,8 @@ static int snd_ctl_audient_boolean_get(struct snd_kcontrol *kctl,static int snd_ctl_audient_boolean_set (struct snd_kcontrol *kctl,struct snd_ctl_elem_value *ctl_val) { -struct usb_mixer_elem_list *list =snd_kcontrol_chip (kctl); -struct usb_mixer_interface *mixer = list->mixer; +struct usb_mixer_elem_info *const elem =snd_kcontrol_chip (kctl); +struct usb_mixer_interface *const mixer = elem->head.mixer;const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl);const struct snd_audient_ctrl_type *const ctype
@@ -389,13 +445,17 @@ static int snd_ctl_audient_boolean_set(struct snd_kcontrol *kctl,CLASS (snd_usb_lock, pm)(mixer->chip);if (pm.err <0 )return pm.err; +/* serializes the transfers and the cache, also between gets */ +guard (mutex)(&mixer->lock);for (i =0 ; i < hwchan; i++) {u32 buf = ctl_val->value.integer.value[i] ? ctype->max.integer : ctype->min.integer;int ret; - ret =snd_audient_raw_set_one (mixer, ctype, base + i, buf); + ret =snd_audient_raw_set_one (mixer, ctype, +snd_audient_cache_slot (elem, i), + base + i, buf, false);if (ret <0 )return ret;
@@ -409,8 +469,8 @@ static int snd_ctl_audient_boolean_set(struct snd_kcontrol *kctl,static int snd_ctl_audient_integer_get (struct snd_kcontrol *kctl,struct snd_ctl_elem_value *ctl_val) { -struct usb_mixer_elem_list *const list =snd_kcontrol_chip (kctl); -struct usb_mixer_interface *const mixer = list->mixer; +struct usb_mixer_elem_info *const elem =snd_kcontrol_chip (kctl); +struct usb_mixer_interface *const mixer = elem->head.mixer;const unsigned int nchan =snd_audient_kctl_channels (kctl);const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl);
@@ -423,13 +483,19 @@ static int snd_ctl_audient_integer_get(struct snd_kcontrol *kctl,CLASS (snd_usb_lock, pm)(mixer->chip);if (pm.err <0 )return pm.err; +/* serializes the transfers and the cache, also between gets */ +guard (mutex)(&mixer->lock);for (i =0 ; i < hwchan; i++) {s32 val;int ret; - ret =snd_audient_raw_get_one (mixer, ctype, base + i, &val); -if (ret <0 ) + ret =snd_audient_raw_get_one (mixer, ctype, +snd_audient_cache_slot (elem, i), + base + i, &val); +if (ret == -ENODATA )/* unknown write-only value: minimum */ + val = ctype->min.integer; +else if (ret <0 )return ret;if (val < ctype->min.integer)
@@ -450,8 +516,8 @@ static int snd_ctl_audient_integer_get(struct snd_kcontrol *kctl,static int snd_ctl_audient_integer_set (struct snd_kcontrol *kctl,struct snd_ctl_elem_value *ctl_val) { -struct usb_mixer_elem_list *list =snd_kcontrol_chip (kctl); -struct usb_mixer_interface *mixer = list->mixer; +struct usb_mixer_elem_info *const elem =snd_kcontrol_chip (kctl); +struct usb_mixer_interface *mixer = elem->head.mixer;const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl);const struct snd_audient_ctrl_type *const ctype
@@ -471,12 +537,16 @@ static int snd_ctl_audient_integer_set(struct snd_kcontrol *kctl,CLASS (snd_usb_lock, pm)(mixer->chip);if (pm.err <0 )return pm.err; +/* serializes the transfers and the cache, also between gets */ +guard (mutex)(&mixer->lock);for (i =0 ; i < hwchan; i++) {s32 val = ctl_val->value.integer.value[i];int ret; - ret =snd_audient_raw_set_one (mixer, ctype, base + i, val); + ret =snd_audient_raw_set_one (mixer, ctype, +snd_audient_cache_slot (elem, i), + base + i, val, false);if (ret <0 )return ret;
@@ -517,6 +587,8 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer,struct snd_kcontrol *kctl;struct usb_mixer_elem_info *elem; +int ret; + knew.iface =SNDRV_CTL_ELEM_IFACE_MIXER ; knew.name = ctrl->name; knew.info = snd_ctl_audient_info;
@@ -524,7 +596,9 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer, ctrl->hwchannels); knew.tlv.p = ctype->tlv; knew.access =SNDRV_CTL_ELEM_ACCESS_READWRITE - |SNDRV_CTL_ELEM_ACCESS_VOLATILE + | ((ctype->flags &SND_AUDIENT_CTYPE_FLAGS_CACHE ) + ?0 + :SNDRV_CTL_ELEM_ACCESS_VOLATILE ) | (ctype->tlv ?SNDRV_CTL_ELEM_ACCESS_TLV_READ :0 );switch (ctype->type) {
@@ -540,36 +614,75 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer,return -EINVAL ; } + elem =kzalloc (sizeof (*elem) + + ((ctype->flags &SND_AUDIENT_CTYPE_FLAGS_CACHE ) + ? (sizeof (struct snd_audient_cache_entry ) + * ctrl->hwchannels) + :0 ), +GFP_KERNEL ); +if (!elem) +return -ENOMEM ; + + elem->head.mixer = mixer; + elem->channels = ctrl->channels; + +if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_CACHE ) + elem->private_data = elem +1 ; + +/* +* A failed probe transfer must not fail the card: warn and keep the +* control. Its cache entry stays invalid, so a readable control reads +* the device again on its next get, and a write-only control shows an +* unknown value until a put succeeds. +*/ if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_INIT_HW ) {int i;for (i =0 ; i < ctrl->hwchannels; i++) { -int ret =snd_audient_raw_set_one (mixer, ctype, - ctrl->val_offs + i, - ctype->init); + ret =snd_audient_raw_set_one (mixer, ctype, +snd_audient_cache_slot (elem, i), + ctrl->val_offs + i, + ctype->init, true);if (ret <0 )usb_audio_warn (mixer->chip,"%s: cannot set channel %d (%d)\n" , ctrl->name, i, ret); } - } - - elem =kzalloc_obj (*elem); -if (!elem) -return -ENOMEM ; + }else if (elem->private_data) { +struct snd_audient_cache_entry *const cache = elem->private_data; +int i; - elem->head.mixer = mixer; - elem->channels = ctrl->channels; +for (i =0 ; i < ctrl->hwchannels; i++) { +if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_FORCE_SET ) { + cache[i].value = ctype->init; + cache[i].valid = true; +continue ; + } + + ret =snd_audient_raw_get_one (mixer, ctype, cache + i, + ctrl->val_offs + i, + &cache[i].value); +if (ret <0 ) +usb_audio_warn (mixer->chip, +"%s: cannot read channel %d (%d)\n" , + ctrl->name, i, ret); + } + } kctl =snd_ctl_new1 (&knew, elem);if (!kctl) { -kfree (elem); -return -ENOMEM ; + ret = -ENOMEM ; + goto free_elem; } kctl->private_free = snd_usb_mixer_elem_free;return snd_usb_mixer_add_control (&elem->head, kctl); + +free_elem: +kfree (elem); + +return ret; }
Signature · 1 line
2.47.3
RFC PATCH 11/16 ALSA: mixer_audient: Create matrix programmatically
In reply to Will PorterFrom: Christian Ruppert <[email protected]>
Most Audient devices seem to have a similar mixer matrix with many identical channels. The only difference between devices seems to be the matrix' dimension. Create it programmatically in a loop rather than from the controls table.
--- sound/usb/mixer_audient.c | 77 +++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 43 deletions(-)
sound/usb/mixer_audient.c +34 -43
@@ -105,7 +105,7 @@ static const struct snd_audient_ctrl_type {struct snd_audient_ctrl { -char *name; +const char *const name;enum snd_audient_type type;unsigned int channels;unsigned int hwchannels;
@@ -134,48 +134,6 @@ static const struct snd_audient_ctrl snd_audient_evo4_controls[] = { .hwchannels = 1, .val_offs = 0, }, - { - .name = "Mic 1 Capture Volume", - .type = SND_AUDIENT_TYPE_MIXER, - .channels = 2, - .hwchannels = 2, - .val_offs = 0, - }, - { - .name = "Mic 2 Capture Volume", - .type = SND_AUDIENT_TYPE_MIXER, - .channels = 2, - .hwchannels = 2, - .val_offs = 2, - }, - { - .name = "Master Left Capture Volume", - .type = SND_AUDIENT_TYPE_MIXER, - .channels = 2, - .hwchannels = 2, - .val_offs = 4, - }, - { - .name = "Master Right Capture Volume", - .type = SND_AUDIENT_TYPE_MIXER, - .channels = 2, - .hwchannels = 2, - .val_offs = 6, - }, - { - .name = "Loopback Left Capture Volume", - .type = SND_AUDIENT_TYPE_MIXER, - .channels = 2, - .hwchannels = 2, - .val_offs = 8, - }, - { - .name = "Loopback Right Capture Volume", - .type = SND_AUDIENT_TYPE_MIXER, - .channels = 2, - .hwchannels = 2, - .val_offs = 10, - }, { .name = "Mic 1 Phantom Capture Switch", .type = SND_AUDIENT_TYPE_PHANTOM,
@@ -193,13 +151,27 @@ static const struct snd_audient_ctrl snd_audient_evo4_controls[] = { { 0 }, /* sentinel */ }; +static const char *const snd_audient_evo4_matrix[] = { +"Mic 1 Capture Volume" , +"Mic 2 Capture Volume" , +"Master Left Capture Volume" , +"Master Right Capture Volume" , +"Loopback Left Capture Volume" , +"Loopback Right Capture Volume" , +NULL +}; +static const struct audient_devinfo {u32 usb_id;const struct snd_audient_ctrl *controls; +const char *const *const matrix_names; +const unsigned int matrix_channels; } audient_devinfo[] = { { .usb_id =USB_ID (USB_AUDIENT_VID ,USB_EVO4_PID ), .controls = snd_audient_evo4_controls, + .matrix_names = snd_audient_evo4_matrix, + .matrix_channels =2 , }, {0 }/* sentinel */ };
@@ -692,6 +664,8 @@ int snd_audient_controls_create(struct usb_mixer_interface *mixer)const struct audient_devinfo *info;const struct snd_audient_ctrl *ctrl; +int i; +for (info = audient_devinfo; info->controls; info++)if (info->usb_id == mixer->chip->usb_id)break ;
@@ -706,5 +680,22 @@ int snd_audient_controls_create(struct usb_mixer_interface *mixer)return ret; } +if (info->matrix_names) { +for (i =0 ; info->matrix_names[i]; i++) { +const struct snd_audient_ctrl c = { + .name = info->matrix_names[i], + .type =SND_AUDIENT_TYPE_MIXER , + .channels = info->matrix_channels, + .hwchannels = info->matrix_channels, + .val_offs = i * info->matrix_channels, + }; + +const int ret =snd_audient_add_ctrl (mixer, &c); + +if (ret <0 ) +return ret; + } + } +return 0 ; }
Signature · 1 line
2.47.3
RFC PATCH 12/16 ALSA: mixer_audient: Add a step size to integer controls
In reply to Will PorterThe iD14 level controls use s16 values in 1/256 dB. Expose them in 1 dB steps, matching the volume knob's adjustment. Let a control type give a step size: the control then counts steps from the minimum, as the generic USB mixer does with the RANGE resolution. A device value between two steps reads as the nearest step, clamped to the maximum. Types without a step size keep the device value.
--- sound/usb/mixer_audient.c | 55 ++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 12 deletions(-)
sound/usb/mixer_audient.c +43 -12
@@ -53,6 +53,7 @@ static const struct snd_audient_ctrl_type {long integer; } max;/* for booleans holds physical int value for true */ u32 init;/* hardware and cache are initialized to this value */ +unsigned int res;/* integers: device units per control step, 0 = 1 */ const unsigned int *tlv;u8 unit;u8 sel;
@@ -438,6 +439,39 @@ static int snd_ctl_audient_boolean_set(struct snd_kcontrol *kctl,return changed; } +/* +* With a step size (res), an integer control counts steps from min: +* 0 ... (max - min) / res. Without one it shows the device value. +*/ +static long snd_audient_int_max (const struct snd_audient_ctrl_type *ctype) +{ +return ctype->res ? (ctype->max.integer - ctype->min.integer) / ctype->res + : ctype->max.integer; +} + +static long snd_audient_int_min (const struct snd_audient_ctrl_type *ctype) +{ +return ctype->res ?0 : ctype->min.integer; +} + +static long snd_audient_int_to_ctl (const struct snd_audient_ctrl_type *ctype, +long val) +{ + val =clamp (val, ctype->min.integer, ctype->max.integer); +if (!ctype->res) +return val; + +/* round a device value between two steps to the nearest one */ +return min (DIV_ROUND_CLOSEST (val - ctype->min.integer, (long )ctype->res), +snd_audient_int_max (ctype)); +} + +static long snd_audient_int_from_ctl (const struct snd_audient_ctrl_type *ctype, +long val) +{ +return ctype->res ? ctype->min.integer + val * ctype->res : val; +} +static int snd_ctl_audient_integer_get (struct snd_kcontrol *kctl,struct snd_ctl_elem_value *ctl_val) {
@@ -470,17 +504,12 @@ static int snd_ctl_audient_integer_get(struct snd_kcontrol *kctl,else if (ret <0 )return ret; -if (val < ctype->min.integer) - val = ctype->min.integer; - -if (val > ctype->max.integer) - val = ctype->max.integer; - - ctl_val->value.integer.value[i] = val; + ctl_val->value.integer.value[i] = +snd_audient_int_to_ctl (ctype, val); }for (; i < nchan; i++) - ctl_val->value.integer.value[i] = ctype->min.integer; + ctl_val->value.integer.value[i] =snd_audient_int_min (ctype);return 0 ; }
@@ -502,7 +531,8 @@ static int snd_ctl_audient_integer_set(struct snd_kcontrol *kctl,for (i =0 ; i < hwchan; i++) {long val = ctl_val->value.integer.value[i]; -if ((val < ctype->min.integer) || (val > ctype->max.integer)) +if (val <snd_audient_int_min (ctype) || + val >snd_audient_int_max (ctype))return -EINVAL ; }
@@ -513,7 +543,8 @@ static int snd_ctl_audient_integer_set(struct snd_kcontrol *kctl,guard (mutex)(&mixer->lock);for (i =0 ; i < hwchan; i++) { -s32 val = ctl_val->value.integer.value[i]; +s32 val =snd_audient_int_from_ctl (ctype, + ctl_val->value.integer.value[i]);int ret; ret = snd_audient_raw_set_one(mixer, ctype,
@@ -542,8 +573,8 @@ static int snd_ctl_audient_info(struct snd_kcontrol *kctl, uinfo->value.integer.min =0 ; uinfo->value.integer.max =1 ; }else { - uinfo->value.integer.min = ctype->min.integer; - uinfo->value.integer.max = ctype->max.integer; + uinfo->value.integer.min =snd_audient_int_min (ctype); + uinfo->value.integer.max =snd_audient_int_max (ctype); }return 0 ;
Signature · 1 line
2.47.3
RFC PATCH 13/16 ALSA: mixer_audient: Add enumerated controls
In reply to Will PorterThe iD14 has selectors with a fixed set of device values: output routing, mono mode, the iD key function, talkback source and the digital input mode. Add an enumerated control type with a value list.
The item list has one item more than the values. A put cannot select it. A get shows it for a device value outside the list, so a value set by other means stays visible as such, not as a wrong item, and for a write-only value that no write has confirmed.
--- sound/usb/mixer_audient.c | 130 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+)
sound/usb/mixer_audient.c +130 -0
@@ -42,6 +42,27 @@ static const DECLARE_TLV_DB_MINMAX_MUTE(snd_audient_tlv_mixer, -12800, 600);#define SND_AUDIENT_CTYPE_FLAGS_FORCE_SET BIT(2)#define SND_AUDIENT_CTYPE_FLAGS_CACHE BIT(3) +/* +* An enumerated control: item i sends values[i]. The texts have one item +* more than the values. A put cannot select that last item: a get shows it +* for a device value outside the list ("Other"), or for a write-only value +* that no write has confirmed ("Unknown"). +*/ +struct snd_audient_enum { +const char *const *texts; +const u32 *values; +unsigned int items; +}; + +#define SND_AUDIENT_ENUM (name, texts_, ...) \ + static const u32 name##_values[] = { __VA_ARGS__ }; \ + static const struct snd_audient_enum name = { \ + .texts = texts_, \ + .values = name##_values, \ + .items = ARRAY_SIZE(name##_values), \ + }; \ + static_assert(ARRAY_SIZE(texts_) == ARRAY_SIZE(name##_values) + 1) + static const struct snd_audient_ctrl_type { snd_ctl_elem_type_t type; unsigned long flags;
@@ -54,6 +75,7 @@ static const struct snd_audient_ctrl_type { } max;/* for booleans holds physical int value for true */ u32 init;/* hardware and cache are initialized to this value */ unsigned int res;/* integers: device units per control step, 0 = 1 */ +const struct snd_audient_enum *enumeration;const unsigned int *tlv;u8 unit;u8 sel;
@@ -560,12 +582,116 @@ static int snd_ctl_audient_integer_set(struct snd_kcontrol *kctl,return changed; } +static unsigned int snd_audient_enum_item (const struct snd_audient_enum *e, +u32 value) +{ +unsigned int item; + +for (item =0 ; item < e->items; item++) +if (e->values[item] == value) +break ; + +return item;/* e->items: not in the list */ +} + +static int snd_ctl_audient_enum_get (struct snd_kcontrol *kctl, +struct snd_ctl_elem_value *ctl_val) +{ +struct usb_mixer_elem_info *const elem =snd_kcontrol_chip (kctl); +struct usb_mixer_interface *const mixer = elem->head.mixer; + +const unsigned int nchan =snd_audient_kctl_channels (kctl); +const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl); +const struct snd_audient_ctrl_type *const ctype + =snd_audient_kctl_type (kctl); +const u8 base =snd_audient_kctl_cidxoffs (kctl); + +unsigned int i; + +CLASS (snd_usb_lock, pm)(mixer->chip); +if (pm.err <0 ) +return pm.err; +/* serializes the transfers and the cache, also between gets */ +guard (mutex)(&mixer->lock); + +for (i =0 ; i < hwchan; i++) { +u32 val; +int ret; + + ret =snd_audient_raw_get_one (mixer, ctype, +snd_audient_cache_slot (elem, i), + base + i, &val); +if (ret == -ENODATA ) {/* unknown write-only value */ + ctl_val->value.enumerated.item[i] = + ctype->enumeration->items; +continue ; + }else if (ret <0 ) { +return ret; + } + + ctl_val->value.enumerated.item[i] = +snd_audient_enum_item (ctype->enumeration, val); + } + +for (; i < nchan; i++) + ctl_val->value.enumerated.item[i] =0 ; + +return 0 ; +} + +static int snd_ctl_audient_enum_set (struct snd_kcontrol *kctl, +struct snd_ctl_elem_value *ctl_val) +{ +struct usb_mixer_elem_info *const elem =snd_kcontrol_chip (kctl); +struct usb_mixer_interface *const mixer = elem->head.mixer; + +const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl); +const struct snd_audient_ctrl_type *const ctype + =snd_audient_kctl_type (kctl); +const struct snd_audient_enum *const e = ctype->enumeration; +const u8 base =snd_audient_kctl_cidxoffs (kctl); + +unsigned int i; +int changed =0 ; + +for (i =0 ; i < hwchan; i++) +if (ctl_val->value.enumerated.item[i] >= e->items) +return -EINVAL ; + +CLASS (snd_usb_lock, pm)(mixer->chip); +if (pm.err <0 ) +return pm.err; +/* serializes the transfers and the cache, also between gets */ +guard (mutex)(&mixer->lock); + +for (i =0 ; i < hwchan; i++) { +const unsigned int item = ctl_val->value.enumerated.item[i]; +int ret; + + ret =snd_audient_raw_set_one (mixer, ctype, +snd_audient_cache_slot (elem, i), + base + i, e->values[item], false); +if (ret <0 ) +return ret; + +if (ret) + changed =1 ; + } + +return changed; +} +static int snd_ctl_audient_info (struct snd_kcontrol *kctl,struct snd_ctl_elem_info *uinfo) {const struct snd_audient_ctrl_type *const ctype =snd_audient_kctl_type (kctl); +if (ctype->type ==SNDRV_CTL_ELEM_TYPE_ENUMERATED ) +return snd_ctl_enum_info (uinfo,snd_audient_kctl_channels (kctl), + ctype->enumeration->items +1 , + ctype->enumeration->texts); + uinfo->type = ctype->type; uinfo->count =snd_audient_kctl_channels (kctl);
@@ -613,6 +739,10 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer, knew.get = snd_ctl_audient_boolean_get; knew.put = snd_ctl_audient_boolean_set;break ; +case SNDRV_CTL_ELEM_TYPE_ENUMERATED : + knew.get = snd_ctl_audient_enum_get; + knew.put = snd_ctl_audient_enum_set; +break ;default :return -EINVAL ; }
Signature · 1 line
2.47.3
RFC PATCH 14/16 ALSA: usb-audio: Give the Audient iD14 MkI its own mixer map
In reply to Will PorterThe iD14 MkI (2708:0002) and MkII (2708:0008) share audient_id14_map. Later commits add MkI vendor controls that replace some of the generic MkI controls. The MkII keeps the generic controls. Give the MkI its own copy of the map.
No functional change.
--- sound/usb/mixer_maps.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
sound/usb/mixer_maps.c +7 -1
@@ -526,6 +526,12 @@ static const struct usbmix_name_map audient_id14_map[] = { {} }; +/* Audient iD14 MkI: model-specific control map. */ +static const struct usbmix_name_map audient_id14_mk1_map[] = { + {12 ,"Monitor Mix Playback" },/* FU, partial coverage */ + {} +}; +/* * Audient iD24: feature unit 12 ("Speaker Playback Volume") sits in the * monitor-mixer branch and does not apply volume to all of its channels;
@@ -638,7 +644,7 @@ static const struct usbmix_ctl_map usbmix_ctl_maps[] = { {/* Audient iD14 MkI */ .id = USB_ID(0x2708, 0x0002), - .map = audient_id14_map, + .map = audient_id14_mk1_map, }, {/* Audient EVO4 MkI */
Signature · 1 line
2.47.3
RFC PATCH 15/16 ALSA: mixer_audient: Add Audient iD14 MkI controls
In reply to Will PorterThe iD14 MkI (2708:0002) has its monitor controller on extension unit 54 and its output routing on extension unit 51. The headphone level is on feature unit 10 (CN 3-4, which the descriptor does not declare). The mixer is mixer unit 60. The generic driver cannot find the vendor controls and creates wrong controls for mixer unit 60 and feature unit
11. Add the MkI as a device with these tables. Apart from the tables and their macros, the patch adds the device ID, its case in mixer_quirks.c and the map entries that hide the generic controls.
Monitor and routing controls: speaker volume, cut, dim, dim level, mono, mono mode, polarity, talkback, headphone volume and mute, and one routing selector per output channel. All of them read the device on every get: the front panel knob changes the volumes and the cut and mute states.
The volumes are s16 values in 1/256 dB from -128 to 0 dB, in the 1 dB steps of the knob. -128 dB does not mute the headphones, so the TLV does not declare a mute.
DAW Thru plays the USB stream past the monitor controller, so the main output selectors name it "DAW Thru (full scale)". The headphone volume and mute still act on every headphone source, so the headphone selectors name it "DAW Thru".
Mixer matrix: mixer unit 60 mixes 14 inputs (Mic 1-2, Digi 1-8, DAW 1-4) into four outputs (Main L/R, Cue L/R), CN = input * 4 + output. GET RANGE reports -127 to 0 dB in 1 dB steps, so the generic driver creates four "Analogue 4 Volume" controls with values from 0 to 127. The crosspoints take -128 dB (mute) to +6 dB in 1/256 dB steps, as on the EVO4, so they use the same control type. Add one stereo control per input and output pair: "Mix Main <input> Playback Volume" and "Mix Cue <input> Playback Volume". Hide the generic controls in the MkI map. The driver reads each crosspoint at probe and writes nothing to the mixer.
Write-only controls: some MkI controls cannot be read back:
- GET stalls for the input gain boost and polarity (feature unit 11), the iD key function and the digital input mode.
- GET of the talkback source answers 0, whatever value a SET wrote.
For FU 11 the generic driver creates "Input Gain Control" and "Phase Inverter Control" and logs "cannot get min/max values". Add:
- Mic 1/2 Boost Capture Switch (+10 dB)
- Mic 1/2 and Digi 1/2 Polarity Invert Capture Switch
- iD Key Function Playback Enum (ScrollControl, Mono, Mono + Polarity, Dim, Talkback)
- Talkback Source Capture Enum (None, Mic 1-2, Digi 1-8)
- Digital In Mode Capture Enum (ADAT, S/PDIF)
and hide the generic FU 11 controls in the MkI map. The device refuses polarity on Digi 3-8 with EPIPE, in ADAT and in S/PDIF mode, so Digi 3-8 have no polarity control.
These controls use the cache, init and force-set flags: they show the last value written, every put sends its value, and the probe writes each one once so that the value shown is true:
- boost and polarity off, iD key ScrollControl, talkback source None
- S/PDIF: the MkI's measured power-on mode
If a probe write fails, the card still registers: the control shows "Unknown" (or off) until a put succeeds.
The probe write replaces any value the device kept. On mains power the device keeps its values across a replug, so the controls return to the probe values until alsactl restore runs.
--- sound/usb/mixer_audient.c | 313 ++++++++++++++++++++++++++++++++++++++ sound/usb/mixer_audient.h | 1 + sound/usb/mixer_maps.c | 2 + sound/usb/mixer_quirks.c | 3 + 4 files changed, 319 insertions(+)
sound/usb/mixer_audient.c +313 -0
@@ -3,6 +3,10 @@* Audient driver for ALSA * Copyright (C) 2026 Christian Ruppert <[email protected]> * +* Supported models: EVO4 (2708:0006), iD14 MkI (2708:0002). +* The iD14 MkII and other iD models keep the generic driver: their units +* may differ. +* * EVO4 support is based on the work of Ivan Hazucha for audient-evo-py. * https://github.com/vanzaho/audient-evo-py/ */
@@ -10,6 +14,7 @@#include <asm/byteorder.h> #include <linux/usb.h> +#include <linux/usb/audio.h> #include <linux/usb/audio-v2.h> #include <linux/slab.h> #include <linux/types.h>
@@ -31,6 +36,25 @@ enum snd_audient_type {SND_AUDIENT_TYPE_MUTE ,SND_AUDIENT_TYPE_MUTE_OUT ,SND_AUDIENT_TYPE_MIXER , +SND_AUDIENT_TYPE_ID14_MON_VOLUME , +SND_AUDIENT_TYPE_ID14_MON_CUT , +SND_AUDIENT_TYPE_ID14_MON_DIM , +SND_AUDIENT_TYPE_ID14_MON_DIM_LEVEL , +SND_AUDIENT_TYPE_ID14_MON_MONO , +SND_AUDIENT_TYPE_ID14_MON_MONO_MODE , +SND_AUDIENT_TYPE_ID14_MON_POLARITY , +SND_AUDIENT_TYPE_ID14_MON_TALKBACK , +SND_AUDIENT_TYPE_ID14_HP_VOLUME , +SND_AUDIENT_TYPE_ID14_HP_MUTE , +SND_AUDIENT_TYPE_ID14_ROUTE_MAIN_L , +SND_AUDIENT_TYPE_ID14_ROUTE_MAIN_R , +SND_AUDIENT_TYPE_ID14_ROUTE_HP_L , +SND_AUDIENT_TYPE_ID14_ROUTE_HP_R , +SND_AUDIENT_TYPE_ID14_IN_BOOST , +SND_AUDIENT_TYPE_ID14_IN_POLARITY , +SND_AUDIENT_TYPE_ID14_MON_ID_KEY , +SND_AUDIENT_TYPE_ID14_MON_TALKBACK_SRC , +SND_AUDIENT_TYPE_ID14_OPTICAL_MODE ,SND_AUDIENT_TYPE_NCTYPES };
@@ -63,6 +87,151 @@ struct snd_audient_enum { }; \ static_assert(ARRAY_SIZE(texts_) == ARRAY_SIZE(name##_values) + 1) +/* +* iD14 MkI units. The monitor controller, output routing, headphone level, +* input options and the mixer sit on extension units and on feature units +* whose descriptors declare no controls; the generic driver cannot find them. + */ +#define ID14_IT_DIGITAL 0x01/* input terminal: optical and coaxial */ +#define ID14_FU_OUT 0x0a/* before the outputs: CN 3-4 headphones */ +#define ID14_FU_IN 0x0b/* inputs: CN 1-2 Mic, 3-10 Digi */ +#define ID14_FU_MIX 0x0c/* after the mixer: CN 1-2 Main, 3-4 Cue */ +#define ID14_ROUTE 0x33/* routing XU: CN = destination */ +#define ID14_MON 0x36/* monitor controller XU */ + +/* Monitor controller selectors */ +#define ID14_MON_MONO 0x00 +#define ID14_MON_MONO_MODE 0x01 +#define ID14_MON_POLARITY 0x03 +#define ID14_MON_CUT 0x04 +#define ID14_MON_DIM 0x05 +#define ID14_MON_DIM_LEVEL 0x06/* s16, 1/256 dB */ +#define ID14_MON_TALKBACK 0x07 +#define ID14_MON_TALKBACK_SRC 0x08/* GET always returns 0 */ +#define ID14_MON_ID_KEY 0x10/* u16: the selector the iD key toggles */ +#define ID14_MON_VOLUME 0x12/* s16, 1/256 dB; the knob also sets it */ + +#define ID14_IN_BOOST 0x0b/* s16: 0x0a00 = +10 dB, 0 = off */ +#define ID14_IN_POLARITY 0x0d +#define ID14_IT_OPTICAL_MODE 0x00/* u32: 0 ADAT, 1 S/PDIF */ + +#define ID14_ROUTE_SOURCE 0x06/* u8: source of the destination */ + +/* +* iD14 volumes: s16 in 1/256 dB, -128 ... 0 dB, in the 1 dB steps of the +* front panel knob. Control value 0 is -128 dB, 128 is 0 dB. -128 dB is not +* a mute: on the headphones the level stops falling at a small residual. +*/ +static const DECLARE_TLV_DB_SCALE(snd_audient_tlv_id14_vol, -12800, 100, 0); + +/* Mono mode: one-speaker sum (Left, Right) or phantom centre */ +static const char *const snd_audient_id14_mono_mode_texts[] = { +"Left" ,"Centre" ,"Right" ,"Other" , +}; +SND_AUDIENT_ENUM (snd_audient_id14_mono_mode, + snd_audient_id14_mono_mode_texts,1 ,0 ,2 ); + +/* +* Output routing. Main Mix is 0x14/0x15 on the main outputs and 0x18/0x19 +* on the headphones; DAW Thru on destination n plays DAW n + 1. DAW Thru +* bypasses the monitor controller (speaker volume, cut and dim), so the +* main outputs play the USB stream at full scale. The headphone volume and +* mute still act on every headphone source. +*/ +static const char *const snd_audient_id14_route_main_texts[] = { +"Main Mix" ,"Cue Mix" ,"DAW Thru (full scale)" ,"Other" , +}; +static const char *const snd_audient_id14_route_hp_texts[] = { +"Main Mix" ,"Cue Mix" ,"DAW Thru" ,"Other" , +}; +SND_AUDIENT_ENUM (snd_audient_id14_route_main_l, + snd_audient_id14_route_main_texts,0x14 ,0x10 ,0x00 ); +SND_AUDIENT_ENUM (snd_audient_id14_route_main_r, + snd_audient_id14_route_main_texts,0x15 ,0x11 ,0x01 ); +SND_AUDIENT_ENUM (snd_audient_id14_route_hp_l, + snd_audient_id14_route_hp_texts,0x18 ,0x10 ,0x02 ); +SND_AUDIENT_ENUM (snd_audient_id14_route_hp_r, + snd_audient_id14_route_hp_texts,0x19 ,0x11 ,0x03 ); + +/* +* iD key function: the value is the monitor controller selector the key +* toggles. ScrollControl (0xffff) toggles nothing: the knob then scrolls +* through the HID interface. The last item of a write-only enum shows a +* value that is not known. +*/ +static const char *const snd_audient_id14_id_key_texts[] = { +"ScrollControl" ,"Mono" ,"Mono + Polarity" ,"Dim" ,"Talkback" , +"Unknown" , +}; +SND_AUDIENT_ENUM (snd_audient_id14_id_key, snd_audient_id14_id_key_texts, +0xffff ,ID14_MON_MONO ,ID14_MON_POLARITY ,ID14_MON_DIM , +ID14_MON_TALKBACK ); + +/* Talkback source: the routing source number of the input; none = 0xff */ +static const char *const snd_audient_id14_talkback_texts[] = { +"None" ,"Mic 1" ,"Mic 2" ,"Digi 1" ,"Digi 2" ,"Digi 3" ,"Digi 4" , +"Digi 5" ,"Digi 6" ,"Digi 7" ,"Digi 8" ,"Unknown" , +}; +SND_AUDIENT_ENUM (snd_audient_id14_talkback, snd_audient_id14_talkback_texts, +0xff ,4 ,5 ,6 ,7 ,8 ,9 ,10 ,11 ,12 ,13 ); + +static const char *const snd_audient_id14_optical_texts[] = { +"ADAT" ,"S/PDIF" ,"Unknown" , +}; +SND_AUDIENT_ENUM (snd_audient_id14_optical, snd_audient_id14_optical_texts, +0 ,1 ); + +/* +* Write-only: GET stalls or does not report writes. Show the last value +* written, write the init value at probe, and send every put. +*/ +#define ID14_WO (SND_AUDIENT_CTYPE_FLAGS_CACHE \ + | SND_AUDIENT_CTYPE_FLAGS_FORCE_SET \ + | SND_AUDIENT_CTYPE_FLAGS_INIT_HW) + +#define ID14_BOOL (unit_, sel_) \ + { \ + .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, \ + .len = 1, \ + .min.integer = 0, \ + .max.integer = 1, \ + .unit = (unit_), \ + .sel = (sel_), \ + } + +/* 1 = cut or mute: shown as a switch that is off */ +#define ID14_BOOL_INV (unit_, sel_) \ + { \ + .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, \ + .len = 1, \ + .min.integer = 1, \ + .max.integer = 0, \ + .unit = (unit_), \ + .sel = (sel_), \ + } + +#define ID14_VOLUME (unit_, sel_) \ + { \ + .type = SNDRV_CTL_ELEM_TYPE_INTEGER, \ + .flags = SND_AUDIENT_CTYPE_FLAGS_SIGNED, \ + .len = 2, \ + .min.integer = -128 * 256, \ + .max.integer = 0, \ + .res = 256, \ + .tlv = snd_audient_tlv_id14_vol, \ + .unit = (unit_), \ + .sel = (sel_), \ + } + +#define ID14_ENUM (unit_, sel_, len_, enum_) \ + { \ + .type = SNDRV_CTL_ELEM_TYPE_ENUMERATED, \ + .len = (len_), \ + .enumeration = &(enum_), \ + .unit = (unit_), \ + .sel = (sel_), \ + } + static const struct snd_audient_ctrl_type { snd_ctl_elem_type_t type; unsigned long flags;
@@ -124,6 +293,88 @@ static const struct snd_audient_ctrl_type { .sel = 0x01, .tlv = snd_audient_tlv_mixer, }, + [SND_AUDIENT_TYPE_ID14_MON_VOLUME ] = + ID14_VOLUME(ID14_MON, ID14_MON_VOLUME), + [SND_AUDIENT_TYPE_ID14_MON_CUT ] = + ID14_BOOL_INV(ID14_MON, ID14_MON_CUT), + [SND_AUDIENT_TYPE_ID14_MON_DIM ] = + ID14_BOOL(ID14_MON, ID14_MON_DIM), + [SND_AUDIENT_TYPE_ID14_MON_DIM_LEVEL ] = + ID14_VOLUME(ID14_MON, ID14_MON_DIM_LEVEL), + [SND_AUDIENT_TYPE_ID14_MON_MONO ] = + ID14_BOOL(ID14_MON, ID14_MON_MONO), + [SND_AUDIENT_TYPE_ID14_MON_MONO_MODE ] = +ID14_ENUM (ID14_MON ,ID14_MON_MONO_MODE ,1 , + snd_audient_id14_mono_mode), + [SND_AUDIENT_TYPE_ID14_MON_POLARITY ] = + ID14_BOOL(ID14_MON, ID14_MON_POLARITY), + [SND_AUDIENT_TYPE_ID14_MON_TALKBACK ] = + ID14_BOOL(ID14_MON, ID14_MON_TALKBACK), + [SND_AUDIENT_TYPE_ID14_HP_VOLUME ] = + ID14_VOLUME(ID14_FU_OUT, UAC_FU_VOLUME), + [SND_AUDIENT_TYPE_ID14_HP_MUTE ] = + ID14_BOOL_INV(ID14_FU_OUT, UAC_FU_MUTE), + [SND_AUDIENT_TYPE_ID14_ROUTE_MAIN_L ] = +ID14_ENUM (ID14_ROUTE ,ID14_ROUTE_SOURCE ,1 , + snd_audient_id14_route_main_l), + [SND_AUDIENT_TYPE_ID14_ROUTE_MAIN_R ] = +ID14_ENUM (ID14_ROUTE ,ID14_ROUTE_SOURCE ,1 , + snd_audient_id14_route_main_r), + [SND_AUDIENT_TYPE_ID14_ROUTE_HP_L ] = +ID14_ENUM (ID14_ROUTE ,ID14_ROUTE_SOURCE ,1 , + snd_audient_id14_route_hp_l), + [SND_AUDIENT_TYPE_ID14_ROUTE_HP_R ] = +ID14_ENUM (ID14_ROUTE ,ID14_ROUTE_SOURCE ,1 , + snd_audient_id14_route_hp_r), +/* the documented boost is a fixed +10 dB */ + [SND_AUDIENT_TYPE_ID14_IN_BOOST] = { + .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, + .flags = ID14_WO, + .len = 2, + .min.integer = 0, + .max.integer = 10 * 256, + .init = 0, + .unit = ID14_FU_IN, + .sel = ID14_IN_BOOST, + }, + [SND_AUDIENT_TYPE_ID14_IN_POLARITY] = { + .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, + .flags = ID14_WO, + .len = 1, + .min.integer = 0, + .max.integer = 1, + .init = 0, + .unit = ID14_FU_IN, + .sel = ID14_IN_POLARITY, + }, + [SND_AUDIENT_TYPE_ID14_MON_ID_KEY] = { + .type = SNDRV_CTL_ELEM_TYPE_ENUMERATED, + .flags = ID14_WO, + .len = 2, + .init = 0xffff, /* ScrollControl */ + .enumeration = &snd_audient_id14_id_key, + .unit = ID14_MON, + .sel = ID14_MON_ID_KEY, + }, + [SND_AUDIENT_TYPE_ID14_MON_TALKBACK_SRC] = { + .type = SNDRV_CTL_ELEM_TYPE_ENUMERATED, + .flags = ID14_WO, + .len = 1, + .init = 0xff, /* None */ + .enumeration = &snd_audient_id14_talkback, + .unit = ID14_MON, + .sel = ID14_MON_TALKBACK_SRC, + }, +/* the power-on mode is S/PDIF */ + [SND_AUDIENT_TYPE_ID14_OPTICAL_MODE] = { + .type = SNDRV_CTL_ELEM_TYPE_ENUMERATED, + .flags = ID14_WO, + .len = 4, + .init = 1, /* S/PDIF */ + .enumeration = &snd_audient_id14_optical, + .unit = ID14_IT_DIGITAL, + .sel = ID14_IT_OPTICAL_MODE, + }, };
@@ -184,6 +435,62 @@ static const char *const snd_audient_evo4_matrix[] = {NULL }; +#define ID14_CTRL (name_, type_, offs_, chans_) \ + { \ + .name = (name_), \ + .type = SND_AUDIENT_TYPE_ID14_##type_, \ + .channels = (chans_), \ + .hwchannels = (chans_), \ + .val_offs = (offs_), \ + } + +static const struct snd_audient_ctrl snd_audient_id14_mk1_controls[] = { +ID14_CTRL ("Monitor Speaker Playback Volume" ,MON_VOLUME ,0 ,1 ), +ID14_CTRL ("Monitor Speaker Playback Switch" ,MON_CUT ,0 ,1 ), +ID14_CTRL ("Monitor Dim Playback Switch" ,MON_DIM ,0 ,1 ), +ID14_CTRL ("Monitor Dim Level Playback Volume" ,MON_DIM_LEVEL ,0 ,1 ), +ID14_CTRL ("Monitor Mono Playback Switch" ,MON_MONO ,0 ,1 ), +ID14_CTRL ("Monitor Mono Mode Playback Enum" ,MON_MONO_MODE ,0 ,1 ), +ID14_CTRL ("Monitor Polarity Invert Playback Switch" ,MON_POLARITY ,0 ,1 ), +ID14_CTRL ("Monitor Headphone Playback Volume" ,HP_VOLUME ,3 ,2 ), +ID14_CTRL ("Monitor Headphone Playback Switch" ,HP_MUTE ,3 ,2 ), +ID14_CTRL ("Talkback Playback Switch" ,MON_TALKBACK ,0 ,1 ), +ID14_CTRL ("Main Out L Source Playback Enum" ,ROUTE_MAIN_L ,0 ,1 ), +ID14_CTRL ("Main Out R Source Playback Enum" ,ROUTE_MAIN_R ,1 ,1 ), +ID14_CTRL ("Headphone L Source Playback Enum" ,ROUTE_HP_L ,2 ,1 ), +ID14_CTRL ("Headphone R Source Playback Enum" ,ROUTE_HP_R ,3 ,1 ), +ID14_CTRL ("Mic 1 Boost Capture Switch" ,IN_BOOST ,1 ,1 ), +ID14_CTRL ("Mic 2 Boost Capture Switch" ,IN_BOOST ,2 ,1 ), +ID14_CTRL ("Mic 1 Polarity Invert Capture Switch" ,IN_POLARITY ,1 ,1 ), +ID14_CTRL ("Mic 2 Polarity Invert Capture Switch" ,IN_POLARITY ,2 ,1 ), +/* Digi 3-8 refuse polarity (CN 5-10 stall) */ +ID14_CTRL ("Digi 1 Polarity Invert Capture Switch" ,IN_POLARITY ,3 ,1 ), +ID14_CTRL ("Digi 2 Polarity Invert Capture Switch" ,IN_POLARITY ,4 ,1 ), +ID14_CTRL ("iD Key Function Playback Enum" ,MON_ID_KEY ,0 ,1 ), +ID14_CTRL ("Talkback Source Capture Enum" ,MON_TALKBACK_SRC ,0 ,1 ), +ID14_CTRL ("Digital In Mode Capture Enum" ,OPTICAL_MODE ,0 ,1 ), + {0 },/* sentinel */ +}; + +/* +* iD14 MkI mixer: unit 60, 14 inputs x 4 outputs, CN = input * 4 + output +* (outputs Main L, Main R, Cue L, Cue R). Each input has a Main and a Cue +* pair, so with 2 channels per element, element n starts at CN 2 * n. +*/ +#define ID14_MIX (in) "Mix Main " in " Playback Volume", \ + "Mix Cue " in " Playback Volume" + +static const char *const snd_audient_id14_mk1_matrix[] = { +ID14_MIX ("Mic 1" ),ID14_MIX ("Mic 2" ), +ID14_MIX ("Digi 1" ),ID14_MIX ("Digi 2" ), +ID14_MIX ("Digi 3" ),ID14_MIX ("Digi 4" ), +ID14_MIX ("Digi 5" ),ID14_MIX ("Digi 6" ), +ID14_MIX ("Digi 7" ),ID14_MIX ("Digi 8" ), +ID14_MIX ("DAW 1" ),ID14_MIX ("DAW 2" ), +ID14_MIX ("DAW 3" ),ID14_MIX ("DAW 4" ), +NULL +}; + static const struct audient_devinfo { u32 usb_id; const struct snd_audient_ctrl *controls;
@@ -196,6 +503,12 @@ static const struct audient_devinfo { .matrix_names = snd_audient_evo4_matrix, .matrix_channels = 2, }, + { + .usb_id = USB_ID(USB_AUDIENT_VID, USB_ID14_MK1_PID), + .controls = snd_audient_id14_mk1_controls, + .matrix_names = snd_audient_id14_mk1_matrix, + .matrix_channels = 2, + }, { 0 } /* sentinel */ };
sound/usb/mixer_audient.h +1 -0
@@ -6,6 +6,7 @@#define USB_AUDIENT_VID (0x2708)#define USB_EVO4_PID (0x0006) +#define USB_ID14_MK1_PID (0x0002)int snd_audient_controls_create (struct usb_mixer_interface *mixer);
sound/usb/mixer_maps.c +2 -0
@@ -528,7 +528,9 @@ static const struct usbmix_name_map audient_id14_map[] = {/* Audient iD14 MkI: model-specific control map. */ static const struct usbmix_name_map audient_id14_mk1_map[] = { + {11 ,NULL },/* FU, see mixer_audient.c */ {12 ,"Monitor Mix Playback" },/* FU, partial coverage */ + {60 ,NULL },/* MU, see mixer_audient.c */ {} };
sound/usb/mixer_quirks.c +3 -0
@@ -4543,6 +4543,9 @@ int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)case USB_ID (USB_AUDIENT_VID ,USB_EVO4_PID ):/* Audient EVO 4 */ err =snd_audient_controls_create (mixer);break ; +case USB_ID (USB_AUDIENT_VID ,USB_ID14_MK1_PID ):/* Audient iD14 MkI */ + err =snd_audient_controls_create (mixer); +break ;case USB_ID (0x041e ,0x323b ):/* Creative Sound Blaster E1 */ err =snd_soundblaster_e1_switch_create (mixer);
Signature · 1 line
2.47.3
RFC PATCH 16/16 ALSA: mixer_audient: Replace the Audient iD14 MkI FU 12 control
In reply to Will PorterFeature unit 12 sets the level of the mixer outputs: channels 1-2 Main, 3-4 Cue. Two firmware faults make the generic control wrong on the MkI:
- GET CUR does not return the FU 12 value. It returns a reply buffer that the device shares with FU 10, MU 60 and XU 51. The buffer holds the data of the last GET or SET to any of them. So the generic sticky-GET check passes, because GET echoes the SET just sent. The check then writes the stale value that it read first to channel 1.
- Main L ignores its level, but Main R applies it. So any Main value other than 0 dB unbalances the main outputs. audient_id14_map already records this asymmetry. A loopback cable measured it: Main R at -20 dB and -40 dB changes its output by -20.0 and -40.9 dB. Main L at the same values changes nothing. Cue L and Cue R both work: Cue L follows the set value within about 1 dB down to at least -70 dB; the headphone residual hides lower levels.
Replace the generic control with one of the same name, count and range. It is "Monitor Mix Playback Volume", with four values from 0 to 127 in 1 dB steps. 127 is 0 dB. Value 0 writes 0x8000, the floor that Audient's iD application writes, and the TLV declares it as mute. On Cue L, value 0 gives no output above the fixed headphone residual, about 76 dB below 0 dB. The four values keep the Main L/R, Cue L/R layout of existing saved ALSA states.
The control holds Main at 0 dB, as the iD application does. (The application has no Main fader and writes 0 dB at launch.) A put always sends 0 dB to channels 1-2 and returns that value to the caller. Get reports it too. For Cue the control shows the last value the device accepted. At probe the driver writes the iD application's launch values once per channel: Main 0 dB, Cue muted. A channel whose probe write fails reads as mute until a put succeeds.
The iD14 MkI profile in alsa-ucm-conf writes 127,127,127,127 to this control at boot and when its HiFi verb starts. The new control accepts that write: Main stays at 0 dB and Cue goes to 0 dB, the same result as with the generic control.
Differences from the generic control:
- Value 0 is now mute. It was -127 dB.
- The control holds Main at 0 dB. A Main R attenuation stored with the generic control (for example 107, -20 dB) now restores as 0 dB, which raises Main R by 20 dB. Main L never applied that attenuation, so Main R comes up to the level that Main L already had. FU 12 comes before the monitor controller (XU 54) and the headphone level (FU 10), so the volume knob still sets the listening level.
- Cue starts muted at every probe. An output routed to the Cue Mix keeps that routing across a module reload or a rebind. On mains power it also keeps it across a replug. If the probe writes succeed, that output is then muted until user space sets the Cue level (alsactl restore or the UCM boot write). On bus power the MkI returns to DAW Thru when it enumerates, so no output is on the Cue Mix at probe.
The control does not fit the generic types, so the device table gains a create hook for controls the tables cannot describe, called after the tables.
--- sound/usb/mixer_audient.c | 167 ++++++++++++++++++++++++++++++++++++++ sound/usb/mixer_maps.c | 2 +- 2 files changed, 168 insertions(+), 1 deletion(-)
sound/usb/mixer_audient.c +167 -0
@@ -491,11 +491,15 @@ static const char *const snd_audient_id14_mk1_matrix[] = {NULL }; +static int snd_audient_id14_mk1_create (struct usb_mixer_interface *mixer); +static const struct audient_devinfo {u32 usb_id;const struct snd_audient_ctrl *controls;const char *const *const matrix_names;const unsigned int matrix_channels; +/* controls the tables cannot describe; called after the tables */ +int (*create)(struct usb_mixer_interface *mixer); } audient_devinfo[] = { { .usb_id =USB_ID (USB_AUDIENT_VID ,USB_EVO4_PID ),
@@ -508,6 +512,7 @@ static const struct audient_devinfo { .controls = snd_audient_id14_mk1_controls, .matrix_names = snd_audient_id14_mk1_matrix, .matrix_channels = 2, + .create = snd_audient_id14_mk1_create, }, { 0 } /* sentinel */ };
@@ -1132,6 +1137,165 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer, } +/* +* iD14 MkI FU 12, the mixer output level: CN 1-2 Main, 3-4 Cue. GET RANGE +* works (-127 ... 0 dB, 1 dB steps), but GET CUR returns a reply buffer the +* device shares with other units, not the FU 12 value. So the generic +* control shows stale data, and its sticky-GET check passes and then writes +* that stale value to Main L. +* +* The firmware ignores Main L (CN 1) but applies Main R (CN 2), so any Main +* level other than 0 dB unbalances the main outputs (Cue L and Cue R both +* work). This control holds Main at 0 dB: a put sends 0 dB to CN 1-2 +* whatever it asks for, and get reports it. +* +* It keeps the generic control's name and format: four values, 0 ... 127 +* in 1 dB steps, 127 = 0 dB, 0 = mute (0x8000). It shows the last value the +* device accepted, and every put sends all four channels. +*/ +#define ID14_FU12_CHANNELS 4 +#define ID14_FU12_MAIN_CHANNELS 2/* CN 1-2, held at 0 dB */ +#define ID14_FU12_MAX 127 +#define ID14_FU12_MUTE 0 + +static const DECLARE_TLV_DB_MINMAX_MUTE(snd_audient_tlv_id14_fu12, -12700, 0); + +static const struct snd_audient_ctrl_type snd_audient_id14_fu12_type = { + .len =2 , + .unit =ID14_FU_MIX , + .sel =UAC_FU_VOLUME , +}; + +struct snd_audient_id14_fu12 { +struct usb_mixer_elem_list list;/* first: snd_usb_mixer_elem_free */ +long val[ID14_FU12_CHANNELS ]; +u8 valid;/* bit per channel */ +}; + +static int snd_audient_id14_fu12_write (struct snd_audient_id14_fu12 *f, +unsigned int ch,long val) +{ +__le16 buf =cpu_to_le16 (val ==ID14_FU12_MUTE ?-128 *256 + : (val -ID14_FU12_MAX ) *256 ); +int ret; + + ret =snd_audient_set_cur (f->list.mixer, &snd_audient_id14_fu12_type, + ch +1 , &buf); +if (ret <0 ) +return ret; + + f->val[ch] = val; + f->valid |=BIT (ch); + +return 0 ; +} + +static int snd_ctl_audient_id14_fu12_info (struct snd_kcontrol *kctl, +struct snd_ctl_elem_info *uinfo) +{ + uinfo->type =SNDRV_CTL_ELEM_TYPE_INTEGER ; + uinfo->count =ID14_FU12_CHANNELS ; + uinfo->value.integer.min =0 ; + uinfo->value.integer.max =ID14_FU12_MAX ; + +return 0 ; +} + +static int snd_ctl_audient_id14_fu12_get (struct snd_kcontrol *kctl, +struct snd_ctl_elem_value *ctl_val) +{ +struct snd_audient_id14_fu12 *f =snd_kcontrol_chip (kctl); +unsigned int ch; + +/* a channel that was never written reads as mute */ +for (ch =0 ; ch <ID14_FU12_CHANNELS ; ch++) + ctl_val->value.integer.value[ch] = (f->valid &BIT (ch)) + ? f->val[ch] + :ID14_FU12_MUTE ; + +return 0 ; +} + +static int snd_ctl_audient_id14_fu12_set (struct snd_kcontrol *kctl, +struct snd_ctl_elem_value *ctl_val) +{ +struct snd_audient_id14_fu12 *f =snd_kcontrol_chip (kctl); +long *const v = ctl_val->value.integer.value; +unsigned int ch; +int changed =0 ; + +for (ch =0 ; ch <ID14_FU12_CHANNELS ; ch++) +if (v[ch] <0 || v[ch] >ID14_FU12_MAX ) +return -EINVAL ; + +CLASS (snd_usb_lock, pm)(f->list.mixer->chip); +if (pm.err <0 ) +return pm.err; + +/* Main is held at 0 dB: report that back to the caller */ +for (ch =0 ; ch <ID14_FU12_MAIN_CHANNELS ; ch++) + v[ch] =ID14_FU12_MAX ; + +for (ch =0 ; ch <ID14_FU12_CHANNELS ; ch++) { +int ret; + +if (!(f->valid &BIT (ch)) || f->val[ch] != v[ch]) + changed =1 ; + + ret =snd_audient_id14_fu12_write (f, ch, v[ch]); +if (ret <0 ) +return ret; + } + +return changed; +} + +/* At probe, set Main to 0 dB and mute Cue. */ +static int snd_audient_id14_mk1_create (struct usb_mixer_interface *mixer) +{ +struct snd_kcontrol_new knew = { + .iface =SNDRV_CTL_ELEM_IFACE_MIXER , + .name ="Monitor Mix Playback Volume" , + .access =SNDRV_CTL_ELEM_ACCESS_READWRITE + |SNDRV_CTL_ELEM_ACCESS_TLV_READ , + .info = snd_ctl_audient_id14_fu12_info, + .get = snd_ctl_audient_id14_fu12_get, + .put = snd_ctl_audient_id14_fu12_set, + .tlv.p = snd_audient_tlv_id14_fu12, + }; +struct snd_audient_id14_fu12 *f; +struct snd_kcontrol *kctl; +unsigned int ch; + + f =kzalloc_obj (*f); +if (!f) +return -ENOMEM ; + + f->list.mixer = mixer; + f->list.id =ID14_FU_MIX ; + +for (ch =0 ; ch <ID14_FU12_CHANNELS ; ch++) { +const int ret =snd_audient_id14_fu12_write (f, ch, + ch <ID14_FU12_MAIN_CHANNELS ?ID14_FU12_MAX + :ID14_FU12_MUTE ); + +if (ret <0 )/* the channel stays unknown and reads as mute */ +usb_audio_warn (mixer->chip, +"iD14: cannot set FU 12 channel %u (%d)\n" , + ch +1 , ret); + } + + kctl =snd_ctl_new1 (&knew, f); +if (!kctl) { +kfree (f); +return -ENOMEM ; + } + + kctl->private_free = snd_usb_mixer_elem_free; + +return snd_usb_mixer_add_list (&f->list, kctl, false, true); +} +/* called from mixer_quirks.c */ int snd_audient_controls_create (struct usb_mixer_interface *mixer) {
@@ -1171,5 +1335,8 @@ int snd_audient_controls_create(struct usb_mixer_interface *mixer) } } +if (info->create) +return info->create (mixer); +return 0 ; }
sound/usb/mixer_maps.c +1 -1
@@ -529,7 +529,7 @@ static const struct usbmix_name_map audient_id14_map[] = {/* Audient iD14 MkI: model-specific control map. */ static const struct usbmix_name_map audient_id14_mk1_map[] = { {11 ,NULL },/* FU, see mixer_audient.c */ - {12 ,"Monitor Mix Playback" },/* FU, partial coverage */ + {12 ,NULL },/* FU, see mixer_audient.c */ {60 ,NULL },/* MU, see mixer_audient.c */ {} };
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [RFC PATCH 13/16] ALSA: mixer_audient: Add enumerated controls
In reply to Will PorterThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] ALSA: mixer_audient: unselectable enum item in snd_ctl_audient_info() breaks UAPI --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] ALSA: mixer_audient: unselectable enum item in snd_ctl_audient_info() breaks UAPI
--
commit 11b395622645c1753139b078b4521e003601a600
Author: Will Porter <[email protected]>
ALSA: mixer_audient: Add enumerated controls
This commit adds support for enumerated mixer controls in the Audient USB mixer driver, including a trailing read-only item for unknown or unconfirmed device values.
Quoted 4 lines
sound/usb/mixer_audient.c +0
-0
[ ... ]
Quoted 1 line
sound/usb/mixer_audient.c +0
-0@@ -560,12 +582,116 @@ static int snd_ctl_audient_integer_set(struct snd_kcontrol *kctl,
[ ... ]
Quoted 18 lines
sound/usb/mixer_audient.c +18
-0+static int snd_ctl_audient_enum_set (struct snd_kcontrol *kctl, +struct snd_ctl_elem_value *ctl_val) +{ +struct usb_mixer_elem_info *const elem =snd_kcontrol_chip (kctl); +struct usb_mixer_interface *const mixer = elem->head.mixer; + +const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl); +const struct snd_audient_ctrl_type *const ctype + =snd_audient_kctl_type (kctl); +const struct snd_audient_enum *const e = ctype->enumeration; +const u8 base =snd_audient_kctl_cidxoffs (kctl); + +unsigned int i; +int changed =0 ; + +for (i =0 ; i < hwchan; i++) +if (ctl_val->value.enumerated.item[i] >= e->items) +return -EINVAL ;
[ ... ]
sound/usb/mixer_audient.c static int snd_ctl_audient_integer_set(struct snd_kcontrol *kctl, · line 693
Quoted 10 lines
static int snd_ctl_audient_info(struct
snd_kcontrol*kctl,sound/usb/mixer_audient.c +4
-0struct snd_ctl_elem_info *uinfo) {const struct snd_audient_ctrl_type *const ctype =snd_audient_kctl_type (kctl); +if (ctype->type ==SNDRV_CTL_ELEM_TYPE_ENUMERATED ) +return snd_ctl_enum_info (uinfo,snd_audient_kctl_channels (kctl), + ctype->enumeration->items +1 , + ctype->enumeration->texts);
[Severity: Medium]
Does advertising ctype->enumeration->items + 1 items in snd_ctl_audient_info() while rejecting item index e->items with -EINVAL in snd_ctl_audient_enum_set() break the ALSA control UAPI contract for writable enumerated controls?
For a SNDRV_CTL_ELEM_ACCESS_READWRITE enumerated control, userspace expects all advertised item indices (0 .. uinfo->value.enumerated.items - 1) to be valid on write. Rejecting the last advertised item causes the ALSA mixer-test kselftest (test_ctl_write_valid_enumerated() and test_ctl_write_side_effects()) to fail on every enumerated control, and breaks alsactl store/restore or multi-channel read-modify-write updates whenever snd_ctl_audient_enum_get() returns e->items.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=13
Re: [RFC PATCH 13/16] ALSA: mixer_audient: Add enumerated controls
Hi Christian,
The bot found a real problem in my patch 13:
Quoted 4 lines
Does advertising
ctype->enumeration->items+ 1 items insnd_ctl_audient_info()while rejecting item indexe->itemswith-EINVALinsnd_ctl_audient_enum_set()break the ALSA control UAPI contract for writable enumerated controls?
Yes. mixer-test writes every advertised item, and alsactl restore fails on a value that store saved as the extra item.
The diff below drops the extra item from every enum:
- A device value outside the list makes get return -EIO. I chose an error over a fallback item: an unknown routing value shown as Main Mix could hide a route that bypasses the speaker volume, cut and dim. The device is not known to report such a value.
- A write-only value that no transfer has confirmed (only after a failed probe write) reads as its init value, as a write-only switch reads off.
Tested on the iD14 (stable 7.2.15) with the diff applied, with a script that does the enum writes of mixer-test on this card only:
get returned every advertised item after its put (from the cache for the write-only controls), and the item past the end was rejected. alsactl store and restore of the card succeeded. I did not run the full mixer-test, because it writes the controls of every card.
Does -EIO from get look right to you here? If the diff looks good, I'll fold it into patches 13 and 15 in the next version.
Thanks,
Will
-- >8 --
From: Will Porter <[email protected]>
Subject: [RFC PATCH] ALSA: mixer_audient: Advertise only selectable enum items
Every enumerated control advertised one item more than a put accepts. mixer-test writes every advertised item, and alsactl restore fails on a stored value of that item. Advertise only the real items.
A get of a device value outside the list now returns -EIO: an unknown routing value shown as Main Mix could hide a route that bypasses the speaker volume, cut and dim. After a failed probe write, a write-only value reads as its init value; this does not confirm the device state.
---
Proposed change to patches 13 and 15.
sound/usb/mixer_audient.c | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-)
sound/usb/mixer_audient.c +19 -22
@@ -67,10 +67,8 @@ static const DECLARE_TLV_DB_MINMAX_MUTE(snd_audient_tlv_mixer, -12800, 600);#define SND_AUDIENT_CTYPE_FLAGS_CACHE BIT(3)/* -* An enumerated control: item i sends values[i]. The texts have one item -* more than the values. A put cannot select that last item: a get shows it -* for a device value outside the list ("Other"), or for a write-only value -* that no write has confirmed ("Unknown"). +* An enumerated control: item i sends values[i]. A get of a device value +* outside the list returns -EIO; it does not show a wrong item. */ struct snd_audient_enum {const char *const *texts;
@@ -85,7 +83,7 @@ struct snd_audient_enum { .values = name##_values, \ .items = ARRAY_SIZE(name##_values), \ }; \ - static_assert(ARRAY_SIZE(texts_) == ARRAY_SIZE(name##_values) + 1) + static_assert(ARRAY_SIZE(texts_) == ARRAY_SIZE(name##_values))/* * iD14 MkI units. The monitor controller, output routing, headphone level,
@@ -126,7 +124,7 @@ static const DECLARE_TLV_DB_SCALE(snd_audient_tlv_id14_vol, -12800, 100, 0);/* Mono mode: one-speaker sum (Left, Right) or phantom centre */ static const char *const snd_audient_id14_mono_mode_texts[] = { -"Left" ,"Centre" ,"Right" ,"Other" , +"Left" ,"Centre" ,"Right" , };SND_AUDIENT_ENUM (snd_audient_id14_mono_mode, snd_audient_id14_mono_mode_texts,1 ,0 ,2 );
@@ -139,10 +137,10 @@ SND_AUDIENT_ENUM(snd_audient_id14_mono_mode,* mute still act on every headphone source. */ static const char *const snd_audient_id14_route_main_texts[] = { -"Main Mix" ,"Cue Mix" ,"DAW Thru (full scale)" ,"Other" , +"Main Mix" ,"Cue Mix" ,"DAW Thru (full scale)" , };static const char *const snd_audient_id14_route_hp_texts[] = { -"Main Mix" ,"Cue Mix" ,"DAW Thru" ,"Other" , +"Main Mix" ,"Cue Mix" ,"DAW Thru" , };SND_AUDIENT_ENUM (snd_audient_id14_route_main_l, snd_audient_id14_route_main_texts,0x14 ,0x10 ,0x00 );
@@ -156,12 +154,10 @@ SND_AUDIENT_ENUM(snd_audient_id14_route_hp_r,/* * iD key function: the value is the monitor controller selector the key * toggles. ScrollControl (0xffff) toggles nothing: the knob then scrolls -* through the HID interface. The last item of a write-only enum shows a -* value that is not known. +* through the HID interface. */ static const char *const snd_audient_id14_id_key_texts[] = {"ScrollControl" ,"Mono" ,"Mono + Polarity" ,"Dim" ,"Talkback" , -"Unknown" , }; SND_AUDIENT_ENUM(snd_audient_id14_id_key, snd_audient_id14_id_key_texts, 0xffff, ID14_MON_MONO, ID14_MON_POLARITY, ID14_MON_DIM,
@@ -170,13 +166,13 @@ SND_AUDIENT_ENUM(snd_audient_id14_id_key, snd_audient_id14_id_key_texts,/* Talkback source: the routing source number of the input; none = 0xff */ static const char *const snd_audient_id14_talkback_texts[] = {"None" ,"Mic 1" ,"Mic 2" ,"Digi 1" ,"Digi 2" ,"Digi 3" ,"Digi 4" , -"Digi 5" ,"Digi 6" ,"Digi 7" ,"Digi 8" ,"Unknown" , +"Digi 5" ,"Digi 6" ,"Digi 7" ,"Digi 8" , };SND_AUDIENT_ENUM (snd_audient_id14_talkback, snd_audient_id14_talkback_texts,0xff ,4 ,5 ,6 ,7 ,8 ,9 ,10 ,11 ,12 ,13 );static const char *const snd_audient_id14_optical_texts[] = { -"ADAT" ,"S/PDIF" ,"Unknown" , +"ADAT" ,"S/PDIF" , };SND_AUDIENT_ENUM (snd_audient_id14_optical, snd_audient_id14_optical_texts,0 ,1 );
@@ -933,22 +929,23 @@ static int snd_ctl_audient_enum_get(struct snd_kcontrol *kctl,guard (mutex)(&mixer->lock);for (i =0 ; i < hwchan; i++) { +unsigned int item;u32 val;int ret; ret =snd_audient_raw_get_one (mixer, ctype,snd_audient_cache_slot (elem, i), base + i, &val); -if (ret == -ENODATA ) {/* unknown write-only value */ - ctl_val->value.enumerated.item[i] = - ctype->enumeration->items; -continue ; - }else if (ret <0 ) { +if (ret == -ENODATA )/* unknown write-only value: init */ + val = ctype->init; +else if (ret <0 )return ret; - } - ctl_val->value.enumerated.item[i] = -snd_audient_enum_item (ctype->enumeration, val); + item =snd_audient_enum_item (ctype->enumeration, val); +if (item >= ctype->enumeration->items) +return -EIO ; + + ctl_val->value.enumerated.item[i] = item; }for (; i < nchan; i++)
@@ -1007,7 +1004,7 @@ static int snd_ctl_audient_info(struct snd_kcontrol *kctl,if (ctype->type ==SNDRV_CTL_ELEM_TYPE_ENUMERATED )return snd_ctl_enum_info (uinfo,snd_audient_kctl_channels (kctl), - ctype->enumeration->items +1 , + ctype->enumeration->items, ctype->enumeration->texts); uinfo->type = ctype->type;
Re: [RFC PATCH 13/16] ALSA: mixer_audient: Add enumerated controls
Hi Will,
Thanks for this update. I squashed it into patches 13 and 15 before reviewing. I also tested everything on 7.3.3 and could not find any issues. Here are my comments about the code, most of them are minor:
patch 12:
- I would declare snd_audient_int_max, snd_audient_int_min and snd_audient_int_from_ctl as inline, they are little more than macros.
patch 13:
- I would have snd_audient_enum_item return the negative errno instead of e->items and then propagate it. This seems more coherent with the convention applied almost everywhere else in the kernel.
- I wonder if it would make the code more readable if we refactor all the if-statements snd_ctl_audient_info has grown into something like DIFF 1 below?
patch 15:
- snd_ctl_audient_enum_get uses ctype->init which is not set by the ID14_ENUM() macro. Is this intentionally always constant 0? In this case, could the logic be removed?
- Not sure if this is relevant for the iD14 but we might want to apply something like DIFF 2 to make update events work on the replaced controls 11 and possibly 60 (in case somebody fiddles with the buttons, please check if it actually works with the device). BTW: I'll see if we can somehow also get update events for the new controls of the EVO4 on the occasion. The events the generic mixer driver generates don't work for those so I didn't bother initializing the ID until now.
- In mixer_quirks.c: Fallthrough case statements seem to be used almost everywhere else, I suggest to replace the repeating call to snd_audient_controls_create with a fallthrough as well.
patch 16:
- can we rename 'create' to something which makes it obvious from the name that the callback is optional, e.g. 'extra_init' or similar?
Christian
---- DIFF 1 ----
sound/usb/mixer_audient.c +15 -12
@@ -1002,22 +1002,25 @@ static int snd_ctl_audient_info(struct snd_kcontrol *kctl,const struct snd_audient_ctrl_type *const ctype =snd_audient_kctl_type (kctl); -if (ctype->type ==SNDRV_CTL_ELEM_TYPE_ENUMERATED ) -return snd_ctl_enum_info (uinfo,snd_audient_kctl_channels (kctl), - ctype->enumeration->items, - ctype->enumeration->texts); +switch (ctype->type) { +case SNDRV_CTL_ELEM_TYPE_ENUMERATED : +return snd_ctl_enum_info (uinfo, +snd_audient_kctl_channels (kctl), + ctype->enumeration->items, + ctype->enumeration->texts); +case SNDRV_CTL_ELEM_TYPE_BOOLEAN : + uinfo->value.integer.min =0 ; + uinfo->value.integer.max =1 ; +break ; +default : + uinfo->value.integer.min =snd_audient_int_min (ctype); + uinfo->value.integer.max =snd_audient_int_max (ctype); +break ; + } uinfo->type = ctype->type; uinfo->count =snd_audient_kctl_channels (kctl); -if (ctype->type ==SNDRV_CTL_ELEM_TYPE_BOOLEAN ) { - uinfo->value.integer.min =0 ; - uinfo->value.integer.max =1 ; - }else { - uinfo->value.integer.min =snd_audient_int_min (ctype); - uinfo->value.integer.max =snd_audient_int_max (ctype); - } -return 0 ; }
---- DIFF 2 ----
sound/usb/mixer_audient.c +1 -0
@@ -1083,6 +1083,7 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer,return -ENOMEM ; elem->head.mixer = mixer; + elem->head.id = ctype->unit; elem->channels = ctrl->channels;if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_CACHE )
Quoted 176 lines · Will Porter
Hi Christian,
The bot found a real problem in my patch 13:
Quoted 4 lines
Does advertising
ctype->enumeration->items+ 1 items insnd_ctl_audient_info()while rejecting item indexe->itemswith-EINVALinsnd_ctl_audient_enum_set()break the ALSA control UAPI contract for writable enumerated controls?Yes. mixer-test writes every advertised item, and alsactl restore fails on a value that store saved as the extra item.
The diff below drops the extra item from every enum:
- A device value outside the list makes get return
-EIO. I chose an error over a fallback item: an unknown routing value shown as Main Mix could hide a route that bypasses the speaker volume, cut and dim. The device is not known to report such a value.
- A write-only value that no transfer has confirmed (only after a failed probe write) reads as its init value, as a write-only switch reads off.Tested on the iD14 (stable 7.2.15) with the diff applied, with a script that does the enum writes of mixer-test on this card only:
get returned every advertised item after its put (from the cache for the write-only controls), and the item past the end was rejected. alsactl store and restore of the card succeeded. I did not run the full mixer-test, because it writes the controls of every card.Does
-EIOfrom get look right to you here? If the diff looks good, I'll fold it into patches 13 and 15 in the next version.Thanks,
Will-- >8 --
From: Will Porter <[email protected]>
Subject: [RFC PATCH] ALSA:mixer_audient: Advertise only selectable enum itemsEvery enumerated control advertised one item more than a put accepts. mixer-test writes every advertised item, and alsactl restore fails on a stored value of that item. Advertise only the real items.
A get of a device value outside the list now returns
-EIO: an unknown routing value shown as Main Mix could hide a route that bypasses the speaker volume, cut and dim. After a failed probe write, a write-only value reads as its init value; this does not confirm the device state.Assisted-by Claude:claude-opus-5-5Signed-off-by Will Porter <[email protected]>---
Proposed change to patches 13 and 15.sound/usb/mixer_audient.c | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-)sound/usb/mixer_audient.c +19
-22@@ -67,10 +67,8 @@ static const DECLARE_TLV_DB_MINMAX_MUTE(snd_audient_tlv_mixer, -12800, 600);#define SND_AUDIENT_CTYPE_FLAGS_CACHE BIT(3)/* -* An enumerated control: item i sends values[i]. The texts have one item -* more than the values. A put cannot select that last item: a get shows it -* for a device value outside the list ("Other"), or for a write-only value -* that no write has confirmed ("Unknown"). +* An enumerated control: item i sends values[i]. A get of a device value +* outside the list returns -EIO; it does not show a wrong item. */ struct snd_audient_enum {const char *const *texts;@@ -85,7 +83,7 @@ struct snd_audient_enum { .values = name##_values, \ .items = ARRAY_SIZE(name##_values), \ }; \ - static_assert(ARRAY_SIZE(texts_) == ARRAY_SIZE(name##_values) + 1) + static_assert(ARRAY_SIZE(texts_) == ARRAY_SIZE(name##_values))/* * iD14 MkI units. The monitor controller, output routing, headphone level, @@ -126,7 +124,7 @@ static const DECLARE_TLV_DB_SCALE(snd_audient_tlv_id14_vol, -12800, 100, 0);/* Mono mode: one-speaker sum (Left, Right) or phantom centre */ static const char *const snd_audient_id14_mono_mode_texts[] = { -"Left" ,"Centre" ,"Right" ,"Other" , +"Left" ,"Centre" ,"Right" , };SND_AUDIENT_ENUM (snd_audient_id14_mono_mode, snd_audient_id14_mono_mode_texts,1 ,0 ,2 );@@ -139,10 +137,10 @@ SND_AUDIENT_ENUM(snd_audient_id14_mono_mode,* mute still act on every headphone source. */ static const char *const snd_audient_id14_route_main_texts[] = { -"Main Mix" ,"Cue Mix" ,"DAW Thru (full scale)" ,"Other" , +"Main Mix" ,"Cue Mix" ,"DAW Thru (full scale)" , };static const char *const snd_audient_id14_route_hp_texts[] = { -"Main Mix" ,"Cue Mix" ,"DAW Thru" ,"Other" , +"Main Mix" ,"Cue Mix" ,"DAW Thru" , };SND_AUDIENT_ENUM (snd_audient_id14_route_main_l, snd_audient_id14_route_main_texts,0x14 ,0x10 ,0x00 );@@ -156,12 +154,10 @@ SND_AUDIENT_ENUM(snd_audient_id14_route_hp_r,/* * iD key function: the value is the monitor controller selector the key * toggles. ScrollControl (0xffff) toggles nothing: the knob then scrolls -* through the HID interface. The last item of a write-only enum shows a -* value that is not known. +* through the HID interface. */ static const char *const snd_audient_id14_id_key_texts[] = {"ScrollControl" ,"Mono" ,"Mono + Polarity" ,"Dim" ,"Talkback" , -"Unknown" , }; SND_AUDIENT_ENUM(snd_audient_id14_id_key, snd_audient_id14_id_key_texts, 0xffff, ID14_MON_MONO, ID14_MON_POLARITY, ID14_MON_DIM,@@ -170,13 +166,13 @@ SND_AUDIENT_ENUM(snd_audient_id14_id_key, snd_audient_id14_id_key_texts,/* Talkback source: the routing source number of the input; none = 0xff */ static const char *const snd_audient_id14_talkback_texts[] = {"None" ,"Mic 1" ,"Mic 2" ,"Digi 1" ,"Digi 2" ,"Digi 3" ,"Digi 4" , -"Digi 5" ,"Digi 6" ,"Digi 7" ,"Digi 8" ,"Unknown" , +"Digi 5" ,"Digi 6" ,"Digi 7" ,"Digi 8" , };SND_AUDIENT_ENUM (snd_audient_id14_talkback, snd_audient_id14_talkback_texts,0xff ,4 ,5 ,6 ,7 ,8 ,9 ,10 ,11 ,12 ,13 );static const char *const snd_audient_id14_optical_texts[] = { -"ADAT" ,"S/PDIF" ,"Unknown" , +"ADAT" ,"S/PDIF" , };SND_AUDIENT_ENUM (snd_audient_id14_optical, snd_audient_id14_optical_texts,0 ,1 );@@ -933,22 +929,23 @@ static int snd_ctl_audient_enum_get(struct snd_kcontrol *kctl,guard (mutex)(&mixer->lock);for (i =0 ; i < hwchan; i++) { +unsigned int item;u32 val;int ret; ret =snd_audient_raw_get_one (mixer, ctype,snd_audient_cache_slot (elem, i), base + i, &val); -if (ret == -ENODATA ) {/* unknown write-only value */ - ctl_val->value.enumerated.item[i] = - ctype->enumeration->items; -continue ; - }else if (ret <0 ) { +if (ret == -ENODATA )/* unknown write-only value: init */ + val = ctype->init; +else if (ret <0 )return ret; - } - ctl_val->value.enumerated.item[i] = -snd_audient_enum_item (ctype->enumeration, val); + item =snd_audient_enum_item (ctype->enumeration, val); +if (item >= ctype->enumeration->items) +return -EIO ; + + ctl_val->value.enumerated.item[i] = item; }for (; i < nchan; i++)@@ -1007,7 +1004,7 @@ static int snd_ctl_audient_info(struct snd_kcontrol *kctl,if (ctype->type ==SNDRV_CTL_ELEM_TYPE_ENUMERATED )return snd_ctl_enum_info (uinfo,snd_audient_kctl_channels (kctl), - ctype->enumeration->items +1 , + ctype->enumeration->items, ctype->enumeration->texts); uinfo->type = ctype->type;
Signature · 4 lines
Christian Ruppert <[email protected]> This message is digitally signed with GnuPG. GPG/PGP Key fingerprint = 4492 2196 75F0 EAA0 981E B661 1476 F17A 975F 587B
Re: [RFC PATCH 13/16] ALSA: mixer_audient: Add enumerated controls
Hi Christian,
Thank you for squashing the fix and for testing it on 7.3.3.
Quoted 3 lines
patch 12:
- I would declaresnd_audient_int_max,snd_audient_int_minandsnd_audient_int_from_ctlas inline [...]
Done.
Quoted 3 lines
patch 13:
- I would havesnd_audient_enum_itemreturn the negative errno instead ofe->itemsand then propagate it.
Done. It returns the item or -EIO, and get propagates the error.
Quoted 3 lines
- I wonder if it would make the code more readable if we refactor all the if-statements
snd_ctl_audient_infohas grown into something like DIFF 1 below?
Done. snd_ctl_audient_info() now uses a switch.
Quoted 4 lines
patch 15:
-snd_ctl_audient_enum_getusesctype->initwhich is not set by theID14_ENUM()macro. Is this intentionally always constant 0? In this case, could the logic be removed?
I think the logic is still needed, because init is not always 0. ID14_ENUM() builds only the readable enums: Mono Mode and the four routing controls. They have no cache entry, so snd_audient_raw_get_one() never returns -ENODATA for them, and no code reads init for them. The three write-only enums (iD key function, talkback source, optical mode) do not use the macro. They set .init explicitly, to 0xffff, 0xff and 1. A comment on the macro now says this.
Quoted 3 lines
- Not sure if this is relevant for the iD14 but we might want to apply something like DIFF 2 to make update events work on the replaced controls 11 and possibly 60 [...]
I left DIFF 2 out of my patches. I have no objection to it, but I cannot test it. The audio control interface of the iD14 MkI has no interrupt endpoint (bNumEndpoints is 0), so snd_usb_mixer_status_create() returns before it creates the URB. The device sends no status interrupts, and a knob change shows only by a read. On the iD14 the diff only moves the table-created controls from id 0 to their unit in id_elems and in the usbmixer proc file.
Two things in sound/usb/mixer.c may matter for your EVO4 events:
- snd_usb_mixer_interrupt_v2() skips an element when the unit has more than one element and info->control differs from the control selector in the message. Our elements leave control at 0. Would the event reach them?
- The notify paths clear info->cached of the generic mixer, not the mixer_audient cache. Would a cached control report its old value after the event?
Could you carry DIFF 2 with your EVO4 event change?
Quoted 2 lines
- In
mixer_quirks.c: Fallthrough case statements seem to be used almost everywhere else, [...]
Done. The two case labels share one call.
Quoted 3 lines
patch 16:
- can we rename 'create' to something which makes it obvious from the name that the callback is optional, e.g. 'extra_init' or similar?
Done. It is now extra_init, with a comment that it is optional.
With these changes each of the five patches builds with W=1 without warnings, and checkpatch --strict reports nothing new.
On the iD14 (stable 7.2.15) the read and write checks of the controls pass with the new version.
For the next version: unless you would like another RFC round, I would send it as a normal series, on top of your four mixer_evo fixes as before. Does that work for you?
Thanks,
Will
Re: [RFC PATCH 13/16] ALSA: mixer_audient: Add enumerated controls
Hi Will,
Quoted 23 lines · Will Porter
[...]
Quoted 3 lines
- Not sure if this is relevant for the iD14 but we might want to apply something like DIFF 2 to make update events work on the replaced controls 11 and possibly 60 [...]
I left DIFF 2 out of my patches. I have no objection to it, but I cannot test it. The audio control interface of the iD14 MkI has no interrupt endpoint (bNumEndpoints is 0), so
snd_usb_mixer_status_create()returns before it creates the URB. The device sends no status interrupts, and a knob change shows only by a read. On the iD14 the diff only moves the table-created controls from id 0 to their unit inid_elemsand in the usbmixer proc file.Two things in
sound/usb/mixer.cmay matter for your EVO4 events:-
snd_usb_mixer_interrupt_v2()skips an element when the unit has more than one element andinfo->controldiffers from the control selector in the message. Our elements leave control at 0. Would the event reach them?
- The notify paths clearinfo->cachedof the generic mixer, not themixer_audientcache. Would a cached control report its old value after the event?
Quoted 1 line
Could you carry DIFF 2 with your EVO4 event change?
OK, thanks for the hints, I'll keep them in mind when I start working on this. I haven't tested the diff either, for the moment it was only a sketch so it's most probably incomplete. This is actually only required for the EVO if I decide to replace generic controls - which I might eventually to keep the philosophy of the driver consistent:
Until now I tried not to touch what was working, even if it's quirky but as you cleaned up comparable controls for the iD I might just as well do so for the EVO, too. A higher priority will be to figure out if and how I can get events for controls not supported by the generic driver, though, but that will require a few hours on a rainy day...
Quoted 9 lines
[...]
With these changes each of the five patches builds with W=1 without warnings, and checkpatch --strict reports nothing new.
On the iD14 (stable 7.2.15) the read and write checks of the controls pass with the new version.For the next version: unless you would like another RFC round, I would send it as a normal series, on top of your four
mixer_evofixes as before. Does that work for you?
Actually... I was just about to propose the same but when looking at the code in mixer.c you refer to above (interrupts and cache invalidation) I realized that usb_mixer_elem_info already contains an integer array for caching we could use instead of our manually allocated cache. I suspect we should rework patch 10 accordingly. The positive side-effect of this would be that info->cached management in the standard notify path would work should we decide to use it one day.
I'll prepare a new patch 10 but won't be able to test before the week-end. I'll send a new RFC after that. Do you think it makes sense to refactor FU12 caching as well?
Cheers,
Christian
cover ALSA: mixer_audient: Cache rework and simplifications
Hi Christian,
Quoted 3 lines · Christian Ruppert
I realized that
usb_mixer_elem_infoalready contains an integer array for caching we could use instead of our manually allocated cache. I suspect we should rework patch 10 accordingly.
I like the idea. When I read the code for it, I saw a few more places where the driver could be simpler. It seemed easier to show them as patches than to describe them, so here they are for you to try on the EVO4. Please take what you like and drop the rest.
Quoted 1 line
I'll prepare a new patch 10 but won't be able to test before the week-end.
Patches 3 to 6 need the cache change as a base, so patch 2 is my version of it, only so that the rest can be tested. Please replace it with yours. Two questions came up when I wrote it:
- The notify paths clear info->cached unless get_cur_broken is set. A write-only control could not read its value back after that. Patch 2 sets get_cur_broken for the write-only controls. Is that a correct use of the field?
- The interrupt path clears the bit of the channel number in the message, and channel 0 clears all bits. Patch 2 uses the channel index in the element as the bit. Would the channel number of the request fit your EVO4 events better?
Quoted 1 line
Do you think it makes sense to refactor FU12 caching as well?
Yes, I think so: the driver then has one cache. Patch 6 does it.
The patches:
1. Not for merging. It has the changes from your review as one diff, so that patches 2 to 6 apply to the RFC with the enum fix.
2. Use cached and cache_val[] of usb_mixer_elem_info.
3. Replace INIT_HW, FORCE_SET and CACHE with an access mode:
read-back, cached or write-only. The tables use only these three combinations of the flags. Do you plan to use another combination on the EVO4, for example INIT_HW on a control that can be read? If so, I will drop this patch.
4. Fill the cache on the first get or put, not at probe. The probe then sends 12 fewer GET requests on the EVO4 and 56 fewer on the iD14. Is there a reason for the EVO4 to read at probe?
5. Use one get and one put for booleans, integers and enums. This changes the code path of the EVO4 controls, which I cannot test.
6. Use the same cache for the FU 12 control.
Patches 2 to 6 make mixer_audient.c about 100 lines shorter (227 insertions, 324 deletions). Only patch 4 is meant to change behaviour.
Each patch builds with W=1 without warnings, and checkpatch --strict shows no errors or warnings. On the iD14 MkI (stable 7.2.15) the read and write checks of the controls pass with all six patches, change events included. In 7.2.15 cached is still an int, so that build used bit masks in place of the bitmap calls.
If some of these look useful, please take them into your new RFC in any form you like. I can also fold them into the earlier patches, if that saves you time.
Thanks,
Will
Will Porter (6):
ALSA: mixer_audient: Fold in the review changes to patches 12-16
ALSA: mixer_audient: Use the cache of usb_mixer_elem_info
ALSA: mixer_audient: Replace three flags with an access mode
ALSA: mixer_audient: Fill the cache on first use
ALSA: mixer_audient: Use one get and one put for all control types
ALSA: mixer_audient: Use the same cache for the iD14 MkI FU 12 control
sound/usb/mixer_audient.c | 589 ++++++++++++++++---------------------- sound/usb/mixer_quirks.c | 2 - 2 files changed, 251 insertions(+), 340 deletions(-)
Signature · 1 line
2.47.3
RFC PATCH 1/6 ALSA: mixer_audient: Fold in the review changes to patches 12-16
This patch is not for merging. It carries the changes from the review of RFC patches 12 to 16 as one diff, so that the patches after it apply to the RFC with the enum fix. The next version of the series has these changes in patches 12, 13, 15 and 16.
- Declare snd_audient_int_max(), snd_audient_int_min() and snd_audient_int_from_ctl() inline.
- snd_audient_enum_item() returns the item or -EIO, and get propagates the error.
- snd_ctl_audient_info() uses a switch.
- A comment on ID14_ENUM() says that readable enums do not use init.
- The two case labels in mixer_quirks.c share one call.
- Rename the create hook to extra_init and say that it is optional.
--- sound/usb/mixer_audient.c | 58 +++++++++++++++++++++++---------------- sound/usb/mixer_quirks.c | 2 -- 2 files changed, 34 insertions(+), 26 deletions(-)
sound/usb/mixer_audient.c +34 -24
@@ -219,6 +219,11 @@ SND_AUDIENT_ENUM(snd_audient_id14_optical, snd_audient_id14_optical_texts, .sel = (sel_), \ } +/* +* A readable enum. It has no cache entry, so a get always reads the device +* and never uses init. Write-only enums set .init and .flags without this +* macro. +*/ #define ID14_ENUM (unit_, sel_, len_, enum_) \ { \ .type = SNDRV_CTL_ELEM_TYPE_ENUMERATED, \
@@ -494,8 +499,8 @@ static const struct audient_devinfo {const struct snd_audient_ctrl *controls;const char *const *const matrix_names;const unsigned int matrix_channels; -/* controls the tables cannot describe; called after the tables */ -int (*create)(struct usb_mixer_interface *mixer); +/* optional: controls the tables cannot describe, created after them */ +int (*extra_init)(struct usb_mixer_interface *mixer); } audient_devinfo[] = { { .usb_id = USB_ID(USB_AUDIENT_VID, USB_EVO4_PID),
@@ -508,7 +513,7 @@ static const struct audient_devinfo { .controls = snd_audient_id14_mk1_controls, .matrix_names = snd_audient_id14_mk1_matrix, .matrix_channels = 2, - .create = snd_audient_id14_mk1_create, + .extra_init = snd_audient_id14_mk1_create, }, { 0 } /* sentinel */ };
@@ -779,13 +784,15 @@ static int snd_ctl_audient_boolean_set(struct snd_kcontrol *kctl,* With a step size (res), an integer control counts steps from min: * 0 ... (max - min) / res. Without one it shows the device value. */ -static long snd_audient_int_max (const struct snd_audient_ctrl_type *ctype) +static inline long +snd_audient_int_max (const struct snd_audient_ctrl_type *ctype) {return ctype->res ? (ctype->max.integer - ctype->min.integer) / ctype->res : ctype->max.integer; } -static long snd_audient_int_min (const struct snd_audient_ctrl_type *ctype) +static inline long +snd_audient_int_min (const struct snd_audient_ctrl_type *ctype) {return ctype->res ?0 : ctype->min.integer; }
@@ -802,8 +809,8 @@ static long snd_audient_int_to_ctl(const struct snd_audient_ctrl_type *ctype, snd_audient_int_max(ctype)); } -static long snd_audient_int_from_ctl (const struct snd_audient_ctrl_type *ctype, -long val) +static inline long +snd_audient_int_from_ctl (const struct snd_audient_ctrl_type *ctype,long val) {return ctype->res ? ctype->min.integer + val * ctype->res : val; }
@@ -896,16 +903,16 @@ static int snd_ctl_audient_integer_set(struct snd_kcontrol *kctl,return changed; } -static unsigned int snd_audient_enum_item (const struct snd_audient_enum *e, -u32 value) +/* The item index of a device value, or -EIO if the value is not in the list */ +static int snd_audient_enum_item (const struct snd_audient_enum *e,u32 value) {unsigned int item;for (item =0 ; item < e->items; item++)if (e->values[item] == value) -break ; +return item; -return item;/* e->items: not in the list */ +return -EIO ; } static int snd_ctl_audient_enum_get(struct snd_kcontrol *kctl,
@@ -929,8 +936,8 @@ static int snd_ctl_audient_enum_get(struct snd_kcontrol *kctl,guard (mutex)(&mixer->lock);for (i =0 ; i < hwchan; i++) { -unsigned int item;u32 val; +int item;int ret; ret = snd_audient_raw_get_one(mixer, ctype,
@@ -942,8 +949,8 @@ static int snd_ctl_audient_enum_get(struct snd_kcontrol *kctl,return ret; item =snd_audient_enum_item (ctype->enumeration, val); -if (item >= ctype->enumeration->items) -return -EIO ; +if (item <0 ) +return item; ctl_val->value.enumerated.item[i] = item; }
@@ -1002,22 +1009,25 @@ static int snd_ctl_audient_info(struct snd_kcontrol *kctl,const struct snd_audient_ctrl_type *const ctype =snd_audient_kctl_type (kctl); -if (ctype->type ==SNDRV_CTL_ELEM_TYPE_ENUMERATED ) -return snd_ctl_enum_info (uinfo,snd_audient_kctl_channels (kctl), +switch (ctype->type) { +case SNDRV_CTL_ELEM_TYPE_ENUMERATED : +return snd_ctl_enum_info (uinfo, +snd_audient_kctl_channels (kctl), ctype->enumeration->items, ctype->enumeration->texts); - - uinfo->type = ctype->type; - uinfo->count =snd_audient_kctl_channels (kctl); - -if (ctype->type ==SNDRV_CTL_ELEM_TYPE_BOOLEAN ) { +case SNDRV_CTL_ELEM_TYPE_BOOLEAN : uinfo->value.integer.min =0 ; uinfo->value.integer.max =1 ; - }else { +break ; +default : uinfo->value.integer.min =snd_audient_int_min (ctype); uinfo->value.integer.max =snd_audient_int_max (ctype); +break ; } + uinfo->type = ctype->type; + uinfo->count =snd_audient_kctl_channels (kctl); +return 0 ; }
@@ -1332,8 +1342,8 @@ int snd_audient_controls_create(struct usb_mixer_interface *mixer) } } -if (info->create) -return info->create (mixer); +if (info->extra_init) +return info->extra_init (mixer);return 0 ; }
sound/usb/mixer_quirks.c +0 -2
@@ -4541,8 +4541,6 @@ int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)break ;case USB_ID (USB_AUDIENT_VID ,USB_EVO4_PID ):/* Audient EVO 4 */ - err =snd_audient_controls_create (mixer); -break ;case USB_ID (USB_AUDIENT_VID ,USB_ID14_MK1_PID ):/* Audient iD14 MkI */ err =snd_audient_controls_create (mixer);break ;
Signature · 1 line
2.47.3
RFC PATCH 2/6 ALSA: mixer_audient: Use the cache of usb_mixer_elem_info
In reply to Will PorterA cached control keeps its values in an array that is allocated after the element and reached through elem->private_data. Every struct usb_mixer_elem_info already has fields for this: the cached bitmap and the cache_val[] array.
Use bit i of elem->cached and elem->cache_val[i] for element channel i. The bit means what the valid flag meant: a transfer confirmed the value. A successful read or write records the value and sets its bit. A failed transfer leaves the cached value and the bit unchanged. Remove the cache struct, its accessor and the extra allocation.
The generic cache holds MAX_CHANNELS values, so refuse a control with more hardware channels. No control in the tables has more than two.
The generic notify paths clear the cache of an element unless get_cur_broken is set. A write-only control cannot read its value back after that, so set get_cur_broken for the cached FORCE_SET controls. The notify paths do not reach these elements today, because the elements do not set their unit id.
No functional change for the controls in the tables.
--- sound/usb/mixer_audient.c | 131 +++++++++++++++++--------------------- 1 file changed, 60 insertions(+), 71 deletions(-)
sound/usb/mixer_audient.c +60 -71
@@ -555,24 +555,13 @@ static inline u16 snd_audient_kctl_channels(struct snd_kcontrol *kctl) }/* -* A cached value is valid once a transfer confirmed it: a read, or a write -* that succeeded. A probe transfer that fails leaves it invalid. CACHE | -* FORCE_SET without INIT_HW keeps the earlier behaviour: the init value is -* assumed, without a transfer. +* A cached control keeps its values in the cache of struct +* usb_mixer_elem_info: bit i of elem->cached and elem->cache_val[i] for +* element channel i. The bit is set once a transfer confirmed the value: a +* read, or a write that succeeded. A probe transfer that fails leaves it +* clear. CACHE | FORCE_SET without INIT_HW keeps the earlier behaviour: the +* init value is assumed, without a transfer. */ -struct snd_audient_cache_entry { -u32 value; -bool valid; -}; - -/* Cache entry of element channel i, or NULL for an uncached control. */ -static inline struct snd_audient_cache_entry * -snd_audient_cache_slot (struct usb_mixer_elem_info *elem,unsigned int i) -{ -struct snd_audient_cache_entry *const cache = elem->private_data; - -return cache ? cache + i :NULL ; -}#define AUDIENT_REQTYPE_SET (USB_DIR_OUT | USB_TYPE_CLASS \
@@ -621,26 +610,28 @@ static inline int snd_audient_set_cur(struct usb_mixer_interface *mixer, } -static int snd_audient_raw_get_one (struct usb_mixer_interface *const mixer, +static int snd_audient_raw_get_one (struct usb_mixer_elem_info *const elem,const struct snd_audient_ctrl_type *const ctype, -struct snd_audient_cache_entry *const slot, -const u8 cidx,u32 *const value) +const unsigned int ch,const u8 cidx, +u32 *const value) { +struct usb_mixer_interface *const mixer = elem->head.mixer; +const bool cache = ctype->flags &SND_AUDIENT_CTYPE_FLAGS_CACHE ;int ret;__le32 buf =0 ;s32 val; -if (slot && slot->valid) { - *value = slot->value; +if (cache &&test_bit (ch, elem->cached)) { + *value = elem->cache_val[ch];return ctype->len; }/* -* Cached FORCE_SET controls are treated as write-only: an invalid -* cache entry does not trigger a GET. +* Cached FORCE_SET controls are treated as write-only: a clear +* cache bit does not trigger a GET. */ -if (slot && (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_FORCE_SET )) +if (cache && (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_FORCE_SET ))return -ENODATA ; ret =snd_audient_get_cur (mixer, ctype, cidx, &buf);
@@ -654,27 +645,27 @@ static int snd_audient_raw_get_one(struct usb_mixer_interface *const mixer, *value = val; -if (slot) { - slot->value = val; - slot->valid = true; +if (cache) { + elem->cache_val[ch] = val; +set_bit (ch, elem->cached); }return ret; } -static int snd_audient_raw_set_one (struct usb_mixer_interface *const mixer, +static int snd_audient_raw_set_one (struct usb_mixer_elem_info *const elem,const struct snd_audient_ctrl_type *const ctype, -struct snd_audient_cache_entry *const slot, -const u8 cidx,const u32 value, -bool force) +const unsigned int ch,const u8 cidx, +const u32 value,bool force) { +struct usb_mixer_interface *const mixer = elem->head.mixer;int ret;u32 val;if (force) { val = !value;/* just make it different */ }else { - ret =snd_audient_raw_get_one (mixer, ctype, slot, cidx, &val); + ret =snd_audient_raw_get_one (elem, ctype, ch, cidx, &val);if (ret == -ENODATA )/* FORCE_SET and not cached yet */ val = !value;/* just make it different */ else if (ret <0 )
@@ -690,9 +681,9 @@ static int snd_audient_raw_set_one(struct usb_mixer_interface *const mixer,if (ret <0 )return ret; -if (slot) { - slot->value = value; - slot->valid = true; +if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_CACHE ) { + elem->cache_val[ch] = value; +set_bit (ch, elem->cached); } }
@@ -724,9 +715,8 @@ static int snd_ctl_audient_boolean_get(struct snd_kcontrol *kctl,u32 buf;int ret; - ret =snd_audient_raw_get_one (mixer, ctype, -snd_audient_cache_slot (elem, i), - base + i, &buf); + ret =snd_audient_raw_get_one (elem, ctype, i, base + i, + &buf);if (ret == -ENODATA )/* unknown write-only value: off */ buf = ctype->min.integer;else if (ret <0 )
@@ -767,9 +757,8 @@ static int snd_ctl_audient_boolean_set(struct snd_kcontrol *kctl, : ctype->min.integer;int ret; - ret =snd_audient_raw_set_one (mixer, ctype, -snd_audient_cache_slot (elem, i), - base + i, buf, false); + ret =snd_audient_raw_set_one (elem, ctype, i, base + i, + buf, false);if (ret <0 )return ret;
@@ -839,9 +828,8 @@ static int snd_ctl_audient_integer_get(struct snd_kcontrol *kctl,s32 val;int ret; - ret =snd_audient_raw_get_one (mixer, ctype, -snd_audient_cache_slot (elem, i), - base + i, &val); + ret =snd_audient_raw_get_one (elem, ctype, i, base + i, + &val);if (ret == -ENODATA )/* unknown write-only value: minimum */ val = ctype->min.integer;else if (ret <0 )
@@ -890,9 +878,8 @@ static int snd_ctl_audient_integer_set(struct snd_kcontrol *kctl, ctl_val->value.integer.value[i]);int ret; - ret =snd_audient_raw_set_one (mixer, ctype, -snd_audient_cache_slot (elem, i), - base + i, val, false); + ret =snd_audient_raw_set_one (elem, ctype, i, base + i, + val, false);if (ret <0 )return ret;
@@ -940,9 +927,8 @@ static int snd_ctl_audient_enum_get(struct snd_kcontrol *kctl,int item;int ret; - ret =snd_audient_raw_get_one (mixer, ctype, -snd_audient_cache_slot (elem, i), - base + i, &val); + ret =snd_audient_raw_get_one (elem, ctype, i, base + i, + &val);if (ret == -ENODATA )/* unknown write-only value: init */ val = ctype->init;else if (ret <0 )
@@ -990,9 +976,8 @@ static int snd_ctl_audient_enum_set(struct snd_kcontrol *kctl,const unsigned int item = ctl_val->value.enumerated.item[i];int ret; - ret =snd_audient_raw_set_one (mixer, ctype, -snd_audient_cache_slot (elem, i), - base + i, e->values[item], false); + ret =snd_audient_raw_set_one (elem, ctype, i, base + i, + e->values[item], false);if (ret <0 )return ret;
@@ -1072,24 +1057,28 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer,return -EINVAL ; } - elem =kzalloc (sizeof (*elem) - + ((ctype->flags &SND_AUDIENT_CTYPE_FLAGS_CACHE ) - ? (sizeof (struct snd_audient_cache_entry ) - * ctrl->hwchannels) - :0 ), -GFP_KERNEL ); +if (ctrl->hwchannels >MAX_CHANNELS ) +return -EINVAL ; + + elem =kzalloc_obj (*elem);if (!elem)return -ENOMEM ; elem->head.mixer = mixer; elem->channels = ctrl->channels; -if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_CACHE ) - elem->private_data = elem +1 ; +/* +* The generic notify paths clear the cache of an element unless +* get_cur_broken is set. A write-only control cannot read its value +* back after that. +*/ +if ((ctype->flags &SND_AUDIENT_CTYPE_FLAGS_CACHE ) && + (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_FORCE_SET )) + elem->get_cur_broken =1 ;/* * A failed probe transfer must not fail the card: warn and keep the -* control. Its cache entry stays invalid, so a readable control reads +* control. Its cache bit stays clear, so a readable control reads * the device again on its next get, and a write-only control shows an * unknown value until a put succeeds. */
@@ -1097,8 +1086,7 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer,int i;for (i =0 ; i < ctrl->hwchannels; i++) { - ret =snd_audient_raw_set_one (mixer, ctype, -snd_audient_cache_slot (elem, i), + ret =snd_audient_raw_set_one (elem, ctype, i, ctrl->val_offs + i, ctype->init, true);if (ret <0 )
@@ -1106,20 +1094,21 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer,"%s: cannot set channel %d (%d)\n" , ctrl->name, i, ret); } - }else if (elem->private_data) { -struct snd_audient_cache_entry *const cache = elem->private_data; + }else if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_CACHE ) {int i;for (i =0 ; i < ctrl->hwchannels; i++) { +u32 val; +if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_FORCE_SET ) { - cache[i].value = ctype->init; - cache[i].valid = true; + elem->cache_val[i] = ctype->init; +set_bit (i, elem->cached);continue ; } - ret =snd_audient_raw_get_one (mixer, ctype, cache + i, + ret =snd_audient_raw_get_one (elem, ctype, i, ctrl->val_offs + i, - &cache[i].value); + &val);if (ret <0 ) usb_audio_warn(mixer->chip, "%s: cannot read channel %d (%d)\n",
Signature · 1 line
2.47.3
RFC PATCH 3/6 ALSA: mixer_audient: Replace three flags with an access mode
In reply to Will PorterThe INIT_HW, FORCE_SET and CACHE flags allow eight combinations. The control tables use three: no flag, CACHE alone, and all three together (ID14_WO). Name these three with an enum in a new field, access:
READBACK: every get reads the device
CACHED: read once, then use the cache
WRITE_ONLY: never read; show the last write
The SIGNED flag stays.
With a mode, the set helper decides "is it a change" and "send it" separately. It no longer needs the force argument, or a compare value that is made different to force a write. The probe write of a write-only control calls the send helper directly.
The mode also decides the VOLATILE access bit and get_cur_broken. Remove the ID14_WO macro and the code for the combinations that no table uses.
No functional change for the controls in the tables.
--- sound/usb/mixer_audient.c | 172 ++++++++++++++++++++------------------ 1 file changed, 90 insertions(+), 82 deletions(-)
sound/usb/mixer_audient.c +90 -82
@@ -62,9 +62,23 @@ enum snd_audient_type { static const DECLARE_TLV_DB_MINMAX_MUTE(snd_audient_tlv_mixer, -12800, 600);#define SND_AUDIENT_CTYPE_FLAGS_SIGNED BIT(0) -#define SND_AUDIENT_CTYPE_FLAGS_INIT_HW BIT(1) -#define SND_AUDIENT_CTYPE_FLAGS_FORCE_SET BIT(2) -#define SND_AUDIENT_CTYPE_FLAGS_CACHE BIT(3) + +/* +* How a control reaches the device. +* +* A cached value is valid once a transfer confirmed it. A read or a write +* that succeeds records the value and sets its cache bit. A transfer that +* fails leaves the cached value and the bit unchanged. +* +* WRITE_ONLY: GET stalls or does not report writes. The driver writes the +* init value at probe and sends every put. A get shows the last value +* written, or an unknown value while none was. +*/ +enum snd_audient_access { +SND_AUDIENT_ACCESS_READBACK =0 ,/* every get reads the device */ +SND_AUDIENT_ACCESS_CACHED ,/* read once, then use the cache */ +SND_AUDIENT_ACCESS_WRITE_ONLY ,/* never read; show the last write */ +};/* * An enumerated control: item i sends values[i]. A get of a device value
@@ -177,14 +191,6 @@ static const char *const snd_audient_id14_optical_texts[] = {SND_AUDIENT_ENUM (snd_audient_id14_optical, snd_audient_id14_optical_texts,0 ,1 ); -/* -* Write-only: GET stalls or does not report writes. Show the last value -* written, write the init value at probe, and send every put. -*/ -#define ID14_WO (SND_AUDIENT_CTYPE_FLAGS_CACHE \ - | SND_AUDIENT_CTYPE_FLAGS_FORCE_SET \ - | SND_AUDIENT_CTYPE_FLAGS_INIT_HW) -#define ID14_BOOL (unit_, sel_) \ { \ .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, \
@@ -220,9 +226,9 @@ SND_AUDIENT_ENUM(snd_audient_id14_optical, snd_audient_id14_optical_texts, }/* -* A readable enum. It has no cache entry, so a get always reads the device -* and never uses init. Write-only enums set .init and .flags without this -* macro. +* A readable enum. Its access mode is READBACK, so a get always reads the +* device and never uses init. Write-only enums set .init and .access +* without this macro. */ #define ID14_ENUM (unit_, sel_, len_, enum_) \ { \
@@ -235,6 +241,7 @@ SND_AUDIENT_ENUM(snd_audient_id14_optical, snd_audient_id14_optical_texts, static const struct snd_audient_ctrl_type { snd_ctl_elem_type_t type; + enum snd_audient_access access; unsigned long flags; size_t len; /* datatype size, can be 1, 2 or 4 bytes */ union {
@@ -285,8 +292,8 @@ static const struct snd_audient_ctrl_type { }, [SND_AUDIENT_TYPE_MIXER] = { .type = SNDRV_CTL_ELEM_TYPE_INTEGER, - .flags =SND_AUDIENT_CTYPE_FLAGS_SIGNED - | SND_AUDIENT_CTYPE_FLAGS_CACHE, + .access = SND_AUDIENT_ACCESS_CACHED, + .flags = SND_AUDIENT_CTYPE_FLAGS_SIGNED, .len = 2, .min.integer = -128 * 256, .max.integer = 6 * 256,
@@ -330,7 +337,7 @@ static const struct snd_audient_ctrl_type { /* the documented boost is a fixed +10 dB */ [SND_AUDIENT_TYPE_ID14_IN_BOOST] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, - .flags = ID14_WO, + .access = SND_AUDIENT_ACCESS_WRITE_ONLY, .len = 2, .min.integer = 0, .max.integer = 10 * 256,
@@ -340,7 +347,7 @@ static const struct snd_audient_ctrl_type { }, [SND_AUDIENT_TYPE_ID14_IN_POLARITY] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, - .flags = ID14_WO, + .access = SND_AUDIENT_ACCESS_WRITE_ONLY, .len = 1, .min.integer = 0, .max.integer = 1,
@@ -350,7 +357,7 @@ static const struct snd_audient_ctrl_type { }, [SND_AUDIENT_TYPE_ID14_MON_ID_KEY] = { .type = SNDRV_CTL_ELEM_TYPE_ENUMERATED, - .flags = ID14_WO, + .access = SND_AUDIENT_ACCESS_WRITE_ONLY, .len = 2, .init = 0xffff, /* ScrollControl */ .enumeration = &snd_audient_id14_id_key,
@@ -359,7 +366,7 @@ static const struct snd_audient_ctrl_type { }, [SND_AUDIENT_TYPE_ID14_MON_TALKBACK_SRC] = { .type = SNDRV_CTL_ELEM_TYPE_ENUMERATED, - .flags = ID14_WO, + .access = SND_AUDIENT_ACCESS_WRITE_ONLY, .len = 1, .init = 0xff, /* None */ .enumeration = &snd_audient_id14_talkback,
@@ -369,7 +376,7 @@ static const struct snd_audient_ctrl_type { /* the power-on mode is S/PDIF */ [SND_AUDIENT_TYPE_ID14_OPTICAL_MODE] = { .type = SNDRV_CTL_ELEM_TYPE_ENUMERATED, - .flags = ID14_WO, + .access = SND_AUDIENT_ACCESS_WRITE_ONLY, .len = 4, .init = 1, /* S/PDIF */ .enumeration = &snd_audient_id14_optical,
@@ -557,10 +564,7 @@ static inline u16 snd_audient_kctl_channels(struct snd_kcontrol *kctl)/* * A cached control keeps its values in the cache of struct * usb_mixer_elem_info: bit i of elem->cached and elem->cache_val[i] for -* element channel i. The bit is set once a transfer confirmed the value: a -* read, or a write that succeeded. A probe transfer that fails leaves it -* clear. CACHE | FORCE_SET without INIT_HW keeps the earlier behaviour: the -* init value is assumed, without a transfer. +* element channel i. See enum snd_audient_access for when the bit is set. */
@@ -611,27 +615,24 @@ static inline int snd_audient_set_cur(struct usb_mixer_interface *mixer,static int snd_audient_raw_get_one (struct usb_mixer_elem_info *const elem, -const struct snd_audient_ctrl_type *const ctype, -const unsigned int ch,const u8 cidx, -u32 *const value) +const struct snd_audient_ctrl_type *const ctype, +const unsigned int ch,const u8 cidx, +u32 *const value) {struct usb_mixer_interface *const mixer = elem->head.mixer; -const bool cache = ctype->flags &SND_AUDIENT_CTYPE_FLAGS_CACHE ;int ret;__le32 buf =0 ;s32 val; -if (cache &&test_bit (ch, elem->cached)) { +if (ctype->access !=SND_AUDIENT_ACCESS_READBACK && +test_bit (ch, elem->cached)) { *value = elem->cache_val[ch];return ctype->len; } -/* -* Cached FORCE_SET controls are treated as write-only: a clear -* cache bit does not trigger a GET. -*/ -if (cache && (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_FORCE_SET )) +/* A write-only control never sends a GET: its value is unknown. */ +if (ctype->access ==SND_AUDIENT_ACCESS_WRITE_ONLY )return -ENODATA ; ret =snd_audient_get_cur (mixer, ctype, cidx, &buf);
@@ -645,7 +646,7 @@ static int snd_audient_raw_get_one(struct usb_mixer_elem_info *const elem, *value = val; -if (cache) { +if (ctype->access ==SND_AUDIENT_ACCESS_CACHED ) { elem->cache_val[ch] = val;set_bit (ch, elem->cached); }
@@ -653,41 +654,55 @@ static int snd_audient_raw_get_one(struct usb_mixer_elem_info *const elem,return ret; } -static int snd_audient_raw_set_one (struct usb_mixer_elem_info *const elem, -const struct snd_audient_ctrl_type *const ctype, -const unsigned int ch,const u8 cidx, -const u32 value,bool force) +/* Send a value and, for a cached control, record that the device has it. */ +static int snd_audient_raw_send_one (struct usb_mixer_elem_info *const elem, +const struct snd_audient_ctrl_type *const ctype, +const unsigned int ch,const u8 cidx, +const u32 value) { -struct usb_mixer_interface *const mixer = elem->head.mixer; +__le32 buf =cpu_to_le32 (value);int ret; -u32 val; - -if (force) { - val = !value;/* just make it different */ - }else { - ret =snd_audient_raw_get_one (elem, ctype, ch, cidx, &val); -if (ret == -ENODATA )/* FORCE_SET and not cached yet */ - val = !value;/* just make it different */ -else if (ret <0 ) -return ret; + + ret =snd_audient_set_cur (elem->head.mixer, ctype, cidx, &buf); +if (ret <0 ) +return ret; + +if (ctype->access !=SND_AUDIENT_ACCESS_READBACK ) { + elem->cache_val[ch] = value; +set_bit (ch, elem->cached); } - force = force || (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_FORCE_SET ); +return 0 ; +} + +/* +* Set one channel. Returns 1 if the value changed, 0 if not, or a negative +* error. A write-only control sends every value; the others send only a +* changed one. +*/ +static int snd_audient_raw_set_one (struct usb_mixer_elem_info *const elem, +const struct snd_audient_ctrl_type *const ctype, +const unsigned int ch,const u8 cidx, +const u32 value) +{ +bool changed; +u32 cur =0 ; +int ret; + + ret =snd_audient_raw_get_one (elem, ctype, ch, cidx, &cur); +if (ret <0 && ret != -ENODATA ) +return ret; -if (force || (val != value)) { -__le32 buf =cpu_to_le32 (value); +/* -ENODATA: write-only and not cached yet */ + changed = ret == -ENODATA || cur != value; - ret =snd_audient_set_cur (mixer, ctype, cidx, &buf); +if (changed || ctype->access ==SND_AUDIENT_ACCESS_WRITE_ONLY ) { + ret =snd_audient_raw_send_one (elem, ctype, ch, cidx, value);if (ret <0 )return ret; - -if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_CACHE ) { - elem->cache_val[ch] = value; -set_bit (ch, elem->cached); - } } -return val != value; +return changed; }
@@ -758,7 +773,7 @@ static int snd_ctl_audient_boolean_set(struct snd_kcontrol *kctl,int ret; ret =snd_audient_raw_set_one (elem, ctype, i, base + i, - buf, false); + buf);if (ret <0 )return ret;
@@ -879,7 +894,7 @@ static int snd_ctl_audient_integer_set(struct snd_kcontrol *kctl,int ret; ret =snd_audient_raw_set_one (elem, ctype, i, base + i, - val, false); + val);if (ret <0 )return ret;
@@ -977,7 +992,7 @@ static int snd_ctl_audient_enum_set(struct snd_kcontrol *kctl,int ret; ret =snd_audient_raw_set_one (elem, ctype, i, base + i, - e->values[item], false); + e->values[item]);if (ret <0 )return ret;
@@ -1035,9 +1050,9 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer, ctrl->hwchannels); knew.tlv.p = ctype->tlv; knew.access =SNDRV_CTL_ELEM_ACCESS_READWRITE - | ((ctype->flags &SND_AUDIENT_CTYPE_FLAGS_CACHE ) - ?0 - :SNDRV_CTL_ELEM_ACCESS_VOLATILE ) + | ((ctype->access ==SND_AUDIENT_ACCESS_READBACK ) + ?SNDRV_CTL_ELEM_ACCESS_VOLATILE + :0 ) | (ctype->tlv ?SNDRV_CTL_ELEM_ACCESS_TLV_READ :0 );switch (ctype->type) {
@@ -1072,40 +1087,33 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer,* get_cur_broken is set. A write-only control cannot read its value * back after that. */ -if ((ctype->flags &SND_AUDIENT_CTYPE_FLAGS_CACHE ) && - (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_FORCE_SET )) +if (ctype->access ==SND_AUDIENT_ACCESS_WRITE_ONLY ) elem->get_cur_broken =1 ;/* * A failed probe transfer must not fail the card: warn and keep the -* control. Its cache bit stays clear, so a readable control reads -* the device again on its next get, and a write-only control shows an +* control. Its cache bit stays clear, so a cached control reads the +* device again on its next get, and a write-only control shows an * unknown value until a put succeeds. */ -if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_INIT_HW ) { +if (ctype->access ==SND_AUDIENT_ACCESS_WRITE_ONLY ) {int i;for (i =0 ; i < ctrl->hwchannels; i++) { - ret =snd_audient_raw_set_one (elem, ctype, i, - ctrl->val_offs + i, - ctype->init, true); + ret =snd_audient_raw_send_one (elem, ctype, i, + ctrl->val_offs + i, + ctype->init);if (ret <0 )usb_audio_warn (mixer->chip,"%s: cannot set channel %d (%d)\n" , ctrl->name, i, ret); } - }else if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_CACHE ) { + }else if (ctype->access ==SND_AUDIENT_ACCESS_CACHED ) {int i;for (i =0 ; i < ctrl->hwchannels; i++) {u32 val; -if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_FORCE_SET ) { - elem->cache_val[i] = ctype->init; -set_bit (i, elem->cached); -continue ; - } - ret =snd_audient_raw_get_one (elem, ctype, i, ctrl->val_offs + i, &val);
Signature · 1 line
2.47.3
RFC PATCH 4/6 ALSA: mixer_audient: Fill the cache on first use
In reply to Will PorterThe probe reads every channel of a cached control. That is not
necessary: a get or put of a channel whose cache bit is clear already reads the device and fills the cache.
Remove the probe read of cached controls. A failed first read returns its error to the caller and leaves the cache bit clear, so the next call reads again.
This changes behaviour. The probe sends no GET for a cached control:
that is 12 fewer requests on the EVO4 and 56 fewer on the iD14 MkI. A failed read no longer logs "cannot read channel" at probe. A put to a channel whose cache bit is clear first sends a GET, then sends a SET only if the value differs.
The probe write of the init value of write-only controls stays.
--- sound/usb/mixer_audient.c | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-)
sound/usb/mixer_audient.c +4 -18
@@ -1091,10 +1091,10 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer, elem->get_cur_broken =1 ;/* -* A failed probe transfer must not fail the card: warn and keep the -* control. Its cache bit stays clear, so a cached control reads the -* device again on its next get, and a write-only control shows an -* unknown value until a put succeeds. +* A cached control reads the device on its first get or put. A +* write-only control is written once at probe. A failed probe write +* must not fail the card: warn and keep the control. Its cache bit +* stays clear, so it shows an unknown value until a put succeeds. */ if (ctype->access ==SND_AUDIENT_ACCESS_WRITE_ONLY ) {int i;
@@ -1108,20 +1108,6 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer,"%s: cannot set channel %d (%d)\n" , ctrl->name, i, ret); } - }else if (ctype->access ==SND_AUDIENT_ACCESS_CACHED ) { -int i; - -for (i =0 ; i < ctrl->hwchannels; i++) { -u32 val; - - ret =snd_audient_raw_get_one (elem, ctype, i, - ctrl->val_offs + i, - &val); -if (ret <0 ) -usb_audio_warn (mixer->chip, -"%s: cannot read channel %d (%d)\n" , - ctrl->name, i, ret); - } } kctl =snd_ctl_new1 (&knew, elem);
Signature · 1 line
2.47.3
RFC PATCH 5/6 ALSA: mixer_audient: Use one get and one put for all control types
In reply to Will PorterThe boolean, integer and enum get and put functions differ only in how they convert a value between the device and the control. Replace the six functions with snd_ctl_audient_get() and snd_ctl_audient_put(). Three helpers switch on the control type: one converts a device value to a control value, one converts a control value back and checks its range, and one fills a channel that has no hardware.
The locking and the order stay. Put checks every hardware channel before it takes the lock or sends a request. Get returns -EIO for an enum value that is not in the list.
The get functions showed an unknown write-only value as off, as the minimum or as init, by type. Every write-only control in the tables is a boolean whose init equals min, or an enum. So init gives the same value for each of them: use init for all types.
No functional change for the controls in the tables.
--- sound/usb/mixer_audient.c | 284 ++++++++++++++------------------------ 1 file changed, 101 insertions(+), 183 deletions(-)
sound/usb/mixer_audient.c +101 -183
@@ -706,84 +706,6 @@ static int snd_audient_raw_set_one(struct usb_mixer_elem_info *const elem, } -static int snd_ctl_audient_boolean_get (struct snd_kcontrol *kctl, -struct snd_ctl_elem_value *ctl_val) -{ -struct usb_mixer_elem_info *const elem =snd_kcontrol_chip (kctl); -struct usb_mixer_interface *const mixer = elem->head.mixer; - -const unsigned int nchan =snd_audient_kctl_channels (kctl); -const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl); -const struct snd_audient_ctrl_type *const ctype - =snd_audient_kctl_type (kctl); -const u8 base =snd_audient_kctl_cidxoffs (kctl); - -int i; - -CLASS (snd_usb_lock, pm)(mixer->chip); -if (pm.err <0 ) -return pm.err; -/* serializes the transfers and the cache, also between gets */ -guard (mutex)(&mixer->lock); - -for (i =0 ; i < hwchan; i++) { -u32 buf; -int ret; - - ret =snd_audient_raw_get_one (elem, ctype, i, base + i, - &buf); -if (ret == -ENODATA )/* unknown write-only value: off */ - buf = ctype->min.integer; -else if (ret <0 ) -return ret; - - ctl_val->value.integer.value[i] = (buf == ctype->min.integer) - ? false : true; - } - -for (; i < nchan; i++) - ctl_val->value.integer.value[i] =0 ; - -return 0 ; -} - -static int snd_ctl_audient_boolean_set (struct snd_kcontrol *kctl, -struct snd_ctl_elem_value *ctl_val) -{ -struct usb_mixer_elem_info *const elem =snd_kcontrol_chip (kctl); -struct usb_mixer_interface *const mixer = elem->head.mixer; - -const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl); -const struct snd_audient_ctrl_type *const ctype - =snd_audient_kctl_type (kctl); -const u8 base =snd_audient_kctl_cidxoffs (kctl); - -int changed =0 ; -int i; - -CLASS (snd_usb_lock, pm)(mixer->chip); -if (pm.err <0 ) -return pm.err; -/* serializes the transfers and the cache, also between gets */ -guard (mutex)(&mixer->lock); - -for (i =0 ; i < hwchan; i++) { -u32 buf = ctl_val->value.integer.value[i] ? ctype->max.integer - : ctype->min.integer; -int ret; - - ret =snd_audient_raw_set_one (elem, ctype, i, base + i, - buf); -if (ret <0 ) -return ret; - -if (ret) - changed =1 ; - } - -return changed; -} -/* * With a step size (res), an integer control counts steps from min: * 0 ... (max - min) / res. Without one it shows the device value.
@@ -819,106 +741,104 @@ snd_audient_int_from_ctl(const struct snd_audient_ctrl_type *ctype, long val)return ctype->res ? ctype->min.integer + val * ctype->res : val; } -static int snd_ctl_audient_integer_get (struct snd_kcontrol *kctl, -struct snd_ctl_elem_value *ctl_val) +/* The item index of a device value, or -EIO if the value is not in the list */ +static int snd_audient_enum_item (const struct snd_audient_enum *e,u32 value) { -struct usb_mixer_elem_info *const elem =snd_kcontrol_chip (kctl); -struct usb_mixer_interface *const mixer = elem->head.mixer; - -const unsigned int nchan =snd_audient_kctl_channels (kctl); -const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl); -const struct snd_audient_ctrl_type *const ctype - =snd_audient_kctl_type (kctl); -const u8 base =snd_audient_kctl_cidxoffs (kctl); - -int i; +unsigned int item; -CLASS (snd_usb_lock, pm)(mixer->chip); -if (pm.err <0 ) -return pm.err; -/* serializes the transfers and the cache, also between gets */ -guard (mutex)(&mixer->lock); +for (item =0 ; item < e->items; item++) +if (e->values[item] == value) +return item; -for (i =0 ; i < hwchan; i++) { -s32 val; -int ret; +return -EIO ; +} - ret =snd_audient_raw_get_one (elem, ctype, i, base + i, - &val); -if (ret == -ENODATA )/* unknown write-only value: minimum */ - val = ctype->min.integer; -else if (ret <0 ) -return ret; +/* +* Convert a device value to the control value of hardware channel i. An +* enumerated value that is not in the list returns -EIO. +*/ +static int snd_audient_value_to_ctl (const struct snd_audient_ctrl_type *ctype, +struct snd_ctl_elem_value *ctl_val, +unsigned int i,u32 raw) +{ +int item; +switch (ctype->type) { +case SNDRV_CTL_ELEM_TYPE_BOOLEAN : + ctl_val->value.integer.value[i] = raw != ctype->min.integer; +break ; +case SNDRV_CTL_ELEM_TYPE_INTEGER : ctl_val->value.integer.value[i] = -snd_audient_int_to_ctl (ctype, val); - } +snd_audient_int_to_ctl (ctype, (s32 )raw); +break ; +default :/* SNDRV_CTL_ELEM_TYPE_ENUMERATED */ + item =snd_audient_enum_item (ctype->enumeration, raw); +if (item <0 ) +return item; -for (; i < nchan; i++) - ctl_val->value.integer.value[i] =snd_audient_int_min (ctype); + ctl_val->value.enumerated.item[i] = item; +break ; + }return 0 ; } -static int snd_ctl_audient_integer_set (struct snd_kcontrol *kctl, -struct snd_ctl_elem_value *ctl_val) +/* The control value of a channel without hardware: off, minimum, item 0 */ +static void snd_audient_empty_ctl (const struct snd_audient_ctrl_type *ctype, +struct snd_ctl_elem_value *ctl_val, +unsigned int i) { -struct usb_mixer_elem_info *const elem =snd_kcontrol_chip (kctl); -struct usb_mixer_interface *mixer = elem->head.mixer; - -const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl); -const struct snd_audient_ctrl_type *const ctype - =snd_audient_kctl_type (kctl); -const u8 base =snd_audient_kctl_cidxoffs (kctl); - -int changed =0 ; -int i; +switch (ctype->type) { +case SNDRV_CTL_ELEM_TYPE_BOOLEAN : + ctl_val->value.integer.value[i] =0 ; +break ; +case SNDRV_CTL_ELEM_TYPE_INTEGER : + ctl_val->value.integer.value[i] =snd_audient_int_min (ctype); +break ; +default :/* SNDRV_CTL_ELEM_TYPE_ENUMERATED */ + ctl_val->value.enumerated.item[i] =0 ; +break ; + } +} -for (i =0 ; i < hwchan; i++) { -long val = ctl_val->value.integer.value[i]; +/* +* Convert the control value of hardware channel i to a device value. A +* value out of range returns -EINVAL; a boolean has no range error. +*/ +static int snd_audient_value_from_ctl (const struct snd_audient_ctrl_type *ctype, +const struct snd_ctl_elem_value *ctl_val, +unsigned int i,u32 *raw) +{ +unsigned int item; +long val; +switch (ctype->type) { +case SNDRV_CTL_ELEM_TYPE_BOOLEAN : + *raw = ctl_val->value.integer.value[i] ? ctype->max.integer + : ctype->min.integer; +break ; +case SNDRV_CTL_ELEM_TYPE_INTEGER : + val = ctl_val->value.integer.value[i];if (val <snd_audient_int_min (ctype) || val >snd_audient_int_max (ctype))return -EINVAL ; - } -CLASS (snd_usb_lock, pm)(mixer->chip); -if (pm.err <0 ) -return pm.err; -/* serializes the transfers and the cache, also between gets */ -guard (mutex)(&mixer->lock); - -for (i =0 ; i < hwchan; i++) { -s32 val =snd_audient_int_from_ctl (ctype, - ctl_val->value.integer.value[i]); -int ret; - - ret =snd_audient_raw_set_one (elem, ctype, i, base + i, - val); -if (ret <0 ) -return ret; + *raw = (s32 )snd_audient_int_from_ctl (ctype, val); +break ; +default :/* SNDRV_CTL_ELEM_TYPE_ENUMERATED */ + item = ctl_val->value.enumerated.item[i]; +if (item >= ctype->enumeration->items) +return -EINVAL ; -if (ret) - changed =1 ; + *raw = ctype->enumeration->values[item]; +break ; } -return changed; -} - -/* The item index of a device value, or -EIO if the value is not in the list */ -static int snd_audient_enum_item (const struct snd_audient_enum *e,u32 value) -{ -unsigned int item; - -for (item =0 ; item < e->items; item++) -if (e->values[item] == value) -return item; - -return -EIO ; +return 0 ; } -static int snd_ctl_audient_enum_get (struct snd_kcontrol *kctl, -struct snd_ctl_elem_value *ctl_val) +static int snd_ctl_audient_get (struct snd_kcontrol *kctl, +struct snd_ctl_elem_value *ctl_val) {struct usb_mixer_elem_info *const elem =snd_kcontrol_chip (kctl);struct usb_mixer_interface *const mixer = elem->head.mixer;
@@ -938,32 +858,28 @@ static int snd_ctl_audient_enum_get(struct snd_kcontrol *kctl,guard (mutex)(&mixer->lock);for (i =0 ; i < hwchan; i++) { -u32 val; -int item; +u32 raw;int ret; - ret =snd_audient_raw_get_one (elem, ctype, i, base + i, - &val); + ret =snd_audient_raw_get_one (elem, ctype, i, base + i, &raw);if (ret == -ENODATA )/* unknown write-only value: init */ - val = ctype->init; + raw = ctype->init;else if (ret <0 )return ret; - item =snd_audient_enum_item (ctype->enumeration, val); -if (item <0 ) -return item; - - ctl_val->value.enumerated.item[i] = item; + ret =snd_audient_value_to_ctl (ctype, ctl_val, i, raw); +if (ret <0 ) +return ret; }for (; i < nchan; i++) - ctl_val->value.enumerated.item[i] =0 ; +snd_audient_empty_ctl (ctype, ctl_val, i);return 0 ; } -static int snd_ctl_audient_enum_set (struct snd_kcontrol *kctl, -struct snd_ctl_elem_value *ctl_val) +static int snd_ctl_audient_put (struct snd_kcontrol *kctl, +struct snd_ctl_elem_value *ctl_val) {struct usb_mixer_elem_info *const elem =snd_kcontrol_chip (kctl);struct usb_mixer_interface *const mixer = elem->head.mixer;
@@ -971,15 +887,19 @@ static int snd_ctl_audient_enum_set(struct snd_kcontrol *kctl,const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl);const struct snd_audient_ctrl_type *const ctype =snd_audient_kctl_type (kctl); -const struct snd_audient_enum *const e = ctype->enumeration;const u8 base =snd_audient_kctl_cidxoffs (kctl);unsigned int i;int changed =0 ; -for (i =0 ; i < hwchan; i++) -if (ctl_val->value.enumerated.item[i] >= e->items) -return -EINVAL ; +for (i =0 ; i < hwchan; i++) { +u32 raw; +int ret; + + ret =snd_audient_value_from_ctl (ctype, ctl_val, i, &raw); +if (ret <0 ) +return ret; + }CLASS (snd_usb_lock, pm)(mixer->chip);if (pm.err <0 )
@@ -988,11 +908,14 @@ static int snd_ctl_audient_enum_set(struct snd_kcontrol *kctl,guard (mutex)(&mixer->lock);for (i =0 ; i < hwchan; i++) { -const unsigned int item = ctl_val->value.enumerated.item[i]; +u32 raw;int ret; - ret =snd_audient_raw_set_one (elem, ctype, i, base + i, - e->values[item]); + ret =snd_audient_value_from_ctl (ctype, ctl_val, i, &raw); +if (ret <0 ) +return ret; + + ret =snd_audient_raw_set_one (elem, ctype, i, base + i, raw);if (ret <0 )return ret;
@@ -1057,21 +980,16 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer,switch (ctype->type) {case SNDRV_CTL_ELEM_TYPE_INTEGER : - knew.get = snd_ctl_audient_integer_get; - knew.put = snd_ctl_audient_integer_set; -break ;case SNDRV_CTL_ELEM_TYPE_BOOLEAN : - knew.get = snd_ctl_audient_boolean_get; - knew.put = snd_ctl_audient_boolean_set; -break ;case SNDRV_CTL_ELEM_TYPE_ENUMERATED : - knew.get = snd_ctl_audient_enum_get; - knew.put = snd_ctl_audient_enum_set;break ;default :return -EINVAL ; } + knew.get = snd_ctl_audient_get; + knew.put = snd_ctl_audient_put; +if (ctrl->hwchannels >MAX_CHANNELS )return -EINVAL ;
Signature · 1 line
2.47.3
RFC PATCH 6/6 ALSA: mixer_audient: Use the same cache for the iD14 MkI FU 12 control
In reply to Will PorterThe FU 12 control keeps its own value array and valid mask on a struct usb_mixer_elem_list. Make it a struct usb_mixer_elem_info, and use cache_val[ch] and bit ch of cached as the other controls do. Set channels and get_cur_broken. Remove the private struct.
The list head is the first member of struct usb_mixer_elem_info, so snd_usb_mixer_elem_free() still frees the right pointer. The control is still registered with is_std_info false, so the generic notify paths do not touch it.
No functional change.
--- sound/usb/mixer_audient.c | 54 ++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 26 deletions(-)
sound/usb/mixer_audient.c +28 -26
@@ -1074,26 +1074,26 @@ static const struct snd_audient_ctrl_type snd_audient_id14_fu12_type = { .sel = UAC_FU_VOLUME, }; -struct snd_audient_id14_fu12 { -struct usb_mixer_elem_list list;/* first: snd_usb_mixer_elem_free */ -long val[ID14_FU12_CHANNELS ]; -u8 valid;/* bit per channel */ -}; - -static int snd_audient_id14_fu12_write (struct snd_audient_id14_fu12 *f, +/* +* The control is a struct usb_mixer_elem_info whose list head is registered +* with is_std_info false. The head is the first member, as +* snd_usb_mixer_elem_free needs. cache_val[ch] and bit ch of cached hold +* the last value the device accepted. +*/ +static int snd_audient_id14_fu12_write (struct usb_mixer_elem_info *elem,unsigned int ch,long val) {__le16 buf =cpu_to_le16 (val ==ID14_FU12_MUTE ?-128 *256 : (val -ID14_FU12_MAX ) *256 );int ret; - ret =snd_audient_set_cur (f->list.mixer, &snd_audient_id14_fu12_type, + ret =snd_audient_set_cur (elem->head.mixer, &snd_audient_id14_fu12_type, ch +1 , &buf);if (ret <0 )return ret; - f->val[ch] = val; - f->valid |=BIT (ch); + elem->cache_val[ch] = val; +set_bit (ch, elem->cached);return 0 ; }
@@ -1112,13 +1112,13 @@ static int snd_ctl_audient_id14_fu12_info(struct snd_kcontrol *kctl,static int snd_ctl_audient_id14_fu12_get (struct snd_kcontrol *kctl,struct snd_ctl_elem_value *ctl_val) { -struct snd_audient_id14_fu12 *f =snd_kcontrol_chip (kctl); +struct usb_mixer_elem_info *elem =snd_kcontrol_chip (kctl);unsigned int ch;/* a channel that was never written reads as mute */ for (ch =0 ; ch <ID14_FU12_CHANNELS ; ch++) - ctl_val->value.integer.value[ch] = (f->valid &BIT (ch)) - ? f->val[ch] + ctl_val->value.integer.value[ch] =test_bit (ch, elem->cached) + ? elem->cache_val[ch] :ID14_FU12_MUTE ;return 0 ;
@@ -1127,7 +1127,7 @@ static int snd_ctl_audient_id14_fu12_get(struct snd_kcontrol *kctl,static int snd_ctl_audient_id14_fu12_set (struct snd_kcontrol *kctl,struct snd_ctl_elem_value *ctl_val) { -struct snd_audient_id14_fu12 *f =snd_kcontrol_chip (kctl); +struct usb_mixer_elem_info *elem =snd_kcontrol_chip (kctl);long *const v = ctl_val->value.integer.value;unsigned int ch;int changed =0 ;
@@ -1136,7 +1136,7 @@ static int snd_ctl_audient_id14_fu12_set(struct snd_kcontrol *kctl,if (v[ch] <0 || v[ch] >ID14_FU12_MAX )return -EINVAL ; -CLASS (snd_usb_lock, pm)(f->list.mixer->chip); +CLASS (snd_usb_lock, pm)(elem->head.mixer->chip);if (pm.err <0 )return pm.err;
@@ -1147,10 +1147,10 @@ static int snd_ctl_audient_id14_fu12_set(struct snd_kcontrol *kctl,for (ch =0 ; ch <ID14_FU12_CHANNELS ; ch++) {int ret; -if (!(f->valid &BIT (ch)) || f->val[ch] != v[ch]) +if (!test_bit (ch, elem->cached) || elem->cache_val[ch] != v[ch]) changed =1 ; - ret =snd_audient_id14_fu12_write (f, ch, v[ch]); + ret =snd_audient_id14_fu12_write (elem, ch, v[ch]);if (ret <0 )return ret; }
@@ -1171,19 +1171,21 @@ static int snd_audient_id14_mk1_create(struct usb_mixer_interface *mixer) .put = snd_ctl_audient_id14_fu12_set, .tlv.p = snd_audient_tlv_id14_fu12, }; -struct snd_audient_id14_fu12 *f; +struct usb_mixer_elem_info *elem;struct snd_kcontrol *kctl;unsigned int ch; - f =kzalloc_obj (*f); -if (!f) + elem =kzalloc_obj (*elem); +if (!elem)return -ENOMEM ; - f->list.mixer = mixer; - f->list.id =ID14_FU_MIX ; + elem->head.mixer = mixer; + elem->head.id =ID14_FU_MIX ; + elem->channels =ID14_FU12_CHANNELS ; + elem->get_cur_broken =1 ;for (ch =0 ; ch <ID14_FU12_CHANNELS ; ch++) { -const int ret =snd_audient_id14_fu12_write (f, ch, +const int ret =snd_audient_id14_fu12_write (elem, ch, ch <ID14_FU12_MAIN_CHANNELS ?ID14_FU12_MAX :ID14_FU12_MUTE );
@@ -1193,15 +1195,15 @@ static int snd_audient_id14_mk1_create(struct usb_mixer_interface *mixer) ch + 1, ret); } - kctl =snd_ctl_new1 (&knew, f); + kctl =snd_ctl_new1 (&knew, elem);if (!kctl) { -kfree (f); +kfree (elem);return -ENOMEM ; } kctl->private_free = snd_usb_mixer_elem_free; -return snd_usb_mixer_add_list (&f->list, kctl, false, true); +return snd_usb_mixer_add_list (&elem->head, kctl, false, true); }/* called from mixer_quirks.c */
Signature · 1 line
2.47.3
RFC PATCH v4 3/19 ALSA: mixer_audient: clarify USB control message definition
In reply to Will PorterPreviously, base values for wIndex and wValue were directly given in the control type. Construct them from a unit ID and selector for clarity.
--- sound/usb/mixer_audient.c | 76 +++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 35 deletions(-)
sound/usb/mixer_audient.c +41 -35
@@ -45,15 +45,15 @@ static const struct snd_audient_ctrl_type {int integer; } max;const unsigned int *tlv; -u16 wValue; -u16 wIndex; +u8 unit; +u8 sel; } snd_audient_ctypes[SND_AUDIENT_TYPE_NCTYPES] = { [SND_AUDIENT_TYPE_MONITOR] = { .type = SNDRV_CTL_ELEM_TYPE_INTEGER, .min.integer = 0, .max.integer = 127, - .wValue = 0x0000, - .wIndex = 0x3800, + .unit = 0x38, + .sel = 0x00, /* no TLV here because we can't describe the cross-fader */ }, [SND_AUDIENT_TYPE_PHANTOM] = {
@@ -61,31 +61,31 @@ static const struct snd_audient_ctrl_type { .invert = false, .min.integer = 0, .max.integer = 1, - .wValue = 0x0000, - .wIndex = 0x3A00, + .unit = 0x3A, + .sel = 0x00, }, [SND_AUDIENT_TYPE_MUTE] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, .invert = true, .min.integer = 0, .max.integer = 1, - .wValue = 0x0200, - .wIndex = 0x3A00, + .unit = 0x3A, + .sel = 0x02, }, [SND_AUDIENT_TYPE_MUTE_OUT] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, .invert = true, .min.integer = 0, .max.integer = 1, - .wValue = 0x0100, - .wIndex = 0x3B00, + .unit = 0x3B, + .sel = 0x01, }, [SND_AUDIENT_TYPE_MIXER] = { .type = SNDRV_CTL_ELEM_TYPE_INTEGER, .min.integer = -128 * 256, .max.integer = 6 * 256, - .wValue = 0x0100, - .wIndex = 0x3C00, + .unit = 0x3C, + .sel = 0x01, .tlv = snd_audient_tlv_mixer, }, };
@@ -209,7 +209,7 @@ const struct snd_audient_ctrl_type *snd_audient_kctl_type(struct snd_kcontrolreturn &snd_audient_ctypes[kctl->private_value &0xFF ]; } -static __always_inline u16 snd_audient_kctl_valoffs(struct snd_kcontrol *kctl) +static __always_inline u16 snd_audient_kctl_cidxoffs(struct snd_kcontrol *kctl) {return (kctl->private_value >>8 ) &0xFF ; }
@@ -233,11 +233,16 @@ static inline u16 snd_audient_kctl_channels(struct snd_kcontrol *kctl)#define AUDIENT_REQTYPE_GET (USB_DIR_IN | USB_TYPE_CLASS \ | USB_RECIP_INTERFACE) +#define U8_U8 (HI ,LO ) ((((u16)(HI)) << 8) | ((LO) & 0xFF)) +static inline int snd_audient_get_cur (struct usb_mixer_interface *mixer, -u16 value,u16 index, -void *buf,size_t len) +const u8 unit,const u8 sel, +const u8 cidx, +void *const buf,const size_t len) {struct usb_device *const dev = mixer->chip->dev; +const u16 value =U8_U8 (sel, cidx); +const u16 index =U8_U8 (unit, mixer->hostif->desc.bInterfaceNumber); return snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_CUR, AUDIENT_REQTYPE_GET,
@@ -245,10 +250,13 @@ static inline int snd_audient_get_cur(struct usb_mixer_interface *mixer, }static inline int snd_audient_set_cur (struct usb_mixer_interface *mixer, -u16 value,u16 index, -void *buf,size_t len) +const u8 unit,const u8 sel, +const u8 cidx, +void *const buf,const size_t len) {struct usb_device *const dev = mixer->chip->dev; +const u16 value =U8_U8 (sel, cidx); +const u16 index =U8_U8 (unit, mixer->hostif->desc.bInterfaceNumber); return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC2_CS_CUR, AUDIENT_REQTYPE_SET,
@@ -266,8 +274,7 @@ static int snd_ctl_audient_boolean_get(struct snd_kcontrol *kctl,const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl);const struct snd_audient_ctrl_type *const ctype =snd_audient_kctl_type (kctl); -const u16 value = ctype->wValue +snd_audient_kctl_valoffs (kctl); -const u16 index = ctype->wIndex; +const u8 base =snd_audient_kctl_cidxoffs (kctl);int i;
@@ -279,8 +286,8 @@ static int snd_ctl_audient_boolean_get(struct snd_kcontrol *kctl,u32 buf;int ret; - ret =snd_audient_get_cur (mixer, value + i, index, - &buf,sizeof (buf)); + ret =snd_audient_get_cur (mixer, ctype->unit, ctype->sel, + base + i, &buf,sizeof (buf));if (ret <0 )return ret;
@@ -307,8 +314,7 @@ static int snd_ctl_audient_boolean_set(struct snd_kcontrol *kctl,const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl);const struct snd_audient_ctrl_type *const ctype =snd_audient_kctl_type (kctl); -const u16 value = ctype->wValue +snd_audient_kctl_valoffs (kctl); -const u16 index = ctype->wIndex; +const u8 base =snd_audient_kctl_cidxoffs (kctl);int changed =0 ;int i;
@@ -325,15 +331,16 @@ static int snd_ctl_audient_boolean_set(struct snd_kcontrol *kctl,if (ctype->invert) buf ^=cpu_to_le32 (0x1 ); - ret =snd_audient_get_cur (mixer, value + i, index, - &rbuf,sizeof (rbuf)); + ret =snd_audient_get_cur (mixer, ctype->unit, ctype->sel, + base + i, &rbuf,sizeof (rbuf));if (ret <0 )return ret;if (rbuf != buf) { changed =1 ; - ret =snd_audient_set_cur (mixer, value + i, index, + ret =snd_audient_set_cur (mixer, ctype->unit, + ctype->sel, base + i, &buf,sizeof (buf));if (ret <0 )return ret;
@@ -353,8 +360,7 @@ static int snd_ctl_audient_integer_get(struct snd_kcontrol *kctl,const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl);const struct snd_audient_ctrl_type *const ctype =snd_audient_kctl_type (kctl); -const u16 value = ctype->wValue +snd_audient_kctl_valoffs (kctl); -const u16 index = ctype->wIndex; +const u8 base =snd_audient_kctl_cidxoffs (kctl);int i;
@@ -367,8 +373,8 @@ static int snd_ctl_audient_integer_get(struct snd_kcontrol *kctl,s16 val;int ret; - ret =snd_audient_get_cur (mixer, value + i, index, - &buf,sizeof (buf)); + ret =snd_audient_get_cur (mixer, ctype->unit, ctype->sel, + base + i, &buf,sizeof (buf));if (ret <0 )return ret;
@@ -391,8 +397,7 @@ static int snd_ctl_audient_integer_set(struct snd_kcontrol *kctl,const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl);const struct snd_audient_ctrl_type *const ctype =snd_audient_kctl_type (kctl); -const u16 value = ctype->wValue +snd_audient_kctl_valoffs (kctl); -const u16 index = ctype->wIndex; +const u8 base =snd_audient_kctl_cidxoffs (kctl);int changed =0 ;int i;
@@ -406,15 +411,16 @@ static int snd_ctl_audient_integer_set(struct snd_kcontrol *kctl,s16 buf =cpu_to_le16 (ctl_val->value.integer.value[i]);int ret; - ret =snd_audient_get_cur (mixer, value + i, index, - &rbuf,sizeof (rbuf)); + ret =snd_audient_get_cur (mixer, ctype->unit, ctype->sel, + base + i, &rbuf,sizeof (rbuf));if (ret <0 )return ret;if (rbuf != buf) { changed =1 ; - ret =snd_audient_set_cur (mixer, value + i, index, + ret =snd_audient_set_cur (mixer, ctype->unit, + ctype->sel, base + i, &buf,sizeof (buf));if (ret <0 )return ret;
Signature · 1 line
2.56.1
RFC PATCH v4 4/19 ALSA: mixer_audient: Add length check to USB transfer
In reply to Will PorterCheck USB control transfers not only for errors but also for expected length and return -EIO in case of error.
--- sound/usb/mixer_audient.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
sound/usb/mixer_audient.c +16 -6
@@ -244,9 +244,14 @@ static inline int snd_audient_get_cur(struct usb_mixer_interface *mixer,const u16 value =U8_U8 (sel, cidx);const u16 index =U8_U8 (unit, mixer->hostif->desc.bInterfaceNumber); -return snd_usb_ctl_msg (dev,usb_rcvctrlpipe (dev,0 ), -UAC2_CS_CUR ,AUDIENT_REQTYPE_GET , - value, index, buf, len); +const int ret =snd_usb_ctl_msg (dev,usb_rcvctrlpipe (dev,0 ), +UAC2_CS_CUR ,AUDIENT_REQTYPE_GET , + value, index, buf, len); + +if ((ret >=0 ) && (ret != len)) +return -EIO ; + +return ret; } static inline int snd_audient_set_cur(struct usb_mixer_interface *mixer,
@@ -258,9 +263,14 @@ static inline int snd_audient_set_cur(struct usb_mixer_interface *mixer,const u16 value =U8_U8 (sel, cidx);const u16 index =U8_U8 (unit, mixer->hostif->desc.bInterfaceNumber); -return snd_usb_ctl_msg (dev,usb_sndctrlpipe (dev,0 ), -UAC2_CS_CUR ,AUDIENT_REQTYPE_SET , - value, index, buf, len); +const int ret =snd_usb_ctl_msg (dev,usb_sndctrlpipe (dev,0 ), +UAC2_CS_CUR ,AUDIENT_REQTYPE_SET , + value, index, buf, len); + +if ((ret >=0 ) && (ret != len)) +return -EIO ; + +return ret; }
Signature · 1 line
2.56.1
RFC PATCH v4 5/19 ALSA: mixer_audient: make USB control transfer size configurable
In reply to Will PorterPreviously, the USB transfer size was hardcoded in the datatype get/set functions. Make it configurable in the ctype structure in preparation of new control types for the id14.
--- sound/usb/mixer_audient.c | 131 ++++++++++++++++++++++++-------------- 1 file changed, 84 insertions(+), 47 deletions(-)
sound/usb/mixer_audient.c +84 -47
@@ -12,6 +12,8 @@#include <linux/usb.h> #include <linux/usb/audio-v2.h> #include <linux/slab.h> +#include <linux/types.h> +#include <linux/bitops.h> #include <sound/core.h> #include <sound/control.h> #include <sound/tlv.h>
@@ -35,8 +37,12 @@ enum snd_audient_type {/* Mixer matrix: -128dB (mute) to +6dB */ static const DECLARE_TLV_DB_MINMAX_MUTE(snd_audient_tlv_mixer, -12800, 600); +#define SND_AUDIENT_CTYPE_FLAGS_SIGNED BIT(0) + static const struct snd_audient_ctrl_type { snd_ctl_elem_type_t type; + unsigned long flags; + size_t len; /* datatype size, can be 1, 2 or 4 bytes */ bool invert; union { int integer;
@@ -50,6 +56,7 @@ static const struct snd_audient_ctrl_type { } snd_audient_ctypes[SND_AUDIENT_TYPE_NCTYPES] = { [SND_AUDIENT_TYPE_MONITOR] = { .type = SNDRV_CTL_ELEM_TYPE_INTEGER, + .len = 2, .min.integer = 0, .max.integer = 127, .unit = 0x38,
@@ -59,6 +66,7 @@ static const struct snd_audient_ctrl_type { [SND_AUDIENT_TYPE_PHANTOM] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, .invert = false, + .len = 4, .min.integer = 0, .max.integer = 1, .unit = 0x3A,
@@ -67,6 +75,7 @@ static const struct snd_audient_ctrl_type { [SND_AUDIENT_TYPE_MUTE] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, .invert = true, + .len = 4, .min.integer = 0, .max.integer = 1, .unit = 0x3A,
@@ -75,6 +84,7 @@ static const struct snd_audient_ctrl_type { [SND_AUDIENT_TYPE_MUTE_OUT] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, .invert = true, + .len = 4, .min.integer = 0, .max.integer = 1, .unit = 0x3B,
@@ -82,6 +92,8 @@ static const struct snd_audient_ctrl_type { }, [SND_AUDIENT_TYPE_MIXER] = { .type = SNDRV_CTL_ELEM_TYPE_INTEGER, + .flags = SND_AUDIENT_CTYPE_FLAGS_SIGNED, + .len = 2, .min.integer = -128 * 256, .max.integer = 6 * 256, .unit = 0x3C,
@@ -236,44 +248,91 @@ static inline u16 snd_audient_kctl_channels(struct snd_kcontrol *kctl)#define U8_U8 (HI ,LO ) ((((u16)(HI)) << 8) | ((LO) & 0xFF))static inline int snd_audient_get_cur (struct usb_mixer_interface *mixer, -const u8 unit,const u8 sel, -const u8 cidx, -void *const buf,const size_t len) +const struct snd_audient_ctrl_type *const ctype, +const u8 cidx,void *const buf) {struct usb_device *const dev = mixer->chip->dev; -const u16 value =U8_U8 (sel, cidx); -const u16 index =U8_U8 (unit, mixer->hostif->desc.bInterfaceNumber); +const u16 value =U8_U8 (ctype->sel, cidx); +const u16 index =U8_U8 (ctype->unit, + mixer->hostif->desc.bInterfaceNumber);const int ret =snd_usb_ctl_msg (dev,usb_rcvctrlpipe (dev,0 ),UAC2_CS_CUR ,AUDIENT_REQTYPE_GET , - value, index, buf, len); + value, index, buf, ctype->len); -if ((ret >=0 ) && (ret != len)) +if ((ret >=0 ) && (ret != ctype->len))return -EIO ;return ret; }static inline int snd_audient_set_cur (struct usb_mixer_interface *mixer, -const u8 unit,const u8 sel, -const u8 cidx, -void *const buf,const size_t len) +const struct snd_audient_ctrl_type *const ctype, +const u8 cidx,void *const buf) {struct usb_device *const dev = mixer->chip->dev; -const u16 value =U8_U8 (sel, cidx); -const u16 index =U8_U8 (unit, mixer->hostif->desc.bInterfaceNumber); +const u16 value =U8_U8 (ctype->sel, cidx); +const u16 index =U8_U8 (ctype->unit, + mixer->hostif->desc.bInterfaceNumber);const int ret =snd_usb_ctl_msg (dev,usb_sndctrlpipe (dev,0 ),UAC2_CS_CUR ,AUDIENT_REQTYPE_SET , - value, index, buf, len); + value, index, buf, ctype->len); -if ((ret >=0 ) && (ret != len)) +if ((ret >=0 ) && (ret != ctype->len))return -EIO ;return ret; } +static int snd_audient_raw_get_one (struct usb_mixer_interface *const mixer, +const struct snd_audient_ctrl_type *const ctype, +const u8 cidx,u32 *const value) +{ +int ret; +__le32 buf =0 ; +s32 val; + + ret =snd_audient_get_cur (mixer, ctype, cidx, &buf); +if (ret <0 ) +return ret; + + val =le32_to_cpu (buf); + +if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_SIGNED ) + val =sign_extend32 (val,8 * ctype->len -1 ); + + *value = val; + +return ret; +} + +static int snd_audient_raw_set_one (struct usb_mixer_interface *const mixer, +const struct snd_audient_ctrl_type *const ctype, +const u8 cidx,const u32 value) +{ +int ret; +u32 val; + + ret =snd_audient_raw_get_one (mixer, ctype, cidx, &val); +if (ret <0 ) +return ret; + +if (val != value) { +__le32 buf =cpu_to_le32 (value); + + ret =snd_audient_set_cur (mixer, ctype, cidx, &buf); +if (ret <0 ) +return ret; + +return 1 ; + } + +return 0 ; +} + +static int snd_ctl_audient_boolean_get (struct snd_kcontrol *kctl,struct snd_ctl_elem_value *ctl_val) {
@@ -296,12 +355,11 @@ static int snd_ctl_audient_boolean_get(struct snd_kcontrol *kctl,u32 buf;int ret; - ret =snd_audient_get_cur (mixer, ctype->unit, ctype->sel, - base + i, &buf,sizeof (buf)); + ret =snd_audient_raw_get_one (mixer, ctype, base + i, &buf);if (ret <0 )return ret; - ctl_val->value.integer.value[i] =le32_to_cpu (buf) ?1 :0 ; + ctl_val->value.integer.value[i] = buf ?1 :0 ;if (ctype->invert) ctl_val->value.integer.value[i] ^=0x1 ;
@@ -334,27 +392,18 @@ static int snd_ctl_audient_boolean_set(struct snd_kcontrol *kctl,return pm.err;for (i =0 ; i < hwchan; i++) { -u32 rbuf; -u32 buf =cpu_to_le32 (ctl_val->value.integer.value[i] ?1 :0 ); +u32 buf = ctl_val->value.integer.value[i] ?1 :0 ;int ret;if (ctype->invert) - buf ^=cpu_to_le32 (0x1 ); + buf ^=0x1 ; - ret =snd_audient_get_cur (mixer, ctype->unit, ctype->sel, - base + i, &rbuf,sizeof (rbuf)); + ret =snd_audient_raw_set_one (mixer, ctype, base + i, buf);if (ret <0 )return ret; -if (rbuf != buf) { +if (ret) changed =1 ; - - ret =snd_audient_set_cur (mixer, ctype->unit, - ctype->sel, base + i, - &buf,sizeof (buf)); -if (ret <0 ) -return ret; - } }return changed;
@@ -379,16 +428,13 @@ static int snd_ctl_audient_integer_get(struct snd_kcontrol *kctl,return pm.err;for (i =0 ; i < hwchan; i++) { -u16 buf; -s16 val; +s32 val;int ret; - ret =snd_audient_get_cur (mixer, ctype->unit, ctype->sel, - base + i, &buf,sizeof (buf)); + ret =snd_audient_raw_get_one (mixer, ctype, base + i, &val);if (ret <0 )return ret; - val =le16_to_cpu (buf); ctl_val->value.integer.value[i] = val; }
@@ -417,24 +463,15 @@ static int snd_ctl_audient_integer_set(struct snd_kcontrol *kctl,return pm.err;for (i =0 ; i < hwchan; i++) { -s16 rbuf; -s16 buf =cpu_to_le16 (ctl_val->value.integer.value[i]); +s32 val = ctl_val->value.integer.value[i];int ret; - ret =snd_audient_get_cur (mixer, ctype->unit, ctype->sel, - base + i, &rbuf,sizeof (rbuf)); + ret =snd_audient_raw_set_one (mixer, ctype, base + i, val);if (ret <0 )return ret; -if (rbuf != buf) { +if (ret) changed =1 ; - - ret =snd_audient_set_cur (mixer, ctype->unit, - ctype->sel, base + i, - &buf,sizeof (buf)); -if (ret <0 ) -return ret; - } }return changed;
Signature · 1 line
2.56.1
RFC PATCH v4 6/19 ALSA: mixer_audient: Allow arbitrary boolean control values
In reply to Will PorterIn preparation of id14 support, allow arbitrary values for true and false of boolean switches. This also rids us of the tedious invert flag.
--- sound/usb/mixer_audient.c | 43 ++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 23 deletions(-)
sound/usb/mixer_audient.c +20 -23
@@ -43,13 +43,12 @@ static const struct snd_audient_ctrl_type {snd_ctl_elem_type_t type;unsigned long flags;size_t len;/* datatype size, can be 1, 2 or 4 bytes */ -bool invert;union {int integer; - } min; + } min;/* for booleans holds physical int value for false */ union {int integer; - } max; + } max;/* for booleans holds physical int value for true */ const unsigned int *tlv;u8 unit;u8 sel;
@@ -65,7 +64,6 @@ static const struct snd_audient_ctrl_type { }, [SND_AUDIENT_TYPE_PHANTOM] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, - .invert = false, .len = 4, .min.integer = 0, .max.integer = 1,
@@ -74,19 +72,17 @@ static const struct snd_audient_ctrl_type { }, [SND_AUDIENT_TYPE_MUTE] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, - .invert = true, .len = 4, - .min.integer = 0, - .max.integer = 1, + .min.integer = 1, + .max.integer = 0, .unit = 0x3A, .sel = 0x02, }, [SND_AUDIENT_TYPE_MUTE_OUT] = { .type = SNDRV_CTL_ELEM_TYPE_BOOLEAN, - .invert = true, .len = 4, - .min.integer = 0, - .max.integer = 1, + .min.integer = 1, + .max.integer = 0, .unit = 0x3B, .sel = 0x01, },
@@ -359,16 +355,12 @@ static int snd_ctl_audient_boolean_get(struct snd_kcontrol *kctl,if (ret <0 )return ret; - ctl_val->value.integer.value[i] = buf ?1 :0 ; - -if (ctype->invert) - ctl_val->value.integer.value[i] ^=0x1 ; + ctl_val->value.integer.value[i] = (buf == ctype->min.integer) + ? false : true; }for (; i < nchan; i++) - ctl_val->value.integer.value[i] = ctype->invert - ? ctype->max.integer - : ctype->min.integer; + ctl_val->value.integer.value[i] =0 ;return 0 ; }
@@ -392,12 +384,10 @@ static int snd_ctl_audient_boolean_set(struct snd_kcontrol *kctl,return pm.err;for (i =0 ; i < hwchan; i++) { -u32 buf = ctl_val->value.integer.value[i] ?1 :0 ; +u32 buf = ctl_val->value.integer.value[i] ? ctype->max.integer + : ctype->min.integer;int ret; -if (ctype->invert) - buf ^=0x1 ; - ret =snd_audient_raw_set_one (mixer, ctype, base + i, buf);if (ret <0 )return ret;
@@ -485,8 +475,15 @@ static int snd_ctl_audient_info(struct snd_kcontrol *kctl, uinfo->type = ctype->type; uinfo->count =snd_audient_kctl_channels (kctl); - uinfo->value.integer.min = ctype->min.integer; - uinfo->value.integer.max = ctype->max.integer; + +if (ctype->type ==SNDRV_CTL_ELEM_TYPE_BOOLEAN ) { + uinfo->value.integer.min =0 ; + uinfo->value.integer.max =1 ; + }else { + uinfo->value.integer.min = ctype->min.integer; + uinfo->value.integer.max = ctype->max.integer; + } +return 0 ; }
Signature · 1 line
2.56.1
RFC PATCH v4 7/19 ALSA: mixer_audient: Add integer range checks
In reply to Will PorterAdd range checks to integer parameters to improve error management:
- Reject out-of-range write attempts with -EINVAL
- Prune out-of-range values returned by the device to the range limits
--- sound/usb/mixer_audient.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
sound/usb/mixer_audient.c +15 -2
@@ -44,10 +44,10 @@ static const struct snd_audient_ctrl_type {unsigned long flags;size_t len;/* datatype size, can be 1, 2 or 4 bytes */ union { -int integer; +long integer; } min;/* for booleans holds physical int value for false */ union { -int integer; +long integer; } max;/* for booleans holds physical int value for true */ const unsigned int *tlv;u8 unit;
@@ -425,6 +425,12 @@ static int snd_ctl_audient_integer_get(struct snd_kcontrol *kctl,if (ret <0 )return ret; +if (val < ctype->min.integer) + val = ctype->min.integer; + +if (val > ctype->max.integer) + val = ctype->max.integer; + ctl_val->value.integer.value[i] = val; }
@@ -448,6 +454,13 @@ static int snd_ctl_audient_integer_set(struct snd_kcontrol *kctl,int changed =0 ;int i; +for (i =0 ; i < hwchan; i++) { +long val = ctl_val->value.integer.value[i]; + +if ((val < ctype->min.integer) || (val > ctype->max.integer)) +return -EINVAL ; + } +CLASS (snd_usb_lock, pm)(mixer->chip);if (pm.err <0 )return pm.err;
Signature · 1 line
2.56.1
RFC PATCH v4 8/19 ALSA: mixer_audient: Add control initialization at probe
In reply to Will PorterAdd the possibility to initialize certain control types to known values at probe time. This is particularly useful for controls which initially read wrong values and for controls which cannot be read at all.
--- sound/usb/mixer_audient.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
sound/usb/mixer_audient.c +16 -0
@@ -38,6 +38,7 @@ enum snd_audient_type { static const DECLARE_TLV_DB_MINMAX_MUTE(snd_audient_tlv_mixer, -12800, 600);#define SND_AUDIENT_CTYPE_FLAGS_SIGNED BIT(0) +#define SND_AUDIENT_CTYPE_FLAGS_INIT_HW BIT(1) static const struct snd_audient_ctrl_type { snd_ctl_elem_type_t type;
@@ -49,6 +50,7 @@ static const struct snd_audient_ctrl_type {union {long integer; } max;/* for booleans holds physical int value for true */ +u32 init;const unsigned int *tlv;u8 unit;u8 sel;
@@ -533,6 +535,20 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer,return -EINVAL ; } +if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_INIT_HW ) { +int i; + +for (i =0 ; i < ctrl->hwchannels; i++) { +int ret =snd_audient_raw_set_one (mixer, ctype, + ctrl->val_offs + i, + ctype->init); +if (ret <0 ) +usb_audio_warn (mixer->chip, +"%s: cannot set channel %d (%d)\n" , + ctrl->name, i, ret); + } + } + elem =kzalloc_obj (*elem);if (!elem)return -ENOMEM ;
Signature · 1 line
2.56.1
RFC PATCH v4 2/19 ALSA: mixer_audient: explicitly define full control names
In reply to Will PorterPreviously, control names were dynamically created depending if the control was an input or an output, a volume or a switch. Get rid of this logic by simply defining the full name in the control structure.
--- sound/usb/mixer_audient.c | 50 +++++++++++---------------------------- 1 file changed, 14 insertions(+), 36 deletions(-)
sound/usb/mixer_audient.c +14 -36
@@ -90,107 +90,92 @@ static const struct snd_audient_ctrl_type { }, }; -#define SND_AUDIENT_FLAGS_DIRECTION (1L<<0) -#define SND_AUDIENT_FLAGS_CAPTURE (1L<<0) -#define SND_AUDIENT_FLAGS_PLAYBACK (0L<<0)struct snd_audient_ctrl { -char *basename; +char *name;enum snd_audient_type type;unsigned int channels;unsigned int hwchannels;unsigned int val_offs; -unsigned long flags; };static const struct snd_audient_ctrl snd_audient_evo4_controls[] = { { - .basename ="Master" , + .name ="Master Playback Switch" , .type =SND_AUDIENT_TYPE_MUTE_OUT , .channels =1 , .hwchannels =1 , .val_offs =0 , - .flags =SND_AUDIENT_FLAGS_PLAYBACK , }, { - .basename ="Mic" , + .name ="Mic Playback Switch" , .type =SND_AUDIENT_TYPE_MUTE , .channels =4 , .hwchannels =2 , .val_offs =0 , - .flags =SND_AUDIENT_FLAGS_PLAYBACK , }, { - .basename ="Monitor" , + .name ="Monitor Playback Volume" , .type =SND_AUDIENT_TYPE_MONITOR , .channels =1 , .hwchannels =1 , .val_offs =0 , - .flags =SND_AUDIENT_FLAGS_PLAYBACK , }, { - .basename ="Mic 1" , + .name ="Mic 1 Capture Volume" , .type =SND_AUDIENT_TYPE_MIXER , .channels =2 , .hwchannels =2 , .val_offs =0 , - .flags =SND_AUDIENT_FLAGS_CAPTURE , }, { - .basename ="Mic 2" , + .name ="Mic 2 Capture Volume" , .type =SND_AUDIENT_TYPE_MIXER , .channels =2 , .hwchannels =2 , .val_offs =2 , - .flags =SND_AUDIENT_FLAGS_CAPTURE , }, { - .basename ="Master Left" , + .name ="Master Left Capture Volume" , .type =SND_AUDIENT_TYPE_MIXER , .channels =2 , .hwchannels =2 , .val_offs =4 , - .flags =SND_AUDIENT_FLAGS_CAPTURE , }, { - .basename ="Master Right" , + .name ="Master Right Capture Volume" , .type =SND_AUDIENT_TYPE_MIXER , .channels =2 , .hwchannels =2 , .val_offs =6 , - .flags =SND_AUDIENT_FLAGS_CAPTURE , }, { - .basename ="Loopback Left" , + .name ="Loopback Left Capture Volume" , .type =SND_AUDIENT_TYPE_MIXER , .channels =2 , .hwchannels =2 , .val_offs =8 , - .flags =SND_AUDIENT_FLAGS_CAPTURE , }, { - .basename ="Loopback Right" , + .name ="Loopback Right Capture Volume" , .type =SND_AUDIENT_TYPE_MIXER , .channels =2 , .hwchannels =2 , .val_offs =10 , - .flags =SND_AUDIENT_FLAGS_CAPTURE , }, { - .basename ="Mic 1 Phantom" , + .name ="Mic 1 Phantom Capture Switch" , .type =SND_AUDIENT_TYPE_PHANTOM , .channels =1 , .hwchannels =1 , .val_offs =0 , - .flags =SND_AUDIENT_FLAGS_CAPTURE , }, { - .basename ="Mic 2 Phantom" , + .name ="Mic 2 Phantom Capture Switch" , .type =SND_AUDIENT_TYPE_PHANTOM , .channels =1 , .hwchannels =1 , .val_offs =1 , - .flags =SND_AUDIENT_FLAGS_CAPTURE , }, {0 },/* sentinel */ };
@@ -458,13 +443,12 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer, {const struct snd_audient_ctrl_type *ctype = &snd_audient_ctypes[ctrl->type]; -char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN ];struct snd_kcontrol_new knew = {0 };struct snd_kcontrol *kctl;struct usb_mixer_elem_info *elem; knew.iface =SNDRV_CTL_ELEM_IFACE_MIXER ; - knew.name = name; + knew.name = ctrl->name; knew.info = snd_ctl_audient_info; knew.private_value =snd_audient_kctl_priv (ctrl->type, ctrl->val_offs, ctrl->hwchannels);
@@ -486,12 +470,6 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer,return -EINVAL ; } -snprintf (name,sizeof (name),"%s %s %s" , ctrl->basename, - ((ctrl->flags &SND_AUDIENT_FLAGS_DIRECTION ) - ==SND_AUDIENT_FLAGS_CAPTURE ) ?"Capture" :"Playback" , - (ctype->type ==SNDRV_CTL_ELEM_TYPE_BOOLEAN ) - ?"Switch" :"Volume" ); - elem =kzalloc_obj (*elem);if (!elem)return -ENOMEM ;
@@ -524,7 +502,7 @@ int snd_audient_controls_create(struct usb_mixer_interface *mixer)if (!info->controls)return -ENODEV ; -for (ctrl = info->controls; ctrl->basename; ctrl++) { +for (ctrl = info->controls; ctrl->name; ctrl++) {const int ret =snd_audient_add_ctrl (mixer, ctrl);if (ret <0 )
Signature · 1 line
2.56.1
RFC PATCH v4 9/19 ALSA: mixer_audient: Add readback-free parameter set
In reply to Will PorterAdd a flag to systematically force parameter writing without prior readback to certain control types. In preparation of the id14 driver.
--- sound/usb/mixer_audient.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
sound/usb/mixer_audient.c +8 -3
@@ -39,6 +39,7 @@ static const DECLARE_TLV_DB_MINMAX_MUTE(snd_audient_tlv_mixer, -12800, 600);#define SND_AUDIENT_CTYPE_FLAGS_SIGNED BIT(0)#define SND_AUDIENT_CTYPE_FLAGS_INIT_HW BIT(1) +#define SND_AUDIENT_CTYPE_FLAGS_GET_BROKEN BIT(2) static const struct snd_audient_ctrl_type { snd_ctl_elem_type_t type;
@@ -313,9 +314,13 @@ static int snd_audient_raw_set_one(struct usb_mixer_interface *const mixer,int ret;u32 val; - ret =snd_audient_raw_get_one (mixer, ctype, cidx, &val); -if (ret <0 ) -return ret; +if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_GET_BROKEN ) { + val = !value;/* just make it different */ + }else { + ret =snd_audient_raw_get_one (mixer, ctype, cidx, &val); +if (ret <0 ) +return ret; + }if (val != value) {__le32 buf =cpu_to_le32 (value);
Signature · 1 line
2.56.1
RFC PATCH v4 10/19 ALSA: mixer_audient: add control value caching
In reply to Will PorterIn preparation of id14 support, add control value caching.
--- sound/usb/mixer_audient.c | 144 +++++++++++++++++++++++++++----------- 1 file changed, 105 insertions(+), 39 deletions(-)
sound/usb/mixer_audient.c +105 -39
@@ -40,6 +40,7 @@ static const DECLARE_TLV_DB_MINMAX_MUTE(snd_audient_tlv_mixer, -12800, 600);#define SND_AUDIENT_CTYPE_FLAGS_SIGNED BIT(0)#define SND_AUDIENT_CTYPE_FLAGS_INIT_HW BIT(1)#define SND_AUDIENT_CTYPE_FLAGS_GET_BROKEN BIT(2) +#define SND_AUDIENT_CTYPE_FLAGS_CACHE BIT(3) static const struct snd_audient_ctrl_type { snd_ctl_elem_type_t type;
@@ -51,7 +52,7 @@ static const struct snd_audient_ctrl_type {union {long integer; } max;/* for booleans holds physical int value for true */ -u32 init; +u32 init;/* hardware and cache are initialized to this value */ const unsigned int *tlv;u8 unit;u8 sel;
@@ -91,7 +92,8 @@ static const struct snd_audient_ctrl_type { }, [SND_AUDIENT_TYPE_MIXER] = { .type = SNDRV_CTL_ELEM_TYPE_INTEGER, - .flags = SND_AUDIENT_CTYPE_FLAGS_SIGNED, + .flags =SND_AUDIENT_CTYPE_FLAGS_SIGNED + | SND_AUDIENT_CTYPE_FLAGS_CACHE, .len = 2, .min.integer = -128 * 256, .max.integer = 6 * 256,
@@ -285,14 +287,33 @@ static inline int snd_audient_set_cur(struct usb_mixer_interface *mixer, } -static int snd_audient_raw_get_one (struct usb_mixer_interface *const mixer, +static int snd_audient_raw_get_one (struct usb_mixer_elem_info *const elem,const struct snd_audient_ctrl_type *const ctype, -const u8 cidx,u32 *const value) +const unsigned int cidx,u32 *const value) { +struct usb_mixer_interface *const mixer = elem->head.mixer;int ret;__le32 buf =0 ;s32 val; +if (cidx >MAX_CHANNELS ) +return -EINVAL ; + +if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_CACHE ) { +if (test_bit (cidx, elem->cached)) { + *value = elem->cache_val[cidx]; + +return ctype->len; + }else if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_GET_BROKEN ) { +/* +* Cached FORCE_SET controls are treated as write-only: +* an invalid cache entry does not trigger a GET. +*/ +return -ENODATA ; + } + } + + ret =snd_audient_get_cur (mixer, ctype, cidx, &buf);if (ret <0 )return ret;
@@ -304,43 +325,55 @@ static int snd_audient_raw_get_one(struct usb_mixer_interface *const mixer, *value = val; +set_bit (cidx, elem->cached); + elem->cache_val[cidx] = val; +return ret; } -static int snd_audient_raw_set_one (struct usb_mixer_interface *const mixer, +static int snd_audient_raw_set_one (struct usb_mixer_elem_info *const elem,const struct snd_audient_ctrl_type *const ctype, -const u8 cidx,const u32 value) +const unsigned int cidx,const u32 value,bool force) { +struct usb_mixer_interface *const mixer = elem->head.mixer;int ret;u32 val; -if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_GET_BROKEN ) { +if (cidx >MAX_CHANNELS ) +return -EINVAL ; + +if (force) { val = !value;/* just make it different */ }else { - ret =snd_audient_raw_get_one (mixer, ctype, cidx, &val); -if (ret <0 ) + ret =snd_audient_raw_get_one (elem, ctype, cidx, &val); +if (ret == -ENODATA )/* FORCE_SET and not cached yet */ + val = !value;/* just make it different */ +else if (ret <0 )return ret; } -if (val != value) { + force = force || (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_GET_BROKEN ); + +if (force || (val != value)) {__le32 buf =cpu_to_le32 (value); ret =snd_audient_set_cur (mixer, ctype, cidx, &buf);if (ret <0 )return ret; -return 1 ; +set_bit (cidx, elem->cached); + elem->cache_val[cidx] = value; } -return 0 ; +return val != value; }static int snd_ctl_audient_boolean_get (struct snd_kcontrol *kctl,struct snd_ctl_elem_value *ctl_val) { -struct usb_mixer_elem_list *const list =snd_kcontrol_chip (kctl); -struct usb_mixer_interface *const mixer = list->mixer; +struct usb_mixer_elem_info *const elem =snd_kcontrol_chip (kctl); +struct usb_mixer_interface *const mixer = elem->head.mixer;const unsigned int nchan =snd_audient_kctl_channels (kctl);const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl);
@@ -353,13 +386,17 @@ static int snd_ctl_audient_boolean_get(struct snd_kcontrol *kctl,CLASS (snd_usb_lock, pm)(mixer->chip);if (pm.err <0 )return pm.err; +/* serializes the transfers and the cache, also between gets */ +guard (mutex)(&mixer->lock);for (i =0 ; i < hwchan; i++) {u32 buf;int ret; - ret =snd_audient_raw_get_one (mixer, ctype, base + i, &buf); -if (ret <0 ) + ret =snd_audient_raw_get_one (elem, ctype, base + i, &buf); +if (ret == -ENODATA )/* unknown write-only value: off */ + buf = ctype->min.integer; +else if (ret <0 )return ret; ctl_val->value.integer.value[i] = (buf == ctype->min.integer)
@@ -375,8 +412,8 @@ static int snd_ctl_audient_boolean_get(struct snd_kcontrol *kctl,static int snd_ctl_audient_boolean_set (struct snd_kcontrol *kctl,struct snd_ctl_elem_value *ctl_val) { -struct usb_mixer_elem_list *list =snd_kcontrol_chip (kctl); -struct usb_mixer_interface *mixer = list->mixer; +struct usb_mixer_elem_info *const elem =snd_kcontrol_chip (kctl); +struct usb_mixer_interface *const mixer = elem->head.mixer;const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl);const struct snd_audient_ctrl_type *const ctype
@@ -389,13 +426,16 @@ static int snd_ctl_audient_boolean_set(struct snd_kcontrol *kctl,CLASS (snd_usb_lock, pm)(mixer->chip);if (pm.err <0 )return pm.err; +/* serializes the transfers and the cache, also between gets */ +guard (mutex)(&mixer->lock);for (i =0 ; i < hwchan; i++) {u32 buf = ctl_val->value.integer.value[i] ? ctype->max.integer : ctype->min.integer;int ret; - ret =snd_audient_raw_set_one (mixer, ctype, base + i, buf); + ret =snd_audient_raw_set_one (elem, ctype, base + i, buf, + false);if (ret <0 )return ret;
@@ -409,8 +449,8 @@ static int snd_ctl_audient_boolean_set(struct snd_kcontrol *kctl,static int snd_ctl_audient_integer_get (struct snd_kcontrol *kctl,struct snd_ctl_elem_value *ctl_val) { -struct usb_mixer_elem_list *const list =snd_kcontrol_chip (kctl); -struct usb_mixer_interface *const mixer = list->mixer; +struct usb_mixer_elem_info *const elem =snd_kcontrol_chip (kctl); +struct usb_mixer_interface *const mixer = elem->head.mixer;const unsigned int nchan =snd_audient_kctl_channels (kctl);const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl);
@@ -423,13 +463,17 @@ static int snd_ctl_audient_integer_get(struct snd_kcontrol *kctl,CLASS (snd_usb_lock, pm)(mixer->chip);if (pm.err <0 )return pm.err; +/* serializes the transfers and the cache, also between gets */ +guard (mutex)(&mixer->lock);for (i =0 ; i < hwchan; i++) {s32 val;int ret; - ret =snd_audient_raw_get_one (mixer, ctype, base + i, &val); -if (ret <0 ) + ret =snd_audient_raw_get_one (elem, ctype, base + i, &val); +if (ret == -ENODATA )/* unknown write-only value: minimum */ + val = ctype->min.integer; +else if (ret <0 )return ret;if (val < ctype->min.integer)
@@ -450,8 +494,8 @@ static int snd_ctl_audient_integer_get(struct snd_kcontrol *kctl,static int snd_ctl_audient_integer_set (struct snd_kcontrol *kctl,struct snd_ctl_elem_value *ctl_val) { -struct usb_mixer_elem_list *list =snd_kcontrol_chip (kctl); -struct usb_mixer_interface *mixer = list->mixer; +struct usb_mixer_elem_info *const elem =snd_kcontrol_chip (kctl); +struct usb_mixer_interface *mixer = elem->head.mixer;const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl);const struct snd_audient_ctrl_type *const ctype
@@ -471,12 +515,15 @@ static int snd_ctl_audient_integer_set(struct snd_kcontrol *kctl,CLASS (snd_usb_lock, pm)(mixer->chip);if (pm.err <0 )return pm.err; +/* serializes the transfers and the cache, also between gets */ +guard (mutex)(&mixer->lock);for (i =0 ; i < hwchan; i++) {s32 val = ctl_val->value.integer.value[i];int ret; - ret =snd_audient_raw_set_one (mixer, ctype, base + i, val); + ret =snd_audient_raw_set_one (elem, ctype, base + i, val, + false);if (ret <0 )return ret;
@@ -517,6 +564,8 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer,struct snd_kcontrol *kctl;struct usb_mixer_elem_info *elem; +int ret; + knew.iface =SNDRV_CTL_ELEM_IFACE_MIXER ; knew.name = ctrl->name; knew.info = snd_ctl_audient_info;
@@ -524,7 +573,9 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer, ctrl->hwchannels); knew.tlv.p = ctype->tlv; knew.access =SNDRV_CTL_ELEM_ACCESS_READWRITE - |SNDRV_CTL_ELEM_ACCESS_VOLATILE + | ((ctype->flags &SND_AUDIENT_CTYPE_FLAGS_CACHE ) + ?0 + :SNDRV_CTL_ELEM_ACCESS_VOLATILE ) | (ctype->tlv ?SNDRV_CTL_ELEM_ACCESS_TLV_READ :0 );switch (ctype->type) {
@@ -540,13 +591,30 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer,return -EINVAL ; } + elem =kzalloc_obj (*elem); +if (!elem) +return -ENOMEM ; + + elem->head.mixer = mixer; + elem->channels = ctrl->channels; + elem->head.id = ctype->unit; + elem->control = ctype->sel; + elem->get_cur_broken = (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_CACHE ) + && (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_GET_BROKEN ); + +/* +* A failed probe transfer must not fail the card: warn and keep the +* control. +* We don't initialize the cache: This will be done implicitly when +* the control is first successfully accessed. +*/ if (ctype->flags &SND_AUDIENT_CTYPE_FLAGS_INIT_HW ) {int i;for (i =0 ; i < ctrl->hwchannels; i++) { -int ret =snd_audient_raw_set_one (mixer, ctype, - ctrl->val_offs + i, - ctype->init); + ret =snd_audient_raw_set_one (elem, ctype, + ctrl->val_offs + i, + ctype->init, true);if (ret <0 ) usb_audio_warn(mixer->chip, "%s: cannot set channel %d (%d)\n",
@@ -554,22 +622,20 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer, } } - elem =kzalloc_obj (*elem); -if (!elem) -return -ENOMEM ; - - elem->head.mixer = mixer; - elem->channels = ctrl->channels; - kctl =snd_ctl_new1 (&knew, elem);if (!kctl) { -kfree (elem); -return -ENOMEM ; + ret = -ENOMEM ; + goto free_elem; } kctl->private_free = snd_usb_mixer_elem_free;return snd_usb_mixer_add_control (&elem->head, kctl); + +free_elem: +kfree (elem); + +return ret; }
Signature · 1 line
2.56.1
[RFC V4 PATCH 00/19] Re: ALSA: mixer_audient: Cache rework and simplifications
In reply to Will PorterHi Will,
Quoted 9 lines · Will Porter
Quoted 3 lines · Christian Ruppert
I realized that
usb_mixer_elem_infoalready contains an integer array for caching we could use instead of our manually allocated cache. I suspect we should rework patch 10 accordingly.I like the idea. When I read the code for it, I saw a few more places where the driver could be simpler. It seemed easier to show them as patches than to describe them, so here they are for you to try on the EVO4. Please take what you like and drop the rest.
OK, so here's RFC V4 with the cache changes and a few other improvements inspired by your suggestions. Also contains your follow-up patch weaved into 13 and 15. See below for details.
Compiles on Alsa master and compiled and tested on 7.3.4.
Quoted 10 lines
Quoted 1 line
I'll prepare a new patch 10 but won't be able to test before the week-end.
Patches 3 to 6 need the cache change as a base, so patch 2 is my version of it, only so that the rest can be tested. Please replace it with yours. Two questions came up when I wrote it:
- The notify paths clear
info->cachedunlessget_cur_brokenis set. A write-only control could not read its value back after that. Patch 2 setsget_cur_brokenfor the write-only controls. Is that a correct use of the field?
I was wondering about the same but originally didn't plan to set it as it doesn't make much sense without the control and head.id fields. To settle the question once and for all, I decided to add all three to patch 10 after all.
Quoted 4 lines
- The interrupt path clears the bit of the channel number in the message, and channel 0 clears all bits. Patch 2 uses the channel index in the element as the bit. Would the channel number of the request fit your EVO4 events better?
I tried to stick to the hardware channel numbers as they are the ones used in mixer.c as well. Please see patch 10.
Quoted 8 lines
Quoted 1 line
Do you think it makes sense to refactor FU12 caching as well?
Yes, I think so: the driver then has one cache. Patch 6 does it.
The patches:
1. Not for merging. It has the changes from your review as one diff, so that patches 2 to 6 apply to the RFC with the enum fix.
OK, didn't touch those in the RFC, please squash them into the respective patches.
Quoted 1 line
2. Use cached and cache_val[] of
usb_mixer_elem_info.
This is almost identical to what I had prepared, except for a few parameter names and indices. Please double-check the new patch 10 to make sure I didn't miss anything, I can't fully test it on the EVO. There is also a subtle behavioural change when initializing write-only cache values. Shouldn't have an impact as it only affects integer and boolean types but let me know if something comes up in your tests.
Quoted 5 lines
3. Replace
INIT_HW,FORCE_SETand CACHE with an access mode:
read-back, cached or write-only. The tables use only these three combinations of the flags. Do you plan to use another combination on the EVO4, for exampleINIT_HWon a control that can be read? If so, I will drop this patch.
I don't like this, it violates the separation of mechanism from politics which I hold dear. Also, see the newly added patch 19 for an example why the flags are useful as they are (turns out ID12 is just such an INIT_HW control that can be read).
Quoted 3 lines
4. Fill the cache on the first get or put, not at probe. The probe then sends 12 fewer GET requests on the EVO4 and 56 fewer on the iD14. Is there a reason for the EVO4 to read at probe?
This is a good idea, now (no longer) part of patch 10.
Quoted 2 lines
5. Use one get and one put for booleans, integers and enums. This changes the code path of the EVO4 controls, which I cannot test.
This is also a good idea, I added patch 18 for this.
Quoted 1 line
6. Use the same cache for the FU 12 control.
I added patch 19 with another proposal I came up with when working on patch 18. Removes all iD14/FU12 specific functions and shortens the code by another 60ish lines. Please double-check if this makes any sense as I might have badly misunderstood something. We could even get rid of the FU12 specific value type if the iD14 accepts -127 * 256 as a volume setting (the one which is currently skipped and replaced with MUTE). In this case FU12 would become a normal integer control with a step size of 256.
We might also make some more code more generic if we replace the current hwchannels with a mask of don't-touch channels. This is not yet included in the patches because I first wanted to discuss it with you and we don't have to submit this as part of the current patch set, can be submitted as a follow-up simplification for a future kernel version.
With above two items, all FU12 specific branches should be gone.
Quoted 1 line
[...]
I suggest we now proceed as follows:
- Re-check patches 1 through 12, I don't believe they need to be changed anymore unless if we discover a bug.
- Weave patch 17 into patches 13 through 16.
- Review patch 18 (I suggest to keep it separate as it is).
- Decide what you would like to do with patch 19 and the two related comments after your point 6, either drop or modify patch 16 accordingly, possibly after rebasing it on top of patch 18.
- Submit the series for final review and testing and subsequent merging.
Do you think this would work?
Christian
Christian Ruppert (13):
ALSA: rename mixer_evo to mixer_audient
ALSA: mixer_audient: explicitly define full control names
ALSA: mixer_audient: clarify USB control message definition
ALSA: mixer_audient: Add length check to USB transfer
ALSA: mixer_audient: make USB control transfer size configurable
ALSA: mixer_audient: Allow arbitrary boolean control values
ALSA: mixer_audient: Add integer range checks
ALSA: mixer_audient: Add control initialization at probe
ALSA: mixer_audient: Add readback-free parameter set
ALSA: mixer_audient: add control value caching
ALSA: mixer_audient: Create matrix programmatically
ALSA: mixer_audient: Unify snd_audient_*_set/get functions for
different types
ALSA: mixer_audient: Refactor FU12 special cases into generic set/get
functions
Will Porter (6):
ALSA: mixer_audient: Add a step size to integer controls
ALSA: mixer_audient: Add enumerated controls
ALSA: usb-audio: Give the Audient iD14 MkI its own mixer map
ALSA: mixer_audient: Add Audient iD14 MkI controls
ALSA: mixer_audient: Replace the Audient iD14 MkI FU 12 control
ALSA: mixer_audient: Fold in the review changes to patches 12-16
MAINTAINERS | 7 +- sound/usb/Makefile | 2 +- sound/usb/mixer_audient.c | 1118 +++++++++++++++++++++++++++++++++++++ sound/usb/mixer_audient.h | 13 + sound/usb/mixer_evo.c | 526 ----------------- sound/usb/mixer_evo.h | 12 - sound/usb/mixer_maps.c | 10 +- sound/usb/mixer_quirks.c | 5 +- 8 files changed, 1148 insertions(+), 545 deletions(-) create mode 100644 sound/usb/mixer_audient.c create mode 100644 sound/usb/mixer_audient.h delete mode 100644 sound/usb/mixer_evo.c delete mode 100644 sound/usb/mixer_evo.h
Signature · 1 line
2.56.1
RFC PATCH v4 12/19 ALSA: mixer_audient: Add a step size to integer controls
In reply to Will PorterFrom: Will Porter <[email protected]>
The iD14 level controls use s16 values in 1/256 dB. Expose them in 1 dB steps, matching the volume knob's adjustment. Let a control type give a step size: the control then counts steps from the minimum, as the generic USB mixer does with the RANGE resolution. A device value between two steps reads as the nearest step, clamped to the maximum. Types without a step size keep the device value.
--- sound/usb/mixer_audient.c | 55 ++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 12 deletions(-)
sound/usb/mixer_audient.c +43 -12
@@ -53,6 +53,7 @@ static const struct snd_audient_ctrl_type {long integer; } max;/* for booleans holds physical int value for true */ u32 init;/* hardware and cache are initialized to this value */ +unsigned int res;/* integers: device units per control step, 0 = 1 */ const unsigned int *tlv;u8 unit;u8 sel;
@@ -418,6 +419,39 @@ static int snd_ctl_audient_boolean_set(struct snd_kcontrol *kctl,return changed; } +/* +* With a step size (res), an integer control counts steps from min: +* 0 ... (max - min) / res. Without one it shows the device value. +*/ +static long snd_audient_int_max (const struct snd_audient_ctrl_type *ctype) +{ +return ctype->res ? (ctype->max.integer - ctype->min.integer) / ctype->res + : ctype->max.integer; +} + +static long snd_audient_int_min (const struct snd_audient_ctrl_type *ctype) +{ +return ctype->res ?0 : ctype->min.integer; +} + +static long snd_audient_int_to_ctl (const struct snd_audient_ctrl_type *ctype, +long val) +{ + val =clamp (val, ctype->min.integer, ctype->max.integer); +if (!ctype->res) +return val; + +/* round a device value between two steps to the nearest one */ +return min (DIV_ROUND_CLOSEST (val - ctype->min.integer, (long )ctype->res), +snd_audient_int_max (ctype)); +} + +static long snd_audient_int_from_ctl (const struct snd_audient_ctrl_type *ctype, +long val) +{ +return ctype->res ? ctype->min.integer + val * ctype->res : val; +} +static int snd_ctl_audient_integer_get (struct snd_kcontrol *kctl,struct snd_ctl_elem_value *ctl_val) {
@@ -448,17 +482,12 @@ static int snd_ctl_audient_integer_get(struct snd_kcontrol *kctl,else if (ret <0 )return ret; -if (val < ctype->min.integer) - val = ctype->min.integer; - -if (val > ctype->max.integer) - val = ctype->max.integer; - - ctl_val->value.integer.value[i] = val; + ctl_val->value.integer.value[i] = +snd_audient_int_to_ctl (ctype, val); }for (; i < nchan; i++) - ctl_val->value.integer.value[i] = ctype->min.integer; + ctl_val->value.integer.value[i] =snd_audient_int_min (ctype);return 0 ; }
@@ -480,7 +509,8 @@ static int snd_ctl_audient_integer_set(struct snd_kcontrol *kctl,for (i =0 ; i < hwchan; i++) {long val = ctl_val->value.integer.value[i]; -if ((val < ctype->min.integer) || (val > ctype->max.integer)) +if (val <snd_audient_int_min (ctype) || + val >snd_audient_int_max (ctype))return -EINVAL ; }
@@ -491,7 +521,8 @@ static int snd_ctl_audient_integer_set(struct snd_kcontrol *kctl,guard (mutex)(&mixer->lock);for (i =0 ; i < hwchan; i++) { -s32 val = ctl_val->value.integer.value[i]; +s32 val =snd_audient_int_from_ctl (ctype, + ctl_val->value.integer.value[i]);int ret; ret = snd_audient_raw_set_one(elem, ctype, base + i, val,
@@ -519,8 +550,8 @@ static int snd_ctl_audient_info(struct snd_kcontrol *kctl, uinfo->value.integer.min =0 ; uinfo->value.integer.max =1 ; }else { - uinfo->value.integer.min = ctype->min.integer; - uinfo->value.integer.max = ctype->max.integer; + uinfo->value.integer.min =snd_audient_int_min (ctype); + uinfo->value.integer.max =snd_audient_int_max (ctype); }return 0 ;
Signature · 1 line
2.56.1
RFC PATCH v4 11/19 ALSA: mixer_audient: Create matrix programmatically
In reply to Will PorterMost Audient devices seem to have a similar mixer matrix with many identical channels. The only difference between devices seems to be the matrix' dimension. Create it programmatically in a loop rather than from the controls table.
--- sound/usb/mixer_audient.c | 77 +++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 43 deletions(-)
sound/usb/mixer_audient.c +34 -43
@@ -105,7 +105,7 @@ static const struct snd_audient_ctrl_type {struct snd_audient_ctrl { -char *name; +const char *const name;enum snd_audient_type type;unsigned int channels;unsigned int hwchannels;
@@ -134,48 +134,6 @@ static const struct snd_audient_ctrl snd_audient_evo4_controls[] = { .hwchannels = 1, .val_offs = 0, }, - { - .name = "Mic 1 Capture Volume", - .type = SND_AUDIENT_TYPE_MIXER, - .channels = 2, - .hwchannels = 2, - .val_offs = 0, - }, - { - .name = "Mic 2 Capture Volume", - .type = SND_AUDIENT_TYPE_MIXER, - .channels = 2, - .hwchannels = 2, - .val_offs = 2, - }, - { - .name = "Master Left Capture Volume", - .type = SND_AUDIENT_TYPE_MIXER, - .channels = 2, - .hwchannels = 2, - .val_offs = 4, - }, - { - .name = "Master Right Capture Volume", - .type = SND_AUDIENT_TYPE_MIXER, - .channels = 2, - .hwchannels = 2, - .val_offs = 6, - }, - { - .name = "Loopback Left Capture Volume", - .type = SND_AUDIENT_TYPE_MIXER, - .channels = 2, - .hwchannels = 2, - .val_offs = 8, - }, - { - .name = "Loopback Right Capture Volume", - .type = SND_AUDIENT_TYPE_MIXER, - .channels = 2, - .hwchannels = 2, - .val_offs = 10, - }, { .name = "Mic 1 Phantom Capture Switch", .type = SND_AUDIENT_TYPE_PHANTOM,
@@ -193,13 +151,27 @@ static const struct snd_audient_ctrl snd_audient_evo4_controls[] = { { 0 }, /* sentinel */ }; +static const char *const snd_audient_evo4_matrix[] = { +"Mic 1 Capture Volume" , +"Mic 2 Capture Volume" , +"Master Left Capture Volume" , +"Master Right Capture Volume" , +"Loopback Left Capture Volume" , +"Loopback Right Capture Volume" , +NULL +}; +static const struct audient_devinfo {u32 usb_id;const struct snd_audient_ctrl *controls; +const char *const *const matrix_names; +const unsigned int matrix_channels; } audient_devinfo[] = { { .usb_id =USB_ID (USB_AUDIENT_VID ,USB_EVO4_PID ), .controls = snd_audient_evo4_controls, + .matrix_names = snd_audient_evo4_matrix, + .matrix_channels =2 , }, {0 }/* sentinel */ };
@@ -645,6 +617,8 @@ int snd_audient_controls_create(struct usb_mixer_interface *mixer)const struct audient_devinfo *info;const struct snd_audient_ctrl *ctrl; +int i; +for (info = audient_devinfo; info->controls; info++)if (info->usb_id == mixer->chip->usb_id)break ;
@@ -659,5 +633,22 @@ int snd_audient_controls_create(struct usb_mixer_interface *mixer)return ret; } +if (info->matrix_names) { +for (i =0 ; info->matrix_names[i]; i++) { +const struct snd_audient_ctrl c = { + .name = info->matrix_names[i], + .type =SND_AUDIENT_TYPE_MIXER , + .channels = info->matrix_channels, + .hwchannels = info->matrix_channels, + .val_offs = i * info->matrix_channels, + }; + +const int ret =snd_audient_add_ctrl (mixer, &c); + +if (ret <0 ) +return ret; + } + } +return 0 ; }
Signature · 1 line
2.56.1
RFC PATCH v4 13/19 ALSA: mixer_audient: Add enumerated controls
In reply to Will PorterFrom: Will Porter <[email protected]>
The iD14 has selectors with a fixed set of device values: output routing, mono mode, the iD key function, talkback source and the digital input mode. Add an enumerated control type with a value list.
The item list has one item more than the values. A put cannot select it. A get shows it for a device value outside the list, so a value set by other means stays visible as such, not as a wrong item, and for a write-only value that no write has confirmed.
--- sound/usb/mixer_audient.c | 126 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+)
sound/usb/mixer_audient.c +126 -0
@@ -42,6 +42,25 @@ static const DECLARE_TLV_DB_MINMAX_MUTE(snd_audient_tlv_mixer, -12800, 600);#define SND_AUDIENT_CTYPE_FLAGS_GET_BROKEN BIT(2)#define SND_AUDIENT_CTYPE_FLAGS_CACHE BIT(3) +/* +* An enumerated control: item i sends values[i]. A get of a device value +* outside the list returns -EIO; it does not show a wrong item. +*/ +struct snd_audient_enum { +const char *const *texts; +const u32 *values; +unsigned int items; +}; + +#define SND_AUDIENT_ENUM (name, texts_, ...) \ + static const u32 name##_values[] = { __VA_ARGS__ }; \ + static const struct snd_audient_enum name = { \ + .texts = texts_, \ + .values = name##_values, \ + .items = ARRAY_SIZE(name##_values), \ + }; \ + static_assert(ARRAY_SIZE(texts_) == ARRAY_SIZE(name##_values)) + static const struct snd_audient_ctrl_type { snd_ctl_elem_type_t type; unsigned long flags;
@@ -54,6 +73,7 @@ static const struct snd_audient_ctrl_type { } max;/* for booleans holds physical int value for true */ u32 init;/* hardware and cache are initialized to this value */ unsigned int res;/* integers: device units per control step, 0 = 1 */ +const struct snd_audient_enum *enumeration;const unsigned int *tlv;u8 unit;u8 sel;
@@ -537,12 +557,114 @@ static int snd_ctl_audient_integer_set(struct snd_kcontrol *kctl,return changed; } +static unsigned int snd_audient_enum_item (const struct snd_audient_enum *e, +u32 value) +{ +unsigned int item; + +for (item =0 ; item < e->items; item++) +if (e->values[item] == value) +break ; + +return item;/* e->items: not in the list */ +} + +static int snd_ctl_audient_enum_get (struct snd_kcontrol *kctl, +struct snd_ctl_elem_value *ctl_val) +{ +struct usb_mixer_elem_info *const elem =snd_kcontrol_chip (kctl); +struct usb_mixer_interface *const mixer = elem->head.mixer; + +const unsigned int nchan =snd_audient_kctl_channels (kctl); +const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl); +const struct snd_audient_ctrl_type *const ctype + =snd_audient_kctl_type (kctl); +const u8 base =snd_audient_kctl_cidxoffs (kctl); + +unsigned int i; + +CLASS (snd_usb_lock, pm)(mixer->chip); +if (pm.err <0 ) +return pm.err; +/* serializes the transfers and the cache, also between gets */ +guard (mutex)(&mixer->lock); + +for (i =0 ; i < hwchan; i++) { +unsigned int item; +u32 val; +int ret; + + ret =snd_audient_raw_get_one (elem, ctype, base + i, &val); +if (ret == -ENODATA )/* unknown write-only value: init */ + val = ctype->init; +else if (ret <0 ) +return ret; + + item =snd_audient_enum_item (ctype->enumeration, val); +if (item >= ctype->enumeration->items) +return -EIO ; + + ctl_val->value.enumerated.item[i] = item; + } + +for (; i < nchan; i++) + ctl_val->value.enumerated.item[i] =0 ; + +return 0 ; +} + +static int snd_ctl_audient_enum_set (struct snd_kcontrol *kctl, +struct snd_ctl_elem_value *ctl_val) +{ +struct usb_mixer_elem_info *const elem =snd_kcontrol_chip (kctl); +struct usb_mixer_interface *const mixer = elem->head.mixer; + +const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl); +const struct snd_audient_ctrl_type *const ctype + =snd_audient_kctl_type (kctl); +const struct snd_audient_enum *const e = ctype->enumeration; +const u8 base =snd_audient_kctl_cidxoffs (kctl); + +unsigned int i; +int changed =0 ; + +for (i =0 ; i < hwchan; i++) +if (ctl_val->value.enumerated.item[i] >= e->items) +return -EINVAL ; + +CLASS (snd_usb_lock, pm)(mixer->chip); +if (pm.err <0 ) +return pm.err; +/* serializes the transfers and the cache, also between gets */ +guard (mutex)(&mixer->lock); + +for (i =0 ; i < hwchan; i++) { +const unsigned int item = ctl_val->value.enumerated.item[i]; +int ret; + + ret =snd_audient_raw_set_one (elem, ctype, base + i, + e->values[item], false); +if (ret <0 ) +return ret; + +if (ret) + changed =1 ; + } + +return changed; +} +static int snd_ctl_audient_info (struct snd_kcontrol *kctl,struct snd_ctl_elem_info *uinfo) {const struct snd_audient_ctrl_type *const ctype =snd_audient_kctl_type (kctl); +if (ctype->type ==SNDRV_CTL_ELEM_TYPE_ENUMERATED ) +return snd_ctl_enum_info (uinfo,snd_audient_kctl_channels (kctl), + ctype->enumeration->items, + ctype->enumeration->texts); + uinfo->type = ctype->type; uinfo->count =snd_audient_kctl_channels (kctl);
@@ -590,6 +712,10 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer, knew.get = snd_ctl_audient_boolean_get; knew.put = snd_ctl_audient_boolean_set;break ; +case SNDRV_CTL_ELEM_TYPE_ENUMERATED : + knew.get = snd_ctl_audient_enum_get; + knew.put = snd_ctl_audient_enum_set; +break ;default :return -EINVAL ; }
Signature · 1 line
2.56.1
RFC PATCH v4 16/19 ALSA: mixer_audient: Replace the Audient iD14 MkI FU 12 control
In reply to Will PorterFrom: Will Porter <[email protected]>
Feature unit 12 sets the level of the mixer outputs: channels 1-2 Main, 3-4 Cue. Two firmware faults make the generic control wrong on the MkI:
- GET CUR does not return the FU 12 value. It returns a reply buffer that the device shares with FU 10, MU 60 and XU 51. The buffer holds the data of the last GET or SET to any of them. So the generic sticky-GET check passes, because GET echoes the SET just sent. The check then writes the stale value that it read first to channel 1.
- Main L ignores its level, but Main R applies it. So any Main value other than 0 dB unbalances the main outputs. audient_id14_map already records this asymmetry. A loopback cable measured it: Main R at -20 dB and -40 dB changes its output by -20.0 and -40.9 dB. Main L at the same values changes nothing. Cue L and Cue R both work: Cue L follows the set value within about 1 dB down to at least -70 dB; the headphone residual hides lower levels.
Replace the generic control with one of the same name, count and range. It is "Monitor Mix Playback Volume", with four values from 0 to 127 in 1 dB steps. 127 is 0 dB. Value 0 writes 0x8000, the floor that Audient's iD application writes, and the TLV declares it as mute. On Cue L, value 0 gives no output above the fixed headphone residual, about 76 dB below 0 dB. The four values keep the Main L/R, Cue L/R layout of existing saved ALSA states.
The control holds Main at 0 dB, as the iD application does. (The application has no Main fader and writes 0 dB at launch.) A put always sends 0 dB to channels 1-2 and returns that value to the caller. Get reports it too. For Cue the control shows the last value the device accepted. At probe the driver writes the iD application's launch values once per channel: Main 0 dB, Cue muted. A channel whose probe write fails reads as mute until a put succeeds.
The iD14 MkI profile in alsa-ucm-conf writes 127,127,127,127 to this control at boot and when its HiFi verb starts. The new control accepts that write: Main stays at 0 dB and Cue goes to 0 dB, the same result as with the generic control.
Differences from the generic control:
- Value 0 is now mute. It was -127 dB.
- The control holds Main at 0 dB. A Main R attenuation stored with the generic control (for example 107, -20 dB) now restores as 0 dB, which raises Main R by 20 dB. Main L never applied that attenuation, so Main R comes up to the level that Main L already had. FU 12 comes before the monitor controller (XU 54) and the headphone level (FU 10), so the volume knob still sets the listening level.
- Cue starts muted at every probe. An output routed to the Cue Mix keeps that routing across a module reload or a rebind. On mains power it also keeps it across a replug. If the probe writes succeed, that output is then muted until user space sets the Cue level (alsactl restore or the UCM boot write). On bus power the MkI returns to DAW Thru when it enumerates, so no output is on the Cue Mix at probe.
The control does not fit the generic types, so the device table gains a create hook for controls the tables cannot describe, called after the tables.
--- sound/usb/mixer_audient.c | 167 ++++++++++++++++++++++++++++++++++++++ sound/usb/mixer_maps.c | 2 +- 2 files changed, 168 insertions(+), 1 deletion(-)
sound/usb/mixer_audient.c +167 -0
@@ -487,11 +487,15 @@ static const char *const snd_audient_id14_mk1_matrix[] = {NULL }; +static int snd_audient_id14_mk1_create (struct usb_mixer_interface *mixer); +static const struct audient_devinfo {u32 usb_id;const struct snd_audient_ctrl *controls;const char *const *const matrix_names;const unsigned int matrix_channels; +/* controls the tables cannot describe; called after the tables */ +int (*create)(struct usb_mixer_interface *mixer); } audient_devinfo[] = { { .usb_id =USB_ID (USB_AUDIENT_VID ,USB_EVO4_PID ),
@@ -504,6 +508,7 @@ static const struct audient_devinfo { .controls = snd_audient_id14_mk1_controls, .matrix_names = snd_audient_id14_mk1_matrix, .matrix_channels = 2, + .create = snd_audient_id14_mk1_create, }, { 0 } /* sentinel */ };
@@ -1079,6 +1084,165 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer, } +/* +* iD14 MkI FU 12, the mixer output level: CN 1-2 Main, 3-4 Cue. GET RANGE +* works (-127 ... 0 dB, 1 dB steps), but GET CUR returns a reply buffer the +* device shares with other units, not the FU 12 value. So the generic +* control shows stale data, and its sticky-GET check passes and then writes +* that stale value to Main L. +* +* The firmware ignores Main L (CN 1) but applies Main R (CN 2), so any Main +* level other than 0 dB unbalances the main outputs (Cue L and Cue R both +* work). This control holds Main at 0 dB: a put sends 0 dB to CN 1-2 +* whatever it asks for, and get reports it. +* +* It keeps the generic control's name and format: four values, 0 ... 127 +* in 1 dB steps, 127 = 0 dB, 0 = mute (0x8000). It shows the last value the +* device accepted, and every put sends all four channels. +*/ +#define ID14_FU12_CHANNELS 4 +#define ID14_FU12_MAIN_CHANNELS 2/* CN 1-2, held at 0 dB */ +#define ID14_FU12_MAX 127 +#define ID14_FU12_MUTE 0 + +static const DECLARE_TLV_DB_MINMAX_MUTE(snd_audient_tlv_id14_fu12, -12700, 0); + +static const struct snd_audient_ctrl_type snd_audient_id14_fu12_type = { + .len =2 , + .unit =ID14_FU_MIX , + .sel =UAC_FU_VOLUME , +}; + +struct snd_audient_id14_fu12 { +struct usb_mixer_elem_list list;/* first: snd_usb_mixer_elem_free */ +long val[ID14_FU12_CHANNELS ]; +u8 valid;/* bit per channel */ +}; + +static int snd_audient_id14_fu12_write (struct snd_audient_id14_fu12 *f, +unsigned int ch,long val) +{ +__le16 buf =cpu_to_le16 (val ==ID14_FU12_MUTE ?-128 *256 + : (val -ID14_FU12_MAX ) *256 ); +int ret; + + ret =snd_audient_set_cur (f->list.mixer, &snd_audient_id14_fu12_type, + ch +1 , &buf); +if (ret <0 ) +return ret; + + f->val[ch] = val; + f->valid |=BIT (ch); + +return 0 ; +} + +static int snd_ctl_audient_id14_fu12_info (struct snd_kcontrol *kctl, +struct snd_ctl_elem_info *uinfo) +{ + uinfo->type =SNDRV_CTL_ELEM_TYPE_INTEGER ; + uinfo->count =ID14_FU12_CHANNELS ; + uinfo->value.integer.min =0 ; + uinfo->value.integer.max =ID14_FU12_MAX ; + +return 0 ; +} + +static int snd_ctl_audient_id14_fu12_get (struct snd_kcontrol *kctl, +struct snd_ctl_elem_value *ctl_val) +{ +struct snd_audient_id14_fu12 *f =snd_kcontrol_chip (kctl); +unsigned int ch; + +/* a channel that was never written reads as mute */ +for (ch =0 ; ch <ID14_FU12_CHANNELS ; ch++) + ctl_val->value.integer.value[ch] = (f->valid &BIT (ch)) + ? f->val[ch] + :ID14_FU12_MUTE ; + +return 0 ; +} + +static int snd_ctl_audient_id14_fu12_set (struct snd_kcontrol *kctl, +struct snd_ctl_elem_value *ctl_val) +{ +struct snd_audient_id14_fu12 *f =snd_kcontrol_chip (kctl); +long *const v = ctl_val->value.integer.value; +unsigned int ch; +int changed =0 ; + +for (ch =0 ; ch <ID14_FU12_CHANNELS ; ch++) +if (v[ch] <0 || v[ch] >ID14_FU12_MAX ) +return -EINVAL ; + +CLASS (snd_usb_lock, pm)(f->list.mixer->chip); +if (pm.err <0 ) +return pm.err; + +/* Main is held at 0 dB: report that back to the caller */ +for (ch =0 ; ch <ID14_FU12_MAIN_CHANNELS ; ch++) + v[ch] =ID14_FU12_MAX ; + +for (ch =0 ; ch <ID14_FU12_CHANNELS ; ch++) { +int ret; + +if (!(f->valid &BIT (ch)) || f->val[ch] != v[ch]) + changed =1 ; + + ret =snd_audient_id14_fu12_write (f, ch, v[ch]); +if (ret <0 ) +return ret; + } + +return changed; +} + +/* At probe, set Main to 0 dB and mute Cue. */ +static int snd_audient_id14_mk1_create (struct usb_mixer_interface *mixer) +{ +struct snd_kcontrol_new knew = { + .iface =SNDRV_CTL_ELEM_IFACE_MIXER , + .name ="Monitor Mix Playback Volume" , + .access =SNDRV_CTL_ELEM_ACCESS_READWRITE + |SNDRV_CTL_ELEM_ACCESS_TLV_READ , + .info = snd_ctl_audient_id14_fu12_info, + .get = snd_ctl_audient_id14_fu12_get, + .put = snd_ctl_audient_id14_fu12_set, + .tlv.p = snd_audient_tlv_id14_fu12, + }; +struct snd_audient_id14_fu12 *f; +struct snd_kcontrol *kctl; +unsigned int ch; + + f =kzalloc_obj (*f); +if (!f) +return -ENOMEM ; + + f->list.mixer = mixer; + f->list.id =ID14_FU_MIX ; + +for (ch =0 ; ch <ID14_FU12_CHANNELS ; ch++) { +const int ret =snd_audient_id14_fu12_write (f, ch, + ch <ID14_FU12_MAIN_CHANNELS ?ID14_FU12_MAX + :ID14_FU12_MUTE ); + +if (ret <0 )/* the channel stays unknown and reads as mute */ +usb_audio_warn (mixer->chip, +"iD14: cannot set FU 12 channel %u (%d)\n" , + ch +1 , ret); + } + + kctl =snd_ctl_new1 (&knew, f); +if (!kctl) { +kfree (f); +return -ENOMEM ; + } + + kctl->private_free = snd_usb_mixer_elem_free; + +return snd_usb_mixer_add_list (&f->list, kctl, false, true); +} +/* called from mixer_quirks.c */ int snd_audient_controls_create (struct usb_mixer_interface *mixer) {
@@ -1118,5 +1282,8 @@ int snd_audient_controls_create(struct usb_mixer_interface *mixer) } } +if (info->create) +return info->create (mixer); +return 0 ; }
sound/usb/mixer_maps.c +1 -1
@@ -543,7 +543,7 @@ static const struct usbmix_name_map audient_id14_map[] = {/* Audient iD14 MkI: model-specific control map. */ static const struct usbmix_name_map audient_id14_mk1_map[] = { {11 ,NULL },/* FU, see mixer_audient.c */ - {12 ,"Monitor Mix Playback" },/* FU, partial coverage */ + {12 ,NULL },/* FU, see mixer_audient.c */ {60 ,NULL },/* MU, see mixer_audient.c */ {} };
Signature · 1 line
2.56.1
RFC PATCH v4 18/19 ALSA: mixer_audient: Unify snd_audient_*_set/get functions for different types
In reply to Will PorterThe set/get functions were originally type specific. With more and more types needed we reached the threshold where it makes sense to merge them into one function for get and one for set and handle the type differences in a switch statement. Perform this merge to reduce code duplication.
--- sound/usb/mixer_audient.c | 294 ++++++++++++-------------------------- 1 file changed, 88 insertions(+), 206 deletions(-)
sound/usb/mixer_audient.c +88 -206
@@ -683,83 +683,6 @@ static int snd_audient_raw_set_one(struct usb_mixer_elem_info *const elem, } -static int snd_ctl_audient_boolean_get (struct snd_kcontrol *kctl, -struct snd_ctl_elem_value *ctl_val) -{ -struct usb_mixer_elem_info *const elem =snd_kcontrol_chip (kctl); -struct usb_mixer_interface *const mixer = elem->head.mixer; - -const unsigned int nchan =snd_audient_kctl_channels (kctl); -const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl); -const struct snd_audient_ctrl_type *const ctype - =snd_audient_kctl_type (kctl); -const u8 base =snd_audient_kctl_cidxoffs (kctl); - -int i; - -CLASS (snd_usb_lock, pm)(mixer->chip); -if (pm.err <0 ) -return pm.err; -/* serializes the transfers and the cache, also between gets */ -guard (mutex)(&mixer->lock); - -for (i =0 ; i < hwchan; i++) { -u32 buf; -int ret; - - ret =snd_audient_raw_get_one (elem, ctype, base + i, &buf); -if (ret == -ENODATA )/* unknown write-only value: off */ - buf = ctype->min.integer; -else if (ret <0 ) -return ret; - - ctl_val->value.integer.value[i] = (buf == ctype->min.integer) - ? false : true; - } - -for (; i < nchan; i++) - ctl_val->value.integer.value[i] =0 ; - -return 0 ; -} - -static int snd_ctl_audient_boolean_set (struct snd_kcontrol *kctl, -struct snd_ctl_elem_value *ctl_val) -{ -struct usb_mixer_elem_info *const elem =snd_kcontrol_chip (kctl); -struct usb_mixer_interface *const mixer = elem->head.mixer; - -const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl); -const struct snd_audient_ctrl_type *const ctype - =snd_audient_kctl_type (kctl); -const u8 base =snd_audient_kctl_cidxoffs (kctl); - -int changed =0 ; -int i; - -CLASS (snd_usb_lock, pm)(mixer->chip); -if (pm.err <0 ) -return pm.err; -/* serializes the transfers and the cache, also between gets */ -guard (mutex)(&mixer->lock); - -for (i =0 ; i < hwchan; i++) { -u32 buf = ctl_val->value.integer.value[i] ? ctype->max.integer - : ctype->min.integer; -int ret; - - ret =snd_audient_raw_set_one (elem, ctype, base + i, buf, - false); -if (ret <0 ) -return ret; - -if (ret) - changed =1 ; - } - -return changed; -} -/* * With a step size (res), an integer control counts steps from min: * 0 ... (max - min) / res. Without one it shows the device value.
@@ -778,8 +701,9 @@ snd_audient_int_min(const struct snd_audient_ctrl_type *ctype) }static long snd_audient_int_to_ctl (const struct snd_audient_ctrl_type *ctype, -long val) +u32 buf) { +s32 val = (s32 )buf; val =clamp (val, ctype->min.integer, ctype->max.integer);if (!ctype->res)return val;
@@ -789,96 +713,19 @@ static long snd_audient_int_to_ctl(const struct snd_audient_ctrl_type *ctype, snd_audient_int_max(ctype)); } -static inline long +static inline u32 snd_audient_int_from_ctl (const struct snd_audient_ctrl_type *ctype,long val) { -return ctype->res ? ctype->min.integer + val * ctype->res : val; -} - -static int snd_ctl_audient_integer_get (struct snd_kcontrol *kctl, -struct snd_ctl_elem_value *ctl_val) -{ -struct usb_mixer_elem_info *const elem =snd_kcontrol_chip (kctl); -struct usb_mixer_interface *const mixer = elem->head.mixer; - -const unsigned int nchan =snd_audient_kctl_channels (kctl); -const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl); -const struct snd_audient_ctrl_type *const ctype - =snd_audient_kctl_type (kctl); -const u8 base =snd_audient_kctl_cidxoffs (kctl); - -int i; - -CLASS (snd_usb_lock, pm)(mixer->chip); -if (pm.err <0 ) -return pm.err; -/* serializes the transfers and the cache, also between gets */ -guard (mutex)(&mixer->lock); - -for (i =0 ; i < hwchan; i++) { -s32 val; -int ret; - - ret =snd_audient_raw_get_one (elem, ctype, base + i, &val); -if (ret == -ENODATA )/* unknown write-only value: minimum */ - val = ctype->min.integer; -else if (ret <0 ) -return ret; +s32 ret; - ctl_val->value.integer.value[i] = -snd_audient_int_to_ctl (ctype, val); - } +if (ctype->res) + ret = ctype->min.integer + val * ctype->res; +else + ret = val; -for (; i < nchan; i++) - ctl_val->value.integer.value[i] =snd_audient_int_min (ctype); - -return 0 ; +return (u32 )ret; } -static int snd_ctl_audient_integer_set (struct snd_kcontrol *kctl, -struct snd_ctl_elem_value *ctl_val) -{ -struct usb_mixer_elem_info *const elem =snd_kcontrol_chip (kctl); -struct usb_mixer_interface *mixer = elem->head.mixer; - -const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl); -const struct snd_audient_ctrl_type *const ctype - =snd_audient_kctl_type (kctl); -const u8 base =snd_audient_kctl_cidxoffs (kctl); - -int changed =0 ; -int i; - -for (i =0 ; i < hwchan; i++) { -long val = ctl_val->value.integer.value[i]; - -if (val <snd_audient_int_min (ctype) || - val >snd_audient_int_max (ctype)) -return -EINVAL ; - } - -CLASS (snd_usb_lock, pm)(mixer->chip); -if (pm.err <0 ) -return pm.err; -/* serializes the transfers and the cache, also between gets */ -guard (mutex)(&mixer->lock); - -for (i =0 ; i < hwchan; i++) { -s32 val =snd_audient_int_from_ctl (ctype, - ctl_val->value.integer.value[i]); -int ret; - - ret =snd_audient_raw_set_one (elem, ctype, base + i, val, - false); -if (ret <0 ) -return ret; - -if (ret) - changed =1 ; - } - -return changed; -}/* The item index of a device value, or -EIO if the value is not in the list */ static int snd_audient_enum_item (const struct snd_audient_enum *e,u32 value)
@@ -892,8 +739,9 @@ static int snd_audient_enum_item(const struct snd_audient_enum *e, u32 value)return -EIO ; } -static int snd_ctl_audient_enum_get (struct snd_kcontrol *kctl, -struct snd_ctl_elem_value *ctl_val) + +static int snd_ctl_audient_get (struct snd_kcontrol *kctl, +struct snd_ctl_elem_value *ctl_val) {struct usb_mixer_elem_info *const elem =snd_kcontrol_chip (kctl);struct usb_mixer_interface *const mixer = elem->head.mixer;
@@ -904,7 +752,7 @@ static int snd_ctl_audient_enum_get(struct snd_kcontrol *kctl, = snd_audient_kctl_type(kctl);const u8 base =snd_audient_kctl_cidxoffs (kctl); -unsigned int i; +int i;CLASS (snd_usb_lock, pm)(mixer->chip);if (pm.err <0 )
@@ -912,32 +760,53 @@ static int snd_ctl_audient_enum_get(struct snd_kcontrol *kctl,/* serializes the transfers and the cache, also between gets */ guard (mutex)(&mixer->lock); -for (i =0 ; i < hwchan; i++) { -u32 val; -int item; -int ret; +for (i =0 ; i < nchan; i++) { +u32 buf; +long ret; - ret =snd_audient_raw_get_one (elem, ctype, base + i, &val); -if (ret == -ENODATA )/* unknown write-only value: init */ - val = ctype->init; + ret =snd_audient_raw_get_one (elem, ctype, base + i, &buf); +if (ret == -ENODATA )/* unknown write-only value: off */ + buf = ctype->init;else if (ret <0 )return ret; - item =snd_audient_enum_item (ctype->enumeration, val); -if (item <0 ) -return item; - - ctl_val->value.enumerated.item[i] = item; +switch (ctype->type) { +case SNDRV_CTL_ELEM_TYPE_BOOLEAN : +if (i >= hwchan) + ctl_val->value.integer.value[i] =0 ; +else if (buf == ctype->min.integer) + ctl_val->value.integer.value[i] = false; +else + ctl_val->value.integer.value[i] = true; +break ; +case SNDRV_CTL_ELEM_TYPE_INTEGER : +if (i >= hwchan) + ctl_val->value.integer.value[i] = +snd_audient_int_min (ctype); +else + ctl_val->value.integer.value[i] = +snd_audient_int_to_ctl (ctype, buf); +break ; +case SNDRV_CTL_ELEM_TYPE_ENUMERATED : +if (i >= hwchan) { + ctl_val->value.enumerated.item[i] =0 ; + }else { + ret =snd_audient_enum_item (ctype->enumeration, + buf); +if (ret <0 ) +return ret; + + ctl_val->value.enumerated.item[i] = ret; + } +break ; + } } -for (; i < nchan; i++) - ctl_val->value.enumerated.item[i] =0 ; -return 0 ; } -static int snd_ctl_audient_enum_set (struct snd_kcontrol *kctl, -struct snd_ctl_elem_value *ctl_val) +static int snd_ctl_audient_set (struct snd_kcontrol *kctl, +struct snd_ctl_elem_value *ctl_val) {struct usb_mixer_elem_info *const elem =snd_kcontrol_chip (kctl);struct usb_mixer_interface *const mixer = elem->head.mixer;
@@ -945,15 +814,28 @@ static int snd_ctl_audient_enum_set(struct snd_kcontrol *kctl,const unsigned int hwchan =snd_audient_kctl_hwchannels (kctl);const struct snd_audient_ctrl_type *const ctype =snd_audient_kctl_type (kctl); -const struct snd_audient_enum *const e = ctype->enumeration;const u8 base =snd_audient_kctl_cidxoffs (kctl); -unsigned int i; + typeof(ctl_val->value) *const v = &ctl_val->value; +const struct snd_audient_enum *const e = ctype->enumeration; +int changed =0 ; +int i; -for (i =0 ; i < hwchan; i++) -if (ctl_val->value.enumerated.item[i] >= e->items) -return -EINVAL ; + +for (i =0 ; i < hwchan; i++) { +switch (ctype->type) { +case SNDRV_CTL_ELEM_TYPE_INTEGER : +if (v->integer.value[i] <snd_audient_int_min (ctype) || + v->integer.value[i] >snd_audient_int_max (ctype)) +return -EINVAL ; +break ; +case SNDRV_CTL_ELEM_TYPE_ENUMERATED : +if (v->enumerated.item[i] >= e->items) +return -EINVAL ; +break ; + } + }CLASS (snd_usb_lock, pm)(mixer->chip);if (pm.err <0 )
@@ -962,11 +844,25 @@ static int snd_ctl_audient_enum_set(struct snd_kcontrol *kctl,guard (mutex)(&mixer->lock);for (i =0 ; i < hwchan; i++) { -const unsigned int item = ctl_val->value.enumerated.item[i]; +u32 val;int ret; - ret =snd_audient_raw_set_one (elem, ctype, base + i, - e->values[item], false); +switch (ctype->type) { +case SNDRV_CTL_ELEM_TYPE_BOOLEAN : + val = v->integer.value[i] ? ctype->max.integer + : ctype->min.integer; +break ; +case SNDRV_CTL_ELEM_TYPE_INTEGER : + val =snd_audient_int_from_ctl (ctype, + v->integer.value[i]); +break ; +case SNDRV_CTL_ELEM_TYPE_ENUMERATED : + val = e->values[v->enumerated.item[i]]; +break ; + } + + ret =snd_audient_raw_set_one (elem, ctype, base + i, val, + false);if (ret <0 )return ret;
@@ -1029,22 +925,8 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer, : SNDRV_CTL_ELEM_ACCESS_VOLATILE) | (ctype->tlv ?SNDRV_CTL_ELEM_ACCESS_TLV_READ :0 ); -switch (ctype->type) { -case SNDRV_CTL_ELEM_TYPE_INTEGER : - knew.get = snd_ctl_audient_integer_get; - knew.put = snd_ctl_audient_integer_set; -break ; -case SNDRV_CTL_ELEM_TYPE_BOOLEAN : - knew.get = snd_ctl_audient_boolean_get; - knew.put = snd_ctl_audient_boolean_set; -break ; -case SNDRV_CTL_ELEM_TYPE_ENUMERATED : - knew.get = snd_ctl_audient_enum_get; - knew.put = snd_ctl_audient_enum_set; -break ; -default : -return -EINVAL ; - } + knew.get = snd_ctl_audient_get; + knew.put = snd_ctl_audient_set; elem =kzalloc_obj (*elem);if (!elem)
Signature · 1 line
2.56.1
RFC PATCH v4 14/19 ALSA: usb-audio: Give the Audient iD14 MkI its own mixer map
In reply to Will PorterFrom: Will Porter <[email protected]>
The iD14 MkI (2708:0002) and MkII (2708:0008) share audient_id14_map. Later commits add MkI vendor controls that replace some of the generic MkI controls. The MkII keeps the generic controls. Give the MkI its own copy of the map.
No functional change.
--- sound/usb/mixer_maps.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
sound/usb/mixer_maps.c +7 -1
@@ -540,6 +540,12 @@ static const struct usbmix_name_map audient_id14_map[] = { {} }; +/* Audient iD14 MkI: model-specific control map. */ +static const struct usbmix_name_map audient_id14_mk1_map[] = { + {12 ,"Monitor Mix Playback" },/* FU, partial coverage */ + {} +}; +/* * Audient iD24: feature unit 12 ("Speaker Playback Volume") sits in the * monitor-mixer branch and does not apply volume to all of its channels;
@@ -652,7 +658,7 @@ static const struct usbmix_ctl_map usbmix_ctl_maps[] = { {/* Audient iD14 MkI */ .id = USB_ID(0x2708, 0x0002), - .map = audient_id14_map, + .map = audient_id14_mk1_map, }, {/* Audient EVO4 MkI */
Signature · 1 line
2.56.1
RFC PATCH v4 19/19 ALSA: mixer_audient: Refactor FU12 special cases into generic set/get functions
In reply to Will PorterWith the unified get and set functions it is trivial to merge the iD14 FU12 quirks into the generic table controls and remove even more redundant code. Add an ID14_FU12 control type, implement the respective case branches in set/get and remove specific iD14 FU12 code.
--- sound/usb/mixer_audient.c | 289 +++++++++++++++----------------------- 1 file changed, 113 insertions(+), 176 deletions(-)
sound/usb/mixer_audient.c +113 -176
@@ -55,17 +55,45 @@ enum snd_audient_type {SND_AUDIENT_TYPE_ID14_MON_ID_KEY ,SND_AUDIENT_TYPE_ID14_MON_TALKBACK_SRC ,SND_AUDIENT_TYPE_ID14_OPTICAL_MODE , +SND_AUDIENT_TYPE_ID14_FU12 ,SND_AUDIENT_TYPE_NCTYPES };/* Mixer matrix: -128dB (mute) to +6dB */ static const DECLARE_TLV_DB_MINMAX_MUTE(snd_audient_tlv_mixer, -12800, 600); +/* +* iD14 MkI FU 12, the mixer output level: CN 1-2 Main, 3-4 Cue. GET RANGE +* works (-127 ... 0 dB, 1 dB steps), but GET CUR returns a reply buffer the +* device shares with other units, not the FU 12 value. So the generic +* control shows stale data, and its sticky-GET check passes and then writes +* that stale value to Main L. +* +* The firmware ignores Main L (CN 1) but applies Main R (CN 2), so any Main +* level other than 0 dB unbalances the main outputs (Cue L and Cue R both +* work). This control holds Main at 0 dB: a put sends 0 dB to CN 1-2 +* whatever it asks for, and get reports it. +* +* It keeps the generic control's name and format: four values, 0 ... 127 +* in 1 dB steps, 127 = 0 dB, 0 = mute (0x8000). It shows the last value the +* device accepted, and every put sends all four channels. +*/ +#define ID14_FU12_MAIN_CHANNELS 2/* CN 1-2, held at 0 dB */ +#define ID14_FU12_MAX 127 +#define ID14_FU12_MUTE 0 +#define ID14_FU12_HW_MUTE (-128 * 256) + +static const DECLARE_TLV_DB_MINMAX_MUTE(snd_audient_tlv_id14_fu12, -12700, 0); + +/* control type flags */ #define SND_AUDIENT_CTYPE_FLAGS_SIGNED BIT(0)#define SND_AUDIENT_CTYPE_FLAGS_INIT_HW BIT(1)#define SND_AUDIENT_CTYPE_FLAGS_GET_BROKEN BIT(2)#define SND_AUDIENT_CTYPE_FLAGS_CACHE BIT(3) +/* Private control element types for quirky controls */ +#define SNDRV_AUDIENT_CTL_ELEM_TYPE_ID14_FU12 (SNDRV_CTL_ELEM_TYPE_LAST + 1) +/* * An enumerated control: item i sends values[i]. A get of a device value * outside the list returns -EIO; it does not show a wrong item.
@@ -376,6 +404,20 @@ static const struct snd_audient_ctrl_type { .unit = ID14_IT_DIGITAL, .sel = ID14_IT_OPTICAL_MODE, }, + [SND_AUDIENT_TYPE_ID14_FU12] = { + .type = SNDRV_AUDIENT_CTL_ELEM_TYPE_ID14_FU12, + .flags =SND_AUDIENT_CTYPE_FLAGS_SIGNED + |SND_AUDIENT_CTYPE_FLAGS_INIT_HW + | SND_AUDIENT_CTYPE_FLAGS_CACHE, + .len = 2, + .min.integer = -127 * 256, + .max.integer = 0, + .init = ID14_FU12_HW_MUTE, + .res = 256, + .unit = ID14_FU_MIX, + .sel = UAC_FU_VOLUME, + .tlv = snd_audient_tlv_id14_fu12, + }, };
@@ -470,6 +512,7 @@ static const struct snd_audient_ctrl snd_audient_id14_mk1_controls[] = {ID14_CTRL ("iD Key Function Playback Enum" ,MON_ID_KEY ,0 ,1 ),ID14_CTRL ("Talkback Source Capture Enum" ,MON_TALKBACK_SRC ,0 ,1 ),ID14_CTRL ("Digital In Mode Capture Enum" ,OPTICAL_MODE ,0 ,1 ), +ID14_CTRL ("Monitor Mix Playback Volume" ,FU12 ,1 ,4 ), { 0 }, /* sentinel */ };
@@ -492,15 +535,12 @@ static const char *const snd_audient_id14_mk1_matrix[] = {NULL }; -static int snd_audient_id14_mk1_create (struct usb_mixer_interface *mixer); -static const struct audient_devinfo {u32 usb_id;const struct snd_audient_ctrl *controls;const char *const *const matrix_names;const unsigned int matrix_channels;/* optional: controls the tables cannot describe, created after them */ -int (*extra_init)(struct usb_mixer_interface *mixer); } audient_devinfo[] = { { .usb_id =USB_ID (USB_AUDIENT_VID ,USB_EVO4_PID ),
@@ -513,7 +553,6 @@ static const struct audient_devinfo { .controls = snd_audient_id14_mk1_controls, .matrix_names = snd_audient_id14_mk1_matrix, .matrix_channels = 2, - .extra_init = snd_audient_id14_mk1_create, }, { 0 } /* sentinel */ };
@@ -739,6 +778,31 @@ static int snd_audient_enum_item(const struct snd_audient_enum *e, u32 value)return -EIO ; } +static inline u32 +snd_audient_fu12_from_ctl (const struct snd_audient_ctrl_type *ctype,long val) +{ +s32 ret; + +if (val ==ID14_FU12_MUTE ) + ret =ID14_FU12_HW_MUTE ; +else + ret = ctype->min.integer + val * ctype->res; + +return (u32 )ret; +} + +static inline long +snd_audient_fu12_to_ctl (const struct snd_audient_ctrl_type *ctype,u32 buf) +{ +s32 val = (s32 )buf; + +if (val ==ID14_FU12_HW_MUTE ) +return ID14_FU12_MUTE ; +else +return min (DIV_ROUND_CLOSEST (val - ctype->min.integer, + (long )ctype->res), +snd_audient_int_max (ctype)); +}static int snd_ctl_audient_get (struct snd_kcontrol *kctl,struct snd_ctl_elem_value *ctl_val)
@@ -799,6 +863,10 @@ static int snd_ctl_audient_get(struct snd_kcontrol *kctl, ctl_val->value.enumerated.item[i] = ret; }break ; +case SNDRV_AUDIENT_CTL_ELEM_TYPE_ID14_FU12 : + ctl_val->value.integer.value[i] = +snd_audient_fu12_to_ctl (ctype, buf); +break ; } }
@@ -834,6 +902,11 @@ static int snd_ctl_audient_set(struct snd_kcontrol *kctl,if (v->enumerated.item[i] >= e->items)return -EINVAL ;break ; +case SNDRV_AUDIENT_CTL_ELEM_TYPE_ID14_FU12 : +if (v->integer.value[i] <0 + || v->integer.value[i] >ID14_FU12_MAX ) +return -EINVAL ; +break ; } }
@@ -859,6 +932,14 @@ static int snd_ctl_audient_set(struct snd_kcontrol *kctl,case SNDRV_CTL_ELEM_TYPE_ENUMERATED : val = e->values[v->enumerated.item[i]];break ; +case SNDRV_AUDIENT_CTL_ELEM_TYPE_ID14_FU12 : +if (i <ID14_FU12_MAIN_CHANNELS ) { + val = ctype->max.integer; + }else { + val =snd_audient_fu12_from_ctl (ctype, + v->integer.value[i]); + } +break ; } ret = snd_audient_raw_set_one(elem, ctype, base + i, val,
@@ -879,25 +960,30 @@ static int snd_ctl_audient_info(struct snd_kcontrol *kctl,const struct snd_audient_ctrl_type *const ctype =snd_audient_kctl_type (kctl); + uinfo->type = ctype->type; + uinfo->count =snd_audient_kctl_channels (kctl); +switch (ctype->type) { -case SNDRV_CTL_ELEM_TYPE_ENUMERATED : -return snd_ctl_enum_info (uinfo, -snd_audient_kctl_channels (kctl), - ctype->enumeration->items, - ctype->enumeration->texts);case SNDRV_CTL_ELEM_TYPE_BOOLEAN : uinfo->value.integer.min =0 ; uinfo->value.integer.max =1 ;break ; -default : +case SNDRV_CTL_ELEM_TYPE_INTEGER : uinfo->value.integer.min =snd_audient_int_min (ctype); uinfo->value.integer.max =snd_audient_int_max (ctype);break ; +case SNDRV_CTL_ELEM_TYPE_ENUMERATED : +return snd_ctl_enum_info (uinfo, +snd_audient_kctl_channels (kctl), + ctype->enumeration->items, + ctype->enumeration->texts); +case SNDRV_AUDIENT_CTL_ELEM_TYPE_ID14_FU12 : + uinfo->value.integer.min =0 ; + uinfo->value.integer.max =ID14_FU12_MAX ; + uinfo->type =SNDRV_CTL_ELEM_TYPE_INTEGER ; +break ; } - uinfo->type = ctype->type; - uinfo->count =snd_audient_kctl_channels (kctl); -return 0 ; }
@@ -949,9 +1035,22 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer,int i;for (i =0 ; i < ctrl->hwchannels; i++) { +u32 init; + +switch (ctype->type) { +case SNDRV_AUDIENT_CTL_ELEM_TYPE_ID14_FU12 : +if (i <ID14_FU12_MAIN_CHANNELS ) + init = ctype->max.integer; +else + init = ctype->init; +break ; +default : + init = ctype->init; +break ; + } ret =snd_audient_raw_set_one (elem, ctype, ctrl->val_offs + i, - ctype->init, true); + init, true);if (ret <0 ) usb_audio_warn(mixer->chip, "%s: cannot set channel %d (%d)\n",
@@ -976,165 +1075,6 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer, } -/* -* iD14 MkI FU 12, the mixer output level: CN 1-2 Main, 3-4 Cue. GET RANGE -* works (-127 ... 0 dB, 1 dB steps), but GET CUR returns a reply buffer the -* device shares with other units, not the FU 12 value. So the generic -* control shows stale data, and its sticky-GET check passes and then writes -* that stale value to Main L. -* -* The firmware ignores Main L (CN 1) but applies Main R (CN 2), so any Main -* level other than 0 dB unbalances the main outputs (Cue L and Cue R both -* work). This control holds Main at 0 dB: a put sends 0 dB to CN 1-2 -* whatever it asks for, and get reports it. -* -* It keeps the generic control's name and format: four values, 0 ... 127 -* in 1 dB steps, 127 = 0 dB, 0 = mute (0x8000). It shows the last value the -* device accepted, and every put sends all four channels. -*/ -#define ID14_FU12_CHANNELS 4 -#define ID14_FU12_MAIN_CHANNELS 2/* CN 1-2, held at 0 dB */ -#define ID14_FU12_MAX 127 -#define ID14_FU12_MUTE 0 - -static const DECLARE_TLV_DB_MINMAX_MUTE(snd_audient_tlv_id14_fu12, -12700, 0); - -static const struct snd_audient_ctrl_type snd_audient_id14_fu12_type = { - .len =2 , - .unit =ID14_FU_MIX , - .sel =UAC_FU_VOLUME , -}; - -struct snd_audient_id14_fu12 { -struct usb_mixer_elem_list list;/* first: snd_usb_mixer_elem_free */ -long val[ID14_FU12_CHANNELS ]; -u8 valid;/* bit per channel */ -}; - -static int snd_audient_id14_fu12_write (struct snd_audient_id14_fu12 *f, -unsigned int ch,long val) -{ -__le16 buf =cpu_to_le16 (val ==ID14_FU12_MUTE ?-128 *256 - : (val -ID14_FU12_MAX ) *256 ); -int ret; - - ret =snd_audient_set_cur (f->list.mixer, &snd_audient_id14_fu12_type, - ch +1 , &buf); -if (ret <0 ) -return ret; - - f->val[ch] = val; - f->valid |=BIT (ch); - -return 0 ; -} - -static int snd_ctl_audient_id14_fu12_info (struct snd_kcontrol *kctl, -struct snd_ctl_elem_info *uinfo) -{ - uinfo->type =SNDRV_CTL_ELEM_TYPE_INTEGER ; - uinfo->count =ID14_FU12_CHANNELS ; - uinfo->value.integer.min =0 ; - uinfo->value.integer.max =ID14_FU12_MAX ; - -return 0 ; -} - -static int snd_ctl_audient_id14_fu12_get (struct snd_kcontrol *kctl, -struct snd_ctl_elem_value *ctl_val) -{ -struct snd_audient_id14_fu12 *f =snd_kcontrol_chip (kctl); -unsigned int ch; - -/* a channel that was never written reads as mute */ -for (ch =0 ; ch <ID14_FU12_CHANNELS ; ch++) - ctl_val->value.integer.value[ch] = (f->valid &BIT (ch)) - ? f->val[ch] - :ID14_FU12_MUTE ; - -return 0 ; -} - -static int snd_ctl_audient_id14_fu12_set (struct snd_kcontrol *kctl, -struct snd_ctl_elem_value *ctl_val) -{ -struct snd_audient_id14_fu12 *f =snd_kcontrol_chip (kctl); -long *const v = ctl_val->value.integer.value; -unsigned int ch; -int changed =0 ; - -for (ch =0 ; ch <ID14_FU12_CHANNELS ; ch++) -if (v[ch] <0 || v[ch] >ID14_FU12_MAX ) -return -EINVAL ; - -CLASS (snd_usb_lock, pm)(f->list.mixer->chip); -if (pm.err <0 ) -return pm.err; - -/* Main is held at 0 dB: report that back to the caller */ -for (ch =0 ; ch <ID14_FU12_MAIN_CHANNELS ; ch++) - v[ch] =ID14_FU12_MAX ; - -for (ch =0 ; ch <ID14_FU12_CHANNELS ; ch++) { -int ret; - -if (!(f->valid &BIT (ch)) || f->val[ch] != v[ch]) - changed =1 ; - - ret =snd_audient_id14_fu12_write (f, ch, v[ch]); -if (ret <0 ) -return ret; - } - -return changed; -} - -/* At probe, set Main to 0 dB and mute Cue. */ -static int snd_audient_id14_mk1_create (struct usb_mixer_interface *mixer) -{ -struct snd_kcontrol_new knew = { - .iface =SNDRV_CTL_ELEM_IFACE_MIXER , - .name ="Monitor Mix Playback Volume" , - .access =SNDRV_CTL_ELEM_ACCESS_READWRITE - |SNDRV_CTL_ELEM_ACCESS_TLV_READ , - .info = snd_ctl_audient_id14_fu12_info, - .get = snd_ctl_audient_id14_fu12_get, - .put = snd_ctl_audient_id14_fu12_set, - .tlv.p = snd_audient_tlv_id14_fu12, - }; -struct snd_audient_id14_fu12 *f; -struct snd_kcontrol *kctl; -unsigned int ch; - - f =kzalloc_obj (*f); -if (!f) -return -ENOMEM ; - - f->list.mixer = mixer; - f->list.id =ID14_FU_MIX ; - -for (ch =0 ; ch <ID14_FU12_CHANNELS ; ch++) { -const int ret =snd_audient_id14_fu12_write (f, ch, - ch <ID14_FU12_MAIN_CHANNELS ?ID14_FU12_MAX - :ID14_FU12_MUTE ); - -if (ret <0 )/* the channel stays unknown and reads as mute */ -usb_audio_warn (mixer->chip, -"iD14: cannot set FU 12 channel %u (%d)\n" , - ch +1 , ret); - } - - kctl =snd_ctl_new1 (&knew, f); -if (!kctl) { -kfree (f); -return -ENOMEM ; - } - - kctl->private_free = snd_usb_mixer_elem_free; - -return snd_usb_mixer_add_list (&f->list, kctl, false, true); -} -/* called from mixer_quirks.c */ int snd_audient_controls_create (struct usb_mixer_interface *mixer) {
@@ -1174,8 +1114,5 @@ int snd_audient_controls_create(struct usb_mixer_interface *mixer) } } -if (info->extra_init) -return info->extra_init (mixer); -return 0 ; }
Signature · 1 line
2.56.1
RFC PATCH v4 17/19 ALSA: mixer_audient: Fold in the review changes to patches 12-16
In reply to Will PorterFrom: Will Porter <[email protected]>
This patch is not for merging. It carries the changes from the review of RFC patches 12 to 16 as one diff, so that the patches after it apply to the RFC with the enum fix. The next version of the series has these changes in patches 12, 13, 15 and 16.
- Declare snd_audient_int_max(), snd_audient_int_min() and snd_audient_int_from_ctl() inline.
- snd_audient_enum_item() returns the item or -EIO, and get propagates the error.
- snd_ctl_audient_info() uses a switch.
- A comment on ID14_ENUM() says that readable enums do not use init.
- The two case labels in mixer_quirks.c share one call.
- Rename the create hook to extra_init and say that it is optional.
--- sound/usb/mixer_audient.c | 58 +++++++++++++++++++++++---------------- sound/usb/mixer_quirks.c | 2 -- 2 files changed, 34 insertions(+), 26 deletions(-)
sound/usb/mixer_audient.c +34 -24
@@ -219,6 +219,11 @@ SND_AUDIENT_ENUM(snd_audient_id14_optical, snd_audient_id14_optical_texts, .sel = (sel_), \ } +/* +* A readable enum. It has no cache entry, so a get always reads the device +* and never uses init. Write-only enums set .init and .flags without this +* macro. +*/ #define ID14_ENUM (unit_, sel_, len_, enum_) \ { \ .type = SNDRV_CTL_ELEM_TYPE_ENUMERATED, \
@@ -494,8 +499,8 @@ static const struct audient_devinfo {const struct snd_audient_ctrl *controls;const char *const *const matrix_names;const unsigned int matrix_channels; -/* controls the tables cannot describe; called after the tables */ -int (*create)(struct usb_mixer_interface *mixer); +/* optional: controls the tables cannot describe, created after them */ +int (*extra_init)(struct usb_mixer_interface *mixer); } audient_devinfo[] = { { .usb_id = USB_ID(USB_AUDIENT_VID, USB_EVO4_PID),
@@ -508,7 +513,7 @@ static const struct audient_devinfo { .controls = snd_audient_id14_mk1_controls, .matrix_names = snd_audient_id14_mk1_matrix, .matrix_channels = 2, - .create = snd_audient_id14_mk1_create, + .extra_init = snd_audient_id14_mk1_create, }, { 0 } /* sentinel */ };
@@ -759,13 +764,15 @@ static int snd_ctl_audient_boolean_set(struct snd_kcontrol *kctl,* With a step size (res), an integer control counts steps from min: * 0 ... (max - min) / res. Without one it shows the device value. */ -static long snd_audient_int_max (const struct snd_audient_ctrl_type *ctype) +static inline long +snd_audient_int_max (const struct snd_audient_ctrl_type *ctype) {return ctype->res ? (ctype->max.integer - ctype->min.integer) / ctype->res : ctype->max.integer; } -static long snd_audient_int_min (const struct snd_audient_ctrl_type *ctype) +static inline long +snd_audient_int_min (const struct snd_audient_ctrl_type *ctype) {return ctype->res ?0 : ctype->min.integer; }
@@ -782,8 +789,8 @@ static long snd_audient_int_to_ctl(const struct snd_audient_ctrl_type *ctype, snd_audient_int_max(ctype)); } -static long snd_audient_int_from_ctl (const struct snd_audient_ctrl_type *ctype, -long val) +static inline long +snd_audient_int_from_ctl (const struct snd_audient_ctrl_type *ctype,long val) {return ctype->res ? ctype->min.integer + val * ctype->res : val; }
@@ -873,16 +880,16 @@ static int snd_ctl_audient_integer_set(struct snd_kcontrol *kctl,return changed; } -static unsigned int snd_audient_enum_item (const struct snd_audient_enum *e, -u32 value) +/* The item index of a device value, or -EIO if the value is not in the list */ +static int snd_audient_enum_item (const struct snd_audient_enum *e,u32 value) {unsigned int item;for (item =0 ; item < e->items; item++)if (e->values[item] == value) -break ; +return item; -return item;/* e->items: not in the list */ +return -EIO ; } static int snd_ctl_audient_enum_get(struct snd_kcontrol *kctl,
@@ -906,8 +913,8 @@ static int snd_ctl_audient_enum_get(struct snd_kcontrol *kctl,guard (mutex)(&mixer->lock);for (i =0 ; i < hwchan; i++) { -unsigned int item;u32 val; +int item;int ret; ret =snd_audient_raw_get_one (elem, ctype, base + i, &val);
@@ -917,8 +924,8 @@ static int snd_ctl_audient_enum_get(struct snd_kcontrol *kctl,return ret; item =snd_audient_enum_item (ctype->enumeration, val); -if (item >= ctype->enumeration->items) -return -EIO ; +if (item <0 ) +return item; ctl_val->value.enumerated.item[i] = item; }
@@ -976,22 +983,25 @@ static int snd_ctl_audient_info(struct snd_kcontrol *kctl,const struct snd_audient_ctrl_type *const ctype =snd_audient_kctl_type (kctl); -if (ctype->type ==SNDRV_CTL_ELEM_TYPE_ENUMERATED ) -return snd_ctl_enum_info (uinfo,snd_audient_kctl_channels (kctl), +switch (ctype->type) { +case SNDRV_CTL_ELEM_TYPE_ENUMERATED : +return snd_ctl_enum_info (uinfo, +snd_audient_kctl_channels (kctl), ctype->enumeration->items, ctype->enumeration->texts); - - uinfo->type = ctype->type; - uinfo->count =snd_audient_kctl_channels (kctl); - -if (ctype->type ==SNDRV_CTL_ELEM_TYPE_BOOLEAN ) { +case SNDRV_CTL_ELEM_TYPE_BOOLEAN : uinfo->value.integer.min =0 ; uinfo->value.integer.max =1 ; - }else { +break ; +default : uinfo->value.integer.min =snd_audient_int_min (ctype); uinfo->value.integer.max =snd_audient_int_max (ctype); +break ; } + uinfo->type = ctype->type; + uinfo->count =snd_audient_kctl_channels (kctl); +return 0 ; }
@@ -1282,8 +1292,8 @@ int snd_audient_controls_create(struct usb_mixer_interface *mixer) } } -if (info->create) -return info->create (mixer); +if (info->extra_init) +return info->extra_init (mixer);return 0 ; }
sound/usb/mixer_quirks.c +0 -2
@@ -4781,8 +4781,6 @@ int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)break ;case USB_ID (USB_AUDIENT_VID ,USB_EVO4_PID ):/* Audient EVO 4 */ - err =snd_audient_controls_create (mixer); -break ;case USB_ID (USB_AUDIENT_VID ,USB_ID14_MK1_PID ):/* Audient iD14 MkI */ err =snd_audient_controls_create (mixer);break ;
Signature · 1 line
2.56.1