mixart_hwdep.c 19 KB

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