[PATCH] m68k: namespace pollution fix (custom->amiga_custom)
[pandora-kernel.git] / sound / oss / dmasound / dmasound_paula.c
1 /*
2  *  linux/sound/oss/dmasound/dmasound_paula.c
3  *
4  *  Amiga `Paula' DMA Sound Driver
5  *
6  *  See linux/sound/oss/dmasound/dmasound_core.c for copyright and credits
7  *  prior to 28/01/2001
8  *
9  *  28/01/2001 [0.1] Iain Sandoe
10  *                   - added versioning
11  *                   - put in and populated the hardware_afmts field.
12  *             [0.2] - put in SNDCTL_DSP_GETCAPS value.
13  *             [0.3] - put in constraint on state buffer usage.
14  *             [0.4] - put in default hard/soft settings
15 */
16
17
18 #include <linux/module.h>
19 #include <linux/config.h>
20 #include <linux/mm.h>
21 #include <linux/init.h>
22 #include <linux/ioport.h>
23 #include <linux/soundcard.h>
24 #include <linux/interrupt.h>
25
26 #include <asm/uaccess.h>
27 #include <asm/setup.h>
28 #include <asm/amigahw.h>
29 #include <asm/amigaints.h>
30 #include <asm/machdep.h>
31
32 #include "dmasound.h"
33
34 #define DMASOUND_PAULA_REVISION 0
35 #define DMASOUND_PAULA_EDITION 4
36
37 #define custom amiga_custom
38    /*
39     *   The minimum period for audio depends on htotal (for OCS/ECS/AGA)
40     *   (Imported from arch/m68k/amiga/amisound.c)
41     */
42
43 extern volatile u_short amiga_audio_min_period;
44
45
46    /*
47     *   amiga_mksound() should be able to restore the period after beeping
48     *   (Imported from arch/m68k/amiga/amisound.c)
49     */
50
51 extern u_short amiga_audio_period;
52
53
54    /*
55     *   Audio DMA masks
56     */
57
58 #define AMI_AUDIO_OFF   (DMAF_AUD0 | DMAF_AUD1 | DMAF_AUD2 | DMAF_AUD3)
59 #define AMI_AUDIO_8     (DMAF_SETCLR | DMAF_MASTER | DMAF_AUD0 | DMAF_AUD1)
60 #define AMI_AUDIO_14    (AMI_AUDIO_8 | DMAF_AUD2 | DMAF_AUD3)
61
62
63     /*
64      *  Helper pointers for 16(14)-bit sound
65      */
66
67 static int write_sq_block_size_half, write_sq_block_size_quarter;
68
69
70 /*** Low level stuff *********************************************************/
71
72
73 static void *AmiAlloc(unsigned int size, gfp_t flags);
74 static void AmiFree(void *obj, unsigned int size);
75 static int AmiIrqInit(void);
76 #ifdef MODULE
77 static void AmiIrqCleanUp(void);
78 #endif
79 static void AmiSilence(void);
80 static void AmiInit(void);
81 static int AmiSetFormat(int format);
82 static int AmiSetVolume(int volume);
83 static int AmiSetTreble(int treble);
84 static void AmiPlayNextFrame(int index);
85 static void AmiPlay(void);
86 static irqreturn_t AmiInterrupt(int irq, void *dummy, struct pt_regs *fp);
87
88 #ifdef CONFIG_HEARTBEAT
89
90     /*
91      *  Heartbeat interferes with sound since the 7 kHz low-pass filter and the
92      *  power LED are controlled by the same line.
93      */
94
95 #ifdef CONFIG_APUS
96 #define mach_heartbeat  ppc_md.heartbeat
97 #endif
98
99 static void (*saved_heartbeat)(int) = NULL;
100
101 static inline void disable_heartbeat(void)
102 {
103         if (mach_heartbeat) {
104             saved_heartbeat = mach_heartbeat;
105             mach_heartbeat = NULL;
106         }
107         AmiSetTreble(dmasound.treble);
108 }
109
110 static inline void enable_heartbeat(void)
111 {
112         if (saved_heartbeat)
113             mach_heartbeat = saved_heartbeat;
114 }
115 #else /* !CONFIG_HEARTBEAT */
116 #define disable_heartbeat()     do { } while (0)
117 #define enable_heartbeat()      do { } while (0)
118 #endif /* !CONFIG_HEARTBEAT */
119
120
121 /*** Mid level stuff *********************************************************/
122
123 static void AmiMixerInit(void);
124 static int AmiMixerIoctl(u_int cmd, u_long arg);
125 static int AmiWriteSqSetup(void);
126 static int AmiStateInfo(char *buffer, size_t space);
127
128
129 /*** Translations ************************************************************/
130
131 /* ++TeSche: radically changed for new expanding purposes...
132  *
133  * These two routines now deal with copying/expanding/translating the samples
134  * from user space into our buffer at the right frequency. They take care about
135  * how much data there's actually to read, how much buffer space there is and
136  * to convert samples into the right frequency/encoding. They will only work on
137  * complete samples so it may happen they leave some bytes in the input stream
138  * if the user didn't write a multiple of the current sample size. They both
139  * return the number of bytes they've used from both streams so you may detect
140  * such a situation. Luckily all programs should be able to cope with that.
141  *
142  * I think I've optimized anything as far as one can do in plain C, all
143  * variables should fit in registers and the loops are really short. There's
144  * one loop for every possible situation. Writing a more generalized and thus
145  * parameterized loop would only produce slower code. Feel free to optimize
146  * this in assembler if you like. :)
147  *
148  * I think these routines belong here because they're not yet really hardware
149  * independent, especially the fact that the Falcon can play 16bit samples
150  * only in stereo is hardcoded in both of them!
151  *
152  * ++geert: split in even more functions (one per format)
153  */
154
155
156     /*
157      *  Native format
158      */
159
160 static ssize_t ami_ct_s8(const u_char *userPtr, size_t userCount,
161                          u_char frame[], ssize_t *frameUsed, ssize_t frameLeft)
162 {
163         ssize_t count, used;
164
165         if (!dmasound.soft.stereo) {
166                 void *p = &frame[*frameUsed];
167                 count = min_t(unsigned long, userCount, frameLeft) & ~1;
168                 used = count;
169                 if (copy_from_user(p, userPtr, count))
170                         return -EFAULT;
171         } else {
172                 u_char *left = &frame[*frameUsed>>1];
173                 u_char *right = left+write_sq_block_size_half;
174                 count = min_t(unsigned long, userCount, frameLeft)>>1 & ~1;
175                 used = count*2;
176                 while (count > 0) {
177                         if (get_user(*left++, userPtr++)
178                             || get_user(*right++, userPtr++))
179                                 return -EFAULT;
180                         count--;
181                 }
182         }
183         *frameUsed += used;
184         return used;
185 }
186
187
188     /*
189      *  Copy and convert 8 bit data
190      */
191
192 #define GENERATE_AMI_CT8(funcname, convsample)                          \
193 static ssize_t funcname(const u_char *userPtr, size_t userCount,        \
194                         u_char frame[], ssize_t *frameUsed,             \
195                         ssize_t frameLeft)                              \
196 {                                                                       \
197         ssize_t count, used;                                            \
198                                                                         \
199         if (!dmasound.soft.stereo) {                                    \
200                 u_char *p = &frame[*frameUsed];                         \
201                 count = min_t(size_t, userCount, frameLeft) & ~1;       \
202                 used = count;                                           \
203                 while (count > 0) {                                     \
204                         u_char data;                                    \
205                         if (get_user(data, userPtr++))                  \
206                                 return -EFAULT;                         \
207                         *p++ = convsample(data);                        \
208                         count--;                                        \
209                 }                                                       \
210         } else {                                                        \
211                 u_char *left = &frame[*frameUsed>>1];                   \
212                 u_char *right = left+write_sq_block_size_half;          \
213                 count = min_t(size_t, userCount, frameLeft)>>1 & ~1;    \
214                 used = count*2;                                         \
215                 while (count > 0) {                                     \
216                         u_char data;                                    \
217                         if (get_user(data, userPtr++))                  \
218                                 return -EFAULT;                         \
219                         *left++ = convsample(data);                     \
220                         if (get_user(data, userPtr++))                  \
221                                 return -EFAULT;                         \
222                         *right++ = convsample(data);                    \
223                         count--;                                        \
224                 }                                                       \
225         }                                                               \
226         *frameUsed += used;                                             \
227         return used;                                                    \
228 }
229
230 #define AMI_CT_ULAW(x)  (dmasound_ulaw2dma8[(x)])
231 #define AMI_CT_ALAW(x)  (dmasound_alaw2dma8[(x)])
232 #define AMI_CT_U8(x)    ((x) ^ 0x80)
233
234 GENERATE_AMI_CT8(ami_ct_ulaw, AMI_CT_ULAW)
235 GENERATE_AMI_CT8(ami_ct_alaw, AMI_CT_ALAW)
236 GENERATE_AMI_CT8(ami_ct_u8, AMI_CT_U8)
237
238
239     /*
240      *  Copy and convert 16 bit data
241      */
242
243 #define GENERATE_AMI_CT_16(funcname, convsample)                        \
244 static ssize_t funcname(const u_char *userPtr, size_t userCount,        \
245                         u_char frame[], ssize_t *frameUsed,             \
246                         ssize_t frameLeft)                              \
247 {                                                                       \
248         ssize_t count, used;                                            \
249         u_short data;                                                   \
250                                                                         \
251         if (!dmasound.soft.stereo) {                                    \
252                 u_char *high = &frame[*frameUsed>>1];                   \
253                 u_char *low = high+write_sq_block_size_half;            \
254                 count = min_t(size_t, userCount, frameLeft)>>1 & ~1;    \
255                 used = count*2;                                         \
256                 while (count > 0) {                                     \
257                         if (get_user(data, ((u_short *)userPtr)++))     \
258                                 return -EFAULT;                         \
259                         data = convsample(data);                        \
260                         *high++ = data>>8;                              \
261                         *low++ = (data>>2) & 0x3f;                      \
262                         count--;                                        \
263                 }                                                       \
264         } else {                                                        \
265                 u_char *lefth = &frame[*frameUsed>>2];                  \
266                 u_char *leftl = lefth+write_sq_block_size_quarter;      \
267                 u_char *righth = lefth+write_sq_block_size_half;        \
268                 u_char *rightl = righth+write_sq_block_size_quarter;    \
269                 count = min_t(size_t, userCount, frameLeft)>>2 & ~1;    \
270                 used = count*4;                                         \
271                 while (count > 0) {                                     \
272                         if (get_user(data, ((u_short *)userPtr)++))     \
273                                 return -EFAULT;                         \
274                         data = convsample(data);                        \
275                         *lefth++ = data>>8;                             \
276                         *leftl++ = (data>>2) & 0x3f;                    \
277                         if (get_user(data, ((u_short *)userPtr)++))     \
278                                 return -EFAULT;                         \
279                         data = convsample(data);                        \
280                         *righth++ = data>>8;                            \
281                         *rightl++ = (data>>2) & 0x3f;                   \
282                         count--;                                        \
283                 }                                                       \
284         }                                                               \
285         *frameUsed += used;                                             \
286         return used;                                                    \
287 }
288
289 #define AMI_CT_S16BE(x) (x)
290 #define AMI_CT_U16BE(x) ((x) ^ 0x8000)
291 #define AMI_CT_S16LE(x) (le2be16((x)))
292 #define AMI_CT_U16LE(x) (le2be16((x)) ^ 0x8000)
293
294 GENERATE_AMI_CT_16(ami_ct_s16be, AMI_CT_S16BE)
295 GENERATE_AMI_CT_16(ami_ct_u16be, AMI_CT_U16BE)
296 GENERATE_AMI_CT_16(ami_ct_s16le, AMI_CT_S16LE)
297 GENERATE_AMI_CT_16(ami_ct_u16le, AMI_CT_U16LE)
298
299
300 static TRANS transAmiga = {
301         .ct_ulaw        = ami_ct_ulaw,
302         .ct_alaw        = ami_ct_alaw,
303         .ct_s8          = ami_ct_s8,
304         .ct_u8          = ami_ct_u8,
305         .ct_s16be       = ami_ct_s16be,
306         .ct_u16be       = ami_ct_u16be,
307         .ct_s16le       = ami_ct_s16le,
308         .ct_u16le       = ami_ct_u16le,
309 };
310
311 /*** Low level stuff *********************************************************/
312
313 static inline void StopDMA(void)
314 {
315         custom.aud[0].audvol = custom.aud[1].audvol = 0;
316         custom.aud[2].audvol = custom.aud[3].audvol = 0;
317         custom.dmacon = AMI_AUDIO_OFF;
318         enable_heartbeat();
319 }
320
321 static void *AmiAlloc(unsigned int size, gfp_t flags)
322 {
323         return amiga_chip_alloc((long)size, "dmasound [Paula]");
324 }
325
326 static void AmiFree(void *obj, unsigned int size)
327 {
328         amiga_chip_free (obj);
329 }
330
331 static int __init AmiIrqInit(void)
332 {
333         /* turn off DMA for audio channels */
334         StopDMA();
335
336         /* Register interrupt handler. */
337         if (request_irq(IRQ_AMIGA_AUD0, AmiInterrupt, 0, "DMA sound",
338                         AmiInterrupt))
339                 return 0;
340         return 1;
341 }
342
343 #ifdef MODULE
344 static void AmiIrqCleanUp(void)
345 {
346         /* turn off DMA for audio channels */
347         StopDMA();
348         /* release the interrupt */
349         free_irq(IRQ_AMIGA_AUD0, AmiInterrupt);
350 }
351 #endif /* MODULE */
352
353 static void AmiSilence(void)
354 {
355         /* turn off DMA for audio channels */
356         StopDMA();
357 }
358
359
360 static void AmiInit(void)
361 {
362         int period, i;
363
364         AmiSilence();
365
366         if (dmasound.soft.speed)
367                 period = amiga_colorclock/dmasound.soft.speed-1;
368         else
369                 period = amiga_audio_min_period;
370         dmasound.hard = dmasound.soft;
371         dmasound.trans_write = &transAmiga;
372
373         if (period < amiga_audio_min_period) {
374                 /* we would need to squeeze the sound, but we won't do that */
375                 period = amiga_audio_min_period;
376         } else if (period > 65535) {
377                 period = 65535;
378         }
379         dmasound.hard.speed = amiga_colorclock/(period+1);
380
381         for (i = 0; i < 4; i++)
382                 custom.aud[i].audper = period;
383         amiga_audio_period = period;
384 }
385
386
387 static int AmiSetFormat(int format)
388 {
389         int size;
390
391         /* Amiga sound DMA supports 8bit and 16bit (pseudo 14 bit) modes */
392
393         switch (format) {
394         case AFMT_QUERY:
395                 return dmasound.soft.format;
396         case AFMT_MU_LAW:
397         case AFMT_A_LAW:
398         case AFMT_U8:
399         case AFMT_S8:
400                 size = 8;
401                 break;
402         case AFMT_S16_BE:
403         case AFMT_U16_BE:
404         case AFMT_S16_LE:
405         case AFMT_U16_LE:
406                 size = 16;
407                 break;
408         default: /* :-) */
409                 size = 8;
410                 format = AFMT_S8;
411         }
412
413         dmasound.soft.format = format;
414         dmasound.soft.size = size;
415         if (dmasound.minDev == SND_DEV_DSP) {
416                 dmasound.dsp.format = format;
417                 dmasound.dsp.size = dmasound.soft.size;
418         }
419         AmiInit();
420
421         return format;
422 }
423
424
425 #define VOLUME_VOXWARE_TO_AMI(v) \
426         (((v) < 0) ? 0 : ((v) > 100) ? 64 : ((v) * 64)/100)
427 #define VOLUME_AMI_TO_VOXWARE(v) ((v)*100/64)
428
429 static int AmiSetVolume(int volume)
430 {
431         dmasound.volume_left = VOLUME_VOXWARE_TO_AMI(volume & 0xff);
432         custom.aud[0].audvol = dmasound.volume_left;
433         dmasound.volume_right = VOLUME_VOXWARE_TO_AMI((volume & 0xff00) >> 8);
434         custom.aud[1].audvol = dmasound.volume_right;
435         if (dmasound.hard.size == 16) {
436                 if (dmasound.volume_left == 64 && dmasound.volume_right == 64) {
437                         custom.aud[2].audvol = 1;
438                         custom.aud[3].audvol = 1;
439                 } else {
440                         custom.aud[2].audvol = 0;
441                         custom.aud[3].audvol = 0;
442                 }
443         }
444         return VOLUME_AMI_TO_VOXWARE(dmasound.volume_left) |
445                (VOLUME_AMI_TO_VOXWARE(dmasound.volume_right) << 8);
446 }
447
448 static int AmiSetTreble(int treble)
449 {
450         dmasound.treble = treble;
451         if (treble < 50)
452                 ciaa.pra &= ~0x02;
453         else
454                 ciaa.pra |= 0x02;
455         return treble;
456 }
457
458
459 #define AMI_PLAY_LOADED         1
460 #define AMI_PLAY_PLAYING        2
461 #define AMI_PLAY_MASK           3
462
463
464 static void AmiPlayNextFrame(int index)
465 {
466         u_char *start, *ch0, *ch1, *ch2, *ch3;
467         u_long size;
468
469         /* used by AmiPlay() if all doubts whether there really is something
470          * to be played are already wiped out.
471          */
472         start = write_sq.buffers[write_sq.front];
473         size = (write_sq.count == index ? write_sq.rear_size
474                                         : write_sq.block_size)>>1;
475
476         if (dmasound.hard.stereo) {
477                 ch0 = start;
478                 ch1 = start+write_sq_block_size_half;
479                 size >>= 1;
480         } else {
481                 ch0 = start;
482                 ch1 = start;
483         }
484
485         disable_heartbeat();
486         custom.aud[0].audvol = dmasound.volume_left;
487         custom.aud[1].audvol = dmasound.volume_right;
488         if (dmasound.hard.size == 8) {
489                 custom.aud[0].audlc = (u_short *)ZTWO_PADDR(ch0);
490                 custom.aud[0].audlen = size;
491                 custom.aud[1].audlc = (u_short *)ZTWO_PADDR(ch1);
492                 custom.aud[1].audlen = size;
493                 custom.dmacon = AMI_AUDIO_8;
494         } else {
495                 size >>= 1;
496                 custom.aud[0].audlc = (u_short *)ZTWO_PADDR(ch0);
497                 custom.aud[0].audlen = size;
498                 custom.aud[1].audlc = (u_short *)ZTWO_PADDR(ch1);
499                 custom.aud[1].audlen = size;
500                 if (dmasound.volume_left == 64 && dmasound.volume_right == 64) {
501                         /* We can play pseudo 14-bit only with the maximum volume */
502                         ch3 = ch0+write_sq_block_size_quarter;
503                         ch2 = ch1+write_sq_block_size_quarter;
504                         custom.aud[2].audvol = 1;  /* we are being affected by the beeps */
505                         custom.aud[3].audvol = 1;  /* restoring volume here helps a bit */
506                         custom.aud[2].audlc = (u_short *)ZTWO_PADDR(ch2);
507                         custom.aud[2].audlen = size;
508                         custom.aud[3].audlc = (u_short *)ZTWO_PADDR(ch3);
509                         custom.aud[3].audlen = size;
510                         custom.dmacon = AMI_AUDIO_14;
511                 } else {
512                         custom.aud[2].audvol = 0;
513                         custom.aud[3].audvol = 0;
514                         custom.dmacon = AMI_AUDIO_8;
515                 }
516         }
517         write_sq.front = (write_sq.front+1) % write_sq.max_count;
518         write_sq.active |= AMI_PLAY_LOADED;
519 }
520
521
522 static void AmiPlay(void)
523 {
524         int minframes = 1;
525
526         custom.intena = IF_AUD0;
527
528         if (write_sq.active & AMI_PLAY_LOADED) {
529                 /* There's already a frame loaded */
530                 custom.intena = IF_SETCLR | IF_AUD0;
531                 return;
532         }
533
534         if (write_sq.active & AMI_PLAY_PLAYING)
535                 /* Increase threshold: frame 1 is already being played */
536                 minframes = 2;
537
538         if (write_sq.count < minframes) {
539                 /* Nothing to do */
540                 custom.intena = IF_SETCLR | IF_AUD0;
541                 return;
542         }
543
544         if (write_sq.count <= minframes &&
545             write_sq.rear_size < write_sq.block_size && !write_sq.syncing) {
546                 /* hmmm, the only existing frame is not
547                  * yet filled and we're not syncing?
548                  */
549                 custom.intena = IF_SETCLR | IF_AUD0;
550                 return;
551         }
552
553         AmiPlayNextFrame(minframes);
554
555         custom.intena = IF_SETCLR | IF_AUD0;
556 }
557
558
559 static irqreturn_t AmiInterrupt(int irq, void *dummy, struct pt_regs *fp)
560 {
561         int minframes = 1;
562
563         custom.intena = IF_AUD0;
564
565         if (!write_sq.active) {
566                 /* Playing was interrupted and sq_reset() has already cleared
567                  * the sq variables, so better don't do anything here.
568                  */
569                 WAKE_UP(write_sq.sync_queue);
570                 return IRQ_HANDLED;
571         }
572
573         if (write_sq.active & AMI_PLAY_PLAYING) {
574                 /* We've just finished a frame */
575                 write_sq.count--;
576                 WAKE_UP(write_sq.action_queue);
577         }
578
579         if (write_sq.active & AMI_PLAY_LOADED)
580                 /* Increase threshold: frame 1 is already being played */
581                 minframes = 2;
582
583         /* Shift the flags */
584         write_sq.active = (write_sq.active<<1) & AMI_PLAY_MASK;
585
586         if (!write_sq.active)
587                 /* No frame is playing, disable audio DMA */
588                 StopDMA();
589
590         custom.intena = IF_SETCLR | IF_AUD0;
591
592         if (write_sq.count >= minframes)
593                 /* Try to play the next frame */
594                 AmiPlay();
595
596         if (!write_sq.active)
597                 /* Nothing to play anymore.
598                    Wake up a process waiting for audio output to drain. */
599                 WAKE_UP(write_sq.sync_queue);
600         return IRQ_HANDLED;
601 }
602
603 /*** Mid level stuff *********************************************************/
604
605
606 /*
607  * /dev/mixer abstraction
608  */
609
610 static void __init AmiMixerInit(void)
611 {
612         dmasound.volume_left = 64;
613         dmasound.volume_right = 64;
614         custom.aud[0].audvol = dmasound.volume_left;
615         custom.aud[3].audvol = 1;       /* For pseudo 14bit */
616         custom.aud[1].audvol = dmasound.volume_right;
617         custom.aud[2].audvol = 1;       /* For pseudo 14bit */
618         dmasound.treble = 50;
619 }
620
621 static int AmiMixerIoctl(u_int cmd, u_long arg)
622 {
623         int data;
624         switch (cmd) {
625             case SOUND_MIXER_READ_DEVMASK:
626                     return IOCTL_OUT(arg, SOUND_MASK_VOLUME | SOUND_MASK_TREBLE);
627             case SOUND_MIXER_READ_RECMASK:
628                     return IOCTL_OUT(arg, 0);
629             case SOUND_MIXER_READ_STEREODEVS:
630                     return IOCTL_OUT(arg, SOUND_MASK_VOLUME);
631             case SOUND_MIXER_READ_VOLUME:
632                     return IOCTL_OUT(arg,
633                             VOLUME_AMI_TO_VOXWARE(dmasound.volume_left) |
634                             VOLUME_AMI_TO_VOXWARE(dmasound.volume_right) << 8);
635             case SOUND_MIXER_WRITE_VOLUME:
636                     IOCTL_IN(arg, data);
637                     return IOCTL_OUT(arg, dmasound_set_volume(data));
638             case SOUND_MIXER_READ_TREBLE:
639                     return IOCTL_OUT(arg, dmasound.treble);
640             case SOUND_MIXER_WRITE_TREBLE:
641                     IOCTL_IN(arg, data);
642                     return IOCTL_OUT(arg, dmasound_set_treble(data));
643         }
644         return -EINVAL;
645 }
646
647
648 static int AmiWriteSqSetup(void)
649 {
650         write_sq_block_size_half = write_sq.block_size>>1;
651         write_sq_block_size_quarter = write_sq_block_size_half>>1;
652         return 0;
653 }
654
655
656 static int AmiStateInfo(char *buffer, size_t space)
657 {
658         int len = 0;
659         len += sprintf(buffer+len, "\tsound.volume_left = %d [0...64]\n",
660                        dmasound.volume_left);
661         len += sprintf(buffer+len, "\tsound.volume_right = %d [0...64]\n",
662                        dmasound.volume_right);
663         if (len >= space) {
664                 printk(KERN_ERR "dmasound_paula: overlowed state buffer alloc.\n") ;
665                 len = space ;
666         }
667         return len;
668 }
669
670
671 /*** Machine definitions *****************************************************/
672
673 static SETTINGS def_hard = {
674         .format = AFMT_S8,
675         .stereo = 0,
676         .size   = 8,
677         .speed  = 8000
678 } ;
679
680 static SETTINGS def_soft = {
681         .format = AFMT_U8,
682         .stereo = 0,
683         .size   = 8,
684         .speed  = 8000
685 } ;
686
687 static MACHINE machAmiga = {
688         .name           = "Amiga",
689         .name2          = "AMIGA",
690         .owner          = THIS_MODULE,
691         .dma_alloc      = AmiAlloc,
692         .dma_free       = AmiFree,
693         .irqinit        = AmiIrqInit,
694 #ifdef MODULE
695         .irqcleanup     = AmiIrqCleanUp,
696 #endif /* MODULE */
697         .init           = AmiInit,
698         .silence        = AmiSilence,
699         .setFormat      = AmiSetFormat,
700         .setVolume      = AmiSetVolume,
701         .setTreble      = AmiSetTreble,
702         .play           = AmiPlay,
703         .mixer_init     = AmiMixerInit,
704         .mixer_ioctl    = AmiMixerIoctl,
705         .write_sq_setup = AmiWriteSqSetup,
706         .state_info     = AmiStateInfo,
707         .min_dsp_speed  = 8000,
708         .version        = ((DMASOUND_PAULA_REVISION<<8) | DMASOUND_PAULA_EDITION),
709         .hardware_afmts = (AFMT_S8 | AFMT_S16_BE), /* h'ware-supported formats *only* here */
710         .capabilities   = DSP_CAP_BATCH          /* As per SNDCTL_DSP_GETCAPS */
711 };
712
713
714 /*** Config & Setup **********************************************************/
715
716
717 int __init dmasound_paula_init(void)
718 {
719         int err;
720
721         if (MACH_IS_AMIGA && AMIGAHW_PRESENT(AMI_AUDIO)) {
722             if (!request_mem_region(CUSTOM_PHYSADDR+0xa0, 0x40,
723                                     "dmasound [Paula]"))
724                 return -EBUSY;
725             dmasound.mach = machAmiga;
726             dmasound.mach.default_hard = def_hard ;
727             dmasound.mach.default_soft = def_soft ;
728             err = dmasound_init();
729             if (err)
730                 release_mem_region(CUSTOM_PHYSADDR+0xa0, 0x40);
731             return err;
732         } else
733             return -ENODEV;
734 }
735
736 static void __exit dmasound_paula_cleanup(void)
737 {
738         dmasound_deinit();
739         release_mem_region(CUSTOM_PHYSADDR+0xa0, 0x40);
740 }
741
742 module_init(dmasound_paula_init);
743 module_exit(dmasound_paula_cleanup);
744 MODULE_LICENSE("GPL");