📄 opti92x-ad1848.c
字号:
/* card-opti92x-ad1848.c - driver for OPTi 82c92x based soundcards. Copyright (C) 1998-2000 by Massimo Piccioni <dafastidio@libero.it> Part of this code was developed at the Italian Ministry of Air Defence, Sixth Division (oh, che pace ...), Rome. Thanks to Maria Grazia Pollarini, Salvatore Vassallo. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/#include <sound/driver.h>#include <asm/io.h>#include <asm/dma.h>#include <linux/delay.h>#include <linux/init.h>#include <linux/slab.h>#include <linux/pnp.h>#include <linux/moduleparam.h>#include <sound/core.h>#ifdef CS4231#include <sound/cs4231.h>#else#ifndef OPTi93X#include <sound/ad1848.h>#else#include <sound/control.h>#include <sound/pcm.h>#endif /* OPTi93X */#endif /* CS4231 */#include <sound/mpu401.h>#include <sound/opl3.h>#ifndef OPTi93X#include <sound/opl4.h>#endif#define SNDRV_LEGACY_FIND_FREE_IRQ#define SNDRV_LEGACY_FIND_FREE_DMA#include <sound/initval.h>MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");MODULE_LICENSE("GPL");#ifdef OPTi93XMODULE_DESCRIPTION("OPTi93X");MODULE_SUPPORTED_DEVICE("{{OPTi,82C931/3}}");#else /* OPTi93X */#ifdef CS4231MODULE_DESCRIPTION("OPTi92X - CS4231");MODULE_SUPPORTED_DEVICE("{{OPTi,82C924 (CS4231)}," "{OPTi,82C925 (CS4231)}}");#else /* CS4231 */MODULE_DESCRIPTION("OPTi92X - AD1848");MODULE_SUPPORTED_DEVICE("{{OPTi,82C924 (AD1848)}," "{OPTi,82C925 (AD1848)}," "{OAK,Mozart}}");#endif /* CS4231 */#endif /* OPTi93X */static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */static char *id = SNDRV_DEFAULT_STR1; /* ID for this card *///static int enable = SNDRV_DEFAULT_ENABLE1; /* Enable this card */static int isapnp = 1; /* Enable ISA PnP detection */static long port = SNDRV_DEFAULT_PORT1; /* 0x530,0xe80,0xf40,0x604 */static long mpu_port = SNDRV_DEFAULT_PORT1; /* 0x300,0x310,0x320,0x330 */static long fm_port = SNDRV_DEFAULT_PORT1; /* 0x388 */static int irq = SNDRV_DEFAULT_IRQ1; /* 5,7,9,10,11 */static int mpu_irq = SNDRV_DEFAULT_IRQ1; /* 5,7,9,10 */static int dma1 = SNDRV_DEFAULT_DMA1; /* 0,1,3 */#if defined(CS4231) || defined(OPTi93X)static int dma2 = SNDRV_DEFAULT_DMA1; /* 0,1,3 */#endif /* CS4231 || OPTi93X */module_param(index, int, 0444);MODULE_PARM_DESC(index, "Index value for opti9xx based soundcard.");module_param(id, charp, 0444);MODULE_PARM_DESC(id, "ID string for opti9xx based soundcard.");//module_param(enable, bool, 0444);//MODULE_PARM_DESC(enable, "Enable opti9xx soundcard.");module_param(isapnp, bool, 0444);MODULE_PARM_DESC(isapnp, "Enable ISA PnP detection for specified soundcard.");module_param(port, long, 0444);MODULE_PARM_DESC(port, "WSS port # for opti9xx driver.");module_param(mpu_port, long, 0444);MODULE_PARM_DESC(mpu_port, "MPU-401 port # for opti9xx driver.");module_param(fm_port, long, 0444);MODULE_PARM_DESC(fm_port, "FM port # for opti9xx driver.");module_param(irq, int, 0444);MODULE_PARM_DESC(irq, "WSS irq # for opti9xx driver.");module_param(mpu_irq, int, 0444);MODULE_PARM_DESC(mpu_irq, "MPU-401 irq # for opti9xx driver.");module_param(dma1, int, 0444);MODULE_PARM_DESC(dma1, "1st dma # for opti9xx driver.");#if defined(CS4231) || defined(OPTi93X)module_param(dma2, int, 0444);MODULE_PARM_DESC(dma2, "2nd dma # for opti9xx driver.");#endif /* CS4231 || OPTi93X */#define OPTi9XX_HW_DETECT 0#define OPTi9XX_HW_82C928 1#define OPTi9XX_HW_82C929 2#define OPTi9XX_HW_82C924 3#define OPTi9XX_HW_82C925 4#define OPTi9XX_HW_82C930 5#define OPTi9XX_HW_82C931 6#define OPTi9XX_HW_82C933 7#define OPTi9XX_HW_LAST OPTi9XX_HW_82C933#define OPTi9XX_MC_REG(n) ntypedef struct _snd_opti9xx opti9xx_t;#ifdef OPTi93X#define OPTi93X_INDEX 0x00#define OPTi93X_DATA 0x01#define OPTi93X_STATUS 0x02#define OPTi93X_DDATA 0x03#define OPTi93X_PORT(chip, r) ((chip)->port + OPTi93X_##r)#define OPTi93X_MIXOUT_LEFT 0x00#define OPTi93X_MIXOUT_RIGHT 0x01#define OPTi93X_CD_LEFT_INPUT 0x02#define OPTi93X_CD_RIGHT_INPUT 0x03#define OPTi930_AUX_LEFT_INPUT 0x04#define OPTi930_AUX_RIGHT_INPUT 0x05#define OPTi931_FM_LEFT_INPUT 0x04#define OPTi931_FM_RIGHT_INPUT 0x05#define OPTi93X_DAC_LEFT 0x06#define OPTi93X_DAC_RIGHT 0x07#define OPTi93X_PLAY_FORMAT 0x08#define OPTi93X_IFACE_CONF 0x09#define OPTi93X_PIN_CTRL 0x0a#define OPTi93X_ERR_INIT 0x0b#define OPTi93X_ID 0x0c#define OPTi93X_PLAY_UPR_CNT 0x0e#define OPTi93X_PLAY_LWR_CNT 0x0f#define OPTi931_AUX_LEFT_INPUT 0x10#define OPTi931_AUX_RIGHT_INPUT 0x11#define OPTi93X_LINE_LEFT_INPUT 0x12#define OPTi93X_LINE_RIGHT_INPUT 0x13#define OPTi93X_MIC_LEFT_INPUT 0x14#define OPTi93X_MIC_RIGHT_INPUT 0x15#define OPTi93X_OUT_LEFT 0x16#define OPTi93X_OUT_RIGHT 0x17#define OPTi93X_CAPT_FORMAT 0x1c#define OPTi93X_CAPT_UPR_CNT 0x1e#define OPTi93X_CAPT_LWR_CNT 0x1f#define OPTi93X_TRD 0x20#define OPTi93X_MCE 0x40#define OPTi93X_INIT 0x80#define OPTi93X_MIXOUT_MIC_GAIN 0x20#define OPTi93X_MIXOUT_LINE 0x00#define OPTi93X_MIXOUT_CD 0x40#define OPTi93X_MIXOUT_MIC 0x80#define OPTi93X_MIXOUT_MIXER 0xc0#define OPTi93X_STEREO 0x10#define OPTi93X_LINEAR_8 0x00#define OPTi93X_ULAW_8 0x20#define OPTi93X_LINEAR_16_LIT 0x40#define OPTi93X_ALAW_8 0x60#define OPTi93X_ADPCM_16 0xa0#define OPTi93X_LINEAR_16_BIG 0xc0#define OPTi93X_CAPTURE_PIO 0x80#define OPTi93X_PLAYBACK_PIO 0x40#define OPTi93X_AUTOCALIB 0x08#define OPTi93X_SINGLE_DMA 0x04#define OPTi93X_CAPTURE_ENABLE 0x02#define OPTi93X_PLAYBACK_ENABLE 0x01#define OPTi93X_IRQ_ENABLE 0x02#define OPTi93X_DMA_REQUEST 0x10#define OPTi93X_CALIB_IN_PROGRESS 0x20#define OPTi93X_IRQ_PLAYBACK 0x04#define OPTi93X_IRQ_CAPTURE 0x08typedef struct _snd_opti93x opti93x_t;struct _snd_opti93x { unsigned long port; struct resource *res_port; int irq; int dma1; int dma2; opti9xx_t *chip; unsigned short hardware; unsigned char image[32]; unsigned char mce_bit; unsigned short mode; int mute; spinlock_t lock; snd_card_t *card; snd_pcm_t *pcm; snd_pcm_substream_t *playback_substream; snd_pcm_substream_t *capture_substream; unsigned int p_dma_size; unsigned int c_dma_size;};#define OPTi93X_MODE_NONE 0x00#define OPTi93X_MODE_PLAY 0x01#define OPTi93X_MODE_CAPTURE 0x02#define OPTi93X_MODE_OPEN (OPTi93X_MODE_PLAY | OPTi93X_MODE_CAPTURE)#endif /* OPTi93X */struct _snd_opti9xx { unsigned short hardware; unsigned char password; char name[7]; unsigned long mc_base; struct resource *res_mc_base; unsigned long mc_base_size;#ifdef OPTi93X unsigned long mc_indir_index;#endif /* OPTi93X */ unsigned long pwd_reg; spinlock_t lock; long wss_base; int irq; int dma1;#if defined(CS4231) || defined(OPTi93X) int dma2;#endif /* CS4231 || OPTi93X */ long fm_port; long mpu_port; int mpu_irq;#ifdef CONFIG_PNP struct pnp_dev *dev; struct pnp_dev *devmpu;#endif /* CONFIG_PNP */};static int snd_opti9xx_first_hit = 1;static snd_card_t *snd_opti9xx_legacy = SNDRV_DEFAULT_PTR1;#ifdef CONFIG_PNPstatic struct pnp_card_device_id snd_opti9xx_pnpids[] = {#ifndef OPTi93X /* OPTi 82C924 */ { .id = "OPT0924", .devs = { { "OPT0000" }, { "OPT0002" } }, .driver_data = 0x0924 }, /* OPTi 82C925 */ { .id = "OPT0925", .devs = { { "OPT9250" }, { "OPT0002" } }, .driver_data = 0x0925 },#else /* OPTi 82C931/3 */ { .id = "OPT0931", .devs = { { "OPT9310" }, { "OPT0002" } }, .driver_data = 0x0931 },#endif /* OPTi93X */ { .id = "" }};MODULE_DEVICE_TABLE(pnp_card, snd_opti9xx_pnpids);#endif /* CONFIG_PNP */#ifdef OPTi93X#define DRIVER_NAME "snd-card-opti93x"#else#define DRIVER_NAME "snd-card-opti92x"#endif /* OPTi93X */static char * snd_opti9xx_names[] = { "unkown", "82C928", "82C929", "82C924", "82C925", "82C930", "82C931", "82C933"};static long snd_legacy_find_free_ioport(long *port_table, long size){ while (*port_table != -1) { if (request_region(*port_table, size, "ALSA test")) { release_region(*port_table, size); return *port_table; } port_table++; } return -1;}static int __devinit snd_opti9xx_init(opti9xx_t *chip, unsigned short hardware){ static int opti9xx_mc_size[] = {7, 7, 10, 10, 2, 2, 2}; chip->hardware = hardware; strcpy(chip->name, snd_opti9xx_names[hardware]); chip->mc_base_size = opti9xx_mc_size[hardware]; spin_lock_init(&chip->lock); chip->wss_base = -1; chip->irq = -1; chip->dma1 = -1;#if defined(CS4231) || defined (OPTi93X) chip->dma2 = -1;#endif /* CS4231 || OPTi93X */ chip->fm_port = -1; chip->mpu_port = -1; chip->mpu_irq = -1; switch (hardware) {#ifndef OPTi93X case OPTi9XX_HW_82C928: case OPTi9XX_HW_82C929: chip->mc_base = 0xf8c; chip->password = (hardware == OPTi9XX_HW_82C928) ? 0xe2 : 0xe3; chip->pwd_reg = 3; break; case OPTi9XX_HW_82C924: case OPTi9XX_HW_82C925: chip->mc_base = 0xf8c; chip->password = 0xe5; chip->pwd_reg = 3; break;#else /* OPTi93X */ case OPTi9XX_HW_82C930: case OPTi9XX_HW_82C931: case OPTi9XX_HW_82C933: chip->mc_base = (hardware == OPTi9XX_HW_82C930) ? 0xf8f : 0xf8d; chip->mc_indir_index = 0xe0e; chip->password = 0xe4; chip->pwd_reg = 0; break;#endif /* OPTi93X */ default: snd_printk("chip %d not supported\n", hardware); return -ENODEV; } return 0;}static unsigned char snd_opti9xx_read(opti9xx_t *chip, unsigned char reg){ unsigned long flags; unsigned char retval = 0xff; spin_lock_irqsave(&chip->lock, flags); outb(chip->password, chip->mc_base + chip->pwd_reg); switch (chip->hardware) {#ifndef OPTi93X case OPTi9XX_HW_82C924: case OPTi9XX_HW_82C925: if (reg > 7) { outb(reg, chip->mc_base + 8); outb(chip->password, chip->mc_base + chip->pwd_reg); retval = inb(chip->mc_base + 9); break; } case OPTi9XX_HW_82C928: case OPTi9XX_HW_82C929: retval = inb(chip->mc_base + reg); break;#else /* OPTi93X */ case OPTi9XX_HW_82C930: case OPTi9XX_HW_82C931: case OPTi9XX_HW_82C933: outb(reg, chip->mc_indir_index); outb(chip->password, chip->mc_base + chip->pwd_reg); retval = inb(chip->mc_indir_index + 1); break;#endif /* OPTi93X */ default: snd_printk("chip %d not supported\n", chip->hardware); } spin_unlock_irqrestore(&chip->lock, flags); return retval;} static void snd_opti9xx_write(opti9xx_t *chip, unsigned char reg, unsigned char value){ unsigned long flags; spin_lock_irqsave(&chip->lock, flags); outb(chip->password, chip->mc_base + chip->pwd_reg); switch (chip->hardware) {#ifndef OPTi93X case OPTi9XX_HW_82C924: case OPTi9XX_HW_82C925: if (reg > 7) { outb(reg, chip->mc_base + 8); outb(chip->password, chip->mc_base + chip->pwd_reg); outb(value, chip->mc_base + 9); break; } case OPTi9XX_HW_82C928: case OPTi9XX_HW_82C929: outb(value, chip->mc_base + reg); break;#else /* OPTi93X */ case OPTi9XX_HW_82C930: case OPTi9XX_HW_82C931: case OPTi9XX_HW_82C933: outb(reg, chip->mc_indir_index); outb(chip->password, chip->mc_base + chip->pwd_reg); outb(value, chip->mc_indir_index + 1); break;#endif /* OPTi93X */ default: snd_printk("chip %d not supported\n", chip->hardware);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -