<?xml version="1.0" encoding="ANSI_X3.4-1968" standalone="no"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><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.75.2" /><link rel="home" href="index.html" title="Writing an ALSA Driver" /><link rel="up" href="ch03.html" title="Chapter 3. Management of Cards and Components" /><link rel="prev" href="ch03.html" title="Chapter 3. Management of Cards and Components" /><link rel="next" href="ch03s03.html" title="Chip-Specific Data" /></head><body><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="ch03.html">Prev</a> </td><th width="60%" align="center">Chapter 3. Management of Cards and Components</th><td width="20%" align="right"> <a accesskey="n" href="ch03s03.html">Next</a></td></tr></table><hr /></div><div class="section" title="Components"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="card-management-component"></a>Components</h2></div></div></div><p> After the card is created, you can attach the components (devices) to the card instance. In an ALSA driver, a component is represented as a struct <span class="structname">snd_device</span> object. A component can be a PCM instance, a control interface, a raw MIDI interface, etc. Each such instance has one component entry. </p><p> A component can be created via <code class="function">snd_device_new()</code> function. </p><div class="informalexample"><pre class="programlisting"> snd_device_new(card, SNDRV_DEV_XXX, chip, &ops); </pre></div><p> </p><p> This takes the card pointer, the device-level (<code class="constant">SNDRV_DEV_XXX</code>), the data pointer, and the callback pointers (<em class="parameter"><code>&ops</code></em>). The device-level defines the type of components and the order of registration and de-registration. For most components, the device-level is already defined. For a user-defined component, you can use <code class="constant">SNDRV_DEV_LOWLEVEL</code>. </p><p> This function itself doesn't allocate the data space. The data must be allocated manually beforehand, and its pointer is passed as the argument. This pointer is used as the (<em class="parameter"><code>chip</code></em> identifier in the above example) for the instance. </p><p> Each pre-defined ALSA component such as ac97 and pcm calls <code class="function">snd_device_new()</code> inside its constructor. The destructor for each component is defined in the callback pointers. Hence, you don't need to take care of calling a destructor for such a component. </p><p> If you wish to create your own component, you need to set the destructor function to the dev_free callback in the <em class="parameter"><code>ops</code></em>, so that it can be released automatically via <code class="function">snd_card_free()</code>. The next example will show an implementation of chip-specific data. </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch03.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch03.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch03s03.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 3. Management of Cards and Components </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chip-Specific Data</td></tr></table></div></body></html>