没有合适的资源?快使用搜索试试~ 我知道了~
首页writing-an-alsa-driver.pdf
writing-an-alsa-driver.pdf
需积分: 9 107 浏览量
更新于2023-03-03
评论
收藏 714KB PDF 举报
how to write linux alsa audio driver.
资源详情
资源评论
资源推荐

Writing an ALSA Driver
Takashi Iwai
tiwai@suse.de

Writing an ALSA Driver
by Takashi Iwai
0.3.6 Edition
This document describes how to write an ALSA (Advanced Linux Sound Architecture) driver.
Copyright (c) 2002-2005 Takashi Iwai <tiwai@suse.de>
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

Table of Contents
Preface .................................................................................................................................................... viii
1. File Tree Structure.................................................................................................................................1
General ...............................................................................................................................................1
core directory .....................................................................................................................................2
core/oss .....................................................................................................................................2
core/ioctl32 ...............................................................................................................................2
core/seq.....................................................................................................................................2
core/seq/oss...............................................................................................................................2
core/seq/instr.............................................................................................................................2
include directory ................................................................................................................................2
drivers directory .................................................................................................................................2
drivers/mpu401 .........................................................................................................................3
drivers/opl3 and opl4 ................................................................................................................3
i2c directory .......................................................................................................................................3
i2c/l3 .........................................................................................................................................3
synth directory....................................................................................................................................3
pci directory .......................................................................................................................................3
isa directory........................................................................................................................................3
arm, ppc, and sparc directories ......................................... ..................................................................4
usb directory.......................................................................................................................................4
pcmcia directory.................................................................................................................................4
oss directory .......................................................................................................................................4
2. Basic Flow for PCI Drivers ...................................................................................................................5
Outline................................................................................................................................................5
Full Code Example.............................................................................................................................5
Constructor.........................................................................................................................................8
1) Check and increment the device index.................................................................................8
2) Create a card instance...........................................................................................................8
3) Create a main component.....................................................................................................8
4) Set the driver ID and name strings. ......................................................................................9
5) Create other components, such as mixer, MIDI, etc. ...........................................................9
6) Register the card instance.....................................................................................................9
7) Set the PCI driver data and return zero. ...............................................................................9
Destructor.........................................................................................................................................10
Header Files .....................................................................................................................................10
3. Management of Cards and Components ...........................................................................................11
Card Instance....................................................................................................................................11
Components .....................................................................................................................................11
Chip-Specific Data ...........................................................................................................................12
1. Allocating via snd_card_new(). .....................................................................................12
2. Allocating an extra device. .................................................................................................12
Registration and Release ..................................................................................................................13
iii

4. PCI Resource Managements...............................................................................................................15
Full Code Example...........................................................................................................................15
Some Hafta’s ....................................................................................................................................17
Resource Allocation.........................................................................................................................18
Registration of Device Struct ...........................................................................................................21
PCI Entries .......................................................................................................................................21
5. PCM Interface......................................................................................................................................23
General .............................................................................................................................................23
Full Code Example...........................................................................................................................23
Constructor.......................................................................................................................................27
... And the Destructor? .....................................................................................................................29
Runtime Pointer - The Chest of PCM Information..........................................................................29
Hardware Description.............................................................................................................31
PCM Configurations...............................................................................................................33
DMA Buffer Information .......................................................................................................34
Running Status........................................................................................................................34
Private Data ............................................................................................................................34
Interrupt Callbacks .................................................................................................................35
Operators..........................................................................................................................................35
open callback ..........................................................................................................................35
close callback..........................................................................................................................36
ioctl callback...........................................................................................................................36
hw_params callback ...............................................................................................................36
hw_free callback.....................................................................................................................37
prepare callback......................................................................................................................37
trigger callback .......................................................................................................................38
pointer callback ......................................................................................................................38
copy and silence callbacks......................................................................................................39
ack callback ............................................................................................................................39
page callback ..........................................................................................................................39
Interrupt Handler..............................................................................................................................39
Interrupts at the period (fragment) boundary .........................................................................40
High-frequent timer interrupts................................................................................................40
On calling snd_pcm_period_elapsed() ..........................................................................41
Atomicity .........................................................................................................................................41
Constraints .......................................................................................................................................42
6. Control Interface .................................................................................................................................45
General .............................................................................................................................................45
Definition of Controls ......................................................................................................................45
Control Names ................................................................. ................................................................46
Global capture and playback ..................................................................................................46
Tone-controls ..........................................................................................................................46
3D controls .............................................................................................................................46
Mic boost ................................................................................................................................46
Access Flags.....................................................................................................................................47
Callbacks..........................................................................................................................................47
info callback ...........................................................................................................................47
iv

get callback.............................................................................................................................48
put callback.............................................................................................................................49
Callbacks are not atomic ........................................................................................................49
Constructor.......................................................................................................................................49
Change Notification ......................................................... ................................................................50
7. API for AC97 Codec ............................................................................................................................51
General .............................................................................................................................................51
Full Code Example...........................................................................................................................51
Constructor.......................................................................................................................................52
Callbacks..........................................................................................................................................52
Updating Registers in The Driver ....................................................................................................53
Clock Adjustment ............................................................................................................................54
Proc Files..........................................................................................................................................54
Multiple Codecs ...............................................................................................................................54
8. MIDI (MPU401-UART) Interface ......................................................................................................55
General .............................................................................................................................................55
Constructor.......................................................................................................................................55
Interrupt Handler..............................................................................................................................56
9. RawMIDI Interface .............................................................................................................................57
Overview ..........................................................................................................................................57
Constructor.......................................................................................................................................57
Callbacks..........................................................................................................................................58
open callback .........................................................................................................................58
close callback .......................................................................................................................58
trigger callback for output substreams ...............................................................................59
trigger callback for input substreams .................................................................................60
drain callback .......................................................................................................................60
10. Miscellaneous Devices .......................................................................................................................61
FM OPL3 .........................................................................................................................................61
Hardware-Dependent Devices..........................................................................................................62
IEC958 (S/PDIF)..............................................................................................................................62
11. Buffer and Memory Management....................................................................................................64
Buffer Types.....................................................................................................................................64
External Hardware Buffers...............................................................................................................64
Non-Contiguous Buffers ..................................................................................................................66
Vmalloc’ed Buffers..........................................................................................................................67
12. Proc Interface.....................................................................................................................................68
13. Power Management ...........................................................................................................................70
14. Module Parameters ...........................................................................................................................74
15. How To Put Your Driver Into ALSA Tree.......................................................................................75
General .............................................................................................................................................75
Driver with A Single Source File.....................................................................................................75
Drivers with Several Source Files ....................................................................................................76
v
剩余85页未读,继续阅读


















安全验证
文档复制为VIP权益,开通VIP直接复制

评论0