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