diff options
Diffstat (limited to 'sound/pci/intel8x0.c')
-rw-r--r-- | sound/pci/intel8x0.c | 144 |
1 files changed, 44 insertions, 100 deletions
diff --git a/sound/pci/intel8x0.c b/sound/pci/intel8x0.c index df3ba5c70de9..a51032b3ac4d 100644 --- a/sound/pci/intel8x0.c +++ b/sound/pci/intel8x0.c @@ -378,7 +378,7 @@ struct intel8x0 { spinlock_t reg_lock; u32 bdbars_count; - struct snd_dma_buffer bdbars; + struct snd_dma_buffer *bdbars; u32 int_sta_reg; /* interrupt status register */ u32 int_sta_mask; /* interrupt status mask */ }; @@ -1427,7 +1427,7 @@ struct ich_pcm_table { }; #define intel8x0_dma_type(chip) \ - ((chip)->fix_nocache ? SNDRV_DMA_TYPE_DEV_UC : SNDRV_DMA_TYPE_DEV) + ((chip)->fix_nocache ? SNDRV_DMA_TYPE_DEV_WC : SNDRV_DMA_TYPE_DEV) static int snd_intel8x0_pcm1(struct intel8x0 *chip, int device, const struct ich_pcm_table *rec) @@ -2528,8 +2528,9 @@ static int snd_intel8x0_chip_init(struct intel8x0 *chip, int probing) return 0; } -static int snd_intel8x0_free(struct intel8x0 *chip) +static void snd_intel8x0_free(struct snd_card *card) { + struct intel8x0 *chip = card->private_data; unsigned int i; if (chip->irq < 0) @@ -2552,16 +2553,6 @@ static int snd_intel8x0_free(struct intel8x0 *chip) __hw_end: if (chip->irq >= 0) free_irq(chip->irq, chip); - if (chip->bdbars.area) - snd_dma_free_pages(&chip->bdbars); - if (chip->addr) - pci_iounmap(chip->pci, chip->addr); - if (chip->bmaddr) - pci_iounmap(chip->pci, chip->bmaddr); - pci_release_regions(chip->pci); - pci_disable_device(chip->pci); - kfree(chip); - return 0; } #ifdef CONFIG_PM_SLEEP @@ -2656,6 +2647,8 @@ static void intel8x0_measure_ac97_clock(struct intel8x0 *chip) if (chip->ac97_bus->clock != 48000) return; /* specified in module option */ + if (chip->inside_vm && !ac97_clock) + return; /* no measurement on VM */ __again: subs = chip->pcm[0]->streams[0].substream; @@ -2829,12 +2822,6 @@ static void snd_intel8x0_proc_init(struct intel8x0 *chip) snd_intel8x0_proc_read); } -static int snd_intel8x0_dev_free(struct snd_device *device) -{ - struct intel8x0 *chip = device->device_data; - return snd_intel8x0_free(chip); -} - struct ich_reg_info { unsigned int int_sta_mask; unsigned int offset; @@ -2878,19 +2865,15 @@ fini: return result; } -static int snd_intel8x0_create(struct snd_card *card, - struct pci_dev *pci, - unsigned long device_type, - struct intel8x0 **r_intel8x0) +static int snd_intel8x0_init(struct snd_card *card, + struct pci_dev *pci, + unsigned long device_type) { - struct intel8x0 *chip; + struct intel8x0 *chip = card->private_data; int err; unsigned int i; unsigned int int_sta_masks; struct ichdev *ichdev; - static const struct snd_device_ops ops = { - .dev_free = snd_intel8x0_dev_free, - }; static const unsigned int bdbars[] = { 3, /* DEVICE_INTEL */ @@ -2923,17 +2906,10 @@ static int snd_intel8x0_create(struct snd_card *card, }; const struct ich_reg_info *tbl; - *r_intel8x0 = NULL; - - err = pci_enable_device(pci); + err = pcim_enable_device(pci); if (err < 0) return err; - chip = kzalloc(sizeof(*chip), GFP_KERNEL); - if (chip == NULL) { - pci_disable_device(pci); - return -ENOMEM; - } spin_lock_init(&chip->reg_lock); chip->device_type = device_type; chip->card = card; @@ -2959,38 +2935,23 @@ static int snd_intel8x0_create(struct snd_card *card, chip->fix_nocache = 1; /* enable workaround */ err = pci_request_regions(pci, card->shortname); - if (err < 0) { - kfree(chip); - pci_disable_device(pci); + if (err < 0) return err; - } if (device_type == DEVICE_ALI) { /* ALI5455 has no ac97 region */ - chip->bmaddr = pci_iomap(pci, 0, 0); - goto port_inited; - } - - if (pci_resource_flags(pci, 2) & IORESOURCE_MEM) /* ICH4 and Nforce */ - chip->addr = pci_iomap(pci, 2, 0); - else - chip->addr = pci_iomap(pci, 0, 0); - if (!chip->addr) { - dev_err(card->dev, "AC'97 space ioremap problem\n"); - snd_intel8x0_free(chip); - return -EIO; + chip->bmaddr = pcim_iomap(pci, 0, 0); + } else { + if (pci_resource_flags(pci, 2) & IORESOURCE_MEM) /* ICH4 and Nforce */ + chip->addr = pcim_iomap(pci, 2, 0); + else + chip->addr = pcim_iomap(pci, 0, 0); + if (pci_resource_flags(pci, 3) & IORESOURCE_MEM) /* ICH4 */ + chip->bmaddr = pcim_iomap(pci, 3, 0); + else + chip->bmaddr = pcim_iomap(pci, 1, 0); } - if (pci_resource_flags(pci, 3) & IORESOURCE_MEM) /* ICH4 */ - chip->bmaddr = pci_iomap(pci, 3, 0); - else - chip->bmaddr = pci_iomap(pci, 1, 0); - port_inited: - if (!chip->bmaddr) { - dev_err(card->dev, "Controller space ioremap problem\n"); - snd_intel8x0_free(chip); - return -EIO; - } chip->bdbars_count = bdbars[device_type]; /* initialize offsets */ @@ -3026,21 +2987,20 @@ static int snd_intel8x0_create(struct snd_card *card, /* allocate buffer descriptor lists */ /* the start of each lists must be aligned to 8 bytes */ - if (snd_dma_alloc_pages(intel8x0_dma_type(chip), &pci->dev, - chip->bdbars_count * sizeof(u32) * ICH_MAX_FRAGS * 2, - &chip->bdbars) < 0) { - snd_intel8x0_free(chip); - dev_err(card->dev, "cannot allocate buffer descriptors\n"); + chip->bdbars = snd_devm_alloc_pages(&pci->dev, intel8x0_dma_type(chip), + chip->bdbars_count * sizeof(u32) * + ICH_MAX_FRAGS * 2); + if (!chip->bdbars) return -ENOMEM; - } + /* tables must be aligned to 8 bytes here, but the kernel pages are much bigger, so we don't care (on i386) */ int_sta_masks = 0; for (i = 0; i < chip->bdbars_count; i++) { ichdev = &chip->ichd[i]; - ichdev->bdbar = ((__le32 *)chip->bdbars.area) + + ichdev->bdbar = ((__le32 *)chip->bdbars->area) + (i * ICH_MAX_FRAGS * 2); - ichdev->bdbar_addr = chip->bdbars.addr + + ichdev->bdbar_addr = chip->bdbars->addr + (i * sizeof(u32) * ICH_MAX_FRAGS * 2); int_sta_masks |= ichdev->int_sta_mask; } @@ -3074,28 +3034,24 @@ static int snd_intel8x0_create(struct snd_card *card, chip->codec_isr_bits |= chip->codec_bit[i]; err = snd_intel8x0_chip_init(chip, 1); - if (err < 0) { - snd_intel8x0_free(chip); + if (err < 0) return err; - } /* request irq after initializaing int_sta_mask, etc */ + /* NOTE: we don't use devm version here since it's released / + * re-acquired in PM callbacks. + * It's released explicitly in snd_intel8x0_free(), too. + */ if (request_irq(pci->irq, snd_intel8x0_interrupt, IRQF_SHARED, KBUILD_MODNAME, chip)) { dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq); - snd_intel8x0_free(chip); return -EBUSY; } chip->irq = pci->irq; card->sync_irq = chip->irq; - err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); - if (err < 0) { - snd_intel8x0_free(chip); - return err; - } + card->private_free = snd_intel8x0_free; - *r_intel8x0 = chip; return 0; } @@ -3161,9 +3117,11 @@ static int snd_intel8x0_probe(struct pci_dev *pci, int err; struct shortname_table *name; - err = snd_card_new(&pci->dev, index, id, THIS_MODULE, 0, &card); + err = snd_devm_card_new(&pci->dev, index, id, THIS_MODULE, + sizeof(*chip), &card); if (err < 0) return err; + chip = card->private_data; if (spdif_aclink < 0) spdif_aclink = check_default_spdif_aclink(pci); @@ -3197,23 +3155,16 @@ static int snd_intel8x0_probe(struct pci_dev *pci, buggy_irq = 0; } - err = snd_intel8x0_create(card, pci, pci_id->driver_data, &chip); - if (err < 0) { - snd_card_free(card); + err = snd_intel8x0_init(card, pci, pci_id->driver_data); + if (err < 0) return err; - } - card->private_data = chip; err = snd_intel8x0_mixer(chip, ac97_clock, ac97_quirk); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } err = snd_intel8x0_pcm(chip); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } snd_intel8x0_proc_init(chip); @@ -3231,24 +3182,17 @@ static int snd_intel8x0_probe(struct pci_dev *pci, } err = snd_card_register(card); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } + pci_set_drvdata(pci, card); return 0; } -static void snd_intel8x0_remove(struct pci_dev *pci) -{ - snd_card_free(pci_get_drvdata(pci)); -} - static struct pci_driver intel8x0_driver = { .name = KBUILD_MODNAME, .id_table = snd_intel8x0_ids, .probe = snd_intel8x0_probe, - .remove = snd_intel8x0_remove, .driver = { .pm = INTEL8X0_PM_OPS, }, |