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