18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/***************************************************************************
38c2ecf20Sopenharmony_ci			  msnd_pinnacle_mixer.c  -  description
48c2ecf20Sopenharmony_ci			     -------------------
58c2ecf20Sopenharmony_ci    begin		: Fre Jun 7 2002
68c2ecf20Sopenharmony_ci    copyright 		: (C) 2002 by karsten wiese
78c2ecf20Sopenharmony_ci    email		: annabellesgarden@yahoo.de
88c2ecf20Sopenharmony_ci ***************************************************************************/
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci/***************************************************************************
118c2ecf20Sopenharmony_ci *							      		   *
128c2ecf20Sopenharmony_ci *									   *
138c2ecf20Sopenharmony_ci ***************************************************************************/
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include <linux/io.h>
168c2ecf20Sopenharmony_ci#include <linux/export.h>
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#include <sound/core.h>
198c2ecf20Sopenharmony_ci#include <sound/control.h>
208c2ecf20Sopenharmony_ci#include "msnd.h"
218c2ecf20Sopenharmony_ci#include "msnd_pinnacle.h"
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#define MSND_MIXER_VOLUME	0
258c2ecf20Sopenharmony_ci#define MSND_MIXER_PCM		1
268c2ecf20Sopenharmony_ci#define MSND_MIXER_AUX		2	/* Input source 1  (aux1) */
278c2ecf20Sopenharmony_ci#define MSND_MIXER_IMIX		3	/*  Recording monitor  */
288c2ecf20Sopenharmony_ci#define MSND_MIXER_SYNTH	4
298c2ecf20Sopenharmony_ci#define MSND_MIXER_SPEAKER	5
308c2ecf20Sopenharmony_ci#define MSND_MIXER_LINE		6
318c2ecf20Sopenharmony_ci#define MSND_MIXER_MIC		7
328c2ecf20Sopenharmony_ci#define MSND_MIXER_RECLEV	11	/* Recording level */
338c2ecf20Sopenharmony_ci#define MSND_MIXER_IGAIN	12	/* Input gain */
348c2ecf20Sopenharmony_ci#define MSND_MIXER_OGAIN	13	/* Output gain */
358c2ecf20Sopenharmony_ci#define MSND_MIXER_DIGITAL	17	/* Digital (input) 1 */
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci/*	Device mask bits	*/
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#define MSND_MASK_VOLUME	(1 << MSND_MIXER_VOLUME)
408c2ecf20Sopenharmony_ci#define MSND_MASK_SYNTH		(1 << MSND_MIXER_SYNTH)
418c2ecf20Sopenharmony_ci#define MSND_MASK_PCM		(1 << MSND_MIXER_PCM)
428c2ecf20Sopenharmony_ci#define MSND_MASK_SPEAKER	(1 << MSND_MIXER_SPEAKER)
438c2ecf20Sopenharmony_ci#define MSND_MASK_LINE		(1 << MSND_MIXER_LINE)
448c2ecf20Sopenharmony_ci#define MSND_MASK_MIC		(1 << MSND_MIXER_MIC)
458c2ecf20Sopenharmony_ci#define MSND_MASK_IMIX		(1 << MSND_MIXER_IMIX)
468c2ecf20Sopenharmony_ci#define MSND_MASK_RECLEV	(1 << MSND_MIXER_RECLEV)
478c2ecf20Sopenharmony_ci#define MSND_MASK_IGAIN		(1 << MSND_MIXER_IGAIN)
488c2ecf20Sopenharmony_ci#define MSND_MASK_OGAIN		(1 << MSND_MIXER_OGAIN)
498c2ecf20Sopenharmony_ci#define MSND_MASK_AUX		(1 << MSND_MIXER_AUX)
508c2ecf20Sopenharmony_ci#define MSND_MASK_DIGITAL	(1 << MSND_MIXER_DIGITAL)
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_cistatic int snd_msndmix_info_mux(struct snd_kcontrol *kcontrol,
538c2ecf20Sopenharmony_ci				struct snd_ctl_elem_info *uinfo)
548c2ecf20Sopenharmony_ci{
558c2ecf20Sopenharmony_ci	static const char * const texts[3] = {
568c2ecf20Sopenharmony_ci		"Analog", "MASS", "SPDIF",
578c2ecf20Sopenharmony_ci	};
588c2ecf20Sopenharmony_ci	struct snd_msnd *chip = snd_kcontrol_chip(kcontrol);
598c2ecf20Sopenharmony_ci	unsigned items = test_bit(F_HAVEDIGITAL, &chip->flags) ? 3 : 2;
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci	return snd_ctl_enum_info(uinfo, 1, items, texts);
628c2ecf20Sopenharmony_ci}
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_cistatic int snd_msndmix_get_mux(struct snd_kcontrol *kcontrol,
658c2ecf20Sopenharmony_ci				struct snd_ctl_elem_value *ucontrol)
668c2ecf20Sopenharmony_ci{
678c2ecf20Sopenharmony_ci	struct snd_msnd *chip = snd_kcontrol_chip(kcontrol);
688c2ecf20Sopenharmony_ci	/* MSND_MASK_IMIX is the default */
698c2ecf20Sopenharmony_ci	ucontrol->value.enumerated.item[0] = 0;
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci	if (chip->recsrc & MSND_MASK_SYNTH) {
728c2ecf20Sopenharmony_ci		ucontrol->value.enumerated.item[0] = 1;
738c2ecf20Sopenharmony_ci	} else if ((chip->recsrc & MSND_MASK_DIGITAL) &&
748c2ecf20Sopenharmony_ci		 test_bit(F_HAVEDIGITAL, &chip->flags)) {
758c2ecf20Sopenharmony_ci		ucontrol->value.enumerated.item[0] = 2;
768c2ecf20Sopenharmony_ci	}
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci	return 0;
808c2ecf20Sopenharmony_ci}
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_cistatic int snd_msndmix_set_mux(struct snd_msnd *chip, int val)
838c2ecf20Sopenharmony_ci{
848c2ecf20Sopenharmony_ci	unsigned newrecsrc;
858c2ecf20Sopenharmony_ci	int change;
868c2ecf20Sopenharmony_ci	unsigned char msndbyte;
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci	switch (val) {
898c2ecf20Sopenharmony_ci	case 0:
908c2ecf20Sopenharmony_ci		newrecsrc = MSND_MASK_IMIX;
918c2ecf20Sopenharmony_ci		msndbyte = HDEXAR_SET_ANA_IN;
928c2ecf20Sopenharmony_ci		break;
938c2ecf20Sopenharmony_ci	case 1:
948c2ecf20Sopenharmony_ci		newrecsrc = MSND_MASK_SYNTH;
958c2ecf20Sopenharmony_ci		msndbyte = HDEXAR_SET_SYNTH_IN;
968c2ecf20Sopenharmony_ci		break;
978c2ecf20Sopenharmony_ci	case 2:
988c2ecf20Sopenharmony_ci		newrecsrc = MSND_MASK_DIGITAL;
998c2ecf20Sopenharmony_ci		msndbyte = HDEXAR_SET_DAT_IN;
1008c2ecf20Sopenharmony_ci		break;
1018c2ecf20Sopenharmony_ci	default:
1028c2ecf20Sopenharmony_ci		return -EINVAL;
1038c2ecf20Sopenharmony_ci	}
1048c2ecf20Sopenharmony_ci	change  = newrecsrc != chip->recsrc;
1058c2ecf20Sopenharmony_ci	if (change) {
1068c2ecf20Sopenharmony_ci		change = 0;
1078c2ecf20Sopenharmony_ci		if (!snd_msnd_send_word(chip, 0, 0, msndbyte))
1088c2ecf20Sopenharmony_ci			if (!snd_msnd_send_dsp_cmd(chip, HDEX_AUX_REQ)) {
1098c2ecf20Sopenharmony_ci				chip->recsrc = newrecsrc;
1108c2ecf20Sopenharmony_ci				change = 1;
1118c2ecf20Sopenharmony_ci			}
1128c2ecf20Sopenharmony_ci	}
1138c2ecf20Sopenharmony_ci	return change;
1148c2ecf20Sopenharmony_ci}
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_cistatic int snd_msndmix_put_mux(struct snd_kcontrol *kcontrol,
1178c2ecf20Sopenharmony_ci				struct snd_ctl_elem_value *ucontrol)
1188c2ecf20Sopenharmony_ci{
1198c2ecf20Sopenharmony_ci	struct snd_msnd *msnd = snd_kcontrol_chip(kcontrol);
1208c2ecf20Sopenharmony_ci	return snd_msndmix_set_mux(msnd, ucontrol->value.enumerated.item[0]);
1218c2ecf20Sopenharmony_ci}
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_cistatic int snd_msndmix_volume_info(struct snd_kcontrol *kcontrol,
1258c2ecf20Sopenharmony_ci				   struct snd_ctl_elem_info *uinfo)
1268c2ecf20Sopenharmony_ci{
1278c2ecf20Sopenharmony_ci	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1288c2ecf20Sopenharmony_ci	uinfo->count = 2;
1298c2ecf20Sopenharmony_ci	uinfo->value.integer.min = 0;
1308c2ecf20Sopenharmony_ci	uinfo->value.integer.max = 100;
1318c2ecf20Sopenharmony_ci	return 0;
1328c2ecf20Sopenharmony_ci}
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_cistatic int snd_msndmix_volume_get(struct snd_kcontrol *kcontrol,
1358c2ecf20Sopenharmony_ci				  struct snd_ctl_elem_value *ucontrol)
1368c2ecf20Sopenharmony_ci{
1378c2ecf20Sopenharmony_ci	struct snd_msnd *msnd = snd_kcontrol_chip(kcontrol);
1388c2ecf20Sopenharmony_ci	int addr = kcontrol->private_value;
1398c2ecf20Sopenharmony_ci	unsigned long flags;
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci	spin_lock_irqsave(&msnd->mixer_lock, flags);
1428c2ecf20Sopenharmony_ci	ucontrol->value.integer.value[0] = msnd->left_levels[addr] * 100;
1438c2ecf20Sopenharmony_ci	ucontrol->value.integer.value[0] /= 0xFFFF;
1448c2ecf20Sopenharmony_ci	ucontrol->value.integer.value[1] = msnd->right_levels[addr] * 100;
1458c2ecf20Sopenharmony_ci	ucontrol->value.integer.value[1] /= 0xFFFF;
1468c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&msnd->mixer_lock, flags);
1478c2ecf20Sopenharmony_ci	return 0;
1488c2ecf20Sopenharmony_ci}
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci#define update_volm(a, b)						\
1518c2ecf20Sopenharmony_ci	do {								\
1528c2ecf20Sopenharmony_ci		writew((dev->left_levels[a] >> 1) *			\
1538c2ecf20Sopenharmony_ci		       readw(dev->SMA + SMA_wCurrMastVolLeft) / 0xffff,	\
1548c2ecf20Sopenharmony_ci		       dev->SMA + SMA_##b##Left);			\
1558c2ecf20Sopenharmony_ci		writew((dev->right_levels[a] >> 1)  *			\
1568c2ecf20Sopenharmony_ci		       readw(dev->SMA + SMA_wCurrMastVolRight) / 0xffff, \
1578c2ecf20Sopenharmony_ci		       dev->SMA + SMA_##b##Right);			\
1588c2ecf20Sopenharmony_ci	} while (0);
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci#define update_potm(d, s, ar)						\
1618c2ecf20Sopenharmony_ci	do {								\
1628c2ecf20Sopenharmony_ci		writeb((dev->left_levels[d] >> 8) *			\
1638c2ecf20Sopenharmony_ci		       readw(dev->SMA + SMA_wCurrMastVolLeft) / 0xffff, \
1648c2ecf20Sopenharmony_ci		       dev->SMA + SMA_##s##Left);			\
1658c2ecf20Sopenharmony_ci		writeb((dev->right_levels[d] >> 8) *			\
1668c2ecf20Sopenharmony_ci		       readw(dev->SMA + SMA_wCurrMastVolRight) / 0xffff, \
1678c2ecf20Sopenharmony_ci		       dev->SMA + SMA_##s##Right);			\
1688c2ecf20Sopenharmony_ci		if (snd_msnd_send_word(dev, 0, 0, ar) == 0)		\
1698c2ecf20Sopenharmony_ci			snd_msnd_send_dsp_cmd(dev, HDEX_AUX_REQ);	\
1708c2ecf20Sopenharmony_ci	} while (0);
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci#define update_pot(d, s, ar)						\
1738c2ecf20Sopenharmony_ci	do {								\
1748c2ecf20Sopenharmony_ci		writeb(dev->left_levels[d] >> 8,			\
1758c2ecf20Sopenharmony_ci		       dev->SMA + SMA_##s##Left);			\
1768c2ecf20Sopenharmony_ci		writeb(dev->right_levels[d] >> 8,			\
1778c2ecf20Sopenharmony_ci		       dev->SMA + SMA_##s##Right);			\
1788c2ecf20Sopenharmony_ci		if (snd_msnd_send_word(dev, 0, 0, ar) == 0)		\
1798c2ecf20Sopenharmony_ci			snd_msnd_send_dsp_cmd(dev, HDEX_AUX_REQ);	\
1808c2ecf20Sopenharmony_ci	} while (0);
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_cistatic int snd_msndmix_set(struct snd_msnd *dev, int d, int left, int right)
1848c2ecf20Sopenharmony_ci{
1858c2ecf20Sopenharmony_ci	int bLeft, bRight;
1868c2ecf20Sopenharmony_ci	int wLeft, wRight;
1878c2ecf20Sopenharmony_ci	int updatemaster = 0;
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci	if (d >= LEVEL_ENTRIES)
1908c2ecf20Sopenharmony_ci		return -EINVAL;
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ci	bLeft = left * 0xff / 100;
1938c2ecf20Sopenharmony_ci	wLeft = left * 0xffff / 100;
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ci	bRight = right * 0xff / 100;
1968c2ecf20Sopenharmony_ci	wRight = right * 0xffff / 100;
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_ci	dev->left_levels[d] = wLeft;
1998c2ecf20Sopenharmony_ci	dev->right_levels[d] = wRight;
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci	switch (d) {
2028c2ecf20Sopenharmony_ci		/* master volume unscaled controls */
2038c2ecf20Sopenharmony_ci	case MSND_MIXER_LINE:			/* line pot control */
2048c2ecf20Sopenharmony_ci		/* scaled by IMIX in digital mix */
2058c2ecf20Sopenharmony_ci		writeb(bLeft, dev->SMA + SMA_bInPotPosLeft);
2068c2ecf20Sopenharmony_ci		writeb(bRight, dev->SMA + SMA_bInPotPosRight);
2078c2ecf20Sopenharmony_ci		if (snd_msnd_send_word(dev, 0, 0, HDEXAR_IN_SET_POTS) == 0)
2088c2ecf20Sopenharmony_ci			snd_msnd_send_dsp_cmd(dev, HDEX_AUX_REQ);
2098c2ecf20Sopenharmony_ci		break;
2108c2ecf20Sopenharmony_ci	case MSND_MIXER_MIC:			/* mic pot control */
2118c2ecf20Sopenharmony_ci		if (dev->type == msndClassic)
2128c2ecf20Sopenharmony_ci			return -EINVAL;
2138c2ecf20Sopenharmony_ci		/* scaled by IMIX in digital mix */
2148c2ecf20Sopenharmony_ci		writeb(bLeft, dev->SMA + SMA_bMicPotPosLeft);
2158c2ecf20Sopenharmony_ci		writeb(bRight, dev->SMA + SMA_bMicPotPosRight);
2168c2ecf20Sopenharmony_ci		if (snd_msnd_send_word(dev, 0, 0, HDEXAR_MIC_SET_POTS) == 0)
2178c2ecf20Sopenharmony_ci			snd_msnd_send_dsp_cmd(dev, HDEX_AUX_REQ);
2188c2ecf20Sopenharmony_ci		break;
2198c2ecf20Sopenharmony_ci	case MSND_MIXER_VOLUME:		/* master volume */
2208c2ecf20Sopenharmony_ci		writew(wLeft, dev->SMA + SMA_wCurrMastVolLeft);
2218c2ecf20Sopenharmony_ci		writew(wRight, dev->SMA + SMA_wCurrMastVolRight);
2228c2ecf20Sopenharmony_ci		fallthrough;
2238c2ecf20Sopenharmony_ci	case MSND_MIXER_AUX:			/* aux pot control */
2248c2ecf20Sopenharmony_ci		/* scaled by master volume */
2258c2ecf20Sopenharmony_ci
2268c2ecf20Sopenharmony_ci		/* digital controls */
2278c2ecf20Sopenharmony_ci	case MSND_MIXER_SYNTH:			/* synth vol (dsp mix) */
2288c2ecf20Sopenharmony_ci	case MSND_MIXER_PCM:			/* pcm vol (dsp mix) */
2298c2ecf20Sopenharmony_ci	case MSND_MIXER_IMIX:			/* input monitor (dsp mix) */
2308c2ecf20Sopenharmony_ci		/* scaled by master volume */
2318c2ecf20Sopenharmony_ci		updatemaster = 1;
2328c2ecf20Sopenharmony_ci		break;
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_ci	default:
2358c2ecf20Sopenharmony_ci		return -EINVAL;
2368c2ecf20Sopenharmony_ci	}
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ci	if (updatemaster) {
2398c2ecf20Sopenharmony_ci		/* update master volume scaled controls */
2408c2ecf20Sopenharmony_ci		update_volm(MSND_MIXER_PCM, wCurrPlayVol);
2418c2ecf20Sopenharmony_ci		update_volm(MSND_MIXER_IMIX, wCurrInVol);
2428c2ecf20Sopenharmony_ci		if (dev->type == msndPinnacle)
2438c2ecf20Sopenharmony_ci			update_volm(MSND_MIXER_SYNTH, wCurrMHdrVol);
2448c2ecf20Sopenharmony_ci		update_potm(MSND_MIXER_AUX, bAuxPotPos, HDEXAR_AUX_SET_POTS);
2458c2ecf20Sopenharmony_ci	}
2468c2ecf20Sopenharmony_ci
2478c2ecf20Sopenharmony_ci	return 0;
2488c2ecf20Sopenharmony_ci}
2498c2ecf20Sopenharmony_ci
2508c2ecf20Sopenharmony_cistatic int snd_msndmix_volume_put(struct snd_kcontrol *kcontrol,
2518c2ecf20Sopenharmony_ci				  struct snd_ctl_elem_value *ucontrol)
2528c2ecf20Sopenharmony_ci{
2538c2ecf20Sopenharmony_ci	struct snd_msnd *msnd = snd_kcontrol_chip(kcontrol);
2548c2ecf20Sopenharmony_ci	int change, addr = kcontrol->private_value;
2558c2ecf20Sopenharmony_ci	int left, right;
2568c2ecf20Sopenharmony_ci	unsigned long flags;
2578c2ecf20Sopenharmony_ci
2588c2ecf20Sopenharmony_ci	left = ucontrol->value.integer.value[0] % 101;
2598c2ecf20Sopenharmony_ci	right = ucontrol->value.integer.value[1] % 101;
2608c2ecf20Sopenharmony_ci	spin_lock_irqsave(&msnd->mixer_lock, flags);
2618c2ecf20Sopenharmony_ci	change = msnd->left_levels[addr] != left
2628c2ecf20Sopenharmony_ci		|| msnd->right_levels[addr] != right;
2638c2ecf20Sopenharmony_ci	snd_msndmix_set(msnd, addr, left, right);
2648c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&msnd->mixer_lock, flags);
2658c2ecf20Sopenharmony_ci	return change;
2668c2ecf20Sopenharmony_ci}
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_ci
2698c2ecf20Sopenharmony_ci#define DUMMY_VOLUME(xname, xindex, addr) \
2708c2ecf20Sopenharmony_ci{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
2718c2ecf20Sopenharmony_ci  .info = snd_msndmix_volume_info, \
2728c2ecf20Sopenharmony_ci  .get = snd_msndmix_volume_get, .put = snd_msndmix_volume_put, \
2738c2ecf20Sopenharmony_ci  .private_value = addr }
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new snd_msnd_controls[] = {
2778c2ecf20Sopenharmony_ciDUMMY_VOLUME("Master Volume", 0, MSND_MIXER_VOLUME),
2788c2ecf20Sopenharmony_ciDUMMY_VOLUME("PCM Volume", 0, MSND_MIXER_PCM),
2798c2ecf20Sopenharmony_ciDUMMY_VOLUME("Aux Volume", 0, MSND_MIXER_AUX),
2808c2ecf20Sopenharmony_ciDUMMY_VOLUME("Line Volume", 0, MSND_MIXER_LINE),
2818c2ecf20Sopenharmony_ciDUMMY_VOLUME("Mic Volume", 0, MSND_MIXER_MIC),
2828c2ecf20Sopenharmony_ciDUMMY_VOLUME("Monitor",	0, MSND_MIXER_IMIX),
2838c2ecf20Sopenharmony_ci{
2848c2ecf20Sopenharmony_ci	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2858c2ecf20Sopenharmony_ci	.name = "Capture Source",
2868c2ecf20Sopenharmony_ci	.info = snd_msndmix_info_mux,
2878c2ecf20Sopenharmony_ci	.get = snd_msndmix_get_mux,
2888c2ecf20Sopenharmony_ci	.put = snd_msndmix_put_mux,
2898c2ecf20Sopenharmony_ci}
2908c2ecf20Sopenharmony_ci};
2918c2ecf20Sopenharmony_ci
2928c2ecf20Sopenharmony_ci
2938c2ecf20Sopenharmony_ciint snd_msndmix_new(struct snd_card *card)
2948c2ecf20Sopenharmony_ci{
2958c2ecf20Sopenharmony_ci	struct snd_msnd *chip = card->private_data;
2968c2ecf20Sopenharmony_ci	unsigned int idx;
2978c2ecf20Sopenharmony_ci	int err;
2988c2ecf20Sopenharmony_ci
2998c2ecf20Sopenharmony_ci	if (snd_BUG_ON(!chip))
3008c2ecf20Sopenharmony_ci		return -EINVAL;
3018c2ecf20Sopenharmony_ci	spin_lock_init(&chip->mixer_lock);
3028c2ecf20Sopenharmony_ci	strcpy(card->mixername, "MSND Pinnacle Mixer");
3038c2ecf20Sopenharmony_ci
3048c2ecf20Sopenharmony_ci	for (idx = 0; idx < ARRAY_SIZE(snd_msnd_controls); idx++) {
3058c2ecf20Sopenharmony_ci		err = snd_ctl_add(card,
3068c2ecf20Sopenharmony_ci				  snd_ctl_new1(snd_msnd_controls + idx, chip));
3078c2ecf20Sopenharmony_ci		if (err < 0)
3088c2ecf20Sopenharmony_ci			return err;
3098c2ecf20Sopenharmony_ci	}
3108c2ecf20Sopenharmony_ci
3118c2ecf20Sopenharmony_ci	return 0;
3128c2ecf20Sopenharmony_ci}
3138c2ecf20Sopenharmony_ciEXPORT_SYMBOL(snd_msndmix_new);
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_civoid snd_msndmix_setup(struct snd_msnd *dev)
3168c2ecf20Sopenharmony_ci{
3178c2ecf20Sopenharmony_ci	update_pot(MSND_MIXER_LINE, bInPotPos, HDEXAR_IN_SET_POTS);
3188c2ecf20Sopenharmony_ci	update_potm(MSND_MIXER_AUX, bAuxPotPos, HDEXAR_AUX_SET_POTS);
3198c2ecf20Sopenharmony_ci	update_volm(MSND_MIXER_PCM, wCurrPlayVol);
3208c2ecf20Sopenharmony_ci	update_volm(MSND_MIXER_IMIX, wCurrInVol);
3218c2ecf20Sopenharmony_ci	if (dev->type == msndPinnacle) {
3228c2ecf20Sopenharmony_ci		update_pot(MSND_MIXER_MIC, bMicPotPos, HDEXAR_MIC_SET_POTS);
3238c2ecf20Sopenharmony_ci		update_volm(MSND_MIXER_SYNTH, wCurrMHdrVol);
3248c2ecf20Sopenharmony_ci	}
3258c2ecf20Sopenharmony_ci}
3268c2ecf20Sopenharmony_ciEXPORT_SYMBOL(snd_msndmix_setup);
3278c2ecf20Sopenharmony_ci
3288c2ecf20Sopenharmony_ciint snd_msndmix_force_recsrc(struct snd_msnd *dev, int recsrc)
3298c2ecf20Sopenharmony_ci{
3308c2ecf20Sopenharmony_ci	dev->recsrc = -1;
3318c2ecf20Sopenharmony_ci	return snd_msndmix_set_mux(dev, recsrc);
3328c2ecf20Sopenharmony_ci}
3338c2ecf20Sopenharmony_ciEXPORT_SYMBOL(snd_msndmix_force_recsrc);
334