sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / sound / drivers / pcsp / pcsp.c
blob72e2d0012084730498123aee36ca4d35bb3a2a7e
1 /*
2 * PC-Speaker driver for Linux
4 * Copyright (C) 1997-2001 David Woodhouse
5 * Copyright (C) 2001-2008 Stas Sergeev
6 */
8 #include <linux/init.h>
9 #include <linux/module.h>
10 #include <linux/platform_device.h>
11 #include <sound/core.h>
12 #include <sound/initval.h>
13 #include <sound/pcm.h>
14 #include <linux/input.h>
15 #include <linux/delay.h>
16 #include <linux/bitops.h>
17 #include <linux/mm.h>
18 #include "pcsp_input.h"
19 #include "pcsp.h"
21 MODULE_AUTHOR("Stas Sergeev <stsp@users.sourceforge.net>");
22 MODULE_DESCRIPTION("PC-Speaker driver");
23 MODULE_LICENSE("GPL");
24 MODULE_SUPPORTED_DEVICE("{{PC-Speaker, pcsp}}");
25 MODULE_ALIAS("platform:pcspkr");
27 static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
28 static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
29 static bool enable = SNDRV_DEFAULT_ENABLE1; /* Enable this card */
30 static bool nopcm; /* Disable PCM capability of the driver */
32 module_param(index, int, 0444);
33 MODULE_PARM_DESC(index, "Index value for pcsp soundcard.");
34 module_param(id, charp, 0444);
35 MODULE_PARM_DESC(id, "ID string for pcsp soundcard.");
36 module_param(enable, bool, 0444);
37 MODULE_PARM_DESC(enable, "Enable PC-Speaker sound.");
38 module_param(nopcm, bool, 0444);
39 MODULE_PARM_DESC(nopcm, "Disable PC-Speaker PCM sound. Only beeps remain.");
41 struct snd_pcsp pcsp_chip;
43 static int snd_pcsp_create(struct snd_card *card)
45 static struct snd_device_ops ops = { };
46 unsigned int resolution = hrtimer_resolution;
47 int err, div, min_div, order;
49 if (!nopcm) {
50 if (resolution > PCSP_MAX_PERIOD_NS) {
51 printk(KERN_ERR "PCSP: Timer resolution is not sufficient "
52 "(%unS)\n", resolution);
53 printk(KERN_ERR "PCSP: Make sure you have HPET and ACPI "
54 "enabled.\n");
55 printk(KERN_ERR "PCSP: Turned into nopcm mode.\n");
56 nopcm = 1;
60 if (loops_per_jiffy >= PCSP_MIN_LPJ && resolution <= PCSP_MIN_PERIOD_NS)
61 min_div = MIN_DIV;
62 else
63 min_div = MAX_DIV;
64 #if PCSP_DEBUG
65 printk(KERN_DEBUG "PCSP: lpj=%li, min_div=%i, res=%u\n",
66 loops_per_jiffy, min_div, resolution);
67 #endif
69 div = MAX_DIV / min_div;
70 order = fls(div) - 1;
72 pcsp_chip.max_treble = min(order, PCSP_MAX_TREBLE);
73 pcsp_chip.treble = min(pcsp_chip.max_treble, PCSP_DEFAULT_TREBLE);
74 pcsp_chip.playback_ptr = 0;
75 pcsp_chip.period_ptr = 0;
76 atomic_set(&pcsp_chip.timer_active, 0);
77 pcsp_chip.enable = 1;
78 pcsp_chip.pcspkr = 1;
80 spin_lock_init(&pcsp_chip.substream_lock);
82 pcsp_chip.card = card;
83 pcsp_chip.port = 0x61;
84 pcsp_chip.irq = -1;
85 pcsp_chip.dma = -1;
87 /* Register device */
88 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, &pcsp_chip, &ops);
89 if (err < 0)
90 return err;
92 return 0;
95 static int snd_card_pcsp_probe(int devnum, struct device *dev)
97 struct snd_card *card;
98 int err;
100 if (devnum != 0)
101 return -EINVAL;
103 hrtimer_init(&pcsp_chip.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
104 pcsp_chip.timer.function = pcsp_do_timer;
106 err = snd_card_new(dev, index, id, THIS_MODULE, 0, &card);
107 if (err < 0)
108 return err;
110 err = snd_pcsp_create(card);
111 if (err < 0) {
112 snd_card_free(card);
113 return err;
115 if (!nopcm) {
116 err = snd_pcsp_new_pcm(&pcsp_chip);
117 if (err < 0) {
118 snd_card_free(card);
119 return err;
122 err = snd_pcsp_new_mixer(&pcsp_chip, nopcm);
123 if (err < 0) {
124 snd_card_free(card);
125 return err;
128 strcpy(card->driver, "PC-Speaker");
129 strcpy(card->shortname, "pcsp");
130 sprintf(card->longname, "Internal PC-Speaker at port 0x%x",
131 pcsp_chip.port);
133 err = snd_card_register(card);
134 if (err < 0) {
135 snd_card_free(card);
136 return err;
139 return 0;
142 static int alsa_card_pcsp_init(struct device *dev)
144 int err;
146 err = snd_card_pcsp_probe(0, dev);
147 if (err) {
148 printk(KERN_ERR "PC-Speaker initialization failed.\n");
149 return err;
152 /* Well, CONFIG_DEBUG_PAGEALLOC makes the sound horrible. Lets alert */
153 if (debug_pagealloc_enabled()) {
154 printk(KERN_WARNING "PCSP: CONFIG_DEBUG_PAGEALLOC is enabled, "
155 "which may make the sound noisy.\n");
158 return 0;
161 static void alsa_card_pcsp_exit(struct snd_pcsp *chip)
163 snd_card_free(chip->card);
166 static int pcsp_probe(struct platform_device *dev)
168 int err;
170 err = pcspkr_input_init(&pcsp_chip.input_dev, &dev->dev);
171 if (err < 0)
172 return err;
174 err = alsa_card_pcsp_init(&dev->dev);
175 if (err < 0) {
176 pcspkr_input_remove(pcsp_chip.input_dev);
177 return err;
180 platform_set_drvdata(dev, &pcsp_chip);
181 return 0;
184 static int pcsp_remove(struct platform_device *dev)
186 struct snd_pcsp *chip = platform_get_drvdata(dev);
187 pcspkr_input_remove(chip->input_dev);
188 alsa_card_pcsp_exit(chip);
189 return 0;
192 static void pcsp_stop_beep(struct snd_pcsp *chip)
194 pcsp_sync_stop(chip);
195 pcspkr_stop_sound();
198 #ifdef CONFIG_PM_SLEEP
199 static int pcsp_suspend(struct device *dev)
201 struct snd_pcsp *chip = dev_get_drvdata(dev);
202 pcsp_stop_beep(chip);
203 snd_pcm_suspend_all(chip->pcm);
204 return 0;
207 static SIMPLE_DEV_PM_OPS(pcsp_pm, pcsp_suspend, NULL);
208 #define PCSP_PM_OPS &pcsp_pm
209 #else
210 #define PCSP_PM_OPS NULL
211 #endif /* CONFIG_PM_SLEEP */
213 static void pcsp_shutdown(struct platform_device *dev)
215 struct snd_pcsp *chip = platform_get_drvdata(dev);
216 pcsp_stop_beep(chip);
219 static struct platform_driver pcsp_platform_driver = {
220 .driver = {
221 .name = "pcspkr",
222 .pm = PCSP_PM_OPS,
224 .probe = pcsp_probe,
225 .remove = pcsp_remove,
226 .shutdown = pcsp_shutdown,
229 static int __init pcsp_init(void)
231 if (!enable)
232 return -ENODEV;
233 return platform_driver_register(&pcsp_platform_driver);
236 static void __exit pcsp_exit(void)
238 platform_driver_unregister(&pcsp_platform_driver);
241 module_init(pcsp_init);
242 module_exit(pcsp_exit);