forked from neo01124/omap3-pwm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pwmsp.c
201 lines (168 loc) · 4.57 KB
/
pwmsp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/moduleparam.h>
#include <linux/platform_device.h>
#include <sound/core.h>
#include <sound/initval.h>
#include <sound/pcm.h>
#include <linux/input.h>
#include <linux/delay.h>
#include <asm/bitops.h>
#include "pwmsp.h"
MODULE_DESCRIPTION("PWM-Speaker driver");
MODULE_LICENSE("GPL");
MODULE_SUPPORTED_DEVICE("{{PWM-Speaker, pwmsp}}");
MODULE_ALIAS("platform:pwmspkr");
static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
static int enable = SNDRV_DEFAULT_ENABLE1; /* Enable this card */
module_param(index, int, 0444);
MODULE_PARM_DESC(index, "Index value for pwmsp soundcard.");
module_param(id, charp, 0444);
MODULE_PARM_DESC(id, "ID string for pwmsp soundcard.");
module_param(enable, bool, 0444);
MODULE_PARM_DESC(enable, "Enable PWM-Speaker sound.");
struct snd_pwmsp pwmsp_chip;
static int __devinit snd_pwmsp_create(struct snd_card *card)
{
static struct snd_device_ops ops = { };
// struct timespec tp;
int err;
#if PWMSP_DEBUG
printk("pwmsp: lpj=%li, min_div=%i, res=%li\n",
loops_per_jiffy, min_div, tp.tv_nsec);
#endif
pwmsp_chip.max_treble = PWMSP_MAX_TREBLE; //min(order, PWMSP_MAX_TREBLE);
pwmsp_chip.treble = min(pwmsp_chip.max_treble, PWMSP_DEFAULT_TREBLE);
pwmsp_chip.playback_ptr = 0;
pwmsp_chip.period_ptr = 0;
atomic_set(&pwmsp_chip.active, 0);
pwmsp_chip.enable = 1;
spin_lock_init(&pwmsp_chip.substream_lock);
pwmsp_chip.card = card;
pwmsp_chip.port = 0x61; //what?
pwmsp_chip.irq = -1;
pwmsp_chip.dma = -1;
/* Register device */
err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, &pwmsp_chip, &ops);
if (err < 0)
return err;
return 0;
}
static int __devinit snd_card_pwmsp_probe(int devnum, struct device *dev)
{
struct snd_card *card;
int err;
if (devnum != 0)
return -EINVAL;
snd_card_create(index, id, THIS_MODULE, 0,&card);
if (!card)
return -ENOMEM;
err = snd_pwmsp_create(card);
if (err < 0) {
snd_card_free(card);
return err;
}
err = snd_pwmsp_new_pcm(&pwmsp_chip);
if (err < 0) {
snd_card_free(card);
return err;
}
snd_card_set_dev(pwmsp_chip.card, dev);
strcpy(card->driver, "PWM-Speaker");
strcpy(card->shortname, "pwmsp");
sprintf(card->longname, "Internal PWM-Speaker at port 0x%x",
pwmsp_chip.port);
err = snd_card_register(card);
if (err < 0) {
snd_card_free(card);
return err;
}
return 0;
}
static int __devinit alsa_card_pwmsp_init(struct device *dev)
{
int err;
err = snd_card_pwmsp_probe(0, dev);
if (err) {
printk(KERN_ERR "PWM-Speaker initialization failed.\n");
return err;
}
#ifdef CONFIG_DEBUG_PAGEALLOC
/* Well, CONFIG_DEBUG_PAGEALLOC makes the sound horrible. Lets alert */
printk(KERN_WARNING "PWMSP: CONFIG_DEBUG_PAGEALLOC is enabled, "
"which may make the sound noisy.\n");
#endif
return 0;
}
static void __devexit alsa_card_pwmsp_exit(struct snd_pwmsp *chip)
{
snd_card_free(chip->card);
}
static int __devinit pwmsp_probe(struct platform_device *dev)
{
int err;
/*err = pwmspkr_input_init(&pwmsp_chip.input_dev, &dev->dev);
if (err < 0)
return err; */
err = alsa_card_pwmsp_init(&dev->dev);
/*if (err < 0) {
pwmspkr_input_remove(pwmsp_chip.input_dev);
return err;
} */
platform_set_drvdata(dev, &pwmsp_chip);
return 0;
}
static int __devexit pwmsp_remove(struct platform_device *dev)
{
struct snd_pwmsp *chip = platform_get_drvdata(dev);
alsa_card_pwmsp_exit(chip);
// pwmspkr_input_remove(chip->input_dev);
platform_set_drvdata(dev, NULL);
return 0;
}
static void pwmsp_stop_beep(struct snd_pwmsp *chip)
{
pwmsp_sync_stop(chip);
//pwmspkr_stop_sound();
}
#ifdef CONFIG_PM
static int pwmsp_suspend(struct platform_device *dev, pm_message_t state)
{
struct snd_pwmsp *chip = platform_get_drvdata(dev);
pwmsp_stop_beep(chip);
snd_pcm_suspend_all(chip->pcm);
return 0;
}
#else
#define pwmsp_suspend NULL
#endif /* CONFIG_PM */
static void pwmsp_shutdown(struct platform_device *dev)
{
struct snd_pwmsp *chip = platform_get_drvdata(dev);
pwmsp_stop_beep(chip);
}
static struct platform_driver pwmsp_platform_driver = {
.driver = {
.name = "pwmspkr",
.owner = THIS_MODULE,
},
.probe = pwmsp_probe,
.remove = __devexit_p(pwmsp_remove),
.suspend = pwmsp_suspend,
.shutdown = pwmsp_shutdown,
};
static int __init pwmsp_init(void)
{
printk(KERN_ALERT "189 \n");
if (!enable)
return -ENODEV;
return platform_driver_register(&pwmsp_platform_driver);
printk(KERN_ALERT "193 \n");
}
static void __exit pwmsp_exit(void)
{
platform_driver_unregister(&pwmsp_platform_driver);
}
module_init(pwmsp_init);
module_exit(pwmsp_exit);