📄 fm801.c
字号:
/* * The driver for the ForteMedia FM801 based soundcards * Copyright (c) by Jaroslav Kysela <perex@perex.cz> * * Support FM only card by Andy Shevchenko <andy@smile.org.ua> * * 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 <linux/delay.h>#include <linux/init.h>#include <linux/interrupt.h>#include <linux/pci.h>#include <linux/slab.h>#include <linux/moduleparam.h>#include <sound/core.h>#include <sound/pcm.h>#include <sound/tlv.h>#include <sound/ac97_codec.h>#include <sound/mpu401.h>#include <sound/opl3.h>#include <sound/initval.h>#include <asm/io.h>#ifdef CONFIG_SND_FM801_TEA575X_BOOL#include <sound/tea575x-tuner.h>#define TEA575X_RADIO 1#endifMODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");MODULE_DESCRIPTION("ForteMedia FM801");MODULE_LICENSE("GPL");MODULE_SUPPORTED_DEVICE("{{ForteMedia,FM801}," "{Genius,SoundMaker Live 5.1}}");static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card *//* * Enable TEA575x tuner * 1 = MediaForte 256-PCS * 2 = MediaForte 256-PCPR * 3 = MediaForte 64-PCR * 16 = setup tuner only (this is additional bit), i.e. SF-64-PCR FM card * High 16-bits are video (radio) device number + 1 */static int tea575x_tuner[SNDRV_CARDS];module_param_array(index, int, NULL, 0444);MODULE_PARM_DESC(index, "Index value for the FM801 soundcard.");module_param_array(id, charp, NULL, 0444);MODULE_PARM_DESC(id, "ID string for the FM801 soundcard.");module_param_array(enable, bool, NULL, 0444);MODULE_PARM_DESC(enable, "Enable FM801 soundcard.");module_param_array(tea575x_tuner, int, NULL, 0444);MODULE_PARM_DESC(tea575x_tuner, "Enable TEA575x tuner.");/* * Direct registers */#define FM801_REG(chip, reg) (chip->port + FM801_##reg)#define FM801_PCM_VOL 0x00 /* PCM Output Volume */#define FM801_FM_VOL 0x02 /* FM Output Volume */#define FM801_I2S_VOL 0x04 /* I2S Volume */#define FM801_REC_SRC 0x06 /* Record Source */#define FM801_PLY_CTRL 0x08 /* Playback Control */#define FM801_PLY_COUNT 0x0a /* Playback Count */#define FM801_PLY_BUF1 0x0c /* Playback Bufer I */#define FM801_PLY_BUF2 0x10 /* Playback Buffer II */#define FM801_CAP_CTRL 0x14 /* Capture Control */#define FM801_CAP_COUNT 0x16 /* Capture Count */#define FM801_CAP_BUF1 0x18 /* Capture Buffer I */#define FM801_CAP_BUF2 0x1c /* Capture Buffer II */#define FM801_CODEC_CTRL 0x22 /* Codec Control */#define FM801_I2S_MODE 0x24 /* I2S Mode Control */#define FM801_VOLUME 0x26 /* Volume Up/Down/Mute Status */#define FM801_I2C_CTRL 0x29 /* I2C Control */#define FM801_AC97_CMD 0x2a /* AC'97 Command */#define FM801_AC97_DATA 0x2c /* AC'97 Data */#define FM801_MPU401_DATA 0x30 /* MPU401 Data */#define FM801_MPU401_CMD 0x31 /* MPU401 Command */#define FM801_GPIO_CTRL 0x52 /* General Purpose I/O Control */#define FM801_GEN_CTRL 0x54 /* General Control */#define FM801_IRQ_MASK 0x56 /* Interrupt Mask */#define FM801_IRQ_STATUS 0x5a /* Interrupt Status */#define FM801_OPL3_BANK0 0x68 /* OPL3 Status Read / Bank 0 Write */#define FM801_OPL3_DATA0 0x69 /* OPL3 Data 0 Write */#define FM801_OPL3_BANK1 0x6a /* OPL3 Bank 1 Write */#define FM801_OPL3_DATA1 0x6b /* OPL3 Bank 1 Write */#define FM801_POWERDOWN 0x70 /* Blocks Power Down Control *//* codec access */#define FM801_AC97_READ (1<<7) /* read=1, write=0 */#define FM801_AC97_VALID (1<<8) /* port valid=1 */#define FM801_AC97_BUSY (1<<9) /* busy=1 */#define FM801_AC97_ADDR_SHIFT 10 /* codec id (2bit) *//* playback and record control register bits */#define FM801_BUF1_LAST (1<<1)#define FM801_BUF2_LAST (1<<2)#define FM801_START (1<<5)#define FM801_PAUSE (1<<6)#define FM801_IMMED_STOP (1<<7)#define FM801_RATE_SHIFT 8#define FM801_RATE_MASK (15 << FM801_RATE_SHIFT)#define FM801_CHANNELS_4 (1<<12) /* playback only */#define FM801_CHANNELS_6 (2<<12) /* playback only */#define FM801_CHANNELS_6MS (3<<12) /* playback only */#define FM801_CHANNELS_MASK (3<<12)#define FM801_16BIT (1<<14)#define FM801_STEREO (1<<15)/* IRQ status bits */#define FM801_IRQ_PLAYBACK (1<<8)#define FM801_IRQ_CAPTURE (1<<9)#define FM801_IRQ_VOLUME (1<<14)#define FM801_IRQ_MPU (1<<15)/* GPIO control register */#define FM801_GPIO_GP0 (1<<0) /* read/write */#define FM801_GPIO_GP1 (1<<1)#define FM801_GPIO_GP2 (1<<2)#define FM801_GPIO_GP3 (1<<3)#define FM801_GPIO_GP(x) (1<<(0+(x)))#define FM801_GPIO_GD0 (1<<8) /* directions: 1 = input, 0 = output*/#define FM801_GPIO_GD1 (1<<9)#define FM801_GPIO_GD2 (1<<10)#define FM801_GPIO_GD3 (1<<11)#define FM801_GPIO_GD(x) (1<<(8+(x)))#define FM801_GPIO_GS0 (1<<12) /* function select: */#define FM801_GPIO_GS1 (1<<13) /* 1 = GPIO */#define FM801_GPIO_GS2 (1<<14) /* 0 = other (S/PDIF, VOL) */#define FM801_GPIO_GS3 (1<<15)#define FM801_GPIO_GS(x) (1<<(12+(x))) /* */struct fm801 { int irq; unsigned long port; /* I/O port number */ unsigned int multichannel: 1, /* multichannel support */ secondary: 1; /* secondary codec */ unsigned char secondary_addr; /* address of the secondary codec */ unsigned int tea575x_tuner; /* tuner flags */ unsigned short ply_ctrl; /* playback control */ unsigned short cap_ctrl; /* capture control */ unsigned long ply_buffer; unsigned int ply_buf; unsigned int ply_count; unsigned int ply_size; unsigned int ply_pos; unsigned long cap_buffer; unsigned int cap_buf; unsigned int cap_count; unsigned int cap_size; unsigned int cap_pos; struct snd_ac97_bus *ac97_bus; struct snd_ac97 *ac97; struct snd_ac97 *ac97_sec; struct pci_dev *pci; struct snd_card *card; struct snd_pcm *pcm; struct snd_rawmidi *rmidi; struct snd_pcm_substream *playback_substream; struct snd_pcm_substream *capture_substream; unsigned int p_dma_size; unsigned int c_dma_size; spinlock_t reg_lock; struct snd_info_entry *proc_entry;#ifdef TEA575X_RADIO struct snd_tea575x tea;#endif#ifdef CONFIG_PM u16 saved_regs[0x20];#endif};static struct pci_device_id snd_fm801_ids[] = { { 0x1319, 0x0801, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0, }, /* FM801 */ { 0x5213, 0x0510, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0, }, /* Gallant Odyssey Sound 4 */ { 0, }};MODULE_DEVICE_TABLE(pci, snd_fm801_ids);/* * common I/O routines */static int snd_fm801_update_bits(struct fm801 *chip, unsigned short reg, unsigned short mask, unsigned short value){ int change; unsigned long flags; unsigned short old, new; spin_lock_irqsave(&chip->reg_lock, flags); old = inw(chip->port + reg); new = (old & ~mask) | value; change = old != new; if (change) outw(new, chip->port + reg); spin_unlock_irqrestore(&chip->reg_lock, flags); return change;}static void snd_fm801_codec_write(struct snd_ac97 *ac97, unsigned short reg, unsigned short val){ struct fm801 *chip = ac97->private_data; int idx; /* * Wait until the codec interface is not ready.. */ for (idx = 0; idx < 100; idx++) { if (!(inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_BUSY)) goto ok1; udelay(10); } snd_printk(KERN_ERR "AC'97 interface is busy (1)\n"); return; ok1: /* write data and address */ outw(val, FM801_REG(chip, AC97_DATA)); outw(reg | (ac97->addr << FM801_AC97_ADDR_SHIFT), FM801_REG(chip, AC97_CMD)); /* * Wait until the write command is not completed.. */ for (idx = 0; idx < 1000; idx++) { if (!(inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_BUSY)) return; udelay(10); } snd_printk(KERN_ERR "AC'97 interface #%d is busy (2)\n", ac97->num);}static unsigned short snd_fm801_codec_read(struct snd_ac97 *ac97, unsigned short reg){ struct fm801 *chip = ac97->private_data; int idx; /* * Wait until the codec interface is not ready.. */ for (idx = 0; idx < 100; idx++) { if (!(inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_BUSY)) goto ok1; udelay(10); } snd_printk(KERN_ERR "AC'97 interface is busy (1)\n"); return 0; ok1: /* read command */ outw(reg | (ac97->addr << FM801_AC97_ADDR_SHIFT) | FM801_AC97_READ, FM801_REG(chip, AC97_CMD)); for (idx = 0; idx < 100; idx++) { if (!(inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_BUSY)) goto ok2; udelay(10); } snd_printk(KERN_ERR "AC'97 interface #%d is busy (2)\n", ac97->num); return 0; ok2: for (idx = 0; idx < 1000; idx++) { if (inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_VALID) goto ok3; udelay(10); } snd_printk(KERN_ERR "AC'97 interface #%d is not valid (2)\n", ac97->num); return 0; ok3: return inw(FM801_REG(chip, AC97_DATA));}static unsigned int rates[] = { 5500, 8000, 9600, 11025, 16000, 19200, 22050, 32000, 38400, 44100, 48000};static struct snd_pcm_hw_constraint_list hw_constraints_rates = { .count = ARRAY_SIZE(rates), .list = rates, .mask = 0,};static unsigned int channels[] = { 2, 4, 6};static struct snd_pcm_hw_constraint_list hw_constraints_channels = { .count = ARRAY_SIZE(channels), .list = channels, .mask = 0,};/* * Sample rate routines */static unsigned short snd_fm801_rate_bits(unsigned int rate){ unsigned int idx; for (idx = 0; idx < ARRAY_SIZE(rates); idx++) if (rates[idx] == rate) return idx; snd_BUG(); return ARRAY_SIZE(rates) - 1;}/* * PCM part */static int snd_fm801_playback_trigger(struct snd_pcm_substream *substream, int cmd){ struct fm801 *chip = snd_pcm_substream_chip(substream); spin_lock(&chip->reg_lock); switch (cmd) { case SNDRV_PCM_TRIGGER_START: chip->ply_ctrl &= ~(FM801_BUF1_LAST | FM801_BUF2_LAST | FM801_PAUSE); chip->ply_ctrl |= FM801_START | FM801_IMMED_STOP; break; case SNDRV_PCM_TRIGGER_STOP: chip->ply_ctrl &= ~(FM801_START | FM801_PAUSE); break; case SNDRV_PCM_TRIGGER_PAUSE_PUSH: case SNDRV_PCM_TRIGGER_SUSPEND: chip->ply_ctrl |= FM801_PAUSE; break; case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: case SNDRV_PCM_TRIGGER_RESUME: chip->ply_ctrl &= ~FM801_PAUSE; break; default: spin_unlock(&chip->reg_lock); snd_BUG(); return -EINVAL; } outw(chip->ply_ctrl, FM801_REG(chip, PLY_CTRL)); spin_unlock(&chip->reg_lock); return 0;}static int snd_fm801_capture_trigger(struct snd_pcm_substream *substream, int cmd){ struct fm801 *chip = snd_pcm_substream_chip(substream); spin_lock(&chip->reg_lock); switch (cmd) { case SNDRV_PCM_TRIGGER_START: chip->cap_ctrl &= ~(FM801_BUF1_LAST | FM801_BUF2_LAST | FM801_PAUSE); chip->cap_ctrl |= FM801_START | FM801_IMMED_STOP;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -