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