mixart_hwdep.c 19 KB

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