123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405 |
- #include <linux/interrupt.h>
- #include <linux/vmalloc.h>
- #include <linux/firmware.h>
- #include <linux/pci.h>
- #include <linux/module.h>
- #include <linux/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"
- #include "pcxhr_mix22.h"
- static int pcxhr_sub_init(struct pcxhr_mgr *mgr);
- static int pcxhr_init_board(struct pcxhr_mgr *mgr)
- {
- int err;
- struct pcxhr_rmh rmh;
- int card_streams;
-
- if (mgr->mono_capture)
- card_streams = mgr->capture_chips * 2;
- else
- card_streams = mgr->capture_chips;
- card_streams += mgr->playback_chips * PCXHR_PLAYBACK_STREAMS;
-
- pcxhr_enable_dsp(mgr);
- pcxhr_init_rmh(&rmh, CMD_SUPPORTED);
- err = pcxhr_send_msg(mgr, &rmh);
- if (err)
- return err;
-
- if ((rmh.stat[0] & MASK_FIRST_FIELD) < mgr->playback_chips * 2)
- return -EINVAL;
-
- if (((rmh.stat[0] >> (2 * FIELD_SIZE)) & MASK_FIRST_FIELD) <
- mgr->capture_chips * 2)
- return -EINVAL;
-
- if ((rmh.stat[1] & 0x5F) < card_streams)
- return -EINVAL;
-
- if (((rmh.stat[1] >> 7) & 0x5F) < PCXHR_PLAYBACK_STREAMS)
- return -EINVAL;
- dev_dbg(&mgr->pci->dev,
- "supported formats : playback=%x capture=%x\n",
- rmh.stat[2], rmh.stat[3]);
- pcxhr_init_rmh(&rmh, CMD_VERSION);
-
- rmh.cmd[0] |= mgr->firmware_num;
-
- rmh.cmd[1] = (1<<23) + mgr->granularity;
- rmh.cmd_len = 2;
- err = pcxhr_send_msg(mgr, &rmh);
- if (err)
- return err;
- dev_dbg(&mgr->pci->dev,
- "PCXHR DSP version is %d.%d.%d\n", (rmh.stat[0]>>16)&0xff,
- (rmh.stat[0]>>8)&0xff, rmh.stat[0]&0xff);
- 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;
-
- 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;
- if ((rmh.stat[1] & REG_STATUS_OPT_DAUGHTER_MASK) ==
- REG_STATUS_OPT_ANALOG_BOARD)
- mgr->board_has_analog = 1;
-
- err = pcxhr_write_io_num_reg_cont(mgr, REG_CONT_UNMUTE_INPUTS,
- REG_CONT_UNMUTE_INPUTS, NULL);
- if (err)
- return err;
-
- pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_READ);
- rmh.cmd[0] |= IO_NUM_REG_MUTE_OUT;
- if (DSP_EXT_CMD_SET(mgr)) {
- rmh.cmd[1] = 1;
- rmh.cmd_len = 2;
- }
- 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)) {
-
- if (!mgr->is_hr_stereo) {
-
- pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE);
- rmh.cmd[0] |= IO_NUM_REG_MUTE_OUT;
- pcxhr_send_msg(mgr, &rmh);
-
- pcxhr_write_io_num_reg_cont(mgr, REG_CONT_UNMUTE_INPUTS,
- 0, NULL);
- }
-
- }
-
- if (mgr->dsp_loaded & (1 << PCXHR_FIRMWARE_DSP_EPRM_INDEX))
- pcxhr_reset_dsp(mgr);
-
- if (mgr->dsp_loaded & (1 << PCXHR_FIRMWARE_XLX_COM_INDEX)) {
- pcxhr_reset_xilinx_com(mgr);
- mgr->dsp_loaded = 1;
- }
- return;
- }
- static int pcxhr_dsp_allocate_pipe(struct pcxhr_mgr *mgr,
- struct pcxhr_pipe *pipe,
- int is_capture, int pin)
- {
- 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;
- }
- dev_dbg(&mgr->pci->dev, "snd_add_ref_pipe pin(%d) pcm%c0\n",
- pin, is_capture ? 'c' : 'p');
- pipe->is_capture = is_capture;
- pipe->first_audio = pin;
-
- pcxhr_init_rmh(&rmh, CMD_RES_PIPE);
- pcxhr_set_pipe_cmd_params(&rmh, is_capture, pin,
- audio_count, stream_count);
- rmh.cmd[1] |= 0x020000;
- if (DSP_EXT_CMD_SET(mgr)) {
-
- rmh.cmd[rmh.cmd_len++] = (audio_count == 1) ? 0x01 : 0x03;
- }
- err = pcxhr_send_msg(mgr, &rmh);
- if (err < 0) {
- dev_err(&mgr->pci->dev, "error pipe allocation "
- "(CMD_RES_PIPE) err=%x!\n", err);
- return err;
- }
- pipe->status = PCXHR_PIPE_DEFINED;
- return 0;
- }
- #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);
-
- err = pcxhr_set_pipe_state(mgr, playback_mask, capture_mask, 0);
- if (err < 0)
- dev_err(&mgr->pci->dev, "error stopping pipe!\n");
-
- pcxhr_init_rmh(&rmh, CMD_FREE_PIPE);
- pcxhr_set_pipe_cmd_params(&rmh, pipe->is_capture, pipe->first_audio,
- 0, 0);
- err = pcxhr_send_msg(mgr, &rmh);
- if (err < 0)
- dev_err(&mgr->pci->dev, "error pipe release "
- "(CMD_FREE_PIPE) err(%x)\n", err);
- 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;
-
- 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;
-
- for (i = 0; i < mgr->num_cards; i++) {
- chip = mgr->chip[i];
- if (chip->nb_streams_play)
- playback_mask |= 1 << chip->playback_pipe.first_audio;
- for (j = 0; j < chip->nb_streams_capt; j++)
- capture_mask |= 1 << chip->capture_pipe[j].first_audio;
- }
- 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)
- {
- int err, card_index;
- dev_dbg(&mgr->pci->dev,
- "loading dsp [%d] size = %Zd\n", 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;
- default:
- dev_err(&mgr->pci->dev, "wrong file index\n");
- return -EFAULT;
- }
-
- err = pcxhr_init_board(mgr);
- if (err < 0) {
- dev_err(&mgr->pci->dev, "pcxhr could not be set up\n");
- return err;
- }
- err = pcxhr_config_pipes(mgr);
- if (err < 0) {
- dev_err(&mgr->pci->dev, "pcxhr pipes could not be set up\n");
- return err;
- }
-
- 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) {
- dev_err(&mgr->pci->dev, "pcxhr pipes could not be started\n");
- return err;
- }
- dev_dbg(&mgr->pci->dev,
- "pcxhr firmware downloaded and successfully set up\n");
- return 0;
- }
- int pcxhr_setup_firmware(struct pcxhr_mgr *mgr)
- {
- static char *fw_files[][5] = {
- [0] = { "/*(DEBLOBBED)*/", "/*(DEBLOBBED)*/",
- "/*(DEBLOBBED)*/", "/*(DEBLOBBED)*/", "/*(DEBLOBBED)*/" },
- [1] = { "/*(DEBLOBBED)*/", "/*(DEBLOBBED)*/",
- "/*(DEBLOBBED)*/", "/*(DEBLOBBED)*/", "/*(DEBLOBBED)*/" },
- [2] = { "/*(DEBLOBBED)*/", "/*(DEBLOBBED)*/",
- "/*(DEBLOBBED)*/", "/*(DEBLOBBED)*/", "/*(DEBLOBBED)*/" },
- [3] = { "/*(DEBLOBBED)*/", "/*(DEBLOBBED)*/",
- "/*(DEBLOBBED)*/", "/*(DEBLOBBED)*/", "/*(DEBLOBBED)*/" },
- [4] = { NULL, "/*(DEBLOBBED)*/",
- "/*(DEBLOBBED)*/", "/*(DEBLOBBED)*/", "/*(DEBLOBBED)*/" },
- [5] = { NULL, "/*(DEBLOBBED)*/",
- "/*(DEBLOBBED)*/", "/*(DEBLOBBED)*/", "/*(DEBLOBBED)*/" },
- };
- char path[32];
- const struct firmware *fw_entry;
- int i, err;
- int fw_set = mgr->fw_file_set;
- for (i = 0; i < 5; i++) {
- if (!fw_files[fw_set][i])
- continue;
- sprintf(path, "/*(DEBLOBBED)*/", fw_files[fw_set][i]);
- if (reject_firmware(&fw_entry, path, &mgr->pci->dev)) {
- dev_err(&mgr->pci->dev,
- "pcxhr: can't load firmware %s\n",
- path);
- return -ENOENT;
- }
-
- err = pcxhr_dsp_load(mgr, i, fw_entry);
- release_firmware(fw_entry);
- if (err < 0)
- return err;
- mgr->dsp_loaded |= 1 << i;
- }
- return 0;
- }
|