ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / sound / isa / sb / sb16_csp.c
1 /*
2  *  Copyright (c) 1999 by Uros Bizjak <uros@kss-loka.si>
3  *                        Takashi Iwai <tiwai@suse.de>
4  *
5  *  SB16ASP/AWE32 CSP control
6  *
7  *  CSP microcode loader:
8  *   alsa-tools/sb16_csp/ 
9  *
10  *   This program is free software; you can redistribute it and/or modify 
11  *   it under the terms of the GNU General Public License as published by
12  *   the Free Software Foundation; either version 2 of the License, or
13  *   (at your option) any later version.
14  *
15  *   This program is distributed in the hope that it will be useful,
16  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *   GNU General Public License for more details.
19  *
20  *   You should have received a copy of the GNU General Public License
21  *   along with this program; if not, write to the Free Software
22  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
23  *
24  */
25
26 #include <sound/driver.h>
27 #include <linux/delay.h>
28 #include <linux/init.h>
29 #include <linux/slab.h>
30 #include <sound/core.h>
31 #include <sound/control.h>
32 #include <sound/info.h>
33 #include <sound/sb16_csp.h>
34 #include <sound/initval.h>
35
36 #define chip_t snd_sb_csp_t
37
38 MODULE_AUTHOR("Uros Bizjak <uros@kss-loka.si>");
39 MODULE_DESCRIPTION("ALSA driver for SB16 Creative Signal Processor");
40 MODULE_LICENSE("GPL");
41 MODULE_CLASSES("{sound}");
42
43 #ifdef SNDRV_LITTLE_ENDIAN
44 #define CSP_HDR_VALUE(a,b,c,d)  ((a) | ((b)<<8) | ((c)<<16) | ((d)<<24))
45 #else
46 #define CSP_HDR_VALUE(a,b,c,d)  ((d) | ((c)<<8) | ((b)<<16) | ((a)<<24))
47 #endif
48 #define LE_SHORT(v)             le16_to_cpu(v)
49 #define LE_INT(v)               le32_to_cpu(v)
50
51 #define RIFF_HEADER     CSP_HDR_VALUE('R', 'I', 'F', 'F')
52 #define CSP__HEADER     CSP_HDR_VALUE('C', 'S', 'P', ' ')
53 #define LIST_HEADER     CSP_HDR_VALUE('L', 'I', 'S', 'T')
54 #define FUNC_HEADER     CSP_HDR_VALUE('f', 'u', 'n', 'c')
55 #define CODE_HEADER     CSP_HDR_VALUE('c', 'o', 'd', 'e')
56 #define INIT_HEADER     CSP_HDR_VALUE('i', 'n', 'i', 't')
57 #define MAIN_HEADER     CSP_HDR_VALUE('m', 'a', 'i', 'n')
58
59 /*
60  * RIFF data format
61  */
62 typedef struct riff_header {
63         __u32 name;
64         __u32 len;
65 } riff_header_t;
66
67 typedef struct desc_header {
68         riff_header_t info;
69         __u16 func_nr;
70         __u16 VOC_type;
71         __u16 flags_play_rec;
72         __u16 flags_16bit_8bit;
73         __u16 flags_stereo_mono;
74         __u16 flags_rates;
75 } desc_header_t;
76
77 /*
78  * prototypes
79  */
80 static void snd_sb_csp_free(snd_hwdep_t *hw);
81 static int snd_sb_csp_open(snd_hwdep_t * hw, struct file *file);
82 static int snd_sb_csp_ioctl(snd_hwdep_t * hw, struct file *file, unsigned int cmd, unsigned long arg);
83 static int snd_sb_csp_release(snd_hwdep_t * hw, struct file *file);
84
85 static int csp_detect(sb_t *chip, int *version);
86 static int set_codec_parameter(sb_t *chip, unsigned char par, unsigned char val);
87 static int set_register(sb_t *chip, unsigned char reg, unsigned char val);
88 static int read_register(sb_t *chip, unsigned char reg);
89 static int set_mode_register(sb_t *chip, unsigned char mode);
90 static int get_version(sb_t *chip);
91
92 static int snd_sb_csp_riff_load(snd_sb_csp_t * p, snd_sb_csp_microcode_t * code);
93 static int snd_sb_csp_unload(snd_sb_csp_t * p);
94 static int snd_sb_csp_load(snd_sb_csp_t * p, const unsigned char *buf, int size, int load_flags);
95 static int snd_sb_csp_autoload(snd_sb_csp_t * p, int pcm_sfmt, int play_rec_mode);
96 static int snd_sb_csp_check_version(snd_sb_csp_t * p);
97
98 static int snd_sb_csp_use(snd_sb_csp_t * p);
99 static int snd_sb_csp_unuse(snd_sb_csp_t * p);
100 static int snd_sb_csp_start(snd_sb_csp_t * p, int sample_width, int channels);
101 static int snd_sb_csp_stop(snd_sb_csp_t * p);
102 static int snd_sb_csp_pause(snd_sb_csp_t * p);
103 static int snd_sb_csp_restart(snd_sb_csp_t * p);
104
105 static int snd_sb_qsound_build(snd_sb_csp_t * p);
106 static void snd_sb_qsound_destroy(snd_sb_csp_t * p);
107 static int snd_sb_csp_qsound_transfer(snd_sb_csp_t * p);
108
109 static int init_proc_entry(snd_sb_csp_t * p, int device);
110 static void info_read(snd_info_entry_t *entry, snd_info_buffer_t * buffer);
111
112 /*
113  * Detect CSP chip and create a new instance
114  */
115 int snd_sb_csp_new(sb_t *chip, int device, snd_hwdep_t ** rhwdep)
116 {
117         snd_sb_csp_t *p;
118         int version, err;
119         snd_hwdep_t *hw;
120
121         if (rhwdep)
122                 *rhwdep = NULL;
123
124         if (csp_detect(chip, &version))
125                 return -ENODEV;
126
127         if ((err = snd_hwdep_new(chip->card, "SB16-CSP", device, &hw)) < 0)
128                 return err;
129
130         if ((p = snd_magic_kcalloc(snd_sb_csp_t, 0, GFP_KERNEL)) == NULL) {
131                 snd_device_free(chip->card, hw);
132                 return -ENOMEM;
133         }
134         p->chip = chip;
135         p->version = version;
136
137         /* CSP operators */
138         p->ops.csp_use = snd_sb_csp_use;
139         p->ops.csp_unuse = snd_sb_csp_unuse;
140         p->ops.csp_autoload = snd_sb_csp_autoload;
141         p->ops.csp_start = snd_sb_csp_start;
142         p->ops.csp_stop = snd_sb_csp_stop;
143         p->ops.csp_qsound_transfer = snd_sb_csp_qsound_transfer;
144
145         init_MUTEX(&p->access_mutex);
146         sprintf(hw->name, "CSP v%d.%d", (version >> 4), (version & 0x0f));
147         hw->iface = SNDRV_HWDEP_IFACE_SB16CSP;
148         hw->private_data = p;
149         hw->private_free = snd_sb_csp_free;
150
151         /* operators - only write/ioctl */
152         hw->ops.open = snd_sb_csp_open;
153         hw->ops.ioctl = snd_sb_csp_ioctl;
154         hw->ops.release = snd_sb_csp_release;
155
156         /* create a proc entry */
157         init_proc_entry(p, device);
158         if (rhwdep)
159                 *rhwdep = hw;
160         return 0;
161 }
162
163 /*
164  * free_private for hwdep instance
165  */
166 static void snd_sb_csp_free(snd_hwdep_t *hwdep)
167 {
168         snd_sb_csp_t *p = snd_magic_cast(snd_sb_csp_t, hwdep->private_data, return);
169         if (p) {
170                 if (p->running & SNDRV_SB_CSP_ST_RUNNING)
171                         snd_sb_csp_stop(p);
172                 snd_magic_kfree(p);
173         }
174 }
175
176 /* ------------------------------ */
177
178 /*
179  * open the device exclusively
180  */
181 static int snd_sb_csp_open(snd_hwdep_t * hw, struct file *file)
182 {
183         snd_sb_csp_t *p = snd_magic_cast(snd_sb_csp_t, hw->private_data, return -ENXIO);
184         return (snd_sb_csp_use(p));
185 }
186
187 /*
188  * ioctl for hwdep device:
189  */
190 static int snd_sb_csp_ioctl(snd_hwdep_t * hw, struct file *file, unsigned int cmd, unsigned long arg)
191 {
192         snd_sb_csp_t *p = snd_magic_cast(snd_sb_csp_t, hw->private_data, return -ENXIO);
193         snd_sb_csp_info_t info;
194         snd_sb_csp_start_t start_info;
195         int err;
196
197         snd_assert(p != NULL, return -EINVAL);
198
199         if (snd_sb_csp_check_version(p))
200                 return -ENODEV;
201
202         switch (cmd) {
203                 /* get information */
204         case SNDRV_SB_CSP_IOCTL_INFO:
205                 *info.codec_name = *p->codec_name;
206                 info.func_nr = p->func_nr;
207                 info.acc_format = p->acc_format;
208                 info.acc_channels = p->acc_channels;
209                 info.acc_width = p->acc_width;
210                 info.acc_rates = p->acc_rates;
211                 info.csp_mode = p->mode;
212                 info.run_channels = p->run_channels;
213                 info.run_width = p->run_width;
214                 info.version = p->version;
215                 info.state = p->running;
216                 if (copy_to_user((void *) arg, &info, sizeof(info)))
217                         err = -EFAULT;
218                 else
219                         err = 0;
220                 break;
221
222                 /* load CSP microcode */
223         case SNDRV_SB_CSP_IOCTL_LOAD_CODE:
224                 err = (p->running & SNDRV_SB_CSP_ST_RUNNING ?
225                        -EBUSY : snd_sb_csp_riff_load(p, (snd_sb_csp_microcode_t *) arg));
226                 break;
227         case SNDRV_SB_CSP_IOCTL_UNLOAD_CODE:
228                 err = (p->running & SNDRV_SB_CSP_ST_RUNNING ?
229                        -EBUSY : snd_sb_csp_unload(p));
230                 break;
231
232                 /* change CSP running state */
233         case SNDRV_SB_CSP_IOCTL_START:
234                 if (copy_from_user(&start_info, (void *) arg, sizeof(start_info)))
235                         err = -EFAULT;
236                 else
237                         err = snd_sb_csp_start(p, start_info.sample_width, start_info.channels);
238                 break;
239         case SNDRV_SB_CSP_IOCTL_STOP:
240                 err = snd_sb_csp_stop(p);
241                 break;
242         case SNDRV_SB_CSP_IOCTL_PAUSE:
243                 err = snd_sb_csp_pause(p);
244                 break;
245         case SNDRV_SB_CSP_IOCTL_RESTART:
246                 err = snd_sb_csp_restart(p);
247                 break;
248         default:
249                 err = -ENOTTY;
250                 break;
251         }
252
253         return err;
254 }
255
256 /*
257  * close the device
258  */
259 static int snd_sb_csp_release(snd_hwdep_t * hw, struct file *file)
260 {
261         snd_sb_csp_t *p = snd_magic_cast(snd_sb_csp_t, hw->private_data, return -ENXIO);
262         return (snd_sb_csp_unuse(p));
263 }
264
265 /* ------------------------------ */
266
267 /*
268  * acquire device
269  */
270 static int snd_sb_csp_use(snd_sb_csp_t * p)
271 {
272         down(&p->access_mutex);
273         if (p->used) {
274                 up(&p->access_mutex);
275                 return -EAGAIN;
276         }
277         p->used++;
278         up(&p->access_mutex);
279
280         return 0;
281
282 }
283
284 /*
285  * release device
286  */
287 static int snd_sb_csp_unuse(snd_sb_csp_t * p)
288 {
289         down(&p->access_mutex);
290         p->used--;
291         up(&p->access_mutex);
292
293         return 0;
294 }
295
296 /*
297  * load microcode via ioctl: 
298  * code is user-space pointer
299  */
300 static int snd_sb_csp_riff_load(snd_sb_csp_t * p, snd_sb_csp_microcode_t * mcode)
301 {
302         snd_sb_csp_mc_header_t info;
303
304         unsigned char *data_ptr, *data_end;
305         unsigned short func_nr = 0;
306
307         riff_header_t file_h, item_h, code_h;
308         __u32 item_type;
309         desc_header_t funcdesc_h;
310
311         unsigned long flags;
312         int err;
313
314         if (copy_from_user(&info, mcode, sizeof(info)))
315                 return -EFAULT;
316         data_ptr = mcode->data;
317
318         if (copy_from_user(&file_h, data_ptr, sizeof(file_h)))
319                 return -EFAULT;
320         if ((file_h.name != RIFF_HEADER) ||
321             (LE_INT(file_h.len) >= SNDRV_SB_CSP_MAX_MICROCODE_FILE_SIZE - sizeof(file_h))) {
322                 snd_printd("%s: Invalid RIFF header\n", __FUNCTION__);
323                 return -EINVAL;
324         }
325         data_ptr += sizeof(file_h);
326         data_end = data_ptr + LE_INT(file_h.len);
327
328         if (copy_from_user(&item_type, data_ptr, sizeof(item_type)))
329                 return -EFAULT;
330         if (item_type != CSP__HEADER) {
331                 snd_printd("%s: Invalid RIFF file type\n", __FUNCTION__);
332                 return -EINVAL;
333         }
334         data_ptr += sizeof (item_type);
335
336         for (; data_ptr < data_end; data_ptr += LE_INT(item_h.len)) {
337                 if (copy_from_user(&item_h, data_ptr, sizeof(item_h)))
338                         return -EFAULT;
339                 data_ptr += sizeof(item_h);
340                 if (item_h.name != LIST_HEADER)
341                         continue;
342
343                 if (copy_from_user(&item_type, data_ptr, sizeof(item_type)))
344                          return -EFAULT;
345                 switch (item_type) {
346                 case FUNC_HEADER:
347                         if (copy_from_user(&funcdesc_h, data_ptr + sizeof(item_type), sizeof(funcdesc_h)))
348                                 return -EFAULT;
349                         func_nr = LE_SHORT(funcdesc_h.func_nr);
350                         break;
351                 case CODE_HEADER:
352                         if (func_nr != info.func_req)
353                                 break;  /* not required function, try next */
354                         data_ptr += sizeof(item_type);
355
356                         /* destroy QSound mixer element */
357                         if (p->mode == SNDRV_SB_CSP_MODE_QSOUND) {
358                                 snd_sb_qsound_destroy(p);
359                         }
360                         /* Clear all flags */
361                         p->running = 0;
362                         p->mode = 0;
363
364                         /* load microcode blocks */
365                         for (;;) {
366                                 if (data_ptr >= data_end)
367                                         return -EINVAL;
368                                 if (copy_from_user(&code_h, data_ptr, sizeof(code_h)))
369                                         return -EFAULT;
370
371                                 /* init microcode blocks */
372                                 if (code_h.name != INIT_HEADER)
373                                         break;
374                                 data_ptr += sizeof(code_h);
375                                 err = snd_sb_csp_load(p, data_ptr, LE_INT(code_h.len),
376                                                       SNDRV_SB_CSP_LOAD_INITBLOCK | SNDRV_SB_CSP_LOAD_FROMUSER);
377                                 if (err)
378                                         return err;
379                                 data_ptr += LE_INT(code_h.len);
380                         }
381                         /* main microcode block */
382                         if (copy_from_user(&code_h, data_ptr, sizeof(code_h)))
383                                 return -EFAULT;
384
385                         if (code_h.name != MAIN_HEADER) {
386                                 snd_printd("%s: Missing 'main' microcode\n", __FUNCTION__);
387                                 return -EINVAL;
388                         }
389                         data_ptr += sizeof(code_h);
390                         err = snd_sb_csp_load(p, data_ptr, LE_INT(code_h.len),
391                                               SNDRV_SB_CSP_LOAD_FROMUSER);
392                         if (err)
393                                 return err;
394
395                         /* fill in codec header */
396                         strlcpy(p->codec_name, info.codec_name, sizeof(p->codec_name));
397                         p->func_nr = func_nr;
398                         p->mode = LE_SHORT(funcdesc_h.flags_play_rec);
399                         switch (LE_SHORT(funcdesc_h.VOC_type)) {
400                         case 0x0001:    /* QSound decoder */
401                                 if (LE_SHORT(funcdesc_h.flags_play_rec) == SNDRV_SB_CSP_MODE_DSP_WRITE) {
402                                         if (snd_sb_qsound_build(p) == 0)
403                                                 /* set QSound flag and clear all other mode flags */
404                                                 p->mode = SNDRV_SB_CSP_MODE_QSOUND;
405                                 }
406                                 p->acc_format = 0;
407                                 break;
408                         case 0x0006:    /* A Law codec */
409                                 p->acc_format = SNDRV_PCM_FMTBIT_A_LAW;
410                                 break;
411                         case 0x0007:    /* Mu Law codec */
412                                 p->acc_format = SNDRV_PCM_FMTBIT_MU_LAW;
413                                 break;
414                         case 0x0011:    /* what Creative thinks is IMA ADPCM codec */
415                         case 0x0200:    /* Creative ADPCM codec */
416                                 p->acc_format = SNDRV_PCM_FMTBIT_IMA_ADPCM;
417                                 break;
418                         case    201:    /* Text 2 Speech decoder */
419                                 /* TODO: Text2Speech handling routines */
420                                 p->acc_format = 0;
421                                 break;
422                         case 0x0202:    /* Fast Speech 8 codec */
423                         case 0x0203:    /* Fast Speech 10 codec */
424                                 p->acc_format = SNDRV_PCM_FMTBIT_SPECIAL;
425                                 break;
426                         default:        /* other codecs are unsupported */
427                                 p->acc_format = p->acc_width = p->acc_rates = 0;
428                                 p->mode = 0;
429                                 snd_printd("%s: Unsupported CSP codec type: 0x%04x\n",
430                                            __FUNCTION__,
431                                            LE_SHORT(funcdesc_h.VOC_type));
432                                 return -EINVAL;
433                         }
434                         p->acc_channels = LE_SHORT(funcdesc_h.flags_stereo_mono);
435                         p->acc_width = LE_SHORT(funcdesc_h.flags_16bit_8bit);
436                         p->acc_rates = LE_SHORT(funcdesc_h.flags_rates);
437
438                         /* Decouple CSP from IRQ and DMAREQ lines */
439                         spin_lock_irqsave(&p->chip->reg_lock, flags);
440                         set_mode_register(p->chip, 0xfc);
441                         set_mode_register(p->chip, 0x00);
442                         spin_unlock_irqrestore(&p->chip->reg_lock, flags);
443
444                         /* finished loading successfully */
445                         p->running = SNDRV_SB_CSP_ST_LOADED;    /* set LOADED flag */
446                         return 0;
447                 }
448         }
449         snd_printd("%s: Function #%d not found\n", __FUNCTION__, info.func_req);
450         return -EINVAL;
451 }
452
453 /*
454  * unload CSP microcode
455  */
456 static int snd_sb_csp_unload(snd_sb_csp_t * p)
457 {
458         if (p->running & SNDRV_SB_CSP_ST_RUNNING)
459                 return -EBUSY;
460         if (!(p->running & SNDRV_SB_CSP_ST_LOADED))
461                 return -ENXIO;
462
463         /* clear supported formats */
464         p->acc_format = 0;
465         p->acc_channels = p->acc_width = p->acc_rates = 0;
466         /* destroy QSound mixer element */
467         if (p->mode == SNDRV_SB_CSP_MODE_QSOUND) {
468                 snd_sb_qsound_destroy(p);
469         }
470         /* clear all flags */
471         p->running = 0;
472         p->mode = 0;
473         return 0;
474 }
475
476 /*
477  * send command sequence to DSP
478  */
479 static inline int command_seq(sb_t *chip, const unsigned char *seq, int size)
480 {
481         int i;
482         for (i = 0; i < size; i++) {
483                 if (!snd_sbdsp_command(chip, seq[i]))
484                         return -EIO;
485         }
486         return 0;
487 }
488
489 /*
490  * set CSP codec parameter
491  */
492 static int set_codec_parameter(sb_t *chip, unsigned char par, unsigned char val)
493 {
494         unsigned char dsp_cmd[3];
495
496         dsp_cmd[0] = 0x05;      /* CSP set codec parameter */
497         dsp_cmd[1] = val;       /* Parameter value */
498         dsp_cmd[2] = par;       /* Parameter */
499         command_seq(chip, dsp_cmd, 3);
500         snd_sbdsp_command(chip, 0x03);  /* DSP read? */
501         if (snd_sbdsp_get_byte(chip) != par)
502                 return -EIO;
503         return 0;
504 }
505
506 /*
507  * set CSP register
508  */
509 static int set_register(sb_t *chip, unsigned char reg, unsigned char val)
510 {
511         unsigned char dsp_cmd[3];
512
513         dsp_cmd[0] = 0x0e;      /* CSP set register */
514         dsp_cmd[1] = reg;       /* CSP Register */
515         dsp_cmd[2] = val;       /* value */
516         return command_seq(chip, dsp_cmd, 3);
517 }
518
519 /*
520  * read CSP register
521  * return < 0 -> error
522  */
523 static int read_register(sb_t *chip, unsigned char reg)
524 {
525         unsigned char dsp_cmd[2];
526
527         dsp_cmd[0] = 0x0f;      /* CSP read register */
528         dsp_cmd[1] = reg;       /* CSP Register */
529         command_seq(chip, dsp_cmd, 2);
530         return snd_sbdsp_get_byte(chip);        /* Read DSP value */
531 }
532
533 /*
534  * set CSP mode register
535  */
536 static int set_mode_register(sb_t *chip, unsigned char mode)
537 {
538         unsigned char dsp_cmd[2];
539
540         dsp_cmd[0] = 0x04;      /* CSP set mode register */
541         dsp_cmd[1] = mode;      /* mode */
542         return command_seq(chip, dsp_cmd, 2);
543 }
544
545 /*
546  * Detect CSP
547  * return 0 if CSP exists.
548  */
549 static int csp_detect(sb_t *chip, int *version)
550 {
551         unsigned char csp_test1, csp_test2;
552         unsigned long flags;
553         int result = -ENODEV;
554
555         spin_lock_irqsave(&chip->reg_lock, flags);
556
557         set_codec_parameter(chip, 0x00, 0x00);
558         set_mode_register(chip, 0xfc);          /* 0xfc = ?? */
559
560         csp_test1 = read_register(chip, 0x83);
561         set_register(chip, 0x83, ~csp_test1);
562         csp_test2 = read_register(chip, 0x83);
563         if (csp_test2 != (csp_test1 ^ 0xff))
564                 goto __fail;
565
566         set_register(chip, 0x83, csp_test1);
567         csp_test2 = read_register(chip, 0x83);
568         if (csp_test2 != csp_test1)
569                 goto __fail;
570
571         set_mode_register(chip, 0x00);          /* 0x00 = ? */
572
573         *version = get_version(chip);
574         snd_sbdsp_reset(chip);  /* reset DSP after getversion! */
575         if (*version >= 0x10 && *version <= 0x1f)
576                 result = 0;             /* valid version id */
577
578       __fail:
579         spin_unlock_irqrestore(&chip->reg_lock, flags);
580         return result;
581 }
582
583 /*
584  * get CSP version number
585  */
586 static int get_version(sb_t *chip)
587 {
588         unsigned char dsp_cmd[2];
589
590         dsp_cmd[0] = 0x08;      /* SB_DSP_!something! */
591         dsp_cmd[1] = 0x03;      /* get chip version id? */
592         command_seq(chip, dsp_cmd, 2);
593
594         return (snd_sbdsp_get_byte(chip));
595 }
596
597 /*
598  * check if the CSP version is valid
599  */
600 static int snd_sb_csp_check_version(snd_sb_csp_t * p)
601 {
602         if (p->version < 0x10 || p->version > 0x1f) {
603                 snd_printd("%s: Invalid CSP version: 0x%x\n", __FUNCTION__, p->version);
604                 return 1;
605         }
606         return 0;
607 }
608
609 /*
610  * download microcode to CSP (microcode should have one "main" block).
611  */
612 static int snd_sb_csp_load(snd_sb_csp_t * p, const unsigned char *buf, int size, int load_flags)
613 {
614         int status, i;
615         int err;
616         int result = -EIO;
617         unsigned long flags;
618
619         spin_lock_irqsave(&p->chip->reg_lock, flags);
620         snd_sbdsp_command(p->chip, 0x01);       /* CSP download command */
621         if (snd_sbdsp_get_byte(p->chip)) {
622                 snd_printd("%s: Download command failed\n", __FUNCTION__);
623                 goto __fail;
624         }
625         /* Send CSP low byte (size - 1) */
626         snd_sbdsp_command(p->chip, (unsigned char)(size - 1));
627         /* Send high byte */
628         snd_sbdsp_command(p->chip, (unsigned char)((size - 1) >> 8));
629         /* send microcode sequence */
630         if (load_flags & SNDRV_SB_CSP_LOAD_FROMUSER) {
631                 /* copy microcode from user space */
632                 unsigned char *kbuf, *_kbuf;
633                 _kbuf = kbuf = kmalloc (size, GFP_KERNEL);
634                 if (copy_from_user(kbuf, buf, size)) {
635                         result = -EFAULT;
636                         kfree (_kbuf);
637                         goto __fail;
638                 }
639                 while (size--) {
640                         if (!snd_sbdsp_command(p->chip, *kbuf++)) {
641                                 kfree (_kbuf);
642                                 goto __fail;
643                         }
644                 }
645                 kfree (_kbuf);
646         } else {
647                 /* load from kernel space */
648                 while (size--) {
649                         if (!snd_sbdsp_command(p->chip, *buf++))
650                                 goto __fail;
651                 }
652         }
653         if (snd_sbdsp_get_byte(p->chip))
654                 goto __fail;
655
656         if (load_flags & SNDRV_SB_CSP_LOAD_INITBLOCK) {
657                 i = 0;
658                 /* some codecs (FastSpeech) take some time to initialize */
659                 while (1) {
660                         snd_sbdsp_command(p->chip, 0x03);
661                         status = snd_sbdsp_get_byte(p->chip);
662                         if (status == 0x55 || ++i >= 10)
663                                 break;
664                         udelay (10);
665                 }
666                 if (status != 0x55) {
667                         snd_printd("%s: Microcode initialization failed\n", __FUNCTION__);
668                         goto __fail;
669                 }
670         } else {
671                 /*
672                  * Read mixer register SB_DSP4_DMASETUP after loading 'main' code.
673                  * Start CSP chip if no 16bit DMA channel is set - some kind
674                  * of autorun or perhaps a bugfix?
675                  */
676                 spin_lock(&p->chip->mixer_lock);
677                 status = snd_sbmixer_read(p->chip, SB_DSP4_DMASETUP);
678                 spin_unlock(&p->chip->mixer_lock);
679                 if (!(status & (SB_DMASETUP_DMA7 | SB_DMASETUP_DMA6 | SB_DMASETUP_DMA5))) {
680                         err = (set_codec_parameter(p->chip, 0xaa, 0x00) ||
681                                set_codec_parameter(p->chip, 0xff, 0x00));
682                         snd_sbdsp_reset(p->chip);               /* really! */
683                         if (err)
684                                 goto __fail;
685                         set_mode_register(p->chip, 0xc0);       /* c0 = STOP */
686                         set_mode_register(p->chip, 0x70);       /* 70 = RUN */
687                 }
688         }
689         result = 0;
690
691       __fail:
692         spin_unlock_irqrestore(&p->chip->reg_lock, flags);
693         return result;
694 }
695
696 #include "sb16_csp_codecs.h"
697
698 /*
699  * autoload hardware codec if necessary
700  * return 0 if CSP is loaded and ready to run (p->running != 0)
701  */
702 static int snd_sb_csp_autoload(snd_sb_csp_t * p, int pcm_sfmt, int play_rec_mode)
703 {
704         unsigned long flags;
705         int err = 0;
706
707         /* if CSP is running or manually loaded then exit */
708         if (p->running & (SNDRV_SB_CSP_ST_RUNNING | SNDRV_SB_CSP_ST_LOADED)) 
709                 return -EBUSY;
710
711         /* autoload microcode only if requested hardware codec is not already loaded */
712         if (((1 << pcm_sfmt) & p->acc_format) && (play_rec_mode & p->mode)) {
713                 p->running = SNDRV_SB_CSP_ST_AUTO;
714         } else {
715                 switch (pcm_sfmt) {
716                 case SNDRV_PCM_FORMAT_MU_LAW:
717                         err = snd_sb_csp_load(p, &mulaw_main[0], sizeof(mulaw_main), 0);
718                         p->acc_format = SNDRV_PCM_FMTBIT_MU_LAW;
719                         p->mode = SNDRV_SB_CSP_MODE_DSP_READ | SNDRV_SB_CSP_MODE_DSP_WRITE;
720                         break;
721                 case SNDRV_PCM_FORMAT_A_LAW:
722                         err = snd_sb_csp_load(p, &alaw_main[0], sizeof(alaw_main), 0);
723                         p->acc_format = SNDRV_PCM_FMTBIT_A_LAW;
724                         p->mode = SNDRV_SB_CSP_MODE_DSP_READ | SNDRV_SB_CSP_MODE_DSP_WRITE;
725                         break;
726                 case SNDRV_PCM_FORMAT_IMA_ADPCM:
727                         err = snd_sb_csp_load(p, &ima_adpcm_init[0], sizeof(ima_adpcm_init),
728                                               SNDRV_SB_CSP_LOAD_INITBLOCK);
729                         if (err)
730                                 break;
731                         if (play_rec_mode == SNDRV_SB_CSP_MODE_DSP_WRITE) {
732                                 err = snd_sb_csp_load(p, &ima_adpcm_playback[0],
733                                                       sizeof(ima_adpcm_playback), 0);
734                                 p->mode = SNDRV_SB_CSP_MODE_DSP_WRITE;
735                         } else {
736                                 err = snd_sb_csp_load(p, &ima_adpcm_capture[0],
737                                                       sizeof(ima_adpcm_capture), 0);
738                                 p->mode = SNDRV_SB_CSP_MODE_DSP_READ;
739                         }
740                         p->acc_format = SNDRV_PCM_FMTBIT_IMA_ADPCM;
741                         break;                            
742                 default:
743                         /* Decouple CSP from IRQ and DMAREQ lines */
744                         if (p->running & SNDRV_SB_CSP_ST_AUTO) {
745                                 spin_lock_irqsave(&p->chip->reg_lock, flags);
746                                 set_mode_register(p->chip, 0xfc);
747                                 set_mode_register(p->chip, 0x00);
748                                 spin_unlock_irqrestore(&p->chip->reg_lock, flags);
749                                 p->running = 0;                 /* clear autoloaded flag */
750                         }
751                         return -EINVAL;
752                 }
753                 if (err) {
754                         p->acc_format = 0;
755                         p->acc_channels = p->acc_width = p->acc_rates = 0;
756
757                         p->running = 0;                         /* clear autoloaded flag */
758                         p->mode = 0;
759                         return (err);
760                 } else {
761                         p->running = SNDRV_SB_CSP_ST_AUTO;      /* set autoloaded flag */
762                         p->acc_width = SNDRV_SB_CSP_SAMPLE_16BIT;       /* only 16 bit data */
763                         p->acc_channels = SNDRV_SB_CSP_MONO | SNDRV_SB_CSP_STEREO;
764                         p->acc_rates = SNDRV_SB_CSP_RATE_ALL;   /* HW codecs accept all rates */
765                 }   
766
767         }
768         return (p->running & SNDRV_SB_CSP_ST_AUTO) ? 0 : -ENXIO;
769 }
770
771 /*
772  * start CSP
773  */
774 static int snd_sb_csp_start(snd_sb_csp_t * p, int sample_width, int channels)
775 {
776         unsigned char s_type;   /* sample type */
777         unsigned char mixL, mixR;
778         int result = -EIO;
779         unsigned long flags;
780
781         if (!(p->running & (SNDRV_SB_CSP_ST_LOADED | SNDRV_SB_CSP_ST_AUTO))) {
782                 snd_printd("%s: Microcode not loaded\n", __FUNCTION__);
783                 return -ENXIO;
784         }
785         if (p->running & SNDRV_SB_CSP_ST_RUNNING) {
786                 snd_printd("%s: CSP already running\n", __FUNCTION__);
787                 return -EBUSY;
788         }
789         if (!(sample_width & p->acc_width)) {
790                 snd_printd("%s: Unsupported PCM sample width\n", __FUNCTION__);
791                 return -EINVAL;
792         }
793         if (!(channels & p->acc_channels)) {
794                 snd_printd("%s: Invalid number of channels\n", __FUNCTION__);
795                 return -EINVAL;
796         }
797
798         /* Mute PCM volume */
799         spin_lock_irqsave(&p->chip->mixer_lock, flags);
800         mixL = snd_sbmixer_read(p->chip, SB_DSP4_PCM_DEV);
801         mixR = snd_sbmixer_read(p->chip, SB_DSP4_PCM_DEV + 1);
802         snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV, mixL & 0x7);
803         snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV + 1, mixR & 0x7);
804
805         spin_lock(&p->chip->reg_lock);
806         set_mode_register(p->chip, 0xc0);       /* c0 = STOP */
807         set_mode_register(p->chip, 0x70);       /* 70 = RUN */
808
809         s_type = 0x00;
810         if (channels == SNDRV_SB_CSP_MONO)
811                 s_type = 0x11;  /* 000n 000n    (n = 1 if mono) */
812         if (sample_width == SNDRV_SB_CSP_SAMPLE_8BIT)
813                 s_type |= 0x22; /* 00dX 00dX    (d = 1 if 8 bit samples) */
814
815         if (set_codec_parameter(p->chip, 0x81, s_type)) {
816                 snd_printd("%s: Set sample type command failed\n", __FUNCTION__);
817                 goto __fail;
818         }
819         if (set_codec_parameter(p->chip, 0x80, 0x00)) {
820                 snd_printd("%s: Codec start command failed\n", __FUNCTION__);
821                 goto __fail;
822         }
823         p->run_width = sample_width;
824         p->run_channels = channels;
825
826         p->running |= SNDRV_SB_CSP_ST_RUNNING;
827
828         if (p->mode & SNDRV_SB_CSP_MODE_QSOUND) {
829                 set_codec_parameter(p->chip, 0xe0, 0x01);
830                 /* enable QSound decoder */
831                 set_codec_parameter(p->chip, 0x00, 0xff);
832                 set_codec_parameter(p->chip, 0x01, 0xff);
833                 p->running |= SNDRV_SB_CSP_ST_QSOUND;
834                 /* set QSound startup value */
835                 snd_sb_csp_qsound_transfer(p);
836         }
837         result = 0;
838
839       __fail:
840         spin_unlock(&p->chip->reg_lock);
841
842         /* restore PCM volume */
843         snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV, mixL);
844         snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV + 1, mixR);
845         spin_unlock_irqrestore(&p->chip->mixer_lock, flags);
846
847         return result;
848 }
849
850 /*
851  * stop CSP
852  */
853 static int snd_sb_csp_stop(snd_sb_csp_t * p)
854 {
855         int result;
856         unsigned char mixL, mixR;
857         unsigned long flags;
858
859         if (!(p->running & SNDRV_SB_CSP_ST_RUNNING))
860                 return 0;
861
862         /* Mute PCM volume */
863         spin_lock_irqsave(&p->chip->mixer_lock, flags);
864         mixL = snd_sbmixer_read(p->chip, SB_DSP4_PCM_DEV);
865         mixR = snd_sbmixer_read(p->chip, SB_DSP4_PCM_DEV + 1);
866         snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV, mixL & 0x7);
867         snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV + 1, mixR & 0x7);
868
869         spin_lock(&p->chip->reg_lock);
870         if (p->running & SNDRV_SB_CSP_ST_QSOUND) {
871                 set_codec_parameter(p->chip, 0xe0, 0x01);
872                 /* disable QSound decoder */
873                 set_codec_parameter(p->chip, 0x00, 0x00);
874                 set_codec_parameter(p->chip, 0x01, 0x00);
875
876                 p->running &= ~SNDRV_SB_CSP_ST_QSOUND;
877         }
878         result = set_mode_register(p->chip, 0xc0);      /* c0 = STOP */
879         spin_unlock(&p->chip->reg_lock);
880
881         /* restore PCM volume */
882         snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV, mixL);
883         snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV + 1, mixR);
884         spin_unlock_irqrestore(&p->chip->mixer_lock, flags);
885
886         if (!(result))
887                 p->running &= ~(SNDRV_SB_CSP_ST_PAUSED | SNDRV_SB_CSP_ST_RUNNING);
888         return result;
889 }
890
891 /*
892  * pause CSP codec and hold DMA transfer
893  */
894 static int snd_sb_csp_pause(snd_sb_csp_t * p)
895 {
896         int result;
897         unsigned long flags;
898
899         if (!(p->running & SNDRV_SB_CSP_ST_RUNNING))
900                 return -EBUSY;
901
902         spin_lock_irqsave(&p->chip->reg_lock, flags);
903         result = set_codec_parameter(p->chip, 0x80, 0xff);
904         spin_unlock_irqrestore(&p->chip->reg_lock, flags);
905         if (!(result))
906                 p->running |= SNDRV_SB_CSP_ST_PAUSED;
907
908         return result;
909 }
910
911 /*
912  * restart CSP codec and resume DMA transfer
913  */
914 static int snd_sb_csp_restart(snd_sb_csp_t * p)
915 {
916         int result;
917         unsigned long flags;
918
919         if (!(p->running & SNDRV_SB_CSP_ST_PAUSED))
920                 return -EBUSY;
921
922         spin_lock_irqsave(&p->chip->reg_lock, flags);
923         result = set_codec_parameter(p->chip, 0x80, 0x00);
924         spin_unlock_irqrestore(&p->chip->reg_lock, flags);
925         if (!(result))
926                 p->running &= ~SNDRV_SB_CSP_ST_PAUSED;
927
928         return result;
929 }
930
931 /* ------------------------------ */
932
933 /*
934  * QSound mixer control for PCM
935  */
936
937 static int snd_sb_qsound_switch_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
938 {
939         uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
940         uinfo->count = 1;
941         uinfo->value.integer.min = 0;
942         uinfo->value.integer.max = 1;
943         return 0;
944 }
945
946 static int snd_sb_qsound_switch_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
947 {
948         snd_sb_csp_t *p = snd_kcontrol_chip(kcontrol);
949         
950         ucontrol->value.integer.value[0] = p->q_enabled ? 1 : 0;
951         return 0;
952 }
953
954 static int snd_sb_qsound_switch_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
955 {
956         snd_sb_csp_t *p = snd_kcontrol_chip(kcontrol);
957         unsigned long flags;
958         int change;
959         unsigned char nval;
960         
961         nval = ucontrol->value.integer.value[0] & 0x01;
962         spin_lock_irqsave(&p->q_lock, flags);
963         change = p->q_enabled != nval;
964         p->q_enabled = nval;
965         spin_unlock_irqrestore(&p->q_lock, flags);
966         return change;
967 }
968
969 static int snd_sb_qsound_space_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
970 {
971         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
972         uinfo->count = 2;
973         uinfo->value.integer.min = 0;
974         uinfo->value.integer.max = SNDRV_SB_CSP_QSOUND_MAX_RIGHT;
975         return 0;
976 }
977
978 static int snd_sb_qsound_space_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
979 {
980         snd_sb_csp_t *p = snd_kcontrol_chip(kcontrol);
981         unsigned long flags;
982         
983         spin_lock_irqsave(&p->q_lock, flags);
984         ucontrol->value.integer.value[0] = p->qpos_left;
985         ucontrol->value.integer.value[1] = p->qpos_right;
986         spin_unlock_irqrestore(&p->q_lock, flags);
987         return 0;
988 }
989
990 static int snd_sb_qsound_space_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
991 {
992         snd_sb_csp_t *p = snd_kcontrol_chip(kcontrol);
993         unsigned long flags;
994         int change;
995         unsigned char nval1, nval2;
996         
997         nval1 = ucontrol->value.integer.value[0];
998         if (nval1 > SNDRV_SB_CSP_QSOUND_MAX_RIGHT)
999                 nval1 = SNDRV_SB_CSP_QSOUND_MAX_RIGHT;
1000         nval2 = ucontrol->value.integer.value[1];
1001         if (nval2 > SNDRV_SB_CSP_QSOUND_MAX_RIGHT)
1002                 nval2 = SNDRV_SB_CSP_QSOUND_MAX_RIGHT;
1003         spin_lock_irqsave(&p->q_lock, flags);
1004         change = p->qpos_left != nval1 || p->qpos_right != nval2;
1005         p->qpos_left = nval1;
1006         p->qpos_right = nval2;
1007         p->qpos_changed = change;
1008         spin_unlock_irqrestore(&p->q_lock, flags);
1009         return change;
1010 }
1011
1012 static snd_kcontrol_new_t snd_sb_qsound_switch = {
1013         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1014         .name = "3D Control - Switch",
1015         .info = snd_sb_qsound_switch_info,
1016         .get = snd_sb_qsound_switch_get,
1017         .put = snd_sb_qsound_switch_put
1018 };
1019
1020 static snd_kcontrol_new_t snd_sb_qsound_space = {
1021         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1022         .name = "3D Control - Space",
1023         .info = snd_sb_qsound_space_info,
1024         .get = snd_sb_qsound_space_get,
1025         .put = snd_sb_qsound_space_put
1026 };
1027
1028 static int snd_sb_qsound_build(snd_sb_csp_t * p)
1029 {
1030         snd_card_t * card;
1031         int err;
1032
1033         snd_assert(p != NULL, return -EINVAL);
1034
1035         card = p->chip->card;
1036         p->qpos_left = p->qpos_right = SNDRV_SB_CSP_QSOUND_MAX_RIGHT / 2;
1037         p->qpos_changed = 0;
1038
1039         spin_lock_init(&p->q_lock);
1040
1041         if ((err = snd_ctl_add(card, p->qsound_switch = snd_ctl_new1(&snd_sb_qsound_switch, p))) < 0)
1042                 goto __error;
1043         if ((err = snd_ctl_add(card, p->qsound_space = snd_ctl_new1(&snd_sb_qsound_space, p))) < 0)
1044                 goto __error;
1045
1046         return 0;
1047
1048      __error:
1049         snd_sb_qsound_destroy(p);
1050         return err;
1051 }
1052
1053 static void snd_sb_qsound_destroy(snd_sb_csp_t * p)
1054 {
1055         snd_card_t * card;
1056         unsigned long flags;
1057
1058         snd_assert(p != NULL, return);
1059
1060         card = p->chip->card;   
1061         
1062         down_write(&card->controls_rwsem);
1063         if (p->qsound_switch)
1064                 snd_ctl_remove(card, p->qsound_switch);
1065         if (p->qsound_space)
1066                 snd_ctl_remove(card, p->qsound_space);
1067         up_write(&card->controls_rwsem);
1068
1069         /* cancel pending transfer of QSound parameters */
1070         spin_lock_irqsave (&p->q_lock, flags);
1071         p->qpos_changed = 0;
1072         spin_unlock_irqrestore (&p->q_lock, flags);
1073 }
1074
1075 /*
1076  * Transfer qsound parameters to CSP,
1077  * function should be called from interrupt routine
1078  */
1079 static int snd_sb_csp_qsound_transfer(snd_sb_csp_t * p)
1080 {
1081         int err = -ENXIO;
1082
1083         spin_lock(&p->q_lock);
1084         if (p->running & SNDRV_SB_CSP_ST_QSOUND) {
1085                 set_codec_parameter(p->chip, 0xe0, 0x01);
1086                 /* left channel */
1087                 set_codec_parameter(p->chip, 0x00, p->qpos_left);
1088                 set_codec_parameter(p->chip, 0x02, 0x00);
1089                 /* right channel */
1090                 set_codec_parameter(p->chip, 0x00, p->qpos_right);
1091                 set_codec_parameter(p->chip, 0x03, 0x00);
1092                 err = 0;
1093         }
1094         p->qpos_changed = 0;
1095         spin_unlock(&p->q_lock);
1096         return err;
1097 }
1098
1099 /* ------------------------------ */
1100
1101 /*
1102  * proc interface
1103  */
1104 static int init_proc_entry(snd_sb_csp_t * p, int device)
1105 {
1106         char name[16];
1107         snd_info_entry_t *entry;
1108         sprintf(name, "cspD%d", device);
1109         if (! snd_card_proc_new(p->chip->card, name, &entry))
1110                 snd_info_set_text_ops(entry, p, 1024, info_read);
1111         return 0;
1112 }
1113
1114 static void info_read(snd_info_entry_t *entry, snd_info_buffer_t * buffer)
1115 {
1116         snd_sb_csp_t *p = snd_magic_cast(snd_sb_csp_t, entry->private_data, return);
1117
1118         snd_iprintf(buffer, "Creative Signal Processor [v%d.%d]\n", (p->version >> 4), (p->version & 0x0f));
1119         snd_iprintf(buffer, "State: %cx%c%c%c\n", ((p->running & SNDRV_SB_CSP_ST_QSOUND) ? 'Q' : '-'),
1120                     ((p->running & SNDRV_SB_CSP_ST_PAUSED) ? 'P' : '-'),
1121                     ((p->running & SNDRV_SB_CSP_ST_RUNNING) ? 'R' : '-'),
1122                     ((p->running & SNDRV_SB_CSP_ST_LOADED) ? 'L' : '-'));
1123         if (p->running & SNDRV_SB_CSP_ST_LOADED) {
1124                 snd_iprintf(buffer, "Codec: %s [func #%d]\n", p->codec_name, p->func_nr);
1125                 snd_iprintf(buffer, "Sample rates: ");
1126                 if (p->acc_rates == SNDRV_SB_CSP_RATE_ALL) {
1127                         snd_iprintf(buffer, "All\n");
1128                 } else {
1129                         snd_iprintf(buffer, "%s%s%s%s\n",
1130                                     ((p->acc_rates & SNDRV_SB_CSP_RATE_8000) ? "8000Hz " : ""),
1131                                     ((p->acc_rates & SNDRV_SB_CSP_RATE_11025) ? "11025Hz " : ""),
1132                                     ((p->acc_rates & SNDRV_SB_CSP_RATE_22050) ? "22050Hz " : ""),
1133                                     ((p->acc_rates & SNDRV_SB_CSP_RATE_44100) ? "44100Hz" : ""));
1134                 }
1135                 if (p->mode == SNDRV_SB_CSP_MODE_QSOUND) {
1136                         snd_iprintf(buffer, "QSound decoder %sabled\n",
1137                                     p->q_enabled ? "en" : "dis");
1138                 } else {
1139                         snd_iprintf(buffer, "PCM format ID: 0x%x (%s/%s) [%s/%s] [%s/%s]\n",
1140                                     p->acc_format,
1141                                     ((p->acc_width & SNDRV_SB_CSP_SAMPLE_16BIT) ? "16bit" : "-"),
1142                                     ((p->acc_width & SNDRV_SB_CSP_SAMPLE_8BIT) ? "8bit" : "-"),
1143                                     ((p->acc_channels & SNDRV_SB_CSP_MONO) ? "mono" : "-"),
1144                                     ((p->acc_channels & SNDRV_SB_CSP_STEREO) ? "stereo" : "-"),
1145                                     ((p->mode & SNDRV_SB_CSP_MODE_DSP_WRITE) ? "playback" : "-"),
1146                                     ((p->mode & SNDRV_SB_CSP_MODE_DSP_READ) ? "capture" : "-"));
1147                 }
1148         }
1149         if (p->running & SNDRV_SB_CSP_ST_AUTO) {
1150                 snd_iprintf(buffer, "Autoloaded Mu-Law, A-Law or Ima-ADPCM hardware codec\n");
1151         }
1152         if (p->running & SNDRV_SB_CSP_ST_RUNNING) {
1153                 snd_iprintf(buffer, "Processing %dbit %s PCM samples\n",
1154                             ((p->run_width & SNDRV_SB_CSP_SAMPLE_16BIT) ? 16 : 8),
1155                             ((p->run_channels & SNDRV_SB_CSP_MONO) ? "mono" : "stereo"));
1156         }
1157         if (p->running & SNDRV_SB_CSP_ST_QSOUND) {
1158                 snd_iprintf(buffer, "Qsound position: left = 0x%x, right = 0x%x\n",
1159                             p->qpos_left, p->qpos_right);
1160         }
1161 }
1162
1163 /* */
1164
1165 EXPORT_SYMBOL(snd_sb_csp_new);
1166
1167 /*
1168  * INIT part
1169  */
1170
1171 static int __init alsa_sb_csp_init(void)
1172 {
1173         return 0;
1174 }
1175
1176 static void __exit alsa_sb_csp_exit(void)
1177 {
1178 }
1179
1180 module_init(alsa_sb_csp_init)
1181 module_exit(alsa_sb_csp_exit)