1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>Constructor</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="api-ac97.html" title="Chapter 7. API for AC97 Codec"><link rel="prev" href="api-ac97-example.html" title="Full Code Example"><link rel="next" href="api-ac97-callbacks.html" title="Callbacks"></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">Constructor</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="api-ac97-example.html">Prev</a> </td><th width="60%" align="center">Chapter 7. API for AC97 Codec</th><td width="20%" align="right"> <a accesskey="n" href="api-ac97-callbacks.html">Next</a></td></tr></table><hr></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="api-ac97-constructor"></a>Constructor</h2></div></div></div><p> 2 To create an ac97 instance, first call <code class="function">snd_ac97_bus</code> 3 with an <span class="type">ac97_bus_ops_t</span> record with callback functions. 4 5 </p><div class="informalexample"><pre class="programlisting"> 6 7 struct snd_ac97_bus *bus; 8 static struct snd_ac97_bus_ops ops = { 9 .write = snd_mychip_ac97_write, 10 .read = snd_mychip_ac97_read, 11 }; 12 13 snd_ac97_bus(card, 0, &ops, NULL, &pbus); 14 15 </pre></div><p> 16 17 The bus record is shared among all belonging ac97 instances. 18 </p><p> 19 And then call <code class="function">snd_ac97_mixer()</code> with an 20 struct <span class="structname">snd_ac97_template</span> 21 record together with the bus pointer created above. 22 23 </p><div class="informalexample"><pre class="programlisting"> 24 25 struct snd_ac97_template ac97; 26 int err; 27 28 memset(&ac97, 0, sizeof(ac97)); 29 ac97.private_data = chip; 30 snd_ac97_mixer(bus, &ac97, &chip->ac97); 31 32 </pre></div><p> 33 34 where chip->ac97 is a pointer to a newly created 35 <span class="type">ac97_t</span> instance. 36 In this case, the chip pointer is set as the private data, so that 37 the read/write callback functions can refer to this chip instance. 38 This instance is not necessarily stored in the chip 39 record. If you need to change the register values from the 40 driver, or need the suspend/resume of ac97 codecs, keep this 41 pointer to pass to the corresponding functions. 42 </p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="api-ac97-example.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="api-ac97.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="api-ac97-callbacks.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Full Code Example </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Callbacks</td></tr></table></div></body></html> 43