aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/sound/alsa/DocBook/writing-an-alsa-driver.tmpl
diff options
context:
space:
mode:
authorMichael Opdenacker <michael@free-electrons.com>2007-10-24 04:59:44 -0400
committerJaroslav Kysela <perex@perex.cz>2008-01-31 11:29:10 -0500
commit3f03f7c586471f376eab497ab33394ab086f5301 (patch)
tree0c006a3c778c9c4b2dc0af251e73f15edf5b819f /Documentation/sound/alsa/DocBook/writing-an-alsa-driver.tmpl
parentf31639b8c5916f58441b529c9c364715921b29af (diff)
[ALSA] writing-an-alsa-driver.tmpl: English style improvements
This patch brings some English style improvements throughout the document, as well as 1 or 2 extra technical details. Signed-off-by: Michael Opdenacker <michael@free-electrons.com> Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Diffstat (limited to 'Documentation/sound/alsa/DocBook/writing-an-alsa-driver.tmpl')
-rw-r--r--Documentation/sound/alsa/DocBook/writing-an-alsa-driver.tmpl920
1 files changed, 458 insertions, 462 deletions
diff --git a/Documentation/sound/alsa/DocBook/writing-an-alsa-driver.tmpl b/Documentation/sound/alsa/DocBook/writing-an-alsa-driver.tmpl
index 2c3fc3cb3b6b..48e4053eda12 100644
--- a/Documentation/sound/alsa/DocBook/writing-an-alsa-driver.tmpl
+++ b/Documentation/sound/alsa/DocBook/writing-an-alsa-driver.tmpl
@@ -18,7 +18,7 @@
18 </affiliation> 18 </affiliation>
19 </author> 19 </author>
20 20
21 <date>September 10, 2007</date> 21 <date>Oct 15, 2007</date>
22 <edition>0.3.7</edition> 22 <edition>0.3.7</edition>
23 23
24 <abstract> 24 <abstract>
@@ -67,7 +67,7 @@
67 This document describes how to write an 67 This document describes how to write an
68 <ulink url="http://www.alsa-project.org/"><citetitle> 68 <ulink url="http://www.alsa-project.org/"><citetitle>
69 ALSA (Advanced Linux Sound Architecture)</citetitle></ulink> 69 ALSA (Advanced Linux Sound Architecture)</citetitle></ulink>
70 driver. The document focuses mainly on the PCI soundcard. 70 driver. The document focuses mainly on PCI soundcards.
71 In the case of other device types, the API might 71 In the case of other device types, the API might
72 be different, too. However, at least the ALSA kernel API is 72 be different, too. However, at least the ALSA kernel API is
73 consistent, and therefore it would be still a bit help for 73 consistent, and therefore it would be still a bit help for
@@ -75,23 +75,23 @@
75 </para> 75 </para>
76 76
77 <para> 77 <para>
78 The target of this document is ones who already have enough 78 This document targets people who already have enough
79 skill of C language and have the basic knowledge of linux 79 C language skills and have basic linux kernel programming
80 kernel programming. This document doesn't explain the general 80 knowledge. This document doesn't explain the general
81 topics of linux kernel codes and doesn't cover the detail of 81 topic of linux kernel coding and doesn't cover low-level
82 implementation of each low-level driver. It describes only how is 82 driver implementation details. It only describes
83 the standard way to write a PCI sound driver on ALSA. 83 the standard way to write a PCI sound driver on ALSA.
84 </para> 84 </para>
85 85
86 <para> 86 <para>
87 If you are already familiar with the older ALSA ver.0.5.x, you 87 If you are already familiar with the older ALSA ver.0.5.x API, you
88 can check the drivers such as <filename>es1938.c</filename> or 88 can check the drivers such as <filename>sound/pci/es1938.c</filename> or
89 <filename>maestro3.c</filename> which have also almost the same 89 <filename>sound/pci/maestro3.c</filename> which have also almost the same
90 code-base in the ALSA 0.5.x tree, so you can compare the differences. 90 code-base in the ALSA 0.5.x tree, so you can compare the differences.
91 </para> 91 </para>
92 92
93 <para> 93 <para>
94 This document is still a draft version. Any feedbacks and 94 This document is still a draft version. Any feedback and
95 corrections, please!! 95 corrections, please!!
96 </para> 96 </para>
97 </preface> 97 </preface>
@@ -106,7 +106,7 @@
106 <section id="file-tree-general"> 106 <section id="file-tree-general">
107 <title>General</title> 107 <title>General</title>
108 <para> 108 <para>
109 The ALSA drivers are provided in the two ways. 109 The ALSA drivers are provided in two ways.
110 </para> 110 </para>
111 111
112 <para> 112 <para>
@@ -114,15 +114,14 @@
114 ALSA's ftp site, and another is the 2.6 (or later) Linux kernel 114 ALSA's ftp site, and another is the 2.6 (or later) Linux kernel
115 tree. To synchronize both, the ALSA driver tree is split into 115 tree. To synchronize both, the ALSA driver tree is split into
116 two different trees: alsa-kernel and alsa-driver. The former 116 two different trees: alsa-kernel and alsa-driver. The former
117 contains purely the source codes for the Linux 2.6 (or later) 117 contains purely the source code for the Linux 2.6 (or later)
118 tree. This tree is designed only for compilation on 2.6 or 118 tree. This tree is designed only for compilation on 2.6 or
119 later environment. The latter, alsa-driver, contains many subtle 119 later environment. The latter, alsa-driver, contains many subtle
120 files for compiling the ALSA driver on the outside of Linux 120 files for compiling ALSA drivers outside of the Linux kernel tree,
121 kernel like configure script, the wrapper functions for older, 121 wrapper functions for older 2.2 and 2.4 kernels, to adapt the latest kernel API,
122 2.2 and 2.4 kernels, to adapt the latest kernel API,
123 and additional drivers which are still in development or in 122 and additional drivers which are still in development or in
124 tests. The drivers in alsa-driver tree will be moved to 123 tests. The drivers in alsa-driver tree will be moved to
125 alsa-kernel (eventually 2.6 kernel tree) once when they are 124 alsa-kernel (and eventually to the 2.6 kernel tree) when they are
126 finished and confirmed to work fine. 125 finished and confirmed to work fine.
127 </para> 126 </para>
128 127
@@ -168,7 +167,7 @@
168 <section id="file-tree-core-directory"> 167 <section id="file-tree-core-directory">
169 <title>core directory</title> 168 <title>core directory</title>
170 <para> 169 <para>
171 This directory contains the middle layer, that is, the heart 170 This directory contains the middle layer which is the heart
172 of ALSA drivers. In this directory, the native ALSA modules are 171 of ALSA drivers. In this directory, the native ALSA modules are
173 stored. The sub-directories contain different modules and are 172 stored. The sub-directories contain different modules and are
174 dependent upon the kernel config. 173 dependent upon the kernel config.
@@ -181,7 +180,7 @@
181 The codes for PCM and mixer OSS emulation modules are stored 180 The codes for PCM and mixer OSS emulation modules are stored
182 in this directory. The rawmidi OSS emulation is included in 181 in this directory. The rawmidi OSS emulation is included in
183 the ALSA rawmidi code since it's quite small. The sequencer 182 the ALSA rawmidi code since it's quite small. The sequencer
184 code is stored in core/seq/oss directory (see 183 code is stored in <filename>core/seq/oss</filename> directory (see
185 <link linkend="file-tree-core-directory-seq-oss"><citetitle> 184 <link linkend="file-tree-core-directory-seq-oss"><citetitle>
186 below</citetitle></link>). 185 below</citetitle></link>).
187 </para> 186 </para>
@@ -200,7 +199,7 @@
200 <section id="file-tree-core-directory-seq"> 199 <section id="file-tree-core-directory-seq">
201 <title>core/seq</title> 200 <title>core/seq</title>
202 <para> 201 <para>
203 This and its sub-directories are for the ALSA 202 This directory and its sub-directories are for the ALSA
204 sequencer. This directory contains the sequencer core and 203 sequencer. This directory contains the sequencer core and
205 primary sequencer modules such like snd-seq-midi, 204 primary sequencer modules such like snd-seq-midi,
206 snd-seq-virmidi, etc. They are compiled only when 205 snd-seq-virmidi, etc. They are compiled only when
@@ -229,22 +228,22 @@
229 <title>include directory</title> 228 <title>include directory</title>
230 <para> 229 <para>
231 This is the place for the public header files of ALSA drivers, 230 This is the place for the public header files of ALSA drivers,
232 which are to be exported to the user-space, or included by 231 which are to be exported to user-space, or included by
233 several files at different directories. Basically, the private 232 several files at different directories. Basically, the private
234 header files should not be placed in this directory, but you may 233 header files should not be placed in this directory, but you may
235 still find files there, due to historical reason :) 234 still find files there, due to historical reasons :)
236 </para> 235 </para>
237 </section> 236 </section>
238 237
239 <section id="file-tree-drivers-directory"> 238 <section id="file-tree-drivers-directory">
240 <title>drivers directory</title> 239 <title>drivers directory</title>
241 <para> 240 <para>
242 This directory contains the codes shared among different drivers 241 This directory contains code shared among different drivers
243 on the different architectures. They are hence supposed not to be 242 on different architectures. They are hence supposed not to be
244 architecture-specific. 243 architecture-specific.
245 For example, the dummy pcm driver and the serial MIDI 244 For example, the dummy pcm driver and the serial MIDI
246 driver are found in this directory. In the sub-directories, 245 driver are found in this directory. In the sub-directories,
247 there are the codes for components which are independent from 246 there is code for components which are independent from
248 bus and cpu architectures. 247 bus and cpu architectures.
249 </para> 248 </para>
250 249
@@ -271,7 +270,7 @@
271 270
272 <para> 271 <para>
273 Although there is a standard i2c layer on Linux, ALSA has its 272 Although there is a standard i2c layer on Linux, ALSA has its
274 own i2c codes for some cards, because the soundcard needs only a 273 own i2c code for some cards, because the soundcard needs only a
275 simple operation and the standard i2c API is too complicated for 274 simple operation and the standard i2c API is too complicated for
276 such a purpose. 275 such a purpose.
277 </para> 276 </para>
@@ -292,28 +291,28 @@
292 291
293 <para> 292 <para>
294 So far, there is only Emu8000/Emu10k1 synth driver under 293 So far, there is only Emu8000/Emu10k1 synth driver under
295 synth/emux sub-directory. 294 the <filename>synth/emux</filename> sub-directory.
296 </para> 295 </para>
297 </section> 296 </section>
298 297
299 <section id="file-tree-pci-directory"> 298 <section id="file-tree-pci-directory">
300 <title>pci directory</title> 299 <title>pci directory</title>
301 <para> 300 <para>
302 This and its sub-directories hold the top-level card modules 301 This directory and its sub-directories hold the top-level card modules
303 for PCI soundcards and the codes specific to the PCI BUS. 302 for PCI soundcards and the code specific to the PCI BUS.
304 </para> 303 </para>
305 304
306 <para> 305 <para>
307 The drivers compiled from a single file is stored directly on 306 The drivers compiled from a single file are stored directly
308 pci directory, while the drivers with several source files are 307 in the pci directory, while the drivers with several source files are
309 stored on its own sub-directory (e.g. emu10k1, ice1712). 308 stored on their own sub-directory (e.g. emu10k1, ice1712).
310 </para> 309 </para>
311 </section> 310 </section>
312 311
313 <section id="file-tree-isa-directory"> 312 <section id="file-tree-isa-directory">
314 <title>isa directory</title> 313 <title>isa directory</title>
315 <para> 314 <para>
316 This and its sub-directories hold the top-level card modules 315 This directory and its sub-directories hold the top-level card modules
317 for ISA soundcards. 316 for ISA soundcards.
318 </para> 317 </para>
319 </section> 318 </section>
@@ -321,16 +320,16 @@
321 <section id="file-tree-arm-ppc-sparc-directories"> 320 <section id="file-tree-arm-ppc-sparc-directories">
322 <title>arm, ppc, and sparc directories</title> 321 <title>arm, ppc, and sparc directories</title>
323 <para> 322 <para>
324 These are for the top-level card modules which are 323 They are used for top-level card modules which are
325 specific to each given architecture. 324 specific to one of these architectures.
326 </para> 325 </para>
327 </section> 326 </section>
328 327
329 <section id="file-tree-usb-directory"> 328 <section id="file-tree-usb-directory">
330 <title>usb directory</title> 329 <title>usb directory</title>
331 <para> 330 <para>
332 This contains the USB-audio driver. On the latest version, the 331 This directory contains the USB-audio driver. In the latest version, the
333 USB MIDI driver is integrated together with usb-audio driver. 332 USB MIDI driver is integrated in the usb-audio driver.
334 </para> 333 </para>
335 </section> 334 </section>
336 335
@@ -338,16 +337,17 @@
338 <title>pcmcia directory</title> 337 <title>pcmcia directory</title>
339 <para> 338 <para>
340 The PCMCIA, especially PCCard drivers will go here. CardBus 339 The PCMCIA, especially PCCard drivers will go here. CardBus
341 drivers will be on pci directory, because its API is identical 340 drivers will be in the pci directory, because their API is identical
342 with the standard PCI cards. 341 to that of standard PCI cards.
343 </para> 342 </para>
344 </section> 343 </section>
345 344
346 <section id="file-tree-oss-directory"> 345 <section id="file-tree-oss-directory">
347 <title>oss directory</title> 346 <title>oss directory</title>
348 <para> 347 <para>
349 The OSS/Lite source files are stored here on Linux 2.6 (or 348 The OSS/Lite source files are stored here in Linux 2.6 (or
350 later) tree. (In the ALSA driver tarball, it's empty, of course :) 349 later) tree. In the ALSA driver tarball, this directory is empty,
350 of course :)
351 </para> 351 </para>
352 </section> 352 </section>
353 </chapter> 353 </chapter>
@@ -362,7 +362,7 @@
362 <section id="basic-flow-outline"> 362 <section id="basic-flow-outline">
363 <title>Outline</title> 363 <title>Outline</title>
364 <para> 364 <para>
365 The minimum flow of PCI soundcard is like the following: 365 The minimum flow for PCI soundcards is as follows:
366 366
367 <itemizedlist> 367 <itemizedlist>
368 <listitem><para>define the PCI ID table (see the section 368 <listitem><para>define the PCI ID table (see the section
@@ -370,9 +370,13 @@
370 </citetitle></link>).</para></listitem> 370 </citetitle></link>).</para></listitem>
371 <listitem><para>create <function>probe()</function> callback.</para></listitem> 371 <listitem><para>create <function>probe()</function> callback.</para></listitem>
372 <listitem><para>create <function>remove()</function> callback.</para></listitem> 372 <listitem><para>create <function>remove()</function> callback.</para></listitem>
373 <listitem><para>create pci_driver table which contains the three pointers above.</para></listitem> 373 <listitem><para>create a <structname>pci_driver</structname> structure
374 <listitem><para>create <function>init()</function> function just calling <function>pci_register_driver()</function> to register the pci_driver table defined above.</para></listitem> 374 containing the three pointers above.</para></listitem>
375 <listitem><para>create <function>exit()</function> function to call <function>pci_unregister_driver()</function> function.</para></listitem> 375 <listitem><para>create an <function>init()</function> function just calling
376 the <function>pci_register_driver()</function> to register the pci_driver table
377 defined above.</para></listitem>
378 <listitem><para>create an <function>exit()</function> function to call
379 the <function>pci_unregister_driver()</function> function.</para></listitem>
376 </itemizedlist> 380 </itemizedlist>
377 </para> 381 </para>
378 </section> 382 </section>
@@ -382,12 +386,12 @@
382 <para> 386 <para>
383 The code example is shown below. Some parts are kept 387 The code example is shown below. Some parts are kept
384 unimplemented at this moment but will be filled in the 388 unimplemented at this moment but will be filled in the
385 succeeding sections. The numbers in comment lines of 389 next sections. The numbers in the comment lines of the
386 <function>snd_mychip_probe()</function> function are the 390 <function>snd_mychip_probe()</function> function
387 markers. 391 refer to details explained in the following section.
388 392
389 <example> 393 <example>
390 <title>Basic Flow for PCI Drivers Example</title> 394 <title>Basic Flow for PCI Drivers - Example</title>
391 <programlisting> 395 <programlisting>
392<![CDATA[ 396<![CDATA[
393 #include <sound/driver.h> 397 #include <sound/driver.h>
@@ -398,6 +402,7 @@
398 #include <sound/initval.h> 402 #include <sound/initval.h>
399 403
400 /* module parameters (see "Module Parameters") */ 404 /* module parameters (see "Module Parameters") */
405 /* SNDRV_CARDS: maximum number of cards supported by this module */
401 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; 406 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
402 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; 407 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
403 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; 408 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
@@ -405,13 +410,13 @@
405 /* definition of the chip-specific record */ 410 /* definition of the chip-specific record */
406 struct mychip { 411 struct mychip {
407 struct snd_card *card; 412 struct snd_card *card;
408 /* rest of implementation will be in the section 413 /* the rest of the implementation will be in section
409 * "PCI Resource Managements" 414 * "PCI Resource Management"
410 */ 415 */
411 }; 416 };
412 417
413 /* chip-specific destructor 418 /* chip-specific destructor
414 * (see "PCI Resource Managements") 419 * (see "PCI Resource Management")
415 */ 420 */
416 static int snd_mychip_free(struct mychip *chip) 421 static int snd_mychip_free(struct mychip *chip)
417 { 422 {
@@ -442,7 +447,7 @@
442 *rchip = NULL; 447 *rchip = NULL;
443 448
444 /* check PCI availability here 449 /* check PCI availability here
445 * (see "PCI Resource Managements") 450 * (see "PCI Resource Management")
446 */ 451 */
447 .... 452 ....
448 453
@@ -454,7 +459,7 @@
454 chip->card = card; 459 chip->card = card;
455 460
456 /* rest of initialization here; will be implemented 461 /* rest of initialization here; will be implemented
457 * later, see "PCI Resource Managements" 462 * later, see "PCI Resource Management"
458 */ 463 */
459 .... 464 ....
460 465
@@ -521,7 +526,7 @@
521 return 0; 526 return 0;
522 } 527 }
523 528
524 /* destructor -- see "Destructor" sub-section */ 529 /* destructor -- see the "Destructor" sub-section */
525 static void __devexit snd_mychip_remove(struct pci_dev *pci) 530 static void __devexit snd_mychip_remove(struct pci_dev *pci)
526 { 531 {
527 snd_card_free(pci_get_drvdata(pci)); 532 snd_card_free(pci_get_drvdata(pci));
@@ -536,16 +541,16 @@
536 <section id="basic-flow-constructor"> 541 <section id="basic-flow-constructor">
537 <title>Constructor</title> 542 <title>Constructor</title>
538 <para> 543 <para>
539 The real constructor of PCI drivers is probe callback. The 544 The real constructor of PCI drivers is the <function>probe</function> callback.
540 probe callback and other component-constructors which are called 545 The <function>probe</function> callback and other component-constructors which are called
541 from probe callback should be defined with 546 from the <function>probe</function> callback should be defined with
542 <parameter>__devinit</parameter> prefix. You 547 the <parameter>__devinit</parameter> prefix. You
543 cannot use <parameter>__init</parameter> prefix for them, 548 cannot use the <parameter>__init</parameter> prefix for them,
544 because any PCI device could be a hotplug device. 549 because any PCI device could be a hotplug device.
545 </para> 550 </para>
546 551
547 <para> 552 <para>
548 In the probe callback, the following scheme is often used. 553 In the <function>probe</function> callback, the following scheme is often used.
549 </para> 554 </para>
550 555
551 <section id="basic-flow-constructor-device-index"> 556 <section id="basic-flow-constructor-device-index">
@@ -570,7 +575,7 @@
570 </para> 575 </para>
571 576
572 <para> 577 <para>
573 At each time probe callback is called, check the 578 Each time the <function>probe</function> callback is called, check the
574 availability of the device. If not available, simply increment 579 availability of the device. If not available, simply increment
575 the device index and returns. dev will be incremented also 580 the device index and returns. dev will be incremented also
576 later (<link 581 later (<link
@@ -594,7 +599,7 @@
594 </para> 599 </para>
595 600
596 <para> 601 <para>
597 The detail will be explained in the section 602 The details will be explained in the section
598 <link linkend="card-management-card-instance"><citetitle> 603 <link linkend="card-management-card-instance"><citetitle>
599 Management of Cards and Components</citetitle></link>. 604 Management of Cards and Components</citetitle></link>.
600 </para> 605 </para>
@@ -619,9 +624,9 @@
619 </programlisting> 624 </programlisting>
620 </informalexample> 625 </informalexample>
621 626
622 The detail will be explained in the section <link 627 The details will be explained in the section <link
623 linkend="pci-resource"><citetitle>PCI Resource 628 linkend="pci-resource"><citetitle>PCI Resource
624 Managements</citetitle></link>. 629 Management</citetitle></link>.
625 </para> 630 </para>
626 </section> 631 </section>
627 632
@@ -640,7 +645,7 @@
640 </informalexample> 645 </informalexample>
641 646
642 The driver field holds the minimal ID string of the 647 The driver field holds the minimal ID string of the
643 chip. This is referred by alsa-lib's configurator, so keep it 648 chip. This is used by alsa-lib's configurator, so keep it
644 simple but unique. 649 simple but unique.
645 Even the same driver can have different driver IDs to 650 Even the same driver can have different driver IDs to
646 distinguish the functionality of each chip type. 651 distinguish the functionality of each chip type.
@@ -648,7 +653,7 @@
648 653
649 <para> 654 <para>
650 The shortname field is a string shown as more verbose 655 The shortname field is a string shown as more verbose
651 name. The longname field contains the information which is 656 name. The longname field contains the information
652 shown in <filename>/proc/asound/cards</filename>. 657 shown in <filename>/proc/asound/cards</filename>.
653 </para> 658 </para>
654 </section> 659 </section>
@@ -703,7 +708,7 @@
703 </informalexample> 708 </informalexample>
704 709
705 In the above, the card record is stored. This pointer is 710 In the above, the card record is stored. This pointer is
706 referred in the remove callback and power-management 711 used in the remove callback and power-management
707 callbacks, too. 712 callbacks, too.
708 </para> 713 </para>
709 </section> 714 </section>
@@ -757,22 +762,22 @@
757 </informalexample> 762 </informalexample>
758 763
759 where the last one is necessary only when module options are 764 where the last one is necessary only when module options are
760 defined in the source file. If the codes are split to several 765 defined in the source file. If the code is split into several
761 files, the file without module options don't need them. 766 files, the files without module options don't need them.
762 </para> 767 </para>
763 768
764 <para> 769 <para>
765 In addition to them, you'll need 770 In addition to these headers, you'll need
766 <filename>&lt;linux/interrupt.h&gt;</filename> for the interrupt 771 <filename>&lt;linux/interrupt.h&gt;</filename> for interrupt
767 handling, and <filename>&lt;asm/io.h&gt;</filename> for the i/o 772 handling, and <filename>&lt;asm/io.h&gt;</filename> for I/O
768 access. If you use <function>mdelay()</function> or 773 access. If you use the <function>mdelay()</function> or
769 <function>udelay()</function> functions, you'll need to include 774 <function>udelay()</function> functions, you'll need to include
770 <filename>&lt;linux/delay.h&gt;</filename>, too. 775 <filename>&lt;linux/delay.h&gt;</filename> too.
771 </para> 776 </para>
772 777
773 <para> 778 <para>
774 The ALSA interfaces like PCM or control API are defined in other 779 The ALSA interfaces like the PCM and control APIs are defined in other
775 header files as <filename>&lt;sound/xxx.h&gt;</filename>. 780 <filename>&lt;sound/xxx.h&gt;</filename> header files.
776 They have to be included after 781 They have to be included after
777 <filename>&lt;sound/core.h&gt;</filename>. 782 <filename>&lt;sound/core.h&gt;</filename>.
778 </para> 783 </para>
@@ -795,12 +800,12 @@
795 800
796 <para> 801 <para>
797 A card record is the headquarters of the soundcard. It manages 802 A card record is the headquarters of the soundcard. It manages
798 the list of whole devices (components) on the soundcard, such as 803 the whole list of devices (components) on the soundcard, such as
799 PCM, mixers, MIDI, synthesizer, and so on. Also, the card 804 PCM, mixers, MIDI, synthesizer, and so on. Also, the card
800 record holds the ID and the name strings of the card, manages 805 record holds the ID and the name strings of the card, manages
801 the root of proc files, and controls the power-management states 806 the root of proc files, and controls the power-management states
802 and hotplug disconnections. The component list on the card 807 and hotplug disconnections. The component list on the card
803 record is used to manage the proper releases of resources at 808 record is used to manage the correct release of resources at
804 destruction. 809 destruction.
805 </para> 810 </para>
806 811
@@ -824,9 +829,8 @@
824 <constant>THIS_MODULE</constant>), 829 <constant>THIS_MODULE</constant>),
825 and the size of extra-data space. The last argument is used to 830 and the size of extra-data space. The last argument is used to
826 allocate card-&gt;private_data for the 831 allocate card-&gt;private_data for the
827 chip-specific data. Note that this data 832 chip-specific data. Note that these data
828 <emphasis>is</emphasis> allocated by 833 are allocated by <function>snd_card_new()</function>.
829 <function>snd_card_new()</function>.
830 </para> 834 </para>
831 </section> 835 </section>
832 836
@@ -834,10 +838,10 @@
834 <title>Components</title> 838 <title>Components</title>
835 <para> 839 <para>
836 After the card is created, you can attach the components 840 After the card is created, you can attach the components
837 (devices) to the card instance. On ALSA driver, a component is 841 (devices) to the card instance. In an ALSA driver, a component is
838 represented as a struct <structname>snd_device</structname> object. 842 represented as a struct <structname>snd_device</structname> object.
839 A component can be a PCM instance, a control interface, a raw 843 A component can be a PCM instance, a control interface, a raw
840 MIDI interface, etc. Each of such instances has one component 844 MIDI interface, etc. Each such instance has one component
841 entry. 845 entry.
842 </para> 846 </para>
843 847
@@ -859,7 +863,7 @@
859 (<constant>SNDRV_DEV_XXX</constant>), the data pointer, and the 863 (<constant>SNDRV_DEV_XXX</constant>), the data pointer, and the
860 callback pointers (<parameter>&amp;ops</parameter>). The 864 callback pointers (<parameter>&amp;ops</parameter>). The
861 device-level defines the type of components and the order of 865 device-level defines the type of components and the order of
862 registration and de-registration. For most of components, the 866 registration and de-registration. For most components, the
863 device-level is already defined. For a user-defined component, 867 device-level is already defined. For a user-defined component,
864 you can use <constant>SNDRV_DEV_LOWLEVEL</constant>. 868 you can use <constant>SNDRV_DEV_LOWLEVEL</constant>.
865 </para> 869 </para>
@@ -867,13 +871,13 @@
867 <para> 871 <para>
868 This function itself doesn't allocate the data space. The data 872 This function itself doesn't allocate the data space. The data
869 must be allocated manually beforehand, and its pointer is passed 873 must be allocated manually beforehand, and its pointer is passed
870 as the argument. This pointer is used as the identifier 874 as the argument. This pointer is used as the
871 (<parameter>chip</parameter> in the above example) for the 875 (<parameter>chip</parameter> identifier in the above example)
872 instance. 876 for the instance.
873 </para> 877 </para>
874 878
875 <para> 879 <para>
876 Each ALSA pre-defined component such as ac97 or pcm calls 880 Each pre-defined ALSA component such as ac97 and pcm calls
877 <function>snd_device_new()</function> inside its 881 <function>snd_device_new()</function> inside its
878 constructor. The destructor for each component is defined in the 882 constructor. The destructor for each component is defined in the
879 callback pointers. Hence, you don't need to take care of 883 callback pointers. Hence, you don't need to take care of
@@ -881,19 +885,19 @@
881 </para> 885 </para>
882 886
883 <para> 887 <para>
884 If you would like to create your own component, you need to 888 If you wish to create your own component, you need to
885 set the destructor function to dev_free callback in 889 set the destructor function to the dev_free callback in
886 <parameter>ops</parameter>, so that it can be released 890 the <parameter>ops</parameter>, so that it can be released
887 automatically via <function>snd_card_free()</function>. The 891 automatically via <function>snd_card_free()</function>.
888 example will be shown later as an implementation of a 892 The next example will show an implementation of chip-specific
889 chip-specific data. 893 data.
890 </para> 894 </para>
891 </section> 895 </section>
892 896
893 <section id="card-management-chip-specific"> 897 <section id="card-management-chip-specific">
894 <title>Chip-Specific Data</title> 898 <title>Chip-Specific Data</title>
895 <para> 899 <para>
896 The chip-specific information, e.g. the i/o port address, its 900 Chip-specific information, e.g. the I/O port address, its
897 resource pointer, or the irq number, is stored in the 901 resource pointer, or the irq number, is stored in the
898 chip-specific record. 902 chip-specific record.
899 903
@@ -909,13 +913,14 @@
909 </para> 913 </para>
910 914
911 <para> 915 <para>
912 In general, there are two ways to allocate the chip record. 916 In general, there are two ways of allocating the chip record.
913 </para> 917 </para>
914 918
915 <section id="card-management-chip-specific-snd-card-new"> 919 <section id="card-management-chip-specific-snd-card-new">
916 <title>1. Allocating via <function>snd_card_new()</function>.</title> 920 <title>1. Allocating via <function>snd_card_new()</function>.</title>
917 <para> 921 <para>
918 As mentioned above, you can pass the extra-data-length to the 4th argument of <function>snd_card_new()</function>, i.e. 922 As mentioned above, you can pass the extra-data-length
923 to the 4th argument of <function>snd_card_new()</function>, i.e.
919 924
920 <informalexample> 925 <informalexample>
921 <programlisting> 926 <programlisting>
@@ -925,7 +930,7 @@
925 </programlisting> 930 </programlisting>
926 </informalexample> 931 </informalexample>
927 932
928 whether struct <structname>mychip</structname> is the type of the chip record. 933 struct <structname>mychip</structname> is the type of the chip record.
929 </para> 934 </para>
930 935
931 <para> 936 <para>
@@ -1037,8 +1042,8 @@
1037 <title>Registration and Release</title> 1042 <title>Registration and Release</title>
1038 <para> 1043 <para>
1039 After all components are assigned, register the card instance 1044 After all components are assigned, register the card instance
1040 by calling <function>snd_card_register()</function>. The access 1045 by calling <function>snd_card_register()</function>. Access
1041 to the device files are enabled at this point. That is, before 1046 to the device files is enabled at this point. That is, before
1042 <function>snd_card_register()</function> is called, the 1047 <function>snd_card_register()</function> is called, the
1043 components are safely inaccessible from external side. If this 1048 components are safely inaccessible from external side. If this
1044 call fails, exit the probe function after releasing the card via 1049 call fails, exit the probe function after releasing the card via
@@ -1047,7 +1052,7 @@
1047 1052
1048 <para> 1053 <para>
1049 For releasing the card instance, you can call simply 1054 For releasing the card instance, you can call simply
1050 <function>snd_card_free()</function>. As already mentioned, all 1055 <function>snd_card_free()</function>. As mentioned earlier, all
1051 components are released automatically by this call. 1056 components are released automatically by this call.
1052 </para> 1057 </para>
1053 1058
@@ -1055,7 +1060,7 @@
1055 As further notes, the destructors (both 1060 As further notes, the destructors (both
1056 <function>snd_mychip_dev_free</function> and 1061 <function>snd_mychip_dev_free</function> and
1057 <function>snd_mychip_free</function>) cannot be defined with 1062 <function>snd_mychip_free</function>) cannot be defined with
1058 <parameter>__devexit</parameter> prefix, because they may be 1063 the <parameter>__devexit</parameter> prefix, because they may be
1059 called from the constructor, too, at the false path. 1064 called from the constructor, too, at the false path.
1060 </para> 1065 </para>
1061 1066
@@ -1071,20 +1076,20 @@
1071 1076
1072 1077
1073<!-- ****************************************************** --> 1078<!-- ****************************************************** -->
1074<!-- PCI Resource Managements --> 1079<!-- PCI Resource Management -->
1075<!-- ****************************************************** --> 1080<!-- ****************************************************** -->
1076 <chapter id="pci-resource"> 1081 <chapter id="pci-resource">
1077 <title>PCI Resource Managements</title> 1082 <title>PCI Resource Management</title>
1078 1083
1079 <section id="pci-resource-example"> 1084 <section id="pci-resource-example">
1080 <title>Full Code Example</title> 1085 <title>Full Code Example</title>
1081 <para> 1086 <para>
1082 In this section, we'll finish the chip-specific constructor, 1087 In this section, we'll complete the chip-specific constructor,
1083 destructor and PCI entries. The example code is shown first, 1088 destructor and PCI entries. Example code is shown first,
1084 below. 1089 below.
1085 1090
1086 <example> 1091 <example>
1087 <title>PCI Resource Managements Example</title> 1092 <title>PCI Resource Management Example</title>
1088 <programlisting> 1093 <programlisting>
1089<![CDATA[ 1094<![CDATA[
1090 struct mychip { 1095 struct mychip {
@@ -1103,7 +1108,7 @@
1103 /* release the irq */ 1108 /* release the irq */
1104 if (chip->irq >= 0) 1109 if (chip->irq >= 0)
1105 free_irq(chip->irq, chip); 1110 free_irq(chip->irq, chip);
1106 /* release the i/o ports & memory */ 1111 /* release the I/O ports & memory */
1107 pci_release_regions(chip->pci); 1112 pci_release_regions(chip->pci);
1108 /* disable the PCI entry */ 1113 /* disable the PCI entry */
1109 pci_disable_device(chip->pci); 1114 pci_disable_device(chip->pci);
@@ -1196,13 +1201,13 @@
1196 .remove = __devexit_p(snd_mychip_remove), 1201 .remove = __devexit_p(snd_mychip_remove),
1197 }; 1202 };
1198 1203
1199 /* initialization of the module */ 1204 /* module initialization */
1200 static int __init alsa_card_mychip_init(void) 1205 static int __init alsa_card_mychip_init(void)
1201 { 1206 {
1202 return pci_register_driver(&driver); 1207 return pci_register_driver(&driver);
1203 } 1208 }
1204 1209
1205 /* clean up the module */ 1210 /* module clean up */
1206 static void __exit alsa_card_mychip_exit(void) 1211 static void __exit alsa_card_mychip_exit(void)
1207 { 1212 {
1208 pci_unregister_driver(&driver); 1213 pci_unregister_driver(&driver);
@@ -1228,10 +1233,10 @@
1228 </para> 1233 </para>
1229 1234
1230 <para> 1235 <para>
1231 In the case of PCI devices, you have to call at first 1236 In the case of PCI devices, you first have to call
1232 <function>pci_enable_device()</function> function before 1237 the <function>pci_enable_device()</function> function before
1233 allocating resources. Also, you need to set the proper PCI DMA 1238 allocating resources. Also, you need to set the proper PCI DMA
1234 mask to limit the accessed i/o range. In some cases, you might 1239 mask to limit the accessed I/O range. In some cases, you might
1235 need to call <function>pci_set_master()</function> function, 1240 need to call <function>pci_set_master()</function> function,
1236 too. 1241 too.
1237 </para> 1242 </para>
@@ -1261,15 +1266,15 @@
1261 <section id="pci-resource-resource-allocation"> 1266 <section id="pci-resource-resource-allocation">
1262 <title>Resource Allocation</title> 1267 <title>Resource Allocation</title>
1263 <para> 1268 <para>
1264 The allocation of I/O ports and irqs are done via standard kernel 1269 The allocation of I/O ports and irqs is done via standard kernel
1265 functions. Unlike ALSA ver.0.5.x., there are no helpers for 1270 functions. Unlike ALSA ver.0.5.x., there are no helpers for
1266 that. And these resources must be released in the destructor 1271 that. And these resources must be released in the destructor
1267 function (see below). Also, on ALSA 0.9.x, you don't need to 1272 function (see below). Also, on ALSA 0.9.x, you don't need to
1268 allocate (pseudo-)DMA for PCI like ALSA 0.5.x. 1273 allocate (pseudo-)DMA for PCI like in ALSA 0.5.x.
1269 </para> 1274 </para>
1270 1275
1271 <para> 1276 <para>
1272 Now assume that this PCI device has an I/O port with 8 bytes 1277 Now assume that the PCI device has an I/O port with 8 bytes
1273 and an interrupt. Then struct <structname>mychip</structname> will have the 1278 and an interrupt. Then struct <structname>mychip</structname> will have the
1274 following fields: 1279 following fields:
1275 1280
@@ -1288,7 +1293,7 @@
1288 </para> 1293 </para>
1289 1294
1290 <para> 1295 <para>
1291 For an i/o port (and also a memory region), you need to have 1296 For an I/O port (and also a memory region), you need to have
1292 the resource pointer for the standard resource management. For 1297 the resource pointer for the standard resource management. For
1293 an irq, you have to keep only the irq number (integer). But you 1298 an irq, you have to keep only the irq number (integer). But you
1294 need to initialize this number as -1 before actual allocation, 1299 need to initialize this number as -1 before actual allocation,
@@ -1299,7 +1304,7 @@
1299 </para> 1304 </para>
1300 1305
1301 <para> 1306 <para>
1302 The allocation of an i/o port is done like this: 1307 The allocation of an I/O port is done like this:
1303 1308
1304 <informalexample> 1309 <informalexample>
1305 <programlisting> 1310 <programlisting>
@@ -1318,12 +1323,12 @@
1318 1323
1319 <para> 1324 <para>
1320 <!-- obsolete --> 1325 <!-- obsolete -->
1321 It will reserve the i/o port region of 8 bytes of the given 1326 It will reserve the I/O port region of 8 bytes of the given
1322 PCI device. The returned value, chip-&gt;res_port, is allocated 1327 PCI device. The returned value, chip-&gt;res_port, is allocated
1323 via <function>kmalloc()</function> by 1328 via <function>kmalloc()</function> by
1324 <function>request_region()</function>. The pointer must be 1329 <function>request_region()</function>. The pointer must be
1325 released via <function>kfree()</function>, but there is some 1330 released via <function>kfree()</function>, but there is a
1326 problem regarding this. This issue will be explained more below. 1331 problem with this. This issue will be explained later.
1327 </para> 1332 </para>
1328 1333
1329 <para> 1334 <para>
@@ -1351,8 +1356,8 @@
1351 </para> 1356 </para>
1352 1357
1353 <para> 1358 <para>
1354 On the PCI bus, the interrupts can be shared. Thus, 1359 On the PCI bus, interrupts can be shared. Thus,
1355 <constant>IRQF_SHARED</constant> is given as the interrupt flag of 1360 <constant>IRQF_SHARED</constant> is used as the interrupt flag of
1356 <function>request_irq()</function>. 1361 <function>request_irq()</function>.
1357 </para> 1362 </para>
1358 1363
@@ -1364,7 +1369,7 @@
1364 </para> 1369 </para>
1365 1370
1366 <para> 1371 <para>
1367 I won't define the detail of the interrupt handler at this 1372 I won't give details about the interrupt handler at this
1368 point, but at least its appearance can be explained now. The 1373 point, but at least its appearance can be explained now. The
1369 interrupt handler looks usually like the following: 1374 interrupt handler looks usually like the following:
1370 1375
@@ -1386,11 +1391,11 @@
1386 Now let's write the corresponding destructor for the resources 1391 Now let's write the corresponding destructor for the resources
1387 above. The role of destructor is simple: disable the hardware 1392 above. The role of destructor is simple: disable the hardware
1388 (if already activated) and release the resources. So far, we 1393 (if already activated) and release the resources. So far, we
1389 have no hardware part, so the disabling is not written here. 1394 have no hardware part, so the disabling code is not written here.
1390 </para> 1395 </para>
1391 1396
1392 <para> 1397 <para>
1393 For releasing the resources, <quote>check-and-release</quote> 1398 To release the resources, the <quote>check-and-release</quote>
1394 method is a safer way. For the interrupt, do like this: 1399 method is a safer way. For the interrupt, do like this:
1395 1400
1396 <informalexample> 1401 <informalexample>
@@ -1410,7 +1415,7 @@
1410 <para> 1415 <para>
1411 When you requested I/O ports or memory regions via 1416 When you requested I/O ports or memory regions via
1412 <function>pci_request_region()</function> or 1417 <function>pci_request_region()</function> or
1413 <function>pci_request_regions()</function> like this example, 1418 <function>pci_request_regions()</function> like in this example,
1414 release the resource(s) using the corresponding function, 1419 release the resource(s) using the corresponding function,
1415 <function>pci_release_region()</function> or 1420 <function>pci_release_region()</function> or
1416 <function>pci_release_regions()</function>. 1421 <function>pci_release_regions()</function>.
@@ -1429,7 +1434,7 @@
1429 or <function>request_mem_region</function>, you can release it via 1434 or <function>request_mem_region</function>, you can release it via
1430 <function>release_resource()</function>. Suppose that you keep 1435 <function>release_resource()</function>. Suppose that you keep
1431 the resource pointer returned from <function>request_region()</function> 1436 the resource pointer returned from <function>request_region()</function>
1432 in chip-&gt;res_port, the release procedure looks like below: 1437 in chip-&gt;res_port, the release procedure looks like:
1433 1438
1434 <informalexample> 1439 <informalexample>
1435 <programlisting> 1440 <programlisting>
@@ -1442,7 +1447,7 @@
1442 1447
1443 <para> 1448 <para>
1444 Don't forget to call <function>pci_disable_device()</function> 1449 Don't forget to call <function>pci_disable_device()</function>
1445 before all finished. 1450 before the end.
1446 </para> 1451 </para>
1447 1452
1448 <para> 1453 <para>
@@ -1459,14 +1464,14 @@
1459 1464
1460 <para> 1465 <para>
1461 Again, remember that you cannot 1466 Again, remember that you cannot
1462 set <parameter>__devexit</parameter> prefix for this destructor. 1467 use the <parameter>__devexit</parameter> prefix for this destructor.
1463 </para> 1468 </para>
1464 1469
1465 <para> 1470 <para>
1466 We didn't implement the hardware-disabling part in the above. 1471 We didn't implement the hardware disabling part in the above.
1467 If you need to do this, please note that the destructor may be 1472 If you need to do this, please note that the destructor may be
1468 called even before the initialization of the chip is completed. 1473 called even before the initialization of the chip is completed.
1469 It would be better to have a flag to skip the hardware-disabling 1474 It would be better to have a flag to skip hardware disabling
1470 if the hardware was not initialized yet. 1475 if the hardware was not initialized yet.
1471 </para> 1476 </para>
1472 1477
@@ -1475,14 +1480,14 @@
1475 <function>snd_device_new()</function> with 1480 <function>snd_device_new()</function> with
1476 <constant>SNDRV_DEV_LOWLELVEL</constant> , its destructor is 1481 <constant>SNDRV_DEV_LOWLELVEL</constant> , its destructor is
1477 called at the last. That is, it is assured that all other 1482 called at the last. That is, it is assured that all other
1478 components like PCMs and controls have been already released. 1483 components like PCMs and controls have already been released.
1479 You don't have to call stopping PCMs, etc. explicitly, but just 1484 You don't have to stop PCMs, etc. explicitly, but just
1480 stop the hardware in the low-level. 1485 call low-level hardware stopping.
1481 </para> 1486 </para>
1482 1487
1483 <para> 1488 <para>
1484 The management of a memory-mapped region is almost as same as 1489 The management of a memory-mapped region is almost as same as
1485 the management of an i/o port. You'll need three fields like 1490 the management of an I/O port. You'll need three fields like
1486 the following: 1491 the following:
1487 1492
1488 <informalexample> 1493 <informalexample>
@@ -1561,8 +1566,8 @@
1561 <section id="pci-resource-entries"> 1566 <section id="pci-resource-entries">
1562 <title>PCI Entries</title> 1567 <title>PCI Entries</title>
1563 <para> 1568 <para>
1564 So far, so good. Let's finish the rest of missing PCI 1569 So far, so good. Let's finish the missing PCI
1565 stuffs. At first, we need a 1570 stuff. At first, we need a
1566 <structname>pci_device_id</structname> table for this 1571 <structname>pci_device_id</structname> table for this
1567 chipset. It's a table of PCI vendor/device ID number, and some 1572 chipset. It's a table of PCI vendor/device ID number, and some
1568 masks. 1573 masks.
@@ -1588,13 +1593,13 @@
1588 1593
1589 <para> 1594 <para>
1590 The first and second fields of 1595 The first and second fields of
1591 <structname>pci_device_id</structname> struct are the vendor and 1596 the <structname>pci_device_id</structname> structure are the vendor and
1592 device IDs. If you have nothing special to filter the matching 1597 device IDs. If you have no reason to filter the matching
1593 devices, you can use the rest of fields like above. The last 1598 devices, you can leave the remaining fields as above. The last
1594 field of <structname>pci_device_id</structname> struct is a 1599 field of the <structname>pci_device_id</structname> struct contains
1595 private data for this entry. You can specify any value here, for 1600 private data for this entry. You can specify any value here, for
1596 example, to tell the type of different operations per each 1601 example, to define specific operations for supported device IDs.
1597 device IDs. Such an example is found in intel8x0 driver. 1602 Such an example is found in the intel8x0 driver.
1598 </para> 1603 </para>
1599 1604
1600 <para> 1605 <para>
@@ -1621,10 +1626,10 @@
1621 1626
1622 <para> 1627 <para>
1623 The <structfield>probe</structfield> and 1628 The <structfield>probe</structfield> and
1624 <structfield>remove</structfield> functions are what we already 1629 <structfield>remove</structfield> functions have already
1625 defined in 1630 been defined in the previous sections.
1626 the previous sections. The <structfield>remove</structfield> should 1631 The <structfield>remove</structfield> function should
1627 be defined with 1632 be defined with the
1628 <function>__devexit_p()</function> macro, so that it's not 1633 <function>__devexit_p()</function> macro, so that it's not
1629 defined for built-in (and non-hot-pluggable) case. The 1634 defined for built-in (and non-hot-pluggable) case. The
1630 <structfield>name</structfield> 1635 <structfield>name</structfield>
@@ -1665,8 +1670,7 @@
1665 1670
1666 <para> 1671 <para>
1667 Oh, one thing was forgotten. If you have no exported symbols, 1672 Oh, one thing was forgotten. If you have no exported symbols,
1668 you need to declare it on 2.2 or 2.4 kernels (on 2.6 kernels 1673 you need to declare it in 2.2 or 2.4 kernels (it's not necessary in 2.6 kernels).
1669 it's not necessary, though).
1670 1674
1671 <informalexample> 1675 <informalexample>
1672 <programlisting> 1676 <programlisting>
@@ -1698,7 +1702,7 @@
1698 1702
1699 <para> 1703 <para>
1700 For accessing to the PCM layer, you need to include 1704 For accessing to the PCM layer, you need to include
1701 <filename>&lt;sound/pcm.h&gt;</filename> above all. In addition, 1705 <filename>&lt;sound/pcm.h&gt;</filename> first. In addition,
1702 <filename>&lt;sound/pcm_params.h&gt;</filename> might be needed 1706 <filename>&lt;sound/pcm_params.h&gt;</filename> might be needed
1703 if you access to some functions related with hw_param. 1707 if you access to some functions related with hw_param.
1704 </para> 1708 </para>
@@ -1707,21 +1711,21 @@
1707 Each card device can have up to four pcm instances. A pcm 1711 Each card device can have up to four pcm instances. A pcm
1708 instance corresponds to a pcm device file. The limitation of 1712 instance corresponds to a pcm device file. The limitation of
1709 number of instances comes only from the available bit size of 1713 number of instances comes only from the available bit size of
1710 the linux's device number. Once when 64bit device number is 1714 the Linux's device numbers. Once when 64bit device number is
1711 used, we'll have more available pcm instances. 1715 used, we'll have more pcm instances available.
1712 </para> 1716 </para>
1713 1717
1714 <para> 1718 <para>
1715 A pcm instance consists of pcm playback and capture streams, 1719 A pcm instance consists of pcm playback and capture streams,
1716 and each pcm stream consists of one or more pcm substreams. Some 1720 and each pcm stream consists of one or more pcm substreams. Some
1717 soundcard supports the multiple-playback function. For example, 1721 soundcards support multiple playback functions. For example,
1718 emu10k1 has a PCM playback of 32 stereo substreams. In this case, at 1722 emu10k1 has a PCM playback of 32 stereo substreams. In this case, at
1719 each open, a free substream is (usually) automatically chosen 1723 each open, a free substream is (usually) automatically chosen
1720 and opened. Meanwhile, when only one substream exists and it was 1724 and opened. Meanwhile, when only one substream exists and it was
1721 already opened, the succeeding open will result in the blocking 1725 already opened, the successful open will either block
1722 or the error with <constant>EAGAIN</constant> according to the 1726 or error with <constant>EAGAIN</constant> according to the
1723 file open mode. But you don't have to know the detail in your 1727 file open mode. But you don't have to care about such details in your
1724 driver. The PCM middle layer will take all such jobs. 1728 driver. The PCM middle layer will take care of such work.
1725 </para> 1729 </para>
1726 </section> 1730 </section>
1727 1731
@@ -1944,7 +1948,7 @@
1944 <section id="pcm-interface-constructor"> 1948 <section id="pcm-interface-constructor">
1945 <title>Constructor</title> 1949 <title>Constructor</title>
1946 <para> 1950 <para>
1947 A pcm instance is allocated by <function>snd_pcm_new()</function> 1951 A pcm instance is allocated by the <function>snd_pcm_new()</function>
1948 function. It would be better to create a constructor for pcm, 1952 function. It would be better to create a constructor for pcm,
1949 namely, 1953 namely,
1950 1954
@@ -1971,23 +1975,23 @@
1971 </para> 1975 </para>
1972 1976
1973 <para> 1977 <para>
1974 The <function>snd_pcm_new()</function> function takes the four 1978 The <function>snd_pcm_new()</function> function takes four
1975 arguments. The first argument is the card pointer to which this 1979 arguments. The first argument is the card pointer to which this
1976 pcm is assigned, and the second is the ID string. 1980 pcm is assigned, and the second is the ID string.
1977 </para> 1981 </para>
1978 1982
1979 <para> 1983 <para>
1980 The third argument (<parameter>index</parameter>, 0 in the 1984 The third argument (<parameter>index</parameter>, 0 in the
1981 above) is the index of this new pcm. It begins from zero. When 1985 above) is the index of this new pcm. It begins from zero. If
1982 you will create more than one pcm instances, specify the 1986 you create more than one pcm instances, specify the
1983 different numbers in this argument. For example, 1987 different numbers in this argument. For example,
1984 <parameter>index</parameter> = 1 for the second PCM device. 1988 <parameter>index</parameter> = 1 for the second PCM device.
1985 </para> 1989 </para>
1986 1990
1987 <para> 1991 <para>
1988 The fourth and fifth arguments are the number of substreams 1992 The fourth and fifth arguments are the number of substreams
1989 for playback and capture, respectively. Here both 1 are given in 1993 for playback and capture, respectively. Here 1 is used for
1990 the above example. When no playback or no capture is available, 1994 both arguments. When no playback or capture substreams are available,
1991 pass 0 to the corresponding argument. 1995 pass 0 to the corresponding argument.
1992 </para> 1996 </para>
1993 1997
@@ -2045,13 +2049,13 @@
2045 </programlisting> 2049 </programlisting>
2046 </informalexample> 2050 </informalexample>
2047 2051
2048 Each of callbacks is explained in the subsection 2052 All the callbacks are described in the
2049 <link linkend="pcm-interface-operators"><citetitle> 2053 <link linkend="pcm-interface-operators"><citetitle>
2050 Operators</citetitle></link>. 2054 Operators</citetitle></link> subsection.
2051 </para> 2055 </para>
2052 2056
2053 <para> 2057 <para>
2054 After setting the operators, most likely you'd like to 2058 After setting the operators, you probably will want to
2055 pre-allocate the buffer. For the pre-allocation, simply call 2059 pre-allocate the buffer. For the pre-allocation, simply call
2056 the following: 2060 the following:
2057 2061
@@ -2065,8 +2069,8 @@
2065 </programlisting> 2069 </programlisting>
2066 </informalexample> 2070 </informalexample>
2067 2071
2068 It will allocate up to 64kB buffer as default. The details of 2072 It will allocate a buffer up to 64kB as default.
2069 buffer management will be described in the later section <link 2073 Buffer management details will be described in the later section <link
2070 linkend="buffer-and-memory"><citetitle>Buffer and Memory 2074 linkend="buffer-and-memory"><citetitle>Buffer and Memory
2071 Management</citetitle></link>. 2075 Management</citetitle></link>.
2072 </para> 2076 </para>
@@ -2095,13 +2099,13 @@
2095 <para> 2099 <para>
2096 The destructor for a pcm instance is not always 2100 The destructor for a pcm instance is not always
2097 necessary. Since the pcm device will be released by the middle 2101 necessary. Since the pcm device will be released by the middle
2098 layer code automatically, you don't have to call destructor 2102 layer code automatically, you don't have to call the destructor
2099 explicitly. 2103 explicitly.
2100 </para> 2104 </para>
2101 2105
2102 <para> 2106 <para>
2103 The destructor would be necessary when you created some 2107 The destructor would be necessary if you created
2104 special records internally and need to release them. In such a 2108 special records internally and needed to release them. In such a
2105 case, set the destructor function to 2109 case, set the destructor function to
2106 pcm-&gt;private_free: 2110 pcm-&gt;private_free:
2107 2111
@@ -2141,16 +2145,15 @@
2141 When the PCM substream is opened, a PCM runtime instance is 2145 When the PCM substream is opened, a PCM runtime instance is
2142 allocated and assigned to the substream. This pointer is 2146 allocated and assigned to the substream. This pointer is
2143 accessible via <constant>substream-&gt;runtime</constant>. 2147 accessible via <constant>substream-&gt;runtime</constant>.
2144 This runtime pointer holds the various information; it holds 2148 This runtime pointer holds most information you need
2145 the copy of hw_params and sw_params configurations, the buffer 2149 to control the PCM: the copy of hw_params and sw_params configurations, the buffer
2146 pointers, mmap records, spinlocks, etc. Almost everything you 2150 pointers, mmap records, spinlocks, etc.
2147 need for controlling the PCM can be found there.
2148 </para> 2151 </para>
2149 2152
2150 <para> 2153 <para>
2151 The definition of runtime instance is found in 2154 The definition of runtime instance is found in
2152 <filename>&lt;sound/pcm.h&gt;</filename>. Here is the 2155 <filename>&lt;sound/pcm.h&gt;</filename>. Here are
2153 copy from the file. 2156 the contents of this file:
2154 <informalexample> 2157 <informalexample>
2155 <programlisting> 2158 <programlisting>
2156<![CDATA[ 2159<![CDATA[
@@ -2244,7 +2247,7 @@ struct _snd_pcm_runtime {
2244 <para> 2247 <para>
2245 For the operators (callbacks) of each sound driver, most of 2248 For the operators (callbacks) of each sound driver, most of
2246 these records are supposed to be read-only. Only the PCM 2249 these records are supposed to be read-only. Only the PCM
2247 middle-layer changes / updates these info. The exceptions are 2250 middle-layer changes / updates them. The exceptions are
2248 the hardware description (hw), interrupt callbacks 2251 the hardware description (hw), interrupt callbacks
2249 (transfer_ack_xxx), DMA buffer information, and the private 2252 (transfer_ack_xxx), DMA buffer information, and the private
2250 data. Besides, if you use the standard buffer allocation 2253 data. Besides, if you use the standard buffer allocation
@@ -2285,7 +2288,7 @@ struct _snd_pcm_runtime {
2285 </para> 2288 </para>
2286 2289
2287 <para> 2290 <para>
2288 Typically, you'll have a hardware descriptor like below: 2291 Typically, you'll have a hardware descriptor as below:
2289 <informalexample> 2292 <informalexample>
2290 <programlisting> 2293 <programlisting>
2291<![CDATA[ 2294<![CDATA[
@@ -2320,10 +2323,10 @@ struct _snd_pcm_runtime {
2320 <constant>SNDRV_PCM_INFO_XXX</constant>. Here, at least, you 2323 <constant>SNDRV_PCM_INFO_XXX</constant>. Here, at least, you
2321 have to specify whether the mmap is supported and which 2324 have to specify whether the mmap is supported and which
2322 interleaved format is supported. 2325 interleaved format is supported.
2323 When the mmap is supported, add 2326 When the is supported, add the
2324 <constant>SNDRV_PCM_INFO_MMAP</constant> flag here. When the 2327 <constant>SNDRV_PCM_INFO_MMAP</constant> flag here. When the
2325 hardware supports the interleaved or the non-interleaved 2328 hardware supports the interleaved or the non-interleaved
2326 format, <constant>SNDRV_PCM_INFO_INTERLEAVED</constant> or 2329 formats, <constant>SNDRV_PCM_INFO_INTERLEAVED</constant> or
2327 <constant>SNDRV_PCM_INFO_NONINTERLEAVED</constant> flag must 2330 <constant>SNDRV_PCM_INFO_NONINTERLEAVED</constant> flag must
2328 be set, respectively. If both are supported, you can set both, 2331 be set, respectively. If both are supported, you can set both,
2329 too. 2332 too.
@@ -2331,7 +2334,7 @@ struct _snd_pcm_runtime {
2331 2334
2332 <para> 2335 <para>
2333 In the above example, <constant>MMAP_VALID</constant> and 2336 In the above example, <constant>MMAP_VALID</constant> and
2334 <constant>BLOCK_TRANSFER</constant> are specified for OSS mmap 2337 <constant>BLOCK_TRANSFER</constant> are specified for the OSS mmap
2335 mode. Usually both are set. Of course, 2338 mode. Usually both are set. Of course,
2336 <constant>MMAP_VALID</constant> is set only if the mmap is 2339 <constant>MMAP_VALID</constant> is set only if the mmap is
2337 really supported. 2340 really supported.
@@ -2345,11 +2348,11 @@ struct _snd_pcm_runtime {
2345 <quote>pause</quote> operation, while the 2348 <quote>pause</quote> operation, while the
2346 <constant>RESUME</constant> bit means that the pcm supports 2349 <constant>RESUME</constant> bit means that the pcm supports
2347 the full <quote>suspend/resume</quote> operation. 2350 the full <quote>suspend/resume</quote> operation.
2348 If <constant>PAUSE</constant> flag is set, 2351 If the <constant>PAUSE</constant> flag is set,
2349 the <structfield>trigger</structfield> callback below 2352 the <structfield>trigger</structfield> callback below
2350 must handle the corresponding (pause push/release) commands. 2353 must handle the corresponding (pause push/release) commands.
2351 The suspend/resume trigger commands can be defined even without 2354 The suspend/resume trigger commands can be defined even without
2352 <constant>RESUME</constant> flag. See <link 2355 the <constant>RESUME</constant> flag. See <link
2353 linkend="power-management"><citetitle> 2356 linkend="power-management"><citetitle>
2354 Power Management</citetitle></link> section for details. 2357 Power Management</citetitle></link> section for details.
2355 </para> 2358 </para>
@@ -2382,7 +2385,7 @@ struct _snd_pcm_runtime {
2382 <constant>CONTINUOUS</constant> bit additionally. 2385 <constant>CONTINUOUS</constant> bit additionally.
2383 The pre-defined rate bits are provided only for typical 2386 The pre-defined rate bits are provided only for typical
2384 rates. If your chip supports unconventional rates, you need to add 2387 rates. If your chip supports unconventional rates, you need to add
2385 <constant>KNOT</constant> bit and set up the hardware 2388 the <constant>KNOT</constant> bit and set up the hardware
2386 constraint manually (explained later). 2389 constraint manually (explained later).
2387 </para> 2390 </para>
2388 </listitem> 2391 </listitem>
@@ -2390,8 +2393,8 @@ struct _snd_pcm_runtime {
2390 <listitem> 2393 <listitem>
2391 <para> 2394 <para>
2392 <structfield>rate_min</structfield> and 2395 <structfield>rate_min</structfield> and
2393 <structfield>rate_max</structfield> define the minimal and 2396 <structfield>rate_max</structfield> define the minimum and
2394 maximal sample rate. This should correspond somehow to 2397 maximum sample rate. This should correspond somehow to
2395 <structfield>rates</structfield> bits. 2398 <structfield>rates</structfield> bits.
2396 </para> 2399 </para>
2397 </listitem> 2400 </listitem>
@@ -2400,7 +2403,7 @@ struct _snd_pcm_runtime {
2400 <para> 2403 <para>
2401 <structfield>channel_min</structfield> and 2404 <structfield>channel_min</structfield> and
2402 <structfield>channel_max</structfield> 2405 <structfield>channel_max</structfield>
2403 define, as you might already expected, the minimal and maximal 2406 define, as you might already expected, the minimum and maximum
2404 number of channels. 2407 number of channels.
2405 </para> 2408 </para>
2406 </listitem> 2409 </listitem>
@@ -2408,21 +2411,21 @@ struct _snd_pcm_runtime {
2408 <listitem> 2411 <listitem>
2409 <para> 2412 <para>
2410 <structfield>buffer_bytes_max</structfield> defines the 2413 <structfield>buffer_bytes_max</structfield> defines the
2411 maximal buffer size in bytes. There is no 2414 maximum buffer size in bytes. There is no
2412 <structfield>buffer_bytes_min</structfield> field, since 2415 <structfield>buffer_bytes_min</structfield> field, since
2413 it can be calculated from the minimal period size and the 2416 it can be calculated from the minimum period size and the
2414 minimal number of periods. 2417 minimum number of periods.
2415 Meanwhile, <structfield>period_bytes_min</structfield> and 2418 Meanwhile, <structfield>period_bytes_min</structfield> and
2416 define the minimal and maximal size of the period in bytes. 2419 define the minimum and maximum size of the period in bytes.
2417 <structfield>periods_max</structfield> and 2420 <structfield>periods_max</structfield> and
2418 <structfield>periods_min</structfield> define the maximal and 2421 <structfield>periods_min</structfield> define the maximum and
2419 minimal number of periods in the buffer. 2422 minimum number of periods in the buffer.
2420 </para> 2423 </para>
2421 2424
2422 <para> 2425 <para>
2423 The <quote>period</quote> is a term, that corresponds to 2426 The <quote>period</quote> is a term that corresponds to
2424 fragment in the OSS world. The period defines the size at 2427 a fragment in the OSS world. The period defines the size at
2425 which the PCM interrupt is generated. This size strongly 2428 which a PCM interrupt is generated. This size strongly
2426 depends on the hardware. 2429 depends on the hardware.
2427 Generally, the smaller period size will give you more 2430 Generally, the smaller period size will give you more
2428 interrupts, that is, more controls. 2431 interrupts, that is, more controls.
@@ -2435,8 +2438,8 @@ struct _snd_pcm_runtime {
2435 <listitem> 2438 <listitem>
2436 <para> 2439 <para>
2437 There is also a field <structfield>fifo_size</structfield>. 2440 There is also a field <structfield>fifo_size</structfield>.
2438 This specifies the size of the hardware FIFO, but it's not 2441 This specifies the size of the hardware FIFO, but currently it
2439 used currently in the driver nor in the alsa-lib. So, you 2442 is neither used in the driver nor in the alsa-lib. So, you
2440 can ignore this field. 2443 can ignore this field.
2441 </para> 2444 </para>
2442 </listitem> 2445 </listitem>
@@ -2450,7 +2453,7 @@ struct _snd_pcm_runtime {
2450 Ok, let's go back again to the PCM runtime records. 2453 Ok, let's go back again to the PCM runtime records.
2451 The most frequently referred records in the runtime instance are 2454 The most frequently referred records in the runtime instance are
2452 the PCM configurations. 2455 the PCM configurations.
2453 The PCM configurations are stored on runtime instance 2456 The PCM configurations are stored in the runtime instance
2454 after the application sends <type>hw_params</type> data via 2457 after the application sends <type>hw_params</type> data via
2455 alsa-lib. There are many fields copied from hw_params and 2458 alsa-lib. There are many fields copied from hw_params and
2456 sw_params structs. For example, 2459 sw_params structs. For example,
@@ -2461,11 +2464,11 @@ struct _snd_pcm_runtime {
2461 2464
2462 <para> 2465 <para>
2463 One thing to be noted is that the configured buffer and period 2466 One thing to be noted is that the configured buffer and period
2464 sizes are stored in <quote>frames</quote> in the runtime 2467 sizes are stored in <quote>frames</quote> in the runtime.
2465 In the ALSA world, 1 frame = channels * samples-size. 2468 In the ALSA world, 1 frame = channels * samples-size.
2466 For conversion between frames and bytes, you can use the 2469 For conversion between frames and bytes, you can use the
2467 helper functions, <function>frames_to_bytes()</function> and 2470 <function>frames_to_bytes()</function> and
2468 <function>bytes_to_frames()</function>. 2471 <function>bytes_to_frames()</function> helper functions.
2469 <informalexample> 2472 <informalexample>
2470 <programlisting> 2473 <programlisting>
2471<![CDATA[ 2474<![CDATA[
@@ -2515,7 +2518,7 @@ struct _snd_pcm_runtime {
2515 <structfield>dma_area</structfield> is necessary when the 2518 <structfield>dma_area</structfield> is necessary when the
2516 buffer is mmapped. If your driver doesn't support mmap, this 2519 buffer is mmapped. If your driver doesn't support mmap, this
2517 field is not necessary. <structfield>dma_addr</structfield> 2520 field is not necessary. <structfield>dma_addr</structfield>
2518 is also not mandatory. You can use 2521 is also optional. You can use
2519 <structfield>dma_private</structfield> as you like, too. 2522 <structfield>dma_private</structfield> as you like, too.
2520 </para> 2523 </para>
2521 </section> 2524 </section>
@@ -2524,14 +2527,14 @@ struct _snd_pcm_runtime {
2524 <title>Running Status</title> 2527 <title>Running Status</title>
2525 <para> 2528 <para>
2526 The running status can be referred via <constant>runtime-&gt;status</constant>. 2529 The running status can be referred via <constant>runtime-&gt;status</constant>.
2527 This is the pointer to struct <structname>snd_pcm_mmap_status</structname> 2530 This is the pointer to the struct <structname>snd_pcm_mmap_status</structname>
2528 record. For example, you can get the current DMA hardware 2531 record. For example, you can get the current DMA hardware
2529 pointer via <constant>runtime-&gt;status-&gt;hw_ptr</constant>. 2532 pointer via <constant>runtime-&gt;status-&gt;hw_ptr</constant>.
2530 </para> 2533 </para>
2531 2534
2532 <para> 2535 <para>
2533 The DMA application pointer can be referred via 2536 The DMA application pointer can be referred via
2534 <constant>runtime-&gt;control</constant>, which points 2537 <constant>runtime-&gt;control</constant>, which points to the
2535 struct <structname>snd_pcm_mmap_control</structname> record. 2538 struct <structname>snd_pcm_mmap_control</structname> record.
2536 However, accessing directly to this value is not recommended. 2539 However, accessing directly to this value is not recommended.
2537 </para> 2540 </para>
@@ -2542,14 +2545,14 @@ struct _snd_pcm_runtime {
2542 <para> 2545 <para>
2543 You can allocate a record for the substream and store it in 2546 You can allocate a record for the substream and store it in
2544 <constant>runtime-&gt;private_data</constant>. Usually, this 2547 <constant>runtime-&gt;private_data</constant>. Usually, this
2545 done in 2548 is done in
2546 <link linkend="pcm-interface-operators-open-callback"><citetitle> 2549 <link linkend="pcm-interface-operators-open-callback"><citetitle>
2547 the open callback</citetitle></link>. 2550 the open callback</citetitle></link>.
2548 Don't mix this with <constant>pcm-&gt;private_data</constant>. 2551 Don't mix this with <constant>pcm-&gt;private_data</constant>.
2549 The <constant>pcm-&gt;private_data</constant> usually points the 2552 The <constant>pcm-&gt;private_data</constant> usually points to the
2550 chip instance assigned statically at the creation of PCM, while the 2553 chip instance assigned statically at the creation of PCM, while the
2551 <constant>runtime-&gt;private_data</constant> points a dynamic 2554 <constant>runtime-&gt;private_data</constant> points to a dynamic
2552 data created at the PCM open callback. 2555 data structure created at the PCM open callback.
2553 2556
2554 <informalexample> 2557 <informalexample>
2555 <programlisting> 2558 <programlisting>
@@ -2579,7 +2582,7 @@ struct _snd_pcm_runtime {
2579 <para> 2582 <para>
2580 The field <structfield>transfer_ack_begin</structfield> and 2583 The field <structfield>transfer_ack_begin</structfield> and
2581 <structfield>transfer_ack_end</structfield> are called at 2584 <structfield>transfer_ack_end</structfield> are called at
2582 the beginning and the end of 2585 the beginning and at the end of
2583 <function>snd_pcm_period_elapsed()</function>, respectively. 2586 <function>snd_pcm_period_elapsed()</function>, respectively.
2584 </para> 2587 </para>
2585 </section> 2588 </section>
@@ -2589,17 +2592,18 @@ struct _snd_pcm_runtime {
2589 <section id="pcm-interface-operators"> 2592 <section id="pcm-interface-operators">
2590 <title>Operators</title> 2593 <title>Operators</title>
2591 <para> 2594 <para>
2592 OK, now let me explain the detail of each pcm callback 2595 OK, now let me give details about each pcm callback
2593 (<parameter>ops</parameter>). In general, every callback must 2596 (<parameter>ops</parameter>). In general, every callback must
2594 return 0 if successful, or a negative number with the error 2597 return 0 if successful, or a negative error number
2595 number such as <constant>-EINVAL</constant> at any 2598 such as <constant>-EINVAL</constant>. To choose an appropriate
2596 error. 2599 error number, it is advised to check what value other parts of
2600 the kernel return when the same kind of request fails.
2597 </para> 2601 </para>
2598 2602
2599 <para> 2603 <para>
2600 The callback function takes at least the argument with 2604 The callback function takes at least the argument with
2601 <structname>snd_pcm_substream</structname> pointer. For retrieving the 2605 <structname>snd_pcm_substream</structname> pointer. To retrieve
2602 chip record from the given substream instance, you can use the 2606 the chip record from the given substream instance, you can use the
2603 following macro. 2607 following macro.
2604 2608
2605 <informalexample> 2609 <informalexample>
@@ -2616,7 +2620,7 @@ struct _snd_pcm_runtime {
2616 The macro reads <constant>substream-&gt;private_data</constant>, 2620 The macro reads <constant>substream-&gt;private_data</constant>,
2617 which is a copy of <constant>pcm-&gt;private_data</constant>. 2621 which is a copy of <constant>pcm-&gt;private_data</constant>.
2618 You can override the former if you need to assign different data 2622 You can override the former if you need to assign different data
2619 records per PCM substream. For example, cmi8330 driver assigns 2623 records per PCM substream. For example, the cmi8330 driver assigns
2620 different private_data for playback and capture directions, 2624 different private_data for playback and capture directions,
2621 because it uses two different codecs (SB- and AD-compatible) for 2625 because it uses two different codecs (SB- and AD-compatible) for
2622 different directions. 2626 different directions.
@@ -2709,7 +2713,7 @@ struct _snd_pcm_runtime {
2709 <section id="pcm-interface-operators-ioctl-callback"> 2713 <section id="pcm-interface-operators-ioctl-callback">
2710 <title>ioctl callback</title> 2714 <title>ioctl callback</title>
2711 <para> 2715 <para>
2712 This is used for any special action to pcm ioctls. But 2716 This is used for any special call to pcm ioctls. But
2713 usually you can pass a generic ioctl callback, 2717 usually you can pass a generic ioctl callback,
2714 <function>snd_pcm_lib_ioctl</function>. 2718 <function>snd_pcm_lib_ioctl</function>.
2715 </para> 2719 </para>
@@ -2726,9 +2730,6 @@ struct _snd_pcm_runtime {
2726]]> 2730]]>
2727 </programlisting> 2731 </programlisting>
2728 </informalexample> 2732 </informalexample>
2729
2730 This and <structfield>hw_free</structfield> callbacks exist
2731 only on ALSA 0.9.x.
2732 </para> 2733 </para>
2733 2734
2734 <para> 2735 <para>
@@ -2740,13 +2741,13 @@ struct _snd_pcm_runtime {
2740 </para> 2741 </para>
2741 2742
2742 <para> 2743 <para>
2743 Many hardware set-up should be done in this callback, 2744 Many hardware setups should be done in this callback,
2744 including the allocation of buffers. 2745 including the allocation of buffers.
2745 </para> 2746 </para>
2746 2747
2747 <para> 2748 <para>
2748 Parameters to be initialized are retrieved by 2749 Parameters to be initialized are retrieved by
2749 <function>params_xxx()</function> macros. For allocating a 2750 <function>params_xxx()</function> macros. To allocate
2750 buffer, you can call a helper function, 2751 buffer, you can call a helper function,
2751 2752
2752 <informalexample> 2753 <informalexample>
@@ -2772,8 +2773,8 @@ struct _snd_pcm_runtime {
2772 </para> 2773 </para>
2773 2774
2774 <para> 2775 <para>
2775 Thus, you need to take care not to allocate the same buffers 2776 Thus, you need to be careful not to allocate the same buffers
2776 many times, which will lead to memory leak! Calling the 2777 many times, which will lead to memory leaks! Calling the
2777 helper function above many times is OK. It will release the 2778 helper function above many times is OK. It will release the
2778 previous buffer automatically when it was already allocated. 2779 previous buffer automatically when it was already allocated.
2779 </para> 2780 </para>
@@ -2782,7 +2783,7 @@ struct _snd_pcm_runtime {
2782 Another note is that this callback is non-atomic 2783 Another note is that this callback is non-atomic
2783 (schedulable). This is important, because the 2784 (schedulable). This is important, because the
2784 <structfield>trigger</structfield> callback 2785 <structfield>trigger</structfield> callback
2785 is atomic (non-schedulable). That is, mutex or any 2786 is atomic (non-schedulable). That is, mutexes or any
2786 schedule-related functions are not available in 2787 schedule-related functions are not available in
2787 <structfield>trigger</structfield> callback. 2788 <structfield>trigger</structfield> callback.
2788 Please see the subsection 2789 Please see the subsection
@@ -2843,15 +2844,15 @@ struct _snd_pcm_runtime {
2843 <quote>prepared</quote>. You can set the format type, sample 2844 <quote>prepared</quote>. You can set the format type, sample
2844 rate, etc. here. The difference from 2845 rate, etc. here. The difference from
2845 <structfield>hw_params</structfield> is that the 2846 <structfield>hw_params</structfield> is that the
2846 <structfield>prepare</structfield> callback will be called at each 2847 <structfield>prepare</structfield> callback will be called each
2847 time 2848 time
2848 <function>snd_pcm_prepare()</function> is called, i.e. when 2849 <function>snd_pcm_prepare()</function> is called, i.e. when
2849 recovered after underruns, etc. 2850 recovering after underruns, etc.
2850 </para> 2851 </para>
2851 2852
2852 <para> 2853 <para>
2853 Note that this callback became non-atomic since the recent version. 2854 Note that this callback is now non-atomic.
2854 You can use schedule-related functions safely in this callback now. 2855 You can use schedule-related functions safely in this callback.
2855 </para> 2856 </para>
2856 2857
2857 <para> 2858 <para>
@@ -2871,7 +2872,7 @@ struct _snd_pcm_runtime {
2871 2872
2872 <para> 2873 <para>
2873 Be careful that this callback will be called many times at 2874 Be careful that this callback will be called many times at
2874 each set up, too. 2875 each setup, too.
2875 </para> 2876 </para>
2876 </section> 2877 </section>
2877 2878
@@ -2893,7 +2894,7 @@ struct _snd_pcm_runtime {
2893 Which action is specified in the second argument, 2894 Which action is specified in the second argument,
2894 <constant>SNDRV_PCM_TRIGGER_XXX</constant> in 2895 <constant>SNDRV_PCM_TRIGGER_XXX</constant> in
2895 <filename>&lt;sound/pcm.h&gt;</filename>. At least, 2896 <filename>&lt;sound/pcm.h&gt;</filename>. At least,
2896 <constant>START</constant> and <constant>STOP</constant> 2897 the <constant>START</constant> and <constant>STOP</constant>
2897 commands must be defined in this callback. 2898 commands must be defined in this callback.
2898 2899
2899 <informalexample> 2900 <informalexample>
@@ -2915,8 +2916,8 @@ struct _snd_pcm_runtime {
2915 </para> 2916 </para>
2916 2917
2917 <para> 2918 <para>
2918 When the pcm supports the pause operation (given in info 2919 When the pcm supports the pause operation (given in the info
2919 field of the hardware table), <constant>PAUSE_PUSE</constant> 2920 field of the hardware table), the <constant>PAUSE_PUSE</constant>
2920 and <constant>PAUSE_RELEASE</constant> commands must be 2921 and <constant>PAUSE_RELEASE</constant> commands must be
2921 handled here, too. The former is the command to pause the pcm, 2922 handled here, too. The former is the command to pause the pcm,
2922 and the latter to restart the pcm again. 2923 and the latter to restart the pcm again.
@@ -2925,21 +2926,21 @@ struct _snd_pcm_runtime {
2925 <para> 2926 <para>
2926 When the pcm supports the suspend/resume operation, 2927 When the pcm supports the suspend/resume operation,
2927 regardless of full or partial suspend/resume support, 2928 regardless of full or partial suspend/resume support,
2928 <constant>SUSPEND</constant> and <constant>RESUME</constant> 2929 the <constant>SUSPEND</constant> and <constant>RESUME</constant>
2929 commands must be handled, too. 2930 commands must be handled, too.
2930 These commands are issued when the power-management status is 2931 These commands are issued when the power-management status is
2931 changed. Obviously, the <constant>SUSPEND</constant> and 2932 changed. Obviously, the <constant>SUSPEND</constant> and
2932 <constant>RESUME</constant> 2933 <constant>RESUME</constant> commands
2933 do suspend and resume of the pcm substream, and usually, they 2934 suspend and resume the pcm substream, and usually, they
2934 are identical with <constant>STOP</constant> and 2935 are identical to the <constant>STOP</constant> and
2935 <constant>START</constant> commands, respectively. 2936 <constant>START</constant> commands, respectively.
2936 See <link linkend="power-management"><citetitle> 2937 See the <link linkend="power-management"><citetitle>
2937 Power Management</citetitle></link> section for details. 2938 Power Management</citetitle></link> section for details.
2938 </para> 2939 </para>
2939 2940
2940 <para> 2941 <para>
2941 As mentioned, this callback is atomic. You cannot call 2942 As mentioned, this callback is atomic. You cannot call
2942 the function going to sleep. 2943 functions which may sleep.
2943 The trigger callback should be as minimal as possible, 2944 The trigger callback should be as minimal as possible,
2944 just really triggering the DMA. The other stuff should be 2945 just really triggering the DMA. The other stuff should be
2945 initialized hw_params and prepare callbacks properly 2946 initialized hw_params and prepare callbacks properly
@@ -2960,8 +2961,8 @@ struct _snd_pcm_runtime {
2960 2961
2961 This callback is called when the PCM middle layer inquires 2962 This callback is called when the PCM middle layer inquires
2962 the current hardware position on the buffer. The position must 2963 the current hardware position on the buffer. The position must
2963 be returned in frames (which was in bytes on ALSA 0.5.x), 2964 be returned in frames,
2964 ranged from 0 to buffer_size - 1. 2965 ranging from 0 to buffer_size - 1.
2965 </para> 2966 </para>
2966 2967
2967 <para> 2968 <para>
@@ -2983,7 +2984,7 @@ struct _snd_pcm_runtime {
2983 <para> 2984 <para>
2984 These callbacks are not mandatory, and can be omitted in 2985 These callbacks are not mandatory, and can be omitted in
2985 most cases. These callbacks are used when the hardware buffer 2986 most cases. These callbacks are used when the hardware buffer
2986 cannot be on the normal memory space. Some chips have their 2987 cannot be in the normal memory space. Some chips have their
2987 own buffer on the hardware which is not mappable. In such a 2988 own buffer on the hardware which is not mappable. In such a
2988 case, you have to transfer the data manually from the memory 2989 case, you have to transfer the data manually from the memory
2989 buffer to the hardware buffer. Or, if the buffer is 2990 buffer to the hardware buffer. Or, if the buffer is
@@ -3018,8 +3019,8 @@ struct _snd_pcm_runtime {
3018 <title>page callback</title> 3019 <title>page callback</title>
3019 3020
3020 <para> 3021 <para>
3021 This callback is also not mandatory. This callback is used 3022 This callback is optional too. This callback is used
3022 mainly for the non-contiguous buffer. The mmap calls this 3023 mainly for non-contiguous buffers. The mmap calls this
3023 callback to get the page address. Some examples will be 3024 callback to get the page address. Some examples will be
3024 explained in the later section <link 3025 explained in the later section <link
3025 linkend="buffer-and-memory"><citetitle>Buffer and Memory 3026 linkend="buffer-and-memory"><citetitle>Buffer and Memory
@@ -3035,7 +3036,7 @@ struct _snd_pcm_runtime {
3035 role of PCM interrupt handler in the sound driver is to update 3036 role of PCM interrupt handler in the sound driver is to update
3036 the buffer position and to tell the PCM middle layer when the 3037 the buffer position and to tell the PCM middle layer when the
3037 buffer position goes across the prescribed period size. To 3038 buffer position goes across the prescribed period size. To
3038 inform this, call <function>snd_pcm_period_elapsed()</function> 3039 inform this, call the <function>snd_pcm_period_elapsed()</function>
3039 function. 3040 function.
3040 </para> 3041 </para>
3041 3042
@@ -3072,7 +3073,7 @@ struct _snd_pcm_runtime {
3072 </para> 3073 </para>
3073 3074
3074 <para> 3075 <para>
3075 A typical coding would be like: 3076 Typical code would be like:
3076 3077
3077 <example> 3078 <example>
3078 <title>Interrupt Handler Case #1</title> 3079 <title>Interrupt Handler Case #1</title>
@@ -3101,21 +3102,21 @@ struct _snd_pcm_runtime {
3101 </section> 3102 </section>
3102 3103
3103 <section id="pcm-interface-interrupt-handler-timer"> 3104 <section id="pcm-interface-interrupt-handler-timer">
3104 <title>High-frequent timer interrupts</title> 3105 <title>High frequency timer interrupts</title>
3105 <para> 3106 <para>
3106 This is the case when the hardware doesn't generate interrupts 3107 This happense when the hardware doesn't generate interrupts
3107 at the period boundary but do timer-interrupts at the fixed 3108 at the period boundary but issues timer interrupts at a fixed
3108 timer rate (e.g. es1968 or ymfpci drivers). 3109 timer rate (e.g. es1968 or ymfpci drivers).
3109 In this case, you need to check the current hardware 3110 In this case, you need to check the current hardware
3110 position and accumulates the processed sample length at each 3111 position and accumulate the processed sample length at each
3111 interrupt. When the accumulated size overcomes the period 3112 interrupt. When the accumulated size exceeds the period
3112 size, call 3113 size, call
3113 <function>snd_pcm_period_elapsed()</function> and reset the 3114 <function>snd_pcm_period_elapsed()</function> and reset the
3114 accumulator. 3115 accumulator.
3115 </para> 3116 </para>
3116 3117
3117 <para> 3118 <para>
3118 A typical coding would be like the following. 3119 Typical code would be like the following.
3119 3120
3120 <example> 3121 <example>
3121 <title>Interrupt Handler Case #2</title> 3122 <title>Interrupt Handler Case #2</title>
@@ -3178,32 +3179,33 @@ struct _snd_pcm_runtime {
3178 <section id="pcm-interface-atomicity"> 3179 <section id="pcm-interface-atomicity">
3179 <title>Atomicity</title> 3180 <title>Atomicity</title>
3180 <para> 3181 <para>
3181 One of the most important (and thus difficult to debug) problem 3182 One of the most important (and thus difficult to debug) problems
3182 on the kernel programming is the race condition. 3183 in kernel programming are race conditions.
3183 On linux kernel, usually it's solved via spin-locks or 3184 In the Linux kernel, they are usually avoided via spin-locks, mutexes
3184 semaphores. In general, if the race condition may 3185 or semaphores. In general, if a race condition can happen
3185 happen in the interrupt handler, it's handled as atomic, and you 3186 in an interrupt handler, it has to be managed atomically, and you
3186 have to use spinlock for protecting the critical session. If it 3187 have to use a spinlock to protect the critical session. If the
3187 never happens in the interrupt and it may take relatively long 3188 critical section is not in interrupt handler code and
3188 time, you should use semaphore. 3189 if taking a relatively long time to execute is acceptable, you
3190 should use mutexes or semaphores instead.
3189 </para> 3191 </para>
3190 3192
3191 <para> 3193 <para>
3192 As already seen, some pcm callbacks are atomic and some are 3194 As already seen, some pcm callbacks are atomic and some are
3193 not. For example, <parameter>hw_params</parameter> callback is 3195 not. For example, the <parameter>hw_params</parameter> callback is
3194 non-atomic, while <parameter>trigger</parameter> callback is 3196 non-atomic, while <parameter>trigger</parameter> callback is
3195 atomic. This means, the latter is called already in a spinlock 3197 atomic. This means, the latter is called already in a spinlock
3196 held by the PCM middle layer. Please take this atomicity into 3198 held by the PCM middle layer. Please take this atomicity into
3197 account when you use a spinlock or a semaphore in the callbacks. 3199 account when you choose a locking scheme in the callbacks.
3198 </para> 3200 </para>
3199 3201
3200 <para> 3202 <para>
3201 In the atomic callbacks, you cannot use functions which may call 3203 In the atomic callbacks, you cannot use functions which may call
3202 <function>schedule</function> or go to 3204 <function>schedule</function> or go to
3203 <function>sleep</function>. The semaphore and mutex do sleep, 3205 <function>sleep</function>. Semaphores and mutexes can sleep,
3204 and hence they cannot be used inside the atomic callbacks 3206 and hence they cannot be used inside the atomic callbacks
3205 (e.g. <parameter>trigger</parameter> callback). 3207 (e.g. <parameter>trigger</parameter> callback).
3206 For taking a certain delay in such a callback, please use 3208 To implement some delay in such a callback, please use
3207 <function>udelay()</function> or <function>mdelay()</function>. 3209 <function>udelay()</function> or <function>mdelay()</function>.
3208 </para> 3210 </para>
3209 3211
@@ -3257,7 +3259,7 @@ struct _snd_pcm_runtime {
3257 3259
3258 <para> 3260 <para>
3259 There are many different constraints. 3261 There are many different constraints.
3260 Look in <filename>sound/pcm.h</filename> for a complete list. 3262 Look at <filename>sound/pcm.h</filename> for a complete list.
3261 You can even define your own constraint rules. 3263 You can even define your own constraint rules.
3262 For example, let's suppose my_chip can manage a substream of 1 channel 3264 For example, let's suppose my_chip can manage a substream of 1 channel
3263 if and only if the format is S16_LE, otherwise it supports any format 3265 if and only if the format is S16_LE, otherwise it supports any format
@@ -3346,7 +3348,7 @@ struct _snd_pcm_runtime {
3346 </para> 3348 </para>
3347 3349
3348 <para> 3350 <para>
3349 I won't explain more details here, rather I 3351 I won't give more details here, rather I
3350 would like to say, <quote>Luke, use the source.</quote> 3352 would like to say, <quote>Luke, use the source.</quote>
3351 </para> 3353 </para>
3352 </section> 3354 </section>
@@ -3364,10 +3366,9 @@ struct _snd_pcm_runtime {
3364 <title>General</title> 3366 <title>General</title>
3365 <para> 3367 <para>
3366 The control interface is used widely for many switches, 3368 The control interface is used widely for many switches,
3367 sliders, etc. which are accessed from the user-space. Its most 3369 sliders, etc. which are accessed from user-space. Its most
3368 important use is the mixer interface. In other words, on ALSA 3370 important use is the mixer interface. In other words, since ALSA
3369 0.9.x, all the mixer stuff is implemented on the control kernel 3371 0.9.x, all the mixer stuff is implemented on the control kernel API.
3370 API (while there was an independent mixer kernel API on 0.5.x).
3371 </para> 3372 </para>
3372 3373
3373 <para> 3374 <para>
@@ -3379,14 +3380,15 @@ struct _snd_pcm_runtime {
3379 <para> 3380 <para>
3380 The control API is defined in 3381 The control API is defined in
3381 <filename>&lt;sound/control.h&gt;</filename>. 3382 <filename>&lt;sound/control.h&gt;</filename>.
3382 Include this file if you add your own controls. 3383 Include this file if you want to add your own controls.
3383 </para> 3384 </para>
3384 </section> 3385 </section>
3385 3386
3386 <section id="control-interface-definition"> 3387 <section id="control-interface-definition">
3387 <title>Definition of Controls</title> 3388 <title>Definition of Controls</title>
3388 <para> 3389 <para>
3389 For creating a new control, you need to define the three 3390 To create a new control, you need to define the
3391 following three
3390 callbacks: <structfield>info</structfield>, 3392 callbacks: <structfield>info</structfield>,
3391 <structfield>get</structfield> and 3393 <structfield>get</structfield> and
3392 <structfield>put</structfield>. Then, define a 3394 <structfield>put</structfield>. Then, define a
@@ -3414,13 +3416,13 @@ struct _snd_pcm_runtime {
3414 <para> 3416 <para>
3415 Most likely the control is created via 3417 Most likely the control is created via
3416 <function>snd_ctl_new1()</function>, and in such a case, you can 3418 <function>snd_ctl_new1()</function>, and in such a case, you can
3417 add <parameter>__devinitdata</parameter> prefix to the 3419 add the <parameter>__devinitdata</parameter> prefix to the
3418 definition like above. 3420 definition as above.
3419 </para> 3421 </para>
3420 3422
3421 <para> 3423 <para>
3422 The <structfield>iface</structfield> field specifies the type of 3424 The <structfield>iface</structfield> field specifies the control
3423 the control, <constant>SNDRV_CTL_ELEM_IFACE_XXX</constant>, which 3425 type, <constant>SNDRV_CTL_ELEM_IFACE_XXX</constant>, which
3424 is usually <constant>MIXER</constant>. 3426 is usually <constant>MIXER</constant>.
3425 Use <constant>CARD</constant> for global controls that are not 3427 Use <constant>CARD</constant> for global controls that are not
3426 logically part of the mixer. 3428 logically part of the mixer.
@@ -3435,12 +3437,11 @@ struct _snd_pcm_runtime {
3435 3437
3436 <para> 3438 <para>
3437 The <structfield>name</structfield> is the name identifier 3439 The <structfield>name</structfield> is the name identifier
3438 string. On ALSA 0.9.x, the control name is very important, 3440 string. Since ALSA 0.9.x, the control name is very important,
3439 because its role is classified from its name. There are 3441 because its role is classified from its name. There are
3440 pre-defined standard control names. The details are described in 3442 pre-defined standard control names. The details are described in
3441 the subsection 3443 the <link linkend="control-interface-control-names"><citetitle>
3442 <link linkend="control-interface-control-names"><citetitle> 3444 Control Names</citetitle></link> subsection.
3443 Control Names</citetitle></link>.
3444 </para> 3445 </para>
3445 3446
3446 <para> 3447 <para>
@@ -3456,15 +3457,15 @@ struct _snd_pcm_runtime {
3456 The <structfield>access</structfield> field contains the access 3457 The <structfield>access</structfield> field contains the access
3457 type of this control. Give the combination of bit masks, 3458 type of this control. Give the combination of bit masks,
3458 <constant>SNDRV_CTL_ELEM_ACCESS_XXX</constant>, there. 3459 <constant>SNDRV_CTL_ELEM_ACCESS_XXX</constant>, there.
3459 The detailed will be explained in the subsection 3460 The details will be explained in
3460 <link linkend="control-interface-access-flags"><citetitle> 3461 the <link linkend="control-interface-access-flags"><citetitle>
3461 Access Flags</citetitle></link>. 3462 Access Flags</citetitle></link> subsection.
3462 </para> 3463 </para>
3463 3464
3464 <para> 3465 <para>
3465 The <structfield>private_value</structfield> field contains 3466 The <structfield>private_value</structfield> field contains
3466 an arbitrary long integer value for this record. When using 3467 an arbitrary long integer value for this record. When using
3467 generic <structfield>info</structfield>, 3468 the generic <structfield>info</structfield>,
3468 <structfield>get</structfield> and 3469 <structfield>get</structfield> and
3469 <structfield>put</structfield> callbacks, you can pass a value 3470 <structfield>put</structfield> callbacks, you can pass a value
3470 through this field. If several small numbers are necessary, you can 3471 through this field. If several small numbers are necessary, you can
@@ -3489,7 +3490,7 @@ struct _snd_pcm_runtime {
3489 <section id="control-interface-control-names"> 3490 <section id="control-interface-control-names">
3490 <title>Control Names</title> 3491 <title>Control Names</title>
3491 <para> 3492 <para>
3492 There are some standards for defining the control names. A 3493 There are some standards to define the control names. A
3493 control is usually defined from the three parts as 3494 control is usually defined from the three parts as
3494 <quote>SOURCE DIRECTION FUNCTION</quote>. 3495 <quote>SOURCE DIRECTION FUNCTION</quote>.
3495 </para> 3496 </para>
@@ -3497,7 +3498,7 @@ struct _snd_pcm_runtime {
3497 <para> 3498 <para>
3498 The first, <constant>SOURCE</constant>, specifies the source 3499 The first, <constant>SOURCE</constant>, specifies the source
3499 of the control, and is a string such as <quote>Master</quote>, 3500 of the control, and is a string such as <quote>Master</quote>,
3500 <quote>PCM</quote>, <quote>CD</quote> or 3501 <quote>PCM</quote>, <quote>CD</quote> and
3501 <quote>Line</quote>. There are many pre-defined sources. 3502 <quote>Line</quote>. There are many pre-defined sources.
3502 </para> 3503 </para>
3503 3504
@@ -3575,22 +3576,22 @@ struct _snd_pcm_runtime {
3575 <title>Access Flags</title> 3576 <title>Access Flags</title>
3576 3577
3577 <para> 3578 <para>
3578 The access flag is the bit-flags which specifies the access type 3579 The access flag is the bitmask which specifies the access type
3579 of the given control. The default access type is 3580 of the given control. The default access type is
3580 <constant>SNDRV_CTL_ELEM_ACCESS_READWRITE</constant>, 3581 <constant>SNDRV_CTL_ELEM_ACCESS_READWRITE</constant>,
3581 which means both read and write are allowed to this control. 3582 which means both read and write are allowed to this control.
3582 When the access flag is omitted (i.e. = 0), it is 3583 When the access flag is omitted (i.e. = 0), it is
3583 regarded as <constant>READWRITE</constant> access as default. 3584 considered as <constant>READWRITE</constant> access as default.
3584 </para> 3585 </para>
3585 3586
3586 <para> 3587 <para>
3587 When the control is read-only, pass 3588 When the control is read-only, pass
3588 <constant>SNDRV_CTL_ELEM_ACCESS_READ</constant> instead. 3589 <constant>SNDRV_CTL_ELEM_ACCESS_READ</constant> instead.
3589 In this case, you don't have to define 3590 In this case, you don't have to define
3590 <structfield>put</structfield> callback. 3591 the <structfield>put</structfield> callback.
3591 Similarly, when the control is write-only (although it's a rare 3592 Similarly, when the control is write-only (although it's a rare
3592 case), you can use <constant>WRITE</constant> flag instead, and 3593 case), you can use the <constant>WRITE</constant> flag instead, and
3593 you don't need <structfield>get</structfield> callback. 3594 you don't need the <structfield>get</structfield> callback.
3594 </para> 3595 </para>
3595 3596
3596 <para> 3597 <para>
@@ -3598,15 +3599,15 @@ struct _snd_pcm_runtime {
3598 <constant>VOLATILE</constant> flag should be given. This means 3599 <constant>VOLATILE</constant> flag should be given. This means
3599 that the control may be changed without 3600 that the control may be changed without
3600 <link linkend="control-interface-change-notification"><citetitle> 3601 <link linkend="control-interface-change-notification"><citetitle>
3601 notification</citetitle></link>. Applications should poll such 3602 notification</citetitle></link>. Applications should poll such
3602 a control constantly. 3603 a control constantly.
3603 </para> 3604 </para>
3604 3605
3605 <para> 3606 <para>
3606 When the control is inactive, set 3607 When the control is inactive, set
3607 <constant>INACTIVE</constant> flag, too. 3608 the <constant>INACTIVE</constant> flag, too.
3608 There are <constant>LOCK</constant> and 3609 There are <constant>LOCK</constant> and
3609 <constant>OWNER</constant> flags for changing the write 3610 <constant>OWNER</constant> flags to change the write
3610 permissions. 3611 permissions.
3611 </para> 3612 </para>
3612 3613
@@ -3619,10 +3620,10 @@ struct _snd_pcm_runtime {
3619 <title>info callback</title> 3620 <title>info callback</title>
3620 <para> 3621 <para>
3621 The <structfield>info</structfield> callback is used to get 3622 The <structfield>info</structfield> callback is used to get
3622 the detailed information of this control. This must store the 3623 detailed information on this control. This must store the
3623 values of the given struct <structname>snd_ctl_elem_info</structname> 3624 values of the given struct <structname>snd_ctl_elem_info</structname>
3624 object. For example, for a boolean control with a single 3625 object. For example, for a boolean control with a single
3625 element will be: 3626 element:
3626 3627
3627 <example> 3628 <example>
3628 <title>Example of info callback</title> 3629 <title>Example of info callback</title>
@@ -3653,7 +3654,7 @@ struct _snd_pcm_runtime {
3653 volume would have count = 2. The 3654 volume would have count = 2. The
3654 <structfield>value</structfield> field is a union, and 3655 <structfield>value</structfield> field is a union, and
3655 the values stored are depending on the type. The boolean and 3656 the values stored are depending on the type. The boolean and
3656 integer are identical. 3657 integer types are identical.
3657 </para> 3658 </para>
3658 3659
3659 <para> 3660 <para>
@@ -3684,7 +3685,7 @@ struct _snd_pcm_runtime {
3684 </para> 3685 </para>
3685 3686
3686 <para> 3687 <para>
3687 Some common info callbacks are prepared for easy use: 3688 Some common info callbacks are available for your convenience:
3688 <function>snd_ctl_boolean_mono_info()</function> and 3689 <function>snd_ctl_boolean_mono_info()</function> and
3689 <function>snd_ctl_boolean_stereo_info()</function>. 3690 <function>snd_ctl_boolean_stereo_info()</function>.
3690 Obviously, the former is an info callback for a mono channel 3691 Obviously, the former is an info callback for a mono channel
@@ -3699,7 +3700,7 @@ struct _snd_pcm_runtime {
3699 3700
3700 <para> 3701 <para>
3701 This callback is used to read the current value of the 3702 This callback is used to read the current value of the
3702 control and to return to the user-space. 3703 control and to return to user-space.
3703 </para> 3704 </para>
3704 3705
3705 <para> 3706 <para>
@@ -3722,11 +3723,11 @@ struct _snd_pcm_runtime {
3722 </para> 3723 </para>
3723 3724
3724 <para> 3725 <para>
3725 The <structfield>value</structfield> field is depending on 3726 The <structfield>value</structfield> field depends on
3726 the type of control as well as on info callback. For example, 3727 the type of control as well as on the info callback. For example,
3727 the sb driver uses this field to store the register offset, 3728 the sb driver uses this field to store the register offset,
3728 the bit-shift and the bit-mask. The 3729 the bit-shift and the bit-mask. The
3729 <structfield>private_value</structfield> is set like 3730 <structfield>private_value</structfield> field is set as follows:
3730 <informalexample> 3731 <informalexample>
3731 <programlisting> 3732 <programlisting>
3732<![CDATA[ 3733<![CDATA[
@@ -3752,7 +3753,8 @@ struct _snd_pcm_runtime {
3752 </para> 3753 </para>
3753 3754
3754 <para> 3755 <para>
3755 In <structfield>get</structfield> callback, you have to fill all the elements if the 3756 In the <structfield>get</structfield> callback,
3757 you have to fill all the elements if the
3756 control has more than one elements, 3758 control has more than one elements,
3757 i.e. <structfield>count</structfield> &gt; 1. 3759 i.e. <structfield>count</structfield> &gt; 1.
3758 In the example above, we filled only one element 3760 In the example above, we filled only one element
@@ -3765,7 +3767,7 @@ struct _snd_pcm_runtime {
3765 <title>put callback</title> 3767 <title>put callback</title>
3766 3768
3767 <para> 3769 <para>
3768 This callback is used to write a value from the user-space. 3770 This callback is used to write a value from user-space.
3769 </para> 3771 </para>
3770 3772
3771 <para> 3773 <para>
@@ -3799,7 +3801,7 @@ struct _snd_pcm_runtime {
3799 </para> 3801 </para>
3800 3802
3801 <para> 3803 <para>
3802 Like <structfield>get</structfield> callback, 3804 As in the <structfield>get</structfield> callback,
3803 when the control has more than one elements, 3805 when the control has more than one elements,
3804 all elements must be evaluated in this callback, too. 3806 all elements must be evaluated in this callback, too.
3805 </para> 3807 </para>
@@ -3817,7 +3819,7 @@ struct _snd_pcm_runtime {
3817 <title>Constructor</title> 3819 <title>Constructor</title>
3818 <para> 3820 <para>
3819 When everything is ready, finally we can create a new 3821 When everything is ready, finally we can create a new
3820 control. For creating a control, there are two functions to be 3822 control. To create a control, there are two functions to be
3821 called, <function>snd_ctl_new1()</function> and 3823 called, <function>snd_ctl_new1()</function> and
3822 <function>snd_ctl_add()</function>. 3824 <function>snd_ctl_add()</function>.
3823 </para> 3825 </para>
@@ -3839,14 +3841,14 @@ struct _snd_pcm_runtime {
3839 struct <structname>snd_kcontrol_new</structname> object defined above, and chip 3841 struct <structname>snd_kcontrol_new</structname> object defined above, and chip
3840 is the object pointer to be passed to 3842 is the object pointer to be passed to
3841 kcontrol-&gt;private_data 3843 kcontrol-&gt;private_data
3842 which can be referred in callbacks. 3844 which can be referred to in callbacks.
3843 </para> 3845 </para>
3844 3846
3845 <para> 3847 <para>
3846 <function>snd_ctl_new1()</function> allocates a new 3848 <function>snd_ctl_new1()</function> allocates a new
3847 <structname>snd_kcontrol</structname> instance (that's why the definition 3849 <structname>snd_kcontrol</structname> instance (that's why the definition
3848 of <parameter>my_control</parameter> can be with 3850 of <parameter>my_control</parameter> can be with
3849 <parameter>__devinitdata</parameter> 3851 the <parameter>__devinitdata</parameter>
3850 prefix), and <function>snd_ctl_add</function> assigns the given 3852 prefix), and <function>snd_ctl_add</function> assigns the given
3851 control component to the card. 3853 control component to the card.
3852 </para> 3854 </para>
@@ -3941,7 +3943,7 @@ struct _snd_pcm_runtime {
3941 <title>General</title> 3943 <title>General</title>
3942 <para> 3944 <para>
3943 The ALSA AC97 codec layer is a well-defined one, and you don't 3945 The ALSA AC97 codec layer is a well-defined one, and you don't
3944 have to write many codes to control it. Only low-level control 3946 have to write much code to control it. Only low-level control
3945 routines are necessary. The AC97 codec API is defined in 3947 routines are necessary. The AC97 codec API is defined in
3946 <filename>&lt;sound/ac97_codec.h&gt;</filename>. 3948 <filename>&lt;sound/ac97_codec.h&gt;</filename>.
3947 </para> 3949 </para>
@@ -4004,7 +4006,7 @@ struct _snd_pcm_runtime {
4004 <section id="api-ac97-constructor"> 4006 <section id="api-ac97-constructor">
4005 <title>Constructor</title> 4007 <title>Constructor</title>
4006 <para> 4008 <para>
4007 For creating an ac97 instance, first call <function>snd_ac97_bus</function> 4009 To create an ac97 instance, first call <function>snd_ac97_bus</function>
4008 with an <type>ac97_bus_ops_t</type> record with callback functions. 4010 with an <type>ac97_bus_ops_t</type> record with callback functions.
4009 4011
4010 <informalexample> 4012 <informalexample>
@@ -4042,12 +4044,12 @@ struct _snd_pcm_runtime {
4042 </programlisting> 4044 </programlisting>
4043 </informalexample> 4045 </informalexample>
4044 4046
4045 where chip-&gt;ac97 is the pointer of a newly created 4047 where chip-&gt;ac97 is a pointer to a newly created
4046 <type>ac97_t</type> instance. 4048 <type>ac97_t</type> instance.
4047 In this case, the chip pointer is set as the private data, so that 4049 In this case, the chip pointer is set as the private data, so that
4048 the read/write callback functions can refer to this chip instance. 4050 the read/write callback functions can refer to this chip instance.
4049 This instance is not necessarily stored in the chip 4051 This instance is not necessarily stored in the chip
4050 record. When you need to change the register values from the 4052 record. If you need to change the register values from the
4051 driver, or need the suspend/resume of ac97 codecs, keep this 4053 driver, or need the suspend/resume of ac97 codecs, keep this
4052 pointer to pass to the corresponding functions. 4054 pointer to pass to the corresponding functions.
4053 </para> 4055 </para>
@@ -4098,7 +4100,7 @@ struct _snd_pcm_runtime {
4098 </para> 4100 </para>
4099 4101
4100 <para> 4102 <para>
4101 These callbacks are non-atomic like the callbacks of control API. 4103 These callbacks are non-atomic like the control API callbacks.
4102 </para> 4104 </para>
4103 4105
4104 <para> 4106 <para>
@@ -4110,14 +4112,14 @@ struct _snd_pcm_runtime {
4110 4112
4111 <para> 4113 <para>
4112 The <structfield>reset</structfield> callback is used to reset 4114 The <structfield>reset</structfield> callback is used to reset
4113 the codec. If the chip requires a special way of reset, you can 4115 the codec. If the chip requires a special kind of reset, you can
4114 define this callback. 4116 define this callback.
4115 </para> 4117 </para>
4116 4118
4117 <para> 4119 <para>
4118 The <structfield>wait</structfield> callback is used for a 4120 The <structfield>wait</structfield> callback is used to
4119 certain wait at the standard initialization of the codec. If the 4121 add some waiting time in the standard initialization of the codec. If the
4120 chip requires the extra wait-time, define this callback. 4122 chip requires the extra waiting time, define this callback.
4121 </para> 4123 </para>
4122 4124
4123 <para> 4125 <para>
@@ -4172,7 +4174,7 @@ struct _snd_pcm_runtime {
4172 4174
4173 <para> 4175 <para>
4174 <function>snd_ac97_update_bits()</function> is used to update 4176 <function>snd_ac97_update_bits()</function> is used to update
4175 some bits of the given register. 4177 some bits in the given register.
4176 4178
4177 <informalexample> 4179 <informalexample>
4178 <programlisting> 4180 <programlisting>
@@ -4185,7 +4187,7 @@ struct _snd_pcm_runtime {
4185 4187
4186 <para> 4188 <para>
4187 Also, there is a function to change the sample rate (of a 4189 Also, there is a function to change the sample rate (of a
4188 certain register such as 4190 given register such as
4189 <constant>AC97_PCM_FRONT_DAC_RATE</constant>) when VRA or 4191 <constant>AC97_PCM_FRONT_DAC_RATE</constant>) when VRA or
4190 DRA is supported by the codec: 4192 DRA is supported by the codec:
4191 <function>snd_ac97_set_rate()</function>. 4193 <function>snd_ac97_set_rate()</function>.
@@ -4200,11 +4202,11 @@ struct _snd_pcm_runtime {
4200 </para> 4202 </para>
4201 4203
4202 <para> 4204 <para>
4203 The following registers are available for setting the rate: 4205 The following registers are available to set the rate:
4204 <constant>AC97_PCM_MIC_ADC_RATE</constant>, 4206 <constant>AC97_PCM_MIC_ADC_RATE</constant>,
4205 <constant>AC97_PCM_FRONT_DAC_RATE</constant>, 4207 <constant>AC97_PCM_FRONT_DAC_RATE</constant>,
4206 <constant>AC97_PCM_LR_ADC_RATE</constant>, 4208 <constant>AC97_PCM_LR_ADC_RATE</constant>,
4207 <constant>AC97_SPDIF</constant>. When the 4209 <constant>AC97_SPDIF</constant>. When
4208 <constant>AC97_SPDIF</constant> is specified, the register is 4210 <constant>AC97_SPDIF</constant> is specified, the register is
4209 not really changed but the corresponding IEC958 status bits will 4211 not really changed but the corresponding IEC958 status bits will
4210 be updated. 4212 be updated.
@@ -4214,12 +4216,11 @@ struct _snd_pcm_runtime {
4214 <section id="api-ac97-clock-adjustment"> 4216 <section id="api-ac97-clock-adjustment">
4215 <title>Clock Adjustment</title> 4217 <title>Clock Adjustment</title>
4216 <para> 4218 <para>
4217 On some chip, the clock of the codec isn't 48000 but using a 4219 In some chips, the clock of the codec isn't 48000 but using a
4218 PCI clock (to save a quartz!). In this case, change the field 4220 PCI clock (to save a quartz!). In this case, change the field
4219 bus-&gt;clock to the corresponding 4221 bus-&gt;clock to the corresponding
4220 value. For example, intel8x0 4222 value. For example, intel8x0
4221 and es1968 drivers have the auto-measurement function of the 4223 and es1968 drivers have their own function to read from the clock.
4222 clock.
4223 </para> 4224 </para>
4224 </section> 4225 </section>
4225 4226
@@ -4239,15 +4240,13 @@ struct _snd_pcm_runtime {
4239 When there are several codecs on the same card, you need to 4240 When there are several codecs on the same card, you need to
4240 call <function>snd_ac97_mixer()</function> multiple times with 4241 call <function>snd_ac97_mixer()</function> multiple times with
4241 ac97.num=1 or greater. The <structfield>num</structfield> field 4242 ac97.num=1 or greater. The <structfield>num</structfield> field
4242 specifies the codec 4243 specifies the codec number.
4243 number.
4244 </para> 4244 </para>
4245 4245
4246 <para> 4246 <para>
4247 If you have set up multiple codecs, you need to either write 4247 If you set up multiple codecs, you either need to write
4248 different callbacks for each codec or check 4248 different callbacks for each codec or check
4249 ac97-&gt;num in the 4249 ac97-&gt;num in the callback routines.
4250 callback routines.
4251 </para> 4250 </para>
4252 </section> 4251 </section>
4253 4252
@@ -4271,7 +4270,7 @@ struct _snd_pcm_runtime {
4271 </para> 4270 </para>
4272 4271
4273 <para> 4272 <para>
4274 Some soundchips have similar but a little bit different 4273 Some soundchips have a similar but slightly different
4275 implementation of mpu401 stuff. For example, emu10k1 has its own 4274 implementation of mpu401 stuff. For example, emu10k1 has its own
4276 mpu401 routines. 4275 mpu401 routines.
4277 </para> 4276 </para>
@@ -4280,7 +4279,7 @@ struct _snd_pcm_runtime {
4280 <section id="midi-interface-constructor"> 4279 <section id="midi-interface-constructor">
4281 <title>Constructor</title> 4280 <title>Constructor</title>
4282 <para> 4281 <para>
4283 For creating a rawmidi object, call 4282 To create a rawmidi object, call
4284 <function>snd_mpu401_uart_new()</function>. 4283 <function>snd_mpu401_uart_new()</function>.
4285 4284
4286 <informalexample> 4285 <informalexample>
@@ -4307,25 +4306,24 @@ struct _snd_pcm_runtime {
4307 </para> 4306 </para>
4308 4307
4309 <para> 4308 <para>
4310 The 4th argument is the i/o port address. Many 4309 The 4th argument is the I/O port address. Many
4311 backward-compatible MPU401 has an i/o port such as 0x330. Or, it 4310 backward-compatible MPU401 have an I/O port such as 0x330. Or, it
4312 might be a part of its own PCI i/o region. It depends on the 4311 might be a part of its own PCI I/O region. It depends on the
4313 chip design. 4312 chip design.
4314 </para> 4313 </para>
4315 4314
4316 <para> 4315 <para>
4317 The 5th argument is bitflags for additional information. 4316 The 5th argument is a bitflag for additional information.
4318 When the i/o port address above is a part of the PCI i/o 4317 When the I/O port address above is part of the PCI I/O
4319 region, the MPU401 i/o port might have been already allocated 4318 region, the MPU401 I/O port might have been already allocated
4320 (reserved) by the driver itself. In such a case, pass a bit flag 4319 (reserved) by the driver itself. In such a case, pass a bit flag
4321 <constant>MPU401_INFO_INTEGRATED</constant>, 4320 <constant>MPU401_INFO_INTEGRATED</constant>,
4322 and 4321 and the mpu401-uart layer will allocate the I/O ports by itself.
4323 the mpu401-uart layer will allocate the i/o ports by itself.
4324 </para> 4322 </para>
4325 4323
4326 <para> 4324 <para>
4327 When the controller supports only the input or output MIDI stream, 4325 When the controller supports only the input or output MIDI stream,
4328 pass <constant>MPU401_INFO_INPUT</constant> or 4326 pass the <constant>MPU401_INFO_INPUT</constant> or
4329 <constant>MPU401_INFO_OUTPUT</constant> bitflag, respectively. 4327 <constant>MPU401_INFO_OUTPUT</constant> bitflag, respectively.
4330 Then the rawmidi instance is created as a single stream. 4328 Then the rawmidi instance is created as a single stream.
4331 </para> 4329 </para>
@@ -4333,7 +4331,7 @@ struct _snd_pcm_runtime {
4333 <para> 4331 <para>
4334 <constant>MPU401_INFO_MMIO</constant> bitflag is used to change 4332 <constant>MPU401_INFO_MMIO</constant> bitflag is used to change
4335 the access method to MMIO (via readb and writeb) instead of 4333 the access method to MMIO (via readb and writeb) instead of
4336 iob and outb. In this case, you have to pass the iomapped address 4334 iob and outb. In this case, you have to pass the iomapped address
4337 to <function>snd_mpu401_uart_new()</function>. 4335 to <function>snd_mpu401_uart_new()</function>.
4338 </para> 4336 </para>
4339 4337
@@ -4341,7 +4339,7 @@ struct _snd_pcm_runtime {
4341 When <constant>MPU401_INFO_TX_IRQ</constant> is set, the output 4339 When <constant>MPU401_INFO_TX_IRQ</constant> is set, the output
4342 stream isn't checked in the default interrupt handler. The driver 4340 stream isn't checked in the default interrupt handler. The driver
4343 needs to call <function>snd_mpu401_uart_interrupt_tx()</function> 4341 needs to call <function>snd_mpu401_uart_interrupt_tx()</function>
4344 by itself to start processing the output stream in irq handler. 4342 by itself to start processing the output stream in the irq handler.
4345 </para> 4343 </para>
4346 4344
4347 <para> 4345 <para>
@@ -4381,7 +4379,7 @@ struct _snd_pcm_runtime {
4381 (<parameter>irq_flags</parameter>). Otherwise, pass the flags 4379 (<parameter>irq_flags</parameter>). Otherwise, pass the flags
4382 for irq allocation 4380 for irq allocation
4383 (<constant>SA_XXX</constant> bits) to it, and the irq will be 4381 (<constant>SA_XXX</constant> bits) to it, and the irq will be
4384 reserved by the mpu401-uart layer. If the card doesn't generates 4382 reserved by the mpu401-uart layer. If the card doesn't generate
4385 UART interrupts, pass -1 as the irq number. Then a timer 4383 UART interrupts, pass -1 as the irq number. Then a timer
4386 interrupt will be invoked for polling. 4384 interrupt will be invoked for polling.
4387 </para> 4385 </para>
@@ -4392,8 +4390,8 @@ struct _snd_pcm_runtime {
4392 <para> 4390 <para>
4393 When the interrupt is allocated in 4391 When the interrupt is allocated in
4394 <function>snd_mpu401_uart_new()</function>, the private 4392 <function>snd_mpu401_uart_new()</function>, the private
4395 interrupt handler is used, hence you don't have to do nothing 4393 interrupt handler is used, hence you don't have anything else to do
4396 else than creating the mpu401 stuff. Otherwise, you have to call 4394 than creating the mpu401 stuff. Otherwise, you have to call
4397 <function>snd_mpu401_uart_interrupt()</function> explicitly when 4395 <function>snd_mpu401_uart_interrupt()</function> explicitly when
4398 a UART interrupt is invoked and checked in your own interrupt 4396 a UART interrupt is invoked and checked in your own interrupt
4399 handler. 4397 handler.
@@ -4480,8 +4478,8 @@ struct _snd_pcm_runtime {
4480 4478
4481 <para> 4479 <para>
4482 The fourth and fifth arguments are the number of output and 4480 The fourth and fifth arguments are the number of output and
4483 input substreams, respectively, of this device. (A substream is 4481 input substreams, respectively, of this device (a substream is
4484 the equivalent of a MIDI port.) 4482 the equivalent of a MIDI port).
4485 </para> 4483 </para>
4486 4484
4487 <para> 4485 <para>
@@ -4498,7 +4496,7 @@ struct _snd_pcm_runtime {
4498 <para> 4496 <para>
4499 After the rawmidi device is created, you need to set the 4497 After the rawmidi device is created, you need to set the
4500 operators (callbacks) for each substream. There are helper 4498 operators (callbacks) for each substream. There are helper
4501 functions to set the operators for all substream of a device: 4499 functions to set the operators for all the substreams of a device:
4502 <informalexample> 4500 <informalexample>
4503 <programlisting> 4501 <programlisting>
4504<![CDATA[ 4502<![CDATA[
@@ -4528,8 +4526,8 @@ struct _snd_pcm_runtime {
4528 </para> 4526 </para>
4529 4527
4530 <para> 4528 <para>
4531 If there is more than one substream, you should give each one a 4529 If there are more than one substream, you should give a
4532 unique name: 4530 unique name to each of them:
4533 <informalexample> 4531 <informalexample>
4534 <programlisting> 4532 <programlisting>
4535<![CDATA[ 4533<![CDATA[
@@ -4550,7 +4548,7 @@ struct _snd_pcm_runtime {
4550 <title>Callbacks</title> 4548 <title>Callbacks</title>
4551 4549
4552 <para> 4550 <para>
4553 In all callbacks, the private data that you've set for the 4551 In all the callbacks, the private data that you've set for the
4554 rawmidi device can be accessed as 4552 rawmidi device can be accessed as
4555 substream-&gt;rmidi-&gt;private_data. 4553 substream-&gt;rmidi-&gt;private_data.
4556 <!-- <code> isn't available before DocBook 4.3 --> 4554 <!-- <code> isn't available before DocBook 4.3 -->
@@ -4583,8 +4581,8 @@ struct _snd_pcm_runtime {
4583 4581
4584 <para> 4582 <para>
4585 This is called when a substream is opened. 4583 This is called when a substream is opened.
4586 You can initialize the hardware here, but you should not yet 4584 You can initialize the hardware here, but you shouldn't
4587 start transmitting/receiving data. 4585 start transmitting/receiving data yet.
4588 </para> 4586 </para>
4589 </section> 4587 </section>
4590 4588
@@ -4632,9 +4630,9 @@ struct _snd_pcm_runtime {
4632 To read data from the buffer, call 4630 To read data from the buffer, call
4633 <function>snd_rawmidi_transmit_peek</function>. It will 4631 <function>snd_rawmidi_transmit_peek</function>. It will
4634 return the number of bytes that have been read; this will be 4632 return the number of bytes that have been read; this will be
4635 less than the number of bytes requested when there is no more 4633 less than the number of bytes requested when there are no more
4636 data in the buffer. 4634 data in the buffer.
4637 After the data has been transmitted successfully, call 4635 After the data have been transmitted successfully, call
4638 <function>snd_rawmidi_transmit_ack</function> to remove the 4636 <function>snd_rawmidi_transmit_ack</function> to remove the
4639 data from the substream buffer: 4637 data from the substream buffer:
4640 <informalexample> 4638 <informalexample>
@@ -4655,7 +4653,7 @@ struct _snd_pcm_runtime {
4655 <para> 4653 <para>
4656 If you know beforehand that the hardware will accept data, you 4654 If you know beforehand that the hardware will accept data, you
4657 can use the <function>snd_rawmidi_transmit</function> function 4655 can use the <function>snd_rawmidi_transmit</function> function
4658 which reads some data and removes it from the buffer at once: 4656 which reads some data and removes them from the buffer at once:
4659 <informalexample> 4657 <informalexample>
4660 <programlisting> 4658 <programlisting>
4661<![CDATA[ 4659<![CDATA[
@@ -4749,13 +4747,13 @@ struct _snd_pcm_runtime {
4749 4747
4750 <para> 4748 <para>
4751 This is only used with output substreams. This function should wait 4749 This is only used with output substreams. This function should wait
4752 until all data read from the substream buffer has been transmitted. 4750 until all data read from the substream buffer have been transmitted.
4753 This ensures that the device can be closed and the driver unloaded 4751 This ensures that the device can be closed and the driver unloaded
4754 without losing data. 4752 without losing data.
4755 </para> 4753 </para>
4756 4754
4757 <para> 4755 <para>
4758 This callback is optional. If you do not set 4756 This callback is optional. If you do not set
4759 <structfield>drain</structfield> in the struct snd_rawmidi_ops 4757 <structfield>drain</structfield> in the struct snd_rawmidi_ops
4760 structure, ALSA will simply wait for 50&nbsp;milliseconds 4758 structure, ALSA will simply wait for 50&nbsp;milliseconds
4761 instead. 4759 instead.
@@ -4775,24 +4773,24 @@ struct _snd_pcm_runtime {
4775 <section id="misc-devices-opl3"> 4773 <section id="misc-devices-opl3">
4776 <title>FM OPL3</title> 4774 <title>FM OPL3</title>
4777 <para> 4775 <para>
4778 The FM OPL3 is still used on many chips (mainly for backward 4776 The FM OPL3 is still used in many chips (mainly for backward
4779 compatibility). ALSA has a nice OPL3 FM control layer, too. The 4777 compatibility). ALSA has a nice OPL3 FM control layer, too. The
4780 OPL3 API is defined in 4778 OPL3 API is defined in
4781 <filename>&lt;sound/opl3.h&gt;</filename>. 4779 <filename>&lt;sound/opl3.h&gt;</filename>.
4782 </para> 4780 </para>
4783 4781
4784 <para> 4782 <para>
4785 FM registers can be directly accessed through direct-FM API, 4783 FM registers can be directly accessed through the direct-FM API,
4786 defined in <filename>&lt;sound/asound_fm.h&gt;</filename>. In 4784 defined in <filename>&lt;sound/asound_fm.h&gt;</filename>. In
4787 ALSA native mode, FM registers are accessed through 4785 ALSA native mode, FM registers are accessed through
4788 Hardware-Dependant Device direct-FM extension API, whereas in 4786 the Hardware-Dependant Device direct-FM extension API, whereas in
4789 OSS compatible mode, FM registers can be accessed with OSS 4787 OSS compatible mode, FM registers can be accessed with the OSS
4790 direct-FM compatible API on <filename>/dev/dmfmX</filename> device. 4788 direct-FM compatible API in <filename>/dev/dmfmX</filename> device.
4791 </para> 4789 </para>
4792 4790
4793 <para> 4791 <para>
4794 For creating the OPL3 component, you have two functions to 4792 To create the OPL3 component, you have two functions to
4795 call. The first one is a constructor for <type>opl3_t</type> 4793 call. The first one is a constructor for the <type>opl3_t</type>
4796 instance. 4794 instance.
4797 4795
4798 <informalexample> 4796 <informalexample>
@@ -4819,12 +4817,12 @@ struct _snd_pcm_runtime {
4819 <para> 4817 <para>
4820 When the left and right ports have been already allocated by 4818 When the left and right ports have been already allocated by
4821 the card driver, pass non-zero to the fifth argument 4819 the card driver, pass non-zero to the fifth argument
4822 (<parameter>integrated</parameter>). Otherwise, opl3 module will 4820 (<parameter>integrated</parameter>). Otherwise, the opl3 module will
4823 allocate the specified ports by itself. 4821 allocate the specified ports by itself.
4824 </para> 4822 </para>
4825 4823
4826 <para> 4824 <para>
4827 When the accessing to the hardware requires special method 4825 When the accessing the hardware requires special method
4828 instead of the standard I/O access, you can create opl3 instance 4826 instead of the standard I/O access, you can create opl3 instance
4829 separately with <function>snd_opl3_new()</function>. 4827 separately with <function>snd_opl3_new()</function>.
4830 4828
@@ -4845,13 +4843,13 @@ struct _snd_pcm_runtime {
4845 access function, the private data and the destructor. 4843 access function, the private data and the destructor.
4846 The l_port and r_port are not necessarily set. Only the 4844 The l_port and r_port are not necessarily set. Only the
4847 command must be set properly. You can retrieve the data 4845 command must be set properly. You can retrieve the data
4848 from opl3-&gt;private_data field. 4846 from the opl3-&gt;private_data field.
4849 </para> 4847 </para>
4850 4848
4851 <para> 4849 <para>
4852 After creating the opl3 instance via <function>snd_opl3_new()</function>, 4850 After creating the opl3 instance via <function>snd_opl3_new()</function>,
4853 call <function>snd_opl3_init()</function> to initialize the chip to the 4851 call <function>snd_opl3_init()</function> to initialize the chip to the
4854 proper state. Note that <function>snd_opl3_create()</function> always 4852 proper state. Note that <function>snd_opl3_create()</function> always
4855 calls it internally. 4853 calls it internally.
4856 </para> 4854 </para>
4857 4855
@@ -4884,7 +4882,7 @@ struct _snd_pcm_runtime {
4884 <section id="misc-devices-hardware-dependent"> 4882 <section id="misc-devices-hardware-dependent">
4885 <title>Hardware-Dependent Devices</title> 4883 <title>Hardware-Dependent Devices</title>
4886 <para> 4884 <para>
4887 Some chips need the access from the user-space for special 4885 Some chips need user-space access for special
4888 controls or for loading the micro code. In such a case, you can 4886 controls or for loading the micro code. In such a case, you can
4889 create a hwdep (hardware-dependent) device. The hwdep API is 4887 create a hwdep (hardware-dependent) device. The hwdep API is
4890 defined in <filename>&lt;sound/hwdep.h&gt;</filename>. You can 4888 defined in <filename>&lt;sound/hwdep.h&gt;</filename>. You can
@@ -4893,7 +4891,7 @@ struct _snd_pcm_runtime {
4893 </para> 4891 </para>
4894 4892
4895 <para> 4893 <para>
4896 Creation of the <type>hwdep</type> instance is done via 4894 The creation of the <type>hwdep</type> instance is done via
4897 <function>snd_hwdep_new()</function>. 4895 <function>snd_hwdep_new()</function>.
4898 4896
4899 <informalexample> 4897 <informalexample>
@@ -4912,8 +4910,8 @@ struct _snd_pcm_runtime {
4912 You can then pass any pointer value to the 4910 You can then pass any pointer value to the
4913 <parameter>private_data</parameter>. 4911 <parameter>private_data</parameter>.
4914 If you assign a private data, you should define the 4912 If you assign a private data, you should define the
4915 destructor, too. The destructor function is set to 4913 destructor, too. The destructor function is set in
4916 <structfield>private_free</structfield> field. 4914 the <structfield>private_free</structfield> field.
4917 4915
4918 <informalexample> 4916 <informalexample>
4919 <programlisting> 4917 <programlisting>
@@ -4925,7 +4923,7 @@ struct _snd_pcm_runtime {
4925 </programlisting> 4923 </programlisting>
4926 </informalexample> 4924 </informalexample>
4927 4925
4928 and the implementation of destructor would be: 4926 and the implementation of the destructor would be:
4929 4927
4930 <informalexample> 4928 <informalexample>
4931 <programlisting> 4929 <programlisting>
@@ -4943,7 +4941,7 @@ struct _snd_pcm_runtime {
4943 <para> 4941 <para>
4944 The arbitrary file operations can be defined for this 4942 The arbitrary file operations can be defined for this
4945 instance. The file operators are defined in 4943 instance. The file operators are defined in
4946 <parameter>ops</parameter> table. For example, assume that 4944 the <parameter>ops</parameter> table. For example, assume that
4947 this chip needs an ioctl. 4945 this chip needs an ioctl.
4948 4946
4949 <informalexample> 4947 <informalexample>
@@ -4964,7 +4962,7 @@ struct _snd_pcm_runtime {
4964 <title>IEC958 (S/PDIF)</title> 4962 <title>IEC958 (S/PDIF)</title>
4965 <para> 4963 <para>
4966 Usually the controls for IEC958 devices are implemented via 4964 Usually the controls for IEC958 devices are implemented via
4967 control interface. There is a macro to compose a name string for 4965 the control interface. There is a macro to compose a name string for
4968 IEC958 controls, <function>SNDRV_CTL_NAME_IEC958()</function> 4966 IEC958 controls, <function>SNDRV_CTL_NAME_IEC958()</function>
4969 defined in <filename>&lt;include/asound.h&gt;</filename>. 4967 defined in <filename>&lt;include/asound.h&gt;</filename>.
4970 </para> 4968 </para>
@@ -4973,7 +4971,7 @@ struct _snd_pcm_runtime {
4973 There are some standard controls for IEC958 status bits. These 4971 There are some standard controls for IEC958 status bits. These
4974 controls use the type <type>SNDRV_CTL_ELEM_TYPE_IEC958</type>, 4972 controls use the type <type>SNDRV_CTL_ELEM_TYPE_IEC958</type>,
4975 and the size of element is fixed as 4 bytes array 4973 and the size of element is fixed as 4 bytes array
4976 (value.iec958.status[x]). For <structfield>info</structfield> 4974 (value.iec958.status[x]). For the <structfield>info</structfield>
4977 callback, you don't specify 4975 callback, you don't specify
4978 the value field for this type (the count field must be set, 4976 the value field for this type (the count field must be set,
4979 though). 4977 though).
@@ -5001,7 +4999,7 @@ struct _snd_pcm_runtime {
5001 enable/disable or to set the raw bit mode. The implementation 4999 enable/disable or to set the raw bit mode. The implementation
5002 will depend on the chip, but the control should be named as 5000 will depend on the chip, but the control should be named as
5003 <quote>IEC958 xxx</quote>, preferably using 5001 <quote>IEC958 xxx</quote>, preferably using
5004 <function>SNDRV_CTL_NAME_IEC958()</function> macro. 5002 the <function>SNDRV_CTL_NAME_IEC958()</function> macro.
5005 </para> 5003 </para>
5006 5004
5007 <para> 5005 <para>
@@ -5036,12 +5034,12 @@ struct _snd_pcm_runtime {
5036 The allocation of pages with fallback is 5034 The allocation of pages with fallback is
5037 <function>snd_malloc_xxx_pages_fallback()</function>. This 5035 <function>snd_malloc_xxx_pages_fallback()</function>. This
5038 function tries to allocate the specified pages but if the pages 5036 function tries to allocate the specified pages but if the pages
5039 are not available, it tries to reduce the page sizes until the 5037 are not available, it tries to reduce the page sizes until
5040 enough space is found. 5038 enough space is found.
5041 </para> 5039 </para>
5042 5040
5043 <para> 5041 <para>
5044 For releasing the space, call 5042 The release the pages, call
5045 <function>snd_free_xxx_pages()</function> function. 5043 <function>snd_free_xxx_pages()</function> function.
5046 </para> 5044 </para>
5047 5045
@@ -5050,8 +5048,8 @@ struct _snd_pcm_runtime {
5050 a large contiguous physical space 5048 a large contiguous physical space
5051 at the time the module is loaded for the later use. 5049 at the time the module is loaded for the later use.
5052 This is called <quote>pre-allocation</quote>. 5050 This is called <quote>pre-allocation</quote>.
5053 As already written, you can call the following function at the 5051 As already written, you can call the following function at
5054 construction of pcm instance (in the case of PCI bus). 5052 pcm instance construction time (in the case of PCI bus).
5055 5053
5056 <informalexample> 5054 <informalexample>
5057 <programlisting> 5055 <programlisting>
@@ -5063,34 +5061,34 @@ struct _snd_pcm_runtime {
5063 </informalexample> 5061 </informalexample>
5064 5062
5065 where <parameter>size</parameter> is the byte size to be 5063 where <parameter>size</parameter> is the byte size to be
5066 pre-allocated and the <parameter>max</parameter> is the maximal 5064 pre-allocated and the <parameter>max</parameter> is the maximum
5067 size to be changed via <filename>prealloc</filename> proc file. 5065 size to be changed via the <filename>prealloc</filename> proc file.
5068 The allocator will try to get as large area as possible 5066 The allocator will try to get an area as large as possible
5069 within the given size. 5067 within the given size.
5070 </para> 5068 </para>
5071 5069
5072 <para> 5070 <para>
5073 The second argument (type) and the third argument (device pointer) 5071 The second argument (type) and the third argument (device pointer)
5074 are dependent on the bus. 5072 are dependent on the bus.
5075 In the case of ISA bus, pass <function>snd_dma_isa_data()</function> 5073 In the case of the ISA bus, pass <function>snd_dma_isa_data()</function>
5076 as the third argument with <constant>SNDRV_DMA_TYPE_DEV</constant> type. 5074 as the third argument with <constant>SNDRV_DMA_TYPE_DEV</constant> type.
5077 For the continuous buffer unrelated to the bus can be pre-allocated 5075 For the continuous buffer unrelated to the bus can be pre-allocated
5078 with <constant>SNDRV_DMA_TYPE_CONTINUOUS</constant> type and the 5076 with <constant>SNDRV_DMA_TYPE_CONTINUOUS</constant> type and the
5079 <function>snd_dma_continuous_data(GFP_KERNEL)</function> device pointer, 5077 <function>snd_dma_continuous_data(GFP_KERNEL)</function> device pointer,
5080 whereh <constant>GFP_KERNEL</constant> is the kernel allocation flag to 5078 where <constant>GFP_KERNEL</constant> is the kernel allocation flag to
5081 use. For the SBUS, <constant>SNDRV_DMA_TYPE_SBUS</constant> and 5079 use. For the SBUS, <constant>SNDRV_DMA_TYPE_SBUS</constant> and
5082 <function>snd_dma_sbus_data(sbus_dev)</function> are used instead. 5080 <function>snd_dma_sbus_data(sbus_dev)</function> are used instead.
5083 For the PCI scatter-gather buffers, use 5081 For the PCI scatter-gather buffers, use
5084 <constant>SNDRV_DMA_TYPE_DEV_SG</constant> with 5082 <constant>SNDRV_DMA_TYPE_DEV_SG</constant> with
5085 <function>snd_dma_pci_data(pci)</function> 5083 <function>snd_dma_pci_data(pci)</function>
5086 (see the section 5084 (see the
5087 <link linkend="buffer-and-memory-non-contiguous"><citetitle>Non-Contiguous Buffers 5085 <link linkend="buffer-and-memory-non-contiguous"><citetitle>Non-Contiguous Buffers
5088 </citetitle></link>). 5086 </citetitle></link> section).
5089 </para> 5087 </para>
5090 5088
5091 <para> 5089 <para>
5092 Once when the buffer is pre-allocated, you can use the 5090 Once the buffer is pre-allocated, you can use the
5093 allocator in the <structfield>hw_params</structfield> callback 5091 allocator in the <structfield>hw_params</structfield> callback:
5094 5092
5095 <informalexample> 5093 <informalexample>
5096 <programlisting> 5094 <programlisting>
@@ -5116,8 +5114,8 @@ struct _snd_pcm_runtime {
5116 </para> 5114 </para>
5117 5115
5118 <para> 5116 <para>
5119 The first case works fine if the external hardware buffer is enough 5117 The first case works fine if the external hardware buffer is large
5120 large. This method doesn't need any extra buffers and thus is 5118 enough. This method doesn't need any extra buffers and thus is
5121 more effective. You need to define the 5119 more effective. You need to define the
5122 <structfield>copy</structfield> and 5120 <structfield>copy</structfield> and
5123 <structfield>silence</structfield> callbacks for 5121 <structfield>silence</structfield> callbacks for
@@ -5127,25 +5125,25 @@ struct _snd_pcm_runtime {
5127 </para> 5125 </para>
5128 5126
5129 <para> 5127 <para>
5130 The second case allows the mmap of the buffer, although you have 5128 The second case allows for mmap on the buffer, although you have
5131 to handle an interrupt or a tasklet for transferring the data 5129 to handle an interrupt or a tasklet to transfer the data
5132 from the intermediate buffer to the hardware buffer. You can find an 5130 from the intermediate buffer to the hardware buffer. You can find an
5133 example in vxpocket driver. 5131 example in the vxpocket driver.
5134 </para> 5132 </para>
5135 5133
5136 <para> 5134 <para>
5137 Another case is that the chip uses a PCI memory-map 5135 Another case is when the chip uses a PCI memory-map
5138 region for the buffer instead of the host memory. In this case, 5136 region for the buffer instead of the host memory. In this case,
5139 mmap is available only on certain architectures like intel. In 5137 mmap is available only on certain architectures like the Intel one.
5140 non-mmap mode, the data cannot be transferred as the normal 5138 In non-mmap mode, the data cannot be transferred as in the normal
5141 way. Thus you need to define <structfield>copy</structfield> and 5139 way. Thus you need to define the <structfield>copy</structfield> and
5142 <structfield>silence</structfield> callbacks as well 5140 <structfield>silence</structfield> callbacks as well,
5143 as in the cases above. The examples are found in 5141 as in the cases above. The examples are found in
5144 <filename>rme32.c</filename> and <filename>rme96.c</filename>. 5142 <filename>rme32.c</filename> and <filename>rme96.c</filename>.
5145 </para> 5143 </para>
5146 5144
5147 <para> 5145 <para>
5148 The implementation of <structfield>copy</structfield> and 5146 The implementation of the <structfield>copy</structfield> and
5149 <structfield>silence</structfield> callbacks depends upon 5147 <structfield>silence</structfield> callbacks depends upon
5150 whether the hardware supports interleaved or non-interleaved 5148 whether the hardware supports interleaved or non-interleaved
5151 samples. The <structfield>copy</structfield> callback is 5149 samples. The <structfield>copy</structfield> callback is
@@ -5184,8 +5182,8 @@ struct _snd_pcm_runtime {
5184 5182
5185 <para> 5183 <para>
5186 What you have to do in this callback is again different 5184 What you have to do in this callback is again different
5187 between playback and capture directions. In the case of 5185 between playback and capture directions. In the
5188 playback, you do: copy the given amount of data 5186 playback case, you copy the given amount of data
5189 (<parameter>count</parameter>) at the specified pointer 5187 (<parameter>count</parameter>) at the specified pointer
5190 (<parameter>src</parameter>) to the specified offset 5188 (<parameter>src</parameter>) to the specified offset
5191 (<parameter>pos</parameter>) on the hardware buffer. When 5189 (<parameter>pos</parameter>) on the hardware buffer. When
@@ -5202,7 +5200,7 @@ struct _snd_pcm_runtime {
5202 </para> 5200 </para>
5203 5201
5204 <para> 5202 <para>
5205 For the capture direction, you do: copy the given amount of 5203 For the capture direction, you copy the given amount of
5206 data (<parameter>count</parameter>) at the specified offset 5204 data (<parameter>count</parameter>) at the specified offset
5207 (<parameter>pos</parameter>) on the hardware buffer to the 5205 (<parameter>pos</parameter>) on the hardware buffer to the
5208 specified pointer (<parameter>dst</parameter>). 5206 specified pointer (<parameter>dst</parameter>).
@@ -5216,7 +5214,7 @@ struct _snd_pcm_runtime {
5216 </programlisting> 5214 </programlisting>
5217 </informalexample> 5215 </informalexample>
5218 5216
5219 Note that both of the position and the data amount are given 5217 Note that both the position and the amount of data are given
5220 in frames. 5218 in frames.
5221 </para> 5219 </para>
5222 5220
@@ -5247,7 +5245,7 @@ struct _snd_pcm_runtime {
5247 </para> 5245 </para>
5248 5246
5249 <para> 5247 <para>
5250 The meanings of arguments are identical with the 5248 The meanings of arguments are the same as in the
5251 <structfield>copy</structfield> 5249 <structfield>copy</structfield>
5252 callback, although there is no <parameter>src/dst</parameter> 5250 callback, although there is no <parameter>src/dst</parameter>
5253 argument. In the case of interleaved samples, the channel 5251 argument. In the case of interleaved samples, the channel
@@ -5284,8 +5282,8 @@ struct _snd_pcm_runtime {
5284 <section id="buffer-and-memory-non-contiguous"> 5282 <section id="buffer-and-memory-non-contiguous">
5285 <title>Non-Contiguous Buffers</title> 5283 <title>Non-Contiguous Buffers</title>
5286 <para> 5284 <para>
5287 If your hardware supports the page table like emu10k1 or the 5285 If your hardware supports the page table as in emu10k1 or the
5288 buffer descriptors like via82xx, you can use the scatter-gather 5286 buffer descriptors as in via82xx, you can use the scatter-gather
5289 (SG) DMA. ALSA provides an interface for handling SG-buffers. 5287 (SG) DMA. ALSA provides an interface for handling SG-buffers.
5290 The API is provided in <filename>&lt;sound/pcm.h&gt;</filename>. 5288 The API is provided in <filename>&lt;sound/pcm.h&gt;</filename>.
5291 </para> 5289 </para>
@@ -5296,7 +5294,7 @@ struct _snd_pcm_runtime {
5296 <function>snd_pcm_lib_preallocate_pages_for_all()</function> 5294 <function>snd_pcm_lib_preallocate_pages_for_all()</function>
5297 with <constant>SNDRV_DMA_TYPE_DEV_SG</constant> 5295 with <constant>SNDRV_DMA_TYPE_DEV_SG</constant>
5298 in the PCM constructor like other PCI pre-allocator. 5296 in the PCM constructor like other PCI pre-allocator.
5299 You need to pass the <function>snd_dma_pci_data(pci)</function>, 5297 You need to pass <function>snd_dma_pci_data(pci)</function>,
5300 where pci is the struct <structname>pci_dev</structname> pointer 5298 where pci is the struct <structname>pci_dev</structname> pointer
5301 of the chip as well. 5299 of the chip as well.
5302 The <type>struct snd_sg_buf</type> instance is created as 5300 The <type>struct snd_sg_buf</type> instance is created as
@@ -5314,7 +5312,7 @@ struct _snd_pcm_runtime {
5314 5312
5315 <para> 5313 <para>
5316 Then call <function>snd_pcm_lib_malloc_pages()</function> 5314 Then call <function>snd_pcm_lib_malloc_pages()</function>
5317 in <structfield>hw_params</structfield> callback 5315 in the <structfield>hw_params</structfield> callback
5318 as well as in the case of normal PCI buffer. 5316 as well as in the case of normal PCI buffer.
5319 The SG-buffer handler will allocate the non-contiguous kernel 5317 The SG-buffer handler will allocate the non-contiguous kernel
5320 pages of the given size and map them onto the virtually contiguous 5318 pages of the given size and map them onto the virtually contiguous
@@ -5335,7 +5333,7 @@ struct _snd_pcm_runtime {
5335 </para> 5333 </para>
5336 5334
5337 <para> 5335 <para>
5338 For releasing the data, call 5336 To release the data, call
5339 <function>snd_pcm_lib_free_pages()</function> in the 5337 <function>snd_pcm_lib_free_pages()</function> in the
5340 <structfield>hw_free</structfield> callback as usual. 5338 <structfield>hw_free</structfield> callback as usual.
5341 </para> 5339 </para>
@@ -5390,7 +5388,7 @@ struct _snd_pcm_runtime {
5390 </para> 5388 </para>
5391 5389
5392 <para> 5390 <para>
5393 For creating a proc file, call 5391 To create a proc file, call
5394 <function>snd_card_proc_new()</function>. 5392 <function>snd_card_proc_new()</function>.
5395 5393
5396 <informalexample> 5394 <informalexample>
@@ -5402,7 +5400,7 @@ struct _snd_pcm_runtime {
5402 </programlisting> 5400 </programlisting>
5403 </informalexample> 5401 </informalexample>
5404 5402
5405 where the second argument specifies the proc-file name to be 5403 where the second argument specifies the name of the proc file to be
5406 created. The above example will create a file 5404 created. The above example will create a file
5407 <filename>my-file</filename> under the card directory, 5405 <filename>my-file</filename> under the card directory,
5408 e.g. <filename>/proc/asound/card0/my-file</filename>. 5406 e.g. <filename>/proc/asound/card0/my-file</filename>.
@@ -5417,8 +5415,8 @@ struct _snd_pcm_runtime {
5417 5415
5418 <para> 5416 <para>
5419 When the creation is successful, the function stores a new 5417 When the creation is successful, the function stores a new
5420 instance at the pointer given in the third argument. 5418 instance in the pointer given in the third argument.
5421 It is initialized as a text proc file for read only. For using 5419 It is initialized as a text proc file for read only. To use
5422 this proc file as a read-only text file as it is, set the read 5420 this proc file as a read-only text file as it is, set the read
5423 callback with a private data via 5421 callback with a private data via
5424 <function>snd_info_set_text_ops()</function>. 5422 <function>snd_info_set_text_ops()</function>.
@@ -5470,9 +5468,9 @@ struct _snd_pcm_runtime {
5470 </para> 5468 </para>
5471 5469
5472 <para> 5470 <para>
5473 The file permission can be changed afterwards. As default, it's 5471 The file permissions can be changed afterwards. As default, it's
5474 set as read only for all users. If you want to add the write 5472 set as read only for all users. If you want to add write
5475 permission to the user (root as default), set like below: 5473 permission for the user (root as default), do as follows:
5476 5474
5477 <informalexample> 5475 <informalexample>
5478 <programlisting> 5476 <programlisting>
@@ -5503,7 +5501,7 @@ struct _snd_pcm_runtime {
5503 </para> 5501 </para>
5504 5502
5505 <para> 5503 <para>
5506 For a raw-data proc-file, set the attributes like the following: 5504 For a raw-data proc-file, set the attributes as follows:
5507 5505
5508 <informalexample> 5506 <informalexample>
5509 <programlisting> 5507 <programlisting>
@@ -5524,7 +5522,7 @@ struct _snd_pcm_runtime {
5524 5522
5525 <para> 5523 <para>
5526 The callback is much more complicated than the text-file 5524 The callback is much more complicated than the text-file
5527 version. You need to use a low-level i/o functions such as 5525 version. You need to use a low-level I/O functions such as
5528 <function>copy_from/to_user()</function> to transfer the 5526 <function>copy_from/to_user()</function> to transfer the
5529 data. 5527 data.
5530 5528
@@ -5560,28 +5558,28 @@ struct _snd_pcm_runtime {
5560 <title>Power Management</title> 5558 <title>Power Management</title>
5561 <para> 5559 <para>
5562 If the chip is supposed to work with suspend/resume 5560 If the chip is supposed to work with suspend/resume
5563 functions, you need to add the power-management codes to the 5561 functions, you need to add power-management code to the
5564 driver. The additional codes for the power-management should be 5562 driver. The additional code for power-management should be
5565 <function>ifdef</function>'ed with 5563 <function>ifdef</function>'ed with
5566 <constant>CONFIG_PM</constant>. 5564 <constant>CONFIG_PM</constant>.
5567 </para> 5565 </para>
5568 5566
5569 <para> 5567 <para>
5570 If the driver supports the suspend/resume 5568 If the driver <emphasis>fully</emphasis> supports suspend/resume
5571 <emphasis>fully</emphasis>, that is, the device can be 5569 that is, the device can be
5572 properly resumed to the status at the suspend is called, 5570 properly resumed to its state when suspend was called,
5573 you can set <constant>SNDRV_PCM_INFO_RESUME</constant> flag 5571 you can set the <constant>SNDRV_PCM_INFO_RESUME</constant> flag
5574 to pcm info field. Usually, this is possible when the 5572 in the pcm info field. Usually, this is possible when the
5575 registers of ths chip can be safely saved and restored to the 5573 registers of the chip can be safely saved and restored to
5576 RAM. If this is set, the trigger callback is called with 5574 RAM. If this is set, the trigger callback is called with
5577 <constant>SNDRV_PCM_TRIGGER_RESUME</constant> after resume 5575 <constant>SNDRV_PCM_TRIGGER_RESUME</constant> after the resume
5578 callback is finished. 5576 callback completes.
5579 </para> 5577 </para>
5580 5578
5581 <para> 5579 <para>
5582 Even if the driver doesn't support PM fully but only the 5580 Even if the driver doesn't support PM fully but
5583 partial suspend/resume is possible, it's still worthy to 5581 partial suspend/resume is still possible, it's still worthy to
5584 implement suspend/resume callbacks. In such a case, applications 5582 implement suspend/resume callbacks. In such a case, applications
5585 would reset the status by calling 5583 would reset the status by calling
5586 <function>snd_pcm_prepare()</function> and restart the stream 5584 <function>snd_pcm_prepare()</function> and restart the stream
5587 appropriately. Hence, you can define suspend/resume callbacks 5585 appropriately. Hence, you can define suspend/resume callbacks
@@ -5590,22 +5588,22 @@ struct _snd_pcm_runtime {
5590 </para> 5588 </para>
5591 5589
5592 <para> 5590 <para>
5593 Note that the trigger with SUSPEND can be always called when 5591 Note that the trigger with SUSPEND can always be called when
5594 <function>snd_pcm_suspend_all</function> is called, 5592 <function>snd_pcm_suspend_all</function> is called,
5595 regardless of <constant>SNDRV_PCM_INFO_RESUME</constant> flag. 5593 regardless of the <constant>SNDRV_PCM_INFO_RESUME</constant> flag.
5596 The <constant>RESUME</constant> flag affects only the behavior 5594 The <constant>RESUME</constant> flag affects only the behavior
5597 of <function>snd_pcm_resume()</function>. 5595 of <function>snd_pcm_resume()</function>.
5598 (Thus, in theory, 5596 (Thus, in theory,
5599 <constant>SNDRV_PCM_TRIGGER_RESUME</constant> isn't needed 5597 <constant>SNDRV_PCM_TRIGGER_RESUME</constant> isn't needed
5600 to be handled in the trigger callback when no 5598 to be handled in the trigger callback when no
5601 <constant>SNDRV_PCM_INFO_RESUME</constant> flag is set. But, 5599 <constant>SNDRV_PCM_INFO_RESUME</constant> flag is set. But,
5602 it's better to keep it for compatibility reason.) 5600 it's better to keep it for compatibility reasons.)
5603 </para> 5601 </para>
5604 <para> 5602 <para>
5605 In the earlier version of ALSA drivers, a common 5603 In the earlier version of ALSA drivers, a common
5606 power-management layer was provided, but it has been removed. 5604 power-management layer was provided, but it has been removed.
5607 The driver needs to define the suspend/resume hooks according to 5605 The driver needs to define the suspend/resume hooks according to
5608 the bus the device is assigned. In the case of PCI driver, the 5606 the bus the device is connected to. In the case of PCI drivers, the
5609 callbacks look like below: 5607 callbacks look like below:
5610 5608
5611 <informalexample> 5609 <informalexample>
@@ -5629,7 +5627,7 @@ struct _snd_pcm_runtime {
5629 </para> 5627 </para>
5630 5628
5631 <para> 5629 <para>
5632 The scheme of the real suspend job is as following. 5630 The scheme of the real suspend job is as follows.
5633 5631
5634 <orderedlist> 5632 <orderedlist>
5635 <listitem><para>Retrieve the card and the chip data.</para></listitem> 5633 <listitem><para>Retrieve the card and the chip data.</para></listitem>
@@ -5679,11 +5677,11 @@ struct _snd_pcm_runtime {
5679 </para> 5677 </para>
5680 5678
5681 <para> 5679 <para>
5682 The scheme of the real resume job is as following. 5680 The scheme of the real resume job is as follows.
5683 5681
5684 <orderedlist> 5682 <orderedlist>
5685 <listitem><para>Retrieve the card and the chip data.</para></listitem> 5683 <listitem><para>Retrieve the card and the chip data.</para></listitem>
5686 <listitem><para>Set up PCI. First, call <function>pci_restore_state()</function>. 5684 <listitem><para>Set up PCI. First, call <function>pci_restore_state()</function>.
5687 Then enable the pci device again by calling <function>pci_enable_device()</function>. 5685 Then enable the pci device again by calling <function>pci_enable_device()</function>.
5688 Call <function>pci_set_master()</function> if necessary, too.</para></listitem> 5686 Call <function>pci_set_master()</function> if necessary, too.</para></listitem>
5689 <listitem><para>Re-initialize the chip.</para></listitem> 5687 <listitem><para>Re-initialize the chip.</para></listitem>
@@ -5734,7 +5732,7 @@ struct _snd_pcm_runtime {
5734 <function>snd_pcm_suspend_all()</function> or 5732 <function>snd_pcm_suspend_all()</function> or
5735 <function>snd_pcm_suspend()</function>. It means that the PCM 5733 <function>snd_pcm_suspend()</function>. It means that the PCM
5736 streams are already stoppped when the register snapshot is 5734 streams are already stoppped when the register snapshot is
5737 taken. But, remind that you don't have to restart the PCM 5735 taken. But, remember that you don't have to restart the PCM
5738 stream in the resume callback. It'll be restarted via 5736 stream in the resume callback. It'll be restarted via
5739 trigger call with <constant>SNDRV_PCM_TRIGGER_RESUME</constant> 5737 trigger call with <constant>SNDRV_PCM_TRIGGER_RESUME</constant>
5740 when necessary. 5738 when necessary.
@@ -5795,7 +5793,7 @@ struct _snd_pcm_runtime {
5795 </para> 5793 </para>
5796 5794
5797 <para> 5795 <para>
5798 If you need a space for saving the registers, allocate the 5796 If you need a space to save the registers, allocate the
5799 buffer for it here, too, since it would be fatal 5797 buffer for it here, too, since it would be fatal
5800 if you cannot allocate a memory in the suspend phase. 5798 if you cannot allocate a memory in the suspend phase.
5801 The allocated buffer should be released in the corresponding 5799 The allocated buffer should be released in the corresponding
@@ -5833,7 +5831,7 @@ struct _snd_pcm_runtime {
5833 <title>Module Parameters</title> 5831 <title>Module Parameters</title>
5834 <para> 5832 <para>
5835 There are standard module options for ALSA. At least, each 5833 There are standard module options for ALSA. At least, each
5836 module should have <parameter>index</parameter>, 5834 module should have the <parameter>index</parameter>,
5837 <parameter>id</parameter> and <parameter>enable</parameter> 5835 <parameter>id</parameter> and <parameter>enable</parameter>
5838 options. 5836 options.
5839 </para> 5837 </para>
@@ -5841,8 +5839,8 @@ struct _snd_pcm_runtime {
5841 <para> 5839 <para>
5842 If the module supports multiple cards (usually up to 5840 If the module supports multiple cards (usually up to
5843 8 = <constant>SNDRV_CARDS</constant> cards), they should be 5841 8 = <constant>SNDRV_CARDS</constant> cards), they should be
5844 arrays. The default initial values are defined already as 5842 arrays. The default initial values are defined already as
5845 constants for ease of programming: 5843 constants for easier programming:
5846 5844
5847 <informalexample> 5845 <informalexample>
5848 <programlisting> 5846 <programlisting>
@@ -5858,7 +5856,7 @@ struct _snd_pcm_runtime {
5858 <para> 5856 <para>
5859 If the module supports only a single card, they could be single 5857 If the module supports only a single card, they could be single
5860 variables, instead. <parameter>enable</parameter> option is not 5858 variables, instead. <parameter>enable</parameter> option is not
5861 always necessary in this case, but it wouldn't be so bad to have a 5859 always necessary in this case, but it would be better to have a
5862 dummy option for compatibility. 5860 dummy option for compatibility.
5863 </para> 5861 </para>
5864 5862
@@ -5923,22 +5921,22 @@ struct _snd_pcm_runtime {
5923 </para> 5921 </para>
5924 5922
5925 <para> 5923 <para>
5926 Suppose that you'll create a new PCI driver for the card 5924 Suppose that you create a new PCI driver for the card
5927 <quote>xyz</quote>. The card module name would be 5925 <quote>xyz</quote>. The card module name would be
5928 snd-xyz. The new driver is usually put into alsa-driver 5926 snd-xyz. The new driver is usually put into the alsa-driver
5929 tree, <filename>alsa-driver/pci</filename> directory in 5927 tree, <filename>alsa-driver/pci</filename> directory in
5930 the case of PCI cards. 5928 the case of PCI cards.
5931 Then the driver is evaluated, audited and tested 5929 Then the driver is evaluated, audited and tested
5932 by developers and users. After a certain time, the driver 5930 by developers and users. After a certain time, the driver
5933 will go to alsa-kernel tree (to the corresponding directory, 5931 will go to the alsa-kernel tree (to the corresponding directory,
5934 such as <filename>alsa-kernel/pci</filename>) and eventually 5932 such as <filename>alsa-kernel/pci</filename>) and eventually
5935 integrated into Linux 2.6 tree (the directory would be 5933 will be integrated into the Linux 2.6 tree (the directory would be
5936 <filename>linux/sound/pci</filename>). 5934 <filename>linux/sound/pci</filename>).
5937 </para> 5935 </para>
5938 5936
5939 <para> 5937 <para>
5940 In the following sections, the driver code is supposed 5938 In the following sections, the driver code is supposed
5941 to be put into alsa-driver tree. The two cases are assumed: 5939 to be put into alsa-driver tree. The two cases are covered:
5942 a driver consisting of a single source file and one consisting 5940 a driver consisting of a single source file and one consisting
5943 of several source files. 5941 of several source files.
5944 </para> 5942 </para>
@@ -6033,7 +6031,7 @@ struct _snd_pcm_runtime {
6033 <listitem> 6031 <listitem>
6034 <para> 6032 <para>
6035 Add a new directory (<filename>xyz</filename>) in 6033 Add a new directory (<filename>xyz</filename>) in
6036 <filename>alsa-driver/pci/Makefile</filename> like below 6034 <filename>alsa-driver/pci/Makefile</filename> as below
6037 6035
6038 <informalexample> 6036 <informalexample>
6039 <programlisting> 6037 <programlisting>
@@ -6102,7 +6100,7 @@ struct _snd_pcm_runtime {
6102 <section id="useful-functions-snd-printk"> 6100 <section id="useful-functions-snd-printk">
6103 <title><function>snd_printk()</function> and friends</title> 6101 <title><function>snd_printk()</function> and friends</title>
6104 <para> 6102 <para>
6105 ALSA provides a verbose version of 6103 ALSA provides a verbose version of the
6106 <function>printk()</function> function. If a kernel config 6104 <function>printk()</function> function. If a kernel config
6107 <constant>CONFIG_SND_VERBOSE_PRINTK</constant> is set, this 6105 <constant>CONFIG_SND_VERBOSE_PRINTK</constant> is set, this
6108 function prints the given message together with the file name 6106 function prints the given message together with the file name
@@ -6170,7 +6168,7 @@ struct _snd_pcm_runtime {
6170 <section id="useful-functions-snd-bug"> 6168 <section id="useful-functions-snd-bug">
6171 <title><function>snd_BUG()</function></title> 6169 <title><function>snd_BUG()</function></title>
6172 <para> 6170 <para>
6173 It shows <computeroutput>BUG?</computeroutput> message and 6171 It shows the <computeroutput>BUG?</computeroutput> message and
6174 stack trace as well as <function>snd_assert</function> at the point. 6172 stack trace as well as <function>snd_assert</function> at the point.
6175 It's useful to show that a fatal error happens there. 6173 It's useful to show that a fatal error happens there.
6176 </para> 6174 </para>
@@ -6199,6 +6197,4 @@ struct _snd_pcm_runtime {
6199 in the hardware constraints section. 6197 in the hardware constraints section.
6200 </para> 6198 </para>
6201 </chapter> 6199 </chapter>
6202
6203
6204</book> 6200</book>