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 <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",
  304. status_xilinx);
  305. return -EIO; /* modprob -r may help ? */
  306. }
  307. /* check xilinx validity */
  308. if (((u32*)(dsp->data))[0] == 0xffffffff)
  309. return -EINVAL;
  310. if (dsp->size % 4)
  311. return -EINVAL;
  312. /* set xilinx status to copying */
  313. writel_be( 1, MIXART_MEM( mgr, MIXART_PSEUDOREG_MXLX_STATUS_OFFSET ));
  314. /* setup xilinx base address */
  315. writel_be( MIXART_MOTHERBOARD_XLX_BASE_ADDRESS, MIXART_MEM( mgr,MIXART_PSEUDOREG_MXLX_BASE_ADDR_OFFSET ));
  316. /* setup code size for xilinx file */
  317. writel_be( dsp->size, MIXART_MEM( mgr, MIXART_PSEUDOREG_MXLX_SIZE_OFFSET ));
  318. /* copy xilinx code */
  319. memcpy_toio( MIXART_MEM( mgr, MIXART_MOTHERBOARD_XLX_BASE_ADDRESS), dsp->data, dsp->size);
  320. /* set xilinx status to copy finished */
  321. writel_be( 2, MIXART_MEM( mgr, MIXART_PSEUDOREG_MXLX_STATUS_OFFSET ));
  322. /* return, because no further processing needed */
  323. return 0;
  324. case MIXART_MOTHERBOARD_ELF_INDEX:
  325. if (status_elf == 4) {
  326. snd_printk(KERN_DEBUG "elf file already loaded !\n");
  327. return 0;
  328. }
  329. /* the status should be 0 == "idle" */
  330. if (status_elf != 0) {
  331. snd_printk(KERN_ERR "elf load error ! status = %d\n",
  332. status_elf);
  333. return -EIO; /* modprob -r may help ? */
  334. }
  335. /* wait for xilinx status == 4 */
  336. err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_MXLX_STATUS_OFFSET, 1, 4, 500); /* 5sec */
  337. if (err < 0) {
  338. snd_printk(KERN_ERR "xilinx was not loaded or "
  339. "could not be started\n");
  340. return err;
  341. }
  342. /* init some data on the card */
  343. writel_be( 0, MIXART_MEM( mgr, MIXART_PSEUDOREG_BOARDNUMBER ) ); /* set miXart boardnumber to 0 */
  344. writel_be( 0, MIXART_MEM( mgr, MIXART_FLOWTABLE_PTR ) ); /* reset pointer to flow table on miXart */
  345. /* set elf status to copying */
  346. writel_be( 1, MIXART_MEM( mgr, MIXART_PSEUDOREG_ELF_STATUS_OFFSET ));
  347. /* process the copying of the elf packets */
  348. err = mixart_load_elf( mgr, dsp );
  349. if (err < 0) return err;
  350. /* set elf status to copy finished */
  351. writel_be( 2, MIXART_MEM( mgr, MIXART_PSEUDOREG_ELF_STATUS_OFFSET ));
  352. /* wait for elf status == 4 */
  353. err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_ELF_STATUS_OFFSET, 1, 4, 300); /* 3sec */
  354. if (err < 0) {
  355. snd_printk(KERN_ERR "elf could not be started\n");
  356. return err;
  357. }
  358. /* miXart waits at this point on the pointer to the flow table */
  359. writel_be( (u32)mgr->flowinfo.addr, MIXART_MEM( mgr, MIXART_FLOWTABLE_PTR ) ); /* give pointer of flow table to miXart */
  360. return 0; /* return, another xilinx file has to be loaded before */
  361. case MIXART_AESEBUBOARD_XLX_INDEX:
  362. default:
  363. /* elf and xilinx should be loaded */
  364. if (status_elf != 4 || status_xilinx != 4) {
  365. printk(KERN_ERR "xilinx or elf not "
  366. "successfully loaded\n");
  367. return -EIO; /* modprob -r may help ? */
  368. }
  369. /* wait for daughter detection != 0 */
  370. err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_DBRD_PRESENCE_OFFSET, 0, 0, 30); /* 300msec */
  371. if (err < 0) {
  372. snd_printk(KERN_ERR "error starting elf file\n");
  373. return err;
  374. }
  375. /* the board type can now be retrieved */
  376. mgr->board_type = (DAUGHTER_TYPE_MASK & readl_be( MIXART_MEM( mgr, MIXART_PSEUDOREG_DBRD_TYPE_OFFSET)));
  377. if (mgr->board_type == MIXART_DAUGHTER_TYPE_NONE)
  378. break; /* no daughter board; the file does not have to be loaded, continue after the switch */
  379. /* only if aesebu daughter board presence (elf code must run) */
  380. if (mgr->board_type != MIXART_DAUGHTER_TYPE_AES )
  381. return -EINVAL;
  382. /* daughter should be idle */
  383. if (status_daught != 0) {
  384. printk(KERN_ERR "daughter load error ! status = %d\n",
  385. status_daught);
  386. return -EIO; /* modprob -r may help ? */
  387. }
  388. /* check daughterboard xilinx validity */
  389. if (((u32*)(dsp->data))[0] == 0xffffffff)
  390. return -EINVAL;
  391. if (dsp->size % 4)
  392. return -EINVAL;
  393. /* inform mixart about the size of the file */
  394. writel_be( dsp->size, MIXART_MEM( mgr, MIXART_PSEUDOREG_DXLX_SIZE_OFFSET ));
  395. /* set daughterboard status to 1 */
  396. writel_be( 1, MIXART_MEM( mgr, MIXART_PSEUDOREG_DXLX_STATUS_OFFSET ));
  397. /* wait for status == 2 */
  398. err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_DXLX_STATUS_OFFSET, 1, 2, 30); /* 300msec */
  399. if (err < 0) {
  400. snd_printk(KERN_ERR "daughter board load error\n");
  401. return err;
  402. }
  403. /* get the address where to write the file */
  404. val = readl_be( MIXART_MEM( mgr, MIXART_PSEUDOREG_DXLX_BASE_ADDR_OFFSET ));
  405. if (!val)
  406. return -EINVAL;
  407. /* copy daughterboard xilinx code */
  408. memcpy_toio( MIXART_MEM( mgr, val), dsp->data, dsp->size);
  409. /* set daughterboard status to 4 */
  410. writel_be( 4, MIXART_MEM( mgr, MIXART_PSEUDOREG_DXLX_STATUS_OFFSET ));
  411. /* continue with init */
  412. break;
  413. } /* end of switch file index*/
  414. /* wait for daughter status == 3 */
  415. err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_DXLX_STATUS_OFFSET, 1, 3, 300); /* 3sec */
  416. if (err < 0) {
  417. snd_printk(KERN_ERR
  418. "daughter board could not be initialised\n");
  419. return err;
  420. }
  421. /* init mailbox (communication with embedded) */
  422. snd_mixart_init_mailbox(mgr);
  423. /* first communication with embedded */
  424. err = mixart_first_init(mgr);
  425. if (err < 0) {
  426. snd_printk(KERN_ERR "miXart could not be set up\n");
  427. return err;
  428. }
  429. /* create devices and mixer in accordance with HW options*/
  430. for (card_index = 0; card_index < mgr->num_cards; card_index++) {
  431. struct snd_mixart *chip = mgr->chip[card_index];
  432. if ((err = snd_mixart_create_pcm(chip)) < 0)
  433. return err;
  434. if (card_index == 0) {
  435. if ((err = snd_mixart_create_mixer(chip->mgr)) < 0)
  436. return err;
  437. }
  438. if ((err = snd_card_register(chip->card)) < 0)
  439. return err;
  440. };
  441. snd_printdd("miXart firmware downloaded and successfully set up\n");
  442. return 0;
  443. }
  444. #if defined(CONFIG_FW_LOADER) || defined(CONFIG_FW_LOADER_MODULE)
  445. #if !defined(CONFIG_USE_MIXARTLOADER) && !defined(CONFIG_SND_MIXART) /* built-in kernel */
  446. #define SND_MIXART_FW_LOADER /* use the standard firmware loader */
  447. #endif
  448. #endif
  449. #ifdef SND_MIXART_FW_LOADER
  450. int snd_mixart_setup_firmware(struct mixart_mgr *mgr)
  451. {
  452. static char *fw_files[3] = {
  453. "miXart8.xlx", "miXart8.elf", "miXart8AES.xlx"
  454. };
  455. char path[32];
  456. const struct firmware *fw_entry;
  457. int i, err;
  458. for (i = 0; i < 3; i++) {
  459. sprintf(path, "mixart/%s", fw_files[i]);
  460. if (request_firmware(&fw_entry, path, &mgr->pci->dev)) {
  461. snd_printk(KERN_ERR "miXart: can't load firmware %s\n", path);
  462. return -ENOENT;
  463. }
  464. /* fake hwdep dsp record */
  465. err = mixart_dsp_load(mgr, i, fw_entry);
  466. release_firmware(fw_entry);
  467. if (err < 0)
  468. return err;
  469. mgr->dsp_loaded |= 1 << i;
  470. }
  471. return 0;
  472. }
  473. MODULE_FIRMWARE("mixart/miXart8.xlx");
  474. MODULE_FIRMWARE("mixart/miXart8.elf");
  475. MODULE_FIRMWARE("mixart/miXart8AES.xlx");
  476. #else /* old style firmware loading */
  477. /* miXart hwdep interface id string */
  478. #define SND_MIXART_HWDEP_ID "miXart Loader"
  479. static int mixart_hwdep_dsp_status(struct snd_hwdep *hw,
  480. struct snd_hwdep_dsp_status *info)
  481. {
  482. struct mixart_mgr *mgr = hw->private_data;
  483. strcpy(info->id, "miXart");
  484. info->num_dsps = MIXART_HARDW_FILES_MAX_INDEX;
  485. if (mgr->dsp_loaded & (1 << MIXART_MOTHERBOARD_ELF_INDEX))
  486. info->chip_ready = 1;
  487. info->version = MIXART_DRIVER_VERSION;
  488. return 0;
  489. }
  490. static int mixart_hwdep_dsp_load(struct snd_hwdep *hw,
  491. struct snd_hwdep_dsp_image *dsp)
  492. {
  493. struct mixart_mgr* mgr = hw->private_data;
  494. struct firmware fw;
  495. int err;
  496. fw.size = dsp->length;
  497. fw.data = vmalloc(dsp->length);
  498. if (! fw.data) {
  499. snd_printk(KERN_ERR "miXart: cannot allocate image size %d\n",
  500. (int)dsp->length);
  501. return -ENOMEM;
  502. }
  503. if (copy_from_user((void *) fw.data, dsp->image, dsp->length)) {
  504. vfree(fw.data);
  505. return -EFAULT;
  506. }
  507. err = mixart_dsp_load(mgr, dsp->index, &fw);
  508. vfree(fw.data);
  509. if (err < 0)
  510. return err;
  511. mgr->dsp_loaded |= 1 << dsp->index;
  512. return err;
  513. }
  514. int snd_mixart_setup_firmware(struct mixart_mgr *mgr)
  515. {
  516. int err;
  517. struct snd_hwdep *hw;
  518. /* only create hwdep interface for first cardX (see "index" module parameter)*/
  519. if ((err = snd_hwdep_new(mgr->chip[0]->card, SND_MIXART_HWDEP_ID, 0, &hw)) < 0)
  520. return err;
  521. hw->iface = SNDRV_HWDEP_IFACE_MIXART;
  522. hw->private_data = mgr;
  523. hw->ops.dsp_status = mixart_hwdep_dsp_status;
  524. hw->ops.dsp_load = mixart_hwdep_dsp_load;
  525. hw->exclusive = 1;
  526. sprintf(hw->name, SND_MIXART_HWDEP_ID);
  527. mgr->dsp_loaded = 0;
  528. return snd_card_register(mgr->chip[0]->card);
  529. }
  530. #endif /* SND_MIXART_FW_LOADER */