aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sound/ppc/beep.c66
1 files changed, 37 insertions, 29 deletions
diff --git a/sound/ppc/beep.c b/sound/ppc/beep.c
index 31ea7a4c069f..1681ee13efbb 100644
--- a/sound/ppc/beep.c
+++ b/sound/ppc/beep.c
@@ -31,14 +31,14 @@
31#include "pmac.h" 31#include "pmac.h"
32 32
33struct snd_pmac_beep { 33struct snd_pmac_beep {
34 int running; /* boolean */ 34 int running; /* boolean */
35 int volume; /* mixer volume: 0-100 */ 35 int volume; /* mixer volume: 0-100 */
36 int volume_play; /* currently playing volume */ 36 int volume_play; /* currently playing volume */
37 int hz; 37 int hz;
38 int nsamples; 38 int nsamples;
39 short *buf; /* allocated wave buffer */ 39 short *buf; /* allocated wave buffer */
40 dma_addr_t addr; /* physical address of buffer */ 40 dma_addr_t addr; /* physical address of buffer */
41 struct input_dev dev; 41 struct input_dev *dev;
42}; 42};
43 43
44/* 44/*
@@ -212,47 +212,55 @@ static snd_kcontrol_new_t snd_pmac_beep_mixer = {
212int __init snd_pmac_attach_beep(pmac_t *chip) 212int __init snd_pmac_attach_beep(pmac_t *chip)
213{ 213{
214 pmac_beep_t *beep; 214 pmac_beep_t *beep;
215 int err; 215 struct input_dev *input_dev;
216 void *dmabuf;
217 int err = -ENOMEM;
216 218
217 beep = kmalloc(sizeof(*beep), GFP_KERNEL); 219 beep = kzalloc(sizeof(*beep), GFP_KERNEL);
218 if (! beep) 220 dmabuf = dma_alloc_coherent(&chip->pdev->dev, BEEP_BUFLEN * 4,
219 return -ENOMEM; 221 &beep->addr, GFP_KERNEL);
220 222 input_dev = input_allocate_device();
221 memset(beep, 0, sizeof(*beep)); 223 if (!beep || !dmabuf || !input_dev)
222 beep->buf = dma_alloc_coherent(&chip->pdev->dev, BEEP_BUFLEN * 4, 224 goto fail;
223 &beep->addr, GFP_KERNEL);
224
225 beep->dev.evbit[0] = BIT(EV_SND);
226 beep->dev.sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE);
227 beep->dev.event = snd_pmac_beep_event;
228 beep->dev.private = chip;
229 225
230 /* FIXME: set more better values */ 226 /* FIXME: set more better values */
231 beep->dev.name = "PowerMac Beep"; 227 input_dev->name = "PowerMac Beep";
232 beep->dev.phys = "powermac/beep"; 228 input_dev->phys = "powermac/beep";
233 beep->dev.id.bustype = BUS_ADB; 229 input_dev->id.bustype = BUS_ADB;
234 beep->dev.id.vendor = 0x001f; 230 input_dev->id.vendor = 0x001f;
235 beep->dev.id.product = 0x0001; 231 input_dev->id.product = 0x0001;
236 beep->dev.id.version = 0x0100; 232 input_dev->id.version = 0x0100;
233
234 input_dev->evbit[0] = BIT(EV_SND);
235 input_dev->sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE);
236 input_dev->event = snd_pmac_beep_event;
237 input_dev->private = chip;
238 input_dev->cdev.dev = &chip->pdev->dev;
237 239
240 beep->dev = input_dev;
241 beep->buf = dmabuf;
238 beep->volume = BEEP_VOLUME; 242 beep->volume = BEEP_VOLUME;
239 beep->running = 0; 243 beep->running = 0;
240 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_pmac_beep_mixer, chip))) < 0) { 244
241 kfree(beep->buf); 245 err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_pmac_beep_mixer, chip));
242 kfree(beep); 246 if (err < 0)
243 return err; 247 goto fail;
244 }
245 248
246 chip->beep = beep; 249 chip->beep = beep;
247 input_register_device(&beep->dev); 250 input_register_device(beep->dev);
248 251
249 return 0; 252 return 0;
253
254 fail: input_free_device(input_dev);
255 kfree(dmabuf);
256 kfree(beep);
257 return err;
250} 258}
251 259
252void snd_pmac_detach_beep(pmac_t *chip) 260void snd_pmac_detach_beep(pmac_t *chip)
253{ 261{
254 if (chip->beep) { 262 if (chip->beep) {
255 input_unregister_device(&chip->beep->dev); 263 input_unregister_device(chip->beep->dev);
256 dma_free_coherent(&chip->pdev->dev, BEEP_BUFLEN * 4, 264 dma_free_coherent(&chip->pdev->dev, BEEP_BUFLEN * 4,
257 chip->beep->buf, chip->beep->addr); 265 chip->beep->buf, chip->beep->addr);
258 kfree(chip->beep); 266 kfree(chip->beep);