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