Skip to content

Commit 701949c

Browse files
geoffreybennetttiwai
authored andcommitted
ALSA: scarlett2: Add support for reading firmware version
The 84 bytes read during initialisation step 2 were previously ignored. This patch retrieves the firmware version from bytes 8-11, stores it in the scarlett2_data struct, and makes it available through a new control "Firmware Version". Signed-off-by: Geoffrey D. Bennett <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent f3c42a2 commit 701949c

File tree

1 file changed

+59
-3
lines changed

1 file changed

+59
-3
lines changed

sound/usb/mixer_scarlett2.c

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ struct scarlett2_data {
406406
__u8 bInterval;
407407
int num_mux_srcs;
408408
int num_mux_dsts;
409+
u32 firmware_version;
409410
u16 scarlett2_seq;
410411
u8 sync_updated;
411412
u8 vol_updated;
@@ -1856,6 +1857,44 @@ static int scarlett2_add_new_ctl(struct usb_mixer_interface *mixer,
18561857
return 0;
18571858
}
18581859

1860+
/*** Firmware Version Control ***/
1861+
1862+
static int scarlett2_firmware_version_ctl_get(
1863+
struct snd_kcontrol *kctl,
1864+
struct snd_ctl_elem_value *ucontrol)
1865+
{
1866+
struct usb_mixer_elem_info *elem = kctl->private_data;
1867+
struct scarlett2_data *private = elem->head.mixer->private_data;
1868+
1869+
ucontrol->value.integer.value[0] = private->firmware_version;
1870+
1871+
return 0;
1872+
}
1873+
1874+
static int scarlett2_firmware_version_ctl_info(
1875+
struct snd_kcontrol *kctl,
1876+
struct snd_ctl_elem_info *uinfo)
1877+
{
1878+
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1879+
uinfo->count = 1;
1880+
1881+
return 0;
1882+
}
1883+
1884+
static const struct snd_kcontrol_new scarlett2_firmware_version_ctl = {
1885+
.iface = SNDRV_CTL_ELEM_IFACE_CARD,
1886+
.access = SNDRV_CTL_ELEM_ACCESS_READ,
1887+
.name = "",
1888+
.info = scarlett2_firmware_version_ctl_info,
1889+
.get = scarlett2_firmware_version_ctl_get
1890+
};
1891+
1892+
static int scarlett2_add_firmware_version_ctl(
1893+
struct usb_mixer_interface *mixer)
1894+
{
1895+
return scarlett2_add_new_ctl(mixer, &scarlett2_firmware_version_ctl,
1896+
0, 0, "Firmware Version", NULL);
1897+
}
18591898
/*** Sync Control ***/
18601899

18611900
/* Update sync control after receiving notification that the status
@@ -3854,15 +3893,17 @@ static int scarlett2_usb_init(struct usb_mixer_interface *mixer)
38543893
{
38553894
struct usb_device *dev = mixer->chip->dev;
38563895
struct scarlett2_data *private = mixer->private_data;
3857-
u8 buf[24];
3896+
u8 step0_buf[24];
3897+
u8 step2_buf[84];
38583898
int err;
38593899

38603900
if (usb_pipe_type_check(dev, usb_sndctrlpipe(dev, 0)))
38613901
return -EINVAL;
38623902

38633903
/* step 0 */
38643904
err = scarlett2_usb_rx(dev, private->bInterfaceNumber,
3865-
SCARLETT2_USB_CMD_INIT, buf, sizeof(buf));
3905+
SCARLETT2_USB_CMD_INIT,
3906+
step0_buf, sizeof(step0_buf));
38663907
if (err < 0)
38673908
return err;
38683909

@@ -3874,7 +3915,19 @@ static int scarlett2_usb_init(struct usb_mixer_interface *mixer)
38743915

38753916
/* step 2 */
38763917
private->scarlett2_seq = 1;
3877-
return scarlett2_usb(mixer, SCARLETT2_USB_INIT_2, NULL, 0, NULL, 84);
3918+
err = scarlett2_usb(mixer, SCARLETT2_USB_INIT_2,
3919+
NULL, 0,
3920+
step2_buf, sizeof(step2_buf));
3921+
if (err < 0)
3922+
return err;
3923+
3924+
/* extract 4-byte firmware version from step2_buf[8] */
3925+
private->firmware_version = le32_to_cpu(*(__le32 *)(step2_buf + 8));
3926+
usb_audio_info(mixer->chip,
3927+
"Firmware version %d\n",
3928+
private->firmware_version);
3929+
3930+
return 0;
38783931
}
38793932

38803933
/* Read configuration from the interface on start */
@@ -4192,6 +4245,9 @@ static int snd_scarlett2_controls_create(
41924245
if (err < 0)
41934246
return err;
41944247

4248+
/* Add firmware version control */
4249+
err = scarlett2_add_firmware_version_ctl(mixer);
4250+
41954251
/* Read volume levels and controls from the interface */
41964252
err = scarlett2_read_configs(mixer);
41974253
if (err < 0)

0 commit comments

Comments
 (0)