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 7. API for AC97 Codec"><link rel="prev" href="api-ac97.html" title="Chapter 7. 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> </td><th width="60%" align="center">Chapter 7. API for AC97 Codec</th><td width="20%" align="right"> <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 7.1. 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->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->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->card, 0, &ops, NULL, &bus); 38 if (err < 0) 39 return err; 40 memset(&ac97, 0, sizeof(ac97)); 41 ac97.private_data = chip; 42 return snd_ac97_mixer(bus, &ac97, &chip->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> </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-constructor.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 7. API for AC97 Codec </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Constructor</td></tr></table></div></body></html> 48