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