hv: remove unused LOWORD and HIWORD macros from hyperv.h
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / sound / core / rtctimer.c
blobe85e72baff9e8535c9cbd7a56ba0e4d65ddd1ac1
1 /*
2 * RTC based high-frequency timer
4 * Copyright (C) 2000 Takashi Iwai
5 * based on rtctimer.c by Steve Ratcliffe
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <linux/init.h>
24 #include <linux/interrupt.h>
25 #include <linux/module.h>
26 #include <linux/log2.h>
27 #include <sound/core.h>
28 #include <sound/timer.h>
30 #if defined(CONFIG_RTC) || defined(CONFIG_RTC_MODULE)
32 #include <linux/mc146818rtc.h>
34 #define RTC_FREQ 1024 /* default frequency */
35 #define NANO_SEC 1000000000L /* 10^9 in sec */
38 * prototypes
40 static int rtctimer_open(struct snd_timer *t);
41 static int rtctimer_close(struct snd_timer *t);
42 static int rtctimer_start(struct snd_timer *t);
43 static int rtctimer_stop(struct snd_timer *t);
47 * The hardware dependent description for this timer.
49 static struct snd_timer_hardware rtc_hw = {
50 .flags = SNDRV_TIMER_HW_AUTO |
51 SNDRV_TIMER_HW_FIRST |
52 SNDRV_TIMER_HW_TASKLET,
53 .ticks = 100000000L, /* FIXME: XXX */
54 .open = rtctimer_open,
55 .close = rtctimer_close,
56 .start = rtctimer_start,
57 .stop = rtctimer_stop,
60 static int rtctimer_freq = RTC_FREQ; /* frequency */
61 static struct snd_timer *rtctimer;
62 static struct tasklet_struct rtc_tasklet;
63 static rtc_task_t rtc_task;
66 static int
67 rtctimer_open(struct snd_timer *t)
69 int err;
71 err = rtc_register(&rtc_task);
72 if (err < 0)
73 return err;
74 t->private_data = &rtc_task;
75 return 0;
78 static int
79 rtctimer_close(struct snd_timer *t)
81 rtc_task_t *rtc = t->private_data;
82 if (rtc) {
83 rtc_unregister(rtc);
84 tasklet_kill(&rtc_tasklet);
85 t->private_data = NULL;
87 return 0;
90 static int
91 rtctimer_start(struct snd_timer *timer)
93 rtc_task_t *rtc = timer->private_data;
94 if (snd_BUG_ON(!rtc))
95 return -EINVAL;
96 rtc_control(rtc, RTC_IRQP_SET, rtctimer_freq);
97 rtc_control(rtc, RTC_PIE_ON, 0);
98 return 0;
101 static int
102 rtctimer_stop(struct snd_timer *timer)
104 rtc_task_t *rtc = timer->private_data;
105 if (snd_BUG_ON(!rtc))
106 return -EINVAL;
107 rtc_control(rtc, RTC_PIE_OFF, 0);
108 return 0;
111 static void rtctimer_tasklet(unsigned long data)
113 snd_timer_interrupt((struct snd_timer *)data, 1);
117 * interrupt
119 static void rtctimer_interrupt(void *private_data)
121 tasklet_schedule(private_data);
126 * ENTRY functions
128 static int __init rtctimer_init(void)
130 int err;
131 struct snd_timer *timer;
133 if (rtctimer_freq < 2 || rtctimer_freq > 8192 ||
134 !is_power_of_2(rtctimer_freq)) {
135 snd_printk(KERN_ERR "rtctimer: invalid frequency %d\n",
136 rtctimer_freq);
137 return -EINVAL;
140 /* Create a new timer and set up the fields */
141 err = snd_timer_global_new("rtc", SNDRV_TIMER_GLOBAL_RTC, &timer);
142 if (err < 0)
143 return err;
145 timer->module = THIS_MODULE;
146 strcpy(timer->name, "RTC timer");
147 timer->hw = rtc_hw;
148 timer->hw.resolution = NANO_SEC / rtctimer_freq;
150 tasklet_init(&rtc_tasklet, rtctimer_tasklet, (unsigned long)timer);
152 /* set up RTC callback */
153 rtc_task.func = rtctimer_interrupt;
154 rtc_task.private_data = &rtc_tasklet;
156 err = snd_timer_global_register(timer);
157 if (err < 0) {
158 snd_timer_global_free(timer);
159 return err;
161 rtctimer = timer; /* remember this */
163 return 0;
166 static void __exit rtctimer_exit(void)
168 if (rtctimer) {
169 snd_timer_global_free(rtctimer);
170 rtctimer = NULL;
176 * exported stuff
178 module_init(rtctimer_init)
179 module_exit(rtctimer_exit)
181 module_param(rtctimer_freq, int, 0444);
182 MODULE_PARM_DESC(rtctimer_freq, "timer frequency in Hz");
184 MODULE_LICENSE("GPL");
186 MODULE_ALIAS("snd-timer-" __stringify(SNDRV_TIMER_GLOBAL_RTC));
188 #endif /* CONFIG_RTC || CONFIG_RTC_MODULE */