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 snd_printdd("supported formats : playback=%x capture=%x\n",
76 rmh
.stat
[2], rmh
.stat
[3]);
78 pcxhr_init_rmh(&rmh
, CMD_VERSION
);
79 /* firmware num for DSP */
80 rmh
.cmd
[0] |= mgr
->firmware_num
;
81 /* transfer granularity in samples (should be multiple of 48) */
82 rmh
.cmd
[1] = (1<<23) + mgr
->granularity
;
84 err
= pcxhr_send_msg(mgr
, &rmh
);
87 snd_printdd("PCXHR DSP version is %d.%d.%d\n", (rmh
.stat
[0]>>16)&0xff,
88 (rmh
.stat
[0]>>8)&0xff, rmh
.stat
[0]&0xff);
89 mgr
->dsp_version
= rmh
.stat
[0];
91 if (mgr
->is_hr_stereo
)
92 err
= hr222_sub_init(mgr
);
94 err
= pcxhr_sub_init(mgr
);
98 static int pcxhr_sub_init(struct pcxhr_mgr
*mgr
)
101 struct pcxhr_rmh rmh
;
104 pcxhr_init_rmh(&rmh
, CMD_ACCESS_IO_READ
);
105 rmh
.cmd
[0] |= IO_NUM_REG_STATUS
;
106 rmh
.cmd
[1] = REG_STATUS_OPTIONS
;
108 err
= pcxhr_send_msg(mgr
, &rmh
);
112 if ((rmh
.stat
[1] & REG_STATUS_OPT_DAUGHTER_MASK
) ==
113 REG_STATUS_OPT_ANALOG_BOARD
)
114 mgr
->board_has_analog
= 1; /* analog addon board found */
117 err
= pcxhr_write_io_num_reg_cont(mgr
, REG_CONT_UNMUTE_INPUTS
,
118 REG_CONT_UNMUTE_INPUTS
, NULL
);
121 /* unmute outputs (a write to IO_NUM_REG_MUTE_OUT mutes!) */
122 pcxhr_init_rmh(&rmh
, CMD_ACCESS_IO_READ
);
123 rmh
.cmd
[0] |= IO_NUM_REG_MUTE_OUT
;
124 if (DSP_EXT_CMD_SET(mgr
)) {
125 rmh
.cmd
[1] = 1; /* unmute digital plugs */
128 err
= pcxhr_send_msg(mgr
, &rmh
);
132 void pcxhr_reset_board(struct pcxhr_mgr
*mgr
)
134 struct pcxhr_rmh rmh
;
136 if (mgr
->dsp_loaded
& (1 << PCXHR_FIRMWARE_DSP_MAIN_INDEX
)) {
138 if (!mgr
->is_hr_stereo
) {
139 /* a read to IO_NUM_REG_MUTE_OUT register unmutes! */
140 pcxhr_init_rmh(&rmh
, CMD_ACCESS_IO_WRITE
);
141 rmh
.cmd
[0] |= IO_NUM_REG_MUTE_OUT
;
142 pcxhr_send_msg(mgr
, &rmh
);
144 pcxhr_write_io_num_reg_cont(mgr
, REG_CONT_UNMUTE_INPUTS
,
147 /* stereo cards mute with reset of dsp */
149 /* reset pcxhr dsp */
150 if (mgr
->dsp_loaded
& (1 << PCXHR_FIRMWARE_DSP_EPRM_INDEX
))
151 pcxhr_reset_dsp(mgr
);
152 /* reset second xilinx */
153 if (mgr
->dsp_loaded
& (1 << PCXHR_FIRMWARE_XLX_COM_INDEX
)) {
154 pcxhr_reset_xilinx_com(mgr
);
162 * allocate a playback/capture pipe (pcmp0/pcmc0)
164 static int pcxhr_dsp_allocate_pipe(struct pcxhr_mgr
*mgr
,
165 struct pcxhr_pipe
*pipe
,
166 int is_capture
, int pin
)
168 int stream_count
, audio_count
;
170 struct pcxhr_rmh rmh
;
174 if (mgr
->mono_capture
)
179 stream_count
= PCXHR_PLAYBACK_STREAMS
;
180 audio_count
= 2; /* always stereo */
182 snd_printdd("snd_add_ref_pipe pin(%d) pcm%c0\n",
183 pin
, is_capture
? 'c' : 'p');
184 pipe
->is_capture
= is_capture
;
185 pipe
->first_audio
= pin
;
186 /* define pipe (P_PCM_ONLY_MASK (0x020000) is not necessary) */
187 pcxhr_init_rmh(&rmh
, CMD_RES_PIPE
);
188 pcxhr_set_pipe_cmd_params(&rmh
, is_capture
, pin
,
189 audio_count
, stream_count
);
190 rmh
.cmd
[1] |= 0x020000; /* add P_PCM_ONLY_MASK */
191 if (DSP_EXT_CMD_SET(mgr
)) {
192 /* add channel mask to command */
193 rmh
.cmd
[rmh
.cmd_len
++] = (audio_count
== 1) ? 0x01 : 0x03;
195 err
= pcxhr_send_msg(mgr
, &rmh
);
197 snd_printk(KERN_ERR
"error pipe allocation "
198 "(CMD_RES_PIPE) err=%x!\n", err
);
201 pipe
->status
= PCXHR_PIPE_DEFINED
;
207 * free playback/capture pipe (pcmp0/pcmc0)
210 static int pcxhr_dsp_free_pipe( struct pcxhr_mgr
*mgr
, struct pcxhr_pipe
*pipe
)
212 struct pcxhr_rmh rmh
;
213 int capture_mask
= 0;
214 int playback_mask
= 0;
217 if (pipe
->is_capture
)
218 capture_mask
= (1 << pipe
->first_audio
);
220 playback_mask
= (1 << pipe
->first_audio
);
223 err
= pcxhr_set_pipe_state(mgr
, playback_mask
, capture_mask
, 0);
225 snd_printk(KERN_ERR
"error stopping pipe!\n");
226 /* release the pipe */
227 pcxhr_init_rmh(&rmh
, CMD_FREE_PIPE
);
228 pcxhr_set_pipe_cmd_params(&rmh
, pipe
->is_capture
, pipe
->first_audio
,
230 err
= pcxhr_send_msg(mgr
, &rmh
);
232 snd_printk(KERN_ERR
"error pipe release "
233 "(CMD_FREE_PIPE) err(%x)\n", err
);
234 pipe
->status
= PCXHR_PIPE_UNDEFINED
;
240 static int pcxhr_config_pipes(struct pcxhr_mgr
*mgr
)
243 struct snd_pcxhr
*chip
;
244 struct pcxhr_pipe
*pipe
;
246 /* allocate the pipes on the dsp */
247 for (i
= 0; i
< mgr
->num_cards
; i
++) {
249 if (chip
->nb_streams_play
) {
250 pipe
= &chip
->playback_pipe
;
251 err
= pcxhr_dsp_allocate_pipe( mgr
, pipe
, 0, i
*2);
254 for(j
= 0; j
< chip
->nb_streams_play
; j
++)
255 chip
->playback_stream
[j
].pipe
= pipe
;
257 for (j
= 0; j
< chip
->nb_streams_capt
; j
++) {
258 pipe
= &chip
->capture_pipe
[j
];
259 err
= pcxhr_dsp_allocate_pipe(mgr
, pipe
, 1, i
*2 + j
);
262 chip
->capture_stream
[j
].pipe
= pipe
;
268 static int pcxhr_start_pipes(struct pcxhr_mgr
*mgr
)
271 struct snd_pcxhr
*chip
;
272 int playback_mask
= 0;
273 int capture_mask
= 0;
275 /* start all the pipes on the dsp */
276 for (i
= 0; i
< mgr
->num_cards
; i
++) {
278 if (chip
->nb_streams_play
)
279 playback_mask
|= 1 << chip
->playback_pipe
.first_audio
;
280 for (j
= 0; j
< chip
->nb_streams_capt
; j
++)
281 capture_mask
|= 1 << chip
->capture_pipe
[j
].first_audio
;
283 return pcxhr_set_pipe_state(mgr
, playback_mask
, capture_mask
, 1);
287 static int pcxhr_dsp_load(struct pcxhr_mgr
*mgr
, int index
,
288 const struct firmware
*dsp
)
292 snd_printdd("loading dsp [%d] size = %Zd\n", index
, dsp
->size
);
295 case PCXHR_FIRMWARE_XLX_INT_INDEX
:
296 pcxhr_reset_xilinx_com(mgr
);
297 return pcxhr_load_xilinx_binary(mgr
, dsp
, 0);
299 case PCXHR_FIRMWARE_XLX_COM_INDEX
:
300 pcxhr_reset_xilinx_com(mgr
);
301 return pcxhr_load_xilinx_binary(mgr
, dsp
, 1);
303 case PCXHR_FIRMWARE_DSP_EPRM_INDEX
:
304 pcxhr_reset_dsp(mgr
);
305 return pcxhr_load_eeprom_binary(mgr
, dsp
);
307 case PCXHR_FIRMWARE_DSP_BOOT_INDEX
:
308 return pcxhr_load_boot_binary(mgr
, dsp
);
310 case PCXHR_FIRMWARE_DSP_MAIN_INDEX
:
311 err
= pcxhr_load_dsp_binary(mgr
, dsp
);
314 break; /* continue with first init */
316 snd_printk(KERN_ERR
"wrong file index\n");
318 } /* end of switch file index*/
320 /* first communication with embedded */
321 err
= pcxhr_init_board(mgr
);
323 snd_printk(KERN_ERR
"pcxhr could not be set up\n");
326 err
= pcxhr_config_pipes(mgr
);
328 snd_printk(KERN_ERR
"pcxhr pipes could not be set up\n");
331 /* create devices and mixer in accordance with HW options*/
332 for (card_index
= 0; card_index
< mgr
->num_cards
; card_index
++) {
333 struct snd_pcxhr
*chip
= mgr
->chip
[card_index
];
335 if ((err
= pcxhr_create_pcm(chip
)) < 0)
338 if (card_index
== 0) {
339 if ((err
= pcxhr_create_mixer(chip
->mgr
)) < 0)
342 if ((err
= snd_card_register(chip
->card
)) < 0)
345 err
= pcxhr_start_pipes(mgr
);
347 snd_printk(KERN_ERR
"pcxhr pipes could not be started\n");
350 snd_printdd("pcxhr firmware downloaded and successfully set up\n");
358 int pcxhr_setup_firmware(struct pcxhr_mgr
*mgr
)
360 static char *fw_files
[][5] = {
361 [0] = { "xlxint.dat", "xlxc882hr.dat",
362 "dspe882.e56", "dspb882hr.b56", "dspd882.d56" },
363 [1] = { "xlxint.dat", "xlxc882e.dat",
364 "dspe882.e56", "dspb882e.b56", "dspd882.d56" },
365 [2] = { "xlxint.dat", "xlxc1222hr.dat",
366 "dspe882.e56", "dspb1222hr.b56", "dspd1222.d56" },
367 [3] = { "xlxint.dat", "xlxc1222e.dat",
368 "dspe882.e56", "dspb1222e.b56", "dspd1222.d56" },
369 [4] = { NULL
, "xlxc222.dat",
370 "dspe924.e56", "dspb924.b56", "dspd222.d56" },
371 [5] = { NULL
, "xlxc924.dat",
372 "dspe924.e56", "dspb924.b56", "dspd222.d56" },
376 const struct firmware
*fw_entry
;
378 int fw_set
= mgr
->fw_file_set
;
380 for (i
= 0; i
< 5; i
++) {
381 if (!fw_files
[fw_set
][i
])
383 sprintf(path
, "pcxhr/%s", fw_files
[fw_set
][i
]);
384 if (request_firmware(&fw_entry
, path
, &mgr
->pci
->dev
)) {
385 snd_printk(KERN_ERR
"pcxhr: can't load firmware %s\n",
389 /* fake hwdep dsp record */
390 err
= pcxhr_dsp_load(mgr
, i
, fw_entry
);
391 release_firmware(fw_entry
);
394 mgr
->dsp_loaded
|= 1 << i
;
399 MODULE_FIRMWARE("pcxhr/xlxint.dat");
400 MODULE_FIRMWARE("pcxhr/xlxc882hr.dat");
401 MODULE_FIRMWARE("pcxhr/xlxc882e.dat");
402 MODULE_FIRMWARE("pcxhr/dspe882.e56");
403 MODULE_FIRMWARE("pcxhr/dspb882hr.b56");
404 MODULE_FIRMWARE("pcxhr/dspb882e.b56");
405 MODULE_FIRMWARE("pcxhr/dspd882.d56");
407 MODULE_FIRMWARE("pcxhr/xlxc1222hr.dat");
408 MODULE_FIRMWARE("pcxhr/xlxc1222e.dat");
409 MODULE_FIRMWARE("pcxhr/dspb1222hr.b56");
410 MODULE_FIRMWARE("pcxhr/dspb1222e.b56");
411 MODULE_FIRMWARE("pcxhr/dspd1222.d56");
413 MODULE_FIRMWARE("pcxhr/xlxc222.dat");
414 MODULE_FIRMWARE("pcxhr/xlxc924.dat");
415 MODULE_FIRMWARE("pcxhr/dspe924.e56");
416 MODULE_FIRMWARE("pcxhr/dspb924.b56");
417 MODULE_FIRMWARE("pcxhr/dspd222.d56");