ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / sound / oss / harmony.c
1 /*
2         drivers/sound/harmony.c 
3
4         This is a sound driver for ASP's and Lasi's Harmony sound chip
5         and is unlikely to be used for anything other than on a HP PA-RISC.
6
7         Harmony is found in HP 712s, 715/new and many other GSC based machines.
8         On older 715 machines you'll find the technically identical chip 
9         called 'Vivace'. Both Harmony and Vicace are supported by this driver.
10
11         Copyright 2000 (c) Linuxcare Canada, Alex deVries <alex@linuxcare.com>
12         Copyright 2000-2003 (c) Helge Deller <deller@gmx.de>
13         Copyright 2001 (c) Matthieu Delahaye <delahaym@esiee.fr>
14         Copyright 2001 (c) Jean-Christophe Vaugeois <vaugeoij@esiee.fr>
15
16                                 
17 TODO:
18         - fix SNDCTL_DSP_GETOSPACE and SNDCTL_DSP_GETISPACE ioctls to
19                 return the real values
20         - add private ioctl for selecting line- or microphone input
21                 (only one of them is available at the same time)
22         - add module parameters
23         - implement mmap functionality
24         - implement gain meter ?
25         - ...
26 */
27
28 #include <linux/delay.h>
29 #include <linux/errno.h>
30 #include <linux/init.h>
31 #include <linux/interrupt.h>
32 #include <linux/ioport.h>
33 #include <linux/types.h>
34 #include <linux/mm.h>
35 #include <linux/pci.h>
36
37 #include <asm/parisc-device.h>
38 #include <asm/io.h>
39
40 #include "sound_config.h"
41
42
43 #define PFX "harmony: "
44 #define HARMONY_VERSION "V0.9a"
45
46 #undef DEBUG
47 #ifdef DEBUG
48 # define DPRINTK printk 
49 #else
50 # define DPRINTK(x,...)
51 #endif
52
53
54 #define MAX_BUFS 10             /* maximum number of rotating buffers */
55 #define HARMONY_BUF_SIZE 4096   /* needs to be a multiple of PAGE_SIZE (4096)! */
56
57 #define CNTL_C          0x80000000
58 #define CNTL_ST         0x00000020
59 #define CNTL_44100      0x00000015      /* HARMONY_SR_44KHZ */
60 #define CNTL_8000       0x00000008      /* HARMONY_SR_8KHZ */
61
62 #define GAINCTL_HE      0x08000000
63 #define GAINCTL_LE      0x04000000
64 #define GAINCTL_SE      0x02000000
65
66 #define DSTATUS_PN      0x00000200
67 #define DSTATUS_RN      0x00000002
68
69 #define DSTATUS_IE      0x80000000
70
71 #define HARMONY_DF_16BIT_LINEAR 0
72 #define HARMONY_DF_8BIT_ULAW    1
73 #define HARMONY_DF_8BIT_ALAW    2
74
75 #define HARMONY_SS_MONO         0
76 #define HARMONY_SS_STEREO       1
77
78 #define HARMONY_SR_8KHZ         0x08
79 #define HARMONY_SR_16KHZ        0x09
80 #define HARMONY_SR_27KHZ        0x0A
81 #define HARMONY_SR_32KHZ        0x0B
82 #define HARMONY_SR_48KHZ        0x0E
83 #define HARMONY_SR_9KHZ         0x0F
84 #define HARMONY_SR_5KHZ         0x10
85 #define HARMONY_SR_11KHZ        0x11
86 #define HARMONY_SR_18KHZ        0x12
87 #define HARMONY_SR_22KHZ        0x13
88 #define HARMONY_SR_37KHZ        0x14
89 #define HARMONY_SR_44KHZ        0x15
90 #define HARMONY_SR_33KHZ        0x16
91 #define HARMONY_SR_6KHZ         0x17
92
93 /*
94  * Some magics numbers used to auto-detect file formats
95  */
96
97 #define HARMONY_MAGIC_8B_ULAW   1
98 #define HARMONY_MAGIC_8B_ALAW   27
99 #define HARMONY_MAGIC_16B_LINEAR 3
100 #define HARMONY_MAGIC_MONO      1
101 #define HARMONY_MAGIC_STEREO    2
102
103 /*
104  * Channels Positions in mixer register
105  */
106
107 #define GAIN_HE_SHIFT   27
108 #define GAIN_HE_MASK    ( 1 << GAIN_HE_SHIFT) 
109 #define GAIN_LE_SHIFT   26
110 #define GAIN_LE_MASK    ( 1 << GAIN_LE_SHIFT) 
111 #define GAIN_SE_SHIFT   25
112 #define GAIN_SE_MASK    ( 1 << GAIN_SE_SHIFT) 
113 #define GAIN_IS_SHIFT   24
114 #define GAIN_IS_MASK    ( 1 << GAIN_IS_SHIFT) 
115 #define GAIN_MA_SHIFT   20
116 #define GAIN_MA_MASK    ( 0x0f << GAIN_MA_SHIFT) 
117 #define GAIN_LI_SHIFT   16
118 #define GAIN_LI_MASK    ( 0x0f << GAIN_LI_SHIFT) 
119 #define GAIN_RI_SHIFT   12
120 #define GAIN_RI_MASK    ( 0x0f << GAIN_RI_SHIFT) 
121 #define GAIN_LO_SHIFT   6
122 #define GAIN_LO_MASK    ( 0x3f << GAIN_LO_SHIFT) 
123 #define GAIN_RO_SHIFT   0
124 #define GAIN_RO_MASK    ( 0x3f << GAIN_RO_SHIFT) 
125
126
127 #define MAX_OUTPUT_LEVEL (GAIN_RO_MASK >> GAIN_RO_SHIFT)
128 #define MAX_INPUT_LEVEL  (GAIN_RI_MASK >> GAIN_RI_SHIFT)
129 #define MAX_VOLUME_LEVEL (GAIN_MA_MASK >> GAIN_MA_SHIFT)
130
131 /*
132  * Channels Mask in mixer register
133  */
134
135 #define GAIN_TOTAL_SILENCE 0x00F00FFF
136 #define GAIN_DEFAULT       0x0FF00000
137
138
139 struct harmony_hpa {
140         u8      unused000;
141         u8      id;
142         u8      teleshare_id;
143         u8      unused003;
144         u32     reset;
145         u32     cntl;
146         u32     gainctl;
147         u32     pnxtadd;
148         u32     pcuradd;
149         u32     rnxtadd;
150         u32     rcuradd;
151         u32     dstatus;
152         u32     ov;
153         u32     pio;
154         u32     unused02c;
155         u32     unused030[3];
156         u32     diag;
157 };
158
159 struct harmony_dev {
160         struct harmony_hpa *hpa;
161         struct parisc_device *dev;
162         u32 current_gain;
163         u32 dac_rate;           /* 8000 ... 48000 (Hz) */
164         u8 data_format;         /* HARMONY_DF_xx_BIT_xxx */
165         u8 sample_rate;         /* HARMONY_SR_xx_KHZ */
166         u8 stereo_select;       /* HARMONY_SS_MONO or HARMONY_SS_STEREO */
167         int format_initialized  :1;
168         int suspended_playing   :1;
169         int suspended_recording :1;
170         
171         int blocked_playing     :1;
172         int blocked_recording   :1;
173         int audio_open          :1;
174         int mixer_open          :1;
175         
176         wait_queue_head_t wq_play, wq_record;
177         int first_filled_play;  /* first buffer containing data (next to play) */
178         int nb_filled_play; 
179         int play_offset;
180         int first_filled_record;
181         int nb_filled_record;
182                 
183         int dsp_unit, mixer_unit;
184 };
185
186
187 static struct harmony_dev harmony;
188
189
190 /*
191  * Dynamic sound buffer allocation and DMA memory
192  */
193
194 struct harmony_buffer {
195         unsigned char *addr;
196         dma_addr_t dma_handle;
197         int dma_coherent;       /* Zero if dma_alloc_coherent() fails */
198         unsigned int len;
199 };
200
201 /*
202  * Harmony memory buffers
203  */
204
205 static struct harmony_buffer played_buf, recorded_buf, silent, graveyard;
206
207
208 #define CHECK_WBACK_INV_OFFSET(b,offset,len) \
209         do { if (!b.dma_coherent) \
210                 dma_cache_wback_inv((unsigned long)b.addr+offset,len); \
211         } while (0) 
212
213         
214 static int __init harmony_alloc_buffer(struct harmony_buffer *b, 
215                 unsigned int buffer_count)
216 {
217         b->len = buffer_count * HARMONY_BUF_SIZE;
218         b->addr = dma_alloc_coherent(&harmony.dev->dev, 
219                           b->len, &b->dma_handle, GFP_KERNEL|GFP_DMA);
220         if (b->addr && b->dma_handle) {
221                 b->dma_coherent = 1;
222                 DPRINTK(KERN_INFO PFX "coherent memory: 0x%lx, played_buf: 0x%lx\n",
223                                 (unsigned long)b->dma_handle, (unsigned long)b->addr);
224         } else {
225                 b->dma_coherent = 0;
226                 /* kmalloc()ed memory will HPMC on ccio machines ! */
227                 b->addr = kmalloc(b->len, GFP_KERNEL);
228                 if (!b->addr) {
229                         printk(KERN_ERR PFX "couldn't allocate memory\n");
230                         return -EBUSY;
231                 }
232                 b->dma_handle = __pa(b->addr);
233         }
234         return 0;
235 }
236
237 static void __exit harmony_free_buffer(struct harmony_buffer *b)
238 {
239         if (!b->addr)
240                 return;
241
242         if (b->dma_coherent)
243                 dma_free_coherent(&harmony.dev->dev,
244                                 b->len, b->addr, b->dma_handle);
245         else
246                 kfree(b->addr);
247
248         memset(b, 0, sizeof(*b));
249 }
250
251
252
253 /*
254  * Low-Level sound-chip programming
255  */
256
257 static void __inline__ harmony_wait_CNTL(void)
258 {
259         /* Wait until we're out of control mode */
260         while (gsc_readl(&harmony.hpa->cntl) & CNTL_C)
261                 /* wait */ ;
262 }
263
264
265 static void harmony_update_control(void) 
266 {
267         u32 default_cntl;
268         
269         /* Set CNTL */
270         default_cntl = (CNTL_C |                /* The C bit */
271                 (harmony.data_format << 6) |    /* Set the data format */
272                 (harmony.stereo_select << 5) |  /* Stereo select */
273                 (harmony.sample_rate));         /* Set sample rate */
274         harmony.format_initialized = 1;
275         
276         /* initialize CNTL */
277         gsc_writel(default_cntl, &harmony.hpa->cntl);
278 }
279
280 static void harmony_set_control(u8 data_format, u8 sample_rate, u8 stereo_select) 
281 {
282         harmony.sample_rate = sample_rate;
283         harmony.data_format = data_format;
284         harmony.stereo_select = stereo_select;
285         harmony_update_control();
286 }
287
288 static void harmony_set_rate(u8 data_rate) 
289 {
290         harmony.sample_rate = data_rate;
291         harmony_update_control();
292 }
293
294 static int harmony_detect_rate(int *freq)
295 {
296         int newrate;
297         switch (*freq) {
298         case 8000:      newrate = HARMONY_SR_8KHZ;      break;
299         case 16000:     newrate = HARMONY_SR_16KHZ;     break; 
300         case 27428:     newrate = HARMONY_SR_27KHZ;     break; 
301         case 32000:     newrate = HARMONY_SR_32KHZ;     break; 
302         case 48000:     newrate = HARMONY_SR_48KHZ;     break; 
303         case 9600:      newrate = HARMONY_SR_9KHZ;      break; 
304         case 5125:      newrate = HARMONY_SR_5KHZ;      break; 
305         case 11025:     newrate = HARMONY_SR_11KHZ;     break; 
306         case 18900:     newrate = HARMONY_SR_18KHZ;     break; 
307         case 22050:     newrate = HARMONY_SR_22KHZ;     break; 
308         case 37800:     newrate = HARMONY_SR_37KHZ;     break; 
309         case 44100:     newrate = HARMONY_SR_44KHZ;     break; 
310         case 33075:     newrate = HARMONY_SR_33KHZ;     break; 
311         case 6615:      newrate = HARMONY_SR_6KHZ;      break; 
312         default:        newrate = HARMONY_SR_8KHZ; 
313                         *freq = 8000;                   break;
314         }
315         return newrate;
316 }
317
318 static void harmony_set_format(u8 data_format) 
319 {
320         harmony.data_format = data_format;
321         harmony_update_control();
322 }
323
324 static void harmony_set_stereo(u8 stereo_select) 
325 {
326         harmony.stereo_select = stereo_select;
327         harmony_update_control();
328 }
329
330 static void harmony_disable_interrupts(void) 
331 {
332         harmony_wait_CNTL();
333         gsc_writel(0, &harmony.hpa->dstatus); 
334 }
335
336 static void harmony_enable_interrupts(void) 
337 {
338         harmony_wait_CNTL();
339         gsc_writel(DSTATUS_IE, &harmony.hpa->dstatus); 
340 }
341
342 /*
343  * harmony_silence()
344  *
345  * This subroutine fills in a buffer starting at location start and
346  * silences for length bytes.  This references the current
347  * configuration of the audio format.
348  *
349  */
350
351 static void harmony_silence(struct harmony_buffer *buffer, int start, int length) 
352 {
353         u8 silence_char;
354
355         /* Despite what you hear, silence is different in
356            different audio formats.  */
357         switch (harmony.data_format) {
358                 case HARMONY_DF_8BIT_ULAW:      silence_char = 0x55; break;
359                 case HARMONY_DF_8BIT_ALAW:      silence_char = 0xff; break;
360                 case HARMONY_DF_16BIT_LINEAR:   /* fall through */
361                 default:                        silence_char = 0;
362         }
363
364         memset(buffer->addr+start, silence_char, length);
365 }
366
367
368 static int harmony_audio_open(struct inode *inode, struct file *file)
369 {
370         if (harmony.audio_open) 
371                 return -EBUSY;
372         
373         harmony.audio_open = 1;
374         harmony.suspended_playing = harmony.suspended_recording = 1;
375         harmony.blocked_playing   = harmony.blocked_recording   = 0;
376         harmony.first_filled_play = harmony.first_filled_record = 0;
377         harmony.nb_filled_play    = harmony.nb_filled_record    = 0;
378         harmony.play_offset = 0;
379         init_waitqueue_head(&harmony.wq_play);
380         init_waitqueue_head(&harmony.wq_record);
381         
382         /* Start off in a balanced mode. */
383         harmony_set_control(HARMONY_DF_8BIT_ULAW, HARMONY_SR_8KHZ, HARMONY_SS_MONO);
384         harmony_update_control();
385         harmony.format_initialized = 0;
386
387         /* Clear out all the buffers and flush to cache */
388         harmony_silence(&played_buf, 0, HARMONY_BUF_SIZE*MAX_BUFS);
389         CHECK_WBACK_INV_OFFSET(played_buf, 0, HARMONY_BUF_SIZE*MAX_BUFS);
390         
391         return 0;
392 }
393
394 /*
395  * Release (close) the audio device.
396  */
397
398 static int harmony_audio_release(struct inode *inode, struct file *file)
399 {
400         if (!harmony.audio_open) 
401                 return -EBUSY;
402         
403         harmony.audio_open = 0;
404
405         return 0;
406 }
407
408 /*
409  * Read recorded data off the audio device.
410  */
411
412 static ssize_t harmony_audio_read(struct file *file,
413                                 char *buffer,
414                                 size_t size_count,
415                                 loff_t *ppos)
416 {
417         int total_count = (int) size_count;
418         int count = 0;
419         int buf_to_read;
420
421         while (count<total_count) {
422                 /* Wait until we're out of control mode */
423                 harmony_wait_CNTL();
424                 
425                 /* Figure out which buffer to fill in */
426                 if (harmony.nb_filled_record <= 2) {
427                         harmony.blocked_recording = 1;
428                         if (harmony.suspended_recording) {
429                                 harmony.suspended_recording = 0;
430                                 harmony_enable_interrupts();
431                         }
432                                                         
433                         interruptible_sleep_on(&harmony.wq_record);
434                         harmony.blocked_recording = 0;
435                 }
436                 
437                 if (harmony.nb_filled_record < 2)
438                         return -EBUSY;
439                 
440                 buf_to_read = harmony.first_filled_record;
441
442                 /* Copy the page to an aligned buffer */
443                 if (copy_to_user(buffer+count, recorded_buf.addr +
444                                  (HARMONY_BUF_SIZE*buf_to_read),
445                                  HARMONY_BUF_SIZE)) {
446                         count = -EFAULT;
447                         break;
448                 }
449                 
450                 harmony.nb_filled_record--;
451                 harmony.first_filled_record++;
452                 harmony.first_filled_record %= MAX_BUFS;
453                                 
454                 count += HARMONY_BUF_SIZE;
455         }
456         return count;
457 }
458
459
460
461
462 /*
463  * Here is the place where we try to recognize file format.
464  * Sun/NeXT .au files begin with the string .snd
465  * At offset 12 is specified the encoding.
466  * At offset 16 is specified speed rate
467  * At Offset 20 is specified the numbers of voices
468  */
469
470 #define four_bytes_to_u32(start) (file_header[start] << 24)|\
471                                   (file_header[start+1] << 16)|\
472                                   (file_header[start+2] << 8)|\
473                                   (file_header[start+3]);
474
475 #define test_rate(tested,real_value,harmony_value) if ((tested)<=(real_value))\
476                                                     
477
478 static int harmony_format_auto_detect(const char *buffer, int block_size)
479 {
480         u8 file_header[24];
481         u32 start_string;
482         int ret = 0;
483         
484         if (block_size>24) {
485                 if (copy_from_user(file_header, buffer, sizeof(file_header)))
486                         ret = -EFAULT;
487                         
488                 start_string = four_bytes_to_u32(0);
489                 
490                 if ((file_header[4]==0) && (start_string==0x2E736E64)) {
491                         u32 format;
492                         u32 nb_voices;
493                         u32 speed;
494                         
495                         format = four_bytes_to_u32(12);
496                         nb_voices = four_bytes_to_u32(20);
497                         speed = four_bytes_to_u32(16);
498                         
499                         switch (format) {
500                         case HARMONY_MAGIC_8B_ULAW:
501                                 harmony.data_format = HARMONY_DF_8BIT_ULAW;
502                                 break;
503                         case HARMONY_MAGIC_8B_ALAW:
504                                 harmony.data_format = HARMONY_DF_8BIT_ALAW;
505                                 break;
506                         case HARMONY_MAGIC_16B_LINEAR:
507                                 harmony.data_format = HARMONY_DF_16BIT_LINEAR;
508                                 break;
509                         default:
510                                 harmony_set_control(HARMONY_DF_16BIT_LINEAR,
511                                                 HARMONY_SR_44KHZ, HARMONY_SS_STEREO);
512                                 goto out;
513                         }
514                         switch (nb_voices) {
515                         case HARMONY_MAGIC_MONO:
516                                 harmony.stereo_select = HARMONY_SS_MONO;
517                                 break;
518                         case HARMONY_MAGIC_STEREO:
519                                 harmony.stereo_select = HARMONY_SS_STEREO;
520                                 break;
521                         default:
522                                 harmony.stereo_select = HARMONY_SS_MONO;
523                                 break;
524                         }
525                         harmony_set_rate(harmony_detect_rate(&speed));
526                         harmony.dac_rate = speed;
527                         goto out;
528                 }
529         }
530         harmony_set_control(HARMONY_DF_8BIT_ULAW, HARMONY_SR_8KHZ, HARMONY_SS_MONO);
531 out:
532         return ret;
533 }
534 #undef four_bytes_to_u32
535
536
537 static ssize_t harmony_audio_write(struct file *file,
538                                  const char *buffer,
539                                  size_t size_count,
540                                  loff_t *ppos)
541 {
542         int total_count = (int) size_count;
543         int count = 0;
544         int frame_size;
545         int buf_to_fill;
546
547         if (!harmony.format_initialized) {
548                 if (harmony_format_auto_detect(buffer, total_count))
549                         return -EFAULT;
550         }
551         
552         while (count<total_count) {
553                 /* Wait until we're out of control mode */
554                 harmony_wait_CNTL();
555
556                 /* Figure out which buffer to fill in */
557                 if (harmony.nb_filled_play+2 >= MAX_BUFS && !harmony.play_offset) {
558                         harmony.blocked_playing = 1;
559                         interruptible_sleep_on(&harmony.wq_play);
560                         harmony.blocked_playing = 0;
561                 }
562                 if (harmony.nb_filled_play+2 >= MAX_BUFS && !harmony.play_offset)
563                         return -EBUSY;
564                 
565                 
566                 buf_to_fill = (harmony.first_filled_play+harmony.nb_filled_play); 
567                 if (harmony.play_offset)
568                         buf_to_fill--;
569                 buf_to_fill %= MAX_BUFS;
570
571                 /* Figure out the size of the frame */
572                 if ((total_count-count) > HARMONY_BUF_SIZE - harmony.play_offset) {
573                         frame_size = HARMONY_BUF_SIZE - harmony.play_offset;
574                 } else {
575                         frame_size = total_count - count;
576                         /* Clear out the buffer, since there we'll only be 
577                            overlaying part of the old buffer with the new one */
578                         harmony_silence(&played_buf, 
579                                 HARMONY_BUF_SIZE*buf_to_fill+frame_size+harmony.play_offset,
580                                 HARMONY_BUF_SIZE-frame_size-harmony.play_offset);
581                 }
582
583                 /* Copy the page to an aligned buffer */
584                 if (copy_from_user(played_buf.addr +(HARMONY_BUF_SIZE*buf_to_fill) + harmony.play_offset, 
585                                    buffer+count, frame_size))
586                         return -EFAULT;
587                 CHECK_WBACK_INV_OFFSET(played_buf, (HARMONY_BUF_SIZE*buf_to_fill + harmony.play_offset), 
588                                 frame_size);
589         
590                 if (!harmony.play_offset)
591                         harmony.nb_filled_play++;
592                 
593                 count += frame_size;
594                 harmony.play_offset += frame_size;
595                 harmony.play_offset %= HARMONY_BUF_SIZE;
596                 if (harmony.suspended_playing && (harmony.nb_filled_play>=4))
597                         harmony_enable_interrupts();
598         }
599         
600         return count;
601 }
602
603 static unsigned int harmony_audio_poll(struct file *file,
604                                      struct poll_table_struct *wait)
605 {
606         unsigned int mask = 0;
607         
608         if (file->f_mode & FMODE_READ) {
609                 if (!harmony.suspended_recording)
610                         poll_wait(file, &harmony.wq_record, wait);
611                 if (harmony.nb_filled_record)
612                         mask |= POLLIN | POLLRDNORM;
613         }
614
615         if (file->f_mode & FMODE_WRITE) {
616                 if (!harmony.suspended_playing)
617                         poll_wait(file, &harmony.wq_play, wait);
618                 if (harmony.nb_filled_play)
619                         mask |= POLLOUT | POLLWRNORM;
620         }
621
622         return mask;
623 }
624
625 static int harmony_audio_ioctl(struct inode *inode,
626                                 struct file *file,
627                                 unsigned int cmd,
628                                 unsigned long arg)
629 {
630         int ival, new_format;
631         int frag_size, frag_buf;
632         struct audio_buf_info info;
633         
634         switch (cmd) {
635         case OSS_GETVERSION:
636                 return put_user(SOUND_VERSION, (int *) arg);
637
638         case SNDCTL_DSP_GETCAPS:
639                 ival = DSP_CAP_DUPLEX;
640                 return put_user(ival, (int *) arg);
641
642         case SNDCTL_DSP_GETFMTS:
643                 ival = (AFMT_S16_BE | AFMT_MU_LAW | AFMT_A_LAW ); 
644                 return put_user(ival, (int *) arg);
645         
646         case SNDCTL_DSP_SETFMT:
647                 if (get_user(ival, (int *) arg)) 
648                         return -EFAULT;
649                 if (ival != AFMT_QUERY) {
650                         switch (ival) {
651                         case AFMT_MU_LAW:       new_format = HARMONY_DF_8BIT_ULAW; break;
652                         case AFMT_A_LAW:        new_format = HARMONY_DF_8BIT_ALAW; break;
653                         case AFMT_S16_LE:       /* fall through, but not really supported */
654                         case AFMT_S16_BE:       new_format = HARMONY_DF_16BIT_LINEAR;
655                                                 ival = AFMT_S16_BE;
656                                                 break; 
657                         default: {
658                                 DPRINTK(KERN_WARNING PFX 
659                                         "unsupported sound format 0x%04x requested.\n",
660                                         ival);
661                                 return -EINVAL;
662                         }
663                         }
664                         harmony_set_format(new_format);
665                 } else {
666                         switch (harmony.data_format) {
667                         case HARMONY_DF_8BIT_ULAW:      ival = AFMT_MU_LAW; break;
668                         case HARMONY_DF_8BIT_ALAW:      ival = AFMT_A_LAW;  break;
669                         case HARMONY_DF_16BIT_LINEAR:   ival = AFMT_U16_BE; break;
670                         default: ival = 0;
671                         }
672                 }
673                 return put_user(ival, (int *) arg);
674
675         case SOUND_PCM_READ_RATE:
676                 ival = harmony.dac_rate;
677                 return put_user(ival, (int *) arg);
678
679         case SNDCTL_DSP_SPEED:
680                 if (get_user(ival, (int *) arg))
681                         return -EFAULT;
682                 harmony_set_rate(harmony_detect_rate(&ival));
683                 harmony.dac_rate = ival;
684                 return put_user(ival, (int*) arg);
685
686         case SNDCTL_DSP_STEREO:
687                 if (get_user(ival, (int *) arg))
688                         return -EFAULT;
689                 if (ival != 0 && ival != 1)
690                         return -EINVAL;
691                 harmony_set_stereo(ival);
692                 return put_user(ival, (int *) arg);
693
694         case SNDCTL_DSP_GETBLKSIZE:
695                 ival = HARMONY_BUF_SIZE;
696                 return put_user(ival, (int *) arg);
697                 
698         case SNDCTL_DSP_NONBLOCK:
699                 file->f_flags |= O_NONBLOCK;
700                 return 0;
701
702         case SNDCTL_DSP_RESET:
703                 if (!harmony.suspended_recording) {
704                         /* TODO: stop_recording() */
705                 }
706                 return 0;
707
708         case SNDCTL_DSP_SETFRAGMENT:
709                 if (get_user(ival, (int *)arg))
710                         return -EFAULT;
711                 frag_size = ival & 0xffff;
712                 frag_buf = (ival>>16) & 0xffff;
713                 /* TODO: We use hardcoded fragment sizes and numbers for now */
714                 frag_size = 12;  /* 4096 == 2^12 */
715                 frag_buf  = MAX_BUFS;
716                 ival = (frag_buf << 16) + frag_size;
717                 return put_user(ival, (int *) arg);
718                 
719         case SNDCTL_DSP_GETOSPACE:
720                 if (!(file->f_mode & FMODE_WRITE))
721                         return -EINVAL;
722                 info.fragstotal = MAX_BUFS;
723                 info.fragments = MAX_BUFS - harmony.nb_filled_play;
724                 info.fragsize = HARMONY_BUF_SIZE;
725                 info.bytes = info.fragments * info.fragsize;
726                 return copy_to_user((void *)arg, &info, sizeof(info)) ? -EFAULT : 0;
727
728         case SNDCTL_DSP_GETISPACE:
729                 if (!(file->f_mode & FMODE_READ))
730                         return -EINVAL;
731                 info.fragstotal = MAX_BUFS;
732                 info.fragments = /*MAX_BUFS-*/ harmony.nb_filled_record;
733                 info.fragsize = HARMONY_BUF_SIZE;
734                 info.bytes = info.fragments * info.fragsize;
735                 return copy_to_user((void *)arg, &info, sizeof(info)) ? -EFAULT : 0;
736         
737         case SNDCTL_DSP_SYNC:
738                 return 0;
739         }
740         
741         return -EINVAL;
742 }
743
744
745 /*
746  * harmony_interrupt()
747  *
748  * harmony interruption service routine
749  * 
750  */
751
752 static irqreturn_t harmony_interrupt(int irq, void *dev, struct pt_regs *regs)
753 {
754         u32 dstatus;
755         struct harmony_hpa *hpa;
756
757         /* Setup the hpa */
758         hpa = ((struct harmony_dev *)dev)->hpa;
759         harmony_wait_CNTL();
760
761         /* Read dstatus and pcuradd (the current address) */
762         dstatus = gsc_readl(&hpa->dstatus);
763         
764         /* Turn off interrupts */
765         harmony_disable_interrupts();
766         
767         /* Check if this is a request to get the next play buffer */
768         if (dstatus & DSTATUS_PN) {
769                 if (!harmony.nb_filled_play) {
770                         harmony.suspended_playing = 1;
771                         gsc_writel((unsigned long)silent.dma_handle, &hpa->pnxtadd);
772                                                 
773                         if (!harmony.suspended_recording)
774                                 harmony_enable_interrupts();
775                 } else {
776                         harmony.suspended_playing = 0;
777                         gsc_writel((unsigned long)played_buf.dma_handle + 
778                                         (HARMONY_BUF_SIZE*harmony.first_filled_play),
779                                         &hpa->pnxtadd);
780                         harmony.first_filled_play++;
781                         harmony.first_filled_play %= MAX_BUFS;
782                         harmony.nb_filled_play--;
783                         
784                         harmony_enable_interrupts();
785                 }
786                 
787                 if (harmony.blocked_playing)
788                         wake_up_interruptible(&harmony.wq_play);
789         }
790         
791         /* Check if we're being asked to fill in a recording buffer */
792         if (dstatus & DSTATUS_RN) {
793                 if((harmony.nb_filled_record+2>=MAX_BUFS) || harmony.suspended_recording)
794                 {
795                         harmony.nb_filled_record = 0;
796                         harmony.first_filled_record = 0;
797                         harmony.suspended_recording = 1;
798                         gsc_writel((unsigned long)graveyard.dma_handle, &hpa->rnxtadd);
799                         if (!harmony.suspended_playing)
800                                 harmony_enable_interrupts();
801                 } else {
802                         int buf_to_fill;
803                         buf_to_fill = (harmony.first_filled_record+harmony.nb_filled_record) % MAX_BUFS;
804                         CHECK_WBACK_INV_OFFSET(recorded_buf, HARMONY_BUF_SIZE*buf_to_fill, HARMONY_BUF_SIZE);
805                         gsc_writel((unsigned long)recorded_buf.dma_handle +
806                                         HARMONY_BUF_SIZE*buf_to_fill,
807                                         &hpa->rnxtadd);
808                         harmony.nb_filled_record++;
809                         harmony_enable_interrupts();
810                 }
811
812                 if (harmony.blocked_recording && harmony.nb_filled_record>3)
813                         wake_up_interruptible(&harmony.wq_record);
814         }
815         return IRQ_HANDLED;
816 }
817
818 /*
819  * Sound playing functions
820  */
821
822 static struct file_operations harmony_audio_fops = {
823         .owner          = THIS_MODULE,
824         .llseek         = no_llseek,
825         .read           = harmony_audio_read,
826         .write          = harmony_audio_write,
827         .poll           = harmony_audio_poll,
828         .ioctl          = harmony_audio_ioctl,
829         .open           = harmony_audio_open,
830         .release        = harmony_audio_release,
831 };
832
833 static int harmony_audio_init(void)
834 {
835         /* Request that IRQ */
836         if (request_irq(harmony.dev->irq, harmony_interrupt, 0 ,"harmony", &harmony)) {
837                 printk(KERN_ERR PFX "Error requesting irq %d.\n", harmony.dev->irq);
838                 return -EFAULT;
839         }
840
841         harmony.dsp_unit = register_sound_dsp(&harmony_audio_fops, -1);
842         if (harmony.dsp_unit < 0) {
843                 printk(KERN_ERR PFX "Error registering dsp\n");
844                 free_irq(harmony.dev->irq, &harmony);
845                 return -EFAULT;
846         }
847         
848         /* Clear the buffers so you don't end up with crap in the buffers. */ 
849         harmony_silence(&played_buf, 0, HARMONY_BUF_SIZE*MAX_BUFS);
850
851         /* Make sure this makes it to cache */
852         CHECK_WBACK_INV_OFFSET(played_buf, 0, HARMONY_BUF_SIZE*MAX_BUFS);
853
854         /* Clear out the silent buffer and flush to cache */
855         harmony_silence(&silent, 0, HARMONY_BUF_SIZE);
856         CHECK_WBACK_INV_OFFSET(silent, 0, HARMONY_BUF_SIZE);
857         
858         harmony.audio_open = 0;
859         
860         return 0;
861 }
862
863
864 /*
865  * mixer functions 
866  */
867
868 static void harmony_mixer_set_gain(void)
869 {
870         harmony_wait_CNTL();
871         gsc_writel(harmony.current_gain, &harmony.hpa->gainctl);
872 }
873
874 /* 
875  *  Read gain of selected channel.
876  *  The OSS rate is from 0 (silent) to 100 -> need some conversions
877  *
878  *  The harmony gain are attenuation for output and monitor gain.
879  *                   is amplifaction for input gain
880  */
881 #define to_harmony_level(level,max) ((level)*max/100)
882 #define to_oss_level(level,max) ((level)*100/max)
883
884 static int harmony_mixer_get_level(int channel)
885 {
886         int left_level;
887         int right_level;
888
889         switch (channel) {
890                 case SOUND_MIXER_OGAIN:
891                         left_level  = (harmony.current_gain & GAIN_LO_MASK) >> GAIN_LO_SHIFT;
892                         right_level = (harmony.current_gain & GAIN_RO_MASK) >> GAIN_RO_SHIFT;
893                         left_level  = to_oss_level(MAX_OUTPUT_LEVEL - left_level, MAX_OUTPUT_LEVEL);
894                         right_level = to_oss_level(MAX_OUTPUT_LEVEL - right_level, MAX_OUTPUT_LEVEL);
895                         return (right_level << 8)+left_level;
896                         
897                 case SOUND_MIXER_IGAIN:
898                         left_level = (harmony.current_gain & GAIN_LI_MASK) >> GAIN_LI_SHIFT;
899                         right_level= (harmony.current_gain & GAIN_RI_MASK) >> GAIN_RI_SHIFT;
900                         left_level = to_oss_level(left_level, MAX_INPUT_LEVEL);
901                         right_level= to_oss_level(right_level, MAX_INPUT_LEVEL);
902                         return (right_level << 8)+left_level;
903                         
904                 case SOUND_MIXER_VOLUME:
905                         left_level = (harmony.current_gain & GAIN_MA_MASK) >> GAIN_MA_SHIFT;
906                         left_level = to_oss_level(MAX_VOLUME_LEVEL-left_level, MAX_VOLUME_LEVEL);
907                         return left_level;
908         }
909         return -EINVAL;
910 }
911
912
913
914 /*
915  * Some conversions for the same reasons.
916  * We give back the new real value(s) due to
917  * the rescale.
918  */
919
920 static int harmony_mixer_set_level(int channel, int value)
921 {
922         int left_level;
923         int right_level;
924         int new_left_level;
925         int new_right_level;
926
927         right_level = (value & 0x0000ff00) >> 8;
928         left_level = value & 0x000000ff;
929   
930         switch (channel) {
931                 case SOUND_MIXER_OGAIN:
932                         right_level = to_harmony_level(100-right_level, MAX_OUTPUT_LEVEL);
933                         left_level  = to_harmony_level(100-left_level, MAX_OUTPUT_LEVEL);
934                         new_right_level = to_oss_level(MAX_OUTPUT_LEVEL - right_level, MAX_OUTPUT_LEVEL);
935                         new_left_level  = to_oss_level(MAX_OUTPUT_LEVEL - left_level, MAX_OUTPUT_LEVEL);
936                         harmony.current_gain = (harmony.current_gain & ~(GAIN_LO_MASK | GAIN_RO_MASK)) 
937                                         | (left_level << GAIN_LO_SHIFT) | (right_level << GAIN_RO_SHIFT);
938                         harmony_mixer_set_gain();
939                         return (new_right_level << 8) + new_left_level;
940                         
941                 case SOUND_MIXER_IGAIN:
942                         right_level = to_harmony_level(right_level, MAX_INPUT_LEVEL);
943                         left_level  = to_harmony_level(left_level, MAX_INPUT_LEVEL);
944                         new_right_level = to_oss_level(right_level, MAX_INPUT_LEVEL);
945                         new_left_level  = to_oss_level(left_level, MAX_INPUT_LEVEL);
946                         harmony.current_gain = (harmony.current_gain & ~(GAIN_LI_MASK | GAIN_RI_MASK))
947                                         | (left_level << GAIN_LI_SHIFT) | (right_level << GAIN_RI_SHIFT);
948                         harmony_mixer_set_gain();
949                         return (new_right_level << 8) + new_left_level;
950         
951                 case SOUND_MIXER_VOLUME:
952                         left_level = to_harmony_level(100-left_level, MAX_VOLUME_LEVEL);
953                         new_left_level = to_oss_level(MAX_VOLUME_LEVEL-left_level, MAX_VOLUME_LEVEL);
954                         harmony.current_gain = (harmony.current_gain & ~GAIN_MA_MASK)| (left_level << GAIN_MA_SHIFT);
955                         harmony_mixer_set_gain();
956                         return new_left_level;
957         }
958
959         return -EINVAL;
960 }
961
962 #undef to_harmony_level
963 #undef to_oss_level
964
965 /* 
966  * Return the selected input device (mic or line)
967  */
968
969 static int harmony_mixer_get_recmask(void) 
970 {
971         int current_input_line;
972         
973         current_input_line = (harmony.current_gain & GAIN_IS_MASK) 
974                                     >> GAIN_IS_SHIFT;
975         if (current_input_line) 
976                 return SOUND_MASK_MIC;
977
978         return SOUND_MASK_LINE;
979 }
980
981 /*
982  * Set the input (only one at time, arbitrary priority to line in)
983  */
984
985 static int harmony_mixer_set_recmask(int recmask)
986 {
987         int new_input_line;
988         int new_input_mask;
989
990         if ((recmask & SOUND_MASK_LINE)) {
991                 new_input_line = 0;
992                 new_input_mask = SOUND_MASK_LINE;
993         } else  {
994                 new_input_line = 1;
995                 new_input_mask = SOUND_MASK_MIC;
996         }
997         harmony.current_gain = ((harmony.current_gain & ~GAIN_IS_MASK) | 
998                                 (new_input_line << GAIN_IS_SHIFT ));
999         harmony_mixer_set_gain();
1000         return new_input_mask;
1001 }
1002
1003
1004 /* 
1005  * give the active outlines
1006  */
1007
1008 static int harmony_mixer_get_outmask(void)
1009 {
1010         int outmask = 0;
1011         
1012         if (harmony.current_gain & GAIN_HE_MASK) outmask |=SOUND_MASK_PHONEOUT;
1013         if (harmony.current_gain & GAIN_LE_MASK) outmask |=SOUND_MASK_LINE;
1014         if (harmony.current_gain & GAIN_SE_MASK) outmask |=SOUND_MASK_SPEAKER;
1015         
1016         return outmask;
1017 }
1018
1019
1020 static int harmony_mixer_set_outmask(int outmask)
1021 {
1022         if (outmask & SOUND_MASK_PHONEOUT) 
1023                 harmony.current_gain |= GAIN_HE_MASK; 
1024         else 
1025                 harmony.current_gain &= ~GAIN_HE_MASK;
1026         
1027         if (outmask & SOUND_MASK_LINE) 
1028                 harmony.current_gain |= GAIN_LE_MASK;
1029         else 
1030                 harmony.current_gain &= ~GAIN_LE_MASK;
1031         
1032         if (outmask & SOUND_MASK_SPEAKER) 
1033                 harmony.current_gain |= GAIN_SE_MASK;
1034         else 
1035                 harmony.current_gain &= ~GAIN_SE_MASK;
1036         
1037         harmony_mixer_set_gain();
1038
1039         return (outmask & (SOUND_MASK_PHONEOUT | SOUND_MASK_LINE | SOUND_MASK_SPEAKER));
1040 }
1041
1042 /*
1043  * This code is inspired from sb_mixer.c
1044  */
1045
1046 static int harmony_mixer_ioctl(struct inode * inode, struct file * file,
1047                 unsigned int cmd, unsigned long arg)
1048 {
1049         int val;
1050         int ret;
1051
1052         if (cmd == SOUND_MIXER_INFO) {
1053                 mixer_info info;
1054                 memset(&info, 0, sizeof(info));
1055                 strncpy(info.id, "harmony", sizeof(info.id)-1);
1056                 strncpy(info.name, "Harmony audio", sizeof(info.name)-1);
1057                 info.modify_counter = 1; /* ? */
1058                 if (copy_to_user((void *)arg, &info, sizeof(info)))
1059                         return -EFAULT;
1060                 return 0;
1061         }
1062         
1063         if (cmd == OSS_GETVERSION)
1064                 return put_user(SOUND_VERSION, (int *)arg);
1065
1066         /* read */
1067         val = 0;
1068         if (_SIOC_DIR(cmd) & _SIOC_WRITE)
1069                 if (get_user(val, (int *)arg))
1070                         return -EFAULT;
1071
1072         switch (cmd) {
1073         case MIXER_READ(SOUND_MIXER_CAPS):
1074                 ret = SOUND_CAP_EXCL_INPUT;
1075                 break;
1076         case MIXER_READ(SOUND_MIXER_STEREODEVS):
1077                 ret = SOUND_MASK_IGAIN | SOUND_MASK_OGAIN;
1078                 break;
1079                 
1080         case MIXER_READ(SOUND_MIXER_RECMASK):
1081                 ret = SOUND_MASK_MIC | SOUND_MASK_LINE;
1082                 break;
1083         case MIXER_READ(SOUND_MIXER_DEVMASK):
1084                 ret = SOUND_MASK_OGAIN | SOUND_MASK_IGAIN |
1085                         SOUND_MASK_VOLUME;
1086                 break;
1087         case MIXER_READ(SOUND_MIXER_OUTMASK):
1088                 ret = SOUND_MASK_SPEAKER | SOUND_MASK_LINE |
1089                         SOUND_MASK_PHONEOUT;
1090                 break;
1091                 
1092         case MIXER_WRITE(SOUND_MIXER_RECSRC):
1093                 ret = harmony_mixer_set_recmask(val);
1094                 break;
1095         case MIXER_READ(SOUND_MIXER_RECSRC):
1096                 ret = harmony_mixer_get_recmask();
1097                 break;
1098               
1099         case MIXER_WRITE(SOUND_MIXER_OUTSRC):
1100                 ret = harmony_mixer_set_outmask(val);
1101                 break;
1102         case MIXER_READ(SOUND_MIXER_OUTSRC):
1103                 ret = harmony_mixer_get_outmask();
1104                 break;
1105         
1106         case MIXER_WRITE(SOUND_MIXER_OGAIN):
1107         case MIXER_WRITE(SOUND_MIXER_IGAIN):
1108         case MIXER_WRITE(SOUND_MIXER_VOLUME):
1109                 ret = harmony_mixer_set_level(cmd & 0xff, val);
1110                 break;
1111
1112         case MIXER_READ(SOUND_MIXER_OGAIN):
1113         case MIXER_READ(SOUND_MIXER_IGAIN):
1114         case MIXER_READ(SOUND_MIXER_VOLUME):
1115                 ret = harmony_mixer_get_level(cmd & 0xff);
1116                 break;
1117
1118         default:
1119                 return -EINVAL;
1120         }
1121
1122         if (put_user(ret, (int *)arg))
1123                 return -EFAULT;
1124         return 0;
1125 }
1126
1127
1128 static int harmony_mixer_open(struct inode *inode, struct file *file)
1129 {
1130         if (harmony.mixer_open) 
1131                 return -EBUSY;
1132         harmony.mixer_open = 1;
1133         return 0;
1134 }
1135
1136 static int harmony_mixer_release(struct inode *inode, struct file *file)
1137 {
1138         if (!harmony.mixer_open) 
1139                 return -EBUSY;
1140         harmony.mixer_open = 0;
1141         return 0;
1142 }
1143
1144 static struct file_operations harmony_mixer_fops = {
1145         .owner          = THIS_MODULE,
1146         .llseek         = no_llseek,
1147         .open           = harmony_mixer_open,
1148         .release        = harmony_mixer_release,
1149         .ioctl          = harmony_mixer_ioctl,
1150 };
1151
1152
1153 /*
1154  * Mute all the output and reset Harmony.
1155  */
1156
1157 static void __init harmony_mixer_reset(void)
1158 {
1159         harmony.current_gain = GAIN_TOTAL_SILENCE;
1160         harmony_mixer_set_gain();
1161         harmony_wait_CNTL();
1162         gsc_writel(1, &harmony.hpa->reset);
1163         mdelay(50);             /* wait 50 ms */
1164         gsc_writel(0, &harmony.hpa->reset);
1165         harmony.current_gain = GAIN_DEFAULT;
1166         harmony_mixer_set_gain();
1167 }
1168
1169 static int __init harmony_mixer_init(void)
1170 {
1171         /* Register the device file operations */
1172         harmony.mixer_unit = register_sound_mixer(&harmony_mixer_fops, -1);
1173         if (harmony.mixer_unit < 0) {
1174                 printk(KERN_WARNING PFX "Error Registering Mixer Driver\n");
1175                 return -EFAULT;
1176         }
1177   
1178         harmony_mixer_reset();
1179         harmony.mixer_open = 0;
1180         
1181         return 0;
1182 }
1183
1184
1185
1186 /* 
1187  * This is the callback that's called by the inventory hardware code 
1188  * if it finds a match to the registered driver. 
1189  */
1190 static int __devinit
1191 harmony_driver_probe(struct parisc_device *dev)
1192 {
1193         u8      id;
1194         u8      rev;
1195         u32     cntl;
1196         int     ret;
1197
1198         if (harmony.hpa) {
1199                 /* We only support one Harmony at this time */
1200                 printk(KERN_ERR PFX "driver already registered\n");
1201                 return -EBUSY;
1202         }
1203
1204         harmony.dev = dev;
1205
1206         /* Set the HPA of harmony */
1207         harmony.hpa = (struct harmony_hpa *)dev->hpa;
1208
1209         if (!harmony.dev->irq) {
1210                 printk(KERN_ERR PFX "no irq found\n");
1211                 return -ENODEV;
1212         }
1213
1214         /* Grab the ID and revision from the device */
1215         id = gsc_readb(&harmony.hpa->id);
1216         if ((id | 1) != 0x15) {
1217                 printk(KERN_WARNING PFX "wrong harmony id 0x%02x\n", id);
1218                 return -EBUSY;
1219         }
1220         cntl = gsc_readl(&harmony.hpa->cntl);
1221         rev = (cntl>>20) & 0xff;
1222
1223         printk(KERN_INFO "Lasi Harmony Audio driver " HARMONY_VERSION ", "
1224                         "h/w id %i, rev. %i at 0x%lx, IRQ %i\n",
1225                         id, rev, dev->hpa, harmony.dev->irq);
1226         
1227         /* Make sure the control bit isn't set, although I don't think it 
1228            ever is. */
1229         if (cntl & CNTL_C) {
1230                 printk(KERN_WARNING PFX "CNTL busy\n");
1231                 harmony.hpa = 0;
1232                 return -EBUSY;
1233         }
1234
1235         /* Initialize the memory buffers */
1236         if (harmony_alloc_buffer(&played_buf, MAX_BUFS) || 
1237             harmony_alloc_buffer(&recorded_buf, MAX_BUFS) ||
1238             harmony_alloc_buffer(&graveyard, 1) ||
1239             harmony_alloc_buffer(&silent, 1)) {
1240                 ret = -EBUSY;
1241                 goto out_err;
1242         }
1243
1244         /* Initialize /dev/mixer and /dev/audio  */
1245         if ((ret=harmony_mixer_init())) 
1246                 goto out_err;
1247         if ((ret=harmony_audio_init())) 
1248                 goto out_err;
1249
1250         return 0;
1251
1252 out_err:
1253         harmony.hpa = 0;
1254         harmony_free_buffer(&played_buf);
1255         harmony_free_buffer(&recorded_buf);
1256         harmony_free_buffer(&graveyard);
1257         harmony_free_buffer(&silent);
1258         return ret;
1259 }
1260
1261
1262 static struct parisc_device_id harmony_tbl[] = {
1263  /* { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0007A }, Bushmaster/Flounder */
1264  { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0007B }, /* 712/715 Audio */
1265  { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0007E }, /* Pace Audio */
1266  { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0007F }, /* Outfield / Coral II */
1267  { 0, }
1268 };
1269
1270 MODULE_DEVICE_TABLE(parisc, harmony_tbl);
1271
1272 static struct parisc_driver harmony_driver = {
1273         .name           = "Lasi Harmony",
1274         .id_table       = harmony_tbl,
1275         .probe          = harmony_driver_probe,
1276 };
1277
1278 static int __init init_harmony(void)
1279 {
1280         return register_parisc_driver(&harmony_driver);
1281 }
1282
1283 static void __exit cleanup_harmony(void)
1284 {
1285         free_irq(harmony.dev->irq, &harmony);
1286         unregister_sound_mixer(harmony.mixer_unit);
1287         unregister_sound_dsp(harmony.dsp_unit);
1288         harmony_free_buffer(&played_buf);
1289         harmony_free_buffer(&recorded_buf);
1290         harmony_free_buffer(&graveyard);
1291         harmony_free_buffer(&silent);
1292         unregister_parisc_driver(&harmony_driver);
1293 }
1294
1295
1296 MODULE_AUTHOR("Alex DeVries <alex@linuxcare.com>");
1297 MODULE_DESCRIPTION("Harmony sound driver");
1298 MODULE_LICENSE("GPL");
1299
1300 module_init(init_harmony);
1301 module_exit(cleanup_harmony);
1302