1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>Full Code Example</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&#160;7.&#160;API for AC97 Codec"><link rel="prev" href="api-ac97.html" title="Chapter&#160;7.&#160;API for AC97 Codec"><link rel="next" href="api-ac97-constructor.html" title="Constructor"></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">Full Code Example</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="api-ac97.html">Prev</a>&#160;</td><th width="60%" align="center">Chapter&#160;7.&#160;API for AC97 Codec</th><td width="20%" align="right">&#160;<a accesskey="n" href="api-ac97-constructor.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-example"></a>Full Code Example</h2></div></div></div><p>
2          </p><div class="example"><a name="idp1094229132"></a><p class="title"><b>Example&#160;7.1.&#160;Example of AC97 Interface</b></p><div class="example-contents"><pre class="programlisting">
3
4  struct mychip {
5          ....
6          struct snd_ac97 *ac97;
7          ....
8  };
9
10  static unsigned short snd_mychip_ac97_read(struct snd_ac97 *ac97,
11                                             unsigned short reg)
12  {
13          struct mychip *chip = ac97-&gt;private_data;
14          ....
15          /* read a register value here from the codec */
16          return the_register_value;
17  }
18
19  static void snd_mychip_ac97_write(struct snd_ac97 *ac97,
20                                   unsigned short reg, unsigned short val)
21  {
22          struct mychip *chip = ac97-&gt;private_data;
23          ....
24          /* write the given register value to the codec */
25  }
26
27  static int snd_mychip_ac97(struct mychip *chip)
28  {
29          struct snd_ac97_bus *bus;
30          struct snd_ac97_template ac97;
31          int err;
32          static struct snd_ac97_bus_ops ops = {
33                  .write = snd_mychip_ac97_write,
34                  .read = snd_mychip_ac97_read,
35          };
36
37          err = snd_ac97_bus(chip-&gt;card, 0, &amp;ops, NULL, &amp;bus);
38          if (err &lt; 0)
39                  return err;
40          memset(&amp;ac97, 0, sizeof(ac97));
41          ac97.private_data = chip;
42          return snd_ac97_mixer(bus, &amp;ac97, &amp;chip-&gt;ac97);
43  }
44
45
46          </pre></div></div><p><br class="example-break">
47      </p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="api-ac97.html">Prev</a>&#160;</td><td width="20%" align="center"><a accesskey="u" href="api-ac97.html">Up</a></td><td width="40%" align="right">&#160;<a accesskey="n" href="api-ac97-constructor.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter&#160;7.&#160;API for AC97 Codec&#160;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&#160;Constructor</td></tr></table></div></body></html>
48