This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / sound / pci / emu10k1 / timer.c
1 /*
2  *  Copyright (c) by Lee Revell <rlrevell@joe-job.com>
3  *  
4  *  Routines for control of EMU10K1 chips
5  *
6  *  Copied from similar code by Clemens Ladisch in the ymfpci driver
7  * 
8  *  BUGS:
9  *    --
10  *
11  *  TODO:
12  *    --
13  *
14  *   This program is free software; you can redistribute it and/or modify
15  *   it under the terms of the GNU General Public License as published by
16  *   the Free Software Foundation; either version 2 of the License, or
17  *   (at your option) any later version.
18  *
19  *   This program is distributed in the hope that it will be useful,
20  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
21  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  *   GNU General Public License for more details.
23  *
24  *   You should have received a copy of the GNU General Public License
25  *   along with this program; if not, write to the Free Software
26  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
27  *
28  */
29
30 #include <sound/driver.h>
31 #include <linux/time.h>
32 #include <sound/core.h>
33 #include <sound/emu10k1.h>
34
35 static int snd_emu10k1_timer_start(snd_timer_t *timer)
36 {
37         emu10k1_t *emu;
38         unsigned long flags;
39         unsigned int delay;
40
41         emu = snd_timer_chip(timer);
42         delay = timer->sticks - 1;
43         if (delay < 5 ) /* minimum time is 5 ticks */
44                 delay = 5;
45         spin_lock_irqsave(&emu->reg_lock, flags);
46         snd_emu10k1_intr_enable(emu, INTE_INTERVALTIMERENB);
47         outw(delay & TIMER_RATE_MASK, emu->port + TIMER);
48         spin_unlock_irqrestore(&emu->reg_lock, flags);
49         return 0;
50 }
51
52 static int snd_emu10k1_timer_stop(snd_timer_t *timer)
53 {
54         emu10k1_t *emu;
55         unsigned long flags;
56
57         emu = snd_timer_chip(timer);
58         spin_lock_irqsave(&emu->reg_lock, flags);
59         snd_emu10k1_intr_disable(emu, INTE_INTERVALTIMERENB);
60         spin_unlock_irqrestore(&emu->reg_lock, flags);
61         return 0;
62 }
63
64 static int snd_emu10k1_timer_precise_resolution(snd_timer_t *timer,
65                                                unsigned long *num, unsigned long *den)
66 {
67         *num = 1;
68         *den = 48000;
69         return 0;
70 }
71
72 static struct _snd_timer_hardware snd_emu10k1_timer_hw = {
73         .flags = SNDRV_TIMER_HW_AUTO,
74         .resolution = 20833, /* 1 sample @ 48KHZ = 20.833...us */
75         .ticks = 1024,
76         .start = snd_emu10k1_timer_start,
77         .stop = snd_emu10k1_timer_stop,
78         .precise_resolution = snd_emu10k1_timer_precise_resolution,
79 };
80
81 int __devinit snd_emu10k1_timer(emu10k1_t *emu, int device)
82 {
83         snd_timer_t *timer = NULL;
84         snd_timer_id_t tid;
85         int err;
86
87         tid.dev_class = SNDRV_TIMER_CLASS_CARD;
88         tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE;
89         tid.card = emu->card->number;
90         tid.device = device;
91         tid.subdevice = 0;
92         if ((err = snd_timer_new(emu->card, "EMU10K1", &tid, &timer)) >= 0) {
93                 strcpy(timer->name, "EMU10K1 timer");
94                 timer->private_data = emu;
95                 timer->hw = snd_emu10k1_timer_hw;
96         }
97         emu->timer = timer;
98         return err;
99 }