Writing an ALSA Driver

Takashi Iwai


          
        

Copyright (c) 2002-2005 Takashi Iwai

This document is free; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This document is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Abstract

This document describes how to write an ALSA (Advanced Linux Sound Architecture) driver.


Table of Contents

Preface
1. File Tree Structure
General
core directory
core/oss
core/ioctl32
core/seq
core/seq/oss
core/seq/instr
include directory
drivers directory
drivers/mpu401
drivers/opl3 and opl4
i2c directory
i2c/l3
synth directory
pci directory
isa directory
arm, ppc, and sparc directories
usb directory
pcmcia directory
oss directory
2. Basic Flow for PCI Drivers
Outline
Full Code Example
Constructor
1) Check and increment the device index.
2) Create a card instance
3) Create a main component
4) Set the driver ID and name strings.
5) Create other components, such as mixer, MIDI, etc.
6) Register the card instance.
7) Set the PCI driver data and return zero.
Destructor
Header Files
3. Management of Cards and Components
Card Instance
Components
Chip-Specific Data
1. Allocating via snd_card_create().
2. Allocating an extra device.
Registration and Release
4. PCI Resource Management
Full Code Example
Some Hafta's
Resource Allocation
Registration of Device Struct
PCI Entries
5. PCM Interface
General
Full Code Example
Constructor
... And the Destructor?
Runtime Pointer - The Chest of PCM Information
Hardware Description
PCM Configurations
DMA Buffer Information
Running Status
Private Data
Interrupt Callbacks
Operators
open callback
close callback
ioctl callback
hw_params callback
hw_free callback
prepare callback
trigger callback
pointer callback
copy and silence callbacks
ack callback
page callback
Interrupt Handler
Interrupts at the period (fragment) boundary
High frequency timer interrupts
On calling snd_pcm_period_elapsed()
Atomicity
Constraints
6. Control Interface
General
Definition of Controls
Control Names
Global capture and playback
Tone-controls
3D controls
Mic boost
Access Flags
Callbacks
info callback
get callback
put callback
Callbacks are not atomic
Constructor
Change Notification
Metadata
7. API for AC97 Codec
General
Full Code Example
Constructor
Callbacks
Updating Registers in The Driver
Clock Adjustment
Proc Files
Multiple Codecs
8. MIDI (MPU401-UART) Interface
General
Constructor
Interrupt Handler
9. RawMIDI Interface
Overview
Constructor
Callbacks
open callback
close callback
trigger callback for output substreams
trigger callback for input substreams
drain callback
10. Miscellaneous Devices
FM OPL3
Hardware-Dependent Devices
IEC958 (S/PDIF)
11. Buffer and Memory Management
Buffer Types
External Hardware Buffers
Non-Contiguous Buffers
Vmalloc'ed Buffers
12. Proc Interface
13. Power Management
14. Module Parameters
15. How To Put Your Driver Into ALSA Tree
General
Driver with A Single Source File
Drivers with Several Source Files
16. Useful Functions
snd_printk() and friends
snd_BUG()
snd_BUG_ON()
17. Acknowledgments

List of Examples

1.1. ALSA File Tree Structure
2.1. Basic Flow for PCI Drivers - Example
4.1. PCI Resource Management Example
5.1. PCM Example Code
5.2. PCM Instance with a Destructor
5.3. Interrupt Handler Case #1
5.4. Interrupt Handler Case #2
5.5. Example of Hardware Constraints
5.6. Example of Hardware Constraints for Channels
5.7. Example of Hardware Constraints for Channels
6.1. Definition of a Control
6.2. Example of info callback
6.3. Example of get callback
6.4. Example of put callback
7.1. Example of AC97 Interface
15.1. Sample Makefile for a driver xyz