1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>Hardware-Dependent Devices</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="misc-devices.html" title="Chapter&#160;10.&#160;Miscellaneous Devices"><link rel="prev" href="misc-devices.html" title="Chapter&#160;10.&#160;Miscellaneous Devices"><link rel="next" href="misc-devices-IEC958.html" title="IEC958 (S/PDIF)"></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">Hardware-Dependent Devices</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="misc-devices.html">Prev</a>&#160;</td><th width="60%" align="center">Chapter&#160;10.&#160;Miscellaneous Devices</th><td width="20%" align="right">&#160;<a accesskey="n" href="misc-devices-IEC958.html">Next</a></td></tr></table><hr></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="misc-devices-hardware-dependent"></a>Hardware-Dependent Devices</h2></div></div></div><p>
2        Some chips need user-space access for special
3      controls or for loading the micro code. In such a case, you can
4      create a hwdep (hardware-dependent) device. The hwdep API is
5      defined in <code class="filename">&lt;sound/hwdep.h&gt;</code>. You can
6      find examples in opl3 driver or
7      <code class="filename">isa/sb/sb16_csp.c</code>. 
8      </p><p>
9        The creation of the <span class="type">hwdep</span> instance is done via
10        <code class="function">snd_hwdep_new()</code>. 
11
12        </p><div class="informalexample"><pre class="programlisting">
13
14  struct snd_hwdep *hw;
15  snd_hwdep_new(card, "My HWDEP", 0, &amp;hw);
16
17          </pre></div><p>
18
19        where the third argument is the index number.
20      </p><p>
21        You can then pass any pointer value to the
22        <em class="parameter"><code>private_data</code></em>.
23        If you assign a private data, you should define the
24        destructor, too. The destructor function is set in
25        the <em class="structfield"><code>private_free</code></em> field.  
26
27        </p><div class="informalexample"><pre class="programlisting">
28
29  struct mydata *p = kmalloc(sizeof(*p), GFP_KERNEL);
30  hw-&gt;private_data = p;
31  hw-&gt;private_free = mydata_free;
32
33          </pre></div><p>
34
35        and the implementation of the destructor would be:
36
37        </p><div class="informalexample"><pre class="programlisting">
38
39  static void mydata_free(struct snd_hwdep *hw)
40  {
41          struct mydata *p = hw-&gt;private_data;
42          kfree(p);
43  }
44
45          </pre></div><p>
46      </p><p>
47        The arbitrary file operations can be defined for this
48        instance. The file operators are defined in
49        the <em class="parameter"><code>ops</code></em> table. For example, assume that
50        this chip needs an ioctl. 
51
52        </p><div class="informalexample"><pre class="programlisting">
53
54  hw-&gt;ops.open = mydata_open;
55  hw-&gt;ops.ioctl = mydata_ioctl;
56  hw-&gt;ops.release = mydata_release;
57
58          </pre></div><p>
59
60        And implement the callback functions as you like.
61      </p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="misc-devices.html">Prev</a>&#160;</td><td width="20%" align="center"><a accesskey="u" href="misc-devices.html">Up</a></td><td width="40%" align="right">&#160;<a accesskey="n" href="misc-devices-IEC958.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter&#160;10.&#160;Miscellaneous Devices&#160;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&#160;IEC958 (S/PDIF)</td></tr></table></div></body></html>
62