1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>Chip-Specific Data</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="card-management.html" title="Chapter 3. Management of Cards and Components"><link rel="prev" href="card-management-component.html" title="Components"><link rel="next" href="card-management-registration.html" title="Registration and Release"></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">Chip-Specific Data</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="card-management-component.html">Prev</a> </td><th width="60%" align="center">Chapter 3. Management of Cards and Components</th><td width="20%" align="right"> <a accesskey="n" href="card-management-registration.html">Next</a></td></tr></table><hr></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="card-management-chip-specific"></a>Chip-Specific Data</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="section"><a href="card-management-chip-specific.html#card-management-chip-specific-snd-card-new">1. Allocating via <code class="function">snd_card_new()</code>.</a></span></dt><dt><span class="section"><a href="card-management-chip-specific.html#card-management-chip-specific-allocate-extra">2. Allocating an extra device.</a></span></dt></dl></div><p> 2 Chip-specific information, e.g. the I/O port address, its 3 resource pointer, or the irq number, is stored in the 4 chip-specific record. 5 6 </p><div class="informalexample"><pre class="programlisting"> 7 8 struct mychip { 9 .... 10 }; 11 12 </pre></div><p> 13 </p><p> 14 In general, there are two ways of allocating the chip record. 15 </p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="card-management-chip-specific-snd-card-new"></a>1. Allocating via <code class="function">snd_card_new()</code>.</h3></div></div></div><p> 16 As mentioned above, you can pass the extra-data-length 17 to the 5th argument of <code class="function">snd_card_new()</code>, i.e. 18 19 </p><div class="informalexample"><pre class="programlisting"> 20 21 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, 22 sizeof(struct mychip), &card); 23 24 </pre></div><p> 25 26 struct <span class="structname">mychip</span> is the type of the chip record. 27 </p><p> 28 In return, the allocated record can be accessed as 29 30 </p><div class="informalexample"><pre class="programlisting"> 31 32 struct mychip *chip = card->private_data; 33 34 </pre></div><p> 35 36 With this method, you don't have to allocate twice. 37 The record is released together with the card instance. 38 </p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="card-management-chip-specific-allocate-extra"></a>2. Allocating an extra device.</h3></div></div></div><p> 39 After allocating a card instance via 40 <code class="function">snd_card_new()</code> (with 41 <code class="constant">0</code> on the 4th arg), call 42 <code class="function">kzalloc()</code>. 43 44 </p><div class="informalexample"><pre class="programlisting"> 45 46 struct snd_card *card; 47 struct mychip *chip; 48 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, 49 0, &card); 50 ..... 51 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 52 53 </pre></div><p> 54 </p><p> 55 The chip record should have the field to hold the card 56 pointer at least, 57 58 </p><div class="informalexample"><pre class="programlisting"> 59 60 struct mychip { 61 struct snd_card *card; 62 .... 63 }; 64 65 </pre></div><p> 66 </p><p> 67 Then, set the card pointer in the returned chip instance. 68 69 </p><div class="informalexample"><pre class="programlisting"> 70 71 chip->card = card; 72 73 </pre></div><p> 74 </p><p> 75 Next, initialize the fields, and register this chip 76 record as a low-level device with a specified 77 <em class="parameter"><code>ops</code></em>, 78 79 </p><div class="informalexample"><pre class="programlisting"> 80 81 static struct snd_device_ops ops = { 82 .dev_free = snd_mychip_dev_free, 83 }; 84 .... 85 snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); 86 87 </pre></div><p> 88 89 <code class="function">snd_mychip_dev_free()</code> is the 90 device-destructor function, which will call the real 91 destructor. 92 </p><p> 93 </p><div class="informalexample"><pre class="programlisting"> 94 95 static int snd_mychip_dev_free(struct snd_device *device) 96 { 97 return snd_mychip_free(device->device_data); 98 } 99 100 </pre></div><p> 101 102 where <code class="function">snd_mychip_free()</code> is the real destructor. 103 </p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="card-management-component.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="card-management.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="card-management-registration.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Components </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Registration and Release</td></tr></table></div></body></html> 104