1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) by Lee Revell <rlrevell@joe-job.com>
4 * Clemens Ladisch <clemens@ladisch.de>
5 * Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
7 * Routines for control of EMU10K1 chips
10 #include <linux/time.h>
11 #include <sound/core.h>
12 #include <sound/emu10k1.h>
14 static int snd_emu10k1_timer_start(struct snd_timer *timer)
16 struct snd_emu10k1 *emu;
19 emu = snd_timer_chip(timer);
20 delay = timer->sticks - 1;
21 if (delay < 5 ) /* minimum time is 5 ticks */
23 snd_emu10k1_intr_enable(emu, INTE_INTERVALTIMERENB);
24 outw(delay & TIMER_RATE_MASK, emu->port + TIMER);
28 static int snd_emu10k1_timer_stop(struct snd_timer *timer)
30 struct snd_emu10k1 *emu;
32 emu = snd_timer_chip(timer);
33 snd_emu10k1_intr_disable(emu, INTE_INTERVALTIMERENB);
37 static unsigned long snd_emu10k1_timer_c_resolution(struct snd_timer *timer)
39 struct snd_emu10k1 *emu = snd_timer_chip(timer);
41 if (emu->card_capabilities->emu_model &&
42 emu->emu1010.word_clock == 44100)
43 return 22676; // 1 sample @ 44.1 kHz = 22.675736...us
45 return 20833; // 1 sample @ 48 kHz = 20.833...us
48 static int snd_emu10k1_timer_precise_resolution(struct snd_timer *timer,
49 unsigned long *num, unsigned long *den)
51 struct snd_emu10k1 *emu = snd_timer_chip(timer);
54 if (emu->card_capabilities->emu_model)
55 *den = emu->emu1010.word_clock;
61 static const struct snd_timer_hardware snd_emu10k1_timer_hw = {
62 .flags = SNDRV_TIMER_HW_AUTO,
64 .start = snd_emu10k1_timer_start,
65 .stop = snd_emu10k1_timer_stop,
66 .c_resolution = snd_emu10k1_timer_c_resolution,
67 .precise_resolution = snd_emu10k1_timer_precise_resolution,
70 int snd_emu10k1_timer(struct snd_emu10k1 *emu, int device)
72 struct snd_timer *timer = NULL;
73 struct snd_timer_id tid;
76 tid.dev_class = SNDRV_TIMER_CLASS_CARD;
77 tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE;
78 tid.card = emu->card->number;
81 err = snd_timer_new(emu->card, "EMU10K1", &tid, &timer);
83 strcpy(timer->name, "EMU10K1 timer");
84 timer->private_data = emu;
85 timer->hw = snd_emu10k1_timer_hw;