xref: /linux/sound/pci/ice1712/amp.c (revision e23e7a1436207217000c2854214bc908936af3cb)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  *   ALSA driver for ICEnsemble VT1724 (Envy24HT)
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  *   Lowlevel functions for Advanced Micro Peripherals Ltd AUDIO2000
51da177e4SLinus Torvalds  *
6c1017a4cSJaroslav Kysela  *	Copyright (c) 2000 Jaroslav Kysela <perex@perex.cz>
71da177e4SLinus Torvalds  *
81da177e4SLinus Torvalds  *   This program is free software; you can redistribute it and/or modify
91da177e4SLinus Torvalds  *   it under the terms of the GNU General Public License as published by
101da177e4SLinus Torvalds  *   the Free Software Foundation; either version 2 of the License, or
111da177e4SLinus Torvalds  *   (at your option) any later version.
121da177e4SLinus Torvalds  *
131da177e4SLinus Torvalds  *   This program is distributed in the hope that it will be useful,
141da177e4SLinus Torvalds  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
151da177e4SLinus Torvalds  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
161da177e4SLinus Torvalds  *   GNU General Public License for more details.
171da177e4SLinus Torvalds  *
181da177e4SLinus Torvalds  *   You should have received a copy of the GNU General Public License
191da177e4SLinus Torvalds  *   along with this program; if not, write to the Free Software
201da177e4SLinus Torvalds  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
211da177e4SLinus Torvalds  *
221da177e4SLinus Torvalds  */
231da177e4SLinus Torvalds 
241da177e4SLinus Torvalds #include <linux/delay.h>
251da177e4SLinus Torvalds #include <linux/interrupt.h>
261da177e4SLinus Torvalds #include <linux/init.h>
271da177e4SLinus Torvalds #include <sound/core.h>
281da177e4SLinus Torvalds 
291da177e4SLinus Torvalds #include "ice1712.h"
308cfbbac6STakashi Iwai #include "envy24ht.h"
311da177e4SLinus Torvalds #include "amp.h"
321da177e4SLinus Torvalds 
33ab0c7d72STakashi Iwai static void wm_put(struct snd_ice1712 *ice, int reg, unsigned short val)
348cfbbac6STakashi Iwai {
358cfbbac6STakashi Iwai 	unsigned short cval;
368cfbbac6STakashi Iwai 	cval = (reg << 9) | val;
378cfbbac6STakashi Iwai 	snd_vt1724_write_i2c(ice, WM_DEV, cval >> 8, cval & 0xff);
388cfbbac6STakashi Iwai }
391da177e4SLinus Torvalds 
40*e23e7a14SBill Pemberton static int snd_vt1724_amp_init(struct snd_ice1712 *ice)
411da177e4SLinus Torvalds {
4232b47da0STakashi Iwai 	static const unsigned short wm_inits[] = {
438cfbbac6STakashi Iwai 		WM_ATTEN_L,	0x0000,	/* 0 db */
448cfbbac6STakashi Iwai 		WM_ATTEN_R,	0x0000,	/* 0 db */
458cfbbac6STakashi Iwai 		WM_DAC_CTRL,	0x0008,	/* 24bit I2S */
468cfbbac6STakashi Iwai 		WM_INT_CTRL,	0x0001, /* 24bit I2S */
478cfbbac6STakashi Iwai 	};
488cfbbac6STakashi Iwai 
498cfbbac6STakashi Iwai 	unsigned int i;
508cfbbac6STakashi Iwai 
511da177e4SLinus Torvalds 	/* only use basic functionality for now */
521da177e4SLinus Torvalds 
5343189a38SRobert Hancock 	/* VT1616 6ch codec connected to PSDOUT0 using packed mode */
5443189a38SRobert Hancock 	ice->num_total_dacs = 6;
551da177e4SLinus Torvalds 	ice->num_total_adcs = 2;
561da177e4SLinus Torvalds 
5743189a38SRobert Hancock 	/* Chaintech AV-710 has another WM8728 codec connected to PSDOUT4
5843189a38SRobert Hancock 	   (shared with the SPDIF output). Mixer control for this codec
5943189a38SRobert Hancock 	   is not yet supported. */
608cfbbac6STakashi Iwai 	if (ice->eeprom.subvendor == VT1724_SUBDEVICE_AV710) {
618cfbbac6STakashi Iwai 		for (i = 0; i < ARRAY_SIZE(wm_inits); i += 2)
628cfbbac6STakashi Iwai 			wm_put(ice, wm_inits[i], wm_inits[i+1]);
638cfbbac6STakashi Iwai 	}
648cfbbac6STakashi Iwai 
651da177e4SLinus Torvalds 	return 0;
661da177e4SLinus Torvalds }
671da177e4SLinus Torvalds 
68*e23e7a14SBill Pemberton static int snd_vt1724_amp_add_controls(struct snd_ice1712 *ice)
691da177e4SLinus Torvalds {
70e7848163SPavel Hofman 	if (ice->ac97)
71e7848163SPavel Hofman 		/* we use pins 39 and 41 of the VT1616 for left and right
72e7848163SPavel Hofman 		read outputs */
73e7848163SPavel Hofman 		snd_ac97_write_cache(ice->ac97, 0x5a,
74e7848163SPavel Hofman 			snd_ac97_read(ice->ac97, 0x5a) & ~0x8000);
751da177e4SLinus Torvalds 	return 0;
761da177e4SLinus Torvalds }
771da177e4SLinus Torvalds 
781da177e4SLinus Torvalds 
791da177e4SLinus Torvalds /* entry point */
80*e23e7a14SBill Pemberton struct snd_ice1712_card_info snd_vt1724_amp_cards[] = {
811da177e4SLinus Torvalds 	{
828cfbbac6STakashi Iwai 		.subvendor = VT1724_SUBDEVICE_AV710,
838cfbbac6STakashi Iwai 		.name = "Chaintech AV-710",
848cfbbac6STakashi Iwai 		.model = "av710",
858cfbbac6STakashi Iwai 		.chip_init = snd_vt1724_amp_init,
868cfbbac6STakashi Iwai 		.build_controls = snd_vt1724_amp_add_controls,
878cfbbac6STakashi Iwai 	},
888cfbbac6STakashi Iwai 	{
891da177e4SLinus Torvalds 		.subvendor = VT1724_SUBDEVICE_AUDIO2000,
901da177e4SLinus Torvalds 		.name = "AMP Ltd AUDIO2000",
911da177e4SLinus Torvalds 		.model = "amp2000",
921da177e4SLinus Torvalds 		.chip_init = snd_vt1724_amp_init,
931da177e4SLinus Torvalds 		.build_controls = snd_vt1724_amp_add_controls,
941da177e4SLinus Torvalds 	},
951da177e4SLinus Torvalds 	{ } /* terminator */
961da177e4SLinus Torvalds };
971da177e4SLinus Torvalds 
98