mixart_hwdep.c 19 KB

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