📄 emu10k1_main.c
字号:
.driver = "EMU10K1", .name = "SB Live 5.1 Dell OEM [SB0220]", .id = "Live", .emu10k1_chip = 1, .ac97_chip = 1, .sblive51 = 1} , /* Tested by Thomas Zehetbauer 27th Aug 2005 */ {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80651102, .driver = "EMU10K1", .name = "SB Live 5.1 [SB0220]", .id = "Live", .emu10k1_chip = 1, .ac97_chip = 1, .sblive51 = 1} , {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x100a1102, .driver = "EMU10K1", .name = "SB Live 5.1 [SB0220]", .id = "Live", .emu10k1_chip = 1, .ac97_chip = 1, .sblive51 = 1} , {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80641102, .driver = "EMU10K1", .name = "SB Live 5.1", .id = "Live", .emu10k1_chip = 1, .ac97_chip = 1, .sblive51 = 1} , /* Tested by alsa bugtrack user "hus" bug #1297 12th Aug 2005 */ {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80611102, .driver = "EMU10K1", .name = "SBLive 5.1 [SB0060]", .id = "Live", .emu10k1_chip = 1, .ac97_chip = 2, /* ac97 is optional; both SBLive 5.1 and platinum * share the same IDs! */ .sblive51 = 1} , {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80511102, .driver = "EMU10K1", .name = "SBLive! Value [CT4850]", .id = "Live", .emu10k1_chip = 1, .ac97_chip = 1, .sblive51 = 1} , {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80401102, .driver = "EMU10K1", .name = "SBLive! Platinum [CT4760P]", .id = "Live", .emu10k1_chip = 1, .ac97_chip = 1} , {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80321102, .driver = "EMU10K1", .name = "SBLive! Value [CT4871]", .id = "Live", .emu10k1_chip = 1, .ac97_chip = 1, .sblive51 = 1} , {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80311102, .driver = "EMU10K1", .name = "SBLive! Value [CT4831]", .id = "Live", .emu10k1_chip = 1, .ac97_chip = 1, .sblive51 = 1} , {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80281102, .driver = "EMU10K1", .name = "SBLive! Value [CT4870]", .id = "Live", .emu10k1_chip = 1, .ac97_chip = 1, .sblive51 = 1} , /* Tested by James@superbug.co.uk 3rd July 2005 */ {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80271102, .driver = "EMU10K1", .name = "SBLive! Value [CT4832]", .id = "Live", .emu10k1_chip = 1, .ac97_chip = 1, .sblive51 = 1} , {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80261102, .driver = "EMU10K1", .name = "SBLive! Value [CT4830]", .id = "Live", .emu10k1_chip = 1, .ac97_chip = 1, .sblive51 = 1} , {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80231102, .driver = "EMU10K1", .name = "SB PCI512 [CT4790]", .id = "Live", .emu10k1_chip = 1, .ac97_chip = 1, .sblive51 = 1} , {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80221102, .driver = "EMU10K1", .name = "SBLive! Value [CT4780]", .id = "Live", .emu10k1_chip = 1, .ac97_chip = 1, .sblive51 = 1} , {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x40011102, .driver = "EMU10K1", .name = "E-mu APS [4001]", .id = "APS", .emu10k1_chip = 1, .ecard = 1} , {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x00211102, .driver = "EMU10K1", .name = "SBLive! [CT4620]", .id = "Live", .emu10k1_chip = 1, .ac97_chip = 1, .sblive51 = 1} , {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x00201102, .driver = "EMU10K1", .name = "SBLive! Value [CT4670]", .id = "Live", .emu10k1_chip = 1, .ac97_chip = 1, .sblive51 = 1} , {.vendor = 0x1102, .device = 0x0002, .driver = "EMU10K1", .name = "SB Live [Unknown]", .id = "Live", .emu10k1_chip = 1, .ac97_chip = 1, .sblive51 = 1} , { } /* terminator */};int __devinit snd_emu10k1_create(struct snd_card *card, struct pci_dev * pci, unsigned short extin_mask, unsigned short extout_mask, long max_cache_bytes, int enable_ir, uint subsystem, struct snd_emu10k1 ** remu){ struct snd_emu10k1 *emu; int idx, err; int is_audigy; unsigned char revision; unsigned int silent_page; const struct snd_emu_chip_details *c; static struct snd_device_ops ops = { .dev_free = snd_emu10k1_dev_free, }; *remu = NULL; /* enable PCI device */ if ((err = pci_enable_device(pci)) < 0) return err; emu = kzalloc(sizeof(*emu), GFP_KERNEL); if (emu == NULL) { pci_disable_device(pci); return -ENOMEM; } emu->card = card; spin_lock_init(&emu->reg_lock); spin_lock_init(&emu->emu_lock); spin_lock_init(&emu->voice_lock); spin_lock_init(&emu->synth_lock); spin_lock_init(&emu->memblk_lock); init_MUTEX(&emu->ptb_lock); init_MUTEX(&emu->fx8010.lock); INIT_LIST_HEAD(&emu->mapped_link_head); INIT_LIST_HEAD(&emu->mapped_order_link_head); emu->pci = pci; emu->irq = -1; emu->synth = NULL; emu->get_synth_voice = NULL; /* read revision & serial */ pci_read_config_byte(pci, PCI_REVISION_ID, &revision); emu->revision = revision; pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &emu->serial); pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &emu->model); snd_printdd("vendor=0x%x, device=0x%x, subsystem_vendor_id=0x%x, subsystem_id=0x%x\n",pci->vendor, pci->device, emu->serial, emu->model); for (c = emu_chip_details; c->vendor; c++) { if (c->vendor == pci->vendor && c->device == pci->device) { if (subsystem) { if (c->subsystem && (c->subsystem == subsystem) ) { break; } else continue; } else { if (c->subsystem && (c->subsystem != emu->serial) ) continue; if (c->revision && c->revision != emu->revision) continue; } break; } } if (c->vendor == 0) { snd_printk(KERN_ERR "emu10k1: Card not recognised\n"); kfree(emu); pci_disable_device(pci); return -ENOENT; } emu->card_capabilities = c; if (c->subsystem && !subsystem) snd_printdd("Sound card name=%s\n", c->name); else if (subsystem) snd_printdd("Sound card name=%s, vendor=0x%x, device=0x%x, subsystem=0x%x. Forced to subsytem=0x%x\n", c->name, pci->vendor, pci->device, emu->serial, c->subsystem); else snd_printdd("Sound card name=%s, vendor=0x%x, device=0x%x, subsystem=0x%x.\n", c->name, pci->vendor, pci->device, emu->serial); if (!*card->id && c->id) { int i, n = 0; strlcpy(card->id, c->id, sizeof(card->id)); for (;;) { for (i = 0; i < snd_ecards_limit; i++) { if (snd_cards[i] && !strcmp(snd_cards[i]->id, card->id)) break; } if (i >= snd_ecards_limit) break; n++; if (n >= SNDRV_CARDS) break; snprintf(card->id, sizeof(card->id), "%s_%d", c->id, n); } } is_audigy = emu->audigy = c->emu10k2_chip; /* set the DMA transfer mask */ emu->dma_mask = is_audigy ? AUDIGY_DMA_MASK : EMU10K1_DMA_MASK; if (pci_set_dma_mask(pci, emu->dma_mask) < 0 || pci_set_consistent_dma_mask(pci, emu->dma_mask) < 0) { snd_printk(KERN_ERR "architecture does not support PCI busmaster DMA with mask 0x%lx\n", emu->dma_mask); kfree(emu); pci_disable_device(pci); return -ENXIO; } if (is_audigy) emu->gpr_base = A_FXGPREGBASE; else emu->gpr_base = FXGPREGBASE; if ((err = pci_request_regions(pci, "EMU10K1")) < 0) { kfree(emu); pci_disable_device(pci); return err; } emu->port = pci_resource_start(pci, 0); if (request_irq(pci->irq, snd_emu10k1_interrupt, SA_INTERRUPT|SA_SHIRQ, "EMU10K1", (void *)emu)) { err = -EBUSY; goto error; } emu->irq = pci->irq; emu->max_cache_pages = max_cache_bytes >> PAGE_SHIFT; if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci), 32 * 1024, &emu->ptb_pages) < 0) { err = -ENOMEM; goto error; } emu->page_ptr_table = (void **)vmalloc(emu->max_cache_pages * sizeof(void*)); emu->page_addr_table = (unsigned long*)vmalloc(emu->max_cache_pages * sizeof(unsigned long)); if (emu->page_ptr_table == NULL || emu->page_addr_table == NULL) { err = -ENOMEM; goto error; } if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci), EMUPAGESIZE, &emu->silent_page) < 0) { err = -ENOMEM; goto error; } emu->memhdr = snd_util_memhdr_new(emu->max_cache_pages * PAGE_SIZE); if (emu->memhdr == NULL) { err = -ENOMEM; goto error; } emu->memhdr->block_extra_size = sizeof(struct snd_emu10k1_memblk) - sizeof(struct snd_util_memblk); pci_set_master(pci); emu->fx8010.fxbus_mask = 0x303f; if (extin_mask == 0) extin_mask = 0x3fcf; if (extout_mask == 0) extout_mask = 0x7fff; emu->fx8010.extin_mask = extin_mask; emu->fx8010.extout_mask = extout_mask; emu->enable_ir = enable_ir; if (emu->card_capabilities->ecard) { if ((err = snd_emu10k1_ecard_init(emu)) < 0) goto error; } else if (emu->card_capabilities->ca_cardbus_chip) { if ((err = snd_emu10k1_cardbus_init(emu)) < 0) goto error; } else if (emu->card_capabilities->emu1212m) { if ((err = snd_emu10k1_emu1212m_init(emu)) < 0) { snd_emu10k1_free(emu); return err; } } else { /* 5.1: Enable the additional AC97 Slots. If the emu10k1 version does not support this, it shouldn't do any harm */ snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE); } /* initialize TRAM setup */ emu->fx8010.itram_size = (16 * 1024)/2; emu->fx8010.etram_pages.area = NULL; emu->fx8010.etram_pages.bytes = 0; /* * Init to 0x02109204 : * Clock accuracy = 0 (1000ppm) * Sample Rate = 2 (48kHz) * Audio Channel = 1 (Left of 2) * Source Number = 0 (Unspecified) * Generation Status = 1 (Original for Cat Code 12) * Cat Code = 12 (Digital Signal Mixer) * Mode = 0 (Mode 0) * Emphasis = 0 (None) * CP = 1 (Copyright unasserted) * AN = 0 (Audio data) * P = 0 (Consumer) */ emu->spdif_bits[0] = emu->spdif_bits[1] = emu->spdif_bits[2] = SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 | SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | SPCS_GENERATIONSTATUS | 0x00001200 | 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT; emu->reserved_page = (struct snd_emu10k1_memblk *) snd_emu10k1_synth_alloc(emu, 4096); if (emu->reserved_page) emu->reserved_page->map_locked = 1; /* Clear silent pages and set up pointers */ memset(emu->silent_page.area, 0, PAGE_SIZE); silent_page = emu->silent_page.addr << 1; for (idx = 0; idx < MAXPAGES; idx++) ((u32 *)emu->ptb_pages.area)[idx] = cpu_to_le32(silent_page | idx); /* set up voice indices */ for (idx = 0; idx < NUM_G; idx++) { emu->voices[idx].emu = emu; emu->voices[idx].number = idx; } if ((err = snd_emu10k1_init(emu, enable_ir, 0)) < 0) goto error;#ifdef CONFIG_PM if ((err = alloc_pm_buffer(emu)) < 0) goto error;#endif /* Initialize the effect engine */ if ((err = snd_emu10k1_init_efx(emu)) < 0) goto error; snd_emu10k1_audio_enable(emu); if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, emu, &ops)) < 0) goto error;#ifdef CONFIG_PROC_FS snd_emu10k1_proc_init(emu);#endif snd_card_set_dev(card, &pci->dev); *remu = emu; return 0; error: snd_emu10k1_free(emu); return err;}#ifdef CONFIG_PMstatic unsigned char saved_regs[] = { CPF, PTRX, CVCF, VTFT, Z1, Z2, PSST, DSL, CCCA, CCR, CLP, FXRT, MAPA, MAPB, ENVVOL, ATKHLDV, DCYSUSV, LFOVAL1, ENVVAL, ATKHLDM, DCYSUSM, LFOVAL2, IP, IFATN, PEFE, FMMOD, TREMFRQ, FM2FRQ2, TEMPENV, ADCCR, FXWC, MICBA, ADCBA, FXBA, MICBS, ADCBS, FXBS, CDCS, GPSCS, SPCS0, SPCS1, SPCS2, SPBYPASS, AC97SLOT, CDSRCS, GPSRCS, ZVSRCS, MICIDX, ADCIDX, FXIDX, 0xff /* end */};static unsigned char saved_regs_audigy[] = { A_ADCIDX, A_MICIDX, A_FXWC1, A_FXWC2, A_SAMPLE_RATE, A_FXRT2, A_SENDAMOUNTS, A_FXRT1, 0xff /* end */};static int __devinit alloc_pm_buffer(struct snd_emu10k1 *emu){ int size; size = ARRAY_SIZE(saved_regs); if (emu->audigy) size += ARRAY_SIZE(saved_regs_audigy); emu->saved_ptr = vmalloc(4 * NUM_G * size); if (! emu->saved_ptr) return -ENOMEM; if (snd_emu10k1_efx_alloc_pm_buffer(emu) < 0) return -ENOMEM; if (emu->card_capabilities->ca0151_chip && snd_p16v_alloc_pm_buffer(emu) < 0) return -ENOMEM; return 0;}static void free_pm_buffer(struct snd_emu10k1 *emu){ vfree(emu->saved_ptr); snd_emu10k1_efx_free_pm_buffer(emu); if (emu->card_capabilities->ca0151_chip) snd_p16v_free_pm_buffer(emu);}void snd_emu10k1_suspend_regs(struct snd_emu10k1 *emu){ int i; unsigned char *reg; unsigned int *val; val = emu->saved_ptr; for (reg = saved_regs; *reg != 0xff; reg++) for (i = 0; i < NUM_G; i++, val++) *val = snd_emu10k1_ptr_read(emu, *reg, i); if (emu->audigy) { for (reg = saved_regs_audigy; *reg != 0xff; reg++) for (i = 0; i < NUM_G; i++, val++) *val = snd_emu10k1_ptr_read(emu, *reg, i); } if (emu->audigy) emu->saved_a_iocfg = inl(emu->port + A_IOCFG); emu->saved_hcfg = inl(emu->port + HCFG);}void snd_emu10k1_resume_init(struct snd_emu10k1 *emu){ if (emu->card_capabilities->ecard) snd_emu10k1_ecard_init(emu); else snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE); snd_emu10k1_init(emu, emu->enable_ir, 1);}void snd_emu10k1_resume_regs(struct snd_emu10k1 *emu){ int i; unsigned char *reg; unsigned int *val; snd_emu10k1_audio_enable(emu); /* resore for spdif */ if (emu->audigy) outl(emu->port + A_IOCFG, emu->saved_a_iocfg); outl(emu->port + HCFG, emu->saved_hcfg); val = emu->saved_ptr; for (reg = saved_regs; *reg != 0xff; reg++) for (i = 0; i < NUM_G; i++, val++) snd_emu10k1_ptr_write(emu, *reg, i, *val); if (emu->audigy) { for (reg = saved_regs_audigy; *reg != 0xff; reg++) for (i = 0; i < NUM_G; i++, val++) snd_emu10k1_ptr_write(emu, *reg, i, *val); }}#endif/* memory.c */EXPORT_SYMBOL(snd_emu10k1_synth_alloc);EXPORT_SYMBOL(snd_emu10k1_synth_free);EXPORT_SYMBOL(snd_emu10k1_synth_bzero);EXPORT_SYMBOL(snd_emu10k1_synth_copy_from_user);EXPORT_SYMBOL(snd_emu10k1_memblk_map);/* voice.c */EXPORT_SYMBOL(snd_emu10k1_voice_alloc);EXPORT_SYMBOL(snd_emu10k1_voice_free);/* io.c */EXPORT_SYMBOL(snd_emu10k1_ptr_read);EXPORT_SYMBOL(snd_emu10k1_ptr_write);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -