⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nm256_audio.c

📁 linux和2410结合开发 用他可以生成2410所需的zImage文件
💻 C
📖 第 1 页 / 共 3 页
字号:
		stopRecord (card);	    badintrcount = 0;	}	return;    }    badintrcount = 0;    /* Rather boring; check for individual interrupts and process them. */    if (status & NM_PLAYBACK_INT) {	status &= ~NM_PLAYBACK_INT;	NM_ACK_INT (card, NM_PLAYBACK_INT);	if (card->playing)	    nm256_get_new_block (card);    }    if (status & NM_RECORD_INT) {	status &= ~NM_RECORD_INT;	NM_ACK_INT (card, NM_RECORD_INT);	if (card->recording)	    nm256_read_block (card);    }    if (status & NM_MISC_INT_1) {	u8 cbyte;	status &= ~NM_MISC_INT_1;	printk (KERN_ERR "NM256: Got misc interrupt #1\n");	NM_ACK_INT (card, NM_MISC_INT_1);	nm256_writePort16 (card, 2, NM_INT_REG, 0x8000);	cbyte = nm256_readPort8 (card, 2, 0x400);	nm256_writePort8 (card, 2, 0x400, cbyte | 2);    }    if (status & NM_MISC_INT_2) {	u8 cbyte;	status &= ~NM_MISC_INT_2;	printk (KERN_ERR "NM256: Got misc interrupt #2\n");	NM_ACK_INT (card, NM_MISC_INT_2);	cbyte = nm256_readPort8 (card, 2, 0x400);	nm256_writePort8 (card, 2, 0x400, cbyte & ~2);    }    /* Unknown interrupt. */    if (status) {	printk (KERN_ERR "NM256: Fire in the hole! Unknown status 0x%x\n",		status);	/* Pray. */	NM_ACK_INT (card, status);    }}/* * Handle a potential interrupt for the device referred to by DEV_ID. * This handler is for the 256ZX, and is very similar to the non-ZX * routine. */static voidnm256_interrupt_zx (int irq, void *dev_id, struct pt_regs *dummy){    struct nm256_info *card = (struct nm256_info *)dev_id;    u32 status;    static int badintrcount = 0;    if ((card == NULL) || (card->magsig != NM_MAGIC_SIG)) {	printk (KERN_ERR "NM256: Bad card pointer\n");	return;    }    status = nm256_readPort32 (card, 2, NM_INT_REG);    /* Not ours. */    if (status == 0) {	if (badintrcount++ > 1000) {	    printk (KERN_ERR "NM256: Releasing interrupt, over 1000 invalid interrupts\n");	    /*	     * I'm not sure if the best thing is to stop the card from	     * playing or just release the interrupt (after all, we're in	     * a bad situation, so doing fancy stuff may not be such a good	     * idea).	     *	     * I worry about the card engine continuing to play noise	     * over and over, however--that could become a very	     * obnoxious problem.  And we know that when this usually	     * happens things are fairly safe, it just means the user's	     * inserted a PCMCIA card and someone's spamming us with 	     * IRQ 9s.	     */	    if (card->playing)		stopPlay (card);	    if (card->recording)		stopRecord (card);	    badintrcount = 0;	}	return;    }    badintrcount = 0;    /* Rather boring; check for individual interrupts and process them. */    if (status & NM2_PLAYBACK_INT) {	status &= ~NM2_PLAYBACK_INT;	NM2_ACK_INT (card, NM2_PLAYBACK_INT);	if (card->playing)	    nm256_get_new_block (card);    }    if (status & NM2_RECORD_INT) {	status &= ~NM2_RECORD_INT;	NM2_ACK_INT (card, NM2_RECORD_INT);	if (card->recording)	    nm256_read_block (card);    }    if (status & NM2_MISC_INT_1) {	u8 cbyte;	status &= ~NM2_MISC_INT_1;	printk (KERN_ERR "NM256: Got misc interrupt #1\n");	NM2_ACK_INT (card, NM2_MISC_INT_1);	cbyte = nm256_readPort8 (card, 2, 0x400);	nm256_writePort8 (card, 2, 0x400, cbyte | 2);    }    if (status & NM2_MISC_INT_2) {	u8 cbyte;	status &= ~NM2_MISC_INT_2;	printk (KERN_ERR "NM256: Got misc interrupt #2\n");	NM2_ACK_INT (card, NM2_MISC_INT_2);	cbyte = nm256_readPort8 (card, 2, 0x400);	nm256_writePort8 (card, 2, 0x400, cbyte & ~2);    }    /* Unknown interrupt. */    if (status) {	printk (KERN_ERR "NM256: Fire in the hole! Unknown status 0x%x\n",		status);	/* Pray. */	NM2_ACK_INT (card, status);    }}/*  * Request our interrupt. */static intnm256_grabInterrupt (struct nm256_info *card){    if (card->has_irq++ == 0) {	if (request_irq (card->irq, card->introutine, SA_SHIRQ,			 "NM256_audio", card) < 0) {	    printk (KERN_ERR "NM256: can't obtain IRQ %d\n", card->irq);	    return -1;	}    }    return 0;}/*  * Release our interrupt.  */static intnm256_releaseInterrupt (struct nm256_info *card){    if (card->has_irq <= 0) {	printk (KERN_ERR "nm256: too many calls to releaseInterrupt\n");	return -1;    }    card->has_irq--;    if (card->has_irq == 0) {	free_irq (card->irq, card);    }    return 0;}/* * Waits for the mixer to become ready to be written; returns a zero value * if it timed out. */static intnm256_isReady (struct ac97_hwint *dev){    struct nm256_info *card = (struct nm256_info *)dev->driver_private;    int t2 = 10;    u32 testaddr;    u16 testb;    int done = 0;    if (card->magsig != NM_MAGIC_SIG) {	printk (KERN_ERR "NM256: Bad magic signature in isReady!\n");	return 0;    }    testaddr = card->mixer_status_offset;    testb = card->mixer_status_mask;    /*      * Loop around waiting for the mixer to become ready.      */    while (! done && t2-- > 0) {	if ((nm256_readPort16 (card, 2, testaddr) & testb) == 0)	    done = 1;	else	    udelay (100);    }    return done;}/* * Return the contents of the AC97 mixer register REG.  Returns a positive * value if successful, or a negative error code. */static intnm256_readAC97Reg (struct ac97_hwint *dev, u8 reg){    struct nm256_info *card = (struct nm256_info *)dev->driver_private;    if (card->magsig != NM_MAGIC_SIG) {	printk (KERN_ERR "NM256: Bad magic signature in readAC97Reg!\n");	return -EINVAL;    }    if (reg < 128) {	int res;	nm256_isReady (dev);	res = nm256_readPort16 (card, 2, card->mixer + reg);	/* Magic delay.  Bleah yucky.  */        udelay (1000);	return res;    }    else	return -EINVAL;}/*  * Writes VALUE to AC97 mixer register REG.  Returns 0 if successful, or * a negative error code.  */static intnm256_writeAC97Reg (struct ac97_hwint *dev, u8 reg, u16 value){    unsigned long flags;    int tries = 2;    int done = 0;    u32 base;    struct nm256_info *card = (struct nm256_info *)dev->driver_private;    if (card->magsig != NM_MAGIC_SIG) {	printk (KERN_ERR "NM256: Bad magic signature in writeAC97Reg!\n");	return -EINVAL;    }    base = card->mixer;    save_flags (flags);    cli ();    nm256_isReady (dev);    /* Wait for the write to take, too. */    while ((tries-- > 0) && !done) {	nm256_writePort16 (card, 2, base + reg, value);	if (nm256_isReady (dev)) {	    done = 1;	    break;	}    }    restore_flags (flags);    udelay (1000);    return ! done;}/*  * Initial register values to be written to the AC97 mixer. * While most of these are identical to the reset values, we do this * so that we have most of the register contents cached--this avoids * reading from the mixer directly (which seems to be problematic, * probably due to ignorance). */struct initialValues {    unsigned short port;    unsigned short value;};static struct initialValues nm256_ac97_initial_values[] = {    { AC97_MASTER_VOL_STEREO, 0x8000 },    { AC97_HEADPHONE_VOL,     0x8000 },    { AC97_MASTER_VOL_MONO,   0x0000 },    { AC97_PCBEEP_VOL,        0x0000 },    { AC97_PHONE_VOL,         0x0008 },    { AC97_MIC_VOL,           0x8000 },    { AC97_LINEIN_VOL,        0x8808 },    { AC97_CD_VOL,            0x8808 },    { AC97_VIDEO_VOL,         0x8808 },    { AC97_AUX_VOL,           0x8808 },    { AC97_PCMOUT_VOL,        0x0808 },    { AC97_RECORD_SELECT,     0x0000 },    { AC97_RECORD_GAIN,       0x0B0B },    { AC97_GENERAL_PURPOSE,   0x0000 },    { 0xffff, 0xffff }};/* Initialize the AC97 into a known state.  */static intnm256_resetAC97 (struct ac97_hwint *dev){    struct nm256_info *card = (struct nm256_info *)dev->driver_private;    int x;    if (card->magsig != NM_MAGIC_SIG) {	printk (KERN_ERR "NM256: Bad magic signature in resetAC97!\n");	return -EINVAL;    }    /* Reset the mixer.  'Tis magic!  */    nm256_writePort8 (card, 2, 0x6c0, 1);    nm256_writePort8 (card, 2, 0x6cc, 0x87);    nm256_writePort8 (card, 2, 0x6cc, 0x80);    nm256_writePort8 (card, 2, 0x6cc, 0x0);    if (! card->mixer_values_init) {	for (x = 0; nm256_ac97_initial_values[x].port != 0xffff; x++) {	    ac97_put_register (dev,			       nm256_ac97_initial_values[x].port,			       nm256_ac97_initial_values[x].value);	    card->mixer_values_init = 1;	}    }    return 0;}/* * We don't do anything particularly special here; it just passes the * mixer ioctl to the AC97 driver. */static intnm256_default_mixer_ioctl (int dev, unsigned int cmd, caddr_t arg){    struct nm256_info *card = nm256_find_card_for_mixer (dev);    if (card != NULL)	return ac97_mixer_ioctl (&(card->mdev), cmd, arg);    else	return -ENODEV;}static struct mixer_operations nm256_mixer_operations = {    owner:	THIS_MODULE,    id:		"NeoMagic",    name:	"NM256AC97Mixer",    ioctl:	nm256_default_mixer_ioctl};/* * Default settings for the OSS mixer.  These are set last, after the * mixer is initialized. * * I "love" C sometimes.  Got braces? */static struct ac97_mixer_value_list mixer_defaults[] = {    { SOUND_MIXER_VOLUME,  { { 85, 85 } } },    { SOUND_MIXER_SPEAKER, { { 100 } } },    { SOUND_MIXER_PCM,     { { 65, 65 } } },    { SOUND_MIXER_CD,      { { 65, 65 } } },    { -1,                  {  { 0,  0 } } }};/* Installs the AC97 mixer into CARD.  */static int __initnm256_install_mixer (struct nm256_info *card){    int mixer;    card->mdev.reset_device = nm256_resetAC97;    card->mdev.read_reg = nm256_readAC97Reg;    card->mdev.write_reg = nm256_writeAC97Reg;    card->mdev.driver_private = (void *)card;    if (ac97_init (&(card->mdev)))	return -1;    mixer = sound_alloc_mixerdev();    if (num_mixers >= MAX_MIXER_DEV) {	printk ("NM256 mixer: Unable to alloc mixerdev\n");	return -1;    }    mixer_devs[mixer] = &nm256_mixer_operations;    card->mixer_oss_dev = mixer;    /* Some reasonable default values.  */    ac97_set_values (&(card->mdev), mixer_defaults);    printk(KERN_INFO "Initialized AC97 mixer\n");    return 0;}/* Perform a full reset on the hardware; this is invoked when an APM   resume event occurs.  */static voidnm256_full_reset (struct nm256_info *card){    nm256_initHw (card);    ac97_reset (&(card->mdev));}/*  * See if the signature left by the NM256 BIOS is intact; if so, we use * the associated address as the end of our audio buffer in the video * RAM. */static void __initnm256_peek_for_sig (struct nm256_info *card){    u32 port1offset 	= card->port[0].physaddr + card->port[0].end_offset - 0x0400;    /* The signature is located 1K below the end of video RAM.  */    char *temp = ioremap_nocache (port1offset, 16);    /* Default buffer end is 5120 bytes below the top of RAM.  */    u32 default_value = card->port[0].end_offset - 0x1400;    u32 sig;    /* Install the default value first, so we don't have to repeatedly       do it if there is a problem.  */    card->port[0].end_offset = default_value;    if (temp == NULL) {	printk (KERN_ERR "NM256: Unable to scan for card signature in video RAM\n");	return;    }    sig = readl (temp);    if ((sig & NM_SIG_MASK) == NM_SIGNATURE) {	u32 pointer = readl (temp + 4);	/*	 * If it's obviously invalid, don't use it (the port already has a	 * suitable default value set).	 */	if (pointer != 0xffffffff)	    card->port[0].end_offset = pointer;	printk (KERN_INFO "NM256: Found card signature in video RAM: 0x%x\n",		pointer);    }    iounmap (temp);}/*  * Install a driver for the PCI device referenced by PCIDEV. * VERSTR is a human-readable version string. */static int __initnm256_install(struct pci_dev *pcidev, enum nm256rev rev, char *verstr){    struct nm256_info *card;    struct pm_dev *pmdev;    int x;    if (pci_enable_device(pcidev))	    return 0;    card = kmalloc (sizeof (struct nm256_info), GFP_KERNEL);    if (card == NULL) {	printk (KERN_ERR "NM256: out of memory!\n");	return 0;    }    card->magsig = NM_MAGIC_SIG;    card->playing  = 0;    card->recording = 0;    card->rev = rev;    /* Init the memory port info.  */    for (x = 0; x < 2; x++) {	card->port[x].physaddr = pci_resource_start (pcidev, x);	card->port[x].ptr = NULL;	card->port[x].start_offset = 0;	card->port[x].end_offset = 0;    }    /* Port 2 is easy.  */    card->port[1].start_offset = 0;    card->port[1].end_offset = NM_PORT2_SIZE;    /* Yuck.  But we have to map in port 2 so we can check how much RAM the       card has.  */    if (nm256_remap_ports (card)) {	kfree (card);	return 0;    }    /*      * The NM256 has two memory ports.  The first port is nothing     * more than a chunk of video RAM, which is used as the I/O ring     * buffer.  The second port has the actual juicy stuff (like the     * mixer and the playback engine control registers).     */    if (card->rev == REV_NM256AV) {	/* Ok, try to see if this is a non-AC97 version of the hardware. */	int pval = nm256_readPort16 (card, 2, NM_MIXER_PRESENCE);	if ((pval & NM_PRESENCE_MASK) != NM_PRESENCE_VALUE) {	    if (! force_load) {		printk (KERN_ERR "NM256: This doesn't look to me like the AC97-compatible version.\n");		printk (KERN_ERR "       You can force the driver to load by passing in the module\n");		printk (KERN_ERR "       parameter:\n");		printk (KERN_ERR "              force_ac97 = 1\n");		printk (KERN_ERR "\n");		printk (KERN_ERR "       More likely, you should be using the appropriate SB-16 or\n");		printk (KERN_ERR "       CS4232 driver instead.  (If your BIOS has settings for\n");		printk (KERN_ERR "       IRQ and/or DMA for the sound card, this is *not* the correct\n");		printk (KERN_ERR "       driver to use.)\n");		nm256_release_ports (card);		kfree (card);		return 0;	    }	    else {		printk (KERN_INFO "NM256: Forcing driver load as per user request.\n");	    }	}	else {	 /*   printk (KERN_INFO "NM256: Congratulations. You're not running Eunice.\n")*/;	}	card->port[0].end_offset = 2560 * 1024;	card->introutine = nm256_interrupt;	card->mixer_status_offset = NM_MIXER_STATUS_OFFSET;	card->mixer_status_mask = NM_MIXER_READY_MASK;    }     else {	/* Not sure if there is any relevant detect for the ZX or not.  */	if (nm256_readPort8 (card, 2, 0xa0b) != 0)	    card->port[0].end_offset = 6144 * 1024;	else	    card->port[0].end_offset = 4096 * 1024;	card->introutine = nm256_interrupt_zx;	card->mixer_status_offset = NM2_MIXER_STATUS_OFFSET;	card->mixer_status_mask = NM2_MIXER_READY_MASK;    }    if (buffertop >= 98304 && buffertop < card->port[0].end_offset)	card->port[0].end_offset = buffertop;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -