1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>Components</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="Writing an ALSA Driver"><link rel="up" href="card-management.html" title="Chapter&#160;3.&#160;Management of Cards and Components"><link rel="prev" href="card-management.html" title="Chapter&#160;3.&#160;Management of Cards and Components"><link rel="next" href="card-management-chip-specific.html" title="Chip-Specific Data"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Components</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="card-management.html">Prev</a>&#160;</td><th width="60%" align="center">Chapter&#160;3.&#160;Management of Cards and Components</th><td width="20%" align="right">&#160;<a accesskey="n" href="card-management-chip-specific.html">Next</a></td></tr></table><hr></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="card-management-component"></a>Components</h2></div></div></div><p>
2        After the card is created, you can attach the components
3      (devices) to the card instance. In an ALSA driver, a component is
4      represented as a struct <span class="structname">snd_device</span> object.
5      A component can be a PCM instance, a control interface, a raw
6      MIDI interface, etc.  Each such instance has one component
7      entry.
8      </p><p>
9        A component can be created via
10        <code class="function">snd_device_new()</code> function. 
11
12        </p><div class="informalexample"><pre class="programlisting">
13
14  snd_device_new(card, SNDRV_DEV_XXX, chip, &amp;ops);
15
16          </pre></div><p>
17      </p><p>
18        This takes the card pointer, the device-level
19      (<code class="constant">SNDRV_DEV_XXX</code>), the data pointer, and the
20      callback pointers (<em class="parameter"><code>&amp;ops</code></em>). The
21      device-level defines the type of components and the order of
22      registration and de-registration.  For most components, the
23      device-level is already defined.  For a user-defined component,
24      you can use <code class="constant">SNDRV_DEV_LOWLEVEL</code>.
25      </p><p>
26      This function itself doesn't allocate the data space. The data
27      must be allocated manually beforehand, and its pointer is passed
28      as the argument. This pointer (<em class="parameter"><code>chip</code></em> in the
29      above example) is used as the identifier for the instance.
30      </p><p>
31        Each pre-defined ALSA component such as ac97 and pcm calls
32      <code class="function">snd_device_new()</code> inside its
33      constructor. The destructor for each component is defined in the
34      callback pointers.  Hence, you don't need to take care of
35      calling a destructor for such a component.
36      </p><p>
37        If you wish to create your own component, you need to
38      set the destructor function to the dev_free callback in
39      the <em class="parameter"><code>ops</code></em>, so that it can be released
40      automatically via <code class="function">snd_card_free()</code>.
41      The next example will show an implementation of chip-specific
42      data.
43      </p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="card-management.html">Prev</a>&#160;</td><td width="20%" align="center"><a accesskey="u" href="card-management.html">Up</a></td><td width="40%" align="right">&#160;<a accesskey="n" href="card-management-chip-specific.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter&#160;3.&#160;Management of Cards and Components&#160;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&#160;Chip-Specific Data</td></tr></table></div></body></html>
44