2 * Copyright (c) by Lee Revell <rlrevell@joe-job.com>
4 * Routines for control of EMU10K1 chips
6 * Copied from similar code by Clemens Ladisch in the ymfpci driver
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.
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.
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
30 #include <sound/driver.h>
31 #include <linux/time.h>
32 #include <sound/core.h>
33 #include <sound/emu10k1.h>
35 static int snd_emu10k1_timer_start(snd_timer_t *timer)
41 emu = snd_timer_chip(timer);
42 delay = timer->sticks - 1;
43 if (delay < 5 ) /* minimum time is 5 ticks */
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);
52 static int snd_emu10k1_timer_stop(snd_timer_t *timer)
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);
64 static int snd_emu10k1_timer_precise_resolution(snd_timer_t *timer,
65 unsigned long *num, unsigned long *den)
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 */
76 .start = snd_emu10k1_timer_start,
77 .stop = snd_emu10k1_timer_stop,
78 .precise_resolution = snd_emu10k1_timer_precise_resolution,
81 int __devinit snd_emu10k1_timer(emu10k1_t *emu, int device)
83 snd_timer_t *timer = NULL;
87 tid.dev_class = SNDRV_TIMER_CLASS_CARD;
88 tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE;
89 tid.card = emu->card->number;
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;