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 * Routines for control of EMU10K1 chips
14 #include <linux/time.h>
15 #include <sound/core.h>
16 #include <sound/emu10k1.h>
18 static int snd_emu10k1_timer_start(struct snd_timer *timer)
20 struct snd_emu10k1 *emu;
23 emu = snd_timer_chip(timer);
24 delay = timer->sticks - 1;
25 if (delay < 5 ) /* minimum time is 5 ticks */
27 snd_emu10k1_intr_enable(emu, INTE_INTERVALTIMERENB);
28 outw(delay & TIMER_RATE_MASK, emu->port + TIMER);
32 static int snd_emu10k1_timer_stop(struct snd_timer *timer)
34 struct snd_emu10k1 *emu;
36 emu = snd_timer_chip(timer);
37 snd_emu10k1_intr_disable(emu, INTE_INTERVALTIMERENB);
41 static unsigned long snd_emu10k1_timer_c_resolution(struct snd_timer *timer)
43 struct snd_emu10k1 *emu = snd_timer_chip(timer);
45 if (emu->card_capabilities->emu_model &&
46 emu->emu1010.word_clock == 44100)
47 return 22676; // 1 sample @ 44.1 kHz = 22.675736...us
49 return 20833; // 1 sample @ 48 kHz = 20.833...us
52 static int snd_emu10k1_timer_precise_resolution(struct snd_timer *timer,
53 unsigned long *num, unsigned long *den)
55 struct snd_emu10k1 *emu = snd_timer_chip(timer);
58 if (emu->card_capabilities->emu_model)
59 *den = emu->emu1010.word_clock;
65 static const struct snd_timer_hardware snd_emu10k1_timer_hw = {
66 .flags = SNDRV_TIMER_HW_AUTO,
68 .start = snd_emu10k1_timer_start,
69 .stop = snd_emu10k1_timer_stop,
70 .c_resolution = snd_emu10k1_timer_c_resolution,
71 .precise_resolution = snd_emu10k1_timer_precise_resolution,
74 int snd_emu10k1_timer(struct snd_emu10k1 *emu, int device)
76 struct snd_timer *timer = NULL;
77 struct snd_timer_id tid;
80 tid.dev_class = SNDRV_TIMER_CLASS_CARD;
81 tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE;
82 tid.card = emu->card->number;
85 err = snd_timer_new(emu->card, "EMU10K1", &tid, &timer);
87 strcpy(timer->name, "EMU10K1 timer");
88 timer->private_data = emu;
89 timer->hw = snd_emu10k1_timer_hw;