2 * Driver for Digigram pcxhr compatible soundcards
6 * Copyright (c) 2004 by Digigram <alsa@digigram.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <linux/interrupt.h>
24 #include <linux/vmalloc.h>
25 #include <linux/firmware.h>
26 #include <linux/pci.h>
27 #include <linux/module.h>
29 #include <sound/core.h>
30 #include <sound/hwdep.h>
32 #include "pcxhr_mixer.h"
33 #include "pcxhr_hwdep.h"
34 #include "pcxhr_core.h"
35 #include "pcxhr_mix22.h"
38 static int pcxhr_sub_init(struct pcxhr_mgr
*mgr
);
40 * get basic information and init pcxhr card
42 static int pcxhr_init_board(struct pcxhr_mgr
*mgr
)
48 /* calc the number of all streams used */
49 if (mgr
->mono_capture
)
50 card_streams
= mgr
->capture_chips
* 2;
52 card_streams
= mgr
->capture_chips
;
53 card_streams
+= mgr
->playback_chips
* PCXHR_PLAYBACK_STREAMS
;
55 /* enable interrupts */
56 pcxhr_enable_dsp(mgr
);
58 pcxhr_init_rmh(&rmh
, CMD_SUPPORTED
);
59 err
= pcxhr_send_msg(mgr
, &rmh
);
62 /* test 4, 8 or 12 phys out */
63 if ((rmh
.stat
[0] & MASK_FIRST_FIELD
) < mgr
->playback_chips
* 2)
65 /* test 4, 8 or 2 phys in */
66 if (((rmh
.stat
[0] >> (2 * FIELD_SIZE
)) & MASK_FIRST_FIELD
) <
67 mgr
->capture_chips
* 2)
69 /* test max nb substream per board */
70 if ((rmh
.stat
[1] & 0x5F) < card_streams
)
72 /* test max nb substream per pipe */
73 if (((rmh
.stat
[1] >> 7) & 0x5F) < PCXHR_PLAYBACK_STREAMS
)
75 dev_dbg(&mgr
->pci
->dev
,
76 "supported formats : playback=%x capture=%x\n",
77 rmh
.stat
[2], rmh
.stat
[3]);
79 pcxhr_init_rmh(&rmh
, CMD_VERSION
);
80 /* firmware num for DSP */
81 rmh
.cmd
[0] |= mgr
->firmware_num
;
82 /* transfer granularity in samples (should be multiple of 48) */
83 rmh
.cmd
[1] = (1<<23) + mgr
->granularity
;
85 err
= pcxhr_send_msg(mgr
, &rmh
);
88 dev_dbg(&mgr
->pci
->dev
,
89 "PCXHR DSP version is %d.%d.%d\n", (rmh
.stat
[0]>>16)&0xff,
90 (rmh
.stat
[0]>>8)&0xff, rmh
.stat
[0]&0xff);
91 mgr
->dsp_version
= rmh
.stat
[0];
93 if (mgr
->is_hr_stereo
)
94 err
= hr222_sub_init(mgr
);
96 err
= pcxhr_sub_init(mgr
);
100 static int pcxhr_sub_init(struct pcxhr_mgr
*mgr
)
103 struct pcxhr_rmh rmh
;
106 pcxhr_init_rmh(&rmh
, CMD_ACCESS_IO_READ
);
107 rmh
.cmd
[0] |= IO_NUM_REG_STATUS
;
108 rmh
.cmd
[1] = REG_STATUS_OPTIONS
;
110 err
= pcxhr_send_msg(mgr
, &rmh
);
114 if ((rmh
.stat
[1] & REG_STATUS_OPT_DAUGHTER_MASK
) ==
115 REG_STATUS_OPT_ANALOG_BOARD
)
116 mgr
->board_has_analog
= 1; /* analog addon board found */
119 err
= pcxhr_write_io_num_reg_cont(mgr
, REG_CONT_UNMUTE_INPUTS
,
120 REG_CONT_UNMUTE_INPUTS
, NULL
);
123 /* unmute outputs (a write to IO_NUM_REG_MUTE_OUT mutes!) */
124 pcxhr_init_rmh(&rmh
, CMD_ACCESS_IO_READ
);
125 rmh
.cmd
[0] |= IO_NUM_REG_MUTE_OUT
;
126 if (DSP_EXT_CMD_SET(mgr
)) {
127 rmh
.cmd
[1] = 1; /* unmute digital plugs */
130 err
= pcxhr_send_msg(mgr
, &rmh
);
134 void pcxhr_reset_board(struct pcxhr_mgr
*mgr
)
136 struct pcxhr_rmh rmh
;
138 if (mgr
->dsp_loaded
& (1 << PCXHR_FIRMWARE_DSP_MAIN_INDEX
)) {
140 if (!mgr
->is_hr_stereo
) {
141 /* a read to IO_NUM_REG_MUTE_OUT register unmutes! */
142 pcxhr_init_rmh(&rmh
, CMD_ACCESS_IO_WRITE
);
143 rmh
.cmd
[0] |= IO_NUM_REG_MUTE_OUT
;
144 pcxhr_send_msg(mgr
, &rmh
);
146 pcxhr_write_io_num_reg_cont(mgr
, REG_CONT_UNMUTE_INPUTS
,
149 /* stereo cards mute with reset of dsp */
151 /* reset pcxhr dsp */
152 if (mgr
->dsp_loaded
& (1 << PCXHR_FIRMWARE_DSP_EPRM_INDEX
))
153 pcxhr_reset_dsp(mgr
);
154 /* reset second xilinx */
155 if (mgr
->dsp_loaded
& (1 << PCXHR_FIRMWARE_XLX_COM_INDEX
)) {
156 pcxhr_reset_xilinx_com(mgr
);
164 * allocate a playback/capture pipe (pcmp0/pcmc0)
166 static int pcxhr_dsp_allocate_pipe(struct pcxhr_mgr
*mgr
,
167 struct pcxhr_pipe
*pipe
,
168 int is_capture
, int pin
)
170 int stream_count
, audio_count
;
172 struct pcxhr_rmh rmh
;
176 if (mgr
->mono_capture
)
181 stream_count
= PCXHR_PLAYBACK_STREAMS
;
182 audio_count
= 2; /* always stereo */
184 dev_dbg(&mgr
->pci
->dev
, "snd_add_ref_pipe pin(%d) pcm%c0\n",
185 pin
, is_capture
? 'c' : 'p');
186 pipe
->is_capture
= is_capture
;
187 pipe
->first_audio
= pin
;
188 /* define pipe (P_PCM_ONLY_MASK (0x020000) is not necessary) */
189 pcxhr_init_rmh(&rmh
, CMD_RES_PIPE
);
190 pcxhr_set_pipe_cmd_params(&rmh
, is_capture
, pin
,
191 audio_count
, stream_count
);
192 rmh
.cmd
[1] |= 0x020000; /* add P_PCM_ONLY_MASK */
193 if (DSP_EXT_CMD_SET(mgr
)) {
194 /* add channel mask to command */
195 rmh
.cmd
[rmh
.cmd_len
++] = (audio_count
== 1) ? 0x01 : 0x03;
197 err
= pcxhr_send_msg(mgr
, &rmh
);
199 dev_err(&mgr
->pci
->dev
, "error pipe allocation "
200 "(CMD_RES_PIPE) err=%x!\n", err
);
203 pipe
->status
= PCXHR_PIPE_DEFINED
;
209 * free playback/capture pipe (pcmp0/pcmc0)
212 static int pcxhr_dsp_free_pipe( struct pcxhr_mgr
*mgr
, struct pcxhr_pipe
*pipe
)
214 struct pcxhr_rmh rmh
;
215 int capture_mask
= 0;
216 int playback_mask
= 0;
219 if (pipe
->is_capture
)
220 capture_mask
= (1 << pipe
->first_audio
);
222 playback_mask
= (1 << pipe
->first_audio
);
225 err
= pcxhr_set_pipe_state(mgr
, playback_mask
, capture_mask
, 0);
227 dev_err(&mgr
->pci
->dev
, "error stopping pipe!\n");
228 /* release the pipe */
229 pcxhr_init_rmh(&rmh
, CMD_FREE_PIPE
);
230 pcxhr_set_pipe_cmd_params(&rmh
, pipe
->is_capture
, pipe
->first_audio
,
232 err
= pcxhr_send_msg(mgr
, &rmh
);
234 dev_err(&mgr
->pci
->dev
, "error pipe release "
235 "(CMD_FREE_PIPE) err(%x)\n", err
);
236 pipe
->status
= PCXHR_PIPE_UNDEFINED
;
242 static int pcxhr_config_pipes(struct pcxhr_mgr
*mgr
)
245 struct snd_pcxhr
*chip
;
246 struct pcxhr_pipe
*pipe
;
248 /* allocate the pipes on the dsp */
249 for (i
= 0; i
< mgr
->num_cards
; i
++) {
251 if (chip
->nb_streams_play
) {
252 pipe
= &chip
->playback_pipe
;
253 err
= pcxhr_dsp_allocate_pipe( mgr
, pipe
, 0, i
*2);
256 for(j
= 0; j
< chip
->nb_streams_play
; j
++)
257 chip
->playback_stream
[j
].pipe
= pipe
;
259 for (j
= 0; j
< chip
->nb_streams_capt
; j
++) {
260 pipe
= &chip
->capture_pipe
[j
];
261 err
= pcxhr_dsp_allocate_pipe(mgr
, pipe
, 1, i
*2 + j
);
264 chip
->capture_stream
[j
].pipe
= pipe
;
270 static int pcxhr_start_pipes(struct pcxhr_mgr
*mgr
)
273 struct snd_pcxhr
*chip
;
274 int playback_mask
= 0;
275 int capture_mask
= 0;
277 /* start all the pipes on the dsp */
278 for (i
= 0; i
< mgr
->num_cards
; i
++) {
280 if (chip
->nb_streams_play
)
281 playback_mask
|= 1 << chip
->playback_pipe
.first_audio
;
282 for (j
= 0; j
< chip
->nb_streams_capt
; j
++)
283 capture_mask
|= 1 << chip
->capture_pipe
[j
].first_audio
;
285 return pcxhr_set_pipe_state(mgr
, playback_mask
, capture_mask
, 1);
289 static int pcxhr_dsp_load(struct pcxhr_mgr
*mgr
, int index
,
290 const struct firmware
*dsp
)
294 dev_dbg(&mgr
->pci
->dev
,
295 "loading dsp [%d] size = %zd\n", index
, dsp
->size
);
298 case PCXHR_FIRMWARE_XLX_INT_INDEX
:
299 pcxhr_reset_xilinx_com(mgr
);
300 return pcxhr_load_xilinx_binary(mgr
, dsp
, 0);
302 case PCXHR_FIRMWARE_XLX_COM_INDEX
:
303 pcxhr_reset_xilinx_com(mgr
);
304 return pcxhr_load_xilinx_binary(mgr
, dsp
, 1);
306 case PCXHR_FIRMWARE_DSP_EPRM_INDEX
:
307 pcxhr_reset_dsp(mgr
);
308 return pcxhr_load_eeprom_binary(mgr
, dsp
);
310 case PCXHR_FIRMWARE_DSP_BOOT_INDEX
:
311 return pcxhr_load_boot_binary(mgr
, dsp
);
313 case PCXHR_FIRMWARE_DSP_MAIN_INDEX
:
314 err
= pcxhr_load_dsp_binary(mgr
, dsp
);
317 break; /* continue with first init */
319 dev_err(&mgr
->pci
->dev
, "wrong file index\n");
321 } /* end of switch file index*/
323 /* first communication with embedded */
324 err
= pcxhr_init_board(mgr
);
326 dev_err(&mgr
->pci
->dev
, "pcxhr could not be set up\n");
329 err
= pcxhr_config_pipes(mgr
);
331 dev_err(&mgr
->pci
->dev
, "pcxhr pipes could not be set up\n");
334 /* create devices and mixer in accordance with HW options*/
335 for (card_index
= 0; card_index
< mgr
->num_cards
; card_index
++) {
336 struct snd_pcxhr
*chip
= mgr
->chip
[card_index
];
338 if ((err
= pcxhr_create_pcm(chip
)) < 0)
341 if (card_index
== 0) {
342 if ((err
= pcxhr_create_mixer(chip
->mgr
)) < 0)
345 if ((err
= snd_card_register(chip
->card
)) < 0)
348 err
= pcxhr_start_pipes(mgr
);
350 dev_err(&mgr
->pci
->dev
, "pcxhr pipes could not be started\n");
353 dev_dbg(&mgr
->pci
->dev
,
354 "pcxhr firmware downloaded and successfully set up\n");
362 int pcxhr_setup_firmware(struct pcxhr_mgr
*mgr
)
364 static char *fw_files
[][5] = {
365 [0] = { "xlxint.dat", "xlxc882hr.dat",
366 "dspe882.e56", "dspb882hr.b56", "dspd882.d56" },
367 [1] = { "xlxint.dat", "xlxc882e.dat",
368 "dspe882.e56", "dspb882e.b56", "dspd882.d56" },
369 [2] = { "xlxint.dat", "xlxc1222hr.dat",
370 "dspe882.e56", "dspb1222hr.b56", "dspd1222.d56" },
371 [3] = { "xlxint.dat", "xlxc1222e.dat",
372 "dspe882.e56", "dspb1222e.b56", "dspd1222.d56" },
373 [4] = { NULL
, "xlxc222.dat",
374 "dspe924.e56", "dspb924.b56", "dspd222.d56" },
375 [5] = { NULL
, "xlxc924.dat",
376 "dspe924.e56", "dspb924.b56", "dspd222.d56" },
380 const struct firmware
*fw_entry
;
382 int fw_set
= mgr
->fw_file_set
;
384 for (i
= 0; i
< 5; i
++) {
385 if (!fw_files
[fw_set
][i
])
387 sprintf(path
, "pcxhr/%s", fw_files
[fw_set
][i
]);
388 if (request_firmware(&fw_entry
, path
, &mgr
->pci
->dev
)) {
389 dev_err(&mgr
->pci
->dev
,
390 "pcxhr: can't load firmware %s\n",
394 /* fake hwdep dsp record */
395 err
= pcxhr_dsp_load(mgr
, i
, fw_entry
);
396 release_firmware(fw_entry
);
399 mgr
->dsp_loaded
|= 1 << i
;
404 MODULE_FIRMWARE("pcxhr/xlxint.dat");
405 MODULE_FIRMWARE("pcxhr/xlxc882hr.dat");
406 MODULE_FIRMWARE("pcxhr/xlxc882e.dat");
407 MODULE_FIRMWARE("pcxhr/dspe882.e56");
408 MODULE_FIRMWARE("pcxhr/dspb882hr.b56");
409 MODULE_FIRMWARE("pcxhr/dspb882e.b56");
410 MODULE_FIRMWARE("pcxhr/dspd882.d56");
412 MODULE_FIRMWARE("pcxhr/xlxc1222hr.dat");
413 MODULE_FIRMWARE("pcxhr/xlxc1222e.dat");
414 MODULE_FIRMWARE("pcxhr/dspb1222hr.b56");
415 MODULE_FIRMWARE("pcxhr/dspb1222e.b56");
416 MODULE_FIRMWARE("pcxhr/dspd1222.d56");
418 MODULE_FIRMWARE("pcxhr/xlxc222.dat");
419 MODULE_FIRMWARE("pcxhr/xlxc924.dat");
420 MODULE_FIRMWARE("pcxhr/dspe924.e56");
421 MODULE_FIRMWARE("pcxhr/dspb924.b56");
422 MODULE_FIRMWARE("pcxhr/dspd222.d56");