^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Presonus Studio 1810c driver for ALSA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2019 Nick Kossifidis <mickflemm@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Based on reverse engineering of the communication protocol
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * between the windows driver / Univeral Control (UC) program
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * and the device, through usbmon.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * For now this bypasses the mixer, with all channels split,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * so that the software can mix with greater flexibility.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * It also adds controls for the 4 buttons on the front of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/usb/audio-v2.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <sound/control.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include "usbaudio.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include "mixer.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include "mixer_quirks.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include "helper.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include "mixer_s1810c.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define SC1810C_CMD_REQ 160
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define SC1810C_CMD_REQTYPE \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) (USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define SC1810C_CMD_F1 0x50617269
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define SC1810C_CMD_F2 0x14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * DISCLAIMER: These are just guesses based on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * dumps I got.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * It seems like a selects between
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * device (0), mixer (0x64) and output (0x65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * For mixer (0x64):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * * b selects an input channel (see below).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * * c selects an output channel pair (see below).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * * d selects left (0) or right (1) of that pair.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * * e 0-> disconnect, 0x01000000-> connect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * 0x0109-> used for stereo-linking channels,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * e is also used for setting volume levels
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * in which case b is also set so I guess
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * this way it is possible to set the volume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * level from the specified input to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * specified output.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * IN Channels:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * 0 - 7 Mic/Inst/Line (Analog inputs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * 8 - 9 S/PDIF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * 10 - 17 ADAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * 18 - 35 DAW (Inputs from the host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * OUT Channels (pairs):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * 0 -> Main out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * 1 -> Line1/2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * 2 -> Line3/4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * 3 -> S/PDIF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * 4 -> ADAT?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * For device (0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * * b and c are not used, at least not on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * dumps I got.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * * d sets the control id to be modified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * (see below).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * * e sets the setting for that control.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * (so for the switches I was interested
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * in it's 0/1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * For output (0x65):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * * b is the output channel (see above).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * * c is zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * * e I guess the same as with mixer except 0x0109
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * which I didn't see in my dumps.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * The two fixed fields have the same values for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * mixer and output but a different set for device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct s1810c_ctl_packet {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) u32 a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) u32 b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) u32 fixed1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) u32 fixed2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) u32 c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) u32 d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) u32 e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) #define SC1810C_CTL_LINE_SW 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) #define SC1810C_CTL_MUTE_SW 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) #define SC1810C_CTL_AB_SW 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) #define SC1810C_CTL_48V_SW 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) #define SC1810C_SET_STATE_REQ 161
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #define SC1810C_SET_STATE_REQTYPE SC1810C_CMD_REQTYPE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #define SC1810C_SET_STATE_F1 0x64656D73
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #define SC1810C_SET_STATE_F2 0xF4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #define SC1810C_GET_STATE_REQ 162
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) #define SC1810C_GET_STATE_REQTYPE \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) (USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #define SC1810C_GET_STATE_F1 SC1810C_SET_STATE_F1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) #define SC1810C_GET_STATE_F2 SC1810C_SET_STATE_F2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) #define SC1810C_STATE_F1_IDX 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #define SC1810C_STATE_F2_IDX 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * This packet includes mixer volumes and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * various other fields, it's an extended
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * version of ctl_packet, with a and b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * being zero and different f1/f2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct s1810c_state_packet {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) u32 fields[63];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) #define SC1810C_STATE_48V_SW 58
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) #define SC1810C_STATE_LINE_SW 59
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) #define SC1810C_STATE_MUTE_SW 60
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) #define SC1810C_STATE_AB_SW 62
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct s1810_mixer_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) uint16_t seqnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) struct mutex usb_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct mutex data_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) snd_s1810c_send_ctl_packet(struct usb_device *dev, u32 a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) u32 b, u32 c, u32 d, u32 e)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct s1810c_ctl_packet pkt = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) pkt.fixed1 = SC1810C_CMD_F1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) pkt.fixed2 = SC1810C_CMD_F2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) pkt.a = a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) pkt.b = b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) pkt.c = c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) pkt.d = d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) * Value for settings 0/1 for this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) * output channel is always 0 (probably because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * there is no ADAT output on 1810c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) pkt.e = (c == 4) ? 0 : e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) ret = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) SC1810C_CMD_REQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) SC1810C_CMD_REQTYPE, 0, 0, &pkt, sizeof(pkt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) dev_warn(&dev->dev, "could not send ctl packet\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * When opening Universal Control the program periodicaly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) * sends and receives state packets for syncinc state between
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * the device and the host.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * Note that if we send only the request to get data back we'll
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * get an error, we need to first send an empty state packet and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * then ask to receive a filled. Their seqnumbers must also match.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) snd_sc1810c_get_status_field(struct usb_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) u32 *field, int field_idx, uint16_t *seqnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct s1810c_state_packet pkt_out = { { 0 } };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) struct s1810c_state_packet pkt_in = { { 0 } };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) pkt_out.fields[SC1810C_STATE_F1_IDX] = SC1810C_SET_STATE_F1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) pkt_out.fields[SC1810C_STATE_F2_IDX] = SC1810C_SET_STATE_F2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) ret = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) SC1810C_SET_STATE_REQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) SC1810C_SET_STATE_REQTYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) (*seqnum), 0, &pkt_out, sizeof(pkt_out));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) dev_warn(&dev->dev, "could not send state packet (%d)\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) ret = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) SC1810C_GET_STATE_REQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) SC1810C_GET_STATE_REQTYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) (*seqnum), 0, &pkt_in, sizeof(pkt_in));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) dev_warn(&dev->dev, "could not get state field %u (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) field_idx, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) (*field) = pkt_in.fields[field_idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) (*seqnum)++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) * This is what I got when bypassing the mixer with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) * all channels split. I'm not 100% sure of what's going
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) * on, I could probably clean this up based on my observations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) * but I prefer to keep the same behavior as the windows driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) static int snd_s1810c_init_mixer_maps(struct snd_usb_audio *chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) u32 a, b, c, e, n, off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) struct usb_device *dev = chip->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) /* Set initial volume levels ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) a = 0x64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) e = 0xbc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) for (n = 0; n < 2; n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) off = n * 18;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) for (b = off, c = 0; b < 18 + off; b++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) /* This channel to all outputs ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) for (c = 0; c <= 8; c++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) snd_s1810c_send_ctl_packet(dev, a, b, c, 0, e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) snd_s1810c_send_ctl_packet(dev, a, b, c, 1, e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) /* This channel to main output (again) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) snd_s1810c_send_ctl_packet(dev, a, b, 0, 0, e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) snd_s1810c_send_ctl_packet(dev, a, b, 0, 1, e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * I noticed on UC that DAW channels have different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) * initial volumes, so this makes sense.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) e = 0xb53bf0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) /* Connect analog outputs ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) a = 0x65;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) e = 0x01000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) for (b = 1; b < 3; b++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) snd_s1810c_send_ctl_packet(dev, a, b, 0, 0, e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) snd_s1810c_send_ctl_packet(dev, a, b, 0, 1, e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) snd_s1810c_send_ctl_packet(dev, a, 0, 0, 0, e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) snd_s1810c_send_ctl_packet(dev, a, 0, 0, 1, e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) /* Set initial volume levels for S/PDIF mappings ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) a = 0x64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) e = 0xbc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) c = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) for (n = 0; n < 2; n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) off = n * 18;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) for (b = off; b < 18 + off; b++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) snd_s1810c_send_ctl_packet(dev, a, b, c, 0, e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) snd_s1810c_send_ctl_packet(dev, a, b, c, 1, e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) e = 0xb53bf0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) /* Connect S/PDIF output ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) a = 0x65;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) e = 0x01000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) snd_s1810c_send_ctl_packet(dev, a, 3, 0, 0, e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) snd_s1810c_send_ctl_packet(dev, a, 3, 0, 1, e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) /* Connect all outputs (again) ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) a = 0x65;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) e = 0x01000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) for (b = 0; b < 4; b++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) snd_s1810c_send_ctl_packet(dev, a, b, 0, 0, e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) snd_s1810c_send_ctl_packet(dev, a, b, 0, 1, e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) /* Basic routing to get sound out of the device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) a = 0x64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) e = 0x01000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) for (c = 0; c < 4; c++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) for (b = 0; b < 36; b++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) if ((c == 0 && b == 18) || /* DAW1/2 -> Main */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) (c == 1 && b == 20) || /* DAW3/4 -> Line3/4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) (c == 2 && b == 22) || /* DAW4/5 -> Line5/6 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) (c == 3 && b == 24)) { /* DAW5/6 -> S/PDIF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) /* Left */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) snd_s1810c_send_ctl_packet(dev, a, b, c, 0, e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) snd_s1810c_send_ctl_packet(dev, a, b, c, 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) b++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) /* Right */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) snd_s1810c_send_ctl_packet(dev, a, b, c, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) snd_s1810c_send_ctl_packet(dev, a, b, c, 1, e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) /* Leave the rest disconnected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) snd_s1810c_send_ctl_packet(dev, a, b, c, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) snd_s1810c_send_ctl_packet(dev, a, b, c, 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) /* Set initial volume levels for S/PDIF (again) ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) a = 0x64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) e = 0xbc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) c = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) for (n = 0; n < 2; n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) off = n * 18;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) for (b = off; b < 18 + off; b++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) snd_s1810c_send_ctl_packet(dev, a, b, c, 0, e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) snd_s1810c_send_ctl_packet(dev, a, b, c, 1, e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) e = 0xb53bf0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) /* Connect S/PDIF outputs (again) ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) a = 0x65;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) e = 0x01000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) snd_s1810c_send_ctl_packet(dev, a, 3, 0, 0, e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) snd_s1810c_send_ctl_packet(dev, a, 3, 0, 1, e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) /* Again ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) snd_s1810c_send_ctl_packet(dev, a, 3, 0, 0, e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) snd_s1810c_send_ctl_packet(dev, a, 3, 0, 1, e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) * Sync state with the device and retrieve the requested field,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) * whose index is specified in (kctl->private_value & 0xFF),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) * from the received fields array.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) snd_s1810c_get_switch_state(struct usb_mixer_interface *mixer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) struct snd_kcontrol *kctl, u32 *state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) struct snd_usb_audio *chip = mixer->chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) struct s1810_mixer_state *private = mixer->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) u32 field = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) u32 ctl_idx = (u32) (kctl->private_value & 0xFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) mutex_lock(&private->usb_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) ret = snd_sc1810c_get_status_field(chip->dev, &field,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) ctl_idx, &private->seqnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) *state = field;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) mutex_unlock(&private->usb_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) return ret ? ret : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) * Send a control packet to the device for the control id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) * specified in (kctl->private_value >> 8) with value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) * specified in (kctl->private_value >> 16).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) snd_s1810c_set_switch_state(struct usb_mixer_interface *mixer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) struct snd_kcontrol *kctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) struct snd_usb_audio *chip = mixer->chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) struct s1810_mixer_state *private = mixer->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) u32 pval = (u32) kctl->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) u32 ctl_id = (pval >> 8) & 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) u32 ctl_val = (pval >> 16) & 0x1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) mutex_lock(&private->usb_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) ret = snd_s1810c_send_ctl_packet(chip->dev, 0, 0, 0, ctl_id, ctl_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) mutex_unlock(&private->usb_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) /* Generic get/set/init functions for switch controls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) snd_s1810c_switch_get(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) struct snd_ctl_elem_value *ctl_elem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) struct usb_mixer_interface *mixer = list->mixer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) struct s1810_mixer_state *private = mixer->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) u32 pval = (u32) kctl->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) u32 ctl_idx = pval & 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) u32 state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) mutex_lock(&private->data_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) ret = snd_s1810c_get_switch_state(mixer, kctl, &state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) switch (ctl_idx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) case SC1810C_STATE_LINE_SW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) case SC1810C_STATE_AB_SW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) ctl_elem->value.enumerated.item[0] = (int)state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) ctl_elem->value.integer.value[0] = (long)state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) mutex_unlock(&private->data_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) return (ret < 0) ? ret : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) snd_s1810c_switch_set(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) struct snd_ctl_elem_value *ctl_elem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) struct usb_mixer_interface *mixer = list->mixer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) struct s1810_mixer_state *private = mixer->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) u32 pval = (u32) kctl->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) u32 ctl_idx = pval & 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) u32 curval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) u32 newval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) mutex_lock(&private->data_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) ret = snd_s1810c_get_switch_state(mixer, kctl, &curval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) switch (ctl_idx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) case SC1810C_STATE_LINE_SW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) case SC1810C_STATE_AB_SW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) newval = (u32) ctl_elem->value.enumerated.item[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) newval = (u32) ctl_elem->value.integer.value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) if (curval == newval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) kctl->private_value &= ~(0x1 << 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) kctl->private_value |= (unsigned int)(newval & 0x1) << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) ret = snd_s1810c_set_switch_state(mixer, kctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) mutex_unlock(&private->data_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) return (ret < 0) ? 0 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) snd_s1810c_switch_init(struct usb_mixer_interface *mixer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) const struct snd_kcontrol_new *new_kctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) struct snd_kcontrol *kctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) struct usb_mixer_elem_info *elem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) elem = kzalloc(sizeof(struct usb_mixer_elem_info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) if (!elem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) elem->head.mixer = mixer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) elem->control = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) elem->head.id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) elem->channels = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) kctl = snd_ctl_new1(new_kctl, elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) if (!kctl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) kfree(elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) kctl->private_free = snd_usb_mixer_elem_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) return snd_usb_mixer_add_control(&elem->head, kctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) snd_s1810c_line_sw_info(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) static const char *const texts[2] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) "Preamp On (Mic/Inst)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) "Preamp Off (Line in)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) static const struct snd_kcontrol_new snd_s1810c_line_sw = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) .name = "Line 1/2 Source Type",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) .info = snd_s1810c_line_sw_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) .get = snd_s1810c_switch_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) .put = snd_s1810c_switch_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) .private_value = (SC1810C_STATE_LINE_SW | SC1810C_CTL_LINE_SW << 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) static const struct snd_kcontrol_new snd_s1810c_mute_sw = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) .name = "Mute Main Out Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) .info = snd_ctl_boolean_mono_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) .get = snd_s1810c_switch_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) .put = snd_s1810c_switch_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) .private_value = (SC1810C_STATE_MUTE_SW | SC1810C_CTL_MUTE_SW << 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) static const struct snd_kcontrol_new snd_s1810c_48v_sw = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) .name = "48V Phantom Power On Mic Inputs Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) .info = snd_ctl_boolean_mono_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) .get = snd_s1810c_switch_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) .put = snd_s1810c_switch_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) .private_value = (SC1810C_STATE_48V_SW | SC1810C_CTL_48V_SW << 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) snd_s1810c_ab_sw_info(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) static const char *const texts[2] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) "1/2",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) "3/4"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) static const struct snd_kcontrol_new snd_s1810c_ab_sw = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) .name = "Headphone 1 Source Route",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) .info = snd_s1810c_ab_sw_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) .get = snd_s1810c_switch_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) .put = snd_s1810c_switch_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) .private_value = (SC1810C_STATE_AB_SW | SC1810C_CTL_AB_SW << 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) static void snd_sc1810_mixer_state_free(struct usb_mixer_interface *mixer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) struct s1810_mixer_state *private = mixer->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) kfree(private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) mixer->private_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) /* Entry point, called from mixer_quirks.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) int snd_sc1810_init_mixer(struct usb_mixer_interface *mixer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) struct s1810_mixer_state *private = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) struct snd_usb_audio *chip = mixer->chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) struct usb_device *dev = chip->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) /* Run this only once */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) if (!list_empty(&chip->mixer_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) dev_info(&dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) "Presonus Studio 1810c, device_setup: %u\n", chip->setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) if (chip->setup == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) dev_info(&dev->dev, "(8out/18in @ 48kHz)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) else if (chip->setup == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) dev_info(&dev->dev, "(6out/8in @ 192kHz)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) dev_info(&dev->dev, "(8out/14in @ 96kHz)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) ret = snd_s1810c_init_mixer_maps(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) private = kzalloc(sizeof(struct s1810_mixer_state), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) if (!private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) mutex_init(&private->usb_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) mutex_init(&private->data_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) mixer->private_data = private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) mixer->private_free = snd_sc1810_mixer_state_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) private->seqnum = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) ret = snd_s1810c_switch_init(mixer, &snd_s1810c_line_sw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) ret = snd_s1810c_switch_init(mixer, &snd_s1810c_mute_sw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) ret = snd_s1810c_switch_init(mixer, &snd_s1810c_48v_sw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) ret = snd_s1810c_switch_init(mixer, &snd_s1810c_ab_sw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) }