aboutsummaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2008-12-25 05:40:32 -0500
committerTakashi Iwai <tiwai@suse.de>2008-12-25 05:40:32 -0500
commit9649745c8670eacc671e9cff72c5c1e346e13036 (patch)
tree4c2db2aa5e524293269dfea5e4bd15bdea81ee6b /sound
parenta9c3c7e04b9a744eafb2e87c770e7300bbffa375 (diff)
parent5e03c54eeb016cf1b066e9e48d30116814ca2459 (diff)
Merge branch 'topic/snd-hrtimer' into to-push
Diffstat (limited to 'sound')
-rw-r--r--sound/core/Kconfig21
-rw-r--r--sound/core/Makefile2
-rw-r--r--sound/core/hrtimer.c155
-rw-r--r--sound/core/seq/seq.c4
4 files changed, 181 insertions, 1 deletions
diff --git a/sound/core/Kconfig b/sound/core/Kconfig
index 66348c92f88d..7bbdda041a99 100644
--- a/sound/core/Kconfig
+++ b/sound/core/Kconfig
@@ -95,6 +95,26 @@ config SND_SEQUENCER_OSS
95 this will be compiled as a module. The module will be called 95 this will be compiled as a module. The module will be called
96 snd-seq-oss. 96 snd-seq-oss.
97 97
98config SND_HRTIMER
99 tristate "HR-timer backend support"
100 depends on HIGH_RES_TIMERS
101 select SND_TIMER
102 help
103 Say Y here to enable HR-timer backend for ALSA timer. ALSA uses
104 the hrtimer as a precise timing source. The ALSA sequencer code
105 also can use this timing source.
106
107 To compile this driver as a module, choose M here: the module
108 will be called snd-hrtimer.
109
110config SND_SEQ_HRTIMER_DEFAULT
111 bool "Use HR-timer as default sequencer timer"
112 depends on SND_HRTIMER && SND_SEQUENCER
113 default y
114 help
115 Say Y here to use the HR-timer backend as the default sequencer
116 timer.
117
98config SND_RTCTIMER 118config SND_RTCTIMER
99 tristate "RTC Timer support" 119 tristate "RTC Timer support"
100 depends on RTC 120 depends on RTC
@@ -114,6 +134,7 @@ config SND_RTCTIMER
114config SND_SEQ_RTCTIMER_DEFAULT 134config SND_SEQ_RTCTIMER_DEFAULT
115 bool "Use RTC as default sequencer timer" 135 bool "Use RTC as default sequencer timer"
116 depends on SND_RTCTIMER && SND_SEQUENCER 136 depends on SND_RTCTIMER && SND_SEQUENCER
137 depends on !SND_SEQ_HRTIMER_DEFAULT
117 default y 138 default y
118 help 139 help
119 Say Y here to use the RTC timer as the default sequencer 140 Say Y here to use the RTC timer as the default sequencer
diff --git a/sound/core/Makefile b/sound/core/Makefile
index d57125a5687d..4229052e7b91 100644
--- a/sound/core/Makefile
+++ b/sound/core/Makefile
@@ -17,12 +17,14 @@ snd-page-alloc-$(CONFIG_HAS_DMA) += sgbuf.o
17 17
18snd-rawmidi-objs := rawmidi.o 18snd-rawmidi-objs := rawmidi.o
19snd-timer-objs := timer.o 19snd-timer-objs := timer.o
20snd-hrtimer-objs := hrtimer.o
20snd-rtctimer-objs := rtctimer.o 21snd-rtctimer-objs := rtctimer.o
21snd-hwdep-objs := hwdep.o 22snd-hwdep-objs := hwdep.o
22 23
23obj-$(CONFIG_SND) += snd.o 24obj-$(CONFIG_SND) += snd.o
24obj-$(CONFIG_SND_HWDEP) += snd-hwdep.o 25obj-$(CONFIG_SND_HWDEP) += snd-hwdep.o
25obj-$(CONFIG_SND_TIMER) += snd-timer.o 26obj-$(CONFIG_SND_TIMER) += snd-timer.o
27obj-$(CONFIG_SND_HRTIMER) += snd-hrtimer.o
26obj-$(CONFIG_SND_RTCTIMER) += snd-rtctimer.o 28obj-$(CONFIG_SND_RTCTIMER) += snd-rtctimer.o
27obj-$(CONFIG_SND_PCM) += snd-pcm.o snd-page-alloc.o 29obj-$(CONFIG_SND_PCM) += snd-pcm.o snd-page-alloc.o
28obj-$(CONFIG_SND_RAWMIDI) += snd-rawmidi.o 30obj-$(CONFIG_SND_RAWMIDI) += snd-rawmidi.o
diff --git a/sound/core/hrtimer.c b/sound/core/hrtimer.c
new file mode 100644
index 000000000000..c1d285921f80
--- /dev/null
+++ b/sound/core/hrtimer.c
@@ -0,0 +1,155 @@
1/*
2 * ALSA timer back-end using hrtimer
3 * Copyright (C) 2008 Takashi Iwai
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 */
20
21#include <linux/init.h>
22#include <linux/module.h>
23#include <linux/moduleparam.h>
24#include <linux/hrtimer.h>
25#include <sound/core.h>
26#include <sound/timer.h>
27
28MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
29MODULE_DESCRIPTION("ALSA hrtimer backend");
30MODULE_LICENSE("GPL");
31
32MODULE_ALIAS("snd-timer-" __stringify(SNDRV_TIMER_GLOBAL_HRTIMER));
33
34#define NANO_SEC 1000000000UL /* 10^9 in sec */
35static unsigned int resolution;
36
37struct snd_hrtimer {
38 struct snd_timer *timer;
39 struct hrtimer hrt;
40};
41
42static enum hrtimer_restart snd_hrtimer_callback(struct hrtimer *hrt)
43{
44 struct snd_hrtimer *stime = container_of(hrt, struct snd_hrtimer, hrt);
45 struct snd_timer *t = stime->timer;
46 hrtimer_forward_now(hrt, ns_to_ktime(t->sticks * resolution));
47 snd_timer_interrupt(stime->timer, t->sticks);
48 return HRTIMER_RESTART;
49}
50
51static int snd_hrtimer_open(struct snd_timer *t)
52{
53 struct snd_hrtimer *stime;
54
55 stime = kmalloc(sizeof(*stime), GFP_KERNEL);
56 if (!stime)
57 return -ENOMEM;
58 hrtimer_init(&stime->hrt, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
59 stime->timer = t;
60 stime->hrt.cb_mode = HRTIMER_CB_IRQSAFE_UNLOCKED;
61 stime->hrt.function = snd_hrtimer_callback;
62 t->private_data = stime;
63 return 0;
64}
65
66static int snd_hrtimer_close(struct snd_timer *t)
67{
68 struct snd_hrtimer *stime = t->private_data;
69
70 if (stime) {
71 hrtimer_cancel(&stime->hrt);
72 kfree(stime);
73 t->private_data = NULL;
74 }
75 return 0;
76}
77
78static int snd_hrtimer_start(struct snd_timer *t)
79{
80 struct snd_hrtimer *stime = t->private_data;
81
82 hrtimer_start(&stime->hrt, ns_to_ktime(t->sticks * resolution),
83 HRTIMER_MODE_REL);
84 return 0;
85}
86
87static int snd_hrtimer_stop(struct snd_timer *t)
88{
89 struct snd_hrtimer *stime = t->private_data;
90
91 hrtimer_cancel(&stime->hrt);
92 return 0;
93}
94
95static struct snd_timer_hardware hrtimer_hw = {
96 .flags = SNDRV_TIMER_HW_AUTO,
97 .open = snd_hrtimer_open,
98 .close = snd_hrtimer_close,
99 .start = snd_hrtimer_start,
100 .stop = snd_hrtimer_stop,
101};
102
103/*
104 * entry functions
105 */
106
107static struct snd_timer *mytimer;
108
109static int __init snd_hrtimer_init(void)
110{
111 struct snd_timer *timer;
112 struct timespec tp;
113 int err;
114
115 hrtimer_get_res(CLOCK_MONOTONIC, &tp);
116 if (tp.tv_sec > 0 || !tp.tv_nsec) {
117 snd_printk(KERN_ERR
118 "snd-hrtimer: Invalid resolution %u.%09u",
119 (unsigned)tp.tv_sec, (unsigned)tp.tv_nsec);
120 return -EINVAL;
121 }
122 resolution = tp.tv_nsec;
123
124 /* Create a new timer and set up the fields */
125 err = snd_timer_global_new("hrtimer", SNDRV_TIMER_GLOBAL_HRTIMER,
126 &timer);
127 if (err < 0)
128 return err;
129
130 timer->module = THIS_MODULE;
131 strcpy(timer->name, "HR timer");
132 timer->hw = hrtimer_hw;
133 timer->hw.resolution = resolution;
134 timer->hw.ticks = NANO_SEC / resolution;
135
136 err = snd_timer_global_register(timer);
137 if (err < 0) {
138 snd_timer_global_free(timer);
139 return err;
140 }
141 mytimer = timer; /* remember this */
142
143 return 0;
144}
145
146static void __exit snd_hrtimer_exit(void)
147{
148 if (mytimer) {
149 snd_timer_global_free(mytimer);
150 mytimer = NULL;
151 }
152}
153
154module_init(snd_hrtimer_init);
155module_exit(snd_hrtimer_exit);
diff --git a/sound/core/seq/seq.c b/sound/core/seq/seq.c
index ee0f8405ab35..bf09a5ad1865 100644
--- a/sound/core/seq/seq.c
+++ b/sound/core/seq/seq.c
@@ -43,7 +43,9 @@ int seq_default_timer_class = SNDRV_TIMER_CLASS_GLOBAL;
43int seq_default_timer_sclass = SNDRV_TIMER_SCLASS_NONE; 43int seq_default_timer_sclass = SNDRV_TIMER_SCLASS_NONE;
44int seq_default_timer_card = -1; 44int seq_default_timer_card = -1;
45int seq_default_timer_device = 45int seq_default_timer_device =
46#ifdef CONFIG_SND_SEQ_RTCTIMER_DEFAULT 46#ifdef CONFIG_SND_SEQ_HRTIMER_DEFAULT
47 SNDRV_TIMER_GLOBAL_HRTIMER
48#elif defined(CONFIG_SND_SEQ_RTCTIMER_DEFAULT)
47 SNDRV_TIMER_GLOBAL_RTC 49 SNDRV_TIMER_GLOBAL_RTC
48#else 50#else
49 SNDRV_TIMER_GLOBAL_SYSTEM 51 SNDRV_TIMER_GLOBAL_SYSTEM