ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / sound / parisc / harmony.c
1 /*
2  *  Harmony chipset driver
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  *  this ALSA driver is based on OSS driver by:
12  *      Copyright 2000 (c) Linuxcare Canada, Alex deVries <alex@linuxcare.com>
13  *      Copyright 2000-2002 (c) Helge Deller <deller@gmx.de>
14  *      Copyright 2001 (c) Matthieu Delahaye <delahaym@esiee.fr>
15  *
16  * TODO:
17  * - use generic DMA interface and ioremap()/iounmap()
18  * - capture is still untested (and probaby non-working)
19  * - spin locks
20  * - implement non-consistent DMA pages
21  * - implement gain meter
22  * - module parameters
23  * - correct cleaning sequence
24  * - better error checking
25  * - try to have a better quality.
26  *   
27  */
28
29 /*
30  * Harmony chipset 'modus operandi'.
31  * - This chipset is found in some HP 32bit workstations, like 712, or B132 class.
32  * most of controls are done through registers. Register are found at a fixed offset
33  * from the hard physical adress, given in struct dev by register_parisc_driver.
34  *
35  * Playback and recording use 4kb pages (dma or not, depending on the machine).
36  *
37  * Most of PCM playback & capture is done through interrupt. When harmony needs
38  * a new buffer to put recorded data or read played PCM, it sends an interrupt.
39  * Bits 2 and 10 of DSTATUS register are '1' when harmony needs respectively
40  * a new page for recording and playing. 
41  * Interrupt are disabled/enabled by writing to bit 32 of DSTATUS. 
42  * Adresses of next page to be played is put in PNXTADD register, next page
43  * to be recorded is put in RNXTADD. There is 2 read-only registers, PCURADD and 
44  * RCURADD that provides adress of current page.
45  * 
46  * Harmony has no way to controll full duplex or half duplex mode. It means
47  * that we always need to provide adresses of playback and capture data, even
48  * when this is not needed. That's why we statically alloc one graveyard
49  * buffer (to put recorded data in play-only mode) and a silence buffer.
50  * 
51  * Bitrate, number of channels and data format are controlled with
52  * the CNTL register.
53  *
54  * Mixer work is done through one register (GAINCTL). Only input gain,
55  * output attenuation and general attenuation control is provided. There is
56  * also controls for enabling/disabling internal speaker and line
57  * input.
58  *
59  * Buffers used by this driver are all DMA consistent. Since harmony is
60  * not "real" pci device, we use a fake struct pci_dev for
61  * pci_alloc_consistent().
62  * (note that some machines -712 for ex.- don't implement DMA consistent
63  * memory, so we will need to use kmalloc instead)
64  */
65
66 #include <linux/delay.h>
67 #include <sound/driver.h>
68 #include <linux/init.h>
69 #include <linux/interrupt.h>
70 #include <linux/slab.h>
71 #include <linux/time.h>
72 #include <linux/wait.h>
73 #include <sound/core.h>
74 #include <sound/control.h>
75 #include <sound/pcm.h>
76 #include <sound/rawmidi.h>
77 #define SNDRV_GET_ID
78 #include <sound/initval.h>
79 #include <sound/info.h>
80 #include <asm/hardware.h>
81 #include <asm/io.h>
82 #include <asm/parisc-device.h>
83
84 MODULE_AUTHOR("Laurent Canet <canetl@esiee.fr>");
85 MODULE_DESCRIPTION("ALSA Harmony sound driver");
86 MODULE_LICENSE("GPL");
87 MODULE_CLASSES("{sound}");
88 MODULE_DEVICES("{{ALSA,Harmony soundcard}}");
89
90 #undef DEBUG
91 #ifdef DEBUG
92 # define DPRINTK printk 
93 #else
94 # define DPRINTK(x,...)
95 #endif
96
97 #define PFX     "harmony: "
98
99 #define MAX_PCM_DEVICES         1
100 #define MAX_PCM_SUBSTREAMS      4
101 #define MAX_MIDI_DEVICES        0
102
103 #define BUFFER_SIZE                     4096
104 #define MAX_BUFS                        10
105
106 /* number of silence & graveyard buffers */
107 #define GRAVEYARD_BUFS          3
108 #define SILENCE_BUFS            3
109
110 #define MAX_BUFFER_SIZE         (MAX_BUFS * BUFFER_SIZE)
111 #define HARMONY_BUF_SIZE        BUFFER_SIZE
112
113 #define HARMONY_CNTL_C          0x80000000
114
115 #define HARMONY_DSTATUS_PN      0x00000200
116 #define HARMONY_DSTATUS_RN      0x00000002
117 #define HARMONY_DSTATUS_IE      0x80000000
118
119 #define HARMONY_DF_16BIT_LINEAR 0x00000000
120 #define HARMONY_DF_8BIT_ULAW    0x00000001
121 #define HARMONY_DF_8BIT_ALAW    0x00000002
122
123 #define HARMONY_SS_MONO         0x00000000
124 #define HARMONY_SS_STEREO       0x00000001
125
126 /*
127  * Channels Mask in mixer register
128  * try some "reasonable" default gain values
129  */
130
131 #define HARMONY_GAIN_TOTAL_SILENCE 0x00F00FFF
132
133 /* the following should be enough (mixer is 
134  * very sensible on harmony)
135  */
136 #define HARMONY_GAIN_DEFAULT       0x0F2FF082
137
138
139 /* useless since only one card is supported ATM */
140 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;      /* Index 0-MAX */
141 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;       /* ID for this card */
142 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE;
143
144 /* Register offset (from base hpa) */
145 #define REG_ID          0x00
146 #define REG_RESET       0x04
147 #define REG_CNTL        0x08
148 #define REG_GAINCTL     0x0C
149 #define REG_PNXTADD     0x10
150 #define REG_PCURADD     0x14
151 #define REG_RNXTADD     0x18
152 #define REG_RCURADD     0x1C
153 #define REG_DSTATUS     0x20
154 #define REG_OV          0x24
155 #define REG_PIO         0x28
156 #define REG_DIAG        0x3C
157
158 /*
159  * main harmony structure
160  */
161
162 typedef struct snd_card_harmony {
163
164         /* spinlocks (To be done) */
165         spinlock_t mixer_lock;
166         spinlock_t control_lock;
167
168         /* parameters */        
169         int irq;
170         unsigned long hpa;
171         int id;
172         int rev;
173         
174         u32 current_gain;
175         int data_format;                /* HARMONY_DF_xx_BIT_xxx */
176         int sample_rate;                /* HARMONY_SR_xx_KHZ */
177         int stereo_select;      /* HARMONY_SS_MONO or HARMONY_SS_STEREO */
178         int format_initialized;
179         
180         unsigned long ply_buffer;
181         int ply_buf;
182         int ply_count;
183         int ply_size;
184         int ply_stopped;
185         int ply_total;
186         
187         unsigned long cap_buffer;
188         int cap_buf;
189         int cap_count;
190         int cap_size;
191         int cap_stopped;
192         int cap_total;
193
194         struct pci_dev *fake_pci_dev; /* The fake pci_dev needed for 
195                                         pci_* functions under ccio. */
196
197         /* the graveyard buffer is used as recording buffer when playback, 
198          * because harmony always want a buffer to put recorded data */
199
200         unsigned char *graveyard_addr;
201         dma_addr_t graveyard_dma;
202         int graveyard_count;
203         
204         /* same thing for silence buffer */
205         unsigned char *silence_addr;
206         dma_addr_t silence_dma;
207         int silence_count;
208         struct snd_dma_device dma_dev;
209
210         /* alsa stuff */
211         snd_card_t *card;
212         snd_pcm_t *pcm;
213         snd_pcm_substream_t *playback_substream;
214         snd_pcm_substream_t *capture_substream;
215         snd_info_entry_t *proc_entry;
216 } snd_card_harmony_t;
217 #define chip_t snd_card_harmony_t
218
219 static snd_card_t *snd_harmony_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
220
221 /* wait to be out of control mode */
222 static inline void snd_harmony_wait_cntl(snd_card_harmony_t *harmony)
223 {
224         int timeout = 5000;
225
226         while ( (gsc_readl(harmony->hpa+REG_CNTL) & HARMONY_CNTL_C) && --timeout)
227         {
228                 /* Wait */ ;    
229         }
230         if (timeout == 0) DPRINTK(KERN_DEBUG PFX "Error: wait cntl timeouted\n");
231 }
232
233
234 /*
235  * sample rate routines 
236  */
237 static unsigned int snd_card_harmony_rates[] = {
238         5125, 6615, 8000, 9600,
239         11025, 16000, 18900, 22050,
240         27428, 32000, 33075, 37800,
241         44100, 48000
242 };
243
244 #define RATES sizeof(snd_card_harmony_rates) / sizeof(snd_card_harmony_rates[0])
245
246 static snd_pcm_hw_constraint_list_t hw_constraint_rates = {
247         .count = RATES,
248         .list = snd_card_harmony_rates,
249         .mask = 0,
250 };
251
252 #define HARMONY_SR_8KHZ         0x08
253 #define HARMONY_SR_16KHZ        0x09
254 #define HARMONY_SR_27KHZ        0x0A
255 #define HARMONY_SR_32KHZ        0x0B
256 #define HARMONY_SR_48KHZ        0x0E
257 #define HARMONY_SR_9KHZ         0x0F
258 #define HARMONY_SR_5KHZ         0x10
259 #define HARMONY_SR_11KHZ        0x11
260 #define HARMONY_SR_18KHZ        0x12
261 #define HARMONY_SR_22KHZ        0x13
262 #define HARMONY_SR_37KHZ        0x14
263 #define HARMONY_SR_44KHZ        0x15
264 #define HARMONY_SR_33KHZ        0x16
265 #define HARMONY_SR_6KHZ         0x17
266
267 /* snd_card_harmony_rate_bits
268  * @rate:       index of current data rate in list
269  * returns: harmony hex code for registers
270  */
271 static unsigned int snd_card_harmony_rate_bits(int rate)
272 {
273         unsigned int idx;
274         
275         for (idx = 0; idx <= RATES; idx++)
276                 if (snd_card_harmony_rates[idx] == rate) break;
277         
278         switch (idx) {
279                 case 0: return HARMONY_SR_5KHZ;
280                 case 1: return HARMONY_SR_6KHZ;
281                 case 2: return HARMONY_SR_8KHZ;
282                 case 3: return HARMONY_SR_9KHZ;
283                 case 4: return HARMONY_SR_11KHZ;
284                 case 5: return HARMONY_SR_16KHZ;
285                 case 6: return HARMONY_SR_18KHZ;
286                 case 7: return HARMONY_SR_22KHZ;
287                 case 8: return HARMONY_SR_27KHZ;
288                 case 9: return HARMONY_SR_32KHZ;
289                 case 10: return HARMONY_SR_33KHZ;
290                 case 11: return HARMONY_SR_37KHZ;
291                 case 12: return HARMONY_SR_44KHZ;
292                 case 13: return HARMONY_SR_48KHZ;
293                 default:  /* fallback */
294                                 return HARMONY_SR_44KHZ;
295         }
296 }
297
298 /*
299  * update controls (data format, sample rate, number of channels)
300  * according to value supplied in data structure
301  */
302 void snd_harmony_update_control(snd_card_harmony_t *harmony) 
303 {
304         u32 default_cntl;
305         
306         /* Set CNTL */
307         default_cntl = (HARMONY_CNTL_C |        /* The C bit */
308                 (harmony->data_format << 6) |   /* Set the data format */
309                 (harmony->stereo_select << 5) | /* Stereo select */
310                 (harmony->sample_rate));                /* Set sample rate */
311         
312         /* initialize CNTL */
313         snd_harmony_wait_cntl(harmony);
314         
315         gsc_writel(default_cntl, harmony->hpa+REG_CNTL);
316         
317 }
318
319 /*
320  * silence a buffer
321  * XXX: alsa could probably do this by itself
322  * XXX: memset hpmc, commented.
323  */
324
325 void snd_harmony_silence(snd_card_harmony_t *harmony,
326                 void *addr, int length)
327 {
328         u8 silence_char;
329         
330         switch(harmony->data_format) {
331                         case HARMONY_DF_8BIT_ULAW: silence_char = 0x55; break;
332                         case HARMONY_DF_8BIT_ALAW: silence_char = 0xff; break;
333                         case HARMONY_DF_16BIT_LINEAR:
334                         default:
335                                                                            silence_char = 0;
336         }
337         //memset(addr, silence_char, length);
338 }
339
340 /*
341  * interruption controls routines
342  */
343
344 static void snd_harmony_disable_interrupts(snd_card_harmony_t *chip) 
345 {
346         snd_harmony_wait_cntl(chip);
347         gsc_writel(0, chip->hpa+REG_DSTATUS); 
348 }
349
350 static void snd_harmony_enable_interrupts(snd_card_harmony_t *chip) 
351 {
352         snd_harmony_wait_cntl(chip);
353         gsc_writel(HARMONY_DSTATUS_IE, chip->hpa+REG_DSTATUS); 
354 }
355
356 /*
357  * interruption routine:
358  * The interrupt routine must provide adresse of next physical pages 
359  * used by harmony
360  */
361 static int snd_card_harmony_interrupt(int irq, void *dev, struct pt_regs *regs)
362 {
363         snd_card_harmony_t *harmony = (snd_card_harmony_t *)dev;
364         u32 dstatus = 0;
365         unsigned long hpa = harmony->hpa;
366         
367         /* Turn off interrupts */
368         snd_harmony_disable_interrupts(harmony);
369         
370         /* wait for control to free */
371         snd_harmony_wait_cntl(harmony);
372         
373         /* Read dstatus and pcuradd (the current address) */
374         dstatus = gsc_readl(hpa+REG_DSTATUS);
375         
376         /* Check if this is a request to get the next play buffer */
377         if (dstatus & HARMONY_DSTATUS_PN) {
378                 if (harmony->playback_substream) {
379                         harmony->ply_buf += harmony->ply_count;
380                         harmony->ply_buf %= harmony->ply_size;
381                 
382                         gsc_writel(harmony->ply_buffer + harmony->ply_buf,
383                                         hpa+REG_PNXTADD);
384                 
385                         snd_pcm_period_elapsed(harmony->playback_substream);
386                         harmony->ply_total++;
387                 } else {
388                         gsc_writel(harmony->silence_dma + 
389                                         (HARMONY_BUF_SIZE*harmony->silence_count),
390                                         hpa+REG_PNXTADD);
391                         harmony->silence_count++;
392                         harmony->silence_count %= SILENCE_BUFS;
393                 }
394         }
395         
396         /* Check if we're being asked to fill in a recording buffer */
397         if (dstatus & HARMONY_DSTATUS_RN) {
398                 if (harmony->capture_substream) {
399                         harmony->cap_buf += harmony->cap_count;
400                         harmony->cap_buf %= harmony->cap_size;
401                 
402                         gsc_writel(harmony->cap_buffer + harmony->cap_buf,
403                                         hpa+REG_RNXTADD);
404                 
405                         snd_pcm_period_elapsed(harmony->capture_substream);
406                         harmony->cap_total++;
407                 } else {
408                         /* graveyard buffer */
409                         gsc_writel(harmony->graveyard_dma +
410                                                 (HARMONY_BUF_SIZE*harmony->graveyard_count),
411                                                 hpa+REG_RNXTADD);
412                         harmony->graveyard_count++;
413                         harmony->graveyard_count %= GRAVEYARD_BUFS;
414                 }
415         }
416         snd_harmony_enable_interrupts(harmony);
417
418         return IRQ_HANDLED;
419 }
420
421 /* 
422  * proc entry
423  * this proc file will give some debugging info
424  */
425
426 static void snd_harmony_proc_read(snd_info_entry_t *entry, snd_info_buffer_t *buffer)
427 {
428         snd_card_harmony_t *harmony = (snd_card_harmony_t *)entry->private_data;
429
430         snd_iprintf(buffer, "LASI Harmony driver\nLaurent Canet <canetl@esiee.fr>\n\n");
431         snd_iprintf(buffer, "IRQ %d, hpa %lx, id %d rev %d\n",
432                         harmony->irq, harmony->hpa,
433                         harmony->id, harmony->rev);
434         snd_iprintf(buffer, "Current gain %lx\n", (unsigned long) harmony->current_gain);
435         snd_iprintf(buffer, "\tsample rate=%d\n", harmony->sample_rate);
436         snd_iprintf(buffer, "\tstereo select=%d\n", harmony->stereo_select);
437         snd_iprintf(buffer, "\tbitperchan=%d\n\n", harmony->data_format);
438         
439         snd_iprintf(buffer, "Play status:\n");
440         snd_iprintf(buffer, "\tstopped %d\n", harmony->ply_stopped);
441         snd_iprintf(buffer, "\tbuffer %lx, count %d\n", harmony->ply_buffer, harmony->ply_count);
442         snd_iprintf(buffer, "\tbuf %d size %d\n\n", harmony->ply_buf, harmony->ply_size);
443         
444         snd_iprintf(buffer, "Capture status:\n");
445         snd_iprintf(buffer, "\tstopped %d\n", harmony->cap_stopped);
446         snd_iprintf(buffer, "\tbuffer %lx, count %d\n", harmony->cap_buffer, harmony->cap_count);
447         snd_iprintf(buffer, "\tbuf %d, size %d\n\n", harmony->cap_buf, harmony->cap_size);
448
449         snd_iprintf(buffer, "Funny stats: total played=%d, recorded=%d\n\n", harmony->ply_total, harmony->cap_total);
450                 
451         snd_iprintf(buffer, "Register:\n");
452         snd_iprintf(buffer, "\tgainctl: %lx\n", (unsigned long) gsc_readl(harmony->hpa+REG_GAINCTL));
453         snd_iprintf(buffer, "\tcntl: %lx\n", (unsigned long) gsc_readl(harmony->hpa+REG_CNTL));
454         snd_iprintf(buffer, "\tid: %lx\n", (unsigned long) gsc_readl(harmony->hpa+REG_ID));
455         snd_iprintf(buffer, "\tpcuradd: %lx\n", (unsigned long) gsc_readl(harmony->hpa+REG_PCURADD));
456         snd_iprintf(buffer, "\trcuradd: %lx\n", (unsigned long) gsc_readl(harmony->hpa+REG_RCURADD));
457         snd_iprintf(buffer, "\tpnxtadd: %lx\n", (unsigned long) gsc_readl(harmony->hpa+REG_PNXTADD));
458         snd_iprintf(buffer, "\trnxtadd: %lx\n", (unsigned long) gsc_readl(harmony->hpa+REG_RNXTADD));
459         snd_iprintf(buffer, "\tdstatus: %lx\n", (unsigned long) gsc_readl(harmony->hpa+REG_DSTATUS));
460         snd_iprintf(buffer, "\tov: %lx\n\n", (unsigned long) gsc_readl(harmony->hpa+REG_OV));
461         
462 }
463
464 static void __devinit snd_harmony_proc_init(snd_card_harmony_t *harmony)
465 {
466         snd_info_entry_t *entry;
467         
468         if ((entry = snd_info_create_card_entry(harmony->card, "harmony", harmony->card->proc_root)) != NULL) {
469                 entry->content = SNDRV_INFO_CONTENT_TEXT;
470                 entry->private_data = harmony;
471                 entry->mode = S_IFREG | S_IRUGO | S_IWUSR;
472                 entry->c.text.read_size = 2048;  /* should be enough */
473                 entry->c.text.read = snd_harmony_proc_read;
474                 if (snd_info_register(entry) < 0) {
475                         snd_info_free_entry(entry);
476                         entry = NULL;
477                 }
478         }
479         harmony->proc_entry = entry;
480 }
481
482 static void snd_harmony_proc_done(snd_card_harmony_t *harmony)
483 {
484         if (harmony->proc_entry) {
485                 snd_info_unregister(harmony->proc_entry);
486                 harmony->proc_entry = NULL;
487         }
488 }
489
490 /* 
491  * PCM Stuff
492  */
493
494 static int snd_card_harmony_playback_ioctl(snd_pcm_substream_t * substream,
495                                          unsigned int cmd,
496                                          void *arg)
497 {
498         return snd_pcm_lib_ioctl(substream, cmd, arg);
499 }
500
501 static int snd_card_harmony_capture_ioctl(snd_pcm_substream_t * substream,
502                                         unsigned int cmd,
503                                         void *arg)
504 {
505         return snd_pcm_lib_ioctl(substream, cmd, arg);
506 }
507
508 static int snd_card_harmony_playback_trigger(snd_pcm_substream_t * substream,
509                                            int cmd)
510 {
511         snd_card_harmony_t *harmony = snd_pcm_substream_chip(substream);
512         
513         switch (cmd) {
514                 case SNDRV_PCM_TRIGGER_STOP:
515                         if (harmony->ply_stopped) 
516                                 return -EBUSY;
517                         harmony->ply_stopped = 1;
518                         snd_harmony_disable_interrupts(harmony);
519                         break;
520                 case SNDRV_PCM_TRIGGER_START:
521                         if (!harmony->ply_stopped)
522                                 return -EBUSY;
523                         harmony->ply_stopped = 0;
524                         /* write the location of the first buffer to play */
525                         gsc_writel(harmony->ply_buffer, harmony->hpa+REG_PNXTADD);
526                         snd_harmony_enable_interrupts(harmony);
527                         break;
528                 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
529                 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
530                 case SNDRV_PCM_TRIGGER_SUSPEND:
531                         DPRINTK(KERN_INFO PFX "received unimplemented trigger: %d\n", cmd);
532                 default:
533                         return -EINVAL;
534         }
535         return 0;
536 }
537
538 static int snd_card_harmony_capture_trigger(snd_pcm_substream_t * substream,
539                                           int cmd)
540 {
541         snd_card_harmony_t *harmony = snd_pcm_substream_chip(substream);
542         
543         switch (cmd) {
544                 case SNDRV_PCM_TRIGGER_STOP:
545                         if (harmony->cap_stopped) 
546                                 return -EBUSY;
547                         harmony->cap_stopped = 1;
548                         snd_harmony_disable_interrupts(harmony);
549                         break;
550                 case SNDRV_PCM_TRIGGER_START:
551                         if (!harmony->cap_stopped)
552                                 return -EBUSY;
553                         harmony->cap_stopped = 0;
554                         snd_harmony_enable_interrupts(harmony);
555                         break;
556                 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
557                 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
558                 case SNDRV_PCM_TRIGGER_SUSPEND:
559                         DPRINTK(KERN_INFO PFX "Received unimplemented trigger: %d\n", cmd);
560                 default:
561                         return -EINVAL;
562         }
563         return 0;
564 }
565
566 static int snd_card_harmony_playback_prepare(snd_pcm_substream_t * substream)
567 {
568         snd_card_harmony_t *harmony = snd_pcm_substream_chip(substream);
569         snd_pcm_runtime_t *runtime = substream->runtime;
570         
571         harmony->ply_size                       = snd_pcm_lib_buffer_bytes(substream);
572         harmony->ply_count                      = snd_pcm_lib_period_bytes(substream);
573         harmony->ply_buf                        = 0;
574         harmony->ply_stopped            = 1;
575         
576         /* initialize given sample rate */
577         harmony->sample_rate = snd_card_harmony_rate_bits(runtime->rate);
578
579         /* data format */
580         if (snd_pcm_format_width(runtime->format) == 16) harmony->data_format = HARMONY_DF_16BIT_LINEAR;
581         else harmony->data_format = HARMONY_DF_8BIT_ULAW;
582         
583         /* number of channels */
584         if (runtime->channels == 2) harmony->stereo_select = HARMONY_SS_STEREO;
585         else harmony->stereo_select = HARMONY_SS_MONO;
586         
587         DPRINTK(KERN_INFO PFX "Playback_prepare, sr=%d(%x), df=%x, ss=%x hpa=%lx\n", runtime->rate,
588                                 harmony->sample_rate, harmony->data_format, harmony->stereo_select, harmony->hpa);
589         snd_harmony_update_control(harmony);
590         harmony->format_initialized = 1;
591         harmony->ply_buffer = runtime->dma_addr;
592         
593         return 0;
594 }
595
596 static int snd_card_harmony_capture_prepare(snd_pcm_substream_t * substream)
597 {
598         snd_pcm_runtime_t *runtime = substream->runtime;
599         snd_card_harmony_t *harmony = snd_pcm_substream_chip(substream);
600         
601         harmony->cap_size                       = snd_pcm_lib_buffer_bytes(substream);
602         harmony->cap_count                      = snd_pcm_lib_period_bytes(substream);
603         harmony->cap_count                      = 0;
604         harmony->cap_stopped            = 1;
605
606         /* initialize given sample rate */
607         harmony->sample_rate = snd_card_harmony_rate_bits(runtime->rate);
608         
609         /* data format */
610         if (snd_pcm_format_width(runtime->format) == 16) harmony->data_format = HARMONY_DF_16BIT_LINEAR;
611         else harmony->data_format = HARMONY_DF_8BIT_ULAW;
612         
613         /* number of channels */
614         if (runtime->channels == 1) harmony->stereo_select = HARMONY_SS_MONO;
615         else if (runtime->channels == 2) harmony->stereo_select = HARMONY_SS_STEREO;
616                 
617         snd_harmony_update_control(harmony);
618         harmony->format_initialized = 1;
619         
620         harmony->cap_buffer = runtime->dma_addr;
621
622         return 0;
623 }
624
625 static snd_pcm_uframes_t snd_card_harmony_capture_pointer(snd_pcm_substream_t * substream)
626 {
627         snd_pcm_runtime_t *runtime = substream->runtime;
628         snd_card_harmony_t *harmony = snd_pcm_substream_chip(substream);
629         unsigned long rcuradd;
630         int recorded;
631         
632         if (harmony->cap_stopped) return 0;
633         if (harmony->capture_substream == NULL) return 0;
634
635         rcuradd = gsc_readl(harmony->hpa+REG_RCURADD);
636         recorded = (rcuradd - harmony->cap_buffer);
637         recorded %= harmony->cap_size;
638                 
639         return bytes_to_frames(runtime, recorded);
640 }
641
642 /*
643  */
644
645 static snd_pcm_uframes_t snd_card_harmony_playback_pointer(snd_pcm_substream_t * substream)
646 {
647         snd_pcm_runtime_t *runtime = substream->runtime;
648         snd_card_harmony_t *harmony = snd_pcm_substream_chip(substream);
649         int played;
650         long int pcuradd = gsc_readl(harmony->hpa+REG_PCURADD);
651         
652         if ((harmony->ply_stopped) || (harmony->playback_substream == NULL)) return 0;
653         if ((harmony->ply_buffer == 0) || (harmony->ply_size == 0)) return 0;
654         
655         played = (pcuradd - harmony->ply_buffer);
656         
657         printk(KERN_DEBUG PFX "Pointer is %lx-%lx = %d\n", pcuradd, harmony->ply_buffer, played);       
658
659         if (pcuradd > harmony->ply_buffer + harmony->ply_size) return 0;
660         
661         return bytes_to_frames(runtime, played);
662 }
663
664 static snd_pcm_hardware_t snd_card_harmony_playback =
665 {
666         .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 
667                                         SNDRV_PCM_INFO_JOINT_DUPLEX | 
668                                         SNDRV_PCM_INFO_MMAP_VALID |
669                                         SNDRV_PCM_INFO_BLOCK_TRANSFER),
670         .formats =              (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_BE | 
671                                         SNDRV_PCM_FMTBIT_A_LAW | SNDRV_PCM_FMTBIT_MU_LAW),
672         .rates =                SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
673         .rate_min =             5500,
674         .rate_max =             48000,
675         .channels_min =         1,
676         .channels_max =         2,
677         .buffer_bytes_max =     MAX_BUFFER_SIZE,
678         .period_bytes_min =     HARMONY_BUF_SIZE,
679         .period_bytes_max =     HARMONY_BUF_SIZE,
680         .periods_min =          1,
681         .periods_max =          MAX_BUFS,
682         .fifo_size =            0,
683 };
684
685 static snd_pcm_hardware_t snd_card_harmony_capture =
686 {
687         .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 
688                                         SNDRV_PCM_INFO_JOINT_DUPLEX | 
689                                         SNDRV_PCM_INFO_MMAP_VALID |
690                                         SNDRV_PCM_INFO_BLOCK_TRANSFER),
691         .formats =              (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_BE | 
692                                         SNDRV_PCM_FMTBIT_A_LAW | SNDRV_PCM_FMTBIT_MU_LAW),
693         .rates =                SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
694         .rate_min =             5500,
695         .rate_max =             48000,
696         .channels_min =         1,
697         .channels_max =         2,
698         .buffer_bytes_max =     MAX_BUFFER_SIZE,
699         .period_bytes_min =     HARMONY_BUF_SIZE,
700         .period_bytes_max =     HARMONY_BUF_SIZE,
701         .periods_min =          1,
702         .periods_max =          MAX_BUFS,
703         .fifo_size =            0,
704 };
705
706 static int snd_card_harmony_playback_open(snd_pcm_substream_t * substream)
707 {
708         snd_card_harmony_t *harmony = snd_pcm_substream_chip(substream);
709         snd_pcm_runtime_t *runtime = substream->runtime;
710         int err;
711         
712         /*
713          * harmony is not "real" pci, but we need a pci_dev
714          * to alloc PCI DMA pages
715          */
716         substream->runtime->dma_private = harmony->fake_pci_dev;
717 //      substream->dma_type = SNDRV_PCM_DMA_TYPE_PCI;
718         
719         harmony->playback_substream = substream;
720         runtime->hw = snd_card_harmony_playback;
721         snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraint_rates);
722         
723         if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
724                 return err;
725         
726         return 0;
727 }
728
729 static int snd_card_harmony_capture_open(snd_pcm_substream_t * substream)
730 {
731         snd_card_harmony_t *harmony = snd_pcm_substream_chip(substream);
732         snd_pcm_runtime_t *runtime = substream->runtime;
733         int err;
734         
735         
736         /*
737          * harmony is not "real" pci, but we need a pci_dev
738          * to alloc PCI DMA pages
739          */
740         substream->runtime->dma_private = harmony->fake_pci_dev;
741 //      substream->dma_type = SNDRV_PCM_DMA_TYPE_PCI;
742
743         harmony->capture_substream = substream;
744         runtime->hw = snd_card_harmony_capture;
745         snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraint_rates);
746         if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
747                 return err;
748         return 0;
749
750 }
751
752 static int snd_card_harmony_playback_close(snd_pcm_substream_t * substream)
753 {
754         snd_card_harmony_t *harmony = snd_pcm_substream_chip(substream);
755         snd_pcm_lib_free_pages(substream);
756         
757         harmony->playback_substream = NULL;
758         harmony->ply_size                       = 0;
759         harmony->ply_buf                        = 0;
760         harmony->ply_buffer                     = 0;
761         harmony->ply_count                      = 0;
762         harmony->ply_stopped            = 1;
763         harmony->format_initialized = 0;
764         
765         return 0;
766 }
767
768 static int snd_card_harmony_capture_close(snd_pcm_substream_t * substream)
769 {
770         snd_card_harmony_t *harmony = snd_pcm_substream_chip(substream);
771         
772         snd_pcm_lib_free_pages(substream);
773         
774         harmony->capture_substream = NULL;
775         harmony->cap_size                       = 0;
776         harmony->cap_buf                        = 0;
777         harmony->cap_buffer                     = 0;
778         harmony->cap_count                      = 0;
779         harmony->cap_stopped            = 1;
780         harmony->format_initialized = 0;
781         
782         return 0;
783 }
784
785 static int snd_card_harmony_hw_params(snd_pcm_substream_t *substream, 
786                            snd_pcm_hw_params_t * hw_params)
787 {
788         snd_pcm_runtime_t *runtime = substream->runtime;
789         int err;
790         
791         err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
792         DPRINTK(KERN_INFO PFX "HW Params returned %d, dma_addr %lx\n", err,
793                         (unsigned long)runtime->dma_addr);
794         return err;
795 }
796
797 static int snd_card_harmony_hw_free(snd_pcm_substream_t *substream) 
798 {
799         snd_pcm_lib_free_pages(substream);              
800         return 0;
801 }
802
803 static snd_pcm_ops_t snd_card_harmony_playback_ops = {
804         .open =                 snd_card_harmony_playback_open,
805         .close =                snd_card_harmony_playback_close,
806         .ioctl =                snd_card_harmony_playback_ioctl,
807         .hw_params =    snd_card_harmony_hw_params,
808         .hw_free =              snd_card_harmony_hw_free,
809         .prepare =              snd_card_harmony_playback_prepare,
810         .trigger =              snd_card_harmony_playback_trigger,
811         .pointer =              snd_card_harmony_playback_pointer,
812 };
813
814 static snd_pcm_ops_t snd_card_harmony_capture_ops = {
815         .open =                 snd_card_harmony_capture_open,
816         .close =                snd_card_harmony_capture_close,
817         .ioctl =                snd_card_harmony_capture_ioctl,
818         .hw_params =    snd_card_harmony_hw_params,
819         .hw_free =              snd_card_harmony_hw_free,
820         .prepare =              snd_card_harmony_capture_prepare,
821         .trigger =              snd_card_harmony_capture_trigger,
822         .pointer =              snd_card_harmony_capture_pointer,
823 };
824
825 static int snd_card_harmony_pcm_init(snd_card_harmony_t *harmony, int device)
826 {
827         snd_pcm_t *pcm;
828         int err;
829
830         /* Request that IRQ */
831         if (request_irq(harmony->irq, snd_card_harmony_interrupt, 0 ,"harmony", harmony)) {
832                 printk(KERN_ERR PFX "Error requesting irq %d.\n", harmony->irq);
833                 return -EFAULT;
834         }
835         
836         snd_harmony_disable_interrupts(harmony);
837         
838         if ((err = snd_pcm_new(harmony->card, "Harmony", device, 1, 1, &pcm)) < 0)
839                 return err;
840         
841         snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_card_harmony_playback_ops);
842         snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_card_harmony_capture_ops); 
843         
844         pcm->private_data = harmony;
845         pcm->info_flags = 0;
846         strcpy(pcm->name, "Harmony");
847         harmony->pcm = pcm;
848         
849         /* initialize graveyard buffer */
850         harmony->dma_dev.type = SNDRV_DMA_TYPE_PCI;
851         harmony->dma_dev.dev = snd_dma_pci_data(harmony->fake_pci_dev); 
852         harmony->graveyard_addr = snd_dma_alloc_pages(&chip->dma_dev,
853                         HARMONY_BUF_SIZE*GRAVEYARD_BUFS, &harmony->graveyard_dma);
854         harmony->graveyard_count = 0;
855         
856         /* initialize silence buffers */
857         harmony->silence_addr = snd_dma_alloc_pages(&chip->dma_dev,
858                         HARMONY_BUF_SIZE*SILENCE_BUFS, &harmony->silence_dma);
859         harmony->silence_count = 0;
860
861         harmony->ply_stopped = harmony->cap_stopped = 1;
862         
863         harmony->playback_substream = NULL;
864         harmony->capture_substream = NULL;
865         harmony->graveyard_count = 0;
866         
867         snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
868                                               snd_dma_pci_data(harmony->fake_pci_dev),
869                                               64 * 1024, 128 * 1024);
870
871         return 0;
872 }
873
874 /*
875  * mixer routines
876  */
877
878 static void snd_harmony_set_new_gain(snd_card_harmony_t *harmony)
879 {
880         DPRINTK(KERN_INFO PFX "Setting new gain %x at %lx\n", harmony->current_gain, harmony->hpa+REG_GAINCTL);
881         /* Wait until we're out of control mode */
882         snd_harmony_wait_cntl(harmony);
883         
884         gsc_writel(harmony->current_gain, harmony->hpa+REG_GAINCTL);
885 }
886
887 #define HARMONY_VOLUME(xname, left_shift, right_shift, mask, invert) \
888 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
889   .info = snd_harmony_mixercontrol_info, \
890   .get = snd_harmony_volume_get, .put = snd_harmony_volume_put, \
891   .private_value = ((left_shift) | ((right_shift) << 8) | ((mask) << 16) | ((invert) << 24)) }
892
893 static int snd_harmony_mixercontrol_info(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t * uinfo)
894 {
895         int mask = (kcontrol->private_value >> 16) & 0xff;
896         int left_shift = (kcontrol->private_value) & 0xff;
897         int right_shift = (kcontrol->private_value >> 8) & 0xff;
898         
899         uinfo->type = (mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER);
900         uinfo->count = (left_shift == right_shift) ? 1 : 2;
901         uinfo->value.integer.min = 0;
902         uinfo->value.integer.max = mask;
903         return 0;
904 }
905  
906 static int snd_harmony_volume_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
907 {
908         snd_card_harmony_t *harmony = _snd_kcontrol_chip(kcontrol);
909         int shift_left = (kcontrol->private_value) & 0xff;
910         int shift_right = (kcontrol->private_value >> 8) & 0xff;
911         int mask = (kcontrol->private_value >> 16) & 0xff;
912         int invert = (kcontrol->private_value >> 24) & 0xff;
913         unsigned long flags;
914         int left, right;
915         
916         spin_lock_irqsave(&harmony->mixer_lock, flags);
917         left = (harmony->current_gain >> shift_left) & mask;
918         right = (harmony->current_gain >> shift_right) & mask;
919
920         if (invert) {
921                 left = mask - left;
922                 right = mask - right;
923         }
924         ucontrol->value.integer.value[0] = left;
925         ucontrol->value.integer.value[1] = right;
926         spin_unlock_irqrestore(&harmony->mixer_lock, flags);
927
928         return 0;
929 }  
930
931 static int snd_harmony_volume_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
932 {
933         snd_card_harmony_t *harmony = _snd_kcontrol_chip(kcontrol);
934         int shift_left = (kcontrol->private_value) & 0xff;
935         int shift_right = (kcontrol->private_value >> 8) & 0xff;
936         int mask = (kcontrol->private_value >> 16) & 0xff;
937         int invert = (kcontrol->private_value >> 24) & 0xff;
938         unsigned long flags;
939         int left, right;
940         int old_gain = harmony->current_gain;
941         
942         left = ucontrol->value.integer.value[0] & mask;
943         right = ucontrol->value.integer.value[1] & mask;
944         if (invert) {
945                 left = mask - left;
946                 right = mask - right;
947         }
948         
949         spin_lock_irqsave(&harmony->mixer_lock, flags);
950         harmony->current_gain = harmony->current_gain & ~( (mask << shift_right) | (mask << shift_left));
951         harmony->current_gain = harmony->current_gain | ((left << shift_left) | (right << shift_right) );
952         snd_harmony_set_new_gain(harmony);
953         spin_unlock_irqrestore(&harmony->mixer_lock, flags);
954         
955         return (old_gain - harmony->current_gain);
956 }
957
958 #define HARMONY_CONTROLS (sizeof(snd_harmony_controls)/sizeof(snd_kcontrol_new_t))
959
960 static snd_kcontrol_new_t snd_harmony_controls[] = {
961 HARMONY_VOLUME("PCM Capture Volume", 12, 16, 0x0f, 0),
962 HARMONY_VOLUME("Master Volume", 20, 20, 0x0f, 1),
963 HARMONY_VOLUME("PCM Playback Volume", 6, 0, 0x3f, 1),
964 };
965
966 static void snd_harmony_reset_codec(snd_card_harmony_t *harmony)
967 {
968         snd_harmony_wait_cntl(harmony);
969         gsc_writel(1, harmony->hpa+REG_RESET);
970         mdelay(50);             /* wait 50 ms */
971         gsc_writel(0, harmony->hpa+REG_RESET);
972 }
973
974 /*
975  * Mute all the output and reset Harmony.
976  */
977
978 static void __init snd_harmony_mixer_reset(snd_card_harmony_t *harmony)
979 {
980         harmony->current_gain = HARMONY_GAIN_TOTAL_SILENCE;
981         snd_harmony_set_new_gain(harmony);
982         snd_harmony_reset_codec(harmony);
983         harmony->current_gain = HARMONY_GAIN_DEFAULT;
984         snd_harmony_set_new_gain(harmony);
985 }
986
987
988 int __init snd_card_harmony_mixer_init(snd_card_harmony_t *harmony)
989 {
990         snd_card_t *card = harmony->card;
991         int idx, err;
992
993         snd_assert(harmony != NULL, return -EINVAL);
994         strcpy(card->mixername, "Harmony Gain control interface");
995
996         for (idx = 0; idx < HARMONY_CONTROLS; idx++) {
997                 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_harmony_controls[idx], harmony))) < 0)
998                         return err;
999         }
1000         
1001         snd_harmony_mixer_reset(harmony);
1002
1003         return 0;
1004 }
1005
1006 static int snd_card_harmony_create(snd_card_t *card, struct parisc_device *pa_dev, snd_card_harmony_t *harmony)
1007 {
1008         u32     cntl;
1009         
1010         harmony->card = card;
1011         
1012         /* Set the HPA of harmony */
1013         harmony->hpa = pa_dev->hpa;
1014         
1015
1016         harmony->irq = pa_dev->irq;
1017         if (!harmony->irq) {
1018                 printk(KERN_ERR PFX "no irq found\n");
1019                 return -ENODEV;
1020         }
1021
1022         /* Grab the ID and revision from the device */
1023         harmony->id = (gsc_readl(harmony->hpa+REG_ID)&0x00ff0000) >> 16;
1024         if ((harmony->id | 1) != 0x15) {
1025                 printk(KERN_WARNING PFX "wrong harmony id 0x%02x\n", harmony->id);
1026                 return -EBUSY;
1027         }
1028         cntl = gsc_readl(harmony->hpa+REG_CNTL);
1029         harmony->rev = (cntl>>20) & 0xff;
1030
1031         printk(KERN_INFO "Lasi Harmony Audio driver h/w id %i, rev. %i at 0x%lx, IRQ %i\n",     harmony->id, harmony->rev, pa_dev->hpa, harmony->irq);
1032         
1033         /* Make sure the control bit isn't set, although I don't think it 
1034            ever is. */
1035         if (cntl & HARMONY_CNTL_C) {
1036                 printk(KERN_WARNING PFX "CNTL busy\n");
1037                 harmony->hpa = 0;
1038                 return -EBUSY;
1039         }
1040         
1041         /* a fake pci_dev is needed for pci_* functions under ccio */
1042         harmony->fake_pci_dev = ccio_get_fake(pa_dev);
1043         return 0;
1044 }
1045         
1046 static int __init snd_card_harmony_probe(struct parisc_device *pa_dev)
1047 {
1048         static int dev;
1049         snd_card_harmony_t *chip;
1050         snd_card_t *card;
1051         int err;
1052         
1053     if (dev >= SNDRV_CARDS)
1054                 return -ENODEV;
1055         if (!enable[dev]) {
1056                 dev++;
1057                 return -ENOENT;
1058         }
1059         
1060         snd_harmony_cards[dev] = snd_card_new(index[dev], id[dev], THIS_MODULE,
1061                             sizeof(snd_card_harmony_t));
1062         card = snd_harmony_cards[dev];
1063                                 
1064         if (card == NULL)
1065                 return -ENOMEM;
1066         chip = (struct snd_card_harmony *)card->private_data;
1067         
1068         if ((err = snd_card_harmony_create(card, pa_dev, chip)) < 0) {
1069                 printk(KERN_ERR PFX "Creation failed\n");
1070                 snd_card_free(card);
1071                 return err;
1072         }
1073         if ((err = snd_card_harmony_pcm_init(chip, dev)) < 0) {
1074                 printk(KERN_ERR PFX "PCM Init failed\n");
1075                 snd_card_free(card);
1076                 return err;
1077         }
1078         if ((err = snd_card_harmony_mixer_init(chip)) < 0) {
1079                 printk(KERN_ERR PFX "Mixer init failed\n");
1080                 snd_card_free(card);
1081                 return err;
1082         }
1083         
1084         snd_harmony_proc_init(chip);
1085         
1086         strcpy(card->driver, "Harmony");
1087         strcpy(card->shortname, "ALSA driver for LASI Harmony");
1088         sprintf(card->longname, "%s at h/w, id %i, rev. %i hpa 0x%lx, IRQ %i\n",card->shortname, chip->id, chip->rev, pa_dev->hpa, chip->irq);
1089
1090         if ((err = snd_card_register(card)) < 0) {
1091                 snd_card_free(card);
1092                 return err;
1093         }
1094
1095         printk(KERN_DEBUG PFX "Successfully registered harmony pcm backend & mixer %d\n", dev);
1096         dev++;
1097         return 0;
1098 }
1099
1100 static struct parisc_device_id snd_card_harmony_devicetbl[] = {
1101  { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0007A }, /* Bushmaster/Flounder */
1102  { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0007B }, /* 712/715 Audio */
1103  { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0007E }, /* Pace Audio */
1104  { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0007F }, /* Outfield / Coral II */
1105  { 0, }
1106 };
1107
1108 MODULE_DEVICE_TABLE(parisc, snd_card_harmony_devicetbl);
1109
1110 /*
1111  * bloc device parisc. c'est une structure qui definit un device
1112  * que l'on trouve sur parisc. 
1113  * On y trouve les differents numeros HVERSION correspondant au device
1114  * en question (ce qui permet a l'inventory de l'identifier) et la fonction
1115  * d'initialisation du chose 
1116  */
1117
1118 static struct parisc_driver snd_card_harmony_driver = {
1119         .name           = "Lasi ALSA Harmony",
1120         .id_table       = snd_card_harmony_devicetbl,
1121         .probe          = snd_card_harmony_probe,
1122 };
1123
1124 static int __init alsa_card_harmony_init(void)
1125 {
1126         int err;
1127         
1128         if ((err = register_parisc_driver(&snd_card_harmony_driver)) < 0) {
1129                 printk(KERN_ERR "Harmony soundcard not found or device busy\n");
1130                 return err;
1131         }
1132
1133         return 0;
1134 }
1135
1136 static void __exit alsa_card_harmony_exit(void)
1137 {
1138         int idx;
1139         snd_card_harmony_t *harmony;
1140         
1141         for (idx = 0; idx < SNDRV_CARDS; idx++)
1142         {
1143                 if (snd_harmony_cards[idx] != NULL)
1144                 {       
1145                         DPRINTK(KERN_INFO PFX "Freeing card %d\n", idx);
1146                         harmony = snd_harmony_cards[idx]->private_data;
1147                         snd_harmony_proc_done(harmony);
1148                         free_irq(harmony->irq, snd_card_harmony_interrupt);
1149                         printk(KERN_INFO PFX "Card unloaded %d, irq=%d\n", idx, harmony->irq);
1150                         snd_card_free(snd_harmony_cards[idx]);
1151                 }
1152         }       
1153 }
1154
1155 module_init(alsa_card_harmony_init)
1156 module_exit(alsa_card_harmony_exit)