18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  Driver for AMD InterWave soundcard
48c2ecf20Sopenharmony_ci *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci *   1999/07/22		Erik Inge Bolso <knan@mo.himolde.no>
78c2ecf20Sopenharmony_ci *			* mixer group handlers
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#include <linux/init.h>
118c2ecf20Sopenharmony_ci#include <linux/err.h>
128c2ecf20Sopenharmony_ci#include <linux/isa.h>
138c2ecf20Sopenharmony_ci#include <linux/delay.h>
148c2ecf20Sopenharmony_ci#include <linux/pnp.h>
158c2ecf20Sopenharmony_ci#include <linux/module.h>
168c2ecf20Sopenharmony_ci#include <asm/dma.h>
178c2ecf20Sopenharmony_ci#include <sound/core.h>
188c2ecf20Sopenharmony_ci#include <sound/gus.h>
198c2ecf20Sopenharmony_ci#include <sound/wss.h>
208c2ecf20Sopenharmony_ci#ifdef SNDRV_STB
218c2ecf20Sopenharmony_ci#include <sound/tea6330t.h>
228c2ecf20Sopenharmony_ci#endif
238c2ecf20Sopenharmony_ci#define SNDRV_LEGACY_FIND_FREE_IRQ
248c2ecf20Sopenharmony_ci#define SNDRV_LEGACY_FIND_FREE_DMA
258c2ecf20Sopenharmony_ci#include <sound/initval.h>
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ciMODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
288c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
298c2ecf20Sopenharmony_ci#ifndef SNDRV_STB
308c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("AMD InterWave");
318c2ecf20Sopenharmony_ciMODULE_SUPPORTED_DEVICE("{{Gravis,UltraSound Plug & Play},"
328c2ecf20Sopenharmony_ci		"{STB,SoundRage32},"
338c2ecf20Sopenharmony_ci		"{MED,MED3210},"
348c2ecf20Sopenharmony_ci		"{Dynasonix,Dynasonix Pro},"
358c2ecf20Sopenharmony_ci		"{Panasonic,PCA761AW}}");
368c2ecf20Sopenharmony_ci#else
378c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("AMD InterWave STB with TEA6330T");
388c2ecf20Sopenharmony_ciMODULE_SUPPORTED_DEVICE("{{AMD,InterWave STB with TEA6330T}}");
398c2ecf20Sopenharmony_ci#endif
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_cistatic int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;	/* Index 0-MAX */
428c2ecf20Sopenharmony_cistatic char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;	/* ID for this card */
438c2ecf20Sopenharmony_cistatic bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
448c2ecf20Sopenharmony_ci#ifdef CONFIG_PNP
458c2ecf20Sopenharmony_cistatic bool isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
468c2ecf20Sopenharmony_ci#endif
478c2ecf20Sopenharmony_cistatic long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;	/* 0x210,0x220,0x230,0x240,0x250,0x260 */
488c2ecf20Sopenharmony_ci#ifdef SNDRV_STB
498c2ecf20Sopenharmony_cistatic long port_tc[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;	/* 0x350,0x360,0x370,0x380 */
508c2ecf20Sopenharmony_ci#endif
518c2ecf20Sopenharmony_cistatic int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;	/* 2,3,5,9,11,12,15 */
528c2ecf20Sopenharmony_cistatic int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;	/* 0,1,3,5,6,7 */
538c2ecf20Sopenharmony_cistatic int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;	/* 0,1,3,5,6,7 */
548c2ecf20Sopenharmony_cistatic int joystick_dac[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 29};
558c2ecf20Sopenharmony_ci				/* 0 to 31, (0.59V-4.52V or 0.389V-2.98V) */
568c2ecf20Sopenharmony_cistatic int midi[SNDRV_CARDS];
578c2ecf20Sopenharmony_cistatic int pcm_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2};
588c2ecf20Sopenharmony_cistatic int effect[SNDRV_CARDS];
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci#ifdef SNDRV_STB
618c2ecf20Sopenharmony_ci#define PFX "interwave-stb: "
628c2ecf20Sopenharmony_ci#define INTERWAVE_DRIVER	"snd_interwave_stb"
638c2ecf20Sopenharmony_ci#define INTERWAVE_PNP_DRIVER	"interwave-stb"
648c2ecf20Sopenharmony_ci#else
658c2ecf20Sopenharmony_ci#define PFX "interwave: "
668c2ecf20Sopenharmony_ci#define INTERWAVE_DRIVER	"snd_interwave"
678c2ecf20Sopenharmony_ci#define INTERWAVE_PNP_DRIVER	"interwave"
688c2ecf20Sopenharmony_ci#endif
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_cimodule_param_array(index, int, NULL, 0444);
718c2ecf20Sopenharmony_ciMODULE_PARM_DESC(index, "Index value for InterWave soundcard.");
728c2ecf20Sopenharmony_cimodule_param_array(id, charp, NULL, 0444);
738c2ecf20Sopenharmony_ciMODULE_PARM_DESC(id, "ID string for InterWave soundcard.");
748c2ecf20Sopenharmony_cimodule_param_array(enable, bool, NULL, 0444);
758c2ecf20Sopenharmony_ciMODULE_PARM_DESC(enable, "Enable InterWave soundcard.");
768c2ecf20Sopenharmony_ci#ifdef CONFIG_PNP
778c2ecf20Sopenharmony_cimodule_param_array(isapnp, bool, NULL, 0444);
788c2ecf20Sopenharmony_ciMODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard.");
798c2ecf20Sopenharmony_ci#endif
808c2ecf20Sopenharmony_cimodule_param_hw_array(port, long, ioport, NULL, 0444);
818c2ecf20Sopenharmony_ciMODULE_PARM_DESC(port, "Port # for InterWave driver.");
828c2ecf20Sopenharmony_ci#ifdef SNDRV_STB
838c2ecf20Sopenharmony_cimodule_param_hw_array(port_tc, long, ioport, NULL, 0444);
848c2ecf20Sopenharmony_ciMODULE_PARM_DESC(port_tc, "Tone control (TEA6330T - i2c bus) port # for InterWave driver.");
858c2ecf20Sopenharmony_ci#endif
868c2ecf20Sopenharmony_cimodule_param_hw_array(irq, int, irq, NULL, 0444);
878c2ecf20Sopenharmony_ciMODULE_PARM_DESC(irq, "IRQ # for InterWave driver.");
888c2ecf20Sopenharmony_cimodule_param_hw_array(dma1, int, dma, NULL, 0444);
898c2ecf20Sopenharmony_ciMODULE_PARM_DESC(dma1, "DMA1 # for InterWave driver.");
908c2ecf20Sopenharmony_cimodule_param_hw_array(dma2, int, dma, NULL, 0444);
918c2ecf20Sopenharmony_ciMODULE_PARM_DESC(dma2, "DMA2 # for InterWave driver.");
928c2ecf20Sopenharmony_cimodule_param_array(joystick_dac, int, NULL, 0444);
938c2ecf20Sopenharmony_ciMODULE_PARM_DESC(joystick_dac, "Joystick DAC level 0.59V-4.52V or 0.389V-2.98V for InterWave driver.");
948c2ecf20Sopenharmony_cimodule_param_array(midi, int, NULL, 0444);
958c2ecf20Sopenharmony_ciMODULE_PARM_DESC(midi, "MIDI UART enable for InterWave driver.");
968c2ecf20Sopenharmony_cimodule_param_array(pcm_channels, int, NULL, 0444);
978c2ecf20Sopenharmony_ciMODULE_PARM_DESC(pcm_channels, "Reserved PCM channels for InterWave driver.");
988c2ecf20Sopenharmony_cimodule_param_array(effect, int, NULL, 0444);
998c2ecf20Sopenharmony_ciMODULE_PARM_DESC(effect, "Effects enable for InterWave driver.");
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_cistruct snd_interwave {
1028c2ecf20Sopenharmony_ci	int irq;
1038c2ecf20Sopenharmony_ci	struct snd_card *card;
1048c2ecf20Sopenharmony_ci	struct snd_gus_card *gus;
1058c2ecf20Sopenharmony_ci	struct snd_wss *wss;
1068c2ecf20Sopenharmony_ci#ifdef SNDRV_STB
1078c2ecf20Sopenharmony_ci	struct resource *i2c_res;
1088c2ecf20Sopenharmony_ci#endif
1098c2ecf20Sopenharmony_ci	unsigned short gus_status_reg;
1108c2ecf20Sopenharmony_ci	unsigned short pcm_status_reg;
1118c2ecf20Sopenharmony_ci#ifdef CONFIG_PNP
1128c2ecf20Sopenharmony_ci	struct pnp_dev *dev;
1138c2ecf20Sopenharmony_ci#ifdef SNDRV_STB
1148c2ecf20Sopenharmony_ci	struct pnp_dev *devtc;
1158c2ecf20Sopenharmony_ci#endif
1168c2ecf20Sopenharmony_ci#endif
1178c2ecf20Sopenharmony_ci};
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci#ifdef CONFIG_PNP
1218c2ecf20Sopenharmony_cistatic int isa_registered;
1228c2ecf20Sopenharmony_cistatic int pnp_registered;
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_cistatic const struct pnp_card_device_id snd_interwave_pnpids[] = {
1258c2ecf20Sopenharmony_ci#ifndef SNDRV_STB
1268c2ecf20Sopenharmony_ci	/* Gravis UltraSound Plug & Play */
1278c2ecf20Sopenharmony_ci	{ .id = "GRV0001", .devs = { { .id = "GRV0000" } } },
1288c2ecf20Sopenharmony_ci	/* STB SoundRage32 */
1298c2ecf20Sopenharmony_ci	{ .id = "STB011a", .devs = { { .id = "STB0010" } } },
1308c2ecf20Sopenharmony_ci	/* MED3210 */
1318c2ecf20Sopenharmony_ci	{ .id = "DXP3201", .devs = { { .id = "DXP0010" } } },
1328c2ecf20Sopenharmony_ci	/* Dynasonic Pro */
1338c2ecf20Sopenharmony_ci	/* This device also have CDC1117:DynaSonix Pro Audio Effects Processor */
1348c2ecf20Sopenharmony_ci	{ .id = "CDC1111", .devs = { { .id = "CDC1112" } } },
1358c2ecf20Sopenharmony_ci	/* Panasonic PCA761AW Audio Card */
1368c2ecf20Sopenharmony_ci	{ .id = "ADV55ff", .devs = { { .id = "ADV0010" } } },
1378c2ecf20Sopenharmony_ci	/* InterWave STB without TEA6330T */
1388c2ecf20Sopenharmony_ci	{ .id = "ADV550a", .devs = { { .id = "ADV0010" } } },
1398c2ecf20Sopenharmony_ci#else
1408c2ecf20Sopenharmony_ci	/* InterWave STB with TEA6330T */
1418c2ecf20Sopenharmony_ci	{ .id = "ADV550a", .devs = { { .id = "ADV0010" }, { .id = "ADV0015" } } },
1428c2ecf20Sopenharmony_ci#endif
1438c2ecf20Sopenharmony_ci	{ .id = "" }
1448c2ecf20Sopenharmony_ci};
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(pnp_card, snd_interwave_pnpids);
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci#endif /* CONFIG_PNP */
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci#ifdef SNDRV_STB
1528c2ecf20Sopenharmony_cistatic void snd_interwave_i2c_setlines(struct snd_i2c_bus *bus, int ctrl, int data)
1538c2ecf20Sopenharmony_ci{
1548c2ecf20Sopenharmony_ci	unsigned long port = bus->private_value;
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci#if 0
1578c2ecf20Sopenharmony_ci	printk(KERN_DEBUG "i2c_setlines - 0x%lx <- %i,%i\n", port, ctrl, data);
1588c2ecf20Sopenharmony_ci#endif
1598c2ecf20Sopenharmony_ci	outb((data << 1) | ctrl, port);
1608c2ecf20Sopenharmony_ci	udelay(10);
1618c2ecf20Sopenharmony_ci}
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_cistatic int snd_interwave_i2c_getclockline(struct snd_i2c_bus *bus)
1648c2ecf20Sopenharmony_ci{
1658c2ecf20Sopenharmony_ci	unsigned long port = bus->private_value;
1668c2ecf20Sopenharmony_ci	unsigned char res;
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ci	res = inb(port) & 1;
1698c2ecf20Sopenharmony_ci#if 0
1708c2ecf20Sopenharmony_ci	printk(KERN_DEBUG "i2c_getclockline - 0x%lx -> %i\n", port, res);
1718c2ecf20Sopenharmony_ci#endif
1728c2ecf20Sopenharmony_ci	return res;
1738c2ecf20Sopenharmony_ci}
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_cistatic int snd_interwave_i2c_getdataline(struct snd_i2c_bus *bus, int ack)
1768c2ecf20Sopenharmony_ci{
1778c2ecf20Sopenharmony_ci	unsigned long port = bus->private_value;
1788c2ecf20Sopenharmony_ci	unsigned char res;
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci	if (ack)
1818c2ecf20Sopenharmony_ci		udelay(10);
1828c2ecf20Sopenharmony_ci	res = (inb(port) & 2) >> 1;
1838c2ecf20Sopenharmony_ci#if 0
1848c2ecf20Sopenharmony_ci	printk(KERN_DEBUG "i2c_getdataline - 0x%lx -> %i\n", port, res);
1858c2ecf20Sopenharmony_ci#endif
1868c2ecf20Sopenharmony_ci	return res;
1878c2ecf20Sopenharmony_ci}
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_cistatic struct snd_i2c_bit_ops snd_interwave_i2c_bit_ops = {
1908c2ecf20Sopenharmony_ci	.setlines = snd_interwave_i2c_setlines,
1918c2ecf20Sopenharmony_ci	.getclock = snd_interwave_i2c_getclockline,
1928c2ecf20Sopenharmony_ci	.getdata  = snd_interwave_i2c_getdataline,
1938c2ecf20Sopenharmony_ci};
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_cistatic int snd_interwave_detect_stb(struct snd_interwave *iwcard,
1968c2ecf20Sopenharmony_ci				    struct snd_gus_card *gus, int dev,
1978c2ecf20Sopenharmony_ci				    struct snd_i2c_bus **rbus)
1988c2ecf20Sopenharmony_ci{
1998c2ecf20Sopenharmony_ci	unsigned long port;
2008c2ecf20Sopenharmony_ci	struct snd_i2c_bus *bus;
2018c2ecf20Sopenharmony_ci	struct snd_card *card = iwcard->card;
2028c2ecf20Sopenharmony_ci	char name[32];
2038c2ecf20Sopenharmony_ci	int err;
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ci	*rbus = NULL;
2068c2ecf20Sopenharmony_ci	port = port_tc[dev];
2078c2ecf20Sopenharmony_ci	if (port == SNDRV_AUTO_PORT) {
2088c2ecf20Sopenharmony_ci		port = 0x350;
2098c2ecf20Sopenharmony_ci		if (gus->gf1.port == 0x250) {
2108c2ecf20Sopenharmony_ci			port = 0x360;
2118c2ecf20Sopenharmony_ci		}
2128c2ecf20Sopenharmony_ci		while (port <= 0x380) {
2138c2ecf20Sopenharmony_ci			if ((iwcard->i2c_res = request_region(port, 1, "InterWave (I2C bus)")) != NULL)
2148c2ecf20Sopenharmony_ci				break;
2158c2ecf20Sopenharmony_ci			port += 0x10;
2168c2ecf20Sopenharmony_ci		}
2178c2ecf20Sopenharmony_ci	} else {
2188c2ecf20Sopenharmony_ci		iwcard->i2c_res = request_region(port, 1, "InterWave (I2C bus)");
2198c2ecf20Sopenharmony_ci	}
2208c2ecf20Sopenharmony_ci	if (iwcard->i2c_res == NULL) {
2218c2ecf20Sopenharmony_ci		snd_printk(KERN_ERR "interwave: can't grab i2c bus port\n");
2228c2ecf20Sopenharmony_ci		return -ENODEV;
2238c2ecf20Sopenharmony_ci	}
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_ci	sprintf(name, "InterWave-%i", card->number);
2268c2ecf20Sopenharmony_ci	if ((err = snd_i2c_bus_create(card, name, NULL, &bus)) < 0)
2278c2ecf20Sopenharmony_ci		return err;
2288c2ecf20Sopenharmony_ci	bus->private_value = port;
2298c2ecf20Sopenharmony_ci	bus->hw_ops.bit = &snd_interwave_i2c_bit_ops;
2308c2ecf20Sopenharmony_ci	if ((err = snd_tea6330t_detect(bus, 0)) < 0)
2318c2ecf20Sopenharmony_ci		return err;
2328c2ecf20Sopenharmony_ci	*rbus = bus;
2338c2ecf20Sopenharmony_ci	return 0;
2348c2ecf20Sopenharmony_ci}
2358c2ecf20Sopenharmony_ci#endif
2368c2ecf20Sopenharmony_ci
2378c2ecf20Sopenharmony_cistatic int snd_interwave_detect(struct snd_interwave *iwcard,
2388c2ecf20Sopenharmony_ci				struct snd_gus_card *gus,
2398c2ecf20Sopenharmony_ci				int dev
2408c2ecf20Sopenharmony_ci#ifdef SNDRV_STB
2418c2ecf20Sopenharmony_ci				, struct snd_i2c_bus **rbus
2428c2ecf20Sopenharmony_ci#endif
2438c2ecf20Sopenharmony_ci				          )
2448c2ecf20Sopenharmony_ci{
2458c2ecf20Sopenharmony_ci	unsigned long flags;
2468c2ecf20Sopenharmony_ci	unsigned char rev1, rev2;
2478c2ecf20Sopenharmony_ci	int d;
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_ci	snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 0);	/* reset GF1 */
2508c2ecf20Sopenharmony_ci	if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 0) {
2518c2ecf20Sopenharmony_ci		snd_printdd("[0x%lx] check 1 failed - 0x%x\n", gus->gf1.port, d);
2528c2ecf20Sopenharmony_ci		return -ENODEV;
2538c2ecf20Sopenharmony_ci	}
2548c2ecf20Sopenharmony_ci	udelay(160);
2558c2ecf20Sopenharmony_ci	snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 1);	/* release reset */
2568c2ecf20Sopenharmony_ci	udelay(160);
2578c2ecf20Sopenharmony_ci	if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 1) {
2588c2ecf20Sopenharmony_ci		snd_printdd("[0x%lx] check 2 failed - 0x%x\n", gus->gf1.port, d);
2598c2ecf20Sopenharmony_ci		return -ENODEV;
2608c2ecf20Sopenharmony_ci	}
2618c2ecf20Sopenharmony_ci	spin_lock_irqsave(&gus->reg_lock, flags);
2628c2ecf20Sopenharmony_ci	rev1 = snd_gf1_look8(gus, SNDRV_GF1_GB_VERSION_NUMBER);
2638c2ecf20Sopenharmony_ci	snd_gf1_write8(gus, SNDRV_GF1_GB_VERSION_NUMBER, ~rev1);
2648c2ecf20Sopenharmony_ci	rev2 = snd_gf1_look8(gus, SNDRV_GF1_GB_VERSION_NUMBER);
2658c2ecf20Sopenharmony_ci	snd_gf1_write8(gus, SNDRV_GF1_GB_VERSION_NUMBER, rev1);
2668c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&gus->reg_lock, flags);
2678c2ecf20Sopenharmony_ci	snd_printdd("[0x%lx] InterWave check - rev1=0x%x, rev2=0x%x\n", gus->gf1.port, rev1, rev2);
2688c2ecf20Sopenharmony_ci	if ((rev1 & 0xf0) == (rev2 & 0xf0) &&
2698c2ecf20Sopenharmony_ci	    (rev1 & 0x0f) != (rev2 & 0x0f)) {
2708c2ecf20Sopenharmony_ci		snd_printdd("[0x%lx] InterWave check - passed\n", gus->gf1.port);
2718c2ecf20Sopenharmony_ci		gus->interwave = 1;
2728c2ecf20Sopenharmony_ci		strcpy(gus->card->shortname, "AMD InterWave");
2738c2ecf20Sopenharmony_ci		gus->revision = rev1 >> 4;
2748c2ecf20Sopenharmony_ci#ifndef SNDRV_STB
2758c2ecf20Sopenharmony_ci		return 0;	/* ok.. We have an InterWave board */
2768c2ecf20Sopenharmony_ci#else
2778c2ecf20Sopenharmony_ci		return snd_interwave_detect_stb(iwcard, gus, dev, rbus);
2788c2ecf20Sopenharmony_ci#endif
2798c2ecf20Sopenharmony_ci	}
2808c2ecf20Sopenharmony_ci	snd_printdd("[0x%lx] InterWave check - failed\n", gus->gf1.port);
2818c2ecf20Sopenharmony_ci	return -ENODEV;
2828c2ecf20Sopenharmony_ci}
2838c2ecf20Sopenharmony_ci
2848c2ecf20Sopenharmony_cistatic irqreturn_t snd_interwave_interrupt(int irq, void *dev_id)
2858c2ecf20Sopenharmony_ci{
2868c2ecf20Sopenharmony_ci	struct snd_interwave *iwcard = dev_id;
2878c2ecf20Sopenharmony_ci	int loop, max = 5;
2888c2ecf20Sopenharmony_ci	int handled = 0;
2898c2ecf20Sopenharmony_ci
2908c2ecf20Sopenharmony_ci	do {
2918c2ecf20Sopenharmony_ci		loop = 0;
2928c2ecf20Sopenharmony_ci		if (inb(iwcard->gus_status_reg)) {
2938c2ecf20Sopenharmony_ci			handled = 1;
2948c2ecf20Sopenharmony_ci			snd_gus_interrupt(irq, iwcard->gus);
2958c2ecf20Sopenharmony_ci			loop++;
2968c2ecf20Sopenharmony_ci		}
2978c2ecf20Sopenharmony_ci		if (inb(iwcard->pcm_status_reg) & 0x01) {	/* IRQ bit is set? */
2988c2ecf20Sopenharmony_ci			handled = 1;
2998c2ecf20Sopenharmony_ci			snd_wss_interrupt(irq, iwcard->wss);
3008c2ecf20Sopenharmony_ci			loop++;
3018c2ecf20Sopenharmony_ci		}
3028c2ecf20Sopenharmony_ci	} while (loop && --max > 0);
3038c2ecf20Sopenharmony_ci	return IRQ_RETVAL(handled);
3048c2ecf20Sopenharmony_ci}
3058c2ecf20Sopenharmony_ci
3068c2ecf20Sopenharmony_cistatic void snd_interwave_reset(struct snd_gus_card *gus)
3078c2ecf20Sopenharmony_ci{
3088c2ecf20Sopenharmony_ci	snd_gf1_write8(gus, SNDRV_GF1_GB_RESET, 0x00);
3098c2ecf20Sopenharmony_ci	udelay(160);
3108c2ecf20Sopenharmony_ci	snd_gf1_write8(gus, SNDRV_GF1_GB_RESET, 0x01);
3118c2ecf20Sopenharmony_ci	udelay(160);
3128c2ecf20Sopenharmony_ci}
3138c2ecf20Sopenharmony_ci
3148c2ecf20Sopenharmony_cistatic void snd_interwave_bank_sizes(struct snd_gus_card *gus, int *sizes)
3158c2ecf20Sopenharmony_ci{
3168c2ecf20Sopenharmony_ci	unsigned int idx;
3178c2ecf20Sopenharmony_ci	unsigned int local;
3188c2ecf20Sopenharmony_ci	unsigned char d;
3198c2ecf20Sopenharmony_ci
3208c2ecf20Sopenharmony_ci	for (idx = 0; idx < 4; idx++) {
3218c2ecf20Sopenharmony_ci		sizes[idx] = 0;
3228c2ecf20Sopenharmony_ci		d = 0x55;
3238c2ecf20Sopenharmony_ci		for (local = idx << 22;
3248c2ecf20Sopenharmony_ci		     local < (idx << 22) + 0x400000;
3258c2ecf20Sopenharmony_ci		     local += 0x40000, d++) {
3268c2ecf20Sopenharmony_ci			snd_gf1_poke(gus, local, d);
3278c2ecf20Sopenharmony_ci			snd_gf1_poke(gus, local + 1, d + 1);
3288c2ecf20Sopenharmony_ci#if 0
3298c2ecf20Sopenharmony_ci			printk(KERN_DEBUG "d = 0x%x, local = 0x%x, "
3308c2ecf20Sopenharmony_ci			       "local + 1 = 0x%x, idx << 22 = 0x%x\n",
3318c2ecf20Sopenharmony_ci			       d,
3328c2ecf20Sopenharmony_ci			       snd_gf1_peek(gus, local),
3338c2ecf20Sopenharmony_ci			       snd_gf1_peek(gus, local + 1),
3348c2ecf20Sopenharmony_ci			       snd_gf1_peek(gus, idx << 22));
3358c2ecf20Sopenharmony_ci#endif
3368c2ecf20Sopenharmony_ci			if (snd_gf1_peek(gus, local) != d ||
3378c2ecf20Sopenharmony_ci			    snd_gf1_peek(gus, local + 1) != d + 1 ||
3388c2ecf20Sopenharmony_ci			    snd_gf1_peek(gus, idx << 22) != 0x55)
3398c2ecf20Sopenharmony_ci				break;
3408c2ecf20Sopenharmony_ci			sizes[idx]++;
3418c2ecf20Sopenharmony_ci		}
3428c2ecf20Sopenharmony_ci	}
3438c2ecf20Sopenharmony_ci#if 0
3448c2ecf20Sopenharmony_ci	printk(KERN_DEBUG "sizes: %i %i %i %i\n",
3458c2ecf20Sopenharmony_ci	       sizes[0], sizes[1], sizes[2], sizes[3]);
3468c2ecf20Sopenharmony_ci#endif
3478c2ecf20Sopenharmony_ci}
3488c2ecf20Sopenharmony_ci
3498c2ecf20Sopenharmony_cistruct rom_hdr {
3508c2ecf20Sopenharmony_ci	/* 000 */ unsigned char iwave[8];
3518c2ecf20Sopenharmony_ci	/* 008 */ unsigned char rom_hdr_revision;
3528c2ecf20Sopenharmony_ci	/* 009 */ unsigned char series_number;
3538c2ecf20Sopenharmony_ci	/* 010 */ unsigned char series_name[16];
3548c2ecf20Sopenharmony_ci	/* 026 */ unsigned char date[10];
3558c2ecf20Sopenharmony_ci	/* 036 */ unsigned short vendor_revision_major;
3568c2ecf20Sopenharmony_ci	/* 038 */ unsigned short vendor_revision_minor;
3578c2ecf20Sopenharmony_ci	/* 040 */ unsigned int rom_size;
3588c2ecf20Sopenharmony_ci	/* 044 */ unsigned char copyright[128];
3598c2ecf20Sopenharmony_ci	/* 172 */ unsigned char vendor_name[64];
3608c2ecf20Sopenharmony_ci	/* 236 */ unsigned char rom_description[128];
3618c2ecf20Sopenharmony_ci	/* 364 */ unsigned char pad[147];
3628c2ecf20Sopenharmony_ci	/* 511 */ unsigned char csum;
3638c2ecf20Sopenharmony_ci};
3648c2ecf20Sopenharmony_ci
3658c2ecf20Sopenharmony_cistatic void snd_interwave_detect_memory(struct snd_gus_card *gus)
3668c2ecf20Sopenharmony_ci{
3678c2ecf20Sopenharmony_ci	static const unsigned int lmc[13] =
3688c2ecf20Sopenharmony_ci	{
3698c2ecf20Sopenharmony_ci		0x00000001, 0x00000101, 0x01010101, 0x00000401,
3708c2ecf20Sopenharmony_ci		0x04040401, 0x00040101, 0x04040101, 0x00000004,
3718c2ecf20Sopenharmony_ci		0x00000404, 0x04040404, 0x00000010, 0x00001010,
3728c2ecf20Sopenharmony_ci		0x10101010
3738c2ecf20Sopenharmony_ci	};
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_ci	int bank_pos, pages;
3768c2ecf20Sopenharmony_ci	unsigned int i, lmct;
3778c2ecf20Sopenharmony_ci	int psizes[4];
3788c2ecf20Sopenharmony_ci	unsigned char iwave[8];
3798c2ecf20Sopenharmony_ci	unsigned char csum;
3808c2ecf20Sopenharmony_ci
3818c2ecf20Sopenharmony_ci	snd_interwave_reset(gus);
3828c2ecf20Sopenharmony_ci	snd_gf1_write8(gus, SNDRV_GF1_GB_GLOBAL_MODE, snd_gf1_read8(gus, SNDRV_GF1_GB_GLOBAL_MODE) | 0x01);		/* enhanced mode */
3838c2ecf20Sopenharmony_ci	snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, 0x01);	/* DRAM I/O cycles selected */
3848c2ecf20Sopenharmony_ci	snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, (snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xff10) | 0x004c);
3858c2ecf20Sopenharmony_ci	/* ok.. simple test of memory size */
3868c2ecf20Sopenharmony_ci	pages = 0;
3878c2ecf20Sopenharmony_ci	snd_gf1_poke(gus, 0, 0x55);
3888c2ecf20Sopenharmony_ci	snd_gf1_poke(gus, 1, 0xaa);
3898c2ecf20Sopenharmony_ci#if 1
3908c2ecf20Sopenharmony_ci	if (snd_gf1_peek(gus, 0) == 0x55 && snd_gf1_peek(gus, 1) == 0xaa)
3918c2ecf20Sopenharmony_ci#else
3928c2ecf20Sopenharmony_ci	if (0)			/* ok.. for testing of 0k RAM */
3938c2ecf20Sopenharmony_ci#endif
3948c2ecf20Sopenharmony_ci	{
3958c2ecf20Sopenharmony_ci		snd_interwave_bank_sizes(gus, psizes);
3968c2ecf20Sopenharmony_ci		lmct = (psizes[3] << 24) | (psizes[2] << 16) |
3978c2ecf20Sopenharmony_ci		    (psizes[1] << 8) | psizes[0];
3988c2ecf20Sopenharmony_ci#if 0
3998c2ecf20Sopenharmony_ci		printk(KERN_DEBUG "lmct = 0x%08x\n", lmct);
4008c2ecf20Sopenharmony_ci#endif
4018c2ecf20Sopenharmony_ci		for (i = 0; i < ARRAY_SIZE(lmc); i++)
4028c2ecf20Sopenharmony_ci			if (lmct == lmc[i]) {
4038c2ecf20Sopenharmony_ci#if 0
4048c2ecf20Sopenharmony_ci				printk(KERN_DEBUG "found !!! %i\n", i);
4058c2ecf20Sopenharmony_ci#endif
4068c2ecf20Sopenharmony_ci				snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, (snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xfff0) | i);
4078c2ecf20Sopenharmony_ci				snd_interwave_bank_sizes(gus, psizes);
4088c2ecf20Sopenharmony_ci				break;
4098c2ecf20Sopenharmony_ci			}
4108c2ecf20Sopenharmony_ci		if (i >= ARRAY_SIZE(lmc) && !gus->gf1.enh_mode)
4118c2ecf20Sopenharmony_ci			 snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, (snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xfff0) | 2);
4128c2ecf20Sopenharmony_ci		for (i = 0; i < 4; i++) {
4138c2ecf20Sopenharmony_ci			gus->gf1.mem_alloc.banks_8[i].address =
4148c2ecf20Sopenharmony_ci			    gus->gf1.mem_alloc.banks_16[i].address = i << 22;
4158c2ecf20Sopenharmony_ci			gus->gf1.mem_alloc.banks_8[i].size =
4168c2ecf20Sopenharmony_ci			    gus->gf1.mem_alloc.banks_16[i].size = psizes[i] << 18;
4178c2ecf20Sopenharmony_ci			pages += psizes[i];
4188c2ecf20Sopenharmony_ci		}
4198c2ecf20Sopenharmony_ci	}
4208c2ecf20Sopenharmony_ci	pages <<= 18;
4218c2ecf20Sopenharmony_ci	gus->gf1.memory = pages;
4228c2ecf20Sopenharmony_ci
4238c2ecf20Sopenharmony_ci	snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, 0x03);	/* select ROM */
4248c2ecf20Sopenharmony_ci	snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, (snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xff1f) | (4 << 5));
4258c2ecf20Sopenharmony_ci	gus->gf1.rom_banks = 0;
4268c2ecf20Sopenharmony_ci	gus->gf1.rom_memory = 0;
4278c2ecf20Sopenharmony_ci	for (bank_pos = 0; bank_pos < 16L * 1024L * 1024L; bank_pos += 4L * 1024L * 1024L) {
4288c2ecf20Sopenharmony_ci		for (i = 0; i < 8; ++i)
4298c2ecf20Sopenharmony_ci			iwave[i] = snd_gf1_peek(gus, bank_pos + i);
4308c2ecf20Sopenharmony_ci		if (strncmp(iwave, "INTRWAVE", 8))
4318c2ecf20Sopenharmony_ci			continue;	/* first check */
4328c2ecf20Sopenharmony_ci		csum = 0;
4338c2ecf20Sopenharmony_ci		for (i = 0; i < sizeof(struct rom_hdr); i++)
4348c2ecf20Sopenharmony_ci			csum += snd_gf1_peek(gus, bank_pos + i);
4358c2ecf20Sopenharmony_ci		if (csum != 0)
4368c2ecf20Sopenharmony_ci			continue;	/* not valid rom */
4378c2ecf20Sopenharmony_ci		gus->gf1.rom_banks++;
4388c2ecf20Sopenharmony_ci		gus->gf1.rom_present |= 1 << (bank_pos >> 22);
4398c2ecf20Sopenharmony_ci		gus->gf1.rom_memory = snd_gf1_peek(gus, bank_pos + 40) |
4408c2ecf20Sopenharmony_ci				     (snd_gf1_peek(gus, bank_pos + 41) << 8) |
4418c2ecf20Sopenharmony_ci				     (snd_gf1_peek(gus, bank_pos + 42) << 16) |
4428c2ecf20Sopenharmony_ci				     (snd_gf1_peek(gus, bank_pos + 43) << 24);
4438c2ecf20Sopenharmony_ci	}
4448c2ecf20Sopenharmony_ci#if 0
4458c2ecf20Sopenharmony_ci	if (gus->gf1.rom_memory > 0) {
4468c2ecf20Sopenharmony_ci		if (gus->gf1.rom_banks == 1 && gus->gf1.rom_present == 8)
4478c2ecf20Sopenharmony_ci			gus->card->type = SNDRV_CARD_TYPE_IW_DYNASONIC;
4488c2ecf20Sopenharmony_ci	}
4498c2ecf20Sopenharmony_ci#endif
4508c2ecf20Sopenharmony_ci	snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, 0x00);	/* select RAM */
4518c2ecf20Sopenharmony_ci
4528c2ecf20Sopenharmony_ci	if (!gus->gf1.enh_mode)
4538c2ecf20Sopenharmony_ci		snd_interwave_reset(gus);
4548c2ecf20Sopenharmony_ci}
4558c2ecf20Sopenharmony_ci
4568c2ecf20Sopenharmony_cistatic void snd_interwave_init(int dev, struct snd_gus_card *gus)
4578c2ecf20Sopenharmony_ci{
4588c2ecf20Sopenharmony_ci	unsigned long flags;
4598c2ecf20Sopenharmony_ci
4608c2ecf20Sopenharmony_ci	/* ok.. some InterWave specific initialization */
4618c2ecf20Sopenharmony_ci	spin_lock_irqsave(&gus->reg_lock, flags);
4628c2ecf20Sopenharmony_ci	snd_gf1_write8(gus, SNDRV_GF1_GB_SOUND_BLASTER_CONTROL, 0x00);
4638c2ecf20Sopenharmony_ci	snd_gf1_write8(gus, SNDRV_GF1_GB_COMPATIBILITY, 0x1f);
4648c2ecf20Sopenharmony_ci	snd_gf1_write8(gus, SNDRV_GF1_GB_DECODE_CONTROL, 0x49);
4658c2ecf20Sopenharmony_ci	snd_gf1_write8(gus, SNDRV_GF1_GB_VERSION_NUMBER, 0x11);
4668c2ecf20Sopenharmony_ci	snd_gf1_write8(gus, SNDRV_GF1_GB_MPU401_CONTROL_A, 0x00);
4678c2ecf20Sopenharmony_ci	snd_gf1_write8(gus, SNDRV_GF1_GB_MPU401_CONTROL_B, 0x30);
4688c2ecf20Sopenharmony_ci	snd_gf1_write8(gus, SNDRV_GF1_GB_EMULATION_IRQ, 0x00);
4698c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&gus->reg_lock, flags);
4708c2ecf20Sopenharmony_ci	gus->equal_irq = 1;
4718c2ecf20Sopenharmony_ci	gus->codec_flag = 1;
4728c2ecf20Sopenharmony_ci	gus->interwave = 1;
4738c2ecf20Sopenharmony_ci	gus->max_flag = 1;
4748c2ecf20Sopenharmony_ci	gus->joystick_dac = joystick_dac[dev];
4758c2ecf20Sopenharmony_ci
4768c2ecf20Sopenharmony_ci}
4778c2ecf20Sopenharmony_ci
4788c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new snd_interwave_controls[] = {
4798c2ecf20Sopenharmony_ciWSS_DOUBLE("Master Playback Switch", 0,
4808c2ecf20Sopenharmony_ci		CS4231_LINE_LEFT_OUTPUT, CS4231_LINE_RIGHT_OUTPUT, 7, 7, 1, 1),
4818c2ecf20Sopenharmony_ciWSS_DOUBLE("Master Playback Volume", 0,
4828c2ecf20Sopenharmony_ci		CS4231_LINE_LEFT_OUTPUT, CS4231_LINE_RIGHT_OUTPUT, 0, 0, 31, 1),
4838c2ecf20Sopenharmony_ciWSS_DOUBLE("Mic Playback Switch", 0,
4848c2ecf20Sopenharmony_ci		CS4231_LEFT_MIC_INPUT, CS4231_RIGHT_MIC_INPUT, 7, 7, 1, 1),
4858c2ecf20Sopenharmony_ciWSS_DOUBLE("Mic Playback Volume", 0,
4868c2ecf20Sopenharmony_ci		CS4231_LEFT_MIC_INPUT, CS4231_RIGHT_MIC_INPUT, 0, 0, 31, 1)
4878c2ecf20Sopenharmony_ci};
4888c2ecf20Sopenharmony_ci
4898c2ecf20Sopenharmony_cistatic int snd_interwave_mixer(struct snd_wss *chip)
4908c2ecf20Sopenharmony_ci{
4918c2ecf20Sopenharmony_ci	struct snd_card *card = chip->card;
4928c2ecf20Sopenharmony_ci	struct snd_ctl_elem_id id1, id2;
4938c2ecf20Sopenharmony_ci	unsigned int idx;
4948c2ecf20Sopenharmony_ci	int err;
4958c2ecf20Sopenharmony_ci
4968c2ecf20Sopenharmony_ci	memset(&id1, 0, sizeof(id1));
4978c2ecf20Sopenharmony_ci	memset(&id2, 0, sizeof(id2));
4988c2ecf20Sopenharmony_ci	id1.iface = id2.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
4998c2ecf20Sopenharmony_ci#if 0
5008c2ecf20Sopenharmony_ci	/* remove mono microphone controls */
5018c2ecf20Sopenharmony_ci	strcpy(id1.name, "Mic Playback Switch");
5028c2ecf20Sopenharmony_ci	if ((err = snd_ctl_remove_id(card, &id1)) < 0)
5038c2ecf20Sopenharmony_ci		return err;
5048c2ecf20Sopenharmony_ci	strcpy(id1.name, "Mic Playback Volume");
5058c2ecf20Sopenharmony_ci	if ((err = snd_ctl_remove_id(card, &id1)) < 0)
5068c2ecf20Sopenharmony_ci		return err;
5078c2ecf20Sopenharmony_ci#endif
5088c2ecf20Sopenharmony_ci	/* add new master and mic controls */
5098c2ecf20Sopenharmony_ci	for (idx = 0; idx < ARRAY_SIZE(snd_interwave_controls); idx++)
5108c2ecf20Sopenharmony_ci		if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_interwave_controls[idx], chip))) < 0)
5118c2ecf20Sopenharmony_ci			return err;
5128c2ecf20Sopenharmony_ci	snd_wss_out(chip, CS4231_LINE_LEFT_OUTPUT, 0x9f);
5138c2ecf20Sopenharmony_ci	snd_wss_out(chip, CS4231_LINE_RIGHT_OUTPUT, 0x9f);
5148c2ecf20Sopenharmony_ci	snd_wss_out(chip, CS4231_LEFT_MIC_INPUT, 0x9f);
5158c2ecf20Sopenharmony_ci	snd_wss_out(chip, CS4231_RIGHT_MIC_INPUT, 0x9f);
5168c2ecf20Sopenharmony_ci	/* reassign AUXA to SYNTHESIZER */
5178c2ecf20Sopenharmony_ci	strcpy(id1.name, "Aux Playback Switch");
5188c2ecf20Sopenharmony_ci	strcpy(id2.name, "Synth Playback Switch");
5198c2ecf20Sopenharmony_ci	if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
5208c2ecf20Sopenharmony_ci		return err;
5218c2ecf20Sopenharmony_ci	strcpy(id1.name, "Aux Playback Volume");
5228c2ecf20Sopenharmony_ci	strcpy(id2.name, "Synth Playback Volume");
5238c2ecf20Sopenharmony_ci	if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
5248c2ecf20Sopenharmony_ci		return err;
5258c2ecf20Sopenharmony_ci	/* reassign AUXB to CD */
5268c2ecf20Sopenharmony_ci	strcpy(id1.name, "Aux Playback Switch"); id1.index = 1;
5278c2ecf20Sopenharmony_ci	strcpy(id2.name, "CD Playback Switch");
5288c2ecf20Sopenharmony_ci	if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
5298c2ecf20Sopenharmony_ci		return err;
5308c2ecf20Sopenharmony_ci	strcpy(id1.name, "Aux Playback Volume");
5318c2ecf20Sopenharmony_ci	strcpy(id2.name, "CD Playback Volume");
5328c2ecf20Sopenharmony_ci	if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
5338c2ecf20Sopenharmony_ci		return err;
5348c2ecf20Sopenharmony_ci	return 0;
5358c2ecf20Sopenharmony_ci}
5368c2ecf20Sopenharmony_ci
5378c2ecf20Sopenharmony_ci#ifdef CONFIG_PNP
5388c2ecf20Sopenharmony_ci
5398c2ecf20Sopenharmony_cistatic int snd_interwave_pnp(int dev, struct snd_interwave *iwcard,
5408c2ecf20Sopenharmony_ci			     struct pnp_card_link *card,
5418c2ecf20Sopenharmony_ci			     const struct pnp_card_device_id *id)
5428c2ecf20Sopenharmony_ci{
5438c2ecf20Sopenharmony_ci	struct pnp_dev *pdev;
5448c2ecf20Sopenharmony_ci	int err;
5458c2ecf20Sopenharmony_ci
5468c2ecf20Sopenharmony_ci	iwcard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
5478c2ecf20Sopenharmony_ci	if (iwcard->dev == NULL)
5488c2ecf20Sopenharmony_ci		return -EBUSY;
5498c2ecf20Sopenharmony_ci
5508c2ecf20Sopenharmony_ci#ifdef SNDRV_STB
5518c2ecf20Sopenharmony_ci	iwcard->devtc = pnp_request_card_device(card, id->devs[1].id, NULL);
5528c2ecf20Sopenharmony_ci	if (iwcard->devtc == NULL)
5538c2ecf20Sopenharmony_ci		return -EBUSY;
5548c2ecf20Sopenharmony_ci#endif
5558c2ecf20Sopenharmony_ci	/* Synth & Codec initialization */
5568c2ecf20Sopenharmony_ci	pdev = iwcard->dev;
5578c2ecf20Sopenharmony_ci
5588c2ecf20Sopenharmony_ci	err = pnp_activate_dev(pdev);
5598c2ecf20Sopenharmony_ci	if (err < 0) {
5608c2ecf20Sopenharmony_ci		snd_printk(KERN_ERR "InterWave PnP configure failure (out of resources?)\n");
5618c2ecf20Sopenharmony_ci		return err;
5628c2ecf20Sopenharmony_ci	}
5638c2ecf20Sopenharmony_ci	if (pnp_port_start(pdev, 0) + 0x100 != pnp_port_start(pdev, 1) ||
5648c2ecf20Sopenharmony_ci	    pnp_port_start(pdev, 0) + 0x10c != pnp_port_start(pdev, 2)) {
5658c2ecf20Sopenharmony_ci		snd_printk(KERN_ERR "PnP configure failure (wrong ports)\n");
5668c2ecf20Sopenharmony_ci		return -ENOENT;
5678c2ecf20Sopenharmony_ci	}
5688c2ecf20Sopenharmony_ci	port[dev] = pnp_port_start(pdev, 0);
5698c2ecf20Sopenharmony_ci	dma1[dev] = pnp_dma(pdev, 0);
5708c2ecf20Sopenharmony_ci	if (dma2[dev] >= 0)
5718c2ecf20Sopenharmony_ci		dma2[dev] = pnp_dma(pdev, 1);
5728c2ecf20Sopenharmony_ci	irq[dev] = pnp_irq(pdev, 0);
5738c2ecf20Sopenharmony_ci	snd_printdd("isapnp IW: sb port=0x%llx, gf1 port=0x%llx, codec port=0x%llx\n",
5748c2ecf20Sopenharmony_ci			(unsigned long long)pnp_port_start(pdev, 0),
5758c2ecf20Sopenharmony_ci			(unsigned long long)pnp_port_start(pdev, 1),
5768c2ecf20Sopenharmony_ci			(unsigned long long)pnp_port_start(pdev, 2));
5778c2ecf20Sopenharmony_ci	snd_printdd("isapnp IW: dma1=%i, dma2=%i, irq=%i\n", dma1[dev], dma2[dev], irq[dev]);
5788c2ecf20Sopenharmony_ci#ifdef SNDRV_STB
5798c2ecf20Sopenharmony_ci	/* Tone Control initialization */
5808c2ecf20Sopenharmony_ci	pdev = iwcard->devtc;
5818c2ecf20Sopenharmony_ci
5828c2ecf20Sopenharmony_ci	err = pnp_activate_dev(pdev);
5838c2ecf20Sopenharmony_ci	if (err < 0) {
5848c2ecf20Sopenharmony_ci		snd_printk(KERN_ERR "InterWave ToneControl PnP configure failure (out of resources?)\n");
5858c2ecf20Sopenharmony_ci		return err;
5868c2ecf20Sopenharmony_ci	}
5878c2ecf20Sopenharmony_ci	port_tc[dev] = pnp_port_start(pdev, 0);
5888c2ecf20Sopenharmony_ci	snd_printdd("isapnp IW: tone control port=0x%lx\n", port_tc[dev]);
5898c2ecf20Sopenharmony_ci#endif
5908c2ecf20Sopenharmony_ci	return 0;
5918c2ecf20Sopenharmony_ci}
5928c2ecf20Sopenharmony_ci#endif /* CONFIG_PNP */
5938c2ecf20Sopenharmony_ci
5948c2ecf20Sopenharmony_cistatic void snd_interwave_free(struct snd_card *card)
5958c2ecf20Sopenharmony_ci{
5968c2ecf20Sopenharmony_ci	struct snd_interwave *iwcard = card->private_data;
5978c2ecf20Sopenharmony_ci
5988c2ecf20Sopenharmony_ci	if (iwcard == NULL)
5998c2ecf20Sopenharmony_ci		return;
6008c2ecf20Sopenharmony_ci#ifdef SNDRV_STB
6018c2ecf20Sopenharmony_ci	release_and_free_resource(iwcard->i2c_res);
6028c2ecf20Sopenharmony_ci#endif
6038c2ecf20Sopenharmony_ci	if (iwcard->irq >= 0)
6048c2ecf20Sopenharmony_ci		free_irq(iwcard->irq, (void *)iwcard);
6058c2ecf20Sopenharmony_ci}
6068c2ecf20Sopenharmony_ci
6078c2ecf20Sopenharmony_cistatic int snd_interwave_card_new(struct device *pdev, int dev,
6088c2ecf20Sopenharmony_ci				  struct snd_card **cardp)
6098c2ecf20Sopenharmony_ci{
6108c2ecf20Sopenharmony_ci	struct snd_card *card;
6118c2ecf20Sopenharmony_ci	struct snd_interwave *iwcard;
6128c2ecf20Sopenharmony_ci	int err;
6138c2ecf20Sopenharmony_ci
6148c2ecf20Sopenharmony_ci	err = snd_card_new(pdev, index[dev], id[dev], THIS_MODULE,
6158c2ecf20Sopenharmony_ci			   sizeof(struct snd_interwave), &card);
6168c2ecf20Sopenharmony_ci	if (err < 0)
6178c2ecf20Sopenharmony_ci		return err;
6188c2ecf20Sopenharmony_ci	iwcard = card->private_data;
6198c2ecf20Sopenharmony_ci	iwcard->card = card;
6208c2ecf20Sopenharmony_ci	iwcard->irq = -1;
6218c2ecf20Sopenharmony_ci	card->private_free = snd_interwave_free;
6228c2ecf20Sopenharmony_ci	*cardp = card;
6238c2ecf20Sopenharmony_ci	return 0;
6248c2ecf20Sopenharmony_ci}
6258c2ecf20Sopenharmony_ci
6268c2ecf20Sopenharmony_cistatic int snd_interwave_probe(struct snd_card *card, int dev)
6278c2ecf20Sopenharmony_ci{
6288c2ecf20Sopenharmony_ci	int xirq, xdma1, xdma2;
6298c2ecf20Sopenharmony_ci	struct snd_interwave *iwcard = card->private_data;
6308c2ecf20Sopenharmony_ci	struct snd_wss *wss;
6318c2ecf20Sopenharmony_ci	struct snd_gus_card *gus;
6328c2ecf20Sopenharmony_ci#ifdef SNDRV_STB
6338c2ecf20Sopenharmony_ci	struct snd_i2c_bus *i2c_bus;
6348c2ecf20Sopenharmony_ci#endif
6358c2ecf20Sopenharmony_ci	char *str;
6368c2ecf20Sopenharmony_ci	int err;
6378c2ecf20Sopenharmony_ci
6388c2ecf20Sopenharmony_ci	xirq = irq[dev];
6398c2ecf20Sopenharmony_ci	xdma1 = dma1[dev];
6408c2ecf20Sopenharmony_ci	xdma2 = dma2[dev];
6418c2ecf20Sopenharmony_ci
6428c2ecf20Sopenharmony_ci	if ((err = snd_gus_create(card,
6438c2ecf20Sopenharmony_ci				  port[dev],
6448c2ecf20Sopenharmony_ci				  -xirq, xdma1, xdma2,
6458c2ecf20Sopenharmony_ci				  0, 32,
6468c2ecf20Sopenharmony_ci				  pcm_channels[dev], effect[dev], &gus)) < 0)
6478c2ecf20Sopenharmony_ci		return err;
6488c2ecf20Sopenharmony_ci
6498c2ecf20Sopenharmony_ci	if ((err = snd_interwave_detect(iwcard, gus, dev
6508c2ecf20Sopenharmony_ci#ifdef SNDRV_STB
6518c2ecf20Sopenharmony_ci            , &i2c_bus
6528c2ecf20Sopenharmony_ci#endif
6538c2ecf20Sopenharmony_ci	    )) < 0)
6548c2ecf20Sopenharmony_ci		return err;
6558c2ecf20Sopenharmony_ci
6568c2ecf20Sopenharmony_ci	iwcard->gus_status_reg = gus->gf1.reg_irqstat;
6578c2ecf20Sopenharmony_ci	iwcard->pcm_status_reg = gus->gf1.port + 0x10c + 2;
6588c2ecf20Sopenharmony_ci
6598c2ecf20Sopenharmony_ci	snd_interwave_init(dev, gus);
6608c2ecf20Sopenharmony_ci	snd_interwave_detect_memory(gus);
6618c2ecf20Sopenharmony_ci	if ((err = snd_gus_initialize(gus)) < 0)
6628c2ecf20Sopenharmony_ci		return err;
6638c2ecf20Sopenharmony_ci
6648c2ecf20Sopenharmony_ci	if (request_irq(xirq, snd_interwave_interrupt, 0,
6658c2ecf20Sopenharmony_ci			"InterWave", iwcard)) {
6668c2ecf20Sopenharmony_ci		snd_printk(KERN_ERR PFX "unable to grab IRQ %d\n", xirq);
6678c2ecf20Sopenharmony_ci		return -EBUSY;
6688c2ecf20Sopenharmony_ci	}
6698c2ecf20Sopenharmony_ci	iwcard->irq = xirq;
6708c2ecf20Sopenharmony_ci	card->sync_irq = iwcard->irq;
6718c2ecf20Sopenharmony_ci
6728c2ecf20Sopenharmony_ci	err = snd_wss_create(card,
6738c2ecf20Sopenharmony_ci			     gus->gf1.port + 0x10c, -1, xirq,
6748c2ecf20Sopenharmony_ci			     xdma2 < 0 ? xdma1 : xdma2, xdma1,
6758c2ecf20Sopenharmony_ci			     WSS_HW_INTERWAVE,
6768c2ecf20Sopenharmony_ci			     WSS_HWSHARE_IRQ |
6778c2ecf20Sopenharmony_ci			     WSS_HWSHARE_DMA1 |
6788c2ecf20Sopenharmony_ci			     WSS_HWSHARE_DMA2,
6798c2ecf20Sopenharmony_ci			     &wss);
6808c2ecf20Sopenharmony_ci	if (err < 0)
6818c2ecf20Sopenharmony_ci		return err;
6828c2ecf20Sopenharmony_ci
6838c2ecf20Sopenharmony_ci	err = snd_wss_pcm(wss, 0);
6848c2ecf20Sopenharmony_ci	if (err < 0)
6858c2ecf20Sopenharmony_ci		return err;
6868c2ecf20Sopenharmony_ci
6878c2ecf20Sopenharmony_ci	sprintf(wss->pcm->name + strlen(wss->pcm->name), " rev %c",
6888c2ecf20Sopenharmony_ci		gus->revision + 'A');
6898c2ecf20Sopenharmony_ci	strcat(wss->pcm->name, " (codec)");
6908c2ecf20Sopenharmony_ci
6918c2ecf20Sopenharmony_ci	err = snd_wss_timer(wss, 2);
6928c2ecf20Sopenharmony_ci	if (err < 0)
6938c2ecf20Sopenharmony_ci		return err;
6948c2ecf20Sopenharmony_ci
6958c2ecf20Sopenharmony_ci	err = snd_wss_mixer(wss);
6968c2ecf20Sopenharmony_ci	if (err < 0)
6978c2ecf20Sopenharmony_ci		return err;
6988c2ecf20Sopenharmony_ci
6998c2ecf20Sopenharmony_ci	if (pcm_channels[dev] > 0) {
7008c2ecf20Sopenharmony_ci		err = snd_gf1_pcm_new(gus, 1, 1);
7018c2ecf20Sopenharmony_ci		if (err < 0)
7028c2ecf20Sopenharmony_ci			return err;
7038c2ecf20Sopenharmony_ci	}
7048c2ecf20Sopenharmony_ci	err = snd_interwave_mixer(wss);
7058c2ecf20Sopenharmony_ci	if (err < 0)
7068c2ecf20Sopenharmony_ci		return err;
7078c2ecf20Sopenharmony_ci
7088c2ecf20Sopenharmony_ci#ifdef SNDRV_STB
7098c2ecf20Sopenharmony_ci	{
7108c2ecf20Sopenharmony_ci		struct snd_ctl_elem_id id1, id2;
7118c2ecf20Sopenharmony_ci		memset(&id1, 0, sizeof(id1));
7128c2ecf20Sopenharmony_ci		memset(&id2, 0, sizeof(id2));
7138c2ecf20Sopenharmony_ci		id1.iface = id2.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
7148c2ecf20Sopenharmony_ci		strcpy(id1.name, "Master Playback Switch");
7158c2ecf20Sopenharmony_ci		strcpy(id2.name, id1.name);
7168c2ecf20Sopenharmony_ci		id2.index = 1;
7178c2ecf20Sopenharmony_ci		if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
7188c2ecf20Sopenharmony_ci			return err;
7198c2ecf20Sopenharmony_ci		strcpy(id1.name, "Master Playback Volume");
7208c2ecf20Sopenharmony_ci		strcpy(id2.name, id1.name);
7218c2ecf20Sopenharmony_ci		if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
7228c2ecf20Sopenharmony_ci			return err;
7238c2ecf20Sopenharmony_ci		if ((err = snd_tea6330t_update_mixer(card, i2c_bus, 0, 1)) < 0)
7248c2ecf20Sopenharmony_ci			return err;
7258c2ecf20Sopenharmony_ci	}
7268c2ecf20Sopenharmony_ci#endif
7278c2ecf20Sopenharmony_ci
7288c2ecf20Sopenharmony_ci	gus->uart_enable = midi[dev];
7298c2ecf20Sopenharmony_ci	if ((err = snd_gf1_rawmidi_new(gus, 0)) < 0)
7308c2ecf20Sopenharmony_ci		return err;
7318c2ecf20Sopenharmony_ci
7328c2ecf20Sopenharmony_ci#ifndef SNDRV_STB
7338c2ecf20Sopenharmony_ci	str = "AMD InterWave";
7348c2ecf20Sopenharmony_ci	if (gus->gf1.rom_banks == 1 && gus->gf1.rom_present == 8)
7358c2ecf20Sopenharmony_ci		str = "Dynasonic 3-D";
7368c2ecf20Sopenharmony_ci#else
7378c2ecf20Sopenharmony_ci	str = "InterWave STB";
7388c2ecf20Sopenharmony_ci#endif
7398c2ecf20Sopenharmony_ci	strcpy(card->driver, str);
7408c2ecf20Sopenharmony_ci	strcpy(card->shortname, str);
7418c2ecf20Sopenharmony_ci	sprintf(card->longname, "%s at 0x%lx, irq %i, dma %d",
7428c2ecf20Sopenharmony_ci		str,
7438c2ecf20Sopenharmony_ci		gus->gf1.port,
7448c2ecf20Sopenharmony_ci		xirq,
7458c2ecf20Sopenharmony_ci		xdma1);
7468c2ecf20Sopenharmony_ci	if (xdma2 >= 0)
7478c2ecf20Sopenharmony_ci		sprintf(card->longname + strlen(card->longname), "&%d", xdma2);
7488c2ecf20Sopenharmony_ci
7498c2ecf20Sopenharmony_ci	err = snd_card_register(card);
7508c2ecf20Sopenharmony_ci	if (err < 0)
7518c2ecf20Sopenharmony_ci		return err;
7528c2ecf20Sopenharmony_ci
7538c2ecf20Sopenharmony_ci	iwcard->wss = wss;
7548c2ecf20Sopenharmony_ci	iwcard->gus = gus;
7558c2ecf20Sopenharmony_ci	return 0;
7568c2ecf20Sopenharmony_ci}
7578c2ecf20Sopenharmony_ci
7588c2ecf20Sopenharmony_cistatic int snd_interwave_isa_probe1(int dev, struct device *devptr)
7598c2ecf20Sopenharmony_ci{
7608c2ecf20Sopenharmony_ci	struct snd_card *card;
7618c2ecf20Sopenharmony_ci	int err;
7628c2ecf20Sopenharmony_ci
7638c2ecf20Sopenharmony_ci	err = snd_interwave_card_new(devptr, dev, &card);
7648c2ecf20Sopenharmony_ci	if (err < 0)
7658c2ecf20Sopenharmony_ci		return err;
7668c2ecf20Sopenharmony_ci
7678c2ecf20Sopenharmony_ci	if ((err = snd_interwave_probe(card, dev)) < 0) {
7688c2ecf20Sopenharmony_ci		snd_card_free(card);
7698c2ecf20Sopenharmony_ci		return err;
7708c2ecf20Sopenharmony_ci	}
7718c2ecf20Sopenharmony_ci	dev_set_drvdata(devptr, card);
7728c2ecf20Sopenharmony_ci	return 0;
7738c2ecf20Sopenharmony_ci}
7748c2ecf20Sopenharmony_ci
7758c2ecf20Sopenharmony_cistatic int snd_interwave_isa_match(struct device *pdev,
7768c2ecf20Sopenharmony_ci				   unsigned int dev)
7778c2ecf20Sopenharmony_ci{
7788c2ecf20Sopenharmony_ci	if (!enable[dev])
7798c2ecf20Sopenharmony_ci		return 0;
7808c2ecf20Sopenharmony_ci#ifdef CONFIG_PNP
7818c2ecf20Sopenharmony_ci	if (isapnp[dev])
7828c2ecf20Sopenharmony_ci		return 0;
7838c2ecf20Sopenharmony_ci#endif
7848c2ecf20Sopenharmony_ci	return 1;
7858c2ecf20Sopenharmony_ci}
7868c2ecf20Sopenharmony_ci
7878c2ecf20Sopenharmony_cistatic int snd_interwave_isa_probe(struct device *pdev,
7888c2ecf20Sopenharmony_ci				   unsigned int dev)
7898c2ecf20Sopenharmony_ci{
7908c2ecf20Sopenharmony_ci	int err;
7918c2ecf20Sopenharmony_ci	static const int possible_irqs[] = {5, 11, 12, 9, 7, 15, 3, -1};
7928c2ecf20Sopenharmony_ci	static const int possible_dmas[] = {0, 1, 3, 5, 6, 7, -1};
7938c2ecf20Sopenharmony_ci
7948c2ecf20Sopenharmony_ci	if (irq[dev] == SNDRV_AUTO_IRQ) {
7958c2ecf20Sopenharmony_ci		if ((irq[dev] = snd_legacy_find_free_irq(possible_irqs)) < 0) {
7968c2ecf20Sopenharmony_ci			snd_printk(KERN_ERR PFX "unable to find a free IRQ\n");
7978c2ecf20Sopenharmony_ci			return -EBUSY;
7988c2ecf20Sopenharmony_ci		}
7998c2ecf20Sopenharmony_ci	}
8008c2ecf20Sopenharmony_ci	if (dma1[dev] == SNDRV_AUTO_DMA) {
8018c2ecf20Sopenharmony_ci		if ((dma1[dev] = snd_legacy_find_free_dma(possible_dmas)) < 0) {
8028c2ecf20Sopenharmony_ci			snd_printk(KERN_ERR PFX "unable to find a free DMA1\n");
8038c2ecf20Sopenharmony_ci			return -EBUSY;
8048c2ecf20Sopenharmony_ci		}
8058c2ecf20Sopenharmony_ci	}
8068c2ecf20Sopenharmony_ci	if (dma2[dev] == SNDRV_AUTO_DMA) {
8078c2ecf20Sopenharmony_ci		if ((dma2[dev] = snd_legacy_find_free_dma(possible_dmas)) < 0) {
8088c2ecf20Sopenharmony_ci			snd_printk(KERN_ERR PFX "unable to find a free DMA2\n");
8098c2ecf20Sopenharmony_ci			return -EBUSY;
8108c2ecf20Sopenharmony_ci		}
8118c2ecf20Sopenharmony_ci	}
8128c2ecf20Sopenharmony_ci
8138c2ecf20Sopenharmony_ci	if (port[dev] != SNDRV_AUTO_PORT)
8148c2ecf20Sopenharmony_ci		return snd_interwave_isa_probe1(dev, pdev);
8158c2ecf20Sopenharmony_ci	else {
8168c2ecf20Sopenharmony_ci		static const long possible_ports[] = {0x210, 0x220, 0x230, 0x240, 0x250, 0x260};
8178c2ecf20Sopenharmony_ci		int i;
8188c2ecf20Sopenharmony_ci		for (i = 0; i < ARRAY_SIZE(possible_ports); i++) {
8198c2ecf20Sopenharmony_ci			port[dev] = possible_ports[i];
8208c2ecf20Sopenharmony_ci			err = snd_interwave_isa_probe1(dev, pdev);
8218c2ecf20Sopenharmony_ci			if (! err)
8228c2ecf20Sopenharmony_ci				return 0;
8238c2ecf20Sopenharmony_ci		}
8248c2ecf20Sopenharmony_ci		return err;
8258c2ecf20Sopenharmony_ci	}
8268c2ecf20Sopenharmony_ci}
8278c2ecf20Sopenharmony_ci
8288c2ecf20Sopenharmony_cistatic int snd_interwave_isa_remove(struct device *devptr, unsigned int dev)
8298c2ecf20Sopenharmony_ci{
8308c2ecf20Sopenharmony_ci	snd_card_free(dev_get_drvdata(devptr));
8318c2ecf20Sopenharmony_ci	return 0;
8328c2ecf20Sopenharmony_ci}
8338c2ecf20Sopenharmony_ci
8348c2ecf20Sopenharmony_cistatic struct isa_driver snd_interwave_driver = {
8358c2ecf20Sopenharmony_ci	.match		= snd_interwave_isa_match,
8368c2ecf20Sopenharmony_ci	.probe		= snd_interwave_isa_probe,
8378c2ecf20Sopenharmony_ci	.remove		= snd_interwave_isa_remove,
8388c2ecf20Sopenharmony_ci	/* FIXME: suspend,resume */
8398c2ecf20Sopenharmony_ci	.driver		= {
8408c2ecf20Sopenharmony_ci		.name	= INTERWAVE_DRIVER
8418c2ecf20Sopenharmony_ci	},
8428c2ecf20Sopenharmony_ci};
8438c2ecf20Sopenharmony_ci
8448c2ecf20Sopenharmony_ci#ifdef CONFIG_PNP
8458c2ecf20Sopenharmony_cistatic int snd_interwave_pnp_detect(struct pnp_card_link *pcard,
8468c2ecf20Sopenharmony_ci				    const struct pnp_card_device_id *pid)
8478c2ecf20Sopenharmony_ci{
8488c2ecf20Sopenharmony_ci	static int dev;
8498c2ecf20Sopenharmony_ci	struct snd_card *card;
8508c2ecf20Sopenharmony_ci	int res;
8518c2ecf20Sopenharmony_ci
8528c2ecf20Sopenharmony_ci	for ( ; dev < SNDRV_CARDS; dev++) {
8538c2ecf20Sopenharmony_ci		if (enable[dev] && isapnp[dev])
8548c2ecf20Sopenharmony_ci			break;
8558c2ecf20Sopenharmony_ci	}
8568c2ecf20Sopenharmony_ci	if (dev >= SNDRV_CARDS)
8578c2ecf20Sopenharmony_ci		return -ENODEV;
8588c2ecf20Sopenharmony_ci
8598c2ecf20Sopenharmony_ci	res = snd_interwave_card_new(&pcard->card->dev, dev, &card);
8608c2ecf20Sopenharmony_ci	if (res < 0)
8618c2ecf20Sopenharmony_ci		return res;
8628c2ecf20Sopenharmony_ci
8638c2ecf20Sopenharmony_ci	if ((res = snd_interwave_pnp(dev, card->private_data, pcard, pid)) < 0) {
8648c2ecf20Sopenharmony_ci		snd_card_free(card);
8658c2ecf20Sopenharmony_ci		return res;
8668c2ecf20Sopenharmony_ci	}
8678c2ecf20Sopenharmony_ci	if ((res = snd_interwave_probe(card, dev)) < 0) {
8688c2ecf20Sopenharmony_ci		snd_card_free(card);
8698c2ecf20Sopenharmony_ci		return res;
8708c2ecf20Sopenharmony_ci	}
8718c2ecf20Sopenharmony_ci	pnp_set_card_drvdata(pcard, card);
8728c2ecf20Sopenharmony_ci	dev++;
8738c2ecf20Sopenharmony_ci	return 0;
8748c2ecf20Sopenharmony_ci}
8758c2ecf20Sopenharmony_ci
8768c2ecf20Sopenharmony_cistatic void snd_interwave_pnp_remove(struct pnp_card_link *pcard)
8778c2ecf20Sopenharmony_ci{
8788c2ecf20Sopenharmony_ci	snd_card_free(pnp_get_card_drvdata(pcard));
8798c2ecf20Sopenharmony_ci	pnp_set_card_drvdata(pcard, NULL);
8808c2ecf20Sopenharmony_ci}
8818c2ecf20Sopenharmony_ci
8828c2ecf20Sopenharmony_cistatic struct pnp_card_driver interwave_pnpc_driver = {
8838c2ecf20Sopenharmony_ci	.flags = PNP_DRIVER_RES_DISABLE,
8848c2ecf20Sopenharmony_ci	.name = INTERWAVE_PNP_DRIVER,
8858c2ecf20Sopenharmony_ci	.id_table = snd_interwave_pnpids,
8868c2ecf20Sopenharmony_ci	.probe = snd_interwave_pnp_detect,
8878c2ecf20Sopenharmony_ci	.remove = snd_interwave_pnp_remove,
8888c2ecf20Sopenharmony_ci	/* FIXME: suspend,resume */
8898c2ecf20Sopenharmony_ci};
8908c2ecf20Sopenharmony_ci
8918c2ecf20Sopenharmony_ci#endif /* CONFIG_PNP */
8928c2ecf20Sopenharmony_ci
8938c2ecf20Sopenharmony_cistatic int __init alsa_card_interwave_init(void)
8948c2ecf20Sopenharmony_ci{
8958c2ecf20Sopenharmony_ci	int err;
8968c2ecf20Sopenharmony_ci
8978c2ecf20Sopenharmony_ci	err = isa_register_driver(&snd_interwave_driver, SNDRV_CARDS);
8988c2ecf20Sopenharmony_ci#ifdef CONFIG_PNP
8998c2ecf20Sopenharmony_ci	if (!err)
9008c2ecf20Sopenharmony_ci		isa_registered = 1;
9018c2ecf20Sopenharmony_ci
9028c2ecf20Sopenharmony_ci	err = pnp_register_card_driver(&interwave_pnpc_driver);
9038c2ecf20Sopenharmony_ci	if (!err)
9048c2ecf20Sopenharmony_ci		pnp_registered = 1;
9058c2ecf20Sopenharmony_ci
9068c2ecf20Sopenharmony_ci	if (isa_registered)
9078c2ecf20Sopenharmony_ci		err = 0;
9088c2ecf20Sopenharmony_ci#endif
9098c2ecf20Sopenharmony_ci	return err;
9108c2ecf20Sopenharmony_ci}
9118c2ecf20Sopenharmony_ci
9128c2ecf20Sopenharmony_cistatic void __exit alsa_card_interwave_exit(void)
9138c2ecf20Sopenharmony_ci{
9148c2ecf20Sopenharmony_ci#ifdef CONFIG_PNP
9158c2ecf20Sopenharmony_ci	if (pnp_registered)
9168c2ecf20Sopenharmony_ci		pnp_unregister_card_driver(&interwave_pnpc_driver);
9178c2ecf20Sopenharmony_ci	if (isa_registered)
9188c2ecf20Sopenharmony_ci#endif
9198c2ecf20Sopenharmony_ci		isa_unregister_driver(&snd_interwave_driver);
9208c2ecf20Sopenharmony_ci}
9218c2ecf20Sopenharmony_ci
9228c2ecf20Sopenharmony_cimodule_init(alsa_card_interwave_init)
9238c2ecf20Sopenharmony_cimodule_exit(alsa_card_interwave_exit)
924