pcxhr_hwdep.c 11 KB

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