drivers/sound/nm256_audio.c
PATCH 1/1 drivers/sound/nm256_audio.c
Hi,
This updates the nm256_audio driver to the 2.4 PCI API.
Patch is against 2.4.3-ac9, verified on Sony VAIO Laptop.
Ciao, Marcus
Index: drivers/sound/nm256_audio.c
===================================================================
RCS file: /build/mm/work/repository/linux-mm/drivers/sound/nm256_audio.c,v retrieving revision 1.1
sound/nm256_audio.c +55 -61
@@ -15,6 +16,8 @@* Changes: * 11-10-2000 Bartlomiej Zolnierkiewicz <[email protected]> * Added some __init +* 19-04-2001 Marcus Meissner <[email protected]> +* Ported to 2.4 PCI API. */ #define __NO_VERSION__
@@ -49,8 +52,6 @@#define PCI_DEVICE_ID_NEOMAGIC_NM256AV_AUDIO 0x8005#define PCI_DEVICE_ID_NEOMAGIC_NM256ZX_AUDIO 0x8006 -#define RSRCADDRESS (dev,num) ((dev)->resource[(num)].start) -/* List of cards. */ static struct nm256_info *nmcard_list;
@@ -1042,6 +1043,9 @@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" );
@@ -1055,7 +1059,7 @@/* Init the memory port info. */ for (x =0 ; x <2 ; x++) { - card->port[x].physaddr =RSRCADDRESS (pcidev, 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 ;
@@ -1201,6 +1205,8 @@ } } +pci_set_drvdata (pcidev,card); +/* Insert the card in the list. */ card->next_card = nmcard_list; nmcard_list = card;
@@ -1251,37 +1257,38 @@return 0 ; } -/* -* This loop walks the PCI configuration database and finds where -* the sound cards are. -*/ - -int __init -init_nm256 (void ) +static int __devinit +nm256_probe (struct pci_dev *pcidev,const struct pci_device_id *pciid) { -struct pci_dev *pcidev =NULL ; -int count =0 ; - -if (!pci_present ()) -return -ENODEV ; - -while ((pcidev =pci_find_device (PCI_VENDOR_ID_NEOMAGIC , -PCI_DEVICE_ID_NEOMAGIC_NM256AV_AUDIO , - pcidev)) !=NULL ) { - count +=nm256_install (pcidev,REV_NM256AV ,"256AV" ); - } - -while ((pcidev =pci_find_device (PCI_VENDOR_ID_NEOMAGIC , -PCI_DEVICE_ID_NEOMAGIC_NM256ZX_AUDIO , - pcidev)) !=NULL ) { - count +=nm256_install (pcidev,REV_NM256ZX ,"256ZX" ); +if (pcidev->device ==PCI_DEVICE_ID_NEOMAGIC_NM256AV_AUDIO ) +return nm256_install (pcidev,REV_NM256AV ,"256AV" ); +if (pcidev->device ==PCI_DEVICE_ID_NEOMAGIC_NM256ZX_AUDIO ) +return nm256_install (pcidev,REV_NM256ZX ,"256ZX" ); +return -1 ;/* should not come here ... */ +} + +static void __devinit +nm256_remove (struct pci_dev *pcidev) { +struct nm256_info *xcard =pci_get_drvdata (pcidev); +struct nm256_info *card,*next_card =NULL ; + +for (card = nmcard_list; card !=NULL ; card = next_card) { + next_card = card->next_card; +if (card == xcard) { +stopPlay (card); +stopRecord (card); +if (card->has_irq) +free_irq (card->irq, card); +nm256_release_ports (card); +sound_unload_mixerdev (card->mixer_oss_dev); +sound_unload_audiodev (card->dev[0 ]); +sound_unload_audiodev (card->dev[1 ]); +kfree (card); +break ; + } } - -if (count ==0 ) -return -ENODEV ; - -printk (KERN_INFO "Done installing NM256 audio driver.\n" ); -return 0 ; +if (nmcard_list == card) + nmcard_list = next_card; }/*
@@ -1639,9 +1646,21 @@ local_qlen: nm256_audio_local_qlen, }; -EXPORT_SYMBOL (init_nm256); +static struct pci_device_id nm256_pci_tbl[]__devinitdata = { + {PCI_VENDOR_ID_NEOMAGIC ,PCI_DEVICE_ID_NEOMAGIC_NM256AV_AUDIO , +PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 }, + {PCI_VENDOR_ID_NEOMAGIC ,PCI_DEVICE_ID_NEOMAGIC_NM256ZX_AUDIO , +PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 }, + {0 ,} +}; +MODULE_DEVICE_TABLE (pci, nm256_pci_tbl); -static int loaded =0 ; +struct pci_driver nm256_pci_driver = { + name:"nm256_audio" , + id_table:nm256_pci_tbl, + probe:nm256_probe, + remove:nm256_remove, +};MODULE_PARM (usecache,"i" );MODULE_PARM (buffertop,"i" );
@@ -1650,37 +1669,13 @@static int __init do_init_nm256 (void ) { - nmcard_list =NULL ; -printk (KERN_INFO "NeoMagic 256AV/256ZX audio driver, version 1.1\n" ); - -if (init_nm256 () ==0 ) { - loaded =1 ; -return 0 ; - } -else -return -ENODEV ; +printk (KERN_INFO "NeoMagic 256AV/256ZX audio driver, version 1.1p\n" ); +return pci_module_init (&nm256_pci_driver); } static void __exit cleanup_nm256 (void) { -if (loaded) { -struct nm256_info *card; -struct nm256_info *next_card; - -for (card = nmcard_list; card !=NULL ; card = next_card) { -stopPlay (card); -stopRecord (card); -if (card->has_irq) -free_irq (card->irq, card); -nm256_release_ports (card); -sound_unload_mixerdev (card->mixer_oss_dev); -sound_unload_audiodev (card->dev[0 ]); -sound_unload_audiodev (card->dev[1 ]); - next_card = card->next_card; -kfree (card); - } - nmcard_list =NULL ; - } +pci_unregister_driver (&nm256_pci_driver);pm_unregister_all (&handle_pm_event); }
Quoted 6 lines · Marcus Meissner
Hi,
This updates the
nm256_audiodriver to the 2.4 PCI API.Patch is against 2.4.3-ac9, verified on Sony VAIO Laptop.
"verified" is the really important part with this driver, since its really finicky. I have a patch I would love to bounce to you in private, that I have been searching for a tester for -months- because I had no test hardware of my own.
Your patch looks ok to me and I would say apply it. But I also think it is incomplete.
* there is no need for a linked list of cards, since pci_{get,set}_drvdata is used. This eliminates the list walk in nm256_remove
* the new PCI API has suspend/resume hooks, and those should be used in preference to register_pm_...
* there is rarely a need to compare PCI ids manually in a driver. Do this implicitly by using the struct pci_device_id::driver_data field. In the following code, you could simply pass these two strings as your driver_data:
sound/nm256_audio.c line 1266
Quoted 4 lines
sound/nm256_audio.c +4
-0+if (pcidev->device ==PCI_DEVICE_ID_NEOMAGIC_NM256AV_AUDIO ) +return nm256_install (pcidev,REV_NM256AV ,"256AV" ); +if (pcidev->device ==PCI_DEVICE_ID_NEOMAGIC_NM256ZX_AUDIO ) +return nm256_install (pcidev,REV_NM256ZX ,"256ZX" );
* typically you don't want to -always- printout the module version when built into the kernel. that can get ugly, when you have a bunch of drivers in the kernel. you should surround the existing version printk code with ifdef MODULE, and then add some additional code in your pci_driver::probe routine which looks something like
#ifndef MODULE static int printed_version; if (!printed_version++) printk(version); #endif
and further, declare your version string like the following code, so it can be dropped from the kernel image...
static char version[] __devinitdata = KERN_INFO "... version ...\n";
Looks good, thanks for the work! If you spot any other drivers you can convert, feel free.
Jeff
Signature · 3 lines
Jeff Garzik | "The universe is like a safe to which there is a Building 1024 | combination -- but the combination is locked up MandrakeSoft | in the safe." -- Peter DeVries
Quoted 4 lines · Jeff Garzik
Quoted 3 lines · Marcus Meissner
Hi,
Quoted 8 lines
Quoted 3 lines
This updates the
nm256_audiodriver to the 2.4 PCI API.Patch is against 2.4.3-ac9, verified on Sony VAIO Laptop.
"verified" is the really important part with this driver, since its really finicky. I have a patch I would love to bounce to you in private, that I have been searching for a tester for -months- because I had no test hardware of my own.
Feel free to send (I have a NM256AV card in that VAIO).
Quoted 6 lines
Your patch looks ok to me and I would say apply it. But I also think it is incomplete.
* there is no need for a linked list of cards, since pci_{get,set}_drvdata is used. This eliminates the list walk in
nm256_remove
The problem is with device opens, which just pass numbers, most other sound drivers still use linked lists.
Hmm, but via8xxxx_audio.c doesn't, I will take this as example.
Quoted 2 lines
* the new PCI API has suspend/resume hooks, and those should be used in preference to
register_pm_...
Ok, will have another look at the other issues.
And I hope my colleague brings his VAIO to work tomorrow ;)
Ciao, Marcus