Skip to contentSkip to conversation

ALSA: hda/tas2781: Add tas2781 HDA driver

PATCH Superseded Shenghao Ding 2 participants 3 messages Aug 17, 2023 Sound

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/2 ALSA: hda/tas2781: Add tas2781 HDA driver

Create tas2781 side codec HDA driver for Lenovo Laptops. The quantity of the speakers has been define in ACPI. All of the tas2781s in the laptop will be aggregated as one audio speaker. The code supports realtek codec as the primary codec. Code offers several controls for digtial/analog gain setting during playback, and other for eq params setting in case of different audio profiles, such as music, voice, movie, etc.

---
Changes in v3:
- oprimize the indentation
- fix the ambiguous error message
- The check of the given value to kcontrol's put func is in the sound/tas2781-comlib.c
- In tasdevice_info_programs, corrected max value
- Seperate snd_kcontrol_new tas2781_dsp_controls into two standalone kcontrol.
- All the controls set as const static
- Add static for page_array & rgno_array
- Remove uncessary blank lines
- Add descriptions for tas2781_save_calibration
- remove global addr handling in the code
- checking subid in switch statement in function tas2781_hda_bind
- add force firmware load Kcontrol
- rename the kcontrol name to be more undertandable
- remove Superfluous cast in tasdevice_fw_ready
- correct weird line break in function tas2781_acpi_get_i2c_resource
- correct Referencing adev after acpi_dev_put() in tas2781_hda_read_acpi
- As to checking the given value in tasdevice_set_profile_id, it seems done by the tasdevice_info_profile
- replace strcpy with strscpy in tas2781_hda_read_acpi
- rewrite the subid judgement
- Add [email protected] into Cc list
- remove the cast in tas2781_acpi_get_i2c_resource
- remove else in tas2781_acpi_get_i2c_resource
- fix the return value in tasdevice_set_profile_id
- remove unneeded NL in tasdevice_config_get
- Unifiy the comment style
- remove ret = 0 in tasdevice_fw_ready
- remove ret in tas2781_save_calibration
- remove unused ret in tas2781_hda_playback
- add force firmware load Kcontrol

---
 sound/pci/hda/Kconfig           |  15 +
 sound/pci/hda/Makefile          |   2 +
 sound/pci/hda/tas2781_hda_i2c.c | 858 ++++++++++++++++++++++++++++++++
 3 files changed, 875 insertions(+)
 create mode 100644 sound/pci/hda/tas2781_hda_i2c.c
sound/pci/hda/Kconfig +15 -0
index 886255a03e8b..e66257277492 100644
@@ -130,6 +130,21 @@ config SND_HDA_SCODEC_CS35L41_SPI
 comment "Set to Y if you want auto-loading the side codec driver"
 	depends on SND_HDA=y && SND_HDA_SCODEC_CS35L41_SPI=m
 
+config SND_HDA_SCODEC_TAS2781_I2C
+	tristate "Build TAS2781 HD-audio side codec support for I2C Bus"
+	depends on I2C
+	depends on ACPI
+	depends on SND_SOC
+	select SND_SOC_TAS2781_COMLIB
+	select SND_SOC_TAS2781_FMWLIB
+	select CRC32_SARWATE
+	help
+	  Say Y or M here to include TAS2781 I2C HD-audio side codec support
+	  in snd-hda-intel driver, such as ALC287.
+
+comment "Set to Y if you want auto-loading the side codec driver"
+	depends on SND_HDA=y && SND_HDA_SCODEC_TAS2781_I2C=m
+
 config SND_HDA_CODEC_REALTEK
 	tristate "Build Realtek HD-audio codec support"
 	select SND_HDA_GENERIC
sound/pci/hda/Makefile +2 -0
index 00d306104484..1c76609690d6 100644
@@ -32,6 +32,7 @@ snd-hda-scodec-cs35l41-objs :=		cs35l41_hda.o
 snd-hda-scodec-cs35l41-i2c-objs :=	cs35l41_hda_i2c.o
 snd-hda-scodec-cs35l41-spi-objs :=	cs35l41_hda_spi.o
 snd-hda-cs-dsp-ctls-objs :=		hda_cs_dsp_ctl.o
+snd-hda-scodec-tas2781-i2c-objs :=	tas2781_hda_i2c.o
 
 # common driver
 obj-$(CONFIG_SND_HDA) := snd-hda-codec.o
@@ -56,6 +57,7 @@ obj-$(CONFIG_SND_HDA_SCODEC_CS35L41) += snd-hda-scodec-cs35l41.o
 obj-$(CONFIG_SND_HDA_SCODEC_CS35L41_I2C) += snd-hda-scodec-cs35l41-i2c.o
 obj-$(CONFIG_SND_HDA_SCODEC_CS35L41_SPI) += snd-hda-scodec-cs35l41-spi.o
 obj-$(CONFIG_SND_HDA_CS_DSP_CONTROLS) += snd-hda-cs-dsp-ctls.o
+obj-$(CONFIG_SND_HDA_SCODEC_TAS2781_I2C) += snd-hda-scodec-tas2781-i2c.o
 
 # this must be the last entry after codec drivers;
 # otherwise the codec patches won't be hooked before the PCI probe
sound/pci/hda/tas2781_hda_i2c.c new file +858 -0

858 lines not on this page · raw message

Signature · 1 line
2.34.1
#1 lore raw

PATCH v3 2/2 ALSA: hda/tas2781: Add tas2781 HDA driver

Integrate tas2781 configs for Lenovo Laptops. All of the tas2781s in the laptop will be aggregated as one audio device. The code support realtek as the primary codec. Rename "struct cs35l41_dev_name" to "struct scodec_dev_name" for all other side codecs instead of the certain one.

---
Changes in v3:
- remove workaround code for 0x17aa38be, laptop vendor will fix it in acpi.
- rename comp_match_tas2781_dev_name to avoid indentation
- simplify the check of vendor id with Lenovo
- ThinkPad is one of Lenovo's brands, I was suggested me to use ALC269_FIXUP_THINKPAD_ACPI.
- Add comments on ACARD_SINGLE_RANGE_EXT_TLV
- Add the range check for tas_priv->tasdevice[] in tas2781_acpi_get_i2c_res.
- remove acpi_subsystem_id
- Issue in Laptop 0x17aa38be ACPI talbe caused codec->bus->pci->subsystem_device is not equal to (codec->core.subsystem_id & 0xffff) in snd_hda_pick_fixup. The former is 0x3802 and the latter is 0x38be leads to getting the wrong fixup_id and enter into the wrong entry. Although, this issue has been raised to the laptop manufacturer, but the ACPI table is locked, cannot be changed any more. Correct the wrong entry in the code.
- Rename "struct cs35l41_dev_name" to "struct scodec_dev_name" for all other side codecs instead of one certain codec.
- Ignore the checkpatch complaints in alc269_fixup_tbl
- Drop the hunk which is irrelevant with my code in alc_fixup_headset_mode_alc255_no_hp_mic
- Add [email protected] into Cc list
- remove useless index
- combine ALC287_FIXUP_TAS2781_I2C_2 and ALC287_FIXUP_TAS2781_I2C_4 together as ALC287_FIXUP_TAS2781_I2C, The code view all the tas2781s in the laptop as one instance.
- delete the white space at the end of the line in alc_fixup_headset_mode_alc255_no_hp_mic

---
 sound/pci/hda/patch_realtek.c | 88 +++++++++++++++++++++++++++++++++--
 1 file changed, 85 insertions(+), 3 deletions(-)
sound/pci/hda/patch_realtek.c +85 -3
index 44fccfb93cff..ba1b02ed184a 100644
@@ -6721,7 +6721,7 @@ static void comp_generic_playback_hook(struct hda_pcm_stream *hinfo, struct hda_
 	}
 }
 
-struct cs35l41_dev_name {
+struct scodec_dev_name {
 	const char *bus;
 	const char *hid;
 	int index;
@@ -6730,7 +6730,7 @@ struct cs35l41_dev_name {
 /* match the device name in a slightly relaxed manner */
 static int comp_match_cs35l41_dev_name(struct device *dev, void *data)
 {
-	struct cs35l41_dev_name *p = data;
+	struct scodec_dev_name *p = data;
 	const char *d = dev_name(dev);
 	int n = strlen(p->bus);
 	char tmp[32];
@@ -6746,12 +6746,32 @@ static int comp_match_cs35l41_dev_name(struct device *dev, void *data)
 	return !strcmp(d + n, tmp);
 }
 
+static int comp_match_tas2781_dev_name(struct device *dev,
+	void *data)
+{
+	struct scodec_dev_name *p = data;
+	const char *d = dev_name(dev);
+	int n = strlen(p->bus);
+	char tmp[32];
+
+	/* check the bus name */
+	if (strncmp(d, p->bus, n))
+		return 0;
+	/* skip the bus number */
+	if (isdigit(d[n]))
+		n++;
+	/* the rest must be exact matching */
+	snprintf(tmp, sizeof(tmp), "-%s:00", p->hid);
+
+	return !strcmp(d + n, tmp);
+}
+
 static void cs35l41_generic_fixup(struct hda_codec *cdc, int action, const char *bus,
 				  const char *hid, int count)
 {
 	struct device *dev = hda_codec_dev(cdc);
 	struct alc_spec *spec = cdc->spec;
-	struct cs35l41_dev_name *rec;
+	struct scodec_dev_name *rec;
 	int ret, i;
 
 	switch (action) {
@@ -6779,6 +6799,41 @@ static void cs35l41_generic_fixup(struct hda_codec *cdc, int action, const char
 	}
 }
 
+static void tas2781_generic_fixup(struct hda_codec *cdc, int action,
+	const char *bus, const char *hid)
+{
+	struct device *dev = hda_codec_dev(cdc);
+	struct alc_spec *spec = cdc->spec;
+	struct scodec_dev_name *rec;
+	int ret;
+
+	switch (action) {
+	case HDA_FIXUP_ACT_PRE_PROBE:
+		rec = devm_kmalloc(dev, sizeof(*rec), GFP_KERNEL);
+		if (!rec)
+			return;
+		rec->bus = bus;
+		rec->hid = hid;
+		rec->index = 0;
+		spec->comps[0].codec = cdc;
+		component_match_add(dev, &spec->match,
+			comp_match_tas2781_dev_name, rec);
+		ret = component_master_add_with_match(dev, &comp_master_ops,
+			spec->match);
+		if (ret)
+			codec_err(cdc,
+				"Fail to register component aggregator %d\n",
+				ret);
+		else
+			spec->gen.pcm_playback_hook =
+				comp_generic_playback_hook;
+		break;
+	case HDA_FIXUP_ACT_FREE:
+		component_master_del(dev, &comp_master_ops);
+		break;
+	}
+}
+
 static void cs35l41_fixup_i2c_two(struct hda_codec *cdc, const struct hda_fixup *fix, int action)
 {
 	cs35l41_generic_fixup(cdc, action, "i2c", "CSC3551", 2);
@@ -6806,6 +6861,12 @@ static void alc287_fixup_legion_16ithg6_speakers(struct hda_codec *cdc, const st
 	cs35l41_generic_fixup(cdc, action, "i2c", "CLSA0101", 2);
 }
 
+static void tas2781_fixup_i2c(struct hda_codec *cdc,
+	const struct hda_fixup *fix, int action)
+{
+	 tas2781_generic_fixup(cdc, action, "i2c", "TIAS2781");
+}
+
 /* for alc295_fixup_hp_top_speakers */
 #include "hp_x360_helper.c"
 
@@ -7231,6 +7292,7 @@ enum {
 	ALC295_FIXUP_DELL_INSPIRON_TOP_SPEAKERS,
 	ALC236_FIXUP_DELL_DUAL_CODECS,
 	ALC287_FIXUP_CS35L41_I2C_2_THINKPAD_ACPI,
+	ALC287_FIXUP_TAS2781_I2C,
 };
 
 /* A special fixup for Lenovo C940 and Yoga Duet 7;
@@ -9309,6 +9371,12 @@ static const struct hda_fixup alc269_fixups[] = {
 		.chained = true,
 		.chain_id = ALC269_FIXUP_THINKPAD_ACPI,
 	},
+	[ALC287_FIXUP_TAS2781_I2C] = {
+		.type = HDA_FIXUP_FUNC,
+		.v.func = tas2781_fixup_i2c,
+		.chained = true,
+		.chain_id = ALC269_FIXUP_THINKPAD_ACPI,
+	},
 };
 
 static const struct snd_pci_quirk alc269_fixup_tbl[] = {
@@ -9884,6 +9952,20 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
 	SND_PCI_QUIRK(0x17aa, 0x3853, "Lenovo Yoga 7 15ITL5", ALC287_FIXUP_YOGA7_14ITL_SPEAKERS),
 	SND_PCI_QUIRK(0x17aa, 0x3855, "Legion 7 16ITHG6", ALC287_FIXUP_LEGION_16ITHG6),
 	SND_PCI_QUIRK(0x17aa, 0x3869, "Lenovo Yoga7 14IAL7", ALC287_FIXUP_YOGA9_14IAP7_BASS_SPK_PIN),
+	SND_PCI_QUIRK(0x17aa, 0x387d, "Yoga S780-16 pro Quad AAC", ALC287_FIXUP_TAS2781_I2C),
+	SND_PCI_QUIRK(0x17aa, 0x387e, "Yoga S780-16 pro Quad YC", ALC287_FIXUP_TAS2781_I2C),
+	SND_PCI_QUIRK(0x17aa, 0x3881, "YB9 dual powe mode2 YC", ALC287_FIXUP_TAS2781_I2C),
+	SND_PCI_QUIRK(0x17aa, 0x3884, "Y780 YG DUAL", ALC287_FIXUP_TAS2781_I2C),
+	SND_PCI_QUIRK(0x17aa, 0x3886, "Y780 VECO DUAL", ALC287_FIXUP_TAS2781_I2C),
+	SND_PCI_QUIRK(0x17aa, 0x38a7, "Y780P AMD YG dual", ALC287_FIXUP_TAS2781_I2C),
+	SND_PCI_QUIRK(0x17aa, 0x38a8, "Y780P AMD VECO dual", ALC287_FIXUP_TAS2781_I2C),
+	SND_PCI_QUIRK(0x17aa, 0x38ba, "Yoga S780-14.5 Air AMD quad YC", ALC287_FIXUP_TAS2781_I2C),
+	SND_PCI_QUIRK(0x17aa, 0x38bb, "Yoga S780-14.5 Air AMD quad AAC", ALC287_FIXUP_TAS2781_I2C),
+	SND_PCI_QUIRK(0x17aa, 0x38be, "Yoga S980-14.5 proX YC Dual", ALC287_FIXUP_TAS2781_I2C),
+	SND_PCI_QUIRK(0x17aa, 0x38bf, "Yoga S980-14.5 proX LX Dual", ALC287_FIXUP_TAS2781_I2C),
+	SND_PCI_QUIRK(0x17aa, 0x38c3, "Y980 DUAL", ALC287_FIXUP_TAS2781_I2C),
+	SND_PCI_QUIRK(0x17aa, 0x38cb, "Y790 YG DUAL", ALC287_FIXUP_TAS2781_I2C),
+	SND_PCI_QUIRK(0x17aa, 0x38cd, "Y790 VECO DUAL", ALC287_FIXUP_TAS2781_I2C),
 	SND_PCI_QUIRK(0x17aa, 0x3902, "Lenovo E50-80", ALC269_FIXUP_DMIC_THINKPAD_ACPI),
 	SND_PCI_QUIRK(0x17aa, 0x3977, "IdeaPad S210", ALC283_FIXUP_INT_MIC),
 	SND_PCI_QUIRK(0x17aa, 0x3978, "Lenovo B50-70", ALC269_FIXUP_DMIC_THINKPAD_ACPI),
Signature · 1 line
2.34.1
#2 lore raw
In reply to Shenghao Ding
kernel test robot noticed the following build warnings:

Hi Shenghao,

kernel test robot noticed the following build warnings:

[auto build test WARNING on tiwai-sound/for-linus]
[also build test WARNING on linus/master v6.5-rc6]
[cannot apply to tiwai-sound/for-next next-20230817]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Shenghao-Ding/ALSA-hda-tas2781-Add-tas2781-HDA-driver/20230817-162901
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-linus
patch link:    https://lore.kernel.org/r/20230817082606.940-1-shenghao-ding%40ti.com
patch subject: [PATCH v3 1/2] ALSA: hda/tas2781: Add tas2781 HDA driver
config: loongarch-allmodconfig (https://download.01.org/0day-ci/archive/20230817/[email protected]/config)
compiler: loongarch64-linux-gcc (GCC) 12.3.0
reproduce: (https://download.01.org/0day-ci/archive/20230817/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

In file included from include/linux/irqflags.h:18,

                    from include/linux/spinlock.h:59,
                    from include/linux/mmzone.h:8,
                    from include/linux/gfp.h:7,
                    from include/linux/slab.h:16,
                    from include/linux/resource_ext.h:11,
                    from include/linux/acpi.h:13,
                    from sound/pci/hda/tas2781_hda_i2c.c:9:
   arch/loongarch/include/asm/percpu.h:20:4: error: #error compiler support for the model attribute is necessary when a recent assembler is used
      20 | #  error compiler support for the model attribute is necessary when a recent assembler is used
         |    ^~~~~
   sound/pci/hda/tas2781_hda_i2c.c: In function 'tasdevice_set_profile_id':
>> sound/pci/hda/tas2781_hda_i2c.c:192:13: warning: variable 'val' set but not used [-Wunused-but-set-variable]
     192 |         int val, ret = 0;
         |             ^~~
   sound/pci/hda/tas2781_hda_i2c.c: In function 'tasdevice_program_put':
   sound/pci/hda/tas2781_hda_i2c.c:249:13: warning: variable 'val' set but not used [-Wunused-but-set-variable]
     249 |         int val, ret = 0;
         |             ^~~
   sound/pci/hda/tas2781_hda_i2c.c: In function 'tasdevice_config_put':
   sound/pci/hda/tas2781_hda_i2c.c:278:13: warning: variable 'val' set but not used [-Wunused-but-set-variable]
     278 |         int val, ret = 0;
         |             ^~~

vim +/val +192 sound/pci/hda/tas2781_hda_i2c.c

     8	
   > 9	#include <linux/acpi.h>
    10	#include <linux/crc8.h>
    11	#include <linux/crc32.h>
    12	#include <linux/efi.h>
    13	#include <linux/firmware.h>
    14	#include <linux/i2c.h>
    15	#include <linux/mod_devicetable.h>
    16	#include <linux/module.h>
    17	#include <linux/pm_runtime.h>
    18	#include <linux/regmap.h>
    19	#include <sound/hda_codec.h>
    20	#include <sound/soc.h>
    21	#include <sound/tas2781.h>
    22	#include <sound/tlv.h>
    23	#include <sound/tas2781-tlv.h>
    24	
    25	#include "hda_local.h"
    26	#include "hda_auto_parser.h"
    27	#include "hda_component.h"
    28	#include "hda_jack.h"
    29	#include "hda_generic.h"
    30	
    31	#define TASDEVICE_SPEAKER_CALIBRATION_SIZE	20
    32	
    33	/* No standard control callbacks for SNDRV_CTL_ELEM_IFACE_CARD
    34	 * Define two controls, one is Volume control callbacks, the other is
    35	 * flag setting control callbacks.
    36	 */
    37	
    38	/* Volume control callbacks for tas2781 */
    39	#define ACARD_SINGLE_RANGE_EXT_TLV(xname, xreg, xshift, xmin, xmax, xinvert, \
    40		xhandler_get, xhandler_put, tlv_array) \
    41	{	.iface = SNDRV_CTL_ELEM_IFACE_CARD, .name = (xname),\
    42		.access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
    43			 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
    44		.tlv.p = (tlv_array), \
    45		.info = snd_soc_info_volsw_range, \
    46		.get = xhandler_get, .put = xhandler_put, \
    47		.private_value = (unsigned long)&(struct soc_mixer_control) \
    48			{.reg = xreg, .rreg = xreg, .shift = xshift, \
    49			 .rshift = xshift, .min = xmin, .max = xmax, \
    50			 .invert = xinvert} }
    51	
    52	/* Flag control callbacks for tas2781 */
    53	#define ACARD_SINGLE_BOOL_EXT(xname, xdata, xhandler_get, xhandler_put) \
    54	{	.iface = SNDRV_CTL_ELEM_IFACE_CARD, .name = xname, \
    55		.info = snd_ctl_boolean_mono_info, \
    56		.get = xhandler_get, .put = xhandler_put, \
    57		.private_value = xdata }
    58	
    59	enum calib_data {
    60		R0_VAL = 0,
    61		INV_R0,
    62		R0LOW,
    63		POWER,
    64		TLIM,
    65		CALIB_MAX
    66	};
    67	
    68	static int tas2781_get_i2c_res(struct acpi_resource *ares, void *data)
    69	{
    70		struct tasdevice_priv *tas_priv = data;
    71		struct acpi_resource_i2c_serialbus *sb;
    72	
    73		if (i2c_acpi_get_i2c_resource(ares, &sb)) {
    74			if (tas_priv->ndev < TASDEVICE_MAX_CHANNELS &&
    75				sb->slave_address != TAS2781_GLOBAL_ADDR) {
    76				tas_priv->tasdevice[tas_priv->ndev].dev_addr =
    77					(unsigned int)sb->slave_address;
    78				tas_priv->ndev++;
    79			}
    80		}
    81		return 1;
    82	}
    83	
    84	static int tas2781_read_acpi(struct tasdevice_priv *p, const char *hid)
    85	{
    86		struct acpi_device *adev;
    87		struct device *physdev;
    88		LIST_HEAD(resources);
    89		const char *sub;
    90		int ret;
    91	
    92		adev = acpi_dev_get_first_match_dev(hid, NULL, -1);
    93		if (!adev) {
    94			dev_err(p->dev,
    95				"Failed to find an ACPI device for %s\n", hid);
    96			return -ENODEV;
    97		}
    98	
    99		ret = acpi_dev_get_resources(adev, &resources, tas2781_get_i2c_res, p);
   100		if (ret < 0)
   101			goto err;
   102	
   103		acpi_dev_free_resource_list(&resources);
   104		strscpy(p->dev_name, hid, sizeof(p->dev_name));
   105		physdev = get_device(acpi_get_first_physical_node(adev));
   106		acpi_dev_put(adev);
   107	
   108		/* No side-effect to the playback even if subsystem_id is NULL*/
   109		sub = acpi_get_subsystem_id(ACPI_HANDLE(physdev));
   110		if (IS_ERR(sub))
   111			sub = NULL;
   112	
   113		p->acpi_subsystem_id = sub;
   114	
   115		put_device(physdev);
   116	
   117		return 0;
   118	
   119	err:
   120		dev_err(p->dev, "read acpi error, ret: %d\n", ret);
   121		put_device(physdev);
   122	
   123		return ret;
   124	}
   125	
   126	static void tas2781_hda_playback_hook(struct device *dev, int action)
   127	{
   128		struct tasdevice_priv *tas_priv = dev_get_drvdata(dev);
   129	
   130		dev_dbg(tas_priv->dev, "%s: action = %d\n", __func__, action);
   131		switch (action) {
   132		case HDA_GEN_PCM_ACT_OPEN:
   133			pm_runtime_get_sync(dev);
   134			mutex_lock(&tas_priv->codec_lock);
   135			tasdevice_tuning_switch(tas_priv, 0);
   136			mutex_unlock(&tas_priv->codec_lock);
   137			break;
   138		case HDA_GEN_PCM_ACT_CLOSE:
   139			mutex_lock(&tas_priv->codec_lock);
   140			tasdevice_tuning_switch(tas_priv, 1);
   141			mutex_unlock(&tas_priv->codec_lock);
   142	
   143			pm_runtime_mark_last_busy(dev);
   144			pm_runtime_put_autosuspend(dev);
   145			break;
   146		default:
   147			dev_dbg(tas_priv->dev, "Playback action not supported: %d\n",
   148				action);
   149			break;
   150		}
   151	}
   152	
   153	static int tasdevice_info_profile(struct snd_kcontrol *kcontrol,
   154				struct snd_ctl_elem_info *uinfo)
   155	{
   156		struct tasdevice_priv *tas_priv = snd_kcontrol_chip(kcontrol);
   157	
   158		uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
   159		uinfo->count = 1;
   160		uinfo->value.integer.min = 0;
   161		uinfo->value.integer.max = tas_priv->rcabin.ncfgs - 1;
   162	
   163		return 0;
   164	}
   165	
   166	static int tasdevice_get_profile_id(struct snd_kcontrol *kcontrol,
   167				struct snd_ctl_elem_value *ucontrol)
   168	{
   169		struct tasdevice_priv *tas_priv = snd_kcontrol_chip(kcontrol);
   170	
   171		ucontrol->value.integer.value[0] = tas_priv->rcabin.profile_cfg_id;
   172	
   173		return 0;
   174	}
   175	
   176	static int tasdevice_hda_clamp(int val, int max)
   177	{
   178		if (val > max)
   179			val = max;
   180	
   181		if (val < 0)
   182			val = 0;
   183		return val;
   184	}
   185	
   186	static int tasdevice_set_profile_id(struct snd_kcontrol *kcontrol,
   187			struct snd_ctl_elem_value *ucontrol)
   188	{
   189		struct tasdevice_priv *tas_priv = snd_kcontrol_chip(kcontrol);
   190		int nr_profile = ucontrol->value.integer.value[0];
   191		int max = tas_priv->rcabin.ncfgs - 1;
 > 192		int val, ret = 0;

193
194 val = tasdevice_hda_clamp(nr_profile, max);
195
196 if (tas_priv->rcabin.profile_cfg_id != nr_profile) {
197 tas_priv->rcabin.profile_cfg_id = nr_profile;
198 ret = 1;
199 }
200
201 return ret;
202 }
203

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki