Linux Audio

Check our new training course

Loading...
v5.9
   1// SPDX-License-Identifier: GPL-2.0-or-later
   2/*********************************************************************
   3 *
   4 * Linux multisound pinnacle/fiji driver for ALSA.
   5 *
   6 * 2002/06/30 Karsten Wiese:
   7 *	for now this is only used to build a pinnacle / fiji driver.
   8 *	the OSS parent of this code is designed to also support
   9 *	the multisound classic via the file msnd_classic.c.
  10 *	to make it easier for some brave heart to implemt classic
  11 *	support in alsa, i left all the MSND_CLASSIC tokens in this file.
  12 *	but for now this untested & undone.
  13 *
 
  14 * ripped from linux kernel 2.4.18 by Karsten Wiese.
  15 *
  16 * the following is a copy of the 2.4.18 OSS FREE file-heading comment:
  17 *
  18 * Turtle Beach MultiSound Sound Card Driver for Linux
  19 * msnd_pinnacle.c / msnd_classic.c
  20 *
  21 * -- If MSND_CLASSIC is defined:
  22 *
  23 *     -> driver for Turtle Beach Classic/Monterey/Tahiti
  24 *
  25 * -- Else
  26 *
  27 *     -> driver for Turtle Beach Pinnacle/Fiji
  28 *
  29 * 12-3-2000  Modified IO port validation  Steve Sycamore
  30 *
  31 * Copyright (C) 1998 Andrew Veliath
  32 *
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  33 ********************************************************************/
  34
  35#include <linux/kernel.h>
  36#include <linux/module.h>
  37#include <linux/interrupt.h>
  38#include <linux/types.h>
  39#include <linux/delay.h>
  40#include <linux/ioport.h>
  41#include <linux/firmware.h>
  42#include <linux/isa.h>
  43#include <linux/isapnp.h>
  44#include <linux/irq.h>
  45#include <linux/io.h>
  46
  47#include <sound/core.h>
  48#include <sound/initval.h>
  49#include <sound/asound.h>
  50#include <sound/pcm.h>
  51#include <sound/mpu401.h>
  52
  53#ifdef MSND_CLASSIC
  54# ifndef __alpha__
  55#  define SLOWIO
  56# endif
  57#endif
  58#include "msnd.h"
  59#ifdef MSND_CLASSIC
  60#  include "msnd_classic.h"
  61#  define LOGNAME			"msnd_classic"
  62#  define DEV_NAME			"msnd-classic"
  63#else
  64#  include "msnd_pinnacle.h"
  65#  define LOGNAME			"snd_msnd_pinnacle"
  66#  define DEV_NAME			"msnd-pinnacle"
  67#endif
  68
  69static void set_default_audio_parameters(struct snd_msnd *chip)
  70{
  71	chip->play_sample_size = snd_pcm_format_width(DEFSAMPLESIZE);
  72	chip->play_sample_rate = DEFSAMPLERATE;
  73	chip->play_channels = DEFCHANNELS;
  74	chip->capture_sample_size = snd_pcm_format_width(DEFSAMPLESIZE);
  75	chip->capture_sample_rate = DEFSAMPLERATE;
  76	chip->capture_channels = DEFCHANNELS;
  77}
  78
  79static void snd_msnd_eval_dsp_msg(struct snd_msnd *chip, u16 wMessage)
  80{
  81	switch (HIBYTE(wMessage)) {
  82	case HIMT_PLAY_DONE: {
  83		if (chip->banksPlayed < 3)
  84			snd_printdd("%08X: HIMT_PLAY_DONE: %i\n",
  85				(unsigned)jiffies, LOBYTE(wMessage));
  86
  87		if (chip->last_playbank == LOBYTE(wMessage)) {
  88			snd_printdd("chip.last_playbank == LOBYTE(wMessage)\n");
  89			break;
  90		}
  91		chip->banksPlayed++;
  92
  93		if (test_bit(F_WRITING, &chip->flags))
  94			snd_msnd_DAPQ(chip, 0);
  95
  96		chip->last_playbank = LOBYTE(wMessage);
  97		chip->playDMAPos += chip->play_period_bytes;
  98		if (chip->playDMAPos > chip->playLimit)
  99			chip->playDMAPos = 0;
 100		snd_pcm_period_elapsed(chip->playback_substream);
 101
 102		break;
 103	}
 104	case HIMT_RECORD_DONE:
 105		if (chip->last_recbank == LOBYTE(wMessage))
 106			break;
 107		chip->last_recbank = LOBYTE(wMessage);
 108		chip->captureDMAPos += chip->capturePeriodBytes;
 109		if (chip->captureDMAPos > (chip->captureLimit))
 110			chip->captureDMAPos = 0;
 111
 112		if (test_bit(F_READING, &chip->flags))
 113			snd_msnd_DARQ(chip, chip->last_recbank);
 114
 115		snd_pcm_period_elapsed(chip->capture_substream);
 116		break;
 117
 118	case HIMT_DSP:
 119		switch (LOBYTE(wMessage)) {
 120#ifndef MSND_CLASSIC
 121		case HIDSP_PLAY_UNDER:
 122#endif
 123		case HIDSP_INT_PLAY_UNDER:
 124			snd_printd(KERN_WARNING LOGNAME ": Play underflow %i\n",
 125				chip->banksPlayed);
 126			if (chip->banksPlayed > 2)
 127				clear_bit(F_WRITING, &chip->flags);
 128			break;
 129
 130		case HIDSP_INT_RECORD_OVER:
 131			snd_printd(KERN_WARNING LOGNAME ": Record overflow\n");
 132			clear_bit(F_READING, &chip->flags);
 133			break;
 134
 135		default:
 136			snd_printd(KERN_WARNING LOGNAME
 137				   ": DSP message %d 0x%02x\n",
 138				   LOBYTE(wMessage), LOBYTE(wMessage));
 139			break;
 140		}
 141		break;
 142
 143	case HIMT_MIDI_IN_UCHAR:
 144		if (chip->msndmidi_mpu)
 145			snd_msndmidi_input_read(chip->msndmidi_mpu);
 146		break;
 147
 148	default:
 149		snd_printd(KERN_WARNING LOGNAME ": HIMT message %d 0x%02x\n",
 150			   HIBYTE(wMessage), HIBYTE(wMessage));
 151		break;
 152	}
 153}
 154
 155static irqreturn_t snd_msnd_interrupt(int irq, void *dev_id)
 156{
 157	struct snd_msnd *chip = dev_id;
 158	void __iomem *pwDSPQData = chip->mappedbase + DSPQ_DATA_BUFF;
 159	u16 head, tail, size;
 160
 161	/* Send ack to DSP */
 162	/* inb(chip->io + HP_RXL); */
 163
 164	/* Evaluate queued DSP messages */
 165	head = readw(chip->DSPQ + JQS_wHead);
 166	tail = readw(chip->DSPQ + JQS_wTail);
 167	size = readw(chip->DSPQ + JQS_wSize);
 168	if (head > size || tail > size)
 169		goto out;
 170	while (head != tail) {
 171		snd_msnd_eval_dsp_msg(chip, readw(pwDSPQData + 2 * head));
 172		if (++head > size)
 173			head = 0;
 174		writew(head, chip->DSPQ + JQS_wHead);
 
 175	}
 176 out:
 177	/* Send ack to DSP */
 178	inb(chip->io + HP_RXL);
 179	return IRQ_HANDLED;
 180}
 181
 182
 183static int snd_msnd_reset_dsp(long io, unsigned char *info)
 184{
 185	int timeout = 100;
 186
 187	outb(HPDSPRESET_ON, io + HP_DSPR);
 188	msleep(1);
 189#ifndef MSND_CLASSIC
 190	if (info)
 191		*info = inb(io + HP_INFO);
 192#endif
 193	outb(HPDSPRESET_OFF, io + HP_DSPR);
 194	msleep(1);
 195	while (timeout-- > 0) {
 196		if (inb(io + HP_CVR) == HP_CVR_DEF)
 197			return 0;
 198		msleep(1);
 199	}
 200	snd_printk(KERN_ERR LOGNAME ": Cannot reset DSP\n");
 201
 202	return -EIO;
 203}
 204
 205static int snd_msnd_probe(struct snd_card *card)
 206{
 207	struct snd_msnd *chip = card->private_data;
 208	unsigned char info;
 209#ifndef MSND_CLASSIC
 210	char *xv, *rev = NULL;
 211	char *pin = "TB Pinnacle", *fiji = "TB Fiji";
 212	char *pinfiji = "TB Pinnacle/Fiji";
 213#endif
 214
 215	if (!request_region(chip->io, DSP_NUMIO, "probing")) {
 216		snd_printk(KERN_ERR LOGNAME ": I/O port conflict\n");
 217		return -ENODEV;
 218	}
 219
 220	if (snd_msnd_reset_dsp(chip->io, &info) < 0) {
 221		release_region(chip->io, DSP_NUMIO);
 222		return -ENODEV;
 223	}
 224
 225#ifdef MSND_CLASSIC
 226	strcpy(card->shortname, "Classic/Tahiti/Monterey");
 227	strcpy(card->longname, "Turtle Beach Multisound");
 228	printk(KERN_INFO LOGNAME ": %s, "
 229	       "I/O 0x%lx-0x%lx, IRQ %d, memory mapped to 0x%lX-0x%lX\n",
 230	       card->shortname,
 231	       chip->io, chip->io + DSP_NUMIO - 1,
 232	       chip->irq,
 233	       chip->base, chip->base + 0x7fff);
 234#else
 235	switch (info >> 4) {
 236	case 0xf:
 237		xv = "<= 1.15";
 238		break;
 239	case 0x1:
 240		xv = "1.18/1.2";
 241		break;
 242	case 0x2:
 243		xv = "1.3";
 244		break;
 245	case 0x3:
 246		xv = "1.4";
 247		break;
 248	default:
 249		xv = "unknown";
 250		break;
 251	}
 252
 253	switch (info & 0x7) {
 254	case 0x0:
 255		rev = "I";
 256		strcpy(card->shortname, pin);
 257		break;
 258	case 0x1:
 259		rev = "F";
 260		strcpy(card->shortname, pin);
 261		break;
 262	case 0x2:
 263		rev = "G";
 264		strcpy(card->shortname, pin);
 265		break;
 266	case 0x3:
 267		rev = "H";
 268		strcpy(card->shortname, pin);
 269		break;
 270	case 0x4:
 271		rev = "E";
 272		strcpy(card->shortname, fiji);
 273		break;
 274	case 0x5:
 275		rev = "C";
 276		strcpy(card->shortname, fiji);
 277		break;
 278	case 0x6:
 279		rev = "D";
 280		strcpy(card->shortname, fiji);
 281		break;
 282	case 0x7:
 283		rev = "A-B (Fiji) or A-E (Pinnacle)";
 284		strcpy(card->shortname, pinfiji);
 285		break;
 286	}
 287	strcpy(card->longname, "Turtle Beach Multisound Pinnacle");
 288	printk(KERN_INFO LOGNAME ": %s revision %s, Xilinx version %s, "
 289	       "I/O 0x%lx-0x%lx, IRQ %d, memory mapped to 0x%lX-0x%lX\n",
 290	       card->shortname,
 291	       rev, xv,
 292	       chip->io, chip->io + DSP_NUMIO - 1,
 293	       chip->irq,
 294	       chip->base, chip->base + 0x7fff);
 295#endif
 296
 297	release_region(chip->io, DSP_NUMIO);
 298	return 0;
 299}
 300
 301static int snd_msnd_init_sma(struct snd_msnd *chip)
 302{
 303	static int initted;
 304	u16 mastVolLeft, mastVolRight;
 305	unsigned long flags;
 306
 307#ifdef MSND_CLASSIC
 308	outb(chip->memid, chip->io + HP_MEMM);
 309#endif
 310	outb(HPBLKSEL_0, chip->io + HP_BLKS);
 311	/* Motorola 56k shared memory base */
 312	chip->SMA = chip->mappedbase + SMA_STRUCT_START;
 313
 314	if (initted) {
 315		mastVolLeft = readw(chip->SMA + SMA_wCurrMastVolLeft);
 316		mastVolRight = readw(chip->SMA + SMA_wCurrMastVolRight);
 317	} else
 318		mastVolLeft = mastVolRight = 0;
 319	memset_io(chip->mappedbase, 0, 0x8000);
 320
 321	/* Critical section: bank 1 access */
 322	spin_lock_irqsave(&chip->lock, flags);
 323	outb(HPBLKSEL_1, chip->io + HP_BLKS);
 324	memset_io(chip->mappedbase, 0, 0x8000);
 325	outb(HPBLKSEL_0, chip->io + HP_BLKS);
 326	spin_unlock_irqrestore(&chip->lock, flags);
 327
 328	/* Digital audio play queue */
 329	chip->DAPQ = chip->mappedbase + DAPQ_OFFSET;
 330	snd_msnd_init_queue(chip->DAPQ, DAPQ_DATA_BUFF, DAPQ_BUFF_SIZE);
 331
 332	/* Digital audio record queue */
 333	chip->DARQ = chip->mappedbase + DARQ_OFFSET;
 334	snd_msnd_init_queue(chip->DARQ, DARQ_DATA_BUFF, DARQ_BUFF_SIZE);
 335
 336	/* MIDI out queue */
 337	chip->MODQ = chip->mappedbase + MODQ_OFFSET;
 338	snd_msnd_init_queue(chip->MODQ, MODQ_DATA_BUFF, MODQ_BUFF_SIZE);
 339
 340	/* MIDI in queue */
 341	chip->MIDQ = chip->mappedbase + MIDQ_OFFSET;
 342	snd_msnd_init_queue(chip->MIDQ, MIDQ_DATA_BUFF, MIDQ_BUFF_SIZE);
 343
 344	/* DSP -> host message queue */
 345	chip->DSPQ = chip->mappedbase + DSPQ_OFFSET;
 346	snd_msnd_init_queue(chip->DSPQ, DSPQ_DATA_BUFF, DSPQ_BUFF_SIZE);
 347
 348	/* Setup some DSP values */
 349#ifndef MSND_CLASSIC
 350	writew(1, chip->SMA + SMA_wCurrPlayFormat);
 351	writew(chip->play_sample_size, chip->SMA + SMA_wCurrPlaySampleSize);
 352	writew(chip->play_channels, chip->SMA + SMA_wCurrPlayChannels);
 353	writew(chip->play_sample_rate, chip->SMA + SMA_wCurrPlaySampleRate);
 354#endif
 355	writew(chip->play_sample_rate, chip->SMA + SMA_wCalFreqAtoD);
 356	writew(mastVolLeft, chip->SMA + SMA_wCurrMastVolLeft);
 357	writew(mastVolRight, chip->SMA + SMA_wCurrMastVolRight);
 358#ifndef MSND_CLASSIC
 359	writel(0x00010000, chip->SMA + SMA_dwCurrPlayPitch);
 360	writel(0x00000001, chip->SMA + SMA_dwCurrPlayRate);
 361#endif
 362	writew(0x303, chip->SMA + SMA_wCurrInputTagBits);
 363
 364	initted = 1;
 365
 366	return 0;
 367}
 368
 369
 370static int upload_dsp_code(struct snd_card *card)
 371{
 372	struct snd_msnd *chip = card->private_data;
 373	const struct firmware *init_fw = NULL, *perm_fw = NULL;
 374	int err;
 375
 376	outb(HPBLKSEL_0, chip->io + HP_BLKS);
 377
 378	err = request_firmware(&init_fw, INITCODEFILE, card->dev);
 379	if (err < 0) {
 380		printk(KERN_ERR LOGNAME ": Error loading " INITCODEFILE);
 381		goto cleanup1;
 382	}
 383	err = request_firmware(&perm_fw, PERMCODEFILE, card->dev);
 384	if (err < 0) {
 385		printk(KERN_ERR LOGNAME ": Error loading " PERMCODEFILE);
 386		goto cleanup;
 387	}
 388
 389	memcpy_toio(chip->mappedbase, perm_fw->data, perm_fw->size);
 390	if (snd_msnd_upload_host(chip, init_fw->data, init_fw->size) < 0) {
 391		printk(KERN_WARNING LOGNAME ": Error uploading to DSP\n");
 392		err = -ENODEV;
 393		goto cleanup;
 394	}
 395	printk(KERN_INFO LOGNAME ": DSP firmware uploaded\n");
 396	err = 0;
 397
 398cleanup:
 399	release_firmware(perm_fw);
 400cleanup1:
 401	release_firmware(init_fw);
 402	return err;
 403}
 404
 405#ifdef MSND_CLASSIC
 406static void reset_proteus(struct snd_msnd *chip)
 407{
 408	outb(HPPRORESET_ON, chip->io + HP_PROR);
 409	msleep(TIME_PRO_RESET);
 410	outb(HPPRORESET_OFF, chip->io + HP_PROR);
 411	msleep(TIME_PRO_RESET_DONE);
 412}
 413#endif
 414
 415static int snd_msnd_initialize(struct snd_card *card)
 416{
 417	struct snd_msnd *chip = card->private_data;
 418	int err, timeout;
 419
 420#ifdef MSND_CLASSIC
 421	outb(HPWAITSTATE_0, chip->io + HP_WAIT);
 422	outb(HPBITMODE_16, chip->io + HP_BITM);
 423
 424	reset_proteus(chip);
 425#endif
 426	err = snd_msnd_init_sma(chip);
 427	if (err < 0) {
 428		printk(KERN_WARNING LOGNAME ": Cannot initialize SMA\n");
 429		return err;
 430	}
 431
 432	err = snd_msnd_reset_dsp(chip->io, NULL);
 433	if (err < 0)
 434		return err;
 435
 436	err = upload_dsp_code(card);
 437	if (err < 0) {
 438		printk(KERN_WARNING LOGNAME ": Cannot upload DSP code\n");
 439		return err;
 440	}
 441
 442	timeout = 200;
 443
 444	while (readw(chip->mappedbase)) {
 445		msleep(1);
 446		if (!timeout--) {
 447			snd_printd(KERN_ERR LOGNAME ": DSP reset timeout\n");
 448			return -EIO;
 449		}
 450	}
 451
 452	snd_msndmix_setup(chip);
 453	return 0;
 454}
 455
 456static int snd_msnd_dsp_full_reset(struct snd_card *card)
 457{
 458	struct snd_msnd *chip = card->private_data;
 459	int rv;
 460
 461	if (test_bit(F_RESETTING, &chip->flags) || ++chip->nresets > 10)
 462		return 0;
 463
 464	set_bit(F_RESETTING, &chip->flags);
 465	snd_msnd_dsp_halt(chip, NULL);	/* Unconditionally halt */
 466
 467	rv = snd_msnd_initialize(card);
 468	if (rv)
 469		printk(KERN_WARNING LOGNAME ": DSP reset failed\n");
 470	snd_msndmix_force_recsrc(chip, 0);
 471	clear_bit(F_RESETTING, &chip->flags);
 472	return rv;
 473}
 474
 475static int snd_msnd_dev_free(struct snd_device *device)
 476{
 477	snd_printdd("snd_msnd_chip_free()\n");
 478	return 0;
 479}
 480
 481static int snd_msnd_send_dsp_cmd_chk(struct snd_msnd *chip, u8 cmd)
 482{
 483	if (snd_msnd_send_dsp_cmd(chip, cmd) == 0)
 484		return 0;
 485	snd_msnd_dsp_full_reset(chip->card);
 486	return snd_msnd_send_dsp_cmd(chip, cmd);
 487}
 488
 489static int snd_msnd_calibrate_adc(struct snd_msnd *chip, u16 srate)
 490{
 491	snd_printdd("snd_msnd_calibrate_adc(%i)\n", srate);
 492	writew(srate, chip->SMA + SMA_wCalFreqAtoD);
 493	if (chip->calibrate_signal == 0)
 494		writew(readw(chip->SMA + SMA_wCurrHostStatusFlags)
 495		       | 0x0001, chip->SMA + SMA_wCurrHostStatusFlags);
 496	else
 497		writew(readw(chip->SMA + SMA_wCurrHostStatusFlags)
 498		       & ~0x0001, chip->SMA + SMA_wCurrHostStatusFlags);
 499	if (snd_msnd_send_word(chip, 0, 0, HDEXAR_CAL_A_TO_D) == 0 &&
 500	    snd_msnd_send_dsp_cmd_chk(chip, HDEX_AUX_REQ) == 0) {
 501		schedule_timeout_interruptible(msecs_to_jiffies(333));
 502		return 0;
 503	}
 504	printk(KERN_WARNING LOGNAME ": ADC calibration failed\n");
 505	return -EIO;
 506}
 507
 508/*
 509 * ALSA callback function, called when attempting to open the MIDI device.
 510 */
 511static int snd_msnd_mpu401_open(struct snd_mpu401 *mpu)
 512{
 513	snd_msnd_enable_irq(mpu->private_data);
 514	snd_msnd_send_dsp_cmd(mpu->private_data, HDEX_MIDI_IN_START);
 515	return 0;
 516}
 517
 518static void snd_msnd_mpu401_close(struct snd_mpu401 *mpu)
 519{
 520	snd_msnd_send_dsp_cmd(mpu->private_data, HDEX_MIDI_IN_STOP);
 521	snd_msnd_disable_irq(mpu->private_data);
 522}
 523
 524static long mpu_io[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
 525static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
 526
 527static int snd_msnd_attach(struct snd_card *card)
 528{
 529	struct snd_msnd *chip = card->private_data;
 530	int err;
 531	static const struct snd_device_ops ops = {
 532		.dev_free =      snd_msnd_dev_free,
 533		};
 534
 535	err = request_irq(chip->irq, snd_msnd_interrupt, 0, card->shortname,
 536			  chip);
 537	if (err < 0) {
 538		printk(KERN_ERR LOGNAME ": Couldn't grab IRQ %d\n", chip->irq);
 539		return err;
 540	}
 541	card->sync_irq = chip->irq;
 542	if (request_region(chip->io, DSP_NUMIO, card->shortname) == NULL) {
 543		free_irq(chip->irq, chip);
 544		return -EBUSY;
 545	}
 546
 547	if (!request_mem_region(chip->base, BUFFSIZE, card->shortname)) {
 548		printk(KERN_ERR LOGNAME
 549			": unable to grab memory region 0x%lx-0x%lx\n",
 550			chip->base, chip->base + BUFFSIZE - 1);
 551		release_region(chip->io, DSP_NUMIO);
 552		free_irq(chip->irq, chip);
 553		return -EBUSY;
 554	}
 555	chip->mappedbase = ioremap(chip->base, 0x8000);
 556	if (!chip->mappedbase) {
 557		printk(KERN_ERR LOGNAME
 558			": unable to map memory region 0x%lx-0x%lx\n",
 559			chip->base, chip->base + BUFFSIZE - 1);
 560		err = -EIO;
 561		goto err_release_region;
 562	}
 563
 564	err = snd_msnd_dsp_full_reset(card);
 565	if (err < 0)
 566		goto err_release_region;
 567
 568	/* Register device */
 569	err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
 570	if (err < 0)
 571		goto err_release_region;
 572
 573	err = snd_msnd_pcm(card, 0);
 574	if (err < 0) {
 575		printk(KERN_ERR LOGNAME ": error creating new PCM device\n");
 576		goto err_release_region;
 577	}
 578
 579	err = snd_msndmix_new(card);
 580	if (err < 0) {
 581		printk(KERN_ERR LOGNAME ": error creating new Mixer device\n");
 582		goto err_release_region;
 583	}
 584
 585
 586	if (mpu_io[0] != SNDRV_AUTO_PORT) {
 587		struct snd_mpu401 *mpu;
 588
 589		err = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
 590					  mpu_io[0],
 591					  MPU401_MODE_INPUT |
 592					  MPU401_MODE_OUTPUT,
 593					  mpu_irq[0],
 594					  &chip->rmidi);
 595		if (err < 0) {
 596			printk(KERN_ERR LOGNAME
 597				": error creating new Midi device\n");
 598			goto err_release_region;
 599		}
 600		mpu = chip->rmidi->private_data;
 601
 602		mpu->open_input = snd_msnd_mpu401_open;
 603		mpu->close_input = snd_msnd_mpu401_close;
 604		mpu->private_data = chip;
 605	}
 606
 607	disable_irq(chip->irq);
 608	snd_msnd_calibrate_adc(chip, chip->play_sample_rate);
 609	snd_msndmix_force_recsrc(chip, 0);
 610
 611	err = snd_card_register(card);
 612	if (err < 0)
 613		goto err_release_region;
 614
 615	return 0;
 616
 617err_release_region:
 618	iounmap(chip->mappedbase);
 
 619	release_mem_region(chip->base, BUFFSIZE);
 620	release_region(chip->io, DSP_NUMIO);
 621	free_irq(chip->irq, chip);
 622	return err;
 623}
 624
 625
 626static void snd_msnd_unload(struct snd_card *card)
 627{
 628	struct snd_msnd *chip = card->private_data;
 629
 630	iounmap(chip->mappedbase);
 631	release_mem_region(chip->base, BUFFSIZE);
 632	release_region(chip->io, DSP_NUMIO);
 633	free_irq(chip->irq, chip);
 634	snd_card_free(card);
 635}
 636
 637#ifndef MSND_CLASSIC
 638
 639/* Pinnacle/Fiji Logical Device Configuration */
 640
 641static int snd_msnd_write_cfg(int cfg, int reg, int value)
 642{
 643	outb(reg, cfg);
 644	outb(value, cfg + 1);
 645	if (value != inb(cfg + 1)) {
 646		printk(KERN_ERR LOGNAME ": snd_msnd_write_cfg: I/O error\n");
 647		return -EIO;
 648	}
 649	return 0;
 650}
 651
 652static int snd_msnd_write_cfg_io0(int cfg, int num, u16 io)
 653{
 654	if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
 655		return -EIO;
 656	if (snd_msnd_write_cfg(cfg, IREG_IO0_BASEHI, HIBYTE(io)))
 657		return -EIO;
 658	if (snd_msnd_write_cfg(cfg, IREG_IO0_BASELO, LOBYTE(io)))
 659		return -EIO;
 660	return 0;
 661}
 662
 663static int snd_msnd_write_cfg_io1(int cfg, int num, u16 io)
 664{
 665	if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
 666		return -EIO;
 667	if (snd_msnd_write_cfg(cfg, IREG_IO1_BASEHI, HIBYTE(io)))
 668		return -EIO;
 669	if (snd_msnd_write_cfg(cfg, IREG_IO1_BASELO, LOBYTE(io)))
 670		return -EIO;
 671	return 0;
 672}
 673
 674static int snd_msnd_write_cfg_irq(int cfg, int num, u16 irq)
 675{
 676	if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
 677		return -EIO;
 678	if (snd_msnd_write_cfg(cfg, IREG_IRQ_NUMBER, LOBYTE(irq)))
 679		return -EIO;
 680	if (snd_msnd_write_cfg(cfg, IREG_IRQ_TYPE, IRQTYPE_EDGE))
 681		return -EIO;
 682	return 0;
 683}
 684
 685static int snd_msnd_write_cfg_mem(int cfg, int num, int mem)
 686{
 687	u16 wmem;
 688
 689	mem >>= 8;
 690	wmem = (u16)(mem & 0xfff);
 691	if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
 692		return -EIO;
 693	if (snd_msnd_write_cfg(cfg, IREG_MEMBASEHI, HIBYTE(wmem)))
 694		return -EIO;
 695	if (snd_msnd_write_cfg(cfg, IREG_MEMBASELO, LOBYTE(wmem)))
 696		return -EIO;
 697	if (wmem && snd_msnd_write_cfg(cfg, IREG_MEMCONTROL,
 698				       MEMTYPE_HIADDR | MEMTYPE_16BIT))
 699		return -EIO;
 700	return 0;
 701}
 702
 703static int snd_msnd_activate_logical(int cfg, int num)
 704{
 705	if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
 706		return -EIO;
 707	if (snd_msnd_write_cfg(cfg, IREG_ACTIVATE, LD_ACTIVATE))
 708		return -EIO;
 709	return 0;
 710}
 711
 712static int snd_msnd_write_cfg_logical(int cfg, int num, u16 io0,
 713				      u16 io1, u16 irq, int mem)
 714{
 715	if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
 716		return -EIO;
 717	if (snd_msnd_write_cfg_io0(cfg, num, io0))
 718		return -EIO;
 719	if (snd_msnd_write_cfg_io1(cfg, num, io1))
 720		return -EIO;
 721	if (snd_msnd_write_cfg_irq(cfg, num, irq))
 722		return -EIO;
 723	if (snd_msnd_write_cfg_mem(cfg, num, mem))
 724		return -EIO;
 725	if (snd_msnd_activate_logical(cfg, num))
 726		return -EIO;
 727	return 0;
 728}
 729
 730static int snd_msnd_pinnacle_cfg_reset(int cfg)
 731{
 732	int i;
 733
 734	/* Reset devices if told to */
 735	printk(KERN_INFO LOGNAME ": Resetting all devices\n");
 736	for (i = 0; i < 4; ++i)
 737		if (snd_msnd_write_cfg_logical(cfg, i, 0, 0, 0, 0))
 738			return -EIO;
 739
 740	return 0;
 741}
 742#endif
 743
 744static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;	/* Index 0-MAX */
 745static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;	/* ID for this card */
 746
 747module_param_array(index, int, NULL, 0444);
 748MODULE_PARM_DESC(index, "Index value for msnd_pinnacle soundcard.");
 749module_param_array(id, charp, NULL, 0444);
 750MODULE_PARM_DESC(id, "ID string for msnd_pinnacle soundcard.");
 751
 752static long io[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
 753static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
 754static long mem[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
 755
 756#ifndef MSND_CLASSIC
 757static long cfg[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
 758
 759/* Extra Peripheral Configuration (Default: Disable) */
 760static long ide_io0[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
 761static long ide_io1[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
 762static int ide_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
 763
 764static long joystick_io[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
 765/* If we have the digital daugherboard... */
 766static int digital[SNDRV_CARDS];
 767
 768/* Extra Peripheral Configuration */
 769static int reset[SNDRV_CARDS];
 770#endif
 771
 772static int write_ndelay[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = 1 };
 773
 774static int calibrate_signal;
 775
 776#ifdef CONFIG_PNP
 777static bool isapnp[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
 778module_param_array(isapnp, bool, NULL, 0444);
 779MODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard.");
 780#define has_isapnp(x) isapnp[x]
 781#else
 782#define has_isapnp(x) 0
 783#endif
 784
 785MODULE_AUTHOR("Karsten Wiese <annabellesgarden@yahoo.de>");
 786MODULE_DESCRIPTION("Turtle Beach " LONGNAME " Linux Driver");
 787MODULE_LICENSE("GPL");
 788MODULE_FIRMWARE(INITCODEFILE);
 789MODULE_FIRMWARE(PERMCODEFILE);
 790
 791module_param_hw_array(io, long, ioport, NULL, 0444);
 792MODULE_PARM_DESC(io, "IO port #");
 793module_param_hw_array(irq, int, irq, NULL, 0444);
 794module_param_hw_array(mem, long, iomem, NULL, 0444);
 795module_param_array(write_ndelay, int, NULL, 0444);
 796module_param(calibrate_signal, int, 0444);
 797#ifndef MSND_CLASSIC
 798module_param_array(digital, int, NULL, 0444);
 799module_param_hw_array(cfg, long, ioport, NULL, 0444);
 800module_param_array(reset, int, NULL, 0444);
 801module_param_hw_array(mpu_io, long, ioport, NULL, 0444);
 802module_param_hw_array(mpu_irq, int, irq, NULL, 0444);
 803module_param_hw_array(ide_io0, long, ioport, NULL, 0444);
 804module_param_hw_array(ide_io1, long, ioport, NULL, 0444);
 805module_param_hw_array(ide_irq, int, irq, NULL, 0444);
 806module_param_hw_array(joystick_io, long, ioport, NULL, 0444);
 807#endif
 808
 809
 810static int snd_msnd_isa_match(struct device *pdev, unsigned int i)
 811{
 812	if (io[i] == SNDRV_AUTO_PORT)
 813		return 0;
 814
 815	if (irq[i] == SNDRV_AUTO_PORT || mem[i] == SNDRV_AUTO_PORT) {
 816		printk(KERN_WARNING LOGNAME ": io, irq and mem must be set\n");
 817		return 0;
 818	}
 819
 820#ifdef MSND_CLASSIC
 821	if (!(io[i] == 0x290 ||
 822	      io[i] == 0x260 ||
 823	      io[i] == 0x250 ||
 824	      io[i] == 0x240 ||
 825	      io[i] == 0x230 ||
 826	      io[i] == 0x220 ||
 827	      io[i] == 0x210 ||
 828	      io[i] == 0x3e0)) {
 829		printk(KERN_ERR LOGNAME ": \"io\" - DSP I/O base must be set "
 830			" to 0x210, 0x220, 0x230, 0x240, 0x250, 0x260, 0x290, "
 831			"or 0x3E0\n");
 832		return 0;
 833	}
 834#else
 835	if (io[i] < 0x100 || io[i] > 0x3e0 || (io[i] % 0x10) != 0) {
 836		printk(KERN_ERR LOGNAME
 837			": \"io\" - DSP I/O base must within the range 0x100 "
 838			"to 0x3E0 and must be evenly divisible by 0x10\n");
 839		return 0;
 840	}
 841#endif /* MSND_CLASSIC */
 842
 843	if (!(irq[i] == 5 ||
 844	      irq[i] == 7 ||
 845	      irq[i] == 9 ||
 846	      irq[i] == 10 ||
 847	      irq[i] == 11 ||
 848	      irq[i] == 12)) {
 849		printk(KERN_ERR LOGNAME
 850			": \"irq\" - must be set to 5, 7, 9, 10, 11 or 12\n");
 851		return 0;
 852	}
 853
 854	if (!(mem[i] == 0xb0000 ||
 855	      mem[i] == 0xc8000 ||
 856	      mem[i] == 0xd0000 ||
 857	      mem[i] == 0xd8000 ||
 858	      mem[i] == 0xe0000 ||
 859	      mem[i] == 0xe8000)) {
 860		printk(KERN_ERR LOGNAME ": \"mem\" - must be set to "
 861		       "0xb0000, 0xc8000, 0xd0000, 0xd8000, 0xe0000 or "
 862		       "0xe8000\n");
 863		return 0;
 864	}
 865
 866#ifndef MSND_CLASSIC
 867	if (cfg[i] == SNDRV_AUTO_PORT) {
 868		printk(KERN_INFO LOGNAME ": Assuming PnP mode\n");
 869	} else if (cfg[i] != 0x250 && cfg[i] != 0x260 && cfg[i] != 0x270) {
 870		printk(KERN_INFO LOGNAME
 871			": Config port must be 0x250, 0x260 or 0x270 "
 872			"(or unspecified for PnP mode)\n");
 873		return 0;
 874	}
 875#endif /* MSND_CLASSIC */
 876
 877	return 1;
 878}
 879
 880static int snd_msnd_isa_probe(struct device *pdev, unsigned int idx)
 881{
 882	int err;
 883	struct snd_card *card;
 884	struct snd_msnd *chip;
 885
 886	if (has_isapnp(idx)
 887#ifndef MSND_CLASSIC
 888	    || cfg[idx] == SNDRV_AUTO_PORT
 889#endif
 890	    ) {
 891		printk(KERN_INFO LOGNAME ": Assuming PnP mode\n");
 892		return -ENODEV;
 893	}
 894
 895	err = snd_card_new(pdev, index[idx], id[idx], THIS_MODULE,
 896			   sizeof(struct snd_msnd), &card);
 897	if (err < 0)
 898		return err;
 899
 
 900	chip = card->private_data;
 901	chip->card = card;
 902
 903#ifdef MSND_CLASSIC
 904	switch (irq[idx]) {
 905	case 5:
 906		chip->irqid = HPIRQ_5; break;
 907	case 7:
 908		chip->irqid = HPIRQ_7; break;
 909	case 9:
 910		chip->irqid = HPIRQ_9; break;
 911	case 10:
 912		chip->irqid = HPIRQ_10; break;
 913	case 11:
 914		chip->irqid = HPIRQ_11; break;
 915	case 12:
 916		chip->irqid = HPIRQ_12; break;
 917	}
 918
 919	switch (mem[idx]) {
 920	case 0xb0000:
 921		chip->memid = HPMEM_B000; break;
 922	case 0xc8000:
 923		chip->memid = HPMEM_C800; break;
 924	case 0xd0000:
 925		chip->memid = HPMEM_D000; break;
 926	case 0xd8000:
 927		chip->memid = HPMEM_D800; break;
 928	case 0xe0000:
 929		chip->memid = HPMEM_E000; break;
 930	case 0xe8000:
 931		chip->memid = HPMEM_E800; break;
 932	}
 933#else
 934	printk(KERN_INFO LOGNAME ": Non-PnP mode: configuring at port 0x%lx\n",
 935			cfg[idx]);
 936
 937	if (!request_region(cfg[idx], 2, "Pinnacle/Fiji Config")) {
 938		printk(KERN_ERR LOGNAME ": Config port 0x%lx conflict\n",
 939			   cfg[idx]);
 940		snd_card_free(card);
 941		return -EIO;
 942	}
 943	if (reset[idx])
 944		if (snd_msnd_pinnacle_cfg_reset(cfg[idx])) {
 945			err = -EIO;
 946			goto cfg_error;
 947		}
 948
 949	/* DSP */
 950	err = snd_msnd_write_cfg_logical(cfg[idx], 0,
 951					 io[idx], 0,
 952					 irq[idx], mem[idx]);
 953
 954	if (err)
 955		goto cfg_error;
 956
 957	/* The following are Pinnacle specific */
 958
 959	/* MPU */
 960	if (mpu_io[idx] != SNDRV_AUTO_PORT
 961	    && mpu_irq[idx] != SNDRV_AUTO_IRQ) {
 962		printk(KERN_INFO LOGNAME
 963		       ": Configuring MPU to I/O 0x%lx IRQ %d\n",
 964		       mpu_io[idx], mpu_irq[idx]);
 965		err = snd_msnd_write_cfg_logical(cfg[idx], 1,
 966						 mpu_io[idx], 0,
 967						 mpu_irq[idx], 0);
 968
 969		if (err)
 970			goto cfg_error;
 971	}
 972
 973	/* IDE */
 974	if (ide_io0[idx] != SNDRV_AUTO_PORT
 975	    && ide_io1[idx] != SNDRV_AUTO_PORT
 976	    && ide_irq[idx] != SNDRV_AUTO_IRQ) {
 977		printk(KERN_INFO LOGNAME
 978		       ": Configuring IDE to I/O 0x%lx, 0x%lx IRQ %d\n",
 979		       ide_io0[idx], ide_io1[idx], ide_irq[idx]);
 980		err = snd_msnd_write_cfg_logical(cfg[idx], 2,
 981						 ide_io0[idx], ide_io1[idx],
 982						 ide_irq[idx], 0);
 983
 984		if (err)
 985			goto cfg_error;
 986	}
 987
 988	/* Joystick */
 989	if (joystick_io[idx] != SNDRV_AUTO_PORT) {
 990		printk(KERN_INFO LOGNAME
 991		       ": Configuring joystick to I/O 0x%lx\n",
 992		       joystick_io[idx]);
 993		err = snd_msnd_write_cfg_logical(cfg[idx], 3,
 994						 joystick_io[idx], 0,
 995						 0, 0);
 996
 997		if (err)
 998			goto cfg_error;
 999	}
1000	release_region(cfg[idx], 2);
1001
1002#endif /* MSND_CLASSIC */
1003
1004	set_default_audio_parameters(chip);
1005#ifdef MSND_CLASSIC
1006	chip->type = msndClassic;
1007#else
1008	chip->type = msndPinnacle;
1009#endif
1010	chip->io = io[idx];
1011	chip->irq = irq[idx];
1012	chip->base = mem[idx];
1013
1014	chip->calibrate_signal = calibrate_signal ? 1 : 0;
1015	chip->recsrc = 0;
1016	chip->dspq_data_buff = DSPQ_DATA_BUFF;
1017	chip->dspq_buff_size = DSPQ_BUFF_SIZE;
1018	if (write_ndelay[idx])
1019		clear_bit(F_DISABLE_WRITE_NDELAY, &chip->flags);
1020	else
1021		set_bit(F_DISABLE_WRITE_NDELAY, &chip->flags);
1022#ifndef MSND_CLASSIC
1023	if (digital[idx])
1024		set_bit(F_HAVEDIGITAL, &chip->flags);
1025#endif
1026	spin_lock_init(&chip->lock);
1027	err = snd_msnd_probe(card);
1028	if (err < 0) {
1029		printk(KERN_ERR LOGNAME ": Probe failed\n");
1030		snd_card_free(card);
1031		return err;
1032	}
1033
1034	err = snd_msnd_attach(card);
1035	if (err < 0) {
1036		printk(KERN_ERR LOGNAME ": Attach failed\n");
1037		snd_card_free(card);
1038		return err;
1039	}
1040	dev_set_drvdata(pdev, card);
1041
1042	return 0;
1043
1044#ifndef MSND_CLASSIC
1045cfg_error:
1046	release_region(cfg[idx], 2);
1047	snd_card_free(card);
1048	return err;
1049#endif
1050}
1051
1052static int snd_msnd_isa_remove(struct device *pdev, unsigned int dev)
1053{
1054	snd_msnd_unload(dev_get_drvdata(pdev));
 
1055	return 0;
1056}
1057
 
 
1058static struct isa_driver snd_msnd_driver = {
1059	.match		= snd_msnd_isa_match,
1060	.probe		= snd_msnd_isa_probe,
1061	.remove		= snd_msnd_isa_remove,
1062	/* FIXME: suspend, resume */
1063	.driver		= {
1064		.name	= DEV_NAME
1065	},
1066};
1067
1068#ifdef CONFIG_PNP
1069static int snd_msnd_pnp_detect(struct pnp_card_link *pcard,
1070			       const struct pnp_card_device_id *pid)
1071{
1072	static int idx;
1073	struct pnp_dev *pnp_dev;
1074	struct pnp_dev *mpu_dev;
1075	struct snd_card *card;
1076	struct snd_msnd *chip;
1077	int ret;
1078
1079	for ( ; idx < SNDRV_CARDS; idx++) {
1080		if (has_isapnp(idx))
1081			break;
1082	}
1083	if (idx >= SNDRV_CARDS)
1084		return -ENODEV;
1085
1086	/*
1087	 * Check that we still have room for another sound card ...
1088	 */
1089	pnp_dev = pnp_request_card_device(pcard, pid->devs[0].id, NULL);
1090	if (!pnp_dev)
1091		return -ENODEV;
1092
1093	mpu_dev = pnp_request_card_device(pcard, pid->devs[1].id, NULL);
1094	if (!mpu_dev)
1095		return -ENODEV;
1096
1097	if (!pnp_is_active(pnp_dev) && pnp_activate_dev(pnp_dev) < 0) {
1098		printk(KERN_INFO "msnd_pinnacle: device is inactive\n");
1099		return -EBUSY;
1100	}
1101
1102	if (!pnp_is_active(mpu_dev) && pnp_activate_dev(mpu_dev) < 0) {
1103		printk(KERN_INFO "msnd_pinnacle: MPU device is inactive\n");
1104		return -EBUSY;
1105	}
1106
1107	/*
1108	 * Create a new ALSA sound card entry, in anticipation
1109	 * of detecting our hardware ...
1110	 */
1111	ret = snd_card_new(&pcard->card->dev,
1112			   index[idx], id[idx], THIS_MODULE,
1113			   sizeof(struct snd_msnd), &card);
1114	if (ret < 0)
1115		return ret;
1116
1117	chip = card->private_data;
1118	chip->card = card;
 
1119
1120	/*
1121	 * Read the correct parameters off the ISA PnP bus ...
1122	 */
1123	io[idx] = pnp_port_start(pnp_dev, 0);
1124	irq[idx] = pnp_irq(pnp_dev, 0);
1125	mem[idx] = pnp_mem_start(pnp_dev, 0);
1126	mpu_io[idx] = pnp_port_start(mpu_dev, 0);
1127	mpu_irq[idx] = pnp_irq(mpu_dev, 0);
1128
1129	set_default_audio_parameters(chip);
1130#ifdef MSND_CLASSIC
1131	chip->type = msndClassic;
1132#else
1133	chip->type = msndPinnacle;
1134#endif
1135	chip->io = io[idx];
1136	chip->irq = irq[idx];
1137	chip->base = mem[idx];
1138
1139	chip->calibrate_signal = calibrate_signal ? 1 : 0;
1140	chip->recsrc = 0;
1141	chip->dspq_data_buff = DSPQ_DATA_BUFF;
1142	chip->dspq_buff_size = DSPQ_BUFF_SIZE;
1143	if (write_ndelay[idx])
1144		clear_bit(F_DISABLE_WRITE_NDELAY, &chip->flags);
1145	else
1146		set_bit(F_DISABLE_WRITE_NDELAY, &chip->flags);
1147#ifndef MSND_CLASSIC
1148	if (digital[idx])
1149		set_bit(F_HAVEDIGITAL, &chip->flags);
1150#endif
1151	spin_lock_init(&chip->lock);
1152	ret = snd_msnd_probe(card);
1153	if (ret < 0) {
1154		printk(KERN_ERR LOGNAME ": Probe failed\n");
1155		goto _release_card;
1156	}
1157
1158	ret = snd_msnd_attach(card);
1159	if (ret < 0) {
1160		printk(KERN_ERR LOGNAME ": Attach failed\n");
1161		goto _release_card;
1162	}
1163
1164	pnp_set_card_drvdata(pcard, card);
1165	++idx;
1166	return 0;
1167
1168_release_card:
1169	snd_card_free(card);
1170	return ret;
1171}
1172
1173static void snd_msnd_pnp_remove(struct pnp_card_link *pcard)
1174{
1175	snd_msnd_unload(pnp_get_card_drvdata(pcard));
1176	pnp_set_card_drvdata(pcard, NULL);
1177}
1178
1179static int isa_registered;
1180static int pnp_registered;
1181
1182static const struct pnp_card_device_id msnd_pnpids[] = {
1183	/* Pinnacle PnP */
1184	{ .id = "BVJ0440", .devs = { { "TBS0000" }, { "TBS0001" } } },
1185	{ .id = "" }	/* end */
1186};
1187
1188MODULE_DEVICE_TABLE(pnp_card, msnd_pnpids);
1189
1190static struct pnp_card_driver msnd_pnpc_driver = {
1191	.flags = PNP_DRIVER_RES_DO_NOT_CHANGE,
1192	.name = "msnd_pinnacle",
1193	.id_table = msnd_pnpids,
1194	.probe = snd_msnd_pnp_detect,
1195	.remove = snd_msnd_pnp_remove,
1196};
1197#endif /* CONFIG_PNP */
1198
1199static int __init snd_msnd_init(void)
1200{
1201	int err;
1202
1203	err = isa_register_driver(&snd_msnd_driver, SNDRV_CARDS);
1204#ifdef CONFIG_PNP
1205	if (!err)
1206		isa_registered = 1;
1207
1208	err = pnp_register_card_driver(&msnd_pnpc_driver);
1209	if (!err)
1210		pnp_registered = 1;
1211
1212	if (isa_registered)
1213		err = 0;
1214#endif
1215	return err;
1216}
1217
1218static void __exit snd_msnd_exit(void)
1219{
1220#ifdef CONFIG_PNP
1221	if (pnp_registered)
1222		pnp_unregister_card_driver(&msnd_pnpc_driver);
1223	if (isa_registered)
1224#endif
1225		isa_unregister_driver(&snd_msnd_driver);
1226}
1227
1228module_init(snd_msnd_init);
1229module_exit(snd_msnd_exit);
1230
v3.1
 
   1/*********************************************************************
   2 *
   3 * Linux multisound pinnacle/fiji driver for ALSA.
   4 *
   5 * 2002/06/30 Karsten Wiese:
   6 *	for now this is only used to build a pinnacle / fiji driver.
   7 *	the OSS parent of this code is designed to also support
   8 *	the multisound classic via the file msnd_classic.c.
   9 *	to make it easier for some brave heart to implemt classic
  10 *	support in alsa, i left all the MSND_CLASSIC tokens in this file.
  11 *	but for now this untested & undone.
  12 *
  13 *
  14 * ripped from linux kernel 2.4.18 by Karsten Wiese.
  15 *
  16 * the following is a copy of the 2.4.18 OSS FREE file-heading comment:
  17 *
  18 * Turtle Beach MultiSound Sound Card Driver for Linux
  19 * msnd_pinnacle.c / msnd_classic.c
  20 *
  21 * -- If MSND_CLASSIC is defined:
  22 *
  23 *     -> driver for Turtle Beach Classic/Monterey/Tahiti
  24 *
  25 * -- Else
  26 *
  27 *     -> driver for Turtle Beach Pinnacle/Fiji
  28 *
  29 * 12-3-2000  Modified IO port validation  Steve Sycamore
  30 *
  31 * Copyright (C) 1998 Andrew Veliath
  32 *
  33 * This program is free software; you can redistribute it and/or modify
  34 * it under the terms of the GNU General Public License as published by
  35 * the Free Software Foundation; either version 2 of the License, or
  36 * (at your option) any later version.
  37 *
  38 * This program is distributed in the hope that it will be useful,
  39 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  40 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  41 * GNU General Public License for more details.
  42 *
  43 * You should have received a copy of the GNU General Public License
  44 * along with this program; if not, write to the Free Software
  45 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  46 *
  47 ********************************************************************/
  48
  49#include <linux/kernel.h>
  50#include <linux/module.h>
  51#include <linux/interrupt.h>
  52#include <linux/types.h>
  53#include <linux/delay.h>
  54#include <linux/ioport.h>
  55#include <linux/firmware.h>
  56#include <linux/isa.h>
  57#include <linux/isapnp.h>
  58#include <linux/irq.h>
  59#include <linux/io.h>
  60
  61#include <sound/core.h>
  62#include <sound/initval.h>
  63#include <sound/asound.h>
  64#include <sound/pcm.h>
  65#include <sound/mpu401.h>
  66
  67#ifdef MSND_CLASSIC
  68# ifndef __alpha__
  69#  define SLOWIO
  70# endif
  71#endif
  72#include "msnd.h"
  73#ifdef MSND_CLASSIC
  74#  include "msnd_classic.h"
  75#  define LOGNAME			"msnd_classic"
 
  76#else
  77#  include "msnd_pinnacle.h"
  78#  define LOGNAME			"snd_msnd_pinnacle"
 
  79#endif
  80
  81static void __devinit set_default_audio_parameters(struct snd_msnd *chip)
  82{
  83	chip->play_sample_size = DEFSAMPLESIZE;
  84	chip->play_sample_rate = DEFSAMPLERATE;
  85	chip->play_channels = DEFCHANNELS;
  86	chip->capture_sample_size = DEFSAMPLESIZE;
  87	chip->capture_sample_rate = DEFSAMPLERATE;
  88	chip->capture_channels = DEFCHANNELS;
  89}
  90
  91static void snd_msnd_eval_dsp_msg(struct snd_msnd *chip, u16 wMessage)
  92{
  93	switch (HIBYTE(wMessage)) {
  94	case HIMT_PLAY_DONE: {
  95		if (chip->banksPlayed < 3)
  96			snd_printdd("%08X: HIMT_PLAY_DONE: %i\n",
  97				(unsigned)jiffies, LOBYTE(wMessage));
  98
  99		if (chip->last_playbank == LOBYTE(wMessage)) {
 100			snd_printdd("chip.last_playbank == LOBYTE(wMessage)\n");
 101			break;
 102		}
 103		chip->banksPlayed++;
 104
 105		if (test_bit(F_WRITING, &chip->flags))
 106			snd_msnd_DAPQ(chip, 0);
 107
 108		chip->last_playbank = LOBYTE(wMessage);
 109		chip->playDMAPos += chip->play_period_bytes;
 110		if (chip->playDMAPos > chip->playLimit)
 111			chip->playDMAPos = 0;
 112		snd_pcm_period_elapsed(chip->playback_substream);
 113
 114		break;
 115	}
 116	case HIMT_RECORD_DONE:
 117		if (chip->last_recbank == LOBYTE(wMessage))
 118			break;
 119		chip->last_recbank = LOBYTE(wMessage);
 120		chip->captureDMAPos += chip->capturePeriodBytes;
 121		if (chip->captureDMAPos > (chip->captureLimit))
 122			chip->captureDMAPos = 0;
 123
 124		if (test_bit(F_READING, &chip->flags))
 125			snd_msnd_DARQ(chip, chip->last_recbank);
 126
 127		snd_pcm_period_elapsed(chip->capture_substream);
 128		break;
 129
 130	case HIMT_DSP:
 131		switch (LOBYTE(wMessage)) {
 132#ifndef MSND_CLASSIC
 133		case HIDSP_PLAY_UNDER:
 134#endif
 135		case HIDSP_INT_PLAY_UNDER:
 136			snd_printd(KERN_WARNING LOGNAME ": Play underflow %i\n",
 137				chip->banksPlayed);
 138			if (chip->banksPlayed > 2)
 139				clear_bit(F_WRITING, &chip->flags);
 140			break;
 141
 142		case HIDSP_INT_RECORD_OVER:
 143			snd_printd(KERN_WARNING LOGNAME ": Record overflow\n");
 144			clear_bit(F_READING, &chip->flags);
 145			break;
 146
 147		default:
 148			snd_printd(KERN_WARNING LOGNAME
 149				   ": DSP message %d 0x%02x\n",
 150				   LOBYTE(wMessage), LOBYTE(wMessage));
 151			break;
 152		}
 153		break;
 154
 155	case HIMT_MIDI_IN_UCHAR:
 156		if (chip->msndmidi_mpu)
 157			snd_msndmidi_input_read(chip->msndmidi_mpu);
 158		break;
 159
 160	default:
 161		snd_printd(KERN_WARNING LOGNAME ": HIMT message %d 0x%02x\n",
 162			   HIBYTE(wMessage), HIBYTE(wMessage));
 163		break;
 164	}
 165}
 166
 167static irqreturn_t snd_msnd_interrupt(int irq, void *dev_id)
 168{
 169	struct snd_msnd *chip = dev_id;
 170	void *pwDSPQData = chip->mappedbase + DSPQ_DATA_BUFF;
 
 171
 172	/* Send ack to DSP */
 173	/* inb(chip->io + HP_RXL); */
 174
 175	/* Evaluate queued DSP messages */
 176	while (readw(chip->DSPQ + JQS_wTail) != readw(chip->DSPQ + JQS_wHead)) {
 177		u16 wTmp;
 178
 179		snd_msnd_eval_dsp_msg(chip,
 180			readw(pwDSPQData + 2 * readw(chip->DSPQ + JQS_wHead)));
 181
 182		wTmp = readw(chip->DSPQ + JQS_wHead) + 1;
 183		if (wTmp > readw(chip->DSPQ + JQS_wSize))
 184			writew(0, chip->DSPQ + JQS_wHead);
 185		else
 186			writew(wTmp, chip->DSPQ + JQS_wHead);
 187	}
 
 188	/* Send ack to DSP */
 189	inb(chip->io + HP_RXL);
 190	return IRQ_HANDLED;
 191}
 192
 193
 194static int snd_msnd_reset_dsp(long io, unsigned char *info)
 195{
 196	int timeout = 100;
 197
 198	outb(HPDSPRESET_ON, io + HP_DSPR);
 199	msleep(1);
 200#ifndef MSND_CLASSIC
 201	if (info)
 202		*info = inb(io + HP_INFO);
 203#endif
 204	outb(HPDSPRESET_OFF, io + HP_DSPR);
 205	msleep(1);
 206	while (timeout-- > 0) {
 207		if (inb(io + HP_CVR) == HP_CVR_DEF)
 208			return 0;
 209		msleep(1);
 210	}
 211	snd_printk(KERN_ERR LOGNAME ": Cannot reset DSP\n");
 212
 213	return -EIO;
 214}
 215
 216static int __devinit snd_msnd_probe(struct snd_card *card)
 217{
 218	struct snd_msnd *chip = card->private_data;
 219	unsigned char info;
 220#ifndef MSND_CLASSIC
 221	char *xv, *rev = NULL;
 222	char *pin = "TB Pinnacle", *fiji = "TB Fiji";
 223	char *pinfiji = "TB Pinnacle/Fiji";
 224#endif
 225
 226	if (!request_region(chip->io, DSP_NUMIO, "probing")) {
 227		snd_printk(KERN_ERR LOGNAME ": I/O port conflict\n");
 228		return -ENODEV;
 229	}
 230
 231	if (snd_msnd_reset_dsp(chip->io, &info) < 0) {
 232		release_region(chip->io, DSP_NUMIO);
 233		return -ENODEV;
 234	}
 235
 236#ifdef MSND_CLASSIC
 237	strcpy(card->shortname, "Classic/Tahiti/Monterey");
 238	strcpy(card->longname, "Turtle Beach Multisound");
 239	printk(KERN_INFO LOGNAME ": %s, "
 240	       "I/O 0x%lx-0x%lx, IRQ %d, memory mapped to 0x%lX-0x%lX\n",
 241	       card->shortname,
 242	       chip->io, chip->io + DSP_NUMIO - 1,
 243	       chip->irq,
 244	       chip->base, chip->base + 0x7fff);
 245#else
 246	switch (info >> 4) {
 247	case 0xf:
 248		xv = "<= 1.15";
 249		break;
 250	case 0x1:
 251		xv = "1.18/1.2";
 252		break;
 253	case 0x2:
 254		xv = "1.3";
 255		break;
 256	case 0x3:
 257		xv = "1.4";
 258		break;
 259	default:
 260		xv = "unknown";
 261		break;
 262	}
 263
 264	switch (info & 0x7) {
 265	case 0x0:
 266		rev = "I";
 267		strcpy(card->shortname, pin);
 268		break;
 269	case 0x1:
 270		rev = "F";
 271		strcpy(card->shortname, pin);
 272		break;
 273	case 0x2:
 274		rev = "G";
 275		strcpy(card->shortname, pin);
 276		break;
 277	case 0x3:
 278		rev = "H";
 279		strcpy(card->shortname, pin);
 280		break;
 281	case 0x4:
 282		rev = "E";
 283		strcpy(card->shortname, fiji);
 284		break;
 285	case 0x5:
 286		rev = "C";
 287		strcpy(card->shortname, fiji);
 288		break;
 289	case 0x6:
 290		rev = "D";
 291		strcpy(card->shortname, fiji);
 292		break;
 293	case 0x7:
 294		rev = "A-B (Fiji) or A-E (Pinnacle)";
 295		strcpy(card->shortname, pinfiji);
 296		break;
 297	}
 298	strcpy(card->longname, "Turtle Beach Multisound Pinnacle");
 299	printk(KERN_INFO LOGNAME ": %s revision %s, Xilinx version %s, "
 300	       "I/O 0x%lx-0x%lx, IRQ %d, memory mapped to 0x%lX-0x%lX\n",
 301	       card->shortname,
 302	       rev, xv,
 303	       chip->io, chip->io + DSP_NUMIO - 1,
 304	       chip->irq,
 305	       chip->base, chip->base + 0x7fff);
 306#endif
 307
 308	release_region(chip->io, DSP_NUMIO);
 309	return 0;
 310}
 311
 312static int snd_msnd_init_sma(struct snd_msnd *chip)
 313{
 314	static int initted;
 315	u16 mastVolLeft, mastVolRight;
 316	unsigned long flags;
 317
 318#ifdef MSND_CLASSIC
 319	outb(chip->memid, chip->io + HP_MEMM);
 320#endif
 321	outb(HPBLKSEL_0, chip->io + HP_BLKS);
 322	/* Motorola 56k shared memory base */
 323	chip->SMA = chip->mappedbase + SMA_STRUCT_START;
 324
 325	if (initted) {
 326		mastVolLeft = readw(chip->SMA + SMA_wCurrMastVolLeft);
 327		mastVolRight = readw(chip->SMA + SMA_wCurrMastVolRight);
 328	} else
 329		mastVolLeft = mastVolRight = 0;
 330	memset_io(chip->mappedbase, 0, 0x8000);
 331
 332	/* Critical section: bank 1 access */
 333	spin_lock_irqsave(&chip->lock, flags);
 334	outb(HPBLKSEL_1, chip->io + HP_BLKS);
 335	memset_io(chip->mappedbase, 0, 0x8000);
 336	outb(HPBLKSEL_0, chip->io + HP_BLKS);
 337	spin_unlock_irqrestore(&chip->lock, flags);
 338
 339	/* Digital audio play queue */
 340	chip->DAPQ = chip->mappedbase + DAPQ_OFFSET;
 341	snd_msnd_init_queue(chip->DAPQ, DAPQ_DATA_BUFF, DAPQ_BUFF_SIZE);
 342
 343	/* Digital audio record queue */
 344	chip->DARQ = chip->mappedbase + DARQ_OFFSET;
 345	snd_msnd_init_queue(chip->DARQ, DARQ_DATA_BUFF, DARQ_BUFF_SIZE);
 346
 347	/* MIDI out queue */
 348	chip->MODQ = chip->mappedbase + MODQ_OFFSET;
 349	snd_msnd_init_queue(chip->MODQ, MODQ_DATA_BUFF, MODQ_BUFF_SIZE);
 350
 351	/* MIDI in queue */
 352	chip->MIDQ = chip->mappedbase + MIDQ_OFFSET;
 353	snd_msnd_init_queue(chip->MIDQ, MIDQ_DATA_BUFF, MIDQ_BUFF_SIZE);
 354
 355	/* DSP -> host message queue */
 356	chip->DSPQ = chip->mappedbase + DSPQ_OFFSET;
 357	snd_msnd_init_queue(chip->DSPQ, DSPQ_DATA_BUFF, DSPQ_BUFF_SIZE);
 358
 359	/* Setup some DSP values */
 360#ifndef MSND_CLASSIC
 361	writew(1, chip->SMA + SMA_wCurrPlayFormat);
 362	writew(chip->play_sample_size, chip->SMA + SMA_wCurrPlaySampleSize);
 363	writew(chip->play_channels, chip->SMA + SMA_wCurrPlayChannels);
 364	writew(chip->play_sample_rate, chip->SMA + SMA_wCurrPlaySampleRate);
 365#endif
 366	writew(chip->play_sample_rate, chip->SMA + SMA_wCalFreqAtoD);
 367	writew(mastVolLeft, chip->SMA + SMA_wCurrMastVolLeft);
 368	writew(mastVolRight, chip->SMA + SMA_wCurrMastVolRight);
 369#ifndef MSND_CLASSIC
 370	writel(0x00010000, chip->SMA + SMA_dwCurrPlayPitch);
 371	writel(0x00000001, chip->SMA + SMA_dwCurrPlayRate);
 372#endif
 373	writew(0x303, chip->SMA + SMA_wCurrInputTagBits);
 374
 375	initted = 1;
 376
 377	return 0;
 378}
 379
 380
 381static int upload_dsp_code(struct snd_card *card)
 382{
 383	struct snd_msnd *chip = card->private_data;
 384	const struct firmware *init_fw = NULL, *perm_fw = NULL;
 385	int err;
 386
 387	outb(HPBLKSEL_0, chip->io + HP_BLKS);
 388
 389	err = request_firmware(&init_fw, INITCODEFILE, card->dev);
 390	if (err < 0) {
 391		printk(KERN_ERR LOGNAME ": Error loading " INITCODEFILE);
 392		goto cleanup1;
 393	}
 394	err = request_firmware(&perm_fw, PERMCODEFILE, card->dev);
 395	if (err < 0) {
 396		printk(KERN_ERR LOGNAME ": Error loading " PERMCODEFILE);
 397		goto cleanup;
 398	}
 399
 400	memcpy_toio(chip->mappedbase, perm_fw->data, perm_fw->size);
 401	if (snd_msnd_upload_host(chip, init_fw->data, init_fw->size) < 0) {
 402		printk(KERN_WARNING LOGNAME ": Error uploading to DSP\n");
 403		err = -ENODEV;
 404		goto cleanup;
 405	}
 406	printk(KERN_INFO LOGNAME ": DSP firmware uploaded\n");
 407	err = 0;
 408
 409cleanup:
 410	release_firmware(perm_fw);
 411cleanup1:
 412	release_firmware(init_fw);
 413	return err;
 414}
 415
 416#ifdef MSND_CLASSIC
 417static void reset_proteus(struct snd_msnd *chip)
 418{
 419	outb(HPPRORESET_ON, chip->io + HP_PROR);
 420	msleep(TIME_PRO_RESET);
 421	outb(HPPRORESET_OFF, chip->io + HP_PROR);
 422	msleep(TIME_PRO_RESET_DONE);
 423}
 424#endif
 425
 426static int snd_msnd_initialize(struct snd_card *card)
 427{
 428	struct snd_msnd *chip = card->private_data;
 429	int err, timeout;
 430
 431#ifdef MSND_CLASSIC
 432	outb(HPWAITSTATE_0, chip->io + HP_WAIT);
 433	outb(HPBITMODE_16, chip->io + HP_BITM);
 434
 435	reset_proteus(chip);
 436#endif
 437	err = snd_msnd_init_sma(chip);
 438	if (err < 0) {
 439		printk(KERN_WARNING LOGNAME ": Cannot initialize SMA\n");
 440		return err;
 441	}
 442
 443	err = snd_msnd_reset_dsp(chip->io, NULL);
 444	if (err < 0)
 445		return err;
 446
 447	err = upload_dsp_code(card);
 448	if (err < 0) {
 449		printk(KERN_WARNING LOGNAME ": Cannot upload DSP code\n");
 450		return err;
 451	}
 452
 453	timeout = 200;
 454
 455	while (readw(chip->mappedbase)) {
 456		msleep(1);
 457		if (!timeout--) {
 458			snd_printd(KERN_ERR LOGNAME ": DSP reset timeout\n");
 459			return -EIO;
 460		}
 461	}
 462
 463	snd_msndmix_setup(chip);
 464	return 0;
 465}
 466
 467static int snd_msnd_dsp_full_reset(struct snd_card *card)
 468{
 469	struct snd_msnd *chip = card->private_data;
 470	int rv;
 471
 472	if (test_bit(F_RESETTING, &chip->flags) || ++chip->nresets > 10)
 473		return 0;
 474
 475	set_bit(F_RESETTING, &chip->flags);
 476	snd_msnd_dsp_halt(chip, NULL);	/* Unconditionally halt */
 477
 478	rv = snd_msnd_initialize(card);
 479	if (rv)
 480		printk(KERN_WARNING LOGNAME ": DSP reset failed\n");
 481	snd_msndmix_force_recsrc(chip, 0);
 482	clear_bit(F_RESETTING, &chip->flags);
 483	return rv;
 484}
 485
 486static int snd_msnd_dev_free(struct snd_device *device)
 487{
 488	snd_printdd("snd_msnd_chip_free()\n");
 489	return 0;
 490}
 491
 492static int snd_msnd_send_dsp_cmd_chk(struct snd_msnd *chip, u8 cmd)
 493{
 494	if (snd_msnd_send_dsp_cmd(chip, cmd) == 0)
 495		return 0;
 496	snd_msnd_dsp_full_reset(chip->card);
 497	return snd_msnd_send_dsp_cmd(chip, cmd);
 498}
 499
 500static int __devinit snd_msnd_calibrate_adc(struct snd_msnd *chip, u16 srate)
 501{
 502	snd_printdd("snd_msnd_calibrate_adc(%i)\n", srate);
 503	writew(srate, chip->SMA + SMA_wCalFreqAtoD);
 504	if (chip->calibrate_signal == 0)
 505		writew(readw(chip->SMA + SMA_wCurrHostStatusFlags)
 506		       | 0x0001, chip->SMA + SMA_wCurrHostStatusFlags);
 507	else
 508		writew(readw(chip->SMA + SMA_wCurrHostStatusFlags)
 509		       & ~0x0001, chip->SMA + SMA_wCurrHostStatusFlags);
 510	if (snd_msnd_send_word(chip, 0, 0, HDEXAR_CAL_A_TO_D) == 0 &&
 511	    snd_msnd_send_dsp_cmd_chk(chip, HDEX_AUX_REQ) == 0) {
 512		schedule_timeout_interruptible(msecs_to_jiffies(333));
 513		return 0;
 514	}
 515	printk(KERN_WARNING LOGNAME ": ADC calibration failed\n");
 516	return -EIO;
 517}
 518
 519/*
 520 * ALSA callback function, called when attempting to open the MIDI device.
 521 */
 522static int snd_msnd_mpu401_open(struct snd_mpu401 *mpu)
 523{
 524	snd_msnd_enable_irq(mpu->private_data);
 525	snd_msnd_send_dsp_cmd(mpu->private_data, HDEX_MIDI_IN_START);
 526	return 0;
 527}
 528
 529static void snd_msnd_mpu401_close(struct snd_mpu401 *mpu)
 530{
 531	snd_msnd_send_dsp_cmd(mpu->private_data, HDEX_MIDI_IN_STOP);
 532	snd_msnd_disable_irq(mpu->private_data);
 533}
 534
 535static long mpu_io[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
 536static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
 537
 538static int __devinit snd_msnd_attach(struct snd_card *card)
 539{
 540	struct snd_msnd *chip = card->private_data;
 541	int err;
 542	static struct snd_device_ops ops = {
 543		.dev_free =      snd_msnd_dev_free,
 544		};
 545
 546	err = request_irq(chip->irq, snd_msnd_interrupt, 0, card->shortname,
 547			  chip);
 548	if (err < 0) {
 549		printk(KERN_ERR LOGNAME ": Couldn't grab IRQ %d\n", chip->irq);
 550		return err;
 551	}
 
 552	if (request_region(chip->io, DSP_NUMIO, card->shortname) == NULL) {
 553		free_irq(chip->irq, chip);
 554		return -EBUSY;
 555	}
 556
 557	if (!request_mem_region(chip->base, BUFFSIZE, card->shortname)) {
 558		printk(KERN_ERR LOGNAME
 559			": unable to grab memory region 0x%lx-0x%lx\n",
 560			chip->base, chip->base + BUFFSIZE - 1);
 561		release_region(chip->io, DSP_NUMIO);
 562		free_irq(chip->irq, chip);
 563		return -EBUSY;
 564	}
 565	chip->mappedbase = ioremap_nocache(chip->base, 0x8000);
 566	if (!chip->mappedbase) {
 567		printk(KERN_ERR LOGNAME
 568			": unable to map memory region 0x%lx-0x%lx\n",
 569			chip->base, chip->base + BUFFSIZE - 1);
 570		err = -EIO;
 571		goto err_release_region;
 572	}
 573
 574	err = snd_msnd_dsp_full_reset(card);
 575	if (err < 0)
 576		goto err_release_region;
 577
 578	/* Register device */
 579	err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
 580	if (err < 0)
 581		goto err_release_region;
 582
 583	err = snd_msnd_pcm(card, 0, NULL);
 584	if (err < 0) {
 585		printk(KERN_ERR LOGNAME ": error creating new PCM device\n");
 586		goto err_release_region;
 587	}
 588
 589	err = snd_msndmix_new(card);
 590	if (err < 0) {
 591		printk(KERN_ERR LOGNAME ": error creating new Mixer device\n");
 592		goto err_release_region;
 593	}
 594
 595
 596	if (mpu_io[0] != SNDRV_AUTO_PORT) {
 597		struct snd_mpu401 *mpu;
 598
 599		err = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
 600					  mpu_io[0],
 601					  MPU401_MODE_INPUT |
 602					  MPU401_MODE_OUTPUT,
 603					  mpu_irq[0], IRQF_DISABLED,
 604					  &chip->rmidi);
 605		if (err < 0) {
 606			printk(KERN_ERR LOGNAME
 607				": error creating new Midi device\n");
 608			goto err_release_region;
 609		}
 610		mpu = chip->rmidi->private_data;
 611
 612		mpu->open_input = snd_msnd_mpu401_open;
 613		mpu->close_input = snd_msnd_mpu401_close;
 614		mpu->private_data = chip;
 615	}
 616
 617	disable_irq(chip->irq);
 618	snd_msnd_calibrate_adc(chip, chip->play_sample_rate);
 619	snd_msndmix_force_recsrc(chip, 0);
 620
 621	err = snd_card_register(card);
 622	if (err < 0)
 623		goto err_release_region;
 624
 625	return 0;
 626
 627err_release_region:
 628	if (chip->mappedbase)
 629		iounmap(chip->mappedbase);
 630	release_mem_region(chip->base, BUFFSIZE);
 631	release_region(chip->io, DSP_NUMIO);
 632	free_irq(chip->irq, chip);
 633	return err;
 634}
 635
 636
 637static void __devexit snd_msnd_unload(struct snd_card *card)
 638{
 639	struct snd_msnd *chip = card->private_data;
 640
 641	iounmap(chip->mappedbase);
 642	release_mem_region(chip->base, BUFFSIZE);
 643	release_region(chip->io, DSP_NUMIO);
 644	free_irq(chip->irq, chip);
 645	snd_card_free(card);
 646}
 647
 648#ifndef MSND_CLASSIC
 649
 650/* Pinnacle/Fiji Logical Device Configuration */
 651
 652static int __devinit snd_msnd_write_cfg(int cfg, int reg, int value)
 653{
 654	outb(reg, cfg);
 655	outb(value, cfg + 1);
 656	if (value != inb(cfg + 1)) {
 657		printk(KERN_ERR LOGNAME ": snd_msnd_write_cfg: I/O error\n");
 658		return -EIO;
 659	}
 660	return 0;
 661}
 662
 663static int __devinit snd_msnd_write_cfg_io0(int cfg, int num, u16 io)
 664{
 665	if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
 666		return -EIO;
 667	if (snd_msnd_write_cfg(cfg, IREG_IO0_BASEHI, HIBYTE(io)))
 668		return -EIO;
 669	if (snd_msnd_write_cfg(cfg, IREG_IO0_BASELO, LOBYTE(io)))
 670		return -EIO;
 671	return 0;
 672}
 673
 674static int __devinit snd_msnd_write_cfg_io1(int cfg, int num, u16 io)
 675{
 676	if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
 677		return -EIO;
 678	if (snd_msnd_write_cfg(cfg, IREG_IO1_BASEHI, HIBYTE(io)))
 679		return -EIO;
 680	if (snd_msnd_write_cfg(cfg, IREG_IO1_BASELO, LOBYTE(io)))
 681		return -EIO;
 682	return 0;
 683}
 684
 685static int __devinit snd_msnd_write_cfg_irq(int cfg, int num, u16 irq)
 686{
 687	if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
 688		return -EIO;
 689	if (snd_msnd_write_cfg(cfg, IREG_IRQ_NUMBER, LOBYTE(irq)))
 690		return -EIO;
 691	if (snd_msnd_write_cfg(cfg, IREG_IRQ_TYPE, IRQTYPE_EDGE))
 692		return -EIO;
 693	return 0;
 694}
 695
 696static int __devinit snd_msnd_write_cfg_mem(int cfg, int num, int mem)
 697{
 698	u16 wmem;
 699
 700	mem >>= 8;
 701	wmem = (u16)(mem & 0xfff);
 702	if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
 703		return -EIO;
 704	if (snd_msnd_write_cfg(cfg, IREG_MEMBASEHI, HIBYTE(wmem)))
 705		return -EIO;
 706	if (snd_msnd_write_cfg(cfg, IREG_MEMBASELO, LOBYTE(wmem)))
 707		return -EIO;
 708	if (wmem && snd_msnd_write_cfg(cfg, IREG_MEMCONTROL,
 709				       MEMTYPE_HIADDR | MEMTYPE_16BIT))
 710		return -EIO;
 711	return 0;
 712}
 713
 714static int __devinit snd_msnd_activate_logical(int cfg, int num)
 715{
 716	if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
 717		return -EIO;
 718	if (snd_msnd_write_cfg(cfg, IREG_ACTIVATE, LD_ACTIVATE))
 719		return -EIO;
 720	return 0;
 721}
 722
 723static int __devinit snd_msnd_write_cfg_logical(int cfg, int num, u16 io0,
 724						u16 io1, u16 irq, int mem)
 725{
 726	if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
 727		return -EIO;
 728	if (snd_msnd_write_cfg_io0(cfg, num, io0))
 729		return -EIO;
 730	if (snd_msnd_write_cfg_io1(cfg, num, io1))
 731		return -EIO;
 732	if (snd_msnd_write_cfg_irq(cfg, num, irq))
 733		return -EIO;
 734	if (snd_msnd_write_cfg_mem(cfg, num, mem))
 735		return -EIO;
 736	if (snd_msnd_activate_logical(cfg, num))
 737		return -EIO;
 738	return 0;
 739}
 740
 741static int __devinit snd_msnd_pinnacle_cfg_reset(int cfg)
 742{
 743	int i;
 744
 745	/* Reset devices if told to */
 746	printk(KERN_INFO LOGNAME ": Resetting all devices\n");
 747	for (i = 0; i < 4; ++i)
 748		if (snd_msnd_write_cfg_logical(cfg, i, 0, 0, 0, 0))
 749			return -EIO;
 750
 751	return 0;
 752}
 753#endif
 754
 755static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;	/* Index 0-MAX */
 756static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;	/* ID for this card */
 757
 758module_param_array(index, int, NULL, S_IRUGO);
 759MODULE_PARM_DESC(index, "Index value for msnd_pinnacle soundcard.");
 760module_param_array(id, charp, NULL, S_IRUGO);
 761MODULE_PARM_DESC(id, "ID string for msnd_pinnacle soundcard.");
 762
 763static long io[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
 764static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
 765static long mem[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
 766
 767#ifndef MSND_CLASSIC
 768static long cfg[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
 769
 770/* Extra Peripheral Configuration (Default: Disable) */
 771static long ide_io0[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
 772static long ide_io1[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
 773static int ide_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
 774
 775static long joystick_io[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
 776/* If we have the digital daugherboard... */
 777static int digital[SNDRV_CARDS];
 778
 779/* Extra Peripheral Configuration */
 780static int reset[SNDRV_CARDS];
 781#endif
 782
 783static int write_ndelay[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = 1 };
 784
 785static int calibrate_signal;
 786
 787#ifdef CONFIG_PNP
 788static int isapnp[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
 789module_param_array(isapnp, bool, NULL, 0444);
 790MODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard.");
 791#define has_isapnp(x) isapnp[x]
 792#else
 793#define has_isapnp(x) 0
 794#endif
 795
 796MODULE_AUTHOR("Karsten Wiese <annabellesgarden@yahoo.de>");
 797MODULE_DESCRIPTION("Turtle Beach " LONGNAME " Linux Driver");
 798MODULE_LICENSE("GPL");
 799MODULE_FIRMWARE(INITCODEFILE);
 800MODULE_FIRMWARE(PERMCODEFILE);
 801
 802module_param_array(io, long, NULL, S_IRUGO);
 803MODULE_PARM_DESC(io, "IO port #");
 804module_param_array(irq, int, NULL, S_IRUGO);
 805module_param_array(mem, long, NULL, S_IRUGO);
 806module_param_array(write_ndelay, int, NULL, S_IRUGO);
 807module_param(calibrate_signal, int, S_IRUGO);
 808#ifndef MSND_CLASSIC
 809module_param_array(digital, int, NULL, S_IRUGO);
 810module_param_array(cfg, long, NULL, S_IRUGO);
 811module_param_array(reset, int, 0, S_IRUGO);
 812module_param_array(mpu_io, long, NULL, S_IRUGO);
 813module_param_array(mpu_irq, int, NULL, S_IRUGO);
 814module_param_array(ide_io0, long, NULL, S_IRUGO);
 815module_param_array(ide_io1, long, NULL, S_IRUGO);
 816module_param_array(ide_irq, int, NULL, S_IRUGO);
 817module_param_array(joystick_io, long, NULL, S_IRUGO);
 818#endif
 819
 820
 821static int __devinit snd_msnd_isa_match(struct device *pdev, unsigned int i)
 822{
 823	if (io[i] == SNDRV_AUTO_PORT)
 824		return 0;
 825
 826	if (irq[i] == SNDRV_AUTO_PORT || mem[i] == SNDRV_AUTO_PORT) {
 827		printk(KERN_WARNING LOGNAME ": io, irq and mem must be set\n");
 828		return 0;
 829	}
 830
 831#ifdef MSND_CLASSIC
 832	if (!(io[i] == 0x290 ||
 833	      io[i] == 0x260 ||
 834	      io[i] == 0x250 ||
 835	      io[i] == 0x240 ||
 836	      io[i] == 0x230 ||
 837	      io[i] == 0x220 ||
 838	      io[i] == 0x210 ||
 839	      io[i] == 0x3e0)) {
 840		printk(KERN_ERR LOGNAME ": \"io\" - DSP I/O base must be set "
 841			" to 0x210, 0x220, 0x230, 0x240, 0x250, 0x260, 0x290, "
 842			"or 0x3E0\n");
 843		return 0;
 844	}
 845#else
 846	if (io[i] < 0x100 || io[i] > 0x3e0 || (io[i] % 0x10) != 0) {
 847		printk(KERN_ERR LOGNAME
 848			": \"io\" - DSP I/O base must within the range 0x100 "
 849			"to 0x3E0 and must be evenly divisible by 0x10\n");
 850		return 0;
 851	}
 852#endif /* MSND_CLASSIC */
 853
 854	if (!(irq[i] == 5 ||
 855	      irq[i] == 7 ||
 856	      irq[i] == 9 ||
 857	      irq[i] == 10 ||
 858	      irq[i] == 11 ||
 859	      irq[i] == 12)) {
 860		printk(KERN_ERR LOGNAME
 861			": \"irq\" - must be set to 5, 7, 9, 10, 11 or 12\n");
 862		return 0;
 863	}
 864
 865	if (!(mem[i] == 0xb0000 ||
 866	      mem[i] == 0xc8000 ||
 867	      mem[i] == 0xd0000 ||
 868	      mem[i] == 0xd8000 ||
 869	      mem[i] == 0xe0000 ||
 870	      mem[i] == 0xe8000)) {
 871		printk(KERN_ERR LOGNAME ": \"mem\" - must be set to "
 872		       "0xb0000, 0xc8000, 0xd0000, 0xd8000, 0xe0000 or "
 873		       "0xe8000\n");
 874		return 0;
 875	}
 876
 877#ifndef MSND_CLASSIC
 878	if (cfg[i] == SNDRV_AUTO_PORT) {
 879		printk(KERN_INFO LOGNAME ": Assuming PnP mode\n");
 880	} else if (cfg[i] != 0x250 && cfg[i] != 0x260 && cfg[i] != 0x270) {
 881		printk(KERN_INFO LOGNAME
 882			": Config port must be 0x250, 0x260 or 0x270 "
 883			"(or unspecified for PnP mode)\n");
 884		return 0;
 885	}
 886#endif /* MSND_CLASSIC */
 887
 888	return 1;
 889}
 890
 891static int __devinit snd_msnd_isa_probe(struct device *pdev, unsigned int idx)
 892{
 893	int err;
 894	struct snd_card *card;
 895	struct snd_msnd *chip;
 896
 897	if (has_isapnp(idx)
 898#ifndef MSND_CLASSIC
 899	    || cfg[idx] == SNDRV_AUTO_PORT
 900#endif
 901	    ) {
 902		printk(KERN_INFO LOGNAME ": Assuming PnP mode\n");
 903		return -ENODEV;
 904	}
 905
 906	err = snd_card_create(index[idx], id[idx], THIS_MODULE,
 907			      sizeof(struct snd_msnd), &card);
 908	if (err < 0)
 909		return err;
 910
 911	snd_card_set_dev(card, pdev);
 912	chip = card->private_data;
 913	chip->card = card;
 914
 915#ifdef MSND_CLASSIC
 916	switch (irq[idx]) {
 917	case 5:
 918		chip->irqid = HPIRQ_5; break;
 919	case 7:
 920		chip->irqid = HPIRQ_7; break;
 921	case 9:
 922		chip->irqid = HPIRQ_9; break;
 923	case 10:
 924		chip->irqid = HPIRQ_10; break;
 925	case 11:
 926		chip->irqid = HPIRQ_11; break;
 927	case 12:
 928		chip->irqid = HPIRQ_12; break;
 929	}
 930
 931	switch (mem[idx]) {
 932	case 0xb0000:
 933		chip->memid = HPMEM_B000; break;
 934	case 0xc8000:
 935		chip->memid = HPMEM_C800; break;
 936	case 0xd0000:
 937		chip->memid = HPMEM_D000; break;
 938	case 0xd8000:
 939		chip->memid = HPMEM_D800; break;
 940	case 0xe0000:
 941		chip->memid = HPMEM_E000; break;
 942	case 0xe8000:
 943		chip->memid = HPMEM_E800; break;
 944	}
 945#else
 946	printk(KERN_INFO LOGNAME ": Non-PnP mode: configuring at port 0x%lx\n",
 947			cfg[idx]);
 948
 949	if (!request_region(cfg[idx], 2, "Pinnacle/Fiji Config")) {
 950		printk(KERN_ERR LOGNAME ": Config port 0x%lx conflict\n",
 951			   cfg[idx]);
 952		snd_card_free(card);
 953		return -EIO;
 954	}
 955	if (reset[idx])
 956		if (snd_msnd_pinnacle_cfg_reset(cfg[idx])) {
 957			err = -EIO;
 958			goto cfg_error;
 959		}
 960
 961	/* DSP */
 962	err = snd_msnd_write_cfg_logical(cfg[idx], 0,
 963					 io[idx], 0,
 964					 irq[idx], mem[idx]);
 965
 966	if (err)
 967		goto cfg_error;
 968
 969	/* The following are Pinnacle specific */
 970
 971	/* MPU */
 972	if (mpu_io[idx] != SNDRV_AUTO_PORT
 973	    && mpu_irq[idx] != SNDRV_AUTO_IRQ) {
 974		printk(KERN_INFO LOGNAME
 975		       ": Configuring MPU to I/O 0x%lx IRQ %d\n",
 976		       mpu_io[idx], mpu_irq[idx]);
 977		err = snd_msnd_write_cfg_logical(cfg[idx], 1,
 978						 mpu_io[idx], 0,
 979						 mpu_irq[idx], 0);
 980
 981		if (err)
 982			goto cfg_error;
 983	}
 984
 985	/* IDE */
 986	if (ide_io0[idx] != SNDRV_AUTO_PORT
 987	    && ide_io1[idx] != SNDRV_AUTO_PORT
 988	    && ide_irq[idx] != SNDRV_AUTO_IRQ) {
 989		printk(KERN_INFO LOGNAME
 990		       ": Configuring IDE to I/O 0x%lx, 0x%lx IRQ %d\n",
 991		       ide_io0[idx], ide_io1[idx], ide_irq[idx]);
 992		err = snd_msnd_write_cfg_logical(cfg[idx], 2,
 993						 ide_io0[idx], ide_io1[idx],
 994						 ide_irq[idx], 0);
 995
 996		if (err)
 997			goto cfg_error;
 998	}
 999
1000	/* Joystick */
1001	if (joystick_io[idx] != SNDRV_AUTO_PORT) {
1002		printk(KERN_INFO LOGNAME
1003		       ": Configuring joystick to I/O 0x%lx\n",
1004		       joystick_io[idx]);
1005		err = snd_msnd_write_cfg_logical(cfg[idx], 3,
1006						 joystick_io[idx], 0,
1007						 0, 0);
1008
1009		if (err)
1010			goto cfg_error;
1011	}
1012	release_region(cfg[idx], 2);
1013
1014#endif /* MSND_CLASSIC */
1015
1016	set_default_audio_parameters(chip);
1017#ifdef MSND_CLASSIC
1018	chip->type = msndClassic;
1019#else
1020	chip->type = msndPinnacle;
1021#endif
1022	chip->io = io[idx];
1023	chip->irq = irq[idx];
1024	chip->base = mem[idx];
1025
1026	chip->calibrate_signal = calibrate_signal ? 1 : 0;
1027	chip->recsrc = 0;
1028	chip->dspq_data_buff = DSPQ_DATA_BUFF;
1029	chip->dspq_buff_size = DSPQ_BUFF_SIZE;
1030	if (write_ndelay[idx])
1031		clear_bit(F_DISABLE_WRITE_NDELAY, &chip->flags);
1032	else
1033		set_bit(F_DISABLE_WRITE_NDELAY, &chip->flags);
1034#ifndef MSND_CLASSIC
1035	if (digital[idx])
1036		set_bit(F_HAVEDIGITAL, &chip->flags);
1037#endif
1038	spin_lock_init(&chip->lock);
1039	err = snd_msnd_probe(card);
1040	if (err < 0) {
1041		printk(KERN_ERR LOGNAME ": Probe failed\n");
1042		snd_card_free(card);
1043		return err;
1044	}
1045
1046	err = snd_msnd_attach(card);
1047	if (err < 0) {
1048		printk(KERN_ERR LOGNAME ": Attach failed\n");
1049		snd_card_free(card);
1050		return err;
1051	}
1052	dev_set_drvdata(pdev, card);
1053
1054	return 0;
1055
1056#ifndef MSND_CLASSIC
1057cfg_error:
1058	release_region(cfg[idx], 2);
1059	snd_card_free(card);
1060	return err;
1061#endif
1062}
1063
1064static int __devexit snd_msnd_isa_remove(struct device *pdev, unsigned int dev)
1065{
1066	snd_msnd_unload(dev_get_drvdata(pdev));
1067	dev_set_drvdata(pdev, NULL);
1068	return 0;
1069}
1070
1071#define DEV_NAME "msnd-pinnacle"
1072
1073static struct isa_driver snd_msnd_driver = {
1074	.match		= snd_msnd_isa_match,
1075	.probe		= snd_msnd_isa_probe,
1076	.remove		= __devexit_p(snd_msnd_isa_remove),
1077	/* FIXME: suspend, resume */
1078	.driver		= {
1079		.name	= DEV_NAME
1080	},
1081};
1082
1083#ifdef CONFIG_PNP
1084static int __devinit snd_msnd_pnp_detect(struct pnp_card_link *pcard,
1085					 const struct pnp_card_device_id *pid)
1086{
1087	static int idx;
1088	struct pnp_dev *pnp_dev;
1089	struct pnp_dev *mpu_dev;
1090	struct snd_card *card;
1091	struct snd_msnd *chip;
1092	int ret;
1093
1094	for ( ; idx < SNDRV_CARDS; idx++) {
1095		if (has_isapnp(idx))
1096			break;
1097	}
1098	if (idx >= SNDRV_CARDS)
1099		return -ENODEV;
1100
1101	/*
1102	 * Check that we still have room for another sound card ...
1103	 */
1104	pnp_dev = pnp_request_card_device(pcard, pid->devs[0].id, NULL);
1105	if (!pnp_dev)
1106		return -ENODEV;
1107
1108	mpu_dev = pnp_request_card_device(pcard, pid->devs[1].id, NULL);
1109	if (!mpu_dev)
1110		return -ENODEV;
1111
1112	if (!pnp_is_active(pnp_dev) && pnp_activate_dev(pnp_dev) < 0) {
1113		printk(KERN_INFO "msnd_pinnacle: device is inactive\n");
1114		return -EBUSY;
1115	}
1116
1117	if (!pnp_is_active(mpu_dev) && pnp_activate_dev(mpu_dev) < 0) {
1118		printk(KERN_INFO "msnd_pinnacle: MPU device is inactive\n");
1119		return -EBUSY;
1120	}
1121
1122	/*
1123	 * Create a new ALSA sound card entry, in anticipation
1124	 * of detecting our hardware ...
1125	 */
1126	ret = snd_card_create(index[idx], id[idx], THIS_MODULE,
1127			      sizeof(struct snd_msnd), &card);
 
1128	if (ret < 0)
1129		return ret;
1130
1131	chip = card->private_data;
1132	chip->card = card;
1133	snd_card_set_dev(card, &pcard->card->dev);
1134
1135	/*
1136	 * Read the correct parameters off the ISA PnP bus ...
1137	 */
1138	io[idx] = pnp_port_start(pnp_dev, 0);
1139	irq[idx] = pnp_irq(pnp_dev, 0);
1140	mem[idx] = pnp_mem_start(pnp_dev, 0);
1141	mpu_io[idx] = pnp_port_start(mpu_dev, 0);
1142	mpu_irq[idx] = pnp_irq(mpu_dev, 0);
1143
1144	set_default_audio_parameters(chip);
1145#ifdef MSND_CLASSIC
1146	chip->type = msndClassic;
1147#else
1148	chip->type = msndPinnacle;
1149#endif
1150	chip->io = io[idx];
1151	chip->irq = irq[idx];
1152	chip->base = mem[idx];
1153
1154	chip->calibrate_signal = calibrate_signal ? 1 : 0;
1155	chip->recsrc = 0;
1156	chip->dspq_data_buff = DSPQ_DATA_BUFF;
1157	chip->dspq_buff_size = DSPQ_BUFF_SIZE;
1158	if (write_ndelay[idx])
1159		clear_bit(F_DISABLE_WRITE_NDELAY, &chip->flags);
1160	else
1161		set_bit(F_DISABLE_WRITE_NDELAY, &chip->flags);
1162#ifndef MSND_CLASSIC
1163	if (digital[idx])
1164		set_bit(F_HAVEDIGITAL, &chip->flags);
1165#endif
1166	spin_lock_init(&chip->lock);
1167	ret = snd_msnd_probe(card);
1168	if (ret < 0) {
1169		printk(KERN_ERR LOGNAME ": Probe failed\n");
1170		goto _release_card;
1171	}
1172
1173	ret = snd_msnd_attach(card);
1174	if (ret < 0) {
1175		printk(KERN_ERR LOGNAME ": Attach failed\n");
1176		goto _release_card;
1177	}
1178
1179	pnp_set_card_drvdata(pcard, card);
1180	++idx;
1181	return 0;
1182
1183_release_card:
1184	snd_card_free(card);
1185	return ret;
1186}
1187
1188static void __devexit snd_msnd_pnp_remove(struct pnp_card_link *pcard)
1189{
1190	snd_msnd_unload(pnp_get_card_drvdata(pcard));
1191	pnp_set_card_drvdata(pcard, NULL);
1192}
1193
1194static int isa_registered;
1195static int pnp_registered;
1196
1197static struct pnp_card_device_id msnd_pnpids[] = {
1198	/* Pinnacle PnP */
1199	{ .id = "BVJ0440", .devs = { { "TBS0000" }, { "TBS0001" } } },
1200	{ .id = "" }	/* end */
1201};
1202
1203MODULE_DEVICE_TABLE(pnp_card, msnd_pnpids);
1204
1205static struct pnp_card_driver msnd_pnpc_driver = {
1206	.flags = PNP_DRIVER_RES_DO_NOT_CHANGE,
1207	.name = "msnd_pinnacle",
1208	.id_table = msnd_pnpids,
1209	.probe = snd_msnd_pnp_detect,
1210	.remove = __devexit_p(snd_msnd_pnp_remove),
1211};
1212#endif /* CONFIG_PNP */
1213
1214static int __init snd_msnd_init(void)
1215{
1216	int err;
1217
1218	err = isa_register_driver(&snd_msnd_driver, SNDRV_CARDS);
1219#ifdef CONFIG_PNP
1220	if (!err)
1221		isa_registered = 1;
1222
1223	err = pnp_register_card_driver(&msnd_pnpc_driver);
1224	if (!err)
1225		pnp_registered = 1;
1226
1227	if (isa_registered)
1228		err = 0;
1229#endif
1230	return err;
1231}
1232
1233static void __exit snd_msnd_exit(void)
1234{
1235#ifdef CONFIG_PNP
1236	if (pnp_registered)
1237		pnp_unregister_card_driver(&msnd_pnpc_driver);
1238	if (isa_registered)
1239#endif
1240		isa_unregister_driver(&snd_msnd_driver);
1241}
1242
1243module_init(snd_msnd_init);
1244module_exit(snd_msnd_exit);
1245