blob: 6295b2dca785d59533c25268cc80e120094d488a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Takashi Iwaieb4698f2005-11-17 14:50:13 +010033static int snd_emu10k1_timer_start(struct snd_timer *timer)
Linus Torvalds1da177e2005-04-16 15:20:36 -070034{
Takashi Iwaieb4698f2005-11-17 14:50:13 +010035 struct snd_emu10k1 *emu;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 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
Takashi Iwaieb4698f2005-11-17 14:50:13 +010050static int snd_emu10k1_timer_stop(struct snd_timer *timer)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051{
Takashi Iwaieb4698f2005-11-17 14:50:13 +010052 struct snd_emu10k1 *emu;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 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
Takashi Iwaieb4698f2005-11-17 14:50:13 +010062static int snd_emu10k1_timer_precise_resolution(struct snd_timer *timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 unsigned long *num, unsigned long *den)
64{
65 *num = 1;
66 *den = 48000;
67 return 0;
68}
69
Takashi Iwaieb4698f2005-11-17 14:50:13 +010070static struct snd_timer_hardware snd_emu10k1_timer_hw = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 .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
Takashi Iwaieb4698f2005-11-17 14:50:13 +010079int __devinit snd_emu10k1_timer(struct snd_emu10k1 *emu, int device)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080{
Takashi Iwaieb4698f2005-11-17 14:50:13 +010081 struct snd_timer *timer = NULL;
82 struct snd_timer_id tid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 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}