mixart_hwdep.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. /*
  2. * Driver for Digigram miXart soundcards
  3. *
  4. * DSP firmware management
  5. *
  6. * Copyright (c) 2003 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/pci.h>
  24. #include <linux/firmware.h>
  25. #include <linux/vmalloc.h>
  26. #include <linux/slab.h>
  27. #include <linux/module.h>
  28. #include <asm/io.h>
  29. #include <sound/core.h>
  30. #include "mixart.h"
  31. #include "mixart_mixer.h"
  32. #include "mixart_core.h"
  33. #include "mixart_hwdep.h"
  34. /**
  35. * wait for a value on a peudo register, exit with a timeout
  36. *
  37. * @param mgr pointer to miXart manager structure
  38. * @param offset unsigned pseudo_register base + offset of value
  39. * @param value value
  40. * @param timeout timeout in centisenconds
  41. */
  42. static int mixart_wait_nice_for_register_value(struct mixart_mgr *mgr,
  43. u32 offset, int is_egal,
  44. u32 value, unsigned long timeout)
  45. {
  46. unsigned long end_time = jiffies + (timeout * HZ / 100);
  47. u32 read;
  48. do { /* we may take too long time in this loop.
  49. * so give controls back to kernel if needed.
  50. */
  51. cond_resched();
  52. read = readl_be( MIXART_MEM( mgr, offset ));
  53. if(is_egal) {
  54. if(read == value) return 0;
  55. }
  56. else { /* wait for different value */
  57. if(read != value) return 0;
  58. }
  59. } while ( time_after_eq(end_time, jiffies) );
  60. return -EBUSY;
  61. }
  62. /*
  63. structures needed to upload elf code packets
  64. */
  65. struct snd_mixart_elf32_ehdr {
  66. u8 e_ident[16];
  67. u16 e_type;
  68. u16 e_machine;
  69. u32 e_version;
  70. u32 e_entry;
  71. u32 e_phoff;
  72. u32 e_shoff;
  73. u32 e_flags;
  74. u16 e_ehsize;
  75. u16 e_phentsize;
  76. u16 e_phnum;
  77. u16 e_shentsize;
  78. u16 e_shnum;
  79. u16 e_shstrndx;
  80. };
  81. struct snd_mixart_elf32_phdr {
  82. u32 p_type;
  83. u32 p_offset;
  84. u32 p_vaddr;
  85. u32 p_paddr;
  86. u32 p_filesz;
  87. u32 p_memsz;
  88. u32 p_flags;
  89. u32 p_align;
  90. };
  91. static int mixart_load_elf(struct mixart_mgr *mgr, const struct firmware *dsp )
  92. {
  93. char elf32_magic_number[4] = {0x7f,'E','L','F'};
  94. struct snd_mixart_elf32_ehdr *elf_header;
  95. int i;
  96. elf_header = (struct snd_mixart_elf32_ehdr *)dsp->data;
  97. for( i=0; i<4; i++ )
  98. if ( elf32_magic_number[i] != elf_header->e_ident[i] )
  99. return -EINVAL;
  100. if( elf_header->e_phoff != 0 ) {
  101. struct snd_mixart_elf32_phdr elf_programheader;
  102. for( i=0; i < be16_to_cpu(elf_header->e_phnum); i++ ) {
  103. u32 pos = be32_to_cpu(elf_header->e_phoff) + (u32)(i * be16_to_cpu(elf_header->e_phentsize));
  104. memcpy( &elf_programheader, dsp->data + pos, sizeof(elf_programheader) );
  105. if(elf_programheader.p_type != 0) {
  106. if( elf_programheader.p_filesz != 0 ) {
  107. memcpy_toio( MIXART_MEM( mgr, be32_to_cpu(elf_programheader.p_vaddr)),
  108. dsp->data + be32_to_cpu( elf_programheader.p_offset ),
  109. be32_to_cpu( elf_programheader.p_filesz ));
  110. }
  111. }
  112. }
  113. }
  114. return 0;
  115. }
  116. /*
  117. * get basic information and init miXart
  118. */
  119. /* audio IDs for request to the board */
  120. #define MIXART_FIRST_ANA_AUDIO_ID 0
  121. #define MIXART_FIRST_DIG_AUDIO_ID 8
  122. static int mixart_enum_connectors(struct mixart_mgr *mgr)
  123. {
  124. u32 k;
  125. int err;
  126. struct mixart_msg request;
  127. struct mixart_enum_connector_resp *connector;
  128. struct mixart_audio_info_req *audio_info_req;
  129. struct mixart_audio_info_resp *audio_info;
  130. connector = kmalloc(sizeof(*connector), GFP_KERNEL);
  131. audio_info_req = kmalloc(sizeof(*audio_info_req), GFP_KERNEL);
  132. audio_info = kmalloc(sizeof(*audio_info), GFP_KERNEL);
  133. if (! connector || ! audio_info_req || ! audio_info) {
  134. err = -ENOMEM;
  135. goto __error;
  136. }
  137. audio_info_req->line_max_level = MIXART_FLOAT_P_22_0_TO_HEX;
  138. audio_info_req->micro_max_level = MIXART_FLOAT_M_20_0_TO_HEX;
  139. audio_info_req->cd_max_level = MIXART_FLOAT____0_0_TO_HEX;
  140. request.message_id = MSG_SYSTEM_ENUM_PLAY_CONNECTOR;
  141. request.uid = (struct mixart_uid){0,0}; /* board num = 0 */
  142. request.data = NULL;
  143. request.size = 0;
  144. err = snd_mixart_send_msg(mgr, &request, sizeof(*connector), connector);
  145. if((err < 0) || (connector->error_code) || (connector->uid_count > MIXART_MAX_PHYS_CONNECTORS)) {
  146. snd_printk(KERN_ERR "error MSG_SYSTEM_ENUM_PLAY_CONNECTOR\n");
  147. err = -EINVAL;
  148. goto __error;
  149. }
  150. for(k=0; k < connector->uid_count; k++) {
  151. struct mixart_pipe *pipe;
  152. if(k < MIXART_FIRST_DIG_AUDIO_ID) {
  153. pipe = &mgr->chip[k/2]->pipe_out_ana;
  154. } else {
  155. pipe = &mgr->chip[(k-MIXART_FIRST_DIG_AUDIO_ID)/2]->pipe_out_dig;
  156. }
  157. if(k & 1) {
  158. pipe->uid_right_connector = connector->uid[k]; /* odd */
  159. } else {
  160. pipe->uid_left_connector = connector->uid[k]; /* even */
  161. }
  162. /* snd_printk(KERN_DEBUG "playback connector[%d].object_id = %x\n", k, connector->uid[k].object_id); */
  163. /* TODO: really need send_msg MSG_CONNECTOR_GET_AUDIO_INFO for each connector ? perhaps for analog level caps ? */
  164. request.message_id = MSG_CONNECTOR_GET_AUDIO_INFO;
  165. request.uid = connector->uid[k];
  166. request.data = audio_info_req;
  167. request.size = sizeof(*audio_info_req);
  168. err = snd_mixart_send_msg(mgr, &request, sizeof(*audio_info), audio_info);
  169. if( err < 0 ) {
  170. snd_printk(KERN_ERR "error MSG_CONNECTOR_GET_AUDIO_INFO\n");
  171. goto __error;
  172. }
  173. /*snd_printk(KERN_DEBUG "play analog_info.analog_level_present = %x\n", audio_info->info.analog_info.analog_level_present);*/
  174. }
  175. request.message_id = MSG_SYSTEM_ENUM_RECORD_CONNECTOR;
  176. request.uid = (struct mixart_uid){0,0}; /* board num = 0 */
  177. request.data = NULL;
  178. request.size = 0;
  179. err = snd_mixart_send_msg(mgr, &request, sizeof(*connector), connector);
  180. if((err < 0) || (connector->error_code) || (connector->uid_count > MIXART_MAX_PHYS_CONNECTORS)) {
  181. snd_printk(KERN_ERR "error MSG_SYSTEM_ENUM_RECORD_CONNECTOR\n");
  182. err = -EINVAL;
  183. goto __error;
  184. }
  185. for(k=0; k < connector->uid_count; k++) {
  186. struct mixart_pipe *pipe;
  187. if(k < MIXART_FIRST_DIG_AUDIO_ID) {
  188. pipe = &mgr->chip[k/2]->pipe_in_ana;
  189. } else {
  190. pipe = &mgr->chip[(k-MIXART_FIRST_DIG_AUDIO_ID)/2]->pipe_in_dig;
  191. }
  192. if(k & 1) {
  193. pipe->uid_right_connector = connector->uid[k]; /* odd */
  194. } else {
  195. pipe->uid_left_connector = connector->uid[k]; /* even */
  196. }
  197. /* snd_printk(KERN_DEBUG "capture connector[%d].object_id = %x\n", k, connector->uid[k].object_id); */
  198. /* TODO: really need send_msg MSG_CONNECTOR_GET_AUDIO_INFO for each connector ? perhaps for analog level caps ? */
  199. request.message_id = MSG_CONNECTOR_GET_AUDIO_INFO;
  200. request.uid = connector->uid[k];
  201. request.data = audio_info_req;
  202. request.size = sizeof(*audio_info_req);
  203. err = snd_mixart_send_msg(mgr, &request, sizeof(*audio_info), audio_info);
  204. if( err < 0 ) {
  205. snd_printk(KERN_ERR "error MSG_CONNECTOR_GET_AUDIO_INFO\n");
  206. goto __error;
  207. }
  208. /*snd_printk(KERN_DEBUG "rec analog_info.analog_level_present = %x\n", audio_info->info.analog_info.analog_level_present);*/
  209. }
  210. err = 0;
  211. __error:
  212. kfree(connector);
  213. kfree(audio_info_req);
  214. kfree(audio_info);
  215. return err;
  216. }
  217. static int mixart_enum_physio(struct mixart_mgr *mgr)
  218. {
  219. u32 k;
  220. int err;
  221. struct mixart_msg request;
  222. struct mixart_uid get_console_mgr;
  223. struct mixart_return_uid console_mgr;
  224. struct mixart_uid_enumeration phys_io;
  225. /* get the uid for the console manager */
  226. get_console_mgr.object_id = 0;
  227. get_console_mgr.desc = MSG_CONSOLE_MANAGER | 0; /* cardindex = 0 */
  228. request.message_id = MSG_CONSOLE_GET_CLOCK_UID;
  229. request.uid = get_console_mgr;
  230. request.data = &get_console_mgr;
  231. request.size = sizeof(get_console_mgr);
  232. err = snd_mixart_send_msg(mgr, &request, sizeof(console_mgr), &console_mgr);
  233. if( (err < 0) || (console_mgr.error_code != 0) ) {
  234. snd_printk(KERN_DEBUG "error MSG_CONSOLE_GET_CLOCK_UID : err=%x\n", console_mgr.error_code);
  235. return -EINVAL;
  236. }
  237. /* used later for clock issues ! */
  238. mgr->uid_console_manager = console_mgr.uid;
  239. request.message_id = MSG_SYSTEM_ENUM_PHYSICAL_IO;
  240. request.uid = (struct mixart_uid){0,0};
  241. request.data = &console_mgr.uid;
  242. request.size = sizeof(console_mgr.uid);
  243. err = snd_mixart_send_msg(mgr, &request, sizeof(phys_io), &phys_io);
  244. if( (err < 0) || ( phys_io.error_code != 0 ) ) {
  245. snd_printk(KERN_ERR "error MSG_SYSTEM_ENUM_PHYSICAL_IO err(%x) error_code(%x)\n", err, phys_io.error_code );
  246. return -EINVAL;
  247. }
  248. /* min 2 phys io per card (analog in + analog out) */
  249. if (phys_io.nb_uid < MIXART_MAX_CARDS * 2)
  250. return -EINVAL;
  251. for(k=0; k<mgr->num_cards; k++) {
  252. mgr->chip[k]->uid_in_analog_physio = phys_io.uid[k];
  253. mgr->chip[k]->uid_out_analog_physio = phys_io.uid[phys_io.nb_uid/2 + k];
  254. }
  255. return 0;
  256. }
  257. static int mixart_first_init(struct mixart_mgr *mgr)
  258. {
  259. u32 k;
  260. int err;
  261. struct mixart_msg request;
  262. if((err = mixart_enum_connectors(mgr)) < 0) return err;
  263. if((err = mixart_enum_physio(mgr)) < 0) return err;
  264. /* send a synchro command to card (necessary to do this before first MSG_STREAM_START_STREAM_GRP_PACKET) */
  265. /* though why not here */
  266. request.message_id = MSG_SYSTEM_SEND_SYNCHRO_CMD;
  267. request.uid = (struct mixart_uid){0,0};
  268. request.data = NULL;
  269. request.size = 0;
  270. /* this command has no data. response is a 32 bit status */
  271. err = snd_mixart_send_msg(mgr, &request, sizeof(k), &k);
  272. if( (err < 0) || (k != 0) ) {
  273. snd_printk(KERN_ERR "error MSG_SYSTEM_SEND_SYNCHRO_CMD\n");
  274. return err == 0 ? -EINVAL : err;
  275. }
  276. return 0;
  277. }
  278. /* firmware base addresses (when hard coded) */
  279. #define MIXART_MOTHERBOARD_XLX_BASE_ADDRESS 0x00600000
  280. static int mixart_dsp_load(struct mixart_mgr* mgr, int index, const struct firmware *dsp)
  281. {
  282. int err, card_index;
  283. u32 status_xilinx, status_elf, status_daught;
  284. u32 val;
  285. /* read motherboard xilinx status */
  286. status_xilinx = readl_be( MIXART_MEM( mgr,MIXART_PSEUDOREG_MXLX_STATUS_OFFSET ));
  287. /* read elf status */
  288. status_elf = readl_be( MIXART_MEM( mgr,MIXART_PSEUDOREG_ELF_STATUS_OFFSET ));
  289. /* read daughterboard xilinx status */
  290. status_daught = readl_be( MIXART_MEM( mgr,MIXART_PSEUDOREG_DXLX_STATUS_OFFSET ));
  291. /* motherboard xilinx status 5 will say that the board is performing a reset */
  292. if (status_xilinx == 5) {
  293. snd_printk(KERN_ERR "miXart is resetting !\n");
  294. return -EAGAIN; /* try again later */
  295. }
  296. switch (index) {
  297. case MIXART_MOTHERBOARD_XLX_INDEX:
  298. /* xilinx already loaded ? */
  299. if (status_xilinx == 4) {
  300. snd_printk(KERN_DEBUG "xilinx is already loaded !\n");
  301. return 0;
  302. }
  303. /* the status should be 0 == "idle" */
  304. if (status_xilinx != 0) {
  305. snd_printk(KERN_ERR "xilinx load error ! status = %d\n",
  306. status_xilinx);
  307. return -EIO; /* modprob -r may help ? */
  308. }
  309. /* check xilinx validity */
  310. if (((u32*)(dsp->data))[0] == 0xffffffff)
  311. return -EINVAL;
  312. if (dsp->size % 4)
  313. return -EINVAL;
  314. /* set xilinx status to copying */
  315. writel_be( 1, MIXART_MEM( mgr, MIXART_PSEUDOREG_MXLX_STATUS_OFFSET ));
  316. /* setup xilinx base address */
  317. writel_be( MIXART_MOTHERBOARD_XLX_BASE_ADDRESS, MIXART_MEM( mgr,MIXART_PSEUDOREG_MXLX_BASE_ADDR_OFFSET ));
  318. /* setup code size for xilinx file */
  319. writel_be( dsp->size, MIXART_MEM( mgr, MIXART_PSEUDOREG_MXLX_SIZE_OFFSET ));
  320. /* copy xilinx code */
  321. memcpy_toio( MIXART_MEM( mgr, MIXART_MOTHERBOARD_XLX_BASE_ADDRESS), dsp->data, dsp->size);
  322. /* set xilinx status to copy finished */
  323. writel_be( 2, MIXART_MEM( mgr, MIXART_PSEUDOREG_MXLX_STATUS_OFFSET ));
  324. /* return, because no further processing needed */
  325. return 0;
  326. case MIXART_MOTHERBOARD_ELF_INDEX:
  327. if (status_elf == 4) {
  328. snd_printk(KERN_DEBUG "elf file already loaded !\n");
  329. return 0;
  330. }
  331. /* the status should be 0 == "idle" */
  332. if (status_elf != 0) {
  333. snd_printk(KERN_ERR "elf load error ! status = %d\n",
  334. status_elf);
  335. return -EIO; /* modprob -r may help ? */
  336. }
  337. /* wait for xilinx status == 4 */
  338. err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_MXLX_STATUS_OFFSET, 1, 4, 500); /* 5sec */
  339. if (err < 0) {
  340. snd_printk(KERN_ERR "xilinx was not loaded or "
  341. "could not be started\n");
  342. return err;
  343. }
  344. /* init some data on the card */
  345. writel_be( 0, MIXART_MEM( mgr, MIXART_PSEUDOREG_BOARDNUMBER ) ); /* set miXart boardnumber to 0 */
  346. writel_be( 0, MIXART_MEM( mgr, MIXART_FLOWTABLE_PTR ) ); /* reset pointer to flow table on miXart */
  347. /* set elf status to copying */
  348. writel_be( 1, MIXART_MEM( mgr, MIXART_PSEUDOREG_ELF_STATUS_OFFSET ));
  349. /* process the copying of the elf packets */
  350. err = mixart_load_elf( mgr, dsp );
  351. if (err < 0) return err;
  352. /* set elf status to copy finished */
  353. writel_be( 2, MIXART_MEM( mgr, MIXART_PSEUDOREG_ELF_STATUS_OFFSET ));
  354. /* wait for elf status == 4 */
  355. err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_ELF_STATUS_OFFSET, 1, 4, 300); /* 3sec */
  356. if (err < 0) {
  357. snd_printk(KERN_ERR "elf could not be started\n");
  358. return err;
  359. }
  360. /* miXart waits at this point on the pointer to the flow table */
  361. writel_be( (u32)mgr->flowinfo.addr, MIXART_MEM( mgr, MIXART_FLOWTABLE_PTR ) ); /* give pointer of flow table to miXart */
  362. return 0; /* return, another xilinx file has to be loaded before */
  363. case MIXART_AESEBUBOARD_XLX_INDEX:
  364. default:
  365. /* elf and xilinx should be loaded */
  366. if (status_elf != 4 || status_xilinx != 4) {
  367. printk(KERN_ERR "xilinx or elf not "
  368. "successfully loaded\n");
  369. return -EIO; /* modprob -r may help ? */
  370. }
  371. /* wait for daughter detection != 0 */
  372. err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_DBRD_PRESENCE_OFFSET, 0, 0, 30); /* 300msec */
  373. if (err < 0) {
  374. snd_printk(KERN_ERR "error starting elf file\n");
  375. return err;
  376. }
  377. /* the board type can now be retrieved */
  378. mgr->board_type = (DAUGHTER_TYPE_MASK & readl_be( MIXART_MEM( mgr, MIXART_PSEUDOREG_DBRD_TYPE_OFFSET)));
  379. if (mgr->board_type == MIXART_DAUGHTER_TYPE_NONE)
  380. break; /* no daughter board; the file does not have to be loaded, continue after the switch */
  381. /* only if aesebu daughter board presence (elf code must run) */
  382. if (mgr->board_type != MIXART_DAUGHTER_TYPE_AES )
  383. return -EINVAL;
  384. /* daughter should be idle */
  385. if (status_daught != 0) {
  386. printk(KERN_ERR "daughter load error ! status = %d\n",
  387. status_daught);
  388. return -EIO; /* modprob -r may help ? */
  389. }
  390. /* check daughterboard xilinx validity */
  391. if (((u32*)(dsp->data))[0] == 0xffffffff)
  392. return -EINVAL;
  393. if (dsp->size % 4)
  394. return -EINVAL;
  395. /* inform mixart about the size of the file */
  396. writel_be( dsp->size, MIXART_MEM( mgr, MIXART_PSEUDOREG_DXLX_SIZE_OFFSET ));
  397. /* set daughterboard status to 1 */
  398. writel_be( 1, MIXART_MEM( mgr, MIXART_PSEUDOREG_DXLX_STATUS_OFFSET ));
  399. /* wait for status == 2 */
  400. err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_DXLX_STATUS_OFFSET, 1, 2, 30); /* 300msec */
  401. if (err < 0) {
  402. snd_printk(KERN_ERR "daughter board load error\n");
  403. return err;
  404. }
  405. /* get the address where to write the file */
  406. val = readl_be( MIXART_MEM( mgr, MIXART_PSEUDOREG_DXLX_BASE_ADDR_OFFSET ));
  407. if (!val)
  408. return -EINVAL;
  409. /* copy daughterboard xilinx code */
  410. memcpy_toio( MIXART_MEM( mgr, val), dsp->data, dsp->size);
  411. /* set daughterboard status to 4 */
  412. writel_be( 4, MIXART_MEM( mgr, MIXART_PSEUDOREG_DXLX_STATUS_OFFSET ));
  413. /* continue with init */
  414. break;
  415. } /* end of switch file index*/
  416. /* wait for daughter status == 3 */
  417. err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_DXLX_STATUS_OFFSET, 1, 3, 300); /* 3sec */
  418. if (err < 0) {
  419. snd_printk(KERN_ERR
  420. "daughter board could not be initialised\n");
  421. return err;
  422. }
  423. /* init mailbox (communication with embedded) */
  424. snd_mixart_init_mailbox(mgr);
  425. /* first communication with embedded */
  426. err = mixart_first_init(mgr);
  427. if (err < 0) {
  428. snd_printk(KERN_ERR "miXart could not be set up\n");
  429. return err;
  430. }
  431. /* create devices and mixer in accordance with HW options*/
  432. for (card_index = 0; card_index < mgr->num_cards; card_index++) {
  433. struct snd_mixart *chip = mgr->chip[card_index];
  434. if ((err = snd_mixart_create_pcm(chip)) < 0)
  435. return err;
  436. if (card_index == 0) {
  437. if ((err = snd_mixart_create_mixer(chip->mgr)) < 0)
  438. return err;
  439. }
  440. if ((err = snd_card_register(chip->card)) < 0)
  441. return err;
  442. };
  443. snd_printdd("miXart firmware downloaded and successfully set up\n");
  444. return 0;
  445. }
  446. #if defined(CONFIG_FW_LOADER) || defined(CONFIG_FW_LOADER_MODULE)
  447. #if !defined(CONFIG_USE_MIXARTLOADER) && !defined(CONFIG_SND_MIXART) /* built-in kernel */
  448. #define SND_MIXART_FW_LOADER /* use the standard firmware loader */
  449. #endif
  450. #endif
  451. #ifdef SND_MIXART_FW_LOADER
  452. int snd_mixart_setup_firmware(struct mixart_mgr *mgr)
  453. {
  454. static char *fw_files[3] = {
  455. "miXart8.xlx", "miXart8.elf", "miXart8AES.xlx"
  456. };
  457. char path[32];
  458. const struct firmware *fw_entry;
  459. int i, err;
  460. for (i = 0; i < 3; i++) {
  461. sprintf(path, "mixart/%s", fw_files[i]);
  462. if (request_firmware(&fw_entry, path, &mgr->pci->dev)) {
  463. snd_printk(KERN_ERR "miXart: can't load firmware %s\n", path);
  464. return -ENOENT;
  465. }
  466. /* fake hwdep dsp record */
  467. err = mixart_dsp_load(mgr, i, fw_entry);
  468. release_firmware(fw_entry);
  469. if (err < 0)
  470. return err;
  471. mgr->dsp_loaded |= 1 << i;
  472. }
  473. return 0;
  474. }
  475. MODULE_FIRMWARE("mixart/miXart8.xlx");
  476. MODULE_FIRMWARE("mixart/miXart8.elf");
  477. MODULE_FIRMWARE("mixart/miXart8AES.xlx");
  478. #else /* old style firmware loading */
  479. /* miXart hwdep interface id string */
  480. #define SND_MIXART_HWDEP_ID "miXart Loader"
  481. static int mixart_hwdep_dsp_status(struct snd_hwdep *hw,
  482. struct snd_hwdep_dsp_status *info)
  483. {
  484. struct mixart_mgr *mgr = hw->private_data;
  485. strcpy(info->id, "miXart");
  486. info->num_dsps = MIXART_HARDW_FILES_MAX_INDEX;
  487. if (mgr->dsp_loaded & (1 << MIXART_MOTHERBOARD_ELF_INDEX))
  488. info->chip_ready = 1;
  489. info->version = MIXART_DRIVER_VERSION;
  490. return 0;
  491. }
  492. static int mixart_hwdep_dsp_load(struct snd_hwdep *hw,
  493. struct snd_hwdep_dsp_image *dsp)
  494. {
  495. struct mixart_mgr* mgr = hw->private_data;
  496. struct firmware fw;
  497. int err;
  498. fw.size = dsp->length;
  499. fw.data = vmalloc(dsp->length);
  500. if (! fw.data) {
  501. snd_printk(KERN_ERR "miXart: cannot allocate image size %d\n",
  502. (int)dsp->length);
  503. return -ENOMEM;
  504. }
  505. if (copy_from_user((void *) fw.data, dsp->image, dsp->length)) {
  506. vfree(fw.data);
  507. return -EFAULT;
  508. }
  509. err = mixart_dsp_load(mgr, dsp->index, &fw);
  510. vfree(fw.data);
  511. if (err < 0)
  512. return err;
  513. mgr->dsp_loaded |= 1 << dsp->index;
  514. return err;
  515. }
  516. int snd_mixart_setup_firmware(struct mixart_mgr *mgr)
  517. {
  518. int err;
  519. struct snd_hwdep *hw;
  520. /* only create hwdep interface for first cardX (see "index" module parameter)*/
  521. if ((err = snd_hwdep_new(mgr->chip[0]->card, SND_MIXART_HWDEP_ID, 0, &hw)) < 0)
  522. return err;
  523. hw->iface = SNDRV_HWDEP_IFACE_MIXART;
  524. hw->private_data = mgr;
  525. hw->ops.dsp_status = mixart_hwdep_dsp_status;
  526. hw->ops.dsp_load = mixart_hwdep_dsp_load;
  527. hw->exclusive = 1;
  528. sprintf(hw->name, SND_MIXART_HWDEP_ID);
  529. mgr->dsp_loaded = 0;
  530. return snd_card_register(mgr->chip[0]->card);
  531. }
  532. #endif /* SND_MIXART_FW_LOADER */