<?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>Hardware-Dependent Devices</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="ch10.html" title="Chapter 10. Miscellaneous Devices" /><link rel="prev" href="ch10.html" title="Chapter 10. Miscellaneous Devices" /><link rel="next" href="ch10s03.html" title="IEC958 (S/PDIF)" /></head><body><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="ch10.html">Prev</a> </td><th width="60%" align="center">Chapter 10. Miscellaneous Devices</th><td width="20%" align="right"> <a accesskey="n" href="ch10s03.html">Next</a></td></tr></table><hr /></div><div class="section" title="Hardware-Dependent Devices"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="misc-devices-hardware-dependent"></a>Hardware-Dependent Devices</h2></div></div></div><p> Some chips need user-space access for special controls or for loading the micro code. In such a case, you can create a hwdep (hardware-dependent) device. The hwdep API is defined in <code class="filename"><sound/hwdep.h></code>. You can find examples in opl3 driver or <code class="filename">isa/sb/sb16_csp.c</code>. </p><p> The creation of the <span class="type">hwdep</span> instance is done via <code class="function">snd_hwdep_new()</code>. </p><div class="informalexample"><pre class="programlisting"> struct snd_hwdep *hw; snd_hwdep_new(card, "My HWDEP", 0, &hw); </pre></div><p> where the third argument is the index number. </p><p> You can then pass any pointer value to the <em class="parameter"><code>private_data</code></em>. If you assign a private data, you should define the destructor, too. The destructor function is set in the <em class="structfield"><code>private_free</code></em> field. </p><div class="informalexample"><pre class="programlisting"> struct mydata *p = kmalloc(sizeof(*p), GFP_KERNEL); hw->private_data = p; hw->private_free = mydata_free; </pre></div><p> and the implementation of the destructor would be: </p><div class="informalexample"><pre class="programlisting"> static void mydata_free(struct snd_hwdep *hw) { struct mydata *p = hw->private_data; kfree(p); } </pre></div><p> </p><p> The arbitrary file operations can be defined for this instance. The file operators are defined in the <em class="parameter"><code>ops</code></em> table. For example, assume that this chip needs an ioctl. </p><div class="informalexample"><pre class="programlisting"> hw->ops.open = mydata_open; hw->ops.ioctl = mydata_ioctl; hw->ops.release = mydata_release; </pre></div><p> And implement the callback functions as you like. </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch10.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch10.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch10s03.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 10. Miscellaneous Devices </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> IEC958 (S/PDIF)</td></tr></table></div></body></html>