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