Crystal CS 4281 with AC97 Sound Card Driver Tips
The example code from the book is known to work with the systems we have in the lab and has been used successfully by students for the past several years, but will require that you study and understand the hardware, example code, carefully verify in a stepwise fashion the PCI config space, MMU programming, and Interrupts as well as careful verification of your audio test source, board, and careful handling of the hardware. Note that there is a web page example that presently implements only playback and no record, but that there is a more complete example included with the book as well on the CDROM which includes both play and record features.
Early versions of code have been used with the Crystla/Pine-Technology cards and x86 PCI platforms successfully with only minor modification, again for config space MMIO/IRQ assignment, for the past 10 years!!
For those of you working with Cirrus Logic Crystal Sound Card with AC97 and driver, please consider the following carefully as you unit test the card, driver, and audio test source:
- Use code from web page as well as the CDROM that comes with the book - Playback Only Example or Book CDROM driver examples
- You can get help from the TA during office hours -the TA has used this driver or similar successfully in the past on the exact same systems we are using when he took the class
- Please pre-test your headphones and microphone, or better yet, provide audio input from a continuous source like an iPOD or CD player when you start to work on record.
- Install Sound card with POWER OFF (pull the power cord) and NEVER hot plug PCI cards in our lab.
- Make sure working audio source is plugged into the sound card.
- Verify the interrupt and BAR assigned by the BSP by reading config space (you did this in labs) and read the code carefully to make sure you are connecting the correct IRQ and verify that the MMIO address makes sense.
- Verify that the MMIO address in the code is the same as the config space BAR, and also that you can do "d 0x" on a Wind Shell command line without MMU exception - i.e. the BSP should program the MMU to allow for addresses in this same range to be put out on the bus - verify that you can read the status registers on the Cirrus chip or AC97 using this MMIO BAR (base address) using the example code . One of the best ways to verify the PCI device BAR for a given function on a given bus is to use the VxWorks built-in "pci" helper functions. The BSP enumerates the bus and fills out data structures with the overall configuration of all buses, devices, functions and the BARs, IRQs, etc.
Verify the VxWorks BSP configuration space programming using:
- pciConfigTopoShow - this should give you a very complete high level view of the overall PCI topology
- Now that you know how many PCI buses are built into the target, use pciDeviceShow(BUSNO) where BUSNO is the bus number where you found the Crystal deviceID and vendorID.
- Finally, to verify the BAR0...BARn for your device functions, use pciFuncBarShow(BUSNO, DEVNO) where DEVNO is the device number as parsed by the BSP for the vendorID/deviceID for your device. Note that the device may have multiple functions - the Crystal has a CS4281 DMA function as well as an AC97 audio encoding function, so read the chipset manual carefully and make sure your have properly assigned the BAR(s) for the functions.
- Now, set your MMIO address in the btvid3.c code to match what the BSP programmed the MMU for and make sure that the MMU address and PCI device BAR match.
- To further verify, use d 0xBACEADD0 where 0xBACEADD0 is the base address that was programmed by the BSP. Likewise, you should be able to dump and modify a RAM address such as 0x04000000 (which is 64MB from address 0x00000000) using "d" and "m" in the windshell.
- Read the chipset manual carefully and make sure you understand device operation for both the Cirrus Crytsal DMA and AC97 ADC/PCM functions - Cirrus Chipset Docs.
For background on Audio PCM, these links are helpful:
PCM Audio
- Read the driver source carefully, make sure you understand it based on the chipset documentation. Ask TA or myself if you have questions on the code. We will expect you to have read the code and chipset manual. You may also find the Linux version of this driver in ALSA (Advanced Linux Sound Architecture) useful as a reference, but reference to this driver is not required -
Linux ALSA
- Make use of built-in status and debug functions (or add your own) and carefully set gain and attenuation registers to mid-range to start and ensure that mute is not enabled.
- See TA during office hours to get help if you are still stuck.
- Schedule debug session with Dr. Siewert if you are still stuck. Remember, the example code is not "plug and play" solution that you mindlessly INSTALL - you must read, understand, master, modify, and make this your own -- the example code will save you about 15 weeks of work if you had to code this driver from chipset manual alone. So invest some time, but if you are stuck and you have read the background, then please do ask for help.