Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Linux driver for TerraTec DMX 6Fire USB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Mixer control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Author:	Torsten Schenk <torsten.schenk@zoho.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Created:	Jan 01, 2011
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Copyright:	(C) Torsten Schenk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * Thanks to:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * - Holger Ruckdeschel: he found out how to control individual channel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *   volumes and introduced mute switch
^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/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <sound/control.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <sound/tlv.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include "control.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include "comm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include "chip.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static const char * const opt_coax_texts[2] = { "Optical", "Coax" };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) static const char * const line_phono_texts[2] = { "Line", "Phono" };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * data that needs to be sent to device. sets up card internal stuff.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * values dumped from windows driver and filtered by trial'n'error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) static const struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	u8 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	u8 reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	u8 value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) init_data[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	{ 0x22, 0x00, 0x00 }, { 0x20, 0x00, 0x08 }, { 0x22, 0x01, 0x01 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	{ 0x20, 0x01, 0x08 }, { 0x22, 0x02, 0x00 }, { 0x20, 0x02, 0x08 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	{ 0x22, 0x03, 0x00 }, { 0x20, 0x03, 0x08 }, { 0x22, 0x04, 0x00 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	{ 0x20, 0x04, 0x08 }, { 0x22, 0x05, 0x01 }, { 0x20, 0x05, 0x08 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	{ 0x22, 0x04, 0x01 }, { 0x12, 0x04, 0x00 }, { 0x12, 0x05, 0x00 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	{ 0x12, 0x0d, 0x38 }, { 0x12, 0x21, 0x82 }, { 0x12, 0x22, 0x80 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	{ 0x12, 0x23, 0x00 }, { 0x12, 0x06, 0x02 }, { 0x12, 0x03, 0x00 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	{ 0x12, 0x02, 0x00 }, { 0x22, 0x03, 0x01 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	{ 0 } /* TERMINATING ENTRY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) static const int rates_altsetting[] = { 1, 1, 2, 2, 3, 3 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) /* values to write to soundcard register for all samplerates */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) static const u16 rates_6fire_vl[] = {0x00, 0x01, 0x00, 0x01, 0x00, 0x01};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) static const u16 rates_6fire_vh[] = {0x11, 0x11, 0x10, 0x10, 0x00, 0x00};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) static DECLARE_TLV_DB_MINMAX(tlv_output, -9000, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) static DECLARE_TLV_DB_MINMAX(tlv_input, -1500, 1500);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	DIGITAL_THRU_ONLY_SAMPLERATE = 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) static void usb6fire_control_output_vol_update(struct control_runtime *rt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	struct comm_runtime *comm_rt = rt->chip->comm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	if (comm_rt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		for (i = 0; i < 6; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 			if (!(rt->ovol_updated & (1 << i))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 				comm_rt->write8(comm_rt, 0x12, 0x0f + i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 					180 - rt->output_vol[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 				rt->ovol_updated |= 1 << i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) static void usb6fire_control_output_mute_update(struct control_runtime *rt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	struct comm_runtime *comm_rt = rt->chip->comm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	if (comm_rt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		comm_rt->write8(comm_rt, 0x12, 0x0e, ~rt->output_mute);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) static void usb6fire_control_input_vol_update(struct control_runtime *rt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	struct comm_runtime *comm_rt = rt->chip->comm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	if (comm_rt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		for (i = 0; i < 2; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 			if (!(rt->ivol_updated & (1 << i))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 				comm_rt->write8(comm_rt, 0x12, 0x1c + i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 					rt->input_vol[i] & 0x3f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 				rt->ivol_updated |= 1 << i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) static void usb6fire_control_line_phono_update(struct control_runtime *rt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	struct comm_runtime *comm_rt = rt->chip->comm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	if (comm_rt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		comm_rt->write8(comm_rt, 0x22, 0x02, rt->line_phono_switch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		comm_rt->write8(comm_rt, 0x21, 0x02, rt->line_phono_switch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static void usb6fire_control_opt_coax_update(struct control_runtime *rt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	struct comm_runtime *comm_rt = rt->chip->comm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	if (comm_rt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		comm_rt->write8(comm_rt, 0x22, 0x00, rt->opt_coax_switch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		comm_rt->write8(comm_rt, 0x21, 0x00, rt->opt_coax_switch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	}
^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) static int usb6fire_control_set_rate(struct control_runtime *rt, int rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	struct usb_device *device = rt->chip->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	struct comm_runtime *comm_rt = rt->chip->comm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	if (rate < 0 || rate >= CONTROL_N_RATES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	ret = usb_set_interface(device, 1, rates_altsetting[rate]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	/* set soundcard clock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	ret = comm_rt->write16(comm_rt, 0x02, 0x01, rates_6fire_vl[rate],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 			rates_6fire_vh[rate]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static int usb6fire_control_set_channels(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	struct control_runtime *rt, int n_analog_out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	int n_analog_in, bool spdif_out, bool spdif_in)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	struct comm_runtime *comm_rt = rt->chip->comm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	/* enable analog inputs and outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	 * (one bit per stereo-channel) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	ret = comm_rt->write16(comm_rt, 0x02, 0x02,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 			(1 << (n_analog_out / 2)) - 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			(1 << (n_analog_in / 2)) - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	/* disable digital inputs and outputs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	/* TODO: use spdif_x to enable/disable digital channels */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	ret = comm_rt->write16(comm_rt, 0x02, 0x03, 0x00, 0x00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) static int usb6fire_control_streaming_update(struct control_runtime *rt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	struct comm_runtime *comm_rt = rt->chip->comm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	if (comm_rt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		if (!rt->usb_streaming && rt->digital_thru_switch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 			usb6fire_control_set_rate(rt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 				DIGITAL_THRU_ONLY_SAMPLERATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		return comm_rt->write16(comm_rt, 0x02, 0x00, 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 			(rt->usb_streaming ? 0x01 : 0x00) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			(rt->digital_thru_switch ? 0x08 : 0x00));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) static int usb6fire_control_output_vol_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	uinfo->count = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	uinfo->value.integer.min = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	uinfo->value.integer.max = 180;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static int usb6fire_control_output_vol_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	unsigned int ch = kcontrol->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	int changed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	if (ch > 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		dev_err(&rt->chip->dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			"Invalid channel in volume control.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	if (rt->output_vol[ch] != ucontrol->value.integer.value[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		rt->output_vol[ch] = ucontrol->value.integer.value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		rt->ovol_updated &= ~(1 << ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		changed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	if (rt->output_vol[ch + 1] != ucontrol->value.integer.value[1]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		rt->output_vol[ch + 1] = ucontrol->value.integer.value[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		rt->ovol_updated &= ~(2 << ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		changed = 1;
^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) 	if (changed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		usb6fire_control_output_vol_update(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	return changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) static int usb6fire_control_output_vol_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	unsigned int ch = kcontrol->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	if (ch > 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		dev_err(&rt->chip->dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 			"Invalid channel in volume control.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	ucontrol->value.integer.value[0] = rt->output_vol[ch];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	ucontrol->value.integer.value[1] = rt->output_vol[ch + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) static int usb6fire_control_output_mute_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	unsigned int ch = kcontrol->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	u8 old = rt->output_mute;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	u8 value = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	if (ch > 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		dev_err(&rt->chip->dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 			"Invalid channel in volume control.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	rt->output_mute &= ~(3 << ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	if (ucontrol->value.integer.value[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		value |= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	if (ucontrol->value.integer.value[1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		value |= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	rt->output_mute |= value << ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	if (rt->output_mute != old)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		usb6fire_control_output_mute_update(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	return rt->output_mute != old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) static int usb6fire_control_output_mute_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	unsigned int ch = kcontrol->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	u8 value = rt->output_mute >> ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	if (ch > 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		dev_err(&rt->chip->dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 			"Invalid channel in volume control.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	ucontrol->value.integer.value[0] = 1 & value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	value >>= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	ucontrol->value.integer.value[1] = 1 & value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) static int usb6fire_control_input_vol_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	uinfo->count = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	uinfo->value.integer.min = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	uinfo->value.integer.max = 30;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) static int usb6fire_control_input_vol_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	int changed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	if (rt->input_vol[0] != ucontrol->value.integer.value[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		rt->input_vol[0] = ucontrol->value.integer.value[0] - 15;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		rt->ivol_updated &= ~(1 << 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		changed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	if (rt->input_vol[1] != ucontrol->value.integer.value[1]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		rt->input_vol[1] = ucontrol->value.integer.value[1] - 15;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		rt->ivol_updated &= ~(1 << 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		changed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	if (changed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		usb6fire_control_input_vol_update(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	return changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) static int usb6fire_control_input_vol_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	ucontrol->value.integer.value[0] = rt->input_vol[0] + 15;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	ucontrol->value.integer.value[1] = rt->input_vol[1] + 15;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) static int usb6fire_control_line_phono_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	return snd_ctl_enum_info(uinfo, 1, 2, line_phono_texts);
^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) static int usb6fire_control_line_phono_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	int changed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	if (rt->line_phono_switch != ucontrol->value.integer.value[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		rt->line_phono_switch = ucontrol->value.integer.value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		usb6fire_control_line_phono_update(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		changed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	return changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) static int usb6fire_control_line_phono_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	ucontrol->value.integer.value[0] = rt->line_phono_switch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) static int usb6fire_control_opt_coax_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	return snd_ctl_enum_info(uinfo, 1, 2, opt_coax_texts);
^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) static int usb6fire_control_opt_coax_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	int changed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	if (rt->opt_coax_switch != ucontrol->value.enumerated.item[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		rt->opt_coax_switch = ucontrol->value.enumerated.item[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		usb6fire_control_opt_coax_update(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		changed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	return changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) static int usb6fire_control_opt_coax_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	ucontrol->value.enumerated.item[0] = rt->opt_coax_switch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) static int usb6fire_control_digital_thru_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 		struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	int changed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	if (rt->digital_thru_switch != ucontrol->value.integer.value[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		rt->digital_thru_switch = ucontrol->value.integer.value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 		usb6fire_control_streaming_update(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 		changed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	return changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) static int usb6fire_control_digital_thru_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	struct control_runtime *rt = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	ucontrol->value.integer.value[0] = rt->digital_thru_switch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) static const struct snd_kcontrol_new vol_elements[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		.name = "Analog Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		.index = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		.private_value = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 			SNDRV_CTL_ELEM_ACCESS_TLV_READ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		.info = usb6fire_control_output_vol_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 		.get = usb6fire_control_output_vol_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		.put = usb6fire_control_output_vol_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		.tlv = { .p = tlv_output }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		.name = "Analog Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		.index = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		.private_value = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 			SNDRV_CTL_ELEM_ACCESS_TLV_READ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		.info = usb6fire_control_output_vol_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 		.get = usb6fire_control_output_vol_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		.put = usb6fire_control_output_vol_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		.tlv = { .p = tlv_output }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 		.name = "Analog Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 		.index = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 		.private_value = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 			SNDRV_CTL_ELEM_ACCESS_TLV_READ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		.info = usb6fire_control_output_vol_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 		.get = usb6fire_control_output_vol_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 		.put = usb6fire_control_output_vol_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 		.tlv = { .p = tlv_output }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	{}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) static const struct snd_kcontrol_new mute_elements[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		.name = "Analog Playback Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 		.index = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		.private_value = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 		.info = snd_ctl_boolean_stereo_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 		.get = usb6fire_control_output_mute_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 		.put = usb6fire_control_output_mute_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 		.name = "Analog Playback Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 		.index = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 		.private_value = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 		.info = snd_ctl_boolean_stereo_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 		.get = usb6fire_control_output_mute_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 		.put = usb6fire_control_output_mute_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 		.name = "Analog Playback Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		.index = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 		.private_value = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 		.info = snd_ctl_boolean_stereo_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 		.get = usb6fire_control_output_mute_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 		.put = usb6fire_control_output_mute_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	{}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) static const struct snd_kcontrol_new elements[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		.name = "Line/Phono Capture Route",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		.index = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 		.info = usb6fire_control_line_phono_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 		.get = usb6fire_control_line_phono_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 		.put = usb6fire_control_line_phono_put
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 		.name = "Opt/Coax Capture Route",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 		.index = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 		.info = usb6fire_control_opt_coax_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 		.get = usb6fire_control_opt_coax_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 		.put = usb6fire_control_opt_coax_put
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 		.name = "Digital Thru Playback Route",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 		.index = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 		.info = snd_ctl_boolean_mono_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 		.get = usb6fire_control_digital_thru_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 		.put = usb6fire_control_digital_thru_put
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 		.name = "Analog Capture Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 		.index = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 			SNDRV_CTL_ELEM_ACCESS_TLV_READ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 		.info = usb6fire_control_input_vol_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 		.get = usb6fire_control_input_vol_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 		.put = usb6fire_control_input_vol_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 		.tlv = { .p = tlv_input }
^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) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) static int usb6fire_control_add_virtual(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	struct control_runtime *rt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	struct snd_card *card,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	const struct snd_kcontrol_new *elems)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	struct snd_kcontrol *vmaster =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 		snd_ctl_make_virtual_master(name, tlv_output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	struct snd_kcontrol *control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	if (!vmaster)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	ret = snd_ctl_add(card, vmaster);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	while (elems[i].name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 		control = snd_ctl_new1(&elems[i], rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 		if (!control)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 		ret = snd_ctl_add(card, control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 		if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 		ret = snd_ctl_add_follower(vmaster, control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 		if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 		i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) int usb6fire_control_init(struct sfire_chip *chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	struct control_runtime *rt = kzalloc(sizeof(struct control_runtime),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 			GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	struct comm_runtime *comm_rt = chip->comm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	if (!rt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	rt->chip = chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	rt->update_streaming = usb6fire_control_streaming_update;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	rt->set_rate = usb6fire_control_set_rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	rt->set_channels = usb6fire_control_set_channels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	while (init_data[i].type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 		comm_rt->write8(comm_rt, init_data[i].type, init_data[i].reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 				init_data[i].value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 		i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 	usb6fire_control_opt_coax_update(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	usb6fire_control_line_phono_update(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	usb6fire_control_output_vol_update(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	usb6fire_control_output_mute_update(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	usb6fire_control_input_vol_update(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	usb6fire_control_streaming_update(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	ret = usb6fire_control_add_virtual(rt, chip->card,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 		"Master Playback Volume", vol_elements);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 		dev_err(&chip->dev->dev, "cannot add control.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 		kfree(rt);
^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 = usb6fire_control_add_virtual(rt, chip->card,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 		"Master Playback Switch", mute_elements);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 		dev_err(&chip->dev->dev, "cannot add control.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 		kfree(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 	i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 	while (elements[i].name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 		ret = snd_ctl_add(chip->card, snd_ctl_new1(&elements[i], rt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 		if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 			kfree(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 			dev_err(&chip->dev->dev, "cannot add control.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 		i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	chip->control = rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) void usb6fire_control_abort(struct sfire_chip *chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) void usb6fire_control_destroy(struct sfire_chip *chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 	kfree(chip->control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	chip->control = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) }