<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[Freeswitch-trunk][15538] </title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<div id="header">FreeSWITCH Subversion</div>
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://fisheye.freeswitch.org/changelog/FreeSWITCH?cs=15538">15538</a></dd>
<dt>Author</dt> <dd>gmaruzz</dd>
<dt>Date</dt> <dd>2009-11-18 20:01:28 -0600 (Wed, 18 Nov 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>skypiax: updated /usr/src/freeswitch.trunk/src/mod/endpoints/mod_skypiax/kernel dummy.c</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunksrcmodendpointsmod_skypiaxkerneldummycskypiax">freeswitch/trunk/src/mod/endpoints/mod_skypiax/kernel/dummy.c.skypiax</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunksrcmodendpointsmod_skypiaxkerneldummycskypiax"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_skypiax/kernel/dummy.c.skypiax (15537 => 15538)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_skypiax/kernel/dummy.c.skypiax        2009-11-19 00:17:47 UTC (rev 15537)
+++ freeswitch/trunk/src/mod/endpoints/mod_skypiax/kernel/dummy.c.skypiax        2009-11-19 02:01:28 UTC (rev 15538)
</span><span class="lines">@@ -18,7 +18,6 @@
</span><span class="cx">  *
</span><span class="cx">  */
</span><span class="cx"> 
</span><del>-#include &lt;sound/driver.h&gt; //giova
</del><span class="cx"> #include &lt;linux/init.h&gt;
</span><span class="cx"> #include &lt;linux/err.h&gt;
</span><span class="cx"> #include &lt;linux/platform_device.h&gt;
</span><span class="lines">@@ -26,6 +25,8 @@
</span><span class="cx"> #include &lt;linux/slab.h&gt;
</span><span class="cx"> #include &lt;linux/time.h&gt;
</span><span class="cx"> #include &lt;linux/wait.h&gt;
</span><ins>+#include &lt;linux/hrtimer.h&gt;
+#include &lt;linux/math64.h&gt;
</ins><span class="cx"> #include &lt;linux/moduleparam.h&gt;
</span><span class="cx"> #include &lt;sound/core.h&gt;
</span><span class="cx"> #include &lt;sound/control.h&gt;
</span><span class="lines">@@ -34,7 +35,6 @@
</span><span class="cx"> #include &lt;sound/rawmidi.h&gt;
</span><span class="cx"> #include &lt;sound/initval.h&gt;
</span><span class="cx"> 
</span><del>-
</del><span class="cx"> MODULE_AUTHOR(&quot;Jaroslav Kysela &lt;perex@perex.cz&gt;&quot;);
</span><span class="cx"> MODULE_DESCRIPTION(&quot;Dummy soundcard (/dev/null)&quot;);
</span><span class="cx"> MODULE_LICENSE(&quot;GPL&quot;);
</span><span class="lines">@@ -112,10 +112,10 @@
</span><span class="cx"> 
</span><span class="cx"> /* defaults */
</span><span class="cx"> #ifndef MAX_BUFFER_SIZE
</span><del>-#define MAX_BUFFER_SIZE                (64*1024)
</del><ins>+#define MAX_BUFFER_SIZE                1024
</ins><span class="cx"> #endif
</span><span class="cx"> #ifndef MAX_PERIOD_SIZE
</span><del>-#define MAX_PERIOD_SIZE                MAX_BUFFER_SIZE
</del><ins>+#define MAX_PERIOD_SIZE                512
</ins><span class="cx"> #endif
</span><span class="cx"> #ifndef USE_FORMATS
</span><span class="cx"> #define USE_FORMATS                 (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE)
</span><span class="lines">@@ -150,6 +150,10 @@
</span><span class="cx"> static int pcm_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
</span><span class="cx"> static int pcm_substreams[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 128};
</span><span class="cx"> //static int midi_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2};
</span><ins>+#ifdef CONFIG_HIGH_RES_TIMERS
+static int hrtimer = 1;
+#endif
+static int fake_buffer = 1;
</ins><span class="cx"> 
</span><span class="cx"> module_param_array(index, int, NULL, 0444);
</span><span class="cx"> MODULE_PARM_DESC(index, &quot;Index value for dummy soundcard.&quot;);
</span><span class="lines">@@ -160,21 +164,17 @@
</span><span class="cx"> module_param_array(pcm_devs, int, NULL, 0444);
</span><span class="cx"> MODULE_PARM_DESC(pcm_devs, &quot;PCM devices # (0-4) for dummy driver.&quot;);
</span><span class="cx"> module_param_array(pcm_substreams, int, NULL, 0444);
</span><del>-MODULE_PARM_DESC(pcm_substreams, &quot;PCM substreams # (1-64) for dummy driver.&quot;);
</del><ins>+MODULE_PARM_DESC(pcm_substreams, &quot;PCM substreams # (1-16) for dummy driver.&quot;);
</ins><span class="cx"> //module_param_array(midi_devs, int, NULL, 0444);
</span><span class="cx"> //MODULE_PARM_DESC(midi_devs, &quot;MIDI devices # (0-2) for dummy driver.&quot;);
</span><ins>+module_param(fake_buffer, bool, 0444);
+MODULE_PARM_DESC(fake_buffer, &quot;Fake buffer allocations.&quot;);
+#ifdef CONFIG_HIGH_RES_TIMERS
+module_param(hrtimer, bool, 0644);
+MODULE_PARM_DESC(hrtimer, &quot;Use hrtimer as the timer source.&quot;);
+#endif
</ins><span class="cx"> 
</span><span class="cx"> static struct platform_device *devices[SNDRV_CARDS];
</span><del>-static struct timer_list giovatimer; //giova
-static int giovastarted=0;
-static int giovaindex=0;
-static spinlock_t giovalock;
-struct giovadpcm {
-        struct snd_pcm_substream *substream;
-        struct snd_dummy_pcm *dpcm;
-        int        started;
-};
-static struct giovadpcm giovadpcms[MAX_PCM_SUBSTREAMS];
</del><span class="cx"> 
</span><span class="cx"> #define MIXER_ADDR_MASTER        0
</span><span class="cx"> #define MIXER_ADDR_LINE                1
</span><span class="lines">@@ -183,215 +183,324 @@
</span><span class="cx"> #define MIXER_ADDR_CD                4
</span><span class="cx"> #define MIXER_ADDR_LAST                4
</span><span class="cx"> 
</span><del>-static void snd_card_dummy_pcm_timer_function(unsigned long data);
</del><ins>+struct dummy_timer_ops {
+        int (*create)(struct snd_pcm_substream *);
+        void (*free)(struct snd_pcm_substream *);
+        int (*prepare)(struct snd_pcm_substream *);
+        int (*start)(struct snd_pcm_substream *);
+        int (*stop)(struct snd_pcm_substream *);
+        snd_pcm_uframes_t (*pointer)(struct snd_pcm_substream *);
+};
+
</ins><span class="cx"> struct snd_dummy {
</span><span class="cx">         struct snd_card *card;
</span><span class="cx">         struct snd_pcm *pcm;
</span><span class="cx">         spinlock_t mixer_lock;
</span><span class="cx">         int mixer_volume[MIXER_ADDR_LAST+1][2];
</span><span class="cx">         int capture_source[MIXER_ADDR_LAST+1][2];
</span><ins>+        const struct dummy_timer_ops *timer_ops;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><del>-struct snd_dummy_pcm {
-        struct snd_dummy *dummy;
</del><ins>+/*
+ * system timer interface
+ */
+
+struct dummy_systimer_pcm {
</ins><span class="cx">         spinlock_t lock;
</span><span class="cx">         struct timer_list timer;
</span><del>-        unsigned int pcm_buffer_size;
-        unsigned int pcm_period_size;
-        unsigned int pcm_bps;                /* bytes per second */
-        unsigned int pcm_hz;                /* HZ */
-        unsigned int pcm_irq_pos;        /* IRQ position */
-        unsigned int pcm_buf_pos;        /* position in buffer */
</del><ins>+        unsigned long base_time;
+        unsigned int frac_pos;        /* fractional sample position (based HZ) */
+        unsigned int frac_period_rest;
+        unsigned int frac_buffer_size;        /* buffer_size * HZ */
+        unsigned int frac_period_size;        /* period_size * HZ */
+        unsigned int rate;
+        int elapsed;
</ins><span class="cx">         struct snd_pcm_substream *substream;
</span><span class="cx"> };
</span><span class="cx"> 
</span><ins>+static void dummy_systimer_rearm(struct dummy_systimer_pcm *dpcm)
+{
+        dpcm-&gt;timer.expires = jiffies +
+                (dpcm-&gt;frac_period_rest + dpcm-&gt;rate - 1) / dpcm-&gt;rate;
+        add_timer(&amp;dpcm-&gt;timer);
+}
</ins><span class="cx"> 
</span><del>-static inline void snd_card_dummy_pcm_timer_start(struct snd_dummy_pcm *dpcm)
</del><ins>+static void dummy_systimer_update(struct dummy_systimer_pcm *dpcm)
</ins><span class="cx"> {
</span><del>-int i;
-int found=0;
</del><ins>+        unsigned long delta;
</ins><span class="cx"> 
</span><del>-
-//printk(&quot;giova: 1 timer_start %d %p\n&quot;, __LINE__, dpcm);
-for(i=0; i&lt;giovaindex+1; i++){
-        if(i &gt; MAX_PCM_SUBSTREAMS || giovaindex &gt; MAX_PCM_SUBSTREAMS){
-                printk(&quot;giova, %s:%d, i=%d, giovaindex=%d dpcm=%p\n&quot;, __FILE__, __LINE__, i, giovaindex, dpcm);
</del><ins>+        delta = jiffies - dpcm-&gt;base_time;
+        if (!delta)
+                return;
+        dpcm-&gt;base_time += delta;
+        delta *= dpcm-&gt;rate;
+        dpcm-&gt;frac_pos += delta;
+        while (dpcm-&gt;frac_pos &gt;= dpcm-&gt;frac_buffer_size)
+                dpcm-&gt;frac_pos -= dpcm-&gt;frac_buffer_size;
+        while (dpcm-&gt;frac_period_rest &lt;= delta) {
+                dpcm-&gt;elapsed++;
+                dpcm-&gt;frac_period_rest += dpcm-&gt;frac_period_size;
</ins><span class="cx">         }
</span><ins>+        dpcm-&gt;frac_period_rest -= delta;
+}
</ins><span class="cx"> 
</span><del>-if(giovadpcms[i].dpcm == dpcm){
-        giovadpcms[i].started=1;
-        found=1;
</del><ins>+static int dummy_systimer_start(struct snd_pcm_substream *substream)
+{
+        struct dummy_systimer_pcm *dpcm = substream-&gt;runtime-&gt;private_data;
+        spin_lock(&amp;dpcm-&gt;lock);
+        dpcm-&gt;base_time = jiffies;
+        dummy_systimer_rearm(dpcm);
+        spin_unlock(&amp;dpcm-&gt;lock);
+        return 0;
</ins><span class="cx"> }
</span><ins>+
+static int dummy_systimer_stop(struct snd_pcm_substream *substream)
+{
+        struct dummy_systimer_pcm *dpcm = substream-&gt;runtime-&gt;private_data;
+        spin_lock(&amp;dpcm-&gt;lock);
+        del_timer(&amp;dpcm-&gt;timer);
+        spin_unlock(&amp;dpcm-&gt;lock);
+        return 0;
</ins><span class="cx"> }
</span><del>-if(!found){
-        printk(&quot;skypiax: start, NOT found?\n&quot;);
</del><ins>+
+static int dummy_systimer_prepare(struct snd_pcm_substream *substream)
+{
+        struct snd_pcm_runtime *runtime = substream-&gt;runtime;
+        struct dummy_systimer_pcm *dpcm = runtime-&gt;private_data;
+
+        dpcm-&gt;frac_pos = 0;
+        dpcm-&gt;rate = runtime-&gt;rate;
+        dpcm-&gt;frac_buffer_size = runtime-&gt;buffer_size * HZ;
+        dpcm-&gt;frac_period_size = runtime-&gt;period_size * HZ;
+        dpcm-&gt;frac_period_rest = dpcm-&gt;frac_period_size;
+        dpcm-&gt;elapsed = 0;
+
+        return 0;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static void dummy_systimer_callback(unsigned long data)
+{
+        struct dummy_systimer_pcm *dpcm = (struct dummy_systimer_pcm *)data;
+        unsigned long flags;
+        int elapsed = 0;
+        
+        spin_lock_irqsave(&amp;dpcm-&gt;lock, flags);
+        dummy_systimer_update(dpcm);
+        dummy_systimer_rearm(dpcm);
+        elapsed = dpcm-&gt;elapsed;
+        dpcm-&gt;elapsed = 0;
+        spin_unlock_irqrestore(&amp;dpcm-&gt;lock, flags);
+        if (elapsed)
+                snd_pcm_period_elapsed(dpcm-&gt;substream);
+}
</ins><span class="cx"> 
</span><ins>+static snd_pcm_uframes_t
+dummy_systimer_pointer(struct snd_pcm_substream *substream)
+{
+        struct dummy_systimer_pcm *dpcm = substream-&gt;runtime-&gt;private_data;
+        snd_pcm_uframes_t pos;
</ins><span class="cx"> 
</span><del>-//printk(&quot;giova: 2 timer_start %d %p\n&quot;, __LINE__, dpcm);
</del><ins>+        spin_lock(&amp;dpcm-&gt;lock);
+        dummy_systimer_update(dpcm);
+        pos = dpcm-&gt;frac_pos / HZ;
+        spin_unlock(&amp;dpcm-&gt;lock);
+        return pos;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-static inline void snd_card_dummy_pcm_timer_stop(struct snd_dummy_pcm *dpcm)
</del><ins>+static int dummy_systimer_create(struct snd_pcm_substream *substream)
</ins><span class="cx"> {
</span><del>-        //del_timer(&amp;dpcm-&gt;timer);
-int i;
-int found=0;
</del><ins>+        struct dummy_systimer_pcm *dpcm;
</ins><span class="cx"> 
</span><del>-//printk(&quot;giova: 1 timer_stop %d %p\n&quot;, __LINE__, dpcm);
-for(i=0; i&lt;giovaindex +1; i++){
</del><ins>+        dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL);
+        if (!dpcm)
+                return -ENOMEM;
+        substream-&gt;runtime-&gt;private_data = dpcm;
+        init_timer(&amp;dpcm-&gt;timer);
+        dpcm-&gt;timer.data = (unsigned long) dpcm;
+        dpcm-&gt;timer.function = dummy_systimer_callback;
+        spin_lock_init(&amp;dpcm-&gt;lock);
+        dpcm-&gt;substream = substream;
+        return 0;
+}
</ins><span class="cx"> 
</span><del>-        if(i &gt; MAX_PCM_SUBSTREAMS || giovaindex &gt; MAX_PCM_SUBSTREAMS){
-                printk(&quot;giova, %s:%d, i=%d, giovaindex=%d dpcm=%p\n&quot;, __FILE__, __LINE__, i, giovaindex, dpcm);
-        }
-if(giovadpcms[i].dpcm == dpcm){
-        giovadpcms[i].started=0;
-        found=1;
</del><ins>+static void dummy_systimer_free(struct snd_pcm_substream *substream)
+{
+        kfree(substream-&gt;runtime-&gt;private_data);
</ins><span class="cx"> }
</span><ins>+
+static struct dummy_timer_ops dummy_systimer_ops = {
+        .create =        dummy_systimer_create,
+        .free =                dummy_systimer_free,
+        .prepare =        dummy_systimer_prepare,
+        .start =        dummy_systimer_start,
+        .stop =                dummy_systimer_stop,
+        .pointer =        dummy_systimer_pointer,
+};
+
+#ifdef CONFIG_HIGH_RES_TIMERS
+/*
+ * hrtimer interface
+ */
+
+struct dummy_hrtimer_pcm {
+        ktime_t base_time;
+        ktime_t period_time;
+        atomic_t running;
+        struct hrtimer timer;
+        struct tasklet_struct tasklet;
+        struct snd_pcm_substream *substream;
+};
+
+static void dummy_hrtimer_pcm_elapsed(unsigned long priv)
+{
+        struct dummy_hrtimer_pcm *dpcm = (struct dummy_hrtimer_pcm *)priv;
+        if (atomic_read(&amp;dpcm-&gt;running))
+                snd_pcm_period_elapsed(dpcm-&gt;substream);
</ins><span class="cx"> }
</span><del>-if(!found){
-        //printk(&quot;skypiax: stop, NOT found?\n&quot;);
-        } else { 
-                //printk(&quot;skypiax: stop, YES found!\n&quot;); 
-        }
</del><span class="cx"> 
</span><ins>+static enum hrtimer_restart dummy_hrtimer_callback(struct hrtimer *timer)
+{
+        struct dummy_hrtimer_pcm *dpcm;
</ins><span class="cx"> 
</span><ins>+        dpcm = container_of(timer, struct dummy_hrtimer_pcm, timer);
+        if (!atomic_read(&amp;dpcm-&gt;running))
+                return HRTIMER_NORESTART;
+        tasklet_schedule(&amp;dpcm-&gt;tasklet);
+        hrtimer_forward_now(timer, dpcm-&gt;period_time);
+        return HRTIMER_RESTART;
+}
</ins><span class="cx"> 
</span><del>-//printk(&quot;giova: 2 timer_stop %d %p\n&quot;, __LINE__, dpcm);
</del><ins>+static int dummy_hrtimer_start(struct snd_pcm_substream *substream)
+{
+        struct dummy_hrtimer_pcm *dpcm = substream-&gt;runtime-&gt;private_data;
+
+        dpcm-&gt;base_time = hrtimer_cb_get_time(&amp;dpcm-&gt;timer);
+        hrtimer_start(&amp;dpcm-&gt;timer, dpcm-&gt;period_time, HRTIMER_MODE_REL);
+        atomic_set(&amp;dpcm-&gt;running, 1);
+        return 0;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-static int snd_card_dummy_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
</del><ins>+static int dummy_hrtimer_stop(struct snd_pcm_substream *substream)
</ins><span class="cx"> {
</span><del>-        struct snd_pcm_runtime *runtime = substream-&gt;runtime;
-        struct snd_dummy_pcm *dpcm = runtime-&gt;private_data;
-        int err = 0;
</del><ins>+        struct dummy_hrtimer_pcm *dpcm = substream-&gt;runtime-&gt;private_data;
</ins><span class="cx"> 
</span><del>-        //spin_lock(&amp;dpcm-&gt;lock, flags);
-        spin_lock_bh(&amp;giovalock);
-        switch (cmd) {
-        case SNDRV_PCM_TRIGGER_START:
-        case SNDRV_PCM_TRIGGER_RESUME:
-//printk(&quot;giova: trigger timer_start %d %p\n&quot;, __LINE__, dpcm);
-                snd_card_dummy_pcm_timer_start(dpcm);
-                break;
-        case SNDRV_PCM_TRIGGER_STOP:
-        case SNDRV_PCM_TRIGGER_SUSPEND:
-//printk(&quot;giova: trigger timer_stop %d %p\n&quot;, __LINE__, dpcm);
-                snd_card_dummy_pcm_timer_stop(dpcm);
-                break;
-        default:
-                err = -EINVAL;
-                break;
-        }
-        //spin_unlock(&amp;dpcm-&gt;lock, flags);
-        spin_unlock_bh(&amp;giovalock);
</del><ins>+        atomic_set(&amp;dpcm-&gt;running, 0);
+        hrtimer_cancel(&amp;dpcm-&gt;timer);
</ins><span class="cx">         return 0;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static int snd_card_dummy_pcm_prepare(struct snd_pcm_substream *substream)
</del><ins>+static inline void dummy_hrtimer_sync(struct dummy_hrtimer_pcm *dpcm)
</ins><span class="cx"> {
</span><ins>+        tasklet_kill(&amp;dpcm-&gt;tasklet);
+}
+
+static snd_pcm_uframes_t
+dummy_hrtimer_pointer(struct snd_pcm_substream *substream)
+{
</ins><span class="cx">         struct snd_pcm_runtime *runtime = substream-&gt;runtime;
</span><del>-        struct snd_dummy_pcm *dpcm = runtime-&gt;private_data;
-        int bps;
</del><ins>+        struct dummy_hrtimer_pcm *dpcm = runtime-&gt;private_data;
+        u64 delta;
+        u32 pos;
</ins><span class="cx"> 
</span><del>-        bps = snd_pcm_format_width(runtime-&gt;format) * runtime-&gt;rate *
-                runtime-&gt;channels / 8;
</del><ins>+        delta = ktime_us_delta(hrtimer_cb_get_time(&amp;dpcm-&gt;timer),
+                               dpcm-&gt;base_time);
+        delta = div_u64(delta * runtime-&gt;rate + 999999, 1000000);
+        div_u64_rem(delta, runtime-&gt;buffer_size, &amp;pos);
+        return pos;
+}
</ins><span class="cx"> 
</span><del>-        if (bps &lt;= 0)
-                return -EINVAL;
</del><ins>+static int dummy_hrtimer_prepare(struct snd_pcm_substream *substream)
+{
+        struct snd_pcm_runtime *runtime = substream-&gt;runtime;
+        struct dummy_hrtimer_pcm *dpcm = runtime-&gt;private_data;
+        unsigned int period, rate;
+        long sec;
+        unsigned long nsecs;
</ins><span class="cx"> 
</span><del>-        dpcm-&gt;pcm_bps = bps;
-        dpcm-&gt;pcm_hz = HZ;
-        dpcm-&gt;pcm_buffer_size = snd_pcm_lib_buffer_bytes(substream);
-        dpcm-&gt;pcm_period_size = snd_pcm_lib_period_bytes(substream);
-        dpcm-&gt;pcm_irq_pos = 0;
-        dpcm-&gt;pcm_buf_pos = 0;
-        snd_pcm_format_set_silence(runtime-&gt;format, runtime-&gt;dma_area,
-                        bytes_to_samples(runtime, runtime-&gt;dma_bytes));
</del><ins>+        dummy_hrtimer_sync(dpcm);
+        period = runtime-&gt;period_size;
+        rate = runtime-&gt;rate;
+        sec = period / rate;
+        period %= rate;
+        nsecs = div_u64((u64)period * 1000000000UL + rate - 1, rate);
+        dpcm-&gt;period_time = ktime_set(sec, nsecs);
</ins><span class="cx"> 
</span><del>-//printk(&quot;giova: prepare %d %p\n&quot;, __LINE__, dpcm);
</del><span class="cx">         return 0;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static void snd_card_dummy_pcm_timer_function(unsigned long data)
</del><ins>+static int dummy_hrtimer_create(struct snd_pcm_substream *substream)
</ins><span class="cx"> {
</span><del>-        //struct snd_dummy_pcm *dpcm = (struct snd_dummy_pcm *)data;
-        struct snd_dummy_pcm *dpcm=NULL;
-        //unsigned long flags;
-int i;
-        
</del><ins>+        struct dummy_hrtimer_pcm *dpcm;
</ins><span class="cx"> 
</span><del>-        giovatimer.expires = (HZ/100) + jiffies;
-        add_timer(&amp;giovatimer);
</del><ins>+        dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL);
+        if (!dpcm)
+                return -ENOMEM;
+        substream-&gt;runtime-&gt;private_data = dpcm;
+        hrtimer_init(&amp;dpcm-&gt;timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
+        dpcm-&gt;timer.function = dummy_hrtimer_callback;
+        dpcm-&gt;substream = substream;
+        atomic_set(&amp;dpcm-&gt;running, 0);
+        tasklet_init(&amp;dpcm-&gt;tasklet, dummy_hrtimer_pcm_elapsed,
+                     (unsigned long)dpcm);
+        return 0;
+}
</ins><span class="cx"> 
</span><del>-for(i=0; i&lt; giovaindex +1; i++) {
</del><ins>+static void dummy_hrtimer_free(struct snd_pcm_substream *substream)
+{
+        struct dummy_hrtimer_pcm *dpcm = substream-&gt;runtime-&gt;private_data;
+        dummy_hrtimer_sync(dpcm);
+        kfree(dpcm);
+}
</ins><span class="cx"> 
</span><del>-        if(i &gt; MAX_PCM_SUBSTREAMS || giovaindex &gt; MAX_PCM_SUBSTREAMS){
-                printk(&quot;giova, %s:%d, i=%d, giovaindex=%d dpcm=%p\n&quot;, __FILE__, __LINE__, i, giovaindex, dpcm);
-        }
-//printk(&quot;giova: timer_func %d i=%d\n&quot;, __LINE__, i);
</del><ins>+static struct dummy_timer_ops dummy_hrtimer_ops = {
+        .create =        dummy_hrtimer_create,
+        .free =                dummy_hrtimer_free,
+        .prepare =        dummy_hrtimer_prepare,
+        .start =        dummy_hrtimer_start,
+        .stop =                dummy_hrtimer_stop,
+        .pointer =        dummy_hrtimer_pointer,
+};
</ins><span class="cx"> 
</span><del>-if(giovadpcms[i].started != 1)
-        continue; 
-dpcm = giovadpcms[i].dpcm;
-if(dpcm==NULL){
-        printk(&quot;giova: timer_func %d %d NULL: continue\n&quot;, __LINE__, i);
-        continue;
</del><ins>+#endif /* CONFIG_HIGH_RES_TIMERS */
+
+/*
+ * PCM interface
+ */
+
+static int dummy_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
+{
+        struct snd_dummy *dummy = snd_pcm_substream_chip(substream);
+
+        switch (cmd) {
+        case SNDRV_PCM_TRIGGER_START:
+        case SNDRV_PCM_TRIGGER_RESUME:
+                return dummy-&gt;timer_ops-&gt;start(substream);
+        case SNDRV_PCM_TRIGGER_STOP:
+        case SNDRV_PCM_TRIGGER_SUSPEND:
+                return dummy-&gt;timer_ops-&gt;stop(substream);
</ins><span class="cx">         }
</span><del>-        if(in_irq())
-                printk(&quot;giova: timer_func %d %d we are in HARDWARE IRQ\n&quot;, __LINE__, i);
-        //if(in_softirq())
-                //printk(&quot;giova: timer_func %d %d we are in SOFT IRQ\n&quot;, __LINE__, i);
-//printk(&quot;giova: timer_func %d %d\n&quot;, __LINE__, i);
-        //spin_lock_irqsave(&amp;dpcm-&gt;lock, flags);
-        spin_lock_bh(&amp;dpcm-&gt;lock);
-        dpcm-&gt;pcm_irq_pos += dpcm-&gt;pcm_bps * (HZ/100);
-        dpcm-&gt;pcm_buf_pos += dpcm-&gt;pcm_bps * (HZ/100);
-        dpcm-&gt;pcm_buf_pos %= dpcm-&gt;pcm_buffer_size * dpcm-&gt;pcm_hz;
-        if (dpcm-&gt;pcm_irq_pos &gt;= dpcm-&gt;pcm_period_size * dpcm-&gt;pcm_hz) {
-                dpcm-&gt;pcm_irq_pos %= dpcm-&gt;pcm_period_size * dpcm-&gt;pcm_hz;
-                //spin_unlock_irqrestore(&amp;dpcm-&gt;lock, flags);
-                spin_unlock_bh(&amp;dpcm-&gt;lock);
-                snd_pcm_period_elapsed(dpcm-&gt;substream);
-        } else {
-                //spin_unlock_irqrestore(&amp;dpcm-&gt;lock, flags);
-                spin_unlock_bh(&amp;dpcm-&gt;lock);
-        }
</del><ins>+        return -EINVAL;
</ins><span class="cx"> }
</span><del>-}
</del><span class="cx"> 
</span><del>-static snd_pcm_uframes_t snd_card_dummy_pcm_pointer(struct snd_pcm_substream *substream)
</del><ins>+static int dummy_pcm_prepare(struct snd_pcm_substream *substream)
</ins><span class="cx"> {
</span><del>-        struct snd_pcm_runtime *runtime = substream-&gt;runtime;
-        struct snd_dummy_pcm *dpcm = runtime-&gt;private_data;
</del><ins>+        struct snd_dummy *dummy = snd_pcm_substream_chip(substream);
</ins><span class="cx"> 
</span><del>-//printk(&quot;giova: pointer %d %p\n&quot;, __LINE__, dpcm);
-        //return bytes_to_frames(runtime, dpcm-&gt;pcm_buf_pos / dpcm-&gt;pcm_hz);
-        return (dpcm-&gt;pcm_buf_pos / dpcm-&gt;pcm_hz)/2;
</del><ins>+        return dummy-&gt;timer_ops-&gt;prepare(substream);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-static struct snd_pcm_hardware snd_card_dummy_playback =
</del><ins>+static snd_pcm_uframes_t dummy_pcm_pointer(struct snd_pcm_substream *substream)
</ins><span class="cx"> {
</span><del>-        .info =                        (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
-                                 SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID),
-        .formats =                USE_FORMATS,
-        .rates =                USE_RATE,
-        .rate_min =                USE_RATE_MIN,
-        .rate_max =                USE_RATE_MAX,
-        .channels_min =                USE_CHANNELS_MIN,
-        .channels_max =                USE_CHANNELS_MAX,
-        .buffer_bytes_max =        MAX_BUFFER_SIZE,
-        .period_bytes_min =        64,
-        .period_bytes_max =        MAX_PERIOD_SIZE,
-        .periods_min =                USE_PERIODS_MIN,
-        .periods_max =                USE_PERIODS_MAX,
-        .fifo_size =                0,
-};
</del><ins>+        struct snd_dummy *dummy = snd_pcm_substream_chip(substream);
</ins><span class="cx"> 
</span><del>-static struct snd_pcm_hardware snd_card_dummy_capture =
-{
-        .info =                        (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
-                                 SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID),
</del><ins>+        return dummy-&gt;timer_ops-&gt;pointer(substream);
+}
+
+static struct snd_pcm_hardware dummy_pcm_hardware = {
+        .info =                        (SNDRV_PCM_INFO_MMAP |
+                                 SNDRV_PCM_INFO_INTERLEAVED |
+                                 SNDRV_PCM_INFO_RESUME |
+                                 SNDRV_PCM_INFO_MMAP_VALID),
</ins><span class="cx">         .formats =                USE_FORMATS,
</span><span class="cx">         .rates =                USE_RATE,
</span><span class="cx">         .rate_min =                USE_RATE_MIN,
</span><span class="lines">@@ -406,209 +515,152 @@
</span><span class="cx">         .fifo_size =                0,
</span><span class="cx"> };
</span><span class="cx"> 
</span><del>-static void snd_card_dummy_runtime_free(struct snd_pcm_runtime *runtime)
</del><ins>+static int dummy_pcm_hw_params(struct snd_pcm_substream *substream,
+                               struct snd_pcm_hw_params *hw_params)
</ins><span class="cx"> {
</span><del>-int i;
-//int found=0;
-
-//printk(&quot;snd_card_dummy_runtime_free giova 1 giovaindex=%d dpcm=%p runtime=%p\n&quot;, giovaindex, runtime-&gt;private_data, runtime);
-        spin_lock_bh(&amp;giovalock);
-
-for(i=0; i &lt; giovaindex; i++) {
-
-        if(i &gt; MAX_PCM_SUBSTREAMS || giovaindex &gt; MAX_PCM_SUBSTREAMS){
-                printk(&quot;giova, %s:%d, i=%d, giovaindex=%d \n&quot;, __FILE__, __LINE__, i, giovaindex);
</del><ins>+        if (fake_buffer) {
+                /* runtime-&gt;dma_bytes has to be set manually to allow mmap */
+                substream-&gt;runtime-&gt;dma_bytes = params_buffer_bytes(hw_params);
+                return 0;
</ins><span class="cx">         }
</span><del>-        //if((giovadpcms[i].substream == substream)  &amp;&amp; (giovadpcms[i].dpcm == dpcm)){
-        if((giovadpcms[i].dpcm == runtime-&gt;private_data)){
-                //printk(&quot;giova, %s:%d, i=%d, giovaindex=%d %p==%p YES I AM!!!!\n&quot;, __FILE__, __LINE__, i, giovaindex, giovadpcms[i].dpcm , runtime-&gt;private_data);
-                //giovadpcms[i].dpcm = NULL;
-                //giovadpcms[i].substream = NULL;
-                giovadpcms[i].started = 0;
-                //break;
-        } else {
-                //printk(&quot;giova, %s:%d, i=%d, giovaindex=%d %p!=%p NOT ME\n&quot;, __FILE__, __LINE__, i, giovaindex, giovadpcms[i].dpcm , runtime-&gt;private_data);
-        }
</del><ins>+        return snd_pcm_lib_malloc_pages(substream,
+                                        params_buffer_bytes(hw_params));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-        spin_unlock_bh(&amp;giovalock);
-        kfree(runtime-&gt;private_data);
-}
-
-static int snd_card_dummy_hw_params(struct snd_pcm_substream *substream,
-                                    struct snd_pcm_hw_params *hw_params)
</del><ins>+static int dummy_pcm_hw_free(struct snd_pcm_substream *substream)
</ins><span class="cx"> {
</span><del>-        return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
-}
-
-static int snd_card_dummy_hw_free(struct snd_pcm_substream *substream)
-{
</del><ins>+        if (fake_buffer)
+                return 0;
</ins><span class="cx">         return snd_pcm_lib_free_pages(substream);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static struct snd_dummy_pcm *new_pcm_stream(struct snd_pcm_substream *substream)
</del><ins>+static int dummy_pcm_open(struct snd_pcm_substream *substream)
</ins><span class="cx"> {
</span><del>-        struct snd_dummy_pcm *dpcm;
-        int i;
-        int found=0;
</del><ins>+        struct snd_dummy *dummy = snd_pcm_substream_chip(substream);
+        struct snd_pcm_runtime *runtime = substream-&gt;runtime;
+        int err;
</ins><span class="cx"> 
</span><del>-        //printk(&quot;giova, %s:%d, i=%d, giovaindex=%d %p==%p YES I AM!!!!\n&quot;, __FILE__, __LINE__, i, giovaindex, giovadpcms[i].dpcm , runtime-&gt;private_data);
-        //printk(&quot;giova, %s:%d, giovaindex=%d\n&quot;, __FILE__, __LINE__, giovaindex);
-        dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL);
-        //printk(&quot;giova, %s:%d, giovaindex=%d\n&quot;, __FILE__, __LINE__, giovaindex);
-        if (! dpcm){
-                //spin_unlock_bh(&amp;giovalock);
-                printk(&quot;giova, %s:%d, giovaindex=%d NO MEMORY!!!!\n&quot;, __FILE__, __LINE__, giovaindex);
-                return dpcm;
-        }
-        //printk(&quot;giova, %s:%d, giovaindex=%d dpcm=%p\n&quot;, __FILE__, __LINE__, giovaindex, dpcm);
-        init_timer(&amp;dpcm-&gt;timer);
-        //dpcm-&gt;timer.data = (unsigned long) dpcm;
-        //dpcm-&gt;timer.function = snd_card_dummy_pcm_timer_function;
-        spin_lock_init(&amp;dpcm-&gt;lock);
-        dpcm-&gt;substream = substream;
</del><ins>+        dummy-&gt;timer_ops = &amp;dummy_systimer_ops;
+#ifdef CONFIG_HIGH_RES_TIMERS
+        if (hrtimer)
+                dummy-&gt;timer_ops = &amp;dummy_hrtimer_ops;
+#endif
</ins><span class="cx"> 
</span><del>-        spin_lock_bh(&amp;giovalock);
-        //printk(&quot;giova 1 giovaindex=%d dpcm=%p substream=%p sizeof=%lu\n&quot;, giovaindex, dpcm, substream, sizeof(*dpcm));
-        for(i=0; i &lt; giovaindex; i++) {
</del><ins>+        err = dummy-&gt;timer_ops-&gt;create(substream);
+        if (err &lt; 0)
+                return err;
</ins><span class="cx"> 
</span><del>-        if(i &gt; MAX_PCM_SUBSTREAMS || giovaindex &gt; MAX_PCM_SUBSTREAMS){
-                printk(&quot;giova, %s:%d, i=%d, giovaindex=%d dpcm=%p\n&quot;, __FILE__, __LINE__, i, giovaindex, dpcm);
</del><ins>+        runtime-&gt;hw = dummy_pcm_hardware;
+        if (substream-&gt;pcm-&gt;device &amp; 1) {
+                runtime-&gt;hw.info &amp;= ~SNDRV_PCM_INFO_INTERLEAVED;
+                runtime-&gt;hw.info |= SNDRV_PCM_INFO_NONINTERLEAVED;
</ins><span class="cx">         }
</span><del>-                //if((giovadpcms[i].substream == substream)  &amp;&amp; (giovadpcms[i].dpcm == dpcm))
-                if((giovadpcms[i].substream == substream)){
-                        found=1;
-                        break;
-                }
</del><ins>+        if (substream-&gt;pcm-&gt;device &amp; 2)
+                runtime-&gt;hw.info &amp;= ~(SNDRV_PCM_INFO_MMAP |
+                                      SNDRV_PCM_INFO_MMAP_VALID);
</ins><span class="cx"> 
</span><ins>+        if (substream-&gt;stream == SNDRV_PCM_STREAM_PLAYBACK)
+                err = add_playback_constraints(substream-&gt;runtime);
+        else
+                err = add_capture_constraints(substream-&gt;runtime);
+        if (err &lt; 0) {
+                dummy-&gt;timer_ops-&gt;free(substream);
+                return err;
</ins><span class="cx">         }
</span><ins>+        return 0;
+}
</ins><span class="cx"> 
</span><del>-        if(!found){
</del><ins>+static int dummy_pcm_close(struct snd_pcm_substream *substream)
+{
+        struct snd_dummy *dummy = snd_pcm_substream_chip(substream);
+        dummy-&gt;timer_ops-&gt;free(substream);
+        return 0;
+}
</ins><span class="cx"> 
</span><del>-                giovadpcms[giovaindex].substream=substream;
-                giovaindex++;
-                //printk(&quot;giova 2 giovaindex=%d dpcm=%p substream=%p\n&quot;, giovaindex, dpcm, substream);
-        }
</del><ins>+/*
+ * dummy buffer handling
+ */
</ins><span class="cx"> 
</span><ins>+static void *dummy_page[2];
</ins><span class="cx"> 
</span><del>-
-        found =0;
-        for(i=0; i &lt; giovaindex; i++) {
-
-        if(i &gt; MAX_PCM_SUBSTREAMS || giovaindex &gt; MAX_PCM_SUBSTREAMS){
-                printk(&quot;giova, %s:%d, i=%d, giovaindex=%d dpcm=%p\n&quot;, __FILE__, __LINE__, i, giovaindex, dpcm);
</del><ins>+static void free_fake_buffer(void)
+{
+        if (fake_buffer) {
+                int i;
+                for (i = 0; i &lt; 2; i++)
+                        if (dummy_page[i]) {
+                                free_page((unsigned long)dummy_page[i]);
+                                dummy_page[i] = NULL;
+                        }
</ins><span class="cx">         }
</span><del>-                if(giovadpcms[i].substream == substream){
-                        giovadpcms[i].dpcm=dpcm;
-                        giovadpcms[i].started=0;
-                        found = 1;
-                        //printk(&quot;giova 3 giovaindex=%d dpcm=%p substream=%p\n&quot;, giovaindex, dpcm, substream);
-                        break;
-                } 
-
-        }
-
-        spin_unlock_bh(&amp;giovalock);
-        if(!found) {
-                printk(&quot;skypiax giovaindex=%d NOT found????\n&quot;, giovaindex);
-        }
-
-        //printk(&quot;giova, %s:%d, giovaindex=%d\n&quot;, __FILE__, __LINE__, giovaindex);
-        return dpcm;
</del><span class="cx"> }
</span><span class="cx"> 
</span><del>-static int snd_card_dummy_playback_open(struct snd_pcm_substream *substream)
</del><ins>+static int alloc_fake_buffer(void)
</ins><span class="cx"> {
</span><del>-        struct snd_pcm_runtime *runtime = substream-&gt;runtime;
-        struct snd_dummy_pcm *dpcm;
-        int err;
</del><ins>+        int i;
</ins><span class="cx"> 
</span><del>-        if ((dpcm = new_pcm_stream(substream)) == NULL)
-                return -ENOMEM;
-        //printk(&quot;giova, %s:%d, giovaindex=%d dpcm=%p\n&quot;, __FILE__, __LINE__, giovaindex, dpcm);
-        runtime-&gt;private_data = dpcm;
-        /* makes the infrastructure responsible for freeing dpcm */
-        runtime-&gt;private_free = snd_card_dummy_runtime_free;
-        runtime-&gt;hw = snd_card_dummy_playback;
-        if (substream-&gt;pcm-&gt;device &amp; 1) {
-                runtime-&gt;hw.info &amp;= ~SNDRV_PCM_INFO_INTERLEAVED;
-                runtime-&gt;hw.info |= SNDRV_PCM_INFO_NONINTERLEAVED;
</del><ins>+        if (!fake_buffer)
+                return 0;
+        for (i = 0; i &lt; 2; i++) {
+                dummy_page[i] = (void *)get_zeroed_page(GFP_KERNEL);
+                if (!dummy_page[i]) {
+                        free_fake_buffer();
+                        return -ENOMEM;
+                }
</ins><span class="cx">         }
</span><del>-        if (substream-&gt;pcm-&gt;device &amp; 2)
-                runtime-&gt;hw.info &amp;= ~(SNDRV_PCM_INFO_MMAP|SNDRV_PCM_INFO_MMAP_VALID);
-        err = add_playback_constraints(runtime);
-        if (err &lt; 0)
-                return err;
-
</del><span class="cx">         return 0;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static int snd_card_dummy_capture_open(struct snd_pcm_substream *substream)
</del><ins>+static int dummy_pcm_copy(struct snd_pcm_substream *substream,
+                          int channel, snd_pcm_uframes_t pos,
+                          void __user *dst, snd_pcm_uframes_t count)
</ins><span class="cx"> {
</span><del>-        struct snd_pcm_runtime *runtime = substream-&gt;runtime;
-        struct snd_dummy_pcm *dpcm;
-        int err;
-
-        if ((dpcm = new_pcm_stream(substream)) == NULL)
-                return -ENOMEM;
-        //printk(&quot;giova, %s:%d, giovaindex=%d dpcm=%p\n&quot;, __FILE__, __LINE__, giovaindex, dpcm);
-        runtime-&gt;private_data = dpcm;
-        /* makes the infrastructure responsible for freeing dpcm */
-        runtime-&gt;private_free = snd_card_dummy_runtime_free;
-        runtime-&gt;hw = snd_card_dummy_capture;
-        if (substream-&gt;pcm-&gt;device == 1) {
-                runtime-&gt;hw.info &amp;= ~SNDRV_PCM_INFO_INTERLEAVED;
-                runtime-&gt;hw.info |= SNDRV_PCM_INFO_NONINTERLEAVED;
-        }
-        if (substream-&gt;pcm-&gt;device &amp; 2)
-                runtime-&gt;hw.info &amp;= ~(SNDRV_PCM_INFO_MMAP|SNDRV_PCM_INFO_MMAP_VALID);
-        err = add_capture_constraints(runtime);
-        if (err &lt; 0)
-                return err;
-
-        return 0;
</del><ins>+        return 0; /* do nothing */
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-static int snd_card_dummy_playback_close(struct snd_pcm_substream *substream)
</del><ins>+static int dummy_pcm_silence(struct snd_pcm_substream *substream,
+                             int channel, snd_pcm_uframes_t pos,
+                             snd_pcm_uframes_t count)
</ins><span class="cx"> {
</span><del>-//printk(&quot;play giova 1 giovaindex=%d dpcm=%p substream=%p\n&quot;, giovaindex, substream-&gt;private_data, substream);
-        snd_card_dummy_pcm_timer_stop(substream-&gt;private_data);
-        return 0;
</del><ins>+        return 0; /* do nothing */
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-static int snd_card_dummy_capture_close(struct snd_pcm_substream *substream)
</del><ins>+static struct page *dummy_pcm_page(struct snd_pcm_substream *substream,
+                                   unsigned long offset)
</ins><span class="cx"> {
</span><del>-//printk(&quot;capt giova 2 giovaindex=%d dpcm=%p substream=%p\n&quot;, giovaindex, substream-&gt;private_data, substream);
-        snd_card_dummy_pcm_timer_stop(substream-&gt;private_data);
-        return 0;
</del><ins>+        return virt_to_page(dummy_page[substream-&gt;stream]); /* the same page */
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-static struct snd_pcm_ops snd_card_dummy_playback_ops = {
-        .open =                        snd_card_dummy_playback_open,
-        .close =                snd_card_dummy_playback_close,
-        .ioctl =                snd_pcm_lib_ioctl,
-        .hw_params =                snd_card_dummy_hw_params,
-        .hw_free =                snd_card_dummy_hw_free,
-        .prepare =                snd_card_dummy_pcm_prepare,
-        .trigger =                snd_card_dummy_pcm_trigger,
-        .pointer =                snd_card_dummy_pcm_pointer,
</del><ins>+static struct snd_pcm_ops dummy_pcm_ops = {
+        .open =                dummy_pcm_open,
+        .close =        dummy_pcm_close,
+        .ioctl =        snd_pcm_lib_ioctl,
+        .hw_params =        dummy_pcm_hw_params,
+        .hw_free =        dummy_pcm_hw_free,
+        .prepare =        dummy_pcm_prepare,
+        .trigger =        dummy_pcm_trigger,
+        .pointer =        dummy_pcm_pointer,
</ins><span class="cx"> };
</span><span class="cx"> 
</span><del>-static struct snd_pcm_ops snd_card_dummy_capture_ops = {
-        .open =                        snd_card_dummy_capture_open,
-        .close =                snd_card_dummy_capture_close,
-        .ioctl =                snd_pcm_lib_ioctl,
-        .hw_params =                snd_card_dummy_hw_params,
-        .hw_free =                snd_card_dummy_hw_free,
-        .prepare =                snd_card_dummy_pcm_prepare,
-        .trigger =                snd_card_dummy_pcm_trigger,
-        .pointer =                snd_card_dummy_pcm_pointer,
</del><ins>+static struct snd_pcm_ops dummy_pcm_ops_no_buf = {
+        .open =                dummy_pcm_open,
+        .close =        dummy_pcm_close,
+        .ioctl =        snd_pcm_lib_ioctl,
+        .hw_params =        dummy_pcm_hw_params,
+        .hw_free =        dummy_pcm_hw_free,
+        .prepare =        dummy_pcm_prepare,
+        .trigger =        dummy_pcm_trigger,
+        .pointer =        dummy_pcm_pointer,
+        .copy =                dummy_pcm_copy,
+        .silence =        dummy_pcm_silence,
+        .page =                dummy_pcm_page,
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> static int __devinit snd_card_dummy_pcm(struct snd_dummy *dummy, int device,
</span><span class="cx">                                         int substreams)
</span><span class="cx"> {
</span><span class="cx">         struct snd_pcm *pcm;
</span><ins>+        struct snd_pcm_ops *ops;
</ins><span class="cx">         int err;
</span><span class="cx"> 
</span><span class="cx">         err = snd_pcm_new(dummy-&gt;card, &quot;Dummy PCM&quot;, device,
</span><span class="lines">@@ -616,15 +668,21 @@
</span><span class="cx">         if (err &lt; 0)
</span><span class="cx">                 return err;
</span><span class="cx">         dummy-&gt;pcm = pcm;
</span><del>-        snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &amp;snd_card_dummy_playback_ops);
-        snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &amp;snd_card_dummy_capture_ops);
</del><ins>+        if (fake_buffer)
+                ops = &amp;dummy_pcm_ops_no_buf;
+        else
+                ops = &amp;dummy_pcm_ops;
+        snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, ops);
+        snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, ops);
</ins><span class="cx">         pcm-&gt;private_data = dummy;
</span><span class="cx">         pcm-&gt;info_flags = 0;
</span><span class="cx">         strcpy(pcm-&gt;name, &quot;Dummy PCM&quot;);
</span><del>-        snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
-                                              snd_dma_continuous_data(GFP_KERNEL),
-                                              128*1024, 1024*1024);
-
</del><ins>+        if (!fake_buffer) {
+                snd_pcm_lib_preallocate_pages_for_all(pcm,
+                        SNDRV_DMA_TYPE_CONTINUOUS,
+                        snd_dma_continuous_data(GFP_KERNEL),
+                        0, 64*1024);
+        }
</ins><span class="cx">         return 0;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -652,18 +710,11 @@
</span><span class="cx"> {
</span><span class="cx">         struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
</span><span class="cx">         int addr = kcontrol-&gt;private_value;
</span><del>-        //unsigned long flags;
</del><span class="cx"> 
</span><del>-        if(in_irq())
-                printk(&quot;giova: line %d we are in HARDWARE IRQ\n&quot;, __LINE__);
-//printk(&quot;giova: volume get %d %d\n&quot;, __LINE__, addr);
-        //spin_lock_irq(&amp;dummy-&gt;mixer_lock);
-        //spin_lock_irqsave(&amp;dummy-&gt;mixer_lock, flags);
-        spin_lock_bh(&amp;dummy-&gt;mixer_lock);
</del><ins>+        spin_lock_irq(&amp;dummy-&gt;mixer_lock);
</ins><span class="cx">         ucontrol-&gt;value.integer.value[0] = dummy-&gt;mixer_volume[addr][0];
</span><span class="cx">         ucontrol-&gt;value.integer.value[1] = dummy-&gt;mixer_volume[addr][1];
</span><del>-        //spin_unlock_irqrestore(&amp;dummy-&gt;mixer_lock, flags);
-        spin_unlock_bh(&amp;dummy-&gt;mixer_lock);
</del><ins>+        spin_unlock_irq(&amp;dummy-&gt;mixer_lock);
</ins><span class="cx">         return 0;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -673,10 +724,7 @@
</span><span class="cx">         struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
</span><span class="cx">         int change, addr = kcontrol-&gt;private_value;
</span><span class="cx">         int left, right;
</span><del>-        //unsigned long flags;
</del><span class="cx"> 
</span><del>-        if(in_irq())
-                printk(&quot;giova: line %d we are in HARDWARE IRQ\n&quot;, __LINE__);
</del><span class="cx">         left = ucontrol-&gt;value.integer.value[0];
</span><span class="cx">         if (left &lt; -50)
</span><span class="cx">                 left = -50;
</span><span class="lines">@@ -687,17 +735,12 @@
</span><span class="cx">                 right = -50;
</span><span class="cx">         if (right &gt; 100)
</span><span class="cx">                 right = 100;
</span><del>-//printk(&quot;giova: volume put %d %d\n&quot;, __LINE__, addr);
-        //spin_lock_irq(&amp;dummy-&gt;mixer_lock);
-        //spin_lock_irqsave(&amp;dummy-&gt;mixer_lock, flags);
-        spin_lock_bh(&amp;dummy-&gt;mixer_lock);
</del><ins>+        spin_lock_irq(&amp;dummy-&gt;mixer_lock);
</ins><span class="cx">         change = dummy-&gt;mixer_volume[addr][0] != left ||
</span><span class="cx">                  dummy-&gt;mixer_volume[addr][1] != right;
</span><span class="cx">         dummy-&gt;mixer_volume[addr][0] = left;
</span><span class="cx">         dummy-&gt;mixer_volume[addr][1] = right;
</span><del>-        //spin_unlock_irq(&amp;dummy-&gt;mixer_lock);
-        //spin_unlock_irqrestore(&amp;dummy-&gt;mixer_lock, flags);
-        spin_unlock_bh(&amp;dummy-&gt;mixer_lock);
</del><ins>+        spin_unlock_irq(&amp;dummy-&gt;mixer_lock);
</ins><span class="cx">         return change;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -716,19 +759,11 @@
</span><span class="cx"> {
</span><span class="cx">         struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
</span><span class="cx">         int addr = kcontrol-&gt;private_value;
</span><del>-        //unsigned long flags;
</del><span class="cx"> 
</span><del>-        if(in_irq())
-                printk(&quot;giova: line %d we are in HARDWARE IRQ\n&quot;, __LINE__);
-        //spin_lock_irq(&amp;dummy-&gt;mixer_lock);
-        //spin_lock_irqsave(&amp;dummy-&gt;mixer_lock, flags);
-        spin_lock_bh(&amp;dummy-&gt;mixer_lock);
</del><ins>+        spin_lock_irq(&amp;dummy-&gt;mixer_lock);
</ins><span class="cx">         ucontrol-&gt;value.integer.value[0] = dummy-&gt;capture_source[addr][0];
</span><span class="cx">         ucontrol-&gt;value.integer.value[1] = dummy-&gt;capture_source[addr][1];
</span><del>-        //spin_unlock_irq(&amp;dummy-&gt;mixer_lock);
-        //spin_unlock_irqrestore(&amp;dummy-&gt;mixer_lock, flags);
-        spin_unlock_bh(&amp;dummy-&gt;mixer_lock);
-//printk(&quot;giova: capsrc_get %d %d\n&quot;, __LINE__, addr);
</del><ins>+        spin_unlock_irq(&amp;dummy-&gt;mixer_lock);
</ins><span class="cx">         return 0;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -737,23 +772,15 @@
</span><span class="cx">         struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
</span><span class="cx">         int change, addr = kcontrol-&gt;private_value;
</span><span class="cx">         int left, right;
</span><del>-        //unsigned long flags;
</del><span class="cx"> 
</span><del>-        if(in_irq())
-                printk(&quot;giova: line %d we are in HARDWARE IRQ\n&quot;, __LINE__);
</del><span class="cx">         left = ucontrol-&gt;value.integer.value[0] &amp; 1;
</span><span class="cx">         right = ucontrol-&gt;value.integer.value[1] &amp; 1;
</span><del>-        //spin_lock_irq(&amp;dummy-&gt;mixer_lock);
-        //spin_lock_irqsave(&amp;dummy-&gt;mixer_lock, flags);
-        spin_lock_bh(&amp;dummy-&gt;mixer_lock);
</del><ins>+        spin_lock_irq(&amp;dummy-&gt;mixer_lock);
</ins><span class="cx">         change = dummy-&gt;capture_source[addr][0] != left &amp;&amp;
</span><span class="cx">                  dummy-&gt;capture_source[addr][1] != right;
</span><span class="cx">         dummy-&gt;capture_source[addr][0] = left;
</span><span class="cx">         dummy-&gt;capture_source[addr][1] = right;
</span><del>-        //spin_unlock_irq(&amp;dummy-&gt;mixer_lock);
-        //spin_unlock_irqrestore(&amp;dummy-&gt;mixer_lock, flags);
-        spin_unlock_bh(&amp;dummy-&gt;mixer_lock);
-//printk(&quot;giova: capsrc_put %d %d\n&quot;, __LINE__, addr);
</del><ins>+        spin_unlock_irq(&amp;dummy-&gt;mixer_lock);
</ins><span class="cx">         return change;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -776,12 +803,10 @@
</span><span class="cx">         unsigned int idx;
</span><span class="cx">         int err;
</span><span class="cx"> 
</span><del>-        //giova if (snd_BUG_ON(!dummy))
-                //giova return -EINVAL;
</del><ins>+        if (snd_BUG_ON(!dummy))
+                return -EINVAL;
</ins><span class="cx">         spin_lock_init(&amp;dummy-&gt;mixer_lock);
</span><span class="cx">         strcpy(card-&gt;mixername, &quot;Dummy Mixer&quot;);
</span><del>-//printk(&quot;giova: new_mixer %d\n&quot;, __LINE__);
-        return 0; //giova no mixer
</del><span class="cx"> 
</span><span class="cx">         for (idx = 0; idx &lt; ARRAY_SIZE(snd_dummy_controls); idx++) {
</span><span class="cx">                 err = snd_ctl_add(card, snd_ctl_new1(&amp;snd_dummy_controls[idx], dummy));
</span><span class="lines">@@ -798,15 +823,10 @@
</span><span class="cx">         int idx, err;
</span><span class="cx">         int dev = devptr-&gt;id;
</span><span class="cx"> 
</span><del>-        card = snd_card_new(index[dev], id[dev], THIS_MODULE,
-                            sizeof(struct snd_dummy));
-        if (card == NULL)
-                return -ENOMEM;
-
-        //giova err = snd_card_create(index[dev], id[dev], THIS_MODULE,
-                              //giova sizeof(struct snd_dummy), &amp;card);
-        //giova if (err &lt; 0)
-                //giova return err;
</del><ins>+        err = snd_card_create(index[dev], id[dev], THIS_MODULE,
+                              sizeof(struct snd_dummy), &amp;card);
+        if (err &lt; 0)
+                return err;
</ins><span class="cx">         dummy = card-&gt;private_data;
</span><span class="cx">         dummy-&gt;card = card;
</span><span class="cx">         for (idx = 0; idx &lt; MAX_PCM_DEVICES &amp;&amp; idx &lt; pcm_devs[dev]; idx++) {
</span><span class="lines">@@ -839,8 +859,6 @@
</span><span class="cx"> 
</span><span class="cx"> static int __devexit snd_dummy_remove(struct platform_device *devptr)
</span><span class="cx"> {
</span><del>-
-        del_timer(&amp;giovatimer);
</del><span class="cx">         snd_card_free(platform_get_drvdata(devptr));
</span><span class="cx">         platform_set_drvdata(devptr, NULL);
</span><span class="cx">         return 0;
</span><span class="lines">@@ -887,6 +905,7 @@
</span><span class="cx">         for (i = 0; i &lt; ARRAY_SIZE(devices); ++i)
</span><span class="cx">                 platform_device_unregister(devices[i]);
</span><span class="cx">         platform_driver_unregister(&amp;snd_dummy_driver);
</span><ins>+        free_fake_buffer();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static int __init alsa_card_dummy_init(void)
</span><span class="lines">@@ -897,31 +916,12 @@
</span><span class="cx">         if (err &lt; 0)
</span><span class="cx">                 return err;
</span><span class="cx"> 
</span><del>-if(!giovastarted){
-giovastarted=1;
-        spin_lock_init(&amp;giovalock);
-
-        spin_lock_bh(&amp;giovalock);
-for(i=0; i&lt;MAX_PCM_SUBSTREAMS;i++){
-
-        if(i &gt; MAX_PCM_SUBSTREAMS || giovaindex &gt; MAX_PCM_SUBSTREAMS){
-                printk(&quot;giova, %s:%d, i=%d, giovaindex=%d \n&quot;, __FILE__, __LINE__, i, giovaindex);
</del><ins>+        err = alloc_fake_buffer();
+        if (err &lt; 0) {
+                platform_driver_unregister(&amp;snd_dummy_driver);
+                return err;
</ins><span class="cx">         }
</span><del>-giovadpcms[i].substream=NULL;
-giovadpcms[i].dpcm=NULL;
-giovadpcms[i].started=0;
-}
-        init_timer(&amp;giovatimer);
-        //giovatimer.data = (unsigned long) dpcm;
-        giovatimer.data = (unsigned long) &amp;giovadpcms;
-        giovatimer.function = snd_card_dummy_pcm_timer_function;
-        giovatimer.expires = (HZ/100) + jiffies;
-        add_timer(&amp;giovatimer);
-printk(&quot;snd-dummy skypiax driver, %s:%d working on a machine with %dHZ kernel\n&quot;, __FILE__, __LINE__, HZ);
-        spin_unlock_bh(&amp;giovalock);
-}
</del><span class="cx"> 
</span><del>-
</del><span class="cx">         cards = 0;
</span><span class="cx">         for (i = 0; i &lt; SNDRV_CARDS; i++) {
</span><span class="cx">                 struct platform_device *device;
</span><span class="lines">@@ -950,7 +950,6 @@
</span><span class="cx"> 
</span><span class="cx"> static void __exit alsa_card_dummy_exit(void)
</span><span class="cx"> {
</span><del>-        del_timer(&amp;giovatimer);
</del><span class="cx">         snd_dummy_unregister_all();
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>