Commit 7628700e authored by Markus Bollinger's avatar Markus Bollinger Committed by Takashi Iwai

ALSA: pcxhr - add support for pcxhr stereo sound cards (firmware support)

- Add support for pcxhr stereo cards and their firmware
- autorize sound cards without analog IO
- do some cleanup
Signed-off-by: default avatarMarkus Bollinger <bollinger@digigram.com>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 9d948d27
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "pcxhr_mixer.h" #include "pcxhr_mixer.h"
#include "pcxhr_hwdep.h" #include "pcxhr_hwdep.h"
#include "pcxhr_core.h" #include "pcxhr_core.h"
#include "pcxhr_mix22.h"
#if defined(CONFIG_FW_LOADER) || defined(CONFIG_FW_LOADER_MODULE) #if defined(CONFIG_FW_LOADER) || defined(CONFIG_FW_LOADER_MODULE)
...@@ -40,10 +41,10 @@ ...@@ -40,10 +41,10 @@
#endif #endif
static int pcxhr_sub_init(struct pcxhr_mgr *mgr);
/* /*
* get basic information and init pcxhr card * get basic information and init pcxhr card
*/ */
static int pcxhr_init_board(struct pcxhr_mgr *mgr) static int pcxhr_init_board(struct pcxhr_mgr *mgr)
{ {
int err; int err;
...@@ -68,7 +69,7 @@ static int pcxhr_init_board(struct pcxhr_mgr *mgr) ...@@ -68,7 +69,7 @@ static int pcxhr_init_board(struct pcxhr_mgr *mgr)
if ((rmh.stat[0] & MASK_FIRST_FIELD) != mgr->playback_chips * 2) if ((rmh.stat[0] & MASK_FIRST_FIELD) != mgr->playback_chips * 2)
return -EINVAL; return -EINVAL;
/* test 8 or 2 phys in */ /* test 8 or 2 phys in */
if (((rmh.stat[0] >> (2 * FIELD_SIZE)) & MASK_FIRST_FIELD) != if (((rmh.stat[0] >> (2 * FIELD_SIZE)) & MASK_FIRST_FIELD) <
mgr->capture_chips * 2) mgr->capture_chips * 2)
return -EINVAL; return -EINVAL;
/* test max nb substream per board */ /* test max nb substream per board */
...@@ -77,20 +78,34 @@ static int pcxhr_init_board(struct pcxhr_mgr *mgr) ...@@ -77,20 +78,34 @@ static int pcxhr_init_board(struct pcxhr_mgr *mgr)
/* test max nb substream per pipe */ /* test max nb substream per pipe */
if (((rmh.stat[1] >> 7) & 0x5F) < PCXHR_PLAYBACK_STREAMS) if (((rmh.stat[1] >> 7) & 0x5F) < PCXHR_PLAYBACK_STREAMS)
return -EINVAL; return -EINVAL;
snd_printdd("supported formats : playback=%x capture=%x\n",
rmh.stat[2], rmh.stat[3]);
pcxhr_init_rmh(&rmh, CMD_VERSION); pcxhr_init_rmh(&rmh, CMD_VERSION);
/* firmware num for DSP */ /* firmware num for DSP */
rmh.cmd[0] |= mgr->firmware_num; rmh.cmd[0] |= mgr->firmware_num;
/* transfer granularity in samples (should be multiple of 48) */ /* transfer granularity in samples (should be multiple of 48) */
rmh.cmd[1] = (1<<23) + PCXHR_GRANULARITY; rmh.cmd[1] = (1<<23) + mgr->granularity;
rmh.cmd_len = 2; rmh.cmd_len = 2;
err = pcxhr_send_msg(mgr, &rmh); err = pcxhr_send_msg(mgr, &rmh);
if (err) if (err)
return err; return err;
snd_printdd("PCXHR DSP version is %d.%d.%d\n", snd_printdd("PCXHR DSP version is %d.%d.%d\n", (rmh.stat[0]>>16)&0xff,
(rmh.stat[0]>>16)&0xff, (rmh.stat[0]>>8)&0xff, rmh.stat[0]&0xff); (rmh.stat[0]>>8)&0xff, rmh.stat[0]&0xff);
mgr->dsp_version = rmh.stat[0]; mgr->dsp_version = rmh.stat[0];
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;
/* get options */ /* get options */
pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_READ); pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_READ);
rmh.cmd[0] |= IO_NUM_REG_STATUS; rmh.cmd[0] |= IO_NUM_REG_STATUS;
...@@ -100,20 +115,22 @@ static int pcxhr_init_board(struct pcxhr_mgr *mgr) ...@@ -100,20 +115,22 @@ static int pcxhr_init_board(struct pcxhr_mgr *mgr)
if (err) if (err)
return err; return err;
if ((rmh.stat[1] & REG_STATUS_OPT_DAUGHTER_MASK) == REG_STATUS_OPT_ANALOG_BOARD) if ((rmh.stat[1] & REG_STATUS_OPT_DAUGHTER_MASK) ==
mgr->board_has_analog = 1; /* analog addon board available */ REG_STATUS_OPT_ANALOG_BOARD)
else mgr->board_has_analog = 1; /* analog addon board found */
/* analog addon board not available -> no support for instance */
return -EINVAL;
/* unmute inputs */ /* unmute inputs */
err = pcxhr_write_io_num_reg_cont(mgr, REG_CONT_UNMUTE_INPUTS, err = pcxhr_write_io_num_reg_cont(mgr, REG_CONT_UNMUTE_INPUTS,
REG_CONT_UNMUTE_INPUTS, NULL); REG_CONT_UNMUTE_INPUTS, NULL);
if (err) if (err)
return err; return err;
/* unmute outputs */ /* unmute outputs (a write to IO_NUM_REG_MUTE_OUT mutes!) */
pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_READ); /* a write to IO_NUM_REG_MUTE_OUT mutes! */ pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_READ);
rmh.cmd[0] |= IO_NUM_REG_MUTE_OUT; rmh.cmd[0] |= IO_NUM_REG_MUTE_OUT;
if (DSP_EXT_CMD_SET(mgr)) {
rmh.cmd[1] = 1; /* unmute digital plugs */
rmh.cmd_len = 2;
}
err = pcxhr_send_msg(mgr, &rmh); err = pcxhr_send_msg(mgr, &rmh);
return err; return err;
} }
...@@ -124,19 +141,25 @@ void pcxhr_reset_board(struct pcxhr_mgr *mgr) ...@@ -124,19 +141,25 @@ void pcxhr_reset_board(struct pcxhr_mgr *mgr)
if (mgr->dsp_loaded & (1 << PCXHR_FIRMWARE_DSP_MAIN_INDEX)) { if (mgr->dsp_loaded & (1 << PCXHR_FIRMWARE_DSP_MAIN_INDEX)) {
/* mute outputs */ /* mute outputs */
if (!mgr->is_hr_stereo) {
/* a read to IO_NUM_REG_MUTE_OUT register unmutes! */ /* a read to IO_NUM_REG_MUTE_OUT register unmutes! */
pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE); pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE);
rmh.cmd[0] |= IO_NUM_REG_MUTE_OUT; rmh.cmd[0] |= IO_NUM_REG_MUTE_OUT;
pcxhr_send_msg(mgr, &rmh); pcxhr_send_msg(mgr, &rmh);
/* mute inputs */ /* mute inputs */
pcxhr_write_io_num_reg_cont(mgr, REG_CONT_UNMUTE_INPUTS, 0, NULL); pcxhr_write_io_num_reg_cont(mgr, REG_CONT_UNMUTE_INPUTS,
0, NULL);
}
/* stereo cards mute with reset of dsp */
} }
/* reset pcxhr dsp */ /* reset pcxhr dsp */
if (mgr->dsp_loaded & ( 1 << PCXHR_FIRMWARE_DSP_EPRM_INDEX)) if (mgr->dsp_loaded & (1 << PCXHR_FIRMWARE_DSP_EPRM_INDEX))
pcxhr_reset_dsp(mgr); pcxhr_reset_dsp(mgr);
/* reset second xilinx */ /* reset second xilinx */
if (mgr->dsp_loaded & ( 1 << PCXHR_FIRMWARE_XLX_COM_INDEX)) if (mgr->dsp_loaded & (1 << PCXHR_FIRMWARE_XLX_COM_INDEX)) {
pcxhr_reset_xilinx_com(mgr); pcxhr_reset_xilinx_com(mgr);
mgr->dsp_loaded = 1;
}
return; return;
} }
...@@ -144,8 +167,9 @@ void pcxhr_reset_board(struct pcxhr_mgr *mgr) ...@@ -144,8 +167,9 @@ void pcxhr_reset_board(struct pcxhr_mgr *mgr)
/* /*
* allocate a playback/capture pipe (pcmp0/pcmc0) * allocate a playback/capture pipe (pcmp0/pcmc0)
*/ */
static int pcxhr_dsp_allocate_pipe( struct pcxhr_mgr *mgr, struct pcxhr_pipe *pipe, static int pcxhr_dsp_allocate_pipe(struct pcxhr_mgr *mgr,
int is_capture, int pin) struct pcxhr_pipe *pipe,
int is_capture, int pin)
{ {
int stream_count, audio_count; int stream_count, audio_count;
int err; int err;
...@@ -161,15 +185,23 @@ static int pcxhr_dsp_allocate_pipe( struct pcxhr_mgr *mgr, struct pcxhr_pipe *pi ...@@ -161,15 +185,23 @@ static int pcxhr_dsp_allocate_pipe( struct pcxhr_mgr *mgr, struct pcxhr_pipe *pi
stream_count = PCXHR_PLAYBACK_STREAMS; stream_count = PCXHR_PLAYBACK_STREAMS;
audio_count = 2; /* always stereo */ audio_count = 2; /* always stereo */
} }
snd_printdd("snd_add_ref_pipe pin(%d) pcm%c0\n", pin, is_capture ? 'c' : 'p'); snd_printdd("snd_add_ref_pipe pin(%d) pcm%c0\n",
pin, is_capture ? 'c' : 'p');
pipe->is_capture = is_capture; pipe->is_capture = is_capture;
pipe->first_audio = pin; pipe->first_audio = pin;
/* define pipe (P_PCM_ONLY_MASK (0x020000) is not necessary) */ /* define pipe (P_PCM_ONLY_MASK (0x020000) is not necessary) */
pcxhr_init_rmh(&rmh, CMD_RES_PIPE); pcxhr_init_rmh(&rmh, CMD_RES_PIPE);
pcxhr_set_pipe_cmd_params(&rmh, is_capture, pin, audio_count, stream_count); 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;
}
err = pcxhr_send_msg(mgr, &rmh); err = pcxhr_send_msg(mgr, &rmh);
if (err < 0) { if (err < 0) {
snd_printk(KERN_ERR "error pipe allocation (CMD_RES_PIPE) err=%x!\n", err ); snd_printk(KERN_ERR "error pipe allocation "
"(CMD_RES_PIPE) err=%x!\n", err);
return err; return err;
} }
pipe->status = PCXHR_PIPE_DEFINED; pipe->status = PCXHR_PIPE_DEFINED;
...@@ -199,10 +231,12 @@ static int pcxhr_dsp_free_pipe( struct pcxhr_mgr *mgr, struct pcxhr_pipe *pipe) ...@@ -199,10 +231,12 @@ static int pcxhr_dsp_free_pipe( struct pcxhr_mgr *mgr, struct pcxhr_pipe *pipe)
snd_printk(KERN_ERR "error stopping pipe!\n"); snd_printk(KERN_ERR "error stopping pipe!\n");
/* release the pipe */ /* release the pipe */
pcxhr_init_rmh(&rmh, CMD_FREE_PIPE); pcxhr_init_rmh(&rmh, CMD_FREE_PIPE);
pcxhr_set_pipe_cmd_params(&rmh, pipe->is_capture, pipe->first_audio, 0, 0); pcxhr_set_pipe_cmd_params(&rmh, pipe->is_capture, pipe->first_audio,
0, 0);
err = pcxhr_send_msg(mgr, &rmh); err = pcxhr_send_msg(mgr, &rmh);
if (err < 0) if (err < 0)
snd_printk(KERN_ERR "error pipe release (CMD_FREE_PIPE) err(%x)\n", err); snd_printk(KERN_ERR "error pipe release "
"(CMD_FREE_PIPE) err(%x)\n", err);
pipe->status = PCXHR_PIPE_UNDEFINED; pipe->status = PCXHR_PIPE_UNDEFINED;
return err; return err;
} }
...@@ -248,15 +282,16 @@ static int pcxhr_start_pipes(struct pcxhr_mgr *mgr) ...@@ -248,15 +282,16 @@ static int pcxhr_start_pipes(struct pcxhr_mgr *mgr)
for (i = 0; i < mgr->num_cards; i++) { for (i = 0; i < mgr->num_cards; i++) {
chip = mgr->chip[i]; chip = mgr->chip[i];
if (chip->nb_streams_play) if (chip->nb_streams_play)
playback_mask |= (1 << chip->playback_pipe.first_audio); playback_mask |= 1 << chip->playback_pipe.first_audio;
for (j = 0; j < chip->nb_streams_capt; j++) for (j = 0; j < chip->nb_streams_capt; j++)
capture_mask |= (1 << chip->capture_pipe[j].first_audio); capture_mask |= 1 << chip->capture_pipe[j].first_audio;
} }
return pcxhr_set_pipe_state(mgr, playback_mask, capture_mask, 1); return pcxhr_set_pipe_state(mgr, playback_mask, capture_mask, 1);
} }
static int pcxhr_dsp_load(struct pcxhr_mgr *mgr, int index, const struct firmware *dsp) static int pcxhr_dsp_load(struct pcxhr_mgr *mgr, int index,
const struct firmware *dsp)
{ {
int err, card_index; int err, card_index;
...@@ -330,22 +365,33 @@ static int pcxhr_dsp_load(struct pcxhr_mgr *mgr, int index, const struct firmwar ...@@ -330,22 +365,33 @@ static int pcxhr_dsp_load(struct pcxhr_mgr *mgr, int index, const struct firmwar
int pcxhr_setup_firmware(struct pcxhr_mgr *mgr) int pcxhr_setup_firmware(struct pcxhr_mgr *mgr)
{ {
static char *fw_files[5] = { static char *fw_files[][5] = {
"xi_1_882.dat", [0] = { "xi_1_882.dat", "xc_1_882.dat",
"xc_1_882.dat", "e321_512.e56", "b321_512.b56", "d321_512.d56" },
"e321_512.e56", [1] = { "xi_1_882.dat", "xc_882e.dat",
"b321_512.b56", "e321_512.e56", "b882e.b56", "d321_512.d56" },
"d321_512.d56" [2] = { "xi_1_882.dat", "xc_1222.dat",
"e321_512.e56", "b1222.b56", "d1222.d56" },
[3] = { "xi_1_882.dat", "xc_1222e.dat",
"e321_512.e56", "b1222e.b56", "d1222.d56" },
[4] = { NULL, "x1_222hr.dat",
"e924.e56", "b924.b56", "l_1_222.d56" },
[5] = { NULL, "x1_924hr.dat",
"e924.e56", "b924.b56", "l_1_222.d56" },
}; };
char path[32]; char path[32];
const struct firmware *fw_entry; const struct firmware *fw_entry;
int i, err; int i, err;
int fw_set = mgr->fw_file_set;
for (i = 0; i < ARRAY_SIZE(fw_files); i++) { for (i = 0; i < 5; i++) {
sprintf(path, "pcxhr/%s", fw_files[i]); if (!fw_files[fw_set][i])
continue;
sprintf(path, "pcxhr/%s", fw_files[fw_set][i]);
if (request_firmware(&fw_entry, path, &mgr->pci->dev)) { if (request_firmware(&fw_entry, path, &mgr->pci->dev)) {
snd_printk(KERN_ERR "pcxhr: can't load firmware %s\n", path); snd_printk(KERN_ERR "pcxhr: can't load firmware %s\n",
path);
return -ENOENT; return -ENOENT;
} }
/* fake hwdep dsp record */ /* fake hwdep dsp record */
...@@ -360,10 +406,25 @@ int pcxhr_setup_firmware(struct pcxhr_mgr *mgr) ...@@ -360,10 +406,25 @@ int pcxhr_setup_firmware(struct pcxhr_mgr *mgr)
MODULE_FIRMWARE("pcxhr/xi_1_882.dat"); MODULE_FIRMWARE("pcxhr/xi_1_882.dat");
MODULE_FIRMWARE("pcxhr/xc_1_882.dat"); MODULE_FIRMWARE("pcxhr/xc_1_882.dat");
MODULE_FIRMWARE("pcxhr/xc_882e.dat");
MODULE_FIRMWARE("pcxhr/e321_512.e56"); MODULE_FIRMWARE("pcxhr/e321_512.e56");
MODULE_FIRMWARE("pcxhr/b321_512.b56"); MODULE_FIRMWARE("pcxhr/b321_512.b56");
MODULE_FIRMWARE("pcxhr/b882e.b56");
MODULE_FIRMWARE("pcxhr/d321_512.d56"); MODULE_FIRMWARE("pcxhr/d321_512.d56");
MODULE_FIRMWARE("pcxhr/xc_1222.dat");
MODULE_FIRMWARE("pcxhr/xc_1222e.dat");
MODULE_FIRMWARE("pcxhr/b1222.b56");
MODULE_FIRMWARE("pcxhr/b1222e.b56");
MODULE_FIRMWARE("pcxhr/d1222.d56");
MODULE_FIRMWARE("pcxhr/x1_222hr.dat");
MODULE_FIRMWARE("pcxhr/x1_924hr.dat");
MODULE_FIRMWARE("pcxhr/e924.e56");
MODULE_FIRMWARE("pcxhr/b924.b56");
MODULE_FIRMWARE("pcxhr/l_1_222.d56");
#else /* old style firmware loading */ #else /* old style firmware loading */
/* pcxhr hwdep interface id string */ /* pcxhr hwdep interface id string */
...@@ -373,7 +434,8 @@ MODULE_FIRMWARE("pcxhr/d321_512.d56"); ...@@ -373,7 +434,8 @@ MODULE_FIRMWARE("pcxhr/d321_512.d56");
static int pcxhr_hwdep_dsp_status(struct snd_hwdep *hw, static int pcxhr_hwdep_dsp_status(struct snd_hwdep *hw,
struct snd_hwdep_dsp_status *info) struct snd_hwdep_dsp_status *info)
{ {
strcpy(info->id, "pcxhr"); struct pcxhr_mgr *mgr = hw->private_data;
sprintf(info->id, "pcxhr%d", mgr->fw_file_set);
info->num_dsps = PCXHR_FIRMWARE_FILES_MAX_INDEX; info->num_dsps = PCXHR_FIRMWARE_FILES_MAX_INDEX;
if (hw->dsp_loaded & (1 << PCXHR_FIRMWARE_DSP_MAIN_INDEX)) if (hw->dsp_loaded & (1 << PCXHR_FIRMWARE_DSP_MAIN_INDEX))
...@@ -393,8 +455,8 @@ static int pcxhr_hwdep_dsp_load(struct snd_hwdep *hw, ...@@ -393,8 +455,8 @@ static int pcxhr_hwdep_dsp_load(struct snd_hwdep *hw,
fw.size = dsp->length; fw.size = dsp->length;
fw.data = vmalloc(fw.size); fw.data = vmalloc(fw.size);
if (! fw.data) { if (! fw.data) {
snd_printk(KERN_ERR "pcxhr: cannot allocate dsp image (%lu bytes)\n", snd_printk(KERN_ERR "pcxhr: cannot allocate dsp image "
(unsigned long)fw.size); "(%lu bytes)\n", (unsigned long)fw.size);
return -ENOMEM; return -ENOMEM;
} }
if (copy_from_user((void *)fw.data, dsp->image, dsp->length)) { if (copy_from_user((void *)fw.data, dsp->image, dsp->length)) {
...@@ -424,8 +486,11 @@ int pcxhr_setup_firmware(struct pcxhr_mgr *mgr) ...@@ -424,8 +486,11 @@ int pcxhr_setup_firmware(struct pcxhr_mgr *mgr)
int err; int err;
struct snd_hwdep *hw; struct snd_hwdep *hw;
/* only create hwdep interface for first cardX (see "index" module parameter)*/ /* only create hwdep interface for first cardX
if ((err = snd_hwdep_new(mgr->chip[0]->card, PCXHR_HWDEP_ID, 0, &hw)) < 0) * (see "index" module parameter)
*/
err = snd_hwdep_new(mgr->chip[0]->card, PCXHR_HWDEP_ID, 0, &hw);
if (err < 0)
return err; return err;
hw->iface = SNDRV_HWDEP_IFACE_PCXHR; hw->iface = SNDRV_HWDEP_IFACE_PCXHR;
...@@ -435,10 +500,13 @@ int pcxhr_setup_firmware(struct pcxhr_mgr *mgr) ...@@ -435,10 +500,13 @@ int pcxhr_setup_firmware(struct pcxhr_mgr *mgr)
hw->ops.dsp_status = pcxhr_hwdep_dsp_status; hw->ops.dsp_status = pcxhr_hwdep_dsp_status;
hw->ops.dsp_load = pcxhr_hwdep_dsp_load; hw->ops.dsp_load = pcxhr_hwdep_dsp_load;
hw->exclusive = 1; hw->exclusive = 1;
/* stereo cards don't need fw_file_0 -> dsp_loaded = 1 */
hw->dsp_loaded = mgr->is_hr_stereo ? 1 : 0;
mgr->dsp_loaded = 0; mgr->dsp_loaded = 0;
sprintf(hw->name, PCXHR_HWDEP_ID); sprintf(hw->name, PCXHR_HWDEP_ID);
if ((err = snd_card_register(mgr->chip[0]->card)) < 0) err = snd_card_register(mgr->chip[0]->card);
if (err < 0)
return err; return err;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment