pcxhr_hwdep.c 11 KB

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