xref: /linux/sound/isa/opti9xx/opti92x-ad1848.c (revision 9e76a76efc43d604a20bf0c5564caaf028a24d2e)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds     card-opti92x-ad1848.c - driver for OPTi 82c92x based soundcards.
31da177e4SLinus Torvalds     Copyright (C) 1998-2000 by Massimo Piccioni <dafastidio@libero.it>
41da177e4SLinus Torvalds 
51da177e4SLinus Torvalds     Part of this code was developed at the Italian Ministry of Air Defence,
61da177e4SLinus Torvalds     Sixth Division (oh, che pace ...), Rome.
71da177e4SLinus Torvalds 
81da177e4SLinus Torvalds     Thanks to Maria Grazia Pollarini, Salvatore Vassallo.
91da177e4SLinus Torvalds 
101da177e4SLinus Torvalds     This program is free software; you can redistribute it and/or modify
111da177e4SLinus Torvalds     it under the terms of the GNU General Public License as published by
121da177e4SLinus Torvalds     the Free Software Foundation; either version 2 of the License, or
131da177e4SLinus Torvalds     (at your option) any later version.
141da177e4SLinus Torvalds 
151da177e4SLinus Torvalds     This program is distributed in the hope that it will be useful,
161da177e4SLinus Torvalds     but WITHOUT ANY WARRANTY; without even the implied warranty of
171da177e4SLinus Torvalds     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
181da177e4SLinus Torvalds     GNU General Public License for more details.
191da177e4SLinus Torvalds 
201da177e4SLinus Torvalds     You should have received a copy of the GNU General Public License
211da177e4SLinus Torvalds     along with this program; if not, write to the Free Software
221da177e4SLinus Torvalds     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
231da177e4SLinus Torvalds */
241da177e4SLinus Torvalds 
251da177e4SLinus Torvalds 
261da177e4SLinus Torvalds #include <sound/driver.h>
271da177e4SLinus Torvalds #include <asm/io.h>
281da177e4SLinus Torvalds #include <asm/dma.h>
291da177e4SLinus Torvalds #include <linux/delay.h>
301da177e4SLinus Torvalds #include <linux/init.h>
311da177e4SLinus Torvalds #include <linux/slab.h>
321da177e4SLinus Torvalds #include <linux/pnp.h>
331da177e4SLinus Torvalds #include <linux/moduleparam.h>
341da177e4SLinus Torvalds #include <sound/core.h>
351da177e4SLinus Torvalds #ifdef CS4231
361da177e4SLinus Torvalds #include <sound/cs4231.h>
371da177e4SLinus Torvalds #else
381da177e4SLinus Torvalds #ifndef OPTi93X
391da177e4SLinus Torvalds #include <sound/ad1848.h>
401da177e4SLinus Torvalds #else
411da177e4SLinus Torvalds #include <sound/control.h>
421da177e4SLinus Torvalds #include <sound/pcm.h>
431da177e4SLinus Torvalds #endif	/* OPTi93X */
441da177e4SLinus Torvalds #endif	/* CS4231 */
451da177e4SLinus Torvalds #include <sound/mpu401.h>
461da177e4SLinus Torvalds #include <sound/opl3.h>
471da177e4SLinus Torvalds #ifndef OPTi93X
481da177e4SLinus Torvalds #include <sound/opl4.h>
491da177e4SLinus Torvalds #endif
501da177e4SLinus Torvalds #define SNDRV_LEGACY_FIND_FREE_IRQ
511da177e4SLinus Torvalds #define SNDRV_LEGACY_FIND_FREE_DMA
521da177e4SLinus Torvalds #include <sound/initval.h>
531da177e4SLinus Torvalds 
541da177e4SLinus Torvalds MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
551da177e4SLinus Torvalds MODULE_LICENSE("GPL");
561da177e4SLinus Torvalds #ifdef OPTi93X
571da177e4SLinus Torvalds MODULE_DESCRIPTION("OPTi93X");
581da177e4SLinus Torvalds MODULE_SUPPORTED_DEVICE("{{OPTi,82C931/3}}");
591da177e4SLinus Torvalds #else	/* OPTi93X */
601da177e4SLinus Torvalds #ifdef CS4231
611da177e4SLinus Torvalds MODULE_DESCRIPTION("OPTi92X - CS4231");
621da177e4SLinus Torvalds MODULE_SUPPORTED_DEVICE("{{OPTi,82C924 (CS4231)},"
631da177e4SLinus Torvalds 		"{OPTi,82C925 (CS4231)}}");
641da177e4SLinus Torvalds #else	/* CS4231 */
651da177e4SLinus Torvalds MODULE_DESCRIPTION("OPTi92X - AD1848");
661da177e4SLinus Torvalds MODULE_SUPPORTED_DEVICE("{{OPTi,82C924 (AD1848)},"
671da177e4SLinus Torvalds 		"{OPTi,82C925 (AD1848)},"
681da177e4SLinus Torvalds 	        "{OAK,Mozart}}");
691da177e4SLinus Torvalds #endif	/* CS4231 */
701da177e4SLinus Torvalds #endif	/* OPTi93X */
711da177e4SLinus Torvalds 
721da177e4SLinus Torvalds static int index = SNDRV_DEFAULT_IDX1;	/* Index 0-MAX */
731da177e4SLinus Torvalds static char *id = SNDRV_DEFAULT_STR1;		/* ID for this card */
741da177e4SLinus Torvalds //static int enable = SNDRV_DEFAULT_ENABLE1;	/* Enable this card */
751da177e4SLinus Torvalds static int isapnp = 1;			/* Enable ISA PnP detection */
761da177e4SLinus Torvalds static long port = SNDRV_DEFAULT_PORT1; 	/* 0x530,0xe80,0xf40,0x604 */
771da177e4SLinus Torvalds static long mpu_port = SNDRV_DEFAULT_PORT1;	/* 0x300,0x310,0x320,0x330 */
781da177e4SLinus Torvalds static long fm_port = SNDRV_DEFAULT_PORT1;	/* 0x388 */
791da177e4SLinus Torvalds static int irq = SNDRV_DEFAULT_IRQ1;		/* 5,7,9,10,11 */
801da177e4SLinus Torvalds static int mpu_irq = SNDRV_DEFAULT_IRQ1;	/* 5,7,9,10 */
811da177e4SLinus Torvalds static int dma1 = SNDRV_DEFAULT_DMA1;		/* 0,1,3 */
821da177e4SLinus Torvalds #if defined(CS4231) || defined(OPTi93X)
831da177e4SLinus Torvalds static int dma2 = SNDRV_DEFAULT_DMA1;		/* 0,1,3 */
841da177e4SLinus Torvalds #endif	/* CS4231 || OPTi93X */
851da177e4SLinus Torvalds 
861da177e4SLinus Torvalds module_param(index, int, 0444);
871da177e4SLinus Torvalds MODULE_PARM_DESC(index, "Index value for opti9xx based soundcard.");
881da177e4SLinus Torvalds module_param(id, charp, 0444);
891da177e4SLinus Torvalds MODULE_PARM_DESC(id, "ID string for opti9xx based soundcard.");
901da177e4SLinus Torvalds //module_param(enable, bool, 0444);
911da177e4SLinus Torvalds //MODULE_PARM_DESC(enable, "Enable opti9xx soundcard.");
921da177e4SLinus Torvalds module_param(isapnp, bool, 0444);
931da177e4SLinus Torvalds MODULE_PARM_DESC(isapnp, "Enable ISA PnP detection for specified soundcard.");
941da177e4SLinus Torvalds module_param(port, long, 0444);
951da177e4SLinus Torvalds MODULE_PARM_DESC(port, "WSS port # for opti9xx driver.");
961da177e4SLinus Torvalds module_param(mpu_port, long, 0444);
971da177e4SLinus Torvalds MODULE_PARM_DESC(mpu_port, "MPU-401 port # for opti9xx driver.");
981da177e4SLinus Torvalds module_param(fm_port, long, 0444);
991da177e4SLinus Torvalds MODULE_PARM_DESC(fm_port, "FM port # for opti9xx driver.");
1001da177e4SLinus Torvalds module_param(irq, int, 0444);
1011da177e4SLinus Torvalds MODULE_PARM_DESC(irq, "WSS irq # for opti9xx driver.");
1021da177e4SLinus Torvalds module_param(mpu_irq, int, 0444);
1031da177e4SLinus Torvalds MODULE_PARM_DESC(mpu_irq, "MPU-401 irq # for opti9xx driver.");
1041da177e4SLinus Torvalds module_param(dma1, int, 0444);
1051da177e4SLinus Torvalds MODULE_PARM_DESC(dma1, "1st dma # for opti9xx driver.");
1061da177e4SLinus Torvalds #if defined(CS4231) || defined(OPTi93X)
1071da177e4SLinus Torvalds module_param(dma2, int, 0444);
1081da177e4SLinus Torvalds MODULE_PARM_DESC(dma2, "2nd dma # for opti9xx driver.");
1091da177e4SLinus Torvalds #endif	/* CS4231 || OPTi93X */
1101da177e4SLinus Torvalds 
1111da177e4SLinus Torvalds #define OPTi9XX_HW_DETECT	0
1121da177e4SLinus Torvalds #define OPTi9XX_HW_82C928	1
1131da177e4SLinus Torvalds #define OPTi9XX_HW_82C929	2
1141da177e4SLinus Torvalds #define OPTi9XX_HW_82C924	3
1151da177e4SLinus Torvalds #define OPTi9XX_HW_82C925	4
1161da177e4SLinus Torvalds #define OPTi9XX_HW_82C930	5
1171da177e4SLinus Torvalds #define OPTi9XX_HW_82C931	6
1181da177e4SLinus Torvalds #define OPTi9XX_HW_82C933	7
1191da177e4SLinus Torvalds #define OPTi9XX_HW_LAST		OPTi9XX_HW_82C933
1201da177e4SLinus Torvalds 
1211da177e4SLinus Torvalds #define OPTi9XX_MC_REG(n)	n
1221da177e4SLinus Torvalds 
1231da177e4SLinus Torvalds typedef struct _snd_opti9xx opti9xx_t;
1241da177e4SLinus Torvalds 
1251da177e4SLinus Torvalds #ifdef OPTi93X
1261da177e4SLinus Torvalds 
1271da177e4SLinus Torvalds #define OPTi93X_INDEX			0x00
1281da177e4SLinus Torvalds #define OPTi93X_DATA			0x01
1291da177e4SLinus Torvalds #define OPTi93X_STATUS			0x02
1301da177e4SLinus Torvalds #define OPTi93X_DDATA			0x03
1311da177e4SLinus Torvalds #define OPTi93X_PORT(chip, r)		((chip)->port + OPTi93X_##r)
1321da177e4SLinus Torvalds 
1331da177e4SLinus Torvalds #define OPTi93X_MIXOUT_LEFT		0x00
1341da177e4SLinus Torvalds #define OPTi93X_MIXOUT_RIGHT		0x01
1351da177e4SLinus Torvalds #define OPTi93X_CD_LEFT_INPUT		0x02
1361da177e4SLinus Torvalds #define OPTi93X_CD_RIGHT_INPUT		0x03
1371da177e4SLinus Torvalds #define OPTi930_AUX_LEFT_INPUT		0x04
1381da177e4SLinus Torvalds #define OPTi930_AUX_RIGHT_INPUT		0x05
1391da177e4SLinus Torvalds #define OPTi931_FM_LEFT_INPUT		0x04
1401da177e4SLinus Torvalds #define OPTi931_FM_RIGHT_INPUT		0x05
1411da177e4SLinus Torvalds #define OPTi93X_DAC_LEFT		0x06
1421da177e4SLinus Torvalds #define OPTi93X_DAC_RIGHT		0x07
1431da177e4SLinus Torvalds #define OPTi93X_PLAY_FORMAT		0x08
1441da177e4SLinus Torvalds #define OPTi93X_IFACE_CONF		0x09
1451da177e4SLinus Torvalds #define OPTi93X_PIN_CTRL		0x0a
1461da177e4SLinus Torvalds #define OPTi93X_ERR_INIT		0x0b
1471da177e4SLinus Torvalds #define OPTi93X_ID			0x0c
1481da177e4SLinus Torvalds #define OPTi93X_PLAY_UPR_CNT		0x0e
1491da177e4SLinus Torvalds #define OPTi93X_PLAY_LWR_CNT		0x0f
1501da177e4SLinus Torvalds #define OPTi931_AUX_LEFT_INPUT		0x10
1511da177e4SLinus Torvalds #define OPTi931_AUX_RIGHT_INPUT		0x11
1521da177e4SLinus Torvalds #define OPTi93X_LINE_LEFT_INPUT		0x12
1531da177e4SLinus Torvalds #define OPTi93X_LINE_RIGHT_INPUT	0x13
1541da177e4SLinus Torvalds #define OPTi93X_MIC_LEFT_INPUT		0x14
1551da177e4SLinus Torvalds #define OPTi93X_MIC_RIGHT_INPUT		0x15
1561da177e4SLinus Torvalds #define OPTi93X_OUT_LEFT		0x16
1571da177e4SLinus Torvalds #define OPTi93X_OUT_RIGHT		0x17
1581da177e4SLinus Torvalds #define OPTi93X_CAPT_FORMAT		0x1c
1591da177e4SLinus Torvalds #define OPTi93X_CAPT_UPR_CNT		0x1e
1601da177e4SLinus Torvalds #define OPTi93X_CAPT_LWR_CNT		0x1f
1611da177e4SLinus Torvalds 
1621da177e4SLinus Torvalds #define OPTi93X_TRD			0x20
1631da177e4SLinus Torvalds #define OPTi93X_MCE			0x40
1641da177e4SLinus Torvalds #define OPTi93X_INIT			0x80
1651da177e4SLinus Torvalds 
1661da177e4SLinus Torvalds #define OPTi93X_MIXOUT_MIC_GAIN		0x20
1671da177e4SLinus Torvalds #define OPTi93X_MIXOUT_LINE		0x00
1681da177e4SLinus Torvalds #define OPTi93X_MIXOUT_CD		0x40
1691da177e4SLinus Torvalds #define OPTi93X_MIXOUT_MIC		0x80
1701da177e4SLinus Torvalds #define OPTi93X_MIXOUT_MIXER		0xc0
1711da177e4SLinus Torvalds 
1721da177e4SLinus Torvalds #define OPTi93X_STEREO			0x10
1731da177e4SLinus Torvalds #define OPTi93X_LINEAR_8		0x00
1741da177e4SLinus Torvalds #define OPTi93X_ULAW_8			0x20
1751da177e4SLinus Torvalds #define OPTi93X_LINEAR_16_LIT		0x40
1761da177e4SLinus Torvalds #define OPTi93X_ALAW_8			0x60
1771da177e4SLinus Torvalds #define OPTi93X_ADPCM_16		0xa0
1781da177e4SLinus Torvalds #define OPTi93X_LINEAR_16_BIG		0xc0
1791da177e4SLinus Torvalds 
1801da177e4SLinus Torvalds #define OPTi93X_CAPTURE_PIO		0x80
1811da177e4SLinus Torvalds #define OPTi93X_PLAYBACK_PIO		0x40
1821da177e4SLinus Torvalds #define OPTi93X_AUTOCALIB		0x08
1831da177e4SLinus Torvalds #define OPTi93X_SINGLE_DMA		0x04
1841da177e4SLinus Torvalds #define OPTi93X_CAPTURE_ENABLE		0x02
1851da177e4SLinus Torvalds #define OPTi93X_PLAYBACK_ENABLE		0x01
1861da177e4SLinus Torvalds 
1871da177e4SLinus Torvalds #define OPTi93X_IRQ_ENABLE		0x02
1881da177e4SLinus Torvalds 
1891da177e4SLinus Torvalds #define OPTi93X_DMA_REQUEST		0x10
1901da177e4SLinus Torvalds #define OPTi93X_CALIB_IN_PROGRESS	0x20
1911da177e4SLinus Torvalds 
1921da177e4SLinus Torvalds #define OPTi93X_IRQ_PLAYBACK		0x04
1931da177e4SLinus Torvalds #define OPTi93X_IRQ_CAPTURE		0x08
1941da177e4SLinus Torvalds 
1951da177e4SLinus Torvalds 
1961da177e4SLinus Torvalds typedef struct _snd_opti93x opti93x_t;
1971da177e4SLinus Torvalds 
1981da177e4SLinus Torvalds struct _snd_opti93x {
1991da177e4SLinus Torvalds 	unsigned long port;
2001da177e4SLinus Torvalds 	struct resource *res_port;
2011da177e4SLinus Torvalds 	int irq;
2021da177e4SLinus Torvalds 	int dma1;
2031da177e4SLinus Torvalds 	int dma2;
2041da177e4SLinus Torvalds 
2051da177e4SLinus Torvalds 	opti9xx_t *chip;
2061da177e4SLinus Torvalds 	unsigned short hardware;
2071da177e4SLinus Torvalds 	unsigned char image[32];
2081da177e4SLinus Torvalds 
2091da177e4SLinus Torvalds 	unsigned char mce_bit;
2101da177e4SLinus Torvalds 	unsigned short mode;
2111da177e4SLinus Torvalds 	int mute;
2121da177e4SLinus Torvalds 
2131da177e4SLinus Torvalds 	spinlock_t lock;
2141da177e4SLinus Torvalds 
2151da177e4SLinus Torvalds 	snd_card_t *card;
2161da177e4SLinus Torvalds 	snd_pcm_t *pcm;
2171da177e4SLinus Torvalds 	snd_pcm_substream_t *playback_substream;
2181da177e4SLinus Torvalds 	snd_pcm_substream_t *capture_substream;
2191da177e4SLinus Torvalds 	unsigned int p_dma_size;
2201da177e4SLinus Torvalds 	unsigned int c_dma_size;
2211da177e4SLinus Torvalds };
2221da177e4SLinus Torvalds 
2231da177e4SLinus Torvalds #define OPTi93X_MODE_NONE	0x00
2241da177e4SLinus Torvalds #define OPTi93X_MODE_PLAY	0x01
2251da177e4SLinus Torvalds #define OPTi93X_MODE_CAPTURE	0x02
2261da177e4SLinus Torvalds #define OPTi93X_MODE_OPEN	(OPTi93X_MODE_PLAY | OPTi93X_MODE_CAPTURE)
2271da177e4SLinus Torvalds 
2281da177e4SLinus Torvalds #endif /* OPTi93X */
2291da177e4SLinus Torvalds 
2301da177e4SLinus Torvalds struct _snd_opti9xx {
2311da177e4SLinus Torvalds 	unsigned short hardware;
2321da177e4SLinus Torvalds 	unsigned char password;
2331da177e4SLinus Torvalds 	char name[7];
2341da177e4SLinus Torvalds 
2351da177e4SLinus Torvalds 	unsigned long mc_base;
2361da177e4SLinus Torvalds 	struct resource *res_mc_base;
2371da177e4SLinus Torvalds 	unsigned long mc_base_size;
2381da177e4SLinus Torvalds #ifdef OPTi93X
2391da177e4SLinus Torvalds 	unsigned long mc_indir_index;
2401da177e4SLinus Torvalds #endif	/* OPTi93X */
2411da177e4SLinus Torvalds 	unsigned long pwd_reg;
2421da177e4SLinus Torvalds 
2431da177e4SLinus Torvalds 	spinlock_t lock;
2441da177e4SLinus Torvalds 
2451da177e4SLinus Torvalds 	long wss_base;
2461da177e4SLinus Torvalds 	int irq;
2471da177e4SLinus Torvalds 	int dma1;
2481da177e4SLinus Torvalds #if defined(CS4231) || defined(OPTi93X)
2491da177e4SLinus Torvalds 	int dma2;
2501da177e4SLinus Torvalds #endif	/* CS4231 || OPTi93X */
2511da177e4SLinus Torvalds 
2521da177e4SLinus Torvalds 	long fm_port;
2531da177e4SLinus Torvalds 
2541da177e4SLinus Torvalds 	long mpu_port;
2551da177e4SLinus Torvalds 	int mpu_irq;
2561da177e4SLinus Torvalds 
2571da177e4SLinus Torvalds #ifdef CONFIG_PNP
2581da177e4SLinus Torvalds 	struct pnp_dev *dev;
2591da177e4SLinus Torvalds 	struct pnp_dev *devmpu;
2601da177e4SLinus Torvalds #endif	/* CONFIG_PNP */
2611da177e4SLinus Torvalds };
2621da177e4SLinus Torvalds 
2631da177e4SLinus Torvalds static int snd_opti9xx_first_hit = 1;
2641da177e4SLinus Torvalds static snd_card_t *snd_opti9xx_legacy = SNDRV_DEFAULT_PTR1;
2651da177e4SLinus Torvalds 
2661da177e4SLinus Torvalds #ifdef CONFIG_PNP
2671da177e4SLinus Torvalds 
2681da177e4SLinus Torvalds static struct pnp_card_device_id snd_opti9xx_pnpids[] = {
2691da177e4SLinus Torvalds #ifndef OPTi93X
2701da177e4SLinus Torvalds 	/* OPTi 82C924 */
2711da177e4SLinus Torvalds 	{ .id = "OPT0924", .devs = { { "OPT0000" }, { "OPT0002" } }, .driver_data = 0x0924 },
2721da177e4SLinus Torvalds 	/* OPTi 82C925 */
2731da177e4SLinus Torvalds 	{ .id = "OPT0925", .devs = { { "OPT9250" }, { "OPT0002" } }, .driver_data = 0x0925 },
2741da177e4SLinus Torvalds #else
2751da177e4SLinus Torvalds 	/* OPTi 82C931/3 */
2761da177e4SLinus Torvalds 	{ .id = "OPT0931", .devs = { { "OPT9310" }, { "OPT0002" } }, .driver_data = 0x0931 },
2771da177e4SLinus Torvalds #endif	/* OPTi93X */
2781da177e4SLinus Torvalds 	{ .id = "" }
2791da177e4SLinus Torvalds };
2801da177e4SLinus Torvalds 
2811da177e4SLinus Torvalds MODULE_DEVICE_TABLE(pnp_card, snd_opti9xx_pnpids);
2821da177e4SLinus Torvalds 
2831da177e4SLinus Torvalds #endif	/* CONFIG_PNP */
2841da177e4SLinus Torvalds 
2851da177e4SLinus Torvalds #ifdef OPTi93X
2861da177e4SLinus Torvalds #define DRIVER_NAME	"snd-card-opti93x"
2871da177e4SLinus Torvalds #else
2881da177e4SLinus Torvalds #define DRIVER_NAME	"snd-card-opti92x"
2891da177e4SLinus Torvalds #endif	/* OPTi93X */
2901da177e4SLinus Torvalds 
2911da177e4SLinus Torvalds static char * snd_opti9xx_names[] = {
2921da177e4SLinus Torvalds 	"unkown",
2931da177e4SLinus Torvalds 	"82C928",	"82C929",
2941da177e4SLinus Torvalds 	"82C924",	"82C925",
2951da177e4SLinus Torvalds 	"82C930",	"82C931",	"82C933"
2961da177e4SLinus Torvalds };
2971da177e4SLinus Torvalds 
2981da177e4SLinus Torvalds 
2991da177e4SLinus Torvalds static long snd_legacy_find_free_ioport(long *port_table, long size)
3001da177e4SLinus Torvalds {
3011da177e4SLinus Torvalds 	while (*port_table != -1) {
3021da177e4SLinus Torvalds 		struct resource *res;
3031da177e4SLinus Torvalds 		if ((res = request_region(*port_table, size, "ALSA test")) != NULL) {
3041da177e4SLinus Torvalds 			release_resource(res);
3051da177e4SLinus Torvalds 			kfree_nocheck(res);
3061da177e4SLinus Torvalds 			return *port_table;
3071da177e4SLinus Torvalds 		}
3081da177e4SLinus Torvalds 		port_table++;
3091da177e4SLinus Torvalds 	}
3101da177e4SLinus Torvalds 	return -1;
3111da177e4SLinus Torvalds }
3121da177e4SLinus Torvalds 
3131da177e4SLinus Torvalds static int __devinit snd_opti9xx_init(opti9xx_t *chip, unsigned short hardware)
3141da177e4SLinus Torvalds {
3151da177e4SLinus Torvalds 	static int opti9xx_mc_size[] = {7, 7, 10, 10, 2, 2, 2};
3161da177e4SLinus Torvalds 
3171da177e4SLinus Torvalds 	chip->hardware = hardware;
3181da177e4SLinus Torvalds 	strcpy(chip->name, snd_opti9xx_names[hardware]);
3191da177e4SLinus Torvalds 
3201da177e4SLinus Torvalds 	chip->mc_base_size = opti9xx_mc_size[hardware];
3211da177e4SLinus Torvalds 
3221da177e4SLinus Torvalds 	spin_lock_init(&chip->lock);
3231da177e4SLinus Torvalds 
3241da177e4SLinus Torvalds 	chip->wss_base = -1;
3251da177e4SLinus Torvalds 	chip->irq = -1;
3261da177e4SLinus Torvalds 	chip->dma1 = -1;
3271da177e4SLinus Torvalds #if defined(CS4231) || defined (OPTi93X)
3281da177e4SLinus Torvalds 	chip->dma2 = -1;
3291da177e4SLinus Torvalds #endif 	/* CS4231 || OPTi93X */
3301da177e4SLinus Torvalds 	chip->fm_port = -1;
3311da177e4SLinus Torvalds 	chip->mpu_port = -1;
3321da177e4SLinus Torvalds 	chip->mpu_irq = -1;
3331da177e4SLinus Torvalds 
3341da177e4SLinus Torvalds 	switch (hardware) {
3351da177e4SLinus Torvalds #ifndef OPTi93X
3361da177e4SLinus Torvalds 	case OPTi9XX_HW_82C928:
3371da177e4SLinus Torvalds 	case OPTi9XX_HW_82C929:
3381da177e4SLinus Torvalds 		chip->mc_base = 0xf8c;
3391da177e4SLinus Torvalds 		chip->password = (hardware == OPTi9XX_HW_82C928) ? 0xe2 : 0xe3;
3401da177e4SLinus Torvalds 		chip->pwd_reg = 3;
3411da177e4SLinus Torvalds 		break;
3421da177e4SLinus Torvalds 
3431da177e4SLinus Torvalds 	case OPTi9XX_HW_82C924:
3441da177e4SLinus Torvalds 	case OPTi9XX_HW_82C925:
3451da177e4SLinus Torvalds 		chip->mc_base = 0xf8c;
3461da177e4SLinus Torvalds 		chip->password = 0xe5;
3471da177e4SLinus Torvalds 		chip->pwd_reg = 3;
3481da177e4SLinus Torvalds 		break;
3491da177e4SLinus Torvalds #else	/* OPTi93X */
3501da177e4SLinus Torvalds 
3511da177e4SLinus Torvalds 	case OPTi9XX_HW_82C930:
3521da177e4SLinus Torvalds 	case OPTi9XX_HW_82C931:
3531da177e4SLinus Torvalds 	case OPTi9XX_HW_82C933:
3541da177e4SLinus Torvalds 		chip->mc_base = (hardware == OPTi9XX_HW_82C930) ? 0xf8f : 0xf8d;
3551da177e4SLinus Torvalds 		chip->mc_indir_index = 0xe0e;
3561da177e4SLinus Torvalds 		chip->password = 0xe4;
3571da177e4SLinus Torvalds 		chip->pwd_reg = 0;
3581da177e4SLinus Torvalds 		break;
3591da177e4SLinus Torvalds #endif	/* OPTi93X */
3601da177e4SLinus Torvalds 
3611da177e4SLinus Torvalds 	default:
3621da177e4SLinus Torvalds 		snd_printk("chip %d not supported\n", hardware);
3631da177e4SLinus Torvalds 		return -ENODEV;
3641da177e4SLinus Torvalds 	}
3651da177e4SLinus Torvalds 	return 0;
3661da177e4SLinus Torvalds }
3671da177e4SLinus Torvalds 
3681da177e4SLinus Torvalds static unsigned char snd_opti9xx_read(opti9xx_t *chip,
3691da177e4SLinus Torvalds 				      unsigned char reg)
3701da177e4SLinus Torvalds {
3711da177e4SLinus Torvalds 	unsigned long flags;
3721da177e4SLinus Torvalds 	unsigned char retval = 0xff;
3731da177e4SLinus Torvalds 
3741da177e4SLinus Torvalds 	spin_lock_irqsave(&chip->lock, flags);
3751da177e4SLinus Torvalds 	outb(chip->password, chip->mc_base + chip->pwd_reg);
3761da177e4SLinus Torvalds 
3771da177e4SLinus Torvalds 	switch (chip->hardware) {
3781da177e4SLinus Torvalds #ifndef OPTi93X
3791da177e4SLinus Torvalds 	case OPTi9XX_HW_82C924:
3801da177e4SLinus Torvalds 	case OPTi9XX_HW_82C925:
3811da177e4SLinus Torvalds 		if (reg > 7) {
3821da177e4SLinus Torvalds 			outb(reg, chip->mc_base + 8);
3831da177e4SLinus Torvalds 			outb(chip->password, chip->mc_base + chip->pwd_reg);
3841da177e4SLinus Torvalds 			retval = inb(chip->mc_base + 9);
3851da177e4SLinus Torvalds 			break;
3861da177e4SLinus Torvalds 		}
3871da177e4SLinus Torvalds 
3881da177e4SLinus Torvalds 	case OPTi9XX_HW_82C928:
3891da177e4SLinus Torvalds 	case OPTi9XX_HW_82C929:
3901da177e4SLinus Torvalds 		retval = inb(chip->mc_base + reg);
3911da177e4SLinus Torvalds 		break;
3921da177e4SLinus Torvalds #else	/* OPTi93X */
3931da177e4SLinus Torvalds 
3941da177e4SLinus Torvalds 	case OPTi9XX_HW_82C930:
3951da177e4SLinus Torvalds 	case OPTi9XX_HW_82C931:
3961da177e4SLinus Torvalds 	case OPTi9XX_HW_82C933:
3971da177e4SLinus Torvalds 		outb(reg, chip->mc_indir_index);
3981da177e4SLinus Torvalds 		outb(chip->password, chip->mc_base + chip->pwd_reg);
3991da177e4SLinus Torvalds 		retval = inb(chip->mc_indir_index + 1);
4001da177e4SLinus Torvalds 		break;
4011da177e4SLinus Torvalds #endif	/* OPTi93X */
4021da177e4SLinus Torvalds 
4031da177e4SLinus Torvalds 	default:
4041da177e4SLinus Torvalds 		snd_printk("chip %d not supported\n", chip->hardware);
4051da177e4SLinus Torvalds 	}
4061da177e4SLinus Torvalds 
4071da177e4SLinus Torvalds 	spin_unlock_irqrestore(&chip->lock, flags);
4081da177e4SLinus Torvalds 	return retval;
4091da177e4SLinus Torvalds }
4101da177e4SLinus Torvalds 
4111da177e4SLinus Torvalds static void snd_opti9xx_write(opti9xx_t *chip, unsigned char reg,
4121da177e4SLinus Torvalds 			      unsigned char value)
4131da177e4SLinus Torvalds {
4141da177e4SLinus Torvalds 	unsigned long flags;
4151da177e4SLinus Torvalds 
4161da177e4SLinus Torvalds 	spin_lock_irqsave(&chip->lock, flags);
4171da177e4SLinus Torvalds 	outb(chip->password, chip->mc_base + chip->pwd_reg);
4181da177e4SLinus Torvalds 
4191da177e4SLinus Torvalds 	switch (chip->hardware) {
4201da177e4SLinus Torvalds #ifndef OPTi93X
4211da177e4SLinus Torvalds 	case OPTi9XX_HW_82C924:
4221da177e4SLinus Torvalds 	case OPTi9XX_HW_82C925:
4231da177e4SLinus Torvalds 		if (reg > 7) {
4241da177e4SLinus Torvalds 			outb(reg, chip->mc_base + 8);
4251da177e4SLinus Torvalds 			outb(chip->password, chip->mc_base + chip->pwd_reg);
4261da177e4SLinus Torvalds 			outb(value, chip->mc_base + 9);
4271da177e4SLinus Torvalds 			break;
4281da177e4SLinus Torvalds 		}
4291da177e4SLinus Torvalds 
4301da177e4SLinus Torvalds 	case OPTi9XX_HW_82C928:
4311da177e4SLinus Torvalds 	case OPTi9XX_HW_82C929:
4321da177e4SLinus Torvalds 		outb(value, chip->mc_base + reg);
4331da177e4SLinus Torvalds 		break;
4341da177e4SLinus Torvalds #else	/* OPTi93X */
4351da177e4SLinus Torvalds 
4361da177e4SLinus Torvalds 	case OPTi9XX_HW_82C930:
4371da177e4SLinus Torvalds 	case OPTi9XX_HW_82C931:
4381da177e4SLinus Torvalds 	case OPTi9XX_HW_82C933:
4391da177e4SLinus Torvalds 		outb(reg, chip->mc_indir_index);
4401da177e4SLinus Torvalds 		outb(chip->password, chip->mc_base + chip->pwd_reg);
4411da177e4SLinus Torvalds 		outb(value, chip->mc_indir_index + 1);
4421da177e4SLinus Torvalds 		break;
4431da177e4SLinus Torvalds #endif	/* OPTi93X */
4441da177e4SLinus Torvalds 
4451da177e4SLinus Torvalds 	default:
4461da177e4SLinus Torvalds 		snd_printk("chip %d not supported\n", chip->hardware);
4471da177e4SLinus Torvalds 	}
4481da177e4SLinus Torvalds 
4491da177e4SLinus Torvalds 	spin_unlock_irqrestore(&chip->lock, flags);
4501da177e4SLinus Torvalds }
4511da177e4SLinus Torvalds 
4521da177e4SLinus Torvalds 
4531da177e4SLinus Torvalds #define snd_opti9xx_write_mask(chip, reg, value, mask)	\
4541da177e4SLinus Torvalds 	snd_opti9xx_write(chip, reg,			\
4551da177e4SLinus Torvalds 		(snd_opti9xx_read(chip, reg) & ~(mask)) | ((value) & (mask)))
4561da177e4SLinus Torvalds 
4571da177e4SLinus Torvalds 
4581da177e4SLinus Torvalds static int __devinit snd_opti9xx_configure(opti9xx_t *chip)
4591da177e4SLinus Torvalds {
4601da177e4SLinus Torvalds 	unsigned char wss_base_bits;
4611da177e4SLinus Torvalds 	unsigned char irq_bits;
4621da177e4SLinus Torvalds 	unsigned char dma_bits;
4631da177e4SLinus Torvalds 	unsigned char mpu_port_bits = 0;
4641da177e4SLinus Torvalds 	unsigned char mpu_irq_bits;
4651da177e4SLinus Torvalds 
4661da177e4SLinus Torvalds 	switch (chip->hardware) {
4671da177e4SLinus Torvalds #ifndef OPTi93X
4681da177e4SLinus Torvalds 	case OPTi9XX_HW_82C924:
4691da177e4SLinus Torvalds 		snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0xf0, 0xfc);
4701da177e4SLinus Torvalds 		snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x02);
4711da177e4SLinus Torvalds 
4721da177e4SLinus Torvalds 	case OPTi9XX_HW_82C925:
4731da177e4SLinus Torvalds 		snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80);
4741da177e4SLinus Torvalds 		snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), 0x00, 0x20);
4751da177e4SLinus Torvalds 		snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0xf0, 0xff);
4761da177e4SLinus Torvalds #ifdef CS4231
4771da177e4SLinus Torvalds 		snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
4781da177e4SLinus Torvalds #else
4791da177e4SLinus Torvalds 		snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x00, 0x02);
4801da177e4SLinus Torvalds #endif	/* CS4231 */
4811da177e4SLinus Torvalds 		break;
4821da177e4SLinus Torvalds 
4831da177e4SLinus Torvalds 	case OPTi9XX_HW_82C928:
4841da177e4SLinus Torvalds 	case OPTi9XX_HW_82C929:
4851da177e4SLinus Torvalds 		snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80);
4861da177e4SLinus Torvalds 		snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), 0x00, 0x20);
4871da177e4SLinus Torvalds 		/*
4881da177e4SLinus Torvalds 		snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0xa2, 0xae);
4891da177e4SLinus Torvalds 		*/
4901da177e4SLinus Torvalds 		snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0x00, 0x0c);
4911da177e4SLinus Torvalds #ifdef CS4231
4921da177e4SLinus Torvalds 		snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
4931da177e4SLinus Torvalds #else
4941da177e4SLinus Torvalds 		snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x00, 0x02);
4951da177e4SLinus Torvalds #endif	/* CS4231 */
4961da177e4SLinus Torvalds 		break;
4971da177e4SLinus Torvalds 
4981da177e4SLinus Torvalds #else	/* OPTi93X */
4991da177e4SLinus Torvalds 	case OPTi9XX_HW_82C930:
5001da177e4SLinus Torvalds 	case OPTi9XX_HW_82C931:
5011da177e4SLinus Torvalds 	case OPTi9XX_HW_82C933:
5021da177e4SLinus Torvalds 		snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x03);
5031da177e4SLinus Torvalds 		snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0x00, 0xff);
5041da177e4SLinus Torvalds 		snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0x10 |
5051da177e4SLinus Torvalds 			(chip->hardware == OPTi9XX_HW_82C930 ? 0x00 : 0x04),
5061da177e4SLinus Torvalds 			0x34);
5071da177e4SLinus Torvalds 		snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x20, 0xbf);
5081da177e4SLinus Torvalds 		break;
5091da177e4SLinus Torvalds #endif	/* OPTi93X */
5101da177e4SLinus Torvalds 
5111da177e4SLinus Torvalds 	default:
5121da177e4SLinus Torvalds 		snd_printk("chip %d not supported\n", chip->hardware);
5131da177e4SLinus Torvalds 		return -EINVAL;
5141da177e4SLinus Torvalds 	}
5151da177e4SLinus Torvalds 
5161da177e4SLinus Torvalds 	switch (chip->wss_base) {
5171da177e4SLinus Torvalds 	case 0x530:
5181da177e4SLinus Torvalds 		wss_base_bits = 0x00;
5191da177e4SLinus Torvalds 		break;
5201da177e4SLinus Torvalds 	case 0x604:
5211da177e4SLinus Torvalds 		wss_base_bits = 0x03;
5221da177e4SLinus Torvalds 		break;
5231da177e4SLinus Torvalds 	case 0xe80:
5241da177e4SLinus Torvalds 		wss_base_bits = 0x01;
5251da177e4SLinus Torvalds 		break;
5261da177e4SLinus Torvalds 	case 0xf40:
5271da177e4SLinus Torvalds 		wss_base_bits = 0x02;
5281da177e4SLinus Torvalds 		break;
5291da177e4SLinus Torvalds 	default:
5301da177e4SLinus Torvalds 		snd_printk("WSS port 0x%lx not valid\n", chip->wss_base);
5311da177e4SLinus Torvalds 		goto __skip_base;
5321da177e4SLinus Torvalds 	}
5331da177e4SLinus Torvalds 	snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), wss_base_bits << 4, 0x30);
5341da177e4SLinus Torvalds 
5351da177e4SLinus Torvalds __skip_base:
5361da177e4SLinus Torvalds 	switch (chip->irq) {
5371da177e4SLinus Torvalds //#ifdef OPTi93X
5381da177e4SLinus Torvalds 	case 5:
5391da177e4SLinus Torvalds 		irq_bits = 0x05;
5401da177e4SLinus Torvalds 		break;
5411da177e4SLinus Torvalds //#endif	/* OPTi93X */
5421da177e4SLinus Torvalds 	case 7:
5431da177e4SLinus Torvalds 		irq_bits = 0x01;
5441da177e4SLinus Torvalds 		break;
5451da177e4SLinus Torvalds 	case 9:
5461da177e4SLinus Torvalds 		irq_bits = 0x02;
5471da177e4SLinus Torvalds 		break;
5481da177e4SLinus Torvalds 	case 10:
5491da177e4SLinus Torvalds 		irq_bits = 0x03;
5501da177e4SLinus Torvalds 		break;
5511da177e4SLinus Torvalds 	case 11:
5521da177e4SLinus Torvalds 		irq_bits = 0x04;
5531da177e4SLinus Torvalds 		break;
5541da177e4SLinus Torvalds 	default:
5551da177e4SLinus Torvalds 		snd_printk("WSS irq # %d not valid\n", chip->irq);
5561da177e4SLinus Torvalds 		goto __skip_resources;
5571da177e4SLinus Torvalds 	}
5581da177e4SLinus Torvalds 
5591da177e4SLinus Torvalds 	switch (chip->dma1) {
5601da177e4SLinus Torvalds 	case 0:
5611da177e4SLinus Torvalds 		dma_bits = 0x01;
5621da177e4SLinus Torvalds 		break;
5631da177e4SLinus Torvalds 	case 1:
5641da177e4SLinus Torvalds 		dma_bits = 0x02;
5651da177e4SLinus Torvalds 		break;
5661da177e4SLinus Torvalds 	case 3:
5671da177e4SLinus Torvalds 		dma_bits = 0x03;
5681da177e4SLinus Torvalds 		break;
5691da177e4SLinus Torvalds 	default:
5701da177e4SLinus Torvalds 		snd_printk("WSS dma1 # %d not valid\n", chip->dma1);
5711da177e4SLinus Torvalds 		goto __skip_resources;
5721da177e4SLinus Torvalds 	}
5731da177e4SLinus Torvalds 
5741da177e4SLinus Torvalds #if defined(CS4231) || defined(OPTi93X)
5751da177e4SLinus Torvalds 	if (chip->dma1 == chip->dma2) {
5761da177e4SLinus Torvalds 		snd_printk("don't want to share dmas\n");
5771da177e4SLinus Torvalds 		return -EBUSY;
5781da177e4SLinus Torvalds 	}
5791da177e4SLinus Torvalds 
5801da177e4SLinus Torvalds 	switch (chip->dma2) {
5811da177e4SLinus Torvalds 	case 0:
5821da177e4SLinus Torvalds 	case 1:
5831da177e4SLinus Torvalds 		break;
5841da177e4SLinus Torvalds 	default:
5851da177e4SLinus Torvalds 		snd_printk("WSS dma2 # %d not valid\n", chip->dma2);
5861da177e4SLinus Torvalds 		goto __skip_resources;
5871da177e4SLinus Torvalds 	}
5881da177e4SLinus Torvalds 	dma_bits |= 0x04;
5891da177e4SLinus Torvalds #endif	/* CS4231 || OPTi93X */
5901da177e4SLinus Torvalds 
5911da177e4SLinus Torvalds #ifndef OPTi93X
5921da177e4SLinus Torvalds 	 outb(irq_bits << 3 | dma_bits, chip->wss_base);
5931da177e4SLinus Torvalds #else /* OPTi93X */
5941da177e4SLinus Torvalds 	snd_opti9xx_write(chip, OPTi9XX_MC_REG(3), (irq_bits << 3 | dma_bits));
5951da177e4SLinus Torvalds #endif /* OPTi93X */
5961da177e4SLinus Torvalds 
5971da177e4SLinus Torvalds __skip_resources:
5981da177e4SLinus Torvalds 	if (chip->hardware > OPTi9XX_HW_82C928) {
5991da177e4SLinus Torvalds 		switch (chip->mpu_port) {
6001da177e4SLinus Torvalds 		case 0:
6011da177e4SLinus Torvalds 		case -1:
6021da177e4SLinus Torvalds 			break;
6031da177e4SLinus Torvalds 		case 0x300:
6041da177e4SLinus Torvalds 			mpu_port_bits = 0x03;
6051da177e4SLinus Torvalds 			break;
6061da177e4SLinus Torvalds 		case 0x310:
6071da177e4SLinus Torvalds 			mpu_port_bits = 0x02;
6081da177e4SLinus Torvalds 			break;
6091da177e4SLinus Torvalds 		case 0x320:
6101da177e4SLinus Torvalds 			mpu_port_bits = 0x01;
6111da177e4SLinus Torvalds 			break;
6121da177e4SLinus Torvalds 		case 0x330:
6131da177e4SLinus Torvalds 			mpu_port_bits = 0x00;
6141da177e4SLinus Torvalds 			break;
6151da177e4SLinus Torvalds 		default:
6161da177e4SLinus Torvalds 			snd_printk("MPU-401 port 0x%lx not valid\n",
6171da177e4SLinus Torvalds 				chip->mpu_port);
6181da177e4SLinus Torvalds 			goto __skip_mpu;
6191da177e4SLinus Torvalds 		}
6201da177e4SLinus Torvalds 
6211da177e4SLinus Torvalds 		switch (chip->mpu_irq) {
6221da177e4SLinus Torvalds 		case 5:
6231da177e4SLinus Torvalds 			mpu_irq_bits = 0x02;
6241da177e4SLinus Torvalds 			break;
6251da177e4SLinus Torvalds 		case 7:
6261da177e4SLinus Torvalds 			mpu_irq_bits = 0x03;
6271da177e4SLinus Torvalds 			break;
6281da177e4SLinus Torvalds 		case 9:
6291da177e4SLinus Torvalds 			mpu_irq_bits = 0x00;
6301da177e4SLinus Torvalds 			break;
6311da177e4SLinus Torvalds 		case 10:
6321da177e4SLinus Torvalds 			mpu_irq_bits = 0x01;
6331da177e4SLinus Torvalds 			break;
6341da177e4SLinus Torvalds 		default:
6351da177e4SLinus Torvalds 			snd_printk("MPU-401 irq # %d not valid\n",
6361da177e4SLinus Torvalds 				chip->mpu_irq);
6371da177e4SLinus Torvalds 			goto __skip_mpu;
6381da177e4SLinus Torvalds 		}
6391da177e4SLinus Torvalds 
6401da177e4SLinus Torvalds 		snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6),
6411da177e4SLinus Torvalds 			(chip->mpu_port <= 0) ? 0x00 :
6421da177e4SLinus Torvalds 				0x80 | mpu_port_bits << 5 | mpu_irq_bits << 3,
6431da177e4SLinus Torvalds 			0xf8);
6441da177e4SLinus Torvalds 	}
6451da177e4SLinus Torvalds __skip_mpu:
6461da177e4SLinus Torvalds 
6471da177e4SLinus Torvalds 	return 0;
6481da177e4SLinus Torvalds }
6491da177e4SLinus Torvalds 
6501da177e4SLinus Torvalds #ifdef OPTi93X
6511da177e4SLinus Torvalds 
6521da177e4SLinus Torvalds static unsigned char snd_opti93x_default_image[32] =
6531da177e4SLinus Torvalds {
6541da177e4SLinus Torvalds 	0x00,		/* 00/00 - l_mixout_outctrl */
6551da177e4SLinus Torvalds 	0x00,		/* 01/01 - r_mixout_outctrl */
6561da177e4SLinus Torvalds 	0x88,		/* 02/02 - l_cd_inctrl */
6571da177e4SLinus Torvalds 	0x88,		/* 03/03 - r_cd_inctrl */
6581da177e4SLinus Torvalds 	0x88,		/* 04/04 - l_a1/fm_inctrl */
6591da177e4SLinus Torvalds 	0x88,		/* 05/05 - r_a1/fm_inctrl */
6601da177e4SLinus Torvalds 	0x80,		/* 06/06 - l_dac_inctrl */
6611da177e4SLinus Torvalds 	0x80,		/* 07/07 - r_dac_inctrl */
6621da177e4SLinus Torvalds 	0x00,		/* 08/08 - ply_dataform_reg */
6631da177e4SLinus Torvalds 	0x00,		/* 09/09 - if_conf */
6641da177e4SLinus Torvalds 	0x00,		/* 0a/10 - pin_ctrl */
6651da177e4SLinus Torvalds 	0x00,		/* 0b/11 - err_init_reg */
6661da177e4SLinus Torvalds 	0x0a,		/* 0c/12 - id_reg */
6671da177e4SLinus Torvalds 	0x00,		/* 0d/13 - reserved */
6681da177e4SLinus Torvalds 	0x00,		/* 0e/14 - ply_upcount_reg */
6691da177e4SLinus Torvalds 	0x00,		/* 0f/15 - ply_lowcount_reg */
6701da177e4SLinus Torvalds 	0x88,		/* 10/16 - reserved/l_a1_inctrl */
6711da177e4SLinus Torvalds 	0x88,		/* 11/17 - reserved/r_a1_inctrl */
6721da177e4SLinus Torvalds 	0x88,		/* 12/18 - l_line_inctrl */
6731da177e4SLinus Torvalds 	0x88,		/* 13/19 - r_line_inctrl */
6741da177e4SLinus Torvalds 	0x88,		/* 14/20 - l_mic_inctrl */
6751da177e4SLinus Torvalds 	0x88,		/* 15/21 - r_mic_inctrl */
6761da177e4SLinus Torvalds 	0x80,		/* 16/22 - l_out_outctrl */
6771da177e4SLinus Torvalds 	0x80,		/* 17/23 - r_out_outctrl */
6781da177e4SLinus Torvalds 	0x00,		/* 18/24 - reserved */
6791da177e4SLinus Torvalds 	0x00,		/* 19/25 - reserved */
6801da177e4SLinus Torvalds 	0x00,		/* 1a/26 - reserved */
6811da177e4SLinus Torvalds 	0x00,		/* 1b/27 - reserved */
6821da177e4SLinus Torvalds 	0x00,		/* 1c/28 - cap_dataform_reg */
6831da177e4SLinus Torvalds 	0x00,		/* 1d/29 - reserved */
6841da177e4SLinus Torvalds 	0x00,		/* 1e/30 - cap_upcount_reg */
6851da177e4SLinus Torvalds 	0x00		/* 1f/31 - cap_lowcount_reg */
6861da177e4SLinus Torvalds };
6871da177e4SLinus Torvalds 
6881da177e4SLinus Torvalds 
6891da177e4SLinus Torvalds static int snd_opti93x_busy_wait(opti93x_t *chip)
6901da177e4SLinus Torvalds {
6911da177e4SLinus Torvalds 	int timeout;
6921da177e4SLinus Torvalds 
6931da177e4SLinus Torvalds 	for (timeout = 250; timeout-- > 0; udelay(10))
6941da177e4SLinus Torvalds 		if (!(inb(OPTi93X_PORT(chip, INDEX)) & OPTi93X_INIT))
6951da177e4SLinus Torvalds 			return 0;
6961da177e4SLinus Torvalds 
6971da177e4SLinus Torvalds 	snd_printk("chip still busy.\n");
6981da177e4SLinus Torvalds 	return -EBUSY;
6991da177e4SLinus Torvalds }
7001da177e4SLinus Torvalds 
7011da177e4SLinus Torvalds static unsigned char snd_opti93x_in(opti93x_t *chip, unsigned char reg)
7021da177e4SLinus Torvalds {
7031da177e4SLinus Torvalds 	snd_opti93x_busy_wait(chip);
7041da177e4SLinus Torvalds 	outb(chip->mce_bit | (reg & 0x1f), OPTi93X_PORT(chip, INDEX));
7051da177e4SLinus Torvalds 	return inb(OPTi93X_PORT(chip, DATA));
7061da177e4SLinus Torvalds }
7071da177e4SLinus Torvalds 
7081da177e4SLinus Torvalds static void snd_opti93x_out(opti93x_t *chip, unsigned char reg,
7091da177e4SLinus Torvalds 			    unsigned char value)
7101da177e4SLinus Torvalds {
7111da177e4SLinus Torvalds 	snd_opti93x_busy_wait(chip);
7121da177e4SLinus Torvalds 	outb(chip->mce_bit | (reg & 0x1f), OPTi93X_PORT(chip, INDEX));
7131da177e4SLinus Torvalds 	outb(value, OPTi93X_PORT(chip, DATA));
7141da177e4SLinus Torvalds }
7151da177e4SLinus Torvalds 
7161da177e4SLinus Torvalds static void snd_opti93x_out_image(opti93x_t *chip, unsigned char reg,
7171da177e4SLinus Torvalds 				  unsigned char value)
7181da177e4SLinus Torvalds {
7191da177e4SLinus Torvalds 	snd_opti93x_out(chip, reg, chip->image[reg] = value);
7201da177e4SLinus Torvalds }
7211da177e4SLinus Torvalds 
7221da177e4SLinus Torvalds static void snd_opti93x_out_mask(opti93x_t *chip, unsigned char reg,
7231da177e4SLinus Torvalds 				 unsigned char mask, unsigned char value)
7241da177e4SLinus Torvalds {
7251da177e4SLinus Torvalds 	snd_opti93x_out_image(chip, reg,
7261da177e4SLinus Torvalds 		(chip->image[reg] & ~mask) | (value & mask));
7271da177e4SLinus Torvalds }
7281da177e4SLinus Torvalds 
7291da177e4SLinus Torvalds 
7301da177e4SLinus Torvalds static void snd_opti93x_mce_up(opti93x_t *chip)
7311da177e4SLinus Torvalds {
7321da177e4SLinus Torvalds 	snd_opti93x_busy_wait(chip);
7331da177e4SLinus Torvalds 
7341da177e4SLinus Torvalds 	chip->mce_bit = OPTi93X_MCE;
7351da177e4SLinus Torvalds 	if (!(inb(OPTi93X_PORT(chip, INDEX)) & OPTi93X_MCE))
7361da177e4SLinus Torvalds 		outb(chip->mce_bit, OPTi93X_PORT(chip, INDEX));
7371da177e4SLinus Torvalds }
7381da177e4SLinus Torvalds 
7391da177e4SLinus Torvalds static void snd_opti93x_mce_down(opti93x_t *chip)
7401da177e4SLinus Torvalds {
7411da177e4SLinus Torvalds 	snd_opti93x_busy_wait(chip);
7421da177e4SLinus Torvalds 
7431da177e4SLinus Torvalds 	chip->mce_bit = 0;
7441da177e4SLinus Torvalds 	if (inb(OPTi93X_PORT(chip, INDEX)) & OPTi93X_MCE)
7451da177e4SLinus Torvalds 		outb(chip->mce_bit, OPTi93X_PORT(chip, INDEX));
7461da177e4SLinus Torvalds }
7471da177e4SLinus Torvalds 
7481da177e4SLinus Torvalds #define snd_opti93x_mute_reg(chip, reg, mute)	\
7491da177e4SLinus Torvalds 	snd_opti93x_out(chip, reg, mute ? 0x80 : chip->image[reg]);
7501da177e4SLinus Torvalds 
7511da177e4SLinus Torvalds static void snd_opti93x_mute(opti93x_t *chip, int mute)
7521da177e4SLinus Torvalds {
7531da177e4SLinus Torvalds 	mute = mute ? 1 : 0;
7541da177e4SLinus Torvalds 	if (chip->mute == mute)
7551da177e4SLinus Torvalds 		return;
7561da177e4SLinus Torvalds 
7571da177e4SLinus Torvalds 	chip->mute = mute;
7581da177e4SLinus Torvalds 
7591da177e4SLinus Torvalds 	snd_opti93x_mute_reg(chip, OPTi93X_CD_LEFT_INPUT, mute);
7601da177e4SLinus Torvalds 	snd_opti93x_mute_reg(chip, OPTi93X_CD_RIGHT_INPUT, mute);
7611da177e4SLinus Torvalds 	switch (chip->hardware) {
7621da177e4SLinus Torvalds 	case OPTi9XX_HW_82C930:
7631da177e4SLinus Torvalds 		snd_opti93x_mute_reg(chip, OPTi930_AUX_LEFT_INPUT, mute);
7641da177e4SLinus Torvalds 		snd_opti93x_mute_reg(chip, OPTi930_AUX_RIGHT_INPUT, mute);
7651da177e4SLinus Torvalds 		break;
7661da177e4SLinus Torvalds 	case OPTi9XX_HW_82C931:
7671da177e4SLinus Torvalds 	case OPTi9XX_HW_82C933:
7681da177e4SLinus Torvalds 		snd_opti93x_mute_reg(chip, OPTi931_FM_LEFT_INPUT, mute);
7691da177e4SLinus Torvalds 		snd_opti93x_mute_reg(chip, OPTi931_FM_RIGHT_INPUT, mute);
7701da177e4SLinus Torvalds 		snd_opti93x_mute_reg(chip, OPTi931_AUX_LEFT_INPUT, mute);
7711da177e4SLinus Torvalds 		snd_opti93x_mute_reg(chip, OPTi931_AUX_RIGHT_INPUT, mute);
7721da177e4SLinus Torvalds 	}
7731da177e4SLinus Torvalds 	snd_opti93x_mute_reg(chip, OPTi93X_DAC_LEFT, mute);
7741da177e4SLinus Torvalds 	snd_opti93x_mute_reg(chip, OPTi93X_DAC_RIGHT, mute);
7751da177e4SLinus Torvalds 	snd_opti93x_mute_reg(chip, OPTi93X_LINE_LEFT_INPUT, mute);
7761da177e4SLinus Torvalds 	snd_opti93x_mute_reg(chip, OPTi93X_LINE_RIGHT_INPUT, mute);
7771da177e4SLinus Torvalds 	snd_opti93x_mute_reg(chip, OPTi93X_MIC_LEFT_INPUT, mute);
7781da177e4SLinus Torvalds 	snd_opti93x_mute_reg(chip, OPTi93X_MIC_RIGHT_INPUT, mute);
7791da177e4SLinus Torvalds 	snd_opti93x_mute_reg(chip, OPTi93X_OUT_LEFT, mute);
7801da177e4SLinus Torvalds 	snd_opti93x_mute_reg(chip, OPTi93X_OUT_RIGHT, mute);
7811da177e4SLinus Torvalds }
7821da177e4SLinus Torvalds 
7831da177e4SLinus Torvalds 
7841da177e4SLinus Torvalds static unsigned int snd_opti93x_get_count(unsigned char format,
7851da177e4SLinus Torvalds 					  unsigned int size)
7861da177e4SLinus Torvalds {
7871da177e4SLinus Torvalds 	switch (format & 0xe0) {
7881da177e4SLinus Torvalds 	case OPTi93X_LINEAR_16_LIT:
7891da177e4SLinus Torvalds 	case OPTi93X_LINEAR_16_BIG:
7901da177e4SLinus Torvalds 		size >>= 1;
7911da177e4SLinus Torvalds 		break;
7921da177e4SLinus Torvalds 	case OPTi93X_ADPCM_16:
7931da177e4SLinus Torvalds 		return size >> 2;
7941da177e4SLinus Torvalds 	}
7951da177e4SLinus Torvalds 	return (format & OPTi93X_STEREO) ? (size >> 1) : size;
7961da177e4SLinus Torvalds }
7971da177e4SLinus Torvalds 
7981da177e4SLinus Torvalds static unsigned int rates[] = {  5512,  6615,  8000,  9600, 11025, 16000,
7991da177e4SLinus Torvalds 				18900, 22050, 27428, 32000, 33075, 37800,
8001da177e4SLinus Torvalds 				44100, 48000 };
8011da177e4SLinus Torvalds #define RATES ARRAY_SIZE(rates)
8021da177e4SLinus Torvalds 
8031da177e4SLinus Torvalds static snd_pcm_hw_constraint_list_t hw_constraints_rates = {
8041da177e4SLinus Torvalds 	.count = RATES,
8051da177e4SLinus Torvalds 	.list = rates,
8061da177e4SLinus Torvalds 	.mask = 0,
8071da177e4SLinus Torvalds };
8081da177e4SLinus Torvalds 
8091da177e4SLinus Torvalds static unsigned char bits[] = {  0x01,  0x0f,  0x00,  0x0e,  0x03,  0x02,
8101da177e4SLinus Torvalds 				 0x05,  0x07,  0x04,  0x06,  0x0d,  0x09,
8111da177e4SLinus Torvalds 				 0x0b,  0x0c};
8121da177e4SLinus Torvalds 
8131da177e4SLinus Torvalds static unsigned char snd_opti93x_get_freq(unsigned int rate)
8141da177e4SLinus Torvalds {
8151da177e4SLinus Torvalds 	unsigned int i;
8161da177e4SLinus Torvalds 
8171da177e4SLinus Torvalds 	for (i = 0; i < RATES; i++) {
8181da177e4SLinus Torvalds 		if (rate == rates[i])
8191da177e4SLinus Torvalds 			return bits[i];
8201da177e4SLinus Torvalds 	}
8211da177e4SLinus Torvalds 	snd_BUG();
8221da177e4SLinus Torvalds 	return bits[RATES-1];
8231da177e4SLinus Torvalds }
8241da177e4SLinus Torvalds 
8251da177e4SLinus Torvalds static unsigned char snd_opti93x_get_format(opti93x_t *chip,
8261da177e4SLinus Torvalds 					    unsigned int format, int channels)
8271da177e4SLinus Torvalds {
8281da177e4SLinus Torvalds 	unsigned char retval = OPTi93X_LINEAR_8;
8291da177e4SLinus Torvalds 
8301da177e4SLinus Torvalds 	switch (format) {
8311da177e4SLinus Torvalds 	case SNDRV_PCM_FORMAT_MU_LAW:
8321da177e4SLinus Torvalds 		retval = OPTi93X_ULAW_8;
8331da177e4SLinus Torvalds 		break;
8341da177e4SLinus Torvalds 	case SNDRV_PCM_FORMAT_A_LAW:
8351da177e4SLinus Torvalds 		retval = OPTi93X_ALAW_8;
8361da177e4SLinus Torvalds 		break;
8371da177e4SLinus Torvalds 	case SNDRV_PCM_FORMAT_S16_LE:
8381da177e4SLinus Torvalds 		retval = OPTi93X_LINEAR_16_LIT;
8391da177e4SLinus Torvalds 		break;
8401da177e4SLinus Torvalds 	case SNDRV_PCM_FORMAT_S16_BE:
8411da177e4SLinus Torvalds 		retval = OPTi93X_LINEAR_16_BIG;
8421da177e4SLinus Torvalds 		break;
8431da177e4SLinus Torvalds 	case SNDRV_PCM_FORMAT_IMA_ADPCM:
8441da177e4SLinus Torvalds 		retval = OPTi93X_ADPCM_16;
8451da177e4SLinus Torvalds 	}
8461da177e4SLinus Torvalds 	return (channels > 1) ? (retval | OPTi93X_STEREO) : retval;
8471da177e4SLinus Torvalds }
8481da177e4SLinus Torvalds 
8491da177e4SLinus Torvalds 
8501da177e4SLinus Torvalds static void snd_opti93x_playback_format(opti93x_t *chip, unsigned char fmt)
8511da177e4SLinus Torvalds {
8521da177e4SLinus Torvalds 	unsigned char mask;
8531da177e4SLinus Torvalds 
8541da177e4SLinus Torvalds 	snd_opti93x_mute(chip, 1);
8551da177e4SLinus Torvalds 
8561da177e4SLinus Torvalds 	snd_opti93x_mce_up(chip);
8571da177e4SLinus Torvalds 	mask = (chip->mode & OPTi93X_MODE_CAPTURE) ? 0xf0 : 0xff;
8581da177e4SLinus Torvalds 	snd_opti93x_out_mask(chip, OPTi93X_PLAY_FORMAT, mask, fmt);
8591da177e4SLinus Torvalds 	snd_opti93x_mce_down(chip);
8601da177e4SLinus Torvalds 
8611da177e4SLinus Torvalds 	snd_opti93x_mute(chip, 0);
8621da177e4SLinus Torvalds }
8631da177e4SLinus Torvalds 
8641da177e4SLinus Torvalds static void snd_opti93x_capture_format(opti93x_t *chip, unsigned char fmt)
8651da177e4SLinus Torvalds {
8661da177e4SLinus Torvalds 	snd_opti93x_mute(chip, 1);
8671da177e4SLinus Torvalds 
8681da177e4SLinus Torvalds 	snd_opti93x_mce_up(chip);
8691da177e4SLinus Torvalds 	if (!(chip->mode & OPTi93X_MODE_PLAY))
8701da177e4SLinus Torvalds 		snd_opti93x_out_mask(chip, OPTi93X_PLAY_FORMAT, 0x0f, fmt);
8711da177e4SLinus Torvalds 	else
8721da177e4SLinus Torvalds 		fmt = chip->image[OPTi93X_PLAY_FORMAT] & 0xf0;
8731da177e4SLinus Torvalds 	snd_opti93x_out_image(chip, OPTi93X_CAPT_FORMAT, fmt);
8741da177e4SLinus Torvalds 	snd_opti93x_mce_down(chip);
8751da177e4SLinus Torvalds 
8761da177e4SLinus Torvalds 	snd_opti93x_mute(chip, 0);
8771da177e4SLinus Torvalds }
8781da177e4SLinus Torvalds 
8791da177e4SLinus Torvalds 
8801da177e4SLinus Torvalds static int snd_opti93x_open(opti93x_t *chip, unsigned int mode)
8811da177e4SLinus Torvalds {
8821da177e4SLinus Torvalds 	unsigned long flags;
8831da177e4SLinus Torvalds 
8841da177e4SLinus Torvalds 	spin_lock_irqsave(&chip->lock, flags);
8851da177e4SLinus Torvalds 
8861da177e4SLinus Torvalds 	if (chip->mode & mode) {
8871da177e4SLinus Torvalds 		spin_unlock_irqrestore(&chip->lock, flags);
8881da177e4SLinus Torvalds 		return -EAGAIN;
8891da177e4SLinus Torvalds 	}
8901da177e4SLinus Torvalds 
8911da177e4SLinus Torvalds 	if (!(chip->mode & OPTi93X_MODE_OPEN)) {
8921da177e4SLinus Torvalds 		outb(0x00, OPTi93X_PORT(chip, STATUS));
8931da177e4SLinus Torvalds 		snd_opti93x_out_mask(chip, OPTi93X_PIN_CTRL,
8941da177e4SLinus Torvalds 			OPTi93X_IRQ_ENABLE, OPTi93X_IRQ_ENABLE);
8951da177e4SLinus Torvalds 		chip->mode = mode;
8961da177e4SLinus Torvalds 	}
8971da177e4SLinus Torvalds 	else
8981da177e4SLinus Torvalds 		chip->mode |= mode;
8991da177e4SLinus Torvalds 
9001da177e4SLinus Torvalds 	spin_unlock_irqrestore(&chip->lock, flags);
9011da177e4SLinus Torvalds 	return 0;
9021da177e4SLinus Torvalds }
9031da177e4SLinus Torvalds 
9041da177e4SLinus Torvalds static void snd_opti93x_close(opti93x_t *chip, unsigned int mode)
9051da177e4SLinus Torvalds {
9061da177e4SLinus Torvalds 	unsigned long flags;
9071da177e4SLinus Torvalds 
9081da177e4SLinus Torvalds 	spin_lock_irqsave(&chip->lock, flags);
9091da177e4SLinus Torvalds 
9101da177e4SLinus Torvalds 	chip->mode &= ~mode;
9111da177e4SLinus Torvalds 	if (chip->mode & OPTi93X_MODE_OPEN) {
9121da177e4SLinus Torvalds 		spin_unlock_irqrestore(&chip->lock, flags);
9131da177e4SLinus Torvalds 		return;
9141da177e4SLinus Torvalds 	}
9151da177e4SLinus Torvalds 
9161da177e4SLinus Torvalds 	snd_opti93x_mute(chip, 1);
9171da177e4SLinus Torvalds 
9181da177e4SLinus Torvalds 	outb(0, OPTi93X_PORT(chip, STATUS));
9191da177e4SLinus Torvalds 	snd_opti93x_out_mask(chip, OPTi93X_PIN_CTRL, OPTi93X_IRQ_ENABLE,
9201da177e4SLinus Torvalds 		~OPTi93X_IRQ_ENABLE);
9211da177e4SLinus Torvalds 
9221da177e4SLinus Torvalds 	snd_opti93x_mce_up(chip);
9231da177e4SLinus Torvalds 	snd_opti93x_out_image(chip, OPTi93X_IFACE_CONF, 0x00);
9241da177e4SLinus Torvalds 	snd_opti93x_mce_down(chip);
9251da177e4SLinus Torvalds 	chip->mode = 0;
9261da177e4SLinus Torvalds 
9271da177e4SLinus Torvalds 	snd_opti93x_mute(chip, 0);
9281da177e4SLinus Torvalds 	spin_unlock_irqrestore(&chip->lock, flags);
9291da177e4SLinus Torvalds }
9301da177e4SLinus Torvalds 
9311da177e4SLinus Torvalds static int snd_opti93x_trigger(snd_pcm_substream_t *substream,
9321da177e4SLinus Torvalds 			       unsigned char what, int cmd)
9331da177e4SLinus Torvalds {
9341da177e4SLinus Torvalds 	opti93x_t *chip = snd_pcm_substream_chip(substream);
9351da177e4SLinus Torvalds 
9361da177e4SLinus Torvalds 	switch (cmd) {
9371da177e4SLinus Torvalds 	case SNDRV_PCM_TRIGGER_START:
9381da177e4SLinus Torvalds 	case SNDRV_PCM_TRIGGER_STOP:
9391da177e4SLinus Torvalds 	{
9401da177e4SLinus Torvalds 		unsigned int what = 0;
9411da177e4SLinus Torvalds 		struct list_head *pos;
9421da177e4SLinus Torvalds 		snd_pcm_substream_t *s;
9431da177e4SLinus Torvalds 		snd_pcm_group_for_each(pos, substream) {
9441da177e4SLinus Torvalds 			s = snd_pcm_group_substream_entry(pos);
9451da177e4SLinus Torvalds 			if (s == chip->playback_substream) {
9461da177e4SLinus Torvalds 				what |= OPTi93X_PLAYBACK_ENABLE;
9471da177e4SLinus Torvalds 				snd_pcm_trigger_done(s, substream);
9481da177e4SLinus Torvalds 			} else if (s == chip->capture_substream) {
9491da177e4SLinus Torvalds 				what |= OPTi93X_CAPTURE_ENABLE;
9501da177e4SLinus Torvalds 				snd_pcm_trigger_done(s, substream);
9511da177e4SLinus Torvalds 			}
9521da177e4SLinus Torvalds 		}
9531da177e4SLinus Torvalds 		spin_lock(&chip->lock);
9541da177e4SLinus Torvalds 		if (cmd == SNDRV_PCM_TRIGGER_START) {
9551da177e4SLinus Torvalds 			snd_opti93x_out_mask(chip, OPTi93X_IFACE_CONF, what, what);
9561da177e4SLinus Torvalds 			if (what & OPTi93X_CAPTURE_ENABLE)
9571da177e4SLinus Torvalds 				udelay(50);
9581da177e4SLinus Torvalds 		} else
9591da177e4SLinus Torvalds 			snd_opti93x_out_mask(chip, OPTi93X_IFACE_CONF, what, 0x00);
9601da177e4SLinus Torvalds 		spin_unlock(&chip->lock);
9611da177e4SLinus Torvalds 		break;
9621da177e4SLinus Torvalds 	}
9631da177e4SLinus Torvalds 	default:
9641da177e4SLinus Torvalds 		return -EINVAL;
9651da177e4SLinus Torvalds 	}
9661da177e4SLinus Torvalds 	return 0;
9671da177e4SLinus Torvalds }
9681da177e4SLinus Torvalds 
9691da177e4SLinus Torvalds static int snd_opti93x_playback_trigger(snd_pcm_substream_t *substream, int cmd)
9701da177e4SLinus Torvalds {
9711da177e4SLinus Torvalds 	return snd_opti93x_trigger(substream,
9721da177e4SLinus Torvalds 				   OPTi93X_PLAYBACK_ENABLE, cmd);
9731da177e4SLinus Torvalds }
9741da177e4SLinus Torvalds 
9751da177e4SLinus Torvalds static int snd_opti93x_capture_trigger(snd_pcm_substream_t * substream, int cmd)
9761da177e4SLinus Torvalds {
9771da177e4SLinus Torvalds 	return snd_opti93x_trigger(substream,
9781da177e4SLinus Torvalds 				   OPTi93X_CAPTURE_ENABLE, cmd);
9791da177e4SLinus Torvalds }
9801da177e4SLinus Torvalds 
9811da177e4SLinus Torvalds static int snd_opti93x_hw_params(snd_pcm_substream_t * substream,
9821da177e4SLinus Torvalds 				 snd_pcm_hw_params_t * hw_params)
9831da177e4SLinus Torvalds {
9841da177e4SLinus Torvalds 	return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
9851da177e4SLinus Torvalds }
9861da177e4SLinus Torvalds 
9871da177e4SLinus Torvalds 
9881da177e4SLinus Torvalds static int snd_opti93x_hw_free(snd_pcm_substream_t * substream)
9891da177e4SLinus Torvalds {
9901da177e4SLinus Torvalds 	snd_pcm_lib_free_pages(substream);
9911da177e4SLinus Torvalds 	return 0;
9921da177e4SLinus Torvalds }
9931da177e4SLinus Torvalds 
9941da177e4SLinus Torvalds 
9951da177e4SLinus Torvalds static int snd_opti93x_playback_prepare(snd_pcm_substream_t * substream)
9961da177e4SLinus Torvalds {
9971da177e4SLinus Torvalds 	opti93x_t *chip = snd_pcm_substream_chip(substream);
9981da177e4SLinus Torvalds 	snd_pcm_runtime_t *runtime = substream->runtime;
9991da177e4SLinus Torvalds 	unsigned long flags;
10001da177e4SLinus Torvalds 	unsigned char format;
10011da177e4SLinus Torvalds 	unsigned int count = snd_pcm_lib_period_bytes(substream);
10021da177e4SLinus Torvalds 	unsigned int size = snd_pcm_lib_buffer_bytes(substream);
10031da177e4SLinus Torvalds 
10041da177e4SLinus Torvalds 	spin_lock_irqsave(&chip->lock, flags);
10051da177e4SLinus Torvalds 
10061da177e4SLinus Torvalds 	chip->p_dma_size = size;
10071da177e4SLinus Torvalds 	snd_opti93x_out_mask(chip, OPTi93X_IFACE_CONF,
10081da177e4SLinus Torvalds 		OPTi93X_PLAYBACK_ENABLE | OPTi93X_PLAYBACK_PIO,
10091da177e4SLinus Torvalds 		~(OPTi93X_PLAYBACK_ENABLE | OPTi93X_PLAYBACK_PIO));
10101da177e4SLinus Torvalds 
10111da177e4SLinus Torvalds 	snd_dma_program(chip->dma1, runtime->dma_addr, size,
10121da177e4SLinus Torvalds 		DMA_MODE_WRITE | DMA_AUTOINIT);
10131da177e4SLinus Torvalds 
10141da177e4SLinus Torvalds 	format = snd_opti93x_get_freq(runtime->rate);
10151da177e4SLinus Torvalds 	format |= snd_opti93x_get_format(chip, runtime->format,
10161da177e4SLinus Torvalds 		runtime->channels);
10171da177e4SLinus Torvalds 	snd_opti93x_playback_format(chip, format);
10181da177e4SLinus Torvalds 	format = chip->image[OPTi93X_PLAY_FORMAT];
10191da177e4SLinus Torvalds 
10201da177e4SLinus Torvalds 	count = snd_opti93x_get_count(format, count) - 1;
10211da177e4SLinus Torvalds 	snd_opti93x_out_image(chip, OPTi93X_PLAY_LWR_CNT, count);
10221da177e4SLinus Torvalds 	snd_opti93x_out_image(chip, OPTi93X_PLAY_UPR_CNT, count >> 8);
10231da177e4SLinus Torvalds 
10241da177e4SLinus Torvalds 	spin_unlock_irqrestore(&chip->lock, flags);
10251da177e4SLinus Torvalds 	return 0;
10261da177e4SLinus Torvalds }
10271da177e4SLinus Torvalds 
10281da177e4SLinus Torvalds static int snd_opti93x_capture_prepare(snd_pcm_substream_t *substream)
10291da177e4SLinus Torvalds {
10301da177e4SLinus Torvalds 	opti93x_t *chip = snd_pcm_substream_chip(substream);
10311da177e4SLinus Torvalds 	snd_pcm_runtime_t *runtime = substream->runtime;
10321da177e4SLinus Torvalds 	unsigned long flags;
10331da177e4SLinus Torvalds 	unsigned char format;
10341da177e4SLinus Torvalds 	unsigned int count = snd_pcm_lib_period_bytes(substream);
10351da177e4SLinus Torvalds 	unsigned int size = snd_pcm_lib_buffer_bytes(substream);
10361da177e4SLinus Torvalds 
10371da177e4SLinus Torvalds 	spin_lock_irqsave(&chip->lock, flags);
10381da177e4SLinus Torvalds 
10391da177e4SLinus Torvalds 	chip->c_dma_size = size;
10401da177e4SLinus Torvalds 	snd_opti93x_out_mask(chip, OPTi93X_IFACE_CONF,
1041db67319aSClemens Ladisch 		OPTi93X_CAPTURE_ENABLE | OPTi93X_CAPTURE_PIO, 0);
10421da177e4SLinus Torvalds 
10431da177e4SLinus Torvalds 	snd_dma_program(chip->dma2, runtime->dma_addr, size,
10441da177e4SLinus Torvalds 		DMA_MODE_READ | DMA_AUTOINIT);
10451da177e4SLinus Torvalds 
10461da177e4SLinus Torvalds 	format = snd_opti93x_get_freq(runtime->rate);
10471da177e4SLinus Torvalds 	format |= snd_opti93x_get_format(chip, runtime->format,
10481da177e4SLinus Torvalds 		runtime->channels);
10491da177e4SLinus Torvalds 	snd_opti93x_capture_format(chip, format);
10501da177e4SLinus Torvalds 	format = chip->image[OPTi93X_CAPT_FORMAT];
10511da177e4SLinus Torvalds 
10521da177e4SLinus Torvalds 	count = snd_opti93x_get_count(format, count) - 1;
10531da177e4SLinus Torvalds 	snd_opti93x_out_image(chip, OPTi93X_CAPT_LWR_CNT, count);
10541da177e4SLinus Torvalds 	snd_opti93x_out_image(chip, OPTi93X_CAPT_UPR_CNT, count >> 8);
10551da177e4SLinus Torvalds 
10561da177e4SLinus Torvalds 	spin_unlock_irqrestore(&chip->lock, flags);
10571da177e4SLinus Torvalds 	return 0;
10581da177e4SLinus Torvalds }
10591da177e4SLinus Torvalds 
10601da177e4SLinus Torvalds static snd_pcm_uframes_t snd_opti93x_playback_pointer(snd_pcm_substream_t *substream)
10611da177e4SLinus Torvalds {
10621da177e4SLinus Torvalds 	opti93x_t *chip = snd_pcm_substream_chip(substream);
10631da177e4SLinus Torvalds 	size_t ptr;
10641da177e4SLinus Torvalds 
10651da177e4SLinus Torvalds 	if (!(chip->image[OPTi93X_IFACE_CONF] & OPTi93X_PLAYBACK_ENABLE))
10661da177e4SLinus Torvalds 		return 0;
10671da177e4SLinus Torvalds 
10681da177e4SLinus Torvalds 	ptr = snd_dma_pointer(chip->dma1, chip->p_dma_size);
10691da177e4SLinus Torvalds 	return bytes_to_frames(substream->runtime, ptr);
10701da177e4SLinus Torvalds }
10711da177e4SLinus Torvalds 
10721da177e4SLinus Torvalds static snd_pcm_uframes_t snd_opti93x_capture_pointer(snd_pcm_substream_t *substream)
10731da177e4SLinus Torvalds {
10741da177e4SLinus Torvalds 	opti93x_t *chip = snd_pcm_substream_chip(substream);
10751da177e4SLinus Torvalds 	size_t ptr;
10761da177e4SLinus Torvalds 
10771da177e4SLinus Torvalds 	if (!(chip->image[OPTi93X_IFACE_CONF] & OPTi93X_CAPTURE_ENABLE))
10781da177e4SLinus Torvalds 		return 0;
10791da177e4SLinus Torvalds 
10801da177e4SLinus Torvalds 	ptr = snd_dma_pointer(chip->dma2, chip->c_dma_size);
10811da177e4SLinus Torvalds 	return bytes_to_frames(substream->runtime, ptr);
10821da177e4SLinus Torvalds }
10831da177e4SLinus Torvalds 
10841da177e4SLinus Torvalds 
10851da177e4SLinus Torvalds static void snd_opti93x_overrange(opti93x_t *chip)
10861da177e4SLinus Torvalds {
10871da177e4SLinus Torvalds 	unsigned long flags;
10881da177e4SLinus Torvalds 
10891da177e4SLinus Torvalds 	spin_lock_irqsave(&chip->lock, flags);
10901da177e4SLinus Torvalds 
10911da177e4SLinus Torvalds 	if (snd_opti93x_in(chip, OPTi93X_ERR_INIT) & (0x08 | 0x02))
10921da177e4SLinus Torvalds 		chip->capture_substream->runtime->overrange++;
10931da177e4SLinus Torvalds 
10941da177e4SLinus Torvalds 	spin_unlock_irqrestore(&chip->lock, flags);
10951da177e4SLinus Torvalds }
10961da177e4SLinus Torvalds 
10971da177e4SLinus Torvalds static irqreturn_t snd_opti93x_interrupt(int irq, void *dev_id, struct pt_regs *regs)
10981da177e4SLinus Torvalds {
10991da177e4SLinus Torvalds 	opti93x_t *codec = dev_id;
11001da177e4SLinus Torvalds 	unsigned char status;
11011da177e4SLinus Torvalds 
11021da177e4SLinus Torvalds 	status = snd_opti9xx_read(codec->chip, OPTi9XX_MC_REG(11));
11031da177e4SLinus Torvalds 	if ((status & OPTi93X_IRQ_PLAYBACK) && codec->playback_substream)
11041da177e4SLinus Torvalds 		snd_pcm_period_elapsed(codec->playback_substream);
11051da177e4SLinus Torvalds 	if ((status & OPTi93X_IRQ_CAPTURE) && codec->capture_substream) {
11061da177e4SLinus Torvalds 		snd_opti93x_overrange(codec);
11071da177e4SLinus Torvalds 		snd_pcm_period_elapsed(codec->capture_substream);
11081da177e4SLinus Torvalds 	}
11091da177e4SLinus Torvalds 	outb(0x00, OPTi93X_PORT(codec, STATUS));
11101da177e4SLinus Torvalds 	return IRQ_HANDLED;
11111da177e4SLinus Torvalds }
11121da177e4SLinus Torvalds 
11131da177e4SLinus Torvalds 
11141da177e4SLinus Torvalds static snd_pcm_hardware_t snd_opti93x_playback = {
11151da177e4SLinus Torvalds 	.info =			(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
11161da177e4SLinus Torvalds 				 SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START),
11171da177e4SLinus Torvalds 	.formats =		(SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW | SNDRV_PCM_FMTBIT_IMA_ADPCM |
11181da177e4SLinus Torvalds 				 SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE),
11191da177e4SLinus Torvalds 	.rates =		SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
11201da177e4SLinus Torvalds 	.rate_min =		5512,
11211da177e4SLinus Torvalds 	.rate_max =		48000,
11221da177e4SLinus Torvalds 	.channels_min =		1,
11231da177e4SLinus Torvalds 	.channels_max =		2,
11241da177e4SLinus Torvalds 	.buffer_bytes_max =	(128*1024),
11251da177e4SLinus Torvalds 	.period_bytes_min =	64,
11261da177e4SLinus Torvalds 	.period_bytes_max =	(128*1024),
11271da177e4SLinus Torvalds 	.periods_min =		1,
11281da177e4SLinus Torvalds 	.periods_max =		1024,
11291da177e4SLinus Torvalds 	.fifo_size =		0,
11301da177e4SLinus Torvalds };
11311da177e4SLinus Torvalds 
11321da177e4SLinus Torvalds static snd_pcm_hardware_t snd_opti93x_capture = {
11331da177e4SLinus Torvalds 	.info =			(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
11341da177e4SLinus Torvalds 				 SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START),
11351da177e4SLinus Torvalds 	.formats =		(SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW | SNDRV_PCM_FMTBIT_IMA_ADPCM |
11361da177e4SLinus Torvalds 				 SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE),
11371da177e4SLinus Torvalds 	.rates =		SNDRV_PCM_RATE_8000_48000,
11381da177e4SLinus Torvalds 	.rate_min =		5512,
11391da177e4SLinus Torvalds 	.rate_max =		48000,
11401da177e4SLinus Torvalds 	.channels_min =		1,
11411da177e4SLinus Torvalds 	.channels_max =		2,
11421da177e4SLinus Torvalds 	.buffer_bytes_max =	(128*1024),
11431da177e4SLinus Torvalds 	.period_bytes_min =	64,
11441da177e4SLinus Torvalds 	.period_bytes_max =	(128*1024),
11451da177e4SLinus Torvalds 	.periods_min =		1,
11461da177e4SLinus Torvalds 	.periods_max =		1024,
11471da177e4SLinus Torvalds 	.fifo_size =		0,
11481da177e4SLinus Torvalds };
11491da177e4SLinus Torvalds 
11501da177e4SLinus Torvalds static int snd_opti93x_playback_open(snd_pcm_substream_t *substream)
11511da177e4SLinus Torvalds {
11521da177e4SLinus Torvalds 	int error;
11531da177e4SLinus Torvalds 	opti93x_t *chip = snd_pcm_substream_chip(substream);
11541da177e4SLinus Torvalds 	snd_pcm_runtime_t *runtime = substream->runtime;
11551da177e4SLinus Torvalds 
11561da177e4SLinus Torvalds 	if ((error = snd_opti93x_open(chip, OPTi93X_MODE_PLAY)) < 0)
11571da177e4SLinus Torvalds 		return error;
11581da177e4SLinus Torvalds 	snd_pcm_set_sync(substream);
11591da177e4SLinus Torvalds 	chip->playback_substream = substream;
11601da177e4SLinus Torvalds 	runtime->hw = snd_opti93x_playback;
11611da177e4SLinus Torvalds 	snd_pcm_limit_isa_dma_size(chip->dma1, &runtime->hw.buffer_bytes_max);
11621da177e4SLinus Torvalds 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
11631da177e4SLinus Torvalds 	return error;
11641da177e4SLinus Torvalds }
11651da177e4SLinus Torvalds 
11661da177e4SLinus Torvalds static int snd_opti93x_capture_open(snd_pcm_substream_t *substream)
11671da177e4SLinus Torvalds {
11681da177e4SLinus Torvalds 	int error;
11691da177e4SLinus Torvalds 	opti93x_t *chip = snd_pcm_substream_chip(substream);
11701da177e4SLinus Torvalds 	snd_pcm_runtime_t *runtime = substream->runtime;
11711da177e4SLinus Torvalds 
11721da177e4SLinus Torvalds 	if ((error = snd_opti93x_open(chip, OPTi93X_MODE_CAPTURE)) < 0)
11731da177e4SLinus Torvalds 		return error;
11741da177e4SLinus Torvalds 	runtime->hw = snd_opti93x_capture;
11751da177e4SLinus Torvalds 	snd_pcm_set_sync(substream);
11761da177e4SLinus Torvalds 	chip->capture_substream = substream;
11771da177e4SLinus Torvalds 	snd_pcm_limit_isa_dma_size(chip->dma2, &runtime->hw.buffer_bytes_max);
11781da177e4SLinus Torvalds 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
11791da177e4SLinus Torvalds 	return error;
11801da177e4SLinus Torvalds }
11811da177e4SLinus Torvalds 
11821da177e4SLinus Torvalds static int snd_opti93x_playback_close(snd_pcm_substream_t *substream)
11831da177e4SLinus Torvalds {
11841da177e4SLinus Torvalds 	opti93x_t *chip = snd_pcm_substream_chip(substream);
11851da177e4SLinus Torvalds 
11861da177e4SLinus Torvalds 	chip->playback_substream = NULL;
11871da177e4SLinus Torvalds 	snd_opti93x_close(chip, OPTi93X_MODE_PLAY);
11881da177e4SLinus Torvalds 	return 0;
11891da177e4SLinus Torvalds }
11901da177e4SLinus Torvalds 
11911da177e4SLinus Torvalds static int snd_opti93x_capture_close(snd_pcm_substream_t *substream)
11921da177e4SLinus Torvalds {
11931da177e4SLinus Torvalds 	opti93x_t *chip = snd_pcm_substream_chip(substream);
11941da177e4SLinus Torvalds 
11951da177e4SLinus Torvalds 	chip->capture_substream = NULL;
11961da177e4SLinus Torvalds 	snd_opti93x_close(chip, OPTi93X_MODE_CAPTURE);
11971da177e4SLinus Torvalds 	return 0;
11981da177e4SLinus Torvalds }
11991da177e4SLinus Torvalds 
12001da177e4SLinus Torvalds 
12011da177e4SLinus Torvalds static void snd_opti93x_init(opti93x_t *chip)
12021da177e4SLinus Torvalds {
12031da177e4SLinus Torvalds 	unsigned long flags;
12041da177e4SLinus Torvalds 	int i;
12051da177e4SLinus Torvalds 
12061da177e4SLinus Torvalds 	spin_lock_irqsave(&chip->lock, flags);
12071da177e4SLinus Torvalds 	snd_opti93x_mce_up(chip);
12081da177e4SLinus Torvalds 
12091da177e4SLinus Torvalds 	for (i = 0; i < 32; i++)
12101da177e4SLinus Torvalds 		snd_opti93x_out_image(chip, i, snd_opti93x_default_image[i]);
12111da177e4SLinus Torvalds 
12121da177e4SLinus Torvalds 	snd_opti93x_mce_down(chip);
12131da177e4SLinus Torvalds 	spin_unlock_irqrestore(&chip->lock, flags);
12141da177e4SLinus Torvalds }
12151da177e4SLinus Torvalds 
12161da177e4SLinus Torvalds static int snd_opti93x_probe(opti93x_t *chip)
12171da177e4SLinus Torvalds {
12181da177e4SLinus Torvalds 	unsigned long flags;
12191da177e4SLinus Torvalds 	unsigned char val;
12201da177e4SLinus Torvalds 
12211da177e4SLinus Torvalds 	spin_lock_irqsave(&chip->lock, flags);
12221da177e4SLinus Torvalds 	val = snd_opti93x_in(chip, OPTi93X_ID) & 0x0f;
12231da177e4SLinus Torvalds 	spin_unlock_irqrestore(&chip->lock, flags);
12241da177e4SLinus Torvalds 
12251da177e4SLinus Torvalds 	return (val == 0x0a) ? 0 : -ENODEV;
12261da177e4SLinus Torvalds }
12271da177e4SLinus Torvalds 
12281da177e4SLinus Torvalds static int snd_opti93x_free(opti93x_t *chip)
12291da177e4SLinus Torvalds {
12301da177e4SLinus Torvalds 	if (chip->res_port) {
12311da177e4SLinus Torvalds 		release_resource(chip->res_port);
12321da177e4SLinus Torvalds 		kfree_nocheck(chip->res_port);
12331da177e4SLinus Torvalds 	}
12341da177e4SLinus Torvalds 	if (chip->dma1 >= 0) {
12351da177e4SLinus Torvalds 		disable_dma(chip->dma1);
12361da177e4SLinus Torvalds 		free_dma(chip->dma1);
12371da177e4SLinus Torvalds 	}
12381da177e4SLinus Torvalds 	if (chip->dma2 >= 0) {
12391da177e4SLinus Torvalds 		disable_dma(chip->dma2);
12401da177e4SLinus Torvalds 		free_dma(chip->dma2);
12411da177e4SLinus Torvalds 	}
12421da177e4SLinus Torvalds 	if (chip->irq >= 0) {
12431da177e4SLinus Torvalds 	  free_irq(chip->irq, chip);
12441da177e4SLinus Torvalds 	}
12451da177e4SLinus Torvalds 	kfree(chip);
12461da177e4SLinus Torvalds 	return 0;
12471da177e4SLinus Torvalds }
12481da177e4SLinus Torvalds 
12491da177e4SLinus Torvalds static int snd_opti93x_dev_free(snd_device_t *device)
12501da177e4SLinus Torvalds {
12511da177e4SLinus Torvalds 	opti93x_t *chip = device->device_data;
12521da177e4SLinus Torvalds 	return snd_opti93x_free(chip);
12531da177e4SLinus Torvalds }
12541da177e4SLinus Torvalds 
12551da177e4SLinus Torvalds static const char *snd_opti93x_chip_id(opti93x_t *codec)
12561da177e4SLinus Torvalds {
12571da177e4SLinus Torvalds 	switch (codec->hardware) {
12581da177e4SLinus Torvalds 	case OPTi9XX_HW_82C930: return "82C930";
12591da177e4SLinus Torvalds 	case OPTi9XX_HW_82C931: return "82C931";
12601da177e4SLinus Torvalds 	case OPTi9XX_HW_82C933: return "82C933";
12611da177e4SLinus Torvalds 	default:		return "???";
12621da177e4SLinus Torvalds 	}
12631da177e4SLinus Torvalds }
12641da177e4SLinus Torvalds 
12651da177e4SLinus Torvalds static int snd_opti93x_create(snd_card_t *card, opti9xx_t *chip,
12661da177e4SLinus Torvalds 			      int dma1, int dma2,
12671da177e4SLinus Torvalds 			      opti93x_t **rcodec)
12681da177e4SLinus Torvalds {
12691da177e4SLinus Torvalds 	static snd_device_ops_t ops = {
12701da177e4SLinus Torvalds 		.dev_free =	snd_opti93x_dev_free,
12711da177e4SLinus Torvalds 	};
12721da177e4SLinus Torvalds 	int error;
12731da177e4SLinus Torvalds 	opti93x_t *codec;
12741da177e4SLinus Torvalds 
12751da177e4SLinus Torvalds 	*rcodec = NULL;
1276*9e76a76eSTakashi Iwai 	codec = kzalloc(sizeof(*codec), GFP_KERNEL);
12771da177e4SLinus Torvalds 	if (codec == NULL)
12781da177e4SLinus Torvalds 		return -ENOMEM;
12791da177e4SLinus Torvalds 	codec->irq = -1;
12801da177e4SLinus Torvalds 	codec->dma1 = -1;
12811da177e4SLinus Torvalds 	codec->dma2 = -1;
12821da177e4SLinus Torvalds 
12831da177e4SLinus Torvalds 	if ((codec->res_port = request_region(chip->wss_base + 4, 4, "OPTI93x CODEC")) == NULL) {
12841da177e4SLinus Torvalds 		snd_printk(KERN_ERR "opti9xx: can't grab port 0x%lx\n", chip->wss_base + 4);
12851da177e4SLinus Torvalds 		snd_opti93x_free(codec);
12861da177e4SLinus Torvalds 		return -EBUSY;
12871da177e4SLinus Torvalds 	}
12881da177e4SLinus Torvalds 	if (request_dma(dma1, "OPTI93x - 1")) {
12891da177e4SLinus Torvalds 		snd_printk(KERN_ERR "opti9xx: can't grab DMA1 %d\n", dma1);
12901da177e4SLinus Torvalds 		snd_opti93x_free(codec);
12911da177e4SLinus Torvalds 		return -EBUSY;
12921da177e4SLinus Torvalds 	}
12931da177e4SLinus Torvalds 	codec->dma1 = chip->dma1;
12941da177e4SLinus Torvalds 	if (request_dma(dma2, "OPTI93x - 2")) {
12951da177e4SLinus Torvalds 		snd_printk(KERN_ERR "opti9xx: can't grab DMA2 %d\n", dma2);
12961da177e4SLinus Torvalds 		snd_opti93x_free(codec);
12971da177e4SLinus Torvalds 		return -EBUSY;
12981da177e4SLinus Torvalds 	}
12991da177e4SLinus Torvalds 	codec->dma2 = chip->dma2;
13001da177e4SLinus Torvalds 
13011da177e4SLinus Torvalds 	if (request_irq(chip->irq, snd_opti93x_interrupt, SA_INTERRUPT, DRIVER_NAME" - WSS", codec)) {
13021da177e4SLinus Torvalds 		snd_printk(KERN_ERR "opti9xx: can't grab IRQ %d\n", chip->irq);
13031da177e4SLinus Torvalds 		snd_opti93x_free(codec);
13041da177e4SLinus Torvalds 		return -EBUSY;
13051da177e4SLinus Torvalds 	}
13061da177e4SLinus Torvalds 
13071da177e4SLinus Torvalds 	codec->card = card;
13081da177e4SLinus Torvalds 	codec->port = chip->wss_base + 4;
13091da177e4SLinus Torvalds 	codec->irq = chip->irq;
13101da177e4SLinus Torvalds 
13111da177e4SLinus Torvalds 	spin_lock_init(&codec->lock);
13121da177e4SLinus Torvalds 	codec->hardware = chip->hardware;
13131da177e4SLinus Torvalds 	codec->chip = chip;
13141da177e4SLinus Torvalds 
13151da177e4SLinus Torvalds 	if ((error = snd_opti93x_probe(codec))) {
13161da177e4SLinus Torvalds 		snd_opti93x_free(codec);
13171da177e4SLinus Torvalds 		return error;
13181da177e4SLinus Torvalds 	}
13191da177e4SLinus Torvalds 
13201da177e4SLinus Torvalds 	snd_opti93x_init(codec);
13211da177e4SLinus Torvalds 
13221da177e4SLinus Torvalds 	/* Register device */
13231da177e4SLinus Torvalds 	if ((error = snd_device_new(card, SNDRV_DEV_LOWLEVEL, codec, &ops)) < 0) {
13241da177e4SLinus Torvalds 		snd_opti93x_free(codec);
13251da177e4SLinus Torvalds 		return error;
13261da177e4SLinus Torvalds 	}
13271da177e4SLinus Torvalds 
13281da177e4SLinus Torvalds 	*rcodec = codec;
13291da177e4SLinus Torvalds 	return 0;
13301da177e4SLinus Torvalds }
13311da177e4SLinus Torvalds 
13321da177e4SLinus Torvalds static snd_pcm_ops_t snd_opti93x_playback_ops = {
13331da177e4SLinus Torvalds 	.open =		snd_opti93x_playback_open,
13341da177e4SLinus Torvalds 	.close =	snd_opti93x_playback_close,
13351da177e4SLinus Torvalds 	.ioctl =	snd_pcm_lib_ioctl,
13361da177e4SLinus Torvalds 	.hw_params =	snd_opti93x_hw_params,
13371da177e4SLinus Torvalds 	.hw_free =	snd_opti93x_hw_free,
13381da177e4SLinus Torvalds 	.prepare =	snd_opti93x_playback_prepare,
13391da177e4SLinus Torvalds 	.trigger =	snd_opti93x_playback_trigger,
13401da177e4SLinus Torvalds 	.pointer =	snd_opti93x_playback_pointer,
13411da177e4SLinus Torvalds };
13421da177e4SLinus Torvalds 
13431da177e4SLinus Torvalds static snd_pcm_ops_t snd_opti93x_capture_ops = {
13441da177e4SLinus Torvalds 	.open =		snd_opti93x_capture_open,
13451da177e4SLinus Torvalds 	.close =	snd_opti93x_capture_close,
13461da177e4SLinus Torvalds 	.ioctl =	snd_pcm_lib_ioctl,
13471da177e4SLinus Torvalds 	.hw_params =	snd_opti93x_hw_params,
13481da177e4SLinus Torvalds 	.hw_free =	snd_opti93x_hw_free,
13491da177e4SLinus Torvalds 	.prepare =	snd_opti93x_capture_prepare,
13501da177e4SLinus Torvalds 	.trigger =	snd_opti93x_capture_trigger,
13511da177e4SLinus Torvalds 	.pointer =	snd_opti93x_capture_pointer,
13521da177e4SLinus Torvalds };
13531da177e4SLinus Torvalds 
13541da177e4SLinus Torvalds static void snd_opti93x_pcm_free(snd_pcm_t *pcm)
13551da177e4SLinus Torvalds {
13561da177e4SLinus Torvalds 	opti93x_t *codec = pcm->private_data;
13571da177e4SLinus Torvalds 	codec->pcm = NULL;
13581da177e4SLinus Torvalds 	snd_pcm_lib_preallocate_free_for_all(pcm);
13591da177e4SLinus Torvalds }
13601da177e4SLinus Torvalds 
13611da177e4SLinus Torvalds static int snd_opti93x_pcm(opti93x_t *codec, int device, snd_pcm_t **rpcm)
13621da177e4SLinus Torvalds {
13631da177e4SLinus Torvalds 	int error;
13641da177e4SLinus Torvalds 	snd_pcm_t *pcm;
13651da177e4SLinus Torvalds 
13661da177e4SLinus Torvalds 	if ((error = snd_pcm_new(codec->card, "OPTi 82C93X", device, 1, 1, &pcm)))
13671da177e4SLinus Torvalds 		return error;
13681da177e4SLinus Torvalds 
13691da177e4SLinus Torvalds 	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_opti93x_playback_ops);
13701da177e4SLinus Torvalds 	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_opti93x_capture_ops);
13711da177e4SLinus Torvalds 
13721da177e4SLinus Torvalds 	pcm->private_data = codec;
13731da177e4SLinus Torvalds 	pcm->private_free = snd_opti93x_pcm_free;
13741da177e4SLinus Torvalds 	pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX;
13751da177e4SLinus Torvalds 
13761da177e4SLinus Torvalds 	strcpy(pcm->name, snd_opti93x_chip_id(codec));
13771da177e4SLinus Torvalds 
13781da177e4SLinus Torvalds 	snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
13791da177e4SLinus Torvalds 					      snd_dma_isa_data(),
13801da177e4SLinus Torvalds 					      64*1024, codec->dma1 > 3 || codec->dma2 > 3 ? 128*1024 : 64*1024);
13811da177e4SLinus Torvalds 
13821da177e4SLinus Torvalds 	codec->pcm = pcm;
13831da177e4SLinus Torvalds 	if (rpcm)
13841da177e4SLinus Torvalds 		*rpcm = pcm;
13851da177e4SLinus Torvalds 	return 0;
13861da177e4SLinus Torvalds }
13871da177e4SLinus Torvalds 
13881da177e4SLinus Torvalds /*
13891da177e4SLinus Torvalds  *  MIXER part
13901da177e4SLinus Torvalds  */
13911da177e4SLinus Torvalds 
13921da177e4SLinus Torvalds static int snd_opti93x_info_mux(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
13931da177e4SLinus Torvalds {
13941da177e4SLinus Torvalds 	static char *texts[4] = {
13951da177e4SLinus Torvalds 		"Line1", "Aux", "Mic", "Mix"
13961da177e4SLinus Torvalds 	};
13971da177e4SLinus Torvalds 
13981da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
13991da177e4SLinus Torvalds 	uinfo->count = 2;
14001da177e4SLinus Torvalds 	uinfo->value.enumerated.items = 4;
14011da177e4SLinus Torvalds 	if (uinfo->value.enumerated.item > 3)
14021da177e4SLinus Torvalds 		uinfo->value.enumerated.item = 3;
14031da177e4SLinus Torvalds 	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
14041da177e4SLinus Torvalds 	return 0;
14051da177e4SLinus Torvalds }
14061da177e4SLinus Torvalds 
14071da177e4SLinus Torvalds static int snd_opti93x_get_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
14081da177e4SLinus Torvalds {
14091da177e4SLinus Torvalds 	opti93x_t *chip = snd_kcontrol_chip(kcontrol);
14101da177e4SLinus Torvalds 	unsigned long flags;
14111da177e4SLinus Torvalds 
14121da177e4SLinus Torvalds 	spin_lock_irqsave(&chip->lock, flags);
14131da177e4SLinus Torvalds 	ucontrol->value.enumerated.item[0] = (chip->image[OPTi93X_MIXOUT_LEFT] & OPTi93X_MIXOUT_MIXER) >> 6;
14141da177e4SLinus Torvalds 	ucontrol->value.enumerated.item[1] = (chip->image[OPTi93X_MIXOUT_RIGHT] & OPTi93X_MIXOUT_MIXER) >> 6;
14151da177e4SLinus Torvalds 	spin_unlock_irqrestore(&chip->lock, flags);
14161da177e4SLinus Torvalds 	return 0;
14171da177e4SLinus Torvalds }
14181da177e4SLinus Torvalds 
14191da177e4SLinus Torvalds static int snd_opti93x_put_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
14201da177e4SLinus Torvalds {
14211da177e4SLinus Torvalds 	opti93x_t *chip = snd_kcontrol_chip(kcontrol);
14221da177e4SLinus Torvalds 	unsigned long flags;
14231da177e4SLinus Torvalds 	unsigned short left, right;
14241da177e4SLinus Torvalds 	int change;
14251da177e4SLinus Torvalds 
14261da177e4SLinus Torvalds 	if (ucontrol->value.enumerated.item[0] > 3 ||
14271da177e4SLinus Torvalds 	    ucontrol->value.enumerated.item[1] > 3)
14281da177e4SLinus Torvalds 		return -EINVAL;
14291da177e4SLinus Torvalds 	left = ucontrol->value.enumerated.item[0] << 6;
14301da177e4SLinus Torvalds 	right = ucontrol->value.enumerated.item[1] << 6;
14311da177e4SLinus Torvalds 	spin_lock_irqsave(&chip->lock, flags);
14321da177e4SLinus Torvalds 	left = (chip->image[OPTi93X_MIXOUT_LEFT] & ~OPTi93X_MIXOUT_MIXER) | left;
14331da177e4SLinus Torvalds 	right = (chip->image[OPTi93X_MIXOUT_RIGHT] & ~OPTi93X_MIXOUT_MIXER) | right;
14341da177e4SLinus Torvalds 	change = left != chip->image[OPTi93X_MIXOUT_LEFT] ||
14351da177e4SLinus Torvalds 	         right != chip->image[OPTi93X_MIXOUT_RIGHT];
14361da177e4SLinus Torvalds 	snd_opti93x_out_image(chip, OPTi93X_MIXOUT_LEFT, left);
14371da177e4SLinus Torvalds 	snd_opti93x_out_image(chip, OPTi93X_MIXOUT_RIGHT, right);
14381da177e4SLinus Torvalds 	spin_unlock_irqrestore(&chip->lock, flags);
14391da177e4SLinus Torvalds 	return change;
14401da177e4SLinus Torvalds }
14411da177e4SLinus Torvalds 
14421da177e4SLinus Torvalds #if 0
14431da177e4SLinus Torvalds 
14441da177e4SLinus Torvalds #define OPTi93X_SINGLE(xname, xindex, reg, shift, mask, invert) \
14451da177e4SLinus Torvalds { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
14461da177e4SLinus Torvalds   .info = snd_opti93x_info_single, \
14471da177e4SLinus Torvalds   .get = snd_opti93x_get_single, .put = snd_opti93x_put_single, \
14481da177e4SLinus Torvalds   .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
14491da177e4SLinus Torvalds 
14501da177e4SLinus Torvalds static int snd_opti93x_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
14511da177e4SLinus Torvalds {
14521da177e4SLinus Torvalds 	int mask = (kcontrol->private_value >> 16) & 0xff;
14531da177e4SLinus Torvalds 
14541da177e4SLinus Torvalds 	uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
14551da177e4SLinus Torvalds 	uinfo->count = 1;
14561da177e4SLinus Torvalds 	uinfo->value.integer.min = 0;
14571da177e4SLinus Torvalds 	uinfo->value.integer.max = mask;
14581da177e4SLinus Torvalds 	return 0;
14591da177e4SLinus Torvalds }
14601da177e4SLinus Torvalds 
14611da177e4SLinus Torvalds static int snd_opti93x_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
14621da177e4SLinus Torvalds {
14631da177e4SLinus Torvalds 	opti93x_t *chip = snd_kcontrol_chip(kcontrol);
14641da177e4SLinus Torvalds 	unsigned long flags;
14651da177e4SLinus Torvalds 	int reg = kcontrol->private_value & 0xff;
14661da177e4SLinus Torvalds 	int shift = (kcontrol->private_value >> 8) & 0xff;
14671da177e4SLinus Torvalds 	int mask = (kcontrol->private_value >> 16) & 0xff;
14681da177e4SLinus Torvalds 	int invert = (kcontrol->private_value >> 24) & 0xff;
14691da177e4SLinus Torvalds 
14701da177e4SLinus Torvalds 	spin_lock_irqsave(&chip->lock, flags);
14711da177e4SLinus Torvalds 	ucontrol->value.integer.value[0] = (chip->image[reg] >> shift) & mask;
14721da177e4SLinus Torvalds 	spin_unlock_irqrestore(&chip->lock, flags);
14731da177e4SLinus Torvalds 	if (invert)
14741da177e4SLinus Torvalds 		ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
14751da177e4SLinus Torvalds 	return 0;
14761da177e4SLinus Torvalds }
14771da177e4SLinus Torvalds 
14781da177e4SLinus Torvalds static int snd_opti93x_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
14791da177e4SLinus Torvalds {
14801da177e4SLinus Torvalds 	opti93x_t *chip = snd_kcontrol_chip(kcontrol);
14811da177e4SLinus Torvalds 	unsigned long flags;
14821da177e4SLinus Torvalds 	int reg = kcontrol->private_value & 0xff;
14831da177e4SLinus Torvalds 	int shift = (kcontrol->private_value >> 8) & 0xff;
14841da177e4SLinus Torvalds 	int mask = (kcontrol->private_value >> 16) & 0xff;
14851da177e4SLinus Torvalds 	int invert = (kcontrol->private_value >> 24) & 0xff;
14861da177e4SLinus Torvalds 	int change;
14871da177e4SLinus Torvalds 	unsigned short val;
14881da177e4SLinus Torvalds 
14891da177e4SLinus Torvalds 	val = (ucontrol->value.integer.value[0] & mask);
14901da177e4SLinus Torvalds 	if (invert)
14911da177e4SLinus Torvalds 		val = mask - val;
14921da177e4SLinus Torvalds 	val <<= shift;
14931da177e4SLinus Torvalds 	spin_lock_irqsave(&chip->lock, flags);
14941da177e4SLinus Torvalds 	val = (chip->image[reg] & ~(mask << shift)) | val;
14951da177e4SLinus Torvalds 	change = val != chip->image[reg];
14961da177e4SLinus Torvalds 	snd_opti93x_out(chip, reg, val);
14971da177e4SLinus Torvalds 	spin_unlock_irqrestore(&chip->lock, flags);
14981da177e4SLinus Torvalds 	return change;
14991da177e4SLinus Torvalds }
15001da177e4SLinus Torvalds 
15011da177e4SLinus Torvalds #endif /* single */
15021da177e4SLinus Torvalds 
15031da177e4SLinus Torvalds #define OPTi93X_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
15041da177e4SLinus Torvalds { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
15051da177e4SLinus Torvalds   .info = snd_opti93x_info_double, \
15061da177e4SLinus Torvalds   .get = snd_opti93x_get_double, .put = snd_opti93x_put_double, \
15071da177e4SLinus Torvalds   .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
15081da177e4SLinus Torvalds 
15091da177e4SLinus Torvalds #define OPTi93X_DOUBLE_INVERT_INVERT(xctl) \
15101da177e4SLinus Torvalds 	do { xctl.private_value ^= 22; } while (0)
15111da177e4SLinus Torvalds #define OPTi93X_DOUBLE_CHANGE_REGS(xctl, left_reg, right_reg) \
15121da177e4SLinus Torvalds 	do { xctl.private_value &= ~0x0000ffff; \
15131da177e4SLinus Torvalds 	     xctl.private_value |= left_reg | (right_reg << 8); } while (0)
15141da177e4SLinus Torvalds 
15151da177e4SLinus Torvalds static int snd_opti93x_info_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
15161da177e4SLinus Torvalds {
15171da177e4SLinus Torvalds 	int mask = (kcontrol->private_value >> 24) & 0xff;
15181da177e4SLinus Torvalds 
15191da177e4SLinus Torvalds 	uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
15201da177e4SLinus Torvalds 	uinfo->count = 2;
15211da177e4SLinus Torvalds 	uinfo->value.integer.min = 0;
15221da177e4SLinus Torvalds 	uinfo->value.integer.max = mask;
15231da177e4SLinus Torvalds 	return 0;
15241da177e4SLinus Torvalds }
15251da177e4SLinus Torvalds 
15261da177e4SLinus Torvalds static int snd_opti93x_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
15271da177e4SLinus Torvalds {
15281da177e4SLinus Torvalds 	opti93x_t *chip = snd_kcontrol_chip(kcontrol);
15291da177e4SLinus Torvalds 	unsigned long flags;
15301da177e4SLinus Torvalds 	int left_reg = kcontrol->private_value & 0xff;
15311da177e4SLinus Torvalds 	int right_reg = (kcontrol->private_value >> 8) & 0xff;
15321da177e4SLinus Torvalds 	int shift_left = (kcontrol->private_value >> 16) & 0x07;
15331da177e4SLinus Torvalds 	int shift_right = (kcontrol->private_value >> 19) & 0x07;
15341da177e4SLinus Torvalds 	int mask = (kcontrol->private_value >> 24) & 0xff;
15351da177e4SLinus Torvalds 	int invert = (kcontrol->private_value >> 22) & 1;
15361da177e4SLinus Torvalds 
15371da177e4SLinus Torvalds 	spin_lock_irqsave(&chip->lock, flags);
15381da177e4SLinus Torvalds 	ucontrol->value.integer.value[0] = (chip->image[left_reg] >> shift_left) & mask;
15391da177e4SLinus Torvalds 	ucontrol->value.integer.value[1] = (chip->image[right_reg] >> shift_right) & mask;
15401da177e4SLinus Torvalds 	spin_unlock_irqrestore(&chip->lock, flags);
15411da177e4SLinus Torvalds 	if (invert) {
15421da177e4SLinus Torvalds 		ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
15431da177e4SLinus Torvalds 		ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
15441da177e4SLinus Torvalds 	}
15451da177e4SLinus Torvalds 	return 0;
15461da177e4SLinus Torvalds }
15471da177e4SLinus Torvalds 
15481da177e4SLinus Torvalds static int snd_opti93x_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
15491da177e4SLinus Torvalds {
15501da177e4SLinus Torvalds 	opti93x_t *chip = snd_kcontrol_chip(kcontrol);
15511da177e4SLinus Torvalds 	unsigned long flags;
15521da177e4SLinus Torvalds 	int left_reg = kcontrol->private_value & 0xff;
15531da177e4SLinus Torvalds 	int right_reg = (kcontrol->private_value >> 8) & 0xff;
15541da177e4SLinus Torvalds 	int shift_left = (kcontrol->private_value >> 16) & 0x07;
15551da177e4SLinus Torvalds 	int shift_right = (kcontrol->private_value >> 19) & 0x07;
15561da177e4SLinus Torvalds 	int mask = (kcontrol->private_value >> 24) & 0xff;
15571da177e4SLinus Torvalds 	int invert = (kcontrol->private_value >> 22) & 1;
15581da177e4SLinus Torvalds 	int change;
15591da177e4SLinus Torvalds 	unsigned short val1, val2;
15601da177e4SLinus Torvalds 
15611da177e4SLinus Torvalds 	val1 = ucontrol->value.integer.value[0] & mask;
15621da177e4SLinus Torvalds 	val2 = ucontrol->value.integer.value[1] & mask;
15631da177e4SLinus Torvalds 	if (invert) {
15641da177e4SLinus Torvalds 		val1 = mask - val1;
15651da177e4SLinus Torvalds 		val2 = mask - val2;
15661da177e4SLinus Torvalds 	}
15671da177e4SLinus Torvalds 	val1 <<= shift_left;
15681da177e4SLinus Torvalds 	val2 <<= shift_right;
15691da177e4SLinus Torvalds 	spin_lock_irqsave(&chip->lock, flags);
15701da177e4SLinus Torvalds 	val1 = (chip->image[left_reg] & ~(mask << shift_left)) | val1;
15711da177e4SLinus Torvalds 	val2 = (chip->image[right_reg] & ~(mask << shift_right)) | val2;
15721da177e4SLinus Torvalds 	change = val1 != chip->image[left_reg] || val2 != chip->image[right_reg];
15731da177e4SLinus Torvalds 	snd_opti93x_out_image(chip, left_reg, val1);
15741da177e4SLinus Torvalds 	snd_opti93x_out_image(chip, right_reg, val2);
15751da177e4SLinus Torvalds 	spin_unlock_irqrestore(&chip->lock, flags);
15761da177e4SLinus Torvalds 	return change;
15771da177e4SLinus Torvalds }
15781da177e4SLinus Torvalds 
15791da177e4SLinus Torvalds static snd_kcontrol_new_t snd_opti93x_controls[] = {
15801da177e4SLinus Torvalds OPTi93X_DOUBLE("Master Playback Switch", 0, OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 7, 7, 1, 1),
15811da177e4SLinus Torvalds OPTi93X_DOUBLE("Master Playback Volume", 0, OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 1, 1, 31, 1),
15821da177e4SLinus Torvalds OPTi93X_DOUBLE("PCM Playback Switch", 0, OPTi93X_DAC_LEFT, OPTi93X_DAC_RIGHT, 7, 7, 1, 1),
15831da177e4SLinus Torvalds OPTi93X_DOUBLE("PCM Playback Volume", 0, OPTi93X_DAC_LEFT, OPTi93X_DAC_RIGHT, 0, 0, 31, 1),
15841da177e4SLinus Torvalds OPTi93X_DOUBLE("FM Playback Switch", 0, OPTi931_FM_LEFT_INPUT, OPTi931_FM_RIGHT_INPUT, 7, 7, 1, 1),
15851da177e4SLinus Torvalds OPTi93X_DOUBLE("FM Playback Volume", 0, OPTi931_FM_LEFT_INPUT, OPTi931_FM_RIGHT_INPUT, 1, 1, 15, 1),
15861da177e4SLinus Torvalds OPTi93X_DOUBLE("Line Playback Switch", 0, OPTi93X_LINE_LEFT_INPUT, OPTi93X_LINE_RIGHT_INPUT, 7, 7, 1, 1),
15871da177e4SLinus Torvalds OPTi93X_DOUBLE("Line Playback Volume", 0, OPTi93X_LINE_LEFT_INPUT, OPTi93X_LINE_RIGHT_INPUT, 1, 1, 15, 1),
15881da177e4SLinus Torvalds OPTi93X_DOUBLE("Mic Playback Switch", 0, OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 7, 7, 1, 1),
15891da177e4SLinus Torvalds OPTi93X_DOUBLE("Mic Playback Volume", 0, OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 1, 1, 15, 1),
15901da177e4SLinus Torvalds OPTi93X_DOUBLE("Mic Boost", 0, OPTi93X_MIXOUT_LEFT, OPTi93X_MIXOUT_RIGHT, 5, 5, 1, 1),
15911da177e4SLinus Torvalds OPTi93X_DOUBLE("CD Playback Switch", 0, OPTi93X_CD_LEFT_INPUT, OPTi93X_CD_RIGHT_INPUT, 7, 7, 1, 1),
15921da177e4SLinus Torvalds OPTi93X_DOUBLE("CD Playback Volume", 0, OPTi93X_CD_LEFT_INPUT, OPTi93X_CD_RIGHT_INPUT, 1, 1, 15, 1),
15931da177e4SLinus Torvalds OPTi93X_DOUBLE("Aux Playback Switch", 0, OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 7, 7, 1, 1),
15941da177e4SLinus Torvalds OPTi93X_DOUBLE("Aux Playback Volume", 0, OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 1, 1, 15, 1),
15951da177e4SLinus Torvalds OPTi93X_DOUBLE("Capture Volume", 0, OPTi93X_MIXOUT_LEFT, OPTi93X_MIXOUT_RIGHT, 0, 0, 15, 0),
15961da177e4SLinus Torvalds {
15971da177e4SLinus Torvalds 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15981da177e4SLinus Torvalds 	.name = "Capture Source",
15991da177e4SLinus Torvalds 	.info = snd_opti93x_info_mux,
16001da177e4SLinus Torvalds 	.get = snd_opti93x_get_mux,
16011da177e4SLinus Torvalds 	.put = snd_opti93x_put_mux,
16021da177e4SLinus Torvalds }
16031da177e4SLinus Torvalds };
16041da177e4SLinus Torvalds 
16051da177e4SLinus Torvalds static int snd_opti93x_mixer(opti93x_t *chip)
16061da177e4SLinus Torvalds {
16071da177e4SLinus Torvalds 	snd_card_t *card;
16081da177e4SLinus Torvalds 	snd_kcontrol_new_t knew;
16091da177e4SLinus Torvalds 	int err;
16101da177e4SLinus Torvalds 	unsigned int idx;
16111da177e4SLinus Torvalds 
16121da177e4SLinus Torvalds 	snd_assert(chip != NULL && chip->card != NULL, return -EINVAL);
16131da177e4SLinus Torvalds 
16141da177e4SLinus Torvalds 	card = chip->card;
16151da177e4SLinus Torvalds 
16161da177e4SLinus Torvalds 	strcpy(card->mixername, snd_opti93x_chip_id(chip));
16171da177e4SLinus Torvalds 
16181da177e4SLinus Torvalds 	for (idx = 0; idx < ARRAY_SIZE(snd_opti93x_controls); idx++) {
16191da177e4SLinus Torvalds 		knew = snd_opti93x_controls[idx];
16201da177e4SLinus Torvalds 		if (chip->hardware == OPTi9XX_HW_82C930) {
16211da177e4SLinus Torvalds 			if (strstr(knew.name, "FM"))	/* skip FM controls */
16221da177e4SLinus Torvalds 				continue;
16231da177e4SLinus Torvalds 			else if (strcmp(knew.name, "Mic Playback Volume"))
16241da177e4SLinus Torvalds 				OPTi93X_DOUBLE_INVERT_INVERT(knew);
16251da177e4SLinus Torvalds 			else if (strstr(knew.name, "Aux"))
16261da177e4SLinus Torvalds 				OPTi93X_DOUBLE_CHANGE_REGS(knew, OPTi930_AUX_LEFT_INPUT, OPTi930_AUX_RIGHT_INPUT);
16271da177e4SLinus Torvalds 			else if (strcmp(knew.name, "PCM Playback Volume"))
16281da177e4SLinus Torvalds 				OPTi93X_DOUBLE_INVERT_INVERT(knew);
16291da177e4SLinus Torvalds 			else if (strcmp(knew.name, "Master Playback Volume"))
16301da177e4SLinus Torvalds 				OPTi93X_DOUBLE_INVERT_INVERT(knew);
16311da177e4SLinus Torvalds 		}
16321da177e4SLinus Torvalds 		if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_opti93x_controls[idx], chip))) < 0)
16331da177e4SLinus Torvalds 			return err;
16341da177e4SLinus Torvalds 	}
16351da177e4SLinus Torvalds 	return 0;
16361da177e4SLinus Torvalds }
16371da177e4SLinus Torvalds 
16381da177e4SLinus Torvalds #endif /* OPTi93X */
16391da177e4SLinus Torvalds 
16401da177e4SLinus Torvalds static int __devinit snd_card_opti9xx_detect(snd_card_t *card, opti9xx_t *chip)
16411da177e4SLinus Torvalds {
16421da177e4SLinus Torvalds 	int i, err;
16431da177e4SLinus Torvalds 
16441da177e4SLinus Torvalds #ifndef OPTi93X
16451da177e4SLinus Torvalds 	for (i = OPTi9XX_HW_82C928; i < OPTi9XX_HW_82C930; i++) {
16461da177e4SLinus Torvalds 		unsigned char value;
16471da177e4SLinus Torvalds 
16481da177e4SLinus Torvalds 		if ((err = snd_opti9xx_init(chip, i)) < 0)
16491da177e4SLinus Torvalds 			return err;
16501da177e4SLinus Torvalds 
16511da177e4SLinus Torvalds 		if ((chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size, "OPTi9xx MC")) == NULL)
16521da177e4SLinus Torvalds 			continue;
16531da177e4SLinus Torvalds 
16541da177e4SLinus Torvalds 		value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(1));
16551da177e4SLinus Torvalds 		if ((value != 0xff) && (value != inb(chip->mc_base + 1)))
16561da177e4SLinus Torvalds 			if (value == snd_opti9xx_read(chip, OPTi9XX_MC_REG(1)))
16571da177e4SLinus Torvalds 				return 1;
16581da177e4SLinus Torvalds 
16591da177e4SLinus Torvalds 		release_resource(chip->res_mc_base);
16601da177e4SLinus Torvalds 		kfree_nocheck(chip->res_mc_base);
16611da177e4SLinus Torvalds 		chip->res_mc_base = NULL;
16621da177e4SLinus Torvalds 
16631da177e4SLinus Torvalds 	}
16641da177e4SLinus Torvalds #else	/* OPTi93X */
16651da177e4SLinus Torvalds 	for (i = OPTi9XX_HW_82C931; i >= OPTi9XX_HW_82C930; i--) {
16661da177e4SLinus Torvalds 		unsigned long flags;
16671da177e4SLinus Torvalds 		unsigned char value;
16681da177e4SLinus Torvalds 
16691da177e4SLinus Torvalds 		if ((err = snd_opti9xx_init(chip, i)) < 0)
16701da177e4SLinus Torvalds 			return err;
16711da177e4SLinus Torvalds 
16721da177e4SLinus Torvalds 		if ((chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size, "OPTi9xx MC")) == NULL)
16731da177e4SLinus Torvalds 			continue;
16741da177e4SLinus Torvalds 
16751da177e4SLinus Torvalds 		spin_lock_irqsave(&chip->lock, flags);
16761da177e4SLinus Torvalds 		outb(chip->password, chip->mc_base + chip->pwd_reg);
16771da177e4SLinus Torvalds 		outb(((chip->mc_indir_index & (1 << 8)) >> 4) |
16781da177e4SLinus Torvalds 			((chip->mc_indir_index & 0xf0) >> 4), chip->mc_base);
16791da177e4SLinus Torvalds 		spin_unlock_irqrestore(&chip->lock, flags);
16801da177e4SLinus Torvalds 
16811da177e4SLinus Torvalds 		value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(7));
16821da177e4SLinus Torvalds 		snd_opti9xx_write(chip, OPTi9XX_MC_REG(7), 0xff - value);
16831da177e4SLinus Torvalds 		if (snd_opti9xx_read(chip, OPTi9XX_MC_REG(7)) == 0xff - value)
16841da177e4SLinus Torvalds 			return 1;
16851da177e4SLinus Torvalds 
16861da177e4SLinus Torvalds 		release_resource(chip->res_mc_base);
16871da177e4SLinus Torvalds 		kfree_nocheck(chip->res_mc_base);
16881da177e4SLinus Torvalds 		chip->res_mc_base = NULL;
16891da177e4SLinus Torvalds 	}
16901da177e4SLinus Torvalds #endif	/* OPTi93X */
16911da177e4SLinus Torvalds 
16921da177e4SLinus Torvalds 	return -ENODEV;
16931da177e4SLinus Torvalds }
16941da177e4SLinus Torvalds 
16951da177e4SLinus Torvalds #ifdef CONFIG_PNP
16961da177e4SLinus Torvalds static int __devinit snd_card_opti9xx_pnp(opti9xx_t *chip, struct pnp_card_link *card,
16971da177e4SLinus Torvalds 					  const struct pnp_card_device_id *pid)
16981da177e4SLinus Torvalds {
16991da177e4SLinus Torvalds 	struct pnp_dev *pdev;
17001da177e4SLinus Torvalds 	struct pnp_resource_table *cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
17011da177e4SLinus Torvalds 	int err;
17021da177e4SLinus Torvalds 
17031da177e4SLinus Torvalds 	chip->dev = pnp_request_card_device(card, pid->devs[0].id, NULL);
17041da177e4SLinus Torvalds 	if (chip->dev == NULL) {
17051da177e4SLinus Torvalds 		kfree(cfg);
17061da177e4SLinus Torvalds 		return -EBUSY;
17071da177e4SLinus Torvalds 	}
17081da177e4SLinus Torvalds 	chip->devmpu = pnp_request_card_device(card, pid->devs[1].id, NULL);
17091da177e4SLinus Torvalds 
17101da177e4SLinus Torvalds 	pdev = chip->dev;
17111da177e4SLinus Torvalds 	pnp_init_resource_table(cfg);
17121da177e4SLinus Torvalds 
17131da177e4SLinus Torvalds #ifdef OPTi93X
17141da177e4SLinus Torvalds 	if (port != SNDRV_AUTO_PORT)
17151da177e4SLinus Torvalds 		pnp_resource_change(&cfg->port_resource[0], port + 4, 4);
17161da177e4SLinus Torvalds #else
17171da177e4SLinus Torvalds 	if (pid->driver_data != 0x0924 && port != SNDRV_AUTO_PORT)
17181da177e4SLinus Torvalds 		pnp_resource_change(&cfg->port_resource[1], port, 4);
17191da177e4SLinus Torvalds #endif	/* OPTi93X */
17201da177e4SLinus Torvalds 	if (irq != SNDRV_AUTO_IRQ)
17211da177e4SLinus Torvalds 		pnp_resource_change(&cfg->irq_resource[0], irq, 1);
17221da177e4SLinus Torvalds 	if (dma1 != SNDRV_AUTO_DMA)
17231da177e4SLinus Torvalds 		pnp_resource_change(&cfg->dma_resource[0], dma1, 1);
17241da177e4SLinus Torvalds #if defined(CS4231) || defined(OPTi93X)
17251da177e4SLinus Torvalds 	if (dma2 != SNDRV_AUTO_DMA)
17261da177e4SLinus Torvalds 		pnp_resource_change(&cfg->dma_resource[1], dma2, 1);
17271da177e4SLinus Torvalds #else
17281da177e4SLinus Torvalds #ifdef snd_opti9xx_fixup_dma2
17291da177e4SLinus Torvalds 	snd_opti9xx_fixup_dma2(pdev);
17301da177e4SLinus Torvalds #endif
17311da177e4SLinus Torvalds #endif	/* CS4231 || OPTi93X */
17321da177e4SLinus Torvalds #ifdef OPTi93X
17331da177e4SLinus Torvalds 	if (fm_port > 0 && fm_port != SNDRV_AUTO_PORT)
17341da177e4SLinus Torvalds 		pnp_resource_change(&cfg->port_resource[1], fm_port, 4);
17351da177e4SLinus Torvalds #else
17361da177e4SLinus Torvalds 	if (fm_port > 0 && fm_port != SNDRV_AUTO_PORT)
17371da177e4SLinus Torvalds 		pnp_resource_change(&cfg->port_resource[2], fm_port, 4);
17381da177e4SLinus Torvalds #endif
17391da177e4SLinus Torvalds 	if (pnp_manual_config_dev(pdev, cfg, 0) < 0)
17401da177e4SLinus Torvalds 		snd_printk(KERN_ERR "AUDIO the requested resources are invalid, using auto config\n");
17411da177e4SLinus Torvalds 	err = pnp_activate_dev(pdev);
17421da177e4SLinus Torvalds 	if (err < 0) {
17431da177e4SLinus Torvalds 		snd_printk(KERN_ERR "AUDIO pnp configure failure: %d\n", err);
17441da177e4SLinus Torvalds 		kfree(cfg);
17451da177e4SLinus Torvalds 		return err;
17461da177e4SLinus Torvalds 	}
17471da177e4SLinus Torvalds 
17481da177e4SLinus Torvalds #ifdef OPTi93X
17491da177e4SLinus Torvalds 	port = pnp_port_start(pdev, 0) - 4;
17501da177e4SLinus Torvalds 	fm_port = pnp_port_start(pdev, 1);
17511da177e4SLinus Torvalds #else
17521da177e4SLinus Torvalds 	if (pid->driver_data != 0x0924)
17531da177e4SLinus Torvalds 		port = pnp_port_start(pdev, 1);
17541da177e4SLinus Torvalds 	fm_port = pnp_port_start(pdev, 2);
17551da177e4SLinus Torvalds #endif	/* OPTi93X */
17561da177e4SLinus Torvalds 	irq = pnp_irq(pdev, 0);
17571da177e4SLinus Torvalds 	dma1 = pnp_dma(pdev, 0);
17581da177e4SLinus Torvalds #if defined(CS4231) || defined(OPTi93X)
17591da177e4SLinus Torvalds 	dma2 = pnp_dma(pdev, 1);
17601da177e4SLinus Torvalds #endif	/* CS4231 || OPTi93X */
17611da177e4SLinus Torvalds 
17621da177e4SLinus Torvalds 	pdev = chip->devmpu;
17631da177e4SLinus Torvalds 	if (pdev && mpu_port > 0) {
17641da177e4SLinus Torvalds 		pnp_init_resource_table(cfg);
17651da177e4SLinus Torvalds 
17661da177e4SLinus Torvalds 		if (mpu_port != SNDRV_AUTO_PORT)
17671da177e4SLinus Torvalds 			pnp_resource_change(&cfg->port_resource[0], mpu_port, 2);
17681da177e4SLinus Torvalds 		if (mpu_irq != SNDRV_AUTO_IRQ)
17691da177e4SLinus Torvalds 			pnp_resource_change(&cfg->irq_resource[0], mpu_irq, 1);
17701da177e4SLinus Torvalds 
17711da177e4SLinus Torvalds 		if (pnp_manual_config_dev(pdev, cfg, 0) < 0)
17721da177e4SLinus Torvalds 			snd_printk(KERN_ERR "AUDIO the requested resources are invalid, using auto config\n");
17731da177e4SLinus Torvalds 		err = pnp_activate_dev(pdev);
17741da177e4SLinus Torvalds 		if (err < 0) {
17751da177e4SLinus Torvalds 			snd_printk(KERN_ERR "AUDIO pnp configure failure\n");
17761da177e4SLinus Torvalds 			mpu_port = -1;
17771da177e4SLinus Torvalds 			chip->devmpu = NULL;
17781da177e4SLinus Torvalds 		} else {
17791da177e4SLinus Torvalds 			mpu_port = pnp_port_start(pdev, 0);
17801da177e4SLinus Torvalds 			mpu_irq = pnp_irq(pdev, 0);
17811da177e4SLinus Torvalds 		}
17821da177e4SLinus Torvalds 	}
17831da177e4SLinus Torvalds 	kfree(cfg);
17841da177e4SLinus Torvalds 	return pid->driver_data;
17851da177e4SLinus Torvalds }
17861da177e4SLinus Torvalds #endif	/* CONFIG_PNP */
17871da177e4SLinus Torvalds 
17881da177e4SLinus Torvalds #if 0
17891da177e4SLinus Torvalds static int __devinit snd_card_opti9xx_resources(struct snd_card_opti9xx *chip,
17901da177e4SLinus Torvalds 						snd_card_t *card)
17911da177e4SLinus Torvalds {
17921da177e4SLinus Torvalds 	int error, i, pnp = 0;
17931da177e4SLinus Torvalds 
17941da177e4SLinus Torvalds #ifdef CONFIG_PNP
17951da177e4SLinus Torvalds 	pnp = chip->dev != NULL;
17961da177e4SLinus Torvalds #endif	/* CONFIG_PNP */
17971da177e4SLinus Torvalds 
17981da177e4SLinus Torvalds #ifndef OPTi93X
17991da177e4SLinus Torvalds 	if (chip->chip->hardware == OPTi9XX_HW_82C928)
18001da177e4SLinus Torvalds 		mpu_port = -1;
18011da177e4SLinus Torvalds #endif	/* OPTi93X */
18021da177e4SLinus Torvalds 	error = 0;
18031da177e4SLinus Torvalds 	if (!pnp && (mpu_port == SNDRV_DEFAULT_PORT1)) {
18041da177e4SLinus Torvalds 		for (i = 0; possible_mpu_ports[i] != -1; i++)
18051da177e4SLinus Torvalds 			if (!snd_register_ioport(card, possible_mpu_ports[i], 2,
18061da177e4SLinus Torvalds 					DRIVER_NAME" - MPU-401", NULL)) {
18071da177e4SLinus Torvalds 				mpu_port = possible_mpu_ports[i];
18081da177e4SLinus Torvalds 				break;
18091da177e4SLinus Torvalds 			}
18101da177e4SLinus Torvalds 		if (mpu_port == SNDRV_DEFAULT_PORT1)
18111da177e4SLinus Torvalds 			error = -EBUSY;
18121da177e4SLinus Torvalds 	}
18131da177e4SLinus Torvalds 	else
18141da177e4SLinus Torvalds 		error = (mpu_port == -1) ? -ENODEV :
18151da177e4SLinus Torvalds 			snd_register_ioport(card, mpu_port, 2,
18161da177e4SLinus Torvalds 			DRIVER_NAME" - MPU-401", NULL);
18171da177e4SLinus Torvalds 	if (error)
18181da177e4SLinus Torvalds 		chip->chip->mpu_port = -1;
18191da177e4SLinus Torvalds 	else if (pnp && (irq == mpu_irq))
18201da177e4SLinus Torvalds 		chip->chip->mpu_irq = mpu_irq;
18211da177e4SLinus Torvalds 	else if (!snd_register_interrupt(card,
18221da177e4SLinus Torvalds 			DRIVER_NAME" - MPU-401",
18231da177e4SLinus Torvalds 			mpu_irq, SNDRV_IRQ_TYPE_ISA,
18241da177e4SLinus Torvalds 			snd_card_opti9xx_mpu_interrupt, chip,
18251da177e4SLinus Torvalds 			pnp ? no_alternatives : possible_mpu_irqs,
18261da177e4SLinus Torvalds 			&chip->mpuirqptr)) {
18271da177e4SLinus Torvalds 		chip->chip->mpu_port = mpu_port;
18281da177e4SLinus Torvalds 		chip->chip->mpu_irq = chip->mpuirqptr->irq;
18291da177e4SLinus Torvalds 	}
18301da177e4SLinus Torvalds 	else
18311da177e4SLinus Torvalds 		chip->chip->mpu_port = -1;
18321da177e4SLinus Torvalds 
18331da177e4SLinus Torvalds 	if (!pnp && (port == SNDRV_DEFAULT_PORT1)) {
18341da177e4SLinus Torvalds 		for (i = 0; possible_ports[i] != -1; i++)
18351da177e4SLinus Torvalds 			if (!snd_register_ioport(card, possible_ports[i], 8,
18361da177e4SLinus Torvalds 					DRIVER_NAME" - WSS", NULL)) {
18371da177e4SLinus Torvalds 				port = possible_ports[i];
18381da177e4SLinus Torvalds 				break;
18391da177e4SLinus Torvalds 			}
18401da177e4SLinus Torvalds 		if (port == SNDRV_DEFAULT_PORT1)
18411da177e4SLinus Torvalds 			return -EBUSY;
18421da177e4SLinus Torvalds 	}
18431da177e4SLinus Torvalds 	else if ((error = snd_register_ioport(card, port, 8,
18441da177e4SLinus Torvalds 			DRIVER_NAME" - WSS", NULL)) < 0)
18451da177e4SLinus Torvalds 		return error;
18461da177e4SLinus Torvalds 	chip->chip->wss_base = port;
18471da177e4SLinus Torvalds 	if ((error = snd_register_interrupt(card, DRIVER_NAME" - WSS",
18481da177e4SLinus Torvalds 			irq, SNDRV_IRQ_TYPE_ISA,
18491da177e4SLinus Torvalds 			snd_card_opti9xx_interrupt, chip,
18501da177e4SLinus Torvalds 			pnp ? no_alternatives : possible_irqs,
18511da177e4SLinus Torvalds 			&chip->irqptr)) < 0)
18521da177e4SLinus Torvalds 		return error;
18531da177e4SLinus Torvalds 	chip->chip->irq = chip->irqptr->irq;
18541da177e4SLinus Torvalds 	if ((error = snd_register_dma_channel(card,
18551da177e4SLinus Torvalds #if defined(CS4231) || defined(OPTi93X)
18561da177e4SLinus Torvalds 			DRIVER_NAME" - WSS playback",
18571da177e4SLinus Torvalds #else
18581da177e4SLinus Torvalds 			DRIVER_NAME" - WSS",
18591da177e4SLinus Torvalds #endif	/* CS4231 || OPTi93X */
18601da177e4SLinus Torvalds 			dma1, SNDRV_DMA_TYPE_ISA, dma1_size,
18611da177e4SLinus Torvalds 			pnp ? no_alternatives : possible_dma1s,
18621da177e4SLinus Torvalds 			&chip->dma1ptr)) < 0)
18631da177e4SLinus Torvalds 		return error;
18641da177e4SLinus Torvalds 	chip->chip->dma1 = chip->dma1ptr->dma;
18651da177e4SLinus Torvalds #if defined(CS4231) || defined(OPTi93X)
18661da177e4SLinus Torvalds 	if ((error = snd_register_dma_channel(card, DRIVER_NAME" - WSS capture",
18671da177e4SLinus Torvalds 			dma2, SNDRV_DMA_TYPE_ISA, dma2_size,
18681da177e4SLinus Torvalds 			pnp ? no_alternatives :
18691da177e4SLinus Torvalds 				possible_dma2s[chip->dma1ptr->dma],
18701da177e4SLinus Torvalds 			&chip->dma2ptr)) < 0)
18711da177e4SLinus Torvalds 		return error;
18721da177e4SLinus Torvalds 	chip->chip->dma2 = chip->dma2ptr->dma;
18731da177e4SLinus Torvalds #endif	/* CS4231 || OPTi93X */
18741da177e4SLinus Torvalds 
18751da177e4SLinus Torvalds 	if (snd_register_ioport(card,
18761da177e4SLinus Torvalds 			pnp ? fm_port : fm_port = 0x388, 4,
18771da177e4SLinus Torvalds 			DRIVER_NAME" - OPL", NULL) < 0)
18781da177e4SLinus Torvalds 		fm_port = -1;
18791da177e4SLinus Torvalds 	chip->chip->fm_port = fm_port;
18801da177e4SLinus Torvalds 
18811da177e4SLinus Torvalds 	return 0;
18821da177e4SLinus Torvalds }
18831da177e4SLinus Torvalds #endif
18841da177e4SLinus Torvalds 
18851da177e4SLinus Torvalds static void snd_card_opti9xx_free(snd_card_t *card)
18861da177e4SLinus Torvalds {
18871da177e4SLinus Torvalds 	opti9xx_t *chip = (opti9xx_t *)card->private_data;
18881da177e4SLinus Torvalds 
18891da177e4SLinus Torvalds 	if (chip) {
18901da177e4SLinus Torvalds 		if (chip->res_mc_base) {
18911da177e4SLinus Torvalds 			release_resource(chip->res_mc_base);
18921da177e4SLinus Torvalds 			kfree_nocheck(chip->res_mc_base);
18931da177e4SLinus Torvalds 		}
18941da177e4SLinus Torvalds 	}
18951da177e4SLinus Torvalds }
18961da177e4SLinus Torvalds 
189743bcd973STakashi Iwai static int snd_card_opti9xx_probe(struct pnp_card_link *pcard,
18981da177e4SLinus Torvalds 				  const struct pnp_card_device_id *pid)
18991da177e4SLinus Torvalds {
19001da177e4SLinus Torvalds 	static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1};
19011da177e4SLinus Torvalds 	static long possible_mpu_ports[] = {0x300, 0x310, 0x320, 0x330, -1};
19021da177e4SLinus Torvalds #ifdef OPTi93X
19031da177e4SLinus Torvalds 	static int possible_irqs[] = {5, 9, 10, 11, 7, -1};
19041da177e4SLinus Torvalds #else
19051da177e4SLinus Torvalds 	static int possible_irqs[] = {9, 10, 11, 7, -1};
19061da177e4SLinus Torvalds #endif	/* OPTi93X */
19071da177e4SLinus Torvalds 	static int possible_mpu_irqs[] = {5, 9, 10, 7, -1};
19081da177e4SLinus Torvalds 	static int possible_dma1s[] = {3, 1, 0, -1};
19091da177e4SLinus Torvalds #if defined(CS4231) || defined(OPTi93X)
19101da177e4SLinus Torvalds 	static int possible_dma2s[][2] = {{1,-1}, {0,-1}, {-1,-1}, {0,-1}};
19111da177e4SLinus Torvalds #endif	/* CS4231 || OPTi93X */
19121da177e4SLinus Torvalds 	int error;
19131da177e4SLinus Torvalds 	opti9xx_t *chip;
19141da177e4SLinus Torvalds #if defined(OPTi93X)
19151da177e4SLinus Torvalds 	opti93x_t *codec;
19161da177e4SLinus Torvalds #elif defined(CS4231)
19171da177e4SLinus Torvalds 	cs4231_t *codec;
19181da177e4SLinus Torvalds 	snd_timer_t *timer;
19191da177e4SLinus Torvalds #else
19201da177e4SLinus Torvalds 	ad1848_t *codec;
19211da177e4SLinus Torvalds #endif
19221da177e4SLinus Torvalds 	snd_card_t *card;
19231da177e4SLinus Torvalds 	snd_pcm_t *pcm;
19241da177e4SLinus Torvalds 	snd_rawmidi_t *rmidi;
19251da177e4SLinus Torvalds 	snd_hwdep_t *synth;
19261da177e4SLinus Torvalds #ifdef CONFIG_PNP
19271da177e4SLinus Torvalds 	int hw;
19281da177e4SLinus Torvalds #endif	/* CONFIG_PNP */
19291da177e4SLinus Torvalds 
19301da177e4SLinus Torvalds 	if (pcard && !snd_opti9xx_first_hit)
19311da177e4SLinus Torvalds 		return -EBUSY;
19321da177e4SLinus Torvalds 	if (!(card = snd_card_new(index, id, THIS_MODULE,
19331da177e4SLinus Torvalds 				  sizeof(opti9xx_t))))
19341da177e4SLinus Torvalds 		return -ENOMEM;
19351da177e4SLinus Torvalds 	card->private_free = snd_card_opti9xx_free;
19361da177e4SLinus Torvalds 	chip = (opti9xx_t *)card->private_data;
19371da177e4SLinus Torvalds 
19381da177e4SLinus Torvalds #ifdef CONFIG_PNP
19391da177e4SLinus Torvalds 	if (isapnp && pcard && (hw = snd_card_opti9xx_pnp(chip, pcard, pid)) > 0) {
19401da177e4SLinus Torvalds 		switch (hw) {
19411da177e4SLinus Torvalds 		case 0x0924:
19421da177e4SLinus Torvalds 			hw = OPTi9XX_HW_82C924;
19431da177e4SLinus Torvalds 			break;
19441da177e4SLinus Torvalds 		case 0x0925:
19451da177e4SLinus Torvalds 			hw = OPTi9XX_HW_82C925;
19461da177e4SLinus Torvalds 			break;
19471da177e4SLinus Torvalds 		case 0x0931:
19481da177e4SLinus Torvalds 			hw = OPTi9XX_HW_82C931;
19491da177e4SLinus Torvalds 			break;
19501da177e4SLinus Torvalds 		default:
19511da177e4SLinus Torvalds 			snd_card_free(card);
19521da177e4SLinus Torvalds 			return -ENODEV;
19531da177e4SLinus Torvalds 		}
19541da177e4SLinus Torvalds 
19551da177e4SLinus Torvalds 		if ((error = snd_opti9xx_init(chip, hw))) {
19561da177e4SLinus Torvalds 			snd_card_free(card);
19571da177e4SLinus Torvalds 			return error;
19581da177e4SLinus Torvalds 		}
19591da177e4SLinus Torvalds 		if (hw <= OPTi9XX_HW_82C930)
19601da177e4SLinus Torvalds 			chip->mc_base -= 0x80;
19611da177e4SLinus Torvalds 		snd_card_set_dev(card, &pcard->card->dev);
19621da177e4SLinus Torvalds 	} else {
19631da177e4SLinus Torvalds #endif	/* CONFIG_PNP */
19641da177e4SLinus Torvalds 		if ((error = snd_card_opti9xx_detect(card, chip)) < 0) {
19651da177e4SLinus Torvalds 			snd_card_free(card);
19661da177e4SLinus Torvalds 			return error;
19671da177e4SLinus Torvalds 		}
196843bcd973STakashi Iwai 		if ((error = snd_card_set_generic_dev(card)) < 0) {
196943bcd973STakashi Iwai 			snd_card_free(card);
197043bcd973STakashi Iwai 			return error;
197143bcd973STakashi Iwai 		}
19721da177e4SLinus Torvalds #ifdef CONFIG_PNP
19731da177e4SLinus Torvalds 	}
19741da177e4SLinus Torvalds #endif	/* CONFIG_PNP */
19751da177e4SLinus Torvalds 
19761da177e4SLinus Torvalds 	if (! chip->res_mc_base &&
19771da177e4SLinus Torvalds 	    (chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size, "OPTi9xx MC")) == NULL) {
19781da177e4SLinus Torvalds 		snd_card_free(card);
19791da177e4SLinus Torvalds 		return -ENOMEM;
19801da177e4SLinus Torvalds 	}
19811da177e4SLinus Torvalds 
19821da177e4SLinus Torvalds 	chip->wss_base = port;
19831da177e4SLinus Torvalds 	chip->fm_port = fm_port;
19841da177e4SLinus Torvalds 	chip->mpu_port = mpu_port;
19851da177e4SLinus Torvalds 	chip->irq = irq;
19861da177e4SLinus Torvalds 	chip->mpu_irq = mpu_irq;
19871da177e4SLinus Torvalds 	chip->dma1 = dma1;
19881da177e4SLinus Torvalds #if defined(CS4231) || defined(OPTi93X)
19891da177e4SLinus Torvalds 	chip->dma2 = dma2;
19901da177e4SLinus Torvalds #endif
19911da177e4SLinus Torvalds 
19921da177e4SLinus Torvalds 	if (chip->wss_base == SNDRV_AUTO_PORT) {
19931da177e4SLinus Torvalds 		if ((chip->wss_base = snd_legacy_find_free_ioport(possible_ports, 4)) < 0) {
19941da177e4SLinus Torvalds 			snd_card_free(card);
19951da177e4SLinus Torvalds 			snd_printk("unable to find a free WSS port\n");
19961da177e4SLinus Torvalds 			return -EBUSY;
19971da177e4SLinus Torvalds 		}
19981da177e4SLinus Torvalds 	}
19991da177e4SLinus Torvalds #ifdef CONFIG_PNP
20001da177e4SLinus Torvalds 	if (!isapnp) {
20011da177e4SLinus Torvalds #endif
20021da177e4SLinus Torvalds 	if (chip->mpu_port == SNDRV_AUTO_PORT) {
20031da177e4SLinus Torvalds 		if ((chip->mpu_port = snd_legacy_find_free_ioport(possible_mpu_ports, 2)) < 0) {
20041da177e4SLinus Torvalds 			snd_card_free(card);
20051da177e4SLinus Torvalds 			snd_printk("unable to find a free MPU401 port\n");
20061da177e4SLinus Torvalds 			return -EBUSY;
20071da177e4SLinus Torvalds 		}
20081da177e4SLinus Torvalds 	}
20091da177e4SLinus Torvalds 	if (chip->irq == SNDRV_AUTO_IRQ) {
20101da177e4SLinus Torvalds 		if ((chip->irq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
20111da177e4SLinus Torvalds 			snd_card_free(card);
20121da177e4SLinus Torvalds 			snd_printk("unable to find a free IRQ\n");
20131da177e4SLinus Torvalds 			return -EBUSY;
20141da177e4SLinus Torvalds 		}
20151da177e4SLinus Torvalds 	}
20161da177e4SLinus Torvalds 	if (chip->mpu_irq == SNDRV_AUTO_IRQ) {
20171da177e4SLinus Torvalds 		if ((chip->mpu_irq = snd_legacy_find_free_irq(possible_mpu_irqs)) < 0) {
20181da177e4SLinus Torvalds 			snd_card_free(card);
20191da177e4SLinus Torvalds 			snd_printk("unable to find a free MPU401 IRQ\n");
20201da177e4SLinus Torvalds 			return -EBUSY;
20211da177e4SLinus Torvalds 		}
20221da177e4SLinus Torvalds 	}
20231da177e4SLinus Torvalds 	if (chip->dma1 == SNDRV_AUTO_DMA) {
20241da177e4SLinus Torvalds                 if ((chip->dma1 = snd_legacy_find_free_dma(possible_dma1s)) < 0) {
20251da177e4SLinus Torvalds                         snd_card_free(card);
20261da177e4SLinus Torvalds 			snd_printk("unable to find a free DMA1\n");
20271da177e4SLinus Torvalds 			return -EBUSY;
20281da177e4SLinus Torvalds 		}
20291da177e4SLinus Torvalds         }
20301da177e4SLinus Torvalds #if defined(CS4231) || defined(OPTi93X)
20311da177e4SLinus Torvalds 	if (chip->dma2 == SNDRV_AUTO_DMA) {
20321da177e4SLinus Torvalds                 if ((chip->dma2 = snd_legacy_find_free_dma(possible_dma2s[chip->dma1 % 4])) < 0) {
20331da177e4SLinus Torvalds                         snd_card_free(card);
20341da177e4SLinus Torvalds 			snd_printk("unable to find a free DMA2\n");
20351da177e4SLinus Torvalds 			return -EBUSY;
20361da177e4SLinus Torvalds 		}
20371da177e4SLinus Torvalds         }
20381da177e4SLinus Torvalds #endif
20391da177e4SLinus Torvalds 
20401da177e4SLinus Torvalds #ifdef CONFIG_PNP
20411da177e4SLinus Torvalds 	}
20421da177e4SLinus Torvalds #endif
20431da177e4SLinus Torvalds 
20441da177e4SLinus Torvalds 	if ((error = snd_opti9xx_configure(chip))) {
20451da177e4SLinus Torvalds 		snd_card_free(card);
20461da177e4SLinus Torvalds 		return error;
20471da177e4SLinus Torvalds 	}
20481da177e4SLinus Torvalds 
20491da177e4SLinus Torvalds #if defined(OPTi93X)
20501da177e4SLinus Torvalds 	if ((error = snd_opti93x_create(card, chip, chip->dma1, chip->dma2, &codec))) {
20511da177e4SLinus Torvalds 		snd_card_free(card);
20521da177e4SLinus Torvalds 		return error;
20531da177e4SLinus Torvalds 	}
20541da177e4SLinus Torvalds 	if ((error = snd_opti93x_pcm(codec, 0, &pcm)) < 0) {
20551da177e4SLinus Torvalds 		snd_card_free(card);
20561da177e4SLinus Torvalds 		return error;
20571da177e4SLinus Torvalds 	}
20581da177e4SLinus Torvalds 	if ((error = snd_opti93x_mixer(codec)) < 0) {
20591da177e4SLinus Torvalds 		snd_card_free(card);
20601da177e4SLinus Torvalds 		return error;
20611da177e4SLinus Torvalds 	}
20621da177e4SLinus Torvalds #elif defined(CS4231)
20631da177e4SLinus Torvalds 	if ((error = snd_cs4231_create(card, chip->wss_base + 4, -1,
20641da177e4SLinus Torvalds 				       chip->irq, chip->dma1, chip->dma2,
20651da177e4SLinus Torvalds 				       CS4231_HW_DETECT,
20661da177e4SLinus Torvalds 				       0,
20671da177e4SLinus Torvalds 				       &codec)) < 0) {
20681da177e4SLinus Torvalds 		snd_card_free(card);
20691da177e4SLinus Torvalds 		return error;
20701da177e4SLinus Torvalds 	}
20711da177e4SLinus Torvalds 	if ((error = snd_cs4231_pcm(codec, 0, &pcm)) < 0) {
20721da177e4SLinus Torvalds 		snd_card_free(card);
20731da177e4SLinus Torvalds 		return error;
20741da177e4SLinus Torvalds 	}
20751da177e4SLinus Torvalds 	if ((error = snd_cs4231_mixer(codec)) < 0) {
20761da177e4SLinus Torvalds 		snd_card_free(card);
20771da177e4SLinus Torvalds 		return error;
20781da177e4SLinus Torvalds 	}
20791da177e4SLinus Torvalds 	if ((error = snd_cs4231_timer(codec, 0, &timer)) < 0) {
20801da177e4SLinus Torvalds 		snd_card_free(card);
20811da177e4SLinus Torvalds 		return error;
20821da177e4SLinus Torvalds 	}
20831da177e4SLinus Torvalds #else
20841da177e4SLinus Torvalds 	if ((error = snd_ad1848_create(card, chip->wss_base + 4,
20851da177e4SLinus Torvalds 				       chip->irq, chip->dma1,
20861da177e4SLinus Torvalds 				       AD1848_HW_DETECT, &codec)) < 0) {
20871da177e4SLinus Torvalds 		snd_card_free(card);
20881da177e4SLinus Torvalds 		return error;
20891da177e4SLinus Torvalds 	}
20901da177e4SLinus Torvalds 	if ((error = snd_ad1848_pcm(codec, 0, &pcm)) < 0) {
20911da177e4SLinus Torvalds 		snd_card_free(card);
20921da177e4SLinus Torvalds 		return error;
20931da177e4SLinus Torvalds 	}
20941da177e4SLinus Torvalds 	if ((error = snd_ad1848_mixer(codec)) < 0) {
20951da177e4SLinus Torvalds 		snd_card_free(card);
20961da177e4SLinus Torvalds 		return error;
20971da177e4SLinus Torvalds 	}
20981da177e4SLinus Torvalds #endif
20991da177e4SLinus Torvalds 	strcpy(card->driver, chip->name);
21001da177e4SLinus Torvalds 	sprintf(card->shortname, "OPTi %s", card->driver);
21011da177e4SLinus Torvalds #if defined(CS4231) || defined(OPTi93X)
21021da177e4SLinus Torvalds 	sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d&%d",
21031da177e4SLinus Torvalds 		card->shortname, pcm->name, chip->wss_base + 4,
21041da177e4SLinus Torvalds 		chip->irq, chip->dma1, chip->dma2);
21051da177e4SLinus Torvalds #else
21061da177e4SLinus Torvalds 	sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d",
21071da177e4SLinus Torvalds 		card->shortname, pcm->name, chip->wss_base + 4,
21081da177e4SLinus Torvalds 		chip->irq, chip->dma1);
21091da177e4SLinus Torvalds #endif	/* CS4231 || OPTi93X */
21101da177e4SLinus Torvalds 
21111da177e4SLinus Torvalds 	if (chip->mpu_port <= 0 || chip->mpu_port == SNDRV_AUTO_PORT)
21121da177e4SLinus Torvalds 		rmidi = NULL;
21131da177e4SLinus Torvalds 	else
21141da177e4SLinus Torvalds 		if ((error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
21151da177e4SLinus Torvalds 				chip->mpu_port, 0, chip->mpu_irq, SA_INTERRUPT,
21161da177e4SLinus Torvalds 				&rmidi)))
21171da177e4SLinus Torvalds 			snd_printk("no MPU-401 device at 0x%lx?\n", chip->mpu_port);
21181da177e4SLinus Torvalds 
21191da177e4SLinus Torvalds 	if (chip->fm_port > 0 && chip->fm_port != SNDRV_AUTO_PORT) {
21201da177e4SLinus Torvalds 		opl3_t *opl3 = NULL;
21211da177e4SLinus Torvalds #ifndef OPTi93X
21221da177e4SLinus Torvalds 		if (chip->hardware == OPTi9XX_HW_82C928 ||
21231da177e4SLinus Torvalds 		    chip->hardware == OPTi9XX_HW_82C929 ||
21241da177e4SLinus Torvalds 		    chip->hardware == OPTi9XX_HW_82C924) {
21251da177e4SLinus Torvalds 			opl4_t *opl4;
21261da177e4SLinus Torvalds 			/* assume we have an OPL4 */
21271da177e4SLinus Torvalds 			snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2),
21281da177e4SLinus Torvalds 					       0x20, 0x20);
21291da177e4SLinus Torvalds 			if (snd_opl4_create(card,
21301da177e4SLinus Torvalds 					    chip->fm_port,
21311da177e4SLinus Torvalds 					    chip->fm_port - 8,
21321da177e4SLinus Torvalds 					    2, &opl3, &opl4) < 0) {
21331da177e4SLinus Torvalds 				/* no luck, use OPL3 instead */
21341da177e4SLinus Torvalds 				snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2),
21351da177e4SLinus Torvalds 						       0x00, 0x20);
21361da177e4SLinus Torvalds 			}
21371da177e4SLinus Torvalds 		}
21381da177e4SLinus Torvalds #endif	/* !OPTi93X */
21391da177e4SLinus Torvalds 		if (!opl3 && snd_opl3_create(card,
21401da177e4SLinus Torvalds 					     chip->fm_port,
21411da177e4SLinus Torvalds 					     chip->fm_port + 2,
21421da177e4SLinus Torvalds 					     OPL3_HW_AUTO, 0, &opl3) < 0) {
21431da177e4SLinus Torvalds 			snd_printk("no OPL device at 0x%lx-0x%lx\n",
21441da177e4SLinus Torvalds 				   chip->fm_port, chip->fm_port + 4 - 1);
21451da177e4SLinus Torvalds 		}
21461da177e4SLinus Torvalds 		if (opl3) {
21471da177e4SLinus Torvalds 			if ((error = snd_opl3_timer_new(opl3,
21481da177e4SLinus Torvalds #ifdef CS4231
21491da177e4SLinus Torvalds 							1, 2)) < 0) {
21501da177e4SLinus Torvalds #else
21511da177e4SLinus Torvalds 							0, 1)) < 0) {
21521da177e4SLinus Torvalds #endif	/* CS4231 */
21531da177e4SLinus Torvalds 				snd_card_free(card);
21541da177e4SLinus Torvalds 				return error;
21551da177e4SLinus Torvalds 			}
21561da177e4SLinus Torvalds 			if ((error = snd_opl3_hwdep_new(opl3, 0, 1, &synth)) < 0) {
21571da177e4SLinus Torvalds 				snd_card_free(card);
21581da177e4SLinus Torvalds 				return error;
21591da177e4SLinus Torvalds 			}
21601da177e4SLinus Torvalds 		}
21611da177e4SLinus Torvalds 	}
21621da177e4SLinus Torvalds 
21631da177e4SLinus Torvalds 	if ((error = snd_card_register(card))) {
21641da177e4SLinus Torvalds 		snd_card_free(card);
21651da177e4SLinus Torvalds 		return error;
21661da177e4SLinus Torvalds 	}
21671da177e4SLinus Torvalds 	snd_opti9xx_first_hit = 0;
21681da177e4SLinus Torvalds 	if (pcard)
21691da177e4SLinus Torvalds 		pnp_set_card_drvdata(pcard, card);
21701da177e4SLinus Torvalds 	else
21711da177e4SLinus Torvalds 		snd_opti9xx_legacy = card;
21721da177e4SLinus Torvalds 	return 0;
21731da177e4SLinus Torvalds }
21741da177e4SLinus Torvalds 
21751da177e4SLinus Torvalds #ifdef CONFIG_PNP
21761da177e4SLinus Torvalds static void __devexit snd_opti9xx_pnp_remove(struct pnp_card_link * pcard)
21771da177e4SLinus Torvalds {
21781da177e4SLinus Torvalds 	snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
21791da177e4SLinus Torvalds 
21801da177e4SLinus Torvalds 	snd_card_disconnect(card);
21811da177e4SLinus Torvalds 	snd_card_free_in_thread(card);
21821da177e4SLinus Torvalds 	snd_opti9xx_first_hit = 0;
21831da177e4SLinus Torvalds }
21841da177e4SLinus Torvalds 
21851da177e4SLinus Torvalds static struct pnp_card_driver opti9xx_pnpc_driver = {
21861da177e4SLinus Torvalds 	.flags		= PNP_DRIVER_RES_DISABLE,
21871da177e4SLinus Torvalds 	.name		= "opti9xx",
21881da177e4SLinus Torvalds 	.id_table	= snd_opti9xx_pnpids,
21891da177e4SLinus Torvalds 	.probe		= snd_card_opti9xx_probe,
21901da177e4SLinus Torvalds 	.remove		= __devexit_p(snd_opti9xx_pnp_remove),
21911da177e4SLinus Torvalds };
21921da177e4SLinus Torvalds #endif
21931da177e4SLinus Torvalds 
21941da177e4SLinus Torvalds static int __init alsa_card_opti9xx_init(void)
21951da177e4SLinus Torvalds {
21961da177e4SLinus Torvalds 	int cards, error;
21971da177e4SLinus Torvalds 
21981da177e4SLinus Torvalds #ifdef CONFIG_PNP
21991da177e4SLinus Torvalds 	cards = pnp_register_card_driver(&opti9xx_pnpc_driver);
22001da177e4SLinus Torvalds #else
22011da177e4SLinus Torvalds 	cards = 0;
22021da177e4SLinus Torvalds #endif
22031da177e4SLinus Torvalds 	if (cards == 0 && (error = snd_card_opti9xx_probe(NULL, NULL)) < 0) {
22041da177e4SLinus Torvalds #ifdef CONFIG_PNP
22051da177e4SLinus Torvalds 		pnp_unregister_card_driver(&opti9xx_pnpc_driver);
22061da177e4SLinus Torvalds #endif
22071da177e4SLinus Torvalds #ifdef MODULE
22081da177e4SLinus Torvalds #ifdef OPTi93X
22091da177e4SLinus Torvalds 		printk(KERN_ERR "no OPTi 82C93x soundcard found\n");
22101da177e4SLinus Torvalds #else
22111da177e4SLinus Torvalds 		printk(KERN_ERR "no OPTi 82C92x soundcard found\n");
22121da177e4SLinus Torvalds #endif	/* OPTi93X */
22131da177e4SLinus Torvalds #endif
22141da177e4SLinus Torvalds 		return error;
22151da177e4SLinus Torvalds 	}
22161da177e4SLinus Torvalds 	return 0;
22171da177e4SLinus Torvalds }
22181da177e4SLinus Torvalds 
22191da177e4SLinus Torvalds static void __exit alsa_card_opti9xx_exit(void)
22201da177e4SLinus Torvalds {
22211da177e4SLinus Torvalds #ifdef CONFIG_PNP
22221da177e4SLinus Torvalds 	pnp_unregister_card_driver(&opti9xx_pnpc_driver);
22231da177e4SLinus Torvalds #endif
22241da177e4SLinus Torvalds 	if (snd_opti9xx_legacy)
22251da177e4SLinus Torvalds 		snd_card_free(snd_opti9xx_legacy);
22261da177e4SLinus Torvalds }
22271da177e4SLinus Torvalds 
22281da177e4SLinus Torvalds module_init(alsa_card_opti9xx_init)
22291da177e4SLinus Torvalds module_exit(alsa_card_opti9xx_exit)
2230