aboutsummaryrefslogtreecommitdiffstats
path: root/sound/core
diff options
context:
space:
mode:
Diffstat (limited to 'sound/core')
-rw-r--r--sound/core/Kconfig21
-rw-r--r--sound/core/Makefile2
-rw-r--r--sound/core/device.c4
-rw-r--r--sound/core/hrtimer.c155
-rw-r--r--sound/core/jack.c15
-rw-r--r--sound/core/rawmidi.c4
-rw-r--r--sound/core/rtctimer.c2
-rw-r--r--sound/core/seq/seq.c4
-rw-r--r--sound/core/timer.c2
9 files changed, 201 insertions, 8 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/device.c b/sound/core/device.c
index c58d8227254c..a67dfac08c03 100644
--- a/sound/core/device.c
+++ b/sound/core/device.c
@@ -98,7 +98,7 @@ int snd_device_free(struct snd_card *card, void *device_data)
98 kfree(dev); 98 kfree(dev);
99 return 0; 99 return 0;
100 } 100 }
101 snd_printd("device free %p (from %p), not found\n", device_data, 101 snd_printd("device free %p (from %pF), not found\n", device_data,
102 __builtin_return_address(0)); 102 __builtin_return_address(0));
103 return -ENXIO; 103 return -ENXIO;
104} 104}
@@ -135,7 +135,7 @@ int snd_device_disconnect(struct snd_card *card, void *device_data)
135 } 135 }
136 return 0; 136 return 0;
137 } 137 }
138 snd_printd("device disconnect %p (from %p), not found\n", device_data, 138 snd_printd("device disconnect %p (from %pF), not found\n", device_data,
139 __builtin_return_address(0)); 139 __builtin_return_address(0));
140 return -ENXIO; 140 return -ENXIO;
141} 141}
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/jack.c b/sound/core/jack.c
index bd2d9e6b55e9..dd4a12dc09aa 100644
--- a/sound/core/jack.c
+++ b/sound/core/jack.c
@@ -34,6 +34,7 @@ static int snd_jack_dev_free(struct snd_device *device)
34 else 34 else
35 input_free_device(jack->input_dev); 35 input_free_device(jack->input_dev);
36 36
37 kfree(jack->id);
37 kfree(jack); 38 kfree(jack);
38 39
39 return 0; 40 return 0;
@@ -87,7 +88,7 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
87 if (jack == NULL) 88 if (jack == NULL)
88 return -ENOMEM; 89 return -ENOMEM;
89 90
90 jack->id = id; 91 jack->id = kstrdup(id, GFP_KERNEL);
91 92
92 jack->input_dev = input_allocate_device(); 93 jack->input_dev = input_allocate_device();
93 if (jack->input_dev == NULL) { 94 if (jack->input_dev == NULL) {
@@ -102,9 +103,15 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
102 if (type & SND_JACK_HEADPHONE) 103 if (type & SND_JACK_HEADPHONE)
103 input_set_capability(jack->input_dev, EV_SW, 104 input_set_capability(jack->input_dev, EV_SW,
104 SW_HEADPHONE_INSERT); 105 SW_HEADPHONE_INSERT);
106 if (type & SND_JACK_LINEOUT)
107 input_set_capability(jack->input_dev, EV_SW,
108 SW_LINEOUT_INSERT);
105 if (type & SND_JACK_MICROPHONE) 109 if (type & SND_JACK_MICROPHONE)
106 input_set_capability(jack->input_dev, EV_SW, 110 input_set_capability(jack->input_dev, EV_SW,
107 SW_MICROPHONE_INSERT); 111 SW_MICROPHONE_INSERT);
112 if (type & SND_JACK_MECHANICAL)
113 input_set_capability(jack->input_dev, EV_SW,
114 SW_JACK_PHYSICAL_INSERT);
108 115
109 err = snd_device_new(card, SNDRV_DEV_JACK, jack, &ops); 116 err = snd_device_new(card, SNDRV_DEV_JACK, jack, &ops);
110 if (err < 0) 117 if (err < 0)
@@ -153,9 +160,15 @@ void snd_jack_report(struct snd_jack *jack, int status)
153 if (jack->type & SND_JACK_HEADPHONE) 160 if (jack->type & SND_JACK_HEADPHONE)
154 input_report_switch(jack->input_dev, SW_HEADPHONE_INSERT, 161 input_report_switch(jack->input_dev, SW_HEADPHONE_INSERT,
155 status & SND_JACK_HEADPHONE); 162 status & SND_JACK_HEADPHONE);
163 if (jack->type & SND_JACK_LINEOUT)
164 input_report_switch(jack->input_dev, SW_LINEOUT_INSERT,
165 status & SND_JACK_LINEOUT);
156 if (jack->type & SND_JACK_MICROPHONE) 166 if (jack->type & SND_JACK_MICROPHONE)
157 input_report_switch(jack->input_dev, SW_MICROPHONE_INSERT, 167 input_report_switch(jack->input_dev, SW_MICROPHONE_INSERT,
158 status & SND_JACK_MICROPHONE); 168 status & SND_JACK_MICROPHONE);
169 if (jack->type & SND_JACK_MECHANICAL)
170 input_report_switch(jack->input_dev, SW_JACK_PHYSICAL_INSERT,
171 status & SND_JACK_MECHANICAL);
159 172
160 input_sync(jack->input_dev); 173 input_sync(jack->input_dev);
161} 174}
diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c
index 39672f68ce5d..002777ba336a 100644
--- a/sound/core/rawmidi.c
+++ b/sound/core/rawmidi.c
@@ -151,7 +151,7 @@ static inline void snd_rawmidi_output_trigger(struct snd_rawmidi_substream *subs
151 if (!substream->opened) 151 if (!substream->opened)
152 return; 152 return;
153 if (up) { 153 if (up) {
154 tasklet_hi_schedule(&substream->runtime->tasklet); 154 tasklet_schedule(&substream->runtime->tasklet);
155 } else { 155 } else {
156 tasklet_kill(&substream->runtime->tasklet); 156 tasklet_kill(&substream->runtime->tasklet);
157 substream->ops->trigger(substream, 0); 157 substream->ops->trigger(substream, 0);
@@ -908,7 +908,7 @@ int snd_rawmidi_receive(struct snd_rawmidi_substream *substream,
908 } 908 }
909 if (result > 0) { 909 if (result > 0) {
910 if (runtime->event) 910 if (runtime->event)
911 tasklet_hi_schedule(&runtime->tasklet); 911 tasklet_schedule(&runtime->tasklet);
912 else if (snd_rawmidi_ready(substream)) 912 else if (snd_rawmidi_ready(substream))
913 wake_up(&runtime->sleep); 913 wake_up(&runtime->sleep);
914 } 914 }
diff --git a/sound/core/rtctimer.c b/sound/core/rtctimer.c
index 51e64e30dd3b..0851cd13e303 100644
--- a/sound/core/rtctimer.c
+++ b/sound/core/rtctimer.c
@@ -118,7 +118,7 @@ static void rtctimer_tasklet(unsigned long data)
118 */ 118 */
119static void rtctimer_interrupt(void *private_data) 119static void rtctimer_interrupt(void *private_data)
120{ 120{
121 tasklet_hi_schedule(private_data); 121 tasklet_schedule(private_data);
122} 122}
123 123
124 124
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
diff --git a/sound/core/timer.c b/sound/core/timer.c
index c584408c9f17..796532081e81 100644
--- a/sound/core/timer.c
+++ b/sound/core/timer.c
@@ -743,7 +743,7 @@ void snd_timer_interrupt(struct snd_timer * timer, unsigned long ticks_left)
743 spin_unlock_irqrestore(&timer->lock, flags); 743 spin_unlock_irqrestore(&timer->lock, flags);
744 744
745 if (use_tasklet) 745 if (use_tasklet)
746 tasklet_hi_schedule(&timer->task_queue); 746 tasklet_schedule(&timer->task_queue);
747} 747}
748 748
749/* 749/*