Ignore:
Timestamp:
Aug 22, 2007, 5:33:25 AM (18 years ago)
Author:
Brendan Oakley
Message:

Merged to ALSA 0.9.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GPL/branches/alsa-resync1/alsa-kernel/isa/cmi8330.c

    r224 r246  
    4747#include <linux/init.h>
    4848#include <linux/slab.h>
    49 #ifndef LINUX_ISAPNP_H
    50 #include <linux/isapnp.h>
    51 #define isapnp_card pci_bus
    52 #define isapnp_dev pci_dev
    53 #endif
     49#include <linux/pnp.h>
    5450#include <sound/core.h>
    5551#include <sound/ad1848.h>
     
    7470static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
    7571static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP;
    76 #ifdef __ISAPNP__
     72#ifdef CONFIG_PNP
    7773#ifdef TARGET_OS2
    7874static int isapnp[SNDRV_CARDS] = {REPEAT_SNDRV(1)};
     
    9894MODULE_PARM_DESC(enable, "Enable CMI8330 soundcard.");
    9995MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
    100 #ifdef __ISAPNP__
     96#ifdef CONFIG_PNP
    10197MODULE_PARM(isapnp, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
    102 MODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard.");
     98MODULE_PARM_DESC(isapnp, "PnP detection for specified soundcard.");
    10399MODULE_PARM_SYNTAX(isapnp, SNDRV_ISAPNP_DESC);
    104100#endif
     
    161157
    162158struct snd_cmi8330 {
    163 #ifdef __ISAPNP__
    164         struct isapnp_dev *cap;
    165         struct isapnp_dev *play;
     159#ifdef CONFIG_PNP
     160        struct pnp_dev *cap;
     161        struct pnp_dev *play;
    166162#endif
    167163        snd_card_t *card;
     
    177173};
    178174
    179 static snd_card_t *snd_cmi8330_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
    180 
    181 #ifdef __ISAPNP__
    182 
    183 static struct isapnp_card *snd_cmi8330_isapnp_cards[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
    184 static const struct isapnp_card_id *snd_cmi8330_isapnp_id[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
    185 
    186 #define ISAPNP_CMI8330(_va, _vb, _vc, _device, _audio1, _audio2) \
    187         { \
    188                 ISAPNP_CARD_ID(_va, _vb, _vc, _device), \
    189                 .devs = { ISAPNP_DEVICE_ID('@', '@', '@', _audio1), \
    190                          ISAPNP_DEVICE_ID('@', 'X', '@', _audio2), } \
    191         }
    192 
    193 static struct isapnp_card_id snd_cmi8330_pnpids[] __devinitdata =
    194 {
    195         ISAPNP_CMI8330('C','M','I',0x0001,0x0001,0x0001),
    196         { ISAPNP_CARD_END, }
     175static snd_card_t *snd_cmi8330_legacy[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
     176
     177#ifdef CONFIG_PNP
     178
     179static struct pnp_card_device_id snd_cmi8330_pnpids[] __devinitdata = {
     180        { .id = "CMI0001", .devs = { { "@@@0001" }, { "@X@0001" } } },
     181        { .id = "" }
    197182};
    198183
    199 ISAPNP_CARD_TABLE(snd_cmi8330_pnpids);
     184MODULE_DEVICE_TABLE(pnp_card, snd_cmi8330_pnpids);
    200185
    201186#endif
     
    263248
    264249
    265 static int __init cmi8330_add_sb_mixers(sb_t *chip)
     250static int __devinit cmi8330_add_sb_mixers(sb_t *chip)
    266251{
    267252        int idx, err;
     
    288273#endif
    289274
    290 static int __init snd_cmi8330_mixer(snd_card_t *card, struct snd_cmi8330 *acard)
     275static int __devinit snd_cmi8330_mixer(snd_card_t *card, struct snd_cmi8330 *acard)
    291276{
    292277        unsigned int idx;
     
    307292}
    308293
    309 #ifdef __ISAPNP__
    310 static int __init snd_cmi8330_isapnp(int dev, struct snd_cmi8330 *acard)
    311 {
    312         const struct isapnp_card_id *id = snd_cmi8330_isapnp_id[dev];
    313         struct isapnp_card *card = snd_cmi8330_isapnp_cards[dev];
    314         struct isapnp_dev *pdev;
    315 
    316         acard->cap = isapnp_find_dev(card, id->devs[0].vendor, id->devs[0].function, NULL);
    317         if (acard->cap->active) {
    318                 acard->cap = NULL;
     294#ifdef CONFIG_PNP
     295static int __devinit snd_cmi8330_pnp(int dev, struct snd_cmi8330 *acard,
     296                                     struct pnp_card_link *card,
     297                                     const struct pnp_card_device_id *id)
     298{
     299        struct pnp_dev *pdev;
     300        struct pnp_resource_table * cfg = kmalloc(GFP_ATOMIC, sizeof(struct pnp_resource_table));
     301        int err;
     302
     303        acard->cap = pnp_request_card_device(card, id->devs[0].id, NULL);
     304        if (acard->cap == NULL) {
     305                kfree(cfg);
    319306                return -EBUSY;
    320307        }
    321         acard->play = isapnp_find_dev(card, id->devs[1].vendor, id->devs[1].function, NULL);
    322         if (acard->play->active) {
    323                 acard->cap = acard->play = NULL;
     308        acard->play = pnp_request_card_device(card, id->devs[1].id, NULL);
     309        if (acard->play == NULL) {
     310                kfree(cfg);
    324311                return -EBUSY;
    325312        }
    326313
    327314        pdev = acard->cap;
    328         if (pdev->prepare(pdev)<0)
    329                 return -EAGAIN;
     315        pnp_init_resource_table(cfg);
    330316        /* allocate AD1848 resources */
    331317        if (wssport[dev] != SNDRV_AUTO_PORT)
    332                 isapnp_resource_change(&pdev->resource[0], wssport[dev], 8);
     318                pnp_resource_change(&cfg->port_resource[0], wssport[dev], 8);
    333319        if (wssdma[dev] != SNDRV_AUTO_DMA)
    334                 isapnp_resource_change(&pdev->dma_resource[0], wssdma[dev], 1);
     320                pnp_resource_change(&cfg->dma_resource[0], wssdma[dev], 1);
    335321        if (wssirq[dev] != SNDRV_AUTO_IRQ)
    336                 isapnp_resource_change(&pdev->irq_resource[0], wssirq[dev], 1);
    337 
    338         if (pdev->activate(pdev)<0) {
    339                 snd_printk("(AD1848) PnP configure failure\n");
     322                pnp_resource_change(&cfg->irq_resource[0], wssirq[dev], 1);
     323
     324        err = pnp_manual_config_dev(pdev, cfg, 0);
     325        if (err < 0)
     326                snd_printk(KERN_ERR "CMI8330/C3D (AD1848) PnP manual resources are invalid, using auto config\n");
     327        err = pnp_activate_dev(pdev);
     328        if (err < 0) {
     329                snd_printk(KERN_ERR "CMI8330/C3D (AD1848) PnP configure failure\n");
     330                kfree(cfg);
    340331                return -EBUSY;
    341332        }
    342         wssport[dev] = pdev->resource[0].start;
    343         wssdma[dev] = pdev->dma_resource[0].start;
    344         wssirq[dev] = pdev->irq_resource[0].start;
     333        wssport[dev] = pnp_port_start(pdev, 0);
     334        wssdma[dev] = pnp_dma(pdev, 0);
     335        wssirq[dev] = pnp_irq(pdev, 0);
    345336
    346337        /* allocate SB16 resources */
    347338        pdev = acard->play;
    348         if (pdev->prepare(pdev)<0) {
    349                 acard->cap->deactivate(acard->cap);
    350                 return -EAGAIN;
    351         }
     339        pnp_init_resource_table(cfg);
    352340        if (sbport[dev] != SNDRV_AUTO_PORT)
    353                 isapnp_resource_change(&pdev->resource[0], sbport[dev], 16);
     341                pnp_resource_change(&cfg->port_resource[0], sbport[dev], 16);
    354342        if (sbdma8[dev] != SNDRV_AUTO_DMA)
    355                 isapnp_resource_change(&pdev->dma_resource[0], sbdma8[dev], 1);
     343                pnp_resource_change(&cfg->dma_resource[0], sbdma8[dev], 1);
    356344        if (sbdma16[dev] != SNDRV_AUTO_DMA)
    357                 isapnp_resource_change(&pdev->dma_resource[1], sbdma16[dev], 1);
     345                pnp_resource_change(&cfg->dma_resource[1], sbdma16[dev], 1);
    358346        if (sbirq[dev] != SNDRV_AUTO_IRQ)
    359                 isapnp_resource_change(&pdev->irq_resource[0], sbirq[dev], 1);
    360 
    361         if (pdev->activate(pdev)<0) {
    362                 snd_printk("CMI8330/C3D (SB16) PnP configure failure\n");
    363                 acard->cap->deactivate(acard->cap);
     347                pnp_resource_change(&cfg->irq_resource[0], sbirq[dev], 1);
     348
     349        err = pnp_manual_config_dev(pdev, cfg, 0);
     350        if (err < 0)
     351                snd_printk(KERN_ERR "CMI8330/C3D (SB16) PnP manual resources are invalid, using auto config\n");
     352        err = pnp_activate_dev(pdev);
     353        if (err < 0) {
     354                snd_printk(KERN_ERR "CMI8330/C3D (SB16) PnP configure failure\n");
     355                kfree(cfg);
    364356                return -EBUSY;
    365357        }
    366         sbport[dev] = pdev->resource[0].start;
    367         sbdma8[dev] = pdev->dma_resource[0].start;
    368         sbdma16[dev] = pdev->dma_resource[1].start;
    369         sbirq[dev] = pdev->irq_resource[0].start;
    370 
     358        sbport[dev] = pnp_port_start(pdev, 0);
     359        sbdma8[dev] = pnp_dma(pdev, 0);
     360        sbdma16[dev] = pnp_dma(pdev, 1);
     361        sbirq[dev] = pnp_irq(pdev, 0);
     362
     363        kfree(cfg);
    371364        return 0;
    372 }
    373 
    374 static void snd_cmi8330_deactivate(struct snd_cmi8330 *acard)
    375 {
    376         if (acard->cap) {
    377                 acard->cap->deactivate(acard->cap);
    378                 acard->cap = NULL;
    379         }
    380         if (acard->play) {
    381                 acard->play->deactivate(acard->play);
    382                 acard->play = NULL;
    383         }
    384365}
    385366#endif
     
    429410}
    430411
    431 static int __init snd_cmi8330_pcm(snd_card_t *card, struct snd_cmi8330 *chip)
     412static int __devinit snd_cmi8330_pcm(snd_card_t *card, struct snd_cmi8330 *chip)
    432413{
    433414        snd_pcm_t *pcm;
     
    472453 */
    473454
    474 static void snd_cmi8330_free(snd_card_t *card)
    475 {
    476         struct snd_cmi8330 *acard = (struct snd_cmi8330 *)card->private_data;
    477 
    478         if (acard) {
    479 #ifdef __ISAPNP__
    480                 snd_cmi8330_deactivate(acard);
    481 #endif
    482         }
    483 }
    484 
    485 static int __init snd_cmi8330_probe(int dev)
     455static int __devinit snd_cmi8330_probe(int dev,
     456                                       struct pnp_card_link *pcard,
     457                                       const struct pnp_card_device_id *pid)
    486458{
    487459        snd_card_t *card;
     
    490462        int i, err;
    491463
    492 #ifdef __ISAPNP__
     464#ifdef CONFIG_PNP
    493465        if (!isapnp[dev]) {
    494466#endif
     
    501473                        return -EINVAL;
    502474                }
    503 #ifdef __ISAPNP__
     475#ifdef CONFIG_PNP
    504476        }
    505477#endif
     
    512484        acard = (struct snd_cmi8330 *)card->private_data;
    513485        acard->card = card;
    514         card->private_free = snd_cmi8330_free;
    515 
    516 #ifdef __ISAPNP__
    517         if (isapnp[dev] && (err = snd_cmi8330_isapnp(dev, acard)) < 0) {
     486
     487#ifdef CONFIG_PNP
     488        if (isapnp[dev] && (err = snd_cmi8330_pnp(dev, acard, pcard, pid)) < 0) {
    518489                snd_printk("PnP detection failed\n");
    519490                snd_card_free(card);
     
    585556        }
    586557
    587         snd_cmi8330_cards[dev] = card;
     558        if (pcard)
     559                pnp_set_card_drvdata(pcard, card);
     560        else
     561                snd_cmi8330_legacy[dev] = card;
    588562        return 0;
    589563}
    590564
    591 static void __exit alsa_card_cmi8330_exit(void)
    592 {
    593         int i;
    594 
    595         for (i = 0; i < SNDRV_CARDS; i++)
    596                 snd_card_free(snd_cmi8330_cards[i]);
    597 }
    598 
    599 #ifdef __ISAPNP__
    600 static int __init snd_cmi8330_isapnp_detect(struct isapnp_card *card,
    601                                             const struct isapnp_card_id *id)
     565#ifdef CONFIG_PNP
     566static int __devinit snd_cmi8330_pnp_detect(struct pnp_card_link *card,
     567                                            const struct pnp_card_device_id *id)
    602568{
    603569        static int dev;
     
    607573                if (!enable[dev] || !isapnp[dev])
    608574                        continue;
    609                 snd_cmi8330_isapnp_cards[dev] = card;
    610                 snd_cmi8330_isapnp_id[dev] = id;
    611                 res = snd_cmi8330_probe(dev);
     575                res = snd_cmi8330_probe(dev, card, id);
    612576                if (res < 0)
    613577                        return res;
     
    617581        return -ENODEV;
    618582}
    619 #endif /* __ISAPNP__ */
     583
     584static void __devexit snd_cmi8330_pnp_remove(struct pnp_card_link * pcard)
     585{
     586        snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
     587
     588        snd_card_disconnect(card);
     589        snd_card_free_in_thread(card);
     590}
     591
     592static struct pnp_card_driver cmi8330_pnpc_driver = {
     593        .flags = PNP_DRIVER_RES_DISABLE,
     594        .name = "cmi8330",
     595        .id_table = snd_cmi8330_pnpids,
     596        .probe = snd_cmi8330_pnp_detect,
     597        .remove = __devexit_p(snd_cmi8330_pnp_remove),
     598};
     599#endif /* CONFIG_PNP */
    620600
    621601static int __init alsa_card_cmi8330_init(void)
     
    626606                if (!enable[dev])
    627607                        continue;
    628 #ifdef __ISAPNP__
     608#ifdef CONFIG_PNP
    629609                if (isapnp[dev])
    630610                        continue;
    631611#endif
    632                 if (snd_cmi8330_probe(dev) >= 0)
     612                if (snd_cmi8330_probe(dev, NULL, NULL) >= 0)
    633613                        cards++;
    634614        }
    635 #ifdef __ISAPNP__
    636         cards += isapnp_probe_cards(snd_cmi8330_pnpids, snd_cmi8330_isapnp_detect);
     615#ifdef CONFIG_PNP
     616        cards += pnp_register_card_driver(&cmi8330_pnpc_driver);
    637617#endif
    638618
    639619        if (!cards) {
     620#ifdef CONFIG_PNP
     621                pnp_unregister_card_driver(&cmi8330_pnpc_driver);
     622#endif
    640623#ifdef MODULE
    641                 printk(KERN_ERR "CMI8330 not found or device busy\n");
     624                snd_printk(KERN_ERR "CMI8330 not found or device busy\n");
    642625#endif
    643626                return -ENODEV;
    644627        }
    645628        return 0;
     629}
     630
     631static void __exit alsa_card_cmi8330_exit(void)
     632{
     633        int i;
     634
     635#ifdef CONFIG_PNP
     636        /* PnP cards first */
     637        pnp_unregister_card_driver(&cmi8330_pnpc_driver);
     638#endif
     639        for (i = 0; i < SNDRV_CARDS; i++)
     640                snd_card_free(snd_cmi8330_legacy[i]);
    646641}
    647642
     
    675670               get_option(&str,&wssirq[nr_dev]) == 2 &&
    676671               get_option(&str,&wssdma[nr_dev]) == 2);
    677 #ifdef __ISAPNP__
     672#ifdef CONFIG_PNP
    678673        if (pnp != INT_MAX)
    679674                isapnp[nr_dev] = pnp;
Note: See TracChangeset for help on using the changeset viewer.