mixart_hwdep.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  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 <sound/driver.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/pci.h>
  25. #include <linux/firmware.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. snd_assert(phys_io.nb_uid >= (MIXART_MAX_CARDS * 2), return -EINVAL); /* min 2 phys io per card (analog in + analog out) */
  247. for(k=0; k<mgr->num_cards; k++) {
  248. mgr->chip[k]->uid_in_analog_physio = phys_io.uid[k];
  249. mgr->chip[k]->uid_out_analog_physio = phys_io.uid[phys_io.nb_uid/2 + k];
  250. }
  251. return 0;
  252. }
  253. static int mixart_first_init(struct mixart_mgr *mgr)
  254. {
  255. u32 k;
  256. int err;
  257. struct mixart_msg request;
  258. if((err = mixart_enum_connectors(mgr)) < 0) return err;
  259. if((err = mixart_enum_physio(mgr)) < 0) return err;
  260. /* send a synchro command to card (necessary to do this before first MSG_STREAM_START_STREAM_GRP_PACKET) */
  261. /* though why not here */
  262. request.message_id = MSG_SYSTEM_SEND_SYNCHRO_CMD;
  263. request.uid = (struct mixart_uid){0,0};
  264. request.data = NULL;
  265. request.size = 0;
  266. /* this command has no data. response is a 32 bit status */
  267. err = snd_mixart_send_msg(mgr, &request, sizeof(k), &k);
  268. if( (err < 0) || (k != 0) ) {
  269. snd_printk(KERN_ERR "error MSG_SYSTEM_SEND_SYNCHRO_CMD\n");
  270. return err == 0 ? -EINVAL : err;
  271. }
  272. return 0;
  273. }
  274. /* firmware base addresses (when hard coded) */
  275. #define MIXART_MOTHERBOARD_XLX_BASE_ADDRESS 0x00600000
  276. static int mixart_dsp_load(struct mixart_mgr* mgr, int index, const struct firmware *dsp)
  277. {
  278. int err, card_index;
  279. u32 status_xilinx, status_elf, status_daught;
  280. u32 val;
  281. /* read motherboard xilinx status */
  282. status_xilinx = readl_be( MIXART_MEM( mgr,MIXART_PSEUDOREG_MXLX_STATUS_OFFSET ));
  283. /* read elf status */
  284. status_elf = readl_be( MIXART_MEM( mgr,MIXART_PSEUDOREG_ELF_STATUS_OFFSET ));
  285. /* read daughterboard xilinx status */
  286. status_daught = readl_be( MIXART_MEM( mgr,MIXART_PSEUDOREG_DXLX_STATUS_OFFSET ));
  287. /* motherboard xilinx status 5 will say that the board is performing a reset */
  288. if( status_xilinx == 5 ) {
  289. snd_printk( KERN_ERR "miXart is resetting !\n");
  290. return -EAGAIN; /* try again later */
  291. }
  292. switch (index) {
  293. case MIXART_MOTHERBOARD_XLX_INDEX:
  294. /* xilinx already loaded ? */
  295. if( status_xilinx == 4 ) {
  296. snd_printk( KERN_DEBUG "xilinx is already loaded !\n");
  297. return 0;
  298. }
  299. /* the status should be 0 == "idle" */
  300. if( status_xilinx != 0 ) {
  301. snd_printk( KERN_ERR "xilinx load error ! status = %d\n", status_xilinx);
  302. return -EIO; /* modprob -r may help ? */
  303. }
  304. /* check xilinx validity */
  305. snd_assert(((u32*)(dsp->data))[0]==0xFFFFFFFF, return -EINVAL);
  306. snd_assert(dsp->size % 4 == 0, return -EINVAL);
  307. /* set xilinx status to copying */
  308. writel_be( 1, MIXART_MEM( mgr, MIXART_PSEUDOREG_MXLX_STATUS_OFFSET ));
  309. /* setup xilinx base address */
  310. writel_be( MIXART_MOTHERBOARD_XLX_BASE_ADDRESS, MIXART_MEM( mgr,MIXART_PSEUDOREG_MXLX_BASE_ADDR_OFFSET ));
  311. /* setup code size for xilinx file */
  312. writel_be( dsp->size, MIXART_MEM( mgr, MIXART_PSEUDOREG_MXLX_SIZE_OFFSET ));
  313. /* copy xilinx code */
  314. memcpy_toio( MIXART_MEM( mgr, MIXART_MOTHERBOARD_XLX_BASE_ADDRESS), dsp->data, dsp->size);
  315. /* set xilinx status to copy finished */
  316. writel_be( 2, MIXART_MEM( mgr, MIXART_PSEUDOREG_MXLX_STATUS_OFFSET ));
  317. /* return, because no further processing needed */
  318. return 0;
  319. case MIXART_MOTHERBOARD_ELF_INDEX:
  320. if( status_elf == 4 ) {
  321. snd_printk( KERN_DEBUG "elf file already loaded !\n");
  322. return 0;
  323. }
  324. /* the status should be 0 == "idle" */
  325. if( status_elf != 0 ) {
  326. snd_printk( KERN_ERR "elf load error ! status = %d\n", status_elf);
  327. return -EIO; /* modprob -r may help ? */
  328. }
  329. /* wait for xilinx status == 4 */
  330. err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_MXLX_STATUS_OFFSET, 1, 4, 500); /* 5sec */
  331. if (err < 0) {
  332. snd_printk( KERN_ERR "xilinx was not loaded or could not be started\n");
  333. return err;
  334. }
  335. /* init some data on the card */
  336. writel_be( 0, MIXART_MEM( mgr, MIXART_PSEUDOREG_BOARDNUMBER ) ); /* set miXart boardnumber to 0 */
  337. writel_be( 0, MIXART_MEM( mgr, MIXART_FLOWTABLE_PTR ) ); /* reset pointer to flow table on miXart */
  338. /* set elf status to copying */
  339. writel_be( 1, MIXART_MEM( mgr, MIXART_PSEUDOREG_ELF_STATUS_OFFSET ));
  340. /* process the copying of the elf packets */
  341. err = mixart_load_elf( mgr, dsp );
  342. if (err < 0) return err;
  343. /* set elf status to copy finished */
  344. writel_be( 2, MIXART_MEM( mgr, MIXART_PSEUDOREG_ELF_STATUS_OFFSET ));
  345. /* wait for elf status == 4 */
  346. err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_ELF_STATUS_OFFSET, 1, 4, 300); /* 3sec */
  347. if (err < 0) {
  348. snd_printk( KERN_ERR "elf could not be started\n");
  349. return err;
  350. }
  351. /* miXart waits at this point on the pointer to the flow table */
  352. writel_be( (u32)mgr->flowinfo.addr, MIXART_MEM( mgr, MIXART_FLOWTABLE_PTR ) ); /* give pointer of flow table to miXart */
  353. return 0; /* return, another xilinx file has to be loaded before */
  354. case MIXART_AESEBUBOARD_XLX_INDEX:
  355. default:
  356. /* elf and xilinx should be loaded */
  357. if( (status_elf != 4) || (status_xilinx != 4) ) {
  358. printk( KERN_ERR "xilinx or elf not successfully loaded\n");
  359. return -EIO; /* modprob -r may help ? */
  360. }
  361. /* wait for daughter detection != 0 */
  362. err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_DBRD_PRESENCE_OFFSET, 0, 0, 30); /* 300msec */
  363. if (err < 0) {
  364. snd_printk( KERN_ERR "error starting elf file\n");
  365. return err;
  366. }
  367. /* the board type can now be retrieved */
  368. mgr->board_type = (DAUGHTER_TYPE_MASK & readl_be( MIXART_MEM( mgr, MIXART_PSEUDOREG_DBRD_TYPE_OFFSET)));
  369. if (mgr->board_type == MIXART_DAUGHTER_TYPE_NONE)
  370. break; /* no daughter board; the file does not have to be loaded, continue after the switch */
  371. /* only if aesebu daughter board presence (elf code must run) */
  372. if (mgr->board_type != MIXART_DAUGHTER_TYPE_AES )
  373. return -EINVAL;
  374. /* daughter should be idle */
  375. if( status_daught != 0 ) {
  376. printk( KERN_ERR "daughter load error ! status = %d\n", status_daught);
  377. return -EIO; /* modprob -r may help ? */
  378. }
  379. /* check daughterboard xilinx validity */
  380. snd_assert(((u32*)(dsp->data))[0]==0xFFFFFFFF, return -EINVAL);
  381. snd_assert(dsp->size % 4 == 0, return -EINVAL);
  382. /* inform mixart about the size of the file */
  383. writel_be( dsp->size, MIXART_MEM( mgr, MIXART_PSEUDOREG_DXLX_SIZE_OFFSET ));
  384. /* set daughterboard status to 1 */
  385. writel_be( 1, MIXART_MEM( mgr, MIXART_PSEUDOREG_DXLX_STATUS_OFFSET ));
  386. /* wait for status == 2 */
  387. err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_DXLX_STATUS_OFFSET, 1, 2, 30); /* 300msec */
  388. if (err < 0) {
  389. snd_printk( KERN_ERR "daughter board load error\n");
  390. return err;
  391. }
  392. /* get the address where to write the file */
  393. val = readl_be( MIXART_MEM( mgr, MIXART_PSEUDOREG_DXLX_BASE_ADDR_OFFSET ));
  394. snd_assert(val != 0, return -EINVAL);
  395. /* copy daughterboard xilinx code */
  396. memcpy_toio( MIXART_MEM( mgr, val), dsp->data, dsp->size);
  397. /* set daughterboard status to 4 */
  398. writel_be( 4, MIXART_MEM( mgr, MIXART_PSEUDOREG_DXLX_STATUS_OFFSET ));
  399. /* continue with init */
  400. break;
  401. } /* end of switch file index*/
  402. /* wait for daughter status == 3 */
  403. err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_DXLX_STATUS_OFFSET, 1, 3, 300); /* 3sec */
  404. if (err < 0) {
  405. snd_printk( KERN_ERR "daughter board could not be initialised\n");
  406. return err;
  407. }
  408. /* init mailbox (communication with embedded) */
  409. snd_mixart_init_mailbox(mgr);
  410. /* first communication with embedded */
  411. err = mixart_first_init(mgr);
  412. if (err < 0) {
  413. snd_printk( KERN_ERR "miXart could not be set up\n");
  414. return err;
  415. }
  416. /* create devices and mixer in accordance with HW options*/
  417. for (card_index = 0; card_index < mgr->num_cards; card_index++) {
  418. struct snd_mixart *chip = mgr->chip[card_index];
  419. if ((err = snd_mixart_create_pcm(chip)) < 0)
  420. return err;
  421. if (card_index == 0) {
  422. if ((err = snd_mixart_create_mixer(chip->mgr)) < 0)
  423. return err;
  424. }
  425. if ((err = snd_card_register(chip->card)) < 0)
  426. return err;
  427. };
  428. snd_printdd("miXart firmware downloaded and successfully set up\n");
  429. return 0;
  430. }
  431. #if defined(CONFIG_FW_LOADER) || defined(CONFIG_FW_LOADER_MODULE)
  432. #if !defined(CONFIG_USE_MIXARTLOADER) && !defined(CONFIG_SND_MIXART) /* built-in kernel */
  433. #define SND_MIXART_FW_LOADER /* use the standard firmware loader */
  434. #endif
  435. #endif
  436. #ifdef SND_MIXART_FW_LOADER
  437. int snd_mixart_setup_firmware(struct mixart_mgr *mgr)
  438. {
  439. static char *fw_files[3] = {
  440. "miXart8.xlx", "miXart8.elf", "miXart8AES.xlx"
  441. };
  442. char path[32];
  443. const struct firmware *fw_entry;
  444. int i, err;
  445. for (i = 0; i < 3; i++) {
  446. sprintf(path, "mixart/%s", fw_files[i]);
  447. if (request_firmware(&fw_entry, path, &mgr->pci->dev)) {
  448. snd_printk(KERN_ERR "miXart: can't load firmware %s\n", path);
  449. return -ENOENT;
  450. }
  451. /* fake hwdep dsp record */
  452. err = mixart_dsp_load(mgr, i, fw_entry);
  453. release_firmware(fw_entry);
  454. if (err < 0)
  455. return err;
  456. mgr->dsp_loaded |= 1 << i;
  457. }
  458. return 0;
  459. }
  460. #else /* old style firmware loading */
  461. /* miXart hwdep interface id string */
  462. #define SND_MIXART_HWDEP_ID "miXart Loader"
  463. static int mixart_hwdep_open(struct snd_hwdep *hw, struct file *file)
  464. {
  465. return 0;
  466. }
  467. static int mixart_hwdep_release(struct snd_hwdep *hw, struct file *file)
  468. {
  469. return 0;
  470. }
  471. static int mixart_hwdep_dsp_status(struct snd_hwdep *hw,
  472. struct snd_hwdep_dsp_status *info)
  473. {
  474. struct mixart_mgr *mgr = hw->private_data;
  475. strcpy(info->id, "miXart");
  476. info->num_dsps = MIXART_HARDW_FILES_MAX_INDEX;
  477. if (mgr->dsp_loaded & (1 << MIXART_MOTHERBOARD_ELF_INDEX))
  478. info->chip_ready = 1;
  479. info->version = MIXART_DRIVER_VERSION;
  480. return 0;
  481. }
  482. static int mixart_hwdep_dsp_load(struct snd_hwdep *hw,
  483. struct snd_hwdep_dsp_image *dsp)
  484. {
  485. struct mixart_mgr* mgr = hw->private_data;
  486. struct firmware fw;
  487. int err;
  488. fw.size = dsp->length;
  489. fw.data = vmalloc(dsp->length);
  490. if (! fw.data) {
  491. snd_printk(KERN_ERR "miXart: cannot allocate image size %d\n",
  492. (int)dsp->length);
  493. return -ENOMEM;
  494. }
  495. if (copy_from_user(fw.data, dsp->image, dsp->length)) {
  496. vfree(fw.data);
  497. return -EFAULT;
  498. }
  499. err = mixart_dsp_load(mgr, dsp->index, &fw);
  500. vfree(fw.data);
  501. if (err < 0)
  502. return err;
  503. mgr->dsp_loaded |= 1 << dsp->index;
  504. return err;
  505. }
  506. int snd_mixart_setup_firmware(struct mixart_mgr *mgr)
  507. {
  508. int err;
  509. struct snd_hwdep *hw;
  510. /* only create hwdep interface for first cardX (see "index" module parameter)*/
  511. if ((err = snd_hwdep_new(mgr->chip[0]->card, SND_MIXART_HWDEP_ID, 0, &hw)) < 0)
  512. return err;
  513. hw->iface = SNDRV_HWDEP_IFACE_MIXART;
  514. hw->private_data = mgr;
  515. hw->ops.open = mixart_hwdep_open;
  516. hw->ops.release = mixart_hwdep_release;
  517. hw->ops.dsp_status = mixart_hwdep_dsp_status;
  518. hw->ops.dsp_load = mixart_hwdep_dsp_load;
  519. hw->exclusive = 1;
  520. sprintf(hw->name, SND_MIXART_HWDEP_ID);
  521. mgr->dsp_loaded = 0;
  522. return snd_card_register(mgr->chip[0]->card);
  523. }
  524. #endif /* SND_MIXART_FW_LOADER */