18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/********************************************************************* 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Linux multisound pinnacle/fiji driver for ALSA. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * 2002/06/30 Karsten Wiese: 78c2ecf20Sopenharmony_ci * for now this is only used to build a pinnacle / fiji driver. 88c2ecf20Sopenharmony_ci * the OSS parent of this code is designed to also support 98c2ecf20Sopenharmony_ci * the multisound classic via the file msnd_classic.c. 108c2ecf20Sopenharmony_ci * to make it easier for some brave heart to implemt classic 118c2ecf20Sopenharmony_ci * support in alsa, i left all the MSND_CLASSIC tokens in this file. 128c2ecf20Sopenharmony_ci * but for now this untested & undone. 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci * ripped from linux kernel 2.4.18 by Karsten Wiese. 158c2ecf20Sopenharmony_ci * 168c2ecf20Sopenharmony_ci * the following is a copy of the 2.4.18 OSS FREE file-heading comment: 178c2ecf20Sopenharmony_ci * 188c2ecf20Sopenharmony_ci * Turtle Beach MultiSound Sound Card Driver for Linux 198c2ecf20Sopenharmony_ci * msnd_pinnacle.c / msnd_classic.c 208c2ecf20Sopenharmony_ci * 218c2ecf20Sopenharmony_ci * -- If MSND_CLASSIC is defined: 228c2ecf20Sopenharmony_ci * 238c2ecf20Sopenharmony_ci * -> driver for Turtle Beach Classic/Monterey/Tahiti 248c2ecf20Sopenharmony_ci * 258c2ecf20Sopenharmony_ci * -- Else 268c2ecf20Sopenharmony_ci * 278c2ecf20Sopenharmony_ci * -> driver for Turtle Beach Pinnacle/Fiji 288c2ecf20Sopenharmony_ci * 298c2ecf20Sopenharmony_ci * 12-3-2000 Modified IO port validation Steve Sycamore 308c2ecf20Sopenharmony_ci * 318c2ecf20Sopenharmony_ci * Copyright (C) 1998 Andrew Veliath 328c2ecf20Sopenharmony_ci * 338c2ecf20Sopenharmony_ci ********************************************************************/ 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#include <linux/kernel.h> 368c2ecf20Sopenharmony_ci#include <linux/module.h> 378c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 388c2ecf20Sopenharmony_ci#include <linux/types.h> 398c2ecf20Sopenharmony_ci#include <linux/delay.h> 408c2ecf20Sopenharmony_ci#include <linux/ioport.h> 418c2ecf20Sopenharmony_ci#include <linux/firmware.h> 428c2ecf20Sopenharmony_ci#include <linux/isa.h> 438c2ecf20Sopenharmony_ci#include <linux/isapnp.h> 448c2ecf20Sopenharmony_ci#include <linux/irq.h> 458c2ecf20Sopenharmony_ci#include <linux/io.h> 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci#include <sound/core.h> 488c2ecf20Sopenharmony_ci#include <sound/initval.h> 498c2ecf20Sopenharmony_ci#include <sound/asound.h> 508c2ecf20Sopenharmony_ci#include <sound/pcm.h> 518c2ecf20Sopenharmony_ci#include <sound/mpu401.h> 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci#ifdef MSND_CLASSIC 548c2ecf20Sopenharmony_ci# ifndef __alpha__ 558c2ecf20Sopenharmony_ci# define SLOWIO 568c2ecf20Sopenharmony_ci# endif 578c2ecf20Sopenharmony_ci#endif 588c2ecf20Sopenharmony_ci#include "msnd.h" 598c2ecf20Sopenharmony_ci#ifdef MSND_CLASSIC 608c2ecf20Sopenharmony_ci# include "msnd_classic.h" 618c2ecf20Sopenharmony_ci# define LOGNAME "msnd_classic" 628c2ecf20Sopenharmony_ci# define DEV_NAME "msnd-classic" 638c2ecf20Sopenharmony_ci#else 648c2ecf20Sopenharmony_ci# include "msnd_pinnacle.h" 658c2ecf20Sopenharmony_ci# define LOGNAME "snd_msnd_pinnacle" 668c2ecf20Sopenharmony_ci# define DEV_NAME "msnd-pinnacle" 678c2ecf20Sopenharmony_ci#endif 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_cistatic void set_default_audio_parameters(struct snd_msnd *chip) 708c2ecf20Sopenharmony_ci{ 718c2ecf20Sopenharmony_ci chip->play_sample_size = snd_pcm_format_width(DEFSAMPLESIZE); 728c2ecf20Sopenharmony_ci chip->play_sample_rate = DEFSAMPLERATE; 738c2ecf20Sopenharmony_ci chip->play_channels = DEFCHANNELS; 748c2ecf20Sopenharmony_ci chip->capture_sample_size = snd_pcm_format_width(DEFSAMPLESIZE); 758c2ecf20Sopenharmony_ci chip->capture_sample_rate = DEFSAMPLERATE; 768c2ecf20Sopenharmony_ci chip->capture_channels = DEFCHANNELS; 778c2ecf20Sopenharmony_ci} 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_cistatic void snd_msnd_eval_dsp_msg(struct snd_msnd *chip, u16 wMessage) 808c2ecf20Sopenharmony_ci{ 818c2ecf20Sopenharmony_ci switch (HIBYTE(wMessage)) { 828c2ecf20Sopenharmony_ci case HIMT_PLAY_DONE: { 838c2ecf20Sopenharmony_ci if (chip->banksPlayed < 3) 848c2ecf20Sopenharmony_ci snd_printdd("%08X: HIMT_PLAY_DONE: %i\n", 858c2ecf20Sopenharmony_ci (unsigned)jiffies, LOBYTE(wMessage)); 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci if (chip->last_playbank == LOBYTE(wMessage)) { 888c2ecf20Sopenharmony_ci snd_printdd("chip.last_playbank == LOBYTE(wMessage)\n"); 898c2ecf20Sopenharmony_ci break; 908c2ecf20Sopenharmony_ci } 918c2ecf20Sopenharmony_ci chip->banksPlayed++; 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci if (test_bit(F_WRITING, &chip->flags)) 948c2ecf20Sopenharmony_ci snd_msnd_DAPQ(chip, 0); 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci chip->last_playbank = LOBYTE(wMessage); 978c2ecf20Sopenharmony_ci chip->playDMAPos += chip->play_period_bytes; 988c2ecf20Sopenharmony_ci if (chip->playDMAPos > chip->playLimit) 998c2ecf20Sopenharmony_ci chip->playDMAPos = 0; 1008c2ecf20Sopenharmony_ci snd_pcm_period_elapsed(chip->playback_substream); 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci break; 1038c2ecf20Sopenharmony_ci } 1048c2ecf20Sopenharmony_ci case HIMT_RECORD_DONE: 1058c2ecf20Sopenharmony_ci if (chip->last_recbank == LOBYTE(wMessage)) 1068c2ecf20Sopenharmony_ci break; 1078c2ecf20Sopenharmony_ci chip->last_recbank = LOBYTE(wMessage); 1088c2ecf20Sopenharmony_ci chip->captureDMAPos += chip->capturePeriodBytes; 1098c2ecf20Sopenharmony_ci if (chip->captureDMAPos > (chip->captureLimit)) 1108c2ecf20Sopenharmony_ci chip->captureDMAPos = 0; 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci if (test_bit(F_READING, &chip->flags)) 1138c2ecf20Sopenharmony_ci snd_msnd_DARQ(chip, chip->last_recbank); 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci snd_pcm_period_elapsed(chip->capture_substream); 1168c2ecf20Sopenharmony_ci break; 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci case HIMT_DSP: 1198c2ecf20Sopenharmony_ci switch (LOBYTE(wMessage)) { 1208c2ecf20Sopenharmony_ci#ifndef MSND_CLASSIC 1218c2ecf20Sopenharmony_ci case HIDSP_PLAY_UNDER: 1228c2ecf20Sopenharmony_ci#endif 1238c2ecf20Sopenharmony_ci case HIDSP_INT_PLAY_UNDER: 1248c2ecf20Sopenharmony_ci snd_printd(KERN_WARNING LOGNAME ": Play underflow %i\n", 1258c2ecf20Sopenharmony_ci chip->banksPlayed); 1268c2ecf20Sopenharmony_ci if (chip->banksPlayed > 2) 1278c2ecf20Sopenharmony_ci clear_bit(F_WRITING, &chip->flags); 1288c2ecf20Sopenharmony_ci break; 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci case HIDSP_INT_RECORD_OVER: 1318c2ecf20Sopenharmony_ci snd_printd(KERN_WARNING LOGNAME ": Record overflow\n"); 1328c2ecf20Sopenharmony_ci clear_bit(F_READING, &chip->flags); 1338c2ecf20Sopenharmony_ci break; 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci default: 1368c2ecf20Sopenharmony_ci snd_printd(KERN_WARNING LOGNAME 1378c2ecf20Sopenharmony_ci ": DSP message %d 0x%02x\n", 1388c2ecf20Sopenharmony_ci LOBYTE(wMessage), LOBYTE(wMessage)); 1398c2ecf20Sopenharmony_ci break; 1408c2ecf20Sopenharmony_ci } 1418c2ecf20Sopenharmony_ci break; 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci case HIMT_MIDI_IN_UCHAR: 1448c2ecf20Sopenharmony_ci if (chip->msndmidi_mpu) 1458c2ecf20Sopenharmony_ci snd_msndmidi_input_read(chip->msndmidi_mpu); 1468c2ecf20Sopenharmony_ci break; 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci default: 1498c2ecf20Sopenharmony_ci snd_printd(KERN_WARNING LOGNAME ": HIMT message %d 0x%02x\n", 1508c2ecf20Sopenharmony_ci HIBYTE(wMessage), HIBYTE(wMessage)); 1518c2ecf20Sopenharmony_ci break; 1528c2ecf20Sopenharmony_ci } 1538c2ecf20Sopenharmony_ci} 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_cistatic irqreturn_t snd_msnd_interrupt(int irq, void *dev_id) 1568c2ecf20Sopenharmony_ci{ 1578c2ecf20Sopenharmony_ci struct snd_msnd *chip = dev_id; 1588c2ecf20Sopenharmony_ci void __iomem *pwDSPQData = chip->mappedbase + DSPQ_DATA_BUFF; 1598c2ecf20Sopenharmony_ci u16 head, tail, size; 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ci /* Send ack to DSP */ 1628c2ecf20Sopenharmony_ci /* inb(chip->io + HP_RXL); */ 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci /* Evaluate queued DSP messages */ 1658c2ecf20Sopenharmony_ci head = readw(chip->DSPQ + JQS_wHead); 1668c2ecf20Sopenharmony_ci tail = readw(chip->DSPQ + JQS_wTail); 1678c2ecf20Sopenharmony_ci size = readw(chip->DSPQ + JQS_wSize); 1688c2ecf20Sopenharmony_ci if (head > size || tail > size) 1698c2ecf20Sopenharmony_ci goto out; 1708c2ecf20Sopenharmony_ci while (head != tail) { 1718c2ecf20Sopenharmony_ci snd_msnd_eval_dsp_msg(chip, readw(pwDSPQData + 2 * head)); 1728c2ecf20Sopenharmony_ci if (++head > size) 1738c2ecf20Sopenharmony_ci head = 0; 1748c2ecf20Sopenharmony_ci writew(head, chip->DSPQ + JQS_wHead); 1758c2ecf20Sopenharmony_ci } 1768c2ecf20Sopenharmony_ci out: 1778c2ecf20Sopenharmony_ci /* Send ack to DSP */ 1788c2ecf20Sopenharmony_ci inb(chip->io + HP_RXL); 1798c2ecf20Sopenharmony_ci return IRQ_HANDLED; 1808c2ecf20Sopenharmony_ci} 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_cistatic int snd_msnd_reset_dsp(long io, unsigned char *info) 1848c2ecf20Sopenharmony_ci{ 1858c2ecf20Sopenharmony_ci int timeout = 100; 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ci outb(HPDSPRESET_ON, io + HP_DSPR); 1888c2ecf20Sopenharmony_ci msleep(1); 1898c2ecf20Sopenharmony_ci#ifndef MSND_CLASSIC 1908c2ecf20Sopenharmony_ci if (info) 1918c2ecf20Sopenharmony_ci *info = inb(io + HP_INFO); 1928c2ecf20Sopenharmony_ci#endif 1938c2ecf20Sopenharmony_ci outb(HPDSPRESET_OFF, io + HP_DSPR); 1948c2ecf20Sopenharmony_ci msleep(1); 1958c2ecf20Sopenharmony_ci while (timeout-- > 0) { 1968c2ecf20Sopenharmony_ci if (inb(io + HP_CVR) == HP_CVR_DEF) 1978c2ecf20Sopenharmony_ci return 0; 1988c2ecf20Sopenharmony_ci msleep(1); 1998c2ecf20Sopenharmony_ci } 2008c2ecf20Sopenharmony_ci snd_printk(KERN_ERR LOGNAME ": Cannot reset DSP\n"); 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_ci return -EIO; 2038c2ecf20Sopenharmony_ci} 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_cistatic int snd_msnd_probe(struct snd_card *card) 2068c2ecf20Sopenharmony_ci{ 2078c2ecf20Sopenharmony_ci struct snd_msnd *chip = card->private_data; 2088c2ecf20Sopenharmony_ci unsigned char info; 2098c2ecf20Sopenharmony_ci#ifndef MSND_CLASSIC 2108c2ecf20Sopenharmony_ci char *xv, *rev = NULL; 2118c2ecf20Sopenharmony_ci char *pin = "TB Pinnacle", *fiji = "TB Fiji"; 2128c2ecf20Sopenharmony_ci char *pinfiji = "TB Pinnacle/Fiji"; 2138c2ecf20Sopenharmony_ci#endif 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ci if (!request_region(chip->io, DSP_NUMIO, "probing")) { 2168c2ecf20Sopenharmony_ci snd_printk(KERN_ERR LOGNAME ": I/O port conflict\n"); 2178c2ecf20Sopenharmony_ci return -ENODEV; 2188c2ecf20Sopenharmony_ci } 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci if (snd_msnd_reset_dsp(chip->io, &info) < 0) { 2218c2ecf20Sopenharmony_ci release_region(chip->io, DSP_NUMIO); 2228c2ecf20Sopenharmony_ci return -ENODEV; 2238c2ecf20Sopenharmony_ci } 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_ci#ifdef MSND_CLASSIC 2268c2ecf20Sopenharmony_ci strcpy(card->shortname, "Classic/Tahiti/Monterey"); 2278c2ecf20Sopenharmony_ci strcpy(card->longname, "Turtle Beach Multisound"); 2288c2ecf20Sopenharmony_ci printk(KERN_INFO LOGNAME ": %s, " 2298c2ecf20Sopenharmony_ci "I/O 0x%lx-0x%lx, IRQ %d, memory mapped to 0x%lX-0x%lX\n", 2308c2ecf20Sopenharmony_ci card->shortname, 2318c2ecf20Sopenharmony_ci chip->io, chip->io + DSP_NUMIO - 1, 2328c2ecf20Sopenharmony_ci chip->irq, 2338c2ecf20Sopenharmony_ci chip->base, chip->base + 0x7fff); 2348c2ecf20Sopenharmony_ci#else 2358c2ecf20Sopenharmony_ci switch (info >> 4) { 2368c2ecf20Sopenharmony_ci case 0xf: 2378c2ecf20Sopenharmony_ci xv = "<= 1.15"; 2388c2ecf20Sopenharmony_ci break; 2398c2ecf20Sopenharmony_ci case 0x1: 2408c2ecf20Sopenharmony_ci xv = "1.18/1.2"; 2418c2ecf20Sopenharmony_ci break; 2428c2ecf20Sopenharmony_ci case 0x2: 2438c2ecf20Sopenharmony_ci xv = "1.3"; 2448c2ecf20Sopenharmony_ci break; 2458c2ecf20Sopenharmony_ci case 0x3: 2468c2ecf20Sopenharmony_ci xv = "1.4"; 2478c2ecf20Sopenharmony_ci break; 2488c2ecf20Sopenharmony_ci default: 2498c2ecf20Sopenharmony_ci xv = "unknown"; 2508c2ecf20Sopenharmony_ci break; 2518c2ecf20Sopenharmony_ci } 2528c2ecf20Sopenharmony_ci 2538c2ecf20Sopenharmony_ci switch (info & 0x7) { 2548c2ecf20Sopenharmony_ci case 0x0: 2558c2ecf20Sopenharmony_ci rev = "I"; 2568c2ecf20Sopenharmony_ci strcpy(card->shortname, pin); 2578c2ecf20Sopenharmony_ci break; 2588c2ecf20Sopenharmony_ci case 0x1: 2598c2ecf20Sopenharmony_ci rev = "F"; 2608c2ecf20Sopenharmony_ci strcpy(card->shortname, pin); 2618c2ecf20Sopenharmony_ci break; 2628c2ecf20Sopenharmony_ci case 0x2: 2638c2ecf20Sopenharmony_ci rev = "G"; 2648c2ecf20Sopenharmony_ci strcpy(card->shortname, pin); 2658c2ecf20Sopenharmony_ci break; 2668c2ecf20Sopenharmony_ci case 0x3: 2678c2ecf20Sopenharmony_ci rev = "H"; 2688c2ecf20Sopenharmony_ci strcpy(card->shortname, pin); 2698c2ecf20Sopenharmony_ci break; 2708c2ecf20Sopenharmony_ci case 0x4: 2718c2ecf20Sopenharmony_ci rev = "E"; 2728c2ecf20Sopenharmony_ci strcpy(card->shortname, fiji); 2738c2ecf20Sopenharmony_ci break; 2748c2ecf20Sopenharmony_ci case 0x5: 2758c2ecf20Sopenharmony_ci rev = "C"; 2768c2ecf20Sopenharmony_ci strcpy(card->shortname, fiji); 2778c2ecf20Sopenharmony_ci break; 2788c2ecf20Sopenharmony_ci case 0x6: 2798c2ecf20Sopenharmony_ci rev = "D"; 2808c2ecf20Sopenharmony_ci strcpy(card->shortname, fiji); 2818c2ecf20Sopenharmony_ci break; 2828c2ecf20Sopenharmony_ci case 0x7: 2838c2ecf20Sopenharmony_ci rev = "A-B (Fiji) or A-E (Pinnacle)"; 2848c2ecf20Sopenharmony_ci strcpy(card->shortname, pinfiji); 2858c2ecf20Sopenharmony_ci break; 2868c2ecf20Sopenharmony_ci } 2878c2ecf20Sopenharmony_ci strcpy(card->longname, "Turtle Beach Multisound Pinnacle"); 2888c2ecf20Sopenharmony_ci printk(KERN_INFO LOGNAME ": %s revision %s, Xilinx version %s, " 2898c2ecf20Sopenharmony_ci "I/O 0x%lx-0x%lx, IRQ %d, memory mapped to 0x%lX-0x%lX\n", 2908c2ecf20Sopenharmony_ci card->shortname, 2918c2ecf20Sopenharmony_ci rev, xv, 2928c2ecf20Sopenharmony_ci chip->io, chip->io + DSP_NUMIO - 1, 2938c2ecf20Sopenharmony_ci chip->irq, 2948c2ecf20Sopenharmony_ci chip->base, chip->base + 0x7fff); 2958c2ecf20Sopenharmony_ci#endif 2968c2ecf20Sopenharmony_ci 2978c2ecf20Sopenharmony_ci release_region(chip->io, DSP_NUMIO); 2988c2ecf20Sopenharmony_ci return 0; 2998c2ecf20Sopenharmony_ci} 3008c2ecf20Sopenharmony_ci 3018c2ecf20Sopenharmony_cistatic int snd_msnd_init_sma(struct snd_msnd *chip) 3028c2ecf20Sopenharmony_ci{ 3038c2ecf20Sopenharmony_ci static int initted; 3048c2ecf20Sopenharmony_ci u16 mastVolLeft, mastVolRight; 3058c2ecf20Sopenharmony_ci unsigned long flags; 3068c2ecf20Sopenharmony_ci 3078c2ecf20Sopenharmony_ci#ifdef MSND_CLASSIC 3088c2ecf20Sopenharmony_ci outb(chip->memid, chip->io + HP_MEMM); 3098c2ecf20Sopenharmony_ci#endif 3108c2ecf20Sopenharmony_ci outb(HPBLKSEL_0, chip->io + HP_BLKS); 3118c2ecf20Sopenharmony_ci /* Motorola 56k shared memory base */ 3128c2ecf20Sopenharmony_ci chip->SMA = chip->mappedbase + SMA_STRUCT_START; 3138c2ecf20Sopenharmony_ci 3148c2ecf20Sopenharmony_ci if (initted) { 3158c2ecf20Sopenharmony_ci mastVolLeft = readw(chip->SMA + SMA_wCurrMastVolLeft); 3168c2ecf20Sopenharmony_ci mastVolRight = readw(chip->SMA + SMA_wCurrMastVolRight); 3178c2ecf20Sopenharmony_ci } else 3188c2ecf20Sopenharmony_ci mastVolLeft = mastVolRight = 0; 3198c2ecf20Sopenharmony_ci memset_io(chip->mappedbase, 0, 0x8000); 3208c2ecf20Sopenharmony_ci 3218c2ecf20Sopenharmony_ci /* Critical section: bank 1 access */ 3228c2ecf20Sopenharmony_ci spin_lock_irqsave(&chip->lock, flags); 3238c2ecf20Sopenharmony_ci outb(HPBLKSEL_1, chip->io + HP_BLKS); 3248c2ecf20Sopenharmony_ci memset_io(chip->mappedbase, 0, 0x8000); 3258c2ecf20Sopenharmony_ci outb(HPBLKSEL_0, chip->io + HP_BLKS); 3268c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&chip->lock, flags); 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_ci /* Digital audio play queue */ 3298c2ecf20Sopenharmony_ci chip->DAPQ = chip->mappedbase + DAPQ_OFFSET; 3308c2ecf20Sopenharmony_ci snd_msnd_init_queue(chip->DAPQ, DAPQ_DATA_BUFF, DAPQ_BUFF_SIZE); 3318c2ecf20Sopenharmony_ci 3328c2ecf20Sopenharmony_ci /* Digital audio record queue */ 3338c2ecf20Sopenharmony_ci chip->DARQ = chip->mappedbase + DARQ_OFFSET; 3348c2ecf20Sopenharmony_ci snd_msnd_init_queue(chip->DARQ, DARQ_DATA_BUFF, DARQ_BUFF_SIZE); 3358c2ecf20Sopenharmony_ci 3368c2ecf20Sopenharmony_ci /* MIDI out queue */ 3378c2ecf20Sopenharmony_ci chip->MODQ = chip->mappedbase + MODQ_OFFSET; 3388c2ecf20Sopenharmony_ci snd_msnd_init_queue(chip->MODQ, MODQ_DATA_BUFF, MODQ_BUFF_SIZE); 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_ci /* MIDI in queue */ 3418c2ecf20Sopenharmony_ci chip->MIDQ = chip->mappedbase + MIDQ_OFFSET; 3428c2ecf20Sopenharmony_ci snd_msnd_init_queue(chip->MIDQ, MIDQ_DATA_BUFF, MIDQ_BUFF_SIZE); 3438c2ecf20Sopenharmony_ci 3448c2ecf20Sopenharmony_ci /* DSP -> host message queue */ 3458c2ecf20Sopenharmony_ci chip->DSPQ = chip->mappedbase + DSPQ_OFFSET; 3468c2ecf20Sopenharmony_ci snd_msnd_init_queue(chip->DSPQ, DSPQ_DATA_BUFF, DSPQ_BUFF_SIZE); 3478c2ecf20Sopenharmony_ci 3488c2ecf20Sopenharmony_ci /* Setup some DSP values */ 3498c2ecf20Sopenharmony_ci#ifndef MSND_CLASSIC 3508c2ecf20Sopenharmony_ci writew(1, chip->SMA + SMA_wCurrPlayFormat); 3518c2ecf20Sopenharmony_ci writew(chip->play_sample_size, chip->SMA + SMA_wCurrPlaySampleSize); 3528c2ecf20Sopenharmony_ci writew(chip->play_channels, chip->SMA + SMA_wCurrPlayChannels); 3538c2ecf20Sopenharmony_ci writew(chip->play_sample_rate, chip->SMA + SMA_wCurrPlaySampleRate); 3548c2ecf20Sopenharmony_ci#endif 3558c2ecf20Sopenharmony_ci writew(chip->play_sample_rate, chip->SMA + SMA_wCalFreqAtoD); 3568c2ecf20Sopenharmony_ci writew(mastVolLeft, chip->SMA + SMA_wCurrMastVolLeft); 3578c2ecf20Sopenharmony_ci writew(mastVolRight, chip->SMA + SMA_wCurrMastVolRight); 3588c2ecf20Sopenharmony_ci#ifndef MSND_CLASSIC 3598c2ecf20Sopenharmony_ci writel(0x00010000, chip->SMA + SMA_dwCurrPlayPitch); 3608c2ecf20Sopenharmony_ci writel(0x00000001, chip->SMA + SMA_dwCurrPlayRate); 3618c2ecf20Sopenharmony_ci#endif 3628c2ecf20Sopenharmony_ci writew(0x303, chip->SMA + SMA_wCurrInputTagBits); 3638c2ecf20Sopenharmony_ci 3648c2ecf20Sopenharmony_ci initted = 1; 3658c2ecf20Sopenharmony_ci 3668c2ecf20Sopenharmony_ci return 0; 3678c2ecf20Sopenharmony_ci} 3688c2ecf20Sopenharmony_ci 3698c2ecf20Sopenharmony_ci 3708c2ecf20Sopenharmony_cistatic int upload_dsp_code(struct snd_card *card) 3718c2ecf20Sopenharmony_ci{ 3728c2ecf20Sopenharmony_ci struct snd_msnd *chip = card->private_data; 3738c2ecf20Sopenharmony_ci const struct firmware *init_fw = NULL, *perm_fw = NULL; 3748c2ecf20Sopenharmony_ci int err; 3758c2ecf20Sopenharmony_ci 3768c2ecf20Sopenharmony_ci outb(HPBLKSEL_0, chip->io + HP_BLKS); 3778c2ecf20Sopenharmony_ci 3788c2ecf20Sopenharmony_ci err = request_firmware(&init_fw, INITCODEFILE, card->dev); 3798c2ecf20Sopenharmony_ci if (err < 0) { 3808c2ecf20Sopenharmony_ci printk(KERN_ERR LOGNAME ": Error loading " INITCODEFILE); 3818c2ecf20Sopenharmony_ci goto cleanup1; 3828c2ecf20Sopenharmony_ci } 3838c2ecf20Sopenharmony_ci err = request_firmware(&perm_fw, PERMCODEFILE, card->dev); 3848c2ecf20Sopenharmony_ci if (err < 0) { 3858c2ecf20Sopenharmony_ci printk(KERN_ERR LOGNAME ": Error loading " PERMCODEFILE); 3868c2ecf20Sopenharmony_ci goto cleanup; 3878c2ecf20Sopenharmony_ci } 3888c2ecf20Sopenharmony_ci 3898c2ecf20Sopenharmony_ci memcpy_toio(chip->mappedbase, perm_fw->data, perm_fw->size); 3908c2ecf20Sopenharmony_ci if (snd_msnd_upload_host(chip, init_fw->data, init_fw->size) < 0) { 3918c2ecf20Sopenharmony_ci printk(KERN_WARNING LOGNAME ": Error uploading to DSP\n"); 3928c2ecf20Sopenharmony_ci err = -ENODEV; 3938c2ecf20Sopenharmony_ci goto cleanup; 3948c2ecf20Sopenharmony_ci } 3958c2ecf20Sopenharmony_ci printk(KERN_INFO LOGNAME ": DSP firmware uploaded\n"); 3968c2ecf20Sopenharmony_ci err = 0; 3978c2ecf20Sopenharmony_ci 3988c2ecf20Sopenharmony_cicleanup: 3998c2ecf20Sopenharmony_ci release_firmware(perm_fw); 4008c2ecf20Sopenharmony_cicleanup1: 4018c2ecf20Sopenharmony_ci release_firmware(init_fw); 4028c2ecf20Sopenharmony_ci return err; 4038c2ecf20Sopenharmony_ci} 4048c2ecf20Sopenharmony_ci 4058c2ecf20Sopenharmony_ci#ifdef MSND_CLASSIC 4068c2ecf20Sopenharmony_cistatic void reset_proteus(struct snd_msnd *chip) 4078c2ecf20Sopenharmony_ci{ 4088c2ecf20Sopenharmony_ci outb(HPPRORESET_ON, chip->io + HP_PROR); 4098c2ecf20Sopenharmony_ci msleep(TIME_PRO_RESET); 4108c2ecf20Sopenharmony_ci outb(HPPRORESET_OFF, chip->io + HP_PROR); 4118c2ecf20Sopenharmony_ci msleep(TIME_PRO_RESET_DONE); 4128c2ecf20Sopenharmony_ci} 4138c2ecf20Sopenharmony_ci#endif 4148c2ecf20Sopenharmony_ci 4158c2ecf20Sopenharmony_cistatic int snd_msnd_initialize(struct snd_card *card) 4168c2ecf20Sopenharmony_ci{ 4178c2ecf20Sopenharmony_ci struct snd_msnd *chip = card->private_data; 4188c2ecf20Sopenharmony_ci int err, timeout; 4198c2ecf20Sopenharmony_ci 4208c2ecf20Sopenharmony_ci#ifdef MSND_CLASSIC 4218c2ecf20Sopenharmony_ci outb(HPWAITSTATE_0, chip->io + HP_WAIT); 4228c2ecf20Sopenharmony_ci outb(HPBITMODE_16, chip->io + HP_BITM); 4238c2ecf20Sopenharmony_ci 4248c2ecf20Sopenharmony_ci reset_proteus(chip); 4258c2ecf20Sopenharmony_ci#endif 4268c2ecf20Sopenharmony_ci err = snd_msnd_init_sma(chip); 4278c2ecf20Sopenharmony_ci if (err < 0) { 4288c2ecf20Sopenharmony_ci printk(KERN_WARNING LOGNAME ": Cannot initialize SMA\n"); 4298c2ecf20Sopenharmony_ci return err; 4308c2ecf20Sopenharmony_ci } 4318c2ecf20Sopenharmony_ci 4328c2ecf20Sopenharmony_ci err = snd_msnd_reset_dsp(chip->io, NULL); 4338c2ecf20Sopenharmony_ci if (err < 0) 4348c2ecf20Sopenharmony_ci return err; 4358c2ecf20Sopenharmony_ci 4368c2ecf20Sopenharmony_ci err = upload_dsp_code(card); 4378c2ecf20Sopenharmony_ci if (err < 0) { 4388c2ecf20Sopenharmony_ci printk(KERN_WARNING LOGNAME ": Cannot upload DSP code\n"); 4398c2ecf20Sopenharmony_ci return err; 4408c2ecf20Sopenharmony_ci } 4418c2ecf20Sopenharmony_ci 4428c2ecf20Sopenharmony_ci timeout = 200; 4438c2ecf20Sopenharmony_ci 4448c2ecf20Sopenharmony_ci while (readw(chip->mappedbase)) { 4458c2ecf20Sopenharmony_ci msleep(1); 4468c2ecf20Sopenharmony_ci if (!timeout--) { 4478c2ecf20Sopenharmony_ci snd_printd(KERN_ERR LOGNAME ": DSP reset timeout\n"); 4488c2ecf20Sopenharmony_ci return -EIO; 4498c2ecf20Sopenharmony_ci } 4508c2ecf20Sopenharmony_ci } 4518c2ecf20Sopenharmony_ci 4528c2ecf20Sopenharmony_ci snd_msndmix_setup(chip); 4538c2ecf20Sopenharmony_ci return 0; 4548c2ecf20Sopenharmony_ci} 4558c2ecf20Sopenharmony_ci 4568c2ecf20Sopenharmony_cistatic int snd_msnd_dsp_full_reset(struct snd_card *card) 4578c2ecf20Sopenharmony_ci{ 4588c2ecf20Sopenharmony_ci struct snd_msnd *chip = card->private_data; 4598c2ecf20Sopenharmony_ci int rv; 4608c2ecf20Sopenharmony_ci 4618c2ecf20Sopenharmony_ci if (test_bit(F_RESETTING, &chip->flags) || ++chip->nresets > 10) 4628c2ecf20Sopenharmony_ci return 0; 4638c2ecf20Sopenharmony_ci 4648c2ecf20Sopenharmony_ci set_bit(F_RESETTING, &chip->flags); 4658c2ecf20Sopenharmony_ci snd_msnd_dsp_halt(chip, NULL); /* Unconditionally halt */ 4668c2ecf20Sopenharmony_ci 4678c2ecf20Sopenharmony_ci rv = snd_msnd_initialize(card); 4688c2ecf20Sopenharmony_ci if (rv) 4698c2ecf20Sopenharmony_ci printk(KERN_WARNING LOGNAME ": DSP reset failed\n"); 4708c2ecf20Sopenharmony_ci snd_msndmix_force_recsrc(chip, 0); 4718c2ecf20Sopenharmony_ci clear_bit(F_RESETTING, &chip->flags); 4728c2ecf20Sopenharmony_ci return rv; 4738c2ecf20Sopenharmony_ci} 4748c2ecf20Sopenharmony_ci 4758c2ecf20Sopenharmony_cistatic int snd_msnd_dev_free(struct snd_device *device) 4768c2ecf20Sopenharmony_ci{ 4778c2ecf20Sopenharmony_ci snd_printdd("snd_msnd_chip_free()\n"); 4788c2ecf20Sopenharmony_ci return 0; 4798c2ecf20Sopenharmony_ci} 4808c2ecf20Sopenharmony_ci 4818c2ecf20Sopenharmony_cistatic int snd_msnd_send_dsp_cmd_chk(struct snd_msnd *chip, u8 cmd) 4828c2ecf20Sopenharmony_ci{ 4838c2ecf20Sopenharmony_ci if (snd_msnd_send_dsp_cmd(chip, cmd) == 0) 4848c2ecf20Sopenharmony_ci return 0; 4858c2ecf20Sopenharmony_ci snd_msnd_dsp_full_reset(chip->card); 4868c2ecf20Sopenharmony_ci return snd_msnd_send_dsp_cmd(chip, cmd); 4878c2ecf20Sopenharmony_ci} 4888c2ecf20Sopenharmony_ci 4898c2ecf20Sopenharmony_cistatic int snd_msnd_calibrate_adc(struct snd_msnd *chip, u16 srate) 4908c2ecf20Sopenharmony_ci{ 4918c2ecf20Sopenharmony_ci snd_printdd("snd_msnd_calibrate_adc(%i)\n", srate); 4928c2ecf20Sopenharmony_ci writew(srate, chip->SMA + SMA_wCalFreqAtoD); 4938c2ecf20Sopenharmony_ci if (chip->calibrate_signal == 0) 4948c2ecf20Sopenharmony_ci writew(readw(chip->SMA + SMA_wCurrHostStatusFlags) 4958c2ecf20Sopenharmony_ci | 0x0001, chip->SMA + SMA_wCurrHostStatusFlags); 4968c2ecf20Sopenharmony_ci else 4978c2ecf20Sopenharmony_ci writew(readw(chip->SMA + SMA_wCurrHostStatusFlags) 4988c2ecf20Sopenharmony_ci & ~0x0001, chip->SMA + SMA_wCurrHostStatusFlags); 4998c2ecf20Sopenharmony_ci if (snd_msnd_send_word(chip, 0, 0, HDEXAR_CAL_A_TO_D) == 0 && 5008c2ecf20Sopenharmony_ci snd_msnd_send_dsp_cmd_chk(chip, HDEX_AUX_REQ) == 0) { 5018c2ecf20Sopenharmony_ci schedule_timeout_interruptible(msecs_to_jiffies(333)); 5028c2ecf20Sopenharmony_ci return 0; 5038c2ecf20Sopenharmony_ci } 5048c2ecf20Sopenharmony_ci printk(KERN_WARNING LOGNAME ": ADC calibration failed\n"); 5058c2ecf20Sopenharmony_ci return -EIO; 5068c2ecf20Sopenharmony_ci} 5078c2ecf20Sopenharmony_ci 5088c2ecf20Sopenharmony_ci/* 5098c2ecf20Sopenharmony_ci * ALSA callback function, called when attempting to open the MIDI device. 5108c2ecf20Sopenharmony_ci */ 5118c2ecf20Sopenharmony_cistatic int snd_msnd_mpu401_open(struct snd_mpu401 *mpu) 5128c2ecf20Sopenharmony_ci{ 5138c2ecf20Sopenharmony_ci snd_msnd_enable_irq(mpu->private_data); 5148c2ecf20Sopenharmony_ci snd_msnd_send_dsp_cmd(mpu->private_data, HDEX_MIDI_IN_START); 5158c2ecf20Sopenharmony_ci return 0; 5168c2ecf20Sopenharmony_ci} 5178c2ecf20Sopenharmony_ci 5188c2ecf20Sopenharmony_cistatic void snd_msnd_mpu401_close(struct snd_mpu401 *mpu) 5198c2ecf20Sopenharmony_ci{ 5208c2ecf20Sopenharmony_ci snd_msnd_send_dsp_cmd(mpu->private_data, HDEX_MIDI_IN_STOP); 5218c2ecf20Sopenharmony_ci snd_msnd_disable_irq(mpu->private_data); 5228c2ecf20Sopenharmony_ci} 5238c2ecf20Sopenharmony_ci 5248c2ecf20Sopenharmony_cistatic long mpu_io[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; 5258c2ecf20Sopenharmony_cistatic int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; 5268c2ecf20Sopenharmony_ci 5278c2ecf20Sopenharmony_cistatic int snd_msnd_attach(struct snd_card *card) 5288c2ecf20Sopenharmony_ci{ 5298c2ecf20Sopenharmony_ci struct snd_msnd *chip = card->private_data; 5308c2ecf20Sopenharmony_ci int err; 5318c2ecf20Sopenharmony_ci static const struct snd_device_ops ops = { 5328c2ecf20Sopenharmony_ci .dev_free = snd_msnd_dev_free, 5338c2ecf20Sopenharmony_ci }; 5348c2ecf20Sopenharmony_ci 5358c2ecf20Sopenharmony_ci err = request_irq(chip->irq, snd_msnd_interrupt, 0, card->shortname, 5368c2ecf20Sopenharmony_ci chip); 5378c2ecf20Sopenharmony_ci if (err < 0) { 5388c2ecf20Sopenharmony_ci printk(KERN_ERR LOGNAME ": Couldn't grab IRQ %d\n", chip->irq); 5398c2ecf20Sopenharmony_ci return err; 5408c2ecf20Sopenharmony_ci } 5418c2ecf20Sopenharmony_ci card->sync_irq = chip->irq; 5428c2ecf20Sopenharmony_ci if (request_region(chip->io, DSP_NUMIO, card->shortname) == NULL) { 5438c2ecf20Sopenharmony_ci free_irq(chip->irq, chip); 5448c2ecf20Sopenharmony_ci return -EBUSY; 5458c2ecf20Sopenharmony_ci } 5468c2ecf20Sopenharmony_ci 5478c2ecf20Sopenharmony_ci if (!request_mem_region(chip->base, BUFFSIZE, card->shortname)) { 5488c2ecf20Sopenharmony_ci printk(KERN_ERR LOGNAME 5498c2ecf20Sopenharmony_ci ": unable to grab memory region 0x%lx-0x%lx\n", 5508c2ecf20Sopenharmony_ci chip->base, chip->base + BUFFSIZE - 1); 5518c2ecf20Sopenharmony_ci release_region(chip->io, DSP_NUMIO); 5528c2ecf20Sopenharmony_ci free_irq(chip->irq, chip); 5538c2ecf20Sopenharmony_ci return -EBUSY; 5548c2ecf20Sopenharmony_ci } 5558c2ecf20Sopenharmony_ci chip->mappedbase = ioremap(chip->base, 0x8000); 5568c2ecf20Sopenharmony_ci if (!chip->mappedbase) { 5578c2ecf20Sopenharmony_ci printk(KERN_ERR LOGNAME 5588c2ecf20Sopenharmony_ci ": unable to map memory region 0x%lx-0x%lx\n", 5598c2ecf20Sopenharmony_ci chip->base, chip->base + BUFFSIZE - 1); 5608c2ecf20Sopenharmony_ci err = -EIO; 5618c2ecf20Sopenharmony_ci goto err_release_region; 5628c2ecf20Sopenharmony_ci } 5638c2ecf20Sopenharmony_ci 5648c2ecf20Sopenharmony_ci err = snd_msnd_dsp_full_reset(card); 5658c2ecf20Sopenharmony_ci if (err < 0) 5668c2ecf20Sopenharmony_ci goto err_release_region; 5678c2ecf20Sopenharmony_ci 5688c2ecf20Sopenharmony_ci /* Register device */ 5698c2ecf20Sopenharmony_ci err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); 5708c2ecf20Sopenharmony_ci if (err < 0) 5718c2ecf20Sopenharmony_ci goto err_release_region; 5728c2ecf20Sopenharmony_ci 5738c2ecf20Sopenharmony_ci err = snd_msnd_pcm(card, 0); 5748c2ecf20Sopenharmony_ci if (err < 0) { 5758c2ecf20Sopenharmony_ci printk(KERN_ERR LOGNAME ": error creating new PCM device\n"); 5768c2ecf20Sopenharmony_ci goto err_release_region; 5778c2ecf20Sopenharmony_ci } 5788c2ecf20Sopenharmony_ci 5798c2ecf20Sopenharmony_ci err = snd_msndmix_new(card); 5808c2ecf20Sopenharmony_ci if (err < 0) { 5818c2ecf20Sopenharmony_ci printk(KERN_ERR LOGNAME ": error creating new Mixer device\n"); 5828c2ecf20Sopenharmony_ci goto err_release_region; 5838c2ecf20Sopenharmony_ci } 5848c2ecf20Sopenharmony_ci 5858c2ecf20Sopenharmony_ci 5868c2ecf20Sopenharmony_ci if (mpu_io[0] != SNDRV_AUTO_PORT) { 5878c2ecf20Sopenharmony_ci struct snd_mpu401 *mpu; 5888c2ecf20Sopenharmony_ci 5898c2ecf20Sopenharmony_ci err = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, 5908c2ecf20Sopenharmony_ci mpu_io[0], 5918c2ecf20Sopenharmony_ci MPU401_MODE_INPUT | 5928c2ecf20Sopenharmony_ci MPU401_MODE_OUTPUT, 5938c2ecf20Sopenharmony_ci mpu_irq[0], 5948c2ecf20Sopenharmony_ci &chip->rmidi); 5958c2ecf20Sopenharmony_ci if (err < 0) { 5968c2ecf20Sopenharmony_ci printk(KERN_ERR LOGNAME 5978c2ecf20Sopenharmony_ci ": error creating new Midi device\n"); 5988c2ecf20Sopenharmony_ci goto err_release_region; 5998c2ecf20Sopenharmony_ci } 6008c2ecf20Sopenharmony_ci mpu = chip->rmidi->private_data; 6018c2ecf20Sopenharmony_ci 6028c2ecf20Sopenharmony_ci mpu->open_input = snd_msnd_mpu401_open; 6038c2ecf20Sopenharmony_ci mpu->close_input = snd_msnd_mpu401_close; 6048c2ecf20Sopenharmony_ci mpu->private_data = chip; 6058c2ecf20Sopenharmony_ci } 6068c2ecf20Sopenharmony_ci 6078c2ecf20Sopenharmony_ci disable_irq(chip->irq); 6088c2ecf20Sopenharmony_ci snd_msnd_calibrate_adc(chip, chip->play_sample_rate); 6098c2ecf20Sopenharmony_ci snd_msndmix_force_recsrc(chip, 0); 6108c2ecf20Sopenharmony_ci 6118c2ecf20Sopenharmony_ci err = snd_card_register(card); 6128c2ecf20Sopenharmony_ci if (err < 0) 6138c2ecf20Sopenharmony_ci goto err_release_region; 6148c2ecf20Sopenharmony_ci 6158c2ecf20Sopenharmony_ci return 0; 6168c2ecf20Sopenharmony_ci 6178c2ecf20Sopenharmony_cierr_release_region: 6188c2ecf20Sopenharmony_ci iounmap(chip->mappedbase); 6198c2ecf20Sopenharmony_ci release_mem_region(chip->base, BUFFSIZE); 6208c2ecf20Sopenharmony_ci release_region(chip->io, DSP_NUMIO); 6218c2ecf20Sopenharmony_ci free_irq(chip->irq, chip); 6228c2ecf20Sopenharmony_ci return err; 6238c2ecf20Sopenharmony_ci} 6248c2ecf20Sopenharmony_ci 6258c2ecf20Sopenharmony_ci 6268c2ecf20Sopenharmony_cistatic void snd_msnd_unload(struct snd_card *card) 6278c2ecf20Sopenharmony_ci{ 6288c2ecf20Sopenharmony_ci struct snd_msnd *chip = card->private_data; 6298c2ecf20Sopenharmony_ci 6308c2ecf20Sopenharmony_ci iounmap(chip->mappedbase); 6318c2ecf20Sopenharmony_ci release_mem_region(chip->base, BUFFSIZE); 6328c2ecf20Sopenharmony_ci release_region(chip->io, DSP_NUMIO); 6338c2ecf20Sopenharmony_ci free_irq(chip->irq, chip); 6348c2ecf20Sopenharmony_ci snd_card_free(card); 6358c2ecf20Sopenharmony_ci} 6368c2ecf20Sopenharmony_ci 6378c2ecf20Sopenharmony_ci#ifndef MSND_CLASSIC 6388c2ecf20Sopenharmony_ci 6398c2ecf20Sopenharmony_ci/* Pinnacle/Fiji Logical Device Configuration */ 6408c2ecf20Sopenharmony_ci 6418c2ecf20Sopenharmony_cistatic int snd_msnd_write_cfg(int cfg, int reg, int value) 6428c2ecf20Sopenharmony_ci{ 6438c2ecf20Sopenharmony_ci outb(reg, cfg); 6448c2ecf20Sopenharmony_ci outb(value, cfg + 1); 6458c2ecf20Sopenharmony_ci if (value != inb(cfg + 1)) { 6468c2ecf20Sopenharmony_ci printk(KERN_ERR LOGNAME ": snd_msnd_write_cfg: I/O error\n"); 6478c2ecf20Sopenharmony_ci return -EIO; 6488c2ecf20Sopenharmony_ci } 6498c2ecf20Sopenharmony_ci return 0; 6508c2ecf20Sopenharmony_ci} 6518c2ecf20Sopenharmony_ci 6528c2ecf20Sopenharmony_cistatic int snd_msnd_write_cfg_io0(int cfg, int num, u16 io) 6538c2ecf20Sopenharmony_ci{ 6548c2ecf20Sopenharmony_ci if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num)) 6558c2ecf20Sopenharmony_ci return -EIO; 6568c2ecf20Sopenharmony_ci if (snd_msnd_write_cfg(cfg, IREG_IO0_BASEHI, HIBYTE(io))) 6578c2ecf20Sopenharmony_ci return -EIO; 6588c2ecf20Sopenharmony_ci if (snd_msnd_write_cfg(cfg, IREG_IO0_BASELO, LOBYTE(io))) 6598c2ecf20Sopenharmony_ci return -EIO; 6608c2ecf20Sopenharmony_ci return 0; 6618c2ecf20Sopenharmony_ci} 6628c2ecf20Sopenharmony_ci 6638c2ecf20Sopenharmony_cistatic int snd_msnd_write_cfg_io1(int cfg, int num, u16 io) 6648c2ecf20Sopenharmony_ci{ 6658c2ecf20Sopenharmony_ci if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num)) 6668c2ecf20Sopenharmony_ci return -EIO; 6678c2ecf20Sopenharmony_ci if (snd_msnd_write_cfg(cfg, IREG_IO1_BASEHI, HIBYTE(io))) 6688c2ecf20Sopenharmony_ci return -EIO; 6698c2ecf20Sopenharmony_ci if (snd_msnd_write_cfg(cfg, IREG_IO1_BASELO, LOBYTE(io))) 6708c2ecf20Sopenharmony_ci return -EIO; 6718c2ecf20Sopenharmony_ci return 0; 6728c2ecf20Sopenharmony_ci} 6738c2ecf20Sopenharmony_ci 6748c2ecf20Sopenharmony_cistatic int snd_msnd_write_cfg_irq(int cfg, int num, u16 irq) 6758c2ecf20Sopenharmony_ci{ 6768c2ecf20Sopenharmony_ci if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num)) 6778c2ecf20Sopenharmony_ci return -EIO; 6788c2ecf20Sopenharmony_ci if (snd_msnd_write_cfg(cfg, IREG_IRQ_NUMBER, LOBYTE(irq))) 6798c2ecf20Sopenharmony_ci return -EIO; 6808c2ecf20Sopenharmony_ci if (snd_msnd_write_cfg(cfg, IREG_IRQ_TYPE, IRQTYPE_EDGE)) 6818c2ecf20Sopenharmony_ci return -EIO; 6828c2ecf20Sopenharmony_ci return 0; 6838c2ecf20Sopenharmony_ci} 6848c2ecf20Sopenharmony_ci 6858c2ecf20Sopenharmony_cistatic int snd_msnd_write_cfg_mem(int cfg, int num, int mem) 6868c2ecf20Sopenharmony_ci{ 6878c2ecf20Sopenharmony_ci u16 wmem; 6888c2ecf20Sopenharmony_ci 6898c2ecf20Sopenharmony_ci mem >>= 8; 6908c2ecf20Sopenharmony_ci wmem = (u16)(mem & 0xfff); 6918c2ecf20Sopenharmony_ci if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num)) 6928c2ecf20Sopenharmony_ci return -EIO; 6938c2ecf20Sopenharmony_ci if (snd_msnd_write_cfg(cfg, IREG_MEMBASEHI, HIBYTE(wmem))) 6948c2ecf20Sopenharmony_ci return -EIO; 6958c2ecf20Sopenharmony_ci if (snd_msnd_write_cfg(cfg, IREG_MEMBASELO, LOBYTE(wmem))) 6968c2ecf20Sopenharmony_ci return -EIO; 6978c2ecf20Sopenharmony_ci if (wmem && snd_msnd_write_cfg(cfg, IREG_MEMCONTROL, 6988c2ecf20Sopenharmony_ci MEMTYPE_HIADDR | MEMTYPE_16BIT)) 6998c2ecf20Sopenharmony_ci return -EIO; 7008c2ecf20Sopenharmony_ci return 0; 7018c2ecf20Sopenharmony_ci} 7028c2ecf20Sopenharmony_ci 7038c2ecf20Sopenharmony_cistatic int snd_msnd_activate_logical(int cfg, int num) 7048c2ecf20Sopenharmony_ci{ 7058c2ecf20Sopenharmony_ci if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num)) 7068c2ecf20Sopenharmony_ci return -EIO; 7078c2ecf20Sopenharmony_ci if (snd_msnd_write_cfg(cfg, IREG_ACTIVATE, LD_ACTIVATE)) 7088c2ecf20Sopenharmony_ci return -EIO; 7098c2ecf20Sopenharmony_ci return 0; 7108c2ecf20Sopenharmony_ci} 7118c2ecf20Sopenharmony_ci 7128c2ecf20Sopenharmony_cistatic int snd_msnd_write_cfg_logical(int cfg, int num, u16 io0, 7138c2ecf20Sopenharmony_ci u16 io1, u16 irq, int mem) 7148c2ecf20Sopenharmony_ci{ 7158c2ecf20Sopenharmony_ci if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num)) 7168c2ecf20Sopenharmony_ci return -EIO; 7178c2ecf20Sopenharmony_ci if (snd_msnd_write_cfg_io0(cfg, num, io0)) 7188c2ecf20Sopenharmony_ci return -EIO; 7198c2ecf20Sopenharmony_ci if (snd_msnd_write_cfg_io1(cfg, num, io1)) 7208c2ecf20Sopenharmony_ci return -EIO; 7218c2ecf20Sopenharmony_ci if (snd_msnd_write_cfg_irq(cfg, num, irq)) 7228c2ecf20Sopenharmony_ci return -EIO; 7238c2ecf20Sopenharmony_ci if (snd_msnd_write_cfg_mem(cfg, num, mem)) 7248c2ecf20Sopenharmony_ci return -EIO; 7258c2ecf20Sopenharmony_ci if (snd_msnd_activate_logical(cfg, num)) 7268c2ecf20Sopenharmony_ci return -EIO; 7278c2ecf20Sopenharmony_ci return 0; 7288c2ecf20Sopenharmony_ci} 7298c2ecf20Sopenharmony_ci 7308c2ecf20Sopenharmony_cistatic int snd_msnd_pinnacle_cfg_reset(int cfg) 7318c2ecf20Sopenharmony_ci{ 7328c2ecf20Sopenharmony_ci int i; 7338c2ecf20Sopenharmony_ci 7348c2ecf20Sopenharmony_ci /* Reset devices if told to */ 7358c2ecf20Sopenharmony_ci printk(KERN_INFO LOGNAME ": Resetting all devices\n"); 7368c2ecf20Sopenharmony_ci for (i = 0; i < 4; ++i) 7378c2ecf20Sopenharmony_ci if (snd_msnd_write_cfg_logical(cfg, i, 0, 0, 0, 0)) 7388c2ecf20Sopenharmony_ci return -EIO; 7398c2ecf20Sopenharmony_ci 7408c2ecf20Sopenharmony_ci return 0; 7418c2ecf20Sopenharmony_ci} 7428c2ecf20Sopenharmony_ci#endif 7438c2ecf20Sopenharmony_ci 7448c2ecf20Sopenharmony_cistatic int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 7458c2ecf20Sopenharmony_cistatic char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 7468c2ecf20Sopenharmony_ci 7478c2ecf20Sopenharmony_cimodule_param_array(index, int, NULL, 0444); 7488c2ecf20Sopenharmony_ciMODULE_PARM_DESC(index, "Index value for msnd_pinnacle soundcard."); 7498c2ecf20Sopenharmony_cimodule_param_array(id, charp, NULL, 0444); 7508c2ecf20Sopenharmony_ciMODULE_PARM_DESC(id, "ID string for msnd_pinnacle soundcard."); 7518c2ecf20Sopenharmony_ci 7528c2ecf20Sopenharmony_cistatic long io[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; 7538c2ecf20Sopenharmony_cistatic int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; 7548c2ecf20Sopenharmony_cistatic long mem[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; 7558c2ecf20Sopenharmony_ci 7568c2ecf20Sopenharmony_ci#ifndef MSND_CLASSIC 7578c2ecf20Sopenharmony_cistatic long cfg[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; 7588c2ecf20Sopenharmony_ci 7598c2ecf20Sopenharmony_ci/* Extra Peripheral Configuration (Default: Disable) */ 7608c2ecf20Sopenharmony_cistatic long ide_io0[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; 7618c2ecf20Sopenharmony_cistatic long ide_io1[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; 7628c2ecf20Sopenharmony_cistatic int ide_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; 7638c2ecf20Sopenharmony_ci 7648c2ecf20Sopenharmony_cistatic long joystick_io[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; 7658c2ecf20Sopenharmony_ci/* If we have the digital daugherboard... */ 7668c2ecf20Sopenharmony_cistatic int digital[SNDRV_CARDS]; 7678c2ecf20Sopenharmony_ci 7688c2ecf20Sopenharmony_ci/* Extra Peripheral Configuration */ 7698c2ecf20Sopenharmony_cistatic int reset[SNDRV_CARDS]; 7708c2ecf20Sopenharmony_ci#endif 7718c2ecf20Sopenharmony_ci 7728c2ecf20Sopenharmony_cistatic int write_ndelay[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = 1 }; 7738c2ecf20Sopenharmony_ci 7748c2ecf20Sopenharmony_cistatic int calibrate_signal; 7758c2ecf20Sopenharmony_ci 7768c2ecf20Sopenharmony_ci#ifdef CONFIG_PNP 7778c2ecf20Sopenharmony_cistatic bool isapnp[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; 7788c2ecf20Sopenharmony_cimodule_param_array(isapnp, bool, NULL, 0444); 7798c2ecf20Sopenharmony_ciMODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard."); 7808c2ecf20Sopenharmony_ci#define has_isapnp(x) isapnp[x] 7818c2ecf20Sopenharmony_ci#else 7828c2ecf20Sopenharmony_ci#define has_isapnp(x) 0 7838c2ecf20Sopenharmony_ci#endif 7848c2ecf20Sopenharmony_ci 7858c2ecf20Sopenharmony_ciMODULE_AUTHOR("Karsten Wiese <annabellesgarden@yahoo.de>"); 7868c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Turtle Beach " LONGNAME " Linux Driver"); 7878c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 7888c2ecf20Sopenharmony_ciMODULE_FIRMWARE(INITCODEFILE); 7898c2ecf20Sopenharmony_ciMODULE_FIRMWARE(PERMCODEFILE); 7908c2ecf20Sopenharmony_ci 7918c2ecf20Sopenharmony_cimodule_param_hw_array(io, long, ioport, NULL, 0444); 7928c2ecf20Sopenharmony_ciMODULE_PARM_DESC(io, "IO port #"); 7938c2ecf20Sopenharmony_cimodule_param_hw_array(irq, int, irq, NULL, 0444); 7948c2ecf20Sopenharmony_cimodule_param_hw_array(mem, long, iomem, NULL, 0444); 7958c2ecf20Sopenharmony_cimodule_param_array(write_ndelay, int, NULL, 0444); 7968c2ecf20Sopenharmony_cimodule_param(calibrate_signal, int, 0444); 7978c2ecf20Sopenharmony_ci#ifndef MSND_CLASSIC 7988c2ecf20Sopenharmony_cimodule_param_array(digital, int, NULL, 0444); 7998c2ecf20Sopenharmony_cimodule_param_hw_array(cfg, long, ioport, NULL, 0444); 8008c2ecf20Sopenharmony_cimodule_param_array(reset, int, NULL, 0444); 8018c2ecf20Sopenharmony_cimodule_param_hw_array(mpu_io, long, ioport, NULL, 0444); 8028c2ecf20Sopenharmony_cimodule_param_hw_array(mpu_irq, int, irq, NULL, 0444); 8038c2ecf20Sopenharmony_cimodule_param_hw_array(ide_io0, long, ioport, NULL, 0444); 8048c2ecf20Sopenharmony_cimodule_param_hw_array(ide_io1, long, ioport, NULL, 0444); 8058c2ecf20Sopenharmony_cimodule_param_hw_array(ide_irq, int, irq, NULL, 0444); 8068c2ecf20Sopenharmony_cimodule_param_hw_array(joystick_io, long, ioport, NULL, 0444); 8078c2ecf20Sopenharmony_ci#endif 8088c2ecf20Sopenharmony_ci 8098c2ecf20Sopenharmony_ci 8108c2ecf20Sopenharmony_cistatic int snd_msnd_isa_match(struct device *pdev, unsigned int i) 8118c2ecf20Sopenharmony_ci{ 8128c2ecf20Sopenharmony_ci if (io[i] == SNDRV_AUTO_PORT) 8138c2ecf20Sopenharmony_ci return 0; 8148c2ecf20Sopenharmony_ci 8158c2ecf20Sopenharmony_ci if (irq[i] == SNDRV_AUTO_PORT || mem[i] == SNDRV_AUTO_PORT) { 8168c2ecf20Sopenharmony_ci printk(KERN_WARNING LOGNAME ": io, irq and mem must be set\n"); 8178c2ecf20Sopenharmony_ci return 0; 8188c2ecf20Sopenharmony_ci } 8198c2ecf20Sopenharmony_ci 8208c2ecf20Sopenharmony_ci#ifdef MSND_CLASSIC 8218c2ecf20Sopenharmony_ci if (!(io[i] == 0x290 || 8228c2ecf20Sopenharmony_ci io[i] == 0x260 || 8238c2ecf20Sopenharmony_ci io[i] == 0x250 || 8248c2ecf20Sopenharmony_ci io[i] == 0x240 || 8258c2ecf20Sopenharmony_ci io[i] == 0x230 || 8268c2ecf20Sopenharmony_ci io[i] == 0x220 || 8278c2ecf20Sopenharmony_ci io[i] == 0x210 || 8288c2ecf20Sopenharmony_ci io[i] == 0x3e0)) { 8298c2ecf20Sopenharmony_ci printk(KERN_ERR LOGNAME ": \"io\" - DSP I/O base must be set " 8308c2ecf20Sopenharmony_ci " to 0x210, 0x220, 0x230, 0x240, 0x250, 0x260, 0x290, " 8318c2ecf20Sopenharmony_ci "or 0x3E0\n"); 8328c2ecf20Sopenharmony_ci return 0; 8338c2ecf20Sopenharmony_ci } 8348c2ecf20Sopenharmony_ci#else 8358c2ecf20Sopenharmony_ci if (io[i] < 0x100 || io[i] > 0x3e0 || (io[i] % 0x10) != 0) { 8368c2ecf20Sopenharmony_ci printk(KERN_ERR LOGNAME 8378c2ecf20Sopenharmony_ci ": \"io\" - DSP I/O base must within the range 0x100 " 8388c2ecf20Sopenharmony_ci "to 0x3E0 and must be evenly divisible by 0x10\n"); 8398c2ecf20Sopenharmony_ci return 0; 8408c2ecf20Sopenharmony_ci } 8418c2ecf20Sopenharmony_ci#endif /* MSND_CLASSIC */ 8428c2ecf20Sopenharmony_ci 8438c2ecf20Sopenharmony_ci if (!(irq[i] == 5 || 8448c2ecf20Sopenharmony_ci irq[i] == 7 || 8458c2ecf20Sopenharmony_ci irq[i] == 9 || 8468c2ecf20Sopenharmony_ci irq[i] == 10 || 8478c2ecf20Sopenharmony_ci irq[i] == 11 || 8488c2ecf20Sopenharmony_ci irq[i] == 12)) { 8498c2ecf20Sopenharmony_ci printk(KERN_ERR LOGNAME 8508c2ecf20Sopenharmony_ci ": \"irq\" - must be set to 5, 7, 9, 10, 11 or 12\n"); 8518c2ecf20Sopenharmony_ci return 0; 8528c2ecf20Sopenharmony_ci } 8538c2ecf20Sopenharmony_ci 8548c2ecf20Sopenharmony_ci if (!(mem[i] == 0xb0000 || 8558c2ecf20Sopenharmony_ci mem[i] == 0xc8000 || 8568c2ecf20Sopenharmony_ci mem[i] == 0xd0000 || 8578c2ecf20Sopenharmony_ci mem[i] == 0xd8000 || 8588c2ecf20Sopenharmony_ci mem[i] == 0xe0000 || 8598c2ecf20Sopenharmony_ci mem[i] == 0xe8000)) { 8608c2ecf20Sopenharmony_ci printk(KERN_ERR LOGNAME ": \"mem\" - must be set to " 8618c2ecf20Sopenharmony_ci "0xb0000, 0xc8000, 0xd0000, 0xd8000, 0xe0000 or " 8628c2ecf20Sopenharmony_ci "0xe8000\n"); 8638c2ecf20Sopenharmony_ci return 0; 8648c2ecf20Sopenharmony_ci } 8658c2ecf20Sopenharmony_ci 8668c2ecf20Sopenharmony_ci#ifndef MSND_CLASSIC 8678c2ecf20Sopenharmony_ci if (cfg[i] == SNDRV_AUTO_PORT) { 8688c2ecf20Sopenharmony_ci printk(KERN_INFO LOGNAME ": Assuming PnP mode\n"); 8698c2ecf20Sopenharmony_ci } else if (cfg[i] != 0x250 && cfg[i] != 0x260 && cfg[i] != 0x270) { 8708c2ecf20Sopenharmony_ci printk(KERN_INFO LOGNAME 8718c2ecf20Sopenharmony_ci ": Config port must be 0x250, 0x260 or 0x270 " 8728c2ecf20Sopenharmony_ci "(or unspecified for PnP mode)\n"); 8738c2ecf20Sopenharmony_ci return 0; 8748c2ecf20Sopenharmony_ci } 8758c2ecf20Sopenharmony_ci#endif /* MSND_CLASSIC */ 8768c2ecf20Sopenharmony_ci 8778c2ecf20Sopenharmony_ci return 1; 8788c2ecf20Sopenharmony_ci} 8798c2ecf20Sopenharmony_ci 8808c2ecf20Sopenharmony_cistatic int snd_msnd_isa_probe(struct device *pdev, unsigned int idx) 8818c2ecf20Sopenharmony_ci{ 8828c2ecf20Sopenharmony_ci int err; 8838c2ecf20Sopenharmony_ci struct snd_card *card; 8848c2ecf20Sopenharmony_ci struct snd_msnd *chip; 8858c2ecf20Sopenharmony_ci 8868c2ecf20Sopenharmony_ci if (has_isapnp(idx) 8878c2ecf20Sopenharmony_ci#ifndef MSND_CLASSIC 8888c2ecf20Sopenharmony_ci || cfg[idx] == SNDRV_AUTO_PORT 8898c2ecf20Sopenharmony_ci#endif 8908c2ecf20Sopenharmony_ci ) { 8918c2ecf20Sopenharmony_ci printk(KERN_INFO LOGNAME ": Assuming PnP mode\n"); 8928c2ecf20Sopenharmony_ci return -ENODEV; 8938c2ecf20Sopenharmony_ci } 8948c2ecf20Sopenharmony_ci 8958c2ecf20Sopenharmony_ci err = snd_card_new(pdev, index[idx], id[idx], THIS_MODULE, 8968c2ecf20Sopenharmony_ci sizeof(struct snd_msnd), &card); 8978c2ecf20Sopenharmony_ci if (err < 0) 8988c2ecf20Sopenharmony_ci return err; 8998c2ecf20Sopenharmony_ci 9008c2ecf20Sopenharmony_ci chip = card->private_data; 9018c2ecf20Sopenharmony_ci chip->card = card; 9028c2ecf20Sopenharmony_ci 9038c2ecf20Sopenharmony_ci#ifdef MSND_CLASSIC 9048c2ecf20Sopenharmony_ci switch (irq[idx]) { 9058c2ecf20Sopenharmony_ci case 5: 9068c2ecf20Sopenharmony_ci chip->irqid = HPIRQ_5; break; 9078c2ecf20Sopenharmony_ci case 7: 9088c2ecf20Sopenharmony_ci chip->irqid = HPIRQ_7; break; 9098c2ecf20Sopenharmony_ci case 9: 9108c2ecf20Sopenharmony_ci chip->irqid = HPIRQ_9; break; 9118c2ecf20Sopenharmony_ci case 10: 9128c2ecf20Sopenharmony_ci chip->irqid = HPIRQ_10; break; 9138c2ecf20Sopenharmony_ci case 11: 9148c2ecf20Sopenharmony_ci chip->irqid = HPIRQ_11; break; 9158c2ecf20Sopenharmony_ci case 12: 9168c2ecf20Sopenharmony_ci chip->irqid = HPIRQ_12; break; 9178c2ecf20Sopenharmony_ci } 9188c2ecf20Sopenharmony_ci 9198c2ecf20Sopenharmony_ci switch (mem[idx]) { 9208c2ecf20Sopenharmony_ci case 0xb0000: 9218c2ecf20Sopenharmony_ci chip->memid = HPMEM_B000; break; 9228c2ecf20Sopenharmony_ci case 0xc8000: 9238c2ecf20Sopenharmony_ci chip->memid = HPMEM_C800; break; 9248c2ecf20Sopenharmony_ci case 0xd0000: 9258c2ecf20Sopenharmony_ci chip->memid = HPMEM_D000; break; 9268c2ecf20Sopenharmony_ci case 0xd8000: 9278c2ecf20Sopenharmony_ci chip->memid = HPMEM_D800; break; 9288c2ecf20Sopenharmony_ci case 0xe0000: 9298c2ecf20Sopenharmony_ci chip->memid = HPMEM_E000; break; 9308c2ecf20Sopenharmony_ci case 0xe8000: 9318c2ecf20Sopenharmony_ci chip->memid = HPMEM_E800; break; 9328c2ecf20Sopenharmony_ci } 9338c2ecf20Sopenharmony_ci#else 9348c2ecf20Sopenharmony_ci printk(KERN_INFO LOGNAME ": Non-PnP mode: configuring at port 0x%lx\n", 9358c2ecf20Sopenharmony_ci cfg[idx]); 9368c2ecf20Sopenharmony_ci 9378c2ecf20Sopenharmony_ci if (!request_region(cfg[idx], 2, "Pinnacle/Fiji Config")) { 9388c2ecf20Sopenharmony_ci printk(KERN_ERR LOGNAME ": Config port 0x%lx conflict\n", 9398c2ecf20Sopenharmony_ci cfg[idx]); 9408c2ecf20Sopenharmony_ci snd_card_free(card); 9418c2ecf20Sopenharmony_ci return -EIO; 9428c2ecf20Sopenharmony_ci } 9438c2ecf20Sopenharmony_ci if (reset[idx]) 9448c2ecf20Sopenharmony_ci if (snd_msnd_pinnacle_cfg_reset(cfg[idx])) { 9458c2ecf20Sopenharmony_ci err = -EIO; 9468c2ecf20Sopenharmony_ci goto cfg_error; 9478c2ecf20Sopenharmony_ci } 9488c2ecf20Sopenharmony_ci 9498c2ecf20Sopenharmony_ci /* DSP */ 9508c2ecf20Sopenharmony_ci err = snd_msnd_write_cfg_logical(cfg[idx], 0, 9518c2ecf20Sopenharmony_ci io[idx], 0, 9528c2ecf20Sopenharmony_ci irq[idx], mem[idx]); 9538c2ecf20Sopenharmony_ci 9548c2ecf20Sopenharmony_ci if (err) 9558c2ecf20Sopenharmony_ci goto cfg_error; 9568c2ecf20Sopenharmony_ci 9578c2ecf20Sopenharmony_ci /* The following are Pinnacle specific */ 9588c2ecf20Sopenharmony_ci 9598c2ecf20Sopenharmony_ci /* MPU */ 9608c2ecf20Sopenharmony_ci if (mpu_io[idx] != SNDRV_AUTO_PORT 9618c2ecf20Sopenharmony_ci && mpu_irq[idx] != SNDRV_AUTO_IRQ) { 9628c2ecf20Sopenharmony_ci printk(KERN_INFO LOGNAME 9638c2ecf20Sopenharmony_ci ": Configuring MPU to I/O 0x%lx IRQ %d\n", 9648c2ecf20Sopenharmony_ci mpu_io[idx], mpu_irq[idx]); 9658c2ecf20Sopenharmony_ci err = snd_msnd_write_cfg_logical(cfg[idx], 1, 9668c2ecf20Sopenharmony_ci mpu_io[idx], 0, 9678c2ecf20Sopenharmony_ci mpu_irq[idx], 0); 9688c2ecf20Sopenharmony_ci 9698c2ecf20Sopenharmony_ci if (err) 9708c2ecf20Sopenharmony_ci goto cfg_error; 9718c2ecf20Sopenharmony_ci } 9728c2ecf20Sopenharmony_ci 9738c2ecf20Sopenharmony_ci /* IDE */ 9748c2ecf20Sopenharmony_ci if (ide_io0[idx] != SNDRV_AUTO_PORT 9758c2ecf20Sopenharmony_ci && ide_io1[idx] != SNDRV_AUTO_PORT 9768c2ecf20Sopenharmony_ci && ide_irq[idx] != SNDRV_AUTO_IRQ) { 9778c2ecf20Sopenharmony_ci printk(KERN_INFO LOGNAME 9788c2ecf20Sopenharmony_ci ": Configuring IDE to I/O 0x%lx, 0x%lx IRQ %d\n", 9798c2ecf20Sopenharmony_ci ide_io0[idx], ide_io1[idx], ide_irq[idx]); 9808c2ecf20Sopenharmony_ci err = snd_msnd_write_cfg_logical(cfg[idx], 2, 9818c2ecf20Sopenharmony_ci ide_io0[idx], ide_io1[idx], 9828c2ecf20Sopenharmony_ci ide_irq[idx], 0); 9838c2ecf20Sopenharmony_ci 9848c2ecf20Sopenharmony_ci if (err) 9858c2ecf20Sopenharmony_ci goto cfg_error; 9868c2ecf20Sopenharmony_ci } 9878c2ecf20Sopenharmony_ci 9888c2ecf20Sopenharmony_ci /* Joystick */ 9898c2ecf20Sopenharmony_ci if (joystick_io[idx] != SNDRV_AUTO_PORT) { 9908c2ecf20Sopenharmony_ci printk(KERN_INFO LOGNAME 9918c2ecf20Sopenharmony_ci ": Configuring joystick to I/O 0x%lx\n", 9928c2ecf20Sopenharmony_ci joystick_io[idx]); 9938c2ecf20Sopenharmony_ci err = snd_msnd_write_cfg_logical(cfg[idx], 3, 9948c2ecf20Sopenharmony_ci joystick_io[idx], 0, 9958c2ecf20Sopenharmony_ci 0, 0); 9968c2ecf20Sopenharmony_ci 9978c2ecf20Sopenharmony_ci if (err) 9988c2ecf20Sopenharmony_ci goto cfg_error; 9998c2ecf20Sopenharmony_ci } 10008c2ecf20Sopenharmony_ci release_region(cfg[idx], 2); 10018c2ecf20Sopenharmony_ci 10028c2ecf20Sopenharmony_ci#endif /* MSND_CLASSIC */ 10038c2ecf20Sopenharmony_ci 10048c2ecf20Sopenharmony_ci set_default_audio_parameters(chip); 10058c2ecf20Sopenharmony_ci#ifdef MSND_CLASSIC 10068c2ecf20Sopenharmony_ci chip->type = msndClassic; 10078c2ecf20Sopenharmony_ci#else 10088c2ecf20Sopenharmony_ci chip->type = msndPinnacle; 10098c2ecf20Sopenharmony_ci#endif 10108c2ecf20Sopenharmony_ci chip->io = io[idx]; 10118c2ecf20Sopenharmony_ci chip->irq = irq[idx]; 10128c2ecf20Sopenharmony_ci chip->base = mem[idx]; 10138c2ecf20Sopenharmony_ci 10148c2ecf20Sopenharmony_ci chip->calibrate_signal = calibrate_signal ? 1 : 0; 10158c2ecf20Sopenharmony_ci chip->recsrc = 0; 10168c2ecf20Sopenharmony_ci chip->dspq_data_buff = DSPQ_DATA_BUFF; 10178c2ecf20Sopenharmony_ci chip->dspq_buff_size = DSPQ_BUFF_SIZE; 10188c2ecf20Sopenharmony_ci if (write_ndelay[idx]) 10198c2ecf20Sopenharmony_ci clear_bit(F_DISABLE_WRITE_NDELAY, &chip->flags); 10208c2ecf20Sopenharmony_ci else 10218c2ecf20Sopenharmony_ci set_bit(F_DISABLE_WRITE_NDELAY, &chip->flags); 10228c2ecf20Sopenharmony_ci#ifndef MSND_CLASSIC 10238c2ecf20Sopenharmony_ci if (digital[idx]) 10248c2ecf20Sopenharmony_ci set_bit(F_HAVEDIGITAL, &chip->flags); 10258c2ecf20Sopenharmony_ci#endif 10268c2ecf20Sopenharmony_ci spin_lock_init(&chip->lock); 10278c2ecf20Sopenharmony_ci err = snd_msnd_probe(card); 10288c2ecf20Sopenharmony_ci if (err < 0) { 10298c2ecf20Sopenharmony_ci printk(KERN_ERR LOGNAME ": Probe failed\n"); 10308c2ecf20Sopenharmony_ci snd_card_free(card); 10318c2ecf20Sopenharmony_ci return err; 10328c2ecf20Sopenharmony_ci } 10338c2ecf20Sopenharmony_ci 10348c2ecf20Sopenharmony_ci err = snd_msnd_attach(card); 10358c2ecf20Sopenharmony_ci if (err < 0) { 10368c2ecf20Sopenharmony_ci printk(KERN_ERR LOGNAME ": Attach failed\n"); 10378c2ecf20Sopenharmony_ci snd_card_free(card); 10388c2ecf20Sopenharmony_ci return err; 10398c2ecf20Sopenharmony_ci } 10408c2ecf20Sopenharmony_ci dev_set_drvdata(pdev, card); 10418c2ecf20Sopenharmony_ci 10428c2ecf20Sopenharmony_ci return 0; 10438c2ecf20Sopenharmony_ci 10448c2ecf20Sopenharmony_ci#ifndef MSND_CLASSIC 10458c2ecf20Sopenharmony_cicfg_error: 10468c2ecf20Sopenharmony_ci release_region(cfg[idx], 2); 10478c2ecf20Sopenharmony_ci snd_card_free(card); 10488c2ecf20Sopenharmony_ci return err; 10498c2ecf20Sopenharmony_ci#endif 10508c2ecf20Sopenharmony_ci} 10518c2ecf20Sopenharmony_ci 10528c2ecf20Sopenharmony_cistatic int snd_msnd_isa_remove(struct device *pdev, unsigned int dev) 10538c2ecf20Sopenharmony_ci{ 10548c2ecf20Sopenharmony_ci snd_msnd_unload(dev_get_drvdata(pdev)); 10558c2ecf20Sopenharmony_ci return 0; 10568c2ecf20Sopenharmony_ci} 10578c2ecf20Sopenharmony_ci 10588c2ecf20Sopenharmony_cistatic struct isa_driver snd_msnd_driver = { 10598c2ecf20Sopenharmony_ci .match = snd_msnd_isa_match, 10608c2ecf20Sopenharmony_ci .probe = snd_msnd_isa_probe, 10618c2ecf20Sopenharmony_ci .remove = snd_msnd_isa_remove, 10628c2ecf20Sopenharmony_ci /* FIXME: suspend, resume */ 10638c2ecf20Sopenharmony_ci .driver = { 10648c2ecf20Sopenharmony_ci .name = DEV_NAME 10658c2ecf20Sopenharmony_ci }, 10668c2ecf20Sopenharmony_ci}; 10678c2ecf20Sopenharmony_ci 10688c2ecf20Sopenharmony_ci#ifdef CONFIG_PNP 10698c2ecf20Sopenharmony_cistatic int snd_msnd_pnp_detect(struct pnp_card_link *pcard, 10708c2ecf20Sopenharmony_ci const struct pnp_card_device_id *pid) 10718c2ecf20Sopenharmony_ci{ 10728c2ecf20Sopenharmony_ci static int idx; 10738c2ecf20Sopenharmony_ci struct pnp_dev *pnp_dev; 10748c2ecf20Sopenharmony_ci struct pnp_dev *mpu_dev; 10758c2ecf20Sopenharmony_ci struct snd_card *card; 10768c2ecf20Sopenharmony_ci struct snd_msnd *chip; 10778c2ecf20Sopenharmony_ci int ret; 10788c2ecf20Sopenharmony_ci 10798c2ecf20Sopenharmony_ci for ( ; idx < SNDRV_CARDS; idx++) { 10808c2ecf20Sopenharmony_ci if (has_isapnp(idx)) 10818c2ecf20Sopenharmony_ci break; 10828c2ecf20Sopenharmony_ci } 10838c2ecf20Sopenharmony_ci if (idx >= SNDRV_CARDS) 10848c2ecf20Sopenharmony_ci return -ENODEV; 10858c2ecf20Sopenharmony_ci 10868c2ecf20Sopenharmony_ci /* 10878c2ecf20Sopenharmony_ci * Check that we still have room for another sound card ... 10888c2ecf20Sopenharmony_ci */ 10898c2ecf20Sopenharmony_ci pnp_dev = pnp_request_card_device(pcard, pid->devs[0].id, NULL); 10908c2ecf20Sopenharmony_ci if (!pnp_dev) 10918c2ecf20Sopenharmony_ci return -ENODEV; 10928c2ecf20Sopenharmony_ci 10938c2ecf20Sopenharmony_ci mpu_dev = pnp_request_card_device(pcard, pid->devs[1].id, NULL); 10948c2ecf20Sopenharmony_ci if (!mpu_dev) 10958c2ecf20Sopenharmony_ci return -ENODEV; 10968c2ecf20Sopenharmony_ci 10978c2ecf20Sopenharmony_ci if (!pnp_is_active(pnp_dev) && pnp_activate_dev(pnp_dev) < 0) { 10988c2ecf20Sopenharmony_ci printk(KERN_INFO "msnd_pinnacle: device is inactive\n"); 10998c2ecf20Sopenharmony_ci return -EBUSY; 11008c2ecf20Sopenharmony_ci } 11018c2ecf20Sopenharmony_ci 11028c2ecf20Sopenharmony_ci if (!pnp_is_active(mpu_dev) && pnp_activate_dev(mpu_dev) < 0) { 11038c2ecf20Sopenharmony_ci printk(KERN_INFO "msnd_pinnacle: MPU device is inactive\n"); 11048c2ecf20Sopenharmony_ci return -EBUSY; 11058c2ecf20Sopenharmony_ci } 11068c2ecf20Sopenharmony_ci 11078c2ecf20Sopenharmony_ci /* 11088c2ecf20Sopenharmony_ci * Create a new ALSA sound card entry, in anticipation 11098c2ecf20Sopenharmony_ci * of detecting our hardware ... 11108c2ecf20Sopenharmony_ci */ 11118c2ecf20Sopenharmony_ci ret = snd_card_new(&pcard->card->dev, 11128c2ecf20Sopenharmony_ci index[idx], id[idx], THIS_MODULE, 11138c2ecf20Sopenharmony_ci sizeof(struct snd_msnd), &card); 11148c2ecf20Sopenharmony_ci if (ret < 0) 11158c2ecf20Sopenharmony_ci return ret; 11168c2ecf20Sopenharmony_ci 11178c2ecf20Sopenharmony_ci chip = card->private_data; 11188c2ecf20Sopenharmony_ci chip->card = card; 11198c2ecf20Sopenharmony_ci 11208c2ecf20Sopenharmony_ci /* 11218c2ecf20Sopenharmony_ci * Read the correct parameters off the ISA PnP bus ... 11228c2ecf20Sopenharmony_ci */ 11238c2ecf20Sopenharmony_ci io[idx] = pnp_port_start(pnp_dev, 0); 11248c2ecf20Sopenharmony_ci irq[idx] = pnp_irq(pnp_dev, 0); 11258c2ecf20Sopenharmony_ci mem[idx] = pnp_mem_start(pnp_dev, 0); 11268c2ecf20Sopenharmony_ci mpu_io[idx] = pnp_port_start(mpu_dev, 0); 11278c2ecf20Sopenharmony_ci mpu_irq[idx] = pnp_irq(mpu_dev, 0); 11288c2ecf20Sopenharmony_ci 11298c2ecf20Sopenharmony_ci set_default_audio_parameters(chip); 11308c2ecf20Sopenharmony_ci#ifdef MSND_CLASSIC 11318c2ecf20Sopenharmony_ci chip->type = msndClassic; 11328c2ecf20Sopenharmony_ci#else 11338c2ecf20Sopenharmony_ci chip->type = msndPinnacle; 11348c2ecf20Sopenharmony_ci#endif 11358c2ecf20Sopenharmony_ci chip->io = io[idx]; 11368c2ecf20Sopenharmony_ci chip->irq = irq[idx]; 11378c2ecf20Sopenharmony_ci chip->base = mem[idx]; 11388c2ecf20Sopenharmony_ci 11398c2ecf20Sopenharmony_ci chip->calibrate_signal = calibrate_signal ? 1 : 0; 11408c2ecf20Sopenharmony_ci chip->recsrc = 0; 11418c2ecf20Sopenharmony_ci chip->dspq_data_buff = DSPQ_DATA_BUFF; 11428c2ecf20Sopenharmony_ci chip->dspq_buff_size = DSPQ_BUFF_SIZE; 11438c2ecf20Sopenharmony_ci if (write_ndelay[idx]) 11448c2ecf20Sopenharmony_ci clear_bit(F_DISABLE_WRITE_NDELAY, &chip->flags); 11458c2ecf20Sopenharmony_ci else 11468c2ecf20Sopenharmony_ci set_bit(F_DISABLE_WRITE_NDELAY, &chip->flags); 11478c2ecf20Sopenharmony_ci#ifndef MSND_CLASSIC 11488c2ecf20Sopenharmony_ci if (digital[idx]) 11498c2ecf20Sopenharmony_ci set_bit(F_HAVEDIGITAL, &chip->flags); 11508c2ecf20Sopenharmony_ci#endif 11518c2ecf20Sopenharmony_ci spin_lock_init(&chip->lock); 11528c2ecf20Sopenharmony_ci ret = snd_msnd_probe(card); 11538c2ecf20Sopenharmony_ci if (ret < 0) { 11548c2ecf20Sopenharmony_ci printk(KERN_ERR LOGNAME ": Probe failed\n"); 11558c2ecf20Sopenharmony_ci goto _release_card; 11568c2ecf20Sopenharmony_ci } 11578c2ecf20Sopenharmony_ci 11588c2ecf20Sopenharmony_ci ret = snd_msnd_attach(card); 11598c2ecf20Sopenharmony_ci if (ret < 0) { 11608c2ecf20Sopenharmony_ci printk(KERN_ERR LOGNAME ": Attach failed\n"); 11618c2ecf20Sopenharmony_ci goto _release_card; 11628c2ecf20Sopenharmony_ci } 11638c2ecf20Sopenharmony_ci 11648c2ecf20Sopenharmony_ci pnp_set_card_drvdata(pcard, card); 11658c2ecf20Sopenharmony_ci ++idx; 11668c2ecf20Sopenharmony_ci return 0; 11678c2ecf20Sopenharmony_ci 11688c2ecf20Sopenharmony_ci_release_card: 11698c2ecf20Sopenharmony_ci snd_card_free(card); 11708c2ecf20Sopenharmony_ci return ret; 11718c2ecf20Sopenharmony_ci} 11728c2ecf20Sopenharmony_ci 11738c2ecf20Sopenharmony_cistatic void snd_msnd_pnp_remove(struct pnp_card_link *pcard) 11748c2ecf20Sopenharmony_ci{ 11758c2ecf20Sopenharmony_ci snd_msnd_unload(pnp_get_card_drvdata(pcard)); 11768c2ecf20Sopenharmony_ci pnp_set_card_drvdata(pcard, NULL); 11778c2ecf20Sopenharmony_ci} 11788c2ecf20Sopenharmony_ci 11798c2ecf20Sopenharmony_cistatic int isa_registered; 11808c2ecf20Sopenharmony_cistatic int pnp_registered; 11818c2ecf20Sopenharmony_ci 11828c2ecf20Sopenharmony_cistatic const struct pnp_card_device_id msnd_pnpids[] = { 11838c2ecf20Sopenharmony_ci /* Pinnacle PnP */ 11848c2ecf20Sopenharmony_ci { .id = "BVJ0440", .devs = { { "TBS0000" }, { "TBS0001" } } }, 11858c2ecf20Sopenharmony_ci { .id = "" } /* end */ 11868c2ecf20Sopenharmony_ci}; 11878c2ecf20Sopenharmony_ci 11888c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(pnp_card, msnd_pnpids); 11898c2ecf20Sopenharmony_ci 11908c2ecf20Sopenharmony_cistatic struct pnp_card_driver msnd_pnpc_driver = { 11918c2ecf20Sopenharmony_ci .flags = PNP_DRIVER_RES_DO_NOT_CHANGE, 11928c2ecf20Sopenharmony_ci .name = "msnd_pinnacle", 11938c2ecf20Sopenharmony_ci .id_table = msnd_pnpids, 11948c2ecf20Sopenharmony_ci .probe = snd_msnd_pnp_detect, 11958c2ecf20Sopenharmony_ci .remove = snd_msnd_pnp_remove, 11968c2ecf20Sopenharmony_ci}; 11978c2ecf20Sopenharmony_ci#endif /* CONFIG_PNP */ 11988c2ecf20Sopenharmony_ci 11998c2ecf20Sopenharmony_cistatic int __init snd_msnd_init(void) 12008c2ecf20Sopenharmony_ci{ 12018c2ecf20Sopenharmony_ci int err; 12028c2ecf20Sopenharmony_ci 12038c2ecf20Sopenharmony_ci err = isa_register_driver(&snd_msnd_driver, SNDRV_CARDS); 12048c2ecf20Sopenharmony_ci#ifdef CONFIG_PNP 12058c2ecf20Sopenharmony_ci if (!err) 12068c2ecf20Sopenharmony_ci isa_registered = 1; 12078c2ecf20Sopenharmony_ci 12088c2ecf20Sopenharmony_ci err = pnp_register_card_driver(&msnd_pnpc_driver); 12098c2ecf20Sopenharmony_ci if (!err) 12108c2ecf20Sopenharmony_ci pnp_registered = 1; 12118c2ecf20Sopenharmony_ci 12128c2ecf20Sopenharmony_ci if (isa_registered) 12138c2ecf20Sopenharmony_ci err = 0; 12148c2ecf20Sopenharmony_ci#endif 12158c2ecf20Sopenharmony_ci return err; 12168c2ecf20Sopenharmony_ci} 12178c2ecf20Sopenharmony_ci 12188c2ecf20Sopenharmony_cistatic void __exit snd_msnd_exit(void) 12198c2ecf20Sopenharmony_ci{ 12208c2ecf20Sopenharmony_ci#ifdef CONFIG_PNP 12218c2ecf20Sopenharmony_ci if (pnp_registered) 12228c2ecf20Sopenharmony_ci pnp_unregister_card_driver(&msnd_pnpc_driver); 12238c2ecf20Sopenharmony_ci if (isa_registered) 12248c2ecf20Sopenharmony_ci#endif 12258c2ecf20Sopenharmony_ci isa_unregister_driver(&snd_msnd_driver); 12268c2ecf20Sopenharmony_ci} 12278c2ecf20Sopenharmony_ci 12288c2ecf20Sopenharmony_cimodule_init(snd_msnd_init); 12298c2ecf20Sopenharmony_cimodule_exit(snd_msnd_exit); 12308c2ecf20Sopenharmony_ci 1231