Blame view

sound/pci/pcxhr/pcxhr_hwdep.c 13.2 KB
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  /*
   * Driver for Digigram pcxhr compatible soundcards
   *
   * hwdep device manager
   *
   * Copyright (c) 2004 by Digigram <alsa@digigram.com>
   *
   *   This program is free software; you can redistribute it and/or modify
   *   it under the terms of the GNU General Public License as published by
   *   the Free Software Foundation; either version 2 of the License, or
   *   (at your option) any later version.
   *
   *   This program is distributed in the hope that it will be useful,
   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   *   GNU General Public License for more details.
   *
   *   You should have received a copy of the GNU General Public License
   *   along with this program; if not, write to the Free Software
   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
   */
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
22
23
24
25
  #include <linux/interrupt.h>
  #include <linux/vmalloc.h>
  #include <linux/firmware.h>
  #include <linux/pci.h>
da155d5b4   Paul Gortmaker   sound: Add module...
26
  #include <linux/module.h>
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
27
28
29
30
31
32
33
  #include <asm/io.h>
  #include <sound/core.h>
  #include <sound/hwdep.h>
  #include "pcxhr.h"
  #include "pcxhr_mixer.h"
  #include "pcxhr_hwdep.h"
  #include "pcxhr_core.h"
7628700e0   Markus Bollinger   ALSA: pcxhr - add...
34
  #include "pcxhr_mix22.h"
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
35
36
37
38
39
40
41
  
  
  #if defined(CONFIG_FW_LOADER) || defined(CONFIG_FW_LOADER_MODULE)
  #if !defined(CONFIG_USE_PCXHRLOADER) && !defined(CONFIG_SND_PCXHR) /* built-in kernel */
  #define SND_PCXHR_FW_LOADER	/* use the standard firmware loader */
  #endif
  #endif
7628700e0   Markus Bollinger   ALSA: pcxhr - add...
42
  static int pcxhr_sub_init(struct pcxhr_mgr *mgr);
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
43
44
45
  /*
   * get basic information and init pcxhr card
   */
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
  static int pcxhr_init_board(struct pcxhr_mgr *mgr)
  {
  	int err;
  	struct pcxhr_rmh rmh;
  	int card_streams;
  
  	/* calc the number of all streams used */
  	if (mgr->mono_capture)
  		card_streams = mgr->capture_chips * 2;
  	else
  		card_streams = mgr->capture_chips;
  	card_streams += mgr->playback_chips * PCXHR_PLAYBACK_STREAMS;
  
  	/* enable interrupts */
  	pcxhr_enable_dsp(mgr);
  
  	pcxhr_init_rmh(&rmh, CMD_SUPPORTED);
  	err = pcxhr_send_msg(mgr, &rmh);
  	if (err)
  		return err;
  	/* test 8 or 12 phys out */
da3cec35d   Takashi Iwai   ALSA: Kill snd_as...
67
68
  	if ((rmh.stat[0] & MASK_FIRST_FIELD) != mgr->playback_chips * 2)
  		return -EINVAL;
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
69
  	/* test 8 or 2 phys in */
7628700e0   Markus Bollinger   ALSA: pcxhr - add...
70
  	if (((rmh.stat[0] >> (2 * FIELD_SIZE)) & MASK_FIRST_FIELD) <
da3cec35d   Takashi Iwai   ALSA: Kill snd_as...
71
72
  	    mgr->capture_chips * 2)
  		return -EINVAL;
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
73
  	/* test max nb substream per board */
da3cec35d   Takashi Iwai   ALSA: Kill snd_as...
74
75
  	if ((rmh.stat[1] & 0x5F) < card_streams)
  		return -EINVAL;
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
76
  	/* test max nb substream per pipe */
da3cec35d   Takashi Iwai   ALSA: Kill snd_as...
77
78
  	if (((rmh.stat[1] >> 7) & 0x5F) < PCXHR_PLAYBACK_STREAMS)
  		return -EINVAL;
7628700e0   Markus Bollinger   ALSA: pcxhr - add...
79
80
81
  	snd_printdd("supported formats : playback=%x capture=%x
  ",
  		    rmh.stat[2], rmh.stat[3]);
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
82
83
84
85
86
  
  	pcxhr_init_rmh(&rmh, CMD_VERSION);
  	/* firmware num for DSP */
  	rmh.cmd[0] |= mgr->firmware_num;
  	/* transfer granularity in samples (should be multiple of 48) */
7628700e0   Markus Bollinger   ALSA: pcxhr - add...
87
  	rmh.cmd[1] = (1<<23) + mgr->granularity;
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
88
89
90
91
  	rmh.cmd_len = 2;
  	err = pcxhr_send_msg(mgr, &rmh);
  	if (err)
  		return err;
7628700e0   Markus Bollinger   ALSA: pcxhr - add...
92
93
94
  	snd_printdd("PCXHR DSP version is %d.%d.%d
  ", (rmh.stat[0]>>16)&0xff,
  		    (rmh.stat[0]>>8)&0xff, rmh.stat[0]&0xff);
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
95
  	mgr->dsp_version = rmh.stat[0];
7628700e0   Markus Bollinger   ALSA: pcxhr - add...
96
97
98
99
100
101
102
103
104
105
106
  	if (mgr->is_hr_stereo)
  		err = hr222_sub_init(mgr);
  	else
  		err = pcxhr_sub_init(mgr);
  	return err;
  }
  
  static int pcxhr_sub_init(struct pcxhr_mgr *mgr)
  {
  	int err;
  	struct pcxhr_rmh rmh;
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
107
108
109
110
111
112
113
114
  	/* get options */
  	pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_READ);
  	rmh.cmd[0] |= IO_NUM_REG_STATUS;
  	rmh.cmd[1]  = REG_STATUS_OPTIONS;
  	rmh.cmd_len = 2;
  	err = pcxhr_send_msg(mgr, &rmh);
  	if (err)
  		return err;
7628700e0   Markus Bollinger   ALSA: pcxhr - add...
115
116
117
  	if ((rmh.stat[1] & REG_STATUS_OPT_DAUGHTER_MASK) ==
  	    REG_STATUS_OPT_ANALOG_BOARD)
  		mgr->board_has_analog = 1;	/* analog addon board found */
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
118
119
120
121
122
123
  
  	/* unmute inputs */
  	err = pcxhr_write_io_num_reg_cont(mgr, REG_CONT_UNMUTE_INPUTS,
  					  REG_CONT_UNMUTE_INPUTS, NULL);
  	if (err)
  		return err;
7628700e0   Markus Bollinger   ALSA: pcxhr - add...
124
125
  	/* unmute outputs (a write to IO_NUM_REG_MUTE_OUT mutes!) */
  	pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_READ);
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
126
  	rmh.cmd[0] |= IO_NUM_REG_MUTE_OUT;
7628700e0   Markus Bollinger   ALSA: pcxhr - add...
127
128
129
130
  	if (DSP_EXT_CMD_SET(mgr)) {
  		rmh.cmd[1]  = 1;	/* unmute digital plugs */
  		rmh.cmd_len = 2;
  	}
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
131
132
133
134
135
136
137
138
139
140
  	err = pcxhr_send_msg(mgr, &rmh);
  	return err;
  }
  
  void pcxhr_reset_board(struct pcxhr_mgr *mgr)
  {
  	struct pcxhr_rmh rmh;
  
  	if (mgr->dsp_loaded & (1 << PCXHR_FIRMWARE_DSP_MAIN_INDEX)) {
  		/* mute outputs */
7628700e0   Markus Bollinger   ALSA: pcxhr - add...
141
  	    if (!mgr->is_hr_stereo) {
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
142
143
144
145
146
  		/* a read to IO_NUM_REG_MUTE_OUT register unmutes! */
  		pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE);
  		rmh.cmd[0] |= IO_NUM_REG_MUTE_OUT;
  		pcxhr_send_msg(mgr, &rmh);
  		/* mute inputs */
7628700e0   Markus Bollinger   ALSA: pcxhr - add...
147
148
149
150
  		pcxhr_write_io_num_reg_cont(mgr, REG_CONT_UNMUTE_INPUTS,
  					    0, NULL);
  	    }
  		/* stereo cards mute with reset of dsp */
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
151
152
  	}
  	/* reset pcxhr dsp */
7628700e0   Markus Bollinger   ALSA: pcxhr - add...
153
  	if (mgr->dsp_loaded & (1 << PCXHR_FIRMWARE_DSP_EPRM_INDEX))
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
154
155
  		pcxhr_reset_dsp(mgr);
  	/* reset second xilinx */
7628700e0   Markus Bollinger   ALSA: pcxhr - add...
156
  	if (mgr->dsp_loaded & (1 << PCXHR_FIRMWARE_XLX_COM_INDEX)) {
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
157
  		pcxhr_reset_xilinx_com(mgr);
7628700e0   Markus Bollinger   ALSA: pcxhr - add...
158
159
  		mgr->dsp_loaded = 1;
  	}
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
160
161
162
163
164
165
166
  	return;
  }
  
  
  /*
   *  allocate a playback/capture pipe (pcmp0/pcmc0)
   */
7628700e0   Markus Bollinger   ALSA: pcxhr - add...
167
168
169
  static int pcxhr_dsp_allocate_pipe(struct pcxhr_mgr *mgr,
  				   struct pcxhr_pipe *pipe,
  				   int is_capture, int pin)
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
  {
  	int stream_count, audio_count;
  	int err;
  	struct pcxhr_rmh rmh;
  
  	if (is_capture) {
  		stream_count = 1;
  		if (mgr->mono_capture)
  			audio_count = 1;
  		else
  			audio_count = 2;
  	} else {
  		stream_count = PCXHR_PLAYBACK_STREAMS;
  		audio_count = 2;	/* always stereo */
  	}
7628700e0   Markus Bollinger   ALSA: pcxhr - add...
185
186
187
  	snd_printdd("snd_add_ref_pipe pin(%d) pcm%c0
  ",
  		    pin, is_capture ? 'c' : 'p');
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
188
189
190
191
  	pipe->is_capture = is_capture;
  	pipe->first_audio = pin;
  	/* define pipe (P_PCM_ONLY_MASK (0x020000) is not necessary) */
  	pcxhr_init_rmh(&rmh, CMD_RES_PIPE);
7628700e0   Markus Bollinger   ALSA: pcxhr - add...
192
193
194
195
196
197
198
  	pcxhr_set_pipe_cmd_params(&rmh, is_capture, pin,
  				  audio_count, stream_count);
  	rmh.cmd[1] |= 0x020000; /* add P_PCM_ONLY_MASK */
  	if (DSP_EXT_CMD_SET(mgr)) {
  		/* add channel mask to command */
  	  rmh.cmd[rmh.cmd_len++] = (audio_count == 1) ? 0x01 : 0x03;
  	}
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
199
200
  	err = pcxhr_send_msg(mgr, &rmh);
  	if (err < 0) {
7628700e0   Markus Bollinger   ALSA: pcxhr - add...
201
202
203
  		snd_printk(KERN_ERR "error pipe allocation "
  			   "(CMD_RES_PIPE) err=%x!
  ", err);
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
  		return err;
  	}
  	pipe->status = PCXHR_PIPE_DEFINED;
  
  	return 0;
  }
  
  /*
   *  free playback/capture pipe (pcmp0/pcmc0)
   */
  #if 0
  static int pcxhr_dsp_free_pipe( struct pcxhr_mgr *mgr, struct pcxhr_pipe *pipe)
  {
  	struct pcxhr_rmh rmh;
  	int capture_mask = 0;
  	int playback_mask = 0;
  	int err = 0;
  
  	if (pipe->is_capture)
  		capture_mask  = (1 << pipe->first_audio);
  	else
  		playback_mask = (1 << pipe->first_audio);
  
  	/* stop one pipe */
  	err = pcxhr_set_pipe_state(mgr, playback_mask, capture_mask, 0);
  	if (err < 0)
  		snd_printk(KERN_ERR "error stopping pipe!
  ");
  	/* release the pipe */
  	pcxhr_init_rmh(&rmh, CMD_FREE_PIPE);
7628700e0   Markus Bollinger   ALSA: pcxhr - add...
234
235
  	pcxhr_set_pipe_cmd_params(&rmh, pipe->is_capture, pipe->first_audio,
  				  0, 0);
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
236
237
  	err = pcxhr_send_msg(mgr, &rmh);
  	if (err < 0)
7628700e0   Markus Bollinger   ALSA: pcxhr - add...
238
239
240
  		snd_printk(KERN_ERR "error pipe release "
  			   "(CMD_FREE_PIPE) err(%x)
  ", err);
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
  	pipe->status = PCXHR_PIPE_UNDEFINED;
  	return err;
  }
  #endif
  
  
  static int pcxhr_config_pipes(struct pcxhr_mgr *mgr)
  {
  	int err, i, j;
  	struct snd_pcxhr *chip;
  	struct pcxhr_pipe *pipe;
  
  	/* allocate the pipes on the dsp */
  	for (i = 0; i < mgr->num_cards; i++) {
  		chip = mgr->chip[i];
  		if (chip->nb_streams_play) {
  			pipe = &chip->playback_pipe;
  			err = pcxhr_dsp_allocate_pipe( mgr, pipe, 0, i*2);
  			if (err)
  				return err;
  			for(j = 0; j < chip->nb_streams_play; j++)
  				chip->playback_stream[j].pipe = pipe;
  		}
  		for (j = 0; j < chip->nb_streams_capt; j++) {
  			pipe = &chip->capture_pipe[j];
  			err = pcxhr_dsp_allocate_pipe(mgr, pipe, 1, i*2 + j);
  			if (err)
  				return err;
  			chip->capture_stream[j].pipe = pipe;
  		}
  	}
  	return 0;
  }
  
  static int pcxhr_start_pipes(struct pcxhr_mgr *mgr)
  {
  	int i, j;
  	struct snd_pcxhr *chip;
  	int playback_mask = 0;
  	int capture_mask = 0;
  
  	/* start all the pipes on the dsp */
  	for (i = 0; i < mgr->num_cards; i++) {
  		chip = mgr->chip[i];
  		if (chip->nb_streams_play)
7628700e0   Markus Bollinger   ALSA: pcxhr - add...
286
  			playback_mask |= 1 << chip->playback_pipe.first_audio;
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
287
  		for (j = 0; j < chip->nb_streams_capt; j++)
7628700e0   Markus Bollinger   ALSA: pcxhr - add...
288
  			capture_mask |= 1 << chip->capture_pipe[j].first_audio;
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
289
290
291
  	}
  	return pcxhr_set_pipe_state(mgr, playback_mask, capture_mask, 1);
  }
7628700e0   Markus Bollinger   ALSA: pcxhr - add...
292
293
  static int pcxhr_dsp_load(struct pcxhr_mgr *mgr, int index,
  			  const struct firmware *dsp)
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
  {
  	int err, card_index;
  
  	snd_printdd("loading dsp [%d] size = %Zd
  ", index, dsp->size);
  
  	switch (index) {
  	case PCXHR_FIRMWARE_XLX_INT_INDEX:
  		pcxhr_reset_xilinx_com(mgr);
  		return pcxhr_load_xilinx_binary(mgr, dsp, 0);
  
  	case PCXHR_FIRMWARE_XLX_COM_INDEX:
  		pcxhr_reset_xilinx_com(mgr);
  		return pcxhr_load_xilinx_binary(mgr, dsp, 1);
  
  	case PCXHR_FIRMWARE_DSP_EPRM_INDEX:
  		pcxhr_reset_dsp(mgr);
  		return pcxhr_load_eeprom_binary(mgr, dsp);
  
  	case PCXHR_FIRMWARE_DSP_BOOT_INDEX:
  		return pcxhr_load_boot_binary(mgr, dsp);
  
  	case PCXHR_FIRMWARE_DSP_MAIN_INDEX:
  		err = pcxhr_load_dsp_binary(mgr, dsp);
  		if (err)
  			return err;
  		break;	/* continue with first init */
  	default:
  		snd_printk(KERN_ERR "wrong file index
  ");
  		return -EFAULT;
  	} /* end of switch file index*/
  
  	/* first communication with embedded */
  	err = pcxhr_init_board(mgr);
          if (err < 0) {
  		snd_printk(KERN_ERR "pcxhr could not be set up
  ");
  		return err;
  	}
  	err = pcxhr_config_pipes(mgr);
          if (err < 0) {
  		snd_printk(KERN_ERR "pcxhr pipes could not be set up
  ");
  		return err;
  	}
         	/* create devices and mixer in accordance with HW options*/
          for (card_index = 0; card_index < mgr->num_cards; card_index++) {
  		struct snd_pcxhr *chip = mgr->chip[card_index];
  
  		if ((err = pcxhr_create_pcm(chip)) < 0)
  			return err;
  
  		if (card_index == 0) {
  			if ((err = pcxhr_create_mixer(chip->mgr)) < 0)
  				return err;
  		}
  		if ((err = snd_card_register(chip->card)) < 0)
  			return err;
  	}
  	err = pcxhr_start_pipes(mgr);
          if (err < 0) {
  		snd_printk(KERN_ERR "pcxhr pipes could not be started
  ");
  		return err;
  	}
  	snd_printdd("pcxhr firmware downloaded and successfully set up
  ");
  
  	return 0;
  }
  
  /*
   * fw loader entry
   */
  #ifdef SND_PCXHR_FW_LOADER
  
  int pcxhr_setup_firmware(struct pcxhr_mgr *mgr)
  {
7628700e0   Markus Bollinger   ALSA: pcxhr - add...
373
  	static char *fw_files[][5] = {
ade9b2fb9   Markus Bollinger   ALSA: pcxhr - cha...
374
375
376
377
378
379
380
381
382
383
384
385
  	[0] = { "xlxint.dat", "xlxc882hr.dat",
  		"dspe882.e56", "dspb882hr.b56", "dspd882.d56" },
  	[1] = { "xlxint.dat", "xlxc882e.dat",
  		"dspe882.e56", "dspb882e.b56", "dspd882.d56" },
  	[2] = { "xlxint.dat", "xlxc1222hr.dat",
  		"dspe882.e56", "dspb1222hr.b56", "dspd1222.d56" },
  	[3] = { "xlxint.dat", "xlxc1222e.dat",
  		"dspe882.e56", "dspb1222e.b56", "dspd1222.d56" },
  	[4] = { NULL, "xlxc222.dat",
  		"dspe924.e56", "dspb924.b56", "dspd222.d56" },
  	[5] = { NULL, "xlxc924.dat",
  		"dspe924.e56", "dspb924.b56", "dspd222.d56" },
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
386
387
388
389
390
  	};
  	char path[32];
  
  	const struct firmware *fw_entry;
  	int i, err;
7628700e0   Markus Bollinger   ALSA: pcxhr - add...
391
  	int fw_set = mgr->fw_file_set;
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
392

7628700e0   Markus Bollinger   ALSA: pcxhr - add...
393
394
395
396
  	for (i = 0; i < 5; i++) {
  		if (!fw_files[fw_set][i])
  			continue;
  		sprintf(path, "pcxhr/%s", fw_files[fw_set][i]);
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
397
  		if (request_firmware(&fw_entry, path, &mgr->pci->dev)) {
7628700e0   Markus Bollinger   ALSA: pcxhr - add...
398
399
400
  			snd_printk(KERN_ERR "pcxhr: can't load firmware %s
  ",
  				   path);
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
401
402
403
404
405
406
407
408
409
410
411
  			return -ENOENT;
  		}
  		/* fake hwdep dsp record */
  		err = pcxhr_dsp_load(mgr, i, fw_entry);
  		release_firmware(fw_entry);
  		if (err < 0)
  			return err;
  		mgr->dsp_loaded |= 1 << i;
  	}
  	return 0;
  }
ade9b2fb9   Markus Bollinger   ALSA: pcxhr - cha...
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
  MODULE_FIRMWARE("pcxhr/xlxint.dat");
  MODULE_FIRMWARE("pcxhr/xlxc882hr.dat");
  MODULE_FIRMWARE("pcxhr/xlxc882e.dat");
  MODULE_FIRMWARE("pcxhr/dspe882.e56");
  MODULE_FIRMWARE("pcxhr/dspb882hr.b56");
  MODULE_FIRMWARE("pcxhr/dspb882e.b56");
  MODULE_FIRMWARE("pcxhr/dspd882.d56");
  
  MODULE_FIRMWARE("pcxhr/xlxc1222hr.dat");
  MODULE_FIRMWARE("pcxhr/xlxc1222e.dat");
  MODULE_FIRMWARE("pcxhr/dspb1222hr.b56");
  MODULE_FIRMWARE("pcxhr/dspb1222e.b56");
  MODULE_FIRMWARE("pcxhr/dspd1222.d56");
  
  MODULE_FIRMWARE("pcxhr/xlxc222.dat");
  MODULE_FIRMWARE("pcxhr/xlxc924.dat");
  MODULE_FIRMWARE("pcxhr/dspe924.e56");
  MODULE_FIRMWARE("pcxhr/dspb924.b56");
  MODULE_FIRMWARE("pcxhr/dspd222.d56");
7628700e0   Markus Bollinger   ALSA: pcxhr - add...
431

e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
432
433
434
435
436
437
438
439
440
  #else /* old style firmware loading */
  
  /* pcxhr hwdep interface id string */
  #define PCXHR_HWDEP_ID       "pcxhr loader"
  
  
  static int pcxhr_hwdep_dsp_status(struct snd_hwdep *hw,
  				  struct snd_hwdep_dsp_status *info)
  {
7628700e0   Markus Bollinger   ALSA: pcxhr - add...
441
442
  	struct pcxhr_mgr *mgr = hw->private_data;
  	sprintf(info->id, "pcxhr%d", mgr->fw_file_set);
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
          info->num_dsps = PCXHR_FIRMWARE_FILES_MAX_INDEX;
  
  	if (hw->dsp_loaded & (1 << PCXHR_FIRMWARE_DSP_MAIN_INDEX))
  		info->chip_ready = 1;
  
  	info->version = PCXHR_DRIVER_VERSION;
  	return 0;
  }
  
  static int pcxhr_hwdep_dsp_load(struct snd_hwdep *hw,
  				struct snd_hwdep_dsp_image *dsp)
  {
  	struct pcxhr_mgr *mgr = hw->private_data;
  	int err;
  	struct firmware fw;
  
  	fw.size = dsp->length;
  	fw.data = vmalloc(fw.size);
  	if (! fw.data) {
7628700e0   Markus Bollinger   ALSA: pcxhr - add...
462
463
464
  		snd_printk(KERN_ERR "pcxhr: cannot allocate dsp image "
  			   "(%lu bytes)
  ", (unsigned long)fw.size);
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
465
466
  		return -ENOMEM;
  	}
67852dc08   David Howells   Fix a const point...
467
  	if (copy_from_user((void *)fw.data, dsp->image, dsp->length)) {
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
468
469
470
471
472
473
474
475
476
477
  		vfree(fw.data);
  		return -EFAULT;
  	}
  	err = pcxhr_dsp_load(mgr, dsp->index, &fw);
  	vfree(fw.data);
  	if (err < 0)
  		return err;
  	mgr->dsp_loaded |= 1 << dsp->index;
  	return 0;
  }
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
478
479
480
481
  int pcxhr_setup_firmware(struct pcxhr_mgr *mgr)
  {
  	int err;
  	struct snd_hwdep *hw;
7628700e0   Markus Bollinger   ALSA: pcxhr - add...
482
483
484
485
486
  	/* only create hwdep interface for first cardX
  	 * (see "index" module parameter)
  	 */
  	err = snd_hwdep_new(mgr->chip[0]->card, PCXHR_HWDEP_ID, 0, &hw);
  	if (err < 0)
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
487
488
489
490
  		return err;
  
  	hw->iface = SNDRV_HWDEP_IFACE_PCXHR;
  	hw->private_data = mgr;
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
491
492
493
  	hw->ops.dsp_status = pcxhr_hwdep_dsp_status;
  	hw->ops.dsp_load = pcxhr_hwdep_dsp_load;
  	hw->exclusive = 1;
7628700e0   Markus Bollinger   ALSA: pcxhr - add...
494
495
  	/* stereo cards don't need fw_file_0 -> dsp_loaded = 1 */
  	hw->dsp_loaded = mgr->is_hr_stereo ? 1 : 0;
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
496
497
  	mgr->dsp_loaded = 0;
  	sprintf(hw->name, PCXHR_HWDEP_ID);
7628700e0   Markus Bollinger   ALSA: pcxhr - add...
498
499
  	err = snd_card_register(mgr->chip[0]->card);
  	if (err < 0)
e12229b4d   Markus Bollinger   [ALSA] Add PCXHR ...
500
501
502
503
504
  		return err;
  	return 0;
  }
  
  #endif /* SND_PCXHR_FW_LOADER */