linux/sound/usb/mixer_s1810c.c

// SPDX-License-Identifier: GPL-2.0
/*
 * Presonus Studio 1810c driver for ALSA
 * Copyright (C) 2019 Nick Kossifidis <[email protected]>
 *
 * Based on reverse engineering of the communication protocol
 * between the windows driver / Univeral Control (UC) program
 * and the device, through usbmon.
 *
 * For now this bypasses the mixer, with all channels split,
 * so that the software can mix with greater flexibility.
 * It also adds controls for the 4 buttons on the front of
 * the device.
 */

#include <linux/usb.h>
#include <linux/usb/audio-v2.h>
#include <linux/slab.h>
#include <sound/core.h>
#include <sound/control.h>

#include "usbaudio.h"
#include "mixer.h"
#include "mixer_quirks.h"
#include "helper.h"
#include "mixer_s1810c.h"

#define SC1810C_CMD_REQ
#define SC1810C_CMD_REQTYPE
#define SC1810C_CMD_F1
#define SC1810C_CMD_F2

/*
 * DISCLAIMER: These are just guesses based on the
 * dumps I got.
 *
 * It seems like a selects between
 * device (0), mixer (0x64) and output (0x65)
 *
 * For mixer (0x64):
 *  * b selects an input channel (see below).
 *  * c selects an output channel pair (see below).
 *  * d selects left (0) or right (1) of that pair.
 *  * e 0-> disconnect, 0x01000000-> connect,
 *	0x0109-> used for stereo-linking channels,
 *	e is also used for setting volume levels
 *	in which case b is also set so I guess
 *	this way it is possible to set the volume
 *	level from the specified input to the
 *	specified output.
 *
 * IN Channels:
 * 0  - 7  Mic/Inst/Line (Analog inputs)
 * 8  - 9  S/PDIF
 * 10 - 17 ADAT
 * 18 - 35 DAW (Inputs from the host)
 *
 * OUT Channels (pairs):
 * 0 -> Main out
 * 1 -> Line1/2
 * 2 -> Line3/4
 * 3 -> S/PDIF
 * 4 -> ADAT?
 *
 * For device (0):
 *  * b and c are not used, at least not on the
 *    dumps I got.
 *  * d sets the control id to be modified
 *    (see below).
 *  * e sets the setting for that control.
 *    (so for the switches I was interested
 *    in it's 0/1)
 *
 * For output (0x65):
 *   * b is the output channel (see above).
 *   * c is zero.
 *   * e I guess the same as with mixer except 0x0109
 *	 which I didn't see in my dumps.
 *
 * The two fixed fields have the same values for
 * mixer and output but a different set for device.
 */
struct s1810c_ctl_packet {};

#define SC1810C_CTL_LINE_SW
#define SC1810C_CTL_MUTE_SW
#define SC1810C_CTL_AB_SW
#define SC1810C_CTL_48V_SW

#define SC1810C_SET_STATE_REQ
#define SC1810C_SET_STATE_REQTYPE
#define SC1810C_SET_STATE_F1
#define SC1810C_SET_STATE_F2

#define SC1810C_GET_STATE_REQ
#define SC1810C_GET_STATE_REQTYPE
#define SC1810C_GET_STATE_F1
#define SC1810C_GET_STATE_F2

#define SC1810C_STATE_F1_IDX
#define SC1810C_STATE_F2_IDX

/*
 * This packet includes mixer volumes and
 * various other fields, it's an extended
 * version of ctl_packet, with a and b
 * being zero and different f1/f2.
 */
struct s1810c_state_packet {};

#define SC1810C_STATE_48V_SW
#define SC1810C_STATE_LINE_SW
#define SC1810C_STATE_MUTE_SW
#define SC1810C_STATE_AB_SW

struct s1810_mixer_state {};

static int
snd_s1810c_send_ctl_packet(struct usb_device *dev, u32 a,
			   u32 b, u32 c, u32 d, u32 e)
{}

/*
 * When opening Universal Control the program periodically
 * sends and receives state packets for syncinc state between
 * the device and the host.
 *
 * Note that if we send only the request to get data back we'll
 * get an error, we need to first send an empty state packet and
 * then ask to receive a filled. Their seqnumbers must also match.
 */
static int
snd_sc1810c_get_status_field(struct usb_device *dev,
			     u32 *field, int field_idx, uint16_t *seqnum)
{}

/*
 * This is what I got when bypassing the mixer with
 * all channels split. I'm not 100% sure of what's going
 * on, I could probably clean this up based on my observations
 * but I prefer to keep the same behavior as the windows driver.
 */
static int snd_s1810c_init_mixer_maps(struct snd_usb_audio *chip)
{}

/*
 * Sync state with the device and retrieve the requested field,
 * whose index is specified in (kctl->private_value & 0xFF),
 * from the received fields array.
 */
static int
snd_s1810c_get_switch_state(struct usb_mixer_interface *mixer,
			    struct snd_kcontrol *kctl, u32 *state)
{}

/*
 * Send a control packet to the device for the control id
 * specified in (kctl->private_value >> 8) with value
 * specified in (kctl->private_value >> 16).
 */
static int
snd_s1810c_set_switch_state(struct usb_mixer_interface *mixer,
			    struct snd_kcontrol *kctl)
{}

/* Generic get/set/init functions for switch controls */

static int
snd_s1810c_switch_get(struct snd_kcontrol *kctl,
		      struct snd_ctl_elem_value *ctl_elem)
{}

static int
snd_s1810c_switch_set(struct snd_kcontrol *kctl,
		      struct snd_ctl_elem_value *ctl_elem)
{}

static int
snd_s1810c_switch_init(struct usb_mixer_interface *mixer,
		       const struct snd_kcontrol_new *new_kctl)
{}

static int
snd_s1810c_line_sw_info(struct snd_kcontrol *kctl,
			struct snd_ctl_elem_info *uinfo)
{}

static const struct snd_kcontrol_new snd_s1810c_line_sw =;

static const struct snd_kcontrol_new snd_s1810c_mute_sw =;

static const struct snd_kcontrol_new snd_s1810c_48v_sw =;

static int
snd_s1810c_ab_sw_info(struct snd_kcontrol *kctl,
		      struct snd_ctl_elem_info *uinfo)
{}

static const struct snd_kcontrol_new snd_s1810c_ab_sw =;

static void snd_sc1810_mixer_state_free(struct usb_mixer_interface *mixer)
{}

/* Entry point, called from mixer_quirks.c */
int snd_sc1810_init_mixer(struct usb_mixer_interface *mixer)
{}