ALSA: Add new TLV types for dBwith min/max
[safe/jmp/linux-2.6] / sound / core / rtctimer.c
index 412dd62..0851cd1 100644 (file)
  *
  */
 
-#include <sound/driver.h>
 #include <linux/init.h>
-#include <linux/time.h>
-#include <linux/threads.h>
 #include <linux/interrupt.h>
 #include <linux/moduleparam.h>
+#include <linux/log2.h>
 #include <sound/core.h>
 #include <sound/timer.h>
-#include <sound/info.h>
 
 #if defined(CONFIG_RTC) || defined(CONFIG_RTC_MODULE)
 
@@ -50,7 +47,9 @@ static int rtctimer_stop(struct snd_timer *t);
  * The hardware dependent description for this timer.
  */
 static struct snd_timer_hardware rtc_hw = {
-       .flags =        SNDRV_TIMER_HW_FIRST|SNDRV_TIMER_HW_AUTO,
+       .flags =        SNDRV_TIMER_HW_AUTO |
+                       SNDRV_TIMER_HW_FIRST |
+                       SNDRV_TIMER_HW_TASKLET,
        .ticks =        100000000L,             /* FIXME: XXX */
        .open =         rtctimer_open,
        .close =        rtctimer_close,
@@ -60,6 +59,7 @@ static struct snd_timer_hardware rtc_hw = {
 
 static int rtctimer_freq = RTC_FREQ;           /* frequency */
 static struct snd_timer *rtctimer;
+static struct tasklet_struct rtc_tasklet;
 static rtc_task_t rtc_task;
 
 
@@ -81,6 +81,7 @@ rtctimer_close(struct snd_timer *t)
        rtc_task_t *rtc = t->private_data;
        if (rtc) {
                rtc_unregister(rtc);
+               tasklet_kill(&rtc_tasklet);
                t->private_data = NULL;
        }
        return 0;
@@ -90,7 +91,8 @@ static int
 rtctimer_start(struct snd_timer *timer)
 {
        rtc_task_t *rtc = timer->private_data;
-       snd_assert(rtc != NULL, return -EINVAL);
+       if (snd_BUG_ON(!rtc))
+               return -EINVAL;
        rtc_control(rtc, RTC_IRQP_SET, rtctimer_freq);
        rtc_control(rtc, RTC_PIE_ON, 0);
        return 0;
@@ -100,17 +102,23 @@ static int
 rtctimer_stop(struct snd_timer *timer)
 {
        rtc_task_t *rtc = timer->private_data;
-       snd_assert(rtc != NULL, return -EINVAL);
+       if (snd_BUG_ON(!rtc))
+               return -EINVAL;
        rtc_control(rtc, RTC_PIE_OFF, 0);
        return 0;
 }
 
+static void rtctimer_tasklet(unsigned long data)
+{
+       snd_timer_interrupt((struct snd_timer *)data, 1);
+}
+
 /*
  * interrupt
  */
 static void rtctimer_interrupt(void *private_data)
 {
-       snd_timer_interrupt(private_data, 1);
+       tasklet_schedule(private_data);
 }
 
 
@@ -123,7 +131,7 @@ static int __init rtctimer_init(void)
        struct snd_timer *timer;
 
        if (rtctimer_freq < 2 || rtctimer_freq > 8192 ||
-           (rtctimer_freq & (rtctimer_freq - 1)) != 0) {
+           !is_power_of_2(rtctimer_freq)) {
                snd_printk(KERN_ERR "rtctimer: invalid frequency %d\n",
                           rtctimer_freq);
                return -EINVAL;
@@ -139,9 +147,11 @@ static int __init rtctimer_init(void)
        timer->hw = rtc_hw;
        timer->hw.resolution = NANO_SEC / rtctimer_freq;
 
+       tasklet_init(&rtc_tasklet, rtctimer_tasklet, (unsigned long)timer);
+
        /* set up RTC callback */
        rtc_task.func = rtctimer_interrupt;
-       rtc_task.private_data = timer;
+       rtc_task.private_data = &rtc_tasklet;
 
        err = snd_timer_global_register(timer);
        if (err < 0) {