* better
[mascara-docs.git] / i386 / linux-2.3.21 / drivers / sound / skeleton.c
blobf011058a2e8b0618956bbd97c6e26e012c9130d7
1 /*
2 * PCI sound skeleton example
4 * (c) 1998 Red Hat Software
6 * This software may be used and distributed according to the
7 * terms of the GNU Public License, incorporated herein by
8 * reference.
10 * This example is designed to be built in the linux/drivers/sound
11 * directory as part of a kernel build. The example is modular only
12 * drop me a note once you have a working modular driver and want
13 * to integrate it with the main code.
14 * -- Alan <alan@redhat.com>
16 * This is a first draft. Please report any errors, corrections or
17 * improvements to me.
20 #include <linux/module.h>
21 #include <linux/delay.h>
22 #include <linux/errno.h>
23 #include <linux/fs.h>
24 #include <linux/kernel.h>
25 #include <linux/pci.h>
27 #include <asm/io.h>
29 #include "sound_config.h"
30 #include "soundmodule.h"
33 * Define our PCI vendor ID here
36 #ifndef PCI_VENDOR_MYIDENT
37 #define PCI_VENDOR_MYIDENT 0x125D
40 * PCI identity for the card.
43 #define PCI_DEVICE_ID_MYIDENT_MYCARD1 0x1969
44 #endif
46 #define CARD_NAME "ExampleWave 3D Pro Ultra ThingyWotsit"
48 #define MAX_CARDS 8
51 * Each address_info object holds the information about one of
52 * our card resources. In this case the MSS emulation of our
53 * ficticious card. Its used to manage and attach things.
56 static struct address_info mss_data[MAX_CARDS];
57 static int cards = 0;
60 * Install the actual card. This is an example
63 static int mycard_install(struct pci_dev *pcidev)
65 int iobase;
66 int mssbase;
67 int mpubase;
68 u8 x;
69 u16 w;
70 u32 v;
71 int i;
72 int dma;
75 * Our imaginary code has its I/O on PCI address 0, a
76 * MSS on PCI address 1 and an MPU on address 2
78 * For the example we will only initialise the MSS
81 iobase = pcidev->base_address[0] & PCI_BASE_ADDRESS_IO_MASK;
82 mssbase = pcidev->base_address[1] & PCI_BASE_ADDRESS_IO_MASK;
83 mpubase = pcidev->base_address[2] & PCI_BASE_ADDRESS_IO_MASK;
86 * Reset the board
90 * Wait for completion. udelay() waits in microseconds
93 udelay(100);
96 * Ok card ready. Begin setup proper. You might for example
97 * load the firmware here
100 dma = card_specific_magic(ioaddr);
103 * Turn on legacy mode (example), There are also byte and
104 * dword (32bit) PCI configuration function calls
107 pci_read_config_word(pcidev, 0x40, &w);
108 w&=~(1<<15); /* legacy decode on */
109 w|=(1<<14); /* Reserved write as 1 in this case */
110 w|=(1<<3)|(1<<1)|(1<<0); /* SB on , FM on, MPU on */
111 pci_write_config_word(pcidev, 0x40, w);
114 * Let the user know we found his toy.
117 printk(KERN_INFO "Programmed "CARD_NAME" at 0x%X to legacy mode.\n",
118 iobase);
121 * Now set it up the description of the card
124 mss_data[cards].io_base = mssbase;
125 mss_data[cards].irq = pcidev->irq;
126 mss_data[cards].dma = dma;
129 * Check there is an MSS present
132 if(ad1848_detect(mssbase, NULL, mss_data[cards].osp)==0)
133 return 0;
136 * Initialize it
139 mss_data[cards].slots[3] = ad1848_init("MyCard MSS 16bit",
140 mssbase, mss_data[cards].irq);
142 cards++;
143 return 1;
148 * This loop walks the PCI configuration database and finds where
149 * the sound cards are.
152 int init_mycard(void)
154 struct pci_dev *pcidev=NULL;
155 int count=0;
157 if(!pci_present())
158 return -ENODEV;
161 while((pcidev = pci_find_device(PCI_VENDOR_MYIDENT, PCI_DEVICE_ID_MYIDENT_MYCARD1, pcidev))!=NULL)
163 count+=mycard_install(pcidev);
164 if(count)
165 return 0;
166 if(count==MAX_CARDS)
167 break;
170 if(count==0)
171 return -ENODEV;
172 return 0;
176 * This function is called when the user or kernel loads the
177 * module into memory.
181 int init_module(void)
183 if(init_mycard()<0)
185 printk(KERN_ERR "No "CARD_NAME" cards found.\n");
186 return -ENODEV;
189 * Binds us to the sound subsystem
191 SOUND_LOCK;
192 return 0;
196 * This is called when it is removed. It will only be removed
197 * when its use count is 0. For sound the SOUND_LOCK/SOUND_UNLOCK
198 * macros hide the entire work for this.
201 void cleanup_module(void)
203 for(i=0;i< cards; i++)
206 * Free attached resources
209 ad1848_unload(mss_data[i].io_base,
210 mss_data[i].irq,
211 mss_data[i].dma,
212 mss_data[i].dma,
215 * And disconnect the device from the kernel
217 sound_unload_audiodevice(mss_data[i].slots[3]);
220 * Final clean up with the sound layer
222 SOUND_LOCK_END;