source: GPL/alsa-kernel/pci/emu10k1/timer.c@ 18

Last change on this file since 18 was 18, checked in by vladest, 20 years ago

initial import

File size: 2.9 KB
Line 
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
35static 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
52static 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
64static 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
72static struct _snd_timer_hardware snd_emu10k1_timer_hw = {
73 /*.flags = */SNDRV_TIMER_HW_AUTO,
74 /*.resolution = */20833, /* 1 sample @ 48KHZ = 20.833...us */
75 0, 0,
76 /*.ticks = */1024,
77 NULL, NULL, NULL,
78 /*.start = */snd_emu10k1_timer_start,
79 /*.stop = */snd_emu10k1_timer_stop,
80 NULL,
81 /*.precise_resolution = */snd_emu10k1_timer_precise_resolution
82};
83
84int __devinit snd_emu10k1_timer(emu10k1_t *emu, int device)
85{
86 snd_timer_t *timer = NULL;
87 snd_timer_id_t tid;
88 int err;
89
90 tid.dev_class = SNDRV_TIMER_CLASS_CARD;
91 tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE;
92 tid.card = emu->card->number;
93 tid.device = device;
94 tid.subdevice = 0;
95 if ((err = snd_timer_new(emu->card, "EMU10K1", &tid, &timer)) >= 0) {
96 strcpy(timer->name, "EMU10K1 timer");
97 timer->private_data = emu;
98 timer->hw = snd_emu10k1_timer_hw;
99 }
100 emu->timer = timer;
101 return err;
102}
Note: See TracBrowser for help on using the repository browser.